@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/jsonapi.cjs
CHANGED
@@ -1,184 +1,16 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
4
|
-
|
5
|
-
|
6
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
7
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
8
|
-
});
|
3
|
+
var common = require('./common');
|
4
|
+
var config = require('./config');
|
5
|
+
var Debug = require('./debug');
|
9
6
|
|
10
|
-
|
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;
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
147
8
|
|
148
|
-
|
149
|
-
var
|
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;
|
9
|
+
var config__default = /*#__PURE__*/_interopDefault(config);
|
10
|
+
var Debug__default = /*#__PURE__*/_interopDefault(Debug);
|
178
11
|
|
179
|
-
|
180
|
-
|
181
|
-
var denormalize = (response) => {
|
12
|
+
const debug = Debug__default.default("jsonapi");
|
13
|
+
const denormalize = (response) => {
|
182
14
|
if (!response) return response;
|
183
15
|
let denormalizedResponse;
|
184
16
|
if (response.links) delete response.links;
|
@@ -191,14 +23,14 @@ var denormalize = (response) => {
|
|
191
23
|
}
|
192
24
|
return denormalizedResponse;
|
193
25
|
};
|
194
|
-
|
26
|
+
const findIncluded = (rel, included = []) => {
|
195
27
|
const inc = included.find((inc2) => {
|
196
28
|
return rel.id === inc2.id && rel.type === inc2.type;
|
197
29
|
});
|
198
30
|
return inc || rel;
|
199
31
|
};
|
200
|
-
|
201
|
-
|
32
|
+
const denormalizeResource = (res, included, chain = []) => {
|
33
|
+
debug("denormalize resource: %O, %o", res, included || {});
|
202
34
|
if (!res) return res;
|
203
35
|
const resource = {
|
204
36
|
id: res.id,
|
@@ -208,28 +40,28 @@ var denormalizeResource = (res, included, chain = []) => {
|
|
208
40
|
if (res.relationships) Object.keys(res.relationships).forEach((key) => {
|
209
41
|
const rel = res.relationships[key].data;
|
210
42
|
if (rel) {
|
211
|
-
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >=
|
43
|
+
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config__default.default.jsonapi.maxResourceIncluded) resource[key] = rel;
|
212
44
|
else {
|
213
45
|
if (Array.isArray(rel)) resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
|
214
46
|
else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
215
47
|
}
|
216
48
|
} else if (rel === null) resource[key] = null;
|
217
49
|
});
|
218
|
-
|
50
|
+
debug("denormalized resource: %O", resource);
|
219
51
|
return resource;
|
220
52
|
};
|
221
|
-
|
222
|
-
|
53
|
+
const normalize = (resource) => {
|
54
|
+
debug("normalize resource: %O", resource);
|
223
55
|
const attributes = {};
|
224
56
|
const relationships = {};
|
225
57
|
for (const field in resource) {
|
226
58
|
if (["type", "id"].includes(field)) continue;
|
227
59
|
const value = resource[field];
|
228
|
-
if (Array.isArray(value) && value.length === 1 && isResourceType(value[0]) && value[0].id === null) {
|
60
|
+
if (Array.isArray(value) && value.length === 1 && common.isResourceType(value[0]) && value[0].id === null) {
|
229
61
|
relationships[field] = { data: [] };
|
230
|
-
} else if (value && isResourceType(value) && value.id === null) {
|
62
|
+
} else if (value && common.isResourceType(value) && value.id === null) {
|
231
63
|
relationships[field] = { data: null };
|
232
|
-
} else if (value && (isResourceId(value) || Array.isArray(value) && isResourceId(value[0]))) {
|
64
|
+
} else if (value && (common.isResourceId(value) || Array.isArray(value) && common.isResourceId(value[0]))) {
|
233
65
|
relationships[field] = { data: value };
|
234
66
|
} else attributes[field] = value;
|
235
67
|
}
|
@@ -238,8 +70,8 @@ var normalize = (resource) => {
|
|
238
70
|
attributes,
|
239
71
|
relationships
|
240
72
|
};
|
241
|
-
if (isResourceId(resource)) normalized.id = resource.id;
|
242
|
-
|
73
|
+
if (common.isResourceId(resource)) normalized.id = resource.id;
|
74
|
+
debug("normalized resource: %O", normalized);
|
243
75
|
return normalized;
|
244
76
|
};
|
245
77
|
|
package/lib/jsonapi.js
CHANGED
@@ -1,182 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
6
|
-
});
|
1
|
+
import { isResourceType, isResourceId } from './common';
|
2
|
+
import config from './config';
|
3
|
+
import Debug from './debug';
|
7
4
|
|
8
|
-
|
9
|
-
|
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) => {
|
5
|
+
const debug = Debug("jsonapi");
|
6
|
+
const denormalize = (response) => {
|
180
7
|
if (!response) return response;
|
181
8
|
let denormalizedResponse;
|
182
9
|
if (response.links) delete response.links;
|
@@ -189,14 +16,14 @@ var denormalize = (response) => {
|
|
189
16
|
}
|
190
17
|
return denormalizedResponse;
|
191
18
|
};
|
192
|
-
|
19
|
+
const findIncluded = (rel, included = []) => {
|
193
20
|
const inc = included.find((inc2) => {
|
194
21
|
return rel.id === inc2.id && rel.type === inc2.type;
|
195
22
|
});
|
196
23
|
return inc || rel;
|
197
24
|
};
|
198
|
-
|
199
|
-
|
25
|
+
const denormalizeResource = (res, included, chain = []) => {
|
26
|
+
debug("denormalize resource: %O, %o", res, included || {});
|
200
27
|
if (!res) return res;
|
201
28
|
const resource = {
|
202
29
|
id: res.id,
|
@@ -206,18 +33,18 @@ var denormalizeResource = (res, included, chain = []) => {
|
|
206
33
|
if (res.relationships) Object.keys(res.relationships).forEach((key) => {
|
207
34
|
const rel = res.relationships[key].data;
|
208
35
|
if (rel) {
|
209
|
-
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >=
|
36
|
+
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config.jsonapi.maxResourceIncluded) resource[key] = rel;
|
210
37
|
else {
|
211
38
|
if (Array.isArray(rel)) resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
|
212
39
|
else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
213
40
|
}
|
214
41
|
} else if (rel === null) resource[key] = null;
|
215
42
|
});
|
216
|
-
|
43
|
+
debug("denormalized resource: %O", resource);
|
217
44
|
return resource;
|
218
45
|
};
|
219
|
-
|
220
|
-
|
46
|
+
const normalize = (resource) => {
|
47
|
+
debug("normalize resource: %O", resource);
|
221
48
|
const attributes = {};
|
222
49
|
const relationships = {};
|
223
50
|
for (const field in resource) {
|
@@ -237,7 +64,7 @@ var normalize = (resource) => {
|
|
237
64
|
relationships
|
238
65
|
};
|
239
66
|
if (isResourceId(resource)) normalized.id = resource.id;
|
240
|
-
|
67
|
+
debug("normalized resource: %O", normalized);
|
241
68
|
return normalized;
|
242
69
|
};
|
243
70
|
|
package/lib/query.cjs
CHANGED
@@ -1,85 +1,26 @@
|
|
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 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;
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
24
7
|
|
25
|
-
|
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
|
-
};
|
8
|
+
var Debug__default = /*#__PURE__*/_interopDefault(Debug);
|
67
9
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
var isArrayFilter = (filter) => {
|
10
|
+
const debug = Debug__default.default("query");
|
11
|
+
const arrayFilters = ["_any", "_all", "_in", "_not_in_or_null"];
|
12
|
+
const isArrayFilter = (filter) => {
|
72
13
|
return arrayFilters.some((f) => filter.endsWith(f));
|
73
14
|
};
|
74
|
-
|
75
|
-
|
15
|
+
const objectFilters = ["_jcont"];
|
16
|
+
const isObjectFilter = (filter) => {
|
76
17
|
return objectFilters.some((f) => filter.endsWith(f));
|
77
18
|
};
|
78
|
-
|
19
|
+
const isParamsList = (params) => {
|
79
20
|
return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
|
80
21
|
};
|
81
|
-
|
82
|
-
|
22
|
+
const generateQueryStringParams = (params, res) => {
|
23
|
+
debug("generate query string params: %O, %O", params, res);
|
83
24
|
const qp = {};
|
84
25
|
if (!params) return qp;
|
85
26
|
if (params.include) qp.include = params.include.join(",");
|
@@ -100,20 +41,20 @@ var generateQueryStringParams = (params, res) => {
|
|
100
41
|
Object.entries(params.filters).forEach(([p, v]) => {
|
101
42
|
let val;
|
102
43
|
if (Array.isArray(v)) {
|
103
|
-
if (!isArrayFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Array value is supported only for the following filters: ${arrayFilters.join(", ")}`, type:
|
44
|
+
if (!isArrayFilter(p)) throw new error.SdkError({ message: `Incorrect filter [${p}]: Array value is supported only for the following filters: ${arrayFilters.join(", ")}`, type: error.ErrorType.REQUEST });
|
104
45
|
val = v.join(",");
|
105
46
|
} else if (typeof v === "object") {
|
106
|
-
if (!isObjectFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Object value is supported only for the following filters: ${objectFilters.join(", ")}`, type:
|
47
|
+
if (!isObjectFilter(p)) throw new error.SdkError({ message: `Incorrect filter [${p}]: Object value is supported only for the following filters: ${objectFilters.join(", ")}`, type: error.ErrorType.REQUEST });
|
107
48
|
val = JSON.stringify(v);
|
108
49
|
} else val = String(v);
|
109
50
|
qp[`filter[q][${p}]`] = val;
|
110
51
|
});
|
111
52
|
}
|
112
53
|
}
|
113
|
-
|
54
|
+
debug("query string params: %O", qp);
|
114
55
|
return qp;
|
115
56
|
};
|
116
|
-
|
57
|
+
const generateSearchString = (params, questionMark = true) => {
|
117
58
|
if (!params || Object.keys(params).length === 0) return "";
|
118
59
|
return `${questionMark ? "?" : ""}${Object.entries(params).map(([key, val]) => `${key}=${String(val)}`).join("&")}`;
|
119
60
|
};
|