doboxa-js 1.0.2 → 1.1.0
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/README.md +134 -72
- package/dist/{chunk-CGJD4ZO5.mjs → chunk-7RN7PBJH.mjs} +11 -1
- package/dist/chunk-7RN7PBJH.mjs.map +1 -0
- package/dist/{chunk-36DDSV5T.mjs → chunk-RTI5YLAB.mjs} +163 -44
- package/dist/chunk-RTI5YLAB.mjs.map +1 -0
- package/dist/client-BrWpdgrN.d.mts +3024 -0
- package/dist/client-BrWpdgrN.d.ts +3024 -0
- package/dist/client.d.mts +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +167 -28
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +2 -2
- package/dist/errors-lG5MwUyw.d.mts +176 -0
- package/dist/errors-lG5MwUyw.d.ts +176 -0
- package/dist/errors.d.mts +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +3 -1
- package/dist/index.d.mts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +172 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -10
- package/dist/index.mjs.map +1 -1
- package/dist/models.d.mts +2 -0
- package/dist/models.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunk-36DDSV5T.mjs.map +0 -1
- package/dist/chunk-CGJD4ZO5.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { D as Doboxa, a as DoboxaConfig } from './client-BrWpdgrN.mjs';
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { D as Doboxa, a as DoboxaConfig } from './client-BrWpdgrN.js';
|
package/dist/client.js
CHANGED
|
@@ -344,6 +344,15 @@ var DoboxaAuthenticationError = class _DoboxaAuthenticationError extends DoboxaE
|
|
|
344
344
|
Object.setPrototypeOf(this, _DoboxaAuthenticationError.prototype);
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
|
+
var DoboxaConnectorError = class _DoboxaConnectorError extends DoboxaError {
|
|
348
|
+
constructor(errorCode, errorText, message) {
|
|
349
|
+
super(message || errorText || `BaseLinker connector error: ${errorCode}`);
|
|
350
|
+
this.name = "DoboxaConnectorError";
|
|
351
|
+
this.errorCode = errorCode;
|
|
352
|
+
this.errorText = errorText;
|
|
353
|
+
Object.setPrototypeOf(this, _DoboxaConnectorError.prototype);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
347
356
|
function parseErrorResponse(statusCode, body) {
|
|
348
357
|
if (typeof body === "object" && body !== null) {
|
|
349
358
|
if ("invalid_parameters" in body || "error_message" in body) {
|
|
@@ -373,26 +382,24 @@ var HTTPClient = class {
|
|
|
373
382
|
if (!accessToken || this.tokenManager.isTokenExpired()) {
|
|
374
383
|
if (this.onTokenRefresh) {
|
|
375
384
|
const refreshToken = this.tokenManager.getRefreshToken();
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
this.tokenManager.setRefreshPromise(null);
|
|
385
|
+
if (refreshToken) {
|
|
386
|
+
let refreshPromise = this.tokenManager.getRefreshPromise();
|
|
387
|
+
if (!refreshPromise) {
|
|
388
|
+
refreshPromise = this.onTokenRefresh(refreshToken);
|
|
389
|
+
this.tokenManager.setRefreshPromise(refreshPromise);
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
accessToken = yield refreshPromise;
|
|
393
|
+
} finally {
|
|
394
|
+
this.tokenManager.setRefreshPromise(null);
|
|
395
|
+
}
|
|
388
396
|
}
|
|
389
|
-
} else {
|
|
390
|
-
throw new DoboxaAuthenticationError("No access token available");
|
|
391
397
|
}
|
|
392
398
|
}
|
|
393
399
|
const headers = new Headers(options.headers);
|
|
394
400
|
headers.set("Content-Type", "application/json");
|
|
395
401
|
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
402
|
+
console.log("url", url);
|
|
396
403
|
const response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
|
|
397
404
|
headers
|
|
398
405
|
}));
|
|
@@ -581,11 +588,6 @@ var AuthenticationResource = class {
|
|
|
581
588
|
}
|
|
582
589
|
};
|
|
583
590
|
|
|
584
|
-
// src/types/generated/src/models/Bool.ts
|
|
585
|
-
function BoolFromJSON(json) {
|
|
586
|
-
return json;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
591
|
// src/types/generated/src/models/Attachment.ts
|
|
590
592
|
function AttachmentToJSON(json) {
|
|
591
593
|
return AttachmentToJSONTyped(json, false);
|
|
@@ -893,7 +895,7 @@ function OrderCancellationResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
893
895
|
return json;
|
|
894
896
|
}
|
|
895
897
|
return {
|
|
896
|
-
"cancelled": json["cancelled"] == null ? void 0 :
|
|
898
|
+
"cancelled": json["cancelled"] == null ? void 0 : json["cancelled"],
|
|
897
899
|
"details": json["details"] == null ? void 0 : json["details"]
|
|
898
900
|
};
|
|
899
901
|
}
|
|
@@ -1993,10 +1995,122 @@ var UsersResource = class {
|
|
|
1993
1995
|
}
|
|
1994
1996
|
};
|
|
1995
1997
|
|
|
1998
|
+
// src/resources/catalog.ts
|
|
1999
|
+
var CatalogResource = class {
|
|
2000
|
+
constructor(config) {
|
|
2001
|
+
this.config = config;
|
|
2002
|
+
}
|
|
2003
|
+
/**
|
|
2004
|
+
* Call a connector action.
|
|
2005
|
+
*
|
|
2006
|
+
* @param action - Connector action, e.g. "ProductsList"
|
|
2007
|
+
* @param params - Additional action parameters
|
|
2008
|
+
* @throws DoboxaConnectorError on HTTP or connector errors
|
|
2009
|
+
*/
|
|
2010
|
+
call(_0) {
|
|
2011
|
+
return __async(this, arguments, function* (action, params = {}) {
|
|
2012
|
+
const response = yield fetch(this.config.url, {
|
|
2013
|
+
method: "POST",
|
|
2014
|
+
headers: {
|
|
2015
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
2016
|
+
},
|
|
2017
|
+
body: new URLSearchParams(__spreadValues({
|
|
2018
|
+
bl_pass: this.config.password,
|
|
2019
|
+
action
|
|
2020
|
+
}, params))
|
|
2021
|
+
});
|
|
2022
|
+
if (!response.ok) {
|
|
2023
|
+
throw new DoboxaConnectorError(
|
|
2024
|
+
`http_${response.status}`,
|
|
2025
|
+
response.statusText || "Unexpected HTTP status",
|
|
2026
|
+
`BaseLinker connector request failed with HTTP ${response.status}`
|
|
2027
|
+
);
|
|
2028
|
+
}
|
|
2029
|
+
let payload;
|
|
2030
|
+
try {
|
|
2031
|
+
payload = yield response.json();
|
|
2032
|
+
} catch (e) {
|
|
2033
|
+
throw new DoboxaConnectorError(
|
|
2034
|
+
"invalid_response",
|
|
2035
|
+
"Connector response is not valid JSON",
|
|
2036
|
+
"BaseLinker connector returned a non-JSON response"
|
|
2037
|
+
);
|
|
2038
|
+
}
|
|
2039
|
+
if (payload !== null && typeof payload === "object" && !Array.isArray(payload) && payload.error === true) {
|
|
2040
|
+
const error = payload;
|
|
2041
|
+
throw new DoboxaConnectorError(error.error_code, error.error_text);
|
|
2042
|
+
}
|
|
2043
|
+
return payload;
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Get the connector platform and version.
|
|
2048
|
+
*/
|
|
2049
|
+
fileVersion() {
|
|
2050
|
+
return __async(this, null, function* () {
|
|
2051
|
+
return this.call("FileVersion");
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
/**
|
|
2055
|
+
* Get the list of actions the connector supports.
|
|
2056
|
+
*/
|
|
2057
|
+
supportedMethods() {
|
|
2058
|
+
return __async(this, null, function* () {
|
|
2059
|
+
return this.call("SupportedMethods");
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Get all product categories as a map of category id to category path.
|
|
2064
|
+
*/
|
|
2065
|
+
categories() {
|
|
2066
|
+
return __async(this, null, function* () {
|
|
2067
|
+
return this.call("ProductsCategories");
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* List one page of products (designs).
|
|
2072
|
+
*
|
|
2073
|
+
* @param params - Page number and optional category filter
|
|
2074
|
+
*/
|
|
2075
|
+
list() {
|
|
2076
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2077
|
+
var _a;
|
|
2078
|
+
const response = yield this.call("ProductsList", __spreadValues({
|
|
2079
|
+
page: String((_a = params.page) != null ? _a : 1)
|
|
2080
|
+
}, params.category_id !== void 0 ? { category_id: params.category_id } : {}));
|
|
2081
|
+
const items = [];
|
|
2082
|
+
for (const id of Object.keys(response)) {
|
|
2083
|
+
if (id === "pages") {
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
const value = response[id];
|
|
2087
|
+
if (typeof value !== "object" || value === null) {
|
|
2088
|
+
continue;
|
|
2089
|
+
}
|
|
2090
|
+
items.push(__spreadValues({ id }, value));
|
|
2091
|
+
}
|
|
2092
|
+
return { pages: response.pages, items };
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Get full product data (images, variants) for the given design ids.
|
|
2097
|
+
*
|
|
2098
|
+
* @param params - Design ids from the product list
|
|
2099
|
+
*/
|
|
2100
|
+
data(params) {
|
|
2101
|
+
return __async(this, null, function* () {
|
|
2102
|
+
const response = yield this.call("ProductsData", {
|
|
2103
|
+
products_id: params.products_id.join(",")
|
|
2104
|
+
});
|
|
2105
|
+
return Array.isArray(response) ? {} : response;
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
|
|
1996
2110
|
// src/client.ts
|
|
1997
2111
|
var Doboxa = class {
|
|
1998
2112
|
constructor(config = {}) {
|
|
1999
|
-
const baseURL = config.baseURL || getBaseURL() || "
|
|
2113
|
+
const baseURL = config.baseURL || getBaseURL() || "https://pl.doboxa.biz";
|
|
2000
2114
|
this.tokenManager = new TokenManager();
|
|
2001
2115
|
if (config.apiKey) {
|
|
2002
2116
|
this.tokenManager.setTokens(config.apiKey, "", 3600);
|
|
@@ -2022,21 +2136,46 @@ var Doboxa = class {
|
|
|
2022
2136
|
baseURL,
|
|
2023
2137
|
tokenManager: this.tokenManager,
|
|
2024
2138
|
onTokenRefresh: (refreshToken) => __async(this, null, function* () {
|
|
2025
|
-
const tempAuth = new AuthenticationResource(
|
|
2139
|
+
const tempAuth = new AuthenticationResource(
|
|
2140
|
+
tempHttpClient,
|
|
2141
|
+
this.tokenManager
|
|
2142
|
+
);
|
|
2026
2143
|
const response = yield tempAuth.refreshToken(refreshToken);
|
|
2027
|
-
this.tokenManager.setTokens(
|
|
2144
|
+
this.tokenManager.setTokens(
|
|
2145
|
+
response.token,
|
|
2146
|
+
response.refresh_token,
|
|
2147
|
+
3600
|
|
2148
|
+
);
|
|
2028
2149
|
return response.token;
|
|
2029
2150
|
})
|
|
2030
2151
|
});
|
|
2031
|
-
this.authentication = new AuthenticationResource(
|
|
2152
|
+
this.authentication = new AuthenticationResource(
|
|
2153
|
+
this.httpClient,
|
|
2154
|
+
this.tokenManager
|
|
2155
|
+
);
|
|
2032
2156
|
this.orders = new OrdersResource(this.httpClient, this.config);
|
|
2033
2157
|
this.invoices = new InvoicesResource(this.httpClient, this.config);
|
|
2034
2158
|
this.clients = new ClientsResource(this.httpClient, this.config);
|
|
2035
|
-
this.discountCodes = new DiscountCodesResource(
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2159
|
+
this.discountCodes = new DiscountCodesResource(
|
|
2160
|
+
this.httpClient,
|
|
2161
|
+
this.config
|
|
2162
|
+
);
|
|
2163
|
+
this.trackingNumbers = new TrackingNumbersResource(
|
|
2164
|
+
this.httpClient,
|
|
2165
|
+
this.config
|
|
2166
|
+
);
|
|
2167
|
+
this.orderComments = new OrderCommentsResource(
|
|
2168
|
+
this.httpClient,
|
|
2169
|
+
this.config
|
|
2170
|
+
);
|
|
2171
|
+
this.orderStatusChanges = new OrderStatusChangesResource(
|
|
2172
|
+
this.httpClient,
|
|
2173
|
+
this.config
|
|
2174
|
+
);
|
|
2039
2175
|
this.users = new UsersResource(this.httpClient, this.config);
|
|
2176
|
+
if (config.catalog) {
|
|
2177
|
+
this.catalog = new CatalogResource(config.catalog);
|
|
2178
|
+
}
|
|
2040
2179
|
}
|
|
2041
2180
|
};
|
|
2042
2181
|
// Annotate the CommonJS export names for ESM import in node:
|