@gradientedge/commercetools-utils 4.11.2 → 4.11.3

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 (105) hide show
  1. package/dist/ge-commercetools-utils-browser.cjs.js +2 -0
  2. package/dist/ge-commercetools-utils-browser.cjs.js.map +1 -0
  3. package/dist/ge-commercetools-utils-browser.esm.js +2 -0
  4. package/dist/ge-commercetools-utils-browser.esm.js.map +1 -0
  5. package/dist/ge-commercetools-utils-node.cjs.js +2 -0
  6. package/dist/ge-commercetools-utils-node.cjs.js.map +1 -0
  7. package/dist/ge-commercetools-utils-node.esm.js +1 -0
  8. package/dist/typings/api/CommercetoolsApi.d.ts +436 -0
  9. package/dist/{api → typings/api}/index.d.ts +0 -1
  10. package/dist/typings/api/types.d.ts +12 -0
  11. package/dist/typings/auth/CommercetoolsAuth.d.ts +22 -0
  12. package/dist/typings/auth/CommercetoolsAuthApi.d.ts +21 -0
  13. package/dist/typings/auth/CommercetoolsGrant.d.ts +13 -0
  14. package/dist/{auth → typings/auth}/constants.d.ts +0 -4
  15. package/dist/{auth → typings/auth}/index.d.ts +0 -1
  16. package/dist/typings/auth/scopes.d.ts +2 -0
  17. package/dist/typings/auth/types.d.ts +43 -0
  18. package/dist/{auth → typings/auth}/utils.d.ts +0 -1
  19. package/dist/typings/constants.d.ts +1 -0
  20. package/dist/typings/error/CommercetoolsError.d.ts +16 -0
  21. package/dist/{error → typings/error}/index.d.ts +0 -1
  22. package/dist/{index.d.ts → typings/index.d.ts} +0 -1
  23. package/dist/typings/types.d.ts +21 -0
  24. package/dist/typings/utils/format.d.ts +1 -0
  25. package/dist/{utils → typings/utils}/index.d.ts +0 -2
  26. package/dist/typings/utils/mask.d.ts +6 -0
  27. package/dist/typings/utils/useragent.d.ts +1 -0
  28. package/package.json +23 -7
  29. package/dist/api/CommercetoolsApi.d.ts +0 -1096
  30. package/dist/api/CommercetoolsApi.d.ts.map +0 -1
  31. package/dist/api/CommercetoolsApi.js +0 -1425
  32. package/dist/api/CommercetoolsApi.js.map +0 -1
  33. package/dist/api/index.d.ts.map +0 -1
  34. package/dist/api/index.js +0 -15
  35. package/dist/api/index.js.map +0 -1
  36. package/dist/api/types.d.ts +0 -33
  37. package/dist/api/types.d.ts.map +0 -1
  38. package/dist/api/types.js +0 -3
  39. package/dist/api/types.js.map +0 -1
  40. package/dist/auth/CommercetoolsAuth.d.ts +0 -182
  41. package/dist/auth/CommercetoolsAuth.d.ts.map +0 -1
  42. package/dist/auth/CommercetoolsAuth.js +0 -326
  43. package/dist/auth/CommercetoolsAuth.js.map +0 -1
  44. package/dist/auth/CommercetoolsAuthApi.d.ts +0 -74
  45. package/dist/auth/CommercetoolsAuthApi.d.ts.map +0 -1
  46. package/dist/auth/CommercetoolsAuthApi.js +0 -248
  47. package/dist/auth/CommercetoolsAuthApi.js.map +0 -1
  48. package/dist/auth/CommercetoolsGrant.d.ts +0 -66
  49. package/dist/auth/CommercetoolsGrant.d.ts.map +0 -1
  50. package/dist/auth/CommercetoolsGrant.js +0 -82
  51. package/dist/auth/CommercetoolsGrant.js.map +0 -1
  52. package/dist/auth/constants.d.ts.map +0 -1
  53. package/dist/auth/constants.js +0 -32
  54. package/dist/auth/constants.js.map +0 -1
  55. package/dist/auth/index.d.ts.map +0 -1
  56. package/dist/auth/index.js +0 -15
  57. package/dist/auth/index.js.map +0 -1
  58. package/dist/auth/scopes.d.ts +0 -11
  59. package/dist/auth/scopes.d.ts.map +0 -1
  60. package/dist/auth/scopes.js +0 -30
  61. package/dist/auth/scopes.js.map +0 -1
  62. package/dist/auth/types.d.ts +0 -120
  63. package/dist/auth/types.d.ts.map +0 -1
  64. package/dist/auth/types.js +0 -28
  65. package/dist/auth/types.js.map +0 -1
  66. package/dist/auth/utils.d.ts.map +0 -1
  67. package/dist/auth/utils.js +0 -15
  68. package/dist/auth/utils.js.map +0 -1
  69. package/dist/constants.d.ts +0 -6
  70. package/dist/constants.d.ts.map +0 -1
  71. package/dist/constants.js +0 -9
  72. package/dist/constants.js.map +0 -1
  73. package/dist/error/CommercetoolsError.d.ts +0 -38
  74. package/dist/error/CommercetoolsError.d.ts.map +0 -1
  75. package/dist/error/CommercetoolsError.js +0 -117
  76. package/dist/error/CommercetoolsError.js.map +0 -1
  77. package/dist/error/index.d.ts.map +0 -1
  78. package/dist/error/index.js +0 -14
  79. package/dist/error/index.js.map +0 -1
  80. package/dist/index.d.ts.map +0 -1
  81. package/dist/index.js +0 -21
  82. package/dist/index.js.map +0 -1
  83. package/dist/types.d.ts +0 -44
  84. package/dist/types.d.ts.map +0 -1
  85. package/dist/types.js +0 -16
  86. package/dist/types.js.map +0 -1
  87. package/dist/utils/format.d.ts +0 -11
  88. package/dist/utils/format.d.ts.map +0 -1
  89. package/dist/utils/format.js +0 -48
  90. package/dist/utils/format.js.map +0 -1
  91. package/dist/utils/index.d.ts.map +0 -1
  92. package/dist/utils/index.js +0 -17
  93. package/dist/utils/index.js.map +0 -1
  94. package/dist/utils/isNode.d.ts +0 -2
  95. package/dist/utils/isNode.d.ts.map +0 -1
  96. package/dist/utils/isNode.js +0 -12
  97. package/dist/utils/isNode.js.map +0 -1
  98. package/dist/utils/mask.d.ts +0 -28
  99. package/dist/utils/mask.d.ts.map +0 -1
  100. package/dist/utils/mask.js +0 -56
  101. package/dist/utils/mask.js.map +0 -1
  102. package/dist/utils/useragent.d.ts +0 -10
  103. package/dist/utils/useragent.d.ts.map +0 -1
  104. package/dist/utils/useragent.js +0 -20
  105. package/dist/utils/useragent.js.map +0 -1
