92233f2e90
* Changeset should ignore the example projects * Removed note in Contributing instructions about not adding a changeset for internal * Renamed @trigger.dev/internal to @trigger.dev/core. Set sdk and internal to be ES2020, so we don’t get errors about private identifiers * Env vars in nextjs-example use square bracket syntax to avoid Turbo Repo errors * Set the tsconfigs back for core and sdk * @examples/nextjs compile error with undefined tasks * Set the example projects to use ES2015 to avoid private modifier complaints * package-tester example, which will use built packages * package-tester package.json * Created a readme for the package-tester * Added all the packages to package-tester * Create .env.local.example and readme instructions * Added name to the package.json * Upgraded @types/react and @types/react-dom everywhrre, so we can use server actions * Upgraded @types/react and @types/react-dom everywhrre, so we can use server actions * Reworked the react package build, so it generates separate files * The SDK no longer bundles core * package-tester setup with a server action and react hooks * Added new SDK methods with logging * Working tsup settings for client and server * Explicit react hooks return types * Added all the hooks for testing * Added OpenAI step to the job to check types are still ok in integrations * Get rid of rogue Changeset ignores * Changeset: @trigger.dev/core is now a separate package * Exited prerelease mode, added a changeset * Changed @next to @latest * Deleted seed.js, this shouldn’t be committed * Ignore seed.js * The webapp was importing @trigger.dev/core with a folder path rather package name… * More webapp imports instead of @trigger.dev/core were a folder path * Accidentally edited Stripe internal API url in the comment * Added “sideEffects”: false so @trigger.dev/core is tree shaken by Remix
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { $transaction, PrismaClientOrTransaction, prisma } from "~/db.server";
|
|
import { IngestSendEvent } from "../events/ingestSendEvent.server";
|
|
import { env } from "~/env.server";
|
|
import { MISSING_CONNECTION_NOTIFICATION } from "@trigger.dev/core";
|
|
|
|
export class MissingConnectionCreatedService {
|
|
#prismaClient: PrismaClientOrTransaction;
|
|
|
|
constructor(prismaClient: PrismaClientOrTransaction = prisma) {
|
|
this.#prismaClient = prismaClient;
|
|
}
|
|
|
|
public async call(id: string) {
|
|
return await $transaction(this.#prismaClient, async (tx) => {
|
|
// first, deliver the event through the dispatcher
|
|
const missingConnection = await tx.missingConnection.findUniqueOrThrow({
|
|
where: {
|
|
id,
|
|
},
|
|
include: {
|
|
runs: {
|
|
include: {
|
|
environment: {
|
|
include: {
|
|
project: true,
|
|
organization: true,
|
|
},
|
|
},
|
|
},
|
|
take: 1,
|
|
orderBy: {
|
|
createdAt: "asc",
|
|
},
|
|
},
|
|
externalAccount: true,
|
|
integration: true,
|
|
},
|
|
});
|
|
|
|
if (missingConnection.resolved) {
|
|
return;
|
|
}
|
|
|
|
const firstRun = missingConnection.runs[0];
|
|
|
|
if (!firstRun) {
|
|
return;
|
|
}
|
|
|
|
const eventId = missingConnection.id;
|
|
|
|
const eventService = new IngestSendEvent(tx);
|
|
|
|
await eventService.call(firstRun.environment, {
|
|
id: eventId,
|
|
name: MISSING_CONNECTION_NOTIFICATION,
|
|
payload: {
|
|
id: missingConnection.id,
|
|
type: missingConnection.connectionType,
|
|
client: {
|
|
id: missingConnection.integration.slug,
|
|
title: missingConnection.integration.title,
|
|
scopes: missingConnection.integration.scopes,
|
|
createdAt: missingConnection.integration.createdAt,
|
|
updatedAt: missingConnection.integration.updatedAt,
|
|
},
|
|
authorizationUrl: `${env.APP_ORIGIN}/api/missing-connections/${missingConnection.id}/authorize`, // TODO: make this real
|
|
account: missingConnection.externalAccount
|
|
? {
|
|
id: missingConnection.externalAccount.identifier,
|
|
metadata: missingConnection.externalAccount.metadata,
|
|
}
|
|
: undefined,
|
|
},
|
|
context: {},
|
|
});
|
|
});
|
|
}
|
|
}
|