@rechargeapps/storefront-client 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var request = require('../utils/request.js');
6
+
7
+ async function getCharge(id) {
8
+ const { charge } = await request.rechargeApiRequest("get", `/charges`, { id });
9
+ return charge;
10
+ }
11
+ function listCharges(query) {
12
+ return request.rechargeApiRequest("get", `/charges`, { query });
13
+ }
14
+ async function applyDiscount(id, request$1) {
15
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/apply_discount`, {
16
+ data: request$1
17
+ });
18
+ return charge;
19
+ }
20
+ async function removeDiscount(id) {
21
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/remove_discount`);
22
+ return charge;
23
+ }
24
+ async function skipCharge(id) {
25
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/skip`);
26
+ return charge;
27
+ }
28
+ async function unskipCharge(id) {
29
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/unskip`);
30
+ return charge;
31
+ }
32
+ async function refundCharge(id, request$1) {
33
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/refund`, { data: request$1 });
34
+ return charge;
35
+ }
36
+ async function processCharge(id) {
37
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/process`);
38
+ return charge;
39
+ }
40
+ async function captureCharge(id) {
41
+ const { charge } = await request.rechargeApiRequest("post", `/charges/${id}/capture_payment`);
42
+ return charge;
43
+ }
44
+
45
+ exports.applyDiscount = applyDiscount;
46
+ exports.captureCharge = captureCharge;
47
+ exports.getCharge = getCharge;
48
+ exports.listCharges = listCharges;
49
+ exports.processCharge = processCharge;
50
+ exports.refundCharge = refundCharge;
51
+ exports.removeDiscount = removeDiscount;
52
+ exports.skipCharge = skipCharge;
53
+ exports.unskipCharge = unskipCharge;
54
+ //# sourceMappingURL=charge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charge.js","sources":["../../../src/api/charge.ts"],"sourcesContent":["import {\n ApplyDiscountRequest,\n ChargeListParams,\n ChargeListResponse,\n ChargeResponse,\n RefundChargeRequest,\n} from '../types/charge';\nimport { rechargeApiRequest } from '../utils/request';\n\n/* Retrieve a Charge using the charge_id. */\nexport async function getCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('get', `/charges`, { id });\n return charge;\n}\n\n/** Lists charges */\nexport function listCharges(query?: ChargeListParams) {\n return rechargeApiRequest<ChargeListResponse>('get', `/charges`, { query });\n}\n\n/**\n * You cannot add a Discount to an existing queued Charge if the Charge or the associated Address already has one.\n * You can provide either discount_id or discount_code. If both parameters are passed, the value for discount_id will take precedence.\n * If a Charge has a Discount and it gets updated, or a regeneration occurs, the Discount will be lost. Regeneration is a process that refreshes the Charge JSON with new data in the case of the Subscription or Address being updated.\n */\nexport async function applyDiscount(id: number | string, request: ApplyDiscountRequest) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/apply_discount`, {\n data: request,\n });\n return charge;\n}\n\n/**\n * Remove a Discount from a Charge without destroying the Discount.\n * In most cases the Discount should be removed from the Address. When the Discount is removed from the Address, the Discount is also removed from any future Charges.\n * If the Discount is on the parent Address, you cannot remove it using charge_id.\n * When removing your Discount, it is preferable to pass the address_id so that the Discount stays removed if the Charge is regenerated. Only pass charge_id in edge cases in which there are two or more Charges on a parent Address and you only want to remove the Discount from one Charge.\n * If you pass both parameters, it will remove the Discount from the Address.\n */\nexport async function removeDiscount(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/remove_discount`);\n return charge;\n}\n\n/* Skip a Charge. */\nexport async function skipCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/skip`);\n return charge;\n}\n\n/* Unskip a Charge. */\nexport async function unskipCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/unskip`);\n return charge;\n}\n\n/*\n * Refund a Charge.\n * After the POST request, that particular Charge will have status parameter updated to refunded or partially_refunded depending on the value of the amount parameter.\n */\nexport async function refundCharge(id: number | string, request: RefundChargeRequest) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/refund`, { data: request });\n return charge;\n}\n\n/** The charge processing route can be used to process Charges that are in a queued or error status. */\nexport async function processCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/process`);\n return charge;\n}\n\n/**\n * If you are leveraging the authorize/capture workflow with Recharge, the charge/{id}/capture_payment endpoint is how to capture the funds of a previously authorized Charge.\n */\nexport async function captureCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/capture_payment`);\n return charge;\n}\n"],"names":["rechargeApiRequest","request"],"mappings":";;;;;;AACO,eAAe,SAAS,CAAC,EAAE,EAAE;AACpC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACzE,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,SAAS,WAAW,CAAC,KAAK,EAAE;AACnC,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,CAAC;AACM,eAAe,aAAa,CAAC,EAAE,EAAEC,SAAO,EAAE;AACjD,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAMD,0BAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE;AACvF,IAAI,IAAI,EAAEC,SAAO;AACjB,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,cAAc,CAAC,EAAE,EAAE;AACzC,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AO,MAAM,CAAC;AAChB;;;;;;;;;;;;"}
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var request = require('../utils/request.js');
6
+
7
+ const getOnetime = async (id) => {
8
+ const { onetime } = await request.rechargeApiRequest("get", `/onetimes`, {
9
+ id
10
+ });
11
+ return onetime;
12
+ };
13
+ const listOnetimes = (query) => {
14
+ return request.rechargeApiRequest("get", `/onetimes`, { query });
15
+ };
16
+ const createOnetime = async (data) => {
17
+ const { onetime } = await request.rechargeApiRequest("post", `/onetimes`, {
18
+ data
19
+ });
20
+ return onetime;
21
+ };
22
+ const updateOnetime = async (id, data) => {
23
+ const { onetime } = await request.rechargeApiRequest("put", `/onetimes`, {
24
+ id,
25
+ data
26
+ });
27
+ return onetime;
28
+ };
29
+ const deleteOnetime = (id) => {
30
+ return request.rechargeApiRequest("delete", `/onetime`, {
31
+ id
32
+ });
33
+ };
34
+
35
+ exports.createOnetime = createOnetime;
36
+ exports.deleteOnetime = deleteOnetime;
37
+ exports.getOnetime = getOnetime;
38
+ exports.listOnetimes = listOnetimes;
39
+ exports.updateOnetime = updateOnetime;
40
+ //# sourceMappingURL=onetime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onetime.js","sources":["../../../src/api/onetime.ts"],"sourcesContent":["import {\n CreateOnetimeRequest,\n Onetime,\n OnetimeListParams,\n OnetimesResponse,\n UpdateOnetimeRequest,\n} from '../types/onetime';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport const getOnetime = async (id: string | number): Promise<Onetime> => {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>('get', `/onetimes`, {\n id,\n });\n return onetime;\n};\n\nexport const listOnetimes = (query?: OnetimeListParams): Promise<OnetimesResponse> => {\n return rechargeApiRequest<OnetimesResponse>('get', `/onetimes`, { query });\n};\n\nexport const createOnetime = async (data: CreateOnetimeRequest): Promise<Onetime> => {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>('post', `/onetimes`, {\n data,\n });\n return onetime;\n};\n\nexport const updateOnetime = async (id: string | number, data: UpdateOnetimeRequest): Promise<Onetime> => {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>('put', `/onetimes`, {\n id,\n data,\n });\n return onetime;\n};\n\nexport const deleteOnetime = (id: string | number): Promise<void> => {\n return rechargeApiRequest<void>('delete', `/onetime`, {\n id,\n });\n};\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACY,MAAC,UAAU,GAAG,OAAO,EAAE,KAAK;AACxC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;AACnE,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,OAAO,CAAC;AACjB,EAAE;AACU,MAAC,YAAY,GAAG,CAAC,KAAK,KAAK;AACvC,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC3D,EAAE;AACU,MAAC,aAAa,GAAG,OAAO,IAAI,KAAK;AAC7C,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE;AACpE,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,OAAO,CAAC;AACjB,EAAE;AACU,MAAC,aAAa,GAAG,OAAO,EAAE,EAAE,IAAI,KAAK;AACjD,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;AACnE,IAAI,EAAE;AACN,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,OAAO,CAAC;AACjB,EAAE;AACU,MAAC,aAAa,GAAG,CAAC,EAAE,KAAK;AACrC,EAAE,OAAOA,0BAAkB,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE;AAClD,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL;;;;;;;;"}
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var request = require('../utils/request.js');
6
+
7
+ const getOrder = async (id) => {
8
+ const { order } = await request.rechargeApiRequest("get", `/orders`, {
9
+ id
10
+ });
11
+ return order;
12
+ };
13
+ const listOrders = (query) => {
14
+ return request.rechargeApiRequest("get", `/orders`, { query });
15
+ };
16
+
17
+ exports.getOrder = getOrder;
18
+ exports.listOrders = listOrders;
19
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse } from '../types/order';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport const getOrder = async (id: string | number): Promise<Order> => {\n const { order } = await rechargeApiRequest<{ order: Order }>('get', `/orders`, {\n id,\n });\n return order;\n};\n\nexport const listOrders = (query?: OrderListParams): Promise<OrdersResponse> => {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query });\n};\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACY,MAAC,QAAQ,GAAG,OAAO,EAAE,KAAK;AACtC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE;AAC/D,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,KAAK,CAAC;AACf,EAAE;AACU,MAAC,UAAU,GAAG,CAAC,KAAK,KAAK;AACrC,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AACzD;;;;;"}
@@ -4,9 +4,58 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var request = require('../utils/request.js');
6
6
 
