@friggframework/core 2.0.0--canary.680.6bacd26.0 → 2.0.0--canary.663.8de669c.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +0 -11
  2. package/application/commands/integration-commands.js +8 -18
  3. package/application/index.js +2 -6
  4. package/credential/repositories/credential-repository-documentdb.js +0 -34
  5. package/credential/repositories/credential-repository-interface.js +0 -15
  6. package/credential/repositories/credential-repository-mongo.js +0 -23
  7. package/credential/repositories/credential-repository-postgres.js +0 -28
  8. package/database/encryption/README.md +0 -2
  9. package/database/encryption/encryption-schema-registry.js +12 -41
  10. package/database/encryption/field-encryption-service.js +5 -69
  11. package/generated/prisma-mongodb/edge.js +4 -20
  12. package/generated/prisma-mongodb/index-browser.js +1 -17
  13. package/generated/prisma-mongodb/index.d.ts +95 -1543
  14. package/generated/prisma-mongodb/index.js +4 -20
  15. package/generated/prisma-mongodb/package.json +1 -1
  16. package/generated/prisma-mongodb/schema.prisma +0 -27
  17. package/generated/prisma-mongodb/wasm.js +4 -20
  18. package/generated/prisma-postgresql/edge.js +4 -20
  19. package/generated/prisma-postgresql/index-browser.js +1 -17
  20. package/generated/prisma-postgresql/index.d.ts +84 -1565
  21. package/generated/prisma-postgresql/index.js +4 -20
  22. package/generated/prisma-postgresql/package.json +1 -1
  23. package/generated/prisma-postgresql/schema.prisma +0 -26
  24. package/generated/prisma-postgresql/wasm.js +4 -20
  25. package/handlers/app-definition-loader.js +8 -19
  26. package/handlers/app-handler-helpers.js +3 -25
  27. package/handlers/backend-utils.js +25 -31
  28. package/handlers/middleware/admin-auth.js +1 -14
  29. package/handlers/routers/auth.js +3 -11
  30. package/handlers/routers/health.js +4 -11
  31. package/handlers/workers/integration-defined-workers.js +2 -5
  32. package/index.js +2 -4
  33. package/integrations/index.js +4 -0
  34. package/integrations/integration-router.js +23 -16
  35. package/integrations/utils/map-integration-dto.js +15 -1
  36. package/modules/index.js +0 -6
  37. package/modules/requester/requester.js +2 -27
  38. package/package.json +5 -5
  39. package/prisma-mongodb/schema.prisma +0 -27
  40. package/prisma-postgresql/schema.prisma +0 -26
  41. package/types/index.d.ts +0 -1
  42. package/credential/use-cases/credential-operations-for-user.js +0 -117
  43. package/credential/use-cases/reauthorize-credential-for-user.js +0 -66
  44. package/database/encryption/test-support/fake-ciphertext.js +0 -15
  45. package/integrations/use-cases/integration-operations-for-user.js +0 -225
  46. package/management-api/create-management-api-router.js +0 -49
  47. package/management-api/error-response.js +0 -116
  48. package/management-api/management-api-config.js +0 -82
  49. package/management-api/meta-router.js +0 -57
  50. package/management-api/openapi/build-openapi.js +0 -144
  51. package/management-api/openapi/components.js +0 -368
  52. package/management-api/openapi/v1-operations.js +0 -83
  53. package/management-api/openapi/v2-operations.js +0 -252
  54. package/management-api/route-registry.js +0 -294
  55. package/management-api/test-support/http-client.js +0 -39
  56. package/management-api/use-cases/get-management-api-meta.js +0 -57
  57. package/management-api/v1-deprecation.js +0 -120
  58. package/management-api/v2/create-v2-router.js +0 -85
  59. package/management-api/v2/dependencies.js +0 -256
  60. package/management-api/v2/dto.js +0 -123
  61. package/management-api/v2/handlers/authorization.js +0 -93
  62. package/management-api/v2/handlers/credentials.js +0 -29
  63. package/management-api/v2/handlers/entities.js +0 -74
  64. package/management-api/v2/handlers/integrations.js +0 -125
  65. package/management-api/v2/handlers/proxy.js +0 -34
  66. package/management-api/v2/request.js +0 -54
  67. package/management-api/v2/test-support/fake-dependencies.js +0 -103
  68. package/modules/domain/authorization-session.js +0 -144
  69. package/modules/entity-type-registry.js +0 -311
  70. package/modules/proxy/proxy-errors.js +0 -20
  71. package/modules/proxy/proxy-path.js +0 -179
  72. package/modules/proxy/proxy-policy.js +0 -248
  73. package/modules/repositories/authorization-session-repository-documentdb.js +0 -112
  74. package/modules/repositories/authorization-session-repository-factory.js +0 -31
  75. package/modules/repositories/authorization-session-repository-interface.js +0 -47
  76. package/modules/repositories/authorization-session-repository-prisma.js +0 -87
  77. package/modules/requester/proxy-request.js +0 -244
  78. package/modules/tests/doubles/in-memory-authorization-session-repository.js +0 -45
  79. package/modules/use-cases/entity-operations-for-user.js +0 -125
  80. package/modules/use-cases/entity-types.js +0 -115
  81. package/modules/use-cases/execute-entity-proxy-request.js +0 -239
  82. package/modules/use-cases/get-authorization-requirements.js +0 -100
  83. package/modules/use-cases/get-entity-module-for-user.js +0 -86
  84. package/modules/use-cases/multi-step-authorization.js +0 -302
  85. package/prisma-postgresql/migrations/20261003000000_add_authorization_session/migration.sql +0 -28
  86. package/types/modules/index.d.ts +0 -58
