@commercelayer/sdk 7.0.0-beta.17 → 7.0.0-beta.18
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 +7460 -792
- package/lib/api.js +7331 -132
- package/lib/client.cjs +253 -78
- package/lib/client.js +252 -72
- package/lib/commercelayer.cjs +777 -31
- package/lib/commercelayer.js +773 -23
- package/lib/common.cjs +143 -7
- package/lib/common.js +141 -5
- package/lib/config.cjs +2 -3
- package/lib/config.js +2 -3
- package/lib/debug.cjs +12 -6
- package/lib/debug.js +12 -6
- package/lib/enum.cjs +9 -10
- package/lib/enum.js +9 -10
- package/lib/error.cjs +75 -26
- package/lib/error.js +74 -25
- package/lib/fetch.cjs +85 -33
- package/lib/fetch.js +87 -31
- package/lib/index.cjs +8104 -23
- package/lib/index.d.cts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +7977 -4
- package/lib/jsonapi.cjs +188 -21
- package/lib/jsonapi.js +186 -14
- package/lib/query.cjs +75 -17
- package/lib/query.js +77 -15
- package/lib/resource.cjs +660 -71
- package/lib/resource.js +646 -51
- package/lib/resources/addresses.cjs +794 -6
- package/lib/resources/addresses.js +794 -6
- package/lib/resources/adjustments.cjs +794 -6
- package/lib/resources/adjustments.js +794 -6
- package/lib/resources/adyen_gateways.cjs +794 -6
- package/lib/resources/adyen_gateways.js +794 -6
- package/lib/resources/adyen_payments.cjs +794 -6
- package/lib/resources/adyen_payments.js +794 -6
- package/lib/resources/applications.cjs +786 -6
- package/lib/resources/applications.js +786 -6
- package/lib/resources/attachments.cjs +794 -6
- package/lib/resources/attachments.js +794 -6
- package/lib/resources/authorizations.cjs +794 -6
- package/lib/resources/authorizations.js +794 -6
- package/lib/resources/avalara_accounts.cjs +794 -6
- package/lib/resources/avalara_accounts.js +794 -6
- package/lib/resources/axerve_gateways.cjs +794 -6
- package/lib/resources/axerve_gateways.js +794 -6
- package/lib/resources/axerve_payments.cjs +794 -6
- package/lib/resources/axerve_payments.js +794 -6
- package/lib/resources/bing_geocoders.cjs +794 -6
- package/lib/resources/bing_geocoders.js +794 -6
- package/lib/resources/braintree_gateways.cjs +794 -6
- package/lib/resources/braintree_gateways.js +794 -6
- package/lib/resources/braintree_payments.cjs +794 -6
- package/lib/resources/braintree_payments.js +794 -6
- package/lib/resources/bundles.cjs +794 -6
- package/lib/resources/bundles.js +794 -6
- package/lib/resources/buy_x_pay_y_promotions.cjs +794 -6
- package/lib/resources/buy_x_pay_y_promotions.js +794 -6
- package/lib/resources/captures.cjs +794 -6
- package/lib/resources/captures.js +794 -6
- package/lib/resources/carrier_accounts.cjs +794 -6
- package/lib/resources/carrier_accounts.js +794 -6
- package/lib/resources/checkout_com_gateways.cjs +794 -6
- package/lib/resources/checkout_com_gateways.js +794 -6
- package/lib/resources/checkout_com_payments.cjs +794 -6
- package/lib/resources/checkout_com_payments.js +794 -6
- package/lib/resources/cleanups.cjs +794 -6
- package/lib/resources/cleanups.js +794 -6
- package/lib/resources/coupon_codes_promotion_rules.cjs +794 -6
- package/lib/resources/coupon_codes_promotion_rules.js +794 -6
- package/lib/resources/coupon_recipients.cjs +794 -6
- package/lib/resources/coupon_recipients.js +794 -6
- package/lib/resources/coupons.cjs +794 -6
- package/lib/resources/coupons.js +794 -6
- package/lib/resources/custom_promotion_rules.cjs +794 -6
- package/lib/resources/custom_promotion_rules.js +794 -6
- package/lib/resources/customer_addresses.cjs +794 -6
- package/lib/resources/customer_addresses.js +794 -6
- package/lib/resources/customer_groups.cjs +794 -6
- package/lib/resources/customer_groups.js +794 -6
- package/lib/resources/customer_password_resets.cjs +794 -6
- package/lib/resources/customer_password_resets.js +794 -6
- package/lib/resources/customer_payment_sources.cjs +794 -6
- package/lib/resources/customer_payment_sources.js +794 -6
- package/lib/resources/customer_subscriptions.cjs +794 -6
- package/lib/resources/customer_subscriptions.js +794 -6
- package/lib/resources/customers.cjs +794 -6
- package/lib/resources/customers.js +794 -6
- package/lib/resources/delivery_lead_times.cjs +794 -6
- package/lib/resources/delivery_lead_times.js +794 -6
- package/lib/resources/discount_engine_items.cjs +794 -6
- package/lib/resources/discount_engine_items.js +794 -6
- package/lib/resources/discount_engines.cjs +794 -6
- package/lib/resources/discount_engines.js +794 -6
- package/lib/resources/easypost_pickups.cjs +794 -6
- package/lib/resources/easypost_pickups.js +794 -6
- package/lib/resources/event_callbacks.cjs +794 -6
- package/lib/resources/event_callbacks.js +794 -6
- package/lib/resources/events.cjs +794 -6
- package/lib/resources/events.js +794 -6
- package/lib/resources/exports.cjs +794 -6
- package/lib/resources/exports.js +794 -6
- package/lib/resources/external_gateways.cjs +794 -6
- package/lib/resources/external_gateways.js +794 -6
- package/lib/resources/external_payments.cjs +794 -6
- package/lib/resources/external_payments.js +794 -6
- package/lib/resources/external_promotions.cjs +794 -6
- package/lib/resources/external_promotions.js +794 -6
- package/lib/resources/external_tax_calculators.cjs +794 -6
- package/lib/resources/external_tax_calculators.js +794 -6
- package/lib/resources/fixed_amount_promotions.cjs +794 -6
- package/lib/resources/fixed_amount_promotions.js +794 -6
- package/lib/resources/fixed_price_promotions.cjs +794 -6
- package/lib/resources/fixed_price_promotions.js +794 -6
- package/lib/resources/flex_promotions.cjs +794 -6
- package/lib/resources/flex_promotions.js +794 -6
- package/lib/resources/free_gift_promotions.cjs +794 -6
- package/lib/resources/free_gift_promotions.js +794 -6
- package/lib/resources/free_shipping_promotions.cjs +794 -6
- package/lib/resources/free_shipping_promotions.js +794 -6
- package/lib/resources/geocoders.cjs +794 -6
- package/lib/resources/geocoders.js +794 -6
- package/lib/resources/gift_card_recipients.cjs +794 -6
- package/lib/resources/gift_card_recipients.js +794 -6
- package/lib/resources/gift_cards.cjs +794 -6
- package/lib/resources/gift_cards.js +794 -6
- package/lib/resources/google_geocoders.cjs +794 -6
- package/lib/resources/google_geocoders.js +794 -6
- package/lib/resources/imports.cjs +794 -6
- package/lib/resources/imports.js +794 -6
- package/lib/resources/in_stock_subscriptions.cjs +794 -6
- package/lib/resources/in_stock_subscriptions.js +794 -6
- package/lib/resources/inventory_models.cjs +794 -6
- package/lib/resources/inventory_models.js +794 -6
- package/lib/resources/inventory_return_locations.cjs +794 -6
- package/lib/resources/inventory_return_locations.js +794 -6
- package/lib/resources/inventory_stock_locations.cjs +794 -6
- package/lib/resources/inventory_stock_locations.js +794 -6
- package/lib/resources/klarna_gateways.cjs +794 -6
- package/lib/resources/klarna_gateways.js +794 -6
- package/lib/resources/klarna_payments.cjs +794 -6
- package/lib/resources/klarna_payments.js +794 -6
- package/lib/resources/line_item_options.cjs +794 -6
- package/lib/resources/line_item_options.js +794 -6
- package/lib/resources/line_items.cjs +794 -6
- package/lib/resources/line_items.js +794 -6
- package/lib/resources/links.cjs +794 -6
- package/lib/resources/links.js +794 -6
- package/lib/resources/manual_gateways.cjs +794 -6
- package/lib/resources/manual_gateways.js +794 -6
- package/lib/resources/manual_tax_calculators.cjs +794 -6
- package/lib/resources/manual_tax_calculators.js +794 -6
- package/lib/resources/markets.cjs +794 -6
- package/lib/resources/markets.js +794 -6
- package/lib/resources/merchants.cjs +794 -6
- package/lib/resources/merchants.js +794 -6
- package/lib/resources/notifications.cjs +794 -6
- package/lib/resources/notifications.js +794 -6
- package/lib/resources/order_amount_promotion_rules.cjs +794 -6
- package/lib/resources/order_amount_promotion_rules.js +794 -6
- package/lib/resources/order_copies.cjs +794 -6
- package/lib/resources/order_copies.js +794 -6
- package/lib/resources/order_factories.cjs +794 -6
- package/lib/resources/order_factories.js +794 -6
- package/lib/resources/order_subscription_items.cjs +794 -6
- package/lib/resources/order_subscription_items.js +794 -6
- package/lib/resources/order_subscriptions.cjs +794 -6
- package/lib/resources/order_subscriptions.js +794 -6
- package/lib/resources/orders.cjs +794 -6
- package/lib/resources/orders.js +794 -6
- package/lib/resources/organizations.cjs +786 -6
- package/lib/resources/organizations.js +786 -6
- package/lib/resources/packages.cjs +794 -6
- package/lib/resources/packages.js +794 -6
- package/lib/resources/parcel_line_items.cjs +794 -6
- package/lib/resources/parcel_line_items.js +794 -6
- package/lib/resources/parcels.cjs +794 -6
- package/lib/resources/parcels.js +794 -6
- package/lib/resources/payment_gateways.cjs +794 -6
- package/lib/resources/payment_gateways.js +794 -6
- package/lib/resources/payment_methods.cjs +794 -6
- package/lib/resources/payment_methods.js +794 -6
- package/lib/resources/payment_options.cjs +794 -6
- package/lib/resources/payment_options.js +794 -6
- package/lib/resources/paypal_gateways.cjs +794 -6
- package/lib/resources/paypal_gateways.js +794 -6
- package/lib/resources/paypal_payments.cjs +794 -6
- package/lib/resources/paypal_payments.js +794 -6
- package/lib/resources/percentage_discount_promotions.cjs +794 -6
- package/lib/resources/percentage_discount_promotions.js +794 -6
- package/lib/resources/pickups.cjs +794 -6
- package/lib/resources/pickups.js +794 -6
- package/lib/resources/price_frequency_tiers.cjs +794 -6
- package/lib/resources/price_frequency_tiers.js +794 -6
- package/lib/resources/price_list_schedulers.cjs +794 -6
- package/lib/resources/price_list_schedulers.js +794 -6
- package/lib/resources/price_lists.cjs +794 -6
- package/lib/resources/price_lists.js +794 -6
- package/lib/resources/price_tiers.cjs +794 -6
- package/lib/resources/price_tiers.js +794 -6
- package/lib/resources/price_volume_tiers.cjs +794 -6
- package/lib/resources/price_volume_tiers.js +794 -6
- package/lib/resources/prices.cjs +794 -6
- package/lib/resources/prices.js +794 -6
- package/lib/resources/promotion_rules.cjs +794 -6
- package/lib/resources/promotion_rules.js +794 -6
- package/lib/resources/promotions.cjs +794 -6
- package/lib/resources/promotions.js +794 -6
- package/lib/resources/recurring_order_copies.cjs +794 -6
- package/lib/resources/recurring_order_copies.js +794 -6
- package/lib/resources/refunds.cjs +794 -6
- package/lib/resources/refunds.js +794 -6
- package/lib/resources/reserved_stocks.cjs +794 -6
- package/lib/resources/reserved_stocks.js +794 -6
- package/lib/resources/resource_errors.cjs +794 -6
- package/lib/resources/resource_errors.js +794 -6
- package/lib/resources/return_line_items.cjs +794 -6
- package/lib/resources/return_line_items.js +794 -6
- package/lib/resources/returns.cjs +794 -6
- package/lib/resources/returns.js +794 -6
- package/lib/resources/satispay_gateways.cjs +794 -6
- package/lib/resources/satispay_gateways.js +794 -6
- package/lib/resources/satispay_payments.cjs +794 -6
- package/lib/resources/satispay_payments.js +794 -6
- package/lib/resources/shipments.cjs +794 -6
- package/lib/resources/shipments.js +794 -6
- package/lib/resources/shipping_categories.cjs +794 -6
- package/lib/resources/shipping_categories.js +794 -6
- package/lib/resources/shipping_method_tiers.cjs +794 -6
- package/lib/resources/shipping_method_tiers.js +794 -6
- package/lib/resources/shipping_methods.cjs +794 -6
- package/lib/resources/shipping_methods.js +794 -6
- package/lib/resources/shipping_weight_tiers.cjs +794 -6
- package/lib/resources/shipping_weight_tiers.js +794 -6
- package/lib/resources/shipping_zones.cjs +794 -6
- package/lib/resources/shipping_zones.js +794 -6
- package/lib/resources/sku_list_items.cjs +794 -6
- package/lib/resources/sku_list_items.js +794 -6
- package/lib/resources/sku_list_promotion_rules.cjs +794 -6
- package/lib/resources/sku_list_promotion_rules.js +794 -6
- package/lib/resources/sku_lists.cjs +794 -6
- package/lib/resources/sku_lists.js +794 -6
- package/lib/resources/sku_options.cjs +794 -6
- package/lib/resources/sku_options.js +794 -6
- package/lib/resources/skus.cjs +794 -6
- package/lib/resources/skus.js +794 -6
- package/lib/resources/stock_items.cjs +794 -6
- package/lib/resources/stock_items.js +794 -6
- package/lib/resources/stock_line_items.cjs +794 -6
- package/lib/resources/stock_line_items.js +794 -6
- package/lib/resources/stock_locations.cjs +794 -6
- package/lib/resources/stock_locations.js +794 -6
- package/lib/resources/stock_reservations.cjs +794 -6
- package/lib/resources/stock_reservations.js +794 -6
- package/lib/resources/stock_transfers.cjs +794 -6
- package/lib/resources/stock_transfers.js +794 -6
- package/lib/resources/stores.cjs +794 -6
- package/lib/resources/stores.js +794 -6
- package/lib/resources/stripe_gateways.cjs +794 -6
- package/lib/resources/stripe_gateways.js +794 -6
- package/lib/resources/stripe_payments.cjs +794 -6
- package/lib/resources/stripe_payments.js +794 -6
- package/lib/resources/stripe_tax_accounts.cjs +794 -6
- package/lib/resources/stripe_tax_accounts.js +794 -6
- package/lib/resources/subscription_models.cjs +794 -6
- package/lib/resources/subscription_models.js +794 -6
- package/lib/resources/tags.cjs +794 -6
- package/lib/resources/tags.js +794 -6
- package/lib/resources/talon_one_accounts.cjs +794 -6
- package/lib/resources/talon_one_accounts.js +794 -6
- package/lib/resources/tax_calculators.cjs +794 -6
- package/lib/resources/tax_calculators.js +794 -6
- package/lib/resources/tax_categories.cjs +794 -6
- package/lib/resources/tax_categories.js +794 -6
- package/lib/resources/tax_rules.cjs +794 -6
- package/lib/resources/tax_rules.js +794 -6
- package/lib/resources/taxjar_accounts.cjs +794 -6
- package/lib/resources/taxjar_accounts.js +794 -6
- package/lib/resources/transactions.cjs +794 -6
- package/lib/resources/transactions.js +794 -6
- package/lib/resources/versions.cjs +794 -6
- package/lib/resources/versions.js +794 -6
- package/lib/resources/vertex_accounts.cjs +794 -6
- package/lib/resources/vertex_accounts.js +794 -6
- package/lib/resources/voids.cjs +794 -6
- package/lib/resources/voids.js +794 -6
- package/lib/resources/webhooks.cjs +794 -6
- package/lib/resources/webhooks.js +794 -6
- package/lib/resources/wire_transfers.cjs +794 -6
- package/lib/resources/wire_transfers.js +794 -6
- package/lib/static.cjs +753 -20
- package/lib/static.js +739 -6
- package/lib/util.cjs +5 -6
- package/lib/util.js +5 -6
- package/package.json +1 -1
- package/lib/chunk-AQ5VUG5P.js +0 -12
- package/lib/chunk-JE77HYXB.cjs +0 -17
package/lib/jsonapi.cjs
CHANGED
@@ -1,17 +1,184 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
require(
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
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
|
+
});
|
7
9
|
|
8
|
-
|
10
|
+
// src/enum.ts
|
11
|
+
var apiResources = [
|
12
|
+
// ##__API_RESOURCE_LIST_START__##
|
13
|
+
"addresses",
|
14
|
+
"adjustments",
|
15
|
+
"adyen_gateways",
|
16
|
+
"adyen_payments",
|
17
|
+
"applications",
|
18
|
+
"attachments",
|
19
|
+
"authorizations",
|
20
|
+
"avalara_accounts",
|
21
|
+
"axerve_gateways",
|
22
|
+
"axerve_payments",
|
23
|
+
"bing_geocoders",
|
24
|
+
"braintree_gateways",
|
25
|
+
"braintree_payments",
|
26
|
+
"bundles",
|
27
|
+
"buy_x_pay_y_promotions",
|
28
|
+
"captures",
|
29
|
+
"carrier_accounts",
|
30
|
+
"checkout_com_gateways",
|
31
|
+
"checkout_com_payments",
|
32
|
+
"cleanups",
|
33
|
+
"coupon_codes_promotion_rules",
|
34
|
+
"coupon_recipients",
|
35
|
+
"coupons",
|
36
|
+
"custom_promotion_rules",
|
37
|
+
"customer_addresses",
|
38
|
+
"customer_groups",
|
39
|
+
"customer_password_resets",
|
40
|
+
"customer_payment_sources",
|
41
|
+
"customer_subscriptions",
|
42
|
+
"customers",
|
43
|
+
"delivery_lead_times",
|
44
|
+
"discount_engine_items",
|
45
|
+
"discount_engines",
|
46
|
+
"easypost_pickups",
|
47
|
+
"event_callbacks",
|
48
|
+
"events",
|
49
|
+
"exports",
|
50
|
+
"external_gateways",
|
51
|
+
"external_payments",
|
52
|
+
"external_promotions",
|
53
|
+
"external_tax_calculators",
|
54
|
+
"fixed_amount_promotions",
|
55
|
+
"fixed_price_promotions",
|
56
|
+
"flex_promotions",
|
57
|
+
"free_gift_promotions",
|
58
|
+
"free_shipping_promotions",
|
59
|
+
"geocoders",
|
60
|
+
"gift_card_recipients",
|
61
|
+
"gift_cards",
|
62
|
+
"google_geocoders",
|
63
|
+
"imports",
|
64
|
+
"in_stock_subscriptions",
|
65
|
+
"inventory_models",
|
66
|
+
"inventory_return_locations",
|
67
|
+
"inventory_stock_locations",
|
68
|
+
"klarna_gateways",
|
69
|
+
"klarna_payments",
|
70
|
+
"line_item_options",
|
71
|
+
"line_items",
|
72
|
+
"links",
|
73
|
+
"manual_gateways",
|
74
|
+
"manual_tax_calculators",
|
75
|
+
"markets",
|
76
|
+
"merchants",
|
77
|
+
"notifications",
|
78
|
+
"order_amount_promotion_rules",
|
79
|
+
"order_copies",
|
80
|
+
"order_factories",
|
81
|
+
"order_subscription_items",
|
82
|
+
"order_subscriptions",
|
83
|
+
"orders",
|
84
|
+
"organizations",
|
85
|
+
"packages",
|
86
|
+
"parcel_line_items",
|
87
|
+
"parcels",
|
88
|
+
"payment_gateways",
|
89
|
+
"payment_methods",
|
90
|
+
"payment_options",
|
91
|
+
"paypal_gateways",
|
92
|
+
"paypal_payments",
|
93
|
+
"percentage_discount_promotions",
|
94
|
+
"pickups",
|
95
|
+
"price_frequency_tiers",
|
96
|
+
"price_list_schedulers",
|
97
|
+
"price_lists",
|
98
|
+
"price_tiers",
|
99
|
+
"price_volume_tiers",
|
100
|
+
"prices",
|
101
|
+
"promotion_rules",
|
102
|
+
"promotions",
|
103
|
+
"recurring_order_copies",
|
104
|
+
"refunds",
|
105
|
+
"reserved_stocks",
|
106
|
+
"resource_errors",
|
107
|
+
"return_line_items",
|
108
|
+
"returns",
|
109
|
+
"satispay_gateways",
|
110
|
+
"satispay_payments",
|
111
|
+
"shipments",
|
112
|
+
"shipping_categories",
|
113
|
+
"shipping_method_tiers",
|
114
|
+
"shipping_methods",
|
115
|
+
"shipping_weight_tiers",
|
116
|
+
"shipping_zones",
|
117
|
+
"sku_list_items",
|
118
|
+
"sku_list_promotion_rules",
|
119
|
+
"sku_lists",
|
120
|
+
"sku_options",
|
121
|
+
"skus",
|
122
|
+
"stock_items",
|
123
|
+
"stock_line_items",
|
124
|
+
"stock_locations",
|
125
|
+
"stock_reservations",
|
126
|
+
"stock_transfers",
|
127
|
+
"stores",
|
128
|
+
"stripe_gateways",
|
129
|
+
"stripe_payments",
|
130
|
+
"stripe_tax_accounts",
|
131
|
+
"subscription_models",
|
132
|
+
"tags",
|
133
|
+
"talon_one_accounts",
|
134
|
+
"tax_calculators",
|
135
|
+
"tax_categories",
|
136
|
+
"tax_rules",
|
137
|
+
"taxjar_accounts",
|
138
|
+
"transactions",
|
139
|
+
"versions",
|
140
|
+
"vertex_accounts",
|
141
|
+
"voids",
|
142
|
+
"webhooks",
|
143
|
+
"wire_transfers"
|
144
|
+
// ##__API_RESOURCE_LIST_STOP__##
|
145
|
+
];
|
146
|
+
var resourceList = apiResources;
|
9
147
|
|
10
|
-
|
11
|
-
var
|
148
|
+
// src/common.ts
|
149
|
+
var isResourceId = (resource) => {
|
150
|
+
return resource?.type && resource.id && resourceList.includes(resource.type);
|
151
|
+
};
|
152
|
+
var isResourceType = (resource) => {
|
153
|
+
return resource && typeof resource.type !== "undefined" && resource.type && resourceList.includes(resource.type);
|
154
|
+
};
|
155
|
+
|
156
|
+
// src/config.ts
|
157
|
+
var config = {
|
158
|
+
jsonapi: {
|
159
|
+
maxResourceIncluded: 2
|
160
|
+
}
|
161
|
+
};
|
162
|
+
var config_default = config;
|
163
|
+
|
164
|
+
// src/debug.ts
|
165
|
+
var debuggerFunction = (_pattern, ..._args) => {
|
166
|
+
};
|
167
|
+
var debuggerFactory = (_namespace) => debuggerFunction;
|
168
|
+
try {
|
169
|
+
const debugModule = __require("debug");
|
170
|
+
if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
|
171
|
+
} catch (error) {
|
172
|
+
}
|
173
|
+
var debugPrefix = "clsdk";
|
174
|
+
var debug = (namespace) => {
|
175
|
+
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
176
|
+
};
|
177
|
+
var debug_default = debug;
|
12
178
|
|
13
|
-
|
14
|
-
|
179
|
+
// src/jsonapi.ts
|
180
|
+
var debug2 = debug_default("jsonapi");
|
181
|
+
var denormalize = (response) => {
|
15
182
|
if (!response) return response;
|
16
183
|
let denormalizedResponse;
|
17
184
|
if (response.links) delete response.links;
|
@@ -24,14 +191,14 @@ const denormalize = (response) => {
|
|
24
191
|
}
|
25
192
|
return denormalizedResponse;
|
26
193
|
};
|
27
|
-
|
194
|
+
var findIncluded = (rel, included = []) => {
|
28
195
|
const inc = included.find((inc2) => {
|
29
196
|
return rel.id === inc2.id && rel.type === inc2.type;
|
30
197
|
});
|
31
198
|
return inc || rel;
|
32
199
|
};
|
33
|
-
|
34
|
-
|
200
|
+
var denormalizeResource = (res, included, chain = []) => {
|
201
|
+
debug2("denormalize resource: %O, %o", res, included || {});
|
35
202
|
if (!res) return res;
|
36
203
|
const resource = {
|
37
204
|
id: res.id,
|
@@ -41,28 +208,28 @@ const denormalizeResource = (res, included, chain = []) => {
|
|
41
208
|
if (res.relationships) Object.keys(res.relationships).forEach((key) => {
|
42
209
|
const rel = res.relationships[key].data;
|
43
210
|
if (rel) {
|
44
|
-
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >=
|
211
|
+
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config_default.jsonapi.maxResourceIncluded) resource[key] = rel;
|
45
212
|
else {
|
46
213
|
if (Array.isArray(rel)) resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
|
47
214
|
else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
48
215
|
}
|
49
216
|
} else if (rel === null) resource[key] = null;
|
50
217
|
});
|
51
|
-
|
218
|
+
debug2("denormalized resource: %O", resource);
|
52
219
|
return resource;
|
53
220
|
};
|
54
|
-
|
55
|
-
|
221
|
+
var normalize = (resource) => {
|
222
|
+
debug2("normalize resource: %O", resource);
|
56
223
|
const attributes = {};
|
57
224
|
const relationships = {};
|
58
225
|
for (const field in resource) {
|
59
226
|
if (["type", "id"].includes(field)) continue;
|
60
227
|
const value = resource[field];
|
61
|
-
if (Array.isArray(value) && value.length === 1 &&
|
228
|
+
if (Array.isArray(value) && value.length === 1 && isResourceType(value[0]) && value[0].id === null) {
|
62
229
|
relationships[field] = { data: [] };
|
63
|
-
} else if (value &&
|
230
|
+
} else if (value && isResourceType(value) && value.id === null) {
|
64
231
|
relationships[field] = { data: null };
|
65
|
-
} else if (value && (
|
232
|
+
} else if (value && (isResourceId(value) || Array.isArray(value) && isResourceId(value[0]))) {
|
66
233
|
relationships[field] = { data: value };
|
67
234
|
} else attributes[field] = value;
|
68
235
|
}
|
@@ -71,8 +238,8 @@ const normalize = (resource) => {
|
|
71
238
|
attributes,
|
72
239
|
relationships
|
73
240
|
};
|
74
|
-
if (
|
75
|
-
|
241
|
+
if (isResourceId(resource)) normalized.id = resource.id;
|
242
|
+
debug2("normalized resource: %O", normalized);
|
76
243
|
return normalized;
|
77
244
|
};
|
78
245
|
|
package/lib/jsonapi.js
CHANGED
@@ -1,10 +1,182 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
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
|
+
});
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
// src/enum.ts
|
9
|
+
var apiResources = [
|
10
|
+
// ##__API_RESOURCE_LIST_START__##
|
11
|
+
"addresses",
|
12
|
+
"adjustments",
|
13
|
+
"adyen_gateways",
|
14
|
+
"adyen_payments",
|
15
|
+
"applications",
|
16
|
+
"attachments",
|
17
|
+
"authorizations",
|
18
|
+
"avalara_accounts",
|
19
|
+
"axerve_gateways",
|
20
|
+
"axerve_payments",
|
21
|
+
"bing_geocoders",
|
22
|
+
"braintree_gateways",
|
23
|
+
"braintree_payments",
|
24
|
+
"bundles",
|
25
|
+
"buy_x_pay_y_promotions",
|
26
|
+
"captures",
|
27
|
+
"carrier_accounts",
|
28
|
+
"checkout_com_gateways",
|
29
|
+
"checkout_com_payments",
|
30
|
+
"cleanups",
|
31
|
+
"coupon_codes_promotion_rules",
|
32
|
+
"coupon_recipients",
|
33
|
+
"coupons",
|
34
|
+
"custom_promotion_rules",
|
35
|
+
"customer_addresses",
|
36
|
+
"customer_groups",
|
37
|
+
"customer_password_resets",
|
38
|
+
"customer_payment_sources",
|
39
|
+
"customer_subscriptions",
|
40
|
+
"customers",
|
41
|
+
"delivery_lead_times",
|
42
|
+
"discount_engine_items",
|
43
|
+
"discount_engines",
|
44
|
+
"easypost_pickups",
|
45
|
+
"event_callbacks",
|
46
|
+
"events",
|
47
|
+
"exports",
|
48
|
+
"external_gateways",
|
49
|
+
"external_payments",
|
50
|
+
"external_promotions",
|
51
|
+
"external_tax_calculators",
|
52
|
+
"fixed_amount_promotions",
|
53
|
+
"fixed_price_promotions",
|
54
|
+
"flex_promotions",
|
55
|
+
"free_gift_promotions",
|
56
|
+
"free_shipping_promotions",
|
57
|
+
"geocoders",
|
58
|
+
"gift_card_recipients",
|
59
|
+
"gift_cards",
|
60
|
+
"google_geocoders",
|
61
|
+
"imports",
|
62
|
+
"in_stock_subscriptions",
|
63
|
+
"inventory_models",
|
64
|
+
"inventory_return_locations",
|
65
|
+
"inventory_stock_locations",
|
66
|
+
"klarna_gateways",
|
67
|
+
"klarna_payments",
|
68
|
+
"line_item_options",
|
69
|
+
"line_items",
|
70
|
+
"links",
|
71
|
+
"manual_gateways",
|
72
|
+
"manual_tax_calculators",
|
73
|
+
"markets",
|
74
|
+
"merchants",
|
75
|
+
"notifications",
|
76
|
+
"order_amount_promotion_rules",
|
77
|
+
"order_copies",
|
78
|
+
"order_factories",
|
79
|
+
"order_subscription_items",
|
80
|
+
"order_subscriptions",
|
81
|
+
"orders",
|
82
|
+
"organizations",
|
83
|
+
"packages",
|
84
|
+
"parcel_line_items",
|
85
|
+
"parcels",
|
86
|
+
"payment_gateways",
|
87
|
+
"payment_methods",
|
88
|
+
"payment_options",
|
89
|
+
"paypal_gateways",
|
90
|
+
"paypal_payments",
|
91
|
+
"percentage_discount_promotions",
|
92
|
+
"pickups",
|
93
|
+
"price_frequency_tiers",
|
94
|
+
"price_list_schedulers",
|
95
|
+
"price_lists",
|
96
|
+
"price_tiers",
|
97
|
+
"price_volume_tiers",
|
98
|
+
"prices",
|
99
|
+
"promotion_rules",
|
100
|
+
"promotions",
|
101
|
+
"recurring_order_copies",
|
102
|
+
"refunds",
|
103
|
+
"reserved_stocks",
|
104
|
+
"resource_errors",
|
105
|
+
"return_line_items",
|
106
|
+
"returns",
|
107
|
+
"satispay_gateways",
|
108
|
+
"satispay_payments",
|
109
|
+
"shipments",
|
110
|
+
"shipping_categories",
|
111
|
+
"shipping_method_tiers",
|
112
|
+
"shipping_methods",
|
113
|
+
"shipping_weight_tiers",
|
114
|
+
"shipping_zones",
|
115
|
+
"sku_list_items",
|
116
|
+
"sku_list_promotion_rules",
|
117
|
+
"sku_lists",
|
118
|
+
"sku_options",
|
119
|
+
"skus",
|
120
|
+
"stock_items",
|
121
|
+
"stock_line_items",
|
122
|
+
"stock_locations",
|
123
|
+
"stock_reservations",
|
124
|
+
"stock_transfers",
|
125
|
+
"stores",
|
126
|
+
"stripe_gateways",
|
127
|
+
"stripe_payments",
|
128
|
+
"stripe_tax_accounts",
|
129
|
+
"subscription_models",
|
130
|
+
"tags",
|
131
|
+
"talon_one_accounts",
|
132
|
+
"tax_calculators",
|
133
|
+
"tax_categories",
|
134
|
+
"tax_rules",
|
135
|
+
"taxjar_accounts",
|
136
|
+
"transactions",
|
137
|
+
"versions",
|
138
|
+
"vertex_accounts",
|
139
|
+
"voids",
|
140
|
+
"webhooks",
|
141
|
+
"wire_transfers"
|
142
|
+
// ##__API_RESOURCE_LIST_STOP__##
|
143
|
+
];
|
144
|
+
var resourceList = apiResources;
|
145
|
+
|
146
|
+
// src/common.ts
|
147
|
+
var isResourceId = (resource) => {
|
148
|
+
return resource?.type && resource.id && resourceList.includes(resource.type);
|
149
|
+
};
|
150
|
+
var isResourceType = (resource) => {
|
151
|
+
return resource && typeof resource.type !== "undefined" && resource.type && resourceList.includes(resource.type);
|
152
|
+
};
|
153
|
+
|
154
|
+
// src/config.ts
|
155
|
+
var config = {
|
156
|
+
jsonapi: {
|
157
|
+
maxResourceIncluded: 2
|
158
|
+
}
|
159
|
+
};
|
160
|
+
var config_default = config;
|
161
|
+
|
162
|
+
// src/debug.ts
|
163
|
+
var debuggerFunction = (_pattern, ..._args) => {
|
164
|
+
};
|
165
|
+
var debuggerFactory = (_namespace) => debuggerFunction;
|
166
|
+
try {
|
167
|
+
const debugModule = __require("debug");
|
168
|
+
if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
|
169
|
+
} catch (error) {
|
170
|
+
}
|
171
|
+
var debugPrefix = "clsdk";
|
172
|
+
var debug = (namespace) => {
|
173
|
+
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
174
|
+
};
|
175
|
+
var debug_default = debug;
|
176
|
+
|
177
|
+
// src/jsonapi.ts
|
178
|
+
var debug2 = debug_default("jsonapi");
|
179
|
+
var denormalize = (response) => {
|
8
180
|
if (!response) return response;
|
9
181
|
let denormalizedResponse;
|
10
182
|
if (response.links) delete response.links;
|
@@ -17,14 +189,14 @@ const denormalize = (response) => {
|
|
17
189
|
}
|
18
190
|
return denormalizedResponse;
|
19
191
|
};
|
20
|
-
|
192
|
+
var findIncluded = (rel, included = []) => {
|
21
193
|
const inc = included.find((inc2) => {
|
22
194
|
return rel.id === inc2.id && rel.type === inc2.type;
|
23
195
|
});
|
24
196
|
return inc || rel;
|
25
197
|
};
|
26
|
-
|
27
|
-
|
198
|
+
var denormalizeResource = (res, included, chain = []) => {
|
199
|
+
debug2("denormalize resource: %O, %o", res, included || {});
|
28
200
|
if (!res) return res;
|
29
201
|
const resource = {
|
30
202
|
id: res.id,
|
@@ -34,18 +206,18 @@ const denormalizeResource = (res, included, chain = []) => {
|
|
34
206
|
if (res.relationships) Object.keys(res.relationships).forEach((key) => {
|
35
207
|
const rel = res.relationships[key].data;
|
36
208
|
if (rel) {
|
37
|
-
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >=
|
209
|
+
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config_default.jsonapi.maxResourceIncluded) resource[key] = rel;
|
38
210
|
else {
|
39
211
|
if (Array.isArray(rel)) resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
|
40
212
|
else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
41
213
|
}
|
42
214
|
} else if (rel === null) resource[key] = null;
|
43
215
|
});
|
44
|
-
|
216
|
+
debug2("denormalized resource: %O", resource);
|
45
217
|
return resource;
|
46
218
|
};
|
47
|
-
|
48
|
-
|
219
|
+
var normalize = (resource) => {
|
220
|
+
debug2("normalize resource: %O", resource);
|
49
221
|
const attributes = {};
|
50
222
|
const relationships = {};
|
51
223
|
for (const field in resource) {
|
@@ -65,7 +237,7 @@ const normalize = (resource) => {
|
|
65
237
|
relationships
|
66
238
|
};
|
67
239
|
if (isResourceId(resource)) normalized.id = resource.id;
|
68
|
-
|
240
|
+
debug2("normalized resource: %O", normalized);
|
69
241
|
return normalized;
|
70
242
|
};
|
71
243
|
|
package/lib/query.cjs
CHANGED
@@ -1,27 +1,85 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
require(
|
4
|
-
|
5
|
-
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
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
|
+
});
|
6
9
|
|
7
|
-
|
10
|
+
// src/debug.ts
|
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;
|
8
24
|
|
9
|
-
|
25
|
+
// src/error.ts
|
26
|
+
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
27
|
+
ErrorType2["CLIENT"] = "client";
|
28
|
+
ErrorType2["REQUEST"] = "request";
|
29
|
+
ErrorType2["RESPONSE"] = "response";
|
30
|
+
ErrorType2["CANCEL"] = "cancel";
|
31
|
+
ErrorType2["PARSE"] = "parse";
|
32
|
+
ErrorType2["TIMEOUT"] = "timeout";
|
33
|
+
ErrorType2["TOKEN_REFRESH"] = "token-refresh";
|
34
|
+
return ErrorType2;
|
35
|
+
})(ErrorType || {});
|
36
|
+
var SdkError = class _SdkError extends Error {
|
37
|
+
static NAME = "SdkError";
|
38
|
+
static isSdkError(error) {
|
39
|
+
return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
40
|
+
}
|
41
|
+
type;
|
42
|
+
code;
|
43
|
+
source;
|
44
|
+
constructor(error) {
|
45
|
+
super(error.message);
|
46
|
+
this.name = _SdkError.NAME;
|
47
|
+
this.type = error.type || "client" /* CLIENT */;
|
48
|
+
}
|
49
|
+
};
|
50
|
+
var ApiError = class _ApiError extends SdkError {
|
51
|
+
static NAME = "ApiError";
|
52
|
+
static isApiError(error) {
|
53
|
+
return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
|
54
|
+
}
|
55
|
+
errors = [];
|
56
|
+
status;
|
57
|
+
statusText;
|
58
|
+
// constructor(error: SdkError)
|
59
|
+
constructor(error) {
|
60
|
+
super({ ...error, type: "response" /* RESPONSE */ });
|
61
|
+
this.name = _ApiError.NAME;
|
62
|
+
}
|
63
|
+
first() {
|
64
|
+
return this.errors?.length > 0 ? this.errors[0] : void 0;
|
65
|
+
}
|
66
|
+
};
|
10
67
|
|
11
|
-
|
12
|
-
|
13
|
-
|
68
|
+
// src/query.ts
|
69
|
+
var debug2 = debug_default("query");
|
70
|
+
var arrayFilters = ["_any", "_all", "_in", "_not_in_or_null"];
|
71
|
+
var isArrayFilter = (filter) => {
|
14
72
|
return arrayFilters.some((f) => filter.endsWith(f));
|
15
73
|
};
|
16
|
-
|
17
|
-
|
74
|
+
var objectFilters = ["_jcont"];
|
75
|
+
var isObjectFilter = (filter) => {
|
18
76
|
return objectFilters.some((f) => filter.endsWith(f));
|
19
77
|
};
|
20
|
-
|
78
|
+
var isParamsList = (params) => {
|
21
79
|
return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
|
22
80
|
};
|
23
|
-
|
24
|
-
|
81
|
+
var generateQueryStringParams = (params, res) => {
|
82
|
+
debug2("generate query string params: %O, %O", params, res);
|
25
83
|
const qp = {};
|
26
84
|
if (!params) return qp;
|
27
85
|
if (params.include) qp.include = params.include.join(",");
|
@@ -42,20 +100,20 @@ const generateQueryStringParams = (params, res) => {
|
|
42
100
|
Object.entries(params.filters).forEach(([p, v]) => {
|
43
101
|
let val;
|
44
102
|
if (Array.isArray(v)) {
|
45
|
-
if (!isArrayFilter(p)) throw new
|
103
|
+
if (!isArrayFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Array value is supported only for the following filters: ${arrayFilters.join(", ")}`, type: "request" /* REQUEST */ });
|
46
104
|
val = v.join(",");
|
47
105
|
} else if (typeof v === "object") {
|
48
|
-
if (!isObjectFilter(p)) throw new
|
106
|
+
if (!isObjectFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Object value is supported only for the following filters: ${objectFilters.join(", ")}`, type: "request" /* REQUEST */ });
|
49
107
|
val = JSON.stringify(v);
|
50
108
|
} else val = String(v);
|
51
109
|
qp[`filter[q][${p}]`] = val;
|
52
110
|
});
|
53
111
|
}
|
54
112
|
}
|
55
|
-
|
113
|
+
debug2("query string params: %O", qp);
|
56
114
|
return qp;
|
57
115
|
};
|
58
|
-
|
116
|
+
var generateSearchString = (params, questionMark = true) => {
|
59
117
|
if (!params || Object.keys(params).length === 0) return "";
|
60
118
|
return `${questionMark ? "?" : ""}${Object.entries(params).map(([key, val]) => `${key}=${String(val)}`).join("&")}`;
|
61
119
|
};
|