@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,269 +0,0 @@
|
|
|
1
|
-
import type { C15TInstance } from '~/core';
|
|
2
|
-
import { ERROR_CODES } from '~/pkgs/results';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Convert a c15t handler to a Cloudflare Worker handler.
|
|
6
|
-
*
|
|
7
|
-
* This adapter is specifically designed for Cloudflare Workers environments,
|
|
8
|
-
* avoiding Node.js-specific dependencies and APIs.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { toCloudflareHandler } from '@c15t/backend/integrations';
|
|
13
|
-
* import { c15tInstance } from '@c15t/backend';
|
|
14
|
-
*
|
|
15
|
-
* // Create c15t instance
|
|
16
|
-
* const c15t = c15tInstance({
|
|
17
|
-
* basePath: '/',
|
|
18
|
-
* cors: true,
|
|
19
|
-
* // other options...
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // Export the worker handler
|
|
23
|
-
* export default {
|
|
24
|
-
* async fetch(request, env, ctx) {
|
|
25
|
-
* return await toCloudflareHandler(c15t)(request);
|
|
26
|
-
* }
|
|
27
|
-
* };
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param instance - The c15t instance to adapt
|
|
31
|
-
* @returns A handler function suitable for Cloudflare Workers
|
|
32
|
-
*/
|
|
33
|
-
export function toCloudflareHandler(instance: C15TInstance) {
|
|
34
|
-
return async (request: Request): Promise<Response> => {
|
|
35
|
-
try {
|
|
36
|
-
const basePath: string =
|
|
37
|
-
(instance.options?.basePath as string) || '/api/c15t';
|
|
38
|
-
|
|
39
|
-
// Extract the path and rewrite for c15t routing
|
|
40
|
-
const originalUrl = new URL(request.url);
|
|
41
|
-
|
|
42
|
-
let pathWithoutBase = originalUrl.pathname;
|
|
43
|
-
|
|
44
|
-
// Handle CORS preflight requests directly
|
|
45
|
-
if (request.method === 'OPTIONS') {
|
|
46
|
-
return handleCorsPreflightRequest(request, instance);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (pathWithoutBase.startsWith(basePath)) {
|
|
50
|
-
pathWithoutBase = pathWithoutBase.substring(basePath.length);
|
|
51
|
-
// Ensure leading slash
|
|
52
|
-
if (!pathWithoutBase.startsWith('/')) {
|
|
53
|
-
pathWithoutBase = `/${pathWithoutBase}`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Create rewritten request with careful cloning to avoid stream issues
|
|
58
|
-
const rewrittenUrl = new URL(originalUrl.toString());
|
|
59
|
-
rewrittenUrl.pathname = pathWithoutBase;
|
|
60
|
-
|
|
61
|
-
const headers = new Headers();
|
|
62
|
-
for (const [key, value] of request.headers.entries()) {
|
|
63
|
-
headers.set(key, value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Create a new request without the credentials field which is not supported in Cloudflare Workers
|
|
67
|
-
const rewrittenRequest = new Request(rewrittenUrl.toString(), {
|
|
68
|
-
method: request.method,
|
|
69
|
-
headers,
|
|
70
|
-
body: ['GET', 'HEAD'].includes(request.method)
|
|
71
|
-
? undefined
|
|
72
|
-
: request.body,
|
|
73
|
-
duplex: ['GET', 'HEAD'].includes(request.method) ? undefined : 'half',
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// Let c15t handle the request
|
|
77
|
-
|
|
78
|
-
const result = await instance.handler(rewrittenRequest);
|
|
79
|
-
|
|
80
|
-
// Convert c15t response to standard Response with CORS headers
|
|
81
|
-
return await result.match(
|
|
82
|
-
// Success case - add CORS headers and return
|
|
83
|
-
(response) => {
|
|
84
|
-
return addCorsHeaders(response, request, instance);
|
|
85
|
-
},
|
|
86
|
-
// Error case - create an error response with CORS headers
|
|
87
|
-
(error) => {
|
|
88
|
-
const status = error.statusCode || 500;
|
|
89
|
-
const message = error.message || ERROR_CODES.INTERNAL_SERVER_ERROR;
|
|
90
|
-
|
|
91
|
-
const errorResponse = new Response(
|
|
92
|
-
JSON.stringify({
|
|
93
|
-
error: true,
|
|
94
|
-
code: error.code || ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
95
|
-
message,
|
|
96
|
-
meta: error.meta,
|
|
97
|
-
}),
|
|
98
|
-
{
|
|
99
|
-
status,
|
|
100
|
-
headers: {
|
|
101
|
-
'Content-Type': 'application/json',
|
|
102
|
-
},
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
return addCorsHeaders(errorResponse, request, instance);
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
// Basic error handling
|
|
111
|
-
|
|
112
|
-
const errorResponse = new Response(
|
|
113
|
-
JSON.stringify({
|
|
114
|
-
error: true,
|
|
115
|
-
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
116
|
-
message: 'An unexpected error occurred',
|
|
117
|
-
meta: { error: String(error) },
|
|
118
|
-
}),
|
|
119
|
-
{
|
|
120
|
-
status: 500,
|
|
121
|
-
headers: {
|
|
122
|
-
'Content-Type': 'application/json',
|
|
123
|
-
},
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
return addCorsHeaders(errorResponse, request, instance);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Handle CORS preflight requests directly
|
|
133
|
-
*/
|
|
134
|
-
function handleCorsPreflightRequest(
|
|
135
|
-
request: Request,
|
|
136
|
-
instance: C15TInstance
|
|
137
|
-
): Response {
|
|
138
|
-
const origin = request.headers.get('Origin');
|
|
139
|
-
const isTrusted = isTrustedOrigin(origin, instance);
|
|
140
|
-
|
|
141
|
-
const headers = new Headers({
|
|
142
|
-
'Access-Control-Allow-Origin': isTrusted && origin ? origin : '*',
|
|
143
|
-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
|
144
|
-
'Access-Control-Allow-Headers':
|
|
145
|
-
'Content-Type, Authorization, x-request-id',
|
|
146
|
-
'Access-Control-Max-Age': '86400',
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Add credentials header if trusted origin
|
|
150
|
-
if (isTrusted) {
|
|
151
|
-
headers.set('Access-Control-Allow-Credentials', 'true');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return new Response(null, {
|
|
155
|
-
status: 204,
|
|
156
|
-
headers,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Add CORS headers to a response
|
|
162
|
-
*/
|
|
163
|
-
function addCorsHeaders(
|
|
164
|
-
response: Response,
|
|
165
|
-
request: Request,
|
|
166
|
-
instance: C15TInstance
|
|
167
|
-
): Response {
|
|
168
|
-
const origin = request.headers.get('Origin');
|
|
169
|
-
const isTrusted = isTrustedOrigin(origin, instance);
|
|
170
|
-
|
|
171
|
-
const newResponse = new Response(response.body, {
|
|
172
|
-
status: response.status,
|
|
173
|
-
statusText: response.statusText,
|
|
174
|
-
headers: response.headers,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Set CORS headers
|
|
178
|
-
newResponse.headers.set(
|
|
179
|
-
'Access-Control-Allow-Origin',
|
|
180
|
-
isTrusted && origin ? origin : '*'
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
// Add credentials header if trusted origin
|
|
184
|
-
if (isTrusted) {
|
|
185
|
-
newResponse.headers.set('Access-Control-Allow-Credentials', 'true');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return newResponse;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Check if origin is trusted
|
|
193
|
-
*/
|
|
194
|
-
function isTrustedOrigin(
|
|
195
|
-
origin: string | null,
|
|
196
|
-
instance: C15TInstance
|
|
197
|
-
): boolean {
|
|
198
|
-
if (!origin) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Get trusted origins from options
|
|
203
|
-
const { trustedOrigins = [] } = instance.options || {};
|
|
204
|
-
|
|
205
|
-
// Normalize trustedOrigins to array of strings
|
|
206
|
-
let originsArray: string[] = [];
|
|
207
|
-
|
|
208
|
-
if (Array.isArray(trustedOrigins)) {
|
|
209
|
-
// Handle potential nested array from env vars: ["localhost"] becomes ["localhost"]
|
|
210
|
-
originsArray = trustedOrigins.map((item) => {
|
|
211
|
-
// If item is a string that looks like an array element (has quotes and brackets)
|
|
212
|
-
if (
|
|
213
|
-
typeof item === 'string' &&
|
|
214
|
-
((item.startsWith('"') && item.endsWith('"')) ||
|
|
215
|
-
(item.startsWith('[') && item.endsWith(']')))
|
|
216
|
-
) {
|
|
217
|
-
try {
|
|
218
|
-
const parsed = JSON.parse(item);
|
|
219
|
-
return typeof parsed === 'string' ? parsed : item;
|
|
220
|
-
} catch {
|
|
221
|
-
return item;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return item;
|
|
225
|
-
});
|
|
226
|
-
} else if (typeof trustedOrigins === 'string') {
|
|
227
|
-
// Try to parse as JSON if it looks like an array
|
|
228
|
-
if (
|
|
229
|
-
(trustedOrigins as string).startsWith('[') &&
|
|
230
|
-
(trustedOrigins as string).endsWith(']')
|
|
231
|
-
) {
|
|
232
|
-
try {
|
|
233
|
-
const parsed = JSON.parse(trustedOrigins as string);
|
|
234
|
-
originsArray = Array.isArray(parsed) ? parsed : [trustedOrigins];
|
|
235
|
-
} catch {
|
|
236
|
-
originsArray = [trustedOrigins];
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
originsArray = [trustedOrigins];
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// If wildcard is included, all origins are trusted
|
|
244
|
-
if (originsArray.includes('*')) {
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// 1. Check exact match
|
|
249
|
-
const isExactMatch = originsArray.includes(origin);
|
|
250
|
-
if (isExactMatch) {
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// 2. Check domain-based matching
|
|
255
|
-
try {
|
|
256
|
-
const originUrl = new URL(origin);
|
|
257
|
-
const originHostname = originUrl.hostname;
|
|
258
|
-
|
|
259
|
-
// Check if any trusted origin is just the hostname (without protocol)
|
|
260
|
-
if (originsArray.includes(originHostname)) {
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return false;
|
|
265
|
-
} catch {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
package/src/integrations/next.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import type { C15TInstance } from '~/core';
|
|
2
|
-
import { ERROR_CODES } from '~/pkgs/results';
|
|
3
|
-
import type { C15TContext } from '~/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Type definition for a Next.js route handler function
|
|
7
|
-
*/
|
|
8
|
-
type RouteHandler = (request: Request) => Promise<Response>;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Type definition for Next.js route handlers object
|
|
12
|
-
*/
|
|
13
|
-
type NextRouteHandlers = {
|
|
14
|
-
GET: RouteHandler;
|
|
15
|
-
POST: RouteHandler;
|
|
16
|
-
PUT: RouteHandler;
|
|
17
|
-
DELETE: RouteHandler;
|
|
18
|
-
OPTIONS: RouteHandler;
|
|
19
|
-
HEAD: RouteHandler;
|
|
20
|
-
PATCH: RouteHandler;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Convert a c15t handler to a Next.js route handler.
|
|
25
|
-
*
|
|
26
|
-
* This adapter converts between standard Web API and c15t, letting c15t/H3 handle
|
|
27
|
-
* all the HTTP logic including CORS. It doesn't depend on next/server.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* import { toNextHandler } from '@c15t/backend/integrations/next';
|
|
32
|
-
* import { c15t } from '@/c15t';
|
|
33
|
-
*
|
|
34
|
-
* // app/api/c15t/[...paths]/route.ts
|
|
35
|
-
* export const { GET, POST } = toNextHandler(c15t);
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @param instance - The c15t instance to adapt
|
|
39
|
-
* @returns An object with Next.js route handler functions for each method
|
|
40
|
-
*/
|
|
41
|
-
export function toNextHandler(instance: C15TInstance): NextRouteHandlers {
|
|
42
|
-
// Create the base handler that processes requests
|
|
43
|
-
const handleRequest = async (request: Request) => {
|
|
44
|
-
try {
|
|
45
|
-
const basePath: string =
|
|
46
|
-
(instance.options?.basePath as string) || '/api/c15t';
|
|
47
|
-
|
|
48
|
-
// Extract the path and rewrite for c15t routing
|
|
49
|
-
const originalUrl = new URL(request.url);
|
|
50
|
-
let pathWithoutBase = originalUrl.pathname;
|
|
51
|
-
|
|
52
|
-
if (pathWithoutBase.startsWith(basePath)) {
|
|
53
|
-
pathWithoutBase = pathWithoutBase.substring(basePath.length);
|
|
54
|
-
// Ensure leading slash
|
|
55
|
-
if (!pathWithoutBase.startsWith('/')) {
|
|
56
|
-
pathWithoutBase = `/${pathWithoutBase}`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Create rewritten request
|
|
61
|
-
const rewrittenUrl = new URL(originalUrl.toString());
|
|
62
|
-
rewrittenUrl.pathname = pathWithoutBase;
|
|
63
|
-
|
|
64
|
-
const rewrittenRequest = new Request(rewrittenUrl.toString(), {
|
|
65
|
-
method: request.method,
|
|
66
|
-
headers: request.headers,
|
|
67
|
-
body: request.body,
|
|
68
|
-
// Preserve request properties
|
|
69
|
-
credentials: 'include',
|
|
70
|
-
// Add duplex option when body is present
|
|
71
|
-
duplex: ['GET', 'HEAD'].includes(request.method) ? undefined : 'half',
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Update baseURL for proper URL generation in responses
|
|
75
|
-
await updateBaseUrl(request, basePath);
|
|
76
|
-
|
|
77
|
-
// Let c15t handle the request
|
|
78
|
-
const result = await instance.handler(rewrittenRequest);
|
|
79
|
-
|
|
80
|
-
// Return the response directly - Next.js supports standard Response objects
|
|
81
|
-
return await result.match(
|
|
82
|
-
// Success case - just return the response
|
|
83
|
-
(response) => response,
|
|
84
|
-
// Error case - create an error response
|
|
85
|
-
(error) => {
|
|
86
|
-
const status = error.statusCode || 500;
|
|
87
|
-
const message = error.message || ERROR_CODES.INTERNAL_SERVER_ERROR;
|
|
88
|
-
|
|
89
|
-
return new Response(
|
|
90
|
-
JSON.stringify({
|
|
91
|
-
error: true,
|
|
92
|
-
code: error.code || ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
93
|
-
message,
|
|
94
|
-
meta: error.meta,
|
|
95
|
-
}),
|
|
96
|
-
{
|
|
97
|
-
status,
|
|
98
|
-
headers: {
|
|
99
|
-
'Content-Type': 'application/json',
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
// Basic error handling
|
|
107
|
-
return new Response(
|
|
108
|
-
JSON.stringify({
|
|
109
|
-
error: true,
|
|
110
|
-
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
111
|
-
message: 'An unexpected error occurred',
|
|
112
|
-
meta: { error: String(error) },
|
|
113
|
-
}),
|
|
114
|
-
{
|
|
115
|
-
status: 500,
|
|
116
|
-
headers: {
|
|
117
|
-
'Content-Type': 'application/json',
|
|
118
|
-
},
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// Return an object with handler functions for each HTTP method
|
|
125
|
-
return {
|
|
126
|
-
GET: handleRequest,
|
|
127
|
-
POST: handleRequest,
|
|
128
|
-
PUT: handleRequest,
|
|
129
|
-
DELETE: handleRequest,
|
|
130
|
-
OPTIONS: handleRequest,
|
|
131
|
-
HEAD: handleRequest,
|
|
132
|
-
PATCH: handleRequest,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
async function updateBaseUrl(
|
|
136
|
-
request: Request,
|
|
137
|
-
basePath: string
|
|
138
|
-
): Promise<void> {
|
|
139
|
-
if (!instance.$context) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
const contextResult = await instance.$context;
|
|
145
|
-
|
|
146
|
-
contextResult.match(
|
|
147
|
-
(context: C15TContext) => {
|
|
148
|
-
const url = new URL(request.url);
|
|
149
|
-
const baseURL = `${url.protocol}//${url.host}${basePath}`;
|
|
150
|
-
|
|
151
|
-
if (!context.baseURL || context.baseURL !== baseURL) {
|
|
152
|
-
context.baseURL = baseURL;
|
|
153
|
-
if (context.options) {
|
|
154
|
-
context.options.baseURL = baseURL;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
() => {} // Ignore errors
|
|
159
|
-
);
|
|
160
|
-
} catch {
|
|
161
|
-
// Ignore errors
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Alternative Next.js route handler that works with any handler function.
|
|
168
|
-
*
|
|
169
|
-
* This utility function helps create Next.js App Router route handlers
|
|
170
|
-
* from any function that accepts a Request and returns a Response.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* // Using with c15t
|
|
175
|
-
* import { toNextJsHandler } from '@c15t/backend/integrations/next';
|
|
176
|
-
* import { c15t } from '@/c15t';
|
|
177
|
-
*
|
|
178
|
-
* // app/api/auth/[...slug]/route.ts
|
|
179
|
-
* export const { GET, POST } = toNextJsHandler(c15t);
|
|
180
|
-
*
|
|
181
|
-
* // Using with a custom handler
|
|
182
|
-
* export const { GET } = toNextJsHandler((request) => {
|
|
183
|
-
* return new Response('Hello World');
|
|
184
|
-
* });
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* @param auth - Either a function or an object with a handler method
|
|
188
|
-
* @returns An object with GET and POST methods for Next.js App Router
|
|
189
|
-
*/
|
|
190
|
-
export function toNextJsHandler(
|
|
191
|
-
auth:
|
|
192
|
-
| {
|
|
193
|
-
handler: (request: Request) => Promise<Response>;
|
|
194
|
-
}
|
|
195
|
-
| ((request: Request) => Promise<Response>)
|
|
196
|
-
) {
|
|
197
|
-
const handler = async (request: Request) => {
|
|
198
|
-
return 'handler' in auth ? auth.handler(request) : auth(request);
|
|
199
|
-
};
|
|
200
|
-
return {
|
|
201
|
-
GET: handler,
|
|
202
|
-
POST: handler,
|
|
203
|
-
};
|
|
204
|
-
}
|
package/src/integrations/node.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { C15TInstance } from '~/core';
|
|
2
|
-
import { ERROR_CODES } from '~/pkgs/results';
|
|
3
|
-
import type { C15TContext } from '~/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Convert a c15t handler to a pure Node.js/Cloudflare Worker handler.
|
|
7
|
-
*
|
|
8
|
-
* This adapter converts between Web API Request/Response objects and c15t,
|
|
9
|
-
* letting c15t/H3 handle all the HTTP logic including CORS.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Node.js with standard Request/Response objects
|
|
14
|
-
* import { toNodeHandler } from '@c15t/backend/integrations/node';
|
|
15
|
-
* import { c15t } from './c15t';
|
|
16
|
-
*
|
|
17
|
-
* // Create the request handler
|
|
18
|
-
* const handler = toNodeHandler(c15t);
|
|
19
|
-
*
|
|
20
|
-
* // Example for Cloudflare Worker
|
|
21
|
-
* export default {
|
|
22
|
-
* async fetch(request, env, ctx) {
|
|
23
|
-
* return await handler(request);
|
|
24
|
-
* }
|
|
25
|
-
* };
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @param instance - The c15t instance to adapt
|
|
29
|
-
* @returns A handler function that takes a Request and returns a Response
|
|
30
|
-
*/
|
|
31
|
-
export function toNodeHandler(instance: C15TInstance) {
|
|
32
|
-
return async (request: Request): Promise<Response> => {
|
|
33
|
-
try {
|
|
34
|
-
const basePath: string =
|
|
35
|
-
(instance.options?.basePath as string) || '/api/c15t';
|
|
36
|
-
|
|
37
|
-
// Extract the path and rewrite for c15t routing
|
|
38
|
-
const originalUrl = new URL(request.url);
|
|
39
|
-
let pathWithoutBase = originalUrl.pathname;
|
|
40
|
-
|
|
41
|
-
if (pathWithoutBase.startsWith(basePath)) {
|
|
42
|
-
pathWithoutBase = pathWithoutBase.substring(basePath.length);
|
|
43
|
-
// Ensure leading slash
|
|
44
|
-
if (!pathWithoutBase.startsWith('/')) {
|
|
45
|
-
pathWithoutBase = `/${pathWithoutBase}`;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Create rewritten request
|
|
50
|
-
const rewrittenUrl = new URL(originalUrl.toString());
|
|
51
|
-
rewrittenUrl.pathname = pathWithoutBase;
|
|
52
|
-
|
|
53
|
-
const rewrittenRequest = new Request(rewrittenUrl.toString(), {
|
|
54
|
-
method: request.method,
|
|
55
|
-
headers: request.headers,
|
|
56
|
-
body: request.body,
|
|
57
|
-
// Preserve request properties
|
|
58
|
-
credentials: 'include',
|
|
59
|
-
duplex: ['GET', 'HEAD'].includes(request.method) ? undefined : 'half',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Update baseURL for proper URL generation in responses
|
|
63
|
-
await updateBaseUrl(request, basePath);
|
|
64
|
-
|
|
65
|
-
// Let c15t handle the request
|
|
66
|
-
const result = await instance.handler(rewrittenRequest);
|
|
67
|
-
|
|
68
|
-
// Convert c15t response to standard Response
|
|
69
|
-
return await result.match(
|
|
70
|
-
// Success case - just return the response
|
|
71
|
-
(response) => response,
|
|
72
|
-
// Error case - create an error response
|
|
73
|
-
(error) => {
|
|
74
|
-
const status = error.statusCode || 500;
|
|
75
|
-
const message = error.message || ERROR_CODES.INTERNAL_SERVER_ERROR;
|
|
76
|
-
|
|
77
|
-
return new Response(
|
|
78
|
-
JSON.stringify({
|
|
79
|
-
error: true,
|
|
80
|
-
code: error.code || ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
81
|
-
message,
|
|
82
|
-
meta: error.meta,
|
|
83
|
-
}),
|
|
84
|
-
{
|
|
85
|
-
status,
|
|
86
|
-
headers: {
|
|
87
|
-
'Content-Type': 'application/json',
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
} catch (error) {
|
|
94
|
-
// Basic error handling
|
|
95
|
-
return new Response(
|
|
96
|
-
JSON.stringify({
|
|
97
|
-
error: true,
|
|
98
|
-
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
99
|
-
message: 'An unexpected error occurred',
|
|
100
|
-
meta: { error: String(error) },
|
|
101
|
-
}),
|
|
102
|
-
{
|
|
103
|
-
status: 500,
|
|
104
|
-
headers: {
|
|
105
|
-
'Content-Type': 'application/json',
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
async function updateBaseUrl(
|
|
113
|
-
request: Request,
|
|
114
|
-
basePath: string
|
|
115
|
-
): Promise<void> {
|
|
116
|
-
if (!instance.$context) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const contextResult = await instance.$context;
|
|
122
|
-
|
|
123
|
-
contextResult.match(
|
|
124
|
-
(context: C15TContext) => {
|
|
125
|
-
const url = new URL(request.url);
|
|
126
|
-
const baseURL = `${url.protocol}//${url.host}${basePath}`;
|
|
127
|
-
|
|
128
|
-
if (!context.baseURL || context.baseURL !== baseURL) {
|
|
129
|
-
context.baseURL = baseURL;
|
|
130
|
-
if (context.options) {
|
|
131
|
-
context.options.baseURL = baseURL;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
() => {} // Ignore errors
|
|
136
|
-
);
|
|
137
|
-
} catch {
|
|
138
|
-
// Ignore errors
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|