@commercelayer/sdk 6.0.0-alfa.5 → 6.0.0-alfa.6
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/cjs/api.d.ts +0 -3
- package/lib/cjs/api.js +0 -10
- package/lib/cjs/client.js +0 -23
- package/lib/cjs/commercelayer.js +3 -25
- package/lib/cjs/common.js +0 -11
- package/lib/cjs/config.js +0 -2
- package/lib/cjs/debug.js +0 -21
- package/lib/cjs/error.d.ts +5 -5
- package/lib/cjs/error.js +1 -6
- package/lib/cjs/fetch.js +2 -2
- package/lib/cjs/index.js +0 -2
- package/lib/cjs/jsonapi.js +0 -2
- package/lib/cjs/model.d.ts +0 -3
- package/lib/cjs/model.js +0 -1
- package/lib/cjs/query.js +0 -5
- package/lib/cjs/resource.js +0 -35
- package/lib/cjs/static.js +0 -1
- package/lib/cjs/util.js +0 -1
- package/lib/esm/api.d.ts +0 -3
- package/lib/esm/api.js +0 -10
- package/lib/esm/client.js +0 -23
- package/lib/esm/commercelayer.js +3 -25
- package/lib/esm/common.js +0 -11
- package/lib/esm/config.js +0 -2
- package/lib/esm/debug.js +0 -21
- package/lib/esm/error.d.ts +5 -5
- package/lib/esm/error.js +1 -6
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/index.js +0 -2
- package/lib/esm/jsonapi.js +0 -2
- package/lib/esm/model.d.ts +0 -3
- package/lib/esm/model.js +0 -1
- package/lib/esm/query.js +0 -5
- package/lib/esm/resource.js +0 -35
- package/lib/esm/static.js +0 -1
- package/lib/esm/util.js +1 -27
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
package/lib/cjs/api.d.ts
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
import type { Resource, ResourceRel } from './resource';
|
2
2
|
import type { TagType } from './resources/tags';
|
3
3
|
import type { VersionType } from './resources/versions';
|
4
|
-
/**
|
5
|
-
* ©2024 Commerce Layer Inc.
|
6
|
-
**/
|
7
4
|
export { default as Addresses } from './resources/addresses';
|
8
5
|
export { default as Adjustments } from './resources/adjustments';
|
9
6
|
export { default as AdyenGateways } from './resources/adyen_gateways';
|
package/lib/cjs/api.js
CHANGED
@@ -6,11 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.InventoryModels = exports.InStockSubscriptions = exports.Imports = exports.GoogleGeocoders = exports.GiftCards = exports.GiftCardRecipients = exports.Geocoders = exports.FreeShippingPromotions = exports.FreeGiftPromotions = exports.FixedPricePromotions = exports.FixedAmountPromotions = exports.ExternalTaxCalculators = exports.ExternalPromotions = exports.ExternalPayments = exports.ExternalGateways = exports.Exports = exports.Events = exports.EventCallbacks = exports.DeliveryLeadTimes = exports.Customers = exports.CustomerSubscriptions = exports.CustomerPaymentSources = exports.CustomerPasswordResets = exports.CustomerGroups = exports.CustomerAddresses = exports.CustomPromotionRules = exports.Coupons = exports.CouponRecipients = exports.CouponCodesPromotionRules = exports.Cleanups = exports.CheckoutComPayments = exports.CheckoutComGateways = exports.CarrierAccounts = exports.Captures = exports.BuyXPayYPromotions = exports.Bundles = exports.BraintreePayments = exports.BraintreeGateways = exports.BingGeocoders = exports.BillingInfoValidationRules = exports.AxervePayments = exports.AxerveGateways = exports.AvalaraAccounts = exports.Authorizations = exports.Attachments = exports.Applications = exports.AdyenPayments = exports.AdyenGateways = exports.Adjustments = exports.Addresses = void 0;
|
7
7
|
exports.SkuListPromotionRules = exports.SkuListItems = exports.ShippingZones = exports.ShippingWeightTiers = exports.ShippingMethods = exports.ShippingMethodTiers = exports.ShippingCategories = exports.Shipments = exports.SatispayPayments = exports.SatispayGateways = exports.Returns = exports.ReturnLineItems = exports.ResourceErrors = exports.ReservedStocks = exports.Refunds = exports.RecurringOrderCopies = exports.Promotions = exports.PromotionRules = exports.Prices = exports.PriceVolumeTiers = exports.PriceTiers = exports.PriceLists = exports.PriceFrequencyTiers = exports.PercentageDiscountPromotions = exports.PaypalPayments = exports.PaypalGateways = exports.PaymentOptions = exports.PaymentMethods = exports.PaymentGateways = exports.Parcels = exports.ParcelLineItems = exports.Packages = exports.Organizations = exports.Orders = exports.OrderValidationRules = exports.OrderSubscriptions = exports.OrderSubscriptionItems = exports.OrderFactories = exports.OrderCopies = exports.OrderAmountPromotionRules = exports.Merchants = exports.Markets = exports.ManualTaxCalculators = exports.ManualGateways = exports.LineItems = exports.LineItemOptions = exports.KlarnaPayments = exports.KlarnaGateways = exports.InventoryStockLocations = exports.InventoryReturnLocations = void 0;
|
8
8
|
exports.singletonList = exports.resourceList = exports.WireTransfers = exports.Webhooks = exports.Voids = exports.Versions = exports.Transactions = exports.TaxjarAccounts = exports.TaxRules = exports.TaxCategories = exports.TaxCalculators = exports.Tags = exports.SubscriptionModels = exports.StripePayments = exports.StripeGateways = exports.StockTransfers = exports.StockReservations = exports.StockLocations = exports.StockLineItems = exports.StockItems = exports.Skus = exports.SkuOptions = exports.SkuLists = void 0;
|
9
|
-
// ##__API_RESOURCES_START__##
|
10
|
-
// ##__API_RESOURCES_TEMPLATE:: export { default as ##__RESOURCE_CLASS__## } from './resources/##__RESOURCE_TYPE__##'
|
11
|
-
/**
|
12
|
-
* ©2024 Commerce Layer Inc.
|
13
|
-
**/
|
14
9
|
var addresses_1 = require("./resources/addresses");
|
15
10
|
Object.defineProperty(exports, "Addresses", { enumerable: true, get: function () { return __importDefault(addresses_1).default; } });
|
16
11
|
var adjustments_1 = require("./resources/adjustments");
|
@@ -253,9 +248,7 @@ var webhooks_1 = require("./resources/webhooks");
|
|
253
248
|
Object.defineProperty(exports, "Webhooks", { enumerable: true, get: function () { return __importDefault(webhooks_1).default; } });
|
254
249
|
var wire_transfers_1 = require("./resources/wire_transfers");
|
255
250
|
Object.defineProperty(exports, "WireTransfers", { enumerable: true, get: function () { return __importDefault(wire_transfers_1).default; } });
|
256
|
-
// ##__API_RESOURCE_TYPES_STOP__##
|
257
251
|
exports.resourceList = [
|
258
|
-
// ##__API_RESOURCE_LIST_START__##
|
259
252
|
'addresses',
|
260
253
|
'adjustments',
|
261
254
|
'adyen_gateways',
|
@@ -377,11 +370,8 @@ exports.resourceList = [
|
|
377
370
|
'voids',
|
378
371
|
'webhooks',
|
379
372
|
'wire_transfers'
|
380
|
-
// ##__API_RESOURCE_LIST_STOP__##
|
381
373
|
];
|
382
374
|
exports.singletonList = [
|
383
|
-
// ##__API_RESOURCE_SINGLETON_START__##
|
384
375
|
'application',
|
385
376
|
'organization'
|
386
|
-
// ##__API_RESOURCE_SINGLETON_STOP__##
|
387
377
|
];
|
package/lib/cjs/client.js
CHANGED
@@ -40,26 +40,20 @@ class ApiClient {
|
|
40
40
|
__classPrivateFieldSet(this, _ApiClient_accessToken, options.accessToken, "f");
|
41
41
|
const fetchConfig = {
|
42
42
|
timeout: options.timeout || config_1.default.client.timeout,
|
43
|
-
// httpAgent: options.httpAgent,
|
44
|
-
// httpsAgent: options.httpsAgent
|
45
43
|
};
|
46
|
-
// Set custom headers
|
47
44
|
const customHeaders = this.customHeaders(options.headers);
|
48
|
-
// Set headers
|
49
45
|
const headers = {
|
50
46
|
...customHeaders,
|
51
47
|
'Accept': 'application/vnd.api+json',
|
52
48
|
'Content-Type': 'application/vnd.api+json',
|
53
49
|
'Authorization': 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f")
|
54
50
|
};
|
55
|
-
// Set User-Agent
|
56
51
|
const userAgent = options.userAgent;
|
57
52
|
if (userAgent)
|
58
53
|
headers['User-Agent'] = userAgent;
|
59
54
|
fetchConfig.headers = headers;
|
60
55
|
__classPrivateFieldSet(this, _ApiClient_clientConfig, fetchConfig, "f");
|
61
56
|
debug('fetch config: %O', fetchConfig);
|
62
|
-
// Interceptors
|
63
57
|
__classPrivateFieldSet(this, _ApiClient_interceptors, {}, "f");
|
64
58
|
}
|
65
59
|
get interceptors() { return __classPrivateFieldGet(this, _ApiClient_interceptors, "f"); }
|
@@ -68,24 +62,15 @@ class ApiClient {
|
|
68
62
|
__classPrivateFieldGet(this, _ApiClient_clientConfig, "f").headers = {};
|
69
63
|
return __classPrivateFieldGet(this, _ApiClient_clientConfig, "f").headers;
|
70
64
|
}
|
71
|
-
/*
|
72
|
-
set requestHeaders(headers: RequestHeaders) {
|
73
|
-
this.#clientConfig.headers = { ...this.#clientConfig.headers, ...headers }
|
74
|
-
}
|
75
|
-
*/
|
76
65
|
config(config) {
|
77
66
|
debug('config %o', config);
|
78
67
|
const def = __classPrivateFieldGet(this, _ApiClient_clientConfig, "f");
|
79
68
|
if (!def.headers)
|
80
69
|
def.headers = {};
|
81
|
-
// Client config
|
82
70
|
if (config.timeout)
|
83
71
|
def.timeout = config.timeout;
|
84
|
-
// if (config.httpAgent) def.httpAgent = config.httpAgent
|
85
|
-
// if (config.httpsAgent) def.httpsAgent = config.httpsAgent
|
86
72
|
if (config.userAgent)
|
87
73
|
this.userAgent(config.userAgent);
|
88
|
-
// API Client config
|
89
74
|
if (config.organization)
|
90
75
|
__classPrivateFieldSet(this, _ApiClient_baseUrl, baseURL(config.organization, config.domain), "f");
|
91
76
|
if (config.accessToken) {
|
@@ -103,31 +88,23 @@ class ApiClient {
|
|
103
88
|
}
|
104
89
|
async request(method, path, body, options) {
|
105
90
|
debug('request %s %s, %O, %O', method, path, body || {}, options || {});
|
106
|
-
// Ignored params (in debug mode)
|
107
91
|
if (options?.userAgent)
|
108
92
|
debug('User-Agent header ignored in request config');
|
109
|
-
// URL
|
110
93
|
const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : __classPrivateFieldGet(this, _ApiClient_baseUrl, "f");
|
111
94
|
const url = new URL(`${baseUrl}/${path}`);
|
112
|
-
// Body
|
113
95
|
const bodyData = body ? JSON.stringify({ data: body }) : undefined;
|
114
|
-
// Headers
|
115
96
|
const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
|
116
|
-
// Access token
|
117
97
|
const accessToken = options?.accessToken || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
|
118
98
|
if (accessToken)
|
119
99
|
headers.Authorization = 'Bearer ' + accessToken;
|
120
100
|
const fetchOptions = { method, body: bodyData, headers };
|
121
|
-
// Timeout
|
122
101
|
const timeout = options?.timeout || __classPrivateFieldGet(this, _ApiClient_clientConfig, "f").timeout;
|
123
102
|
if (timeout)
|
124
103
|
fetchOptions.signal = AbortSignal.timeout(timeout);
|
125
104
|
if (options?.params)
|
126
105
|
Object.entries(options?.params).forEach(([name, value]) => { url.searchParams.append(name, String(value)); });
|
127
|
-
// const start = Date.now()
|
128
106
|
return await (0, fetch_1.fetchURL)(url, fetchOptions, this.interceptors)
|
129
107
|
.catch((error) => (0, error_1.handleError)(error));
|
130
|
-
// .finally(() => { console.log(`<<-- ${method} ${path} ${Date.now() - start}`) })
|
131
108
|
}
|
132
109
|
customHeaders(headers) {
|
133
110
|
const customHeaders = {};
|
package/lib/cjs/commercelayer.js
CHANGED
@@ -44,19 +44,13 @@ const static_1 = require("./static");
|
|
44
44
|
const resource_1 = __importDefault(require("./resource"));
|
45
45
|
const debug_1 = __importDefault(require("./debug"));
|
46
46
|
const debug = (0, debug_1.default)('commercelayer');
|
47
|
-
// Autogenerated schema version number, do not remove this line
|
48
47
|
const OPEN_API_SCHEMA_VERSION = '5.1.0';
|
49
48
|
exports.OPEN_API_SCHEMA_VERSION = OPEN_API_SCHEMA_VERSION;
|
50
49
|
class CommerceLayerClient {
|
51
|
-
// ##__CL_RESOURCES_DEF_STOP__##
|
52
50
|
constructor(config) {
|
53
|
-
// static get openApiSchemaVersion(): string { return OPEN_API_SCHEMA_VERSION }
|
54
51
|
this.openApiSchemaVersion = OPEN_API_SCHEMA_VERSION;
|
55
52
|
_CommerceLayerClient_adapter.set(this, void 0);
|
56
53
|
_CommerceLayerClient_slug.set(this, void 0);
|
57
|
-
// #environment: ApiMode = sdkConfig.default.environment
|
58
|
-
// ##__CL_RESOURCES_DEF_START__##
|
59
|
-
// ##__CL_RESOURCES_DEF_TEMPLATE:: ##__TAB__#####__RESOURCE_TYPE__##?: api.##__RESOURCE_CLASS__##
|
60
54
|
_CommerceLayerClient_addresses.set(this, void 0);
|
61
55
|
_CommerceLayerClient_adjustments.set(this, void 0);
|
62
56
|
_CommerceLayerClient_adyen_gateways.set(this, void 0);
|
@@ -181,13 +175,7 @@ class CommerceLayerClient {
|
|
181
175
|
debug('new commercelayer instance %O', config);
|
182
176
|
__classPrivateFieldSet(this, _CommerceLayerClient_adapter, new resource_1.default(config), "f");
|
183
177
|
__classPrivateFieldSet(this, _CommerceLayerClient_slug, config.organization, "f");
|
184
|
-
// this.#environment = 'test'
|
185
|
-
// ##__CL_RESOURCES_INIT_START__##
|
186
|
-
// ##__CL_RESOURCES_INIT_TEMPLATE:: ##__TAB__####__TAB__##this.##__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)
|
187
|
-
// ##__CL_RESOURCES_INIT_STOP__##
|
188
178
|
}
|
189
|
-
// ##__CL_RESOURCES_LEAZY_LOADING_START__##
|
190
|
-
// ##__CL_RESOURCES_LEAZY_LOADING_TEMPLATE:: ##__TAB__##get ##__RESOURCE_TYPE__##(): api.##__RESOURCE_CLASS__## { return this.###__RESOURCE_TYPE__## || (this.###__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)) }
|
191
179
|
get addresses() { return __classPrivateFieldGet(this, _CommerceLayerClient_addresses, "f") || (__classPrivateFieldSet(this, _CommerceLayerClient_addresses, new api.Addresses(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f")), "f")); }
|
192
180
|
get adjustments() { return __classPrivateFieldGet(this, _CommerceLayerClient_adjustments, "f") || (__classPrivateFieldSet(this, _CommerceLayerClient_adjustments, new api.Adjustments(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f")), "f")); }
|
193
181
|
get adyen_gateways() { return __classPrivateFieldGet(this, _CommerceLayerClient_adyen_gateways, "f") || (__classPrivateFieldSet(this, _CommerceLayerClient_adyen_gateways, new api.AdyenGateways(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f")), "f")); }
|
@@ -309,10 +297,7 @@ class CommerceLayerClient {
|
|
309
297
|
get voids() { return __classPrivateFieldGet(this, _CommerceLayerClient_voids, "f") || (__classPrivateFieldSet(this, _CommerceLayerClient_voids, new api.Voids(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f")), "f")); }
|
310
298
|
get webhooks() { return __classPrivateFieldGet(this, _CommerceLayerClient_webhooks, "f") || (__classPrivateFieldSet(this, _CommerceLayerClient_webhooks, new api.Webhooks(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f")), "f")); }
|
311
299
|
get wire_transfers() { return __classPrivateFieldGet(this, _CommerceLayerClient_wire_transfers, "f") || (__classPrivateFieldSet(this, _CommerceLayerClient_wire_transfers, new api.WireTransfers(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f")), "f")); }
|
312
|
-
// ##__CL_RESOURCES_LEAZY_LOADING_STOP__##
|
313
300
|
get currentOrganization() { return __classPrivateFieldGet(this, _CommerceLayerClient_slug, "f"); }
|
314
|
-
// get currentAccessToken(): string { return this.#adapter?.clientInstance?.currentAccessToken}
|
315
|
-
// get environment(): ApiMode { return this.#environment }
|
316
301
|
get interceptors() { return __classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f").client.interceptors; }
|
317
302
|
localConfig(config) {
|
318
303
|
if (config.organization)
|
@@ -320,10 +305,7 @@ class CommerceLayerClient {
|
|
320
305
|
}
|
321
306
|
config(config) {
|
322
307
|
debug('config %o', config);
|
323
|
-
// CommerceLayer config
|
324
308
|
this.localConfig(config);
|
325
|
-
// ResourceAdapter config
|
326
|
-
// To rebuild baseUrl in client in case only the domain is defined
|
327
309
|
if (!config.organization)
|
328
310
|
config.organization = this.currentOrganization;
|
329
311
|
__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f").config(config);
|
@@ -367,15 +349,11 @@ class CommerceLayerClient {
|
|
367
349
|
}
|
368
350
|
return response;
|
369
351
|
}
|
370
|
-
|
371
|
-
reader.id = 1;
|
352
|
+
this.interceptors.rawReader = { onSuccess: rawResponseInterceptor, onFailure: rawResponseInterceptor };
|
353
|
+
reader.id = 1;
|
372
354
|
return reader;
|
373
355
|
}
|
374
|
-
removeRawResponseReader(
|
375
|
-
/*
|
376
|
-
const id = (typeof reader === 'number') ? reader : reader?.id
|
377
|
-
if (id && (id >= 0)) this.removeInterceptor('response', id)
|
378
|
-
*/
|
356
|
+
removeRawResponseReader() {
|
379
357
|
this.interceptors.rawReader = undefined;
|
380
358
|
}
|
381
359
|
}
|
package/lib/cjs/common.js
CHANGED
@@ -10,14 +10,3 @@ const isResourceType = (resource) => {
|
|
10
10
|
return resource && (typeof resource.type !== 'undefined') && resource.type && api_1.resourceList.includes(resource.type);
|
11
11
|
};
|
12
12
|
exports.isResourceType = isResourceType;
|
13
|
-
/*
|
14
|
-
// Nullable types
|
15
|
-
type StringNullable = string | null
|
16
|
-
type NumberNullable = number | null
|
17
|
-
type BooleanNullable = boolean | null
|
18
|
-
type ResourceNullable<R extends Resource> = R | null
|
19
|
-
type ResourceArrayNullable<R extends Resource> = R[] | null
|
20
|
-
|
21
|
-
|
22
|
-
export type { StringNullable, NumberNullable, BooleanNullable, ResourceNullable, ResourceArrayNullable }
|
23
|
-
*/
|
package/lib/cjs/config.js
CHANGED
package/lib/cjs/debug.js
CHANGED
@@ -1,37 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
/* Nope debugger */
|
4
3
|
const debuggerFunction = (_pattern, ..._args) => {
|
5
|
-
// console.log(_pattern)
|
6
4
|
};
|
7
5
|
let debuggerFactory = (_namespace) => debuggerFunction;
|
8
|
-
/* Try loading 'debug' module */
|
9
6
|
try {
|
10
7
|
const debugModule = require('debug');
|
11
8
|
if (debugModule && (typeof debugModule === 'function'))
|
12
9
|
debuggerFactory = debugModule;
|
13
10
|
}
|
14
11
|
catch (error) {
|
15
|
-
//
|
16
12
|
}
|
17
13
|
const debugPrefix = 'clsdk';
|
18
|
-
/* Retrieve the name of the caller 'module' */
|
19
|
-
/*
|
20
|
-
const caller = (): string => {
|
21
|
-
|
22
|
-
const err = new Error()
|
23
|
-
|
24
|
-
Error.prepareStackTrace = (_, stack) => stack
|
25
|
-
const stack = err.stack as unknown as NodeJS.CallSite[]
|
26
|
-
Error.prepareStackTrace = undefined
|
27
|
-
|
28
|
-
const fileName = stack[2].getFileName() || '/'
|
29
|
-
|
30
|
-
return fileName.replace(/^.*[\\/]/, '').replace('.ts', '')
|
31
|
-
|
32
|
-
}
|
33
|
-
*/
|
34
|
-
/* Return a debugger for the defined namespace */
|
35
14
|
const debug = (namespace) => {
|
36
15
|
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
37
16
|
};
|
package/lib/cjs/error.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
declare enum ErrorType {
|
2
|
-
CLIENT = "client"
|
3
|
-
REQUEST = "request"
|
4
|
-
RESPONSE = "response"
|
5
|
-
CANCEL = "cancel"
|
6
|
-
PARSE = "parse"
|
2
|
+
CLIENT = "client",
|
3
|
+
REQUEST = "request",
|
4
|
+
RESPONSE = "response",
|
5
|
+
CANCEL = "cancel",
|
6
|
+
PARSE = "parse",
|
7
7
|
TIMEOUT = "timeout"
|
8
8
|
}
|
9
9
|
declare class SdkError extends Error {
|
package/lib/cjs/error.js
CHANGED
@@ -9,7 +9,7 @@ var ErrorType;
|
|
9
9
|
ErrorType["RESPONSE"] = "response";
|
10
10
|
ErrorType["CANCEL"] = "cancel";
|
11
11
|
ErrorType["PARSE"] = "parse";
|
12
|
-
ErrorType["TIMEOUT"] = "timeout";
|
12
|
+
ErrorType["TIMEOUT"] = "timeout";
|
13
13
|
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
14
14
|
class SdkError extends Error {
|
15
15
|
static isSdkError(error) {
|
@@ -50,7 +50,6 @@ const isTimeoutError = (error) => {
|
|
50
50
|
const handleError = (error) => {
|
51
51
|
let sdkError = new SdkError({ message: error.message });
|
52
52
|
if (fetch_1.FetchError.isFetchError(error)) {
|
53
|
-
// console.log('********** FetchError')
|
54
53
|
const apiError = new ApiError(sdkError);
|
55
54
|
apiError.type = ErrorType.RESPONSE;
|
56
55
|
apiError.status = error.status;
|
@@ -62,19 +61,15 @@ const handleError = (error) => {
|
|
62
61
|
sdkError = apiError;
|
63
62
|
}
|
64
63
|
else if (isRequestError(error)) {
|
65
|
-
// console.log('********** RequestError')
|
66
64
|
sdkError.type = ErrorType.REQUEST;
|
67
65
|
}
|
68
66
|
else if (isCancelError(error)) {
|
69
|
-
// console.log('********** CancelError')
|
70
67
|
sdkError.type = ErrorType.CANCEL;
|
71
68
|
}
|
72
69
|
else if (isTimeoutError(error)) {
|
73
|
-
// console.log('********** TimeoutError')
|
74
70
|
sdkError.type = ErrorType.TIMEOUT;
|
75
71
|
}
|
76
72
|
else {
|
77
|
-
// console.log('********** ClientError')
|
78
73
|
sdkError.type = ErrorType.CLIENT;
|
79
74
|
sdkError.source = error;
|
80
75
|
}
|
package/lib/cjs/fetch.js
CHANGED
@@ -42,8 +42,8 @@ const fetchURL = async (url, options, interceptors) => {
|
|
42
42
|
debug('fetch: %s, %O', url, options || {});
|
43
43
|
if (interceptors?.request?.onSuccess)
|
44
44
|
({ url, options } = await interceptors.request.onSuccess({ url, options }));
|
45
|
-
|
46
|
-
let response = await fetch(
|
45
|
+
const request = new Request(url, options);
|
46
|
+
let response = await fetch(request);
|
47
47
|
if (response.ok) {
|
48
48
|
if (interceptors?.rawReader?.onSuccess)
|
49
49
|
await interceptors.rawReader.onSuccess(response);
|
package/lib/cjs/index.js
CHANGED
@@ -4,10 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.CommerceLayerStatic = exports.CommerceLayer = exports.default = void 0;
|
7
|
-
// SDK
|
8
7
|
var commercelayer_1 = require("./commercelayer");
|
9
8
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(commercelayer_1).default; } });
|
10
9
|
Object.defineProperty(exports, "CommerceLayer", { enumerable: true, get: function () { return commercelayer_1.CommerceLayer; } });
|
11
|
-
// Commerce Layer static functions
|
12
10
|
var static_1 = require("./static");
|
13
11
|
Object.defineProperty(exports, "CommerceLayerStatic", { enumerable: true, get: function () { return static_1.CommerceLayerStatic; } });
|
package/lib/cjs/jsonapi.js
CHANGED
@@ -8,7 +8,6 @@ const common_1 = require("./common");
|
|
8
8
|
const config_1 = __importDefault(require("./config"));
|
9
9
|
const debug_1 = __importDefault(require("./debug"));
|
10
10
|
const debug = (0, debug_1.default)('jsonapi');
|
11
|
-
// DENORMALIZATION
|
12
11
|
const denormalize = (response) => {
|
13
12
|
let denormalizedResponse;
|
14
13
|
if (response.links)
|
@@ -60,7 +59,6 @@ const denormalizeResource = (res, included, chain = []) => {
|
|
60
59
|
debug('denormalized resource: %O', resource);
|
61
60
|
return resource;
|
62
61
|
};
|
63
|
-
// NORMALIZATION
|
64
62
|
const normalize = (resource) => {
|
65
63
|
debug('normalize resource: %O', resource);
|
66
64
|
const attributes = {};
|
package/lib/cjs/model.d.ts
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* ©2024 Commerce Layer Inc.
|
3
|
-
**/
|
4
1
|
export type { Address, AddressCreate, AddressUpdate } from './resources/addresses';
|
5
2
|
export type { Adjustment, AdjustmentCreate, AdjustmentUpdate } from './resources/adjustments';
|
6
3
|
export type { AdyenGateway, AdyenGatewayCreate, AdyenGatewayUpdate } from './resources/adyen_gateways';
|
package/lib/cjs/model.js
CHANGED
package/lib/cjs/query.js
CHANGED
@@ -18,10 +18,8 @@ const generateQueryStringParams = (params, res) => {
|
|
18
18
|
const qp = {};
|
19
19
|
if (!params)
|
20
20
|
return qp;
|
21
|
-
// Include
|
22
21
|
if (params.include)
|
23
22
|
qp.include = params.include.join(',');
|
24
|
-
// Fields
|
25
23
|
if (params.fields) {
|
26
24
|
if (Array.isArray(params.fields))
|
27
25
|
params.fields = { [res.type || res]: params.fields };
|
@@ -30,19 +28,16 @@ const generateQueryStringParams = (params, res) => {
|
|
30
28
|
});
|
31
29
|
}
|
32
30
|
if (isParamsList(params)) {
|
33
|
-
// Sort
|
34
31
|
if (params.sort) {
|
35
32
|
if (Array.isArray(params.sort))
|
36
33
|
qp.sort = params.sort.join(',');
|
37
34
|
else
|
38
35
|
qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === 'desc' ? '-' : ''}${k}`).join(',');
|
39
36
|
}
|
40
|
-
// Page
|
41
37
|
if (params.pageNumber)
|
42
38
|
qp['page[number]'] = String(params.pageNumber);
|
43
39
|
if (params.pageSize)
|
44
40
|
qp['page[size]'] = String(params.pageSize);
|
45
|
-
// Filters
|
46
41
|
if (params.filters) {
|
47
42
|
Object.entries(params.filters).forEach(([p, v]) => {
|
48
43
|
const filter = p.substring(p.lastIndexOf('_'));
|
package/lib/cjs/resource.js
CHANGED
@@ -45,13 +45,10 @@ class ResourceAdapter {
|
|
45
45
|
this.localConfig(config);
|
46
46
|
}
|
47
47
|
localConfig(config) {
|
48
|
-
// if (typeof config.xyz !== 'undefined') this.#config.xyz = config.xyz
|
49
48
|
}
|
50
49
|
config(config) {
|
51
50
|
debug('config %o', config);
|
52
|
-
// ResourceAdapter config
|
53
51
|
this.localConfig(config);
|
54
|
-
// Client config
|
55
52
|
__classPrivateFieldGet(this, _ResourceAdapter_client, "f").config(config);
|
56
53
|
return this;
|
57
54
|
}
|
@@ -141,7 +138,6 @@ class ApiResourceBase {
|
|
141
138
|
constructor(adapter) {
|
142
139
|
debug('new resource instance: %s', this.type());
|
143
140
|
this.resources = adapter;
|
144
|
-
console.log('CONSTRUCTOR ' + this.type());
|
145
141
|
}
|
146
142
|
relationshipOneToOne(id) {
|
147
143
|
return (((id === null) || (typeof id === 'string')) ? { id, type: this.type() } : { id: id.id, type: this.type() });
|
@@ -149,37 +145,6 @@ class ApiResourceBase {
|
|
149
145
|
relationshipOneToMany(...ids) {
|
150
146
|
return (((ids === null) || (ids.length === 0) || (ids[0] === null)) ? [{ id: null, type: this.type() }] : ids.map(id => { return { id, type: this.type() }; }));
|
151
147
|
}
|
152
|
-
/*
|
153
|
-
parse(resource: string, options?: { ignoreSlug?: boolean }): R | R[] {
|
154
|
-
|
155
|
-
try {
|
156
|
-
|
157
|
-
const res = JSON.parse(resource)
|
158
|
-
|
159
|
-
// Resource type always checked
|
160
|
-
const rtype = res.data?.type
|
161
|
-
if (rtype !== this.type()) throw new SdkError({ message: `Invalid resource type [${rtype}]`, type: ErrorType.PARSE })
|
162
|
-
|
163
|
-
// Parse options
|
164
|
-
const { ignoreSlug } = options || {}
|
165
|
-
|
166
|
-
if (!ignoreSlug) {
|
167
|
-
const links = res.data.links.self
|
168
|
-
if (!links || !String(links).match(`^${this.resources.client.baseUrl}/${this.type()}/*`))
|
169
|
-
throw new SdkError({ message: `Resource contains invalid links [${links}]`, type: ErrorType.PARSE })
|
170
|
-
}
|
171
|
-
|
172
|
-
|
173
|
-
return denormalize<R>(res as DocWithData)
|
174
|
-
|
175
|
-
} catch (error: any) {
|
176
|
-
if (SdkError.isSdkError(error)) throw error
|
177
|
-
else throw new SdkError({ message: `Payload parse error [${error.message}]`, type: ErrorType.PARSE })
|
178
|
-
}
|
179
|
-
|
180
|
-
}
|
181
|
-
*/
|
182
|
-
// reference, reference_origin and metadata attributes are always updatable
|
183
148
|
async update(resource, params, options) {
|
184
149
|
return this.resources.update({ ...resource, type: this.type() }, params, options);
|
185
150
|
}
|
package/lib/cjs/static.js
CHANGED
@@ -27,7 +27,6 @@ exports.CommerceLayerStatic = void 0;
|
|
27
27
|
const api = __importStar(require("./api"));
|
28
28
|
const error_1 = require("./error");
|
29
29
|
const commercelayer_1 = __importStar(require("./commercelayer"));
|
30
|
-
/* Static functions */
|
31
30
|
exports.CommerceLayerStatic = {
|
32
31
|
resources: (sort) => {
|
33
32
|
return sort ? [...api.resourceList].sort() : api.resourceList;
|
package/lib/cjs/util.js
CHANGED
package/lib/esm/api.d.ts
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
import type { Resource, ResourceRel } from './resource';
|
2
2
|
import type { TagType } from './resources/tags';
|
3
3
|
import type { VersionType } from './resources/versions';
|
4
|
-
/**
|
5
|
-
* ©2024 Commerce Layer Inc.
|
6
|
-
**/
|
7
4
|
export { default as Addresses } from './resources/addresses';
|
8
5
|
export { default as Adjustments } from './resources/adjustments';
|
9
6
|
export { default as AdyenGateways } from './resources/adyen_gateways';
|
package/lib/esm/api.js
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
// ##__API_RESOURCES_START__##
|
2
|
-
// ##__API_RESOURCES_TEMPLATE:: export { default as ##__RESOURCE_CLASS__## } from './resources/##__RESOURCE_TYPE__##'
|
3
|
-
/**
|
4
|
-
* ©2024 Commerce Layer Inc.
|
5
|
-
**/
|
6
1
|
export { default as Addresses } from './resources/addresses';
|
7
2
|
export { default as Adjustments } from './resources/adjustments';
|
8
3
|
export { default as AdyenGateways } from './resources/adyen_gateways';
|
@@ -124,9 +119,7 @@ export { default as Versions } from './resources/versions';
|
|
124
119
|
export { default as Voids } from './resources/voids';
|
125
120
|
export { default as Webhooks } from './resources/webhooks';
|
126
121
|
export { default as WireTransfers } from './resources/wire_transfers';
|
127
|
-
// ##__API_RESOURCE_TYPES_STOP__##
|
128
122
|
export const resourceList = [
|
129
|
-
// ##__API_RESOURCE_LIST_START__##
|
130
123
|
'addresses',
|
131
124
|
'adjustments',
|
132
125
|
'adyen_gateways',
|
@@ -248,11 +241,8 @@ export const resourceList = [
|
|
248
241
|
'voids',
|
249
242
|
'webhooks',
|
250
243
|
'wire_transfers'
|
251
|
-
// ##__API_RESOURCE_LIST_STOP__##
|
252
244
|
];
|
253
245
|
export const singletonList = [
|
254
|
-
// ##__API_RESOURCE_SINGLETON_START__##
|
255
246
|
'application',
|
256
247
|
'organization'
|
257
|
-
// ##__API_RESOURCE_SINGLETON_STOP__##
|
258
248
|
];
|
package/lib/esm/client.js
CHANGED
@@ -23,26 +23,20 @@ class ApiClient {
|
|
23
23
|
this.#accessToken = options.accessToken;
|
24
24
|
const fetchConfig = {
|
25
25
|
timeout: options.timeout || config.client.timeout,
|
26
|
-
// httpAgent: options.httpAgent,
|
27
|
-
// httpsAgent: options.httpsAgent
|
28
26
|
};
|
29
|
-
// Set custom headers
|
30
27
|
const customHeaders = this.customHeaders(options.headers);
|
31
|
-
// Set headers
|
32
28
|
const headers = {
|
33
29
|
...customHeaders,
|
34
30
|
'Accept': 'application/vnd.api+json',
|
35
31
|
'Content-Type': 'application/vnd.api+json',
|
36
32
|
'Authorization': 'Bearer ' + this.#accessToken
|
37
33
|
};
|
38
|
-
// Set User-Agent
|
39
34
|
const userAgent = options.userAgent;
|
40
35
|
if (userAgent)
|
41
36
|
headers['User-Agent'] = userAgent;
|
42
37
|
fetchConfig.headers = headers;
|
43
38
|
this.#clientConfig = fetchConfig;
|
44
39
|
debug('fetch config: %O', fetchConfig);
|
45
|
-
// Interceptors
|
46
40
|
this.#interceptors = {};
|
47
41
|
}
|
48
42
|
get interceptors() { return this.#interceptors; }
|
@@ -51,24 +45,15 @@ class ApiClient {
|
|
51
45
|
this.#clientConfig.headers = {};
|
52
46
|
return this.#clientConfig.headers;
|
53
47
|
}
|
54
|
-
/*
|
55
|
-
set requestHeaders(headers: RequestHeaders) {
|
56
|
-
this.#clientConfig.headers = { ...this.#clientConfig.headers, ...headers }
|
57
|
-
}
|
58
|
-
*/
|
59
48
|
config(config) {
|
60
49
|
debug('config %o', config);
|
61
50
|
const def = this.#clientConfig;
|
62
51
|
if (!def.headers)
|
63
52
|
def.headers = {};
|
64
|
-
// Client config
|
65
53
|
if (config.timeout)
|
66
54
|
def.timeout = config.timeout;
|
67
|
-
// if (config.httpAgent) def.httpAgent = config.httpAgent
|
68
|
-
// if (config.httpsAgent) def.httpsAgent = config.httpsAgent
|
69
55
|
if (config.userAgent)
|
70
56
|
this.userAgent(config.userAgent);
|
71
|
-
// API Client config
|
72
57
|
if (config.organization)
|
73
58
|
this.#baseUrl = baseURL(config.organization, config.domain);
|
74
59
|
if (config.accessToken) {
|
@@ -86,31 +71,23 @@ class ApiClient {
|
|
86
71
|
}
|
87
72
|
async request(method, path, body, options) {
|
88
73
|
debug('request %s %s, %O, %O', method, path, body || {}, options || {});
|
89
|
-
// Ignored params (in debug mode)
|
90
74
|
if (options?.userAgent)
|
91
75
|
debug('User-Agent header ignored in request config');
|
92
|
-
// URL
|
93
76
|
const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : this.#baseUrl;
|
94
77
|
const url = new URL(`${baseUrl}/${path}`);
|
95
|
-
// Body
|
96
78
|
const bodyData = body ? JSON.stringify({ data: body }) : undefined;
|
97
|
-
// Headers
|
98
79
|
const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
|
99
|
-
// Access token
|
100
80
|
const accessToken = options?.accessToken || this.#accessToken;
|
101
81
|
if (accessToken)
|
102
82
|
headers.Authorization = 'Bearer ' + accessToken;
|
103
83
|
const fetchOptions = { method, body: bodyData, headers };
|
104
|
-
// Timeout
|
105
84
|
const timeout = options?.timeout || this.#clientConfig.timeout;
|
106
85
|
if (timeout)
|
107
86
|
fetchOptions.signal = AbortSignal.timeout(timeout);
|
108
87
|
if (options?.params)
|
109
88
|
Object.entries(options?.params).forEach(([name, value]) => { url.searchParams.append(name, String(value)); });
|
110
|
-
// const start = Date.now()
|
111
89
|
return await fetchURL(url, fetchOptions, this.interceptors)
|
112
90
|
.catch((error) => handleError(error));
|
113
|
-
// .finally(() => { console.log(`<<-- ${method} ${path} ${Date.now() - start}`) })
|
114
91
|
}
|
115
92
|
customHeaders(headers) {
|
116
93
|
const customHeaders = {};
|