@rechargeapps/storefront-client 0.28.0 → 0.29.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/subscription.js +50 -0
- package/dist/cjs/api/subscription.js.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mappers/subscription.js +141 -0
- package/dist/cjs/mappers/subscription.js.map +1 -0
- package/dist/cjs/mappers/utils.js +7 -0
- package/dist/cjs/mappers/utils.js.map +1 -1
- package/dist/esm/api/subscription.js +45 -1
- package/dist/esm/api/subscription.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/mappers/subscription.js +131 -0
- package/dist/esm/mappers/subscription.js.map +1 -0
- package/dist/esm/mappers/utils.js +7 -1
- package/dist/esm/mappers/utils.js.map +1 -1
- package/dist/index.d.ts +68 -1
- package/dist/umd/recharge-client.min.js +12 -10
- package/package.json +1 -1
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var partial = require('lodash/partial');
|
|
5
6
|
var request = require('../utils/request.js');
|
|
7
|
+
var subscription = require('../mappers/subscription.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var partial__default = /*#__PURE__*/_interopDefaultLegacy(partial);
|
|
6
12
|
|
|
7
13
|
async function getSubscription(session, id, options) {
|
|
8
14
|
const { subscription } = await request.rechargeApiRequest("get", `/subscriptions`, {
|
|
@@ -62,14 +68,58 @@ async function skipSubscriptionCharge(session, id, date) {
|
|
|
62
68
|
}, session);
|
|
63
69
|
return charge;
|
|
64
70
|
}
|
|
71
|
+
async function createSubscriptions(session, createRequestBulk) {
|
|
72
|
+
const length = createRequestBulk.length;
|
|
73
|
+
if (length < 1 || length > 21) {
|
|
74
|
+
throw new Error("Number of subscriptions must be between 1 and 20.");
|
|
75
|
+
}
|
|
76
|
+
const { customerId } = session;
|
|
77
|
+
if (!customerId) {
|
|
78
|
+
throw new Error("No customerId in session.");
|
|
79
|
+
}
|
|
80
|
+
const addressId = createRequestBulk[0].address_id;
|
|
81
|
+
if (!createRequestBulk.every((createRequest) => createRequest.address_id === addressId)) {
|
|
82
|
+
throw new Error("All subscriptions must have the same address_id.");
|
|
83
|
+
}
|
|
84
|
+
const bulkSubscriptionMapperPartial = partial__default["default"](subscription.bulkSubscriptionCreateMapper, customerId);
|
|
85
|
+
const requestData = createRequestBulk.map(bulkSubscriptionMapperPartial);
|
|
86
|
+
const { subscriptions } = await request.rechargeApiRequest("post", `/addresses/${addressId}/subscriptions-bulk`, {
|
|
87
|
+
data: { subscriptions: requestData },
|
|
88
|
+
headers: {
|
|
89
|
+
"X-Recharge-Version": "2021-01"
|
|
90
|
+
}
|
|
91
|
+
}, session);
|
|
92
|
+
return subscriptions.map(subscription.subscriptionMapperOldToNew);
|
|
93
|
+
}
|
|
94
|
+
async function updateSubscriptions(session, addressId, updateRequestBulk, query) {
|
|
95
|
+
const length = updateRequestBulk.length;
|
|
96
|
+
if (length < 1 || length > 21) {
|
|
97
|
+
throw new Error("Number of subscriptions must be between 1 and 20.");
|
|
98
|
+
}
|
|
99
|
+
const { customerId } = session;
|
|
100
|
+
if (!customerId) {
|
|
101
|
+
throw new Error("No customerId in session.");
|
|
102
|
+
}
|
|
103
|
+
const bulkSubscriptionMapperPartial = partial__default["default"](subscription.bulkSubscriptionUpdateMapper, !!(query == null ? void 0 : query.force_update));
|
|
104
|
+
const requestData = updateRequestBulk.map(bulkSubscriptionMapperPartial);
|
|
105
|
+
const { subscriptions } = await request.rechargeApiRequest("put", `/addresses/${addressId}/subscriptions-bulk`, {
|
|
106
|
+
data: { subscriptions: requestData },
|
|
107
|
+
headers: {
|
|
108
|
+
"X-Recharge-Version": "2021-01"
|
|
109
|
+
}
|
|
110
|
+
}, session);
|
|
111
|
+
return subscriptions.map(subscription.subscriptionMapperOldToNew);
|
|
112
|
+
}
|
|
65
113
|
|
|
66
114
|
exports.activateSubscription = activateSubscription;
|
|
67
115
|
exports.cancelSubscription = cancelSubscription;
|
|
68
116
|
exports.createSubscription = createSubscription;
|
|
117
|
+
exports.createSubscriptions = createSubscriptions;
|
|
69
118
|
exports.getSubscription = getSubscription;
|
|
70
119
|
exports.listSubscriptions = listSubscriptions;
|
|
71
120
|
exports.skipSubscriptionCharge = skipSubscriptionCharge;
|
|
72
121
|
exports.updateSubscription = updateSubscription;
|
|
73
122
|
exports.updateSubscriptionAddress = updateSubscriptionAddress;
|
|
74
123
|
exports.updateSubscriptionChargeDate = updateSubscriptionChargeDate;
|
|
124
|
+
exports.updateSubscriptions = updateSubscriptions;
|
|
75
125
|
//# sourceMappingURL=subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import { rechargeApiRequest } from '../utils/request';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n BasicSubscriptionParams,\n} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } from '../types';\n\nexport async function getSubscription(\n session: Session,\n id: string | number,\n options?: GetSubscriptionOptions\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query }, session);\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 session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n session\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?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/change_address`,\n {\n data: { address_id },\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n { query },\n session\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 const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${id}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n session\n );\n return charge;\n}\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;AAClE,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,SAAS,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE;AAClD,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO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,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE;AAC5E,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;AAC3F,IAAI,IAAI,EAAE,aAAa;AACvB,IAAI,KAAK;AACT,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,oBAAoB,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE;AAC/D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACjH,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,sBAAsB,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE;AAChE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE;AAC3F,IAAI,IAAI,EAAE;AACV,MAAM,IAAI;AACV,MAAM,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9B,KAAK;AACL,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import partial from 'lodash/partial';\nimport { 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} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } 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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query }, session);\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 session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n session\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?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/change_address`,\n {\n data: { address_id },\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n { query },\n session\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 const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${id}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n session\n );\n return charge;\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: CreateSubscriptionRequest[]\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 const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'post',\n `/addresses/${addressId}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n return subscriptions.map(subscriptionMapperOldToNew);\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 * 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 // 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 const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'put',\n `/addresses/${addressId}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n"],"names":["rechargeApiRequest","partial","bulkSubscriptionCreateMapper","subscriptionMapperOldToNew","bulkSubscriptionUpdateMapper"],"mappings":";;;;;;;;;;;;AAOO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;AAClE,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,SAAS,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE;AAClD,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE;AACxE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE;AAC9E,IAAI,IAAI,EAAE,aAAa;AACvB,IAAI,KAAK;AACT,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE;AAC5E,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,IAAI,EAAE,aAAa;AACvB,IAAI,KAAK;AACT,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAA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SAAS;AACrC,KAAK;AACL,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,aAAa,CAAC,GAAG,CAACG,uCAA0B,CAAC,CAAC;AACvD;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -80,12 +80,14 @@ exports.listPlans = plan.listPlans;
|
|
|
80
80
|
exports.activateSubscription = subscription.activateSubscription;
|
|
81
81
|
exports.cancelSubscription = subscription.cancelSubscription;
|
|
82
82
|
exports.createSubscription = subscription.createSubscription;
|
|
83
|
+
exports.createSubscriptions = subscription.createSubscriptions;
|
|
83
84
|
exports.getSubscription = subscription.getSubscription;
|
|
84
85
|
exports.listSubscriptions = subscription.listSubscriptions;
|
|
85
86
|
exports.skipSubscriptionCharge = subscription.skipSubscriptionCharge;
|
|
86
87
|
exports.updateSubscription = subscription.updateSubscription;
|
|
87
88
|
exports.updateSubscriptionAddress = subscription.updateSubscriptionAddress;
|
|
88
89
|
exports.updateSubscriptionChargeDate = subscription.updateSubscriptionChargeDate;
|
|
90
|
+
exports.updateSubscriptions = subscription.updateSubscriptions;
|
|
89
91
|
exports.getCustomer = customer.getCustomer;
|
|
90
92
|
exports.getCustomerPortalAccess = customer.getCustomerPortalAccess;
|
|
91
93
|
exports.getDeliverySchedule = customer.getDeliverySchedule;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var omit = require('lodash/omit');
|
|
6
|
+
var utils = require('./utils.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defProps = Object.defineProperties;
|
|
14
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
15
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
19
|
+
var __spreadValues = (a, b) => {
|
|
20
|
+
for (var prop in b || (b = {}))
|
|
21
|
+
if (__hasOwnProp.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
if (__getOwnPropSymbols)
|
|
24
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
25
|
+
if (__propIsEnum.call(b, prop))
|
|
26
|
+
__defNormalProp(a, prop, b[prop]);
|
|
27
|
+
}
|
|
28
|
+
return a;
|
|
29
|
+
};
|
|
30
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
31
|
+
function bulkSubscriptionCreateMapper(customer_id, createRequest) {
|
|
32
|
+
return __spreadProps(__spreadValues({}, omit__default["default"](createRequest, [
|
|
33
|
+
"address_id",
|
|
34
|
+
"external_variant_id",
|
|
35
|
+
"external_product_id",
|
|
36
|
+
"charge_interval_frequency",
|
|
37
|
+
"order_interval_frequency",
|
|
38
|
+
"price",
|
|
39
|
+
"status"
|
|
40
|
+
])), {
|
|
41
|
+
customer_id: parseInt(customer_id, 10),
|
|
42
|
+
shopify_variant_id: createRequest.external_variant_id.ecommerce ? parseInt(createRequest.external_variant_id.ecommerce, 10) : void 0,
|
|
43
|
+
charge_interval_frequency: `${createRequest.charge_interval_frequency}`,
|
|
44
|
+
order_interval_frequency: `${createRequest.order_interval_frequency}`,
|
|
45
|
+
price: createRequest.price ? parseFloat(createRequest.price) : void 0,
|
|
46
|
+
status: createRequest.status ? createRequest.status.toUpperCase() : void 0
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function bulkSubscriptionUpdateMapper(force_update, updateRequest) {
|
|
50
|
+
var _a;
|
|
51
|
+
return __spreadProps(__spreadValues({}, omit__default["default"](updateRequest, [
|
|
52
|
+
"external_variant_id",
|
|
53
|
+
"external_product_id",
|
|
54
|
+
"charge_interval_frequency",
|
|
55
|
+
"order_interval_frequency",
|
|
56
|
+
"price",
|
|
57
|
+
"use_external_variant_defaults"
|
|
58
|
+
])), {
|
|
59
|
+
shopify_variant_id: ((_a = updateRequest.external_variant_id) == null ? void 0 : _a.ecommerce) ? parseInt(updateRequest.external_variant_id.ecommerce, 10) : void 0,
|
|
60
|
+
charge_interval_frequency: updateRequest.charge_interval_frequency ? `${updateRequest.charge_interval_frequency}` : void 0,
|
|
61
|
+
order_interval_frequency: updateRequest.order_interval_frequency ? `${updateRequest.order_interval_frequency}` : void 0,
|
|
62
|
+
price: updateRequest.price ? parseFloat(updateRequest.price) : void 0,
|
|
63
|
+
use_shopify_variant_defaults: updateRequest.use_external_variant_defaults,
|
|
64
|
+
force_update
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function subscriptionMapperOldToNew(old) {
|
|
68
|
+
const {
|
|
69
|
+
id,
|
|
70
|
+
address_id,
|
|
71
|
+
customer_id,
|
|
72
|
+
analytics_data,
|
|
73
|
+
cancellation_reason,
|
|
74
|
+
cancellation_reason_comments,
|
|
75
|
+
cancelled_at,
|
|
76
|
+
charge_interval_frequency,
|
|
77
|
+
created_at,
|
|
78
|
+
expire_after_specific_number_of_charges,
|
|
79
|
+
shopify_product_id,
|
|
80
|
+
shopify_variant_id,
|
|
81
|
+
has_queued_charges,
|
|
82
|
+
is_prepaid,
|
|
83
|
+
is_skippable,
|
|
84
|
+
is_swappable,
|
|
85
|
+
max_retries_reached,
|
|
86
|
+
next_charge_scheduled_at,
|
|
87
|
+
order_day_of_month,
|
|
88
|
+
order_day_of_week,
|
|
89
|
+
order_interval_frequency,
|
|
90
|
+
order_interval_unit,
|
|
91
|
+
presentment_currency,
|
|
92
|
+
price,
|
|
93
|
+
product_title,
|
|
94
|
+
properties,
|
|
95
|
+
quantity,
|
|
96
|
+
sku,
|
|
97
|
+
sku_override,
|
|
98
|
+
status,
|
|
99
|
+
updated_at,
|
|
100
|
+
variant_title
|
|
101
|
+
} = old;
|
|
102
|
+
return {
|
|
103
|
+
id,
|
|
104
|
+
address_id,
|
|
105
|
+
customer_id,
|
|
106
|
+
analytics_data,
|
|
107
|
+
cancellation_reason,
|
|
108
|
+
cancellation_reason_comments,
|
|
109
|
+
cancelled_at,
|
|
110
|
+
charge_interval_frequency: parseInt(charge_interval_frequency, 10),
|
|
111
|
+
created_at,
|
|
112
|
+
expire_after_specific_number_of_charges,
|
|
113
|
+
external_product_id: { ecommerce: `${shopify_product_id}` },
|
|
114
|
+
external_variant_id: { ecommerce: `${shopify_variant_id}` },
|
|
115
|
+
has_queued_charges: utils.convertToBool(has_queued_charges),
|
|
116
|
+
is_prepaid,
|
|
117
|
+
is_skippable,
|
|
118
|
+
is_swappable,
|
|
119
|
+
max_retries_reached: utils.convertToBool(max_retries_reached),
|
|
120
|
+
next_charge_scheduled_at,
|
|
121
|
+
order_day_of_month,
|
|
122
|
+
order_day_of_week,
|
|
123
|
+
order_interval_frequency: parseInt(order_interval_frequency, 10),
|
|
124
|
+
order_interval_unit,
|
|
125
|
+
presentment_currency,
|
|
126
|
+
price: `${price}`,
|
|
127
|
+
product_title: product_title != null ? product_title : "",
|
|
128
|
+
properties,
|
|
129
|
+
quantity,
|
|
130
|
+
sku,
|
|
131
|
+
sku_override,
|
|
132
|
+
status: status.toLowerCase(),
|
|
133
|
+
updated_at,
|
|
134
|
+
variant_title
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.bulkSubscriptionCreateMapper = bulkSubscriptionCreateMapper;
|
|
139
|
+
exports.bulkSubscriptionUpdateMapper = bulkSubscriptionUpdateMapper;
|
|
140
|
+
exports.subscriptionMapperOldToNew = subscriptionMapperOldToNew;
|
|
141
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sources":["../../../src/mappers/subscription.ts"],"sourcesContent":["import omit from 'lodash/omit';\nimport {\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionStatus,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n} from '../types';\nimport { convertToBool } from './utils';\n\nexport function bulkSubscriptionCreateMapper(customer_id: string, createRequest: CreateSubscriptionRequest) {\n return {\n ...omit(createRequest, [\n 'address_id',\n 'external_variant_id',\n 'external_product_id',\n 'charge_interval_frequency',\n 'order_interval_frequency',\n 'price',\n 'status',\n ]),\n customer_id: parseInt(customer_id, 10),\n shopify_variant_id: createRequest.external_variant_id.ecommerce\n ? parseInt(createRequest.external_variant_id.ecommerce, 10)\n : undefined,\n charge_interval_frequency: `${createRequest.charge_interval_frequency}`,\n order_interval_frequency: `${createRequest.order_interval_frequency}`,\n price: createRequest.price ? parseFloat(createRequest.price) : undefined,\n status: createRequest.status ? createRequest.status.toUpperCase() : undefined,\n };\n}\n\nexport function bulkSubscriptionUpdateMapper(force_update: boolean, updateRequest: UpdateSubscriptionsRequest) {\n return {\n ...omit(updateRequest, [\n 'external_variant_id',\n 'external_product_id',\n 'charge_interval_frequency',\n 'order_interval_frequency',\n 'price',\n 'use_external_variant_defaults',\n ]),\n shopify_variant_id: updateRequest.external_variant_id?.ecommerce\n ? parseInt(updateRequest.external_variant_id.ecommerce, 10)\n : undefined,\n charge_interval_frequency: updateRequest.charge_interval_frequency\n ? `${updateRequest.charge_interval_frequency}`\n : undefined,\n order_interval_frequency: updateRequest.order_interval_frequency\n ? `${updateRequest.order_interval_frequency}`\n : undefined,\n price: updateRequest.price ? parseFloat(updateRequest.price) : undefined,\n use_shopify_variant_defaults: updateRequest.use_external_variant_defaults,\n force_update,\n };\n}\n\nexport function subscriptionMapperOldToNew(old: Subscription_2021_01): Subscription {\n const {\n id,\n address_id,\n customer_id,\n analytics_data,\n cancellation_reason,\n cancellation_reason_comments,\n cancelled_at,\n charge_interval_frequency,\n created_at,\n expire_after_specific_number_of_charges,\n shopify_product_id,\n shopify_variant_id,\n has_queued_charges,\n is_prepaid,\n is_skippable,\n is_swappable,\n max_retries_reached,\n next_charge_scheduled_at,\n order_day_of_month,\n order_day_of_week,\n order_interval_frequency,\n order_interval_unit,\n presentment_currency,\n price,\n product_title,\n properties,\n quantity,\n sku,\n sku_override,\n status,\n updated_at,\n variant_title,\n } = old;\n return {\n id,\n address_id,\n customer_id,\n analytics_data,\n cancellation_reason,\n cancellation_reason_comments,\n cancelled_at,\n charge_interval_frequency: parseInt(charge_interval_frequency, 10),\n created_at,\n expire_after_specific_number_of_charges,\n external_product_id: { ecommerce: `${shopify_product_id}` },\n external_variant_id: { ecommerce: `${shopify_variant_id}` },\n has_queued_charges: convertToBool(has_queued_charges),\n is_prepaid,\n is_skippable,\n is_swappable,\n max_retries_reached: convertToBool(max_retries_reached),\n next_charge_scheduled_at,\n order_day_of_month,\n order_day_of_week,\n order_interval_frequency: parseInt(order_interval_frequency, 10),\n order_interval_unit,\n presentment_currency,\n price: `${price}`,\n product_title: product_title ?? '',\n properties,\n quantity,\n sku,\n sku_override,\n status: status.toLowerCase() as SubscriptionStatus,\n updated_at,\n variant_title,\n };\n}\n"],"names":["omit","convertToBool"],"mappings":";;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAA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
+
const convertToBool = (val) => {
|
|
37
|
+
if (typeof val === "string") {
|
|
38
|
+
return val !== "0" && val !== "false";
|
|
39
|
+
}
|
|
40
|
+
return !!val;
|
|
41
|
+
};
|
|
36
42
|
|
|
43
|
+
exports.convertToBool = convertToBool;
|
|
37
44
|
exports.parseValues = parseValues;
|
|
38
45
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/mappers/utils.ts"],"sourcesContent":["/** Trys to parse passed in value. If it doesn't work returns the same passed in value */\nfunction parseValue(value: unknown): any {\n try {\n return JSON.parse(value as string);\n } catch {\n return value;\n }\n}\n\n/** Returns a new object that updates \"string\" values into their correct data type. */\nexport function parseValues<T = any>(json: Record<string, unknown>): T {\n return Object.entries(json).reduce((memo, [key, value]) => {\n return { ...memo, [key]: parseValue(value) };\n }, {}) as T;\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;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mappers/utils.ts"],"sourcesContent":["import { BooleanLike } from '../types';\n\n/** Trys to parse passed in value. If it doesn't work returns the same passed in value */\nfunction parseValue(value: unknown): any {\n try {\n return JSON.parse(value as string);\n } catch {\n return value;\n }\n}\n\n/** Returns a new object that updates \"string\" values into their correct data type. */\nexport function parseValues<T = any>(json: Record<string, unknown>): T {\n return Object.entries(json).reduce((memo, [key, value]) => {\n return { ...memo, [key]: parseValue(value) };\n }, {}) as T;\n}\n\nexport const convertToBool = (val: BooleanLike) => {\n if (typeof val === 'string') {\n return val !== '0' && val !== 'false';\n }\n\n return !!val;\n};\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAA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;"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import partial from 'lodash/partial';
|
|
1
2
|
import { rechargeApiRequest } from '../utils/request.js';
|
|
3
|
+
import { bulkSubscriptionCreateMapper, subscriptionMapperOldToNew, bulkSubscriptionUpdateMapper } from '../mappers/subscription.js';
|
|
2
4
|
|
|
3
5
|
async function getSubscription(session, id, options) {
|
|
4
6
|
const { subscription } = await rechargeApiRequest("get", `/subscriptions`, {
|
|
@@ -58,6 +60,48 @@ async function skipSubscriptionCharge(session, id, date) {
|
|
|
58
60
|
}, session);
|
|
59
61
|
return charge;
|
|
60
62
|
}
|
|
63
|
+
async function createSubscriptions(session, createRequestBulk) {
|
|
64
|
+
const length = createRequestBulk.length;
|
|
65
|
+
if (length < 1 || length > 21) {
|
|
66
|
+
throw new Error("Number of subscriptions must be between 1 and 20.");
|
|
67
|
+
}
|
|
68
|
+
const { customerId } = session;
|
|
69
|
+
if (!customerId) {
|
|
70
|
+
throw new Error("No customerId in session.");
|
|
71
|
+
}
|
|
72
|
+
const addressId = createRequestBulk[0].address_id;
|
|
73
|
+
if (!createRequestBulk.every((createRequest) => createRequest.address_id === addressId)) {
|
|
74
|
+
throw new Error("All subscriptions must have the same address_id.");
|
|
75
|
+
}
|
|
76
|
+
const bulkSubscriptionMapperPartial = partial(bulkSubscriptionCreateMapper, customerId);
|
|
77
|
+
const requestData = createRequestBulk.map(bulkSubscriptionMapperPartial);
|
|
78
|
+
const { subscriptions } = await rechargeApiRequest("post", `/addresses/${addressId}/subscriptions-bulk`, {
|
|
79
|
+
data: { subscriptions: requestData },
|
|
80
|
+
headers: {
|
|
81
|
+
"X-Recharge-Version": "2021-01"
|
|
82
|
+
}
|
|
83
|
+
}, session);
|
|
84
|
+
return subscriptions.map(subscriptionMapperOldToNew);
|
|
85
|
+
}
|
|
86
|
+
async function updateSubscriptions(session, addressId, updateRequestBulk, query) {
|
|
87
|
+
const length = updateRequestBulk.length;
|
|
88
|
+
if (length < 1 || length > 21) {
|
|
89
|
+
throw new Error("Number of subscriptions must be between 1 and 20.");
|
|
90
|
+
}
|
|
91
|
+
const { customerId } = session;
|
|
92
|
+
if (!customerId) {
|
|
93
|
+
throw new Error("No customerId in session.");
|
|
94
|
+
}
|
|
95
|
+
const bulkSubscriptionMapperPartial = partial(bulkSubscriptionUpdateMapper, !!(query == null ? void 0 : query.force_update));
|
|
96
|
+
const requestData = updateRequestBulk.map(bulkSubscriptionMapperPartial);
|
|
97
|
+
const { subscriptions } = await rechargeApiRequest("put", `/addresses/${addressId}/subscriptions-bulk`, {
|
|
98
|
+
data: { subscriptions: requestData },
|
|
99
|
+
headers: {
|
|
100
|
+
"X-Recharge-Version": "2021-01"
|
|
101
|
+
}
|
|
102
|
+
}, session);
|
|
103
|
+
return subscriptions.map(subscriptionMapperOldToNew);
|
|
104
|
+
}
|
|
61
105
|
|
|
62
|
-
export { activateSubscription, cancelSubscription, createSubscription, getSubscription, listSubscriptions, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate };
|
|
106
|
+
export { activateSubscription, cancelSubscription, createSubscription, createSubscriptions, getSubscription, listSubscriptions, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate, updateSubscriptions };
|
|
63
107
|
//# sourceMappingURL=subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import { rechargeApiRequest } from '../utils/request';\nimport {\n CancelSubscriptionRequest,\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionsResponse,\n SubscriptionListParams,\n UpdateSubscriptionRequest,\n UpdateSubscriptionParams,\n GetSubscriptionOptions,\n BasicSubscriptionParams,\n} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } from '../types';\n\nexport async function getSubscription(\n session: Session,\n id: string | number,\n options?: GetSubscriptionOptions\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query }, session);\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 session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n session\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?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/change_address`,\n {\n data: { address_id },\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n { query },\n session\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 const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${id}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n session\n );\n return charge;\n}\n"],"names":[],"mappings":";;AACO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;AAClE,GAAG,EAAE,OAAO,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../src/api/subscription.ts"],"sourcesContent":["import partial from 'lodash/partial';\nimport { 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} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } 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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return subscription;\n}\n\nexport function listSubscriptions(session: Session, query?: SubscriptionListParams): Promise<SubscriptionsResponse> {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query }, session);\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 session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'put',\n `/subscriptions`,\n {\n id,\n data: updateRequest,\n query,\n },\n session\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?: BasicSubscriptionParams\n): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/change_address`,\n {\n data: { address_id },\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\n query,\n },\n session\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 const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n { query },\n session\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 const { charge } = await rechargeApiRequest<ChargeResponse>(\n 'post',\n `/subscriptions/${id}/charges/skip`,\n {\n data: {\n date,\n subscription_id: `${id}`,\n },\n },\n session\n );\n return charge;\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: CreateSubscriptionRequest[]\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 const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'post',\n `/addresses/${addressId}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n return subscriptions.map(subscriptionMapperOldToNew);\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 * 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 // 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 const { subscriptions } = await rechargeApiRequest<{ subscriptions: Subscription_2021_01[] }>(\n 'put',\n `/addresses/${addressId}/subscriptions-bulk`,\n {\n data: { subscriptions: requestData },\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n return subscriptions.map(subscriptionMapperOldToNew);\n}\n"],"names":[],"mappings":";;;;AAOO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AAC5D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;AAClE,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,SAAS,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE;AAClD,EAAE,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE;AACxE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE;AAC9E,IAAI,IAAI,EAAE,aAAa;AACvB,IAAI,KAAK;AACT,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE;AAC5E,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,C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AAS,CAAC,mBAAmB,CAAC,EAAE;AAC1G,IAAI,IAAI,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE;AACxC,IAAI,OAAO,EAAE;AACb,MAAM,oBAAoB,EAAE,SAAS;AACrC,KAAK;AACL,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,aAAa,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACvD;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { createOnetime, deleteOnetime, getOnetime, listOnetimes, updateOnetime }
|
|
|
9
9
|
export { getOrder, listOrders } from './api/order.js';
|
|
10
10
|
export { getPaymentMethod, listPaymentMethods, updatePaymentMethod } from './api/paymentMethod.js';
|
|
11
11
|
export { getPlan, listPlans } from './api/plan.js';
|
|
12
|
-
export { activateSubscription, cancelSubscription, createSubscription, getSubscription, listSubscriptions, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate } from './api/subscription.js';
|
|
12
|
+
export { activateSubscription, cancelSubscription, createSubscription, createSubscriptions, getSubscription, listSubscriptions, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate, updateSubscriptions } from './api/subscription.js';
|
|
13
13
|
export { getCustomer, getCustomerPortalAccess, getDeliverySchedule, updateCustomer } from './api/customer.js';
|
|
14
14
|
export { api, initRecharge } from './utils/init.js';
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import omit from 'lodash/omit';
|
|
2
|
+
import { convertToBool } from './utils.js';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
function bulkSubscriptionCreateMapper(customer_id, createRequest) {
|
|
24
|
+
return __spreadProps(__spreadValues({}, omit(createRequest, [
|
|
25
|
+
"address_id",
|
|
26
|
+
"external_variant_id",
|
|
27
|
+
"external_product_id",
|
|
28
|
+
"charge_interval_frequency",
|
|
29
|
+
"order_interval_frequency",
|
|
30
|
+
"price",
|
|
31
|
+
"status"
|
|
32
|
+
])), {
|
|
33
|
+
customer_id: parseInt(customer_id, 10),
|
|
34
|
+
shopify_variant_id: createRequest.external_variant_id.ecommerce ? parseInt(createRequest.external_variant_id.ecommerce, 10) : void 0,
|
|
35
|
+
charge_interval_frequency: `${createRequest.charge_interval_frequency}`,
|
|
36
|
+
order_interval_frequency: `${createRequest.order_interval_frequency}`,
|
|
37
|
+
price: createRequest.price ? parseFloat(createRequest.price) : void 0,
|
|
38
|
+
status: createRequest.status ? createRequest.status.toUpperCase() : void 0
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function bulkSubscriptionUpdateMapper(force_update, updateRequest) {
|
|
42
|
+
var _a;
|
|
43
|
+
return __spreadProps(__spreadValues({}, omit(updateRequest, [
|
|
44
|
+
"external_variant_id",
|
|
45
|
+
"external_product_id",
|
|
46
|
+
"charge_interval_frequency",
|
|
47
|
+
"order_interval_frequency",
|
|
48
|
+
"price",
|
|
49
|
+
"use_external_variant_defaults"
|
|
50
|
+
])), {
|
|
51
|
+
shopify_variant_id: ((_a = updateRequest.external_variant_id) == null ? void 0 : _a.ecommerce) ? parseInt(updateRequest.external_variant_id.ecommerce, 10) : void 0,
|
|
52
|
+
charge_interval_frequency: updateRequest.charge_interval_frequency ? `${updateRequest.charge_interval_frequency}` : void 0,
|
|
53
|
+
order_interval_frequency: updateRequest.order_interval_frequency ? `${updateRequest.order_interval_frequency}` : void 0,
|
|
54
|
+
price: updateRequest.price ? parseFloat(updateRequest.price) : void 0,
|
|
55
|
+
use_shopify_variant_defaults: updateRequest.use_external_variant_defaults,
|
|
56
|
+
force_update
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function subscriptionMapperOldToNew(old) {
|
|
60
|
+
const {
|
|
61
|
+
id,
|
|
62
|
+
address_id,
|
|
63
|
+
customer_id,
|
|
64
|
+
analytics_data,
|
|
65
|
+
cancellation_reason,
|
|
66
|
+
cancellation_reason_comments,
|
|
67
|
+
cancelled_at,
|
|
68
|
+
charge_interval_frequency,
|
|
69
|
+
created_at,
|
|
70
|
+
expire_after_specific_number_of_charges,
|
|
71
|
+
shopify_product_id,
|
|
72
|
+
shopify_variant_id,
|
|
73
|
+
has_queued_charges,
|
|
74
|
+
is_prepaid,
|
|
75
|
+
is_skippable,
|
|
76
|
+
is_swappable,
|
|
77
|
+
max_retries_reached,
|
|
78
|
+
next_charge_scheduled_at,
|
|
79
|
+
order_day_of_month,
|
|
80
|
+
order_day_of_week,
|
|
81
|
+
order_interval_frequency,
|
|
82
|
+
order_interval_unit,
|
|
83
|
+
presentment_currency,
|
|
84
|
+
price,
|
|
85
|
+
product_title,
|
|
86
|
+
properties,
|
|
87
|
+
quantity,
|
|
88
|
+
sku,
|
|
89
|
+
sku_override,
|
|
90
|
+
status,
|
|
91
|
+
updated_at,
|
|
92
|
+
variant_title
|
|
93
|
+
} = old;
|
|
94
|
+
return {
|
|
95
|
+
id,
|
|
96
|
+
address_id,
|
|
97
|
+
customer_id,
|
|
98
|
+
analytics_data,
|
|
99
|
+
cancellation_reason,
|
|
100
|
+
cancellation_reason_comments,
|
|
101
|
+
cancelled_at,
|
|
102
|
+
charge_interval_frequency: parseInt(charge_interval_frequency, 10),
|
|
103
|
+
created_at,
|
|
104
|
+
expire_after_specific_number_of_charges,
|
|
105
|
+
external_product_id: { ecommerce: `${shopify_product_id}` },
|
|
106
|
+
external_variant_id: { ecommerce: `${shopify_variant_id}` },
|
|
107
|
+
has_queued_charges: convertToBool(has_queued_charges),
|
|
108
|
+
is_prepaid,
|
|
109
|
+
is_skippable,
|
|
110
|
+
is_swappable,
|
|
111
|
+
max_retries_reached: convertToBool(max_retries_reached),
|
|
112
|
+
next_charge_scheduled_at,
|
|
113
|
+
order_day_of_month,
|
|
114
|
+
order_day_of_week,
|
|
115
|
+
order_interval_frequency: parseInt(order_interval_frequency, 10),
|
|
116
|
+
order_interval_unit,
|
|
117
|
+
presentment_currency,
|
|
118
|
+
price: `${price}`,
|
|
119
|
+
product_title: product_title != null ? product_title : "",
|
|
120
|
+
properties,
|
|
121
|
+
quantity,
|
|
122
|
+
sku,
|
|
123
|
+
sku_override,
|
|
124
|
+
status: status.toLowerCase(),
|
|
125
|
+
updated_at,
|
|
126
|
+
variant_title
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { bulkSubscriptionCreateMapper, bulkSubscriptionUpdateMapper, subscriptionMapperOldToNew };
|
|
131
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sources":["../../../src/mappers/subscription.ts"],"sourcesContent":["import omit from 'lodash/omit';\nimport {\n CreateSubscriptionRequest,\n Subscription,\n SubscriptionStatus,\n Subscription_2021_01,\n UpdateSubscriptionsRequest,\n} from '../types';\nimport { convertToBool } from './utils';\n\nexport function bulkSubscriptionCreateMapper(customer_id: string, createRequest: CreateSubscriptionRequest) {\n return {\n ...omit(createRequest, [\n 'address_id',\n 'external_variant_id',\n 'external_product_id',\n 'charge_interval_frequency',\n 'order_interval_frequency',\n 'price',\n 'status',\n ]),\n customer_id: parseInt(customer_id, 10),\n shopify_variant_id: createRequest.external_variant_id.ecommerce\n ? parseInt(createRequest.external_variant_id.ecommerce, 10)\n : undefined,\n charge_interval_frequency: `${createRequest.charge_interval_frequency}`,\n order_interval_frequency: `${createRequest.order_interval_frequency}`,\n price: createRequest.price ? parseFloat(createRequest.price) : undefined,\n status: createRequest.status ? createRequest.status.toUpperCase() : undefined,\n };\n}\n\nexport function bulkSubscriptionUpdateMapper(force_update: boolean, updateRequest: UpdateSubscriptionsRequest) {\n return {\n ...omit(updateRequest, [\n 'external_variant_id',\n 'external_product_id',\n 'charge_interval_frequency',\n 'order_interval_frequency',\n 'price',\n 'use_external_variant_defaults',\n ]),\n shopify_variant_id: updateRequest.external_variant_id?.ecommerce\n ? parseInt(updateRequest.external_variant_id.ecommerce, 10)\n : undefined,\n charge_interval_frequency: updateRequest.charge_interval_frequency\n ? `${updateRequest.charge_interval_frequency}`\n : undefined,\n order_interval_frequency: updateRequest.order_interval_frequency\n ? `${updateRequest.order_interval_frequency}`\n : undefined,\n price: updateRequest.price ? parseFloat(updateRequest.price) : undefined,\n use_shopify_variant_defaults: updateRequest.use_external_variant_defaults,\n force_update,\n };\n}\n\nexport function subscriptionMapperOldToNew(old: Subscription_2021_01): Subscription {\n const {\n id,\n address_id,\n customer_id,\n analytics_data,\n cancellation_reason,\n cancellation_reason_comments,\n cancelled_at,\n charge_interval_frequency,\n created_at,\n expire_after_specific_number_of_charges,\n shopify_product_id,\n shopify_variant_id,\n has_queued_charges,\n is_prepaid,\n is_skippable,\n is_swappable,\n max_retries_reached,\n next_charge_scheduled_at,\n order_day_of_month,\n order_day_of_week,\n order_interval_frequency,\n order_interval_unit,\n presentment_currency,\n price,\n product_title,\n properties,\n quantity,\n sku,\n sku_override,\n status,\n updated_at,\n variant_title,\n } = old;\n return {\n id,\n address_id,\n customer_id,\n analytics_data,\n cancellation_reason,\n cancellation_reason_comments,\n cancelled_at,\n charge_interval_frequency: parseInt(charge_interval_frequency, 10),\n created_at,\n expire_after_specific_number_of_charges,\n external_product_id: { ecommerce: `${shopify_product_id}` },\n external_variant_id: { ecommerce: `${shopify_variant_id}` },\n has_queued_charges: convertToBool(has_queued_charges),\n is_prepaid,\n is_skippable,\n is_swappable,\n max_retries_reached: convertToBool(max_retries_reached),\n next_charge_scheduled_at,\n order_day_of_month,\n order_day_of_week,\n order_interval_frequency: parseInt(order_interval_frequency, 10),\n order_interval_unit,\n presentment_currency,\n price: `${price}`,\n product_title: product_title ?? '',\n properties,\n quantity,\n sku,\n sku_override,\n status: status.toLowerCase() as SubscriptionStatus,\n updated_at,\n variant_title,\n };\n}\n"],"names":[],"mappings":";;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/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,YAAY;AAChB,IAAI,mBAAmB,EAAE,aAAa,CAAC,mBAAmB,CAAC;AAC3D,IAAI,wBAAwB;AAC5B,IAAI,kBAAkB;AACtB,IAAI,iBAAiB;AACrB,IAAI,wBAAwB,EAAE,QAAQ,CAAC,wBAAwB,EAAE,EAAE,CAAC;AACpE,IAAI,mBAAmB;AACvB,IAAI,oBAAoB;AACxB,IAAI,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AACrB,IAAI,aAAa,EAAE,aAAa,IAAI,IAAI,GAAG,aAAa,GAAG,EAAE;AAC7D,IAAI,UAAU;AACd,IAAI,QAAQ;AACZ,IAAI,GAAG;AACP,IAAI,YAAY;AAChB,IAAI,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;AAChC,IAAI,UAAU;AACd,IAAI,aAAa;AACjB,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -29,6 +29,12 @@ function parseValues(json) {
|
|
|
29
29
|
return __spreadProps(__spreadValues({}, memo), { [key]: parseValue(value) });
|
|
30
30
|
}, {});
|
|
31
31
|
}
|
|
32
|
+
const convertToBool = (val) => {
|
|
33
|
+
if (typeof val === "string") {
|
|
34
|
+
return val !== "0" && val !== "false";
|
|
35
|
+
}
|
|
36
|
+
return !!val;
|
|
37
|
+
};
|
|
32
38
|
|
|
33
|
-
export { parseValues };
|
|
39
|
+
export { convertToBool, parseValues };
|
|
34
40
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/mappers/utils.ts"],"sourcesContent":["/** Trys to parse passed in value. If it doesn't work returns the same passed in value */\nfunction parseValue(value: unknown): any {\n try {\n return JSON.parse(value as string);\n } catch {\n return value;\n }\n}\n\n/** Returns a new object that updates \"string\" values into their correct data type. */\nexport function parseValues<T = any>(json: Record<string, unknown>): T {\n return Object.entries(json).reduce((memo, [key, value]) => {\n return { ...memo, [key]: parseValue(value) };\n }, {}) as T;\n}\n"],"names":[],"mapp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C,KAAK,UAAU,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,SAAS,UAAU,CAAC,KAAK,EAAE;AAC3B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,CAAC;AACM,SAAS,WAAW,CAAC,IAAI,EAAE;AAClC,EAAE,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC7D,IAAI,OAAO,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjF,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/mappers/utils.ts"],"sourcesContent":["import { BooleanLike } from '../types';\n\n/** Trys to parse passed in value. If it doesn't work returns the same passed in value */\nfunction parseValue(value: unknown): any {\n try {\n return JSON.parse(value as string);\n } catch {\n return value;\n }\n}\n\n/** Returns a new object that updates \"string\" values into their correct data type. */\nexport function parseValues<T = any>(json: Record<string, unknown>): T {\n return Object.entries(json).reduce((memo, [key, value]) => {\n return { ...memo, [key]: parseValue(value) };\n }, {}) as T;\n}\n\nexport const convertToBool = (val: BooleanLike) => {\n if (typeof val === 'string') {\n return val !== '0' && val !== 'false';\n }\n\n return !!val;\n};\n"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,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