@rechargeapps/storefront-client 0.27.0 → 0.29.0

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Storefront client
1
+ # Recharge JS-SDK
2
2
 
3
- Recharge Storefront client
3
+ Recharge JavaScript SDK
4
4
 
5
5
  ## Install
6
6
 
@@ -24,45 +24,6 @@ npm install @rechargeapps/storefront-client
24
24
  yarn add @rechargeapps/storefront-client
25
25
  ```
26
26
 
27
- ## Init
27
+ ## Docs & examples
28
28
 
29
- ```js
30
- recharge.init({ storeIdentifier: 'storeIdentifier', storefrontAccessToken: 'storefrontAccessToken' });
31
- ```
32
-
33
- ## Testing with Shopify App Proxy
34
-
35
- - Build UMD locally
36
- - run `npx http-server ./packages/storefront/client/dist`
37
- - login to storefront
38
- - run script from `test.html` in the dev tools
39
-
40
- ## Running e2e tests
41
-
42
- You will need to set up 3 environment variables to a store to run locally. You will need to set `SHOPIFY_URL`, `SHOPIFY_USERNAME`, and `SHOPIFY_PASSWORD`. These should be to a store that you have a user associated with. This allows the e2e tests to test authenticated calls.
43
-
44
- You can run the e2e tests 2 ways.
45
-
46
- 1. You can run via `yarn test:e2e --filter @rechargeapps/storefront-client` which will automatically start up the server needed and run through the tests on the command line.
47
- 2. Run `yarn build --filter @rechargeapps/storefront-client` to make sure you are using the latest build. You then need to host those files locally in a window via `yarn workspace @rechargeapps/storefront-client serve`. Then run `yarn workspace @rechargeapps/storefront-client cypress open` in another to get the GUI for cypress and run the tests.
48
-
49
- ## Deploys
50
-
51
- - Not deployed to a stage environment
52
- - Deployed via NPM, Gitlab, and CDN. All are versioned.
53
- - No rollbacks needed, just fix the bug and release a new version.
54
-
55
- ## Naming Types
56
-
57
- Due to possible naming conflicts we recommend name spacing anything that is not part of the Recharge Storefront API to reduce that chance of collisions later on.
58
-
59
- Example:
60
-
61
- CDN: `CDNBundleSettings`
62
- AppProxy: `BundleAppProxy`
63
-
64
- ## V2 ideas
65
-
66
- List of possible ideas around the SDK when moving towards a V2
67
-
68
- - separate packages based on API (api, cdn, appProxy, etc.)
29
+ See our public documentation [here](https://storefront.rechargepayments.com/client/)
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var bundlingData = require('@rechargeapps/bundling-data');
6
5
  var nanoid = require('nanoid');
7
6
  var request = require('../utils/request.js');
8
7
  var options = require('../utils/options.js');
9
8
  var cdn = require('./cdn.js');
9
+ var bundle = require('../utils/bundle.js');
10
10
 
11
11
  const STORE_FRONT_MANAGER_URL = "/bundling-storefront-manager";
12
12
  function getTimestampSecondsFromClient() {
@@ -23,17 +23,17 @@ async function getTimestampSecondsFromServer() {
23
23
  return getTimestampSecondsFromClient();
24
24
  }
25
25
  }
26
- async function getBundleId(bundle) {
26
+ async function getBundleId(bundle$1) {
27
27
  const opts = options.getOptions();
28
- const isValid = await validateBundle(bundle);
28
+ const isValid = await validateBundle(bundle$1);
29
29
  if (isValid !== true) {
30
30
  throw new Error(isValid);
31
31
  }
32
32
  const timestampSeconds = await getTimestampSecondsFromServer();
33
- const bundleData = bundlingData.toLineItemProperty({
34
- variantId: bundle.externalVariantId,
33
+ const bundleData = bundle.toLineItemProperty({
34
+ variantId: bundle$1.externalVariantId,
35
35
  version: timestampSeconds,
36
- items: bundle.selections.map((item) => {
36
+ items: bundle$1.selections.map((item) => {
37
37
  return {
38
38
  collectionId: item.collectionId,
39
39
  productId: item.externalProductId,
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { toLineItemProperty } from '@rechargeapps/bundling-data';\nimport { nanoid } from 'nanoid';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n Session,\n UpdateBundleSelectionRequest,\n} from '../types';\nimport { rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { getCDNBundleSettings } from './cdn';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction getTimestampSecondsFromClient(): number {\n /**\n * Get the current unix epoch in seconds from the client-side.\n */\n return Math.ceil(Date.now() / 1000);\n}\n\nasync function getTimestampSecondsFromServer(): Promise<number> {\n /**\n * Get the unix epoch from the server instead of using it directly from the\n * client. This must reduce even more the number of invalid Bundles.\n */\n try {\n const { timestamp } = await shopifyAppProxyRequest<{ timestamp: number }>('get', `${STORE_FRONT_MANAGER_URL}/t`, {\n headers: { 'X-Recharge-App': 'storefront-client' },\n });\n return timestamp;\n } catch (ex) {\n console.error(`Fetch failed: ${ex}. Using client-side date.`);\n return getTimestampSecondsFromClient();\n }\n}\n\nexport async function getBundleId(bundle: BundleAppProxy): Promise<string> {\n const opts = getOptions();\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const timestampSeconds = await getTimestampSecondsFromServer();\n const bundleData = toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: timestampSeconds,\n items: bundle.selections.map(item => {\n return {\n collectionId: item.collectionId,\n productId: item.externalProductId,\n variantId: item.externalVariantId,\n quantity: item.quantity,\n sku: '',\n };\n }),\n });\n\n try {\n const payload = await shopifyAppProxyRequest<{ id: string; code: number; message: string }>(\n 'post',\n `${STORE_FRONT_MANAGER_URL}/api/v1/bundles`,\n {\n data: {\n bundle: bundleData,\n },\n headers: {\n Origin: `https://${opts.storeIdentifier}`,\n },\n }\n );\n\n if (!payload.id || payload.code !== 200) {\n throw new Error(`1: failed generating rb_id: ${JSON.stringify(payload)}`);\n }\n\n return payload.id;\n } catch (e) {\n // Handle NetworkError exceptions\n throw new Error(`2: failed generating rb_id ${e}`);\n }\n}\n\nexport function getDynamicBundleItems(bundle: BundleAppProxy, shopifyProductHandle: string) {\n const isValid = validateDynamicBundle(bundle);\n if (isValid !== true) {\n throw new Error(`Dynamic Bundle is invalid. ${isValid}`);\n }\n // generate unique id for dynamic bundle\n const bundleId = `${nanoid(9)}:${bundle.externalProductId}`;\n return bundle.selections.map(item => {\n const itemData: DynamicBundleItemAppProxy = {\n id: item.externalVariantId,\n quantity: item.quantity,\n properties: {\n _rc_bundle: bundleId,\n _rc_bundle_variant: bundle.externalVariantId,\n _rc_bundle_parent: shopifyProductHandle,\n _rc_bundle_collection_id: item.collectionId,\n },\n };\n\n if (item.sellingPlan) {\n // this is used by SCI stores\n itemData.selling_plan = item.sellingPlan;\n } else if (item.shippingIntervalFrequency) {\n // this is used by RCS stores\n itemData.properties.shipping_interval_frequency = item.shippingIntervalFrequency;\n itemData.properties.shipping_interval_unit_type = item.shippingIntervalUnitType;\n itemData.id = `${item.discountedVariantId}`;\n }\n\n return itemData;\n });\n}\n\nexport async function validateBundle(bundle: BundleAppProxy): Promise<true | string> {\n try {\n // once we implement this function, we can make it raise an exception\n // we could also have a local store relative to this function so we don't have to pass bundleProduct\n if (!bundle) {\n return 'Bundle is not defined';\n }\n const bundleSettings = await getCDNBundleSettings(bundle.externalProductId);\n if (!bundleSettings) {\n return 'Bundle settings do not exist for the given product';\n }\n return true;\n } catch (e) {\n return `Error fetching bundle settings: ${e}`;\n }\n}\n\nconst intervalUnitGroups = {\n day: ['day', 'days', 'Days'],\n days: ['day', 'days', 'Days'],\n Days: ['day', 'days', 'Days'],\n week: ['week', 'weeks', 'Weeks'],\n weeks: ['week', 'weeks', 'Weeks'],\n Weeks: ['week', 'weeks', 'Weeks'],\n month: ['month', 'months', 'Months'],\n months: ['month', 'months', 'Months'],\n Months: ['month', 'months', 'Months'],\n};\n\n/**\n * Validates a dynamic bundle\n *\n * @param bundle Dynamic Bundle being validated\n * @returns true or error message\n */\nexport function validateDynamicBundle(bundle: BundleAppProxy): true | string {\n if (!bundle) {\n return 'No bundle defined.';\n }\n if (bundle.selections.length === 0) {\n return 'No selections defined.';\n }\n // validation for RCS onetimes\n const { shippingIntervalFrequency, shippingIntervalUnitType } =\n bundle.selections.find(selection => selection.shippingIntervalFrequency || selection.shippingIntervalUnitType) ||\n {};\n if (shippingIntervalFrequency || shippingIntervalUnitType) {\n // if we have shipping intervals then we should have both defined\n if (!shippingIntervalFrequency || !shippingIntervalUnitType) {\n return 'Shipping intervals do not match on selections.';\n } else {\n // if we have shipping intervals then any that are defined should match\n const shippingIntervalUnitGroup = intervalUnitGroups[shippingIntervalUnitType];\n for (let x = 0; x < bundle.selections.length; x++) {\n const { shippingIntervalFrequency: frequency, shippingIntervalUnitType: unitType } = bundle.selections[x];\n if (\n (frequency && frequency !== shippingIntervalFrequency) ||\n (unitType && !shippingIntervalUnitGroup.includes(unitType))\n ) {\n return 'Shipping intervals do not match on selections.';\n }\n }\n }\n }\n return true;\n}\n\nexport async function getBundleSelection(session: Session, id: string | number): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>('get', `/bundle_selections`, { query }, session);\n}\n\nexport async function createBundleSelection(\n session: Session,\n createRequest: CreateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'post',\n `/bundle_selections`,\n {\n data: createRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport async function updateBundleSelection(\n session: Session,\n id: string | number,\n updateRequest: UpdateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n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OAAO,CAAC,CAAC;AAC7E,CAAC;AACM,eAAe,qBAAqB,CAAC,OAAO,EAAE,aAAa,EAAE;AACpE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,kBAAkB,CAAC,EAAE;AACtF,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,eAAe,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE;AACxE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE;AACrF,IAAI,EAAE;AACN,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,SAAS,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE;AACnD,EAAE,OAAOA,0BAAkB,CAAC,QAAQ,EAAE,CAAC,kBAAkB,CAAC,EAAE;AAC5D,IAAI,EAAE;AACN,GAAG,EAAE,OAAO,CAAC,CAAC;AACd;;;;;;;;;;;;"}
1
+ {"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n Session,\n UpdateBundleSelectionRequest,\n} from '../types';\nimport { rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { getCDNBundleSettings } from './cdn';\nimport { toLineItemProperty } from '../utils/bundle';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction getTimestampSecondsFromClient(): number {\n /**\n * Get the current unix epoch in seconds from the client-side.\n */\n return Math.ceil(Date.now() / 1000);\n}\n\nasync function getTimestampSecondsFromServer(): Promise<number> {\n /**\n * Get the unix epoch from the server instead of using it directly from the\n * client. This must reduce even more the number of invalid Bundles.\n */\n try {\n const { timestamp } = await shopifyAppProxyRequest<{ timestamp: number }>('get', `${STORE_FRONT_MANAGER_URL}/t`, {\n headers: { 'X-Recharge-App': 'storefront-client' },\n });\n return timestamp;\n } catch (ex) {\n console.error(`Fetch failed: ${ex}. Using client-side date.`);\n return getTimestampSecondsFromClient();\n }\n}\n\nexport async function getBundleId(bundle: BundleAppProxy): Promise<string> {\n const opts = getOptions();\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const timestampSeconds = await getTimestampSecondsFromServer();\n const bundleData = toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: timestampSeconds,\n items: bundle.selections.map(item => {\n return {\n collectionId: item.collectionId,\n productId: item.externalProductId,\n variantId: item.externalVariantId,\n quantity: item.quantity,\n sku: '',\n };\n }),\n });\n\n try {\n const payload = await shopifyAppProxyRequest<{ id: string; code: number; message: string }>(\n 'post',\n `${STORE_FRONT_MANAGER_URL}/api/v1/bundles`,\n {\n data: {\n bundle: bundleData,\n },\n headers: {\n Origin: `https://${opts.storeIdentifier}`,\n },\n }\n );\n\n if (!payload.id || payload.code !== 200) {\n throw new Error(`1: failed generating rb_id: ${JSON.stringify(payload)}`);\n }\n\n return payload.id;\n } catch (e) {\n // Handle NetworkError exceptions\n throw new Error(`2: failed generating rb_id ${e}`);\n }\n}\n\nexport function getDynamicBundleItems(bundle: BundleAppProxy, shopifyProductHandle: string) {\n const isValid = validateDynamicBundle(bundle);\n if (isValid !== true) {\n throw new Error(`Dynamic Bundle is invalid. ${isValid}`);\n }\n // generate unique id for dynamic bundle\n const bundleId = `${nanoid(9)}:${bundle.externalProductId}`;\n return bundle.selections.map(item => {\n const itemData: DynamicBundleItemAppProxy = {\n id: item.externalVariantId,\n quantity: item.quantity,\n properties: {\n _rc_bundle: bundleId,\n _rc_bundle_variant: bundle.externalVariantId,\n _rc_bundle_parent: shopifyProductHandle,\n _rc_bundle_collection_id: item.collectionId,\n },\n };\n\n if (item.sellingPlan) {\n // this is used by SCI stores\n itemData.selling_plan = item.sellingPlan;\n } else if (item.shippingIntervalFrequency) {\n // this is used by RCS stores\n itemData.properties.shipping_interval_frequency = item.shippingIntervalFrequency;\n itemData.properties.shipping_interval_unit_type = item.shippingIntervalUnitType;\n itemData.id = `${item.discountedVariantId}`;\n }\n\n return itemData;\n });\n}\n\nexport async function validateBundle(bundle: BundleAppProxy): Promise<true | string> {\n try {\n // once we implement this function, we can make it raise an exception\n // we could also have a local store relative to this function so we don't have to pass bundleProduct\n if (!bundle) {\n return 'Bundle is not defined';\n }\n const bundleSettings = await getCDNBundleSettings(bundle.externalProductId);\n if (!bundleSettings) {\n return 'Bundle settings do not exist for the given product';\n }\n return true;\n } catch (e) {\n return `Error fetching bundle settings: ${e}`;\n }\n}\n\nconst intervalUnitGroups = {\n day: ['day', 'days', 'Days'],\n days: ['day', 'days', 'Days'],\n Days: ['day', 'days', 'Days'],\n week: ['week', 'weeks', 'Weeks'],\n weeks: ['week', 'weeks', 'Weeks'],\n Weeks: ['week', 'weeks', 'Weeks'],\n month: ['month', 'months', 'Months'],\n months: ['month', 'months', 'Months'],\n Months: ['month', 'months', 'Months'],\n};\n\n/**\n * Validates a dynamic bundle\n *\n * @param bundle Dynamic Bundle being validated\n * @returns true or error message\n */\nexport function validateDynamicBundle(bundle: BundleAppProxy): true | string {\n if (!bundle) {\n return 'No bundle defined.';\n }\n if (bundle.selections.length === 0) {\n return 'No selections defined.';\n }\n // validation for RCS onetimes\n const { shippingIntervalFrequency, shippingIntervalUnitType } =\n bundle.selections.find(selection => selection.shippingIntervalFrequency || selection.shippingIntervalUnitType) ||\n {};\n if (shippingIntervalFrequency || shippingIntervalUnitType) {\n // if we have shipping intervals then we should have both defined\n if (!shippingIntervalFrequency || !shippingIntervalUnitType) {\n return 'Shipping intervals do not match on selections.';\n } else {\n // if we have shipping intervals then any that are defined should match\n const shippingIntervalUnitGroup = intervalUnitGroups[shippingIntervalUnitType];\n for (let x = 0; x < bundle.selections.length; x++) {\n const { shippingIntervalFrequency: frequency, shippingIntervalUnitType: unitType } = bundle.selections[x];\n if (\n (frequency && frequency !== shippingIntervalFrequency) ||\n (unitType && !shippingIntervalUnitGroup.includes(unitType))\n ) {\n return 'Shipping intervals do not match on selections.';\n }\n }\n }\n }\n return true;\n}\n\nexport async function getBundleSelection(session: Session, id: string | number): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>('get', `/bundle_selections`, { query }, session);\n}\n\nexport async function createBundleSelection(\n session: Session,\n createRequest: CreateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'post',\n `/bundle_selections`,\n {\n data: createRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport async function updateBundleSelection(\n session: Session,\n id: string | number,\n updateRequest: UpdateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n}\n"],"names":["shopifyAppProxyRequest","bundle","getOptions","toLineItemProperty","nanoid","getCDNBundleSettings","rechargeApiRequest"],"mappings":";;;;;;;;;;AAKA,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAC/D,SAAS,6BAA6B,GA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AAkB,CAAC,EAAE;AACtF,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,eAAe,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE;AACxE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE;AACrF,IAAI,EAAE;AACN,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,SAAS,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE;AACnD,EAAE,OAAOA,0BAAkB,CAAC,QAAQ,EAAE,CAAC,kBAAkB,CAAC,EAAE;AAC5D,IAAI,EAAE;AACN,GAAG,EAAE,OAAO,CAAC,CAAC;AACd;;;;;;;;;;;;"}
@@ -2,7 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var partial = require('lodash/partial');
5
6
  var request = require('../utils/request.js');
