@gradientedge/commercetools-utils 4.32.0 → 5.0.1

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.
Files changed (31) hide show
  1. package/dist/ge-commercetools-utils-browser.cjs.js +1 -1
  2. package/dist/ge-commercetools-utils-browser.cjs.js.map +1 -1
  3. package/dist/ge-commercetools-utils-browser.esm.js +1 -1
  4. package/dist/ge-commercetools-utils-browser.esm.js.map +1 -1
  5. package/dist/ge-commercetools-utils-node.cjs.js +1 -1
  6. package/dist/ge-commercetools-utils-node.cjs.js.map +1 -1
  7. package/dist/ge-commercetools-utils-node.esm.js +1 -1
  8. package/dist/typings/api/CommercetoolsApi.d.ts +4 -13
  9. package/dist/typings/api/types.d.ts +1 -1
  10. package/dist/typings/auth/CommercetoolsAuthApi.d.ts +8 -7
  11. package/dist/typings/auth/types.d.ts +4 -10
  12. package/dist/typings/constants.d.ts +10 -0
  13. package/dist/typings/error/CommercetoolsError.d.ts +3 -8
  14. package/dist/typings/index.d.ts +1 -1
  15. package/dist/typings/request/index.d.ts +2 -0
  16. package/dist/typings/request/is-retryable-error.d.ts +1 -0
  17. package/dist/typings/request/request-executor.d.ts +11 -0
  18. package/dist/typings/request/request.d.ts +10 -0
  19. package/dist/typings/request/transform-error.d.ts +2 -0
  20. package/dist/typings/types.d.ts +26 -9
  21. package/dist/typings/utils/axios/convert-error.d.ts +3 -0
  22. package/dist/typings/utils/axios/convert-response.d.ts +3 -0
  23. package/dist/typings/utils/axios/create-instance.d.ts +6 -0
  24. package/dist/typings/utils/axios/extract-headers.d.ts +1 -0
  25. package/dist/typings/utils/axios/index.d.ts +4 -0
  26. package/dist/typings/utils/index.d.ts +1 -0
  27. package/dist/typings/utils/mask.d.ts +3 -3
  28. package/dist/typings/utils/plain-clone.d.ts +1 -0
  29. package/dist/typings/utils/retry-on-conflict.d.ts +1 -1
  30. package/package.json +13 -14
  31. package/dist/typings/axios/interceptors/logger.d.ts +0 -3
@@ -1,8 +1,7 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { CommercetoolsApiConfig, CommercetoolsRetryConfig } from './types';
3
2
  import { CommercetoolsAuth, PaymentDraft, ProductTypePagedQueryResponse, TypePagedQueryResponse } from '../';
