@rechargeapps/storefront-client 2.6.1 → 2.7.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 (93) hide show
  1. package/dist/cjs/api/address.js.map +1 -1
  2. package/dist/cjs/api/auth.js +1 -1
  3. package/dist/cjs/api/auth.js.map +1 -1
  4. package/dist/cjs/api/bundle.js +0 -1
  5. package/dist/cjs/api/bundle.js.map +1 -1
  6. package/dist/cjs/api/bundleData.js +1 -1
  7. package/dist/cjs/api/bundleData.js.map +1 -1
  8. package/dist/cjs/api/cdn.js.map +1 -1
  9. package/dist/cjs/api/charge.js.map +1 -1
  10. package/dist/cjs/api/collection.js.map +1 -1
  11. package/dist/cjs/api/credit.js.map +1 -1
  12. package/dist/cjs/api/customer.js.map +1 -1
  13. package/dist/cjs/api/customerSurveys.js.map +1 -1
  14. package/dist/cjs/api/flow.js.map +1 -1
  15. package/dist/cjs/api/gift.js.map +1 -1
  16. package/dist/cjs/api/membership.js.map +1 -1
  17. package/dist/cjs/api/membershipProgram.js.map +1 -1
  18. package/dist/cjs/api/metafield.js.map +1 -1
  19. package/dist/cjs/api/onetime.js.map +1 -1
  20. package/dist/cjs/api/order.js.map +1 -1
  21. package/dist/cjs/api/paymentMethod.js.map +1 -1
  22. package/dist/cjs/api/plan.js.map +1 -1
  23. package/dist/cjs/api/product.js.map +1 -1
  24. package/dist/cjs/api/store.js.map +1 -1
  25. package/dist/cjs/api/subscription.js.map +1 -1
  26. package/dist/cjs/api/tieredDiscount.js +0 -6
  27. package/dist/cjs/api/tieredDiscount.js.map +1 -1
  28. package/dist/cjs/constants/api.js.map +1 -1
  29. package/dist/cjs/mappers/cdn.js.map +1 -1
  30. package/dist/cjs/mappers/subscription.js.map +1 -1
  31. package/dist/cjs/mappers/utils.js.map +1 -1
  32. package/dist/cjs/utils/bundle.js +28 -51
  33. package/dist/cjs/utils/bundle.js.map +1 -1
  34. package/dist/cjs/utils/bundleData.js +4 -8
  35. package/dist/cjs/utils/bundleData.js.map +1 -1
  36. package/dist/cjs/utils/error.js.map +1 -1
  37. package/dist/cjs/utils/id.js.map +1 -1
  38. package/dist/cjs/utils/init.js.map +1 -1
  39. package/dist/cjs/utils/loadSpreedlyScript.js +34 -20
  40. package/dist/cjs/utils/loadSpreedlyScript.js.map +1 -1
  41. package/dist/cjs/utils/options.js.map +1 -1
  42. package/dist/cjs/utils/request.js +1 -1
  43. package/dist/cjs/utils/request.js.map +1 -1
  44. package/dist/cjs/utils/url.js.map +1 -1
  45. package/dist/esm/api/address.js +1 -1
  46. package/dist/esm/api/address.js.map +1 -1
  47. package/dist/esm/api/auth.js +1 -1
  48. package/dist/esm/api/auth.js.map +1 -1
  49. package/dist/esm/api/bundle.js +1 -2
  50. package/dist/esm/api/bundle.js.map +1 -1
  51. package/dist/esm/api/bundleData.js +1 -1
  52. package/dist/esm/api/bundleData.js.map +1 -1
  53. package/dist/esm/api/cdn.js.map +1 -1
  54. package/dist/esm/api/charge.js.map +1 -1
  55. package/dist/esm/api/collection.js.map +1 -1
  56. package/dist/esm/api/credit.js.map +1 -1
  57. package/dist/esm/api/customer.js +1 -1
  58. package/dist/esm/api/customer.js.map +1 -1
  59. package/dist/esm/api/customerSurveys.js.map +1 -1
  60. package/dist/esm/api/flow.js.map +1 -1
  61. package/dist/esm/api/gift.js.map +1 -1
  62. package/dist/esm/api/membership.js.map +1 -1
  63. package/dist/esm/api/membershipProgram.js.map +1 -1
  64. package/dist/esm/api/metafield.js.map +1 -1
  65. package/dist/esm/api/onetime.js.map +1 -1
  66. package/dist/esm/api/order.js.map +1 -1
  67. package/dist/esm/api/paymentMethod.js.map +1 -1
  68. package/dist/esm/api/plan.js.map +1 -1
  69. package/dist/esm/api/product.js.map +1 -1
  70. package/dist/esm/api/store.js.map +1 -1
  71. package/dist/esm/api/subscription.js.map +1 -1
  72. package/dist/esm/api/tieredDiscount.js +0 -6
  73. package/dist/esm/api/tieredDiscount.js.map +1 -1
  74. package/dist/esm/constants/api.js.map +1 -1
  75. package/dist/esm/mappers/cdn.js.map +1 -1
  76. package/dist/esm/mappers/subscription.js.map +1 -1
  77. package/dist/esm/mappers/utils.js.map +1 -1
  78. package/dist/esm/utils/bundle.js +29 -52
  79. package/dist/esm/utils/bundle.js.map +1 -1
  80. package/dist/esm/utils/bundleData.js +4 -8
  81. package/dist/esm/utils/bundleData.js.map +1 -1
  82. package/dist/esm/utils/error.js.map +1 -1
  83. package/dist/esm/utils/id.js.map +1 -1
  84. package/dist/esm/utils/init.js.map +1 -1
  85. package/dist/esm/utils/loadSpreedlyScript.js +34 -20
  86. package/dist/esm/utils/loadSpreedlyScript.js.map +1 -1
  87. package/dist/esm/utils/options.js.map +1 -1
  88. package/dist/esm/utils/request.js +2 -2
  89. package/dist/esm/utils/request.js.map +1 -1
  90. package/dist/esm/utils/url.js.map +1 -1
  91. package/dist/index.d.ts +0 -6
  92. package/dist/umd/recharge-client.min.js +2 -2
  93. package/package.json +11 -10
