@ehrenkind/shopify-lib 0.2.1 → 0.3.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/generated-api-types/2025-04/admin.generated.d.ts +14 -2
- package/dist/generated-api-types/2025-04/admin.generated.d.ts.map +1 -1
- package/dist/generated-api-types/2025-04/admin.types.d.ts +12 -11
- package/dist/generated-api-types/2025-04/admin.types.d.ts.map +1 -1
- package/dist/generated-api-types/2025-04/admin.types.js +3 -3
- package/dist/generated-api-types/2025-04/admin.types.js.map +1 -1
- package/dist/index.cjs +63 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -39
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -42
- package/dist/index.mjs.map +1 -1
- package/dist/mutations/orders/cancelOrderById.d.ts +23 -0
- package/dist/mutations/orders/cancelOrderById.d.ts.map +1 -0
- package/dist/mutations/orders/cancelOrderById.js +63 -0
- package/dist/mutations/orders/cancelOrderById.js.map +1 -0
- package/dist/mutations/orders/cancelOrderById.mock.d.ts +15 -0
- package/dist/mutations/orders/cancelOrderById.mock.d.ts.map +1 -0
- package/dist/mutations/orders/cancelOrderById.mock.js +17 -0
- package/dist/mutations/orders/cancelOrderById.mock.js.map +1 -0
- package/dist/mutations/orders/cancelOrderById.test.d.ts +2 -0
- package/dist/mutations/orders/cancelOrderById.test.d.ts.map +1 -0
- package/dist/mutations/orders/cancelOrderById.test.js +42 -0
- package/dist/mutations/orders/cancelOrderById.test.js.map +1 -0
- package/dist/queries/orders/getOrderById.d.ts +2 -2
- package/dist/queries/orders/getOrderById.d.ts.map +1 -1
- package/dist/queries/orders/getOrderById.mock.d.ts +1 -1
- package/dist/queries/orders/getOrderById.mock.d.ts.map +1 -1
- package/dist/queries/orders/getOrderById.mock.js +1 -0
- package/dist/queries/orders/getOrderById.mock.js.map +1 -1
- package/dist/queries/orders/getOrderById.queries.d.ts.map +1 -1
- package/dist/queries/orders/getOrderById.queries.js +1 -0
- package/dist/queries/orders/getOrderById.queries.js.map +1 -1
- package/dist/utils/mswHandlers.d.ts +6 -0
- package/dist/utils/mswHandlers.d.ts.map +1 -1
- package/dist/utils/mswHandlers.js +5 -2
- package/dist/utils/mswHandlers.js.map +1 -1
- package/dist/utils/shopifyFetch.d.ts +24 -3
- package/dist/utils/shopifyFetch.d.ts.map +1 -1
- package/dist/utils/shopifyFetch.js +23 -1
- package/dist/utils/shopifyFetch.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,53 @@ import z from 'zod';
|
|
|
3
3
|
declare const DeleteCustomerByIdReturn: z.ZodNullable<z.ZodString>;
|
|
4
4
|
declare function deleteCustomerById(customerId: string): Promise<z.infer<typeof DeleteCustomerByIdReturn>>;
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Cancel an order in Shopify.
|
|
8
|
+
*
|
|
9
|
+
* @param orderId - The order ID (numeric, bigint, or GID string)
|
|
10
|
+
* @returns Promise resolving to true on success
|
|
11
|
+
* @throws {ShopifyUserError} When cancellation fails (e.g., ORDER_ALREADY_CANCELLED)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Success case
|
|
15
|
+
* await cancelOrderById(12345678901234)
|
|
16
|
+
*
|
|
17
|
+
* // Error handling
|
|
18
|
+
* import { ShopifyUserError } from '@ehrenkind/shopify-lib'
|
|
19
|
+
* try {
|
|
20
|
+
* await cancelOrderById(orderId)
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* if (error instanceof ShopifyUserError) {
|
|
23
|
+
* const alreadyCancelled = error.errors.some(e => e.code === 'ORDER_ALREADY_CANCELLED')
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
*/
|
|
27
|
+
declare function cancelOrderById(orderId: number | bigint | string): Promise<boolean>;
|
|
28
|
+
|
|
29
|
+
interface ShopifyUserErrorDetail {
|
|
30
|
+
code?: string | null;
|
|
31
|
+
field?: string[] | null;
|
|
32
|
+
message?: string | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Custom error class for Shopify mutation userErrors.
|
|
36
|
+
* Preserves the full error array so callers can inspect specific error codes.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* try {
|
|
40
|
+
* await cancelOrderById(orderId)
|
|
41
|
+
* } catch (error) {
|
|
42
|
+
* if (error instanceof ShopifyUserError) {
|
|
43
|
+
* const alreadyCancelled = error.errors.some(e => e.code === 'ORDER_ALREADY_CANCELLED')
|
|
44
|
+
* if (alreadyCancelled) { ... }
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
*/
|
|
48
|
+
declare class ShopifyUserError extends Error {
|
|
49
|
+
readonly errors: ShopifyUserErrorDetail[];
|
|
50
|
+
constructor(message: string, errors: ShopifyUserErrorDetail[]);
|
|
51
|
+
}
|
|
52
|
+
|
|
6
53
|
type Maybe<T> = T | null;
|
|
7
54
|
type InputMaybe<T> = Maybe<T>;
|
|
8
55
|
type Exact<T extends {
|
|
@@ -4704,7 +4751,7 @@ type DeliveryProfile = Node & {
|
|
|
4704
4751
|
id: Scalars['ID']['output'];
|
|
4705
4752
|
/**
|
|
4706
4753
|
* Whether this shop has enabled legacy compatibility mode for delivery profiles.
|
|
4707
|
-
* @deprecated Legacy mode profiles are no longer supported.
|
|
4754
|
+
* @deprecated Legacy mode profiles are no longer supported. This will be removed in 2026-04.
|
|
4708
4755
|
*/
|
|
4709
4756
|
legacyMode: Scalars['Boolean']['output'];
|
|
4710
4757
|
/** The number of locations without rates defined. */
|
|
@@ -9409,7 +9456,7 @@ type Location = HasMetafieldDefinitions & HasMetafields & LegacyInteroperability
|
|
|
9409
9456
|
metafields: MetafieldConnection;
|
|
9410
9457
|
/** The name of the location. */
|
|
9411
9458
|
name: Scalars['String']['output'];
|
|
9412
|
-
/**
|
|
9459
|
+
/** Legacy field indicating this location was designated for shipping. All locations with valid addresses can now ship. */
|
|
9413
9460
|
shipsInventory: Scalars['Boolean']['output'];
|
|
9414
9461
|
/** List of suggested addresses for this location (empty if none). */
|
|
9415
9462
|
suggestedAddresses: Array<LocationSuggestedAddress>;
|
|
@@ -11920,6 +11967,27 @@ declare enum OrderCancelReason {
|
|
|
11920
11967
|
/** Staff made an error. */
|
|
11921
11968
|
Staff = "STAFF"
|
|
11922
11969
|
}
|
|
11970
|
+
/** Errors related to order cancellation. */
|
|
11971
|
+
type OrderCancelUserError = DisplayableError & {
|
|
11972
|
+
__typename?: 'OrderCancelUserError';
|
|
11973
|
+
/** The error code. */
|
|
11974
|
+
code?: Maybe<OrderCancelUserErrorCode>;
|
|
11975
|
+
/** The path to the input field that caused the error. */
|
|
11976
|
+
field?: Maybe<Array<Scalars['String']['output']>>;
|
|
11977
|
+
/** The error message. */
|
|
11978
|
+
message: Scalars['String']['output'];
|
|
11979
|
+
};
|
|
11980
|
+
/** Possible error codes that can be returned by `OrderCancelUserError`. */
|
|
11981
|
+
declare enum OrderCancelUserErrorCode {
|
|
11982
|
+
/** Unexpected internal error happened. */
|
|
11983
|
+
InternalError = "INTERNAL_ERROR",
|
|
11984
|
+
/** The input value is invalid. */
|
|
11985
|
+
Invalid = "INVALID",
|
|
11986
|
+
/** The record with the ID used as the input value couldn't be found. */
|
|
11987
|
+
NotFound = "NOT_FOUND",
|
|
11988
|
+
/** An order refund was requested but the user does not have the refund_orders permission. */
|
|
11989
|
+
NoRefundPermission = "NO_REFUND_PERMISSION"
|
|
11990
|
+
}
|
|
11923
11991
|
/** Details about the order cancellation. */
|
|
11924
11992
|
type OrderCancellation = {
|
|
11925
11993
|
__typename?: 'OrderCancellation';
|
|
@@ -12265,7 +12333,7 @@ declare enum OrderTransactionErrorCode {
|
|
|
12265
12333
|
AmazonPaymentsOrderReferenceCanceled = "AMAZON_PAYMENTS_ORDER_REFERENCE_CANCELED",
|
|
12266
12334
|
/** The order was not confirmed within three hours. */
|
|
12267
12335
|
AmazonPaymentsStale = "AMAZON_PAYMENTS_STALE",
|
|
12268
|
-
/**
|
|
12336
|
+
/** The issuer declined the transaction, the customer should contact their issuer for more details. */
|
|
12269
12337
|
CallIssuer = "CALL_ISSUER",
|
|
12270
12338
|
/** The card was declined. */
|
|
12271
12339
|
CardDeclined = "CARD_DECLINED",
|
|
@@ -12285,7 +12353,7 @@ declare enum OrderTransactionErrorCode {
|
|
|
12285
12353
|
IncorrectPin = "INCORRECT_PIN",
|
|
12286
12354
|
/** The ZIP or postal code doesn't match the one on file. */
|
|
12287
12355
|
IncorrectZip = "INCORRECT_ZIP",
|
|
12288
|
-
/** The amount is
|
|
12356
|
+
/** The amount is invalid. */
|
|
12289
12357
|
InvalidAmount = "INVALID_AMOUNT",
|
|
12290
12358
|
/** The payment method is not available in the customer's country. */
|
|
12291
12359
|
InvalidCountry = "INVALID_COUNTRY",
|
|
@@ -18505,6 +18573,14 @@ type CustomerDeleteMutation = {
|
|
|
18505
18573
|
userErrors: Array<Pick<UserError, 'field' | 'message'>>;
|
|
18506
18574
|
})>;
|
|
18507
18575
|
};
|
|
18576
|
+
type OrderCancelMutationVariables = Exact<{
|
|
18577
|
+
orderId: Scalars['ID']['input'];
|
|
18578
|
+
}>;
|
|
18579
|
+
type OrderCancelMutation = {
|
|
18580
|
+
orderCancel?: Maybe<{
|
|
18581
|
+
orderCancelUserErrors: Array<Pick<OrderCancelUserError, 'code' | 'field' | 'message'>>;
|
|
18582
|
+
}>;
|
|
18583
|
+
};
|
|
18508
18584
|
type ConnectMetaObjectToProductVariantMutationVariables = Exact<{
|
|
18509
18585
|
productId: Scalars['ID']['input'];
|
|
18510
18586
|
variantId: Scalars['ID']['input'];
|
|
@@ -18558,7 +18634,7 @@ type OrderByIdFullQuery = {
|
|
|
18558
18634
|
fulfillmentLineItems: {
|
|
18559
18635
|
edges: Array<{
|
|
18560
18636
|
node: (Pick<FulfillmentLineItem, 'id' | 'quantity'> & {
|
|
18561
|
-
lineItem: Pick<LineItem, 'id'>;
|
|
18637
|
+
lineItem: Pick<LineItem, 'id' | 'sku'>;
|
|
18562
18638
|
});
|
|
18563
18639
|
}>;
|
|
18564
18640
|
};
|
|
@@ -18735,7 +18811,7 @@ interface GeneratedQueryTypes {
|
|
|
18735
18811
|
return: OrderByIdQuery;
|
|
18736
18812
|
variables: OrderByIdQueryVariables;
|
|
18737
18813
|
};
|
|
18738
|
-
"#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n firstName\n lastName\n email\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n": {
|
|
18814
|
+
"#graphql\n query orderByIdFull($id: ID!) {\n order(id: $id) {\n id\n name\n createdAt\n updatedAt\n processedAt\n closedAt\n cancelledAt\n cancelReason\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n customer {\n id\n firstName\n lastName\n email\n phone\n }\n displayFinancialStatus\n displayFulfillmentStatus\n shippingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n billingAddress {\n firstName\n lastName\n address1\n address2\n city\n province\n country\n zip\n }\n lineItems(first: 100) {\n edges {\n node {\n id\n sku\n title\n variantTitle\n quantity\n customAttributes {\n key\n value\n }\n originalUnitPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n vendor\n image {\n url\n width\n height\n altText\n }\n }\n }\n }\n fulfillments {\n id\n name\n totalQuantity\n status\n createdAt\n estimatedDeliveryAt\n deliveredAt\n trackingInfo {\n company\n number\n url\n }\n fulfillmentLineItems(first: 100) {\n edges {\n node {\n id\n quantity\n lineItem {\n id\n sku\n }\n }\n }\n }\n }\n shippingLine {\n originalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n taxLines {\n priceSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n totalDiscountsSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n discountCodes\n refunds {\n totalRefundedSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\n": {
|
|
18739
18815
|
return: OrderByIdFullQuery;
|
|
18740
18816
|
variables: OrderByIdFullQueryVariables;
|
|
18741
18817
|
};
|
|
@@ -18765,6 +18841,10 @@ interface GeneratedMutationTypes {
|
|
|
18765
18841
|
return: CustomerDeleteMutation;
|
|
18766
18842
|
variables: CustomerDeleteMutationVariables;
|
|
18767
18843
|
};
|
|
18844
|
+
"#graphql\n mutation orderCancel($orderId: ID!) {\n orderCancel(\n orderId: $orderId\n refund: true\n restock: false\n reason: CUSTOMER\n notifyCustomer: true\n ) {\n orderCancelUserErrors {\n code\n field\n message\n }\n }\n }\n": {
|
|
18845
|
+
return: OrderCancelMutation;
|
|
18846
|
+
variables: OrderCancelMutationVariables;
|
|
18847
|
+
};
|
|
18768
18848
|
"#graphql\n mutation connectMetaObjectToProductVariant($productId: ID!, $variantId: ID!, $metaObjectId: String!, $metaObjectKey: String!) {\n productVariantsBulkUpdate(\n productId: $productId\n variants: [\n {\n id: $variantId\n metafields: [\n {\n namespace: \"custom\"\n key: $metaObjectKey\n value: $metaObjectId\n type: \"metaobject_reference\"\n }\n ]\n }\n ] \n ) {\n productVariants { \n id\n }\n userErrors {\n field\n message\n }\n }\n }\n ": {
|
|
18769
18849
|
return: ConnectMetaObjectToProductVariantMutation;
|
|
18770
18850
|
variables: ConnectMetaObjectToProductVariantMutationVariables;
|
|
@@ -18906,10 +18986,10 @@ declare const GetLeanOrderByIdReturn: z.ZodNullable<z.ZodObject<{
|
|
|
18906
18986
|
financialStatus: string | null;
|
|
18907
18987
|
}>>;
|
|
18908
18988
|
type LeanOrder = z.infer<typeof GetLeanOrderByIdReturn>;
|
|
18909
|
-
type FullOrder = NonNullable<OrderByIdFullQuery['order']
|
|
18989
|
+
type FullOrder = NonNullable<OrderByIdFullQuery['order']>;
|
|
18910
18990
|
declare function getOrderById(id: number | bigint): Promise<LeanOrder>;
|
|
18911
18991
|
declare function getOrderById(id: number | bigint, detailLevel: 'lean'): Promise<LeanOrder>;
|
|
18912
|
-
declare function getOrderById(id: number | bigint, detailLevel: 'full'): Promise<FullOrder>;
|
|
18992
|
+
declare function getOrderById(id: number | bigint, detailLevel: 'full'): Promise<FullOrder | null>;
|
|
18913
18993
|
|
|
18914
18994
|
declare const GetLeanOrderByNameReturn: z.ZodNullable<z.ZodObject<{
|
|
18915
18995
|
id: z.ZodString;
|
|
@@ -19139,36 +19219,6 @@ type GetOrderPaymentDetailsByIdReturnType = z.infer<typeof GetOrderPaymentDetail
|
|
|
19139
19219
|
*/
|
|
19140
19220
|
declare function getOrderPaymentDetailsById(id: bigint): Promise<GetOrderPaymentDetailsByIdReturnType | null>;
|
|
19141
19221
|
|
|
19142
|
-
/**
|
|
19143
|
-
* Transforms GraphQL responses to REST-like format.
|
|
19144
|
-
*
|
|
19145
|
-
* This utility recursively:
|
|
19146
|
-
* 1. Flattens `{ edges: [{ node: ... }] }` → `[...]`
|
|
19147
|
-
* 2. Converts camelCase to snake_case (`lineItems` → `line_items`)
|
|
19148
|
-
* 3. Extracts numeric IDs from GIDs (`gid://shopify/Order/123` → `123`)
|
|
19149
|
-
*/
|
|
19150
|
-
/**
|
|
19151
|
-
* Transform a GraphQL response object to REST-like format.
|
|
19152
|
-
*
|
|
19153
|
-
* @example
|
|
19154
|
-
* ```typescript
|
|
19155
|
-
* const graphqlOrder = {
|
|
19156
|
-
* id: 'gid://shopify/Order/123',
|
|
19157
|
-
* lineItems: {
|
|
19158
|
-
* edges: [{ node: { id: 'gid://shopify/LineItem/456', sku: 'ABC' } }]
|
|
19159
|
-
* }
|
|
19160
|
-
* };
|
|
19161
|
-
*
|
|
19162
|
-
* const restOrder = toRestFormat(graphqlOrder);
|
|
19163
|
-
* // Result:
|
|
19164
|
-
* // {
|
|
19165
|
-
* // id: 123,
|
|
19166
|
-
* // line_items: [{ id: 456, sku: 'ABC' }]
|
|
19167
|
-
* // }
|
|
19168
|
-
* ```
|
|
19169
|
-
*/
|
|
19170
|
-
declare function toRestFormat<T>(obj: T): unknown;
|
|
19171
|
-
|
|
19172
19222
|
/**
|
|
19173
19223
|
* Extract numeric ID from a Shopify GID string.
|
|
19174
19224
|
*
|
|
@@ -19178,4 +19228,4 @@ declare function toRestFormat<T>(obj: T): unknown;
|
|
|
19178
19228
|
*/
|
|
19179
19229
|
declare function parseGid(gid: string): number;
|
|
19180
19230
|
|
|
19181
|
-
export { type FullOrder, type FullOrderByName, type LeanOrder, type LeanOrderByName, deleteCustomerById, getLeanProductVariants, getOrderById, getOrderByName, getOrderPaymentDetailsById, parseGid
|
|
19231
|
+
export { type FullOrder, type FullOrderByName, type LeanOrder, type LeanOrderByName, ShopifyUserError, type ShopifyUserErrorDetail, cancelOrderById, deleteCustomerById, getLeanProductVariants, getOrderById, getOrderByName, getOrderPaymentDetailsById, parseGid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { deleteCustomerById } from './mutations/customers/deleteCustomerById.js';
|
|
2
|
+
export { cancelOrderById } from './mutations/orders/cancelOrderById.js';
|
|
3
|
+
export { ShopifyUserError, type ShopifyUserErrorDetail, } from './utils/shopifyFetch.js';
|
|
2
4
|
export { getOrderById, type FullOrder, type LeanOrder, } from './queries/orders/getOrderById.js';
|
|
3
5
|
export { getOrderByName, type FullOrderByName, type LeanOrderByName, } from './queries/orders/getOrderByName.js';
|
|
4
6
|
export { getLeanProductVariants } from './queries/productVariants/getLeanProductVariants.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,EACL,gBAAgB,EAChB,KAAK,sBAAsB,GAC5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { deleteCustomerById } from './mutations/customers/deleteCustomerById.js';
|
|
2
|
+
export { cancelOrderById } from './mutations/orders/cancelOrderById.js';
|
|
3
|
+
export { ShopifyUserError, } from './utils/shopifyFetch.js';
|
|
2
4
|
export { getOrderById, } from './queries/orders/getOrderById.js';
|
|
3
5
|
export { getOrderByName, } from './queries/orders/getOrderByName.js';
|
|
4
6
|
export { getLeanProductVariants } from './queries/productVariants/getLeanProductVariants.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EACL,YAAY,GAGb,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,GAGf,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,EACL,gBAAgB,GAEjB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,YAAY,GAGb,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,cAAc,GAGf,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -132,6 +132,13 @@ try {
|
|
|
132
132
|
function convertIdIntoGid(id, type) {
|
|
133
133
|
return `gid://shopify/${type}/${id}`;
|
|
134
134
|
}
|
|
135
|
+
var ShopifyUserError = class extends Error {
|
|
136
|
+
constructor(message, errors) {
|
|
137
|
+
super(message);
|
|
138
|
+
this.errors = errors;
|
|
139
|
+
this.name = "ShopifyUserError";
|
|
140
|
+
}
|
|
141
|
+
};
|
|
135
142
|
async function fetchShopifyGraphql(params) {
|
|
136
143
|
const {
|
|
137
144
|
query,
|
|
@@ -151,7 +158,10 @@ async function fetchShopifyGraphql(params) {
|
|
|
151
158
|
if (Array.isArray(userErrors) && userErrors.length > 0) {
|
|
152
159
|
const errorMessages = userErrors.map((e) => e.message || JSON.stringify(e)).join("\n");
|
|
153
160
|
logger.error("Shopify mutation userErrors:", errorMessages);
|
|
154
|
-
throw new
|
|
161
|
+
throw new ShopifyUserError(
|
|
162
|
+
`Shopify mutation userErrors: ${errorMessages}`,
|
|
163
|
+
userErrors
|
|
164
|
+
);
|
|
155
165
|
}
|
|
156
166
|
allNodes.push(...nodes);
|
|
157
167
|
hasNextLoop = fetchAllPages ? !!pageInfo?.hasNextPage : false;
|
|
@@ -209,7 +219,7 @@ async function returnOutputParsed(data, Model) {
|
|
|
209
219
|
// src/mutations/customers/deleteCustomerById.ts
|
|
210
220
|
var DeleteCustomerByIdReturn = z3.string().nullable();
|
|
211
221
|
async function deleteCustomerById(customerId) {
|
|
212
|
-
const
|
|
222
|
+
const mutation2 = gql`#graphql
|
|
213
223
|
mutation customerDelete($input: CustomerDeleteInput!) {
|
|
214
224
|
customerDelete(input: $input) {
|
|
215
225
|
deletedCustomerId
|
|
@@ -224,7 +234,7 @@ async function deleteCustomerById(customerId) {
|
|
|
224
234
|
input: { id: customerId }
|
|
225
235
|
};
|
|
226
236
|
const response = await fetchShopifyGraphql({
|
|
227
|
-
query:
|
|
237
|
+
query: mutation2,
|
|
228
238
|
variables,
|
|
229
239
|
dataExtractor: (data) => {
|
|
230
240
|
if (!data.customerDelete) {
|
|
@@ -244,6 +254,48 @@ async function deleteCustomerById(customerId) {
|
|
|
244
254
|
);
|
|
245
255
|
}
|
|
246
256
|
|
|
257
|
+
// src/mutations/orders/cancelOrderById.ts
|
|
258
|
+
var mutation = gql`#graphql
|
|
259
|
+
mutation orderCancel($orderId: ID!) {
|
|
260
|
+
orderCancel(
|
|
261
|
+
orderId: $orderId
|
|
262
|
+
refund: true
|
|
263
|
+
restock: false
|
|
264
|
+
reason: CUSTOMER
|
|
265
|
+
notifyCustomer: true
|
|
266
|
+
) {
|
|
267
|
+
orderCancelUserErrors {
|
|
268
|
+
code
|
|
269
|
+
field
|
|
270
|
+
message
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
`;
|
|
275
|
+
async function cancelOrderById(orderId) {
|
|
276
|
+
const orderGid = typeof orderId === "string" ? orderId : convertIdIntoGid(
|
|
277
|
+
typeof orderId === "number" ? BigInt(orderId) : orderId,
|
|
278
|
+
"Order"
|
|
279
|
+
);
|
|
280
|
+
logger.debug(`Cancelling order ${orderGid}`);
|
|
281
|
+
const variables = { orderId: orderGid };
|
|
282
|
+
await fetchShopifyGraphql({
|
|
283
|
+
query: mutation,
|
|
284
|
+
variables,
|
|
285
|
+
dataExtractor: (data) => {
|
|
286
|
+
if (!data.orderCancel) {
|
|
287
|
+
throw new Error("GraphQL response missing 'orderCancel' field");
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
nodes: [{ success: true }],
|
|
291
|
+
userErrors: data.orderCancel.orderCancelUserErrors
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
logger.debug(`Order ${orderGid} cancelled successfully`);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
|
|
247
299
|
// src/queries/orders/getOrderById.ts
|
|
248
300
|
import z4 from "zod";
|
|
249
301
|
|
|
@@ -381,6 +433,7 @@ var queryOrderByIdFull = gql`#graphql
|
|
|
381
433
|
quantity
|
|
382
434
|
lineItem {
|
|
383
435
|
id
|
|
436
|
+
sku
|
|
384
437
|
}
|
|
385
438
|
}
|
|
386
439
|
}
|
|
@@ -1101,54 +1154,19 @@ async function getOrderPaymentDetailsById(id) {
|
|
|
1101
1154
|
return await returnOutputParsed(response, GetOrderPaymentDetailsByIdReturn);
|
|
1102
1155
|
}
|
|
1103
1156
|
|
|
1104
|
-
// src/utils/toRestFormat.ts
|
|
1105
|
-
function camelToSnake(str) {
|
|
1106
|
-
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
1107
|
-
}
|
|
1108
|
-
function extractNumericId(gid) {
|
|
1109
|
-
const match = gid.match(/\d+$/);
|
|
1110
|
-
return match ? parseInt(match[0], 10) : 0;
|
|
1111
|
-
}
|
|
1112
|
-
function toRestFormat(obj) {
|
|
1113
|
-
if (obj === null || obj === void 0) {
|
|
1114
|
-
return obj;
|
|
1115
|
-
}
|
|
1116
|
-
if (Array.isArray(obj)) {
|
|
1117
|
-
return obj.map(toRestFormat);
|
|
1118
|
-
}
|
|
1119
|
-
if (typeof obj === "object") {
|
|
1120
|
-
const record = obj;
|
|
1121
|
-
const result = {};
|
|
1122
|
-
for (const [key, value] of Object.entries(record)) {
|
|
1123
|
-
if (key === "edges" && Array.isArray(value) && value.every(
|
|
1124
|
-
(item) => typeof item === "object" && item !== null && "node" in item
|
|
1125
|
-
)) {
|
|
1126
|
-
return value.map((edge) => toRestFormat(edge.node));
|
|
1127
|
-
}
|
|
1128
|
-
if (key === "id" && typeof value === "string" && value.startsWith("gid://")) {
|
|
1129
|
-
result[key] = extractNumericId(value);
|
|
1130
|
-
continue;
|
|
1131
|
-
}
|
|
1132
|
-
const snakeKey = camelToSnake(key);
|
|
1133
|
-
result[snakeKey] = toRestFormat(value);
|
|
1134
|
-
}
|
|
1135
|
-
return result;
|
|
1136
|
-
}
|
|
1137
|
-
return obj;
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
1157
|
// src/utils/parseGid.ts
|
|
1141
1158
|
function parseGid(gid) {
|
|
1142
1159
|
const match = gid.match(/\d+$/);
|
|
1143
|
-
return match ? parseInt(match[0], 10) : 0;
|
|
1160
|
+
return match ? Number.parseInt(match[0], 10) : 0;
|
|
1144
1161
|
}
|
|
1145
1162
|
export {
|
|
1163
|
+
ShopifyUserError,
|
|
1164
|
+
cancelOrderById,
|
|
1146
1165
|
deleteCustomerById,
|
|
1147
1166
|
getLeanProductVariants,
|
|
1148
1167
|
getOrderById,
|
|
1149
1168
|
getOrderByName,
|
|
1150
1169
|
getOrderPaymentDetailsById,
|
|
1151
|
-
parseGid
|
|
1152
|
-
toRestFormat
|
|
1170
|
+
parseGid
|
|
1153
1171
|
};
|
|
1154
1172
|
//# sourceMappingURL=index.mjs.map
|