@shushed/helpers 0.0.202 → 0.0.203-bug-erp-770-20251208112219

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 (290) hide show
  1. package/dist/index.d.ts +34970 -0
  2. package/dist/index.js +113321 -0
  3. package/dist/package.json +3 -6
  4. package/package.json +4 -7
  5. package/dist/cjs/contracts/asset.schema.json +0 -78
  6. package/dist/cjs/contracts/category.schema.json +0 -86
  7. package/dist/cjs/contracts/country.schema.json +0 -258
  8. package/dist/cjs/contracts/currency.schema.json +0 -177
  9. package/dist/cjs/contracts/customer-segment.schema.json +0 -32
  10. package/dist/cjs/contracts/development-colour.schema.json +0 -97
  11. package/dist/cjs/contracts/index.js +0 -48
  12. package/dist/cjs/contracts/marketing-preferences.schema.json +0 -41
  13. package/dist/cjs/contracts/messages/ean-change.schema.json +0 -22
  14. package/dist/cjs/contracts/messages/index.js +0 -29
  15. package/dist/cjs/contracts/messages/order/delivered.schema.json +0 -26
  16. package/dist/cjs/contracts/messages/order/index.js +0 -18
  17. package/dist/cjs/contracts/messages/order/new.schema.json +0 -32
  18. package/dist/cjs/contracts/messages/order/processed.schema.json +0 -15
  19. package/dist/cjs/contracts/messages/order/return-initiated.schema.json +0 -26
  20. package/dist/cjs/contracts/messages/order/returned.schema.json +0 -25
  21. package/dist/cjs/contracts/messages/order/shipped.schema.json +0 -26
  22. package/dist/cjs/contracts/messages/product-category.schema.json +0 -21
  23. package/dist/cjs/contracts/messages/product-draft.schema.json +0 -66
  24. package/dist/cjs/contracts/messages/product.schema.json +0 -29
  25. package/dist/cjs/contracts/money.schema.json +0 -54
  26. package/dist/cjs/contracts/order/address.schema.json +0 -127
  27. package/dist/cjs/contracts/order/customer.schema.json +0 -149
  28. package/dist/cjs/contracts/order/index.js +0 -31
  29. package/dist/cjs/contracts/order/item.schema.json +0 -98
  30. package/dist/cjs/contracts/order/payment.schema.json +0 -115
  31. package/dist/cjs/contracts/order/shipment/index.js +0 -29
  32. package/dist/cjs/contracts/order/shipment/item/index.js +0 -8
  33. package/dist/cjs/contracts/order/shipment/item/returned.schema.json +0 -30
  34. package/dist/cjs/contracts/order/shipment/item.schema.json +0 -22
  35. package/dist/cjs/contracts/order/shipment/pos/index.js +0 -10
  36. package/dist/cjs/contracts/order/shipment/pos/outbound.schema.json +0 -37
  37. package/dist/cjs/contracts/order/shipment/pos/return.schema.json +0 -31
  38. package/dist/cjs/contracts/order/shipment/pos.schema.json +0 -48
  39. package/dist/cjs/contracts/order/shipment/shipped/index.js +0 -10
  40. package/dist/cjs/contracts/order/shipment/shipped/outbound.schema.json +0 -34
  41. package/dist/cjs/contracts/order/shipment/shipped/return.schema.json +0 -43
  42. package/dist/cjs/contracts/order/shipment/shipped.schema.json +0 -52
  43. package/dist/cjs/contracts/order/shipment.schema.json +0 -58
  44. package/dist/cjs/contracts/order.schema.json +0 -231
  45. package/dist/cjs/contracts/product-category.schema.json +0 -34
  46. package/dist/cjs/contracts/product-draft.schema.json +0 -782
  47. package/dist/cjs/contracts/product.schema.json +0 -816
  48. package/dist/cjs/contracts/total.schema.json +0 -41
  49. package/dist/cjs/dist-dereferenced/asset.js +0 -4
  50. package/dist/cjs/dist-dereferenced/category.js +0 -4
  51. package/dist/cjs/dist-dereferenced/country.js +0 -4
  52. package/dist/cjs/dist-dereferenced/currency.js +0 -4
  53. package/dist/cjs/dist-dereferenced/customer-segment.js +0 -4
  54. package/dist/cjs/dist-dereferenced/development-colour.js +0 -4
  55. package/dist/cjs/dist-dereferenced/index.js +0 -69
  56. package/dist/cjs/dist-dereferenced/marketing-preferences.js +0 -4
  57. package/dist/cjs/dist-dereferenced/messages/ean-change.js +0 -4
  58. package/dist/cjs/dist-dereferenced/messages/index.js +0 -50
  59. package/dist/cjs/dist-dereferenced/messages/order/delivered.js +0 -4
  60. package/dist/cjs/dist-dereferenced/messages/order/index.js +0 -18
  61. package/dist/cjs/dist-dereferenced/messages/order/new.js +0 -4
  62. package/dist/cjs/dist-dereferenced/messages/order/processed.js +0 -4
  63. package/dist/cjs/dist-dereferenced/messages/order/return-initiated.js +0 -4
  64. package/dist/cjs/dist-dereferenced/messages/order/returned.js +0 -4
  65. package/dist/cjs/dist-dereferenced/messages/order/shipped.js +0 -4
  66. package/dist/cjs/dist-dereferenced/messages/price-change.js +0 -4
  67. package/dist/cjs/dist-dereferenced/messages/product-category.js +0 -4
  68. package/dist/cjs/dist-dereferenced/messages/product-draft.js +0 -4
  69. package/dist/cjs/dist-dereferenced/messages/product.js +0 -4
  70. package/dist/cjs/dist-dereferenced/money.js +0 -4
  71. package/dist/cjs/dist-dereferenced/order/address.js +0 -4
  72. package/dist/cjs/dist-dereferenced/order/customer.js +0 -4
  73. package/dist/cjs/dist-dereferenced/order/index.js +0 -51
  74. package/dist/cjs/dist-dereferenced/order/item.js +0 -4
  75. package/dist/cjs/dist-dereferenced/order/orderMain.js +0 -4
  76. package/dist/cjs/dist-dereferenced/order/payment.js +0 -4
  77. package/dist/cjs/dist-dereferenced/order/shipment/index.js +0 -45
  78. package/dist/cjs/dist-dereferenced/order/shipment/item/index.js +0 -11
  79. package/dist/cjs/dist-dereferenced/order/shipment/item/itemMain.js +0 -4
  80. package/dist/cjs/dist-dereferenced/order/shipment/item/returned.js +0 -4
  81. package/dist/cjs/dist-dereferenced/order/shipment/pos/index.js +0 -13
  82. package/dist/cjs/dist-dereferenced/order/shipment/pos/outbound.js +0 -4
  83. package/dist/cjs/dist-dereferenced/order/shipment/pos/posMain.js +0 -4
  84. package/dist/cjs/dist-dereferenced/order/shipment/pos/return.js +0 -4
  85. package/dist/cjs/dist-dereferenced/order/shipment/shipmentMain.js +0 -4
  86. package/dist/cjs/dist-dereferenced/order/shipment/shipped/index.js +0 -13
  87. package/dist/cjs/dist-dereferenced/order/shipment/shipped/outbound.js +0 -4
  88. package/dist/cjs/dist-dereferenced/order/shipment/shipped/return.js +0 -4
  89. package/dist/cjs/dist-dereferenced/order/shipment/shipped/shippedMain.js +0 -4
  90. package/dist/cjs/dist-dereferenced/price.js +0 -4
  91. package/dist/cjs/dist-dereferenced/product-category.js +0 -4
  92. package/dist/cjs/dist-dereferenced/product-draft.js +0 -4
  93. package/dist/cjs/dist-dereferenced/product.js +0 -4
  94. package/dist/cjs/dist-dereferenced/stock.js +0 -4
  95. package/dist/cjs/dist-dereferenced/total.js +0 -4
  96. package/dist/cjs/dist-types/asset.js +0 -2
  97. package/dist/cjs/dist-types/category.js +0 -2
  98. package/dist/cjs/dist-types/country.js +0 -2
  99. package/dist/cjs/dist-types/currency.js +0 -2
  100. package/dist/cjs/dist-types/customer-segment.js +0 -2
  101. package/dist/cjs/dist-types/development-colour.js +0 -2
  102. package/dist/cjs/dist-types/index.js +0 -38
  103. package/dist/cjs/dist-types/marketing-preferences.js +0 -2
  104. package/dist/cjs/dist-types/messages/ean-change.js +0 -2
  105. package/dist/cjs/dist-types/messages/index.js +0 -37
  106. package/dist/cjs/dist-types/messages/order/delivered.js +0 -2
  107. package/dist/cjs/dist-types/messages/order/index.js +0 -2
  108. package/dist/cjs/dist-types/messages/order/new.js +0 -2
  109. package/dist/cjs/dist-types/messages/order/processed.js +0 -2
  110. package/dist/cjs/dist-types/messages/order/return-initiated.js +0 -2
  111. package/dist/cjs/dist-types/messages/order/returned.js +0 -2
  112. package/dist/cjs/dist-types/messages/order/shipped.js +0 -2
  113. package/dist/cjs/dist-types/messages/price-change.js +0 -2
  114. package/dist/cjs/dist-types/messages/product-category.js +0 -2
  115. package/dist/cjs/dist-types/messages/product-draft.js +0 -2
  116. package/dist/cjs/dist-types/messages/product.js +0 -2
  117. package/dist/cjs/dist-types/money.js +0 -2
  118. package/dist/cjs/dist-types/order/address.js +0 -2
  119. package/dist/cjs/dist-types/order/customer.js +0 -2
  120. package/dist/cjs/dist-types/order/index.js +0 -37
  121. package/dist/cjs/dist-types/order/item.js +0 -2
  122. package/dist/cjs/dist-types/order/orderMain.js +0 -2
  123. package/dist/cjs/dist-types/order/payment.js +0 -2
  124. package/dist/cjs/dist-types/order/shipment/index.js +0 -39
  125. package/dist/cjs/dist-types/order/shipment/item/index.js +0 -2
  126. package/dist/cjs/dist-types/order/shipment/item/itemMain.js +0 -2
  127. package/dist/cjs/dist-types/order/shipment/item/returned.js +0 -2
  128. package/dist/cjs/dist-types/order/shipment/pos/index.js +0 -2
  129. package/dist/cjs/dist-types/order/shipment/pos/outbound.js +0 -2
  130. package/dist/cjs/dist-types/order/shipment/pos/posMain.js +0 -2
  131. package/dist/cjs/dist-types/order/shipment/pos/return.js +0 -2
  132. package/dist/cjs/dist-types/order/shipment/shipmentMain.js +0 -2
  133. package/dist/cjs/dist-types/order/shipment/shipped/index.js +0 -2
  134. package/dist/cjs/dist-types/order/shipment/shipped/outbound.js +0 -2
  135. package/dist/cjs/dist-types/order/shipment/shipped/return.js +0 -2
  136. package/dist/cjs/dist-types/order/shipment/shipped/shippedMain.js +0 -2
  137. package/dist/cjs/dist-types/price.js +0 -2
  138. package/dist/cjs/dist-types/product-category.js +0 -2
  139. package/dist/cjs/dist-types/product-draft.js +0 -2
  140. package/dist/cjs/dist-types/product.js +0 -2
  141. package/dist/cjs/dist-types/stock.js +0 -2
  142. package/dist/cjs/dist-types/total.js +0 -2
  143. package/dist/cjs/index.js +0 -39
  144. package/dist/cjs/src-public/airtable.js +0 -625
  145. package/dist/cjs/src-public/bcOrder.js +0 -943
  146. package/dist/cjs/src-public/bigquery.js +0 -59
  147. package/dist/cjs/src-public/centra.js +0 -1053
  148. package/dist/cjs/src-public/cloudtasks.js +0 -207
  149. package/dist/cjs/src-public/dato.js +0 -403
  150. package/dist/cjs/src-public/env.js +0 -900
  151. package/dist/cjs/src-public/getEventTime.js +0 -28
  152. package/dist/cjs/src-public/index.js +0 -54
  153. package/dist/cjs/src-public/ipValidation.js +0 -167
  154. package/dist/cjs/src-public/jwks.js +0 -108
  155. package/dist/cjs/src-public/pubsub.js +0 -423
  156. package/dist/cjs/src-public/rateLimit.js +0 -140
  157. package/dist/cjs/src-public/redisClient.js +0 -44
  158. package/dist/cjs/src-public/runtime.js +0 -145
  159. package/dist/cjs/src-public/sanitize.js +0 -25
  160. package/dist/cjs/src-public/scheduler.js +0 -247
  161. package/dist/cjs/src-public/secret.js +0 -16
  162. package/dist/cjs/src-public/setHeaders.js +0 -16
  163. package/dist/cjs/src-public/types.js +0 -2
  164. package/dist/cjs/src-public/utils.js +0 -457
  165. package/dist/cjs/src-public/validate.js +0 -74
  166. package/dist/types/contracts/index.d.ts +0 -15
  167. package/dist/types/contracts/messages/index.d.ts +0 -5
  168. package/dist/types/contracts/messages/order/index.d.ts +0 -6
  169. package/dist/types/contracts/order/index.d.ts +0 -6
  170. package/dist/types/contracts/order/shipment/index.d.ts +0 -6
  171. package/dist/types/contracts/order/shipment/item/index.d.ts +0 -1
  172. package/dist/types/contracts/order/shipment/pos/index.d.ts +0 -2
  173. package/dist/types/contracts/order/shipment/shipped/index.d.ts +0 -2
  174. package/dist/types/dist-dereferenced/asset.d.ts +0 -51
  175. package/dist/types/dist-dereferenced/category.d.ts +0 -58
  176. package/dist/types/dist-dereferenced/country.d.ts +0 -8
  177. package/dist/types/dist-dereferenced/currency.d.ts +0 -8
  178. package/dist/types/dist-dereferenced/customer-segment.d.ts +0 -26
  179. package/dist/types/dist-dereferenced/development-colour.d.ts +0 -114
  180. package/dist/types/dist-dereferenced/index.d.ts +0 -16
  181. package/dist/types/dist-dereferenced/marketing-preferences.d.ts +0 -31
  182. package/dist/types/dist-dereferenced/messages/ean-change.d.ts +0 -17
  183. package/dist/types/dist-dereferenced/messages/index.d.ts +0 -6
  184. package/dist/types/dist-dereferenced/messages/order/delivered.d.ts +0 -3438
  185. package/dist/types/dist-dereferenced/messages/order/index.d.ts +0 -6
  186. package/dist/types/dist-dereferenced/messages/order/new.d.ts +0 -3438
  187. package/dist/types/dist-dereferenced/messages/order/processed.d.ts +0 -3432
  188. package/dist/types/dist-dereferenced/messages/order/return-initiated.d.ts +0 -3438
  189. package/dist/types/dist-dereferenced/messages/order/returned.d.ts +0 -3437
  190. package/dist/types/dist-dereferenced/messages/order/shipped.d.ts +0 -3436
  191. package/dist/types/dist-dereferenced/messages/price-change.d.ts +0 -67
  192. package/dist/types/dist-dereferenced/messages/product-category.d.ts +0 -33
  193. package/dist/types/dist-dereferenced/messages/product-draft.d.ts +0 -589
  194. package/dist/types/dist-dereferenced/messages/product.d.ts +0 -628
  195. package/dist/types/dist-dereferenced/money.d.ts +0 -41
  196. package/dist/types/dist-dereferenced/order/address.d.ts +0 -98
  197. package/dist/types/dist-dereferenced/order/customer.d.ts +0 -312
  198. package/dist/types/dist-dereferenced/order/index.d.ts +0 -3428
  199. package/dist/types/dist-dereferenced/order/item.d.ts +0 -339
  200. package/dist/types/dist-dereferenced/order/orderMain.d.ts +0 -3423
  201. package/dist/types/dist-dereferenced/order/payment.d.ts +0 -110
  202. package/dist/types/dist-dereferenced/order/shipment/index.d.ts +0 -253
  203. package/dist/types/dist-dereferenced/order/shipment/item/index.d.ts +0 -19
  204. package/dist/types/dist-dereferenced/order/shipment/item/itemMain.d.ts +0 -18
  205. package/dist/types/dist-dereferenced/order/shipment/item/returned.d.ts +0 -34
  206. package/dist/types/dist-dereferenced/order/shipment/pos/index.d.ts +0 -282
  207. package/dist/types/dist-dereferenced/order/shipment/pos/outbound.d.ts +0 -319
  208. package/dist/types/dist-dereferenced/order/shipment/pos/posMain.d.ts +0 -280
  209. package/dist/types/dist-dereferenced/order/shipment/pos/return.d.ts +0 -330
  210. package/dist/types/dist-dereferenced/order/shipment/shipmentMain.d.ts +0 -250
  211. package/dist/types/dist-dereferenced/order/shipment/shipped/index.d.ts +0 -288
  212. package/dist/types/dist-dereferenced/order/shipment/shipped/outbound.d.ts +0 -286
  213. package/dist/types/dist-dereferenced/order/shipment/shipped/return.d.ts +0 -287
  214. package/dist/types/dist-dereferenced/order/shipment/shipped/shippedMain.d.ts +0 -286
  215. package/dist/types/dist-dereferenced/price.d.ts +0 -58
  216. package/dist/types/dist-dereferenced/product-category.d.ts +0 -24
  217. package/dist/types/dist-dereferenced/product-draft.d.ts +0 -580
  218. package/dist/types/dist-dereferenced/product.d.ts +0 -619
  219. package/dist/types/dist-dereferenced/stock.d.ts +0 -74
  220. package/dist/types/dist-dereferenced/total.d.ts +0 -172
  221. package/dist/types/dist-types/asset.d.ts +0 -16
  222. package/dist/types/dist-types/category.d.ts +0 -20
  223. package/dist/types/dist-types/country.d.ts +0 -2
  224. package/dist/types/dist-types/currency.d.ts +0 -2
  225. package/dist/types/dist-types/customer-segment.d.ts +0 -6
  226. package/dist/types/dist-types/development-colour.d.ts +0 -31
  227. package/dist/types/dist-types/index.d.ts +0 -16
  228. package/dist/types/dist-types/marketing-preferences.d.ts +0 -9
  229. package/dist/types/dist-types/messages/ean-change.d.ts +0 -5
  230. package/dist/types/dist-types/messages/index.d.ts +0 -6
  231. package/dist/types/dist-types/messages/order/delivered.d.ts +0 -300
  232. package/dist/types/dist-types/messages/order/index.d.ts +0 -6
  233. package/dist/types/dist-types/messages/order/new.d.ts +0 -300
  234. package/dist/types/dist-types/messages/order/processed.d.ts +0 -300
  235. package/dist/types/dist-types/messages/order/return-initiated.d.ts +0 -300
  236. package/dist/types/dist-types/messages/order/returned.d.ts +0 -301
  237. package/dist/types/dist-types/messages/order/shipped.d.ts +0 -301
  238. package/dist/types/dist-types/messages/price-change.d.ts +0 -16
  239. package/dist/types/dist-types/messages/product-category.d.ts +0 -7
  240. package/dist/types/dist-types/messages/product-draft.d.ts +0 -136
  241. package/dist/types/dist-types/messages/product.d.ts +0 -144
  242. package/dist/types/dist-types/money.d.ts +0 -11
  243. package/dist/types/dist-types/order/address.d.ts +0 -27
  244. package/dist/types/dist-types/order/customer.d.ts +0 -82
  245. package/dist/types/dist-types/order/index.d.ts +0 -8
  246. package/dist/types/dist-types/order/item.d.ts +0 -86
  247. package/dist/types/dist-types/order/orderMain.d.ts +0 -297
  248. package/dist/types/dist-types/order/payment.d.ts +0 -30
  249. package/dist/types/dist-types/order/shipment/index.d.ts +0 -6
  250. package/dist/types/dist-types/order/shipment/item/index.d.ts +0 -4
  251. package/dist/types/dist-types/order/shipment/item/itemMain.d.ts +0 -6
  252. package/dist/types/dist-types/order/shipment/item/returned.d.ts +0 -11
  253. package/dist/types/dist-types/order/shipment/pos/index.d.ts +0 -5
  254. package/dist/types/dist-types/order/shipment/pos/outbound.d.ts +0 -76
  255. package/dist/types/dist-types/order/shipment/pos/posMain.d.ts +0 -71
  256. package/dist/types/dist-types/order/shipment/pos/return.d.ts +0 -75
  257. package/dist/types/dist-types/order/shipment/shipmentMain.d.ts +0 -62
  258. package/dist/types/dist-types/order/shipment/shipped/index.d.ts +0 -5
  259. package/dist/types/dist-types/order/shipment/shipped/outbound.d.ts +0 -68
  260. package/dist/types/dist-types/order/shipment/shipped/return.d.ts +0 -68
  261. package/dist/types/dist-types/order/shipment/shipped/shippedMain.d.ts +0 -69
  262. package/dist/types/dist-types/price.d.ts +0 -15
  263. package/dist/types/dist-types/product-category.d.ts +0 -6
  264. package/dist/types/dist-types/product-draft.d.ts +0 -135
  265. package/dist/types/dist-types/product.d.ts +0 -143
  266. package/dist/types/dist-types/stock.d.ts +0 -19
  267. package/dist/types/dist-types/total.d.ts +0 -44
  268. package/dist/types/index.d.ts +0 -3
  269. package/dist/types/src-public/airtable.d.ts +0 -227
  270. package/dist/types/src-public/bcOrder.d.ts +0 -84
  271. package/dist/types/src-public/bigquery.d.ts +0 -17
  272. package/dist/types/src-public/centra.d.ts +0 -176
  273. package/dist/types/src-public/cloudtasks.d.ts +0 -74
  274. package/dist/types/src-public/dato.d.ts +0 -62
  275. package/dist/types/src-public/env.d.ts +0 -144
  276. package/dist/types/src-public/getEventTime.d.ts +0 -1
  277. package/dist/types/src-public/index.d.ts +0 -19
  278. package/dist/types/src-public/ipValidation.d.ts +0 -15
  279. package/dist/types/src-public/jwks.d.ts +0 -15
  280. package/dist/types/src-public/pubsub.d.ts +0 -95
  281. package/dist/types/src-public/rateLimit.d.ts +0 -21
  282. package/dist/types/src-public/redisClient.d.ts +0 -6
  283. package/dist/types/src-public/runtime.d.ts +0 -58
  284. package/dist/types/src-public/sanitize.d.ts +0 -4
  285. package/dist/types/src-public/scheduler.d.ts +0 -71
  286. package/dist/types/src-public/secret.d.ts +0 -6
  287. package/dist/types/src-public/setHeaders.d.ts +0 -13
  288. package/dist/types/src-public/types.d.ts +0 -264
  289. package/dist/types/src-public/utils.d.ts +0 -101
  290. package/dist/types/src-public/validate.d.ts +0 -9