@@ -1 +1 @@
1
- {"version":3,"file":"address.js","sources":["../../../src/api/address.ts"],"sourcesContent":["import { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n AddressResponse,\n AddressListParams,\n CreateAddressRequest,\n UpdateAddressRequest,\n AddressListResponse,\n MergeAddressesRequest,\n SkipFutureChargeAddressRequest,\n SkipFutureChargeAddressResponse,\n GetAddressOptions,\n Session,\n UpdateAddressParams,\n} from '../types';\n\n/** Returns all addresses from the store, or addresses for the customer given in the parameter. */\nexport function listAddresses(session: Session, query?: AddressListParams) {\n return rechargeApiRequest<AddressListResponse>(\n 'get',\n `/addresses`,\n { query },\n getInternalSession(session, 'listAddresses')\n );\n}\n\n/** Retrieves address for customer based on specified address id. */\nexport async function getAddress(session: Session, id: string | number, options?: GetAddressOptions) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'get',\n `/addresses`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getAddress')\n );\n return address;\n}\n\n/** Create a new address for a customer. */\nexport async function createAddress(session: Session, createRequest: CreateAddressRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses`,\n { data: { ...createRequest, customer_id: session.customerId ? Number(session.customerId) : undefined } },\n getInternalSession(session, 'createAddress')\n );\n return address;\n}\n\n/** Updates an existing address to match the specified parameters. */\nexport async function updateAddress(\n session: Session,\n id: string | number,\n updateRequest: UpdateAddressRequest,\n query?: UpdateAddressParams\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'put',\n `/addresses`,\n { id, data: updateRequest, query },\n getInternalSession(session, 'updateAddress')\n );\n return address;\n}\n\n/** Apply discount code to an address. Addresses are currently limited to a single discount. */\nexport async function applyDiscountToAddress(\n session: Session,\n id: string | number,\n discountCode: string,\n query?: UpdateAddressParams\n) {\n return updateAddress(\n getInternalSession(session, 'applyDiscountToAddress'),\n id,\n {\n discounts: [{ code: discountCode }],\n },\n query\n );\n}\n\n/** Removes all discounts from an address. */\nexport async function removeDiscountsFromAddress(session: Session, id: string | number, query?: UpdateAddressParams) {\n if (id === undefined || id === '') {\n throw new Error('Id is required');\n }\n return updateAddress(getInternalSession(session, 'removeDiscountsFromAddress'), id, { discounts: [] }, query);\n}\n\n/** Deletes an address. Only Addresses with no active Subscriptions can be deleted. */\nexport function deleteAddress(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<void>('delete', `/addresses`, { id }, getInternalSession(session, 'deleteAddress'));\n}\n\n/**\n * Merges up to 10 source addresses into 1 target address.\n */\nexport async function mergeAddresses(session: Session, mergeRequest: MergeAddressesRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses/merge`,\n {\n data: mergeRequest,\n },\n getInternalSession(session, 'mergeAddresses')\n );\n return address;\n}\n\n/**\n * Skip a Charge in the future for one or multiple Subscriptions associated with the Address.\n */\nexport async function skipFutureCharge(\n session: Session,\n id: string | number,\n skipRequest: SkipFutureChargeAddressRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<SkipFutureChargeAddressResponse>(\n 'post',\n `/addresses/${encodePathSegment(id)}/charges/skip`,\n {\n data: skipRequest,\n },\n getInternalSession(session, 'skipFutureCharge')\n );\n return charge;\n}\n"],"names":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AAiBgB,SAAA,aAAA,CAAc,SAAkB,KAA2B,EAAA;AACzE,EAAO,OAAAA,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA,EAAE,KAAM,EAAA;AAAA,IACRC,0BAAA,CAAmB,SAAS,eAAe,CAAA;AAAA,GAC7C,CAAA;AACF,CAAA;AAGsB,eAAA,UAAA,CAAW,OAAkB,EAAA,EAAA,EAAqB,OAA6B,EAAA;AACnG,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,OAAQ,EAAA,GAAI,MAAMD,0BAAA;AAAA,IACxB,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,IACAC,0BAAA,CAAmB,SAAS,YAAY,CAAA;AAAA,GAC1C,CAAA;AACA,EAAO,OAAA,OAAA,CAAA;AACT,CAAA;AAGsB,eAAA,aAAA,CAAc,SAAkB,aAAqC,EAAA;AACzF,EAAM,MAAA,EAAE,OAAQ,EAAA,GAAI,MAAMD,0BAAA;AAAA,IACxB,MAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA,EAAE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AA,CAAA;AACT;;;;;;;;;;;;"}
1
+ {"version":3,"file":"address.js","sources":["../../../src/api/address.ts"],"sourcesContent":["import { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n AddressResponse,\n AddressListParams,\n CreateAddressRequest,\n UpdateAddressRequest,\n AddressListResponse,\n MergeAddressesRequest,\n SkipFutureChargeAddressRequest,\n SkipFutureChargeAddressResponse,\n GetAddressOptions,\n Session,\n UpdateAddressParams,\n} from '../types';\n\n/** Returns all addresses from the store, or addresses for the customer given in the parameter. */\nexport function listAddresses(session: Session, query?: AddressListParams) {\n return rechargeApiRequest<AddressListResponse>(\n 'get',\n `/addresses`,\n { query },\n getInternalSession(session, 'listAddresses')\n );\n}\n\n/** Retrieves address for customer based on specified address id. */\nexport async function getAddress(session: Session, id: string | number, options?: GetAddressOptions) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'get',\n `/addresses`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getAddress')\n );\n return address;\n}\n\n/** Create a new address for a customer. */\nexport async function createAddress(session: Session, createRequest: CreateAddressRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses`,\n { data: { ...createRequest, customer_id: session.customerId ? Number(session.customerId) : undefined } },\n getInternalSession(session, 'createAddress')\n );\n return address;\n}\n\n/** Updates an existing address to match the specified parameters. */\nexport async function updateAddress(\n session: Session,\n id: string | number,\n updateRequest: UpdateAddressRequest,\n query?: UpdateAddressParams\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'put',\n `/addresses`,\n { id, data: updateRequest, query },\n getInternalSession(session, 'updateAddress')\n );\n return address;\n}\n\n/** Apply discount code to an address. Addresses are currently limited to a single discount. */\nexport async function applyDiscountToAddress(\n session: Session,\n id: string | number,\n discountCode: string,\n query?: UpdateAddressParams\n) {\n return updateAddress(\n getInternalSession(session, 'applyDiscountToAddress'),\n id,\n {\n discounts: [{ code: discountCode }],\n },\n query\n );\n}\n\n/** Removes all discounts from an address. */\nexport async function removeDiscountsFromAddress(session: Session, id: string | number, query?: UpdateAddressParams) {\n if (id === undefined || id === '') {\n throw new Error('Id is required');\n }\n return updateAddress(getInternalSession(session, 'removeDiscountsFromAddress'), id, { discounts: [] }, query);\n}\n\n/** Deletes an address. Only Addresses with no active Subscriptions can be deleted. */\nexport function deleteAddress(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<void>('delete', `/addresses`, { id }, getInternalSession(session, 'deleteAddress'));\n}\n\n/**\n * Merges up to 10 source addresses into 1 target address.\n */\nexport async function mergeAddresses(session: Session, mergeRequest: MergeAddressesRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses/merge`,\n {\n data: mergeRequest,\n },\n getInternalSession(session, 'mergeAddresses')\n );\n return address;\n}\n\n/**\n * Skip a Charge in the future for one or multiple Subscriptions associated with the Address.\n */\nexport async function skipFutureCharge(\n session: Session,\n id: string | number,\n skipRequest: SkipFutureChargeAddressRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<SkipFutureChargeAddressResponse>(\n 'post',\n `/addresses/${encodePathSegment(id)}/charges/skip`,\n {\n data: skipRequest,\n },\n getInternalSession(session, 'skipFutureCharge')\n );\n return charge;\n}\n"],"names":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AAiBO,SAAS,aAAA,CAAc,SAAkB,KAAA,EAA2B;AACzE,EAAA,OAAOA,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA,EAAE,KAAA,EAAM;AAAA,IACRC,0BAAA,CAAmB,SAAS,eAAe;AAAA,GAC7C;AACF;AAGA,eAAsB,UAAA,CAAW,OAAA,EAAkB,EAAA,EAAqB,OAA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AACA,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAMD,0BAAA;AAAA,IACvB,MAAA;AAAA,IACA,CAAA,WAAA,EAAcE,qBAAA,CAAkB,EAAE,CAAC,CAAA,aAAA,CAAA;AAAA,IACnC;AAAA,MACE,IAAA,EAAM;AAAA,KACR;AAAA,IACAD,0BAAA,CAAmB,SAAS,kBAAkB;AAAA,GAChD;AACA,EAAA,OAAO,MAAA;AACT;;;;;;;;;;"}
@@ -190,7 +190,7 @@ async function rechargeAdminRequest(method, url, { id, query, data, headers } =
190
190
  ...storefrontAccessToken ? { "X-Recharge-Storefront-Access-Token": storefrontAccessToken } : {},
191
191
  ...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
192
192
  ...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {},
193
- "X-Recharge-Sdk-Version": "2.6.1",
193
+ "X-Recharge-Sdk-Version": "2.7.0",
194
194
  ...headers ? headers : {}
195
195
  };
196
196
  return request.request(method, `${rechargeBaseUrl}${url}`, { id, query, data, headers: reqHeaders });
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sources":["../../../src/api/auth.ts"],"sourcesContent":["import { request as baseRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n LoginResponse,\n Method,\n PasswordlessCodeResponse,\n PasswordlessOptions,\n PasswordlessValidateResponse,\n RequestHeaders,\n RequestOptions,\n Session,\n} from '../types';\nimport { getOptions } from '../utils/options';\nimport { RECHARGE_ADMIN_URL } from '../constants/api';\n\nexport async function loginShopifyAppProxy(): Promise<Session> {\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<LoginResponse>('get', '/access', { headers });\n\n return { apiToken: response.api_token, customerId: response.customer_id, message: response.message };\n}\n\n/** @deprecated Use `loginWithShopifyStorefront` instead */\nexport async function loginShopifyApi(\n shopifyStorefrontToken: string,\n shopifyCustomerAccessToken?: string\n): Promise<Session | null> {\n return loginWithShopifyStorefront(shopifyStorefrontToken, shopifyCustomerAccessToken);\n}\n\nexport async function loginWithShopifyStorefront(\n shopifyStorefrontToken: string,\n shopifyCustomerAccessToken?: string\n): Promise<Session | null> {\n if (!shopifyStorefrontToken) {\n throw new Error('Shopify storefront token is required');\n }\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n const {\n api_token: apiToken,\n customer_id: customerId,\n message,\n } = await rechargeAdminRequest<LoginResponse>('post', '/shopify_storefront_access', {\n data: {\n customer_token: shopifyCustomerAccessToken,\n storefront_token: shopifyStorefrontToken,\n shop_url: storeIdentifier,\n },\n });\n\n return apiToken ? { apiToken, customerId, message } : null;\n}\n\nexport async function loginWithShopifyCustomerAccount(shopifyCustomerAccessToken?: string): Promise<Session | null> {\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n const {\n api_token: apiToken,\n customer_id: customerId,\n message,\n } = await rechargeAdminRequest<LoginResponse>('post', '/shopify_customer_account_api_access', {\n data: {\n customer_token: shopifyCustomerAccessToken,\n shop_url: storeIdentifier,\n },\n });\n\n return apiToken ? { apiToken, customerId, message } : null;\n}\n\nexport async function sendPasswordlessCode(email: string, options: PasswordlessOptions = {}): Promise<string> {\n if (!email) {\n throw new Error('Email is required.');\n }\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n // Only forward documented option keys. Spreading raw `options` after the\n // trusted `shop`/`email` fields would let a runtime caller override them or\n // inject undocumented authority fields (H1-3884986 / SEC-4002).\n const { send_email, send_sms } = options;\n const response = await rechargeAdminRequest<PasswordlessCodeResponse>('post', '/attempt_login', {\n data: {\n email,\n shop: storeIdentifier,\n ...(send_email !== undefined ? { send_email } : {}),\n ...(send_sms !== undefined ? { send_sms } : {}),\n },\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function sendPasswordlessCodeAppProxy(email: string, options: PasswordlessOptions = {}): Promise<string> {\n if (!email) {\n throw new Error('Email is required.');\n }\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n // Only forward documented option keys (see sendPasswordlessCode above) so a\n // caller can't override `email` or inject undocumented fields (SEC-4002).\n const { send_email, send_sms } = options;\n const response = await shopifyAppProxyRequest<PasswordlessCodeResponse>('post', '/attempt_login', {\n data: {\n email,\n ...(send_email !== undefined ? { send_email } : {}),\n ...(send_sms !== undefined ? { send_sms } : {}),\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function validatePasswordlessCode(email: string, session_token: string, code: string): Promise<Session> {\n if (!email) {\n throw new Error('Email is required.');\n }\n if (!session_token) {\n throw new Error('Session token is required.');\n }\n if (!code) {\n throw new Error('Code is required.');\n }\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n const response = await rechargeAdminRequest<PasswordlessValidateResponse>('post', '/validate_login', {\n data: {\n code,\n email,\n session_token,\n shop: storeIdentifier,\n },\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nexport async function validatePasswordlessCodeAppProxy(\n email: string,\n session_token: string,\n code: string\n): Promise<Session> {\n if (!email) {\n throw new Error('Email is required.');\n }\n if (!session_token) {\n throw new Error('Session token is required.');\n }\n if (!code) {\n throw new Error('Code is required.');\n }\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<PasswordlessValidateResponse>('post', '/validate_login', {\n data: {\n code,\n email,\n session_token,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nfunction getCustomerParams() {\n const { customerHash: devCustomerHash } = getOptions();\n const { pathname, search } = window.location;\n const urlParams = new URLSearchParams(search);\n const token = urlParams.get('token');\n const subpaths = pathname.split('/').filter(Boolean);\n const portalIndex = subpaths.findIndex(path => path === 'portal');\n const customerHash = portalIndex !== -1 ? subpaths[portalIndex + 1] : devCustomerHash;\n\n // make sure the URL contained the data we need\n if (!token || !customerHash) {\n throw new Error('Not in context of Recharge Customer Portal or URL did not contain correct params');\n }\n return { customerHash, token };\n}\n\nexport async function loginCustomerPortal(): Promise<Session> {\n const { customerHash, token } = getCustomerParams();\n const { storeIdentifier } = getOptions();\n const response = await rechargeAdminRequest<LoginResponse>(\n 'post',\n `/customers/${encodePathSegment(customerHash)}/access`,\n {\n data: {\n token,\n shop: storeIdentifier,\n },\n }\n );\n\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nasync function rechargeAdminRequest<T>(\n method: Method,\n url: string,\n { id, query, data, headers }: RequestOptions = {}\n): Promise<T> {\n const { environment, environmentUri, storefrontAccessToken, appName, appVersion } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment, environmentUri);\n const reqHeaders: RequestHeaders = {\n ...(storefrontAccessToken ? { 'X-Recharge-Storefront-Access-Token': storefrontAccessToken } : {}),\n ...(appName ? { 'X-Recharge-Sdk-App-Name': appName } : {}),\n ...(appVersion ? { 'X-Recharge-Sdk-App-Version': appVersion } : {}),\n 'X-Recharge-Sdk-Version': '__SDK_VERSION__',\n ...(headers ? headers : {}),\n };\n\n return baseRequest<T>(method, `${rechargeBaseUrl}${url}`, { id, query, data, headers: reqHeaders });\n}\n"],"names":["getOptions","shopifyAppProxyRequest","options","encodePathSegment","RECHARGE_ADMIN_URL","baseRequest"],"mappings":";;;;;;;AAeA,eAAsB,oBAAyC,GAAA;AAC7D,EAAM,MAAA,EAAE,qBAAsB,EAAA,GAAIA,kBAAW,EAAA,CAAA;AAC7C,EAAA,MAAM,UAA0B,EAAC,CAAA;AACjC,EAAA,IAAI,qBAAuB,EAAA;AACzB,IAAA,OAAA,CAAQ,oCAAoC,CAAI,GAAA,qBAAA,CAAA;AAAA,GAClD;AACA,EAAA,MAAM,WAAW,MAAMC,8BAAA,CAAsC,OAAO,SAAW,EAAA,EAAE,SAAS,CAAA,CAAA;AAE1F,EAAO,OAAA,EAAE,UAAU,QAAS,CAAA,SAAA,EAAW,YAAY,QAAS,CAAA,WAAA,EAAa,OAAS,EAAA,QAAA,CAAS,OAAQ,EAAA,CAAA;AACrG,CAAA;AAGsB,eAAA,eAAA,CACpB,wBACA,0BACyB,EAAA;AACzB,EAAO,OAAA,0BAAA,CAA2B,wBAAwB,0BAA0B,CAAA,CAAA;AACtF,CAAA;AAEsB,eAAA,0BAAA,CACpB,wBACA,0BACyB,EAAA;AACzB,EAAA,IAAI,CAAC,sBAAwB,EAAA;AAC3B,IAAM,MAAA,IAAI,MAAM,sCAAsC,CAAA,CAAA;AAAA,GACxD;AACA,EAAM,MAAA,EAAE,eAAgB,EAAA,GAAID,kBAAW,EAAA,CAAA;AACvC,EAAA,IAAI,CAAC,eAAiB,EAAA;AACpB,IAAM,MAAA,IAAI,MAAM,+EAA+E,CAAA,CAAA;AAAA,GACjG;AACA,EAAM,MAAA;AAAA,IACJ,SAAW,EAAA,QAAA;AAAA,IACX,WAAa,EAAA,UAAA;AAAA,IACb,OAAA;AAAA,GACE,GAAA,MAAM,oBAAoC,CAAA,MAAA,EAAQ,4BAA8B,EAAA;AAAA,IAClF,IAAM,EAAA;AAAA,MACJ,cAAgB,EAAA,0BAAA;AAAA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M,UAA6B,GAAA;AAAA,IACjC,GAAI,qBAAwB,GAAA,EAAE,oCAAsC,EAAA,qBAAA,KAA0B,EAAC;AAAA,IAC/F,GAAI,OAAU,GAAA,EAAE,yBAA2B,EAAA,OAAA,KAAY,EAAC;AAAA,IACxD,GAAI,UAAa,GAAA,EAAE,4BAA8B,EAAA,UAAA,KAAe,EAAC;AAAA,IACjE,wBAA0B,EAAA,OAAA;AAAA,IAC1B,GAAI,OAAU,GAAA,OAAA,GAAU,EAAC;AAAA,GAC3B,CAAA;AAEA,EAAA,OAAOC,eAAe,CAAA,MAAA,EAAQ,CAAG,EAAA,eAAe,CAAG,EAAA,GAAG,CAAI,CAAA,EAAA,EAAE,EAAI,EAAA,KAAA,EAAO,IAAM,EAAA,OAAA,EAAS,YAAY,CAAA,CAAA;AACpG;;;;;;;;;;;;"}
1
+ {"version":3,"file":"auth.js","sources":["../../../src/api/auth.ts"],"sourcesContent":["import { request as baseRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n LoginResponse,\n Method,\n PasswordlessCodeResponse,\n PasswordlessOptions,\n PasswordlessValidateResponse,\n RequestHeaders,\n RequestOptions,\n Session,\n} from '../types';\nimport { getOptions } from '../utils/options';\nimport { RECHARGE_ADMIN_URL } from '../constants/api';\n\nexport async function loginShopifyAppProxy(): Promise<Session> {\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<LoginResponse>('get', '/access', { headers });\n\n return { apiToken: response.api_token, customerId: response.customer_id, message: response.message };\n}\n\n/** @deprecated Use `loginWithShopifyStorefront` instead */\nexport async function loginShopifyApi(\n shopifyStorefrontToken: string,\n shopifyCustomerAccessToken?: string\n): Promise<Session | null> {\n return loginWithShopifyStorefront(shopifyStorefrontToken, shopifyCustomerAccessToken);\n}\n\nexport async function loginWithShopifyStorefront(\n shopifyStorefrontToken: string,\n shopifyCustomerAccessToken?: string\n): Promise<Session | null> {\n if (!shopifyStorefrontToken) {\n throw new Error('Shopify storefront token is required');\n }\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n const {\n api_token: apiToken,\n customer_id: customerId,\n message,\n } = await rechargeAdminRequest<LoginResponse>('post', '/shopify_storefront_access', {\n data: {\n customer_token: shopifyCustomerAccessToken,\n storefront_token: shopifyStorefrontToken,\n shop_url: storeIdentifier,\n },\n });\n\n return apiToken ? { apiToken, customerId, message } : null;\n}\n\nexport async function loginWithShopifyCustomerAccount(shopifyCustomerAccessToken?: string): Promise<Session | null> {\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n const {\n api_token: apiToken,\n customer_id: customerId,\n message,\n } = await rechargeAdminRequest<LoginResponse>('post', '/shopify_customer_account_api_access', {\n data: {\n customer_token: shopifyCustomerAccessToken,\n shop_url: storeIdentifier,\n },\n });\n\n return apiToken ? { apiToken, customerId, message } : null;\n}\n\nexport async function sendPasswordlessCode(email: string, options: PasswordlessOptions = {}): Promise<string> {\n if (!email) {\n throw new Error('Email is required.');\n }\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n // Only forward documented option keys. Spreading raw `options` after the\n // trusted `shop`/`email` fields would let a runtime caller override them or\n // inject undocumented authority fields (H1-3884986 / SEC-4002).\n const { send_email, send_sms } = options;\n const response = await rechargeAdminRequest<PasswordlessCodeResponse>('post', '/attempt_login', {\n data: {\n email,\n shop: storeIdentifier,\n ...(send_email !== undefined ? { send_email } : {}),\n ...(send_sms !== undefined ? { send_sms } : {}),\n },\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function sendPasswordlessCodeAppProxy(email: string, options: PasswordlessOptions = {}): Promise<string> {\n if (!email) {\n throw new Error('Email is required.');\n }\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n // Only forward documented option keys (see sendPasswordlessCode above) so a\n // caller can't override `email` or inject undocumented fields (SEC-4002).\n const { send_email, send_sms } = options;\n const response = await shopifyAppProxyRequest<PasswordlessCodeResponse>('post', '/attempt_login', {\n data: {\n email,\n ...(send_email !== undefined ? { send_email } : {}),\n ...(send_sms !== undefined ? { send_sms } : {}),\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function validatePasswordlessCode(email: string, session_token: string, code: string): Promise<Session> {\n if (!email) {\n throw new Error('Email is required.');\n }\n if (!session_token) {\n throw new Error('Session token is required.');\n }\n if (!code) {\n throw new Error('Code is required.');\n }\n const { storeIdentifier } = getOptions();\n if (!storeIdentifier) {\n throw new Error('InitRecharge has not been called and/or no store identifier has been defined.');\n }\n const response = await rechargeAdminRequest<PasswordlessValidateResponse>('post', '/validate_login', {\n data: {\n code,\n email,\n session_token,\n shop: storeIdentifier,\n },\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nexport async function validatePasswordlessCodeAppProxy(\n email: string,\n session_token: string,\n code: string\n): Promise<Session> {\n if (!email) {\n throw new Error('Email is required.');\n }\n if (!session_token) {\n throw new Error('Session token is required.');\n }\n if (!code) {\n throw new Error('Code is required.');\n }\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<PasswordlessValidateResponse>('post', '/validate_login', {\n data: {\n code,\n email,\n session_token,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nfunction getCustomerParams() {\n const { customerHash: devCustomerHash } = getOptions();\n const { pathname, search } = window.location;\n const urlParams = new URLSearchParams(search);\n const token = urlParams.get('token');\n const subpaths = pathname.split('/').filter(Boolean);\n const portalIndex = subpaths.findIndex(path => path === 'portal');\n const customerHash = portalIndex !== -1 ? subpaths[portalIndex + 1] : devCustomerHash;\n\n // make sure the URL contained the data we need\n if (!token || !customerHash) {\n throw new Error('Not in context of Recharge Customer Portal or URL did not contain correct params');\n }\n return { customerHash, token };\n}\n\nexport async function loginCustomerPortal(): Promise<Session> {\n const { customerHash, token } = getCustomerParams();\n const { storeIdentifier } = getOptions();\n const response = await rechargeAdminRequest<LoginResponse>(\n 'post',\n `/customers/${encodePathSegment(customerHash)}/access`,\n {\n data: {\n token,\n shop: storeIdentifier,\n },\n }\n );\n\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nasync function rechargeAdminRequest<T>(\n method: Method,\n url: string,\n { id, query, data, headers }: RequestOptions = {}\n): Promise<T> {\n const { environment, environmentUri, storefrontAccessToken, appName, appVersion } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment, environmentUri);\n const reqHeaders: RequestHeaders = {\n ...(storefrontAccessToken ? { 'X-Recharge-Storefront-Access-Token': storefrontAccessToken } : {}),\n ...(appName ? { 'X-Recharge-Sdk-App-Name': appName } : {}),\n ...(appVersion ? { 'X-Recharge-Sdk-App-Version': appVersion } : {}),\n 'X-Recharge-Sdk-Version': '__SDK_VERSION__',\n ...(headers ? headers : {}),\n };\n\n return baseRequest<T>(method, `${rechargeBaseUrl}${url}`, { id, query, data, headers: reqHeaders });\n}\n"],"names":["getOptions","shopifyAppProxyRequest","options","encodePathSegment","RECHARGE_ADMIN_URL","baseRequest"],"mappings":";;;;;;;AAeA,eAAsB,oBAAA,GAAyC;AAC7D,EAAA,MAAM,EAAE,qBAAA,EAAsB,GAAIA,kBAAA,EAAW;AAC7C,EAAA,MAAM,UAA0B,EAAC;AACjC,EAAA,IAAI,qBA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AACF,GACF;AAEA,EAAA,OAAO,EAAE,QAAA,EAAU,QAAA,CAAS,SAAA,EAAW,UAAA,EAAY,SAAS,WAAA,EAAY;AAC1E;AAEA,eAAe,oBAAA,CACb,MAAA,EACA,GAAA,EACA,EAAE,EAAA,EAAI,OAAO,IAAA,EAAM,OAAA,EAAQ,GAAoB,EAAC,EACpC;AACZ,EAAA,MAAM,EAAE,WAAA,EAAa,cAAA,EAAgB,uBAAuB,OAAA,EAAS,UAAA,KAAeH,kBAAA,EAAW;AAC/F,EAAA,MAAM,eAAA,GAAkBI,sBAAA,CAAmB,WAAA,EAAa,cAAc,CAAA;AACtE,EAAA,MAAM,UAAA,GAA6B;AAAA,IACjC,GAAI,qBAAA,GAAwB,EAAE,oCAAA,EAAsC,qBAAA,KAA0B,EAAC;AAAA,IAC/F,GAAI,OAAA,GAAU,EAAE,yBAAA,EAA2B,OAAA,KAAY,EAAC;AAAA,IACxD,GAAI,UAAA,GAAa,EAAE,4BAAA,EAA8B,UAAA,KAAe,EAAC;AAAA,IACjE,wBAAA,EAA0B,OAAA;AAAA,IAC1B,GAAI,OAAA,GAAU,OAAA,GAAU;AAAC,GAC3B;AAEA,EAAA,OAAOC,eAAA,CAAe,MAAA,EAAQ,CAAA,EAAG,eAAe,CAAA,EAAG,GAAG,CAAA,CAAA,EAAI,EAAE,EAAA,EAAI,KAAA,EAAO,IAAA,EAAM,OAAA,EAAS,YAAY,CAAA;AACpG;;;;;;;;;;"}
@@ -10,7 +10,6 @@ const STORE_FRONT_MANAGER_URL = "/bundling-storefront-manager";
10
10
  function createBundleData(bundle$1) {
11
11
  return bundle.toLineItemProperty({
12
12
  variantId: bundle$1.externalVariantId,
13
- version: 0,
14
13
  // server will replace it with the current time
15
14
  items: bundle$1.selections.map((item) => {
16
15
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from '../utils/id';\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":["bundle","toLineItemProperty","getOptions","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;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from '../utils/id';\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":["bundle","toLineItemProperty","getOptions","shopifyAppProxyRequest","rechargeApiRequest","getInternalSession","nanoid","encodePathSegment","BundleSelectionValidator"],"mappings":";;;;;;;;AAoBA,MAAM,uBAAA,GAA0B,8BAAA;AAEhC,SAAS,iBAAiBA,QAAA,EAAwB;AAChD,EAAA,OAAOC,yBAAA,CAAmB;AAAA,IACxB,WAAWD,QAAA,CAAO,iBAAA;AAAA,IACT;AAAA,IACT,KAAA,EAAOA,QAAA,CAAO,UAAA,CAAW,GAAA,CAAI,CAAA,IAAA,KAAQ;AACnC,MAAA,OAAO;AAAA,QACL,cAAc,IAAA,CAAK,YAAA;AAAA,QACnB,WAAW,IAAA,CAAK,iBAAA;AAAA,QAChB,WAAW,IAAA,CAAK,iBAAA;AAAA,QAChB,UAAU,IAAA,CAAK,QAAA;AAAA,QACf,GAAA,EAAK;AAAA,OACP;AAAA,IACF,CAAC;AAAA,GACF,CAAA;AACH;AAEA,eAAsB,YAAY,MAAA,EAAyC;AACzE,EAAA,MAAM,OAAOE,kBAAA,EAAW;AACxB,EAAA,MAAM,OAAA,GAAU,MAAM,cAAA,CAAe,MAAM,CAAA;AAC3C,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,MAAM,IAAI,MAAM,OAAO,CAAA;AAAA,EACzB;AACA,EAAA,MAAM,UAAA,GAAa,iBAAiB,MAAM,CAAA;AAE1C,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,MAAMC,8BAAA;AAAA,MACpB,MAAA;AAAA,MACA,GAAG,uBAAuB,CAAA,eAAA,CAAA;AAAA,MAC1B;AAAA,QACE,IAAA,EAAM;AAAA,UACJ,MAAA,EAAQ;AAAA,SACV;AAAA,QACA,OAAA,EAAS;AAAA,UACP,MAAA,EAAQ,CAAA,QAAA,EAAW,IAAA,CAAK,eAAe,CAAA;A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AA,CAAsB,SAAkB,EAAA,EAAoC;AAC1F,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,OAAOD,0BAAA;AAAA,IACL,QAAA;AAAA,IACA,CAAA,kBAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACAC,0BAAA,CAAmB,SAAS,uBAAuB;AAAA,GACrD;AACF;AAEA,eAAsB,YAAA,CACpB,OAAA,EACA,gBAAA,EACA,aAAA,EACA,KAAA,EAC6B;AAC7B,EAAA,IAAI,gBAAA,KAAqB,MAAA,IAAa,gBAAA,KAAqB,EAAA,EAAI;AAC7D,IAAA,MAAM,IAAI,MAAM,8BAA8B,CAAA;AAAA,EAChD;AACA,EAAA,MAAM,EAAE,YAAA,EAAa,GAAI,MAAMD,0BAAA;AAAA,IAC7B,KAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,MACE,EAAA,EAAI,gBAAA;AAAA,MACJ,IAAA,EAAM,aAAA;AAAA,MACN;AAAA,KACF;AAAA,IACAC,0BAAA,CAAmB,SAAS,cAAc;AAAA,GAC5C;AAEA,EAAA,OAAO,YAAA;AACT;;;;;;;;;;;;;"}
@@ -16,7 +16,7 @@ async function loadFromOnlineStore(id, country_code) {
16
16
  const { appName, appVersion } = options.getOptions();
17
17
  const headers = {
18
18
  "X-Recharge-Sdk-Fn": "loadFromOnlineStore",
19
- "X-Recharge-Sdk-Version": "2.6.1",
19
+ "X-Recharge-Sdk-Version": "2.7.0",
20
20
  ...appName ? { "X-Recharge-Sdk-App-Name": appName } : {},
21
21
  ...appVersion ? { "X-Recharge-Sdk-App-Version": appVersion } : {}
22
22
  };
@@ -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 { 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":["getOptions","shopifyAppProxyRequest","encodePathSegment","mapOnlineStoreToPublicBundleData","SHOPIFY_APP_PROXY_URL","request","options"],"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,GAAIA,kBAAW,EAAA,CAAA;AAC3C,EAAA,MAAM,OAAU,GAAA;AAAA,IACd,mBAAqB,EAAA,qBAAA;AAAA,IACrB,wBAA0B,EAAA,OAAA;AAAA,IAC1B,GAAI,OAAU,GAAA,EAAE,yBAA2B,EAAA,OAAA,KAAY,EAAC;AAAA,IACxD,GAAI,UAAa,GAAA,EAAE,4BAA8B,E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A,MAAM,OAAON,kBAAW,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":["getOptions","shopifyAppProxyRequest","encodePathSegment","mapOnlineStoreToPublicBundleData","SHOPIFY_APP_PROXY_URL","request","options"],"mappings":";;;;;;;;AA0CA,eAAsB,cAAA,CAAe,IAAY,OAAA,EAA8C;AAC7F,EAAA,IAAI,OAAA,EAAS,WAAW,oBAAA,EAAsB;AAC5C,IAAA,OAAO,4BAAA,CAAwC,CAAA;AAAA,EACjD;AAEA,EAAA,OAAO,mBAAA,CAAoB,EAAA,EAAI,OAAA,EAAS,YAAY,CAAA;AACtD;AAKA,eAAe,mBAAA,CAAoB,IAAY,YAAA,EAAkD;AAC/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,CAAkB,EAAE,CAAC,CAAA,CAAA,EAAI;AAAA,MAC9G;AAAA,KACD,CAAA;AACD,IAAA,OAAOC,4CAAiC,IAAI,CAAA;AAAA,EAC9C;AACF;AAKA,eAAe,4BAAA,CAA6B,IAAYG,SAAA,EAA8D;AACpH,EAAA,MAAM,OAAON,kBAAA,EAAW;AAExB,EAAA,IAAI,CAAC,KAAK,eAAA,EAAiB;AACzB,IAAA,MAAM,IAAI,MAAM,kEAAkE,CAAA;AAAA,EACpF;AAGA,EAAA,OAAO,EAAC;AACV;;"}
@@ -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';\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":["cdnRequest","encodePathSegment","productMapper","widgetSettingsMapper","productArrayMapper"],"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,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,MAChFA,mBAAsC,KAAO,EAAA,CA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,CAAA,CAAA;AAAA,GACpC;AAEA,EAAO,OAAA;AAAA,IACL,QAAA,EAAUI,uBAAmB,QAAQ,CAAA;AAAA,IACrC,eAAA,EAAiBD,yBAAqB,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":["cdnRequest","encodePathSegment","productMapper","widgetSettingsMapper","productArrayMapper"],"mappings":";;;;;;AAmBA,MAAM,gBAAA,GAAmB,SAAA;AAGzB,MAAM,sBAAA,GAA2C;AAAA,EAC/C,cAAA,EAAgB;AAAA,IACd,aAAA,EAAe,KAAA;AAAA,IACf,eAAA,EAAiB,GAAA;AAAA,IACjB,iBAAA,EAAmB,GAAA;AAAA,IACnB,mBAAA,EAAqB,GAAA;AAAA,IACrB,wBAAA,EAA0B;AAAA;AAE9B,CAAA;AAEA,MAAM,YAAA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ClB;AACF;AAEA,eAAsB,qBACpB,iBAAA,EAC+C;AAC/C,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,MAAM,cAAc,iBAAiB,CAAA;AAEhE,EAAA,OAAO,cAAA;AACT;AAEA,eAAsB,aAAA,GAAgB;AACpC,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,YAAA,CAAa,IAAA,EAAM,CAAA,CAAE,OAAA,CAAQ,CAAA,GAAA,KAAO,YAAA,CAAa,MAAA,CAAO,GAAG,CAAC,CAAA;AAChF;;;;;;;;;"}
@@ -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';\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":["rechargeApiRequest","getInternalSession","encodePathSegment","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,MAAMA,0BAAA;AAAA,IACvB,KAAA;AAAA,IACA,CAAA,QAAA,CAAA;AAAA,IACA,EAAE,EAAI,EAAA,KAAA,EAAO,EAAE,OAAS,EAAA,OAAA,EAAS,SAAU,EAAA;AAAA,IAC3CC,0BAAA,CAAmB,SAAS,WAAW,CAAA;AAAA,GACzC,CAAA;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAGgB,SAAA,WAAA,CAAY,SAAkB,KAA0B,EAAA;AACtE,EAAO,OAAAD,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,QAAA,CAAA;AAAA,IACA,EAAE,KAAM,EAAA;AAAA,IACRC,0BAAA,CAAmB,SAAS,aAAa,CAAA;AAAA,GAC3C,CAAA;AACF,CAAA;AAMsB,eAAA,qBAAA,CA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AA;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAGsB,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,MAAO,EAAA,GAAI,MAAMD,0BAAA;AAAA,IACvB,MAAA;AAAA,IACA,CAAA,SAAA,EAAYE,qBAAkB,CAAA,EAAE,CAAC,CAAA,QAAA,CAAA;AAAA,IACjC,EAAC;AAAA,IACDD,0BAAA,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,MAAMD,0BAAA;AAAA,IACvB,MAAA;AAAA,IACA,CAAA,SAAA,EAAYE,qBAAkB,CAAA,EAAE,CAAC,CAAA,wBAAA,CAAA;AAAA,IACjC;AAAA,MACE,IAAA,EAAM,EAAE,gBAAA,EAAkB,IAAK,EAAA;AAAA,KACjC;AAAA,IACAD,0BAAA,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":["rechargeApiRequest","getInternalSession","encodePathSegment","id"],"mappings":";;;;;AAaA,eAAsB,SAAA,CAAU,OAAA,EAAkB,EAAA,EAA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AAAA,IACjC;AAAA,MACE,IAAA,EAAM,EAAE,gBAAA,EAAkB,IAAA;AAAK,KACjC;AAAA,IACAD,0BAAA,CAAmB,SAAS,kBAAkB;AAAA,GAChD;AACA,EAAA,OAAO,MAAA;AACT;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"collection.js","sources":["../../../src/api/collection.ts"],"sourcesContent":["import {\n Collection,\n CollectionListParams,\n CollectionsResponse,\n CollectionsSortBy,\n ProductSearchParams_2020_12,\n ProductSearchParams_2022_06,\n Product_2020_12,\n Product_2022_06,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { productSearch } from './product';\n\nexport type ProductListResponse<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06> =\n T extends ProductSearchParams_2020_12 ? { products: Product_2020_12[] } : { products: Product_2022_06[] };\n\nexport async function getCollection(session: Session, id: string | number): Promise<Collection> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { collection } = await rechargeApiRequest<{ collection: Collection }>(\n 'get',\n `/collections`,\n {\n id,\n },\n getInternalSession(session, 'getCollection')\n );\n return collection;\n}\n\nexport function listCollections(session: Session, query?: CollectionListParams): Promise<CollectionsResponse> {\n return rechargeApiRequest<CollectionsResponse>(\n 'get',\n `/collections`,\n { query },\n getInternalSession(session, 'listCollections')\n );\n}\n\nexport async function listCollectionProducts<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06>(\n session: Session,\n id: string | number,\n query: T\n): Promise<ProductListResponse<T>> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n if (!['2020-12', '2022-06'].includes(query.format_version)) {\n throw new Error('Missing or unsupported format_version.');\n }\n\n const internalSession = getInternalSession(session, 'listCollectionProducts');\n const [{ sort_order, manual_sort_order }, { products }] = await Promise.all([\n getCollection(internalSession, id),\n productSearch(internalSession, {\n ...query,\n collection_ids: [id],\n limit: 250,\n }),\n ]);\n if (sort_order === 'manual') {\n return {\n products: manual_sort_order.reduce((prev, curr) => {\n const product = products.find(product => product.external_product_id === curr);\n if (product) {\n // @ts-expect-error types are unhappy with push\n prev.push(product);\n }\n return prev;\n }, [] as Product_2020_12[] | Product_2022_06[]),\n } as ProductListResponse<T>;\n } else {\n const compareFn = getProductCompareFn(sort_order);\n return { products: products.slice().sort(compareFn) } as ProductListResponse<T>;\n }\n}\n\nfunction sortByCreatedAt(a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) {\n const aCreatedAt = a.external_created_at;\n const bCreatedAt = b.external_created_at;\n return aCreatedAt < bCreatedAt ? -1 : bCreatedAt > aCreatedAt ? 1 : 0;\n}\n\nfunction sortById(a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) {\n const aProductId = a.external_product_id;\n const bProductId = b.external_product_id;\n return aProductId < bProductId ? -1 : bProductId > aProductId ? 1 : 0;\n}\n\nfunction sortByTitle(a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) {\n const aTitle = a.title.toLowerCase();\n const bTitle = b.title.toLowerCase();\n return aTitle < bTitle ? -1 : bTitle > aTitle ? 1 : 0;\n}\n\nfunction getProductCompareFn(sortOrder: CollectionsSortBy) {\n switch (sortOrder) {\n case 'created_at-asc':\n return sortByCreatedAt;\n case 'created_at-desc':\n return (a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) => sortByCreatedAt(b, a);\n case 'id-asc':\n return sortById;\n case 'id-desc':\n return (a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) => sortById(b, a);\n case 'title-asc':\n return sortByTitle;\n case 'title-desc':\n return (a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) => sortByTitle(b, a);\n }\n}\n"],"names":["rechargeApiRequest","getInternalSession","productSearch","product"],"mappings":";;;;;AAiBsB,eAAA,aAAA,CAAc,SAAkB,EAA0C,EAAA;AAC9F,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EA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sC,CAAsC,EAAA;AAC/F,EAAM,MAAA,MAAA,GAAS,CAAE,CAAA,KAAA,CAAM,WAAY,EAAA,CAAA;AACnC,EAAM,MAAA,MAAA,GAAS,CAAE,CAAA,KAAA,CAAM,WAAY,EAAA,CAAA;AACnC,EAAA,OAAO,MAAS,GAAA,MAAA,GAAS,CAAK,CAAA,GAAA,MAAA,GAAS,SAAS,CAAI,GAAA,CAAA,CAAA;AACtD,CAAA;AAEA,SAAS,oBAAoB,SAA8B,EAAA;AACzD,EAAA,QAAQ,SAAW;AAAA,IACjB,KAAK,gBAAA;AACH,MAAO,OAAA,eAAA,CAAA;AAAA,IACT,KAAK,iBAAA;AACH,MAAA,OAAO,CAAC,CAAA,EAAsC,CAAyC,KAAA,eAAA,CAAgB,GAAG,CAAC,CAAA,CAAA;AAAA,IAC7G,KAAK,QAAA;AACH,MAAO,OAAA,QAAA,CAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAA,OAAO,CAAC,CAAA,EAAsC,CAAyC,KAAA,QAAA,CAAS,GAAG,CAAC,CAAA,CAAA;AAAA,IACtG,KAAK,WAAA;AACH,MAAO,OAAA,WAAA,CAAA;AAAA,IACT,KAAK,YAAA;AACH,MAAA,OAAO,CAAC,CAAA,EAAsC,CAAyC,KAAA,WAAA,CAAY,GAAG,CAAC,CAAA,CAAA;AAAA,GAC3G;AACF;;;;;;"}
1
+ {"version":3,"file":"collection.js","sources":["../../../src/api/collection.ts"],"sourcesContent":["import {\n Collection,\n CollectionListParams,\n CollectionsResponse,\n CollectionsSortBy,\n ProductSearchParams_2020_12,\n ProductSearchParams_2022_06,\n Product_2020_12,\n Product_2022_06,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { productSearch } from './product';\n\nexport type ProductListResponse<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06> =\n T extends ProductSearchParams_2020_12 ? { products: Product_2020_12[] } : { products: Product_2022_06[] };\n\nexport async function getCollection(session: Session, id: string | number): Promise<Collection> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { collection } = await rechargeApiRequest<{ collection: Collection }>(\n 'get',\n `/collections`,\n {\n id,\n },\n getInternalSession(session, 'getCollection')\n );\n return collection;\n}\n\nexport function listCollections(session: Session, query?: CollectionListParams): Promise<CollectionsResponse> {\n return rechargeApiRequest<CollectionsResponse>(\n 'get',\n `/collections`,\n { query },\n getInternalSession(session, 'listCollections')\n );\n}\n\nexport async function listCollectionProducts<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06>(\n session: Session,\n id: string | number,\n query: T\n): Promise<ProductListResponse<T>> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n if (!['2020-12', '2022-06'].includes(query.format_version)) {\n throw new Error('Missing or unsupported format_version.');\n }\n\n const internalSession = getInternalSession(session, 'listCollectionProducts');\n const [{ sort_order, manual_sort_order }, { products }] = await Promise.all([\n getCollection(internalSession, id),\n productSearch(internalSession, {\n ...query,\n collection_ids: [id],\n limit: 250,\n }),\n ]);\n if (sort_order === 'manual') {\n return {\n products: manual_sort_order.reduce((prev, curr) => {\n const product = products.find(product => product.external_product_id === curr);\n if (product) {\n // @ts-expect-error types are unhappy with push\n prev.push(product);\n }\n return prev;\n }, [] as Product_2020_12[] | Product_2022_06[]),\n } as ProductListResponse<T>;\n } else {\n const compareFn = getProductCompareFn(sort_order);\n return { products: products.slice().sort(compareFn) } as ProductListResponse<T>;\n }\n}\n\nfunction sortByCreatedAt(a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) {\n const aCreatedAt = a.external_created_at;\n const bCreatedAt = b.external_created_at;\n return aCreatedAt < bCreatedAt ? -1 : bCreatedAt > aCreatedAt ? 1 : 0;\n}\n\nfunction sortById(a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) {\n const aProductId = a.external_product_id;\n const bProductId = b.external_product_id;\n return aProductId < bProductId ? -1 : bProductId > aProductId ? 1 : 0;\n}\n\nfunction sortByTitle(a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) {\n const aTitle = a.title.toLowerCase();\n const bTitle = b.title.toLowerCase();\n return aTitle < bTitle ? -1 : bTitle > aTitle ? 1 : 0;\n}\n\nfunction getProductCompareFn(sortOrder: CollectionsSortBy) {\n switch (sortOrder) {\n case 'created_at-asc':\n return sortByCreatedAt;\n case 'created_at-desc':\n return (a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) => sortByCreatedAt(b, a);\n case 'id-asc':\n return sortById;\n case 'id-desc':\n return (a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) => sortById(b, a);\n case 'title-asc':\n return sortByTitle;\n case 'title-desc':\n return (a: Product_2020_12 | Product_2022_06, b: Product_2020_12 | Product_2022_06) => sortByTitle(b, a);\n }\n}\n"],"names":["rechargeApiRequest","getInternalSession","productSearch","product"],"mappings":";;;;;AAiBA,eAAsB,aAAA,CAAc,SAAkB,EAAA,EAA0C;AAC9F,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,UAAA,EAAW,GAAI,MAAMA,0BAAA;AAAA,IAC3B,KAAA;AAAA,IACA,CAAA,YAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACAC,0BAAA,CAAmB,SAAS,eAAe;AAAA,GAC7C;AACA,EAAA,OAAO,UAAA;AACT;AAEO,SAAS,eAAA,CAAgB,SAAkB,KAAA,EAA4D;AAC5G,EAAA,OAAOD,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,YAAA,CAAA;AAAA,IACA,EAAE,KAAA,EAAM;AAAA,IACRC,0BAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACF;AAEA,eAAsB,sBAAA,CACpB,OAAA,EACA,EAAA,EACA,KAAA,EACiC;AACjC,EAAA,IAAI,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A;AAE7G;;;;"}
@@ -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 { 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":["rechargeApiRequest","encodePathSegment","getInternalSession","updateCustomer"],"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,MAAMA,0BAAA;AAAA,IAC/B,KAAA;AAAA,IACA,CAAA,WAAA,EAAcC,qBAAkB,CAAA,EAAE,CAAC,CAAA,eAAA,CAAA;AAAA,IACnC;AAAA,MACE,OAAO,EAAE,OAAA,EAAS,SAAS,OAAS,EAAA,yBAAA,EAA2B,SAAS,yBAA0B,EAAA;AAAA,KACpG;AAAA,IACAC,0BAAA,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,OAAOC,uBAAe,CAAAD,0BAAA,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;AAIA,EAAA,MAAM,EAAE,WAAa,EAAA,kBAAA,EAAoB,GAAG,SAAU,EAAA,GAAK,SAAS,EAAC,CAAA;AAGrE,EAAA,MAAM,WAAW,MAAMF,0BAAA;AAAA,IACrB,KAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA,MACE,KAAO,EAAA,EAAE,GAAG,SAAA,EAAW,WAAY,EAAA;AAAA,KACrC;AAAA,IACAE,0BAAA,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":["rechargeApiRequest","encodePathSegment","getInternalSession","updateCustomer"],"mappings":";;;;;;AAcA,eAAsB,gBAAA,CACpB,SACA,OAAA,EACgC;AAChC,EAAA,MAAM,KAAK,OAAA,CAAQ,UAAA;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACP,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,MAAMA,0BAAA;AAAA,IAC/B,KAAA;AAAA,IACA,CAAA,WAAA,EAAcC,qBAAA,CAAkB,EAAE,CAAC,CAAA,eAAA,CAAA;AAAA,IACnC;AAAA,MACE,OAAO,EAAE,OAAA,EAAS,SAAS,OAAA,EAAS,yBAAA,EAA2B,SAAS,yBAAA;AAA0B,KACpG;AAAA,IACAC,0BAAA,CAAmB,SAAS,kBAAkB;AAAA,GAChD;AACA,EAAA,OAAO,cAAA;AACT;AAEO,SAAS,2BAAA,CAA4B,OAAA,EAAkB,EAAE,SAAA,EAAU,EAA0C;AAClH,EAAA,MAAM,KAAK,OAAA,CAAQ,UAAA;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACP,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,gBAAuC,EAAC;AAC9C,EAAA,IAAI,cAAc,MAAA,EAAW;AAC3B,IAAA,aAAA,CAAc,qCAAA,GAAwC,SAAA;AAAA,EACxD;AACA,EAAA,OAAOC,uBAAA,CAAeD,0BAAA,CAAmB,OAAA,EAAS,6BAA6B,GAAG,aAAa,CAAA;AACjG;AAEA,eAAsB,kBAAA,CACpB,SACA,KAAA,EACiC;AACjC,EAAA,MAAM,cAAc,OAAA,CAAQ,UAAA;AAC5B,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AAIA,EAAA,MAAM,EAAE,WAAA,EAAa,kBAAA,EAAoB,GAAG,SAAA,EAAU,GAAK,SAAS,EAAC;AAGrE,EAAA,MAAM,WAAW,MAAMF,0BAAA;AAAA,IACrB,KAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO,EAAE,GAAG,SAAA,EAAW,WAAA;AAAY,KACrC;AAAA,IACAE,0BAAA,CAAmB,SAAS,oBAAoB;AAAA,GAClD;AACA,EAAA,OAAO,QAAA;AACT;;;;"}
@@ -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';\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\nfunction getLandingPagesBaseURL(portalBaseURL: string): string {\n return portalBaseURL.replace(/\\/portal\\/?$/, '/pages/');\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 `${getLandingPagesBaseURL(\n base_url\n )}${customer_hash}/subscriptions/${subscriptionId}/cancel?token=${temp_token}&subscription=${subscriptionId}&redirect_to=${encodeURIComponent(\n redirectURL\n )}`;\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 `${getLandingPagesBaseURL(base_url)}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 `${getLandingPagesBaseURL(\n base_url\n )}${customer_hash}/gifts/${giftId}?token=${temp_token}&redirect_to=${encodeURIComponent(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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"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,MAAMA,0BAAA;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,IACAC,0BAAA,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,EAAI,EAAA;AACP,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,QAAS,EAAA,GAAI,MAAMD,0BAAA;AAAA,IACzB,KAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA,EAAE,EAAI,EAAA,IAAA,EAAM,aAAc,EAAA;AAAA,IAC1BC,0BAAA,CAAmB,SAAS,gBAAgB,CAAA;AAAA,GAC9C,CAAA;AACA,EAAO,OAAA,QAAA,CAAA;AACT,CAAA;AAEsB,eAAA,mBAAA,CACpB,SACA,KACqB,EAAA;AACrB,EAAA,MAAM,KAAK,OAAQ,CAAA,UA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AA;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,OAAAD,0BAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,WAAA,EAAcE,qBAAkB,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,IACAD,0BAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;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\nfunction getLandingPagesBaseURL(portalBaseURL: string): string {\n return portalBaseURL.replace(/\\/portal\\/?$/, '/pages/');\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 `${getLandingPagesBaseURL(\n base_url\n )}${customer_hash}/subscriptions/${subscriptionId}/cancel?token=${temp_token}&subscription=${subscriptionId}&redirect_to=${encodeURIComponent(\n redirectURL\n )}`;\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 `${getLandingPagesBaseURL(base_url)}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 `${getLandingPagesBaseURL(\n base_url\n )}${customer_hash}/gifts/${giftId}?token=${temp_token}&redirect_to=${encodeURIComponent(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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AAoBA,eAAsB,WAAA,CAAY,SAAkB,OAAA,EAAiD;AACnG,EAAA,MAAM,KAAK,OAAA,CAAQ,UAAA;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACP,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAMA,0BAAA;AAAA,IACzB,KAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,KAAA,EAAO,EAAE,OAAA,EAAS,OAAA,EAAS,OAAA;AAAQ,KACrC;AAAA,IACAC,0BAAA,CAAmB,SAAS,aAAa;AAAA,GAC3C;AACA,EAAA,OAAO,QAAA;AACT;AAEA,eAAsB,cAAA,CAAe,SAAkB,aAAA,EAAyD;AAC9G,EAAA,MAAM,KAAK,OAAA,CAAQ,UAAA;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACP,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAMD,0BAAA;AAAA,IACzB,KAAA;AAAA,IACA,CAAA,UAAA,CAAA;AAAA,IACA,EAAE,EAAA,EAAI,IAAA,EAAM,aAAA,EAAc;AAAA,IAC1BC,0BAAA,CAAmB,SAAS,gBAAgB;AAAA,GAC9C;AACA,EAAA,OAAO,QAAA;AACT;AAEA,eAAsB,mBAAA,CACpB,SACA,KAAA,EACqB;AACrB,EAAA,MAAM,KAAK,OAAA,CAAQ,UAAA;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACP,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,UAAA,EAAW,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AAA;AAAA,IACA,CAAA,WAAA,EAAcE,qBAAA,CAAkB,UAAU,CAAC,CAAA,cAAA,CAAA;AAAA,IAC3C;AAAA,MACE,IAAA,EAAM;AAAA,QACJ,GAAG,IAAA;AAAA,QACH,aAAA,EAAe;AAAA;AACjB,KACF;AAAA,IACAD,0BAAA,CAAmB,SAAS,0BAA0B;AAAA,GACxD;AACF;;;;;;;;;"}
@@ -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';\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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AASsB,eAAA,wBAAA,CAAyB,OAAkB,EAAA,UAAA,EAAoB,cAAwB,EAAA;AAC3G,EAAA,MAAM,iCAAiC,MAAMA,0BAAA;AAAA,IAC3C,MAAA;AAAA,IACA,CAAA,yCAAA,CAAA;AAAA,IACA,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,eAAA,EAAiB,gBAAiB,EAAA;AAAA,IACrEC,0BAAA,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,MAAMD,0BAAA;AAAA,IAC1C,MAAA;AAAA,IACA,CAAA,kBAAA,EAAqBE,qBAAkB,CAAA,gBAAgB,CAAC,CAAA,kBAAA,CAAA;AAAA,IACxD,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,WAAA,EAAa,YAAa,EAAA;AAAA,IAC7DD,0BAAA,CAAmB,SAAS,yBAAyB,CAAA;AAAA,GACvD,CAAA;AACA,EAAO,OAAA,6BAAA,CAAA;AACT,CAAA;AAEsB,eAAA,wBAAA,CAAyB,SAAkB,OAAoC,EAAA;AACnG,EAAM,MAAAD,0BAAA;AAAA,IACJ,MAAA;AAAA,IACA,CAAA,aAAA,CAAA;AAAA,IACA,EAAE,MAAM,OAAQ,EAAA;AAAA,IAChBC,0BAAA,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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AASA,eAAsB,wBAAA,CAAyB,OAAA,EAAkB,UAAA,EAAoB,cAAA,EAAwB;AAC3G,EAAA,MAAM,iCAAiC,MAAMA,0BAAA;AAAA,IAC3C,MAAA;AAAA,IACA,CAAA,yCAAA,CAAA;AAAA,IACA,EAAE,IAAA,EAAM,EAAE,aAAa,UAAA,EAAY,eAAA,EAAiB,gBAAe,EAAE;AAAA,IACrEC,0BAAA,CAAmB,SAAS,0BAA0B;AAAA,GACxD;AACA,EAAA,OAAO,8BAAA;AACT;AAEA,eAAsB,uBAAA,CACpB,OAAA,EACA,UAAA,EACA,gBAAA,EACA,UAAA,EACA;AACA,EAAA,MAAM,gCAAgC,MAAMD,0BAAA;AAAA,IAC1C,MAAA;AAAA,IACA,CAAA,kBAAA,EAAqBE,qBAAA,CAAkB,gBAAgB,CAAC,CAAA,kBAAA,CAAA;AAAA,IACxD,EAAE,IAAA,EAAM,EAAE,aAAa,UAAA,EAAY,WAAA,EAAa,YAAW,EAAE;AAAA,IAC7DD,0BAAA,CAAmB,SAAS,yBAAyB;AAAA,GACvD;AACA,EAAA,OAAO,6BAAA;AACT;AAEA,eAAsB,wBAAA,CAAyB,SAAkB,OAAA,EAAoC;AACnG,EAAA,MAAMD,0BAAA;AAAA,IACJ,MAAA;AAAA,IACA,CAAA,aAAA,CAAA;AAAA,IACA,EAAE,MAAM,OAAA,EAAQ;AAAA,IAChBC,0BAAA,CAAmB,SAAS,0BAA0B;AAAA,GACxD;AACA,EAAA,OAAO,EAAC;AACV;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"flow.js","sources":["../../../src/api/flow.ts"],"sourcesContent":["import { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n CustomerPortalFlowAction,\n Session,\n TriggerCustomerPortalFlowOptions,\n TriggerCustomerPortalFlowResponse,\n} from '../types';\n\n/**\n * Trigger the store's active customer portal flow for a subscription.\n *\n * The flow is queued, not finished: a successful result only means the job was enqueued.\n *\n * Works with a customer portal session (only for that customer's own subscriptions), or with an\n * API token that has both the `read_subscriptions` and `write_flows` scopes.\n *\n * The store needs the `enable_customer_portal_triggered_flows` beta flag and an active\n * `customer_portal_triggered_flow` with trigger `subscription/unpack` and `limits.max_times_per_customer: -1`.\n *\n * Pass `options.flow_id` to run only that flow. The 24h cooldown is per subscription and action, not per flow.\n *\n * Throws a `RechargeRequestError` with one of these statuses on failure:\n * - `403`: the feature is not enabled for the store, or the token is missing a scope. Not retryable.\n * - `404`: the subscription does not exist or does not belong to the customer.\n * - `422` \"Unable to trigger flows, please try again\": temporary, safe to retry. Any other `422` means the action was invalid.\n * - `429`: this subscription was already triggered for this action in the last 24h. Treat it as already done rather than retrying.\n */\nexport async function triggerCustomerPortalFlow(\n session: Session,\n subscriptionId: string | number,\n action: CustomerPortalFlowAction,\n options?: TriggerCustomerPortalFlowOptions\n): Promise<TriggerCustomerPortalFlowResponse> {\n if (subscriptionId === undefined || subscriptionId === '') {\n throw new Error('Subscription ID is required');\n }\n return rechargeApiRequest<TriggerCustomerPortalFlowResponse>(\n 'post',\n `/flows/customer_portal_flow/subscription/${encodePathSegment(subscriptionId)}`,\n { query: { action, flow_id: options?.flow_id }, data: {} },\n getInternalSession(session, 'triggerCustomerPortalFlow')\n );\n}\n"],"names":["rechargeApiRequest","encodePathSegment","getInternalSession"],"mappings":";;;;;AA4BA,eAAsB,yBACpB,CAAA,OAAA,EACA,cACA,EAAA,MAAA,EACA,OAC4C,EAAA;AAC5C,EAAI,IAAA,cAAA,KAAmB,KAAa,CAAA,IAAA,cAAA,KAAmB,EAAI,EAAA;AACzD,IAAM,MAAA,IAAI,MAAM,6BAA6B,CAAA,CAAA;AAAA,GAC/C;AACA,EAAO,OAAAA,0BAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,yCAAA,EAA4CC,qBAAkB,CAAA,cAAc,CAAC,CAAA,CAAA;AAAA,IAC7E,EAAE,KAAO,EAAA,EAAE,MAAQ,EAAA,OAAA,EAAS,SAAS,OAAQ,EAAA,EAAG,IAAM,EAAA,EAAG,EAAA;AAAA,IACzDC,0BAAA,CAAmB,SAAS,2BAA2B,CAAA;AAAA,GACzD,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"flow.js","sources":["../../../src/api/flow.ts"],"sourcesContent":["import { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n CustomerPortalFlowAction,\n Session,\n TriggerCustomerPortalFlowOptions,\n TriggerCustomerPortalFlowResponse,\n} from '../types';\n\n/**\n * Trigger the store's active customer portal flow for a subscription.\n *\n * The flow is queued, not finished: a successful result only means the job was enqueued.\n *\n * Works with a customer portal session (only for that customer's own subscriptions), or with an\n * API token that has both the `read_subscriptions` and `write_flows` scopes.\n *\n * The store needs the `enable_customer_portal_triggered_flows` beta flag and an active\n * `customer_portal_triggered_flow` with trigger `subscription/unpack` and `limits.max_times_per_customer: -1`.\n *\n * Pass `options.flow_id` to run only that flow. The 24h cooldown is per subscription and action, not per flow.\n *\n * Throws a `RechargeRequestError` with one of these statuses on failure:\n * - `403`: the feature is not enabled for the store, or the token is missing a scope. Not retryable.\n * - `404`: the subscription does not exist or does not belong to the customer.\n * - `422` \"Unable to trigger flows, please try again\": temporary, safe to retry. Any other `422` means the action was invalid.\n * - `429`: this subscription was already triggered for this action in the last 24h. Treat it as already done rather than retrying.\n */\nexport async function triggerCustomerPortalFlow(\n session: Session,\n subscriptionId: string | number,\n action: CustomerPortalFlowAction,\n options?: TriggerCustomerPortalFlowOptions\n): Promise<TriggerCustomerPortalFlowResponse> {\n if (subscriptionId === undefined || subscriptionId === '') {\n throw new Error('Subscription ID is required');\n }\n return rechargeApiRequest<TriggerCustomerPortalFlowResponse>(\n 'post',\n `/flows/customer_portal_flow/subscription/${encodePathSegment(subscriptionId)}`,\n { query: { action, flow_id: options?.flow_id }, data: {} },\n getInternalSession(session, 'triggerCustomerPortalFlow')\n );\n}\n"],"names":["rechargeApiRequest","encodePathSegment","getInternalSession"],"mappings":";;;;;AA4BA,eAAsB,yBAAA,CACpB,OAAA,EACA,cAAA,EACA,MAAA,EACA,OAAA,EAC4C;AAC5C,EAAA,IAAI,cAAA,KAAmB,MAAA,IAAa,cAAA,KAAmB,EAAA,EAAI;AACzD,IAAA,MAAM,IAAI,MAAM,6BAA6B,CAAA;AAAA,EAC/C;AACA,EAAA,OAAOA,0BAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,yCAAA,EAA4CC,qBAAA,CAAkB,cAAc,CAAC,CAAA,CAAA;AAAA,IAC7E,EAAE,KAAA,EAAO,EAAE,MAAA,EAAQ,OAAA,EAAS,SAAS,OAAA,EAAQ,EAAG,IAAA,EAAM,EAAC,EAAE;AAAA,IACzDC,0BAAA,CAAmB,SAAS,2BAA2B;AAAA,GACzD;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"gift.js","sources":["../../../src/api/gift.ts"],"sourcesContent":["import { GiftPurchase, GiftPurchasesParams, GiftPurchasesResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport function listGiftPurchases(session: Session, options?: GiftPurchasesParams): Promise<GiftPurchasesResponse> {\n if (!session.customerId) {\n throw new Error('Not logged in.');\n }\n return rechargeApiRequest<GiftPurchasesResponse>(\n 'get',\n `/gift_purchases`,\n {\n query: options,\n },\n getInternalSession(session, 'listGiftPurchases')\n );\n}\n\nexport async function getGiftPurchase(session: Session, id: string | number): Promise<GiftPurchase> {\n if (!session.customerId) {\n throw new Error('Not logged in.');\n }\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { gift_purchase } = await rechargeApiRequest<{ gift_purchase: GiftPurchase }>(\n 'get',\n `/gift_purchases`,\n {\n id,\n },\n getInternalSession(session, 'getGiftPurchase')\n );\n return gift_purchase;\n}\n"],"names":["rechargeApiRequest","getInternalSession"],"mappings":";;;;AAGgB,SAAA,iBAAA,CAAkB,SAAkB,OAA+D,EAAA;AACjH,EAAI,IAAA,CAAC,QAAQ,UAAY,EAAA;AACvB,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAO,OAAAA,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAO,EAAA,OAAA;AAAA,KACT;AAAA,IACAC,0BAAA,CAAmB,SAAS,mBAAmB,CAAA;AAAA,GACjD,CAAA;AACF,CAAA;AAEsB,eAAA,eAAA,CAAgB,SAAkB,EAA4C,EAAA;AAClG,EAAI,IAAA,CAAC,QAAQ,UAAY,EAAA;AACvB,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,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,aAAc,EAAA,GAAI,MAAMD,0BAAA;AAAA,IAC9B,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,KACF;AAAA,IACAC,0BAAA,CAAmB,SAAS,iBAAiB,CAAA;AAAA,GAC/C,CAAA;AACA,EAAO,OAAA,aAAA,CAAA;AACT;;;;;"}
1
+ {"version":3,"file":"gift.js","sources":["../../../src/api/gift.ts"],"sourcesContent":["import { GiftPurchase, GiftPurchasesParams, GiftPurchasesResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport function listGiftPurchases(session: Session, options?: GiftPurchasesParams): Promise<GiftPurchasesResponse> {\n if (!session.customerId) {\n throw new Error('Not logged in.');\n }\n return rechargeApiRequest<GiftPurchasesResponse>(\n 'get',\n `/gift_purchases`,\n {\n query: options,\n },\n getInternalSession(session, 'listGiftPurchases')\n );\n}\n\nexport async function getGiftPurchase(session: Session, id: string | number): Promise<GiftPurchase> {\n if (!session.customerId) {\n throw new Error('Not logged in.');\n }\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { gift_purchase } = await rechargeApiRequest<{ gift_purchase: GiftPurchase }>(\n 'get',\n `/gift_purchases`,\n {\n id,\n },\n getInternalSession(session, 'getGiftPurchase')\n );\n return gift_purchase;\n}\n"],"names":["rechargeApiRequest","getInternalSession"],"mappings":";;;;AAGO,SAAS,iBAAA,CAAkB,SAAkB,OAAA,EAA+D;AACjH,EAAA,IAAI,CAAC,QAAQ,UAAA,EAAY;AACvB,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,OAAOA,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO;AAAA,KACT;AAAA,IACAC,0BAAA,CAAmB,SAAS,mBAAmB;AAAA,GACjD;AACF;AAEA,eAAsB,eAAA,CAAgB,SAAkB,EAAA,EAA4C;AAClG,EAAA,IAAI,CAAC,QAAQ,UAAA,EAAY;AACvB,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,aAAA,EAAc,GAAI,MAAMD,0BAAA;AAAA,IAC9B,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACAC,0BAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACA,EAAA,OAAO,aAAA;AACT;;;"}