@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.cjs
CHANGED
|
@@ -36,8 +36,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
36
|
c15tInstance: ()=>c15tInstance
|
|
37
37
|
});
|
|
38
38
|
const logger_namespaceObject = require("@doubletie/logger");
|
|
39
|
+
const openapi_namespaceObject = require("@orpc/openapi");
|
|
39
40
|
const fetch_namespaceObject = require("@orpc/openapi/fetch");
|
|
40
41
|
const plugins_namespaceObject = require("@orpc/server/plugins");
|
|
42
|
+
const zod_namespaceObject = require("@orpc/zod");
|
|
41
43
|
const external_neverthrow_namespaceObject = require("neverthrow");
|
|
42
44
|
const server_namespaceObject = require("@orpc/server");
|
|
43
45
|
const error_codes_ERROR_CODES = Object.freeze({
|
|
@@ -285,6 +287,7 @@ function createTelemetryOptions(appName = 'c15t', telemetryConfig) {
|
|
|
285
287
|
};
|
|
286
288
|
return config;
|
|
287
289
|
}
|
|
290
|
+
var package_namespaceObject = JSON.parse('{"i8":"1.2.0-canary.2"}');
|
|
288
291
|
const resources_namespaceObject = require("@opentelemetry/resources");
|
|
289
292
|
const sdk_node_namespaceObject = require("@opentelemetry/sdk-node");
|
|
290
293
|
const sdk_trace_base_namespaceObject = require("@opentelemetry/sdk-trace-base");
|
|
@@ -1210,21 +1213,10 @@ function consentRegistry({ adapter, ...ctx }) {
|
|
|
1210
1213
|
};
|
|
1211
1214
|
return registry;
|
|
1212
1215
|
}
|
|
1213
|
-
|
|
1216
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
1217
|
+
function generatePolicyPlaceholder(name, date) {
|
|
1214
1218
|
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()}`;
|
|
1215
|
-
|
|
1216
|
-
try {
|
|
1217
|
-
const encoder = new TextEncoder();
|
|
1218
|
-
const data = encoder.encode(content);
|
|
1219
|
-
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
1220
|
-
contentHash = Array.from(new Uint8Array(hashBuffer)).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
1221
|
-
} catch (error) {
|
|
1222
|
-
throw new error_class_DoubleTieError('Failed to generate policy content hash', {
|
|
1223
|
-
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1224
|
-
status: 500,
|
|
1225
|
-
cause: error instanceof Error ? error : new Error(String(error))
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1219
|
+
const contentHash = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(content).digest('hex');
|
|
1228
1220
|
return {
|
|
1229
1221
|
content,
|
|
1230
1222
|
contentHash
|
|
@@ -1284,53 +1276,44 @@ function policyRegistry({ adapter, ...ctx }) {
|
|
|
1284
1276
|
});
|
|
1285
1277
|
return policy ? validateEntityOutput('consentPolicy', policy, ctx.options) : null;
|
|
1286
1278
|
},
|
|
1287
|
-
findOrCreatePolicy: async (type)=>
|
|
1279
|
+
findOrCreatePolicy: async (type)=>adapter.transaction({
|
|
1288
1280
|
callback: async (txAdapter)=>{
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
value: type
|
|
1305
|
-
}
|
|
1306
|
-
],
|
|
1307
|
-
sortBy: {
|
|
1308
|
-
field: 'effectiveDate',
|
|
1309
|
-
direction: 'desc'
|
|
1281
|
+
const now = new Date();
|
|
1282
|
+
const txRegistry = policyRegistry({
|
|
1283
|
+
adapter: txAdapter,
|
|
1284
|
+
...ctx
|
|
1285
|
+
});
|
|
1286
|
+
const rawLatestPolicy = await txAdapter.findOne({
|
|
1287
|
+
model: 'consentPolicy',
|
|
1288
|
+
where: [
|
|
1289
|
+
{
|
|
1290
|
+
field: 'isActive',
|
|
1291
|
+
value: true
|
|
1292
|
+
},
|
|
1293
|
+
{
|
|
1294
|
+
field: 'type',
|
|
1295
|
+
value: type
|
|
1310
1296
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
cause: error instanceof Error ? error : new Error(String(error))
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1297
|
+
],
|
|
1298
|
+
sortBy: {
|
|
1299
|
+
field: 'effectiveDate',
|
|
1300
|
+
direction: 'desc'
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
const latestPolicy = rawLatestPolicy ? validateEntityOutput('consentPolicy', rawLatestPolicy, ctx.options) : null;
|
|
1304
|
+
if (latestPolicy) return latestPolicy;
|
|
1305
|
+
const { content: defaultContent, contentHash } = generatePolicyPlaceholder(type, now);
|
|
1306
|
+
return txRegistry.createConsentPolicy({
|
|
1307
|
+
version: '1.0.0',
|
|
1308
|
+
type,
|
|
1309
|
+
name: type,
|
|
1310
|
+
effectiveDate: now,
|
|
1311
|
+
content: defaultContent,
|
|
1312
|
+
contentHash,
|
|
1313
|
+
isActive: true,
|
|
1314
|
+
updatedAt: now,
|
|
1315
|
+
expirationDate: null
|
|
1316
|
+
});
|
|
1334
1317
|
}
|
|
1335
1318
|
})
|
|
1336
1319
|
};
|
|
@@ -2233,7 +2216,6 @@ function getBaseURL(url, path) {
|
|
|
2233
2216
|
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);
|
|
2234
2217
|
if (fromEnv) return withPath(fromEnv, path);
|
|
2235
2218
|
}
|
|
2236
|
-
var package_namespaceObject = JSON.parse('{"i8":"1.2.0-canary.13"}');
|
|
2237
2219
|
const createRegistry = (ctx)=>({
|
|
2238
2220
|
...auditLogRegistry(ctx),
|
|
2239
2221
|
...consentRegistry(ctx),
|
|
@@ -2385,86 +2367,51 @@ function getInternalPlugins(_options) {
|
|
|
2385
2367
|
const plugins = [];
|
|
2386
2368
|
return plugins;
|
|
2387
2369
|
}
|
|
2388
|
-
const
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
'POST',
|
|
2393
|
-
'PUT',
|
|
2394
|
-
'DELETE',
|
|
2395
|
-
'PATCH',
|
|
2396
|
-
'OPTIONS'
|
|
2397
|
-
];
|
|
2398
|
-
const SUPPORTED_HEADERS = [
|
|
2399
|
-
'Content-Type',
|
|
2400
|
-
'Authorization',
|
|
2401
|
-
'x-request-id'
|
|
2402
|
-
];
|
|
2403
|
-
const DEFAULT_CORS_CONFIG = {
|
|
2404
|
-
origin: async (origin)=>await Promise.resolve(origin || '*'),
|
|
2405
|
-
credentials: true,
|
|
2406
|
-
allowHeaders: SUPPORTED_HEADERS,
|
|
2407
|
-
maxAge: 600,
|
|
2408
|
-
methods: SUPPORTED_METHODS
|
|
2370
|
+
const API_ROUTER_TRACER_NAME = '@doubletie/api-router';
|
|
2371
|
+
const getTracer = (options)=>{
|
|
2372
|
+
if (options?.telemetry?.tracer) return options.telemetry.tracer;
|
|
2373
|
+
return api_namespaceObject.trace.getTracer(API_ROUTER_TRACER_NAME);
|
|
2409
2374
|
};
|
|
2410
|
-
|
|
2411
|
-
if (
|
|
2412
|
-
const
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
if (!origin.includes('://') && !origin.includes(':') && !origin.includes('/')) return origin.toLowerCase();
|
|
2419
|
-
const originWithProtocol = origin.startsWith('http://') || origin.startsWith('https://') || origin.startsWith('ws://') || origin.startsWith('wss://') ? origin : `http://${origin}`;
|
|
2420
|
-
const url = new URL(originWithProtocol);
|
|
2421
|
-
const hostname = url.hostname.replace(WWW_REGEX, '');
|
|
2422
|
-
return `${hostname}${url.port ? `:${url.port}` : ''}`;
|
|
2423
|
-
} catch {
|
|
2424
|
-
return origin.replace(PROTOCOL_WWW_REGEX, '').replace(WWW_REGEX, '');
|
|
2375
|
+
const createRequestSpan = (method, path, options)=>{
|
|
2376
|
+
if (options?.telemetry?.disabled) return null;
|
|
2377
|
+
const tracer = getTracer(options);
|
|
2378
|
+
const span = tracer.startSpan(`${method} ${path}`, {
|
|
2379
|
+
attributes: {
|
|
2380
|
+
'http.method': method,
|
|
2381
|
+
'http.path': path,
|
|
2382
|
+
...options?.telemetry?.defaultAttributes || {}
|
|
2425
2383
|
}
|
|
2384
|
+
});
|
|
2385
|
+
return span;
|
|
2386
|
+
};
|
|
2387
|
+
const withRequestSpan = async (method, path, operation, options)=>{
|
|
2388
|
+
const span = createRequestSpan(method, path, options);
|
|
2389
|
+
if (!span) return operation();
|
|
2390
|
+
try {
|
|
2391
|
+
const result = await operation();
|
|
2392
|
+
span.setStatus({
|
|
2393
|
+
code: api_namespaceObject.SpanStatusCode.OK
|
|
2394
|
+
});
|
|
2395
|
+
return result;
|
|
2396
|
+
} catch (error) {
|
|
2397
|
+
handleSpanError(span, error);
|
|
2398
|
+
throw error;
|
|
2399
|
+
} finally{
|
|
2400
|
+
span.end();
|
|
2426
2401
|
}
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
}
|
|
2438
|
-
return Array.from(expanded);
|
|
2402
|
+
};
|
|
2403
|
+
const handleSpanError = (span, error)=>{
|
|
2404
|
+
span.setStatus({
|
|
2405
|
+
code: api_namespaceObject.SpanStatusCode.ERROR,
|
|
2406
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2407
|
+
});
|
|
2408
|
+
if (error instanceof Error) {
|
|
2409
|
+
span.setAttribute('error.type', error.name);
|
|
2410
|
+
span.setAttribute('error.message', error.message);
|
|
2411
|
+
if (error.stack) span.setAttribute('error.stack', error.stack);
|
|
2439
2412
|
}
|
|
2440
|
-
|
|
2441
|
-
const returnConfig = {
|
|
2442
|
-
origin: async (origin)=>{
|
|
2443
|
-
if (!origin) return '*';
|
|
2444
|
-
const normalizedOrigin = normalizeOrigin(origin);
|
|
2445
|
-
if (expandedTrusted.includes('*')) return origin;
|
|
2446
|
-
const isTrusted = expandedTrusted.some((trusted)=>{
|
|
2447
|
-
const normalizedTrusted = normalizeOrigin(trusted);
|
|
2448
|
-
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]:');
|
|
2449
|
-
return normalizedTrusted === normalizedOrigin;
|
|
2450
|
-
});
|
|
2451
|
-
return isTrusted ? origin : null;
|
|
2452
|
-
},
|
|
2453
|
-
credentials: true,
|
|
2454
|
-
allowHeaders: SUPPORTED_HEADERS,
|
|
2455
|
-
maxAge: 600,
|
|
2456
|
-
methods: SUPPORTED_METHODS
|
|
2457
|
-
};
|
|
2458
|
-
return returnConfig;
|
|
2459
|
-
}
|
|
2413
|
+
};
|
|
2460
2414
|
const STRIP_REGEX = /^(https?:\/\/)|(wss?:\/\/)|(\/+$)|:\d+/g;
|
|
2461
|
-
function matchesWildcard(hostname, wildcardPattern, logger) {
|
|
2462
|
-
const wildcardDomain = wildcardPattern.slice(2);
|
|
2463
|
-
const parts = hostname.split('.');
|
|
2464
|
-
const isValid = parts.length > 2 && hostname.endsWith(wildcardDomain);
|
|
2465
|
-
logger?.debug(`Wildcard match result: ${isValid} ${hostname} ends with ${wildcardDomain} ${parts.length > 2} ${hostname.endsWith(wildcardDomain)}`);
|
|
2466
|
-
return isValid;
|
|
2467
|
-
}
|
|
2468
2415
|
function isOriginTrusted(origin, trustedDomains, logger) {
|
|
2469
2416
|
try {
|
|
2470
2417
|
if (0 === trustedDomains.length) throw new Error('No trusted domains');
|
|
@@ -2483,7 +2430,13 @@ function isOriginTrusted(origin, trustedDomains, logger) {
|
|
|
2483
2430
|
}
|
|
2484
2431
|
const strippedDomain = domain.replace(STRIP_REGEX, '').toLowerCase();
|
|
2485
2432
|
logger?.debug(`Checking against stripped domain: ${strippedDomain}`);
|
|
2486
|
-
if (strippedDomain.startsWith('*.'))
|
|
2433
|
+
if (strippedDomain.startsWith('*.')) {
|
|
2434
|
+
const wildcardDomain = strippedDomain.slice(2);
|
|
2435
|
+
const parts = originHostname.split('.');
|
|
2436
|
+
const isValid = parts.length > 2 && originHostname.endsWith(wildcardDomain);
|
|
2437
|
+
logger?.debug(`Wildcard match result: ${isValid} ${originHostname} ends with ${wildcardDomain} ${parts.length > 2} ${originHostname.endsWith(wildcardDomain)}`);
|
|
2438
|
+
return isValid;
|
|
2439
|
+
}
|
|
2487
2440
|
const isMatch = originHostname === strippedDomain;
|
|
2488
2441
|
logger?.debug(`Exact match result: ${isMatch} ${originHostname} === ${strippedDomain}`);
|
|
2489
2442
|
return isMatch;
|
|
@@ -2493,58 +2446,38 @@ function isOriginTrusted(origin, trustedDomains, logger) {
|
|
|
2493
2446
|
return false;
|
|
2494
2447
|
}
|
|
2495
2448
|
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
const
|
|
2509
|
-
if (
|
|
2510
|
-
|
|
2511
|
-
|
|
2449
|
+
const DEFAULT_IP_HEADERS = [
|
|
2450
|
+
'x-client-ip',
|
|
2451
|
+
'x-forwarded-for',
|
|
2452
|
+
'cf-connecting-ip',
|
|
2453
|
+
'fastly-client-ip',
|
|
2454
|
+
'x-real-ip',
|
|
2455
|
+
'x-cluster-client-ip',
|
|
2456
|
+
'x-forwarded',
|
|
2457
|
+
'forwarded-for',
|
|
2458
|
+
'forwarded'
|
|
2459
|
+
];
|
|
2460
|
+
function getIp(req, options) {
|
|
2461
|
+
const advanced = options.advanced || {};
|
|
2462
|
+
if (advanced?.ipAddress?.disableIpTracking) return null;
|
|
2463
|
+
const testIP = '127.0.0.1';
|
|
2464
|
+
if (isTest) return testIP;
|
|
2465
|
+
const ipHeaders = advanced?.ipAddress?.ipAddressHeaders || DEFAULT_IP_HEADERS;
|
|
2466
|
+
const headers = req instanceof Request ? req.headers : req;
|
|
2467
|
+
for (const key of ipHeaders){
|
|
2468
|
+
const value = headers.get(key);
|
|
2469
|
+
if (value) {
|
|
2470
|
+
const ip = value.split(',')[0]?.trim();
|
|
2471
|
+
if (ip) return ip;
|
|
2472
|
+
}
|
|
2512
2473
|
}
|
|
2513
|
-
return
|
|
2514
|
-
}
|
|
2515
|
-
const createOpenAPIConfig = (options)=>{
|
|
2516
|
-
const basePath = options.basePath || '';
|
|
2517
|
-
return {
|
|
2518
|
-
enabled: true,
|
|
2519
|
-
specPath: `${basePath}/spec.json`,
|
|
2520
|
-
docsPath: `${basePath}/docs`,
|
|
2521
|
-
...options.openapi || {}
|
|
2522
|
-
};
|
|
2523
|
-
};
|
|
2524
|
-
const createDefaultOpenAPIOptions = (options)=>({
|
|
2525
|
-
info: {
|
|
2526
|
-
title: options.appName || 'c15t API',
|
|
2527
|
-
version: package_namespaceObject.i8,
|
|
2528
|
-
description: 'API for consent management'
|
|
2529
|
-
},
|
|
2530
|
-
servers: [
|
|
2531
|
-
{
|
|
2532
|
-
url: options.basePath || '/'
|
|
2533
|
-
}
|
|
2534
|
-
],
|
|
2535
|
-
security: [
|
|
2536
|
-
{
|
|
2537
|
-
bearerAuth: []
|
|
2538
|
-
}
|
|
2539
|
-
]
|
|
2540
|
-
});
|
|
2541
|
-
const openapi_namespaceObject = require("@orpc/openapi");
|
|
2542
|
-
const zod_namespaceObject = require("@orpc/zod");
|
|
2474
|
+
return null;
|
|
2475
|
+
}
|
|
2543
2476
|
const contract_namespaceObject = require("@orpc/contract");
|
|
2544
2477
|
const baseConsentSchema = external_zod_namespaceObject.z.object({
|
|
2545
2478
|
subjectId: external_zod_namespaceObject.z.string().optional(),
|
|
2546
2479
|
externalSubjectId: external_zod_namespaceObject.z.string().optional(),
|
|
2547
|
-
domain: external_zod_namespaceObject.z.string(),
|
|
2480
|
+
domain: external_zod_namespaceObject.z.string().regex(/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/i, 'invalid domain'),
|
|
2548
2481
|
type: PolicyTypeSchema,
|
|
2549
2482
|
metadata: external_zod_namespaceObject.z.record(external_zod_namespaceObject.z.unknown()).optional()
|
|
2550
2483
|
});
|
|
@@ -3134,7 +3067,7 @@ function checkJurisdiction(countryCode) {
|
|
|
3134
3067
|
'KR'
|
|
3135
3068
|
])
|
|
3136
3069
|
};
|
|
3137
|
-
|
|
3070
|
+
let showConsentBanner = false;
|
|
3138
3071
|
let jurisdictionCode = 'NONE';
|
|
3139
3072
|
if (countryCode) {
|
|
3140
3073
|
const jurisdictionMap = [
|
|
@@ -3184,6 +3117,7 @@ function checkJurisdiction(countryCode) {
|
|
|
3184
3117
|
}
|
|
3185
3118
|
];
|
|
3186
3119
|
for (const { sets, code } of jurisdictionMap)if (sets.some((set)=>set.has(countryCode))) {
|
|
3120
|
+
showConsentBanner = true;
|
|
3187
3121
|
jurisdictionCode = code;
|
|
3188
3122
|
break;
|
|
3189
3123
|
}
|
|
@@ -3383,182 +3317,155 @@ const router = os.router({
|
|
|
3383
3317
|
consent: consentHandlers,
|
|
3384
3318
|
meta: metaHandlers
|
|
3385
3319
|
});
|
|
3386
|
-
const
|
|
3387
|
-
const
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3320
|
+
const c15tInstance = (options)=>{
|
|
3321
|
+
const contextPromise = init(options);
|
|
3322
|
+
const corsOptions = options.trustedOrigins ? {
|
|
3323
|
+
origin: options.trustedOrigins.includes('*') ? (origin)=>origin : options.trustedOrigins,
|
|
3324
|
+
credentials: true,
|
|
3325
|
+
methods: [
|
|
3326
|
+
'GET',
|
|
3327
|
+
'POST',
|
|
3328
|
+
'PUT',
|
|
3329
|
+
'DELETE',
|
|
3330
|
+
'OPTIONS',
|
|
3331
|
+
'PATCH'
|
|
3332
|
+
],
|
|
3333
|
+
allowedHeaders: [
|
|
3334
|
+
'Content-Type',
|
|
3335
|
+
'Authorization',
|
|
3336
|
+
'X-Request-ID'
|
|
3337
|
+
],
|
|
3338
|
+
maxAge: 86400
|
|
3339
|
+
} : {
|
|
3340
|
+
origin: '*',
|
|
3341
|
+
credentials: false,
|
|
3342
|
+
methods: [
|
|
3343
|
+
'GET',
|
|
3344
|
+
'POST',
|
|
3345
|
+
'PUT',
|
|
3346
|
+
'DELETE',
|
|
3347
|
+
'OPTIONS',
|
|
3348
|
+
'PATCH'
|
|
3349
|
+
],
|
|
3350
|
+
allowedHeaders: [
|
|
3351
|
+
'Content-Type',
|
|
3352
|
+
'Authorization',
|
|
3353
|
+
'X-Request-ID'
|
|
3354
|
+
],
|
|
3355
|
+
maxAge: 86400
|
|
3393
3356
|
};
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3357
|
+
const rpcHandler = new fetch_namespaceObject.OpenAPIHandler(router, {
|
|
3358
|
+
plugins: [
|
|
3359
|
+
new plugins_namespaceObject.CORSPlugin({
|
|
3360
|
+
...corsOptions,
|
|
3361
|
+
origin: (origin)=>{
|
|
3362
|
+
if (!origin) return null;
|
|
3363
|
+
if (options.trustedOrigins?.includes('*')) return origin;
|
|
3364
|
+
if (options.trustedOrigins?.includes(origin)) return origin;
|
|
3365
|
+
return null;
|
|
3366
|
+
},
|
|
3367
|
+
credentials: true,
|
|
3368
|
+
exposeHeaders: [
|
|
3369
|
+
'Content-Type',
|
|
3370
|
+
'Authorization',
|
|
3371
|
+
'X-Request-ID'
|
|
3372
|
+
]
|
|
3373
|
+
})
|
|
3374
|
+
]
|
|
3375
|
+
});
|
|
3398
3376
|
const openAPIGenerator = new openapi_namespaceObject.OpenAPIGenerator({
|
|
3399
3377
|
schemaConverters: [
|
|
3400
3378
|
new zod_namespaceObject.ZodToJsonSchemaConverter()
|
|
3401
3379
|
]
|
|
3402
3380
|
});
|
|
3381
|
+
const openApiConfig = {
|
|
3382
|
+
enabled: true,
|
|
3383
|
+
specPath: '/spec.json',
|
|
3384
|
+
docsPath: '/docs',
|
|
3385
|
+
...options.openapi || {}
|
|
3386
|
+
};
|
|
3387
|
+
const defaultOpenApiOptions = {
|
|
3388
|
+
info: {
|
|
3389
|
+
title: options.appName || 'c15t API',
|
|
3390
|
+
version: package_namespaceObject.i8,
|
|
3391
|
+
description: 'API for consent management'
|
|
3392
|
+
},
|
|
3393
|
+
servers: [
|
|
3394
|
+
{
|
|
3395
|
+
url: '/'
|
|
3396
|
+
}
|
|
3397
|
+
],
|
|
3398
|
+
security: [
|
|
3399
|
+
{
|
|
3400
|
+
bearerAuth: []
|
|
3401
|
+
}
|
|
3402
|
+
]
|
|
3403
|
+
};
|
|
3404
|
+
const processIp = (request, context)=>{
|
|
3405
|
+
const ip = getIp(request, options);
|
|
3406
|
+
if (ip) context.ipAddress = ip;
|
|
3407
|
+
return context;
|
|
3408
|
+
};
|
|
3409
|
+
const processCors = (request, context)=>{
|
|
3410
|
+
const origin = request.headers.get('origin');
|
|
3411
|
+
if (origin && options.trustedOrigins) {
|
|
3412
|
+
const trusted = isOriginTrusted(origin, options.trustedOrigins, context.logger);
|
|
3413
|
+
context.origin = origin;
|
|
3414
|
+
context.trustedOrigin = trusted;
|
|
3415
|
+
}
|
|
3416
|
+
return context;
|
|
3417
|
+
};
|
|
3418
|
+
const processTelemetry = (request, context)=>{
|
|
3419
|
+
const url = new URL(request.url);
|
|
3420
|
+
const path = url.pathname;
|
|
3421
|
+
const method = request.method;
|
|
3422
|
+
withRequestSpan(method, path, async ()=>{}, options);
|
|
3423
|
+
context.path = path;
|
|
3424
|
+
context.method = method;
|
|
3425
|
+
context.headers = request.headers;
|
|
3426
|
+
context.userAgent = request.headers.get('user-agent') || void 0;
|
|
3427
|
+
return context;
|
|
3428
|
+
};
|
|
3403
3429
|
const getOpenAPISpec = async ()=>{
|
|
3404
3430
|
if (getOpenAPISpec.cached) return getOpenAPISpec.cached;
|
|
3405
|
-
const
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
return {
|
|
3414
|
-
openapi: '3.0.0',
|
|
3415
|
-
info: {
|
|
3416
|
-
title: options.appName || 'c15t API',
|
|
3417
|
-
version: '0.0.0'
|
|
3418
|
-
},
|
|
3419
|
-
paths: {}
|
|
3431
|
+
const mergedOptions = {
|
|
3432
|
+
...defaultOpenApiOptions
|
|
3433
|
+
};
|
|
3434
|
+
if (openApiConfig.options) {
|
|
3435
|
+
const userOptions = openApiConfig.options;
|
|
3436
|
+
if (userOptions.info) mergedOptions.info = {
|
|
3437
|
+
...defaultOpenApiOptions.info,
|
|
3438
|
+
...userOptions.info
|
|
3420
3439
|
};
|
|
3440
|
+
for (const [key, value] of Object.entries(userOptions))if ('info' !== key) mergedOptions[key] = value;
|
|
3421
3441
|
}
|
|
3442
|
+
const spec = await openAPIGenerator.generate(router, mergedOptions);
|
|
3443
|
+
getOpenAPISpec.cached = spec;
|
|
3444
|
+
return spec;
|
|
3422
3445
|
};
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
const config = createOpenAPIConfig(options);
|
|
3427
|
-
if (config.customUiTemplate) return config.customUiTemplate;
|
|
3428
|
-
return `
|
|
3446
|
+
const getDocsUI = ()=>{
|
|
3447
|
+
if (openApiConfig.customUiTemplate) return openApiConfig.customUiTemplate;
|
|
3448
|
+
return `
|
|
3429
3449
|
<!doctype html>
|
|
3430
3450
|
<html>
|
|
3431
3451
|
<head>
|
|
3432
3452
|
<title>${options.appName || 'c15t API'} Documentation</title>
|
|
3433
3453
|
<meta charset="utf-8" />
|
|
3434
3454
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
3435
|
-
<link rel="icon" type="image/svg+xml" href="https://
|
|
3455
|
+
<link rel="icon" type="image/svg+xml" href="https://orpc.unnoq.com/icon.svg" />
|
|
3436
3456
|
</head>
|
|
3437
3457
|
<body>
|
|
3438
3458
|
<script
|
|
3439
3459
|
id="api-reference"
|
|
3440
|
-
data-url="${encodeURI(
|
|
3460
|
+
data-url="${encodeURI(openApiConfig.specPath)}">
|
|
3441
3461
|
</script>
|
|
3442
3462
|
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
3443
3463
|
</body>
|
|
3444
3464
|
</html>
|
|
3445
|
-
|
|
3446
|
-
};
|
|
3447
|
-
const API_ROUTER_TRACER_NAME = '@doubletie/api-router';
|
|
3448
|
-
const getTracer = (options)=>{
|
|
3449
|
-
if (options?.telemetry?.tracer) return options.telemetry.tracer;
|
|
3450
|
-
return api_namespaceObject.trace.getTracer(API_ROUTER_TRACER_NAME);
|
|
3451
|
-
};
|
|
3452
|
-
const createRequestSpan = (method, path, options)=>{
|
|
3453
|
-
if (options?.telemetry?.disabled) return null;
|
|
3454
|
-
const tracer = getTracer(options);
|
|
3455
|
-
const span = tracer.startSpan(`${method} ${path}`, {
|
|
3456
|
-
attributes: {
|
|
3457
|
-
'http.method': method,
|
|
3458
|
-
'http.path': path,
|
|
3459
|
-
...options?.telemetry?.defaultAttributes || {}
|
|
3460
|
-
}
|
|
3461
|
-
});
|
|
3462
|
-
return span;
|
|
3463
|
-
};
|
|
3464
|
-
const withRequestSpan = async (method, path, operation, options)=>{
|
|
3465
|
-
const span = createRequestSpan(method, path, options);
|
|
3466
|
-
if (!span) return operation();
|
|
3467
|
-
try {
|
|
3468
|
-
const result = await operation();
|
|
3469
|
-
span.setStatus({
|
|
3470
|
-
code: api_namespaceObject.SpanStatusCode.OK
|
|
3471
|
-
});
|
|
3472
|
-
return result;
|
|
3473
|
-
} catch (error) {
|
|
3474
|
-
handleSpanError(span, error);
|
|
3475
|
-
throw error;
|
|
3476
|
-
} finally{
|
|
3477
|
-
span.end();
|
|
3478
|
-
}
|
|
3479
|
-
};
|
|
3480
|
-
const handleSpanError = (span, error)=>{
|
|
3481
|
-
span.setStatus({
|
|
3482
|
-
code: api_namespaceObject.SpanStatusCode.ERROR,
|
|
3483
|
-
message: error instanceof Error ? error.message : String(error)
|
|
3484
|
-
});
|
|
3485
|
-
if (error instanceof Error) {
|
|
3486
|
-
span.setAttribute('error.type', error.name);
|
|
3487
|
-
span.setAttribute('error.message', error.message);
|
|
3488
|
-
if (error.stack) span.setAttribute('error.stack', error.stack);
|
|
3489
|
-
}
|
|
3490
|
-
};
|
|
3491
|
-
const DEFAULT_IP_HEADERS = [
|
|
3492
|
-
'x-client-ip',
|
|
3493
|
-
'x-forwarded-for',
|
|
3494
|
-
'cf-connecting-ip',
|
|
3495
|
-
'fastly-client-ip',
|
|
3496
|
-
'x-real-ip',
|
|
3497
|
-
'x-cluster-client-ip',
|
|
3498
|
-
'x-forwarded',
|
|
3499
|
-
'forwarded-for',
|
|
3500
|
-
'forwarded'
|
|
3501
|
-
];
|
|
3502
|
-
function getIp(req, options) {
|
|
3503
|
-
const advanced = options.advanced || {};
|
|
3504
|
-
if (advanced?.ipAddress?.disableIpTracking) return null;
|
|
3505
|
-
const testIP = '127.0.0.1';
|
|
3506
|
-
if (isTest) return testIP;
|
|
3507
|
-
const ipHeaders = advanced?.ipAddress?.ipAddressHeaders || DEFAULT_IP_HEADERS;
|
|
3508
|
-
const headers = req instanceof Request ? req.headers : req;
|
|
3509
|
-
for (const key of ipHeaders){
|
|
3510
|
-
const value = headers.get(key);
|
|
3511
|
-
if (value) {
|
|
3512
|
-
const ip = value.split(',')[0]?.trim();
|
|
3513
|
-
if (ip) return ip;
|
|
3514
|
-
}
|
|
3515
|
-
}
|
|
3516
|
-
return null;
|
|
3517
|
-
}
|
|
3518
|
-
const c15tInstance = (options)=>{
|
|
3519
|
-
const contextPromise = init(options);
|
|
3520
|
-
const corsOptions = createCORSOptions(options.trustedOrigins);
|
|
3521
|
-
const rpcHandler = new fetch_namespaceObject.OpenAPIHandler(router, {
|
|
3522
|
-
plugins: [
|
|
3523
|
-
new plugins_namespaceObject.CORSPlugin(corsOptions)
|
|
3524
|
-
]
|
|
3525
|
-
});
|
|
3526
|
-
const openApiConfig = createOpenAPIConfig(options);
|
|
3527
|
-
const getDocsUI = ()=>createDocsUI(options);
|
|
3528
|
-
const processIp = (request, context)=>{
|
|
3529
|
-
const ip = getIp(request, options);
|
|
3530
|
-
if (ip) context.ipAddress = ip;
|
|
3531
|
-
return context;
|
|
3532
|
-
};
|
|
3533
|
-
const processTelemetry = (request, context)=>{
|
|
3534
|
-
const url = new URL(request.url);
|
|
3535
|
-
const path = url.pathname;
|
|
3536
|
-
const method = request.method;
|
|
3537
|
-
withRequestSpan(method, path, async ()=>{}, options);
|
|
3538
|
-
context.path = path;
|
|
3539
|
-
context.method = method;
|
|
3540
|
-
context.headers = request.headers;
|
|
3541
|
-
context.userAgent = request.headers.get('user-agent') || void 0;
|
|
3542
|
-
return context;
|
|
3465
|
+
`;
|
|
3543
3466
|
};
|
|
3544
3467
|
const handleOpenApiSpecRequest = async (url)=>{
|
|
3545
3468
|
if (openApiConfig.enabled && url.pathname === openApiConfig.specPath) {
|
|
3546
|
-
const ctxResult = await contextPromise;
|
|
3547
|
-
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3548
|
-
const ctx = ctxResult.value;
|
|
3549
|
-
const orpcContext = {
|
|
3550
|
-
adapter: ctx.adapter,
|
|
3551
|
-
registry: ctx.registry,
|
|
3552
|
-
logger: ctx.logger,
|
|
3553
|
-
generateId: ctx.generateId,
|
|
3554
|
-
headers: new Headers(),
|
|
3555
|
-
appName: options.appName || 'c15t',
|
|
3556
|
-
options,
|
|
3557
|
-
trustedOrigins: options.trustedOrigins || [],
|
|
3558
|
-
baseURL: options.baseURL || '/',
|
|
3559
|
-
tables: ctx.tables
|
|
3560
|
-
};
|
|
3561
|
-
const getOpenAPISpec = createOpenAPISpec(orpcContext, options);
|
|
3562
3469
|
const spec = await getOpenAPISpec();
|
|
3563
3470
|
return new Response(JSON.stringify(spec), {
|
|
3564
3471
|
status: 200,
|
|
@@ -3624,37 +3531,17 @@ const c15tInstance = (options)=>{
|
|
|
3624
3531
|
logger: ctx.logger,
|
|
3625
3532
|
generateId: ctx.generateId,
|
|
3626
3533
|
headers: request.headers,
|
|
3627
|
-
userAgent: request.headers.get('user-agent') || void 0
|
|
3628
|
-
appName: options.appName || 'c15t',
|
|
3629
|
-
options,
|
|
3630
|
-
trustedOrigins: options.trustedOrigins || [],
|
|
3631
|
-
baseURL: options.baseURL || '/',
|
|
3632
|
-
tables: ctx.tables
|
|
3534
|
+
userAgent: request.headers.get('user-agent') || void 0
|
|
3633
3535
|
};
|
|
3634
3536
|
processIp(request, orpcContext);
|
|
3635
|
-
processCors(request, orpcContext
|
|
3537
|
+
processCors(request, orpcContext);
|
|
3636
3538
|
processTelemetry(request, orpcContext);
|
|
3637
3539
|
const handlerContext = orpcContext;
|
|
3638
|
-
orpcContext.logger.debug?.('Handling prefix', {
|
|
3639
|
-
prefix: options.basePath || '/'
|
|
3640
|
-
});
|
|
3641
3540
|
const { matched, response } = await rpcHandler.handle(request, {
|
|
3642
|
-
prefix:
|
|
3541
|
+
prefix: '/',
|
|
3643
3542
|
context: handlerContext
|
|
3644
3543
|
});
|
|
3645
|
-
if (matched && response)
|
|
3646
|
-
orpcContext.logger.debug('Handler matched', {
|
|
3647
|
-
request,
|
|
3648
|
-
matched,
|
|
3649
|
-
response
|
|
3650
|
-
});
|
|
3651
|
-
return response;
|
|
3652
|
-
}
|
|
3653
|
-
orpcContext.logger.debug('No handler matched', {
|
|
3654
|
-
request,
|
|
3655
|
-
matched,
|
|
3656
|
-
response
|
|
3657
|
-
});
|
|
3544
|
+
if (matched && response) return response;
|
|
3658
3545
|
return new Response('Not Found', {
|
|
3659
3546
|
status: 404
|
|
3660
3547
|
});
|
|
@@ -3662,10 +3549,6 @@ const c15tInstance = (options)=>{
|
|
|
3662
3549
|
const handler = async (request)=>{
|
|
3663
3550
|
try {
|
|
3664
3551
|
const url = new URL(request.url);
|
|
3665
|
-
(0, logger_namespaceObject.createLogger)(options.logger)?.debug?.('Incoming request', {
|
|
3666
|
-
method: request.method,
|
|
3667
|
-
pathname: url.pathname
|
|
3668
|
-
});
|
|
3669
3552
|
const openApiResponse = await handleOpenApiSpecRequest(url);
|
|
3670
3553
|
if (openApiResponse) return openApiResponse;
|
|
3671
3554
|
const docsResponse = handleDocsUiRequest(url);
|
|
@@ -3673,15 +3556,6 @@ const c15tInstance = (options)=>{
|
|
|
3673
3556
|
const ctxResult = await contextPromise;
|
|
3674
3557
|
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3675
3558
|
const ctx = ctxResult.value;
|
|
3676
|
-
const basePath = options.basePath || options.baseURL || '/';
|
|
3677
|
-
(0, logger_namespaceObject.createLogger)(options.logger)?.debug?.('[c15t] Using basePath/baseURL', {
|
|
3678
|
-
basePath
|
|
3679
|
-
});
|
|
3680
|
-
(0, logger_namespaceObject.createLogger)(options.logger)?.debug?.('[c15t] Routing request', {
|
|
3681
|
-
method: request.method,
|
|
3682
|
-
url: request.url,
|
|
3683
|
-
prefix: basePath
|
|
3684
|
-
});
|
|
3685
3559
|
return await handleApiRequest(request, ctx);
|
|
3686
3560
|
} catch (error) {
|
|
3687
3561
|
const logger = options.logger ? (0, logger_namespaceObject.createLogger)(options.logger) : console;
|
|
@@ -3711,25 +3585,7 @@ const c15tInstance = (options)=>{
|
|
|
3711
3585
|
router: router,
|
|
3712
3586
|
handler,
|
|
3713
3587
|
...createNextHandlers(),
|
|
3714
|
-
getOpenAPISpec
|
|
3715
|
-
const ctxResult = await contextPromise;
|
|
3716
|
-
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3717
|
-
const ctx = ctxResult.value;
|
|
3718
|
-
const orpcContext = {
|
|
3719
|
-
adapter: ctx.adapter,
|
|
3720
|
-
registry: ctx.registry,
|
|
3721
|
-
logger: ctx.logger,
|
|
3722
|
-
generateId: ctx.generateId,
|
|
3723
|
-
headers: new Headers(),
|
|
3724
|
-
appName: options.appName || 'c15t',
|
|
3725
|
-
options,
|
|
3726
|
-
trustedOrigins: options.trustedOrigins || [],
|
|
3727
|
-
baseURL: options.baseURL || '/',
|
|
3728
|
-
tables: ctx.tables
|
|
3729
|
-
};
|
|
3730
|
-
const getOpenAPISpec = createOpenAPISpec(orpcContext, options);
|
|
3731
|
-
return getOpenAPISpec();
|
|
3732
|
-
},
|
|
3588
|
+
getOpenAPISpec,
|
|
3733
3589
|
getDocsUI
|
|
3734
3590
|
};
|
|
3735
3591
|
};
|