@sp-api-sdk/services-api-v1 1.7.3 → 1.8.0

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
@@ -64,6 +64,29 @@ const client = new ServicesApiClient({
64
64
 
65
65
  The rate limits used for each route are specified in the [API documentation](https://developer-docs.amazon.com/sp-api/docs).
66
66
 
67
+ ## Logging
68
+
69
+ You can enable logging for both SP-API requests and responses by configuring the `logging.request` and `logging.response` properties.
70
+
71
+ ```javascript
72
+ const client = new ServicesApiClient({
73
+ auth,
74
+ region: 'eu',
75
+ logging: {
76
+ request: {
77
+ logger: console.debug
78
+ },
79
+ response: {
80
+ logger: console.debug
81
+ }
82
+ },
83
+ })
84
+ ```
85
+
86
+ Specifying `true` will use the default options, specifying an object will allow you to override the default options.
87
+ This uses [axios-logger](https://github.com/hg-pyun/axios-logger) under the hood.
88
+
89
+
67
90
  ## License
68
91
 
69
92
  MIT
package/dist/cjs/index.js CHANGED
@@ -2,5 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./src/client"), exports);
5
- tslib_1.__exportStar(require("./src/error"), exports);
6
5
  tslib_1.__exportStar(require("./src/api-model/models"), exports);
@@ -1,68 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServicesApiClient = exports.clientRateLimits = void 0;
4
- /* eslint-disable prefer-regex-literals */
5
4
  const common_1 = require("@sp-api-sdk/common");
6
5
  const api_model_1 = require("./api-model");
7
- const error_1 = require("./error");
8
6
  exports.clientRateLimits = [
9
7
  {
10
8
  method: 'get',
9
+ // eslint-disable-next-line prefer-regex-literals
11
10
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*$'),
12
11
  rate: 20,
13
12
  burst: 40,
14
13
  },
15
14
  {
16
15
  method: 'put',
16
+ // eslint-disable-next-line prefer-regex-literals
17
17
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*/cancellations$'),
18
18
  rate: 5,
19
19
  burst: 20,
20
20
  },
21
21
  {
22
22
  method: 'put',
23
+ // eslint-disable-next-line prefer-regex-literals
23
24
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*/completions$'),
24
25
  rate: 5,
25
26
  burst: 20,
26
27
  },
27
28
  {
28
29
  method: 'get',
30
+ // eslint-disable-next-line prefer-regex-literals
29
31
  urlRegex: new RegExp('^/service/v1/serviceJobs$'),
30
32
  rate: 10,
31
33
  burst: 40,
32
34
  },
33
35
  {
34
36
  method: 'post',
37
+ // eslint-disable-next-line prefer-regex-literals
35
38
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*/appointments$'),
36
39
  rate: 5,
37
40
  burst: 20,
38
41
  },
39
42
  {
40
43
  method: 'post',
44
+ // eslint-disable-next-line prefer-regex-literals
41
45
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*$'),
42
46
  rate: 5,
43
47
  burst: 20,
44
48
  },
45
49
  ];
46
50
  class ServicesApiClient extends api_model_1.ServiceApi {
47
- constructor(parameters) {
48
- const config = common_1.sellingPartnerRegions[parameters.region];
49
- if (!config) {
50
- throw new error_1.ServicesApiError(`Unknown region: ${parameters.region}`);
51
- }
52
- const { rateLimiting, ...clientParameters } = parameters;
53
- const axiosParameters = {
54
- ...clientParameters,
55
- region: config.awsRegion,
56
- };
57
- if (rateLimiting?.retry) {
58
- axiosParameters.rateLimits = exports.clientRateLimits;
59
- axiosParameters.onRetry = rateLimiting.onRetry;
60
- }
61
- const axiosInstance = (0, common_1.createAxiosInstance)(axiosParameters);
62
- const configuration = new api_model_1.Configuration();
63
- const environment = parameters.sandbox ? 'sandbox' : 'production';
64
- const endpoint = config.endpoints[environment];
65
- super(configuration, endpoint, axiosInstance);
51
+ constructor(configuration) {
52
+ const { axios, endpoint } = (0, common_1.createAxiosInstance)(configuration, exports.clientRateLimits);
53
+ super(new api_model_1.Configuration(), endpoint, axios);
66
54
  }
67
55
  }
68
56
  exports.ServicesApiClient = ServicesApiClient;
package/dist/es/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './src/client';
2
- export * from './src/error';
3
2
  export * from './src/api-model/models';
@@ -1,64 +1,52 @@
1
- /* eslint-disable prefer-regex-literals */
2
- import { sellingPartnerRegions, createAxiosInstance } from '@sp-api-sdk/common';
1
+ import { createAxiosInstance } from '@sp-api-sdk/common';
3
2
  import { Configuration, ServiceApi } from './api-model';
4
- import { ServicesApiError } from './error';
5
3
  export const clientRateLimits = [
6
4
  {
7
5
  method: 'get',
6
+ // eslint-disable-next-line prefer-regex-literals
8
7
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*$'),
9
8
  rate: 20,
10
9
  burst: 40,
11
10
  },
12
11
  {
13
12
  method: 'put',
13
+ // eslint-disable-next-line prefer-regex-literals
14
14
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*/cancellations$'),
15
15
  rate: 5,
16
16
  burst: 20,
17
17
  },
18
18
  {
19
19
  method: 'put',
20
+ // eslint-disable-next-line prefer-regex-literals
20
21
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*/completions$'),
21
22
  rate: 5,
22
23
  burst: 20,
23
24
  },
24
25
  {
25
26
  method: 'get',
27
+ // eslint-disable-next-line prefer-regex-literals
26
28
  urlRegex: new RegExp('^/service/v1/serviceJobs$'),
27
29
  rate: 10,
28
30
  burst: 40,
29
31
  },
30
32
  {
31
33
  method: 'post',
34
+ // eslint-disable-next-line prefer-regex-literals
32
35
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*/appointments$'),
33
36
  rate: 5,
34
37
  burst: 20,
35
38
  },
36
39
  {
37
40
  method: 'post',
41
+ // eslint-disable-next-line prefer-regex-literals
38
42
  urlRegex: new RegExp('^/service/v1/serviceJobs/[^/]*$'),
39
43
  rate: 5,
40
44
  burst: 20,
41
45
  },
42
46
  ];
43
47
  export class ServicesApiClient extends ServiceApi {
44
- constructor(parameters) {
45
- const config = sellingPartnerRegions[parameters.region];
46
- if (!config) {
47
- throw new ServicesApiError(`Unknown region: ${parameters.region}`);
48
- }
49
- const { rateLimiting, ...clientParameters } = parameters;
50
- const axiosParameters = {
51
- ...clientParameters,
52
- region: config.awsRegion,
53
- };
54
- if (rateLimiting?.retry) {
55
- axiosParameters.rateLimits = clientRateLimits;
56
- axiosParameters.onRetry = rateLimiting.onRetry;
57
- }
58
- const axiosInstance = createAxiosInstance(axiosParameters);
59
- const configuration = new Configuration();
60
- const environment = parameters.sandbox ? 'sandbox' : 'production';
61
- const endpoint = config.endpoints[environment];
62
- super(configuration, endpoint, axiosInstance);
48
+ constructor(configuration) {
49
+ const { axios, endpoint } = createAxiosInstance(configuration, clientRateLimits);
50
+ super(new Configuration(), endpoint, axios);
63
51
  }
64
52
  }
@@ -1,3 +1,2 @@
1
1
  export * from './src/client';
2
- export * from './src/error';
3
2
  export * from './src/api-model/models';
@@ -1,13 +1,6 @@
1
- import type { ClientConfiguration, SellingPartnerRegion, RateLimit, OnRetryHandler } from '@sp-api-sdk/common';
1
+ import { type ClientConfiguration, type RateLimit } from '@sp-api-sdk/common';
2
2
  import { ServiceApi } from './api-model';
3
3
  export declare const clientRateLimits: RateLimit[];
4
- export interface ClientParameters extends Omit<ClientConfiguration, 'rateLimits' | 'onRetry'> {
5
- region: SellingPartnerRegion;
6
- rateLimiting?: {
7
- retry: boolean;
8
- onRetry?: OnRetryHandler;
9
- };
10
- }
11
4
  export declare class ServicesApiClient extends ServiceApi {
12
- constructor(parameters: ClientParameters);
5
+ constructor(configuration: ClientConfiguration);
13
6
  }
package/package.json CHANGED
@@ -2,10 +2,11 @@
2
2
  "name": "@sp-api-sdk/services-api-v1",
3
3
  "author": "Vincent Mesquita <vincent.mesquita@bizon.solutions>",
4
4
  "description": "With the Services API, you can build applications that help service providers get and modify their service orders.",
5
- "version": "1.7.3",
5
+ "version": "1.8.0",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/es/index.js",
8
8
  "types": "dist/types/index.d.ts",
9
+ "typedocMain": "./index.ts",
9
10
  "license": "MIT",
10
11
  "publishConfig": {
11
12
  "access": "public"
@@ -26,8 +27,8 @@
26
27
  "test": "NODE_ENV='test' yarn jest"
27
28
  },
28
29
  "dependencies": {
29
- "@sp-api-sdk/auth": "^1.9.12",
30
- "@sp-api-sdk/common": "^1.7.14",
30
+ "@sp-api-sdk/auth": "^1.9.13",
31
+ "@sp-api-sdk/common": "^1.8.0",
31
32
  "axios": "^0.27.2"
32
33
  },
33
34
  "repository": {
@@ -49,5 +50,5 @@
49
50
  "sp sdk",
50
51
  "services api"
51
52
  ],
52
- "gitHead": "e6a6c9da0de5a001da60b1d3f34a3796a3adab0d"
53
+ "gitHead": "975705017de9384bf28b85e97d93f866d4d71611"
53
54
  }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServicesApiError = void 0;
4
- class ServicesApiError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = 'ServicesApiError';
8
- }
9
- }
10
- exports.ServicesApiError = ServicesApiError;
@@ -1,6 +0,0 @@
1
- export class ServicesApiError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'ServicesApiError';
5
- }
6
- }
@@ -1,3 +0,0 @@
1
- export declare class ServicesApiError extends Error {
2
- constructor(message: string);
3
- }