7
+ const getSubscription = async (id) => {
8
+ const { subscription } = await request.rechargeApiRequest("get", `/subscriptions`, {
9
+ id
10
+ });
11
+ return subscription;
12
+ };
7
13
  const listSubscriptions = (query) => {
8
14
  return request.rechargeApiRequest("get", `/subscriptions`, { query });
9
15
  };
16
+ const createSubscription = async (data) => {
17
+ const { subscription } = await request.rechargeApiRequest("post", `/subscriptions`, {
18
+ data
19
+ });
20
+ return subscription;
21
+ };
22
+ const updateSubscription = async (id, data, query) => {
23
+ const { subscription } = await request.rechargeApiRequest("put", `/subscriptions`, {
24
+ id,
25
+ data,
26
+ query
27
+ });
28
+ return subscription;
29
+ };
30
+ const updateSubscriptionChargeDate = async (id, date) => {
31
+ const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/set_next_charge_date`, {
32
+ data: { date }
33
+ });
34
+ return subscription;
35
+ };
36
+ const updateSubscriptionAddress = async (id, address_id) => {
37
+ const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/change_address`, {
38
+ data: { address_id }
39
+ });
40
+ return subscription;
41
+ };
42
+ const cancelSubscription = async (id, data) => {
43
+ const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/cancel`, {
44
+ data
45
+ });
46
+ return subscription;
47
+ };
48
+ const activateSubscription = async (id) => {
49
+ const { subscription } = await request.rechargeApiRequest("post", `/subscriptions/${id}/activate`);
50
+ return subscription;
51
+ };
10
52
 
53
+ exports.activateSubscription = activateSubscription;
54
+ exports.cancelSubscription = cancelSubscription;
55
+ exports.createSubscription = createSubscription;
56
+ exports.getSubscription = getSubscription;
11
57
  exports.listSubscriptions = listSubscriptions;
58
+ exports.updateSubscription = updateSubscription;
59
+ exports.updateSubscriptionAddress = updateSubscriptionAddress;
60
+ exports.updateSubscriptionChargeDate = updateSubscriptionChargeDate;
12
61
  //# sourceMappingURL=subscription.js.map
@@ -1 +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":["rechargeApiRequest"],"mappings":";;;;;;AACY,MAAC,iBAAiB,GAAG,CAAC,KAAK,KAAK;AAC5C,EAAE,OAAOA,0BAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAChE;;;;"}
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';\n\nexport const getSubscription = async (id: string | number): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>('get', `/subscriptions`, {\n id,\n });\n return subscription;\n};\n\nexport const listSubscriptions = (query?: SubscriptionListParams): Promise<SubscriptionsResponse> => {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query });\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 const createSubscription = async (data: CreateSubscriptionRequest): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>('post', `/subscriptions`, {\n data,\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 const updateSubscription = async (\n id: string | number,\n data: UpdateSubscriptionRequest,\n query?: UpdateSubscriptionParams\n): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>('put', `/subscriptions`, {\n id,\n data,\n query,\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 const updateSubscriptionChargeDate = async (id: string | number, date: IsoDateString): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n }\n );\n return subscription;\n};\n\nexport const updateSubscriptionAddress = async (\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 );\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 const cancelSubscription = async (\n id: string | number,\n data: CancelSubscriptionRequest\n): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data,\n }\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 const activateSubscription = async (id: string | number): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`\n );\n return subscription;\n};\n"],"names":["rechargeApiRequest"],"mappings":";;;;;;AACY,MAAC,eAAe,GAAG,OAAO,EAAE,KAAK;AAC7C,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,KAAK,EAAE,CA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C,EAAE;AACnG,IAAI,IAAI,EAAE,EAAE,UAAU,EAAE;AACxB,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,kBAAkB,GAAG,OAAO,EAAE,EAAE,IAAI,KAAK;AACtD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;AAC3F,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,oBAAoB,GAAG,OAAO,EAAE,KAAK;AAClD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAMA,0BAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7F,EAAE,OAAO,YAAY,CAAC;AACtB;;;;;;;;;;;"}
package/dist/cjs/index.js CHANGED
@@ -3,8 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var auth = require('./api/auth.js');
6
+ var charge = require('./api/charge.js');
6
7
  var cdn = require('./api/cdn.js');
