@rechargeapps/storefront-client 1.88.0 → 1.90.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.
Files changed (75) hide show
  1. package/dist/cjs/api/address.js +2 -1
  2. package/dist/cjs/api/address.js.map +1 -1
  3. package/dist/cjs/api/auth.js +17 -8
  4. package/dist/cjs/api/auth.js.map +1 -1
  5. package/dist/cjs/api/bundle.js +5 -1
  6. package/dist/cjs/api/bundle.js.map +1 -1
  7. package/dist/cjs/api/bundleData.js +6 -3
  8. package/dist/cjs/api/bundleData.js.map +1 -1
  9. package/dist/cjs/api/cdn.js +2 -1
  10. package/dist/cjs/api/cdn.js.map +1 -1
  11. package/dist/cjs/api/charge.js +7 -6
  12. package/dist/cjs/api/charge.js.map +1 -1
  13. package/dist/cjs/api/credit.js +4 -2
  14. package/dist/cjs/api/credit.js.map +1 -1
  15. package/dist/cjs/api/customer.js +5 -4
  16. package/dist/cjs/api/customer.js.map +1 -1
  17. package/dist/cjs/api/customerSurveys.js +2 -1
  18. package/dist/cjs/api/customerSurveys.js.map +1 -1
  19. package/dist/cjs/api/membership.js +4 -3
  20. package/dist/cjs/api/membership.js.map +1 -1
  21. package/dist/cjs/api/order.js +2 -1
  22. package/dist/cjs/api/order.js.map +1 -1
  23. package/dist/cjs/api/subscription.js +10 -9
  24. package/dist/cjs/api/subscription.js.map +1 -1
  25. package/dist/cjs/api/tieredDiscount.js +2 -1
  26. package/dist/cjs/api/tieredDiscount.js.map +1 -1
  27. package/dist/cjs/mappers/cdn.js +6 -1
  28. package/dist/cjs/mappers/cdn.js.map +1 -1
  29. package/dist/cjs/utils/bundle.js +25 -11
  30. package/dist/cjs/utils/bundle.js.map +1 -1
  31. package/dist/cjs/utils/bundleData.js +1 -1
  32. package/dist/cjs/utils/bundleData.js.map +1 -1
  33. package/dist/cjs/utils/request.js +5 -4
  34. package/dist/cjs/utils/request.js.map +1 -1
  35. package/dist/cjs/utils/url.js +8 -0
  36. package/dist/cjs/utils/url.js.map +1 -0
  37. package/dist/esm/api/address.js +2 -1
  38. package/dist/esm/api/address.js.map +1 -1
  39. package/dist/esm/api/auth.js +17 -8
  40. package/dist/esm/api/auth.js.map +1 -1
  41. package/dist/esm/api/bundle.js +5 -1
  42. package/dist/esm/api/bundle.js.map +1 -1
  43. package/dist/esm/api/bundleData.js +6 -3
  44. package/dist/esm/api/bundleData.js.map +1 -1
  45. package/dist/esm/api/cdn.js +2 -1
  46. package/dist/esm/api/cdn.js.map +1 -1
  47. package/dist/esm/api/charge.js +7 -6
  48. package/dist/esm/api/charge.js.map +1 -1
  49. package/dist/esm/api/credit.js +4 -2
  50. package/dist/esm/api/credit.js.map +1 -1
  51. package/dist/esm/api/customer.js +5 -4
  52. package/dist/esm/api/customer.js.map +1 -1
  53. package/dist/esm/api/customerSurveys.js +2 -1
  54. package/dist/esm/api/customerSurveys.js.map +1 -1
  55. package/dist/esm/api/membership.js +4 -3
  56. package/dist/esm/api/membership.js.map +1 -1
  57. package/dist/esm/api/order.js +2 -1
  58. package/dist/esm/api/order.js.map +1 -1
  59. package/dist/esm/api/subscription.js +10 -9
  60. package/dist/esm/api/subscription.js.map +1 -1
  61. package/dist/esm/api/tieredDiscount.js +2 -1
  62. package/dist/esm/api/tieredDiscount.js.map +1 -1
  63. package/dist/esm/mappers/cdn.js +6 -1
  64. package/dist/esm/mappers/cdn.js.map +1 -1
  65. package/dist/esm/utils/bundle.js +25 -11
  66. package/dist/esm/utils/bundle.js.map +1 -1
  67. package/dist/esm/utils/bundleData.js +1 -1
  68. package/dist/esm/utils/bundleData.js.map +1 -1
  69. package/dist/esm/utils/request.js +3 -2
  70. package/dist/esm/utils/request.js.map +1 -1
  71. package/dist/esm/utils/url.js +6 -0
  72. package/dist/esm/utils/url.js.map +1 -0
  73. package/dist/index.d.ts +13 -1
  74. package/dist/umd/recharge-client.min.js +11 -11
  75. package/package.json +1 -1
@@ -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 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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MAAM,kBAAA;AAAA,IACjC,KAAA;AAAA,IACA,CAAA,kBAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,IAAM,EAAA,aAAA;AAAA,KACR;AAAA,IACA,kBAAA,CAAmB,SAAS,uBAAuB,CAAA;AAAA,GACrD,CAAA;AACA,EAAO,OAAA,gBAAA,CAAA;AACT,CAAA;AAEgB,SAAA,qBAAA,CAAsB,SAAkB,EAAoC,EAAA;AAC1F,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAO,OAAA,kBAAA;AAAA,IACL,QAAA;AAAA,IACA,CAAA,kBAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,uBAAuB,CAAA;AAAA,GACrD,CAAA;AACF,CAAA;AAEA,eAAsB,YACpB,CAAA,OAAA,EACA,gBACA,EAAA,aAAA,EACA,KAC6B,EAAA;AAC7B,EAAI,IAAA,gBAAA,KAAqB,KAAa,CAAA,IAAA,gBAAA,KAAqB,EAAI,EAAA;AAC7D,IAAM,MAAA,IAAI,MAAM,8BAA8B,CAAA,CAAA;AAAA,GAChD;AACA,EAAM,MAAA,EAAE,YAAa,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC7B,KAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,MACE,EAAI,EAAA,gBAAA;AAAA,MACJ,IAAM,EAAA,aAAA;AAAA,MACN,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 { encodePathSegment } from '../utils/url';\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>(\n 'get',\n `/bundle-data/${encodePathSegment(bundle.externalProductId)}`\n );\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,u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M,kBAAA;AAAA,IACjC,KAAA;AAAA,IACA,CAAA,kBAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,IAAM,EAAA,aAAA;AAAA,KACR;AAAA,IACA,kBAAA,CAAmB,SAAS,uBAAuB,CAAA;AAAA,GACrD,CAAA;AACA,EAAO,OAAA,gBAAA,CAAA;AACT,CAAA;AAEgB,SAAA,qBAAA,CAAsB,SAAkB,EAAoC,EAAA;AAC1F,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAO,OAAA,kBAAA;AAAA,IACL,QAAA;AAAA,IACA,CAAA,kBAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,uBAAuB,CAAA;AAAA,GACrD,CAAA;AACF,CAAA;AAEA,eAAsB,YACpB,CAAA,OAAA,EACA,gBACA,EAAA,aAAA,EACA,KAC6B,EAAA;AAC7B,EAAI,IAAA,gBAAA,KAAqB,KAAa,CAAA,IAAA,gBAAA,KAAqB,EAAI,EAAA;AAC7D,IAAM,MAAA,IAAI,MAAM,8BAA8B,CAAA,CAAA;AAAA,GAChD;AACA,EAAM,MAAA,EAAE,YAAa,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC7B,KAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,MACE,EAAI,EAAA,gBAAA;AAAA,MACJ,IAAM,EAAA,aAAA;AAAA,MACN,KAAA;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,cAAc,CAAA;AAAA,GAC5C,CAAA;AAEA,EAAO,OAAA,YAAA,CAAA;AACT;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { getOptions } from '../utils/options.js';
2
2
  import { SHOPIFY_APP_PROXY_URL } from '../constants/api.js';
3
3
  import { shopifyAppProxyRequest, request } from '../utils/request.js';
4
+ import { encodePathSegment } from '../utils/url.js';
4
5
  import { mapOnlineStoreToPublicBundleData } from '../utils/bundleData.js';
5
6
 
