 02b935bcde
			
		
	
	
		02b935bcde
		
			
		
	
	
	
	
		
			
			* 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 <wollencarina@gmail.com> Co-authored-by: zomars <zomars@me.com>
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { NextApiRequest, NextApiResponse } from "next";
 | |
| import { v4 } from "uuid";
 | |
| 
 | |
| import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
 | |
| import prisma from "@calcom/prisma";
 | |
| 
 | |
| export default async function handler(req: NextApiRequest, res: NextApiResponse) {
 | |
|   const apiKey = req.query.apiKey as string;
 | |
| 
 | |
|   if (!apiKey) {
 | |
|     return res.status(401).json({ message: "No API key provided" });
 | |
|   }
 | |
| 
 | |
|   const validKey = await findValidApiKey(apiKey, "zapier");
 | |
| 
 | |
|   if (!validKey) {
 | |
|     return res.status(401).json({ message: "API key not valid" });
 | |
|   }
 | |
| 
 | |
|   const { subscriberUrl, triggerEvent } = req.body;
 | |
| 
 | |
|   if (req.method === "POST") {
 | |
|     try {
 | |
|       const createSubscription = await prisma.webhook.create({
 | |
|         data: {
 | |
|           id: v4(),
 | |
|           userId: validKey.userId,
 | |
|           eventTriggers: [triggerEvent],
 | |
|           subscriberUrl,
 | |
|           active: true,
 | |
|           appId: "zapier",
 | |
|         },
 | |
|       });
 | |
|       res.status(200).json(createSubscription);
 | |
|     } catch (error) {
 | |
|       return res.status(500).json({ message: "Could not create subscription." });
 | |
|     }
 | |
|   }
 | |
| }
 |