Skip to content

Commit f530830

Browse files
committed
doc(sdk) add TSDoc comments to public API
1 parent 94dfb2d commit f530830

File tree

2 files changed

+354
-5
lines changed

2 files changed

+354
-5
lines changed

src/index.ts

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ export class MtLinkSdk {
5151
mode: 'production'
5252
};
5353

54+
/**
55+
* Call `init` to initialize the SDK and set default options for API calls.
56+
*
57+
* Some LINK APIs can be used without calling `init`.
58+
* Calls related to OAuth require a client id which can only be set via the `init` function.
59+
* These APIs include:
60+
* - {@link authorize}
61+
* - {@link onboard}
62+
* - {@link exchangeToken}
63+
* - {@link tokenInfo}
64+
*
65+
* @example
66+
* ```js
67+
* mtLinkSdk.init(client_id, options);
68+
* ```
69+
* @param clientId - OAuth `clientId` of the app (please request this from your Moneytree representative if you need one).
70+
* <br />⚠️ This function will throw an error if this parameter isn't provided.
71+
* @param options - Optional parameters for the SDK.
72+
* These options include all of the values below and also all `options` parameters of the other APIs.
73+
* <br />Options values passed here during initialization will be used by default if no options are
74+
* passed when calling a specific API.
75+
* <br />Available options are documented under {@link AuthorizeOptions} and {@link ConfigsOptions}
76+
* refer to each individual link for more details.
77+
*/
5478
public init(clientId: string, options: InitOptions = {}): void {
5579
if (!clientId) {
5680
throw new Error('[mt-link-sdk] Missing parameter `client_id` in `init`.');
@@ -66,37 +90,129 @@ export class MtLinkSdk {
6690
mode: validModes.indexOf(mode) === -1 ? 'production' : mode
6791
};
6892
}
69-
93+
/**
94+
* Use this method to send a guest identifier to Moneytree so that Moneytree can forward it as `saml_subject_id` parameter
95+
* to the Identity Provider (IdP) via the SAMLRequest during SAML SSO flows. See the [SAML SSO documentation for details](https://docs.link.getmoneytree.com/docs/saml-introduction#saml-subject-identifier).
96+
*
97+
* This parameter can be set during {@link init} or changed on a request-by-request basis with this method.
98+
* The `saml_subject_id` parameter will be forwarded to the `authorize`, `logout` and `open-service` methods when defined.
99+
*/
70100
public setSamlSubjectId(value: string): void {
71101
this.storedOptions.samlSubjectId = value;
72102
}
73103

104+
/**
105+
* OAuth authorization method to request guest consent to access data via the [Link API](https://getmoneytree.com/jp/link/about).
106+
*
107+
* The only supported flow is authorization code grant with PKCE [PKCE](https://auth0.com/docs/flows/concepts/auth-code-pkce)
108+
* If the user is not logged in yet this will show the login screen and redirect the guest to the consent screen after they log in.
109+
* After the guest consents, they will be redirected to the redirect URI with an authorization code.
110+
* If the user is already logged and has granted consent in the redirection happens immediately.
111+
*
112+
* You can pass the {@link AuthorizeOptions.forceLogout} option to force the guest to log in, even if they have an active session.
113+
*
114+
* You can also choose to display the sign up form when the user is not logged in yet by setting the {@link AuthorizeOptions.authAction} option.
115+
*
116+
* @remark
117+
* You must initialize the SDK via the {@link init} before calling this API.
118+
*
119+
* @example
120+
* ```javascript
121+
* mtLinkSdk.authorize(options);
122+
* ```
123+
*/
74124
public authorize(options?: AuthorizeOptions): void {
75125
authorize(this.storedOptions, options);
76126
}
77127

128+
/**
129+
* This method generates an URL for OAuth authorization that requires guest consent to access data via [Link API](https://getmoneytree.com/jp/link/about).
130+
*
131+
* See {@link authorize} API for authorization details. This API has exactly the same parameters as {@link authorize},
132+
* the only difference is that it returns an URL instead of opening immediately with `window.open`.
133+
*/
78134
public authorizeUrl(options?: AuthorizeUrlOptions): string {
79135
return authorizeUrl(this.storedOptions, options);
80136
}
81137

138+
/**
139+
* The onboard API allows a new guest to get onboard faster without having to go through the registration process.
140+
* All you have to do is provide an emai address and pass the same options parameter as the {@link authorize} function.
141+
* We will display a consent screen explaining the access requests and applicable scopes.
142+
* Once the guest consents, a new Moneytree account will be created on their behalf and authorization is completed.
143+
* Resulting behavior will be the same as the {@link authorize} redirection flow.
144+
*
145+
* Onboard will force any current guest session to logout, hence you do not have to call {@link logout} manually to
146+
* ensure a clean state.
147+
*
148+
* If an account with this email address already exists we will redirect the guest to the login screen.
149+
*
150+
* @remark
151+
* ⚠️ You must initialize the SDK via the {@link init} before calling this API.
152+
*
153+
* ⚠️ For legal reasons, you have to set up your app's terms and conditions URL to use the onboard API.
154+
* Please ask your Moneytree representative for more details.
155+
*
156+
* @throws If the `email` property is not set (via {@link init} or in the `options` parameter of this function).
157+
*/
82158
public onboard(options?: OnboardOptions): void {
83159
onboard(this.storedOptions, options);
84160
}
85161

162+
/**
163+
* This method generates a URL for guest onboarding.
164+
*
165+
* This API has exactly the same parameters as {@link onboard}, the only difference being that it returns an URL
166+
* instead of opening immediately with `window.open`.
167+
*/
86168
public onboardUrl(options?: OnboardUrlOptions): string {
87169
return onboardUrl(this.storedOptions, options);
88170
}
89171

172+
/**
173+
* Logout current user from Moneytree.
174+
*/
90175
public logout(options?: LogoutOptions): void {
91176
logout(this.storedOptions, options);
92177
}
93178

179+
/**
180+
* This method generates a URL to log out the guest.
181+
*
182+
* This API has exactly the same parameters as {@link logout}, the only difference being that it returns an URL
183+
* instead of opening immediately with `window.open`.
184+
*/
94185
public logoutUrl(options?: LogoutUrlOptions): string {
95186
return logoutUrl(this.storedOptions, options);
96187
}
97188

189+
/**
190+
* This is a method to open various services provided by Moneytree such as Moneytree account settings, Vault etc.
191+
*
192+
* Pass `serviceId: 'link-kit'` to open the LINK Kit service.
193+
*
194+
* @remark ⚠️ calling this API before calling {@link init} will open the services view without branding (company logo etc.)
195+
*/
98196
public openService(serviceId: 'link-kit', options?: LinkKitOpenServiceOptions): void;
197+
/**
198+
* Pass `serviceId: 'myaccount'` to open the MyAccount service.
199+
*
200+
* Open different MyAccount sub-pages by passing the {@link MyAccountServiceTypes} for all possible options.
201+
*
202+
* @remark ⚠️ calling this API before calling {@link init} will open the services view without branding (company logo etc.)
203+
*/
99204
public openService(serviceId: 'myaccount', options?: MyAccountOpenServiceOptions): void;
205+
/**
206+
* Pass `serviceId: 'vault'` to open the Vault service.
207+
*
208+
* Depending on the Vault sub-page you want to open, you can pass the following options:
209+
* - `serviceList`: opens the vault service list page, pass {@link VaultOpenServiceViewServiceList} as options.
210+
* - `serviceConnection`: opens the vault service connection page, pass {@link VaultOpenServiceViewServiceConnection} as options.
211+
* - `connectionSetting`: opens the vault connection setting page, pass {@link VaultOpenServiceViewConnectionSetting} as options.
212+
* - `customerSupport`: opens the vault customer support page, pass {@link VaultOpenServiceViewCustomerSupport} as options.
213+
*
214+
* @remark ⚠️ calling this API before calling {@link init} will open the services view without branding (company logo etc.)
215+
*/
100216
public openService(serviceId: 'vault', options?: ConfigsOptions): void;
101217
public openService(serviceId: 'vault', options?: VaultOpenServiceViewServiceList): void;
102218
public openService(serviceId: 'vault', options?: VaultOpenServiceViewServiceConnection): void;
@@ -118,6 +234,12 @@ export class MtLinkSdk {
118234
}
119235
}
120236