7
8
  var bundle = require('./api/bundle.js');
9
+ var onetime = require('./api/onetime.js');
10
+ var order = require('./api/order.js');
8
11
  var subscription = require('./api/subscription.js');
9
12
  var init = require('./utils/init.js');
10
13
 
@@ -12,6 +15,15 @@ var init = require('./utils/init.js');
12
15
 
13
16
  exports.login = auth.login;
14
17
  exports.logout = auth.logout;
18
+ exports.applyDiscount = charge.applyDiscount;
19
+ exports.captureCharge = charge.captureCharge;
20
+ exports.getCharge = charge.getCharge;
21
+ exports.listCharges = charge.listCharges;
22
+ exports.processCharge = charge.processCharge;
23
+ exports.refundCharge = charge.refundCharge;
24
+ exports.removeDiscount = charge.removeDiscount;
25
+ exports.skipCharge = charge.skipCharge;
26
+ exports.unskipCharge = charge.unskipCharge;
15
27
  exports.getBundleSettings = cdn.getBundleSettings;
16
28
  exports.getProduct = cdn.getProduct;
17
29
  exports.getProductAndSettings = cdn.getProductAndSettings;
@@ -22,7 +34,21 @@ exports.getWidgetSettings = cdn.getWidgetSettings;
22
34
  exports.resetCache = cdn.resetCache;
