@ehrenkind/shopify-lib 0.7.0 → 0.7.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/dist/index.cjs +180 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +339 -109
- package/dist/index.d.ts +339 -109
- package/dist/index.mjs +179 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -54,6 +54,7 @@ __export(index_exports, {
|
|
|
54
54
|
getOrderPaymentDetailsById: () => getOrderPaymentDetailsById,
|
|
55
55
|
getOrdersByCustomerId: () => getOrdersByCustomerId,
|
|
56
56
|
getProductVariantsBySkus: () => getProductVariantsBySkus,
|
|
57
|
+
isRetryableError: () => isRetryableError,
|
|
57
58
|
parseGid: () => parseGid,
|
|
58
59
|
updateFulfillmentTracking: () => updateFulfillmentTracking,
|
|
59
60
|
upsertMetaobject: () => upsertMetaobject
|
|
@@ -115,7 +116,7 @@ var import_zod = require("zod");
|
|
|
115
116
|
|
|
116
117
|
// src/utils/apiVersion.ts
|
|
117
118
|
var import_shopify_api = require("@shopify/shopify-api");
|
|
118
|
-
var SHOPIFY_API_VERSION = import_shopify_api.ApiVersion.
|
|
119
|
+
var SHOPIFY_API_VERSION = import_shopify_api.ApiVersion.July25;
|
|
119
120
|
|
|
120
121
|
// src/utils/shopifyClient.ts
|
|
121
122
|
import_dotenv.default.config();
|
|
@@ -188,6 +189,38 @@ try {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
// src/utils/shopifyFetch.ts
|
|
192
|
+
var RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
193
|
+
"ECONNRESET",
|
|
194
|
+
"ETIMEDOUT",
|
|
195
|
+
"ECONNREFUSED",
|
|
196
|
+
"ENOTFOUND",
|
|
197
|
+
"EPIPE",
|
|
198
|
+
"EAI_AGAIN",
|
|
199
|
+
"EHOSTUNREACH",
|
|
200
|
+
"ENETUNREACH",
|
|
201
|
+
// undici (Node 18+ fetch) error codes
|
|
202
|
+
"UND_ERR_SOCKET",
|
|
203
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
204
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
205
|
+
"UND_ERR_BODY_TIMEOUT"
|
|
206
|
+
]);
|
|
207
|
+
function hasRetryableCode(value) {
|
|
208
|
+
if (!value || typeof value !== "object") return false;
|
|
209
|
+
const code = value.code;
|
|
210
|
+
return typeof code === "string" && RETRYABLE_ERROR_CODES.has(code);
|
|
211
|
+
}
|
|
212
|
+
function isRetryableError(error) {
|
|
213
|
+
if (!(error instanceof Error)) return false;
|
|
214
|
+
if (hasRetryableCode(error)) return true;
|
|
215
|
+
if (error instanceof TypeError && error.message.includes("fetch failed")) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
if (hasRetryableCode(error.cause)) return true;
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
function sleep(ms) {
|
|
222
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
223
|
+
}
|
|
191
224
|
function convertIdIntoGid(id, type) {
|
|
192
225
|
return `gid://shopify/${type}/${id}`;
|
|
193
226
|
}
|
|
@@ -204,16 +237,25 @@ async function fetchShopifyGraphql(params) {
|
|
|
204
237
|
query,
|
|
205
238
|
variables: initialVariables,
|
|
206
239
|
dataExtractor,
|
|
207
|
-
fetchAllPages = false
|
|
240
|
+
fetchAllPages = false,
|
|
241
|
+
retries = 0
|
|
208
242
|
} = params;
|
|
209
243
|
let currentVariables = { ...initialVariables };
|
|
210
244
|
if (!dataExtractor) {
|
|
211
|
-
return makeRequest(
|
|
245
|
+
return makeRequest(
|
|
246
|
+
query,
|
|
247
|
+
currentVariables,
|
|
248
|
+
retries
|
|
249
|
+
);
|
|
212
250
|
}
|
|
213
251
|
const allNodes = [];
|
|
214
252
|
let hasNextLoop = true;
|
|
215
253
|
do {
|
|
216
|
-
const response = await makeRequest(
|
|
254
|
+
const response = await makeRequest(
|
|
255
|
+
query,
|
|
256
|
+
currentVariables,
|
|
257
|
+
retries
|
|
258
|
+
);
|
|
217
259
|
const { nodes, pageInfo, userErrors } = dataExtractor(response);
|
|
218
260
|
if (Array.isArray(userErrors) && userErrors.length > 0) {
|
|
219
261
|
const errorMessages = userErrors.map((e) => e.message || JSON.stringify(e)).join("\n");
|
|
@@ -234,33 +276,53 @@ async function fetchShopifyGraphql(params) {
|
|
|
234
276
|
} while (hasNextLoop);
|
|
235
277
|
return allNodes;
|
|
236
278
|
}
|
|
237
|
-
async function makeRequest(query, variables) {
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
279
|
+
async function makeRequest(query, variables, retries = 0) {
|
|
280
|
+
const maxRetries = Number.isFinite(retries) ? Math.max(0, Math.floor(retries)) : 0;
|
|
281
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
282
|
+
try {
|
|
283
|
+
const response = await shopifyGraphqlClient.request(query, {
|
|
284
|
+
variables
|
|
285
|
+
});
|
|
286
|
+
if (response.errors) {
|
|
287
|
+
let errorMessages = "GraphQL query failed.";
|
|
288
|
+
const errors = response.errors;
|
|
289
|
+
if (Array.isArray(errors)) {
|
|
290
|
+
errorMessages = errors.map((e) => e.message || JSON.stringify(e)).join("\n");
|
|
291
|
+
} else if (typeof errors === "object" && errors !== null && "message" in errors) {
|
|
292
|
+
errorMessages = errors.message || JSON.stringify(errors);
|
|
293
|
+
} else if (typeof errors === "string") {
|
|
294
|
+
errorMessages = errors;
|
|
295
|
+
} else {
|
|
296
|
+
errorMessages = JSON.stringify(errors);
|
|
297
|
+
}
|
|
298
|
+
logger.error("GraphQL query failed:", errorMessages);
|
|
299
|
+
throw new Error(`GraphQL errors: ${errorMessages}`);
|
|
300
|
+
}
|
|
301
|
+
if (!response.data) {
|
|
302
|
+
throw new Error("No data in Shopify API response");
|
|
303
|
+
}
|
|
304
|
+
return response.data;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (attempt < maxRetries && isRetryableError(error)) {
|
|
307
|
+
const base = Math.min(1e3 * 2 ** attempt, 1e4);
|
|
308
|
+
const jitter = base * 0.2 * (Math.random() * 2 - 1);
|
|
309
|
+
const delay = Math.max(0, Math.round(base + jitter));
|
|
310
|
+
const totalAttempts = maxRetries + 1;
|
|
311
|
+
logger.warn(
|
|
312
|
+
`Transient error (attempt ${attempt + 1}/${totalAttempts}), retrying in ${delay}ms:`,
|
|
313
|
+
error.message
|
|
314
|
+
);
|
|
315
|
+
await sleep(delay);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
throw error;
|
|
252
319
|
}
|
|
253
|
-
logger.error("GraphQL query failed:", errorMessages);
|
|
254
|
-
throw new Error(`GraphQL errors: ${errorMessages}`);
|
|
255
320
|
}
|
|
256
|
-
|
|
257
|
-
throw new Error("No data in Shopify API response");
|
|
258
|
-
}
|
|
259
|
-
return response.data;
|
|
321
|
+
throw new Error("Unexpected: retry loop exited without result");
|
|
260
322
|
}
|
|
261
323
|
|
|
262
324
|
// src/mutations/customers/deleteCustomerById.ts
|
|
263
|
-
async function deleteCustomerById(customerId) {
|
|
325
|
+
async function deleteCustomerById(customerId, retries = 1) {
|
|
264
326
|
const mutation9 = gql`#graphql
|
|
265
327
|
mutation customerDelete($input: CustomerDeleteInput!) {
|
|
266
328
|
customerDelete(input: $input) {
|
|
@@ -278,6 +340,7 @@ async function deleteCustomerById(customerId) {
|
|
|
278
340
|
const response = await fetchShopifyGraphql({
|
|
279
341
|
query: mutation9,
|
|
280
342
|
variables,
|
|
343
|
+
retries,
|
|
281
344
|
dataExtractor: (data) => {
|
|
282
345
|
if (!data.customerDelete) {
|
|
283
346
|
throw new Error("GraphQL response missing 'customerDelete' field");
|
|
@@ -294,7 +357,7 @@ async function deleteCustomerById(customerId) {
|
|
|
294
357
|
}
|
|
295
358
|
|
|
296
359
|
// src/mutations/files/deleteFilesByIds.ts
|
|
297
|
-
async function deleteFilesByIds(fileIds) {
|
|
360
|
+
async function deleteFilesByIds(fileIds, retries = 1) {
|
|
298
361
|
if (fileIds.length === 0) {
|
|
299
362
|
return [];
|
|
300
363
|
}
|
|
@@ -314,6 +377,7 @@ async function deleteFilesByIds(fileIds) {
|
|
|
314
377
|
const response = await fetchShopifyGraphql({
|
|
315
378
|
query: mutation9,
|
|
316
379
|
variables,
|
|
380
|
+
retries,
|
|
317
381
|
dataExtractor: (data) => {
|
|
318
382
|
if (!data.fileDelete) {
|
|
319
383
|
throw new Error("GraphQL response missing 'fileDelete' field");
|
|
@@ -342,7 +406,7 @@ var mutation = gql`#graphql
|
|
|
342
406
|
}
|
|
343
407
|
}
|
|
344
408
|
`;
|
|
345
|
-
async function createFile(url, altText, filename) {
|
|
409
|
+
async function createFile(url, altText, filename, retries = 0) {
|
|
346
410
|
if (!url.startsWith("https://")) {
|
|
347
411
|
throw new Error(
|
|
348
412
|
`Not a valid public URL (https://) provided for file (url: ${url}).`
|
|
@@ -361,6 +425,7 @@ async function createFile(url, altText, filename) {
|
|
|
361
425
|
const result = await fetchShopifyGraphql({
|
|
362
426
|
query: mutation,
|
|
363
427
|
variables,
|
|
428
|
+
retries,
|
|
364
429
|
dataExtractor: (data) => {
|
|
365
430
|
if (!data.fileCreate) {
|
|
366
431
|
throw new Error("GraphQL response missing 'fileCreate' field");
|
|
@@ -397,7 +462,7 @@ var mutation2 = gql`#graphql
|
|
|
397
462
|
}
|
|
398
463
|
}
|
|
399
464
|
`;
|
|
400
|
-
async function createMetaobjectDefinition(input) {
|
|
465
|
+
async function createMetaobjectDefinition(input, retries = 0) {
|
|
401
466
|
logger.debug(`Creating metaobject definition with type: ${input.type}`);
|
|
402
467
|
const variables = {
|
|
403
468
|
definition: {
|
|
@@ -411,6 +476,7 @@ async function createMetaobjectDefinition(input) {
|
|
|
411
476
|
const result = await fetchShopifyGraphql({
|
|
412
477
|
query: mutation2,
|
|
413
478
|
variables,
|
|
479
|
+
retries,
|
|
414
480
|
dataExtractor: (data) => {
|
|
415
481
|
if (!data.metaobjectDefinitionCreate) {
|
|
416
482
|
throw new Error(
|
|
@@ -471,7 +537,7 @@ function toGid(id, type) {
|
|
|
471
537
|
}
|
|
472
538
|
return `gid://shopify/${type}/${id}`;
|
|
473
539
|
}
|
|
474
|
-
async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}) {
|
|
540
|
+
async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}, retries = 0) {
|
|
475
541
|
const {
|
|
476
542
|
trackingNumber,
|
|
477
543
|
carrier,
|
|
@@ -505,6 +571,7 @@ async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems,
|
|
|
505
571
|
const result = await fetchShopifyGraphql({
|
|
506
572
|
query: mutation3,
|
|
507
573
|
variables,
|
|
574
|
+
retries,
|
|
508
575
|
dataExtractor: (data) => {
|
|
509
576
|
if (!data.fulfillmentCreate) {
|
|
510
577
|
throw new Error("GraphQL response missing 'fulfillmentCreate' field");
|
|
@@ -553,7 +620,7 @@ var queryFulfillmentTrackingIds = gql`#graphql
|
|
|
553
620
|
`;
|
|
554
621
|
|
|
555
622
|
// src/queries/fulfillments/getFulfillmentTrackingIds.ts
|
|
556
|
-
async function getFulfillmentTrackingIds(id) {
|
|
623
|
+
async function getFulfillmentTrackingIds(id, retries = 3) {
|
|
557
624
|
const gid = typeof id === "string" ? id : convertIdIntoGid(
|
|
558
625
|
typeof id === "number" ? BigInt(id) : id,
|
|
559
626
|
"Fulfillment"
|
|
@@ -561,7 +628,8 @@ async function getFulfillmentTrackingIds(id) {
|
|
|
561
628
|
const variables = { id: gid };
|
|
562
629
|
const response = await fetchShopifyGraphql({
|
|
563
630
|
query: queryFulfillmentTrackingIds,
|
|
564
|
-
variables
|
|
631
|
+
variables,
|
|
632
|
+
retries
|
|
565
633
|
});
|
|
566
634
|
if (!response.fulfillment) {
|
|
567
635
|
logger.debug(`No fulfillment found with ID: ${id}`);
|
|
@@ -602,7 +670,7 @@ var mutation4 = gql`#graphql
|
|
|
602
670
|
}
|
|
603
671
|
}
|
|
604
672
|
`;
|
|
605
|
-
async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false) {
|
|
673
|
+
async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false, retries = 1) {
|
|
606
674
|
const fulfillmentGid = typeof fulfillmentId === "string" ? fulfillmentId : convertIdIntoGid(
|
|
607
675
|
typeof fulfillmentId === "number" ? BigInt(fulfillmentId) : fulfillmentId,
|
|
608
676
|
"Fulfillment"
|
|
@@ -624,6 +692,7 @@ async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCu
|
|
|
624
692
|
const result = await fetchShopifyGraphql({
|
|
625
693
|
query: mutation4,
|
|
626
694
|
variables,
|
|
695
|
+
retries,
|
|
627
696
|
dataExtractor: (data) => {
|
|
628
697
|
if (!data.fulfillmentTrackingInfoUpdate) {
|
|
629
698
|
throw new Error(
|
|
@@ -655,7 +724,7 @@ var mutation5 = gql`#graphql
|
|
|
655
724
|
mutation orderCancel($orderId: ID!) {
|
|
656
725
|
orderCancel(
|
|
657
726
|
orderId: $orderId
|
|
658
|
-
|
|
727
|
+
refundMethod: { originalPaymentMethodsRefund: true }
|
|
659
728
|
restock: false
|
|
660
729
|
reason: CUSTOMER
|
|
661
730
|
notifyCustomer: true
|
|
@@ -668,7 +737,7 @@ var mutation5 = gql`#graphql
|
|
|
668
737
|
}
|
|
669
738
|
}
|
|
670
739
|
`;
|
|
671
|
-
async function cancelOrderById(orderId) {
|
|
740
|
+
async function cancelOrderById(orderId, retries = 0) {
|
|
672
741
|
const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
|
|
673
742
|
typeof orderId === "number" ? BigInt(orderId) : orderId,
|
|
674
743
|
"Order"
|
|
@@ -678,6 +747,7 @@ async function cancelOrderById(orderId) {
|
|
|
678
747
|
await fetchShopifyGraphql({
|
|
679
748
|
query: mutation5,
|
|
680
749
|
variables,
|
|
750
|
+
retries,
|
|
681
751
|
dataExtractor: (data) => {
|
|
682
752
|
if (!data.orderCancel) {
|
|
683
753
|
throw new Error("GraphQL response missing 'orderCancel' field");
|
|
@@ -722,7 +792,7 @@ function toGid2(id, type) {
|
|
|
722
792
|
}
|
|
723
793
|
return `gid://shopify/${type}/${id}`;
|
|
724
794
|
}
|
|
725
|
-
async function createRefund(orderId, options = {}) {
|
|
795
|
+
async function createRefund(orderId, options = {}, retries = 0) {
|
|
726
796
|
const { currency, note, notify, refundLineItems, shipping, transactions } = options;
|
|
727
797
|
const orderGid = toGid2(orderId, "Order");
|
|
728
798
|
logger.debug(`Creating refund for order ${orderGid}`);
|
|
@@ -760,6 +830,7 @@ async function createRefund(orderId, options = {}) {
|
|
|
760
830
|
const result = await fetchShopifyGraphql({
|
|
761
831
|
query: mutation6,
|
|
762
832
|
variables,
|
|
833
|
+
retries,
|
|
763
834
|
dataExtractor: (data) => {
|
|
764
835
|
if (!data.refundCreate) {
|
|
765
836
|
throw new Error("GraphQL response missing 'refundCreate' field");
|
|
@@ -821,7 +892,7 @@ var mutation7 = gql`#graphql
|
|
|
821
892
|
}
|
|
822
893
|
}
|
|
823
894
|
`;
|
|
824
|
-
async function bulkUpdateProductVariants(productId, variants) {
|
|
895
|
+
async function bulkUpdateProductVariants(productId, variants, retries = 1) {
|
|
825
896
|
logger.debug(
|
|
826
897
|
`Bulk updating ${variants.length} variants for product ${productId}`
|
|
827
898
|
);
|
|
@@ -832,6 +903,7 @@ async function bulkUpdateProductVariants(productId, variants) {
|
|
|
832
903
|
const result = await fetchShopifyGraphql({
|
|
833
904
|
query: mutation7,
|
|
834
905
|
variables,
|
|
906
|
+
retries,
|
|
835
907
|
dataExtractor: (data) => {
|
|
836
908
|
if (!data.productVariantsBulkUpdate) {
|
|
837
909
|
throw new Error(
|
|
@@ -877,7 +949,7 @@ var mutation8 = gql`#graphql
|
|
|
877
949
|
}
|
|
878
950
|
}
|
|
879
951
|
`;
|
|
880
|
-
async function upsertMetaobject(input) {
|
|
952
|
+
async function upsertMetaobject(input, retries = 1) {
|
|
881
953
|
const { type, handle, fields } = input;
|
|
882
954
|
logger.debug(`Upserting metaobject type=${type} handle=${handle}`);
|
|
883
955
|
const variables = {
|
|
@@ -887,6 +959,7 @@ async function upsertMetaobject(input) {
|
|
|
887
959
|
const response = await fetchShopifyGraphql({
|
|
888
960
|
query: mutation8,
|
|
889
961
|
variables,
|
|
962
|
+
retries,
|
|
890
963
|
dataExtractor: (data) => {
|
|
891
964
|
if (!data.metaobjectUpsert) {
|
|
892
965
|
throw new Error("GraphQL response missing 'metaobjectUpsert' field");
|
|
@@ -1071,7 +1144,7 @@ function mapRestockType(restockType) {
|
|
|
1071
1144
|
return "NO_RESTOCK" /* NoRestock */;
|
|
1072
1145
|
}
|
|
1073
1146
|
}
|
|
1074
|
-
async function calculateRefund(orderId, options = {}) {
|
|
1147
|
+
async function calculateRefund(orderId, options = {}, retries = 3) {
|
|
1075
1148
|
const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
|
|
1076
1149
|
typeof orderId === "number" ? BigInt(orderId) : orderId,
|
|
1077
1150
|
"Order"
|
|
@@ -1090,7 +1163,8 @@ async function calculateRefund(orderId, options = {}) {
|
|
|
1090
1163
|
};
|
|
1091
1164
|
const response = await fetchShopifyGraphql({
|
|
1092
1165
|
query: querySuggestedRefund,
|
|
1093
|
-
variables
|
|
1166
|
+
variables,
|
|
1167
|
+
retries
|
|
1094
1168
|
});
|
|
1095
1169
|
if (!response.order?.suggestedRefund) {
|
|
1096
1170
|
logger.debug(`No refund suggestion available for order: ${orderId}`);
|
|
@@ -1230,6 +1304,12 @@ var queryOrderByIdFull = gql`#graphql
|
|
|
1230
1304
|
height
|
|
1231
1305
|
altText
|
|
1232
1306
|
}
|
|
1307
|
+
lineItemGroup {
|
|
1308
|
+
id
|
|
1309
|
+
title
|
|
1310
|
+
quantity
|
|
1311
|
+
variantSku
|
|
1312
|
+
}
|
|
1233
1313
|
}
|
|
1234
1314
|
}
|
|
1235
1315
|
}
|
|
@@ -1327,20 +1407,23 @@ var GetLeanOrderByIdReturn = import_zod3.default.object({
|
|
|
1327
1407
|
fulfillmentStatus: import_zod3.default.string().nullable(),
|
|
1328
1408
|
shippingAddress: AddressSchema
|
|
1329
1409
|
});
|
|
1330
|
-
async function getOrderById(id,
|
|
1410
|
+
async function getOrderById(id, detailLevelOrRetries, retries) {
|
|
1411
|
+
const detailLevel = typeof detailLevelOrRetries === "string" ? detailLevelOrRetries : "lean";
|
|
1412
|
+
const resolvedRetries = typeof detailLevelOrRetries === "number" ? detailLevelOrRetries : retries ?? 3;
|
|
1331
1413
|
const bigIntId = typeof id === "number" ? BigInt(id) : id;
|
|
1332
1414
|
if (detailLevel === "lean") {
|
|
1333
|
-
return getLeanOrderById(bigIntId);
|
|
1415
|
+
return getLeanOrderById(bigIntId, resolvedRetries);
|
|
1334
1416
|
}
|
|
1335
|
-
return getFullOrderById(bigIntId);
|
|
1417
|
+
return getFullOrderById(bigIntId, resolvedRetries);
|
|
1336
1418
|
}
|
|
1337
|
-
async function getLeanOrderById(id) {
|
|
1419
|
+
async function getLeanOrderById(id, retries = 3) {
|
|
1338
1420
|
const variables = {
|
|
1339
1421
|
id: convertIdIntoGid(id, "Order")
|
|
1340
1422
|
};
|
|
1341
1423
|
const response = await fetchShopifyGraphql({
|
|
1342
1424
|
query: queryOrderById,
|
|
1343
|
-
variables
|
|
1425
|
+
variables,
|
|
1426
|
+
retries
|
|
1344
1427
|
});
|
|
1345
1428
|
if (!response.order) {
|
|
1346
1429
|
logger.debug(`No order found with ID: ${id}`);
|
|
@@ -1380,13 +1463,14 @@ async function getLeanOrderById(id) {
|
|
|
1380
1463
|
};
|
|
1381
1464
|
return await returnOutputParsed(leanOrder, GetLeanOrderByIdReturn);
|
|
1382
1465
|
}
|
|
1383
|
-
async function getFullOrderById(id) {
|
|
1466
|
+
async function getFullOrderById(id, retries = 3) {
|
|
1384
1467
|
const variables = {
|
|
1385
1468
|
id: convertIdIntoGid(id, "Order")
|
|
1386
1469
|
};
|
|
1387
1470
|
const response = await fetchShopifyGraphql({
|
|
1388
1471
|
query: queryOrderByIdFull,
|
|
1389
|
-
variables
|
|
1472
|
+
variables,
|
|
1473
|
+
retries
|
|
1390
1474
|
});
|
|
1391
1475
|
if (!response.order) {
|
|
1392
1476
|
logger.debug(`No order found with ID: ${id}`);
|
|
@@ -1751,13 +1835,15 @@ var GetLeanOrderByNameReturn = import_zod5.default.object({
|
|
|
1751
1835
|
financialStatus: import_zod5.default.string().nullable(),
|
|
1752
1836
|
fulfillmentStatus: import_zod5.default.string().nullable()
|
|
1753
1837
|
});
|
|
1754
|
-
async function getOrderByName(orderName,
|
|
1838
|
+
async function getOrderByName(orderName, detailLevelOrRetries, retries) {
|
|
1839
|
+
const detailLevel = typeof detailLevelOrRetries === "string" ? detailLevelOrRetries : "lean";
|
|
1840
|
+
const resolvedRetries = typeof detailLevelOrRetries === "number" ? detailLevelOrRetries : retries ?? 3;
|
|
1755
1841
|
if (detailLevel === "lean") {
|
|
1756
|
-
return getLeanOrderByName(orderName);
|
|
1842
|
+
return getLeanOrderByName(orderName, resolvedRetries);
|
|
1757
1843
|
}
|
|
1758
|
-
return getFullOrderByName(orderName);
|
|
1844
|
+
return getFullOrderByName(orderName, resolvedRetries);
|
|
1759
1845
|
}
|
|
1760
|
-
async function getLeanOrderByName(orderName) {
|
|
1846
|
+
async function getLeanOrderByName(orderName, retries = 3) {
|
|
1761
1847
|
const variables = {
|
|
1762
1848
|
first: 1,
|
|
1763
1849
|
queryFilter: `name:${orderName}`
|
|
@@ -1778,7 +1864,8 @@ async function getLeanOrderByName(orderName) {
|
|
|
1778
1864
|
nodes
|
|
1779
1865
|
};
|
|
1780
1866
|
},
|
|
1781
|
-
fetchAllPages: false
|
|
1867
|
+
fetchAllPages: false,
|
|
1868
|
+
retries
|
|
1782
1869
|
});
|
|
1783
1870
|
const order = extractedNodes[0];
|
|
1784
1871
|
if (!order) {
|
|
@@ -1804,7 +1891,7 @@ async function getLeanOrderByName(orderName) {
|
|
|
1804
1891
|
};
|
|
1805
1892
|
return await returnOutputParsed(leanOrder, GetLeanOrderByNameReturn);
|
|
1806
1893
|
}
|
|
1807
|
-
async function getFullOrderByName(orderName) {
|
|
1894
|
+
async function getFullOrderByName(orderName, retries = 3) {
|
|
1808
1895
|
const variables = {
|
|
1809
1896
|
first: 1,
|
|
1810
1897
|
queryFilter: `name:${orderName}`
|
|
@@ -1825,7 +1912,8 @@ async function getFullOrderByName(orderName) {
|
|
|
1825
1912
|
nodes
|
|
1826
1913
|
};
|
|
1827
1914
|
},
|
|
1828
|
-
fetchAllPages: false
|
|
1915
|
+
fetchAllPages: false,
|
|
1916
|
+
retries
|
|
1829
1917
|
});
|
|
1830
1918
|
if (extractedNodes.length === 0) {
|
|
1831
1919
|
logger.debug(`No order found with name: ${orderName}`);
|
|
@@ -1855,14 +1943,15 @@ var queryOrderCancellationInfoByName = gql`#graphql
|
|
|
1855
1943
|
`;
|
|
1856
1944
|
|
|
1857
1945
|
// src/queries/orders/getOrderCancellationInfo.ts
|
|
1858
|
-
async function getOrderCancellationInfoByName(orderName) {
|
|
1946
|
+
async function getOrderCancellationInfoByName(orderName, retries = 3) {
|
|
1859
1947
|
const variables = {
|
|
1860
1948
|
first: 1,
|
|
1861
1949
|
queryFilter: `name:${orderName}`
|
|
1862
1950
|
};
|
|
1863
1951
|
const response = await fetchShopifyGraphql({
|
|
1864
1952
|
query: queryOrderCancellationInfoByName,
|
|
1865
|
-
variables
|
|
1953
|
+
variables,
|
|
1954
|
+
retries
|
|
1866
1955
|
});
|
|
1867
1956
|
if (!response.orders) {
|
|
1868
1957
|
throw new Error(
|
|
@@ -1895,7 +1984,7 @@ var GetLeanProductVariantsReturn = import_zod7.default.array(
|
|
|
1895
1984
|
status: import_zod7.default.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
|
|
1896
1985
|
})
|
|
1897
1986
|
);
|
|
1898
|
-
async function getLeanProductVariants(skus, options) {
|
|
1987
|
+
async function getLeanProductVariants(skus, options, retries = 3) {
|
|
1899
1988
|
const queryGql = gql`#graphql
|
|
1900
1989
|
query leanProductVariants($first: Int!, $after: String, $queryFilter: String) {
|
|
1901
1990
|
productVariants(first: $first, after: $after, query: $queryFilter) {
|
|
@@ -1948,7 +2037,8 @@ async function getLeanProductVariants(skus, options) {
|
|
|
1948
2037
|
pageInfo: pageData.productVariants.pageInfo
|
|
1949
2038
|
};
|
|
1950
2039
|
},
|
|
1951
|
-
fetchAllPages: true
|
|
2040
|
+
fetchAllPages: true,
|
|
2041
|
+
retries
|
|
1952
2042
|
});
|
|
1953
2043
|
const allVariants = extractedNodes.flatMap((v) => {
|
|
1954
2044
|
if (v.sku) {
|
|
@@ -1983,7 +2073,7 @@ var GetProductVariantsBySkusReturn = import_zod9.default.array(
|
|
|
1983
2073
|
status: import_zod9.default.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
|
|
1984
2074
|
})
|
|
1985
2075
|
);
|
|
1986
|
-
async function getProductVariantsBySkus(skus, options) {
|
|
2076
|
+
async function getProductVariantsBySkus(skus, options, retries = 3) {
|
|
1987
2077
|
if (skus.length === 0) {
|
|
1988
2078
|
return [];
|
|
1989
2079
|
}
|
|
@@ -2033,7 +2123,8 @@ async function getProductVariantsBySkus(skus, options) {
|
|
|
2033
2123
|
pageInfo: pageData.productVariants.pageInfo
|
|
2034
2124
|
};
|
|
2035
2125
|
},
|
|
2036
|
-
fetchAllPages: true
|
|
2126
|
+
fetchAllPages: true,
|
|
2127
|
+
retries
|
|
2037
2128
|
});
|
|
2038
2129
|
const allVariants = extractedNodes.flatMap((v) => {
|
|
2039
2130
|
if (!v.sku) {
|
|
@@ -2108,7 +2199,7 @@ var ProductVariantSchema = import_zod11.default.object({
|
|
|
2108
2199
|
combinedListingRole: import_zod11.default.enum(["PARENT", "CHILD"]).nullable()
|
|
2109
2200
|
});
|
|
2110
2201
|
var GetAllProductVariantsReturn = import_zod11.default.array(ProductVariantSchema);
|
|
2111
|
-
async function getAllProductVariants() {
|
|
2202
|
+
async function getAllProductVariants(retries = 3) {
|
|
2112
2203
|
const initialVariables = { first: 250 };
|
|
2113
2204
|
const extractedNodes = await fetchShopifyGraphql({
|
|
2114
2205
|
query: queryAllProductVariants,
|
|
@@ -2127,7 +2218,8 @@ async function getAllProductVariants() {
|
|
|
2127
2218
|
pageInfo: pageData.productVariants.pageInfo
|
|
2128
2219
|
};
|
|
2129
2220
|
},
|
|
2130
|
-
fetchAllPages: true
|
|
2221
|
+
fetchAllPages: true,
|
|
2222
|
+
retries
|
|
2131
2223
|
});
|
|
2132
2224
|
logger.debug(`Fetched ${extractedNodes.length} product variants from Shopify`);
|
|
2133
2225
|
const allVariants = extractedNodes.map((v) => {
|
|
@@ -2160,6 +2252,10 @@ var queryOrderPaymentDetails = gql`#graphql
|
|
|
2160
2252
|
amount
|
|
2161
2253
|
currencyCode
|
|
2162
2254
|
}
|
|
2255
|
+
presentmentMoney {
|
|
2256
|
+
amount
|
|
2257
|
+
currencyCode
|
|
2258
|
+
}
|
|
2163
2259
|
}
|
|
2164
2260
|
createdAt
|
|
2165
2261
|
gateway
|
|
@@ -2172,13 +2268,14 @@ var queryOrderPaymentDetails = gql`#graphql
|
|
|
2172
2268
|
`;
|
|
2173
2269
|
|
|
2174
2270
|
// src/queries/orders/getOrderPaymentDetails.ts
|
|
2175
|
-
async function getOrderPaymentDetailsById(id) {
|
|
2271
|
+
async function getOrderPaymentDetailsById(id, retries = 3) {
|
|
2176
2272
|
const variables = {
|
|
2177
2273
|
id: convertIdIntoGid(id, "Order")
|
|
2178
2274
|
};
|
|
2179
2275
|
const response = await fetchShopifyGraphql({
|
|
2180
2276
|
query: queryOrderPaymentDetails,
|
|
2181
|
-
variables
|
|
2277
|
+
variables,
|
|
2278
|
+
retries
|
|
2182
2279
|
});
|
|
2183
2280
|
if (!response.order) {
|
|
2184
2281
|
logger.debug(`No order found with ID: ${id}`);
|
|
@@ -2248,7 +2345,7 @@ var queryFulfillmentById = gql`#graphql
|
|
|
2248
2345
|
`;
|
|
2249
2346
|
|
|
2250
2347
|
// src/queries/fulfillments/getFulfillmentById.ts
|
|
2251
|
-
async function getFulfillmentById(id) {
|
|
2348
|
+
async function getFulfillmentById(id, retries = 3) {
|
|
2252
2349
|
const gid = typeof id === "string" ? id : convertIdIntoGid(
|
|
2253
2350
|
typeof id === "number" ? BigInt(id) : id,
|
|
2254
2351
|
"Fulfillment"
|
|
@@ -2256,7 +2353,8 @@ async function getFulfillmentById(id) {
|
|
|
2256
2353
|
const variables = { id: gid };
|
|
2257
2354
|
const response = await fetchShopifyGraphql({
|
|
2258
2355
|
query: queryFulfillmentById,
|
|
2259
|
-
variables
|
|
2356
|
+
variables,
|
|
2357
|
+
retries
|
|
2260
2358
|
});
|
|
2261
2359
|
if (!response.fulfillment) {
|
|
2262
2360
|
logger.debug(`No fulfillment found with ID: ${id}`);
|
|
@@ -2294,7 +2392,7 @@ var queryFulfillmentOrdersByOrderId = gql`#graphql
|
|
|
2294
2392
|
`;
|
|
2295
2393
|
|
|
2296
2394
|
// src/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.ts
|
|
2297
|
-
async function getFulfillmentOrdersByOrderId(orderId) {
|
|
2395
|
+
async function getFulfillmentOrdersByOrderId(orderId, retries = 3) {
|
|
2298
2396
|
const gid = typeof orderId === "string" ? orderId : convertIdIntoGid(
|
|
2299
2397
|
typeof orderId === "number" ? BigInt(orderId) : orderId,
|
|
2300
2398
|
"Order"
|
|
@@ -2302,7 +2400,8 @@ async function getFulfillmentOrdersByOrderId(orderId) {
|
|
|
2302
2400
|
const variables = { orderId: gid };
|
|
2303
2401
|
const response = await fetchShopifyGraphql({
|
|
2304
2402
|
query: queryFulfillmentOrdersByOrderId,
|
|
2305
|
-
variables
|
|
2403
|
+
variables,
|
|
2404
|
+
retries
|
|
2306
2405
|
});
|
|
2307
2406
|
if (!response.order) {
|
|
2308
2407
|
logger.debug(`No order found with ID: ${orderId}`);
|
|
@@ -2353,14 +2452,15 @@ var queryCustomersByEmail = gql`#graphql
|
|
|
2353
2452
|
`;
|
|
2354
2453
|
|
|
2355
2454
|
// src/queries/customers/getCustomersByEmail.ts
|
|
2356
|
-
async function getCustomersByEmail(email, limit = 10) {
|
|
2455
|
+
async function getCustomersByEmail(email, limit = 10, retries = 3) {
|
|
2357
2456
|
const variables = {
|
|
2358
2457
|
query: `email:${email}`,
|
|
2359
2458
|
first: limit
|
|
2360
2459
|
};
|
|
2361
2460
|
const response = await fetchShopifyGraphql({
|
|
2362
2461
|
query: queryCustomersByEmail,
|
|
2363
|
-
variables
|
|
2462
|
+
variables,
|
|
2463
|
+
retries
|
|
2364
2464
|
});
|
|
2365
2465
|
const customers = response.customers.edges.map((edge) => edge.node);
|
|
2366
2466
|
logger.debug(`Found ${customers.length} customers for email: ${email}`);
|
|
@@ -2398,7 +2498,7 @@ var queryCustomerSegmentMembersWithStatistics = gql`#graphql
|
|
|
2398
2498
|
`;
|
|
2399
2499
|
|
|
2400
2500
|
// src/queries/customerSegments/getCustomerSegmentMembers.ts
|
|
2401
|
-
async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250) {
|
|
2501
|
+
async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250, retries = 3) {
|
|
2402
2502
|
const variables = {
|
|
2403
2503
|
query,
|
|
2404
2504
|
first: limit,
|
|
@@ -2406,7 +2506,8 @@ async function getCustomerSegmentMembers(query, statisticsAttributeName, limit =
|
|
|
2406
2506
|
};
|
|
2407
2507
|
const response = await fetchShopifyGraphql({
|
|
2408
2508
|
query: queryCustomerSegmentMembersWithStatistics,
|
|
2409
|
-
variables
|
|
2509
|
+
variables,
|
|
2510
|
+
retries
|
|
2410
2511
|
});
|
|
2411
2512
|
const members = response.customerSegmentMembers.edges.map((edge) => edge.node);
|
|
2412
2513
|
logger.debug(`Found ${members.length} customer segment members`);
|
|
@@ -2459,7 +2560,7 @@ var queryOrdersByCustomerId = gql`#graphql
|
|
|
2459
2560
|
`;
|
|
2460
2561
|
|
|
2461
2562
|
// src/queries/orders/getOrdersByCustomerId.ts
|
|
2462
|
-
async function getOrdersByCustomerId(customerId, limit = 250) {
|
|
2563
|
+
async function getOrdersByCustomerId(customerId, limit = 250, retries = 3) {
|
|
2463
2564
|
const bigIntId = typeof customerId === "number" ? BigInt(customerId) : customerId;
|
|
2464
2565
|
const gid = convertIdIntoGid(bigIntId, "Customer");
|
|
2465
2566
|
const variables = {
|
|
@@ -2468,7 +2569,8 @@ async function getOrdersByCustomerId(customerId, limit = 250) {
|
|
|
2468
2569
|
};
|
|
2469
2570
|
const response = await fetchShopifyGraphql({
|
|
2470
2571
|
query: queryOrdersByCustomerId,
|
|
2471
|
-
variables
|
|
2572
|
+
variables,
|
|
2573
|
+
retries
|
|
2472
2574
|
});
|
|
2473
2575
|
if (!response.customer) {
|
|
2474
2576
|
logger.debug(`No customer found with ID: ${customerId}`);
|
|
@@ -2504,11 +2606,12 @@ var queryMetaobjectByHandle = gql`#graphql
|
|
|
2504
2606
|
`;
|
|
2505
2607
|
|
|
2506
2608
|
// src/queries/metaobjects/getMetaobjectByHandle.ts
|
|
2507
|
-
async function getMetaobjectByHandle(handle) {
|
|
2609
|
+
async function getMetaobjectByHandle(handle, retries = 3) {
|
|
2508
2610
|
const variables = { handle };
|
|
2509
2611
|
const response = await fetchShopifyGraphql({
|
|
2510
2612
|
query: queryMetaobjectByHandle,
|
|
2511
|
-
variables
|
|
2613
|
+
variables,
|
|
2614
|
+
retries
|
|
2512
2615
|
});
|
|
2513
2616
|
if (!response.metaobjectByHandle) {
|
|
2514
2617
|
logger.debug(
|
|
@@ -2544,6 +2647,7 @@ async function getMetaobjectByHandle(handle) {
|
|
|
2544
2647
|
getOrderPaymentDetailsById,
|
|
2545
2648
|
getOrdersByCustomerId,
|
|
2546
2649
|
getProductVariantsBySkus,
|
|
2650
|
+
isRetryableError,
|
|
2547
2651
|
parseGid,
|
|
2548
2652
|
updateFulfillmentTracking,
|
|
2549
2653
|
upsertMetaobject
|