@rechargeapps/storefront-client 1.88.0 → 1.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/address.js +2 -1
- package/dist/cjs/api/address.js.map +1 -1
- package/dist/cjs/api/auth.js +17 -8
- package/dist/cjs/api/auth.js.map +1 -1
- package/dist/cjs/api/bundle.js +5 -1
- package/dist/cjs/api/bundle.js.map +1 -1
- package/dist/cjs/api/bundleData.js +6 -3
- package/dist/cjs/api/bundleData.js.map +1 -1
- package/dist/cjs/api/cdn.js +2 -1
- package/dist/cjs/api/cdn.js.map +1 -1
- package/dist/cjs/api/charge.js +7 -6
- package/dist/cjs/api/charge.js.map +1 -1
- package/dist/cjs/api/credit.js +4 -2
- package/dist/cjs/api/credit.js.map +1 -1
- package/dist/cjs/api/customer.js +5 -4
- package/dist/cjs/api/customer.js.map +1 -1
- package/dist/cjs/api/customerSurveys.js +2 -1
- package/dist/cjs/api/customerSurveys.js.map +1 -1
- package/dist/cjs/api/membership.js +4 -3
- package/dist/cjs/api/membership.js.map +1 -1
- package/dist/cjs/api/order.js +2 -1
- package/dist/cjs/api/order.js.map +1 -1
- package/dist/cjs/api/subscription.js +10 -9
- package/dist/cjs/api/subscription.js.map +1 -1
- package/dist/cjs/api/tieredDiscount.js +2 -1
- package/dist/cjs/api/tieredDiscount.js.map +1 -1
- package/dist/cjs/mappers/cdn.js +6 -1
- package/dist/cjs/mappers/cdn.js.map +1 -1
- package/dist/cjs/utils/bundle.js +25 -11
- package/dist/cjs/utils/bundle.js.map +1 -1
- package/dist/cjs/utils/bundleData.js +1 -1
- package/dist/cjs/utils/bundleData.js.map +1 -1
- package/dist/cjs/utils/request.js +5 -4
- package/dist/cjs/utils/request.js.map +1 -1
- package/dist/cjs/utils/url.js +8 -0
- package/dist/cjs/utils/url.js.map +1 -0
- package/dist/esm/api/address.js +2 -1
- package/dist/esm/api/address.js.map +1 -1
- package/dist/esm/api/auth.js +17 -8
- package/dist/esm/api/auth.js.map +1 -1
- package/dist/esm/api/bundle.js +5 -1
- package/dist/esm/api/bundle.js.map +1 -1
- package/dist/esm/api/bundleData.js +6 -3
- package/dist/esm/api/bundleData.js.map +1 -1
- package/dist/esm/api/cdn.js +2 -1
- package/dist/esm/api/cdn.js.map +1 -1
- package/dist/esm/api/charge.js +7 -6
- package/dist/esm/api/charge.js.map +1 -1
- package/dist/esm/api/credit.js +4 -2
- package/dist/esm/api/credit.js.map +1 -1
- package/dist/esm/api/customer.js +5 -4
- package/dist/esm/api/customer.js.map +1 -1
- package/dist/esm/api/customerSurveys.js +2 -1
- package/dist/esm/api/customerSurveys.js.map +1 -1
- package/dist/esm/api/membership.js +4 -3
- package/dist/esm/api/membership.js.map +1 -1
- package/dist/esm/api/order.js +2 -1
- package/dist/esm/api/order.js.map +1 -1
- package/dist/esm/api/subscription.js +10 -9
- package/dist/esm/api/subscription.js.map +1 -1
- package/dist/esm/api/tieredDiscount.js +2 -1
- package/dist/esm/api/tieredDiscount.js.map +1 -1
- package/dist/esm/mappers/cdn.js +6 -1
- package/dist/esm/mappers/cdn.js.map +1 -1
- package/dist/esm/utils/bundle.js +25 -11
- package/dist/esm/utils/bundle.js.map +1 -1
- package/dist/esm/utils/bundleData.js +1 -1
- package/dist/esm/utils/bundleData.js.map +1 -1
- package/dist/esm/utils/request.js +3 -2
- package/dist/esm/utils/request.js.map +1 -1
- package/dist/esm/utils/url.js +6 -0
- package/dist/esm/utils/url.js.map +1 -0
- package/dist/index.d.ts +13 -1
- package/dist/umd/recharge-client.min.js +11 -11
- package/package.json +1 -1
package/dist/cjs/api/customer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var request = require('../utils/request.js');
|
|
4
|
+
var url = require('../utils/url.js');
|
|
4
5
|
|
|
5
6
|
async function getCustomer(session, options) {
|
|
6
7
|
const id = session.customerId;
|
|
@@ -38,7 +39,7 @@ async function getDeliverySchedule(session, query) {
|
|
|
38
39
|
}
|
|
39
40
|
const { deliveries } = await request.rechargeApiRequest(
|
|
40
41
|
"get",
|
|
41
|
-
`/customers/${id}/delivery_schedule`,
|
|
42
|
+
`/customers/${url.encodePathSegment(id)}/delivery_schedule`,
|
|
42
43
|
{ query },
|
|
43
44
|
request.getInternalSession(session, "getDeliverySchedule")
|
|
44
45
|
);
|
|
@@ -97,13 +98,13 @@ async function sendCustomerNotification(session, notification, options) {
|
|
|
97
98
|
if (!customerId) {
|
|
98
99
|
throw new Error("Not logged in.");
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
if (!data) {
|
|
101
|
+
if (!Object.prototype.hasOwnProperty.call(customerNotificationMap, notification)) {
|
|
102
102
|
throw new Error("Notification not supported.");
|
|
103
103
|
}
|
|
104
|
+
const data = customerNotificationMap[notification];
|
|
104
105
|
return request.rechargeApiRequest(
|
|
105
106
|
"post",
|
|
106
|
-
`/customers/${customerId}/notifications`,
|
|
107
|
+
`/customers/${url.encodePathSegment(customerId)}/notifications`,
|
|
107
108
|
{
|
|
108
109
|
data: {
|
|
109
110
|
...data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import {\n Customer,\n CustomerCreditSummary,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerNotification,\n CustomerNotificationOptions,\n CustomerNotificationTemplate,\n CustomerNotificationType,\n CustomerPortalAccessOptions,\n CustomerPortalAccessResponse,\n Delivery,\n GetCreditSummaryOptions,\n GetCustomerOptions,\n Session,\n UpdateCustomerRequest,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCustomer')\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n getInternalSession(session, 'updateCustomer')\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${id}/delivery_schedule`,\n { query },\n getInternalSession(session, 'getDeliverySchedule')\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(\n session: Session,\n query?: CustomerPortalAccessOptions\n): Promise<CustomerPortalAccessResponse> {\n return rechargeApiRequest<CustomerPortalAccessResponse>(\n 'get',\n '/portal_access',\n { query },\n getInternalSession(session, 'getCustomerPortalAccess')\n );\n}\n\nexport async function getActiveChurnLandingPageURL(\n session: Session,\n subscriptionId: string | number,\n redirectURL: string\n): Promise<string> {\n if (subscriptionId === undefined || subscriptionId === '') {\n throw new Error('Subscription ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getActiveChurnLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/subscriptions/${subscriptionId}/cancel?token=${temp_token}&subscription=${subscriptionId}&redirect_to=${redirectURL}`;\n}\n\nexport async function getFailedPaymentMethodRecoveryLandingPageURL(session: Session): Promise<string> {\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getFailedPaymentMethodRecoveryLandingPageURL')\n );\n return `${base_url.replace('portal', 'pages')}account/payment-methods?token=${temp_token}&hash=${customer_hash}`;\n}\n\nexport async function getGiftRedemptionLandingPageURL(\n session: Session,\n giftId: string | number,\n redirectURL: string\n): Promise<string> {\n if (giftId === undefined || giftId === '') {\n throw new Error('Gift ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getGiftRedemptionLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/gifts/${giftId}?token=${temp_token}&redirect_to=${redirectURL}`;\n}\n\nconst customerNotificationMap: Record<\n CustomerNotification,\n { type: CustomerNotificationType; template_type: CustomerNotificationTemplate }\n> = {\n SHOPIFY_UPDATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_update_payment_information',\n },\n SHOPIFY_MIGRATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_migrate_payment_information',\n },\n};\n\nexport async function sendCustomerNotification<T extends CustomerNotification>(\n session: Session,\n notification: CustomerNotification,\n options?: CustomerNotificationOptions<T>\n): Promise<void> {\n const customerId = session.customerId;\n if (!customerId) {\n throw new Error('Not logged in.');\n }\n
|
|
1
|
+
{"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import {\n Customer,\n CustomerCreditSummary,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerNotification,\n CustomerNotificationOptions,\n CustomerNotificationTemplate,\n CustomerNotificationType,\n CustomerPortalAccessOptions,\n CustomerPortalAccessResponse,\n Delivery,\n GetCreditSummaryOptions,\n GetCustomerOptions,\n Session,\n UpdateCustomerRequest,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport { encodePathSegment } from '../utils/url';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCustomer')\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n getInternalSession(session, 'updateCustomer')\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${encodePathSegment(id)}/delivery_schedule`,\n { query },\n getInternalSession(session, 'getDeliverySchedule')\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(\n session: Session,\n query?: CustomerPortalAccessOptions\n): Promise<CustomerPortalAccessResponse> {\n return rechargeApiRequest<CustomerPortalAccessResponse>(\n 'get',\n '/portal_access',\n { query },\n getInternalSession(session, 'getCustomerPortalAccess')\n );\n}\n\nexport async function getActiveChurnLandingPageURL(\n session: Session,\n subscriptionId: string | number,\n redirectURL: string\n): Promise<string> {\n if (subscriptionId === undefined || subscriptionId === '') {\n throw new Error('Subscription ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getActiveChurnLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/subscriptions/${subscriptionId}/cancel?token=${temp_token}&subscription=${subscriptionId}&redirect_to=${redirectURL}`;\n}\n\nexport async function getFailedPaymentMethodRecoveryLandingPageURL(session: Session): Promise<string> {\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getFailedPaymentMethodRecoveryLandingPageURL')\n );\n return `${base_url.replace('portal', 'pages')}account/payment-methods?token=${temp_token}&hash=${customer_hash}`;\n}\n\nexport async function getGiftRedemptionLandingPageURL(\n session: Session,\n giftId: string | number,\n redirectURL: string\n): Promise<string> {\n if (giftId === undefined || giftId === '') {\n throw new Error('Gift ID is required');\n }\n const { base_url, customer_hash, temp_token } = await getCustomerPortalAccess(\n getInternalSession(session, 'getGiftRedemptionLandingPageURL')\n );\n return `${base_url.replace(\n 'portal',\n 'pages'\n )}${customer_hash}/gifts/${giftId}?token=${temp_token}&redirect_to=${redirectURL}`;\n}\n\nconst customerNotificationMap: Record<\n CustomerNotification,\n { type: CustomerNotificationType; template_type: CustomerNotificationTemplate }\n> = {\n SHOPIFY_UPDATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_update_payment_information',\n },\n SHOPIFY_MIGRATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_migrate_payment_information',\n },\n};\n\nexport async function sendCustomerNotification<T extends CustomerNotification>(\n session: Session,\n notification: CustomerNotification,\n options?: CustomerNotificationOptions<T>\n): Promise<void> {\n const customerId = session.customerId;\n if (!customerId) {\n throw new Error('Not logged in.');\n }\n // Own-property check: a plain-object lookup resolves inherited keys such as\n // `__proto__`/`constructor` to truthy prototype values, bypassing this guard\n // (H1-3889216 / SEC-4002; same class as the CDN/bundle maps fixed in SEC-3996).\n if (!Object.prototype.hasOwnProperty.call(customerNotificationMap, notification)) {\n throw new Error('Notification not supported.');\n }\n const data = customerNotificationMap[notification];\n return rechargeApiRequest<void>(\n 'post',\n `/customers/${encodePathSegment(customerId)}/notifications`,\n {\n data: {\n ...data,\n template_vars: options,\n },\n },\n getInternalSession(session, 'sendCustomerNotification')\n );\n}\n\n/** @deprecated Use `getCreditSummary` on credit instead */\nexport async function getCreditSummary(\n session: Session,\n options?: GetCreditSummaryOptions\n): Promise<CustomerCreditSummary> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { credit_summary } = await rechargeApiRequest<{ credit_summary: CustomerCreditSummary }>(\n 'get',\n `/customers/${encodePathSegment(id)}/credit_summary`,\n {\n query: { include: options?.include },\n },\n getInternalSession(session, 'getCreditSummary')\n );\n return credit_summary;\n}\n"],"names":["rechargeApiRequest","getInternalSession","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ACA,EAAM,MAAA,IAAA,GAAO,wBAAwB,YAAY,CAAA,CAAA;AACjD,EAAO,OAAAD,0BAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,WAAA,EAAcE,qBAAkB,CAAA,UAAU,CAAC,CAAA,cAAA,CAAA;AAAA,IAC3C;AAAA,MACE,IAAM,EAAA;AAAA,QACJ,GAAG,IAAA;AAAA,QACH,aAAe,EAAA,OAAA;AAAA,OACjB;AAAA,KACF;AAAA,IACAD,0BAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACF;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var request = require('../utils/request.js');
|
|
4
|
+
var url = require('../utils/url.js');
|
|
4
5
|
|
|
5
6
|
async function getCustomerSurveyReasons(session, customerId, subscriptionId) {
|
|
6
7
|
const customerSurveysReasonsResponse = await request.rechargeApiRequest(
|
|
@@ -14,7 +15,7 @@ async function getCustomerSurveyReasons(session, customerId, subscriptionId) {
|
|
|
14
15
|
async function getCustomerSurveyOffers(session, customerId, customerSurveyId, responseId) {
|
|
15
16
|
const customerSurveysOffersResponse = await request.rechargeApiRequest(
|
|
16
17
|
"post",
|
|
17
|
-
`/customer_surveys/${customerSurveyId}/customer_response`,
|
|
18
|
+
`/customer_surveys/${url.encodePathSegment(customerSurveyId)}/customer_response`,
|
|
18
19
|
{ data: { customer_id: customerId, response_id: responseId } },
|
|
19
20
|
request.getInternalSession(session, "getCustomerSurveyOffers")
|
|
20
21
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customerSurveys.js","sources":["../../../src/api/customerSurveys.ts"],"sourcesContent":["import {\n Session,\n CustomerSurveyOffersResponse,\n CustomerSurveyReasonsResponse,\n CustomerSurveyOfferParams,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomerSurveyReasons(session: Session, customerId: number, subscriptionId: number) {\n const customerSurveysReasonsResponse = await rechargeApiRequest<CustomerSurveyReasonsResponse>(\n 'post',\n `/customer_surveys/cancellation_prevention`,\n { data: { customer_id: customerId, subscription_id: subscriptionId } },\n getInternalSession(session, 'getCustomerSurveyReasons')\n );\n return customerSurveysReasonsResponse;\n}\n\nexport async function getCustomerSurveyOffers(\n session: Session,\n customerId: number,\n customerSurveyId: number,\n responseId: number\n) {\n const customerSurveysOffersResponse = await rechargeApiRequest<CustomerSurveyOffersResponse>(\n 'post',\n `/customer_surveys/${customerSurveyId}/customer_response`,\n { data: { customer_id: customerId, response_id: responseId } },\n getInternalSession(session, 'getCustomerSurveyOffers')\n );\n return customerSurveysOffersResponse;\n}\n\nexport async function claimOfferCustomerSurvey(session: Session, payload: CustomerSurveyOfferParams) {\n await rechargeApiRequest(\n 'post',\n `/offers/claim`,\n { data: payload },\n getInternalSession(session, 'claimOfferCustomerSurvey')\n );\n return {};\n}\n"],"names":["rechargeApiRequest","getInternalSession"],"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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AASsB,eAAA,wBAAA,CAAyB,OAAkB,EAAA,UAAA,EAAoB,cAAwB,EAAA;AAC3G,EAAA,MAAM,iCAAiC,MAAMA,0BAAA;AAAA,IAC3C,MAAA;AAAA,IACA,CAAA,yCAAA,CAAA;AAAA,IACA,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,eAAA,EAAiB,gBAAiB,EAAA;AAAA,IACrEC,0BAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACA,EAAO,OAAA,8BAAA,CAAA;AACT,CAAA;AAEA,eAAsB,uBACpB,CAAA,OAAA,EACA,UACA,EAAA,gBAAA,EACA,UACA,EAAA;AACA,EAAA,MAAM,gCAAgC,MAAMD,0BAAA;AAAA,IAC1C,MAAA;AAAA,IACA,CAAA,kBAAA,EAAqBE,qBAAkB,CAAA,gBAAgB,CAAC,CAAA,kBAAA,CAAA;AAAA,IACxD,EAAE,IAAM,EAAA,EAAE,aAAa,UAAY,EAAA,WAAA,EAAa,YAAa,EAAA;AAAA,IAC7DD,0BAAA,CAAmB,SAAS,yBAAyB,CAAA;AAAA,GACvD,CAAA;AACA,EAAO,OAAA,6BAAA,CAAA;AACT,CAAA;AAEsB,eAAA,wBAAA,CAAyB,SAAkB,OAAoC,EAAA;AACnG,EAAM,MAAAD,0BAAA;AAAA,IACJ,MAAA;AAAA,IACA,CAAA,aAAA,CAAA;AAAA,IACA,EAAE,MAAM,OAAQ,EAAA;AAAA,IAChBC,0BAAA,CAAmB,SAAS,0BAA0B,CAAA;AAAA,GACxD,CAAA;AACA,EAAA,OAAO,EAAC,CAAA;AACV;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var request = require('../utils/request.js');
|
|
4
|
+
var url = require('../utils/url.js');
|
|
4
5
|
|
|
5
6
|
async function getMembership(session, id) {
|
|
6
7
|
if (id === void 0 || id === "") {
|
|
@@ -28,7 +29,7 @@ async function cancelMembership(session, id, cancelRequest) {
|
|
|
28
29
|
}
|
|
29
30
|
const { membership } = await request.rechargeApiRequest(
|
|
30
31
|
"post",
|
|
31
|
-
`/memberships/${id}/cancel`,
|
|
32
|
+
`/memberships/${url.encodePathSegment(id)}/cancel`,
|
|
32
33
|
{
|
|
33
34
|
data: cancelRequest
|
|
34
35
|
},
|
|
@@ -42,7 +43,7 @@ async function activateMembership(session, id, activateRequest) {
|
|
|
42
43
|
}
|
|
43
44
|
const { membership } = await request.rechargeApiRequest(
|
|
44
45
|
"post",
|
|
45
|
-
`/memberships/${id}/activate`,
|
|
46
|
+
`/memberships/${url.encodePathSegment(id)}/activate`,
|
|
46
47
|
{
|
|
47
48
|
data: activateRequest
|
|
48
49
|
},
|
|
@@ -56,7 +57,7 @@ async function changeMembership(session, id, changeRequest) {
|
|
|
56
57
|
}
|
|
57
58
|
const { membership } = await request.rechargeApiRequest(
|
|
58
59
|
"post",
|
|
59
|
-
`/memberships/${id}/change`,
|
|
60
|
+
`/memberships/${url.encodePathSegment(id)}/change`,
|
|
60
61
|
{
|
|
61
62
|
data: changeRequest
|
|
62
63
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership.js","sources":["../../../src/api/membership.ts"],"sourcesContent":["import {\n ActivateMembershipRequest,\n CancelMembershipRequest,\n ChangeMembershipRequest,\n MembershipListParams,\n MembershipListResponse,\n MembershipResponse,\n Session,\n} from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\n/** @internal Retrieves membership information for passed in id */\nexport async function getMembership(session: Session, id: string | number) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'get',\n `/memberships`,\n { id },\n getInternalSession(session, 'getMembership')\n );\n return membership;\n}\n\n/** @internal Retrieves a list of memberships */\nexport function listMemberships(session: Session, query?: MembershipListParams) {\n return rechargeApiRequest<MembershipListResponse>(\n 'get',\n `/memberships`,\n { query },\n getInternalSession(session, 'listMemberships')\n );\n}\n\n/** @internal Cancels a membership */\nexport async function cancelMembership(session: Session, id: string | number, cancelRequest: CancelMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${id}/cancel`,\n {\n data: cancelRequest,\n },\n getInternalSession(session, 'cancelMembership')\n );\n return membership;\n}\n\n/** @internal Activates a membership */\nexport async function activateMembership(\n session: Session,\n id: string | number,\n activateRequest: ActivateMembershipRequest\n) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${id}/activate`,\n {\n data: activateRequest,\n },\n getInternalSession(session, 'activateMembership')\n );\n return membership;\n}\n\n/** @internal changes a membership program/product*/\nexport async function changeMembership(session: Session, id: string | number, changeRequest: ChangeMembershipRequest) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { membership } = await rechargeApiRequest<MembershipResponse>(\n 'post',\n `/memberships/${id}/change`,\n {\n data: changeRequest,\n },\n getInternalSession(session, 'changeMembership')\n );\n return membership;\n}\n"],"names":["rechargeApiRequest","getInternalSession"],"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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AAasB,eAAA,aAAA,CAAc,SAAkB,EAAqB,EAAA;AACzE,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI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;AACA,EAAM,MAAA,EAAE,UAAW,EAAA,GAAI,MAAMD,0BAAA;AAAA,IAC3B,MAAA;AAAA,IACA,CAAA,aAAA,EAAgBE,qBAAkB,CAAA,EAAE,CAAC,CAAA,SAAA,CAAA;AAAA,IACrC;AAAA,MACE,IAAM,EAAA,eAAA;AAAA,KACR;AAAA,IACAD,0BAAA,CAAmB,SAAS,oBAAoB,CAAA;AAAA,GAClD,CAAA;AACA,EAAO,OAAA,UAAA,CAAA;AACT,CAAA;AAGsB,eAAA,gBAAA,CAAiB,OAAkB,EAAA,EAAA,EAAqB,aAAwC,EAAA;AACpH,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,UAAW,EAAA,GAAI,MAAMD,0BAAA;AAAA,IAC3B,MAAA;AAAA,IACA,CAAA,aAAA,EAAgBE,qBAAkB,CAAA,EAAE,CAAC,CAAA,OAAA,CAAA;AAAA,IACrC;AAAA,MACE,IAAM,EAAA,aAAA;AAAA,KACR;AAAA,IACAD,0BAAA,CAAmB,SAAS,kBAAkB,CAAA;AAAA,GAChD,CAAA;AACA,EAAO,OAAA,UAAA,CAAA;AACT;;;;;;;;"}
|
package/dist/cjs/api/order.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var request = require('../utils/request.js');
|
|
4
|
+
var url = require('../utils/url.js');
|
|
4
5
|
|
|
5
6
|
async function getOrder(session, id) {
|
|
6
7
|
if (id === void 0 || id === "") {
|
|
@@ -25,7 +26,7 @@ async function delayOrder(session, id) {
|
|
|
25
26
|
}
|
|
26
27
|
const { order } = await request.rechargeApiRequest(
|
|
27
28
|
"post",
|
|
28
|
-
`/orders/${id}/delay`,
|
|
29
|
+
`/orders/${url.encodePathSegment(id)}/delay`,
|
|
29
30
|
{},
|
|
30
31
|
request.getInternalSession(session, "delayOrder")
|
|
31
32
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse, Session } from '../types';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\n\nexport async function getOrder(session: Session, id: string | number): Promise<Order> {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'get',\n `/orders`,\n {\n id,\n },\n getInternalSession(session, 'getOrder')\n );\n return order;\n}\n\nexport function listOrders(session: Session, query?: OrderListParams): Promise<OrdersResponse> {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query }, getInternalSession(session, 'listOrders'));\n}\n\nexport async function delayOrder(session: Session, id: number | string) {\n if (id === undefined || id === '') {\n throw new Error('ID is required');\n }\n const { order } = await rechargeApiRequest<{ order: Order }>(\n 'post',\n `/orders/${id}/delay`,\n {},\n getInternalSession(session, 'delayOrder')\n );\n\n return order;\n}\n"],"names":["rechargeApiRequest","getInternalSession"],"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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AAIsB,eAAA,QAAA,CAAS,SAAkB,EAAqC,EAAA;AACpF,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAMA,0BAAA;AAAA,IACtB,KAAA;AAAA,IACA,CAAA,OAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,KACF;AAAA,IACAC,0BAAA,CAAmB,SAAS,UAAU,CAAA;AAAA,GACxC,CAAA;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEgB,SAAA,UAAA,CAAW,SAAkB,KAAkD,EAAA;AAC7F,EAAO,OAAAD,0BAAA,CAAmC,OAAO,CAAW,OAAA,CAAA,EAAA,EAAE,OAAS,EAAAC,0BAAA,CAAmB,OAAS,EAAA,YAAY,CAAC,CAAA,CAAA;AAClH,CAAA;AAEsB,eAAA,UAAA,CAAW,SAAkB,EAAqB,EAAA;AACtE,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,MAAMD,0BAAA;AAAA,IACtB,MAAA;AAAA,IACA,CAAA,QAAA,EAAWE,qBAAkB,CAAA,EAAE,CAAC,CAAA,MAAA,CAAA;AAAA,IAChC,EAAC;AAAA,IACDD,0BAAA,CAAmB,SAAS,YAAY,CAAA;AAAA,GAC1C,CAAA;AAEA,EAAO,OAAA,KAAA,CAAA;AACT;;;;;;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var partial = require('lodash.partial');
|
|
4
4
|
var request = require('../utils/request.js');
|
|
5
|
+
var url = require('../utils/url.js');
|
|
5
6
|
var subscription = require('../mappers/subscription.js');
|
|
6
7
|
|
|
7
8
|
async function getSubscription(session, id, options) {
|
|
@@ -33,7 +34,7 @@ function listSubscriptionAddons(session, id, query) {
|
|
|
33
34
|
}
|
|
34
35
|
return request.rechargeApiRequest(
|
|
35
36
|
"get",
|
|
36
|
-
`/subscriptions/${id}/addons`,
|
|
37
|
+
`/subscriptions/${url.encodePathSegment(id)}/addons`,
|
|
37
38
|
{ query },
|
|
38
39
|
request.getInternalSession(session, "listSubscriptionAddons")
|
|
39
40
|
);
|
|
@@ -72,7 +73,7 @@ async function updateSubscriptionChargeDate(session, id, date, query) {
|
|
|
72
73
|
}
|
|
73
74
|
const { subscription } = await request.rechargeApiRequest(
|
|
74
75
|
"post",
|
|
75
|
-
`/subscriptions/${id}/set_next_charge_date`,
|
|
76
|
+
`/subscriptions/${url.encodePathSegment(id)}/set_next_charge_date`,
|
|
76
77
|
{
|
|
77
78
|
data: { date },
|
|
78
79
|
query
|
|
@@ -87,7 +88,7 @@ async function updateSubscriptionAddress(session, id, address_id) {
|
|
|
87
88
|
}
|
|
88
89
|
const { subscription } = await request.rechargeApiRequest(
|
|
89
90
|
"post",
|
|
90
|
-
`/subscriptions/${id}/change_address`,
|
|
91
|
+
`/subscriptions/${url.encodePathSegment(id)}/change_address`,
|
|
91
92
|
{
|
|
92
93
|
data: { address_id }
|
|
93
94
|
},
|
|
@@ -101,7 +102,7 @@ async function cancelSubscription(session, id, cancelRequest, query) {
|
|
|
101
102
|
}
|
|
102
103
|
const { subscription } = await request.rechargeApiRequest(
|
|
103
104
|
"post",
|
|
104
|
-
`/subscriptions/${id}/cancel`,
|
|
105
|
+
`/subscriptions/${url.encodePathSegment(id)}/cancel`,
|
|
105
106
|
{
|
|
106
107
|
data: cancelRequest,
|
|
107
108
|
query
|
|
@@ -116,7 +117,7 @@ async function activateSubscription(session, id, query) {
|
|
|
116
117
|
}
|
|
117
118
|
const { subscription } = await request.rechargeApiRequest(
|
|
118
119
|
"post",
|
|
119
|
-
`/subscriptions/${id}/activate`,
|
|
120
|
+
`/subscriptions/${url.encodePathSegment(id)}/activate`,
|
|
120
121
|
{ query },
|
|
121
122
|
request.getInternalSession(session, "activateSubscription")
|
|
122
123
|
);
|
|
@@ -128,7 +129,7 @@ async function skipSubscriptionCharge(session, id, date) {
|
|
|
128
129
|
}
|
|
129
130
|
const { charge } = await request.rechargeApiRequest(
|
|
130
131
|
"post",
|
|
131
|
-
`/subscriptions/${id}/charges/skip`,
|
|
132
|
+
`/subscriptions/${url.encodePathSegment(id)}/charges/skip`,
|
|
132
133
|
{
|
|
133
134
|
data: {
|
|
134
135
|
date,
|
|
@@ -177,7 +178,7 @@ async function createSubscriptions(session, createRequestBulk, query) {
|
|
|
177
178
|
}
|
|
178
179
|
const { subscriptions } = await request.rechargeApiRequest(
|
|
179
180
|
"post",
|
|
180
|
-
`/addresses/${addressId}/subscriptions-bulk`,
|
|
181
|
+
`/addresses/${url.encodePathSegment(addressId)}/subscriptions-bulk`,
|
|
181
182
|
{
|
|
182
183
|
data: { subscriptions: requestData, commit_update: !!query?.commit },
|
|
183
184
|
headers: {
|
|
@@ -209,7 +210,7 @@ async function updateSubscriptions(session, addressId, updateRequestBulk, query)
|
|
|
209
210
|
}
|
|
210
211
|
const { subscriptions } = await request.rechargeApiRequest(
|
|
211
212
|
"put",
|
|
212
|
-
`/addresses/${addressId}/subscriptions-bulk`,
|
|
213
|
+
`/addresses/${url.encodePathSegment(addressId)}/subscriptions-bulk`,
|
|
213
214
|
{
|
|
214
215
|
data: { subscriptions: requestData, commit_update: !!query?.commit },
|
|
215
216
|
headers: {
|
|
@@ -239,7 +240,7 @@ async function deleteSubscriptions(session, addressId, deleteRequestBulk, query)
|
|
|
239
240
|
}
|
|
240
241
|
await request.rechargeApiRequest(
|
|
241
242
|
"delete",
|
|
242
|
-
`/addresses/${addressId}/subscriptions-bulk`,
|
|
243
|
+
`/addresses/${url.encodePathSegment(addressId)}/subscriptions-bulk`,
|
|
243
244
|
{
|
|
244
245
|
data: { subscriptions: deleteRequestBulk, send_email: !!query?.send_email, commit_update: !!query?.commit },
|
|
245
246
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import partial from 'lodash.partial';\nimport { getInternalSession, rechargeApiRequest } from '../utils/request';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n BasicSubscriptionParams,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n UpdateSubscriptionsParams,\n Session,\n ChargeResponse,\n CreateRecipientAddress,\n Onetime,\n IsoDateString,\n CreateSubscriptionsParams,\n CreateSubscriptionsRequest,\n DeleteSubscriptionsParams,\n DeleteSubscriptionsRequest,\n UpdateSubscriptionChargeDateParams,\n SubscriptionListAddonsParams,\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/${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/${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/${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/${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/${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/${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 * 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 bulkSubscriptionMapperPartial = partial(bulkSubscriptionCreateMapper, customerId);\n const requestData = createRequestBulk.map(bulkSubscriptionMapperPartial);\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/${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 bulkSubscriptionMapperPartial = partial(bulkSubscriptionUpdateMapper, !!query?.force_update);\n const requestData = updateRequestBulk.map(bulkSubscriptionMapperPartial);\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/${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/${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":["rechargeApiRequest","getInternalSession","bulkSubscriptionCreateMapper","subscriptionMapperOldToNew","bulkSubscriptionUpdateMapper"],"mappings":";;;;;;AAiCsB,eAAA,eAAA,CACpB,OACA,EAAA,EAAA,EACA,OACuB,EAAA;AACvB,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,YAAa,EAAA,GAAI,MAAMA,0BAAA;AAAA,IAC7B,KAAA;AAAA,IACA,CAAA,cAAA,CAAA;AAAA,IACA;AAAA,MACE,EAAA;AAAA,MACA,KAAO,EAAA,EAAE,OAAS,EAAA,OAAA,EAAS,OAAQ,EAAA;AAAA,KACrC;AAAA,IACAC,0BAAA,CAAmB,SAAS,iBAAiB,CAAA;AAAA,GAC/C,CAAA;AACA,EAAO,OAAA,YAAA,CAAA;AACT,CAAA;AAEgB,SAAA,iBAAA,CAAkB,SAAkB,KAAgE,EAAA;AAClH,EAAO,OAAAD,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,cAAA,CAAA;AAAA,IACA,EAAE,KAAM,EAAA;AAAA,IACRC,0BAAA,CAAmB,SAAS,mBAAmB,CAAA;AAAA,GACjD,CAA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AAA;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,MAAAH,0BAAA;AAAA,IACJ,QAAA;AAAA,IACA,cAAc,SAAS,CAAA,mBAAA,CAAA;AAAA,IACvB;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,IACAC,0BAAA,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 partial from 'lodash.partial';\nimport { 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} 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 * 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 bulkSubscriptionMapperPartial = partial(bulkSubscriptionCreateMapper, customerId);\n const requestData = createRequestBulk.map(bulkSubscriptionMapperPartial);\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 bulkSubscriptionMapperPartial = partial(bulkSubscriptionUpdateMapper, !!query?.force_update);\n const requestData = updateRequestBulk.map(bulkSubscriptionMapperPartial);\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":["rechargeApiRequest","getInternalSession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AAA,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,MAAAJ,0BAAA;AAAA,IACJ,QAAA;AAAA,IACA,CAAA,WAAA,EAAcE,qBAAkB,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,IACAD,0BAAA,CAAmB,SAAS,qBAAqB,CAAA;AAAA,GACnD,CAAA;AACA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var request = require('../utils/request.js');
|
|
4
|
+
var url = require('../utils/url.js');
|
|
4
5
|
|
|
5
6
|
function listTieredDiscounts(session, options) {
|
|
6
7
|
if (!session.customerId) {
|
|
@@ -24,7 +25,7 @@ async function getTieredDiscount(session, id) {
|
|
|
24
25
|
}
|
|
25
26
|
const { tiered_discount } = await request.rechargeApiRequest(
|
|
26
27
|
"get",
|
|
27
|
-
`/incentives/tiered_discounts/${id}`,
|
|
28
|
+
`/incentives/tiered_discounts/${url.encodePathSegment(id)}`,
|
|
28
29
|
{},
|
|
29
30
|
request.getInternalSession(session, "getTieredDiscount")
|
|
30
31
|
);
|
|
@@ -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';\n\nexport function listTieredDiscounts(\n session: Session,\n options?: TieredDiscountsParams\n): Promise<TieredDiscountsResponse> {\n if (!session.customerId) {\n throw new Error('Not logged in.');\n }\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 (!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 { tiered_discount } = await rechargeApiRequest<{ tiered_discount: TieredDiscount }>(\n 'get',\n `/incentives/tiered_discounts/${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":["rechargeApiRequest","getInternalSession"],"mappings":"
|
|
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 if (!session.customerId) {\n throw new Error('Not logged in.');\n }\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 (!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 { 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":["rechargeApiRequest","getInternalSession","encodePathSegment"],"mappings":";;;;;AAWgB,SAAA,mBAAA,CACd,SACA,OACkC,EAAA;AAClC,EAAI,IAAA,CAAC,QAAQ,UAAY,EAAA;AACvB,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAO,OAAAA,0BAAA;AAAA,IACL,KAAA;AAAA,IACA,CAAA,4BAAA,CAAA;AAAA,IACA;AAAA,MACE,KAAO,EAAA,OAAA;AAAA,KACT;AAAA,IACAC,0BAAA,CAAmB,SAAS,qBAAqB,CAAA;AAAA,GACnD,CAAA;AACF,CAAA;AAEsB,eAAA,iBAAA,CAAkB,SAAkB,EAA8C,EAAA;AACtG,EAAI,IAAA,CAAC,QAAQ,UAAY,EAAA;AACvB,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAI,IAAA,EAAA,KAAO,KAAa,CAAA,IAAA,EAAA,KAAO,EAAI,EAAA;AACjC,IAAM,MAAA,IAAI,MAAM,gBAAgB,CAAA,CAAA;AAAA,GAClC;AACA,EAAM,MAAA,EAAE,eAAgB,EAAA,GAAI,MAAMD,0BAAA;AAAA,IAChC,KAAA;AAAA,IACA,CAAA,6BAAA,EAAgCE,qBAAkB,CAAA,EAAE,CAAC,CAAA,CAAA;AAAA,IACrD,EAAC;AAAA,IACDD,0BAAA,CAAmB,SAAS,mBAAmB,CAAA;AAAA,GACjD,CAAA;AACA,EAAO,OAAA,eAAA,CAAA;AACT,CAAA;AAEgB,SAAA,uBAAA,CACd,SACA,IACuC,EAAA;AACvC,EAAO,OAAAD,0BAAA;AAAA,IACL,MAAA;AAAA,IACA,CAAA,mCAAA,CAAA;AAAA,IACA,EAAE,MAAM,IAAK,EAAA;AAAA,IACbC,0BAAA,CAAmB,SAAS,yBAAyB,CAAA;AAAA,GACvD,CAAA;AACF;;;;;;"}
|
package/dist/cjs/mappers/cdn.js
CHANGED
|
@@ -30,7 +30,12 @@ function productArrayMapper(productsArray) {
|
|
|
30
30
|
return productsArray.map((productObjRaw) => {
|
|
31
31
|
const productObj = {};
|
|
32
32
|
Object.entries(productObjRaw).forEach(([key, value]) => {
|
|
33
|
-
productObj
|
|
33
|
+
Object.defineProperty(productObj, key, {
|
|
34
|
+
value: productMapper(value),
|
|
35
|
+
enumerable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
});
|
|
34
39
|
});
|
|
35
40
|
return productObj;
|
|
36
41
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.js","sources":["../../../src/mappers/cdn.ts"],"sourcesContent":["import omit from 'lodash.omit';\nimport {\n CDNBaseWidgetSettings,\n CDNProductRaw,\n CDNWidgetSettings,\n CDNWidgetSettingsRaw,\n CDNProduct,\n CDNProductKeyObject,\n} from '../types';\nimport { 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 productObj
|
|
1
|
+
{"version":3,"file":"cdn.js","sources":["../../../src/mappers/cdn.ts"],"sourcesContent":["import omit from 'lodash.omit';\nimport {\n CDNBaseWidgetSettings,\n CDNProductRaw,\n CDNWidgetSettings,\n CDNWidgetSettingsRaw,\n CDNProduct,\n CDNProductKeyObject,\n} from '../types';\nimport { 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":["parseValues"],"mappings":";;;;;AAWO,SAAS,qBAAqB,iBAA4D,EAAA;AAC/F,EAAM,MAAA,cAAA,GAAiBA,kBAAmC,iBAAiB,CAAA,CAAA;AAE3E,EAAA,MAAM,WAAc,GAAA,cAAA,CAAe,WAAgB,KAAA,KAAA,CAAA,GAAY,OAAO,cAAe,CAAA,WAAA,CAAA;AACrF,EAAM,MAAA,WAAA,GAAc,cAAe,CAAA,UAAA,IAAc,EAAC,CAAA;AAClD,EAAM,MAAA,qBAAA,GAAwB,eAAe,YAAiB,KAAA,aAAA,CAAA;AAE9D,EAAO,OAAA;AAAA,IACL,GAAG,IAAK,CAAA,cAAA,EAAgB,CAAC,YAAA,EAAc,cAAc,CAAC,CAAA;AAAA,IACtD,WAAA;AAAA,IACA,WAAA;AAAA,IACA,qBAAA;AAAA,IACA,UAAY,EAAA,WAAA;AAAA,IACZ,UAAY,EAAA,WAAA;AAAA,IACZ,mBAAqB,EAAA,qBAAA;AAAA,GACvB,CAAA;AACF,CAAA;AAEO,SAAS,cAAc,UAAuC,EAAA;AACnE,EAAM,MAAA,oBAAA,GAAuB,UAAW,CAAA,oBAAA,EAAsB,2BAAgC,KAAA,mBAAA,CAAA;AAC9F,EAAO,OAAA;AAAA,IACL,GAAG,UAAA;AAAA,IACH,oBAAA;AAAA,IACA,kBAAoB,EAAA,oBAAA;AAAA,GACtB,CAAA;AACF,CAAA;AAEO,SAAS,mBACd,aAGuB,EAAA;AACvB,EAAO,OAAA,aAAA,CAAc,IAAI,CAAiB,aAAA,KAAA;AACxC,IAAA,MAAM,aAAkC,EAAC,CAAA;AACzC,IAAO,MAAA,CAAA,OAAA,CAAQ,aAAa,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAC,GAAA,EAAK,KAAK,CAAM,KAAA;AAEtD,MAAO,MAAA,CAAA,cAAA,CAAe,YAAY,GAAK,EAAA;AAAA,QACrC,KAAA,EAAO,cAAc,KAAK,CAAA;AAAA,QAC1B,UAAY,EAAA,IAAA;AAAA,QACZ,QAAU,EAAA,IAAA;AAAA,QACV,YAAc,EAAA,IAAA;AAAA,OACf,CAAA,CAAA;AAAA,KACF,CAAA,CAAA;AACD,IAAO,OAAA,UAAA,CAAA;AAAA,GACR,CAAA,CAAA;AACH;;;;;;"}
|
package/dist/cjs/utils/bundle.js
CHANGED
|
@@ -24,7 +24,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
24
24
|
__accessCheck(obj, member, "access private method");
|
|
25
25
|
return method;
|
|
26
26
|
};
|
|
27
|
-
var _bundleSettings, _items, _bundleData, _formatBundleSettings, formatBundleSettings_fn, _formatBundleData, formatBundleData_fn, _isValueInRange, isValueInRange_fn, _unique, unique_fn;
|
|
27
|
+
var _bundleSettings, _items, _bundleData, _formatBundleSettings, formatBundleSettings_fn, _formatBundleData, formatBundleData_fn, _isValueInRange, isValueInRange_fn, _unique, unique_fn, _hasOwn, hasOwn_fn;
|
|
28
28
|
function toLineItemProperty(bundle) {
|
|
29
29
|
const opts = {
|
|
30
30
|
variantId: xdr.Uint64.fromString(bundle.variantId.toString()),
|
|
@@ -93,6 +93,9 @@ class BundleSelectionValidator {
|
|
|
93
93
|
__privateAdd(this, _formatBundleData);
|
|
94
94
|
__privateAdd(this, _isValueInRange);
|
|
95
95
|
__privateAdd(this, _unique);
|
|
96
|
+
// Own-property membership check. Guards against inherited keys (e.g. `__proto__`,
|
|
97
|
+
// `constructor`, `toString`) resolving to truthy values on plain-object maps.
|
|
98
|
+
__privateAdd(this, _hasOwn);
|
|
96
99
|
__privateAdd(this, _bundleSettings, void 0);
|
|
97
100
|
__privateAdd(this, _items, void 0);
|
|
98
101
|
__privateAdd(this, _bundleData, void 0);
|
|
@@ -137,7 +140,10 @@ class BundleSelectionValidator {
|
|
|
137
140
|
}
|
|
138
141
|
areSelectedCollectionsValid(externalVariantId) {
|
|
139
142
|
const variantSettings = __privateGet(this, _bundleSettings)?.variantsSettings[externalVariantId];
|
|
140
|
-
const
|
|
143
|
+
const optionSources = variantSettings?.optionSources;
|
|
144
|
+
const invalidCollections = __privateGet(this, _items).filter(
|
|
145
|
+
({ collectionId }) => !optionSources || !__privateMethod(this, _hasOwn, hasOwn_fn).call(this, optionSources, collectionId)
|
|
146
|
+
);
|
|
141
147
|
if (invalidCollections.length) {
|
|
142
148
|
const invalidIds = __privateMethod(this, _unique, unique_fn).call(this, invalidCollections.map(({ collectionId }) => collectionId)).join(", ");
|
|
143
149
|
throw `The collections (${invalidIds}) are no longer valid for the bundle variant (${externalVariantId}).`;
|
|
@@ -148,7 +154,7 @@ class BundleSelectionValidator {
|
|
|
148
154
|
const totalSelectedByCollection = __privateGet(this, _items).reduce((acc, current) => {
|
|
149
155
|
acc[current.collectionId] = current.quantity + (acc[current.collectionId] || 0);
|
|
150
156
|
return acc;
|
|
151
|
-
},
|
|
157
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
152
158
|
const variantSettings = __privateGet(this, _bundleSettings)?.variantsSettings[externalVariantId];
|
|
153
159
|
const invalidItems = Object.values(variantSettings?.optionSources || {}).filter((collection) => {
|
|
154
160
|
const quantity = totalSelectedByCollection[collection.collectionId] || 0;
|
|
@@ -170,14 +176,17 @@ class BundleSelectionValidator {
|
|
|
170
176
|
}
|
|
171
177
|
return acc;
|
|
172
178
|
},
|
|
173
|
-
|
|
179
|
+
/* @__PURE__ */ Object.create(null)
|
|
174
180
|
);
|
|
175
181
|
if (!Object.values(variantCollections).length) {
|
|
176
182
|
throw `No collections found for the bundle variant (${externalVariantId}).`;
|
|
177
183
|
}
|
|
178
|
-
const missingProducts = __privateGet(this, _items).filter(
|
|
179
|
-
(
|
|
180
|
-
|
|
184
|
+
const missingProducts = __privateGet(this, _items).filter(({ externalProductId, collectionId }) => {
|
|
185
|
+
if (!__privateMethod(this, _hasOwn, hasOwn_fn).call(this, variantCollections, collectionId)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
return !__privateMethod(this, _hasOwn, hasOwn_fn).call(this, variantCollections[collectionId].products, externalProductId);
|
|
189
|
+
});
|
|
181
190
|
if (missingProducts.length) {
|
|
182
191
|
const invalidIds = __privateMethod(this, _unique, unique_fn).call(this, missingProducts.map(({ externalProductId }) => externalProductId)).join(", ");
|
|
183
192
|
throw `The products (${invalidIds}) are no longer valid for the bundle product.`;
|
|
@@ -207,6 +216,7 @@ formatBundleSettings_fn = function(bundleData) {
|
|
|
207
216
|
maxPerItem: bundleSettings.max_quantity_per_variant,
|
|
208
217
|
isCustomizable: bundleSettings.is_customizable
|
|
209
218
|
},
|
|
219
|
+
// null-proto seeds so external variant/option-source ids become real own keys, not prototype pollution
|
|
210
220
|
variantsSettings: bundleSettings.variants.reduce((acc, variant) => {
|
|
211
221
|
if (!variant.enabled)
|
|
212
222
|
return acc;
|
|
@@ -226,11 +236,11 @@ formatBundleSettings_fn = function(bundleData) {
|
|
|
226
236
|
collectionId: optionSource.option_source_id
|
|
227
237
|
};
|
|
228
238
|
return acc2;
|
|
229
|
-
},
|
|
239
|
+
}, /* @__PURE__ */ Object.create(null)),
|
|
230
240
|
ranges
|
|
231
241
|
};
|
|
232
242
|
return acc;
|
|
233
|
-
},
|
|
243
|
+
}, /* @__PURE__ */ Object.create(null))
|
|
234
244
|
};
|
|
235
245
|
} catch (error) {
|
|
236
246
|
return null;
|
|
@@ -245,10 +255,10 @@ formatBundleData_fn = function(bundleData) {
|
|
|
245
255
|
products: current.products.reduce((productAcc, product) => {
|
|
246
256
|
productAcc[product.id] = product;
|
|
247
257
|
return productAcc;
|
|
248
|
-
},
|
|
258
|
+
}, /* @__PURE__ */ Object.create(null))
|
|
249
259
|
};
|
|
250
260
|
return acc;
|
|
251
|
-
},
|
|
261
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
252
262
|
return { ...bundleData, collections };
|
|
253
263
|
} catch (error) {
|
|
254
264
|
return null;
|
|
@@ -267,6 +277,10 @@ _unique = new WeakSet();
|
|
|
267
277
|
unique_fn = function(ids) {
|
|
268
278
|
return Array.from(new Set(ids));
|
|
269
279
|
};
|
|
280
|
+
_hasOwn = new WeakSet();
|
|
281
|
+
hasOwn_fn = function(target, key) {
|
|
282
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
283
|
+
};
|
|
270
284
|
|
|
271
285
|
exports.BundleSelectionValidator = BundleSelectionValidator;
|
|
272
286
|
exports.toLineItemProperty = toLineItemProperty;
|