Skip to content

Commit c73dd2e

Browse files
committed
chore(magic-link): rename api to login-link
1 parent 15b7be2 commit c73dd2e

11 files changed

+63
-63
lines changed

dist/api/request-login-link.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { StoredOptions, RequestLoginLinkOptions } from '../typings';
2+
export default function requestLoginLink(storedOptions: StoredOptions, options?: RequestLoginLinkOptions): Promise<void>;

dist/api/request-magic-link.d.ts

-2
This file was deleted.

docs/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,21 @@ mtLinkSdk.openService('myaccount-settings', { view: 'update-email' });
291291
| serviceId | `myaccount-settings` | true | | Open MyAccount |
292292
| options.view | `authorized-applications`, `change-language`, `email-preferences`, `delete-account`, `update-email`, `update-password` | false | | Directly go to the chosen page. If no view is provided, it goes to the top page of MyAccount. |
293293

294-
### requestMagicLink
294+
### requestLoginLink
295295

296-
Request for a magic link (password-less login link) to be sent to the guest's email address. Clicking on the link in the email will log a guest in directly to the screen specified by the `magicLinkTo` parameter.
296+
Request for a password-less login link to be sent to the guest's email address. Clicking on the link in the email will log a guest in directly to the screen specified by the `loginLinkTo` parameter.
297297

298298
<h6>Usage:</h6>
299299

300300
```javascript
301-
mtLinkSdk.requestMagicLink(options);
301+
mtLinkSdk.requestLoginLink(options);
302302
```
303303

