@shipfox/api-integration-gitea 8.0.0 → 9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +45 -0
- package/README.md +3 -8
- package/dist/api/client.js +1 -1
- package/dist/api/client.js.map +1 -1
- package/dist/core/connect.d.ts +1 -1
- package/dist/core/connect.d.ts.map +1 -1
- package/dist/core/connect.js.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +1 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/source-control.d.ts +1 -1
- package/dist/core/source-control.d.ts.map +1 -1
- package/dist/core/source-control.js +1 -1
- package/dist/core/source-control.js.map +1 -1
- package/dist/core/webhook-processor.d.ts +1 -1
- package/dist/core/webhook-processor.d.ts.map +1 -1
- package/dist/core/webhook-processor.js +1 -1
- package/dist/core/webhook-processor.js.map +1 -1
- package/dist/core/webhook.d.ts +1 -1
- package/dist/core/webhook.d.ts.map +1 -1
- package/dist/core/webhook.js +1 -1
- package/dist/core/webhook.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/presentation/dto/integrations.d.ts +3 -3
- package/dist/presentation/dto/integrations.d.ts.map +1 -1
- package/dist/presentation/dto/integrations.js +20 -7
- package/dist/presentation/dto/integrations.js.map +1 -1
- package/dist/presentation/routes/connections.d.ts +1 -1
- package/dist/presentation/routes/connections.d.ts.map +1 -1
- package/dist/presentation/routes/connections.js.map +1 -1
- package/dist/presentation/routes/errors.js +1 -1
- package/dist/presentation/routes/errors.js.map +1 -1
- package/dist/presentation/routes/webhooks.d.ts +1 -1
- package/dist/presentation/routes/webhooks.d.ts.map +1 -1
- package/dist/presentation/routes/webhooks.js +1 -1
- package/dist/presentation/routes/webhooks.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +20 -13
- package/src/api/client.ts +1 -1
- package/src/core/connect.test.ts +1 -1
- package/src/core/connect.ts +1 -1
- package/src/core/errors.ts +1 -1
- package/src/core/source-control-clone-url.test.ts +1 -1
- package/src/core/source-control.test.ts +1 -1
- package/src/core/source-control.ts +2 -2
- package/src/core/webhook-processor.test.ts +1 -1
- package/src/core/webhook-processor.ts +1 -1
- package/src/core/webhook.test.ts +1 -1
- package/src/core/webhook.ts +6 -6
- package/src/index.ts +2 -2
- package/src/presentation/dto/integrations.ts +22 -8
- package/src/presentation/routes/connections.test.ts +1 -1
- package/src/presentation/routes/connections.ts +1 -1
- package/src/presentation/routes/errors.ts +1 -1
- package/src/presentation/routes/webhooks.ts +2 -5
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { toIntegrationConnectionDto as toCoreIntegrationConnectionDto } from '@shipfox/api-integration-core-dto';
|
|
2
1
|
export function toIntegrationConnectionDto(connection, options = {}) {
|
|
3
|
-
return
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
return mapIntegrationConnection(connection, [
|
|
3
|
+
'source_control'
|
|
4
|
+
], options.externalUrl);
|
|
5
|
+
}
|
|
6
|
+
function mapIntegrationConnection(connection, capabilities, externalUrl) {
|
|
7
|
+
return {
|
|
8
|
+
id: connection.id,
|
|
9
|
+
workspace_id: connection.workspaceId,
|
|
10
|
+
provider: connection.provider,
|
|
11
|
+
external_account_id: connection.externalAccountId,
|
|
12
|
+
slug: connection.slug,
|
|
13
|
+
display_name: connection.displayName,
|
|
14
|
+
lifecycle_status: connection.lifecycleStatus,
|
|
15
|
+
capabilities,
|
|
16
|
+
...externalUrl ? {
|
|
17
|
+
external_url: externalUrl
|
|
18
|
+
} : {},
|
|
19
|
+
created_at: connection.createdAt.toISOString(),
|
|
20
|
+
updated_at: connection.updatedAt.toISOString()
|
|
21
|
+
};
|
|
9
22
|
}
|
|
10
23
|
|
|
11
24
|
//# sourceMappingURL=integrations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/dto/integrations.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/dto/integrations.ts"],"sourcesContent":["import type {IntegrationConnection} from '@shipfox/api-integration-spi';\n\nexport function toIntegrationConnectionDto(\n connection: IntegrationConnection<'gitea'>,\n options: {externalUrl?: string | undefined} = {},\n) {\n return mapIntegrationConnection(connection, ['source_control'], options.externalUrl);\n}\n\nfunction mapIntegrationConnection(\n connection: IntegrationConnection,\n capabilities: string[],\n externalUrl?: string,\n) {\n return {\n id: connection.id,\n workspace_id: connection.workspaceId,\n provider: connection.provider,\n external_account_id: connection.externalAccountId,\n slug: connection.slug,\n display_name: connection.displayName,\n lifecycle_status: connection.lifecycleStatus,\n capabilities,\n ...(externalUrl ? {external_url: externalUrl} : {}),\n created_at: connection.createdAt.toISOString(),\n updated_at: connection.updatedAt.toISOString(),\n };\n}\n"],"names":["toIntegrationConnectionDto","connection","options","mapIntegrationConnection","externalUrl","capabilities","id","workspace_id","workspaceId","provider","external_account_id","externalAccountId","slug","display_name","displayName","lifecycle_status","lifecycleStatus","external_url","created_at","createdAt","toISOString","updated_at","updatedAt"],"mappings":"AAEA,OAAO,SAASA,2BACdC,UAA0C,EAC1CC,UAA8C,CAAC,CAAC;IAEhD,OAAOC,yBAAyBF,YAAY;QAAC;KAAiB,EAAEC,QAAQE,WAAW;AACrF;AAEA,SAASD,yBACPF,UAAiC,EACjCI,YAAsB,EACtBD,WAAoB;IAEpB,OAAO;QACLE,IAAIL,WAAWK,EAAE;QACjBC,cAAcN,WAAWO,WAAW;QACpCC,UAAUR,WAAWQ,QAAQ;QAC7BC,qBAAqBT,WAAWU,iBAAiB;QACjDC,MAAMX,WAAWW,IAAI;QACrBC,cAAcZ,WAAWa,WAAW;QACpCC,kBAAkBd,WAAWe,eAAe;QAC5CX;QACA,GAAID,cAAc;YAACa,cAAcb;QAAW,IAAI,CAAC,CAAC;QAClDc,YAAYjB,WAAWkB,SAAS,CAACC,WAAW;QAC5CC,YAAYpB,WAAWqB,SAAS,CAACF,WAAW;IAC9C;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IntegrationConnection } from '@shipfox/api-integration-
|
|
1
|
+
import type { IntegrationConnection } from '@shipfox/api-integration-spi';
|
|
2
2
|
import { type RouteGroup } from '@shipfox/node-fastify';
|
|
3
3
|
import type { GiteaApiClient } from '#api/client.js';
|
|
4
4
|
import { type ConnectGiteaConnectionInput } from '#core/connect.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/connections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/connections.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAc,KAAK,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAC,KAAK,2BAA2B,EAAqB,MAAM,kBAAkB,CAAC;AAKtF,MAAM,WAAW,kCAAkC;IACjD,KAAK,EAAE,cAAc,CAAC;IACtB,0BAA0B,EAAE,CAAC,KAAK,EAAE;QAClC,GAAG,EAAE,MAAM,CAAC;KACb,KAAK,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1D,sBAAsB,EAAE,CACtB,KAAK,EAAE,2BAA2B,KAC/B,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;CAC9C;AAED,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,EAAE,kCAAkC,GAAG,UAAU,CAmCjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/connections.ts"],"sourcesContent":["import {AUTH_USER, requireWorkspaceAccess} from '@shipfox/api-auth-context';\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/connections.ts"],"sourcesContent":["import {AUTH_USER, requireWorkspaceAccess} from '@shipfox/api-auth-context';\nimport {\n createGiteaConnectionBodySchema,\n createGiteaConnectionResponseSchema,\n} from '@shipfox/api-integration-gitea-dto';\nimport type {IntegrationConnection} from '@shipfox/api-integration-spi';\nimport {defineRoute, type RouteGroup} from '@shipfox/node-fastify';\nimport type {GiteaApiClient} from '#api/client.js';\nimport {type ConnectGiteaConnectionInput, handleGiteaConnect} from '#core/connect.js';\nimport {giteaConnectionExternalUrl} from '#core/connection-url.js';\nimport {toIntegrationConnectionDto} from '#presentation/dto/integrations.js';\nimport {giteaRouteErrorHandler} from './errors.js';\n\nexport interface CreateGiteaConnectionRoutesOptions {\n gitea: GiteaApiClient;\n getExistingGiteaConnection: (input: {\n org: string;\n }) => Promise<IntegrationConnection<'gitea'> | undefined>;\n connectGiteaConnection: (\n input: ConnectGiteaConnectionInput,\n ) => Promise<IntegrationConnection<'gitea'>>;\n}\n\nexport function createGiteaConnectionRoutes({\n gitea,\n getExistingGiteaConnection,\n connectGiteaConnection,\n}: CreateGiteaConnectionRoutesOptions): RouteGroup {\n const createConnectionRoute = defineRoute({\n method: 'POST',\n path: '/connections',\n auth: AUTH_USER,\n description: 'Connect a Gitea organization to a workspace.',\n schema: {\n body: createGiteaConnectionBodySchema,\n response: {\n 200: createGiteaConnectionResponseSchema,\n },\n },\n errorHandler: giteaRouteErrorHandler,\n handler: async (request) => {\n const {workspace_id: workspaceId, org} = request.body;\n\n requireWorkspaceAccess({request, workspaceId});\n const connection = await handleGiteaConnect({\n gitea,\n workspaceId,\n org,\n getExistingGiteaConnection,\n connectGiteaConnection,\n });\n\n return toIntegrationConnectionDto(connection, {\n externalUrl: giteaConnectionExternalUrl(connection.externalAccountId),\n });\n },\n });\n\n return {\n prefix: '/integrations/gitea',\n routes: [createConnectionRoute],\n };\n}\n"],"names":["AUTH_USER","requireWorkspaceAccess","createGiteaConnectionBodySchema","createGiteaConnectionResponseSchema","defineRoute","handleGiteaConnect","giteaConnectionExternalUrl","toIntegrationConnectionDto","giteaRouteErrorHandler","createGiteaConnectionRoutes","gitea","getExistingGiteaConnection","connectGiteaConnection","createConnectionRoute","method","path","auth","description","schema","body","response","errorHandler","handler","request","workspace_id","workspaceId","org","connection","externalUrl","externalAccountId","prefix","routes"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,sBAAsB,QAAO,4BAA4B;AAC5E,SACEC,+BAA+B,EAC/BC,mCAAmC,QAC9B,qCAAqC;AAE5C,SAAQC,WAAW,QAAwB,wBAAwB;AAEnE,SAA0CC,kBAAkB,QAAO,mBAAmB;AACtF,SAAQC,0BAA0B,QAAO,0BAA0B;AACnE,SAAQC,0BAA0B,QAAO,oCAAoC;AAC7E,SAAQC,sBAAsB,QAAO,cAAc;AAYnD,OAAO,SAASC,4BAA4B,EAC1CC,KAAK,EACLC,0BAA0B,EAC1BC,sBAAsB,EACa;IACnC,MAAMC,wBAAwBT,YAAY;QACxCU,QAAQ;QACRC,MAAM;QACNC,MAAMhB;QACNiB,aAAa;QACbC,QAAQ;YACNC,MAAMjB;YACNkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,cAAcb;QACdc,SAAS,OAAOC;YACd,MAAM,EAACC,cAAcC,WAAW,EAAEC,GAAG,EAAC,GAAGH,QAAQJ,IAAI;YAErDlB,uBAAuB;gBAACsB;gBAASE;YAAW;YAC5C,MAAME,aAAa,MAAMtB,mBAAmB;gBAC1CK;gBACAe;gBACAC;gBACAf;gBACAC;YACF;YAEA,OAAOL,2BAA2BoB,YAAY;gBAC5CC,aAAatB,2BAA2BqB,WAAWE,iBAAiB;YACtE;QACF;IACF;IAEA,OAAO;QACLC,QAAQ;QACRC,QAAQ;YAAClB;SAAsB;IACjC;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConnectionSlugConflictError } from '@shipfox/api-integration-
|
|
1
|
+
import { ConnectionSlugConflictError } from '@shipfox/api-integration-spi';
|
|
2
2
|
import { ClientError } from '@shipfox/node-fastify';
|
|
3
3
|
import { GiteaIntegrationProviderError, GiteaOrgAlreadyLinkedError, GiteaOrganizationNotFoundError } from '#core/errors.js';
|
|
4
4
|
function providerStatus(reason) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/errors.ts"],"sourcesContent":["import {\n ConnectionSlugConflictError,\n type IntegrationProviderErrorReason,\n} from '@shipfox/api-integration-
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/errors.ts"],"sourcesContent":["import {\n ConnectionSlugConflictError,\n type IntegrationProviderErrorReason,\n} from '@shipfox/api-integration-spi';\nimport {ClientError} from '@shipfox/node-fastify';\nimport {\n GiteaIntegrationProviderError,\n GiteaOrgAlreadyLinkedError,\n GiteaOrganizationNotFoundError,\n} from '#core/errors.js';\n\nfunction providerStatus(reason: IntegrationProviderErrorReason): number {\n if (reason === 'rate-limited') return 429;\n if (reason === 'timeout' || reason === 'provider-unavailable') return 503;\n return 422;\n}\n\nexport function giteaRouteErrorHandler(error: unknown): never {\n if (error instanceof GiteaOrganizationNotFoundError) {\n throw new ClientError(error.message, 'gitea-organization-not-found', {status: 404});\n }\n if (error instanceof GiteaOrgAlreadyLinkedError) {\n throw new ClientError(error.message, 'gitea-org-already-linked', {status: 409});\n }\n if (error instanceof ConnectionSlugConflictError) {\n throw new ClientError(error.message, 'slug-conflict', {status: 409});\n }\n if (error instanceof GiteaIntegrationProviderError) {\n throw new ClientError(error.message, error.reason, {\n details: {retry_after_seconds: error.retryAfterSeconds},\n status: providerStatus(error.reason),\n });\n }\n throw error;\n}\n"],"names":["ConnectionSlugConflictError","ClientError","GiteaIntegrationProviderError","GiteaOrgAlreadyLinkedError","GiteaOrganizationNotFoundError","providerStatus","reason","giteaRouteErrorHandler","error","message","status","details","retry_after_seconds","retryAfterSeconds"],"mappings":"AAAA,SACEA,2BAA2B,QAEtB,+BAA+B;AACtC,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SACEC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,8BAA8B,QACzB,kBAAkB;AAEzB,SAASC,eAAeC,MAAsC;IAC5D,IAAIA,WAAW,gBAAgB,OAAO;IACtC,IAAIA,WAAW,aAAaA,WAAW,wBAAwB,OAAO;IACtE,OAAO;AACT;AAEA,OAAO,SAASC,uBAAuBC,KAAc;IACnD,IAAIA,iBAAiBJ,gCAAgC;QACnD,MAAM,IAAIH,YAAYO,MAAMC,OAAO,EAAE,gCAAgC;YAACC,QAAQ;QAAG;IACnF;IACA,IAAIF,iBAAiBL,4BAA4B;QAC/C,MAAM,IAAIF,YAAYO,MAAMC,OAAO,EAAE,4BAA4B;YAACC,QAAQ;QAAG;IAC/E;IACA,IAAIF,iBAAiBR,6BAA6B;QAChD,MAAM,IAAIC,YAAYO,MAAMC,OAAO,EAAE,iBAAiB;YAACC,QAAQ;QAAG;IACpE;IACA,IAAIF,iBAAiBN,+BAA+B;QAClD,MAAM,IAAID,YAAYO,MAAMC,OAAO,EAAED,MAAMF,MAAM,EAAE;YACjDK,SAAS;gBAACC,qBAAqBJ,MAAMK,iBAAiB;YAAA;YACtDH,QAAQL,eAAeG,MAAMF,MAAM;QACrC;IACF;IACA,MAAME;AACR"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetIntegrationConnectionByIdFn, PublishSourcePushFn, RecordDeliveryOnlyFn } from '@shipfox/api-integration-
|
|
1
|
+
import type { GetIntegrationConnectionByIdFn, PublishSourcePushFn, RecordDeliveryOnlyFn } from '@shipfox/api-integration-spi';
|
|
2
2
|
import { type RouteGroup } from '@shipfox/node-fastify';
|
|
3
3
|
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
4
|
import { type GiteaWebhookProcessor } from '#core/webhook-processor.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/webhooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,8BAA8B,EAC9B,mBAAmB,EACnB,oBAAoB,EAGrB,MAAM,
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/webhooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,8BAA8B,EAC9B,mBAAmB,EACnB,oBAAoB,EAGrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAA8B,KAAK,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAMnG,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,iBAAiB,EAAE,mBAAmB,CAAC;IACvC,kBAAkB,EAAE,oBAAoB,CAAC;IACzC,4BAA4B,EAAE,8BAA8B,CAAC;IAC7D,SAAS,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC/C;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,+BAA+B,GAAG,UAAU,CA+C7F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { createStoredWebhookRequest, WEBHOOK_MAX_RAW_BODY_BYTES } from '@shipfox/api-integration-
|
|
2
|
+
import { createStoredWebhookRequest, WEBHOOK_MAX_RAW_BODY_BYTES } from '@shipfox/api-integration-spi';
|
|
3
3
|
import { ClientError, defineRoute, rawBodyPlugin, WEBHOOK_BODY_LIMIT } from '@shipfox/node-fastify';
|
|
4
4
|
import { createGiteaWebhookProcessor } from '#core/webhook-processor.js';
|
|
5
5
|
const SIGNATURE_HEADER = 'x-gitea-signature';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/webhooks.ts"],"sourcesContent":["import {randomUUID} from 'node:crypto';\nimport type {\n GetIntegrationConnectionByIdFn,\n PublishSourcePushFn,\n RecordDeliveryOnlyFn,\n StoredWebhookRequest,\n WebhookProcessingResult,\n} from '@shipfox/api-integration-
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/webhooks.ts"],"sourcesContent":["import {randomUUID} from 'node:crypto';\nimport type {\n GetIntegrationConnectionByIdFn,\n PublishSourcePushFn,\n RecordDeliveryOnlyFn,\n StoredWebhookRequest,\n WebhookProcessingResult,\n} from '@shipfox/api-integration-spi';\nimport {createStoredWebhookRequest, WEBHOOK_MAX_RAW_BODY_BYTES} from '@shipfox/api-integration-spi';\nimport {\n ClientError,\n defineRoute,\n type RouteGroup,\n rawBodyPlugin,\n WEBHOOK_BODY_LIMIT,\n} from '@shipfox/node-fastify';\nimport type {NodePgDatabase} from 'drizzle-orm/node-postgres';\nimport {createGiteaWebhookProcessor, type GiteaWebhookProcessor} from '#core/webhook-processor.js';\n\nconst SIGNATURE_HEADER = 'x-gitea-signature';\nconst EVENT_HEADER = 'x-gitea-event';\nconst DELIVERY_HEADER = 'x-gitea-delivery';\n\nexport interface CreateGiteaWebhookRoutesOptions {\n coreDb: () => NodePgDatabase<Record<string, unknown>>;\n publishSourcePush: PublishSourcePushFn;\n recordDeliveryOnly: RecordDeliveryOnlyFn;\n getIntegrationConnectionById: GetIntegrationConnectionByIdFn;\n processor?: GiteaWebhookProcessor | undefined;\n}\n\nexport function createGiteaWebhookRoutes(options: CreateGiteaWebhookRoutesOptions): RouteGroup {\n const processor = options.processor ?? createGiteaWebhookProcessor(options);\n const pushRoute = defineRoute({\n method: 'POST',\n path: '/',\n auth: [],\n description: 'Gitea org webhook receiver.',\n options: {bodyLimit: WEBHOOK_BODY_LIMIT},\n handler: async (request, reply) => {\n const deliveryId = request.headers[DELIVERY_HEADER];\n const signature = request.headers[SIGNATURE_HEADER];\n const event = request.headers[EVENT_HEADER];\n\n if (typeof deliveryId !== 'string' || !deliveryId) {\n reply.code(400);\n return {error: 'missing X-Gitea-Delivery header'};\n }\n if (typeof signature !== 'string' || !signature) {\n reply.code(401);\n return {error: 'missing X-Gitea-Signature header'};\n }\n if (typeof event !== 'string' || !event) {\n reply.code(400);\n return {error: 'missing X-Gitea-Event header'};\n }\n\n if (!(request.body instanceof Uint8Array)) {\n reply.code(400);\n return {error: 'expected raw JSON body'};\n }\n const result = await processor.process(\n createGiteaStoredWebhookRequest({\n body: request.body,\n headers: request.headers,\n rawQueryString: request.raw.url?.split('?')[1] ?? '',\n }),\n );\n return sendGiteaWebhookResponse(reply, result);\n },\n });\n\n return {\n prefix: '/webhooks/integrations/gitea',\n auth: [],\n plugins: [rawBodyPlugin],\n routes: [pushRoute],\n };\n}\n\nfunction createGiteaStoredWebhookRequest(input: {\n body: Uint8Array;\n headers: Record<string, string | string[] | undefined>;\n rawQueryString: string;\n}): StoredWebhookRequest {\n if (input.body.byteLength > WEBHOOK_MAX_RAW_BODY_BYTES) {\n throw new ClientError('Webhook request body is too large', 'body-too-large', {status: 413});\n }\n try {\n return createStoredWebhookRequest({\n requestId: randomUUID(),\n routeId: 'gitea',\n receivedAt: new Date().toISOString(),\n rawQueryString: input.rawQueryString,\n headers: giteaWebhookHeaders(input.headers),\n body: input.body,\n });\n } catch (error) {\n throw new ClientError('Webhook request metadata is invalid', 'invalid-webhook-request', {\n cause: error,\n });\n }\n}\n\nfunction giteaWebhookHeaders(headers: Record<string, string | string[] | undefined>) {\n return Object.fromEntries(\n ['content-type', DELIVERY_HEADER, EVENT_HEADER, SIGNATURE_HEADER].flatMap((name) => {\n const value = headers[name];\n return typeof value === 'string' ? [[name, value]] : [];\n }),\n );\n}\n\nfunction sendGiteaWebhookResponse(\n reply: {code(statusCode: number): void},\n result: WebhookProcessingResult,\n) {\n if (result.outcome === 'discarded' && result.reason === 'invalid_signature') {\n reply.code(401);\n return {error: 'invalid signature'};\n }\n if (result.outcome === 'discarded' && result.reason === 'malformed_payload') {\n reply.code(400);\n return {error: 'malformed JSON'};\n }\n if (result.outcome === 'discarded' && result.reason === 'unsupported_event') {\n reply.code(400);\n return {error: 'malformed push payload'};\n }\n reply.code(204);\n return null;\n}\n"],"names":["randomUUID","createStoredWebhookRequest","WEBHOOK_MAX_RAW_BODY_BYTES","ClientError","defineRoute","rawBodyPlugin","WEBHOOK_BODY_LIMIT","createGiteaWebhookProcessor","SIGNATURE_HEADER","EVENT_HEADER","DELIVERY_HEADER","createGiteaWebhookRoutes","options","processor","pushRoute","method","path","auth","description","bodyLimit","handler","request","reply","deliveryId","headers","signature","event","code","error","body","Uint8Array","result","process","createGiteaStoredWebhookRequest","rawQueryString","raw","url","split","sendGiteaWebhookResponse","prefix","plugins","routes","input","byteLength","status","requestId","routeId","receivedAt","Date","toISOString","giteaWebhookHeaders","cause","Object","fromEntries","flatMap","name","value","outcome","reason"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAc;AAQvC,SAAQC,0BAA0B,EAAEC,0BAA0B,QAAO,+BAA+B;AACpG,SACEC,WAAW,EACXC,WAAW,EAEXC,aAAa,EACbC,kBAAkB,QACb,wBAAwB;AAE/B,SAAQC,2BAA2B,QAAmC,6BAA6B;AAEnG,MAAMC,mBAAmB;AACzB,MAAMC,eAAe;AACrB,MAAMC,kBAAkB;AAUxB,OAAO,SAASC,yBAAyBC,OAAwC;IAC/E,MAAMC,YAAYD,QAAQC,SAAS,IAAIN,4BAA4BK;IACnE,MAAME,YAAYV,YAAY;QAC5BW,QAAQ;QACRC,MAAM;QACNC,MAAM,EAAE;QACRC,aAAa;QACbN,SAAS;YAACO,WAAWb;QAAkB;QACvCc,SAAS,OAAOC,SAASC;YACvB,MAAMC,aAAaF,QAAQG,OAAO,CAACd,gBAAgB;YAC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