Skip to content

Commit c918b9d

Browse files
committed
refactor!: remove options from tokenInfo
BREAKING CHANGE: `tokenInfo` API no longer accept options parameter as it provide no benefit.
1 parent c7d5dc7 commit c918b9d

File tree

6 files changed

+14
-71
lines changed

6 files changed

+14
-71
lines changed

docs/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ tokenInfo.isMtClient // for internal use
169169
| Parameter | Type | Required | Default Value | Description |
170170
| - | - | - | - | - |
171171
| token | string | true | | Token you wish to get info for. |
172-
| options | object | false | Value set during `init`. | Optional parameters. |
173-
| options.redirectUri | string | false | Value set during `init`. | Make sure the value of `redirectUri` here is the same state value used during `authorize` or `onboard` call.<br /><br /><strong>NOTE:</strong> The SDK will throw an error if both this parameter and the default value from the [init options](?id=api-init_options) are undefined. |
174172

175173
### logout
176174

src/__tests__/index.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ describe('index', () => {
6363
mocked(tokenInfo).mockResolvedValueOnce('test');
6464
const result7 = await instance.tokenInfo('test');
6565
expect(result7).toBe('test');
66-
expect(tokenInfo).toBeCalledWith(storedOptions, 'test', undefined);
6766
});
6867

6968
test('mtLinkSdk', () => {

src/api/__tests__/token-info.test.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fetch from 'jest-fetch-mock';
2-
import qs from 'qs';
32

43
import { MY_ACCOUNT_DOMAINS } from '../../server-paths';
54
import { MtLinkSdk } from '../..';
@@ -35,56 +34,24 @@ describe('api', () => {
3534
);
3635
});
3736

38-
test('redirectUri is required', async () => {
39-
const instance = new MtLinkSdk();
40-
41-
await expect(tokenInfo(instance.storedOptions, token)).rejects.toThrow(
42-
'[mt-link-sdk] Missing option `redirectUri` in `tokenInfo`, make sure to pass one via `tokenInfo` options or `init` options.'
43-
);
44-
});
45-
4637
test('make request', async () => {
4738
fetch.mockClear();
4839
fetch.mockResponseOnce(JSON.stringify(response));
4940

5041
await tokenInfo(mtLinkSdk.storedOptions, token);
5142

52-
const query = qs.stringify({
53-
client_id: clientId,
54-
redirect_uri: redirectUri,
55-
response_type: 'token',
56-
});
57-
58-
const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/token/info.json?${query}`;
43+
const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/token/info.json`;
5944

6045
expect(fetch).toBeCalledTimes(1);
6146
expect(fetch).toBeCalledWith(url, {
6247
method: 'GET',
6348
headers: {
6449
Authorization: `Bearer ${token}`,
50+
'x-api-key': clientId,
6551
},
6652
});
6753
});
6854

69-
test('use option', async () => {
70-
fetch.mockClear();
71-
fetch.mockResponseOnce(JSON.stringify(response));
72-
73-
const newRedirectUri = 'newRedirectUri';
74-
75-
await tokenInfo(mtLinkSdk.storedOptions, token, { redirectUri: newRedirectUri });
76-
77-
const query = qs.stringify({
78-
client_id: clientId,
79-
redirect_uri: newRedirectUri,
80-
response_type: 'token',
81-
});
82-
83-
const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/token/info.json?${query}`;
84-
85-
expect(fetch.mock.calls[0][0]).toBe(url);
86-
});
87-
8855
test('failed to request', async () => {
8956
const error = 'failed';
9057

src/api/token-info.ts

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
1-
import qs from 'qs';
2-
31
import { MY_ACCOUNT_DOMAINS } from '../server-paths';
4-
import { StoredOptions, TokenInfoOptions, TokenInfo } from '../typings';
2+
import { StoredOptions, TokenInfo } from '../typings';
53

64
export default async function tokenInfo(
75
storedOptions: StoredOptions,
8-
token: string,
9-
options: TokenInfoOptions = {}
6+
token: string
107
): Promise<TokenInfo> {
11-
const { clientId, redirectUri: defaultRedirectUri, mode } = storedOptions;
12-
const { redirectUri = defaultRedirectUri } = options;
8+
const { mode, clientId } = storedOptions;
139

1410
if (!token) {
1511
throw new Error('[mt-link-sdk] Missing parameter `token` in `tokenInfo`.');
1612
}
1713

18-
if (!redirectUri) {
19-
throw new Error(
20-
'[mt-link-sdk] Missing option `redirectUri` in `tokenInfo`, make sure to pass one via `tokenInfo` options or `init` options.'
21-
);
22-
}
23-
24-
const queryParams = qs.stringify({
25-
client_id: clientId, // TODO: test if we need this
26-
redirect_uri: redirectUri,
27-
response_type: 'token',
28-
});
29-
3014
try {
31-
const response = await fetch(
32-
`${MY_ACCOUNT_DOMAINS[mode]}/oauth/token/info.json?${queryParams}`,
33-
{
34-
method: 'GET',
35-
headers: {
36-
Authorization: `Bearer ${token}`,
37-
},
38-
}
39-
);
15+
const response = await fetch(`${MY_ACCOUNT_DOMAINS[mode]}/oauth/token/info.json`, {
16+
method: 'GET',
17+
headers: {
18+
Authorization: `Bearer ${token}`,
19+
'x-api-key': clientId as string,
20+
},
21+
});
4022

4123
const result = await response.json();
4224

src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
InitOptions,
1616
AuthorizeOptions,
1717
ExchangeTokenOptions,
18-
TokenInfoOptions,
1918
RequestMagicLinkOptions,
2019
TokenInfo,
2120
Mode,
@@ -76,8 +75,8 @@ export class MtLinkSdk {
7675
return exchangeToken(this.storedOptions, options);
7776
}
7877

79-
public tokenInfo(token: string, options?: TokenInfoOptions): Promise<TokenInfo> {
80-
return tokenInfo(this.storedOptions, token, options);
78+
public tokenInfo(token: string): Promise<TokenInfo> {
79+
return tokenInfo(this.storedOptions, token);
8180
}
8281
}
8382

src/typings.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ export interface RequestMagicLinkOptions extends ConfigsOptions {
110110
magicLinkTo?: MagicLinkTo;
111111
}
112112

113-
export type TokenInfoOptions = Omit<Omit<OAuthSharedParams, 'state'>, 'codeVerifier'>;
114-
115113
export interface TokenInfo {
116114
guestUid: string;
117115
resourceServer: string;

0 commit comments

Comments
 (0)