@thorprovider/adapters 4.2.1 → 5.0.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.
Files changed (60) hide show
  1. package/PROVIDER_IMPLEMENTATION_ANALYSIS.md +659 -0
  2. package/dist/index.d.mts +225 -387
  3. package/dist/index.d.ts +225 -387
  4. package/dist/index.js +613 -3062
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +609 -3052
  7. package/dist/index.mjs.map +1 -1
  8. package/docs/RETRY_SOLUTION_SUMMARY.md +26 -11
  9. package/docs/authentication.md +115 -62
  10. package/docs/capabilities-system.md +4 -2
  11. package/docs/category-customization.md +37 -29
  12. package/docs/fetch-reliability-solution.md +127 -278
  13. package/docs/getting-started.md +43 -29
  14. package/docs/profile-management.md +68 -38
  15. package/docs/services-overview.md +4 -2
  16. package/package.json +1 -1
  17. package/quick-reference.md +33 -0
  18. package/src/backend/factory.ts +1 -11
  19. package/src/factory/index.ts +74 -52
  20. package/src/index.ts +5 -15
  21. package/src/providers/index.ts +1 -16
  22. package/src/providers/medusa/admin.test.ts +404 -0
  23. package/src/providers/medusa/admin.ts +442 -0
  24. package/src/providers/medusa/auth.test.ts +137 -0
  25. package/src/providers/medusa/auth.ts +96 -1
  26. package/src/providers/medusa/index.ts +21 -1
  27. package/src/resilience/README.md +70 -48
  28. package/src/types/capabilities.types.ts +0 -250
  29. package/src/core/errors.js +0 -161
  30. package/src/core/fetch-utils.js +0 -240
  31. package/src/core/logger.js +0 -63
  32. package/src/metadata/channel-scope-validation.js +0 -136
  33. package/src/metadata/channel-scope.js +0 -174
  34. package/src/metadata/index.js +0 -31
  35. package/src/providers/bigcommerce/bigcommerce.ts +0 -6
  36. package/src/providers/bigcommerce/index.ts +0 -315
  37. package/src/providers/bigcommerce/transforms.ts +0 -227
  38. package/src/providers/magento/index.ts +0 -387
  39. package/src/providers/magento/magento.ts +0 -5
  40. package/src/providers/magento/queries.ts +0 -267
  41. package/src/providers/magento/transforms.ts +0 -249
  42. package/src/providers/medusa/auth.js +0 -601
  43. package/src/providers/medusa/index.js +0 -2485
  44. package/src/providers/medusa/payment.js +0 -265
  45. package/src/providers/medusa/transforms.js +0 -505
  46. package/src/providers/shopify/auth.ts +0 -402
  47. package/src/providers/shopify/index.ts +0 -444
  48. package/src/providers/shopify/mutations.ts +0 -247
  49. package/src/providers/shopify/queries.ts +0 -324
  50. package/src/providers/shopify/shopify.ts +0 -7
  51. package/src/providers/shopify/transforms.ts +0 -275
  52. package/src/providers/spree/index.ts +0 -344
  53. package/src/providers/spree/spree.ts +0 -5
  54. package/src/providers/spree/transforms.ts +0 -254
  55. package/src/providers/woocommerce/index.ts +0 -310
  56. package/src/providers/woocommerce/transforms.ts +0 -254
  57. package/src/providers/woocommerce/woocommerce.ts +0 -5
  58. package/src/types/capabilities.types.js +0 -141
  59. package/src/types/provider.js +0 -9
  60. package/src/utils/payment-utils.js +0 -152