7
+ var subscription = require('../mappers/subscription.js');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var partial__default = /*#__PURE__*/_interopDefaultLegacy(partial);
6
12
 
7
13
  async function getSubscription(session, id, options) {
8
14
  const { subscription } = await request.rechargeApiRequest("get", `/subscriptions`, {
@@ -14,9 +20,10 @@ async function getSubscription(session, id, options) {
14
20
  function listSubscriptions(session, query) {
15
21
  return request.rechargeApiRequest("get", `/subscriptions`, { query }, session);
16
22
  }
17
- async function createSubscription(session, createRequest) {
23
+ async function createSubscription(session, createRequest, query) {
18
24
  const { subscription } = await request.rechargeApiRequest("post", `/subscriptions`, {
19
- data: createRequest
25
+ data: createRequest,
26
+ query
20
27
  }, session);
21
28
  return subscription;
22
29
  }
@@ -28,9 +35,10 @@ async function updateSubscription(session, id, updateRequest, query) {
28
35
  }, session);
29
36
  return subscription;
30
37
  }
31
- async function updateSubscriptionChargeDate(session, id, date) {
38
+ async function updateSubscriptionChargeDate(session, id, date, query) {
32
39
  const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/set_next_charge_date`, {
33
- data: { date }
40
+ data: { date },
41
+ query
34
42
  }, session);
35
43
  return subscription;
36
44
  }
@@ -40,14 +48,15 @@ async function updateSubscriptionAddress(session, id, address_id) {
40
48
  }, session);
41
49
  return subscription;
42
50
  }
43
- async function cancelSubscription(session, id, cancelRequest) {
51
+ async function cancelSubscription(session, id, cancelRequest, query) {
44
52
  const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/cancel`, {
45
- data: cancelRequest
53
+ data: cancelRequest,
54
+ query
46
55
  }, session);
47
56
  return subscription;
48
57
  }
49
- async function activateSubscription(session, id) {
50
- const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/activate`, {}, session);
58
+ async function activateSubscription(session, id, query) {
59
+ const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/activate`, { query }, session);
51
60
  return subscription;
52
61
  }
53
62
  async function skipSubscriptionCharge(session, id, date) {
@@ -59,14 +68,58 @@ async function skipSubscriptionCharge(session, id, date) {
59
68
  }, session);
60
69
  return charge;
61
70
  }
71
+ async function createSubscriptions(session, createRequestBulk) {
72
+ const length = createRequestBulk.length;
73
+ if (length < 1 || length > 21) {
74
+ throw new Error("Number of subscriptions must be between 1 and 20.");
75
+ }
76
+ const { customerId } = session;
77
+ if (!customerId) {
78
+ throw new Error("No customerId in session.");
79
+ }
80
+ const addressId = createRequestBulk[0].address_id;
81
+ if (!createRequestBulk.every((createRequest) => createRequest.address_id === addressId)) {
82
+ throw new Error("All subscriptions must have the same address_id.");
83
+ }
84
+ const bulkSubscriptionMapperPartial = partial__default["default"](subscription.bulkSubscriptionCreateMapper, customerId);
85
+ const requestData = createRequestBulk.map(bulkSubscriptionMapperPartial);
86
+ const { subscriptions } = await request.rechargeApiRequest("post", `/addresses/${addressId}/subscriptions-bulk`, {
87
+ data: { subscriptions: requestData },
88
+ headers: {
89
+ "X-Recharge-Version": "2021-01"
90
+ }
91
+ }, session);
92
+ return subscriptions.map(subscription.subscriptionMapperOldToNew);
93
+ }
94
+ async function updateSubscriptions(session, addressId, updateRequestBulk, query) {
95
+ const length = updateRequestBulk.length;
96
+ if (length < 1 || length > 21) {
97
+ throw new Error("Number of subscriptions must be between 1 and 20.");
98
+ }
99
+ const { customerId } = session;
100
+ if (!customerId) {
101
+ throw new Error("No customerId in session.");
102
+ }
103
+ const bulkSubscriptionMapperPartial = partial__default["default"](subscription.bulkSubscriptionUpdateMapper, !!(query == null ? void 0 : query.force_update));
104
+ const requestData = updateRequestBulk.map(bulkSubscriptionMapperPartial);
105
+ const { subscriptions } = await request.rechargeApiRequest("put", `/addresses/${addressId}/subscriptions-bulk`, {
106
+ data: { subscriptions: requestData },
107
+ headers: {
108
+ "X-Recharge-Version": "2021-01"
109
+ }
110
+ }, session);
111
+ return subscriptions.map(subscription.subscriptionMapperOldToNew);
112
+ }
62
113
 
63
114
  exports.activateSubscription = activateSubscription;
64
115
  exports.cancelSubscription = cancelSubscription;
65
116
  exports.createSubscription = createSubscription;
117
+ exports.createSubscriptions = createSubscriptions;
66
118
  exports.getSubscription = getSubscription;
67
119
  exports.listSubscriptions = listSubscriptions;
68
120
  exports.skipSubscriptionCharge = skipSubscriptionCharge;
69
121
  exports.updateSubscription = updateSubscription;
70
122
  exports.updateSubscriptionAddress = updateSubscriptionAddress;
71
123
  exports.updateSubscriptionChargeDate = updateSubscriptionChargeDate;
124
+ exports.updateSubscriptions = updateSubscriptions;
72
125
  //# sourceMappingURL=subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import { rechargeApiRequest } from '../utils/request';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } from '../types';\n\nexport async function getSubscription(\n session: Session,\n id: string | number,\n options?: GetSubscriptionOptions\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query }, session);\n}\n\n/**\n * When creating a subscription via API, order_interval_frequency and charge_interval_frequency values do not necessarily\n * need to match the values set in the respective Plans. The product, however, does need to have at least one Plan in order\n * to be added to a subscription.\n */\nexport async function createSubscription(\n session: Session,\n createRequest: CreateSubscriptionRequest\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions`,\n {\n data: createRequest,\n },\n session\n );\n return subscription;\n}\n\n/**\n * Updating parameters like frequency, charge_interval_frequency, order_interval_frequency, order_interval_unit will cause our algorithm to automatically recalculate the next charge date (next_charge_scheduled_at).\n * WARNING: This update will remove skipped and manually changed charges.\n * If you want to change the next charge date (next_charge_scheduled_at) we recommend you to update these parameters first.\n * When updating order_interval_unit OR order_interval_frequency OR charge_interval_frequency all three parameters are required.\n */\nexport async function updateSubscription(\n session: Session,\n id: string | number,\n updateRequest: UpdateSubscriptionRequest,\n query?: UpdateSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n session\n );\n return subscription;\n}\n\n/**\n * If there are two active subscriptions with the same address_id, and you update their\n * next_charge_date parameters to match, their charges will get merged into a new charge\n * with a new id\n */\nexport async function updateSubscriptionChargeDate(\n session: Session,\n id: string | number,\n date: IsoDateString\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n },\n session\n );\n return subscription;\n}\n\nexport async function updateSubscriptionAddress(\n session: Session,\n id: string | number,\n address_id: string | number\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/change_address`,\n {\n data: { address_id },\n },\n session\n );\n return subscription;\n}\n\n/**\n * An involuntary subscription cancelled due to max retries reached will trigger the\n * charge/max_retries_reached webhook. If this leads to the subscription being cancelled,\n * the subscription/cancelled webhook will trigger.\n */\nexport async function cancelSubscription(\n session: Session,\n id: string | number,\n cancelRequest: CancelSubscriptionRequest\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\n },\n session\n );\n return subscription;\n}\n\n/**\n * When activating subscription, following attributes will be set to null: cancelled_at, cancellation_reason\n * and cancellation_reason_comments.\n */\nexport async function activateSubscription(session: Session, id: string | number): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n {},\n session\n );\n return subscription;\n}\n\n/* Skip charge associated with a subscription. */\nexport async function skipSubscriptionCharge(session: Session, id: number | string, date: IsoDateString) {\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${id}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n session\n );\n return charge;\n}\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,C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OAAO,MAAM,CAAC;AAChB;;;;;;;;;;;;"}
1
+ {"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import partial from 'lodash/partial';\nimport { rechargeApiRequest } from '../utils/request';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n BasicSubscriptionParams,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n UpdateSubscriptionsParams,\n} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } from '../types';\nimport {\n bulkSubscriptionCreateMapper,\n bulkSubscriptionUpdateMapper,\n subscriptionMapperOldToNew,\n} from '../mappers/subscription';\n\nexport async function getSubscription(\n session: Session,\n id: string | number,\n options?: GetSubscriptionOptions\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query }, session);\n}\n\n/**\n * When creating a subscription via API, order_interval_frequency and charge_interval_frequency values do not necessarily\n * need to match the values set in the respective Plans. The product, however, does need to have at least one Plan in order\n * to be added to a subscription.\n */\nexport async function createSubscription(\n session: Session,\n createRequest: CreateSubscriptionRequest,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions`,\n {\n data: createRequest,\n query,\n },\n session\n );\n return subscription;\n}\n\n/**\n * Updating parameters like frequency, charge_interval_frequency, order_interval_frequency, order_interval_unit will cause our algorithm to automatically recalculate the next charge date (next_charge_scheduled_at).\n * WARNING: This update will remove skipped and manually changed charges.\n * If you want to change the next charge date (next_charge_scheduled_at) we recommend you to update these parameters first.\n * When updating order_interval_unit OR order_interval_frequency OR charge_interval_frequency all three parameters are required.\n */\nexport async function updateSubscription(\n session: Session,\n id: string | number,\n updateRequest: UpdateSubscriptionRequest,\n query?: UpdateSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n session\n );\n return subscription;\n}\n\n/**\n * If there are two active subscriptions with the same address_id, and you update their\n * next_charge_date parameters to match, their charges will get merged into a new charge\n * with a new id\n */\nexport async function updateSubscriptionChargeDate(\n session: Session,\n id: string | number,\n date: IsoDateString,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n session\n );\n return subscription;\n}\n\nexport async function updateSubscriptionAddress(\n session: Session,\n id: string | number,\n address_id: string | number\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/change_address`,\n {\n data: { address_id },\n },\n session\n );\n return subscription;\n}\n\n/**\n * An involuntary subscription cancelled due to max retries reached will trigger the\n * charge/max_retries_reached webhook. If this leads to the subscription being cancelled,\n * the subscription/cancelled webhook will trigger.\n */\nexport async function cancelSubscription(\n session: Session,\n id: string | number,\n cancelRequest: CancelSubscriptionRequest,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n session\n );\n return subscription;\n}\n\n/**\n * When activating subscription, following attributes will be set to null: cancelled_at, cancellation_reason\n * and cancellation_reason_comments.\n */\nexport async function activateSubscription(\n session: Session,\n id: string | number,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n { query },\n session\n );\n return subscription;\n}\n\n/* Skip charge associated with a subscription. */\nexport async function skipSubscriptionCharge(session: Session, id: number | string, date: IsoDateString) {\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${id}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n session\n );\n return charge;\n}\n\n/**\n * Bulk create new subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n */\nexport async function createSubscriptions(\n session: Session,\n createRequestBulk: CreateSubscriptionRequest[]\n): Promise<Subscription[]> {\n // validate size\n const length = createRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n // validate addressId\n const addressId = createRequestBulk[0].address_id;\n if (!createRequestBulk.every(createRequest => createRequest.address_id === addressId)) {\n throw new Error('All subscriptions must have the same address_id.');\n }\n const bulkSubscriptionMapperPartial = partial(bulkSubscriptionCreateMapper, customerId);\n const requestData = createRequestBulk.map(bulkSubscriptionMapperPartial);\n const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'post',\n `/addresses/${addressId}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n\n/**\n * Bulk create new subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n * Same rules apply as a single subscription update\n */\nexport async function updateSubscriptions(\n session: Session,\n addressId: string | number,\n updateRequestBulk: UpdateSubscriptionsRequest[],\n query?: UpdateSubscriptionsParams\n): Promise<Subscription[]> {\n // validate size\n const length = updateRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n const bulkSubscriptionMapperPartial = partial(bulkSubscriptionUpdateMapper, !!query?.force_update);\n const requestData = updateRequestBulk.map(bulkSubscriptionMapperPartial);\n const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'put',\n `/addresses/${addressId}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n"],"names":["rechargeApiRequest","partial","bulkSubscriptionCreateMapper","subscriptionMapperOldToNew","bulkSubscriptionUpdateMapper"],"mappings":";;;;;;;;;;;;AAOO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;AAClE,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,SAAS,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE;AAClD,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE;AACxE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE;AAC9E,IAAI,IAAI,EAAE,aAAa;AACvB,IAAI,KAAK;AACT,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO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C/H,EAAE,MAAM,WAAW,GAAG,iBAAiB,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3E,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAMJ,0BAAkB,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;AAC1G,IAAI,IAAI,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE;AACxC,IAAI,OAAO,EAAE;AACb,MAAM,oBAAoB,EAAE,SAAS;AACrC,KAAK;AACL,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,aAAa,CAAC,GAAG,CAACG,uCAA0B,CAAC,CAAC;AACvD;;;;;;;;;;;;;;"}
package/dist/cjs/index.js CHANGED
@@ -80,12 +80,14 @@ exports.listPlans = plan.listPlans;
80
80
  exports.activateSubscription = subscription.activateSubscription;
