Skip to content

Commit fad8f44

Browse files
ericallammatt-aitken
authored andcommitted
Breakout shopify into it’s own package
1 parent 5f517a5 commit fad8f44

16 files changed

Lines changed: 1946 additions & 16 deletions

File tree

apps/webapp/app/services/requests/performIntegrationRequest.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import type {
44
NormalizedResponse,
55
PerformedRequestResponse,
66
} from "@trigger.dev/integration-sdk";
7-
import { shopify } from "internal-integrations";
7+
88
import * as slack from "@trigger.dev/slack/internal";
99
import * as resend from "@trigger.dev/resend/internal";
10+
import * as shopify from "@trigger.dev/shopify/internal";
1011
import type { PrismaClient } from "~/db.server";
1112
import { prisma } from "~/db.server";
1213
import type { IntegrationRequest } from "~/models/integrationRequest.server";

apps/webapp/remix.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
"@trigger.dev/github",
1818
"@trigger.dev/slack",
1919
"@trigger.dev/resend",
20+
"@trigger.dev/shopify",
2021
"@trigger.dev/common-schemas",
2122
"@trigger.dev/sdk",
2223
"@trigger.dev/integrations",
@@ -39,6 +40,7 @@ module.exports = {
3940
"../../integrations/github/src/**/*",
4041
"../../integrations/slack/src/**/*",
4142
"../../integrations/resend/src/**/*",
43+
"../../integrations/shopify/src/**/*",
4244
];
4345
},
4446
};

apps/webapp/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
"@trigger.dev/slack": ["../../integrations/slack/src/index"],
5656
"@trigger.dev/slack/*": ["../../integrations/slack/src/*"],
5757
"@trigger.dev/resend": ["../../integrations/resend/src/index"],
58-
"@trigger.dev/resend/*": ["../../integrations/resend/src/*"]
58+
"@trigger.dev/resend/*": ["../../integrations/resend/src/*"],
59+
"@trigger.dev/shopify": ["../../integrations/shopify/src/index"],
60+
"@trigger.dev/shopify/*": ["../../integrations/shopify/src/*"]
5961
},
6062
"noEmit": true
6163
}

config-packages/tsconfig/examples.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
],
4848
"@trigger.dev/resend/*": [
4949
"../../integrations/resend/src/*"
50+
],
51+
"@trigger.dev/shopify": [
52+
"../../integrations/shopify/src/index"
53+
],
54+
"@trigger.dev/shopify/*": [
55+
"../../integrations/shopify/src/*"
5056
]
5157
}
5258
}

examples/shopify/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.1",
55
"description": "Send a message to slack when a customer creates a new custom domain",
66
"dependencies": {
7-
"@trigger.dev/integrations": "workspace:*",
7+
"@trigger.dev/shopify": "workspace:*",
88
"@trigger.dev/sdk": "workspace:*",
99
"zod": "^3.20.2"
1010
},
@@ -16,4 +16,4 @@
1616
"scripts": {
1717
"dev": "tsx src/index.ts"
1818
}
19-
}
19+
}

examples/shopify/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Trigger, customEvent } from "@trigger.dev/sdk";
22
import { z } from "zod";
3-
import { shopify } from "@trigger.dev/integrations";
3+
import * as shopify from "@trigger.dev/shopify";
44

