@c15t/backend 1.5.0 → 1.6.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 +63 -37
- package/CHANGELOG.md +4 -209
- package/README.md +86 -164
- package/dist/contracts/consent/index.d.ts +103 -615
- package/dist/contracts/consent/index.d.ts.map +1 -1
- package/dist/contracts/consent/post.contract.d.ts +42 -140
- package/dist/contracts/consent/post.contract.d.ts.map +1 -1
- package/dist/contracts/consent/show-banner.contract.d.ts +28 -376
- package/dist/contracts/consent/show-banner.contract.d.ts.map +1 -1
- package/dist/contracts/consent/verify.contract.d.ts +33 -99
- package/dist/contracts/consent/verify.contract.d.ts.map +1 -1
- package/dist/contracts/index.d.ts +222 -1356
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/meta/index.d.ts +8 -63
- package/dist/contracts/meta/index.d.ts.map +1 -1
- package/dist/contracts/meta/status.contract.d.ts +8 -63
- package/dist/contracts/meta/status.contract.d.ts.map +1 -1
- package/dist/contracts/shared/jurisdiction.schema.d.ts +21 -9
- package/dist/contracts/shared/jurisdiction.schema.d.ts.map +1 -1
- package/dist/contracts.cjs +100 -106
- package/dist/contracts.js +100 -106
- package/dist/core.cjs +681 -681
- package/dist/core.d.ts +118 -678
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +634 -637
- package/dist/handlers/consent/index.d.ts +103 -615
- package/dist/handlers/consent/index.d.ts.map +1 -1
- package/dist/handlers/consent/post.handler.d.ts +42 -140
- package/dist/handlers/consent/post.handler.d.ts.map +1 -1
- package/dist/handlers/consent/show-banner/handler.d.ts +28 -376
- package/dist/handlers/consent/show-banner/handler.d.ts.map +1 -1
- package/dist/handlers/consent/show-banner/translations.d.ts.map +1 -1
- package/dist/handlers/consent/verify.handler.d.ts +33 -99
- package/dist/handlers/consent/verify.handler.d.ts.map +1 -1
- package/dist/handlers/meta/index.d.ts +8 -63
- package/dist/handlers/meta/index.d.ts.map +1 -1
- package/dist/handlers/meta/status.handler.d.ts +8 -63
- package/dist/handlers/meta/status.handler.d.ts.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/middleware/openapi/index.d.ts +2 -2
- package/dist/middleware/openapi/index.d.ts.map +1 -1
- package/dist/pkgs/data-model/fields/index.cjs +14 -26
- package/dist/pkgs/data-model/fields/index.d.ts +4 -4
- package/dist/pkgs/data-model/fields/index.d.ts.map +1 -1
- package/dist/pkgs/data-model/fields/index.js +14 -26
- package/dist/pkgs/data-model/fields/zod-fields.d.ts +195 -871
- package/dist/pkgs/data-model/fields/zod-fields.d.ts.map +1 -1
- package/dist/pkgs/data-model/hooks/index.d.ts +2 -2
- package/dist/pkgs/data-model/hooks/index.d.ts.map +1 -1
- package/dist/pkgs/data-model/index.cjs +346 -358
- package/dist/pkgs/data-model/index.d.ts +1 -1
- package/dist/pkgs/data-model/index.d.ts.map +1 -1
- package/dist/pkgs/data-model/index.js +345 -357
- package/dist/pkgs/data-model/schema/index.cjs +346 -358
- package/dist/pkgs/data-model/schema/index.d.ts +1 -1
- package/dist/pkgs/data-model/schema/index.d.ts.map +1 -1
- package/dist/pkgs/data-model/schema/index.js +345 -357
- package/dist/pkgs/data-model/schema/schemas.d.ts +2 -2
- package/dist/pkgs/data-model/schema/schemas.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts +3 -0
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +158 -170
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +157 -169
- package/dist/pkgs/db-adapters/adapters/index.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapters/index.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +215 -227
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +213 -225
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.d.ts +2 -0
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts +1 -1
- 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 +158 -170
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +157 -169
- package/dist/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.d.ts +3 -0
- package/dist/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +243 -255
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.d.ts +1 -1
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +241 -253
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.d.ts +3 -0
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/index.cjs +714 -726
- package/dist/pkgs/db-adapters/index.d.ts +6 -6
- package/dist/pkgs/db-adapters/index.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/index.js +708 -720
- package/dist/pkgs/migrations/get-migration.d.ts.map +1 -1
- package/dist/pkgs/migrations/get-schema/get-schema.d.ts.map +1 -1
- package/dist/pkgs/migrations/get-schema/process-tables.d.ts.map +1 -1
- package/dist/pkgs/migrations/index.cjs +236 -248
- package/dist/pkgs/migrations/index.d.ts +4 -4
- package/dist/pkgs/migrations/index.d.ts.map +1 -1
- package/dist/pkgs/migrations/index.js +235 -247
- package/dist/pkgs/results/index.cjs +67 -67
- package/dist/pkgs/results/index.d.ts +5 -5
- package/dist/pkgs/results/index.d.ts.map +1 -1
- package/dist/pkgs/results/index.js +67 -67
- package/dist/pkgs/results/orpc-error-handler.d.ts +1 -1
- package/dist/pkgs/results/orpc-error-handler.d.ts.map +1 -1
- package/dist/pkgs/types/index.d.ts +1 -2
- package/dist/pkgs/types/index.d.ts.map +1 -1
- package/dist/pkgs/types/options.d.ts +9 -2
- package/dist/pkgs/types/options.d.ts.map +1 -1
- package/dist/pkgs/utils/index.d.ts +1 -1
- package/dist/pkgs/utils/index.d.ts.map +1 -1
- package/dist/pkgs/utils/logger.d.ts +1 -1
- package/dist/pkgs/utils/logger.d.ts.map +1 -1
- package/dist/router.cjs +114 -117
- package/dist/router.d.ts +111 -678
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +114 -117
- package/dist/schema/audit-log/schema.d.ts +2 -24
- package/dist/schema/audit-log/schema.d.ts.map +1 -1
- package/dist/schema/audit-log/table.d.ts +2 -24
- package/dist/schema/audit-log/table.d.ts.map +1 -1
- package/dist/schema/consent/registry.d.ts +8 -8
- package/dist/schema/consent/schema.d.ts +9 -33
- package/dist/schema/consent/schema.d.ts.map +1 -1
- package/dist/schema/consent/table.d.ts +9 -33
- package/dist/schema/consent/table.d.ts.map +1 -1
- package/dist/schema/consent-policy/registry.d.ts +20 -20
- package/dist/schema/consent-policy/schema.d.ts +22 -30
- package/dist/schema/consent-policy/schema.d.ts.map +1 -1
- package/dist/schema/consent-policy/table.d.ts +13 -29
- package/dist/schema/consent-policy/table.d.ts.map +1 -1
- package/dist/schema/consent-purpose/registry.d.ts +6 -6
- package/dist/schema/consent-purpose/schema.d.ts +5 -27
- package/dist/schema/consent-purpose/schema.d.ts.map +1 -1
- package/dist/schema/consent-purpose/table.d.ts +5 -27
- package/dist/schema/consent-purpose/table.d.ts.map +1 -1
- package/dist/schema/consent-record/schema.d.ts +3 -19
- package/dist/schema/consent-record/schema.d.ts.map +1 -1
- package/dist/schema/consent-record/table.d.ts +3 -19
- package/dist/schema/consent-record/table.d.ts.map +1 -1
- package/dist/schema/create-registry.d.ts +58 -58
- package/dist/schema/definition.d.ts +42 -176
- package/dist/schema/definition.d.ts.map +1 -1
- package/dist/schema/domain/registry.d.ts +20 -20
- package/dist/schema/domain/schema.d.ts +6 -24
- package/dist/schema/domain/schema.d.ts.map +1 -1
- package/dist/schema/domain/table.d.ts +6 -24
- package/dist/schema/domain/table.d.ts.map +1 -1
- package/dist/schema/index.cjs +426 -438
- package/dist/schema/index.d.ts +12 -12
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +426 -438
- package/dist/schema/schemas.d.ts +42 -176
- package/dist/schema/schemas.d.ts.map +1 -1
- package/dist/schema/subject/registry.d.ts +4 -4
- package/dist/schema/subject/schema.d.ts +4 -20
- package/dist/schema/subject/schema.d.ts.map +1 -1
- package/dist/schema/subject/table.d.ts +4 -20
- package/dist/schema/subject/table.d.ts.map +1 -1
- package/dist/schema/types.d.ts +1 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/testing/contract-testing.d.ts +3 -2
- package/dist/testing/contract-testing.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/options.d.ts +2 -2
- package/dist/types/options.d.ts.map +1 -1
- package/dist/v2/contracts/consent/index.d.ts +260 -0
- package/dist/v2/contracts/consent/index.d.ts.map +1 -0
- package/dist/v2/contracts/consent/index.test.d.ts +2 -0
- package/dist/v2/contracts/consent/index.test.d.ts.map +1 -0
- package/dist/v2/contracts/consent/post.contract.d.ts +114 -0
- package/dist/v2/contracts/consent/post.contract.d.ts.map +1 -0
- package/dist/v2/contracts/consent/post.contract.test.d.ts +2 -0
- package/dist/v2/contracts/consent/post.contract.test.d.ts.map +1 -0
- package/dist/v2/contracts/consent/show-banner.contract.d.ts +68 -0
- package/dist/v2/contracts/consent/show-banner.contract.d.ts.map +1 -0
- package/dist/v2/contracts/consent/show-banner.contract.test.d.ts +2 -0
- package/dist/v2/contracts/consent/show-banner.contract.test.d.ts.map +1 -0
- package/dist/v2/contracts/consent/verify.contract.d.ts +81 -0
- package/dist/v2/contracts/consent/verify.contract.d.ts.map +1 -0
- package/dist/v2/contracts/consent/verify.contract.test.d.ts +2 -0
- package/dist/v2/contracts/consent/verify.contract.test.d.ts.map +1 -0
- package/dist/v2/contracts/index.cjs +644 -0
- package/dist/v2/contracts/index.d.ts +563 -0
- package/dist/v2/contracts/index.d.ts.map +1 -0
- package/dist/v2/contracts/index.js +607 -0
- package/dist/v2/contracts/meta/index.d.ts +19 -0
- package/dist/v2/contracts/meta/index.d.ts.map +1 -0
- package/dist/v2/contracts/meta/index.test.d.ts +2 -0
- package/dist/v2/contracts/meta/index.test.d.ts.map +1 -0
- package/dist/v2/contracts/meta/status.contract.d.ts +18 -0
- package/dist/v2/contracts/meta/status.contract.d.ts.map +1 -0
- package/dist/v2/contracts/meta/status.contract.test.d.ts +2 -0
- package/dist/v2/contracts/meta/status.contract.test.d.ts.map +1 -0
- package/dist/v2/contracts/shared/jurisdiction.schema.d.ts +36 -0
- package/dist/v2/contracts/shared/jurisdiction.schema.d.ts.map +1 -0
- package/dist/v2/contracts/test.utils.d.ts +38 -0
- package/dist/v2/contracts/test.utils.d.ts.map +1 -0
- package/dist/v2/core.cjs +2181 -0
- package/dist/v2/core.d.ts +364 -0
- package/dist/v2/core.d.ts.map +1 -0
- package/dist/v2/core.js +2130 -0
- package/dist/v2/db/adapters/drizzle.cjs +36 -0
- package/dist/v2/db/adapters/drizzle.d.ts +2 -0
- package/dist/v2/db/adapters/drizzle.d.ts.map +1 -0
- package/dist/v2/db/adapters/drizzle.js +3 -0
- package/dist/v2/db/adapters/index.cjs +18 -0
- package/dist/v2/db/adapters/index.d.ts +2 -0
- package/dist/v2/db/adapters/index.d.ts.map +1 -0
- package/dist/v2/db/adapters/index.js +0 -0
- package/dist/v2/db/adapters/kysely.cjs +36 -0
- package/dist/v2/db/adapters/kysely.d.ts +2 -0
- package/dist/v2/db/adapters/kysely.d.ts.map +1 -0
- package/dist/v2/db/adapters/kysely.js +3 -0
- package/dist/v2/db/adapters/mongo.cjs +36 -0
- package/dist/v2/db/adapters/mongo.d.ts +2 -0
- package/dist/v2/db/adapters/mongo.d.ts.map +1 -0
- package/dist/v2/db/adapters/mongo.js +3 -0
- package/dist/v2/db/adapters/prisma.cjs +36 -0
- package/dist/v2/db/adapters/prisma.d.ts +2 -0
- package/dist/v2/db/adapters/prisma.d.ts.map +1 -0
- package/dist/v2/db/adapters/prisma.js +3 -0
- package/dist/v2/db/adapters/typeorm.cjs +36 -0
- package/dist/v2/db/adapters/typeorm.d.ts +2 -0
- package/dist/v2/db/adapters/typeorm.d.ts.map +1 -0
- package/dist/v2/db/adapters/typeorm.js +3 -0
- package/dist/v2/db/migrator/index.cjs +61 -0
- package/dist/v2/db/migrator/index.d.ts +29 -0
- package/dist/v2/db/migrator/index.d.ts.map +1 -0
- package/dist/v2/db/migrator/index.js +27 -0
- package/dist/v2/db/registry/audit-log.d.ts +21 -0
- package/dist/v2/db/registry/audit-log.d.ts.map +1 -0
- package/dist/v2/db/registry/audit-log.test.d.ts +2 -0
- package/dist/v2/db/registry/audit-log.test.d.ts.map +1 -0
- package/dist/v2/db/registry/consent-policy.d.ts +29 -0
- package/dist/v2/db/registry/consent-policy.d.ts.map +1 -0
- package/dist/v2/db/registry/consent-policy.test.d.ts +2 -0
- package/dist/v2/db/registry/consent-policy.test.d.ts.map +1 -0
- package/dist/v2/db/registry/consent-purpose.d.ts +16 -0
- package/dist/v2/db/registry/consent-purpose.d.ts.map +1 -0
- package/dist/v2/db/registry/consent-purpose.test.d.ts +2 -0
- package/dist/v2/db/registry/consent-purpose.test.d.ts.map +1 -0
- package/dist/v2/db/registry/consent.d.ts +20 -0
- package/dist/v2/db/registry/consent.d.ts.map +1 -0
- package/dist/v2/db/registry/consent.test.d.ts +2 -0
- package/dist/v2/db/registry/consent.test.d.ts.map +1 -0
- package/dist/v2/db/registry/domain.d.ts +24 -0
- package/dist/v2/db/registry/domain.d.ts.map +1 -0
- package/dist/v2/db/registry/domain.test.d.ts +2 -0
- package/dist/v2/db/registry/domain.test.d.ts.map +1 -0
- package/dist/v2/db/registry/index.d.ts +102 -0
- package/dist/v2/db/registry/index.d.ts.map +1 -0
- package/dist/v2/db/registry/subject.d.ts +18 -0
- package/dist/v2/db/registry/subject.d.ts.map +1 -0
- package/dist/v2/db/registry/subject.test.d.ts +2 -0
- package/dist/v2/db/registry/subject.test.d.ts.map +1 -0
- package/dist/v2/db/registry/types.d.ts +10 -0
- package/dist/v2/db/registry/types.d.ts.map +1 -0
- package/dist/v2/db/registry/utils/generate-id.d.ts +25 -0
- package/dist/v2/db/registry/utils/generate-id.d.ts.map +1 -0
- package/dist/v2/db/registry/utils/generate-id.test.d.ts +2 -0
- package/dist/v2/db/registry/utils/generate-id.test.d.ts.map +1 -0
- package/dist/v2/db/registry/utils.d.ts +25 -0
- package/dist/v2/db/registry/utils.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/audit-log.d.ts +29 -0
- package/dist/v2/db/schema/1.0.0/audit-log.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/consent-policy.d.ts +45 -0
- package/dist/v2/db/schema/1.0.0/consent-policy.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/consent-purpose.d.ts +27 -0
- package/dist/v2/db/schema/1.0.0/consent-purpose.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/consent-record.d.ts +19 -0
- package/dist/v2/db/schema/1.0.0/consent-record.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/consent.d.ts +42 -0
- package/dist/v2/db/schema/1.0.0/consent.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/domain.d.ts +23 -0
- package/dist/v2/db/schema/1.0.0/domain.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/index.d.ts +1513 -0
- package/dist/v2/db/schema/1.0.0/index.d.ts.map +1 -0
- package/dist/v2/db/schema/1.0.0/subject.d.ts +23 -0
- package/dist/v2/db/schema/1.0.0/subject.d.ts.map +1 -0
- package/dist/v2/db/schema/index.cjs +326 -0
- package/dist/v2/db/schema/index.d.ts +1507 -0
- package/dist/v2/db/schema/index.d.ts.map +1 -0
- package/dist/v2/db/schema/index.js +241 -0
- package/dist/v2/define-config.cjs +36 -0
- package/dist/v2/define-config.d.ts +5 -0
- package/dist/v2/define-config.d.ts.map +1 -0
- package/dist/v2/define-config.js +2 -0
- package/dist/v2/handlers/consent/index.d.ts +260 -0
- package/dist/v2/handlers/consent/index.d.ts.map +1 -0
- package/dist/v2/handlers/consent/post.handler.d.ts +136 -0
- package/dist/v2/handlers/consent/post.handler.d.ts.map +1 -0
- package/dist/v2/handlers/consent/show-banner/geo.d.ts +10 -0
- package/dist/v2/handlers/consent/show-banner/geo.d.ts.map +1 -0
- package/dist/v2/handlers/consent/show-banner/geo.test.d.ts +2 -0
- package/dist/v2/handlers/consent/show-banner/geo.test.d.ts.map +1 -0
- package/dist/v2/handlers/consent/show-banner/handler.d.ts +71 -0
- package/dist/v2/handlers/consent/show-banner/handler.d.ts.map +1 -0
- package/dist/v2/handlers/consent/show-banner/handler.test.d.ts +2 -0
- package/dist/v2/handlers/consent/show-banner/handler.test.d.ts.map +1 -0
- package/dist/v2/handlers/consent/show-banner/translations.d.ts +13 -0
- package/dist/v2/handlers/consent/show-banner/translations.d.ts.map +1 -0
- package/dist/v2/handlers/consent/show-banner/translations.test.d.ts +2 -0
- package/dist/v2/handlers/consent/show-banner/translations.test.d.ts.map +1 -0
- package/dist/v2/handlers/consent/verify.handler.d.ts +103 -0
- package/dist/v2/handlers/consent/verify.handler.d.ts.map +1 -0
- package/dist/v2/handlers/meta/index.d.ts +19 -0
- package/dist/v2/handlers/meta/index.d.ts.map +1 -0
- package/dist/v2/handlers/meta/status.handler.d.ts +17 -0
- package/dist/v2/handlers/meta/status.handler.d.ts.map +1 -0
- package/dist/v2/init.d.ts +3 -0
- package/dist/v2/init.d.ts.map +1 -0
- package/dist/v2/init.test.d.ts +2 -0
- package/dist/v2/init.test.d.ts.map +1 -0
- package/dist/v2/middleware/cors/cors.d.ts +37 -0
- package/dist/v2/middleware/cors/cors.d.ts.map +1 -0
- package/dist/v2/middleware/cors/cors.test.d.ts +2 -0
- package/dist/v2/middleware/cors/cors.test.d.ts.map +1 -0
- package/dist/v2/middleware/cors/index.d.ts +30 -0
- package/dist/v2/middleware/cors/index.d.ts.map +1 -0
- package/dist/v2/middleware/cors/is-origin-trusted.d.ts +49 -0
- package/dist/v2/middleware/cors/is-origin-trusted.d.ts.map +1 -0
- package/dist/v2/middleware/cors/is-origin-trusted.test.d.ts +2 -0
- package/dist/v2/middleware/cors/is-origin-trusted.test.d.ts.map +1 -0
- package/dist/v2/middleware/cors/process-cors.d.ts +31 -0
- package/dist/v2/middleware/cors/process-cors.d.ts.map +1 -0
- package/dist/v2/middleware/openapi/config.d.ts +28 -0
- package/dist/v2/middleware/openapi/config.d.ts.map +1 -0
- package/dist/v2/middleware/openapi/handlers.d.ts +29 -0
- package/dist/v2/middleware/openapi/handlers.d.ts.map +1 -0
- package/dist/v2/middleware/openapi/index.d.ts +11 -0
- package/dist/v2/middleware/openapi/index.d.ts.map +1 -0
- package/dist/v2/middleware/process-ip/index.d.ts +3 -0
- package/dist/v2/middleware/process-ip/index.d.ts.map +1 -0
- package/dist/v2/router.cjs +1275 -0
- package/dist/v2/router.d.ts +280 -0
- package/dist/v2/router.d.ts.map +1 -0
- package/dist/v2/router.js +1231 -0
- package/dist/v2/types/api.d.ts +27 -0
- package/dist/v2/types/api.d.ts.map +1 -0
- package/dist/v2/types/index.cjs +40 -0
- package/dist/v2/types/index.d.ts +104 -0
- package/dist/v2/types/index.d.ts.map +1 -0
- package/dist/v2/types/index.js +6 -0
- package/dist/v2/utils/create-telemetry-options.d.ts +28 -0
- package/dist/v2/utils/create-telemetry-options.d.ts.map +1 -0
- package/dist/v2/utils/env.d.ts +60 -0
- package/dist/v2/utils/env.d.ts.map +1 -0
- package/dist/v2/utils/index.d.ts +3 -0
- package/dist/v2/utils/index.d.ts.map +1 -0
- package/dist/v2/utils/logger.d.ts +16 -0
- package/dist/v2/utils/logger.d.ts.map +1 -0
- package/dist/version.d.ts +1 -1
- package/package.json +106 -15
- package/readme.json +30 -0
- package/rslib.config.ts +13 -14
- package/src/__tests__/server.test.ts +1 -1
- package/src/contracts/consent/post.contract.test.ts +3 -8
- package/src/contracts/consent/post.contract.ts +13 -13
- package/src/contracts/consent/show-banner.contract.test.ts +9 -0
- package/src/contracts/consent/show-banner.contract.ts +2 -0
- package/src/contracts/consent/verify.contract.ts +19 -23
- package/src/core.ts +7 -0
- package/src/handlers/consent/show-banner/handler.ts +12 -9
- package/src/handlers/consent/show-banner/translations.ts +2 -2
- package/src/init.ts +9 -6
- package/src/middleware/openapi/index.ts +2 -2
- package/src/pkgs/api-router/hooks/__tests__/processor.test.ts +1 -1
- package/src/pkgs/data-model/fields/index.ts +17 -22
- package/src/pkgs/data-model/fields/zod-fields.ts +14 -26
- package/src/pkgs/data-model/hooks/index.ts +3 -2
- package/src/pkgs/data-model/index.ts +2 -4
- package/src/pkgs/data-model/schema/index.ts +6 -7
- package/src/pkgs/data-model/schema/schemas.ts +3 -3
- package/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts +4 -1
- package/src/pkgs/db-adapters/adapters/index.ts +2 -2
- package/src/pkgs/db-adapters/adapters/kysely-adapter/index.ts +4 -4
- package/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts +4 -5
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/postgres.test.ts +2 -4
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/sqlite.test.ts +2 -3
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts +1 -6
- package/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts +4 -1
- package/src/pkgs/db-adapters/adapters/prisma-adapter/index.ts +1 -1
- package/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts +5 -2
- package/src/pkgs/db-adapters/index.ts +12 -13
- package/src/pkgs/migrations/get-migration.ts +4 -2
- package/src/pkgs/migrations/get-schema/get-schema.ts +0 -1
- package/src/pkgs/migrations/get-schema/process-fields.ts +1 -1
- package/src/pkgs/migrations/get-schema/process-tables.ts +0 -2
- package/src/pkgs/migrations/index.ts +7 -8
- package/src/pkgs/results/__tests__/error-codes.test.ts +2 -2
- package/src/pkgs/results/index.ts +22 -27
- package/src/pkgs/results/orpc-error-handler.ts +1 -1
- package/src/pkgs/results/results/result-helpers.ts +1 -1
- package/src/pkgs/types/index.ts +4 -4
- package/src/pkgs/types/options.ts +10 -3
- package/src/pkgs/utils/index.ts +1 -1
- package/src/pkgs/utils/logger.ts +1 -1
- package/src/schema/audit-log/schema.ts +3 -3
- package/src/schema/consent/schema.ts +4 -4
- package/src/schema/consent-policy/schema.ts +3 -3
- package/src/schema/consent-purpose/schema.ts +4 -4
- package/src/schema/consent-record/schema.ts +3 -3
- package/src/schema/definition.ts +1 -1
- package/src/schema/domain/schema.ts +5 -5
- package/src/schema/index.ts +14 -17
- package/src/schema/subject/schema.ts +3 -3
- package/src/schema/types.ts +1 -1
- package/src/testing/contract-testing.ts +15 -52
- package/src/types/index.ts +8 -8
- package/src/types/options.ts +2 -3
- package/src/v2/contracts/consent/index.test.ts +5 -0
- package/src/v2/contracts/consent/index.ts +9 -0
- package/src/v2/contracts/consent/post.contract.test.ts +521 -0
- package/src/v2/contracts/consent/post.contract.ts +155 -0
- package/src/v2/contracts/consent/show-banner.contract.test.ts +252 -0
- package/src/v2/contracts/consent/show-banner.contract.ts +73 -0
- package/src/v2/contracts/consent/verify.contract.test.ts +185 -0
- package/src/v2/contracts/consent/verify.contract.ts +122 -0
- package/src/v2/contracts/index.ts +20 -0
- package/src/v2/contracts/meta/index.test.ts +5 -0
- package/src/v2/contracts/meta/index.ts +5 -0
- package/src/v2/contracts/meta/status.contract.test.ts +226 -0
- package/src/v2/contracts/meta/status.contract.ts +34 -0
- package/src/v2/contracts/shared/jurisdiction.schema.ts +30 -0
- package/src/v2/contracts/test.utils.ts +400 -0
- package/src/v2/core.ts +379 -0
- package/src/v2/db/adapters/drizzle.ts +1 -0
- package/src/v2/db/adapters/index.ts +1 -0
- package/src/v2/db/adapters/kysely.ts +1 -0
- package/src/v2/db/adapters/mongo.ts +1 -0
- package/src/v2/db/adapters/prisma.ts +1 -0
- package/src/v2/db/adapters/typeorm.ts +1 -0
- package/src/v2/db/migrator/index.ts +80 -0
- package/src/v2/db/registry/audit-log.test.ts +77 -0
- package/src/v2/db/registry/audit-log.ts +46 -0
- package/src/v2/db/registry/consent-policy.test.ts +778 -0
- package/src/v2/db/registry/consent-policy.ts +74 -0
- package/src/v2/db/registry/consent-purpose.test.ts +485 -0
- package/src/v2/db/registry/consent-purpose.ts +41 -0
- package/src/v2/db/registry/consent.test.ts +843 -0
- package/src/v2/db/registry/consent.ts +42 -0
- package/src/v2/db/registry/domain.test.ts +463 -0
- package/src/v2/db/registry/domain.ts +51 -0
- package/src/v2/db/registry/index.ts +18 -0
- package/src/v2/db/registry/subject.test.ts +497 -0
- package/src/v2/db/registry/subject.ts +101 -0
- package/src/v2/db/registry/types.ts +10 -0
- package/src/v2/db/registry/utils/generate-id.test.ts +217 -0
- package/src/v2/db/registry/utils/generate-id.ts +134 -0
- package/src/v2/db/registry/utils.ts +134 -0
- package/src/v2/db/schema/1.0.0/audit-log.ts +32 -0
- package/src/v2/db/schema/1.0.0/consent-policy.ts +41 -0
- package/src/v2/db/schema/1.0.0/consent-purpose.ts +30 -0
- package/src/v2/db/schema/1.0.0/consent-record.ts +22 -0
- package/src/v2/db/schema/1.0.0/consent.ts +38 -0
- package/src/v2/db/schema/1.0.0/domain.ts +26 -0
- package/src/v2/db/schema/1.0.0/index.ts +56 -0
- package/src/v2/db/schema/1.0.0/subject.ts +26 -0
- package/src/v2/db/schema/index.ts +9 -0
- package/src/v2/define-config.ts +5 -0
- package/src/v2/handlers/consent/index.ts +9 -0
- package/src/v2/handlers/consent/post.handler.ts +254 -0
- package/src/v2/handlers/consent/show-banner/geo.test.ts +281 -0
- package/src/v2/handlers/consent/show-banner/geo.ts +96 -0
- package/src/v2/handlers/consent/show-banner/handler.test.ts +374 -0
- package/src/v2/handlers/consent/show-banner/handler.ts +123 -0
- package/src/v2/handlers/consent/show-banner/translations.test.ts +121 -0
- package/src/v2/handlers/consent/show-banner/translations.ts +79 -0
- package/src/v2/handlers/consent/verify.handler.ts +288 -0
- package/src/v2/handlers/meta/index.ts +5 -0
- package/src/v2/handlers/meta/status.handler.ts +43 -0
- package/src/v2/init.test.ts +114 -0
- package/src/v2/init.ts +126 -0
- package/src/v2/middleware/cors/cors.test.ts +111 -0
- package/src/v2/middleware/cors/cors.ts +192 -0
- package/src/v2/middleware/cors/index.ts +30 -0
- package/src/v2/middleware/cors/is-origin-trusted.test.ts +104 -0
- package/src/v2/middleware/cors/is-origin-trusted.ts +126 -0
- package/src/v2/middleware/cors/process-cors.ts +91 -0
- package/src/v2/middleware/openapi/config.ts +27 -0
- package/src/v2/middleware/openapi/handlers.ts +132 -0
- package/src/v2/middleware/openapi/index.ts +11 -0
- package/src/v2/middleware/process-ip/index.ts +39 -0
- package/src/v2/router.ts +8 -0
- package/src/v2/types/api.ts +32 -0
- package/src/v2/types/index.ts +121 -0
- package/src/v2/utils/create-telemetry-options.ts +115 -0
- package/src/v2/utils/env.ts +84 -0
- package/src/v2/utils/index.ts +2 -0
- package/src/v2/utils/logger.ts +38 -0
- package/src/version.ts +1 -1
- package/vitest.config.ts +11 -2
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { OpenAPIGenerator } from '@orpc/openapi';
|
|
2
|
+
import { ZodToJsonSchemaConverter } from '@orpc/zod';
|
|
3
|
+
import { router } from '~/v2/router';
|
|
4
|
+
import type { C15TContext, C15TOptions } from '~/v2/types';
|
|
5
|
+
import { createDefaultOpenAPIOptions, createOpenAPIConfig } from './config';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Type for the memoized OpenAPI spec function
|
|
9
|
+
*/
|
|
10
|
+
type MemoizedSpecFunction = {
|
|
11
|
+
(): Promise<Record<string, unknown>>;
|
|
12
|
+
cached?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Merges user OpenAPI options with default options
|
|
17
|
+
*/
|
|
18
|
+
const mergeOpenAPIOptions = (
|
|
19
|
+
defaultOptions: Record<string, unknown>,
|
|
20
|
+
userOptions: Record<string, unknown>
|
|
21
|
+
): Record<string, unknown> => {
|
|
22
|
+
const merged = { ...defaultOptions };
|
|
23
|
+
|
|
24
|
+
// Handle nested info object specially
|
|
25
|
+
if (userOptions.info && typeof userOptions.info === 'object') {
|
|
26
|
+
merged.info = {
|
|
27
|
+
...(merged.info as Record<string, unknown>),
|
|
28
|
+
...userOptions.info,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// For all other top-level properties, override defaults
|
|
33
|
+
for (const [key, value] of Object.entries(userOptions)) {
|
|
34
|
+
if (key !== 'info') {
|
|
35
|
+
merged[key] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return merged;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generate the OpenAPI specification document
|
|
44
|
+
*
|
|
45
|
+
* @param options - Configuration options for the OpenAPI spec generation
|
|
46
|
+
* @returns A memoized function that generates and caches the OpenAPI spec
|
|
47
|
+
*
|
|
48
|
+
* @throws {Error} When the OpenAPI generator fails to create a valid spec
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const getSpec = createOpenAPISpec(options);
|
|
53
|
+
* const spec = await getSpec();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const createOpenAPISpec = (
|
|
57
|
+
context: C15TContext,
|
|
58
|
+
options: C15TOptions
|
|
59
|
+
) => {
|
|
60
|
+
// Initialize OpenAPI generator with schema converters
|
|
61
|
+
const openAPIGenerator = new OpenAPIGenerator({
|
|
62
|
+
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Memoise once per process
|
|
66
|
+
const getOpenAPISpec = (async (): Promise<Record<string, unknown>> => {
|
|
67
|
+
if (getOpenAPISpec.cached) {
|
|
68
|
+
return getOpenAPISpec.cached;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const defaultOptions = createDefaultOpenAPIOptions(options);
|
|
72
|
+
const mergedOptions = options.advanced?.openapi?.options
|
|
73
|
+
? mergeOpenAPIOptions(
|
|
74
|
+
defaultOptions,
|
|
75
|
+
options.advanced.openapi.options as Record<string, unknown>
|
|
76
|
+
)
|
|
77
|
+
: defaultOptions;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
// We need to cast to the expected type due to incompatibilities between the types
|
|
81
|
+
// This is safe as we control the options format and it's compatible with what the generator expects
|
|
82
|
+
const spec = await openAPIGenerator.generate(
|
|
83
|
+
router,
|
|
84
|
+
mergedOptions as Record<string, unknown>
|
|
85
|
+
);
|
|
86
|
+
getOpenAPISpec.cached = spec;
|
|
87
|
+
return spec;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
context.logger?.error('Failed to generate OpenAPI spec:', error);
|
|
90
|
+
// Return a minimal valid spec to prevent UI errors
|
|
91
|
+
return {
|
|
92
|
+
openapi: '3.0.0',
|
|
93
|
+
info: { title: options.appName || 'c15t API', version: '0.0.0' },
|
|
94
|
+
paths: {},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}) as MemoizedSpecFunction;
|
|
98
|
+
|
|
99
|
+
return getOpenAPISpec;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Generate the default UI for API documentation
|
|
104
|
+
*/
|
|
105
|
+
export const createDocsUI = (options: C15TOptions) => {
|
|
106
|
+
const config = createOpenAPIConfig(options);
|
|
107
|
+
|
|
108
|
+
// If a custom template is provided, use it
|
|
109
|
+
if (config.customUiTemplate) {
|
|
110
|
+
return config.customUiTemplate;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Otherwise, return the default Scalar UI
|
|
114
|
+
return `
|
|
115
|
+
<!doctype html>
|
|
116
|
+
<html>
|
|
117
|
+
<head>
|
|
118
|
+
<title>${options.appName || 'c15t API'} Documentation</title>
|
|
119
|
+
<meta charset="utf-8" />
|
|
120
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
121
|
+
<link rel="icon" type="image/svg+xml" href="https://c15t.com/icon.svg" />
|
|
122
|
+
</head>
|
|
123
|
+
<body>
|
|
124
|
+
<script
|
|
125
|
+
id="api-reference"
|
|
126
|
+
data-url="${encodeURI(config.specPath)}">
|
|
127
|
+
</script>
|
|
128
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
129
|
+
</body>
|
|
130
|
+
</html>
|
|
131
|
+
`;
|
|
132
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI middleware for c15t
|
|
3
|
+
*
|
|
4
|
+
* This module provides OpenAPI functionality including:
|
|
5
|
+
* - Configuration management
|
|
6
|
+
* - Specification generation
|
|
7
|
+
* - Documentation UI
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { createDefaultOpenAPIOptions, createOpenAPIConfig } from './config';
|
|
11
|
+
export { createDocsUI, createOpenAPISpec } from './handlers';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { C15TOptions } from '~/v2/types';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_IP_HEADERS = [
|
|
4
|
+
'x-client-ip',
|
|
5
|
+
'x-forwarded-for',
|
|
6
|
+
'cf-connecting-ip',
|
|
7
|
+
'fastly-client-ip',
|
|
8
|
+
'x-real-ip',
|
|
9
|
+
'x-cluster-client-ip',
|
|
10
|
+
'x-forwarded',
|
|
11
|
+
'forwarded-for',
|
|
12
|
+
'forwarded',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export function getIpAddress(
|
|
16
|
+
req: Request | Headers,
|
|
17
|
+
options: C15TOptions
|
|
18
|
+
): string | 'unknown' {
|
|
19
|
+
const ipAddress = options.advanced?.ipAddress;
|
|
20
|
+
|
|
21
|
+
if (ipAddress?.disableIpTracking) {
|
|
22
|
+
return 'unknown';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ipHeaders = ipAddress?.ipAddressHeaders || DEFAULT_IP_HEADERS;
|
|
26
|
+
|
|
27
|
+
const headers = req instanceof Request ? req.headers : req;
|
|
28
|
+
for (const key of ipHeaders) {
|
|
29
|
+
const value = headers.get(key);
|
|
30
|
+
if (value) {
|
|
31
|
+
const ip = value.split(',')[0]?.trim();
|
|
32
|
+
if (ip) {
|
|
33
|
+
return ip;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return 'unknown';
|
|
39
|
+
}
|
package/src/v2/router.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API path template literal for c15t consent endpoints
|
|
3
|
+
*
|
|
4
|
+
* This type defines the base path for all consent API routes in the c15t system.
|
|
5
|
+
* Used as a foundation for building type-safe consent API route paths.
|
|
6
|
+
*
|
|
7
|
+
* @see ApiPath for complete path patterns
|
|
8
|
+
*/
|
|
9
|
+
export type ApiPathBase = `/api/c15t`;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Consent API route path with strict type checking
|
|
13
|
+
*
|
|
14
|
+
* This type union represents all valid consent API paths in the system.
|
|
15
|
+
* It enforces type safety when defining routes or middlewares to
|
|
16
|
+
* prevent typos and ensure consistency.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Valid consent API path
|
|
21
|
+
* const consentPath: ApiPath = '/api/c15t/consent';
|
|
22
|
+
*
|
|
23
|
+
* // Invalid - would cause a type error
|
|
24
|
+
* const invalidPath: ApiPath = '/api/c15t/unknown-endpoint';
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type ApiPath =
|
|
28
|
+
| `${ApiPathBase}`
|
|
29
|
+
| `${ApiPathBase}/consent`
|
|
30
|
+
| `${ApiPathBase}/consent/:id`
|
|
31
|
+
| `${ApiPathBase}/jurisdictions`
|
|
32
|
+
| `${ApiPathBase}/jurisdictions/:code`;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Translations } from '@c15t/translations';
|
|
2
|
+
import type { createLogger, LoggerOptions } from '@doubletie/logger';
|
|
3
|
+
import type { Tracer } from '@opentelemetry/api';
|
|
4
|
+
import type { OpenAPIGeneratorOptions } from '@orpc/openapi';
|
|
5
|
+
import type { FumaDB, InferFumaDB } from 'fumadb';
|
|
6
|
+
import type { createRegistry } from '../db/registry';
|
|
7
|
+
import type { DB } from '../db/schema';
|
|
8
|
+
|
|
9
|
+
export * from './api';
|
|
10
|
+
|
|
11
|
+
export const branding = ['c15t', 'consent', 'none'] as const;
|
|
12
|
+
export type Branding = (typeof branding)[number];
|
|
13
|
+
|
|
14
|
+
export interface DatabaseOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The database adapter to use.
|
|
17
|
+
*/
|
|
18
|
+
adapter: FumaDB<FumaDBSchema>['adapter'];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface BaseOptions {
|
|
22
|
+
appName?: string;
|
|
23
|
+
basePath?: string;
|
|
24
|
+
trustedOrigins: string[];
|
|
25
|
+
advanced?: {
|
|
26
|
+
/**
|
|
27
|
+
* Disable geo location - Banner will allways be shown
|
|
28
|
+
*
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
disableGeoLocation?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Override base translations
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* {
|
|
38
|
+
* en: enTranslations,
|
|
39
|
+
* de: deTranslations,
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
customTranslations?: Record<string, Partial<Translations>>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Select which branding to show in the consent banner.
|
|
47
|
+
* Use "none" to hide branding.
|
|
48
|
+
* @default "c15t"
|
|
49
|
+
*/
|
|
50
|
+
branding?: Branding;
|
|
51
|
+
|
|
52
|
+
openapi?: {
|
|
53
|
+
/**
|
|
54
|
+
* Enable/disable OpenAPI spec generation
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Path to serve the OpenAPI JSON spec
|
|
61
|
+
* @default "/spec.json"
|
|
62
|
+
*/
|
|
63
|
+
specPath?: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Path to serve the API documentation UI
|
|
67
|
+
* @default "/docs"
|
|
68
|
+
*/
|
|
69
|
+
docsPath?: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* OpenAPI specification options
|
|
73
|
+
* These are passed to the OpenAPIGenerator.generate() method
|
|
74
|
+
*/
|
|
75
|
+
options?: Partial<OpenAPIGeneratorOptions>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Custom template for rendering the API documentation UI
|
|
79
|
+
* If provided, this will be used instead of the default Scalar UI
|
|
80
|
+
*/
|
|
81
|
+
customUiTemplate?: string;
|
|
82
|
+
};
|
|
83
|
+
telemetry?: {
|
|
84
|
+
disabled?: boolean;
|
|
85
|
+
tracer?: Tracer;
|
|
86
|
+
defaultAttributes?: Record<string, string | number | boolean>;
|
|
87
|
+
};
|
|
88
|
+
ipAddress?: {
|
|
89
|
+
disableIpTracking?: boolean;
|
|
90
|
+
// Override default ip address headers
|
|
91
|
+
ipAddressHeaders?: string[];
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type FumaDBSchema = InferFumaDB<typeof DB>['schemas'];
|
|
97
|
+
export interface C15TOptions extends BaseOptions, DatabaseOptions {
|
|
98
|
+
logger?: LoggerOptions;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface C15TContext extends BaseOptions {
|
|
102
|
+
appName: string;
|
|
103
|
+
logger: ReturnType<typeof createLogger>;
|
|
104
|
+
registry: ReturnType<typeof createRegistry>;
|
|
105
|
+
db: ReturnType<InferFumaDB<typeof DB>['orm']>;
|
|
106
|
+
|
|
107
|
+
// Resolved from request
|
|
108
|
+
ipAddress?: string;
|
|
109
|
+
userAgent?: string;
|
|
110
|
+
origin?: string;
|
|
111
|
+
trustedOrigin?: boolean;
|
|
112
|
+
path?: string;
|
|
113
|
+
method?: string;
|
|
114
|
+
headers?: Headers;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type DeepPartial<T> = T extends (...args: unknown[]) => unknown
|
|
118
|
+
? T
|
|
119
|
+
: T extends object
|
|
120
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
121
|
+
: T;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type Span, SpanStatusCode, trace } from '@opentelemetry/api';
|
|
2
|
+
import type { C15TOptions } from '~/v2/types';
|
|
3
|
+
import { version } from '~/version';
|
|
4
|
+
|
|
5
|
+
type TelemetryConfig = NonNullable<C15TOptions['advanced']>['telemetry'];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates telemetry configuration from provided options
|
|
9
|
+
*
|
|
10
|
+
* This function merges user-provided telemetry options with sensible defaults,
|
|
11
|
+
* ensuring that service name and version are always properly set.
|
|
12
|
+
*
|
|
13
|
+
* @param appName - The application name to use for service.name attribute
|
|
14
|
+
* @param telemetryConfig - Optional user-provided telemetry configuration
|
|
15
|
+
* @returns Properly structured telemetry options for the OpenTelemetry SDK
|
|
16
|
+
*/
|
|
17
|
+
export function createTelemetryOptions(
|
|
18
|
+
appName = 'c15t',
|
|
19
|
+
telemetryConfig?: TelemetryConfig
|
|
20
|
+
): TelemetryConfig {
|
|
21
|
+
const config: TelemetryConfig = {
|
|
22
|
+
disabled: telemetryConfig?.disabled ?? false,
|
|
23
|
+
tracer: telemetryConfig?.tracer,
|
|
24
|
+
|
|
25
|
+
defaultAttributes: {
|
|
26
|
+
...(telemetryConfig?.defaultAttributes || {}),
|
|
27
|
+
|
|
28
|
+
// Always ensure these core attributes are set
|
|
29
|
+
// (will override user values if they exist)
|
|
30
|
+
'service.name': String(appName),
|
|
31
|
+
'service.version': version,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Gets or creates a tracer for the api-router package
|
|
40
|
+
*/
|
|
41
|
+
export const getTracer = (options?: C15TOptions) => {
|
|
42
|
+
if (options?.advanced?.telemetry?.tracer) {
|
|
43
|
+
return options.advanced.telemetry.tracer;
|
|
44
|
+
}
|
|
45
|
+
return trace.getTracer(options?.appName ?? 'c15t');
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a span for an API request
|
|
50
|
+
*/
|
|
51
|
+
export const createRequestSpan = (
|
|
52
|
+
method: string,
|
|
53
|
+
path: string,
|
|
54
|
+
options?: C15TOptions
|
|
55
|
+
) => {
|
|
56
|
+
if (options?.advanced?.telemetry?.disabled) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const tracer = getTracer(options);
|
|
61
|
+
const span = tracer.startSpan(`${method} ${path}`, {
|
|
62
|
+
attributes: {
|
|
63
|
+
'http.method': method,
|
|
64
|
+
'http.path': path,
|
|
65
|
+
...(options?.advanced?.telemetry?.defaultAttributes || {}),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return span;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Wraps an API request handler in a span
|
|
74
|
+
*/
|
|
75
|
+
export const withRequestSpan = async <T>(
|
|
76
|
+
method: string,
|
|
77
|
+
path: string,
|
|
78
|
+
operation: () => Promise<T>,
|
|
79
|
+
options?: C15TOptions
|
|
80
|
+
): Promise<T> => {
|
|
81
|
+
const span = createRequestSpan(method, path, options);
|
|
82
|
+
|
|
83
|
+
if (!span) {
|
|
84
|
+
return operation();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const result = await operation();
|
|
89
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
90
|
+
return result;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
handleSpanError(span, error);
|
|
93
|
+
throw error;
|
|
94
|
+
} finally {
|
|
95
|
+
span.end();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Handles errors in spans
|
|
101
|
+
*/
|
|
102
|
+
const handleSpanError = (span: Span, error: unknown) => {
|
|
103
|
+
span.setStatus({
|
|
104
|
+
code: SpanStatusCode.ERROR,
|
|
105
|
+
message: error instanceof Error ? error.message : String(error),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (error instanceof Error) {
|
|
109
|
+
span.setAttribute('error.type', error.name);
|
|
110
|
+
span.setAttribute('error.message', error.message);
|
|
111
|
+
if (error.stack) {
|
|
112
|
+
span.setAttribute('error.stack', error.stack);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variables object
|
|
3
|
+
*
|
|
4
|
+
* Provides access to environment variables in a way that works in both
|
|
5
|
+
* browser and Node.js environments. In Node.js, this will be process.env,
|
|
6
|
+
* and in browsers, it will be an empty object.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing environment variables accessible in the current runtime
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Access an environment variable
|
|
13
|
+
* const apiKey = env.API_KEY;
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const env = typeof process !== 'undefined' ? process.env : {};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Determines if the application is running in production mode
|
|
20
|
+
*
|
|
21
|
+
* Checks if NODE_ENV is set to 'production'. This is useful for
|
|
22
|
+
* conditionally enabling or disabling features based on the environment.
|
|
23
|
+
*
|
|
24
|
+
* @returns Boolean indicating whether the application is running in production mode
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Conditionally execute code based on environment
|
|
29
|
+
* if (isProduction) {
|
|
30
|
+
* // Production-only code
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const isProduction =
|
|
35
|
+
typeof process !== 'undefined' && process.env.NODE_ENV === 'production';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Converts a string or boolean value to a boolean
|
|
39
|
+
*
|
|
40
|
+
* @param val - The value to convert to boolean
|
|
41
|
+
* @returns `false` if the value is falsy or the string 'false', otherwise `true`
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* toBoolean('true'); // true
|
|
46
|
+
* toBoolean('false'); // false
|
|
47
|
+
* toBoolean(undefined); // false
|
|
48
|
+
* toBoolean(true); // true
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @internal Used for environment variable parsing
|
|
52
|
+
*/
|
|
53
|
+
function toBoolean(val: boolean | string | undefined) {
|
|
54
|
+
return val ? val !== 'false' : false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The current Node.js environment value
|
|
59
|
+
*
|
|
60
|
+
* Retrieves the NODE_ENV environment variable value if available,
|
|
61
|
+
* otherwise returns an empty string.
|
|
62
|
+
*
|
|
63
|
+
* @returns The current NODE_ENV value or empty string if not set
|
|
64
|
+
*/
|
|
65
|
+
export const nodeENV =
|
|
66
|
+
(typeof process !== 'undefined' && process.env && process.env.NODE_ENV) || '';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Determines if the application is running in test mode
|
|
70
|
+
*
|
|
71
|
+
* Checks if NODE_ENV is set to 'test' or if the TEST environment
|
|
72
|
+
* variable is truthy and not 'false'.
|
|
73
|
+
*
|
|
74
|
+
* @returns Boolean indicating whether the application is running in test mode
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* // Skip expensive operations in tests
|
|
79
|
+
* if (!isTest) {
|
|
80
|
+
* runExpensiveOperation();
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export const isTest = nodeENV === 'test' || toBoolean(env.TEST);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLogger as createDTLogger,
|
|
3
|
+
type LoggerOptions,
|
|
4
|
+
} from '@doubletie/logger';
|
|
5
|
+
|
|
6
|
+
let globalLogger: ReturnType<typeof createDTLogger>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets or creates a global logger instance
|
|
10
|
+
*
|
|
11
|
+
* @param options - Optional logger configuration options
|
|
12
|
+
* @returns The global logger instance
|
|
13
|
+
*/
|
|
14
|
+
export function getLogger(
|
|
15
|
+
options?: LoggerOptions
|
|
16
|
+
): ReturnType<typeof createDTLogger> {
|
|
17
|
+
if (!globalLogger) {
|
|
18
|
+
globalLogger = createDTLogger({
|
|
19
|
+
level: 'info',
|
|
20
|
+
appName: 'c15t',
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return globalLogger;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initializes the global logger with specific options
|
|
29
|
+
*
|
|
30
|
+
* @param options - Logger configuration options
|
|
31
|
+
* @returns The initialized global logger instance
|
|
32
|
+
*/
|
|
33
|
+
export function initLogger(
|
|
34
|
+
options: LoggerOptions
|
|
35
|
+
): ReturnType<typeof createDTLogger> {
|
|
36
|
+
globalLogger = createDTLogger(options);
|
|
37
|
+
return globalLogger;
|
|
38
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.6.0';
|
package/vitest.config.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
2
3
|
import { baseConfig } from '@c15t/vitest-config/base';
|
|
3
4
|
import { defineConfig, mergeConfig } from 'vitest/config';
|
|
4
5
|
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
5
9
|
export default mergeConfig(
|
|
6
10
|
baseConfig,
|
|
7
11
|
defineConfig({
|
|
8
12
|
resolve: {
|
|
9
13
|
alias: {
|
|
10
|
-
'~': resolve(__dirname, './src'),
|
|
14
|
+
'~': path.resolve(__dirname, './src'),
|
|
15
|
+
// Workaround: fumadb imports without extension, but Node ESM needs .js
|
|
16
|
+
'semver/functions/compare': 'semver/functions/compare.js',
|
|
11
17
|
},
|
|
12
18
|
},
|
|
13
19
|
test: {
|
|
14
20
|
environment: 'node',
|
|
21
|
+
deps: {
|
|
22
|
+
inline: ['fumadb'],
|
|
23
|
+
},
|
|
15
24
|
},
|
|
16
25
|
})
|
|
17
26
|
);
|