@@ -1,248 +0,0 @@
1
- const { ProxyRequestError } = require('./proxy-errors');
2
-
3
- /**
4
- * What the entity proxy accepts and returns (ADR-052 §5-§7). Pure functions:
5
- * no I/O, so every rule is unit-tested on its own.
6
- */
7
-
8
- const PROXY_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
9
- const METHODS_WITH_BODY = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
10
-
11
- /** Request headers a caller may always send (lower case). */
12
- const ALLOWED_REQUEST_HEADERS = [
13
- 'accept',
14
- 'content-type',
15
- 'accept-language',
16
- 'if-match',
17
- 'if-none-match',
18
- ];
19
-
20
- /** Request headers that are refused outright, even if a module lists them. */
21
- const REJECTED_REQUEST_HEADERS = [
22
- 'authorization',
23
- 'proxy-authorization',
24
- 'cookie',
25
- 'host',
26
- 'forwarded',
27
- 'x-real-ip',
28
- 'x-api-key',
29
- ];
30
- const REJECTED_REQUEST_HEADER_PREFIXES = ['x-forwarded-'];
31
-
32
- /** Response headers never passed back (credentials and hop-by-hop). */
33
- const REMOVED_RESPONSE_HEADERS = [
34
- 'authorization',
35
- 'proxy-authorization',
36
- 'proxy-authenticate',
37
- 'set-cookie',
38
- 'set-cookie2',
39
- 'www-authenticate',
40
- 'x-api-key',
41
- 'connection',
42
- 'keep-alive',
43
- 'te',
44
- 'trailer',
45
- 'transfer-encoding',
46
- 'upgrade',
47
- // The body is re-encoded as JSON, so these no longer describe it.
48
- 'content-length',
49
- 'content-encoding',
50
- ];
51
-
52
- const invalid = (message, details) =>
53
- new ProxyRequestError('INVALID_PROXY_REQUEST', message, details);
54
-
55
- const isPlainObject = (value) =>
56
- value !== null && typeof value === 'object' && !Array.isArray(value);
57
-
58
- /**
59
- * Validates the request body of POST /api/v2/entities/:id/proxy and returns
60
- * it with the method upper-cased and the body serialised.
61
- *
62
- * @param {unknown} request
63
- * @param {{ maxRequestBytes: number }} limits
64
- * @returns {{ method: string, path: string, query?: Object, headers: Object, body?: string, requestBytes: number, bodyIsJson: boolean }}
65
- */
66
- function validateProxyRequest(request, { maxRequestBytes }) {
67
- if (!isPlainObject(request)) throw invalid('The proxy request must be a JSON object');
68
- const method = typeof request.method === 'string' ? request.method.toUpperCase() : '';
69
- if (!PROXY_METHODS.includes(method)) {
70
- throw invalid(`method must be one of ${PROXY_METHODS.join(', ')}`, { field: 'method' });
71
- }
72
- if (typeof request.path !== 'string') {
73
- throw invalid('path is required', { field: 'path' });
74
- }
75
-
76
- let query;
77
- if (request.query !== undefined && request.query !== null) {
78
- if (!isPlainObject(request.query)) throw invalid('query must be an object', { field: 'query' });
79
- query = {};
80
- for (const [key, value] of Object.entries(request.query)) {
81
- const scalar = ['string', 'number', 'boolean'].includes(typeof value);
82
- const list = Array.isArray(value) && value.every((v) => typeof v === 'string');
83
- if (!scalar && !list) {
84
- throw invalid(`query.${key} must be a string, number, boolean or array of strings`, {
85
- field: `query.${key}`,
86
- });
87
- }
88
- // The requester sends one value per key; arrays go comma-separated.
89
- query[key] = list ? value.join(',') : value;
90
- }
91
- }
92
-
93
- const headers = {};
94
- if (request.headers !== undefined && request.headers !== null) {
95
- if (!isPlainObject(request.headers)) throw invalid('headers must be an object', { field: 'headers' });
96
- for (const [name, value] of Object.entries(request.headers)) {
97
- if (typeof value !== 'string') {
98
- throw invalid(`header ${name} must be a string`, { field: `headers.${name}` });
99
- }
100
- headers[name.toLowerCase()] = value;
101
- }
102
- }
103
-
104
- let body;
105
- let bodyIsJson = false;
106
- if (request.body !== undefined && request.body !== null) {
107
- if (!METHODS_WITH_BODY.has(method)) {
108
- throw invalid(`${method} requests cannot have a body`, { field: 'body' });
109
- }
110
- if (typeof request.body === 'string') {
111
- body = request.body;
112
- } else {
113
- body = JSON.stringify(request.body);
114
- bodyIsJson = true;
115
- }
116
- }
117
- const requestBytes = body === undefined ? 0 : Buffer.byteLength(body);
118
- if (requestBytes > maxRequestBytes) {
119
- throw new ProxyRequestError(
120
- 'PAYLOAD_TOO_LARGE',
121
- `The proxied request body is larger than ${maxRequestBytes} bytes`
122
- );
123
- }
124
- return { method, path: request.path, query, headers, body, bodyIsJson, requestBytes };
125
- }
126
-
127
- const isWildcardRule = (rule) => rule?.method === '*' || rule?.path === '/**';
128
-
129
- const isValidRule = (rule) =>
130
- isPlainObject(rule) &&
131
- typeof rule.method === 'string' &&
132
- typeof rule.path === 'string' &&
133
- rule.path.startsWith('/');
134
-
135
- /**
136
- * The allow-list in force for a module: the app definition's list for it when
137
- * one is given (`managementApi.proxy.modules[name].allow`), otherwise the
138
- * module's own `proxy.allow`. A module cannot grant itself a wildcard; only
139
- * the app definition can. No list means nothing may be proxied.
140
- *
141
- * @returns {{ rules: Array<{method: string, path: string}>, source: 'app'|'module'|'none', ignored: number }}
142
- */
143
- function resolveAllowRules(definition, moduleOverrides = {}) {
144
- const override = moduleOverrides?.[definition.moduleName]?.allow;
145
- if (Array.isArray(override)) {
146
- return { rules: override.filter(isValidRule), source: 'app', ignored: 0 };
147
- }
148
- const declared = Array.isArray(definition.proxy?.allow) ? definition.proxy.allow : [];
149
- const rules = declared.filter((rule) => isValidRule(rule) && !isWildcardRule(rule));
150
- return {
151
- rules,
152
- source: rules.length ? 'module' : 'none',
153
- ignored: declared.length - rules.length,
154
- };
155
- }
156
-
157
- /**
158
- * Keeps only the request headers the caller may set. A header from the
159
- * rejected list (credentials, Host, forwarding headers, or one the module's
160
- * own auth sets) fails the request instead of being dropped quietly.
161
- *
162
- * @param {Object} headers - lower-cased names
163
- * @param {Object} options
164
- * @param {string[]} [options.moduleHeaders] - from the module's `proxy.headers`
165
- * @param {string[]} [options.authHeaderNames] - headers the module's auth sets
166
- */
167
- function filterRequestHeaders(headers, { moduleHeaders = [], authHeaderNames = [] } = {}) {
168
- const rejected = new Set([
169
- ...REJECTED_REQUEST_HEADERS,
170
- ...authHeaderNames.filter(Boolean).map((name) => String(name).toLowerCase()),
171
- ]);
172
- const allowed = new Set([
173
- ...ALLOWED_REQUEST_HEADERS,
174
- ...moduleHeaders.map((name) => String(name).toLowerCase()),
175
- ]);
176
- const kept = {};
177
- for (const [name, value] of Object.entries(headers)) {
178
- if (
179
- rejected.has(name) ||
180
- REJECTED_REQUEST_HEADER_PREFIXES.some((prefix) => name.startsWith(prefix))
181
- ) {
182
- throw invalid(`The ${name} header cannot be sent through the proxy`, {
183
- field: `headers.${name}`,
184
- });
185
- }
186
- if (allowed.has(name)) kept[name] = value;
187
- }
188
- return kept;
189
- }
190
-
191
- /**
192
- * Removes credential and hop-by-hop headers from an upstream response, and
193
- * the Location of a redirect the proxy refused to follow.
194
- */
195
- function filterResponseHeaders(headers, { redirectBlocked = false, authHeaderNames = [] } = {}) {
196
- const removed = new Set([
197
- ...REMOVED_RESPONSE_HEADERS,
198
- ...authHeaderNames.filter(Boolean).map((name) => String(name).toLowerCase()),
199
- ]);
200
- if (redirectBlocked) removed.add('location');
201
- const kept = {};
202
- for (const [name, value] of Object.entries(headers || {})) {
203
- if (!removed.has(name.toLowerCase())) kept[name.toLowerCase()] = value;
204
- }
205
- return kept;
206
- }
207
-
208
- const JSON_TYPE = /^application\/([a-z0-9.+-]*\+)?json\b/i;
209
- const TEXT_TYPE = /^(text\/|application\/(xml|x-www-form-urlencoded|javascript|graphql)\b|[a-z]+\/[a-z0-9.+-]*\+xml\b)/i;
210
-
211
- /**
212
- * Turns the upstream body into the `data` of the proxy response: parsed JSON,
213
- * text, or (only if the module allows binary) base64.
214
- *
215
- * @returns {{ data: unknown, encoding?: 'base64' }}
216
- */
217
- function decodeResponseBody(body, contentType, { binary = false } = {}) {
218
- if (!body || body.length === 0) return { data: null };
219
- if (JSON_TYPE.test(contentType)) {
220
- const text = body.toString('utf8');
221
- try {
222
- return { data: JSON.parse(text) };
223
- } catch {
224
- return { data: text };
225
- }
226
- }
227
- if (!contentType || TEXT_TYPE.test(contentType)) {
228
- return { data: body.toString('utf8') };
229
- }
230
- if (binary) return { data: body.toString('base64'), encoding: 'base64' };
231
- throw new ProxyRequestError(
232
- 'UNSUPPORTED_MEDIA_TYPE',
233
- 'The upstream response is binary and this module does not allow binary proxying',
234
- { contentType: contentType.split(';')[0] }
235
- );
236
- }
237
-
238
- module.exports = {
239
- PROXY_METHODS,
240
- ALLOWED_REQUEST_HEADERS,
241
- REJECTED_REQUEST_HEADERS,
242
- REMOVED_RESPONSE_HEADERS,
243
- validateProxyRequest,
244
- resolveAllowRules,
245
- filterRequestHeaders,
246
- filterResponseHeaders,
247
- decodeResponseBody,
248
- };
@@ -1,112 +0,0 @@
1
- const { prisma } = require('../../database/prisma');
2
- const {
3
- findOne,
4
- insertOne,
5
- updateOne,
6
- deleteMany,
7
- } = require('../../database/documentdb-utils');
8
- const {
9
- DocumentDBEncryptionService,
10
- } = require('../../database/documentdb-encryption-service');
11
- const { AuthorizationSession } = require('../domain/authorization-session');
12
- const {
13
- AuthorizationSessionRepositoryInterface,
14
- } = require('./authorization-session-repository-interface');
15
-
16
- const COLLECTION = 'AuthorizationSession';
17
-
18
- /**
19
- * AuthorizationSession persistence for DocumentDB through raw commands.
20
- * `stepData` is encrypted with DocumentDBEncryptionService, as the Prisma
21
- * extension does not run for raw commands.
22
- */
23
- class AuthorizationSessionRepositoryDocumentDB extends AuthorizationSessionRepositoryInterface {
24
- constructor() {
25
- super();
26
- this.prisma = prisma;
27
- this.encryptionService = new DocumentDBEncryptionService();
28
- }
29
-
30
- async create(session) {
31
- const now = new Date();
32
- const document = await this.encryptionService.encryptFields(COLLECTION, {
33
- sessionId: session.sessionId,
34
- userId: session.userId,
35
- entityType: session.entityType,
36
- credentialId: session.credentialId,
37
- currentStep: session.currentStep,
38
- maxSteps: session.maxSteps,
39
- stepData: session.stepData,
40
- expiresAt: session.expiresAt,
41
- completed: session.completed,
42
- createdAt: now,
43
- updatedAt: now,
44
- });
45
- await insertOne(this.prisma, COLLECTION, document);
46
- return this._toDomain(
47
- await this.encryptionService.decryptFields(COLLECTION, document)
48
- );
49
- }
50
-
51
- async findBySessionId(sessionId) {
52
- if (typeof sessionId !== 'string' || !sessionId) return null;
53
- const document = await findOne(this.prisma, COLLECTION, {
54
- sessionId,
55
- expiresAt: { $gt: new Date() },
56
- });
57
- if (!document) return null;
58
- return this._toDomain(
59
- await this.encryptionService.decryptFields(COLLECTION, document)
60
- );
61
- }
62
-
63
- async update(session) {
64
- const encrypted = await this.encryptionService.encryptFields(COLLECTION, {
65
- stepData: session.stepData,
66
- });
67
- await updateOne(
68
- this.prisma,
69
- COLLECTION,
70
- { sessionId: session.sessionId },
71
- {
72
- $set: {
73
- currentStep: session.currentStep,
74
- stepData: encrypted.stepData,
75
- completed: session.completed,
76
- updatedAt: new Date(),
77
- },
78
- }
79
- );
80
- return session;
81
- }
82
-
83
- async deleteBySessionId(sessionId) {
84
- const result = await deleteMany(this.prisma, COLLECTION, { sessionId });
85
- return result?.n ?? 0;
86
- }
87
-
88
- async deleteExpired(now = new Date()) {
89
- const result = await deleteMany(this.prisma, COLLECTION, {
90
- expiresAt: { $lte: now },
91
- });
92
- return result?.n ?? 0;
93
- }
94
-
95
- _toDomain(document) {
96
- return new AuthorizationSession({
97
- sessionId: document.sessionId,
98
- userId: document.userId,
99
- entityType: document.entityType,
100
- credentialId: document.credentialId ?? null,
101
- currentStep: document.currentStep,
102
- maxSteps: document.maxSteps,
103
- stepData: document.stepData || {},
104
- expiresAt: new Date(document.expiresAt),
105
- completed: Boolean(document.completed),
106
- createdAt: document.createdAt,
107
- updatedAt: document.updatedAt,
108
- });
109
- }
110
- }
111
-
112
- module.exports = { AuthorizationSessionRepositoryDocumentDB };
@@ -1,31 +0,0 @@
1
- const config = require('../../database/config');
2
- const {
3
- AuthorizationSessionRepositoryPrisma,
4
- } = require('./authorization-session-repository-prisma');
5
- const {
6
- AuthorizationSessionRepositoryDocumentDB,
7
- } = require('./authorization-session-repository-documentdb');
8
-
9
- /**
10
- * AuthorizationSession repository for the configured database. PostgreSQL
11
- * and MongoDB share the Prisma adapter; DocumentDB uses raw commands.
12
- */
13
- function createAuthorizationSessionRepository() {
14
- switch (config.DB_TYPE) {
15
- case 'mongodb':
16
- case 'postgresql':
17
- return new AuthorizationSessionRepositoryPrisma();
18
- case 'documentdb':
19
- return new AuthorizationSessionRepositoryDocumentDB();
20
- default:
21
- throw new Error(
22
- `Unsupported database type: ${config.DB_TYPE}. Supported values: 'mongodb', 'documentdb', 'postgresql'`
23
- );
24
- }
25
- }
26
-
27
- module.exports = {
28
- createAuthorizationSessionRepository,
29
- AuthorizationSessionRepositoryPrisma,
30
- AuthorizationSessionRepositoryDocumentDB,
31
- };
@@ -1,47 +0,0 @@
1
- /**
2
- * Port for persisting AuthorizationSession records (Management API v2
3
- * multi-step authorization). Adapters return AuthorizationSession domain
4
- * objects and never expired sessions from lookups.
5
- */
6
- class AuthorizationSessionRepositoryInterface {
7
- /**
8
- * @param {import('../domain/authorization-session').AuthorizationSession} session
9
- * @returns {Promise<import('../domain/authorization-session').AuthorizationSession>}
10
- */
11
- async create(session) {
12
- throw new Error('Method create must be implemented by subclass');
13
- }
14
-
15
- /**
16
- * @param {string} sessionId
17
- * @returns {Promise<import('../domain/authorization-session').AuthorizationSession|null>}
18
- * null when missing or expired.
19
- */
20
- async findBySessionId(sessionId) {
21
- throw new Error('Method findBySessionId must be implemented by subclass');
22
- }
23
-
24
- /**
25
- * Saves currentStep, stepData and completed.
26
- * @param {import('../domain/authorization-session').AuthorizationSession} session
27
- */
28
- async update(session) {
29
- throw new Error('Method update must be implemented by subclass');
30
- }
31
-
32
- /** @param {string} sessionId */
33
- async deleteBySessionId(sessionId) {
34
- throw new Error('Method deleteBySessionId must be implemented by subclass');
35
- }
36
-
37
- /**
38
- * Removes sessions that expired before `now`.
39
- * @param {Date} [now]
40
- * @returns {Promise<number>} how many were removed
41
- */
42
- async deleteExpired(now) {
43
- throw new Error('Method deleteExpired must be implemented by subclass');
44
- }
45
- }
46
-
47
- module.exports = { AuthorizationSessionRepositoryInterface };
@@ -1,87 +0,0 @@
1
- const { prisma } = require('../../database/prisma');
2
- const { AuthorizationSession } = require('../domain/authorization-session');
3
- const {
4
- AuthorizationSessionRepositoryInterface,
5
- } = require('./authorization-session-repository-interface');
6
-
7
- /**
8
- * AuthorizationSession persistence through the Prisma client, for PostgreSQL
9
- * and MongoDB (both schemas declare the same model; the session id, not the
10
- * row id, is the key, so no id conversion is needed). `stepData` is
11
- * encrypted by the Prisma encryption extension (encryption-schema-registry).
12
- */
13
- class AuthorizationSessionRepositoryPrisma extends AuthorizationSessionRepositoryInterface {
14
- constructor(prismaClient = prisma) {
15
- super();
16
- this.prisma = prismaClient;
17
- }
18
-
19
- async create(session) {
20
- const record = await this.prisma.authorizationSession.create({
21
- data: {
22
- sessionId: session.sessionId,
23
- userId: session.userId,
24
- entityType: session.entityType,
25
- credentialId: session.credentialId,
26
- currentStep: session.currentStep,
27
- maxSteps: session.maxSteps,
28
- stepData: session.stepData,
29
- expiresAt: session.expiresAt,
30
- completed: session.completed,
31
- },
32
- });
33
- return toDomain(record);
34
- }
35
-
36
- async findBySessionId(sessionId) {
37
- if (typeof sessionId !== 'string' || !sessionId) return null;
38
- const record = await this.prisma.authorizationSession.findFirst({
39
- where: { sessionId, expiresAt: { gt: new Date() } },
40
- });
41
- return record ? toDomain(record) : null;
42
- }
43
-
44
- async update(session) {
45
- const record = await this.prisma.authorizationSession.update({
46
- where: { sessionId: session.sessionId },
47
- data: {
48
- currentStep: session.currentStep,
49
- stepData: session.stepData,
50
- completed: session.completed,
51
- },
52
- });
53
- return toDomain(record);
54
- }
55
-
56
- async deleteBySessionId(sessionId) {
57
- const result = await this.prisma.authorizationSession.deleteMany({
58
- where: { sessionId },
59
- });
60
- return result.count;
61
- }
62
-
63
- async deleteExpired(now = new Date()) {
64
- const result = await this.prisma.authorizationSession.deleteMany({
65
- where: { expiresAt: { lte: now } },
66
- });
67
- return result.count;
68
- }
69
- }
70
-
71
- function toDomain(record) {
72
- return new AuthorizationSession({
73
- sessionId: record.sessionId,
74
- userId: record.userId,
75
- entityType: record.entityType,
76
- credentialId: record.credentialId ?? null,
77
- currentStep: record.currentStep,
78
- maxSteps: record.maxSteps,
79
- stepData: record.stepData || {},
80
- expiresAt: record.expiresAt,
81
- completed: record.completed,
82
- createdAt: record.createdAt,
83
- updatedAt: record.updatedAt,
84
- });
85
- }
86
-
87
- module.exports = { AuthorizationSessionRepositoryPrisma, toDomain };