55
const sizes = ["Small", "Medium", "Large"];
66
const colors = [

integrations/shopify/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Trigger.dev Shopify integration
2+
3+
View more documentation [here](https://docs.trigger.dev)

integrations/shopify/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@trigger.dev/shopify",
3+
"version": "0.1.16",
4+
"description": "The official Shopify integration for Trigger.dev",
5+
"exports": {
6+
".": {
7+
"import": "./dist/index.js",
8+
"require": "./dist/index.js",
9+
"types": "./dist/index.d.ts"
10+
},
11+
"./package.json": "./package.json"
12+
},
13+
"publishConfig": {
14+
"access": "public"
15+
},
16+
"files": [
17+
"dist"
18+
],
19+
"devDependencies": {
20+
"@shopify/shopify-api": "^6.1.0",
21+
"@trigger.dev/integration-sdk": "workspace:*",
22+
"@trigger.dev/sdk": "workspace:*",
23+
"@trigger.dev/tsconfig": "workspace:*",
24+
"@types/debug": "^4.1.7",
25+
"@types/node": "16",
26+
"@urql/core": "^3.1.1",
27+
"graphql": "^16.6.0",
28+
"react": "^18.2.0",
29+
"rimraf": "^3.0.2",
30+
"tsup": "^6.5.0",
31+
"urql": "^3.0.3"
32+
},
33+
"peerDependencies": {
34+
"@trigger.dev/sdk": "workspace:*"
35+
},
36+
"scripts": {
37+
"clean": "rimraf dist",
38+
"build": "npm run clean && npm run build:tsup",
39+
"build:tsup": "tsup"
40+
},
41+
"dependencies": {
42+
"@shopify/admin-graphql-api-utilities": "^2.0.1",
43+
"debug": "^4.3.4",
44+
"zod": "^3.20.2"
45+
}
46+
}

integrations/shopify/src/index.ts

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
import { getTriggerRun } from "@trigger.dev/sdk";
2+
import { z } from "zod";
3+
import {
4+
SearchVariantsBodySchema,
5+
SearchVariantsSuccessResponseSchema,
6+
CreateVariantBodySchema,
7+
ProductVariantSchema,
8+
GetProductBodySchema,
9+
ProductSchema,
10+
CreateProductBodySchema,
11+
UpdateProductBodySchema,
12+
AppendProductImagesBodySchema,
13+
AppendProductImagesResponseSchema,
14+
ListCollectionsBodySchema,
15+
ListCollectionsResponseSchema,
16+
ListLocationsBodySchema,
17+
ListLocationsResponseSchema,
18+
AddProductsToCollectionBodySchema,
19+
AddProductsToCollectionResponseSchema,
20+
} from "./schemas";
21+
22+
export type SearchVariantsOptions = z.infer<typeof SearchVariantsBodySchema>;
23+
export type SearchVariantsResponse = z.infer<
24+
typeof SearchVariantsSuccessResponseSchema
25+
>;
26+
27+
export async function searchProductVariants(
28+
key: string,
29+
options: SearchVariantsOptions
30+
): Promise<SearchVariantsResponse> {
31+
const run = getTriggerRun();
32+
33+
if (!run) {
34+
throw new Error(
35+
"Cannot call searchProductVariants outside of a trigger run"
36+
);
37+
}
38+
39+
const output = await run.performRequest(key, {
40+
service: "shopify",
41+
endpoint: "productVariants.search",
42+
params: options,
43+
response: {
44+
schema: SearchVariantsSuccessResponseSchema,
45+
},
46+
});
47+
48+
return output;
49+
}
50+
51+
export type CreateVariantBody = z.infer<typeof CreateVariantBodySchema>;
52+
53+
export type CreateVariantResponse = z.infer<typeof ProductVariantSchema>;
54+
55+
export async function createProductVariant(
56+
key: string,
57+
options: CreateVariantBody
58+
): Promise<CreateVariantResponse> {
59+
const run = getTriggerRun();
60+
61+
if (!run) {
62+
throw new Error(
63+
"Cannot call createProductVariant outside of a trigger run"
64+
);
65+
}
66+
67+
const output = await run.performRequest(key, {
68+
service: "shopify",
69+
endpoint: "productVariant.create",
70+
params: options,
71+
response: {
72+
schema: ProductVariantSchema,
73+
},
74+
});
75+
76+
return output;
77+
}
78+
79+
export type GetProductBody = z.infer<typeof GetProductBodySchema>;
80+
81+
export type GetProductResponse = z.infer<typeof ProductSchema>;
82+
83+
export async function getProduct(
84+
key: string,
85+
options: GetProductBody
86+
): Promise<GetProductResponse> {
87+
const run = getTriggerRun();
88+
89+
if (!run) {
90+
throw new Error("Cannot call getProduct outside of a trigger run");
91+
}
92+
93+
const output = await run.performRequest(key, {
94+
service: "shopify",
95+
endpoint: "product.get",
96+
params: options,
97+
response: {
98+
schema: ProductSchema,
99+
},
100+
});
101+
102+
return output;
103+
}
104+
105+
export type CreateProductBody = z.infer<typeof CreateProductBodySchema>;
106+
107+
export type CreateProductResponse = z.infer<typeof ProductSchema>;
108+
109+
export async function createProduct(
110+
key: string,
111+
options: CreateProductBody
112+
): Promise<CreateProductResponse> {
113+
const run = getTriggerRun();
114+
115+
if (!run) {
116+
throw new Error("Cannot call createProduct outside of a trigger run");
117+
}
118+
119+
const output = await run.performRequest(key, {
120+
service: "shopify",
121+
endpoint: "product.create",
122+
params: options,
123+
response: {
124+
schema: ProductSchema,
125+
},
126+
});
127+
128+
return output;
129+
}
130+
131+
export type UpdateProductBody = z.infer<typeof UpdateProductBodySchema>;
132+
133+
export type UpdateProductResponse = z.infer<typeof ProductSchema>;
134+
135+
export async function updateProduct(
136+
key: string,
137+
options: UpdateProductBody
138+
): Promise<UpdateProductResponse> {
139+
const run = getTriggerRun();
140+
141+
if (!run) {
142+
throw new Error("Cannot call updateProduct outside of a trigger run");
143+
}
144+
145+
const output = await run.performRequest(key, {
146+
service: "shopify",
147+
endpoint: "product.update",
148+
params: options,
149+
response: {
150+
schema: ProductSchema,
151+
},
152+
});
153+
154+
return output;
155+
}
156+
157+
export type AppendProductImagesBody = z.infer<
158+
typeof AppendProductImagesBodySchema
159+
>;
160+
161+
export type AppendProductImagesResponse = z.infer<
162+
typeof AppendProductImagesResponseSchema
163+
>;
164+
165+
export async function appendProductImages(
166+
key: string,
167+
options: AppendProductImagesBody
168+
): Promise<AppendProductImagesResponse> {
169+
const run = getTriggerRun();
170+
171+
if (!run) {
172+
throw new Error("Cannot call appendProductImages outside of a trigger run");
173+
}
174+
175+
const output = await run.performRequest(key, {
176+
service: "shopify",
177+
endpoint: "productImages.append",
178+
params: options,
179+
response: {
180+
schema: AppendProductImagesResponseSchema,
181+
},
182+
});
183+
184+
return output;
185+
}
186+
187+
export type ListCollectionsBody = z.infer<typeof ListCollectionsBodySchema>;
188+
189+
export type ListCollectionsResponse = z.infer<
190+
typeof ListCollectionsResponseSchema
191+
>;
192+
193+
export async function listCollections(
194+
key: string,
195+
options: ListCollectionsBody
196+
): Promise<ListCollectionsResponse> {
197+
const run = getTriggerRun();
198+
199+
if (!run) {
200+
throw new Error("Cannot call listCollections outside of a trigger run");
201+
}
202+
203+
const output = await run.performRequest(key, {
204+
service: "shopify",
205+
endpoint: "collections.list",
206+
params: options,
207+
response: {
208+
schema: ListCollectionsResponseSchema,
209+
},
210+
});
211+
212+
return output;
213+
}
214+
215+
export type ListLocationsBody = z.infer<typeof ListLocationsBodySchema>;
216+
217+
export type ListLocationsResponse = z.infer<typeof ListLocationsResponseSchema>;
218+
219+
export async function listLocations(
220+
key: string,
221+
options: ListLocationsBody
222+
): Promise<ListLocationsResponse> {
223+
const run = getTriggerRun();
224+
225+
if (!run) {
226+
throw new Error("Cannot call listLocations outside of a trigger run");
227+
}
228+
229+
const output = await run.performRequest(key, {
230+
service: "shopify",
231+
endpoint: "locations.list",
232+
params: options,
233+
response: {
234+
schema: ListLocationsResponseSchema,
235+
},
236+
});
237+
238+
return output;
239+
}
240+
241+
export type AddProductsToCollectionBody = z.infer<
242+
typeof AddProductsToCollectionBodySchema
243+
>;
244+
245+
export type AddProductsToCollectionResponse = z.infer<
246+
typeof AddProductsToCollectionResponseSchema
247+
>;
248+
249+
export async function addProductsToCollection(
250+
key: string,
251+
options: AddProductsToCollectionBody
252+
): Promise<AddProductsToCollectionResponse> {
253+
const run = getTriggerRun();
254+
255+
if (!run) {
256+
throw new Error(
257+
"Cannot call addProductsToCollection outside of a trigger run"
258+
);
259+
}
260+
261+
const output = await run.performRequest(key, {
262+
service: "shopify",
263+
endpoint: "collection.addProducts",
264+
params: options,
265+
response: {
266+
schema: AddProductsToCollectionResponseSchema,
267+
},
268+
});
269+
270+
return output;
271+
}

0 commit comments

Comments
 (0)