@c15t/backend 1.0.5 → 1.2.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +33 -39
- package/.turbo/turbo-fmt.log +3 -3
- package/.turbo/turbo-test.log +531 -0
- package/coverage/coverage-final.json +84 -0
- package/coverage/coverage-summary.json +85 -0
- package/coverage/html/backend/index.html +116 -0
- package/coverage/html/backend/rslib.config.ts.html +415 -0
- package/coverage/html/backend/src/contracts/consent/index.html +161 -0
- package/coverage/html/backend/src/contracts/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/contracts/consent/post.contract.ts.html +559 -0
- package/coverage/html/backend/src/contracts/consent/show-banner.contract.ts.html +220 -0
- package/coverage/html/backend/src/contracts/consent/verify.contract.ts.html +463 -0
- package/coverage/html/backend/src/contracts/index.html +116 -0
- package/coverage/html/backend/src/contracts/index.ts.html +139 -0
- package/coverage/html/backend/src/contracts/meta/index.html +131 -0
- package/coverage/html/backend/src/contracts/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/contracts/meta/status.contract.ts.html +196 -0
- package/coverage/html/backend/src/contracts/shared/index.html +116 -0
- package/coverage/html/backend/src/contracts/shared/jurisdiction.schema.ts.html +175 -0
- package/coverage/html/backend/src/core.ts.html +1624 -0
- package/coverage/html/backend/src/handlers/consent/index.html +161 -0
- package/coverage/html/backend/src/handlers/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/handlers/consent/post.handler.ts.html +889 -0
- package/coverage/html/backend/src/handlers/consent/show-banner.handler.ts.html +535 -0
- package/coverage/html/backend/src/handlers/consent/verify.handler.ts.html +1000 -0
- package/coverage/html/backend/src/handlers/meta/index.html +131 -0
- package/coverage/html/backend/src/handlers/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/handlers/meta/status.handler.ts.html +226 -0
- package/coverage/html/backend/src/index.html +161 -0
- package/coverage/html/backend/src/init.ts.html +1018 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/processor.ts.html +544 -0
- package/coverage/html/backend/src/pkgs/api-router/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/telemetry.ts.html +334 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/cors.ts.html +304 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/index.html +131 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/ip.ts.html +361 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/field-factory.ts.html +709 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/id-generator.ts.html +256 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/index.html +161 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/superjson-utils.ts.html +136 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/zod-fields.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/create-hooks.ts.html +349 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/index.html +176 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-hooks.ts.html +358 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-many-hooks.ts.html +613 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/utils.ts.html +538 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/with-hooks-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapter-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts.html +2203 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts.html +670 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts.html +3634 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts.html +1417 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts.html +2071 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts.html +1834 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/test.ts.html +316 -0
- package/coverage/html/backend/src/pkgs/db-adapters/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/utils.ts.html +238 -0
- package/coverage/html/backend/src/pkgs/migrations/get-migration.ts.html +343 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/get-schema.ts.html +217 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/index.html +146 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-fields.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-tables.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/migrations/index.html +176 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-builders.ts.html +595 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-execution.ts.html +301 -0
- package/coverage/html/backend/src/pkgs/migrations/schema-comparison.ts.html +694 -0
- package/coverage/html/backend/src/pkgs/migrations/type-mapping.ts.html +817 -0
- package/coverage/html/backend/src/pkgs/results/core/error-class.ts.html +976 -0
- package/coverage/html/backend/src/pkgs/results/core/error-codes.ts.html +703 -0
- package/coverage/html/backend/src/pkgs/results/core/index.html +146 -0
- package/coverage/html/backend/src/pkgs/results/core/tracing.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/results/create-telemetry-options.ts.html +271 -0
- package/coverage/html/backend/src/pkgs/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/orpc-error-handler.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/results/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/results/recovery-utils.ts.html +628 -0
- package/coverage/html/backend/src/pkgs/results/results/result-helpers.ts.html +1234 -0
- package/coverage/html/backend/src/pkgs/utils/env.ts.html +337 -0
- package/coverage/html/backend/src/pkgs/utils/index.html +146 -0
- package/coverage/html/backend/src/pkgs/utils/logger.ts.html +199 -0
- package/coverage/html/backend/src/pkgs/utils/url.ts.html +400 -0
- package/coverage/html/backend/src/router.ts.html +109 -0
- package/coverage/html/backend/src/schema/audit-log/index.html +146 -0
- package/coverage/html/backend/src/schema/audit-log/registry.ts.html +436 -0
- package/coverage/html/backend/src/schema/audit-log/schema.ts.html +223 -0
- package/coverage/html/backend/src/schema/audit-log/table.ts.html +640 -0
- package/coverage/html/backend/src/schema/consent/index.html +146 -0
- package/coverage/html/backend/src/schema/consent/registry.ts.html +616 -0
- package/coverage/html/backend/src/schema/consent/schema.ts.html +238 -0
- package/coverage/html/backend/src/schema/consent/table.ts.html +748 -0
- package/coverage/html/backend/src/schema/consent-policy/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-policy/registry.ts.html +1063 -0
- package/coverage/html/backend/src/schema/consent-policy/schema.ts.html +265 -0
- package/coverage/html/backend/src/schema/consent-policy/table.ts.html +535 -0
- package/coverage/html/backend/src/schema/consent-purpose/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-purpose/registry.ts.html +589 -0
- package/coverage/html/backend/src/schema/consent-purpose/schema.ts.html +259 -0
- package/coverage/html/backend/src/schema/consent-purpose/table.ts.html +547 -0
- package/coverage/html/backend/src/schema/consent-record/index.html +131 -0
- package/coverage/html/backend/src/schema/consent-record/schema.ts.html +211 -0
- package/coverage/html/backend/src/schema/consent-record/table.ts.html +457 -0
- package/coverage/html/backend/src/schema/create-registry.ts.html +148 -0
- package/coverage/html/backend/src/schema/definition.ts.html +685 -0
- package/coverage/html/backend/src/schema/domain/index.html +146 -0
- package/coverage/html/backend/src/schema/domain/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/domain/schema.ts.html +214 -0
- package/coverage/html/backend/src/schema/domain/table.ts.html +496 -0
- package/coverage/html/backend/src/schema/index.html +146 -0
- package/coverage/html/backend/src/schema/schemas.ts.html +166 -0
- package/coverage/html/backend/src/schema/subject/index.html +146 -0
- package/coverage/html/backend/src/schema/subject/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/subject/schema.ts.html +208 -0
- package/coverage/html/backend/src/schema/subject/table.ts.html +499 -0
- package/coverage/html/backend/src/server.ts.html +475 -0
- package/coverage/html/backend/src/testing/contract-testing.ts.html +1348 -0
- package/coverage/html/backend/src/testing/index.html +116 -0
- package/coverage/html/base.css +224 -0
- package/coverage/html/block-navigation.js +87 -0
- package/coverage/html/favicon.png +0 -0
- package/coverage/html/index.html +626 -0
- package/coverage/html/prettify.css +1 -0
- package/coverage/html/prettify.js +2 -0
- package/coverage/html/sort-arrow-sprite.png +0 -0
- package/coverage/html/sorter.js +196 -0
- package/dist/contracts/consent/index.d.ts +401 -0
- package/dist/contracts/consent/index.d.ts.map +1 -0
- package/dist/contracts/consent/index.test.d.ts +2 -0
- package/dist/contracts/consent/index.test.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.d.ts +212 -0
- package/dist/contracts/consent/post.contract.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.test.d.ts +2 -0
- package/dist/contracts/consent/post.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.d.ts +45 -0
- package/dist/contracts/consent/show-banner.contract.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts +2 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.d.ts +147 -0
- package/dist/contracts/consent/verify.contract.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.test.d.ts +2 -0
- package/dist/contracts/consent/verify.contract.test.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +963 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.d.ts +78 -0
- package/dist/contracts/meta/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.test.d.ts +2 -0
- package/dist/contracts/meta/index.test.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.d.ts +77 -0
- package/dist/contracts/meta/status.contract.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.test.d.ts +2 -0
- package/dist/contracts/meta/status.contract.test.d.ts.map +1 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts +24 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts.map +1 -0
- package/dist/core.cjs +3584 -0
- package/dist/core.d.ts +533 -76
- package/dist/core.d.ts.map +1 -1
- package/dist/{index.js → core.js} +1163 -1286
- package/dist/handlers/consent/index.d.ts +401 -0
- package/dist/handlers/consent/index.d.ts.map +1 -0
- package/dist/handlers/consent/post.handler.d.ts +234 -0
- package/dist/handlers/consent/post.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.d.ts +57 -0
- package/dist/handlers/consent/show-banner.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts +2 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts.map +1 -0
- package/dist/handlers/consent/verify.handler.d.ts +169 -0
- package/dist/handlers/consent/verify.handler.d.ts.map +1 -0
- package/dist/handlers/meta/index.d.ts +78 -0
- package/dist/handlers/meta/index.d.ts.map +1 -0
- package/dist/handlers/meta/status.handler.d.ts +76 -0
- package/dist/handlers/meta/status.handler.d.ts.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/pkgs/api-router/hooks/processor.d.ts.map +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts.map +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts.map +1 -1
- package/dist/pkgs/data-model/fields/field-types.d.ts +1 -1
- package/dist/pkgs/data-model/fields/zod-fields.d.ts +32 -32
- package/dist/pkgs/data-model/index.cjs +1433 -1799
- package/dist/pkgs/data-model/index.js +20 -385
- package/dist/pkgs/data-model/schema/index.cjs +1402 -1768
- package/dist/pkgs/data-model/schema/index.js +20 -385
- package/dist/pkgs/db-adapters/adapter-factory.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapter-factory.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts +4 -4
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/dialect.d.ts +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/index.cjs +31 -153
- package/dist/pkgs/db-adapters/index.js +31 -153
- package/dist/pkgs/migrations/get-schema/get-schema.d.ts +2 -2
- package/dist/pkgs/migrations/get-schema/index.d.ts +1 -1
- package/dist/pkgs/migrations/index.cjs +30 -153
- package/dist/pkgs/migrations/index.js +30 -153
- package/dist/pkgs/migrations/schema-comparison.d.ts.map +1 -1
- package/dist/pkgs/results/core/error-class.d.ts +23 -21
- package/dist/pkgs/results/core/error-class.d.ts.map +1 -1
- package/dist/pkgs/results/index.cjs +17 -150
- package/dist/pkgs/results/index.d.ts +0 -3
- package/dist/pkgs/results/index.d.ts.map +1 -1
- package/dist/pkgs/results/index.js +17 -138
- package/dist/pkgs/results/orpc-error-handler.d.ts +65 -0
- package/dist/pkgs/results/orpc-error-handler.d.ts.map +1 -0
- package/dist/pkgs/results/types.d.ts +7 -7
- package/dist/pkgs/results/types.d.ts.map +1 -1
- package/dist/pkgs/types/context.d.ts +15 -4
- package/dist/pkgs/types/context.d.ts.map +1 -1
- package/dist/pkgs/types/endpoints.d.ts +3 -4
- package/dist/pkgs/types/endpoints.d.ts.map +1 -1
- package/dist/pkgs/types/options.d.ts +2 -3
- package/dist/pkgs/types/options.d.ts.map +1 -1
- package/dist/pkgs/types/plugins.d.ts +2 -3
- package/dist/pkgs/types/plugins.d.ts.map +1 -1
- package/dist/pkgs/utils/index.d.ts +1 -0
- package/dist/pkgs/utils/index.d.ts.map +1 -1
- package/dist/pkgs/utils/logger.d.ts +16 -0
- package/dist/pkgs/utils/logger.d.ts.map +1 -0
- package/dist/router.cjs +1213 -0
- package/dist/router.d.ts +480 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1169 -0
- package/dist/schema/audit-log/table.d.ts +1 -1
- package/dist/schema/consent/table.d.ts +1 -1
- package/dist/schema/consent-policy/registry.d.ts +12 -12
- package/dist/schema/consent-policy/schema.d.ts +6 -6
- package/dist/schema/consent-policy/table.d.ts +7 -7
- package/dist/schema/consent-purpose/registry.d.ts +6 -6
- package/dist/schema/consent-purpose/schema.d.ts +6 -6
- package/dist/schema/consent-purpose/table.d.ts +7 -7
- package/dist/schema/consent-record/table.d.ts +1 -1
- package/dist/schema/create-registry.d.ts +32 -32
- package/dist/schema/definition.d.ts +19 -19
- package/dist/schema/domain/registry.d.ts +10 -10
- package/dist/schema/domain/schema.d.ts +5 -5
- package/dist/schema/domain/table.d.ts +6 -6
- package/dist/schema/index.cjs +1409 -1775
- package/dist/schema/index.js +20 -385
- package/dist/schema/schemas.d.ts +19 -19
- package/dist/schema/subject/registry.d.ts +4 -4
- package/dist/schema/subject/schema.d.ts +2 -2
- package/dist/schema/subject/table.d.ts +3 -3
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/testing/contract-testing.d.ts +37 -0
- package/dist/testing/contract-testing.d.ts.map +1 -0
- package/dist/types/context.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/options.d.ts +33 -2
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +3 -4
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +22 -30
- package/rslib.config.ts +2 -5
- package/src/contracts/consent/index.test.ts +5 -0
- package/src/contracts/consent/index.ts +9 -0
- package/src/contracts/consent/post.contract.test.ts +526 -0
- package/src/contracts/consent/post.contract.ts +160 -0
- package/src/contracts/consent/show-banner.contract.test.ts +214 -0
- package/src/contracts/consent/show-banner.contract.ts +45 -0
- package/src/contracts/consent/verify.contract.test.ts +185 -0
- package/src/contracts/consent/verify.contract.ts +126 -0
- package/src/contracts/index.ts +18 -0
- package/src/contracts/meta/index.test.ts +5 -0
- package/src/contracts/meta/index.ts +5 -0
- package/src/contracts/meta/status.contract.test.ts +338 -0
- package/src/contracts/meta/status.contract.ts +37 -0
- package/src/contracts/shared/jurisdiction.schema.ts +30 -0
- package/src/core.ts +451 -159
- package/src/handlers/consent/index.ts +9 -0
- package/src/handlers/consent/post.handler.ts +273 -0
- package/src/handlers/consent/show-banner.handler.test.ts +148 -0
- package/src/handlers/consent/show-banner.handler.ts +150 -0
- package/src/handlers/consent/verify.handler.ts +305 -0
- package/src/handlers/meta/index.ts +5 -0
- package/src/handlers/meta/status.handler.ts +47 -0
- package/src/init.ts +8 -5
- package/src/pkgs/api-router/hooks/__tests__/processor.test.ts +6 -0
- package/src/pkgs/api-router/hooks/processor.ts +2 -0
- package/src/pkgs/api-router/types/router-props.ts +1 -1
- package/src/pkgs/api-router/utils/cors.ts +1 -1
- package/src/pkgs/data-model/fields/field-types.ts +1 -1
- package/src/pkgs/data-model/fields/id-generator.ts +1 -1
- package/src/pkgs/db-adapters/README.md +3 -3
- package/src/pkgs/db-adapters/adapter-factory.ts +8 -4
- package/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts +13 -13
- package/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/postgres.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/sqlite.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts +2 -2
- package/src/pkgs/migrations/get-migration.ts +3 -3
- package/src/pkgs/migrations/get-schema/get-schema.ts +2 -2
- package/src/pkgs/migrations/get-schema/index.ts +1 -1
- package/src/pkgs/migrations/migration-builders.ts +2 -2
- package/src/pkgs/migrations/migration-execution.ts +2 -2
- package/src/pkgs/migrations/schema-comparison.ts +5 -4
- package/src/pkgs/results/__tests__/error-class.test.ts +8 -7
- package/src/pkgs/results/core/error-class.ts +31 -43
- package/src/pkgs/results/index.ts +0 -10
- package/src/pkgs/results/orpc-error-handler.ts +137 -0
- package/src/pkgs/results/types.ts +8 -7
- package/src/pkgs/types/context.ts +18 -4
- package/src/pkgs/types/endpoints.ts +3 -5
- package/src/pkgs/types/options.ts +2 -3
- package/src/pkgs/types/plugins.ts +2 -3
- package/src/pkgs/utils/index.ts +1 -0
- package/src/pkgs/utils/logger.ts +38 -0
- package/src/router.ts +8 -0
- package/src/schema/audit-log/table.ts +1 -1
- package/src/schema/consent/table.ts +1 -1
- package/src/schema/consent-policy/table.ts +1 -1
- package/src/schema/consent-purpose/table.ts +1 -1
- package/src/schema/consent-record/table.ts +1 -1
- package/src/schema/definition.ts +2 -2
- package/src/schema/domain/table.ts +1 -1
- package/src/schema/subject/table.ts +1 -1
- package/src/server.ts +130 -0
- package/src/testing/contract-testing.ts +437 -0
- package/src/types/context.ts +1 -1
- package/src/types/index.ts +2 -2
- package/src/types/options.ts +38 -2
- package/src/types/plugins.ts +3 -4
- package/dist/index.cjs +0 -3701
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/init.test.d.ts +0 -2
- package/dist/init.test.d.ts.map +0 -1
- package/dist/integrations/cloudflare.cjs +0 -312
- package/dist/integrations/cloudflare.d.ts +0 -32
- package/dist/integrations/cloudflare.d.ts.map +0 -1
- package/dist/integrations/cloudflare.js +0 -278
- package/dist/integrations/next.cjs +0 -276
- package/dist/integrations/next.d.ts +0 -68
- package/dist/integrations/next.d.ts.map +0 -1
- package/dist/integrations/next.js +0 -239
- package/dist/integrations/node.cjs +0 -257
- package/dist/integrations/node.d.ts +0 -29
- package/dist/integrations/node.d.ts.map +0 -1
- package/dist/integrations/node.js +0 -223
- package/dist/pkgs/api-router/index.d.ts +0 -9
- package/dist/pkgs/api-router/index.d.ts.map +0 -1
- package/dist/pkgs/api-router/utils/define-route.d.ts +0 -87
- package/dist/pkgs/api-router/utils/define-route.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/integration.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/integration.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/types.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/types.test.d.ts.map +0 -1
- package/dist/pkgs/logger/console-formatter.d.ts +0 -56
- package/dist/pkgs/logger/console-formatter.d.ts.map +0 -1
- package/dist/pkgs/logger/index.cjs +0 -240
- package/dist/pkgs/logger/index.d.ts +0 -35
- package/dist/pkgs/logger/index.d.ts.map +0 -1
- package/dist/pkgs/logger/index.js +0 -185
- package/dist/pkgs/logger/log-levels.d.ts +0 -29
- package/dist/pkgs/logger/log-levels.d.ts.map +0 -1
- package/dist/pkgs/logger/logger-factory.d.ts +0 -42
- package/dist/pkgs/logger/logger-factory.d.ts.map +0 -1
- package/dist/pkgs/logger/result-logging.d.ts +0 -71
- package/dist/pkgs/logger/result-logging.d.ts.map +0 -1
- package/dist/pkgs/logger/telemetry.d.ts +0 -14
- package/dist/pkgs/logger/telemetry.d.ts.map +0 -1
- package/dist/pkgs/logger/types.d.ts +0 -121
- package/dist/pkgs/logger/types.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/h3-integration.d.ts +0 -52
- package/dist/pkgs/results/h3-integration.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts +0 -101
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts +0 -89
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts.map +0 -1
- package/dist/response-types.d.ts +0 -19
- package/dist/response-types.d.ts.map +0 -1
- package/dist/routes/__test__/index.test.d.ts +0 -17
- package/dist/routes/__test__/index.test.d.ts.map +0 -1
- package/dist/routes/__test__/set-consent.test.d.ts +0 -2
- package/dist/routes/__test__/set-consent.test.d.ts.map +0 -1
- package/dist/routes/__test__/show-consent-banner.test.d.ts +0 -2
- package/dist/routes/__test__/show-consent-banner.test.d.ts.map +0 -1
- package/dist/routes/__test__/status.test.d.ts +0 -2
- package/dist/routes/__test__/status.test.d.ts.map +0 -1
- package/dist/routes/__test__/verify-consent.test.d.ts +0 -2
- package/dist/routes/__test__/verify-consent.test.d.ts.map +0 -1
- package/dist/routes/index.d.ts +0 -3
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/set-consent.d.ts +0 -89
- package/dist/routes/set-consent.d.ts.map +0 -1
- package/dist/routes/show-consent-banner.d.ts +0 -15
- package/dist/routes/show-consent-banner.d.ts.map +0 -1
- package/dist/routes/status.d.ts +0 -44
- package/dist/routes/status.d.ts.map +0 -1
- package/dist/routes/types.d.ts +0 -7
- package/dist/routes/types.d.ts.map +0 -1
- package/dist/routes/verify-consent.d.ts +0 -38
- package/dist/routes/verify-consent.d.ts.map +0 -1
- package/src/docs/ADVANCED_JSON_HANDLING.md +0 -99
- package/src/docs/neverthrow.md +0 -171
- package/src/index.ts +0 -34
- package/src/init.test.ts +0 -219
- package/src/integrations/cloudflare.ts +0 -269
- package/src/integrations/next.ts +0 -204
- package/src/integrations/node.ts +0 -141
- package/src/pkgs/api-router/index.ts +0 -148
- package/src/pkgs/api-router/types/h3.d.ts +0 -42
- package/src/pkgs/api-router/utils/define-route.ts +0 -410
- package/src/pkgs/logger/README.md +0 -213
- package/src/pkgs/logger/__tests__/console-formatter.test.ts +0 -67
- package/src/pkgs/logger/__tests__/integration.test.ts +0 -184
- package/src/pkgs/logger/__tests__/log-levels.test.ts +0 -77
- package/src/pkgs/logger/__tests__/logger-factory.test.ts +0 -156
- package/src/pkgs/logger/__tests__/result-logging.test.ts +0 -209
- package/src/pkgs/logger/__tests__/types.test.ts +0 -94
- package/src/pkgs/logger/console-formatter.ts +0 -75
- package/src/pkgs/logger/doc.md +0 -569
- package/src/pkgs/logger/index.ts +0 -59
- package/src/pkgs/logger/log-levels.ts +0 -46
- package/src/pkgs/logger/logger-factory.ts +0 -121
- package/src/pkgs/logger/result-logging.ts +0 -134
- package/src/pkgs/logger/telemetry.ts +0 -96
- package/src/pkgs/logger/types.ts +0 -138
- package/src/pkgs/results/__tests__/retrieval-pipeline.test.ts +0 -157
- package/src/pkgs/results/__tests__/validation-pipeline.test.ts +0 -151
- package/src/pkgs/results/h3-integration.ts +0 -142
- package/src/pkgs/results/pipeline/retrieval-pipeline.ts +0 -188
- package/src/pkgs/results/pipeline/validation-pipeline.ts +0 -164
- package/src/plugins/.keep +0 -0
- package/src/response-types.ts +0 -29
- package/src/routes/__test__/index.test.ts +0 -112
- package/src/routes/__test__/set-consent.test.ts +0 -242
- package/src/routes/__test__/show-consent-banner.test.ts +0 -98
- package/src/routes/__test__/status.test.ts +0 -64
- package/src/routes/__test__/verify-consent.test.ts +0 -266
- package/src/routes/index.ts +0 -12
- package/src/routes/set-consent.ts +0 -249
- package/src/routes/show-consent-banner.ts +0 -131
- package/src/routes/status.ts +0 -61
- package/src/routes/types.ts +0 -7
- package/src/routes/verify-consent.ts +0 -206
package/dist/routes/status.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Response type for the status endpoint
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export interface StatusResponse {
|
|
6
|
-
status: 'ok' | 'error';
|
|
7
|
-
version: string;
|
|
8
|
-
timestamp: string;
|
|
9
|
-
storage: {
|
|
10
|
-
type: string;
|
|
11
|
-
available: boolean;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Status endpoint that returns information about the c15t instance.
|
|
16
|
-
*
|
|
17
|
-
* This endpoint provides basic operational information about the c15t instance,
|
|
18
|
-
* including its version, current timestamp, and storage adapter configuration.
|
|
19
|
-
* It can be used for:
|
|
20
|
-
* - Health checks to verify the API is operational
|
|
21
|
-
* - Version verification
|
|
22
|
-
* - Storage adapter verification
|
|
23
|
-
* - Retrieving configuration information about the consent system
|
|
24
|
-
*
|
|
25
|
-
* The endpoint does not require authentication and is accessible via a GET request.
|
|
26
|
-
*
|
|
27
|
-
* @endpoint GET /status
|
|
28
|
-
* @responseExample
|
|
29
|
-
* ```json
|
|
30
|
-
* {
|
|
31
|
-
* "status": "ok",
|
|
32
|
-
* "version": "1.0.0",
|
|
33
|
-
* "timestamp": "2023-04-01T12:34:56.789Z",
|
|
34
|
-
* "storage": {
|
|
35
|
-
* "type": "MemoryAdapter",
|
|
36
|
-
* "available": true
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare const status: import("./types").Route & {
|
|
42
|
-
responseType: StatusResponse;
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/routes/status.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,OAAO,CAAC;KACnB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,MAAM;;CAgBjB,CAAC"}
|
package/dist/routes/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/routes/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAErD,MAAM,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,YAAY,CAAC;CACtB,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
interface Consent {
|
|
3
|
-
id: string;
|
|
4
|
-
purposeIds: string[];
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
}
|
|
7
|
-
export interface VerifyConsentResponse {
|
|
8
|
-
isValid: boolean;
|
|
9
|
-
reasons?: string[];
|
|
10
|
-
consent?: Consent;
|
|
11
|
-
}
|
|
12
|
-
export declare const VerifyConsentRequestBody: z.ZodObject<{
|
|
13
|
-
subjectId: z.ZodOptional<z.ZodString>;
|
|
14
|
-
externalSubjectId: z.ZodOptional<z.ZodString>;
|
|
15
|
-
domain: z.ZodString;
|
|
16
|
-
type: z.ZodEnum<["cookie_banner", "privacy_policy", "dpa", "terms_and_conditions", "marketing_communications", "age_verification", "other"]>;
|
|
17
|
-
policyId: z.ZodOptional<z.ZodString>;
|
|
18
|
-
preferences: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
19
|
-
}, "strip", z.ZodTypeAny, {
|
|
20
|
-
type: "cookie_banner" | "privacy_policy" | "dpa" | "terms_and_conditions" | "marketing_communications" | "age_verification" | "other";
|
|
21
|
-
domain: string;
|
|
22
|
-
subjectId?: string | undefined;
|
|
23
|
-
policyId?: string | undefined;
|
|
24
|
-
externalSubjectId?: string | undefined;
|
|
25
|
-
preferences?: string[] | undefined;
|
|
26
|
-
}, {
|
|
27
|
-
type: "cookie_banner" | "privacy_policy" | "dpa" | "terms_and_conditions" | "marketing_communications" | "age_verification" | "other";
|
|
28
|
-
domain: string;
|
|
29
|
-
subjectId?: string | undefined;
|
|
30
|
-
policyId?: string | undefined;
|
|
31
|
-
externalSubjectId?: string | undefined;
|
|
32
|
-
preferences?: string[] | undefined;
|
|
33
|
-
}>;
|
|
34
|
-
export declare const verifyConsent: import("./types").Route & {
|
|
35
|
-
responseType: VerifyConsentResponse;
|
|
36
|
-
};
|
|
37
|
-
export {};
|
|
38
|
-
//# sourceMappingURL=verify-consent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verify-consent.d.ts","sourceRoot":"","sources":["../../src/routes/verify-consent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,UAAU,OAAO;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;EAOnC,CAAC;AAEH,eAAO,MAAM,aAAa;;CAyGxB,CAAC"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# Advanced JSON and Date Handling in C15T
|
|
2
|
-
|
|
3
|
-
C15T provides intelligent, database-specific handling for JSON data and date/time values to ensure maximum compatibility and performance across different database systems. This document explains how data is stored and accessed in different database environments.
|
|
4
|
-
|
|
5
|
-
## SuperJSON Integration
|
|
6
|
-
|
|
7
|
-
C15T uses [SuperJSON](https://github.com/blitz-js/superjson) to enhance JSON serialization for complex JavaScript types that aren't natively supported by JSON, such as:
|
|
8
|
-
|
|
9
|
-
- `Date` objects with timezone information
|
|
10
|
-
- JavaScript `Map` and `Set` objects
|
|
11
|
-
- `BigInt` values
|
|
12
|
-
- `undefined` values
|
|
13
|
-
- Custom class instances
|
|
14
|
-
- And more
|
|
15
|
-
|
|
16
|
-
## Database-Specific Behavior
|
|
17
|
-
|
|
18
|
-
### PostgreSQL
|
|
19
|
-
|
|
20
|
-
PostgreSQL has excellent native support for both JSON and timestamps with timezone:
|
|
21
|
-
|
|
22
|
-
- **JSON fields**: Uses native JSONB type for most JSON data, with SuperJSON only applied when needed for complex JS types
|
|
23
|
-
- **Date fields**: Uses native TIMESTAMPTZ which properly preserves timezone information
|
|
24
|
-
- **Benefits**: Offers high performance and the ability to perform JSON path queries directly in the database
|
|
25
|
-
|
|
26
|
-
### MySQL
|
|
27
|
-
|
|
28
|
-
MySQL has native JSON support but more limited date/timezone handling:
|
|
29
|
-
|
|
30
|
-
- **JSON fields**: Uses native JSON type with SuperJSON selectively applied for complex types
|
|
31
|
-
- **Date fields**: Uses consistent timezone handling to ensure predictable behavior
|
|
32
|
-
- **Benefits**: Provides good balance between native database features and JavaScript type support
|
|
33
|
-
|
|
34
|
-
### SQLite
|
|
35
|
-
|
|
36
|
-
SQLite has no native JSON or timezone-aware date types:
|
|
37
|
-
|
|
38
|
-
- **JSON fields**: Always uses SuperJSON format stored as TEXT to preserve all JavaScript types
|
|
39
|
-
- **Date fields**: Uses special handling to maintain timezone information
|
|
40
|
-
- **Benefits**: Maintains complete JavaScript data structures even with SQLite's simpler type system
|
|
41
|
-
|
|
42
|
-
## Implications for Your Application
|
|
43
|
-
|
|
44
|
-
### Accessing Data Outside C15T
|
|
45
|
-
|
|
46
|
-
When accessing data stored by C15T from outside the library (e.g., direct database queries), be aware:
|
|
47
|
-
|
|
48
|
-
- **PostgreSQL data**: Most fields can be accessed directly without special handling
|
|
49
|
-
- **MySQL data**: Complex values might be in SuperJSON format (look for `{"json":..., "meta":...}` structure)
|
|
50
|
-
- **SQLite data**: All JSON and date fields will be in SuperJSON format and require parsing
|
|
51
|
-
|
|
52
|
-
To parse SuperJSON data outside of C15T:
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
// If using SuperJSON
|
|
56
|
-
const data = superjson.parse(valueFromDatabase);
|
|
57
|
-
|
|
58
|
-
// Without SuperJSON, you can manually extract the data
|
|
59
|
-
const parsed = JSON.parse(valueFromDatabase);
|
|
60
|
-
const actualData = parsed.json; // The actual data is in the 'json' property
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Best Practices
|
|
64
|
-
|
|
65
|
-
1. **Use C15T's API** when possible to abstract away database differences
|
|
66
|
-
2. **Document data format** if you expect other systems to access the database directly
|
|
67
|
-
3. **Consider database requirements** when designing systems that need to use multiple database types
|
|
68
|
-
4. **Test across databases** if your application needs to support multiple database types
|
|
69
|
-
|
|
70
|
-
## Configuration
|
|
71
|
-
|
|
72
|
-
The database-specific handling is applied automatically based on your database configuration when you initialize C15T.
|
|
73
|
-
|
|
74
|
-
If needed, you can manually set the database type:
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import { setDatabaseType } from '@c15t/backend/db/core/fields/superjson-utils';
|
|
78
|
-
|
|
79
|
-
// Must be called before using any field operations
|
|
80
|
-
setDatabaseType('sqlite'); // or 'postgresql', 'mysql'
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Extending SuperJSON
|
|
84
|
-
|
|
85
|
-
If you need to support additional custom types with SuperJSON, you can register them:
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
import superjson from 'superjson';
|
|
89
|
-
|
|
90
|
-
// Register a custom type
|
|
91
|
-
superjson.registerCustom<MyCustomType, string>(
|
|
92
|
-
// isMyType check
|
|
93
|
-
(v) => v instanceof MyCustomType,
|
|
94
|
-
// serialize
|
|
95
|
-
(v) => v.toString(),
|
|
96
|
-
// deserialize
|
|
97
|
-
(v) => new MyCustomType(v)
|
|
98
|
-
);
|
|
99
|
-
```
|
package/src/docs/neverthrow.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
# Using neverthrow in c15t
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The c15t library now supports a functional approach to error handling using the [neverthrow](https://github.com/supermacro/neverthrow) library. This approach provides several benefits:
|
|
6
|
-
|
|
7
|
-
- More explicit error handling with the `Result` type
|
|
8
|
-
- Better type safety and compile-time checks for error cases
|
|
9
|
-
- Ability to chain operations with proper error propagation
|
|
10
|
-
- No need for try/catch blocks or exception handling
|
|
11
|
-
- Clearer and more predictable code flow
|
|
12
|
-
|
|
13
|
-
This document explains how to use the neverthrow `Result` pattern with c15t.
|
|
14
|
-
|
|
15
|
-
## Basic Concepts
|
|
16
|
-
|
|
17
|
-
The core concept of neverthrow is the `Result` type, which represents either:
|
|
18
|
-
|
|
19
|
-
- A successful operation (`Ok` variant) containing a value, or
|
|
20
|
-
- A failed operation (`Err` variant) containing an error
|
|
21
|
-
|
|
22
|
-
Instead of throwing exceptions, functions return a `Result` that must be handled explicitly.
|
|
23
|
-
|
|
24
|
-
### Result vs Traditional Error Handling
|
|
25
|
-
|
|
26
|
-
Traditional approach:
|
|
27
|
-
```typescript
|
|
28
|
-
try {
|
|
29
|
-
const context = await init(options);
|
|
30
|
-
// Use context...
|
|
31
|
-
} catch (error) {
|
|
32
|
-
// Handle errors...
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
neverthrow approach:
|
|
37
|
-
```typescript
|
|
38
|
-
const contextResult = await init(options);
|
|
39
|
-
contextResult.match({
|
|
40
|
-
ok: (context) => {
|
|
41
|
-
// Use context...
|
|
42
|
-
},
|
|
43
|
-
err: (error) => {
|
|
44
|
-
// Handle errors...
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Using c15t with neverthrow
|
|
50
|
-
|
|
51
|
-
### Initialization
|
|
52
|
-
|
|
53
|
-
The c15t library provides two versions of most core functions:
|
|
54
|
-
|
|
55
|
-
1. Traditional functions that might throw exceptions (for backward compatibility)
|
|
56
|
-
2. New functions with the `WithResult` suffix that return `Result` objects
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { c15tWithResult } from '@c15t/backend';
|
|
60
|
-
import { memoryAdapter } from '@c15t/backend/db/adapters/memory';
|
|
61
|
-
|
|
62
|
-
// Create a c15t instance with Result-based error handling
|
|
63
|
-
const c15tInstance = c15tWithResult({
|
|
64
|
-
secret: 'your-secret-key',
|
|
65
|
-
storage: memoryAdapter(),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// The context is now a ResultAsync
|
|
69
|
-
c15tInstance.$context.match({
|
|
70
|
-
ok: (context) => {
|
|
71
|
-
console.log(`Initialized ${context.appName} successfully`);
|
|
72
|
-
},
|
|
73
|
-
err: (error) => {
|
|
74
|
-
console.error(`Initialization failed: ${error.message}`);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Request Handling
|
|
80
|
-
|
|
81
|
-
The Result-based instance provides both traditional and Result-based handlers:
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
// Traditional approach (might throw)
|
|
85
|
-
app.use('/api/c15t', async (req, res) => {
|
|
86
|
-
try {
|
|
87
|
-
const response = await c15tInstance.handler(request);
|
|
88
|
-
// Handle response...
|
|
89
|
-
} catch (error) {
|
|
90
|
-
// Handle error...
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Result-based approach
|
|
95
|
-
app.use('/api/c15t', async (req, res) => {
|
|
96
|
-
const requestResult = await c15tInstance.handlerWithResult(request);
|
|
97
|
-
|
|
98
|
-
requestResult.match({
|
|
99
|
-
ok: (response) => {
|
|
100
|
-
// Handle successful response...
|
|
101
|
-
},
|
|
102
|
-
err: (error) => {
|
|
103
|
-
// Handle error with structured data...
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Error Types
|
|
110
|
-
|
|
111
|
-
All errors are instances of `C15TError` with properties:
|
|
112
|
-
|
|
113
|
-
- `message`: Human-readable error message
|
|
114
|
-
- `code`: Error code from `BASE_ERROR_CODES`
|
|
115
|
-
- `status`: HTTP status code when applicable
|
|
116
|
-
- `data`: Additional error data
|
|
117
|
-
|
|
118
|
-
### Chaining Operations
|
|
119
|
-
|
|
120
|
-
One of the major benefits of the neverthrow approach is the ability to chain operations with proper error handling:
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
c15tInstance.$context
|
|
124
|
-
.andThen(context => {
|
|
125
|
-
// Use context to perform another operation
|
|
126
|
-
return c15tInstance.handlerWithResult(request);
|
|
127
|
-
})
|
|
128
|
-
.map(response => {
|
|
129
|
-
// Transform successful response
|
|
130
|
-
return response.json();
|
|
131
|
-
})
|
|
132
|
-
.mapErr(error => {
|
|
133
|
-
// Transform or enrich error
|
|
134
|
-
console.error(`Error: ${error.message}`);
|
|
135
|
-
return error;
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Combining with Promises
|
|
140
|
-
|
|
141
|
-
You can convert between Results and Promises:
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
import { toPromise, fromC15TPromise } from '@c15t/backend/utils';
|
|
145
|
-
|
|
146
|
-
// Convert Result to Promise (might throw)
|
|
147
|
-
const contextPromise = toPromise(c15tInstance.$context);
|
|
148
|
-
|
|
149
|
-
// Convert Promise to Result
|
|
150
|
-
const resultFromPromise = fromC15TPromise(somePromise);
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Complete Example
|
|
154
|
-
|
|
155
|
-
See the complete example at `packages/c15t/src/examples/neverthrow-example.ts`.
|
|
156
|
-
|
|
157
|
-
## Best Practices
|
|
158
|
-
|
|
159
|
-
1. **Be explicit about errors**: Use the `match` method to handle both success and error cases explicitly.
|
|
160
|
-
|
|
161
|
-
2. **Chain operations**: Use `andThen`, `map`, and `mapErr` to chain operations and transformations.
|
|
162
|
-
|
|
163
|
-
3. **Type your errors**: Make use of error codes to handle specific error conditions.
|
|
164
|
-
|
|
165
|
-
4. **Avoid mixing patterns**: Stick to either the Result pattern or traditional try/catch within a single function.
|
|
166
|
-
|
|
167
|
-
5. **Convert at boundaries**: Use conversion utilities when interacting with code that doesn't use the Result pattern.
|
|
168
|
-
|
|
169
|
-
## Backward Compatibility
|
|
170
|
-
|
|
171
|
-
The c15t library maintains backward compatibility with the traditional error handling approach. You can continue using the existing API, or gradually migrate to the Result pattern.
|
package/src/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* c15t Consent Management System
|
|
3
|
-
*
|
|
4
|
-
* This is the main entry point for the c15t library, exporting all public APIs,
|
|
5
|
-
* components, and types needed to implement consent management in your application.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
//------------------------------------------------------------------------------
|
|
9
|
-
// Core API
|
|
10
|
-
//------------------------------------------------------------------------------
|
|
11
|
-
export { c15tInstance, type C15TInstance } from './core';
|
|
12
|
-
|
|
13
|
-
//------------------------------------------------------------------------------
|
|
14
|
-
// Types
|
|
15
|
-
//------------------------------------------------------------------------------
|
|
16
|
-
export * as Types from './pkgs/types';
|
|
17
|
-
|
|
18
|
-
export type {
|
|
19
|
-
C15TContext,
|
|
20
|
-
C15TOptions,
|
|
21
|
-
C15TPlugin,
|
|
22
|
-
InferPluginContexts,
|
|
23
|
-
ApiPathBase,
|
|
24
|
-
ApiPath,
|
|
25
|
-
} from './types';
|
|
26
|
-
|
|
27
|
-
// Export all the response types to make them available for client applications
|
|
28
|
-
export type {
|
|
29
|
-
SetConsentResponse,
|
|
30
|
-
ShowConsentBannerResponse,
|
|
31
|
-
VerifyConsentResponse,
|
|
32
|
-
SetConsentRequestBody,
|
|
33
|
-
VerifyConsentRequestBody,
|
|
34
|
-
} from './response-types';
|
package/src/init.test.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import type { DatabaseConfiguration } from '~/pkgs/db-adapters/adapters/kysely-adapter/types';
|
|
3
|
-
import { memoryAdapter } from '~/pkgs/db-adapters/adapters/memory-adapter';
|
|
4
|
-
import type { C15TPlugin } from '~/types';
|
|
5
|
-
import { init } from './init';
|
|
6
|
-
|
|
7
|
-
describe('init', () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
vi.unstubAllEnvs();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should initialize with basic config', async () => {
|
|
13
|
-
const result = await init({
|
|
14
|
-
baseURL: 'http://localhost:3000',
|
|
15
|
-
appName: 'c15t Consent Manager',
|
|
16
|
-
database: memoryAdapter({}),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
expect(result.isOk()).toBe(true);
|
|
20
|
-
if (result.isOk()) {
|
|
21
|
-
const ctx = result.value;
|
|
22
|
-
expect(ctx.options.baseURL).toBe('http://localhost:3000');
|
|
23
|
-
expect(ctx.options.basePath).toBe('/api/c15t');
|
|
24
|
-
expect(ctx.appName).toBe('c15t Consent Manager');
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should infer base URL from environment', async () => {
|
|
29
|
-
vi.stubEnv('C15T_URL', 'http://localhost:5147');
|
|
30
|
-
|
|
31
|
-
const result = await init({
|
|
32
|
-
database: memoryAdapter({}),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect(result.isOk()).toBe(true);
|
|
36
|
-
if (result.isOk()) {
|
|
37
|
-
const ctx = result.value;
|
|
38
|
-
expect(ctx.options.baseURL).toBe('http://localhost:5147');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
vi.unstubAllEnvs();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should respect custom base path', async () => {
|
|
45
|
-
const result = await init({
|
|
46
|
-
baseURL: 'http://localhost:3000',
|
|
47
|
-
basePath: '/custom-path',
|
|
48
|
-
database: memoryAdapter({}),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
expect(result.isOk()).toBe(true);
|
|
52
|
-
if (result.isOk()) {
|
|
53
|
-
const ctx = result.value;
|
|
54
|
-
expect(ctx.options.basePath).toBe('/custom-path');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should initialize plugins', async () => {
|
|
59
|
-
const newBaseURL = 'http://test.test';
|
|
60
|
-
const result = await init({
|
|
61
|
-
baseURL: 'http://localhost:3000',
|
|
62
|
-
database: memoryAdapter({}),
|
|
63
|
-
plugins: [
|
|
64
|
-
{
|
|
65
|
-
id: 'test-plugin',
|
|
66
|
-
name: 'Test Plugin',
|
|
67
|
-
type: 'test',
|
|
68
|
-
init: () => ({
|
|
69
|
-
context: {
|
|
70
|
-
baseURL: newBaseURL,
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
} as C15TPlugin,
|
|
74
|
-
],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(result.isOk()).toBe(true);
|
|
78
|
-
if (result.isOk()) {
|
|
79
|
-
const ctx = result.value;
|
|
80
|
-
expect(ctx.baseURL).toBe(newBaseURL);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should allow plugins to modify options', async () => {
|
|
85
|
-
const result = await init({
|
|
86
|
-
baseURL: 'http://localhost:3000',
|
|
87
|
-
database: memoryAdapter({}),
|
|
88
|
-
plugins: [
|
|
89
|
-
{
|
|
90
|
-
id: 'test-plugin',
|
|
91
|
-
name: 'Test Plugin',
|
|
92
|
-
type: 'test',
|
|
93
|
-
init: () => ({
|
|
94
|
-
options: {
|
|
95
|
-
baseURL: 'http://test.test',
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
} as C15TPlugin,
|
|
99
|
-
],
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
expect(result.isOk()).toBe(true);
|
|
103
|
-
if (result.isOk()) {
|
|
104
|
-
const ctx = result.value;
|
|
105
|
-
expect(ctx.options.baseURL).toBe('http://test.test');
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should handle plugin initialization errors', async () => {
|
|
110
|
-
const result = await init({
|
|
111
|
-
baseURL: 'http://localhost:3000',
|
|
112
|
-
database: memoryAdapter({}),
|
|
113
|
-
plugins: [
|
|
114
|
-
{
|
|
115
|
-
id: 'error-plugin',
|
|
116
|
-
name: 'Error Plugin',
|
|
117
|
-
type: 'test',
|
|
118
|
-
init: () => {
|
|
119
|
-
throw new Error('Plugin initialization failed');
|
|
120
|
-
},
|
|
121
|
-
} as C15TPlugin,
|
|
122
|
-
],
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
expect(result.isErr()).toBe(true);
|
|
126
|
-
if (result.isErr()) {
|
|
127
|
-
expect(result.error.message).toContain('Plugin initialization failed');
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should handle storage adapter errors', async () => {
|
|
132
|
-
const result = await init({
|
|
133
|
-
baseURL: 'http://localhost:3000',
|
|
134
|
-
database: null as unknown as DatabaseConfiguration,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(result.isErr()).toBe(false);
|
|
138
|
-
if (result.isErr()) {
|
|
139
|
-
expect(result.error.message).toContain(
|
|
140
|
-
'Failed to initialize consent system'
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should handle multiple plugins in sequence', async () => {
|
|
146
|
-
const result = await init({
|
|
147
|
-
baseURL: 'http://localhost:3000',
|
|
148
|
-
database: memoryAdapter({}),
|
|
149
|
-
plugins: [
|
|
150
|
-
{
|
|
151
|
-
id: 'plugin-1',
|
|
152
|
-
name: 'Plugin 1',
|
|
153
|
-
type: 'test',
|
|
154
|
-
init: () => ({
|
|
155
|
-
options: {
|
|
156
|
-
baseURL: 'http://plugin1.test',
|
|
157
|
-
},
|
|
158
|
-
}),
|
|
159
|
-
} as C15TPlugin,
|
|
160
|
-
{
|
|
161
|
-
id: 'plugin-2',
|
|
162
|
-
name: 'Plugin 2',
|
|
163
|
-
type: 'test',
|
|
164
|
-
init: () => ({
|
|
165
|
-
options: {
|
|
166
|
-
baseURL: 'http://plugin2.test',
|
|
167
|
-
},
|
|
168
|
-
}),
|
|
169
|
-
} as C15TPlugin,
|
|
170
|
-
],
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
expect(result.isOk()).toBe(true);
|
|
174
|
-
if (result.isOk()) {
|
|
175
|
-
const ctx = result.value;
|
|
176
|
-
expect(ctx.options.baseURL).toBe('http://plugin2.test');
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('should configure trusted origins', async () => {
|
|
181
|
-
const result = await init({
|
|
182
|
-
baseURL: 'http://localhost:3000',
|
|
183
|
-
database: memoryAdapter({}),
|
|
184
|
-
trustedOrigins: ['http://trusted.test', 'http://localhost:3000'],
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(result.isOk()).toBe(true);
|
|
188
|
-
if (result.isOk()) {
|
|
189
|
-
const ctx = result.value;
|
|
190
|
-
expect(ctx.trustedOrigins).toContain('http://localhost:3000');
|
|
191
|
-
expect(ctx.trustedOrigins).toContain('http://trusted.test');
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('should handle plugin context modifications', async () => {
|
|
196
|
-
const result = await init({
|
|
197
|
-
baseURL: 'http://localhost:3000',
|
|
198
|
-
database: memoryAdapter({}),
|
|
199
|
-
plugins: [
|
|
200
|
-
{
|
|
201
|
-
id: 'context-plugin',
|
|
202
|
-
name: 'Context Plugin',
|
|
203
|
-
type: 'test',
|
|
204
|
-
init: () => ({
|
|
205
|
-
context: {
|
|
206
|
-
appName: 'Modified App Name',
|
|
207
|
-
},
|
|
208
|
-
}),
|
|
209
|
-
} as C15TPlugin,
|
|
210
|
-
],
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
expect(result.isOk()).toBe(true);
|
|
214
|
-
if (result.isOk()) {
|
|
215
|
-
const ctx = result.value;
|
|
216
|
-
expect(ctx.appName).toBe('Modified App Name');
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
});
|