@commercelayer/sdk 7.0.0-beta.18 → 7.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.cjs +791 -7460
- package/lib/api.js +131 -7331
- package/lib/client.cjs +31 -215
- package/lib/client.js +23 -212
- package/lib/commercelayer.cjs +30 -778
- package/lib/commercelayer.js +22 -774
- package/lib/common.cjs +6 -143
- package/lib/common.js +4 -141
- package/lib/config.cjs +1 -2
- package/lib/config.js +1 -2
- package/lib/debug.cjs +5 -13
- package/lib/debug.js +5 -13
- package/lib/enum.cjs +8 -9
- package/lib/enum.js +8 -9
- package/lib/error.cjs +15 -67
- package/lib/error.js +14 -66
- package/lib/fetch.cjs +13 -72
- package/lib/fetch.js +11 -74
- package/lib/index.cjs +22 -8104
- package/lib/index.js +3 -7977
- package/lib/jsonapi.cjs +20 -188
- package/lib/jsonapi.js +13 -186
- package/lib/query.cjs +16 -75
- package/lib/query.js +14 -77
- package/lib/resource.cjs +57 -651
- package/lib/resource.js +37 -637
- package/lib/resources/addresses.cjs +11 -801
- package/lib/resources/addresses.js +11 -801
- package/lib/resources/adjustments.cjs +9 -799
- package/lib/resources/adjustments.js +9 -799
- package/lib/resources/adyen_gateways.cjs +9 -799
- package/lib/resources/adyen_gateways.js +9 -799
- package/lib/resources/adyen_payments.cjs +11 -801
- package/lib/resources/adyen_payments.js +11 -801
- package/lib/resources/applications.cjs +6 -788
- package/lib/resources/applications.js +6 -788
- package/lib/resources/attachments.cjs +9 -799
- package/lib/resources/attachments.js +9 -799
- package/lib/resources/authorizations.cjs +12 -802
- package/lib/resources/authorizations.js +12 -802
- package/lib/resources/avalara_accounts.cjs +9 -799
- package/lib/resources/avalara_accounts.js +9 -799
- package/lib/resources/axerve_gateways.cjs +9 -799
- package/lib/resources/axerve_gateways.js +9 -799
- package/lib/resources/axerve_payments.cjs +10 -800
- package/lib/resources/axerve_payments.js +10 -800
- package/lib/resources/bing_geocoders.cjs +9 -799
- package/lib/resources/bing_geocoders.js +9 -799
- package/lib/resources/braintree_gateways.cjs +9 -799
- package/lib/resources/braintree_gateways.js +9 -799
- package/lib/resources/braintree_payments.cjs +9 -799
- package/lib/resources/braintree_payments.js +9 -799
- package/lib/resources/bundles.cjs +13 -803
- package/lib/resources/bundles.js +13 -803
- package/lib/resources/buy_x_pay_y_promotions.cjs +13 -803
- package/lib/resources/buy_x_pay_y_promotions.js +13 -803
- package/lib/resources/captures.cjs +11 -801
- package/lib/resources/captures.js +11 -801
- package/lib/resources/carrier_accounts.cjs +9 -799
- package/lib/resources/carrier_accounts.js +9 -799
- package/lib/resources/checkout_com_gateways.cjs +9 -799
- package/lib/resources/checkout_com_gateways.js +9 -799
- package/lib/resources/checkout_com_payments.cjs +11 -801
- package/lib/resources/checkout_com_payments.js +11 -801
- package/lib/resources/cleanups.cjs +10 -800
- package/lib/resources/cleanups.js +10 -800
- package/lib/resources/coupon_codes_promotion_rules.cjs +9 -799
- package/lib/resources/coupon_codes_promotion_rules.js +9 -799
- package/lib/resources/coupon_recipients.cjs +9 -799
- package/lib/resources/coupon_recipients.js +9 -799
- package/lib/resources/coupons.cjs +11 -801
- package/lib/resources/coupons.js +11 -801
- package/lib/resources/custom_promotion_rules.cjs +9 -799
- package/lib/resources/custom_promotion_rules.js +9 -799
- package/lib/resources/customer_addresses.cjs +9 -799
- package/lib/resources/customer_addresses.js +9 -799
- package/lib/resources/customer_groups.cjs +9 -799
- package/lib/resources/customer_groups.js +9 -799
- package/lib/resources/customer_password_resets.cjs +10 -800
- package/lib/resources/customer_password_resets.js +10 -800
- package/lib/resources/customer_payment_sources.cjs +9 -799
- package/lib/resources/customer_payment_sources.js +9 -799
- package/lib/resources/customer_subscriptions.cjs +9 -799
- package/lib/resources/customer_subscriptions.js +9 -799
- package/lib/resources/customers.cjs +11 -801
- package/lib/resources/customers.js +11 -801
- package/lib/resources/delivery_lead_times.cjs +9 -799
- package/lib/resources/delivery_lead_times.js +9 -799
- package/lib/resources/discount_engine_items.cjs +6 -796
- package/lib/resources/discount_engine_items.js +6 -796
- package/lib/resources/discount_engines.cjs +6 -796
- package/lib/resources/discount_engines.js +6 -796
- package/lib/resources/easypost_pickups.cjs +10 -800
- package/lib/resources/easypost_pickups.js +10 -800
- package/lib/resources/event_callbacks.cjs +6 -796
- package/lib/resources/event_callbacks.js +6 -796
- package/lib/resources/events.cjs +8 -798
- package/lib/resources/events.js +8 -798
- package/lib/resources/exports.cjs +10 -800
- package/lib/resources/exports.js +10 -800
- package/lib/resources/external_gateways.cjs +10 -800
- package/lib/resources/external_gateways.js +10 -800
- package/lib/resources/external_payments.cjs +9 -799
- package/lib/resources/external_payments.js +9 -799
- package/lib/resources/external_promotions.cjs +14 -804
- package/lib/resources/external_promotions.js +14 -804
- package/lib/resources/external_tax_calculators.cjs +10 -800
- package/lib/resources/external_tax_calculators.js +10 -800
- package/lib/resources/fixed_amount_promotions.cjs +13 -803
- package/lib/resources/fixed_amount_promotions.js +13 -803
- package/lib/resources/fixed_price_promotions.cjs +13 -803
- package/lib/resources/fixed_price_promotions.js +13 -803
- package/lib/resources/flex_promotions.cjs +13 -803
- package/lib/resources/flex_promotions.js +13 -803
- package/lib/resources/free_gift_promotions.cjs +13 -803
- package/lib/resources/free_gift_promotions.js +13 -803
- package/lib/resources/free_shipping_promotions.cjs +13 -803
- package/lib/resources/free_shipping_promotions.js +13 -803
- package/lib/resources/geocoders.cjs +6 -796
- package/lib/resources/geocoders.js +6 -796
- package/lib/resources/gift_card_recipients.cjs +9 -799
- package/lib/resources/gift_card_recipients.js +9 -799
- package/lib/resources/gift_cards.cjs +15 -805
- package/lib/resources/gift_cards.js +15 -805
- package/lib/resources/google_geocoders.cjs +9 -799
- package/lib/resources/google_geocoders.js +9 -799
- package/lib/resources/imports.cjs +10 -800
- package/lib/resources/imports.js +10 -800
- package/lib/resources/in_stock_subscriptions.cjs +11 -801
- package/lib/resources/in_stock_subscriptions.js +11 -801
- package/lib/resources/inventory_models.cjs +9 -799
- package/lib/resources/inventory_models.js +9 -799
- package/lib/resources/inventory_return_locations.cjs +9 -799
- package/lib/resources/inventory_return_locations.js +9 -799
- package/lib/resources/inventory_stock_locations.cjs +9 -799
- package/lib/resources/inventory_stock_locations.js +9 -799
- package/lib/resources/klarna_gateways.cjs +9 -799
- package/lib/resources/klarna_gateways.js +9 -799
- package/lib/resources/klarna_payments.cjs +10 -800
- package/lib/resources/klarna_payments.js +10 -800
- package/lib/resources/line_item_options.cjs +11 -801
- package/lib/resources/line_item_options.js +11 -801
- package/lib/resources/line_items.cjs +14 -804
- package/lib/resources/line_items.js +14 -804
- package/lib/resources/links.cjs +11 -801
- package/lib/resources/links.js +11 -801
- package/lib/resources/manual_gateways.cjs +9 -799
- package/lib/resources/manual_gateways.js +9 -799
- package/lib/resources/manual_tax_calculators.cjs +9 -799
- package/lib/resources/manual_tax_calculators.js +9 -799
- package/lib/resources/markets.cjs +11 -801
- package/lib/resources/markets.js +11 -801
- package/lib/resources/merchants.cjs +9 -799
- package/lib/resources/merchants.js +9 -799
- package/lib/resources/notifications.cjs +9 -799
- package/lib/resources/notifications.js +9 -799
- package/lib/resources/order_amount_promotion_rules.cjs +9 -799
- package/lib/resources/order_amount_promotion_rules.js +9 -799
- package/lib/resources/order_copies.cjs +9 -799
- package/lib/resources/order_copies.js +9 -799
- package/lib/resources/order_factories.cjs +6 -796
- package/lib/resources/order_factories.js +6 -796
- package/lib/resources/order_subscription_items.cjs +9 -799
- package/lib/resources/order_subscription_items.js +9 -799
- package/lib/resources/order_subscriptions.cjs +15 -805
- package/lib/resources/order_subscriptions.js +15 -805
- package/lib/resources/orders.cjs +42 -832
- package/lib/resources/orders.js +42 -832
- package/lib/resources/organizations.cjs +6 -788
- package/lib/resources/organizations.js +6 -788
- package/lib/resources/packages.cjs +9 -799
- package/lib/resources/packages.js +9 -799
- package/lib/resources/parcel_line_items.cjs +9 -799
- package/lib/resources/parcel_line_items.js +9 -799
- package/lib/resources/parcels.cjs +9 -799
- package/lib/resources/parcels.js +9 -799
- package/lib/resources/payment_gateways.cjs +6 -796
- package/lib/resources/payment_gateways.js +6 -796
- package/lib/resources/payment_methods.cjs +11 -801
- package/lib/resources/payment_methods.js +11 -801
- package/lib/resources/payment_options.cjs +9 -799
- package/lib/resources/payment_options.js +9 -799
- package/lib/resources/paypal_gateways.cjs +9 -799
- package/lib/resources/paypal_gateways.js +9 -799
- package/lib/resources/paypal_payments.cjs +9 -799
- package/lib/resources/paypal_payments.js +9 -799
- package/lib/resources/percentage_discount_promotions.cjs +13 -803
- package/lib/resources/percentage_discount_promotions.js +13 -803
- package/lib/resources/pickups.cjs +6 -796
- package/lib/resources/pickups.js +6 -796
- package/lib/resources/price_frequency_tiers.cjs +9 -799
- package/lib/resources/price_frequency_tiers.js +9 -799
- package/lib/resources/price_list_schedulers.cjs +11 -801
- package/lib/resources/price_list_schedulers.js +11 -801
- package/lib/resources/price_lists.cjs +9 -799
- package/lib/resources/price_lists.js +9 -799
- package/lib/resources/price_tiers.cjs +6 -796
- package/lib/resources/price_tiers.js +6 -796
- package/lib/resources/price_volume_tiers.cjs +9 -799
- package/lib/resources/price_volume_tiers.js +9 -799
- package/lib/resources/prices.cjs +9 -799
- package/lib/resources/prices.js +9 -799
- package/lib/resources/promotion_rules.cjs +6 -796
- package/lib/resources/promotion_rules.js +6 -796
- package/lib/resources/promotions.cjs +6 -796
- package/lib/resources/promotions.js +6 -796
- package/lib/resources/recurring_order_copies.cjs +9 -799
- package/lib/resources/recurring_order_copies.js +9 -799
- package/lib/resources/refunds.cjs +8 -798
- package/lib/resources/refunds.js +8 -798
- package/lib/resources/reserved_stocks.cjs +6 -796
- package/lib/resources/reserved_stocks.js +6 -796
- package/lib/resources/resource_errors.cjs +6 -796
- package/lib/resources/resource_errors.js +6 -796
- package/lib/resources/return_line_items.cjs +10 -800
- package/lib/resources/return_line_items.js +10 -800
- package/lib/resources/returns.cjs +22 -812
- package/lib/resources/returns.js +22 -812
- package/lib/resources/satispay_gateways.cjs +9 -799
- package/lib/resources/satispay_gateways.js +9 -799
- package/lib/resources/satispay_payments.cjs +10 -800
- package/lib/resources/satispay_payments.js +10 -800
- package/lib/resources/shipments.cjs +24 -814
- package/lib/resources/shipments.js +24 -814
- package/lib/resources/shipping_categories.cjs +9 -799
- package/lib/resources/shipping_categories.js +9 -799
- package/lib/resources/shipping_method_tiers.cjs +6 -796
- package/lib/resources/shipping_method_tiers.js +6 -796
- package/lib/resources/shipping_methods.cjs +12 -802
- package/lib/resources/shipping_methods.js +12 -802
- package/lib/resources/shipping_weight_tiers.cjs +9 -799
- package/lib/resources/shipping_weight_tiers.js +9 -799
- package/lib/resources/shipping_zones.cjs +9 -799
- package/lib/resources/shipping_zones.js +9 -799
- package/lib/resources/sku_list_items.cjs +9 -799
- package/lib/resources/sku_list_items.js +9 -799
- package/lib/resources/sku_list_promotion_rules.cjs +9 -799
- package/lib/resources/sku_list_promotion_rules.js +9 -799
- package/lib/resources/sku_lists.cjs +9 -799
- package/lib/resources/sku_lists.js +9 -799
- package/lib/resources/sku_options.cjs +11 -801
- package/lib/resources/sku_options.js +11 -801
- package/lib/resources/skus.cjs +11 -801
- package/lib/resources/skus.js +11 -801
- package/lib/resources/stock_items.cjs +10 -800
- package/lib/resources/stock_items.js +10 -800
- package/lib/resources/stock_line_items.cjs +12 -802
- package/lib/resources/stock_line_items.js +12 -802
- package/lib/resources/stock_locations.cjs +9 -799
- package/lib/resources/stock_locations.js +9 -799
- package/lib/resources/stock_reservations.cjs +10 -800
- package/lib/resources/stock_reservations.js +10 -800
- package/lib/resources/stock_transfers.cjs +15 -805
- package/lib/resources/stock_transfers.js +15 -805
- package/lib/resources/stores.cjs +9 -799
- package/lib/resources/stores.js +9 -799
- package/lib/resources/stripe_gateways.cjs +9 -799
- package/lib/resources/stripe_gateways.js +9 -799
- package/lib/resources/stripe_payments.cjs +11 -801
- package/lib/resources/stripe_payments.js +11 -801
- package/lib/resources/stripe_tax_accounts.cjs +9 -799
- package/lib/resources/stripe_tax_accounts.js +9 -799
- package/lib/resources/subscription_models.cjs +9 -799
- package/lib/resources/subscription_models.js +9 -799
- package/lib/resources/tags.cjs +9 -799
- package/lib/resources/tags.js +9 -799
- package/lib/resources/talon_one_accounts.cjs +9 -799
- package/lib/resources/talon_one_accounts.js +9 -799
- package/lib/resources/tax_calculators.cjs +6 -796
- package/lib/resources/tax_calculators.js +6 -796
- package/lib/resources/tax_categories.cjs +9 -799
- package/lib/resources/tax_categories.js +9 -799
- package/lib/resources/tax_rules.cjs +9 -799
- package/lib/resources/tax_rules.js +9 -799
- package/lib/resources/taxjar_accounts.cjs +9 -799
- package/lib/resources/taxjar_accounts.js +9 -799
- package/lib/resources/transactions.cjs +6 -796
- package/lib/resources/transactions.js +6 -796
- package/lib/resources/versions.cjs +6 -796
- package/lib/resources/versions.js +6 -796
- package/lib/resources/vertex_accounts.cjs +10 -800
- package/lib/resources/vertex_accounts.js +10 -800
- package/lib/resources/voids.cjs +8 -798
- package/lib/resources/voids.js +8 -798
- package/lib/resources/webhooks.cjs +12 -802
- package/lib/resources/webhooks.js +12 -802
- package/lib/resources/wire_transfers.cjs +9 -799
- package/lib/resources/wire_transfers.js +9 -799
- package/lib/static.cjs +19 -753
- package/lib/static.js +5 -739
- package/lib/util.cjs +4 -5
- package/lib/util.js +4 -5
- package/package.json +4 -4
package/lib/resources/orders.js
CHANGED
@@ -1,805 +1,15 @@
|
|
1
|
-
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
3
|
-
}) : x)(function(x) {
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
6
|
-
});
|
1
|
+
import { ApiResource } from '../resource';
|
7
2
|
|
8
|
-
|
9
|
-
var debuggerFunction = (_pattern, ..._args) => {
|
10
|
-
};
|
11
|
-
var debuggerFactory = (_namespace) => debuggerFunction;
|
12
|
-
try {
|
13
|
-
const debugModule = __require("debug");
|
14
|
-
if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
|
15
|
-
} catch (error) {
|
16
|
-
}
|
17
|
-
var debugPrefix = "clsdk";
|
18
|
-
var debug = (namespace) => {
|
19
|
-
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
20
|
-
};
|
21
|
-
var debug_default = debug;
|
22
|
-
|
23
|
-
// src/fetch.ts
|
24
|
-
var debug2 = debug_default("fetch");
|
25
|
-
var FetchError = class _FetchError extends Error {
|
26
|
-
static isFetchError = (error) => {
|
27
|
-
return error instanceof _FetchError;
|
28
|
-
};
|
29
|
-
#errors;
|
30
|
-
#status;
|
31
|
-
#statusText;
|
32
|
-
#request;
|
33
|
-
constructor(status, statusText, body, request) {
|
34
|
-
super(statusText);
|
35
|
-
this.#status = status;
|
36
|
-
this.#statusText = statusText;
|
37
|
-
if (body) this.#errors = body.errors;
|
38
|
-
if (request) this.#request = request;
|
39
|
-
}
|
40
|
-
get errors() {
|
41
|
-
return this.#errors;
|
42
|
-
}
|
43
|
-
get status() {
|
44
|
-
return this.#status;
|
45
|
-
}
|
46
|
-
get statusText() {
|
47
|
-
return this.#statusText;
|
48
|
-
}
|
49
|
-
get request() {
|
50
|
-
return this.#request;
|
51
|
-
}
|
52
|
-
};
|
53
|
-
var fetchURL = async (url, requestOptions, clientOptions) => {
|
54
|
-
debug2("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
|
55
|
-
const interceptors = clientOptions?.interceptors;
|
56
|
-
if (interceptors?.request?.onSuccess) ({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
|
57
|
-
const fetchClient = clientOptions?.fetch || fetch;
|
58
|
-
let response = await fetchClient(url, requestOptions);
|
59
|
-
if (response.ok) {
|
60
|
-
if (interceptors?.rawReader?.onSuccess) await interceptors.rawReader.onSuccess(response);
|
61
|
-
if (interceptors?.response?.onSuccess) response = await interceptors.response.onSuccess(response);
|
62
|
-
} else {
|
63
|
-
if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
|
64
|
-
}
|
65
|
-
const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
|
66
|
-
debug2("response: %O", json);
|
67
|
-
return json;
|
68
|
-
}).catch((err) => {
|
69
|
-
debug2("error: %s", err.message);
|
70
|
-
if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: "parse" /* PARSE */ });
|
71
|
-
}) : void 0;
|
72
|
-
if (!response.ok) {
|
73
|
-
let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);
|
74
|
-
if (interceptors?.response?.onFailure) error = await interceptors.response.onFailure(error);
|
75
|
-
if (error) throw error;
|
76
|
-
}
|
77
|
-
return responseBody;
|
78
|
-
};
|
79
|
-
|
80
|
-
// src/error.ts
|
81
|
-
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
82
|
-
ErrorType2["CLIENT"] = "client";
|
83
|
-
ErrorType2["REQUEST"] = "request";
|
84
|
-
ErrorType2["RESPONSE"] = "response";
|
85
|
-
ErrorType2["CANCEL"] = "cancel";
|
86
|
-
ErrorType2["PARSE"] = "parse";
|
87
|
-
ErrorType2["TIMEOUT"] = "timeout";
|
88
|
-
ErrorType2["TOKEN_REFRESH"] = "token-refresh";
|
89
|
-
return ErrorType2;
|
90
|
-
})(ErrorType || {});
|
91
|
-
var SdkError = class _SdkError extends Error {
|
92
|
-
static NAME = "SdkError";
|
93
|
-
static isSdkError(error) {
|
94
|
-
return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
95
|
-
}
|
96
|
-
type;
|
97
|
-
code;
|
98
|
-
source;
|
99
|
-
constructor(error) {
|
100
|
-
super(error.message);
|
101
|
-
this.name = _SdkError.NAME;
|
102
|
-
this.type = error.type || "client" /* CLIENT */;
|
103
|
-
}
|
104
|
-
};
|
105
|
-
var ApiError = class _ApiError extends SdkError {
|
106
|
-
static NAME = "ApiError";
|
107
|
-
static isApiError(error) {
|
108
|
-
return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
|
109
|
-
}
|
110
|
-
errors = [];
|
111
|
-
status;
|
112
|
-
statusText;
|
113
|
-
// constructor(error: SdkError)
|
114
|
-
constructor(error) {
|
115
|
-
super({ ...error, type: "response" /* RESPONSE */ });
|
116
|
-
this.name = _ApiError.NAME;
|
117
|
-
}
|
118
|
-
first() {
|
119
|
-
return this.errors?.length > 0 ? this.errors[0] : void 0;
|
120
|
-
}
|
121
|
-
};
|
122
|
-
var isRequestError = (error) => {
|
123
|
-
return error instanceof TypeError && error.message !== "fetch failed";
|
124
|
-
};
|
125
|
-
var isCancelError = (error) => {
|
126
|
-
return error instanceof DOMException && error.name === "AbortError";
|
127
|
-
};
|
128
|
-
var isTimeoutError = (error) => {
|
129
|
-
return error instanceof DOMException && error.name === "TimeoutError";
|
130
|
-
};
|
131
|
-
var isExpiredTokenError = (error) => {
|
132
|
-
const invalidTokenCodes = [
|
133
|
-
"INVALID_TOKEN"
|
134
|
-
/*, 'UNAUTHORIZED' */
|
135
|
-
];
|
136
|
-
return ApiError.isApiError(error) && error.status === 401 && (invalidTokenCodes.includes(error.code || "") || error.errors && error.errors.length > 0 && invalidTokenCodes.includes(error.errors[0].code));
|
137
|
-
};
|
138
|
-
var handleError = (error) => {
|
139
|
-
if (SdkError.isSdkError(error) || ApiError.isApiError(error)) throw error;
|
140
|
-
let sdkError = new SdkError({ message: error.message });
|
141
|
-
if (FetchError.isFetchError(error)) {
|
142
|
-
const apiError = new ApiError(sdkError);
|
143
|
-
apiError.type = "response" /* RESPONSE */;
|
144
|
-
apiError.status = error.status;
|
145
|
-
apiError.statusText = error.statusText;
|
146
|
-
apiError.code = String(apiError.status);
|
147
|
-
apiError.errors = error.errors || [];
|
148
|
-
if (!apiError.message && apiError.statusText) apiError.message = apiError.statusText;
|
149
|
-
sdkError = apiError;
|
150
|
-
} else if (isRequestError(error)) {
|
151
|
-
sdkError.type = "request" /* REQUEST */;
|
152
|
-
} else if (isCancelError(error)) {
|
153
|
-
sdkError.type = "cancel" /* CANCEL */;
|
154
|
-
} else if (isTimeoutError(error)) {
|
155
|
-
sdkError.type = "timeout" /* TIMEOUT */;
|
156
|
-
} else {
|
157
|
-
sdkError.type = "client" /* CLIENT */;
|
158
|
-
sdkError.source = error;
|
159
|
-
}
|
160
|
-
throw sdkError;
|
161
|
-
};
|
162
|
-
|
163
|
-
// src/config.ts
|
164
|
-
var config = {
|
165
|
-
default: {
|
166
|
-
domain: "commercelayer.io",
|
167
|
-
pageNumber: 1,
|
168
|
-
pageSize: 10
|
169
|
-
},
|
170
|
-
client: {
|
171
|
-
timeout: 15e3,
|
172
|
-
requiredAttributes: ["organization", "accessToken"]
|
173
|
-
},
|
174
|
-
jsonapi: {
|
175
|
-
maxResourceIncluded: 2
|
176
|
-
}
|
177
|
-
};
|
178
|
-
var config_default = config;
|
179
|
-
|
180
|
-
// src/util.ts
|
181
|
-
var extractTokenData = (token) => {
|
182
|
-
try {
|
183
|
-
const data = JSON.parse(atob(token.split(".")[1]));
|
184
|
-
return {
|
185
|
-
organization: data.organization.slug,
|
186
|
-
domain: data.iss ? String(data.iss).replace("https://auth.", "") : void 0,
|
187
|
-
expiration: data.exp
|
188
|
-
};
|
189
|
-
} catch (err) {
|
190
|
-
return void 0;
|
191
|
-
}
|
192
|
-
};
|
193
|
-
var isTokenExpired = (token) => {
|
194
|
-
try {
|
195
|
-
const tokenData = extractTokenData(token);
|
196
|
-
return tokenData?.expiration ? tokenData.expiration * 1e3 - Date.now() < 0 : false;
|
197
|
-
} catch (err) {
|
198
|
-
return false;
|
199
|
-
}
|
200
|
-
};
|
201
|
-
|
202
|
-
// src/client.ts
|
203
|
-
var debug3 = debug_default("client");
|
204
|
-
var baseURL = (organization, domain) => {
|
205
|
-
return `https://${organization.toLowerCase()}.${domain || config_default.default.domain}/api`;
|
206
|
-
};
|
207
|
-
var ApiClient = class _ApiClient {
|
208
|
-
static create(options) {
|
209
|
-
if ((!options.organization || !options.domain) && options.accessToken) {
|
210
|
-
const tokenData = extractTokenData(options.accessToken);
|
211
|
-
if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
|
212
|
-
if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
|
213
|
-
}
|
214
|
-
for (const attr of config_default.client.requiredAttributes)
|
215
|
-
if (!options[attr]) throw new SdkError({ message: `Undefined '${attr}' parameter` });
|
216
|
-
return new _ApiClient(options);
|
217
|
-
}
|
218
|
-
#baseUrl;
|
219
|
-
#accessToken;
|
220
|
-
#organization;
|
221
|
-
#domain;
|
222
|
-
#clientConfig;
|
223
|
-
#interceptors;
|
224
|
-
constructor(options) {
|
225
|
-
debug3("new client instance %O", options);
|
226
|
-
this.#baseUrl = baseURL(options.organization ?? "", options.domain);
|
227
|
-
this.#accessToken = options.accessToken;
|
228
|
-
this.#organization = options.organization ?? "";
|
229
|
-
this.#domain = options.domain;
|
230
|
-
const fetchConfig = {
|
231
|
-
timeout: options.timeout || config_default.client.timeout,
|
232
|
-
fetch: options.fetch,
|
233
|
-
refreshToken: options.refreshToken
|
234
|
-
};
|
235
|
-
const customHeaders = this.customHeaders(options.headers);
|
236
|
-
const headers = {
|
237
|
-
...customHeaders,
|
238
|
-
"Accept": "application/vnd.api+json",
|
239
|
-
"Content-Type": "application/vnd.api+json",
|
240
|
-
"Authorization": "Bearer " + this.#accessToken
|
241
|
-
};
|
242
|
-
if (options.userAgent) headers["User-Agent"] = options.userAgent;
|
243
|
-
fetchConfig.headers = headers;
|
244
|
-
this.#clientConfig = fetchConfig;
|
245
|
-
debug3("fetch config: %O", fetchConfig);
|
246
|
-
this.#interceptors = {};
|
247
|
-
}
|
248
|
-
get interceptors() {
|
249
|
-
return this.#interceptors;
|
250
|
-
}
|
251
|
-
get requestHeaders() {
|
252
|
-
if (!this.#clientConfig.headers) this.#clientConfig.headers = {};
|
253
|
-
return this.#clientConfig.headers;
|
254
|
-
}
|
255
|
-
/*
|
256
|
-
set requestHeaders(headers: RequestHeaders) {
|
257
|
-
this.#clientConfig.headers = { ...this.#clientConfig.headers, ...headers }
|
258
|
-
}
|
259
|
-
*/
|
260
|
-
config(config2) {
|
261
|
-
debug3("config %o", config2);
|
262
|
-
const def = this.#clientConfig;
|
263
|
-
if (!def.headers) def.headers = {};
|
264
|
-
if (config2.timeout) def.timeout = config2.timeout;
|
265
|
-
if (config2.userAgent) this.userAgent(config2.userAgent);
|
266
|
-
if (config2.fetch) this.#clientConfig.fetch = config2.fetch;
|
267
|
-
if (config2.refreshToken) this.#clientConfig.refreshToken = config2.refreshToken;
|
268
|
-
if (config2.organization || config2.domain) this.#baseUrl = baseURL(config2.organization || this.#organization, config2.domain || this.#domain);
|
269
|
-
if (config2.organization) this.#organization = config2.organization;
|
270
|
-
if (config2.domain) this.#domain = config2.domain;
|
271
|
-
if (config2.accessToken) {
|
272
|
-
this.#accessToken = config2.accessToken;
|
273
|
-
def.headers.Authorization = "Bearer " + this.#accessToken;
|
274
|
-
}
|
275
|
-
if (config2.headers) def.headers = { ...def.headers, ...this.customHeaders(config2.headers) };
|
276
|
-
return this;
|
277
|
-
}
|
278
|
-
userAgent(userAgent) {
|
279
|
-
if (userAgent) this.requestHeaders["User-Agent"] = userAgent;
|
280
|
-
return this;
|
281
|
-
}
|
282
|
-
async request(method, path, body, options) {
|
283
|
-
debug3("request %s %s, %O, %O", method, path, body || {}, options || {});
|
284
|
-
if (options?.userAgent) debug3("User-Agent header ignored in request config");
|
285
|
-
const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : this.#baseUrl;
|
286
|
-
const url = new URL(`${baseUrl}/${path}`);
|
287
|
-
const bodyData = body ? JSON.stringify({ data: body }) : void 0;
|
288
|
-
const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
|
289
|
-
const accessToken = options?.accessToken || this.#accessToken;
|
290
|
-
if (accessToken) headers.Authorization = "Bearer " + accessToken;
|
291
|
-
const refreshToken = options?.refreshToken || this.#clientConfig.refreshToken;
|
292
|
-
const fetchFunction = options?.fetch || this.#clientConfig.fetch;
|
293
|
-
const requestOptions = { method, body: bodyData, headers };
|
294
|
-
const timeout = options?.timeout || this.#clientConfig.timeout;
|
295
|
-
if (timeout) {
|
296
|
-
if (AbortSignal?.timeout) requestOptions.signal = AbortSignal.timeout(timeout);
|
297
|
-
else debug3("Timeout not set. Undefined function: %s", "AbortSignal.timeout");
|
298
|
-
}
|
299
|
-
if (options?.params) Object.entries(options?.params).forEach(([name, value]) => {
|
300
|
-
url.searchParams.append(name, String(value));
|
301
|
-
});
|
302
|
-
const clientOptions = {
|
303
|
-
interceptors: this.interceptors,
|
304
|
-
fetch: fetchFunction
|
305
|
-
};
|
306
|
-
try {
|
307
|
-
return await fetchURL(url, requestOptions, clientOptions).catch((error) => handleError(error));
|
308
|
-
} catch (err) {
|
309
|
-
if (isExpiredTokenError(err) && refreshToken && isTokenExpired(accessToken)) {
|
310
|
-
debug3("Access token has expired");
|
311
|
-
const newAccessToken = await refreshToken(this.#accessToken).catch((e) => {
|
312
|
-
debug3("Refresh token error: %s", e.message);
|
313
|
-
const tokenError = new SdkError({ message: "Error refreshing access token", type: "token-refresh" /* TOKEN_REFRESH */ });
|
314
|
-
tokenError.source = e;
|
315
|
-
throw tokenError;
|
316
|
-
});
|
317
|
-
if (newAccessToken) {
|
318
|
-
debug3("Access token refreshed");
|
319
|
-
this.config({ accessToken: newAccessToken });
|
320
|
-
this.#accessToken = newAccessToken;
|
321
|
-
if (requestOptions.headers) requestOptions.headers.Authorization = `Bearer ${newAccessToken}`;
|
322
|
-
const response = await fetchURL(url, requestOptions, clientOptions).catch((error) => handleError(error));
|
323
|
-
return response;
|
324
|
-
}
|
325
|
-
} else throw err;
|
326
|
-
}
|
327
|
-
}
|
328
|
-
customHeaders(headers) {
|
329
|
-
const customHeaders = {};
|
330
|
-
if (headers) {
|
331
|
-
for (const [name, value] of Object.entries(headers))
|
332
|
-
if (!["accept", "content-type", "authorization", "user-agent"].includes(name.toLowerCase())) customHeaders[name] = value;
|
333
|
-
}
|
334
|
-
return customHeaders;
|
335
|
-
}
|
336
|
-
get currentAccessToken() {
|
337
|
-
return this.#accessToken;
|
338
|
-
}
|
339
|
-
get currentOrganization() {
|
340
|
-
return this.#organization;
|
341
|
-
}
|
342
|
-
};
|
343
|
-
var client_default = ApiClient;
|
344
|
-
|
345
|
-
// src/enum.ts
|
346
|
-
var apiResources = [
|
347
|
-
// ##__API_RESOURCE_LIST_START__##
|
348
|
-
"addresses",
|
349
|
-
"adjustments",
|
350
|
-
"adyen_gateways",
|
351
|
-
"adyen_payments",
|
352
|
-
"applications",
|
353
|
-
"attachments",
|
354
|
-
"authorizations",
|
355
|
-
"avalara_accounts",
|
356
|
-
"axerve_gateways",
|
357
|
-
"axerve_payments",
|
358
|
-
"bing_geocoders",
|
359
|
-
"braintree_gateways",
|
360
|
-
"braintree_payments",
|
361
|
-
"bundles",
|
362
|
-
"buy_x_pay_y_promotions",
|
363
|
-
"captures",
|
364
|
-
"carrier_accounts",
|
365
|
-
"checkout_com_gateways",
|
366
|
-
"checkout_com_payments",
|
367
|
-
"cleanups",
|
368
|
-
"coupon_codes_promotion_rules",
|
369
|
-
"coupon_recipients",
|
370
|
-
"coupons",
|
371
|
-
"custom_promotion_rules",
|
372
|
-
"customer_addresses",
|
373
|
-
"customer_groups",
|
374
|
-
"customer_password_resets",
|
375
|
-
"customer_payment_sources",
|
376
|
-
"customer_subscriptions",
|
377
|
-
"customers",
|
378
|
-
"delivery_lead_times",
|
379
|
-
"discount_engine_items",
|
380
|
-
"discount_engines",
|
381
|
-
"easypost_pickups",
|
382
|
-
"event_callbacks",
|
383
|
-
"events",
|
384
|
-
"exports",
|
385
|
-
"external_gateways",
|
386
|
-
"external_payments",
|
387
|
-
"external_promotions",
|
388
|
-
"external_tax_calculators",
|
389
|
-
"fixed_amount_promotions",
|
390
|
-
"fixed_price_promotions",
|
391
|
-
"flex_promotions",
|
392
|
-
"free_gift_promotions",
|
393
|
-
"free_shipping_promotions",
|
394
|
-
"geocoders",
|
395
|
-
"gift_card_recipients",
|
396
|
-
"gift_cards",
|
397
|
-
"google_geocoders",
|
398
|
-
"imports",
|
399
|
-
"in_stock_subscriptions",
|
400
|
-
"inventory_models",
|
401
|
-
"inventory_return_locations",
|
402
|
-
"inventory_stock_locations",
|
403
|
-
"klarna_gateways",
|
404
|
-
"klarna_payments",
|
405
|
-
"line_item_options",
|
406
|
-
"line_items",
|
407
|
-
"links",
|
408
|
-
"manual_gateways",
|
409
|
-
"manual_tax_calculators",
|
410
|
-
"markets",
|
411
|
-
"merchants",
|
412
|
-
"notifications",
|
413
|
-
"order_amount_promotion_rules",
|
414
|
-
"order_copies",
|
415
|
-
"order_factories",
|
416
|
-
"order_subscription_items",
|
417
|
-
"order_subscriptions",
|
418
|
-
"orders",
|
419
|
-
"organizations",
|
420
|
-
"packages",
|
421
|
-
"parcel_line_items",
|
422
|
-
"parcels",
|
423
|
-
"payment_gateways",
|
424
|
-
"payment_methods",
|
425
|
-
"payment_options",
|
426
|
-
"paypal_gateways",
|
427
|
-
"paypal_payments",
|
428
|
-
"percentage_discount_promotions",
|
429
|
-
"pickups",
|
430
|
-
"price_frequency_tiers",
|
431
|
-
"price_list_schedulers",
|
432
|
-
"price_lists",
|
433
|
-
"price_tiers",
|
434
|
-
"price_volume_tiers",
|
435
|
-
"prices",
|
436
|
-
"promotion_rules",
|
437
|
-
"promotions",
|
438
|
-
"recurring_order_copies",
|
439
|
-
"refunds",
|
440
|
-
"reserved_stocks",
|
441
|
-
"resource_errors",
|
442
|
-
"return_line_items",
|
443
|
-
"returns",
|
444
|
-
"satispay_gateways",
|
445
|
-
"satispay_payments",
|
446
|
-
"shipments",
|
447
|
-
"shipping_categories",
|
448
|
-
"shipping_method_tiers",
|
449
|
-
"shipping_methods",
|
450
|
-
"shipping_weight_tiers",
|
451
|
-
"shipping_zones",
|
452
|
-
"sku_list_items",
|
453
|
-
"sku_list_promotion_rules",
|
454
|
-
"sku_lists",
|
455
|
-
"sku_options",
|
456
|
-
"skus",
|
457
|
-
"stock_items",
|
458
|
-
"stock_line_items",
|
459
|
-
"stock_locations",
|
460
|
-
"stock_reservations",
|
461
|
-
"stock_transfers",
|
462
|
-
"stores",
|
463
|
-
"stripe_gateways",
|
464
|
-
"stripe_payments",
|
465
|
-
"stripe_tax_accounts",
|
466
|
-
"subscription_models",
|
467
|
-
"tags",
|
468
|
-
"talon_one_accounts",
|
469
|
-
"tax_calculators",
|
470
|
-
"tax_categories",
|
471
|
-
"tax_rules",
|
472
|
-
"taxjar_accounts",
|
473
|
-
"transactions",
|
474
|
-
"versions",
|
475
|
-
"vertex_accounts",
|
476
|
-
"voids",
|
477
|
-
"webhooks",
|
478
|
-
"wire_transfers"
|
479
|
-
// ##__API_RESOURCE_LIST_STOP__##
|
480
|
-
];
|
481
|
-
var resourceList = apiResources;
|
482
|
-
|
483
|
-
// src/common.ts
|
484
|
-
var isResourceId = (resource) => {
|
485
|
-
return resource?.type && resource.id && resourceList.includes(resource.type);
|
486
|
-
};
|
487
|
-
var isResourceType = (resource) => {
|
488
|
-
return resource && typeof resource.type !== "undefined" && resource.type && resourceList.includes(resource.type);
|
489
|
-
};
|
490
|
-
|
491
|
-
// src/jsonapi.ts
|
492
|
-
var debug4 = debug_default("jsonapi");
|
493
|
-
var denormalize = (response) => {
|
494
|
-
if (!response) return response;
|
495
|
-
let denormalizedResponse;
|
496
|
-
if (response.links) delete response.links;
|
497
|
-
const data = response.data;
|
498
|
-
const included = response.included;
|
499
|
-
if (!data) denormalizedResponse = data;
|
500
|
-
else {
|
501
|
-
if (Array.isArray(data)) denormalizedResponse = data.map((res) => denormalizeResource(res, included));
|
502
|
-
else denormalizedResponse = denormalizeResource(data, included);
|
503
|
-
}
|
504
|
-
return denormalizedResponse;
|
505
|
-
};
|
506
|
-
var findIncluded = (rel, included = []) => {
|
507
|
-
const inc = included.find((inc2) => {
|
508
|
-
return rel.id === inc2.id && rel.type === inc2.type;
|
509
|
-
});
|
510
|
-
return inc || rel;
|
511
|
-
};
|
512
|
-
var denormalizeResource = (res, included, chain = []) => {
|
513
|
-
debug4("denormalize resource: %O, %o", res, included || {});
|
514
|
-
if (!res) return res;
|
515
|
-
const resource = {
|
516
|
-
id: res.id,
|
517
|
-
type: res.type,
|
518
|
-
...res.attributes
|
519
|
-
};
|
520
|
-
if (res.relationships) Object.keys(res.relationships).forEach((key) => {
|
521
|
-
const rel = res.relationships[key].data;
|
522
|
-
if (rel) {
|
523
|
-
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config_default.jsonapi.maxResourceIncluded) resource[key] = rel;
|
524
|
-
else {
|
525
|
-
if (Array.isArray(rel)) resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
|
526
|
-
else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
527
|
-
}
|
528
|
-
} else if (rel === null) resource[key] = null;
|
529
|
-
});
|
530
|
-
debug4("denormalized resource: %O", resource);
|
531
|
-
return resource;
|
532
|
-
};
|
533
|
-
var normalize = (resource) => {
|
534
|
-
debug4("normalize resource: %O", resource);
|
535
|
-
const attributes = {};
|
536
|
-
const relationships = {};
|
537
|
-
for (const field in resource) {
|
538
|
-
if (["type", "id"].includes(field)) continue;
|
539
|
-
const value = resource[field];
|
540
|
-
if (Array.isArray(value) && value.length === 1 && isResourceType(value[0]) && value[0].id === null) {
|
541
|
-
relationships[field] = { data: [] };
|
542
|
-
} else if (value && isResourceType(value) && value.id === null) {
|
543
|
-
relationships[field] = { data: null };
|
544
|
-
} else if (value && (isResourceId(value) || Array.isArray(value) && isResourceId(value[0]))) {
|
545
|
-
relationships[field] = { data: value };
|
546
|
-
} else attributes[field] = value;
|
547
|
-
}
|
548
|
-
const normalized = {
|
549
|
-
type: resource.type,
|
550
|
-
attributes,
|
551
|
-
relationships
|
552
|
-
};
|
553
|
-
if (isResourceId(resource)) normalized.id = resource.id;
|
554
|
-
debug4("normalized resource: %O", normalized);
|
555
|
-
return normalized;
|
556
|
-
};
|
557
|
-
|
558
|
-
// src/query.ts
|
559
|
-
var debug5 = debug_default("query");
|
560
|
-
var arrayFilters = ["_any", "_all", "_in", "_not_in_or_null"];
|
561
|
-
var isArrayFilter = (filter) => {
|
562
|
-
return arrayFilters.some((f) => filter.endsWith(f));
|
563
|
-
};
|
564
|
-
var objectFilters = ["_jcont"];
|
565
|
-
var isObjectFilter = (filter) => {
|
566
|
-
return objectFilters.some((f) => filter.endsWith(f));
|
567
|
-
};
|
568
|
-
var isParamsList = (params) => {
|
569
|
-
return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
|
570
|
-
};
|
571
|
-
var generateQueryStringParams = (params, res) => {
|
572
|
-
debug5("generate query string params: %O, %O", params, res);
|
573
|
-
const qp = {};
|
574
|
-
if (!params) return qp;
|
575
|
-
if (params.include) qp.include = params.include.join(",");
|
576
|
-
if (params.fields) {
|
577
|
-
if (Array.isArray(params.fields)) params.fields = { [res.type || res]: params.fields };
|
578
|
-
Object.entries(params.fields).forEach(([p, v]) => {
|
579
|
-
qp[`fields[${p}]`] = v.join(",");
|
580
|
-
});
|
581
|
-
}
|
582
|
-
if (isParamsList(params)) {
|
583
|
-
if (params.sort) {
|
584
|
-
if (Array.isArray(params.sort)) qp.sort = params.sort.join(",");
|
585
|
-
else qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === "desc" ? "-" : ""}${k}`).join(",");
|
586
|
-
}
|
587
|
-
if (params.pageNumber) qp["page[number]"] = String(params.pageNumber);
|
588
|
-
if (params.pageSize) qp["page[size]"] = String(params.pageSize);
|
589
|
-
if (params.filters) {
|
590
|
-
Object.entries(params.filters).forEach(([p, v]) => {
|
591
|
-
let val;
|
592
|
-
if (Array.isArray(v)) {
|
593
|
-
if (!isArrayFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Array value is supported only for the following filters: ${arrayFilters.join(", ")}`, type: "request" /* REQUEST */ });
|
594
|
-
val = v.join(",");
|
595
|
-
} else if (typeof v === "object") {
|
596
|
-
if (!isObjectFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Object value is supported only for the following filters: ${objectFilters.join(", ")}`, type: "request" /* REQUEST */ });
|
597
|
-
val = JSON.stringify(v);
|
598
|
-
} else val = String(v);
|
599
|
-
qp[`filter[q][${p}]`] = val;
|
600
|
-
});
|
601
|
-
}
|
602
|
-
}
|
603
|
-
debug5("query string params: %O", qp);
|
604
|
-
return qp;
|
605
|
-
};
|
606
|
-
|
607
|
-
// src/resource.ts
|
608
|
-
var debug6 = debug_default("resource");
|
609
|
-
var ListResponse = class extends Array {
|
610
|
-
meta;
|
611
|
-
constructor(meta, data) {
|
612
|
-
super(...data || []);
|
613
|
-
this.meta = meta;
|
614
|
-
}
|
615
|
-
first() {
|
616
|
-
return this.length ? this[0] : void 0;
|
617
|
-
}
|
618
|
-
last() {
|
619
|
-
return this.length ? this[this.length - 1] : void 0;
|
620
|
-
}
|
621
|
-
get(index) {
|
622
|
-
return this.length && index >= 0 ? this[index] : void 0;
|
623
|
-
}
|
624
|
-
hasNextPage() {
|
625
|
-
return this.meta.currentPage < this.meta.pageCount;
|
626
|
-
}
|
627
|
-
hasPrevPage() {
|
628
|
-
return this.meta.currentPage > 1;
|
629
|
-
}
|
630
|
-
getRecordCount() {
|
631
|
-
return this.meta.recordCount;
|
632
|
-
}
|
633
|
-
getPageCount() {
|
634
|
-
return this.meta.pageCount;
|
635
|
-
}
|
636
|
-
get recordCount() {
|
637
|
-
return this.meta.recordCount;
|
638
|
-
}
|
639
|
-
get pageCount() {
|
640
|
-
return this.meta.pageCount;
|
641
|
-
}
|
642
|
-
};
|
643
|
-
var ApiResourceAdapter = class _ApiResourceAdapter {
|
644
|
-
static adapter;
|
645
|
-
constructor() {
|
646
|
-
}
|
647
|
-
static init(config2) {
|
648
|
-
return _ApiResourceAdapter.adapter = new ResourceAdapter(config2);
|
649
|
-
}
|
650
|
-
static get(config2) {
|
651
|
-
if (config2) return _ApiResourceAdapter.init(config2);
|
652
|
-
else {
|
653
|
-
if (_ApiResourceAdapter.adapter) return _ApiResourceAdapter.adapter;
|
654
|
-
else throw new SdkError({ message: "Commerce Layer not initialized" });
|
655
|
-
}
|
656
|
-
}
|
657
|
-
static config(config2) {
|
658
|
-
_ApiResourceAdapter.get().config(config2);
|
659
|
-
}
|
660
|
-
};
|
661
|
-
var ResourceAdapter = class {
|
662
|
-
#client;
|
663
|
-
#config = {};
|
664
|
-
constructor(config2) {
|
665
|
-
this.#client = client_default.create(config2);
|
666
|
-
this.localConfig(config2);
|
667
|
-
}
|
668
|
-
localConfig(config2) {
|
669
|
-
}
|
670
|
-
config(config2) {
|
671
|
-
debug6("config %o", config2);
|
672
|
-
this.localConfig(config2);
|
673
|
-
this.#client.config(config2);
|
674
|
-
return this;
|
675
|
-
}
|
676
|
-
get client() {
|
677
|
-
return this.#client;
|
678
|
-
}
|
679
|
-
async singleton(resource, params, options, path) {
|
680
|
-
debug6("singleton: %o, %O, %O", resource, params || {}, options || {});
|
681
|
-
const queryParams = generateQueryStringParams(params, resource);
|
682
|
-
if (options?.params) Object.assign(queryParams, options?.params);
|
683
|
-
const res = await this.#client.request("GET", `${path || resource.type}`, void 0, { ...options, params: queryParams });
|
684
|
-
const r = denormalize(res);
|
685
|
-
return r;
|
686
|
-
}
|
687
|
-
async retrieve(resource, params, options) {
|
688
|
-
debug6("retrieve: %o, %O, %O", resource, params || {}, options || {});
|
689
|
-
const queryParams = generateQueryStringParams(params, resource);
|
690
|
-
if (options?.params) Object.assign(queryParams, options?.params);
|
691
|
-
const res = await this.#client.request("GET", `${resource.type}/${resource.id}`, void 0, { ...options, params: queryParams });
|
692
|
-
const r = denormalize(res);
|
693
|
-
return r;
|
694
|
-
}
|
695
|
-
async list(resource, params, options) {
|
696
|
-
debug6("list: %o, %O, %O", resource, params || {}, options || {});
|
697
|
-
const queryParams = generateQueryStringParams(params, resource);
|
698
|
-
if (options?.params) Object.assign(queryParams, options?.params);
|
699
|
-
if (!queryParams["page[number]"]) queryParams["page[number]"] = "1";
|
700
|
-
const res = await this.#client.request("GET", `${resource.type}`, void 0, { ...options, params: queryParams });
|
701
|
-
const r = denormalize(res);
|
702
|
-
const meta = {
|
703
|
-
pageCount: Number(res.meta?.page_count),
|
704
|
-
recordCount: Number(res.meta?.record_count),
|
705
|
-
currentPage: params?.pageNumber || config_default.default.pageNumber,
|
706
|
-
recordsPerPage: params?.pageSize || config_default.default.pageSize
|
707
|
-
};
|
708
|
-
return new ListResponse(meta, r);
|
709
|
-
}
|
710
|
-
async create(resource, params, options) {
|
711
|
-
debug6("create: %o, %O, %O", resource, params || {}, options || {});
|
712
|
-
const queryParams = generateQueryStringParams(params, resource);
|
713
|
-
if (options?.params) Object.assign(queryParams, options?.params);
|
714
|
-
const data = normalize(resource);
|
715
|
-
const res = await this.#client.request("POST", resource.type, data, { ...options, params: queryParams });
|
716
|
-
const r = denormalize(res);
|
717
|
-
return r;
|
718
|
-
}
|
719
|
-
async update(resource, params, options) {
|
720
|
-
debug6("update: %o, %O, %O", resource, params || {}, options || {});
|
721
|
-
const queryParams = generateQueryStringParams(params, resource);
|
722
|
-
if (options?.params) Object.assign(queryParams, options?.params);
|
723
|
-
const data = normalize(resource);
|
724
|
-
const res = await this.#client.request("PATCH", `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
|
725
|
-
const r = denormalize(res);
|
726
|
-
return r;
|
727
|
-
}
|
728
|
-
async delete(resource, options) {
|
729
|
-
debug6("delete: %o, %O", resource, options || {});
|
730
|
-
await this.#client.request("DELETE", `${resource.type}/${resource.id}`, void 0, options);
|
731
|
-
}
|
732
|
-
async fetch(resource, path, params, options) {
|
733
|
-
debug6("fetch: %o, %O, %O", path, params || {}, options || {});
|
734
|
-
const queryParams = generateQueryStringParams(params, resource);
|
735
|
-
if (options?.params) Object.assign(queryParams, options?.params);
|
736
|
-
const res = await this.#client.request("GET", path, void 0, { ...options, params: queryParams });
|
737
|
-
const r = denormalize(res);
|
738
|
-
if (Array.isArray(r)) {
|
739
|
-
const p = params;
|
740
|
-
const meta = {
|
741
|
-
pageCount: Number(res.meta?.page_count),
|
742
|
-
recordCount: Number(res.meta?.record_count),
|
743
|
-
currentPage: p?.pageNumber || config_default.default.pageNumber,
|
744
|
-
recordsPerPage: p?.pageSize || config_default.default.pageSize
|
745
|
-
};
|
746
|
-
return new ListResponse(meta, r);
|
747
|
-
} else return r;
|
748
|
-
}
|
749
|
-
};
|
750
|
-
var ApiResourceBase = class {
|
751
|
-
static TYPE;
|
752
|
-
// #resources?: ResourceAdapter
|
753
|
-
constructor(adapter) {
|
754
|
-
debug6("new resource instance: %s", this.type());
|
755
|
-
}
|
756
|
-
get resources() {
|
757
|
-
return (
|
758
|
-
/* this.#resources || (this.#resources = */
|
759
|
-
ApiResourceAdapter.get()
|
760
|
-
);
|
761
|
-
}
|
762
|
-
relationshipOneToOne(id) {
|
763
|
-
return id === null || typeof id === "string" ? { id, type: this.type() } : { id: id.id, type: this.type() };
|
764
|
-
}
|
765
|
-
relationshipOneToMany(...ids) {
|
766
|
-
return ids === null || ids.length === 0 || ids[0] === null ? [{ id: null, type: this.type() }] : ids.map((id) => {
|
767
|
-
return { id, type: this.type() };
|
768
|
-
});
|
769
|
-
}
|
770
|
-
path() {
|
771
|
-
return this.type();
|
772
|
-
}
|
773
|
-
// reference, reference_origin and metadata attributes are always updatable
|
774
|
-
async update(resource, params, options) {
|
775
|
-
return this.resources.update({ ...resource, type: this.type() }, params, options);
|
776
|
-
}
|
777
|
-
};
|
778
|
-
var ApiResource = class extends ApiResourceBase {
|
779
|
-
async retrieve(id, params, options) {
|
780
|
-
return this.resources.retrieve(typeof id === "string" ? { type: this.type(), id } : id, params, options);
|
781
|
-
}
|
782
|
-
async list(params, options) {
|
783
|
-
return this.resources.list({ type: this.type() }, params, options);
|
784
|
-
}
|
785
|
-
async count(filter, options) {
|
786
|
-
const params = { filters: isParamsList(filter) ? filter.filters : filter, pageNumber: 1, pageSize: 1 };
|
787
|
-
const response = await this.list(params, options);
|
788
|
-
return Promise.resolve(response.meta.recordCount);
|
789
|
-
}
|
790
|
-
};
|
791
|
-
|
792
|
-
// src/resources/orders.ts
|
793
|
-
var Orders = class _Orders extends ApiResource {
|
3
|
+
class Orders extends ApiResource {
|
794
4
|
static TYPE = "orders";
|
795
5
|
async create(resource, params, options) {
|
796
|
-
return this.resources.create({ ...resource, type:
|
6
|
+
return this.resources.create({ ...resource, type: Orders.TYPE }, params, options);
|
797
7
|
}
|
798
8
|
async update(resource, params, options) {
|
799
|
-
return this.resources.update({ ...resource, type:
|
9
|
+
return this.resources.update({ ...resource, type: Orders.TYPE }, params, options);
|
800
10
|
}
|
801
11
|
async delete(id, options) {
|
802
|
-
await this.resources.delete(typeof id === "string" ? { id, type:
|
12
|
+
await this.resources.delete(typeof id === "string" ? { id, type: Orders.TYPE } : id, options);
|
803
13
|
}
|
804
14
|
async market(orderId, params, options) {
|
805
15
|
const _orderId = orderId.id || orderId;
|
@@ -946,106 +156,106 @@ var Orders = class _Orders extends ApiResource {
|
|
946
156
|
return this.resources.fetch({ type: "versions" }, `orders/${_orderId}/versions`, params, options);
|
947
157
|
}
|
948
158
|
async _archive(id, params, options) {
|
949
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
159
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _archive: true }, params, options);
|
950
160
|
}
|
951
161
|
async _unarchive(id, params, options) {
|
952
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
162
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _unarchive: true }, params, options);
|
953
163
|
}
|
954
164
|
async _pending(id, params, options) {
|
955
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
165
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _pending: true }, params, options);
|
956
166
|
}
|
957
167
|
async _place(id, params, options) {
|
958
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
168
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _place: true }, params, options);
|
959
169
|
}
|
960
170
|
async _cancel(id, params, options) {
|
961
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
171
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _cancel: true }, params, options);
|
962
172
|
}
|
963
173
|
async _approve(id, params, options) {
|
964
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
174
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _approve: true }, params, options);
|
965
175
|
}
|
966
176
|
async _approve_and_capture(id, params, options) {
|
967
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
177
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _approve_and_capture: true }, params, options);
|
968
178
|
}
|
969
179
|
async _authorize(id, params, options) {
|
970
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
180
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _authorize: true }, params, options);
|
971
181
|
}
|
972
182
|
async _authorization_amount_cents(id, triggerValue, params, options) {
|
973
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
183
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _authorization_amount_cents: triggerValue }, params, options);
|
974
184
|
}
|
975
185
|
async _capture(id, params, options) {
|
976
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
186
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _capture: true }, params, options);
|
977
187
|
}
|
978
188
|
async _refund(id, params, options) {
|
979
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
189
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _refund: true }, params, options);
|
980
190
|
}
|
981
191
|
async _fulfill(id, params, options) {
|
982
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
192
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _fulfill: true }, params, options);
|
983
193
|
}
|
984
194
|
async _update_taxes(id, params, options) {
|
985
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
195
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _update_taxes: true }, params, options);
|
986
196
|
}
|
987
197
|
async _nullify_payment_source(id, params, options) {
|
988
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
198
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _nullify_payment_source: true }, params, options);
|
989
199
|
}
|
990
200
|
async _fix_payment_source(id, params, options) {
|
991
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
201
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _fix_payment_source: true }, params, options);
|
992
202
|
}
|
993
203
|
async _billing_address_clone_id(id, triggerValue, params, options) {
|
994
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
204
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _billing_address_clone_id: triggerValue }, params, options);
|
995
205
|
}
|
996
206
|
async _shipping_address_clone_id(id, triggerValue, params, options) {
|
997
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
207
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _shipping_address_clone_id: triggerValue }, params, options);
|
998
208
|
}
|
999
209
|
async _customer_payment_source_id(id, triggerValue, params, options) {
|
1000
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
210
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _customer_payment_source_id: triggerValue }, params, options);
|
1001
211
|
}
|
1002
212
|
async _shipping_address_same_as_billing(id, params, options) {
|
1003
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
213
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _shipping_address_same_as_billing: true }, params, options);
|
1004
214
|
}
|
1005
215
|
async _billing_address_same_as_shipping(id, params, options) {
|
1006
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
216
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _billing_address_same_as_shipping: true }, params, options);
|
1007
217
|
}
|
1008
218
|
async _commit_invoice(id, params, options) {
|
1009
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
219
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _commit_invoice: true }, params, options);
|
1010
220
|
}
|
1011
221
|
async _refund_invoice(id, params, options) {
|
1012
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
222
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _refund_invoice: true }, params, options);
|
1013
223
|
}
|
1014
224
|
async _save_payment_source_to_customer_wallet(id, params, options) {
|
1015
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
225
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _save_payment_source_to_customer_wallet: true }, params, options);
|
1016
226
|
}
|
1017
227
|
async _save_shipping_address_to_customer_address_book(id, params, options) {
|
1018
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
228
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _save_shipping_address_to_customer_address_book: true }, params, options);
|
1019
229
|
}
|
1020
230
|
async _save_billing_address_to_customer_address_book(id, params, options) {
|
1021
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
231
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _save_billing_address_to_customer_address_book: true }, params, options);
|
1022
232
|
}
|
1023
233
|
async _refresh(id, params, options) {
|
1024
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
234
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _refresh: true }, params, options);
|
1025
235
|
}
|
1026
236
|
async _validate(id, params, options) {
|
1027
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
237
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _validate: true }, params, options);
|
1028
238
|
}
|
1029
239
|
async _create_subscriptions(id, params, options) {
|
1030
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
240
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _create_subscriptions: true }, params, options);
|
1031
241
|
}
|
1032
242
|
async _start_editing(id, params, options) {
|
1033
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
243
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _start_editing: true }, params, options);
|
1034
244
|
}
|
1035
245
|
async _stop_editing(id, params, options) {
|
1036
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
246
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _stop_editing: true }, params, options);
|
1037
247
|
}
|
1038
248
|
async _reset_circuit(id, params, options) {
|
1039
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
249
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _reset_circuit: true }, params, options);
|
1040
250
|
}
|
1041
251
|
async _add_tags(id, triggerValue, params, options) {
|
1042
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
252
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _add_tags: triggerValue }, params, options);
|
1043
253
|
}
|
1044
254
|
async _remove_tags(id, triggerValue, params, options) {
|
1045
|
-
return this.resources.update({ id: typeof id === "string" ? id : id.id, type:
|
255
|
+
return this.resources.update({ id: typeof id === "string" ? id : id.id, type: Orders.TYPE, _remove_tags: triggerValue }, params, options);
|
1046
256
|
}
|
1047
257
|
isOrder(resource) {
|
1048
|
-
return resource.type && resource.type ===
|
258
|
+
return resource.type && resource.type === Orders.TYPE;
|
1049
259
|
}
|
1050
260
|
relationship(id) {
|
1051
261
|
return super.relationshipOneToOne(id);
|
@@ -1054,10 +264,10 @@ var Orders = class _Orders extends ApiResource {
|
|
1054
264
|
return super.relationshipOneToMany(...ids);
|
1055
265
|
}
|
1056
266
|
type() {
|
1057
|
-
return
|
267
|
+
return Orders.TYPE;
|
1058
268
|
}
|
1059
|
-
}
|
1060
|
-
|
269
|
+
}
|
270
|
+
const instance = new Orders();
|
1061
271
|
var orders_default = instance;
|
1062
272
|
|
1063
273
|
export { orders_default as default };
|