23
35
  exports.getBundleId = bundle.getBundleId;
24
36
  exports.validateBundle = bundle.validateBundle;
37
+ exports.createOnetime = onetime.createOnetime;
38
+ exports.deleteOnetime = onetime.deleteOnetime;
39
+ exports.getOnetime = onetime.getOnetime;
40
+ exports.listOnetimes = onetime.listOnetimes;
41
+ exports.updateOnetime = onetime.updateOnetime;
42
+ exports.getOrder = order.getOrder;
43
+ exports.listOrders = order.listOrders;
44
+ exports.activateSubscription = subscription.activateSubscription;
45
+ exports.cancelSubscription = subscription.cancelSubscription;
46
+ exports.createSubscription = subscription.createSubscription;
47
+ exports.getSubscription = subscription.getSubscription;
25
48
  exports.listSubscriptions = subscription.listSubscriptions;
49
+ exports.updateSubscription = subscription.updateSubscription;
50
+ exports.updateSubscriptionAddress = subscription.updateSubscriptionAddress;
51
+ exports.updateSubscriptionChargeDate = subscription.updateSubscriptionChargeDate;
26
52
  exports.api = init.api;
27
53
  exports.initRecharge = init.initRecharge;
28
54
  //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -5,16 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  require('isomorphic-fetch');
6
6
  var Cookies = require('js-cookie');
7
7
  var qs = require('qs');
8
- var trimStart = require('lodash/trimStart');
9
- var trimEnd = require('lodash/trimEnd');
10
8
  var options = require('./options.js');
11
9
  var api = require('../constants/api.js');
12
10
 
13
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
12
 
15
13
  var Cookies__default = /*#__PURE__*/_interopDefaultLegacy(Cookies);
16
- var trimStart__default = /*#__PURE__*/_interopDefaultLegacy(trimStart);
17
- var trimEnd__default = /*#__PURE__*/_interopDefaultLegacy(trimEnd);
18
14
 
19
15
  var __defProp = Object.defineProperty;
20
16
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -70,17 +66,18 @@ async function shopifyAppProxyRequest(method, url, { id, query, data, headers }
70
66
  return request(method, `${api.SHOPIFY_APP_PROXY_URL}${url}`, { id, query, data, headers: reqHeaders });
71
67
  }