237+
/**
238+
* This method can generate URLs for various services provided by Moneytree, such as Moneytree Account Settings and Vault.
239+
*
240+
* This API has exactly the same parameters as {@link openService}, the only difference being that it returns an URL
241+
* instead of opening immediately with `window.open`.
242+
*/
121243
public openServiceUrl(serviceId: 'link-kit', options?: LinkKitOpenServiceUrlOptions): string;
122244
public openServiceUrl(serviceId: 'myaccount', options?: MyAccountOpenServiceUrlOptions): string;
123245
public openServiceUrl(serviceId: 'vault', options?: ConfigsOptionsWithoutIsNewTab): string;
@@ -138,14 +260,49 @@ export class MtLinkSdk {
138260
}
139261
}
140262

263+
/**
264+
* Request for a password-less login link to be sent to the guest's email address.
265+
*
266+
* Clicking on the link in the email will log a guest in directly to the screen specified by the
267+
* {@link RequestLoginLinkOptions.loginLinkTo} parameter.
268+
*/
141269
public requestLoginLink(options?: RequestLoginLinkOptions): Promise<void> {
142270
return requestLoginLink(this.storedOptions, options);
143271
}
144272

273+
/**
274+
* Use this function to exchange an authorization `code` for a token.
275+
*
276+
* You can optionally pass `code` via options parameter, otherwise it will automatically extract the `code` URL
277+
* parameter of the current URL.
278+
*
279+
* The `code` can be used only once. The SDK does not store it internally, you have to store it in your application.
280+
*
281+
* One way to use this API is by calling it on your redirection page. For example, if `authorize` redirects to
282+
* `https://yourapp.com/callback?code=somecode`, you can call this function in the script loaded on that redirection
283+
* page and the client library will automatically extract the code to exchange for a token.
284+
*
285+
* Alternatively, you can extract the `code` manually from the redirect URL and pass it to this function via the
286+
* options object yourself.
287+
*
288+
* If you passed a {@link AuthorizeOptions.codeChallenge} option during the {@link authorize} or {@link onboard}
289+
* call and wish to exchange the token on the client side application, make sure to set the code verifier used to
290+
* generate the said `codeChallenge` here.
291+
*
292+
* @see [here](https://www.oauth.com/oauth2-servers/pkce/authorization-code-exchange/) for more details.
293+
*
294+
* @throws If the {@link ExchangeTokenOptions.code} is not set and the SDK fails to extract it from browser URL.
295+
* @throws If the {@link ExchangeTokenOptions.redirectUri} is not set and it is not set via {@link init}.
296+
*/
145297
public exchangeToken(options?: ExchangeTokenOptions): Promise<Token> {
146298
return exchangeToken(this.storedOptions, options);
147299
}
148300

301+
/**
302+
* Validate a token and get information about the user or resource server.
303+
304+
* @throws if the token is expired.
305+
*/
149306
public tokenInfo(token: string): Promise<TokenInfo> {
150307
return tokenInfo(this.storedOptions, token);
151308
}

0 commit comments

Comments
 (0)