@c15t/backend 1.0.5 → 1.2.0-canary.0
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 +33 -39
- package/.turbo/turbo-fmt.log +3 -3
- package/.turbo/turbo-test.log +531 -0
- package/coverage/coverage-final.json +84 -0
- package/coverage/coverage-summary.json +85 -0
- package/coverage/html/backend/index.html +116 -0
- package/coverage/html/backend/rslib.config.ts.html +415 -0
- package/coverage/html/backend/src/contracts/consent/index.html +161 -0
- package/coverage/html/backend/src/contracts/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/contracts/consent/post.contract.ts.html +559 -0
- package/coverage/html/backend/src/contracts/consent/show-banner.contract.ts.html +220 -0
- package/coverage/html/backend/src/contracts/consent/verify.contract.ts.html +463 -0
- package/coverage/html/backend/src/contracts/index.html +116 -0
- package/coverage/html/backend/src/contracts/index.ts.html +139 -0
- package/coverage/html/backend/src/contracts/meta/index.html +131 -0
- package/coverage/html/backend/src/contracts/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/contracts/meta/status.contract.ts.html +196 -0
- package/coverage/html/backend/src/contracts/shared/index.html +116 -0
- package/coverage/html/backend/src/contracts/shared/jurisdiction.schema.ts.html +175 -0
- package/coverage/html/backend/src/core.ts.html +1624 -0
- package/coverage/html/backend/src/handlers/consent/index.html +161 -0
- package/coverage/html/backend/src/handlers/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/handlers/consent/post.handler.ts.html +889 -0
- package/coverage/html/backend/src/handlers/consent/show-banner.handler.ts.html +535 -0
- package/coverage/html/backend/src/handlers/consent/verify.handler.ts.html +1000 -0
- package/coverage/html/backend/src/handlers/meta/index.html +131 -0
- package/coverage/html/backend/src/handlers/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/handlers/meta/status.handler.ts.html +226 -0
- package/coverage/html/backend/src/index.html +161 -0
- package/coverage/html/backend/src/init.ts.html +1018 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/processor.ts.html +544 -0
- package/coverage/html/backend/src/pkgs/api-router/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/telemetry.ts.html +334 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/cors.ts.html +304 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/index.html +131 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/ip.ts.html +361 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/field-factory.ts.html +709 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/id-generator.ts.html +256 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/index.html +161 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/superjson-utils.ts.html +136 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/zod-fields.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/create-hooks.ts.html +349 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/index.html +176 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-hooks.ts.html +358 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-many-hooks.ts.html +613 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/utils.ts.html +538 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/with-hooks-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapter-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts.html +2203 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts.html +670 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts.html +3634 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts.html +1417 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts.html +2071 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts.html +1834 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/test.ts.html +316 -0
- package/coverage/html/backend/src/pkgs/db-adapters/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/utils.ts.html +238 -0
- package/coverage/html/backend/src/pkgs/migrations/get-migration.ts.html +343 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/get-schema.ts.html +217 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/index.html +146 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-fields.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-tables.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/migrations/index.html +176 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-builders.ts.html +595 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-execution.ts.html +301 -0
- package/coverage/html/backend/src/pkgs/migrations/schema-comparison.ts.html +694 -0
- package/coverage/html/backend/src/pkgs/migrations/type-mapping.ts.html +817 -0
- package/coverage/html/backend/src/pkgs/results/core/error-class.ts.html +976 -0
- package/coverage/html/backend/src/pkgs/results/core/error-codes.ts.html +703 -0
- package/coverage/html/backend/src/pkgs/results/core/index.html +146 -0
- package/coverage/html/backend/src/pkgs/results/core/tracing.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/results/create-telemetry-options.ts.html +271 -0
- package/coverage/html/backend/src/pkgs/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/orpc-error-handler.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/results/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/results/recovery-utils.ts.html +628 -0
- package/coverage/html/backend/src/pkgs/results/results/result-helpers.ts.html +1234 -0
- package/coverage/html/backend/src/pkgs/utils/env.ts.html +337 -0
- package/coverage/html/backend/src/pkgs/utils/index.html +146 -0
- package/coverage/html/backend/src/pkgs/utils/logger.ts.html +199 -0
- package/coverage/html/backend/src/pkgs/utils/url.ts.html +400 -0
- package/coverage/html/backend/src/router.ts.html +109 -0
- package/coverage/html/backend/src/schema/audit-log/index.html +146 -0
- package/coverage/html/backend/src/schema/audit-log/registry.ts.html +436 -0
- package/coverage/html/backend/src/schema/audit-log/schema.ts.html +223 -0
- package/coverage/html/backend/src/schema/audit-log/table.ts.html +640 -0
- package/coverage/html/backend/src/schema/consent/index.html +146 -0
- package/coverage/html/backend/src/schema/consent/registry.ts.html +616 -0
- package/coverage/html/backend/src/schema/consent/schema.ts.html +238 -0
- package/coverage/html/backend/src/schema/consent/table.ts.html +748 -0
- package/coverage/html/backend/src/schema/consent-policy/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-policy/registry.ts.html +1063 -0
- package/coverage/html/backend/src/schema/consent-policy/schema.ts.html +265 -0
- package/coverage/html/backend/src/schema/consent-policy/table.ts.html +535 -0
- package/coverage/html/backend/src/schema/consent-purpose/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-purpose/registry.ts.html +589 -0
- package/coverage/html/backend/src/schema/consent-purpose/schema.ts.html +259 -0
- package/coverage/html/backend/src/schema/consent-purpose/table.ts.html +547 -0
- package/coverage/html/backend/src/schema/consent-record/index.html +131 -0
- package/coverage/html/backend/src/schema/consent-record/schema.ts.html +211 -0
- package/coverage/html/backend/src/schema/consent-record/table.ts.html +457 -0
- package/coverage/html/backend/src/schema/create-registry.ts.html +148 -0
- package/coverage/html/backend/src/schema/definition.ts.html +685 -0
- package/coverage/html/backend/src/schema/domain/index.html +146 -0
- package/coverage/html/backend/src/schema/domain/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/domain/schema.ts.html +214 -0
- package/coverage/html/backend/src/schema/domain/table.ts.html +496 -0
- package/coverage/html/backend/src/schema/index.html +146 -0
- package/coverage/html/backend/src/schema/schemas.ts.html +166 -0
- package/coverage/html/backend/src/schema/subject/index.html +146 -0
- package/coverage/html/backend/src/schema/subject/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/subject/schema.ts.html +208 -0
- package/coverage/html/backend/src/schema/subject/table.ts.html +499 -0
- package/coverage/html/backend/src/server.ts.html +475 -0
- package/coverage/html/backend/src/testing/contract-testing.ts.html +1348 -0
- package/coverage/html/backend/src/testing/index.html +116 -0
- package/coverage/html/base.css +224 -0
- package/coverage/html/block-navigation.js +87 -0
- package/coverage/html/favicon.png +0 -0
- package/coverage/html/index.html +626 -0
- package/coverage/html/prettify.css +1 -0
- package/coverage/html/prettify.js +2 -0
- package/coverage/html/sort-arrow-sprite.png +0 -0
- package/coverage/html/sorter.js +196 -0
- package/dist/contracts/consent/index.d.ts +401 -0
- package/dist/contracts/consent/index.d.ts.map +1 -0
- package/dist/contracts/consent/index.test.d.ts +2 -0
- package/dist/contracts/consent/index.test.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.d.ts +212 -0
- package/dist/contracts/consent/post.contract.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.test.d.ts +2 -0
- package/dist/contracts/consent/post.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.d.ts +45 -0
- package/dist/contracts/consent/show-banner.contract.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts +2 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.d.ts +147 -0
- package/dist/contracts/consent/verify.contract.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.test.d.ts +2 -0
- package/dist/contracts/consent/verify.contract.test.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +963 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.d.ts +78 -0
- package/dist/contracts/meta/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.test.d.ts +2 -0
- package/dist/contracts/meta/index.test.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.d.ts +77 -0
- package/dist/contracts/meta/status.contract.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.test.d.ts +2 -0
- package/dist/contracts/meta/status.contract.test.d.ts.map +1 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts +24 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts.map +1 -0
- package/dist/core.cjs +3584 -0
- package/dist/core.d.ts +533 -76
- package/dist/core.d.ts.map +1 -1
- package/dist/{index.js → core.js} +1163 -1286
- package/dist/handlers/consent/index.d.ts +401 -0
- package/dist/handlers/consent/index.d.ts.map +1 -0
- package/dist/handlers/consent/post.handler.d.ts +234 -0
- package/dist/handlers/consent/post.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.d.ts +57 -0
- package/dist/handlers/consent/show-banner.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts +2 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts.map +1 -0
- package/dist/handlers/consent/verify.handler.d.ts +169 -0
- package/dist/handlers/consent/verify.handler.d.ts.map +1 -0
- package/dist/handlers/meta/index.d.ts +78 -0
- package/dist/handlers/meta/index.d.ts.map +1 -0
- package/dist/handlers/meta/status.handler.d.ts +76 -0
- package/dist/handlers/meta/status.handler.d.ts.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/pkgs/api-router/hooks/processor.d.ts.map +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts.map +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts.map +1 -1
- package/dist/pkgs/data-model/fields/field-types.d.ts +1 -1
- package/dist/pkgs/data-model/fields/zod-fields.d.ts +32 -32
- package/dist/pkgs/data-model/index.cjs +1433 -1799
- package/dist/pkgs/data-model/index.js +20 -385
- package/dist/pkgs/data-model/schema/index.cjs +1402 -1768
- package/dist/pkgs/data-model/schema/index.js +20 -385
- package/dist/pkgs/db-adapters/adapter-factory.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapter-factory.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts +4 -4
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/dialect.d.ts +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/index.cjs +31 -153
- package/dist/pkgs/db-adapters/index.js +31 -153
- package/dist/pkgs/migrations/get-schema/get-schema.d.ts +2 -2
- package/dist/pkgs/migrations/get-schema/index.d.ts +1 -1
- package/dist/pkgs/migrations/index.cjs +30 -153
- package/dist/pkgs/migrations/index.js +30 -153
- package/dist/pkgs/migrations/schema-comparison.d.ts.map +1 -1
- package/dist/pkgs/results/core/error-class.d.ts +23 -21
- package/dist/pkgs/results/core/error-class.d.ts.map +1 -1
- package/dist/pkgs/results/index.cjs +17 -150
- package/dist/pkgs/results/index.d.ts +0 -3
- package/dist/pkgs/results/index.d.ts.map +1 -1
- package/dist/pkgs/results/index.js +17 -138
- package/dist/pkgs/results/orpc-error-handler.d.ts +65 -0
- package/dist/pkgs/results/orpc-error-handler.d.ts.map +1 -0
- package/dist/pkgs/results/types.d.ts +7 -7
- package/dist/pkgs/results/types.d.ts.map +1 -1
- package/dist/pkgs/types/context.d.ts +15 -4
- package/dist/pkgs/types/context.d.ts.map +1 -1
- package/dist/pkgs/types/endpoints.d.ts +3 -4
- package/dist/pkgs/types/endpoints.d.ts.map +1 -1
- package/dist/pkgs/types/options.d.ts +2 -3
- package/dist/pkgs/types/options.d.ts.map +1 -1
- package/dist/pkgs/types/plugins.d.ts +2 -3
- package/dist/pkgs/types/plugins.d.ts.map +1 -1
- package/dist/pkgs/utils/index.d.ts +1 -0
- package/dist/pkgs/utils/index.d.ts.map +1 -1
- package/dist/pkgs/utils/logger.d.ts +16 -0
- package/dist/pkgs/utils/logger.d.ts.map +1 -0
- package/dist/router.cjs +1213 -0
- package/dist/router.d.ts +480 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1169 -0
- package/dist/schema/audit-log/table.d.ts +1 -1
- package/dist/schema/consent/table.d.ts +1 -1
- package/dist/schema/consent-policy/registry.d.ts +12 -12
- package/dist/schema/consent-policy/schema.d.ts +6 -6
- package/dist/schema/consent-policy/table.d.ts +7 -7
- package/dist/schema/consent-purpose/registry.d.ts +6 -6
- package/dist/schema/consent-purpose/schema.d.ts +6 -6
- package/dist/schema/consent-purpose/table.d.ts +7 -7
- package/dist/schema/consent-record/table.d.ts +1 -1
- package/dist/schema/create-registry.d.ts +32 -32
- package/dist/schema/definition.d.ts +19 -19
- package/dist/schema/domain/registry.d.ts +10 -10
- package/dist/schema/domain/schema.d.ts +5 -5
- package/dist/schema/domain/table.d.ts +6 -6
- package/dist/schema/index.cjs +1409 -1775
- package/dist/schema/index.js +20 -385
- package/dist/schema/schemas.d.ts +19 -19
- package/dist/schema/subject/registry.d.ts +4 -4
- package/dist/schema/subject/schema.d.ts +2 -2
- package/dist/schema/subject/table.d.ts +3 -3
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/testing/contract-testing.d.ts +37 -0
- package/dist/testing/contract-testing.d.ts.map +1 -0
- package/dist/types/context.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/options.d.ts +33 -2
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +3 -4
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +22 -30
- package/rslib.config.ts +2 -5
- package/src/contracts/consent/index.test.ts +5 -0
- package/src/contracts/consent/index.ts +9 -0
- package/src/contracts/consent/post.contract.test.ts +526 -0
- package/src/contracts/consent/post.contract.ts +160 -0
- package/src/contracts/consent/show-banner.contract.test.ts +214 -0
- package/src/contracts/consent/show-banner.contract.ts +45 -0
- package/src/contracts/consent/verify.contract.test.ts +185 -0
- package/src/contracts/consent/verify.contract.ts +126 -0
- package/src/contracts/index.ts +18 -0
- package/src/contracts/meta/index.test.ts +5 -0
- package/src/contracts/meta/index.ts +5 -0
- package/src/contracts/meta/status.contract.test.ts +338 -0
- package/src/contracts/meta/status.contract.ts +37 -0
- package/src/contracts/shared/jurisdiction.schema.ts +30 -0
- package/src/core.ts +451 -159
- package/src/handlers/consent/index.ts +9 -0
- package/src/handlers/consent/post.handler.ts +273 -0
- package/src/handlers/consent/show-banner.handler.test.ts +148 -0
- package/src/handlers/consent/show-banner.handler.ts +150 -0
- package/src/handlers/consent/verify.handler.ts +305 -0
- package/src/handlers/meta/index.ts +5 -0
- package/src/handlers/meta/status.handler.ts +47 -0
- package/src/init.ts +8 -5
- package/src/pkgs/api-router/hooks/__tests__/processor.test.ts +6 -0
- package/src/pkgs/api-router/hooks/processor.ts +2 -0
- package/src/pkgs/api-router/types/router-props.ts +1 -1
- package/src/pkgs/api-router/utils/cors.ts +1 -1
- package/src/pkgs/data-model/fields/field-types.ts +1 -1
- package/src/pkgs/data-model/fields/id-generator.ts +1 -1
- package/src/pkgs/db-adapters/README.md +3 -3
- package/src/pkgs/db-adapters/adapter-factory.ts +8 -4
- package/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts +13 -13
- package/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/postgres.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/sqlite.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts +2 -2
- package/src/pkgs/migrations/get-migration.ts +3 -3
- package/src/pkgs/migrations/get-schema/get-schema.ts +2 -2
- package/src/pkgs/migrations/get-schema/index.ts +1 -1
- package/src/pkgs/migrations/migration-builders.ts +2 -2
- package/src/pkgs/migrations/migration-execution.ts +2 -2
- package/src/pkgs/migrations/schema-comparison.ts +5 -4
- package/src/pkgs/results/__tests__/error-class.test.ts +8 -7
- package/src/pkgs/results/core/error-class.ts +31 -43
- package/src/pkgs/results/index.ts +0 -10
- package/src/pkgs/results/orpc-error-handler.ts +137 -0
- package/src/pkgs/results/types.ts +8 -7
- package/src/pkgs/types/context.ts +18 -4
- package/src/pkgs/types/endpoints.ts +3 -5
- package/src/pkgs/types/options.ts +2 -3
- package/src/pkgs/types/plugins.ts +2 -3
- package/src/pkgs/utils/index.ts +1 -0
- package/src/pkgs/utils/logger.ts +38 -0
- package/src/router.ts +8 -0
- package/src/schema/audit-log/table.ts +1 -1
- package/src/schema/consent/table.ts +1 -1
- package/src/schema/consent-policy/table.ts +1 -1
- package/src/schema/consent-purpose/table.ts +1 -1
- package/src/schema/consent-record/table.ts +1 -1
- package/src/schema/definition.ts +2 -2
- package/src/schema/domain/table.ts +1 -1
- package/src/schema/subject/table.ts +1 -1
- package/src/server.ts +130 -0
- package/src/testing/contract-testing.ts +437 -0
- package/src/types/context.ts +1 -1
- package/src/types/index.ts +2 -2
- package/src/types/options.ts +38 -2
- package/src/types/plugins.ts +3 -4
- package/dist/index.cjs +0 -3701
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/init.test.d.ts +0 -2
- package/dist/init.test.d.ts.map +0 -1
- package/dist/integrations/cloudflare.cjs +0 -312
- package/dist/integrations/cloudflare.d.ts +0 -32
- package/dist/integrations/cloudflare.d.ts.map +0 -1
- package/dist/integrations/cloudflare.js +0 -278
- package/dist/integrations/next.cjs +0 -276
- package/dist/integrations/next.d.ts +0 -68
- package/dist/integrations/next.d.ts.map +0 -1
- package/dist/integrations/next.js +0 -239
- package/dist/integrations/node.cjs +0 -257
- package/dist/integrations/node.d.ts +0 -29
- package/dist/integrations/node.d.ts.map +0 -1
- package/dist/integrations/node.js +0 -223
- package/dist/pkgs/api-router/index.d.ts +0 -9
- package/dist/pkgs/api-router/index.d.ts.map +0 -1
- package/dist/pkgs/api-router/utils/define-route.d.ts +0 -87
- package/dist/pkgs/api-router/utils/define-route.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/integration.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/integration.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/types.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/types.test.d.ts.map +0 -1
- package/dist/pkgs/logger/console-formatter.d.ts +0 -56
- package/dist/pkgs/logger/console-formatter.d.ts.map +0 -1
- package/dist/pkgs/logger/index.cjs +0 -240
- package/dist/pkgs/logger/index.d.ts +0 -35
- package/dist/pkgs/logger/index.d.ts.map +0 -1
- package/dist/pkgs/logger/index.js +0 -185
- package/dist/pkgs/logger/log-levels.d.ts +0 -29
- package/dist/pkgs/logger/log-levels.d.ts.map +0 -1
- package/dist/pkgs/logger/logger-factory.d.ts +0 -42
- package/dist/pkgs/logger/logger-factory.d.ts.map +0 -1
- package/dist/pkgs/logger/result-logging.d.ts +0 -71
- package/dist/pkgs/logger/result-logging.d.ts.map +0 -1
- package/dist/pkgs/logger/telemetry.d.ts +0 -14
- package/dist/pkgs/logger/telemetry.d.ts.map +0 -1
- package/dist/pkgs/logger/types.d.ts +0 -121
- package/dist/pkgs/logger/types.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/h3-integration.d.ts +0 -52
- package/dist/pkgs/results/h3-integration.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts +0 -101
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts +0 -89
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts.map +0 -1
- package/dist/response-types.d.ts +0 -19
- package/dist/response-types.d.ts.map +0 -1
- package/dist/routes/__test__/index.test.d.ts +0 -17
- package/dist/routes/__test__/index.test.d.ts.map +0 -1
- package/dist/routes/__test__/set-consent.test.d.ts +0 -2
- package/dist/routes/__test__/set-consent.test.d.ts.map +0 -1
- package/dist/routes/__test__/show-consent-banner.test.d.ts +0 -2
- package/dist/routes/__test__/show-consent-banner.test.d.ts.map +0 -1
- package/dist/routes/__test__/status.test.d.ts +0 -2
- package/dist/routes/__test__/status.test.d.ts.map +0 -1
- package/dist/routes/__test__/verify-consent.test.d.ts +0 -2
- package/dist/routes/__test__/verify-consent.test.d.ts.map +0 -1
- package/dist/routes/index.d.ts +0 -3
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/set-consent.d.ts +0 -89
- package/dist/routes/set-consent.d.ts.map +0 -1
- package/dist/routes/show-consent-banner.d.ts +0 -15
- package/dist/routes/show-consent-banner.d.ts.map +0 -1
- package/dist/routes/status.d.ts +0 -44
- package/dist/routes/status.d.ts.map +0 -1
- package/dist/routes/types.d.ts +0 -7
- package/dist/routes/types.d.ts.map +0 -1
- package/dist/routes/verify-consent.d.ts +0 -38
- package/dist/routes/verify-consent.d.ts.map +0 -1
- package/src/docs/ADVANCED_JSON_HANDLING.md +0 -99
- package/src/docs/neverthrow.md +0 -171
- package/src/index.ts +0 -34
- package/src/init.test.ts +0 -219
- package/src/integrations/cloudflare.ts +0 -269
- package/src/integrations/next.ts +0 -204
- package/src/integrations/node.ts +0 -141
- package/src/pkgs/api-router/index.ts +0 -148
- package/src/pkgs/api-router/types/h3.d.ts +0 -42
- package/src/pkgs/api-router/utils/define-route.ts +0 -410
- package/src/pkgs/logger/README.md +0 -213
- package/src/pkgs/logger/__tests__/console-formatter.test.ts +0 -67
- package/src/pkgs/logger/__tests__/integration.test.ts +0 -184
- package/src/pkgs/logger/__tests__/log-levels.test.ts +0 -77
- package/src/pkgs/logger/__tests__/logger-factory.test.ts +0 -156
- package/src/pkgs/logger/__tests__/result-logging.test.ts +0 -209
- package/src/pkgs/logger/__tests__/types.test.ts +0 -94
- package/src/pkgs/logger/console-formatter.ts +0 -75
- package/src/pkgs/logger/doc.md +0 -569
- package/src/pkgs/logger/index.ts +0 -59
- package/src/pkgs/logger/log-levels.ts +0 -46
- package/src/pkgs/logger/logger-factory.ts +0 -121
- package/src/pkgs/logger/result-logging.ts +0 -134
- package/src/pkgs/logger/telemetry.ts +0 -96
- package/src/pkgs/logger/types.ts +0 -138
- package/src/pkgs/results/__tests__/retrieval-pipeline.test.ts +0 -157
- package/src/pkgs/results/__tests__/validation-pipeline.test.ts +0 -151
- package/src/pkgs/results/h3-integration.ts +0 -142
- package/src/pkgs/results/pipeline/retrieval-pipeline.ts +0 -188
- package/src/pkgs/results/pipeline/validation-pipeline.ts +0 -164
- package/src/plugins/.keep +0 -0
- package/src/response-types.ts +0 -29
- package/src/routes/__test__/index.test.ts +0 -112
- package/src/routes/__test__/set-consent.test.ts +0 -242
- package/src/routes/__test__/show-consent-banner.test.ts +0 -98
- package/src/routes/__test__/status.test.ts +0 -64
- package/src/routes/__test__/verify-consent.test.ts +0 -266
- package/src/routes/index.ts +0 -12
- package/src/routes/set-consent.ts +0 -249
- package/src/routes/show-consent-banner.ts +0 -131
- package/src/routes/status.ts +0 -61
- package/src/routes/types.ts +0 -7
- package/src/routes/verify-consent.ts +0 -206
package/src/core.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@doubletie/logger';
|
|
2
|
+
import { OpenAPIGenerator } from '@orpc/openapi';
|
|
3
|
+
import { OpenAPIHandler } from '@orpc/openapi/fetch';
|
|
4
|
+
import { CORSPlugin } from '@orpc/server/plugins';
|
|
5
|
+
import { ZodToJsonSchemaConverter } from '@orpc/zod';
|
|
6
|
+
import { DoubleTieError, ERROR_CODES } from '~/pkgs/results';
|
|
1
7
|
import type { C15TContext, C15TOptions, C15TPlugin } from '~/types';
|
|
8
|
+
import packageJson from '../package.json';
|
|
2
9
|
import { init } from './init';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { withRequestSpan } from './pkgs/api-router/telemetry';
|
|
11
|
+
import { isOriginTrusted } from './pkgs/api-router/utils/cors';
|
|
12
|
+
import { getIp } from './pkgs/api-router/utils/ip';
|
|
13
|
+
import { router } from './router';
|
|
14
|
+
/**
|
|
15
|
+
* Type representing an API route
|
|
16
|
+
*/
|
|
17
|
+
export type Route = {
|
|
18
|
+
path: string;
|
|
19
|
+
method: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
24
|
* Interface representing a configured c15t consent management instance.
|
|
@@ -21,8 +30,7 @@ import type { Route } from './routes/types';
|
|
|
21
30
|
* management system. It includes methods for handling requests, accessing API
|
|
22
31
|
* endpoints, and managing the system's configuration.
|
|
23
32
|
*
|
|
24
|
-
* All asynchronous operations return
|
|
25
|
-
* consistent error handling across the system.
|
|
33
|
+
* All asynchronous operations return Promises for consistent error handling.
|
|
26
34
|
*
|
|
27
35
|
* @example
|
|
28
36
|
* ```typescript
|
|
@@ -40,196 +48,480 @@ export interface C15TInstance<PluginTypes extends C15TPlugin[] = C15TPlugin[]> {
|
|
|
40
48
|
* Processes incoming HTTP requests and routes them to appropriate handlers.
|
|
41
49
|
*
|
|
42
50
|
* @param request - The incoming web request
|
|
43
|
-
* @returns A Promise
|
|
44
|
-
*
|
|
45
|
-
* @throws Never - All errors are captured in the Result type
|
|
51
|
+
* @returns A Promise containing the HTTP response
|
|
46
52
|
*
|
|
47
53
|
* @example
|
|
48
54
|
* ```typescript
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
55
|
+
* try {
|
|
56
|
+
* const response = await instance.handler(request);
|
|
57
|
+
* sendResponse(response);
|
|
58
|
+
* } catch (error) {
|
|
59
|
+
* handleError(error);
|
|
60
|
+
* }
|
|
54
61
|
* ```
|
|
55
62
|
*/
|
|
56
|
-
handler: (request: Request) => Promise<
|
|
63
|
+
handler: (request: Request) => Promise<Response>;
|
|
57
64
|
|
|
58
65
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @returns A Promise resolving to a Result containing the available API endpoints
|
|
62
|
-
*
|
|
63
|
-
* @throws Never - All errors are captured in the Result type
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const endpoints = await instance.getApi();
|
|
68
|
-
* endpoints.map(
|
|
69
|
-
* apis => console.log('Available endpoints:', apis),
|
|
70
|
-
* error => console.error('Failed to get endpoints:', error)
|
|
71
|
-
* );
|
|
72
|
-
* ```
|
|
66
|
+
* The configuration options used for this instance.
|
|
73
67
|
*/
|
|
74
|
-
|
|
68
|
+
options: C15TOptions<PluginTypes>;
|
|
75
69
|
|
|
76
70
|
/**
|
|
77
|
-
*
|
|
71
|
+
* Access to the underlying context.
|
|
78
72
|
*/
|
|
79
|
-
|
|
73
|
+
$context: Promise<C15TContext>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Access to the router for direct usage.
|
|
77
|
+
*/
|
|
78
|
+
router: typeof router;
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
|
-
*
|
|
81
|
+
* Generates and returns the OpenAPI specification as a JSON object.
|
|
83
82
|
*
|
|
84
|
-
* @
|
|
85
|
-
* The context is wrapped in a Result type to ensure error handling
|
|
86
|
-
* consistency. Access should be handled using Result pattern methods.
|
|
83
|
+
* @returns A Promise containing the OpenAPI specification
|
|
87
84
|
*/
|
|
88
|
-
|
|
85
|
+
getOpenAPISpec: () => Promise<Record<string, unknown>>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns an HTML document with the API documentation UI.
|
|
89
|
+
*
|
|
90
|
+
* @returns An HTML string with the API reference UI
|
|
91
|
+
*/
|
|
92
|
+
getDocsUI: () => string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Define middleware context interface
|
|
96
|
+
interface MiddlewareContext {
|
|
97
|
+
logger?: Logger;
|
|
98
|
+
adapter: unknown;
|
|
99
|
+
registry: unknown;
|
|
100
|
+
generateId: unknown;
|
|
101
|
+
ipAddress?: string;
|
|
102
|
+
origin?: string;
|
|
103
|
+
trustedOrigin?: boolean;
|
|
104
|
+
path?: string;
|
|
105
|
+
method?: string;
|
|
106
|
+
headers?: Headers;
|
|
107
|
+
userAgent?: string;
|
|
108
|
+
[key: string]: unknown;
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
/**
|
|
92
112
|
* Creates a new c15t consent management instance.
|
|
93
113
|
*
|
|
94
|
-
*
|
|
95
|
-
* @typeParam ConfigOptions - Configuration options extending the base C15TOptions
|
|
96
|
-
*
|
|
97
|
-
* @param options - Configuration options for the consent management system
|
|
98
|
-
* @returns A configured C15TInstance ready for use
|
|
99
|
-
*
|
|
100
|
-
* @remarks
|
|
101
|
-
* This is the main factory function for creating c15t instances. It initializes
|
|
102
|
-
* the consent management system with the provided configuration and sets up all
|
|
103
|
-
* necessary components including:
|
|
104
|
-
*
|
|
105
|
-
* - Database adapters
|
|
106
|
-
* - Plugin system
|
|
107
|
-
* - Request handlers
|
|
108
|
-
* - API endpoints
|
|
109
|
-
* - CORS configuration
|
|
110
|
-
*
|
|
111
|
-
* All async operations use the Result pattern for error handling, ensuring
|
|
112
|
-
* that errors are handled consistently throughout the system.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* Basic initialization:
|
|
116
|
-
* ```typescript
|
|
117
|
-
* import { c15tInstance } from '@c15t/backend';
|
|
118
|
-
*
|
|
119
|
-
* const manager = c15tInstance({
|
|
120
|
-
* storage: memoryAdapter()
|
|
121
|
-
* });
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* Advanced initialization with type parameters:
|
|
126
|
-
* ```typescript
|
|
127
|
-
* type MyPlugins = [typeof geoPlugin, typeof analyticsPlugin];
|
|
128
|
-
*
|
|
129
|
-
* const c15t = c15tInstance<MyPlugins>({
|
|
130
|
-
* storage: kyselyAdapter(db),
|
|
131
|
-
* plugins: [geoPlugin(), analyticsPlugin()]
|
|
132
|
-
* });
|
|
133
|
-
* ```
|
|
114
|
+
* This version provides a unified handler that works with oRPC to handle requests.
|
|
134
115
|
*/
|
|
135
116
|
export const c15tInstance = <PluginTypes extends C15TPlugin[] = C15TPlugin[]>(
|
|
136
117
|
options: C15TOptions<PluginTypes>
|
|
137
|
-
)
|
|
138
|
-
// Initialize context
|
|
118
|
+
) => {
|
|
119
|
+
// Initialize context
|
|
139
120
|
const contextPromise = init(options);
|
|
140
|
-
|
|
121
|
+
|
|
122
|
+
const corsOptions = options.trustedOrigins
|
|
123
|
+
? {
|
|
124
|
+
// When specific origins are configured
|
|
125
|
+
origin: options.trustedOrigins.includes('*')
|
|
126
|
+
? '*' // If '*' is in the list, allow all origins
|
|
127
|
+
: options.trustedOrigins, // Otherwise use the specific list
|
|
128
|
+
credentials: true, // Allow cookies/auth headers
|
|
129
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
|
|
130
|
+
allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-ID'],
|
|
131
|
+
maxAge: 86400,
|
|
132
|
+
}
|
|
133
|
+
: {
|
|
134
|
+
// Default configuration when no origins specified
|
|
135
|
+
origin: '*', // Allow all origins
|
|
136
|
+
credentials: false, // Can't use credentials with wildcard origin
|
|
137
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
|
|
138
|
+
allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-ID'],
|
|
139
|
+
maxAge: 86400,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Create the oRPC handler with plugins
|
|
143
|
+
const rpcHandler = new OpenAPIHandler(router, {
|
|
144
|
+
plugins: [new CORSPlugin(corsOptions)],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Initialize OpenAPI generator with schema converters
|
|
148
|
+
const openAPIGenerator = new OpenAPIGenerator({
|
|
149
|
+
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Set up OpenAPI configuration with defaults
|
|
153
|
+
const openApiConfig = {
|
|
154
|
+
enabled: true,
|
|
155
|
+
specPath: '/spec.json',
|
|
156
|
+
docsPath: '/docs',
|
|
157
|
+
...(options.openapi || {}),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Default OpenAPI options
|
|
161
|
+
const defaultOpenApiOptions = {
|
|
162
|
+
info: {
|
|
163
|
+
title: options.appName || 'c15t API',
|
|
164
|
+
version: packageJson.version,
|
|
165
|
+
description: 'API for consent management',
|
|
166
|
+
},
|
|
167
|
+
servers: [{ url: '/' }],
|
|
168
|
+
security: [{ bearerAuth: [] }],
|
|
169
|
+
// components: {
|
|
170
|
+
// securitySchemes: {
|
|
171
|
+
// bearerAuth: {
|
|
172
|
+
// type: 'http',
|
|
173
|
+
// scheme: 'bearer',
|
|
174
|
+
// },
|
|
175
|
+
// },
|
|
176
|
+
// },
|
|
177
|
+
};
|
|
141
178
|
|
|
142
179
|
/**
|
|
143
|
-
*
|
|
180
|
+
* Process IP tracking and add it to the context
|
|
144
181
|
*/
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
182
|
+
const processIp = (request: Request, context: MiddlewareContext) => {
|
|
183
|
+
const ip = getIp(request, options);
|
|
184
|
+
if (ip) {
|
|
185
|
+
context.ipAddress = ip;
|
|
186
|
+
}
|
|
187
|
+
return context;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Process CORS validation and add it to the context
|
|
192
|
+
*/
|
|
193
|
+
const processCors = (request: Request, context: MiddlewareContext) => {
|
|
194
|
+
const origin = request.headers.get('origin');
|
|
195
|
+
if (origin && options.trustedOrigins) {
|
|
196
|
+
const trusted = isOriginTrusted(
|
|
197
|
+
origin,
|
|
198
|
+
options.trustedOrigins,
|
|
199
|
+
context.logger
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
context.origin = origin;
|
|
203
|
+
context.trustedOrigin = trusted;
|
|
204
|
+
}
|
|
205
|
+
return context;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Add telemetry tracking to the context
|
|
210
|
+
*/
|
|
211
|
+
const processTelemetry = (request: Request, context: MiddlewareContext) => {
|
|
212
|
+
const url = new URL(request.url);
|
|
213
|
+
const path = url.pathname;
|
|
214
|
+
const method = request.method;
|
|
215
|
+
|
|
216
|
+
// Add a span to the context that can be accessed by handlers
|
|
217
|
+
withRequestSpan(
|
|
218
|
+
method,
|
|
219
|
+
path,
|
|
220
|
+
async () => {
|
|
221
|
+
// This callback is intentionally empty - we're only creating the span
|
|
222
|
+
// The span automatically tracks the current execution context and
|
|
223
|
+
// will be associated with the request processing that follows
|
|
224
|
+
},
|
|
225
|
+
options
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
// Add path and method to context for easier access
|
|
229
|
+
context.path = path;
|
|
230
|
+
context.method = method;
|
|
231
|
+
context.headers = request.headers;
|
|
232
|
+
context.userAgent = request.headers.get('user-agent') || undefined;
|
|
233
|
+
|
|
234
|
+
return context;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Generate the OpenAPI specification document
|
|
239
|
+
*/
|
|
240
|
+
const getOpenAPISpec = (async (): Promise<Record<string, unknown>> => {
|
|
241
|
+
// Memoise once per process
|
|
242
|
+
if (getOpenAPISpec.cached) {
|
|
243
|
+
return getOpenAPISpec.cached;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Start with our defaults
|
|
247
|
+
const mergedOptions = { ...defaultOpenApiOptions };
|
|
248
|
+
|
|
249
|
+
// If user provided options, merge them with defaults
|
|
250
|
+
if (openApiConfig.options) {
|
|
251
|
+
// biome-ignore lint: OpenAPI options are dynamically merged
|
|
252
|
+
const userOptions = openApiConfig.options as Record<string, any>;
|
|
253
|
+
|
|
254
|
+
// Handle nested info object (title, description, version) specially
|
|
255
|
+
if (userOptions.info) {
|
|
256
|
+
mergedOptions.info = {
|
|
257
|
+
...defaultOpenApiOptions.info,
|
|
258
|
+
...userOptions.info,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// For all other top-level properties, override defaults with user settings
|
|
263
|
+
for (const [key, value] of Object.entries(userOptions)) {
|
|
264
|
+
if (key !== 'info') {
|
|
265
|
+
(mergedOptions as Record<string, unknown>)[key] = value;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// We need to cast to the expected type due to incompatibilities between the types
|
|
271
|
+
// This is safe as we control the options format and it's compatible with what the generator expects
|
|
272
|
+
const spec = await openAPIGenerator.generate(
|
|
273
|
+
router,
|
|
274
|
+
mergedOptions as Record<string, unknown>
|
|
275
|
+
);
|
|
276
|
+
getOpenAPISpec.cached = spec;
|
|
277
|
+
return spec;
|
|
278
|
+
}) as (() => Promise<Record<string, unknown>>) & {
|
|
279
|
+
cached?: Record<string, unknown>;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Generate the default UI for API documentation
|
|
284
|
+
*/
|
|
285
|
+
const getDocsUI = () => {
|
|
286
|
+
// If a custom template is provided, use it
|
|
287
|
+
if (openApiConfig.customUiTemplate) {
|
|
288
|
+
return openApiConfig.customUiTemplate;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Otherwise, return the default Scalar UI
|
|
292
|
+
return `
|
|
293
|
+
<!doctype html>
|
|
294
|
+
<html>
|
|
295
|
+
<head>
|
|
296
|
+
<title>${options.appName || 'c15t API'} Documentation</title>
|
|
297
|
+
<meta charset="utf-8" />
|
|
298
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
299
|
+
<link rel="icon" type="image/svg+xml" href="https://orpc.unnoq.com/icon.svg" />
|
|
300
|
+
</head>
|
|
301
|
+
<body>
|
|
302
|
+
<script
|
|
303
|
+
id="api-reference"
|
|
304
|
+
data-url="${encodeURI(openApiConfig.specPath)}">
|
|
305
|
+
</script>
|
|
306
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
307
|
+
</body>
|
|
308
|
+
</html>
|
|
309
|
+
`;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Handle OpenAPI spec requests
|
|
314
|
+
*/
|
|
315
|
+
const handleOpenApiSpecRequest = async (
|
|
316
|
+
url: URL
|
|
317
|
+
): Promise<Response | null> => {
|
|
318
|
+
if (openApiConfig.enabled && url.pathname === openApiConfig.specPath) {
|
|
319
|
+
const spec = await getOpenAPISpec();
|
|
320
|
+
return new Response(JSON.stringify(spec), {
|
|
321
|
+
status: 200,
|
|
322
|
+
headers: { 'Content-Type': 'application/json' },
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return null;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Handle API docs UI requests
|
|
330
|
+
*/
|
|
331
|
+
const handleDocsUiRequest = (url: URL): Response | null => {
|
|
332
|
+
if (openApiConfig.enabled && url.pathname === openApiConfig.docsPath) {
|
|
333
|
+
const html = getDocsUI();
|
|
334
|
+
return new Response(html, {
|
|
335
|
+
status: 200,
|
|
336
|
+
headers: {
|
|
337
|
+
'Content-Type': 'text/html',
|
|
338
|
+
'Content-Security-Policy':
|
|
339
|
+
"default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net;",
|
|
159
340
|
},
|
|
160
341
|
});
|
|
342
|
+
}
|
|
343
|
+
return null;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Create error response for DoubleTieError
|
|
348
|
+
*/
|
|
349
|
+
const createDoubleTieErrorResponse = (error: DoubleTieError): Response => {
|
|
350
|
+
// Sanitize error message to prevent sensitive information disclosure
|
|
351
|
+
const sanitizedMessage = error.message.replace(
|
|
352
|
+
/[^\w\s.,;:!?()[\]{}'"+-]/g,
|
|
353
|
+
''
|
|
354
|
+
);
|
|
355
|
+
return new Response(
|
|
356
|
+
JSON.stringify({
|
|
357
|
+
code: error.code,
|
|
358
|
+
message: sanitizedMessage,
|
|
359
|
+
data: error.meta,
|
|
360
|
+
status: error.statusCode,
|
|
361
|
+
defined: true,
|
|
362
|
+
}),
|
|
363
|
+
{
|
|
364
|
+
status: error.statusCode,
|
|
365
|
+
headers: { 'Content-Type': 'application/json' },
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
};
|
|
161
369
|
|
|
162
|
-
|
|
163
|
-
|
|
370
|
+
/**
|
|
371
|
+
* Create error response for unknown errors
|
|
372
|
+
*/
|
|
373
|
+
const createUnknownErrorResponse = (error: unknown): Response => {
|
|
374
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
375
|
+
// More safely determine the status code with proper type checks
|
|
376
|
+
let status = 500;
|
|
377
|
+
if (error instanceof Error && 'status' in error) {
|
|
378
|
+
const statusValue = (error as { status: unknown }).status;
|
|
379
|
+
if (
|
|
380
|
+
typeof statusValue === 'number' &&
|
|
381
|
+
statusValue >= 100 &&
|
|
382
|
+
statusValue < 600
|
|
383
|
+
) {
|
|
384
|
+
status = statusValue;
|
|
385
|
+
}
|
|
164
386
|
}
|
|
165
387
|
|
|
166
|
-
return
|
|
388
|
+
return new Response(
|
|
389
|
+
JSON.stringify({
|
|
390
|
+
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
391
|
+
message,
|
|
392
|
+
status,
|
|
393
|
+
defined: true,
|
|
394
|
+
data: {},
|
|
395
|
+
}),
|
|
396
|
+
{
|
|
397
|
+
status,
|
|
398
|
+
headers: { 'Content-Type': 'application/json' },
|
|
399
|
+
}
|
|
400
|
+
);
|
|
167
401
|
};
|
|
168
402
|
|
|
169
403
|
/**
|
|
170
|
-
*
|
|
404
|
+
* Handle API requests via oRPC
|
|
171
405
|
*/
|
|
172
|
-
const
|
|
173
|
-
request: Request
|
|
174
|
-
|
|
406
|
+
const handleApiRequest = async (
|
|
407
|
+
request: Request,
|
|
408
|
+
ctx: C15TContext
|
|
409
|
+
): Promise<Response> => {
|
|
410
|
+
// Create context for the handler with c15t specifics
|
|
411
|
+
const orpcContext: MiddlewareContext = {
|
|
412
|
+
adapter: ctx.adapter,
|
|
413
|
+
registry: ctx.registry,
|
|
414
|
+
logger: ctx.logger,
|
|
415
|
+
generateId: ctx.generateId,
|
|
416
|
+
headers: request.headers,
|
|
417
|
+
userAgent: request.headers.get('user-agent') || undefined,
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// Apply middleware processing to enrich the context
|
|
421
|
+
processIp(request, orpcContext);
|
|
422
|
+
processCors(request, orpcContext);
|
|
423
|
+
processTelemetry(request, orpcContext);
|
|
424
|
+
|
|
425
|
+
// Use oRPC handler to handle the request with our enhanced context
|
|
426
|
+
const handlerContext = orpcContext as Record<string, unknown>;
|
|
427
|
+
const { matched, response } = await rpcHandler.handle(request, {
|
|
428
|
+
prefix: '/',
|
|
429
|
+
context: handlerContext,
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// Return the response if handler matched
|
|
433
|
+
if (matched && response) {
|
|
434
|
+
return response;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// If no handler matched, return 404
|
|
438
|
+
return new Response('Not Found', { status: 404 });
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Handle an incoming request using oRPC
|
|
443
|
+
*/
|
|
444
|
+
const handler = async (request: Request): Promise<Response> => {
|
|
175
445
|
try {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return failAsync(`Context initialization failed: ${error.message}`, {
|
|
199
|
-
code: ERROR_CODES.INITIALIZATION_FAILED,
|
|
200
|
-
cause: error,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
);
|
|
446
|
+
const url = new URL(request.url);
|
|
447
|
+
|
|
448
|
+
// Check for OpenAPI spec or docs UI requests
|
|
449
|
+
const openApiResponse = await handleOpenApiSpecRequest(url);
|
|
450
|
+
if (openApiResponse) {
|
|
451
|
+
return openApiResponse;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const docsResponse = handleDocsUiRequest(url);
|
|
455
|
+
if (docsResponse) {
|
|
456
|
+
return docsResponse;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Get context, handling Result type properly
|
|
460
|
+
const ctxResult = await contextPromise;
|
|
461
|
+
if (!ctxResult.isOk()) {
|
|
462
|
+
throw ctxResult.error;
|
|
463
|
+
}
|
|
464
|
+
const ctx = ctxResult.value;
|
|
465
|
+
|
|
466
|
+
// Handle API request
|
|
467
|
+
return await handleApiRequest(request, ctx);
|
|
204
468
|
} catch (error) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
469
|
+
// Log the error
|
|
470
|
+
const logger = options.logger ? createLogger(options.logger) : console;
|
|
471
|
+
logger.error('Request handling error:', error);
|
|
472
|
+
|
|
473
|
+
// Handle different error types
|
|
474
|
+
if (error instanceof DoubleTieError) {
|
|
475
|
+
return createDoubleTieErrorResponse(error);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return createUnknownErrorResponse(error);
|
|
212
479
|
}
|
|
213
480
|
};
|
|
214
481
|
|
|
482
|
+
// Create Next.js-compatible route handlers
|
|
483
|
+
const createNextHandlers = () => {
|
|
484
|
+
const nextHandler = async (request: Request) => {
|
|
485
|
+
return await handler(request);
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
return {
|
|
489
|
+
GET: nextHandler,
|
|
490
|
+
POST: nextHandler,
|
|
491
|
+
PUT: nextHandler,
|
|
492
|
+
PATCH: nextHandler,
|
|
493
|
+
DELETE: nextHandler,
|
|
494
|
+
OPTIONS: nextHandler,
|
|
495
|
+
HEAD: nextHandler,
|
|
496
|
+
};
|
|
497
|
+
};
|
|
498
|
+
|
|
215
499
|
// Return the instance
|
|
216
500
|
return {
|
|
217
|
-
handler,
|
|
218
|
-
getApi: async (): Promise<SDKResultAsync<Route[]>> => {
|
|
219
|
-
const contextResult = await contextPromise;
|
|
220
|
-
|
|
221
|
-
return contextResult.match(
|
|
222
|
-
// Success case - just return the routes
|
|
223
|
-
() => okAsync(routes),
|
|
224
|
-
// Error case
|
|
225
|
-
(error) =>
|
|
226
|
-
failAsync(`API retrieval failed: ${error.message}`, {
|
|
227
|
-
code: ERROR_CODES.API_RETRIEVAL_ERROR,
|
|
228
|
-
cause: error,
|
|
229
|
-
})
|
|
230
|
-
);
|
|
231
|
-
},
|
|
232
501
|
options,
|
|
233
|
-
|
|
502
|
+
|
|
503
|
+
// Unwrap the Result when exposing the context
|
|
504
|
+
$context: contextPromise.then((result) => {
|
|
505
|
+
if (!result.isOk()) {
|
|
506
|
+
throw result.error;
|
|
507
|
+
}
|
|
508
|
+
return result.value;
|
|
509
|
+
}),
|
|
510
|
+
|
|
511
|
+
// Export router for direct access
|
|
512
|
+
router,
|
|
513
|
+
|
|
514
|
+
// Request handler for standard environments
|
|
515
|
+
handler,
|
|
516
|
+
|
|
517
|
+
// Next.js route handlers
|
|
518
|
+
...createNextHandlers(),
|
|
519
|
+
|
|
520
|
+
// OpenAPI functionality
|
|
521
|
+
getOpenAPISpec,
|
|
522
|
+
getDocsUI,
|
|
234
523
|
};
|
|
235
524
|
};
|
|
525
|
+
|
|
526
|
+
export type { C15TPlugin, C15TOptions, C15TContext };
|
|
527
|
+
export type { ContractsInputs, ContractsOutputs } from './contracts';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { postConsent } from './post.handler';
|
|
2
|
+
import { showConsentBanner } from './show-banner.handler';
|
|
3
|
+
import { verifyConsent } from './verify.handler';
|
|
4
|
+
|
|
5
|
+
export const consentHandlers = {
|
|
6
|
+
post: postConsent,
|
|
7
|
+
showBanner: showConsentBanner,
|
|
8
|
+
verify: verifyConsent,
|
|
9
|
+
};
|