72
68
  async function request(method, url, { id, query, data, headers } = {}) {
73
- let reqUrl = url;
69
+ let reqUrl = url.trim();
74
70
  if (id) {
75
- reqUrl = [trimEnd__default["default"](url), trimStart__default["default"](id)].join("/");
71
+ reqUrl = [reqUrl, `${id}`.trim()].join("/");
76
72
  }
77
- let reqBody;
78
- if (method === "get") {
73
+ if (query) {
79
74
  let exQuery;
80
75
  [reqUrl, exQuery] = reqUrl.split("?");
81
76
  const fullQuery = [exQuery, stringifyQuery(query)].join("&").replace(/^&/, "");
82
77
  reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ""}`;
83
- } else {
78
+ }
79
+ let reqBody;
80
+ if (data && method !== "get") {
84
81
  reqBody = JSON.stringify(data);
85
82
  }
86
83
  const reqHeaders = __spreadValues({
@@ -92,7 +89,11 @@ async function request(method, url, { id, query, data, headers } = {}) {
92
89
  body: reqBody,
93
90
  mode: "cors"
94
91
  });
95
- const result = await response.json();
92
+ let result;
93
+ try {
94
+ result = await response.json();
95
+ } catch (e) {
96
+ }
96
97
  if (!response.ok) {
97
98
  if (result && result.error) {
98
99
  throw new Error(`${response.status}: ${result.error}`);
@@ -1 +1 @@
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":["stringify","getOptions","RECHARGE_CDN_URL","Cookies","RECHARGE_API_URL","SHOPIFY_APP_PROXY_URL","trimEnd","trimStart"],"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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AACvB,IAAI,IAAI,EAAE,OAAO;AACjB,IAAI,IAAI,EAAE,MAAM;AAChB,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;AACvC,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AACpB,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE;AAChC,MAAM,MAAM,IAAI,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC7D,KAAK,MAAM;AACX,MAAM,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC9E,KAAK;AACL,GAAG;AACH,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;"}
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';\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.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","Cookies","RECHARGE_API_URL","SHOPIFY_APP_PROXY_URL"],"mappings":";;;;;;;;;;;;;;AAAA,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;AACL,GAAG;AACH,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;"}
@@ -0,0 +1,42 @@
1
+ import { rechargeApiRequest } from '../utils/request.js';
2
+
3
+ async function getCharge(id) {
4
+ const { charge } = await rechargeApiRequest("get", `/charges`, { id });
5
+ return charge;
6
+ }
7
+ function listCharges(query) {
8
+ return rechargeApiRequest("get", `/charges`, { query });
9
+ }
10
+ async function applyDiscount(id, request) {
11
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/apply_discount`, {
12
+ data: request
13
+ });
14
+ return charge;
15
+ }
16
+ async function removeDiscount(id) {
17
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/remove_discount`);
18
+ return charge;
19
+ }
20
+ async function skipCharge(id) {
21
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/skip`);
22
+ return charge;
23
+ }
24
+ async function unskipCharge(id) {
25
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/unskip`);
26
+ return charge;
27
+ }
28
+ async function refundCharge(id, request) {
29
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/refund`, { data: request });
30
+ return charge;
31
+ }
32
+ async function processCharge(id) {
33
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/process`);
34
+ return charge;
35
+ }
36
+ async function captureCharge(id) {
37
+ const { charge } = await rechargeApiRequest("post", `/charges/${id}/capture_payment`);
38
+ return charge;
39
+ }
40
+
41
+ export { applyDiscount, captureCharge, getCharge, listCharges, processCharge, refundCharge, removeDiscount, skipCharge, unskipCharge };
42
+ //# sourceMappingURL=charge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charge.js","sources":["../../../src/api/charge.ts"],"sourcesContent":["import {\n ApplyDiscountRequest,\n ChargeListParams,\n ChargeListResponse,\n ChargeResponse,\n RefundChargeRequest,\n} from '../types/charge';\nimport { rechargeApiRequest } from '../utils/request';\n\n/* Retrieve a Charge using the charge_id. */\nexport async function getCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('get', `/charges`, { id });\n return charge;\n}\n\n/** Lists charges */\nexport function listCharges(query?: ChargeListParams) {\n return rechargeApiRequest<ChargeListResponse>('get', `/charges`, { query });\n}\n\n/**\n * You cannot add a Discount to an existing queued Charge if the Charge or the associated Address already has one.\n * You can provide either discount_id or discount_code. If both parameters are passed, the value for discount_id will take precedence.\n * If a Charge has a Discount and it gets updated, or a regeneration occurs, the Discount will be lost. Regeneration is a process that refreshes the Charge JSON with new data in the case of the Subscription or Address being updated.\n */\nexport async function applyDiscount(id: number | string, request: ApplyDiscountRequest) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/apply_discount`, {\n data: request,\n });\n return charge;\n}\n\n/**\n * Remove a Discount from a Charge without destroying the Discount.\n * In most cases the Discount should be removed from the Address. When the Discount is removed from the Address, the Discount is also removed from any future Charges.\n * If the Discount is on the parent Address, you cannot remove it using charge_id.\n * When removing your Discount, it is preferable to pass the address_id so that the Discount stays removed if the Charge is regenerated. Only pass charge_id in edge cases in which there are two or more Charges on a parent Address and you only want to remove the Discount from one Charge.\n * If you pass both parameters, it will remove the Discount from the Address.\n */\nexport async function removeDiscount(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/remove_discount`);\n return charge;\n}\n\n/* Skip a Charge. */\nexport async function skipCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/skip`);\n return charge;\n}\n\n/* Unskip a Charge. */\nexport async function unskipCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/unskip`);\n return charge;\n}\n\n/*\n * Refund a Charge.\n * After the POST request, that particular Charge will have status parameter updated to refunded or partially_refunded depending on the value of the amount parameter.\n */\nexport async function refundCharge(id: number | string, request: RefundChargeRequest) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/refund`, { data: request });\n return charge;\n}\n\n/** The charge processing route can be used to process Charges that are in a queued or error status. */\nexport async function processCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/process`);\n return charge;\n}\n\n/**\n * If you are leveraging the authorize/capture workflow with Recharge, the charge/{id}/capture_payment endpoint is how to capture the funds of a previously authorized Charge.\n */\nexport async function captureCharge(id: number | string) {\n const { charge } = await rechargeApiRequest<ChargeResponse>('post', `/charges/${id}/capture_payment`);\n return charge;\n}\n"],"names":[],"mappings":";;AACO,eAAe,SAAS,CAAC,EAAE,EAAE;AACpC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACzE,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,SAAS,WAAW,CAAC,KAAK,EAAE;AACnC,EAAE,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,CAAC;AACM,eAAe,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE;AACjD,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE;AACvF,IAAI,IAAI,EAAE,OAAO;AACjB,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,cAAc,CAAC,EAAE,EAAE;AACzC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACxF,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,UAAU,CAAC,EAAE,EAAE;AACrC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7E,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,YAAY,CAAC,EAAE,EAAE;AACvC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/E,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE;AAChD,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAClG,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,aAAa,CAAC,EAAE,EAAE;AACxC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAChF,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC;AACM,eAAe,aAAa,CAAC,EAAE,EAAE;AACxC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACxF,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
@@ -0,0 +1,32 @@
1
+ import { rechargeApiRequest } from '../utils/request.js';
2
+
3
+ const getOnetime = async (id) => {
4
+ const { onetime } = await rechargeApiRequest("get", `/onetimes`, {
5
+ id
6
+ });
7
+ return onetime;
8
+ };
9
+ const listOnetimes = (query) => {
10
+ return rechargeApiRequest("get", `/onetimes`, { query });
11
+ };
12
+ const createOnetime = async (data) => {
13
+ const { onetime } = await rechargeApiRequest("post", `/onetimes`, {
14
+ data
15
+ });
16
+ return onetime;
17
+ };
18
+ const updateOnetime = async (id, data) => {
19
+ const { onetime } = await rechargeApiRequest("put", `/onetimes`, {
20
+ id,
21
+ data
22
+ });
23
+ return onetime;
24
+ };
25
+ const deleteOnetime = (id) => {
26
+ return rechargeApiRequest("delete", `/onetime`, {
27
+ id
28
+ });
29
+ };
30
+
31
+ export { createOnetime, deleteOnetime, getOnetime, listOnetimes, updateOnetime };
32
+ //# sourceMappingURL=onetime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onetime.js","sources":["../../../src/api/onetime.ts"],"sourcesContent":["import {\n CreateOnetimeRequest,\n Onetime,\n OnetimeListParams,\n OnetimesResponse,\n UpdateOnetimeRequest,\n} from '../types/onetime';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport const getOnetime = async (id: string | number): Promise<Onetime> => {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>('get', `/onetimes`, {\n id,\n });\n return onetime;\n};\n\nexport const listOnetimes = (query?: OnetimeListParams): Promise<OnetimesResponse> => {\n return rechargeApiRequest<OnetimesResponse>('get', `/onetimes`, { query });\n};\n\nexport const createOnetime = async (data: CreateOnetimeRequest): Promise<Onetime> => {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>('post', `/onetimes`, {\n data,\n });\n return onetime;\n};\n\nexport const updateOnetime = async (id: string | number, data: UpdateOnetimeRequest): Promise<Onetime> => {\n const { onetime } = await rechargeApiRequest<{ onetime: Onetime }>('put', `/onetimes`, {\n id,\n data,\n });\n return onetime;\n};\n\nexport const deleteOnetime = (id: string | number): Promise<void> => {\n return rechargeApiRequest<void>('delete', `/onetime`, {\n id,\n });\n};\n"],"names":[],"mappings":";;AACY,MAAC,UAAU,GAAG,OAAO,EAAE,KAAK;AACxC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;AACnE,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,OAAO,CAAC;AACjB,EAAE;AACU,MAAC,YAAY,GAAG,CAAC,KAAK,KAAK;AACvC,EAAE,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC3D,EAAE;AACU,MAAC,aAAa,GAAG,OAAO,IAAI,KAAK;AAC7C,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE;AACpE,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,OAAO,CAAC;AACjB,EAAE;AACU,MAAC,aAAa,GAAG,OAAO,EAAE,EAAE,IAAI,KAAK;AACjD,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE;AACnE,IAAI,EAAE;AACN,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,OAAO,CAAC;AACjB,EAAE;AACU,MAAC,aAAa,GAAG,CAAC,EAAE,KAAK;AACrC,EAAE,OAAO,kBAAkB,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE;AAClD,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL;;;;"}
@@ -0,0 +1,14 @@
1
+ import { rechargeApiRequest } from '../utils/request.js';
2
+
3
+ const getOrder = async (id) => {
4
+ const { order } = await rechargeApiRequest("get", `/orders`, {
5
+ id
6
+ });
7
+ return order;
8
+ };
9
+ const listOrders = (query) => {
10
+ return rechargeApiRequest("get", `/orders`, { query });
11
+ };
12
+
13
+ export { getOrder, listOrders };
14
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.js","sources":["../../../src/api/order.ts"],"sourcesContent":["import { Order, OrderListParams, OrdersResponse } from '../types/order';\nimport { rechargeApiRequest } from '../utils/request';\n\nexport const getOrder = async (id: string | number): Promise<Order> => {\n const { order } = await rechargeApiRequest<{ order: Order }>('get', `/orders`, {\n id,\n });\n return order;\n};\n\nexport const listOrders = (query?: OrderListParams): Promise<OrdersResponse> => {\n return rechargeApiRequest<OrdersResponse>('get', `/orders`, { query });\n};\n"],"names":[],"mappings":";;AACY,MAAC,QAAQ,GAAG,OAAO,EAAE,KAAK;AACtC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE;AAC/D,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,KAAK,CAAC;AACf,EAAE;AACU,MAAC,UAAU,GAAG,CAAC,KAAK,KAAK;AACrC,EAAE,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AACzD;;;;"}
@@ -1,8 +1,50 @@
1
1
  import { rechargeApiRequest } from '../utils/request.js';
2
2
 
3
+ const getSubscription = async (id) => {
4
+ const { subscription } = await rechargeApiRequest("get", `/subscriptions`, {
5
+ id
6
+ });
7
+ return subscription;
8
+ };
3
9
  const listSubscriptions = (query) => {
4
10
  return rechargeApiRequest("get", `/subscriptions`, { query });
5
11
  };
12
+ const createSubscription = async (data) => {
13
+ const { subscription } = await rechargeApiRequest("post", `/subscriptions`, {
14
+ data
15
+ });
16
+ return subscription;
17
+ };
18
+ const updateSubscription = async (id, data, query) => {
19
+ const { subscription } = await rechargeApiRequest("put", `/subscriptions`, {
20
+ id,
21
+ data,
22
+ query
23
+ });
24
+ return subscription;
25
+ };
26
+ const updateSubscriptionChargeDate = async (id, date) => {
27
+ const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/set_next_charge_date`, {
28
+ data: { date }
29
+ });
30
+ return subscription;
31
+ };
32
+ const updateSubscriptionAddress = async (id, address_id) => {
33
+ const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/change_address`, {
34
+ data: { address_id }
35
+ });
36
+ return subscription;
37
+ };
38
+ const cancelSubscription = async (id, data) => {
39
+ const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/cancel`, {
40
+ data
41
+ });
42
+ return subscription;
43
+ };
44
+ const activateSubscription = async (id) => {
45
+ const { subscription } = await rechargeApiRequest("post", `/subscriptions/${id}/activate`);
46
+ return subscription;
47
+ };
6
48
 
