@rechargeapps/storefront-client 0.0.17 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/cjs/api/auth.js +29 -0
- package/dist/cjs/api/auth.js.map +1 -0
- package/dist/cjs/api/bundle.js +6 -10
- package/dist/cjs/api/bundle.js.map +1 -1
- package/dist/cjs/api/cdn.js +6 -12
- package/dist/cjs/api/cdn.js.map +1 -1
- package/dist/cjs/api/subscription.js +12 -0
- package/dist/cjs/api/subscription.js.map +1 -0
- package/dist/cjs/constants/api.js +4 -0
- package/dist/cjs/constants/api.js.map +1 -1
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/init.js +25 -3
- package/dist/cjs/utils/init.js.map +1 -1
- package/dist/cjs/utils/options.js +2 -1
- package/dist/cjs/utils/options.js.map +1 -1
- package/dist/cjs/utils/request.js +37 -0
- package/dist/cjs/utils/request.js.map +1 -1
- package/dist/esm/api/auth.js +20 -0
- package/dist/esm/api/auth.js.map +1 -0
- package/dist/esm/api/bundle.js +7 -11
- package/dist/esm/api/bundle.js.map +1 -1
- package/dist/esm/api/cdn.js +7 -13
- package/dist/esm/api/cdn.js.map +1 -1
- package/dist/esm/api/subscription.js +8 -0
- package/dist/esm/api/subscription.js.map +1 -0
- package/dist/esm/constants/api.js +3 -1
- package/dist/esm/constants/api.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/init.js +25 -3
- package/dist/esm/utils/init.js.map +1 -1
- package/dist/esm/utils/options.js +2 -1
- package/dist/esm/utils/options.js.map +1 -1
- package/dist/esm/utils/request.js +34 -1
- package/dist/esm/utils/request.js.map +1 -1
- package/dist/index.d.ts +88 -5
- package/dist/umd/recharge-storefront-client.min.js +8 -8
- package/dist/umd/recharge-storefront-client.min.js.map +1 -1
- package/package.json +13 -8
package/dist/esm/api/cdn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.js","sources":["../../../src/api/cdn.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"cdn.js","sources":["../../../src/api/cdn.ts"],"sourcesContent":["import {\n CDNWidgetSettings,\n CDNStoreSettings,\n CDNWidgetSettingsResource,\n CDNProductsAndSettings,\n CDNProductResource,\n CDNProduct,\n CDNProductAndSettings,\n CDNProductsAndSettingsResource,\n CDNBundleSettings,\n CDNProductKeyObject,\n} from '../types';\nimport { productArrayMapper, productMapper, widgetSettingsMapper } from '../mappers/cdn';\nimport { cdnRequest } from '../utils/request';\n\nconst CDN_VERSION = '2020-12';\n\n// Default store settings if none are provided from the cdn\nconst DEFAULT_STORE_SETTINGS: CDNStoreSettings = {\n store_currency: {\n currency_code: 'USD',\n currency_symbol: '$',\n decimal_separator: '.',\n thousands_separator: ',',\n currency_symbol_location: 'left',\n },\n};\n\nconst promiseCache = new Map();\n\n// This will cache the request and use the same promise anywhere we call this function. This will never make multiple calls and always return the first request\nfunction cacheRequest<T>(cacheKey: string, request: () => T): T {\n if (!promiseCache.has(cacheKey)) {\n promiseCache.set(cacheKey, request());\n }\n return promiseCache.get(cacheKey);\n}\n\nexport const getProduct = async (externalProductId: string | number): Promise<CDNProduct> => {\n const { product } = await cacheRequest(`product.${externalProductId}`, () =>\n cdnRequest<CDNProductResource>('get', `/product/${CDN_VERSION}/${externalProductId}.json`)\n );\n\n return productMapper(product);\n};\n\nexport const getStoreSettings = async (): Promise<CDNStoreSettings> => {\n const storeSettings = await cacheRequest('storeSettings', () =>\n cdnRequest<CDNStoreSettings>('get', `/${CDN_VERSION}/store_settings.json`).catch(() => {\n return DEFAULT_STORE_SETTINGS;\n })\n );\n return storeSettings;\n};\n\nexport const getWidgetSettings = async (): Promise<CDNWidgetSettings> => {\n const { widget_settings } = await cacheRequest('widgetSettings', () =>\n cdnRequest<CDNWidgetSettingsResource>('get', `/${CDN_VERSION}/widget_settings.json`)\n );\n\n const widgetSettings = widgetSettingsMapper(widget_settings);\n\n return widgetSettings;\n};\n\nexport const getProductsAndSettings = async (): Promise<CDNProductsAndSettings> => {\n const { products, widget_settings, store_settings, meta } = await cacheRequest('productsAndSettings', () =>\n cdnRequest<CDNProductsAndSettingsResource>('get', `/product/${CDN_VERSION}/products.json`)\n );\n\n if (meta?.status === 'error') {\n return Promise.reject(meta.message);\n }\n\n return {\n products: productArrayMapper(products),\n widget_settings: widgetSettingsMapper(widget_settings),\n store_settings,\n };\n};\n\nexport const getProducts = async (): Promise<CDNProductKeyObject[]> => {\n const { products } = await getProductsAndSettings();\n return products;\n};\n\nexport const getProductAndSettings = async (externalProductId: string | number): Promise<CDNProductAndSettings> => {\n const [product, store_settings, widget_settings] = await Promise.all([\n getProduct(externalProductId),\n getStoreSettings(),\n getWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n};\n\nexport const getBundleSettings = async (\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> => {\n const { bundle_product } = await getProduct(externalProductId);\n\n return bundle_product;\n};\n\nexport const resetCache = () => Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAAG,SAAS,CAAC;AAC9B,MAAM,sBAAsB,GAAG;AAC/B,EAAE,cAAc,EAAE;AAClB,IAAI,aAAa,EAAE,KAAK;AACxB,IAAI,eAAe,EAAE,GAAG;AACxB,IAAI,iBAAiB,EAAE,GAAG;AAC1B,IAAI,mBAAmB,EAAE,GAAG;AAC5B,IAAI,wBAAwB,EAAE,MAAM;AACpC,GAAG;AACH,CAAC,CAAC;AACF,MAAM,YAAY,mBAAmB,IAAI,GAAG,EAAE,CAAC;AAC/C,SAAS,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE;AACzC,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;A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AAY,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sources":["../../../src/api/subscription.ts"],"sourcesContent":["import { rechargeApiRequest } from '../utils/request';\nimport { CustomerSubscriptionResponse, SubscriptionListParams } from '../types/subscription';\n\nexport const listSubscriptions = (query?: SubscriptionListParams): Promise<CustomerSubscriptionResponse> => {\n return rechargeApiRequest<CustomerSubscriptionResponse>('get', `/subscriptions`, { query });\n};\n"],"names":[],"mappings":";;AACY,MAAC,iBAAiB,GAAG,CAAC,KAAK,KAAK;AAC5C,EAAE,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAChE;;;;"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
const RECHARGE_API_URL = (environment) => environment === "stage" ? "https://api.stage.rechargeapps.com" : "https://api.rechargeapps.com";
|
|
1
2
|
const RECHARGE_CDN_URL = (environment) => environment === "stage" ? "https://static.stage.rechargecdn.com" : "https://static.rechargecdn.com";
|
|
3
|
+
const SHOPIFY_APP_PROXY_URL = "/tools/recurring";
|
|
2
4
|
|
|
3
|
-
export { RECHARGE_CDN_URL };
|
|
5
|
+
export { RECHARGE_API_URL, RECHARGE_CDN_URL, SHOPIFY_APP_PROXY_URL };
|
|
4
6
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +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_CDN_URL = (environment: 'stage' | 'prod'): string =>\n environment === 'stage' ? 'https://static.stage.rechargecdn.com' : 'https://static.rechargecdn.com';\n"],"names":[],"mappings":"
|
|
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_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,gBAAgB,GAAG,CAAC,WAAW,KAAK,WAAW,KAAK,OAAO,GAAG,sCAAsC,GAAG,iCAAiC;AAGzI,MAAC,qBAAqB,GAAG;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { login, logout } from './api/auth.js';
|
|
1
2
|
export { getBundleSettings, getProduct, getProductAndSettings, getProducts, getProductsAndSettings, getStoreSettings, getWidgetSettings, resetCache } from './api/cdn.js';
|
|
2
3
|
export { getBundleId, validateBundle } from './api/bundle.js';
|
|
4
|
+
export { listSubscriptions } from './api/subscription.js';
|
|
3
5
|
export { api, initRecharge } from './utils/init.js';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/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/esm/utils/init.js
CHANGED
|
@@ -16,10 +16,32 @@ const api = {
|
|
|
16
16
|
return request("delete", url, requestOptions);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
function
|
|
19
|
+
function getStoreIdentifier(storeIdentifier) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (storeIdentifier) {
|
|
22
|
+
return storeIdentifier;
|
|
23
|
+
}
|
|
24
|
+
if ((_a = window == null ? void 0 : window.Shopify) == null ? void 0 : _a.shop) {
|
|
25
|
+
return window.Shopify.shop;
|
|
26
|
+
}
|
|
27
|
+
let domain = window == null ? void 0 : window.domain;
|
|
28
|
+
if (!domain) {
|
|
29
|
+
const subdomain = (_b = location == null ? void 0 : location.href.match(/(?:http[s]*:\/\/)*(.*?)\.(?=admin\.rechargeapps\.com)/i)) == null ? void 0 : _b[1].replace(/-sp$/, "");
|
|
30
|
+
if (subdomain) {
|
|
31
|
+
domain = `${subdomain}.myshopify.com`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (domain) {
|
|
35
|
+
return domain;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`No storeIdentifier was passed into init.`);
|
|
38
|
+
}
|
|
39
|
+
function initRecharge(opt = {}) {
|
|
40
|
+
const hiddenOpts = opt;
|
|
20
41
|
setOptions({
|
|
21
|
-
storeIdentifier: opt.storeIdentifier,
|
|
22
|
-
environment:
|
|
42
|
+
storeIdentifier: getStoreIdentifier(opt.storeIdentifier),
|
|
43
|
+
environment: hiddenOpts.environment ? hiddenOpts.environment : "prod",
|
|
44
|
+
apiKey: hiddenOpts.apiKey ? hiddenOpts.apiKey : ""
|
|
23
45
|
});
|
|
24
46
|
resetCache();
|
|
25
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sources":["../../../src/utils/init.ts"],"sourcesContent":["import { resetCache } from '../api/cdn';\nimport { StorefrontOptions, CRUDRequestOptions, GetRequestOptions } from '../types';\nimport { setOptions } from './options';\nimport { request } from './request';\n\
|
|
1
|
+
{"version":3,"file":"init.js","sources":["../../../src/utils/init.ts"],"sourcesContent":["import { resetCache } from '../api/cdn';\nimport { StorefrontOptions, CRUDRequestOptions, GetRequestOptions } from '../types';\nimport { setOptions } from './options';\nimport { request } from './request';\n\n// This omits all of our 'hidden' variables. These can still be passed in, but won't have types generated for them\nexport type InitOptions = Omit<Partial<StorefrontOptions>, 'environment' | 'apiKey'>;\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 environment: hiddenOpts.environment ? hiddenOpts.environment : 'prod',\n apiKey: hiddenOpts.apiKey ? hiddenOpts.apiKey : '',\n });\n\n // When init is called again, reset the cache to make sure we don't have the old cache around\n resetC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DAAwD,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACpL,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,UAAU,CAAC;AACb,IAAI,eAAe,EAAE,kBAAkB,CAAC,GAAG,CAAC,eAAe,CAAC;AAC5D,IAAI,WAAW,EAAE,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,GAAG,MAAM;AACzE,IAAI,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,EAAE;AACtD,GAAG,CAAC,CAAC;AACL,EAAE,UAAU,EAAE,CAAC;AACf;;;;"}
|
|
@@ -1 +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;;;;"}
|
|
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 apiKey: '',\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,EAAE,MAAM,EAAE,EAAE;AACZ,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;;;;"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import 'isomorphic-fetch';
|
|
2
|
+
import Cookies from 'js-cookie';
|
|
2
3
|
import { stringify } from 'qs';
|
|
3
4
|
import trimStart from 'lodash/trimStart';
|
|
4
5
|
import trimEnd from 'lodash/trimEnd';
|
|
6
|
+
import { getOptions } from './options.js';
|
|
7
|
+
import { RECHARGE_API_URL, RECHARGE_CDN_URL, SHOPIFY_APP_PROXY_URL } from '../constants/api.js';
|
|
5
8
|
|
|
6
9
|
var __defProp = Object.defineProperty;
|
|
7
10
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -26,6 +29,36 @@ function stringifyQuery(str) {
|
|
|
26
29
|
arrayFormat: "comma"
|
|
27
30
|
});
|
|
28
31
|
}
|
|
32
|
+
async function cdnRequest(method, url, requestOptions = {}) {
|
|
33
|
+
const opts = getOptions();
|
|
34
|
+
return request(method, `${RECHARGE_CDN_URL(opts.environment)}/store/${opts.storeIdentifier}${url}`, requestOptions);
|
|
35
|
+
}
|
|
36
|
+
async function rechargeApiRequest(method, url, { id, query, data, headers } = {}) {
|
|
37
|
+
var _a;
|
|
38
|
+
const opts = getOptions();
|
|
39
|
+
const token = (_a = Cookies.get("recharge-session")) != null ? _a : opts.apiKey;
|
|
40
|
+
if (!token) {
|
|
41
|
+
throw new Error("No API Key or token found.");
|
|
42
|
+
}
|
|
43
|
+
const rechargeBaseUrl = RECHARGE_API_URL(opts.environment);
|
|
44
|
+
const reqHeaders = __spreadValues({
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
"X-Recharge-Access-Token": token,
|
|
47
|
+
"X-Recharge-Version": "2021-11",
|
|
48
|
+
"X-Recharge-App": "storefront-client"
|
|
49
|
+
}, headers ? headers : {});
|
|
50
|
+
const localQuery = __spreadValues({
|
|
51
|
+
shop_url: opts.storeIdentifier
|
|
52
|
+
}, query);
|
|
53
|
+
return request(method, `${rechargeBaseUrl}${url}`, { id, query: localQuery, data, headers: reqHeaders });
|
|
54
|
+
}
|
|
55
|
+
async function shopifyAppProxyRequest(method, url, { id, query, data, headers } = {}) {
|
|
56
|
+
const reqHeaders = __spreadValues({
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
"X-Recharge-App": "storefront-client"
|
|
59
|
+
}, headers ? headers : {});
|
|
60
|
+
return request(method, `${SHOPIFY_APP_PROXY_URL}${url}`, { id, query, data, headers: reqHeaders });
|
|
61
|
+
}
|
|
29
62
|
async function request(method, url, { id, query, data, headers } = {}) {
|
|
30
63
|
let reqUrl = url;
|
|
31
64
|
if (id) {
|
|
@@ -60,5 +93,5 @@ async function request(method, url, { id, query, data, headers } = {}) {
|
|
|
60
93
|
return result;
|
|
61
94
|
}
|
|
62
95
|
|
|
63
|
-
export { request };
|
|
96
|
+
export { cdnRequest, rechargeApiRequest, request, shopifyAppProxyRequest };
|
|
64
97
|
//# sourceMappingURL=request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sources":["../../../src/utils/request.ts"],"sourcesContent":["import 'isomorphic-fetch';\n\nimport { stringify } from 'qs';\nimport trimStart from 'lodash/trimStart';\nimport trimEnd from 'lodash/trimEnd';\n\nimport { Method, RequestHeaders, RequestOptions } from '../types';\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 request<T>(\n method: Method,\n url: string,\n { id, query, data, headers }: RequestOptions = {}\n): Promise<T> {\n let reqUrl = url;\n\n if (id) {\n reqUrl = [trimEnd(url), trimStart(id as string)].join('/');\n }\n\n let reqBody;\n if (method === 'get') {\n let exQuery;\n [reqUrl, exQuery] = reqUrl.split('?');\n const fullQuery = [exQuery, stringifyQuery(query)].join('&').replace(/^&/, '');\n reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ''}`;\n } else {\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 const result = await response.json();\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":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.js","sources":["../../../src/utils/request.ts"],"sourcesContent":["import 'isomorphic-fetch';\n\nimport Cookies from 'js-cookie';\nimport { stringify } from 'qs';\nimport trimStart from 'lodash/trimStart';\nimport trimEnd from 'lodash/trimEnd';\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';\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): Promise<T> {\n const opts = getOptions();\n const token = Cookies.get('recharge-session') ?? opts.apiKey;\n if (!token) {\n throw new Error('No API Key or token found.');\n }\n const rechargeBaseUrl = RECHARGE_API_URL(opts.environment);\n const reqHeaders: RequestHeaders = {\n 'Content-Type': 'application/json',\n 'X-Recharge-Access-Token': token,\n 'X-Recharge-Version': '2021-11',\n 'X-Recharge-App': 'storefront-client',\n ...(headers ? headers : {}),\n };\n\n const localQuery = {\n shop_url: opts.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 { id, query, data, headers }: RequestOptions = {}\n): Promise<T> {\n const reqHeaders: RequestHeaders = {\n 'Content-Type': 'application/json',\n 'X-Recharge-App': 'storefront-client',\n ...(headers ? headers : {}),\n };\n\n return request(method, `${SHOPIFY_APP_PROXY_URL}${url}`, { id, query, data, headers: reqHeaders });\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;\n\n if (id) {\n reqUrl = [trimEnd(url), trimStart(id as string)].join('/');\n }\n\n let reqBody;\n if (method === 'get') {\n let exQuery;\n [reqUrl, exQuery] = reqUrl.split('?');\n const fullQuery = [exQuery, stringifyQuery(query)].join('&').replace(/^&/, '');\n reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ''}`;\n } else {\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 const result = await response.json();\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":[],"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;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M,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC9E,KAAK;AACL,GAAG;AACH,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
declare const login: () => Promise<boolean>;
|
|
2
|
+
declare const logout: () => void;
|
|
3
|
+
|
|
1
4
|
declare type Method = 'get' | 'post' | 'put' | 'delete';
|
|
2
5
|
declare type Request = <T>(method: Method, url: string, options?: RequestOptions) => Promise<T>;
|
|
3
6
|
interface GetRequestOptions {
|
|
@@ -37,6 +40,18 @@ declare type ColorString = string;
|
|
|
37
40
|
declare type HTMLString = string;
|
|
38
41
|
/** ISO 8601 date time */
|
|
39
42
|
declare type IsoDateString = string;
|
|
43
|
+
interface Properties {
|
|
44
|
+
name: string;
|
|
45
|
+
value: string;
|
|
46
|
+
}
|
|
47
|
+
interface ListParams<T> {
|
|
48
|
+
/** default is 50, max is 250 */
|
|
49
|
+
limit?: number;
|
|
50
|
+
/** next or previous cursor returned by previous list call */
|
|
51
|
+
cursor?: number;
|
|
52
|
+
/** sort list by option */
|
|
53
|
+
sort_by?: T;
|
|
54
|
+
}
|
|
40
55
|
|
|
41
56
|
declare type FirstOption = 'onetime' | 'autodeliver';
|
|
42
57
|
declare type IntervalUnit = 'day' | 'week' | 'month';
|
|
@@ -389,7 +404,10 @@ interface CDNBundleSettings {
|
|
|
389
404
|
declare type StorefrontEnvironment = 'stage' | 'prod';
|
|
390
405
|
interface StorefrontOptions {
|
|
391
406
|
storeIdentifier: string;
|
|
407
|
+
/** This is only for internal use. Sets the environment where data is fetched from. */
|
|
392
408
|
environment: StorefrontEnvironment;
|
|
409
|
+
/** currently only for internal use */
|
|
410
|
+
apiKey?: string;
|
|
393
411
|
}
|
|
394
412
|
|
|
395
413
|
declare const getProduct: (externalProductId: string | number) => Promise<CDNProduct>;
|
|
@@ -404,16 +422,81 @@ declare const resetCache: () => void;
|
|
|
404
422
|
declare const getBundleId: (bundle: Bundle) => Promise<string>;
|
|
405
423
|
declare const validateBundle: (bundle: Bundle) => Promise<boolean>;
|
|
406
424
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
425
|
+
declare enum SubscriptionStatus {
|
|
426
|
+
Active = "active",
|
|
427
|
+
Cancelled = "cancelled",
|
|
428
|
+
Expired = "expired"
|
|
429
|
+
}
|
|
430
|
+
interface CustomerSubscription {
|
|
431
|
+
is_prepaid: boolean;
|
|
432
|
+
order_day_of_month: number | null;
|
|
433
|
+
order_day_of_week: number | null;
|
|
434
|
+
order_interval_unit: 'day' | 'week' | 'month';
|
|
435
|
+
updated_at: IsoDateString;
|
|
436
|
+
id: number;
|
|
437
|
+
address_id: number;
|
|
438
|
+
analytics_data: {
|
|
439
|
+
utm_params: Record<string, unknown>;
|
|
440
|
+
};
|
|
441
|
+
cancellation_reason: string | null;
|
|
442
|
+
cancellation_reason_comments: string | null;
|
|
443
|
+
cancelled_at: string | null;
|
|
444
|
+
charge_delay: number | null;
|
|
445
|
+
created_at: IsoDateString;
|
|
446
|
+
customer_id: number;
|
|
447
|
+
cutoff_day_of_month_before_and_after: number | null;
|
|
448
|
+
cutoff_day_of_week_before_and_after: number | null;
|
|
449
|
+
email: string;
|
|
450
|
+
expire_after_specific_number_of_charges: number | null;
|
|
451
|
+
first_charge_date: IsoDateString | null;
|
|
452
|
+
is_skippable: boolean;
|
|
453
|
+
is_swappable: boolean;
|
|
454
|
+
next_charge_scheduled_at: IsoDateString;
|
|
455
|
+
presentment_currency: string | null;
|
|
456
|
+
properties: Properties[];
|
|
457
|
+
product_title: string | null;
|
|
458
|
+
quantity: number;
|
|
459
|
+
recharge_product_id: number;
|
|
460
|
+
shopify_product_id: number;
|
|
461
|
+
shopify_variant_id: number;
|
|
462
|
+
sku: string | null;
|
|
463
|
+
sku_override: boolean;
|
|
464
|
+
variant_title: string;
|
|
465
|
+
charge_interval_frequency: number;
|
|
466
|
+
external_product_id: {
|
|
467
|
+
ecommerce: string;
|
|
468
|
+
};
|
|
469
|
+
external_variant_id: {
|
|
470
|
+
ecommerce: string;
|
|
471
|
+
};
|
|
472
|
+
has_queued_charges: boolean;
|
|
473
|
+
locked_pending_charge_id: number | null;
|
|
474
|
+
max_retries_reached: boolean;
|
|
475
|
+
order_interval_frequency: number;
|
|
476
|
+
price: string;
|
|
477
|
+
status: SubscriptionStatus;
|
|
478
|
+
}
|
|
479
|
+
interface CustomerSubscriptionResponse {
|
|
480
|
+
next_cursor: null | string;
|
|
481
|
+
previous_cursor: null | string;
|
|
482
|
+
subscriptions: CustomerSubscription[];
|
|
483
|
+
}
|
|
484
|
+
declare type SubscriptionSortBy = 'id-asc' | 'id-desc' | 'created_at-asc' | 'created_at-desc' | 'updated_at-asc' | 'updated_at-desc';
|
|
485
|
+
interface SubscriptionListParams extends ListParams<SubscriptionSortBy> {
|
|
486
|
+
created_at_min?: IsoDateString;
|
|
487
|
+
created_at_max?: IsoDateString;
|
|
488
|
+
customer_id?: string;
|
|
410
489
|
}
|
|
490
|
+
|
|
491
|
+
declare const listSubscriptions: (query?: SubscriptionListParams) => Promise<CustomerSubscriptionResponse>;
|
|
492
|
+
|
|
493
|
+
declare type InitOptions = Omit<Partial<StorefrontOptions>, 'environment' | 'apiKey'>;
|
|
411
494
|
declare const api: {
|
|
412
495
|
get<T>(url: string, requestOptions?: GetRequestOptions): Promise<T>;
|
|
413
496
|
post<T_1>(url: string, requestOptions?: CRUDRequestOptions): Promise<T_1>;
|
|
414
497
|
put<T_2>(url: string, requestOptions?: CRUDRequestOptions): Promise<T_2>;
|
|
415
498
|
delete<T_3>(url: string, requestOptions?: CRUDRequestOptions): Promise<T_3>;
|
|
416
499
|
};
|
|
417
|
-
declare function initRecharge(opt
|
|
500
|
+
declare function initRecharge(opt?: InitOptions): void;
|
|
418
501
|
|
|
419
|
-
export { Bundle, BundleSelection, BundleTranslations, CDNBaseWidgetSettings, CDNBundleLayoutSettings, CDNBundleSettings, CDNBundleStep, CDNBundleStepOption, CDNBundleVariant, CDNBundleVariantOptionSource, CDNBundleVariantSelectionDefault, CDNPrices, CDNProduct, CDNProductAndSettings, CDNProductKeyObject, CDNProductOption, CDNProductOptionValue, CDNProductRaw, CDNProductResource, CDNProductsAndSettings, CDNProductsAndSettingsResource, CDNSellingPlan, CDNSellingPlanAllocations, CDNSellingPlanGroup, CDNStoreSettings, CDNSubscriptionOption, CDNVariant, CDNVariantOptionValue, CDNWidgetSettings, CDNWidgetSettingsRaw, CDNWidgetSettingsResource, CRUDRequestOptions, FirstOption, GetRequestOptions, InitOptions, IntervalUnit, Method, PriceAdjustmentsType, Request, RequestHeaders, RequestOptions, RequestOptionsHeaders, StorefrontEnvironment, StorefrontOptions, StorefrontPurchaseOption, Translations, WidgetIconColor, WidgetTemplateType, api, getBundleId, getBundleSettings, getProduct, getProductAndSettings, getProducts, getProductsAndSettings, getStoreSettings, getWidgetSettings, initRecharge, resetCache, validateBundle };
|
|
502
|
+
export { Bundle, BundleSelection, BundleTranslations, CDNBaseWidgetSettings, CDNBundleLayoutSettings, CDNBundleSettings, CDNBundleStep, CDNBundleStepOption, CDNBundleVariant, CDNBundleVariantOptionSource, CDNBundleVariantSelectionDefault, CDNPrices, CDNProduct, CDNProductAndSettings, CDNProductKeyObject, CDNProductOption, CDNProductOptionValue, CDNProductRaw, CDNProductResource, CDNProductsAndSettings, CDNProductsAndSettingsResource, CDNSellingPlan, CDNSellingPlanAllocations, CDNSellingPlanGroup, CDNStoreSettings, CDNSubscriptionOption, CDNVariant, CDNVariantOptionValue, CDNWidgetSettings, CDNWidgetSettingsRaw, CDNWidgetSettingsResource, CRUDRequestOptions, FirstOption, GetRequestOptions, InitOptions, IntervalUnit, Method, PriceAdjustmentsType, Request, RequestHeaders, RequestOptions, RequestOptionsHeaders, StorefrontEnvironment, StorefrontOptions, StorefrontPurchaseOption, Translations, WidgetIconColor, WidgetTemplateType, api, getBundleId, getBundleSettings, getProduct, getProductAndSettings, getProducts, getProductsAndSettings, getStoreSettings, getWidgetSettings, initRecharge, listSubscriptions, login, logout, resetCache, validateBundle };
|