@rechargeapps/storefront-client 0.15.1 → 0.15.2
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 +45 -0
- package/dist/cjs/api/address.js.map +1 -0
- package/dist/cjs/api/auth.js +36 -0
- package/dist/cjs/api/auth.js.map +1 -0
- package/dist/cjs/api/bundle.js +74 -0
- package/dist/cjs/api/bundle.js.map +1 -0
- package/dist/cjs/api/cdn.js +85 -0
- package/dist/cjs/api/cdn.js.map +1 -0
- package/dist/cjs/api/charge.js +44 -0
- package/dist/cjs/api/charge.js.map +1 -0
- package/dist/cjs/api/customer.js +38 -0
- package/dist/cjs/api/customer.js.map +1 -0
- package/dist/cjs/api/membership.js +31 -0
- package/dist/cjs/api/membership.js.map +1 -0
- package/dist/cjs/api/onetime.js +40 -0
- package/dist/cjs/api/onetime.js.map +1 -0
- package/dist/cjs/api/order.js +19 -0
- package/dist/cjs/api/order.js.map +1 -0
- package/dist/cjs/api/paymentMethod.js +27 -0
- package/dist/cjs/api/paymentMethod.js.map +1 -0
- package/dist/cjs/api/plan.js +19 -0
- package/dist/cjs/api/plan.js.map +1 -0
- package/dist/cjs/api/subscription.js +71 -0
- package/dist/cjs/api/subscription.js.map +1 -0
- package/dist/cjs/constants/api.js +14 -0
- package/dist/cjs/constants/api.js.map +1 -0
- package/dist/cjs/index.js +77 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mappers/cdn.js +67 -0
- package/dist/cjs/mappers/cdn.js.map +1 -0
- package/dist/cjs/mappers/utils.js +38 -0
- package/dist/cjs/mappers/utils.js.map +1 -0
- package/dist/cjs/utils/init.js +55 -0
- package/dist/cjs/utils/init.js.map +1 -0
- package/dist/cjs/utils/options.js +18 -0
- package/dist/cjs/utils/options.js.map +1 -0
- package/dist/cjs/utils/request.js +98 -0
- package/dist/cjs/utils/request.js.map +1 -0
- package/dist/esm/api/address.js +35 -0
- package/dist/esm/api/address.js.map +1 -0
- package/dist/esm/api/auth.js +31 -0
- package/dist/esm/api/auth.js.map +1 -0
- package/dist/esm/api/bundle.js +69 -0
- package/dist/esm/api/bundle.js.map +1 -0
- package/dist/esm/api/cdn.js +74 -0
- package/dist/esm/api/cdn.js.map +1 -0
- package/dist/esm/api/charge.js +34 -0
- package/dist/esm/api/charge.js.map +1 -0
- package/dist/esm/api/customer.js +32 -0
- package/dist/esm/api/customer.js.map +1 -0
- package/dist/esm/api/membership.js +24 -0
- package/dist/esm/api/membership.js.map +1 -0
- package/dist/esm/api/onetime.js +32 -0
- package/dist/esm/api/onetime.js.map +1 -0
- package/dist/esm/api/order.js +14 -0
- package/dist/esm/api/order.js.map +1 -0
- package/dist/esm/api/paymentMethod.js +21 -0
- package/dist/esm/api/paymentMethod.js.map +1 -0
- package/dist/esm/api/plan.js +14 -0
- package/dist/esm/api/plan.js.map +1 -0
- package/dist/esm/api/subscription.js +59 -0
- package/dist/esm/api/subscription.js.map +1 -0
- package/dist/esm/constants/api.js +7 -0
- package/dist/esm/constants/api.js.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/mappers/cdn.js +57 -0
- package/dist/esm/mappers/cdn.js.map +1 -0
- package/dist/esm/mappers/utils.js +34 -0
- package/dist/esm/mappers/utils.js.map +1 -0
- package/dist/esm/utils/init.js +50 -0
- package/dist/esm/utils/init.js.map +1 -0
- package/dist/esm/utils/options.js +13 -0
- package/dist/esm/utils/options.js.map +1 -0
- package/dist/esm/utils/request.js +91 -0
- package/dist/esm/utils/request.js.map +1 -0
- package/dist/index.d.ts +1486 -0
- package/dist/umd/recharge-client.min.js +28 -0
- package/package.json +2 -2
|
@@ -0,0 +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} from '../types/subscription';\nimport { IsoDateString } from '../types/common';\nimport { Session } from '../types/session';\nimport { ChargeResponse } from '../types';\n\nexport async function getSubscription(session: Session, id: string | number): Promise<Subscription> {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'get',\n `/subscriptions`,\n {\n id,\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\n );\n return charge;\n}\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACO,eAAe,eAAe,CAAC,OAAO,EAAE,EAAE,EAAE;AACnD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB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e,CAAC,EAAE;AACnG,IAAI,IAAI,EAAE,EAAE,UAAU,EAAE;AACxB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,kBAAkB,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE;AACrE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;AAC3F,IAAI,IAAI,EAAE,aAAa;AACvB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,oBAAoB,CAAC,OAAO,EAAE,EAAE,EAAE;AACxD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC1G,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AACM,eAAe,sBAAsB,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE;AAChE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE;AAC3F,IAAI,IAAI,EAAE;AACV,MAAM,IAAI;AACV,MAAM,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9B,KAAK;AACL,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const RECHARGE_API_URL = (environment) => environment === "stage" ? "https://api.stage.rechargeapps.com" : "https://api.rechargeapps.com";
|
|
6
|
+
const RECHARGE_ADMIN_URL = (environment) => environment === "stage" ? "https://admin.stage.rechargeapps.com" : "https://admin.rechargeapps.com";
|
|
7
|
+
const RECHARGE_CDN_URL = (environment) => environment === "stage" ? "https://static.stage.rechargecdn.com" : "https://static.rechargecdn.com";
|
|
8
|
+
const SHOPIFY_APP_PROXY_URL = "/tools/recurring";
|
|
9
|
+
|
|
10
|
+
exports.RECHARGE_ADMIN_URL = RECHARGE_ADMIN_URL;
|
|
11
|
+
exports.RECHARGE_API_URL = RECHARGE_API_URL;
|
|
12
|
+
exports.RECHARGE_CDN_URL = RECHARGE_CDN_URL;
|
|
13
|
+
exports.SHOPIFY_APP_PROXY_URL = SHOPIFY_APP_PROXY_URL;
|
|
14
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sources":["../../../src/constants/api.ts"],"sourcesContent":["export const RECHARGE_API_URL = (environment: 'stage' | 'prod'): string =>\n environment === 'stage' ? 'https://api.stage.rechargeapps.com' : 'https://api.rechargeapps.com';\nexport const RECHARGE_ADMIN_URL = (environment: 'stage' | 'prod'): string =>\n environment === 'stage' ? 'https://admin.stage.rechargeapps.com' : 'https://admin.rechargeapps.com';\nexport const RECHARGE_CDN_URL = (environment: 'stage' | 'prod'): string =>\n environment === 'stage' ? 'https://static.stage.rechargecdn.com' : 'https://static.rechargecdn.com';\nexport const RECHARGE_HOSTED_DOMAIN = '.admin.rechargeapps.com';\nexport const SHOPIFY_EMBEDDED_DOMAIN = '.myshopify.com';\nexport const SHOPIFY_APP_PROXY_URL = '/tools/recurring';\n"],"names":[],"mappings":";;;;AAAY,MAAC,gBAAgB,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,OAAO,GAAG,oCAAoC,GAAG,+BAA+B;AACrI,MAAC,kBAAkB,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,OAAO,GAAG,sCAAsC,GAAG,iCAAiC;AAC3I,MAAC,gBAAgB,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,OAAO,GAAG,sCAAsC,GAAG,iCAAiC;AAGzI,MAAC,qBAAqB,GAAG;;;;;;;"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var address = require('./api/address.js');
|
|
6
|
+
var auth = require('./api/auth.js');
|
|
7
|
+
var charge = require('./api/charge.js');
|
|
8
|
+
var cdn = require('./api/cdn.js');
|
|
9
|
+
var bundle = require('./api/bundle.js');
|
|
10
|
+
var membership = require('./api/membership.js');
|
|
11
|
+
var onetime = require('./api/onetime.js');
|
|
12
|
+
var order = require('./api/order.js');
|
|
13
|
+
var paymentMethod = require('./api/paymentMethod.js');
|
|
14
|
+
var plan = require('./api/plan.js');
|
|
15
|
+
var subscription = require('./api/subscription.js');
|
|
16
|
+
var customer = require('./api/customer.js');
|
|
17
|
+
var init = require('./utils/init.js');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.createAddress = address.createAddress;
|
|
22
|
+
exports.deleteAddress = address.deleteAddress;
|
|
23
|
+
exports.getAddress = address.getAddress;
|
|
24
|
+
exports.listAddresses = address.listAddresses;
|
|
25
|
+
exports.mergeAddresses = address.mergeAddresses;
|
|
26
|
+
exports.skipFutureCharge = address.skipFutureCharge;
|
|
27
|
+
exports.updateAddress = address.updateAddress;
|
|
28
|
+
exports.loginShopifyApi = auth.loginShopifyApi;
|
|
29
|
+
exports.loginShopifyAppProxy = auth.loginShopifyAppProxy;
|
|
30
|
+
exports.applyDiscount = charge.applyDiscount;
|
|
31
|
+
exports.getCharge = charge.getCharge;
|
|
32
|
+
exports.listCharges = charge.listCharges;
|
|
33
|
+
exports.processCharge = charge.processCharge;
|
|
34
|
+
exports.removeDiscount = charge.removeDiscount;
|
|
35
|
+
exports.skipCharge = charge.skipCharge;
|
|
36
|
+
exports.unskipCharge = charge.unskipCharge;
|
|
37
|
+
exports.getCDNBundleSettings = cdn.getCDNBundleSettings;
|
|
38
|
+
exports.getCDNProduct = cdn.getCDNProduct;
|
|
39
|
+
exports.getCDNProductAndSettings = cdn.getCDNProductAndSettings;
|
|
40
|
+
exports.getCDNProducts = cdn.getCDNProducts;
|
|
41
|
+
exports.getCDNProductsAndSettings = cdn.getCDNProductsAndSettings;
|
|
42
|
+
exports.getCDNStoreSettings = cdn.getCDNStoreSettings;
|
|
43
|
+
exports.getCDNWidgetSettings = cdn.getCDNWidgetSettings;
|
|
44
|
+
exports.resetCDNCache = cdn.resetCDNCache;
|
|
45
|
+
exports.getBundleId = bundle.getBundleId;
|
|
46
|
+
exports.validateBundle = bundle.validateBundle;
|
|
47
|
+
exports.activateMembership = membership.activateMembership;
|
|
48
|
+
exports.cancelMembership = membership.cancelMembership;
|
|
49
|
+
exports.getMembership = membership.getMembership;
|
|
50
|
+
exports.listMemberships = membership.listMemberships;
|
|
51
|
+
exports.createOnetime = onetime.createOnetime;
|
|
52
|
+
exports.deleteOnetime = onetime.deleteOnetime;
|
|
53
|
+
exports.getOnetime = onetime.getOnetime;
|
|
54
|
+
exports.listOnetimes = onetime.listOnetimes;
|
|
55
|
+
exports.updateOnetime = onetime.updateOnetime;
|
|
56
|
+
exports.getOrder = order.getOrder;
|
|
57
|
+
exports.listOrders = order.listOrders;
|
|
58
|
+
exports.getPaymentMethod = paymentMethod.getPaymentMethod;
|
|
59
|
+
exports.listPaymentMethods = paymentMethod.listPaymentMethods;
|
|
60
|
+
exports.updatePaymentMethod = paymentMethod.updatePaymentMethod;
|
|
61
|
+
exports.getPlan = plan.getPlan;
|
|
62
|
+
exports.listPlans = plan.listPlans;
|
|
63
|
+
exports.activateSubscription = subscription.activateSubscription;
|
|
64
|
+
exports.cancelSubscription = subscription.cancelSubscription;
|
|
65
|
+
exports.createSubscription = subscription.createSubscription;
|
|
66
|
+
exports.getSubscription = subscription.getSubscription;
|
|
67
|
+
exports.listSubscriptions = subscription.listSubscriptions;
|
|
68
|
+
exports.skipSubscriptionCharge = subscription.skipSubscriptionCharge;
|
|
69
|
+
exports.updateSubscription = subscription.updateSubscription;
|
|
70
|
+
exports.updateSubscriptionAddress = subscription.updateSubscriptionAddress;
|
|
71
|
+
exports.updateSubscriptionChargeDate = subscription.updateSubscriptionChargeDate;
|
|
72
|
+
exports.getCustomer = customer.getCustomer;
|
|
73
|
+
exports.getDeliverySchedule = customer.getDeliverySchedule;
|
|
74
|
+
exports.updateCustomer = customer.updateCustomer;
|
|
75
|
+
exports.api = init.api;
|
|
76
|
+
exports.initRecharge = init.initRecharge;
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var omit = require('lodash/omit');
|
|
6
|
+
var utils = require('./utils.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defProps = Object.defineProperties;
|
|
14
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
15
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
19
|
+
var __spreadValues = (a, b) => {
|
|
20
|
+
for (var prop in b || (b = {}))
|
|
21
|
+
if (__hasOwnProp.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
if (__getOwnPropSymbols)
|
|
24
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
25
|
+
if (__propIsEnum.call(b, prop))
|
|
26
|
+
__defNormalProp(a, prop, b[prop]);
|
|
27
|
+
}
|
|
28
|
+
return a;
|
|
29
|
+
};
|
|
30
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
31
|
+
function widgetSettingsMapper(widgetSettingsRaw) {
|
|
32
|
+
var _a;
|
|
33
|
+
const parsedSettings = utils.parseValues(widgetSettingsRaw);
|
|
34
|
+
const auto_inject = parsedSettings.auto_inject === void 0 ? true : parsedSettings.auto_inject;
|
|
35
|
+
const valid_pages = (_a = parsedSettings.display_on) != null ? _a : [];
|
|
36
|
+
const is_subscription_first = parsedSettings.first_option === "autodeliver";
|
|
37
|
+
return __spreadProps(__spreadValues({}, omit__default["default"](parsedSettings, ["display_on", "first_option"])), {
|
|
38
|
+
auto_inject,
|
|
39
|
+
valid_pages,
|
|
40
|
+
is_subscription_first,
|
|
41
|
+
autoInject: auto_inject,
|
|
42
|
+
validPages: valid_pages,
|
|
43
|
+
isSubscriptionFirst: is_subscription_first
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function productMapper(productRaw) {
|
|
47
|
+
var _a;
|
|
48
|
+
const is_subscription_only = ((_a = productRaw.subscription_options) == null ? void 0 : _a.storefront_purchase_options) === "subscription_only";
|
|
49
|
+
return __spreadProps(__spreadValues({}, productRaw), {
|
|
50
|
+
is_subscription_only,
|
|
51
|
+
isSubscriptionOnly: is_subscription_only
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function productArrayMapper(productsArray) {
|
|
55
|
+
return productsArray.map((productObjRaw) => {
|
|
56
|
+
const productObj = {};
|
|
57
|
+
Object.entries(productObjRaw).forEach(([key, value]) => {
|
|
58
|
+
productObj[key] = productMapper(value);
|
|
59
|
+
});
|
|
60
|
+
return productObj;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.productArrayMapper = productArrayMapper;
|
|
65
|
+
exports.productMapper = productMapper;
|
|
66
|
+
exports.widgetSettingsMapper = widgetSettingsMapper;
|
|
67
|
+
//# sourceMappingURL=cdn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cdn.js","sources":["../../../src/mappers/cdn.ts"],"sourcesContent":["import omit from 'lodash/omit';\nimport {\n CDNBaseWidgetSettings,\n CDNProductRaw,\n CDNWidgetSettings,\n CDNWidgetSettingsRaw,\n CDNProduct,\n CDNProductKeyObject,\n} from '../types';\nimport { parseValues } from './utils';\n\nexport function widgetSettingsMapper(widgetSettingsRaw: CDNWidgetSettingsRaw): CDNWidgetSettings {\n const parsedSettings = parseValues<CDNBaseWidgetSettings>(widgetSettingsRaw);\n\n const auto_inject = parsedSettings.auto_inject === undefined ? true : parsedSettings.auto_inject;\n const valid_pages = parsedSettings.display_on ?? [];\n const is_subscription_first = parsedSettings.first_option === 'autodeliver';\n\n return {\n ...omit(parsedSettings, ['display_on', 'first_option']),\n auto_inject,\n valid_pages,\n is_subscription_first,\n autoInject: auto_inject,\n validPages: valid_pages,\n isSubscriptionFirst: is_subscription_first,\n };\n}\n\nexport function productMapper(productRaw: CDNProductRaw): CDNProduct {\n const is_subscription_only = productRaw.subscription_options?.storefront_purchase_options === 'subscription_only';\n return {\n ...productRaw,\n is_subscription_only,\n isSubscriptionOnly: is_subscription_only,\n };\n}\n\nexport function productArrayMapper(\n productsArray: {\n [key: string]: CDNProductRaw;\n }[]\n): CDNProductKeyObject[] {\n return productsArray.map(productObjRaw => {\n const productObj: CDNProductKeyObject = {};\n Object.entries(productObjRaw).forEach(([key, value]) => {\n productOb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C,GAAG,CAAC,CAAC;AACL,CAAC;AACM,SAAS,kBAAkB,CAAC,aAAa,EAAE;AAClD,EAAE,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,aAAa,KAAK;AAC9C,IAAI,MAAM,UAAU,GAAG,EAAE,CAAC;AAC1B,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC5D,MAAM,UAAU,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAC7C,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,UAAU,CAAC;AACtB,GAAG,CAAC,CAAC;AACL;;;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defProps = Object.defineProperties;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
function parseValue(value) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function parseValues(json) {
|
|
32
|
+
return Object.entries(json).reduce((memo, [key, value]) => {
|
|
33
|
+
return __spreadProps(__spreadValues({}, memo), { [key]: parseValue(value) });
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.parseValues = parseValues;
|
|
38
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +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,Y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E,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjF,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var cdn = require('../api/cdn.js');
|
|
6
|
+
var options = require('./options.js');
|
|
7
|
+
var request = require('./request.js');
|
|
8
|
+
|
|
9
|
+
const api = {
|
|
10
|
+
get(url, requestOptions) {
|
|
11
|
+
return request.request("get", url, requestOptions);
|
|
12
|
+
},
|
|
13
|
+
post(url, requestOptions) {
|
|
14
|
+
return request.request("post", url, requestOptions);
|
|
15
|
+
},
|
|
16
|
+
put(url, requestOptions) {
|
|
17
|
+
return request.request("put", url, requestOptions);
|
|
18
|
+
},
|
|
19
|
+
delete(url, requestOptions) {
|
|
20
|
+
return request.request("delete", url, requestOptions);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function getStoreIdentifier(storeIdentifier) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (storeIdentifier) {
|
|
26
|
+
return storeIdentifier;
|
|
27
|
+
}
|
|
28
|
+
if ((_a = window == null ? void 0 : window.Shopify) == null ? void 0 : _a.shop) {
|
|
29
|
+
return window.Shopify.shop;
|
|
30
|
+
}
|
|
31
|
+
let domain = window == null ? void 0 : window.domain;
|
|
32
|
+
if (!domain) {
|
|
33
|
+
const subdomain = (_b = location == null ? void 0 : location.href.match(/(?:http[s]*:\/\/)*(.*?)\.(?=admin\.rechargeapps\.com)/i)) == null ? void 0 : _b[1].replace(/-sp$/, "");
|
|
34
|
+
if (subdomain) {
|
|
35
|
+
domain = `${subdomain}.myshopify.com`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (domain) {
|
|
39
|
+
return domain;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`No storeIdentifier was passed into init.`);
|
|
42
|
+
}
|
|
43
|
+
function initRecharge(opt = {}) {
|
|
44
|
+
const hiddenOpts = opt;
|
|
45
|
+
options.setOptions({
|
|
46
|
+
storeIdentifier: getStoreIdentifier(opt.storeIdentifier),
|
|
47
|
+
storefrontAccessToken: opt.storefrontAccessToken,
|
|
48
|
+
environment: hiddenOpts.environment ? hiddenOpts.environment : "prod"
|
|
49
|
+
});
|
|
50
|
+
cdn.resetCDNCache();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.api = api;
|
|
54
|
+
exports.initRecharge = initRecharge;
|
|
55
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +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 setOptions({\n storeIdentifier: getStoreIdentifier(opt.storeIdentifier),\n storefrontAccessToken: opt.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,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;AAClD,GAAG;AACH,EAAE;AACF,SAAS,kBAAkB,CAAC,eAAe,EAAE;AAC7C,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACb,EAAE,IAAI,eAAe,EAAE;AACvB,IAAI,OAAO,eAAe,CAAC;AAC3B,GAAG;AACH,EAAE,IAAI,CAAC,EAAE,GAAG,MAAM,IAA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|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
let options = {
|
|
6
|
+
storeIdentifier: "",
|
|
7
|
+
environment: "prod"
|
|
8
|
+
};
|
|
9
|
+
function setOptions(opts) {
|
|
10
|
+
options = opts;
|
|
11
|
+
}
|
|
12
|
+
function getOptions() {
|
|
13
|
+
return options;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.getOptions = getOptions;
|
|
17
|
+
exports.setOptions = setOptions;
|
|
18
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sources":["../../../src/utils/options.ts"],"sourcesContent":["import { StorefrontOptions } from '../types';\n\nlet options: StorefrontOptions = {\n storeIdentifier: '',\n environment: 'prod',\n};\n\nexport function setOptions(opts: StorefrontOptions) {\n options = opts;\n}\n\nexport function getOptions() {\n return options;\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,OAAO,GAAG;AACd,EAAE,eAAe,EAAE,EAAE;AACrB,EAAE,WAAW,EAAE,MAAM;AACrB,CAAC,CAAC;AACK,SAAS,UAAU,CAAC,IAAI,EAAE;AACjC,EAAE,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC;AACM,SAAS,UAAU,GAAG;AAC7B,EAAE,OAAO,OAAO,CAAC;AACjB;;;;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('isomorphic-fetch');
|
|
6
|
+
var qs = require('qs');
|
|
7
|
+
var options = require('./options.js');
|
|
8
|
+
var api = require('../constants/api.js');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
14
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __spreadValues = (a, b) => {
|
|
16
|
+
for (var prop in b || (b = {}))
|
|
17
|
+
if (__hasOwnProp.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
if (__getOwnPropSymbols)
|
|
20
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
21
|
+
if (__propIsEnum.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
function stringifyQuery(str) {
|
|
27
|
+
return qs.stringify(str, {
|
|
28
|
+
encode: false,
|
|
29
|
+
indices: false,
|
|
30
|
+
arrayFormat: "comma"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function cdnRequest(method, url, requestOptions = {}) {
|
|
34
|
+
const opts = options.getOptions();
|
|
35
|
+
return request(method, `${api.RECHARGE_CDN_URL(opts.environment)}/store/${opts.storeIdentifier}${url}`, requestOptions);
|
|
36
|
+
}
|
|
37
|
+
async function rechargeApiRequest(method, url, { id, query, data, headers } = {}, session) {
|
|
38
|
+
const { environment, storeIdentifier } = options.getOptions();
|
|
39
|
+
const token = session.apiToken;
|
|
40
|
+
const rechargeBaseUrl = api.RECHARGE_API_URL(environment);
|
|
41
|
+
const reqHeaders = __spreadValues({
|
|
42
|
+
"X-Recharge-Access-Token": token,
|
|
43
|
+
"X-Recharge-Version": "2021-11"
|
|
44
|
+
}, headers ? headers : {});
|
|
45
|
+
const localQuery = __spreadValues({
|
|
46
|
+
shop_url: storeIdentifier
|
|
47
|
+
}, query);
|
|
48
|
+
return request(method, `${rechargeBaseUrl}${url}`, { id, query: localQuery, data, headers: reqHeaders });
|
|
49
|
+
}
|
|
50
|
+
async function shopifyAppProxyRequest(method, url, requestOptions = {}) {
|
|
51
|
+
return request(method, `${api.SHOPIFY_APP_PROXY_URL}${url}`, requestOptions);
|
|
52
|
+
}
|
|
53
|
+
async function request(method, url, { id, query, data, headers } = {}) {
|
|
54
|
+
let reqUrl = url.trim();
|
|
55
|
+
if (id) {
|
|
56
|
+
reqUrl = [reqUrl, `${id}`.trim()].join("/");
|
|
57
|
+
}
|
|
58
|
+
if (query) {
|
|
59
|
+
let exQuery;
|
|
60
|
+
[reqUrl, exQuery] = reqUrl.split("?");
|
|
61
|
+
const fullQuery = [exQuery, stringifyQuery(query)].join("&").replace(/^&/, "");
|
|
62
|
+
reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ""}`;
|
|
63
|
+
}
|
|
64
|
+
let reqBody;
|
|
65
|
+
if (data && method !== "get") {
|
|
66
|
+
reqBody = JSON.stringify(data);
|
|
67
|
+
}
|
|
68
|
+
const reqHeaders = __spreadValues({
|
|
69
|
+
Accept: "application/json",
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
"X-Recharge-App": "storefront-client"
|
|
72
|
+
}, headers ? headers : {});
|
|
73
|
+
const response = await fetch(reqUrl, {
|
|
74
|
+
method,
|
|
75
|
+
headers: reqHeaders,
|
|
76
|
+
body: reqBody,
|
|
77
|
+
mode: "cors"
|
|
78
|
+
});
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
result = await response.json();
|
|
82
|
+
} catch (e) {
|
|
83
|
+
}
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
if (result && result.error) {
|
|
86
|
+
throw new Error(`${response.status}: ${result.error}`);
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error("A connection error occurred while making the request");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.cdnRequest = cdnRequest;
|
|
95
|
+
exports.rechargeApiRequest = rechargeApiRequest;
|
|
96
|
+
exports.request = request;
|
|
97
|
+
exports.shopifyAppProxyRequest = shopifyAppProxyRequest;
|
|
98
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sources":["../../../src/utils/request.ts"],"sourcesContent":["import 'isomorphic-fetch';\n\nimport { stringify } from 'qs';\n\nimport { Method, RequestHeaders, RequestOptions } from '../types';\nimport { getOptions } from './options';\nimport { RECHARGE_API_URL, RECHARGE_CDN_URL, SHOPIFY_APP_PROXY_URL } from '../constants/api';\nimport { Session } from '../types/session';\n\nfunction stringifyQuery(str: unknown): string {\n return stringify(str, {\n encode: false,\n indices: false,\n arrayFormat: 'comma',\n });\n}\n\nexport async function cdnRequest<T>(method: Method, url: string, requestOptions: RequestOptions = {}): Promise<T> {\n const opts = getOptions();\n return request(method, `${RECHARGE_CDN_URL(opts.environment)}/store/${opts.storeIdentifier}${url}`, requestOptions);\n}\n\nexport async function rechargeApiRequest<T>(\n method: Method,\n url: string,\n { id, query, data, headers }: RequestOptions = {},\n session: Session\n): Promise<T> {\n const { environment, storeIdentifier } = getOptions();\n const token = session.apiToken;\n const rechargeBaseUrl = RECHARGE_API_URL(environment);\n const reqHeaders: RequestHeaders = {\n 'X-Recharge-Access-Token': token,\n 'X-Recharge-Version': '2021-11',\n ...(headers ? headers : {}),\n };\n\n const localQuery = {\n shop_url: storeIdentifier,\n ...(query as any),\n };\n\n return request(method, `${rechargeBaseUrl}${url}`, { id, query: localQuery, data, headers: reqHeaders });\n}\n\nexport async function shopifyAppProxyRequest<T>(\n method: Method,\n url: string,\n requestOptions: RequestOptions = {}\n): Promise<T> {\n return request(method, `${SHOPIFY_APP_PROXY_URL}${url}`, requestOptions);\n}\n\nexport async function request<T>(\n method: Method,\n url: string,\n { id, query, data, headers }: RequestOptions = {}\n): Promise<T> {\n let reqUrl = url.trim();\n\n if (id) {\n reqUrl = [reqUrl, `${id}`.trim()].join('/');\n }\n\n if (query) {\n let exQuery;\n [reqUrl, exQuery] = reqUrl.split('?');\n const fullQuery = [exQuery, stringifyQuery(query)].join('&').replace(/^&/, '');\n reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ''}`;\n }\n\n let reqBody;\n if (data && method !== 'get') {\n reqBody = JSON.stringify(data);\n }\n\n const reqHeaders: RequestHeaders = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'X-Recharge-App': 'storefront-client',\n ...(headers ? headers : {}),\n };\n\n const response = await fetch(reqUrl, {\n method,\n headers: reqHeaders,\n body: reqBody,\n mode: 'cors',\n });\n\n let result;\n try {\n result = await response.json();\n } catch (e) {\n // If we get here, it means we were a no content response.\n }\n\n if (!response.ok) {\n if (result && result.error) {\n throw new Error(`${response.status}: ${result.error}`);\n } else {\n throw new Error('A connection error occurred while making the request');\n }\n }\n\n return result as T;\n}\n"],"names":["stringify","getOptions","RECHARGE_CDN_URL","RECHARGE_API_URL","SHOPIFY_APP_PROXY_URL"],"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,C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AAC,CAAC,CAAC;AAC7D,KAAK,MAAM;AACX,MAAM,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC9E,KAAK;AACL,GAAG;AACH,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { rechargeApiRequest } from '../utils/request.js';
|
|
2
|
+
|
|
3
|
+
function listAddresses(session, query) {
|
|
4
|
+
return rechargeApiRequest("get", `/addresses`, { query }, session);
|
|
5
|
+
}
|
|
6
|
+
async function getAddress(session, id) {
|
|
7
|
+
const { address } = await rechargeApiRequest("get", `/addresses`, { id }, session);
|
|
8
|
+
return address;
|
|
9
|
+
}
|
|
10
|
+
async function createAddress(session, createRequest) {
|
|
11
|
+
const { address } = await rechargeApiRequest("post", `/addresses`, { data: createRequest }, session);
|
|
12
|
+
return address;
|
|
13
|
+
}
|
|
14
|
+
async function updateAddress(session, id, updateRequest) {
|
|
15
|
+
const { address } = await rechargeApiRequest("put", `/addresses`, { id, data: updateRequest }, session);
|
|
16
|
+
return address;
|
|
17
|
+
}
|
|
18
|
+
function deleteAddress(session, id) {
|
|
19
|
+
return rechargeApiRequest("delete", `/addresses`, { id }, session);
|
|
20
|
+
}
|
|
21
|
+
async function mergeAddresses(session, mergeRequest) {
|
|
22
|
+
const { address } = await rechargeApiRequest("post", `/addresses/merge`, {
|
|
23
|
+
data: mergeRequest
|
|
24
|
+
}, session);
|
|
25
|
+
return address;
|
|
26
|
+
}
|
|
27
|
+
async function skipFutureCharge(session, id, skipRequest) {
|
|
28
|
+
const { charge } = await rechargeApiRequest("post", `/addresses/${id}/charges/skip`, {
|
|
29
|
+
data: skipRequest
|
|
30
|
+
}, session);
|
|
31
|
+
return charge;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { createAddress, deleteAddress, getAddress, listAddresses, mergeAddresses, skipFutureCharge, updateAddress };
|
|
35
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +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} 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) {\n const { address } = await rechargeApiRequest<AddressResponse>('get', `/addresses`, { id }, session);\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>('post', `/addresses`, { data: createRequest }, session);\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/** 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/${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AAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,gBAAgB,CAAC,EAAE;AAC3E,IAAI,IAAI,EAAE,YAAY;AACtB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB,CAAC;AACM,eAAe,gBAAgB,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE;AACjE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE;AACvF,IAAI,IAAI,EAAE,WAAW;AACrB,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { shopifyAppProxyRequest, request } from '../utils/request.js';
|
|
2
|
+
import { getOptions } from '../utils/options.js';
|
|
3
|
+
import { RECHARGE_ADMIN_URL } from '../constants/api.js';
|
|
4
|
+
|
|
5
|
+
async function loginShopifyAppProxy() {
|
|
6
|
+
const { storefrontAccessToken } = getOptions();
|
|
7
|
+
const headers = {};
|
|
8
|
+
if (storefrontAccessToken) {
|
|
9
|
+
headers["X-Recharge-Storefront-Access-Token"] = storefrontAccessToken;
|
|
10
|
+
}
|
|
11
|
+
const response = await shopifyAppProxyRequest("get", "/access", { headers });
|
|
12
|
+
return { apiToken: response.api_token, customerId: response.customer_id };
|
|
13
|
+
}
|
|
14
|
+
async function loginShopifyApi(customerAccessToken, storefrontAccessToken) {
|
|
15
|
+
const { environment, storeIdentifier } = getOptions();
|
|
16
|
+
const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);
|
|
17
|
+
const response = await request("post", `${rechargeBaseUrl}/shopify_storefront_access`, {
|
|
18
|
+
data: {
|
|
19
|
+
customer_token: customerAccessToken,
|
|
20
|
+
storefront_token: storefrontAccessToken,
|
|
21
|
+
shop_url: storeIdentifier
|
|
22
|
+
},
|
|
23
|
+
headers: {
|
|
24
|
+
"X-Recharge-App": "storefront-client"
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return response.api_token ? { apiToken: response.api_token, customerId: response.customer_id } : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { loginShopifyApi, loginShopifyAppProxy };
|
|
31
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sources":["../../../src/api/auth.ts"],"sourcesContent":["import { request as baseRequest, shopifyAppProxyRequest } from '../utils/request';\nimport { LoginResponse } 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 customerAccessToken: string,\n storefrontAccessToken: string\n): Promise<Session | null> {\n const { environment, storeIdentifier } = getOptions();\n const rechargeBaseUrl = RECHARGE_ADMIN_URL(environment);\n const response = await baseRequest<LoginResponse>('post', `${rechargeBaseUrl}/shopify_storefront_access`, {\n data: {\n customer_token: customerAccessToken,\n storefront_token: storefrontAccessToken,\n shop_url: storeIdentifier,\n },\n headers: {\n 'X-Recharge-App': 'storefront-client',\n },\n });\n\n return response.api_token ? { apiToken: response.api_token, customerId: response.customer_id } : null;\n}\n"],"names":["baseRequest"],"mappings":";;;;AAGO,eAAe,oBAAoB,GAAG;AAC7C,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,UAAU,EAAE,CAAC;AACjD,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,MAAM,sBAAsB,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/E,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC;AAC5E,CAAC;AACM,eAAe,eAAe,CAAC,mBAAmB,EAAE,qBAAqB,EAAE;AAClF,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,UAAU,EAAE,CAAC;AACxD,EAAE,MAAM,eAAe,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;AAC1D,EAAE,MAAM,QAAQ,GAAG,MAAMA,OAAW,CAAC,MAAM,EAAE,CAAC,EAAE,eAAe,CAAC,0BAA0B,CAAC,EAAE;AAC7F,IAAI,IAAI,EAAE;AACV,MAAM,cAAc,EAAE,mBAAmB;AACzC,MAAM,gBAAgB,EAAE,qBAAqB;AAC7C,MAAM,QAAQ,EAAE,eAAe;AAC/B,KAAK;AACL,IAAI,OAAO,EAAE;AACb,MAAM,gBAAgB,EAAE,mBAAmB;AAC3C,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,QAAQ,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC;AACxG;;;;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { toLineItemProperty } from '@rechargeapps/bundling-data';
|
|
2
|
+
import { shopifyAppProxyRequest } from '../utils/request.js';
|
|
3
|
+
import { getOptions } from '../utils/options.js';
|
|
4
|
+
import { getCDNBundleSettings } from './cdn.js';
|
|
5
|
+
|
|
6
|
+
const STORE_FRONT_MANAGER_URL = "/bundling-storefront-manager";
|
|
7
|
+
function getTimestampSecondsFromClient() {
|
|
8
|
+
return Math.ceil(Date.now() / 1e3);
|
|
9
|
+
}
|
|
10
|
+
async function getTimestampSecondsFromServer() {
|
|
11
|
+
try {
|
|
12
|
+
const { timestamp } = await shopifyAppProxyRequest("get", `${STORE_FRONT_MANAGER_URL}/t`, {
|
|
13
|
+
headers: { "X-Recharge-App": "storefront-client" }
|
|
14
|
+
});
|
|
15
|
+
return timestamp;
|
|
16
|
+
} catch (ex) {
|
|
17
|
+
console.error(`Fetch failed: ${ex}. Using client-side date.`);
|
|
18
|
+
return getTimestampSecondsFromClient();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function getBundleId(bundle) {
|
|
22
|
+
const opts = getOptions();
|
|
23
|
+
const isValid = await validateBundle(bundle);
|
|
24
|
+
if (!isValid) {
|
|
25
|
+
throw new Error("Bundle selection is invalid.");
|
|
26
|
+
}
|
|
27
|
+
const timestampSeconds = await getTimestampSecondsFromServer();
|
|
28
|
+
const bundleData = toLineItemProperty({
|
|
29
|
+
variantId: bundle.externalVariantId,
|
|
30
|
+
version: timestampSeconds,
|
|
31
|
+
items: bundle.selections.map((item) => {
|
|
32
|
+
return {
|
|
33
|
+
collectionId: item.collectionId,
|
|
34
|
+
productId: item.externalProductId,
|
|
35
|
+
variantId: item.externalVariantId,
|
|
36
|
+
quantity: item.quantity,
|
|
37
|
+
sku: ""
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
const payload = await shopifyAppProxyRequest("post", `${STORE_FRONT_MANAGER_URL}/api/v1/bundles`, {
|
|
43
|
+
data: {
|
|
44
|
+
bundle: bundleData
|
|
45
|
+
},
|
|
46
|
+
headers: {
|
|
47
|
+
Origin: `https://${opts.storeIdentifier}`
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!payload.id || payload.code !== 200) {
|
|
51
|
+
throw new Error(`1: failed generating rb_id: ${JSON.stringify(payload)}`);
|
|
52
|
+
}
|
|
53
|
+
return payload.id;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw new Error(`2: failed generating rb_id ${e}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function validateBundle(bundle) {
|
|
59
|
+
try {
|
|
60
|
+
const bundleSettings = await getCDNBundleSettings(bundle.externalProductId);
|
|
61
|
+
return !!bundle && !!bundleSettings;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error("Error fetching bundle settings");
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { getBundleId, validateBundle };
|
|
69
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sources":["../../../src/api/bundle.ts"],"sourcesContent":["import { toLineItemProperty } from '@rechargeapps/bundling-data';\nimport { Bundle } from '../types';\nimport { 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: Bundle): Promise<string> {\n const opts = getOptions();\n const isValid = await validateBundle(bundle);\n if (!isValid) {\n throw new Error('Bundle selection is invalid.');\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 async function validateBundle(bundle: Bundle): Promise<boolean> {\n try {\n const bundleSettings = await getCDNBundleSettings(bundle.externalProductId);\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 return !!bundle && !!bundleSettings;\n } catch (e) {\n console.error('Error fetching bundle settings');\n return false;\n }\n}\n"],"names":[],"mappings":";;;;;AAIA,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,uBAAuB,CAAC,EAAE,CAAC,EAAE;AAC9F,MAAM,OAAO,EAAE,EAAE,gBAAgB,EAAE,mBAAmB,EAAE;AACxD,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG,CAAC,OAAO,EAAE,EAAE;AACf,IAAI,OAAO,CAAC,KAAK,CAAC,CA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