@sp-api-sdk/tokens-api-2021-03-01 1.8.2 → 1.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -4,6 +4,15 @@ The Selling Partner API for Tokens provides a secure way to access a customer's
|
|
|
4
4
|
|
|
5
5
|
For more information, see the [Tokens API Use Case Guide](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/tokens-api-use-case-guide/tokens-API-use-case-guide-2021-03-01.md).
|
|
6
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/@sp-api-sdk/tokens-api-2021-03-01)
|
|
8
|
+
[](https://github.com/xojs/xo)
|
|
9
|
+
|
|
10
|
+
## Documentation
|
|
11
|
+
|
|
12
|
+
Learn more about this Selling Partner API by visiting the [official documentation](https://github.com/amzn/selling-partner-api-docs/tree/main/references/tokens-api/tokens_2021-03-01.md).
|
|
13
|
+
|
|
14
|
+
Also, see the [generated documentation](https://bizon.github.io/selling-partner-api-sdk/modules/_sp_api_sdk_tokens_api_2021_03_01.html) for this API client.
|
|
15
|
+
|
|
7
16
|
## Installing
|
|
8
17
|
|
|
9
18
|
```sh
|
|
@@ -21,26 +30,25 @@ import {SellingPartnerApiAuth} from '@sp-api-sdk/auth'
|
|
|
21
30
|
import {TokensApiClient} from '@sp-api-sdk/tokens-api-2021-03-01'
|
|
22
31
|
|
|
23
32
|
const auth = new SellingPartnerApiAuth({
|
|
24
|
-
clientId:
|
|
25
|
-
clientSecret:
|
|
26
|
-
refreshToken: '',
|
|
27
|
-
secretAccessKey: '',
|
|
33
|
+
clientId: process.env.LWA_CLIENT_ID,
|
|
34
|
+
clientSecret: process.env.LWA_CLIENT_SECRET,
|
|
35
|
+
refreshToken: 'Atzr|…',
|
|
28
36
|
accessKeyId: '',
|
|
29
|
-
|
|
37
|
+
secretAccessKey: '',
|
|
30
38
|
role: {
|
|
31
|
-
arn: '',
|
|
32
|
-
}
|
|
39
|
+
arn: 'arn:aws:iam::…',
|
|
40
|
+
},
|
|
33
41
|
})
|
|
34
42
|
|
|
35
43
|
const client = new TokensApiClient({
|
|
36
44
|
auth,
|
|
37
|
-
region: 'eu'
|
|
45
|
+
region: 'eu',
|
|
38
46
|
})
|
|
39
47
|
```
|
|
40
48
|
|
|
41
|
-
##
|
|
49
|
+
## Rate Limiting
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
In order to retry rate limited requests (HTTP 429), you can configure the API client as such:
|
|
44
52
|
|
|
45
53
|
```javascript
|
|
46
54
|
const client = new TokensApiClient({
|
|
@@ -48,13 +56,28 @@ const client = new TokensApiClient({
|
|
|
48
56
|
region: 'eu',
|
|
49
57
|
rateLimiting: {
|
|
50
58
|
retry: true,
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
// Optionally specify a callback that will be called on every retry.
|
|
60
|
+
onRetry: (retryInfo) => {
|
|
61
|
+
console.log(retryInfo)
|
|
62
|
+
},
|
|
63
|
+
},
|
|
53
64
|
})
|
|
54
65
|
```
|
|
55
66
|
|
|
56
|
-
The
|
|
67
|
+
The rate limits used for each route are specified in the [API documentation]((https://github.com/amzn/selling-partner-api-docs/tree/main/references/tokens-api/tokens_2021-03-01.md)).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
|
57
72
|
|
|
58
|
-
##
|
|
73
|
+
## Miscellaneous
|
|
59
74
|
|
|
60
|
-
|
|
75
|
+
```
|
|
76
|
+
╚⊙ ⊙╝
|
|
77
|
+
╚═(███)═╝
|
|
78
|
+
╚═(███)═╝
|
|
79
|
+
╚═(███)═╝
|
|
80
|
+
╚═(███)═╝
|
|
81
|
+
╚═(███)═╝
|
|
82
|
+
╚═(███)═╝
|
|
83
|
+
```
|
package/dist/cjs/src/client.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokensApiClient = exports.
|
|
3
|
+
exports.TokensApiClient = exports.clientRateLimits = void 0;
|
|
4
4
|
/* eslint-disable prefer-regex-literals */
|
|
5
5
|
const common_1 = require("@sp-api-sdk/common");
|
|
6
6
|
const api_model_1 = require("./api-model");
|
|
7
7
|
const error_1 = require("./error");
|
|
8
|
-
exports.
|
|
8
|
+
exports.clientRateLimits = [
|
|
9
9
|
{
|
|
10
10
|
method: 'post',
|
|
11
11
|
urlRegex: new RegExp('^/tokens/2021-03-01/restrictedDataToken$'),
|
|
@@ -15,20 +15,23 @@ exports.RATE_LIMITS = [
|
|
|
15
15
|
];
|
|
16
16
|
class TokensApiClient extends api_model_1.TokensApi {
|
|
17
17
|
constructor(parameters) {
|
|
18
|
-
const
|
|
18
|
+
const config = common_1.sellingPartnerRegions[parameters.region];
|
|
19
|
+
if (!config) {
|
|
20
|
+
throw new error_1.TokensApiError(`Unknown region: ${parameters.region}`);
|
|
21
|
+
}
|
|
19
22
|
const { rateLimiting, ...clientParameters } = parameters;
|
|
20
|
-
const axiosParameters = {
|
|
23
|
+
const axiosParameters = {
|
|
24
|
+
...clientParameters,
|
|
25
|
+
region: config.awsRegion,
|
|
26
|
+
};
|
|
21
27
|
if (rateLimiting?.retry) {
|
|
22
|
-
axiosParameters.rateLimits = exports.
|
|
28
|
+
axiosParameters.rateLimits = exports.clientRateLimits;
|
|
23
29
|
axiosParameters.onRetry = rateLimiting.onRetry;
|
|
24
30
|
}
|
|
25
31
|
const axiosInstance = (0, common_1.createAxiosInstance)(axiosParameters);
|
|
26
32
|
const configuration = new api_model_1.Configuration();
|
|
27
33
|
const environment = parameters.sandbox ? 'sandbox' : 'production';
|
|
28
|
-
const endpoint =
|
|
29
|
-
if (!endpoint) {
|
|
30
|
-
throw new error_1.TokensApiError(`Unknown region : ${region}`);
|
|
31
|
-
}
|
|
34
|
+
const endpoint = config.endpoints[environment];
|
|
32
35
|
super(configuration, endpoint, axiosInstance);
|
|
33
36
|
}
|
|
34
37
|
}
|
package/dist/es/src/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable prefer-regex-literals */
|
|
2
|
-
import {
|
|
2
|
+
import { sellingPartnerRegions, createAxiosInstance } from '@sp-api-sdk/common';
|
|
3
3
|
import { Configuration, TokensApi } from './api-model';
|
|
4
4
|
import { TokensApiError } from './error';
|
|
5
|
-
export const
|
|
5
|
+
export const clientRateLimits = [
|
|
6
6
|
{
|
|
7
7
|
method: 'post',
|
|
8
8
|
urlRegex: new RegExp('^/tokens/2021-03-01/restrictedDataToken$'),
|
|
@@ -12,20 +12,23 @@ export const RATE_LIMITS = [
|
|
|
12
12
|
];
|
|
13
13
|
export class TokensApiClient extends TokensApi {
|
|
14
14
|
constructor(parameters) {
|
|
15
|
-
const
|
|
15
|
+
const config = sellingPartnerRegions[parameters.region];
|
|
16
|
+
if (!config) {
|
|
17
|
+
throw new TokensApiError(`Unknown region: ${parameters.region}`);
|
|
18
|
+
}
|
|
16
19
|
const { rateLimiting, ...clientParameters } = parameters;
|
|
17
|
-
const axiosParameters = {
|
|
20
|
+
const axiosParameters = {
|
|
21
|
+
...clientParameters,
|
|
22
|
+
region: config.awsRegion,
|
|
23
|
+
};
|
|
18
24
|
if (rateLimiting?.retry) {
|
|
19
|
-
axiosParameters.rateLimits =
|
|
25
|
+
axiosParameters.rateLimits = clientRateLimits;
|
|
20
26
|
axiosParameters.onRetry = rateLimiting.onRetry;
|
|
21
27
|
}
|
|
22
28
|
const axiosInstance = createAxiosInstance(axiosParameters);
|
|
23
29
|
const configuration = new Configuration();
|
|
24
30
|
const environment = parameters.sandbox ? 'sandbox' : 'production';
|
|
25
|
-
const endpoint = endpoints[environment]
|
|
26
|
-
if (!endpoint) {
|
|
27
|
-
throw new TokensApiError(`Unknown region : ${region}`);
|
|
28
|
-
}
|
|
31
|
+
const endpoint = config.endpoints[environment];
|
|
29
32
|
super(configuration, endpoint, axiosInstance);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -80,5 +80,5 @@ export declare class TokensApi extends BaseAPI {
|
|
|
80
80
|
* @throws {RequiredError}
|
|
81
81
|
* @memberof TokensApi
|
|
82
82
|
*/
|
|
83
|
-
createRestrictedDataToken(requestParameters: TokensApiCreateRestrictedDataTokenRequest, options?: any): Promise<import("axios").AxiosResponse<CreateRestrictedDataTokenResponse>>;
|
|
83
|
+
createRestrictedDataToken(requestParameters: TokensApiCreateRestrictedDataTokenRequest, options?: any): Promise<import("axios").AxiosResponse<CreateRestrictedDataTokenResponse, any>>;
|
|
84
84
|
}
|
|
@@ -62,4 +62,4 @@ export declare const toPathString: (url: URL) => string;
|
|
|
62
62
|
*
|
|
63
63
|
* @export
|
|
64
64
|
*/
|
|
65
|
-
export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration | undefined) => (axios?: AxiosInstance, basePath?: string) => Promise<import("axios").AxiosResponse<any>>;
|
|
65
|
+
export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration | undefined) => (axios?: AxiosInstance, basePath?: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { ClientConfiguration, RateLimit } from '@sp-api-sdk/common';
|
|
1
|
+
import type { ClientConfiguration, SellingPartnerRegion, RateLimit, OnRetryHandler } from '@sp-api-sdk/common';
|
|
3
2
|
import { TokensApi } from './api-model';
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const clientRateLimits: RateLimit[];
|
|
5
4
|
export interface ClientParameters extends Omit<ClientConfiguration, 'rateLimits' | 'onRetry'> {
|
|
5
|
+
region: SellingPartnerRegion;
|
|
6
6
|
rateLimiting?: {
|
|
7
7
|
retry: boolean;
|
|
8
|
-
onRetry?:
|
|
8
|
+
onRetry?: OnRetryHandler;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
export declare class TokensApiClient extends TokensApi {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@sp-api-sdk/tokens-api-2021-03-01",
|
|
3
3
|
"author": "Vincent Mesquita <vincent.mesquita@bizon.solutions>",
|
|
4
4
|
"description": "The Selling Partner API for Tokens provides a secure way to access a customer's PII (Personally Identifiable Information). You can call the Tokens API to get a Restricted Data Token (RDT) for one or more restricted resources that you specify. The RDT authorizes subsequent calls to restricted operations that correspond to the restricted resources that you specified. For more information, see the Tokens API Use Case Guide.",
|
|
5
|
-
"version": "1.8.
|
|
5
|
+
"version": "1.8.6",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"module": "dist/es/index.js",
|
|
8
8
|
"types": "dist/types/index.d.ts",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"test": "NODE_ENV='test' yarn jest"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sp-api-sdk/auth": "^1.9.
|
|
29
|
-
"@sp-api-sdk/common": "^1.7.
|
|
30
|
-
"axios": "^0.
|
|
28
|
+
"@sp-api-sdk/auth": "^1.9.6",
|
|
29
|
+
"@sp-api-sdk/common": "^1.7.8",
|
|
30
|
+
"axios": "^0.24.0"
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"sp sdk",
|
|
49
49
|
"tokens api"
|
|
50
50
|
],
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "f21b5cb511abd110bf1f07843558719993f36187"
|
|
52
52
|
}
|