@rechargeapps/storefront-client 1.47.0 → 1.49.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/dist/cjs/api/auth.js +1 -1
- package/dist/cjs/api/bundle.js.map +1 -1
- package/dist/cjs/api/bundleData.js +44 -0
- package/dist/cjs/api/bundleData.js.map +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/bundleData.js +224 -0
- package/dist/cjs/utils/bundleData.js.map +1 -0
- package/dist/cjs/utils/request.js +1 -1
- package/dist/esm/api/auth.js +1 -1
- package/dist/esm/api/bundle.js.map +1 -1
- package/dist/esm/api/bundleData.js +42 -0
- package/dist/esm/api/bundleData.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/bundleData.js +222 -0
- package/dist/esm/utils/bundleData.js.map +1 -0
- package/dist/esm/utils/request.js +1 -1
- package/dist/index.d.ts +489 -11
- package/dist/umd/recharge-client.min.js +11 -11
- package/package.json +1 -1
package/dist/cjs/api/auth.js
CHANGED
|
@@ -181,7 +181,7 @@ async function rechargeAdminRequest(method, url, { id, query, data, headers } =
|
|
|
181
181
|
...storefrontAccessToken ? { "X-Recharge-Storefront-Access-Token": storefrontAccessToken } : {},
|
|
182
182
|
...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
|
|
183
183
|
...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {},
|
|
184
|
-
"X-Recharge-Sdk-Version": "1.
|
|
184
|
+
"X-Recharge-Sdk-Version": "1.49.0",
|
|
185
185
|
...headers ? headers : {}
|
|
186
186
|
};
|
|
187
187
|
return request.request(method, `${rechargeBaseUrl}${url}`, { id, query, data, headers: reqHeaders });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n InternalSession,\n Session,\n UpdateBundleSelectionRequest,\n UpdateBundlePurchaseItem,\n BundlePurchaseItem,\n BundlePurchaseItemParams,\n BundleData,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { BundleSelectionValidator, toLineItemProperty } from '../utils/bundle';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction createBundleData(bundle: BundleAppProxy) {\n return toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: 0, // server will replace it with the current time\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\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 bundleData = createBundleData(bundle);\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 async function getBundleSelectionId(session: Session, bundle: BundleAppProxy): Promise<string> {\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const bundleData = createBundleData(bundle);\n\n try {\n const payload = await rechargeApiRequest<{ id: string; code: number; message: string }>(\n 'post',\n `/bundle_selections/bundle_id`,\n {\n data: {\n bundle: bundleData,\n },\n },\n getInternalSession(session, 'getBundleSelectionId')\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 if (bundle.selections.length === 0) {\n return 'No selections defined';\n }\n // Don't make bundle settings call due to merchant issues\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\nexport async function validateBundleSelection(bundle: BundleAppProxy): Promise<{ valid: boolean; error?: string }> {\n try {\n const bundleData = await shopifyAppProxyRequest<BundleData>('get', `/bundle-data/${bundle.externalProductId}`);\n\n const selectionValidator = new BundleSelectionValidator(bundle.selections, bundleData);\n\n return { valid: selectionValidator.isBundleSelectionValid(bundle.externalVariantId) };\n } catch (error) {\n return { valid: false, error: String(error) };\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'getBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>(\n 'get',\n `/bundle_selections`,\n { query },\n getInternalSession(session, 'listBundleSelections')\n );\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 getInternalSession(session, 'createBundleSelection')\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updateBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'deleteBundleSelection')\n );\n}\n\nexport async function updateBundle(\n session: Session,\n purchase_item_id: string | number,\n updateRequest: UpdateBundlePurchaseItem,\n query?: BundlePurchaseItemParams\n): Promise<BundlePurchaseItem> {\n if (purchase_item_id === undefined || purchase_item_id === '') {\n throw new Error('Purchase item ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: BundlePurchaseItem }>(\n 'put',\n '/bundles',\n {\n id: purchase_item_id,\n data: updateRequest,\n query,\n },\n getInternalSession(session, 'updateBundle')\n );\n\n return subscription;\n}\n"],"names":["bundle","toLineItemProperty","getOptions","shopifyAppPro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/bundle.ts"],"sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n Session,\n UpdateBundleSelectionRequest,\n UpdateBundlePurchaseItem,\n BundlePurchaseItem,\n BundlePurchaseItemParams,\n BundleData,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { BundleSelectionValidator, toLineItemProperty } from '../utils/bundle';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction createBundleData(bundle: BundleAppProxy) {\n return toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: 0, // server will replace it with the current time\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\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 bundleData = createBundleData(bundle);\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 async function getBundleSelectionId(session: Session, bundle: BundleAppProxy): Promise<string> {\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const bundleData = createBundleData(bundle);\n\n try {\n const payload = await rechargeApiRequest<{ id: string; code: number; message: string }>(\n 'post',\n `/bundle_selections/bundle_id`,\n {\n data: {\n bundle: bundleData,\n },\n },\n getInternalSession(session, 'getBundleSelectionId')\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 if (bundle.selections.length === 0) {\n return 'No selections defined';\n }\n // Don't make bundle settings call due to merchant issues\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\nexport async function validateBundleSelection(bundle: BundleAppProxy): Promise<{ valid: boolean; error?: string }> {\n try {\n const bundleData = await shopifyAppProxyRequest<BundleData>('get', `/bundle-data/${bundle.externalProductId}`);\n\n const selectionValidator = new BundleSelectionValidator(bundle.selections, bundleData);\n\n return { valid: selectionValidator.isBundleSelectionValid(bundle.externalVariantId) };\n } catch (error) {\n return { valid: false, error: String(error) };\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'getBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>(\n 'get',\n `/bundle_selections`,\n { query },\n getInternalSession(session, 'listBundleSelections')\n );\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 getInternalSession(session, 'createBundleSelection')\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updateBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'deleteBundleSelection')\n );\n}\n\nexport async function updateBundle(\n session: Session,\n purchase_item_id: string | number,\n updateRequest: UpdateBundlePurchaseItem,\n query?: BundlePurchaseItemParams\n): Promise<BundlePurchaseItem> {\n if (purchase_item_id === undefined || purchase_item_id === '') {\n throw new Error('Purchase item ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: BundlePurchaseItem }>(\n 'put',\n '/bundles',\n {\n id: purchase_item_id,\n data: updateRequest,\n query,\n },\n getInternalSession(session, 'updateBundle')\n );\n\n return subscription;\n}\n"],"names":["bundle","toLineItemProperty","getOptions","shopifyAppProxyRequest","rechargeApiRequest","getInternalSession","nanoid","BundleSelectionValidator"],"mappings":";;;;;;;AAmBA,MAAM,uBAA0B,GAAA,8BAAA,CAAA;AAEhC,SAAS,iBAAiBA,QAAwB,EAAA;AAChD,EAAA,OAAOC,yBAAmB,CAAA;AAAA,IACxB,WAAWD,QAAO,CAAA,iBAAA;AAAA,IAClB,OAAS,EAAA,CAAA;AAAA;AAAA,IACT,KAAO,EAAAA,QAAA,CAAO,UAAW,CAAA,GAAA,CAAI,CAAQ,IAAA,KAAA;AACnC,MAAO,OAAA;AAAA,QACL,cAAc,IAAK,CAAA,YAAA;AAAA,QACnB,WAAW,IAAK,CAAA,iBAAA;AAAA,QAChB,WAAW,IAAK,CAAA,iBAAA;AAAA,QAChB,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,GAAK,EAAA,EAAA;AAAA,OACP,CAAA;AAAA,KACD,CAAA;AAAA,GACF,CAAA,CAAA;AACH,CAAA;AAEA,eAAsB,YAAY,MAAyC,EAAA;AACzE,EAAA,MAAM,OAAOE,kBAAW,EAAA,CAAA;AACxB,EAAM,MAAA,OAAA,GAAU,MAAM,cAAA,CAAe,MAAM,CAAA,CAAA;AAC3C,EAAA,IAAI,YAAY,IAAM,EAAA;AACpB,IAAM,MAAA,IAAI,MAAM,OAAO,CAAA,CAAA;AAAA,GACzB;AACA,EAAM,MAAA,UAAA,GAAa,iBAAiB,MAAM,CAAA,CAAA;AAE1C,EAAI,IAAA;AACF,IAAA,MAAM,UAAU,MAAMC,8BAAA;AAAA,MACpB,MAAA;AAAA,MACA,GAAG,uBAAuB,CAAA,eAAA,CAAA;AAAA,MAC1B;AAAA,QACE,IAAM,EAAA;AAAA,UACJ,MAAQ,EAAA,UAAA;AAAA,SACV;AAAA,QACA,OAAS,EAAA;AAAA,UACP,MAAA,EAAQ,CAAW,QAAA,EAAA,IAAA,CAAK,eAAe,CAAA,CAAA;AAAA,SACzC;AAA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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var options = require('../utils/options.js');
|
|
4
|
+
var api = require('../constants/api.js');
|
|
5
|
+
var request = require('../utils/request.js');
|
|
6
|
+
var bundleData = require('../utils/bundleData.js');
|
|
7
|
+
|
|
8
|
+
async function loadBundleData(id, options) {
|
|
9
|
+
if (options?.source === "shopify_storefront") {
|
|
10
|
+
return loadFromShopifyStorefrontApi();
|
|
11
|
+
}
|
|
12
|
+
return loadFromOnlineStore(id, options?.country_code);
|
|
13
|
+
}
|
|
14
|
+
async function loadFromOnlineStore(id, country_code) {
|
|
15
|
+
if (!country_code) {
|
|
16
|
+
const data = await request.shopifyAppProxyRequest("get", `/bundle-data/${id}`);
|
|
17
|
+
return bundleData.mapOnlineStoreToPublicBundleData(data);
|
|
18
|
+
}
|
|
19
|
+
const payload = new FormData();
|
|
20
|
+
payload.append("form_type", "localization");
|
|
21
|
+
payload.append("_method", "put");
|
|
22
|
+
payload.append("return_to", `${api.SHOPIFY_APP_PROXY_URL}/bundle-data/${id}`);
|
|
23
|
+
payload.append("country_code", country_code);
|
|
24
|
+
try {
|
|
25
|
+
const data = await request.request("post", "/localization", {
|
|
26
|
+
headers: { "Content-Type": "multipart/form-data" },
|
|
27
|
+
data: payload
|
|
28
|
+
});
|
|
29
|
+
return bundleData.mapOnlineStoreToPublicBundleData(data);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
const data = await request.shopifyAppProxyRequest("get", `/bundle-data/${id}`);
|
|
32
|
+
return bundleData.mapOnlineStoreToPublicBundleData(data);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function loadFromShopifyStorefrontApi(id, options$1) {
|
|
36
|
+
const opts = options.getOptions();
|
|
37
|
+
if (!opts.storeIdentifier) {
|
|
38
|
+
throw new Error("Store identifier is required for Shopify Storefront API requests");
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.loadBundleData = loadBundleData;
|
|
44
|
+
//# sourceMappingURL=bundleData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleData.js","sources":["../../../src/api/bundleData.ts"],"sourcesContent":["import { PublicBundleData } from '../types/bundleData';\nimport { getOptions } from '../utils/options';\nimport { SHOPIFY_APP_PROXY_URL } from '../constants/api';\nimport { BundleData as StorefrontBundleData } from '../types/bundle';\nimport { request, shopifyAppProxyRequest } from '../utils/request';\nimport { mapOnlineStoreToPublicBundleData } from '../utils/bundleData';\n\ntype BaseOptions = {\n country_code?: string;\n};\n\n/**\n * Options for loading bundle data from online store endpoint (bundle-data)\n */\ntype OnlineStoreOptions = {\n source: 'online_store';\n} & BaseOptions;\n\n/**\n * Options for loading bundle data from Shopify Storefront API\n */\ntype ShopifyStorefrontOptions = {\n source: 'shopify_storefront';\n shopify_storefront_access_token: string;\n} & BaseOptions;\n\ntype Options = OnlineStoreOptions | ShopifyStorefrontOptions;\n\n/**\n * Load bundle data from the specified source\n *\n * @param id - The external product ID (Shopify product ID)\n * @param options - Configuration for data source and parameters\n * @param options.source - The source of the data (online_store or shopify_storefront)\n * @param options.country_code - The country code for the online store\n * @param options.storefront_access_token - The storefront access token for the Shopify Storefront API\n * @returns Promise resolving to bundle data result with success/error handling\n *\n * @example\n * ```typescript\n * // Load from online store\n * const result = await loadBundleData({\n * source: 'online_store',\n * external_product_id: '123456789',\n * country_code: 'US'\n * });\n *\n * if (result.success) {\n * console.log('Bundle data:', result.data);\n * } else {\n * console.error('Error:', result.error.message);\n * }\n *\n * // Load from Shopify Storefront API\n * const result2 = await loadBundleData({\n * source: 'shopify_storefront',\n * external_product_id: '123456789',\n * country_code: 'US',\n * shopify_storefront_access_token: 'your-token-here'\n * });\n * ```\n */\nexport async function loadBundleData(id: string, options?: Options): Promise<PublicBundleData> {\n if (options?.source === 'shopify_storefront') {\n return loadFromShopifyStorefrontApi(id, options);\n }\n\n return loadFromOnlineStore(id, options?.country_code);\n}\n\n/**\n * Load bundle data from the online store endpoint\n */\nasync function loadFromOnlineStore(id: string, country_code?: string): Promise<PublicBundleData> {\n if (!country_code) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${id}`);\n return mapOnlineStoreToPublicBundleData(data);\n }\n\n const payload = new FormData();\n payload.append('form_type', 'localization');\n payload.append('_method', 'put');\n payload.append('return_to', `${SHOPIFY_APP_PROXY_URL}/bundle-data/${id}`);\n payload.append('country_code', country_code);\n\n try {\n const data = await request<StorefrontBundleData>('post', '/localization', {\n headers: { 'Content-Type': 'multipart/form-data' },\n data: payload,\n });\n return mapOnlineStoreToPublicBundleData(data);\n } catch (error) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${id}`);\n return mapOnlineStoreToPublicBundleData(data);\n }\n}\n\n/**\n * Load bundle data from Shopify Storefront API\n */\nasync function loadFromShopifyStorefrontApi(id: string, options: ShopifyStorefrontOptions): Promise<PublicBundleData> {\n const opts = getOptions();\n\n if (!opts.storeIdentifier) {\n throw new Error('Store identifier is required for Shopify Storefront API requests');\n }\n\n // Request data from Shopify Storefront API\n return {} as PublicBundleData;\n}\n"],"names":["shopifyAppProxyRequest","mapOnlineStoreToPublicBundleData","SHOPIFY_APP_PROXY_URL","request","options","getOptions"],"mappings":";;;;;;;AA8DsB,eAAA,cAAA,CAAe,IAAY,OAA8C,EAAA;AAC7F,EAAI,IAAA,OAAA,EAAS,WAAW,oBAAsB,EAAA;AAC5C,IAAO,OAAA,4BAAA,CAAwC,CAAA,CAAA;AAAA,GACjD;AAEA,EAAO,OAAA,mBAAA,CAAoB,EAAI,EAAA,OAAA,EAAS,YAAY,CAAA,CAAA;AACtD,CAAA;AAKA,eAAe,mBAAA,CAAoB,IAAY,YAAkD,EAAA;AAC/F,EAAA,IAAI,CAAC,YAAc,EAAA;AACjB,IAAA,MAAM,OAAO,MAAMA,8BAAA,CAA6C,KAAO,EAAA,CAAA,aAAA,EAAgB,EAAE,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/auth.js');
|
|
5
5
|
var bundle = require('./api/bundle.js');
|
|
6
|
+
var bundleData = require('./api/bundleData.js');
|
|
6
7
|
var cdn = require('./api/cdn.js');
|
|
7
8
|
var charge = require('./api/charge.js');
|
|
8
9
|
var collection = require('./api/collection.js');
|
|
@@ -53,6 +54,7 @@ exports.updateBundleSelection = bundle.updateBundleSelection;
|
|
|
53
54
|
exports.validateBundle = bundle.validateBundle;
|
|
54
55
|
exports.validateBundleSelection = bundle.validateBundleSelection;
|
|
55
56
|
exports.validateDynamicBundle = bundle.validateDynamicBundle;
|
|
57
|
+
exports.loadBundleData = bundleData.loadBundleData;
|
|
56
58
|
exports.getCDNBundleSettings = cdn.getCDNBundleSettings;
|
|
57
59
|
exports.getCDNProduct = cdn.getCDNProduct;
|
|
58
60
|
exports.getCDNProductAndSettings = cdn.getCDNProductAndSettings;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const mapBundleSettings = (bundleSettings) => {
|
|
4
|
+
const addons = bundleSettings.layout_settings.addons;
|
|
5
|
+
const crossSells = bundleSettings.layout_settings.crossSells;
|
|
6
|
+
const customizationWindow = bundleSettings.customization_window;
|
|
7
|
+
const defaultVariantId = bundleSettings.default_bundle_variant_id;
|
|
8
|
+
return {
|
|
9
|
+
default_variant_id: defaultVariantId ? String(defaultVariantId) : null,
|
|
10
|
+
is_customizable: bundleSettings.is_customizable,
|
|
11
|
+
price_rule: String(bundleSettings.price_rule).toUpperCase(),
|
|
12
|
+
customization_window: customizationWindow ? {
|
|
13
|
+
active_days: customizationWindow,
|
|
14
|
+
disabled_message: bundleSettings.customization_window_disabled_message || ""
|
|
15
|
+
} : null,
|
|
16
|
+
addons: addons.collectionId ? { collection_id: addons.collectionId, collection_handle: addons.collectionHandle } : null,
|
|
17
|
+
cross_sells: crossSells.collectionId ? { collection_id: addons.collectionId, collection_handle: addons.collectionHandle } : null
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const mapIncentives = (incentives) => {
|
|
21
|
+
if (incentives.tiered_discounts.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
tiered_discounts: incentives.tiered_discounts.map((tieredDiscount) => ({
|
|
25
|
+
eligible_charge_types: tieredDiscount.eligible_charge_types,
|
|
26
|
+
eligible_line_item_types: tieredDiscount.eligible_line_item_types,
|
|
27
|
+
external_product_id: tieredDiscount.external_product_id,
|
|
28
|
+
name: tieredDiscount.name,
|
|
29
|
+
status: tieredDiscount.status,
|
|
30
|
+
tiers: tieredDiscount.tiers.map((tiered) => ({
|
|
31
|
+
discount_type: tiered.discount_type,
|
|
32
|
+
discount_value: tiered.discount_value,
|
|
33
|
+
condition_quantity_gte: tiered.condition_quantity_gte
|
|
34
|
+
}))
|
|
35
|
+
}))
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const mapSellingPlan = (sellingPlan) => ({
|
|
39
|
+
id: sellingPlan.id,
|
|
40
|
+
name: sellingPlan.name,
|
|
41
|
+
options: sellingPlan.options.map((option) => ({ name: option.name, values: option.values })),
|
|
42
|
+
recurring_deliveries: sellingPlan.recurring_deliveries,
|
|
43
|
+
price_adjustments: sellingPlan.price_adjustments.map(({ value, value_type }) => ({
|
|
44
|
+
value,
|
|
45
|
+
value_type
|
|
46
|
+
}))
|
|
47
|
+
});
|
|
48
|
+
const mapSellingPlanGroups = (sellingPlanGroup) => ({
|
|
49
|
+
name: sellingPlanGroup.name,
|
|
50
|
+
options: sellingPlanGroup.options.map((option) => ({ name: option.name, values: option.values })),
|
|
51
|
+
selling_plans: sellingPlanGroup.selling_plans.map(mapSellingPlan)
|
|
52
|
+
});
|
|
53
|
+
const mapBasicVariant = (variant) => ({
|
|
54
|
+
id: String(variant.id),
|
|
55
|
+
title: variant.title,
|
|
56
|
+
price: variant.price,
|
|
57
|
+
compare_at_price: variant.compare_at_price,
|
|
58
|
+
options: variant.options,
|
|
59
|
+
available_for_sale: variant.available
|
|
60
|
+
});
|
|
61
|
+
const mapBasicProduct = (product) => ({
|
|
62
|
+
id: String(product.id),
|
|
63
|
+
title: product.title,
|
|
64
|
+
description: product.description,
|
|
65
|
+
available_for_sale: product.available,
|
|
66
|
+
featured_image: product.featured_image,
|
|
67
|
+
images: product.images,
|
|
68
|
+
requires_selling_plan: product.requires_selling_plan,
|
|
69
|
+
selling_plan_groups: product.selling_plan_groups.map(mapSellingPlanGroups)
|
|
70
|
+
});
|
|
71
|
+
const mapProduct = (product) => {
|
|
72
|
+
const productPlansLookup = productSellingPlansGroupLookup(product.selling_plan_groups);
|
|
73
|
+
return {
|
|
74
|
+
...mapBasicProduct(product),
|
|
75
|
+
handle: product.handle,
|
|
76
|
+
tags: product.tags,
|
|
77
|
+
price_range: { min: product.price_min, max: product.price_max },
|
|
78
|
+
compare_at_price_range: { min: product.compare_at_price_min, max: product.compare_at_price_max },
|
|
79
|
+
options: product.options,
|
|
80
|
+
variants: product.variants.map((variant) => ({
|
|
81
|
+
...mapBasicVariant(variant),
|
|
82
|
+
selling_plan_allocations: variant.selling_plan_allocations.map((sellingPlan) => ({
|
|
83
|
+
price: sellingPlan.price,
|
|
84
|
+
compare_at_price: sellingPlan.compare_at_price,
|
|
85
|
+
selling_plan: mapSellingPlan(
|
|
86
|
+
productPlansLookup[`${sellingPlan.selling_plan_group_id}-${sellingPlan.selling_plan_id}`]
|
|
87
|
+
)
|
|
88
|
+
})),
|
|
89
|
+
option1: variant.option1,
|
|
90
|
+
option2: variant.option2,
|
|
91
|
+
option3: variant.option3,
|
|
92
|
+
sku: variant.sku,
|
|
93
|
+
requires_shipping: variant.requires_shipping,
|
|
94
|
+
taxable: variant.taxable,
|
|
95
|
+
featured_image: variant.featured_image,
|
|
96
|
+
public_title: variant.public_title,
|
|
97
|
+
requires_selling_plan: variant.requires_selling_plan
|
|
98
|
+
}))
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const mapBundleVariantRanges = ({
|
|
102
|
+
items_count,
|
|
103
|
+
ranges
|
|
104
|
+
}) => {
|
|
105
|
+
if (ranges.length > 0) {
|
|
106
|
+
return ranges.map(({ quantity_max, quantity_min }) => ({ min: quantity_min, max: quantity_max }));
|
|
107
|
+
}
|
|
108
|
+
return [{ min: items_count, max: items_count }];
|
|
109
|
+
};
|
|
110
|
+
const productSellingPlansGroupLookup = (sellingPlanGroups) => sellingPlanGroups.reduce((acc, current) => {
|
|
111
|
+
current.selling_plans.forEach((sellingPlan) => {
|
|
112
|
+
const key = `${current.id}-${sellingPlan.id}`;
|
|
113
|
+
acc[key] = sellingPlan;
|
|
114
|
+
});
|
|
115
|
+
return acc;
|
|
116
|
+
}, {});
|
|
117
|
+
function mapOnlineStoreToPublicBundleData(bundleData) {
|
|
118
|
+
const bundleSettings = mapBundleSettings(bundleData.bundle_settings);
|
|
119
|
+
const variantsLookup = bundleData.variants.reduce(
|
|
120
|
+
(acc, variant) => {
|
|
121
|
+
acc[variant.id] = variant;
|
|
122
|
+
return acc;
|
|
123
|
+
},
|
|
124
|
+
{}
|
|
125
|
+
);
|
|
126
|
+
return {
|
|
127
|
+
id: String(bundleData.id),
|
|
128
|
+
title: bundleData.title,
|
|
129
|
+
handle: bundleData.handle,
|
|
130
|
+
options: bundleData.options.map((option) => ({
|
|
131
|
+
name: option.name,
|
|
132
|
+
position: option.position,
|
|
133
|
+
values: option.values
|
|
134
|
+
})),
|
|
135
|
+
default_variant_id: bundleSettings.default_variant_id,
|
|
136
|
+
available_for_sale: bundleData.available,
|
|
137
|
+
requires_selling_plan: bundleData.requires_selling_plan,
|
|
138
|
+
bundle_settings: {
|
|
139
|
+
is_customizable: bundleSettings.is_customizable,
|
|
140
|
+
price_rule: bundleSettings.price_rule,
|
|
141
|
+
customization_window: bundleSettings.customization_window,
|
|
142
|
+
max_quantity_per_variant: null
|
|
143
|
+
},
|
|
144
|
+
variants: bundleData.bundle_settings.variants.filter(({ enabled }) => enabled).map((item, index) => {
|
|
145
|
+
const variant = variantsLookup[String(item.external_variant_id)];
|
|
146
|
+
return {
|
|
147
|
+
id: String(item.external_variant_id),
|
|
148
|
+
title: variant.title,
|
|
149
|
+
price: variant.price,
|
|
150
|
+
compare_at_price: variant.compare_at_price,
|
|
151
|
+
image: variant.image || "",
|
|
152
|
+
available_for_sale: variant.available,
|
|
153
|
+
options: variant.options,
|
|
154
|
+
requires_selling_plan: variant.requires_selling_plan,
|
|
155
|
+
selling_plan_allocations: variant.selling_plan_allocations.map((sellingPlan) => ({
|
|
156
|
+
price: sellingPlan.price,
|
|
157
|
+
compare_at_price: sellingPlan.compare_at_price,
|
|
158
|
+
selling_plan: mapSellingPlan(sellingPlan.selling_plan)
|
|
159
|
+
})),
|
|
160
|
+
ranges: mapBundleVariantRanges(item),
|
|
161
|
+
collections: item.option_sources.map((source) => ({
|
|
162
|
+
id: source.option_source_id,
|
|
163
|
+
source_platform: "shopify",
|
|
164
|
+
min: source.quantity_min || 0,
|
|
165
|
+
max: source.quantity_max
|
|
166
|
+
})),
|
|
167
|
+
default_selections: item.selection_defaults.map((selectionDefault) => ({
|
|
168
|
+
quantity: selectionDefault.quantity,
|
|
169
|
+
product: {
|
|
170
|
+
id: String(selectionDefault.product.id),
|
|
171
|
+
handle: selectionDefault.handle,
|
|
172
|
+
title: selectionDefault.product.title,
|
|
173
|
+
description: selectionDefault.product.description,
|
|
174
|
+
images: selectionDefault.product.images
|
|
175
|
+
},
|
|
176
|
+
variant: {
|
|
177
|
+
id: selectionDefault.external_variant_id,
|
|
178
|
+
title: selectionDefault.variant.title,
|
|
179
|
+
featured_image: selectionDefault.variant.featured_image,
|
|
180
|
+
sku: selectionDefault.sku
|
|
181
|
+
}
|
|
182
|
+
})),
|
|
183
|
+
position: index
|
|
184
|
+
};
|
|
185
|
+
}),
|
|
186
|
+
selling_plan_groups: bundleData.selling_plan_groups.map(mapSellingPlanGroups),
|
|
187
|
+
collections: Object.values(bundleData.collections).reduce((acc, current) => {
|
|
188
|
+
acc[String(current.id)] = {
|
|
189
|
+
id: String(current.id),
|
|
190
|
+
title: current.title,
|
|
191
|
+
handle: current.handle,
|
|
192
|
+
products: current.products.map(mapProduct)
|
|
193
|
+
};
|
|
194
|
+
return acc;
|
|
195
|
+
}, {}),
|
|
196
|
+
addons: bundleData.addons.products.length ? {
|
|
197
|
+
collection_id: bundleSettings.addons?.collection_id || "",
|
|
198
|
+
collection_handle: bundleSettings.addons?.collection_handle || "",
|
|
199
|
+
products: bundleData.addons.products.map((product) => ({
|
|
200
|
+
...mapBasicProduct(product),
|
|
201
|
+
price_range: { min: product.price, max: product.price },
|
|
202
|
+
compare_at_price_range: { min: product.compare_at_price || 0, max: product.compare_at_price },
|
|
203
|
+
variants: product.variants.map((variant) => ({
|
|
204
|
+
...mapBasicVariant(variant),
|
|
205
|
+
image: variant.image,
|
|
206
|
+
selling_plan_allocations: variant.selling_plan_allocations.map((sellingPlan) => ({
|
|
207
|
+
price: sellingPlan.price,
|
|
208
|
+
compare_at_price: sellingPlan.compare_at_price,
|
|
209
|
+
selling_plan: mapSellingPlan(sellingPlan.selling_plan)
|
|
210
|
+
}))
|
|
211
|
+
}))
|
|
212
|
+
}))
|
|
213
|
+
} : null,
|
|
214
|
+
cross_sells: bundleData.cross_sells.products.length ? {
|
|
215
|
+
collection_id: bundleSettings.cross_sells?.collection_id || "",
|
|
216
|
+
collection_handle: bundleSettings.cross_sells?.collection_handle || "",
|
|
217
|
+
products: bundleData.cross_sells.products.map(mapProduct)
|
|
218
|
+
} : null,
|
|
219
|
+
incentives: mapIncentives(bundleData.incentives)
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
exports.mapOnlineStoreToPublicBundleData = mapOnlineStoreToPublicBundleData;
|
|
224
|
+
//# sourceMappingURL=bundleData.js.map
|
|
@@ -0,0 +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.default_bundle_variant_id;\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 };\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.map(tieredDiscount => ({\n eligible_charge_types: tieredDiscount.eligible_charge_types,\n eligible_line_item_types: tieredDiscount.eligible_line_item_types,\n external_product_id: tieredDiscount.external_product_id,\n name: tieredDiscount.name,\n status: tieredDiscount.status,\n tiers: tieredDiscount.tiers.map(tiered => ({\n discount_type: tiered.discount_type,\n discount_value: tiered.discount_value,\n condition_quantity_gte: tiered.condition_quantity_gte,\n })),\n })),\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, values: option.values })),\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 mapBasicProduct = (product: BaseProduct) => ({\n id: String(product.id),\n title: product.title,\n description: product.description,\n available_for_sale: product.available,\n featured_image: 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\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: 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\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 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 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: null,\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 })),\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: 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 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 };\n}\n"],"names":[],"mappings":";;AAGA,MAAM,iBAAA,GAAoB,CAAC,cAA4D,KAAA;AACrF,EAAM,MAAA,MAAA,GAAS,eAAe,eAAgB,CAAA,MAAA,CAAA;AAC9C,EAAM,MAAA,UAAA,GAAa,eAAe,eAAgB,CAAA,UAAA,CAAA;AAClD,EAAA,MAAM,sBAAsB,cAAe,CAAA,oBAAA,CAAA;AAC3C,EAAA,MAAM,mBAAmB,cAAe,CAAA,yBAAA,CAAA;AAExC,EAAO,OAAA;AAAA,IACL,kBAAoB,EAAA,gBAAA,GAAmB,MAAO,CAAA,gBAAgB,CAAI,GAAA,IAAA;AAAA,IAClE,iBAAiB,cAAe,CAAA,eAAA;AAAA,IAChC,UAAY,EAAA,MAAA,CAAO,cAAe,CAAA,UAAU,EAAE,WAAY,EAAA;AAAA,IAC1D,sBAAsB,mBAClB,GAAA;AAAA,MACE,WAAa,EAAA,mBAAA;AAAA,MACb,gBAAA,EAAkB,eAAe,qCAAyC,IAAA,EAAA;AAAA,KAE5E,GAAA,IAAA;AAAA,IACJ,MAAA,EAAQ,MAAO,CAAA,YAAA,GACX,EAAE,aAAA,EAAe,OAAO,YAAc,EAAA,iBAAA,EAAmB,MAAO,CAAA,gBAAA,EAChE,GAAA,IAAA;AAAA,IACJ,WAAA,EAAa,UAAW,CAAA,YAAA,GACpB,EAAE,aAAA,EAAe,OAAO,YAAc,EAAA,iBAAA,EAAmB,MAAO,CAAA,gBAAA,EAChE,GAAA,IAAA;AAAA,GACN,CAAA;AACF,CAAA,CAAA;AAEA,MAAM,aAAA,GAAgB,CAAC,UAAmF,KAAA;AACxG,EAAI,IAAA,UAAA,CAAW,iBAAiB,MAAW,KAAA,CAAA;AAAG,IAAO,OAAA,IAAA,CAAA;AAErD,EAAO,OAAA;AAAA,IACL,gBAAkB,E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,YAAA,EAAc,cAAe,CAAA,WAAA,CAAY,YAAY,CAAA;AAAA,WACrD,CAAA,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACF,CAAA,CAAA;AAAA,KAEJ,GAAA,IAAA;AAAA,IACJ,WAAa,EAAA,UAAA,CAAW,WAAY,CAAA,QAAA,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,GACjD,CAAA;AACF;;;;"}
|
|
@@ -49,7 +49,7 @@ async function rechargeApiRequest(method, url, { id, query, data, headers } = {}
|
|
|
49
49
|
"X-Recharge-Sdk-Fn": session.internalFnCall,
|
|
50
50
|
...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
|
|
51
51
|
...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {},
|
|
52
|
-
"X-Recharge-Sdk-Version": "1.
|
|
52
|
+
"X-Recharge-Sdk-Version": "1.49.0",
|
|
53
53
|
"X-Request-Id": session.internalRequestId,
|
|
54
54
|
...session.tmp_fn_identifier ? { "X-Recharge-Sdk-Fn-Identifier": session.tmp_fn_identifier } : {},
|
|
55
55
|
...headers ? headers : {}
|
package/dist/esm/api/auth.js
CHANGED
|
@@ -179,7 +179,7 @@ async function rechargeAdminRequest(method, url, { id, query, data, headers } =
|
|
|
179
179
|
...storefrontAccessToken ? { "X-Recharge-Storefront-Access-Token": storefrontAccessToken } : {},
|
|
180
180
|
...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
|
|
181
181
|
...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {},
|
|
182
|
-
"X-Recharge-Sdk-Version": "1.
|
|
182
|
+
"X-Recharge-Sdk-Version": "1.49.0",
|
|
183
183
|
...headers ? headers : {}
|
|
184
184
|
};
|
|
185
185
|
return request(method, `${rechargeBaseUrl}${url}`, { id, query, data, headers: reqHeaders });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n InternalSession,\n Session,\n UpdateBundleSelectionRequest,\n UpdateBundlePurchaseItem,\n BundlePurchaseItem,\n BundlePurchaseItemParams,\n BundleData,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { BundleSelectionValidator, toLineItemProperty } from '../utils/bundle';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction createBundleData(bundle: BundleAppProxy) {\n return toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: 0, // server will replace it with the current time\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\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 bundleData = createBundleData(bundle);\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 async function getBundleSelectionId(session: Session, bundle: BundleAppProxy): Promise<string> {\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const bundleData = createBundleData(bundle);\n\n try {\n const payload = await rechargeApiRequest<{ id: string; code: number; message: string }>(\n 'post',\n `/bundle_selections/bundle_id`,\n {\n data: {\n bundle: bundleData,\n },\n },\n getInternalSession(session, 'getBundleSelectionId')\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 if (bundle.selections.length === 0) {\n return 'No selections defined';\n }\n // Don't make bundle settings call due to merchant issues\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\nexport async function validateBundleSelection(bundle: BundleAppProxy): Promise<{ valid: boolean; error?: string }> {\n try {\n const bundleData = await shopifyAppProxyRequest<BundleData>('get', `/bundle-data/${bundle.externalProductId}`);\n\n const selectionValidator = new BundleSelectionValidator(bundle.selections, bundleData);\n\n return { valid: selectionValidator.isBundleSelectionValid(bundle.externalVariantId) };\n } catch (error) {\n return { valid: false, error: String(error) };\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'getBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>(\n 'get',\n `/bundle_selections`,\n { query },\n getInternalSession(session, 'listBundleSelections')\n );\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 getInternalSession(session, 'createBundleSelection')\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updateBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'deleteBundleSelection')\n );\n}\n\nexport async function updateBundle(\n session: Session,\n purchase_item_id: string | number,\n updateRequest: UpdateBundlePurchaseItem,\n query?: BundlePurchaseItemParams\n): Promise<BundlePurchaseItem> {\n if (purchase_item_id === undefined || purchase_item_id === '') {\n throw new Error('Purchase item ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: BundlePurchaseItem }>(\n 'put',\n '/bundles',\n {\n id: purchase_item_id,\n data: updateRequest,\n query,\n },\n getInternalSession(session, 'updateBundle')\n );\n\n return subscription;\n}\n"],"names":[],"mappings":";;;;;AAoBA,MAAM,uBAA0B,GAAA,8BAAA,CAAA;AAEhC,SAAS,iBAAiB,MAAwB,EAAA;AAChD,EAAA,OAAO,kBAAmB,CAAA;AAAA,IACxB,WAAW,MAAO,CAAA,iBAAA;AAAA,IAClB,OAAS,EAAA,CAAA;AAAA;AAAA,IACT,KAAO,EAAA,MAAA,CAAO,UAAW,CAAA,GAAA,CAAI,CAAQ,IAAA,KAAA;AACnC,MAAO,OAAA;AAAA,QACL,cAAc,IAAK,CAAA,YAAA;AAAA,QACnB,WAAW,IAAK,CAAA,iBAAA;AAAA,QAChB,WAAW,IAAK,CAAA,iBAAA;AAAA,QAChB,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,GAAK,EAAA,EAAA;AAAA,OACP,CAAA;AAAA,KACD,CAAA;AAAA,GACF,CAAA,CAAA;AACH,CAAA;AAEA,eAAsB,YAAY,MAAyC,EAAA;AACzE,EAAA,MAAM,OAAO,UAAW,EAAA,CAAA;AACxB,EAAM,MAAA,OAAA,GAAU,MAAM,cAAA,CAAe,MAAM,CAAA,CAAA;AAC3C,EAAA,IAAI,YAAY,IAAM,EAAA;AACpB,IAAM,MAAA,IAAI,MAAM,OAAO,CAAA,CAAA;AAAA,GACzB;AACA,EAAM,MAAA,UAAA,GAAa,iBAAiB,MAAM,CAAA,CAAA;AAE1C,EAAI,IAAA;AACF,IAAA,MAAM,UAAU,MAAM,sBAAA;AAAA,MACpB,MAAA;AAAA,MACA,GAAG,uBAAuB,CAAA,eAAA,CAAA;AAAA,MAC1B;AAAA,QACE,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N,KAAA;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,cAAc,CAAA;AAAA,GAC5C,CAAA;AAEA,EAAO,OAAA,YAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n Session,\n UpdateBundleSelectionRequest,\n UpdateBundlePurchaseItem,\n BundlePurchaseItem,\n BundlePurchaseItemParams,\n BundleData,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { BundleSelectionValidator, toLineItemProperty } from '../utils/bundle';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction createBundleData(bundle: BundleAppProxy) {\n return toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: 0, // server will replace it with the current time\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\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 bundleData = createBundleData(bundle);\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 async function getBundleSelectionId(session: Session, bundle: BundleAppProxy): Promise<string> {\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const bundleData = createBundleData(bundle);\n\n try {\n const payload = await rechargeApiRequest<{ id: string; code: number; message: string }>(\n 'post',\n `/bundle_selections/bundle_id`,\n {\n data: {\n bundle: bundleData,\n },\n },\n getInternalSession(session, 'getBundleSelectionId')\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 if (bundle.selections.length === 0) {\n return 'No selections defined';\n }\n // Don't make bundle settings call due to merchant issues\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\nexport async function validateBundleSelection(bundle: BundleAppProxy): Promise<{ valid: boolean; error?: string }> {\n try {\n const bundleData = await shopifyAppProxyRequest<BundleData>('get', `/bundle-data/${bundle.externalProductId}`);\n\n const selectionValidator = new BundleSelectionValidator(bundle.selections, bundleData);\n\n return { valid: selectionValidator.isBundleSelectionValid(bundle.externalVariantId) };\n } catch (error) {\n return { valid: false, error: String(error) };\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'getBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>(\n 'get',\n `/bundle_selections`,\n { query },\n getInternalSession(session, 'listBundleSelections')\n );\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 getInternalSession(session, 'createBundleSelection')\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 if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updateBundleSelection')\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n getInternalSession(session, 'deleteBundleSelection')\n );\n}\n\nexport async function updateBundle(\n session: Session,\n purchase_item_id: string | number,\n updateRequest: UpdateBundlePurchaseItem,\n query?: BundlePurchaseItemParams\n): Promise<BundlePurchaseItem> {\n if (purchase_item_id === undefined || purchase_item_id === '') {\n throw new Error('Purchase item ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: BundlePurchaseItem }>(\n 'put',\n '/bundles',\n {\n id: purchase_item_id,\n data: updateRequest,\n query,\n },\n getInternalSession(session, 'updateBundle')\n );\n\n return subscription;\n}\n"],"names":[],"mappings":";;;;;AAmBA,MAAM,uBAA0B,GAAA,8BAAA,CAAA;AAEhC,SAAS,iBAAiB,MAAwB,EAAA;AAChD,EAAA,OAAO,kBAAmB,CAAA;AAAA,IACxB,WAAW,MAAO,CAAA,iBAAA;AAAA,IAClB,OAAS,EAAA,CAAA;AAAA;AAAA,IACT,KAAO,EAAA,MAAA,CAAO,UAAW,CAAA,GAAA,CAAI,CAAQ,IAAA,KAAA;AACnC,MAAO,OAAA;AAAA,QACL,cAAc,IAAK,CAAA,YAAA;AAAA,QACnB,WAAW,IAAK,CAAA,iBAAA;AAAA,QAChB,WAAW,IAAK,CAAA,iBAAA;AAAA,QAChB,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,GAAK,EAAA,EAAA;AAAA,OACP,CAAA;AAAA,KACD,CAAA;AAAA,GACF,CAAA,CAAA;AACH,CAAA;AAEA,eAAsB,YAAY,MAAyC,EAAA;AACzE,EAAA,MAAM,OAAO,UAAW,EAAA,CAAA;AACxB,EAAM,MAAA,OAAA,GAAU,MAAM,cAAA,CAAe,MAAM,CAAA,CAAA;AAC3C,EAAA,IAAI,YAAY,IAAM,EAAA;AACpB,IAAM,MAAA,IAAI,MAAM,OAAO,CAAA,CAAA;AAAA,GACzB;AACA,EAAM,MAAA,UAAA,GAAa,iBAAiB,MAAM,CAAA,CAAA;AAE1C,EAAI,IAAA;AACF,IAAA,MAAM,UAAU,MAAM,sBAAA;AAAA,MACpB,MAAA;AAAA,MACA,GAAG,uBAAuB,CAAA,eAAA,CAAA;AAAA,MAC1B;AAAA,QACE,IAAM,EAAA;AAAA,UACJ,MAAQ,EAAA,UAAA;AAAA,SACV;AAAA,QACA,OAAS,EAAA;AAAA,UAC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A,EAAO,OAAA,YAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getOptions } from '../utils/options.js';
|
|
2
|
+
import { SHOPIFY_APP_PROXY_URL } from '../constants/api.js';
|
|
3
|
+
import { shopifyAppProxyRequest, request } from '../utils/request.js';
|
|
4
|
+
import { mapOnlineStoreToPublicBundleData } from '../utils/bundleData.js';
|
|
5
|
+
|
|
6
|
+
async function loadBundleData(id, options) {
|
|
7
|
+
if (options?.source === "shopify_storefront") {
|
|
8
|
+
return loadFromShopifyStorefrontApi();
|
|
9
|
+
}
|
|
10
|
+
return loadFromOnlineStore(id, options?.country_code);
|
|
11
|
+
}
|
|
12
|
+
async function loadFromOnlineStore(id, country_code) {
|
|
13
|
+
if (!country_code) {
|
|
14
|
+
const data = await shopifyAppProxyRequest("get", `/bundle-data/${id}`);
|
|
15
|
+
return mapOnlineStoreToPublicBundleData(data);
|
|
16
|
+
}
|
|
17
|
+
const payload = new FormData();
|
|
18
|
+
payload.append("form_type", "localization");
|
|
19
|
+
payload.append("_method", "put");
|
|
20
|
+
payload.append("return_to", `${SHOPIFY_APP_PROXY_URL}/bundle-data/${id}`);
|
|
21
|
+
payload.append("country_code", country_code);
|
|
22
|
+
try {
|
|
23
|
+
const data = await request("post", "/localization", {
|
|
24
|
+
headers: { "Content-Type": "multipart/form-data" },
|
|
25
|
+
data: payload
|
|
26
|
+
});
|
|
27
|
+
return mapOnlineStoreToPublicBundleData(data);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
const data = await shopifyAppProxyRequest("get", `/bundle-data/${id}`);
|
|
30
|
+
return mapOnlineStoreToPublicBundleData(data);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function loadFromShopifyStorefrontApi(id, options) {
|
|
34
|
+
const opts = getOptions();
|
|
35
|
+
if (!opts.storeIdentifier) {
|
|
36
|
+
throw new Error("Store identifier is required for Shopify Storefront API requests");
|
|
37
|
+
}
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { loadBundleData };
|
|
42
|
+
//# sourceMappingURL=bundleData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleData.js","sources":["../../../src/api/bundleData.ts"],"sourcesContent":["import { PublicBundleData } from '../types/bundleData';\nimport { getOptions } from '../utils/options';\nimport { SHOPIFY_APP_PROXY_URL } from '../constants/api';\nimport { BundleData as StorefrontBundleData } from '../types/bundle';\nimport { request, shopifyAppProxyRequest } from '../utils/request';\nimport { mapOnlineStoreToPublicBundleData } from '../utils/bundleData';\n\ntype BaseOptions = {\n country_code?: string;\n};\n\n/**\n * Options for loading bundle data from online store endpoint (bundle-data)\n */\ntype OnlineStoreOptions = {\n source: 'online_store';\n} & BaseOptions;\n\n/**\n * Options for loading bundle data from Shopify Storefront API\n */\ntype ShopifyStorefrontOptions = {\n source: 'shopify_storefront';\n shopify_storefront_access_token: string;\n} & BaseOptions;\n\ntype Options = OnlineStoreOptions | ShopifyStorefrontOptions;\n\n/**\n * Load bundle data from the specified source\n *\n * @param id - The external product ID (Shopify product ID)\n * @param options - Configuration for data source and parameters\n * @param options.source - The source of the data (online_store or shopify_storefront)\n * @param options.country_code - The country code for the online store\n * @param options.storefront_access_token - The storefront access token for the Shopify Storefront API\n * @returns Promise resolving to bundle data result with success/error handling\n *\n * @example\n * ```typescript\n * // Load from online store\n * const result = await loadBundleData({\n * source: 'online_store',\n * external_product_id: '123456789',\n * country_code: 'US'\n * });\n *\n * if (result.success) {\n * console.log('Bundle data:', result.data);\n * } else {\n * console.error('Error:', result.error.message);\n * }\n *\n * // Load from Shopify Storefront API\n * const result2 = await loadBundleData({\n * source: 'shopify_storefront',\n * external_product_id: '123456789',\n * country_code: 'US',\n * shopify_storefront_access_token: 'your-token-here'\n * });\n * ```\n */\nexport async function loadBundleData(id: string, options?: Options): Promise<PublicBundleData> {\n if (options?.source === 'shopify_storefront') {\n return loadFromShopifyStorefrontApi(id, options);\n }\n\n return loadFromOnlineStore(id, options?.country_code);\n}\n\n/**\n * Load bundle data from the online store endpoint\n */\nasync function loadFromOnlineStore(id: string, country_code?: string): Promise<PublicBundleData> {\n if (!country_code) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${id}`);\n return mapOnlineStoreToPublicBundleData(data);\n }\n\n const payload = new FormData();\n payload.append('form_type', 'localization');\n payload.append('_method', 'put');\n payload.append('return_to', `${SHOPIFY_APP_PROXY_URL}/bundle-data/${id}`);\n payload.append('country_code', country_code);\n\n try {\n const data = await request<StorefrontBundleData>('post', '/localization', {\n headers: { 'Content-Type': 'multipart/form-data' },\n data: payload,\n });\n return mapOnlineStoreToPublicBundleData(data);\n } catch (error) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${id}`);\n return mapOnlineStoreToPublicBundleData(data);\n }\n}\n\n/**\n * Load bundle data from Shopify Storefront API\n */\nasync function loadFromShopifyStorefrontApi(id: string, options: ShopifyStorefrontOptions): Promise<PublicBundleData> {\n const opts = getOptions();\n\n if (!opts.storeIdentifier) {\n throw new Error('Store identifier is required for Shopify Storefront API requests');\n }\n\n // Request data from Shopify Storefront API\n return {} as PublicBundleData;\n}\n"],"names":[],"mappings":";;;;;AA8DsB,eAAA,cAAA,CAAe,IAAY,OAA8C,EAAA;AAC7F,EAAI,IAAA,OAAA,EAAS,WAAW,oBAAsB,EAAA;AAC5C,IAAO,OAAA,4BAAA,CAAwC,CAAA,CAAA;AAAA,GACjD;AAEA,EAAO,OAAA,mBAAA,CAAoB,EAAI,EAAA,OAAA,EAAS,YAAY,CAAA,CAAA;AACtD,CAAA;AAKA,eAAe,mBAAA,CAAoB,IAAY,YAAkD,EAAA;AAC/F,EAAA,IAAI,CAAC,YAAc,EAAA;AACjB,IAAA,MAAM,OAAO,MAAM,sBAAA,CAA6C,KAAO,EAAA,CAAA,aAAA,EAAgB,EAAE,CAAE,CAAA,CAAA,CAAA;AAC3F,IAAA,OAAO,iCAAiC,IAAI,CAAA,CAAA;AAAA,GAC9C;AAEA,EAAM,MAAA,OAAA,GAAU,IAAI,QAAS,EAAA,CAAA;AAC7B,EAAQ,OAAA,CAAA,MAAA,CAAO,aAAa,cAAc,CAAA,CAAA;AAC1C,EAAQ,OAAA,CAAA,MAAA,CAAO,WAAW,KAAK,CAAA,CAAA;AAC/B,EAAA,OAAA,CAAQ,OAAO,WAAa,EAAA,CAAA,EAAG,qBAAqB,CAAA,aAAA,EAAgB,EAAE,CAAE,CAAA,CAAA,CAAA;AACxE,EAAQ,OAAA,CAAA,MAAA,CAAO,gBAAgB,YAAY,CAAA,CAAA;AAE3C,EAAI,IAAA;AACF,IAAA,MAAM,IAAO,GAAA,MAAM,OAA8B,CAAA,MAAA,EAAQ,eAAiB,EAAA;AAAA,MACxE,OAAA,EAAS,EAAE,cAAA,EAAgB,qBAAsB,EAAA;AAAA,MACjD,IAAM,EAAA,OAAA;AAAA,KACP,CAAA,CAAA;AACD,IAAA,OAAO,iCAAiC,IAAI,CAAA,CAAA;AAAA,WACrC,KAAO,EAAA;AACd,IAAA,MAAM,OAAO,MAAM,sBAAA,CAA6C,KAAO,EAAA,CAAA,aAAA,EAAgB,EAAE,CAAE,CAAA,CAAA,CAAA;AAC3F,IAAA,OAAO,iCAAiC,IAAI,CAAA,CAAA;AAAA,GAC9C;AACF,CAAA;AAKA,eAAe,4BAAA,CAA6B,IAAY,OAA8D,EAAA;AACpH,EAAA,MAAM,OAAO,UAAW,EAAA,CAAA;AAExB,EAAI,IAAA,CAAC,KAAK,eAAiB,EAAA;AACzB,IAAM,MAAA,IAAI,MAAM,kEAAkE,CAAA,CAAA;AAAA,GACpF;AAGA,EAAA,OAAO,EAAC,CAAA;AACV;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { applyDiscountToAddress, createAddress, deleteAddress, getAddress, listAddresses, mergeAddresses, removeDiscountsFromAddress, skipFutureCharge, updateAddress } from './api/address.js';
|
|
2
2
|
export { loginCustomerPortal, loginShopifyApi, loginShopifyAppProxy, loginWithShopifyCustomerAccount, loginWithShopifyStorefront, sendPasswordlessCode, sendPasswordlessCodeAppProxy, validatePasswordlessCode, validatePasswordlessCodeAppProxy } from './api/auth.js';
|
|
3
3
|
export { createBundleSelection, deleteBundleSelection, getBundleId, getBundleSelection, getBundleSelectionId, getDynamicBundleItems, listBundleSelections, updateBundle, updateBundleSelection, validateBundle, validateBundleSelection, validateDynamicBundle } from './api/bundle.js';
|
|
4
|
+
export { loadBundleData } from './api/bundleData.js';
|
|
4
5
|
export { getCDNBundleSettings, getCDNProduct, getCDNProductAndSettings, getCDNProducts, getCDNProductsAndSettings, getCDNStoreSettings, getCDNWidgetSettings, resetCDNCache } from './api/cdn.js';
|
|
5
6
|
export { applyDiscountToCharge, getCharge, listCharges, processCharge, removeDiscountsFromCharge, skipCharge, unskipCharge } from './api/charge.js';
|
|
6
7
|
export { getCollection, listCollectionProducts, listCollections } from './api/collection.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|