@sinch/sdk-client 1.2.1 → 1.4.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 +69 -20
- package/dist/api/api-client-options-helper.d.ts +1 -0
- package/dist/api/api-client-options-helper.js +14 -1
- package/dist/api/api-client-options-helper.js.map +1 -1
- package/dist/api/api-client-options.d.ts +1 -1
- package/dist/api/api-client.d.ts +19 -9
- package/dist/api/api-client.js +19 -10
- package/dist/api/api-client.js.map +1 -1
- package/dist/api/api-errors.d.ts +2 -8
- package/dist/api/api-errors.js +2 -4
- package/dist/api/api-errors.js.map +1 -1
- package/dist/api/api-interface.d.ts +1 -4
- package/dist/api/callback-webhooks-interface.d.ts +0 -1
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.js +2 -1
- package/dist/api/index.js.map +1 -1
- package/dist/client/api-client-helpers.d.ts +2 -2
- package/dist/client/api-client-helpers.js +6 -7
- package/dist/client/api-client-helpers.js.map +1 -1
- package/dist/client/api-client-pagination-helper.js +38 -7
- package/dist/client/api-client-pagination-helper.js.map +1 -1
- package/dist/client/api-fetch-client.d.ts +22 -5
- package/dist/client/api-fetch-client.js +106 -116
- package/dist/client/api-fetch-client.js.map +1 -1
- package/dist/domain/domain-helper.d.ts +3 -1
- package/dist/domain/domain-helper.js +4 -3
- package/dist/domain/domain-helper.js.map +1 -1
- package/dist/domain/domain-interface.d.ts +25 -4
- package/dist/domain/domain-interface.js +13 -1
- package/dist/domain/domain-interface.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +3 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/withAdditionalProperties.d.ts +3 -0
- package/dist/model/withAdditionalProperties.js +3 -0
- package/dist/model/withAdditionalProperties.js.map +1 -0
- package/dist/plugins/core/response-plugin.d.ts +0 -2
- package/dist/plugins/exception/exception.response.js +2 -5
- package/dist/plugins/exception/exception.response.js.map +1 -1
- package/dist/plugins/oauth2/oauth2-token.request.d.ts +3 -0
- package/dist/plugins/oauth2/oauth2-token.request.js +19 -1
- package/dist/plugins/oauth2/oauth2-token.request.js.map +1 -1
- package/dist/plugins/version/version.request.js +17 -7
- package/dist/plugins/version/version.request.js.map +1 -1
- package/dist/utils/authorization.helper.d.ts +0 -1
- package/dist/utils/authorization.helper.js +0 -24
- package/dist/utils/authorization.helper.js.map +1 -1
- package/dist/utils/date.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -32,32 +32,82 @@ yarn add @sinch/sdk-client
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
+
### Lazy Initialization and Dependency Injection of ApiFetchClient
|
|
36
|
+
Starting from version 1.4.0, the SDK supports lazy initialization and dependency injection of the ApiFetchClient in service classes.
|
|
37
|
+
|
|
38
|
+
How it works:
|
|
39
|
+
- Lazy Initialization:
|
|
40
|
+
The ApiFetchClient is not created until the first API call is made. This reduces startup overhead and only initializes what is needed.
|
|
41
|
+
- Dependency Injection:
|
|
42
|
+
The service class (e.g., NumbersService) is responsible for creating and configuring the ApiFetchClient. This client is then injected into the API classes as needed, centralizing configuration and enabling advanced scenarios like custom plugins or test mocks.
|
|
43
|
+
|
|
44
|
+
Example:
|
|
45
|
+
```typescript
|
|
46
|
+
const numbersService = new NumbersService({
|
|
47
|
+
projectId: 'YOUR_PROJECT_ID',
|
|
48
|
+
keyId: 'YOUR_KEY_ID',
|
|
49
|
+
keySecret: 'YOUR_KEY_SECRET',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// No need to instantiate ApiFetchClient manually
|
|
53
|
+
|
|
54
|
+
// The client is created and injected automatically on the first API call
|
|
55
|
+
const numbers = await numbersService.list({});
|
|
56
|
+
|
|
57
|
+
// You can update configuration before the first call
|
|
58
|
+
numbersService.setHostname('https://custom.api.sinch.com');
|
|
59
|
+
numbersService.setCredentials({ projectId: 'NEW_PROJECT_ID' });
|
|
60
|
+
```
|
|
61
|
+
|
|
35
62
|
In this section, we'll see how to implement the `Api` interface and how to use the `ApiFetchClient` to call the API endpoint.
|
|
36
63
|
|
|
37
64
|
### Api interface
|
|
38
65
|
|
|
39
66
|
```typescript
|
|
40
|
-
export class
|
|
41
|
-
|
|
42
|
-
|
|
67
|
+
export class LazyDomainApiClient {
|
|
68
|
+
private apiFetchClient?: ApiFetchClient;
|
|
69
|
+
constructor(public sharedConfig: SinchClientParameters) {}
|
|
43
70
|
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
public getApiClient(): ApiFetchClient {
|
|
72
|
+
if (!this.apiFetchClient) {
|
|
73
|
+
// Create the ApiFetchClient only when it's needed
|
|
46
74
|
}
|
|
75
|
+
return this.apiFetchClient;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
47
78
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
export class ExampleDomainApi implements Api {
|
|
80
|
+
constructor(
|
|
81
|
+
public readonly lazyClient: LazyDomainApiClient,
|
|
82
|
+
public readonly apiName: string,
|
|
83
|
+
) {}
|
|
84
|
+
|
|
85
|
+
public get client(): ApiClient {
|
|
86
|
+
return this.lazyClient.getApiClient();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
export class MyExampleApi extends ExampleDomainApi {
|
|
92
|
+
|
|
93
|
+
constructor(lazyApiClient: LazyDomainApiClient) {
|
|
94
|
+
super(lazyApiClient, 'MyExampleApi');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public async myApiOperation(): Promise<Response> {
|
|
98
|
+
// Define the API endpoint
|
|
99
|
+
const url = `${this.client.apiClientOptions.hostname}/myDomain`;
|
|
100
|
+
// Build the request options: you can use the method 'prepareOptions' from the apiClient
|
|
101
|
+
// that will apply the request plugins onto the default built options
|
|
102
|
+
const requestOptions: RequestOptions = await this.client.prepareOptions(...);
|
|
103
|
+
// Send the request and apply the response plugins
|
|
104
|
+
return this.client.processCall<Response>({
|
|
105
|
+
url,
|
|
106
|
+
requestOptions,
|
|
107
|
+
apiName: this.apiName,
|
|
108
|
+
operationId: 'myApiOperation',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
61
111
|
}
|
|
62
112
|
```
|
|
63
113
|
|
|
@@ -81,13 +131,12 @@ const apiClient = new ApiFetchClient(apiClientOptions);
|
|
|
81
131
|
|
|
82
132
|
```typescript
|
|
83
133
|
// Once the API Client is intantiated, it can be given as a parameter to your API
|
|
84
|
-
const myApi = new MyExampleApi(
|
|
134
|
+
const myApi = new MyExampleApi(lazyApiClient);
|
|
85
135
|
|
|
86
136
|
// The API operations can now be invoked
|
|
87
137
|
const myResponse = await myApi.myApiOperation();
|
|
88
138
|
```
|
|
89
139
|
|
|
90
|
-
|
|
91
140
|
## Plugins
|
|
92
141
|
|
|
93
142
|
### Request plugins
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SinchClientParameters } from '../domain';
|
|
2
2
|
import { ApiClientOptions } from './api-client-options';
|
|
3
3
|
export declare const buildOAuth2ApiClientOptions: (params: SinchClientParameters, apiName: string) => ApiClientOptions;
|
|
4
|
+
export declare const buildMailgunApiClientOptions: (params: SinchClientParameters) => ApiClientOptions;
|
|
4
5
|
export declare const buildApplicationSignedApiClientOptions: (params: SinchClientParameters, apiName: string) => ApiClientOptions;
|
|
5
6
|
export declare const buildFlexibleOAuth2OrApiTokenApiClientOptions: (params: SinchClientParameters) => ApiClientOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildFlexibleOAuth2OrApiTokenApiClientOptions = exports.buildApplicationSignedApiClientOptions = exports.buildOAuth2ApiClientOptions = void 0;
|
|
3
|
+
exports.buildFlexibleOAuth2OrApiTokenApiClientOptions = exports.buildApplicationSignedApiClientOptions = exports.buildMailgunApiClientOptions = exports.buildOAuth2ApiClientOptions = void 0;
|
|
4
4
|
const plugins_1 = require("../plugins");
|
|
5
5
|
const buildOAuth2ApiClientOptions = (params, apiName) => {
|
|
6
6
|
if (!params.projectId || !params.keyId || !params.keySecret) {
|
|
@@ -15,6 +15,19 @@ const buildOAuth2ApiClientOptions = (params, apiName) => {
|
|
|
15
15
|
return apiClientOptions;
|
|
16
16
|
};
|
|
17
17
|
exports.buildOAuth2ApiClientOptions = buildOAuth2ApiClientOptions;
|
|
18
|
+
const buildMailgunApiClientOptions = (params) => {
|
|
19
|
+
if (!params.mailgunApiKey) {
|
|
20
|
+
throw new Error('Invalid configuration for the Mailgun API: the "mailgunApiKey" must be provided');
|
|
21
|
+
}
|
|
22
|
+
const apiClientOptions = {
|
|
23
|
+
requestPlugins: [
|
|
24
|
+
new plugins_1.BasicAuthenticationRequest('api', params.mailgunApiKey),
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
addPlugins(apiClientOptions, params);
|
|
28
|
+
return apiClientOptions;
|
|
29
|
+
};
|
|
30
|
+
exports.buildMailgunApiClientOptions = buildMailgunApiClientOptions;
|
|
18
31
|
const buildApplicationSignedApiClientOptions = (params, apiName) => {
|
|
19
32
|
if (!params.applicationKey || !params.applicationSecret) {
|
|
20
33
|
throw new Error(`Invalid configuration for the ${apiName} API: "applicationKey" and "applicationSecret" values must be provided`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client-options-helper.js","sourceRoot":"","sources":["../../src/api/api-client-options-helper.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"api-client-options-helper.js","sourceRoot":"","sources":["../../src/api/api-client-options-helper.ts"],"names":[],"mappings":";;;AAEA,wCAMoB;AAEb,MAAM,2BAA2B,GAAG,CAAC,MAA6B,EAAE,OAAe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CAAC,CAAC;AAxBW,QAAA,6CAA6C,iDAwBxD;AAEF,MAAM,UAAU,GAAG,CAAC,gBAAkC,EAAE,MAA6B,EAAE,EAAE;IACvF,IAAI,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,IAAI,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC;YACrC,gBAAgB,CAAC,cAAc,GAAG,EAAE,CAAC;QACvC,CAAC;QACD,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChE,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,CAAC;YACtC,gBAAgB,CAAC,eAAe,GAAG,EAAE,CAAC;QACxC,CAAC;QACD,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { ResponsePlugin } from '../plugins/core/response-plugin';
|
|
|
3
3
|
interface BaseApiClientOptions {
|
|
4
4
|
/**
|
|
5
5
|
* ID of the umbrella project containing the access keys
|
|
6
|
-
* Found on your
|
|
6
|
+
* Found on your [Sinch Customer Dashboard](https://dashboard.sinch.com/settings/project-management).
|
|
7
7
|
*/
|
|
8
8
|
projectId: string;
|
|
9
9
|
/** Hostname of the API server */
|
package/dist/api/api-client.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { RequestBody, RequestOptions } from '../plugins/core/request-plugin';
|
|
3
2
|
import { ApiClientOptions } from './api-client-options';
|
|
4
3
|
export declare enum PaginationEnum {
|
|
@@ -55,13 +54,18 @@ export interface FileBuffer {
|
|
|
55
54
|
/** File content as Buffer */
|
|
56
55
|
buffer: Buffer;
|
|
57
56
|
}
|
|
57
|
+
export interface CSVFile {
|
|
58
|
+
/** Name of the file extracted from the 'content-disposition' header */
|
|
59
|
+
fileName: string;
|
|
60
|
+
/** File content as string */
|
|
61
|
+
data: string;
|
|
62
|
+
}
|
|
58
63
|
/**
|
|
59
64
|
* API Client used to call the server
|
|
60
65
|
*/
|
|
61
66
|
export declare class ApiClient {
|
|
62
|
-
/** Options for the API */
|
|
63
67
|
apiClientOptions: ApiClientOptions;
|
|
64
|
-
constructor(
|
|
68
|
+
constructor(apiClientOptions: ApiClientOptions);
|
|
65
69
|
/**
|
|
66
70
|
* Returns a map containing the query parameters based on the provided data and names.
|
|
67
71
|
*
|
|
@@ -112,7 +116,7 @@ export declare class ApiClient {
|
|
|
112
116
|
/**
|
|
113
117
|
* Process HTTP call
|
|
114
118
|
* @abstract
|
|
115
|
-
* @template T
|
|
119
|
+
* @template T - The type of the response object expected from the API call.
|
|
116
120
|
* @param {ApiCallParameters} _httpCallParameters - Parameters for the HTTP call.
|
|
117
121
|
* @return {Promise<T>} A promise that resolves to the result of the HTTP call.
|
|
118
122
|
*/
|
|
@@ -120,17 +124,23 @@ export declare class ApiClient {
|
|
|
120
124
|
/**
|
|
121
125
|
* Process HTTP call with Pagination
|
|
122
126
|
* @abstract
|
|
123
|
-
* @template T
|
|
127
|
+
* @template T - The type of the response object expected in a page from the API call.
|
|
124
128
|
* @param {ApiCallParametersWithPagination} _httpCallParameters - Parameters for the HTTP call.
|
|
125
|
-
* @return {Promise<T
|
|
129
|
+
* @return {Promise<PageResult<T>>} A promise that resolves to the result of the HTTP call.
|
|
126
130
|
*/
|
|
127
131
|
processCallWithPagination<T>(_httpCallParameters: ApiCallParametersWithPagination): Promise<PageResult<T>>;
|
|
128
132
|
/**
|
|
129
|
-
* Process HTTP call to download a PDF file
|
|
133
|
+
* Process HTTP call to download a PDF file as file buffer
|
|
130
134
|
* @abstract
|
|
131
|
-
* @template T
|
|
132
135
|
* @param {ApiCallParameters} _httpCallParameters - Parameters for the HTTP call.
|
|
133
|
-
* @return {Promise<
|
|
136
|
+
* @return {Promise<FileBuffer>} A promise that resolves to the result of the HTTP call.
|
|
134
137
|
*/
|
|
135
138
|
processFileCall(_httpCallParameters: ApiCallParameters): Promise<FileBuffer>;
|
|
139
|
+
/**
|
|
140
|
+
* Process HTTP call to download a CSV file as plain text
|
|
141
|
+
* @abstract
|
|
142
|
+
* @param {ApiCallParameters} _httpCallParameters - Parameters for the HTTP call.
|
|
143
|
+
* @return {Promise<CSVFile>} A promise that resolves to the result of the HTTP call.
|
|
144
|
+
*/
|
|
145
|
+
processCsvCall(_httpCallParameters: ApiCallParameters): Promise<CSVFile>;
|
|
136
146
|
}
|
package/dist/api/api-client.js
CHANGED
|
@@ -20,7 +20,8 @@ var PaginationEnum;
|
|
|
20
20
|
* API Client used to call the server
|
|
21
21
|
*/
|
|
22
22
|
class ApiClient {
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(apiClientOptions) {
|
|
24
|
+
this.apiClientOptions = apiClientOptions;
|
|
24
25
|
/**
|
|
25
26
|
*
|
|
26
27
|
* @param {string} name - The parameter name
|
|
@@ -42,7 +43,6 @@ class ApiClient {
|
|
|
42
43
|
return `${name}=${parameterValue}`;
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
|
-
this.apiClientOptions = options;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Returns a map containing the query parameters based on the provided data and names.
|
|
@@ -110,7 +110,7 @@ class ApiClient {
|
|
|
110
110
|
/**
|
|
111
111
|
* Process HTTP call
|
|
112
112
|
* @abstract
|
|
113
|
-
* @template T
|
|
113
|
+
* @template T - The type of the response object expected from the API call.
|
|
114
114
|
* @param {ApiCallParameters} _httpCallParameters - Parameters for the HTTP call.
|
|
115
115
|
* @return {Promise<T>} A promise that resolves to the result of the HTTP call.
|
|
116
116
|
*/
|
|
@@ -121,25 +121,34 @@ class ApiClient {
|
|
|
121
121
|
/**
|
|
122
122
|
* Process HTTP call with Pagination
|
|
123
123
|
* @abstract
|
|
124
|
-
* @template T
|
|
124
|
+
* @template T - The type of the response object expected in a page from the API call.
|
|
125
125
|
* @param {ApiCallParametersWithPagination} _httpCallParameters - Parameters for the HTTP call.
|
|
126
|
-
* @return {Promise<T
|
|
126
|
+
* @return {Promise<PageResult<T>>} A promise that resolves to the result of the HTTP call.
|
|
127
127
|
*/
|
|
128
128
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
129
129
|
processCallWithPagination(_httpCallParameters) {
|
|
130
130
|
throw new Error('Abstract method must be implemented');
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* Process HTTP call to download a PDF file
|
|
133
|
+
* Process HTTP call to download a PDF file as file buffer
|
|
134
134
|
* @abstract
|
|
135
|
-
* @template T
|
|
136
135
|
* @param {ApiCallParameters} _httpCallParameters - Parameters for the HTTP call.
|
|
137
|
-
* @return {Promise<
|
|
136
|
+
* @return {Promise<FileBuffer>} A promise that resolves to the result of the HTTP call.
|
|
138
137
|
*/
|
|
139
138
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
140
139
|
processFileCall(_httpCallParameters) {
|
|
141
140
|
throw new Error('Abstract method must be implemented');
|
|
142
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Process HTTP call to download a CSV file as plain text
|
|
144
|
+
* @abstract
|
|
145
|
+
* @param {ApiCallParameters} _httpCallParameters - Parameters for the HTTP call.
|
|
146
|
+
* @return {Promise<CSVFile>} A promise that resolves to the result of the HTTP call.
|
|
147
|
+
*/
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
149
|
+
processCsvCall(_httpCallParameters) {
|
|
150
|
+
throw new Error('Abstract method must be implemented');
|
|
151
|
+
}
|
|
143
152
|
}
|
|
144
153
|
exports.ApiClient = ApiClient;
|
|
145
154
|
// ----- INTERNAL ------ \\
|
|
@@ -149,12 +158,12 @@ exports.ApiClient = ApiClient;
|
|
|
149
158
|
* @param {Object.<string, string|undefined>} object - The JSON object to filter.
|
|
150
159
|
* @return {Object.<string, string>} An object without undefined values.
|
|
151
160
|
*/
|
|
152
|
-
|
|
161
|
+
const filterUndefinedValues = (object) => {
|
|
153
162
|
return Object.keys(object)
|
|
154
163
|
.filter((objectKey) => typeof object[objectKey] !== 'undefined')
|
|
155
164
|
.reduce((acc, objectKey) => {
|
|
156
165
|
acc[objectKey] = object[objectKey];
|
|
157
166
|
return acc;
|
|
158
167
|
}, {});
|
|
159
|
-
}
|
|
168
|
+
};
|
|
160
169
|
//# sourceMappingURL=api-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/api/api-client.ts"],"names":[],"mappings":";;;AAEA,2CAAqC;AAErC,IAAY,cAYX;AAZD,WAAY,cAAc;IACxB,mDAAI,CAAA;IACJ,8BAA8B;IAC9B,qDAAK,CAAA;IACL,mCAAmC;IACnC,uDAAM,CAAA;IACN,0BAA0B;IAC1B,mDAAI,CAAA;IACJ,2CAA2C;IAC3C,qDAAK,CAAA;IACL,0BAA0B;IAC1B,qDAAK,CAAA;AACP,CAAC,EAZW,cAAc,8BAAd,cAAc,QAYzB;
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/api/api-client.ts"],"names":[],"mappings":";;;AAEA,2CAAqC;AAErC,IAAY,cAYX;AAZD,WAAY,cAAc;IACxB,mDAAI,CAAA;IACJ,8BAA8B;IAC9B,qDAAK,CAAA;IACL,mCAAmC;IACnC,uDAAM,CAAA;IACN,0BAA0B;IAC1B,mDAAI,CAAA;IACJ,2CAA2C;IAC3C,qDAAK,CAAA;IACL,0BAA0B;IAC1B,qDAAK,CAAA;AACP,CAAC,EAZW,cAAc,8BAAd,cAAc,QAYzB;AAwDD;;GAEG;AACH,MAAa,SAAS;IAEpB,YAAmB,gBAAkC;QAAlC,qBAAgB,GAAhB,gB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OAAO,GAAG,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAC5D,CAAC;IA0BD;;;;;;OAMG;IACH,6DAA6D;IAC7D,WAAW,CAAI,mBAAsC;QACnD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;OAMG;IACH,6DAA6D;IAC7D,yBAAyB,CAAI,mBAAoD;QAC/E,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACH,6DAA6D;IAC7D,eAAe,CAAC,mBAAsC;QACpD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACH,6DAA6D;IAC7D,cAAc,CAAC,mBAAsC;QACnD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;CAEF;AAhKD,8BAgKC;AAED,2BAA2B;AAC3B;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,CAC5B,MAA6C,EAG7C,EAAE;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW,CAAC;SAC/D,MAAM,CAA4B,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE;QACpD,GAAG,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,SAAS,CAAW,CAAC;QAC7C,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC,CAAC"}
|
package/dist/api/api-errors.d.ts
CHANGED
|
@@ -8,8 +8,6 @@ export interface ErrorContext {
|
|
|
8
8
|
operationId?: string;
|
|
9
9
|
/** Base URL */
|
|
10
10
|
url?: string;
|
|
11
|
-
/** Origin domain initiating the call */
|
|
12
|
-
origin?: string | null;
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
13
|
* Generic error class
|
|
@@ -35,12 +33,8 @@ export declare class RequestFailedError<T> extends GenericError {
|
|
|
35
33
|
/**
|
|
36
34
|
* Empty response error class
|
|
37
35
|
*/
|
|
38
|
-
export declare class EmptyResponseError
|
|
39
|
-
|
|
40
|
-
* Data decoded from the response body
|
|
41
|
-
*/
|
|
42
|
-
data?: string;
|
|
43
|
-
constructor(message: string, errorContext: ErrorContext, data?: T);
|
|
36
|
+
export declare class EmptyResponseError extends GenericError {
|
|
37
|
+
constructor(message: string, errorContext: ErrorContext);
|
|
44
38
|
}
|
|
45
39
|
/**
|
|
46
40
|
* Response parse error class
|
package/dist/api/api-errors.js
CHANGED
|
@@ -7,10 +7,9 @@ exports.ResponseJSONParseError = exports.EmptyResponseError = exports.RequestFai
|
|
|
7
7
|
class GenericError extends Error {
|
|
8
8
|
constructor(message, errorContext) {
|
|
9
9
|
const baseUrl = GenericError.formatUrl(errorContext.url);
|
|
10
|
-
const origin = GenericError.formatUrl(errorContext.origin);
|
|
11
10
|
super(`[SDK] [apiName: ${errorContext.apiName || 'unknown'}]
|
|
12
11
|
[operationId: ${errorContext.operationId || 'unknown'}]
|
|
13
|
-
[baseUrl: ${baseUrl}] [
|
|
12
|
+
[baseUrl: ${baseUrl}] [errorType: SDK] ${message}`);
|
|
14
13
|
}
|
|
15
14
|
static formatUrl(url) {
|
|
16
15
|
const httpRegexp = /^https?:\/\//;
|
|
@@ -33,9 +32,8 @@ exports.RequestFailedError = RequestFailedError;
|
|
|
33
32
|
* Empty response error class
|
|
34
33
|
*/
|
|
35
34
|
class EmptyResponseError extends GenericError {
|
|
36
|
-
constructor(message, errorContext
|
|
35
|
+
constructor(message, errorContext) {
|
|
37
36
|
super(`[Empty response] ${message}`, errorContext);
|
|
38
|
-
this.data = JSON.stringify(data, null, 2);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
exports.EmptyResponseError = EmptyResponseError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-errors.js","sourceRoot":"","sources":["../../src/api/api-errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"api-errors.js","sourceRoot":"","sources":["../../src/api/api-errors.ts"],"names":[],"mappings":";;;AAYA;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE,YAA0B;QACrD,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACzD,KAAK,CACH,mBAAmB,YAAY,CAAC,OAAO,IAAI,SAAS;wBAClC,YAAY,CAAC,WAAW,IAAI,SAAS;oBACzC,OAAO,sBAAsB,OAAO,EAAE,CACrD,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,SAAS,CAAC,GAA8B;QACrD,MAAM,UAAU,GAAG,cAAc,CAAC;QAClC,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC;CAEF;AAfD,oCAeC;AAED;;GAEG;AACH,MAAa,kBAAsB,SAAQ,YAAY;IAWrD,YACE,OAAe,EACf,UAAkB,EAClB,YAA0B,EAC1B,IAAQ;QAER,KAAK,CAAC,YAAY,UAAU,KAAK,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF;AArBD,gDAqBC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,YAAY;IAElD,YAAY,OAAe,EAAE,YAA0B;QACrD,KAAK,CAAC,oBAAoB,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;IACrD,CAAC;CACF;AALD,gDAKC;AAED;;GAEG;AACH,MAAa,sBAAuB,SAAQ,kBAA0B;IACpE,YACE,OAAe,EACf,UAAkB,EAClB,YAA0B,EAC1B,WAAoB;QAEpB,KAAK,CACH,+BAA+B,OAAO,EAAE,EACxC,UAAU,EACV,YAAY,EACZ,WAAW,CACZ,CAAC;IACJ,CAAC;CACF;AAdD,wDAcC"}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ApiClientOptions, } from './api-client-options';
|
|
2
|
-
export { buildOAuth2ApiClientOptions, buildApplicationSignedApiClientOptions, buildFlexibleOAuth2OrApiTokenApiClientOptions, } from './api-client-options-helper';
|
|
3
|
-
export { ApiClient, ApiListPromise, FileBuffer, PageResult, PaginatedApiProperties, PaginationEnum, } from './api-client';
|
|
2
|
+
export { buildOAuth2ApiClientOptions, buildMailgunApiClientOptions, buildApplicationSignedApiClientOptions, buildFlexibleOAuth2OrApiTokenApiClientOptions, } from './api-client-options-helper';
|
|
3
|
+
export { ApiClient, ApiListPromise, CSVFile, FileBuffer, PageResult, PaginatedApiProperties, PaginationEnum, } from './api-client';
|
|
4
4
|
export { GenericError, RequestFailedError, EmptyResponseError, ResponseJSONParseError, } from './api-errors';
|
|
5
5
|
export { Api, } from './api-interface';
|
|
6
6
|
export { CallbackProcessor, } from './callback-webhooks-interface';
|
package/dist/api/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseJSONParseError = exports.EmptyResponseError = exports.RequestFailedError = exports.GenericError = exports.PaginationEnum = exports.ApiClient = exports.buildFlexibleOAuth2OrApiTokenApiClientOptions = exports.buildApplicationSignedApiClientOptions = exports.buildOAuth2ApiClientOptions = void 0;
|
|
3
|
+
exports.ResponseJSONParseError = exports.EmptyResponseError = exports.RequestFailedError = exports.GenericError = exports.PaginationEnum = exports.ApiClient = exports.buildFlexibleOAuth2OrApiTokenApiClientOptions = exports.buildApplicationSignedApiClientOptions = exports.buildMailgunApiClientOptions = exports.buildOAuth2ApiClientOptions = void 0;
|
|
4
4
|
var api_client_options_helper_1 = require("./api-client-options-helper");
|
|
5
5
|
Object.defineProperty(exports, "buildOAuth2ApiClientOptions", { enumerable: true, get: function () { return api_client_options_helper_1.buildOAuth2ApiClientOptions; } });
|
|
6
|
+
Object.defineProperty(exports, "buildMailgunApiClientOptions", { enumerable: true, get: function () { return api_client_options_helper_1.buildMailgunApiClientOptions; } });
|
|
6
7
|
Object.defineProperty(exports, "buildApplicationSignedApiClientOptions", { enumerable: true, get: function () { return api_client_options_helper_1.buildApplicationSignedApiClientOptions; } });
|
|
7
8
|
Object.defineProperty(exports, "buildFlexibleOAuth2OrApiTokenApiClientOptions", { enumerable: true, get: function () { return api_client_options_helper_1.buildFlexibleOAuth2OrApiTokenApiClientOptions; } });
|
|
8
9
|
var api_client_1 = require("./api-client");
|
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;AAGA,yEAKqC;AAJnC,wIAAA,2BAA2B,OAAA;AAC3B,yIAAA,4BAA4B,OAAA;AAC5B,mJAAA,sCAAsC,OAAA;AACtC,0JAAA,6CAA6C,OAAA;AAE/C,2CAQsB;AAPpB,uGAAA,SAAS,OAAA;AAMT,4GAAA,cAAc,OAAA;AAEhB,2CAKsB;AAJpB,0GAAA,YAAY,OAAA;AACZ,gHAAA,kBAAkB,OAAA;AAClB,gHAAA,kBAAkB,OAAA;AAClB,oHAAA,sBAAsB,OAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RequestOptions, RequestPlugin } from '../plugins/core/request-plugin';
|
|
2
2
|
import { ApiCallParameters, ApiCallParametersWithPagination } from '../api/api-client';
|
|
3
3
|
import { ErrorContext } from '../api/api-errors';
|
|
4
|
-
export declare const manageExpiredToken: (apiCallParameters: ApiCallParameters | ApiCallParametersWithPagination, errorContext: ErrorContext, requestPlugins: RequestPlugin[] | undefined
|
|
5
|
-
export declare function buildErrorContext(apiCallParameters: ApiCallParameters
|
|
4
|
+
export declare const manageExpiredToken: (apiCallParameters: ApiCallParameters | ApiCallParametersWithPagination, errorContext: ErrorContext, requestPlugins: RequestPlugin[] | undefined) => Promise<RequestOptions>;
|
|
5
|
+
export declare function buildErrorContext(apiCallParameters: ApiCallParameters): ErrorContext;
|
|
6
6
|
export declare function invalidateAndRegenerateJwt(requestPlugins: RequestPlugin[] | undefined, options: RequestOptions, errorContext: ErrorContext): Promise<RequestOptions>;
|
|
7
7
|
/**
|
|
8
8
|
* Go through all an object's properties and transform to date the values that match the right format
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reviveDates = exports.
|
|
3
|
+
exports.reviveDates = exports.manageExpiredToken = void 0;
|
|
4
|
+
exports.buildErrorContext = buildErrorContext;
|
|
5
|
+
exports.invalidateAndRegenerateJwt = invalidateAndRegenerateJwt;
|
|
4
6
|
const request_plugin_1 = require("../plugins/core/request-plugin");
|
|
5
7
|
const api_errors_1 = require("../api/api-errors");
|
|
6
|
-
const manageExpiredToken = async (apiCallParameters, errorContext, requestPlugins
|
|
8
|
+
const manageExpiredToken = async (apiCallParameters, errorContext, requestPlugins) => {
|
|
7
9
|
// Use the circuitBreaker variable to try to regenerate a valid JWT only 3 times
|
|
8
10
|
if (!apiCallParameters.circuitBreaker) {
|
|
9
11
|
apiCallParameters.circuitBreaker = 1;
|
|
@@ -15,18 +17,16 @@ const manageExpiredToken = async (apiCallParameters, errorContext, requestPlugin
|
|
|
15
17
|
throw new api_errors_1.GenericError('Tried to generate a new JWT with no success', errorContext);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
|
-
return await invalidateAndRegenerateJwt(requestPlugins, requestOptions, errorContext);
|
|
20
|
+
return await invalidateAndRegenerateJwt(requestPlugins, apiCallParameters.requestOptions, errorContext);
|
|
19
21
|
};
|
|
20
22
|
exports.manageExpiredToken = manageExpiredToken;
|
|
21
|
-
function buildErrorContext(apiCallParameters
|
|
23
|
+
function buildErrorContext(apiCallParameters) {
|
|
22
24
|
return {
|
|
23
25
|
apiName: apiCallParameters.apiName,
|
|
24
26
|
operationId: apiCallParameters.operationId,
|
|
25
27
|
url: apiCallParameters.url,
|
|
26
|
-
origin,
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
exports.buildErrorContext = buildErrorContext;
|
|
30
30
|
async function invalidateAndRegenerateJwt(requestPlugins, options, errorContext) {
|
|
31
31
|
const oauth2Plugin = requestPlugins?.find((plugin) => plugin.getName() === request_plugin_1.RequestPluginEnum.OAUTH2_TOKEN_REQUEST);
|
|
32
32
|
if (oauth2Plugin) {
|
|
@@ -38,7 +38,6 @@ async function invalidateAndRegenerateJwt(requestPlugins, options, errorContext)
|
|
|
38
38
|
throw new api_errors_1.GenericError(errorMessage, errorContext);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
exports.invalidateAndRegenerateJwt = invalidateAndRegenerateJwt;
|
|
42
41
|
/**
|
|
43
42
|
* Go through all an object's properties and transform to date the values that match the right format
|
|
44
43
|
* @param {any} input - the response object after all the response plugins have been run
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client-helpers.js","sourceRoot":"","sources":["../../src/client/api-client-helpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"api-client-helpers.js","sourceRoot":"","sources":["../../src/client/api-client-helpers.ts"],"names":[],"mappings":";;;AA8BA,8CAQC;AAED,gEAgBC;AAxDD,mEAIwC;AAExC,kDAA+D;AAGxD,MAAM,kBAAkB,GAAG,KAAK,EACrC,iBAAsE,EACtE,YAA0B,EAC1B,cAA2C,EAClB,EAAE;I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AAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,cAAsB,EAAU,EAAE;IAC9D,6CAA6C;IAC7C,MAAM,aAAa,GAAG,kCAAkC,CAAC;IACzD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QACxC,MAAM,wBAAwB,GAAG,cAAc,CAAC;QAChD,iGAAiG;QACjG,IAAI,wBAAwB,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;YAClD,cAAc,GAAG,cAAc,GAAG,KAAK,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,cAAc,GAAG,cAAc,GAAG,GAAG,CAAC;QACxC,CAAC;IACH,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPageResultPromise = exports.
|
|
3
|
+
exports.buildPageResultPromise = exports.createNextPageMethod = exports.createIteratorMethodsForPagination = void 0;
|
|
4
|
+
exports.hasMore = hasMore;
|
|
5
|
+
exports.calculateNextPage = calculateNextPage;
|
|
6
|
+
exports.buildPaginationContext = buildPaginationContext;
|
|
4
7
|
const api_client_1 = require("../api/api-client");
|
|
5
8
|
class SinchIterator {
|
|
6
9
|
constructor(apiClient, requestOptionsPromise, firstPagePromise, context) {
|
|
@@ -42,6 +45,9 @@ class SinchIterator {
|
|
|
42
45
|
const newParams = {
|
|
43
46
|
page_token: pageResult.nextPageValue,
|
|
44
47
|
};
|
|
48
|
+
if (requestOptions.method === 'POST') {
|
|
49
|
+
return updateBodyParamsAndSendRequest(this.apiClient, newParams, requestOptions, this.paginatedOperationProperties);
|
|
50
|
+
}
|
|
45
51
|
return updateQueryParamsAndSendRequest(this.apiClient, newParams, requestOptions, this.paginatedOperationProperties);
|
|
46
52
|
}
|
|
47
53
|
if (this.paginatedOperationProperties.pagination === api_client_1.PaginationEnum.PAGE
|
|
@@ -76,6 +82,27 @@ const updateQueryParamsAndSendRequest = (apiClient, newParams, requestOptions, p
|
|
|
76
82
|
...paginatedApiProperties,
|
|
77
83
|
});
|
|
78
84
|
};
|
|
85
|
+
const updateBodyParamsAndSendRequest = (apiClient, newParams, requestOptions, paginatedApiProperties) => {
|
|
86
|
+
requestOptions.body = JSON.stringify({
|
|
87
|
+
...JSON.parse(requestOptions.body),
|
|
88
|
+
...sanitizeNewParams(newParams),
|
|
89
|
+
});
|
|
90
|
+
return apiClient.processCallWithPagination({
|
|
91
|
+
url: requestOptions.hostname,
|
|
92
|
+
requestOptions,
|
|
93
|
+
...paginatedApiProperties,
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const sanitizeNewParams = (newParams) => {
|
|
97
|
+
const sanitizedParams = {};
|
|
98
|
+
for (const key in newParams) {
|
|
99
|
+
if (newParams[key]) {
|
|
100
|
+
// Remove the quotes added by JSON.stringify to the value of the new params to avoid having pageToken: ""abc"" instead of pageToken: "abc" in the request body
|
|
101
|
+
sanitizedParams[key] = JSON.parse(newParams[key]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return sanitizedParams;
|
|
105
|
+
};
|
|
79
106
|
const createIteratorMethodsForPagination = (apiClient, requestOptionsPromise, firstPagePromise, context) => {
|
|
80
107
|
const iterator = new SinchIterator(apiClient, requestOptionsPromise, firstPagePromise, context);
|
|
81
108
|
const autoPaginationMethods = {
|
|
@@ -113,7 +140,9 @@ const createNextPageMethod = (apiClient, context, requestOptions, nextPageValue)
|
|
|
113
140
|
default:
|
|
114
141
|
throw new Error(`Error: the pagination method (${context.pagination}) is not supported`);
|
|
115
142
|
}
|
|
116
|
-
const pageResultPromise =
|
|
143
|
+
const pageResultPromise = requestOptions.method === 'POST'
|
|
144
|
+
? updateBodyParamsAndSendRequest(apiClient, newParams, requestOptions, context)
|
|
145
|
+
: updateQueryParamsAndSendRequest(apiClient, newParams, requestOptions, context);
|
|
117
146
|
const requestOptionsPromise = new Promise((resolve) => {
|
|
118
147
|
resolve(requestOptions);
|
|
119
148
|
});
|
|
@@ -140,11 +169,10 @@ function hasMore(response, context) {
|
|
|
140
169
|
return checkIfThereAreMorePages(response, pageSize, api_client_1.PaginationEnum.PAGE2);
|
|
141
170
|
}
|
|
142
171
|
if (context.pagination === api_client_1.PaginationEnum.PAGE3) {
|
|
143
|
-
return response.
|
|
172
|
+
return response.page < response.totalPages;
|
|
144
173
|
}
|
|
145
174
|
throw new Error(`The operation ${context.operationId} is not meant to be paginated.`);
|
|
146
175
|
}
|
|
147
|
-
exports.hasMore = hasMore;
|
|
148
176
|
function calculateNextPage(response, context) {
|
|
149
177
|
if (context.pagination === api_client_1.PaginationEnum.TOKEN) {
|
|
150
178
|
return response['nextPageToken'];
|
|
@@ -157,14 +185,18 @@ function calculateNextPage(response, context) {
|
|
|
157
185
|
const nextPage = currentPage + 1;
|
|
158
186
|
return nextPage.toString();
|
|
159
187
|
}
|
|
160
|
-
if (context.pagination === api_client_1.PaginationEnum.PAGE2
|
|
188
|
+
if (context.pagination === api_client_1.PaginationEnum.PAGE2) {
|
|
161
189
|
const currentPage = response.pageNumber || 1;
|
|
162
190
|
const nextPage = currentPage + 1;
|
|
163
191
|
return nextPage.toString();
|
|
164
192
|
}
|
|
193
|
+
if (context.pagination === api_client_1.PaginationEnum.PAGE3) {
|
|
194
|
+
const currentPage = response.page || 1;
|
|
195
|
+
const nextPage = currentPage + 1;
|
|
196
|
+
return nextPage.toString();
|
|
197
|
+
}
|
|
165
198
|
throw new Error(`The operation ${context.operationId} is not meant to be paginated.`);
|
|
166
199
|
}
|
|
167
|
-
exports.calculateNextPage = calculateNextPage;
|
|
168
200
|
function buildPaginationContext(props) {
|
|
169
201
|
return {
|
|
170
202
|
pagination: props.pagination,
|
|
@@ -174,7 +206,6 @@ function buildPaginationContext(props) {
|
|
|
174
206
|
requestOptions: props.requestOptions,
|
|
175
207
|
};
|
|
176
208
|
}
|
|
177
|
-
exports.buildPaginationContext = buildPaginationContext;
|
|
178
209
|
const buildPageResultPromise = async (client, requestOptionsPromise, operationProperties, repeatParamArray) => {
|
|
179
210
|
// Await the promise in this async method and store the result in client so that they can be reused
|
|
180
211
|
const requestOptions = await requestOptionsPromise;
|