@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/error.js
CHANGED
@@ -1,57 +1,5 @@
|
|
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 { FetchError } from './fetch';
|
7
2
|
|
8
|
-
// src/debug.ts
|
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
|
-
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
|
-
|
54
|
-
// src/error.ts
|
55
3
|
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
56
4
|
ErrorType2["CLIENT"] = "client";
|
57
5
|
ErrorType2["REQUEST"] = "request";
|
@@ -62,24 +10,24 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
62
10
|
ErrorType2["TOKEN_REFRESH"] = "token-refresh";
|
63
11
|
return ErrorType2;
|
64
12
|
})(ErrorType || {});
|
65
|
-
|
13
|
+
class SdkError extends Error {
|
66
14
|
static NAME = "SdkError";
|
67
15
|
static isSdkError(error) {
|
68
|
-
return error && [
|
16
|
+
return error && [SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
69
17
|
}
|
70
18
|
type;
|
71
19
|
code;
|
72
20
|
source;
|
73
21
|
constructor(error) {
|
74
22
|
super(error.message);
|
75
|
-
this.name =
|
23
|
+
this.name = SdkError.NAME;
|
76
24
|
this.type = error.type || "client" /* CLIENT */;
|
77
25
|
}
|
78
|
-
}
|
79
|
-
|
26
|
+
}
|
27
|
+
class ApiError extends SdkError {
|
80
28
|
static NAME = "ApiError";
|
81
29
|
static isApiError(error) {
|
82
|
-
return SdkError.isSdkError(error) && error.name ===
|
30
|
+
return SdkError.isSdkError(error) && error.name === ApiError.NAME && error.type === "response" /* RESPONSE */;
|
83
31
|
}
|
84
32
|
errors = [];
|
85
33
|
status;
|
@@ -87,29 +35,29 @@ var ApiError = class _ApiError extends SdkError {
|
|
87
35
|
// constructor(error: SdkError)
|
88
36
|
constructor(error) {
|
89
37
|
super({ ...error, type: "response" /* RESPONSE */ });
|
90
|
-
this.name =
|
38
|
+
this.name = ApiError.NAME;
|
91
39
|
}
|
92
40
|
first() {
|
93
41
|
return this.errors?.length > 0 ? this.errors[0] : void 0;
|
94
42
|
}
|
95
|
-
}
|
96
|
-
|
43
|
+
}
|
44
|
+
const isRequestError = (error) => {
|
97
45
|
return error instanceof TypeError && error.message !== "fetch failed";
|
98
46
|
};
|
99
|
-
|
47
|
+
const isCancelError = (error) => {
|
100
48
|
return error instanceof DOMException && error.name === "AbortError";
|
101
49
|
};
|
102
|
-
|
50
|
+
const isTimeoutError = (error) => {
|
103
51
|
return error instanceof DOMException && error.name === "TimeoutError";
|
104
52
|
};
|
105
|
-
|
53
|
+
const isExpiredTokenError = (error) => {
|
106
54
|
const invalidTokenCodes = [
|
107
55
|
"INVALID_TOKEN"
|
108
56
|
/*, 'UNAUTHORIZED' */
|
109
57
|
];
|
110
58
|
return ApiError.isApiError(error) && error.status === 401 && (invalidTokenCodes.includes(error.code || "") || error.errors && error.errors.length > 0 && invalidTokenCodes.includes(error.errors[0].code));
|
111
59
|
};
|
112
|
-
|
60
|
+
const handleError = (error) => {
|
113
61
|
if (SdkError.isSdkError(error) || ApiError.isApiError(error)) throw error;
|
114
62
|
let sdkError = new SdkError({ message: error.message });
|
115
63
|
if (FetchError.isFetchError(error)) {
|
package/lib/fetch.cjs
CHANGED
@@ -1,75 +1,16 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
4
|
-
|
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 error = require('./error');
|
4
|
+
var Debug = require('./debug');
|
9
5
|
|
10
|
-
|
11
|
-
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
12
|
-
ErrorType2["CLIENT"] = "client";
|
13
|
-
ErrorType2["REQUEST"] = "request";
|
14
|
-
ErrorType2["RESPONSE"] = "response";
|
15
|
-
ErrorType2["CANCEL"] = "cancel";
|
16
|
-
ErrorType2["PARSE"] = "parse";
|
17
|
-
ErrorType2["TIMEOUT"] = "timeout";
|
18
|
-
ErrorType2["TOKEN_REFRESH"] = "token-refresh";
|
19
|
-
return ErrorType2;
|
20
|
-
})(ErrorType || {});
|
21
|
-
var SdkError = class _SdkError extends Error {
|
22
|
-
static NAME = "SdkError";
|
23
|
-
static isSdkError(error) {
|
24
|
-
return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
25
|
-
}
|
26
|
-
type;
|
27
|
-
code;
|
28
|
-
source;
|
29
|
-
constructor(error) {
|
30
|
-
super(error.message);
|
31
|
-
this.name = _SdkError.NAME;
|
32
|
-
this.type = error.type || "client" /* CLIENT */;
|
33
|
-
}
|
34
|
-
};
|
35
|
-
var ApiError = class _ApiError extends SdkError {
|
36
|
-
static NAME = "ApiError";
|
37
|
-
static isApiError(error) {
|
38
|
-
return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
|
39
|
-
}
|
40
|
-
errors = [];
|
41
|
-
status;
|
42
|
-
statusText;
|
43
|
-
// constructor(error: SdkError)
|
44
|
-
constructor(error) {
|
45
|
-
super({ ...error, type: "response" /* RESPONSE */ });
|
46
|
-
this.name = _ApiError.NAME;
|
47
|
-
}
|
48
|
-
first() {
|
49
|
-
return this.errors?.length > 0 ? this.errors[0] : void 0;
|
50
|
-
}
|
51
|
-
};
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
52
7
|
|
53
|
-
|
54
|
-
var debuggerFunction = (_pattern, ..._args) => {
|
55
|
-
};
|
56
|
-
var debuggerFactory = (_namespace) => debuggerFunction;
|
57
|
-
try {
|
58
|
-
const debugModule = __require("debug");
|
59
|
-
if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
|
60
|
-
} catch (error) {
|
61
|
-
}
|
62
|
-
var debugPrefix = "clsdk";
|
63
|
-
var debug = (namespace) => {
|
64
|
-
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
65
|
-
};
|
66
|
-
var debug_default = debug;
|
8
|
+
var Debug__default = /*#__PURE__*/_interopDefault(Debug);
|
67
9
|
|
68
|
-
|
69
|
-
|
70
|
-
var FetchError = class _FetchError extends Error {
|
10
|
+
const debug = Debug__default.default("fetch");
|
11
|
+
class FetchError extends Error {
|
71
12
|
static isFetchError = (error) => {
|
72
|
-
return error instanceof
|
13
|
+
return error instanceof FetchError;
|
73
14
|
};
|
74
15
|
#errors;
|
75
16
|
#status;
|
@@ -94,9 +35,9 @@ var FetchError = class _FetchError extends Error {
|
|
94
35
|
get request() {
|
95
36
|
return this.#request;
|
96
37
|
}
|
97
|
-
}
|
98
|
-
|
99
|
-
|
38
|
+
}
|
39
|
+
const fetchURL = async (url, requestOptions, clientOptions) => {
|
40
|
+
debug("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
|
100
41
|
const interceptors = clientOptions?.interceptors;
|
101
42
|
if (interceptors?.request?.onSuccess) ({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
|
102
43
|
const fetchClient = clientOptions?.fetch || fetch;
|
@@ -108,11 +49,11 @@ var fetchURL = async (url, requestOptions, clientOptions) => {
|
|
108
49
|
if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
|
109
50
|
}
|
110
51
|
const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
|
111
|
-
|
52
|
+
debug("response: %O", json);
|
112
53
|
return json;
|
113
54
|
}).catch((err) => {
|
114
|
-
|
115
|
-
if (response.ok) throw new SdkError({ message: "Error parsing API response body", type:
|
55
|
+
debug("error: %s", err.message);
|
56
|
+
if (response.ok) throw new error.SdkError({ message: "Error parsing API response body", type: error.ErrorType.PARSE });
|
116
57
|
}) : void 0;
|
117
58
|
if (!response.ok) {
|
118
59
|
let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);
|
package/lib/fetch.js
CHANGED
@@ -1,73 +1,10 @@
|
|
1
|
-
|
2
|
-
|
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 { SdkError, ErrorType } from './error';
|
2
|
+
import Debug from './debug';
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
ErrorType2["CLIENT"] = "client";
|
11
|
-
ErrorType2["REQUEST"] = "request";
|
12
|
-
ErrorType2["RESPONSE"] = "response";
|
13
|
-
ErrorType2["CANCEL"] = "cancel";
|
14
|
-
ErrorType2["PARSE"] = "parse";
|
15
|
-
ErrorType2["TIMEOUT"] = "timeout";
|
16
|
-
ErrorType2["TOKEN_REFRESH"] = "token-refresh";
|
17
|
-
return ErrorType2;
|
18
|
-
})(ErrorType || {});
|
19
|
-
var SdkError = class _SdkError extends Error {
|
20
|
-
static NAME = "SdkError";
|
21
|
-
static isSdkError(error) {
|
22
|
-
return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
23
|
-
}
|
24
|
-
type;
|
25
|
-
code;
|
26
|
-
source;
|
27
|
-
constructor(error) {
|
28
|
-
super(error.message);
|
29
|
-
this.name = _SdkError.NAME;
|
30
|
-
this.type = error.type || "client" /* CLIENT */;
|
31
|
-
}
|
32
|
-
};
|
33
|
-
var ApiError = class _ApiError extends SdkError {
|
34
|
-
static NAME = "ApiError";
|
35
|
-
static isApiError(error) {
|
36
|
-
return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
|
37
|
-
}
|
38
|
-
errors = [];
|
39
|
-
status;
|
40
|
-
statusText;
|
41
|
-
// constructor(error: SdkError)
|
42
|
-
constructor(error) {
|
43
|
-
super({ ...error, type: "response" /* RESPONSE */ });
|
44
|
-
this.name = _ApiError.NAME;
|
45
|
-
}
|
46
|
-
first() {
|
47
|
-
return this.errors?.length > 0 ? this.errors[0] : void 0;
|
48
|
-
}
|
49
|
-
};
|
50
|
-
|
51
|
-
// src/debug.ts
|
52
|
-
var debuggerFunction = (_pattern, ..._args) => {
|
53
|
-
};
|
54
|
-
var debuggerFactory = (_namespace) => debuggerFunction;
|
55
|
-
try {
|
56
|
-
const debugModule = __require("debug");
|
57
|
-
if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
|
58
|
-
} catch (error) {
|
59
|
-
}
|
60
|
-
var debugPrefix = "clsdk";
|
61
|
-
var debug = (namespace) => {
|
62
|
-
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
63
|
-
};
|
64
|
-
var debug_default = debug;
|
65
|
-
|
66
|
-
// src/fetch.ts
|
67
|
-
var debug2 = debug_default("fetch");
|
68
|
-
var FetchError = class _FetchError extends Error {
|
4
|
+
const debug = Debug("fetch");
|
5
|
+
class FetchError extends Error {
|
69
6
|
static isFetchError = (error) => {
|
70
|
-
return error instanceof
|
7
|
+
return error instanceof FetchError;
|
71
8
|
};
|
72
9
|
#errors;
|
73
10
|
#status;
|
@@ -92,9 +29,9 @@ var FetchError = class _FetchError extends Error {
|
|
92
29
|
get request() {
|
93
30
|
return this.#request;
|
94
31
|
}
|
95
|
-
}
|
96
|
-
|
97
|
-
|
32
|
+
}
|
33
|
+
const fetchURL = async (url, requestOptions, clientOptions) => {
|
34
|
+
debug("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
|
98
35
|
const interceptors = clientOptions?.interceptors;
|
99
36
|
if (interceptors?.request?.onSuccess) ({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
|
100
37
|
const fetchClient = clientOptions?.fetch || fetch;
|
@@ -106,11 +43,11 @@ var fetchURL = async (url, requestOptions, clientOptions) => {
|
|
106
43
|
if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
|
107
44
|
}
|
108
45
|
const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
|
109
|
-
|
46
|
+
debug("response: %O", json);
|
110
47
|
return json;
|
111
48
|
}).catch((err) => {
|
112
|
-
|
113
|
-
if (response.ok) throw new SdkError({ message: "Error parsing API response body", type:
|
49
|
+
debug("error: %s", err.message);
|
50
|
+
if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: ErrorType.PARSE });
|
114
51
|
}) : void 0;
|
115
52
|
if (!response.ok) {
|
116
53
|
let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);
|