7
- export { listSubscriptions };
49
+ export { activateSubscription, cancelSubscription, createSubscription, getSubscription, listSubscriptions, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate };
8
50
  //# sourceMappingURL=subscription.js.map
@@ -1 +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
+ {"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';\n\nexport const getSubscription = async (id: string | number): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>('get', `/subscriptions`, {\n id,\n });\n return subscription;\n};\n\nexport const listSubscriptions = (query?: SubscriptionListParams): Promise<SubscriptionsResponse> => {\n return rechargeApiRequest<SubscriptionsResponse>('get', `/subscriptions`, { query });\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 const createSubscription = async (data: CreateSubscriptionRequest): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>('post', `/subscriptions`, {\n data,\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 const updateSubscription = async (\n id: string | number,\n data: UpdateSubscriptionRequest,\n query?: UpdateSubscriptionParams\n): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>('put', `/subscriptions`, {\n id,\n data,\n query,\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 const updateSubscriptionChargeDate = async (id: string | number, date: IsoDateString): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/set_next_charge_date`,\n {\n data: { date },\n }\n );\n return subscription;\n};\n\nexport const updateSubscriptionAddress = async (\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 );\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 const cancelSubscription = async (\n id: string | number,\n data: CancelSubscriptionRequest\n): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/cancel`,\n {\n data,\n }\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 const activateSubscription = async (id: string | number): Promise<Subscription> => {\n const { subscription } = await rechargeApiRequest<{ subscription: Subscription }>(\n 'post',\n `/subscriptions/${id}/activate`\n );\n return subscription;\n};\n"],"names":[],"mappings":";;AACY,MAAC,eAAe,GAAG,OAAO,EAAE,KAAK;AAC7C,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,iBAAiB,GAAG,CAAC,KAAK,KAAK;AAC5C,EAAE,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAChE,EAAE;AACU,MAAC,kBAAkB,GAAG,OAAO,IAAI,KAAK;AAClD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE;AAC9E,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,kBAAkB,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,KAAK;AAC7D,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE;AAC7E,IAAI,EAAE;AACN,IAAI,IAAI;AACR,IAAI,KAAK;AACT,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,4BAA4B,GAAG,OAAO,EAAE,EAAE,IAAI,KAAK;AAChE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,qBAAqB,CAAC,EAAE;AACzG,IAAI,IAAI,EAAE,EAAE,IAAI,EAAE;AAClB,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,yBAAyB,GAAG,OAAO,EAAE,EAAE,UAAU,KAAK;AACnE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE;AACnG,IAAI,IAAI,EAAE,EAAE,UAAU,EAAE;AACxB,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,kBAAkB,GAAG,OAAO,EAAE,EAAE,IAAI,KAAK;AACtD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;AAC3F,IAAI,IAAI;AACR,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,YAAY,CAAC;AACtB,EAAE;AACU,MAAC,oBAAoB,GAAG,OAAO,EAAE,KAAK;AAClD,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7F,EAAE,OAAO,YAAY,CAAC;AACtB;;;;"}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export { login, logout } from './api/auth.js';
2
+ export { applyDiscount, captureCharge, getCharge, listCharges, processCharge, refundCharge, removeDiscount, skipCharge, unskipCharge } from './api/charge.js';
2
3
  export { getBundleSettings, getProduct, getProductAndSettings, getProducts, getProductsAndSettings, getStoreSettings, getWidgetSettings, resetCache } from './api/cdn.js';
