@thorprovider/adapters 5.0.0 → 5.0.2
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/AGENTS.md +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +53 -631
- package/dist/index.d.mts +406 -194
- package/dist/index.d.ts +406 -194
- package/dist/index.js +3092 -604
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3081 -602
- package/dist/index.mjs.map +1 -1
- package/docs/RETRY_SOLUTION_SUMMARY.md +1 -1
- package/docs/authentication.md +0 -26
- package/docs/capabilities-system.md +66 -36
- package/docs/getting-started.md +1 -1
- package/docs/providers-overview.md +16 -13
- package/docs/update-documentation.md +10 -8
- package/package.json +6 -5
- package/quick-reference.md +0 -33
- package/src/backend/factory.ts +11 -1
- package/src/factory/index.ts +52 -74
- package/src/index.ts +17 -3
- package/src/providers/bigcommerce/bigcommerce.ts +6 -0
- package/src/providers/bigcommerce/index.ts +315 -0
- package/src/providers/bigcommerce/transforms.ts +227 -0
- package/src/providers/index.ts +16 -1
- package/src/providers/magento/index.ts +387 -0
- package/src/providers/magento/magento.ts +5 -0
- package/src/providers/magento/queries.ts +267 -0
- package/src/providers/magento/transforms.ts +249 -0
- package/src/providers/medusa/auth.test.ts +94 -92
- package/src/providers/medusa/auth.ts +72 -123
- package/src/providers/medusa/index.test.ts +392 -0
- package/src/providers/medusa/index.ts +1 -21
- package/src/providers/medusa/live-smoke.test.ts +412 -0
- package/src/providers/shopify/auth.ts +402 -0
- package/src/providers/shopify/index.ts +444 -0
- package/src/providers/shopify/mutations.ts +247 -0
- package/src/providers/shopify/queries.ts +324 -0
- package/src/providers/shopify/shopify.ts +7 -0
- package/src/providers/shopify/transforms.ts +275 -0
- package/src/providers/spree/index.ts +344 -0
- package/src/providers/spree/spree.ts +5 -0
- package/src/providers/spree/transforms.ts +254 -0
- package/src/providers/woocommerce/index.ts +310 -0
- package/src/providers/woocommerce/transforms.ts +254 -0
- package/src/providers/woocommerce/woocommerce.ts +5 -0
- package/src/types/capabilities.types.ts +250 -0
- package/vitest.live.config.ts +18 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thorprovider/adapters — Shopify Provider
|
|
3
|
+
* GraphQL query definitions for Storefront API
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const PRODUCT_FRAGMENT = `
|
|
7
|
+
fragment ProductFields on Product {
|
|
8
|
+
id
|
|
9
|
+
title
|
|
10
|
+
handle
|
|
11
|
+
description
|
|
12
|
+
descriptionHtml
|
|
13
|
+
vendor
|
|
14
|
+
productType
|
|
15
|
+
tags
|
|
16
|
+
availableForSale
|
|
17
|
+
createdAt
|
|
18
|
+
updatedAt
|
|
19
|
+
seo {
|
|
20
|
+
title
|
|
21
|
+
description
|
|
22
|
+
}
|
|
23
|
+
featuredImage {
|
|
24
|
+
url
|
|
25
|
+
altText
|
|
26
|
+
width
|
|
27
|
+
height
|
|
28
|
+
}
|
|
29
|
+
images(first: 10) {
|
|
30
|
+
edges {
|
|
31
|
+
node {
|
|
32
|
+
url
|
|
33
|
+
altText
|
|
34
|
+
width
|
|
35
|
+
height
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
priceRange {
|
|
40
|
+
minVariantPrice {
|
|
41
|
+
amount
|
|
42
|
+
currencyCode
|
|
43
|
+
}
|
|
44
|
+
maxVariantPrice {
|
|
45
|
+
amount
|
|
46
|
+
currencyCode
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
options {
|
|
50
|
+
id
|
|
51
|
+
name
|
|
52
|
+
values
|
|
53
|
+
}
|
|
54
|
+
variants(first: 100) {
|
|
55
|
+
edges {
|
|
56
|
+
node {
|
|
57
|
+
id
|
|
58
|
+
title
|
|
59
|
+
availableForSale
|
|
60
|
+
price {
|
|
61
|
+
amount
|
|
62
|
+
currencyCode
|
|
63
|
+
}
|
|
64
|
+
compareAtPrice {
|
|
65
|
+
amount
|
|
66
|
+
currencyCode
|
|
67
|
+
}
|
|
68
|
+
selectedOptions {
|
|
69
|
+
name
|
|
70
|
+
value
|
|
71
|
+
}
|
|
72
|
+
image {
|
|
73
|
+
url
|
|
74
|
+
altText
|
|
75
|
+
width
|
|
76
|
+
height
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
export const GET_PRODUCT_BY_HANDLE = `
|
|
85
|
+
query GetProductByHandle($handle: String!) {
|
|
86
|
+
product(handle: $handle) {
|
|
87
|
+
...ProductFields
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
${PRODUCT_FRAGMENT}
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
export const GET_PRODUCTS = `
|
|
94
|
+
query GetProducts($first: Int!, $query: String, $sortKey: ProductSortKeys, $reverse: Boolean, $after: String) {
|
|
95
|
+
products(first: $first, query: $query, sortKey: $sortKey, reverse: $reverse, after: $after) {
|
|
96
|
+
edges {
|
|
97
|
+
node {
|
|
98
|
+
...ProductFields
|
|
99
|
+
}
|
|
100
|
+
cursor
|
|
101
|
+
}
|
|
102
|
+
pageInfo {
|
|
103
|
+
hasNextPage
|
|
104
|
+
hasPreviousPage
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
${PRODUCT_FRAGMENT}
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
export const GET_PRODUCT_RECOMMENDATIONS = `
|
|
112
|
+
query GetProductRecommendations($productId: ID!) {
|
|
113
|
+
productRecommendations(productId: $productId) {
|
|
114
|
+
...ProductFields
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
${PRODUCT_FRAGMENT}
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
export const COLLECTION_FRAGMENT = `
|
|
121
|
+
fragment CollectionFields on Collection {
|
|
122
|
+
id
|
|
123
|
+
title
|
|
124
|
+
handle
|
|
125
|
+
description
|
|
126
|
+
image {
|
|
127
|
+
url
|
|
128
|
+
altText
|
|
129
|
+
width
|
|
130
|
+
height
|
|
131
|
+
}
|
|
132
|
+
seo {
|
|
133
|
+
title
|
|
134
|
+
description
|
|
135
|
+
}
|
|
136
|
+
updatedAt
|
|
137
|
+
}
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
export const GET_COLLECTION_BY_HANDLE = `
|
|
141
|
+
query GetCollectionByHandle($handle: String!) {
|
|
142
|
+
collection(handle: $handle) {
|
|
143
|
+
...CollectionFields
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
${COLLECTION_FRAGMENT}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
export const GET_COLLECTIONS = `
|
|
150
|
+
query GetCollections($first: Int!) {
|
|
151
|
+
collections(first: $first) {
|
|
152
|
+
edges {
|
|
153
|
+
node {
|
|
154
|
+
...CollectionFields
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
${COLLECTION_FRAGMENT}
|
|
160
|
+
`;
|
|
161
|
+
|
|
162
|
+
export const GET_COLLECTION_PRODUCTS = `
|
|
163
|
+
query GetCollectionProducts($handle: String!, $first: Int!, $sortKey: ProductCollectionSortKeys, $reverse: Boolean, $after: String) {
|
|
164
|
+
collection(handle: $handle) {
|
|
165
|
+
products(first: $first, sortKey: $sortKey, reverse: $reverse, after: $after) {
|
|
166
|
+
edges {
|
|
167
|
+
node {
|
|
168
|
+
...ProductFields
|
|
169
|
+
}
|
|
170
|
+
cursor
|
|
171
|
+
}
|
|
172
|
+
pageInfo {
|
|
173
|
+
hasNextPage
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
${PRODUCT_FRAGMENT}
|
|
179
|
+
`;
|
|
180
|
+
|
|
181
|
+
export const CART_FRAGMENT = `
|
|
182
|
+
fragment CartFields on Cart {
|
|
183
|
+
id
|
|
184
|
+
checkoutUrl
|
|
185
|
+
totalQuantity
|
|
186
|
+
cost {
|
|
187
|
+
subtotalAmount {
|
|
188
|
+
amount
|
|
189
|
+
currencyCode
|
|
190
|
+
}
|
|
191
|
+
totalAmount {
|
|
192
|
+
amount
|
|
193
|
+
currencyCode
|
|
194
|
+
}
|
|
195
|
+
totalTaxAmount {
|
|
196
|
+
amount
|
|
197
|
+
currencyCode
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
lines(first: 100) {
|
|
201
|
+
edges {
|
|
202
|
+
node {
|
|
203
|
+
id
|
|
204
|
+
quantity
|
|
205
|
+
cost {
|
|
206
|
+
totalAmount {
|
|
207
|
+
amount
|
|
208
|
+
currencyCode
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
merchandise {
|
|
212
|
+
... on ProductVariant {
|
|
213
|
+
id
|
|
214
|
+
title
|
|
215
|
+
selectedOptions {
|
|
216
|
+
name
|
|
217
|
+
value
|
|
218
|
+
}
|
|
219
|
+
product {
|
|
220
|
+
id
|
|
221
|
+
handle
|
|
222
|
+
title
|
|
223
|
+
featuredImage {
|
|
224
|
+
url
|
|
225
|
+
altText
|
|
226
|
+
width
|
|
227
|
+
height
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
`;
|
|
237
|
+
|
|
238
|
+
export const GET_CART = `
|
|
239
|
+
query GetCart($cartId: ID!) {
|
|
240
|
+
cart(id: $cartId) {
|
|
241
|
+
...CartFields
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
${CART_FRAGMENT}
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
export const GET_CUSTOMER = `
|
|
248
|
+
query GetCustomer {
|
|
249
|
+
customer {
|
|
250
|
+
id
|
|
251
|
+
firstName
|
|
252
|
+
lastName
|
|
253
|
+
email
|
|
254
|
+
phone
|
|
255
|
+
defaultAddress {
|
|
256
|
+
id
|
|
257
|
+
address1
|
|
258
|
+
address2
|
|
259
|
+
city
|
|
260
|
+
province
|
|
261
|
+
country
|
|
262
|
+
zip
|
|
263
|
+
phone
|
|
264
|
+
firstName
|
|
265
|
+
lastName
|
|
266
|
+
}
|
|
267
|
+
addresses(first: 20) {
|
|
268
|
+
edges {
|
|
269
|
+
node {
|
|
270
|
+
id
|
|
271
|
+
address1
|
|
272
|
+
address2
|
|
273
|
+
city
|
|
274
|
+
province
|
|
275
|
+
country
|
|
276
|
+
zip
|
|
277
|
+
phone
|
|
278
|
+
firstName
|
|
279
|
+
lastName
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
orders(first: 50) {
|
|
284
|
+
edges {
|
|
285
|
+
node {
|
|
286
|
+
id
|
|
287
|
+
orderNumber
|
|
288
|
+
processedAt
|
|
289
|
+
financialStatus
|
|
290
|
+
fulfillmentStatus
|
|
291
|
+
totalPrice {
|
|
292
|
+
amount
|
|
293
|
+
currencyCode
|
|
294
|
+
}
|
|
295
|
+
lineItems(first: 50) {
|
|
296
|
+
edges {
|
|
297
|
+
node {
|
|
298
|
+
title
|
|
299
|
+
quantity
|
|
300
|
+
variant {
|
|
301
|
+
id
|
|
302
|
+
title
|
|
303
|
+
price {
|
|
304
|
+
amount
|
|
305
|
+
currencyCode
|
|
306
|
+
}
|
|
307
|
+
image {
|
|
308
|
+
url
|
|
309
|
+
altText
|
|
310
|
+
}
|
|
311
|
+
product {
|
|
312
|
+
id
|
|
313
|
+
handle
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
`;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thorprovider/adapters — Shopify Provider
|
|
3
|
+
* Transform functions: Shopify GraphQL responses → @thorprovider/types
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
Product,
|
|
8
|
+
ProductVariant,
|
|
9
|
+
ProductOption,
|
|
10
|
+
Cart,
|
|
11
|
+
CartItem,
|
|
12
|
+
Collection,
|
|
13
|
+
Money,
|
|
14
|
+
Image,
|
|
15
|
+
Order,
|
|
16
|
+
OrderItem,
|
|
17
|
+
OrderStatus,
|
|
18
|
+
PaymentStatus,
|
|
19
|
+
FulfillmentStatus,
|
|
20
|
+
Customer,
|
|
21
|
+
Address,
|
|
22
|
+
} from '@thorprovider/types';
|
|
23
|
+
|
|
24
|
+
// ============================================
|
|
25
|
+
// Money & Image Transforms
|
|
26
|
+
// ============================================
|
|
27
|
+
|
|
28
|
+
function transformMoney(shopifyMoney: { amount: string; currencyCode: string } | null | undefined): Money {
|
|
29
|
+
return {
|
|
30
|
+
amount: shopifyMoney?.amount ?? '0.00',
|
|
31
|
+
currencyCode: shopifyMoney?.currencyCode?.toUpperCase() ?? 'USD',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function transformImage(shopifyImage: { url: string; altText?: string | null; width?: number; height?: number } | null | undefined): Image {
|
|
36
|
+
return {
|
|
37
|
+
url: shopifyImage?.url ?? '',
|
|
38
|
+
altText: shopifyImage?.altText ?? '',
|
|
39
|
+
width: shopifyImage?.width ?? 800,
|
|
40
|
+
height: shopifyImage?.height ?? 800,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ============================================
|
|
45
|
+
// Product Transforms
|
|
46
|
+
// ============================================
|
|
47
|
+
|
|
48
|
+
function transformVariant(raw: any): ProductVariant {
|
|
49
|
+
return {
|
|
50
|
+
id: raw.id,
|
|
51
|
+
title: raw.title ?? '',
|
|
52
|
+
availableForSale: raw.availableForSale ?? true,
|
|
53
|
+
price: transformMoney(raw.price),
|
|
54
|
+
compareAtPrice: raw.compareAtPrice ? transformMoney(raw.compareAtPrice) : undefined,
|
|
55
|
+
selectedOptions: (raw.selectedOptions ?? []).map((opt: any) => ({
|
|
56
|
+
name: opt.name,
|
|
57
|
+
value: opt.value,
|
|
58
|
+
})),
|
|
59
|
+
image: raw.image ? transformImage(raw.image) : undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function transformOption(raw: any): ProductOption {
|
|
64
|
+
return {
|
|
65
|
+
id: raw.id,
|
|
66
|
+
name: raw.name,
|
|
67
|
+
values: raw.values ?? [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function transformProduct(raw: any): Product {
|
|
72
|
+
const images = (raw.images?.edges ?? []).map((edge: any) => transformImage(edge.node));
|
|
73
|
+
const variants = (raw.variants?.edges ?? []).map((edge: any) => transformVariant(edge.node));
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
id: raw.id,
|
|
77
|
+
handle: raw.handle,
|
|
78
|
+
title: raw.title,
|
|
79
|
+
description: raw.description ?? '',
|
|
80
|
+
descriptionHtml: raw.descriptionHtml ?? '',
|
|
81
|
+
availableForSale: raw.availableForSale ?? true,
|
|
82
|
+
featuredImage: raw.featuredImage ? transformImage(raw.featuredImage) : (images[0] ?? { url: '', altText: '', width: 800, height: 800 }),
|
|
83
|
+
images,
|
|
84
|
+
options: (raw.options ?? []).map(transformOption),
|
|
85
|
+
variants,
|
|
86
|
+
priceRange: {
|
|
87
|
+
minVariantPrice: transformMoney(raw.priceRange?.minVariantPrice),
|
|
88
|
+
maxVariantPrice: transformMoney(raw.priceRange?.maxVariantPrice),
|
|
89
|
+
},
|
|
90
|
+
seo: {
|
|
91
|
+
title: raw.seo?.title ?? raw.title ?? '',
|
|
92
|
+
description: raw.seo?.description ?? raw.description ?? '',
|
|
93
|
+
},
|
|
94
|
+
tags: raw.tags ?? [],
|
|
95
|
+
createdAt: raw.createdAt ?? new Date().toISOString(),
|
|
96
|
+
updatedAt: raw.updatedAt ?? new Date().toISOString(),
|
|
97
|
+
vendor: raw.vendor,
|
|
98
|
+
productType: raw.productType,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ============================================
|
|
103
|
+
// Collection Transforms
|
|
104
|
+
// ============================================
|
|
105
|
+
|
|
106
|
+
export function transformCollection(raw: any): Collection {
|
|
107
|
+
return {
|
|
108
|
+
id: raw.id ?? '',
|
|
109
|
+
handle: raw.handle,
|
|
110
|
+
title: raw.title,
|
|
111
|
+
description: raw.description ?? '',
|
|
112
|
+
seo: {
|
|
113
|
+
title: raw.seo?.title ?? raw.title ?? '',
|
|
114
|
+
description: raw.seo?.description ?? raw.description ?? '',
|
|
115
|
+
},
|
|
116
|
+
updatedAt: raw.updatedAt ?? new Date().toISOString(),
|
|
117
|
+
path: `/collections/${raw.handle}`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ============================================
|
|
122
|
+
// Cart Transforms
|
|
123
|
+
// ============================================
|
|
124
|
+
|
|
125
|
+
function transformCartItem(raw: any): CartItem {
|
|
126
|
+
const merchandise = raw.merchandise ?? {};
|
|
127
|
+
const product = merchandise.product ?? {};
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
id: raw.id,
|
|
131
|
+
quantity: raw.quantity ?? 1,
|
|
132
|
+
cost: {
|
|
133
|
+
totalAmount: transformMoney(raw.cost?.totalAmount),
|
|
134
|
+
},
|
|
135
|
+
merchandise: {
|
|
136
|
+
id: merchandise.id ?? '',
|
|
137
|
+
title: merchandise.title ?? '',
|
|
138
|
+
selectedOptions: (merchandise.selectedOptions ?? []).map((opt: any) => ({
|
|
139
|
+
name: opt.name,
|
|
140
|
+
value: opt.value,
|
|
141
|
+
})),
|
|
142
|
+
product: {
|
|
143
|
+
id: product.id ?? '',
|
|
144
|
+
handle: product.handle ?? '',
|
|
145
|
+
title: product.title ?? '',
|
|
146
|
+
featuredImage: product.featuredImage
|
|
147
|
+
? transformImage(product.featuredImage)
|
|
148
|
+
: { url: '', altText: '', width: 800, height: 800 },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function transformCart(raw: any): Cart {
|
|
155
|
+
const lines = (raw.lines?.edges ?? []).map((edge: any) => transformCartItem(edge.node));
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
id: raw.id,
|
|
159
|
+
checkoutUrl: raw.checkoutUrl ?? '',
|
|
160
|
+
totalQuantity: raw.totalQuantity ?? 0,
|
|
161
|
+
cost: {
|
|
162
|
+
subtotalAmount: transformMoney(raw.cost?.subtotalAmount),
|
|
163
|
+
totalAmount: transformMoney(raw.cost?.totalAmount),
|
|
164
|
+
totalTaxAmount: raw.cost?.totalTaxAmount ? transformMoney(raw.cost.totalTaxAmount) : undefined,
|
|
165
|
+
},
|
|
166
|
+
lines,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ============================================
|
|
171
|
+
// Customer Transforms
|
|
172
|
+
// ============================================
|
|
173
|
+
|
|
174
|
+
export function transformAddress(raw: any): Address {
|
|
175
|
+
return {
|
|
176
|
+
id: raw.id ?? '',
|
|
177
|
+
firstName: raw.firstName ?? '',
|
|
178
|
+
lastName: raw.lastName ?? '',
|
|
179
|
+
address1: raw.address1 ?? '',
|
|
180
|
+
address2: raw.address2 ?? '',
|
|
181
|
+
city: raw.city ?? '',
|
|
182
|
+
province: raw.province ?? '',
|
|
183
|
+
countryCode: raw.country ?? raw.countryCodeV2 ?? '',
|
|
184
|
+
postalCode: raw.zip ?? '',
|
|
185
|
+
phone: raw.phone ?? '',
|
|
186
|
+
company: raw.company ?? '',
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function transformCustomer(raw: any): Customer {
|
|
191
|
+
return {
|
|
192
|
+
id: raw.id ?? '',
|
|
193
|
+
email: raw.email ?? '',
|
|
194
|
+
firstName: raw.firstName ?? '',
|
|
195
|
+
lastName: raw.lastName ?? '',
|
|
196
|
+
phone: raw.phone ?? '',
|
|
197
|
+
hasAccount: true,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function transformCustomerAddresses(raw: any): Address[] {
|
|
202
|
+
const edges = raw.addresses?.edges ?? [];
|
|
203
|
+
return edges.map((edge: any) => transformAddress(edge.node));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ============================================
|
|
207
|
+
// Order Transforms
|
|
208
|
+
// ============================================
|
|
209
|
+
|
|
210
|
+
function mapFinancialStatus(status: string | null | undefined): PaymentStatus {
|
|
211
|
+
switch (status?.toUpperCase()) {
|
|
212
|
+
case 'PAID': return 'paid';
|
|
213
|
+
case 'PENDING': return 'pending';
|
|
214
|
+
case 'AUTHORIZED': return 'authorized';
|
|
215
|
+
case 'REFUNDED': return 'refunded';
|
|
216
|
+
case 'PARTIALLY_REFUNDED': return 'partially_refunded';
|
|
217
|
+
default: return 'pending';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function mapFulfillmentStatus(status: string | null | undefined): FulfillmentStatus {
|
|
222
|
+
switch (status?.toUpperCase()) {
|
|
223
|
+
case 'FULFILLED': return 'fulfilled';
|
|
224
|
+
case 'PARTIAL': return 'partially_fulfilled';
|
|
225
|
+
case 'UNFULFILLED': return 'unfulfilled';
|
|
226
|
+
default: return 'unfulfilled';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function deriveOrderStatus(financial: string | null, fulfillment: string | null): OrderStatus {
|
|
231
|
+
if (financial?.toUpperCase() === 'VOIDED') return 'cancelled';
|
|
232
|
+
if (financial?.toUpperCase() === 'REFUNDED') return 'refunded';
|
|
233
|
+
if (fulfillment?.toUpperCase() === 'FULFILLED') return 'completed';
|
|
234
|
+
if (financial?.toUpperCase() === 'PAID') return 'processing';
|
|
235
|
+
return 'pending';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function transformOrderItem(raw: any): OrderItem {
|
|
239
|
+
const variant = raw.variant ?? {};
|
|
240
|
+
const product = variant.product ?? {};
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
id: variant.id ?? raw.title ?? '',
|
|
244
|
+
title: raw.title ?? '',
|
|
245
|
+
variantTitle: variant.title ?? '',
|
|
246
|
+
quantity: raw.quantity ?? 1,
|
|
247
|
+
price: transformMoney(variant.price),
|
|
248
|
+
total: {
|
|
249
|
+
amount: ((parseFloat(variant.price?.amount ?? '0')) * (raw.quantity ?? 1)).toFixed(2),
|
|
250
|
+
currencyCode: variant.price?.currencyCode ?? 'USD',
|
|
251
|
+
},
|
|
252
|
+
productId: product.id,
|
|
253
|
+
variantId: variant.id,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function transformOrder(raw: any): Order {
|
|
258
|
+
const items = (raw.lineItems?.edges ?? []).map((edge: any) => transformOrderItem(edge.node));
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
id: raw.id ?? '',
|
|
262
|
+
orderNumber: raw.orderNumber?.toString() ?? '',
|
|
263
|
+
email: raw.email ?? '',
|
|
264
|
+
status: deriveOrderStatus(raw.financialStatus, raw.fulfillmentStatus),
|
|
265
|
+
paymentStatus: mapFinancialStatus(raw.financialStatus),
|
|
266
|
+
fulfillmentStatus: mapFulfillmentStatus(raw.fulfillmentStatus),
|
|
267
|
+
items,
|
|
268
|
+
total: transformMoney(raw.totalPrice),
|
|
269
|
+
subtotal: transformMoney(raw.subtotalPrice ?? raw.totalPrice),
|
|
270
|
+
tax: { amount: '0.00', currencyCode: raw.totalPrice?.currencyCode ?? 'USD' },
|
|
271
|
+
shipping: { amount: '0.00', currencyCode: raw.totalPrice?.currencyCode ?? 'USD' },
|
|
272
|
+
createdAt: raw.processedAt ?? new Date().toISOString(),
|
|
273
|
+
updatedAt: raw.processedAt ?? new Date().toISOString(),
|
|
274
|
+
};
|
|
275
|
+
}
|