@rechargeapps/storefront-client 0.27.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/README.md +4 -43
- package/dist/cjs/api/bundle.js +6 -6
- package/dist/cjs/api/bundle.js.map +1 -1
- package/dist/cjs/api/subscription.js +61 -8
- 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/cjs/utils/bundle.js +69 -0
- package/dist/cjs/utils/bundle.js.map +1 -0
- package/dist/esm/api/bundle.js +1 -1
- package/dist/esm/api/bundle.js.map +1 -1
- package/dist/esm/api/subscription.js +56 -9
- 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/esm/utils/bundle.js +65 -0
- package/dist/esm/utils/bundle.js.map +1 -0
- package/dist/index.d.ts +77 -6
- package/dist/umd/recharge-client.min.js +12 -10
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { toLineItemProperty } from '@rechargeapps/bundling-data';\nimport { nanoid } from 'nanoid';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n Session,\n UpdateBundleSelectionRequest,\n} from '../types';\nimport { rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { getCDNBundleSettings } from './cdn';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction getTimestampSecondsFromClient(): number {\n /**\n * Get the current unix epoch in seconds from the client-side.\n */\n return Math.ceil(Date.now() / 1000);\n}\n\nasync function getTimestampSecondsFromServer(): Promise<number> {\n /**\n * Get the unix epoch from the server instead of using it directly from the\n * client. This must reduce even more the number of invalid Bundles.\n */\n try {\n const { timestamp } = await shopifyAppProxyRequest<{ timestamp: number }>('get', `${STORE_FRONT_MANAGER_URL}/t`, {\n headers: { 'X-Recharge-App': 'storefront-client' },\n });\n return timestamp;\n } catch (ex) {\n console.error(`Fetch failed: ${ex}. Using client-side date.`);\n return getTimestampSecondsFromClient();\n }\n}\n\nexport async function getBundleId(bundle: BundleAppProxy): Promise<string> {\n const opts = getOptions();\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const timestampSeconds = await getTimestampSecondsFromServer();\n const bundleData = toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: timestampSeconds,\n items: bundle.selections.map(item => {\n return {\n collectionId: item.collectionId,\n productId: item.externalProductId,\n variantId: item.externalVariantId,\n quantity: item.quantity,\n sku: '',\n };\n }),\n });\n\n try {\n const payload = await shopifyAppProxyRequest<{ id: string; code: number; message: string }>(\n 'post',\n `${STORE_FRONT_MANAGER_URL}/api/v1/bundles`,\n {\n data: {\n bundle: bundleData,\n },\n headers: {\n Origin: `https://${opts.storeIdentifier}`,\n },\n }\n );\n\n if (!payload.id || payload.code !== 200) {\n throw new Error(`1: failed generating rb_id: ${JSON.stringify(payload)}`);\n }\n\n return payload.id;\n } catch (e) {\n // Handle NetworkError exceptions\n throw new Error(`2: failed generating rb_id ${e}`);\n }\n}\n\nexport function getDynamicBundleItems(bundle: BundleAppProxy, shopifyProductHandle: string) {\n const isValid = validateDynamicBundle(bundle);\n if (isValid !== true) {\n throw new Error(`Dynamic Bundle is invalid. ${isValid}`);\n }\n // generate unique id for dynamic bundle\n const bundleId = `${nanoid(9)}:${bundle.externalProductId}`;\n return bundle.selections.map(item => {\n const itemData: DynamicBundleItemAppProxy = {\n id: item.externalVariantId,\n quantity: item.quantity,\n properties: {\n _rc_bundle: bundleId,\n _rc_bundle_variant: bundle.externalVariantId,\n _rc_bundle_parent: shopifyProductHandle,\n _rc_bundle_collection_id: item.collectionId,\n },\n };\n\n if (item.sellingPlan) {\n // this is used by SCI stores\n itemData.selling_plan = item.sellingPlan;\n } else if (item.shippingIntervalFrequency) {\n // this is used by RCS stores\n itemData.properties.shipping_interval_frequency = item.shippingIntervalFrequency;\n itemData.properties.shipping_interval_unit_type = item.shippingIntervalUnitType;\n itemData.id = `${item.discountedVariantId}`;\n }\n\n return itemData;\n });\n}\n\nexport async function validateBundle(bundle: BundleAppProxy): Promise<true | string> {\n try {\n // once we implement this function, we can make it raise an exception\n // we could also have a local store relative to this function so we don't have to pass bundleProduct\n if (!bundle) {\n return 'Bundle is not defined';\n }\n const bundleSettings = await getCDNBundleSettings(bundle.externalProductId);\n if (!bundleSettings) {\n return 'Bundle settings do not exist for the given product';\n }\n return true;\n } catch (e) {\n return `Error fetching bundle settings: ${e}`;\n }\n}\n\nconst intervalUnitGroups = {\n day: ['day', 'days', 'Days'],\n days: ['day', 'days', 'Days'],\n Days: ['day', 'days', 'Days'],\n week: ['week', 'weeks', 'Weeks'],\n weeks: ['week', 'weeks', 'Weeks'],\n Weeks: ['week', 'weeks', 'Weeks'],\n month: ['month', 'months', 'Months'],\n months: ['month', 'months', 'Months'],\n Months: ['month', 'months', 'Months'],\n};\n\n/**\n * Validates a dynamic bundle\n *\n * @param bundle Dynamic Bundle being validated\n * @returns true or error message\n */\nexport function validateDynamicBundle(bundle: BundleAppProxy): true | string {\n if (!bundle) {\n return 'No bundle defined.';\n }\n if (bundle.selections.length === 0) {\n return 'No selections defined.';\n }\n // validation for RCS onetimes\n const { shippingIntervalFrequency, shippingIntervalUnitType } =\n bundle.selections.find(selection => selection.shippingIntervalFrequency || selection.shippingIntervalUnitType) ||\n {};\n if (shippingIntervalFrequency || shippingIntervalUnitType) {\n // if we have shipping intervals then we should have both defined\n if (!shippingIntervalFrequency || !shippingIntervalUnitType) {\n return 'Shipping intervals do not match on selections.';\n } else {\n // if we have shipping intervals then any that are defined should match\n const shippingIntervalUnitGroup = intervalUnitGroups[shippingIntervalUnitType];\n for (let x = 0; x < bundle.selections.length; x++) {\n const { shippingIntervalFrequency: frequency, shippingIntervalUnitType: unitType } = bundle.selections[x];\n if (\n (frequency && frequency !== shippingIntervalFrequency) ||\n (unitType && !shippingIntervalUnitGroup.includes(unitType))\n ) {\n return 'Shipping intervals do not match on selections.';\n }\n }\n }\n }\n return true;\n}\n\nexport async function getBundleSelection(session: Session, id: string | number): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>('get', `/bundle_selections`, { query }, session);\n}\n\nexport async function createBundleSelection(\n session: Session,\n createRequest: CreateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'post',\n `/bundle_selections`,\n {\n data: createRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport async function updateBundleSelection(\n session: Session,\n id: string | number,\n updateRequest: UpdateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n}\n"],"names":[],"mappings":";;;;;;AAKA,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;A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CAAC,kBAAkB,CAAC,EAAE;AACtF,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,eAAe,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE;AACxE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE;AACrF,IAAI,EAAE;AACN,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,SAAS,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE;AACnD,EAAE,OAAO,kBAAkB,CAAC,QAAQ,EAAE,CAAC,kBAAkB,CAAC,EAAE;AAC5D,IAAI,EAAE;AACN,GAAG,EAAE,OAAO,CAAC,CAAC;AACd;;;;"}
|
|
1
|
+
{"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport {\n BundleAppProxy,\n DynamicBundleItemAppProxy,\n BundleSelection,\n BundleSelectionListParams,\n BundleSelectionsResponse,\n CreateBundleSelectionRequest,\n Session,\n UpdateBundleSelectionRequest,\n} from '../types';\nimport { rechargeApiRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { getOptions } from '../utils/options';\nimport { getCDNBundleSettings } from './cdn';\nimport { toLineItemProperty } from '../utils/bundle';\n\nconst STORE_FRONT_MANAGER_URL = '/bundling-storefront-manager';\n\nfunction getTimestampSecondsFromClient(): number {\n /**\n * Get the current unix epoch in seconds from the client-side.\n */\n return Math.ceil(Date.now() / 1000);\n}\n\nasync function getTimestampSecondsFromServer(): Promise<number> {\n /**\n * Get the unix epoch from the server instead of using it directly from the\n * client. This must reduce even more the number of invalid Bundles.\n */\n try {\n const { timestamp } = await shopifyAppProxyRequest<{ timestamp: number }>('get', `${STORE_FRONT_MANAGER_URL}/t`, {\n headers: { 'X-Recharge-App': 'storefront-client' },\n });\n return timestamp;\n } catch (ex) {\n console.error(`Fetch failed: ${ex}. Using client-side date.`);\n return getTimestampSecondsFromClient();\n }\n}\n\nexport async function getBundleId(bundle: BundleAppProxy): Promise<string> {\n const opts = getOptions();\n const isValid = await validateBundle(bundle);\n if (isValid !== true) {\n throw new Error(isValid);\n }\n const timestampSeconds = await getTimestampSecondsFromServer();\n const bundleData = toLineItemProperty({\n variantId: bundle.externalVariantId,\n version: timestampSeconds,\n items: bundle.selections.map(item => {\n return {\n collectionId: item.collectionId,\n productId: item.externalProductId,\n variantId: item.externalVariantId,\n quantity: item.quantity,\n sku: '',\n };\n }),\n });\n\n try {\n const payload = await shopifyAppProxyRequest<{ id: string; code: number; message: string }>(\n 'post',\n `${STORE_FRONT_MANAGER_URL}/api/v1/bundles`,\n {\n data: {\n bundle: bundleData,\n },\n headers: {\n Origin: `https://${opts.storeIdentifier}`,\n },\n }\n );\n\n if (!payload.id || payload.code !== 200) {\n throw new Error(`1: failed generating rb_id: ${JSON.stringify(payload)}`);\n }\n\n return payload.id;\n } catch (e) {\n // Handle NetworkError exceptions\n throw new Error(`2: failed generating rb_id ${e}`);\n }\n}\n\nexport function getDynamicBundleItems(bundle: BundleAppProxy, shopifyProductHandle: string) {\n const isValid = validateDynamicBundle(bundle);\n if (isValid !== true) {\n throw new Error(`Dynamic Bundle is invalid. ${isValid}`);\n }\n // generate unique id for dynamic bundle\n const bundleId = `${nanoid(9)}:${bundle.externalProductId}`;\n return bundle.selections.map(item => {\n const itemData: DynamicBundleItemAppProxy = {\n id: item.externalVariantId,\n quantity: item.quantity,\n properties: {\n _rc_bundle: bundleId,\n _rc_bundle_variant: bundle.externalVariantId,\n _rc_bundle_parent: shopifyProductHandle,\n _rc_bundle_collection_id: item.collectionId,\n },\n };\n\n if (item.sellingPlan) {\n // this is used by SCI stores\n itemData.selling_plan = item.sellingPlan;\n } else if (item.shippingIntervalFrequency) {\n // this is used by RCS stores\n itemData.properties.shipping_interval_frequency = item.shippingIntervalFrequency;\n itemData.properties.shipping_interval_unit_type = item.shippingIntervalUnitType;\n itemData.id = `${item.discountedVariantId}`;\n }\n\n return itemData;\n });\n}\n\nexport async function validateBundle(bundle: BundleAppProxy): Promise<true | string> {\n try {\n // once we implement this function, we can make it raise an exception\n // we could also have a local store relative to this function so we don't have to pass bundleProduct\n if (!bundle) {\n return 'Bundle is not defined';\n }\n const bundleSettings = await getCDNBundleSettings(bundle.externalProductId);\n if (!bundleSettings) {\n return 'Bundle settings do not exist for the given product';\n }\n return true;\n } catch (e) {\n return `Error fetching bundle settings: ${e}`;\n }\n}\n\nconst intervalUnitGroups = {\n day: ['day', 'days', 'Days'],\n days: ['day', 'days', 'Days'],\n Days: ['day', 'days', 'Days'],\n week: ['week', 'weeks', 'Weeks'],\n weeks: ['week', 'weeks', 'Weeks'],\n Weeks: ['week', 'weeks', 'Weeks'],\n month: ['month', 'months', 'Months'],\n months: ['month', 'months', 'Months'],\n Months: ['month', 'months', 'Months'],\n};\n\n/**\n * Validates a dynamic bundle\n *\n * @param bundle Dynamic Bundle being validated\n * @returns true or error message\n */\nexport function validateDynamicBundle(bundle: BundleAppProxy): true | string {\n if (!bundle) {\n return 'No bundle defined.';\n }\n if (bundle.selections.length === 0) {\n return 'No selections defined.';\n }\n // validation for RCS onetimes\n const { shippingIntervalFrequency, shippingIntervalUnitType } =\n bundle.selections.find(selection => selection.shippingIntervalFrequency || selection.shippingIntervalUnitType) ||\n {};\n if (shippingIntervalFrequency || shippingIntervalUnitType) {\n // if we have shipping intervals then we should have both defined\n if (!shippingIntervalFrequency || !shippingIntervalUnitType) {\n return 'Shipping intervals do not match on selections.';\n } else {\n // if we have shipping intervals then any that are defined should match\n const shippingIntervalUnitGroup = intervalUnitGroups[shippingIntervalUnitType];\n for (let x = 0; x < bundle.selections.length; x++) {\n const { shippingIntervalFrequency: frequency, shippingIntervalUnitType: unitType } = bundle.selections[x];\n if (\n (frequency && frequency !== shippingIntervalFrequency) ||\n (unitType && !shippingIntervalUnitGroup.includes(unitType))\n ) {\n return 'Shipping intervals do not match on selections.';\n }\n }\n }\n }\n return true;\n}\n\nexport async function getBundleSelection(session: Session, id: string | number): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'get',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function listBundleSelections(\n session: Session,\n query?: BundleSelectionListParams\n): Promise<BundleSelectionsResponse> {\n return rechargeApiRequest<BundleSelectionsResponse>('get', `/bundle_selections`, { query }, session);\n}\n\nexport async function createBundleSelection(\n session: Session,\n createRequest: CreateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'post',\n `/bundle_selections`,\n {\n data: createRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport async function updateBundleSelection(\n session: Session,\n id: string | number,\n updateRequest: UpdateBundleSelectionRequest\n): Promise<BundleSelection> {\n const { bundle_selection } = await rechargeApiRequest<{ bundle_selection: BundleSelection }>(\n 'put',\n `/bundle_selections`,\n {\n id,\n data: updateRequest,\n },\n session\n );\n return bundle_selection;\n}\n\nexport function deleteBundleSelection(session: Session, id: string | number): Promise<void> {\n return rechargeApiRequest<void>(\n 'delete',\n `/bundle_selections`,\n {\n id,\n },\n session\n );\n}\n"],"names":[],"mappings":";;;;;;AAKA,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAC/D,SAAS,6BAA6B,GAAG;AACzC,EAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AACrC,CAAC;AACD,eAAe,6BAA6B,GAAG;AAC/C,EAAE,IAAI;AACN,IAAI,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,sBAAsB,CAAC,KAAK,EAAE,CAAC,EAAE,u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AC,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE;AACrF,IAAI,EAAE;AACN,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACM,SAAS,qBAAqB,CAAC,OAAO,EAAE,EAAE,EAAE;AACnD,EAAE,OAAO,kBAAkB,CAAC,QAAQ,EAAE,CAAC,kBAAkB,CAAC,EAAE;AAC5D,IAAI,EAAE;AACN,GAAG,EAAE,OAAO,CAAC,CAAC;AACd;;;;"}
|
|
@@ -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`, {
|
|
@@ -10,9 +12,10 @@ async function getSubscription(session, id, options) {
|
|
|
10
12
|
function listSubscriptions(session, query) {
|
|
11
13
|
return rechargeApiRequest("get", `/subscriptions`, { query }, session);
|
|
12
14
|
}
|
|
13
|
-
async function createSubscription(session, createRequest) {
|
|
15
|
+
async function createSubscription(session, createRequest, query) {
|
|
14
16
|
const { subscription } = await rechargeApiRequest("post", `/subscriptions`, {
|
|
15
|
-
data: createRequest
|
|
17
|
+
data: createRequest,
|
|
18
|
+
query
|
|
16
19
|
}, session);
|
|
17
20
|
return subscription;
|
|
18
21
|
}
|
|
@@ -24,9 +27,10 @@ async function updateSubscription(session, id, updateRequest, query) {
|
|
|
24
27
|
}, session);
|
|
25
28
|
return subscription;
|
|
26
29
|
}
|
|
27
|
-
async function updateSubscriptionChargeDate(session, id, date) {
|
|
30
|
+
async function updateSubscriptionChargeDate(session, id, date, query) {
|
|
28
31
|
const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/set_next_charge_date`, {
|
|
29
|
-
data: { date }
|
|
32
|
+
data: { date },
|
|
33
|
+
query
|
|
30
34
|
}, session);
|
|
31
35
|
return subscription;
|
|
32
36
|
}
|
|
@@ -36,14 +40,15 @@ async function updateSubscriptionAddress(session, id, address_id) {
|
|
|
36
40
|
}, session);
|
|
37
41
|
return subscription;
|
|
38
42
|
}
|
|
39
|
-
async function cancelSubscription(session, id, cancelRequest) {
|
|
43
|
+
async function cancelSubscription(session, id, cancelRequest, query) {
|
|
40
44
|
const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/cancel`, {
|
|
41
|
-
data: cancelRequest
|
|
45
|
+
data: cancelRequest,
|
|
46
|
+
query
|
|
42
47
|
}, session);
|
|
43
48
|
return subscription;
|
|
44
49
|
}
|
|
45
|
-
async function activateSubscription(session, id) {
|
|
46
|
-
const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/activate`, {}, session);
|
|
50
|
+
async function activateSubscription(session, id, query) {
|
|
51
|
+
const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/activate`, { query }, session);
|
|
47
52
|
return subscription;
|
|
48
53
|
}
|
|
49
54
|
async function skipSubscriptionCharge(session, id, date) {
|
|
@@ -55,6 +60,48 @@ async function skipSubscriptionCharge(session, id, date) {
|
|
|
55
60
|
}, session);
|
|
56
61
|
return charge;
|
|
57
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
|
+
}
|
|
58
105
|
|
|
59
|
-
export { activateSubscription, cancelSubscription, createSubscription, getSubscription, listSubscriptions, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate };
|
|
106
|
+
export { activateSubscription, cancelSubscription, createSubscription, createSubscriptions, getSubscription, listSubscriptions, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate, updateSubscriptions };
|
|
60
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} 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): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions`,\n {\n data: createRequest,\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): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\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): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data: cancelRequest,\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(session: Session, id: string | number): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`,\n {},\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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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":[],"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,aA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G,KAAK,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;AAC/H,EAAE,MAAM,WAAW,GAAG,iBAAiB,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3E,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,SAAS,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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,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC,EAAE;AAC/D,IAAI,mBAAmB,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC,EAAE;AAC/D,IAAI,kBAAkB,EAAE,aAAa,CAAC,kBAAkB,CAAC;AACzD,IAAI,UAAU;AACd,IAAI,YAAY;AAChB,IAAI,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":[],"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,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB;AACzB,IAAI,KAAK,IAAI,IAAI,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;AAC7C,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AACpC,QAAQ,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,KAAK;AACL,EAAE,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AACF,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC,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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AC;AACF,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC,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,CAAC;AACW,MAAC,aAAa,GAAG,CAAC,GAAG,KAAK;AACtC,EAAE,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAC/B,IAAI,OAAO,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,OAAO,CAAC;AAC1C,GAAG;AACH,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC;AACf;;;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { config } from 'js-xdr';
|
|
2
|
+
|
|
3
|
+
function toLineItemProperty(bundle) {
|
|
4
|
+
const opts = {
|
|
5
|
+
variantId: xdr.Uint64.fromString(bundle.variantId.toString()),
|
|
6
|
+
version: bundle.version || Math.floor(Date.now() / 1e3),
|
|
7
|
+
items: bundle.items.map((item) => {
|
|
8
|
+
return new xdr.BundleItem({
|
|
9
|
+
collectionId: xdr.Uint64.fromString(item.collectionId.toString()),
|
|
10
|
+
productId: xdr.Uint64.fromString(item.productId.toString()),
|
|
11
|
+
variantId: xdr.Uint64.fromString(item.variantId.toString()),
|
|
12
|
+
sku: item.sku || "",
|
|
13
|
+
quantity: item.quantity,
|
|
14
|
+
ext: new xdr.BundleItemExt(0)
|
|
15
|
+
});
|
|
16
|
+
}),
|
|
17
|
+
ext: new xdr.BundleExt(0)
|
|
18
|
+
};
|
|
19
|
+
const xdrBundle = new xdr.Bundle(opts);
|
|
20
|
+
return xdr.BundleEnvelope.envelopeTypeBundle(xdrBundle).toXDR("base64");
|
|
21
|
+
}
|
|
22
|
+
const xdr = config((xdr2) => {
|
|
23
|
+
xdr2.enum("EnvelopeType", {
|
|
24
|
+
envelopeTypeBundle: 0
|
|
25
|
+
});
|
|
26
|
+
xdr2.typedef("Uint32", xdr2.uint());
|
|
27
|
+
xdr2.typedef("Uint64", xdr2.uhyper());
|
|
28
|
+
xdr2.union("BundleItemExt", {
|
|
29
|
+
switchOn: xdr2.int(),
|
|
30
|
+
switchName: "v",
|
|
31
|
+
switches: [[0, xdr2.void()]],
|
|
32
|
+
arms: {}
|
|
33
|
+
});
|
|
34
|
+
xdr2.struct("BundleItem", [
|
|
35
|
+
["collectionId", xdr2.lookup("Uint64")],
|
|
36
|
+
["productId", xdr2.lookup("Uint64")],
|
|
37
|
+
["variantId", xdr2.lookup("Uint64")],
|
|
38
|
+
["sku", xdr2.string()],
|
|
39
|
+
["quantity", xdr2.lookup("Uint32")],
|
|
40
|
+
["ext", xdr2.lookup("BundleItemExt")]
|
|
41
|
+
]);
|
|
42
|
+
xdr2.union("BundleExt", {
|
|
43
|
+
switchOn: xdr2.int(),
|
|
44
|
+
switchName: "v",
|
|
45
|
+
switches: [[0, xdr2.void()]],
|
|
46
|
+
arms: {}
|
|
47
|
+
});
|
|
48
|
+
xdr2.struct("Bundle", [
|
|
49
|
+
["variantId", xdr2.lookup("Uint64")],
|
|
50
|
+
["items", xdr2.varArray(xdr2.lookup("BundleItem"), 500)],
|
|
51
|
+
["version", xdr2.lookup("Uint32")],
|
|
52
|
+
["ext", xdr2.lookup("BundleExt")]
|
|
53
|
+
]);
|
|
54
|
+
xdr2.union("BundleEnvelope", {
|
|
55
|
+
switchOn: xdr2.lookup("EnvelopeType"),
|
|
56
|
+
switchName: "type",
|
|
57
|
+
switches: [["envelopeTypeBundle", "v1"]],
|
|
58
|
+
arms: {
|
|
59
|
+
v1: xdr2.lookup("Bundle")
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export { toLineItemProperty };
|
|
65
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sources":["../../../src/utils/bundle.ts"],"sourcesContent":["import { config } from 'js-xdr';\n\nexport function toLineItemProperty(bundle: { variantId: string; version: number; items: any[] }) {\n const opts = {\n variantId: xdr.Uint64.fromString(bundle.variantId.toString()),\n version: bundle.version || Math.floor(Date.now() / 1000),\n items: bundle.items.map(item => {\n return new xdr.BundleItem({\n collectionId: xdr.Uint64.fromString(item.collectionId.toString()),\n productId: xdr.Uint64.fromString(item.productId.toString()),\n variantId: xdr.Uint64.fromString(item.variantId.toString()),\n sku: item.sku || '',\n quantity: item.quantity,\n ext: new xdr.BundleItemExt(0),\n });\n }),\n ext: new xdr.BundleExt(0),\n };\n\n const xdrBundle = new xdr.Bundle(opts);\n return xdr.BundleEnvelope.envelopeTypeBundle(xdrBundle).toXDR('base64');\n}\n\nconst xdr = config(\n (xdr: {\n enum: (arg0: string, arg1: { envelopeTypeBundle: number }) => void;\n typedef: (arg0: string, arg1: any) => void;\n uint: () => any;\n uhyper: () => any;\n union: (\n arg0: string,\n arg1: {\n switchOn: any;\n switchName: string;\n switches: any[][] | string[][];\n // eslint-disable-next-line @typescript-eslint/ban-types\n arms: {} | {} | { v1: any };\n }\n ) => void;\n int: () => any;\n void: () => any;\n struct: (arg0: string, arg1: any[][]) => void;\n lookup: (arg0: string) => any;\n string: () => any;\n varArray: (arg0: any, arg1: number) => any;\n }) => {\n xdr.enum('EnvelopeType', {\n envelopeTypeBundle: 0,\n });\n xdr.typedef('Uint32', xdr.uint());\n xdr.typedef('Uint64', xdr.uhyper());\n xdr.union('BundleItemExt', {\n switchOn: xdr.int(),\n switchName: 'v',\n switches: [[0, xdr.void()]],\n arms: {},\n });\n xdr.struct('BundleItem', [\n ['collectionId', xdr.lookup('Uint64')],\n ['productId', xdr.lookup('Uint64')],\n ['variantId', xdr.lookup('Uint64')],\n ['sku', xdr.string()],\n ['quantity', xdr.lookup('Uint32')],\n ['ext', xdr.lookup('BundleItemExt')],\n ]);\n xdr.union('BundleExt', {\n switchOn: xdr.int(),\n switchName: 'v',\n switches: [[0, xdr.void()]],\n arms: {},\n });\n xdr.struct('Bundle', [\n ['variantId', xdr.lookup('Uint64')],\n ['items', xdr.varArray(xdr.lookup('BundleItem'), 500)],\n ['version', xdr.lookup('Uint32')],\n ['ext', xdr.lookup('BundleExt')],\n ]);\n xdr.union('BundleEnvelope', {\n switchOn: xdr.lookup('EnvelopeType'),\n switchName: 'type',\n switches: [['envelopeTypeBundle', 'v1']],\n arms: {\n v1: xdr.lookup('Bundle'),\n },\n });\n }\n);\n"],"names":[],"mappings":";;AACO,SAAS,kBAAkB,CAAC,MAAM,EAAE;AAC3C,EAAE,MAAM,IAAI,GAAG;AACf,IAAI,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;AACjE,IAAI,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;AAC3D,IAAI,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK;AACtC,MAAM,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC;AAChC,QAAQ,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,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