@keystrokehq/shopify 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -0
- package/dist/_official/index.d.mts +3 -0
- package/dist/_official/index.mjs +3 -0
- package/dist/_runtime/index.d.mts +56 -0
- package/dist/_runtime/index.mjs +3 -0
- package/dist/articles.d.mts +174 -0
- package/dist/articles.mjs +252 -0
- package/dist/blogs.d.mts +113 -0
- package/dist/blogs.mjs +174 -0
- package/dist/client.d.mts +22 -0
- package/dist/client.mjs +90 -0
- package/dist/collections.d.mts +140 -0
- package/dist/collections.mjs +209 -0
- package/dist/connection.d.mts +2 -0
- package/dist/connection.mjs +3 -0
- package/dist/customers.d.mts +161 -0
- package/dist/customers.mjs +225 -0
- package/dist/events.d.mts +181 -0
- package/dist/events.mjs +67 -0
- package/dist/factory-DC-gY8L0.mjs +8 -0
- package/dist/fulfillments.d.mts +99 -0
- package/dist/fulfillments.mjs +167 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/integration-BN3pjCz4.mjs +204 -0
- package/dist/integration-BwDBsGX-.d.mts +71 -0
- package/dist/inventory.d.mts +103 -0
- package/dist/inventory.mjs +182 -0
- package/dist/locations.d.mts +47 -0
- package/dist/locations.mjs +81 -0
- package/dist/messaging.d.mts +1 -0
- package/dist/messaging.mjs +1 -0
- package/dist/operation-helpers-CKEDIx0o.mjs +21 -0
- package/dist/orders.d.mts +229 -0
- package/dist/orders.mjs +271 -0
- package/dist/products.d.mts +155 -0
- package/dist/products.mjs +171 -0
- package/dist/provider-app-DHxVZI6q.d.mts +37 -0
- package/dist/schemas.d.mts +233 -0
- package/dist/schemas.mjs +164 -0
- package/dist/shop.d.mts +20 -0
- package/dist/shop.mjs +31 -0
- package/dist/triggers.d.mts +23 -0
- package/dist/triggers.mjs +138 -0
- package/dist/webhook-management-BmIxO0vr.mjs +150 -0
- package/package.json +130 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { shopifyCollectionSchema, shopifyConnectionNodesSchema, shopifyGlobalIdSchema, shopifyJobSchema, shopifyUserErrorSchema } from "./schemas.mjs";
|
|
2
|
+
import { createShopifyClient } from "./client.mjs";
|
|
3
|
+
import { t as shopifyOperation } from "./factory-DC-gY8L0.mjs";
|
|
4
|
+
import { i as shopifyProductIdsInputSchema, n as omitUndefined, r as shopifyPageInputSchema, t as assertNoUserErrors } from "./operation-helpers-CKEDIx0o.mjs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/collections.ts
|
|
8
|
+
const collectionSelection = `
|
|
9
|
+
id
|
|
10
|
+
title
|
|
11
|
+
handle
|
|
12
|
+
descriptionHtml
|
|
13
|
+
updatedAt
|
|
14
|
+
image {
|
|
15
|
+
url
|
|
16
|
+
altText
|
|
17
|
+
}
|
|
18
|
+
seo {
|
|
19
|
+
title
|
|
20
|
+
description
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
const collectionMutationInputSchema = z.object({
|
|
24
|
+
title: z.string().min(1).optional(),
|
|
25
|
+
handle: z.string().min(1).optional(),
|
|
26
|
+
descriptionHtml: z.string().optional(),
|
|
27
|
+
seo: z.object({
|
|
28
|
+
title: z.string().optional(),
|
|
29
|
+
description: z.string().optional()
|
|
30
|
+
}).optional()
|
|
31
|
+
});
|
|
32
|
+
const collectionMutationResponseSchema = z.object({
|
|
33
|
+
collection: shopifyCollectionSchema.nullable(),
|
|
34
|
+
userErrors: z.array(shopifyUserErrorSchema)
|
|
35
|
+
});
|
|
36
|
+
const listCollectionsResponseSchema = z.object({ collections: shopifyConnectionNodesSchema(shopifyCollectionSchema) });
|
|
37
|
+
const getCollectionResponseSchema = z.object({ collection: shopifyCollectionSchema.nullable() });
|
|
38
|
+
const deleteCollectionResponseSchema = z.object({
|
|
39
|
+
deletedCollectionId: shopifyGlobalIdSchema.nullable(),
|
|
40
|
+
userErrors: z.array(shopifyUserErrorSchema)
|
|
41
|
+
});
|
|
42
|
+
const removeProductsResponseSchema = z.object({
|
|
43
|
+
job: shopifyJobSchema.nullable(),
|
|
44
|
+
userErrors: z.array(shopifyUserErrorSchema)
|
|
45
|
+
});
|
|
46
|
+
const listCollections = shopifyOperation({
|
|
47
|
+
id: "list_shopify_collections",
|
|
48
|
+
name: "List Shopify Collections",
|
|
49
|
+
description: "List collections from the connected Shopify store.",
|
|
50
|
+
input: shopifyPageInputSchema,
|
|
51
|
+
output: shopifyConnectionNodesSchema(shopifyCollectionSchema),
|
|
52
|
+
run: async (input, credentials) => {
|
|
53
|
+
return (await createShopifyClient(credentials).graphql(`
|
|
54
|
+
query ListCollections($first: Int!, $after: String, $query: String) {
|
|
55
|
+
collections(first: $first, after: $after, query: $query) {
|
|
56
|
+
nodes {
|
|
57
|
+
${collectionSelection}
|
|
58
|
+
}
|
|
59
|
+
pageInfo {
|
|
60
|
+
hasNextPage
|
|
61
|
+
hasPreviousPage
|
|
62
|
+
startCursor
|
|
63
|
+
endCursor
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`, listCollectionsResponseSchema, { variables: {
|
|
68
|
+
first: input.first,
|
|
69
|
+
...input.after ? { after: input.after } : {},
|
|
70
|
+
...input.query ? { query: input.query } : {}
|
|
71
|
+
} })).collections;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const getCollection = shopifyOperation({
|
|
75
|
+
id: "get_shopify_collection",
|
|
76
|
+
name: "Get Shopify Collection",
|
|
77
|
+
description: "Retrieve a single Shopify collection by its global ID.",
|
|
78
|
+
input: z.object({ id: shopifyGlobalIdSchema }),
|
|
79
|
+
output: shopifyCollectionSchema,
|
|
80
|
+
run: async (input, credentials) => {
|
|
81
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
82
|
+
query GetCollection($id: ID!) {
|
|
83
|
+
collection(id: $id) {
|
|
84
|
+
${collectionSelection}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`, getCollectionResponseSchema, { variables: { id: input.id } });
|
|
88
|
+
if (!response.collection) throw new Error(`Shopify collection not found: ${input.id}`);
|
|
89
|
+
return response.collection;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const createCollection = shopifyOperation({
|
|
93
|
+
id: "create_shopify_collection",
|
|
94
|
+
name: "Create Shopify Collection",
|
|
95
|
+
description: "Create a collection in the connected Shopify store.",
|
|
96
|
+
needsApproval: true,
|
|
97
|
+
input: collectionMutationInputSchema.extend({ title: z.string().min(1) }),
|
|
98
|
+
output: shopifyCollectionSchema,
|
|
99
|
+
run: async (input, credentials) => {
|
|
100
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
101
|
+
mutation CreateCollection($input: CollectionInput!) {
|
|
102
|
+
collectionCreate(input: $input) {
|
|
103
|
+
collection {
|
|
104
|
+
${collectionSelection}
|
|
105
|
+
}
|
|
106
|
+
userErrors {
|
|
107
|
+
field
|
|
108
|
+
message
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`, z.object({ collectionCreate: collectionMutationResponseSchema }), { variables: { input: omitUndefined(input) } });
|
|
113
|
+
assertNoUserErrors(response.collectionCreate.userErrors);
|
|
114
|
+
if (!response.collectionCreate.collection) throw new Error("Shopify did not return the created collection.");
|
|
115
|
+
return response.collectionCreate.collection;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const deleteCollection = shopifyOperation({
|
|
119
|
+
id: "delete_shopify_collection",
|
|
120
|
+
name: "Delete Shopify Collection",
|
|
121
|
+
description: "Delete a Shopify collection by its global ID.",
|
|
122
|
+
needsApproval: true,
|
|
123
|
+
input: z.object({ id: shopifyGlobalIdSchema }),
|
|
124
|
+
output: z.object({ deletedCollectionId: shopifyGlobalIdSchema }),
|
|
125
|
+
run: async (input, credentials) => {
|
|
126
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
127
|
+
mutation DeleteCollection($input: CollectionDeleteInput!) {
|
|
128
|
+
collectionDelete(input: $input) {
|
|
129
|
+
deletedCollectionId
|
|
130
|
+
userErrors {
|
|
131
|
+
field
|
|
132
|
+
message
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
`, z.object({ collectionDelete: deleteCollectionResponseSchema }), { variables: { input: { id: input.id } } });
|
|
137
|
+
assertNoUserErrors(response.collectionDelete.userErrors);
|
|
138
|
+
if (!response.collectionDelete.deletedCollectionId) throw new Error(`Shopify did not confirm collection deletion: ${input.id}`);
|
|
139
|
+
return { deletedCollectionId: response.collectionDelete.deletedCollectionId };
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const addProductsToCollection = shopifyOperation({
|
|
143
|
+
id: "add_products_to_shopify_collection",
|
|
144
|
+
name: "Add Products To Shopify Collection",
|
|
145
|
+
description: "Add products to a manual Shopify collection.",
|
|
146
|
+
needsApproval: true,
|
|
147
|
+
input: z.object({
|
|
148
|
+
id: shopifyGlobalIdSchema,
|
|
149
|
+
productIds: shopifyProductIdsInputSchema
|
|
150
|
+
}),
|
|
151
|
+
output: shopifyCollectionSchema,
|
|
152
|
+
run: async (input, credentials) => {
|
|
153
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
154
|
+
mutation AddProductsToCollection($id: ID!, $productIds: [ID!]!) {
|
|
155
|
+
collectionAddProducts(id: $id, productIds: $productIds) {
|
|
156
|
+
collection {
|
|
157
|
+
${collectionSelection}
|
|
158
|
+
}
|
|
159
|
+
userErrors {
|
|
160
|
+
field
|
|
161
|
+
message
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
`, z.object({ collectionAddProducts: collectionMutationResponseSchema }), { variables: {
|
|
166
|
+
id: input.id,
|
|
167
|
+
productIds: input.productIds
|
|
168
|
+
} });
|
|
169
|
+
assertNoUserErrors(response.collectionAddProducts.userErrors);
|
|
170
|
+
if (!response.collectionAddProducts.collection) throw new Error(`Shopify did not return the updated collection: ${input.id}`);
|
|
171
|
+
return response.collectionAddProducts.collection;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
const removeProductsFromCollection = shopifyOperation({
|
|
175
|
+
id: "remove_products_from_shopify_collection",
|
|
176
|
+
name: "Remove Products From Shopify Collection",
|
|
177
|
+
description: "Remove products from a manual Shopify collection.",
|
|
178
|
+
needsApproval: true,
|
|
179
|
+
input: z.object({
|
|
180
|
+
id: shopifyGlobalIdSchema,
|
|
181
|
+
productIds: shopifyProductIdsInputSchema
|
|
182
|
+
}),
|
|
183
|
+
output: shopifyJobSchema,
|
|
184
|
+
run: async (input, credentials) => {
|
|
185
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
186
|
+
mutation RemoveProductsFromCollection($id: ID!, $productIds: [ID!]!) {
|
|
187
|
+
collectionRemoveProducts(id: $id, productIds: $productIds) {
|
|
188
|
+
job {
|
|
189
|
+
id
|
|
190
|
+
done
|
|
191
|
+
}
|
|
192
|
+
userErrors {
|
|
193
|
+
field
|
|
194
|
+
message
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
`, z.object({ collectionRemoveProducts: removeProductsResponseSchema }), { variables: {
|
|
199
|
+
id: input.id,
|
|
200
|
+
productIds: input.productIds
|
|
201
|
+
} });
|
|
202
|
+
assertNoUserErrors(response.collectionRemoveProducts.userErrors);
|
|
203
|
+
if (!response.collectionRemoveProducts.job) throw new Error(`Shopify did not return a removal job for collection: ${input.id}`);
|
|
204
|
+
return response.collectionRemoveProducts.job;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
//#endregion
|
|
209
|
+
export { addProductsToCollection, createCollection, deleteCollection, getCollection, listCollections, removeProductsFromCollection };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
3
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
4
|
+
|
|
5
|
+
//#region src/customers.d.ts
|
|
6
|
+
declare const listCustomers: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
7
|
+
first: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
8
|
+
after: z.ZodOptional<z.ZodString>;
|
|
9
|
+
query: z.ZodOptional<z.ZodString>;
|
|
10
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
11
|
+
nodes: z.ZodArray<z.ZodObject<{
|
|
12
|
+
id: z.ZodString;
|
|
13
|
+
displayName: z.ZodString;
|
|
14
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
|
|
17
|
+
phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
19
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
pageInfo: z.ZodObject<{
|
|
22
|
+
hasNextPage: z.ZodBoolean;
|
|
23
|
+
hasPreviousPage: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
startCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
25
|
+
endCursor: z.ZodNullable<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
28
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
29
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
30
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
31
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
32
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
33
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
34
|
+
declare const getCustomer: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
35
|
+
id: z.ZodString;
|
|
36
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
displayName: z.ZodString;
|
|
39
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
|
|
42
|
+
phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
44
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
45
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
46
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
47
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
48
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
49
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
50
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
51
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
52
|
+
declare const createCustomer: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
53
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
54
|
+
firstName: z.ZodOptional<z.ZodString>;
|
|
55
|
+
lastName: z.ZodOptional<z.ZodString>;
|
|
56
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
57
|
+
note: z.ZodOptional<z.ZodString>;
|
|
58
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
60
|
+
id: z.ZodString;
|
|
61
|
+
displayName: z.ZodString;
|
|
62
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
|
|
65
|
+
phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
66
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
67
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
68
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
69
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
70
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
71
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
72
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
73
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
74
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
75
|
+
declare const updateCustomer: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
76
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
77
|
+
firstName: z.ZodOptional<z.ZodString>;
|
|
78
|
+
lastName: z.ZodOptional<z.ZodString>;
|
|
79
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
80
|
+
note: z.ZodOptional<z.ZodString>;
|
|
81
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
+
id: z.ZodString;
|
|
83
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
84
|
+
id: z.ZodString;
|
|
85
|
+
displayName: z.ZodString;
|
|
86
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
87
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
88
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
|
|
89
|
+
phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
90
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
91
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
92
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
93
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
94
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
95
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
96
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
97
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
98
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
99
|
+
declare const deleteCustomer: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
100
|
+
id: z.ZodString;
|
|
101
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
+
deletedCustomerId: z.ZodString;
|
|
103
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
104
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
105
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
106
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
107
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
108
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
109
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
110
|
+
declare const getCustomerOrders: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
111
|
+
id: z.ZodString;
|
|
112
|
+
first: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
113
|
+
after: z.ZodOptional<z.ZodString>;
|
|
114
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
115
|
+
nodes: z.ZodArray<z.ZodObject<{
|
|
116
|
+
id: z.ZodString;
|
|
117
|
+
name: z.ZodString;
|
|
118
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
119
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
120
|
+
cancelledAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
|
|
121
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
|
|
122
|
+
note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
123
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
|
+
displayFinancialStatus: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
125
|
+
displayFulfillmentStatus: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
126
|
+
currentTotalPriceSet: z.ZodOptional<z.ZodObject<{
|
|
127
|
+
shopMoney: z.ZodObject<{
|
|
128
|
+
amount: z.ZodString;
|
|
129
|
+
currencyCode: z.ZodString;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
presentmentMoney: z.ZodOptional<z.ZodObject<{
|
|
132
|
+
amount: z.ZodString;
|
|
133
|
+
currencyCode: z.ZodString;
|
|
134
|
+
}, z.core.$strip>>;
|
|
135
|
+
}, z.core.$strip>>;
|
|
136
|
+
customer: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
137
|
+
id: z.ZodString;
|
|
138
|
+
displayName: z.ZodString;
|
|
139
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
140
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
141
|
+
email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
|
|
142
|
+
phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
143
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
144
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
145
|
+
}, z.core.$strip>>>;
|
|
146
|
+
}, z.core.$strip>>;
|
|
147
|
+
pageInfo: z.ZodObject<{
|
|
148
|
+
hasNextPage: z.ZodBoolean;
|
|
149
|
+
hasPreviousPage: z.ZodOptional<z.ZodBoolean>;
|
|
150
|
+
startCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
151
|
+
endCursor: z.ZodNullable<z.ZodString>;
|
|
152
|
+
}, z.core.$strip>;
|
|
153
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
154
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
155
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
156
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
157
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
158
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
159
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
160
|
+
//#endregion
|
|
161
|
+
export { createCustomer, deleteCustomer, getCustomer, getCustomerOrders, listCustomers, updateCustomer };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { shopifyConnectionNodesSchema, shopifyCustomerSchema, shopifyGlobalIdSchema, shopifyOrderSchema, shopifyUserErrorSchema } from "./schemas.mjs";
|
|
2
|
+
import { createShopifyClient } from "./client.mjs";
|
|
3
|
+
import { t as shopifyOperation } from "./factory-DC-gY8L0.mjs";
|
|
4
|
+
import { n as omitUndefined, r as shopifyPageInputSchema, t as assertNoUserErrors } from "./operation-helpers-CKEDIx0o.mjs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/customers.ts
|
|
8
|
+
const customerSelection = `
|
|
9
|
+
id
|
|
10
|
+
displayName
|
|
11
|
+
firstName
|
|
12
|
+
lastName
|
|
13
|
+
email
|
|
14
|
+
phone
|
|
15
|
+
createdAt
|
|
16
|
+
updatedAt
|
|
17
|
+
`;
|
|
18
|
+
const orderSelection = `
|
|
19
|
+
id
|
|
20
|
+
name
|
|
21
|
+
createdAt
|
|
22
|
+
updatedAt
|
|
23
|
+
cancelledAt
|
|
24
|
+
email
|
|
25
|
+
note
|
|
26
|
+
tags
|
|
27
|
+
displayFinancialStatus
|
|
28
|
+
displayFulfillmentStatus
|
|
29
|
+
currentTotalPriceSet {
|
|
30
|
+
shopMoney {
|
|
31
|
+
amount
|
|
32
|
+
currencyCode
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
customer {
|
|
36
|
+
id
|
|
37
|
+
displayName
|
|
38
|
+
firstName
|
|
39
|
+
lastName
|
|
40
|
+
email
|
|
41
|
+
phone
|
|
42
|
+
createdAt
|
|
43
|
+
updatedAt
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
const customerMutationInputSchema = z.object({
|
|
47
|
+
email: z.email().optional(),
|
|
48
|
+
firstName: z.string().optional(),
|
|
49
|
+
lastName: z.string().optional(),
|
|
50
|
+
phone: z.string().optional(),
|
|
51
|
+
note: z.string().optional(),
|
|
52
|
+
tags: z.array(z.string()).optional()
|
|
53
|
+
});
|
|
54
|
+
const customerMutationResponseSchema = z.object({
|
|
55
|
+
customer: shopifyCustomerSchema.nullable(),
|
|
56
|
+
userErrors: z.array(shopifyUserErrorSchema)
|
|
57
|
+
});
|
|
58
|
+
const listCustomersResponseSchema = z.object({ customers: shopifyConnectionNodesSchema(shopifyCustomerSchema) });
|
|
59
|
+
const getCustomerResponseSchema = z.object({ customer: shopifyCustomerSchema.nullable() });
|
|
60
|
+
const customerDeleteResponseSchema = z.object({
|
|
61
|
+
deletedCustomerId: shopifyGlobalIdSchema.nullable(),
|
|
62
|
+
userErrors: z.array(shopifyUserErrorSchema)
|
|
63
|
+
});
|
|
64
|
+
const customerOrdersResponseSchema = z.object({ customer: z.object({ orders: shopifyConnectionNodesSchema(shopifyOrderSchema) }).nullable() });
|
|
65
|
+
const listCustomers = shopifyOperation({
|
|
66
|
+
id: "list_shopify_customers",
|
|
67
|
+
name: "List Shopify Customers",
|
|
68
|
+
description: "List customers from the connected Shopify store.",
|
|
69
|
+
input: shopifyPageInputSchema,
|
|
70
|
+
output: shopifyConnectionNodesSchema(shopifyCustomerSchema),
|
|
71
|
+
run: async (input, credentials) => {
|
|
72
|
+
return (await createShopifyClient(credentials).graphql(`
|
|
73
|
+
query ListCustomers($first: Int!, $after: String, $query: String) {
|
|
74
|
+
customers(first: $first, after: $after, query: $query) {
|
|
75
|
+
nodes {
|
|
76
|
+
${customerSelection}
|
|
77
|
+
}
|
|
78
|
+
pageInfo {
|
|
79
|
+
hasNextPage
|
|
80
|
+
hasPreviousPage
|
|
81
|
+
startCursor
|
|
82
|
+
endCursor
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
`, listCustomersResponseSchema, { variables: {
|
|
87
|
+
first: input.first,
|
|
88
|
+
...input.after ? { after: input.after } : {},
|
|
89
|
+
...input.query ? { query: input.query } : {}
|
|
90
|
+
} })).customers;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const getCustomer = shopifyOperation({
|
|
94
|
+
id: "get_shopify_customer",
|
|
95
|
+
name: "Get Shopify Customer",
|
|
96
|
+
description: "Retrieve a single Shopify customer by its global ID.",
|
|
97
|
+
input: z.object({ id: shopifyGlobalIdSchema }),
|
|
98
|
+
output: shopifyCustomerSchema,
|
|
99
|
+
run: async (input, credentials) => {
|
|
100
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
101
|
+
query GetCustomer($id: ID!) {
|
|
102
|
+
customer(id: $id) {
|
|
103
|
+
${customerSelection}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`, getCustomerResponseSchema, { variables: { id: input.id } });
|
|
107
|
+
if (!response.customer) throw new Error(`Shopify customer not found: ${input.id}`);
|
|
108
|
+
return response.customer;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const createCustomer = shopifyOperation({
|
|
112
|
+
id: "create_shopify_customer",
|
|
113
|
+
name: "Create Shopify Customer",
|
|
114
|
+
description: "Create a customer in the connected Shopify store.",
|
|
115
|
+
needsApproval: true,
|
|
116
|
+
input: customerMutationInputSchema.refine((input) => input.email !== void 0 || input.phone !== void 0 || input.firstName !== void 0, { message: "At least one identifying customer field must be provided." }),
|
|
117
|
+
output: shopifyCustomerSchema,
|
|
118
|
+
run: async (input, credentials) => {
|
|
119
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
120
|
+
mutation CreateCustomer($input: CustomerInput!) {
|
|
121
|
+
customerCreate(input: $input) {
|
|
122
|
+
customer {
|
|
123
|
+
${customerSelection}
|
|
124
|
+
}
|
|
125
|
+
userErrors {
|
|
126
|
+
field
|
|
127
|
+
message
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`, z.object({ customerCreate: customerMutationResponseSchema }), { variables: { input: omitUndefined(input) } });
|
|
132
|
+
assertNoUserErrors(response.customerCreate.userErrors);
|
|
133
|
+
if (!response.customerCreate.customer) throw new Error("Shopify did not return the created customer.");
|
|
134
|
+
return response.customerCreate.customer;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const updateCustomer = shopifyOperation({
|
|
138
|
+
id: "update_shopify_customer",
|
|
139
|
+
name: "Update Shopify Customer",
|
|
140
|
+
description: "Update a Shopify customer by its global ID.",
|
|
141
|
+
needsApproval: true,
|
|
142
|
+
input: customerMutationInputSchema.extend({ id: shopifyGlobalIdSchema }),
|
|
143
|
+
output: shopifyCustomerSchema,
|
|
144
|
+
run: async (input, credentials) => {
|
|
145
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
146
|
+
mutation UpdateCustomer($input: CustomerInput!) {
|
|
147
|
+
customerUpdate(input: $input) {
|
|
148
|
+
customer {
|
|
149
|
+
${customerSelection}
|
|
150
|
+
}
|
|
151
|
+
userErrors {
|
|
152
|
+
field
|
|
153
|
+
message
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
`, z.object({ customerUpdate: customerMutationResponseSchema }), { variables: { input: omitUndefined(input) } });
|
|
158
|
+
assertNoUserErrors(response.customerUpdate.userErrors);
|
|
159
|
+
if (!response.customerUpdate.customer) throw new Error(`Shopify did not return the updated customer: ${input.id}`);
|
|
160
|
+
return response.customerUpdate.customer;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const deleteCustomer = shopifyOperation({
|
|
164
|
+
id: "delete_shopify_customer",
|
|
165
|
+
name: "Delete Shopify Customer",
|
|
166
|
+
description: "Delete a Shopify customer who has no placed orders.",
|
|
167
|
+
needsApproval: true,
|
|
168
|
+
input: z.object({ id: shopifyGlobalIdSchema }),
|
|
169
|
+
output: z.object({ deletedCustomerId: shopifyGlobalIdSchema }),
|
|
170
|
+
run: async (input, credentials) => {
|
|
171
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
172
|
+
mutation DeleteCustomer($id: ID!) {
|
|
173
|
+
customerDelete(input: { id: $id }) {
|
|
174
|
+
deletedCustomerId
|
|
175
|
+
userErrors {
|
|
176
|
+
field
|
|
177
|
+
message
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
`, z.object({ customerDelete: customerDeleteResponseSchema }), { variables: { id: input.id } });
|
|
182
|
+
assertNoUserErrors(response.customerDelete.userErrors);
|
|
183
|
+
if (!response.customerDelete.deletedCustomerId) throw new Error(`Shopify did not confirm customer deletion: ${input.id}`);
|
|
184
|
+
return { deletedCustomerId: response.customerDelete.deletedCustomerId };
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const getCustomerOrders = shopifyOperation({
|
|
188
|
+
id: "get_shopify_customer_orders",
|
|
189
|
+
name: "Get Shopify Customer Orders",
|
|
190
|
+
description: "Retrieve orders for a specific Shopify customer.",
|
|
191
|
+
input: z.object({
|
|
192
|
+
id: shopifyGlobalIdSchema,
|
|
193
|
+
first: z.number().int().min(1).max(100).optional().default(25),
|
|
194
|
+
after: z.string().optional()
|
|
195
|
+
}),
|
|
196
|
+
output: shopifyConnectionNodesSchema(shopifyOrderSchema),
|
|
197
|
+
run: async (input, credentials) => {
|
|
198
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
199
|
+
query GetCustomerOrders($id: ID!, $first: Int!, $after: String) {
|
|
200
|
+
customer(id: $id) {
|
|
201
|
+
orders(first: $first, after: $after) {
|
|
202
|
+
nodes {
|
|
203
|
+
${orderSelection}
|
|
204
|
+
}
|
|
205
|
+
pageInfo {
|
|
206
|
+
hasNextPage
|
|
207
|
+
hasPreviousPage
|
|
208
|
+
startCursor
|
|
209
|
+
endCursor
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
`, customerOrdersResponseSchema, { variables: {
|
|
215
|
+
id: input.id,
|
|
216
|
+
first: input.first,
|
|
217
|
+
...input.after ? { after: input.after } : {}
|
|
218
|
+
} });
|
|
219
|
+
if (!response.customer) throw new Error(`Shopify customer not found for orders lookup: ${input.id}`);
|
|
220
|
+
return response.customer.orders;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
export { createCustomer, deleteCustomer, getCustomer, getCustomerOrders, listCustomers, updateCustomer };
|