@keystrokehq/shopify 0.0.15 → 0.0.16-integration-id-canonicalization.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.
Files changed (53) hide show
  1. package/README.md +14 -153
  2. package/dist/{schemas.d.mts → common-C2s35du9.d.mts} +3 -2
  3. package/dist/{schemas.mjs → common-JZyHdK6p.mjs} +3 -3
  4. package/dist/credential-sets/index.d.mts +2 -0
  5. package/dist/credential-sets/index.mjs +4 -0
  6. package/dist/index.d.mts +4 -1
  7. package/dist/index.mjs +6 -1
  8. package/dist/operations/index.d.mts +2 -0
  9. package/dist/operations/index.mjs +3 -0
  10. package/dist/schemas/index.d.mts +2 -0
  11. package/dist/schemas/index.mjs +3 -0
  12. package/dist/shopify-app.credential-set-DuAYUhzY.d.mts +65 -0
  13. package/dist/shopify-app.credential-set-M3vKwTji.mjs +17 -0
  14. package/dist/shopify.credential-set-CaxST3GP.mjs +205 -0
  15. package/dist/update-shopify-product.operation-ByYhZggW.mjs +1972 -0
  16. package/dist/update-shopify-product.operation-Db_kLuJa.d.mts +2817 -0
  17. package/package.json +14 -69
  18. package/dist/_official/index.d.mts +0 -33
  19. package/dist/_official/index.mjs +0 -3
  20. package/dist/_runtime/index.d.mts +0 -56
  21. package/dist/_runtime/index.mjs +0 -150
  22. package/dist/articles.d.mts +0 -158
  23. package/dist/articles.mjs +0 -252
  24. package/dist/blogs.d.mts +0 -97
  25. package/dist/blogs.mjs +0 -174
  26. package/dist/client.d.mts +0 -22
  27. package/dist/client.mjs +0 -90
  28. package/dist/collections.d.mts +0 -121
  29. package/dist/collections.mjs +0 -209
  30. package/dist/connection.d.mts +0 -2
  31. package/dist/connection.mjs +0 -3
  32. package/dist/customers.d.mts +0 -142
  33. package/dist/customers.mjs +0 -225
  34. package/dist/events.d.mts +0 -181
  35. package/dist/events.mjs +0 -67
  36. package/dist/factory-DwZJl9JC.mjs +0 -8
  37. package/dist/fulfillments.d.mts +0 -89
  38. package/dist/fulfillments.mjs +0 -167
  39. package/dist/integration-B5LK_0eR.mjs +0 -63
  40. package/dist/integration-DrHCkXco.d.mts +0 -27
  41. package/dist/inventory.d.mts +0 -90
  42. package/dist/inventory.mjs +0 -182
  43. package/dist/locations.d.mts +0 -40
  44. package/dist/locations.mjs +0 -81
  45. package/dist/messaging.d.mts +0 -1
  46. package/dist/messaging.mjs +0 -1
  47. package/dist/operation-helpers-CKEDIx0o.mjs +0 -21
  48. package/dist/orders.d.mts +0 -213
  49. package/dist/orders.mjs +0 -271
  50. package/dist/products.d.mts +0 -139
  51. package/dist/products.mjs +0 -171
  52. package/dist/shop.d.mts +0 -16
  53. package/dist/shop.mjs +0 -31
