@ehrenkind/shopify-lib 0.4.0 → 0.5.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.
- package/dist/index.cjs +1479 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1842 -252
- package/dist/index.d.ts +20821 -15
- package/dist/index.mjs +1452 -165
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/generated-api-types/2025-04/admin.generated.d.ts +0 -420
- package/dist/generated-api-types/2025-04/admin.generated.d.ts.map +0 -1
- package/dist/generated-api-types/2025-04/admin.generated.js +0 -5
- package/dist/generated-api-types/2025-04/admin.generated.js.map +0 -1
- package/dist/generated-api-types/2025-04/admin.types.d.ts +0 -60045
- package/dist/generated-api-types/2025-04/admin.types.d.ts.map +0 -1
- package/dist/generated-api-types/2025-04/admin.types.js +0 -11451
- package/dist/generated-api-types/2025-04/admin.types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/mutations/customers/deleteCustomerById.d.ts +0 -2
- package/dist/mutations/customers/deleteCustomerById.d.ts.map +0 -1
- package/dist/mutations/customers/deleteCustomerById.js +0 -35
- package/dist/mutations/customers/deleteCustomerById.js.map +0 -1
- package/dist/mutations/customers/deleteCustomerById.mock.d.ts +0 -4
- package/dist/mutations/customers/deleteCustomerById.mock.d.ts.map +0 -1
- package/dist/mutations/customers/deleteCustomerById.mock.js +0 -8
- package/dist/mutations/customers/deleteCustomerById.mock.js.map +0 -1
- package/dist/mutations/customers/deleteCustomerById.test.d.ts +0 -2
- package/dist/mutations/customers/deleteCustomerById.test.d.ts.map +0 -1
- package/dist/mutations/customers/deleteCustomerById.test.js +0 -10
- package/dist/mutations/customers/deleteCustomerById.test.js.map +0 -1
- package/dist/mutations/orders/cancelOrderById.d.ts +0 -23
- package/dist/mutations/orders/cancelOrderById.d.ts.map +0 -1
- package/dist/mutations/orders/cancelOrderById.js +0 -63
- package/dist/mutations/orders/cancelOrderById.js.map +0 -1
- package/dist/mutations/orders/cancelOrderById.mock.d.ts +0 -15
- package/dist/mutations/orders/cancelOrderById.mock.d.ts.map +0 -1
- package/dist/mutations/orders/cancelOrderById.mock.js +0 -17
- package/dist/mutations/orders/cancelOrderById.mock.js.map +0 -1
- package/dist/mutations/orders/cancelOrderById.test.d.ts +0 -2
- package/dist/mutations/orders/cancelOrderById.test.d.ts.map +0 -1
- package/dist/mutations/orders/cancelOrderById.test.js +0 -42
- package/dist/mutations/orders/cancelOrderById.test.js.map +0 -1
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.d.ts +0 -4
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.d.ts.map +0 -1
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.js +0 -56
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.js.map +0 -1
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.d.ts +0 -3
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.d.ts.map +0 -1
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.js +0 -11
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.mock.js.map +0 -1
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.d.ts +0 -2
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.d.ts.map +0 -1
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.js +0 -11
- package/dist/mutations/productVariantsBulkUpdate/connectMetaObjectToProductVariant.test.js.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.d.ts +0 -13
- package/dist/queries/customers/getCustomersByEmail.d.ts.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.js +0 -26
- package/dist/queries/customers/getCustomersByEmail.js.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.mock.d.ts +0 -8
- package/dist/queries/customers/getCustomersByEmail.mock.d.ts.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.mock.js +0 -54
- package/dist/queries/customers/getCustomersByEmail.mock.js.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.queries.d.ts +0 -2
- package/dist/queries/customers/getCustomersByEmail.queries.d.ts.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.queries.js +0 -41
- package/dist/queries/customers/getCustomersByEmail.queries.js.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.test.d.ts +0 -2
- package/dist/queries/customers/getCustomersByEmail.test.d.ts.map +0 -1
- package/dist/queries/customers/getCustomersByEmail.test.js +0 -29
- package/dist/queries/customers/getCustomersByEmail.test.js.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.d.ts +0 -14
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.d.ts.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.js +0 -27
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.js.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.mock.d.ts +0 -12
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.mock.d.ts.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.mock.js +0 -41
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.mock.js.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.queries.d.ts +0 -2
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.queries.d.ts.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.queries.js +0 -28
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.queries.js.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.test.d.ts +0 -2
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.test.d.ts.map +0 -1
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.test.js +0 -19
- package/dist/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.test.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.d.ts +0 -12
- package/dist/queries/fulfillments/getFulfillmentById.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.js +0 -27
- package/dist/queries/fulfillments/getFulfillmentById.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.mock.d.ts +0 -21
- package/dist/queries/fulfillments/getFulfillmentById.mock.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.mock.js +0 -83
- package/dist/queries/fulfillments/getFulfillmentById.mock.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.queries.d.ts +0 -2
- package/dist/queries/fulfillments/getFulfillmentById.queries.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.queries.js +0 -60
- package/dist/queries/fulfillments/getFulfillmentById.queries.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.test.d.ts +0 -2
- package/dist/queries/fulfillments/getFulfillmentById.test.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentById.test.js +0 -37
- package/dist/queries/fulfillments/getFulfillmentById.test.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.d.ts +0 -14
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.js +0 -36
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.mock.d.ts +0 -5
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.mock.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.mock.js +0 -20
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.mock.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.queries.d.ts +0 -2
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.queries.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.queries.js +0 -13
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.queries.js.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.test.d.ts +0 -2
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.test.d.ts.map +0 -1
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.test.js +0 -61
- package/dist/queries/fulfillments/getFulfillmentTrackingIds.test.js.map +0 -1
- package/dist/queries/orders/getOrderById.d.ts +0 -136
- package/dist/queries/orders/getOrderById.d.ts.map +0 -1
- package/dist/queries/orders/getOrderById.js +0 -126
- package/dist/queries/orders/getOrderById.js.map +0 -1
- package/dist/queries/orders/getOrderById.mock.d.ts +0 -82
- package/dist/queries/orders/getOrderById.mock.d.ts.map +0 -1
- package/dist/queries/orders/getOrderById.mock.js +0 -205
- package/dist/queries/orders/getOrderById.mock.js.map +0 -1
- package/dist/queries/orders/getOrderById.queries.d.ts +0 -3
- package/dist/queries/orders/getOrderById.queries.d.ts.map +0 -1
- package/dist/queries/orders/getOrderById.queries.js +0 -175
- package/dist/queries/orders/getOrderById.queries.js.map +0 -1
- package/dist/queries/orders/getOrderById.test.d.ts +0 -2
- package/dist/queries/orders/getOrderById.test.d.ts.map +0 -1
- package/dist/queries/orders/getOrderById.test.js +0 -46
- package/dist/queries/orders/getOrderById.test.js.map +0 -1
- package/dist/queries/orders/getOrderByName.d.ts +0 -72
- package/dist/queries/orders/getOrderByName.d.ts.map +0 -1
- package/dist/queries/orders/getOrderByName.js +0 -117
- package/dist/queries/orders/getOrderByName.js.map +0 -1
- package/dist/queries/orders/getOrderByName.mock.d.ts +0 -21
- package/dist/queries/orders/getOrderByName.mock.d.ts.map +0 -1
- package/dist/queries/orders/getOrderByName.mock.js +0 -55
- package/dist/queries/orders/getOrderByName.mock.js.map +0 -1
- package/dist/queries/orders/getOrderByName.queries.d.ts +0 -3
- package/dist/queries/orders/getOrderByName.queries.d.ts.map +0 -1
- package/dist/queries/orders/getOrderByName.queries.js +0 -335
- package/dist/queries/orders/getOrderByName.queries.js.map +0 -1
- package/dist/queries/orders/getOrderByName.test.d.ts +0 -2
- package/dist/queries/orders/getOrderByName.test.d.ts.map +0 -1
- package/dist/queries/orders/getOrderByName.test.js +0 -30
- package/dist/queries/orders/getOrderByName.test.js.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.d.ts +0 -12
- package/dist/queries/orders/getOrderCancellationInfo.d.ts.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.js +0 -35
- package/dist/queries/orders/getOrderCancellationInfo.js.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.mock.d.ts +0 -6
- package/dist/queries/orders/getOrderCancellationInfo.mock.d.ts.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.mock.js +0 -29
- package/dist/queries/orders/getOrderCancellationInfo.mock.js.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.queries.d.ts +0 -2
- package/dist/queries/orders/getOrderCancellationInfo.queries.d.ts.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.queries.js +0 -15
- package/dist/queries/orders/getOrderCancellationInfo.queries.js.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.test.d.ts +0 -2
- package/dist/queries/orders/getOrderCancellationInfo.test.d.ts.map +0 -1
- package/dist/queries/orders/getOrderCancellationInfo.test.js +0 -34
- package/dist/queries/orders/getOrderCancellationInfo.test.js.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.d.ts +0 -12
- package/dist/queries/orders/getOrderPaymentDetails.d.ts.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.js +0 -26
- package/dist/queries/orders/getOrderPaymentDetails.js.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.mock.d.ts +0 -10
- package/dist/queries/orders/getOrderPaymentDetails.mock.d.ts.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.mock.js +0 -22
- package/dist/queries/orders/getOrderPaymentDetails.mock.js.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.queries.d.ts +0 -2
- package/dist/queries/orders/getOrderPaymentDetails.queries.d.ts.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.queries.js +0 -21
- package/dist/queries/orders/getOrderPaymentDetails.queries.js.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.test.d.ts +0 -2
- package/dist/queries/orders/getOrderPaymentDetails.test.d.ts.map +0 -1
- package/dist/queries/orders/getOrderPaymentDetails.test.js +0 -19
- package/dist/queries/orders/getOrderPaymentDetails.test.js.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.d.ts +0 -15
- package/dist/queries/orders/getOrdersByCustomerId.d.ts.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.js +0 -32
- package/dist/queries/orders/getOrdersByCustomerId.js.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.mock.d.ts +0 -15
- package/dist/queries/orders/getOrdersByCustomerId.mock.d.ts.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.mock.js +0 -76
- package/dist/queries/orders/getOrdersByCustomerId.mock.js.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.queries.d.ts +0 -2
- package/dist/queries/orders/getOrdersByCustomerId.queries.d.ts.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.queries.js +0 -41
- package/dist/queries/orders/getOrdersByCustomerId.queries.js.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.test.d.ts +0 -2
- package/dist/queries/orders/getOrdersByCustomerId.test.d.ts.map +0 -1
- package/dist/queries/orders/getOrdersByCustomerId.test.js +0 -33
- package/dist/queries/orders/getOrdersByCustomerId.test.js.map +0 -1
- package/dist/queries/productVariants/getLeanProductVariants.d.ts +0 -33
- package/dist/queries/productVariants/getLeanProductVariants.d.ts.map +0 -1
- package/dist/queries/productVariants/getLeanProductVariants.js +0 -81
- package/dist/queries/productVariants/getLeanProductVariants.js.map +0 -1
- package/dist/queries/productVariants/getLeanProductVariants.mock.d.ts +0 -3
- package/dist/queries/productVariants/getLeanProductVariants.mock.d.ts.map +0 -1
- package/dist/queries/productVariants/getLeanProductVariants.mock.js +0 -33
- package/dist/queries/productVariants/getLeanProductVariants.mock.js.map +0 -1
- package/dist/queries/productVariants/getLeanProductVariants.test.d.ts +0 -2
- package/dist/queries/productVariants/getLeanProductVariants.test.d.ts.map +0 -1
- package/dist/queries/productVariants/getLeanProductVariants.test.js +0 -38
- package/dist/queries/productVariants/getLeanProductVariants.test.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -11
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -50
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/mswHandlers.d.ts +0 -8
- package/dist/utils/mswHandlers.d.ts.map +0 -1
- package/dist/utils/mswHandlers.js +0 -67
- package/dist/utils/mswHandlers.js.map +0 -1
- package/dist/utils/parseGid.d.ts +0 -9
- package/dist/utils/parseGid.d.ts.map +0 -1
- package/dist/utils/parseGid.js +0 -12
- package/dist/utils/parseGid.js.map +0 -1
- package/dist/utils/parseGid.test.d.ts +0 -2
- package/dist/utils/parseGid.test.d.ts.map +0 -1
- package/dist/utils/parseGid.test.js +0 -26
- package/dist/utils/parseGid.test.js.map +0 -1
- package/dist/utils/shopifyClient.d.ts +0 -6
- package/dist/utils/shopifyClient.d.ts.map +0 -1
- package/dist/utils/shopifyClient.js +0 -82
- package/dist/utils/shopifyClient.js.map +0 -1
- package/dist/utils/shopifyClient.mock.d.ts +0 -3
- package/dist/utils/shopifyClient.mock.d.ts.map +0 -1
- package/dist/utils/shopifyClient.mock.js +0 -19
- package/dist/utils/shopifyClient.mock.js.map +0 -1
- package/dist/utils/shopifyClient.test.d.ts +0 -2
- package/dist/utils/shopifyClient.test.d.ts.map +0 -1
- package/dist/utils/shopifyClient.test.js +0 -27
- package/dist/utils/shopifyClient.test.js.map +0 -1
- package/dist/utils/shopifyFetch.d.ts +0 -45
- package/dist/utils/shopifyFetch.d.ts.map +0 -1
- package/dist/utils/shopifyFetch.js +0 -89
- package/dist/utils/shopifyFetch.js.map +0 -1
- package/dist/utils/shopifyFetch.test.d.ts +0 -2
- package/dist/utils/shopifyFetch.test.d.ts.map +0 -1
- package/dist/utils/shopifyFetch.test.js +0 -17
- package/dist/utils/shopifyFetch.test.js.map +0 -1
- package/dist/utils/test-setup.d.ts +0 -2
- package/dist/utils/test-setup.d.ts.map +0 -1
- package/dist/utils/test-setup.js +0 -13
- package/dist/utils/test-setup.js.map +0 -1
- package/dist/utils/zod.d.ts +0 -3
- package/dist/utils/zod.d.ts.map +0 -1
- package/dist/utils/zod.js +0 -19
- package/dist/utils/zod.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -31,19 +31,35 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ShopifyUserError: () => ShopifyUserError,
|
|
34
|
+
bulkUpdateProductVariants: () => bulkUpdateProductVariants,
|
|
35
|
+
calculateRefund: () => calculateRefund,
|
|
34
36
|
cancelOrderById: () => cancelOrderById,
|
|
37
|
+
createFile: () => createFile,
|
|
38
|
+
createFulfillment: () => createFulfillment,
|
|
39
|
+
createMetaobjectDefinition: () => createMetaobjectDefinition,
|
|
40
|
+
createRefund: () => createRefund,
|
|
35
41
|
deleteCustomerById: () => deleteCustomerById,
|
|
42
|
+
deleteFilesByIds: () => deleteFilesByIds,
|
|
43
|
+
getAllProductVariants: () => getAllProductVariants,
|
|
44
|
+
getCustomerSegmentMembers: () => getCustomerSegmentMembers,
|
|
45
|
+
getCustomersByEmail: () => getCustomersByEmail,
|
|
46
|
+
getFulfillmentById: () => getFulfillmentById,
|
|
47
|
+
getFulfillmentOrdersByOrderId: () => getFulfillmentOrdersByOrderId,
|
|
48
|
+
getFulfillmentTrackingIds: () => getFulfillmentTrackingIds,
|
|
36
49
|
getLeanProductVariants: () => getLeanProductVariants,
|
|
50
|
+
getMetaobjectByHandle: () => getMetaobjectByHandle,
|
|
37
51
|
getOrderById: () => getOrderById,
|
|
38
52
|
getOrderByName: () => getOrderByName,
|
|
53
|
+
getOrderCancellationInfoByName: () => getOrderCancellationInfoByName,
|
|
39
54
|
getOrderPaymentDetailsById: () => getOrderPaymentDetailsById,
|
|
40
|
-
|
|
55
|
+
getOrdersByCustomerId: () => getOrdersByCustomerId,
|
|
56
|
+
getProductVariantsBySkus: () => getProductVariantsBySkus,
|
|
57
|
+
parseGid: () => parseGid,
|
|
58
|
+
updateFulfillmentTracking: () => updateFulfillmentTracking,
|
|
59
|
+
upsertMetaobject: () => upsertMetaobject
|
|
41
60
|
});
|
|
42
61
|
module.exports = __toCommonJS(index_exports);
|
|
43
62
|
|
|
44
|
-
// src/mutations/customers/deleteCustomerById.ts
|
|
45
|
-
var import_zod3 = __toESM(require("zod"), 1);
|
|
46
|
-
|
|
47
63
|
// src/utils/logger.ts
|
|
48
64
|
var { env } = process;
|
|
49
65
|
var gql = String.raw;
|
|
@@ -92,11 +108,16 @@ var logger = {
|
|
|
92
108
|
};
|
|
93
109
|
|
|
94
110
|
// src/utils/shopifyClient.ts
|
|
95
|
-
var
|
|
111
|
+
var import_shopify_api2 = require("@shopify/shopify-api");
|
|
96
112
|
var import_node = require("@shopify/shopify-api/adapters/node");
|
|
97
113
|
var import_dotenv = __toESM(require("dotenv"), 1);
|
|
98
114
|
var import_zod = require("zod");
|
|
115
|
+
|
|
116
|
+
// src/utils/apiVersion.ts
|
|
117
|
+
var import_shopify_api = require("@shopify/shopify-api");
|
|
99
118
|
var SHOPIFY_API_VERSION = import_shopify_api.ApiVersion.April25;
|
|
119
|
+
|
|
120
|
+
// src/utils/shopifyClient.ts
|
|
100
121
|
import_dotenv.default.config();
|
|
101
122
|
var envSchema = import_zod.z.object({
|
|
102
123
|
SHOPIFY_API_KEY: import_zod.z.string({
|
|
@@ -116,23 +137,23 @@ var envSchema = import_zod.z.object({
|
|
|
116
137
|
var mapLogLevelToShopifySeverity = (level) => {
|
|
117
138
|
switch (level) {
|
|
118
139
|
case "silent":
|
|
119
|
-
return
|
|
140
|
+
return import_shopify_api2.LogSeverity.Error;
|
|
120
141
|
case "debug":
|
|
121
|
-
return
|
|
142
|
+
return import_shopify_api2.LogSeverity.Debug;
|
|
122
143
|
case "info":
|
|
123
|
-
return
|
|
144
|
+
return import_shopify_api2.LogSeverity.Info;
|
|
124
145
|
case "warn":
|
|
125
|
-
return
|
|
146
|
+
return import_shopify_api2.LogSeverity.Warning;
|
|
126
147
|
case "error":
|
|
127
|
-
return
|
|
148
|
+
return import_shopify_api2.LogSeverity.Error;
|
|
128
149
|
default:
|
|
129
|
-
return
|
|
150
|
+
return import_shopify_api2.LogSeverity.Info;
|
|
130
151
|
}
|
|
131
152
|
};
|
|
132
153
|
var shopifyGraphqlClient;
|
|
133
154
|
try {
|
|
134
155
|
const env2 = envSchema.parse(process.env);
|
|
135
|
-
const shopify = (0,
|
|
156
|
+
const shopify = (0, import_shopify_api2.shopifyApi)({
|
|
136
157
|
apiKey: env2.SHOPIFY_API_KEY,
|
|
137
158
|
apiSecretKey: env2.SHOPIFY_API_SECRET,
|
|
138
159
|
hostName: env2.SHOPIFY_API_HOSTNAME,
|
|
@@ -145,7 +166,7 @@ try {
|
|
|
145
166
|
unstable_managedPricingSupport: false
|
|
146
167
|
}
|
|
147
168
|
});
|
|
148
|
-
const shopifySession = new
|
|
169
|
+
const shopifySession = new import_shopify_api2.Session({
|
|
149
170
|
id: `custom-session-${env2.SHOPIFY_API_HOSTNAME}`,
|
|
150
171
|
shop: env2.SHOPIFY_API_HOSTNAME,
|
|
151
172
|
state: "authenticated",
|
|
@@ -171,10 +192,11 @@ function convertIdIntoGid(id, type) {
|
|
|
171
192
|
return `gid://shopify/${type}/${id}`;
|
|
172
193
|
}
|
|
173
194
|
var ShopifyUserError = class extends Error {
|
|
195
|
+
errors;
|
|
174
196
|
constructor(message, errors) {
|
|
175
197
|
super(message);
|
|
176
|
-
this.errors = errors;
|
|
177
198
|
this.name = "ShopifyUserError";
|
|
199
|
+
this.errors = errors;
|
|
178
200
|
}
|
|
179
201
|
};
|
|
180
202
|
async function fetchShopifyGraphql(params) {
|
|
@@ -237,27 +259,9 @@ async function makeRequest(query, variables) {
|
|
|
237
259
|
return response.data;
|
|
238
260
|
}
|
|
239
261
|
|
|
240
|
-
// src/utils/zod.ts
|
|
241
|
-
var import_zod2 = __toESM(require("zod"), 1);
|
|
242
|
-
async function returnOutputParsed(data, Model) {
|
|
243
|
-
const parsed = await Model.safeParseAsync(data);
|
|
244
|
-
if (!parsed.success) {
|
|
245
|
-
if (parsed.error instanceof import_zod2.default.ZodError) {
|
|
246
|
-
const msg = JSON.stringify(parsed.error.format(), null, 2);
|
|
247
|
-
logger.error(msg);
|
|
248
|
-
} else {
|
|
249
|
-
logger.error("Failed to parse:", parsed.error);
|
|
250
|
-
}
|
|
251
|
-
throw new Error("Failed to parse product variants");
|
|
252
|
-
}
|
|
253
|
-
logger.info("Parsed data successfully");
|
|
254
|
-
return parsed.data;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
262
|
// src/mutations/customers/deleteCustomerById.ts
|
|
258
|
-
var DeleteCustomerByIdReturn = import_zod3.default.string().nullable();
|
|
259
263
|
async function deleteCustomerById(customerId) {
|
|
260
|
-
const
|
|
264
|
+
const mutation9 = gql`#graphql
|
|
261
265
|
mutation customerDelete($input: CustomerDeleteInput!) {
|
|
262
266
|
customerDelete(input: $input) {
|
|
263
267
|
deletedCustomerId
|
|
@@ -272,7 +276,7 @@ async function deleteCustomerById(customerId) {
|
|
|
272
276
|
input: { id: customerId }
|
|
273
277
|
};
|
|
274
278
|
const response = await fetchShopifyGraphql({
|
|
275
|
-
query:
|
|
279
|
+
query: mutation9,
|
|
276
280
|
variables,
|
|
277
281
|
dataExtractor: (data) => {
|
|
278
282
|
if (!data.customerDelete) {
|
|
@@ -286,14 +290,368 @@ async function deleteCustomerById(customerId) {
|
|
|
286
290
|
};
|
|
287
291
|
}
|
|
288
292
|
});
|
|
289
|
-
return
|
|
290
|
-
|
|
291
|
-
|
|
293
|
+
return response[0]?.deletedCustomerId ?? void 0;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/mutations/files/deleteFilesByIds.ts
|
|
297
|
+
async function deleteFilesByIds(fileIds) {
|
|
298
|
+
if (fileIds.length === 0) {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
const mutation9 = gql`#graphql
|
|
302
|
+
mutation fileDelete($fileIds: [ID!]!) {
|
|
303
|
+
fileDelete(fileIds: $fileIds) {
|
|
304
|
+
deletedFileIds
|
|
305
|
+
userErrors {
|
|
306
|
+
code
|
|
307
|
+
field
|
|
308
|
+
message
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
`;
|
|
313
|
+
const variables = { fileIds };
|
|
314
|
+
const response = await fetchShopifyGraphql({
|
|
315
|
+
query: mutation9,
|
|
316
|
+
variables,
|
|
317
|
+
dataExtractor: (data) => {
|
|
318
|
+
if (!data.fileDelete) {
|
|
319
|
+
throw new Error("GraphQL response missing 'fileDelete' field");
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
nodes: [{ deletedFileIds: data.fileDelete.deletedFileIds ?? [] }],
|
|
323
|
+
userErrors: data.fileDelete.userErrors
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
return response[0]?.deletedFileIds ?? [];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/mutations/files/createFile.ts
|
|
331
|
+
var mutation = gql`#graphql
|
|
332
|
+
mutation createFile($files: [FileCreateInput!]!) {
|
|
333
|
+
fileCreate(files: $files) {
|
|
334
|
+
files {
|
|
335
|
+
id
|
|
336
|
+
}
|
|
337
|
+
userErrors {
|
|
338
|
+
code
|
|
339
|
+
field
|
|
340
|
+
message
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
`;
|
|
345
|
+
async function createFile(url, altText, filename) {
|
|
346
|
+
if (!url.startsWith("https://")) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`Not a valid public URL (https://) provided for file (url: ${url}).`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
logger.debug(`Creating file: ${filename}`);
|
|
352
|
+
const variables = {
|
|
353
|
+
files: [
|
|
354
|
+
{
|
|
355
|
+
originalSource: url,
|
|
356
|
+
alt: altText,
|
|
357
|
+
filename
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
};
|
|
361
|
+
const result = await fetchShopifyGraphql({
|
|
362
|
+
query: mutation,
|
|
363
|
+
variables,
|
|
364
|
+
dataExtractor: (data) => {
|
|
365
|
+
if (!data.fileCreate) {
|
|
366
|
+
throw new Error("GraphQL response missing 'fileCreate' field");
|
|
367
|
+
}
|
|
368
|
+
const file = data.fileCreate.files?.[0];
|
|
369
|
+
return {
|
|
370
|
+
nodes: file ? [{ id: file.id }] : [],
|
|
371
|
+
userErrors: data.fileCreate.userErrors
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
const fileId = result[0]?.id;
|
|
376
|
+
if (!fileId) {
|
|
377
|
+
throw new Error("File creation returned no result");
|
|
378
|
+
}
|
|
379
|
+
logger.debug(`Successfully created file ${fileId}`);
|
|
380
|
+
return fileId;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/mutations/metaobjectDefinitions/createMetaobjectDefinition.ts
|
|
384
|
+
var mutation2 = gql`#graphql
|
|
385
|
+
mutation createMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
|
|
386
|
+
metaobjectDefinitionCreate(definition: $definition) {
|
|
387
|
+
metaobjectDefinition {
|
|
388
|
+
id
|
|
389
|
+
name
|
|
390
|
+
type
|
|
391
|
+
}
|
|
392
|
+
userErrors {
|
|
393
|
+
code
|
|
394
|
+
field
|
|
395
|
+
message
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
`;
|
|
400
|
+
async function createMetaobjectDefinition(input) {
|
|
401
|
+
logger.debug(`Creating metaobject definition with type: ${input.type}`);
|
|
402
|
+
const variables = {
|
|
403
|
+
definition: {
|
|
404
|
+
type: input.type,
|
|
405
|
+
name: input.name,
|
|
406
|
+
description: input.description,
|
|
407
|
+
displayNameKey: input.displayNameKey,
|
|
408
|
+
fieldDefinitions: input.fieldDefinitions
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
const result = await fetchShopifyGraphql({
|
|
412
|
+
query: mutation2,
|
|
413
|
+
variables,
|
|
414
|
+
dataExtractor: (data) => {
|
|
415
|
+
if (!data.metaobjectDefinitionCreate) {
|
|
416
|
+
throw new Error(
|
|
417
|
+
"GraphQL response missing 'metaobjectDefinitionCreate' field"
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const metaobjectDefinition = data.metaobjectDefinitionCreate.metaobjectDefinition;
|
|
421
|
+
if (!metaobjectDefinition) {
|
|
422
|
+
return {
|
|
423
|
+
nodes: [],
|
|
424
|
+
userErrors: data.metaobjectDefinitionCreate.userErrors
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
nodes: [
|
|
429
|
+
{
|
|
430
|
+
id: metaobjectDefinition.id,
|
|
431
|
+
name: metaobjectDefinition.name,
|
|
432
|
+
type: metaobjectDefinition.type
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
userErrors: data.metaobjectDefinitionCreate.userErrors
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
const definitionResult = result[0];
|
|
440
|
+
if (!definitionResult) {
|
|
441
|
+
throw new Error("Metaobject definition creation returned no result");
|
|
442
|
+
}
|
|
443
|
+
logger.debug(
|
|
444
|
+
`Successfully created metaobject definition ${definitionResult.id}`
|
|
445
|
+
);
|
|
446
|
+
return definitionResult;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/mutations/fulfillments/createFulfillment.ts
|
|
450
|
+
var mutation3 = gql`#graphql
|
|
451
|
+
mutation createFulfillment($fulfillment: FulfillmentInput!) {
|
|
452
|
+
fulfillmentCreate(fulfillment: $fulfillment) {
|
|
453
|
+
fulfillment {
|
|
454
|
+
id
|
|
455
|
+
status
|
|
456
|
+
trackingInfo {
|
|
457
|
+
company
|
|
458
|
+
number
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
userErrors {
|
|
462
|
+
field
|
|
463
|
+
message
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
`;
|
|
468
|
+
function toGid(id, type) {
|
|
469
|
+
if (typeof id === "string" && id.startsWith("gid://")) {
|
|
470
|
+
return id;
|
|
471
|
+
}
|
|
472
|
+
return `gid://shopify/${type}/${id}`;
|
|
473
|
+
}
|
|
474
|
+
async function createFulfillment(fulfillmentOrderId, fulfillmentOrderLineItems, options = {}) {
|
|
475
|
+
const {
|
|
476
|
+
trackingNumber,
|
|
477
|
+
carrier,
|
|
478
|
+
trackingUrl,
|
|
479
|
+
notifyCustomer = true
|
|
480
|
+
} = options;
|
|
481
|
+
const fulfillmentOrderGid = toGid(fulfillmentOrderId, "FulfillmentOrder");
|
|
482
|
+
logger.debug(`Creating fulfillment for order ${fulfillmentOrderGid}`);
|
|
483
|
+
const lineItems = fulfillmentOrderLineItems.map((item) => ({
|
|
484
|
+
id: toGid(item.id, "FulfillmentOrderLineItem"),
|
|
485
|
+
quantity: item.quantity
|
|
486
|
+
}));
|
|
487
|
+
const variables = {
|
|
488
|
+
fulfillment: {
|
|
489
|
+
lineItemsByFulfillmentOrder: [
|
|
490
|
+
{
|
|
491
|
+
fulfillmentOrderId: fulfillmentOrderGid,
|
|
492
|
+
...lineItems.length > 0 ? { fulfillmentOrderLineItems: lineItems } : {}
|
|
493
|
+
}
|
|
494
|
+
],
|
|
495
|
+
notifyCustomer,
|
|
496
|
+
...trackingNumber ? {
|
|
497
|
+
trackingInfo: {
|
|
498
|
+
number: trackingNumber,
|
|
499
|
+
...carrier ? { company: carrier } : {},
|
|
500
|
+
...trackingUrl ? { url: trackingUrl } : {}
|
|
501
|
+
}
|
|
502
|
+
} : {}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const result = await fetchShopifyGraphql({
|
|
506
|
+
query: mutation3,
|
|
507
|
+
variables,
|
|
508
|
+
dataExtractor: (data) => {
|
|
509
|
+
if (!data.fulfillmentCreate) {
|
|
510
|
+
throw new Error("GraphQL response missing 'fulfillmentCreate' field");
|
|
511
|
+
}
|
|
512
|
+
const fulfillment = data.fulfillmentCreate.fulfillment;
|
|
513
|
+
if (!fulfillment) {
|
|
514
|
+
return {
|
|
515
|
+
nodes: [],
|
|
516
|
+
userErrors: data.fulfillmentCreate.userErrors
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
nodes: [
|
|
521
|
+
{
|
|
522
|
+
id: fulfillment.id,
|
|
523
|
+
status: fulfillment.status,
|
|
524
|
+
trackingInfo: fulfillment.trackingInfo.map((info) => ({
|
|
525
|
+
company: info.company ?? null,
|
|
526
|
+
number: info.number ?? null
|
|
527
|
+
}))
|
|
528
|
+
}
|
|
529
|
+
],
|
|
530
|
+
userErrors: data.fulfillmentCreate.userErrors
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
const fulfillmentResult = result[0];
|
|
535
|
+
if (!fulfillmentResult) {
|
|
536
|
+
throw new Error("Fulfillment creation returned no result");
|
|
537
|
+
}
|
|
538
|
+
logger.debug(`Successfully created fulfillment ${fulfillmentResult.id}`);
|
|
539
|
+
return fulfillmentResult;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/queries/fulfillments/getFulfillmentTrackingIds.queries.ts
|
|
543
|
+
var queryFulfillmentTrackingIds = gql`#graphql
|
|
544
|
+
query fulfillmentTrackingIds($id: ID!) {
|
|
545
|
+
fulfillment(id: $id) {
|
|
546
|
+
id
|
|
547
|
+
trackingInfo(first: 50) {
|
|
548
|
+
company
|
|
549
|
+
number
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
`;
|
|
554
|
+
|
|
555
|
+
// src/queries/fulfillments/getFulfillmentTrackingIds.ts
|
|
556
|
+
async function getFulfillmentTrackingIds(id) {
|
|
557
|
+
const gid = typeof id === "string" ? id : convertIdIntoGid(
|
|
558
|
+
typeof id === "number" ? BigInt(id) : id,
|
|
559
|
+
"Fulfillment"
|
|
560
|
+
);
|
|
561
|
+
const variables = { id: gid };
|
|
562
|
+
const response = await fetchShopifyGraphql({
|
|
563
|
+
query: queryFulfillmentTrackingIds,
|
|
564
|
+
variables
|
|
565
|
+
});
|
|
566
|
+
if (!response.fulfillment) {
|
|
567
|
+
logger.debug(`No fulfillment found with ID: ${id}`);
|
|
568
|
+
return void 0;
|
|
569
|
+
}
|
|
570
|
+
const trackingInfo = response.fulfillment.trackingInfo;
|
|
571
|
+
const trackingNumbers = trackingInfo.map((info) => info.number).filter((num) => num != null);
|
|
572
|
+
const trackingCompany = trackingInfo[0]?.company ?? null;
|
|
573
|
+
return {
|
|
574
|
+
trackingNumbers,
|
|
575
|
+
trackingCompany
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// src/mutations/fulfillments/updateFulfillmentTracking.ts
|
|
580
|
+
var mutation4 = gql`#graphql
|
|
581
|
+
mutation updateFulfillmentTracking(
|
|
582
|
+
$fulfillmentId: ID!
|
|
583
|
+
$trackingNumbers: [String!]!
|
|
584
|
+
$company: String
|
|
585
|
+
$notifyCustomer: Boolean
|
|
586
|
+
) {
|
|
587
|
+
fulfillmentTrackingInfoUpdate(
|
|
588
|
+
fulfillmentId: $fulfillmentId
|
|
589
|
+
trackingInfoInput: { numbers: $trackingNumbers, company: $company }
|
|
590
|
+
notifyCustomer: $notifyCustomer
|
|
591
|
+
) {
|
|
592
|
+
fulfillment {
|
|
593
|
+
trackingInfo {
|
|
594
|
+
number
|
|
595
|
+
company
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
userErrors {
|
|
599
|
+
field
|
|
600
|
+
message
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
`;
|
|
605
|
+
async function updateFulfillmentTracking(fulfillmentId, trackingNumber, notifyCustomer = false) {
|
|
606
|
+
const fulfillmentGid = typeof fulfillmentId === "string" ? fulfillmentId : convertIdIntoGid(
|
|
607
|
+
typeof fulfillmentId === "number" ? BigInt(fulfillmentId) : fulfillmentId,
|
|
608
|
+
"Fulfillment"
|
|
609
|
+
);
|
|
610
|
+
logger.debug(`Updating tracking for fulfillment ${fulfillmentGid}`);
|
|
611
|
+
const existingTracking = await getFulfillmentTrackingIds(fulfillmentGid);
|
|
612
|
+
if (!existingTracking) {
|
|
613
|
+
throw new Error(`Fulfillment not found: ${fulfillmentGid}`);
|
|
614
|
+
}
|
|
615
|
+
const updatedTrackingNumbers = existingTracking.trackingNumbers.includes(
|
|
616
|
+
trackingNumber
|
|
617
|
+
) ? existingTracking.trackingNumbers : [...existingTracking.trackingNumbers, trackingNumber];
|
|
618
|
+
const variables = {
|
|
619
|
+
fulfillmentId: fulfillmentGid,
|
|
620
|
+
trackingNumbers: updatedTrackingNumbers,
|
|
621
|
+
...existingTracking.trackingCompany ? { company: existingTracking.trackingCompany } : {},
|
|
622
|
+
notifyCustomer
|
|
623
|
+
};
|
|
624
|
+
const result = await fetchShopifyGraphql({
|
|
625
|
+
query: mutation4,
|
|
626
|
+
variables,
|
|
627
|
+
dataExtractor: (data) => {
|
|
628
|
+
if (!data.fulfillmentTrackingInfoUpdate) {
|
|
629
|
+
throw new Error(
|
|
630
|
+
"GraphQL response missing 'fulfillmentTrackingInfoUpdate' field"
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
const fulfillment = data.fulfillmentTrackingInfoUpdate.fulfillment;
|
|
634
|
+
const trackingInfo = fulfillment?.trackingInfo ?? [];
|
|
635
|
+
const trackingNumbers = trackingInfo.map((info) => info.number).filter((num) => num != null);
|
|
636
|
+
const trackingCompany = trackingInfo[0]?.company ?? null;
|
|
637
|
+
return {
|
|
638
|
+
nodes: [{ trackingNumbers, trackingCompany }],
|
|
639
|
+
userErrors: data.fulfillmentTrackingInfoUpdate.userErrors
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
const trackingResult = result[0];
|
|
644
|
+
if (!trackingResult) {
|
|
645
|
+
throw new Error("Unexpected empty result from GraphQL mutation");
|
|
646
|
+
}
|
|
647
|
+
logger.debug(
|
|
648
|
+
`Successfully updated tracking for fulfillment ${fulfillmentGid}`
|
|
292
649
|
);
|
|
650
|
+
return trackingResult;
|
|
293
651
|
}
|
|
294
652
|
|
|
295
653
|
// src/mutations/orders/cancelOrderById.ts
|
|
296
|
-
var
|
|
654
|
+
var mutation5 = gql`#graphql
|
|
297
655
|
mutation orderCancel($orderId: ID!) {
|
|
298
656
|
orderCancel(
|
|
299
657
|
orderId: $orderId
|
|
@@ -318,7 +676,7 @@ async function cancelOrderById(orderId) {
|
|
|
318
676
|
logger.debug(`Cancelling order ${orderGid}`);
|
|
319
677
|
const variables = { orderId: orderGid };
|
|
320
678
|
await fetchShopifyGraphql({
|
|
321
|
-
query:
|
|
679
|
+
query: mutation5,
|
|
322
680
|
variables,
|
|
323
681
|
dataExtractor: (data) => {
|
|
324
682
|
if (!data.orderCancel) {
|
|
@@ -334,68 +692,474 @@ async function cancelOrderById(orderId) {
|
|
|
334
692
|
return true;
|
|
335
693
|
}
|
|
336
694
|
|
|
337
|
-
// src/
|
|
338
|
-
var
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
query orderById($id: ID!) {
|
|
343
|
-
order(id: $id) {
|
|
344
|
-
id
|
|
345
|
-
name
|
|
346
|
-
createdAt
|
|
347
|
-
updatedAt
|
|
348
|
-
cancelledAt
|
|
349
|
-
cancelReason
|
|
350
|
-
totalPriceSet {
|
|
351
|
-
shopMoney {
|
|
352
|
-
amount
|
|
353
|
-
currencyCode
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
customer {
|
|
695
|
+
// src/mutations/refunds/createRefund.ts
|
|
696
|
+
var mutation6 = gql`#graphql
|
|
697
|
+
mutation createRefund($input: RefundInput!) {
|
|
698
|
+
refundCreate(input: $input) {
|
|
699
|
+
refund {
|
|
357
700
|
id
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
701
|
+
totalRefundedSet {
|
|
702
|
+
shopMoney {
|
|
703
|
+
amount
|
|
704
|
+
currencyCode
|
|
705
|
+
}
|
|
706
|
+
presentmentMoney {
|
|
707
|
+
amount
|
|
708
|
+
currencyCode
|
|
709
|
+
}
|
|
361
710
|
}
|
|
362
|
-
displayName
|
|
363
|
-
firstName
|
|
364
711
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
firstName
|
|
369
|
-
lastName
|
|
370
|
-
address1
|
|
371
|
-
address2
|
|
372
|
-
city
|
|
373
|
-
province
|
|
374
|
-
country
|
|
375
|
-
zip
|
|
712
|
+
userErrors {
|
|
713
|
+
field
|
|
714
|
+
message
|
|
376
715
|
}
|
|
377
716
|
}
|
|
378
717
|
}
|
|
379
718
|
`;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
719
|
+
function toGid2(id, type) {
|
|
720
|
+
if (typeof id === "string" && id.startsWith("gid://")) {
|
|
721
|
+
return id;
|
|
722
|
+
}
|
|
723
|
+
return `gid://shopify/${type}/${id}`;
|
|
724
|
+
}
|
|
725
|
+
async function createRefund(orderId, options = {}) {
|
|
726
|
+
const { currency, note, notify, refundLineItems, shipping, transactions } = options;
|
|
727
|
+
const orderGid = toGid2(orderId, "Order");
|
|
728
|
+
logger.debug(`Creating refund for order ${orderGid}`);
|
|
729
|
+
const variables = {
|
|
730
|
+
input: {
|
|
731
|
+
orderId: orderGid,
|
|
732
|
+
notify,
|
|
733
|
+
...currency ? { currency } : {},
|
|
734
|
+
...note ? { note } : {},
|
|
735
|
+
...refundLineItems?.length ? {
|
|
736
|
+
refundLineItems: refundLineItems.map((item) => ({
|
|
737
|
+
lineItemId: toGid2(item.lineItemId, "LineItem"),
|
|
738
|
+
quantity: item.quantity,
|
|
739
|
+
...item.restockType ? { restockType: item.restockType } : {},
|
|
740
|
+
...item.locationId ? { locationId: toGid2(item.locationId, "Location") } : {}
|
|
741
|
+
}))
|
|
742
|
+
} : {},
|
|
743
|
+
...shipping ? {
|
|
744
|
+
shipping: {
|
|
745
|
+
...shipping.fullRefund !== void 0 ? { fullRefund: shipping.fullRefund } : {},
|
|
746
|
+
...shipping.amount ? { amount: shipping.amount } : {}
|
|
395
747
|
}
|
|
748
|
+
} : {},
|
|
749
|
+
...transactions?.length ? {
|
|
750
|
+
transactions: transactions.map((t) => ({
|
|
751
|
+
amount: t.amount,
|
|
752
|
+
gateway: t.gateway,
|
|
753
|
+
kind: "REFUND" /* Refund */,
|
|
754
|
+
orderId: orderGid,
|
|
755
|
+
...t.parentId ? { parentId: toGid2(t.parentId, "OrderTransaction") } : {}
|
|
756
|
+
}))
|
|
757
|
+
} : {}
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
const result = await fetchShopifyGraphql({
|
|
761
|
+
query: mutation6,
|
|
762
|
+
variables,
|
|
763
|
+
dataExtractor: (data) => {
|
|
764
|
+
if (!data.refundCreate) {
|
|
765
|
+
throw new Error("GraphQL response missing 'refundCreate' field");
|
|
396
766
|
}
|
|
397
|
-
|
|
398
|
-
|
|
767
|
+
const refund = data.refundCreate.refund;
|
|
768
|
+
if (!refund) {
|
|
769
|
+
return {
|
|
770
|
+
nodes: [],
|
|
771
|
+
userErrors: data.refundCreate.userErrors
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
return {
|
|
775
|
+
nodes: [
|
|
776
|
+
{
|
|
777
|
+
id: refund.id,
|
|
778
|
+
totalRefunded: {
|
|
779
|
+
shopMoney: {
|
|
780
|
+
amount: refund.totalRefundedSet.shopMoney.amount,
|
|
781
|
+
currencyCode: refund.totalRefundedSet.shopMoney.currencyCode
|
|
782
|
+
},
|
|
783
|
+
presentmentMoney: {
|
|
784
|
+
amount: refund.totalRefundedSet.presentmentMoney.amount,
|
|
785
|
+
currencyCode: refund.totalRefundedSet.presentmentMoney.currencyCode
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
],
|
|
790
|
+
userErrors: data.refundCreate.userErrors
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
const refundResult = result[0];
|
|
795
|
+
if (!refundResult) {
|
|
796
|
+
throw new Error("Refund creation returned no result");
|
|
797
|
+
}
|
|
798
|
+
logger.debug(`Successfully created refund ${refundResult.id}`);
|
|
799
|
+
return refundResult;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/mutations/productVariantsBulkUpdate/bulkUpdateProductVariants.ts
|
|
803
|
+
var mutation7 = gql`#graphql
|
|
804
|
+
mutation bulkUpdateProductVariants(
|
|
805
|
+
$productId: ID!
|
|
806
|
+
$variants: [ProductVariantsBulkInput!]!
|
|
807
|
+
) {
|
|
808
|
+
productVariantsBulkUpdate(
|
|
809
|
+
productId: $productId
|
|
810
|
+
variants: $variants
|
|
811
|
+
) {
|
|
812
|
+
productVariants {
|
|
813
|
+
id
|
|
814
|
+
sku
|
|
815
|
+
}
|
|
816
|
+
userErrors {
|
|
817
|
+
code
|
|
818
|
+
field
|
|
819
|
+
message
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
`;
|
|
824
|
+
async function bulkUpdateProductVariants(productId, variants) {
|
|
825
|
+
logger.debug(
|
|
826
|
+
`Bulk updating ${variants.length} variants for product ${productId}`
|
|
827
|
+
);
|
|
828
|
+
const variables = {
|
|
829
|
+
productId,
|
|
830
|
+
variants
|
|
831
|
+
};
|
|
832
|
+
const result = await fetchShopifyGraphql({
|
|
833
|
+
query: mutation7,
|
|
834
|
+
variables,
|
|
835
|
+
dataExtractor: (data) => {
|
|
836
|
+
if (!data.productVariantsBulkUpdate) {
|
|
837
|
+
throw new Error(
|
|
838
|
+
"GraphQL response missing 'productVariantsBulkUpdate' field"
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
nodes: (data.productVariantsBulkUpdate.productVariants ?? []).map(
|
|
843
|
+
(v) => ({
|
|
844
|
+
id: v.id,
|
|
845
|
+
sku: v.sku ?? null
|
|
846
|
+
})
|
|
847
|
+
),
|
|
848
|
+
userErrors: data.productVariantsBulkUpdate.userErrors
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
logger.debug(`Successfully updated ${result.length} variants`);
|
|
853
|
+
return result;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// src/mutations/metaobjects/upsertMetaobject.ts
|
|
857
|
+
var mutation8 = gql`#graphql
|
|
858
|
+
mutation upsertMetaobject(
|
|
859
|
+
$handle: MetaobjectHandleInput!
|
|
860
|
+
$metaobject: MetaobjectUpsertInput!
|
|
861
|
+
) {
|
|
862
|
+
metaobjectUpsert(handle: $handle, metaobject: $metaobject) {
|
|
863
|
+
metaobject {
|
|
864
|
+
id
|
|
865
|
+
handle
|
|
866
|
+
displayName
|
|
867
|
+
fields {
|
|
868
|
+
key
|
|
869
|
+
value
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
userErrors {
|
|
873
|
+
code
|
|
874
|
+
field
|
|
875
|
+
message
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
`;
|
|
880
|
+
async function upsertMetaobject(input) {
|
|
881
|
+
const { type, handle, fields } = input;
|
|
882
|
+
logger.debug(`Upserting metaobject type=${type} handle=${handle}`);
|
|
883
|
+
const variables = {
|
|
884
|
+
handle: { type, handle },
|
|
885
|
+
metaobject: { fields }
|
|
886
|
+
};
|
|
887
|
+
const response = await fetchShopifyGraphql({
|
|
888
|
+
query: mutation8,
|
|
889
|
+
variables,
|
|
890
|
+
dataExtractor: (data) => {
|
|
891
|
+
if (!data.metaobjectUpsert) {
|
|
892
|
+
throw new Error("GraphQL response missing 'metaobjectUpsert' field");
|
|
893
|
+
}
|
|
894
|
+
const { metaobject, userErrors } = data.metaobjectUpsert;
|
|
895
|
+
return {
|
|
896
|
+
nodes: metaobject ? [
|
|
897
|
+
{
|
|
898
|
+
id: metaobject.id,
|
|
899
|
+
handle: metaobject.handle,
|
|
900
|
+
displayName: metaobject.displayName,
|
|
901
|
+
fields: metaobject.fields.map((f) => ({
|
|
902
|
+
key: f.key,
|
|
903
|
+
value: f.value ?? null
|
|
904
|
+
}))
|
|
905
|
+
}
|
|
906
|
+
] : [],
|
|
907
|
+
userErrors
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
const result = response[0];
|
|
912
|
+
if (!result) {
|
|
913
|
+
throw new Error("No metaobject returned from upsert operation");
|
|
914
|
+
}
|
|
915
|
+
logger.debug(`Metaobject upserted successfully: ${result.id}`);
|
|
916
|
+
return result;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// src/queries/orders/calculateRefund.queries.ts
|
|
920
|
+
var querySuggestedRefund = gql`#graphql
|
|
921
|
+
query suggestedRefund(
|
|
922
|
+
$orderId: ID!
|
|
923
|
+
$refundLineItems: [RefundLineItemInput!]
|
|
924
|
+
$refundShipping: Boolean
|
|
925
|
+
$shippingAmount: Money
|
|
926
|
+
$suggestFullRefund: Boolean
|
|
927
|
+
) {
|
|
928
|
+
order(id: $orderId) {
|
|
929
|
+
id
|
|
930
|
+
name
|
|
931
|
+
suggestedRefund(
|
|
932
|
+
refundLineItems: $refundLineItems
|
|
933
|
+
refundShipping: $refundShipping
|
|
934
|
+
shippingAmount: $shippingAmount
|
|
935
|
+
suggestFullRefund: $suggestFullRefund
|
|
936
|
+
) {
|
|
937
|
+
amountSet {
|
|
938
|
+
shopMoney {
|
|
939
|
+
amount
|
|
940
|
+
currencyCode
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
maximumRefundableSet {
|
|
944
|
+
shopMoney {
|
|
945
|
+
amount
|
|
946
|
+
currencyCode
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
subtotalSet {
|
|
950
|
+
shopMoney {
|
|
951
|
+
amount
|
|
952
|
+
currencyCode
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
totalTaxSet {
|
|
956
|
+
shopMoney {
|
|
957
|
+
amount
|
|
958
|
+
currencyCode
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
discountedSubtotalSet {
|
|
962
|
+
shopMoney {
|
|
963
|
+
amount
|
|
964
|
+
currencyCode
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
totalCartDiscountAmountSet {
|
|
968
|
+
shopMoney {
|
|
969
|
+
amount
|
|
970
|
+
currencyCode
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
shipping {
|
|
974
|
+
amountSet {
|
|
975
|
+
shopMoney {
|
|
976
|
+
amount
|
|
977
|
+
currencyCode
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
maximumRefundableSet {
|
|
981
|
+
shopMoney {
|
|
982
|
+
amount
|
|
983
|
+
currencyCode
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
refundLineItems {
|
|
988
|
+
lineItem {
|
|
989
|
+
id
|
|
990
|
+
sku
|
|
991
|
+
title
|
|
992
|
+
quantity
|
|
993
|
+
}
|
|
994
|
+
quantity
|
|
995
|
+
priceSet {
|
|
996
|
+
shopMoney {
|
|
997
|
+
amount
|
|
998
|
+
currencyCode
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
subtotalSet {
|
|
1002
|
+
shopMoney {
|
|
1003
|
+
amount
|
|
1004
|
+
currencyCode
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
totalTaxSet {
|
|
1008
|
+
shopMoney {
|
|
1009
|
+
amount
|
|
1010
|
+
currencyCode
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
restockType
|
|
1014
|
+
}
|
|
1015
|
+
suggestedTransactions {
|
|
1016
|
+
gateway
|
|
1017
|
+
kind
|
|
1018
|
+
amountSet {
|
|
1019
|
+
shopMoney {
|
|
1020
|
+
amount
|
|
1021
|
+
currencyCode
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
maximumRefundableSet {
|
|
1025
|
+
shopMoney {
|
|
1026
|
+
amount
|
|
1027
|
+
currencyCode
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
parentTransaction {
|
|
1031
|
+
id
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
`;
|
|
1038
|
+
|
|
1039
|
+
// src/queries/orders/calculateRefund.ts
|
|
1040
|
+
function convertLineItemIdToGid(id) {
|
|
1041
|
+
if (typeof id === "string") {
|
|
1042
|
+
return id.startsWith("gid://") ? id : `gid://shopify/LineItem/${id}`;
|
|
1043
|
+
}
|
|
1044
|
+
return `gid://shopify/LineItem/${id}`;
|
|
1045
|
+
}
|
|
1046
|
+
function mapRestockType(restockType) {
|
|
1047
|
+
switch (restockType) {
|
|
1048
|
+
case "CANCEL":
|
|
1049
|
+
return "CANCEL" /* Cancel */;
|
|
1050
|
+
case "RETURN":
|
|
1051
|
+
return "RETURN" /* Return */;
|
|
1052
|
+
default:
|
|
1053
|
+
return "NO_RESTOCK" /* NoRestock */;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
async function calculateRefund(orderId, options = {}) {
|
|
1057
|
+
const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
|
|
1058
|
+
typeof orderId === "number" ? BigInt(orderId) : orderId,
|
|
1059
|
+
"Order"
|
|
1060
|
+
);
|
|
1061
|
+
const variables = {
|
|
1062
|
+
orderId: orderGid,
|
|
1063
|
+
refundLineItems: options.refundLineItems?.map((item) => ({
|
|
1064
|
+
lineItemId: convertLineItemIdToGid(item.lineItemId),
|
|
1065
|
+
quantity: item.quantity,
|
|
1066
|
+
restockType: mapRestockType(item.restockType),
|
|
1067
|
+
...item.locationId ? { locationId: item.locationId } : {}
|
|
1068
|
+
})),
|
|
1069
|
+
refundShipping: options.refundShipping,
|
|
1070
|
+
shippingAmount: options.shippingAmount,
|
|
1071
|
+
suggestFullRefund: options.suggestFullRefund
|
|
1072
|
+
};
|
|
1073
|
+
const response = await fetchShopifyGraphql({
|
|
1074
|
+
query: querySuggestedRefund,
|
|
1075
|
+
variables
|
|
1076
|
+
});
|
|
1077
|
+
if (!response.order?.suggestedRefund) {
|
|
1078
|
+
logger.debug(`No refund suggestion available for order: ${orderId}`);
|
|
1079
|
+
return void 0;
|
|
1080
|
+
}
|
|
1081
|
+
return response.order.suggestedRefund;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// src/queries/orders/getOrderById.ts
|
|
1085
|
+
var import_zod3 = __toESM(require("zod"), 1);
|
|
1086
|
+
|
|
1087
|
+
// src/utils/zod.ts
|
|
1088
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
1089
|
+
async function returnOutputParsed(data, Model) {
|
|
1090
|
+
const parsed = await Model.safeParseAsync(data);
|
|
1091
|
+
if (!parsed.success) {
|
|
1092
|
+
if (parsed.error instanceof import_zod2.default.ZodError) {
|
|
1093
|
+
const msg = JSON.stringify(parsed.error.format(), null, 2);
|
|
1094
|
+
logger.error(msg);
|
|
1095
|
+
} else {
|
|
1096
|
+
logger.error("Failed to parse:", parsed.error);
|
|
1097
|
+
}
|
|
1098
|
+
throw new Error("Failed to parse product variants");
|
|
1099
|
+
}
|
|
1100
|
+
logger.info("Parsed data successfully");
|
|
1101
|
+
return parsed.data;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// src/queries/orders/getOrderById.queries.ts
|
|
1105
|
+
var queryOrderById = gql`#graphql
|
|
1106
|
+
query orderById($id: ID!) {
|
|
1107
|
+
order(id: $id) {
|
|
1108
|
+
id
|
|
1109
|
+
name
|
|
1110
|
+
createdAt
|
|
1111
|
+
updatedAt
|
|
1112
|
+
cancelledAt
|
|
1113
|
+
cancelReason
|
|
1114
|
+
totalPriceSet {
|
|
1115
|
+
shopMoney {
|
|
1116
|
+
amount
|
|
1117
|
+
currencyCode
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
customer {
|
|
1121
|
+
id
|
|
1122
|
+
lastName
|
|
1123
|
+
defaultEmailAddress {
|
|
1124
|
+
emailAddress
|
|
1125
|
+
}
|
|
1126
|
+
displayName
|
|
1127
|
+
firstName
|
|
1128
|
+
}
|
|
1129
|
+
displayFinancialStatus
|
|
1130
|
+
displayFulfillmentStatus
|
|
1131
|
+
shippingAddress {
|
|
1132
|
+
firstName
|
|
1133
|
+
lastName
|
|
1134
|
+
address1
|
|
1135
|
+
address2
|
|
1136
|
+
city
|
|
1137
|
+
province
|
|
1138
|
+
country
|
|
1139
|
+
zip
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
`;
|
|
1144
|
+
var queryOrderByIdFull = gql`#graphql
|
|
1145
|
+
query orderByIdFull($id: ID!) {
|
|
1146
|
+
order(id: $id) {
|
|
1147
|
+
id
|
|
1148
|
+
name
|
|
1149
|
+
createdAt
|
|
1150
|
+
updatedAt
|
|
1151
|
+
processedAt
|
|
1152
|
+
closedAt
|
|
1153
|
+
cancelledAt
|
|
1154
|
+
cancelReason
|
|
1155
|
+
totalPriceSet {
|
|
1156
|
+
shopMoney {
|
|
1157
|
+
amount
|
|
1158
|
+
currencyCode
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
customer {
|
|
1162
|
+
id
|
|
399
1163
|
firstName
|
|
400
1164
|
lastName
|
|
401
1165
|
email
|
|
@@ -513,38 +1277,38 @@ var queryOrderByIdFull = gql`#graphql
|
|
|
513
1277
|
`;
|
|
514
1278
|
|
|
515
1279
|
// src/queries/orders/getOrderById.ts
|
|
516
|
-
var AddressSchema =
|
|
517
|
-
firstName:
|
|
518
|
-
lastName:
|
|
519
|
-
address1:
|
|
520
|
-
address2:
|
|
521
|
-
city:
|
|
522
|
-
province:
|
|
523
|
-
country:
|
|
524
|
-
zip:
|
|
1280
|
+
var AddressSchema = import_zod3.default.object({
|
|
1281
|
+
firstName: import_zod3.default.string().nullable(),
|
|
1282
|
+
lastName: import_zod3.default.string().nullable(),
|
|
1283
|
+
address1: import_zod3.default.string().nullable(),
|
|
1284
|
+
address2: import_zod3.default.string().nullable(),
|
|
1285
|
+
city: import_zod3.default.string().nullable(),
|
|
1286
|
+
province: import_zod3.default.string().nullable(),
|
|
1287
|
+
country: import_zod3.default.string().nullable(),
|
|
1288
|
+
zip: import_zod3.default.string().nullable()
|
|
525
1289
|
}).nullable();
|
|
526
|
-
var GetLeanOrderByIdReturn =
|
|
527
|
-
id:
|
|
528
|
-
name:
|
|
529
|
-
createdAt:
|
|
530
|
-
updatedAt:
|
|
531
|
-
cancelledAt:
|
|
532
|
-
cancelReason:
|
|
533
|
-
totalPrice:
|
|
534
|
-
amount:
|
|
535
|
-
currencyCode:
|
|
1290
|
+
var GetLeanOrderByIdReturn = import_zod3.default.object({
|
|
1291
|
+
id: import_zod3.default.string(),
|
|
1292
|
+
name: import_zod3.default.string(),
|
|
1293
|
+
createdAt: import_zod3.default.string(),
|
|
1294
|
+
updatedAt: import_zod3.default.string(),
|
|
1295
|
+
cancelledAt: import_zod3.default.string().nullable(),
|
|
1296
|
+
cancelReason: import_zod3.default.string().nullable(),
|
|
1297
|
+
totalPrice: import_zod3.default.object({
|
|
1298
|
+
amount: import_zod3.default.string(),
|
|
1299
|
+
currencyCode: import_zod3.default.string()
|
|
536
1300
|
}),
|
|
537
|
-
customer:
|
|
538
|
-
id:
|
|
539
|
-
displayName:
|
|
540
|
-
firstName:
|
|
541
|
-
lastName:
|
|
542
|
-
emailAddress:
|
|
1301
|
+
customer: import_zod3.default.object({
|
|
1302
|
+
id: import_zod3.default.string(),
|
|
1303
|
+
displayName: import_zod3.default.string(),
|
|
1304
|
+
firstName: import_zod3.default.string().nullable(),
|
|
1305
|
+
lastName: import_zod3.default.string().nullable(),
|
|
1306
|
+
emailAddress: import_zod3.default.string().nullable()
|
|
543
1307
|
}).nullable(),
|
|
544
|
-
financialStatus:
|
|
545
|
-
fulfillmentStatus:
|
|
1308
|
+
financialStatus: import_zod3.default.string().nullable(),
|
|
1309
|
+
fulfillmentStatus: import_zod3.default.string().nullable(),
|
|
546
1310
|
shippingAddress: AddressSchema
|
|
547
|
-
})
|
|
1311
|
+
});
|
|
548
1312
|
async function getOrderById(id, detailLevel = "lean") {
|
|
549
1313
|
const bigIntId = typeof id === "number" ? BigInt(id) : id;
|
|
550
1314
|
if (detailLevel === "lean") {
|
|
@@ -562,7 +1326,7 @@ async function getLeanOrderById(id) {
|
|
|
562
1326
|
});
|
|
563
1327
|
if (!response.order) {
|
|
564
1328
|
logger.debug(`No order found with ID: ${id}`);
|
|
565
|
-
return
|
|
1329
|
+
return void 0;
|
|
566
1330
|
}
|
|
567
1331
|
const order = response.order;
|
|
568
1332
|
const leanOrder = {
|
|
@@ -608,13 +1372,13 @@ async function getFullOrderById(id) {
|
|
|
608
1372
|
});
|
|
609
1373
|
if (!response.order) {
|
|
610
1374
|
logger.debug(`No order found with ID: ${id}`);
|
|
611
|
-
return
|
|
1375
|
+
return void 0;
|
|
612
1376
|
}
|
|
613
1377
|
return response.order;
|
|
614
1378
|
}
|
|
615
1379
|
|
|
616
1380
|
// src/queries/orders/getOrderByName.ts
|
|
617
|
-
var
|
|
1381
|
+
var import_zod5 = __toESM(require("zod"), 1);
|
|
618
1382
|
|
|
619
1383
|
// src/queries/orders/getOrderByName.queries.ts
|
|
620
1384
|
var queryOrdersByName = gql`#graphql
|
|
@@ -952,23 +1716,23 @@ var queryOrdersByNameFull = gql`#graphql
|
|
|
952
1716
|
`;
|
|
953
1717
|
|
|
954
1718
|
// src/queries/orders/getOrderByName.ts
|
|
955
|
-
var GetLeanOrderByNameReturn =
|
|
956
|
-
id:
|
|
957
|
-
name:
|
|
958
|
-
createdAt:
|
|
959
|
-
updatedAt:
|
|
960
|
-
totalPrice:
|
|
961
|
-
amount:
|
|
962
|
-
currencyCode:
|
|
1719
|
+
var GetLeanOrderByNameReturn = import_zod5.default.object({
|
|
1720
|
+
id: import_zod5.default.string(),
|
|
1721
|
+
name: import_zod5.default.string(),
|
|
1722
|
+
createdAt: import_zod5.default.string(),
|
|
1723
|
+
updatedAt: import_zod5.default.string(),
|
|
1724
|
+
totalPrice: import_zod5.default.object({
|
|
1725
|
+
amount: import_zod5.default.string(),
|
|
1726
|
+
currencyCode: import_zod5.default.string()
|
|
963
1727
|
}),
|
|
964
|
-
customer:
|
|
965
|
-
id:
|
|
966
|
-
displayName:
|
|
967
|
-
emailAddress:
|
|
1728
|
+
customer: import_zod5.default.object({
|
|
1729
|
+
id: import_zod5.default.string(),
|
|
1730
|
+
displayName: import_zod5.default.string(),
|
|
1731
|
+
emailAddress: import_zod5.default.string().nullable()
|
|
968
1732
|
}).nullable(),
|
|
969
|
-
financialStatus:
|
|
970
|
-
fulfillmentStatus:
|
|
971
|
-
})
|
|
1733
|
+
financialStatus: import_zod5.default.string().nullable(),
|
|
1734
|
+
fulfillmentStatus: import_zod5.default.string().nullable()
|
|
1735
|
+
});
|
|
972
1736
|
async function getOrderByName(orderName, detailLevel = "lean") {
|
|
973
1737
|
if (detailLevel === "lean") {
|
|
974
1738
|
return getLeanOrderByName(orderName);
|
|
@@ -1001,7 +1765,7 @@ async function getLeanOrderByName(orderName) {
|
|
|
1001
1765
|
const order = extractedNodes[0];
|
|
1002
1766
|
if (!order) {
|
|
1003
1767
|
logger.debug(`No order found with name: ${orderName}`);
|
|
1004
|
-
return
|
|
1768
|
+
return void 0;
|
|
1005
1769
|
}
|
|
1006
1770
|
const leanOrder = {
|
|
1007
1771
|
id: order.id,
|
|
@@ -1047,25 +1811,69 @@ async function getFullOrderByName(orderName) {
|
|
|
1047
1811
|
});
|
|
1048
1812
|
if (extractedNodes.length === 0) {
|
|
1049
1813
|
logger.debug(`No order found with name: ${orderName}`);
|
|
1050
|
-
return
|
|
1814
|
+
return void 0;
|
|
1051
1815
|
}
|
|
1052
1816
|
const order = extractedNodes[0];
|
|
1053
1817
|
if (!order) {
|
|
1054
1818
|
logger.debug(`No order found with name: ${orderName}`);
|
|
1055
|
-
return
|
|
1819
|
+
return void 0;
|
|
1820
|
+
}
|
|
1821
|
+
return order;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// src/queries/orders/getOrderCancellationInfo.queries.ts
|
|
1825
|
+
var queryOrderCancellationInfoByName = gql`#graphql
|
|
1826
|
+
query orderCancellationInfoByName($first: Int!, $queryFilter: String!) {
|
|
1827
|
+
orders(first: $first, query: $queryFilter) {
|
|
1828
|
+
edges {
|
|
1829
|
+
node {
|
|
1830
|
+
id
|
|
1831
|
+
name
|
|
1832
|
+
cancelledAt
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
`;
|
|
1838
|
+
|
|
1839
|
+
// src/queries/orders/getOrderCancellationInfo.ts
|
|
1840
|
+
async function getOrderCancellationInfoByName(orderName) {
|
|
1841
|
+
const variables = {
|
|
1842
|
+
first: 1,
|
|
1843
|
+
queryFilter: `name:${orderName}`
|
|
1844
|
+
};
|
|
1845
|
+
const response = await fetchShopifyGraphql({
|
|
1846
|
+
query: queryOrderCancellationInfoByName,
|
|
1847
|
+
variables
|
|
1848
|
+
});
|
|
1849
|
+
if (!response.orders) {
|
|
1850
|
+
throw new Error(
|
|
1851
|
+
"Invalid GraphQL response for getOrderCancellationInfoByName: 'orders' field is missing."
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
if (!Array.isArray(response.orders.edges)) {
|
|
1855
|
+
throw new Error(
|
|
1856
|
+
"Invalid GraphQL response for getOrderCancellationInfoByName: 'orders.edges' is not an array."
|
|
1857
|
+
);
|
|
1858
|
+
}
|
|
1859
|
+
const firstEdge = response.orders.edges[0];
|
|
1860
|
+
const order = firstEdge?.node;
|
|
1861
|
+
if (!order) {
|
|
1862
|
+
logger.debug(`No order found with name: ${orderName}`);
|
|
1863
|
+
return void 0;
|
|
1056
1864
|
}
|
|
1057
1865
|
return order;
|
|
1058
1866
|
}
|
|
1059
1867
|
|
|
1060
1868
|
// src/queries/productVariants/getLeanProductVariants.ts
|
|
1061
|
-
var
|
|
1062
|
-
var GetLeanProductVariantsReturn =
|
|
1063
|
-
|
|
1064
|
-
productId:
|
|
1065
|
-
productTitle:
|
|
1066
|
-
variantId:
|
|
1067
|
-
variantTitle:
|
|
1068
|
-
sku:
|
|
1869
|
+
var import_zod7 = __toESM(require("zod"), 1);
|
|
1870
|
+
var GetLeanProductVariantsReturn = import_zod7.default.array(
|
|
1871
|
+
import_zod7.default.object({
|
|
1872
|
+
productId: import_zod7.default.string(),
|
|
1873
|
+
productTitle: import_zod7.default.string(),
|
|
1874
|
+
variantId: import_zod7.default.string(),
|
|
1875
|
+
variantTitle: import_zod7.default.string(),
|
|
1876
|
+
sku: import_zod7.default.string()
|
|
1069
1877
|
})
|
|
1070
1878
|
);
|
|
1071
1879
|
async function getLeanProductVariants(skus) {
|
|
@@ -1133,9 +1941,182 @@ async function getLeanProductVariants(skus) {
|
|
|
1133
1941
|
return await returnOutputParsed(allVariants, GetLeanProductVariantsReturn);
|
|
1134
1942
|
}
|
|
1135
1943
|
|
|
1136
|
-
// src/queries/
|
|
1944
|
+
// src/queries/productVariants/getProductVariantsBySkus.ts
|
|
1945
|
+
var import_zod9 = __toESM(require("zod"), 1);
|
|
1946
|
+
var GetProductVariantsBySkusReturn = import_zod9.default.array(
|
|
1947
|
+
import_zod9.default.object({
|
|
1948
|
+
productId: import_zod9.default.string(),
|
|
1949
|
+
productTitle: import_zod9.default.string(),
|
|
1950
|
+
variantId: import_zod9.default.string(),
|
|
1951
|
+
variantTitle: import_zod9.default.string(),
|
|
1952
|
+
sku: import_zod9.default.string(),
|
|
1953
|
+
status: import_zod9.default.enum(["ACTIVE", "ARCHIVED", "DRAFT"])
|
|
1954
|
+
})
|
|
1955
|
+
);
|
|
1956
|
+
async function getProductVariantsBySkus(skus, options) {
|
|
1957
|
+
if (skus.length === 0) {
|
|
1958
|
+
return [];
|
|
1959
|
+
}
|
|
1960
|
+
const queryGql = gql`#graphql
|
|
1961
|
+
query productVariantsBySkus($first: Int!, $after: String, $queryFilter: String) {
|
|
1962
|
+
productVariants(first: $first, after: $after, query: $queryFilter) {
|
|
1963
|
+
edges {
|
|
1964
|
+
node {
|
|
1965
|
+
id
|
|
1966
|
+
title
|
|
1967
|
+
sku
|
|
1968
|
+
product {
|
|
1969
|
+
id
|
|
1970
|
+
title
|
|
1971
|
+
status
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
pageInfo {
|
|
1976
|
+
hasNextPage
|
|
1977
|
+
endCursor
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
`;
|
|
1982
|
+
const skuFilter = skus.map((sku) => `sku:${sku}`).join(" OR ");
|
|
1983
|
+
const statusFilter = options?.activeOnly ? "product_status:active,draft" : "";
|
|
1984
|
+
const queryFilter = [skuFilter, statusFilter].filter(Boolean).join(" AND ");
|
|
1985
|
+
const initialVariables = {
|
|
1986
|
+
first: 250,
|
|
1987
|
+
queryFilter
|
|
1988
|
+
};
|
|
1989
|
+
const extractedNodes = await fetchShopifyGraphql({
|
|
1990
|
+
query: queryGql,
|
|
1991
|
+
variables: initialVariables,
|
|
1992
|
+
dataExtractor: (pageData) => {
|
|
1993
|
+
if (!pageData.productVariants) {
|
|
1994
|
+
throw new Error(
|
|
1995
|
+
"GraphQL response for product variants is missing the 'productVariants' field."
|
|
1996
|
+
);
|
|
1997
|
+
}
|
|
1998
|
+
const nodes = pageData.productVariants.edges.map(
|
|
1999
|
+
(edge) => edge.node
|
|
2000
|
+
);
|
|
2001
|
+
return {
|
|
2002
|
+
nodes,
|
|
2003
|
+
pageInfo: pageData.productVariants.pageInfo
|
|
2004
|
+
};
|
|
2005
|
+
},
|
|
2006
|
+
fetchAllPages: true
|
|
2007
|
+
});
|
|
2008
|
+
const allVariants = extractedNodes.flatMap((v) => {
|
|
2009
|
+
if (!v.sku) {
|
|
2010
|
+
logger.debug(
|
|
2011
|
+
`Product ${v.product.title} (ID: ${v.product.id}) has a variant (ID: ${v.id}) with no SKU. Filtering out.`
|
|
2012
|
+
);
|
|
2013
|
+
return [];
|
|
2014
|
+
}
|
|
2015
|
+
return [
|
|
2016
|
+
{
|
|
2017
|
+
productId: v.product.id,
|
|
2018
|
+
productTitle: v.product.title,
|
|
2019
|
+
variantId: v.id,
|
|
2020
|
+
variantTitle: v.title,
|
|
2021
|
+
sku: v.sku,
|
|
2022
|
+
status: v.product.status
|
|
2023
|
+
}
|
|
2024
|
+
];
|
|
2025
|
+
});
|
|
2026
|
+
return await returnOutputParsed(allVariants, GetProductVariantsBySkusReturn);
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
// src/queries/productVariants/getAllProductVariants.ts
|
|
1137
2030
|
var import_zod11 = __toESM(require("zod"), 1);
|
|
1138
2031
|
|
|
2032
|
+
// src/queries/productVariants/getAllProductVariants.queries.ts
|
|
2033
|
+
var queryAllProductVariants = gql`#graphql
|
|
2034
|
+
query allProductVariants($first: Int!, $after: String) {
|
|
2035
|
+
productVariants(first: $first, after: $after) {
|
|
2036
|
+
edges {
|
|
2037
|
+
node {
|
|
2038
|
+
id
|
|
2039
|
+
legacyResourceId
|
|
2040
|
+
sku
|
|
2041
|
+
barcode
|
|
2042
|
+
inventoryQuantity
|
|
2043
|
+
price
|
|
2044
|
+
title
|
|
2045
|
+
product {
|
|
2046
|
+
status
|
|
2047
|
+
title
|
|
2048
|
+
description
|
|
2049
|
+
handle
|
|
2050
|
+
onlineStoreUrl
|
|
2051
|
+
featuredImage {
|
|
2052
|
+
url
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
pageInfo {
|
|
2058
|
+
hasNextPage
|
|
2059
|
+
endCursor
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
`;
|
|
2064
|
+
|
|
2065
|
+
// src/queries/productVariants/getAllProductVariants.ts
|
|
2066
|
+
var ProductVariantSchema = import_zod11.default.object({
|
|
2067
|
+
status: import_zod11.default.enum(["ACTIVE", "ARCHIVED", "DRAFT"]),
|
|
2068
|
+
sku: import_zod11.default.string(),
|
|
2069
|
+
barcode: import_zod11.default.string().nullable(),
|
|
2070
|
+
price: import_zod11.default.string(),
|
|
2071
|
+
title: import_zod11.default.string(),
|
|
2072
|
+
url: import_zod11.default.string().nullable(),
|
|
2073
|
+
handle: import_zod11.default.string(),
|
|
2074
|
+
description: import_zod11.default.string(),
|
|
2075
|
+
imageUrl: import_zod11.default.string().nullable(),
|
|
2076
|
+
inventoryQuantity: import_zod11.default.number()
|
|
2077
|
+
});
|
|
2078
|
+
var GetAllProductVariantsReturn = import_zod11.default.array(ProductVariantSchema);
|
|
2079
|
+
async function getAllProductVariants() {
|
|
2080
|
+
const initialVariables = { first: 250 };
|
|
2081
|
+
const extractedNodes = await fetchShopifyGraphql({
|
|
2082
|
+
query: queryAllProductVariants,
|
|
2083
|
+
variables: initialVariables,
|
|
2084
|
+
dataExtractor: (pageData) => {
|
|
2085
|
+
if (!pageData.productVariants) {
|
|
2086
|
+
throw new Error(
|
|
2087
|
+
"GraphQL response for product variants is missing the 'productVariants' field."
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
const nodes = pageData.productVariants.edges.map(
|
|
2091
|
+
(edge) => edge.node
|
|
2092
|
+
);
|
|
2093
|
+
return {
|
|
2094
|
+
nodes,
|
|
2095
|
+
pageInfo: pageData.productVariants.pageInfo
|
|
2096
|
+
};
|
|
2097
|
+
},
|
|
2098
|
+
fetchAllPages: true
|
|
2099
|
+
});
|
|
2100
|
+
logger.debug(`Fetched ${extractedNodes.length} product variants from Shopify`);
|
|
2101
|
+
const allVariants = extractedNodes.map((v) => {
|
|
2102
|
+
const title = v.title === "Default Title" ? v.product.title : `${v.product.title} ${v.title}`;
|
|
2103
|
+
const url = v.product.onlineStoreUrl ? `${v.product.onlineStoreUrl}?variant=${v.legacyResourceId}` : null;
|
|
2104
|
+
return {
|
|
2105
|
+
status: v.product.status,
|
|
2106
|
+
sku: v.sku ?? "",
|
|
2107
|
+
barcode: v.barcode ?? null,
|
|
2108
|
+
price: v.price,
|
|
2109
|
+
title,
|
|
2110
|
+
url,
|
|
2111
|
+
handle: v.product.handle,
|
|
2112
|
+
description: v.product.description,
|
|
2113
|
+
imageUrl: v.product.featuredImage?.url ?? null,
|
|
2114
|
+
inventoryQuantity: v.inventoryQuantity ?? 0
|
|
2115
|
+
};
|
|
2116
|
+
});
|
|
2117
|
+
return await returnOutputParsed(allVariants, GetAllProductVariantsReturn);
|
|
2118
|
+
}
|
|
2119
|
+
|
|
1139
2120
|
// src/queries/orders/getOrderPaymentDetails.queries.ts
|
|
1140
2121
|
var queryOrderPaymentDetails = gql`#graphql
|
|
1141
2122
|
query orderPaymentDetailsById($id: ID!) {
|
|
@@ -1158,25 +2139,6 @@ var queryOrderPaymentDetails = gql`#graphql
|
|
|
1158
2139
|
`;
|
|
1159
2140
|
|
|
1160
2141
|
// src/queries/orders/getOrderPaymentDetails.ts
|
|
1161
|
-
var GetOrderPaymentDetailsByIdReturn = import_zod11.default.object({
|
|
1162
|
-
order: import_zod11.default.object({
|
|
1163
|
-
transactions: import_zod11.default.array(
|
|
1164
|
-
import_zod11.default.object({
|
|
1165
|
-
amountSet: import_zod11.default.object({
|
|
1166
|
-
shopMoney: import_zod11.default.object({
|
|
1167
|
-
amount: import_zod11.default.string(),
|
|
1168
|
-
currencyCode: import_zod11.default.string()
|
|
1169
|
-
})
|
|
1170
|
-
}),
|
|
1171
|
-
createdAt: import_zod11.default.string(),
|
|
1172
|
-
gateway: import_zod11.default.string(),
|
|
1173
|
-
formattedGateway: import_zod11.default.string(),
|
|
1174
|
-
kind: import_zod11.default.string(),
|
|
1175
|
-
paymentId: import_zod11.default.string()
|
|
1176
|
-
})
|
|
1177
|
-
)
|
|
1178
|
-
})
|
|
1179
|
-
});
|
|
1180
2142
|
async function getOrderPaymentDetailsById(id) {
|
|
1181
2143
|
const variables = {
|
|
1182
2144
|
id: convertIdIntoGid(id, "Order")
|
|
@@ -1187,9 +2149,301 @@ async function getOrderPaymentDetailsById(id) {
|
|
|
1187
2149
|
});
|
|
1188
2150
|
if (!response.order) {
|
|
1189
2151
|
logger.debug(`No order found with ID: ${id}`);
|
|
1190
|
-
return
|
|
2152
|
+
return void 0;
|
|
1191
2153
|
}
|
|
1192
|
-
return
|
|
2154
|
+
return response.order;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// src/queries/fulfillments/getFulfillmentById.queries.ts
|
|
2158
|
+
var queryFulfillmentById = gql`#graphql
|
|
2159
|
+
query fulfillmentById($id: ID!) {
|
|
2160
|
+
fulfillment(id: $id) {
|
|
2161
|
+
id
|
|
2162
|
+
name
|
|
2163
|
+
createdAt
|
|
2164
|
+
updatedAt
|
|
2165
|
+
status
|
|
2166
|
+
totalQuantity
|
|
2167
|
+
estimatedDeliveryAt
|
|
2168
|
+
deliveredAt
|
|
2169
|
+
location {
|
|
2170
|
+
id
|
|
2171
|
+
legacyResourceId
|
|
2172
|
+
name
|
|
2173
|
+
}
|
|
2174
|
+
service {
|
|
2175
|
+
handle
|
|
2176
|
+
serviceName
|
|
2177
|
+
}
|
|
2178
|
+
trackingInfo(first: 10) {
|
|
2179
|
+
company
|
|
2180
|
+
number
|
|
2181
|
+
url
|
|
2182
|
+
}
|
|
2183
|
+
originAddress {
|
|
2184
|
+
address1
|
|
2185
|
+
address2
|
|
2186
|
+
city
|
|
2187
|
+
countryCode
|
|
2188
|
+
provinceCode
|
|
2189
|
+
zip
|
|
2190
|
+
}
|
|
2191
|
+
fulfillmentLineItems(first: 100) {
|
|
2192
|
+
edges {
|
|
2193
|
+
node {
|
|
2194
|
+
id
|
|
2195
|
+
quantity
|
|
2196
|
+
originalTotalSet {
|
|
2197
|
+
shopMoney {
|
|
2198
|
+
amount
|
|
2199
|
+
currencyCode
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
lineItem {
|
|
2203
|
+
id
|
|
2204
|
+
title
|
|
2205
|
+
sku
|
|
2206
|
+
variant {
|
|
2207
|
+
id
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
`;
|
|
2216
|
+
|
|
2217
|
+
// src/queries/fulfillments/getFulfillmentById.ts
|
|
2218
|
+
async function getFulfillmentById(id) {
|
|
2219
|
+
const gid = typeof id === "string" ? id : convertIdIntoGid(
|
|
2220
|
+
typeof id === "number" ? BigInt(id) : id,
|
|
2221
|
+
"Fulfillment"
|
|
2222
|
+
);
|
|
2223
|
+
const variables = { id: gid };
|
|
2224
|
+
const response = await fetchShopifyGraphql({
|
|
2225
|
+
query: queryFulfillmentById,
|
|
2226
|
+
variables
|
|
2227
|
+
});
|
|
2228
|
+
if (!response.fulfillment) {
|
|
2229
|
+
logger.debug(`No fulfillment found with ID: ${id}`);
|
|
2230
|
+
return void 0;
|
|
2231
|
+
}
|
|
2232
|
+
return response.fulfillment;
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
// src/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.queries.ts
|
|
2236
|
+
var queryFulfillmentOrdersByOrderId = gql`#graphql
|
|
2237
|
+
query fulfillmentOrdersByOrderId($orderId: ID!) {
|
|
2238
|
+
order(id: $orderId) {
|
|
2239
|
+
fulfillmentOrders(first: 50) {
|
|
2240
|
+
edges {
|
|
2241
|
+
node {
|
|
2242
|
+
id
|
|
2243
|
+
status
|
|
2244
|
+
lineItems(first: 100) {
|
|
2245
|
+
edges {
|
|
2246
|
+
node {
|
|
2247
|
+
id
|
|
2248
|
+
remainingQuantity
|
|
2249
|
+
totalQuantity
|
|
2250
|
+
lineItem {
|
|
2251
|
+
id
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
`;
|
|
2262
|
+
|
|
2263
|
+
// src/queries/fulfillmentOrders/getFulfillmentOrdersByOrderId.ts
|
|
2264
|
+
async function getFulfillmentOrdersByOrderId(orderId) {
|
|
2265
|
+
const gid = typeof orderId === "string" ? orderId : convertIdIntoGid(
|
|
2266
|
+
typeof orderId === "number" ? BigInt(orderId) : orderId,
|
|
2267
|
+
"Order"
|
|
2268
|
+
);
|
|
2269
|
+
const variables = { orderId: gid };
|
|
2270
|
+
const response = await fetchShopifyGraphql({
|
|
2271
|
+
query: queryFulfillmentOrdersByOrderId,
|
|
2272
|
+
variables
|
|
2273
|
+
});
|
|
2274
|
+
if (!response.order) {
|
|
2275
|
+
logger.debug(`No order found with ID: ${orderId}`);
|
|
2276
|
+
return [];
|
|
2277
|
+
}
|
|
2278
|
+
return response.order.fulfillmentOrders.edges.map((edge) => edge.node);
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
// src/queries/customers/getCustomersByEmail.queries.ts
|
|
2282
|
+
var queryCustomersByEmail = gql`#graphql
|
|
2283
|
+
query customersByEmail($query: String!, $first: Int!) {
|
|
2284
|
+
customers(first: $first, query: $query) {
|
|
2285
|
+
edges {
|
|
2286
|
+
node {
|
|
2287
|
+
id
|
|
2288
|
+
email
|
|
2289
|
+
firstName
|
|
2290
|
+
lastName
|
|
2291
|
+
numberOfOrders
|
|
2292
|
+
amountSpent {
|
|
2293
|
+
amount
|
|
2294
|
+
currencyCode
|
|
2295
|
+
}
|
|
2296
|
+
defaultAddress {
|
|
2297
|
+
id
|
|
2298
|
+
address1
|
|
2299
|
+
address2
|
|
2300
|
+
city
|
|
2301
|
+
province
|
|
2302
|
+
country
|
|
2303
|
+
zip
|
|
2304
|
+
phone
|
|
2305
|
+
}
|
|
2306
|
+
addresses {
|
|
2307
|
+
id
|
|
2308
|
+
address1
|
|
2309
|
+
address2
|
|
2310
|
+
city
|
|
2311
|
+
province
|
|
2312
|
+
country
|
|
2313
|
+
zip
|
|
2314
|
+
phone
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
`;
|
|
2321
|
+
|
|
2322
|
+
// src/queries/customers/getCustomersByEmail.ts
|
|
2323
|
+
async function getCustomersByEmail(email, limit = 10) {
|
|
2324
|
+
const variables = {
|
|
2325
|
+
query: `email:${email}`,
|
|
2326
|
+
first: limit
|
|
2327
|
+
};
|
|
2328
|
+
const response = await fetchShopifyGraphql({
|
|
2329
|
+
query: queryCustomersByEmail,
|
|
2330
|
+
variables
|
|
2331
|
+
});
|
|
2332
|
+
const customers = response.customers.edges.map((edge) => edge.node);
|
|
2333
|
+
logger.debug(`Found ${customers.length} customers for email: ${email}`);
|
|
2334
|
+
return customers;
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
// src/queries/customerSegments/getCustomerSegmentMembers.queries.ts
|
|
2338
|
+
var queryCustomerSegmentMembersWithStatistics = gql`#graphql
|
|
2339
|
+
query customerSegmentMembersWithStatistics($query: String!, $first: Int!, $statisticsAttributeName: String!) {
|
|
2340
|
+
customerSegmentMembers(query: $query, first: $first) {
|
|
2341
|
+
statistics {
|
|
2342
|
+
attributeStatistics(attributeName: $statisticsAttributeName) {
|
|
2343
|
+
sum
|
|
2344
|
+
average
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
edges {
|
|
2348
|
+
node {
|
|
2349
|
+
id
|
|
2350
|
+
firstName
|
|
2351
|
+
lastName
|
|
2352
|
+
displayName
|
|
2353
|
+
defaultEmailAddress {
|
|
2354
|
+
emailAddress
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
pageInfo {
|
|
2359
|
+
hasNextPage
|
|
2360
|
+
endCursor
|
|
2361
|
+
}
|
|
2362
|
+
totalCount
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
`;
|
|
2366
|
+
|
|
2367
|
+
// src/queries/customerSegments/getCustomerSegmentMembers.ts
|
|
2368
|
+
async function getCustomerSegmentMembers(query, statisticsAttributeName, limit = 250) {
|
|
2369
|
+
const variables = {
|
|
2370
|
+
query,
|
|
2371
|
+
first: limit,
|
|
2372
|
+
statisticsAttributeName
|
|
2373
|
+
};
|
|
2374
|
+
const response = await fetchShopifyGraphql({
|
|
2375
|
+
query: queryCustomerSegmentMembersWithStatistics,
|
|
2376
|
+
variables
|
|
2377
|
+
});
|
|
2378
|
+
const members = response.customerSegmentMembers.edges.map((edge) => edge.node);
|
|
2379
|
+
logger.debug(`Found ${members.length} customer segment members`);
|
|
2380
|
+
return {
|
|
2381
|
+
members,
|
|
2382
|
+
totalCount: response.customerSegmentMembers.totalCount,
|
|
2383
|
+
statistics: response.customerSegmentMembers.statistics
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
// src/queries/orders/getOrdersByCustomerId.queries.ts
|
|
2388
|
+
var queryOrdersByCustomerId = gql`#graphql
|
|
2389
|
+
query ordersByCustomerId($customerId: ID!, $first: Int!) {
|
|
2390
|
+
customer(id: $customerId) {
|
|
2391
|
+
id
|
|
2392
|
+
orders(first: $first, reverse: true) {
|
|
2393
|
+
edges {
|
|
2394
|
+
node {
|
|
2395
|
+
id
|
|
2396
|
+
name
|
|
2397
|
+
createdAt
|
|
2398
|
+
cancelledAt
|
|
2399
|
+
cancelReason
|
|
2400
|
+
displayFulfillmentStatus
|
|
2401
|
+
totalPriceSet {
|
|
2402
|
+
shopMoney {
|
|
2403
|
+
amount
|
|
2404
|
+
currencyCode
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
lineItems(first: 100) {
|
|
2408
|
+
edges {
|
|
2409
|
+
node {
|
|
2410
|
+
sku
|
|
2411
|
+
title
|
|
2412
|
+
image {
|
|
2413
|
+
url
|
|
2414
|
+
width
|
|
2415
|
+
height
|
|
2416
|
+
altText
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
`;
|
|
2427
|
+
|
|
2428
|
+
// src/queries/orders/getOrdersByCustomerId.ts
|
|
2429
|
+
async function getOrdersByCustomerId(customerId, limit = 250) {
|
|
2430
|
+
const bigIntId = typeof customerId === "number" ? BigInt(customerId) : customerId;
|
|
2431
|
+
const gid = convertIdIntoGid(bigIntId, "Customer");
|
|
2432
|
+
const variables = {
|
|
2433
|
+
customerId: gid,
|
|
2434
|
+
first: limit
|
|
2435
|
+
};
|
|
2436
|
+
const response = await fetchShopifyGraphql({
|
|
2437
|
+
query: queryOrdersByCustomerId,
|
|
2438
|
+
variables
|
|
2439
|
+
});
|
|
2440
|
+
if (!response.customer) {
|
|
2441
|
+
logger.debug(`No customer found with ID: ${customerId}`);
|
|
2442
|
+
return [];
|
|
2443
|
+
}
|
|
2444
|
+
const orders = response.customer.orders.edges.map((edge) => edge.node);
|
|
2445
|
+
logger.debug(`Got ${orders.length} orders for customer ${customerId}`);
|
|
2446
|
+
return orders;
|
|
1193
2447
|
}
|
|
1194
2448
|
|
|
1195
2449
|
// src/utils/parseGid.ts
|
|
@@ -1197,15 +2451,68 @@ function parseGid(gid) {
|
|
|
1197
2451
|
const match = gid.match(/\d+$/);
|
|
1198
2452
|
return match ? Number.parseInt(match[0], 10) : 0;
|
|
1199
2453
|
}
|
|
2454
|
+
|
|
2455
|
+
// src/queries/metaobjects/getMetaobjectByHandle.queries.ts
|
|
2456
|
+
var queryMetaobjectByHandle = gql`#graphql
|
|
2457
|
+
query metaobjectByHandle($handle: MetaobjectHandleInput!) {
|
|
2458
|
+
metaobjectByHandle(handle: $handle) {
|
|
2459
|
+
id
|
|
2460
|
+
handle
|
|
2461
|
+
type
|
|
2462
|
+
displayName
|
|
2463
|
+
updatedAt
|
|
2464
|
+
fields {
|
|
2465
|
+
key
|
|
2466
|
+
value
|
|
2467
|
+
type
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
`;
|
|
2472
|
+
|
|
2473
|
+
// src/queries/metaobjects/getMetaobjectByHandle.ts
|
|
2474
|
+
async function getMetaobjectByHandle(handle) {
|
|
2475
|
+
const variables = { handle };
|
|
2476
|
+
const response = await fetchShopifyGraphql({
|
|
2477
|
+
query: queryMetaobjectByHandle,
|
|
2478
|
+
variables
|
|
2479
|
+
});
|
|
2480
|
+
if (!response.metaobjectByHandle) {
|
|
2481
|
+
logger.debug(
|
|
2482
|
+
`No metaobject found with type "${handle.type}" and handle "${handle.handle}"`
|
|
2483
|
+
);
|
|
2484
|
+
return void 0;
|
|
2485
|
+
}
|
|
2486
|
+
return response.metaobjectByHandle;
|
|
2487
|
+
}
|
|
1200
2488
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1201
2489
|
0 && (module.exports = {
|
|
1202
2490
|
ShopifyUserError,
|
|
2491
|
+
bulkUpdateProductVariants,
|
|
2492
|
+
calculateRefund,
|
|
1203
2493
|
cancelOrderById,
|
|
2494
|
+
createFile,
|
|
2495
|
+
createFulfillment,
|
|
2496
|
+
createMetaobjectDefinition,
|
|
2497
|
+
createRefund,
|
|
1204
2498
|
deleteCustomerById,
|
|
2499
|
+
deleteFilesByIds,
|
|
2500
|
+
getAllProductVariants,
|
|
2501
|
+
getCustomerSegmentMembers,
|
|
2502
|
+
getCustomersByEmail,
|
|
2503
|
+
getFulfillmentById,
|
|
2504
|
+
getFulfillmentOrdersByOrderId,
|
|
2505
|
+
getFulfillmentTrackingIds,
|
|
1205
2506
|
getLeanProductVariants,
|
|
2507
|
+
getMetaobjectByHandle,
|
|
1206
2508
|
getOrderById,
|
|
1207
2509
|
getOrderByName,
|
|
2510
|
+
getOrderCancellationInfoByName,
|
|
1208
2511
|
getOrderPaymentDetailsById,
|
|
1209
|
-
|
|
2512
|
+
getOrdersByCustomerId,
|
|
2513
|
+
getProductVariantsBySkus,
|
|
2514
|
+
parseGid,
|
|
2515
|
+
updateFulfillmentTracking,
|
|
2516
|
+
upsertMetaobject
|
|
1210
2517
|
});
|
|
1211
2518
|
//# sourceMappingURL=index.cjs.map
|