3
4
  export { getBundleId, validateBundle } from './api/bundle.js';
4
- export { listSubscriptions } from './api/subscription.js';
5
+ export { createOnetime, deleteOnetime, getOnetime, listOnetimes, updateOnetime } from './api/onetime.js';
6
+ export { getOrder, listOrders } from './api/order.js';
7
+ export { activateSubscription, cancelSubscription, createSubscription, getSubscription, listSubscriptions, updateSubscription, updateSubscriptionAddress, updateSubscriptionChargeDate } from './api/subscription.js';
5
8
  export { api, initRecharge } from './utils/init.js';
6
9
  //# 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":";;;;;;;"}
@@ -1,8 +1,6 @@
1
1
  import 'isomorphic-fetch';
2
2
  import Cookies from 'js-cookie';
3
3
  import { stringify } from 'qs';
4
- import trimStart from 'lodash/trimStart';
5
- import trimEnd from 'lodash/trimEnd';
6
4
  import { getOptions } from './options.js';
7
5
  import { RECHARGE_API_URL, RECHARGE_CDN_URL, SHOPIFY_APP_PROXY_URL } from '../constants/api.js';
8
6
 
@@ -60,17 +58,18 @@ async function shopifyAppProxyRequest(method, url, { id, query, data, headers }
60
58
  return request(method, `${SHOPIFY_APP_PROXY_URL}${url}`, { id, query, data, headers: reqHeaders });
61
59
  }