@@ -1,1425 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.CommercetoolsApi = void 0;
54
- var axios_1 = __importDefault(require("axios"));
55
- var qs_1 = __importDefault(require("qs"));
56
- var __1 = require("../");
57
- var error_1 = require("../error");
58
- var constants_1 = require("../auth/constants");
59
- var constants_2 = require("../constants");
60
- var utils_1 = require("../utils");
61
- var utils_2 = require("../utils");
62
- /**
63
- * Default retry configuration - equates to no retying at all
64
- */
65
- var DEFAULT_RETRY_CONFIG = {
66
- maxRetries: 0,
67
- delayMs: 0,
68
- };
69
- /**
70
- * List of status codes which are allowed to retry
71
- */
72
- var RETRYABLE_STATUS_CODES = [500, 501, 502, 503, 504];
73
- /**
74
- * The config options passed in to the {@see HttpsAgent.Agent} used
75
- * with the axios instance that we create.
76
- */
77
- var DEFAULT_HTTPS_AGENT_CONFIG = {
78
- keepAlive: true,
79
- maxSockets: 32,
80
- maxFreeSockets: 10,
81
- timeout: 60000,
82
- };
83
- /**
84
- * A collection of convenience methods for interacting with the
85
- * commercetools API.
86
- */
87
- var CommercetoolsApi = /** @class */ (function () {
88
- function CommercetoolsApi(config) {
89
- CommercetoolsApi.validateConfig(config);
90
- this.config = config;
91
- this.auth = new __1.CommercetoolsAuth(config);
92
- this.endpoints = constants_1.REGION_URLS[this.config.region];
93
- this.userAgent = (0, utils_1.buildUserAgent)(this.config.systemIdentifier);
94
- this.axios = this.createAxiosInstance();
95
- this.retry = config.retry || DEFAULT_RETRY_CONFIG;
96
- }
97
- /**
98
- * Define the base axios instance that forms the foundation
99
- * of all axios calls made by the {@see request} method.
100
- */
101
- CommercetoolsApi.prototype.createAxiosInstance = function () {
102
- var agent;
103
- try {
104
- if (this.config.httpsAgent) {
105
- agent = this.config.httpsAgent;
106
- }
107
- else if ((0, utils_2.isNode)()) {
108
- var https = require('https');
109
- agent = new https.Agent(DEFAULT_HTTPS_AGENT_CONFIG);
110
- }
111
- }
112
- catch (e) { }
113
- var instance = axios_1.default.create({
114
- timeout: this.config.timeoutMs || constants_2.DEFAULT_REQUEST_TIMEOUT_MS,
115
- paramsSerializer: function (params) {
116
- return qs_1.default.stringify(params, { arrayFormat: 'repeat' });
117
- },
118
- httpsAgent: agent,
119
- });
120
- if ((0, utils_2.isNode)()) {
121
- instance.defaults.headers.common['User-Agent'] = this.userAgent;
122
- }
123
- return instance;
124
- };
125
- /**
126
- * Get a store given it's id
127
- * https://docs.commercetools.com/api/projects/stores#get-a-store-by-id
128
- */
129
- CommercetoolsApi.prototype.getStoreById = function (options) {
130
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/stores/".concat(options.id), method: 'GET' }));
131
- };
132
- /**
133
- * Get a store given it's key
134
- * https://docs.commercetools.com/api/projects/stores#get-a-store-by-key
135
- */
136
- CommercetoolsApi.prototype.getStoreByKey = function (options) {
137
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/stores/key=".concat(options.key), method: 'GET' }));
138
- };
139
- /**
140
- * Query stores
141
- * https://docs.commercetools.com/api/projects/stores#get-a-store-by-key
142
- */
143
- CommercetoolsApi.prototype.queryStores = function (options) {
144
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: '/stores', method: 'GET' }));
145
- };
146
- /**
147
- * Create a store:
148
- * https://docs.commercetools.com/api/projects/stores#create-a-store
149
- */
150
- CommercetoolsApi.prototype.createStore = function (options) {
151
- return this.request({
152
- path: "/stores",
153
- method: 'POST',
154
- data: options.data,
155
- });
156
- };
157
- /**
158
- * Update a store by id:
159
- * https://docs.commercetools.com/api/projects/stores#update-store-by-id
160
- */
161
- CommercetoolsApi.prototype.updateStoreById = function (options) {
162
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/stores/".concat(options.id), method: 'POST', data: options.data }));
163
- };
164
- /**
165
- * Update a store by key:
166
- * https://docs.commercetools.com/api/projects/stores#update-store-by-key
167
- */
168
- CommercetoolsApi.prototype.updateStoreByKey = function (options) {
169
- return this.request({
170
- path: "/stores/key=".concat(options.key),
171
- method: 'POST',
172
- data: options.data,
173
- });
174
- };
175
- /**
176
- * Delete a store by id:
177
- * https://docs.commercetools.com/api/projects/stores#delete-store-by-id
178
- */
179
- CommercetoolsApi.prototype.deleteStoreById = function (options) {
180
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/stores/".concat(options.id), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
181
- };
182
- /**
183
- * Delete a store by key:
184
- * https://docs.commercetools.com/api/projects/stores#delete-store-by-key
185
- */
186
- CommercetoolsApi.prototype.deleteStoreByKey = function (options) {
187
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/stores/key=".concat(options.key), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
188
- };
189
- /**
190
- * Get an individual category by id:
191
- * https://docs.commercetools.com/api/projects/categories#get-category-by-id
192
- */
193
- CommercetoolsApi.prototype.getCategoryById = function (options) {
194
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/".concat(options.id), method: 'GET' }));
195
- };
196
- /**
197
- * Get an individual category by key:
198
- * https://docs.commercetools.com/api/projects/categories#get-category-by-key
199
- */
200
- CommercetoolsApi.prototype.getCategoryByKey = function (options) {
201
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/key=".concat(options.key), method: 'GET' }));
202
- };
203
- /**
204
- * Query channels:
205
- * https://docs.commercetools.com/api/projects/channels#query-channels
206
- */
207
- CommercetoolsApi.prototype.queryChannels = function (options) {
208
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/channels", method: 'GET' }));
209
- };
210
- /**
211
- * Import an order.
212
- * https://docs.commercetools.com/api/projects/orders-import#orderimportdraft
213
- */
214
- CommercetoolsApi.prototype.importOrder = function (options) {
215
- return __awaiter(this, void 0, void 0, function () {
216
- return __generator(this, function (_a) {
217
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: '/orders/import', method: 'POST', data: options.data }))];
218
- });
219
- });
220
- };
221
- /**
222
- * Get channel by id:
223
- * https://docs.commercetools.com/api/projects/channels#get-channel-by-id
224
- */
225
- CommercetoolsApi.prototype.getChannelById = function (options) {
226
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/channels/".concat(options.id), method: 'GET' }));
227
- };
228
- /**
229
- * Get an category by id or key. Either the id or the key must be provided.
230
- */
231
- CommercetoolsApi.prototype.getCategory = function (options) {
232
- if (!options.id && !options.key) {
233
- throw new error_1.CommercetoolsError('Either an id, key or slug must be provided');
234
- }
235
- if (options.id) {
236
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/".concat(options.id), method: 'GET' }));
237
- }
238
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/key=".concat(options.key), method: 'GET' }));
239
- };
240
- /**
241
- * Get a category projection by slug and locale
242
- * Queries the categories for the given slug + locale using:
243
- * https://docs.commercetools.com/api/projects/categories#query-categories
244
- */
245
- CommercetoolsApi.prototype.getCategoryBySlug = function (options) {
246
- return __awaiter(this, void 0, void 0, function () {
247
- var languageCodes, data;
248
- return __generator(this, function (_a) {
249
- switch (_a.label) {
250
- case 0:
251
- if (!options.languageCode && !options.languageCodes) {
252
- throw new error_1.CommercetoolsError('Either the `languageCode` or `languageCodes` property must be provided');
253
- }
254
- languageCodes = [];
255
- if (options.languageCodes) {
256
- languageCodes.push.apply(languageCodes, options.languageCodes);
257
- }
258
- else if (options.languageCode) {
259
- languageCodes.push(options.languageCode);
260
- }
261
- return [4 /*yield*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(__assign(__assign({}, options), { params: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.params), { where: "slug(".concat(languageCodes.map(function (code) { return "".concat(code, "=\"").concat(options.slug, "\""); }).join(' or '), ")") }) }))), { path: "/categories", method: 'GET' }))];
262
- case 1:
263
- data = _a.sent();
264
- if (!data.count) {
265
- throw new error_1.CommercetoolsError("No category found with slug [".concat(options.slug, "] and language code [").concat(options.languageCode, "]"), { options: options }, 404);
266
- }
267
- return [2 /*return*/, data.results[0]];
268
- }
269
- });
270
- });
271
- };
272
- /**
273
- * Query categories
274
- * https://docs.commercetools.com/api/projects/categories#query-categories
275
- */
276
- CommercetoolsApi.prototype.queryCategories = function (options) {
277
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories", method: 'GET' }));
278
- };
279
- /**
280
- * Get the parent categories of a given category. This method returns an array
281
- * of {@see Category} items representing the ancestry of categories for the given
282
- * category id. The list is ordered from top down. In other words, the root
283
- * category is always the first item in the list.
284
- */
285
- CommercetoolsApi.prototype.getCategoryParents = function (options) {
286
- return __awaiter(this, void 0, void 0, function () {
287
- var category, ancestors;
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0: return [4 /*yield*/, this.getCategory(__assign(__assign({}, options), { params: __assign(__assign({}, options.params), { expand: 'ancestors[*]' }) }))];
291
- case 1:
292
- category = _a.sent();
293
- ancestors = category.ancestors.map(function (ref) { return ref.obj; });
294
- ancestors.push(__assign(__assign({}, category), { ancestors: category.ancestors.map(function (ancestor) { return ({ id: ancestor.id, typeId: ancestor.typeId }); }) }));
295
- return [2 /*return*/, ancestors];
296
- }
297
- });
298
- });
299
- };
300
- /**
301
- * Get an individual product by id:
302
- * https://docs.commercetools.com/api/projects/products#get-product-by-id
303
- */
304
- CommercetoolsApi.prototype.getProductById = function (options) {
305
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/".concat(options.id), method: 'GET' }));
306
- };
307
- /**
308
- * Get an individual product by key:
309
- * https://docs.commercetools.com/api/projects/products#get-product-by-key
310
- */
311
- CommercetoolsApi.prototype.getProductByKey = function (options) {
312
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/key=".concat(options.key), method: 'GET' }));
313
- };
314
- /**
315
- * Get a product projection by id
316
- * https://docs.commercetools.com/api/projects/productProjections#get-productprojection-by-id
317
- */
318
- CommercetoolsApi.prototype.getProductProjectionById = function (options) {
319
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/product-projections/".concat(options.id), options.storeKey), method: 'GET' }));
320
- };
321
- /**
322
- * Get a product projection by key
323
- * https://docs.commercetools.com/api/projects/productProjections#get-productprojection-by-key
324
- */
325
- CommercetoolsApi.prototype.getProductProjectionByKey = function (options) {
326
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/product-projections/key=".concat(options.key), options.storeKey), method: 'GET' }));
327
- };
328
- /**
329
- * Get a product projection by searching the slug with a given locale or array of locales
330
- *
331
- * Utilises the product projection query endpoint:
332
- * https://docs.commercetools.com/api/projects/productProjections#query-productprojections
333
- *
334
- * You must pass either the {@see options.languageCode} or {@see options.languageCodes}
335
- * property in the {@see options} parameter. If both are provided, only the {@see options.languageCodes}
336
- * is actually used.
337
- */
338
- CommercetoolsApi.prototype.getProductProjectionBySlug = function (options) {
339
- return __awaiter(this, void 0, void 0, function () {
340
- var languageCodes, data;
341
- return __generator(this, function (_a) {
342
- switch (_a.label) {
343
- case 0:
344
- if (!options.languageCode && !options.languageCodes) {
345
- throw new error_1.CommercetoolsError('Either the `languageCode` or `languageCodes` property must be provided');
346
- }
347
- languageCodes = [];
348
- if (options.languageCodes) {
349
- languageCodes.push.apply(languageCodes, options.languageCodes);
350
- }
351
- else if (options.languageCode) {
352
- languageCodes.push(options.languageCode);
353
- }
354
- return [4 /*yield*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(__assign(__assign({}, options), { params: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.params), { where: "slug(".concat(languageCodes.map(function (code) { return "".concat(code, "=\"").concat(options.slug, "\""); }).join(' or '), ")") }) }))), { path: "/product-projections", method: 'GET' }))];
355
- case 1:
356
- data = _a.sent();
357
- if (!data.count) {
358
- throw new error_1.CommercetoolsError("No product projection found with slug [".concat(options.slug, "] and language code [").concat(options.languageCode, "]"), { options: options }, 404);
359
- }
360
- return [2 /*return*/, data.results[0]];
361
- }
362
- });
363
- });
364
- };
365
- /**
366
- * Query product projections
367
- * https://docs.commercetools.com/api/projects/productProjections#query-productprojections
368
- */
369
- CommercetoolsApi.prototype.queryProductProjections = function (options) {
370
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-projections", method: 'GET' }));
371
- };
372
- /**
373
- * Search product projections
374
- * https://docs.commercetools.com/api/projects/products-search#search-productprojections
375
- */
376
- CommercetoolsApi.prototype.searchProductProjections = function (options) {
377
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-projections/search", method: 'GET' }));
378
- };
379
- /**
380
- * Get a product selection by id
381
- * https://docs.commercetools.com/api/projects/product-selections#get-product-selection
382
- */
383
- CommercetoolsApi.prototype.getProductSelectionById = function (options) {
384
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/product-selections/".concat(options.id), options.storeKey), method: 'GET' }));
385
- };
386
- /**
387
- * Get a product selection by key
388
- * https://docs.commercetools.com/api/projects/product-selections#get-product-selection-by-key
389
- */
390
- CommercetoolsApi.prototype.getProductSelectionByKey = function (options) {
391
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/product-selections/key=".concat(options.key), options.storeKey), method: 'GET' }));
392
- };
393
- /**
394
- * Query product selections
395
- * https://docs.commercetools.com/api/projects/product-selections#query-product-selections
396
- */
397
- CommercetoolsApi.prototype.queryProductSelections = function (options) {
398
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-selections", method: 'GET' }));
399
- };
400
- /**
401
- * Create a product selection
402
- * https://docs.commercetools.com/api/projects/product-selections#create-product-selection
403
- */
404
- CommercetoolsApi.prototype.createProductSelection = function (options) {
405
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-selections", method: 'POST', data: options.data }));
406
- };
407
- /**
408
- * Update a product selection by key
409
- * https://docs.commercetools.com/api/projects/product-selections#update-product-selection-by-key
410
- */
411
- CommercetoolsApi.prototype.updateProductSelectionByKey = function (options) {
412
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-selections/key=".concat(options.key), method: 'POST', data: { version: options.version, actions: options.actions } }));
413
- };
414
- /**
415
- * Delete a product selection by key
416
- * https://docs.commercetools.com/api/projects/product-selections#delete-product-selection-by-key
417
- */
418
- CommercetoolsApi.prototype.deleteProductSelectionByKey = function (options) {
419
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-selections/key=".concat(options.key, "&version=").concat(options.version), method: 'DELETE' }));
420
- };
421
- /**
422
- * Query the products available in a store through active Product Selections
423
- * https://docs.commercetools.com/api/projects/product-selections#query-products-available-in-a-store-through-active-product-selections
424
- */
425
- CommercetoolsApi.prototype.queryProductsInStore = function (options) {
426
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/in-store/key=".concat(options.storeKey, "/product-selection-assignments"), method: "GET" }));
427
- };
428
- /**
429
- * Get a cart by id
430
- * https://docs.commercetools.com/api/projects/carts#update-a-cart-by-id
431
- */
432
- CommercetoolsApi.prototype.getCartById = function (options) {
433
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/carts/".concat(options.id), options.storeKey), method: 'GET' }));
434
- };
435
- /**
436
- * Query carts
437
- * https://docs.commercetools.com/api/projects/carts#query-carts-1
438
- */
439
- CommercetoolsApi.prototype.queryCarts = function (options) {
440
- return __awaiter(this, void 0, void 0, function () {
441
- return __generator(this, function (_a) {
442
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/carts", options === null || options === void 0 ? void 0 : options.storeKey), method: 'GET' }))];
443
- });
444
- });
445
- };
446
- /**
447
- * Query my carts
448
- * https://docs.commercetools.com/api/projects/me-carts#query-carts-1
449
- */
450
- CommercetoolsApi.prototype.queryMyCarts = function (options) {
451
- return __awaiter(this, void 0, void 0, function () {
452
- return __generator(this, function (_a) {
453
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/carts", options.storeKey), method: 'GET', accessToken: options.accessToken }))];
454
- });
455
- });
456
- };
457
- /**
458
- * Create a new cart:
459
- * https://docs.commercetools.com/api/projects/carts#create-a-cart-1
460
- */
461
- CommercetoolsApi.prototype.createCart = function (options) {
462
- return __awaiter(this, void 0, void 0, function () {
463
- return __generator(this, function (_a) {
464
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/carts", options.storeKey), method: 'POST', data: options.data }))];
465
- });
466
- });
467
- };
468
- /**
469
- * Update a cart by id
470
- * https://docs.commercetools.com/api/projects/carts#update-a-cart-by-id
471
- */
472
- CommercetoolsApi.prototype.updateCartById = function (options) {
473
- return __awaiter(this, void 0, void 0, function () {
474
- return __generator(this, function (_a) {
475
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/carts/".concat(options.id), options.storeKey), method: 'POST', data: {
476
- version: options.version,
477
- actions: options.actions,
478
- } }))];
479
- });
480
- });
481
- };
482
- /**
483
- * Get the active cart. Requires a logged in or anonymous customer access token:
484
- * https://docs.commercetools.com/api/projects/me-carts#get-active-cart
485
- */
486
- CommercetoolsApi.prototype.getMyActiveCart = function (options) {
487
- return __awaiter(this, void 0, void 0, function () {
488
- return __generator(this, function (_a) {
489
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/active-cart", options.storeKey), method: 'GET', accessToken: options.accessToken }))];
490
- });
491
- });
492
- };
493
- /**
494
- * Get my cart. Requires a logged in or anonymous customer access token:
495
- * https://docs.commercetools.com/api/projects/me-carts#get-cart-by-id
496
- */
497
- CommercetoolsApi.prototype.getMyCartById = function (options) {
498
- return __awaiter(this, void 0, void 0, function () {
499
- return __generator(this, function (_a) {
500
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/carts/".concat(options.cartId), options.storeKey), method: 'GET', accessToken: options.accessToken }))];
501
- });
502
- });
503
- };
504
- /**
505
- * Create a new cart for the customer associated with the given `accessToken` parameter:
506
- * https://docs.commercetools.com/api/projects/me-carts#create-a-cart-1
507
- */
508
- CommercetoolsApi.prototype.createMyCart = function (options) {
509
- return __awaiter(this, void 0, void 0, function () {
510
- return __generator(this, function (_a) {
511
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/carts", options.storeKey), method: 'POST', data: options.data, accessToken: options.accessToken }))];
512
- });
513
- });
514
- };
515
- /**
516
- * Delete the active cart This method uses {@see getMyActiveCart} to first
517
- * get the active cart, in order to find the cart id and version:
518
- * https://docs.commercetools.com/api/projects/me-carts#delete-a-cart
519
- */
520
- CommercetoolsApi.prototype.deleteMyActiveCart = function (options) {
521
- return __awaiter(this, void 0, void 0, function () {
522
- var cart;
523
- return __generator(this, function (_a) {
524
- switch (_a.label) {
525
- case 0: return [4 /*yield*/, this.getMyActiveCart(options)];
526
- case 1:
527
- cart = _a.sent();
528
- return [4 /*yield*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/carts/".concat(cart.id), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: cart.version }), accessToken: options.accessToken }))];
529
- case 2: return [2 /*return*/, _a.sent()];
530
- }
531
- });
532
- });
533
- };
534
- /**
535
- * Delete my cart by id
536
- * https://docs.commercetools.com/api/projects/me-carts#delete-a-cart
537
- */
538
- CommercetoolsApi.prototype.deleteMyCartById = function (options) {
539
- return __awaiter(this, void 0, void 0, function () {
540
- var cart;
541
- return __generator(this, function (_a) {
542
- switch (_a.label) {
543
- case 0: return [4 /*yield*/, this.getMyCartById(options)];
544
- case 1:
545
- cart = _a.sent();
546
- return [4 /*yield*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/carts/".concat(options.cartId), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: cart.version }), accessToken: options.accessToken }))];
547
- case 2: return [2 /*return*/, _a.sent()];
548
- }
549
- });
550
- });
551
- };
552
- /**
553
- * Update a customer's cart with the given actions. Note that we automatically
554
- * retrieve the customer's active cart using the given access token:
555
- * https://docs.commercetools.com/api/projects/me-carts#update-cart
556
- * https://docs.commercetools.com/api/projects/me-carts#update-actions
557
- */
558
- CommercetoolsApi.prototype.updateMyActiveCart = function (options) {
559
- return __awaiter(this, void 0, void 0, function () {
560
- var cart;
561
- return __generator(this, function (_a) {
562
- switch (_a.label) {
563
- case 0: return [4 /*yield*/, this.getMyActiveCart(options)];
564
- case 1:
565
- cart = _a.sent();
566
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/carts/".concat(cart.id), options.storeKey), method: 'POST', data: {
567
- version: cart.version,
568
- actions: options.actions,
569
- }, accessToken: options.accessToken }))];
570
- }
571
- });
572
- });
573
- };
574
- /**
575
- * Create an order from the given cart id. The cart id and version are automatically
576
- * retrieved by looking up the customers active cart:
577
- * https://docs.commercetools.com/api/projects/me-orders#create-order-from-a-cart
578
- */
579
- CommercetoolsApi.prototype.createMyOrderFromActiveCart = function (options) {
580
- return __awaiter(this, void 0, void 0, function () {
581
- var cart;
582
- return __generator(this, function (_a) {
583
- switch (_a.label) {
584
- case 0: return [4 /*yield*/, this.getMyActiveCart(options)];
585
- case 1:
586
- cart = _a.sent();
587
- return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore('/me/orders', options.storeKey), method: 'POST', data: {
588
- version: cart.version,
589
- id: cart.id,
590
- }, accessToken: options.accessToken }))];
591
- }
592
- });
593
- });
594
- };
595
- /**
596
- * Delete a cart by the given id:
597
- * https://docs.commercetools.com/api/projects/carts#delete-a-cart-by-id
598
- */
599
- CommercetoolsApi.prototype.deleteCartById = function (options) {
600
- return __awaiter(this, void 0, void 0, function () {
601
- return __generator(this, function (_a) {
602
- switch (_a.label) {
603
- case 0: return [4 /*yield*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/carts/".concat(options.id), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }))];
604
- case 1: return [2 /*return*/, _a.sent()];
605
- }
606
- });
607
- });
608
- };
609
- /**
610
- * Create a payment object:
611
- * https://docs.commercetools.com/api/projects/payments#create-a-payment
612
- */
613
- CommercetoolsApi.prototype.createPayment = function (options) {
614
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: '/payments', method: 'POST', data: options.data }));
615
- };
616
- /**
617
- * Delete a payment object by id:
618
- * https://docs.commercetools.com/api/projects/payments#delete-payment-by-id
619
- */
620
- CommercetoolsApi.prototype.deletePaymentById = function (options) {
621
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/payments/".concat(options.id), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
622
- };
623
- /**
624
- * Update a payment object by id:
625
- * https://docs.commercetools.com/api/projects/payments#update-payment-by-id
626
- */
627
- CommercetoolsApi.prototype.updatePaymentById = function (options) {
628
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/payments/".concat(options.id), method: 'POST', data: options.data }));
629
- };
630
- /**
631
- * Get a payment object by id:
632
- * https://docs.commercetools.com/api/projects/payments#get-payment-by-id
633
- */
634
- CommercetoolsApi.prototype.getPaymentById = function (options) {
635
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/payments/".concat(options.id), method: 'GET' }));
636
- };
637
- /**
638
- * Query payment objects:
639
- * https://docs.commercetools.com/api/projects/payments#query-payments
640
- */
641
- CommercetoolsApi.prototype.queryPayments = function (options) {
642
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: '/payments', method: 'GET' }));
643
- };
644
- /**
645
- * Create a payment object using the customer's access token:
646
- * https://docs.commercetools.com/api/projects/me-payments#create-mypayment
647
- */
648
- CommercetoolsApi.prototype.createMyPayment = function (options) {
649
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: '/me/payments', method: 'POST', data: options.data, accessToken: options.accessToken }));
650
- };
651
- /**
652
- * Update a payment object using the customer's access token:
653
- * https://docs.commercetools.com/api/projects/me-payments#update-mypayment
654
- */
655
- CommercetoolsApi.prototype.updateMyPaymentById = function (options) {
656
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/me/payments/".concat(options.id), method: 'POST', data: options.data, accessToken: options.accessToken }));
657
- };
658
- /**
659
- * Get a payment object by id using the customer's access token:
660
- * https://docs.commercetools.com/api/projects/me-payments#get-mypayment-by-id
661
- */
662
- CommercetoolsApi.prototype.getMyPaymentById = function (options) {
663
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/me/payments/".concat(options.id), method: 'GET', accessToken: options.accessToken }));
664
- };
665
- /**
666
- * Query payment objects using the customer's access token:
667
- * https://docs.commercetools.com/api/projects/me-payments#query-mypayments
668
- */
669
- CommercetoolsApi.prototype.queryMyPayments = function (options) {
670
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: '/me/payments', method: 'GET', accessToken: options.accessToken }));
671
- };
672
- /**
673
- * Get an order by id using the customer's access token:
674
- * https://docs.commercetools.com/api/projects/me-orders#get-order-by-id
675
- */
676
- CommercetoolsApi.prototype.getMyOrderById = function (options) {
677
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/orders/".concat(options.id), options.storeKey), method: 'GET', accessToken: options.accessToken }));
678
- };
679
- /**
680
- * Query my orders:
681
- * https://docs.commercetools.com/api/projects/me-orders#query-orders-1
682
- */
683
- CommercetoolsApi.prototype.queryMyOrders = function (options) {
684
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/orders", options.storeKey), method: 'GET', accessToken: options.accessToken }));
685
- };
686
- /**
687
- * Update an order by id:
688
- * https://docs.commercetools.com/api/projects/orders#update-order-by-id
689
- */
690
- CommercetoolsApi.prototype.updateOrderById = function (options) {
691
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders/".concat(options.id), options.storeKey), method: 'POST', data: options.data }));
692
- };
693
- /**
694
- * Update an order by order number:
695
- * https://docs.commercetools.com/api/projects/orders#update-order-by-ordernumber
696
- */
697
- CommercetoolsApi.prototype.updateOrderByOrderNumber = function (options) {
698
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders/order-number=".concat(options.orderNumber), options.storeKey), method: 'POST', data: options.data }));
699
- };
700
- /**
701
- * Get an order by id:
702
- * https://docs.commercetools.com/api/projects/orders#get-order-by-id
703
- */
704
- CommercetoolsApi.prototype.getOrderById = function (options) {
705
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders/".concat(options.id), options.storeKey), method: 'GET' }));
706
- };
707
- /**
708
- * Get an order by order number:
709
- * https://docs.commercetools.com/api/projects/orders#get-order-by-ordernumber
710
- */
711
- CommercetoolsApi.prototype.getOrderByOrderNumber = function (options) {
712
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders/order-number=".concat(options.orderNumber), options.storeKey), method: 'GET' }));
713
- };
714
- /**
715
- * Delete an order by id:
716
- * https://docs.commercetools.com/api/projects/orders#delete-order-by-id
717
- */
718
- CommercetoolsApi.prototype.deleteOrderById = function (options) {
719
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders/".concat(options.id), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version, dataErasure: options.dataErasure }) }));
720
- };
721
- /**
722
- * Delete an order by order number:
723
- * https://docs.commercetools.com/api/projects/orders#delete-order-by-ordernumber
724
- */
725
- CommercetoolsApi.prototype.deleteOrderByOrderNumber = function (options) {
726
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders/order-number=".concat(options.orderNo), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version, dataErasure: options.dataErasure }) }));
727
- };
728
- /**
729
- * Query orders:
730
- * https://docs.commercetools.com/api/projects/orders#query-orders-1
731
- */
732
- CommercetoolsApi.prototype.queryOrders = function (options) {
733
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/orders", options.storeKey), method: 'GET' }));
734
- };
735
- /**
736
- * Create a product:
737
- * https://docs.commercetools.com/api/projects/products#create-a-product
738
- */
739
- CommercetoolsApi.prototype.createProduct = function (options) {
740
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products", method: 'POST', data: options.data }));
741
- };
742
- /**
743
- * Update a product by key:
744
- * https://docs.commercetools.com/api/projects/products#update-product-by-key
745
- */
746
- CommercetoolsApi.prototype.updateProductByKey = function (options) {
747
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/key=".concat(options.key), method: 'POST', data: options.data }));
748
- };
749
- /**
750
- * Update a product by id:
751
- * https://docs.commercetools.com/api/projects/products#update-product-by-id
752
- */
753
- CommercetoolsApi.prototype.updateProductById = function (options) {
754
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/".concat(options.id), method: 'POST', data: options.data }));
755
- };
756
- /**
757
- * Delete a product by id:
758
- * https://docs.commercetools.com/api/projects/products#delete-product-by-id
759
- *
760
- * @param {object} options Request options
761
- * @param {boolean} options.unpublish If true, the product will be unpublished before being deleted
762
- */
763
- CommercetoolsApi.prototype.deleteProductById = function (options) {
764
- return __awaiter(this, void 0, void 0, function () {
765
- var version, product;
766
- return __generator(this, function (_a) {
767
- switch (_a.label) {
768
- case 0:
769
- version = options.version;
770
- if (!options.unpublish) return [3 /*break*/, 2];
771
- return [4 /*yield*/, this.unpublishProductById({
772
- id: options.id,
773
- version: options.version,
774
- })];
775
- case 1:
776
- product = _a.sent();
777
- version = product.version;
778
- _a.label = 2;
779
- case 2: return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/".concat(options.id), method: 'DELETE', params: __assign(__assign({}, options.params), { version: version }) }))];
780
- }
781
- });
782
- });
783
- };
784
- /**
785
- * Delete a product by key:
786
- * https://docs.commercetools.com/api/projects/products#delete-product-by-key
787
- *
788
- * @param {object} options Request options
789
- * @param {boolean} options.unpublish If true, the product will be unpublished before being deleted
790
- */
791
- CommercetoolsApi.prototype.deleteProductByKey = function (options) {
792
- return __awaiter(this, void 0, void 0, function () {
793
- var version, product;
794
- return __generator(this, function (_a) {
795
- switch (_a.label) {
796
- case 0:
797
- version = options.version;
798
- if (!options.unpublish) return [3 /*break*/, 2];
799
- return [4 /*yield*/, this.unpublishProductByKey({
800
- key: options.key,
801
- version: options.version,
802
- })];
803
- case 1:
804
- product = _a.sent();
805
- version = product.version;
806
- _a.label = 2;
807
- case 2: return [2 /*return*/, this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/key=".concat(options.key), method: 'DELETE', params: __assign(__assign({}, options.params), { version: version }) }))];
808
- }
809
- });
810
- });
811
- };
812
- /**
813
- * Unpublish a product by key
814
- *
815
- * Issues an 'unpublish' action for the given product:
816
- * https://docs.commercetools.com/api/projects/products#unpublish
817
- */
818
- CommercetoolsApi.prototype.unpublishProductByKey = function (options) {
819
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/key=".concat(options.key), method: 'POST', params: options.params, data: {
820
- version: options.version,
821
- actions: [{ action: 'unpublish' }],
822
- } }));
823
- };
824
- /**
825
- * Unpublish a product by id
826
- *
827
- * Issues an 'unpublish' action for the given product:
828
- * https://docs.commercetools.com/api/projects/products#unpublish
829
- */
830
- CommercetoolsApi.prototype.unpublishProductById = function (options) {
831
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/products/".concat(options.id), method: 'POST', params: options.params, data: {
832
- version: options.version,
833
- actions: [{ action: 'unpublish' }],
834
- } }));
835
- };
836
- /**
837
- * Create a category:
838
- * https://docs.commercetools.com/api/projects/categories#create-a-category
839
- */
840
- CommercetoolsApi.prototype.createCategory = function (options) {
841
- return this.request({
842
- path: "/categories",
843
- method: 'POST',
844
- data: options.data,
845
- });
846
- };
847
- /**
848
- * Update a category by key:
849
- * https://docs.commercetools.com/api/projects/categories#update-category-by-key
850
- */
851
- CommercetoolsApi.prototype.updateCategoryByKey = function (options) {
852
- return this.request({
853
- path: "/categories/key=".concat(options.key),
854
- method: 'POST',
855
- data: options.data,
856
- });
857
- };
858
- /**
859
- * Update a category by id:
860
- * https://docs.commercetools.com/api/projects/categories#update-category-by-id
861
- */
862
- CommercetoolsApi.prototype.updateCategoryById = function (options) {
863
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/".concat(options.id), method: 'POST', data: options.data }));
864
- };
865
- /**
866
- * Delete a category by id:
867
- * https://docs.commercetools.com/api/projects/categories#delete-category-by-id
868
- */
869
- CommercetoolsApi.prototype.deleteCategoryById = function (options) {
870
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/".concat(options.id), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
871
- };
872
- /**
873
- * Delete a category by key:
874
- * https://docs.commercetools.com/api/projects/categories#delete-category-by-key
875
- */
876
- CommercetoolsApi.prototype.deleteCategoryByKey = function (options) {
877
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/categories/key=".concat(options.key), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
878
- };
879
- /**
880
- * Create a customer account:
881
- * https://docs.commercetools.com/api/projects/customers#create-customer-sign-up
882
- */
883
- CommercetoolsApi.prototype.createAccount = function (options) {
884
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers", options.storeKey), method: 'POST', data: options.data }));
885
- };
886
- /**
887
- * Delete a customer account by id
888
- * https://docs.commercetools.com/api/projects/customers#delete-customer-by-id
889
- */
890
- CommercetoolsApi.prototype.deleteCustomerById = function (options) {
891
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers/".concat(options.id), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version, dataErasure: options.dataErasure }) }));
892
- };
893
- /**
894
- * Delete a customer account by key
895
- * https://docs.commercetools.com/api/projects/customers#delete-customer-by-key
896
- */
897
- CommercetoolsApi.prototype.deleteCustomerByKey = function (options) {
898
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers/key=".concat(options.key), options.storeKey), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version, dataErasure: options.dataErasure }) }));
899
- };
900
- /**
901
- * Create a customer account given an (optional) anonymous access token:
902
- * https://docs.commercetools.com/api/projects/me-profile#create-customer-sign-up
903
- */
904
- CommercetoolsApi.prototype.createMyAccount = function (options) {
905
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/signup", options.storeKey), method: 'POST', data: options.data, accessToken: options.accessToken }));
906
- };
907
- /**
908
- * Login to customer's account given an (optional) anonymous access token:
909
- * https://docs.commercetools.com/api/projects/me-profile#authenticate-customer-sign-in
910
- */
911
- CommercetoolsApi.prototype.loginMyAccount = function (options) {
912
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/login", options.storeKey), method: 'POST', data: options.data, accessToken: options.accessToken }));
913
- };
914
- /**
915
- * Login to customer's account:
916
- * https://docs.commercetools.com/api/projects/customers#authenticate-customer-sign-in
917
- */
918
- CommercetoolsApi.prototype.login = function (options) {
919
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/login", options.storeKey), method: 'POST', data: options.data }));
920
- };
921
- /**
922
- * Get a customer's account/profile:
923
- * https://docs.commercetools.com/api/projects/me-profile#get-customer
924
- */
925
- CommercetoolsApi.prototype.getMyAccount = function (options) {
926
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me", options.storeKey), method: 'GET', accessToken: options.accessToken }));
927
- };
928
- /**
929
- * Update a customer's account/profile:
930
- * https://docs.commercetools.com/api/projects/me-profile#update-customer
931
- */
932
- CommercetoolsApi.prototype.updateMyAccount = function (options) {
933
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me", options.storeKey), method: 'POST', accessToken: options.accessToken, data: options.data }));
934
- };
935
- /**
936
- * Change the customer's password:
937
- * https://docs.commercetools.com/api/projects/me-profile#change-customers-password
938
- */
939
- CommercetoolsApi.prototype.changeMyPassword = function (options) {
940
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/password", options.storeKey), method: 'POST', accessToken: options.accessToken, data: options.data }));
941
- };
942
- /**
943
- * Reset the customer's password:
944
- * https://docs.commercetools.com/api/projects/me-profile#reset-customers-password
945
- */
946
- CommercetoolsApi.prototype.resetMyPassword = function (options) {
947
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/me/password/reset", options.storeKey), method: 'POST', accessToken: options.accessToken, data: options.data }));
948
- };
949
- /**
950
- * Get a password reset token
951
- * https://docs.commercetools.com/api/projects/customers#create-a-token-for-resetting-the-customers-password
952
- */
953
- CommercetoolsApi.prototype.getPasswordResetToken = function (options) {
954
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers/password-token", options.storeKey), method: 'POST', data: options.data }));
955
- };
956
- /**
957
- * Get a customer by id:
958
- * https://docs.commercetools.com/api/projects/customers#get-customer-by-id
959
- */
960
- CommercetoolsApi.prototype.getCustomerById = function (options) {
961
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers/".concat(options.id), options.storeKey), method: 'GET' }));
962
- };
963
- /**
964
- * Get a customer by key:
965
- * https://docs.commercetools.com/api/projects/customers#get-customer-by-key
966
- */
967
- CommercetoolsApi.prototype.getCustomerByKey = function (options) {
968
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers/key=".concat(options.key), options.storeKey), method: 'GET' }));
969
- };
970
- /**
971
- * Get a customer by password token:
972
- * https://docs.commercetools.com/api/projects/customers#get-customer-by-password-token
973
- */
974
- CommercetoolsApi.prototype.getCustomerByPasswordToken = function (options) {
975
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers/password-token=".concat(options.token), options.storeKey), method: 'GET' }));
976
- };
977
- /**
978
- * Query customers:
979
- * https://docs.commercetools.com/api/projects/customers#query-customers
980
- */
981
- CommercetoolsApi.prototype.queryCustomers = function (options) {
982
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: this.applyStore("/customers", options.storeKey), method: 'GET' }));
983
- };
984
- /**
985
- * Update a customer by id:
986
- * https://docs.commercetools.com/api/projects/customers#update-customer-by-id
987
- */
988
- CommercetoolsApi.prototype.updateCustomerById = function (options) {
989
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customers/".concat(options.id), method: 'POST', data: options.data }));
990
- };
991
- /**
992
- * Update a customer by key:
993
- * https://docs.commercetools.com/api/projects/customers#update-customer-by-key
994
- */
995
- CommercetoolsApi.prototype.updateCustomerByKey = function (options) {
996
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customers/key=".concat(options.key), method: 'POST', data: options.data }));
997
- };
998
- /**
999
- * Get a product type by id:
1000
- * https://docs.commercetools.com/api/projects/productTypes#get-a-producttype-by-id
1001
- */
1002
- CommercetoolsApi.prototype.getProductTypeById = function (options) {
1003
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-types/".concat(options.id), method: 'GET' }));
1004
- };
1005
- /**
1006
- * Get a product type by key:
1007
- * https://docs.commercetools.com/api/projects/productTypes#get-a-producttype-by-key
1008
- */
1009
- CommercetoolsApi.prototype.getProductTypeByKey = function (options) {
1010
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/product-types/key=".concat(options.key), method: 'GET' }));
1011
- };
1012
- /**
1013
- * Get a type by id:
1014
- * https://docs.commercetools.com/api/projects/types#get-type-by-id
1015
- */
1016
- CommercetoolsApi.prototype.getTypeById = function (options) {
1017
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/types/".concat(options.id), method: 'GET' }));
1018
- };
1019
- /**
1020
- * Get a type by key:
1021
- * https://docs.commercetools.com/api/projects/types#get-type-by-key
1022
- */
1023
- CommercetoolsApi.prototype.getTypeByKey = function (options) {
1024
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/types/key=".concat(options.key), method: 'GET' }));
1025
- };
1026
- /**
1027
- * Get a discount code by id:
1028
- * https://docs.commercetools.com/api/projects/discountCodes#get-discountcode-by-id
1029
- */
1030
- CommercetoolsApi.prototype.getDiscountCodeById = function (options) {
1031
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/discount-codes/".concat(options.id), method: 'GET' }));
1032
- };
1033
- /**
1034
- * Get a cart discount code by id:
1035
- * https://docs.commercetools.com/api/projects/cartDiscounts#get-cartdiscount-by-id
1036
- */
1037
- CommercetoolsApi.prototype.getCartDiscountById = function (options) {
1038
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/cart-discounts/".concat(options.id), method: 'GET' }));
1039
- };
1040
- /**
1041
- * Get a cart discount by key:
1042
- * https://docs.commercetools.com/api/projects/cartDiscounts#get-cartdiscount-by-key
1043
- */
1044
- CommercetoolsApi.prototype.getCartDiscountByKey = function (options) {
1045
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/cart-discounts/key=".concat(options.key), method: 'GET' }));
1046
- };
1047
- /**
1048
- * Query cart discounts:
1049
- * https://docs.commercetools.com/api/projects/cartDiscounts#query-cartdiscounts
1050
- */
1051
- CommercetoolsApi.prototype.queryCartDiscounts = function (options) {
1052
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/cart-discounts", method: 'GET' }));
1053
- };
1054
- /**
1055
- * Get a custom object
1056
- * https://docs.commercetools.com/api/projects/custom-objects#get-customobject-by-container-and-key
1057
- */
1058
- CommercetoolsApi.prototype.getCustomObject = function (options) {
1059
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/custom-objects/".concat(options.container, "/").concat(options.key), method: 'GET' }));
1060
- };
1061
- /**
1062
- * Get a custom object by id
1063
- * https://docs.commercetools.com/api/projects/custom-objects#get-customobject
1064
- */
1065
- CommercetoolsApi.prototype.getCustomObjectById = function (options) {
1066
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/custom-objects/".concat(options.id), method: 'GET' }));
1067
- };
1068
- /**
1069
- * Save a custom object
1070
- * https://docs.commercetools.com/api/projects/custom-objects#create-or-update-a-customobject
1071
- */
1072
- CommercetoolsApi.prototype.saveCustomObject = function (options) {
1073
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/custom-objects", method: 'POST', data: options.data }));
1074
- };
1075
- /**
1076
- * Delete a custom object
1077
- * https://docs.commercetools.com/api/projects/custom-objects#delete-customobject-by-container-and-key
1078
- */
1079
- CommercetoolsApi.prototype.deleteCustomObject = function (options) {
1080
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/custom-objects/".concat(options.container, "/").concat(options.key), method: 'DELETE' }));
1081
- };
1082
- /**
1083
- * Get a shipping method by id:
1084
- * https://docs.commercetools.com/api/projects/shippingMethods#get-shippingmethod-by-id
1085
- */
1086
- CommercetoolsApi.prototype.getShippingMethodById = function (options) {
1087
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/shipping-methods/".concat(options.id), method: 'GET' }));
1088
- };
1089
- /**
1090
- * Get a shipping method by key:
1091
- * https://docs.commercetools.com/api/projects/shippingMethods#get-shippingmethod-by-key
1092
- */
1093
- CommercetoolsApi.prototype.getShippingMethodByKey = function (options) {
1094
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/shipping-methods/key=".concat(options.key), method: 'GET' }));
1095
- };
1096
- /**
1097
- * Get shipping method by location:
1098
- * https://docs.commercetools.com/api/projects/shippingMethods#get-shippingmethods-for-a-location
1099
- */
1100
- CommercetoolsApi.prototype.getShippingMethodsForLocation = function (options) {
1101
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(__assign(__assign({}, options), { params: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.params), { country: options.country, state: options.state, currency: options.currency }) }))), { path: "/shipping-methods/matching-location", method: 'GET', accessToken: options.accessToken }));
1102
- };
1103
- /**
1104
- * Get shipping methods applicable to a given cart id:
1105
- * https://docs.commercetools.com/api/projects/shippingMethods#get-shippingmethods-for-a-cart
1106
- */
1107
- CommercetoolsApi.prototype.getShippingMethodsForCart = function (options) {
1108
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(__assign(__assign({}, options), { params: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.params), { cartId: options.cartId }) }))), { path: "/shipping-methods/matching-cart", method: 'GET', accessToken: options.accessToken }));
1109
- };
1110
- /**
1111
- * Query shipping methods:
1112
- * https://docs.commercetools.com/api/projects/shippingMethods#query-shippingmethods
1113
- */
1114
- CommercetoolsApi.prototype.queryShippingMethods = function (options) {
1115
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/shipping-methods", method: 'GET' }));
1116
- };
1117
- /**
1118
- * Get an individual customer group by id:
1119
- * https://docs.commercetools.com/api/projects/customerGroups#get-customergroup-by-id
1120
- */
1121
- CommercetoolsApi.prototype.getCustomerGroupById = function (options) {
1122
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customer-groups/".concat(options.id), method: 'GET' }));
1123
- };
1124
- /**
1125
- * Get an individual customer group by key:
1126
- * https://docs.commercetools.com/api/projects/customerGroups#get-customergroup-by-key
1127
- */
1128
- CommercetoolsApi.prototype.getCustomerGroupByKey = function (options) {
1129
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customer-groups/key=".concat(options.key), method: 'GET' }));
1130
- };
1131
- /**
1132
- * Query customer groups:
1133
- * https://docs.commercetools.com/api/projects/customerGroups#query-customergroups
1134
- */
1135
- CommercetoolsApi.prototype.queryCustomerGroups = function (options) {
1136
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customer-groups", method: 'GET' }));
1137
- };
1138
- /**
1139
- * Create a customer group:
1140
- * https://docs.commercetools.com/api/projects/customerGroups#create-a-customergroup
1141
- */
1142
- CommercetoolsApi.prototype.createCustomerGroup = function (options) {
1143
- return this.request({
1144
- path: "/customer-groups",
1145
- method: 'POST',
1146
- data: options.data,
1147
- });
1148
- };
1149
- /**
1150
- * Update a customer group by key:
1151
- * https://docs.commercetools.com/api/projects/customerGroups#update-customergroup-by-key
1152
- */
1153
- CommercetoolsApi.prototype.updateCustomerGroupByKey = function (options) {
1154
- return this.request({
1155
- path: "/customer-groups/key=".concat(options.key),
1156
- method: 'POST',
1157
- data: options.data,
1158
- });
1159
- };
1160
- /**
1161
- * Update a customer group by id:
1162
- * https://docs.commercetools.com/api/projects/customerGroups#update-customergroup-by-id
1163
- */
1164
- CommercetoolsApi.prototype.updateCustomerGroupById = function (options) {
1165
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customer-groups/".concat(options.id), method: 'POST', data: options.data }));
1166
- };
1167
- /**
1168
- * Delete a customer group by id:
1169
- * https://docs.commercetools.com/api/projects/customerGroups#delete-customergroup-by-id
1170
- */
1171
- CommercetoolsApi.prototype.deleteCustomerGroupById = function (options) {
1172
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customer-groups/".concat(options.id), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
1173
- };
1174
- /**
1175
- * Delete a customer group by key:
1176
- * https://docs.commercetools.com/api/projects/customerGroups#delete-customergroup-by-key
1177
- */
1178
- CommercetoolsApi.prototype.deleteCustomerGroupByKey = function (options) {
1179
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/customer-groups/key=".concat(options.key), method: 'DELETE', params: __assign(__assign({}, options.params), { version: options.version }) }));
1180
- };
1181
- /**
1182
- * Execute a GraphQL statement:
1183
- * https://docs.commercetools.com/api/graphql
1184
- */
1185
- CommercetoolsApi.prototype.graphql = function (options) {
1186
- return this.request(__assign(__assign({}, this.extractCommonRequestOptions(options)), { path: "/graphql", method: 'POST', data: options.data, accessToken: options.accessToken }));
1187
- };
1188
- /**
1189
- * Make the request to the commercetools REST API.
1190
- */
1191
- CommercetoolsApi.prototype.request = function (options) {
1192
- return __awaiter(this, void 0, void 0, function () {
1193
- var requestConfig, retryConfig, retryCount, lastError, _loop_1, this_1, state_1;
1194
- return __generator(this, function (_a) {
1195
- switch (_a.label) {
1196
- case 0: return [4 /*yield*/, this.getRequestOptions(options)];
1197
- case 1:
1198
- requestConfig = _a.sent();
1199
- retryConfig = this.getRetryConfig(options.retry);
1200
- retryCount = 0;
1201
- _loop_1 = function () {
1202
- var delay_1, response, error_2;
1203
- return __generator(this, function (_b) {
1204
- switch (_b.label) {
1205
- case 0:
1206
- if (!(retryCount > 0)) return [3 /*break*/, 2];
1207
- delay_1 = this_1.calculateDelay(retryCount, retryConfig);
1208
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, delay_1); })];
1209
- case 1:
1210
- _b.sent();
1211
- _b.label = 2;
1212
- case 2:
1213
- _b.trys.push([2, 4, , 5]);
1214
- return [4 /*yield*/, this_1.axios(requestConfig)];
1215
- case 3:
1216
- response = _b.sent();
1217
- return [2 /*return*/, { value: response.data }];
1218
- case 4:
1219
- error_2 = _b.sent();
1220
- if (this_1.isRetryableError(error_2)) {
1221
- lastError = error_2;
1222
- }
1223
- else {
1224
- throw this_1.transformError(error_2);
1225
- }
1226
- return [3 /*break*/, 5];
1227
- case 5:
1228
- retryCount++;
1229
- return [2 /*return*/];
1230
- }
1231
- });
1232
- };
1233
- this_1 = this;
1234
- _a.label = 2;
1235
- case 2: return [5 /*yield**/, _loop_1()];
1236
- case 3:
1237
- state_1 = _a.sent();
1238
- if (typeof state_1 === "object")
1239
- return [2 /*return*/, state_1.value];
1240
- _a.label = 4;
1241
- case 4:
1242
- if (retryCount <= retryConfig.maxRetries) return [3 /*break*/, 2];
1243
- _a.label = 5;
1244
- case 5: throw this.transformError(lastError);
1245
- }
1246
- });
1247
- });
1248
- };
1249
- /**
1250
- * Get the {@see CommercetoolsRetryConfig} for this request.
1251
- * Uses the class instance's retry config and merges and additional
1252
- * config passed in via the request options.
1253
- */
1254
- CommercetoolsApi.prototype.getRetryConfig = function (methodRetryConfig) {
1255
- return methodRetryConfig || this.retry;
1256
- };
1257
- /**
1258
- * Generate request options. These are then fed in to axios when
1259
- * making the request to commercetools.
1260
- */
1261
- CommercetoolsApi.prototype.getRequestOptions = function (options) {
1262
- return __awaiter(this, void 0, void 0, function () {
1263
- var accessToken, url, opts, grant, headers;
1264
- return __generator(this, function (_a) {
1265
- switch (_a.label) {
1266
- case 0:
1267
- accessToken = options.accessToken;
1268
- url = "".concat(this.endpoints.api, "/").concat(this.config.projectKey).concat(options.path);
1269
- opts = __assign({}, options);
1270
- opts.path && delete opts.path;
1271
- opts.accessToken && delete opts.accessToken;
1272
- if (!!accessToken) return [3 /*break*/, 2];
1273
- return [4 /*yield*/, this.auth.getClientGrant()];
1274
- case 1:
1275
- grant = _a.sent();
1276
- accessToken = grant.accessToken;
1277
- _a.label = 2;
1278
- case 2:
1279
- headers = __assign(__assign(__assign({}, this.axios.defaults.headers), { Authorization: "Bearer ".concat(accessToken) }), opts.headers);
1280
- if (typeof options.correlationId === 'string' && options.correlationId !== '') {
1281
- headers['X-Correlation-ID'] = options.correlationId;
1282
- delete options.correlationId;
1283
- }
1284
- return [2 /*return*/, __assign(__assign({}, opts), { url: url, headers: headers })];
1285
- }
1286
- });
1287
- });
1288
- };
1289
- /**
1290
- * Calculate how long to delay before running the request.
1291
- * For each retry attempt, we increase the time that we delay for.
1292
- */
1293
- CommercetoolsApi.prototype.calculateDelay = function (retryCount, retryConfig) {
1294
- if (!retryConfig || retryCount === 0) {
1295
- return 0;
1296
- }
1297
- // `retryCount` will be at least 1 at this point
1298
- var exponentialDelay = retryConfig.delayMs * Math.pow(2, (retryCount - 1));
1299
- if (retryConfig.jitter) {
1300
- // A 'full' jitter calculation usually just calculates the delay value
1301
- // by selecting a random value between zero and the standard exponential
1302
- // delay value (calculated above). This next line increases the exponential
1303
- // delay by a factor that reduces for each further request. This ensures
1304
- // more variance on earlier requests.
1305
- var increasedDelay = exponentialDelay * (1 + 1 / (retryCount + 1));
1306
- return Math.floor(Math.random() * increasedDelay);
1307
- }
1308
- else {
1309
- // Assuming a `delayMs` of 500, you'd get the following responses for
1310
- // the given `retryCount` value: 1 = 500, 2 = 1000, 3 = 2000, 4 = 4000
1311
- return exponentialDelay;
1312
- }
1313
- };
1314
- /**
1315
- * Determine whether the given error means we should allow the request
1316
- * to be retried (assuming retry config is provided).
1317
- */
1318
- CommercetoolsApi.prototype.isRetryableError = function (error) {
1319
- // If the error isn't an axios error, then something serious
1320
- // went wrong. Probably a coding error in this package. We should
1321
- // never really hit this scenario.
1322
- if (!error.isAxiosError) {
1323
- return true;
1324
- }
1325
- // If axios makes a request successfully, the `request` property will
1326
- // be defined. Equally, if it received a response, the `response` property
1327
- // will be defined. If either is not defined then we assume there was
1328
- // a serious connectivity issue and allow the request to be retried.
1329
- if (!error.request || !error.response) {
1330
- return true;
1331
- }
1332
- // Finally we only allow requests to be retried if the status code
1333
- // returned is in the given list
1334
- // @TODO - commercetools returns a 502 error when an extension returns
1335
- // update actions that are not actionable by commercetools:
1336
- // https://docs.commercetools.com/api/errors#502-extension-update-actions-failed
1337
- // In this scenario, we should probably not retry the request as
1338
- // this may result in successful update actions being re-run
1339
- return RETRYABLE_STATUS_CODES.includes(error.response.status);
1340
- };
1341
- /**
1342
- * Type-guard against any additional unexpected properties being passed in.
1343
- */
1344
- CommercetoolsApi.prototype.extractCommonRequestOptions = function (options) {
1345
- if (!options) {
1346
- return {};
1347
- }
1348
- return {
1349
- correlationId: options.correlationId,
1350
- params: options.params,
1351
- retry: options.retry,
1352
- };
1353
- };
1354
- /**
1355
- * Applies the store key to a given path
1356
- */
1357
- CommercetoolsApi.prototype.applyStore = function (path, storeKey) {
1358
- if (typeof storeKey === 'string' && storeKey !== '') {
1359
- return "/in-store/key=".concat(storeKey).concat(path);
1360
- }
1361
- else if (this.config.storeKey) {
1362
- return "/in-store/key=".concat(this.config.storeKey).concat(path);
1363
- }
1364
- return path;
1365
- };
1366
- /**
1367
- * Transform an unknown error in to a {@see CommercetoolsError}
1368
- * if the error we receive is from axios.
1369
- */
1370
- CommercetoolsApi.prototype.transformError = function (lastError) {
1371
- if (lastError.isAxiosError) {
1372
- return error_1.CommercetoolsError.fromAxiosError(lastError);
1373
- }
1374
- return lastError;
1375
- };
1376
- /**
1377
- * Ensure that all required properties on the {@see CommercetoolsApiConfig}
1378
- * object have been populated. These are currently:
1379
- *
1380
- * projectKey: string
1381
- * clientId: string
1382
- * clientSecret: string
1383
- * region: Region
1384
- * clientScopes: string[]
1385
- */
1386
- CommercetoolsApi.validateConfig = function (config) {
1387
- var errors = [];
1388
- if (!config) {
1389
- errors.push('The config object missing or empty');
1390
- }
1391
- else {
1392
- if (!config.projectKey) {
1393
- errors.push('The `projectKey` property is empty');
1394
- }
1395
- else if (typeof config.projectKey !== 'string') {
1396
- errors.push('The `projectKey` property must be a string');
1397
- }
1398
- if (!config.clientId) {
1399
- errors.push('The `clientId` property is empty');
1400
- }
1401
- else if (typeof config.clientId !== 'string') {
1402
- errors.push('The `clientId` property must be a string');
1403
- }
1404
- if (!config.clientSecret) {
1405
- errors.push('The `clientSecret` property is empty');
1406
- }
1407
- else if (typeof config.clientSecret !== 'string') {
1408
- errors.push('The `clientSecret` property must be a string');
1409
- }
1410
- if (!Array.isArray(config.clientScopes)) {
1411
- errors.push('The `clientScopes` property must be an array');
1412
- }
1413
- else if (config.clientScopes.length === 0) {
1414
- errors.push('The `clientScopes` property must have at least 1 scope defined');
1415
- }
1416
- }
1417
- if (errors.length) {
1418
- throw new error_1.CommercetoolsError('The configuration object passed in to the `CommercetoolsApi` constructor is not valid: \n' +
1419
- errors.map(function (error) { return "\u2022 ".concat(error); }).join('\n'));
1420
- }
1421
- };
1422
- return CommercetoolsApi;
1423
- }());
1424
- exports.CommercetoolsApi = CommercetoolsApi;
1425
- //# sourceMappingURL=CommercetoolsApi.js.map