@c15t/backend 1.2.0-canary.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +53 -52
- package/CHANGELOG.md +7 -0
- package/dist/__tests__/server.test.d.ts +2 -0
- package/dist/__tests__/server.test.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts.cjs +708 -0
- package/dist/contracts.js +661 -0
- package/dist/core.cjs +94 -47
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +94 -47
- package/dist/middleware/openapi/config.d.ts +1 -1
- package/dist/middleware/openapi/config.d.ts.map +1 -1
- package/dist/pkgs/data-model/index.cjs +57 -39
- package/dist/pkgs/data-model/index.js +57 -39
- package/dist/pkgs/data-model/schema/index.cjs +57 -39
- package/dist/pkgs/data-model/schema/index.js +57 -39
- package/dist/router.cjs +3 -1
- package/dist/router.js +3 -1
- package/dist/schema/consent-policy/registry.d.ts.map +1 -1
- package/dist/schema/create-registry.d.ts.map +1 -1
- package/dist/schema/index.cjs +57 -39
- package/dist/schema/index.js +57 -39
- package/package.json +7 -2
- package/rslib.config.ts +1 -0
- package/src/__tests__/server.test.ts +96 -0
- package/src/contracts/index.ts +2 -0
- package/src/core.ts +29 -1
- package/src/middleware/cors/cors.test.ts +0 -1
- package/src/middleware/openapi/config.ts +10 -7
- package/src/schema/consent-policy/registry.ts +74 -51
- package/.turbo/turbo-fmt.log +0 -7
- package/.turbo/turbo-test.log +0 -426
- package/coverage/coverage-final.json +0 -88
- package/coverage/coverage-summary.json +0 -89
- package/coverage/html/backend/index.html +0 -116
- package/coverage/html/backend/rslib.config.ts.html +0 -415
- package/coverage/html/backend/src/contracts/consent/index.html +0 -161
- package/coverage/html/backend/src/contracts/consent/index.ts.html +0 -112
- package/coverage/html/backend/src/contracts/consent/post.contract.ts.html +0 -550
- package/coverage/html/backend/src/contracts/consent/show-banner.contract.ts.html +0 -220
- package/coverage/html/backend/src/contracts/consent/verify.contract.ts.html +0 -463
- package/coverage/html/backend/src/contracts/index.html +0 -116
- package/coverage/html/backend/src/contracts/index.ts.html +0 -139
- package/coverage/html/backend/src/contracts/meta/index.html +0 -131
- package/coverage/html/backend/src/contracts/meta/index.ts.html +0 -100
- package/coverage/html/backend/src/contracts/meta/status.contract.ts.html +0 -196
- package/coverage/html/backend/src/contracts/shared/index.html +0 -116
- package/coverage/html/backend/src/contracts/shared/jurisdiction.schema.ts.html +0 -175
- package/coverage/html/backend/src/core.ts.html +0 -1342
- package/coverage/html/backend/src/handlers/consent/index.html +0 -161
- package/coverage/html/backend/src/handlers/consent/index.ts.html +0 -112
- package/coverage/html/backend/src/handlers/consent/post.handler.ts.html +0 -904
- package/coverage/html/backend/src/handlers/consent/show-banner.handler.ts.html +0 -532
- package/coverage/html/backend/src/handlers/consent/verify.handler.ts.html +0 -1000
- package/coverage/html/backend/src/handlers/meta/index.html +0 -131
- package/coverage/html/backend/src/handlers/meta/index.ts.html +0 -100
- package/coverage/html/backend/src/handlers/meta/status.handler.ts.html +0 -226
- package/coverage/html/backend/src/index.html +0 -161
- package/coverage/html/backend/src/init.ts.html +0 -1018
- package/coverage/html/backend/src/middleware/cors/cors.ts.html +0 -661
- package/coverage/html/backend/src/middleware/cors/index.html +0 -146
- package/coverage/html/backend/src/middleware/cors/is-origin-trusted.ts.html +0 -463
- package/coverage/html/backend/src/middleware/cors/process-cors.ts.html +0 -358
- package/coverage/html/backend/src/middleware/openapi/config.ts.html +0 -160
- package/coverage/html/backend/src/middleware/openapi/handlers.ts.html +0 -481
- package/coverage/html/backend/src/middleware/openapi/index.html +0 -131
- package/coverage/html/backend/src/pkgs/api-router/hooks/index.html +0 -116
- package/coverage/html/backend/src/pkgs/api-router/hooks/processor.ts.html +0 -544
- package/coverage/html/backend/src/pkgs/api-router/index.html +0 -116
- package/coverage/html/backend/src/pkgs/api-router/telemetry.ts.html +0 -334
- package/coverage/html/backend/src/pkgs/api-router/utils/index.html +0 -116
- package/coverage/html/backend/src/pkgs/api-router/utils/ip.ts.html +0 -361
- package/coverage/html/backend/src/pkgs/data-model/fields/field-factory.ts.html +0 -709
- package/coverage/html/backend/src/pkgs/data-model/fields/id-generator.ts.html +0 -256
- package/coverage/html/backend/src/pkgs/data-model/fields/index.html +0 -161
- package/coverage/html/backend/src/pkgs/data-model/fields/superjson-utils.ts.html +0 -136
- package/coverage/html/backend/src/pkgs/data-model/fields/zod-fields.ts.html +0 -496
- package/coverage/html/backend/src/pkgs/data-model/hooks/create-hooks.ts.html +0 -349
- package/coverage/html/backend/src/pkgs/data-model/hooks/index.html +0 -176
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-hooks.ts.html +0 -358
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-many-hooks.ts.html +0 -613
- package/coverage/html/backend/src/pkgs/data-model/hooks/utils.ts.html +0 -538
- package/coverage/html/backend/src/pkgs/data-model/hooks/with-hooks-factory.ts.html +0 -289
- package/coverage/html/backend/src/pkgs/db-adapters/adapter-factory.ts.html +0 -289
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts.html +0 -2203
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/index.html +0 -116
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/index.html +0 -116
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts.html +0 -670
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/index.html +0 -131
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts.html +0 -3634
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/index.html +0 -116
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts.html +0 -1417
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/index.html +0 -116
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts.html +0 -2071
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/index.html +0 -116
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts.html +0 -1834
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/test.ts.html +0 -316
- package/coverage/html/backend/src/pkgs/db-adapters/index.html +0 -131
- package/coverage/html/backend/src/pkgs/db-adapters/utils.ts.html +0 -238
- package/coverage/html/backend/src/pkgs/migrations/get-migration.ts.html +0 -343
- package/coverage/html/backend/src/pkgs/migrations/get-schema/get-schema.ts.html +0 -217
- package/coverage/html/backend/src/pkgs/migrations/get-schema/index.html +0 -146
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-fields.ts.html +0 -280
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-tables.ts.html +0 -289
- package/coverage/html/backend/src/pkgs/migrations/index.html +0 -176
- package/coverage/html/backend/src/pkgs/migrations/migration-builders.ts.html +0 -595
- package/coverage/html/backend/src/pkgs/migrations/migration-execution.ts.html +0 -301
- package/coverage/html/backend/src/pkgs/migrations/schema-comparison.ts.html +0 -694
- package/coverage/html/backend/src/pkgs/migrations/type-mapping.ts.html +0 -817
- package/coverage/html/backend/src/pkgs/results/core/error-class.ts.html +0 -976
- package/coverage/html/backend/src/pkgs/results/core/error-codes.ts.html +0 -703
- package/coverage/html/backend/src/pkgs/results/core/index.html +0 -146
- package/coverage/html/backend/src/pkgs/results/core/tracing.ts.html +0 -280
- package/coverage/html/backend/src/pkgs/results/create-telemetry-options.ts.html +0 -271
- package/coverage/html/backend/src/pkgs/results/index.html +0 -131
- package/coverage/html/backend/src/pkgs/results/orpc-error-handler.ts.html +0 -496
- package/coverage/html/backend/src/pkgs/results/results/index.html +0 -131
- package/coverage/html/backend/src/pkgs/results/results/recovery-utils.ts.html +0 -628
- package/coverage/html/backend/src/pkgs/results/results/result-helpers.ts.html +0 -1234
- package/coverage/html/backend/src/pkgs/utils/env.ts.html +0 -337
- package/coverage/html/backend/src/pkgs/utils/index.html +0 -146
- package/coverage/html/backend/src/pkgs/utils/logger.ts.html +0 -199
- package/coverage/html/backend/src/pkgs/utils/url.ts.html +0 -400
- package/coverage/html/backend/src/router.ts.html +0 -109
- package/coverage/html/backend/src/schema/audit-log/index.html +0 -146
- package/coverage/html/backend/src/schema/audit-log/registry.ts.html +0 -436
- package/coverage/html/backend/src/schema/audit-log/schema.ts.html +0 -223
- package/coverage/html/backend/src/schema/audit-log/table.ts.html +0 -640
- package/coverage/html/backend/src/schema/consent/index.html +0 -146
- package/coverage/html/backend/src/schema/consent/registry.ts.html +0 -616
- package/coverage/html/backend/src/schema/consent/schema.ts.html +0 -238
- package/coverage/html/backend/src/schema/consent/table.ts.html +0 -748
- package/coverage/html/backend/src/schema/consent-policy/index.html +0 -146
- package/coverage/html/backend/src/schema/consent-policy/registry.ts.html +0 -1063
- package/coverage/html/backend/src/schema/consent-policy/schema.ts.html +0 -265
- package/coverage/html/backend/src/schema/consent-policy/table.ts.html +0 -535
- package/coverage/html/backend/src/schema/consent-purpose/index.html +0 -146
- package/coverage/html/backend/src/schema/consent-purpose/registry.ts.html +0 -589
- package/coverage/html/backend/src/schema/consent-purpose/schema.ts.html +0 -259
- package/coverage/html/backend/src/schema/consent-purpose/table.ts.html +0 -547
- package/coverage/html/backend/src/schema/consent-record/index.html +0 -131
- package/coverage/html/backend/src/schema/consent-record/schema.ts.html +0 -211
- package/coverage/html/backend/src/schema/consent-record/table.ts.html +0 -457
- package/coverage/html/backend/src/schema/create-registry.ts.html +0 -148
- package/coverage/html/backend/src/schema/definition.ts.html +0 -685
- package/coverage/html/backend/src/schema/domain/index.html +0 -146
- package/coverage/html/backend/src/schema/domain/registry.ts.html +0 -973
- package/coverage/html/backend/src/schema/domain/schema.ts.html +0 -214
- package/coverage/html/backend/src/schema/domain/table.ts.html +0 -496
- package/coverage/html/backend/src/schema/index.html +0 -146
- package/coverage/html/backend/src/schema/schemas.ts.html +0 -166
- package/coverage/html/backend/src/schema/subject/index.html +0 -146
- package/coverage/html/backend/src/schema/subject/registry.ts.html +0 -973
- package/coverage/html/backend/src/schema/subject/schema.ts.html +0 -208
- package/coverage/html/backend/src/schema/subject/table.ts.html +0 -499
- package/coverage/html/backend/src/server.ts.html +0 -463
- package/coverage/html/backend/src/testing/contract-testing.ts.html +0 -1396
- package/coverage/html/backend/src/testing/index.html +0 -116
- package/coverage/html/base.css +0 -224
- package/coverage/html/block-navigation.js +0 -87
- package/coverage/html/favicon.png +0 -0
- package/coverage/html/index.html +0 -656
- package/coverage/html/prettify.css +0 -1
- package/coverage/html/prettify.js +0 -2
- package/coverage/html/sort-arrow-sprite.png +0 -0
- package/coverage/html/sorter.js +0 -196
package/dist/core.cjs
CHANGED
|
@@ -1212,10 +1212,19 @@ function consentRegistry({ adapter, ...ctx }) {
|
|
|
1212
1212
|
}
|
|
1213
1213
|
async function generatePolicyPlaceholder(name, date) {
|
|
1214
1214
|
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
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1215
|
+
let contentHash;
|
|
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
1228
|
return {
|
|
1220
1229
|
content,
|
|
1221
1230
|
contentHash
|
|
@@ -1277,42 +1286,51 @@ function policyRegistry({ adapter, ...ctx }) {
|
|
|
1277
1286
|
},
|
|
1278
1287
|
findOrCreatePolicy: async (type)=>await adapter.transaction({
|
|
1279
1288
|
callback: async (txAdapter)=>{
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1289
|
+
try {
|
|
1290
|
+
const now = new Date();
|
|
1291
|
+
const txRegistry = policyRegistry({
|
|
1292
|
+
adapter: txAdapter,
|
|
1293
|
+
...ctx
|
|
1294
|
+
});
|
|
1295
|
+
const rawLatestPolicy = await txAdapter.findOne({
|
|
1296
|
+
model: 'consentPolicy',
|
|
1297
|
+
where: [
|
|
1298
|
+
{
|
|
1299
|
+
field: 'isActive',
|
|
1300
|
+
value: true
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
field: 'type',
|
|
1304
|
+
value: type
|
|
1305
|
+
}
|
|
1306
|
+
],
|
|
1307
|
+
sortBy: {
|
|
1308
|
+
field: 'effectiveDate',
|
|
1309
|
+
direction: 'desc'
|
|
1295
1310
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1311
|
+
});
|
|
1312
|
+
const latestPolicy = rawLatestPolicy ? validateEntityOutput('consentPolicy', rawLatestPolicy, ctx.options) : null;
|
|
1313
|
+
if (latestPolicy) return latestPolicy;
|
|
1314
|
+
const { content: defaultContent, contentHash } = await generatePolicyPlaceholder(type, now);
|
|
1315
|
+
return txRegistry.createConsentPolicy({
|
|
1316
|
+
version: '1.0.0',
|
|
1317
|
+
type,
|
|
1318
|
+
name: type,
|
|
1319
|
+
effectiveDate: now,
|
|
1320
|
+
content: defaultContent,
|
|
1321
|
+
contentHash,
|
|
1322
|
+
isActive: true,
|
|
1323
|
+
updatedAt: now,
|
|
1324
|
+
expirationDate: null
|
|
1325
|
+
});
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
ctx.logger.error('Error in findOrCreatePolicy transaction:', error);
|
|
1328
|
+
throw new error_class_DoubleTieError('Failed to find or create policy', {
|
|
1329
|
+
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1330
|
+
status: 500,
|
|
1331
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1316
1334
|
}
|
|
1317
1335
|
})
|
|
1318
1336
|
};
|
|
@@ -2215,7 +2233,9 @@ function getBaseURL(url, path) {
|
|
|
2215
2233
|
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);
|
|
2216
2234
|
if (fromEnv) return withPath(fromEnv, path);
|
|
2217
2235
|
}
|
|
2218
|
-
var package_namespaceObject =
|
|
2236
|
+
var package_namespaceObject = {
|
|
2237
|
+
i8: "1.2.0"
|
|
2238
|
+
};
|
|
2219
2239
|
const createRegistry = (ctx)=>({
|
|
2220
2240
|
...auditLogRegistry(ctx),
|
|
2221
2241
|
...consentRegistry(ctx),
|
|
@@ -2494,12 +2514,15 @@ const processCors = (request, context, trustedOrigins)=>{
|
|
|
2494
2514
|
}
|
|
2495
2515
|
return context;
|
|
2496
2516
|
};
|
|
2497
|
-
const createOpenAPIConfig = (options)=>
|
|
2517
|
+
const createOpenAPIConfig = (options)=>{
|
|
2518
|
+
const basePath = options.basePath || '';
|
|
2519
|
+
return {
|
|
2498
2520
|
enabled: true,
|
|
2499
|
-
specPath:
|
|
2500
|
-
docsPath:
|
|
2521
|
+
specPath: `${basePath}/spec.json`,
|
|
2522
|
+
docsPath: `${basePath}/docs`,
|
|
2501
2523
|
...options.openapi || {}
|
|
2502
|
-
}
|
|
2524
|
+
};
|
|
2525
|
+
};
|
|
2503
2526
|
const createDefaultOpenAPIOptions = (options)=>({
|
|
2504
2527
|
info: {
|
|
2505
2528
|
title: options.appName || 'c15t API',
|
|
@@ -2508,7 +2531,7 @@ const createDefaultOpenAPIOptions = (options)=>({
|
|
|
2508
2531
|
},
|
|
2509
2532
|
servers: [
|
|
2510
2533
|
{
|
|
2511
|
-
url: '/'
|
|
2534
|
+
url: options.basePath || '/'
|
|
2512
2535
|
}
|
|
2513
2536
|
],
|
|
2514
2537
|
security: [
|
|
@@ -3614,11 +3637,26 @@ const c15tInstance = (options)=>{
|
|
|
3614
3637
|
processCors(request, orpcContext, options.trustedOrigins);
|
|
3615
3638
|
processTelemetry(request, orpcContext);
|
|
3616
3639
|
const handlerContext = orpcContext;
|
|
3640
|
+
orpcContext.logger.debug?.('Handling prefix', {
|
|
3641
|
+
prefix: options.basePath || '/'
|
|
3642
|
+
});
|
|
3617
3643
|
const { matched, response } = await rpcHandler.handle(request, {
|
|
3618
|
-
prefix: options.
|
|
3644
|
+
prefix: options.basePath || '/',
|
|
3619
3645
|
context: handlerContext
|
|
3620
3646
|
});
|
|
3621
|
-
if (matched && response)
|
|
3647
|
+
if (matched && response) {
|
|
3648
|
+
orpcContext.logger.debug('Handler matched', {
|
|
3649
|
+
request,
|
|
3650
|
+
matched,
|
|
3651
|
+
response
|
|
3652
|
+
});
|
|
3653
|
+
return response;
|
|
3654
|
+
}
|
|
3655
|
+
orpcContext.logger.debug('No handler matched', {
|
|
3656
|
+
request,
|
|
3657
|
+
matched,
|
|
3658
|
+
response
|
|
3659
|
+
});
|
|
3622
3660
|
return new Response('Not Found', {
|
|
3623
3661
|
status: 404
|
|
3624
3662
|
});
|
|
@@ -3637,6 +3675,15 @@ const c15tInstance = (options)=>{
|
|
|
3637
3675
|
const ctxResult = await contextPromise;
|
|
3638
3676
|
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3639
3677
|
const ctx = ctxResult.value;
|
|
3678
|
+
const basePath = options.basePath || options.baseURL || '/';
|
|
3679
|
+
(0, logger_namespaceObject.createLogger)(options.logger)?.debug?.('[c15t] Using basePath/baseURL', {
|
|
3680
|
+
basePath
|
|
3681
|
+
});
|
|
3682
|
+
(0, logger_namespaceObject.createLogger)(options.logger)?.debug?.('[c15t] Routing request', {
|
|
3683
|
+
method: request.method,
|
|
3684
|
+
url: request.url,
|
|
3685
|
+
prefix: basePath
|
|
3686
|
+
});
|
|
3640
3687
|
return await handleApiRequest(request, ctx);
|
|
3641
3688
|
} catch (error) {
|
|
3642
3689
|
const logger = options.logger ? (0, logger_namespaceObject.createLogger)(options.logger) : console;
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAUpE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,YAAY,CAAC,WAAW,SAAS,UAAU,EAAE,GAAG,UAAU,EAAE;IAC5E;;;;;;;;;;;;;;;OAeG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEjD;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAElC;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAE/B;;OAEG;IACH,MAAM,EAAE,OAAO,MAAM,CAAC;IAEtB;;;;OAIG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvD;;;;OAIG;IACH,SAAS,EAAE,MAAM,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,WAAW,SAAS,UAAU,EAAE,GAAG,UAAU,EAAE,EAC3E,SAAS,WAAW,CAAC,WAAW,CAAC;;;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAUpE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,YAAY,CAAC,WAAW,SAAS,UAAU,EAAE,GAAG,UAAU,EAAE;IAC5E;;;;;;;;;;;;;;;OAeG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEjD;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAElC;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAE/B;;OAEG;IACH,MAAM,EAAE,OAAO,MAAM,CAAC;IAEtB;;;;OAIG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvD;;;;OAIG;IACH,SAAS,EAAE,MAAM,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,WAAW,SAAS,UAAU,EAAE,GAAG,UAAU,EAAE,EAC3E,SAAS,WAAW,CAAC,WAAW,CAAC;;;mBA6RI,OAAO;oBAAP,OAAO;mBAAP,OAAO;qBAAP,OAAO;sBAAP,OAAO;uBAAP,OAAO;oBAAP,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA1DZ,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;CAsH3D,CAAC;AAEF,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/core.js
CHANGED
|
@@ -1178,10 +1178,19 @@ function consentRegistry({ adapter, ...ctx }) {
|
|
|
1178
1178
|
}
|
|
1179
1179
|
async function generatePolicyPlaceholder(name, date) {
|
|
1180
1180
|
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
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1181
|
+
let contentHash;
|
|
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
|
+
}
|
|
1185
1194
|
return {
|
|
1186
1195
|
content,
|
|
1187
1196
|
contentHash
|
|
@@ -1243,42 +1252,51 @@ function policyRegistry({ adapter, ...ctx }) {
|
|
|
1243
1252
|
},
|
|
1244
1253
|
findOrCreatePolicy: async (type)=>await adapter.transaction({
|
|
1245
1254
|
callback: async (txAdapter)=>{
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1255
|
+
try {
|
|
1256
|
+
const now = new Date();
|
|
1257
|
+
const txRegistry = policyRegistry({
|
|
1258
|
+
adapter: txAdapter,
|
|
1259
|
+
...ctx
|
|
1260
|
+
});
|
|
1261
|
+
const rawLatestPolicy = await txAdapter.findOne({
|
|
1262
|
+
model: 'consentPolicy',
|
|
1263
|
+
where: [
|
|
1264
|
+
{
|
|
1265
|
+
field: 'isActive',
|
|
1266
|
+
value: true
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
field: 'type',
|
|
1270
|
+
value: type
|
|
1271
|
+
}
|
|
1272
|
+
],
|
|
1273
|
+
sortBy: {
|
|
1274
|
+
field: 'effectiveDate',
|
|
1275
|
+
direction: 'desc'
|
|
1261
1276
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1277
|
+
});
|
|
1278
|
+
const latestPolicy = rawLatestPolicy ? validateEntityOutput('consentPolicy', rawLatestPolicy, ctx.options) : null;
|
|
1279
|
+
if (latestPolicy) return latestPolicy;
|
|
1280
|
+
const { content: defaultContent, contentHash } = await generatePolicyPlaceholder(type, now);
|
|
1281
|
+
return txRegistry.createConsentPolicy({
|
|
1282
|
+
version: '1.0.0',
|
|
1283
|
+
type,
|
|
1284
|
+
name: type,
|
|
1285
|
+
effectiveDate: now,
|
|
1286
|
+
content: defaultContent,
|
|
1287
|
+
contentHash,
|
|
1288
|
+
isActive: true,
|
|
1289
|
+
updatedAt: now,
|
|
1290
|
+
expirationDate: null
|
|
1291
|
+
});
|
|
1292
|
+
} catch (error) {
|
|
1293
|
+
ctx.logger.error('Error in findOrCreatePolicy transaction:', error);
|
|
1294
|
+
throw new error_class_DoubleTieError('Failed to find or create policy', {
|
|
1295
|
+
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1296
|
+
status: 500,
|
|
1297
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1282
1300
|
}
|
|
1283
1301
|
})
|
|
1284
1302
|
};
|
|
@@ -2179,7 +2197,9 @@ function getBaseURL(url, path) {
|
|
|
2179
2197
|
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);
|
|
2180
2198
|
if (fromEnv) return withPath(fromEnv, path);
|
|
2181
2199
|
}
|
|
2182
|
-
var package_namespaceObject =
|
|
2200
|
+
var package_namespaceObject = {
|
|
2201
|
+
i8: "1.2.0"
|
|
2202
|
+
};
|
|
2183
2203
|
const createRegistry = (ctx)=>({
|
|
2184
2204
|
...auditLogRegistry(ctx),
|
|
2185
2205
|
...consentRegistry(ctx),
|
|
@@ -2458,12 +2478,15 @@ const processCors = (request, context, trustedOrigins)=>{
|
|
|
2458
2478
|
}
|
|
2459
2479
|
return context;
|
|
2460
2480
|
};
|
|
2461
|
-
const createOpenAPIConfig = (options)=>
|
|
2481
|
+
const createOpenAPIConfig = (options)=>{
|
|
2482
|
+
const basePath = options.basePath || '';
|
|
2483
|
+
return {
|
|
2462
2484
|
enabled: true,
|
|
2463
|
-
specPath:
|
|
2464
|
-
docsPath:
|
|
2485
|
+
specPath: `${basePath}/spec.json`,
|
|
2486
|
+
docsPath: `${basePath}/docs`,
|
|
2465
2487
|
...options.openapi || {}
|
|
2466
|
-
}
|
|
2488
|
+
};
|
|
2489
|
+
};
|
|
2467
2490
|
const createDefaultOpenAPIOptions = (options)=>({
|
|
2468
2491
|
info: {
|
|
2469
2492
|
title: options.appName || 'c15t API',
|
|
@@ -2472,7 +2495,7 @@ const createDefaultOpenAPIOptions = (options)=>({
|
|
|
2472
2495
|
},
|
|
2473
2496
|
servers: [
|
|
2474
2497
|
{
|
|
2475
|
-
url: '/'
|
|
2498
|
+
url: options.basePath || '/'
|
|
2476
2499
|
}
|
|
2477
2500
|
],
|
|
2478
2501
|
security: [
|
|
@@ -3575,11 +3598,26 @@ const c15tInstance = (options)=>{
|
|
|
3575
3598
|
processCors(request, orpcContext, options.trustedOrigins);
|
|
3576
3599
|
processTelemetry(request, orpcContext);
|
|
3577
3600
|
const handlerContext = orpcContext;
|
|
3601
|
+
orpcContext.logger.debug?.('Handling prefix', {
|
|
3602
|
+
prefix: options.basePath || '/'
|
|
3603
|
+
});
|
|
3578
3604
|
const { matched, response } = await rpcHandler.handle(request, {
|
|
3579
|
-
prefix: options.
|
|
3605
|
+
prefix: options.basePath || '/',
|
|
3580
3606
|
context: handlerContext
|
|
3581
3607
|
});
|
|
3582
|
-
if (matched && response)
|
|
3608
|
+
if (matched && response) {
|
|
3609
|
+
orpcContext.logger.debug('Handler matched', {
|
|
3610
|
+
request,
|
|
3611
|
+
matched,
|
|
3612
|
+
response
|
|
3613
|
+
});
|
|
3614
|
+
return response;
|
|
3615
|
+
}
|
|
3616
|
+
orpcContext.logger.debug('No handler matched', {
|
|
3617
|
+
request,
|
|
3618
|
+
matched,
|
|
3619
|
+
response
|
|
3620
|
+
});
|
|
3583
3621
|
return new Response('Not Found', {
|
|
3584
3622
|
status: 404
|
|
3585
3623
|
});
|
|
@@ -3598,6 +3636,15 @@ const c15tInstance = (options)=>{
|
|
|
3598
3636
|
const ctxResult = await contextPromise;
|
|
3599
3637
|
if (!ctxResult.isOk()) throw ctxResult.error;
|
|
3600
3638
|
const ctx = ctxResult.value;
|
|
3639
|
+
const basePath = options.basePath || options.baseURL || '/';
|
|
3640
|
+
(0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger)?.debug?.('[c15t] Using basePath/baseURL', {
|
|
3641
|
+
basePath
|
|
3642
|
+
});
|
|
3643
|
+
(0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger)?.debug?.('[c15t] Routing request', {
|
|
3644
|
+
method: request.method,
|
|
3645
|
+
url: request.url,
|
|
3646
|
+
prefix: basePath
|
|
3647
|
+
});
|
|
3601
3648
|
return await handleApiRequest(request, ctx);
|
|
3602
3649
|
} catch (error) {
|
|
3603
3650
|
const logger = options.logger ? (0, __WEBPACK_EXTERNAL_MODULE__doubletie_logger_91c58a8f__.createLogger)(options.logger) : console;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/middleware/openapi/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,WAAW;;;;;;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/middleware/openapi/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,WAAW;;;;;;CAQvD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,WAAW;;;;;;;;;;;;CAQ9D,CAAC"}
|
|
@@ -1289,10 +1289,19 @@ function consentRegistry({ adapter, ...ctx }) {
|
|
|
1289
1289
|
}
|
|
1290
1290
|
async function generatePolicyPlaceholder(name, date) {
|
|
1291
1291
|
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()}`;
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1292
|
+
let contentHash;
|
|
1293
|
+
try {
|
|
1294
|
+
const encoder = new TextEncoder();
|
|
1295
|
+
const data = encoder.encode(content);
|
|
1296
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
1297
|
+
contentHash = Array.from(new Uint8Array(hashBuffer)).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
throw new error_class_DoubleTieError('Failed to generate policy content hash', {
|
|
1300
|
+
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1301
|
+
status: 500,
|
|
1302
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1296
1305
|
return {
|
|
1297
1306
|
content,
|
|
1298
1307
|
contentHash
|
|
@@ -1354,42 +1363,51 @@ function policyRegistry({ adapter, ...ctx }) {
|
|
|
1354
1363
|
},
|
|
1355
1364
|
findOrCreatePolicy: async (type)=>await adapter.transaction({
|
|
1356
1365
|
callback: async (txAdapter)=>{
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1366
|
+
try {
|
|
1367
|
+
const now = new Date();
|
|
1368
|
+
const txRegistry = policyRegistry({
|
|
1369
|
+
adapter: txAdapter,
|
|
1370
|
+
...ctx
|
|
1371
|
+
});
|
|
1372
|
+
const rawLatestPolicy = await txAdapter.findOne({
|
|
1373
|
+
model: 'consentPolicy',
|
|
1374
|
+
where: [
|
|
1375
|
+
{
|
|
1376
|
+
field: 'isActive',
|
|
1377
|
+
value: true
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
field: 'type',
|
|
1381
|
+
value: type
|
|
1382
|
+
}
|
|
1383
|
+
],
|
|
1384
|
+
sortBy: {
|
|
1385
|
+
field: 'effectiveDate',
|
|
1386
|
+
direction: 'desc'
|
|
1372
1387
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1388
|
+
});
|
|
1389
|
+
const latestPolicy = rawLatestPolicy ? validateEntityOutput('consentPolicy', rawLatestPolicy, ctx.options) : null;
|
|
1390
|
+
if (latestPolicy) return latestPolicy;
|
|
1391
|
+
const { content: defaultContent, contentHash } = await generatePolicyPlaceholder(type, now);
|
|
1392
|
+
return txRegistry.createConsentPolicy({
|
|
1393
|
+
version: '1.0.0',
|
|
1394
|
+
type,
|
|
1395
|
+
name: type,
|
|
1396
|
+
effectiveDate: now,
|
|
1397
|
+
content: defaultContent,
|
|
1398
|
+
contentHash,
|
|
1399
|
+
isActive: true,
|
|
1400
|
+
updatedAt: now,
|
|
1401
|
+
expirationDate: null
|
|
1402
|
+
});
|
|
1403
|
+
} catch (error) {
|
|
1404
|
+
ctx.logger.error('Error in findOrCreatePolicy transaction:', error);
|
|
1405
|
+
throw new error_class_DoubleTieError('Failed to find or create policy', {
|
|
1406
|
+
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1407
|
+
status: 500,
|
|
1408
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1393
1411
|
}
|
|
1394
1412
|
})
|
|
1395
1413
|
};
|
|
@@ -1221,10 +1221,19 @@ function consentRegistry({ adapter, ...ctx }) {
|
|
|
1221
1221
|
}
|
|
1222
1222
|
async function generatePolicyPlaceholder(name, date) {
|
|
1223
1223
|
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()}`;
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1224
|
+
let contentHash;
|
|
1225
|
+
try {
|
|
1226
|
+
const encoder = new TextEncoder();
|
|
1227
|
+
const data = encoder.encode(content);
|
|
1228
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
1229
|
+
contentHash = Array.from(new Uint8Array(hashBuffer)).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
throw new error_class_DoubleTieError('Failed to generate policy content hash', {
|
|
1232
|
+
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1233
|
+
status: 500,
|
|
1234
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1228
1237
|
return {
|
|
1229
1238
|
content,
|
|
1230
1239
|
contentHash
|
|
@@ -1286,42 +1295,51 @@ function policyRegistry({ adapter, ...ctx }) {
|
|
|
1286
1295
|
},
|
|
1287
1296
|
findOrCreatePolicy: async (type)=>await adapter.transaction({
|
|
1288
1297
|
callback: async (txAdapter)=>{
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1298
|
+
try {
|
|
1299
|
+
const now = new Date();
|
|
1300
|
+
const txRegistry = policyRegistry({
|
|
1301
|
+
adapter: txAdapter,
|
|
1302
|
+
...ctx
|
|
1303
|
+
});
|
|
1304
|
+
const rawLatestPolicy = await txAdapter.findOne({
|
|
1305
|
+
model: 'consentPolicy',
|
|
1306
|
+
where: [
|
|
1307
|
+
{
|
|
1308
|
+
field: 'isActive',
|
|
1309
|
+
value: true
|
|
1310
|
+
},
|
|
1311
|
+
{
|
|
1312
|
+
field: 'type',
|
|
1313
|
+
value: type
|
|
1314
|
+
}
|
|
1315
|
+
],
|
|
1316
|
+
sortBy: {
|
|
1317
|
+
field: 'effectiveDate',
|
|
1318
|
+
direction: 'desc'
|
|
1304
1319
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1320
|
+
});
|
|
1321
|
+
const latestPolicy = rawLatestPolicy ? validateEntityOutput('consentPolicy', rawLatestPolicy, ctx.options) : null;
|
|
1322
|
+
if (latestPolicy) return latestPolicy;
|
|
1323
|
+
const { content: defaultContent, contentHash } = await generatePolicyPlaceholder(type, now);
|
|
1324
|
+
return txRegistry.createConsentPolicy({
|
|
1325
|
+
version: '1.0.0',
|
|
1326
|
+
type,
|
|
1327
|
+
name: type,
|
|
1328
|
+
effectiveDate: now,
|
|
1329
|
+
content: defaultContent,
|
|
1330
|
+
contentHash,
|
|
1331
|
+
isActive: true,
|
|
1332
|
+
updatedAt: now,
|
|
1333
|
+
expirationDate: null
|
|
1334
|
+
});
|
|
1335
|
+
} catch (error) {
|
|
1336
|
+
ctx.logger.error('Error in findOrCreatePolicy transaction:', error);
|
|
1337
|
+
throw new error_class_DoubleTieError('Failed to find or create policy', {
|
|
1338
|
+
code: error_codes_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
1339
|
+
status: 500,
|
|
1340
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1325
1343
|
}
|
|
1326
1344
|
})
|
|
1327
1345
|
};
|