@c15t/backend 1.0.0 → 1.1.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 +7 -0
- package/.turbo/turbo-test.log +531 -0
- package/README.md +19 -7
- 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 -78
- package/dist/core.d.ts.map +1 -1
- package/dist/{index.js → core.js} +1164 -1292
- 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 +0 -1
- 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 -7
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts.map +1 -1
- 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 -3
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/dialect.d.ts.map +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/kysely-adapter.d.ts +0 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.d.ts.map +1 -1
- 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/kysely-adapter/types.d.ts +0 -2
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/types.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/memory-adapter/memory-adapter.d.ts +0 -1
- package/dist/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.d.ts.map +1 -1
- 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/adapters/prisma-adapter/prisma-adapter.d.ts +0 -1
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.d.ts.map +1 -1
- 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 -8
- 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 -4
- 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 -3
- 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 +20 -28
- 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 -161
- 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 -26
- 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 -16
- package/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts +1 -3
- package/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts +0 -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/db-adapters/adapters/kysely-adapter/types.ts +0 -2
- package/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts +0 -1
- package/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts +0 -1
- 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 -9
- package/src/pkgs/types/endpoints.ts +3 -5
- package/src/pkgs/types/options.ts +2 -4
- 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 -3
- package/src/types/plugins.ts +3 -4
- package/dist/index.cjs +0 -3706
- 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 -236
- 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
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import type { Schema as ORPCSchema } from '@orpc/contract';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import type { ZodIssue, z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Contract test utilities for creating reusable test patterns
|
|
7
|
+
* across multiple contracts
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type ContractTestHelpers = {
|
|
11
|
+
validateInput?: (
|
|
12
|
+
input: unknown
|
|
13
|
+
) => z.SafeParseReturnType<unknown, unknown> | undefined;
|
|
14
|
+
validateOutput: (
|
|
15
|
+
output: unknown
|
|
16
|
+
) => z.SafeParseReturnType<unknown, unknown> | undefined;
|
|
17
|
+
testInput: (testName: string, input: unknown, shouldBeValid: boolean) => void;
|
|
18
|
+
testOutput: (
|
|
19
|
+
testName: string,
|
|
20
|
+
output: unknown,
|
|
21
|
+
shouldBeValid: boolean
|
|
22
|
+
) => void;
|
|
23
|
+
testDiscriminatedUnion: (
|
|
24
|
+
discriminator: string,
|
|
25
|
+
validValues: string[]
|
|
26
|
+
) => void;
|
|
27
|
+
testRequiredFields: (schema: 'input' | 'output', fields: string[]) => void;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type ContractSchema = z.ZodType | ORPCSchema<unknown, unknown>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a test suite for basic contract validation
|
|
34
|
+
* @param contractName Display name for the contract
|
|
35
|
+
* @param contract The contract to test
|
|
36
|
+
*/
|
|
37
|
+
export function createContractTests(
|
|
38
|
+
contractName: string,
|
|
39
|
+
contract: {
|
|
40
|
+
'~orpc'?: { inputSchema?: ContractSchema; outputSchema?: ContractSchema };
|
|
41
|
+
}
|
|
42
|
+
): ContractTestHelpers {
|
|
43
|
+
const schemas = {
|
|
44
|
+
input: contract['~orpc']?.inputSchema,
|
|
45
|
+
output: contract['~orpc']?.outputSchema,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Helper functions
|
|
49
|
+
const validateInput = (input: unknown) => {
|
|
50
|
+
const schema = schemas.input;
|
|
51
|
+
if (!schema) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Handle both Zod and oRPC schemas
|
|
56
|
+
if ('safeParse' in schema) {
|
|
57
|
+
return schema.safeParse(input);
|
|
58
|
+
}
|
|
59
|
+
// For oRPC schemas, we'll need to implement validation
|
|
60
|
+
// This is a placeholder - you may need to implement actual validation
|
|
61
|
+
return { success: true, data: input } as z.SafeParseReturnType<
|
|
62
|
+
unknown,
|
|
63
|
+
unknown
|
|
64
|
+
>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const validateOutput = (output: unknown) => {
|
|
68
|
+
const schema = schemas.output;
|
|
69
|
+
if (!schema) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Handle both Zod and oRPC schemas
|
|
74
|
+
if ('safeParse' in schema) {
|
|
75
|
+
return schema.safeParse(output);
|
|
76
|
+
}
|
|
77
|
+
// For oRPC schemas, we'll need to implement validation
|
|
78
|
+
// This is a placeholder - you may need to implement actual validation
|
|
79
|
+
return { success: true, data: output } as z.SafeParseReturnType<
|
|
80
|
+
unknown,
|
|
81
|
+
unknown
|
|
82
|
+
>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Create base test suite
|
|
86
|
+
describe(`${contractName} Contract`, () => {
|
|
87
|
+
describe('Schema Structure', () => {
|
|
88
|
+
it('has properly defined schemas', () => {
|
|
89
|
+
// Only require output schema
|
|
90
|
+
expect(schemas.output).toBeDefined();
|
|
91
|
+
|
|
92
|
+
// Input schema is optional
|
|
93
|
+
if (schemas.input) {
|
|
94
|
+
expect(schemas.input).toBeDefined();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('schemas are serializable', () => {
|
|
99
|
+
// Test serialization for output schema
|
|
100
|
+
if (schemas.output) {
|
|
101
|
+
const serialized = JSON.stringify(schemas.output);
|
|
102
|
+
expect(serialized).toBeDefined();
|
|
103
|
+
expect(typeof serialized).toBe('string');
|
|
104
|
+
expect(() => JSON.parse(serialized)).not.toThrow();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Test serialization for input schema if it exists
|
|
108
|
+
if (schemas.input) {
|
|
109
|
+
const serialized = JSON.stringify(schemas.input);
|
|
110
|
+
expect(serialized).toBeDefined();
|
|
111
|
+
expect(typeof serialized).toBe('string');
|
|
112
|
+
expect(() => JSON.parse(serialized)).not.toThrow();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Define test helpers
|
|
119
|
+
const testInput = (
|
|
120
|
+
testName: string,
|
|
121
|
+
input: unknown,
|
|
122
|
+
shouldBeValid: boolean
|
|
123
|
+
) => {
|
|
124
|
+
it(`${testName}`, () => {
|
|
125
|
+
const result = validateInput(input);
|
|
126
|
+
if (!result) {
|
|
127
|
+
throw new Error('Validation result is undefined');
|
|
128
|
+
}
|
|
129
|
+
expect(result.success).toBe(shouldBeValid);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const testOutput = (
|
|
134
|
+
testName: string,
|
|
135
|
+
output: unknown,
|
|
136
|
+
shouldBeValid: boolean
|
|
137
|
+
) => {
|
|
138
|
+
it(`${testName}`, () => {
|
|
139
|
+
const result = validateOutput(output);
|
|
140
|
+
if (!result) {
|
|
141
|
+
throw new Error('Validation result is undefined');
|
|
142
|
+
}
|
|
143
|
+
expect(result.success).toBe(shouldBeValid);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const testDiscriminatedUnion = (
|
|
148
|
+
discriminator: string,
|
|
149
|
+
validValues: string[]
|
|
150
|
+
) => {
|
|
151
|
+
describe('Discriminated Union validation', () => {
|
|
152
|
+
it(`uses '${discriminator}' as discriminator`, () => {
|
|
153
|
+
if (!schemas.input) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// Only check Zod schemas for discriminated unions
|
|
157
|
+
if ('_def' in schemas.input) {
|
|
158
|
+
const schema = schemas.input as z.ZodDiscriminatedUnion<
|
|
159
|
+
string,
|
|
160
|
+
z.ZodObject<z.ZodRawShape>[]
|
|
161
|
+
>;
|
|
162
|
+
expect(schema._def.typeName).toBe('ZodDiscriminatedUnion');
|
|
163
|
+
expect(schema._def.discriminator).toBe(discriminator);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('validates all defined discriminator values', () => {
|
|
168
|
+
if (!schemas.input) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
for (const value of validValues) {
|
|
172
|
+
const input = {
|
|
173
|
+
[discriminator]: value,
|
|
174
|
+
// Add minimum required fields based on your contract
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// This test assumes minimal input - you may need to add required fields
|
|
178
|
+
// based on the specific contract being tested
|
|
179
|
+
const result = validateInput(input);
|
|
180
|
+
// Specifically assert that it fails due to missing required fields
|
|
181
|
+
expect(result?.success).toBe(false);
|
|
182
|
+
if (!result?.success) {
|
|
183
|
+
expect(
|
|
184
|
+
result?.error.issues.some(
|
|
185
|
+
(issue) => issue.code === 'invalid_type'
|
|
186
|
+
)
|
|
187
|
+
).toBe(true);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const testRequiredFields = (schema: 'input' | 'output', fields: string[]) => {
|
|
195
|
+
describe(`Required ${schema} fields`, () => {
|
|
196
|
+
// Skip if testing input fields but no input schema exists
|
|
197
|
+
if (schema === 'input' && !schemas.input) {
|
|
198
|
+
it('skips input field tests as no input schema exists', () => {
|
|
199
|
+
expect(true).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Create a sample of valid data to test against
|
|
205
|
+
let sampleValid: Record<string, unknown>;
|
|
206
|
+
|
|
207
|
+
if (schema === 'input') {
|
|
208
|
+
// For input schema, we need a valid input based on the contract type
|
|
209
|
+
sampleValid = {
|
|
210
|
+
type: 'marketing_communications', // A common type that most contracts would have
|
|
211
|
+
domain: 'example.com',
|
|
212
|
+
// Add other fields that might be required by your contracts
|
|
213
|
+
subjectId: 'test-123',
|
|
214
|
+
metadata: {},
|
|
215
|
+
};
|
|
216
|
+
} else {
|
|
217
|
+
// For output schema, create a generic valid output
|
|
218
|
+
sampleValid = {
|
|
219
|
+
id: 'test-123',
|
|
220
|
+
domainId: 'domain-123',
|
|
221
|
+
domain: 'example.com',
|
|
222
|
+
type: 'marketing_communications',
|
|
223
|
+
status: 'granted',
|
|
224
|
+
recordId: 'record-123',
|
|
225
|
+
givenAt: new Date().toISOString(),
|
|
226
|
+
metadata: {},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const field of fields) {
|
|
231
|
+
it(`requires '${field}' field`, () => {
|
|
232
|
+
// Create a copy of the valid data without the tested field
|
|
233
|
+
const invalidData = { ...sampleValid };
|
|
234
|
+
delete invalidData[field];
|
|
235
|
+
|
|
236
|
+
const validator = schema === 'input' ? validateInput : validateOutput;
|
|
237
|
+
const result = validator(invalidData);
|
|
238
|
+
|
|
239
|
+
if (!result) {
|
|
240
|
+
throw new Error('Validation result is undefined');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
expect(result.success).toBe(false);
|
|
244
|
+
if (!result.success) {
|
|
245
|
+
expect(
|
|
246
|
+
result.error.issues.some(
|
|
247
|
+
(issue: ZodIssue) =>
|
|
248
|
+
issue.path.some((p) => String(p).includes(field)) ||
|
|
249
|
+
issue.message.includes('required')
|
|
250
|
+
)
|
|
251
|
+
).toBe(true);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// Return the test helpers for re-use
|
|
259
|
+
return {
|
|
260
|
+
validateInput,
|
|
261
|
+
validateOutput,
|
|
262
|
+
testInput,
|
|
263
|
+
testOutput,
|
|
264
|
+
testDiscriminatedUnion,
|
|
265
|
+
testRequiredFields,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Creates consistency tests for multiple related contracts
|
|
271
|
+
*/
|
|
272
|
+
export function createConsistencyTests(
|
|
273
|
+
contracts: Record<
|
|
274
|
+
string,
|
|
275
|
+
{
|
|
276
|
+
'~orpc'?: {
|
|
277
|
+
inputSchema?: ContractSchema;
|
|
278
|
+
outputSchema?: ContractSchema;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
>
|
|
282
|
+
) {
|
|
283
|
+
describe('Contract Consistency', () => {
|
|
284
|
+
it('all contracts have output schemas', () => {
|
|
285
|
+
for (const [_name, contract] of Object.entries(contracts)) {
|
|
286
|
+
expect(contract['~orpc']?.outputSchema).toBeDefined();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Field type consistency - ensure common fields use same types across contracts
|
|
291
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: excessive cognitive complexity is acceptable here
|
|
292
|
+
it('common fields have consistent types across contracts', () => {
|
|
293
|
+
const commonFields = ['id', 'domainId', 'type', 'status'];
|
|
294
|
+
const contractEntries = Object.entries(contracts);
|
|
295
|
+
|
|
296
|
+
for (const field of commonFields) {
|
|
297
|
+
const fieldTypes = new Set();
|
|
298
|
+
|
|
299
|
+
for (const [_name, contract] of contractEntries) {
|
|
300
|
+
const schema = contract['~orpc']?.outputSchema;
|
|
301
|
+
if (!schema || !('shape' in schema)) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const shape = schema.shape as Record<string, z.ZodTypeAny>;
|
|
306
|
+
if (field in shape) {
|
|
307
|
+
const fieldDef = shape[field];
|
|
308
|
+
if (fieldDef) {
|
|
309
|
+
fieldTypes.add(fieldDef.constructor.name);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// If the field exists in multiple contracts, they should all use the same type
|
|
315
|
+
if (fieldTypes.size > 0) {
|
|
316
|
+
expect(
|
|
317
|
+
fieldTypes.size,
|
|
318
|
+
`Field '${field}' has inconsistent types across contracts`
|
|
319
|
+
).toBe(1);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Validate enum value consistency across contracts
|
|
325
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: excessive cognitive complexity is acceptable here
|
|
326
|
+
it('enum values are consistent across contracts', () => {
|
|
327
|
+
// Example: status field should have the same allowed values in all contracts
|
|
328
|
+
const statusValues = new Map<string, string[]>();
|
|
329
|
+
|
|
330
|
+
for (const [name, contract] of Object.entries(contracts)) {
|
|
331
|
+
const schema = contract['~orpc']?.outputSchema;
|
|
332
|
+
if (!schema || !('shape' in schema)) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const shape = schema.shape as Record<string, z.ZodTypeAny>;
|
|
337
|
+
if (!shape.status) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const statusField = shape.status;
|
|
342
|
+
if ('_def' in statusField && 'values' in statusField._def) {
|
|
343
|
+
statusValues.set(name, statusField._def.values as string[]);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// All status enums should have the same values
|
|
348
|
+
const allValues = Array.from(statusValues.values());
|
|
349
|
+
if (allValues.length > 1) {
|
|
350
|
+
for (let i = 1; i < allValues.length; i++) {
|
|
351
|
+
expect(allValues[i]).toEqual(allValues[0]);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Validation rule consistency for common fields
|
|
357
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: excessive cognitive complexity is acceptable here
|
|
358
|
+
it('validation rules for common fields are consistent', () => {
|
|
359
|
+
const contractEntries = Object.entries(contracts);
|
|
360
|
+
const commonStringFields = ['domain', 'subjectId', 'externalSubjectId'];
|
|
361
|
+
|
|
362
|
+
for (const field of commonStringFields) {
|
|
363
|
+
const minLengths = new Set();
|
|
364
|
+
const maxLengths = new Set();
|
|
365
|
+
|
|
366
|
+
for (const [_name, contract] of contractEntries) {
|
|
367
|
+
const schema = contract['~orpc']?.inputSchema;
|
|
368
|
+
if (!schema || !('shape' in schema)) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const shape = schema.shape as Record<string, z.ZodTypeAny>;
|
|
373
|
+
if (!shape[field]) {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const fieldSchema = shape[field];
|
|
378
|
+
if (
|
|
379
|
+
'_def' in fieldSchema &&
|
|
380
|
+
fieldSchema._def.typeName === 'ZodString'
|
|
381
|
+
) {
|
|
382
|
+
// Extract min/max length if they exist
|
|
383
|
+
const checks = fieldSchema._def.checks || [];
|
|
384
|
+
for (const check of checks) {
|
|
385
|
+
if (check.kind === 'min') {
|
|
386
|
+
minLengths.add(check.value);
|
|
387
|
+
}
|
|
388
|
+
if (check.kind === 'max') {
|
|
389
|
+
maxLengths.add(check.value);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// All contracts should use the same min/max for common string fields
|
|
396
|
+
expect(
|
|
397
|
+
minLengths.size,
|
|
398
|
+
`Inconsistent min length for field '${field}'`
|
|
399
|
+
).toBeLessThanOrEqual(1);
|
|
400
|
+
expect(
|
|
401
|
+
maxLengths.size,
|
|
402
|
+
`Inconsistent max length for field '${field}'`
|
|
403
|
+
).toBeLessThanOrEqual(1);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// Discriminated union consistency
|
|
408
|
+
it('discriminated unions use consistent discriminator across contracts', () => {
|
|
409
|
+
const discriminators = new Set();
|
|
410
|
+
|
|
411
|
+
for (const [_name, contract] of Object.entries(contracts)) {
|
|
412
|
+
const schema = contract['~orpc']?.inputSchema;
|
|
413
|
+
if (!schema || !('_def' in schema)) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Check if schema is a discriminated union
|
|
418
|
+
if (
|
|
419
|
+
'typeName' in schema._def &&
|
|
420
|
+
schema._def.typeName === 'ZodDiscriminatedUnion' &&
|
|
421
|
+
'discriminator' in schema._def
|
|
422
|
+
) {
|
|
423
|
+
// Safe assertion since we've checked the property exists
|
|
424
|
+
discriminators.add(
|
|
425
|
+
(schema._def as { discriminator: string }).discriminator
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// All contracts should use the same discriminator (e.g., 'type')
|
|
431
|
+
expect(
|
|
432
|
+
discriminators.size,
|
|
433
|
+
'Inconsistent discriminator fields used across contracts'
|
|
434
|
+
).toBeLessThanOrEqual(1);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
}
|
package/src/types/context.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DoubleTieContext } from '~/pkgs/types/context';
|
|
|
2
2
|
import type { C15TPlugin, InferPluginContexts } from './plugins';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Complete
|
|
5
|
+
* Complete c15t context type for consent management
|
|
6
6
|
*
|
|
7
7
|
* This type combines the base consent context with plugin-specific context extensions.
|
|
8
8
|
* It's the primary context type used throughout the consent management system.
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* c15t Types Package
|
|
3
3
|
*
|
|
4
|
-
* This package provides type definitions specific to the
|
|
4
|
+
* This package provides type definitions specific to the c15t consent management system.
|
|
5
5
|
* It extends the base DoubleTie framework types with consent management specific functionality.
|
|
6
6
|
*
|
|
7
7
|
* The types in this folder should be used for consent management specific features, while
|
package/src/types/options.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OpenAPIGeneratorOptions } from '@orpc/openapi';
|
|
1
2
|
/**
|
|
2
3
|
* c15t Consent Management System Configuration Types
|
|
3
4
|
*
|
|
@@ -8,7 +9,7 @@
|
|
|
8
9
|
import type { DoubleTieOptions } from '~/pkgs/types/options';
|
|
9
10
|
import type { C15TPlugin } from './plugins';
|
|
10
11
|
|
|
11
|
-
import type { LoggerOptions } from '
|
|
12
|
+
import type { LoggerOptions } from '@doubletie/logger';
|
|
12
13
|
// Import table configuration types from the schema module
|
|
13
14
|
import type { TablesConfig } from '~/schema/types';
|
|
14
15
|
/**
|
|
@@ -24,7 +25,6 @@ import type { TablesConfig } from '~/schema/types';
|
|
|
24
25
|
* // Basic consent management configuration
|
|
25
26
|
* const options: C15TOptions = {
|
|
26
27
|
* appName: "My Consent App",
|
|
27
|
-
* secret: process.env.SECRET_KEY,
|
|
28
28
|
* baseURL: "https://example.com",
|
|
29
29
|
* trustedOrigins: ["https://example.com"]
|
|
30
30
|
* };
|
|
@@ -53,7 +53,7 @@ export interface C15TOptions<PluginType extends C15TPlugin[] = C15TPlugin[]>
|
|
|
53
53
|
secret?: string;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Plugins specific to
|
|
56
|
+
* Plugins specific to c15t
|
|
57
57
|
*/
|
|
58
58
|
plugins?: PluginType;
|
|
59
59
|
|
|
@@ -66,4 +66,39 @@ export interface C15TOptions<PluginType extends C15TPlugin[] = C15TPlugin[]>
|
|
|
66
66
|
* Logger configuration
|
|
67
67
|
*/
|
|
68
68
|
logger?: LoggerOptions;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* OpenAPI configuration options
|
|
72
|
+
*/
|
|
73
|
+
openapi?: {
|
|
74
|
+
/**
|
|
75
|
+
* Enable/disable OpenAPI spec generation
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
enabled?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Path to serve the OpenAPI JSON spec
|
|
82
|
+
* @default "/spec.json"
|
|
83
|
+
*/
|
|
84
|
+
specPath?: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Path to serve the API documentation UI
|
|
88
|
+
* @default "/docs"
|
|
89
|
+
*/
|
|
90
|
+
docsPath?: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* OpenAPI specification options
|
|
94
|
+
* These are passed to the OpenAPIGenerator.generate() method
|
|
95
|
+
*/
|
|
96
|
+
options?: Partial<OpenAPIGeneratorOptions>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Custom template for rendering the API documentation UI
|
|
100
|
+
* If provided, this will be used instead of the default Scalar UI
|
|
101
|
+
*/
|
|
102
|
+
customUiTemplate?: string;
|
|
103
|
+
};
|
|
69
104
|
}
|
package/src/types/plugins.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { H3Event } from 'h3';
|
|
2
1
|
import type { Migration } from 'kysely';
|
|
3
2
|
import type { DoubleTieContext, DoubleTieOptions } from '~/pkgs/types';
|
|
4
3
|
import type { Endpoint, EndpointMiddleware } from '~/pkgs/types/endpoints';
|
|
@@ -60,12 +59,12 @@ export interface DoubleTiePlugin {
|
|
|
60
59
|
/**
|
|
61
60
|
* Handler for intercepting and potentially modifying incoming requests
|
|
62
61
|
*/
|
|
63
|
-
onRequest?: (
|
|
62
|
+
onRequest?: (request: Request, ctx: DoubleTieContext) => Promise<unknown>;
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
65
|
* Handler for intercepting and potentially modifying outgoing responses
|
|
67
66
|
*/
|
|
68
|
-
onResponse?: (
|
|
67
|
+
onResponse?: (response: Response, ctx: DoubleTieContext) => Promise<unknown>;
|
|
69
68
|
|
|
70
69
|
/**
|
|
71
70
|
* Schema the plugin needs
|
|
@@ -138,7 +137,7 @@ export interface C15TPlugin extends Omit<DoubleTiePlugin, 'endpoints'> {
|
|
|
138
137
|
/**
|
|
139
138
|
* Handler for intercepting and potentially modifying outgoing responses
|
|
140
139
|
*/
|
|
141
|
-
onResponse?: (
|
|
140
|
+
onResponse?: (response: Response, ctx: C15TContext) => Promise<unknown>;
|
|
142
141
|
|
|
143
142
|
/**
|
|
144
143
|
* Schema the plugin needs for consent data
|