@ehrenkind/shopify-lib 0.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/README.md +172 -0
- package/dist/generated-api-types/2025-04/admin.generated.d.ts +181 -0
- package/dist/generated-api-types/2025-04/admin.generated.d.ts.map +1 -0
- package/dist/generated-api-types/2025-04/admin.generated.js +5 -0
- package/dist/generated-api-types/2025-04/admin.generated.js.map +1 -0
- package/dist/generated-api-types/2025-04/admin.types.d.ts +57664 -0
- package/dist/generated-api-types/2025-04/admin.types.d.ts.map +1 -0
- package/dist/generated-api-types/2025-04/admin.types.js +11356 -0
- package/dist/generated-api-types/2025-04/admin.types.js.map +1 -0
- package/dist/index.cjs +752 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18290 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +719 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.d.ts +4 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.d.ts.map +1 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.js +56 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.js.map +1 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.d.ts +3 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.d.ts.map +1 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.js +11 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.js.map +1 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.d.ts +2 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.d.ts.map +1 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.js +11 -0
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.js.map +1 -0
- package/dist/queries/orders/getOrderByName.d.ts +26 -0
- package/dist/queries/orders/getOrderByName.d.ts.map +1 -0
- package/dist/queries/orders/getOrderByName.js +117 -0
- package/dist/queries/orders/getOrderByName.js.map +1 -0
- package/dist/queries/orders/getOrderByName.mock.d.ts +21 -0
- package/dist/queries/orders/getOrderByName.mock.d.ts.map +1 -0
- package/dist/queries/orders/getOrderByName.mock.js +55 -0
- package/dist/queries/orders/getOrderByName.mock.js.map +1 -0
- package/dist/queries/orders/getOrderByName.queries.d.ts +3 -0
- package/dist/queries/orders/getOrderByName.queries.d.ts.map +1 -0
- package/dist/queries/orders/getOrderByName.queries.js +335 -0
- package/dist/queries/orders/getOrderByName.queries.js.map +1 -0
- package/dist/queries/orders/getOrderByName.test.d.ts +2 -0
- package/dist/queries/orders/getOrderByName.test.d.ts.map +1 -0
- package/dist/queries/orders/getOrderByName.test.js +28 -0
- package/dist/queries/orders/getOrderByName.test.js.map +1 -0
- package/dist/queries/productVariants/getLeanProductVariants.d.ts +21 -0
- package/dist/queries/productVariants/getLeanProductVariants.d.ts.map +1 -0
- package/dist/queries/productVariants/getLeanProductVariants.js +81 -0
- package/dist/queries/productVariants/getLeanProductVariants.js.map +1 -0
- package/dist/queries/productVariants/getLeanProductVariants.mock.d.ts +3 -0
- package/dist/queries/productVariants/getLeanProductVariants.mock.d.ts.map +1 -0
- package/dist/queries/productVariants/getLeanProductVariants.mock.js +33 -0
- package/dist/queries/productVariants/getLeanProductVariants.mock.js.map +1 -0
- package/dist/queries/productVariants/getLeanProductVariants.test.d.ts +2 -0
- package/dist/queries/productVariants/getLeanProductVariants.test.d.ts.map +1 -0
- package/dist/queries/productVariants/getLeanProductVariants.test.js +38 -0
- package/dist/queries/productVariants/getLeanProductVariants.test.js.map +1 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +50 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mswHandlers.d.ts +2 -0
- package/dist/utils/mswHandlers.d.ts.map +1 -0
- package/dist/utils/mswHandlers.js +32 -0
- package/dist/utils/mswHandlers.js.map +1 -0
- package/dist/utils/shopifyClient.d.ts +6 -0
- package/dist/utils/shopifyClient.d.ts.map +1 -0
- package/dist/utils/shopifyClient.js +82 -0
- package/dist/utils/shopifyClient.js.map +1 -0
- package/dist/utils/shopifyClient.mock.d.ts +3 -0
- package/dist/utils/shopifyClient.mock.d.ts.map +1 -0
- package/dist/utils/shopifyClient.mock.js +19 -0
- package/dist/utils/shopifyClient.mock.js.map +1 -0
- package/dist/utils/shopifyClient.test.d.ts +2 -0
- package/dist/utils/shopifyClient.test.d.ts.map +1 -0
- package/dist/utils/shopifyClient.test.js +27 -0
- package/dist/utils/shopifyClient.test.js.map +1 -0
- package/dist/utils/shopifyFetch.d.ts +19 -0
- package/dist/utils/shopifyFetch.d.ts.map +1 -0
- package/dist/utils/shopifyFetch.js +60 -0
- package/dist/utils/shopifyFetch.js.map +1 -0
- package/dist/utils/shopifyFetch.test.d.ts +2 -0
- package/dist/utils/shopifyFetch.test.d.ts.map +1 -0
- package/dist/utils/shopifyFetch.test.js +17 -0
- package/dist/utils/shopifyFetch.test.js.map +1 -0
- package/dist/utils/test-setup.d.ts +2 -0
- package/dist/utils/test-setup.d.ts.map +1 -0
- package/dist/utils/test-setup.js +13 -0
- package/dist/utils/test-setup.js.map +1 -0
- package/dist/utils/zod.d.ts +3 -0
- package/dist/utils/zod.d.ts.map +1 -0
- package/dist/utils/zod.js +19 -0
- package/dist/utils/zod.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { gql } from '../../utils/logger';
|
|
2
|
+
export const queryOrdersByName = gql `#graphql
|
|
3
|
+
query ordersByName($first: Int!, $queryFilter: String!) {
|
|
4
|
+
orders(first: $first, query: $queryFilter) {
|
|
5
|
+
edges {
|
|
6
|
+
node {
|
|
7
|
+
id
|
|
8
|
+
name
|
|
9
|
+
createdAt
|
|
10
|
+
updatedAt
|
|
11
|
+
totalPriceSet {
|
|
12
|
+
shopMoney {
|
|
13
|
+
amount
|
|
14
|
+
currencyCode
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
customer {
|
|
18
|
+
id
|
|
19
|
+
lastName
|
|
20
|
+
defaultEmailAddress {
|
|
21
|
+
emailAddress
|
|
22
|
+
}
|
|
23
|
+
displayName
|
|
24
|
+
firstName
|
|
25
|
+
}
|
|
26
|
+
displayFinancialStatus
|
|
27
|
+
displayFulfillmentStatus
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
pageInfo {
|
|
31
|
+
hasNextPage
|
|
32
|
+
endCursor
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
export const queryOrdersByNameFull = gql `#graphql
|
|
38
|
+
query ordersByNameFull($first: Int!, $queryFilter: String!) {
|
|
39
|
+
orders(first: $first, query: $queryFilter) {
|
|
40
|
+
edges {
|
|
41
|
+
node {
|
|
42
|
+
billingAddress {
|
|
43
|
+
address1
|
|
44
|
+
address2
|
|
45
|
+
city
|
|
46
|
+
company
|
|
47
|
+
country
|
|
48
|
+
countryCodeV2
|
|
49
|
+
firstName
|
|
50
|
+
formattedArea
|
|
51
|
+
id
|
|
52
|
+
lastName
|
|
53
|
+
name
|
|
54
|
+
phone
|
|
55
|
+
province
|
|
56
|
+
provinceCode
|
|
57
|
+
timeZone
|
|
58
|
+
zip
|
|
59
|
+
}
|
|
60
|
+
billingAddressMatchesShippingAddress
|
|
61
|
+
cancelReason
|
|
62
|
+
cancellation {
|
|
63
|
+
staffNote
|
|
64
|
+
}
|
|
65
|
+
cancelledAt
|
|
66
|
+
capturable
|
|
67
|
+
clientIp
|
|
68
|
+
closed
|
|
69
|
+
closedAt
|
|
70
|
+
confirmed
|
|
71
|
+
createdAt
|
|
72
|
+
currencyCode
|
|
73
|
+
currentCartDiscountAmountSet {
|
|
74
|
+
presentmentMoney {
|
|
75
|
+
amount
|
|
76
|
+
currencyCode
|
|
77
|
+
}
|
|
78
|
+
shopMoney {
|
|
79
|
+
amount
|
|
80
|
+
currencyCode
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
currentShippingPriceSet {
|
|
84
|
+
presentmentMoney {
|
|
85
|
+
amount
|
|
86
|
+
currencyCode
|
|
87
|
+
}
|
|
88
|
+
shopMoney {
|
|
89
|
+
amount
|
|
90
|
+
currencyCode
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
currentSubtotalLineItemsQuantity
|
|
94
|
+
currentSubtotalPriceSet {
|
|
95
|
+
presentmentMoney {
|
|
96
|
+
amount
|
|
97
|
+
currencyCode
|
|
98
|
+
}
|
|
99
|
+
shopMoney {
|
|
100
|
+
amount
|
|
101
|
+
currencyCode
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
currentTaxLines {
|
|
105
|
+
channelLiable
|
|
106
|
+
rate
|
|
107
|
+
ratePercentage
|
|
108
|
+
source
|
|
109
|
+
title
|
|
110
|
+
priceSet {
|
|
111
|
+
presentmentMoney {
|
|
112
|
+
amount
|
|
113
|
+
currencyCode
|
|
114
|
+
}
|
|
115
|
+
shopMoney {
|
|
116
|
+
amount
|
|
117
|
+
currencyCode
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
currentTotalAdditionalFeesSet {
|
|
122
|
+
presentmentMoney {
|
|
123
|
+
amount
|
|
124
|
+
currencyCode
|
|
125
|
+
}
|
|
126
|
+
shopMoney {
|
|
127
|
+
amount
|
|
128
|
+
currencyCode
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
currentTotalDiscountsSet {
|
|
132
|
+
presentmentMoney {
|
|
133
|
+
amount
|
|
134
|
+
currencyCode
|
|
135
|
+
currencyCode
|
|
136
|
+
}
|
|
137
|
+
shopMoney {
|
|
138
|
+
amount
|
|
139
|
+
currencyCode
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
currentTotalDutiesSet {
|
|
143
|
+
presentmentMoney {
|
|
144
|
+
amount
|
|
145
|
+
currencyCode
|
|
146
|
+
}
|
|
147
|
+
shopMoney {
|
|
148
|
+
amount
|
|
149
|
+
currencyCode
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
currentTotalPriceSet {
|
|
153
|
+
presentmentMoney {
|
|
154
|
+
amount
|
|
155
|
+
currencyCode
|
|
156
|
+
}
|
|
157
|
+
shopMoney {
|
|
158
|
+
amount
|
|
159
|
+
currencyCode
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
currentTotalTaxSet {
|
|
163
|
+
presentmentMoney {
|
|
164
|
+
amount
|
|
165
|
+
currencyCode
|
|
166
|
+
}
|
|
167
|
+
shopMoney {
|
|
168
|
+
amount
|
|
169
|
+
currencyCode
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
currentTotalWeight
|
|
173
|
+
customer {
|
|
174
|
+
id
|
|
175
|
+
lastName
|
|
176
|
+
defaultEmailAddress {
|
|
177
|
+
emailAddress
|
|
178
|
+
}
|
|
179
|
+
displayName
|
|
180
|
+
firstName
|
|
181
|
+
}
|
|
182
|
+
customerAcceptsMarketing
|
|
183
|
+
discountCodes
|
|
184
|
+
discountCode
|
|
185
|
+
displayAddress {
|
|
186
|
+
address1
|
|
187
|
+
address2
|
|
188
|
+
city
|
|
189
|
+
company
|
|
190
|
+
country
|
|
191
|
+
countryCodeV2
|
|
192
|
+
firstName
|
|
193
|
+
formattedArea
|
|
194
|
+
id
|
|
195
|
+
lastName
|
|
196
|
+
name
|
|
197
|
+
phone
|
|
198
|
+
province
|
|
199
|
+
provinceCode
|
|
200
|
+
timeZone
|
|
201
|
+
zip
|
|
202
|
+
}
|
|
203
|
+
displayFinancialStatus
|
|
204
|
+
displayFulfillmentStatus
|
|
205
|
+
dutiesIncluded
|
|
206
|
+
edited
|
|
207
|
+
email
|
|
208
|
+
estimatedTaxes
|
|
209
|
+
fulfillable
|
|
210
|
+
fulfillments(first: 20) {
|
|
211
|
+
createdAt
|
|
212
|
+
deliveredAt
|
|
213
|
+
displayStatus
|
|
214
|
+
estimatedDeliveryAt
|
|
215
|
+
updatedAt
|
|
216
|
+
trackingInfo(first: 10) {
|
|
217
|
+
company
|
|
218
|
+
url
|
|
219
|
+
}
|
|
220
|
+
totalQuantity
|
|
221
|
+
status
|
|
222
|
+
name
|
|
223
|
+
id
|
|
224
|
+
}
|
|
225
|
+
fullyPaid
|
|
226
|
+
id
|
|
227
|
+
lineItems(first: 50) {
|
|
228
|
+
edges {
|
|
229
|
+
node {
|
|
230
|
+
id
|
|
231
|
+
name
|
|
232
|
+
originalUnitPriceSet {
|
|
233
|
+
presentmentMoney {
|
|
234
|
+
amount
|
|
235
|
+
currencyCode
|
|
236
|
+
}
|
|
237
|
+
shopMoney {
|
|
238
|
+
amount
|
|
239
|
+
currencyCode
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
quantity
|
|
243
|
+
requiresShipping
|
|
244
|
+
sku
|
|
245
|
+
title
|
|
246
|
+
variantTitle
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
name
|
|
251
|
+
note
|
|
252
|
+
processedAt
|
|
253
|
+
shippingAddress {
|
|
254
|
+
address1
|
|
255
|
+
address2
|
|
256
|
+
city
|
|
257
|
+
company
|
|
258
|
+
country
|
|
259
|
+
countryCodeV2
|
|
260
|
+
firstName
|
|
261
|
+
formattedArea
|
|
262
|
+
id
|
|
263
|
+
lastName
|
|
264
|
+
name
|
|
265
|
+
phone
|
|
266
|
+
province
|
|
267
|
+
provinceCode
|
|
268
|
+
timeZone
|
|
269
|
+
zip
|
|
270
|
+
}
|
|
271
|
+
statusPageUrl
|
|
272
|
+
tags
|
|
273
|
+
totalPriceSet {
|
|
274
|
+
presentmentMoney {
|
|
275
|
+
amount
|
|
276
|
+
currencyCode
|
|
277
|
+
}
|
|
278
|
+
shopMoney {
|
|
279
|
+
amount
|
|
280
|
+
currencyCode
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
totalReceivedSet {
|
|
284
|
+
presentmentMoney {
|
|
285
|
+
amount
|
|
286
|
+
currencyCode
|
|
287
|
+
}
|
|
288
|
+
shopMoney {
|
|
289
|
+
amount
|
|
290
|
+
currencyCode
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
totalRefundedSet {
|
|
294
|
+
presentmentMoney {
|
|
295
|
+
amount
|
|
296
|
+
currencyCode
|
|
297
|
+
}
|
|
298
|
+
shopMoney {
|
|
299
|
+
amount
|
|
300
|
+
currencyCode
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
totalShippingPriceSet {
|
|
304
|
+
presentmentMoney {
|
|
305
|
+
amount
|
|
306
|
+
currencyCode
|
|
307
|
+
}
|
|
308
|
+
shopMoney {
|
|
309
|
+
amount
|
|
310
|
+
currencyCode
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
totalTaxSet {
|
|
314
|
+
presentmentMoney {
|
|
315
|
+
amount
|
|
316
|
+
currencyCode
|
|
317
|
+
}
|
|
318
|
+
shopMoney {
|
|
319
|
+
amount
|
|
320
|
+
currencyCode
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
totalWeight
|
|
324
|
+
unpaid
|
|
325
|
+
updatedAt
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
pageInfo {
|
|
329
|
+
hasNextPage
|
|
330
|
+
endCursor
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
`;
|
|
335
|
+
//# sourceMappingURL=getOrderByName.queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrderByName.queries.js","sourceRoot":"","sources":["../../../src/queries/orders/getOrderByName.queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAExC,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCnC,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAySvC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrderByName.test.d.ts","sourceRoot":"","sources":["../../../src/queries/orders/getOrderByName.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { graphql, passthrough } from 'msw';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { server } from '../../utils/mswHandlers';
|
|
4
|
+
import { getOrderByName } from './getOrderByName';
|
|
5
|
+
import { expectedLeanOrder } from './getOrderByName.mock';
|
|
6
|
+
describe('getOrderByName - Using Mock Infrastructure', () => {
|
|
7
|
+
it('should return lean order when found', async () => {
|
|
8
|
+
const result = await getOrderByName('B12345');
|
|
9
|
+
expect(result).toEqual(expectedLeanOrder);
|
|
10
|
+
});
|
|
11
|
+
it('should return lean order when explicitly requesting lean detail', async () => {
|
|
12
|
+
const result = await getOrderByName('B12345', 'lean');
|
|
13
|
+
expect(result).toEqual(expectedLeanOrder);
|
|
14
|
+
});
|
|
15
|
+
it('should return full order when requesting full detail', async () => {
|
|
16
|
+
const result = await getOrderByName('B12345', 'full');
|
|
17
|
+
expect(result).not.toBeNull();
|
|
18
|
+
expect(result?.name).toBe('B12345');
|
|
19
|
+
expect(result?.id).toBe('gid://shopify/Order/12345');
|
|
20
|
+
expect(result?.customer?.displayName).toBe('John Doe');
|
|
21
|
+
});
|
|
22
|
+
it('should return null when order not found', async () => {
|
|
23
|
+
server.use(graphql.query('ordersByName', () => passthrough()));
|
|
24
|
+
const result = await getOrderByName('NONEXISTENT');
|
|
25
|
+
expect(result).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=getOrderByName.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrderByName.test.js","sourceRoot":"","sources":["../../../src/queries/orders/getOrderByName.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IAC1D,EAAE,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACnD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAA;QAC7C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;QAC/E,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QACrD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAErD,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;QAC7B,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;QACpD,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAC9D,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,aAAa,CAAC,CAAA;QAClD,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
declare const GetLeanProductVariantsReturn: z.ZodArray<z.ZodObject<{
|
|
3
|
+
productId: z.ZodString;
|
|
4
|
+
productTitle: z.ZodString;
|
|
5
|
+
variantId: z.ZodString;
|
|
6
|
+
variantTitle: z.ZodString;
|
|
7
|
+
sku: z.ZodString;
|
|
8
|
+
}, {}, {}>>;
|
|
9
|
+
type GetLeanProductVariantsReturnType = z.infer<typeof GetLeanProductVariantsReturn>;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves a lean list of product variants from Shopify, optionally filtered by SKUs.
|
|
12
|
+
* Product variants are mapped to a simpler output structure.
|
|
13
|
+
* Variants missing essential properties (e.g., SKU) will be filtered out and logged.
|
|
14
|
+
*
|
|
15
|
+
* @param {string[]} [skus] - An optional array of SKUs to filter by. If provided, only variants matching these SKUs will be fetched.
|
|
16
|
+
* @returns {Promise<GetLeanProductVariantsReturnType>} A promise that resolves to an array of lean product variant data.
|
|
17
|
+
* @throws {Error} If the GraphQL query fails, returns no data, or if the `productVariants` field is missing in the response.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getLeanProductVariants(skus?: string[]): Promise<GetLeanProductVariantsReturnType>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=getLeanProductVariants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLeanProductVariants.d.ts","sourceRoot":"","sources":["../../../src/queries/productVariants/getLeanProductVariants.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AASnB,QAAA,MAAM,4BAA4B;;;;;;WAQjC,CAAA;AAED,KAAK,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,4BAA4B,CACpC,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,CAAC,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,gCAAgC,CAAC,CAiF3C"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { gql, logger } from '../../utils/logger.js';
|
|
3
|
+
import { fetchShopifyGraphql } from '../../utils/shopifyFetch.js';
|
|
4
|
+
import { returnOutputParsed } from '../../utils/zod.js';
|
|
5
|
+
const GetLeanProductVariantsReturn = z.array(z.object({
|
|
6
|
+
productId: z.string(),
|
|
7
|
+
productTitle: z.string(),
|
|
8
|
+
variantId: z.string(),
|
|
9
|
+
variantTitle: z.string(),
|
|
10
|
+
sku: z.string(),
|
|
11
|
+
}));
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves a lean list of product variants from Shopify, optionally filtered by SKUs.
|
|
14
|
+
* Product variants are mapped to a simpler output structure.
|
|
15
|
+
* Variants missing essential properties (e.g., SKU) will be filtered out and logged.
|
|
16
|
+
*
|
|
17
|
+
* @param {string[]} [skus] - An optional array of SKUs to filter by. If provided, only variants matching these SKUs will be fetched.
|
|
18
|
+
* @returns {Promise<GetLeanProductVariantsReturnType>} A promise that resolves to an array of lean product variant data.
|
|
19
|
+
* @throws {Error} If the GraphQL query fails, returns no data, or if the `productVariants` field is missing in the response.
|
|
20
|
+
*/
|
|
21
|
+
export async function getLeanProductVariants(skus) {
|
|
22
|
+
const queryGql = gql `#graphql
|
|
23
|
+
query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {
|
|
24
|
+
productVariants(first: $first, after: $after, query: $queryFilter) {
|
|
25
|
+
edges {
|
|
26
|
+
node {
|
|
27
|
+
id
|
|
28
|
+
title
|
|
29
|
+
sku
|
|
30
|
+
product {
|
|
31
|
+
id
|
|
32
|
+
title
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
pageInfo {
|
|
37
|
+
hasNextPage
|
|
38
|
+
endCursor
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
const initialVariables = { first: 250 };
|
|
44
|
+
if (skus && skus.length > 0) {
|
|
45
|
+
initialVariables.queryFilter = skus
|
|
46
|
+
.map((sku) => `sku:${sku}`)
|
|
47
|
+
.join(' OR ');
|
|
48
|
+
}
|
|
49
|
+
const extractedNodes = await fetchShopifyGraphql({
|
|
50
|
+
query: queryGql,
|
|
51
|
+
variables: initialVariables,
|
|
52
|
+
dataExtractor: (pageData) => {
|
|
53
|
+
if (!pageData.productVariants) {
|
|
54
|
+
throw new Error("GraphQL response for product variants is missing the 'productVariants' field.");
|
|
55
|
+
}
|
|
56
|
+
const nodes = pageData.productVariants.edges.map((edge) => edge.node);
|
|
57
|
+
return {
|
|
58
|
+
nodes,
|
|
59
|
+
pageInfo: pageData.productVariants.pageInfo,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
fetchAllPages: true,
|
|
63
|
+
});
|
|
64
|
+
const allVariants = extractedNodes.flatMap((v) => {
|
|
65
|
+
if (v.sku) {
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
productId: v.product.id,
|
|
69
|
+
productTitle: v.product.title,
|
|
70
|
+
variantId: v.id,
|
|
71
|
+
variantTitle: v.title,
|
|
72
|
+
sku: v.sku,
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
logger.debug(`Product ${v.product.title} (ID: ${v.product.id}) has a variant (ID: ${v.id}) with no SKU. Filtering out.`);
|
|
77
|
+
return [];
|
|
78
|
+
});
|
|
79
|
+
return await returnOutputParsed(allVariants, GetLeanProductVariantsReturn);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=getLeanProductVariants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLeanProductVariants.js","sourceRoot":"","sources":["../../../src/queries/productVariants/getLeanProductVariants.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAKnB,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAC1C,CAAC,CAAC,MAAM,CAAC;IACP,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,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,EAAE;oBACf,YAAY,EAAE,CAAC,CAAC,KAAK;oBACrB,GAAG,EAAE,CAAC,CAAC,GAAG;iBACX;aACF,CAAA;QACH,CAAC;QACD,MAAM,CAAC,KAAK,CACV,WAAW,CAAC,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC,EAAE,+BAA+B,CAC3G,CAAA;QACD,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,kBAAkB,CAAC,WAAW,EAAE,4BAA4B,CAAC,CAAA;AAC5E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLeanProductVariants.mock.d.ts","sourceRoot":"","sources":["../../../src/queries/productVariants/getLeanProductVariants.mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAA;AAEjG,eAAO,MAAM,uBAAuB,EAAE,wBA+BrC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const leanProductVariantsMock = {
|
|
2
|
+
productVariants: {
|
|
3
|
+
edges: [
|
|
4
|
+
{
|
|
5
|
+
node: {
|
|
6
|
+
id: 'gid://shopify/ProductVariant/1',
|
|
7
|
+
title: 'Default Title',
|
|
8
|
+
sku: 'SKU123',
|
|
9
|
+
product: {
|
|
10
|
+
id: 'gid://shopify/Product/1',
|
|
11
|
+
title: 'Test Product 1',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
node: {
|
|
17
|
+
id: 'gid://shopify/ProductVariant/2',
|
|
18
|
+
title: 'Another Variant',
|
|
19
|
+
sku: 'SKU456',
|
|
20
|
+
product: {
|
|
21
|
+
id: 'gid://shopify/Product/2',
|
|
22
|
+
title: 'Test Product 2',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
pageInfo: {
|
|
28
|
+
hasNextPage: false,
|
|
29
|
+
endCursor: 'eyJsYXN0X2lkIjoxfQ==',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=getLeanProductVariants.mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLeanProductVariants.mock.js","sourceRoot":"","sources":["../../../src/queries/productVariants/getLeanProductVariants.mock.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAA6B;IAC/D,eAAe,EAAE;QACf,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,EAAE,EAAE,gCAAgC;oBACpC,KAAK,EAAE,eAAe;oBACtB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE;wBACP,EAAE,EAAE,yBAAyB;wBAC7B,KAAK,EAAE,gBAAgB;qBACxB;iBACF;aACF;YACD;gBACE,IAAI,EAAE;oBACJ,EAAE,EAAE,gCAAgC;oBACpC,KAAK,EAAE,iBAAiB;oBACxB,GAAG,EAAE,QAAQ;oBACb,OAAO,EAAE;wBACP,EAAE,EAAE,yBAAyB;wBAC7B,KAAK,EAAE,gBAAgB;qBACxB;iBACF;aACF;SACF;QACD,QAAQ,EAAE;YACR,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,sBAAsB;SAClC;KACF;CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLeanProductVariants.test.d.ts","sourceRoot":"","sources":["../../../src/queries/productVariants/getLeanProductVariants.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { graphql, passthrough } from 'msw';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { server } from '../../utils/mswHandlers';
|
|
4
|
+
import { getLeanProductVariants } from './getLeanProductVariants';
|
|
5
|
+
import { leanProductVariantsMock } from './getLeanProductVariants.mock';
|
|
6
|
+
describe('getLeanProductVariants', () => {
|
|
7
|
+
describe('Mocked', () => {
|
|
8
|
+
const skus = ['SKU123', 'SKU456'];
|
|
9
|
+
const variants = leanProductVariantsMock.productVariants.edges.map((edge) => edge.node);
|
|
10
|
+
const reformattedVariants = variants.map((variant) => ({
|
|
11
|
+
productId: variant.product.id,
|
|
12
|
+
productTitle: variant.product.title,
|
|
13
|
+
variantId: variant.id,
|
|
14
|
+
variantTitle: variant.title,
|
|
15
|
+
sku: variant.sku,
|
|
16
|
+
}));
|
|
17
|
+
it('should work with multiple SKUs', async () => {
|
|
18
|
+
const result = await getLeanProductVariants(skus);
|
|
19
|
+
expect(result).toEqual(reformattedVariants);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('Live', () => {
|
|
23
|
+
it('should return an empty array for non-existent SKUs', async () => {
|
|
24
|
+
server.use(graphql.query('leanProductVariants', () => passthrough()));
|
|
25
|
+
const result = await getLeanProductVariants(['not-a-sku']);
|
|
26
|
+
expect(result).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
it('should work without SKUs and fetch more than is on one page (250)', {
|
|
29
|
+
timeout: 20000,
|
|
30
|
+
skip: false,
|
|
31
|
+
}, async () => {
|
|
32
|
+
server.use(graphql.query('leanProductVariants', () => passthrough()));
|
|
33
|
+
const result = await getLeanProductVariants();
|
|
34
|
+
expect(result.length).toBeGreaterThan(251);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=getLeanProductVariants.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLeanProductVariants.test.js","sourceRoot":"","sources":["../../../src/queries/productVariants/getLeanProductVariants.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM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C,CAAC,CAAA;YAC1D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QAEF,EAAE,CACA,mEAAmE,EACnE;YACE,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,KAAK;SACZ,EACD,KAAK,IAAI,EAAE;YACT,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;YAErE,MAAM,MAAM,GAAG,MAAM,sBAAsB,EAAE,CAAA;YAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;QAC5C,CAAC,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const gql: (template: {
|
|
2
|
+
raw: readonly string[] | ArrayLike<string>;
|
|
3
|
+
}, ...substitutions: any[]) => string;
|
|
4
|
+
export declare const activeLogLevelName: "silent" | "error" | "warn" | "info" | "debug";
|
|
5
|
+
export declare const logger: {
|
|
6
|
+
debug: (...args: unknown[]) => void;
|
|
7
|
+
info: (...args: unknown[]) => void;
|
|
8
|
+
warn: (...args: unknown[]) => void;
|
|
9
|
+
error: (...args: unknown[]) => void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;;qCAAa,CAAA;AA8B7B,eAAO,MAAM,kBAAkB,gDAA2C,CAAA;AAG1E,eAAO,MAAM,MAAM;qBACA,OAAO,EAAE;oBAMV,OAAO,EAAE;oBAMT,OAAO,EAAE;qBAMR,OAAO,EAAE;CAM3B,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { env } = process;
|
|
2
|
+
export const gql = String.raw;
|
|
3
|
+
const logLevels = {
|
|
4
|
+
silent: 0,
|
|
5
|
+
error: 1,
|
|
6
|
+
warn: 2,
|
|
7
|
+
info: 3,
|
|
8
|
+
debug: 4,
|
|
9
|
+
};
|
|
10
|
+
function getLogLevel(nodeEnv, logLevelEnv) {
|
|
11
|
+
if (logLevelEnv && logLevelEnv in logLevels) {
|
|
12
|
+
return logLevelEnv;
|
|
13
|
+
}
|
|
14
|
+
if (nodeEnv === 'test') {
|
|
15
|
+
return 'silent';
|
|
16
|
+
}
|
|
17
|
+
if (nodeEnv === 'production') {
|
|
18
|
+
return 'info';
|
|
19
|
+
}
|
|
20
|
+
return 'debug';
|
|
21
|
+
}
|
|
22
|
+
export const activeLogLevelName = getLogLevel(env.NODE_ENV, env.LOG_LEVEL);
|
|
23
|
+
const activeLogLevelValue = logLevels[activeLogLevelName];
|
|
24
|
+
export const logger = {
|
|
25
|
+
debug: (...args) => {
|
|
26
|
+
if (logLevels.debug <= activeLogLevelValue) {
|
|
27
|
+
// biome-ignore lint/suspicious/noConsole: <explanation>
|
|
28
|
+
console.debug(...args);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
info: (...args) => {
|
|
32
|
+
if (logLevels.info <= activeLogLevelValue) {
|
|
33
|
+
// biome-ignore lint/suspicious/noConsole: <explanation>
|
|
34
|
+
console.info(...args);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
warn: (...args) => {
|
|
38
|
+
if (logLevels.warn <= activeLogLevelValue) {
|
|
39
|
+
// biome-ignore lint/suspicious/noConsole: <explanation>
|
|
40
|
+
console.warn(...args);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
error: (...args) => {
|
|
44
|
+
if (logLevels.error <= activeLogLevelValue) {
|
|
45
|
+
// biome-ignore lint/suspicious/noConsole: <explanation>
|
|
46
|
+
console.error(...args);
|
|
47
|
+
}
|
|
48
|
+
},
|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