6
7
  async function loadBundleData(id, options) {
@@ -13,12 +14,14 @@ async function loadFromOnlineStore(id, country_code) {
13
14
  const { appName, appVersion } = getOptions();
14
15
  const headers = {
15
16
  "X-Recharge-Sdk-Fn": "loadFromOnlineStore",
16
- "X-Recharge-Sdk-Version": "1.88.0",
17
+ "X-Recharge-Sdk-Version": "1.90.0",
17
18
  ...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
18
19
  ...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {}
19
20
  };
20
21
  if (!country_code) {
21
- const data = await shopifyAppProxyRequest("get", `/bundle-data/${id}`, { headers });
22
+ const data = await shopifyAppProxyRequest("get", `/bundle-data/${encodePathSegment(id)}`, {
23
+ headers
24
+ });
22
25
  return mapOnlineStoreToPublicBundleData(data);
23
26
  }
24
27
  const payload = new FormData();
@@ -33,7 +36,7 @@ async function loadFromOnlineStore(id, country_code) {
33
36
  });
34
37
  return mapOnlineStoreToPublicBundleData(data);
35
38
  } catch (error) {
36
- const data = await shopifyAppProxyRequest("get", `/bundle-data/${id}`, {
39
+ const data = await shopifyAppProxyRequest("get", `/bundle-data/${encodePathSegment(id)}`, {
37
40
  headers
38
41
  });
39
42
  return mapOnlineStoreToPublicBundleData(data);
@@ -1 +1 @@
1
- {"version":3,"file":"bundleData.js","sources":["../../../src/api/bundleData.ts"],"sourcesContent":["import { Options, PublicBundleData, ShopifyStorefrontOptions } 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\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 const { appName, appVersion } = getOptions();\n const headers = {\n 'X-Recharge-Sdk-Fn': 'loadFromOnlineStore',\n 'X-Recharge-Sdk-Version': '__SDK_VERSION__',\n ...(appName ? { 'X-Recharge-Sdk-App-Name': appName } : {}),\n ...(appVersion ? { 'X-Recharge-Sdk-App-Version': appVersion } : {}),\n };\n\n if (!country_code) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${id}`, { headers });\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', ...headers },\n data: payload,\n });\n return mapOnlineStoreToPublicBundleData(data);\n } catch (error) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${id}`, {\n headers,\n });\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":";;;;;AAyCsB,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,MAAM,EAAE,OAAA,EAAS,UAAW,EAAA,GAAI,UAAW,EAAA,CAAA;AAC3C,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,mBAAqB,EAAA,qBAAA;AAAA,IACrB,wBAA0B,EAAA,QAAA;AAAA,IAC1B,GAAI,OAAU,GAAA,EAAE,yBAA2B,EAAA,OAAA,KAAY,EAAC;AAAA,IACxD,GAAI,UAAa,GAAA,EAAE,4BAA8B,EAAA,UAAA,KAAe,EAAC;AAAA,GACnE,CAAA;AAEA,EAAA,IAAI,CAAC,YAAc,EAAA;AACjB,IAAM,MAAA,IAAA,GAAO,MAAM,sBAA6C,CAAA,KAAA,EAAO,gBAAgB,EAAE,CAAA,CAAA,EAAI,EAAE,OAAA,EAAS,CAAA,CAAA;AACxG,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,OAAS,EAAA,EAAE,cAAgB,EAAA,qBAAA,EAAuB,GAAG,OAAQ,EAAA;AAAA,MAC7D,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,CAAI,CAAA,EAAA;AAAA,MAC3F,OAAA;AAAA,KACD,CAAA,CAAA;AACD,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;;;;"}
1
+ {"version":3,"file":"bundleData.js","sources":["../../../src/api/bundleData.ts"],"sourcesContent":["import { Options, PublicBundleData, ShopifyStorefrontOptions } 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 { encodePathSegment } from '../utils/url';\nimport { mapOnlineStoreToPublicBundleData } from '../utils/bundleData';\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 const { appName, appVersion } = getOptions();\n const headers = {\n 'X-Recharge-Sdk-Fn': 'loadFromOnlineStore',\n 'X-Recharge-Sdk-Version': '__SDK_VERSION__',\n ...(appName ? { 'X-Recharge-Sdk-App-Name': appName } : {}),\n ...(appVersion ? { 'X-Recharge-Sdk-App-Version': appVersion } : {}),\n };\n\n if (!country_code) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${encodePathSegment(id)}`, {\n headers,\n });\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', ...headers },\n data: payload,\n });\n return mapOnlineStoreToPublicBundleData(data);\n } catch (error) {\n const data = await shopifyAppProxyRequest<StorefrontBundleData>('get', `/bundle-data/${encodePathSegment(id)}`, {\n headers,\n });\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":";;;;;;AA0CsB,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,MAAM,EAAE,OAAA,EAAS,UAAW,EAAA,GAAI,UAAW,EAAA,CAAA;AAC3C,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,mBAAqB,EAAA,qBAAA;AAAA,IACrB,wBAA0B,EAAA,QAAA;AAAA,IAC1B,GAAI,OAAU,GAAA,EAAE,yBAA2B,EAAA,OAAA,KAAY,EAAC;AAAA,IACxD,GAAI,UAAa,GAAA,EAAE,4BAA8B,EAAA,UAAA,KAAe,EAAC;AAAA,GACnE,CAAA;AAEA,EAAA,IAAI,CAAC,YAAc,EAAA;AACjB,IAAM,MAAA,IAAA,GAAO,MAAM,sBAA6C,CAAA,KAAA,EAAO,gBAAgB,iBAAkB,CAAA,EAAE,CAAC,CAAI,CAAA,EAAA;AAAA,MAC9G,OAAA;AAAA,KACD,CAAA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../mappers/cdn.js';
2
2
  import { cdnRequest } from '../utils/request.js';
3
+ import { encodePathSegment } from '../utils/url.js';
3
4
 
4
5
  const BASE_CDN_VERSION = "2020-12";
5
6
  const DEFAULT_STORE_SETTINGS = {
@@ -25,7 +26,7 @@ async function getCDNProduct(externalProductId, query) {
25
26
  const version = query?.version ?? "2020-12";
26
27
  const { product } = await cacheRequest(
27
28
  `product.${externalProductId}.${version}`,
28
- () => cdnRequest("get", `/product/${version}/${externalProductId}.json`)
29
+ () => cdnRequest("get", `/product/${version}/${encodePathSegment(externalProductId)}.json`)
29
30
  );
30
31
  if (version === "2020-12") {
31
32
  return productMapper(product);
@@ -1 +1 @@
1
- {"version":3,"file":"cdn.js","sources":["../../../src/api/cdn.ts"],"sourcesContent":["import {\n CDNWidgetSettings,\n CDNStoreSettings,\n CDNWidgetSettingsResource,\n CDNProductsAndSettings,\n CDNProductAndSettings,\n CDNProductsAndSettingsResource,\n CDNBundleSettings,\n CDNProductKeyObject,\n CDNProductRaw,\n CDNProductType,\n CDNProductQuery_2020_12,\n CDNProductQuery_2022_06,\n CDNProductResponseType,\n} from '../types';\nimport { productArrayMapper, productMapper, widgetSettingsMapper } from '../mappers/cdn';\nimport { cdnRequest } from '../utils/request';\n\nconst BASE_CDN_VERSION = '2020-12';\n\n// Default store settings if none are provided from the cdn\nconst DEFAULT_STORE_SETTINGS: CDNStoreSettings = {\n store_currency: {\n currency_code: 'USD',\n currency_symbol: '$',\n decimal_separator: '.',\n thousands_separator: ',',\n currency_symbol_location: 'left',\n },\n};\n\nconst promiseCache = new Map();\n\n// This will cache the request and use the same promise anywhere we call this function. This will never make multiple calls and always return the first request\nfunction cacheRequest<T>(cacheKey: string, request: () => T): T {\n if (!promiseCache.has(cacheKey)) {\n promiseCache.set(cacheKey, request());\n }\n return promiseCache.get(cacheKey);\n}\n\nexport async function getCDNProduct<\n T extends CDNProductQuery_2020_12 | CDNProductQuery_2022_06 = CDNProductQuery_2020_12\n>(externalProductId: string | number, query?: T): Promise<CDNProductType<T>> {\n if (externalProductId === undefined || externalProductId === '') {\n throw new Error('ID is required');\n }\n const version = query?.version ?? '2020-12';\n const { product } = await cacheRequest(`product.${externalProductId}.${version}`, () =>\n cdnRequest<CDNProductResponseType<T>>('get', `/product/${version}/${externalProductId}.json`)\n );\n\n if (version === '2020-12') {\n return productMapper(product as CDNProductRaw) as CDNProductType<T>;\n }\n return product as CDNProductType<T>;\n}\n\nexport async function getCDNStoreSettings(): Promise<CDNStoreSettings> {\n const storeSettings = await cacheRequest('storeSettings', () =>\n cdnRequest<CDNStoreSettings>('get', `/${BASE_CDN_VERSION}/store_settings.json`).catch(() => {\n return DEFAULT_STORE_SETTINGS;\n })\n );\n return storeSettings;\n}\n\nexport async function getCDNWidgetSettings(): Promise<CDNWidgetSettings> {\n const { widget_settings } = await cacheRequest('widgetSettings', () =>\n cdnRequest<CDNWidgetSettingsResource>('get', `/${BASE_CDN_VERSION}/widget_settings.json`)\n );\n\n const widgetSettings = widgetSettingsMapper(widget_settings);\n\n return widgetSettings;\n}\n\nexport async function getCDNProductsAndSettings(): Promise<CDNProductsAndSettings> {\n const { products, widget_settings, store_settings, meta } = await cacheRequest('productsAndSettings', () =>\n cdnRequest<CDNProductsAndSettingsResource>('get', `/product/${BASE_CDN_VERSION}/products.json`)\n );\n\n if (meta?.status === 'error') {\n return Promise.reject(meta.message);\n }\n\n return {\n products: productArrayMapper(products),\n widget_settings: widgetSettingsMapper(widget_settings),\n store_settings: store_settings ?? {},\n };\n}\n\nexport async function getCDNProducts(): Promise<CDNProductKeyObject[]> {\n const { products } = await getCDNProductsAndSettings();\n return products;\n}\n\nexport async function getCDNProductAndSettings(externalProductId: string | number): Promise<CDNProductAndSettings> {\n const [product, store_settings, widget_settings] = await Promise.all([\n getCDNProduct(externalProductId),\n getCDNStoreSettings(),\n getCDNWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n}\n\nexport async function getCDNBundleSettings(\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> {\n const { bundle_product } = await getCDNProduct(externalProductId);\n\n return bundle_product;\n}\n\nexport async function resetCDNCache() {\n return Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n}\n"],"names":[],"mappings":";;;AAkBA,MAAM,gBAAmB,GAAA,SAAA,CAAA;AAGzB,MAAM,sBAA2C,GAAA;AAAA,EAC/C,cAAgB,EAAA;AAAA,IACd,aAAe,EAAA,KAAA;AAAA,IACf,eAAiB,EAAA,GAAA;AAAA,IACjB,iBAAmB,EAAA,GAAA;AAAA,IACnB,mBAAqB,EAAA,GAAA;AAAA,IACrB,wBAA0B,EAAA,MAAA;AAAA,GAC5B;AACF,CAAA,CAAA;AAEA,MAAM,YAAA,uBAAmB,GAAI,EAAA,CAAA;AAG7B,SAAS,YAAA,CAAgB,UAAkB,OAAqB,EAAA;AAC9D,EAAA,IAAI,CAAC,YAAA,CAAa,GAAI,CAAA,QAAQ,CAAG,EAAA;AAC/B,IAAa,YAAA,CAAA,GAAA,CAAI,QAAU,EAAA,OAAA,EAAS,CAAA,CAAA;AAAA,GACtC;AACA,EAAO,OAAA,YAAA,CAAa,IAAI,QAAQ,CAAA,CAAA;AAClC,CAAA;AAEsB,eAAA,aAAA,CAEpB,mBAAoC,KAAuC,EAAA;AAC3E,EAAI,IAAA,iBAAA,KAAsB,KAAa,CAAA,IAAA,iBAAA,KAAsB,EAAI,EAAA;AAC/D,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,OAAA,GAAU,OAAO,OAAW,IAAA,SAAA,CAAA;AAClC,EAAM,MAAA,EAAE,OAAQ,EAAA,GAAI,MAAM,YAAA;AAAA,IAAa,CAAA,QAAA,EAAW,iBAAiB,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA;AAAA,IAAI,MAChF,UAAsC,CAAA,KAAA,EAAO,YAAY,OAAO,CAAA,CAAA,E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mBAAmB,QAAQ,CAAA;AAAA,IACrC,eAAA,EAAiB,qBAAqB,eAAe,CAAA;AAAA,IACrD,cAAA,EAAgB,kBAAkB,EAAC;AAAA,GACrC,CAAA;AACF,CAAA;AAEA,eAAsB,cAAiD,GAAA;AACrE,EAAA,MAAM,EAAE,QAAA,EAAa,GAAA,MAAM,yBAA0B,EAAA,CAAA;AACrD,EAAO,OAAA,QAAA,CAAA;AACT,CAAA;AAEA,eAAsB,yBAAyB,iBAAoE,EAAA;AACjH,EAAA,MAAM,CAAC,OAAS,EAAA,cAAA,EAAgB,eAAe,CAAI,GAAA,MAAM,QAAQ,GAAI,CAAA;AAAA,IACnE,cAAc,iBAAiB,CAAA;AAAA,IAC/B,mBAAoB,EAAA;AAAA,IACpB,oBAAqB,EAAA;AAAA,GACtB,CAAA,CAAA;AAED,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,cAAA;AAAA,IACA,eAAA;AAAA,IACA,aAAe,EAAA,cAAA;AAAA,IACf,cAAgB,EAAA,eAAA;AAAA,GAClB,CAAA;AACF,CAAA;AAEA,eAAsB,qBACpB,iBAC+C,EAAA;AAC/C,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,MAAM,cAAc,iBAAiB,CAAA,CAAA;AAEhE,EAAO,OAAA,cAAA,CAAA;AACT,CAAA;AAEA,eAAsB,aAAgB,GAAA;AACpC,EAAO,OAAA,KAAA,CAAM,IAAK,CAAA,YAAA,CAAa,IAAK,EAAC,CAAE,CAAA,OAAA,CAAQ,CAAO,GAAA,KAAA,YAAA,CAAa,MAAO,CAAA,GAAG,CAAC,CAAA,CAAA;AAChF;;;;"}
1
+ {"version":3,"file":"cdn.js","sources":["../../../src/api/cdn.ts"],"sourcesContent":["import {\n CDNWidgetSettings,\n CDNStoreSettings,\n CDNWidgetSettingsResource,\n CDNProductsAndSettings,\n CDNProductAndSettings,\n CDNProductsAndSettingsResource,\n CDNBundleSettings,\n CDNProductKeyObject,\n CDNProductRaw,\n CDNProductType,\n CDNProductQuery_2020_12,\n CDNProductQuery_2022_06,\n CDNProductResponseType,\n} from '../types';\nimport { productArrayMapper, productMapper, widgetSettingsMapper } from '../mappers/cdn';\nimport { cdnRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nconst BASE_CDN_VERSION = '2020-12';\n\n// Default store settings if none are provided from the cdn\nconst DEFAULT_STORE_SETTINGS: CDNStoreSettings = {\n store_currency: {\n currency_code: 'USD',\n currency_symbol: '$',\n decimal_separator: '.',\n thousands_separator: ',',\n currency_symbol_location: 'left',\n },\n};\n\nconst promiseCache = new Map();\n\n// This will cache the request and use the same promise anywhere we call this function. This will never make multiple calls and always return the first request\nfunction cacheRequest<T>(cacheKey: string, request: () => T): T {\n if (!promiseCache.has(cacheKey)) {\n promiseCache.set(cacheKey, request());\n }\n return promiseCache.get(cacheKey);\n}\n\nexport async function getCDNProduct<\n T extends CDNProductQuery_2020_12 | CDNProductQuery_2022_06 = CDNProductQuery_2020_12\n>(externalProductId: string | number, query?: T): Promise<CDNProductType<T>> {\n if (externalProductId === undefined || externalProductId === '') {\n throw new Error('ID is required');\n }\n const version = query?.version ?? '2020-12';\n const { product } = await cacheRequest(`product.${externalProductId}.${version}`, () =>\n cdnRequest<CDNProductResponseType<T>>('get', `/product/${version}/${encodePathSegment(externalProductId)}.json`)\n );\n\n if (version === '2020-12') {\n return productMapper(product as CDNProductRaw) as CDNProductType<T>;\n }\n return product as CDNProductType<T>;\n}\n\nexport async function getCDNStoreSettings(): Promise<CDNStoreSettings> {\n const storeSettings = await cacheRequest('storeSettings', () =>\n cdnRequest<CDNStoreSettings>('get', `/${BASE_CDN_VERSION}/store_settings.json`).catch(() => {\n return DEFAULT_STORE_SETTINGS;\n })\n );\n return storeSettings;\n}\n\nexport async function getCDNWidgetSettings(): Promise<CDNWidgetSettings> {\n const { widget_settings } = await cacheRequest('widgetSettings', () =>\n cdnRequest<CDNWidgetSettingsResource>('get', `/${BASE_CDN_VERSION}/widget_settings.json`)\n );\n\n const widgetSettings = widgetSettingsMapper(widget_settings);\n\n return widgetSettings;\n}\n\nexport async function getCDNProductsAndSettings(): Promise<CDNProductsAndSettings> {\n const { products, widget_settings, store_settings, meta } = await cacheRequest('productsAndSettings', () =>\n cdnRequest<CDNProductsAndSettingsResource>('get', `/product/${BASE_CDN_VERSION}/products.json`)\n );\n\n if (meta?.status === 'error') {\n return Promise.reject(meta.message);\n }\n\n return {\n products: productArrayMapper(products),\n widget_settings: widgetSettingsMapper(widget_settings),\n store_settings: store_settings ?? {},\n };\n}\n\nexport async function getCDNProducts(): Promise<CDNProductKeyObject[]> {\n const { products } = await getCDNProductsAndSettings();\n return products;\n}\n\nexport async function getCDNProductAndSettings(externalProductId: string | number): Promise<CDNProductAndSettings> {\n const [product, store_settings, widget_settings] = await Promise.all([\n getCDNProduct(externalProductId),\n getCDNStoreSettings(),\n getCDNWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n}\n\nexport async function getCDNBundleSettings(\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> {\n const { bundle_product } = await getCDNProduct(externalProductId);\n\n return bundle_product;\n}\n\nexport async function resetCDNCache() {\n return Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n}\n"],"names":[],"mappings":";;;;AAmBA,MAAM,gBAAmB,GAAA,SAAA,CAAA;AAGzB,MAAM,sBAA2C,GAAA;AAAA,EAC/C,cAAgB,EAAA;AAAA,IACd,aAAe,EAAA,KAAA;AAAA,IACf,eAAiB,EAAA,GAAA;AAAA,IACjB,iBAAmB,EAAA,GAAA;AAAA,IACnB,mBAAqB,EAAA,GAAA;AAAA,IACrB,wBAA0B,EAAA,MAAA;AAAA,GAC5B;AACF,CAAA,CAAA;AAEA,MAAM,YAAA,uBAAmB,GAAI,EAAA,CAAA;AAG7B,SAAS,YAAA,CAAgB,UAAkB,OAAqB,EAAA;AAC9D,EAAA,IAAI,CAAC,YAA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IACA,eAAA;AAAA,IACA,aAAe,EAAA,cAAA;AAAA,IACf,cAAgB,EAAA,eAAA;AAAA,GAClB,CAAA;AACF,CAAA;AAEA,eAAsB,qBACpB,iBAC+C,EAAA;AAC/C,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,MAAM,cAAc,iBAAiB,CAAA,CAAA;AAEhE,EAAO,OAAA,cAAA,CAAA;AACT,CAAA;AAEA,eAAsB,aAAgB,GAAA;AACpC,EAAO,OAAA,KAAA,CAAM,IAAK,CAAA,YAAA,CAAa,IAAK,EAAC,CAAE,CAAA,OAAA,CAAQ,CAAO,GAAA,KAAA,YAAA,CAAa,MAAO,CAAA,GAAG,CAAC,CAAA,CAAA;AAChF;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { rechargeApiRequest, getInternalSession } from '../utils/request.js';
2
+ import { encodePathSegment } from '../utils/url.js';
2
3
 
3
4
  async function getCharge(session, id, options) {
4
5
  if (id === void 0 || id === "") {
@@ -26,7 +27,7 @@ async function applyDiscountToCharge(session, id, discountCode) {
26
27
  }
27
28
  const { charge } = await rechargeApiRequest(
28
29
  "post",
29
- `/charges/${id}/apply_discount`,
30
+ `/charges/${encodePathSegment(id)}/apply_discount`,
30
31
  {
31
32
  data: { discount_code: discountCode }
32
33
  },
@@ -40,7 +41,7 @@ async function removeDiscountsFromCharge(session, id) {
40
41
  }
41
42
  const { charge } = await rechargeApiRequest(
42
43
  "post",
43
- `/charges/${id}/remove_discount`,
44
+ `/charges/${encodePathSegment(id)}/remove_discount`,
44
45
  {},
45
46
  getInternalSession(session, "removeDiscountsFromCharge")
46
47
  );
@@ -55,7 +56,7 @@ async function skipCharge(session, id, purchaseItemIds, query) {
55
56
  }
56
57
  const { charge } = await rechargeApiRequest(
57
58
  "post",
58
- `/charges/${id}/skip`,
59
+ `/charges/${encodePathSegment(id)}/skip`,
59
60
  {
60
61
  query,
61
62
  data: {
@@ -75,7 +76,7 @@ async function unskipCharge(session, id, purchaseItemIds, query) {
75
76
  }
76
77
  const { charge } = await rechargeApiRequest(
77
78
  "post",
78
- `/charges/${id}/unskip`,
79
+ `/charges/${encodePathSegment(id)}/unskip`,
79
80
  {
80
81
  query,
81
82
  data: {
@@ -92,7 +93,7 @@ async function processCharge(session, id) {
92
93
  }
93
94
  const { charge } = await rechargeApiRequest(
94
95
  "post",
95
- `/charges/${id}/process`,
96
+ `/charges/${encodePathSegment(id)}/process`,
96
97
  {},
97
98
  getInternalSession(session, "processCharge")
98
99
  );
@@ -104,7 +105,7 @@ async function rescheduleCharge(session, id, date) {
104
105
  }
105
106
  const { charge } = await rechargeApiRequest(
106
107
  "post",
107
- `/charges/${id}/change_next_charge_date`,
108
+ `/charges/${encodePathSegment(id)}/change_next_charge_date`,
108
109
  {
109
110
  data: { next_charge_date: date }
110
111
  },
@@ -1 +1 @@
1
- {"version":3,"file":"charge.js","sources":["../../../src/api/charge.ts"],"sourcesContent":["import {\n ChargeListParams,\n ChargeListResponse,\n ChargeResponse,\n GetChargeOptions,\n IsoDateString,\n Session,\n SkipChargeParams,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/* Retrieve a Charge using the charge_id. */\nexport async function getCharge(session: Session, id: number | string, options?: GetChargeOptions) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'get',\n `/charges`,\n { id, query: { include: options?.include } },\n getInternalSession(session, 'getCharge')\n );\n return charge;\n}\n\n/** Lists charges */\nexport function listCharges(session: Session, query?: ChargeListParams) {\n return rechargeApiRequest<ChargeListResponse>(\n 'get',\n `/charges`,\n { query },\n getInternalSession(session, 'listCharges')\n );\n}\n\n/**\n * You cannot add a Discount to an existing queued Charge if the Charge or the associated Address already has one.\n * If a Charge has a Discount and it gets updated, or a regeneration occurs, the Discount will be lost. Regeneration is a process that refreshes the Charge JSON with new data in the case of the Subscription or Address being updated.\n */\nexport async function applyDiscountToCharge(session: Session, id: number | string, discountCode: string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${id}/apply_discount`,\n {\n data: { discount_code: discountCode },\n },\n getInternalSession(session, 'applyDiscountToCharge')\n );\n return charge;\n}\n\n/**\n * Remove all Discounts from a Charge without destroying the Discount.\n * In most cases the Discount should be removed from the Address. When the Discount is removed from the Address, the Discount is also removed from any future Charges.\n * If the Discount is on the parent Address, you cannot remove it using charge_id.\n * When removing your Discount, it is preferable to pass the address_id so that the Discount stays removed if the Charge is regenerated. Only pass charge_id in edge cases in which there are two or more Charges on a parent Address and you only want to remove the Discount from one Charge.\n * If you pass both parameters, it will remove the Discount from the Address.\n */\nexport async function removeDiscountsFromCharge(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${id}/remove_discount`,\n {},\n getInternalSession(session, 'removeDiscountsFromCharge')\n );\n return charge;\n}\n\n/* Skip a Charge. */\nexport async function skipCharge(\n session: Session,\n id: number | string,\n purchaseItemIds: (string | number)[],\n query?: SkipChargeParams\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n if (purchaseItemIds === undefined || purchaseItemIds.length === 0) {\n throw new Error('Purchase item IDs are required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${id}/skip`,\n {\n query,\n data: {\n purchase_item_ids: purchaseItemIds.map(id => Number(id)),\n },\n },\n getInternalSession(session, 'skipCharge')\n );\n return charge;\n}\n\n/* Unskip a Charge. */\nexport async function unskipCharge(\n session: Session,\n id: number | string,\n purchaseItemIds: (string | number)[],\n query?: SkipChargeParams\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n if (purchaseItemIds === undefined || purchaseItemIds.length === 0) {\n throw new Error('Purchase item IDs are required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${id}/unskip`,\n {\n query,\n data: {\n purchase_item_ids: purchaseItemIds.map(id => Number(id)),\n },\n },\n getInternalSession(session, 'unskipCharge')\n );\n return charge;\n}\n\n/* Process a Charge. */\nexport async function processCharge(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${id}/process`,\n {},\n getInternalSession(session, 'processCharge')\n );\n return charge;\n}\n\n/* Reschedule all items associated with a Charge. */\nexport async function rescheduleCharge(session: Session, id: number | string, date: IsoDateString) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${id}/change_next_charge_date`,\n {\n data: { next_charge_date: date },\n },\n getInternalSession(session, 'rescheduleCharge')\n );\n return charge;\n}\n"],"names":["id"],"mappings":";;AAYsB,eAAA,SAAA,CAAU,OAAkB,EAAA,EAAA,EAAqB,OAA4B,EAAA;AACjG,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,MAAM,kBAAA;AAAA,IACvB,KAAA;AAAA,IACA,CAAA,QAAA,CAAA;AAAA,IACA,EAAE,EAAI,EAAA,KAAA,EAAO,EAAE,OAAS,EAAA,OAAA,EAAS,SAAU,EAAA;AAAA,IAC3C,kBAAA,CAAmB,SAAS,WAAW,CAAA;AAAA,GACzC,CAAA;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAGgB,SAAA,WAAA,CAAY,SAAkB,KAA0B,EAAA;AACtE,EAAO,OAAA,kBAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,QAAA,CAAA;AAAA,IACA,EAAE,KAAM,EAAA;AAAA,IACR,kBAAA,CAAmB,SAAS,aAAa,CAAA;AAAA,GAC3C,CAAA;AACF,CA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a,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,MAAM,kBAAA;AAAA,IACvB,MAAA;AAAA,IACA,YAAY,EAAE,CAAA,QAAA,CAAA;AAAA,IACd,EAAC;AAAA,IACD,kBAAA,CAAmB,SAAS,eAAe,CAAA;AAAA,GAC7C,CAAA;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAGsB,eAAA,gBAAA,CAAiB,OAAkB,EAAA,EAAA,EAAqB,IAAqB,EAAA;AACjG,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,MAAM,kBAAA;AAAA,IACvB,MAAA;AAAA,IACA,YAAY,EAAE,CAAA,wBAAA,CAAA;AAAA,IACd;AAAA,MACE,IAAA,EAAM,EAAE,gBAAA,EAAkB,IAAK,EAAA;AAAA,KACjC;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"charge.js","sources":["../../../src/api/charge.ts"],"sourcesContent":["import {\n ChargeListParams,\n ChargeListResponse,\n ChargeResponse,\n GetChargeOptions,\n IsoDateString,\n Session,\n SkipChargeParams,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\n/* Retrieve a Charge using the charge_id. */\nexport async function getCharge(session: Session, id: number | string, options?: GetChargeOptions) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'get',\n `/charges`,\n { id, query: { include: options?.include } },\n getInternalSession(session, 'getCharge')\n );\n return charge;\n}\n\n/** Lists charges */\nexport function listCharges(session: Session, query?: ChargeListParams) {\n return rechargeApiRequest<ChargeListResponse>(\n 'get',\n `/charges`,\n { query },\n getInternalSession(session, 'listCharges')\n );\n}\n\n/**\n * You cannot add a Discount to an existing queued Charge if the Charge or the associated Address already has one.\n * If a Charge has a Discount and it gets updated, or a regeneration occurs, the Discount will be lost. Regeneration is a process that refreshes the Charge JSON with new data in the case of the Subscription or Address being updated.\n */\nexport async function applyDiscountToCharge(session: Session, id: number | string, discountCode: string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${encodePathSegment(id)}/apply_discount`,\n {\n data: { discount_code: discountCode },\n },\n getInternalSession(session, 'applyDiscountToCharge')\n );\n return charge;\n}\n\n/**\n * Remove all Discounts from a Charge without destroying the Discount.\n * In most cases the Discount should be removed from the Address. When the Discount is removed from the Address, the Discount is also removed from any future Charges.\n * If the Discount is on the parent Address, you cannot remove it using charge_id.\n * When removing your Discount, it is preferable to pass the address_id so that the Discount stays removed if the Charge is regenerated. Only pass charge_id in edge cases in which there are two or more Charges on a parent Address and you only want to remove the Discount from one Charge.\n * If you pass both parameters, it will remove the Discount from the Address.\n */\nexport async function removeDiscountsFromCharge(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${encodePathSegment(id)}/remove_discount`,\n {},\n getInternalSession(session, 'removeDiscountsFromCharge')\n );\n return charge;\n}\n\n/* Skip a Charge. */\nexport async function skipCharge(\n session: Session,\n id: number | string,\n purchaseItemIds: (string | number)[],\n query?: SkipChargeParams\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n if (purchaseItemIds === undefined || purchaseItemIds.length === 0) {\n throw new Error('Purchase item IDs are required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${encodePathSegment(id)}/skip`,\n {\n query,\n data: {\n purchase_item_ids: purchaseItemIds.map(id => Number(id)),\n },\n },\n getInternalSession(session, 'skipCharge')\n );\n return charge;\n}\n\n/* Unskip a Charge. */\nexport async function unskipCharge(\n session: Session,\n id: number | string,\n purchaseItemIds: (string | number)[],\n query?: SkipChargeParams\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n if (purchaseItemIds === undefined || purchaseItemIds.length === 0) {\n throw new Error('Purchase item IDs are required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${encodePathSegment(id)}/unskip`,\n {\n query,\n data: {\n purchase_item_ids: purchaseItemIds.map(id => Number(id)),\n },\n },\n getInternalSession(session, 'unskipCharge')\n );\n return charge;\n}\n\n/* Process a Charge. */\nexport async function processCharge(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${encodePathSegment(id)}/process`,\n {},\n getInternalSession(session, 'processCharge')\n );\n return charge;\n}\n\n/* Reschedule all items associated with a Charge. */\nexport async function rescheduleCharge(session: Session, id: number | string, date: IsoDateString) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/charges/${encodePathSegment(id)}/change_next_charge_date`,\n {\n data: { next_charge_date: date },\n },\n getInternalSession(session, 'rescheduleCharge')\n );\n return charge;\n}\n"],"names":["id"],"mappings":";;;AAasB,eAAA,SAAA,CAAU,OAAkB,EAAA,EAAA,EAAqB,OAA4B,EAAA;AACjG,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,MAAM,kBAAA;AAAA,IACvB,KAAA;AAAA,IACA,CAAA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A,EAAE,CAAC,CAAA,wBAAA,CAAA;AAAA,IACjC;AAAA,MACE,IAAA,EAAM,EAAE,gBAAA,EAAkB,IAAK,EAAA;AAAA,KACjC;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { rechargeApiRequest, getInternalSession } from '../utils/request.js';
2
+ import { encodePathSegment } from '../utils/url.js';
2
3
  import { updateCustomer } from './customer.js';
3
4
 
4
5
  async function getCreditSummary(session, options) {
@@ -8,7 +9,7 @@ async function getCreditSummary(session, options) {
8
9
  }
9
10
  const { credit_summary } = await rechargeApiRequest(
10
11
  "get",
11
- `/customers/${id}/credit_summary`,
12
+ `/customers/${encodePathSegment(id)}/credit_summary`,
12
13
  {
13
14
  query: { include: options?.include, presentment_currency_code: options?.presentment_currency_code }
14
15
  },
@@ -32,11 +33,12 @@ async function listCreditAccounts(session, query) {
32
33
  if (!customer_id) {
33
34
  throw new Error("Not logged in.");
34
35
  }
36
+ const { customer_id: _ignoredCustomerId, ...safeQuery } = query ?? {};
35
37
  const response = await rechargeApiRequest(
36
38
  "get",
37
39
  "/credit_accounts",
38
40
  {
39
- query: { customer_id, ...query }
41
+ query: { ...safeQuery, customer_id }
40
42
  },
41
43
  getInternalSession(session, "listCreditAccounts")
42
44
  );
@@ -1 +1 @@
1
- {"version":3,"file":"credit.js","sources":["../../../src/api/credit.ts"],"sourcesContent":["import {\n ApplyCreditOptions,\n CreditAccountListParams,\n CreditAccountsResponse,\n Customer,\n CustomerCreditSummary,\n GetCreditSummaryOptions,\n Session,\n UpdateCustomerRequest,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { updateCustomer } from './customer';\n\nexport async function getCreditSummary(\n session: Session,\n options?: GetCreditSummaryOptions\n): Promise<CustomerCreditSummary> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { credit_summary } = await rechargeApiRequest<{ credit_summary: CustomerCreditSummary }>(\n 'get',\n `/customers/${id}/credit_summary`,\n {\n query: { include: options?.include, presentment_currency_code: options?.presentment_currency_code },\n },\n getInternalSession(session, 'getCreditSummary')\n );\n return credit_summary;\n}\n\nexport function setApplyCreditsToNextCharge(session: Session, { recurring }: ApplyCreditOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const updateOptions: UpdateCustomerRequest = {};\n if (recurring !== undefined) {\n updateOptions.apply_credit_to_next_recurring_charge = recurring;\n }\n return updateCustomer(getInternalSession(session, 'setApplyCreditsToNextCharge'), updateOptions);\n}\n\nexport async function listCreditAccounts(\n session: Session,\n query?: CreditAccountListParams\n): Promise<CreditAccountsResponse> {\n const customer_id = session.customerId;\n if (!customer_id) {\n throw new Error('Not logged in.');\n }\n const response = await rechargeApiRequest<CreditAccountsResponse>(\n 'get',\n '/credit_accounts',\n {\n query: { customer_id, ...query },\n },\n getInternalSession(session, 'listCreditAccounts')\n );\n return response;\n}\n"],"names":[],"mappings":";;;AAasB,eAAA,gBAAA,CACpB,SACA,OACgC,EAAA;AAChC,EAAA,MAAM,KAAK,OAAQ,CAAA,UAAA,CAAA;AACnB,EAAA,IAAI,CAAC,EAAI,EAAA;AACP,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,cAAe,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC/B,KAAA;AAAA,IACA,cAAc,EAAE,CAAA,eAAA,CAAA;AAAA,IAChB;AAAA,MACE,OAAO,EAAE,OAAA,EAAS,SAAS,OAAS,EAAA,yBAAA,EAA2B,SAAS,yBAA0B,EAAA;AAAA,KACpG;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,cAAA,CAAA;AACT,CAAA;AAEO,SAAS,2BAA4B,CAAA,OAAA,EAAkB,EAAE,SAAA,EAAoD,EAAA;AAClH,EAAA,MAAM,KAAK,OAAQ,CAAA,UAAA,CAAA;AACnB,EAAA,IAAI,CAAC,EAAI,EAAA;AACP,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAA,MAAM,gBAAuC,EAAC,CAAA;AAC9C,EAAA,IAAI,cAAc,KAAW,CAAA,EAAA;AAC3B,IAAA,aAAA,CAAc,qCAAwC,GAAA,SAAA,CAAA;AAAA,GACxD;AACA,EAAA,OAAO,cAAe,CAAA,kBAAA,CAAmB,OAAS,EAAA,6BAA6B,GAAG,aAAa,CAAA,CAAA;AACjG,CAAA;AAEsB,eAAA,kBAAA,CACpB,SACA,KACiC,EAAA;AACjC,EAAA,MAAM,cAAc,OAAQ,CAAA,UAAA,CAAA;AAC5B,EAAA,IAAI,CAAC,WAAa,EAAA;AAChB,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAA,MAAM,WAAW,MAAM,kBAAA;AAAA,IACrB,KAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA,MACE,KAAO,EAAA,EAAE,WAAa,EAAA,GAAG,KAAM,EAAA;AAAA,KACjC;AAAA,IACA,kBAAA,CAAmB,SAAS,oBAAoB,CAAA;AAAA,GAClD,CAAA;AACA,EAAO,OAAA,QAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"credit.js","sources":["../../../src/api/credit.ts"],"sourcesContent":["import {\n ApplyCreditOptions,\n CreditAccountListParams,\n CreditAccountsResponse,\n Customer,\n CustomerCreditSummary,\n GetCreditSummaryOptions,\n Session,\n UpdateCustomerRequest,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport { updateCustomer } from './customer';\n\nexport async function getCreditSummary(\n session: Session,\n options?: GetCreditSummaryOptions\n): Promise<CustomerCreditSummary> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { credit_summary } = await rechargeApiRequest<{ credit_summary: CustomerCreditSummary }>(\n 'get',\n `/customers/${encodePathSegment(id)}/credit_summary`,\n {\n query: { include: options?.include, presentment_currency_code: options?.presentment_currency_code },\n },\n getInternalSession(session, 'getCreditSummary')\n );\n return credit_summary;\n}\n\nexport function setApplyCreditsToNextCharge(session: Session, { recurring }: ApplyCreditOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const updateOptions: UpdateCustomerRequest = {};\n if (recurring !== undefined) {\n updateOptions.apply_credit_to_next_recurring_charge = recurring;\n }\n return updateCustomer(getInternalSession(session, 'setApplyCreditsToNextCharge'), updateOptions);\n}\n\nexport async function listCreditAccounts(\n session: Session,\n query?: CreditAccountListParams\n): Promise<CreditAccountsResponse> {\n const customer_id = session.customerId;\n if (!customer_id) {\n throw new Error('Not logged in.');\n }\n // Strip any caller-supplied `customer_id` (not part of the public\n // CreditAccountListParams type) and set the session-derived value last so it\n // can't be overridden by a runtime caller (H1-3884988 / SEC-4002).\n const { customer_id: _ignoredCustomerId, ...safeQuery } = (query ?? {}) as CreditAccountListParams & {\n customer_id?: unknown;\n };\n const response = await rechargeApiRequest<CreditAccountsResponse>(\n 'get',\n '/credit_accounts',\n {\n query: { ...safeQuery, customer_id },\n },\n getInternalSession(session, 'listCreditAccounts')\n );\n return response;\n}\n"],"names":[],"mappings":";;;;AAcsB,eAAA,gBAAA,CACpB,SACA,OACgC,EAAA;AAChC,EAAA,MAAM,KAAK,OAAQ,CAAA,UAAA,CAAA;AACnB,EAAA,IAAI,CAAC,EAAI,EAAA;AACP,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,cAAe,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC/B,KAAA;AAAA,IACA,CAAA,WAAA,EAAc,iBAAkB,CAAA,EAAE,CAAC,CAAA,eAAA,CAAA;AAAA,IACnC;AAAA,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ApiRequest, getInternalSession } from '../utils/request.js';
2
+ import { encodePathSegment } from '../utils/url.js';
2
3
 
3
4
  async function getCustomer(session, options) {
4
5
  const id = session.customerId;
@@ -36,7 +37,7 @@ async function getDeliverySchedule(session, query) {
36
37
  }
37
38
  const { deliveries } = await rechargeApiRequest(
38
39
  "get",
39
- `/customers/${id}/delivery_schedule`,
40
+ `/customers/${encodePathSegment(id)}/delivery_schedule`,
40
41
  { query },
41
42
  getInternalSession(session, "getDeliverySchedule")
42
43
  );
@@ -95,13 +96,13 @@ async function sendCustomerNotification(session, notification, options) {
95
96
  if (!customerId) {
96
97
  throw new Error("Not logged in.");
97
98
  }
98
- const data = customerNotificationMap[notification];
99
- if (!data) {
99
+ if (!Object.prototype.hasOwnProperty.call(customerNotificationMap, notification)) {
100
100
  throw new Error("Notification not supported.");
101
101
  }
102
+ const data = customerNotificationMap[notification];
102
103
  return rechargeApiRequest(
103
104
  "post",
104
- `/customers/${customerId}/notifications`,
105
+ `/customers/${encodePathSegment(customerId)}/notifications`,
105
106
  {
106
107
  data: {
107
108
  ...data,
@@ -1 +1 @@
1
- {"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import {\n Customer,\n CustomerCreditSummary,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerNotification,\n CustomerNotificationOptions,\n CustomerNotificationTemplate,\n CustomerNotificationType,\n CustomerPortalAccessOptions,\n CustomerPortalAccessResponse,\n Delivery,\n GetCreditSummaryOptions,\n GetCustomerOptions,\n Session,\n UpdateCustomerRequest,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCustomer')\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n getInternalSession(session, 'updateCustomer')\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${id}/delivery_schedule`,\n { query },\n getInternalSession(session, 'getDeliverySchedule')\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(\n session: Session,\n query?: CustomerPortalAccessOptions\n): Promise<CustomerPortalAccessResponse> {\n return rechargeApiRequest<CustomerPortalAccessResponse>(\n 'get',\n '/portal_access',\n { query },\n getInternalSession(session, 'getCustomerPortalAccess')\n );\n}\n\nexport async function getActiveChurnLandingPageURL(\n session: Session,\n subscriptionId: string | number,\n redirectURL: string\n): Promise<string> {\n if (subscriptionId === undefined || subscriptionId === '') {\n throw new Error('Subscription ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getActiveChurnLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/subscriptions/${subscriptionId}/cancel?token=${temp_token}&subscription=${subscriptionId}&redirect_to=${redirectURL}`;\n}\n\nexport async function getFailedPaymentMethodRecoveryLandingPageURL(session: Session): Promise<string> {\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getFailedPaymentMethodRecoveryLandingPageURL')\n );\n return `${base_url.replace('portal', 'pages')}account/payment-methods?token=${temp_token}&hash=${customer_hash}`;\n}\n\nexport async function getGiftRedemptionLandingPageURL(\n session: Session,\n giftId: string | number,\n redirectURL: string\n): Promise<string> {\n if (giftId === undefined || giftId === '') {\n throw new Error('Gift ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getGiftRedemptionLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/gifts/${giftId}?token=${temp_token}&redirect_to=${redirectURL}`;\n}\n\nconst customerNotificationMap: Record<\n CustomerNotification,\n { type: CustomerNotificationType; template_type: CustomerNotificationTemplate }\n> = {\n SHOPIFY_UPDATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_update_payment_information',\n },\n SHOPIFY_MIGRATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_migrate_payment_information',\n },\n};\n\nexport async function sendCustomerNotification<T extends CustomerNotification>(\n session: Session,\n notification: CustomerNotification,\n options?: CustomerNotificationOptions<T>\n): Promise<void> {\n const customerId = session.customerId;\n if (!customerId) {\n throw new Error('Not logged in.');\n }\n const data = customerNotificationMap[notification];\n if (!data) {\n throw new Error('Notification not supported.');\n }\n return rechargeApiRequest<void>(\n 'post',\n `/customers/${customerId}/notifications`,\n {\n data: {\n ...data,\n template_vars: options,\n },\n },\n getInternalSession(session, 'sendCustomerNotification')\n );\n}\n\n/** @deprecated Use `getCreditSummary` on credit instead */\nexport async function getCreditSummary(\n session: Session,\n options?: GetCreditSummaryOptions\n): Promise<CustomerCreditSummary> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { credit_summary } = await rechargeApiRequest<{ credit_summary: CustomerCreditSummary }>(\n 'get',\n `/customers/${id}/credit_summary`,\n {\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCreditSummary')\n );\n return credit_summary;\n}\n"],"names":[],"mappings":";;AAmBsB,eAAA,WAAA,CAAY,SAAkB,OAAiD,EAAA;AACnG,EAAA,MAAM,KAAK,OAAQ,CAAA,UAAA,CAAA;AACnB,EAAA,IAAI,CAAC,EAAI,EAAA;AACP,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAA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AA;AACF;;;;"}
1
+ {"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import {\n Customer,\n CustomerCreditSummary,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerNotification,\n CustomerNotificationOptions,\n CustomerNotificationTemplate,\n CustomerNotificationType,\n CustomerPortalAccessOptions,\n CustomerPortalAccessResponse,\n Delivery,\n GetCreditSummaryOptions,\n GetCustomerOptions,\n Session,\n UpdateCustomerRequest,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCustomer')\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n getInternalSession(session, 'updateCustomer')\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${encodePathSegment(id)}/delivery_schedule`,\n { query },\n getInternalSession(session, 'getDeliverySchedule')\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(\n session: Session,\n query?: CustomerPortalAccessOptions\n): Promise<CustomerPortalAccessResponse> {\n return rechargeApiRequest<CustomerPortalAccessResponse>(\n 'get',\n '/portal_access',\n { query },\n getInternalSession(session, 'getCustomerPortalAccess')\n );\n}\n\nexport async function getActiveChurnLandingPageURL(\n session: Session,\n subscriptionId: string | number,\n redirectURL: string\n): Promise<string> {\n if (subscriptionId === undefined || subscriptionId === '') {\n throw new Error('Subscription ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getActiveChurnLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/subscriptions/${subscriptionId}/cancel?token=${temp_token}&subscription=${subscriptionId}&redirect_to=${redirectURL}`;\n}\n\nexport async function getFailedPaymentMethodRecoveryLandingPageURL(session: Session): Promise<string> {\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getFailedPaymentMethodRecoveryLandingPageURL')\n );\n return `${base_url.replace('portal', 'pages')}account/payment-methods?token=${temp_token}&hash=${customer_hash}`;\n}\n\nexport async function getGiftRedemptionLandingPageURL(\n session: Session,\n giftId: string | number,\n redirectURL: string\n): Promise<string> {\n if (giftId === undefined || giftId === '') {\n throw new Error('Gift ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getGiftRedemptionLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/gifts/${giftId}?token=${temp_token}&redirect_to=${redirectURL}`;\n}\n\nconst customerNotificationMap: Record<\n CustomerNotification,\n { type: CustomerNotificationType; template_type: CustomerNotificationTemplate }\n> = {\n SHOPIFY_UPDATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_update_payment_information',\n },\n SHOPIFY_MIGRATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_migrate_payment_information',\n },\n};\n\nexport async function sendCustomerNotification<T extends CustomerNotification>(\n session: Session,\n notification: CustomerNotification,\n options?: CustomerNotificationOptions<T>\n): Promise<void> {\n const customerId = session.customerId;\n if (!customerId) {\n throw new Error('Not logged in.');\n }\n // Own-property check: a plain-object lookup resolves inherited keys such as\n // `__proto__`/`constructor` to truthy prototype values, bypassing this guard\n // (H1-3889216 / SEC-4002; same class as the CDN/bundle maps fixed in SEC-3996).\n if (!Object.prototype.hasOwnProperty.call(customerNotificationMap, notification)) {\n throw new Error('Notification not supported.');\n }\n const data = customerNotificationMap[notification];\n return rechargeApiRequest<void>(\n 'post',\n `/customers/${encodePathSegment(customerId)}/notifications`,\n {\n data: {\n ...data,\n template_vars: options,\n },\n },\n getInternalSession(session, 'sendCustomerNotification')\n );\n}\n\n/** @deprecated Use `getCreditSummary` on credit instead */\nexport async function getCreditSummary(\n session: Session,\n options?: GetCreditSummaryOptions\n): Promise<CustomerCreditSummary> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { credit_summary } = await rechargeApiRequest<{ credit_summary: CustomerCreditSummary }>(\n 'get',\n `/customers/${encodePathSegment(id)}/credit_summary`,\n {\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCreditSummary')\n );\n return credit_summary;\n}\n"],"names":[],"mappings":";;;AAoBsB,eAAA,WAAA,CAAY,SAAkB,OAAiD,EAAA;AACnG,EAAA,MAAM,KAAK,OAAQ,CAAA,UAAA,CAAA;AACnB,EAAA,IAAI,CAAC,EAAI,EAAA;AACP,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,QAAS,EAAA,GAAI,MAAM,kBAAA;AAAA,IACzB,KAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,KAAO,EAAA,EAAE,OAAS,EAAA,OAAA,EAAS,OAAQ,EAAA;AAAA,KACrC;AAAA,IACA,kBAAA,CAAmB,SAAS,aAAa,CAAA;AAAA,GAC3C,CAAA;AACA,EAAO,OAAA,QAAA,CAAA;AACT,CAAA;AAEsB,eAAA,cAAA,CAAe,SAAkB,aAAyD,EAAA;AAC9G,EAAA,MAAM,KAAK,OAAQ,CAAA,UAAA,CAAA;AACnB,EAAA,IAAI,CAAC,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BAA6B,EAAA;AAAA,IAC3B,IAAM,EAAA,OAAA;AAAA,IACN,aAAe,EAAA,oCAAA;AAAA,GACjB;AAAA,EACA,4BAA8B,EAAA;AAAA,IAC5B,IAAM,EAAA,OAAA;AAAA,IACN,aAAe,EAAA,qCAAA;AAAA,GACjB;AACF,CAAA,CAAA;AAEsB,eAAA,wBAAA,CACpB,OACA,EAAA,YAAA,EACA,OACe,EAAA;AACf,EAAA,MAAM,aAAa,OAAQ,CAAA,UAAA,CAAA;AAC3B,EAAA,IAAI,CAAC,UAAY,EAAA;AACf,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AAIA,EAAA,IAAI,CAAC,MAAO,CAAA,SAAA,CAAU,eAAe,IAAK,CAAA,uBAAA,EAAyB,YAAY,CAAG,EAAA;AAChF,IAAM,MAAA,IAAI,MAAM,6BAA6B,CAAA,CAAA;AAAA,GAC/C;AACA,EAAM,MAAA,IAAA,GAAO,wBAAwB,YAAY,CAAA,CAAA;AACjD,EAAO,OAAA,kBAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,WAAA,EAAc,iBAAkB,CAAA,UAAU,CAAC,CAAA,cAAA,CAAA;AAAA,IAC3C;AAAA,MACE,IAAM,EAAA;AAAA,QACJ,GAAG,IAAA;AAAA,QACH,aAAe,EAAA,OAAA;AAAA,OACjB;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACF;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { rechargeApiRequest, getInternalSession } from '../utils/request.js';
2
+ import { encodePathSegment } from '../utils/url.js';
2
3
 
3
4
  async function getCustomerSurveyReasons(session, customerId, subscriptionId) {
4
5
  const customerSurveysReasonsResponse = await rechargeApiRequest(
@@ -12,7 +13,7 @@ async function getCustomerSurveyReasons(session, customerId, subscriptionId) {
12
13
  async function getCustomerSurveyOffers(session, customerId, customerSurveyId, responseId) {
13
14
  const customerSurveysOffersResponse = await rechargeApiRequest(
14
15
  "post",
15
- `/customer_surveys/${customerSurveyId}/customer_response`,
16
+ `/customer_surveys/${encodePathSegment(customerSurveyId)}/customer_response`,
16
17
  { data: { customer_id: customerId, response_id: responseId } },
17
18
  getInternalSession(session, "getCustomerSurveyOffers")
18
19
  );
@@ -1 +1 @@
1
- {"version":3,"file":"customerSurveys.js","sources":["../../../src/api/customerSurveys.ts"],"sourcesContent":["import {\n Session,\n CustomerSurveyOffersResponse,\n CustomerSurveyReasonsResponse,\n CustomerSurveyOfferParams,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomerSurveyReasons(session: Session, customerId: number, subscriptionId: number) {\n const customerSurveysReasonsResponse = await rechargeApiRequest<CustomerSurveyReasonsResponse>(\n 'post',\n `/customer_surveys/cancellation_prevention`,\n { data: { customer_id: customerId, subscription_id: subscriptionId } },\n getInternalSession(session, 'getCustomerSurveyReasons')\n );\n return customerSurveysReasonsResponse;\n}\n\nexport async function getCustomerSurveyOffers(\n session: Session,\n customerId: number,\n customerSurveyId: number,\n responseId: number\n) {\n const customerSurveysOffersResponse = await rechargeApiRequest<CustomerSurveyOffersResponse>(\n 'post',\n `/customer_surveys/${customerSurveyId}/customer_response`,\n { data: { customer_id: customerId, response_id: responseId } },\n getInternalSession(session, 'getCustomerSurveyOffers')\n );\n return customerSurveysOffersResponse;\n}\n\nexport async function claimOfferCustomerSurvey(session: Session, payload: CustomerSurveyOfferParams) {\n await rechargeApiRequest(\n 'post',\n `/offers/claim`,\n { data: payload },\n getInternalSession(session, 'claimOfferCustomerSurvey')\n );\n return {};\n}\n"],"names":[],"mappings":";;AAQsB,eAAA,wBAAA,CAAyB,OAAkB,EAAA,UAAA,EAAoB,cAAwB,EAAA;AAC3G,EAAA,MAAM,iCAAiC,MAAM,kBAAA;AAAA,IAC3C,MAAA;AAAA,IACA,CAAA,yCAAA,CAAA;AAAA,IACA,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,eAAA,EAAiB,gBAAiB,EAAA;AAAA,IACrE,kBAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACA,EAAO,OAAA,8BAAA,CAAA;AACT,CAAA;AAEA,eAAsB,uBACpB,CAAA,OAAA,EACA,UACA,EAAA,gBAAA,EACA,UACA,EAAA;AACA,EAAA,MAAM,gCAAgC,MAAM,kBAAA;AAAA,IAC1C,MAAA;AAAA,IACA,qBAAqB,gBAAgB,CAAA,kBAAA,CAAA;AAAA,IACrC,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,WAAA,EAAa,YAAa,EAAA;AAAA,IAC7D,kBAAA,CAAmB,SAAS,yBAAyB,CAAA;AAAA,GACvD,CAAA;AACA,EAAO,OAAA,6BAAA,CAAA;AACT,CAAA;AAEsB,eAAA,wBAAA,CAAyB,SAAkB,OAAoC,EAAA;AACnG,EAAM,MAAA,kBAAA;AAAA,IACJ,MAAA;AAAA,IACA,CAAA,aAAA,CAAA;AAAA,IACA,EAAE,MAAM,OAAQ,EAAA;AAAA,IAChB,kBAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACA,EAAA,OAAO,EAAC,CAAA;AACV;;;;"}
1
+ {"version":3,"file":"customerSurveys.js","sources":["../../../src/api/customerSurveys.ts"],"sourcesContent":["import {\n Session,\n CustomerSurveyOffersResponse,\n CustomerSurveyReasonsResponse,\n CustomerSurveyOfferParams,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getCustomerSurveyReasons(session: Session, customerId: number, subscriptionId: number) {\n const customerSurveysReasonsResponse = await rechargeApiRequest<CustomerSurveyReasonsResponse>(\n 'post',\n `/customer_surveys/cancellation_prevention`,\n { data: { customer_id: customerId, subscription_id: subscriptionId } },\n getInternalSession(session, 'getCustomerSurveyReasons')\n );\n return customerSurveysReasonsResponse;\n}\n\nexport async function getCustomerSurveyOffers(\n session: Session,\n customerId: number,\n customerSurveyId: number,\n responseId: number\n) {\n const customerSurveysOffersResponse = await rechargeApiRequest<CustomerSurveyOffersResponse>(\n 'post',\n `/customer_surveys/${encodePathSegment(customerSurveyId)}/customer_response`,\n { data: { customer_id: customerId, response_id: responseId } },\n getInternalSession(session, 'getCustomerSurveyOffers')\n );\n return customerSurveysOffersResponse;\n}\n\nexport async function claimOfferCustomerSurvey(session: Session, payload: CustomerSurveyOfferParams) {\n await rechargeApiRequest(\n 'post',\n `/offers/claim`,\n { data: payload },\n getInternalSession(session, 'claimOfferCustomerSurvey')\n );\n return {};\n}\n"],"names":[],"mappings":";;;AASsB,eAAA,wBAAA,CAAyB,OAAkB,EAAA,UAAA,EAAoB,cAAwB,EAAA;AAC3G,EAAA,MAAM,iCAAiC,MAAM,kBAAA;AAAA,IAC3C,MAAA;AAAA,IACA,CAAA,yCAAA,CAAA;AAAA,IACA,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,eAAA,EAAiB,gBAAiB,EAAA;AAAA,IACrE,kBAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACA,EAAO,OAAA,8BAAA,CAAA;AACT,CAAA;AAEA,eAAsB,uBACpB,CAAA,OAAA,EACA,UACA,EAAA,gBAAA,EACA,UACA,EAAA;AACA,EAAA,MAAM,gCAAgC,MAAM,kBAAA;AAAA,IAC1C,MAAA;AAAA,IACA,CAAA,kBAAA,EAAqB,iBAAkB,CAAA,gBAAgB,CAAC,CAAA,kBAAA,CAAA;AAAA,IACxD,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,WAAA,EAAa,YAAa,EAAA;AAAA,IAC7D,kBAAA,CAAmB,SAAS,yBAAyB,CAAA;AAAA,GACvD,CAAA;AACA,EAAO,OAAA,6BAAA,CAAA;AACT,CAAA;AAEsB,eAAA,wBAAA,CAAyB,SAAkB,OAAoC,EAAA;AACnG,EAAM,MAAA,kBAAA;AAAA,IACJ,MAAA;AAAA,IACA,CAAA,aAAA,CAAA;AAAA,IACA,EAAE,MAAM,OAAQ,EAAA;AAAA,IAChB,kBAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACA,EAAA,OAAO,EAAC,CAAA;AACV;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { rechargeApiRequest, getInternalSession } from '../utils/request.js';
2
+ import { encodePathSegment } from '../utils/url.js';
2
3
 
3
4
  async function getMembership(session, id) {
4
5
  if (id === void 0 || id === "") {
@@ -26,7 +27,7 @@ async function cancelMembership(session, id, cancelRequest) {
26
27
  }
27
28
  const { membership } = await rechargeApiRequest(
28
29
  "post",
29
- `/memberships/${id}/cancel`,
30
+ `/memberships/${encodePathSegment(id)}/cancel`,
30
31
  {
31
32
  data: cancelRequest
32
33
  },
@@ -40,7 +41,7 @@ async function activateMembership(session, id, activateRequest) {
40
41
  }
41
42
  const { membership } = await rechargeApiRequest(
42
43
  "post",
43
- `/memberships/${id}/activate`,
44
+ `/memberships/${encodePathSegment(id)}/activate`,
44
45
  {
45
46
  data: activateRequest
46
47
  },
@@ -54,7 +55,7 @@ async function changeMembership(session, id, changeRequest) {
54
55
  }
55
56
  const { membership } = await rechargeApiRequest(
56
57
  "post",
57
- `/memberships/${id}/change`,
58
+ `/memberships/${encodePathSegment(id)}/change`,
58
59
  {
59
60
  data: changeRequest
60
61
  },
@@ -1 +1 @@
1
- {"version":3,"file":"membership.js","sources":["../../../src/api/membership.ts"],"sourcesContent":["import {\n ActivateMembershipRequest,\n CancelMembershipRequest,\n ChangeMembershipRequest,\n MembershipListParams,\n MembershipListResponse,\n MembershipResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/** @internal Retrieves membership information for passed in id */\nexport async function getMembership(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'get',\n `/memberships`,\n { id },\n getInternalSession(session, 'getMembership')\n );\n return membership;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMemberships(session: Session, query?: MembershipListParams) {\n return rechargeApiRequest<MembershipListResponse>(\n 'get',\n `/memberships`,\n { query },\n getInternalSession(session, 'listMemberships')\n );\n}\n\n/** @internal Cancels a membership */\nexport async function cancelMembership(session: Session, id: string | number, cancelRequest: CancelMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${id}/cancel`,\n {\n data: cancelRequest,\n },\n getInternalSession(session, 'cancelMembership')\n );\n return membership;\n}\n\n/** @internal Activates a membership */\nexport async function activateMembership(\n session: Session,\n id: string | number,\n activateRequest: ActivateMembershipRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${id}/activate`,\n {\n data: activateRequest,\n },\n getInternalSession(session, 'activateMembership')\n );\n return membership;\n}\n\n/** @internal changes a membership program/product*/\nexport async function changeMembership(session: Session, id: string | number, changeRequest: ChangeMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${id}/change`,\n {\n data: changeRequest,\n },\n getInternalSession(session, 'changeMembership')\n );\n return membership;\n}\n"],"names":[],"mappings":";;AAYsB,eAAA,aAAA,CAAc,SAAkB,EAAqB,EAAA;AACzE,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,UAAW,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC3B,KAAA;AAAA,IACA,CAAA,YAAA,CAAA;AAAA,IACA,EAAE,EAAG,EAAA;AAAA,IACL,kBAAA,CAAmB,SAAS,eAAe,CAAA;AAAA,GAC7C,CAAA;AACA,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EAAA,EAAA,EAAqB,aAAwC,EAAA;AACpH,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,UAAW,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC3B,MAAA;AAAA,IACA,gBAAgB,EAAE,CAAA,OAAA,CAAA;AAAA,IAClB;AAAA,MACE,IAAM,EAAA,aAAA;AAAA,KACR;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,UAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"membership.js","sources":["../../../src/api/membership.ts"],"sourcesContent":["import {\n ActivateMembershipRequest,\n CancelMembershipRequest,\n ChangeMembershipRequest,\n MembershipListParams,\n MembershipListResponse,\n MembershipResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\n/** @internal Retrieves membership information for passed in id */\nexport async function getMembership(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'get',\n `/memberships`,\n { id },\n getInternalSession(session, 'getMembership')\n );\n return membership;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMemberships(session: Session, query?: MembershipListParams) {\n return rechargeApiRequest<MembershipListResponse>(\n 'get',\n `/memberships`,\n { query },\n getInternalSession(session, 'listMemberships')\n );\n}\n\n/** @internal Cancels a membership */\nexport async function cancelMembership(session: Session, id: string | number, cancelRequest: CancelMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/cancel`,\n {\n data: cancelRequest,\n },\n getInternalSession(session, 'cancelMembership')\n );\n return membership;\n}\n\n/** @internal Activates a membership */\nexport async function activateMembership(\n session: Session,\n id: string | number,\n activateRequest: ActivateMembershipRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/activate`,\n {\n data: activateRequest,\n },\n getInternalSession(session, 'activateMembership')\n );\n return membership;\n}\n\n/** @internal changes a membership program/product*/\nexport async function changeMembership(session: Session, id: string | number, changeRequest: ChangeMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/change`,\n {\n data: changeRequest,\n },\n getInternalSession(session, 'changeMembership')\n );\n return membership;\n}\n"],"names":[],"mappings":";;;AAasB,eAAA,aAAA,CAAc,SAAkB,EAAqB,EAAA;AACzE,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,UAAW,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC3B,KAAA;AAAA,IACA,CAAA,YAAA,CAAA;AAAA,IACA,EAAE,EAAG,EAAA;AAAA,IACL,kBAAA,CAAmB,SAAS,eAAe,CAAA;AAAA,GAC7C,CAAA;AACA,EAAO,OAAA,UAAA,CAAA;AACT,CAAA;AAGgB,SAAA,eAAA,CAAgB,SAAkB,KAA8B,EAAA;AAC9E,EAAO,OAAA,kBAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,YAAA,CAAA;AAAA,IACA,EAAE,KAAM,EAAA;AAAA,IACR,kBAAA,CAAmB,SAAS,iBAAiB,CAAA;AAAA,GAC/C,CAAA;AACF,CAAA;AAGsB,eAAA,gBAAA,CAAiB,OAAkB,EAAA,EAAA,EAAqB,aAAwC,EAAA;AACpH,EAAI,IAAA,EAAA,KAAO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AAC,CAAA,OAAA,CAAA;AAAA,IACrC;AAAA,MACE,IAAM,EAAA,aAAA;AAAA,KACR;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,UAAA,CAAA;AACT;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { rechargeApiRequest, getInternalSession } from '../utils/request.js';
2
+ import { encodePathSegment } from '../utils/url.js';
2
3
 
3
4
  async function getOrder(session, id) {
4
5
  if (id === void 0 || id === "") {
@@ -23,7 +24,7 @@ async function delayOrder(session, id) {
23
24
  }
24
25
  const { order } = await rechargeApiRequest(
25
26
  "post",
26
- `/orders/${id}/delay`,
27
+ `/orders/${encodePathSegment(id)}/delay`,
27
28
  {},
28
29
  getInternalSession(session, "delayOrder")
29
30
  );
@@ -1 +1 @@
1
- {"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getOrder(session: Session, id: string | number): Promise<Order> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'get',\n `/orders`,\n {\n id,\n },\n getInternalSession(session, 'getOrder')\n );\n return order;\n}\n\nexport function listOrders(session: Session, query?: OrderListParams): Promise<OrdersResponse> {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query }, getInternalSession(session, 'listOrders'));\n}\n\nexport async function delayOrder(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'post',\n `/orders/${id}/delay`,\n {},\n getInternalSession(session, 'delayOrder')\n );\n\n return order;\n}\n"],"names":[],"mappings":";;AAGsB,eAAA,QAAA,CAAS,SAAkB,EAAqC,EAAA;AACpF,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAM,kBAAA;AAAA,IACtB,KAAA;AAAA,IACA,CAAA,OAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,UAAU,CAAA;AAAA,GACxC,CAAA;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEgB,SAAA,UAAA,CAAW,SAAkB,KAAkD,EAAA;AAC7F,EAAO,OAAA,kBAAA,CAAmC,OAAO,CAAW,OAAA,CAAA,EAAA,EAAE,OAAS,EAAA,kBAAA,CAAmB,OAAS,EAAA,YAAY,CAAC,CAAA,CAAA;AAClH,CAAA;AAEsB,eAAA,UAAA,CAAW,SAAkB,EAAqB,EAAA;AACtE,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAM,kBAAA;AAAA,IACtB,MAAA;AAAA,IACA,WAAW,EAAE,CAAA,MAAA,CAAA;AAAA,IACb,EAAC;AAAA,IACD,kBAAA,CAAmB,SAAS,YAAY,CAAA;AAAA,GAC1C,CAAA;AAEA,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getOrder(session: Session, id: string | number): Promise<Order> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'get',\n `/orders`,\n {\n id,\n },\n getInternalSession(session, 'getOrder')\n );\n return order;\n}\n\nexport function listOrders(session: Session, query?: OrderListParams): Promise<OrdersResponse> {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query }, getInternalSession(session, 'listOrders'));\n}\n\nexport async function delayOrder(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'post',\n `/orders/${encodePathSegment(id)}/delay`,\n {},\n getInternalSession(session, 'delayOrder')\n );\n\n return order;\n}\n"],"names":[],"mappings":";;;AAIsB,eAAA,QAAA,CAAS,SAAkB,EAAqC,EAAA;AACpF,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAM,kBAAA;AAAA,IACtB,KAAA;AAAA,IACA,CAAA,OAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,UAAU,CAAA;AAAA,GACxC,CAAA;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEgB,SAAA,UAAA,CAAW,SAAkB,KAAkD,EAAA;AAC7F,EAAO,OAAA,kBAAA,CAAmC,OAAO,CAAW,OAAA,CAAA,EAAA,EAAE,OAAS,EAAA,kBAAA,CAAmB,OAAS,EAAA,YAAY,CAAC,CAAA,CAAA;AAClH,CAAA;AAEsB,eAAA,UAAA,CAAW,SAAkB,EAAqB,EAAA;AACtE,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAM,kBAAA;AAAA,IACtB,MAAA;AAAA,IACA,CAAA,QAAA,EAAW,iBAAkB,CAAA,EAAE,CAAC,CAAA,MAAA,CAAA;AAAA,IAChC,EAAC;AAAA,IACD,kBAAA,CAAmB,SAAS,YAAY,CAAA;AAAA,GAC1C,CAAA;AAEA,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}