Feat/zapier app (#2623)

* create basic app structure

* add zapierSubscription model to prisma.schema

* change column name triggerEvent to lower case

* add zapier functionality + enpoints + adjust prisma.schema

* add subscriptionType + refactor code

* add app store information

* create setup page to generate api key

* clean code

* add copy functionality in setup page

* clean code

* add apiKeyType and delte key when uninstalled or new key generated

* clean code

* use Promise.all

* only approve zapier api key

* clean code

* fix findValidApiKey for api keys that don't expire

* fix migrations

* clean code

* small fixes

* add i18n

* add README.md file

* add setup guide to README.md

* fix yarn.lock

* Renames zapierother to zapier

* Typo

* Updates package name

* Rename fixes

* Adds zapier to the App Store seeder

* Adds missing zapier to apiHandlers

* Adds credential relationship to App

* Rename fixes

* Allows tailwind to pick up custom app-store components

* Consolidates zapier_setup_instructions

* Webhook fixes

* Uses app relationship instead of custom type

* Refactors sendPayload to accept webhook object

Instead of individual parameters

* refactoring

* Removes unused zapier check

* Update cancel.ts

* Refactoring

* Removes example comments

* Update InstallAppButton.tsx

* Type fixes

* E2E fixes

* Deletes all user zapier webhooks on integration removal

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: zomars <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-05-03 23:16:59 +00:00
1 parent ba283e3dc0
commit 02b935bcde
37 files changed
+660 -57

No files matched your search

@@ -11,16 +11,39 @@ export const apiKeysRouter = createProtectedRouter()
return await ctx.prisma.apiKey.findMany({
where: {
userId: ctx.user.id,
NOT: {
appId: "zapier",
},
},
orderBy: { createdAt: "desc" },
});
},
})
.query("findKeyOfType", {
input: z.object({
appId: z.string().optional().nullable(),
}),
async resolve({ ctx, input }) {
return await ctx.prisma.apiKey.findFirst({
where: {
AND: [
{
userId: ctx.user.id,
},
{
appId: input.appId,
},
],
},
});
},
})
.mutation("create", {
input: z.object({
note: z.string().optional().nullish(),
expiresAt: z.date().optional().nullable(),
neverExpires: z.boolean().optional(),
appId: z.string().optional().nullable(),
}),
async resolve({ ctx, input }) {
const [hashedApiKey, apiKey] = generateUniqueAPIKey();
+16 -11
View File
@@ -1,3 +1,4 @@
import { Prisma } from "@prisma/client";
import { v4 } from "uuid";
import { z } from "zod";
@@ -17,17 +18,18 @@ export const webhookRouter = createProtectedRouter()
})
.optional(),
async resolve({ ctx, input }) {
if (input?.eventTypeId) {
return await ctx.prisma.webhook.findMany({
where: {
eventTypeId: input.eventTypeId,
},
});
let where: Prisma.WebhookWhereInput = {
AND: [{ appId: null /* Don't mixup zapier webhooks with normal ones */ }],
};
if (Array.isArray(where.AND)) {
if (input?.eventTypeId) {
where.AND?.push({ eventTypeId: input.eventTypeId });
} else {
where.AND?.push({ userId: ctx.user.id });
}
}
return await ctx.prisma.webhook.findMany({
where: {
userId: ctx.user.id,
},
where,
});
},
})
@@ -38,6 +40,7 @@ export const webhookRouter = createProtectedRouter()
active: z.boolean(),
payloadTemplate: z.string().nullable(),
eventTypeId: z.number().optional(),
appId: z.string().optional().nullable(),
}),
async resolve({ ctx, input }) {
if (input.eventTypeId) {
@@ -65,6 +68,7 @@ export const webhookRouter = createProtectedRouter()
active: z.boolean().optional(),
payloadTemplate: z.string().nullable(),
eventTypeId: z.number().optional(),
appId: z.string().optional().nullable(),
}),
async resolve({ ctx, input }) {
const { id, ...data } = input;
@@ -139,7 +143,7 @@ export const webhookRouter = createProtectedRouter()
payloadTemplate: z.string().optional().nullable(),
}),
async resolve({ input }) {
const { url, type, payloadTemplate } = input;
const { url, type, payloadTemplate = null } = input;
const translation = await getTranslation("en", "common");
const language = {
locale: "en",
@@ -170,7 +174,8 @@ export const webhookRouter = createProtectedRouter()
};
try {
return await sendPayload(type, new Date().toISOString(), url, data, payloadTemplate);
const webhook = { subscriberUrl: url, payloadTemplate, appId: null };
return await sendPayload(type, new Date().toISOString(), webhook, data);
} catch (_err) {
const error = getErrorFromUnknown(_err);
return {