@rechargeapps/storefront-client 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/address.js +34 -9
- package/dist/cjs/api/address.js.map +1 -1
- package/dist/cjs/api/auth.js +34 -6
- package/dist/cjs/api/auth.js.map +1 -1
- package/dist/cjs/api/bundle.js +57 -20
- package/dist/cjs/api/bundle.js.map +1 -1
- package/dist/cjs/api/cdn.js +18 -6
- package/dist/cjs/api/cdn.js.map +1 -1
- package/dist/cjs/api/charge.js +34 -14
- package/dist/cjs/api/charge.js.map +1 -1
- package/dist/cjs/api/customer.js +21 -6
- package/dist/cjs/api/customer.js.map +1 -1
- package/dist/cjs/api/membership.js +24 -9
- package/dist/cjs/api/membership.js.map +1 -1
- package/dist/cjs/api/membershipProgram.js +6 -1
- package/dist/cjs/api/membershipProgram.js.map +1 -1
- package/dist/cjs/api/metafield.js +25 -10
- package/dist/cjs/api/metafield.js.map +1 -1
- package/dist/cjs/api/onetime.js +33 -13
- package/dist/cjs/api/onetime.js.map +1 -1
- package/dist/cjs/api/order.js +8 -3
- package/dist/cjs/api/order.js.map +1 -1
- package/dist/cjs/api/paymentMethod.js +18 -8
- package/dist/cjs/api/paymentMethod.js.map +1 -1
- package/dist/cjs/api/plan.js +8 -3
- package/dist/cjs/api/plan.js.map +1 -1
- package/dist/cjs/api/subscription.js +93 -43
- 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/utils/bundle.js +43 -41
- package/dist/cjs/utils/bundle.js.map +1 -1
- package/dist/cjs/utils/init.js +3 -1
- package/dist/cjs/utils/init.js.map +1 -1
- package/dist/esm/api/address.js +34 -9
- package/dist/esm/api/address.js.map +1 -1
- package/dist/esm/api/auth.js +34 -7
- package/dist/esm/api/auth.js.map +1 -1
- package/dist/esm/api/bundle.js +57 -21
- package/dist/esm/api/bundle.js.map +1 -1
- package/dist/esm/api/cdn.js +18 -6
- package/dist/esm/api/cdn.js.map +1 -1
- package/dist/esm/api/charge.js +34 -14
- package/dist/esm/api/charge.js.map +1 -1
- package/dist/esm/api/customer.js +21 -6
- package/dist/esm/api/customer.js.map +1 -1
- package/dist/esm/api/membership.js +24 -9
- package/dist/esm/api/membership.js.map +1 -1
- package/dist/esm/api/membershipProgram.js +6 -1
- package/dist/esm/api/membershipProgram.js.map +1 -1
- package/dist/esm/api/metafield.js +25 -10
- package/dist/esm/api/metafield.js.map +1 -1
- package/dist/esm/api/onetime.js +33 -13
- package/dist/esm/api/onetime.js.map +1 -1
- package/dist/esm/api/order.js +8 -3
- package/dist/esm/api/order.js.map +1 -1
- package/dist/esm/api/paymentMethod.js +18 -8
- package/dist/esm/api/paymentMethod.js.map +1 -1
- package/dist/esm/api/plan.js +8 -3
- package/dist/esm/api/plan.js.map +1 -1
- package/dist/esm/api/subscription.js +93 -43
- package/dist/esm/api/subscription.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/bundle.js +43 -41
- package/dist/esm/utils/bundle.js.map +1 -1
- package/dist/esm/utils/init.js +3 -1
- package/dist/esm/utils/init.js.map +1 -1
- package/dist/index.d.ts +237 -86
- package/dist/umd/recharge-client.min.js +8 -8
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
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":";;;;;;;;;;;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;;;;;;;;;;;"}
|
|
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;AACnD,IAAI,KAAK;AACT,IAAI,CAAC,cAAc,CAAC;AACpB,IAAI;AACJ,MAAM,EAAE;AACR,MAAM,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE;AACpE,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,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;AACnD,IAAI,MAAM;AACV,IAAI,CAAC,cAAc,CAAC;AACpB,IAAI;AACJ,MAAM,IAAI,EAAE,aAAa;AACzB,MAAM,KAAK;AACX,KAAK;AACL,IAAI,OAA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UAAU,EAAE;AACnB,IAAI,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;AACjD,GAAG;AACH,EAAE,MAAM,6BAA6B,GAAGF,2BAAO,CAACG,yCAA4B,EAAE,CAAC,EAAE,KAAK,IAAI,IAAI,GAAG,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,MAAMJ,0BAAkB;AACpD,IAAI,KAAK;AACT,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,mBAAmB,CAAC;AAChD,IAAI;AACJ,MAAM,IAAI,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE;AAC1C,MAAM,OAAO,EAAE;AACf,QAAQ,oBAAoB,EAAE,SAAS;AACvC,OAAO;AACP,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,aAAa,CAAC,GAAG,CAACG,uCAA0B,CAAC,CAAC;AACvD;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.mergeAddresses = address.mergeAddresses;
|
|
|
29
29
|
exports.removeDiscountsFromAddress = address.removeDiscountsFromAddress;
|
|
30
30
|
exports.skipFutureCharge = address.skipFutureCharge;
|
|
31
31
|
exports.updateAddress = address.updateAddress;
|
|
32
|
+
exports.loginCustomerPortal = auth.loginCustomerPortal;
|
|
32
33
|
exports.loginShopifyApi = auth.loginShopifyApi;
|
|
33
34
|
exports.loginShopifyAppProxy = auth.loginShopifyAppProxy;
|
|
34
35
|
exports.sendPasswordlessCode = auth.sendPasswordlessCode;
|
|
@@ -56,6 +57,7 @@ exports.getBundleId = bundle.getBundleId;
|
|
|
56
57
|
exports.getBundleSelection = bundle.getBundleSelection;
|
|
57
58
|
exports.getDynamicBundleItems = bundle.getDynamicBundleItems;
|
|
58
59
|
exports.listBundleSelections = bundle.listBundleSelections;
|
|
60
|
+
exports.updateBundle = bundle.updateBundle;
|
|
59
61
|
exports.updateBundleSelection = bundle.updateBundleSelection;
|
|
60
62
|
exports.validateBundle = bundle.validateBundle;
|
|
61
63
|
exports.validateDynamicBundle = bundle.validateDynamicBundle;
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/utils/bundle.js
CHANGED
|
@@ -23,47 +23,49 @@ function toLineItemProperty(bundle) {
|
|
|
23
23
|
const xdrBundle = new xdr.Bundle(opts);
|
|
24
24
|
return xdr.BundleEnvelope.envelopeTypeBundle(xdrBundle).toXDR("base64");
|
|
25
25
|
}
|
|
26
|
-
const xdr = jsXdr.config(
|
|
27
|
-
xdr2
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
26
|
+
const xdr = jsXdr.config(
|
|
27
|
+
(xdr2) => {
|
|
28
|
+
xdr2.enum("EnvelopeType", {
|
|
29
|
+
envelopeTypeBundle: 0
|
|
30
|
+
});
|
|
31
|
+
xdr2.typedef("Uint32", xdr2.uint());
|
|
32
|
+
xdr2.typedef("Uint64", xdr2.uhyper());
|
|
33
|
+
xdr2.union("BundleItemExt", {
|
|
34
|
+
switchOn: xdr2.int(),
|
|
35
|
+
switchName: "v",
|
|
36
|
+
switches: [[0, xdr2.void()]],
|
|
37
|
+
arms: {}
|
|
38
|
+
});
|
|
39
|
+
xdr2.struct("BundleItem", [
|
|
40
|
+
["collectionId", xdr2.lookup("Uint64")],
|
|
41
|
+
["productId", xdr2.lookup("Uint64")],
|
|
42
|
+
["variantId", xdr2.lookup("Uint64")],
|
|
43
|
+
["sku", xdr2.string()],
|
|
44
|
+
["quantity", xdr2.lookup("Uint32")],
|
|
45
|
+
["ext", xdr2.lookup("BundleItemExt")]
|
|
46
|
+
]);
|
|
47
|
+
xdr2.union("BundleExt", {
|
|
48
|
+
switchOn: xdr2.int(),
|
|
49
|
+
switchName: "v",
|
|
50
|
+
switches: [[0, xdr2.void()]],
|
|
51
|
+
arms: {}
|
|
52
|
+
});
|
|
53
|
+
xdr2.struct("Bundle", [
|
|
54
|
+
["variantId", xdr2.lookup("Uint64")],
|
|
55
|
+
["items", xdr2.varArray(xdr2.lookup("BundleItem"), 500)],
|
|
56
|
+
["version", xdr2.lookup("Uint32")],
|
|
57
|
+
["ext", xdr2.lookup("BundleExt")]
|
|
58
|
+
]);
|
|
59
|
+
xdr2.union("BundleEnvelope", {
|
|
60
|
+
switchOn: xdr2.lookup("EnvelopeType"),
|
|
61
|
+
switchName: "type",
|
|
62
|
+
switches: [["envelopeTypeBundle", "v1"]],
|
|
63
|
+
arms: {
|
|
64
|
+
v1: xdr2.lookup("Bundle")
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
);
|
|
67
69
|
|
|
68
70
|
exports.toLineItemProperty = toLineItemProperty;
|
|
69
71
|
//# sourceMappingURL=bundle.js.map
|
|
@@ -1 +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":["config"],"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,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AACzE,QAAQ,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;AACnE,QAAQ,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;AACnE,QAAQ,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE;AAC3B,QAAQ,QAAQ,EAAE,IAAI,CAAC,QAAQ;AAC/B,QAAQ,GAAG,EAAE,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,IAAI,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7B,GAAG,CAAC;AACJ,EAAE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzC,EAAE,OAAO,GAAG,CAAC,cAAc,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC1E,CAAC;AACD,MAAM,GAAG,GAAGA,YAAM,
|
|
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":["config"],"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,G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,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACvC,KAAK,CAAC,CAAC;AACP,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;AACjC,MAAM,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;AAC3C,MAAM,UAAU,EAAE,MAAM;AACxB,MAAM,QAAQ,EAAE,CAAC,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;AAC9C,MAAM,IAAI,EAAE;AACZ,QAAQ,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;AACjC,OAAO;AACP,KAAK,CAAC,CAAC;AACP,GAAG;AACH,CAAC;;;;"}
|
package/dist/cjs/utils/init.js
CHANGED
|
@@ -44,7 +44,9 @@ function initRecharge(opt = {}) {
|
|
|
44
44
|
const hiddenOpts = opt;
|
|
45
45
|
const { storefrontAccessToken } = opt;
|
|
46
46
|
if (storefrontAccessToken && !storefrontAccessToken.startsWith("strfnt")) {
|
|
47
|
-
throw new Error(
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Incorrect storefront access token used. See https://storefront.rechargepayments.com/client/docs/getting_started/package_setup/#initialization-- for more information."
|
|
49
|
+
);
|
|
48
50
|
}
|
|
49
51
|
options.setOptions({
|
|
50
52
|
storeIdentifier: getStoreIdentifier(opt.storeIdentifier),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sources":["../../../src/utils/init.ts"],"sourcesContent":["import { resetCDNCache } from '../api/cdn';\nimport { StorefrontOptions, CRUDRequestOptions, GetRequestOptions, InitOptions } from '../types';\nimport { setOptions } from './options';\nimport { request } from './request';\n\nexport const api = {\n get<T>(url: string, requestOptions?: GetRequestOptions): Promise<T> {\n return request<T>('get', url, requestOptions);\n },\n post<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('post', url, requestOptions);\n },\n put<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('put', url, requestOptions);\n },\n delete<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('delete', url, requestOptions);\n },\n};\n\n/**\n * Uses passed in storeIdentifier, but if it's not passed in will try to infer it.\n * Currently it will only infer if we are in the context of a Shopify store. This will not infer headless or hosted yet.\n */\nfunction getStoreIdentifier(storeIdentifier?: string): string {\n if (storeIdentifier) {\n return storeIdentifier;\n }\n\n // Infer's when on Shopify store (non headless)\n if (window?.Shopify?.shop) {\n return window.Shopify.shop;\n }\n\n // Domain exists on hosted themes. If it doesn't for some reason, get the subdomain and create the identifier\n let domain = window?.domain;\n if (!domain) {\n const subdomain = location?.href\n .match(/(?:http[s]*:\\/\\/)*(.*?)\\.(?=admin\\.rechargeapps\\.com)/i)?.[1]\n .replace(/-sp$/, '');\n if (subdomain) {\n domain = `${subdomain}.myshopify.com`;\n }\n }\n\n // Infer's when on Recharge hosted\n if (domain) {\n return domain;\n }\n\n throw new Error(`No storeIdentifier was passed into init.`);\n}\n\nexport function initRecharge(opt: InitOptions = {}) {\n const hiddenOpts = opt as StorefrontOptions;\n const { storefrontAccessToken } = opt;\n if (storefrontAccessToken && !storefrontAccessToken.startsWith('strfnt')) {\n throw new Error(\n 'Incorrect storefront access token used. See https://storefront.rechargepayments.com/client/docs/getting_started/package_setup/#initialization-- for more information.'\n );\n }\n setOptions({\n storeIdentifier: getStoreIdentifier(opt.storeIdentifier),\n loginRetryFn: opt.loginRetryFn,\n storefrontAccessToken,\n environment: hiddenOpts.environment ? hiddenOpts.environment : 'prod',\n });\n\n // When init is called again, reset the cache to make sure we don't have the old cache around\n resetCDNCache();\n}\n"],"names":["request","setOptions","resetCDNCache"],"mappings":";;;;;;;;AAGY,MAAC,GAAG,GAAG;AACnB,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE;AAC3B,IAAI,OAAOA,eAAO,CAA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L,IAAI,IAAI,SAAS,EAAE;AACnB,MAAM,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAC5C,KAAK;AACL,GAAG;AACH,EAAE,IAAI,MAAM,EAAE;AACd,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,wCAAwC,CAAC,CAAC,CAAC;AAC9D,CAAC;AACM,SAAS,YAAY,CAAC,GAAG,GAAG,EAAE,EAAE;AACvC,EAAE,MAAM,UAAU,GAAG,GAAG,CAAC;AACzB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,GAAG,CAAC;AACxC,EAAE,IAAI,qBAAqB,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;AAC5E,IAAI,MAAM,IAAI,KAAK,
|
|
1
|
+
{"version":3,"file":"init.js","sources":["../../../src/utils/init.ts"],"sourcesContent":["import { resetCDNCache } from '../api/cdn';\nimport { StorefrontOptions, CRUDRequestOptions, GetRequestOptions, InitOptions } from '../types';\nimport { setOptions } from './options';\nimport { request } from './request';\n\nexport const api = {\n get<T>(url: string, requestOptions?: GetRequestOptions): Promise<T> {\n return request<T>('get', url, requestOptions);\n },\n post<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('post', url, requestOptions);\n },\n put<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('put', url, requestOptions);\n },\n delete<T>(url: string, requestOptions?: CRUDRequestOptions): Promise<T> {\n return request<T>('delete', url, requestOptions);\n },\n};\n\n/**\n * Uses passed in storeIdentifier, but if it's not passed in will try to infer it.\n * Currently it will only infer if we are in the context of a Shopify store. This will not infer headless or hosted yet.\n */\nfunction getStoreIdentifier(storeIdentifier?: string): string {\n if (storeIdentifier) {\n return storeIdentifier;\n }\n\n // Infer's when on Shopify store (non headless)\n if (window?.Shopify?.shop) {\n return window.Shopify.shop;\n }\n\n // Domain exists on hosted themes. If it doesn't for some reason, get the subdomain and create the identifier\n let domain = window?.domain;\n if (!domain) {\n const subdomain = location?.href\n .match(/(?:http[s]*:\\/\\/)*(.*?)\\.(?=admin\\.rechargeapps\\.com)/i)?.[1]\n .replace(/-sp$/, '');\n if (subdomain) {\n domain = `${subdomain}.myshopify.com`;\n }\n }\n\n // Infer's when on Recharge hosted\n if (domain) {\n return domain;\n }\n\n throw new Error(`No storeIdentifier was passed into init.`);\n}\n\nexport function initRecharge(opt: InitOptions = {}) {\n const hiddenOpts = opt as StorefrontOptions;\n const { storefrontAccessToken } = opt;\n if (storefrontAccessToken && !storefrontAccessToken.startsWith('strfnt')) {\n throw new Error(\n 'Incorrect storefront access token used. See https://storefront.rechargepayments.com/client/docs/getting_started/package_setup/#initialization-- for more information.'\n );\n }\n setOptions({\n storeIdentifier: getStoreIdentifier(opt.storeIdentifier),\n loginRetryFn: opt.loginRetryFn,\n storefrontAccessToken,\n environment: hiddenOpts.environment ? hiddenOpts.environment : 'prod',\n });\n\n // When init is called again, reset the cache to make sure we don't have the old cache around\n resetCDNCache();\n}\n"],"names":["request","setOptions","resetCDNCache"],"mappings":";;;;;;;;AAGY,MAAC,GAAG,GAAG;AACnB,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE;AAC3B,IAAI,OAAOA,eAAO,CAAC,KAAK,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;AAC/C,GAAG;AACH,EAAE,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE;AAC5B,IAAI,OAAOA,eAAO,CAAC,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;AAChD,GAAG;AACH,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE;AAC3B,IAAI,OAAOA,eAAO,CAAC,KAAK,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;AAC/C,GAAG;AACH,EAAE,MAAM,CAAC,GAAG,EAAE,cAAc,EAAE;AAC9B,IAAI,OAAOA,eAAO,CAAC,QAAQ,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AACxC,EAAE,IAAI,qBAAqB,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;AAC5E,IAAI,MAAM,IAAI,KAAK;AACnB,MAAM,uKAAuK;AAC7K,KAAK,CAAC;AACN,GAAG;AACH,EAAEC,kBAAU,CAAC;AACb,IAAI,eAAe,EAAE,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC;AAC5D,IAAI,YAAY,EAAE,GAAG,CAAC,YAAY;AAClC,IAAI,qBAAqB;AACzB,IAAI,WAAW,EAAE,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,GAAG,MAAM;AACzE,GAAG,CAAC,CAAC;AACL,EAAEC,iBAAa,EAAE,CAAC;AAClB;;;;;"}
|
package/dist/esm/api/address.js
CHANGED
|
@@ -20,15 +20,30 @@ function listAddresses(session, query) {
|
|
|
20
20
|
return rechargeApiRequest("get", `/addresses`, { query }, session);
|
|
21
21
|
}
|
|
22
22
|
async function getAddress(session, id, options) {
|
|
23
|
-
const { address } = await rechargeApiRequest(
|
|
23
|
+
const { address } = await rechargeApiRequest(
|
|
24
|
+
"get",
|
|
25
|
+
`/addresses`,
|
|
26
|
+
{ id, query: { include: options == null ? void 0 : options.include } },
|
|
27
|
+
session
|
|
28
|
+
);
|
|
24
29
|
return address;
|
|
25
30
|
}
|
|
26
31
|
async function createAddress(session, createRequest) {
|
|
27
|
-
const { address } = await rechargeApiRequest(
|
|
32
|
+
const { address } = await rechargeApiRequest(
|
|
33
|
+
"post",
|
|
34
|
+
`/addresses`,
|
|
35
|
+
{ data: __spreadValues({ customer_id: session.customerId ? Number(session.customerId) : void 0 }, createRequest) },
|
|
36
|
+
session
|
|
37
|
+
);
|
|
28
38
|
return address;
|
|
29
39
|
}
|
|
30
40
|
async function updateAddress(session, id, updateRequest) {
|
|
31
|
-
const { address } = await rechargeApiRequest(
|
|
41
|
+
const { address } = await rechargeApiRequest(
|
|
42
|
+
"put",
|
|
43
|
+
`/addresses`,
|
|
44
|
+
{ id, data: updateRequest },
|
|
45
|
+
session
|
|
46
|
+
);
|
|
32
47
|
return address;
|
|
33
48
|
}
|
|
34
49
|
async function applyDiscountToAddress(session, id, discountCode) {
|
|
@@ -41,15 +56,25 @@ function deleteAddress(session, id) {
|
|
|
41
56
|
return rechargeApiRequest("delete", `/addresses`, { id }, session);
|
|
42
57
|
}
|
|
43
58
|
async function mergeAddresses(session, mergeRequest) {
|
|
44
|
-
const { address } = await rechargeApiRequest(
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
const { address } = await rechargeApiRequest(
|
|
60
|
+
"post",
|
|
61
|
+
`/addresses/merge`,
|
|
62
|
+
{
|
|
63
|
+
data: mergeRequest
|
|
64
|
+
},
|
|
65
|
+
session
|
|
66
|
+
);
|
|
47
67
|
return address;
|
|
48
68
|
}
|
|
49
69
|
async function skipFutureCharge(session, id, skipRequest) {
|
|
50
|
-
const { charge } = await rechargeApiRequest(
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
const { charge } = await rechargeApiRequest(
|
|
71
|
+
"post",
|
|
72
|
+
`/addresses/${id}/charges/skip`,
|
|
73
|
+
{
|
|
74
|
+
data: skipRequest
|
|
75
|
+
},
|
|
76
|
+
session
|
|
77
|
+
);
|
|
53
78
|
return charge;
|
|
54
79
|
}
|
|
55
80
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sources":["../../../src/api/address.ts"],"sourcesContent":["import { rechargeApiRequest } from '../utils/request';\nimport {\n AddressResponse,\n AddressListParams,\n CreateAddressRequest,\n UpdateAddressRequest,\n AddressListResponse,\n MergeAddressesRequest,\n SkipFutureChargeAddressRequest,\n SkipFutureChargeAddressResponse,\n GetAddressOptions,\n} from '../types/address';\nimport { Session } from '../types/session';\n\n/** Returns all addresses from the store, or addresses for the customer given in the parameter. */\nexport function listAddresses(session: Session, query?: AddressListParams) {\n return rechargeApiRequest<AddressListResponse>('get', `/addresses`, { query }, session);\n}\n\n/** Retrieves address for customer based on specified address id. */\nexport async function getAddress(session: Session, id: string | number, options?: GetAddressOptions) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'get',\n `/addresses`,\n { id, query: { include: options?.include } },\n session\n );\n return address;\n}\n\n/** Create a new address for a customer. */\nexport async function createAddress(session: Session, createRequest: CreateAddressRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses`,\n { data: { customer_id: session.customerId ? Number(session.customerId) : undefined, ...createRequest } },\n session\n );\n return address;\n}\n\n/** Updates an existing address to match the specified parameters. */\nexport async function updateAddress(session: Session, id: string | number, updateRequest: UpdateAddressRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'put',\n `/addresses`,\n { id, data: updateRequest },\n session\n );\n return address;\n}\n\n/** Apply discount code to an address. Addresses are currently limited to a single discount. */\nexport async function applyDiscountToAddress(session: Session, id: string | number, discountCode: string) {\n return updateAddress(session, id, { discounts: [{ code: discountCode }] });\n}\n\n/** Removes all discounts from an address. */\nexport async function removeDiscountsFromAddress(session: Session, id: string | number) {\n return updateAddress(session, id, { discounts: [] });\n}\n\n/** Deletes an address. Only Addresses with no active Subscriptions can be deleted. */\nexport function deleteAddress(session: Session, id: string | number) {\n return rechargeApiRequest<void>('delete', `/addresses`, { id }, session);\n}\n\n/**\n * Merges up to 10 source addresses into 1 target address.\n */\nexport async function mergeAddresses(session: Session, mergeRequest: MergeAddressesRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses/merge`,\n {\n data: mergeRequest,\n },\n session\n );\n return address;\n}\n\n/**\n * Skip a Charge in the future for one or multiple Subscriptions associated with the Address.\n */\nexport async function skipFutureCharge(\n session: Session,\n id: string | number,\n skipRequest: SkipFutureChargeAddressRequest\n) {\n const { charge } = await rechargeApiRequest<SkipFutureChargeAddressResponse>(\n 'post',\n `/addresses/${id}/charges/skip`,\n {\n data: skipRequest,\n },\n session\n );\n return charge;\n}\n"],"names":[],"mappings":";;AAAA,IAAI,SAAS,GA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AACM,eAAe,UAAU,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;AACvD,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"address.js","sources":["../../../src/api/address.ts"],"sourcesContent":["import { rechargeApiRequest } from '../utils/request';\nimport {\n AddressResponse,\n AddressListParams,\n CreateAddressRequest,\n UpdateAddressRequest,\n AddressListResponse,\n MergeAddressesRequest,\n SkipFutureChargeAddressRequest,\n SkipFutureChargeAddressResponse,\n GetAddressOptions,\n} from '../types/address';\nimport { Session } from '../types/session';\n\n/** Returns all addresses from the store, or addresses for the customer given in the parameter. */\nexport function listAddresses(session: Session, query?: AddressListParams) {\n return rechargeApiRequest<AddressListResponse>('get', `/addresses`, { query }, session);\n}\n\n/** Retrieves address for customer based on specified address id. */\nexport async function getAddress(session: Session, id: string | number, options?: GetAddressOptions) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'get',\n `/addresses`,\n { id, query: { include: options?.include } },\n session\n );\n return address;\n}\n\n/** Create a new address for a customer. */\nexport async function createAddress(session: Session, createRequest: CreateAddressRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses`,\n { data: { customer_id: session.customerId ? Number(session.customerId) : undefined, ...createRequest } },\n session\n );\n return address;\n}\n\n/** Updates an existing address to match the specified parameters. */\nexport async function updateAddress(session: Session, id: string | number, updateRequest: UpdateAddressRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'put',\n `/addresses`,\n { id, data: updateRequest },\n session\n );\n return address;\n}\n\n/** Apply discount code to an address. Addresses are currently limited to a single discount. */\nexport async function applyDiscountToAddress(session: Session, id: string | number, discountCode: string) {\n return updateAddress(session, id, { discounts: [{ code: discountCode }] });\n}\n\n/** Removes all discounts from an address. */\nexport async function removeDiscountsFromAddress(session: Session, id: string | number) {\n return updateAddress(session, id, { discounts: [] });\n}\n\n/** Deletes an address. Only Addresses with no active Subscriptions can be deleted. */\nexport function deleteAddress(session: Session, id: string | number) {\n return rechargeApiRequest<void>('delete', `/addresses`, { id }, session);\n}\n\n/**\n * Merges up to 10 source addresses into 1 target address.\n */\nexport async function mergeAddresses(session: Session, mergeRequest: MergeAddressesRequest) {\n const { address } = await rechargeApiRequest<AddressResponse>(\n 'post',\n `/addresses/merge`,\n {\n data: mergeRequest,\n },\n session\n );\n return address;\n}\n\n/**\n * Skip a Charge in the future for one or multiple Subscriptions associated with the Address.\n */\nexport async function skipFutureCharge(\n session: Session,\n id: string | number,\n skipRequest: SkipFutureChargeAddressRequest\n) {\n const { charge } = await rechargeApiRequest<SkipFutureChargeAddressResponse>(\n 'post',\n `/addresses/${id}/charges/skip`,\n {\n data: skipRequest,\n },\n session\n );\n return charge;\n}\n"],"names":[],"mappings":";;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,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,CA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;AACjE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB;AAC7C,IAAI,MAAM;AACV,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC;AACnC,IAAI;AACJ,MAAM,IAAI,EAAE,WAAW;AACvB,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
package/dist/esm/api/auth.js
CHANGED
|
@@ -64,15 +64,14 @@ async function sendPasswordlessCode(email, options = {}) {
|
|
|
64
64
|
return response.session_token;
|
|
65
65
|
}
|
|
66
66
|
async function sendPasswordlessCodeAppProxy(email, options = {}) {
|
|
67
|
-
const { storefrontAccessToken
|
|
67
|
+
const { storefrontAccessToken } = getOptions();
|
|
68
68
|
const headers = {};
|
|
69
69
|
if (storefrontAccessToken) {
|
|
70
70
|
headers["X-Recharge-Storefront-Access-Token"] = storefrontAccessToken;
|
|
71
71
|
}
|
|
72
72
|
const response = await shopifyAppProxyRequest("post", "/attempt_login", {
|
|
73
73
|
data: __spreadValues({
|
|
74
|
-
email
|
|
75
|
-
shop: storeIdentifier
|
|
74
|
+
email
|
|
76
75
|
}, options),
|
|
77
76
|
headers
|
|
78
77
|
});
|
|
@@ -103,7 +102,7 @@ async function validatePasswordlessCode(email, session_token, code) {
|
|
|
103
102
|
return { apiToken: response.api_token, customerId: response.customer_id };
|
|
104
103
|
}
|
|
105
104
|
async function validatePasswordlessCodeAppProxy(email, session_token, code) {
|
|
106
|
-
const { storefrontAccessToken
|
|
105
|
+
const { storefrontAccessToken } = getOptions();
|
|
107
106
|
const headers = {};
|
|
108
107
|
if (storefrontAccessToken) {
|
|
109
108
|
headers["X-Recharge-Storefront-Access-Token"] = storefrontAccessToken;
|
|
@@ -112,8 +111,7 @@ async function validatePasswordlessCodeAppProxy(email, session_token, code) {
|
|
|
112
111
|
data: {
|
|
113
112
|
code,
|
|
114
113
|
email,
|
|
115
|
-
session_token
|
|
116
|
-
shop: storeIdentifier
|
|
114
|
+
session_token
|
|
117
115
|
},
|
|
118
116
|
headers
|
|
119
117
|
});
|
|
@@ -122,6 +120,35 @@ async function validatePasswordlessCodeAppProxy(email, session_token, code) {
|
|
|
122
120
|
}
|
|
123
121
|
return { apiToken: response.api_token, customerId: response.customer_id };
|
|
124
122
|
}
|
|
123
|
+
function getCustomerParams() {
|
|
124
|
+
const { pathname, search } = window.location;
|
|
125
|
+
const urlParams = new URLSearchParams(search);
|
|
126
|
+
const token = urlParams.get("token");
|
|
127
|
+
const subpaths = pathname.split("/").filter(Boolean);
|
|
128
|
+
const portalIndex = subpaths.findIndex((path) => path === "portal");
|
|
129
|
+
const customerHash = portalIndex !== -1 ? subpaths[portalIndex + 1] : void 0;
|
|
130
|
+
if (!token || !customerHash) {
|
|
131
|
+
throw new Error("URL did not contain correct params");
|
|
132
|
+
}
|
|
133
|
+
return { customerHash, token };
|
|
134
|
+
}
|
|
135
|
+
async function loginCustomerPortal() {
|
|
136
|
+
const { customerHash, token } = getCustomerParams();
|
|
137
|
+
const { environment, storefrontAccessToken, storeIdentifier } = getOptions();
|
|
138
|
+
const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);
|
|
139
|
+
const headers = {};
|
|
140
|
+
if (storefrontAccessToken) {
|
|
141
|
+
headers["X-Recharge-Storefront-Access-Token"] = storefrontAccessToken;
|
|
142
|
+
}
|
|
143
|
+
const response = await request("post", `${rechargeBaseUrl}/customers/${customerHash}/access`, {
|
|
144
|
+
headers,
|
|
145
|
+
data: {
|
|
146
|
+
token,
|
|
147
|
+
shop: storeIdentifier
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return { apiToken: response.api_token, customerId: response.customer_id };
|
|
151
|
+
}
|
|
125
152
|
|
|
126
|
-
export { loginShopifyApi, loginShopifyAppProxy, sendPasswordlessCode, sendPasswordlessCodeAppProxy, validatePasswordlessCode, validatePasswordlessCodeAppProxy };
|
|
153
|
+
export { loginCustomerPortal, loginShopifyApi, loginShopifyAppProxy, sendPasswordlessCode, sendPasswordlessCodeAppProxy, validatePasswordlessCode, validatePasswordlessCodeAppProxy };
|
|
127
154
|
//# sourceMappingURL=auth.js.map
|
package/dist/esm/api/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sources":["../../../src/api/auth.ts"],"sourcesContent":["import { request as baseRequest, shopifyAppProxyRequest } from '../utils/request';\nimport {\n LoginResponse,\n PasswordlessCodeResponse,\n PasswordlessOptions,\n PasswordlessValidateResponse,\n} from '../types/auth';\nimport { getOptions } from '../utils/options';\nimport { RECHARGE_ADMIN_URL } from '../constants/api';\nimport { Session } from '../types/session';\nimport { RequestHeaders } from '../types';\n\nexport async function loginShopifyAppProxy(): Promise<Session> {\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<LoginResponse>('get', '/access', { headers });\n\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nexport async function loginShopifyApi(\n shopifyStorefrontToken: string,\n shopifyCustomerAccessToken?: string\n): Promise<Session | null> {\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<LoginResponse>('post', `${rechargeBaseUrl}/shopify_storefront_access`, {\n data: {\n customer_token: shopifyCustomerAccessToken,\n storefront_token: shopifyStorefrontToken,\n shop_url: storeIdentifier,\n },\n headers,\n });\n\n return response.api_token ? { apiToken: response.api_token, customerId: response.customer_id } : null;\n}\n\nexport async function sendPasswordlessCode(email: string, options: PasswordlessOptions = {}): Promise<string> {\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<PasswordlessCodeResponse>('post', `${rechargeBaseUrl}/attempt_login`, {\n data: {\n email,\n shop: storeIdentifier,\n ...options,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function sendPasswordlessCodeAppProxy(email: string, options: PasswordlessOptions = {}): Promise<string> {\n const { storefrontAccessToken, storeIdentifier } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<PasswordlessCodeResponse>('post', '/attempt_login', {\n data: {\n email,\n shop: storeIdentifier,\n ...options,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function validatePasswordlessCode(email: string, session_token: string, code: string): Promise<Session> {\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<PasswordlessValidateResponse>('post', `${rechargeBaseUrl}/validate_login`, {\n data: {\n code,\n email,\n session_token,\n shop: storeIdentifier,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nexport async function validatePasswordlessCodeAppProxy(\n email: string,\n session_token: string,\n code: string\n): Promise<Session> {\n const { storefrontAccessToken, storeIdentifier } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<PasswordlessValidateResponse>('post', '/validate_login', {\n data: {\n code,\n email,\n session_token,\n shop: storeIdentifier,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n"],"names":["baseRequest"],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,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;AAIK,eAAe,oBAAoB,GAAG;AAC7C,EAAE,MAAM,EAAE,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,MAAM,OAAO,GAAG,EAAE,CAAC;AACrB,EAAE,IAAI,qBAAqB,EAAE;AAC7B,IAAI,OAAO,CAAC,oCAAoC,CAAC,GAAG,qBAAqB,CAAC;AAC1E,GAAG;AACH,EAAE,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,MAAM,EAAE,iBAAiB,EAAE;AAC3E,IAAI,IAAI,EAAE;AACV,MAAM,IAAI;AACV,MAAM,KAAK;AACX,MAAM,aAAa;AACnB,MAAM,IAAI,EAAE,eAAe;AAC3B,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC,CAAC;AACL,EAAE,IAAI,QAAQ,CAAC,MAAM,EAAE;AACvB,IAAI,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,GAAG;AACH,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;AAC5E;;;;"}
|
|
1
|
+
{"version":3,"file":"auth.js","sources":["../../../src/api/auth.ts"],"sourcesContent":["import { request as baseRequest, shopifyAppProxyRequest } from '../utils/request';\nimport {\n LoginResponse,\n PasswordlessCodeResponse,\n PasswordlessOptions,\n PasswordlessValidateResponse,\n} from '../types/auth';\nimport { getOptions } from '../utils/options';\nimport { RECHARGE_ADMIN_URL } from '../constants/api';\nimport { Session } from '../types/session';\nimport { RequestHeaders } from '../types';\n\nexport async function loginShopifyAppProxy(): Promise<Session> {\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<LoginResponse>('get', '/access', { headers });\n\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nexport async function loginShopifyApi(\n shopifyStorefrontToken: string,\n shopifyCustomerAccessToken?: string\n): Promise<Session | null> {\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<LoginResponse>('post', `${rechargeBaseUrl}/shopify_storefront_access`, {\n data: {\n customer_token: shopifyCustomerAccessToken,\n storefront_token: shopifyStorefrontToken,\n shop_url: storeIdentifier,\n },\n headers,\n });\n\n return response.api_token ? { apiToken: response.api_token, customerId: response.customer_id } : null;\n}\n\nexport async function sendPasswordlessCode(email: string, options: PasswordlessOptions = {}): Promise<string> {\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<PasswordlessCodeResponse>('post', `${rechargeBaseUrl}/attempt_login`, {\n data: {\n email,\n shop: storeIdentifier,\n ...options,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function sendPasswordlessCodeAppProxy(email: string, options: PasswordlessOptions = {}): Promise<string> {\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<PasswordlessCodeResponse>('post', '/attempt_login', {\n data: {\n email,\n ...options,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return response.session_token;\n}\n\nexport async function validatePasswordlessCode(email: string, session_token: string, code: string): Promise<Session> {\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<PasswordlessValidateResponse>('post', `${rechargeBaseUrl}/validate_login`, {\n data: {\n code,\n email,\n session_token,\n shop: storeIdentifier,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nexport async function validatePasswordlessCodeAppProxy(\n email: string,\n session_token: string,\n code: string\n): Promise<Session> {\n const { storefrontAccessToken } = getOptions();\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await shopifyAppProxyRequest<PasswordlessValidateResponse>('post', '/validate_login', {\n data: {\n code,\n email,\n session_token,\n },\n headers,\n });\n\n if (response.errors) {\n throw new Error(response.errors);\n }\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n\nfunction getCustomerParams() {\n const { pathname, search } = window.location;\n const urlParams = new URLSearchParams(search);\n const token = urlParams.get('token');\n const subpaths = pathname.split('/').filter(Boolean);\n const portalIndex = subpaths.findIndex(path => path === 'portal');\n const customerHash = portalIndex !== -1 ? subpaths[portalIndex + 1] : undefined;\n\n // make sure the URL contained the data we need\n if (!token || !customerHash) {\n throw new Error('URL did not contain correct params');\n }\n return { customerHash, token };\n}\n\n/** @internal */\nexport async function loginCustomerPortal(): Promise<Session> {\n const { customerHash, token } = getCustomerParams();\n const { environment, storefrontAccessToken, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const headers: RequestHeaders = {};\n if (storefrontAccessToken) {\n headers['X-Recharge-Storefront-Access-Token'] = storefrontAccessToken;\n }\n const response = await baseRequest<LoginResponse>('post', `${rechargeBaseUrl}/customers/${customerHash}/access`, {\n headers,\n data: {\n token,\n shop: storeIdentifier,\n },\n });\n\n return { apiToken: response.api_token, customerId: response.customer_id };\n}\n"],"names":["baseRequest"],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACv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qB,EAAE,eAAe,EAAE,GAAG,UAAU,EAAE,CAAC;AAC/E,EAAE,MAAM,eAAe,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;AAC1D,EAAE,MAAM,OAAO,GAAG,EAAE,CAAC;AACrB,EAAE,IAAI,qBAAqB,EAAE;AAC7B,IAAI,OAAO,CAAC,oCAAoC,CAAC,GAAG,qBAAqB,CAAC;AAC1E,GAAG;AACH,EAAE,MAAM,QAAQ,GAAG,MAAMA,OAAW,CAAC,MAAM,EAAE,CAAC,EAAE,eAAe,CAAC,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE;AACpG,IAAI,OAAO;AACX,IAAI,IAAI,EAAE;AACV,MAAM,KAAK;AACX,MAAM,IAAI,EAAE,eAAe;AAC3B,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;AAC5E;;;;"}
|
package/dist/esm/api/bundle.js
CHANGED
|
@@ -40,14 +40,18 @@ async function getBundleId(bundle) {
|
|
|
40
40
|
})
|
|
41
41
|
});
|
|
42
42
|
try {
|
|
43
|
-
const payload = await shopifyAppProxyRequest(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const payload = await shopifyAppProxyRequest(
|
|
44
|
+
"post",
|
|
45
|
+
`${STORE_FRONT_MANAGER_URL}/api/v1/bundles`,
|
|
46
|
+
{
|
|
47
|
+
data: {
|
|
48
|
+
bundle: bundleData
|
|
49
|
+
},
|
|
50
|
+
headers: {
|
|
51
|
+
Origin: `https://${opts.storeIdentifier}`
|
|
52
|
+
}
|
|
49
53
|
}
|
|
50
|
-
|
|
54
|
+
);
|
|
51
55
|
if (!payload.id || payload.code !== 200) {
|
|
52
56
|
throw new Error(`1: failed generating rb_id: ${JSON.stringify(payload)}`);
|
|
53
57
|
}
|
|
@@ -132,32 +136,64 @@ function validateDynamicBundle(bundle) {
|
|
|
132
136
|
return true;
|
|
133
137
|
}
|
|
134
138
|
async function getBundleSelection(session, id) {
|
|
135
|
-
const { bundle_selection } = await rechargeApiRequest(
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
const { bundle_selection } = await rechargeApiRequest(
|
|
140
|
+
"get",
|
|
141
|
+
`/bundle_selections`,
|
|
142
|
+
{
|
|
143
|
+
id
|
|
144
|
+
},
|
|
145
|
+
session
|
|
146
|
+
);
|
|
138
147
|
return bundle_selection;
|
|
139
148
|
}
|
|
140
149
|
function listBundleSelections(session, query) {
|
|
141
150
|
return rechargeApiRequest("get", `/bundle_selections`, { query }, session);
|
|
142
151
|
}
|
|
143
152
|
async function createBundleSelection(session, createRequest) {
|
|
144
|
-
const { bundle_selection } = await rechargeApiRequest(
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
const { bundle_selection } = await rechargeApiRequest(
|
|
154
|
+
"post",
|
|
155
|
+
`/bundle_selections`,
|
|
156
|
+
{
|
|
157
|
+
data: createRequest
|
|
158
|
+
},
|
|
159
|
+
session
|
|
160
|
+
);
|
|
147
161
|
return bundle_selection;
|
|
148
162
|
}
|
|
149
163
|
async function updateBundleSelection(session, id, updateRequest) {
|
|
150
|
-
const { bundle_selection } = await rechargeApiRequest(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
164
|
+
const { bundle_selection } = await rechargeApiRequest(
|
|
165
|
+
"put",
|
|
166
|
+
`/bundle_selections`,
|
|
167
|
+
{
|
|
168
|
+
id,
|
|
169
|
+
data: updateRequest
|
|
170
|
+
},
|
|
171
|
+
session
|
|
172
|
+
);
|
|
154
173
|
return bundle_selection;
|
|
155
174
|
}
|
|
156
175
|
function deleteBundleSelection(session, id) {
|
|
157
|
-
return rechargeApiRequest(
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
return rechargeApiRequest(
|
|
177
|
+
"delete",
|
|
178
|
+
`/bundle_selections`,
|
|
179
|
+
{
|
|
180
|
+
id
|
|
181
|
+
},
|
|
182
|
+
session
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
async function updateBundle(session, purchase_item_id, updateRequest) {
|
|
186
|
+
const { subscription } = await rechargeApiRequest(
|
|
187
|
+
"put",
|
|
188
|
+
"/bundles",
|
|
189
|
+
{
|
|
190
|
+
id: purchase_item_id,
|
|
191
|
+
data: updateRequest
|
|
192
|
+
},
|
|
193
|
+
session
|
|
194
|
+
);
|
|
195
|
+
return subscription;
|
|
160
196
|
}
|
|
161
197
|
|
|
162
|
-
export { createBundleSelection, deleteBundleSelection, getBundleId, getBundleSelection, getDynamicBundleItems, listBundleSelections, updateBundleSelection, validateBundle, validateDynamicBundle };
|
|
198
|
+
export { createBundleSelection, deleteBundleSelection, getBundleId, getBundleSelection, getDynamicBundleItems, listBundleSelections, updateBundle, updateBundleSelection, validateBundle, validateDynamicBundle };
|
|
163
199
|
//# sourceMappingURL=bundle.js.map
|