@rechargeapps/storefront-client 2.6.1 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/cjs/api/address.js.map +1 -1
  2. package/dist/cjs/api/auth.js +1 -1
  3. package/dist/cjs/api/auth.js.map +1 -1
  4. package/dist/cjs/api/bundle.js +0 -1
  5. package/dist/cjs/api/bundle.js.map +1 -1
  6. package/dist/cjs/api/bundleData.js +1 -1
  7. package/dist/cjs/api/bundleData.js.map +1 -1
  8. package/dist/cjs/api/cdn.js.map +1 -1
  9. package/dist/cjs/api/charge.js.map +1 -1
  10. package/dist/cjs/api/collection.js.map +1 -1
  11. package/dist/cjs/api/credit.js.map +1 -1
  12. package/dist/cjs/api/customer.js.map +1 -1
  13. package/dist/cjs/api/customerSurveys.js.map +1 -1
  14. package/dist/cjs/api/flow.js.map +1 -1
  15. package/dist/cjs/api/gift.js.map +1 -1
  16. package/dist/cjs/api/membership.js.map +1 -1
  17. package/dist/cjs/api/membershipProgram.js.map +1 -1
  18. package/dist/cjs/api/metafield.js.map +1 -1
  19. package/dist/cjs/api/onetime.js.map +1 -1
  20. package/dist/cjs/api/order.js.map +1 -1
  21. package/dist/cjs/api/paymentMethod.js.map +1 -1
  22. package/dist/cjs/api/plan.js.map +1 -1
  23. package/dist/cjs/api/product.js.map +1 -1
  24. package/dist/cjs/api/store.js.map +1 -1
  25. package/dist/cjs/api/subscription.js.map +1 -1
  26. package/dist/cjs/api/tieredDiscount.js +0 -6
  27. package/dist/cjs/api/tieredDiscount.js.map +1 -1
  28. package/dist/cjs/constants/api.js.map +1 -1
  29. package/dist/cjs/mappers/cdn.js.map +1 -1
  30. package/dist/cjs/mappers/subscription.js.map +1 -1
  31. package/dist/cjs/mappers/utils.js.map +1 -1
  32. package/dist/cjs/utils/bundle.js +28 -51
  33. package/dist/cjs/utils/bundle.js.map +1 -1
  34. package/dist/cjs/utils/bundleData.js +4 -8
  35. package/dist/cjs/utils/bundleData.js.map +1 -1
  36. package/dist/cjs/utils/error.js.map +1 -1
  37. package/dist/cjs/utils/id.js.map +1 -1
  38. package/dist/cjs/utils/init.js.map +1 -1
  39. package/dist/cjs/utils/loadSpreedlyScript.js +34 -20
  40. package/dist/cjs/utils/loadSpreedlyScript.js.map +1 -1
  41. package/dist/cjs/utils/options.js.map +1 -1
  42. package/dist/cjs/utils/request.js +1 -1
  43. package/dist/cjs/utils/request.js.map +1 -1
  44. package/dist/cjs/utils/url.js.map +1 -1
  45. package/dist/esm/api/address.js +1 -1
  46. package/dist/esm/api/address.js.map +1 -1
  47. package/dist/esm/api/auth.js +1 -1
  48. package/dist/esm/api/auth.js.map +1 -1
  49. package/dist/esm/api/bundle.js +1 -2
  50. package/dist/esm/api/bundle.js.map +1 -1
  51. package/dist/esm/api/bundleData.js +1 -1
  52. package/dist/esm/api/bundleData.js.map +1 -1
  53. package/dist/esm/api/cdn.js.map +1 -1
  54. package/dist/esm/api/charge.js.map +1 -1
  55. package/dist/esm/api/collection.js.map +1 -1
  56. package/dist/esm/api/credit.js.map +1 -1
  57. package/dist/esm/api/customer.js +1 -1
  58. package/dist/esm/api/customer.js.map +1 -1
  59. package/dist/esm/api/customerSurveys.js.map +1 -1
  60. package/dist/esm/api/flow.js.map +1 -1
  61. package/dist/esm/api/gift.js.map +1 -1
  62. package/dist/esm/api/membership.js.map +1 -1
  63. package/dist/esm/api/membershipProgram.js.map +1 -1
  64. package/dist/esm/api/metafield.js.map +1 -1
  65. package/dist/esm/api/onetime.js.map +1 -1
  66. package/dist/esm/api/order.js.map +1 -1
  67. package/dist/esm/api/paymentMethod.js.map +1 -1
  68. package/dist/esm/api/plan.js.map +1 -1
  69. package/dist/esm/api/product.js.map +1 -1
  70. package/dist/esm/api/store.js.map +1 -1
  71. package/dist/esm/api/subscription.js.map +1 -1
  72. package/dist/esm/api/tieredDiscount.js +0 -6
  73. package/dist/esm/api/tieredDiscount.js.map +1 -1
  74. package/dist/esm/constants/api.js.map +1 -1
  75. package/dist/esm/mappers/cdn.js.map +1 -1
  76. package/dist/esm/mappers/subscription.js.map +1 -1
  77. package/dist/esm/mappers/utils.js.map +1 -1
  78. package/dist/esm/utils/bundle.js +29 -52
  79. package/dist/esm/utils/bundle.js.map +1 -1
  80. package/dist/esm/utils/bundleData.js +4 -8
  81. package/dist/esm/utils/bundleData.js.map +1 -1
  82. package/dist/esm/utils/error.js.map +1 -1
  83. package/dist/esm/utils/id.js.map +1 -1
  84. package/dist/esm/utils/init.js.map +1 -1
  85. package/dist/esm/utils/loadSpreedlyScript.js +34 -20
  86. package/dist/esm/utils/loadSpreedlyScript.js.map +1 -1
  87. package/dist/esm/utils/options.js.map +1 -1
  88. package/dist/esm/utils/request.js +2 -2
  89. package/dist/esm/utils/request.js.map +1 -1
  90. package/dist/esm/utils/url.js.map +1 -1
  91. package/dist/index.d.ts +0 -6
  92. package/dist/umd/recharge-client.min.js +2 -2
  93. package/package.json +11 -10
@@ -2,29 +2,15 @@
2
2
 
3
3
  var jsXdr = require('@stellar/js-xdr');
4
4
 
5
- var __accessCheck = (obj, member, msg) => {
6
- if (!member.has(obj))
7
- throw TypeError("Cannot " + msg);
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
8
7
  };
9
- var __privateGet = (obj, member, getter) => {
10
- __accessCheck(obj, member, "read from private field");
11
- return getter ? getter.call(obj) : member.get(obj);
12
- };
13
- var __privateAdd = (obj, member, value) => {
14
- if (member.has(obj))
15
- throw TypeError("Cannot add the same private member more than once");
16
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
17
- };
18
- var __privateSet = (obj, member, value, setter) => {
19
- __accessCheck(obj, member, "write to private field");
20
- setter ? setter.call(obj, value) : member.set(obj, value);
21
- return value;
22
- };
23
- var __privateMethod = (obj, member, method) => {
24
- __accessCheck(obj, member, "access private method");
25
- return method;
26
- };
27
- var _bundleSettings, _items, _bundleData, _formatBundleSettings, formatBundleSettings_fn, _formatBundleData, formatBundleData_fn, _isValueInRange, isValueInRange_fn, _unique, unique_fn, _hasOwn, hasOwn_fn;
8
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
10
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
11
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
12
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
13
+ var _bundleSettings, _items, _bundleData, _BundleSelectionValidator_instances, formatBundleSettings_fn, formatBundleData_fn, isValueInRange_fn, unique_fn, hasOwn_fn;
28
14
  const textEncoder = new TextEncoder();
29
15
  const emptyExt = { v: 0 };
30
16
  function toBase64(bytes) {
@@ -79,7 +65,7 @@ function toLineItemProperty(bundle) {
79
65
  quantity: item.quantity,
80
66
  ext: emptyExt
81
67
  })),
82
- version: bundle.version || Math.floor(Date.now() / 1e3),
68
+ version: Math.floor(Date.now() / 1e3),
83
69
  ext: emptyExt
84
70
  }
85
71
  };
@@ -87,18 +73,12 @@ function toLineItemProperty(bundle) {
87
73
  }
