The new fields from the Integration catalog are now in the database

This commit is contained in:
Matt Aitken
2023-06-30 17:24:40 +01:00
parent 93c3b10bf7
commit fa1e6bf5e6
9 changed files with 154 additions and 37 deletions
@@ -71,6 +71,20 @@ export const airtable: Integration = {
defaultChecked: true,
},
],
help: {
samples: [
{
title: "Creating the client",
code: `
import { Airtable } from "@trigger.dev/airtable";
const airtable = new Airtable({
id: "__SLUG__"
});
`,
},
],
},
},
},
};
@@ -1,4 +1,4 @@
import type { Integration, ScopeAnnotation } from "../types";
import type { HelpSample, Integration, ScopeAnnotation } from "../types";
const repoAnnotation: ScopeAnnotation = {
label: "Repo",
@@ -20,6 +20,47 @@ const userAnnotation: ScopeAnnotation = {
label: "User",
};
const usageSample: HelpSample = {
title: "Using the client",
code: `
import { Github, events } from "@trigger.dev/github";
const github = new Github({
id: "__SLUG__",
token: process.env.GITHUB_TOKEN,
});
new Job(client, {
id: "alert-on-new-github-issues",
name: "Alert on new GitHub issues",
version: "0.1.1",
trigger: github.triggers.repo({
event: events.onIssueOpened,
owner: "triggerdotdev",
repo: "trigger.dev",
}),
run: async (payload, io, ctx) => {
//wrap the SDK call in runTask
const { data } = await io.runTask(
"create-card",
{ name: "Create card" },
async () => {
//create a project card using the underlying client
return io.github.client.rest.projects.createCard({
column_id: 123,
note: "test",
});
}
);
//log the url of the created card
await io.logger.info(data.url);
},
});
`,
};
export const github: Integration = {
identifier: "github",
name: "GitHub",
@@ -260,6 +301,21 @@ export const github: Integration = {
"Grants the ability to add and update GitHub Actions workflow files. Workflow files can be committed without this scope if the same file (with both the same path and contents) exists on another branch in the same repository. Workflow files can expose GITHUB_TOKEN which may have a different set of scopes.",
},
],
help: {
samples: [
{
title: "Creating the client",
code: `
import { Github } from "@trigger.dev/github";
const github = new Github({
id: "__SLUG__"
});
`,
},
usageSample,
],
},
},
apikey: {
type: "apikey",
@@ -271,38 +327,12 @@ export const github: Integration = {
import { Github } from "@trigger.dev/github";
const github = new Github({
id: "github",
id: "__SLUG__",
token: process.env.GITHUB_TOKEN
});
`,
},
{
title: "Using the client",
code: `
new Job(client, {
id: "alert-on-new-github-issues",
name: "Alert on new GitHub issues",
version: "0.1.1",
integrations: {
//if you want to use the client in the run function, pass it in
github,
},
//you can also subscribe to events using the client
trigger: github.triggers.repo({
event: events.onIssueOpened,
repo: "ericallam/basic-starter-12k",
}),
run: async (payload, io, ctx) => {
const repo = await io.github.getRepo("get-repo", {
repo: \`\${payload.repository.owner}/\${payload.repository.name}\`,
});
return repo;
},
});
`,
},
usageSample,
],
},
},
@@ -17,7 +17,7 @@ export const openai: Integration = {
import { OpenAI } from "@trigger.dev/openai";
const openai = new OpenAI({
id: "openai",
id: "__SLUG__",
apiKey: process.env.OPENAI_API_KEY!,
});
`,
@@ -15,7 +15,7 @@ export const resend: Integration = {
import { Resend } from "@trigger.dev/resend";
const resend = new Resend({
id: "resend",
id: "__SLUG__",
apiKey: process.env.RESEND_API_KEY!,
});
`,
@@ -47,7 +47,6 @@ new Job(client, {
});
},
});
`,
highlight: [
[13, 15],
@@ -1,4 +1,46 @@
import type { Integration } from "../types";
import type { Help, Integration } from "../types";
const help: Help = {
samples: [
{
title: "Creating the client",
code: `
import { Slack } from "@trigger.dev/slack";
const slack = new Slack({
id: "__SLUG__",
});
`,
},
{
title: "Using the client",
code: `
new Job(client, {
id: "slack-test",
name: "Slack test",
version: "0.0.1",
trigger: eventTrigger({
name: "slack.test",
schema: z.object({}),
}),
integrations: {
slack,
},
run: async (payload, io, ctx) => {
const response = await io.slack.postMessage("post message", {
channel: "C04GWUTDC3W",
text: "My first Slack message",
});
},
});
`,
highlight: [
[13, 15],
[17, 22],
],
},
],
};
export const slack: Integration = {
identifier: "slack",
@@ -374,6 +416,7 @@ export const slack: Integration = {
description: "Add steps that people can use in Workflow Builder",
},
],
help,
},
oauth2User: {
name: "OAuth2 (User)",
@@ -824,6 +867,7 @@ export const slack: Integration = {
description: "Set presence for your slack app",
},
],
help,
},
},
};
+15 -3
View File
@@ -18,12 +18,23 @@ export type ApiAuthenticationMethod =
| ApiAuthenticationMethodOAuth2
| ApiAuthenticationMethodApiKey;
const HelpSampleSchema = z.object({
title: z.string(),
code: z.string(),
highlight: z.array(z.tuple([z.number(), z.number()])).optional(),
});
export const HelpSchema = z.object({
samples: z.array(HelpSampleSchema),
});
export type Help = z.infer<typeof HelpSchema>;
export type HelpSample = z.infer<typeof HelpSampleSchema>;
export type ApiAuthenticationMethodApiKey = {
/** The type of authentication method */
type: "apikey";
help: {
samples: { title: string; code: string; highlight?: [number, number][] }[];
};
help: Help;
};
//A useful reference is the Simple OAuth2 npm library: https://github.com/lelylan/simple-oauth2/blob/HEAD/API.md#options
@@ -98,6 +109,7 @@ export type ApiAuthenticationMethodOAuth2 = {
additionalFields?: AdditionalField[];
/** The possible scopes this auth method supports */
scopes: Scope[];
help: Help;
};
export type AuthorizationLocation = "header" | "body";
+9 -1
View File
@@ -16,8 +16,14 @@ async function seedIntegrationAuthMethods() {
id: identifier,
name: integration.name,
instructions: "Instructions go here",
description: integration.description,
packageName: integration.packageName,
},
update: {
name: integration.name,
description: integration.description,
packageName: integration.packageName,
},
update: {},
});
for (const [key, authMethod] of Object.entries(
@@ -46,6 +52,7 @@ async function seedIntegrationAuthMethods() {
id: identifier,
},
},
help: authMethod.help,
},
update: {
name: authMethod.name,
@@ -54,6 +61,7 @@ async function seedIntegrationAuthMethods() {
client: authMethod.client,
config: authMethod.config,
scopes: authMethod.scopes,
help: authMethod.help,
},
});
}
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "IntegrationAuthMethod" ADD COLUMN "help" JSONB;
-- AlterTable
ALTER TABLE "IntegrationDefinition" ADD COLUMN "description" TEXT,
ADD COLUMN "packageName" TEXT NOT NULL DEFAULT '';
+4
View File
@@ -112,6 +112,8 @@ model IntegrationAuthMethod {
definition IntegrationDefinition @relation(fields: [definitionId], references: [id], onDelete: Cascade, onUpdate: Cascade)
definitionId String
help Json?
@@unique([definitionId, key])
}
@@ -119,6 +121,8 @@ model IntegrationDefinition {
id String @id
name String
instructions String?
description String?
packageName String @default("")
authMethods IntegrationAuthMethod[]
Integration Integration[]