@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,267 +0,0 @@
1
- /**
2
- * Magento GraphQL Queries for Storefront
3
- * Used by MagentoProvider to query products, categories, cart, and customer data.
4
- */
5
-
6
- export const PRODUCT_FIELDS = `
7
- id
8
- uid
9
- sku
10
- name
11
- url_key
12
- stock_status
13
- short_description { html }
14
- description { html }
15
- meta_title
16
- meta_description
17
- created_at
18
- updated_at
19
- price_range {
20
- minimum_price {
21
- regular_price { value currency }
22
- final_price { value currency }
23
- }
24
- maximum_price {
25
- regular_price { value currency }
26
- final_price { value currency }
27
- }
28
- }
29
- small_image { url label }
30
- image { url label }
31
- media_gallery {
32
- url
33
- label
34
- }
35
- ... on ConfigurableProduct {
36
- configurable_options {
37
- attribute_code
38
- attribute_id
39
- label
40
- values {
41
- label
42
- value_index
43
- }
44
- }
45
- variants {
46
- product {
47
- id uid sku name
48
- stock_status
49
- price_range {
50
- minimum_price {
51
- final_price { value currency }
52
- }
53
- }
54
- small_image { url label }
55
- }
56
- attributes {
57
- label
58
- value_index
59
- }
60
- }
61
- }
62
- `;
63
-
64
- export const GET_PRODUCTS = `
65
- query GetProducts($search: String, $pageSize: Int, $currentPage: Int, $sort: ProductAttributeSortInput) {
66
- products(search: $search, pageSize: $pageSize, currentPage: $currentPage, sort: $sort) {
67
- items { ${PRODUCT_FIELDS} }
68
- total_count
69
- }
70
- }
71
- `;
72
-
73
- export const GET_PRODUCT_BY_URL_KEY = `
74
- query GetProductByUrlKey($urlKey: String!) {
75
- products(filter: { url_key: { eq: $urlKey } }, pageSize: 1) {
76
- items { ${PRODUCT_FIELDS} }
77
- }
78
- }
79
- `;
80
-
81
- export const GET_CATEGORIES = `
82
- query GetCategories($pageSize: Int) {
83
- categories(pageSize: $pageSize) {
84
- items {
85
- id uid name url_key url_path description meta_title meta_description
86
- }
87
- }
88
- }
89
- `;
90
-
91
- export const GET_CATEGORY_BY_URL_KEY = `
92
- query GetCategoryByUrlKey($urlKey: String!) {
93
- categories(filters: { url_key: { eq: $urlKey } }, pageSize: 1) {
94
- items {
95
- id uid name url_key url_path description meta_title meta_description
96
- }
97
- }
98
- }
99
- `;
100
-
101
- export const GET_CATEGORY_PRODUCTS = `
102
- query GetCategoryProducts($urlKey: String!, $pageSize: Int) {
103
- products(filter: { category_url_key: { eq: $urlKey } }, pageSize: $pageSize) {
104
- items { ${PRODUCT_FIELDS} }
105
- total_count
106
- }
107
- }
108
- `;
109
-
110
- export const GET_CART = `
111
- query GetCart($cartId: String!) {
112
- cart(cart_id: $cartId) {
113
- id
114
- items {
115
- id uid quantity
116
- product {
117
- id uid sku name url_key
118
- small_image { url }
119
- thumbnail { url }
120
- price_range {
121
- minimum_price {
122
- final_price { value currency }
123
- }
124
- }
125
- }
126
- prices {
127
- price { value currency }
128
- row_total { value currency }
129
- }
130
- ... on ConfigurableCartItem {
131
- configurable_options {
132
- option_label
133
- value_label
134
- }
135
- }
136
- }
137
- prices {
138
- grand_total { value currency }
139
- subtotal_excluding_tax { value currency }
140
- subtotal_including_tax { value currency }
141
- applied_taxes {
142
- amount { value currency }
143
- label
144
- }
145
- }
146
- }
147
- }
148
- `;
149
-
150
- export const CREATE_EMPTY_CART = `
151
- mutation CreateEmptyCart {
152
- createEmptyCart
153
- }
154
- `;
155
-
156
- export const ADD_TO_CART = `
157
- mutation AddToCart($cartId: String!, $cartItems: [CartItemInput!]!) {
158
- addProductsToCart(cartId: $cartId, cartItems: $cartItems) {
159
- cart {
160
- id
161
- items { id uid quantity product { sku name } prices { price { value currency } row_total { value currency } } }
162
- prices { grand_total { value currency } subtotal_excluding_tax { value currency } }
163
- }
164
- user_errors { code message }
165
- }
166
- }
167
- `;
168
-
169
- export const REMOVE_FROM_CART = `
170
- mutation RemoveFromCart($cartId: String!, $cartItemUid: ID!) {
171
- removeItemFromCart(input: { cart_id: $cartId, cart_item_uid: $cartItemUid }) {
172
- cart {
173
- id
174
- items { id uid quantity product { sku name } prices { price { value currency } row_total { value currency } } }
175
- prices { grand_total { value currency } subtotal_excluding_tax { value currency } }
176
- }
177
- }
178
- }
179
- `;
180
-
181
- export const UPDATE_CART_ITEMS = `
182
- mutation UpdateCartItems($cartId: String!, $cartItems: [CartItemUpdateInput!]!) {
183
- updateCartItems(input: { cart_id: $cartId, cart_items: $cartItems }) {
184
- cart {
185
- id
186
- items { id uid quantity product { sku name } prices { price { value currency } row_total { value currency } } }
187
- prices { grand_total { value currency } subtotal_excluding_tax { value currency } }
188
- }
189
- }
190
- }
191
- `;
192
-
193
- export const APPLY_COUPON = `
194
- mutation ApplyCoupon($cartId: String!, $couponCode: String!) {
195
- applyCouponToCart(input: { cart_id: $cartId, coupon_code: $couponCode }) {
196
- cart {
197
- id
198
- prices { grand_total { value currency } subtotal_excluding_tax { value currency } }
199
- }
200
- }
201
- }
202
- `;
203
-
204
- export const REMOVE_COUPON = `
205
- mutation RemoveCoupon($cartId: String!) {
206
- removeCouponFromCart(input: { cart_id: $cartId }) {
207
- cart {
208
- id
209
- prices { grand_total { value currency } subtotal_excluding_tax { value currency } }
210
- }
211
- }
212
- }
213
- `;
214
-
215
- export const GET_CUSTOMER = `
216
- query GetCustomer {
217
- customer {
218
- id
219
- email
220
- firstname
221
- lastname
222
- addresses {
223
- id
224
- firstname lastname company
225
- street city
226
- region { region region_code }
227
- postcode
228
- country_code
229
- telephone
230
- default_shipping
231
- default_billing
232
- }
233
- }
234
- }
235
- `;
236
-
237
- export const GET_CUSTOMER_ORDERS = `
238
- query GetCustomerOrders($pageSize: Int, $currentPage: Int) {
239
- customer {
240
- orders(pageSize: $pageSize, currentPage: $currentPage) {
241
- items {
242
- id order_number order_date status
243
- total {
244
- grand_total { value currency }
245
- subtotal { value currency }
246
- total_tax { value currency }
247
- total_shipping { value currency }
248
- }
249
- items {
250
- id product_name product_sku
251
- quantity_ordered
252
- product_sale_price { value currency }
253
- }
254
- shipping_address {
255
- firstname lastname street city
256
- region postcode country_code telephone
257
- }
258
- billing_address {
259
- firstname lastname street city
260
- region postcode country_code telephone
261
- }
262
- }
263
- total_count
264
- }
265
- }
266
- }
267
- `;
@@ -1,249 +0,0 @@
1
- /**
2
- * Adobe Commerce (Magento) Transform Functions
3
- * Converts Magento GraphQL / REST API responses to @thorprovider/types
4
- *
5
- * Magento returns price as { regularPrice: { amount: { value, currency } } }
6
- * Images have url + label directly.
7
- */
8
-
9
- import type { Product, ProductVariant, ProductOption, Image, Collection, Cart, CartItem, Order, OrderItem, Customer, Address, Money } from '@thorprovider/types';
10
-
11
- // ============================================
12
- // Money / Price Helpers
13
- // ============================================
14
-
15
- function toMoney(value: number | undefined, currencyCode: string): Money {
16
- return { amount: (value ?? 0).toFixed(2), currencyCode };
17
- }
18
-
19
- function extractPrice(priceRange: any, currencyCode: string): { min: Money; max: Money } {
20
- const minPrice = priceRange?.minimum_price?.regular_price?.value ?? priceRange?.minimum_price?.final_price?.value ?? 0;
21
- const maxPrice = priceRange?.maximum_price?.regular_price?.value ?? priceRange?.maximum_price?.final_price?.value ?? minPrice;
22
- const currency = priceRange?.minimum_price?.regular_price?.currency ?? currencyCode;
23
- return {
24
- min: toMoney(minPrice, currency),
25
- max: toMoney(maxPrice, currency),
26
- };
27
- }
28
-
29
- // ============================================
30
- // Product Transforms
31
- // ============================================
32
-
33
- export function transformProduct(data: any, currencyCode: string = 'USD'): Product {
34
- const id = String(data.id ?? data.uid ?? '');
35
- const { min, max } = extractPrice(data.price_range, currencyCode);
36
-
37
- // Images
38
- const images: Image[] = (data.media_gallery ?? data.media_gallery_entries ?? []).map((img: any) => ({
39
- url: img.url ?? (img.file ? `${img.file}` : ''),
40
- altText: img.label ?? data.name ?? '',
41
- width: undefined,
42
- height: undefined,
43
- }));
44
-
45
- // Small image fallback
46
- if (images.length === 0 && data.small_image?.url) {
47
- images.push({ url: data.small_image.url, altText: data.small_image.label ?? data.name ?? '' });
48
- }
49
- if (images.length === 0 && data.image?.url) {
50
- images.push({ url: data.image.url, altText: data.image.label ?? data.name ?? '' });
51
- }
52
-
53
- // Variants from configurable_options / variants
54
- const variants: ProductVariant[] = [];
55
- if (data.variants && Array.isArray(data.variants)) {
56
- for (const v of data.variants) {
57
- const product = v.product ?? {};
58
- const vPrice = product.price_range?.minimum_price?.final_price ?? {};
59
- variants.push({
60
- id: String(product.id ?? product.uid ?? product.sku ?? ''),
61
- title: product.name ?? product.sku ?? '',
62
- availableForSale: product.stock_status === 'IN_STOCK',
63
- price: toMoney(vPrice.value ?? min.amount, vPrice.currency ?? currencyCode),
64
- compareAtPrice: undefined,
65
- selectedOptions: (v.attributes ?? []).map((attr: any) => ({
66
- name: attr.label ?? '',
67
- value: attr.value_index != null ? String(attr.value_index) : '',
68
- })),
69
- });
70
- }
71
- }
72
-
73
- // Default variant if simple product
74
- if (variants.length === 0) {
75
- variants.push({
76
- id: data.sku ?? id,
77
- title: data.name ?? '',
78
- availableForSale: data.stock_status === 'IN_STOCK',
79
- price: min,
80
- compareAtPrice: undefined,
81
- selectedOptions: [],
82
- });
83
- }
84
-
85
- // Options
86
- const options: ProductOption[] = (data.configurable_options ?? []).map((opt: any) => ({
87
- id: String(opt.attribute_id ?? opt.attribute_code ?? ''),
88
- name: opt.label ?? opt.attribute_code ?? '',
89
- values: (opt.values ?? []).map((v: any) => v.label ?? v.store_label ?? String(v.value_index ?? '')),
90
- }));
91
-
92
- return {
93
- id,
94
- handle: data.url_key ?? data.sku ?? id,
95
- title: data.name ?? '',
96
- description: data.short_description?.html ?? data.description?.html ?? '',
97
- descriptionHtml: data.description?.html ?? '',
98
- availableForSale: data.stock_status === 'IN_STOCK',
99
- priceRange: { minVariantPrice: min, maxVariantPrice: max },
100
- variants,
101
- options,
102
- images,
103
- featuredImage: images[0] ?? { url: '', altText: data.name ?? '' },
104
- tags: [],
105
- seo: {
106
- title: data.meta_title ?? data.name ?? '',
107
- description: data.meta_description ?? '',
108
- },
109
- updatedAt: data.updated_at ?? new Date().toISOString(),
110
- createdAt: data.created_at ?? new Date().toISOString(),
111
- };
112
- }
113
-
114
- // ============================================
115
- // Collection Transforms (Magento Categories)
116
- // ============================================
117
-
118
- export function transformCollection(data: any): Collection {
119
- return {
120
- id: String(data.id ?? data.uid ?? ''),
121
- handle: data.url_key ?? data.url_path ?? String(data.id ?? data.uid ?? ''),
122
- title: data.name ?? '',
123
- description: data.description ?? '',
124
- seo: {
125
- title: data.meta_title ?? data.name ?? '',
126
- description: data.meta_description ?? '',
127
- },
128
- updatedAt: data.updated_at ?? new Date().toISOString(),
129
- path: `/collections/${data.url_key ?? data.url_path ?? data.id}`,
130
- };
131
- }
132
-
133
- // ============================================
134
- // Cart Transforms (Magento Cart / Quote)
135
- // ============================================
136
-
137
- export function transformCart(data: any, currencyCode: string = 'USD'): Cart {
138
- const items: CartItem[] = (data.items ?? []).map((item: any): CartItem => {
139
- const product = item.product ?? {};
140
- const priceVal = item.prices?.price?.value ?? product.price_range?.minimum_price?.final_price?.value ?? 0;
141
- const totalVal = item.prices?.row_total?.value ?? priceVal * (item.quantity ?? 1);
142
-
143
- return {
144
- id: String(item.id ?? item.uid ?? ''),
145
- quantity: item.quantity ?? 1,
146
- cost: {
147
- totalAmount: toMoney(totalVal, item.prices?.price?.currency ?? currencyCode),
148
- },
149
- merchandise: {
150
- id: String(product.sku ?? item.id ?? ''),
151
- title: product.name ?? item.product?.name ?? '',
152
- selectedOptions: (item.configurable_options ?? []).map((opt: any) => ({
153
- name: opt.option_label ?? '',
154
- value: opt.value_label ?? '',
155
- })),
156
- product: {
157
- id: String(product.id ?? product.uid ?? ''),
158
- handle: product.url_key ?? '',
159
- title: product.name ?? '',
160
- featuredImage: {
161
- url: product.small_image?.url ?? product.thumbnail?.url ?? '',
162
- altText: product.name ?? '',
163
- },
164
- },
165
- },
166
- };
167
- });
168
-
169
- const totalVal = data.prices?.grand_total?.value ?? 0;
170
- const subtotalVal = data.prices?.subtotal_excluding_tax?.value ?? data.prices?.subtotal_including_tax?.value ?? totalVal;
171
- const taxVal = (data.prices?.applied_taxes ?? []).reduce((sum: number, t: any) => sum + (t.amount?.value ?? 0), 0);
172
-
173
- return {
174
- id: String(data.id ?? ''),
175
- checkoutUrl: '',
176
- totalQuantity: items.reduce((sum, i) => sum + i.quantity, 0),
177
- cost: {
178
- subtotalAmount: toMoney(subtotalVal, data.prices?.grand_total?.currency ?? currencyCode),
179
- totalAmount: toMoney(totalVal, data.prices?.grand_total?.currency ?? currencyCode),
180
- totalTaxAmount: toMoney(taxVal, currencyCode),
181
- },
182
- lines: items,
183
- };
184
- }
185
-
186
- // ============================================
187
- // Customer Transforms
188
- // ============================================
189
-
190
- export function transformCustomer(data: any): Customer {
191
- return {
192
- id: String(data.id ?? ''),
193
- email: data.email ?? '',
194
- firstName: data.firstname ?? data.first_name ?? '',
195
- lastName: data.lastname ?? data.last_name ?? '',
196
- phone: data.phone ?? '',
197
- hasAccount: true,
198
- };
199
- }
200
-
201
- function transformAddress(addr: any): Address {
202
- return {
203
- id: String(addr.id ?? ''),
204
- firstName: addr.firstname ?? '',
205
- lastName: addr.lastname ?? '',
206
- company: addr.company ?? '',
207
- address1: Array.isArray(addr.street) ? addr.street[0] ?? '' : addr.street ?? '',
208
- address2: Array.isArray(addr.street) ? addr.street[1] ?? '' : '',
209
- city: addr.city ?? '',
210
- province: addr.region?.region ?? '',
211
- postalCode: addr.postcode ?? '',
212
- countryCode: addr.country_code ?? addr.country_id ?? '',
213
- phone: addr.telephone ?? '',
214
- };
215
- }
216
-
217
- // ============================================
218
- // Order Transforms
219
- // ============================================
220
-
221
- export function transformOrder(data: any, currencyCode: string = 'USD'): Order {
222
- const items: OrderItem[] = (data.items ?? []).map((item: any) => ({
223
- id: String(item.id ?? ''),
224
- title: item.product_name ?? '',
225
- quantity: item.quantity_ordered ?? item.quantity ?? 1,
226
- price: toMoney(item.product_sale_price?.value ?? item.price ?? 0, currencyCode),
227
- total: toMoney((item.product_sale_price?.value ?? item.price ?? 0) * (item.quantity_ordered ?? item.quantity ?? 1), currencyCode),
228
- sku: item.product_sku ?? item.sku,
229
- productId: String(item.product_id ?? ''),
230
- }));
231
-
232
- return {
233
- id: String(data.id ?? data.order_number ?? ''),
234
- orderNumber: data.order_number ?? data.number ?? String(data.id ?? ''),
235
- email: data.email ?? '',
236
- status: (data.status === 'complete' ? 'completed' : data.status === 'canceled' ? 'cancelled' : data.status === 'closed' ? 'refunded' : 'pending') as any,
237
- paymentStatus: (data.payment_status === 'paid' ? 'paid' : 'pending') as any,
238
- fulfillmentStatus: (data.shipment_status === 'shipped' ? 'fulfilled' : 'unfulfilled') as any,
239
- items,
240
- total: toMoney(data.total?.grand_total?.value ?? data.grand_total ?? 0, currencyCode),
241
- subtotal: toMoney(data.total?.subtotal?.value ?? data.subtotal ?? 0, currencyCode),
242
- tax: toMoney(data.total?.total_tax?.value ?? data.tax_amount ?? 0, currencyCode),
243
- shipping: toMoney(data.total?.total_shipping?.value ?? data.shipping_amount ?? 0, currencyCode),
244
- shippingAddress: data.shipping_address ? transformAddress(data.shipping_address) : undefined,
245
- billingAddress: data.billing_address ? transformAddress(data.billing_address) : undefined,
246
- createdAt: data.order_date ?? data.created_at ?? new Date().toISOString(),
247
- updatedAt: data.updated_at ?? data.order_date ?? new Date().toISOString(),
248
- };
249
- }