@commercetools/ts-client 0.0.0-beta.8 → 1.0.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/CHANGELOG.md +24 -0
- package/LICENSE +1 -1
- package/dist/commercetools-ts-client.browser.cjs.js +445 -348
- package/dist/commercetools-ts-client.browser.esm.js +443 -347
- package/dist/commercetools-ts-client.cjs.dev.js +445 -348
- package/dist/commercetools-ts-client.cjs.prod.js +445 -348
- package/dist/commercetools-ts-client.esm.js +443 -347
- package/dist/declarations/src/client/builder.d.ts +1 -3
- package/dist/declarations/src/client/client.d.ts +2 -5
- package/dist/declarations/src/middleware/index.d.ts +0 -1
- package/dist/declarations/src/types/types.d.ts +18 -20
- package/dist/declarations/src/utils/createError.d.ts +8 -0
- package/dist/declarations/src/utils/errors.d.ts +10 -0
- package/dist/declarations/src/utils/executor.d.ts +1 -1
- package/dist/declarations/src/utils/index.d.ts +3 -2
- package/dist/declarations/src/utils/maskAuthData.d.ts +1 -1
- package/dist/declarations/src/utils/retryDelay.d.ts +1 -1
- package/dist/declarations/src/utils/validate.d.ts +1 -6
- package/package.json +5 -8
- package/dist/declarations/src/middleware/create-retry-middleware.d.ts +0 -2
- package/dist/declarations/src/utils/logger.d.ts +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, AuthMiddlewareOptions, CorrelationIdMiddlewareOptions, Credentials, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions, LoggerMiddlewareOptions,
|
|
1
|
+
import { Client, AuthMiddlewareOptions, CorrelationIdMiddlewareOptions, Credentials, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions, LoggerMiddlewareOptions, ErrorMiddlewareOptions } from '../types/types';
|
|
2
2
|
export default class ClientBuilder {
|
|
3
3
|
private projectKey;
|
|
4
4
|
private authMiddleware;
|
|
@@ -7,7 +7,6 @@ export default class ClientBuilder {
|
|
|
7
7
|
private correlationIdMiddleware;
|
|
8
8
|
private loggerMiddleware;
|
|
9
9
|
private queueMiddleware;
|
|
10
|
-
private retryMiddleware;
|
|
11
10
|
private concurrentMiddleware;
|
|
12
11
|
private errorMiddleware;
|
|
13
12
|
private middlewares;
|
|
@@ -20,7 +19,6 @@ export default class ClientBuilder {
|
|
|
20
19
|
withPasswordFlow(options: PasswordAuthMiddlewareOptions): ClientBuilder;
|
|
21
20
|
withAnonymousSessionFlow(options: AuthMiddlewareOptions): ClientBuilder;
|
|
22
21
|
withRefreshTokenFlow(options: RefreshAuthMiddlewareOptions): ClientBuilder;
|
|
23
|
-
withRetryMiddleware(options: RetryMiddlewareOptions): ClientBuilder;
|
|
24
22
|
withExistingTokenFlow(authorization: string, options?: ExistingTokenMiddlewareOptions): ClientBuilder;
|
|
25
23
|
withHttpMiddleware(options: HttpMiddlewareOptions): ClientBuilder;
|
|
26
24
|
withUserAgentMiddleware(options?: HttpUserAgentOptions): ClientBuilder;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Client, ClientRequest, ClientOptions, ProcessFn, ProcessOptions } from '../types/types';
|
|
2
2
|
export declare function process(request: ClientRequest, fn: ProcessFn, processOpt?: ProcessOptions): Promise<Array<ClientRequest>>;
|
|
3
|
-
export default function createClient(middlewares: ClientOptions):
|
|
4
|
-
process: typeof process;
|
|
5
|
-
execute(request: ClientRequest): Promise<ClientResult>;
|
|
6
|
-
};
|
|
3
|
+
export default function createClient(middlewares: ClientOptions): Client;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { default as createCorrelationIdMiddleware } from './create-correlation-id-middleware';
|
|
2
2
|
export { default as createHttpMiddleware } from './create-http-middleware';
|
|
3
3
|
export { default as createQueueMiddleware } from './create-queue-middleware';
|
|
4
|
-
export { default as createRetryMiddleware } from './create-retry-middleware';
|
|
5
4
|
export { default as createLoggerMiddleware } from './create-logger-middleware';
|
|
6
5
|
export { default as createUserAgentMiddleware } from './create-user-agent-middleware';
|
|
7
6
|
export { default as createConcurrentModificationMiddleware } from './create-concurrent-modification-middleware';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'buffer/'
|
|
2
|
+
import AbortController from 'abort-controller'
|
|
2
3
|
|
|
3
4
|
export type Nullable<T> = T | null
|
|
4
5
|
export type Keys = string | number | symbol
|
|
@@ -8,13 +9,12 @@ export type Optional = { [k in Keys]: any }
|
|
|
8
9
|
|
|
9
10
|
export type Middleware = (next: Next) => (request: MiddlewareRequest) => Promise<MiddlewareResponse>
|
|
10
11
|
|
|
11
|
-
export type MiddlewareResponse<T =
|
|
12
|
+
export type MiddlewareResponse<T = unknown> = {
|
|
12
13
|
resolve: Function;
|
|
13
14
|
reject: Function;
|
|
14
15
|
body: T;
|
|
15
16
|
error?: HttpErrorType;
|
|
16
17
|
statusCode: number;
|
|
17
|
-
// headers?: JsonObject<string>;
|
|
18
18
|
headers?: Record<string, any>
|
|
19
19
|
request?: MiddlewareRequest;
|
|
20
20
|
}
|
|
@@ -27,9 +27,8 @@ export type HttpErrorType = {
|
|
|
27
27
|
method: MethodType
|
|
28
28
|
statusCode: number
|
|
29
29
|
originalRequest?: ClientRequest
|
|
30
|
-
body
|
|
30
|
+
body: JsonObject
|
|
31
31
|
retryCount?: number
|
|
32
|
-
// headers?: JsonObject<QueryParam>
|
|
33
32
|
headers?: Record<string, any>
|
|
34
33
|
[key: string]: any
|
|
35
34
|
}
|
|
@@ -37,7 +36,6 @@ export type HttpErrorType = {
|
|
|
37
36
|
export interface ClientRequest {
|
|
38
37
|
baseUri?: string
|
|
39
38
|
uri?: string
|
|
40
|
-
// headers?: VariableMap
|
|
41
39
|
headers?: Record<string, any>
|
|
42
40
|
method: MethodType
|
|
43
41
|
uriTemplate?: string
|
|
@@ -80,10 +78,9 @@ export type ClientResponse<T = any> = {
|
|
|
80
78
|
body: T
|
|
81
79
|
code?: number
|
|
82
80
|
statusCode?: number
|
|
83
|
-
// headers?: JsonObject<string>
|
|
84
81
|
headers?: Record<string, any>
|
|
85
82
|
error?: HttpErrorType
|
|
86
|
-
|
|
83
|
+
retryCount?: number
|
|
87
84
|
}
|
|
88
85
|
|
|
89
86
|
export type ClientResult = ClientResponse
|
|
@@ -216,28 +213,23 @@ export type CredentialsMode = 'omit' | 'same-origin' | 'include'
|
|
|
216
213
|
export type HttpMiddlewareOptions = {
|
|
217
214
|
host: string
|
|
218
215
|
credentialsMode?: CredentialsMode
|
|
219
|
-
includeHeaders?: boolean
|
|
220
216
|
includeResponseHeaders?: boolean
|
|
221
217
|
includeOriginalRequest?: boolean
|
|
222
218
|
includeRequestInErrorResponse?: boolean
|
|
223
|
-
|
|
219
|
+
maskSensitiveHeaderData?: boolean
|
|
224
220
|
timeout?: number
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
// maxRetries?: number
|
|
228
|
-
// retryDelay?: number
|
|
229
|
-
// backoff?: boolean
|
|
230
|
-
// maxDelay?: number
|
|
231
|
-
// retryCodes?: Array<number | string>,
|
|
232
|
-
// }
|
|
221
|
+
enableRetry?: boolean
|
|
222
|
+
retryConfig?: RetryOptions
|
|
233
223
|
httpClient: Function
|
|
234
224
|
getAbortController?: () => AbortController
|
|
235
225
|
httpClientOptions?: object
|
|
236
226
|
}
|
|
237
227
|
|
|
228
|
+
export type RetryOptions = RetryMiddlewareOptions
|
|
229
|
+
|
|
238
230
|
export type HttpOptions = {
|
|
239
231
|
url: string
|
|
240
|
-
clientOptions:
|
|
232
|
+
clientOptions: HttpClientOptions
|
|
241
233
|
httpClient: Function
|
|
242
234
|
}
|
|
243
235
|
|
|
@@ -285,12 +277,15 @@ export type ExistingTokenMiddlewareOptions = {
|
|
|
285
277
|
|
|
286
278
|
export type IClientOptions = {
|
|
287
279
|
method: MethodType;
|
|
288
|
-
// headers: JsonObject<QueryParam>;
|
|
289
280
|
headers: Record<string, any>
|
|
290
281
|
credentialsMode?: CredentialsMode;
|
|
291
282
|
body?: string | Buffer
|
|
292
283
|
timeout?: number
|
|
293
284
|
abortController?: AbortController
|
|
285
|
+
includeOriginalRequest?: boolean
|
|
286
|
+
enableRetry?: boolean
|
|
287
|
+
retryConfig?: RetryOptions
|
|
288
|
+
maskSensitiveHeaderData?: boolean
|
|
294
289
|
}
|
|
295
290
|
|
|
296
291
|
export type HttpClientOptions = IClientOptions & Optional
|
|
@@ -304,6 +299,7 @@ type TResponse = {
|
|
|
304
299
|
data: Record<string, any>
|
|
305
300
|
message?: string
|
|
306
301
|
statusCode: number
|
|
302
|
+
retryCount: number
|
|
307
303
|
headers: Record<string, any>
|
|
308
304
|
}
|
|
309
305
|
|
|
@@ -312,7 +308,7 @@ export type Client = {
|
|
|
312
308
|
process: (
|
|
313
309
|
request: ClientRequest,
|
|
314
310
|
fn: ProcessFn,
|
|
315
|
-
processOpt
|
|
311
|
+
processOpt?: ProcessOptions
|
|
316
312
|
) => Promise<unknown>
|
|
317
313
|
}
|
|
318
314
|
|
|
@@ -328,4 +324,6 @@ export type SuccessResult = {
|
|
|
328
324
|
headers?: JsonObject<string>;
|
|
329
325
|
}
|
|
330
326
|
|
|
327
|
+
export type IResponse = Response & { statusCode?: number; data?: object }
|
|
328
|
+
|
|
331
329
|
export type executeRequest = (request: ClientRequest) => Promise<ClientResponse>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HttpErrorType } from '../types/types';
|
|
2
|
+
type ErrorType = ErrorArgs & Partial<HttpErrorType>;
|
|
3
|
+
type ErrorArgs = {
|
|
4
|
+
statusCode: number;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
declare function createError({ statusCode, message, ...rest }: ErrorType): HttpErrorType;
|
|
8
|
+
export default createError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function NetworkError(...args: Array<unknown>): void;
|
|
2
|
+
export declare function HttpError(...args: Array<unknown>): void;
|
|
3
|
+
export declare function BadRequest(...args: Array<unknown>): void;
|
|
4
|
+
export declare function Unauthorized(...args: Array<unknown>): void;
|
|
5
|
+
export declare function Forbidden(...args: Array<unknown>): void;
|
|
6
|
+
export declare function NotFound(...args: Array<unknown>): void;
|
|
7
|
+
export declare function ConcurrentModification(...args: Array<unknown>): void;
|
|
8
|
+
export declare function InternalServerError(...args: Array<unknown>): void;
|
|
9
|
+
export declare function ServiceUnavailable(...args: Array<unknown>): void;
|
|
10
|
+
export default function getErrorByCode(code: number): typeof NetworkError;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TResponse, HttpClientConfig } from '../types/types';
|
|
2
2
|
export default function executor(request: HttpClientConfig): Promise<TResponse>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default as logger } from './logger';
|
|
2
1
|
export { default as getHeaders } from './headers';
|
|
3
2
|
export { default as isBuffer } from './isBuffer';
|
|
4
3
|
export { default as calculateRetryDelay } from './retryDelay';
|
|
@@ -13,4 +12,6 @@ export { default as executor } from './executor';
|
|
|
13
12
|
export * as constants from './constants';
|
|
14
13
|
export { default as sleep } from './sleep';
|
|
15
14
|
export { default as METHODS } from './methods';
|
|
16
|
-
export {
|
|
15
|
+
export { default as createError } from './createError';
|
|
16
|
+
export { NetworkError } from './errors';
|
|
17
|
+
export { validateRetryCodes, validateHttpOptions, validateClient, validate } from './validate';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { MiddlewareRequest } from '../types/types';
|
|
2
|
-
export default function maskAuthData(request: MiddlewareRequest):
|
|
2
|
+
export default function maskAuthData(request: MiddlewareRequest): import("../types/types").ClientRequest;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientRequest, HttpMiddlewareOptions,
|
|
1
|
+
import { ClientRequest, HttpMiddlewareOptions, Middleware } from '../types/types';
|
|
2
2
|
/**
|
|
3
3
|
* validate some essential http options
|
|
4
4
|
* @param options
|
|
@@ -11,11 +11,6 @@ export declare function validateHttpOptions(options: HttpMiddlewareOptions): voi
|
|
|
11
11
|
* const retryCodes = [500, 504, "ETIMEDOUT"]
|
|
12
12
|
*/
|
|
13
13
|
export declare function validateRetryCodes(retryCodes: Array<string | number>): void;
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param options
|
|
17
|
-
*/
|
|
18
|
-
export declare function validateUserAgentOptions(options: HttpUserAgentOptions): void;
|
|
19
14
|
/**
|
|
20
15
|
* @param options
|
|
21
16
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/ts-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14"
|
|
6
6
|
},
|
|
@@ -33,14 +33,12 @@
|
|
|
33
33
|
"url": "https://github.com/commercetools/commercetools-sdk-typescript/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"abort-controller": "3.0.0",
|
|
36
37
|
"buffer": "^6.0.3",
|
|
37
38
|
"node-fetch": "^2.6.1",
|
|
38
39
|
"querystring": "^0.2.1"
|
|
39
40
|
},
|
|
40
|
-
"files": [
|
|
41
|
-
"dist",
|
|
42
|
-
"CHANGELOG.md"
|
|
43
|
-
],
|
|
41
|
+
"files": ["dist", "CHANGELOG.md"],
|
|
44
42
|
"author": "Chukwuemeka Ajima <meeky.ae@gmail.com>",
|
|
45
43
|
"main": "dist/commercetools-ts-client.cjs.js",
|
|
46
44
|
"module": "dist/commercetools-ts-client.esm.js",
|
|
@@ -49,10 +47,9 @@
|
|
|
49
47
|
"./dist/commercetools-ts-client.esm.js": "./dist/commercetools-ts-client.browser.esm.js"
|
|
50
48
|
},
|
|
51
49
|
"devDependencies": {
|
|
52
|
-
"abort-controller": "3.0.0",
|
|
53
50
|
"common-tags": "1.8.2",
|
|
54
|
-
"dotenv": "16.0.
|
|
55
|
-
"jest": "29.0
|
|
51
|
+
"dotenv": "16.0.3",
|
|
52
|
+
"jest": "29.5.0",
|
|
56
53
|
"nock": "12.0.3",
|
|
57
54
|
"organize-imports-cli": "0.10.0"
|
|
58
55
|
},
|