81
81
  exports.cancelSubscription = subscription.cancelSubscription;
82
82
  exports.createSubscription = subscription.createSubscription;
83
+ exports.createSubscriptions = subscription.createSubscriptions;
83
84
  exports.getSubscription = subscription.getSubscription;
84
85
  exports.listSubscriptions = subscription.listSubscriptions;
85
86
  exports.skipSubscriptionCharge = subscription.skipSubscriptionCharge;
86
87
  exports.updateSubscription = subscription.updateSubscription;
87
88
  exports.updateSubscriptionAddress = subscription.updateSubscriptionAddress;
88
89
  exports.updateSubscriptionChargeDate = subscription.updateSubscriptionChargeDate;
90
+ exports.updateSubscriptions = subscription.updateSubscriptions;
89
91
  exports.getCustomer = customer.getCustomer;
90
92
  exports.getCustomerPortalAccess = customer.getCustomerPortalAccess;
91
93
  exports.getDeliverySchedule = customer.getDeliverySchedule;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,141 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var omit = require('lodash/omit');
6
+ var utils = require('./utils.js');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __defProps = Object.defineProperties;
14
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
15
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
18
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __spreadValues = (a, b) => {
20
+ for (var prop in b || (b = {}))
21
+ if (__hasOwnProp.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ if (__getOwnPropSymbols)
24
+ for (var prop of __getOwnPropSymbols(b)) {
25
+ if (__propIsEnum.call(b, prop))
26
+ __defNormalProp(a, prop, b[prop]);
27
+ }
28
+ return a;
29
+ };
30
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
31
+ function bulkSubscriptionCreateMapper(customer_id, createRequest) {
32
+ return __spreadProps(__spreadValues({}, omit__default["default"](createRequest, [
33
+ "address_id",
34
+ "external_variant_id",
35
+ "external_product_id",
36
+ "charge_interval_frequency",
37
+ "order_interval_frequency",
38
+ "price",
39
+ "status"
40
+ ])), {
41
+ customer_id: parseInt(customer_id, 10),
42
+ shopify_variant_id: createRequest.external_variant_id.ecommerce ? parseInt(createRequest.external_variant_id.ecommerce, 10) : void 0,
43
+ charge_interval_frequency: `${createRequest.charge_interval_frequency}`,
44
+ order_interval_frequency: `${createRequest.order_interval_frequency}`,
45
+ price: createRequest.price ? parseFloat(createRequest.price) : void 0,
46
+ status: createRequest.status ? createRequest.status.toUpperCase() : void 0
47
+ });
48
+ }
49
+ function bulkSubscriptionUpdateMapper(force_update, updateRequest) {
50
+ var _a;
51
+ return __spreadProps(__spreadValues({}, omit__default["default"](updateRequest, [
52
+ "external_variant_id",
53
+ "external_product_id",
54
+ "charge_interval_frequency",
55
+ "order_interval_frequency",
56
+ "price",
57
+ "use_external_variant_defaults"
58
+ ])), {
59
+ shopify_variant_id: ((_a = updateRequest.external_variant_id) == null ? void 0 : _a.ecommerce) ? parseInt(updateRequest.external_variant_id.ecommerce, 10) : void 0,
60
+ charge_interval_frequency: updateRequest.charge_interval_frequency ? `${updateRequest.charge_interval_frequency}` : void 0,
61
+ order_interval_frequency: updateRequest.order_interval_frequency ? `${updateRequest.order_interval_frequency}` : void 0,
62
+ price: updateRequest.price ? parseFloat(updateRequest.price) : void 0,
63
+ use_shopify_variant_defaults: updateRequest.use_external_variant_defaults,
64
+ force_update
65
+ });
66
+ }
67
+ function subscriptionMapperOldToNew(old) {
68
+ const {
69
+ id,
70
+ address_id,
71
+ customer_id,
72
+ analytics_data,
73
+ cancellation_reason,
74
+ cancellation_reason_comments,
75
+ cancelled_at,
76
+ charge_interval_frequency,
77
+ created_at,
78
+ expire_after_specific_number_of_charges,
79
+ shopify_product_id,
80
+ shopify_variant_id,
81
+ has_queued_charges,
82
+ is_prepaid,
83
+ is_skippable,
84
+ is_swappable,
85
+ max_retries_reached,
86
+ next_charge_scheduled_at,
87
+ order_day_of_month,
88
+ order_day_of_week,
89
+ order_interval_frequency,
90
+ order_interval_unit,
91
+ presentment_currency,
92
+ price,
93
+ product_title,
94
+ properties,
95
+ quantity,
96
+ sku,
97
+ sku_override,
98
+ status,
99
+ updated_at,
100
+ variant_title
101
+ } = old;
102
+ return {
103
+ id,
104
+ address_id,
105
+ customer_id,
106
+ analytics_data,
107
+ cancellation_reason,
108
+ cancellation_reason_comments,
109
+ cancelled_at,
110
+ charge_interval_frequency: parseInt(charge_interval_frequency, 10),
111
+ created_at,
112
+ expire_after_specific_number_of_charges,
113
+ external_product_id: { ecommerce: `${shopify_product_id}` },
114
+ external_variant_id: { ecommerce: `${shopify_variant_id}` },
115
+ has_queued_charges: utils.convertToBool(has_queued_charges),
116
+ is_prepaid,
117
+ is_skippable,
118
+ is_swappable,
119
+ max_retries_reached: utils.convertToBool(max_retries_reached),
120
+ next_charge_scheduled_at,
121
+ order_day_of_month,
122
+ order_day_of_week,
123
+ order_interval_frequency: parseInt(order_interval_frequency, 10),
124
+ order_interval_unit,
125
+ presentment_currency,
126
+ price: `${price}`,
127
+ product_title: product_title != null ? product_title : "",
128
+ properties,
129
+ quantity,
130
+ sku,
131
+ sku_override,
132
+ status: status.toLowerCase(),
133
+ updated_at,
134
+ variant_title
135
+ };
136
+ }
137
+
138
+ exports.bulkSubscriptionCreateMapper = bulkSubscriptionCreateMapper;
139
+ exports.bulkSubscriptionUpdateMapper = bulkSubscriptionUpdateMapper;
140
+ exports.subscriptionMapperOldToNew = subscriptionMapperOldToNew;
141
+ //# sourceMappingURL=subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.js","sources":["../../../src/mappers/subscription.ts"],"sourcesContent":["import omit from 'lodash/omit';\nimport {\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionStatus,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n} from '../types';\nimport { convertToBool } from './utils';\n\nexport function bulkSubscriptionCreateMapper(customer_id: string, createRequest: CreateSubscriptionRequest) {\n return {\n ...omit(createRequest, [\n 'address_id',\n 'external_variant_id',\n 'external_product_id',\n 'charge_interval_frequency',\n 'order_interval_frequency',\n 'price',\n 'status',\n ]),\n customer_id: parseInt(customer_id, 10),\n shopify_variant_id: createRequest.external_variant_id.ecommerce\n ? parseInt(createRequest.external_variant_id.ecommerce, 10)\n : undefined,\n charge_interval_frequency: `${createRequest.charge_interval_frequency}`,\n order_interval_frequency: `${createRequest.order_interval_frequency}`,\n price: createRequest.price ? parseFloat(createRequest.price) : undefined,\n status: createRequest.status ? createRequest.status.toUpperCase() : undefined,\n };\n}\n\nexport function bulkSubscriptionUpdateMapper(force_update: boolean, updateRequest: UpdateSubscriptionsRequest) {\n return {\n ...omit(updateRequest, [\n 'external_variant_id',\n 'external_product_id',\n 'charge_interval_frequency',\n 'order_interval_frequency',\n 'price',\n 'use_external_variant_defaults',\n ]),\n shopify_variant_id: updateRequest.external_variant_id?.ecommerce\n ? parseInt(updateRequest.external_variant_id.ecommerce, 10)\n : undefined,\n charge_interval_frequency: updateRequest.charge_interval_frequency\n ? `${updateRequest.charge_interval_frequency}`\n : undefined,\n order_interval_frequency: updateRequest.order_interval_frequency\n ? `${updateRequest.order_interval_frequency}`\n : undefined,\n price: updateRequest.price ? parseFloat(updateRequest.price) : undefined,\n use_shopify_variant_defaults: updateRequest.use_external_variant_defaults,\n force_update,\n };\n}\n\nexport function subscriptionMapperOldToNew(old: Subscription_2021_01): Subscription {\n const {\n id,\n address_id,\n customer_id,\n analytics_data,\n cancellation_reason,\n cancellation_reason_comments,\n cancelled_at,\n charge_interval_frequency,\n created_at,\n expire_after_specific_number_of_charges,\n shopify_product_id,\n shopify_variant_id,\n has_queued_charges,\n is_prepaid,\n is_skippable,\n is_swappable,\n max_retries_reached,\n next_charge_scheduled_at,\n order_day_of_month,\n order_day_of_week,\n order_interval_frequency,\n order_interval_unit,\n presentment_currency,\n price,\n product_title,\n properties,\n quantity,\n sku,\n sku_override,\n status,\n updated_at,\n variant_title,\n } = old;\n return {\n id,\n address_id,\n customer_id,\n analytics_data,\n cancellation_reason,\n cancellation_reason_comments,\n cancelled_at,\n charge_interval_frequency: parseInt(charge_interval_frequency, 10),\n created_at,\n expire_after_specific_number_of_charges,\n external_product_id: { ecommerce: `${shopify_product_id}` },\n external_variant_id: { ecommerce: `${shopify_variant_id}` },\n has_queued_charges: convertToBool(has_queued_charges),\n is_prepaid,\n is_skippable,\n is_swappable,\n max_retries_reached: convertToBool(max_retries_reached),\n next_charge_scheduled_at,\n order_day_of_month,\n order_day_of_week,\n order_interval_frequency: parseInt(order_interval_frequency, 10),\n order_interval_unit,\n presentment_currency,\n price: `${price}`,\n product_title: product_title ?? '',\n properties,\n quantity,\n sku,\n sku_override,\n status: status.toLowerCase() as SubscriptionStatus,\n updated_at,\n variant_title,\n };\n}\n"],"names":["omit","convertToBool"],"mappings":";;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,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AAI,mBAAmB;AACvB,IAAI,oBAAoB;AACxB,IAAI,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AACrB,IAAI,aAAa,EAAE,aAAa,IAAI,IAAI,GAAG,aAAa,GAAG,EAAE;AAC7D,IAAI,UAAU;AACd,IAAI,QAAQ;AACZ,IAAI,GAAG;AACP,IAAI,YAAY;AAChB,IAAI,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;AAChC,IAAI,UAAU;AACd,IAAI,aAAa;AACjB,GAAG,CAAC;AACJ;;;;;;"}
@@ -33,6 +33,13 @@ function parseValues(json) {
33
33
  return __spreadProps(__spreadValues({}, memo), { [key]: parseValue(value) });
34
34
  }, {});
