@@ -4,40 +4,46 @@ function usageSample(hasApiKey: boolean): HelpSample {
44 return {
55 title : "Using the client" ,
66 code : `
7- import { Airtable } from "@trigger.dev/airtable";
7+ import { Airtable } from "@trigger.dev/airtable";
88
9- const airtable = new Airtable({
10- id: "__SLUG__"${ hasApiKey ? ",\n token: process.env.AIRTABLE_API_KEY !" : "" }
11- });
9+ const airtable = new Airtable({
10+ id: "__SLUG__"${ hasApiKey ? ",\n token: process.env.AIRTABLE_TOKEN !" : "" }
11+ });
1212
13- client.defineJob({
14- id: "alert-on-new-github-issues",
15- name: "Alert on new GitHub issues",
16- version: "0.1.1",
17- trigger: github.triggers.repo({
18- event: events.onIssueOpened,
19- owner: "triggerdotdev",
20- repo: "trigger.dev",
13+ //you can define your Airtable table types
14+ type LaunchGoalsAndOkRs = {
15+ "Launch goals"?: string;
16+ DRI?: Collaborator;
17+ Team?: string;
18+ Status?: "On track" | "In progress" | "At risk";
19+ "Key results"?: Array<string>;
20+ "Features (from 💻 Features table)"?: Array<string>;
21+ "Status (from 💻 Features)": Array<"Live" | "Complete" | "In progress" | "Planning" | "In reviews">;
22+ };
23+
24+ client.defineJob({
25+ id: "airtable-example-1",
26+ name: "Airtable Example 1: getRecords",
27+ version: "0.1.0",
28+ trigger: eventTrigger({
29+ name: "airtable.example",
30+ schema: z.object({
31+ baseId: z.string(),
32+ tableName: z.string(),
2133 }),
22- run: async (payload, io, ctx) => {
23- //wrap the SDK call in runTask
24- const { data } = await io.runTask(
25- "create-card",
26- { name: "Create card" },
27- async () => {
28- //create a project card using the underlying client
29- return io.github.client.rest.projects.createCard({
30- column_id: 123,
31- note: "test",
32- });
33- }
34- );
35-
36- //log the url of the created card
37- await io.logger.info(data.url);
38- },
39- });
40-
34+ }),
35+ integrations: {
36+ airtable,
37+ },
38+ run: async (payload, io, ctx) => {
39+ //then you can set the types for your table, so you get type safety
40+ const table = io.airtable.base(payload.baseId).table<LaunchGoalsAndOkRs>(payload.tableName);
41+
42+ const records = await table.getRecords("muliple records", { fields: ["Status"] });
43+ //this will be type checked
44+ await io.logger.log(records[0].fields.Status ?? "no status");
45+ },
46+ });
4147 ` ,
4248 } ;
4349}
0 commit comments