From 0eb167112fbff75bbae97efa4038e5b651074bac Mon Sep 17 00:00:00 2001 From: Vishek Tyagi Date: Mon, 10 Aug 2026 12:51:53 +0530 Subject: [PATCH] feat: add Adrapid plugin --- demo/mcp/corsair.ts | 1 - packages/adrapid/client.ts | 60 +++++ packages/adrapid/endpoints/example.ts | 18 ++ packages/adrapid/endpoints/index.ts | 7 + packages/adrapid/endpoints/types.ts | 29 +++ packages/adrapid/error-handlers.ts | 31 +++ packages/adrapid/index.ts | 206 ++++++++++++++++++ packages/adrapid/jest.config.cjs | 55 +++++ packages/adrapid/package.json | 44 ++++ packages/adrapid/schema.test.ts | 20 ++ packages/adrapid/schema/database.ts | 7 + packages/adrapid/schema/index.ts | 4 + packages/adrapid/tsconfig.json | 20 ++ packages/adrapid/tsup.config.ts | 15 ++ packages/adrapid/webhooks/example.ts | 32 +++ packages/adrapid/webhooks/index.ts | 9 + .../adrapid/webhooks/oauth-tenant-link.ts | 31 +++ packages/adrapid/webhooks/tenant-matcher.ts | 25 +++ packages/adrapid/webhooks/types.ts | 62 ++++++ packages/corsair/core/constants.ts | 6 + packages/youcom/jest.config.cjs | 2 + pnpm-lock.yaml | 143 ++++++------ www/src/components/landing/menu/site-menu.tsx | 2 +- 23 files changed, 757 insertions(+), 72 deletions(-) create mode 100644 packages/adrapid/client.ts create mode 100644 packages/adrapid/endpoints/example.ts create mode 100644 packages/adrapid/endpoints/index.ts create mode 100644 packages/adrapid/endpoints/types.ts create mode 100644 packages/adrapid/error-handlers.ts create mode 100644 packages/adrapid/index.ts create mode 100644 packages/adrapid/jest.config.cjs create mode 100644 packages/adrapid/package.json create mode 100644 packages/adrapid/schema.test.ts create mode 100644 packages/adrapid/schema/database.ts create mode 100644 packages/adrapid/schema/index.ts create mode 100644 packages/adrapid/tsconfig.json create mode 100644 packages/adrapid/tsup.config.ts create mode 100644 packages/adrapid/webhooks/example.ts create mode 100644 packages/adrapid/webhooks/index.ts create mode 100644 packages/adrapid/webhooks/oauth-tenant-link.ts create mode 100644 packages/adrapid/webhooks/tenant-matcher.ts create mode 100644 packages/adrapid/webhooks/types.ts diff --git a/demo/mcp/corsair.ts b/demo/mcp/corsair.ts index 25a1e2cfb..066808855 100644 --- a/demo/mcp/corsair.ts +++ b/demo/mcp/corsair.ts @@ -1,6 +1,5 @@ import 'dotenv/config'; import { github } from '@corsair-dev/github'; -import { gmail } from '@corsair-dev/gmail'; import { linear } from '@corsair-dev/linear'; // import { googlecalendar } from '@corsair-dev/googlecalendar' import { slack } from '@corsair-dev/slack'; diff --git a/packages/adrapid/client.ts b/packages/adrapid/client.ts new file mode 100644 index 000000000..1155b1a29 --- /dev/null +++ b/packages/adrapid/client.ts @@ -0,0 +1,60 @@ +import type { ApiRequestOptions, OpenAPIConfig } from 'corsair/http'; +import { request } from 'corsair/http'; + +export class AdrapidAPIError extends Error { + constructor( + message: string, + public readonly code?: string, + ) { + super(message); + this.name = 'AdrapidAPIError'; + } +} + +// TODO: Update with your API base URL +const ADRAPID_API_BASE = 'https://api.example.com'; + +export async function makeAdrapidRequest( + endpoint: string, + apiKey: string, + options: { + method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; + body?: Record; + query?: Record; + } = {}, +): Promise { + const { method = 'GET', body, query } = options; + + const config: OpenAPIConfig = { + BASE: ADRAPID_API_BASE, + VERSION: '1.0.0', + WITH_CREDENTIALS: false, + CREDENTIALS: 'omit', + TOKEN: apiKey, + HEADERS: { + 'Content-Type': 'application/json', + // TODO: Add authentication headers + // 'Authorization': \`Bearer \${apiKey}\` + }, + }; + + const requestOptions: ApiRequestOptions = { + method, + url: endpoint, + body: + method === 'POST' || method === 'PUT' || method === 'PATCH' + ? body + : undefined, + mediaType: 'application/json; charset=utf-8', + query: method === 'GET' ? query : undefined, + }; + + try { + return await request(config, requestOptions); + } catch (error) { + if (error instanceof Error) { + throw new AdrapidAPIError(error.message); + } + throw new AdrapidAPIError('Unknown error'); + } +} diff --git a/packages/adrapid/endpoints/example.ts b/packages/adrapid/endpoints/example.ts new file mode 100644 index 000000000..d2d8edd29 --- /dev/null +++ b/packages/adrapid/endpoints/example.ts @@ -0,0 +1,18 @@ +import { logEventFromContext } from 'corsair/core'; +import type { AdrapidEndpoints } from '..'; +import { makeAdrapidRequest } from '../client'; +import type { AdrapidEndpointOutputs } from './types'; + +export const get: AdrapidEndpoints['exampleGet'] = async (ctx, input) => { + const response = await makeAdrapidRequest< + AdrapidEndpointOutputs['exampleGet'] + >(`example/${input.id}`, ctx.key, { method: 'GET' }); + + await logEventFromContext( + ctx, + 'adrapid.example.get', + { ...input }, + 'completed', + ); + return response; +}; diff --git a/packages/adrapid/endpoints/index.ts b/packages/adrapid/endpoints/index.ts new file mode 100644 index 000000000..7dc74ef41 --- /dev/null +++ b/packages/adrapid/endpoints/index.ts @@ -0,0 +1,7 @@ +import { get as exampleGet } from './example'; + +export const Example = { + get: exampleGet, +}; + +export * from './types'; diff --git a/packages/adrapid/endpoints/types.ts b/packages/adrapid/endpoints/types.ts new file mode 100644 index 000000000..3909baaff --- /dev/null +++ b/packages/adrapid/endpoints/types.ts @@ -0,0 +1,29 @@ +import { z } from 'zod'; + +const ExampleGetInputSchema = z.object({ + id: z.string(), +}); + +export type ExampleGetInput = z.infer; + +const ExampleGetResponseSchema = z.object({ + id: z.string(), +}); + +export type ExampleGetResponse = z.infer; + +export type AdrapidEndpointInputs = { + exampleGet: ExampleGetInput; +}; + +export type AdrapidEndpointOutputs = { + exampleGet: ExampleGetResponse; +}; + +export const AdrapidEndpointInputSchemas = { + exampleGet: ExampleGetInputSchema, +} as const; + +export const AdrapidEndpointOutputSchemas = { + exampleGet: ExampleGetResponseSchema, +} as const; diff --git a/packages/adrapid/error-handlers.ts b/packages/adrapid/error-handlers.ts new file mode 100644 index 000000000..5a4f4c19f --- /dev/null +++ b/packages/adrapid/error-handlers.ts @@ -0,0 +1,31 @@ +import type { CorsairErrorHandler } from 'corsair/core'; +import { ApiError } from 'corsair/http'; + +export const errorHandlers = { + RATE_LIMIT_ERROR: { + match: (error: Error) => { + if (error instanceof ApiError && error.status === 429) return true; + const msg = error.message.toLowerCase(); + return msg.includes('rate_limited') || msg.includes('429'); + }, + handler: async (error: Error) => { + let retryAfterMs: number | undefined; + if (error instanceof ApiError && error.retryAfter !== undefined) { + retryAfterMs = error.retryAfter; + } + return { maxRetries: 5, headersRetryAfterMs: retryAfterMs }; + }, + }, + AUTH_ERROR: { + match: (error: Error) => { + if (error instanceof ApiError && error.status === 401) return true; + const msg = error.message.toLowerCase(); + return msg.includes('unauthorized') || msg.includes('invalid_auth'); + }, + handler: async () => ({ maxRetries: 0 }), + }, + DEFAULT: { + match: () => true, + handler: async () => ({ maxRetries: 0 }), + }, +} satisfies CorsairErrorHandler; diff --git a/packages/adrapid/index.ts b/packages/adrapid/index.ts new file mode 100644 index 000000000..e43d4e31f --- /dev/null +++ b/packages/adrapid/index.ts @@ -0,0 +1,206 @@ +import type { + AuthTypes, + BindEndpoints, + BindWebhooks, + CorsairEndpoint, + CorsairErrorHandler, + CorsairPlugin, + CorsairPluginContext, + CorsairWebhook, + KeyBuilderContext, + PickAuth, + PluginAuthConfig, + PluginPermissionsConfig, + RequiredPluginEndpointMeta, + RequiredPluginEndpointSchemas, + RequiredPluginWebhookSchemas, +} from 'corsair/core'; +import { Example } from './endpoints'; +import type { + AdrapidEndpointInputs, + AdrapidEndpointOutputs, +} from './endpoints/types'; +import { + AdrapidEndpointInputSchemas, + AdrapidEndpointOutputSchemas, +} from './endpoints/types'; +import { errorHandlers } from './error-handlers'; +import { AdrapidSchema } from './schema'; +import { ExampleWebhooks } from './webhooks'; +import { resolveAdrapidOAuthWebhookTenantLink } from './webhooks/oauth-tenant-link'; +import { matchAdrapidTenantWebhook } from './webhooks/tenant-matcher'; +import type { AdrapidWebhookOutputs, ExampleEvent } from './webhooks/types'; +import { ExampleEventSchema } from './webhooks/types'; + +export type AdrapidPluginOptions = { + authType?: PickAuth<'api_key' | 'oauth_2'>; + key?: string; + webhookSecret?: string; + hooks?: InternalAdrapidPlugin['hooks']; + webhookHooks?: InternalAdrapidPlugin['webhookHooks']; + errorHandlers?: CorsairErrorHandler; + permissions?: PluginPermissionsConfig; +}; + +export type AdrapidContext = CorsairPluginContext< + typeof AdrapidSchema, + AdrapidPluginOptions +>; + +export type AdrapidKeyBuilderContext = KeyBuilderContext; + +export type AdrapidBoundEndpoints = BindEndpoints< + typeof adrapidEndpointsNested +>; + +type AdrapidEndpoint = CorsairEndpoint< + AdrapidContext, + AdrapidEndpointInputs[K], + AdrapidEndpointOutputs[K] +>; + +export type AdrapidEndpoints = { + exampleGet: AdrapidEndpoint<'exampleGet'>; +}; + +type AdrapidWebhook< + K extends keyof AdrapidWebhookOutputs, + TEvent, +> = CorsairWebhook; + +export type AdrapidWebhooks = { + example: AdrapidWebhook<'example', ExampleEvent>; +}; + +export type AdrapidBoundWebhooks = BindWebhooks; + +const adrapidEndpointsNested = { + example: { + get: Example.get, + }, +} as const; + +const adrapidWebhooksNested = { + example: { + example: ExampleWebhooks.example, + }, +} as const; + +export const adrapidEndpointSchemas = { + 'example.get': { + input: AdrapidEndpointInputSchemas.exampleGet, + output: AdrapidEndpointOutputSchemas.exampleGet, + }, +} as const satisfies RequiredPluginEndpointSchemas< + typeof adrapidEndpointsNested +>; + +const adrapidWebhookSchemas = { + 'example.example': { + description: 'An example webhook event', + payload: ExampleEventSchema, + response: ExampleEventSchema, + }, +} as const satisfies RequiredPluginWebhookSchemas; + +const defaultAuthType: AuthTypes = 'api_key' as const; + +const adrapidEndpointMeta = { + 'example.get': { + riskLevel: 'read', + description: 'Get an example resource by ID', + }, +} as const satisfies RequiredPluginEndpointMeta; + +export const adrapidAuthConfig = { + api_key: { + account: ['tenant_external_id'] as const, + }, + oauth_2: { + account: ['tenant_external_id'] as const, + }, +} as const satisfies PluginAuthConfig; + +export type BaseAdrapidPlugin = CorsairPlugin< + 'adrapid', + typeof AdrapidSchema, + typeof adrapidEndpointsNested, + typeof adrapidWebhooksNested, + T, + typeof defaultAuthType +>; + +export type InternalAdrapidPlugin = BaseAdrapidPlugin; + +export type ExternalAdrapidPlugin = + BaseAdrapidPlugin; + +export function adrapid( + incomingOptions: AdrapidPluginOptions & T = {} as AdrapidPluginOptions & T, +): ExternalAdrapidPlugin { + const options = { + ...incomingOptions, + authType: incomingOptions.authType ?? defaultAuthType, + }; + return { + id: 'adrapid', + authConfig: adrapidAuthConfig, + schema: AdrapidSchema, + options: options, + hooks: options.hooks, + webhookHooks: options.webhookHooks, + endpoints: adrapidEndpointsNested, + webhooks: adrapidWebhooksNested, + endpointMeta: adrapidEndpointMeta, + endpointSchemas: adrapidEndpointSchemas, + webhookSchemas: adrapidWebhookSchemas, + pluginWebhookMatcher: (request) => { + const headers = request.headers; + // TODO: Update to match your webhook signature headers + return 'x-adrapid-signature' in headers; + }, + pluginTenantWebhookMatcher: matchAdrapidTenantWebhook, + oauthWebhookTenantLinkResolver: resolveAdrapidOAuthWebhookTenantLink, + errorHandlers: { + ...errorHandlers, + ...options.errorHandlers, + }, + keyBuilder: async (ctx: AdrapidKeyBuilderContext, source) => { + if (source === 'webhook' && options.webhookSecret) { + return options.webhookSecret; + } + + if (source === 'webhook') { + const res = await ctx.keys.get_webhook_signature(); + return res ?? ''; + } + + if (source === 'endpoint' && options.key) { + return options.key; + } + + if (source === 'endpoint' && ctx.authType === 'api_key') { + const res = await ctx.keys.get_api_key(); + return res ?? ''; + } + + if (source === 'endpoint' && ctx.authType === 'oauth_2') { + const res = await ctx.keys.get_access_token(); + return res ?? ''; + } + + return ''; + }, + } satisfies InternalAdrapidPlugin; +} + +export type { + AdrapidEndpointInputs, + AdrapidEndpointOutputs, + ExampleGetInput, + ExampleGetResponse, +} from './endpoints/types'; +export type { + AdrapidWebhookOutputs, + ExampleEvent, +} from './webhooks/types'; diff --git a/packages/adrapid/jest.config.cjs b/packages/adrapid/jest.config.cjs new file mode 100644 index 000000000..8c6218f64 --- /dev/null +++ b/packages/adrapid/jest.config.cjs @@ -0,0 +1,55 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + roots: [''], + testMatch: [ + '**/*.test.ts', + '**/tests/**/*.test.ts', + '**/plugins/**/*.test.ts', + '**/setup/**/*.test.ts', + ], + collectCoverageFrom: [ + '**/*.ts', + '!**/*.d.ts', + '!**/node_modules/**', + '!**/dist/**', + '!jest.config.ts', + '!tests/**', + ], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], + transform: { + '^.+\\.yaml$': '/../corsair/jest-yaml-transform.cjs', + '^.+\\.ts$': [ + 'ts-jest', + { + useESM: true, + tsconfig: { + esModuleInterop: true, + allowSyntheticDefaultImports: true, + verbatimModuleSyntax: false, + module: 'ESNext', + moduleResolution: 'Bundler', + }, + }, + ], + '.*\\.js$': [ + 'ts-jest', + { + useESM: true, + tsconfig: { + esModuleInterop: true, + allowSyntheticDefaultImports: true, + }, + }, + ], + }, + moduleNameMapper: { + '^corsair/core$': '/../corsair/core.ts', + '^corsair/http$': '/../corsair/http.ts', + '^(\\.\\.?/.*)\\.js$': '$1', + }, + transformIgnorePatterns: ['node_modules/(?!.*uuid.*)'], + extensionsToTreatAsEsm: ['.ts'], + testTimeout: 30000, + verbose: true, +}; diff --git a/packages/adrapid/package.json b/packages/adrapid/package.json new file mode 100644 index 000000000..85c6411a5 --- /dev/null +++ b/packages/adrapid/package.json @@ -0,0 +1,44 @@ +{ + "name": "@corsair-dev/adrapid", + "version": "0.1.0", + "description": "Adrapid plugin for Corsair", + "type": "module", + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "dev-source": "./index.ts", + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "scripts": { + "build": "rm -rf dist && tsc --build --force && tsup", + "typecheck": "tsc --noEmit", + "test": "jest" + }, + "peerDependencies": { + "corsair": ">=0.1.0", + "zod": "^4.1.13" + }, + "devDependencies": { + "@types/jest": "^29.5.14", + "corsair": "workspace:*", + "jest": "^29.7.0", + "ts-jest": "^29.4.9", + "tsup": "^8.0.1", + "typescript": "catalog:", + "zod": "^4.1.13" + }, + "keywords": [ + "corsair", + "adrapid", + "plugin" + ], + "author": "", + "license": "Apache-2.0", + "files": [ + "dist" + ] +} diff --git a/packages/adrapid/schema.test.ts b/packages/adrapid/schema.test.ts new file mode 100644 index 000000000..952bed81c --- /dev/null +++ b/packages/adrapid/schema.test.ts @@ -0,0 +1,20 @@ +import { AdrapidSchema } from './schema'; + +describe('Adrapid schema', () => { + it('declares a semver version', () => { + expect(AdrapidSchema.version).toBeDefined(); + expect(AdrapidSchema.version).toMatch(/^\d+\.\d+\.\d+$/); + }); + + it('declares an entities map', () => { + expect(typeof AdrapidSchema.entities).toBe('object'); + expect(AdrapidSchema.entities).not.toBeNull(); + expect(Array.isArray(Object.keys(AdrapidSchema.entities))).toBe(true); + for (const entity of Object.values(AdrapidSchema.entities)) { + expect(entity).toBeDefined(); + } + }); +}); + +// Per .github/PLUGIN_PR_RULES.md (R2), every implemented endpoint +// needs a corresponding test. diff --git a/packages/adrapid/schema/database.ts b/packages/adrapid/schema/database.ts new file mode 100644 index 000000000..6fa5e8b65 --- /dev/null +++ b/packages/adrapid/schema/database.ts @@ -0,0 +1,7 @@ +// TODO: Define your database entities here +// export const AdrapidExample = z.object({ +// id: z.string(), +// name: z.string(), +// created_at: z.coerce.date().nullable().optional(), +// }); +// export type AdrapidExample = z.infer; diff --git a/packages/adrapid/schema/index.ts b/packages/adrapid/schema/index.ts new file mode 100644 index 000000000..9ff7db96e --- /dev/null +++ b/packages/adrapid/schema/index.ts @@ -0,0 +1,4 @@ +export const AdrapidSchema = { + version: '1.0.0', + entities: {}, +} as const; diff --git a/packages/adrapid/tsconfig.json b/packages/adrapid/tsconfig.json new file mode 100644 index 000000000..15e507a13 --- /dev/null +++ b/packages/adrapid/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "lib": ["esnext"], + "types": ["node", "jest"], + "module": "ESNext", + "moduleResolution": "Bundler", + "outDir": "./dist", + "rootDir": "./", + "composite": true, + "incremental": true, + "emitDeclarationOnly": true, + "declaration": true, + "declarationMap": true, + "skipLibCheck": true + }, + "include": ["./**/*"], + "exclude": ["dist", "node_modules"], + "references": [] +} diff --git a/packages/adrapid/tsup.config.ts b/packages/adrapid/tsup.config.ts new file mode 100644 index 000000000..3ec221e23 --- /dev/null +++ b/packages/adrapid/tsup.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig({ + clean: false, + dts: false, + format: ['esm'], + target: 'esnext', + platform: 'node', + bundle: true, + splitting: true, + minify: true, + outDir: 'dist', + external: ['corsair', 'zod'], + entry: ['index.ts'], +}); diff --git a/packages/adrapid/webhooks/example.ts b/packages/adrapid/webhooks/example.ts new file mode 100644 index 000000000..27e1c8d4d --- /dev/null +++ b/packages/adrapid/webhooks/example.ts @@ -0,0 +1,32 @@ +import { logEventFromContext } from 'corsair/core'; +import type { AdrapidWebhooks } from '..'; +import { createAdrapidMatch, verifyAdrapidWebhookSignature } from './types'; + +export const example: AdrapidWebhooks['example'] = { + match: createAdrapidMatch('example'), + + handler: async (ctx, request) => { + const verification = verifyAdrapidWebhookSignature(request, ctx.key); + if (!verification.valid) { + return { + success: false, + statusCode: 401, + error: verification.error || 'Signature verification failed', + }; + } + + const event = request.payload; + if (event.type !== 'example') { + return { success: true, data: undefined }; + } + + await logEventFromContext( + ctx, + 'adrapid.webhook.example', + { ...event }, + 'completed', + ); + + return { success: true, data: event }; + }, +}; diff --git a/packages/adrapid/webhooks/index.ts b/packages/adrapid/webhooks/index.ts new file mode 100644 index 000000000..a12134e8a --- /dev/null +++ b/packages/adrapid/webhooks/index.ts @@ -0,0 +1,9 @@ +import { example } from './example'; + +export const ExampleWebhooks = { + example: example, +}; + +export * from './oauth-tenant-link'; +export * from './tenant-matcher'; +export * from './types'; diff --git a/packages/adrapid/webhooks/oauth-tenant-link.ts b/packages/adrapid/webhooks/oauth-tenant-link.ts new file mode 100644 index 000000000..1b9a8853e --- /dev/null +++ b/packages/adrapid/webhooks/oauth-tenant-link.ts @@ -0,0 +1,31 @@ +import type { TokenResponse, WebhookTenantMatch } from 'corsair/core'; +import { toExternalId } from 'corsair/core'; + +// TODO: Rename linkType 'tenant_external_id' to match pluginTenantWebhookMatcher. +// Called after OAuth to store the routing id on corsair_accounts.config. +export async function resolveAdrapidOAuthWebhookTenantLink( + tokens: TokenResponse, +): Promise { + // TODO: Read from token response when the provider includes a stable id. + // const externalId = toExternalId(asRecord(tokens.team)?.id); + const externalId = toExternalId(tokens.tenant_external_id); + if (externalId) { + return { linkType: 'tenant_external_id', externalId }; + } + + const accessToken = tokens.access_token; + if (!accessToken) return null; + + // TODO: Fetch from provider API when the token response omits the id. + // const response = await fetch('https://api.example.com/me', { + // headers: { Authorization: `Bearer ${accessToken}` }, + // }); + // if (!response.ok) return null; + // const payload = (await response.json()) as { id?: string }; + // const fetchedId = toExternalId(payload.id); + // return fetchedId + // ? { linkType: 'tenant_external_id', externalId: fetchedId } + // : null; + + return null; +} diff --git a/packages/adrapid/webhooks/tenant-matcher.ts b/packages/adrapid/webhooks/tenant-matcher.ts new file mode 100644 index 000000000..5b8a83341 --- /dev/null +++ b/packages/adrapid/webhooks/tenant-matcher.ts @@ -0,0 +1,25 @@ +import type { RawWebhookRequest, WebhookTenantMatch } from 'corsair/core'; +import { asRecord, firstString, readBodyRecord } from 'corsair/core'; + +// TODO: Rename linkType 'tenant_external_id' to match the provider field +// (e.g. team_id, installation_id, organization_id). Must match authConfig.account +// and oauthWebhookTenantLinkResolver. +// Return null for URL verification / handshake payloads that have no tenant id. +export function matchAdrapidTenantWebhook( + request: RawWebhookRequest, +): WebhookTenantMatch | null { + const body = readBodyRecord(request); + if (!body) return null; + + // TODO: Extract the stable external id from the webhook payload. + // Example: + // const externalId = firstString([body.tenant_external_id, asRecord(body.data)?.id]); + const externalId = firstString([ + body.tenant_external_id, + asRecord(body.data)?.tenant_external_id, + ]); + + if (!externalId) return null; + + return { linkType: 'tenant_external_id', externalId }; +} diff --git a/packages/adrapid/webhooks/types.ts b/packages/adrapid/webhooks/types.ts new file mode 100644 index 000000000..9a69b332f --- /dev/null +++ b/packages/adrapid/webhooks/types.ts @@ -0,0 +1,62 @@ +import type { + CorsairWebhookMatcher, + RawWebhookRequest, + WebhookRequest, +} from 'corsair/core'; +import { z } from 'zod'; + +export const AdrapidWebhookPayloadSchema = z.object({ + type: z.string(), + created_at: z.string(), + data: z.record(z.string(), z.unknown()), +}); + +export type AdrapidWebhookPayload = z.infer; + +export const ExampleEventSchema = AdrapidWebhookPayloadSchema.extend({ + type: z.literal('example'), + data: z + .object({ + id: z.string(), + }) + .loose(), +}); + +export type ExampleEvent = z.infer; + +export type AdrapidWebhookOutputs = { + example: ExampleEvent; +}; + +function parseBody(body: unknown): Record | null { + if (typeof body === 'string') { + try { + const parsed = JSON.parse(body); + return parsed !== null && + typeof parsed === 'object' && + !Array.isArray(parsed) + ? (parsed as Record) + : null; + } catch { + return null; + } + } + return body !== null && typeof body === 'object' && !Array.isArray(body) + ? (body as Record) + : null; +} + +export function createAdrapidMatch(eventType: string): CorsairWebhookMatcher { + return (request: RawWebhookRequest) => { + const parsedBody = parseBody(request.body); + return parsedBody !== null && parsedBody.type === eventType; + }; +} + +export function verifyAdrapidWebhookSignature( + request: WebhookRequest, + secret: string, +): { valid: boolean; error?: string } { + // TODO: Implement webhook signature verification + return { valid: true }; +} diff --git a/packages/corsair/core/constants.ts b/packages/corsair/core/constants.ts index e33ec2ca8..1098dd310 100644 --- a/packages/corsair/core/constants.ts +++ b/packages/corsair/core/constants.ts @@ -16,6 +16,7 @@ export const BaseProviders = [ 'abstract', 'activetrail', 'addresszen', + 'adrapid', 'agencyzoom', 'agentmail', 'agentql', @@ -110,6 +111,7 @@ export const BaseProviders = [ 'whatsapp', 'wiza', 'xquik', + 'youcom', 'youtube', 'zendesk', 'zohomail', @@ -120,6 +122,7 @@ export const ProviderDisplayNames = { abstract: 'Abstract', activetrail: 'Active Trail', addresszen: 'Addresszen', + adrapid: 'Adrapid', agencyzoom: 'AgencyZoom', agentmail: 'AgentMail', agentql: 'AgentQL', @@ -214,6 +217,7 @@ export const ProviderDisplayNames = { whatsapp: 'WhatsApp', wiza: 'Wiza', xquik: 'XQuik', + youcom: 'You.com', youtube: 'YouTube', zendesk: 'Zendesk', zohomail: 'Zoho Mail', @@ -231,6 +235,7 @@ export type AllProviders = | 'abstract' | 'activetrail' | 'addresszen' + | 'adrapid' | 'agencyzoom' | 'agentmail' | 'agentql' @@ -325,6 +330,7 @@ export type AllProviders = | 'whatsapp' | 'wiza' | 'xquik' + | 'youcom' | 'youtube' | 'zendesk' | 'zohomail' diff --git a/packages/youcom/jest.config.cjs b/packages/youcom/jest.config.cjs index 296a927ca..82dec3165 100644 --- a/packages/youcom/jest.config.cjs +++ b/packages/youcom/jest.config.cjs @@ -44,6 +44,8 @@ module.exports = { ], }, moduleNameMapper: { + '^corsair/core$': '/../corsair/core.ts', + '^corsair/hub$': '/../corsair/hub.ts', '^corsair/http$': '/../corsair/http.ts', '^(\\.\\.?/.*)\\.js$': '$1', }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91d5ded73..ea5da1470 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -374,6 +374,30 @@ importers: specifier: 4.4.3 version: 4.4.3 + packages/adrapid: + devDependencies: + '@types/jest': + specifier: ^29.5.14 + version: 29.5.14 + corsair: + specifier: workspace:* + version: link:../corsair + jest: + specifier: ^29.7.0 + version: 29.7.0(@types/node@24.10.1)(ts-node@10.9.2(@types/node@24.10.1)(typescript@5.9.3)) + ts-jest: + specifier: ^29.4.9 + version: 29.4.9(@babel/core@7.29.7)(@jest/transform@29.7.0)(@jest/types@30.4.1)(babel-jest@29.7.0(@babel/core@7.29.7))(esbuild@0.27.0)(jest-util@30.4.1)(jest@29.7.0(@types/node@24.10.1)(ts-node@10.9.2(@types/node@24.10.1)(typescript@5.9.3)))(typescript@5.9.3) + tsup: + specifier: ^8.0.1 + version: 8.5.1(jiti@2.7.0)(postcss@8.5.15)(tsx@4.22.4)(typescript@5.9.3)(yaml@2.9.0) + typescript: + specifier: 'catalog:' + version: 5.9.3 + zod: + specifier: 4.4.3 + version: 4.4.3 + packages/agencyzoom: devDependencies: '@types/jest': @@ -3467,10 +3491,6 @@ packages: resolution: {integrity: sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==} engines: {node: '>=6.9.0'} - '@babel/compat-data@7.28.6': - resolution: {integrity: sha512-2lfu57JtzctfIrcGMz992hyLlByuzgIk58+hhGCxjKZ3rWI82NnVLjXcaTqkI2NvlcvOskZaiZ5kjUALo3Lpxg==} - engines: {node: '>=6.9.0'} - '@babel/compat-data@7.29.7': resolution: {integrity: sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg==} engines: {node: '>=6.9.0'} @@ -3530,10 +3550,6 @@ packages: peerDependencies: '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 - '@babel/helper-globals@7.28.0': - resolution: {integrity: sha512-+W6cISkXFa1jXsDEdYA8HeevQT/FULhxzR99pxphltZcVaugps53THCeiWA8SguxxpSp3gKPiuYfSWopkLQ4hw==} - engines: {node: '>=6.9.0'} - '@babel/helper-globals@7.29.7': resolution: {integrity: sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==} engines: {node: '>=6.9.0'} @@ -3608,18 +3624,10 @@ packages: resolution: {integrity: sha512-brcMGQaVzIeUb+6/bs1Av0f8YuNNjKY2JyvfRCsFuFsdKccEQ5Ges2y74D74NZ1Rz8lKJ9ksJkfqwQFJ/iNEyQ==} engines: {node: '>=6.9.0'} - '@babel/helper-string-parser@7.27.1': - resolution: {integrity: sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==} - engines: {node: '>=6.9.0'} - '@babel/helper-string-parser@7.29.7': resolution: {integrity: sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==} engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.28.5': - resolution: {integrity: sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==} - engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.29.7': resolution: {integrity: sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==} engines: {node: '>=6.9.0'} @@ -3798,12 +3806,6 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 - '@babel/plugin-syntax-typescript@7.28.6': - resolution: {integrity: sha512-+nDNmQye7nlnuuHDboPbGm00Vqg3oO8niRRL27/4LYHUsHYh0zJ1xWOz0uRwNFmM1Avzk8wZbc6rdiYhomzv/A==} - engines: {node: '>=6.9.0'} - peerDependencies: - '@babel/core': ^7.0.0-0 - '@babel/plugin-syntax-typescript@7.29.7': resolution: {integrity: sha512-ngr+82Sh0xMz25TPCZi+nC2iTzjfCdWS2ONXTp/PtSCHCgaCNBpdMqgvJ2ccdLlClVZ7sisIgB914j/JFe+RZA==} engines: {node: '>=6.9.0'} @@ -14536,7 +14538,7 @@ snapshots: '@babel/code-frame@7.28.6': dependencies: - '@babel/helper-validator-identifier': 7.28.5 + '@babel/helper-validator-identifier': 7.29.7 js-tokens: 4.0.0 picocolors: 1.1.1 @@ -14546,8 +14548,6 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.1.1 - '@babel/compat-data@7.28.6': {} - '@babel/compat-data@7.29.7': {} '@babel/core@7.28.6': @@ -14592,8 +14592,8 @@ snapshots: '@babel/generator@7.28.6': dependencies: - '@babel/parser': 7.29.2 - '@babel/types': 7.28.6 + '@babel/parser': 7.29.7 + '@babel/types': 7.29.7 '@jridgewell/gen-mapping': 0.3.13 '@jridgewell/trace-mapping': 0.3.31 jsesc: 3.1.0 @@ -14616,8 +14616,8 @@ snapshots: '@babel/helper-compilation-targets@7.28.6': dependencies: - '@babel/compat-data': 7.28.6 - '@babel/helper-validator-option': 7.27.1 + '@babel/compat-data': 7.29.7 + '@babel/helper-validator-option': 7.29.7 browserslist: 4.28.1 lru-cache: 5.1.1 semver: 6.3.1 @@ -14638,7 +14638,7 @@ snapshots: '@babel/helper-optimise-call-expression': 7.27.1 '@babel/helper-replace-supers': 7.28.6(@babel/core@7.28.6) '@babel/helper-skip-transparent-expression-wrappers': 7.27.1 - '@babel/traverse': 7.28.6 + '@babel/traverse': 7.29.7 semver: 6.3.1 transitivePeerDependencies: - supports-color @@ -14674,8 +14674,6 @@ snapshots: transitivePeerDependencies: - supports-color - '@babel/helper-globals@7.28.0': {} - '@babel/helper-globals@7.29.7': {} '@babel/helper-member-expression-to-functions@7.28.5': @@ -14709,9 +14707,18 @@ snapshots: '@babel/helper-module-transforms@7.28.6(@babel/core@7.28.6)': dependencies: '@babel/core': 7.28.6 - '@babel/helper-module-imports': 7.28.6 - '@babel/helper-validator-identifier': 7.28.5 - '@babel/traverse': 7.28.6 + '@babel/helper-module-imports': 7.29.7 + '@babel/helper-validator-identifier': 7.29.7 + '@babel/traverse': 7.29.7 + transitivePeerDependencies: + - supports-color + + '@babel/helper-module-transforms@7.29.7(@babel/core@7.28.6)': + dependencies: + '@babel/core': 7.28.6 + '@babel/helper-module-imports': 7.29.7 + '@babel/helper-validator-identifier': 7.29.7 + '@babel/traverse': 7.29.7 transitivePeerDependencies: - supports-color @@ -14765,8 +14772,8 @@ snapshots: '@babel/helper-skip-transparent-expression-wrappers@7.27.1': dependencies: - '@babel/traverse': 7.28.6 - '@babel/types': 7.29.0 + '@babel/traverse': 7.29.7 + '@babel/types': 7.29.7 transitivePeerDependencies: - supports-color @@ -14777,12 +14784,8 @@ snapshots: transitivePeerDependencies: - supports-color - '@babel/helper-string-parser@7.27.1': {} - '@babel/helper-string-parser@7.29.7': {} - '@babel/helper-validator-identifier@7.28.5': {} - '@babel/helper-validator-identifier@7.29.7': {} '@babel/helper-validator-option@7.27.1': {} @@ -14799,8 +14802,8 @@ snapshots: '@babel/helpers@7.28.6': dependencies: - '@babel/template': 7.28.6 - '@babel/types': 7.28.6 + '@babel/template': 7.29.7 + '@babel/types': 7.29.7 '@babel/helpers@7.29.7': dependencies: @@ -14809,11 +14812,11 @@ snapshots: '@babel/parser@7.28.6': dependencies: - '@babel/types': 7.28.6 + '@babel/types': 7.29.7 '@babel/parser@7.29.2': dependencies: - '@babel/types': 7.29.0 + '@babel/types': 7.29.7 '@babel/parser@7.29.7': dependencies: @@ -14951,7 +14954,7 @@ snapshots: '@babel/plugin-syntax-jsx@7.28.6(@babel/core@7.28.6)': dependencies: '@babel/core': 7.28.6 - '@babel/helper-plugin-utils': 7.28.6 + '@babel/helper-plugin-utils': 7.29.7 '@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7)': dependencies: @@ -15046,10 +15049,10 @@ snapshots: '@babel/core': 7.29.7 '@babel/helper-plugin-utils': 7.29.7 - '@babel/plugin-syntax-typescript@7.28.6(@babel/core@7.28.6)': + '@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.28.6)': dependencies: '@babel/core': 7.28.6 - '@babel/helper-plugin-utils': 7.28.6 + '@babel/helper-plugin-utils': 7.29.7 '@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7)': dependencies: @@ -15225,8 +15228,8 @@ snapshots: '@babel/plugin-transform-modules-commonjs@7.28.6(@babel/core@7.28.6)': dependencies: '@babel/core': 7.28.6 - '@babel/helper-module-transforms': 7.28.6(@babel/core@7.28.6) - '@babel/helper-plugin-utils': 7.28.6 + '@babel/helper-module-transforms': 7.29.7(@babel/core@7.28.6) + '@babel/helper-plugin-utils': 7.29.7 transitivePeerDependencies: - supports-color @@ -15463,9 +15466,9 @@ snapshots: '@babel/core': 7.28.6 '@babel/helper-annotate-as-pure': 7.27.3 '@babel/helper-create-class-features-plugin': 7.28.6(@babel/core@7.28.6) - '@babel/helper-plugin-utils': 7.28.6 + '@babel/helper-plugin-utils': 7.29.7 '@babel/helper-skip-transparent-expression-wrappers': 7.27.1 - '@babel/plugin-syntax-typescript': 7.28.6(@babel/core@7.28.6) + '@babel/plugin-syntax-typescript': 7.29.7(@babel/core@7.28.6) transitivePeerDependencies: - supports-color @@ -15648,9 +15651,9 @@ snapshots: '@babel/template@7.28.6': dependencies: - '@babel/code-frame': 7.28.6 - '@babel/parser': 7.29.2 - '@babel/types': 7.28.6 + '@babel/code-frame': 7.29.7 + '@babel/parser': 7.29.7 + '@babel/types': 7.29.7 '@babel/template@7.29.7': dependencies: @@ -15660,12 +15663,12 @@ snapshots: '@babel/traverse@7.28.6': dependencies: - '@babel/code-frame': 7.28.6 - '@babel/generator': 7.28.6 - '@babel/helper-globals': 7.28.0 - '@babel/parser': 7.29.2 - '@babel/template': 7.28.6 - '@babel/types': 7.28.6 + '@babel/code-frame': 7.29.7 + '@babel/generator': 7.29.7 + '@babel/helper-globals': 7.29.7 + '@babel/parser': 7.29.7 + '@babel/template': 7.29.7 + '@babel/types': 7.29.7 debug: 4.4.3(supports-color@8.1.1) transitivePeerDependencies: - supports-color @@ -15684,13 +15687,13 @@ snapshots: '@babel/types@7.28.6': dependencies: - '@babel/helper-string-parser': 7.27.1 - '@babel/helper-validator-identifier': 7.28.5 + '@babel/helper-string-parser': 7.29.7 + '@babel/helper-validator-identifier': 7.29.7 '@babel/types@7.29.0': dependencies: - '@babel/helper-string-parser': 7.27.1 - '@babel/helper-validator-identifier': 7.28.5 + '@babel/helper-string-parser': 7.29.7 + '@babel/helper-validator-identifier': 7.29.7 '@babel/types@7.29.7': dependencies: @@ -20156,16 +20159,16 @@ snapshots: '@types/babel__generator@7.27.0': dependencies: - '@babel/types': 7.29.0 + '@babel/types': 7.29.7 '@types/babel__template@7.4.4': dependencies: - '@babel/parser': 7.29.2 - '@babel/types': 7.29.0 + '@babel/parser': 7.29.7 + '@babel/types': 7.29.7 '@types/babel__traverse@7.28.0': dependencies: - '@babel/types': 7.29.0 + '@babel/types': 7.29.7 '@types/better-sqlite3@7.6.13': dependencies: @@ -24402,7 +24405,7 @@ snapshots: parse-json@5.2.0: dependencies: - '@babel/code-frame': 7.28.6 + '@babel/code-frame': 7.29.7 error-ex: 1.3.4 json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 diff --git a/www/src/components/landing/menu/site-menu.tsx b/www/src/components/landing/menu/site-menu.tsx index eb534ce15..9e35ba36b 100644 --- a/www/src/components/landing/menu/site-menu.tsx +++ b/www/src/components/landing/menu/site-menu.tsx @@ -5,7 +5,7 @@ import Image from 'next/image'; import Link from 'next/link'; import { useCallback, useEffect, useState } from 'react'; import { APP_URL, DISCORD_URL, DOCS_URL, GITHUB_URL } from '@/lib/site-links'; -import { ArrowRightIcon, PlusCorner } from '../icons'; +import { PlusCorner } from '../icons'; function MenuIcon() { return (