304304
| Parameter | Type | Required | Default Value | Description |
305305
| - | - | - | - | - |
306306
| options | object | false | Value set during `init`. | Optional parameters. Includes all options in [common options](#common-api-options). |
307-
| options.magicLinkTo | string | true | `settings` (for mobile view)<p><strong>OR</strong></p>`settings/update-email` (for desktop view) | Redirection to location after login, currently supported locations include:<li>`settings` - Main Moneytree account settings screen.</li><li>`settings/authorized-applications` - List of apps currently connected to Moneytree.</li><li>`settings/change-language` - Change Moneytree account language screen.<li>`settings/email-preferences` - Change Moneytree email preferences screen</li><li>`settings/delete-account` - Delete Moneytree account screen.</li><li>`settings/update-email` - Change Moneytree account email screen.</li><li>`settings/update-password` - Change Moneytree account password screen.</li> |
308-
| options.email | string | true | Value set during `init`. | Magic link will be sent to this email.<br /><br /><strong>NOTE:</strong> This function will throw an error if both values here and from the [init options](?id=api-init_options) are undefined. |
307+
| options.loginLinkTo | string | true | `settings` (for mobile view)<p><strong>OR</strong></p>`settings/update-email` (for desktop view) | Redirection to location after login, currently supported locations include:<li>`settings` - Main Moneytree account settings screen.</li><li>`settings/authorized-applications` - List of apps currently connected to Moneytree.</li><li>`settings/change-language` - Change Moneytree account language screen.<li>`settings/email-preferences` - Change Moneytree email preferences screen</li><li>`settings/delete-account` - Delete Moneytree account screen.</li><li>`settings/update-email` - Change Moneytree account email screen.</li><li>`settings/update-password` - Change Moneytree account password screen.</li> |
308+
| options.email | string | true | Value set during `init`. | Login Link will be sent to this email.<br /><br /><strong>NOTE:</strong> This function will throw an error if both values here and from the [init options](?id=api-init_options) are undefined. |
309309

310310
## Common API options
311311

sample/src/elements.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ export default {
2828
logoutBtn: document.getElementById('logout-btn') as HTMLButtonElement,
2929
openServiceBtn: document.getElementById('open-service-btn') as HTMLButtonElement,
3030
tokenInfoBtn: document.getElementById('token-info-btn') as HTMLButtonElement,
31-
sendMagicLinkBtn: document.getElementById('send-magic-link') as HTMLButtonElement,
31+
sendLoginLinkBtn: document.getElementById('send-login-link') as HTMLButtonElement,
3232
doOnboardBtn: document.getElementById('do-onboard') as HTMLButtonElement,
3333
tokenElm: document.getElementById('token') as HTMLInputElement,
34-
magicLinkToElm: document.getElementById('magicLinkTo') as HTMLSelectElement,
35-
magicLinkEmailElm: document.getElementById('magicLink-email') as HTMLSelectElement,
34+
loginLinkToElm: document.getElementById('loginLinkTo') as HTMLSelectElement,
35+
loginLinkEmailElm: document.getElementById('loginLink-email') as HTMLSelectElement,
3636
tokenInfoLabel: document.getElementById('token-info-text') as HTMLInputElement,
3737
accessTokenLabel: document.getElementById('access-token-text') as HTMLParagraphElement,
3838
authorizationSection: document.getElementById('authorization-section') as HTMLDivElement,
3939
onBoardSection: document.getElementById('onboard-section') as HTMLDivElement,
40-
magicLinkSection: document.getElementById('magic-link-section') as HTMLDivElement,
40+
loginLinkSection: document.getElementById('login-link-section') as HTMLDivElement,
4141
openServiceSection: document.getElementById('open-service-section') as HTMLDivElement,
4242
logoutSection: document.getElementById('logout-section') as HTMLDivElement,
4343
tokenInfoSection: document.getElementById('token-info-section') as HTMLDivElement,

sample/src/index.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ <h3>Onboard</h3>
151151
<button id="do-onboard">Do Onboard</button>
152152
</section>
153153

154-
<section id="magic-link-section">
155-
<h3>Magic Link</h3>
154+
<section id="login-link-section">
155+
<h3>Login Link</h3>
156156
<p>
157-
<span style="color: red;">*</span>MagicLinkTo, <small>Redirection to location after login </small>
157+
<span style="color: red;">*</span>LoginLinkTo, <small>Redirection to location after login </small>
158158
<div>
159-
<select id="magicLinkTo">
159+
<select id="loginLinkTo">
160160
<option value="settings" default>settings</option>
161161
<option value="settings/authorized-applications">settings/authorized-applications</option>
162162
<option value="settings/change-language">settings/change-language</option>
@@ -168,14 +168,14 @@ <h3>Magic Link</h3>
168168
</div>
169169
</p>
170170
<p>
171-
<span style="color: red;">*</span>Email, <small>Magic link will be sent to this email.</small>
171+
<span style="color: red;">*</span>Email, <small>Login Link will be sent to this email.</small>
172172
<div>
173-
<input id="magicLink-email" type="email"/>
173+
<input id="loginLink-email" type="email"/>
174174
</div>
175175
</p>
176176

177177
<a href="#common-options"><h4>Common API options(optionals)</h4></a>
178-
<button id="send-magic-link">Send Magic Link</button>
178+
<button id="send-login-link">Send Login Link</button>
179179
</section>
180180

181181

sample/src/index.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mtLinkSdk, {
55
OnboardOptions,
66
OpenServicesConfigsOptions,
77
ServiceId,
8-
MagicLinkTo,
8+
LoginLinkTo,
99
ServicesListType,
1010
} from '@moneytree/mt-link-javascript-sdk';
1111

@@ -178,23 +178,23 @@ elements.openServiceBtn.onclick = () => {
178178
mtLinkSdk.openService(serviceId, OpenServicesConfigsOptions);
179179
};
180180

181-
// Launch open magic link
182-
elements.sendMagicLinkBtn.onclick = async () => {
183-
const { sendMagicLinkBtn, magicLinkToElm, magicLinkEmailElm } = elements;
181+
// Launch open login link
182+
elements.sendLoginLinkBtn.onclick = async () => {
183+
const { sendLoginLinkBtn, loginLinkToElm, loginLinkEmailElm } = elements;
184184

185185
try {
186-
sendMagicLinkBtn.disabled = true;
186+
sendLoginLinkBtn.disabled = true;
187187

188-
await mtLinkSdk.requestMagicLink({
189-
magicLinkTo: magicLinkToElm.options[magicLinkToElm.selectedIndex].value as MagicLinkTo,
190-
email: magicLinkEmailElm.value,
188+
await mtLinkSdk.requestLoginLink({
189+
loginLinkTo: loginLinkToElm.options[loginLinkToElm.selectedIndex].value as LoginLinkTo,
190+
email: loginLinkEmailElm.value,
191191
});
192-
window.alert('Success, magicLink sent out.');
192+
window.alert('Success, loginLink sent out.');
193193
} catch (error) {
194194
console.log(error);
195195
}
196196

197-
sendMagicLinkBtn.disabled = false;
197+
sendLoginLinkBtn.disabled = false;
198198
};
199199

200200
// Helper, to switch the vault options, depends on openService's serviceId value
@@ -241,7 +241,7 @@ const initializeLinkSDK = (options: InitOptions = {}) => {
241241
const switchAuthorizeFunctions = (value: string) => {
242242
elements.authorizationSection.style.display = value;
243243
elements.onBoardSection.style.display = value;
244-
elements.magicLinkSection.style.display = value;
244+
elements.loginLinkSection.style.display = value;
245245
};
246246

247247
const disabledFunctions = () => {

src/__tests__/index.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import authorize from '../api/authorize';
44
import onboard from '../api/onboard';
55
import logout from '../api/logout';
66
import openService from '../api/open-service';
7-
import requestMagicLink from '../api/request-magic-link';
7+
import requestLoginLink from '../api/request-login-link';
88
import exchangeToken from '../api/exchange-token';
99
import tokenInfo from '../api/token-info';
1010
import mtLinkSdk, { MtLinkSdk } from '..';
@@ -13,7 +13,7 @@ jest.mock('../api/authorize');
1313
jest.mock('../api/onboard');
1414
jest.mock('../api/logout');
1515
jest.mock('../api/open-service');
16-
jest.mock('../api/request-magic-link');
16+
jest.mock('../api/request-login-link');
1717
jest.mock('../api/exchange-token');
1818
jest.mock('../api/token-info');
1919

@@ -49,9 +49,9 @@ describe('index', () => {
4949
expect(result4).toBeUndefined();
5050
expect(openService).toBeCalledWith(storedOptions, 'test', undefined);
5151

52-
const result5 = await instance.requestMagicLink({ magicLinkTo: 'magicLinkTo' });
52+
const result5 = await instance.requestLoginLink({ loginLinkTo: 'loginLinkTo' });
5353
expect(result5).toBeUndefined();
54-
expect(requestMagicLink).toBeCalledWith(storedOptions, { magicLinkTo: 'magicLinkTo' });
54+
expect(requestLoginLink).toBeCalledWith(storedOptions, { loginLinkTo: 'loginLinkTo' });
5555

5656
mocked(exchangeToken).mockResolvedValueOnce('test');
5757
const result6 = await instance.exchangeToken({ code: 'code' });

src/api/__tests__/request-magic-link.test.ts renamed to src/api/__tests__/request-login-link.test.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import qs from 'qs';
55

66
import { MY_ACCOUNT_DOMAINS } from '../../server-paths';
77
import { MtLinkSdk } from '../..';
8-
import requestMagicLink from '../request-magic-link';
8+
import requestLoginLink from '../request-login-link';
99
import { generateConfigs } from '../../helper';
1010

1111
describe('api', () => {
12-
describe('request-magic-link', () => {
12+
describe('request-login-link', () => {
1313
const clientId = 'clientId';
1414
const email = 'email';
1515

1616
test('email is required', async () => {
17-
await expect(requestMagicLink(new MtLinkSdk().storedOptions)).rejects.toThrow(
18-
'[mt-link-sdk] Missing option `email` in `requestMagicLink`, make sure to pass one via `requestMagicLink` options or `init` options.'
17+
await expect(requestLoginLink(new MtLinkSdk().storedOptions)).rejects.toThrow(
18+
'[mt-link-sdk] Missing option `email` in `requestLoginLink`, make sure to pass one via `requestLoginLink` options or `init` options.'
1919
);
2020
});
2121

@@ -25,15 +25,15 @@ describe('api', () => {
2525
fetch.mockClear();
2626
fetch.mockRejectedValueOnce(error);
2727

28-
await expect(requestMagicLink(new MtLinkSdk().storedOptions, { email })).rejects.toThrow(
29-
`[mt-link-sdk] \`requestMagicLink\` execution failed. ${error}`
28+
await expect(requestLoginLink(new MtLinkSdk().storedOptions, { email })).rejects.toThrow(
29+
`[mt-link-sdk] \`requestLoginLink\` execution failed. ${error}`
3030
);
3131
});
3232

33-
test('default magicLinkTo to /settings', async () => {
33+
test('default loginLinkTo to /settings', async () => {
3434
fetch.mockClear();
3535

36-
await requestMagicLink(new MtLinkSdk().storedOptions, { email });
36+
await requestLoginLink(new MtLinkSdk().storedOptions, { email });
3737

3838
const query = qs.stringify({
3939
configs: generateConfigs(),
@@ -56,12 +56,12 @@ describe('api', () => {
5656
});
5757
});
5858

59-
test('prefix magicLinkTo with "/" if provided value do not have one', async () => {
59+
test('prefix loginLinkTo with "/" if provided value do not have one', async () => {
6060
fetch.mockClear();
6161

62-
await requestMagicLink(new MtLinkSdk().storedOptions, {
62+
await requestLoginLink(new MtLinkSdk().storedOptions, {
6363
email,
64-
magicLinkTo: 'settings/delete-account',
64+
loginLinkTo: 'settings/delete-account',
6565
});
6666

6767
const query = qs.stringify({
@@ -91,7 +91,7 @@ describe('api', () => {
9191
fetch.mockClear();
9292
fetch.mockResolvedValueOnce({ status: 400, statusText } as Response);
9393

94-
await expect(requestMagicLink(new MtLinkSdk().storedOptions, { email })).rejects.toThrow(
94+
await expect(requestLoginLink(new MtLinkSdk().storedOptions, { email })).rejects.toThrow(
9595
statusText
9696
);
9797
});
@@ -109,7 +109,7 @@ describe('api', () => {
109109
cobrandClientId,
110110
});
111111

112-
await requestMagicLink(mtLinkSdk.storedOptions);
112+
await requestLoginLink(mtLinkSdk.storedOptions);
113113

114114
const query = qs.stringify({
115115
client_id: clientId,

src/api/request-magic-link.ts renamed to src/api/request-login-link.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { stringify } from 'qs';
22

33
import { generateConfigs, mergeConfigs, generateSdkHeaderInfo } from '../helper';
44
import { MY_ACCOUNT_DOMAINS } from '../server-paths';
5-
import { StoredOptions, RequestMagicLinkOptions } from '../typings';
5+
import { StoredOptions, RequestLoginLinkOptions } from '../typings';
66

7-
export default async function requestMagicLink(
7+
export default async function requestLoginLink(
88
storedOptions: StoredOptions,
9-
options: RequestMagicLinkOptions = {}
9+
options: RequestLoginLinkOptions = {}
1010
): Promise<void> {
1111
const { clientId, mode, email: defaultEmail, cobrandClientId, locale } = storedOptions;
12-
const { email = defaultEmail, magicLinkTo, ...rest } = options;
12+
const { email = defaultEmail, loginLinkTo, ...rest } = options;
1313
const configs = mergeConfigs(storedOptions, rest, ['email']);
1414

1515
if (!email) {
1616
throw new Error(
17-
'[mt-link-sdk] Missing option `email` in `requestMagicLink`, make sure to pass one via `requestMagicLink` options or `init` options.'
17+
'[mt-link-sdk] Missing option `email` in `requestLoginLink`, make sure to pass one via `requestLoginLink` options or `init` options.'
1818
);
1919
}
2020

@@ -27,10 +27,10 @@ export default async function requestMagicLink(
2727

2828
const url = `${MY_ACCOUNT_DOMAINS[mode]}/magic-link.json?${queryString}`;
2929

30-
let magicLinkToValue = magicLinkTo || '/settings';
30+
let loginLinkToValue = loginLinkTo || '/settings';
3131

32-
if (magicLinkToValue[0] !== '/') {
33-
magicLinkToValue = `/${magicLinkToValue}`;
32+
if (loginLinkToValue[0] !== '/') {
33+
loginLinkToValue = `/${loginLinkToValue}`;
3434
}
3535

3636
try {
@@ -42,14 +42,14 @@ export default async function requestMagicLink(
4242
},
4343
body: JSON.stringify({
4444
email,
45-
magic_link_to: magicLinkToValue,
45+
magic_link_to: loginLinkToValue,
4646
}),
4747
});
4848

4949
if (response.status < 200 || response.status >= 300) {
5050
throw new Error(response.statusText);
5151
}
5252
} catch (error) {
53-
throw new Error(`[mt-link-sdk] \`requestMagicLink\` execution failed. ${error}`);
53+
throw new Error(`[mt-link-sdk] \`requestLoginLink\` execution failed. ${error}`);
5454
}
5555
}

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import authorize from './api/authorize';
22
import onboard from './api/onboard';
33
import logout from './api/logout';
44
import openService from './api/open-service';
5-
import requestMagicLink from './api/request-magic-link';
5+
import requestLoginLink from './api/request-login-link';
66
import exchangeToken from './api/exchange-token';
77
import tokenInfo from './api/token-info';
88
import {
@@ -14,7 +14,7 @@ import {
1414
AuthorizeOptions,
1515
OnboardOptions,
1616
ExchangeTokenOptions,
17-
RequestMagicLinkOptions,
17+
RequestLoginLinkOptions,
1818
TokenInfo,
1919
Mode,
2020
} from './typings';
@@ -60,8 +60,8 @@ export class MtLinkSdk {
6060
openService(this.storedOptions, serviceId, options);
6161
}
6262

63-
public requestMagicLink(options?: RequestMagicLinkOptions): Promise<void> {
64-
return requestMagicLink(this.storedOptions, options);
63+
public requestLoginLink(options?: RequestLoginLinkOptions): Promise<void> {
64+
return requestLoginLink(this.storedOptions, options);
6565
}
6666

6767
public exchangeToken(options?: ExchangeTokenOptions): Promise<string> {

src/typings.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export type OnboardOptions = Omit<
115115

116116
export type ServiceId = string | 'vault' | 'myaccount-settings' | 'linkkit';
117117

118-
export type MagicLinkTo =
118+
export type LoginLinkTo =
119119
| string
120120
| 'settings'
121121
| 'settings/authorized-applications'
@@ -125,8 +125,8 @@ export type MagicLinkTo =
125125
| 'settings/update-email'
126126
| 'settings/update-password';
127127

128-
export interface RequestMagicLinkOptions extends ConfigsOptions {
129-
magicLinkTo?: MagicLinkTo;
128+
export interface RequestLoginLinkOptions extends ConfigsOptions {
129+
loginLinkTo?: LoginLinkTo;
130130
}
131131

132132
export interface TokenInfo {

0 commit comments

Comments
 (0)