@rechargeapps/storefront-client 2.6.1 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/address.js.map +1 -1
- package/dist/cjs/api/auth.js +1 -1
- package/dist/cjs/api/auth.js.map +1 -1
- package/dist/cjs/api/bundle.js +0 -1
- package/dist/cjs/api/bundle.js.map +1 -1
- package/dist/cjs/api/bundleData.js +1 -1
- package/dist/cjs/api/bundleData.js.map +1 -1
- package/dist/cjs/api/cdn.js.map +1 -1
- package/dist/cjs/api/charge.js.map +1 -1
- package/dist/cjs/api/collection.js.map +1 -1
- package/dist/cjs/api/credit.js.map +1 -1
- package/dist/cjs/api/customer.js.map +1 -1
- package/dist/cjs/api/customerSurveys.js.map +1 -1
- package/dist/cjs/api/flow.js.map +1 -1
- package/dist/cjs/api/gift.js.map +1 -1
- package/dist/cjs/api/membership.js.map +1 -1
- package/dist/cjs/api/membershipProgram.js.map +1 -1
- package/dist/cjs/api/metafield.js.map +1 -1
- package/dist/cjs/api/onetime.js.map +1 -1
- package/dist/cjs/api/order.js.map +1 -1
- package/dist/cjs/api/paymentMethod.js.map +1 -1
- package/dist/cjs/api/plan.js.map +1 -1
- package/dist/cjs/api/product.js.map +1 -1
- package/dist/cjs/api/store.js.map +1 -1
- package/dist/cjs/api/subscription.js.map +1 -1
- package/dist/cjs/api/tieredDiscount.js +0 -6
- package/dist/cjs/api/tieredDiscount.js.map +1 -1
- package/dist/cjs/constants/api.js.map +1 -1
- package/dist/cjs/mappers/cdn.js.map +1 -1
- package/dist/cjs/mappers/subscription.js.map +1 -1
- package/dist/cjs/mappers/utils.js.map +1 -1
- package/dist/cjs/utils/bundle.js +28 -51
- package/dist/cjs/utils/bundle.js.map +1 -1
- package/dist/cjs/utils/bundleData.js +4 -8
- package/dist/cjs/utils/bundleData.js.map +1 -1
- package/dist/cjs/utils/error.js.map +1 -1
- package/dist/cjs/utils/id.js.map +1 -1
- package/dist/cjs/utils/init.js.map +1 -1
- package/dist/cjs/utils/loadSpreedlyScript.js +34 -20
- package/dist/cjs/utils/loadSpreedlyScript.js.map +1 -1
- package/dist/cjs/utils/options.js.map +1 -1
- package/dist/cjs/utils/request.js +1 -1
- package/dist/cjs/utils/request.js.map +1 -1
- package/dist/cjs/utils/url.js.map +1 -1
- package/dist/esm/api/address.js +1 -1
- package/dist/esm/api/address.js.map +1 -1
- package/dist/esm/api/auth.js +1 -1
- package/dist/esm/api/auth.js.map +1 -1
- package/dist/esm/api/bundle.js +1 -2
- package/dist/esm/api/bundle.js.map +1 -1
- package/dist/esm/api/bundleData.js +1 -1
- package/dist/esm/api/bundleData.js.map +1 -1
- package/dist/esm/api/cdn.js.map +1 -1
- package/dist/esm/api/charge.js.map +1 -1
- package/dist/esm/api/collection.js.map +1 -1
- package/dist/esm/api/credit.js.map +1 -1
- package/dist/esm/api/customer.js +1 -1
- package/dist/esm/api/customer.js.map +1 -1
- package/dist/esm/api/customerSurveys.js.map +1 -1
- package/dist/esm/api/flow.js.map +1 -1
- package/dist/esm/api/gift.js.map +1 -1
- package/dist/esm/api/membership.js.map +1 -1
- package/dist/esm/api/membershipProgram.js.map +1 -1
- package/dist/esm/api/metafield.js.map +1 -1
- package/dist/esm/api/onetime.js.map +1 -1
- package/dist/esm/api/order.js.map +1 -1
- package/dist/esm/api/paymentMethod.js.map +1 -1
- package/dist/esm/api/plan.js.map +1 -1
- package/dist/esm/api/product.js.map +1 -1
- package/dist/esm/api/store.js.map +1 -1
- package/dist/esm/api/subscription.js.map +1 -1
- package/dist/esm/api/tieredDiscount.js +0 -6
- package/dist/esm/api/tieredDiscount.js.map +1 -1
- package/dist/esm/constants/api.js.map +1 -1
- package/dist/esm/mappers/cdn.js.map +1 -1
- package/dist/esm/mappers/subscription.js.map +1 -1
- package/dist/esm/mappers/utils.js.map +1 -1
- package/dist/esm/utils/bundle.js +29 -52
- package/dist/esm/utils/bundle.js.map +1 -1
- package/dist/esm/utils/bundleData.js +4 -8
- package/dist/esm/utils/bundleData.js.map +1 -1
- package/dist/esm/utils/error.js.map +1 -1
- package/dist/esm/utils/id.js.map +1 -1
- package/dist/esm/utils/init.js.map +1 -1
- package/dist/esm/utils/loadSpreedlyScript.js +34 -20
- package/dist/esm/utils/loadSpreedlyScript.js.map +1 -1
- package/dist/esm/utils/options.js.map +1 -1
- package/dist/esm/utils/request.js +2 -2
- package/dist/esm/utils/request.js.map +1 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/umd/recharge-client.min.js +2 -2
- package/package.json +11 -10
|
@@ -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":[],"mappings":";;;
|
|
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":[],"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,MAAM,kBAAA;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,IACA,kBAAA,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,E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AAA,CACpB,OAAA,EACA,YAAA,EACA,OAAA,EACe;AACf,EAAA,MAAM,aAAa,OAAA,CAAQ,UAAA;AAC3B,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AAIA,EAAA,IAAI,CAAC,MAAA,CAAO,SAAA,CAAU,eAAe,IAAA,CAAK,uBAAA,EAAyB,YAAY,CAAA,EAAG;AAChF,IAAA,MAAM,IAAI,MAAM,6BAA6B,CAAA;AAAA,EAC/C;AACA,EAAA,MAAM,IAAA,GAAO,wBAAwB,YAAY,CAAA;AACjD,EAAA,OAAO,kBAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,WAAA,EAAc,iBAAA,CAAkB,UAAU,CAAC,CAAA,cAAA,CAAA;AAAA,IAC3C;AAAA,MACE,IAAA,EAAM;AAAA,QACJ,GAAG,IAAA;AAAA,QACH,aAAA,EAAe;AAAA;AACjB,KACF;AAAA,IACA,kBAAA,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":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"customerSurveys.js","sources":["../../../src/api/customerSurveys.ts"],"sourcesContent":["import {\n Session,\n CustomerSurveyOffersResponse,\n CustomerSurveyReasonsResponse,\n CustomerSurveyOfferParams,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getCustomerSurveyReasons(session: Session, customerId: number, subscriptionId: number) {\n const customerSurveysReasonsResponse = await rechargeApiRequest<CustomerSurveyReasonsResponse>(\n 'post',\n `/customer_surveys/cancellation_prevention`,\n { data: { customer_id: customerId, subscription_id: subscriptionId } },\n getInternalSession(session, 'getCustomerSurveyReasons')\n );\n return customerSurveysReasonsResponse;\n}\n\nexport async function getCustomerSurveyOffers(\n session: Session,\n customerId: number,\n customerSurveyId: number,\n responseId: number\n) {\n const customerSurveysOffersResponse = await rechargeApiRequest<CustomerSurveyOffersResponse>(\n 'post',\n `/customer_surveys/${encodePathSegment(customerSurveyId)}/customer_response`,\n { data: { customer_id: customerId, response_id: responseId } },\n getInternalSession(session, 'getCustomerSurveyOffers')\n );\n return customerSurveysOffersResponse;\n}\n\nexport async function claimOfferCustomerSurvey(session: Session, payload: CustomerSurveyOfferParams) {\n await rechargeApiRequest(\n 'post',\n `/offers/claim`,\n { data: payload },\n getInternalSession(session, 'claimOfferCustomerSurvey')\n );\n return {};\n}\n"],"names":[],"mappings":";;;AASA,eAAsB,wBAAA,CAAyB,OAAA,EAAkB,UAAA,EAAoB,cAAA,EAAwB;AAC3G,EAAA,MAAM,iCAAiC,MAAM,kBAAA;AAAA,IAC3C,MAAA;AAAA,IACA,CAAA,yCAAA,CAAA;AAAA,IACA,EAAE,IAAA,EAAM,EAAE,aAAa,UAAA,EAAY,eAAA,EAAiB,gBAAe,EAAE;AAAA,IACrE,kBAAA,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,MAAM,kBAAA;AAAA,IAC1C,MAAA;AAAA,IACA,CAAA,kBAAA,EAAqB,iBAAA,CAAkB,gBAAgB,CAAC,CAAA,kBAAA,CAAA;AAAA,IACxD,EAAE,IAAA,EAAM,EAAE,aAAa,UAAA,EAAY,WAAA,EAAa,YAAW,EAAE;AAAA,IAC7D,kBAAA,CAAmB,SAAS,yBAAyB;AAAA,GACvD;AACA,EAAA,OAAO,6BAAA;AACT;AAEA,eAAsB,wBAAA,CAAyB,SAAkB,OAAA,EAAoC;AACnG,EAAA,MAAM,kBAAA;AAAA,IACJ,MAAA;AAAA,IACA,CAAA,aAAA,CAAA;AAAA,IACA,EAAE,MAAM,OAAA,EAAQ;AAAA,IAChB,kBAAA,CAAmB,SAAS,0BAA0B;AAAA,GACxD;AACA,EAAA,OAAO,EAAC;AACV;;"}
|
package/dist/esm/api/flow.js.map
CHANGED
|
@@ -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":[],"mappings":";;;AA4BA,eAAsB,
|
|
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":[],"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,OAAO,kBAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,yCAAA,EAA4C,iBAAA,CAAkB,cAAc,CAAC,CAAA,CAAA;AAAA,IAC7E,EAAE,KAAA,EAAO,EAAE,MAAA,EAAQ,OAAA,EAAS,SAAS,OAAA,EAAQ,EAAG,IAAA,EAAM,EAAC,EAAE;AAAA,IACzD,kBAAA,CAAmB,SAAS,2BAA2B;AAAA,GACzD;AACF;;"}
|
package/dist/esm/api/gift.js.map
CHANGED
|
@@ -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":[],"mappings":";;
|
|
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":[],"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,OAAO,kBAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO;AAAA,KACT;AAAA,IACA,kBAAA,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,MAAM,kBAAA;AAAA,IAC9B,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACA,EAAA,OAAO,aAAA;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership.js","sources":["../../../src/api/membership.ts"],"sourcesContent":["import {\n ActivateMembershipRequest,\n CancelMembershipRequest,\n ChangeMembershipRequest,\n MembershipListParams,\n MembershipListResponse,\n MembershipResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\n/** @internal Retrieves membership information for passed in id */\nexport async function getMembership(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'get',\n `/memberships`,\n { id },\n getInternalSession(session, 'getMembership')\n );\n return membership;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMemberships(session: Session, query?: MembershipListParams) {\n return rechargeApiRequest<MembershipListResponse>(\n 'get',\n `/memberships`,\n { query },\n getInternalSession(session, 'listMemberships')\n );\n}\n\n/** @internal Cancels a membership */\nexport async function cancelMembership(session: Session, id: string | number, cancelRequest: CancelMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/cancel`,\n {\n data: cancelRequest,\n },\n getInternalSession(session, 'cancelMembership')\n );\n return membership;\n}\n\n/** @internal Activates a membership */\nexport async function activateMembership(\n session: Session,\n id: string | number,\n activateRequest: ActivateMembershipRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/activate`,\n {\n data: activateRequest,\n },\n getInternalSession(session, 'activateMembership')\n );\n return membership;\n}\n\n/** @internal changes a membership program/product*/\nexport async function changeMembership(session: Session, id: string | number, changeRequest: ChangeMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/change`,\n {\n data: changeRequest,\n },\n getInternalSession(session, 'changeMembership')\n );\n return membership;\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"membership.js","sources":["../../../src/api/membership.ts"],"sourcesContent":["import {\n ActivateMembershipRequest,\n CancelMembershipRequest,\n ChangeMembershipRequest,\n MembershipListParams,\n MembershipListResponse,\n MembershipResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\n/** @internal Retrieves membership information for passed in id */\nexport async function getMembership(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'get',\n `/memberships`,\n { id },\n getInternalSession(session, 'getMembership')\n );\n return membership;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMemberships(session: Session, query?: MembershipListParams) {\n return rechargeApiRequest<MembershipListResponse>(\n 'get',\n `/memberships`,\n { query },\n getInternalSession(session, 'listMemberships')\n );\n}\n\n/** @internal Cancels a membership */\nexport async function cancelMembership(session: Session, id: string | number, cancelRequest: CancelMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/cancel`,\n {\n data: cancelRequest,\n },\n getInternalSession(session, 'cancelMembership')\n );\n return membership;\n}\n\n/** @internal Activates a membership */\nexport async function activateMembership(\n session: Session,\n id: string | number,\n activateRequest: ActivateMembershipRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/activate`,\n {\n data: activateRequest,\n },\n getInternalSession(session, 'activateMembership')\n );\n return membership;\n}\n\n/** @internal changes a membership program/product*/\nexport async function changeMembership(session: Session, id: string | number, changeRequest: ChangeMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${encodePathSegment(id)}/change`,\n {\n data: changeRequest,\n },\n getInternalSession(session, 'changeMembership')\n );\n return membership;\n}\n"],"names":[],"mappings":";;;AAaA,eAAsB,aAAA,CAAc,SAAkB,EAAA,EAAqB;AACzE,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,MAAM,kBAAA;AAAA,IAC3B,KAAA;AAAA,IACA,CAAA,YAAA,CAAA;AAAA,I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B,gBAAA,CAAiB,OAAA,EAAkB,EAAA,EAAqB,aAAA,EAAwC;AACpH,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,MAAM,kBAAA;AAAA,IAC3B,MAAA;AAAA,IACA,CAAA,aAAA,EAAgB,iBAAA,CAAkB,EAAE,CAAC,CAAA,OAAA,CAAA;AAAA,IACrC;AAAA,MACE,IAAA,EAAM;AAAA,KACR;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB;AAAA,GAChD;AACA,EAAA,OAAO,UAAA;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membershipProgram.js","sources":["../../../src/api/membershipProgram.ts"],"sourcesContent":["import {\n MembershipProgramListParams,\n MembershipProgramListResponse,\n MembershipProgramResponse,\n GetMembershipProgramOptions,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/** @internal Retrieves membership program information for passed in id */\nexport async function getMembershipProgram(\n session: Session,\n id: string | number,\n options?: GetMembershipProgramOptions\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership_program } = await rechargeApiRequest<MembershipProgramResponse>(\n 'get',\n `/membership_programs`,\n { id, query: { include: options?.include } },\n getInternalSession(session, 'getMembershipProgram')\n );\n return membership_program;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMembershipPrograms(session: Session, query?: MembershipProgramListParams) {\n return rechargeApiRequest<MembershipProgramListResponse>(\n 'get',\n `/membership_programs`,\n { query },\n getInternalSession(session, 'listMembershipPrograms')\n );\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"membershipProgram.js","sources":["../../../src/api/membershipProgram.ts"],"sourcesContent":["import {\n MembershipProgramListParams,\n MembershipProgramListResponse,\n MembershipProgramResponse,\n GetMembershipProgramOptions,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/** @internal Retrieves membership program information for passed in id */\nexport async function getMembershipProgram(\n session: Session,\n id: string | number,\n options?: GetMembershipProgramOptions\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership_program } = await rechargeApiRequest<MembershipProgramResponse>(\n 'get',\n `/membership_programs`,\n { id, query: { include: options?.include } },\n getInternalSession(session, 'getMembershipProgram')\n );\n return membership_program;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMembershipPrograms(session: Session, query?: MembershipProgramListParams) {\n return rechargeApiRequest<MembershipProgramListResponse>(\n 'get',\n `/membership_programs`,\n { query },\n getInternalSession(session, 'listMembershipPrograms')\n );\n}\n"],"names":[],"mappings":";;AAUA,eAAsB,oBAAA,CACpB,OAAA,EACA,EAAA,EACA,OAAA,EACA;AACA,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,kBAAA,EAAmB,GAAI,MAAM,kBAAA;AAAA,IACnC,KAAA;AAAA,IACA,CAAA,oBAAA,CAAA;AAAA,IACA,EAAE,EAAA,EAAI,KAAA,EAAO,EAAE,OAAA,EAAS,OAAA,EAAS,SAAQ,EAAE;AAAA,IAC3C,kBAAA,CAAmB,SAAS,sBAAsB;AAAA,GACpD;AACA,EAAA,OAAO,kBAAA;AACT;AAGO,SAAS,sBAAA,CAAuB,SAAkB,KAAA,EAAqC;AAC5F,EAAA,OAAO,kBAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,oBAAA,CAAA;AAAA,IACA,EAAE,KAAA,EAAM;AAAA,IACR,kBAAA,CAAmB,SAAS,wBAAwB;AAAA,GACtD;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metafield.js","sources":["../../../src/api/metafield.ts"],"sourcesContent":["import { CreateMetafieldRequest, Metafield, UpdateMetafieldRequest, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function createMetafield(session: Session, createRequest: CreateMetafieldRequest): Promise<Metafield> {\n const { metafield } = await rechargeApiRequest<{ metafield: Metafield }>(\n 'post',\n `/metafields`,\n {\n data: { metafield: createRequest },\n },\n getInternalSession(session, 'createMetafield')\n );\n return metafield;\n}\n\nexport async function updateMetafield(\n session: Session,\n id: string | number,\n updateRequest: UpdateMetafieldRequest\n): Promise<Metafield> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { metafield } = await rechargeApiRequest<{ metafield: Metafield }>(\n 'put',\n `/metafields`,\n {\n id,\n data: { metafield: updateRequest },\n },\n getInternalSession(session, 'updateMetafield')\n );\n return metafield;\n}\n\nexport function deleteMetafield(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 `/metafields`,\n {\n id,\n },\n getInternalSession(session, 'deleteMetafield')\n );\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"metafield.js","sources":["../../../src/api/metafield.ts"],"sourcesContent":["import { CreateMetafieldRequest, Metafield, UpdateMetafieldRequest, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function createMetafield(session: Session, createRequest: CreateMetafieldRequest): Promise<Metafield> {\n const { metafield } = await rechargeApiRequest<{ metafield: Metafield }>(\n 'post',\n `/metafields`,\n {\n data: { metafield: createRequest },\n },\n getInternalSession(session, 'createMetafield')\n );\n return metafield;\n}\n\nexport async function updateMetafield(\n session: Session,\n id: string | number,\n updateRequest: UpdateMetafieldRequest\n): Promise<Metafield> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { metafield } = await rechargeApiRequest<{ metafield: Metafield }>(\n 'put',\n `/metafields`,\n {\n id,\n data: { metafield: updateRequest },\n },\n getInternalSession(session, 'updateMetafield')\n );\n return metafield;\n}\n\nexport function deleteMetafield(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 `/metafields`,\n {\n id,\n },\n getInternalSession(session, 'deleteMetafield')\n );\n}\n"],"names":[],"mappings":";;AAGA,eAAsB,eAAA,CAAgB,SAAkB,aAAA,EAA2D;AACjH,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,MAAM,kBAAA;AAAA,IAC1B,MAAA;AAAA,IACA,CAAA,WAAA,CAAA;AAAA,IACA;AAAA,MACE,IAAA,EAAM,EAAE,SAAA,EAAW,aAAA;AAAc,KACnC;AAAA,IACA,kBAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACA,EAAA,OAAO,SAAA;AACT;AAEA,eAAsB,eAAA,CACpB,OAAA,EACA,EAAA,EACA,aAAA,EACoB;AACpB,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,MAAM,kBAAA;AAAA,IAC1B,KAAA;AAAA,IACA,CAAA,WAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,IAAA,EAAM,EAAE,SAAA,EAAW,aAAA;AAAc,KACnC;AAAA,IACA,kBAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACA,EAAA,OAAO,SAAA;AACT;AAEO,SAAS,eAAA,CAAgB,SAAkB,EAAA,EAAoC;AACpF,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,OAAO,kBAAA;AAAA,IACL,QAAA;AAAA,IACA,CAAA,WAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onetime.js","sources":["../../../src/api/onetime.ts"],"sourcesContent":["import {\n CreateOnetimeRequest,\n Onetime,\n OnetimeListParams,\n OnetimesResponse,\n UpdateOnetimeRequest,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getOnetime(session: Session, id: string | number): Promise<Onetime> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>(\n 'get',\n `/onetimes`,\n {\n id,\n },\n getInternalSession(session, 'getOnetime')\n );\n return onetime;\n}\n\nexport function listOnetimes(session: Session, query?: OnetimeListParams): Promise<OnetimesResponse> {\n return rechargeApiRequest<OnetimesResponse>(\n 'get',\n `/onetimes`,\n { query },\n getInternalSession(session, 'listOnetimes')\n );\n}\n\nexport async function createOnetime(session: Session, createRequest: CreateOnetimeRequest): Promise<Onetime> {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>(\n 'post',\n `/onetimes`,\n {\n data: createRequest,\n },\n getInternalSession(session, 'createOnetime')\n );\n return onetime;\n}\n\nexport async function updateOnetime(\n session: Session,\n id: string | number,\n updateRequest: UpdateOnetimeRequest\n): Promise<Onetime> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>(\n 'put',\n `/onetimes`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updateOnetime')\n );\n return onetime;\n}\n\nexport function deleteOnetime(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 `/onetimes`,\n {\n id,\n },\n getInternalSession(session, 'deleteOnetime')\n );\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"onetime.js","sources":["../../../src/api/onetime.ts"],"sourcesContent":["import {\n CreateOnetimeRequest,\n Onetime,\n OnetimeListParams,\n OnetimesResponse,\n UpdateOnetimeRequest,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getOnetime(session: Session, id: string | number): Promise<Onetime> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>(\n 'get',\n `/onetimes`,\n {\n id,\n },\n getInternalSession(session, 'getOnetime')\n );\n return onetime;\n}\n\nexport function listOnetimes(session: Session, query?: OnetimeListParams): Promise<OnetimesResponse> {\n return rechargeApiRequest<OnetimesResponse>(\n 'get',\n `/onetimes`,\n { query },\n getInternalSession(session, 'listOnetimes')\n );\n}\n\nexport async function createOnetime(session: Session, createRequest: CreateOnetimeRequest): Promise<Onetime> {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>(\n 'post',\n `/onetimes`,\n {\n data: createRequest,\n },\n getInternalSession(session, 'createOnetime')\n );\n return onetime;\n}\n\nexport async function updateOnetime(\n session: Session,\n id: string | number,\n updateRequest: UpdateOnetimeRequest\n): Promise<Onetime> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>(\n 'put',\n `/onetimes`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updateOnetime')\n );\n return onetime;\n}\n\nexport function deleteOnetime(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 `/onetimes`,\n {\n id,\n },\n getInternalSession(session, 'deleteOnetime')\n );\n}\n"],"names":[],"mappings":";;AAUA,eAAsB,UAAA,CAAW,SAAkB,EAAA,EAAuC;AACxF,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA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I,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,OAAO,kBAAA;AAAA,IACL,QAAA;AAAA,IACA,CAAA,SAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,eAAe;AAAA,GAC7C;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getOrder(session: Session, id: string | number): Promise<Order> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'get',\n `/orders`,\n {\n id,\n },\n getInternalSession(session, 'getOrder')\n );\n return order;\n}\n\nexport function listOrders(session: Session, query?: OrderListParams): Promise<OrdersResponse> {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query }, getInternalSession(session, 'listOrders'));\n}\n\nexport async function delayOrder(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'post',\n `/orders/${encodePathSegment(id)}/delay`,\n {},\n getInternalSession(session, 'delayOrder')\n );\n\n return order;\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getOrder(session: Session, id: string | number): Promise<Order> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'get',\n `/orders`,\n {\n id,\n },\n getInternalSession(session, 'getOrder')\n );\n return order;\n}\n\nexport function listOrders(session: Session, query?: OrderListParams): Promise<OrdersResponse> {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query }, getInternalSession(session, 'listOrders'));\n}\n\nexport async function delayOrder(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'post',\n `/orders/${encodePathSegment(id)}/delay`,\n {},\n getInternalSession(session, 'delayOrder')\n );\n\n return order;\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,QAAA,CAAS,SAAkB,EAAA,EAAqC;AACpF,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,MAAM,kBAAA;AAAA,IACtB,KAAA;AAAA,IACA,CAAA,OAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,UAAU;AAAA,GACxC;AACA,EAAA,OAAO,KAAA;AACT;AAEO,SAAS,UAAA,CAAW,SAAkB,KAAA,EAAkD;AAC7F,EAAA,OAAO,kBAAA,CAAmC,OAAO,CAAA,OAAA,CAAA,EAAW,EAAE,OAAM,EAAG,kBAAA,CAAmB,OAAA,EAAS,YAAY,CAAC,CAAA;AAClH;AAEA,eAAsB,UAAA,CAAW,SAAkB,EAAA,EAAqB;AACtE,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,KAAA,EAAM,GAAI,MAAM,kBAAA;AAAA,IACtB,MAAA;AAAA,IACA,CAAA,QAAA,EAAW,iBAAA,CAAkB,EAAE,CAAC,CAAA,MAAA,CAAA;AAAA,IAChC,EAAC;AAAA,IACD,kBAAA,CAAmB,SAAS,YAAY;AAAA,GAC1C;AAEA,EAAA,OAAO,KAAA;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paymentMethod.js","sources":["../../../src/api/paymentMethod.ts"],"sourcesContent":["import { loadSpreedlyScript } from '../utils/loadSpreedlyScript';\nimport {\n CardDetailsFirstNameLastName,\n CardDetailsFullName,\n CreatePaymentMethodRequest,\n GetPaymentMethodOptions,\n IsoDateString,\n PaymentFormConfig,\n PaymentFormController,\n PaymentFormEventHandlers,\n PaymentMethod,\n PaymentMethodFormOptions,\n PaymentMethodListParams,\n PaymentMethodsResponse,\n UpdatePaymentMethodRequest,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getPaymentMethod(\n session: Session,\n id: string | number,\n options?: GetPaymentMethodOptions\n): Promise<PaymentMethod> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { payment_method } = await rechargeApiRequest<{ payment_method: PaymentMethod }>(\n 'get',\n `/payment_methods`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getPaymentMethod')\n );\n return payment_method;\n}\n\n/**\n * Create a Payment Method\n *\n * Currently, `shopify_payments` is in read-only mode and can only be managed by Shopify.\n */\nexport async function createPaymentMethod(\n session: Session,\n createRequest: CreatePaymentMethodRequest\n): Promise<PaymentMethod> {\n const { payment_method } = await rechargeApiRequest<{ payment_method: PaymentMethod }>(\n 'post',\n `/payment_methods`,\n {\n data: { ...createRequest, customer_id: session.customerId },\n },\n getInternalSession(session, 'createPaymentMethod')\n );\n return payment_method;\n}\n\n/**\n * Modify an existing Payment Method\n *\n * Currently, `shopify_payments` is in read-only mode and can only be managed by Shopify.\n */\nexport async function updatePaymentMethod(\n session: Session,\n id: string | number,\n updateRequest: UpdatePaymentMethodRequest\n): Promise<PaymentMethod> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { payment_method } = await rechargeApiRequest<{ payment_method: PaymentMethod }>(\n 'put',\n `/payment_methods`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updatePaymentMethod')\n );\n return payment_method;\n}\n\nexport function listPaymentMethods(session: Session, query?: PaymentMethodListParams): Promise<PaymentMethodsResponse> {\n return rechargeApiRequest<PaymentMethodsResponse>(\n 'get',\n `/payment_methods`,\n { query },\n getInternalSession(session, 'listPaymentMethods')\n );\n}\n\nexport async function initFrictionlessPaymentV1(\n session: Session,\n rechargePaymentMethodId?: string\n): Promise<PaymentFormController> {\n // Initialize and get environment key\n const intentResponse = await createFrictionlessPaymentIntentV1(session, rechargePaymentMethodId);\n\n const environmentKey = intentResponse.external.environment_key;\n const paymentMethodIntentId = intentResponse.payment_method_intent_id;\n const externalCustomerId = intentResponse.external_customer_id.ecommerce;\n const resourceUrl = intentResponse.external.resource_url;\n const integrityHash = intentResponse.external.integrity_hash;\n const externalPaymentMethodId = intentResponse.payment_method?.processor_payment_method_token;\n\n // Load script\n await loadSpreedlyScript(resourceUrl, integrityHash);\n\n let isInitialized = false;\n let currentToken: string | null = null;\n let tokenCallback: ((token: string) => void) | null = null;\n let pendingSubmitOptions: PaymentMethodFormOptions | null = null;\n\n const controller: PaymentFormController = {\n mount(config: PaymentFormConfig, handlers?: PaymentFormEventHandlers): void {\n if (typeof window === 'undefined' || !window.Spreedly) {\n throw new Error('Payment script failed to load');\n }\n\n // Initialize Spreedly with element IDs\n window.Spreedly!.init(environmentKey, {\n numberEl: config.numberElementId,\n cvvEl: config.cvvElementId,\n });\n\n // Set up ready handler\n window.Spreedly!.on('ready', () => {\n isInitialized = true;\n\n // Apply styles\n if (config.styles) {\n window.Spreedly!.setStyle('number', config.styles);\n window.Spreedly!.setStyle('cvv', config.styles);\n }\n\n // Apply labels\n if (config.numberLabel) {\n window.Spreedly!.setLabel('number', config.numberLabel);\n }\n if (config.cvvLabel) {\n window.Spreedly!.setLabel('cvv', config.cvvLabel);\n }\n\n // Apply placeholders\n if (config.numberPlaceholder) {\n window.Spreedly!.setPlaceholder('number', config.numberPlaceholder);\n }\n if (config.cvvPlaceholder) {\n window.Spreedly!.setPlaceholder('cvv', config.cvvPlaceholder);\n }\n\n // Apply number format\n if (config.numberFormat === 'plainFormat') {\n // Apply field types\n if (config.numberFieldType) {\n window.Spreedly!.setFieldType('number', config.numberFieldType);\n }\n if (config.cvvFieldType) {\n window.Spreedly!.setFieldType('cvv', config.cvvFieldType);\n }\n // @ts-expect-error - SpreedlyNumberFormat doesn't match\n window.Spreedly!.setNumberFormat('plainFormat');\n } else if (config.numberFormat === 'maskedFormat') {\n window.Spreedly!.setFieldType('cvv', 'text');\n window.Spreedly!.setFieldType('number', 'text');\n window.Spreedly!.setNumberFormat('maskedFormat');\n } else if (config.numberFormat === 'prettyFormat') {\n // Apply field types\n if (config.numberFieldType === 'text' || config.numberFieldType === 'tel') {\n window.Spreedly!.setFieldType('number', config.numberFieldType);\n } else {\n window.Spreedly!.setFieldType('number', 'tel');\n }\n if (config.cvvFieldType === 'text' || config.cvvFieldType === 'tel') {\n window.Spreedly!.setFieldType('cvv', config.cvvFieldType);\n } else {\n window.Spreedly!.setFieldType('cvv', 'tel');\n }\n window.Spreedly!.setNumberFormat('prettyFormat');\n } else {\n // Apply field types\n if (config.numberFieldType) {\n window.Spreedly!.setFieldType('number', config.numberFieldType);\n }\n if (config.cvvFieldType) {\n window.Spreedly!.setFieldType('cvv', config.cvvFieldType);\n }\n }\n\n handlers?.onReady?.();\n });\n\n // Set up field event handler\n window.Spreedly!.on('fieldEvent', (name, eventType, activeElement, inputProperties) => {\n handlers?.onFieldEvent?.(name, eventType, activeElement, inputProperties);\n });\n\n // Set up error handler\n window.Spreedly!.on('errors', errors => {\n handlers?.onErrors?.(errors);\n });\n\n // Set up payment method handler\n window.Spreedly!.on('paymentMethod', (token, paymentMethod) => {\n currentToken = token;\n\n handlers?.onPaymentMethod?.(token, paymentMethod);\n\n // If there's a pending submit, execute it\n if (tokenCallback) {\n currentToken = null; // Clear the token after use\n tokenCallback(token);\n tokenCallback = null;\n }\n });\n },\n\n tokenize(cardDetails: CardDetailsFirstNameLastName | CardDetailsFullName): void {\n if (!isInitialized || !window.Spreedly) {\n throw new Error('Payment form is not initialized');\n }\n\n // Normalize year to YYYY format\n let year = String(cardDetails.year);\n if (year.length === 2) {\n year = `20${year}`;\n }\n const month = String(cardDetails.month).padStart(2, '0');\n\n if ('full_name' in cardDetails) {\n window.Spreedly.tokenizeCreditCard({\n full_name: cardDetails.full_name,\n month,\n year,\n });\n } else {\n window.Spreedly.tokenizeCreditCard({\n first_name: cardDetails.first_name,\n last_name: cardDetails.last_name,\n month,\n year,\n });\n }\n },\n\n async submit(options: PaymentMethodFormOptions): Promise<PaymentMethod> {\n if (!isInitialized) {\n throw new Error('Payment form is not initialized');\n }\n\n // Check if we already have a token\n if (currentToken) {\n const token = currentToken;\n currentToken = null; // Clear the token after use\n return submitFrictionlessPaymentMethodV1(session, token, options, {\n external_payment_method_id: externalPaymentMethodId,\n payment_method_intent_id: paymentMethodIntentId,\n external_customer_id: externalCustomerId,\n });\n }\n\n // Need to tokenize first, then submit\n return new Promise((resolve, reject) => {\n pendingSubmitOptions = options;\n\n tokenCallback = async (token: string) => {\n try {\n const result = await submitFrictionlessPaymentMethodV1(session, token, pendingSubmitOptions!, {\n external_payment_method_id: externalPaymentMethodId,\n payment_method_intent_id: paymentMethodIntentId,\n external_customer_id: externalCustomerId,\n });\n resolve(result);\n } catch (error) {\n reject(error);\n } finally {\n pendingSubmitOptions = null;\n }\n };\n\n // Trigger tokenization\n this.tokenize(options.card_details);\n });\n },\n\n reset(): void {\n if (window.Spreedly) {\n window.Spreedly.reload();\n }\n currentToken = null;\n tokenCallback = null;\n pendingSubmitOptions = null;\n },\n\n unmount(): void {\n if (window.Spreedly) {\n window.Spreedly.removeHandlers();\n }\n isInitialized = false;\n currentToken = null;\n tokenCallback = null;\n pendingSubmitOptions = null;\n },\n\n addEventHandlers(handlers: PaymentFormEventHandlers): void {\n if (handlers.onReady) {\n window.Spreedly!.on('ready', handlers.onReady);\n }\n if (handlers.onFieldEvent) {\n window.Spreedly!.on('fieldEvent', handlers.onFieldEvent);\n }\n if (handlers.onErrors) {\n window.Spreedly!.on('errors', handlers.onErrors);\n }\n if (handlers.onPaymentMethod) {\n window.Spreedly!.on('paymentMethod', handlers.onPaymentMethod);\n }\n },\n\n removeHandlers(): void {\n if (window.Spreedly) {\n window.Spreedly.removeHandlers();\n }\n },\n\n setFieldType(name: spreedly.SpreedlyField, type: spreedly.SpreedlyFieldType): void {\n window.Spreedly!.setFieldType(name, type);\n },\n\n setLabel(name: spreedly.SpreedlyField, label: string): void {\n window.Spreedly!.setLabel(name, label);\n },\n\n setNumberFormat(format: 'plainFormat' | 'prettyFormat' | 'maskedFormat'): void {\n // @ts-expect-error - SpreedlyNumberFormat doesn't match allowed values\n window.Spreedly!.setNumberFormat(format);\n },\n\n setPlaceholder(name: spreedly.SpreedlyField, placeholder: string): void {\n window.Spreedly!.setPlaceholder(name, placeholder);\n },\n\n setStyle(name: spreedly.SpreedlyField, style: string): void {\n window.Spreedly!.setStyle(name, style);\n },\n };\n\n return controller;\n}\n\n// defined here since this is only for internal use\ninterface PaymentMethodIntentResponse {\n payment_method_intent_id: string;\n customer_id: number;\n external_customer_id: {\n ecommerce: number;\n };\n external: {\n environment_key: string;\n resource_url: string;\n integrity_hash: string;\n };\n created_at: IsoDateString;\n expires_at: IsoDateString;\n payment_method?: PaymentMethod;\n}\n\nasync function createFrictionlessPaymentIntentV1(\n session: Session,\n rechargePaymentMethodId?: string\n): Promise<PaymentMethodIntentResponse> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const response = await rechargeApiRequest<PaymentMethodIntentResponse>(\n 'post',\n '/payment_method_intents',\n { data: { customer_id: id, payment_method_id: rechargePaymentMethodId } },\n getInternalSession(session, 'createFrictionlessPaymentIntentV1')\n );\n return response;\n}\n\n// defined here since this is only for internal use\ninterface FrictionlessPaymentMethodRequest {\n /** ID of the payment method to update */\n external_payment_method_id?: string;\n payment_method_intent_id: string;\n external_customer_id: number;\n}\n\nasync function submitFrictionlessPaymentMethodV1(\n session: Session,\n token: string,\n {\n billing_address,\n default_payment_method,\n address_ids,\n apply_to_all_subscription_addresses,\n }: PaymentMethodFormOptions,\n { external_payment_method_id, payment_method_intent_id, external_customer_id }: FrictionlessPaymentMethodRequest\n): Promise<PaymentMethod> {\n const paymentMethod = await createPaymentMethod(getInternalSession(session, 'submitFrictionlessPaymentMethodV1'), {\n default: default_payment_method ?? false,\n payment_type: 'CREDIT_CARD',\n processor_customer_token: external_customer_id.toString(),\n processor_name: 'frictionless',\n processor_payment_method_token: token,\n billing_address,\n payment_method_intent_id,\n address_ids,\n external_payment_method_id,\n apply_to_all_subscription_addresses,\n });\n return paymentMethod;\n}\n"],"names":[],"mappings":";;;AAmBsB,eAAA,gBAAA,CACpB,OACA,EAAA,EAAA,EACA,OACwB,EAAA;AACxB,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,cAAe,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC/B,KAAA;AAAA,IACA,CAAA,gBAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,KAAO,EAAA,EAAE,OAAS,EAAA,OAAA,EAAS,OAAQ,EAAA;AAAA,KACrC;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,cAAA,CAAA;AACT,CAAA;AAOsB,eAAA,mBAAA,CACpB,SACA,aACwB,EAAA;AACxB,EAAM,MAAA,EAAE,cAAe,EAAA,GAAI,MAAM,kBAAA;AAAA,IAC/B,MAAA;AAAA,IACA,CAAA,gBAAA,CAAA;AAAA,IACA;AAAA,MACE,MAAM,EAAE,GAAG,aAAe,EAAA,WAAA,EAAa,QAAQ,UAAW,EAAA;AAAA,KAC5D;AAAA,IACA,kBAAA,CAAmB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B,kBAAmB,CAAA,OAAA,EAAS,mCAAmC,CAAG,EAAA;AAAA,IAChH,SAAS,sBAA0B,IAAA,KAAA;AAAA,IACnC,YAAc,EAAA,aAAA;AAAA,IACd,wBAAA,EAA0B,qBAAqB,QAAS,EAAA;AAAA,IACxD,cAAgB,EAAA,cAAA;AAAA,IAChB,8BAAgC,EAAA,KAAA;AAAA,IAChC,eAAA;AAAA,IACA,wBAAA;AAAA,IACA,WAAA;AAAA,IACA,0BAAA;AAAA,IACA,mCAAA;AAAA,GACD,CAAA,CAAA;AACD,EAAO,OAAA,aAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"paymentMethod.js","sources":["../../../src/api/paymentMethod.ts"],"sourcesContent":["import { loadSpreedlyScript } from '../utils/loadSpreedlyScript';\nimport {\n CardDetailsFirstNameLastName,\n CardDetailsFullName,\n CreatePaymentMethodRequest,\n GetPaymentMethodOptions,\n IsoDateString,\n PaymentFormConfig,\n PaymentFormController,\n PaymentFormEventHandlers,\n PaymentMethod,\n PaymentMethodFormOptions,\n PaymentMethodListParams,\n PaymentMethodsResponse,\n UpdatePaymentMethodRequest,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getPaymentMethod(\n session: Session,\n id: string | number,\n options?: GetPaymentMethodOptions\n): Promise<PaymentMethod> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { payment_method } = await rechargeApiRequest<{ payment_method: PaymentMethod }>(\n 'get',\n `/payment_methods`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getPaymentMethod')\n );\n return payment_method;\n}\n\n/**\n * Create a Payment Method\n *\n * Currently, `shopify_payments` is in read-only mode and can only be managed by Shopify.\n */\nexport async function createPaymentMethod(\n session: Session,\n createRequest: CreatePaymentMethodRequest\n): Promise<PaymentMethod> {\n const { payment_method } = await rechargeApiRequest<{ payment_method: PaymentMethod }>(\n 'post',\n `/payment_methods`,\n {\n data: { ...createRequest, customer_id: session.customerId },\n },\n getInternalSession(session, 'createPaymentMethod')\n );\n return payment_method;\n}\n\n/**\n * Modify an existing Payment Method\n *\n * Currently, `shopify_payments` is in read-only mode and can only be managed by Shopify.\n */\nexport async function updatePaymentMethod(\n session: Session,\n id: string | number,\n updateRequest: UpdatePaymentMethodRequest\n): Promise<PaymentMethod> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { payment_method } = await rechargeApiRequest<{ payment_method: PaymentMethod }>(\n 'put',\n `/payment_methods`,\n {\n id,\n data: updateRequest,\n },\n getInternalSession(session, 'updatePaymentMethod')\n );\n return payment_method;\n}\n\nexport function listPaymentMethods(session: Session, query?: PaymentMethodListParams): Promise<PaymentMethodsResponse> {\n return rechargeApiRequest<PaymentMethodsResponse>(\n 'get',\n `/payment_methods`,\n { query },\n getInternalSession(session, 'listPaymentMethods')\n );\n}\n\nexport async function initFrictionlessPaymentV1(\n session: Session,\n rechargePaymentMethodId?: string\n): Promise<PaymentFormController> {\n // Initialize and get environment key\n const intentResponse = await createFrictionlessPaymentIntentV1(session, rechargePaymentMethodId);\n\n const environmentKey = intentResponse.external.environment_key;\n const paymentMethodIntentId = intentResponse.payment_method_intent_id;\n const externalCustomerId = intentResponse.external_customer_id.ecommerce;\n const resourceUrl = intentResponse.external.resource_url;\n const integrityHash = intentResponse.external.integrity_hash;\n const externalPaymentMethodId = intentResponse.payment_method?.processor_payment_method_token;\n\n // Load script\n await loadSpreedlyScript(resourceUrl, integrityHash);\n\n let isInitialized = false;\n let currentToken: string | null = null;\n let tokenCallback: ((token: string) => void) | null = null;\n let pendingSubmitOptions: PaymentMethodFormOptions | null = null;\n\n const controller: PaymentFormController = {\n mount(config: PaymentFormConfig, handlers?: PaymentFormEventHandlers): void {\n if (typeof window === 'undefined' || !window.Spreedly) {\n throw new Error('Payment script failed to load');\n }\n\n // Initialize Spreedly with element IDs\n window.Spreedly!.init(environmentKey, {\n numberEl: config.numberElementId,\n cvvEl: config.cvvElementId,\n });\n\n // Set up ready handler\n window.Spreedly!.on('ready', () => {\n isInitialized = true;\n\n // Apply styles\n if (config.styles) {\n window.Spreedly!.setStyle('number', config.styles);\n window.Spreedly!.setStyle('cvv', config.styles);\n }\n\n // Apply labels\n if (config.numberLabel) {\n window.Spreedly!.setLabel('number', config.numberLabel);\n }\n if (config.cvvLabel) {\n window.Spreedly!.setLabel('cvv', config.cvvLabel);\n }\n\n // Apply placeholders\n if (config.numberPlaceholder) {\n window.Spreedly!.setPlaceholder('number', config.numberPlaceholder);\n }\n if (config.cvvPlaceholder) {\n window.Spreedly!.setPlaceholder('cvv', config.cvvPlaceholder);\n }\n\n // Apply number format\n if (config.numberFormat === 'plainFormat') {\n // Apply field types\n if (config.numberFieldType) {\n window.Spreedly!.setFieldType('number', config.numberFieldType);\n }\n if (config.cvvFieldType) {\n window.Spreedly!.setFieldType('cvv', config.cvvFieldType);\n }\n // @ts-expect-error - SpreedlyNumberFormat doesn't match\n window.Spreedly!.setNumberFormat('plainFormat');\n } else if (config.numberFormat === 'maskedFormat') {\n window.Spreedly!.setFieldType('cvv', 'text');\n window.Spreedly!.setFieldType('number', 'text');\n window.Spreedly!.setNumberFormat('maskedFormat');\n } else if (config.numberFormat === 'prettyFormat') {\n // Apply field types\n if (config.numberFieldType === 'text' || config.numberFieldType === 'tel') {\n window.Spreedly!.setFieldType('number', config.numberFieldType);\n } else {\n window.Spreedly!.setFieldType('number', 'tel');\n }\n if (config.cvvFieldType === 'text' || config.cvvFieldType === 'tel') {\n window.Spreedly!.setFieldType('cvv', config.cvvFieldType);\n } else {\n window.Spreedly!.setFieldType('cvv', 'tel');\n }\n window.Spreedly!.setNumberFormat('prettyFormat');\n } else {\n // Apply field types\n if (config.numberFieldType) {\n window.Spreedly!.setFieldType('number', config.numberFieldType);\n }\n if (config.cvvFieldType) {\n window.Spreedly!.setFieldType('cvv', config.cvvFieldType);\n }\n }\n\n handlers?.onReady?.();\n });\n\n // Set up field event handler\n window.Spreedly!.on('fieldEvent', (name, eventType, activeElement, inputProperties) => {\n handlers?.onFieldEvent?.(name, eventType, activeElement, inputProperties);\n });\n\n // Set up error handler\n window.Spreedly!.on('errors', errors => {\n handlers?.onErrors?.(errors);\n });\n\n // Set up payment method handler\n window.Spreedly!.on('paymentMethod', (token, paymentMethod) => {\n currentToken = token;\n\n handlers?.onPaymentMethod?.(token, paymentMethod);\n\n // If there's a pending submit, execute it\n if (tokenCallback) {\n currentToken = null; // Clear the token after use\n tokenCallback(token);\n tokenCallback = null;\n }\n });\n },\n\n tokenize(cardDetails: CardDetailsFirstNameLastName | CardDetailsFullName): void {\n if (!isInitialized || !window.Spreedly) {\n throw new Error('Payment form is not initialized');\n }\n\n // Normalize year to YYYY format\n let year = String(cardDetails.year);\n if (year.length === 2) {\n year = `20${year}`;\n }\n const month = String(cardDetails.month).padStart(2, '0');\n\n if ('full_name' in cardDetails) {\n window.Spreedly.tokenizeCreditCard({\n full_name: cardDetails.full_name,\n month,\n year,\n });\n } else {\n window.Spreedly.tokenizeCreditCard({\n first_name: cardDetails.first_name,\n last_name: cardDetails.last_name,\n month,\n year,\n });\n }\n },\n\n async submit(options: PaymentMethodFormOptions): Promise<PaymentMethod> {\n if (!isInitialized) {\n throw new Error('Payment form is not initialized');\n }\n\n // Check if we already have a token\n if (currentToken) {\n const token = currentToken;\n currentToken = null; // Clear the token after use\n return submitFrictionlessPaymentMethodV1(session, token, options, {\n external_payment_method_id: externalPaymentMethodId,\n payment_method_intent_id: paymentMethodIntentId,\n external_customer_id: externalCustomerId,\n });\n }\n\n // Need to tokenize first, then submit\n return new Promise((resolve, reject) => {\n pendingSubmitOptions = options;\n\n tokenCallback = async (token: string) => {\n try {\n const result = await submitFrictionlessPaymentMethodV1(session, token, pendingSubmitOptions!, {\n external_payment_method_id: externalPaymentMethodId,\n payment_method_intent_id: paymentMethodIntentId,\n external_customer_id: externalCustomerId,\n });\n resolve(result);\n } catch (error) {\n reject(error);\n } finally {\n pendingSubmitOptions = null;\n }\n };\n\n // Trigger tokenization\n this.tokenize(options.card_details);\n });\n },\n\n reset(): void {\n if (window.Spreedly) {\n window.Spreedly.reload();\n }\n currentToken = null;\n tokenCallback = null;\n pendingSubmitOptions = null;\n },\n\n unmount(): void {\n if (window.Spreedly) {\n window.Spreedly.removeHandlers();\n }\n isInitialized = false;\n currentToken = null;\n tokenCallback = null;\n pendingSubmitOptions = null;\n },\n\n addEventHandlers(handlers: PaymentFormEventHandlers): void {\n if (handlers.onReady) {\n window.Spreedly!.on('ready', handlers.onReady);\n }\n if (handlers.onFieldEvent) {\n window.Spreedly!.on('fieldEvent', handlers.onFieldEvent);\n }\n if (handlers.onErrors) {\n window.Spreedly!.on('errors', handlers.onErrors);\n }\n if (handlers.onPaymentMethod) {\n window.Spreedly!.on('paymentMethod', handlers.onPaymentMethod);\n }\n },\n\n removeHandlers(): void {\n if (window.Spreedly) {\n window.Spreedly.removeHandlers();\n }\n },\n\n setFieldType(name: spreedly.SpreedlyField, type: spreedly.SpreedlyFieldType): void {\n window.Spreedly!.setFieldType(name, type);\n },\n\n setLabel(name: spreedly.SpreedlyField, label: string): void {\n window.Spreedly!.setLabel(name, label);\n },\n\n setNumberFormat(format: 'plainFormat' | 'prettyFormat' | 'maskedFormat'): void {\n // @ts-expect-error - SpreedlyNumberFormat doesn't match allowed values\n window.Spreedly!.setNumberFormat(format);\n },\n\n setPlaceholder(name: spreedly.SpreedlyField, placeholder: string): void {\n window.Spreedly!.setPlaceholder(name, placeholder);\n },\n\n setStyle(name: spreedly.SpreedlyField, style: string): void {\n window.Spreedly!.setStyle(name, style);\n },\n };\n\n return controller;\n}\n\n// defined here since this is only for internal use\ninterface PaymentMethodIntentResponse {\n payment_method_intent_id: string;\n customer_id: number;\n external_customer_id: {\n ecommerce: number;\n };\n external: {\n environment_key: string;\n resource_url: string;\n integrity_hash: string;\n };\n created_at: IsoDateString;\n expires_at: IsoDateString;\n payment_method?: PaymentMethod;\n}\n\nasync function createFrictionlessPaymentIntentV1(\n session: Session,\n rechargePaymentMethodId?: string\n): Promise<PaymentMethodIntentResponse> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const response = await rechargeApiRequest<PaymentMethodIntentResponse>(\n 'post',\n '/payment_method_intents',\n { data: { customer_id: id, payment_method_id: rechargePaymentMethodId } },\n getInternalSession(session, 'createFrictionlessPaymentIntentV1')\n );\n return response;\n}\n\n// defined here since this is only for internal use\ninterface FrictionlessPaymentMethodRequest {\n /** ID of the payment method to update */\n external_payment_method_id?: string;\n payment_method_intent_id: string;\n external_customer_id: number;\n}\n\nasync function submitFrictionlessPaymentMethodV1(\n session: Session,\n token: string,\n {\n billing_address,\n default_payment_method,\n address_ids,\n apply_to_all_subscription_addresses,\n }: PaymentMethodFormOptions,\n { external_payment_method_id, payment_method_intent_id, external_customer_id }: FrictionlessPaymentMethodRequest\n): Promise<PaymentMethod> {\n const paymentMethod = await createPaymentMethod(getInternalSession(session, 'submitFrictionlessPaymentMethodV1'), {\n default: default_payment_method ?? false,\n payment_type: 'CREDIT_CARD',\n processor_customer_token: external_customer_id.toString(),\n processor_name: 'frictionless',\n processor_payment_method_token: token,\n billing_address,\n payment_method_intent_id,\n address_ids,\n external_payment_method_id,\n apply_to_all_subscription_addresses,\n });\n return paymentMethod;\n}\n"],"names":[],"mappings":";;;AAmBA,eAAsB,gBAAA,CACpB,OAAA,EACA,EAAA,EACA,OAAA,EACwB;AACxB,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,MAAM,kBAAA;AAAA,IAC/B,KAAA;AAAA,IACA,CAAA,gBAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,KAAA,EAAO,EAAE,OAAA,EAAS,OAAA,EAAS,OAAA;AAAQ,KACrC;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB;AA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AAAA,IAChC,eAAA;AAAA,IACA,wBAAA;AAAA,IACA,WAAA;AAAA,IACA,0BAAA;AAAA,IACA;AAAA,GACD,CAAA;AACD,EAAA,OAAO,aAAA;AACT;;"}
|
package/dist/esm/api/plan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.js","sources":["../../../src/api/plan.ts"],"sourcesContent":["import { Plan, PlanListParams, PlansResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getPlan(session: Session, id: string | number): Promise<Plan> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { plan } = await rechargeApiRequest<{ plan: Plan }>(\n 'get',\n `/plans`,\n {\n id,\n },\n getInternalSession(session, 'getPlan')\n );\n return plan;\n}\n\nexport function listPlans(session: Session, query?: PlanListParams): Promise<PlansResponse> {\n return rechargeApiRequest<PlansResponse>('get', `/plans`, { query }, getInternalSession(session, 'listPlans'));\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"plan.js","sources":["../../../src/api/plan.ts"],"sourcesContent":["import { Plan, PlanListParams, PlansResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getPlan(session: Session, id: string | number): Promise<Plan> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { plan } = await rechargeApiRequest<{ plan: Plan }>(\n 'get',\n `/plans`,\n {\n id,\n },\n getInternalSession(session, 'getPlan')\n );\n return plan;\n}\n\nexport function listPlans(session: Session, query?: PlanListParams): Promise<PlansResponse> {\n return rechargeApiRequest<PlansResponse>('get', `/plans`, { query }, getInternalSession(session, 'listPlans'));\n}\n"],"names":[],"mappings":";;AAGA,eAAsB,OAAA,CAAQ,SAAkB,EAAA,EAAoC;AAClF,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,kBAAA;AAAA,IACrB,KAAA;AAAA,IACA,CAAA,MAAA,CAAA;AAAA,IACA;AAAA,MACE;AAAA,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,SAAS;AAAA,GACvC;AACA,EAAA,OAAO,IAAA;AACT;AAEO,SAAS,SAAA,CAAU,SAAkB,KAAA,EAAgD;AAC1F,EAAA,OAAO,kBAAA,CAAkC,OAAO,CAAA,MAAA,CAAA,EAAU,EAAE,OAAM,EAAG,kBAAA,CAAmB,OAAA,EAAS,WAAW,CAAC,CAAA;AAC/G;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sources":["../../../src/api/product.ts"],"sourcesContent":["import {\n ProductSearchParams_2020_12,\n ProductSearchParams_2022_06,\n ProductSearchResponse_2020_12,\n ProductSearchResponse_2022_06,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport type ProductSearchType<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06> =\n T extends ProductSearchParams_2020_12 ? ProductSearchResponse_2020_12 : ProductSearchResponse_2022_06;\n\nexport async function productSearch<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06>(\n session: Session,\n query: T\n): Promise<ProductSearchType<T>> {\n if (!['2020-12', '2022-06'].includes(query.format_version)) {\n throw new Error('Missing or unsupported format_version.');\n }\n return rechargeApiRequest<ProductSearchType<T>>(\n 'get',\n `/product_search`,\n {\n query,\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n getInternalSession(session, 'productSearch')\n );\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"product.js","sources":["../../../src/api/product.ts"],"sourcesContent":["import {\n ProductSearchParams_2020_12,\n ProductSearchParams_2022_06,\n ProductSearchResponse_2020_12,\n ProductSearchResponse_2022_06,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport type ProductSearchType<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06> =\n T extends ProductSearchParams_2020_12 ? ProductSearchResponse_2020_12 : ProductSearchResponse_2022_06;\n\nexport async function productSearch<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06>(\n session: Session,\n query: T\n): Promise<ProductSearchType<T>> {\n if (!['2020-12', '2022-06'].includes(query.format_version)) {\n throw new Error('Missing or unsupported format_version.');\n }\n return rechargeApiRequest<ProductSearchType<T>>(\n 'get',\n `/product_search`,\n {\n query,\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n getInternalSession(session, 'productSearch')\n );\n}\n"],"names":[],"mappings":";;AAYA,eAAsB,aAAA,CACpB,SACA,KAAA,EAC+B;AAC/B,EAAA,IAAI,CAAC,CAAC,SAAA,EAAW,SAAS,EAAE,QAAA,CAAS,KAAA,CAAM,cAAc,CAAA,EAAG;AAC1D,IAAA,MAAM,IAAI,MAAM,wCAAwC,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,kBAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,eAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAA;AAAA,MACA,OAAA,EAAS;AAAA,QACP,oBAAA,EAAsB;AAAA;AACxB,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,eAAe;AAAA,GAC7C;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sources":["../../../src/api/store.ts"],"sourcesContent":["import { ShippingCountriesOptions, ShippingCountriesResponse, StoreSettings, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/**\n * Get a list of all shipping countries for the store.\n */\nexport async function getShippingCountries(\n session: Session,\n options?: ShippingCountriesOptions\n): Promise<ShippingCountriesResponse> {\n const response = await rechargeApiRequest<ShippingCountriesResponse>(\n 'get',\n `/shop/shipping_countries`,\n {\n query: options,\n headers: {\n // Currently this is only available on the older api version.\n 'X-Recharge-Version': '2021-01',\n },\n },\n getInternalSession(session, 'getShippingCountries')\n );\n return response;\n}\n\n/**\n * Get the settings of the store. This includes the Customer Portal settings.\n */\nexport async function getStoreSettings(session: Session): Promise<StoreSettings> {\n const response = await rechargeApiRequest<StoreSettings>(\n 'get',\n '/shop/settings',\n {\n headers: {\n // Currently this is only available on the older api version.\n 'X-Recharge-Version': '2021-01',\n },\n },\n getInternalSession(session, 'getStoreSettings')\n );\n return response;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../../../src/api/store.ts"],"sourcesContent":["import { ShippingCountriesOptions, ShippingCountriesResponse, StoreSettings, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/**\n * Get a list of all shipping countries for the store.\n */\nexport async function getShippingCountries(\n session: Session,\n options?: ShippingCountriesOptions\n): Promise<ShippingCountriesResponse> {\n const response = await rechargeApiRequest<ShippingCountriesResponse>(\n 'get',\n `/shop/shipping_countries`,\n {\n query: options,\n headers: {\n // Currently this is only available on the older api version.\n 'X-Recharge-Version': '2021-01',\n },\n },\n getInternalSession(session, 'getShippingCountries')\n );\n return response;\n}\n\n/**\n * Get the settings of the store. This includes the Customer Portal settings.\n */\nexport async function getStoreSettings(session: Session): Promise<StoreSettings> {\n const response = await rechargeApiRequest<StoreSettings>(\n 'get',\n '/shop/settings',\n {\n headers: {\n // Currently this is only available on the older api version.\n 'X-Recharge-Version': '2021-01',\n },\n },\n getInternalSession(session, 'getStoreSettings')\n );\n return response;\n}\n"],"names":[],"mappings":";;AAMA,eAAsB,oBAAA,CACpB,SACA,OAAA,EACoC;AACpC,EAAA,MAAM,WAAW,MAAM,kBAAA;AAAA,IACrB,KAAA;AAAA,IACA,CAAA,wBAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO,OAAA;AAAA,MACP,OAAA,EAAS;AAAA;AAAA,QAEP,oBAAA,EAAsB;AAAA;AACxB,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,sBAAsB;AAAA,GACpD;AACA,EAAA,OAAO,QAAA;AACT;AAKA,eAAsB,iBAAiB,OAAA,EAA0C;AAC/E,EAAA,MAAM,WAAW,MAAM,kBAAA;AAAA,IACrB,KAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,MACE,OAAA,EAAS;AAAA;AAAA,QAEP,oBAAA,EAAsB;AAAA;AACxB,KACF;AAAA,IACA,kBAAA,CAAmB,SAAS,kBAAkB;AAAA,GAChD;AACA,EAAA,OAAO,QAAA;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n BasicSubscriptionParams,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n UpdateSubscriptionsParams,\n Session,\n ChargeResponse,\n CreateRecipientAddress,\n Onetime,\n IsoDateString,\n CreateSubscriptionsParams,\n CreateSubscriptionsRequest,\n DeleteSubscriptionsParams,\n DeleteSubscriptionsRequest,\n UpdateSubscriptionChargeDateParams,\n SubscriptionListAddonsParams,\n SubscriptionPricingPreview,\n SubscriptionPricingPreviewRequest,\n} from '../types';\nimport {\n bulkSubscriptionCreateMapper,\n bulkSubscriptionUpdateMapper,\n subscriptionMapperOldToNew,\n} from '../mappers/subscription';\n\nexport async function getSubscription(\n session: Session,\n id: string | number,\n options?: GetSubscriptionOptions\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getSubscription')\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>(\n 'get',\n `/subscriptions`,\n { query },\n getInternalSession(session, 'listSubscriptions')\n );\n}\n\n/**\n * @internal\n * List add-on subscriptions for the given parent subscription.\n */\nexport function listSubscriptionAddons(\n session: Session,\n id: string | number,\n query?: SubscriptionListAddonsParams\n): Promise<SubscriptionsResponse> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<SubscriptionsResponse>(\n 'get',\n `/subscriptions/${encodePathSegment(id)}/addons`,\n { query },\n getInternalSession(session, 'listSubscriptionAddons')\n );\n}\n\n/**\n * When creating a subscription via API, order_interval_frequency and charge_interval_frequency values do not necessarily\n * need to match the values set in the respective Plans. The product, however, does need to have at least one Plan in order\n * to be added to a subscription.\n */\nexport async function createSubscription(\n session: Session,\n createRequest: CreateSubscriptionRequest,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions`,\n {\n data: createRequest,\n query,\n },\n getInternalSession(session, 'createSubscription')\n );\n return subscription;\n}\n\n/**\n * Updating parameters like frequency, charge_interval_frequency, order_interval_frequency, order_interval_unit will cause our algorithm to automatically recalculate the next charge date (next_charge_scheduled_at).\n * WARNING: This update will remove skipped and manually changed charges.\n * If you want to change the next charge date (next_charge_scheduled_at) we recommend you to update these parameters first.\n * When updating order_interval_unit OR order_interval_frequency OR charge_interval_frequency all three parameters are required.\n */\nexport async function updateSubscription(\n session: Session,\n id: string | number,\n updateRequest: UpdateSubscriptionRequest,\n query?: UpdateSubscriptionParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n getInternalSession(session, 'updateSubscription')\n );\n return subscription;\n}\n\n/**\n * If there are two active subscriptions with the same address_id, and you update their\n * next_charge_date parameters to match, their charges will get merged into a new charge\n * with a new id\n */\nexport async function updateSubscriptionChargeDate(\n session: Session,\n id: string | number,\n date: IsoDateString,\n query?: UpdateSubscriptionChargeDateParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n getInternalSession(session, 'updateSubscriptionChargeDate')\n );\n return subscription;\n}\n\nexport async function updateSubscriptionAddress(\n session: Session,\n id: string | number,\n address_id: string | number\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/change_address`,\n {\n data: { address_id },\n },\n getInternalSession(session, 'updateSubscriptionAddress')\n );\n return subscription;\n}\n\n/**\n * An involuntary subscription cancelled due to max retries reached will trigger the\n * charge/max_retries_reached webhook. If this leads to the subscription being cancelled,\n * the subscription/cancelled webhook will trigger.\n */\nexport async function cancelSubscription(\n session: Session,\n id: string | number,\n cancelRequest: CancelSubscriptionRequest,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n getInternalSession(session, 'cancelSubscription')\n );\n return subscription;\n}\n\n/**\n * When activating subscription, following attributes will be set to null: cancelled_at, cancellation_reason\n * and cancellation_reason_comments.\n */\nexport async function activateSubscription(\n session: Session,\n id: string | number,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/activate`,\n { query },\n getInternalSession(session, 'activateSubscription')\n );\n return subscription;\n}\n\n/* Skip charge associated with a subscription. */\nexport async function skipSubscriptionCharge(session: Session, id: number | string, date: IsoDateString) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n getInternalSession(session, 'skipSubscriptionCharge')\n );\n return charge;\n}\n\n/**\n * @internal\n * Price a proposed variant and/or plan swap for a subscription without persisting it.\n *\n * Runs the same pricing chain the update would run, so the returned `proposed_unit_price` is what\n * the customer would actually be charged -- including dynamic pricing tier resolution and any\n * pricing progression reset the swap would cause. Omitted request fields keep the subscription's\n * current value; quantity and frequency are not accepted because they cannot move the per-unit price\n * between dynamic pricing tiers.\n *\n * Pricing failures are reported in the returned `errors` map rather than thrown.\n */\nexport async function getSubscriptionPricingPreview(\n session: Session,\n id: string | number,\n previewRequest: SubscriptionPricingPreviewRequest = {}\n): Promise<SubscriptionPricingPreview> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: SubscriptionPricingPreview }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/pricing_preview`,\n {\n data: previewRequest,\n },\n getInternalSession(session, 'getSubscriptionPricingPreview')\n );\n return subscription;\n}\n\n/**\n * Gift a subscription to another person. This creates onetime products for the recipient and skips that subscription for the customer.\n * When the gifted onetime ships the recipient receives and email notification.\n */\nexport async function skipGiftSubscriptionCharge(\n session: Session,\n subscriptionIds: Array<number | string>,\n recipientAddress: CreateRecipientAddress\n) {\n if (subscriptionIds === undefined || subscriptionIds.length === 0) {\n throw new Error('Subscription IDs are required');\n }\n const { onetimes } = await rechargeApiRequest<{ onetimes: Onetime[] }>(\n 'post',\n '/purchase_items/skip_gift',\n {\n data: {\n purchase_item_ids: subscriptionIds.map(Number),\n recipient_address: recipientAddress,\n },\n },\n getInternalSession(session, 'skipGiftSubscriptionCharge')\n );\n\n return onetimes;\n}\n\n/**\n * Bulk create new subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n */\nexport async function createSubscriptions(\n session: Session,\n createRequestBulk: CreateSubscriptionsRequest[],\n query?: CreateSubscriptionsParams\n): Promise<Subscription[]> {\n // validate size\n const length = createRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n // validate addressId\n const addressId = createRequestBulk[0].address_id;\n if (!createRequestBulk.every(createRequest => createRequest.address_id === addressId)) {\n throw new Error('All subscriptions must have the same address_id.');\n }\n const requestData = createRequestBulk.map(createRequest => bulkSubscriptionCreateMapper(customerId, createRequest));\n // setup query params\n let localQuery: { allow_onetimes?: boolean } | undefined = undefined;\n if (query?.allow_onetimes !== undefined) {\n localQuery = { allow_onetimes: query.allow_onetimes };\n }\n const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'post',\n `/addresses/${encodePathSegment(addressId)}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData, commit_update: !!query?.commit },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n query: localQuery,\n },\n getInternalSession(session, 'createSubscriptions')\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n\n/**\n * Bulk update subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n * Same rules apply as a single subscription update\n */\nexport async function updateSubscriptions(\n session: Session,\n addressId: string | number,\n updateRequestBulk: UpdateSubscriptionsRequest[],\n query?: UpdateSubscriptionsParams\n): Promise<Subscription[]> {\n if (addressId === undefined || addressId === '') {\n throw new Error('Address ID is required');\n }\n // validate size\n const length = updateRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n const forceUpdate = !!query?.force_update;\n const requestData = updateRequestBulk.map(updateRequest => bulkSubscriptionUpdateMapper(forceUpdate, updateRequest));\n // setup query params\n let localQuery: { allow_onetimes?: boolean } | undefined = undefined;\n if (query?.allow_onetimes !== undefined) {\n localQuery = { allow_onetimes: query.allow_onetimes };\n }\n const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'put',\n `/addresses/${encodePathSegment(addressId)}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData, commit_update: !!query?.commit },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n query: localQuery,\n },\n getInternalSession(session, 'updateSubscriptions')\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n\n/**\n * @internal\n * Bulk delete subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n */\nexport async function deleteSubscriptions(\n session: Session,\n addressId: string | number,\n deleteRequestBulk: DeleteSubscriptionsRequest[],\n query?: DeleteSubscriptionsParams\n): Promise<void> {\n if (addressId === undefined || addressId === '') {\n throw new Error('Address ID is required');\n }\n // validate size\n const length = deleteRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n // setup query params\n let localQuery: { allow_onetimes?: boolean } | undefined = undefined;\n if (query?.allow_onetimes !== undefined) {\n localQuery = { allow_onetimes: query.allow_onetimes };\n }\n await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'delete',\n `/addresses/${encodePathSegment(addressId)}/subscriptions-bulk`,\n {\n data: { subscriptions: deleteRequestBulk, send_email: !!query?.send_email, commit_update: !!query?.commit },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n query: localQuery,\n },\n getInternalSession(session, 'deleteSubscriptions')\n );\n return undefined;\n}\n"],"names":[],"mappings":";;;;AAmCsB,eAAA,eAAA,CACpB,O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AI,MAAM,wBAAwB,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAA,MAAM,SAAS,iBAAkB,CAAA,MAAA,CAAA;AACjC,EAAI,IAAA,MAAA,GAAS,CAAK,IAAA,MAAA,GAAS,EAAI,EAAA;AAC7B,IAAM,MAAA,IAAI,MAAM,mDAAmD,CAAA,CAAA;AAAA,GACrE;AAEA,EAAM,MAAA,EAAE,YAAe,GAAA,OAAA,CAAA;AACvB,EAAA,IAAI,CAAC,UAAY,EAAA;AACf,IAAM,MAAA,IAAI,MAAM,2BAA2B,CAAA,CAAA;AAAA,GAC7C;AAEA,EAAA,IAAI,UAAuD,GAAA,KAAA,CAAA,CAAA;AAC3D,EAAI,IAAA,KAAA,EAAO,mBAAmB,KAAW,CAAA,EAAA;AACvC,IAAa,UAAA,GAAA,EAAE,cAAgB,EAAA,KAAA,CAAM,cAAe,EAAA,CAAA;AAAA,GACtD;AACA,EAAM,MAAA,kBAAA;AAAA,IACJ,QAAA;AAAA,IACA,CAAA,WAAA,EAAc,iBAAkB,CAAA,SAAS,CAAC,CAAA,mBAAA,CAAA;AAAA,IAC1C;AAAA,MACE,IAAM,EAAA,EAAE,aAAe,EAAA,iBAAA,EAAmB,UAAY,EAAA,CAAC,CAAC,KAAA,EAAO,UAAY,EAAA,aAAA,EAAe,CAAC,CAAC,OAAO,MAAO,EAAA;AAAA,MAC1G,OAAS,EAAA;AAAA,QACP,oBAAsB,EAAA,SAAA;AAAA,OACxB;AAAA,MACA,KAAO,EAAA,UAAA;AAAA,KACT;AAAA,IACA,kBAAA,CAAmB,SAAS,qBAAqB,CAAA;AAAA,GACnD,CAAA;AACA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n BasicSubscriptionParams,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n UpdateSubscriptionsParams,\n Session,\n ChargeResponse,\n CreateRecipientAddress,\n Onetime,\n IsoDateString,\n CreateSubscriptionsParams,\n CreateSubscriptionsRequest,\n DeleteSubscriptionsParams,\n DeleteSubscriptionsRequest,\n UpdateSubscriptionChargeDateParams,\n SubscriptionListAddonsParams,\n SubscriptionPricingPreview,\n SubscriptionPricingPreviewRequest,\n} from '../types';\nimport {\n bulkSubscriptionCreateMapper,\n bulkSubscriptionUpdateMapper,\n subscriptionMapperOldToNew,\n} from '../mappers/subscription';\n\nexport async function getSubscription(\n session: Session,\n id: string | number,\n options?: GetSubscriptionOptions\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getSubscription')\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>(\n 'get',\n `/subscriptions`,\n { query },\n getInternalSession(session, 'listSubscriptions')\n );\n}\n\n/**\n * @internal\n * List add-on subscriptions for the given parent subscription.\n */\nexport function listSubscriptionAddons(\n session: Session,\n id: string | number,\n query?: SubscriptionListAddonsParams\n): Promise<SubscriptionsResponse> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n return rechargeApiRequest<SubscriptionsResponse>(\n 'get',\n `/subscriptions/${encodePathSegment(id)}/addons`,\n { query },\n getInternalSession(session, 'listSubscriptionAddons')\n );\n}\n\n/**\n * When creating a subscription via API, order_interval_frequency and charge_interval_frequency values do not necessarily\n * need to match the values set in the respective Plans. The product, however, does need to have at least one Plan in order\n * to be added to a subscription.\n */\nexport async function createSubscription(\n session: Session,\n createRequest: CreateSubscriptionRequest,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions`,\n {\n data: createRequest,\n query,\n },\n getInternalSession(session, 'createSubscription')\n );\n return subscription;\n}\n\n/**\n * Updating parameters like frequency, charge_interval_frequency, order_interval_frequency, order_interval_unit will cause our algorithm to automatically recalculate the next charge date (next_charge_scheduled_at).\n * WARNING: This update will remove skipped and manually changed charges.\n * If you want to change the next charge date (next_charge_scheduled_at) we recommend you to update these parameters first.\n * When updating order_interval_unit OR order_interval_frequency OR charge_interval_frequency all three parameters are required.\n */\nexport async function updateSubscription(\n session: Session,\n id: string | number,\n updateRequest: UpdateSubscriptionRequest,\n query?: UpdateSubscriptionParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n getInternalSession(session, 'updateSubscription')\n );\n return subscription;\n}\n\n/**\n * If there are two active subscriptions with the same address_id, and you update their\n * next_charge_date parameters to match, their charges will get merged into a new charge\n * with a new id\n */\nexport async function updateSubscriptionChargeDate(\n session: Session,\n id: string | number,\n date: IsoDateString,\n query?: UpdateSubscriptionChargeDateParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n getInternalSession(session, 'updateSubscriptionChargeDate')\n );\n return subscription;\n}\n\nexport async function updateSubscriptionAddress(\n session: Session,\n id: string | number,\n address_id: string | number\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/change_address`,\n {\n data: { address_id },\n },\n getInternalSession(session, 'updateSubscriptionAddress')\n );\n return subscription;\n}\n\n/**\n * An involuntary subscription cancelled due to max retries reached will trigger the\n * charge/max_retries_reached webhook. If this leads to the subscription being cancelled,\n * the subscription/cancelled webhook will trigger.\n */\nexport async function cancelSubscription(\n session: Session,\n id: string | number,\n cancelRequest: CancelSubscriptionRequest,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n getInternalSession(session, 'cancelSubscription')\n );\n return subscription;\n}\n\n/**\n * When activating subscription, following attributes will be set to null: cancelled_at, cancellation_reason\n * and cancellation_reason_comments.\n */\nexport async function activateSubscription(\n session: Session,\n id: string | number,\n query?: BasicSubscriptionParams\n): Promise<Subscription> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/activate`,\n { query },\n getInternalSession(session, 'activateSubscription')\n );\n return subscription;\n}\n\n/* Skip charge associated with a subscription. */\nexport async function skipSubscriptionCharge(session: Session, id: number | string, date: IsoDateString) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n getInternalSession(session, 'skipSubscriptionCharge')\n );\n return charge;\n}\n\n/**\n * @internal\n * Price a proposed variant and/or plan swap for a subscription without persisting it.\n *\n * Runs the same pricing chain the update would run, so the returned `proposed_unit_price` is what\n * the customer would actually be charged -- including dynamic pricing tier resolution and any\n * pricing progression reset the swap would cause. Omitted request fields keep the subscription's\n * current value; quantity and frequency are not accepted because they cannot move the per-unit price\n * between dynamic pricing tiers.\n *\n * Pricing failures are reported in the returned `errors` map rather than thrown.\n */\nexport async function getSubscriptionPricingPreview(\n session: Session,\n id: string | number,\n previewRequest: SubscriptionPricingPreviewRequest = {}\n): Promise<SubscriptionPricingPreview> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { subscription } = await rechargeApiRequest<{ subscription: SubscriptionPricingPreview }>(\n 'post',\n `/subscriptions/${encodePathSegment(id)}/pricing_preview`,\n {\n data: previewRequest,\n },\n getInternalSession(session, 'getSubscriptionPricingPreview')\n );\n return subscription;\n}\n\n/**\n * Gift a subscription to another person. This creates onetime products for the recipient and skips that subscription for the customer.\n * When the gifted onetime ships the recipient receives and email notification.\n */\nexport async function skipGiftSubscriptionCharge(\n session: Session,\n subscriptionIds: Array<number | string>,\n recipientAddress: CreateRecipientAddress\n) {\n if (subscriptionIds === undefined || subscriptionIds.length === 0) {\n throw new Error('Subscription IDs are required');\n }\n const { onetimes } = await rechargeApiRequest<{ onetimes: Onetime[] }>(\n 'post',\n '/purchase_items/skip_gift',\n {\n data: {\n purchase_item_ids: subscriptionIds.map(Number),\n recipient_address: recipientAddress,\n },\n },\n getInternalSession(session, 'skipGiftSubscriptionCharge')\n );\n\n return onetimes;\n}\n\n/**\n * Bulk create new subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n */\nexport async function createSubscriptions(\n session: Session,\n createRequestBulk: CreateSubscriptionsRequest[],\n query?: CreateSubscriptionsParams\n): Promise<Subscription[]> {\n // validate size\n const length = createRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n // validate addressId\n const addressId = createRequestBulk[0].address_id;\n if (!createRequestBulk.every(createRequest => createRequest.address_id === addressId)) {\n throw new Error('All subscriptions must have the same address_id.');\n }\n const requestData = createRequestBulk.map(createRequest => bulkSubscriptionCreateMapper(customerId, createRequest));\n // setup query params\n let localQuery: { allow_onetimes?: boolean } | undefined = undefined;\n if (query?.allow_onetimes !== undefined) {\n localQuery = { allow_onetimes: query.allow_onetimes };\n }\n const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'post',\n `/addresses/${encodePathSegment(addressId)}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData, commit_update: !!query?.commit },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n query: localQuery,\n },\n getInternalSession(session, 'createSubscriptions')\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n\n/**\n * Bulk update subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n * Same rules apply as a single subscription update\n */\nexport async function updateSubscriptions(\n session: Session,\n addressId: string | number,\n updateRequestBulk: UpdateSubscriptionsRequest[],\n query?: UpdateSubscriptionsParams\n): Promise<Subscription[]> {\n if (addressId === undefined || addressId === '') {\n throw new Error('Address ID is required');\n }\n // validate size\n const length = updateRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n const forceUpdate = !!query?.force_update;\n const requestData = updateRequestBulk.map(updateRequest => bulkSubscriptionUpdateMapper(forceUpdate, updateRequest));\n // setup query params\n let localQuery: { allow_onetimes?: boolean } | undefined = undefined;\n if (query?.allow_onetimes !== undefined) {\n localQuery = { allow_onetimes: query.allow_onetimes };\n }\n const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'put',\n `/addresses/${encodePathSegment(addressId)}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData, commit_update: !!query?.commit },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n query: localQuery,\n },\n getInternalSession(session, 'updateSubscriptions')\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n\n/**\n * @internal\n * Bulk delete subscriptions.\n * Must all be for the same address.\n * There is a limit of 20 subscriptions per request.\n */\nexport async function deleteSubscriptions(\n session: Session,\n addressId: string | number,\n deleteRequestBulk: DeleteSubscriptionsRequest[],\n query?: DeleteSubscriptionsParams\n): Promise<void> {\n if (addressId === undefined || addressId === '') {\n throw new Error('Address ID is required');\n }\n // validate size\n const length = deleteRequestBulk.length;\n if (length < 1 || length > 21) {\n throw new Error('Number of subscriptions must be between 1 and 20.');\n }\n // validate customerId\n const { customerId } = session;\n if (!customerId) {\n throw new Error('No customerId in session.');\n }\n // setup query params\n let localQuery: { allow_onetimes?: boolean } | undefined = undefined;\n if (query?.allow_onetimes !== undefined) {\n localQuery = { allow_onetimes: query.allow_onetimes };\n }\n await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'delete',\n `/addresses/${encodePathSegment(addressId)}/subscriptions-bulk`,\n {\n data: { subscriptions: deleteRequestBulk, send_email: !!query?.send_email, commit_update: !!query?.commit },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n query: localQuery,\n },\n getInternalSession(session, 'deleteSubscriptions')\n );\n return undefined;\n}\n"],"names":[],"mappings":";;;;AAmCA,eAAsB,eAAA,CACpB,OAAA,EACA,EAAA,EACA,OAAA,EACuB;AACvB,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,YAAA,EAAa,GAAI,MAAM,kBAAA;AAAA,IAC7B,KAAA;AAAA,IACA,CAAA,cAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,KAAA,EAAO,EAAE,OAAA,EAAS,OAAA,EAAS,OAAA;AAAQ,KACrC;AAAA,IACA,kBAAA,CAAmB,SAAS,iBAAiB;AAAA,GAC/C;AACA,EAAA,OAAO,YAAA;AACT;AAEO,SAAS,iBAAA,CAAkB,SAAkB,KAAA,EAAgE;AAClH,EAAA,OAAO,k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SAAA,KAAc,EAAA,EAAI;AAC/C,IAAA,MAAM,IAAI,MAAM,wBAAwB,CAAA;AAAA,EAC1C;AAEA,EAAA,MAAM,SAAS,iBAAA,CAAkB,MAAA;AACjC,EAAA,IAAI,MAAA,GAAS,CAAA,IAAK,MAAA,GAAS,EAAA,EAAI;AAC7B,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAAA,EACrE;AAEA,EAAA,MAAM,EAAE,YAAW,GAAI,OAAA;AACvB,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,MAAM,IAAI,MAAM,2BAA2B,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,UAAA,GAAuD,MAAA;AAC3D,EAAA,IAAI,KAAA,EAAO,mBAAmB,MAAA,EAAW;AACvC,IAAA,UAAA,GAAa,EAAE,cAAA,EAAgB,KAAA,CAAM,cAAA,EAAe;AAAA,EACtD;AACA,EAAA,MAAM,kBAAA;AAAA,IACJ,QAAA;AAAA,IACA,CAAA,WAAA,EAAc,iBAAA,CAAkB,SAAS,CAAC,CAAA,mBAAA,CAAA;AAAA,IAC1C;AAAA,MACE,IAAA,EAAM,EAAE,aAAA,EAAe,iBAAA,EAAmB,UAAA,EAAY,CAAC,CAAC,KAAA,EAAO,UAAA,EAAY,aAAA,EAAe,CAAC,CAAC,OAAO,MAAA,EAAO;AAAA,MAC1G,OAAA,EAAS;AAAA,QACP,oBAAA,EAAsB;AAAA,OACxB;AAAA,MACA,KAAA,EAAO;AAAA,KACT;AAAA,IACA,kBAAA,CAAmB,SAAS,qBAAqB;AAAA,GACnD;AACA,EAAA,OAAO,MAAA;AACT;;"}
|
|
@@ -2,9 +2,6 @@ import { rechargeApiRequest, getInternalSession } from '../utils/request.js';
|
|
|
2
2
|
import { encodePathSegment } from '../utils/url.js';
|
|
3
3
|
|
|
4
4
|
function listTieredDiscounts(session, options) {
|
|
5
|
-
if (!session.customerId) {
|
|
6
|
-
throw new Error("Not logged in.");
|
|
7
|
-
}
|
|
8
5
|
return rechargeApiRequest(
|
|
9
6
|
"get",
|
|
10
7
|
`/incentives/tiered_discounts`,
|
|
@@ -15,9 +12,6 @@ function listTieredDiscounts(session, options) {
|
|
|
15
12
|
);
|
|
16
13
|
}
|
|
17
14
|
async function getTieredDiscount(session, id) {
|
|
18
|
-
if (!session.customerId) {
|
|
19
|
-
throw new Error("Not logged in.");
|
|
20
|
-
}
|
|
21
15
|
if (id === void 0 || id === "") {
|
|
22
16
|
throw new Error("ID is required");
|
|
23
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tieredDiscount.js","sources":["../../../src/api/tieredDiscount.ts"],"sourcesContent":["import {\n TieredDiscount,\n TieredDiscountsParams,\n TieredDiscountsResponse,\n TieredDiscountOffersRequest,\n TieredDiscountOffersResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport function listTieredDiscounts(\n session: Session,\n options?: TieredDiscountsParams\n): Promise<TieredDiscountsResponse> {\n
|
|
1
|
+
{"version":3,"file":"tieredDiscount.js","sources":["../../../src/api/tieredDiscount.ts"],"sourcesContent":["import {\n TieredDiscount,\n TieredDiscountsParams,\n TieredDiscountsResponse,\n TieredDiscountOffersRequest,\n TieredDiscountOffersResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport function listTieredDiscounts(\n session: Session,\n options?: TieredDiscountsParams\n): Promise<TieredDiscountsResponse> {\n return rechargeApiRequest<TieredDiscountsResponse>(\n 'get',\n `/incentives/tiered_discounts`,\n {\n query: options,\n },\n getInternalSession(session, 'listTieredDiscounts')\n );\n}\n\nexport async function getTieredDiscount(session: Session, id: string | number): Promise<TieredDiscount> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { tiered_discount } = await rechargeApiRequest<{ tiered_discount: TieredDiscount }>(\n 'get',\n `/incentives/tiered_discounts/${encodePathSegment(id)}`,\n {},\n getInternalSession(session, 'getTieredDiscount')\n );\n return tiered_discount;\n}\n\nexport function getTieredDiscountOffers(\n session: Session,\n body: TieredDiscountOffersRequest\n): Promise<TieredDiscountOffersResponse> {\n return rechargeApiRequest<TieredDiscountOffersResponse>(\n 'post',\n `/incentives/tiered_discounts/offers`,\n { data: body },\n getInternalSession(session, 'getTieredDiscountOffers')\n );\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,mBAAA,CACd,SACA,OAAA,EACkC;AAClC,EAAA,OAAO,kBAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,4BAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAA,EAAO;AAAA,KACT;AAAA,IACA,kBAAA,CAAmB,SAAS,qBAAqB;AAAA,GACnD;AACF;AAEA,eAAsB,iBAAA,CAAkB,SAAkB,EAAA,EAA8C;AACtG,EAAA,IAAI,EAAA,KAAO,MAAA,IAAa,EAAA,KAAO,EAAA,EAAI;AACjC,IAAA,MAAM,IAAI,MAAM,gBAAgB,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,EAAE,eAAA,EAAgB,GAAI,MAAM,kBAAA;AAAA,IAChC,KAAA;AAAA,IACA,CAAA,6BAAA,EAAgC,iBAAA,CAAkB,EAAE,CAAC,CAAA,CAAA;AAAA,IACrD,EAAC;AAAA,IACD,kBAAA,CAAmB,SAAS,mBAAmB;AAAA,GACjD;AACA,EAAA,OAAO,eAAA;AACT;AAEO,SAAS,uBAAA,CACd,SACA,IAAA,EACuC;AACvC,EAAA,OAAO,kBAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,mCAAA,CAAA;AAAA,IACA,EAAE,MAAM,IAAA,EAAK;AAAA,IACb,kBAAA,CAAmB,SAAS,yBAAyB;AAAA,GACvD;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":["../../../src/constants/api.ts"],"sourcesContent":["import { StorefrontEnvironment } from '../types';\n\nexport const RECHARGE_API_URL = (environment: StorefrontEnvironment, environmentUri = ''): string => {\n switch (environment) {\n case 'prod':\n return 'https://api.rechargeapps.com';\n case 'stage':\n return 'https://api.stage.rechargeapps.com';\n case 'preprod':\n case 'prestage':\n return `${environmentUri}/api`;\n }\n};\nexport const RECHARGE_ADMIN_URL = (environment: StorefrontEnvironment, environmentUri = ''): string => {\n switch (environment) {\n case 'prod':\n return 'https://admin.rechargeapps.com';\n case 'stage':\n return 'https://admin.stage.rechargeapps.com';\n case 'preprod':\n case 'prestage':\n return environmentUri;\n }\n};\nexport const RECHARGE_CDN_URL = (environment: StorefrontEnvironment): string => {\n switch (environment) {\n case 'prod':\n case 'preprod':\n return 'https://static.rechargecdn.com';\n case 'stage':\n case 'prestage':\n return 'https://static.stage.rechargecdn.com';\n }\n};\nexport const SHOPIFY_APP_PROXY_URL = '/tools/recurring';\n"],"names":[],"mappings":"AAEO,MAAM,
|
|
1
|
+
{"version":3,"file":"api.js","sources":["../../../src/constants/api.ts"],"sourcesContent":["import { StorefrontEnvironment } from '../types';\n\nexport const RECHARGE_API_URL = (environment: StorefrontEnvironment, environmentUri = ''): string => {\n switch (environment) {\n case 'prod':\n return 'https://api.rechargeapps.com';\n case 'stage':\n return 'https://api.stage.rechargeapps.com';\n case 'preprod':\n case 'prestage':\n return `${environmentUri}/api`;\n }\n};\nexport const RECHARGE_ADMIN_URL = (environment: StorefrontEnvironment, environmentUri = ''): string => {\n switch (environment) {\n case 'prod':\n return 'https://admin.rechargeapps.com';\n case 'stage':\n return 'https://admin.stage.rechargeapps.com';\n case 'preprod':\n case 'prestage':\n return environmentUri;\n }\n};\nexport const RECHARGE_CDN_URL = (environment: StorefrontEnvironment): string => {\n switch (environment) {\n case 'prod':\n case 'preprod':\n return 'https://static.rechargecdn.com';\n case 'stage':\n case 'prestage':\n return 'https://static.stage.rechargecdn.com';\n }\n};\nexport const SHOPIFY_APP_PROXY_URL = '/tools/recurring';\n"],"names":[],"mappings":"AAEO,MAAM,gBAAA,GAAmB,CAAC,WAAA,EAAoC,cAAA,GAAiB,EAAA,KAAe;AACnG,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,MAAA;AACH,MAAA,OAAO,8BAAA;AAAA,IACT,KAAK,OAAA;AACH,MAAA,OAAO,oCAAA;AAAA,IACT,KAAK,SAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,GAAG,cAAc,CAAA,IAAA,CAAA;AAAA;AAE9B;AACO,MAAM,kBAAA,GAAqB,CAAC,WAAA,EAAoC,cAAA,GAAiB,EAAA,KAAe;AACrG,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,MAAA;AACH,MAAA,OAAO,gCAAA;AAAA,IACT,KAAK,OAAA;AACH,MAAA,OAAO,sCAAA;AAAA,IACT,KAAK,SAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,cAAA;AAAA;AAEb;AACO,MAAM,gBAAA,GAAmB,CAAC,WAAA,KAA+C;AAC9E,EAAA,QAAQ,WAAA;AAAa,IACnB,KAAK,MAAA;AAAA,IACL,KAAK,SAAA;AACH,MAAA,OAAO,gCAAA;AAAA,IACT,KAAK,OAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,sCAAA;AAAA;AAEb;AACO,MAAM,qBAAA,GAAwB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.js","sources":["../../../src/mappers/cdn.ts"],"sourcesContent":["import {\n CDNBaseWidgetSettings,\n CDNProductRaw,\n CDNWidgetSettings,\n CDNWidgetSettingsRaw,\n CDNProduct,\n CDNProductKeyObject,\n} from '../types';\nimport { omit, parseValues } from './utils';\n\nexport function widgetSettingsMapper(widgetSettingsRaw: CDNWidgetSettingsRaw): CDNWidgetSettings {\n const parsedSettings = parseValues<CDNBaseWidgetSettings>(widgetSettingsRaw);\n\n const auto_inject = parsedSettings.auto_inject === undefined ? true : parsedSettings.auto_inject;\n const valid_pages = parsedSettings.display_on ?? [];\n const is_subscription_first = parsedSettings.first_option === 'autodeliver';\n\n return {\n ...omit(parsedSettings, ['display_on', 'first_option']),\n auto_inject,\n valid_pages,\n is_subscription_first,\n autoInject: auto_inject,\n validPages: valid_pages,\n isSubscriptionFirst: is_subscription_first,\n };\n}\n\nexport function productMapper(productRaw: CDNProductRaw): CDNProduct {\n const is_subscription_only = productRaw.subscription_options?.storefront_purchase_options === 'subscription_only';\n return {\n ...productRaw,\n is_subscription_only,\n isSubscriptionOnly: is_subscription_only,\n };\n}\n\nexport function productArrayMapper(\n productsArray: {\n [key: string]: CDNProductRaw;\n }[]\n): CDNProductKeyObject[] {\n return productsArray.map(productObjRaw => {\n const productObj: CDNProductKeyObject = {};\n Object.entries(productObjRaw).forEach(([key, value]) => {\n // defineProperty creates a real own key even for `__proto__`, avoiding prototype pollution\n Object.defineProperty(productObj, key, {\n value: productMapper(value),\n enumerable: true,\n writable: true,\n configurable: true,\n });\n });\n return productObj;\n });\n}\n"],"names":[],"mappings":";;AAUO,SAAS,qBAAqB,
|
|
1
|
+
{"version":3,"file":"cdn.js","sources":["../../../src/mappers/cdn.ts"],"sourcesContent":["import {\n CDNBaseWidgetSettings,\n CDNProductRaw,\n CDNWidgetSettings,\n CDNWidgetSettingsRaw,\n CDNProduct,\n CDNProductKeyObject,\n} from '../types';\nimport { omit, parseValues } from './utils';\n\nexport function widgetSettingsMapper(widgetSettingsRaw: CDNWidgetSettingsRaw): CDNWidgetSettings {\n const parsedSettings = parseValues<CDNBaseWidgetSettings>(widgetSettingsRaw);\n\n const auto_inject = parsedSettings.auto_inject === undefined ? true : parsedSettings.auto_inject;\n const valid_pages = parsedSettings.display_on ?? [];\n const is_subscription_first = parsedSettings.first_option === 'autodeliver';\n\n return {\n ...omit(parsedSettings, ['display_on', 'first_option']),\n auto_inject,\n valid_pages,\n is_subscription_first,\n autoInject: auto_inject,\n validPages: valid_pages,\n isSubscriptionFirst: is_subscription_first,\n };\n}\n\nexport function productMapper(productRaw: CDNProductRaw): CDNProduct {\n const is_subscription_only = productRaw.subscription_options?.storefront_purchase_options === 'subscription_only';\n return {\n ...productRaw,\n is_subscription_only,\n isSubscriptionOnly: is_subscription_only,\n };\n}\n\nexport function productArrayMapper(\n productsArray: {\n [key: string]: CDNProductRaw;\n }[]\n): CDNProductKeyObject[] {\n return productsArray.map(productObjRaw => {\n const productObj: CDNProductKeyObject = {};\n Object.entries(productObjRaw).forEach(([key, value]) => {\n // defineProperty creates a real own key even for `__proto__`, avoiding prototype pollution\n Object.defineProperty(productObj, key, {\n value: productMapper(value),\n enumerable: true,\n writable: true,\n configurable: true,\n });\n });\n return productObj;\n });\n}\n"],"names":[],"mappings":";;AAUO,SAAS,qBAAqB,iBAAA,EAA4D;AAC/F,EAAA,MAAM,cAAA,GAAiB,YAAmC,iBAAiB,CAAA;AAE3E,EAAA,MAAM,WAAA,GAAc,cAAA,CAAe,WAAA,KAAgB,MAAA,GAAY,OAAO,cAAA,CAAe,WAAA;AACrF,EAAA,MAAM,WAAA,GAAc,cAAA,CAAe,UAAA,IAAc,EAAC;AAClD,EAAA,MAAM,qBAAA,GAAwB,eAAe,YAAA,KAAiB,aAAA;AAE9D,EAAA,OAAO;AAAA,IACL,GAAG,IAAA,CAAK,cAAA,EAAgB,CAAC,YAAA,EAAc,cAAc,CAAC,CAAA;AAAA,IACtD,WAAA;AAAA,IACA,WAAA;AAAA,IACA,qBAAA;AAAA,IACA,UAAA,EAAY,WAAA;AAAA,IACZ,UAAA,EAAY,WAAA;AAAA,IACZ,mBAAA,EAAqB;AAAA,GACvB;AACF;AAEO,SAAS,cAAc,UAAA,EAAuC;AACnE,EAAA,MAAM,oBAAA,GAAuB,UAAA,CAAW,oBAAA,EAAsB,2BAAA,KAAgC,mBAAA;AAC9F,EAAA,OAAO;AAAA,IACL,GAAG,UAAA;AAAA,IACH,oBAAA;AAAA,IACA,kBAAA,EAAoB;AAAA,GACtB;AACF;AAEO,SAAS,mBACd,aAAA,EAGuB;AACvB,EAAA,OAAO,aAAA,CAAc,IAAI,CAAA,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