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