@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
package/dist/blogs.d.mts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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/blogs.d.ts
|
|
6
|
+
declare const listBlogs: _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
|
+
title: z.ZodString;
|
|
14
|
+
handle: z.ZodString;
|
|
15
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
16
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
17
|
+
commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
|
+
templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
pageInfo: z.ZodObject<{
|
|
21
|
+
hasNextPage: z.ZodBoolean;
|
|
22
|
+
hasPreviousPage: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
startCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
endCursor: z.ZodNullable<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
27
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
28
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
29
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
30
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
31
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
32
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
33
|
+
declare const getBlog: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
36
|
+
id: z.ZodString;
|
|
37
|
+
title: z.ZodString;
|
|
38
|
+
handle: z.ZodString;
|
|
39
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
40
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
41
|
+
commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
44
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
45
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
46
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
47
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
48
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
49
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
50
|
+
declare const createBlog: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
51
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
52
|
+
templateSuffix: z.ZodOptional<z.ZodString>;
|
|
53
|
+
commentPolicy: z.ZodOptional<z.ZodEnum<{
|
|
54
|
+
DISABLED: "DISABLED";
|
|
55
|
+
HIDDEN: "HIDDEN";
|
|
56
|
+
MODERATED: "MODERATED";
|
|
57
|
+
OPEN: "OPEN";
|
|
58
|
+
}>>;
|
|
59
|
+
title: z.ZodString;
|
|
60
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
title: z.ZodString;
|
|
63
|
+
handle: z.ZodString;
|
|
64
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
65
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
66
|
+
commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
+
templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
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 updateBlog: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
76
|
+
title: z.ZodOptional<z.ZodString>;
|
|
77
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
78
|
+
templateSuffix: z.ZodOptional<z.ZodString>;
|
|
79
|
+
commentPolicy: z.ZodOptional<z.ZodEnum<{
|
|
80
|
+
DISABLED: "DISABLED";
|
|
81
|
+
HIDDEN: "HIDDEN";
|
|
82
|
+
MODERATED: "MODERATED";
|
|
83
|
+
OPEN: "OPEN";
|
|
84
|
+
}>>;
|
|
85
|
+
id: z.ZodString;
|
|
86
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
87
|
+
id: z.ZodString;
|
|
88
|
+
title: z.ZodString;
|
|
89
|
+
handle: z.ZodString;
|
|
90
|
+
createdAt: z.ZodOptional<z.ZodISODateTime>;
|
|
91
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
92
|
+
commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
93
|
+
templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
94
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
95
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
96
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
97
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
98
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
99
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
100
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
101
|
+
declare const deleteBlog: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
102
|
+
id: z.ZodString;
|
|
103
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
104
|
+
deletedBlogId: z.ZodString;
|
|
105
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
106
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
107
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
108
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
109
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
110
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
111
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { createBlog, deleteBlog, getBlog, listBlogs, updateBlog };
|
package/dist/blogs.mjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { shopifyBlogSchema, shopifyConnectionNodesSchema, shopifyGlobalIdSchema, 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/blogs.ts
|
|
8
|
+
const blogSelection = `
|
|
9
|
+
id
|
|
10
|
+
title
|
|
11
|
+
handle
|
|
12
|
+
createdAt
|
|
13
|
+
updatedAt
|
|
14
|
+
commentPolicy
|
|
15
|
+
templateSuffix
|
|
16
|
+
`;
|
|
17
|
+
const blogCommentPolicySchema = z.enum([
|
|
18
|
+
"DISABLED",
|
|
19
|
+
"HIDDEN",
|
|
20
|
+
"MODERATED",
|
|
21
|
+
"OPEN"
|
|
22
|
+
]);
|
|
23
|
+
const blogMutationInputSchema = z.object({
|
|
24
|
+
title: z.string().min(1).optional(),
|
|
25
|
+
handle: z.string().min(1).optional(),
|
|
26
|
+
templateSuffix: z.string().optional(),
|
|
27
|
+
commentPolicy: blogCommentPolicySchema.optional()
|
|
28
|
+
});
|
|
29
|
+
const blogMutationResponseSchema = z.object({
|
|
30
|
+
blog: shopifyBlogSchema.nullable(),
|
|
31
|
+
userErrors: z.array(shopifyUserErrorSchema.extend({ code: z.string().optional() }))
|
|
32
|
+
});
|
|
33
|
+
const listBlogsResponseSchema = z.object({ blogs: shopifyConnectionNodesSchema(shopifyBlogSchema) });
|
|
34
|
+
const getBlogResponseSchema = z.object({ blog: shopifyBlogSchema.nullable() });
|
|
35
|
+
const deleteBlogResponseSchema = z.object({
|
|
36
|
+
deletedBlogId: shopifyGlobalIdSchema.nullable(),
|
|
37
|
+
userErrors: z.array(shopifyUserErrorSchema.extend({ code: z.string().optional() }))
|
|
38
|
+
});
|
|
39
|
+
const listBlogs = shopifyOperation({
|
|
40
|
+
id: "list_shopify_blogs",
|
|
41
|
+
name: "List Shopify Blogs",
|
|
42
|
+
description: "List blogs from the connected Shopify store.",
|
|
43
|
+
input: shopifyPageInputSchema,
|
|
44
|
+
output: shopifyConnectionNodesSchema(shopifyBlogSchema),
|
|
45
|
+
run: async (input, credentials) => {
|
|
46
|
+
return (await createShopifyClient(credentials).graphql(`
|
|
47
|
+
query ListBlogs($first: Int!, $after: String, $query: String) {
|
|
48
|
+
blogs(first: $first, after: $after, query: $query) {
|
|
49
|
+
nodes {
|
|
50
|
+
${blogSelection}
|
|
51
|
+
}
|
|
52
|
+
pageInfo {
|
|
53
|
+
hasNextPage
|
|
54
|
+
hasPreviousPage
|
|
55
|
+
startCursor
|
|
56
|
+
endCursor
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`, listBlogsResponseSchema, { variables: {
|
|
61
|
+
first: input.first,
|
|
62
|
+
...input.after ? { after: input.after } : {},
|
|
63
|
+
...input.query ? { query: input.query } : {}
|
|
64
|
+
} })).blogs;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const getBlog = shopifyOperation({
|
|
68
|
+
id: "get_shopify_blog",
|
|
69
|
+
name: "Get Shopify Blog",
|
|
70
|
+
description: "Retrieve a single Shopify blog by its global ID.",
|
|
71
|
+
input: z.object({ id: shopifyGlobalIdSchema }),
|
|
72
|
+
output: shopifyBlogSchema,
|
|
73
|
+
run: async (input, credentials) => {
|
|
74
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
75
|
+
query GetBlog($id: ID!) {
|
|
76
|
+
blog(id: $id) {
|
|
77
|
+
${blogSelection}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`, getBlogResponseSchema, { variables: { id: input.id } });
|
|
81
|
+
if (!response.blog) throw new Error(`Shopify blog not found: ${input.id}`);
|
|
82
|
+
return response.blog;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const createBlog = shopifyOperation({
|
|
86
|
+
id: "create_shopify_blog",
|
|
87
|
+
name: "Create Shopify Blog",
|
|
88
|
+
description: "Create a blog in the connected Shopify store.",
|
|
89
|
+
needsApproval: true,
|
|
90
|
+
input: blogMutationInputSchema.extend({ title: z.string().min(1) }),
|
|
91
|
+
output: shopifyBlogSchema,
|
|
92
|
+
run: async (input, credentials) => {
|
|
93
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
94
|
+
mutation CreateBlog($blog: BlogCreateInput!) {
|
|
95
|
+
blogCreate(blog: $blog) {
|
|
96
|
+
blog {
|
|
97
|
+
${blogSelection}
|
|
98
|
+
}
|
|
99
|
+
userErrors {
|
|
100
|
+
code
|
|
101
|
+
field
|
|
102
|
+
message
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`, z.object({ blogCreate: blogMutationResponseSchema }), { variables: { blog: omitUndefined(input) } });
|
|
107
|
+
assertNoUserErrors(response.blogCreate.userErrors);
|
|
108
|
+
if (!response.blogCreate.blog) throw new Error("Shopify did not return the created blog.");
|
|
109
|
+
return response.blogCreate.blog;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const updateBlog = shopifyOperation({
|
|
113
|
+
id: "update_shopify_blog",
|
|
114
|
+
name: "Update Shopify Blog",
|
|
115
|
+
description: "Update a Shopify blog by its global ID.",
|
|
116
|
+
needsApproval: true,
|
|
117
|
+
input: blogMutationInputSchema.extend({ id: shopifyGlobalIdSchema }),
|
|
118
|
+
output: shopifyBlogSchema,
|
|
119
|
+
run: async (input, credentials) => {
|
|
120
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
121
|
+
mutation UpdateBlog($id: ID!, $blog: BlogUpdateInput!) {
|
|
122
|
+
blogUpdate(id: $id, blog: $blog) {
|
|
123
|
+
blog {
|
|
124
|
+
${blogSelection}
|
|
125
|
+
}
|
|
126
|
+
userErrors {
|
|
127
|
+
code
|
|
128
|
+
field
|
|
129
|
+
message
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
`, z.object({ blogUpdate: blogMutationResponseSchema }), { variables: {
|
|
134
|
+
id: input.id,
|
|
135
|
+
blog: omitUndefined({
|
|
136
|
+
title: input.title,
|
|
137
|
+
handle: input.handle,
|
|
138
|
+
templateSuffix: input.templateSuffix,
|
|
139
|
+
commentPolicy: input.commentPolicy
|
|
140
|
+
})
|
|
141
|
+
} });
|
|
142
|
+
assertNoUserErrors(response.blogUpdate.userErrors);
|
|
143
|
+
if (!response.blogUpdate.blog) throw new Error(`Shopify did not return the updated blog: ${input.id}`);
|
|
144
|
+
return response.blogUpdate.blog;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const deleteBlog = shopifyOperation({
|
|
148
|
+
id: "delete_shopify_blog",
|
|
149
|
+
name: "Delete Shopify Blog",
|
|
150
|
+
description: "Delete a Shopify blog by its global ID.",
|
|
151
|
+
needsApproval: true,
|
|
152
|
+
input: z.object({ id: shopifyGlobalIdSchema }),
|
|
153
|
+
output: z.object({ deletedBlogId: shopifyGlobalIdSchema }),
|
|
154
|
+
run: async (input, credentials) => {
|
|
155
|
+
const response = await createShopifyClient(credentials).graphql(`
|
|
156
|
+
mutation DeleteBlog($id: ID!) {
|
|
157
|
+
blogDelete(id: $id) {
|
|
158
|
+
deletedBlogId
|
|
159
|
+
userErrors {
|
|
160
|
+
code
|
|
161
|
+
field
|
|
162
|
+
message
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
`, z.object({ blogDelete: deleteBlogResponseSchema }), { variables: { id: input.id } });
|
|
167
|
+
assertNoUserErrors(response.blogDelete.userErrors);
|
|
168
|
+
if (!response.blogDelete.deletedBlogId) throw new Error(`Shopify did not confirm blog deletion: ${input.id}`);
|
|
169
|
+
return { deletedBlogId: response.blogDelete.deletedBlogId };
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { createBlog, deleteBlog, getBlog, listBlogs, updateBlog };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as ShopifyCredentials } from "./integration-BwDBsGX-.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ClientResponse, SearchParams } from "@shopify/admin-api-client";
|
|
4
|
+
|
|
5
|
+
//#region src/client.d.ts
|
|
6
|
+
type ShopifyRestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
7
|
+
interface ShopifyGraphqlRequestOptions {
|
|
8
|
+
readonly variables?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
interface ShopifyRestRequestOptions {
|
|
11
|
+
readonly data?: Record<string, unknown> | string;
|
|
12
|
+
readonly searchParams?: SearchParams;
|
|
13
|
+
readonly headers?: Record<string, string | number | string[]>;
|
|
14
|
+
}
|
|
15
|
+
interface ShopifyClient {
|
|
16
|
+
rawGraphql<TData>(query: string, variables?: Record<string, unknown>): Promise<ClientResponse<TData>>;
|
|
17
|
+
graphql<TSchema extends z.ZodTypeAny>(query: string, schema: TSchema, options?: ShopifyGraphqlRequestOptions): Promise<z.output<TSchema>>;
|
|
18
|
+
rest<TSchema extends z.ZodTypeAny>(method: ShopifyRestMethod, path: string, schema: TSchema, options?: ShopifyRestRequestOptions): Promise<z.output<TSchema>>;
|
|
19
|
+
}
|
|
20
|
+
declare function createShopifyClient(credentials: ShopifyCredentials): ShopifyClient;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ShopifyClient, ShopifyGraphqlRequestOptions, ShopifyRestMethod, ShopifyRestRequestOptions, createShopifyClient };
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { t as shopify } from "./integration-BN3pjCz4.mjs";
|
|
2
|
+
import { shopifyGraphqlErrorSchema } from "./schemas.mjs";
|
|
3
|
+
import { CredentialRevokedError } from "@keystrokehq/core/errors";
|
|
4
|
+
import { createAdminApiClient, createAdminRestApiClient } from "@shopify/admin-api-client";
|
|
5
|
+
|
|
6
|
+
//#region src/client.ts
|
|
7
|
+
const DEFAULT_SHOPIFY_API_VERSION = "2025-01";
|
|
8
|
+
function normalizeShopifyError(error, methodPath) {
|
|
9
|
+
if (error instanceof CredentialRevokedError) return error;
|
|
10
|
+
if (error instanceof Error) {
|
|
11
|
+
const maybeStatus = error;
|
|
12
|
+
const status = maybeStatus.status ?? maybeStatus.response?.status;
|
|
13
|
+
if (status === 401 || status === 403) return new CredentialRevokedError(shopify.id, `Shopify authentication failed while calling \`${methodPath}\`. The stored credentials for ${shopify.id} may be revoked or expired.`);
|
|
14
|
+
if (status === 429) return new Error(`Shopify API throttled while calling \`${methodPath}\`: ${error.message}`, { cause: error });
|
|
15
|
+
return new Error(`Shopify API call failed while calling \`${methodPath}\`: ${error.message}`, { cause: error });
|
|
16
|
+
}
|
|
17
|
+
return /* @__PURE__ */ new Error(`Shopify API call failed while calling \`${methodPath}\`.`);
|
|
18
|
+
}
|
|
19
|
+
function createShopifyCredentialError(methodPath) {
|
|
20
|
+
return new CredentialRevokedError(shopify.id, `Shopify authentication failed while calling \`${methodPath}\`. The stored credentials for ${shopify.id} may be revoked or expired.`);
|
|
21
|
+
}
|
|
22
|
+
function assertGraphqlSuccess(response, methodPath) {
|
|
23
|
+
const status = response.errors?.networkStatusCode;
|
|
24
|
+
if (status === 401 || status === 403) throw createShopifyCredentialError(methodPath);
|
|
25
|
+
if (status === 429) throw new Error(`Shopify API throttled while calling \`${methodPath}\`: ${response.errors?.message ?? "rate limited"}`);
|
|
26
|
+
if (response.errors?.graphQLErrors?.length) {
|
|
27
|
+
const messages = response.errors.graphQLErrors.map((error) => shopifyGraphqlErrorSchema.parse(error).message).join("; ");
|
|
28
|
+
throw new Error(`Shopify GraphQL errors while calling \`${methodPath}\`: ${messages}`);
|
|
29
|
+
}
|
|
30
|
+
if (response.errors?.message) throw new Error(`Shopify API call failed while calling \`${methodPath}\`: ${response.errors.message}`);
|
|
31
|
+
if (response.data === void 0) throw new Error(`Shopify API call returned no data while calling \`${methodPath}\`.`);
|
|
32
|
+
}
|
|
33
|
+
async function parseRestResponse(response, schema, methodPath) {
|
|
34
|
+
if (response.status === 401 || response.status === 403) throw createShopifyCredentialError(methodPath);
|
|
35
|
+
if (response.status === 429) throw new Error(`Shopify API throttled while calling \`${methodPath}\`.`);
|
|
36
|
+
const payload = response.status === 204 ? null : await response.json();
|
|
37
|
+
if (!response.ok) throw new Error(`Shopify REST API call failed while calling \`${methodPath}\`: HTTP ${response.status}`);
|
|
38
|
+
return schema.parse(payload);
|
|
39
|
+
}
|
|
40
|
+
function createShopifyClient(credentials) {
|
|
41
|
+
const graphqlClient = createAdminApiClient({
|
|
42
|
+
storeDomain: credentials.SHOPIFY_STORE_DOMAIN,
|
|
43
|
+
accessToken: credentials.SHOPIFY_ACCESS_TOKEN,
|
|
44
|
+
apiVersion: DEFAULT_SHOPIFY_API_VERSION
|
|
45
|
+
});
|
|
46
|
+
const restClient = createAdminRestApiClient({
|
|
47
|
+
storeDomain: credentials.SHOPIFY_STORE_DOMAIN,
|
|
48
|
+
accessToken: credentials.SHOPIFY_ACCESS_TOKEN,
|
|
49
|
+
apiVersion: DEFAULT_SHOPIFY_API_VERSION
|
|
50
|
+
});
|
|
51
|
+
async function rawGraphql(query, variables) {
|
|
52
|
+
try {
|
|
53
|
+
return await graphqlClient.request(query, { variables });
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw normalizeShopifyError(error, "graphql");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function graphql(query, schema, options) {
|
|
59
|
+
const response = await rawGraphql(query, options?.variables);
|
|
60
|
+
assertGraphqlSuccess(response, "graphql");
|
|
61
|
+
return schema.parse(response.data);
|
|
62
|
+
}
|
|
63
|
+
async function rest(method, path, schema, options) {
|
|
64
|
+
const methodPath = `${method} ${path}`;
|
|
65
|
+
try {
|
|
66
|
+
switch (method) {
|
|
67
|
+
case "GET": return await parseRestResponse(await restClient.get(path, options), schema, methodPath);
|
|
68
|
+
case "POST": return await parseRestResponse(await restClient.post(path, {
|
|
69
|
+
...options,
|
|
70
|
+
data: options?.data ?? {}
|
|
71
|
+
}), schema, methodPath);
|
|
72
|
+
case "PUT": return await parseRestResponse(await restClient.put(path, {
|
|
73
|
+
...options,
|
|
74
|
+
data: options?.data ?? {}
|
|
75
|
+
}), schema, methodPath);
|
|
76
|
+
case "DELETE": return await parseRestResponse(await restClient.delete(path, options), schema, methodPath);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw normalizeShopifyError(error, methodPath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
rawGraphql,
|
|
84
|
+
graphql,
|
|
85
|
+
rest
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { createShopifyClient };
|
|
@@ -0,0 +1,140 @@
|
|
|
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/collections.d.ts
|
|
6
|
+
declare const listCollections: _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
|
+
title: z.ZodString;
|
|
14
|
+
handle: z.ZodString;
|
|
15
|
+
descriptionHtml: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
17
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
18
|
+
url: z.ZodURL;
|
|
19
|
+
altText: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
}, z.core.$strip>>>;
|
|
21
|
+
seo: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
22
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
pageInfo: z.ZodObject<{
|
|
27
|
+
hasNextPage: z.ZodBoolean;
|
|
28
|
+
hasPreviousPage: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
startCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
endCursor: z.ZodNullable<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
33
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
34
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
35
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
36
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
37
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
38
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
39
|
+
declare const getCollection: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
title: z.ZodString;
|
|
44
|
+
handle: z.ZodString;
|
|
45
|
+
descriptionHtml: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
47
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
48
|
+
url: z.ZodURL;
|
|
49
|
+
altText: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
}, z.core.$strip>>>;
|
|
51
|
+
seo: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
52
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
53
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
|
+
}, z.core.$strip>>>;
|
|
55
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
56
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
57
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
58
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
59
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
60
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
61
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
62
|
+
declare const createCollection: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
63
|
+
handle: z.ZodOptional<z.ZodString>;
|
|
64
|
+
descriptionHtml: z.ZodOptional<z.ZodString>;
|
|
65
|
+
seo: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
title: z.ZodOptional<z.ZodString>;
|
|
67
|
+
description: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
title: z.ZodString;
|
|
70
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
title: z.ZodString;
|
|
73
|
+
handle: z.ZodString;
|
|
74
|
+
descriptionHtml: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
75
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
76
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
77
|
+
url: z.ZodURL;
|
|
78
|
+
altText: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
79
|
+
}, z.core.$strip>>>;
|
|
80
|
+
seo: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
81
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
82
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
83
|
+
}, z.core.$strip>>>;
|
|
84
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
85
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
86
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
87
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
88
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
89
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
90
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
91
|
+
declare const deleteCollection: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
92
|
+
id: z.ZodString;
|
|
93
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
94
|
+
deletedCollectionId: z.ZodString;
|
|
95
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
96
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
97
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
98
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
99
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
100
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
101
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
102
|
+
declare const addProductsToCollection: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
103
|
+
id: z.ZodString;
|
|
104
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
105
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
106
|
+
id: z.ZodString;
|
|
107
|
+
title: z.ZodString;
|
|
108
|
+
handle: z.ZodString;
|
|
109
|
+
descriptionHtml: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
110
|
+
updatedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
111
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
112
|
+
url: z.ZodURL;
|
|
113
|
+
altText: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
114
|
+
}, z.core.$strip>>>;
|
|
115
|
+
seo: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
116
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
117
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
118
|
+
}, z.core.$strip>>>;
|
|
119
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
120
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
121
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
122
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
123
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
124
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
125
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
126
|
+
declare const removeProductsFromCollection: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
127
|
+
id: z.ZodString;
|
|
128
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
129
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
130
|
+
id: z.ZodString;
|
|
131
|
+
done: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"shopify", z.ZodObject<{
|
|
133
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
134
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
135
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
136
|
+
SHOPIFY_STORE_DOMAIN: z.ZodString;
|
|
137
|
+
SHOPIFY_ACCESS_TOKEN: z.ZodString;
|
|
138
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
139
|
+
//#endregion
|
|
140
|
+
export { addProductsToCollection, createCollection, deleteCollection, getCollection, listCollections, removeProductsFromCollection };
|