4
- import { Logger, RegionEndpoints } from '../types';
5
- import type { Cart, CartDiscount, CartDiscountPagedQueryResponse, CartDraft, CartPagedQueryResponse, CartUpdateAction, Category, CategoryDraft, CategoryPagedQueryResponse, CategoryUpdate, Channel, ChannelPagedQueryResponse, Customer, CustomerCreatePasswordResetToken, CustomerDraft, CustomerGroup, CustomerGroupDraft, CustomerGroupPagedQueryResponse, CustomerGroupUpdate, CustomerPagedQueryResponse, CustomerResetPassword, CustomerSignin, CustomerSignInResult, CustomerToken, CustomerUpdate, CustomObject, CustomObjectDraft, DiscountCode, GraphQLRequest, GraphQLResponse, MyCartDraft, MyCartUpdateAction, MyCustomerDraft, MyPayment, MyPaymentDraft, MyPaymentPagedQueryResponse, MyPaymentUpdate, Order, OrderImportDraft, OrderPagedQueryResponse, OrderUpdate, Payment, PaymentPagedQueryResponse, PaymentUpdate, Product, ProductDraft, ProductProjection, ProductProjectionPagedQueryResponse, ProductsInStorePagedQueryResponse, ProductSelection, ProductSelectionDraft, ProductSelectionPagedQueryResponse, ProductSelectionUpdateAction, ProductType, ProductUpdate, ShippingMethod, ShippingMethodPagedQueryResponse, StandalonePrice, StandalonePriceDraft, StandalonePricePagedQueryResponse, StandalonePriceUpdate, State, StatePagedQueryResponse, Store, StoreDraft, StorePagedQueryResponse, StoreUpdate, Type } from '../models';
3
+ import { CommercetoolsRequest, RegionEndpoints } from '../types';
4
+ import type { Cart, CartDiscount, CartDiscountPagedQueryResponse, CartDraft, CartPagedQueryResponse, CartUpdateAction, Category, CategoryDraft, CategoryPagedQueryResponse, CategoryUpdate, Channel, ChannelPagedQueryResponse, Customer, CustomerCreatePasswordResetToken, CustomerDraft, CustomerGroup, CustomerGroupDraft, CustomerGroupPagedQueryResponse, CustomerGroupUpdate, CustomerPagedQueryResponse, CustomerResetPassword, CustomerSignin, CustomerSignInResult, CustomerToken, CustomerUpdate, CustomObject, CustomObjectDraft, DiscountCode, GraphQLRequest, GraphQLResponse, MyCartDraft, MyCartUpdateAction, MyCustomerDraft, MyPayment, MyPaymentDraft, MyPaymentPagedQueryResponse, MyPaymentUpdate, Order, OrderImportDraft, OrderPagedQueryResponse, OrderUpdate, Payment, PaymentPagedQueryResponse, PaymentUpdate, Product, ProductDraft, ProductProjection, ProductProjectionPagedQueryResponse, ProductSelection, ProductSelectionDraft, ProductSelectionPagedQueryResponse, ProductSelectionUpdateAction, ProductsInStorePagedQueryResponse, ProductType, ProductUpdate, ShippingMethod, ShippingMethodPagedQueryResponse, StandalonePrice, StandalonePriceDraft, StandalonePricePagedQueryResponse, StandalonePriceUpdate, State, StatePagedQueryResponse, Store, StoreDraft, StorePagedQueryResponse, StoreUpdate, Type } from '../models';
6
5
  export interface FetchOptions<T = any> {
7
6
  path: string;
8
7
  headers?: Record<string, string>;
@@ -25,13 +24,8 @@ export declare class CommercetoolsApi {
25
24
  readonly auth: CommercetoolsAuth;
26
25
  readonly config: CommercetoolsApiConfig;
27
26
  readonly endpoints: RegionEndpoints;
28
- private readonly userAgent;
29
- private readonly axios;
30
- private readonly retry;
27
+ private readonly requestExecutor;
31
28
  constructor(config: CommercetoolsApiConfig);
32
- createAxiosInstance(options?: {
33
- logFn?: Logger | null | undefined;
34
- }): AxiosInstance;
35
29
  getStoreById(options: CommonRequestOptions & {
36
30
  id: string;
37
31
  }): Promise<Store>;
@@ -473,11 +467,8 @@ export declare class CommercetoolsApi {
473
467
  data: GraphQLRequest;
474
468
  }): Promise<GraphQLResponse>;
475
469
  request<T = any, R = any>(options: FetchOptions<T>): Promise<R>;
476
- getRetryConfig(methodRetryConfig?: CommercetoolsRetryConfig): CommercetoolsRetryConfig;
477
- getRequestOptions(options: FetchOptions): Promise<any>;
478
- isRetryableError(error: any): boolean;
470
+ getRequestOptions(options: FetchOptions): Promise<CommercetoolsRequest>;
479
471
  extractCommonRequestOptions(options?: CommonRequestOptions): CommonRequestOptions;
480
472
  applyStore(path: string, storeKey: string | undefined | null): string;
481
- transformError(lastError: any): any;
482
473
  static validateConfig(config: any): void;
483
474
  }
