@rechargeapps/storefront-client 1.7.0 → 1.8.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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var cdn = require('../mappers/cdn.js');
6
6
  var request = require('../utils/request.js');
7
7
 
8
- const CDN_VERSION = "2020-12";
8
+ const BASE_CDN_VERSION = "2020-12";
9
9
  const DEFAULT_STORE_SETTINGS = {
10
10
  store_currency: {
11
11
  currency_code: "USD",
@@ -22,17 +22,22 @@ function cacheRequest(cacheKey, request) {
22
22
  }
23
23
  return promiseCache.get(cacheKey);
24
24
  }
25
- async function getCDNProduct(externalProductId) {
25
+ async function getCDNProduct(externalProductId, query) {
26
+ var _a;
27
+ const version = (_a = query == null ? void 0 : query.version) != null ? _a : "2020-12";
26
28
  const { product } = await cacheRequest(
27
- `product.${externalProductId}`,
28
- () => request.cdnRequest("get", `/product/${CDN_VERSION}/${externalProductId}.json`)
29
+ `product.${externalProductId}.${version}`,
30
+ () => request.cdnRequest("get", `/product/${version}/${externalProductId}.json`)
29
31
  );
30
- return cdn.productMapper(product);
32
+ if (version === "2020-12") {
33
+ return cdn.productMapper(product);
34
+ }
35
+ return product;
31
36
  }
32
37
  async function getCDNStoreSettings() {
33
38
  const storeSettings = await cacheRequest(
34
39
  "storeSettings",
35
- () => request.cdnRequest("get", `/${CDN_VERSION}/store_settings.json`).catch(() => {
40
+ () => request.cdnRequest("get", `/${BASE_CDN_VERSION}/store_settings.json`).catch(() => {
36
41
  return DEFAULT_STORE_SETTINGS;
37
42
  })
38
43
  );
@@ -41,7 +46,7 @@ async function getCDNStoreSettings() {
41
46
  async function getCDNWidgetSettings() {
42
47
  const { widget_settings } = await cacheRequest(
43
48
  "widgetSettings",
44
- () => request.cdnRequest("get", `/${CDN_VERSION}/widget_settings.json`)
49
+ () => request.cdnRequest("get", `/${BASE_CDN_VERSION}/widget_settings.json`)
45
50
  );
46
51
  const widgetSettings = cdn.widgetSettingsMapper(widget_settings);
47
52
  return widgetSettings;
@@ -49,7 +54,7 @@ async function getCDNWidgetSettings() {
49
54
  async function getCDNProductsAndSettings() {
50
55
  const { products, widget_settings, store_settings, meta } = await cacheRequest(
51
56
  "productsAndSettings",
52
- () => request.cdnRequest("get", `/product/${CDN_VERSION}/products.json`)
57
+ () => request.cdnRequest("get", `/product/${BASE_CDN_VERSION}/products.json`)
53
58
  );
54
59
  if ((meta == null ? void 0 : meta.status) === "error") {
55
60
  return Promise.reject(meta.message);
@@ -1 +1 @@
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 async function getCDNProduct(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 async function getCDNStoreSettings(): 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 async function getCDNWidgetSettings(): 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 async function getCDNProductsAndSettings(): 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: store_settings ?? {},\n };\n}\n\nexport async function getCDNProducts(): Promise<CDNProductKeyObject[]> {\n const { products } = await getCDNProductsAndSettings();\n return products;\n}\n\nexport async function getCDNProductAndSettings(externalProductId: string | number): Promise<CDNProductAndSettings> {\n const [product, store_settings, widget_settings] = await Promise.all([\n getCDNProduct(externalProductId),\n getCDNStoreSettings(),\n getCDNWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n}\n\nexport async function getCDNBundleSettings(\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> {\n const { bundle_product } = await getCDNProduct(externalProductId);\n\n return bundle_product;\n}\n\nexport async function resetCDNCache() {\n return Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n}\n"],"names":["cdnRequest","productMapper","widgetSettingsMapper","productArrayMapper"],"mappings":";;;;;;;AAEA,MAAM,WAAW,GAAG,SAAS,CAAC;AAC9B,MAAM,sBAAsB,GAAG;AAC/B,EAAE,cAAc,EAAE;AAClB,IAAI,a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mB,EAAE;AACzB,IAAI,oBAAoB,EAAE;AAC1B,GAAG,CAAC,CAAC;AACL,EAAE,OAAO;AACT,IAAI,OAAO;AACX,IAAI,cAAc;AAClB,IAAI,eAAe;AACnB,IAAI,aAAa,EAAE,cAAc;AACjC,IAAI,cAAc,EAAE,eAAe;AACnC,GAAG,CAAC;AACJ,CAAC;AACM,eAAe,oBAAoB,CAAC,iBAAiB,EAAE;AAC9D,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,aAAa,CAAC,iBAAiB,CAAC,CAAC;AACpE,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,eAAe,aAAa,GAAG;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACpF;;;;;;;;;;;"}
1
+ {"version":3,"file":"cdn.js","sources":["../../../src/api/cdn.ts"],"sourcesContent":["import {\n CDNWidgetSettings,\n CDNStoreSettings,\n CDNWidgetSettingsResource,\n CDNProductsAndSettings,\n CDNProductAndSettings,\n CDNProductsAndSettingsResource,\n CDNBundleSettings,\n CDNProductKeyObject,\n CDNProductRaw,\n CDNProductType,\n CDNProductQuery_2020_12,\n CDNProductQuery_2022_06,\n CDNProductResponseType,\n} from '../types';\nimport { productArrayMapper, productMapper, widgetSettingsMapper } from '../mappers/cdn';\nimport { cdnRequest } from '../utils/request';\n\nconst BASE_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 async function getCDNProduct<\n T extends CDNProductQuery_2020_12 | CDNProductQuery_2022_06 = CDNProductQuery_2020_12\n>(externalProductId: string | number, query?: T): Promise<CDNProductType<T>> {\n const version = query?.version ?? '2020-12';\n const { product } = await cacheRequest(`product.${externalProductId}.${version}`, () =>\n cdnRequest<CDNProductResponseType<T>>('get', `/product/${version}/${externalProductId}.json`)\n );\n\n if (version === '2020-12') {\n return productMapper(product as CDNProductRaw) as CDNProductType<T>;\n }\n return product as CDNProductType<T>;\n}\n\nexport async function getCDNStoreSettings(): Promise<CDNStoreSettings> {\n const storeSettings = await cacheRequest('storeSettings', () =>\n cdnRequest<CDNStoreSettings>('get', `/${BASE_CDN_VERSION}/store_settings.json`).catch(() => {\n return DEFAULT_STORE_SETTINGS;\n })\n );\n return storeSettings;\n}\n\nexport async function getCDNWidgetSettings(): Promise<CDNWidgetSettings> {\n const { widget_settings } = await cacheRequest('widgetSettings', () =>\n cdnRequest<CDNWidgetSettingsResource>('get', `/${BASE_CDN_VERSION}/widget_settings.json`)\n );\n\n const widgetSettings = widgetSettingsMapper(widget_settings);\n\n return widgetSettings;\n}\n\nexport async function getCDNProductsAndSettings(): Promise<CDNProductsAndSettings> {\n const { products, widget_settings, store_settings, meta } = await cacheRequest('productsAndSettings', () =>\n cdnRequest<CDNProductsAndSettingsResource>('get', `/product/${BASE_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: store_settings ?? {},\n };\n}\n\nexport async function getCDNProducts(): Promise<CDNProductKeyObject[]> {\n const { products } = await getCDNProductsAndSettings();\n return products;\n}\n\nexport async function getCDNProductAndSettings(externalProductId: string | number): Promise<CDNProductAndSettings> {\n const [product, store_settings, widget_settings] = await Promise.all([\n getCDNProduct(externalProductId),\n getCDNStoreSettings(),\n getCDNWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n}\n\nexport async function getCDNBundleSettings(\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> {\n const { bundle_product } = await getCDNProduct(externalProductId);\n\n return bundle_product;\n}\n\nexport async function resetCDNCache() {\n return Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n}\n"],"names":["cdnRequest","productMapper","widgetSettingsMapper","productArrayMapper"],"mappings":";;;;;;;AAEA,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACnC,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;AACnC,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1C,GAAG;AACH,EAAE,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AACM,eAAe,aAAa,CAAC,iBAAiB,EAAE,KAAK,EAAE;AAC9D,EAAE,IAAI,EAAE,CAAC;AACT,EAAE,MAAM,OAAO,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,OAAO,KAAK,IAAI,GAAG,EAAE,GAAG,SAAS,CAAC;AACzF,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG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AI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACpF;;;;;;;;;;;"}
@@ -50,9 +50,34 @@ async function getCustomerPortalAccess(session) {
50
50
  const access = await request.rechargeApiRequest("get", "/portal_access", {}, session);
51
51
  return access;
52
52
  }
53
+ const customerNotificationMap = {
54
+ SHOPIFY_UPDATE_PAYMENT_INFO: {
55
+ type: "email",
56
+ template_type: "shopify_update_payment_information"
57
+ }
58
+ };
59
+ async function sendCustomerNotification(session, notification) {
60
+ const customerId = session.customerId;
61
+ if (!customerId) {
62
+ throw new Error("Not logged in.");
63
+ }
64
+ const data = customerNotificationMap[notification];
65
+ if (!data) {
66
+ throw new Error("Notification not supported.");
67
+ }
68
+ return request.rechargeApiRequest(
69
+ "post",
70
+ `/customers/${customerId}/notifications`,
71
+ {
72
+ data
73
+ },
74
+ session
75
+ );
76
+ }
53
77
 
54
78
  exports.getCustomer = getCustomer;
55
79
  exports.getCustomerPortalAccess = getCustomerPortalAccess;
56
80
  exports.getDeliverySchedule = getDeliverySchedule;
81
+ exports.sendCustomerNotification = sendCustomerNotification;
57
82
  exports.updateCustomer = updateCustomer;
58
83
  //# sourceMappingURL=customer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import { Session } from '../types/session';\nimport {\n Customer,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerPortalAccessResponse,\n Delivery,\n GetCustomerOptions,\n UpdateCustomerRequest,\n} from '../types/customer';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n session\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${id}/delivery_schedule`,\n { query },\n session\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(session: Session): Promise<CustomerPortalAccessResponse> {\n const access = await rechargeApiRequest<CustomerPortalAccessResponse>('get', '/portal_access', {}, session);\n return access;\n}\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACO,eAAe,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE;AACpD,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAMA,0BAAkB;AAC/C,IAAI,KAAK;AACT,IAAI,CAAC,UAAU,CAAC;AAChB,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,QAAQ,CAAC;AAClB,CAAC;AACM,eAAe,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE;AAC7D,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAMA,0BAAkB;AAC/C,IAAI,KAAK;AACT,IAAI,CAAC,UAAU,CAAC;AAChB,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;AAC/B,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,QAAQ,CAAC;AAClB,CAAC;AACM,eAAe,mBAAmB,CAAC,OAAO,EAAE,KAAK,EAAE;AAC1D,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAMA,0BAAkB;AACjD,IAAI,KAAK;AACT,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAAC;AACxC,IAAI,EAAE,KAAK,EAAE;AACb,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,UAAU,CAAC;AACpB,CAAC;AACM,eAAe,uBAAuB,CAAC,OAAO,EAAE;AACvD,EAAE,MAAM,MAAM,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChF,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;"}
1
+ {"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import { Session } from '../types/session';\nimport {\n Customer,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerNotification,\n CustomerNotificationTemplate,\n CustomerNotificationType,\n CustomerPortalAccessResponse,\n Delivery,\n GetCustomerOptions,\n UpdateCustomerRequest,\n} from '../types/customer';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n session\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${id}/delivery_schedule`,\n { query },\n session\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(session: Session): Promise<CustomerPortalAccessResponse> {\n const access = await rechargeApiRequest<CustomerPortalAccessResponse>('get', '/portal_access', {}, session);\n return access;\n}\n\nconst customerNotificationMap: Record<\n CustomerNotification,\n { type: CustomerNotificationType; template_type: CustomerNotificationTemplate }\n> = {\n SHOPIFY_UPDATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_update_payment_information',\n },\n};\n\nexport async function sendCustomerNotification(session: Session, notification: CustomerNotification): Promise<void> {\n const customerId = session.customerId;\n if (!customerId) {\n throw new Error('Not logged in.');\n }\n const data = customerNotificationMap[notification];\n if (!data) {\n throw new Error('Notification not supported.');\n }\n return rechargeApiRequest<void>(\n 'post',\n `/customers/${customerId}/notifications`,\n {\n data,\n },\n session\n );\n}\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACO,eAAe,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE;AACpD,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAA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OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,UAAU,CAAC;AACpB,CAAC;AACM,eAAe,uBAAuB,CAAC,OAAO,EAAE;AACvD,EAAE,MAAM,MAAM,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChF,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,MAAM,uBAAuB,GAAG;AAChC,EAAE,2BAA2B,EAAE;AAC/B,IAAI,IAAI,EAAE,OAAO;AACjB,IAAI,aAAa,EAAE,oCAAoC;AACvD,GAAG;AACH,CAAC,CAAC;AACK,eAAe,wBAAwB,CAAC,OAAO,EAAE,YAAY,EAAE;AACtE,EAAE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;AACxC,EAAE,IAAI,CAAC,UAAU,EAAE;AACnB,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,IAAI,GAAG,uBAAuB,CAAC,YAAY,CAAC,CAAC;AACrD,EAAE,IAAI,CAAC,IAAI,EAAE;AACb,IAAI,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;AACnD,GAAG;AACH,EAAE,OAAOA,0BAAkB;AAC3B,IAAI,MAAM;AACV,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,cAAc,CAAC;AAC5C,IAAI;AACJ,MAAM,IAAI;AACV,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ;;;;;;;;"}
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var request = require('../utils/request.js');
6
+
7
+ async function productSearch(session, query) {
8
+ if (!["2020-12", "2022-06"].includes(query.format_version)) {
9
+ throw new Error("Missing or unsupported format_version.");
10
+ }
11
+ return request.rechargeApiRequest(
12
+ "get",
13
+ `/product_search`,
14
+ {
15
+ query,
16
+ headers: {
17
+ "X-Recharge-Version": "2021-01"
18
+ }
19
+ },
20
+ session
21
+ );
22
+ }
23
+
24
+ exports.productSearch = productSearch;
25
+ //# sourceMappingURL=product.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.js","sources":["../../../src/api/product.ts"],"sourcesContent":["import {\n ProductSearchParams_2020_12,\n ProductSearchParams_2022_06,\n ProductSearchResponse_2020_12,\n ProductSearchResponse_2022_06,\n} from '../types';\nimport { Session } from '../types/session';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport type ProductSearchType<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06> =\n T extends ProductSearchParams_2020_12 ? ProductSearchResponse_2020_12 : ProductSearchResponse_2022_06;\n\nexport async function productSearch<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06>(\n session: Session,\n query: T\n): Promise<ProductSearchType<T>> {\n if (!['2020-12', '2022-06'].includes(query.format_version)) {\n throw new Error('Missing or unsupported format_version.');\n }\n return rechargeApiRequest<ProductSearchType<T>>(\n 'get',\n `/product_search`,\n {\n query,\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n}\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACO,eAAe,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE;AACpD,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;AAC9D,IAAI,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC9D,GAAG;AACH,EAAE,OAAOA,0BAAkB;AAC3B,IAAI,KAAK;AACT,IAAI,CAAC,eAAe,CAAC;AACrB,IAAI;AACJ,MAAM,KAAK;AACX,MAAM,OAAO,EAAE;AACf,QAAQ,oBAAoB,EAAE,SAAS;AACvC,OAAO;AACP,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ;;;;"}
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@ var onetime = require('./api/onetime.js');
14
14
  var order = require('./api/order.js');
15
15
  var paymentMethod = require('./api/paymentMethod.js');
16
16
  var plan = require('./api/plan.js');
17
+ var product = require('./api/product.js');
17
18
  var subscription = require('./api/subscription.js');
18
19
  var customer = require('./api/customer.js');
19
20
  var init = require('./utils/init.js');
@@ -83,6 +84,7 @@ exports.listPaymentMethods = paymentMethod.listPaymentMethods;
83
84
  exports.updatePaymentMethod = paymentMethod.updatePaymentMethod;
84
85
  exports.getPlan = plan.getPlan;
85
86
  exports.listPlans = plan.listPlans;
87
+ exports.productSearch = product.productSearch;
86
88
  exports.activateSubscription = subscription.activateSubscription;
87
89
  exports.cancelSubscription = subscription.cancelSubscription;
88
90
  exports.createSubscription = subscription.createSubscription;
@@ -98,6 +100,7 @@ exports.updateSubscriptions = subscription.updateSubscriptions;
98
100
  exports.getCustomer = customer.getCustomer;
99
101
  exports.getCustomerPortalAccess = customer.getCustomerPortalAccess;
100
102
  exports.getDeliverySchedule = customer.getDeliverySchedule;
103
+ exports.sendCustomerNotification = customer.sendCustomerNotification;
101
104
  exports.updateCustomer = customer.updateCustomer;
102
105
  exports.api = init.api;
103
106
  exports.initRecharge = init.initRecharge;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { productMapper, widgetSettingsMapper, productArrayMapper } from '../mappers/cdn.js';
2
2
  import { cdnRequest } from '../utils/request.js';
3
3
 
4
- const CDN_VERSION = "2020-12";
4
+ const BASE_CDN_VERSION = "2020-12";
5
5
  const DEFAULT_STORE_SETTINGS = {
6
6
  store_currency: {
7
7
  currency_code: "USD",
@@ -18,17 +18,22 @@ function cacheRequest(cacheKey, request) {
18
18
  }
19
19
  return promiseCache.get(cacheKey);
20
20
  }
21
- async function getCDNProduct(externalProductId) {
21
+ async function getCDNProduct(externalProductId, query) {
22
+ var _a;
23
+ const version = (_a = query == null ? void 0 : query.version) != null ? _a : "2020-12";
22
24
  const { product } = await cacheRequest(
23
- `product.${externalProductId}`,
24
- () => cdnRequest("get", `/product/${CDN_VERSION}/${externalProductId}.json`)
25
+ `product.${externalProductId}.${version}`,
26
+ () => cdnRequest("get", `/product/${version}/${externalProductId}.json`)
25
27
  );
26
- return productMapper(product);
28
+ if (version === "2020-12") {
29
+ return productMapper(product);
30
+ }
31
+ return product;
27
32
  }
28
33
  async function getCDNStoreSettings() {
29
34
  const storeSettings = await cacheRequest(
30
35
  "storeSettings",
31
- () => cdnRequest("get", `/${CDN_VERSION}/store_settings.json`).catch(() => {
36
+ () => cdnRequest("get", `/${BASE_CDN_VERSION}/store_settings.json`).catch(() => {
32
37
  return DEFAULT_STORE_SETTINGS;
33
38
  })
34
39
  );
@@ -37,7 +42,7 @@ async function getCDNStoreSettings() {
37
42
  async function getCDNWidgetSettings() {
38
43
  const { widget_settings } = await cacheRequest(
39
44
  "widgetSettings",
40
- () => cdnRequest("get", `/${CDN_VERSION}/widget_settings.json`)
45
+ () => cdnRequest("get", `/${BASE_CDN_VERSION}/widget_settings.json`)
41
46
  );
42
47
  const widgetSettings = widgetSettingsMapper(widget_settings);
43
48
  return widgetSettings;
@@ -45,7 +50,7 @@ async function getCDNWidgetSettings() {
45
50
  async function getCDNProductsAndSettings() {
46
51
  const { products, widget_settings, store_settings, meta } = await cacheRequest(
47
52
  "productsAndSettings",
48
- () => cdnRequest("get", `/product/${CDN_VERSION}/products.json`)
53
+ () => cdnRequest("get", `/product/${BASE_CDN_VERSION}/products.json`)
49
54
  );
50
55
  if ((meta == null ? void 0 : meta.status) === "error") {
51
56
  return Promise.reject(meta.message);
@@ -1 +1 @@
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 async function getCDNProduct(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 async function getCDNStoreSettings(): 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 async function getCDNWidgetSettings(): 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 async function getCDNProductsAndSettings(): 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: store_settings ?? {},\n };\n}\n\nexport async function getCDNProducts(): Promise<CDNProductKeyObject[]> {\n const { products } = await getCDNProductsAndSettings();\n return products;\n}\n\nexport async function getCDNProductAndSettings(externalProductId: string | number): Promise<CDNProductAndSettings> {\n const [product, store_settings, widget_settings] = await Promise.all([\n getCDNProduct(externalProductId),\n getCDNStoreSettings(),\n getCDNWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n}\n\nexport async function getCDNBundleSettings(\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> {\n const { bundle_product } = await getCDNProduct(externalProductId);\n\n return bundle_product;\n}\n\nexport async function resetCDNCache() {\n return Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n}\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,C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iBAAiB,CAAC,CAAC;AACpE,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,eAAe,aAAa,GAAG;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACpF;;;;"}
1
+ {"version":3,"file":"cdn.js","sources":["../../../src/api/cdn.ts"],"sourcesContent":["import {\n CDNWidgetSettings,\n CDNStoreSettings,\n CDNWidgetSettingsResource,\n CDNProductsAndSettings,\n CDNProductAndSettings,\n CDNProductsAndSettingsResource,\n CDNBundleSettings,\n CDNProductKeyObject,\n CDNProductRaw,\n CDNProductType,\n CDNProductQuery_2020_12,\n CDNProductQuery_2022_06,\n CDNProductResponseType,\n} from '../types';\nimport { productArrayMapper, productMapper, widgetSettingsMapper } from '../mappers/cdn';\nimport { cdnRequest } from '../utils/request';\n\nconst BASE_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 async function getCDNProduct<\n T extends CDNProductQuery_2020_12 | CDNProductQuery_2022_06 = CDNProductQuery_2020_12\n>(externalProductId: string | number, query?: T): Promise<CDNProductType<T>> {\n const version = query?.version ?? '2020-12';\n const { product } = await cacheRequest(`product.${externalProductId}.${version}`, () =>\n cdnRequest<CDNProductResponseType<T>>('get', `/product/${version}/${externalProductId}.json`)\n );\n\n if (version === '2020-12') {\n return productMapper(product as CDNProductRaw) as CDNProductType<T>;\n }\n return product as CDNProductType<T>;\n}\n\nexport async function getCDNStoreSettings(): Promise<CDNStoreSettings> {\n const storeSettings = await cacheRequest('storeSettings', () =>\n cdnRequest<CDNStoreSettings>('get', `/${BASE_CDN_VERSION}/store_settings.json`).catch(() => {\n return DEFAULT_STORE_SETTINGS;\n })\n );\n return storeSettings;\n}\n\nexport async function getCDNWidgetSettings(): Promise<CDNWidgetSettings> {\n const { widget_settings } = await cacheRequest('widgetSettings', () =>\n cdnRequest<CDNWidgetSettingsResource>('get', `/${BASE_CDN_VERSION}/widget_settings.json`)\n );\n\n const widgetSettings = widgetSettingsMapper(widget_settings);\n\n return widgetSettings;\n}\n\nexport async function getCDNProductsAndSettings(): Promise<CDNProductsAndSettings> {\n const { products, widget_settings, store_settings, meta } = await cacheRequest('productsAndSettings', () =>\n cdnRequest<CDNProductsAndSettingsResource>('get', `/product/${BASE_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: store_settings ?? {},\n };\n}\n\nexport async function getCDNProducts(): Promise<CDNProductKeyObject[]> {\n const { products } = await getCDNProductsAndSettings();\n return products;\n}\n\nexport async function getCDNProductAndSettings(externalProductId: string | number): Promise<CDNProductAndSettings> {\n const [product, store_settings, widget_settings] = await Promise.all([\n getCDNProduct(externalProductId),\n getCDNStoreSettings(),\n getCDNWidgetSettings(),\n ]);\n\n return {\n product,\n store_settings,\n widget_settings,\n storeSettings: store_settings,\n widgetSettings: widget_settings,\n };\n}\n\nexport async function getCDNBundleSettings(\n externalProductId: string | number\n): Promise<CDNBundleSettings | null | undefined> {\n const { bundle_product } = await getCDNProduct(externalProductId);\n\n return bundle_product;\n}\n\nexport async function resetCDNCache() {\n return Array.from(promiseCache.keys()).forEach(key => promiseCache.delete(key));\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,gBA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,GAAG,cAAc,GAAG,EAAE;AAChE,GAAG,CAAC;AACJ,CAAC;AACM,eAAe,cAAc,GAAG;AACvC,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,yBAAyB,EAAE,CAAC;AACzD,EAAE,OAAO,QAAQ,CAAC;AAClB,CAAC;AACM,eAAe,wBAAwB,CAAC,iBAAiB,EAAE;AAClE,EAAE,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;AACvE,IAAI,aAAa,CAAC,iBAAiB,CAAC;AACpC,IAAI,mBAAmB,EAAE;AACzB,IAAI,oBAAoB,EAAE;AAC1B,GAAG,CAAC,CAAC;AACL,EAAE,OAAO;AACT,IAAI,OAAO;AACX,IAAI,cAAc;AAClB,IAAI,eAAe;AACnB,IAAI,aAAa,EAAE,cAAc;AACjC,IAAI,cAAc,EAAE,eAAe;AACnC,GAAG,CAAC;AACJ,CAAC;AACM,eAAe,oBAAoB,CAAC,iBAAiB,EAAE;AAC9D,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,aAAa,CAAC,iBAAiB,CAAC,CAAC;AACpE,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,eAAe,aAAa,GAAG;AACtC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACpF;;;;"}
@@ -46,6 +46,30 @@ async function getCustomerPortalAccess(session) {
46
46
  const access = await rechargeApiRequest("get", "/portal_access", {}, session);
47
47
  return access;
48
48
  }
49
+ const customerNotificationMap = {
50
+ SHOPIFY_UPDATE_PAYMENT_INFO: {
51
+ type: "email",
52
+ template_type: "shopify_update_payment_information"
53
+ }
54
+ };
55
+ async function sendCustomerNotification(session, notification) {
56
+ const customerId = session.customerId;
57
+ if (!customerId) {
58
+ throw new Error("Not logged in.");
59
+ }
60
+ const data = customerNotificationMap[notification];
61
+ if (!data) {
62
+ throw new Error("Notification not supported.");
63
+ }
64
+ return rechargeApiRequest(
65
+ "post",
66
+ `/customers/${customerId}/notifications`,
67
+ {
68
+ data
69
+ },
70
+ session
71
+ );
72
+ }
49
73
 
50
- export { getCustomer, getCustomerPortalAccess, getDeliverySchedule, updateCustomer };
74
+ export { getCustomer, getCustomerPortalAccess, getDeliverySchedule, sendCustomerNotification, updateCustomer };
51
75
  //# sourceMappingURL=customer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import { Session } from '../types/session';\nimport {\n Customer,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerPortalAccessResponse,\n Delivery,\n GetCustomerOptions,\n UpdateCustomerRequest,\n} from '../types/customer';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n session\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${id}/delivery_schedule`,\n { query },\n session\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(session: Session): Promise<CustomerPortalAccessResponse> {\n const access = await rechargeApiRequest<CustomerPortalAccessResponse>('get', '/portal_access', {}, session);\n return access;\n}\n"],"names":[],"mappings":";;AACO,eAAe,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE;AACpD,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,kBAAkB;AAC/C,IAAI,KAAK;AACT,IAAI,CAAC,UAAU,CAAC;AAChB,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,QAAQ,CAAC;AAClB,CAAC;AACM,eAAe,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE;AAC7D,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,kBAAkB;AAC/C,IAAI,KAAK;AACT,IAAI,CAAC,UAAU,CAAC;AAChB,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;AAC/B,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,QAAQ,CAAC;AAClB,CAAC;AACM,eAAe,mBAAmB,CAAC,OAAO,EAAE,KAAK,EAAE;AAC1D,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB;AACjD,IAAI,KAAK;AACT,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAAC;AACxC,IAAI,EAAE,KAAK,EAAE;AACb,IAAI,OAAO;AACX,GAAG,CAAC;AACJ,EAAE,OAAO,UAAU,CAAC;AACpB,CAAC;AACM,eAAe,uBAAuB,CAAC,OAAO,EAAE;AACvD,EAAE,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAChF,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
1
+ {"version":3,"file":"customer.js","sources":["../../../src/api/customer.ts"],"sourcesContent":["import { Session } from '../types/session';\nimport {\n Customer,\n CustomerDeliveryScheduleParams,\n CustomerDeliveryScheduleResponse,\n CustomerNotification,\n CustomerNotificationTemplate,\n CustomerNotificationType,\n CustomerPortalAccessResponse,\n Delivery,\n GetCustomerOptions,\n UpdateCustomerRequest,\n} from '../types/customer';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport async function getCustomer(session: Session, options?: GetCustomerOptions): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'get',\n `/customers`,\n {\n id,\n query: { include: options?.include },\n },\n session\n );\n return customer;\n}\n\nexport async function updateCustomer(session: Session, updateRequest: UpdateCustomerRequest): Promise<Customer> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { customer } = await rechargeApiRequest<{ customer: Customer }>(\n 'put',\n `/customers`,\n { id, data: updateRequest },\n session\n );\n return customer;\n}\n\nexport async function getDeliverySchedule(\n session: Session,\n query?: CustomerDeliveryScheduleParams\n): Promise<Delivery[]> {\n const id = session.customerId;\n if (!id) {\n throw new Error('Not logged in.');\n }\n const { deliveries } = await rechargeApiRequest<CustomerDeliveryScheduleResponse>(\n 'get',\n `/customers/${id}/delivery_schedule`,\n { query },\n session\n );\n return deliveries;\n}\n\nexport async function getCustomerPortalAccess(session: Session): Promise<CustomerPortalAccessResponse> {\n const access = await rechargeApiRequest<CustomerPortalAccessResponse>('get', '/portal_access', {}, session);\n return access;\n}\n\nconst customerNotificationMap: Record<\n CustomerNotification,\n { type: CustomerNotificationType; template_type: CustomerNotificationTemplate }\n> = {\n SHOPIFY_UPDATE_PAYMENT_INFO: {\n type: 'email',\n template_type: 'shopify_update_payment_information',\n },\n};\n\nexport async function sendCustomerNotification(session: Session, notification: CustomerNotification): Promise<void> {\n const customerId = session.customerId;\n if (!customerId) {\n throw new Error('Not logged in.');\n }\n const data = customerNotificationMap[notification];\n if (!data) {\n throw new Error('Notification not supported.');\n }\n return rechargeApiRequest<void>(\n 'post',\n `/customers/${customerId}/notifications`,\n {\n data,\n },\n session\n );\n}\n"],"names":[],"mappings":";;AACO,eAAe,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE;AACpD,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;AAChC,EAAE,IAAI,CAAC,EAAE,EAAE;AACX,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,kBAAkB;AAC/C,IAAI,KAAK;AACT,IAAI,CAAC,UAAU,CAAC;AAChB,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,QAAQ,CAAC;AAClB,CAAC;AACM,eAAe,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE;AAC7D,EAAE,MAAM,EAAE,GAAG,OAAO,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AAC;AACxC,EAAE,IAAI,CAAC,UAAU,EAAE;AACnB,IAAI,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACtC,GAAG;AACH,EAAE,MAAM,IAAI,GAAG,uBAAuB,CAAC,YAAY,CAAC,CAAC;AACrD,EAAE,IAAI,CAAC,IAAI,EAAE;AACb,IAAI,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;AACnD,GAAG;AACH,EAAE,OAAO,kBAAkB;AAC3B,IAAI,MAAM;AACV,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,cAAc,CAAC;AAC5C,IAAI;AACJ,MAAM,IAAI;AACV,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ;;;;"}
@@ -0,0 +1,21 @@
1
+ import { rechargeApiRequest } from '../utils/request.js';
2
+
3
+ async function productSearch(session, query) {
4
+ if (!["2020-12", "2022-06"].includes(query.format_version)) {
5
+ throw new Error("Missing or unsupported format_version.");
6
+ }
7
+ return rechargeApiRequest(
8
+ "get",
9
+ `/product_search`,
10
+ {
11
+ query,
12
+ headers: {
13
+ "X-Recharge-Version": "2021-01"
14
+ }
15
+ },
16
+ session
17
+ );
18
+ }
19
+
20
+ export { productSearch };
21
+ //# sourceMappingURL=product.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.js","sources":["../../../src/api/product.ts"],"sourcesContent":["import {\n ProductSearchParams_2020_12,\n ProductSearchParams_2022_06,\n ProductSearchResponse_2020_12,\n ProductSearchResponse_2022_06,\n} from '../types';\nimport { Session } from '../types/session';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport type ProductSearchType<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06> =\n T extends ProductSearchParams_2020_12 ? ProductSearchResponse_2020_12 : ProductSearchResponse_2022_06;\n\nexport async function productSearch<T extends ProductSearchParams_2020_12 | ProductSearchParams_2022_06>(\n session: Session,\n query: T\n): Promise<ProductSearchType<T>> {\n if (!['2020-12', '2022-06'].includes(query.format_version)) {\n throw new Error('Missing or unsupported format_version.');\n }\n return rechargeApiRequest<ProductSearchType<T>>(\n 'get',\n `/product_search`,\n {\n query,\n headers: {\n 'X-Recharge-Version': '2021-01',\n },\n },\n session\n );\n}\n"],"names":[],"mappings":";;AACO,eAAe,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE;AACpD,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;AAC9D,IAAI,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC9D,GAAG;AACH,EAAE,OAAO,kBAAkB;AAC3B,IAAI,KAAK;AACT,IAAI,CAAC,eAAe,CAAC;AACrB,IAAI;AACJ,MAAM,KAAK;AACX,MAAM,OAAO,EAAE;AACf,QAAQ,oBAAoB,EAAE,SAAS;AACvC,OAAO;AACP,KAAK;AACL,IAAI,OAAO;AACX,GAAG,CAAC;AACJ;;;;"}
package/dist/esm/index.js CHANGED
@@ -10,7 +10,8 @@ export { createOnetime, deleteOnetime, getOnetime, listOnetimes, updateOnetime }
10
10
  export { getOrder, listOrders } from './api/order.js';
11
11
  export { getPaymentMethod, listPaymentMethods, updatePaymentMethod } from './api/paymentMethod.js';
12
12
  export { getPlan, listPlans } from './api/plan.js';
13
+ export { productSearch } from './api/product.js';
13
14
  export { activateSubscription, cancelSubscription, createSubscription, createSubscriptions, getSubscription, listSubscriptions, skipGiftSubscriptionCharge, skipSubscriptionCharge, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate, updateSubscriptions } from './api/subscription.js';
14
- export { getCustomer, getCustomerPortalAccess, getDeliverySchedule, updateCustomer } from './api/customer.js';
15
+ export { getCustomer, getCustomerPortalAccess, getDeliverySchedule, sendCustomerNotification, updateCustomer } from './api/customer.js';
15
16
  export { api, initRecharge } from './utils/init.js';
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}