@thorprovider/adapters 4.2.0 → 4.2.1
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/CHANGELOG.md +6 -0
- package/README.md +19 -0
- package/dist/index.d.mts +90 -2
- package/dist/index.d.ts +90 -2
- package/dist/index.js +1066 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1064 -0
- package/dist/index.mjs.map +1 -1
- package/docs/capabilities-system.md +30 -0
- package/docs/providers-overview.md +14 -0
- package/docs/services-overview.md +16 -0
- package/package.json +10 -6
- package/quick-reference.md +1 -0
- package/src/factory/index.ts +4 -0
- package/src/index.ts +3 -0
- package/src/providers/index.ts +3 -0
- package/src/providers/stelorder/client.test-helpers.ts +3 -0
- package/src/providers/stelorder/client.test.ts +58 -0
- package/src/providers/stelorder/client.ts +326 -0
- package/src/providers/stelorder/index.test.ts +48 -0
- package/src/providers/stelorder/index.ts +685 -0
- package/src/providers/stelorder/live-smoke.test.ts +54 -0
- package/src/providers/stelorder/transforms.test.ts +103 -0
- package/src/providers/stelorder/transforms.ts +631 -0
- package/src/types/capabilities.types.ts +51 -0
- package/vitest.config.ts +13 -0
- package/vitest.setup.ts +6 -0
- package/.turbo/turbo-build.log +0 -18
- package/dist/.tsbuildinfo +0 -1
package/dist/index.js
CHANGED
|
@@ -55,8 +55,10 @@ __export(src_exports, {
|
|
|
55
55
|
ResourceNotFoundError: () => ResourceNotFoundError,
|
|
56
56
|
SHOPIFY_CAPABILITIES: () => SHOPIFY_CAPABILITIES,
|
|
57
57
|
SPREE_CAPABILITIES: () => SPREE_CAPABILITIES,
|
|
58
|
+
STELORDER_CAPABILITIES: () => STELORDER_CAPABILITIES,
|
|
58
59
|
ShopifyProvider: () => ShopifyProvider,
|
|
59
60
|
SpreeProvider: () => SpreeProvider,
|
|
61
|
+
StelOrderProvider: () => StelOrderProvider,
|
|
60
62
|
StorefrontConfigError: () => import_types2.StorefrontConfigError,
|
|
61
63
|
WOOCOMMERCE_CAPABILITIES: () => WOOCOMMERCE_CAPABILITIES,
|
|
62
64
|
WooCommerceProvider: () => WooCommerceProvider,
|
|
@@ -163,6 +165,41 @@ var MEDUSA_CAPABILITIES = {
|
|
|
163
165
|
loyaltyProgram: false
|
|
164
166
|
// Requires custom implementation
|
|
165
167
|
};
|
|
168
|
+
var STELORDER_CAPABILITIES = {
|
|
169
|
+
// Profile Management
|
|
170
|
+
updateProfile: false,
|
|
171
|
+
updateEmail: false,
|
|
172
|
+
changePasswordDirect: false,
|
|
173
|
+
changePasswordViaEmail: false,
|
|
174
|
+
deleteAccount: false,
|
|
175
|
+
// Avatar
|
|
176
|
+
uploadAvatar: false,
|
|
177
|
+
avatarViaMetadata: false,
|
|
178
|
+
// Custom Attributes
|
|
179
|
+
customAttributes: false,
|
|
180
|
+
// Orders
|
|
181
|
+
fetchOrders: true,
|
|
182
|
+
cancelOrder: false,
|
|
183
|
+
// Addresses
|
|
184
|
+
manageAddresses: true,
|
|
185
|
+
defaultAddress: false,
|
|
186
|
+
// Cart/Checkout
|
|
187
|
+
applyDiscounts: false,
|
|
188
|
+
shippingCalculation: false,
|
|
189
|
+
guestCheckout: false,
|
|
190
|
+
savedPaymentMethods: false,
|
|
191
|
+
listPaymentProviders: true,
|
|
192
|
+
regionSpecificPayments: false,
|
|
193
|
+
// Wishlist
|
|
194
|
+
wishlist: false,
|
|
195
|
+
// Search
|
|
196
|
+
advancedSearch: false,
|
|
197
|
+
facetedFilters: false,
|
|
198
|
+
// Reviews
|
|
199
|
+
productReviews: false,
|
|
200
|
+
// Loyalty
|
|
201
|
+
loyaltyProgram: false
|
|
202
|
+
};
|
|
166
203
|
var SHOPIFY_CAPABILITIES = {
|
|
167
204
|
// Profile Management
|
|
168
205
|
updateProfile: true,
|
|
@@ -8069,6 +8106,1031 @@ var MagentoProvider = class {
|
|
|
8069
8106
|
}
|
|
8070
8107
|
};
|
|
8071
8108
|
|
|
8109
|
+
// src/providers/stelorder/transforms.ts
|
|
8110
|
+
function normalizeStelCollection(payload) {
|
|
8111
|
+
if (!payload) {
|
|
8112
|
+
return [];
|
|
8113
|
+
}
|
|
8114
|
+
return Array.isArray(payload) ? payload : [payload];
|
|
8115
|
+
}
|
|
8116
|
+
function normalizeStelEntity(payload) {
|
|
8117
|
+
if (!payload) {
|
|
8118
|
+
return void 0;
|
|
8119
|
+
}
|
|
8120
|
+
return Array.isArray(payload) ? payload[0] : payload;
|
|
8121
|
+
}
|
|
8122
|
+
function transformStelMoney(amount, currencyCode = "USD") {
|
|
8123
|
+
const normalizedAmount = typeof amount === "string" ? Number.parseFloat(amount) : amount ?? 0;
|
|
8124
|
+
return {
|
|
8125
|
+
amount: Number.isFinite(normalizedAmount) ? normalizedAmount.toFixed(2) : "0.00",
|
|
8126
|
+
currencyCode: currencyCode.toUpperCase()
|
|
8127
|
+
};
|
|
8128
|
+
}
|
|
8129
|
+
function transformStelImage(url, altText = "") {
|
|
8130
|
+
const normalizedUrl = url?.trim();
|
|
8131
|
+
if (!normalizedUrl) {
|
|
8132
|
+
return void 0;
|
|
8133
|
+
}
|
|
8134
|
+
return {
|
|
8135
|
+
url: normalizedUrl,
|
|
8136
|
+
altText,
|
|
8137
|
+
width: 800,
|
|
8138
|
+
height: 800
|
|
8139
|
+
};
|
|
8140
|
+
}
|
|
8141
|
+
function normalizeStelDate(value) {
|
|
8142
|
+
if (!value) {
|
|
8143
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
8144
|
+
}
|
|
8145
|
+
const parsed = new Date(value);
|
|
8146
|
+
return Number.isNaN(parsed.getTime()) ? (/* @__PURE__ */ new Date()).toISOString() : parsed.toISOString();
|
|
8147
|
+
}
|
|
8148
|
+
function toStelStringId(value) {
|
|
8149
|
+
if (value === null || value === void 0) {
|
|
8150
|
+
return "";
|
|
8151
|
+
}
|
|
8152
|
+
return String(value);
|
|
8153
|
+
}
|
|
8154
|
+
function slugify(value) {
|
|
8155
|
+
return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
8156
|
+
}
|
|
8157
|
+
function buildStelHandle(...candidates) {
|
|
8158
|
+
for (const candidate of candidates) {
|
|
8159
|
+
if (candidate === null || candidate === void 0) {
|
|
8160
|
+
continue;
|
|
8161
|
+
}
|
|
8162
|
+
const normalized = slugify(String(candidate).trim());
|
|
8163
|
+
if (normalized) {
|
|
8164
|
+
return normalized;
|
|
8165
|
+
}
|
|
8166
|
+
}
|
|
8167
|
+
return "stel-item";
|
|
8168
|
+
}
|
|
8169
|
+
function transformStelProductImages(product) {
|
|
8170
|
+
const images = [];
|
|
8171
|
+
if (!product["item-images"]) {
|
|
8172
|
+
return images;
|
|
8173
|
+
}
|
|
8174
|
+
const sorted = [...product["item-images"]].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
8175
|
+
for (const img of sorted) {
|
|
8176
|
+
const transformed = transformStelImage(img["item-image-path"], product.name ?? "");
|
|
8177
|
+
if (transformed) {
|
|
8178
|
+
images.push(transformed);
|
|
8179
|
+
}
|
|
8180
|
+
}
|
|
8181
|
+
return images;
|
|
8182
|
+
}
|
|
8183
|
+
function deriveStelStockStatus(product) {
|
|
8184
|
+
if (!product["stock-enabled"]) {
|
|
8185
|
+
return "in_stock";
|
|
8186
|
+
}
|
|
8187
|
+
const realStock = product["real-stock"] ?? 0;
|
|
8188
|
+
const minimumStock = product["minimum-stock"] ?? 0;
|
|
8189
|
+
if (realStock <= 0) {
|
|
8190
|
+
return "out_of_stock";
|
|
8191
|
+
}
|
|
8192
|
+
if (realStock <= minimumStock) {
|
|
8193
|
+
return "low_stock";
|
|
8194
|
+
}
|
|
8195
|
+
return "in_stock";
|
|
8196
|
+
}
|
|
8197
|
+
function buildSyntheticVariant(product, currencyCode) {
|
|
8198
|
+
const price = transformStelMoney(product["sales-price"], currencyCode);
|
|
8199
|
+
const stockStatus = deriveStelStockStatus(product);
|
|
8200
|
+
const quantityAvailable = product["stock-enabled"] ? product["real-stock"] ?? 0 : void 0;
|
|
8201
|
+
const image = product["item-images"]?.[0] ? transformStelImage(product["item-images"][0]["item-image-path"], product.name ?? "") : void 0;
|
|
8202
|
+
return {
|
|
8203
|
+
id: toStelStringId(product.id),
|
|
8204
|
+
title: "Default",
|
|
8205
|
+
sku: product.barcode ?? product["full-reference"] ?? void 0,
|
|
8206
|
+
availableForSale: stockStatus !== "out_of_stock",
|
|
8207
|
+
selectedOptions: [],
|
|
8208
|
+
price,
|
|
8209
|
+
compareAtPrice: void 0,
|
|
8210
|
+
quantityAvailable,
|
|
8211
|
+
stockStatus,
|
|
8212
|
+
image
|
|
8213
|
+
};
|
|
8214
|
+
}
|
|
8215
|
+
function transformStelProduct(raw, currencyCode) {
|
|
8216
|
+
const id = toStelStringId(raw.id);
|
|
8217
|
+
const handle = buildStelHandle(raw["full-reference"], raw.reference, raw.name, raw.id);
|
|
8218
|
+
const price = transformStelMoney(raw["sales-price"], currencyCode);
|
|
8219
|
+
const images = transformStelProductImages(raw);
|
|
8220
|
+
const variant = buildSyntheticVariant(raw, currencyCode);
|
|
8221
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
8222
|
+
return {
|
|
8223
|
+
id,
|
|
8224
|
+
handle,
|
|
8225
|
+
title: raw.name ?? "",
|
|
8226
|
+
description: raw.description ?? "",
|
|
8227
|
+
availableForSale: variant.availableForSale,
|
|
8228
|
+
options: [],
|
|
8229
|
+
variants: [variant],
|
|
8230
|
+
featuredImage: images[0],
|
|
8231
|
+
images,
|
|
8232
|
+
priceRange: {
|
|
8233
|
+
minVariantPrice: price,
|
|
8234
|
+
maxVariantPrice: price
|
|
8235
|
+
},
|
|
8236
|
+
productType: void 0,
|
|
8237
|
+
vendor: void 0,
|
|
8238
|
+
tags: raw.promotional ? ["promotional"] : [],
|
|
8239
|
+
createdAt: normalizeStelDate(raw["creation-date"]),
|
|
8240
|
+
updatedAt: normalizeStelDate(raw["utc-last-modification-date"]) || now,
|
|
8241
|
+
metadata: {
|
|
8242
|
+
stelFullReference: raw["full-reference"],
|
|
8243
|
+
stelReference: raw.reference,
|
|
8244
|
+
stelBarcode: raw.barcode,
|
|
8245
|
+
stelCategoryId: raw["product-category-id"],
|
|
8246
|
+
stelInactive: raw.inactive,
|
|
8247
|
+
stelPromotional: raw.promotional,
|
|
8248
|
+
stelPurchasePrice: raw["purchase-price"]
|
|
8249
|
+
}
|
|
8250
|
+
};
|
|
8251
|
+
}
|
|
8252
|
+
function transformStelCategory(raw) {
|
|
8253
|
+
const id = toStelStringId(raw.id);
|
|
8254
|
+
const handle = buildStelHandle(raw.slug, raw.name, raw.id);
|
|
8255
|
+
return {
|
|
8256
|
+
id,
|
|
8257
|
+
name: raw.name ?? "",
|
|
8258
|
+
handle,
|
|
8259
|
+
description: raw.description ?? void 0,
|
|
8260
|
+
parentCategoryId: raw["parent-category-id"] ? toStelStringId(raw["parent-category-id"]) : void 0,
|
|
8261
|
+
metadata: {
|
|
8262
|
+
stelSlug: raw.slug
|
|
8263
|
+
}
|
|
8264
|
+
};
|
|
8265
|
+
}
|
|
8266
|
+
function transformStelCategoryToCollection(raw) {
|
|
8267
|
+
const id = toStelStringId(raw.id);
|
|
8268
|
+
const handle = buildStelHandle(raw.slug, raw.name, raw.id);
|
|
8269
|
+
return {
|
|
8270
|
+
id,
|
|
8271
|
+
handle,
|
|
8272
|
+
title: raw.name ?? "",
|
|
8273
|
+
description: raw.description ?? "",
|
|
8274
|
+
path: `/collections/${handle}`,
|
|
8275
|
+
updatedAt: normalizeStelDate(raw["utc-last-modification-date"])
|
|
8276
|
+
};
|
|
8277
|
+
}
|
|
8278
|
+
function transformStelWarehouseToStockLocation(raw) {
|
|
8279
|
+
return {
|
|
8280
|
+
id: toStelStringId(raw.id),
|
|
8281
|
+
name: raw.name ?? "Warehouse"
|
|
8282
|
+
};
|
|
8283
|
+
}
|
|
8284
|
+
function transformStelProductWarehouseToInventoryLevel(pw) {
|
|
8285
|
+
return {
|
|
8286
|
+
locationId: toStelStringId(pw["warehouse-id"]),
|
|
8287
|
+
locationName: pw["warehouse-path"] ?? `Warehouse ${pw["warehouse-id"] ?? "unknown"}`,
|
|
8288
|
+
availableQuantity: pw["real-stock"] ?? 0,
|
|
8289
|
+
reservedQuantity: Math.max(0, (pw["virtual-stock"] ?? 0) - (pw["real-stock"] ?? 0)),
|
|
8290
|
+
stockedQuantity: pw["virtual-stock"] ?? pw["real-stock"] ?? 0
|
|
8291
|
+
};
|
|
8292
|
+
}
|
|
8293
|
+
function splitStelName(fullName) {
|
|
8294
|
+
if (!fullName?.trim()) {
|
|
8295
|
+
return { firstName: "", lastName: "" };
|
|
8296
|
+
}
|
|
8297
|
+
const parts = fullName.trim().split(/\s+/);
|
|
8298
|
+
const firstName = parts[0] ?? "";
|
|
8299
|
+
const lastName = parts.length > 1 ? parts.slice(1).join(" ") : "";
|
|
8300
|
+
return { firstName, lastName };
|
|
8301
|
+
}
|
|
8302
|
+
function transformStelClient(raw) {
|
|
8303
|
+
const { firstName, lastName } = splitStelName(raw.name ?? raw["business-name"]);
|
|
8304
|
+
return {
|
|
8305
|
+
id: toStelStringId(raw.id),
|
|
8306
|
+
email: raw.email ?? "",
|
|
8307
|
+
firstName: firstName || null,
|
|
8308
|
+
lastName: lastName || null,
|
|
8309
|
+
phone: raw.phone ?? raw.mobile ?? null,
|
|
8310
|
+
hasAccount: true,
|
|
8311
|
+
createdAt: normalizeStelDate(raw["utc-last-modification-date"]),
|
|
8312
|
+
updatedAt: normalizeStelDate(raw["utc-last-modification-date"]),
|
|
8313
|
+
metadata: {
|
|
8314
|
+
stelBusinessName: raw["business-name"],
|
|
8315
|
+
stelRateId: raw["rate-id"],
|
|
8316
|
+
stelPaymentOptionId: raw["payment-option-id"],
|
|
8317
|
+
stelPaymentTermId: raw["payment-term-id"],
|
|
8318
|
+
stelDeliveryOptionId: raw["delivery-option-id"]
|
|
8319
|
+
}
|
|
8320
|
+
};
|
|
8321
|
+
}
|
|
8322
|
+
function deriveStelOrderStatus(raw) {
|
|
8323
|
+
if (raw.deleted) {
|
|
8324
|
+
return "cancelled";
|
|
8325
|
+
}
|
|
8326
|
+
const status = (raw.status ?? "").toLowerCase();
|
|
8327
|
+
if (status.includes("cancel") || status.includes("anulad")) {
|
|
8328
|
+
return "cancelled";
|
|
8329
|
+
}
|
|
8330
|
+
if (status.includes("complet") || status.includes("cerrad") || status.includes("settled")) {
|
|
8331
|
+
return "completed";
|
|
8332
|
+
}
|
|
8333
|
+
if (status.includes("process") || status.includes("confirm")) {
|
|
8334
|
+
return "processing";
|
|
8335
|
+
}
|
|
8336
|
+
return "pending";
|
|
8337
|
+
}
|
|
8338
|
+
function deriveStelPaymentStatus(raw) {
|
|
8339
|
+
const orderStatus = deriveStelOrderStatus(raw);
|
|
8340
|
+
if (orderStatus === "completed") {
|
|
8341
|
+
return "paid";
|
|
8342
|
+
}
|
|
8343
|
+
if (orderStatus === "cancelled") {
|
|
8344
|
+
return "pending";
|
|
8345
|
+
}
|
|
8346
|
+
return "pending";
|
|
8347
|
+
}
|
|
8348
|
+
function deriveStelFulfillmentStatus(raw) {
|
|
8349
|
+
const orderStatus = deriveStelOrderStatus(raw);
|
|
8350
|
+
if (orderStatus === "completed") {
|
|
8351
|
+
return "fulfilled";
|
|
8352
|
+
}
|
|
8353
|
+
return "unfulfilled";
|
|
8354
|
+
}
|
|
8355
|
+
function transformStelDocumentLine(line, index, currencyCode) {
|
|
8356
|
+
const unitPrice = line["item-base-price"] ?? 0;
|
|
8357
|
+
const quantity = line.units ?? 1;
|
|
8358
|
+
const lineTotal = unitPrice * quantity;
|
|
8359
|
+
return {
|
|
8360
|
+
id: toStelStringId(line["item-id"] ?? index),
|
|
8361
|
+
title: line["item-name"] ?? "",
|
|
8362
|
+
variantTitle: void 0,
|
|
8363
|
+
quantity,
|
|
8364
|
+
price: transformStelMoney(unitPrice, currencyCode),
|
|
8365
|
+
total: transformStelMoney(lineTotal, currencyCode),
|
|
8366
|
+
sku: void 0,
|
|
8367
|
+
productId: line["item-id"] ? toStelStringId(line["item-id"]) : void 0
|
|
8368
|
+
};
|
|
8369
|
+
}
|
|
8370
|
+
function transformStelSalesOrder(raw, currencyCode) {
|
|
8371
|
+
const id = toStelStringId(raw.id);
|
|
8372
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
8373
|
+
const items = (raw["document-lines"] ?? []).filter((line) => line["line-type"] === "ITEM" || !line["line-type"]).map((line, i) => transformStelDocumentLine(line, i, currencyCode));
|
|
8374
|
+
const status = deriveStelOrderStatus(raw);
|
|
8375
|
+
return {
|
|
8376
|
+
id,
|
|
8377
|
+
orderNumber: raw.reference ?? id,
|
|
8378
|
+
email: raw.email ?? "",
|
|
8379
|
+
status,
|
|
8380
|
+
paymentStatus: deriveStelPaymentStatus(raw),
|
|
8381
|
+
fulfillmentStatus: deriveStelFulfillmentStatus(raw),
|
|
8382
|
+
customerId: raw["client-id"] ? toStelStringId(raw["client-id"]) : void 0,
|
|
8383
|
+
items,
|
|
8384
|
+
subtotal: transformStelMoney(raw["total-base"], currencyCode),
|
|
8385
|
+
total: transformStelMoney(raw.total, currencyCode),
|
|
8386
|
+
tax: raw["total-tax"] != null ? transformStelMoney(raw["total-tax"], currencyCode) : void 0,
|
|
8387
|
+
createdAt: normalizeStelDate(raw["creation-date"]),
|
|
8388
|
+
updatedAt: normalizeStelDate(raw["utc-last-modification-date"]) || now,
|
|
8389
|
+
cancelledAt: status === "cancelled" ? normalizeStelDate(raw["utc-last-modification-date"]) : void 0,
|
|
8390
|
+
completedAt: status === "completed" ? normalizeStelDate(raw["utc-last-modification-date"]) : void 0,
|
|
8391
|
+
metadata: {
|
|
8392
|
+
stelReference: raw.reference,
|
|
8393
|
+
stelStatus: raw.status,
|
|
8394
|
+
stelPaymentOptionId: raw["payment-option-id"],
|
|
8395
|
+
stelPaymentTermId: raw["payment-term-id"],
|
|
8396
|
+
stelDeliveryOptionId: raw["delivery-option-id"]
|
|
8397
|
+
}
|
|
8398
|
+
};
|
|
8399
|
+
}
|
|
8400
|
+
function inferPaymentMethodType(name) {
|
|
8401
|
+
if (!name) {
|
|
8402
|
+
return "other";
|
|
8403
|
+
}
|
|
8404
|
+
const lower = name.toLowerCase();
|
|
8405
|
+
if (lower.includes("transfer") || lower.includes("bank") || lower.includes("sepa") || lower.includes("iban")) {
|
|
8406
|
+
return "bank_transfer";
|
|
8407
|
+
}
|
|
8408
|
+
if (lower.includes("card") || lower.includes("tarjeta") || lower.includes("visa") || lower.includes("master")) {
|
|
8409
|
+
return "card";
|
|
8410
|
+
}
|
|
8411
|
+
if (lower.includes("paypal") || lower.includes("wallet") || lower.includes("apple") || lower.includes("google")) {
|
|
8412
|
+
return "wallet";
|
|
8413
|
+
}
|
|
8414
|
+
if (lower.includes("cash") || lower.includes("contrar") || lower.includes("efectivo") || lower.includes("cod")) {
|
|
8415
|
+
return "cash_on_delivery";
|
|
8416
|
+
}
|
|
8417
|
+
if (lower.includes("crypto") || lower.includes("bitcoin")) {
|
|
8418
|
+
return "crypto";
|
|
8419
|
+
}
|
|
8420
|
+
return "other";
|
|
8421
|
+
}
|
|
8422
|
+
function transformStelPaymentOption(raw) {
|
|
8423
|
+
return {
|
|
8424
|
+
id: toStelStringId(raw.id),
|
|
8425
|
+
name: raw.name ?? "Payment Option",
|
|
8426
|
+
type: inferPaymentMethodType(raw.name),
|
|
8427
|
+
isEnabled: !raw.deleted,
|
|
8428
|
+
requiresSetup: false,
|
|
8429
|
+
description: raw.description ?? void 0,
|
|
8430
|
+
metadata: {
|
|
8431
|
+
stelPath: raw.path,
|
|
8432
|
+
source: "paymentOption"
|
|
8433
|
+
}
|
|
8434
|
+
};
|
|
8435
|
+
}
|
|
8436
|
+
function transformStelDeliveryOption(raw, currencyCode) {
|
|
8437
|
+
return {
|
|
8438
|
+
id: toStelStringId(raw.id),
|
|
8439
|
+
name: raw.name ?? "Delivery Option",
|
|
8440
|
+
price: transformStelMoney(0, currencyCode),
|
|
8441
|
+
description: raw.description ?? void 0
|
|
8442
|
+
};
|
|
8443
|
+
}
|
|
8444
|
+
|
|
8445
|
+
// src/providers/stelorder/client.ts
|
|
8446
|
+
var DEFAULT_RETRY_CONFIG2 = {
|
|
8447
|
+
maxRetries: 2,
|
|
8448
|
+
initialDelayMs: 300,
|
|
8449
|
+
backoffMultiplier: 2,
|
|
8450
|
+
maxDelayMs: 5e3,
|
|
8451
|
+
timeoutMs: 1e4,
|
|
8452
|
+
retryableStatusCodes: [408, 429, 500, 502, 503, 504]
|
|
8453
|
+
};
|
|
8454
|
+
function sleep2(ms) {
|
|
8455
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8456
|
+
}
|
|
8457
|
+
function calculateDelay2(attempt, retryConfig) {
|
|
8458
|
+
const delay = retryConfig.initialDelayMs * Math.pow(retryConfig.backoffMultiplier, attempt);
|
|
8459
|
+
return Math.min(delay, retryConfig.maxDelayMs);
|
|
8460
|
+
}
|
|
8461
|
+
function isRetryableError2(error, retryConfig) {
|
|
8462
|
+
if (error instanceof ProviderAPIError) {
|
|
8463
|
+
return typeof error.status === "number" && retryConfig.retryableStatusCodes.includes(error.status);
|
|
8464
|
+
}
|
|
8465
|
+
if (!(error instanceof Error)) {
|
|
8466
|
+
return false;
|
|
8467
|
+
}
|
|
8468
|
+
const message = error.message.toLowerCase();
|
|
8469
|
+
return error.name === "AbortError" || error.name === "TimeoutError" || message.includes("fetch failed") || message.includes("timeout") || message.includes("econnrefused") || message.includes("etimedout");
|
|
8470
|
+
}
|
|
8471
|
+
function createRetryingFetch(fetchImplementation, retryConfig, logger2) {
|
|
8472
|
+
return async (url, init) => {
|
|
8473
|
+
let lastError = new Error("Unknown STEL Order request error");
|
|
8474
|
+
for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt += 1) {
|
|
8475
|
+
const controller = new AbortController();
|
|
8476
|
+
const timeoutId = setTimeout(() => controller.abort(), retryConfig.timeoutMs);
|
|
8477
|
+
try {
|
|
8478
|
+
const response = await fetchImplementation(url, {
|
|
8479
|
+
...init,
|
|
8480
|
+
signal: controller.signal
|
|
8481
|
+
});
|
|
8482
|
+
clearTimeout(timeoutId);
|
|
8483
|
+
if (!response.ok && retryConfig.retryableStatusCodes.includes(response.status)) {
|
|
8484
|
+
throw new ProviderAPIError(
|
|
8485
|
+
`STEL Order API error: ${response.status} ${response.statusText}`,
|
|
8486
|
+
"stelorder",
|
|
8487
|
+
response.status
|
|
8488
|
+
);
|
|
8489
|
+
}
|
|
8490
|
+
return response;
|
|
8491
|
+
} catch (error) {
|
|
8492
|
+
clearTimeout(timeoutId);
|
|
8493
|
+
lastError = error;
|
|
8494
|
+
if (attempt >= retryConfig.maxRetries || !isRetryableError2(error, retryConfig)) {
|
|
8495
|
+
throw error;
|
|
8496
|
+
}
|
|
8497
|
+
const delay = calculateDelay2(attempt, retryConfig);
|
|
8498
|
+
logger2.warn("STEL request failed, retrying.", {
|
|
8499
|
+
url,
|
|
8500
|
+
attempt: attempt + 1,
|
|
8501
|
+
maxAttempts: retryConfig.maxRetries + 1,
|
|
8502
|
+
nextRetryIn: delay,
|
|
8503
|
+
error: extractErrorMessage(error)
|
|
8504
|
+
});
|
|
8505
|
+
await sleep2(delay);
|
|
8506
|
+
}
|
|
8507
|
+
}
|
|
8508
|
+
throw lastError;
|
|
8509
|
+
};
|
|
8510
|
+
}
|
|
8511
|
+
async function parseErrorResponse(response) {
|
|
8512
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
8513
|
+
try {
|
|
8514
|
+
if (contentType.includes("application/json")) {
|
|
8515
|
+
const body = await response.json();
|
|
8516
|
+
const message = extractErrorMessage(body);
|
|
8517
|
+
if (message && message !== "An unknown error occurred") {
|
|
8518
|
+
return message;
|
|
8519
|
+
}
|
|
8520
|
+
}
|
|
8521
|
+
} catch {
|
|
8522
|
+
}
|
|
8523
|
+
try {
|
|
8524
|
+
const text = await response.text();
|
|
8525
|
+
if (text.trim()) {
|
|
8526
|
+
return text.trim();
|
|
8527
|
+
}
|
|
8528
|
+
} catch {
|
|
8529
|
+
}
|
|
8530
|
+
return `STEL Order API error: ${response.status} ${response.statusText}`;
|
|
8531
|
+
}
|
|
8532
|
+
function normalizeStelApiBaseUrl(baseUrl) {
|
|
8533
|
+
const trimmed = baseUrl.trim();
|
|
8534
|
+
if (!trimmed) {
|
|
8535
|
+
throw new ConfigurationError("Stel Order baseUrl is required.");
|
|
8536
|
+
}
|
|
8537
|
+
const normalized = trimmed.replace(/\/api\/openapi\.json$/i, "").replace(/\/+$/, "");
|
|
8538
|
+
return normalized.endsWith("/app") ? normalized : `${normalized}/app`;
|
|
8539
|
+
}
|
|
8540
|
+
var StelOrderClient = class {
|
|
8541
|
+
apiBaseUrl;
|
|
8542
|
+
apiKey;
|
|
8543
|
+
logger;
|
|
8544
|
+
retryConfig;
|
|
8545
|
+
fetchImplementation;
|
|
8546
|
+
constructor(config) {
|
|
8547
|
+
const apiKey = config.apiKey ?? config.publishableKey;
|
|
8548
|
+
if (!apiKey) {
|
|
8549
|
+
throw new ConfigurationError(
|
|
8550
|
+
"Stel Order API key is required. Pass `apiKey` or `publishableKey` to createProvider()."
|
|
8551
|
+
);
|
|
8552
|
+
}
|
|
8553
|
+
this.apiBaseUrl = normalizeStelApiBaseUrl(config.baseUrl);
|
|
8554
|
+
this.apiKey = apiKey;
|
|
8555
|
+
this.logger = createLogger("StelOrderClient", config.debug);
|
|
8556
|
+
this.retryConfig = {
|
|
8557
|
+
...DEFAULT_RETRY_CONFIG2,
|
|
8558
|
+
...config.retry
|
|
8559
|
+
};
|
|
8560
|
+
this.fetchImplementation = config.customFetch ? createRetryingFetch(config.customFetch, this.retryConfig, this.logger) : void 0;
|
|
8561
|
+
this.logger.info("Initializing Stel Order client", {
|
|
8562
|
+
apiBaseUrl: this.apiBaseUrl,
|
|
8563
|
+
retryConfig: this.retryConfig
|
|
8564
|
+
});
|
|
8565
|
+
}
|
|
8566
|
+
async list(resource, query) {
|
|
8567
|
+
const payload = await this.request({
|
|
8568
|
+
method: "GET",
|
|
8569
|
+
path: resource,
|
|
8570
|
+
query
|
|
8571
|
+
});
|
|
8572
|
+
return normalizeStelCollection(payload);
|
|
8573
|
+
}
|
|
8574
|
+
async getOne(resource, id, query) {
|
|
8575
|
+
const payload = await this.request({
|
|
8576
|
+
method: "GET",
|
|
8577
|
+
path: `${resource}/${id}`,
|
|
8578
|
+
query
|
|
8579
|
+
});
|
|
8580
|
+
return normalizeStelEntity(payload);
|
|
8581
|
+
}
|
|
8582
|
+
async create(resource, body) {
|
|
8583
|
+
return this.request({
|
|
8584
|
+
method: "POST",
|
|
8585
|
+
path: resource,
|
|
8586
|
+
body
|
|
8587
|
+
});
|
|
8588
|
+
}
|
|
8589
|
+
async update(resource, id, body) {
|
|
8590
|
+
return this.request({
|
|
8591
|
+
method: "PUT",
|
|
8592
|
+
path: `${resource}/${id}`,
|
|
8593
|
+
body
|
|
8594
|
+
});
|
|
8595
|
+
}
|
|
8596
|
+
async remove(resource, id) {
|
|
8597
|
+
await this.request({
|
|
8598
|
+
method: "DELETE",
|
|
8599
|
+
path: `${resource}/${id}`
|
|
8600
|
+
});
|
|
8601
|
+
}
|
|
8602
|
+
buildUrl(path, query) {
|
|
8603
|
+
const normalizedPath = path.replace(/^\/+/, "");
|
|
8604
|
+
const url = new URL(`${this.apiBaseUrl}/${normalizedPath}`);
|
|
8605
|
+
if (!query) {
|
|
8606
|
+
return url.toString();
|
|
8607
|
+
}
|
|
8608
|
+
for (const [key, value] of Object.entries(query)) {
|
|
8609
|
+
if (value === void 0 || value === null || value === "") {
|
|
8610
|
+
continue;
|
|
8611
|
+
}
|
|
8612
|
+
if (Array.isArray(value)) {
|
|
8613
|
+
url.searchParams.set(key, value.map(String).join(","));
|
|
8614
|
+
continue;
|
|
8615
|
+
}
|
|
8616
|
+
url.searchParams.set(key, String(value));
|
|
8617
|
+
}
|
|
8618
|
+
return url.toString();
|
|
8619
|
+
}
|
|
8620
|
+
buildHeaders(headers, hasBody = false) {
|
|
8621
|
+
const normalizedHeaders = new Headers(headers);
|
|
8622
|
+
normalizedHeaders.set("Accept", "application/json");
|
|
8623
|
+
normalizedHeaders.set("APIKEY", this.apiKey);
|
|
8624
|
+
if (hasBody && !normalizedHeaders.has("Content-Type")) {
|
|
8625
|
+
normalizedHeaders.set("Content-Type", "application/json");
|
|
8626
|
+
}
|
|
8627
|
+
return normalizedHeaders;
|
|
8628
|
+
}
|
|
8629
|
+
async executeFetch(url, init) {
|
|
8630
|
+
if (this.fetchImplementation) {
|
|
8631
|
+
return this.fetchImplementation(url, init);
|
|
8632
|
+
}
|
|
8633
|
+
return fetchWithRetry(url, init, this.retryConfig);
|
|
8634
|
+
}
|
|
8635
|
+
async request(options) {
|
|
8636
|
+
const url = this.buildUrl(options.path, options.query);
|
|
8637
|
+
const hasBody = options.body !== void 0;
|
|
8638
|
+
this.logger.debug("STEL request", {
|
|
8639
|
+
method: options.method,
|
|
8640
|
+
url
|
|
8641
|
+
});
|
|
8642
|
+
const response = await this.executeFetch(url, {
|
|
8643
|
+
method: options.method,
|
|
8644
|
+
headers: this.buildHeaders(options.headers, hasBody),
|
|
8645
|
+
body: hasBody ? JSON.stringify(options.body) : void 0
|
|
8646
|
+
});
|
|
8647
|
+
if (!response.ok) {
|
|
8648
|
+
const message = await parseErrorResponse(response);
|
|
8649
|
+
throw new ProviderAPIError(message, "stelorder", response.status);
|
|
8650
|
+
}
|
|
8651
|
+
if (response.status === 204) {
|
|
8652
|
+
return void 0;
|
|
8653
|
+
}
|
|
8654
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
8655
|
+
if (contentType.includes("application/json")) {
|
|
8656
|
+
return await response.json();
|
|
8657
|
+
}
|
|
8658
|
+
return await response.text();
|
|
8659
|
+
}
|
|
8660
|
+
};
|
|
8661
|
+
|
|
8662
|
+
// src/providers/stelorder/index.ts
|
|
8663
|
+
var StelOrderProvider = class {
|
|
8664
|
+
name = "stelorder";
|
|
8665
|
+
version = "1.0.0";
|
|
8666
|
+
capabilities = STELORDER_CAPABILITIES;
|
|
8667
|
+
client;
|
|
8668
|
+
logger;
|
|
8669
|
+
currencyCode;
|
|
8670
|
+
storefrontId;
|
|
8671
|
+
companyName;
|
|
8672
|
+
constructor(config) {
|
|
8673
|
+
this.client = new StelOrderClient(config);
|
|
8674
|
+
this.logger = createLogger("StelOrderProvider", config.debug);
|
|
8675
|
+
this.currencyCode = config.currencyCode ?? "USD";
|
|
8676
|
+
this.storefrontId = config.storefrontId ?? "stelorder-primary";
|
|
8677
|
+
this.companyName = config.companyName ?? "Stel Order";
|
|
8678
|
+
this.logger.info("Initializing Stel Order provider", {
|
|
8679
|
+
storefrontId: this.storefrontId,
|
|
8680
|
+
companyName: this.companyName,
|
|
8681
|
+
currencyCode: this.currencyCode
|
|
8682
|
+
});
|
|
8683
|
+
}
|
|
8684
|
+
// ============================================
|
|
8685
|
+
// Product Operations
|
|
8686
|
+
// ============================================
|
|
8687
|
+
async getProduct(handle, _options) {
|
|
8688
|
+
this.logger.debug("getProduct", { handle });
|
|
8689
|
+
try {
|
|
8690
|
+
if (/^\d+$/.test(handle)) {
|
|
8691
|
+
const raw = await this.client.getOne("products", handle);
|
|
8692
|
+
return raw ? transformStelProduct(raw, this.currencyCode) : void 0;
|
|
8693
|
+
}
|
|
8694
|
+
const rawProducts = await this.client.list("products", { limit: 100 });
|
|
8695
|
+
for (const raw of rawProducts) {
|
|
8696
|
+
const productHandle = buildStelHandle(raw["full-reference"], raw.reference, raw.name, raw.id);
|
|
8697
|
+
if (productHandle === handle) {
|
|
8698
|
+
return transformStelProduct(raw, this.currencyCode);
|
|
8699
|
+
}
|
|
8700
|
+
}
|
|
8701
|
+
return void 0;
|
|
8702
|
+
} catch (error) {
|
|
8703
|
+
this.logger.error("getProduct failed", { handle, error });
|
|
8704
|
+
throw this.wrapError("getProduct", error);
|
|
8705
|
+
}
|
|
8706
|
+
}
|
|
8707
|
+
async getProducts(options) {
|
|
8708
|
+
this.logger.debug("getProducts", { options });
|
|
8709
|
+
try {
|
|
8710
|
+
const query = {};
|
|
8711
|
+
if (options?.first) {
|
|
8712
|
+
query.limit = options.first;
|
|
8713
|
+
}
|
|
8714
|
+
if (options?.skip) {
|
|
8715
|
+
query.start = options.skip;
|
|
8716
|
+
}
|
|
8717
|
+
if (typeof options?.after === "number") {
|
|
8718
|
+
query.start = options.after;
|
|
8719
|
+
}
|
|
8720
|
+
if (options?.sortKey) {
|
|
8721
|
+
query.sort = options.reverse ? `-${options.sortKey}` : options.sortKey;
|
|
8722
|
+
}
|
|
8723
|
+
if (options?.categoryIds?.length) {
|
|
8724
|
+
query["product-category-id"] = `in:${options.categoryIds.join(",")}`;
|
|
8725
|
+
}
|
|
8726
|
+
const rawProducts = await this.client.list("products", query);
|
|
8727
|
+
let products = rawProducts.filter((p) => !p.deleted && !p.inactive).map((p) => transformStelProduct(p, this.currencyCode));
|
|
8728
|
+
if (options?.query) {
|
|
8729
|
+
const needle = options.query.toLowerCase();
|
|
8730
|
+
products = products.filter(
|
|
8731
|
+
(p) => p.title.toLowerCase().includes(needle) || p.description.toLowerCase().includes(needle) || p.handle.includes(needle)
|
|
8732
|
+
);
|
|
8733
|
+
}
|
|
8734
|
+
return products;
|
|
8735
|
+
} catch (error) {
|
|
8736
|
+
this.logger.error("getProducts failed", { options, error });
|
|
8737
|
+
throw this.wrapError("getProducts", error);
|
|
8738
|
+
}
|
|
8739
|
+
}
|
|
8740
|
+
async getProductRecommendations(_productId) {
|
|
8741
|
+
return [];
|
|
8742
|
+
}
|
|
8743
|
+
// ============================================
|
|
8744
|
+
// Category Operations
|
|
8745
|
+
// ============================================
|
|
8746
|
+
async getCategory(idOrHandle) {
|
|
8747
|
+
this.logger.debug("getCategory", { idOrHandle });
|
|
8748
|
+
try {
|
|
8749
|
+
if (/^\d+$/.test(idOrHandle)) {
|
|
8750
|
+
const raw = await this.client.getOne("productCategories", idOrHandle);
|
|
8751
|
+
return raw ? transformStelCategory(raw) : void 0;
|
|
8752
|
+
}
|
|
8753
|
+
const rawCategories = await this.client.list("productCategories");
|
|
8754
|
+
for (const raw of rawCategories) {
|
|
8755
|
+
const catHandle = buildStelHandle(raw.slug, raw.name, raw.id);
|
|
8756
|
+
if (catHandle === idOrHandle) {
|
|
8757
|
+
return transformStelCategory(raw);
|
|
8758
|
+
}
|
|
8759
|
+
}
|
|
8760
|
+
return void 0;
|
|
8761
|
+
} catch (error) {
|
|
8762
|
+
this.logger.error("getCategory failed", { idOrHandle, error });
|
|
8763
|
+
throw this.wrapError("getCategory", error);
|
|
8764
|
+
}
|
|
8765
|
+
}
|
|
8766
|
+
async getCategories(options) {
|
|
8767
|
+
this.logger.debug("getCategories", { options });
|
|
8768
|
+
try {
|
|
8769
|
+
if (options?.customFetcher) {
|
|
8770
|
+
return options.customFetcher(options);
|
|
8771
|
+
}
|
|
8772
|
+
const query = {};
|
|
8773
|
+
if (options?.limit) {
|
|
8774
|
+
query.limit = options.limit;
|
|
8775
|
+
}
|
|
8776
|
+
if (options?.parentCategoryId) {
|
|
8777
|
+
query["parent-category-id"] = options.parentCategoryId;
|
|
8778
|
+
}
|
|
8779
|
+
const rawCategories = await this.client.list("productCategories", query);
|
|
8780
|
+
let categories = rawCategories.filter((c) => !c.deleted).map(transformStelCategory);
|
|
8781
|
+
if (options?.query) {
|
|
8782
|
+
const needle = options.query.toLowerCase();
|
|
8783
|
+
categories = categories.filter(
|
|
8784
|
+
(c) => c.name.toLowerCase().includes(needle) || c.handle.includes(needle)
|
|
8785
|
+
);
|
|
8786
|
+
}
|
|
8787
|
+
return categories;
|
|
8788
|
+
} catch (error) {
|
|
8789
|
+
this.logger.error("getCategories failed", { options, error });
|
|
8790
|
+
throw this.wrapError("getCategories", error);
|
|
8791
|
+
}
|
|
8792
|
+
}
|
|
8793
|
+
async getCategoryProducts(handle, options) {
|
|
8794
|
+
this.logger.debug("getCategoryProducts", { handle, options });
|
|
8795
|
+
try {
|
|
8796
|
+
const category = await this.getCategory(handle);
|
|
8797
|
+
if (!category) {
|
|
8798
|
+
return [];
|
|
8799
|
+
}
|
|
8800
|
+
return this.getProducts({
|
|
8801
|
+
categoryIds: [category.id],
|
|
8802
|
+
first: options?.first,
|
|
8803
|
+
sortKey: options?.sortKey,
|
|
8804
|
+
reverse: options?.reverse,
|
|
8805
|
+
after: options?.after
|
|
8806
|
+
});
|
|
8807
|
+
} catch (error) {
|
|
8808
|
+
this.logger.error("getCategoryProducts failed", { handle, error });
|
|
8809
|
+
throw this.wrapError("getCategoryProducts", error);
|
|
8810
|
+
}
|
|
8811
|
+
}
|
|
8812
|
+
// ============================================
|
|
8813
|
+
// Collection Operations (alias categories)
|
|
8814
|
+
// ============================================
|
|
8815
|
+
async getCollection(handle) {
|
|
8816
|
+
this.logger.debug("getCollection", { handle });
|
|
8817
|
+
try {
|
|
8818
|
+
if (/^\d+$/.test(handle)) {
|
|
8819
|
+
const raw = await this.client.getOne("productCategories", handle);
|
|
8820
|
+
return raw ? transformStelCategoryToCollection(raw) : void 0;
|
|
8821
|
+
}
|
|
8822
|
+
const rawCategories = await this.client.list("productCategories");
|
|
8823
|
+
for (const raw of rawCategories) {
|
|
8824
|
+
const catHandle = buildStelHandle(raw.slug, raw.name, raw.id);
|
|
8825
|
+
if (catHandle === handle) {
|
|
8826
|
+
return transformStelCategoryToCollection(raw);
|
|
8827
|
+
}
|
|
8828
|
+
}
|
|
8829
|
+
return void 0;
|
|
8830
|
+
} catch (error) {
|
|
8831
|
+
this.logger.error("getCollection failed", { handle, error });
|
|
8832
|
+
throw this.wrapError("getCollection", error);
|
|
8833
|
+
}
|
|
8834
|
+
}
|
|
8835
|
+
async getCollections(options) {
|
|
8836
|
+
this.logger.debug("getCollections", { options });
|
|
8837
|
+
try {
|
|
8838
|
+
const query = {};
|
|
8839
|
+
if (options?.limit) {
|
|
8840
|
+
query.limit = options.limit;
|
|
8841
|
+
}
|
|
8842
|
+
const rawCategories = await this.client.list("productCategories", query);
|
|
8843
|
+
let collections = rawCategories.filter((c) => !c.deleted).map(transformStelCategoryToCollection);
|
|
8844
|
+
if (options?.query) {
|
|
8845
|
+
const needle = options.query.toLowerCase();
|
|
8846
|
+
collections = collections.filter(
|
|
8847
|
+
(c) => c.title.toLowerCase().includes(needle) || c.handle.includes(needle)
|
|
8848
|
+
);
|
|
8849
|
+
}
|
|
8850
|
+
return collections;
|
|
8851
|
+
} catch (error) {
|
|
8852
|
+
this.logger.error("getCollections failed", { options, error });
|
|
8853
|
+
throw this.wrapError("getCollections", error);
|
|
8854
|
+
}
|
|
8855
|
+
}
|
|
8856
|
+
async getCollectionProducts(handle, options) {
|
|
8857
|
+
return this.getCategoryProducts(handle, options);
|
|
8858
|
+
}
|
|
8859
|
+
// ============================================
|
|
8860
|
+
// Inventory Operations
|
|
8861
|
+
// ============================================
|
|
8862
|
+
async getStockLocations(_params) {
|
|
8863
|
+
this.logger.debug("getStockLocations");
|
|
8864
|
+
try {
|
|
8865
|
+
const rawWarehouses = await this.client.list("warehouses");
|
|
8866
|
+
return rawWarehouses.filter((w) => !w.deleted).map(transformStelWarehouseToStockLocation);
|
|
8867
|
+
} catch (error) {
|
|
8868
|
+
this.logger.error("getStockLocations failed", { error });
|
|
8869
|
+
throw this.wrapError("getStockLocations", error);
|
|
8870
|
+
}
|
|
8871
|
+
}
|
|
8872
|
+
async checkInventoryLevels(variantId, _salesChannelId) {
|
|
8873
|
+
this.logger.debug("checkInventoryLevels", { variantId });
|
|
8874
|
+
try {
|
|
8875
|
+
const raw = await this.client.getOne("products", variantId);
|
|
8876
|
+
if (!raw?.["product-warehouses"]?.length) {
|
|
8877
|
+
return [];
|
|
8878
|
+
}
|
|
8879
|
+
return raw["product-warehouses"].map(transformStelProductWarehouseToInventoryLevel);
|
|
8880
|
+
} catch (error) {
|
|
8881
|
+
this.logger.error("checkInventoryLevels failed", { variantId, error });
|
|
8882
|
+
throw this.wrapError("checkInventoryLevels", error);
|
|
8883
|
+
}
|
|
8884
|
+
}
|
|
8885
|
+
validateCartStock(_cartId) {
|
|
8886
|
+
return this.notSupported("validateCartStock");
|
|
8887
|
+
}
|
|
8888
|
+
getFulfillmentOptions(_cartId, _salesChannelId) {
|
|
8889
|
+
return this.notSupported("getFulfillmentOptions");
|
|
8890
|
+
}
|
|
8891
|
+
// ============================================
|
|
8892
|
+
// Cart Operations (unsupported — STEL is ERP, not storefront)
|
|
8893
|
+
// ============================================
|
|
8894
|
+
createCart(_options) {
|
|
8895
|
+
return this.notSupported("createCart");
|
|
8896
|
+
}
|
|
8897
|
+
getCart(_cartId) {
|
|
8898
|
+
return this.notSupported("getCart");
|
|
8899
|
+
}
|
|
8900
|
+
addToCart(_cartId, _lines) {
|
|
8901
|
+
return this.notSupported("addToCart");
|
|
8902
|
+
}
|
|
8903
|
+
removeFromCart(_cartId, _lineIds) {
|
|
8904
|
+
return this.notSupported("removeFromCart");
|
|
8905
|
+
}
|
|
8906
|
+
updateCart(_cartId, _lines) {
|
|
8907
|
+
return this.notSupported("updateCart");
|
|
8908
|
+
}
|
|
8909
|
+
// ============================================
|
|
8910
|
+
// Checkout Operations (unsupported)
|
|
8911
|
+
// ============================================
|
|
8912
|
+
completeCheckout(_cartId) {
|
|
8913
|
+
return this.notSupported("completeCheckout");
|
|
8914
|
+
}
|
|
8915
|
+
getRegionCountries(_regionId) {
|
|
8916
|
+
return this.notSupported("getRegionCountries");
|
|
8917
|
+
}
|
|
8918
|
+
addShippingMethod(_cartId, _methodId) {
|
|
8919
|
+
return this.notSupported("addShippingMethod");
|
|
8920
|
+
}
|
|
8921
|
+
initiatePaymentSession(_cartId, _providerId) {
|
|
8922
|
+
return this.notSupported("initiatePaymentSession");
|
|
8923
|
+
}
|
|
8924
|
+
applyDiscountCode(_cartId, _code) {
|
|
8925
|
+
return this.notSupported("applyDiscountCode");
|
|
8926
|
+
}
|
|
8927
|
+
removeDiscountCode(_cartId, _code) {
|
|
8928
|
+
return this.notSupported("removeDiscountCode");
|
|
8929
|
+
}
|
|
8930
|
+
// ============================================
|
|
8931
|
+
// Payment Methods
|
|
8932
|
+
// ============================================
|
|
8933
|
+
async getPaymentMethods(_options) {
|
|
8934
|
+
this.logger.debug("getPaymentMethods");
|
|
8935
|
+
try {
|
|
8936
|
+
const rawOptions = await this.client.list("paymentOptions");
|
|
8937
|
+
return rawOptions.filter((o) => !o.deleted).map(transformStelPaymentOption);
|
|
8938
|
+
} catch (error) {
|
|
8939
|
+
this.logger.error("getPaymentMethods failed", { error });
|
|
8940
|
+
throw this.wrapError("getPaymentMethods", error);
|
|
8941
|
+
}
|
|
8942
|
+
}
|
|
8943
|
+
// ============================================
|
|
8944
|
+
// Shipping / Delivery Methods
|
|
8945
|
+
// ============================================
|
|
8946
|
+
async getShippingMethods(_cartId) {
|
|
8947
|
+
this.logger.debug("getShippingMethods (delivery options listing)");
|
|
8948
|
+
try {
|
|
8949
|
+
const rawOptions = await this.client.list("deliveryOptions");
|
|
8950
|
+
return rawOptions.filter((o) => !o.deleted).map((o) => transformStelDeliveryOption(o, this.currencyCode));
|
|
8951
|
+
} catch (error) {
|
|
8952
|
+
this.logger.error("getShippingMethods failed", { error });
|
|
8953
|
+
throw this.wrapError("getShippingMethods", error);
|
|
8954
|
+
}
|
|
8955
|
+
}
|
|
8956
|
+
// ============================================
|
|
8957
|
+
// Customer Operations (optional)
|
|
8958
|
+
// ============================================
|
|
8959
|
+
async getCustomer(customerId) {
|
|
8960
|
+
this.logger.debug("getCustomer", { customerId });
|
|
8961
|
+
try {
|
|
8962
|
+
const raw = await this.client.getOne("clients", customerId);
|
|
8963
|
+
return raw ? transformStelClient(raw) : void 0;
|
|
8964
|
+
} catch (error) {
|
|
8965
|
+
this.logger.error("getCustomer failed", { customerId, error });
|
|
8966
|
+
throw this.wrapError("getCustomer", error);
|
|
8967
|
+
}
|
|
8968
|
+
}
|
|
8969
|
+
async getCustomers(options) {
|
|
8970
|
+
this.logger.debug("getCustomers", { options });
|
|
8971
|
+
try {
|
|
8972
|
+
if (options?.customFetcher) {
|
|
8973
|
+
return options.customFetcher(options);
|
|
8974
|
+
}
|
|
8975
|
+
const query = {};
|
|
8976
|
+
if (options?.limit) {
|
|
8977
|
+
query.limit = options.limit;
|
|
8978
|
+
}
|
|
8979
|
+
if (options?.offset) {
|
|
8980
|
+
query.start = options.offset;
|
|
8981
|
+
}
|
|
8982
|
+
const rawClients = await this.client.list("clients", query);
|
|
8983
|
+
let customers = rawClients.filter((c) => !c.deleted).map(transformStelClient);
|
|
8984
|
+
if (options?.search) {
|
|
8985
|
+
const needle = options.search.toLowerCase();
|
|
8986
|
+
customers = customers.filter(
|
|
8987
|
+
(c) => c.email.toLowerCase().includes(needle) || (c.firstName ?? "").toLowerCase().includes(needle) || (c.lastName ?? "").toLowerCase().includes(needle)
|
|
8988
|
+
);
|
|
8989
|
+
}
|
|
8990
|
+
return customers;
|
|
8991
|
+
} catch (error) {
|
|
8992
|
+
this.logger.error("getCustomers failed", { options, error });
|
|
8993
|
+
throw this.wrapError("getCustomers", error);
|
|
8994
|
+
}
|
|
8995
|
+
}
|
|
8996
|
+
async updateCustomer(customerId, data) {
|
|
8997
|
+
this.logger.debug("updateCustomer", { customerId, data });
|
|
8998
|
+
try {
|
|
8999
|
+
const stelPayload = {};
|
|
9000
|
+
if (data.firstName || data.lastName) {
|
|
9001
|
+
stelPayload.name = [data.firstName, data.lastName].filter(Boolean).join(" ");
|
|
9002
|
+
}
|
|
9003
|
+
if (data.email) {
|
|
9004
|
+
stelPayload.email = data.email;
|
|
9005
|
+
}
|
|
9006
|
+
if (data.phone) {
|
|
9007
|
+
stelPayload.phone = data.phone;
|
|
9008
|
+
}
|
|
9009
|
+
const raw = await this.client.update("clients", customerId, stelPayload);
|
|
9010
|
+
return transformStelClient(raw);
|
|
9011
|
+
} catch (error) {
|
|
9012
|
+
this.logger.error("updateCustomer failed", { customerId, error });
|
|
9013
|
+
throw this.wrapError("updateCustomer", error);
|
|
9014
|
+
}
|
|
9015
|
+
}
|
|
9016
|
+
// ============================================
|
|
9017
|
+
// Order Operations (optional)
|
|
9018
|
+
// ============================================
|
|
9019
|
+
async getOrder(orderId) {
|
|
9020
|
+
this.logger.debug("getOrder", { orderId });
|
|
9021
|
+
try {
|
|
9022
|
+
const raw = await this.client.getOne("salesOrders", orderId);
|
|
9023
|
+
return raw ? transformStelSalesOrder(raw, this.currencyCode) : void 0;
|
|
9024
|
+
} catch (error) {
|
|
9025
|
+
this.logger.error("getOrder failed", { orderId, error });
|
|
9026
|
+
throw this.wrapError("getOrder", error);
|
|
9027
|
+
}
|
|
9028
|
+
}
|
|
9029
|
+
async getOrders(options) {
|
|
9030
|
+
this.logger.debug("getOrders", { options });
|
|
9031
|
+
try {
|
|
9032
|
+
if (options?.customFetcher) {
|
|
9033
|
+
return options.customFetcher(options);
|
|
9034
|
+
}
|
|
9035
|
+
const query = {};
|
|
9036
|
+
if (options?.limit) {
|
|
9037
|
+
query.limit = options.limit;
|
|
9038
|
+
}
|
|
9039
|
+
if (options?.offset) {
|
|
9040
|
+
query.start = options.offset;
|
|
9041
|
+
}
|
|
9042
|
+
if (options?.customerId) {
|
|
9043
|
+
query["client-id"] = options.customerId;
|
|
9044
|
+
}
|
|
9045
|
+
const rawOrders = await this.client.list("salesOrders", query);
|
|
9046
|
+
return rawOrders.filter((o) => !o.deleted).map((o) => transformStelSalesOrder(o, this.currencyCode));
|
|
9047
|
+
} catch (error) {
|
|
9048
|
+
this.logger.error("getOrders failed", { options, error });
|
|
9049
|
+
throw this.wrapError("getOrders", error);
|
|
9050
|
+
}
|
|
9051
|
+
}
|
|
9052
|
+
async getAdminOrders(options) {
|
|
9053
|
+
this.logger.debug("getAdminOrders", { options });
|
|
9054
|
+
try {
|
|
9055
|
+
const query = {};
|
|
9056
|
+
if (options?.limit) {
|
|
9057
|
+
query.limit = options.limit;
|
|
9058
|
+
}
|
|
9059
|
+
if (options?.offset) {
|
|
9060
|
+
query.start = options.offset;
|
|
9061
|
+
}
|
|
9062
|
+
const rawOrders = await this.client.list("salesOrders", query);
|
|
9063
|
+
let orders = rawOrders.filter((o) => !o.deleted).map((o) => transformStelSalesOrder(o, this.currencyCode));
|
|
9064
|
+
if (options?.search) {
|
|
9065
|
+
const needle = options.search.toLowerCase();
|
|
9066
|
+
orders = orders.filter(
|
|
9067
|
+
(o) => o.orderNumber.toLowerCase().includes(needle) || o.email.toLowerCase().includes(needle)
|
|
9068
|
+
);
|
|
9069
|
+
}
|
|
9070
|
+
if (options?.status) {
|
|
9071
|
+
const statuses = Array.isArray(options.status) ? options.status : [options.status];
|
|
9072
|
+
orders = orders.filter((o) => statuses.includes(o.status));
|
|
9073
|
+
}
|
|
9074
|
+
return { orders, count: orders.length };
|
|
9075
|
+
} catch (error) {
|
|
9076
|
+
this.logger.error("getAdminOrders failed", { options, error });
|
|
9077
|
+
throw this.wrapError("getAdminOrders", error);
|
|
9078
|
+
}
|
|
9079
|
+
}
|
|
9080
|
+
cancelOrder(_orderId) {
|
|
9081
|
+
return this.notSupported("cancelOrder");
|
|
9082
|
+
}
|
|
9083
|
+
createFulfillment(_orderId, _items) {
|
|
9084
|
+
return this.notSupported("createFulfillment");
|
|
9085
|
+
}
|
|
9086
|
+
createRefund(_orderId, _amount, _reason) {
|
|
9087
|
+
return this.notSupported("createRefund");
|
|
9088
|
+
}
|
|
9089
|
+
// ============================================
|
|
9090
|
+
// Storefront Context
|
|
9091
|
+
// ============================================
|
|
9092
|
+
async getStorefrontContext() {
|
|
9093
|
+
return {
|
|
9094
|
+
id: this.storefrontId,
|
|
9095
|
+
name: this.companyName,
|
|
9096
|
+
platformType: "stelorder",
|
|
9097
|
+
requiresProductScoping: false,
|
|
9098
|
+
currencyCode: this.currencyCode,
|
|
9099
|
+
metadata: {
|
|
9100
|
+
apiBaseUrl: this.client.apiBaseUrl,
|
|
9101
|
+
singleCompany: true,
|
|
9102
|
+
providerVersion: this.version
|
|
9103
|
+
}
|
|
9104
|
+
};
|
|
9105
|
+
}
|
|
9106
|
+
isStorefrontRequired() {
|
|
9107
|
+
return false;
|
|
9108
|
+
}
|
|
9109
|
+
// ============================================
|
|
9110
|
+
// Internal helpers
|
|
9111
|
+
// ============================================
|
|
9112
|
+
notSupported(operation) {
|
|
9113
|
+
return Promise.reject(
|
|
9114
|
+
new ProviderAPIError(
|
|
9115
|
+
`Stel Order does not support \`${operation}\`. STEL is an ERP adapter without cart/checkout/auth capabilities.`,
|
|
9116
|
+
"stelorder",
|
|
9117
|
+
501
|
|
9118
|
+
)
|
|
9119
|
+
);
|
|
9120
|
+
}
|
|
9121
|
+
wrapError(operation, error) {
|
|
9122
|
+
if (error instanceof ProviderAPIError) {
|
|
9123
|
+
return error;
|
|
9124
|
+
}
|
|
9125
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9126
|
+
return new ProviderAPIError(
|
|
9127
|
+
`Stel Order \`${operation}\` failed: ${message}`,
|
|
9128
|
+
"stelorder",
|
|
9129
|
+
500
|
|
9130
|
+
);
|
|
9131
|
+
}
|
|
9132
|
+
};
|
|
9133
|
+
|
|
8072
9134
|
// src/providers/mock/mock.ts
|
|
8073
9135
|
var FIXTURE_TIMESTAMP = "2026-01-01T00:00:00.000Z";
|
|
8074
9136
|
var DEFAULT_SITE_URL = "https://mock.thorcommerce.local";
|
|
@@ -9088,6 +10150,8 @@ function createProvider(options) {
|
|
|
9088
10150
|
return new MockProvider(config);
|
|
9089
10151
|
case "medusa":
|
|
9090
10152
|
return new MedusaProvider(config);
|
|
10153
|
+
case "stelorder":
|
|
10154
|
+
return new StelOrderProvider(config);
|
|
9091
10155
|
case "shopify":
|
|
9092
10156
|
return new ShopifyProvider(config);
|
|
9093
10157
|
case "bigcommerce":
|
|
@@ -9132,8 +10196,10 @@ function isProviderType(provider, type) {
|
|
|
9132
10196
|
ResourceNotFoundError,
|
|
9133
10197
|
SHOPIFY_CAPABILITIES,
|
|
9134
10198
|
SPREE_CAPABILITIES,
|
|
10199
|
+
STELORDER_CAPABILITIES,
|
|
9135
10200
|
ShopifyProvider,
|
|
9136
10201
|
SpreeProvider,
|
|
10202
|
+
StelOrderProvider,
|
|
9137
10203
|
StorefrontConfigError,
|
|
9138
10204
|
WOOCOMMERCE_CAPABILITIES,
|
|
9139
10205
|
WooCommerceProvider,
|