@c15t/backend 1.2.0-canary.13 → 1.2.0-canary.2
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 +20 -22
- package/.turbo/turbo-fmt.log +4 -4
- 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 +2 -2
- package/dist/contracts/consent/post.contract.d.ts +2 -2
- package/dist/contracts/consent/post.contract.d.ts.map +1 -1
- package/dist/contracts/index.d.ts +5 -5
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/core.cjs +244 -388
- package/dist/core.d.ts +5 -3
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +244 -388
- package/dist/handlers/consent/index.d.ts +2 -2
- package/dist/handlers/consent/post.handler.d.ts +2 -2
- package/dist/handlers/consent/show-banner.handler.d.ts.map +1 -1
- package/dist/pkgs/api-router/utils/core.test.d.ts +2 -0
- package/dist/pkgs/api-router/utils/core.test.d.ts.map +1 -0
- package/dist/pkgs/api-router/utils/cors.d.ts +14 -0
- package/dist/pkgs/api-router/utils/cors.d.ts.map +1 -0
- package/dist/pkgs/data-model/fields/zod-fields.d.ts +32 -32
- package/dist/pkgs/data-model/index.cjs +39 -59
- package/dist/pkgs/data-model/index.js +39 -59
- package/dist/pkgs/data-model/schema/index.cjs +39 -59
- package/dist/pkgs/data-model/schema/index.js +39 -59
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +1 -0
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +1 -0
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +1 -0
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +1 -0
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs +1 -0
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +1 -0
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +1 -0
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +1 -0
- package/dist/pkgs/db-adapters/index.cjs +1 -0
- package/dist/pkgs/db-adapters/index.js +1 -0
- package/dist/pkgs/migrations/index.cjs +1 -0
- package/dist/pkgs/migrations/index.js +1 -0
- package/dist/router.cjs +5 -3
- package/dist/router.d.ts +2 -2
- package/dist/router.js +5 -3
- package/dist/schema/consent-policy/registry.d.ts +4 -4
- package/dist/schema/consent-policy/registry.d.ts.map +1 -1
- package/dist/schema/consent-policy/schema.d.ts +2 -2
- package/dist/schema/consent-policy/table.d.ts +2 -2
- package/dist/schema/consent-purpose/registry.d.ts +2 -2
- package/dist/schema/consent-purpose/schema.d.ts +2 -2
- package/dist/schema/consent-purpose/table.d.ts +2 -2
- package/dist/schema/create-registry.d.ts +6 -6
- package/dist/schema/create-registry.d.ts.map +1 -1
- package/dist/schema/definition.d.ts +4 -4
- package/dist/schema/index.cjs +39 -59
- package/dist/schema/index.js +39 -59
- package/dist/schema/schemas.d.ts +4 -4
- package/package.json +2 -8
- package/rslib.config.ts +0 -1
- package/src/contracts/consent/post.contract.ts +6 -1
- package/src/contracts/index.ts +0 -2
- package/src/core.ts +195 -96
- package/src/handlers/consent/show-banner.handler.test.ts +1 -1
- package/src/handlers/consent/show-banner.handler.ts +2 -1
- package/src/{middleware/cors/is-origin-trusted.test.ts → pkgs/api-router/utils/core.test.ts} +1 -1
- package/src/pkgs/api-router/utils/cors.ts +73 -0
- package/src/schema/consent-policy/registry.ts +50 -76
- package/src/server.ts +5 -1
- package/dist/__tests__/server.test.d.ts +0 -2
- package/dist/__tests__/server.test.d.ts.map +0 -1
- package/dist/contracts.cjs +0 -708
- package/dist/contracts.js +0 -661
- package/dist/middleware/cors/cors.d.ts +0 -37
- package/dist/middleware/cors/cors.d.ts.map +0 -1
- package/dist/middleware/cors/cors.test.d.ts +0 -2
- package/dist/middleware/cors/cors.test.d.ts.map +0 -1
- package/dist/middleware/cors/index.d.ts +0 -30
- package/dist/middleware/cors/index.d.ts.map +0 -1
- package/dist/middleware/cors/is-origin-trusted.d.ts +0 -49
- package/dist/middleware/cors/is-origin-trusted.d.ts.map +0 -1
- package/dist/middleware/cors/is-origin-trusted.test.d.ts +0 -2
- package/dist/middleware/cors/is-origin-trusted.test.d.ts.map +0 -1
- package/dist/middleware/cors/process-cors.d.ts +0 -31
- package/dist/middleware/cors/process-cors.d.ts.map +0 -1
- package/dist/middleware/openapi/config.d.ts +0 -28
- package/dist/middleware/openapi/config.d.ts.map +0 -1
- package/dist/middleware/openapi/handlers.d.ts +0 -29
- package/dist/middleware/openapi/handlers.d.ts.map +0 -1
- package/dist/middleware/openapi/index.d.ts +0 -11
- package/dist/middleware/openapi/index.d.ts.map +0 -1
- package/src/__tests__/server.test.ts +0 -96
- package/src/middleware/cors/cors.test.ts +0 -419
- package/src/middleware/cors/cors.ts +0 -192
- package/src/middleware/cors/index.ts +0 -30
- package/src/middleware/cors/is-origin-trusted.ts +0 -126
- package/src/middleware/cors/process-cors.ts +0 -91
- package/src/middleware/openapi/config.ts +0 -28
- package/src/middleware/openapi/handlers.ts +0 -132
- package/src/middleware/openapi/index.ts +0 -11
package/dist/core.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__ from "@doubletie/logger";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__orpc_openapi_a95cc8e7__ from "@orpc/openapi";
|
|
2
3
|
import * as __WEBPACK_EXTERNAL_MODULE__orpc_openapi_fetch_89b49e61__ from "@orpc/openapi/fetch";
|
|
3
4
|
import * as __WEBPACK_EXTERNAL_MODULE__orpc_server_plugins_e445fd4f__ from "@orpc/server/plugins";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__orpc_zod_716a28d4__ from "@orpc/zod";
|
|
4
6
|
import * as __WEBPACK_EXTERNAL_MODULE_neverthrow__ from "neverthrow";
|
|
5
7
|
import * as __WEBPACK_EXTERNAL_MODULE__orpc_server_0dae8408__ from "@orpc/server";
|
|
6
8
|
import * as __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__ from "@opentelemetry/api";
|
|
@@ -11,10 +13,9 @@ import * as __WEBPACK_EXTERNAL_MODULE_defu__ from "defu";
|
|
|
11
13
|
import * as __WEBPACK_EXTERNAL_MODULE_superjson__ from "superjson";
|
|
12
14
|
import * as __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__ from "base-x";
|
|
13
15
|
import * as __WEBPACK_EXTERNAL_MODULE_zod__ from "zod";
|
|
16
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
14
17
|
import * as __WEBPACK_EXTERNAL_MODULE_kysely__ from "kysely";
|
|
15
18
|
import "drizzle-orm";
|
|
16
|
-
import * as __WEBPACK_EXTERNAL_MODULE__orpc_openapi_a95cc8e7__ from "@orpc/openapi";
|
|
17
|
-
import * as __WEBPACK_EXTERNAL_MODULE__orpc_zod_716a28d4__ from "@orpc/zod";
|
|
18
19
|
import * as __WEBPACK_EXTERNAL_MODULE__orpc_contract_5a058524__ from "@orpc/contract";
|
|
19
20
|
const error_codes_ERROR_CODES = Object.freeze({
|
|
20
21
|
NOT_FOUND: 'Resource not found',
|
|
@@ -260,6 +261,7 @@ function createTelemetryOptions(appName = 'c15t', telemetryConfig) {
|
|
|
260
261
|
};
|
|
261
262
|
return config;
|
|
262
263
|
}
|
|
264
|
+
var package_namespaceObject = JSON.parse('{"i8":"1.2.0-canary.2"}');
|
|
263
265
|
function utils_applyDefaultValue(inputValue, field, operation) {
|
|
264
266
|
if ('update' === operation) return inputValue;
|
|
265
267
|
if (null == inputValue && field.defaultValue) {
|
|
@@ -1176,21 +1178,9 @@ function consentRegistry({ adapter, ...ctx }) {
|
|
|
1176
1178
|
};
|
|
1177
1179
|
return registry;
|
|
1178
1180
|
}
|
|
1179
|
-
|
|
1181
|
+
function generatePolicyPlaceholder(name, date) {
|
|
1180
1182
|
const content = `[PLACEHOLDER] This is an automatically generated version of the ${name} policy.\n\nThis placeholder content should be replaced with actual policy terms before being presented to users.\n\nGenerated on: ${date.toISOString()}`;
|
|
1181
|
-
|
|
1182
|
-
try {
|
|
1183
|
-
const encoder = new TextEncoder();
|
|
1184
|
-
const data = encoder.encode(content);
|
|
1185
|
-
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
1186
|
-
contentHash = Array.from(new Uint8Array(hashBuffer)).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
1187
|
-
} catch (error) {
|
|
1188
|
-
throw new error_class_DoubleTieError('Failed to generate policy content hash', {
|
|
1189
|
-
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1190
|
-
status: 500,
|
|
1191
|
-
cause: error instanceof Error ? error : new Error(String(error))
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1183
|
+
const contentHash = (0, __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__.createHash)('sha256').update(content).digest('hex');
|
|
1194
1184
|
return {
|
|
1195
1185
|
content,
|
|
1196
1186
|
contentHash
|
|
@@ -1250,53 +1240,44 @@ function policyRegistry({ adapter, ...ctx }) {
|
|
|
1250
1240
|
});
|
|
1251
1241
|
return policy ? validateEntityOutput('consentPolicy', policy, ctx.options) : null;
|
|
1252
1242
|
},
|
|
1253
|
-
findOrCreatePolicy: async (type)=>
|
|
1243
|
+
findOrCreatePolicy: async (type)=>adapter.transaction({
|
|
1254
1244
|
callback: async (txAdapter)=>{
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
value: type
|
|
1271
|
-
}
|
|
1272
|
-
],
|
|
1273
|
-
sortBy: {
|
|
1274
|
-
field: 'effectiveDate',
|
|
1275
|
-
direction: 'desc'
|
|
1245
|
+
const now = new Date();
|
|
1246
|
+
const txRegistry = policyRegistry({
|
|
1247
|
+
adapter: txAdapter,
|
|
1248
|
+
...ctx
|
|
1249
|
+
});
|
|
1250
|
+
const rawLatestPolicy = await txAdapter.findOne({
|
|
1251
|
+
model: 'consentPolicy',
|
|
1252
|
+
where: [
|
|
1253
|
+
{
|
|
1254
|
+
field: 'isActive',
|
|
1255
|
+
value: true
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
field: 'type',
|
|
1259
|
+
value: type
|
|
1276
1260
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
cause: error instanceof Error ? error : new Error(String(error))
|
|
1298
|
-
});
|
|
1299
|
-
}
|
|
1261
|
+
],
|
|
1262
|
+
sortBy: {
|
|
1263
|
+
field: 'effectiveDate',
|
|
1264
|
+
direction: 'desc'
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
const latestPolicy = rawLatestPolicy ? validateEntityOutput('consentPolicy', rawLatestPolicy, ctx.options) : null;
|
|
1268
|
+
if (latestPolicy) return latestPolicy;
|
|
1269
|
+
const { content: defaultContent, contentHash } = generatePolicyPlaceholder(type, now);
|
|
1270
|
+
return txRegistry.createConsentPolicy({
|
|
1271
|
+
version: '1.0.0',
|
|
1272
|
+
type,
|
|
1273
|
+
name: type,
|
|
1274
|
+
effectiveDate: now,
|
|
1275
|
+
content: defaultContent,
|
|
1276
|
+
contentHash,
|
|
1277
|
+
isActive: true,
|
|
1278
|
+
updatedAt: now,
|
|
1279
|
+
expirationDate: null
|
|
1280
|
+
});
|
|
1300
1281
|
}
|
|
1301
1282
|
})
|
|
1302
1283
|
};
|
|
@@ -2197,7 +2178,6 @@ function getBaseURL(url, path) {
|
|
|
2197
2178
|
const fromEnv = env.C15T_URL || env.NEXT_PUBLIC_C15T_URL || env.PUBLIC_C15T_URL || env.NUXT_PUBLIC_C15T_URL || env.NUXT_PUBLIC_AUTH_URL || ('/' !== env.BASE_URL ? env.BASE_URL : void 0);
|
|
2198
2179
|
if (fromEnv) return withPath(fromEnv, path);
|
|
2199
2180
|
}
|
|
2200
|
-
var package_namespaceObject = JSON.parse('{"i8":"1.2.0-canary.13"}');
|
|
2201
2181
|
const createRegistry = (ctx)=>({
|
|
2202
2182
|
...auditLogRegistry(ctx),
|
|
2203
2183
|
...consentRegistry(ctx),
|
|
@@ -2349,86 +2329,51 @@ function getInternalPlugins(_options) {
|
|
|
2349
2329
|
const plugins = [];
|
|
2350
2330
|
return plugins;
|
|
2351
2331
|
}
|
|
2352
|
-
const
|
|
2353
|
-
const
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
'POST',
|
|
2357
|
-
'PUT',
|
|
2358
|
-
'DELETE',
|
|
2359
|
-
'PATCH',
|
|
2360
|
-
'OPTIONS'
|
|
2361
|
-
];
|
|
2362
|
-
const SUPPORTED_HEADERS = [
|
|
2363
|
-
'Content-Type',
|
|
2364
|
-
'Authorization',
|
|
2365
|
-
'x-request-id'
|
|
2366
|
-
];
|
|
2367
|
-
const DEFAULT_CORS_CONFIG = {
|
|
2368
|
-
origin: async (origin)=>await Promise.resolve(origin || '*'),
|
|
2369
|
-
credentials: true,
|
|
2370
|
-
allowHeaders: SUPPORTED_HEADERS,
|
|
2371
|
-
maxAge: 600,
|
|
2372
|
-
methods: SUPPORTED_METHODS
|
|
2332
|
+
const API_ROUTER_TRACER_NAME = '@doubletie/api-router';
|
|
2333
|
+
const getTracer = (options)=>{
|
|
2334
|
+
if (options?.telemetry?.tracer) return options.telemetry.tracer;
|
|
2335
|
+
return __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__.trace.getTracer(API_ROUTER_TRACER_NAME);
|
|
2373
2336
|
};
|
|
2374
|
-
|
|
2375
|
-
if (
|
|
2376
|
-
const
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
if (!origin.includes('://') && !origin.includes(':') && !origin.includes('/')) return origin.toLowerCase();
|
|
2383
|
-
const originWithProtocol = origin.startsWith('http://') || origin.startsWith('https://') || origin.startsWith('ws://') || origin.startsWith('wss://') ? origin : `http://${origin}`;
|
|
2384
|
-
const url = new URL(originWithProtocol);
|
|
2385
|
-
const hostname = url.hostname.replace(WWW_REGEX, '');
|
|
2386
|
-
return `${hostname}${url.port ? `:${url.port}` : ''}`;
|
|
2387
|
-
} catch {
|
|
2388
|
-
return origin.replace(PROTOCOL_WWW_REGEX, '').replace(WWW_REGEX, '');
|
|
2337
|
+
const createRequestSpan = (method, path, options)=>{
|
|
2338
|
+
if (options?.telemetry?.disabled) return null;
|
|
2339
|
+
const tracer = getTracer(options);
|
|
2340
|
+
const span = tracer.startSpan(`${method} ${path}`, {
|
|
2341
|
+
attributes: {
|
|
2342
|
+
'http.method': method,
|
|
2343
|
+
'http.path': path,
|
|
2344
|
+
...options?.telemetry?.defaultAttributes || {}
|
|
2389
2345
|
}
|
|
2346
|
+
});
|
|
2347
|
+
return span;
|
|
2348
|
+
};
|
|
2349
|
+
const withRequestSpan = async (method, path, operation, options)=>{
|
|
2350
|
+
const span = createRequestSpan(method, path, options);
|
|
2351
|
+
if (!span) return operation();
|
|
2352
|
+
try {
|
|
2353
|
+
const result = await operation();
|
|
2354
|
+
span.setStatus({
|
|
2355
|
+
code: __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__.SpanStatusCode.OK
|
|
2356
|
+
});
|
|
2357
|
+
return result;
|
|
2358
|
+
} catch (error) {
|
|
2359
|
+
handleSpanError(span, error);
|
|
2360
|
+
throw error;
|
|
2361
|
+
} finally{
|
|
2362
|
+
span.end();
|
|
2390
2363
|
}
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2402
|
-
return Array.from(expanded);
|
|
2364
|
+
};
|
|
2365
|
+
const handleSpanError = (span, error)=>{
|
|
2366
|
+
span.setStatus({
|
|
2367
|
+
code: __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__.SpanStatusCode.ERROR,
|
|
2368
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2369
|
+
});
|
|
2370
|
+
if (error instanceof Error) {
|
|
2371
|
+
span.setAttribute('error.type', error.name);
|
|
2372
|
+
span.setAttribute('error.message', error.message);
|
|
2373
|
+
if (error.stack) span.setAttribute('error.stack', error.stack);
|
|
2403
2374
|
}
|
|
2404
|
-
|
|
2405
|
-
const returnConfig = {
|
|
2406
|
-
origin: async (origin)=>{
|
|
2407
|
-
if (!origin) return '*';
|
|
2408
|
-
const normalizedOrigin = normalizeOrigin(origin);
|
|
2409
|
-
if (expandedTrusted.includes('*')) return origin;
|
|
2410
|
-
const isTrusted = expandedTrusted.some((trusted)=>{
|
|
2411
|
-
const normalizedTrusted = normalizeOrigin(trusted);
|
|
2412
|
-
if ('localhost' === normalizedTrusted) return 'localhost' === normalizedOrigin || normalizedOrigin.startsWith('localhost:') || '127.0.0.1' === normalizedOrigin || normalizedOrigin.startsWith('127.0.0.1:') || '[::1]' === normalizedOrigin || normalizedOrigin.startsWith('[::1]:');
|
|
2413
|
-
return normalizedTrusted === normalizedOrigin;
|
|
2414
|
-
});
|
|
2415
|
-
return isTrusted ? origin : null;
|
|
2416
|
-
},
|
|
2417
|
-
credentials: true,
|
|
2418
|
-
allowHeaders: SUPPORTED_HEADERS,
|
|
2419
|
-
maxAge: 600,
|
|
2420
|
-
methods: SUPPORTED_METHODS
|
|
2421
|
-
};
|
|
2422
|
-
return returnConfig;
|
|
2423
|
-
}
|
|
2375
|
+
};
|
|
2424
2376
|
const STRIP_REGEX = /^(https?:\/\/)|(wss?:\/\/)|(\/+$)|:\d+/g;
|
|
2425
|
-
function matchesWildcard(hostname, wildcardPattern, logger) {
|
|
2426
|
-
const wildcardDomain = wildcardPattern.slice(2);
|
|
2427
|
-
const parts = hostname.split('.');
|
|
2428
|
-
const isValid = parts.length > 2 && hostname.endsWith(wildcardDomain);
|
|
2429
|
-
logger?.debug(`Wildcard match result: ${isValid} ${hostname} ends with ${wildcardDomain} ${parts.length > 2} ${hostname.endsWith(wildcardDomain)}`);
|
|
2430
|
-
return isValid;
|
|
2431
|
-
}
|
|
2432
2377
|
function isOriginTrusted(origin, trustedDomains, logger) {
|
|
2433
2378
|
try {
|
|
2434
2379
|
if (0 === trustedDomains.length) throw new Error('No trusted domains');
|
|
@@ -2447,7 +2392,13 @@ function isOriginTrusted(origin, trustedDomains, logger) {
|
|
|
2447
2392
|
}
|
|
2448
2393
|
const strippedDomain = domain.replace(STRIP_REGEX, '').toLowerCase();
|
|
2449
2394
|
logger?.debug(`Checking against stripped domain: ${strippedDomain}`);
|
|
2450
|
-
if (strippedDomain.startsWith('*.'))
|
|
2395
|
+
if (strippedDomain.startsWith('*.')) {
|
|
2396
|
+
const wildcardDomain = strippedDomain.slice(2);
|
|
2397
|
+
const parts = originHostname.split('.');
|
|
2398
|
+
const isValid = parts.length > 2 && originHostname.endsWith(wildcardDomain);
|
|
2399
|
+
logger?.debug(`Wildcard match result: ${isValid} ${originHostname} ends with ${wildcardDomain} ${parts.length > 2} ${originHostname.endsWith(wildcardDomain)}`);
|
|
2400
|
+
return isValid;
|
|
2401
|
+
}
|
|
2451
2402
|
const isMatch = originHostname === strippedDomain;
|
|
2452
2403
|
logger?.debug(`Exact match result: ${isMatch} ${originHostname} === ${strippedDomain}`);
|
|
2453
2404
|
return isMatch;
|
|
@@ -2457,55 +2408,37 @@ function isOriginTrusted(origin, trustedDomains, logger) {
|
|
|
2457
2408
|
return false;
|
|
2458
2409
|
}
|
|
2459
2410
|
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
const
|
|
2473
|
-
if (
|
|
2474
|
-
|
|
2475
|
-
|
|
2411
|
+
const DEFAULT_IP_HEADERS = [
|
|
2412
|
+
'x-client-ip',
|
|
2413
|
+
'x-forwarded-for',
|
|
2414
|
+
'cf-connecting-ip',
|
|
2415
|
+
'fastly-client-ip',
|
|
2416
|
+
'x-real-ip',
|
|
2417
|
+
'x-cluster-client-ip',
|
|
2418
|
+
'x-forwarded',
|
|
2419
|
+
'forwarded-for',
|
|
2420
|
+
'forwarded'
|
|
2421
|
+
];
|
|
2422
|
+
function getIp(req, options) {
|
|
2423
|
+
const advanced = options.advanced || {};
|
|
2424
|
+
if (advanced?.ipAddress?.disableIpTracking) return null;
|
|
2425
|
+
const testIP = '127.0.0.1';
|
|
2426
|
+
if (isTest) return testIP;
|
|
2427
|
+
const ipHeaders = advanced?.ipAddress?.ipAddressHeaders || DEFAULT_IP_HEADERS;
|
|
2428
|
+
const headers = req instanceof Request ? req.headers : req;
|
|
2429
|
+
for (const key of ipHeaders){
|
|
2430
|
+
const value = headers.get(key);
|
|
2431
|
+
if (value) {
|
|
2432
|
+
const ip = value.split(',')[0]?.trim();
|
|
2433
|
+
if (ip) return ip;
|
|
2434
|
+
}
|
|
2476
2435
|
}
|
|
2477
|
-
return
|
|
2478
|
-
}
|
|
2479
|
-
const createOpenAPIConfig = (options)=>{
|
|
2480
|
-
const basePath = options.basePath || '';
|
|
2481
|
-
return {
|
|
2482
|
-
enabled: true,
|
|
2483
|
-
specPath: `${basePath}/spec.json`,
|
|
2484
|
-
docsPath: `${basePath}/docs`,
|
|
2485
|
-
...options.openapi || {}
|
|
2486
|
-
};
|
|
2487
|
-
};
|
|
2488
|
-
const createDefaultOpenAPIOptions = (options)=>({
|
|
2489
|
-
info: {
|
|
2490
|
-
title: options.appName || 'c15t API',
|
|
2491
|
-
version: package_namespaceObject.i8,
|
|
2492
|
-
description: 'API for consent management'
|
|
2493
|
-
},
|
|
2494
|
-
servers: [
|
|
2495
|
-
{
|
|
2496
|
-
url: options.basePath || '/'
|
|
2497
|
-
}
|
|
2498
|
-
],
|
|
2499
|
-
security: [
|
|
2500
|
-
{
|
|
2501
|
-
bearerAuth: []
|
|
2502
|
-
}
|
|
2503
|
-
]
|
|
2504
|
-
});
|
|
2436
|
+
return null;
|
|
2437
|
+
}
|
|
2505
2438
|
const baseConsentSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
2506
2439
|
subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
|
|
2507
2440
|
externalSubjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
|
|
2508
|
-
domain: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
|
|
2441
|
+
domain: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().regex(/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/i, 'invalid domain'),
|
|
2509
2442
|
type: PolicyTypeSchema,
|
|
2510
2443
|
metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
|
|
2511
2444
|
});
|
|
@@ -3095,7 +3028,7 @@ function checkJurisdiction(countryCode) {
|
|
|
3095
3028
|
'KR'
|
|
3096
3029
|
])
|
|
3097
3030
|
};
|
|
3098
|
-
|
|
3031
|
+
let showConsentBanner = false;
|
|
3099
3032
|
let jurisdictionCode = 'NONE';
|
|
3100
3033
|
if (countryCode) {
|
|
3101
3034
|
const jurisdictionMap = [
|
|
@@ -3145,6 +3078,7 @@ function checkJurisdiction(countryCode) {
|
|
|
3145
3078
|
}
|
|
3146
3079
|
];
|
|
3147
3080
|
for (const { sets, code } of jurisdictionMap)if (sets.some((set)=>set.has(countryCode))) {
|
|
3081
|
+
showConsentBanner = true;
|
|
3148
3082
|
jurisdictionCode = code;
|
|
3149
3083
|
break;
|
|
3150
3084
|
}
|
|
@@ -3344,182 +3278,155 @@ const router = os.router({
|
|
|
3344
3278
|
consent: consentHandlers,
|
|
3345
3279
|
meta: metaHandlers
|
|
3346
3280
|
});
|
|
3347
|
-
const
|
|
3348
|
-
const
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3281
|
+
const c15tInstance = (options)=>{
|
|
3282
|
+
const contextPromise = init(options);
|
|
3283
|
+
const corsOptions = options.trustedOrigins ? {
|
|
3284
|
+
origin: options.trustedOrigins.includes('*') ? (origin)=>origin : options.trustedOrigins,
|
|
3285
|
+
credentials: true,
|
|
3286
|
+
methods: [
|
|
3287
|
+
'GET',
|
|
3288
|
+
'POST',
|
|
3289
|
+
'PUT',
|
|
3290
|
+
'DELETE',
|
|
3291
|
+
'OPTIONS',
|
|
3292
|
+
'PATCH'
|
|
3293
|
+
],
|
|
3294
|
+
allowedHeaders: [
|
|
3295
|
+
'Content-Type',
|
|
3296
|
+
'Authorization',
|
|
3297
|
+
'X-Request-ID'
|
|
3298
|
+
],
|
|
3299
|
+
maxAge: 86400
|
|
3300
|
+
} : {
|
|
3301
|
+
origin: '*',
|
|
3302
|
+
credentials: false,
|
|
3303
|
+
methods: [
|
|
3304
|
+
'GET',
|
|
3305
|
+
'POST',
|
|
3306
|
+
'PUT',
|
|
3307
|
+
'DELETE',
|
|
3308
|
+
'OPTIONS',
|
|
3309
|
+
'PATCH'
|
|
3310
|
+
],
|
|
3311
|
+
allowedHeaders: [
|
|
3312
|
+
'Content-Type',
|
|
3313
|
+
'Authorization',
|
|
3314
|
+
'X-Request-ID'
|
|
3315
|
+
],
|
|
3316
|
+
maxAge: 86400
|
|
3354
3317
|
};
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3318
|
+
const rpcHandler = new __WEBPACK_EXTERNAL_MODULE__orpc_openapi_fetch_89b49e61__.OpenAPIHandler(router, {
|
|
3319
|
+
plugins: [
|
|
3320
|
+
new __WEBPACK_EXTERNAL_MODULE__orpc_server_plugins_e445fd4f__.CORSPlugin({
|
|
3321
|
+
...corsOptions,
|
|
3322
|
+
origin: (origin)=>{
|
|
3323
|
+
if (!origin) return null;
|
|
3324
|
+
if (options.trustedOrigins?.includes('*')) return origin;
|
|
3325
|
+
if (options.trustedOrigins?.includes(origin)) return origin;
|
|
3326
|
+
return null;
|
|
3327
|
+
},
|
|
3328
|
+
credentials: true,
|
|
3329
|
+
exposeHeaders: [
|
|
3330
|
+
'Content-Type',
|
|
3331
|
+
'Authorization',
|
|
3332
|
+
'X-Request-ID'
|
|
3333
|
+
]
|
|
3334
|
+
})
|
|
3335
|
+
]
|
|
3336
|
+
});
|
|
3359
3337
|
const openAPIGenerator = new __WEBPACK_EXTERNAL_MODULE__orpc_openapi_a95cc8e7__.OpenAPIGenerator({
|
|
3360
3338
|
schemaConverters: [
|
|
3361
3339
|
new __WEBPACK_EXTERNAL_MODULE__orpc_zod_716a28d4__.ZodToJsonSchemaConverter()
|
|
3362
3340
|
]
|
|
3363
3341
|
});
|
|
3342
|
+
const openApiConfig = {
|
|
3343
|
+
enabled: true,
|
|
3344
|
+
specPath: '/spec.json',
|
|
3345
|
+
docsPath: '/docs',
|
|
3346
|
+
...options.openapi || {}
|
|
3347
|
+
};
|
|
3348
|
+
const defaultOpenApiOptions = {
|
|
3349
|
+
info: {
|
|
3350
|
+
title: options.appName || 'c15t API',
|
|
3351
|
+
version: package_namespaceObject.i8,
|
|
3352
|
+
description: 'API for consent management'
|
|
3353
|
+
},
|
|
3354
|
+
servers: [
|
|
3355
|
+
{
|
|
3356
|
+
url: '/'
|
|
3357
|
+
}
|
|
3358
|
+
],
|
|
3359
|
+
security: [
|
|
3360
|
+
{
|
|
3361
|
+
bearerAuth: []
|
|
3362
|
+
}
|
|
3363
|
+
]
|
|
3364
|
+
};
|
|
3365
|
+
const processIp = (request, context)=>{
|
|
3366
|
+
const ip = getIp(request, options);
|
|
3367
|
+
if (ip) context.ipAddress = ip;
|
|
3368
|
+
return context;
|
|
3369
|
+
};
|
|
3370
|
+
const processCors = (request, context)=>{
|
|
3371
|
+
const origin = request.headers.get('origin');
|
|
3372
|
+
if (origin && options.trustedOrigins) {
|
|
3373
|
+
const trusted = isOriginTrusted(origin, options.trustedOrigins, context.logger);
|
|
3374
|
+
context.origin = origin;
|
|
3375
|
+
context.trustedOrigin = trusted;
|
|
3376
|
+
}
|
|
3377
|
+
return context;
|
|
3378
|
+
};
|
|
3379
|
+
const processTelemetry = (request, context)=>{
|
|
3380
|
+
const url = new URL(request.url);
|
|
3381
|
+
const path = url.pathname;
|
|
3382
|
+
const method = request.method;
|
|
3383
|
+
withRequestSpan(method, path, async ()=>{}, options);
|
|
3384
|
+
context.path = path;
|
|
3385
|
+
context.method = method;
|
|
3386
|
+
context.headers = request.headers;
|
|
3387
|
+
context.userAgent = request.headers.get('user-agent') || void 0;
|
|
3388
|
+
return context;
|
|
3389
|
+
};
|
|
3364
3390
|
const getOpenAPISpec = async ()=>{
|
|
3365
3391
|
if (getOpenAPISpec.cached) return getOpenAPISpec.cached;
|
|
3366
|
-
const
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
return {
|
|
3375
|
-
openapi: '3.0.0',
|
|
3376
|
-
info: {
|
|
3377
|
-
title: options.appName || 'c15t API',
|
|
3378
|
-
version: '0.0.0'
|
|
3379
|
-
},
|
|
3380
|
-
paths: {}
|
|
3392
|
+
const mergedOptions = {
|
|
3393
|
+
...defaultOpenApiOptions
|
|
3394
|
+
};
|
|
3395
|
+
if (openApiConfig.options) {
|
|
3396
|
+
const userOptions = openApiConfig.options;
|
|
3397
|
+
if (userOptions.info) mergedOptions.info = {
|
|
3398
|
+
...defaultOpenApiOptions.info,
|
|
3399
|
+
...userOptions.info
|
|
3381
3400
|
};
|
|
3401
|
+
for (const [key, value] of Object.entries(userOptions))if ('info' !== key) mergedOptions[key] = value;
|
|
3382
3402
|
}
|
|
3403
|
+
const spec = await openAPIGenerator.generate(router, mergedOptions);
|
|
3404
|
+
getOpenAPISpec.cached = spec;
|
|
3405
|
+
return spec;
|
|
3383
3406
|
};
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
const config = createOpenAPIConfig(options);
|
|
3388
|
-
if (config.customUiTemplate) return config.customUiTemplate;
|
|
3389
|
-
return `
|
|
3407
|
+
const getDocsUI = ()=>{
|
|
3408
|
+
if (openApiConfig.customUiTemplate) return openApiConfig.customUiTemplate;
|
|
3409
|
+
return `
|
|
3390
3410
|
<!doctype html>
|
|
3391
3411
|
<html>
|
|
3392
3412
|
<head>
|
|
3393
3413
|
<title>${options.appName || 'c15t API'} Documentation</title>
|
|
3394
3414
|
<meta charset="utf-8" />
|
|
3395
3415
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
3396
|
-
<link rel="icon" type="image/svg+xml" href="https://
|
|
3416
|
+
<link rel="icon" type="image/svg+xml" href="https://orpc.unnoq.com/icon.svg" />
|
|
3397
3417
|
</head>
|
|
3398
3418
|
<body>
|
|
3399
3419
|
<script
|
|
3400
3420
|
id="api-reference"
|
|
3401
|
-
data-url="${encodeURI(
|
|
3421
|
+
data-url="${encodeURI(openApiConfig.specPath)}">
|
|
3402
3422
|
</script>
|
|
3403
3423
|
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
3404
3424
|
</body>
|
|
3405
3425
|
</html>
|
|
3406
|
-
|
|
3407
|
-
};
|
|
3408
|
-
const API_ROUTER_TRACER_NAME = '@doubletie/api-router';
|
|
3409
|
-
const getTracer = (options)=>{
|
|
3410
|
-
if (options?.telemetry?.tracer) return options.telemetry.tracer;
|
|
3411
|
-
return __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__.trace.getTracer(API_ROUTER_TRACER_NAME);
|
|
3412
|
-
};
|
|
3413
|
-
const createRequestSpan = (method, path, options)=>{
|
|
3414
|
-
if (options?.telemetry?.disabled) return null;
|
|
3415
|
-
const tracer = getTracer(options);
|
|
3416
|
-
const span = tracer.startSpan(`${method} ${path}`, {
|
|
3417
|
-
attributes: {
|
|
3418
|
-
'http.method': method,
|
|
3419
|
-
'http.path': path,
|
|
3420
|
-
...options?.telemetry?.defaultAttributes || {}
|
|
3421
|
-
}
|
|
3422
|
-
});
|
|
3423
|
-
return span;
|
|
3424
|
-
};
|
|
3425
|
-
const withRequestSpan = async (method, path, operation, options)=>{
|
|
3426
|
-
const span = createRequestSpan(method, path, options);
|
|
3427
|
-
if (!span) return operation();
|
|
3428
|
-
try {
|
|
3429
|
-
const result = await operation();
|
|
3430
|
-
span.setStatus({
|
|
3431
|
-
code: __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__.SpanStatusCode.OK
|
|
3432
|
-
});
|
|
3433
|
-
return result;
|
|
3434
|
-
} catch (error) {
|
|
3435
|
-
handleSpanError(span, error);
|
|
3436
|
-
throw error;
|
|
3437
|
-
} finally{
|
|
3438
|
-
span.end();
|
|
3439
|
-
}
|
|
3440
|
-
};
|
|
3441
|
-
const handleSpanError = (span, error)=>{
|
|
3442
|
-
span.setStatus({
|
|
3443
|
-
code: __WEBPACK_EXTERNAL_MODULE__opentelemetry_api_87359e78__.SpanStatusCode.ERROR,
|
|
3444
|
-
message: error instanceof Error ? error.message : String(error)
|
|
3445
|
-
});
|
|
3446
|
-
if (error instanceof Error) {
|
|
3447
|
-
span.setAttribute('error.type', error.name);
|
|
3448
|
-
span.setAttribute('error.message', error.message);
|
|
3449
|
-
if (error.stack) span.setAttribute('error.stack', error.stack);
|
|
3450
|
-
}
|
|
3451
|
-
};
|
|
3452
|
-
const DEFAULT_IP_HEADERS = [
|
|
3453
|
-
'x-client-ip',
|
|
3454
|
-
'x-forwarded-for',
|
|
3455
|
-
'cf-connecting-ip',
|
|
3456
|
-
'fastly-client-ip',
|
|
3457
|
-
'x-real-ip',
|
|
3458
|
-
'x-cluster-client-ip',
|
|
3459
|
-
'x-forwarded',
|
|
3460
|
-
'forwarded-for',
|
|
3461
|
-
'forwarded'
|
|
3462
|
-
];
|
|
3463
|
-
function getIp(req, options) {
|
|
3464
|
-
const advanced = options.advanced || {};
|
|
3465
|
-
if (advanced?.ipAddress?.disableIpTracking) return null;
|
|
3466
|
-
const testIP = '127.0.0.1';
|
|
3467
|
-
if (isTest) return testIP;
|
|
3468
|
-
const ipHeaders = advanced?.ipAddress?.ipAddressHeaders || DEFAULT_IP_HEADERS;
|
|
3469
|
-
const headers = req instanceof Request ? req.headers : req;
|
|
3470
|
-
for (const key of ipHeaders){
|
|
3471
|
-
const value = headers.get(key);
|
|
3472
|
-
if (value) {
|
|
3473
|
-
const ip = value.split(',')[0]?.trim();
|
|
3474
|
-
if (ip) return ip;
|
|
3475
|
-
}
|
|
3476
|
-
}
|
|
3477
|
-
return null;
|
|
3478
|
-
}
|
|
3479
|
-
const c15tInstance = (options)=>{
|
|
3480
|
-
const contextPromise = init(options);
|
|
3481
|
-
const corsOptions = createCORSOptions(options.trustedOrigins);
|
|
3482
|
-
const rpcHandler = new __WEBPACK_EXTERNAL_MODULE__orpc_openapi_fetch_89b49e61__.OpenAPIHandler(router, {
|
|
3483
|
-
plugins: [
|
|
3484
|
-
new __WEBPACK_EXTERNAL_MODULE__orpc_server_plugins_e445fd4f__.CORSPlugin(corsOptions)
|
|
3485
|
-
]
|
|
3486
|
-
});
|
|
3487
|
-
const openApiConfig = createOpenAPIConfig(options);
|
|
3488
|
-
const getDocsUI = ()=>createDocsUI(options);
|
|
3489
|
-
const processIp = (request, context)=>{
|
|
3490
|
-
const ip = getIp(request, options);
|
|
3491
|
-
if (ip) context.ipAddress = ip;
|
|
3492
|
-
return context;
|
|
3493
|
-
};
|
|
3494
|
-
const processTelemetry = (request, context)=>{
|
|
3495
|
-
const url = new URL(request.url);
|
|
3496
|
-
const path = url.pathname;
|
|
3497
|
-
const method = request.method;
|
|
3498
|
-
withRequestSpan(method, path, async ()=>{}, options);
|
|
3499
|
-
context.path = path;
|
|
3500
|
-
context.method = method;
|
|
3501
|
-
context.headers = request.headers;
|
|
3502
|
-
context.userAgent = request.headers.get('user-agent') || void 0;
|
|
3503
|
-
return context;
|
|
3426
|
+
`;
|
|
3504
3427
|
};
|
|
3505
3428
|
const handleOpenApiSpecRequest = async (url)=>{
|
|
3506
3429
|
if (openApiConfig.enabled && url.pathname === openApiConfig.specPath) {
|
|
3507
|
-
const ctxResult = await contextPromise;
|
|
3508
|
-
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3509
|
-
const ctx = ctxResult.value;
|
|
3510
|
-
const orpcContext = {
|
|
3511
|
-
adapter: ctx.adapter,
|
|
3512
|
-
registry: ctx.registry,
|
|
3513
|
-
logger: ctx.logger,
|
|
3514
|
-
generateId: ctx.generateId,
|
|
3515
|
-
headers: new Headers(),
|
|
3516
|
-
appName: options.appName || 'c15t',
|
|
3517
|
-
options,
|
|
3518
|
-
trustedOrigins: options.trustedOrigins || [],
|
|
3519
|
-
baseURL: options.baseURL || '/',
|
|
3520
|
-
tables: ctx.tables
|
|
3521
|
-
};
|
|
3522
|
-
const getOpenAPISpec = createOpenAPISpec(orpcContext, options);
|
|
3523
3430
|
const spec = await getOpenAPISpec();
|
|
3524
3431
|
return new Response(JSON.stringify(spec), {
|
|
3525
3432
|
status: 200,
|
|
@@ -3585,37 +3492,17 @@ const c15tInstance = (options)=>{
|
|
|
3585
3492
|
logger: ctx.logger,
|
|
3586
3493
|
generateId: ctx.generateId,
|
|
3587
3494
|
headers: request.headers,
|
|
3588
|
-
userAgent: request.headers.get('user-agent') || void 0
|
|
3589
|
-
appName: options.appName || 'c15t',
|
|
3590
|
-
options,
|
|
3591
|
-
trustedOrigins: options.trustedOrigins || [],
|
|
3592
|
-
baseURL: options.baseURL || '/',
|
|
3593
|
-
tables: ctx.tables
|
|
3495
|
+
userAgent: request.headers.get('user-agent') || void 0
|
|
3594
3496
|
};
|
|
3595
3497
|
processIp(request, orpcContext);
|
|
3596
|
-
processCors(request, orpcContext
|
|
3498
|
+
processCors(request, orpcContext);
|
|
3597
3499
|
processTelemetry(request, orpcContext);
|
|
3598
3500
|
const handlerContext = orpcContext;
|
|
3599
|
-
orpcContext.logger.debug?.('Handling prefix', {
|
|
3600
|
-
prefix: options.basePath || '/'
|
|
3601
|
-
});
|
|
3602
3501
|
const { matched, response } = await rpcHandler.handle(request, {
|
|
3603
|
-
prefix:
|
|
3502
|
+
prefix: '/',
|
|
3604
3503
|
context: handlerContext
|
|
3605
3504
|
});
|
|
3606
|
-
if (matched && response)
|
|
3607
|
-
orpcContext.logger.debug('Handler matched', {
|
|
3608
|
-
request,
|
|
3609
|
-
matched,
|
|
3610
|
-
response
|
|
3611
|
-
});
|
|
3612
|
-
return response;
|
|
3613
|
-
}
|
|
3614
|
-
orpcContext.logger.debug('No handler matched', {
|
|
3615
|
-
request,
|
|
3616
|
-
matched,
|
|
3617
|
-
response
|
|
3618
|
-
});
|
|
3505
|
+
if (matched && response) return response;
|
|
3619
3506
|
return new Response('Not Found', {
|
|
3620
3507
|
status: 404
|
|
3621
3508
|
});
|
|
@@ -3623,10 +3510,6 @@ const c15tInstance = (options)=>{
|
|
|
3623
3510
|
const handler = async (request)=>{
|
|
3624
3511
|
try {
|
|
3625
3512
|
const url = new URL(request.url);
|
|
3626
|
-
(0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger)?.debug?.('Incoming request', {
|
|
3627
|
-
method: request.method,
|
|
3628
|
-
pathname: url.pathname
|
|
3629
|
-
});
|
|
3630
3513
|
const openApiResponse = await handleOpenApiSpecRequest(url);
|
|
3631
3514
|
if (openApiResponse) return openApiResponse;
|
|
3632
3515
|
const docsResponse = handleDocsUiRequest(url);
|
|
@@ -3634,15 +3517,6 @@ const c15tInstance = (options)=>{
|
|
|
3634
3517
|
const ctxResult = await contextPromise;
|
|
3635
3518
|
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3636
3519
|
const ctx = ctxResult.value;
|
|
3637
|
-
const basePath = options.basePath || options.baseURL || '/';
|
|
3638
|
-
(0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger)?.debug?.('[c15t] Using basePath/baseURL', {
|
|
3639
|
-
basePath
|
|
3640
|
-
});
|
|
3641
|
-
(0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger)?.debug?.('[c15t] Routing request', {
|
|
3642
|
-
method: request.method,
|
|
3643
|
-
url: request.url,
|
|
3644
|
-
prefix: basePath
|
|
3645
|
-
});
|
|
3646
3520
|
return await handleApiRequest(request, ctx);
|
|
3647
3521
|
} catch (error) {
|
|
3648
3522
|
const logger = options.logger ? (0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger) : console;
|
|
@@ -3672,25 +3546,7 @@ const c15tInstance = (options)=>{
|
|
|
3672
3546
|
router: router,
|
|
3673
3547
|
handler,
|
|
3674
3548
|
...createNextHandlers(),
|
|
3675
|
-
getOpenAPISpec
|
|
3676
|
-
const ctxResult = await contextPromise;
|
|
3677
|
-
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3678
|
-
const ctx = ctxResult.value;
|
|
3679
|
-
const orpcContext = {
|
|
3680
|
-
adapter: ctx.adapter,
|
|
3681
|
-
registry: ctx.registry,
|
|
3682
|
-
logger: ctx.logger,
|
|
3683
|
-
generateId: ctx.generateId,
|
|
3684
|
-
headers: new Headers(),
|
|
3685
|
-
appName: options.appName || 'c15t',
|
|
3686
|
-
options,
|
|
3687
|
-
trustedOrigins: options.trustedOrigins || [],
|
|
3688
|
-
baseURL: options.baseURL || '/',
|
|
3689
|
-
tables: ctx.tables
|
|
3690
|
-
};
|
|
3691
|
-
const getOpenAPISpec = createOpenAPISpec(orpcContext, options);
|
|
3692
|
-
return getOpenAPISpec();
|
|
3693
|
-
},
|
|
3549
|
+
getOpenAPISpec,
|
|
3694
3550
|
getDocsUI
|
|
3695
3551
|
};
|
|
3696
3552
|
};
|