35
35
  }
36
+ const convertToBool = (val) => {
37
+ if (typeof val === "string") {
38
+ return val !== "0" && val !== "false";
39
+ }
40
+ return !!val;
41
+ };
36
42
 
43
+ exports.convertToBool = convertToBool;
37
44
  exports.parseValues = parseValues;
38
45
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/mappers/utils.ts"],"sourcesContent":["/** Trys to parse passed in value. If it doesn't work returns the same passed in value */\nfunction parseValue(value: unknown): any {\n try {\n return JSON.parse(value as string);\n } catch {\n return value;\n }\n}\n\n/** Returns a new object that updates \"string\" values into their correct data type. */\nexport function parseValues<T = any>(json: Record<string, unknown>): T {\n return Object.entries(json).reduce((memo, [key, value]) => {\n return { ...memo, [key]: parseValue(value) };\n }, {}) as T;\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAA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,CAAC,IAAI,EAAE;AAClC,EAAE,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC7D,IAAI,OAAO,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjF,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/mappers/utils.ts"],"sourcesContent":["import { BooleanLike } from '../types';\n\n/** Trys to parse passed in value. If it doesn't work returns the same passed in value */\nfunction parseValue(value: unknown): any {\n try {\n return JSON.parse(value as string);\n } catch {\n return value;\n }\n}\n\n/** Returns a new object that updates \"string\" values into their correct data type. */\nexport function parseValues<T = any>(json: Record<string, unknown>): T {\n return Object.entries(json).reduce((memo, [key, value]) => {\n return { ...memo, [key]: parseValue(value) };\n }, {}) as T;\n}\n\nexport const convertToBool = (val: BooleanLike) => {\n if (typeof val === 'string') {\n return val !== '0' && val !== 'false';\n }\n\n return !!val;\n};\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,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AC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjF,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AACW,MAAC,aAAa,GAAG,CAAC,GAAG,KAAK;AACtC,EAAE,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAC/B,IAAI,OAAO,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,OAAO,CAAC;AAC1C,GAAG;AACH,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC;AACf;;;;;"}
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsXdr = require('js-xdr');
6
+
7
+ function toLineItemProperty(bundle) {
8
+ const opts = {
9
+ variantId: xdr.Uint64.fromString(bundle.variantId.toString()),
10
+ version: bundle.version || Math.floor(Date.now() / 1e3),
11
+ items: bundle.items.map((item) => {
12
+ return new xdr.BundleItem({
13
+ collectionId: xdr.Uint64.fromString(item.collectionId.toString()),
14
+ productId: xdr.Uint64.fromString(item.productId.toString()),
15
+ variantId: xdr.Uint64.fromString(item.variantId.toString()),
16
+ sku: item.sku || "",
17
+ quantity: item.quantity,
18
+ ext: new xdr.BundleItemExt(0)
19
+ });
20
+ }),
21
+ ext: new xdr.BundleExt(0)
22
+ };
23
+ const xdrBundle = new xdr.Bundle(opts);
24
+ return xdr.BundleEnvelope.envelopeTypeBundle(xdrBundle).toXDR("base64");
25
+ }
26
+ const xdr = jsXdr.config((xdr2) => {
27
+ xdr2.enum("EnvelopeType", {
28
+ envelopeTypeBundle: 0
29
+ });
30
+ xdr2.typedef("Uint32", xdr2.uint());
31
+ xdr2.typedef("Uint64", xdr2.uhyper());
32
+ xdr2.union("BundleItemExt", {
33
+ switchOn: xdr2.int(),
34
+ switchName: "v",
35
+ switches: [[0, xdr2.void()]],
36
+ arms: {}
37
+ });
38
+ xdr2.struct("BundleItem", [
39
+ ["collectionId", xdr2.lookup("Uint64")],
40
+ ["productId", xdr2.lookup("Uint64")],
41
+ ["variantId", xdr2.lookup("Uint64")],
42
+ ["sku", xdr2.string()],
43
+ ["quantity", xdr2.lookup("Uint32")],
44
+ ["ext", xdr2.lookup("BundleItemExt")]
45
+ ]);
46
+ xdr2.union("BundleExt", {
47
+ switchOn: xdr2.int(),
48
+ switchName: "v",
49
+ switches: [[0, xdr2.void()]],
50
+ arms: {}
51
+ });
52
+ xdr2.struct("Bundle", [
53
+ ["variantId", xdr2.lookup("Uint64")],
54
+ ["items", xdr2.varArray(xdr2.lookup("BundleItem"), 500)],
55
+ ["version", xdr2.lookup("Uint32")],
56
+ ["ext", xdr2.lookup("BundleExt")]
57
+ ]);
58
+ xdr2.union("BundleEnvelope", {
59
+ switchOn: xdr2.lookup("EnvelopeType"),
60
+ switchName: "type",
61
+ switches: [["envelopeTypeBundle", "v1"]],
62
+ arms: {
63
+ v1: xdr2.lookup("Bundle")
64
+ }
65
+ });
66
+ });
67
+
68
+ exports.toLineItemProperty = toLineItemProperty;
69
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sources":["../../../src/utils/bundle.ts"],"sourcesContent":["import { config } from 'js-xdr';\n\nexport function toLineItemProperty(bundle: { variantId: string; version: number; items: any[] }) {\n const opts = {\n variantId: xdr.Uint64.fromString(bundle.variantId.toString()),\n version: bundle.version || Math.floor(Date.now() / 1000),\n items: bundle.items.map(item => {\n return new xdr.BundleItem({\n collectionId: xdr.Uint64.fromString(item.collectionId.toString()),\n productId: xdr.Uint64.fromString(item.productId.toString()),\n variantId: xdr.Uint64.fromString(item.variantId.toString()),\n sku: item.sku || '',\n quantity: item.quantity,\n ext: new xdr.BundleItemExt(0),\n });\n }),\n ext: new xdr.BundleExt(0),\n };\n\n const xdrBundle = new xdr.Bundle(opts);\n return xdr.BundleEnvelope.envelopeTypeBundle(xdrBundle).toXDR('base64');\n}\n\nconst xdr = config(\n (xdr: {\n enum: (arg0: string, arg1: { envelopeTypeBundle: number }) => void;\n typedef: (arg0: string, arg1: any) => void;\n uint: () => any;\n uhyper: () => any;\n union: (\n arg0: string,\n arg1: {\n switchOn: any;\n switchName: string;\n switches: any[][] | string[][];\n // eslint-disable-next-line @typescript-eslint/ban-types\n arms: {} | {} | { v1: any };\n }\n ) => void;\n int: () => any;\n void: () => any;\n struct: (arg0: string, arg1: any[][]) => void;\n lookup: (arg0: string) => any;\n string: () => any;\n varArray: (arg0: any, arg1: number) => any;\n }) => {\n xdr.enum('EnvelopeType', {\n envelopeTypeBundle: 0,\n });\n xdr.typedef('Uint32', xdr.uint());\n xdr.typedef('Uint64', xdr.uhyper());\n xdr.union('BundleItemExt', {\n switchOn: xdr.int(),\n switchName: 'v',\n switches: [[0, xdr.void()]],\n arms: {},\n });\n xdr.struct('BundleItem', [\n ['collectionId', xdr.lookup('Uint64')],\n ['productId', xdr.lookup('Uint64')],\n ['variantId', xdr.lookup('Uint64')],\n ['sku', xdr.string()],\n ['quantity', xdr.lookup('Uint32')],\n ['ext', xdr.lookup('BundleItemExt')],\n ]);\n xdr.union('BundleExt', {\n switchOn: xdr.int(),\n switchName: 'v',\n switches: [[0, xdr.void()]],\n arms: {},\n });\n xdr.struct('Bundle', [\n ['variantId', xdr.lookup('Uint64')],\n ['items', xdr.varArray(xdr.lookup('BundleItem'), 500)],\n ['version', xdr.lookup('Uint32')],\n ['ext', xdr.lookup('BundleExt')],\n ]);\n xdr.union('BundleEnvelope', {\n switchOn: xdr.lookup('EnvelopeType'),\n switchName: 'type',\n switches: [['envelopeTypeBundle', 'v1']],\n arms: {\n v1: xdr.lookup('Bundle'),\n },\n });\n }\n);\n"],"names":["config"],"mappings":";;;;;;AACO,SAAS,kBAAkB,CAAC,MAAM,EAAE;AAC3C,EAAE,MAAM,IAAI,GAAG;AACf,IAAI,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAA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M,CAAC,QAAQ,EAAE;AACxB,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5D,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACtC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACrC,GAAG,CAAC,CAAC;AACL,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;AAC/B,IAAI,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;AACzC,IAAI,UAAU,EAAE,MAAM;AACtB,IAAI,QAAQ,EAAE,CAAC,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;AAC5C,IAAI,IAAI,EAAE;AACV,MAAM,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC/B,KAAK;AACL,GAAG,CAAC,CAAC;AACL,CAAC,CAAC;;;;"}
@@ -1,8 +1,8 @@
1
- import { toLineItemProperty } from '@rechargeapps/bundling-data';
2
1
  import { nanoid } from 'nanoid';
3
2
  import { shopifyAppProxyRequest, rechargeApiRequest } from '../utils/request.js';
4
3
  import { getOptions } from '../utils/options.js';
5
4
  import { getCDNBundleSettings } from './cdn.js';
5
+ import { toLineItemProperty } from '../utils/bundle.js';
6
6
 
7
7
  const STORE_FRONT_MANAGER_URL = "/bundling-storefront-manager";
8
8
  function getTimestampSecondsFromClient() {