62
60
  async function request(method, url, { id, query, data, headers } = {}) {
63
- let reqUrl = url;
61
+ let reqUrl = url.trim();
64
62
  if (id) {
65
- reqUrl = [trimEnd(url), trimStart(id)].join("/");
63
+ reqUrl = [reqUrl, `${id}`.trim()].join("/");
66
64
  }
67
- let reqBody;
68
- if (method === "get") {
65
+ if (query) {
69
66
  let exQuery;
70
67
  [reqUrl, exQuery] = reqUrl.split("?");
71
68
  const fullQuery = [exQuery, stringifyQuery(query)].join("&").replace(/^&/, "");
72
69
  reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ""}`;
73
- } else {
70
+ }
71
+ let reqBody;
72
+ if (data && method !== "get") {
74
73
  reqBody = JSON.stringify(data);
75
74
  }
76
75
  const reqHeaders = __spreadValues({
@@ -82,7 +81,11 @@ async function request(method, url, { id, query, data, headers } = {}) {
82
81
  body: reqBody,
83
82
  mode: "cors"
84
83
  });
85
- const result = await response.json();
84
+ let result;
85
+ try {
86
+ result = await response.json();
87
+ } catch (e) {
88
+ }
86
89
  if (!response.ok) {
87
90
  if (result && result.error) {
88
91
  throw new Error(`${response.status}: ${result.error}`);