@@ -2,8 +2,8 @@
2
2
  import * as https from 'https';
3
3
  import { CommercetoolsAuthConfig } from '../auth';
4
4
  export interface CommercetoolsApiConfig extends CommercetoolsAuthConfig {
5
- retry?: CommercetoolsRetryConfig;
6
5
  httpsAgent?: https.Agent;
6
+ clientScopes: string[];
7
7
  }
8
8
  export interface CommercetoolsRetryConfig {
9
9
  delayMs: number;
@@ -1,15 +1,11 @@
1
1
  import { CommercetoolsAuthApiConfig, CommercetoolsGrantResponse, LoginOptions, LogoutOptions, RevokeTokenOptions } from './types';
2
- import { Logger, RegionEndpoints } from '../types';
3
- import { AxiosInstance } from 'axios';
2
+ import { CommercetoolsRequest } from '../';
3
+ import { RegionEndpoints } from '../types';
4
4
  export declare class CommercetoolsAuthApi {
5
5
  readonly config: CommercetoolsAuthApiConfig;
6
6
  readonly endpoints: RegionEndpoints;
7
- private readonly userAgent;
8
- private readonly axios;
7
+ private readonly requestExecutor;
9
8
  constructor(config: CommercetoolsAuthApiConfig);
10
- createAxiosInstance(options?: {
11
- logFn?: Logger | null | undefined;
12
- }): AxiosInstance;
13
9
  getClientGrant(scopes: string[]): Promise<CommercetoolsGrantResponse>;
14
10
  refreshGrant(refreshToken: string): Promise<CommercetoolsGrantResponse>;
15
11
  login(options: LoginOptions & {
@@ -22,5 +18,10 @@ export declare class CommercetoolsAuthApi {
22
18
  scopes: string[];
23
19
  }): Promise<CommercetoolsGrantResponse>;
24
20
  post(path: string, body: Record<string, any>): Promise<CommercetoolsGrantResponse>;
21
+ getRequestOptions(options: {
22
+ path: string;
23
+ correlationId?: string | undefined;
24
+ body: Record<string, any>;
25
+ }): CommercetoolsRequest;
25
26
  applyStore(path: string, storeKey: string | undefined | null): string;
26
27
  }
@@ -1,20 +1,14 @@
1
1
  /// <reference types="node" />
2
- import { CommercetoolsBaseConfig, Logger, Region } from '../types';
2
+ import { CommercetoolsBaseConfig } from '../types';
3
3
  import https from 'https';
4
4
  export interface CommercetoolsAuthConfig extends CommercetoolsBaseConfig {
5
5
  refreshIfWithinSecs?: number;
6
6
  customerScopes?: string[];
7
+ clientScopes: string[];
7
8
  }
8
- export interface CommercetoolsAuthApiConfig {
9
- projectKey: string;
10
- clientId: string;
11
- clientSecret: string;
12
- region: Region;
13
- timeoutMs?: number;
14
- systemIdentifier?: string;
15
- storeKey?: string;
9
+ export interface CommercetoolsAuthApiConfig extends CommercetoolsBaseConfig {
10
+ clientScopes?: string[] | undefined;
16
11
  httpsAgent?: https.Agent;
17
- logFn?: Logger;
18
12
  }
19
13
  export interface CommercetoolsGrantResponse {
20
14
  access_token: string;
@@ -1,2 +1,12 @@
1
+ import { CommercetoolsRetryConfig } from './api';
2
+ export declare const USER_AGENT_PREFIX = "@gradientedge/commercetools-utils";
1
3
  export declare const DEFAULT_REQUEST_TIMEOUT_MS = 5000;
2
4
  export declare const MAX_ITEMS_PER_QUERY = 500;
5
+ export declare const DEFAULT_RETRY_CONFIG: CommercetoolsRetryConfig;
6
+ export declare const RETRYABLE_STATUS_CODES: number[];
7
+ export declare const DEFAULT_HTTPS_AGENT_CONFIG: {
8
+ keepAlive: boolean;
9
+ maxSockets: number;
10
+ maxFreeSockets: number;
11
+ timeout: number;
12
+ };
@@ -1,16 +1,11 @@
1
- import { AxiosError, AxiosRequestConfig } from 'axios';
1
+ import { AxiosError, InternalAxiosRequestConfig } from 'axios';
2
2
  export declare class CommercetoolsError extends Error {
3
3
  readonly data?: any;
4
4
  readonly status: number | undefined;
5
5
  readonly isCommercetoolsError = true;
6
6
  constructor(message: string, data?: any, status?: number);
7
7
  static fromAxiosError(e: AxiosError): CommercetoolsError;
8
- static parseRequestData(config: AxiosRequestConfig): any;
9
- toJSON(): {
10
- status: number | undefined;
11
- message: string;
12
- data: any;
13
- isCommercetoolsError: boolean;
14
- };
8
+ static parseRequestData(config: InternalAxiosRequestConfig | undefined): any;
9
+ toJSON(): Record<string, any>;
15
10
  toString(): string;
16
11
  }
@@ -1,7 +1,7 @@
1
1
  export * from './error';
2
2
  export * from './auth';
3
3
  export * from './api';
4
- export { Region, RegionEndpoints, Logger, LoggerParams } from './types';
4
+ export { Region, RegionEndpoints, CommercetoolsRequest, CommercetoolsRequestResponse } from './types';
5
5
  export * from './utils';
6
6
  export * from './models';
7
7
  export { MAX_ITEMS_PER_QUERY } from './constants';
@@ -0,0 +1,2 @@
1
+ export * from './request';
2
+ export * from './is-retryable-error';
@@ -0,0 +1 @@
1
+ export declare function isRetryableError(error: any): boolean;
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import https from 'https';
3
+ import { CommercetoolsRetryConfig } from '../api';
4
+ import { CommercetoolsHooks, RequestExecutor } from '../types';
5
+ export interface GetRequestExecutorProps extends CommercetoolsHooks {
6
+ httpsAgent?: https.Agent;
7
+ timeoutMs?: number;
8
+ retry?: Partial<CommercetoolsRetryConfig>;
9
+ systemIdentifier?: string;
10
+ }
11
+ export declare function getRequestExecutor(props: GetRequestExecutorProps): RequestExecutor;
@@ -0,0 +1,10 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { CommercetoolsRetryConfig } from '../api';
3
+ import { CommercetoolsHooks, CommercetoolsRequest } from '../types';
4
+ export interface RequestOptions extends CommercetoolsHooks {
5
+ axiosInstance: AxiosInstance;
6
+ retry: CommercetoolsRetryConfig;
7
+ request: CommercetoolsRequest;
8
+ timeoutMs?: number;
9
+ }
10
+ export declare function request<T = any>(options: RequestOptions): Promise<T>;
@@ -0,0 +1,2 @@
1
+ import { CommercetoolsError } from '../error';
2
+ export declare function transformError(lastError: any): Error | CommercetoolsError;
@@ -1,3 +1,4 @@
1
+ import { CommercetoolsRetryConfig } from './api';
1
2
  export declare enum Region {
2
3
  NORTH_AMERICA_GCP = "north_america_gcp",
3
4
  NORTH_AMERICA_AWS = "north_america_aws",
@@ -9,33 +10,49 @@ export interface RegionEndpoints {
9
10
  auth: string;
10
11
  api: string;
11
12
  }
12
- export interface CommercetoolsBaseConfig {
13
+ export interface CommercetoolsBaseConfig extends CommercetoolsHooks {
13
14
  projectKey: string;
14
15
  storeKey?: string;
15
16
  clientId: string;
16
17
  clientSecret: string;
17
18
  region: Region;
18
- clientScopes: string[];
19
19
  timeoutMs?: number;
20
+ retry?: Partial<CommercetoolsRetryConfig>;
20
21
  systemIdentifier?: string;
21
- logFn?: Logger;
22
22
  }
23
- export interface Logger {
24
- (options: LoggerParams): any;
23
+ export interface CommercetoolsHooks {
24
+ onBeforeRequest?: (requestConfig: CommercetoolsRequest) => Promise<CommercetoolsRequest> | CommercetoolsRequest;
25
+ onAfterResponse?: (response: CommercetoolsRequestResponse) => void;
25
26
  }
26
- export interface LoggerParams {
27
+ export interface CommercetoolsRequest {
28
+ url: string;
29
+ method: string;
30
+ params?: Record<string, string | number | boolean>;
31
+ headers: Record<string, string>;
32
+ data?: any;
33
+ }
34
+ export interface CommercetoolsRequestResponse {
27
35
  request: {
28
36
  url: string;
29
37
  method: string;
30
- params?: Record<string, string | number | boolean>;
31
- headers?: Record<string, string | number | boolean>;
38
+ params?: Record<string, string | number | boolean> | undefined;
39
+ headers?: Record<string, string> | undefined;
32
40
  data?: any;
33
41
  };
34
42
  response: {
35
43
  code?: string | undefined;
36
44
  message?: string | undefined;
37
45
  status?: number;
38
- headers?: Record<string, string | number | boolean>;
46
+ headers?: Record<string, string> | undefined;
39
47
  data?: any;
40
48
  };
49
+ stats: CommercetoolsRequestResponseStats;
50
+ }
51
+ export interface CommercetoolsRequestResponseStats {
52
+ accumulativeDurationMs: number;
53
+ durationMs: number;
54
+ retries: number;
55
+ }
56
+ export interface RequestExecutor<T = any> {
57
+ (options: CommercetoolsRequest): Promise<T>;
41
58
  }
@@ -0,0 +1,3 @@
1
+ import { CommercetoolsRequestResponse, CommercetoolsRequestResponseStats } from '../../types';
2
+ import { AxiosError } from 'axios';
3
+ export declare function convertAxiosError(error: AxiosError | Error, stats: CommercetoolsRequestResponseStats): CommercetoolsRequestResponse | null;
@@ -0,0 +1,3 @@
1
+ import { CommercetoolsRequestResponse, CommercetoolsRequestResponseStats } from '../../types';
2
+ import { AxiosResponse } from 'axios';
3
+ export declare function convertAxiosResponse(response: AxiosResponse, stats: CommercetoolsRequestResponseStats): CommercetoolsRequestResponse;
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { AxiosInstance } from 'axios';
3
+ import https from 'https';
4
+ export declare function createAxiosInstance(options: {
5
+ httpsAgent?: https.Agent;
6
+ }): AxiosInstance;
@@ -0,0 +1 @@
1
+ export declare function extractAxiosHeaders(headers: unknown): Record<string, string> | undefined;
@@ -0,0 +1,4 @@
1
+ export * from './convert-error';
2
+ export * from './convert-response';
3
+ export * from './create-instance';
4
+ export * from './extract-headers';
@@ -1,3 +1,4 @@
1
+ export * from './axios';
1
2
  export * from './calculate-delay';
2
3
  export * from './format';
3
4
  export * from './get-attribute-value';
@@ -1,6 +1,6 @@
1
1
  export declare const SENSITIVE_PROPERTY_NAMES: string[];
2
2
  export declare const SENSITIVE_HEADER_NAMES: string[];
3
3
  export declare const DEFAULT_MASKING_STRING = "********";
4
- export declare function maskSensitiveInput(data: unknown): unknown;
5
- export declare function maskSensitiveHeaders(data: unknown): unknown;
6
- export declare function maskSensitiveData(data: unknown, propertyNames: string[], mask?: string): unknown;
4
+ export declare function maskSensitiveInput(data: unknown): any;
5
+ export declare function maskSensitiveHeaders(data: unknown): any;
6
+ export declare function maskSensitiveData(data: any, propertyNames: string[], mask?: string): any;
@@ -0,0 +1 @@
1
+ export declare function plainClone(source: any): any;
@@ -1,5 +1,5 @@
1
1
  export interface RetryOnConflictParams<T = any> {
2
- executeFn: (...args: any) => Promise<T>;
2
+ executeFn: (attemptNo: number) => Promise<T>;
3
3
  delayMs?: number;
4
4
  maxRetries?: number;
5
5
  jitter?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/commercetools-utils",
3
- "version": "4.32.0",
3
+ "version": "5.0.1",
4
4
  "description": "Provide utility classes and functions for interacting with the commercetools API",
5
5
  "main": "./dist/ge-commercetools-utils-node.cjs.js",
6
6
  "module": "./dist/ge-commercetools-utils-node.esm.js",
@@ -56,41 +56,40 @@
56
56
  "homepage": "https://github.com/gradientedge/commercetools-utils#readme",
57
57
  "devDependencies": {
58
58
  "@sinonjs/fake-timers": "10.0.2",
59
- "@types/jest": "29.2.6",
59
+ "@types/jest": "29.4.0",
60
60
  "@types/json-stringify-safe": "5.0.0",
61
61
  "@types/lodash": "4.14.191",
62
62
  "@types/lodash.clonedeep": "4.5.7",
63
- "@types/node": "18.11.18",
63
+ "@types/node": "18.14.2",
64
64
  "@types/qs": "6.9.7",
65
65
  "@types/sinonjs__fake-timers": "8.1.2",
66
66
  "@types/traverse": "0.6.32",
67
- "@typescript-eslint/eslint-plugin": "5.48.2",
68
- "@typescript-eslint/parser": "5.48.2",
67
+ "@typescript-eslint/eslint-plugin": "5.54.0",
68
+ "@typescript-eslint/parser": "5.54.0",
69
69
  "codecov": "3.8.3",
70
70
  "commitizen": "4.3.0",
71
71
  "cz-conventional-changelog": "3.3.0",
72
- "eslint": "8.32.0",
72
+ "eslint": "8.35.0",
73
73
  "eslint-config-prettier": "8.6.0",
74
74
  "husky": "8.0.3",
75
- "jest": "29.3.1",
75
+ "jest": "29.4.3",
76
76
  "jest-matcher-specific-error": "1.0.0",
77
- "jest-mock": "29.3.1",
77
+ "jest-mock": "29.4.3",
78
78
  "nock": "13.3.0",
79
- "prettier": "2.8.3",
80
- "rimraf": "4.1.1",
79
+ "prettier": "2.8.4",
80
+ "rimraf": "4.1.2",
81
81
  "semantic-release": "19.0.5",
82
82
  "ts-jest": "29.0.5",
83
83
  "ts-node": "^10.9.1",
84
- "typedoc": "0.23.24",
85
- "typescript": "4.9.4",
84
+ "typedoc": "0.23.26",
85
+ "typescript": "4.9.5",
86
86
  "webpack": "5.75.0",
87
87
  "webpack-cli": "5.0.1"
88
88
  },
89
89
  "dependencies": {
90
90
  "@tshttp/status": "^2.0.0",
91
- "axios": "0.27.2",
91
+ "axios": "1.3.4",
92
92
  "json-stringify-safe": "5.0.1",
93
- "lodash.clonedeep": "4.5.0",
94
93
  "qs": "6.11.0",
95
94
  "traverse": "0.6.7"
96
95
  },
@@ -1,3 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { Logger } from '../../types';
3
- export declare function applyLoggerInterceptor(instance: AxiosInstance, logFn: Logger): void;