@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
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main test suite for consent system route handlers
|
|
3
|
-
*
|
|
4
|
-
* This file imports and runs all the tests for various consent endpoints:
|
|
5
|
-
* - set-consent.ts: Creates consent records for users
|
|
6
|
-
* - verify-consent.ts: Verifies if a user has given consent
|
|
7
|
-
* - show-consent-banner.ts: Determines if a consent banner should be shown
|
|
8
|
-
* - status.ts: Returns system status information
|
|
9
|
-
*
|
|
10
|
-
* Note: These tests expect DoubleTieError validation errors, which is the expected
|
|
11
|
-
* behavior in our test environment due to h3 event simulation challenges.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// Use vi to mock dependencies
|
|
15
|
-
import { vi } from 'vitest';
|
|
16
|
-
import { version } from '../../../package.json';
|
|
17
|
-
|
|
18
|
-
// Mock the routes directly first
|
|
19
|
-
vi.mock('../status', () => {
|
|
20
|
-
return {
|
|
21
|
-
status: {
|
|
22
|
-
path: '/status',
|
|
23
|
-
method: 'get',
|
|
24
|
-
handler: vi.fn().mockImplementation((event) => {
|
|
25
|
-
const adapterType = event.context?.adapter?.id || 'Unavailable';
|
|
26
|
-
return {
|
|
27
|
-
status: 'ok',
|
|
28
|
-
version: version,
|
|
29
|
-
timestamp: new Date().toISOString(),
|
|
30
|
-
storage: {
|
|
31
|
-
type: adapterType,
|
|
32
|
-
available: !!event.context?.adapter,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}),
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
vi.mock('../show-consent-banner', () => {
|
|
41
|
-
return {
|
|
42
|
-
showConsentBanner: {
|
|
43
|
-
path: '/show-consent-banner',
|
|
44
|
-
method: 'get',
|
|
45
|
-
handler: vi.fn().mockImplementation((event) => {
|
|
46
|
-
const countryCode =
|
|
47
|
-
event.headers?.get?.('cf-ipcountry') ||
|
|
48
|
-
event.headers?.get?.('x-vercel-ip-country') ||
|
|
49
|
-
event.headers?.get?.('x-amz-cf-ipcountry') ||
|
|
50
|
-
event.headers?.get?.('x-country-code');
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
showConsentBanner: Boolean(
|
|
54
|
-
countryCode &&
|
|
55
|
-
[
|
|
56
|
-
'DE',
|
|
57
|
-
'GB',
|
|
58
|
-
'FR',
|
|
59
|
-
'IT',
|
|
60
|
-
'CH',
|
|
61
|
-
'BR',
|
|
62
|
-
'CA',
|
|
63
|
-
'AU',
|
|
64
|
-
'JP',
|
|
65
|
-
'KR',
|
|
66
|
-
].includes(countryCode)
|
|
67
|
-
),
|
|
68
|
-
jurisdiction: {
|
|
69
|
-
code:
|
|
70
|
-
countryCode && ['DE', 'GB', 'FR', 'IT'].includes(countryCode)
|
|
71
|
-
? 'GDPR'
|
|
72
|
-
: 'NONE',
|
|
73
|
-
message: 'Test message',
|
|
74
|
-
},
|
|
75
|
-
location: {
|
|
76
|
-
countryCode,
|
|
77
|
-
regionCode: null,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}),
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Now mock the routes/index.ts file
|
|
86
|
-
vi.mock('../index', () => {
|
|
87
|
-
// Import the mocked status and showConsentBanner
|
|
88
|
-
const { status } = require('../status');
|
|
89
|
-
const { showConsentBanner } = require('../show-consent-banner');
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
routes: [status, showConsentBanner],
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Mock h3 to prevent "Cannot read properties of undefined (reading 'req')" errors
|
|
97
|
-
vi.mock('h3', () => {
|
|
98
|
-
return {
|
|
99
|
-
readBody: vi.fn().mockImplementation(() => ({})),
|
|
100
|
-
defineEventHandler: vi.fn().mockImplementation((handler) => handler),
|
|
101
|
-
createError: vi.fn().mockImplementation((opts) => new Error(opts.message)),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Import the tests after all mocks are set up
|
|
106
|
-
import './set-consent.test';
|
|
107
|
-
import './verify-consent.test';
|
|
108
|
-
import './show-consent-banner.test';
|
|
109
|
-
import './status.test';
|
|
110
|
-
|
|
111
|
-
// This file doesn't contain tests itself, but ensures all test suites are included
|
|
112
|
-
// when running the test command targeting this file.
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the set-consent route handler
|
|
3
|
-
*/
|
|
4
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
// Mock dependencies before imports
|
|
7
|
-
vi.mock('../../pkgs/results', () => ({
|
|
8
|
-
DoubleTieError: class extends Error {
|
|
9
|
-
code: string;
|
|
10
|
-
status: number;
|
|
11
|
-
constructor(message: string, options: { code: string; status: number }) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.code = options.code;
|
|
14
|
-
this.status = options.status;
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
ERROR_CODES: {
|
|
18
|
-
BAD_REQUEST: 'BAD_REQUEST',
|
|
19
|
-
NOT_FOUND: 'NOT_FOUND',
|
|
20
|
-
CONFLICT: 'CONFLICT',
|
|
21
|
-
INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
import type { EventHandlerRequest, H3Event } from 'h3';
|
|
26
|
-
// Import after mocks
|
|
27
|
-
import { setConsent } from '../set-consent';
|
|
28
|
-
|
|
29
|
-
describe('setConsent', () => {
|
|
30
|
-
// Mock registry and adapter
|
|
31
|
-
const mockSubject = { id: 'subject-1', externalId: 'ext-1' };
|
|
32
|
-
const mockDomain = { id: 'domain-1', name: 'test.example.com' };
|
|
33
|
-
const mockPolicy = { id: 'policy-1', isActive: true, type: 'cookie_banner' };
|
|
34
|
-
const mockPurpose = { id: 'purpose-1', code: 'functional' };
|
|
35
|
-
|
|
36
|
-
const mockRegistry = {
|
|
37
|
-
findOrCreateSubject: vi.fn().mockResolvedValue(mockSubject),
|
|
38
|
-
findOrCreateDomain: vi.fn().mockResolvedValue(mockDomain),
|
|
39
|
-
findConsentPolicyById: vi.fn().mockResolvedValue(mockPolicy),
|
|
40
|
-
findOrCreatePolicy: vi.fn().mockResolvedValue(mockPolicy),
|
|
41
|
-
findConsentPurposeByCode: vi.fn().mockResolvedValue(mockPurpose),
|
|
42
|
-
createConsentPurpose: vi.fn().mockImplementation(async (data) => ({
|
|
43
|
-
id: `purpose-${Math.random().toString(36).substring(2, 9)}`,
|
|
44
|
-
...data,
|
|
45
|
-
})),
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const mockConsent = {
|
|
49
|
-
id: 'consent-1',
|
|
50
|
-
subjectId: mockSubject.id,
|
|
51
|
-
domainId: mockDomain.id,
|
|
52
|
-
policyId: mockPolicy.id,
|
|
53
|
-
purposeIds: [mockPurpose.id],
|
|
54
|
-
status: 'active',
|
|
55
|
-
isActive: true,
|
|
56
|
-
givenAt: new Date(),
|
|
57
|
-
ipAddress: '127.0.0.1',
|
|
58
|
-
agent: 'test-agent',
|
|
59
|
-
history: [],
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const mockRecord = {
|
|
63
|
-
id: 'record-1',
|
|
64
|
-
subjectId: mockSubject.id,
|
|
65
|
-
consentId: mockConsent.id,
|
|
66
|
-
actionType: 'consent_given',
|
|
67
|
-
details: {},
|
|
68
|
-
createdAt: new Date(),
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const mockAdapter = {
|
|
72
|
-
transaction: vi.fn().mockImplementation(async ({ callback }) => {
|
|
73
|
-
return callback({
|
|
74
|
-
create: vi.fn().mockImplementation(({ model }) => {
|
|
75
|
-
if (model === 'consent') {
|
|
76
|
-
return mockConsent;
|
|
77
|
-
}
|
|
78
|
-
if (model === 'consentRecord') {
|
|
79
|
-
return mockRecord;
|
|
80
|
-
}
|
|
81
|
-
return { id: `${model}-1` };
|
|
82
|
-
}),
|
|
83
|
-
});
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// Mock event context with required properties for h3 compatibility
|
|
88
|
-
const createMockEvent = (
|
|
89
|
-
body: Record<string, unknown>
|
|
90
|
-
): H3Event<EventHandlerRequest> => ({
|
|
91
|
-
//@ts-expect-error
|
|
92
|
-
req: {}, // Add req property to avoid "Cannot read properties of undefined (reading 'req')" error
|
|
93
|
-
context: {
|
|
94
|
-
validated: { body },
|
|
95
|
-
//@ts-expect-error
|
|
96
|
-
registry: mockRegistry,
|
|
97
|
-
//@ts-expect-error
|
|
98
|
-
adapter: mockAdapter,
|
|
99
|
-
ipAddress: '127.0.0.1',
|
|
100
|
-
userAgent: 'test-agent',
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
vi.clearAllMocks();
|
|
106
|
-
|
|
107
|
-
// Override handler to run validation functions and throw expected errors
|
|
108
|
-
// This helps tests pass while validating the right error conditions
|
|
109
|
-
vi.spyOn(setConsent, 'handler').mockImplementation(async (event) => {
|
|
110
|
-
// Access the expected properties to trigger the expected validation calls
|
|
111
|
-
if (event.context?.validated?.body) {
|
|
112
|
-
const body = event.context.validated.body;
|
|
113
|
-
|
|
114
|
-
// Run the mocked functions to make our expectations work
|
|
115
|
-
if (body.subjectId) {
|
|
116
|
-
await event.context.registry.findOrCreateSubject({
|
|
117
|
-
subjectId: body.subjectId as string,
|
|
118
|
-
externalSubjectId: body.externalSubjectId as string,
|
|
119
|
-
ipAddress: event.context.ipAddress as string,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (body.policyId) {
|
|
124
|
-
await event.context.registry.findConsentPolicyById(
|
|
125
|
-
body.policyId as string
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// For test cases expecting success, we could return a valid consent record
|
|
131
|
-
// For now, we'll continue to throw an error for all cases
|
|
132
|
-
throw new Error('Validation failed');
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should expect validation error for cookie banner consent record', async () => {
|
|
137
|
-
const event = createMockEvent({
|
|
138
|
-
type: 'cookie_banner',
|
|
139
|
-
domain: 'test.example.com',
|
|
140
|
-
preferences: { functional: true, analytics: false },
|
|
141
|
-
subjectId: 'user-123',
|
|
142
|
-
metadata: { source: 'website' },
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
await expect(
|
|
146
|
-
setConsent.handler(event as unknown as H3Event<EventHandlerRequest>)
|
|
147
|
-
).rejects.toThrow('Validation failed');
|
|
148
|
-
|
|
149
|
-
// Verify the function was at least called with expected parameters
|
|
150
|
-
expect(mockRegistry.findOrCreateSubject).toHaveBeenCalledWith({
|
|
151
|
-
subjectId: 'user-123',
|
|
152
|
-
externalSubjectId: undefined,
|
|
153
|
-
ipAddress: '127.0.0.1',
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should expect validation error for policy-based consent record', async () => {
|
|
158
|
-
const event = createMockEvent({
|
|
159
|
-
type: 'privacy_policy',
|
|
160
|
-
domain: 'test.example.com',
|
|
161
|
-
policyId: 'policy-2',
|
|
162
|
-
subjectId: 'user-123',
|
|
163
|
-
externalSubjectId: 'ext-user-123',
|
|
164
|
-
preferences: { dataSharing: true },
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Mock policy lookup
|
|
168
|
-
mockRegistry.findConsentPolicyById.mockResolvedValueOnce({
|
|
169
|
-
id: 'policy-2',
|
|
170
|
-
isActive: true,
|
|
171
|
-
type: 'privacy_policy',
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
await expect(setConsent.handler(event)).rejects.toThrow(
|
|
175
|
-
'Validation failed'
|
|
176
|
-
);
|
|
177
|
-
expect(mockRegistry.findConsentPolicyById).toHaveBeenCalledWith('policy-2');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('should expect validation error when subject creation fails', async () => {
|
|
181
|
-
mockRegistry.findOrCreateSubject.mockResolvedValueOnce(null);
|
|
182
|
-
|
|
183
|
-
const event = createMockEvent({
|
|
184
|
-
type: 'cookie_banner',
|
|
185
|
-
domain: 'test.example.com',
|
|
186
|
-
preferences: { functional: true },
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
await expect(setConsent.handler(event)).rejects.toThrow(
|
|
190
|
-
'Validation failed'
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should expect validation error when policy not found', async () => {
|
|
195
|
-
mockRegistry.findConsentPolicyById.mockResolvedValueOnce(null);
|
|
196
|
-
|
|
197
|
-
const event = createMockEvent({
|
|
198
|
-
type: 'privacy_policy',
|
|
199
|
-
domain: 'test.example.com',
|
|
200
|
-
policyId: 'non-existent-policy',
|
|
201
|
-
subjectId: 'user-123',
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
await expect(setConsent.handler(event)).rejects.toThrow(
|
|
205
|
-
'Validation failed'
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('should expect validation error when policy is not active', async () => {
|
|
210
|
-
mockRegistry.findConsentPolicyById.mockResolvedValueOnce({
|
|
211
|
-
id: 'policy-inactive',
|
|
212
|
-
isActive: false,
|
|
213
|
-
type: 'privacy_policy',
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const event = createMockEvent({
|
|
217
|
-
type: 'privacy_policy',
|
|
218
|
-
domain: 'test.example.com',
|
|
219
|
-
policyId: 'policy-inactive',
|
|
220
|
-
subjectId: 'user-123',
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
await expect(setConsent.handler(event)).rejects.toThrow(
|
|
224
|
-
'Validation failed'
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('should expect validation error when transaction fails', async () => {
|
|
229
|
-
mockAdapter.transaction.mockResolvedValueOnce(null);
|
|
230
|
-
|
|
231
|
-
const event = createMockEvent({
|
|
232
|
-
type: 'cookie_banner',
|
|
233
|
-
domain: 'test.example.com',
|
|
234
|
-
preferences: { functional: true },
|
|
235
|
-
subjectId: 'user-123',
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
await expect(setConsent.handler(event)).rejects.toThrow(
|
|
239
|
-
'Validation failed'
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the show-consent-banner route handler
|
|
3
|
-
*/
|
|
4
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
import type { EventHandlerRequest, H3Event } from 'h3';
|
|
7
|
-
// Import after global mocks
|
|
8
|
-
import { showConsentBanner } from '../show-consent-banner';
|
|
9
|
-
|
|
10
|
-
describe('showConsentBanner', () => {
|
|
11
|
-
// Test scenario helper function with proper h3 event structure
|
|
12
|
-
const createMockEvent = (
|
|
13
|
-
headers: Record<string, string> = {}
|
|
14
|
-
): H3Event<EventHandlerRequest> => ({
|
|
15
|
-
//@ts-expect-error
|
|
16
|
-
req: {}, // Add req property to avoid h3 errors
|
|
17
|
-
//@ts-expect-error
|
|
18
|
-
headers: {
|
|
19
|
-
get: vi.fn().mockImplementation((key: string) => headers[key] || null),
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
|
|
26
|
-
// Mock the handler to avoid the defineRoute error
|
|
27
|
-
vi.spyOn(showConsentBanner, 'handler').mockImplementation((event) => {
|
|
28
|
-
// Extract the country code from the event headers
|
|
29
|
-
const countryCode =
|
|
30
|
-
event.headers.get('cf-ipcountry') ||
|
|
31
|
-
event.headers.get('x-vercel-ip-country') ||
|
|
32
|
-
event.headers.get('x-amz-cf-ipcountry') ||
|
|
33
|
-
event.headers.get('x-country-code');
|
|
34
|
-
|
|
35
|
-
// Return a mock response based on the country code
|
|
36
|
-
return Promise.resolve({
|
|
37
|
-
showConsentBanner: Boolean(
|
|
38
|
-
countryCode &&
|
|
39
|
-
[
|
|
40
|
-
'DE',
|
|
41
|
-
'GB',
|
|
42
|
-
'FR',
|
|
43
|
-
'IT',
|
|
44
|
-
'CH',
|
|
45
|
-
'BR',
|
|
46
|
-
'CA',
|
|
47
|
-
'AU',
|
|
48
|
-
'JP',
|
|
49
|
-
'KR',
|
|
50
|
-
].includes(countryCode)
|
|
51
|
-
),
|
|
52
|
-
jurisdiction: {
|
|
53
|
-
code:
|
|
54
|
-
countryCode && ['DE', 'GB', 'FR', 'IT'].includes(countryCode)
|
|
55
|
-
? 'GDPR'
|
|
56
|
-
: 'NONE',
|
|
57
|
-
message: 'Test message',
|
|
58
|
-
},
|
|
59
|
-
location: {
|
|
60
|
-
countryCode,
|
|
61
|
-
regionCode: null,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should show banner for EU countries (GDPR)', async () => {
|
|
68
|
-
const event = createMockEvent({ 'cf-ipcountry': 'DE' });
|
|
69
|
-
const result = await showConsentBanner.handler(
|
|
70
|
-
event as unknown as H3Event<EventHandlerRequest>
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
expect(result.showConsentBanner).toBe(true);
|
|
74
|
-
expect(result.jurisdiction.code).toBe('GDPR');
|
|
75
|
-
expect(result.location.countryCode).toBe('DE');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should show banner for UK (GDPR equivalent)', async () => {
|
|
79
|
-
const event = createMockEvent({ 'cf-ipcountry': 'GB' });
|
|
80
|
-
const result = await showConsentBanner.handler(
|
|
81
|
-
event as unknown as H3Event<EventHandlerRequest>
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
expect(result.showConsentBanner).toBe(true);
|
|
85
|
-
expect(result.jurisdiction.code).toBe('GDPR');
|
|
86
|
-
expect(result.location.countryCode).toBe('GB');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should not show banner for non-regulated countries', async () => {
|
|
90
|
-
const event = createMockEvent({ 'cf-ipcountry': 'US' });
|
|
91
|
-
const result = await showConsentBanner.handler(
|
|
92
|
-
event as unknown as H3Event<EventHandlerRequest>
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
expect(result.showConsentBanner).toBe(false);
|
|
96
|
-
expect(result.location.countryCode).toBe('US');
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { EventHandlerRequest, H3Event } from 'h3';
|
|
2
|
-
/**
|
|
3
|
-
* Tests for the status route handler
|
|
4
|
-
*/
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
import { version } from '../../../package.json';
|
|
7
|
-
// Import the mocked status module
|
|
8
|
-
import { status } from '../status';
|
|
9
|
-
|
|
10
|
-
describe('status', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
vi.useFakeTimers();
|
|
13
|
-
// Set a fixed date for testing
|
|
14
|
-
vi.setSystemTime(new Date('2023-01-01T12:00:00Z'));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
vi.useRealTimers();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Create event with proper h3 structure
|
|
22
|
-
const createMockEvent = (
|
|
23
|
-
adapter: { id: string } | null = null
|
|
24
|
-
): H3Event<EventHandlerRequest> => ({
|
|
25
|
-
//@ts-expect-error
|
|
26
|
-
req: {}, // Add req property to avoid "Cannot read properties of undefined (reading 'req')" error
|
|
27
|
-
context: {
|
|
28
|
-
//@ts-expect-error
|
|
29
|
-
adapter,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should return status OK when adapter is available', async () => {
|
|
34
|
-
const mockAdapter = {
|
|
35
|
-
id: 'TestAdapter',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const result = await status.handler(createMockEvent(mockAdapter));
|
|
39
|
-
|
|
40
|
-
expect(result).toEqual({
|
|
41
|
-
status: 'ok',
|
|
42
|
-
version: version,
|
|
43
|
-
timestamp: '2023-01-01T12:00:00.000Z',
|
|
44
|
-
storage: {
|
|
45
|
-
type: 'TestAdapter',
|
|
46
|
-
available: true,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should handle case when adapter is unavailable', async () => {
|
|
52
|
-
const result = await status.handler(createMockEvent(null));
|
|
53
|
-
|
|
54
|
-
expect(result).toEqual({
|
|
55
|
-
status: 'ok',
|
|
56
|
-
version: version,
|
|
57
|
-
timestamp: '2023-01-01T12:00:00.000Z',
|
|
58
|
-
storage: {
|
|
59
|
-
type: 'Unavailable',
|
|
60
|
-
available: false,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|