88
74
  class BundleSelectionValidator {
89
75
  constructor(selectionItems, bundleData) {
90
- __privateAdd(this, _formatBundleSettings);
91
- __privateAdd(this, _formatBundleData);
92
- __privateAdd(this, _isValueInRange);
93
- __privateAdd(this, _unique);
94
- // Own-property membership check. Guards against inherited keys (e.g. `__proto__`,
95
- // `constructor`, `toString`) resolving to truthy values on plain-object maps.
96
- __privateAdd(this, _hasOwn);
97
- __privateAdd(this, _bundleSettings, void 0);
98
- __privateAdd(this, _items, void 0);
99
- __privateAdd(this, _bundleData, void 0);
100
- __privateSet(this, _bundleSettings, __privateMethod(this, _formatBundleSettings, formatBundleSettings_fn).call(this, bundleData));
101
- __privateSet(this, _bundleData, __privateMethod(this, _formatBundleData, formatBundleData_fn).call(this, bundleData));
76
+ __privateAdd(this, _BundleSelectionValidator_instances);
77
+ __privateAdd(this, _bundleSettings);
78
+ __privateAdd(this, _items);
79
+ __privateAdd(this, _bundleData);
80
+ __privateSet(this, _bundleSettings, __privateMethod(this, _BundleSelectionValidator_instances, formatBundleSettings_fn).call(this, bundleData));
81
+ __privateSet(this, _bundleData, __privateMethod(this, _BundleSelectionValidator_instances, formatBundleData_fn).call(this, bundleData));
102
82
  __privateSet(this, _items, selectionItems);
103
83
  }
104
84
  isInitialDataValid() {
@@ -122,7 +102,7 @@ class BundleSelectionValidator {
122
102
  isSelectionInVariantRange(externalVariantId) {
123
103
  const total = __privateGet(this, _items).reduce((acc, current) => acc + current.quantity, 0);
124
104
  const ranges = __privateGet(this, _bundleSettings)?.variantsSettings[externalVariantId].ranges || [];
125
- if (!__privateMethod(this, _isValueInRange, isValueInRange_fn).call(this, ranges, total)) {
105
+ if (!__privateMethod(this, _BundleSelectionValidator_instances, isValueInRange_fn).call(this, ranges, total)) {
126
106
  throw "The total number of products does not fall within the required variant range.";
127
107
  }
128
108
  return true;
@@ -131,7 +111,7 @@ class BundleSelectionValidator {
131
111
  const maxPerItem = __privateGet(this, _bundleSettings)?.bundleSettings.maxPerItem || 0;
132
112
  const invalidProducts = __privateGet(this, _items).filter(({ quantity }) => quantity > maxPerItem);
133
113
  if (maxPerItem && invalidProducts.length) {
134
- const invalidIds = __privateMethod(this, _unique, unique_fn).call(this, invalidProducts.map(({ externalProductId }) => externalProductId)).join(", ");
114
+ const invalidIds = __privateMethod(this, _BundleSelectionValidator_instances, unique_fn).call(this, invalidProducts.map(({ externalProductId }) => externalProductId)).join(", ");
135
115
  throw `The selected products (${invalidIds}) exceed the maximum limit of ${maxPerItem} items per product.`;
136
116
  }
137
117
  return true;
@@ -140,10 +120,10 @@ class BundleSelectionValidator {
140
120
  const variantSettings = __privateGet(this, _bundleSettings)?.variantsSettings[externalVariantId];
141
121
  const optionSources = variantSettings?.optionSources;
142
122
  const invalidCollections = __privateGet(this, _items).filter(
143
- ({ collectionId }) => !optionSources || !__privateMethod(this, _hasOwn, hasOwn_fn).call(this, optionSources, collectionId)
123
+ ({ collectionId }) => !optionSources || !__privateMethod(this, _BundleSelectionValidator_instances, hasOwn_fn).call(this, optionSources, collectionId)
144
124
  );
145
125
  if (invalidCollections.length) {
146
- const invalidIds = __privateMethod(this, _unique, unique_fn).call(this, invalidCollections.map(({ collectionId }) => collectionId)).join(", ");
126
+ const invalidIds = __privateMethod(this, _BundleSelectionValidator_instances, unique_fn).call(this, invalidCollections.map(({ collectionId }) => collectionId)).join(", ");
147
127
  throw `The collections (${invalidIds}) are no longer valid for the bundle variant (${externalVariantId}).`;
148
128
  }
149
129
  return true;
@@ -156,10 +136,10 @@ class BundleSelectionValidator {
156
136
  const variantSettings = __privateGet(this, _bundleSettings)?.variantsSettings[externalVariantId];
157
137
  const invalidItems = Object.values(variantSettings?.optionSources || {}).filter((collection) => {
158
138
  const quantity = totalSelectedByCollection[collection.collectionId] || 0;
159
- return !__privateMethod(this, _isValueInRange, isValueInRange_fn).call(this, [collection], quantity);
139
+ return !__privateMethod(this, _BundleSelectionValidator_instances, isValueInRange_fn).call(this, [collection], quantity);
160
140
  });
161
141
  if (!variantSettings || invalidItems.length) {
162
- const invalidIds = __privateMethod(this, _unique, unique_fn).call(this, invalidItems.map(({ collectionId }) => collectionId)).join(", ");
142
+ const invalidIds = __privateMethod(this, _BundleSelectionValidator_instances, unique_fn).call(this, invalidItems.map(({ collectionId }) => collectionId)).join(", ");
163
143
  throw `The selection exceeds the limits for the collections (${invalidIds}).`;
164
144
  }
165
145
  return true;
@@ -180,13 +160,13 @@ class BundleSelectionValidator {
180
160
  throw `No collections found for the bundle variant (${externalVariantId}).`;
181
161
  }
182
162
  const missingProducts = __privateGet(this, _items).filter(({ externalProductId, collectionId }) => {
183
- if (!__privateMethod(this, _hasOwn, hasOwn_fn).call(this, variantCollections, collectionId)) {
163
+ if (!__privateMethod(this, _BundleSelectionValidator_instances, hasOwn_fn).call(this, variantCollections, collectionId)) {
184
164
  return true;
185
165
  }
186
- return !__privateMethod(this, _hasOwn, hasOwn_fn).call(this, variantCollections[collectionId].products, externalProductId);
166
+ return !__privateMethod(this, _BundleSelectionValidator_instances, hasOwn_fn).call(this, variantCollections[collectionId].products, externalProductId);
187
167
  });
188
168
  if (missingProducts.length) {
189
- const invalidIds = __privateMethod(this, _unique, unique_fn).call(this, missingProducts.map(({ externalProductId }) => externalProductId)).join(", ");
169
+ const invalidIds = __privateMethod(this, _BundleSelectionValidator_instances, unique_fn).call(this, missingProducts.map(({ externalProductId }) => externalProductId)).join(", ");
190
170
  throw `The products (${invalidIds}) are no longer valid for the bundle product.`;
191
171
  }
192
172
  return true;
@@ -205,7 +185,7 @@ class BundleSelectionValidator {
205
185
  _bundleSettings = new WeakMap();
206
186
  _items = new WeakMap();
207
187
  _bundleData = new WeakMap();
208
- _formatBundleSettings = new WeakSet();
188
+ _BundleSelectionValidator_instances = new WeakSet();
209
189
  formatBundleSettings_fn = function(bundleData) {
210
190
  try {
211
191
  const bundleSettings = bundleData.bundle_settings;
@@ -216,8 +196,7 @@ formatBundleSettings_fn = function(bundleData) {
216
196
  },
217
197
  // null-proto seeds so external variant/option-source ids become real own keys, not prototype pollution
218
198
  variantsSettings: bundleSettings.variants.reduce((acc, variant) => {
219
- if (!variant.enabled)
220
- return acc;
199
+ if (!variant.enabled) return acc;
221
200
  let ranges = [{ min: variant.items_count, max: variant.items_count }];
222
201
  if (!variant.items_count) {
223
202
  ranges = variant.ranges.map(({ quantity_max, quantity_min }) => ({
@@ -244,7 +223,6 @@ formatBundleSettings_fn = function(bundleData) {
244
223
  return null;
245
224
  }
246
225
  };
247
- _formatBundleData = new WeakSet();
248
226
  formatBundleData_fn = function(bundleData) {
249
227
  try {
250
228
  const collections = Object.values(bundleData.collections).reduce((acc, current) => {
@@ -262,7 +240,6 @@ formatBundleData_fn = function(bundleData) {
262
240
  return null;
263
241
  }
264
242
  };
265
- _isValueInRange = new WeakSet();
266
243
  isValueInRange_fn = function(ranges, value) {
267
244
  const matchedRanges = ranges.filter(({ min, max }) => {
268
245
  const minValue = min ?? value;
@@ -271,11 +248,11 @@ isValueInRange_fn = function(ranges, value) {
271
248
  });
272
249
  return !!matchedRanges.length;
273
250
  };
274
- _unique = new WeakSet();
275
251
  unique_fn = function(ids) {
276
252
  return Array.from(new Set(ids));
277
253
  };
278
- _hasOwn = new WeakSet();
254
+ // Own-property membership check. Guards against inherited keys (e.g. `__proto__`,
255
+ // `constructor`, `toString`) resolving to truthy values on plain-object maps.
279
256
  hasOwn_fn = function(target, key) {
280
257
  return Object.prototype.hasOwnProperty.call(target, key);
281
258
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.js","sources":["../../../src/utils/bundle.ts"],"sourcesContent":["import {\n array,\n enumType,\n field,\n int32,\n string as xdrString,\n struct,\n uint32,\n uint64,\n union,\n unionCase,\n voidType,\n UNBOUNDED_MAX_LENGTH,\n} from '@stellar/js-xdr';\nimport { BundleData as StorefrontBundleData, CDNBundleSettings } from '../types';\n\nconst textEncoder = new TextEncoder();\n\nconst emptyExt = { v: 0 } as const;\n\nfunction toBase64(bytes: Uint8Array) {\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\nconst EnvelopeType = enumType('EnvelopeType', {\n envelopeTypeBundle: 0,\n});\n\nconst BundleItemExt = union('BundleItemExt', {\n switchOn: int32(),\n switchKey: 'v',\n cases: [unionCase('v0', 0, voidType())],\n});\n\nconst BundleItem = struct('BundleItem', {\n collectionId: uint64(),\n productId: uint64(),\n variantId: uint64(),\n sku: xdrString(UNBOUNDED_MAX_LENGTH),\n quantity: uint32(),\n ext: BundleItemExt,\n});\n\nconst BundleExt = union('BundleExt', {\n switchOn: int32(),\n switchKey: 'v',\n cases: [unionCase('v0', 0, voidType())],\n});\n\nconst Bundle = struct('Bundle', {\n variantId: uint64(),\n items: array(BundleItem, 500),\n version: uint32(),\n ext: BundleExt,\n});\n\nconst BundleEnvelope = union('BundleEnvelope', {\n switchOn: EnvelopeType,\n switchKey: 'type',\n cases: [unionCase('envelopeTypeBundle', EnvelopeType.envelopeTypeBundle, field('v1', Bundle))],\n});\n\nexport function toLineItemProperty(bundle: { variantId: string; version: number; items: any[] }) {\n const value = {\n type: EnvelopeType.envelopeTypeBundle,\n v1: {\n variantId: BigInt(bundle.variantId.toString()),\n items: bundle.items.map(item => ({\n collectionId: BigInt(item.collectionId.toString()),\n productId: BigInt(item.productId.toString()),\n variantId: BigInt(item.variantId.toString()),\n sku: textEncoder.encode(item.sku || ''),\n quantity: item.quantity as number,\n ext: emptyExt,\n })),\n version: bundle.version || Math.floor(Date.now() / 1000),\n ext: emptyExt,\n },\n };\n\n return toBase64(BundleEnvelope.encode(value));\n}\n\nexport interface BundleSelectionItems {\n collectionId: string;\n externalProductId: string;\n externalVariantId: string;\n quantity: number;\n}\n\ninterface VariantSettings {\n externalVariantId: string;\n optionSources: Record<string, { collectionId: string; min: number | null; max: number | null }>;\n ranges: { min: number; max: number | null }[];\n}\n\ninterface BundleSettings {\n bundleSettings: { maxPerItem: number | null; isCustomizable: boolean };\n variantsSettings: Record<string, VariantSettings>;\n}\n\ntype BundleDataCollection = StorefrontBundleData['collections'][string];\n\ninterface BundleData extends Omit<StorefrontBundleData, 'collections'> {\n collections: Record<\n string,\n Omit<BundleDataCollection, 'products'> & {\n products: Record<string, BundleDataCollection['products'][number]>;\n }\n >;\n}\n\nexport class BundleSelectionValidator {\n #bundleSettings: BundleSettings | null;\n #items: BundleSelectionItems[];\n #bundleData: BundleData | null;\n\n constructor(selectionItems: BundleSelectionItems[], bundleData: StorefrontBundleData) {\n this.#bundleSettings = this.#formatBundleSettings(bundleData);\n this.#bundleData = this.#formatBundleData(bundleData);\n this.#items = selectionItems;\n }\n\n #formatBundleSettings(bundleData: StorefrontBundleData) {\n try {\n const bundleSettings = bundleData.bundle_settings;\n return {\n bundleSettings: {\n maxPerItem: bundleSettings.max_quantity_per_variant,\n isCustomizable: bundleSettings.is_customizable,\n },\n // null-proto seeds so external variant/option-source ids become real own keys, not prototype pollution\n variantsSettings: bundleSettings.variants.reduce<BundleSettings['variantsSettings']>((acc, variant) => {\n if (!variant.enabled) return acc;\n\n let ranges: VariantSettings['ranges'] = [{ min: variant.items_count, max: variant.items_count }];\n if (!variant.items_count) {\n ranges = variant.ranges.map(({ quantity_max, quantity_min }) => ({\n min: quantity_min,\n max: quantity_max,\n }));\n }\n\n acc[variant.external_variant_id] = {\n externalVariantId: variant.external_variant_id,\n optionSources: variant.option_sources.reduce<VariantSettings['optionSources']>((acc, optionSource) => {\n acc[optionSource.option_source_id] = {\n min: optionSource.quantity_min,\n max: optionSource.quantity_max,\n collectionId: optionSource.option_source_id,\n };\n return acc;\n }, Object.create(null)),\n ranges,\n };\n return acc;\n }, Object.create(null)),\n };\n } catch (error) {\n return null;\n }\n }\n\n #formatBundleData(bundleData: StorefrontBundleData) {\n try {\n // null-proto seeds so external collection/product ids become real own keys, not prototype pollution\n const collections = Object.values(bundleData.collections).reduce<BundleData['collections']>((acc, current) => {\n acc[current.id] = {\n ...current,\n products: current.products.reduce<BundleData['collections'][string]['products']>((productAcc, product) => {\n productAcc[product.id] = product;\n return productAcc;\n }, Object.create(null)),\n };\n\n return acc;\n }, Object.create(null));\n\n return { ...bundleData, collections };\n } catch (error) {\n return null;\n }\n }\n\n #isValueInRange(ranges: { min: number | null; max: number | null }[], value: number) {\n const matchedRanges = ranges.filter(({ min, max }) => {\n const minValue = min ?? value;\n const maxValue = max ?? value;\n\n return minValue <= value && value <= maxValue;\n });\n\n return !!matchedRanges.length;\n }\n\n #unique(ids: string[]) {\n return Array.from(new Set(ids));\n }\n\n // Own-property membership check. Guards against inherited keys (e.g. `__proto__`,\n // `constructor`, `toString`) resolving to truthy values on plain-object maps.\n #hasOwn(target: object, key: string) {\n return Object.prototype.hasOwnProperty.call(target, key);\n }\n\n isInitialDataValid() {\n if (!this.#bundleData) {\n throw 'Bundle data does not exist for the given product.';\n }\n\n if (!this.#bundleSettings) {\n throw 'Bundle settings do not exist for the given product.';\n }\n\n if (!Array.isArray(this.#items) || !this.#items.length) {\n throw 'No bundle selection items provided.';\n }\n\n return true;\n }\n\n isValidVariant(externalVariantId: string) {\n if (!this.#bundleSettings?.variantsSettings[externalVariantId]) {\n throw `The ${externalVariantId} bundle variant is invalid.`;\n }\n\n return true;\n }\n\n isSelectionInVariantRange(externalVariantId: string) {\n const total = this.#items.reduce((acc, current) => acc + current.quantity, 0);\n const ranges = this.#bundleSettings?.variantsSettings[externalVariantId].ranges || [];\n\n if (!this.#isValueInRange(ranges, total)) {\n throw 'The total number of products does not fall within the required variant range.';\n }\n\n return true;\n }\n\n areItemsInMaxPerItemBound() {\n const maxPerItem = this.#bundleSettings?.bundleSettings.maxPerItem || 0;\n const invalidProducts = this.#items.filter(({ quantity }) => quantity > maxPerItem);\n\n if (maxPerItem && invalidProducts.length) {\n const invalidIds = this.#unique(invalidProducts.map(({ externalProductId }) => externalProductId)).join(', ');\n throw `The selected products (${invalidIds}) exceed the maximum limit of ${maxPerItem} items per product.`;\n }\n\n return true;\n }\n\n areSelectedCollectionsValid(externalVariantId: string) {\n const variantSettings = this.#bundleSettings?.variantsSettings[externalVariantId];\n const optionSources = variantSettings?.optionSources;\n const invalidCollections = this.#items.filter(\n ({ collectionId }) => !optionSources || !this.#hasOwn(optionSources, collectionId)\n );\n if (invalidCollections.length) {\n const invalidIds = this.#unique(invalidCollections.map(({ collectionId }) => collectionId)).join(', ');\n throw `The collections (${invalidIds}) are no longer valid for the bundle variant (${externalVariantId}).`;\n }\n\n return true;\n }\n\n areItemsQuantitiesValidForTheCollection(externalVariantId: string) {\n // null-proto seed so a `__proto__` collectionId becomes a real own key, not prototype pollution\n const totalSelectedByCollection = this.#items.reduce<Record<string, number>>((acc, current) => {\n acc[current.collectionId] = current.quantity + (acc[current.collectionId] || 0);\n return acc;\n }, Object.create(null));\n\n const variantSettings = this.#bundleSettings?.variantsSettings[externalVariantId];\n const invalidItems = Object.values(variantSettings?.optionSources || {}).filter(collection => {\n const quantity = totalSelectedByCollection[collection.collectionId] || 0;\n return !this.#isValueInRange([collection], quantity);\n });\n\n if (!variantSettings || invalidItems.length) {\n const invalidIds = this.#unique(invalidItems.map(({ collectionId }) => collectionId)).join(', ');\n throw `The selection exceeds the limits for the collections (${invalidIds}).`;\n }\n\n return true;\n }\n\n areSelectedProductsValid(externalVariantId: string) {\n const bundleVariantCollections = this.#bundleSettings?.variantsSettings[externalVariantId]?.optionSources || {};\n // null-proto seed so a `__proto__` collectionId becomes a real own key, not prototype pollution\n const variantCollections = Object.values(bundleVariantCollections).reduce<BundleData['collections']>(\n (acc, optionSource) => {\n const collection = this.#bundleData?.collections[optionSource.collectionId];\n if (collection) {\n acc[optionSource.collectionId] = collection;\n }\n return acc;\n },\n Object.create(null)\n );\n\n if (!Object.values(variantCollections).length) {\n throw `No collections found for the bundle variant (${externalVariantId}).`;\n }\n\n const missingProducts = this.#items.filter(({ externalProductId, collectionId }) => {\n if (!this.#hasOwn(variantCollections, collectionId)) {\n return true;\n }\n return !this.#hasOwn(variantCollections[collectionId].products, externalProductId);\n });\n\n if (missingProducts.length) {\n const invalidIds = this.#unique(missingProducts.map(({ externalProductId }) => externalProductId)).join(', ');\n throw `The products (${invalidIds}) are no longer valid for the bundle product.`;\n }\n\n return true;\n }\n\n isBundleSelectionValid(externalVariantId: string) {\n this.isInitialDataValid();\n this.isValidVariant(externalVariantId);\n this.isSelectionInVariantRange(externalVariantId);\n this.areItemsInMaxPerItemBound();\n this.areSelectedCollectionsValid(externalVariantId);\n this.areItemsQuantitiesValidForTheCollection(externalVariantId);\n this.areSelectedProductsValid(externalVariantId);\n\n return true;\n }\n}\n"],"names":["enumType","union","int32","unionCase","voidType","struct","uint64","xdrString","UNBOUNDED_MAX_LENGTH","uint32","array","field","acc"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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;AACpD,IAAA,MAAM,WAAW,GAAO,IAAA,KAAA,CAAA;AACxB,IAAA,MAAM,WAAW,GAAO,IAAA,KAAA,CAAA;AAExB,IAAO,OAAA,QAAA,IAAY,SAAS,KAAS,IAAA,QAAA,CAAA;AAAA,GACtC,CAAA,CAAA;AAED,EAAO,OAAA,CAAC,CAAC,aAAc,CAAA,MAAA,CAAA;AACzB,CAAA,CAAA;AAEA,OAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAAA,SAAA,GAAO,SAAC,GAAe,EAAA;AACrB,EAAA,OAAO,KAAM,CAAA,IAAA,CAAK,IAAI,GAAA,CAAI,GAAG,CAAC,CAAA,CAAA;AAChC,CAAA,CAAA;AAIA,OAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAAA,SAAO,GAAA,SAAC,QAAgB,GAAa,EAAA;AACnC,EAAA,OAAO,MAAO,CAAA,SAAA,CAAU,cAAe,CAAA,IAAA,CAAK,QAAQ,GAAG,CAAA,CAAA;AACzD,CAAA;;;;;"}
1
+ {"version":3,"file":"bundle.js","sources":["../../../src/utils/bundle.ts"],"sourcesContent":["import {\n array,\n enumType,\n field,\n int32,\n string as xdrString,\n struct,\n uint32,\n uint64,\n union,\n unionCase,\n voidType,\n UNBOUNDED_MAX_LENGTH,\n} from '@stellar/js-xdr';\nimport { BundleData as StorefrontBundleData, CDNBundleSettings } from '../types';\n\nconst textEncoder = new TextEncoder();\n\nconst emptyExt = { v: 0 } as const;\n\nfunction toBase64(bytes: Uint8Array) {\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\nconst EnvelopeType = enumType('EnvelopeType', {\n envelopeTypeBundle: 0,\n});\n\nconst BundleItemExt = union('BundleItemExt', {\n switchOn: int32(),\n switchKey: 'v',\n cases: [unionCase('v0', 0, voidType())],\n});\n\nconst BundleItem = struct('BundleItem', {\n collectionId: uint64(),\n productId: uint64(),\n variantId: uint64(),\n sku: xdrString(UNBOUNDED_MAX_LENGTH),\n quantity: uint32(),\n ext: BundleItemExt,\n});\n\nconst BundleExt = union('BundleExt', {\n switchOn: int32(),\n switchKey: 'v',\n cases: [unionCase('v0', 0, voidType())],\n});\n\nconst Bundle = struct('Bundle', {\n variantId: uint64(),\n items: array(BundleItem, 500),\n version: uint32(),\n ext: BundleExt,\n});\n\nconst BundleEnvelope = union('BundleEnvelope', {\n switchOn: EnvelopeType,\n switchKey: 'type',\n cases: [unionCase('envelopeTypeBundle', EnvelopeType.envelopeTypeBundle, field('v1', Bundle))],\n});\n\nexport function toLineItemProperty(bundle: { variantId: string; version: number; items: any[] }) {\n const value = {\n type: EnvelopeType.envelopeTypeBundle,\n v1: {\n variantId: BigInt(bundle.variantId.toString()),\n items: bundle.items.map(item => ({\n collectionId: BigInt(item.collectionId.toString()),\n productId: BigInt(item.productId.toString()),\n variantId: BigInt(item.variantId.toString()),\n sku: textEncoder.encode(item.sku || ''),\n quantity: item.quantity as number,\n ext: emptyExt,\n })),\n version: bundle.version || Math.floor(Date.now() / 1000),\n ext: emptyExt,\n },\n };\n\n return toBase64(BundleEnvelope.encode(value));\n}\n\nexport interface BundleSelectionItems {\n collectionId: string;\n externalProductId: string;\n externalVariantId: string;\n quantity: number;\n}\n\ninterface VariantSettings {\n externalVariantId: string;\n optionSources: Record<string, { collectionId: string; min: number | null; max: number | null }>;\n ranges: { min: number; max: number | null }[];\n}\n\ninterface BundleSettings {\n bundleSettings: { maxPerItem: number | null; isCustomizable: boolean };\n variantsSettings: Record<string, VariantSettings>;\n}\n\ntype BundleDataCollection = StorefrontBundleData['collections'][string];\n\ninterface BundleData extends Omit<StorefrontBundleData, 'collections'> {\n collections: Record<\n string,\n Omit<BundleDataCollection, 'products'> & {\n products: Record<string, BundleDataCollection['products'][number]>;\n }\n >;\n}\n\nexport class BundleSelectionValidator {\n #bundleSettings: BundleSettings | null;\n #items: BundleSelectionItems[];\n #bundleData: BundleData | null;\n\n constructor(selectionItems: BundleSelectionItems[], bundleData: StorefrontBundleData) {\n this.#bundleSettings = this.#formatBundleSettings(bundleData);\n this.#bundleData = this.#formatBundleData(bundleData);\n this.#items = selectionItems;\n }\n\n #formatBundleSettings(bundleData: StorefrontBundleData) {\n try {\n const bundleSettings = bundleData.bundle_settings;\n return {\n bundleSettings: {\n maxPerItem: bundleSettings.max_quantity_per_variant,\n isCustomizable: bundleSettings.is_customizable,\n },\n // null-proto seeds so external variant/option-source ids become real own keys, not prototype pollution\n variantsSettings: bundleSettings.variants.reduce<BundleSettings['variantsSettings']>((acc, variant) => {\n if (!variant.enabled) return acc;\n\n let ranges: VariantSettings['ranges'] = [{ min: variant.items_count, max: variant.items_count }];\n if (!variant.items_count) {\n ranges = variant.ranges.map(({ quantity_max, quantity_min }) => ({\n min: quantity_min,\n max: quantity_max,\n }));\n }\n\n acc[variant.external_variant_id] = {\n externalVariantId: variant.external_variant_id,\n optionSources: variant.option_sources.reduce<VariantSettings['optionSources']>((acc, optionSource) => {\n acc[optionSource.option_source_id] = {\n min: optionSource.quantity_min,\n max: optionSource.quantity_max,\n collectionId: optionSource.option_source_id,\n };\n return acc;\n }, Object.create(null)),\n ranges,\n };\n return acc;\n }, Object.create(null)),\n };\n } catch (error) {\n return null;\n }\n }\n\n #formatBundleData(bundleData: StorefrontBundleData) {\n try {\n // null-proto seeds so external collection/product ids become real own keys, not prototype pollution\n const collections = Object.values(bundleData.collections).reduce<BundleData['collections']>((acc, current) => {\n acc[current.id] = {\n ...current,\n products: current.products.reduce<BundleData['collections'][string]['products']>((productAcc, product) => {\n productAcc[product.id] = product;\n return productAcc;\n }, Object.create(null)),\n };\n\n return acc;\n }, Object.create(null));\n\n return { ...bundleData, collections };\n } catch (error) {\n return null;\n }\n }\n\n #isValueInRange(ranges: { min: number | null; max: number | null }[], value: number) {\n const matchedRanges = ranges.filter(({ min, max }) => {\n const minValue = min ?? value;\n const maxValue = max ?? value;\n\n return minValue <= value && value <= maxValue;\n });\n\n return !!matchedRanges.length;\n }\n\n #unique(ids: string[]) {\n return Array.from(new Set(ids));\n }\n\n // Own-property membership check. Guards against inherited keys (e.g. `__proto__`,\n // `constructor`, `toString`) resolving to truthy values on plain-object maps.\n #hasOwn(target: object, key: string) {\n return Object.prototype.hasOwnProperty.call(target, key);\n }\n\n isInitialDataValid() {\n if (!this.#bundleData) {\n throw 'Bundle data does not exist for the given product.';\n }\n\n if (!this.#bundleSettings) {\n throw 'Bundle settings do not exist for the given product.';\n }\n\n if (!Array.isArray(this.#items) || !this.#items.length) {\n throw 'No bundle selection items provided.';\n }\n\n return true;\n }\n\n isValidVariant(externalVariantId: string) {\n if (!this.#bundleSettings?.variantsSettings[externalVariantId]) {\n throw `The ${externalVariantId} bundle variant is invalid.`;\n }\n\n return true;\n }\n\n isSelectionInVariantRange(externalVariantId: string) {\n const total = this.#items.reduce((acc, current) => acc + current.quantity, 0);\n const ranges = this.#bundleSettings?.variantsSettings[externalVariantId].ranges || [];\n\n if (!this.#isValueInRange(ranges, total)) {\n throw 'The total number of products does not fall within the required variant range.';\n }\n\n return true;\n }\n\n areItemsInMaxPerItemBound() {\n const maxPerItem = this.#bundleSettings?.bundleSettings.maxPerItem || 0;\n const invalidProducts = this.#items.filter(({ quantity }) => quantity > maxPerItem);\n\n if (maxPerItem && invalidProducts.length) {\n const invalidIds = this.#unique(invalidProducts.map(({ externalProductId }) => externalProductId)).join(', ');\n throw `The selected products (${invalidIds}) exceed the maximum limit of ${maxPerItem} items per product.`;\n }\n\n return true;\n }\n\n areSelectedCollectionsValid(externalVariantId: string) {\n const variantSettings = this.#bundleSettings?.variantsSettings[externalVariantId];\n const optionSources = variantSettings?.optionSources;\n const invalidCollections = this.#items.filter(\n ({ collectionId }) => !optionSources || !this.#hasOwn(optionSources, collectionId)\n );\n if (invalidCollections.length) {\n const invalidIds = this.#unique(invalidCollections.map(({ collectionId }) => collectionId)).join(', ');\n throw `The collections (${invalidIds}) are no longer valid for the bundle variant (${externalVariantId}).`;\n }\n\n return true;\n }\n\n areItemsQuantitiesValidForTheCollection(externalVariantId: string) {\n // null-proto seed so a `__proto__` collectionId becomes a real own key, not prototype pollution\n const totalSelectedByCollection = this.#items.reduce<Record<string, number>>((acc, current) => {\n acc[current.collectionId] = current.quantity + (acc[current.collectionId] || 0);\n return acc;\n }, Object.create(null));\n\n const variantSettings = this.#bundleSettings?.variantsSettings[externalVariantId];\n const invalidItems = Object.values(variantSettings?.optionSources || {}).filter(collection => {\n const quantity = totalSelectedByCollection[collection.collectionId] || 0;\n return !this.#isValueInRange([collection], quantity);\n });\n\n if (!variantSettings || invalidItems.length) {\n const invalidIds = this.#unique(invalidItems.map(({ collectionId }) => collectionId)).join(', ');\n throw `The selection exceeds the limits for the collections (${invalidIds}).`;\n }\n\n return true;\n }\n\n areSelectedProductsValid(externalVariantId: string) {\n const bundleVariantCollections = this.#bundleSettings?.variantsSettings[externalVariantId]?.optionSources || {};\n // null-proto seed so a `__proto__` collectionId becomes a real own key, not prototype pollution\n const variantCollections = Object.values(bundleVariantCollections).reduce<BundleData['collections']>(\n (acc, optionSource) => {\n const collection = this.#bundleData?.collections[optionSource.collectionId];\n if (collection) {\n acc[optionSource.collectionId] = collection;\n }\n return acc;\n },\n Object.create(null)\n );\n\n if (!Object.values(variantCollections).length) {\n throw `No collections found for the bundle variant (${externalVariantId}).`;\n }\n\n const missingProducts = this.#items.filter(({ externalProductId, collectionId }) => {\n if (!this.#hasOwn(variantCollections, collectionId)) {\n return true;\n }\n return !this.#hasOwn(variantCollections[collectionId].products, externalProductId);\n });\n\n if (missingProducts.length) {\n const invalidIds = this.#unique(missingProducts.map(({ externalProductId }) => externalProductId)).join(', ');\n throw `The products (${invalidIds}) are no longer valid for the bundle product.`;\n }\n\n return true;\n }\n\n isBundleSelectionValid(externalVariantId: string) {\n this.isInitialDataValid();\n this.isValidVariant(externalVariantId);\n this.isSelectionInVariantRange(externalVariantId);\n this.areItemsInMaxPerItemBound();\n this.areSelectedCollectionsValid(externalVariantId);\n this.areItemsQuantitiesValidForTheCollection(externalVariantId);\n this.areSelectedProductsValid(externalVariantId);\n\n return true;\n }\n}\n"],"names":["enumType","union","int32","unionCase","voidType","struct","uint64","xdrString","UNBOUNDED_MAX_LENGTH","uint32","array","field","acc"],"mappings":";;;;;;;;;;;;AAAA,IAAA,eAAA,EAAA,MAAA,EAAA,WAAA,EAAA,mCAAA,EAAA,uBAAA,EAAA,mBAAA,EAAA,iBAAA,EAAA,SAAA,EAAA,SAAA;AAgBA,MAAM,WAAA,GAAc,IAAI,WAAA,EAAY;AAEpC,MAAM,QAAA,GAAW,EAAE,CAAA,EAAG,CAAA,EAAE;AAExB,SAAS,SAAS,KAAA,EAAmB;AACnC,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,QAAQ,CAAA,EAAA,EAAK;AACrC,IAAA,MAAA,IAAU,MAAA,CAAO,YAAA,CAAa,KAAA,CAAM,CAAC,CAAC,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,KAAK,MAAM,CAAA;AACpB;AAEA,MAAM,YAAA,GAAeA,eAAS,cAAA,EAAgB;AAAA,EAC5C,kBAAA,EAAoB;AACtB,CAAC,CAAA;AAED,MAAM,aAAA,GAAgBC,YAAM,eAAA,EAAiB;AAAA,EAC3C,UAAUC,WAAA,EAAM;AAAA,EAChB,SAAA,EAAW,GAAA;AAAA,EACX,OAAO,CAACC,eAAA,CAAU,MAAM,CAAA,EAAGC,cAAA,EAAU,CAAC;AACxC,CAAC,CAAA;AAED,MAAM,UAAA,GAAaC,aAAO,YAAA,EAAc;AAAA,EACtC,cAAcC,YAAA,EAAO;AAAA,EACrB,WAAWA,YAAA,EAAO;AAAA,EAClB,WAAWA,YAAA,EAAO;AAAA,EAClB,GAAA,EAAKC,aAAUC,0BAAoB,CAAA;AAAA,EACnC,UAAUC,YAAA,EAAO;AAAA,EACjB,GAAA,EAAK;AACP,CAAC,CAAA;AAED,MAAM,SA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T,CAAA,kBAAG,MAAA,CAAO,MAAA,CAAO,IAAI,CAAC,CAAA;AAEtB,IAAA,OAAO,EAAE,GAAG,UAAA,EAAY,WAAA,EAAY;AAAA,EACtC,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,IAAA;AAAA,EACT;AACF,CAAA;AAEA,iBAAA,GAAe,SAAC,QAAsD,KAAA,EAAe;AACnF,EAAA,MAAM,gBAAgB,MAAA,CAAO,MAAA,CAAO,CAAC,EAAE,GAAA,EAAK,KAAI,KAAM;AACpD,IAAA,MAAM,WAAW,GAAA,IAAO,KAAA;AACxB,IAAA,MAAM,WAAW,GAAA,IAAO,KAAA;AAExB,IAAA,OAAO,QAAA,IAAY,SAAS,KAAA,IAAS,QAAA;AAAA,EACvC,CAAC,CAAA;AAED,EAAA,OAAO,CAAC,CAAC,aAAA,CAAc,MAAA;AACzB,CAAA;AAEA,SAAA,GAAO,SAAC,GAAA,EAAe;AACrB,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,GAAA,CAAI,GAAG,CAAC,CAAA;AAChC,CAAA;AAAA;AAAA;AAIA,SAAA,GAAO,SAAC,QAAgB,GAAA,EAAa;AACnC,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,QAAQ,GAAG,CAAA;AACzD,CAAA;;;"}
@@ -29,8 +29,7 @@ const mapBundleSettings = (bundleSettings) => {
29
29
  };
30
30
  };
31
31
  const mapIncentives = (incentives) => {
32
- if (incentives.tiered_discounts.length === 0)
33
- return null;
32
+ if (incentives.tiered_discounts.length === 0) return null;
34
33
  return {
35
34
  tiered_discounts: incentives.tiered_discounts
36
35
  };
@@ -59,10 +58,8 @@ const mapBasicVariant = (variant) => ({
59
58
  available_for_sale: variant.available
60
59
  });
61
60
  const formatFeaturedImage = (featuredImage) => {
62
- if (featuredImage == null || typeof featuredImage === "string")
63
- return featuredImage;
64
- if ("src" in featuredImage)
65
- return featuredImage["src"];
61
+ if (featuredImage == null || typeof featuredImage === "string") return featuredImage;
62
+ if ("src" in featuredImage) return featuredImage["src"];
66
63
  return null;
67
64
  };
68
65
  const mapBasicProduct = (product) => {
@@ -124,8 +121,7 @@ const productSellingPlansGroupLookup = (sellingPlanGroups) => sellingPlanGroups.
124
121
  return acc;
125
122
  }, {});
126
123
  const mapFilters = (filters) => {
127
- if (!Array.isArray(filters))
128
- return [];
124
+ if (!Array.isArray(filters)) return [];
129
125
  return filters;
130
126
  };
131
127
  function mapOnlineStoreToPublicBundleData(bundleData) {
@@ -1 +1 @@
1
- {"version":3,"file":"bundleData.js","sources":["../../../src/utils/bundleData.ts"],"sourcesContent":["import { PublicBundleData, PriceRule } from '../types/bundleData';\nimport { BaseProduct, BaseProductVariant, BundleData as StorefrontBundleData } from '../types/bundle';\n\nconst mapBundleSettings = (bundleSettings: StorefrontBundleData['bundle_settings']) => {\n const addons = bundleSettings.layout_settings.addons;\n const crossSells = bundleSettings.layout_settings.crossSells;\n const customizationWindow = bundleSettings.customization_window;\n const defaultVariantId = bundleSettings.layout_settings?.defaultVariantId ?? bundleSettings.default_bundle_variant_id;\n const defaultFrequency = bundleSettings.layout_settings.defaultFrequency;\n const addToCartBehavior = bundleSettings.layout_settings.addToCartCallback;\n\n return {\n default_variant_id: defaultVariantId ? String(defaultVariantId) : null,\n is_customizable: bundleSettings.is_customizable,\n price_rule: String(bundleSettings.price_rule).toUpperCase(),\n customization_window: customizationWindow\n ? {\n active_days: customizationWindow,\n disabled_message: bundleSettings.customization_window_disabled_message || '',\n }\n : null,\n addons: addons.collectionId\n ? { collection_id: addons.collectionId, collection_handle: addons.collectionHandle }\n : null,\n cross_sells: crossSells.collectionId\n ? { collection_id: addons.collectionId, collection_handle: addons.collectionHandle }\n : null,\n default_selling_plan_id: defaultFrequency || null,\n collapsible_collections: bundleSettings.layout_settings.collapsibleSections,\n max_quantity_per_variant: bundleSettings.max_quantity_per_variant,\n show_product_variants: bundleSettings.layout_settings.showVariants,\n product_details_modal_enabled: bundleSettings.layout_settings.learnMoreModal,\n addToCartBehavior: {\n type: addToCartBehavior.type === 'none' ? ('cart_page' as const) : addToCartBehavior.type,\n value: addToCartBehavior.value,\n },\n };\n};\n\nconst mapIncentives = (incentives: StorefrontBundleData['incentives']): PublicBundleData['incentives'] => {\n if (incentives.tiered_discounts.length === 0) return null;\n\n return {\n tiered_discounts: incentives.tiered_discounts,\n };\n};\n\nconst mapSellingPlan = (\n sellingPlan: StorefrontBundleData['selling_plan_groups'][number]['selling_plans'][number]\n): PublicBundleData['selling_plan_groups'][number]['selling_plans'][number] => ({\n id: sellingPlan.id,\n name: sellingPlan.name,\n options: sellingPlan.options.map(option => ({ name: option.name, value: option.value })),\n recurring_deliveries: sellingPlan.recurring_deliveries,\n price_adjustments: sellingPlan.price_adjustments.map(({ value, value_type }) => ({\n value,\n value_type,\n })),\n});\n\nconst mapSellingPlanGroups = (\n sellingPlanGroup: StorefrontBundleData['selling_plan_groups'][number]\n): PublicBundleData['selling_plan_groups'][number] => ({\n name: sellingPlanGroup.name,\n options: sellingPlanGroup.options.map(option => ({ name: option.name, values: option.values })),\n selling_plans: sellingPlanGroup.selling_plans.map(mapSellingPlan),\n});\n\nconst mapBasicVariant = (variant: BaseProductVariant) => ({\n id: String(variant.id),\n title: variant.title,\n price: variant.price,\n compare_at_price: variant.compare_at_price,\n options: variant.options,\n available_for_sale: variant.available,\n});\n\nconst formatFeaturedImage = (featuredImage: BaseProduct['featured_image']): string | null => {\n if (featuredImage == null || typeof featuredImage === 'string') return featuredImage;\n\n if ('src' in featuredImage) return featuredImage['src'];\n\n return null;\n};\n\nconst mapBasicProduct = (product: BaseProduct) => {\n return {\n id: String(product.id),\n title: product.title,\n description: product.description,\n available_for_sale: product.available,\n featured_image: formatFeaturedImage(product.featured_image),\n images: product.images,\n requires_selling_plan: product.requires_selling_plan,\n selling_plan_groups: product.selling_plan_groups.map(mapSellingPlanGroups),\n };\n};\n\nconst mapProduct = (product: StorefrontBundleData['collections'][number]['products'][number]) => {\n const productPlansLookup = productSellingPlansGroupLookup(product.selling_plan_groups);\n\n return {\n ...mapBasicProduct(product),\n handle: product.handle,\n tags: product.tags,\n price_range: { min: product.price_min, max: product.price_max },\n compare_at_price_range: { min: product.compare_at_price_min, max: product.compare_at_price_max },\n options: product.options,\n variants: product.variants.map(variant => ({\n ...mapBasicVariant(variant),\n selling_plan_allocations: variant.selling_plan_allocations.map(sellingPlan => ({\n price: sellingPlan.price,\n compare_at_price: sellingPlan.compare_at_price,\n selling_plan: mapSellingPlan(\n productPlansLookup[`${sellingPlan.selling_plan_group_id}-${sellingPlan.selling_plan_id}`]\n ),\n })),\n option1: variant.option1,\n option2: variant.option2,\n option3: variant.option3,\n sku: variant.sku || '',\n requires_shipping: variant.requires_shipping,\n taxable: variant.taxable,\n featured_image: formatFeaturedImage(variant.featured_image),\n public_title: variant.public_title,\n requires_selling_plan: variant.requires_selling_plan,\n })),\n };\n};\n\nconst mapBundleVariantRanges = ({\n items_count,\n ranges,\n}: Pick<StorefrontBundleData['bundle_settings']['variants'][number], 'items_count' | 'ranges'>) => {\n if (ranges.length > 0) {\n return ranges.map(({ quantity_max, quantity_min }) => ({ min: quantity_min, max: quantity_max }));\n }\n\n return [{ min: items_count, max: items_count }];\n};\n\nconst productSellingPlansGroupLookup = (sellingPlanGroups: BaseProduct['selling_plan_groups']) =>\n sellingPlanGroups.reduce<\n Record<string, StorefrontBundleData['selling_plan_groups'][number]['selling_plans'][number]>\n >((acc, current) => {\n current.selling_plans.forEach(sellingPlan => {\n const key = `${current.id}-${sellingPlan.id}`;\n acc[key] = sellingPlan;\n });\n\n return acc;\n }, {});\n\nconst mapFilters = (filters: StorefrontBundleData['filters']): PublicBundleData['filters'] => {\n if (!Array.isArray(filters)) return [];\n return filters;\n};\n\nexport function mapOnlineStoreToPublicBundleData(bundleData: StorefrontBundleData): PublicBundleData {\n const bundleSettings = mapBundleSettings(bundleData.bundle_settings);\n const variantsLookup = bundleData.variants.reduce<Record<string, StorefrontBundleData['variants'][number]>>(\n (acc, variant) => {\n acc[variant.id] = variant;\n return acc;\n },\n {}\n );\n\n return {\n id: String(bundleData.id),\n title: bundleData.title,\n description: bundleData.description || null,\n handle: bundleData.handle,\n options: bundleData.options.map(option => ({\n name: option.name,\n position: option.position,\n values: option.values,\n })),\n default_variant_id: bundleSettings.default_variant_id,\n default_selling_plan_id: bundleSettings.default_selling_plan_id\n ? Number(bundleSettings.default_selling_plan_id)\n : null,\n available_for_sale: bundleData.available,\n requires_selling_plan: bundleData.requires_selling_plan,\n bundle_settings: {\n is_customizable: bundleSettings.is_customizable,\n price_rule: bundleSettings.price_rule as PriceRule,\n customization_window: bundleSettings.customization_window,\n max_quantity_per_variant: bundleSettings.max_quantity_per_variant,\n collapsible_collections: bundleSettings.collapsible_collections,\n show_product_variants: bundleSettings.show_product_variants,\n product_details_modal_enabled: bundleSettings.product_details_modal_enabled,\n show_variants_as_individual_products:\n bundleData.bundle_settings.settings.display_variants_as_separate_products_in_list,\n post_add_to_cart_behavior: bundleSettings.addToCartBehavior,\n },\n variants: bundleData.bundle_settings.variants\n .filter(({ enabled }) => enabled)\n .map((item, index) => {\n const variant = variantsLookup[String(item.external_variant_id)];\n\n return {\n id: String(item.external_variant_id),\n title: variant.title,\n price: variant.price,\n compare_at_price: variant.compare_at_price,\n image: variant.image || '',\n available_for_sale: variant.available,\n options: variant.options,\n requires_selling_plan: variant.requires_selling_plan,\n selling_plan_allocations: variant.selling_plan_allocations.map(sellingPlan => ({\n price: sellingPlan.price,\n compare_at_price: sellingPlan.compare_at_price,\n selling_plan: mapSellingPlan(sellingPlan.selling_plan),\n })),\n ranges: mapBundleVariantRanges(item),\n collections: item.option_sources.map(source => ({\n id: source.option_source_id,\n source_platform: 'shopify',\n min: source.quantity_min || 0,\n max: source.quantity_max,\n position: source.position,\n })),\n default_selections: item.selection_defaults.map(selectionDefault => ({\n quantity: selectionDefault.quantity,\n product: {\n id: String(selectionDefault.product.id),\n handle: selectionDefault.handle,\n title: selectionDefault.product.title,\n description: selectionDefault.product.description,\n images: selectionDefault.product.images,\n },\n variant: {\n id: selectionDefault.external_variant_id,\n title: selectionDefault.variant.title,\n featured_image: formatFeaturedImage(selectionDefault.variant.featured_image),\n sku: selectionDefault.sku || '',\n },\n })),\n position: index,\n };\n }),\n selling_plan_groups: bundleData.selling_plan_groups.map(mapSellingPlanGroups),\n collections: Object.values(bundleData.collections).reduce<PublicBundleData['collections']>((acc, current) => {\n if (!Array.isArray(current.products)) {\n /* If a collection is not published in Online store, it is included \n as _1:{ handle: \"<collection-handle\"} in the collections object.\n We need to skip these collections.\n */\n return acc;\n }\n\n acc[String(current.id)] = {\n id: String(current.id),\n title: current.title,\n handle: current.handle,\n products: current.products.map(mapProduct),\n };\n\n return acc;\n }, {}),\n addons: bundleData.addons.products.length\n ? {\n collection_id: bundleSettings.addons?.collection_id || '',\n collection_handle: bundleSettings.addons?.collection_handle || '',\n products: bundleData.addons.products.map(product => ({\n ...mapBasicProduct(product),\n price_range: { min: product.price, max: product.price },\n compare_at_price_range: { min: product.compare_at_price || 0, max: product.compare_at_price },\n variants: product.variants.map(variant => ({\n ...mapBasicVariant(variant),\n image: variant.image,\n selling_plan_allocations: variant.selling_plan_allocations.map(sellingPlan => ({\n price: sellingPlan.price,\n compare_at_price: sellingPlan.compare_at_price,\n selling_plan: mapSellingPlan(sellingPlan.selling_plan),\n })),\n })),\n })),\n }\n : null,\n cross_sells: bundleData.cross_sells.products.length\n ? {\n collection_id: bundleSettings.cross_sells?.collection_id || '',\n collection_handle: bundleSettings.cross_sells?.collection_handle || '',\n products: bundleData.cross_sells.products.map(mapProduct),\n }\n : null,\n incentives: mapIncentives(bundleData.incentives),\n filters: mapFilters(bundleData.filters),\n templates: bundleData.bundle_settings.layout_settings.templates || null,\n globalStyles: bundleData.bundle_settings.layout_settings.globalStyles || null,\n };\n}\n"],"names":[],"mappings":";;AAGA,MAAM,iBAAA,GAAoB,CAAC,cAA4D,KAAA;AACrF,EAAM,MAAA,MAAA,GAAS,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CAAS,MACzC,GAAA;AAAA,MACE,aAAA,EAAe,cAAe,CAAA,WAAA,EAAa,aAAiB,IAAA,EAAA;AAAA,MAC5D,iBAAA,EAAmB,cAAe,CAAA,WAAA,EAAa,iBAAqB,IAAA,EAAA;AAAA,MACpE,QAAU,EAAA,UAAA,CAAW,WAAY,CAAA,QAAA,CAAS,IAAI,UAAU,CAAA;AAAA,KAE1D,GAAA,IAAA;AAAA,IACJ,UAAA,EAAY,aAAc,CAAA,UAAA,CAAW,UAAU,CAAA;AAAA,IAC/C,OAAA,EAAS,UAAW,CAAA,UAAA,CAAW,OAAO,CAAA;AAAA,IACtC,SAAW,EAAA,UAAA,CAAW,eAAgB,CAAA,eAAA,CAAgB,SAAa,IAAA,IAAA;AAAA,IACnE,YAAc,EAAA,UAAA,CAAW,eAAgB,CAAA,eAAA,CAAgB,YAAgB,IAAA,IAAA;AAAA,GAC3E,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"bundleData.js","sources":["../../../src/utils/bundleData.ts"],"sourcesContent":["import { PublicBundleData, PriceRule } from '../types/bundleData';\nimport { BaseProduct, BaseProductVariant, BundleData as StorefrontBundleData } from '../types/bundle';\n\nconst mapBundleSettings = (bundleSettings: StorefrontBundleData['bundle_settings']) => {\n const addons = bundleSettings.layout_settings.addons;\n const crossSells = bundleSettings.layout_settings.crossSells;\n const customizationWindow = bundleSettings.customization_window;\n const defaultVariantId = bundleSettings.layout_settings?.defaultVariantId ?? bundleSettings.default_bundle_variant_id;\n const defaultFrequency = bundleSettings.layout_settings.defaultFrequency;\n const addToCartBehavior = bundleSettings.layout_settings.addToCartCallback;\n\n return {\n default_variant_id: defaultVariantId ? String(defaultVariantId) : null,\n is_customizable: bundleSettings.is_customizable,\n price_rule: String(bundleSettings.price_rule).toUpperCase(),\n customization_window: customizationWindow\n ? {\n active_days: customizationWindow,\n disabled_message: bundleSettings.customization_window_disabled_message || '',\n }\n : null,\n addons: addons.collectionId\n ? { collection_id: addons.collectionId, collection_handle: addons.collectionHandle }\n : null,\n cross_sells: crossSells.collectionId\n ? { collection_id: addons.collectionId, collection_handle: addons.collectionHandle }\n : null,\n default_selling_plan_id: defaultFrequency || null,\n collapsible_collections: bundleSettings.layout_settings.collapsibleSections,\n max_quantity_per_variant: bundleSettings.max_quantity_per_variant,\n show_product_variants: bundleSettings.layout_settings.showVariants,\n product_details_modal_enabled: bundleSettings.layout_settings.learnMoreModal,\n addToCartBehavior: {\n type: addToCartBehavior.type === 'none' ? ('cart_page' as const) : addToCartBehavior.type,\n value: addToCartBehavior.value,\n },\n };\n};\n\nconst mapIncentives = (incentives: StorefrontBundleData['incentives']): PublicBundleData['incentives'] => {\n if (incentives.tiered_discounts.length === 0) return null;\n\n return {\n tiered_discounts: incentives.tiered_discounts,\n };\n};\n\nconst mapSellingPlan = (\n sellingPlan: StorefrontBundleData['selling_plan_groups'][number]['selling_plans'][number]\n): PublicBundleData['selling_plan_groups'][number]['selling_plans'][number] => ({\n id: sellingPlan.id,\n name: sellingPlan.name,\n options: sellingPlan.options.map(option => ({ name: option.name, value: option.value })),\n recurring_deliveries: sellingPlan.recurring_deliveries,\n price_adjustments: sellingPlan.price_adjustments.map(({ value, value_type }) => ({\n value,\n value_type,\n })),\n});\n\nconst mapSellingPlanGroups = (\n sellingPlanGroup: StorefrontBundleData['selling_plan_groups'][number]\n): PublicBundleData['selling_plan_groups'][number] => ({\n name: sellingPlanGroup.name,\n options: sellingPlanGroup.options.map(option => ({ name: option.name, values: option.values })),\n selling_plans: sellingPlanGroup.selling_plans.map(mapSellingPlan),\n});\n\nconst mapBasicVariant = (variant: BaseProductVariant) => ({\n id: String(variant.id),\n title: variant.title,\n price: variant.price,\n compare_at_price: variant.compare_at_price,\n options: variant.options,\n available_for_sale: variant.available,\n});\n\nconst formatFeaturedImage = (featuredImage: BaseProduct['featured_image']): string | null => {\n if (featuredImage == null || typeof featuredImage === 'string') return featuredImage;\n\n if ('src' in featuredImage) return featuredImage['src'];\n\n return null;\n};\n\nconst mapBasicProduct = (product: BaseProduct) => {\n return {\n id: String(product.id),\n title: product.title,\n description: product.description,\n available_for_sale: product.available,\n featured_image: formatFeaturedImage(product.featured_image),\n images: product.images,\n requires_selling_plan: product.requires_selling_plan,\n selling_plan_groups: product.selling_plan_groups.map(mapSellingPlanGroups),\n };\n};\n\nconst mapProduct = (product: StorefrontBundleData['collections'][number]['products'][number]) => {\n const productPlansLookup = productSellingPlansGroupLookup(product.selling_plan_groups);\n\n return {\n ...mapBasicProduct(product),\n handle: product.handle,\n tags: product.tags,\n price_range: { min: product.price_min, max: product.price_max },\n compare_at_price_range: { min: product.compare_at_price_min, max: product.compare_at_price_max },\n options: product.options,\n variants: product.variants.map(variant => ({\n ...mapBasicVariant(variant),\n selling_plan_allocations: variant.selling_plan_allocations.map(sellingPlan => ({\n price: sellingPlan.price,\n compare_at_price: sellingPlan.compare_at_price,\n selling_plan: mapSellingPlan(\n productPlansLookup[`${sellingPlan.selling_plan_group_id}-${sellingPlan.selling_plan_id}`]\n ),\n })),\n option1: variant.option1,\n option2: variant.option2,\n option3: variant.option3,\n sku: variant.sku || '',\n requires_shipping: variant.requires_shipping,\n taxable: variant.taxable,\n featured_image: formatFeaturedImage(variant.featured_image),\n public_title: variant.public_title,\n requires_selling_plan: variant.requires_selling_plan,\n })),\n };\n};\n\nconst mapBundleVariantRanges = ({\n items_count,\n ranges,\n}: Pick<StorefrontBundleData['bundle_settings']['variants'][number], 'items_count' | 'ranges'>) => {\n if (ranges.length > 0) {\n return ranges.map(({ quantity_max, quantity_min }) => ({ min: quantity_min, max: quantity_max }));\n }\n\n return [{ min: items_count, max: items_count }];\n};\n\nconst productSellingPlansGroupLookup = (sellingPlanGroups: BaseProduct['selling_plan_groups']) =>\n sellingPlanGroups.reduce<\n Record<string, StorefrontBundleData['selling_plan_groups'][number]['selling_plans'][number]>\n >((acc, current) => {\n current.selling_plans.forEach(sellingPlan => {\n const key = `${current.id}-${sellingPlan.id}`;\n acc[key] = sellingPlan;\n });\n\n return acc;\n }, {});\n\nconst mapFilters = (filters: StorefrontBundleData['filters']): PublicBundleData['filters'] => {\n if (!Array.isArray(filters)) return [];\n return filters;\n};\n\nexport function mapOnlineStoreToPublicBundleData(bundleData: StorefrontBundleData): PublicBundleData {\n const bundleSettings = mapBundleSettings(bundleData.bundle_settings);\n const variantsLookup = bundleData.variants.reduce<Record<string, StorefrontBundleData['variants'][number]>>(\n (acc, variant) => {\n acc[variant.id] = variant;\n return acc;\n },\n {}\n );\n\n return {\n id: String(bundleData.id),\n title: bundleData.title,\n description: bundleData.description || null,\n handle: bundleData.handle,\n options: bundleData.options.map(option => ({\n name: option.name,\n position: option.position,\n values: option.values,\n })),\n default_variant_id: bundleSettings.default_variant_id,\n default_selling_plan_id: bundleSettings.default_selling_plan_id\n ? Number(bundleSettings.default_selling_plan_id)\n : null,\n available_for_sale: bundleData.available,\n requires_selling_plan: bundleData.requires_selling_plan,\n bundle_settings: {\n is_customizable: bundleSettings.is_customizable,\n price_rule: bundleSettings.price_rule as PriceRule,\n customization_window: bundleSettings.customization_window,\n max_quantity_per_variant: bundleSettings.max_quantity_per_variant,\n collapsible_collections: bundleSettings.collapsible_collections,\n show_product_variants: bundleSettings.show_product_variants,\n product_details_modal_enabled: bundleSettings.product_details_modal_enabled,\n show_variants_as_individual_products:\n bundleData.bundle_settings.settings.display_variants_as_separate_products_in_list,\n post_add_to_cart_behavior: bundleSettings.addToCartBehavior,\n },\n variants: bundleData.bundle_settings.variants\n .filter(({ enabled }) => enabled)\n .map((item, index) => {\n const variant = variantsLookup[String(item.external_variant_id)];\n\n return {\n id: String(item.external_variant_id),\n title: variant.title,\n price: variant.price,\n compare_at_price: variant.compare_at_price,\n image: variant.image || '',\n available_for_sale: variant.available,\n options: variant.options,\n requires_selling_plan: variant.requires_selling_plan,\n selling_plan_allocations: variant.selling_plan_allocations.map(sellingPlan => ({\n price: sellingPlan.price,\n compare_at_price: sellingPlan.compare_at_price,\n selling_plan: mapSellingPlan(sellingPlan.selling_plan),\n })),\n ranges: mapBundleVariantRanges(item),\n collections: item.option_sources.map(source => ({\n id: source.option_source_id,\n source_platform: 'shopify',\n min: source.quantity_min || 0,\n max: source.quantity_max,\n position: source.position,\n })),\n default_selections: item.selection_defaults.map(selectionDefault => ({\n quantity: selectionDefault.quantity,\n product: {\n id: String(selectionDefault.product.id),\n handle: selectionDefault.handle,\n title: selectionDefault.product.title,\n description: selectionDefault.product.description,\n images: selectionDefault.product.images,\n },\n variant: {\n id: selectionDefault.external_variant_id,\n title: selectionDefault.variant.title,\n featured_image: formatFeaturedImage(selectionDefault.variant.featured_image),\n sku: selectionDefault.sku || '',\n },\n })),\n position: index,\n };\n }),\n selling_plan_groups: bundleData.selling_plan_groups.map(mapSellingPlanGroups),\n collections: Object.values(bundleData.collections).reduce<PublicBundleData['collections']>((acc, current) => {\n if (!Array.isArray(current.products)) {\n /* If a collection is not published in Online store, it is included \n as _1:{ handle: \"<collection-handle\"} in the collections object.\n We need to skip these collections.\n */\n return acc;\n }\n\n acc[String(current.id)] = {\n id: String(current.id),\n title: current.title,\n handle: current.handle,\n products: current.products.map(mapProduct),\n };\n\n return acc;\n }, {}),\n addons: bundleData.addons.products.length\n ? {\n collection_id: bundleSettings.addons?.collection_id || '',\n collection_handle: bundleSettings.addons?.collection_handle || '',\n products: bundleData.addons.products.map(product => ({\n ...mapBasicProduct(product),\n price_range: { min: product.price, max: product.price },\n compare_at_price_range: { min: product.compare_at_price || 0, max: product.compare_at_price },\n variants: product.variants.map(variant => ({\n ...mapBasicVariant(variant),\n image: variant.image,\n selling_plan_allocations: variant.selling_plan_allocations.map(sellingPlan => ({\n price: sellingPlan.price,\n compare_at_price: sellingPlan.compare_at_price,\n selling_plan: mapSellingPlan(sellingPlan.selling_plan),\n })),\n })),\n })),\n }\n : null,\n cross_sells: bundleData.cross_sells.products.length\n ? {\n collection_id: bundleSettings.cross_sells?.collection_id || '',\n collection_handle: bundleSettings.cross_sells?.collection_handle || '',\n products: bundleData.cross_sells.products.map(mapProduct),\n }\n : null,\n incentives: mapIncentives(bundleData.incentives),\n filters: mapFilters(bundleData.filters),\n templates: bundleData.bundle_settings.layout_settings.templates || null,\n globalStyles: bundleData.bundle_settings.layout_settings.globalStyles || null,\n };\n}\n"],"names":[],"mappings":";;AAGA,MAAM,iBAAA,GAAoB,CAAC,cAAA,KAA4D;AACrF,EAAA,MAAM,MAAA,GAAS,eAAe,eAAA,CAAgB,MAAA;AAC9C,EAAA,MAAM,UAAA,GAAa,eAAe,eAAA,CAAgB,UAAA;AAClD,EAAA,MAAM,sBAAsB,cAAA,CAAe,oBAAA;AAC3C,EAAA,MAAM,gBAAA,GAAmB,cAAA,CAAe,eAAA,EAAiB,gBAAA,IAAoB,cAAA,CAAe,yBAAA;AAC5F,EAAA,MAAM,gBAAA,GAAmB,eAAe,eAAA,CAAgB,gBAAA;AACxD,EAAA,MAAM,iBAAA,GAAoB,eAAe,eAAA,CAAgB,iBAAA;AAEzD,EAAA,OAAO;AAAA,IACL,kBAAA,EAAoB,gBAAA,GAAmB,MAAA,CAAO,gBAAgB,CAAA,GAAI,IAAA;AAAA,IAClE,iBAAiB,cAAA,CAAe,eAAA;AAAA,IAChC,UAAA,EAAY,MAAA,CAAO,cAAA,CAAe,UAAU,EAAE,WAAA,EAAY;AAAA,IAC1D,sBAAsB,mBAAA,GAClB;AAAA,MACE,WAAA,EAAa,mBAAA;AAAA,MACb,gBAAA,EAAkB,eAAe,qCAAA,IAAyC;AAAA,KAC5E,GACA,IAAA;AAAA,IACJ,MAAA,EAAQ,MAAA,CAAO,YAAA,GACX,EAAE,aAAA,EAAe,OAAO,YAAA,EAAc,iBAAA,EAAmB,MAAA,CAAO,gBAAA,EAAiB,GACjF,IAAA;AAAA,IACJ,WAAA,EAAa,UAAA,CAAW,YAAA,GACpB,EAAE,aAAA,EAAe,OAAO,YAAA,EAAc,iBAAA,EAAmB,MAAA,CAAO,gBAAA,EAAiB,GACjF,IAAA;AAAA,IACJ,yBAAyB,gBAAA,IAAoB,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AAA,CAAY,QAAA,CAAS,IAAI,UAAU;AAAA,KAC1D,GACA,IAAA;AAAA,IACJ,UAAA,EAAY,aAAA,CAAc,UAAA,CAAW,UAAU,CAAA;AAAA,IAC/C,OAAA,EAAS,UAAA,CAAW,UAAA,CAAW,OAAO,CAAA;AAAA,IACtC,SAAA,EAAW,UAAA,CAAW,eAAA,CAAgB,eAAA,CAAgB,SAAA,IAAa,IAAA;AAAA,IACnE,YAAA,EAAc,UAAA,CAAW,eAAA,CAAgB,eAAA,CAAgB,YAAA,IAAgB;AAAA,GAC3E;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sources":["../../../src/utils/error.ts"],"sourcesContent":["export class RechargeRequestError implements Error {\n name = 'RechargeRequestError';\n message: string;\n status?: number;\n\n constructor(message: string, status?: number) {\n this.message = message;\n this.status = status;\n }\n}\n"],"names":[],"mappings":";;AAAO,MAAM,oBAAsC,CAAA;AAAA,EAKjD,WAAA,CAAY,SAAiB,MAAiB,EAAA;AAJ9C,IAAO,IAAA,CAAA,IAAA,GAAA,sBAAA,CAAA;AAKL,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AAAA,GAChB;AACF;;;;"}
1
+ {"version":3,"file":"error.js","sources":["../../../src/utils/error.ts"],"sourcesContent":["export class RechargeRequestError implements Error {\n name = 'RechargeRequestError';\n message: string;\n status?: number;\n\n constructor(message: string, status?: number) {\n this.message = message;\n this.status = status;\n }\n}\n"],"names":[],"mappings":";;AAAO,MAAM,oBAAA,CAAsC;AAAA,EAKjD,WAAA,CAAY,SAAiB,MAAA,EAAiB;AAJ9C,IAAA,IAAA,CAAA,IAAA,GAAO,sBAAA;AAKL,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"id.js","sources":["../../../src/utils/id.ts"],"sourcesContent":["const ALPHABET = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';\n\n/**\n * Generates a random URL-safe id.\n *\n * Uses `Math.random`, so it is NOT cryptographically secure. Only used for\n * internal request/telemetry ids where uniqueness matters.\n *\n * Reference: nanoid/non-secure\n */\nexport function nanoid(size = 21): string {\n let id = '';\n for (let i = 0; i < size; i++) {\n id += ALPHABET[(Math.random() * 64) | 0];\n }\n return id;\n}\n"],"names":[],"mappings":";;AAAA,MAAM,QAAW,GAAA,kEAAA,CAAA;AAUD,SAAA,MAAA,CAAO,OAAO,EAAY,EAAA;AACxC,EAAA,IAAI,EAAK,GAAA,EAAA,CAAA;AACT,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,EAAM,CAAK,EAAA,EAAA;AAC7B,IAAA,EAAA,IAAM,QAAU,CAAA,IAAA,CAAK,MAAO,EAAA,GAAI,KAAM,CAAC,CAAA,CAAA;AAAA,GACzC;AACA,EAAO,OAAA,EAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"id.js","sources":["../../../src/utils/id.ts"],"sourcesContent":["const ALPHABET = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';\n\n/**\n * Generates a random URL-safe id.\n *\n * Uses `Math.random`, so it is NOT cryptographically secure. Only used for\n * internal request/telemetry ids where uniqueness matters.\n *\n * Reference: nanoid/non-secure\n */\nexport function nanoid(size = 21): string {\n let id = '';\n for (let i = 0; i < size; i++) {\n id += ALPHABET[(Math.random() * 64) | 0];\n }\n return id;\n}\n"],"names":[],"mappings":";;AAAA,MAAM,QAAA,GAAW,kEAAA;AAUV,SAAS,MAAA,CAAO,OAAO,EAAA,EAAY;AACxC,EAAA,IAAI,EAAA,GAAK,EAAA;AACT,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,IAAA,EAAM,CAAA,EAAA,EAAK;AAC7B,IAAA,EAAA,IAAM,QAAA,CAAU,IAAA,CAAK,MAAA,EAAO,GAAI,KAAM,CAAC,CAAA;AAAA,EACzC;AACA,EAAA,OAAO,EAAA;AACT;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sources":["../../../src/utils/init.ts"],"sourcesContent":["import { resetCDNCache } from '../api/cdn';\nimport { StorefrontOptions, CRUDRequestOptions, GetRequestOptions, InitOptions } from '../types';\nimport { setOptions } from './options';\nimport { request } from './request';\n\n/**\n * @internal\n * @deprecated will be removed in next version\n */\nexport const api = {\n get<T>(url: string, requestOptions?: GetRequestOptions): Promise<T> {\n return request<T>('get', url, requestOptions);\n },\n post<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('post', url, requestOptions);\n },\n put<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('put', url, requestOptions);\n },\n delete<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('delete', url, requestOptions);\n },\n};\n\n/**\n * Uses passed in storeIdentifier, but if it's not passed in will try to infer it.\n * Currently it will only infer if we are in the context of a Shopify store. This will not infer headless or hosted yet.\n */\nfunction getStoreIdentifier(storeIdentifier?: string): string {\n if (storeIdentifier) {\n return storeIdentifier;\n }\n\n // Infer's when on Shopify store (non headless)\n if (window?.Shopify?.shop) {\n return window.Shopify.shop;\n }\n\n // Domain exists on hosted themes. If it doesn't for some reason, get the subdomain and create the identifier\n let domain = window?.domain;\n if (!domain) {\n const subdomain = location?.href\n .match(/(?:http[s]*:\\/\\/)*(.*?)\\.(?=admin\\.rechargeapps\\.com)/i)?.[1]\n .replace(/-sp$/, '');\n if (subdomain) {\n domain = `${subdomain}.myshopify.com`;\n }\n }\n\n // Infer's when on Recharge hosted\n if (domain) {\n return domain;\n }\n\n throw new Error(`No storeIdentifier was passed into init.`);\n}\n\nexport function initRecharge(opt: InitOptions = {}) {\n const hiddenOpts = opt as StorefrontOptions;\n const { storefrontAccessToken } = opt;\n if (storefrontAccessToken && !storefrontAccessToken.startsWith('strfnt')) {\n throw new Error(\n 'Incorrect storefront access token used. See https://storefront.rechargepayments.com/client/docs/getting_started/package_setup/#initialization-- for more information.'\n );\n }\n setOptions({\n storeIdentifier: getStoreIdentifier(opt.storeIdentifier),\n loginRetryFn: opt.loginRetryFn,\n __unstable_twoFactorRetryFn: opt.__unstable_twoFactorRetryFn,\n storefrontAccessToken,\n appName: opt.appName,\n appVersion: opt.appVersion,\n environment: hiddenOpts.environment ? hiddenOpts.environment : 'prod',\n environmentUri: hiddenOpts.environmentUri,\n customerHash: hiddenOpts.customerHash,\n });\n\n // When init is called again, reset the cache to make sure we don't have the old cache around\n resetCDNCache();\n}\n"],"names":["request","setOptions","resetCDNCache"],"mappings":";;;;;;AASO,MAAM,GAAM,GAAA;AAAA,EACjB,GAAA,CAAO,KAAa,cAAgD,EAAA;AAClE,IAAO,OAAAA,eAAA,CAAW,KAAO,EAAA,GAAA,EAAK,cAAc,CAAA,CAAA;AAAA,GAC9C;AAAA,EACA,IAAA,CAAQ,KAAa,cAAiD,EAAA;AACpE,IAAO,OAAAA,eAAA,CAAW,MAAQ,EAAA,GAAA,EAAK,cAAc,CAAA,CAAA;AAAA,GAC/C;AAAA,EACA,GAAA,CAAO,KAAa,cAAiD,EAAA;AACnE,IAAO,OAAAA,eAAA,CAAW,KAAO,EAAA,GAAA,EAAK,cAAc,CAAA,CAAA;AAAA,GAC9C;AAAA,EACA,MAAA,CAAU,KAAa,cAAiD,EAAA;AACtE,IAAO,OAAAA,eAAA,CAAW,QAAU,EAAA,GAAA,EAAK,cAAc,CAAA,CAAA;AAAA,GACjD;AACF,EAAA;AAMA,SAAS,mBAAmB,eAAkC,EAAA;AAC5D,EAAA,IAAI,eAAiB,EAAA;AACnB,IAAO,OAAA,eAAA,CAAA;AAAA,GACT;AAGA,EAAI,IAAA,MAAA,EAAQ,SAAS,IAAM,EAAA;AACzB,IAAA,OAAO,OAAO,OAAQ,CAAA,IAAA,CA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,CAAA;AAGD,EAAcC,iBAAA,EAAA,CAAA;AAChB;;;;;"}
1
+ {"version":3,"file":"init.js","sources":["../../../src/utils/init.ts"],"sourcesContent":["import { resetCDNCache } from '../api/cdn';\nimport { StorefrontOptions, CRUDRequestOptions, GetRequestOptions, InitOptions } from '../types';\nimport { setOptions } from './options';\nimport { request } from './request';\n\n/**\n * @internal\n * @deprecated will be removed in next version\n */\nexport const api = {\n get<T>(url: string, requestOptions?: GetRequestOptions): Promise<T> {\n return request<T>('get', url, requestOptions);\n },\n post<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('post', url, requestOptions);\n },\n put<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('put', url, requestOptions);\n },\n delete<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('delete', url, requestOptions);\n },\n};\n\n/**\n * Uses passed in storeIdentifier, but if it's not passed in will try to infer it.\n * Currently it will only infer if we are in the context of a Shopify store. This will not infer headless or hosted yet.\n */\nfunction getStoreIdentifier(storeIdentifier?: string): string {\n if (storeIdentifier) {\n return storeIdentifier;\n }\n\n // Infer's when on Shopify store (non headless)\n if (window?.Shopify?.shop) {\n return window.Shopify.shop;\n }\n\n // Domain exists on hosted themes. If it doesn't for some reason, get the subdomain and create the identifier\n let domain = window?.domain;\n if (!domain) {\n const subdomain = location?.href\n .match(/(?:http[s]*:\\/\\/)*(.*?)\\.(?=admin\\.rechargeapps\\.com)/i)?.[1]\n .replace(/-sp$/, '');\n if (subdomain) {\n domain = `${subdomain}.myshopify.com`;\n }\n }\n\n // Infer's when on Recharge hosted\n if (domain) {\n return domain;\n }\n\n throw new Error(`No storeIdentifier was passed into init.`);\n}\n\nexport function initRecharge(opt: InitOptions = {}) {\n const hiddenOpts = opt as StorefrontOptions;\n const { storefrontAccessToken } = opt;\n if (storefrontAccessToken && !storefrontAccessToken.startsWith('strfnt')) {\n throw new Error(\n 'Incorrect storefront access token used. See https://storefront.rechargepayments.com/client/docs/getting_started/package_setup/#initialization-- for more information.'\n );\n }\n setOptions({\n storeIdentifier: getStoreIdentifier(opt.storeIdentifier),\n loginRetryFn: opt.loginRetryFn,\n __unstable_twoFactorRetryFn: opt.__unstable_twoFactorRetryFn,\n storefrontAccessToken,\n appName: opt.appName,\n appVersion: opt.appVersion,\n environment: hiddenOpts.environment ? hiddenOpts.environment : 'prod',\n environmentUri: hiddenOpts.environmentUri,\n customerHash: hiddenOpts.customerHash,\n });\n\n // When init is called again, reset the cache to make sure we don't have the old cache around\n resetCDNCache();\n}\n"],"names":["request","setOptions","resetCDNCache"],"mappings":";;;;;;AASO,MAAM,GAAA,GAAM;AAAA,EACjB,GAAA,CAAO,KAAa,cAAA,EAAgD;AAClE,IAAA,OAAOA,eAAA,CAAW,KAAA,EAAO,GAAA,EAAK,cAAc,CAAA;AAAA,EAC9C,CAAA;AAAA,EACA,IAAA,CAAQ,KAAa,cAAA,EAAiD;AACpE,IAAA,OAAOA,eAAA,CAAW,MAAA,EAAQ,GAAA,EAAK,cAAc,CAAA;AAAA,EAC/C,CAAA;AAAA,EACA,GAAA,CAAO,KAAa,cAAA,EAAiD;AACnE,IAAA,OAAOA,eAAA,CAAW,KAAA,EAAO,GAAA,EAAK,cAAc,CAAA;AAAA,EAC9C,CAAA;AAAA,EACA,MAAA,CAAU,KAAa,cAAA,EAAiD;AACtE,IAAA,OAAOA,eAAA,CAAW,QAAA,EAAU,GAAA,EAAK,cAAc,CAAA;AAAA,EACjD;AACF;AAMA,SAAS,mBAAmB,eAAA,EAAkC;AAC5D,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAGA,EAAA,IAAI,MAAA,EAAQ,SAAS,IAAA,EAAM;AACzB,IAAA,OAAO,OAAO,OAAA,CAAQ,IAAA;AAAA,EACxB;AAGA,EAAA,IAAI,SAAS,MAAA,EAAQ,MAAA;AACrB,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAA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7
+ const url = new URL(scriptSrc);
8
+ const isSpreedlyHost = url.hostname === "spreedly.com" || url.hostname.endsWith(".spreedly.com");
9
+ return url.protocol === "https:" && isSpreedlyHost ? url : null;
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
3
14
  async function loadSpreedlyScript(scriptSrc, integrity) {
4
15
  if (typeof window !== "undefined" && window.Spreedly) {
5
16
  return Promise.resolve();
@@ -9,36 +20,39 @@ async function loadSpreedlyScript(scriptSrc, integrity) {
9
20
  reject(new Error("Document is not available. This function must be called in a browser environment."));
10
21
  return;
11
22
  }
12
- const existingScript = document.querySelector(`script[src="${scriptSrc}"]`);
23
+ const url = parseSpreedlyUrl(scriptSrc);
24
+ if (!url) {
25
+ reject(new Error("Payment iFrame script must be served over https from spreedly.com"));
26
+ return;
27
+ }
28
+ const deadline = Date.now() + LOAD_TIMEOUT_MS;
29
+ let pollTimer;
30
+ const waitForSpreedly = () => {
31
+ if (window.Spreedly) {
32
+ resolve();
33
+ } else if (Date.now() >= deadline) {
34
+ reject(new Error("Timed out loading payment iFrame script"));
35
+ } else {
36
+ pollTimer = setTimeout(waitForSpreedly, POLL_INTERVAL_MS);
37
+ }
38
+ };
39
+ const existingScript = Array.from(document.scripts).find(
40
+ (script2) => script2.src === url.href && script2.integrity === integrity
41
+ );
13
42
  if (existingScript) {
14
- const checkLoaded = () => {
15
- if (window.Spreedly) {
16
- resolve();
17
- } else {
18
- setTimeout(checkLoaded, 50);
19
- }
20
- };
21
- checkLoaded();
43
+ waitForSpreedly();
22
44
  return;
23
45
  }
24
46
  const script = document.createElement("script");
25
- script.src = scriptSrc;
47
+ script.src = url.href;
26
48
  script.integrity = integrity;
27
49
  script.crossOrigin = "anonymous";
28
- script.addEventListener("load", () => {
29
- const checkLoaded = () => {
30
- if (window.Spreedly) {
31
- resolve();
32
- } else {
33
- setTimeout(checkLoaded, 50);
34
- }
35
- };
36
- checkLoaded();
37
- });
38
50
  script.addEventListener("error", () => {
51
+ clearTimeout(pollTimer);
39
52
  reject(new Error("Failed to load payment iFrame script"));
40
53
  });
41
54
  document.head.appendChild(script);
55
+ waitForSpreedly();
42
56
  });
43
57
  }
44
58
 
@@ -1 +1 @@
1
- {"version":3,"file":"loadSpreedlyScript.js","sources":["../../../src/utils/loadSpreedlyScript.ts"],"sourcesContent":["export async function loadSpreedlyScript(scriptSrc: string, integrity: string): Promise<void> {\n // Check if already loaded\n if (typeof window !== 'undefined' && window.Spreedly) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n if (typeof document === 'undefined') {\n reject(new Error('Document is not available. This function must be called in a browser environment.'));\n return;\n }\n\n // Check if script is already in the DOM\n const existingScript = document.querySelector(`script[src=\"${scriptSrc}\"]`);\n if (existingScript) {\n // Wait for it to load\n const checkLoaded = () => {\n if (window.Spreedly) {\n resolve();\n } else {\n setTimeout(checkLoaded, 50);\n }\n };\n checkLoaded();\n return;\n }\n\n const script = document.createElement('script');\n script.src = scriptSrc;\n script.integrity = integrity;\n script.crossOrigin = 'anonymous';\n\n script.addEventListener('load', () => {\n // Wait for payment script to be fully initialized\n const checkLoaded = () => {\n if (window.Spreedly) {\n resolve();\n } else {\n setTimeout(checkLoaded, 50);\n }\n };\n checkLoaded();\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load payment iFrame script'));\n });\n\n document.head.appendChild(script);\n });\n}\n"],"names":[],"mappings":";;AAAsB,eAAA,kBAAA,CAAmB,WAAmB,SAAkC,EAAA;AAE5F,EAAA,IAAI,OAAO,MAAA,KAAW,WAAe,IAAA,MAAA,CAAO,QAAU,EAAA;AACpD,IAAA,OAAO,QAAQ,OAAQ,EAAA,CAAA;AAAA,GACzB;AAEA,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAW,KAAA;AACtC,IAAI,IAAA,OAAO,aAAa,WAAa,EAAA;AACnC,MAAO,MAAA,CAAA,IAAI,KAAM,CAAA,mFAAmF,CAAC,CAAA,CAAA;AACrG,MAAA,OAAA;AAAA,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MEOUT_MS = 30_000;\nconst POLL_INTERVAL_MS = 50;\n\nfunction parseSpreedlyUrl(scriptSrc: string): URL | null {\n try {\n const url = new URL(scriptSrc);\n const isSpreedlyHost = url.hostname === 'spreedly.com' || url.hostname.endsWith('.spreedly.com');\n return url.protocol === 'https:' && isSpreedlyHost ? url : null;\n } catch {\n return null;\n }\n}\n\nexport async function loadSpreedlyScript(scriptSrc: string, integrity: string): Promise<void> {\n // Check if already loaded\n if (typeof window !== 'undefined' && window.Spreedly) {\n return Promise.resolve();\n }\n\n return new Promise((resolve, reject) => {\n if (typeof document === 'undefined') {\n reject(new Error('Document is not available. This function must be called in a browser environment.'));\n return;\n }\n\n const url = parseSpreedlyUrl(scriptSrc);\n if (!url) {\n reject(new Error('Payment iFrame script must be served over https from spreedly.com'));\n return;\n }\n\n const deadline = Date.now() + LOAD_TIMEOUT_MS;\n let pollTimer: ReturnType<typeof setTimeout> | undefined;\n const waitForSpreedly = () => {\n if (window.Spreedly) {\n resolve();\n } else if (Date.now() >= deadline) {\n reject(new Error('Timed out loading payment iFrame script'));\n } else {\n pollTimer = setTimeout(waitForSpreedly, POLL_INTERVAL_MS);\n }\n };\n\n // A tag already on the page is only trusted if the browser verified it against the same hash\n const existingScript = Array.from(document.scripts).find(\n script => script.src === url.href && script.integrity === integrity\n );\n if (existingScript) {\n waitForSpreedly();\n return;\n }\n\n const script = document.createElement('script');\n script.src = url.href;\n script.integrity = integrity;\n script.crossOrigin = 'anonymous';\n\n script.addEventListener('error', () => {\n clearTimeout(pollTimer);\n reject(new Error('Failed to load payment iFrame script'));\n });\n\n document.head.appendChild(script);\n // Poll from the start rather than on load so a request that stalls still hits the deadline\n waitForSpreedly();\n });\n}\n"],"names":["script"],"mappings":";;AAAA,MAAM,eAAA,GAAkB,GAAA;AACxB,MAAM,gBAAA,GAAmB,EAAA;AAEzB,SAAS,iBAAiB,SAAA,EAA+B;AACvD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA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;AAAA,IACF,CAAA;AAGA,IAAA,MAAM,cAAA,GAAiB,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,OAAO,CAAA,CAAE,IAAA;AAAA,MAClD,CAAAA,OAAAA,KAAUA,OAAAA,CAAO,QAAQ,GAAA,CAAI,IAAA,IAAQA,QAAO,SAAA,KAAc;AAAA,KAC5D;AACA,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,eAAA,EAAgB;AAChB,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,MAAA,GAAS,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC9C,IAAA,MAAA,CAAO,MAAM,GAAA,CAAI,IAAA;AACjB,IAAA,MAAA,CAAO,SAAA,GAAY,SAAA;AACnB,IAAA,MAAA,CAAO,WAAA,GAAc,WAAA;AAErB,IAAA,MAAA,CAAO,gBAAA,CAAiB,SAAS,MAAM;AACrC,MAAA,YAAA,CAAa,SAAS,CAAA;AACtB,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,sCAAsC,CAAC,CAAA;AAAA,IAC1D,CAAC,CAAA;AAED,IAAA,QAAA,CAAS,IAAA,CAAK,YAAY,MAAM,CAAA;AAEhC,IAAA,eAAA,EAAgB;AAAA,EAClB,CAAC,CAAA;AACH;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sources":["../../../src/utils/options.ts"],"sourcesContent":["import { StorefrontOptions } from '../types';\n\nlet options: StorefrontOptions = {\n storeIdentifier: '',\n environment: 'prod',\n};\n\nexport function setOptions(opts: StorefrontOptions) {\n options = opts;\n}\n\nexport function getOptions() {\n return options;\n}\n"],"names":[],"mappings":";;AAEA,IAAI,OAA6B,GAAA;AAAA,EAC/B,eAAiB,EAAA,EAAA;AAAA,EACjB,WAAa,EAAA,MAAA;AACf,CAAA,CAAA;AAEO,SAAS,WAAW,IAAyB,EAAA;AAClD,EAAU,OAAA,GAAA,IAAA,CAAA;AACZ,CAAA;AAEO,SAAS,UAAa,GAAA;AAC3B,EAAO,OAAA,OAAA,CAAA;AACT;;;;;"}
1
+ {"version":3,"file":"options.js","sources":["../../../src/utils/options.ts"],"sourcesContent":["import { StorefrontOptions } from '../types';\n\nlet options: StorefrontOptions = {\n storeIdentifier: '',\n environment: 'prod',\n};\n\nexport function setOptions(opts: StorefrontOptions) {\n options = opts;\n}\n\nexport function getOptions() {\n return options;\n}\n"],"names":[],"mappings":";;AAEA,IAAI,OAAA,GAA6B;AAAA,EAC/B,eAAA,EAAiB,EAAA;AAAA,EACjB,WAAA,EAAa;AACf,CAAA;AAEO,SAAS,WAAW,IAAA,EAAyB;AAClD,EAAA,OAAA,GAAU,IAAA;AACZ;AAEO,SAAS,UAAA,GAAa;AAC3B,EAAA,OAAO,OAAA;AACT;;;"}
@@ -46,7 +46,7 @@ async function rechargeApiRequest(method, url, { id, query, data, headers } = {}
46
46
  "X-Recharge-Sdk-Fn": session.internalFnCall,
47
47
  ...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
48
48
  ...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {},
49
- "X-Recharge-Sdk-Version": "2.6.1",
49
+ "X-Recharge-Sdk-Version": "2.7.1",
50
50
  "X-Request-Id": session.internalRequestId,
51
51
  ...session.tmp_fn_identifier ? { "X-Recharge-Sdk-Fn-Identifier": session.tmp_fn_identifier } : {},
52
52
  ...headers ? headers : {}