Skip to content

Commit

Permalink
ts docs added
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuchawla009 committed Jul 13, 2021
1 parent 2f348a0 commit 539f400
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"plugin:mocha/recommended",
"prettier"
],
"plugins": ["prettier", "promise", "import", "simple-import-sort", "mocha", "@typescript-eslint"],
"plugins": ["prettier", "promise", "import", "simple-import-sort", "mocha", "@typescript-eslint","eslint-plugin-tsdoc"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
Expand Down Expand Up @@ -67,6 +67,7 @@
"props": false
}
],
"tsdoc/syntax": "warn",
"prettier/prettier": [
"error",
{
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"plugin:mocha/recommended",
"prettier"
],
"plugins": ["prettier", "promise", "import", "simple-import-sort", "mocha", "@typescript-eslint"],
"plugins": ["prettier", "promise", "import", "simple-import-sort", "mocha", "@typescript-eslint", "eslint-plugin-tsdoc"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
Expand Down Expand Up @@ -87,6 +87,7 @@
"props": false
}
],
"tsdoc/syntax": "warn",
"prettier/prettier": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-tsdoc": "^0.2.14",
"eslint-webpack-plugin": "^2.5.4",
"husky": "^7.0.1",
"jsdom": "^16.6.0",
Expand Down
207 changes: 162 additions & 45 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,111 @@ export const OPENLOGIN_NETWORK = {
export type OPENLOGIN_NETWORK_TYPE = typeof OPENLOGIN_NETWORK[keyof typeof OPENLOGIN_NETWORK];

export type OpenLoginOptions = {
/**
* You can get your clientId/projectId by registering your
* dapp on {@link "https://developer.tor.us"| developer dashbaord}
*/
clientId: string;

/**
* network specifies the openlogin iframe url url to be used.
*
* - `'mainnet'`: https://app.openlogin.com will be used which is the production version.
* - `'testnet'`: https://beta.openlogin.com will be used which is the beta version.
* - `'development'`: http://localhost:3000 will be used for development purpose.
*/
network: OPENLOGIN_NETWORK_TYPE;

/**
* Setting no3PC forces openlogin to assume that third party cookies are blocked
* in the browser.
*
* @defaultValue false
* @remarks
* Only pass no3PC to `true` when you are sure that third party cookies are not
* supported. By default openlogin will self check third party cookies and proceed
* accordingly.
*/
no3PC?: boolean;

/**
* redirectUrl is the dapp's url where user will be redirected after login.
*
* @remarks
* Register this url at {@link "https://developer.tor.us"| developer dashbaord}
* else initialization will give error.
*/
redirectUrl?: string;

/**
* two uxModes are supported:-
* - `'POPUP'`: In this uxMode, a popup will be shown to user for login.
* - `'REDIRECT'`: In this uxMode, user will be redirected to a new window tab for login.
*
* @defaultValue `'POPUP'`
* @remarks
*
* Use of `'REDIRECT'` mode is recommended in browsers where popups might get blocked.
*/
uxMode?: UX_MODE_TYPE;

/**
* replaceUrlOnRedirect removes the params from the redirected url after login
*
* @defaultValue true
*/
replaceUrlOnRedirect?: boolean;

/**
* originData is used to verify the origin of dapp by iframe.
*
* @internal
* @remarks
* You don't have to pass originData explicitly if you have registered your dapp at
* {@link "https://developer.tor.us"| developer dashbaord}.
*
* originData contains a signature of dapp's origin url which is generated using
* project's secret.
*/
originData?: OriginData;

/**
* loginConfig enables you to pass your own login verifiers configuration for various
* loginProviders.
*
* loginConfig is key value map where each key should be a valid loginProvider and value
* should be custom configuration for that loginProvider
*
* @remarks
* You can deploy your own verifiers from {@link "https://developer.tor.us"| developer dashbaord}
* to use here.
*
*/
loginConfig?: LoginConfig;

/**
* _iframeUrl is for internal development use only and is used to override the
* `network` parameter.
* @internal
*/
_iframeUrl?: string;
/**
* _startUrl is for internal development use only and is used specify authentication
* start url of iframe.
* @internal
*/
_startUrl?: string;

/**
* _popupUrl is for internal development use only and is used specify url of popup window
* for popup uxMode.
* @internal
*/
_popupUrl?: string;

/**
* options for whitelabling default openlogin modal.
*/
whiteLabel?: WhiteLabelData;
};

Expand All @@ -100,57 +194,80 @@ export const LOGIN_PROVIDER = {
WEBAUTHN: "webauthn",
} as const;

/**
* {@label loginProviderType}
*/
export type LOGIN_PROVIDER_TYPE = typeof LOGIN_PROVIDER[keyof typeof LOGIN_PROVIDER];

// autocomplete workaround https://github.com/microsoft/TypeScript/issues/29729
export type CUSTOM_LOGIN_PROVIDER_TYPE = string & { toString?: (radix?: number) => string };

export type LoginParams = BaseRedirectParams & {
/**
* loginProvider sets the oauth login method to be used.
* You can use any of the valid loginProvider from this list.
*
* If this param is not passed then it will show all the available
* login methods to user in a modal.
*
*/
loginProvider: LOGIN_PROVIDER_TYPE | CUSTOM_LOGIN_PROVIDER_TYPE;

/**
* Setting fastLogin to `true` will force user to login with webauthn if
* webauthn is available on device.
*
* Defaults to false
* @default false
*
* @remarks
* Use this option with caution only when you are sure about that user has enabled
* webauthn while registeration, else don't use this option. Openlogin will itself
* take care of detecting and handling webauthn. In general you may not need to use
* this option.
*/
fastLogin?: boolean;

/**
* Setting relogin to `true` will force user to relogin when login
* method is called even if user is already logged in. By default login
* method call skips login process if user is already logged in.
*
* * Defaults to false
* @default false
*/
relogin?: boolean;

/**
* Skips TKey onboarding for new users, whereas old users will be
* presented with an option to skip tKey in UI if this option is enabled.
*
* Defaults to false
* @default false
*/
skipTKey?: boolean;
getWalletKey?: boolean;
extraLoginOptions?: ExtraLoginOptions;
/**
* loginProvider sets the oauth login method to be used.
* You can use any of the valid loginProvider from the supported list.
*
* If this param is not passed then it will show all the available
* login methods to user in a modal.
*
*/
loginProvider?: LOGIN_PROVIDER_TYPE | CUSTOM_LOGIN_PROVIDER_TYPE;

/**
* Setting fastLogin to `true` will force user to login with webauthn if
* webauthn is available on device.
*
* Defaults to false
* @defaultValue false
* @experimental
*
* @remarks
* Use this option with caution only when you are sure about that user has
* enabled webauthn while registeration, else don't use this option.
* Openlogin will itself take care of detecting and handling webauthn.
* In general you may not need to use this option.
*/
fastLogin?: boolean;

/**
* Setting relogin to `true` will force user to relogin when login
* method is called even if user is already logged in. By default login
* method call skips login process if user is already logged in.
*
* * Defaults to false
* @defaultValue false
*/
relogin?: boolean;

/**
* setting skipTKey to `true` will skip TKey onboarding for new users,
* whereas old users will be presented with an option to skip tKey in UI
* if this option is enabled.
*
* Defaults to false
* @defaultValue false
*/
skipTKey?: boolean;

/**
* This option is for internal use only in torus wallet and has not effect
* on user's login on other dapps.
*
* Defaults to false
* @defaultValue false
* @internal
*/
getWalletKey?: boolean;

/**
* extraLoginOptions can be used to pass standard oauth login options to
* loginProvider.
*
* For ex: you will have to pass `login_hint` as user's email and `domain`
* as your app domain in `extraLoginOptions` while using `email_passwordless`
* loginProvider
*/
extraLoginOptions?: ExtraLoginOptions;
};

export type OpenloginUserInfo = {
Expand Down
Loading

0 comments on commit 539f400

Please sign in to comment.