@commercetools/ts-client 0.0.0-beta.9 → 1.1.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 +30 -0
- package/LICENSE +1 -1
- package/dist/commercetools-ts-client.browser.cjs.js +1669 -0
- package/dist/commercetools-ts-client.browser.esm.js +1647 -0
- package/dist/commercetools-ts-client.cjs.d.ts +1 -11
- package/dist/commercetools-ts-client.cjs.dev.js +1669 -0
- package/dist/commercetools-ts-client.cjs.js +6 -15
- package/dist/commercetools-ts-client.cjs.prod.js +1669 -0
- package/dist/commercetools-ts-client.esm.js +1647 -0
- package/dist/declarations/src/client/builder.d.ts +31 -0
- package/dist/declarations/src/client/client.d.ts +3 -0
- package/dist/declarations/src/client/index.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/middleware/auth-middleware/anonymous-session-flow.d.ts +2 -0
- package/dist/declarations/src/middleware/auth-middleware/auth-request-builder.d.ts +24 -0
- package/dist/declarations/src/middleware/auth-middleware/auth-request-executor.d.ts +2 -0
- package/dist/declarations/src/middleware/auth-middleware/client-credentials-flow.d.ts +2 -0
- package/dist/declarations/src/middleware/auth-middleware/existing-token-flow.d.ts +2 -0
- package/dist/declarations/src/middleware/auth-middleware/index.d.ts +6 -0
- package/dist/declarations/src/middleware/auth-middleware/password-flow.d.ts +2 -0
- package/dist/declarations/src/middleware/auth-middleware/refresh-token-flow.d.ts +2 -0
- package/dist/declarations/src/middleware/create-concurrent-modification-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/create-correlation-id-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/create-error-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/create-http-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/create-logger-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/create-queue-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/create-user-agent-middleware.d.ts +2 -0
- package/dist/declarations/src/middleware/index.d.ts +8 -0
- package/dist/declarations/src/types/types.d.ts +329 -0
- package/dist/declarations/src/utils/constants.d.ts +5 -0
- 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 +2 -0
- package/dist/declarations/src/utils/generateID.d.ts +1 -0
- package/dist/declarations/src/utils/headers.d.ts +2 -0
- package/dist/declarations/src/utils/index.d.ts +18 -0
- package/dist/declarations/src/utils/isBuffer.d.ts +1 -0
- package/dist/declarations/src/utils/maskAuthData.d.ts +2 -0
- package/dist/declarations/src/utils/mergeAuthHeader.d.ts +2 -0
- package/dist/declarations/src/utils/methods.d.ts +2 -0
- package/dist/declarations/src/utils/retryDelay.d.ts +8 -0
- package/dist/declarations/src/utils/sleep.d.ts +1 -0
- package/dist/declarations/src/utils/tokenCacheKey.d.ts +2 -0
- package/dist/declarations/src/utils/tokenExpirationTime.d.ts +1 -0
- package/dist/declarations/src/utils/tokenStore.d.ts +2 -0
- package/dist/declarations/src/utils/url.d.ts +2 -0
- package/dist/declarations/src/utils/userAgent.d.ts +2 -0
- package/dist/declarations/src/utils/validate.d.ts +25 -0
- package/package.json +5 -6
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AuthMiddlewareOptions, Client, CorrelationIdMiddlewareOptions, Credentials, ErrorMiddlewareOptions, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, LoggerMiddlewareOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions } from '../types/types';
|
|
2
|
+
export default class ClientBuilder {
|
|
3
|
+
private projectKey;
|
|
4
|
+
private authMiddleware;
|
|
5
|
+
private httpMiddleware;
|
|
6
|
+
private userAgentMiddleware;
|
|
7
|
+
private correlationIdMiddleware;
|
|
8
|
+
private loggerMiddleware;
|
|
9
|
+
private queueMiddleware;
|
|
10
|
+
private concurrentMiddleware;
|
|
11
|
+
private errorMiddleware;
|
|
12
|
+
private middlewares;
|
|
13
|
+
constructor();
|
|
14
|
+
withProjectKey(key: string): ClientBuilder;
|
|
15
|
+
defaultClient(baseUri: string, credentials: Credentials, oauthUri?: string, projectKey?: string, scopes?: Array<string>, httpClient?: Function): ClientBuilder;
|
|
16
|
+
private withAuthMiddleware;
|
|
17
|
+
withMiddleware(middleware: Middleware): ClientBuilder;
|
|
18
|
+
withClientCredentialsFlow(options: AuthMiddlewareOptions): ClientBuilder;
|
|
19
|
+
withPasswordFlow(options: PasswordAuthMiddlewareOptions): ClientBuilder;
|
|
20
|
+
withAnonymousSessionFlow(options: AuthMiddlewareOptions): ClientBuilder;
|
|
21
|
+
withRefreshTokenFlow(options: RefreshAuthMiddlewareOptions): ClientBuilder;
|
|
22
|
+
withExistingTokenFlow(authorization: string, options?: ExistingTokenMiddlewareOptions): ClientBuilder;
|
|
23
|
+
withHttpMiddleware(options: HttpMiddlewareOptions): ClientBuilder;
|
|
24
|
+
withUserAgentMiddleware(options?: HttpUserAgentOptions): ClientBuilder;
|
|
25
|
+
withQueueMiddleware(options?: QueueMiddlewareOptions): ClientBuilder;
|
|
26
|
+
withLoggerMiddleware(options?: LoggerMiddlewareOptions): this;
|
|
27
|
+
withCorrelationIdMiddleware(options?: CorrelationIdMiddlewareOptions): ClientBuilder;
|
|
28
|
+
withConcurrentModificationMiddleware(): ClientBuilder;
|
|
29
|
+
withErrorMiddleware(options?: ErrorMiddlewareOptions): ClientBuilder;
|
|
30
|
+
build(): Client;
|
|
31
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Client, ClientOptions, ClientRequest, ProcessFn, ProcessOptions } from '../types/types';
|
|
2
|
+
export declare function process(request: ClientRequest, fn: ProcessFn, processOpt?: ProcessOptions): Promise<Array<ClientRequest>>;
|
|
3
|
+
export default function createClient(middlewares: ClientOptions): Client;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ClientBuilder, createClient, Process } from './client';
|
|
2
|
+
export { createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow, createCorrelationIdMiddleware, createHttpMiddleware, createLoggerMiddleware, createQueueMiddleware, createUserAgentMiddleware, } from './middleware';
|
|
3
|
+
export * from './types/types.d';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuthMiddlewareOptions, IBuiltRequestParams, PasswordAuthMiddlewareOptions, RefreshAuthMiddlewareOptions } from '../../types/types';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {AuthMiddlewareOptions} options
|
|
5
|
+
* @returns { IBuiltRequestParams } *
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildRequestForClientCredentialsFlow(options: AuthMiddlewareOptions): IBuiltRequestParams;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {AuthMiddlewareOptions} options
|
|
11
|
+
* @returns {IBuiltRequestParams} *
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildRequestForAnonymousSessionFlow(options: AuthMiddlewareOptions): IBuiltRequestParams;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {RefreshAuthMiddlewareOptions} options
|
|
17
|
+
* @returns {IBuiltRequestParams}
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildRequestForRefreshTokenFlow(options: RefreshAuthMiddlewareOptions): IBuiltRequestParams;
|
|
20
|
+
/**
|
|
21
|
+
* @param {PasswordAuthMiddlewareOptions} options
|
|
22
|
+
* @returns {IBuiltRequestParams}
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildRequestForPasswordFlow(options: PasswordAuthMiddlewareOptions): IBuiltRequestParams;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import createAuthMiddlewareForAnonymousSessionFlow from './anonymous-session-flow';
|
|
2
|
+
import createAuthMiddlewareForClientCredentialsFlow from './client-credentials-flow';
|
|
3
|
+
import createAuthMiddlewareForExistingTokenFlow from './existing-token-flow';
|
|
4
|
+
import createAuthMiddlewareForPasswordFlow from './password-flow';
|
|
5
|
+
import createAuthMiddlewareForRefreshTokenFlow from './refresh-token-flow';
|
|
6
|
+
export { createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForRefreshTokenFlow, createAuthMiddlewareForExistingTokenFlow };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow } from './auth-middleware';
|
|
2
|
+
export { default as createConcurrentModificationMiddleware } from './create-concurrent-modification-middleware';
|
|
3
|
+
export { default as createCorrelationIdMiddleware } from './create-correlation-id-middleware';
|
|
4
|
+
export { default as createErrorMiddleware } from './create-error-middleware';
|
|
5
|
+
export { default as createHttpMiddleware } from './create-http-middleware';
|
|
6
|
+
export { default as createLoggerMiddleware } from './create-logger-middleware';
|
|
7
|
+
export { default as createQueueMiddleware } from './create-queue-middleware';
|
|
8
|
+
export { default as createUserAgentMiddleware } from './create-user-agent-middleware';
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import AbortController from 'abort-controller'
|
|
2
|
+
import { Buffer } from 'buffer/'
|
|
3
|
+
|
|
4
|
+
export type Nullable<T> = T | null
|
|
5
|
+
export type Keys = string | number | symbol
|
|
6
|
+
export type JsonObject<T = unknown> = { [key in Keys]: T }
|
|
7
|
+
export type MiddlewareRequest = ClientRequest
|
|
8
|
+
export type Optional = { [k in Keys]: any }
|
|
9
|
+
|
|
10
|
+
export type Middleware = (next: Next) => (request: MiddlewareRequest) => Promise<MiddlewareResponse>
|
|
11
|
+
|
|
12
|
+
export type MiddlewareResponse<T = unknown> = {
|
|
13
|
+
resolve: Function;
|
|
14
|
+
reject: Function;
|
|
15
|
+
body: T;
|
|
16
|
+
error?: HttpErrorType;
|
|
17
|
+
statusCode: number;
|
|
18
|
+
headers?: Record<string, any>
|
|
19
|
+
request?: MiddlewareRequest;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type HttpErrorType = {
|
|
23
|
+
name?: string
|
|
24
|
+
message: string
|
|
25
|
+
code?: number
|
|
26
|
+
status?: number
|
|
27
|
+
method: MethodType
|
|
28
|
+
statusCode: number
|
|
29
|
+
originalRequest?: ClientRequest
|
|
30
|
+
body: JsonObject
|
|
31
|
+
retryCount?: number
|
|
32
|
+
headers?: Record<string, any>
|
|
33
|
+
[key: string]: any
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ClientRequest {
|
|
37
|
+
baseUri?: string
|
|
38
|
+
uri?: string
|
|
39
|
+
headers?: Record<string, any>
|
|
40
|
+
method: MethodType
|
|
41
|
+
uriTemplate?: string
|
|
42
|
+
pathVariables?: VariableMap
|
|
43
|
+
queryParams?: VariableMap
|
|
44
|
+
body?: string | Buffer
|
|
45
|
+
response?: ClientResponse
|
|
46
|
+
resolve?: Function;
|
|
47
|
+
reject?: Function;
|
|
48
|
+
[key: string]: any
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type Next = (request: MiddlewareRequest) => Promise<MiddlewareResponse>
|
|
52
|
+
|
|
53
|
+
export type MethodType =
|
|
54
|
+
| 'GET'
|
|
55
|
+
| 'HEAD'
|
|
56
|
+
| 'POST'
|
|
57
|
+
| 'PUT'
|
|
58
|
+
| 'PATCH'
|
|
59
|
+
| 'DELETE'
|
|
60
|
+
| 'CONNECT'
|
|
61
|
+
| 'OPTIONS'
|
|
62
|
+
| 'TRACE'
|
|
63
|
+
|
|
64
|
+
export type QueryParam =
|
|
65
|
+
| string
|
|
66
|
+
| string[]
|
|
67
|
+
| number
|
|
68
|
+
| number[]
|
|
69
|
+
| boolean
|
|
70
|
+
| boolean[]
|
|
71
|
+
| undefined
|
|
72
|
+
|
|
73
|
+
export type VariableMap = {
|
|
74
|
+
[key: string]: QueryParam
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type ClientResponse<T = any> = {
|
|
78
|
+
body: T
|
|
79
|
+
code?: number
|
|
80
|
+
statusCode?: number
|
|
81
|
+
headers?: Record<string, any>
|
|
82
|
+
error?: HttpErrorType
|
|
83
|
+
retryCount?: number
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type ClientResult = ClientResponse
|
|
87
|
+
export type ClientOptions = { middlewares: Array<Middleware> }
|
|
88
|
+
|
|
89
|
+
export type Credentials = {
|
|
90
|
+
clientId: string
|
|
91
|
+
clientSecret: string
|
|
92
|
+
anonymousId?: string
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type AuthMiddlewareOptions = {
|
|
96
|
+
host: string
|
|
97
|
+
projectKey: string
|
|
98
|
+
credentials: Credentials
|
|
99
|
+
scopes?: Array<string>
|
|
100
|
+
// For internal usage only
|
|
101
|
+
oauthUri?: string
|
|
102
|
+
httpClient?: Function
|
|
103
|
+
tokenCache?: TokenCache
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type TokenCacheOptions = {
|
|
107
|
+
clientId: string
|
|
108
|
+
projectKey: string
|
|
109
|
+
host: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type TokenStore = {
|
|
113
|
+
token: string
|
|
114
|
+
expirationTime?: number
|
|
115
|
+
refreshToken?: string
|
|
116
|
+
tokenCacheKey?: TokenCacheOptions
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type TokenCache = {
|
|
120
|
+
get: (tokenCacheOptions?: TokenCacheOptions) => TokenStore
|
|
121
|
+
set: (cache: TokenStore, tokenCacheOptions?: TokenCacheOptions) => void
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type IBuiltRequestParams = {
|
|
125
|
+
basicAuth: string
|
|
126
|
+
url: string
|
|
127
|
+
body: string
|
|
128
|
+
data?: string
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type RefreshAuthMiddlewareOptions = {
|
|
132
|
+
host: string
|
|
133
|
+
projectKey: string
|
|
134
|
+
credentials: {
|
|
135
|
+
clientId: string
|
|
136
|
+
clientSecret: string
|
|
137
|
+
}
|
|
138
|
+
refreshToken: string
|
|
139
|
+
tokenCache?: TokenCache,
|
|
140
|
+
// For internal usage only
|
|
141
|
+
oauthUri?: string
|
|
142
|
+
httpClient?: Function
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type RequestStateStore = {
|
|
146
|
+
get: () => RequestState
|
|
147
|
+
set: (requestState: RequestState) => void
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* Request */
|
|
151
|
+
type requestBaseOptions = {
|
|
152
|
+
url: string
|
|
153
|
+
body: string
|
|
154
|
+
basicAuth: string
|
|
155
|
+
request: MiddlewareRequest
|
|
156
|
+
tokenCache: TokenCache,
|
|
157
|
+
requestState: RequestStateStore,
|
|
158
|
+
pendingTasks: Array<Task>,
|
|
159
|
+
tokenCacheKey?: TokenCacheOptions,
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type executeRequestOptions = requestBaseOptions & {
|
|
163
|
+
next: Next
|
|
164
|
+
httpClient: Function
|
|
165
|
+
userOption?: AuthMiddlewareOptions | PasswordAuthMiddlewareOptions
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type AuthMiddlewareBaseOptions = requestBaseOptions & {
|
|
169
|
+
request: MiddlewareRequest
|
|
170
|
+
httpClient?: Function
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export type RequestState = boolean
|
|
174
|
+
|
|
175
|
+
export type Task = {
|
|
176
|
+
request: MiddlewareRequest
|
|
177
|
+
next?: Next
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type UserAuthOptions = {
|
|
181
|
+
username: string
|
|
182
|
+
password: string
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type PasswordAuthMiddlewareOptions = {
|
|
186
|
+
host: string
|
|
187
|
+
projectKey: string
|
|
188
|
+
credentials: {
|
|
189
|
+
clientId: string
|
|
190
|
+
clientSecret: string
|
|
191
|
+
user: UserAuthOptions
|
|
192
|
+
}
|
|
193
|
+
scopes?: Array<string>
|
|
194
|
+
tokenCache?: TokenCache,
|
|
195
|
+
// For internal usage only
|
|
196
|
+
oauthUri?: string
|
|
197
|
+
httpClient?: Function
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type TokenInfo = {
|
|
201
|
+
refresh_token: string
|
|
202
|
+
access_token: string
|
|
203
|
+
expires_at: number
|
|
204
|
+
expires_in: number // since this will always be used to calculate the expiration time, it shouldn't be made optional
|
|
205
|
+
scope?: string
|
|
206
|
+
token_type?: string
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export type Dispatch = (next: Next) => (request: MiddlewareRequest) => Promise<MiddlewareResponse>
|
|
210
|
+
|
|
211
|
+
export type CredentialsMode = 'omit' | 'same-origin' | 'include'
|
|
212
|
+
|
|
213
|
+
export type HttpMiddlewareOptions = {
|
|
214
|
+
host: string
|
|
215
|
+
credentialsMode?: CredentialsMode
|
|
216
|
+
includeResponseHeaders?: boolean
|
|
217
|
+
includeOriginalRequest?: boolean
|
|
218
|
+
includeRequestInErrorResponse?: boolean
|
|
219
|
+
maskSensitiveHeaderData?: boolean
|
|
220
|
+
timeout?: number
|
|
221
|
+
enableRetry?: boolean
|
|
222
|
+
retryConfig?: RetryOptions
|
|
223
|
+
httpClient: Function
|
|
224
|
+
getAbortController?: () => AbortController
|
|
225
|
+
httpClientOptions?: object
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type RetryOptions = RetryMiddlewareOptions
|
|
229
|
+
|
|
230
|
+
export type HttpOptions = {
|
|
231
|
+
url: string
|
|
232
|
+
clientOptions: HttpClientOptions
|
|
233
|
+
httpClient: Function
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type LogLevel = 'INFO' | 'ERROR'
|
|
237
|
+
|
|
238
|
+
export type LoggerMiddlewareOptions = {
|
|
239
|
+
logLevel?: LogLevel
|
|
240
|
+
maskSensitiveHeaderData?: boolean
|
|
241
|
+
includeOriginalRequest?: boolean
|
|
242
|
+
includeResponseHeaders?: boolean
|
|
243
|
+
includeRequestInErrorResponse?: boolean
|
|
244
|
+
loggerFn?: (options: MiddlewareResponse) => void
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export type RetryMiddlewareOptions = {
|
|
248
|
+
backoff?: boolean
|
|
249
|
+
maxRetries?: number
|
|
250
|
+
retryDelay?: number
|
|
251
|
+
maxDelay?: typeof Infinity
|
|
252
|
+
retryCodes?: Array<number | string>
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export type CorrelationIdMiddlewareOptions = {
|
|
256
|
+
generate?: () => string
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/* HTTP User Agent */
|
|
260
|
+
export type HttpUserAgentOptions = {
|
|
261
|
+
name?: string
|
|
262
|
+
version?: string
|
|
263
|
+
libraryName?: string
|
|
264
|
+
libraryVersion?: string
|
|
265
|
+
contactUrl?: string
|
|
266
|
+
contactEmail?: string
|
|
267
|
+
customAgent?: string
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type QueueMiddlewareOptions = {
|
|
271
|
+
concurrency?: number
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export type ExistingTokenMiddlewareOptions = {
|
|
275
|
+
force: boolean
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export type IClientOptions = {
|
|
279
|
+
method: MethodType;
|
|
280
|
+
headers: Record<string, any>
|
|
281
|
+
credentialsMode?: CredentialsMode;
|
|
282
|
+
body?: string | Buffer
|
|
283
|
+
timeout?: number
|
|
284
|
+
abortController?: AbortController
|
|
285
|
+
includeOriginalRequest?: boolean
|
|
286
|
+
enableRetry?: boolean
|
|
287
|
+
retryConfig?: RetryOptions
|
|
288
|
+
maskSensitiveHeaderData?: boolean
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export type HttpClientOptions = IClientOptions & Optional
|
|
292
|
+
|
|
293
|
+
export type HttpClientConfig = IClientOptions & {
|
|
294
|
+
url: string
|
|
295
|
+
httpClient: Function
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
type TResponse = {
|
|
299
|
+
data: Record<string, any>
|
|
300
|
+
message?: string
|
|
301
|
+
statusCode: number
|
|
302
|
+
retryCount: number
|
|
303
|
+
headers: Record<string, any>
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export type Client = {
|
|
307
|
+
execute(request: ClientRequest): Promise<ClientResult>
|
|
308
|
+
process: (
|
|
309
|
+
request: ClientRequest,
|
|
310
|
+
fn: ProcessFn,
|
|
311
|
+
processOpt?: ProcessOptions
|
|
312
|
+
) => Promise<unknown>
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export type ProcessFn = (result: ClientResult) => Promise<unknown>
|
|
316
|
+
export type ProcessOptions = { accumulate?: boolean; total?: number }
|
|
317
|
+
export type ErrorMiddlewareOptions = {}
|
|
318
|
+
export type SuccessResult = {
|
|
319
|
+
body: {
|
|
320
|
+
results: Record<string | number, Record<string, any>>;
|
|
321
|
+
count: number;
|
|
322
|
+
};
|
|
323
|
+
statusCode: number;
|
|
324
|
+
headers?: JsonObject<string>;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export type IResponse = Response & { statusCode?: number; data?: object }
|
|
328
|
+
|
|
329
|
+
export type executeRequest = (request: ClientRequest) => Promise<ClientResponse>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const HEADERS_CONTENT_TYPES: string[];
|
|
2
|
+
export declare const CONCURRENCT_REQUEST = 20;
|
|
3
|
+
export declare const CTP_API_URL = "https://api.europe-west1.gcp.commercetools.com";
|
|
4
|
+
export declare const CTP_AUTH_URL = "https://auth.europe-west1.gcp.commercetools.com";
|
|
5
|
+
export declare const DEFAULT_HEADERS: string[];
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function generateID(): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * as constants from './constants';
|
|
2
|
+
export { default as createError } from './createError';
|
|
3
|
+
export { NetworkError } from './errors';
|
|
4
|
+
export { default as executor } from './executor';
|
|
5
|
+
export { default as generate } from './generateID';
|
|
6
|
+
export { default as getHeaders } from './headers';
|
|
7
|
+
export { default as isBuffer } from './isBuffer';
|
|
8
|
+
export { default as maskAuthData } from './maskAuthData';
|
|
9
|
+
export { default as mergeAuthHeader } from './mergeAuthHeader';
|
|
10
|
+
export { default as METHODS } from './methods';
|
|
11
|
+
export { default as calculateRetryDelay } from './retryDelay';
|
|
12
|
+
export { default as sleep } from './sleep';
|
|
13
|
+
export { default as buildTokenCacheKey } from './tokenCacheKey';
|
|
14
|
+
export { default as calculateExpirationTime } from './tokenExpirationTime';
|
|
15
|
+
export { default as store } from './tokenStore';
|
|
16
|
+
export { default as userAgent } from './userAgent';
|
|
17
|
+
export { stringifyURLString, parseURLString } from './url';
|
|
18
|
+
export { validate, validateClient, validateHttpOptions, validateRetryCodes } from './validate';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isBuffer(obj: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function sleep(ms: number): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function calculateExpirationTime(expiresIn: number): number;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function parseURLString<T>(url: string | URLSearchParams, parser?: <T>(url: string | URLSearchParams) => T): T;
|
|
2
|
+
export declare function stringifyURLString(object: string | Record<string, any> | Array<Array<string>>, stringifier?: (object: string | Record<string, any> | Array<Array<string>> | URLSearchParams) => string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClientRequest, HttpMiddlewareOptions, Middleware } from '../types/types';
|
|
2
|
+
/**
|
|
3
|
+
* validate some essential http options
|
|
4
|
+
* @param options
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateHttpOptions(options: HttpMiddlewareOptions): void;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param retryCodes
|
|
10
|
+
* @example
|
|
11
|
+
* const retryCodes = [500, 504, "ETIMEDOUT"]
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateRetryCodes(retryCodes: Array<string | number>): void;
|
|
14
|
+
/**
|
|
15
|
+
* @param options
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateClient(options: {
|
|
18
|
+
middlewares: Array<Middleware>;
|
|
19
|
+
}): void;
|
|
20
|
+
/**
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
export declare function validate(funcName: string, request: ClientRequest, options?: {
|
|
24
|
+
allowedMethods: Array<string>;
|
|
25
|
+
}): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/ts-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14"
|
|
6
6
|
},
|
|
@@ -33,9 +33,9 @@
|
|
|
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
|
-
"node-fetch": "^2.6.1"
|
|
38
|
-
"querystring": "^0.2.1"
|
|
38
|
+
"node-fetch": "^2.6.1"
|
|
39
39
|
},
|
|
40
40
|
"files": ["dist", "CHANGELOG.md"],
|
|
41
41
|
"author": "Chukwuemeka Ajima <meeky.ae@gmail.com>",
|
|
@@ -46,10 +46,9 @@
|
|
|
46
46
|
"./dist/commercetools-ts-client.esm.js": "./dist/commercetools-ts-client.browser.esm.js"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"abort-controller": "3.0.0",
|
|
50
49
|
"common-tags": "1.8.2",
|
|
51
|
-
"dotenv": "16.0.
|
|
52
|
-
"jest": "29.0
|
|
50
|
+
"dotenv": "16.0.3",
|
|
51
|
+
"jest": "29.5.0",
|
|
53
52
|
"nock": "12.0.3",
|
|
54
53
|
"organize-imports-cli": "0.10.0"
|
|
55
54
|
},
|