@@ -1,505 +0,0 @@
1
- "use strict";
2
- /**
3
- * @thorprovider/adapters v2.0
4
- * Medusa Provider - Transform functions
5
- *
6
- * These functions convert Medusa-specific types to our unified types
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.transformStockLocation = transformStockLocation;
10
- exports.transformInventoryLevel = transformInventoryLevel;
11
- exports.transformFulfillmentOption = transformFulfillmentOption;
12
- exports.transformProductOption = transformProductOption;
13
- exports.transformProductVariant = transformProductVariant;
14
- exports.transformProduct = transformProduct;
15
- exports.transformCartItem = transformCartItem;
16
- exports.transformCart = transformCart;
17
- exports.transformCollection = transformCollection;
18
- exports.transformCategory = transformCategory;
19
- exports.transformOrderItem = transformOrderItem;
20
- exports.transformAddress = transformAddress;
21
- exports.transformCustomer = transformCustomer;
22
- exports.transformOrder = transformOrder;
23
- /**
24
- * Transform Medusa Money to unified Money
25
- */
26
- function transformMoney(amount, currencyCode) {
27
- if (currencyCode === void 0) { currencyCode = 'USD'; }
28
- return {
29
- amount: ((amount !== null && amount !== void 0 ? amount : 0) / 100).toFixed(2), // Medusa stores cents
30
- currencyCode: currencyCode.toUpperCase(),
31
- };
32
- }
33
- /**
34
- * Transform Medusa image to unified Image
35
- */
36
- function transformImage(url, alt) {
37
- if (alt === void 0) { alt = ''; }
38
- return {
39
- url: url,
40
- altText: alt,
41
- width: 800,
42
- height: 800,
43
- };
44
- }
45
- // ============================================
46
- // Inventory & Fulfillment Transforms
47
- // ============================================
48
- function transformStockLocation(raw) {
49
- return {
50
- id: raw.id,
51
- name: raw.name,
52
- address: raw.address
53
- ? {
54
- address1: raw.address.address_1,
55
- address2: raw.address.address_2,
56
- city: raw.address.city,
57
- countryCode: raw.address.country_code,
58
- postalCode: raw.address.postal_code,
59
- province: raw.address.province,
60
- }
61
- : undefined,
62
- metadata: raw.metadata,
63
- };
64
- }
65
- function transformInventoryLevel(raw, locationName) {
66
- var _a, _b, _c;
67
- return {
68
- locationId: raw.location_id,
69
- locationName: locationName,
70
- availableQuantity: (_a = raw.available_quantity) !== null && _a !== void 0 ? _a : 0,
71
- reservedQuantity: (_b = raw.reserved_quantity) !== null && _b !== void 0 ? _b : 0,
72
- incomingQuantity: raw.incoming_quantity,
73
- stockedQuantity: (_c = raw.stocked_quantity) !== null && _c !== void 0 ? _c : 0,
74
- };
75
- }
76
- function transformFulfillmentOption(shippingOption, location, currencyCode) {
77
- var _a;
78
- return {
79
- id: shippingOption.id,
80
- providerId: shippingOption.provider_id,
81
- name: shippingOption.name,
82
- description: shippingOption.description,
83
- price: transformMoney(shippingOption.amount, currencyCode),
84
- estimatedDays: (_a = shippingOption.metadata) === null || _a === void 0 ? void 0 : _a.estimated_days,
85
- stockLocation: location,
86
- };
87
- }
88
- /**
89
- * Transform Medusa ProductOption to unified ProductOption
90
- */
91
- function transformProductOption(option) {
92
- var _a, _b, _c;
93
- return {
94
- id: option.id,
95
- name: (_a = option.title) !== null && _a !== void 0 ? _a : '',
96
- values: (_c = (_b = option.values) === null || _b === void 0 ? void 0 : _b.map(function (v) { var _a; return (_a = v.value) !== null && _a !== void 0 ? _a : ''; })) !== null && _c !== void 0 ? _c : [],
97
- };
98
- }
99
- /**
100
- * Transform Medusa ProductVariant to unified ProductVariant
101
- */
102
- function transformProductVariant(variant, currencyCode) {
103
- var _a, _b, _c, _d, _e, _f;
104
- if (currencyCode === void 0) { currencyCode = 'USD'; }
105
- var priceAmount;
106
- var priceCurrency = currencyCode;
107
- // Priority 1: Use calculated_price if available (from region-based pricing)
108
- if (variant.calculated_price) {
109
- priceAmount = variant.calculated_price.calculated_amount;
110
- priceCurrency = variant.calculated_price.currency_code || currencyCode;
111
- }
112
- // Priority 2: Fallback to prices array
113
- else if (variant.prices && variant.prices.length > 0) {
114
- var price = variant.prices.find(function (p) { return p.currency_code === currencyCode.toLowerCase(); });
115
- priceAmount = price === null || price === void 0 ? void 0 : price.amount;
116
- priceCurrency = (price === null || price === void 0 ? void 0 : price.currency_code) || currencyCode;
117
- }
118
- // Determine if variant is available for sale
119
- // Following Medusa docs: https://docs.medusajs.com/resources/storefront-development/products/inventory
120
- // A variant is in stock if:
121
- // 1. manage_inventory is false (inventory not tracked) - always in stock
122
- // 2. inventory_quantity > 0 (has stock)
123
- // 3. allow_backorder is true (can order even without stock)
124
- var isAvailable = variant.manage_inventory === false
125
- ? true
126
- : ((_a = variant.inventory_quantity) !== null && _a !== void 0 ? _a : 0) > 0 || variant.allow_backorder === true;
127
- return {
128
- id: variant.id,
129
- title: (_b = variant.title) !== null && _b !== void 0 ? _b : 'Default',
130
- sku: (_c = variant.sku) !== null && _c !== void 0 ? _c : undefined,
131
- availableForSale: isAvailable,
132
- selectedOptions: (_e = (_d = variant.options) === null || _d === void 0 ? void 0 : _d.map(function (opt) {
133
- var _a, _b, _c;
134
- return ({
135
- name: (_b = (_a = opt.option) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : '',
136
- value: (_c = opt.value) !== null && _c !== void 0 ? _c : '',
137
- });
138
- })) !== null && _e !== void 0 ? _e : [],
139
- price: transformMoney(priceAmount, priceCurrency),
140
- compareAtPrice: undefined, // Medusa doesn't have compare-at pricing
141
- quantityAvailable: variant.manage_inventory ? variant.inventory_quantity : undefined,
142
- image: variant.thumbnail
143
- ? transformImage(variant.thumbnail, (_f = variant.title) !== null && _f !== void 0 ? _f : '')
144
- : undefined,
145
- };
146
- }
147
- /**
148
- * Transform Medusa Product to unified Product
149
- */
150
- function transformProduct(product, currencyCode) {
151
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
152
- if (currencyCode === void 0) { currencyCode = 'USD'; }
153
- var variants = (_b = (_a = product.variants) === null || _a === void 0 ? void 0 : _a.map(function (v) { return transformProductVariant(v, currencyCode); })) !== null && _b !== void 0 ? _b : [];
154
- // Calculate price range
155
- var prices = variants.map(function (v) { return parseFloat(v.price.amount); });
156
- var minPrice = Math.min.apply(Math, prices);
157
- var maxPrice = Math.max.apply(Math, prices);
158
- return {
159
- id: product.id,
160
- handle: (_c = product.handle) !== null && _c !== void 0 ? _c : '',
161
- title: (_d = product.title) !== null && _d !== void 0 ? _d : '',
162
- description: (_e = product.description) !== null && _e !== void 0 ? _e : '',
163
- descriptionHtml: (_f = product.description) !== null && _f !== void 0 ? _f : '',
164
- // Medusa v2 /store/products API doesn't return 'status' field (it's null)
165
- // Products returned by Store API are already published, so we check if any variant is available
166
- availableForSale: variants.length > 0 && variants.some(function (v) { return v.availableForSale; }),
167
- options: (_h = (_g = product.options) === null || _g === void 0 ? void 0 : _g.map(transformProductOption)) !== null && _h !== void 0 ? _h : [],
168
- variants: variants,
169
- featuredImage: product.thumbnail
170
- ? transformImage(product.thumbnail, (_j = product.title) !== null && _j !== void 0 ? _j : '')
171
- : undefined,
172
- images: (_l = (_k = product.images) === null || _k === void 0 ? void 0 : _k.map(function (img) { var _a, _b; return transformImage((_a = img.url) !== null && _a !== void 0 ? _a : '', (_b = product.title) !== null && _b !== void 0 ? _b : ''); })) !== null && _l !== void 0 ? _l : [],
173
- priceRange: {
174
- minVariantPrice: transformMoney(minPrice * 100, currencyCode),
175
- maxVariantPrice: transformMoney(maxPrice * 100, currencyCode),
176
- },
177
- collections: product.collection ? [{
178
- id: product.collection.id,
179
- title: (_m = product.collection.title) !== null && _m !== void 0 ? _m : '',
180
- handle: (_o = product.collection.handle) !== null && _o !== void 0 ? _o : '',
181
- }] : undefined,
182
- productType: (_q = (_p = product.type) === null || _p === void 0 ? void 0 : _p.value) !== null && _q !== void 0 ? _q : undefined,
183
- vendor: undefined, // Medusa doesn't have vendor field
184
- tags: (_s = (_r = product.tags) === null || _r === void 0 ? void 0 : _r.map(function (t) { var _a; return (_a = t.value) !== null && _a !== void 0 ? _a : ''; })) !== null && _s !== void 0 ? _s : [],
185
- seo: {
186
- title: (_t = product.title) !== null && _t !== void 0 ? _t : '',
187
- description: (_u = product.description) !== null && _u !== void 0 ? _u : '',
188
- },
189
- createdAt: typeof product.created_at === 'string'
190
- ? product.created_at
191
- : (_w = (_v = product.created_at) === null || _v === void 0 ? void 0 : _v.toISOString()) !== null && _w !== void 0 ? _w : new Date().toISOString(),
192
- updatedAt: typeof product.updated_at === 'string'
193
- ? product.updated_at
194
- : (_y = (_x = product.updated_at) === null || _x === void 0 ? void 0 : _x.toISOString()) !== null && _y !== void 0 ? _y : new Date().toISOString(),
195
- metadata: (_z = product.metadata) !== null && _z !== void 0 ? _z : undefined,
196
- };
197
- }
198
- /**
199
- * Transform Medusa LineItem to unified CartItem
200
- */
201
- function resolveMedusaCartItemCurrencyCode(item, cartCurrencyCode) {
202
- var _a, _b, _c;
203
- return ((_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.cart) === null || _a === void 0 ? void 0 : _a.currency_code) !== null && _b !== void 0 ? _b : cartCurrencyCode) !== null && _c !== void 0 ? _c : 'usd');
204
- }
205
- function resolveMedusaCartItemTotalCents(item) {
206
- var _a;
207
- var quantity = (_a = item === null || item === void 0 ? void 0 : item.quantity) !== null && _a !== void 0 ? _a : 1;
208
- var safeQuantity = typeof quantity === 'number' && quantity > 0 ? quantity : 1;
209
- var totalCandidates = [
210
- item === null || item === void 0 ? void 0 : item.total,
211
- item === null || item === void 0 ? void 0 : item.item_total,
212
- item === null || item === void 0 ? void 0 : item.original_total,
213
- item === null || item === void 0 ? void 0 : item.subtotal,
214
- item === null || item === void 0 ? void 0 : item.item_subtotal,
215
- item === null || item === void 0 ? void 0 : item.original_subtotal,
216
- ];
217
- for (var _i = 0, totalCandidates_1 = totalCandidates; _i < totalCandidates_1.length; _i++) {
218
- var candidate = totalCandidates_1[_i];
219
- if (typeof candidate === 'number' && Number.isFinite(candidate) && candidate > 0) {
220
- return candidate;
221
- }
222
- }
223
- var unitCandidates = [
224
- item === null || item === void 0 ? void 0 : item.unit_price,
225
- item === null || item === void 0 ? void 0 : item.original_unit_price,
226
- ];
227
- for (var _b = 0, unitCandidates_1 = unitCandidates; _b < unitCandidates_1.length; _b++) {
228
- var candidate = unitCandidates_1[_b];
229
- if (typeof candidate === 'number' && Number.isFinite(candidate) && candidate > 0) {
230
- return candidate * safeQuantity;
231
- }
232
- }
233
- return 0;
234
- }
235
- function transformCartItem(item, cartCurrencyCode) {
236
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
237
- var variant = item.variant;
238
- var product = variant === null || variant === void 0 ? void 0 : variant.product;
239
- var currencyCode = resolveMedusaCartItemCurrencyCode(item, cartCurrencyCode);
240
- var totalCents = resolveMedusaCartItemTotalCents(item);
241
- return {
242
- id: item.id,
243
- quantity: (_a = item.quantity) !== null && _a !== void 0 ? _a : 1,
244
- cost: {
245
- totalAmount: transformMoney(totalCents, currencyCode),
246
- },
247
- merchandise: {
248
- id: (_b = variant === null || variant === void 0 ? void 0 : variant.id) !== null && _b !== void 0 ? _b : '',
249
- title: (_c = variant === null || variant === void 0 ? void 0 : variant.title) !== null && _c !== void 0 ? _c : '',
250
- selectedOptions: (_e = (_d = variant === null || variant === void 0 ? void 0 : variant.options) === null || _d === void 0 ? void 0 : _d.map(function (opt) {
251
- var _a, _b, _c;
252
- return ({
253
- name: (_b = (_a = opt.option) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : '',
254
- value: (_c = opt.value) !== null && _c !== void 0 ? _c : '',
255
- });
256
- })) !== null && _e !== void 0 ? _e : [],
257
- product: {
258
- id: (_f = product === null || product === void 0 ? void 0 : product.id) !== null && _f !== void 0 ? _f : '',
259
- handle: (_g = product === null || product === void 0 ? void 0 : product.handle) !== null && _g !== void 0 ? _g : '',
260
- title: (_h = product === null || product === void 0 ? void 0 : product.title) !== null && _h !== void 0 ? _h : '',
261
- featuredImage: (product === null || product === void 0 ? void 0 : product.thumbnail)
262
- ? transformImage(product.thumbnail, (_j = product.title) !== null && _j !== void 0 ? _j : '')
263
- : transformImage('', ''),
264
- },
265
- },
266
- };
267
- }
268
- /**
269
- * Transform Medusa Cart to unified Cart
270
- */
271
- function transformCart(cart) {
272
- var _a, _b, _c, _d, _e, _f;
273
- var currencyCode = (_a = cart.currency_code) !== null && _a !== void 0 ? _a : 'usd';
274
- return {
275
- id: cart.id,
276
- checkoutUrl: "/checkout/".concat(cart.id), // Medusa doesn't have a direct checkout URL
277
- cost: {
278
- subtotalAmount: transformMoney(cart.subtotal, currencyCode),
279
- totalAmount: transformMoney(cart.total, currencyCode),
280
- totalTaxAmount: transformMoney(cart.tax_total, currencyCode),
281
- },
282
- lines: (_c = (_b = cart.items) === null || _b === void 0 ? void 0 : _b.map(function (item) { return transformCartItem(item, currencyCode); })) !== null && _c !== void 0 ? _c : [],
283
- totalQuantity: (_e = (_d = cart.items) === null || _d === void 0 ? void 0 : _d.reduce(function (sum, item) { var _a; return sum + ((_a = item.quantity) !== null && _a !== void 0 ? _a : 0); }, 0)) !== null && _e !== void 0 ? _e : 0,
284
- completedAt: cart.completed_at
285
- ? (typeof cart.completed_at === 'string'
286
- ? cart.completed_at
287
- : (_f = cart.completed_at) === null || _f === void 0 ? void 0 : _f.toISOString())
288
- : undefined,
289
- };
290
- }
291
- /**
292
- * Transform Medusa Collection to unified Collection
293
- */
294
- function transformCollection(collection) {
295
- var _a, _b, _c, _d, _e, _f, _g, _h;
296
- return {
297
- id: collection.id,
298
- handle: collection.handle,
299
- title: (_a = collection.title) !== null && _a !== void 0 ? _a : '',
300
- description: (_c = (_b = collection.metadata) === null || _b === void 0 ? void 0 : _b.description) !== null && _c !== void 0 ? _c : '',
301
- seo: {
302
- title: (_d = collection.title) !== null && _d !== void 0 ? _d : '',
303
- description: (_f = (_e = collection.metadata) === null || _e === void 0 ? void 0 : _e.description) !== null && _f !== void 0 ? _f : '',
304
- },
305
- path: "/collections/".concat(collection.handle),
306
- updatedAt: typeof collection.updated_at === 'string'
307
- ? collection.updated_at
308
- : (_h = (_g = collection.updated_at) === null || _g === void 0 ? void 0 : _g.toISOString()) !== null && _h !== void 0 ? _h : new Date().toISOString(),
309
- };
310
- }
311
- /**
312
- * Transform Medusa ProductCategory to unified ProductCategory
313
- */
314
- function transformCategory(category) {
315
- var _a, _b, _c, _d, _e, _f, _g, _h;
316
- return {
317
- id: category.id,
318
- name: (_a = category.name) !== null && _a !== void 0 ? _a : '',
319
- handle: (_b = category.handle) !== null && _b !== void 0 ? _b : '',
320
- description: (_c = category.description) !== null && _c !== void 0 ? _c : undefined,
321
- parentCategoryId: (_d = category.parent_category_id) !== null && _d !== void 0 ? _d : undefined,
322
- productCount: (_e = category.product_count) !== null && _e !== void 0 ? _e : undefined,
323
- image: (_g = (_f = category.metadata) === null || _f === void 0 ? void 0 : _f.image) !== null && _g !== void 0 ? _g : undefined,
324
- metadata: (_h = category.metadata) !== null && _h !== void 0 ? _h : undefined,
325
- };
326
- }
327
- /**
328
- * Transform Medusa order status to unified OrderStatus
329
- */
330
- function transformOrderStatus(status) {
331
- // Medusa order statuses: pending, completed, archived, canceled, requires_action
332
- switch (status) {
333
- case 'pending':
334
- case 'requires_action':
335
- return 'pending';
336
- case 'completed':
337
- return 'completed';
338
- case 'canceled':
339
- return 'cancelled';
340
- case 'archived':
341
- // Archived could be completed or refunded, default to completed
342
- return 'completed';
343
- default:
344
- return 'processing';
345
- }
346
- }
347
- /**
348
- * Transform Medusa payment status to unified PaymentStatus
349
- */
350
- function transformPaymentStatus(status) {
351
- // Medusa payment statuses: not_paid, awaiting, captured, partially_refunded, refunded, canceled, requires_action
352
- if (!status || status === 'not_paid' || status === 'requires_action') {
353
- return 'pending';
354
- }
355
- if (status === 'awaiting') {
356
- return 'authorized';
357
- }
358
- if (status === 'captured') {
359
- return 'paid';
360
- }
361
- if (status === 'partially_refunded') {
362
- return 'partially_refunded';
363
- }
364
- if (status === 'refunded') {
365
- return 'refunded';
366
- }
367
- return 'pending';
368
- }
369
- /**
370
- * Transform Medusa fulfillment status to unified FulfillmentStatus
371
- */
372
- function transformFulfillmentStatus(status) {
373
- // Medusa fulfillment statuses: not_fulfilled, partially_fulfilled, fulfilled,
374
- // partially_shipped, shipped, partially_returned, returned, canceled, requires_action
375
- if (!status || status === 'not_fulfilled' || status === 'canceled') {
376
- return 'unfulfilled';
377
- }
378
- if (status === 'partially_fulfilled' || status === 'partially_shipped') {
379
- return 'partially_fulfilled';
380
- }
381
- if (status === 'fulfilled' || status === 'shipped') {
382
- return 'fulfilled';
383
- }
384
- if (status === 'returned' || status === 'partially_returned') {
385
- return 'returned';
386
- }
387
- return 'unfulfilled';
388
- }
389
- /**
390
- * Transform Medusa LineItem to unified OrderItem
391
- */
392
- function transformOrderItem(item, currencyCode) {
393
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
394
- var variant = item.variant;
395
- var product = variant === null || variant === void 0 ? void 0 : variant.product;
396
- return {
397
- id: item.id,
398
- title: (_b = (_a = item.product_title) !== null && _a !== void 0 ? _a : item.title) !== null && _b !== void 0 ? _b : '',
399
- variantTitle: (_d = (_c = item.variant_title) !== null && _c !== void 0 ? _c : variant === null || variant === void 0 ? void 0 : variant.title) !== null && _d !== void 0 ? _d : undefined,
400
- quantity: (_e = item.quantity) !== null && _e !== void 0 ? _e : 1,
401
- price: transformMoney(item.unit_price, currencyCode),
402
- total: transformMoney(item.total, currencyCode),
403
- sku: (_f = variant === null || variant === void 0 ? void 0 : variant.sku) !== null && _f !== void 0 ? _f : undefined,
404
- image: (product === null || product === void 0 ? void 0 : product.thumbnail) || item.thumbnail
405
- ? transformImage((product === null || product === void 0 ? void 0 : product.thumbnail) || item.thumbnail, (_g = item.product_title) !== null && _g !== void 0 ? _g : '')
406
- : undefined,
407
- productId: (_j = (_h = item.product_id) !== null && _h !== void 0 ? _h : product === null || product === void 0 ? void 0 : product.id) !== null && _j !== void 0 ? _j : undefined,
408
- variantId: (_l = (_k = item.variant_id) !== null && _k !== void 0 ? _k : variant === null || variant === void 0 ? void 0 : variant.id) !== null && _l !== void 0 ? _l : undefined,
409
- };
410
- }
411
- /**
412
- * Transform Medusa Address (snake_case) to unified Address (camelCase)
413
- */
414
- function transformAddress(address) {
415
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
416
- return {
417
- id: (_a = address.id) !== null && _a !== void 0 ? _a : undefined,
418
- firstName: (_b = address.first_name) !== null && _b !== void 0 ? _b : '',
419
- lastName: (_c = address.last_name) !== null && _c !== void 0 ? _c : '',
420
- company: (_d = address.company) !== null && _d !== void 0 ? _d : undefined,
421
- address1: (_e = address.address_1) !== null && _e !== void 0 ? _e : '',
422
- address2: (_f = address.address_2) !== null && _f !== void 0 ? _f : undefined,
423
- city: (_g = address.city) !== null && _g !== void 0 ? _g : '',
424
- province: (_h = address.province) !== null && _h !== void 0 ? _h : '',
425
- postalCode: (_j = address.postal_code) !== null && _j !== void 0 ? _j : '',
426
- countryCode: (_k = address.country_code) !== null && _k !== void 0 ? _k : '',
427
- phone: (_l = address.phone) !== null && _l !== void 0 ? _l : undefined,
428
- };
429
- }
430
- /**
431
- * Transform Medusa Customer (snake_case) to unified Customer (camelCase)
432
- */
433
- function transformCustomer(customer, email) {
434
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
435
- return {
436
- id: customer.id,
437
- email: (_b = (_a = customer.email) !== null && _a !== void 0 ? _a : email) !== null && _b !== void 0 ? _b : '',
438
- firstName: (_c = customer.first_name) !== null && _c !== void 0 ? _c : '',
439
- lastName: (_d = customer.last_name) !== null && _d !== void 0 ? _d : '',
440
- phone: (_e = customer.phone) !== null && _e !== void 0 ? _e : undefined,
441
- hasAccount: (_f = customer.has_account) !== null && _f !== void 0 ? _f : false,
442
- createdAt: typeof customer.created_at === 'string'
443
- ? customer.created_at
444
- : (_h = (_g = customer.created_at) === null || _g === void 0 ? void 0 : _g.toISOString()) !== null && _h !== void 0 ? _h : undefined,
445
- updatedAt: typeof customer.updated_at === 'string'
446
- ? customer.updated_at
447
- : (_k = (_j = customer.updated_at) === null || _j === void 0 ? void 0 : _j.toISOString()) !== null && _k !== void 0 ? _k : undefined,
448
- metadata: (_l = customer.metadata) !== null && _l !== void 0 ? _l : undefined,
449
- };
450
- }
451
- /**
452
- * Transform Medusa Order to unified Order
453
- */
454
- function transformOrder(order) {
455
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
456
- var currencyCode = (_a = order.currency_code) !== null && _a !== void 0 ? _a : 'usd';
457
- return {
458
- id: order.id,
459
- orderNumber: (_c = (_b = order.display_id) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : order.id,
460
- email: (_d = order.email) !== null && _d !== void 0 ? _d : '',
461
- // Status (3 separate statuses)
462
- status: transformOrderStatus(order.status),
463
- paymentStatus: transformPaymentStatus(order.payment_status),
464
- fulfillmentStatus: transformFulfillmentStatus(order.fulfillment_status),
465
- // Customer
466
- customerId: (_e = order.customer_id) !== null && _e !== void 0 ? _e : undefined,
467
- customer: order.customer
468
- ? transformCustomer(order.customer, order.email)
469
- : undefined,
470
- // Items
471
- items: (_g = (_f = order.items) === null || _f === void 0 ? void 0 : _f.map(function (item) { return transformOrderItem(item, currencyCode); })) !== null && _g !== void 0 ? _g : [],
472
- // Pricing
473
- subtotal: transformMoney(order.subtotal, currencyCode),
474
- total: transformMoney(order.total, currencyCode),
475
- tax: transformMoney(order.tax_total, currencyCode),
476
- shipping: transformMoney(order.shipping_total, currencyCode),
477
- discount: transformMoney(order.discount_total, currencyCode),
478
- // Addresses (transformed to camelCase)
479
- shippingAddress: order.shipping_address
480
- ? transformAddress(order.shipping_address)
481
- : undefined,
482
- billingAddress: order.billing_address
483
- ? transformAddress(order.billing_address)
484
- : undefined,
485
- // Dates
486
- createdAt: typeof order.created_at === 'string'
487
- ? order.created_at
488
- : (_j = (_h = order.created_at) === null || _h === void 0 ? void 0 : _h.toISOString()) !== null && _j !== void 0 ? _j : new Date().toISOString(),
489
- updatedAt: typeof order.updated_at === 'string'
490
- ? order.updated_at
491
- : (_l = (_k = order.updated_at) === null || _k === void 0 ? void 0 : _k.toISOString()) !== null && _l !== void 0 ? _l : new Date().toISOString(),
492
- completedAt: order.completed_at
493
- ? (typeof order.completed_at === 'string'
494
- ? order.completed_at
495
- : (_m = order.completed_at) === null || _m === void 0 ? void 0 : _m.toISOString())
496
- : undefined,
497
- cancelledAt: order.canceled_at
498
- ? (typeof order.canceled_at === 'string'
499
- ? order.canceled_at
500
- : (_o = order.canceled_at) === null || _o === void 0 ? void 0 : _o.toISOString())
501
- : undefined,
502
- // Platform-specific metadata
503
- metadata: (_p = order.metadata) !== null && _p !== void 0 ? _p : undefined,
504
- };
505
- }