@c15t/backend 2.0.0-rc.4 → 2.0.0-rc.6
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/dist/302.js +473 -0
- package/dist/364.js +1140 -0
- package/dist/583.js +540 -0
- package/dist/cache.cjs +1 -1
- package/dist/cache.js +4 -415
- package/dist/core.cjs +849 -96
- package/dist/core.js +147 -1817
- package/dist/db/adapters/drizzle.cjs +1 -1
- package/dist/db/adapters/drizzle.js +1 -2
- package/dist/db/adapters/kysely.cjs +1 -1
- package/dist/db/adapters/kysely.js +1 -2
- package/dist/db/adapters/mongo.cjs +1 -1
- package/dist/db/adapters/mongo.js +1 -2
- package/dist/db/adapters/prisma.cjs +1 -1
- package/dist/db/adapters/prisma.js +1 -2
- package/dist/db/adapters/typeorm.cjs +1 -1
- package/dist/db/adapters/typeorm.js +1 -2
- package/dist/db/adapters.cjs +1 -1
- package/dist/db/migrator.cjs +1 -1
- package/dist/db/schema.cjs +38 -1
- package/dist/db/schema.js +33 -2
- package/dist/define-config.cjs +1 -1
- package/dist/edge.cjs +1106 -0
- package/dist/edge.js +190 -0
- package/dist/router.cjs +629 -81
- package/dist/router.js +1 -1509
- package/dist/types/index.cjs +1 -1
- package/{dist → dist-types}/cache/adapters/cloudflare-kv.d.ts +0 -1
- package/{dist → dist-types}/cache/adapters/index.d.ts +0 -1
- package/{dist → dist-types}/cache/adapters/memory.d.ts +0 -1
- package/{dist → dist-types}/cache/adapters/upstash-redis.d.ts +0 -1
- package/{dist → dist-types}/cache/gvl-resolver.d.ts +1 -2
- package/{dist → dist-types}/cache/index.d.ts +0 -1
- package/{dist → dist-types}/cache/keys.d.ts +0 -1
- package/{dist → dist-types}/cache/types.d.ts +0 -1
- package/{dist → dist-types}/core.d.ts +8 -1
- package/{dist → dist-types}/db/migrator/index.d.ts +0 -1
- package/{dist → dist-types}/db/registry/consent-policy.d.ts +0 -1
- package/{dist → dist-types}/db/registry/consent-purpose.d.ts +0 -1
- package/{dist → dist-types}/db/registry/domain.d.ts +0 -1
- package/{dist → dist-types}/db/registry/index.d.ts +22 -2
- package/dist-types/db/registry/runtime-policy-decision.d.ts +60 -0
- package/{dist → dist-types}/db/registry/subject.d.ts +0 -1
- package/{dist → dist-types}/db/registry/types.d.ts +1 -2
- package/{dist → dist-types}/db/registry/utils/generate-id.d.ts +0 -1
- package/{dist → dist-types}/db/registry/utils.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/audit-log.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/consent-policy.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/consent-purpose.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/consent-record.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/consent.d.ts +2 -3
- package/{dist → dist-types}/db/schema/1.0.0/domain.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/index.d.ts +0 -1
- package/{dist → dist-types}/db/schema/1.0.0/subject.d.ts +0 -1
- package/{dist → dist-types}/db/schema/2.0.0/audit-log.d.ts +2 -3
- package/{dist → dist-types}/db/schema/2.0.0/consent-policy.d.ts +2 -3
- package/{dist → dist-types}/db/schema/2.0.0/consent-purpose.d.ts +2 -3
- package/{dist → dist-types}/db/schema/2.0.0/consent.d.ts +6 -3
- package/{dist → dist-types}/db/schema/2.0.0/domain.d.ts +2 -3
- package/{dist → dist-types}/db/schema/2.0.0/index.d.ts +432 -17
- package/dist-types/db/schema/2.0.0/runtime-policy-decision.d.ts +23 -0
- package/{dist → dist-types}/db/schema/2.0.0/subject.d.ts +2 -3
- package/{dist → dist-types}/db/schema/index.d.ts +862 -33
- package/{dist → dist-types}/db/tenant-scope.d.ts +0 -1
- package/{dist → dist-types}/define-config.d.ts +0 -1
- package/dist-types/edge/index.d.ts +5 -0
- package/dist-types/edge/init-handler.d.ts +38 -0
- package/dist-types/edge/resolve-consent.d.ts +80 -0
- package/dist-types/edge/types.d.ts +13 -0
- package/{dist → dist-types}/handlers/consent/check.handler.d.ts +0 -1
- package/{src/handlers/consent/index.ts → dist-types/handlers/consent/index.d.ts} +0 -1
- package/{dist → dist-types}/handlers/init/geo.d.ts +2 -3
- package/{dist → dist-types}/handlers/init/index.d.ts +4 -5
- package/dist-types/handlers/init/policy.d.ts +26 -0
- package/dist-types/handlers/init/resolve-init.d.ts +44 -0
- package/dist-types/handlers/init/translations.d.ts +48 -0
- package/dist-types/handlers/policy/snapshot.d.ts +99 -0
- package/{src/handlers/status/index.ts → dist-types/handlers/status/index.d.ts} +0 -1
- package/{dist → dist-types}/handlers/status/status.handler.d.ts +0 -1
- package/{dist → dist-types}/handlers/subject/get.handler.d.ts +0 -1
- package/{src/handlers/subject/index.ts → dist-types/handlers/subject/index.d.ts} +0 -1
- package/{dist → dist-types}/handlers/subject/list.handler.d.ts +0 -1
- package/{dist → dist-types}/handlers/subject/patch.handler.d.ts +0 -1
- package/{dist → dist-types}/handlers/subject/post.handler.d.ts +12 -1
- package/{dist → dist-types}/handlers/utils/consent-enrichment.d.ts +0 -1
- package/{dist → dist-types}/init.d.ts +0 -1
- package/{dist → dist-types}/middleware/auth/index.d.ts +0 -1
- package/{dist → dist-types}/middleware/auth/validate-api-key.d.ts +0 -1
- package/{dist → dist-types}/middleware/cors/cors.d.ts +0 -1
- package/{src/middleware/cors/index.ts → dist-types/middleware/cors/index.d.ts} +0 -1
- package/{dist → dist-types}/middleware/cors/is-origin-trusted.d.ts +1 -2
- package/{dist → dist-types}/middleware/cors/process-cors.d.ts +0 -1
- package/{dist → dist-types}/middleware/openapi/config.d.ts +0 -1
- package/{dist → dist-types}/middleware/openapi/handlers.d.ts +0 -1
- package/{src/middleware/openapi/index.ts → dist-types/middleware/openapi/index.d.ts} +0 -1
- package/{dist → dist-types}/middleware/process-ip/index.d.ts +0 -1
- package/dist-types/policies/builder.d.ts +127 -0
- package/dist-types/policies/defaults.d.ts +2 -0
- package/dist-types/policies/matchers.d.ts +3 -0
- package/{dist → dist-types}/router.d.ts +0 -1
- package/{dist → dist-types}/routes/consent.d.ts +0 -1
- package/{src/routes/index.ts → dist-types/routes/index.d.ts} +0 -1
- package/{dist → dist-types}/routes/init.d.ts +0 -1
- package/{dist → dist-types}/routes/status.d.ts +0 -1
- package/{dist → dist-types}/routes/subject.d.ts +0 -1
- package/{dist → dist-types}/types/api.d.ts +0 -1
- package/{dist → dist-types}/types/index.d.ts +110 -6
- package/dist-types/utils/background.d.ts +6 -0
- package/{dist → dist-types}/utils/create-telemetry-options.d.ts +0 -1
- package/{dist → dist-types}/utils/env.d.ts +0 -1
- package/{dist → dist-types}/utils/extract-error-message.d.ts +0 -1
- package/{dist → dist-types}/utils/instrumentation.d.ts +0 -1
- package/{dist → dist-types}/utils/logger.d.ts +1 -2
- package/{dist → dist-types}/utils/metrics.d.ts +0 -1
- package/dist-types/version.d.ts +1 -0
- package/docs/README.md +49 -0
- package/docs/api/configuration.md +197 -0
- package/docs/api/endpoints.md +211 -0
- package/docs/guides/caching.md +85 -0
- package/docs/guides/database-setup.md +128 -0
- package/docs/guides/edge-deployment.md +248 -0
- package/docs/guides/framework-integration.md +142 -0
- package/docs/guides/iab-tcf.md +89 -0
- package/docs/guides/observability.md +96 -0
- package/docs/guides/policy-packs.md +396 -0
- package/docs/quickstart.md +129 -0
- package/package.json +45 -31
- package/.turbo/turbo-build.log +0 -49
- package/CHANGELOG.md +0 -123
- package/dist/cache/adapters/cloudflare-kv.d.ts.map +0 -1
- package/dist/cache/adapters/index.d.ts.map +0 -1
- package/dist/cache/adapters/memory.d.ts.map +0 -1
- package/dist/cache/adapters/upstash-redis.d.ts.map +0 -1
- package/dist/cache/gvl-resolver.d.ts.map +0 -1
- package/dist/cache/index.d.ts.map +0 -1
- package/dist/cache/keys.d.ts.map +0 -1
- package/dist/cache/types.d.ts.map +0 -1
- package/dist/core.d.ts.map +0 -1
- package/dist/db/adapters/drizzle.d.ts +0 -2
- package/dist/db/adapters/drizzle.d.ts.map +0 -1
- package/dist/db/adapters/index.d.ts +0 -2
- package/dist/db/adapters/index.d.ts.map +0 -1
- package/dist/db/adapters/kysely.d.ts +0 -2
- package/dist/db/adapters/kysely.d.ts.map +0 -1
- package/dist/db/adapters/mongo.d.ts +0 -2
- package/dist/db/adapters/mongo.d.ts.map +0 -1
- package/dist/db/adapters/prisma.d.ts +0 -2
- package/dist/db/adapters/prisma.d.ts.map +0 -1
- package/dist/db/adapters/typeorm.d.ts +0 -2
- package/dist/db/adapters/typeorm.d.ts.map +0 -1
- package/dist/db/migrator/index.d.ts.map +0 -1
- package/dist/db/registry/consent-policy.d.ts.map +0 -1
- package/dist/db/registry/consent-purpose.d.ts.map +0 -1
- package/dist/db/registry/domain.d.ts.map +0 -1
- package/dist/db/registry/index.d.ts.map +0 -1
- package/dist/db/registry/subject.d.ts.map +0 -1
- package/dist/db/registry/types.d.ts.map +0 -1
- package/dist/db/registry/utils/generate-id.d.ts.map +0 -1
- package/dist/db/registry/utils.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/audit-log.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/consent-policy.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/consent-purpose.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/consent-record.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/consent.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/domain.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/index.d.ts.map +0 -1
- package/dist/db/schema/1.0.0/subject.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/audit-log.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/consent-policy.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/consent-purpose.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/consent.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/domain.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/index.d.ts.map +0 -1
- package/dist/db/schema/2.0.0/subject.d.ts.map +0 -1
- package/dist/db/schema/index.d.ts.map +0 -1
- package/dist/db/tenant-scope.d.ts.map +0 -1
- package/dist/define-config.d.ts.map +0 -1
- package/dist/handlers/consent/check.handler.d.ts.map +0 -1
- package/dist/handlers/consent/index.d.ts +0 -12
- package/dist/handlers/consent/index.d.ts.map +0 -1
- package/dist/handlers/init/geo.d.ts.map +0 -1
- package/dist/handlers/init/index.d.ts.map +0 -1
- package/dist/handlers/init/translations.d.ts +0 -26
- package/dist/handlers/init/translations.d.ts.map +0 -1
- package/dist/handlers/status/index.d.ts +0 -7
- package/dist/handlers/status/index.d.ts.map +0 -1
- package/dist/handlers/status/status.handler.d.ts.map +0 -1
- package/dist/handlers/subject/get.handler.d.ts.map +0 -1
- package/dist/handlers/subject/index.d.ts +0 -10
- package/dist/handlers/subject/index.d.ts.map +0 -1
- package/dist/handlers/subject/list.handler.d.ts.map +0 -1
- package/dist/handlers/subject/patch.handler.d.ts.map +0 -1
- package/dist/handlers/subject/post.handler.d.ts.map +0 -1
- package/dist/handlers/utils/consent-enrichment.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/middleware/auth/index.d.ts.map +0 -1
- package/dist/middleware/auth/validate-api-key.d.ts.map +0 -1
- package/dist/middleware/cors/cors.d.ts.map +0 -1
- package/dist/middleware/cors/index.d.ts +0 -30
- package/dist/middleware/cors/index.d.ts.map +0 -1
- package/dist/middleware/cors/is-origin-trusted.d.ts.map +0 -1
- package/dist/middleware/cors/process-cors.d.ts.map +0 -1
- package/dist/middleware/openapi/config.d.ts.map +0 -1
- package/dist/middleware/openapi/handlers.d.ts.map +0 -1
- package/dist/middleware/openapi/index.d.ts +0 -12
- package/dist/middleware/openapi/index.d.ts.map +0 -1
- package/dist/middleware/process-ip/index.d.ts.map +0 -1
- package/dist/router.d.ts.map +0 -1
- package/dist/routes/consent.d.ts.map +0 -1
- package/dist/routes/index.d.ts +0 -10
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/init.d.ts.map +0 -1
- package/dist/routes/status.d.ts.map +0 -1
- package/dist/routes/subject.d.ts.map +0 -1
- package/dist/types/api.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/create-telemetry-options.d.ts.map +0 -1
- package/dist/utils/env.d.ts.map +0 -1
- package/dist/utils/extract-error-message.d.ts.map +0 -1
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/instrumentation.d.ts.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/metrics.d.ts.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
- package/knip.json +0 -31
- package/rslib.config.ts +0 -93
- package/src/cache/adapters/cloudflare-kv.ts +0 -71
- package/src/cache/adapters/index.ts +0 -22
- package/src/cache/adapters/memory.ts +0 -111
- package/src/cache/adapters/upstash-redis.ts +0 -113
- package/src/cache/gvl-resolver.ts +0 -289
- package/src/cache/index.ts +0 -34
- package/src/cache/keys.ts +0 -68
- package/src/cache/types.ts +0 -66
- package/src/core.ts +0 -369
- package/src/db/migrator/index.ts +0 -80
- package/src/db/registry/consent-policy.test.ts +0 -451
- package/src/db/registry/consent-policy.ts +0 -82
- package/src/db/registry/consent-purpose.test.ts +0 -428
- package/src/db/registry/consent-purpose.ts +0 -61
- package/src/db/registry/domain.test.ts +0 -445
- package/src/db/registry/domain.ts +0 -91
- package/src/db/registry/index.ts +0 -14
- package/src/db/registry/subject.test.ts +0 -371
- package/src/db/registry/subject.ts +0 -126
- package/src/db/registry/types.ts +0 -10
- package/src/db/registry/utils/generate-id.test.ts +0 -216
- package/src/db/registry/utils/generate-id.ts +0 -133
- package/src/db/registry/utils.ts +0 -133
- package/src/db/schema/1.0.0/audit-log.ts +0 -15
- package/src/db/schema/1.0.0/consent-policy.ts +0 -14
- package/src/db/schema/1.0.0/consent-purpose.ts +0 -14
- package/src/db/schema/1.0.0/consent-record.ts +0 -10
- package/src/db/schema/1.0.0/consent.ts +0 -20
- package/src/db/schema/1.0.0/domain.ts +0 -12
- package/src/db/schema/1.0.0/index.ts +0 -48
- package/src/db/schema/1.0.0/subject.ts +0 -11
- package/src/db/schema/2.0.0/audit-log.ts +0 -18
- package/src/db/schema/2.0.0/consent-policy.ts +0 -28
- package/src/db/schema/2.0.0/consent-purpose.ts +0 -12
- package/src/db/schema/2.0.0/consent.ts +0 -28
- package/src/db/schema/2.0.0/domain.ts +0 -12
- package/src/db/schema/2.0.0/index.ts +0 -47
- package/src/db/schema/2.0.0/subject.ts +0 -13
- package/src/db/schema/index.ts +0 -15
- package/src/db/tenant-scope.test.ts +0 -747
- package/src/db/tenant-scope.ts +0 -103
- package/src/define-config.ts +0 -19
- package/src/handlers/consent/check.handler.ts +0 -126
- package/src/handlers/init/geo.test.ts +0 -317
- package/src/handlers/init/geo.ts +0 -195
- package/src/handlers/init/index.test.ts +0 -205
- package/src/handlers/init/index.ts +0 -114
- package/src/handlers/init/translations.test.ts +0 -121
- package/src/handlers/init/translations.ts +0 -69
- package/src/handlers/status/status.handler.test.ts +0 -155
- package/src/handlers/status/status.handler.ts +0 -51
- package/src/handlers/subject/get.handler.ts +0 -92
- package/src/handlers/subject/list.handler.ts +0 -92
- package/src/handlers/subject/patch.handler.ts +0 -119
- package/src/handlers/subject/post.handler.test.ts +0 -294
- package/src/handlers/subject/post.handler.ts +0 -268
- package/src/handlers/utils/consent-enrichment.test.ts +0 -380
- package/src/handlers/utils/consent-enrichment.ts +0 -218
- package/src/init.test.ts +0 -122
- package/src/init.ts +0 -88
- package/src/middleware/auth/index.ts +0 -11
- package/src/middleware/auth/validate-api-key.test.ts +0 -86
- package/src/middleware/auth/validate-api-key.ts +0 -107
- package/src/middleware/cors/cors.test.ts +0 -135
- package/src/middleware/cors/cors.ts +0 -186
- package/src/middleware/cors/is-origin-trusted.test.ts +0 -164
- package/src/middleware/cors/is-origin-trusted.ts +0 -130
- package/src/middleware/cors/process-cors.ts +0 -91
- package/src/middleware/openapi/config.ts +0 -29
- package/src/middleware/openapi/handlers.ts +0 -34
- package/src/middleware/process-ip/index.test.ts +0 -193
- package/src/middleware/process-ip/index.ts +0 -199
- package/src/router.ts +0 -15
- package/src/routes/consent.ts +0 -52
- package/src/routes/init.ts +0 -105
- package/src/routes/status.ts +0 -46
- package/src/routes/subject.ts +0 -152
- package/src/types/api.ts +0 -48
- package/src/types/index.ts +0 -391
- package/src/utils/create-telemetry-options.test.ts +0 -286
- package/src/utils/create-telemetry-options.ts +0 -229
- package/src/utils/env.ts +0 -84
- package/src/utils/extract-error-message.ts +0 -21
- package/src/utils/instrumentation.test.ts +0 -183
- package/src/utils/instrumentation.ts +0 -194
- package/src/utils/logger.ts +0 -41
- package/src/utils/metrics.test.ts +0 -311
- package/src/utils/metrics.ts +0 -402
- package/src/utils/telemetry-pii.test.ts +0 -323
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -11
- package/vitest.config.ts +0 -28
- /package/{src/db/adapters/drizzle.ts → dist-types/db/adapters/drizzle.d.ts} +0 -0
- /package/{src/db/adapters/index.ts → dist-types/db/adapters/index.d.ts} +0 -0
- /package/{src/db/adapters/kysely.ts → dist-types/db/adapters/kysely.d.ts} +0 -0
- /package/{src/db/adapters/mongo.ts → dist-types/db/adapters/mongo.d.ts} +0 -0
- /package/{src/db/adapters/prisma.ts → dist-types/db/adapters/prisma.d.ts} +0 -0
- /package/{src/db/adapters/typeorm.ts → dist-types/db/adapters/typeorm.d.ts} +0 -0
- /package/{src/utils/index.ts → dist-types/utils/index.d.ts} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Framework Integration
|
|
3
|
+
description: Mount the c15t consent backend in any JavaScript framework or runtime.
|
|
4
|
+
---
|
|
5
|
+
The c15t backend exposes a single handler with the signature `(request: Request) => Promise<Response>`. This is the standard Fetch API, so it works with any runtime that supports it — Node.js, Bun, Deno, and Cloudflare Workers.
|
|
6
|
+
|
|
7
|
+
## Bun
|
|
8
|
+
|
|
9
|
+
```ts title="server.ts"
|
|
10
|
+
import { c15t } from './c15t';
|
|
11
|
+
|
|
12
|
+
Bun.serve({
|
|
13
|
+
port: 3001,
|
|
14
|
+
fetch: c15t.handler,
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Next.js (App Router)
|
|
19
|
+
|
|
20
|
+
Create a catch-all API route that forwards requests to the handler:
|
|
21
|
+
|
|
22
|
+
```ts title="src/app/api/c15t/[[...path]]/route.ts"
|
|
23
|
+
import { c15t } from '@/lib/c15t';
|
|
24
|
+
|
|
25
|
+
const handler = c15t.handler;
|
|
26
|
+
|
|
27
|
+
export { handler as GET, handler as POST, handler as PUT, handler as PATCH, handler as DELETE };
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> ℹ️ **Info:**
|
|
31
|
+
> Use Next.js rewrites to proxy frontend requests through the same domain and avoid ad-blocker issues. See the Next.js Quickstart for the rewrite configuration.
|
|
32
|
+
|
|
33
|
+
## Hono
|
|
34
|
+
|
|
35
|
+
```ts title="server.ts"
|
|
36
|
+
import { Hono } from 'hono';
|
|
37
|
+
import { c15t } from './c15t';
|
|
38
|
+
|
|
39
|
+
const app = new Hono();
|
|
40
|
+
|
|
41
|
+
app.all('/api/c15t/*', (c) => c15t.handler(c.req.raw));
|
|
42
|
+
|
|
43
|
+
export default app;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Express
|
|
47
|
+
|
|
48
|
+
```ts title="server.ts"
|
|
49
|
+
import express from 'express';
|
|
50
|
+
import { c15t } from './c15t';
|
|
51
|
+
|
|
52
|
+
const app = express();
|
|
53
|
+
|
|
54
|
+
app.all('/api/c15t/*', async (req, res) => {
|
|
55
|
+
const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
|
56
|
+
const headers = new Headers();
|
|
57
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
58
|
+
if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const request = new Request(url, {
|
|
62
|
+
method: req.method,
|
|
63
|
+
headers,
|
|
64
|
+
body: ['GET', 'HEAD'].includes(req.method) ? undefined : req,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const response = await c15t.handler(request);
|
|
68
|
+
|
|
69
|
+
res.status(response.status);
|
|
70
|
+
response.headers.forEach((value, key) => res.setHeader(key, value));
|
|
71
|
+
res.send(await response.text());
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
app.listen(3001);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Fastify
|
|
78
|
+
|
|
79
|
+
```ts title="server.ts"
|
|
80
|
+
import Fastify from 'fastify';
|
|
81
|
+
import { c15t } from './c15t';
|
|
82
|
+
|
|
83
|
+
const app = Fastify();
|
|
84
|
+
|
|
85
|
+
app.all('/api/c15t/*', async (req, reply) => {
|
|
86
|
+
const url = `${req.protocol}://${req.hostname}${req.url}`;
|
|
87
|
+
const request = new Request(url, {
|
|
88
|
+
method: req.method,
|
|
89
|
+
headers: new Headers(req.headers as Record<string, string>),
|
|
90
|
+
body: ['GET', 'HEAD'].includes(req.method) ? undefined : JSON.stringify(req.body),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const response = await c15t.handler(request);
|
|
94
|
+
|
|
95
|
+
reply.status(response.status);
|
|
96
|
+
response.headers.forEach((value, key) => reply.header(key, value));
|
|
97
|
+
reply.send(await response.text());
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
app.listen({ port: 3001 });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Cloudflare Workers
|
|
104
|
+
|
|
105
|
+
```ts title="worker.ts"
|
|
106
|
+
import { c15t } from './c15t';
|
|
107
|
+
|
|
108
|
+
export default {
|
|
109
|
+
async fetch(request: Request, env: Env) {
|
|
110
|
+
return c15t.handler(request);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Deno
|
|
116
|
+
|
|
117
|
+
```ts title="server.ts"
|
|
118
|
+
import { c15t } from './c15t.ts';
|
|
119
|
+
|
|
120
|
+
Deno.serve({ port: 3001 }, c15t.handler);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## CORS
|
|
124
|
+
|
|
125
|
+
The backend automatically handles CORS based on the `trustedOrigins` you configure:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
c15tInstance({
|
|
129
|
+
trustedOrigins: [
|
|
130
|
+
'https://example.com',
|
|
131
|
+
'https://*.example.com', // wildcard subdomains
|
|
132
|
+
],
|
|
133
|
+
// ...
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Features:
|
|
138
|
+
|
|
139
|
+
* `www` variants are automatically allowed
|
|
140
|
+
* Wildcard subdomain matching with `*`
|
|
141
|
+
* `localhost` is allowed in development
|
|
142
|
+
* Preflight `OPTIONS` requests are handled automatically
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: IAB TCF Support
|
|
3
|
+
description: Enable IAB Transparency and Consent Framework (TCF) support in your self-hosted backend.
|
|
4
|
+
---
|
|
5
|
+
The c15t backend optionally supports [IAB TCF v2.3](https://iabeurope.eu/transparency-consent-framework/), including Global Vendor List (GVL) management and TC String generation.
|
|
6
|
+
|
|
7
|
+
## CMP Registration
|
|
8
|
+
|
|
9
|
+
[consent.io](https://consent.io) is pending validation as an IAB Europe-registered CMP for c15t. Once approved, when using consent.io as your hosted backend, the CMP ID will be automatically provided to clients — no additional configuration needed.
|
|
10
|
+
|
|
11
|
+
If you self-host and have your own CMP registration with IAB Europe, configure your CMP ID via `iab.cmpId`. This value is returned to clients in the `/init` response so they use the correct CMP identity in TC Strings.
|
|
12
|
+
|
|
13
|
+
> ℹ️ **Info:**
|
|
14
|
+
> A valid (non-zero) CMP ID is required for IAB TCF compliance. If neither the backend nor the client provides a CMP ID, IAB initialization will fail with an error.
|
|
15
|
+
>
|
|
16
|
+
> ℹ️ **Info:**
|
|
17
|
+
> If you heavily customize or build your own IAB banner or dialog (rather than using the default IABConsentBanner and IABConsentDialog components provided by c15t), you cannot use consent.io's CMP ID. You must register your own CMP with IAB Europe and configure your CMP ID via iab.cmpId.
|
|
18
|
+
|
|
19
|
+
## Enable IAB
|
|
20
|
+
|
|
21
|
+
```ts title="c15t.ts"
|
|
22
|
+
import { c15tInstance } from '@c15t/backend';
|
|
23
|
+
|
|
24
|
+
export const c15t = c15tInstance({
|
|
25
|
+
// ...
|
|
26
|
+
iab: {
|
|
27
|
+
enabled: true,
|
|
28
|
+
cmpId: 10, // your registered CMP ID (consent.io provides this automatically)
|
|
29
|
+
vendorIds: [755, 52, 69], // only include vendors you use
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The backend fetches the GVL from `https://gvl.consent.io` by default and caches it. The `/init` endpoint returns the filtered GVL and your CMP ID to the frontend.
|
|
35
|
+
|
|
36
|
+
## Custom GVL Endpoint
|
|
37
|
+
|
|
38
|
+
Point to your own GVL mirror:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
iab: {
|
|
42
|
+
enabled: true,
|
|
43
|
+
endpoint: 'https://your-gvl-mirror.com',
|
|
44
|
+
vendorIds: [755, 52, 69],
|
|
45
|
+
},
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Bundle GVL by Language
|
|
49
|
+
|
|
50
|
+
Pre-bundle the GVL to avoid runtime fetches:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import gvlEn from './gvl/en.json';
|
|
54
|
+
import gvlDe from './gvl/de.json';
|
|
55
|
+
|
|
56
|
+
iab: {
|
|
57
|
+
enabled: true,
|
|
58
|
+
bundled: {
|
|
59
|
+
en: gvlEn,
|
|
60
|
+
de: gvlDe,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> ℹ️ **Info:**
|
|
66
|
+
> Bundling all required GVL translations can significantly increase your deployment size. On serverless environments like Cloudflare Workers — which have strict bundle size limits — this may cause deployments to fail. Consider bundling only the languages you need, or use the GVL endpoint with a cache adapter instead.
|
|
67
|
+
|
|
68
|
+
## Custom Non-IAB Vendors
|
|
69
|
+
|
|
70
|
+
Add your own vendors alongside IAB-registered ones:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
iab: {
|
|
74
|
+
enabled: true,
|
|
75
|
+
vendorIds: [755],
|
|
76
|
+
customVendors: [
|
|
77
|
+
{
|
|
78
|
+
id: 'internal-analytics',
|
|
79
|
+
name: 'Our Analytics Platform',
|
|
80
|
+
privacyPolicyUrl: 'https://example.com/privacy',
|
|
81
|
+
purposes: [1, 8],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## TC String
|
|
88
|
+
|
|
89
|
+
When IAB TCF is enabled, consent records include a `tcString` field — the encoded TC String that can be passed to vendors. The frontend SDKs handle this automatically when using `mode: 'hosted'`.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Observability
|
|
3
|
+
description: Add logging, metrics, and tracing to your self-hosted c15t backend.
|
|
4
|
+
---
|
|
5
|
+
The c15t backend supports structured logging and opt-in OpenTelemetry integration for production observability.
|
|
6
|
+
|
|
7
|
+
## OpenTelemetry
|
|
8
|
+
|
|
9
|
+
Telemetry is disabled by default. To enable it, pass your own tracer and meter instances:
|
|
10
|
+
|
|
11
|
+
```ts title="c15t.ts"
|
|
12
|
+
import { c15tInstance } from '@c15t/backend';
|
|
13
|
+
import { trace, metrics } from '@opentelemetry/api';
|
|
14
|
+
|
|
15
|
+
export const c15t = c15tInstance({
|
|
16
|
+
// ...
|
|
17
|
+
telemetry: {
|
|
18
|
+
enabled: true,
|
|
19
|
+
tracer: trace.getTracer('consent-api'),
|
|
20
|
+
meter: metrics.getMeter('consent-api'),
|
|
21
|
+
defaultAttributes: {
|
|
22
|
+
'service.name': 'consent-api',
|
|
23
|
+
environment: 'production',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> ℹ️ **Info:**
|
|
30
|
+
> You need to set up your own OpenTelemetry SDK and exporter (e.g. Jaeger, Datadog, Grafana). The c15t backend creates spans and metrics using the instances you provide.
|
|
31
|
+
|
|
32
|
+
## Metrics
|
|
33
|
+
|
|
34
|
+
When telemetry is enabled, the following metrics are recorded:
|
|
35
|
+
|
|
36
|
+
### Business Metrics
|
|
37
|
+
|
|
38
|
+
|Metric|Type|Description|
|
|
39
|
+
|--|--|--|
|
|
40
|
+
|`consentCreated`|Counter|Consent record created (by type, jurisdiction)|
|
|
41
|
+
|`consentAccepted`|Counter|Consent accepted (by type)|
|
|
42
|
+
|`consentRejected`|Counter|Consent rejected (by type)|
|
|
43
|
+
|`subjectCreated`|Counter|New subject created|
|
|
44
|
+
|`subjectLinked`|Counter|Subject linked to external ID|
|
|
45
|
+
|`initCount`|Counter|`/init` endpoint called|
|
|
46
|
+
|
|
47
|
+
### HTTP Metrics
|
|
48
|
+
|
|
49
|
+
|Metric|Type|Description|
|
|
50
|
+
|--|--|--|
|
|
51
|
+
|`httpRequestDuration`|Histogram|Request duration (by method, route, status)|
|
|
52
|
+
|`httpRequestCount`|Counter|Total requests|
|
|
53
|
+
|`httpErrorCount`|Counter|Error responses|
|
|
54
|
+
|
|
55
|
+
### Database Metrics
|
|
56
|
+
|
|
57
|
+
|Metric|Type|Description|
|
|
58
|
+
|--|--|--|
|
|
59
|
+
|`dbQueryDuration`|Histogram|Query duration (by operation, entity)|
|
|
60
|
+
|`dbQueryCount`|Counter|Total queries|
|
|
61
|
+
|`dbErrorCount`|Counter|Query errors|
|
|
62
|
+
|
|
63
|
+
### Cache Metrics
|
|
64
|
+
|
|
65
|
+
|Metric|Type|Description|
|
|
66
|
+
|--|--|--|
|
|
67
|
+
|`cacheHit`|Counter|Cache hits (by layer)|
|
|
68
|
+
|`cacheMiss`|Counter|Cache misses (by layer)|
|
|
69
|
+
|`cacheLatency`|Histogram|Cache operation latency|
|
|
70
|
+
|
|
71
|
+
## Tracing
|
|
72
|
+
|
|
73
|
+
Every request creates a span with:
|
|
74
|
+
|
|
75
|
+
* HTTP method and route
|
|
76
|
+
* Response status code
|
|
77
|
+
* Tenant ID (if multi-tenant)
|
|
78
|
+
* API key authentication status
|
|
79
|
+
* Geo-location resolution
|
|
80
|
+
|
|
81
|
+
Child spans are created for database queries and cache operations.
|
|
82
|
+
|
|
83
|
+
## Logging
|
|
84
|
+
|
|
85
|
+
Configure the log level:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
c15tInstance({
|
|
89
|
+
// ...
|
|
90
|
+
logger: {
|
|
91
|
+
level: 'info', // debug, info, warn, error
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Logs are structured (JSON-compatible) and include trace context when telemetry is enabled, making it easy to correlate logs with traces.
|