package/dist/articles.mjs DELETED
@@ -1,252 +0,0 @@
1
- import { shopifyArticleSchema, shopifyConnectionNodesSchema, shopifyGlobalIdSchema, shopifyUserErrorSchema } from "./schemas.mjs";
2
- import { createShopifyClient } from "./client.mjs";
3
- import { t as shopifyOperation } from "./factory-DwZJl9JC.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/articles.ts
8
- const articleSelection = `
9
- id
10
- title
11
- handle
12
- blog {
13
-
14
- id
15
- title
16
- handle
17
- createdAt
18
- updatedAt
19
- commentPolicy
20
- templateSuffix
21
-
22
- }
23
- author {
24
- name
25
- }
26
- body
27
- summary
28
- tags
29
- image {
30
- url
31
- altText
32
- }
33
- publishedAt
34
- updatedAt
35
- `;
36
- const articleMutationInputSchema = z.object({
37
- blogId: shopifyGlobalIdSchema.optional(),
38
- title: z.string().min(1).optional(),
39
- handle: z.string().min(1).optional(),
40
- body: z.string().optional(),
41
- summary: z.string().optional(),
42
- authorName: z.string().optional(),
43
- isPublished: z.boolean().optional(),
44
- publishDate: z.iso.datetime().optional(),
45
- tags: z.array(z.string()).optional()
46
- });
47
- const articleResponseSchema = z.object({
48
- id: shopifyGlobalIdSchema,
49
- title: z.string(),
50
- handle: z.string(),
51
- blog: z.object({
52
- id: shopifyGlobalIdSchema,
53
- title: z.string(),
54
- handle: z.string(),
55
- createdAt: z.iso.datetime().optional(),
56
- updatedAt: z.iso.datetime().optional(),
57
- commentPolicy: z.string().nullable().optional(),
58
- templateSuffix: z.string().nullable().optional()
59
- }).nullable().optional(),
60
- author: z.object({ name: z.string().nullable().optional() }).nullable().optional(),
61
- body: z.string().nullable().optional(),
62
- summary: z.string().nullable().optional(),
63
- tags: z.array(z.string()).optional(),
64
- image: z.object({
65
- url: z.url(),
66
- altText: z.string().nullable().optional()
67
- }).nullable().optional(),
68
- publishedAt: z.iso.datetime().nullable().optional(),
69
- updatedAt: z.iso.datetime().optional()
70
- });
71
- const articleMutationPayloadSchema = z.object({
72
- article: articleResponseSchema.nullable(),
73
- userErrors: z.array(shopifyUserErrorSchema.extend({ code: z.string().optional() }))
74
- });
75
- const listArticlesResponseSchema = z.object({ articles: shopifyConnectionNodesSchema(articleResponseSchema) });
76
- const getArticleResponseSchema = z.object({ article: articleResponseSchema.nullable() });
77
- const deleteArticleResponseSchema = z.object({
78
- deletedArticleId: shopifyGlobalIdSchema.nullable(),
79
- userErrors: z.array(shopifyUserErrorSchema.extend({ code: z.string().optional() }))
80
- });
81
- function normalizeArticle(article) {
82
- return {
83
- id: article.id,
84
- title: article.title,
85
- handle: article.handle,
86
- blog: article.blog ?? null,
87
- author: article.author?.name ?? null,
88
- body: article.body ?? null,
89
- summary: article.summary ?? null,
90
- tags: article.tags,
91
- image: article.image ?? null,
92
- publishedAt: article.publishedAt ?? null,
93
- updatedAt: article.updatedAt
94
- };
95
- }
96
- function buildArticleInput(input) {
97
- return omitUndefined({
98
- blogId: input.blogId,
99
- title: input.title,
100
- handle: input.handle,
101
- body: input.body,
102
- summary: input.summary,
103
- author: input.authorName ? { name: input.authorName } : void 0,
104
- isPublished: input.isPublished,
105
- publishDate: input.publishDate,
106
- tags: input.tags
107
- });
108
- }
109
- const listArticles = shopifyOperation({
110
- id: "shopify.list-shopify-articles",
111
- name: "List Shopify Articles",
112
- description: "List blog articles from the connected Shopify store.",
113
- input: shopifyPageInputSchema,
114
- output: shopifyConnectionNodesSchema(shopifyArticleSchema),
115
- run: async (input, credentials) => {
116
- const response = await createShopifyClient(credentials).graphql(`
117
- query ListArticles($first: Int!, $after: String, $query: String) {
118
- articles(first: $first, after: $after, query: $query) {
119
- nodes {
120
- ${articleSelection}
121
- }
122
- pageInfo {
123
- hasNextPage
124
- hasPreviousPage
125
- startCursor
126
- endCursor
127
- }
128
- }
129
- }
130
- `, listArticlesResponseSchema, { variables: {
131
- first: input.first,
132
- ...input.after ? { after: input.after } : {},
133
- ...input.query ? { query: input.query } : {}
134
- } });
135
- return {
136
- nodes: response.articles.nodes.map(normalizeArticle),
137
- pageInfo: response.articles.pageInfo
138
- };
139
- }
140
- });
141
- const getArticle = shopifyOperation({
142
- id: "shopify.get-shopify-article",
143
- name: "Get Shopify Article",
144
- description: "Retrieve a single Shopify article by its global ID.",
145
- input: z.object({ id: shopifyGlobalIdSchema }),
146
- output: shopifyArticleSchema,
147
- run: async (input, credentials) => {
148
- const response = await createShopifyClient(credentials).graphql(`
149
- query GetArticle($id: ID!) {
150
- article(id: $id) {
151
- ${articleSelection}
152
- }
153
- }
154
- `, getArticleResponseSchema, { variables: { id: input.id } });
155
- if (!response.article) throw new Error(`Shopify article not found: ${input.id}`);
156
- return normalizeArticle(response.article);
157
- }
158
- });
159
- const createArticle = shopifyOperation({
160
- id: "shopify.create-shopify-article",
161
- name: "Create Shopify Article",
162
- description: "Create an article in the connected Shopify store.",
163
- needsApproval: true,
164
- input: articleMutationInputSchema.extend({
165
- blogId: shopifyGlobalIdSchema,
166
- title: z.string().min(1)
167
- }),
168
- output: shopifyArticleSchema,
169
- run: async (input, credentials) => {
170
- const response = await createShopifyClient(credentials).graphql(`
171
- mutation CreateArticle($article: ArticleCreateInput!) {
172
- articleCreate(article: $article) {
173
- article {
174
- ${articleSelection}
175
- }
176
- userErrors {
177
- code
178
- field
179
- message
180
- }
181
- }
182
- }
183
- `, z.object({ articleCreate: articleMutationPayloadSchema }), { variables: { article: buildArticleInput(input) } });
184
- assertNoUserErrors(response.articleCreate.userErrors);
185
- if (!response.articleCreate.article) throw new Error("Shopify did not return the created article.");
186
- return normalizeArticle(response.articleCreate.article);
187
- }
188
- });
189
- const updateArticle = shopifyOperation({
190
- id: "shopify.update-shopify-article",
191
- name: "Update Shopify Article",
192
- description: "Update a Shopify article by its global ID.",
193
- needsApproval: true,
194
- input: articleMutationInputSchema.extend({
195
- id: shopifyGlobalIdSchema,
196
- redirectNewHandle: z.boolean().optional()
197
- }),
198
- output: shopifyArticleSchema,
199
- run: async (input, credentials) => {
200
- const response = await createShopifyClient(credentials).graphql(`
201
- mutation UpdateArticle($id: ID!, $article: ArticleUpdateInput!) {
202
- articleUpdate(id: $id, article: $article) {
203
- article {
204
- ${articleSelection}
205
- }
206
- userErrors {
207
- code
208
- field
209
- message
210
- }
211
- }
212
- }
213
- `, z.object({ articleUpdate: articleMutationPayloadSchema }), { variables: {
214
- id: input.id,
215
- article: omitUndefined({
216
- ...buildArticleInput(input),
217
- redirectNewHandle: input.redirectNewHandle
218
- })
219
- } });
220
- assertNoUserErrors(response.articleUpdate.userErrors);
221
- if (!response.articleUpdate.article) throw new Error(`Shopify did not return the updated article: ${input.id}`);
222
- return normalizeArticle(response.articleUpdate.article);
223
- }
224
- });
225
- const deleteArticle = shopifyOperation({
226
- id: "shopify.delete-shopify-article",
227
- name: "Delete Shopify Article",
228
- description: "Delete a Shopify article by its global ID.",
229
- needsApproval: true,
230
- input: z.object({ id: shopifyGlobalIdSchema }),
231
- output: z.object({ deletedArticleId: shopifyGlobalIdSchema }),
232
- run: async (input, credentials) => {
233
- const response = await createShopifyClient(credentials).graphql(`
234
- mutation DeleteArticle($id: ID!) {
235
- articleDelete(id: $id) {
236
- deletedArticleId
237
- userErrors {
238
- code
239
- field
240
- message
241
- }
242
- }
243
- }
244
- `, z.object({ articleDelete: deleteArticleResponseSchema }), { variables: { id: input.id } });
245
- assertNoUserErrors(response.articleDelete.userErrors);
246
- if (!response.articleDelete.deletedArticleId) throw new Error(`Shopify did not confirm article deletion: ${input.id}`);
247
- return { deletedArticleId: response.articleDelete.deletedArticleId };
248
- }
249
- });
250
-
251
- //#endregion
252
- export { createArticle, deleteArticle, getArticle, listArticles, updateArticle };
package/dist/blogs.d.mts DELETED
@@ -1,97 +0,0 @@
1
- import { z } from "zod";
2
- import * as _keystrokehq_core0 from "@keystrokehq/core";
3
-
4
- //#region src/blogs.d.ts
5
- declare const listBlogs: _keystrokehq_core0.Operation<z.ZodObject<{
6
- first: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
7
- after: z.ZodOptional<z.ZodString>;
8
- query: z.ZodOptional<z.ZodString>;
9
- }, z.core.$strip>, z.ZodObject<{
10
- nodes: z.ZodArray<z.ZodObject<{
11
- id: z.ZodString;
12
- title: z.ZodString;
13
- handle: z.ZodString;
14
- createdAt: z.ZodOptional<z.ZodISODateTime>;
15
- updatedAt: z.ZodOptional<z.ZodISODateTime>;
16
- commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
- templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
18
- }, z.core.$strip>>;
19
- pageInfo: z.ZodObject<{
20
- hasNextPage: z.ZodBoolean;
21
- hasPreviousPage: z.ZodOptional<z.ZodBoolean>;
22
- startCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
- endCursor: z.ZodNullable<z.ZodString>;
24
- }, z.core.$strip>;
25
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:shopify", z.ZodObject<{
26
- SHOPIFY_STORE_DOMAIN: z.ZodString;
27
- SHOPIFY_ACCESS_TOKEN: z.ZodString;
28
- }, z.core.$strip>>], undefined>;
29
- declare const getBlog: _keystrokehq_core0.Operation<z.ZodObject<{
30
- id: z.ZodString;
31
- }, z.core.$strip>, z.ZodObject<{
32
- id: z.ZodString;
33
- title: z.ZodString;
34
- handle: z.ZodString;
35
- createdAt: z.ZodOptional<z.ZodISODateTime>;
36
- updatedAt: z.ZodOptional<z.ZodISODateTime>;
37
- commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
38
- templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
39
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:shopify", z.ZodObject<{
40
- SHOPIFY_STORE_DOMAIN: z.ZodString;
41
- SHOPIFY_ACCESS_TOKEN: z.ZodString;
42
- }, z.core.$strip>>], undefined>;
43
- declare const createBlog: _keystrokehq_core0.Operation<z.ZodObject<{
44
- handle: z.ZodOptional<z.ZodString>;
45
- templateSuffix: z.ZodOptional<z.ZodString>;
46
- commentPolicy: z.ZodOptional<z.ZodEnum<{
47
- DISABLED: "DISABLED";
48
- HIDDEN: "HIDDEN";
49
- MODERATED: "MODERATED";
50
- OPEN: "OPEN";
51
- }>>;
52
- title: z.ZodString;
53
- }, z.core.$strip>, z.ZodObject<{
54
- id: z.ZodString;
55
- title: z.ZodString;
56
- handle: z.ZodString;
57
- createdAt: z.ZodOptional<z.ZodISODateTime>;
58
- updatedAt: z.ZodOptional<z.ZodISODateTime>;
59
- commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
- templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
61
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:shopify", z.ZodObject<{
62
- SHOPIFY_STORE_DOMAIN: z.ZodString;
63
- SHOPIFY_ACCESS_TOKEN: z.ZodString;
64
- }, z.core.$strip>>], undefined>;
65
- declare const updateBlog: _keystrokehq_core0.Operation<z.ZodObject<{
66
- title: z.ZodOptional<z.ZodString>;
67
- handle: z.ZodOptional<z.ZodString>;
68
- templateSuffix: z.ZodOptional<z.ZodString>;
69
- commentPolicy: z.ZodOptional<z.ZodEnum<{
70
- DISABLED: "DISABLED";
71
- HIDDEN: "HIDDEN";
72
- MODERATED: "MODERATED";
73
- OPEN: "OPEN";
74
- }>>;
75
- id: z.ZodString;
76
- }, z.core.$strip>, z.ZodObject<{
77
- id: z.ZodString;
78
- title: z.ZodString;
79
- handle: z.ZodString;
80
- createdAt: z.ZodOptional<z.ZodISODateTime>;
81
- updatedAt: z.ZodOptional<z.ZodISODateTime>;
82
- commentPolicy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
83
- templateSuffix: z.ZodOptional<z.ZodNullable<z.ZodString>>;
84
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:shopify", z.ZodObject<{
85
- SHOPIFY_STORE_DOMAIN: z.ZodString;
86
- SHOPIFY_ACCESS_TOKEN: z.ZodString;
87
- }, z.core.$strip>>], undefined>;
88
- declare const deleteBlog: _keystrokehq_core0.Operation<z.ZodObject<{
89
- id: z.ZodString;
90
- }, z.core.$strip>, z.ZodObject<{
91
- deletedBlogId: z.ZodString;
92
- }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"keystroke:shopify", z.ZodObject<{
93
- SHOPIFY_STORE_DOMAIN: z.ZodString;
94
- SHOPIFY_ACCESS_TOKEN: z.ZodString;
95
- }, z.core.$strip>>], undefined>;
96
- //#endregion
97
- export { createBlog, deleteBlog, getBlog, listBlogs, updateBlog };
package/dist/blogs.mjs DELETED
@@ -1,174 +0,0 @@
1
- import { shopifyBlogSchema, shopifyConnectionNodesSchema, shopifyGlobalIdSchema, shopifyUserErrorSchema } from "./schemas.mjs";
2
- import { createShopifyClient } from "./client.mjs";
3
- import { t as shopifyOperation } from "./factory-DwZJl9JC.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: "shopify.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: "shopify.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: "shopify.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: "shopify.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: "shopify.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 };
package/dist/client.d.mts DELETED
@@ -1,22 +0,0 @@
1
- import { t as ShopifyCredentials } from "./integration-DrHCkXco.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 DELETED
@@ -1,90 +0,0 @@
1
- import { t as shopify } from "./integration-B5LK_0eR.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 };