@@ -1,1053 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const crypto_1 = __importDefault(require("crypto"));
7
- const env_1 = __importDefault(require("./env"));
8
- const utils_1 = require("./utils");
9
- const CACHE_EXPIRATION_MS = 1000 * 60 * 60 * 3;
10
- class CentraHelper extends env_1.default {
11
- opts;
12
- shaToken;
13
- graphqlUrl;
14
- constructor(options, opts) {
15
- super(options);
16
- this.opts = opts;
17
- this.shaToken = crypto_1.default.createHash('sha256').update(opts.accessToken).digest('hex').slice(0, 8);
18
- const parsedUrl = new URL(opts.centraApiBase);
19
- if (!parsedUrl.pathname.includes('/graphql')) {
20
- this.graphqlUrl = `${opts.centraApiBase}/graphql`;
21
- }
22
- else {
23
- this.graphqlUrl = opts.centraApiBase;
24
- }
25
- }
26
- static isCentraErrors(data) {
27
- return typeof data === 'object' && data !== null && 'errors' in data;
28
- }
29
- async fetch(arg1, arg2) {
30
- let request;
31
- if (typeof arg1 === 'string' || arg1 instanceof URL) {
32
- request = new Request(arg1, arg2);
33
- }
34
- else if (arg1 instanceof Request) {
35
- request = arg1;
36
- }
37
- else {
38
- throw new Error('Invalid argument type');
39
- }
40
- request.headers.set('Authorization', `Bearer ${this.opts.accessToken}`);
41
- request.headers.set('Content-Type', 'application/json');
42
- const errors = [];
43
- let response;
44
- try {
45
- response = await fetch(request);
46
- }
47
- catch (error) {
48
- errors.push({ message: `Failed to fetch: ${error instanceof Error ? error.message : String(error)}`, path: 'global' });
49
- return { errors };
50
- }
51
- if (response.status === 429) {
52
- if (this.workflowRoot != null) {
53
- (0, utils_1.setRetryAfterVariable)(response, { root: this.workflowRoot });
54
- }
55
- else {
56
- this.logging.log('Warning: setRetryAfterVariable is not available because the runtime has not been initialized with a full options object');
57
- }
58
- }
59
- let resp;
60
- try {
61
- resp = await response.json();
62
- }
63
- catch (error) {
64
- errors.push({ message: `Failed to parse response: ${error instanceof Error ? error.message : String(error)}`, path: 'global' });
65
- return { errors, limitExceeded: response.status === 429 };
66
- }
67
- if (resp.errors) {
68
- errors.push(resp.errors.map((x) => x.message).join('\n'));
69
- }
70
- else if (resp.data) {
71
- const userErrors = resp.data?.userErrors;
72
- if (userErrors) {
73
- errors.push(...userErrors.map((x) => ({ message: x.message, path: x.path })));
74
- return { errors, limitExceeded: response.status === 429 };
75
- }
76
- }
77
- if (response.status === 429) {
78
- resp.limitExceeded = true;
79
- }
80
- return resp;
81
- }
82
- getCacheKeyForStyleId(styleId) {
83
- return `centra_${this.shaToken}_style_id_${styleId}`;
84
- }
85
- getCacheKeyForCountryCode(countryCode) {
86
- return `centra_${this.shaToken}_country_code_${countryCode}`;
87
- }
88
- getCacheKeyForMarkets() {
89
- return `centra_${this.shaToken}_market_external_id`;
90
- }
91
- getCacheKeyForMarket(marketExternalId) {
92
- return `${this.getCacheKeyForMarkets()}_${marketExternalId}`;
93
- }
94
- getCacheKeyForSizeCharts() {
95
- return `centra_${this.shaToken}_size_chart_external_id`;
96
- }
97
- getCacheKeyForCountries() {
98
- return `centra_${this.shaToken}_country_iso2_code`;
99
- }
100
- getCacheKeyForCountry(countryIso2Code) {
101
- return `${this.getCacheKeyForCountries()}_${countryIso2Code}`;
102
- }
103
- getCacheKeyForSizeChart(sizeChartExternalId) {
104
- return `${this.getCacheKeyForSizeCharts()}_${sizeChartExternalId}`;
105
- }
106
- getCacheKeyForCentraProduct(productExternalId) {
107
- return `centra_${this.shaToken}_product_${productExternalId}`;
108
- }
109
- getCacheKeyForCentraVariant(variantExternalId) {
110
- return `centra_${this.shaToken}_variant_${variantExternalId}`;
111
- }
112
- getCacheKeyForCentraDisplayByVariantId(centraVariantId) {
113
- return `centra_${this.shaToken}_display_variant_${centraVariantId}`;
114
- }
115
- getCacheKeyForCentraDisplayByProductId(centraProductId) {
116
- return `centra_${this.shaToken}_display_product_${centraProductId}`;
117
- }
118
- getCacheKeyForCentraWarehouses() {
119
- return `centra_${this.shaToken}_warehouse_external_id`;
120
- }
121
- getCacheKeyForCentraWarehouse(warehouseExternalId) {
122
- return `${this.getCacheKeyForCentraWarehouses()}_${warehouseExternalId}`;
123
- }
124
- getCacheKeyForCentraPricelists() {
125
- return `centra_${this.shaToken}_pricelist_external_id`;
126
- }
127
- getCacheKeyForCentraPricelist(pricelistExternalId) {
128
- return `${this.getCacheKeyForCentraPricelists()}_${pricelistExternalId}`;
129
- }
130
- async fetchCountries(iso2Codes) {
131
- const result = [];
132
- const limit = 200;
133
- let page = 0;
134
- let hasNextPage = true;
135
- do {
136
- const data = await this.fetch(this.graphqlUrl, {
137
- method: 'POST',
138
- body: JSON.stringify({
139
- query: `
140
- query countries($page: Int, $limit: Int, $iso2Codes: [String!]) {
141
- countries(limit: $limit, page: $page${iso2Codes ? `, where: { ISO2: $iso2Codes }` : ''} ) {
142
- id
143
- name
144
- code
145
- }
146
- }
147
- `,
148
- variables: { page: page, limit: limit, iso2Codes: iso2Codes }
149
- })
150
- });
151
- if (CentraHelper.isCentraErrors(data)) {
152
- return data;
153
- }
154
- if ((data.data?.countries?.length || 0) < limit) {
155
- hasNextPage = false;
156
- }
157
- else {
158
- page++;
159
- }
160
- for (const country of data.data?.countries || []) {
161
- result.push({
162
- id: country.id,
163
- name: country.name,
164
- code: country.code
165
- });
166
- }
167
- } while (hasNextPage);
168
- return result;
169
- }
170
- async fetchCentraWarehouses(externalIds) {
171
- const result = [];
172
- const limit = 200;
173
- let page = 0;
174
- let hasNextPage = true;
175
- do {
176
- const data = await this.fetch(this.graphqlUrl, {
177
- method: 'POST',
178
- body: JSON.stringify({
179
- query: `
180
- query GetWarehouses($limit: Int, $page: Int${externalIds ? `, $externalIds: WarehousesFilter` : ''}) {
181
- warehouses(${externalIds ? `where: $externalIds, ` : ''}limit: $limit, page: $page) {
182
- id
183
- externalId
184
- name
185
- status
186
- }
187
- }
188
- `,
189
- variables: { page: page, limit: limit, externalIds: { externalId: externalIds } }
190
- })
191
- });
192
- if (CentraHelper.isCentraErrors(data)) {
193
- return data;
194
- }
195
- if ((data.data?.warehouses?.length || 0) < limit) {
196
- hasNextPage = false;
197
- }
198
- else {
199
- page++;
200
- }
201
- for (const warehouse of data.data?.warehouses || []) {
202
- result.push({
203
- id: warehouse.id,
204
- name: warehouse.name,
205
- status: warehouse.status,
206
- externalId: warehouse.externalId
207
- });
208
- }
209
- } while (hasNextPage);
210
- return result;
211
- }
212
- async fetchCentraCampaigns(names) {
213
- const limit = (names?.length || 0) > 200 ? 200 : (names?.length || 0);
214
- let nextCursor = null;
215
- const result = {};
216
- do {
217
- const data = await this.fetch(`${this.graphqlUrl}`, {
218
- method: 'POST',
219
- body: JSON.stringify({
220
- query: `
221
- query campaignConnection (${names ? `$input: CampaignFilter, ` : ''}$limit: Int, $after: String) {
222
- campaignConnection(${names ? `where: $input, ` : ''}first: $limit, after: $after) {
223
- pageInfo {
224
- endCursor
225
- hasNextPage
226
- }
227
- edges {
228
- node {
229
- id
230
- name
231
- }
232
- }
233
- }
234
- }
235
- `,
236
- variables: {
237
- input: {
238
- name: {
239
- equals: names,
240
- }
241
- },
242
- after: nextCursor,
243
- limit: limit,
244
- }
245
- })
246
- });
247
- if (CentraHelper.isCentraErrors(data)) {
248
- if (!names) {
249
- return data;
250
- }
251
- for (let i = 0; i < (names?.length || 0); i++) {
252
- const name = names[i];
253
- result[name] = new Error(data.errors.map((x, idx) => `${idx + 1}. ${x.message}`).join('\n'));
254
- }
255
- }
256
- else {
257
- const campaignConnection = data.data?.campaignConnection;
258
- if (campaignConnection && campaignConnection.pageInfo?.hasNextPage && campaignConnection.pageInfo.endCursor && campaignConnection.pageInfo.endCursor !== nextCursor) {
259
- nextCursor = campaignConnection.pageInfo?.endCursor;
260
- }
261
- else {
262
- nextCursor = null;
263
- }
264
- if (campaignConnection && campaignConnection.edges?.length) {
265
- for (let i = campaignConnection.edges.length; i < (names?.length || 0); i++) {
266
- const { node } = campaignConnection.edges[i];
267
- result[node.name] = node;
268
- }
269
- }
270
- }
271
- } while (nextCursor !== null);
272
- return result;
273
- }
274
- async fetchPricelists(names) {
275
- const result = [];
276
- const limit = 200;
277
- let page = 0;
278
- let hasNextPage = true;
279
- do {
280
- const data = await this.fetch(this.graphqlUrl, {
281
- method: 'POST',
282
- body: JSON.stringify({
283
- query: `
284
- query GetPricelists($limit: Int, $page: Int${names ? `, $input: PricelistFilter` : ''}) {
285
- pricelists(${names ? `where: $input, ` : ''}limit: $limit, page: $page) {
286
- id
287
- externalId
288
- name,
289
- campaigns {
290
- id
291
- name
292
- status
293
- }
294
- currency {
295
- id
296
- name
297
- code
298
- }
299
- }
300
- }
301
- `,
302
- variables: {
303
- page: page, limit: limit, input: {
304
- name: {
305
- equals: names
306
- }
307
- }
308
- }
309
- })
310
- });
311
- if (CentraHelper.isCentraErrors(data)) {
312
- return data;
313
- }
314
- if ((data.data?.pricelists?.length || 0) < limit) {
315
- hasNextPage = false;
316
- }
317
- else {
318
- page++;
319
- }
320
- for (const pricelist of data.data?.pricelists || []) {
321
- result.push(pricelist);
322
- }
323
- } while (hasNextPage);
324
- return result;
325
- }
326
- async fetchCentraMarkets(externalIds) {
327
- const result = [];
328
- const limit = 200;
329
- let page = 0;
330
- let hasNextPage = true;
331
- do {
332
- const data = await this.fetch(this.graphqlUrl, {
333
- method: 'POST',
334
- body: JSON.stringify({
335
- query: `
336
- query GetMarkets($limit: Int, $page: Int${externalIds ? `, $externalIds: MarketsFilter` : ''}) {
337
- markets(${externalIds ? `where: $externalIds, ` : ''}limit: $limit, page: $page) {
338
- id
339
- externalId
340
- name
341
- }
342
- }
343
- `,
344
- variables: { page: page, limit: limit, externalIds: { externalId: externalIds } }
345
- })
346
- });
347
- if (CentraHelper.isCentraErrors(data)) {
348
- return data;
349
- }
350
- if ((data.data?.markets?.length || 0) < limit) {
351
- hasNextPage = false;
352
- }
353
- else {
354
- page++;
355
- }
356
- for (const market of data.data?.markets || []) {
357
- result.push(market);
358
- }
359
- } while (hasNextPage);
360
- return result;
361
- }
362
- async fetchCentraSizeCharts(externalIds) {
363
- const result = [];
364
- const limit = 200;
365
- let page = 0;
366
- let hasNextPage = true;
367
- do {
368
- const data = await this.fetch(this.graphqlUrl, {
369
- method: 'POST',
370
- body: JSON.stringify({
371
- query: `
372
- query sizeCharts($page: Int, $limit: Int${externalIds ? `, $externalIds: SizeChartFilter` : ''}) {
373
- sizeCharts(${externalIds ? `where: $externalIds, ` : ''}limit: $limit, page: $page) {
374
- id
375
- name
376
- externalId
377
- sizes {
378
- id
379
- name
380
- externalId
381
- localized(where: { name: { equals: "System" } }) {
382
- localizedName
383
- }
384
- }
385
- }
386
- }
387
- `,
388
- variables: { page: page, limit: limit, externalIds: { externalId: externalIds } }
389
- })
390
- });
391
- if (CentraHelper.isCentraErrors(data)) {
392
- return data;
393
- }
394
- if ((data.data?.sizeCharts?.length || 0) < limit) {
395
- hasNextPage = false;
396
- }
397
- else {
398
- page++;
399
- }
400
- for (const sizeChart of data.data?.sizeCharts || []) {
401
- result.push({
402
- id: sizeChart.id,
403
- name: sizeChart.name,
404
- externalId: sizeChart.externalId,
405
- sizes: sizeChart.sizes.map((x) => ({
406
- id: x.id,
407
- name: x.name,
408
- externalId: x.externalId,
409
- localizedName: x.localized[0]?.localizedName || undefined
410
- }))
411
- });
412
- }
413
- } while (hasNextPage);
414
- return result;
415
- }
416
- async fetchCentraProducts(styleIds) {
417
- const limit = styleIds.length > 200 ? 200 : styleIds.length;
418
- let nextCursor = null;
419
- const result = {};
420
- do {
421
- const data = await this.fetch(`${this.graphqlUrl}`, {
422
- method: 'POST',
423
- body: JSON.stringify({
424
- query: `
425
- query productConnection ($input: ProductFilter, $limit: Int, $after: String) {
426
- productConnection(where: $input, first: $limit, after: $after) {
427
- pageInfo {
428
- endCursor
429
- hasNextPage
430
- }
431
- edges {
432
- node {
433
- id
434
- externalId
435
- productNumber
436
- name
437
- status
438
- prices {
439
- price {
440
- value
441
- }
442
- pricelist {
443
- id
444
- name
445
- }
446
- }
447
- }
448
- }
449
- }
450
- }
451
- `,
452
- variables: {
453
- input: {
454
- externalId: styleIds,
455
- },
456
- after: nextCursor,
457
- limit: limit,
458
- }
459
- })
460
- });
461
- if (data && data.errors) {
462
- for (let i = 0; i < styleIds.length; i++) {
463
- const styleId = styleIds[i];
464
- result[styleId] = new Error(data.errors.map((x, idx) => `${idx + 1}. ${x.message}`).join('\n'));
465
- }
466
- }
467
- if (data && data.data?.productConnection?.pageInfo?.hasNextPage && data.data.productConnection.pageInfo.endCursor && data.data.productConnection.pageInfo.endCursor !== nextCursor) {
468
- nextCursor = data.data.productConnection?.pageInfo?.endCursor;
469
- }
470
- else {
471
- nextCursor = null;
472
- }
473
- if (data && data.data?.productConnection?.edges?.length) {
474
- for (let i = data.data.productConnection.edges.length; i < styleIds.length; i++) {
475
- const { node } = data.data.productConnection.edges[i];
476
- result[node.externalId] = node;
477
- }
478
- }
479
- } while (nextCursor !== null);
480
- return result;
481
- }
482
- async fetchCentraDisplays(inputIds, inputIdType) {
483
- const limit = inputIds.length > 200 ? 200 : inputIds.length;
484
- let nextCursor = null;
485
- const result = {};
486
- do {
487
- const data = await this.fetch(`${this.graphqlUrl}`, {
488
- method: 'POST',
489
- body: JSON.stringify({
490
- query: `
491
- query displayConnection ($input: DisplayFilter, $limit: Int, $after: String) {
492
- displayConnection(where: $input, first: $limit, after: $after) {
493
- pageInfo {
494
- endCursor,
495
- hasNextPage
496
- }
497
- edges {
498
- node {
499
- id
500
- externalId
501
- status
502
- url
503
- metaTitle
504
- metaDescription
505
- name
506
- categories {
507
- id
508
- name
509
- url
510
- isTopCategory
511
- }
512
- markets {
513
- id
514
- name
515
- }
516
- product {
517
- id
518
- externalId
519
- status
520
- }
521
- productVariant {
522
- id
523
- externalId
524
- status
525
- variantNumber
526
- }
527
- }
528
- }
529
- }
530
- }
531
- `,
532
- variables: {
533
- input: {
534
- ...(inputIdType === 'variant' ? { productVariantId: inputIds } : { productId: inputIds }),
535
- },
536
- after: nextCursor,
537
- limit: limit,
538
- }
539
- })
540
- });
541
- if (data.limitExceeded) {
542
- for (let i = 0; i < inputIds.length; i++) {
543
- const inputId = inputIds[i];
544
- if (!result[inputId]) {
545
- result[inputId] = new Error(`Rate limit exceeded for product ID ${inputId}`);
546
- }
547
- }
548
- return result;
549
- }
550
- if (data?.errors) {
551
- nextCursor = null;
552
- for (let i = 0; i < inputIds.length; i++) {
553
- const inputId = inputIds[i];
554
- result[inputId] = new Error(data.errors.map((x, idx) => `${idx + 1}. ${x.message}`).join('\n'));
555
- }
556
- }
557
- if (data.data?.displayConnection?.pageInfo?.hasNextPage && data.data.displayConnection.pageInfo.endCursor && data.data.displayConnection.pageInfo.endCursor !== nextCursor) {
558
- nextCursor = data.data.displayConnection?.pageInfo?.endCursor;
559
- }
560
- else {
561
- nextCursor = null;
562
- }
563
- const edges = data.data?.displayConnection?.edges || [];
564
- if (edges.length) {
565
- for (let i = 0; i < edges.length; i++) {
566
- const { node } = edges[i];
567
- if (inputIdType === 'variant') {
568
- result[+node.productVariant[0].id] = [];
569
- result[+node.productVariant[0].id].push(node);
570
- }
571
- else {
572
- result[+node.product.id] = [];
573
- result[+node.product.id].push(node);
574
- }
575
- }
576
- }
577
- } while (nextCursor !== null);
578
- return result;
579
- }
580
- async fetchCentraVariants(productIds) {
581
- const limit = productIds.length > 200 ? 200 : productIds.length;
582
- let nextCursor = null;
583
- const result = {};
584
- do {
585
- const data = await this.fetch(`${this.graphqlUrl}`, {
586
- method: 'POST',
587
- body: JSON.stringify({
588
- query: `
589
- query productVariantConnection ($input: ProductVariantFilter, $limit: Int, $after: String) {
590
- productVariantConnection(where: $input, first: $limit, after: $after) {
591
- pageInfo {
592
- endCursor,
593
- hasNextPage
594
- }
595
- edges {
596
- node {
597
- id
598
- externalId
599
- status
600
- name
601
- variantNumber
602
- product {
603
- status
604
- externalId
605
- id
606
- name
607
- productNumber
608
- prices {
609
- price {
610
- value
611
- }
612
- pricelist {
613
- id
614
- name
615
- }
616
- }
617
- }
618
- sizeChart {
619
- externalId
620
- id
621
- }
622
- productSizes {
623
- id
624
- EAN
625
- SKU
626
- isActive
627
- sizeNumber
628
- size {
629
- id
630
- name
631
- }
632
- }
633
- }
634
- }
635
- }
636
- }
637
- `,
638
- variables: {
639
- input: {
640
- externalId: productIds,
641
- },
642
- after: nextCursor,
643
- limit: limit,
644
- }
645
- })
646
- });
647
- if (data.limitExceeded) {
648
- for (let i = 0; i < productIds.length; i++) {
649
- const productId = productIds[i];
650
- if (!result[productId]) {
651
- result[productId] = new Error(`Rate limit exceeded for product ID ${productId}`);
652
- }
653
- }
654
- return result;
655
- }
656
- if (data?.errors) {
657
- nextCursor = null;
658
- for (let i = 0; i < productIds.length; i++) {
659
- const productId = productIds[i];
660
- result[productId] = new Error(data.errors.map((x, idx) => `${idx + 1}. ${x.message}`).join('\n'));
661
- }
662
- }
663
- if (data.data?.productVariantConnection?.pageInfo?.hasNextPage && data.data.productVariantConnection.pageInfo.endCursor && data.data.productVariantConnection.pageInfo.endCursor !== nextCursor) {
664
- nextCursor = data.data.productVariantConnection?.pageInfo?.endCursor;
665
- }
666
- else {
667
- nextCursor = null;
668
- }
669
- const edges = data.data?.productVariantConnection?.edges || [];
670
- if (edges.length) {
671
- for (let i = 0; i < edges.length; i++) {
672
- const { node } = edges[i];
673
- result[node.externalId] = node;
674
- }
675
- }
676
- } while (nextCursor !== null);
677
- return result;
678
- }
679
- async getCentraWarehouses(externalIds, alwaysFetch = false) {
680
- if (externalIds && !externalIds.length) {
681
- return {};
682
- }
683
- let warehouseInCache = {};
684
- let dedupedExternalIds = [];
685
- let warehousesToFetch = null;
686
- if (!alwaysFetch) {
687
- if (!externalIds) {
688
- externalIds = (await this.get(this.getCacheKeyForCentraWarehouses(), 'env', {
689
- isEphemeral: true,
690
- encrypted: false,
691
- }).then(x => x ? JSON.parse(x) : null));
692
- }
693
- if (externalIds) {
694
- dedupedExternalIds = externalIds.filter((x, index, self) => self.indexOf(x) === index);
695
- warehouseInCache = Object.fromEntries(Object.entries(await this.get(dedupedExternalIds.map(x => this.getCacheKeyForCentraWarehouse(x)), 'env', {
696
- isEphemeral: true,
697
- encrypted: false,
698
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
699
- warehousesToFetch = dedupedExternalIds.filter(x => !warehouseInCache[x]);
700
- }
701
- }
702
- const warehouseToSet = {};
703
- if (!warehousesToFetch || warehousesToFetch.length) {
704
- const warehouses = await this.fetchCentraWarehouses(warehousesToFetch);
705
- if (CentraHelper.isCentraErrors(warehouses)) {
706
- if (warehousesToFetch) {
707
- for (const warehouseExternalId of warehousesToFetch) {
708
- warehouseToSet[warehouseExternalId] = new Error(`Failed to fetch warehouse ${warehouseExternalId}: ${warehouses.errors.map((x) => x.message).join(', ')}`);
709
- }
710
- }
711
- else {
712
- return new Error(`Failed to fetch warehouses: ${warehouses.errors.map((x) => x.message).join(', ')}`);
713
- }
714
- }
715
- else {
716
- for (const warehouse of warehouses) {
717
- warehouseToSet[warehouse.externalId] = warehouse;
718
- }
719
- await this.set(Object.entries(warehouseToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraWarehouse(key), value: JSON.stringify(value) })), 'env', {
720
- ephemeralMs: CACHE_EXPIRATION_MS,
721
- encrypted: false,
722
- });
723
- if (!warehousesToFetch) {
724
- await this.set([{
725
- name: this.getCacheKeyForCentraWarehouses(),
726
- value: JSON.stringify(Object.keys(warehouseToSet)),
727
- }], 'env', {
728
- ephemeralMs: CACHE_EXPIRATION_MS,
729
- encrypted: false,
730
- });
731
- }
732
- }
733
- }
734
- return Object.assign({}, warehouseInCache, warehouseToSet);
735
- }
736
- async getCentraPricelists(names, alwaysFetch = false) {
737
- if (names && !names.length) {
738
- return {};
739
- }
740
- let pricelistInCache = {};
741
- let dedupedNames = [];
742
- let pricelistsToFetch = null;
743
- if (!alwaysFetch) {
744
- if (!names) {
745
- names = (await this.get(this.getCacheKeyForCentraPricelists(), 'env', {
746
- isEphemeral: true,
747
- encrypted: false,
748
- }).then(x => x ? JSON.parse(x) : null));
749
- }
750
- if (names) {
751
- dedupedNames = names.filter((x, index, self) => self.indexOf(x) === index);
752
- pricelistInCache = Object.fromEntries(Object.entries(await this.get(dedupedNames.map(x => this.getCacheKeyForCentraPricelist(x)), 'env', {
753
- isEphemeral: true,
754
- encrypted: false,
755
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value !== undefined));
756
- pricelistsToFetch = dedupedNames.filter(x => !pricelistInCache[x]);
757
- }
758
- }
759
- const pricelistToSet = {};
760
- if (!pricelistsToFetch || pricelistsToFetch.length) {
761
- const pricelists = await this.fetchPricelists(pricelistsToFetch);
762
- if (CentraHelper.isCentraErrors(pricelists)) {
763
- if (pricelistsToFetch) {
764
- for (const priceListName of pricelistsToFetch) {
765
- pricelistToSet[priceListName] = new Error(`Failed to fetch pricelist ${priceListName}: ${pricelists.errors.map((x) => x.message).join(', ')}`);
766
- }
767
- }
768
- else {
769
- return new Error(`Failed to fetch pricelists: ${pricelists.errors.map((x) => x.message).join(', ')}`);
770
- }
771
- }
772
- else {
773
- for (const pricelist of pricelists) {
774
- pricelistToSet[pricelist.name] = pricelist;
775
- }
776
- await this.set(Object.entries(pricelistToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraPricelist(key), value: JSON.stringify(value) })), 'env', {
777
- ephemeralMs: CACHE_EXPIRATION_MS,
778
- encrypted: false,
779
- });
780
- if (!pricelistsToFetch) {
781
- await this.set([{
782
- name: this.getCacheKeyForCentraPricelists(),
783
- value: JSON.stringify(Object.keys(pricelistToSet)),
784
- }], 'env', {
785
- ephemeralMs: CACHE_EXPIRATION_MS,
786
- encrypted: false,
787
- });
788
- }
789
- }
790
- }
791
- return Object.assign({}, pricelistInCache, pricelistToSet);
792
- }
793
- async getCentraMarkets(externalIds, alwaysFetch = false) {
794
- if (externalIds && !externalIds.length) {
795
- return {};
796
- }
797
- let marketInCache = {};
798
- let dedupedExternalIds = [];
799
- let marketsToFetch = null;
800
- if (!alwaysFetch) {
801
- if (!externalIds) {
802
- externalIds = (await this.get(this.getCacheKeyForMarkets(), 'env', {
803
- isEphemeral: true,
804
- encrypted: false,
805
- }).then(x => x ? JSON.parse(x) : null));
806
- }
807
- if (externalIds) {
808
- dedupedExternalIds = externalIds.filter((x, index, self) => self.indexOf(x) === index);
809
- marketInCache = Object.fromEntries(Object.entries(await this.get(dedupedExternalIds.map(x => this.getCacheKeyForMarket(x)), 'env', {
810
- isEphemeral: true,
811
- encrypted: false,
812
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
813
- marketsToFetch = dedupedExternalIds.filter(x => !marketInCache[x]);
814
- }
815
- }
816
- const marketToSet = {};
817
- if (!marketsToFetch || marketsToFetch.length) {
818
- const markets = await this.fetchCentraMarkets(marketsToFetch);
819
- if (CentraHelper.isCentraErrors(markets)) {
820
- if (marketsToFetch) {
821
- for (const marketExternalId of marketsToFetch) {
822
- marketToSet[marketExternalId] = new Error(`Failed to fetch market ${marketExternalId}: ${markets.errors.map((x) => x.message).join(', ')}`);
823
- }
824
- }
825
- else {
826
- return new Error(`Failed to fetch markets: ${markets.errors.map((x) => x.message).join(', ')}`);
827
- }
828
- }
829
- else {
830
- for (const market of markets) {
831
- marketToSet[market.externalId] = market;
832
- }
833
- await this.set(Object.entries(marketToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForMarket(key), value: JSON.stringify(value) })), 'env', {
834
- ephemeralMs: CACHE_EXPIRATION_MS,
835
- encrypted: false,
836
- });
837
- if (!marketsToFetch) {
838
- await this.set([{
839
- name: this.getCacheKeyForMarkets(),
840
- value: JSON.stringify(Object.keys(marketToSet)),
841
- }], 'env', {
842
- ephemeralMs: CACHE_EXPIRATION_MS,
843
- encrypted: false,
844
- });
845
- }
846
- }
847
- }
848
- return Object.assign({}, marketInCache, marketToSet);
849
- }
850
- async getCentraCountries(iso2Codes, alwaysFetch = false) {
851
- if (iso2Codes && !iso2Codes.length) {
852
- return {};
853
- }
854
- let countryInCache = {};
855
- let dedupedIso2Codes = [];
856
- let countriesToFetch = null;
857
- if (!alwaysFetch) {
858
- if (!iso2Codes) {
859
- iso2Codes = (await this.get(this.getCacheKeyForCountries(), 'env', {
860
- isEphemeral: true,
861
- encrypted: false,
862
- }).then(x => x ? JSON.parse(x) : null));
863
- }
864
- if (iso2Codes) {
865
- dedupedIso2Codes = iso2Codes.filter((x, index, self) => self.indexOf(x) === index);
866
- countryInCache = Object.fromEntries(Object.entries(await this.get(dedupedIso2Codes.map(x => this.getCacheKeyForCountry(x)), 'env', {
867
- isEphemeral: true,
868
- encrypted: false,
869
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
870
- countriesToFetch = dedupedIso2Codes.filter(x => !countryInCache[x]);
871
- }
872
- }
873
- const countryToSet = {};
874
- if (!countriesToFetch || countriesToFetch.length) {
875
- const countries = await this.fetchCountries(countriesToFetch);
876
- if (CentraHelper.isCentraErrors(countries)) {
877
- if (countriesToFetch) {
878
- for (const countryIso2Code of countriesToFetch) {
879
- countryToSet[countryIso2Code] = new Error(`Failed to fetch country ${countryIso2Code}: ${countries.errors.map((x) => x.message).join(', ')}`);
880
- }
881
- }
882
- else {
883
- return new Error(`Failed to fetch countries: ${countries.errors.map((x) => x.message).join(', ')}`);
884
- }
885
- }
886
- else {
887
- for (const country of countries) {
888
- countryToSet[country.code] = country;
889
- }
890
- await this.set(Object.entries(countryToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCountry(key), value: JSON.stringify(value) })), 'env', {
891
- ephemeralMs: CACHE_EXPIRATION_MS,
892
- encrypted: false,
893
- });
894
- if (!countriesToFetch) {
895
- await this.set([{
896
- name: this.getCacheKeyForCountries(),
897
- value: JSON.stringify(Object.keys(countryToSet)),
898
- }], 'env', {
899
- ephemeralMs: CACHE_EXPIRATION_MS,
900
- encrypted: false,
901
- });
902
- }
903
- }
904
- }
905
- return Object.assign({}, countryInCache, countryToSet);
906
- }
907
- async getCentraSizeCharts(externalIds, alwaysFetch = false) {
908
- if (externalIds && !externalIds.length) {
909
- return {};
910
- }
911
- let sizeChartInCache = {};
912
- let dedupedExternalIds = [];
913
- let sizeChartsToFetch = null;
914
- if (!alwaysFetch) {
915
- if (!externalIds) {
916
- externalIds = (await this.get(this.getCacheKeyForSizeCharts(), 'env', {
917
- isEphemeral: true,
918
- encrypted: false,
919
- }).then(x => x ? JSON.parse(x) : null));
920
- }
921
- if (externalIds) {
922
- dedupedExternalIds = externalIds.filter((x, index, self) => self.indexOf(x) === index);
923
- sizeChartInCache = Object.fromEntries(Object.entries(await this.get(dedupedExternalIds.map(x => this.getCacheKeyForSizeChart(x)), 'env', {
924
- isEphemeral: true,
925
- encrypted: false,
926
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
927
- sizeChartsToFetch = dedupedExternalIds.filter(x => !sizeChartInCache[x]);
928
- }
929
- }
930
- const sizeChartToSet = {};
931
- if (!sizeChartsToFetch || sizeChartsToFetch.length) {
932
- const sizeCharts = await this.fetchCentraSizeCharts(sizeChartsToFetch);
933
- if (CentraHelper.isCentraErrors(sizeCharts)) {
934
- if (sizeChartsToFetch) {
935
- for (const sizeChartExternalId of sizeChartsToFetch) {
936
- sizeChartToSet[sizeChartExternalId] = new Error(`Failed to fetch size chart ${sizeChartExternalId}: ${sizeCharts.errors.map((x) => x.message).join(', ')}`);
937
- }
938
- }
939
- else {
940
- return new Error(`Failed to fetch size charts: ${sizeCharts.errors.map((x) => x.message).join(', ')}`);
941
- }
942
- }
943
- else {
944
- for (const sizeChart of sizeCharts) {
945
- sizeChartToSet[sizeChart.externalId] = sizeChart;
946
- }
947
- await this.set(Object.entries(sizeChartToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForSizeChart(key), value: JSON.stringify(value) })), 'env', {
948
- ephemeralMs: CACHE_EXPIRATION_MS,
949
- encrypted: false,
950
- });
951
- if (!sizeChartsToFetch) {
952
- await this.set([{
953
- name: this.getCacheKeyForSizeCharts(),
954
- value: JSON.stringify(Object.keys(sizeChartToSet)),
955
- }], 'env', {
956
- ephemeralMs: CACHE_EXPIRATION_MS,
957
- encrypted: false,
958
- });
959
- }
960
- }
961
- }
962
- return Object.assign({}, sizeChartInCache, sizeChartToSet);
963
- }
964
- async getCentraProducts(styleIds) {
965
- const dedupedStyleIds = styleIds.filter((x, index, self) => self.indexOf(x) === index);
966
- const productIdsInCache = await this.get(dedupedStyleIds.map(x => this.getCacheKeyForStyleId(x)), 'env', {
967
- isEphemeral: true,
968
- encrypted: false,
969
- });
970
- const productsToFetch = dedupedStyleIds.filter(x => !productIdsInCache[this.getCacheKeyForCentraProduct(x)]);
971
- const products = await this.fetchCentraProducts(productsToFetch);
972
- const productsToSet = {};
973
- for (const styleId of dedupedStyleIds) {
974
- const product = products[styleId];
975
- productsToSet[styleId] = product;
976
- }
977
- this.set(Object.entries(productsToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraProduct(key), value: JSON.stringify(value) })), 'env', {
978
- ephemeralMs: CACHE_EXPIRATION_MS,
979
- encrypted: false,
980
- });
981
- return Object.assign({}, productIdsInCache, productsToSet);
982
- }
983
- async getCentraDisplaysByVariantIds(centraVariantIds) {
984
- const dedupedCentraVariantIds = centraVariantIds.filter((x, index, self) => self.indexOf(x) === index);
985
- const displaysInCache = Object.fromEntries(Object.entries(await this.get(dedupedCentraVariantIds.map(x => this.getCacheKeyForCentraDisplayByVariantId(x)), 'env', {
986
- isEphemeral: true,
987
- encrypted: false,
988
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]));
989
- const displaysToFetch = dedupedCentraVariantIds.filter(x => !displaysInCache[this.getCacheKeyForCentraDisplayByVariantId(x)]);
990
- const displays = await this.fetchCentraDisplays(displaysToFetch, 'variant');
991
- const displaysToSet = {};
992
- for (const centraVariantId of dedupedCentraVariantIds) {
993
- const display = displays[centraVariantId];
994
- displaysToSet[centraVariantId] = display;
995
- }
996
- this.set(Object.entries(displaysToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraDisplayByVariantId(+key), value: JSON.stringify(value) })), 'env', {
997
- ephemeralMs: CACHE_EXPIRATION_MS,
998
- encrypted: false,
999
- });
1000
- return Object.assign({}, displaysInCache, displaysToSet);
1001
- }
1002
- async getCentraDisplaysByProductIds(centraProductIds) {
1003
- const dedupedCentraProductIds = centraProductIds.filter((x, index, self) => self.indexOf(x) === index);
1004
- const displaysInCache = Object.fromEntries(Object.entries(await this.get(dedupedCentraProductIds.map(x => this.getCacheKeyForCentraDisplayByProductId(x)), 'env', {
1005
- isEphemeral: true,
1006
- encrypted: false,
1007
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]));
1008
- const displaysToFetch = dedupedCentraProductIds.filter(x => !displaysInCache[this.getCacheKeyForCentraDisplayByProductId(x)]);
1009
- const displays = await this.fetchCentraDisplays(displaysToFetch, 'product');
1010
- const displaysToSet = {};
1011
- for (const centraProductId of dedupedCentraProductIds) {
1012
- const display = displays[centraProductId];
1013
- displaysToSet[centraProductId] = display;
1014
- }
1015
- this.set(Object.entries(displaysToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraDisplayByProductId(+key), value: JSON.stringify(value) })), 'env', {
1016
- ephemeralMs: CACHE_EXPIRATION_MS,
1017
- encrypted: false,
1018
- });
1019
- return Object.assign({}, displaysInCache, displaysToSet);
1020
- }
1021
- async getCentraVariants(productIds) {
1022
- const dedupedProductIds = productIds.filter((x, index, self) => self.indexOf(x) === index);
1023
- const variantsInCache = Object.fromEntries(Object.entries(await this.get(dedupedProductIds.map(x => this.getCacheKeyForCentraVariant(x)), 'env', {
1024
- isEphemeral: true,
1025
- encrypted: false,
1026
- })).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]));
1027
- const variantsToFetch = dedupedProductIds.filter(x => !variantsInCache[this.getCacheKeyForCentraVariant(x)]);
1028
- const variants = await this.fetchCentraVariants(variantsToFetch);
1029
- const variantsToSet = {};
1030
- for (const productId of dedupedProductIds) {
1031
- const variant = variants[productId];
1032
- variantsToSet[productId] = variant;
1033
- }
1034
- this.set(Object.entries(variantsToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraVariant(key), value: JSON.stringify(value) })), 'env', {
1035
- ephemeralMs: CACHE_EXPIRATION_MS,
1036
- encrypted: false,
1037
- });
1038
- return Object.assign({}, variantsInCache, variantsToSet);
1039
- }
1040
- static centraSizeNameToSize(centraSizeName) {
1041
- if (centraSizeName.endsWith('xS') && !centraSizeName.toLowerCase().endsWith('xxs')) {
1042
- return centraSizeName.slice(0, -2) + 'S';
1043
- }
1044
- if (centraSizeName.endsWith('xT')) {
1045
- return centraSizeName.slice(0, -2) + 'T';
1046
- }
1047
- if (centraSizeName.endsWith('xR')) {
1048
- return centraSizeName.slice(0, -2);
1049
- }
1050
- return centraSizeName;
1051
- }
1052
- }
1053
- exports.default = CentraHelper;