@contentstack/cli-variants 2.0.0-beta.1 → 2.0.0-beta.2

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.
@@ -11,6 +11,7 @@ export type APIConfig = HttpRequestConfig & {
11
11
  config: ExportConfig | Record<string, any> | undefined;
12
12
  baseURL?: string;
13
13
  cmaConfig?: HttpRequestConfig;
14
+ delayMs?: number;
14
15
  };
15
16
  export interface AdapterConstructor<T, C> {
16
17
  new (config: C, options?: HttpClientOptions): T;
@@ -32,6 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
35
44
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
45
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
46
  };
@@ -42,6 +51,7 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
42
51
  const messages_1 = __importStar(require("../messages"));
43
52
  class AdapterHelper {
44
53
  constructor(adapterConfig, options) {
54
+ var _a, _b, _c, _d;
45
55
  this.adapterConfig = adapterConfig;
46
56
  this.$t = messages_1.$t;
47
57
  this.messages = messages_1.default;
@@ -62,6 +72,20 @@ class AdapterHelper {
62
72
  if (adapterConfig.cmaConfig) {
63
73
  this.cmaAPIClient = new cli_utilities_1.HttpClient((0, pick_1.default)(adapterConfig.cmaConfig, pickConfig), options);
64
74
  }
75
+ if (adapterConfig.delayMs) {
76
+ if (this.apiClient) {
77
+ (_b = (_a = this.apiClient.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.use((requestConfig) => __awaiter(this, void 0, void 0, function* () {
78
+ yield this.delay(adapterConfig.delayMs);
79
+ return requestConfig;
80
+ }));
81
+ }
82
+ if (this.cmaAPIClient) {
83
+ (_d = (_c = this.cmaAPIClient.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.use((requestConfig) => __awaiter(this, void 0, void 0, function* () {
84
+ yield this.delay(adapterConfig.delayMs);
85
+ return requestConfig;
86
+ }));
87
+ }
88
+ }
65
89
  }
66
90
  /**
67
91
  * The function constructs a query string from a given object by encoding its key-value pairs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-variants",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Variants plugin",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -13,6 +13,7 @@ export type APIConfig = HttpRequestConfig & {
13
13
  config: ExportConfig | Record<string, any> | undefined;
14
14
  baseURL?: string;
15
15
  cmaConfig?: HttpRequestConfig;
16
+ delayMs?: number;
16
17
  };
17
18
 
18
19
  export interface AdapterConstructor<T, C> {
@@ -28,9 +28,26 @@ export class AdapterHelper<C, ApiClient> implements AdapterHelperInterface<C, Ap
28
28
  'responseType',
29
29
  ];
30
30
  this.apiClient = new HttpClient(pick(adapterConfig, pickConfig), options) as ApiClient;
31
+
31
32
  if (adapterConfig.cmaConfig) {
32
33
  this.cmaAPIClient = new HttpClient(pick(adapterConfig.cmaConfig, pickConfig), options) as ApiClient;
33
34
  }
35
+
36
+ if (adapterConfig.delayMs) {
37
+ if (this.apiClient) {
38
+ (this.apiClient as any).interceptors?.request?.use(async (requestConfig: any) => {
39
+ await this.delay(adapterConfig.delayMs!);
40
+ return requestConfig;
41
+ });
42
+ }
43
+
44
+ if (this.cmaAPIClient) {
45
+ (this.cmaAPIClient as any).interceptors?.request?.use(async (requestConfig: any) => {
46
+ await this.delay(adapterConfig.delayMs!);
47
+ return requestConfig;
48
+ });
49
+ }
50
+ }
34
51
  }
35
52
 
36
53
  /**