Open History to see the last commit
1import * as Context from "effect/Context";
2import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as Option from "effect/Option";
6import * as Schema from "effect/Schema";
7import * as SqlClient from "effect/sql/SqlClient";
8import * as SqlSchema from "effect/sql/SqlSchema";
9
10import { AuthClientMetadata, AuthEnvironmentScopes } from "@t3tools/contracts";
11
12import {
13 type AuthPairingLinkRepositoryError,
14 PersistenceDecodeError,
15 type PersistenceErrorCorrelation,
16 PersistenceSqlError,
17} from "./Errors.ts";
18
19/**
20 * Subjects of codes that approve one agent sign-in at a set level, as `mcp-approval:<level>`.
21 * Only that sign-in may spend one, so every other use of a pairing code refuses them.
22 */
23export const MCP_APPROVAL_SUBJECT_PREFIX = "mcp-approval:";
24
25const SqliteFlag = Schema.Literals([0, 1]);
26
27export const AuthPairingLinkRecord = Schema.Struct({
28 id: Schema.String,
29 credential: Schema.String,
30 method: Schema.Literals(["desktop-bootstrap", "one-time-token"]),
31 scopes: Schema.fromJsonString(AuthEnvironmentScopes),
32 subject: Schema.String,
33 label: Schema.NullOr(Schema.String),
34 proofKeyThumbprint: Schema.NullOr(Schema.String),
35 createdAt: Schema.DateTimeUtcFromString,
36 expiresAt: Schema.DateTimeUtcFromString,
37 consumedAt: Schema.NullOr(Schema.DateTimeUtcFromString),
38 revokedAt: Schema.NullOr(Schema.DateTimeUtcFromString),
39 /** Spendable only once `proofKeyThumbprint` is a trusted T3 Connect device. */
40 requiresConnectApproval: SqliteFlag,
41 connectApproved: SqliteFlag,
42 requestedClient: Schema.NullOr(Schema.fromJsonString(AuthClientMetadata)),
43});
44export type AuthPairingLinkRecord = typeof AuthPairingLinkRecord.Type;
45
46export const CreateAuthPairingLinkInput = Schema.Struct({
47 id: Schema.String,
48 credential: Schema.String,
49 method: Schema.Literals(["desktop-bootstrap", "one-time-token"]),
50 scopes: AuthEnvironmentScopes,
51 subject: Schema.String,
52 label: Schema.NullOr(Schema.String),
53 proofKeyThumbprint: Schema.NullOr(Schema.String),
54 requiresConnectApproval: Schema.optionalKey(Schema.Boolean),
55 createdAt: Schema.DateTimeUtcFromString,
56 expiresAt: Schema.DateTimeUtcFromString,
57});
58export type CreateAuthPairingLinkInput = typeof CreateAuthPairingLinkInput.Type;
59
60export const ConsumeAuthPairingLinkInput = Schema.Struct({
61 credential: Schema.String,
62 proofKeyThumbprint: Schema.NullOr(Schema.String),
63 requestedScopes: Schema.optionalKey(AuthEnvironmentScopes),
64 requiredScopes: Schema.optionalKey(AuthEnvironmentScopes),
65 /** Also spends a code with exactly this `mcp-approval:` subject. Others are always refused. */
66 mcpApprovalSubject: Schema.optionalKey(Schema.String),
67 consumedAt: Schema.DateTimeUtcFromString,
68 now: Schema.DateTimeUtcFromString,
69});
70export type ConsumeAuthPairingLinkInput = typeof ConsumeAuthPairingLinkInput.Type;
71
72export const ListActiveAuthPairingLinksInput = Schema.Struct({
73 now: Schema.DateTimeUtcFromString,
74});
75export type ListActiveAuthPairingLinksInput = typeof ListActiveAuthPairingLinksInput.Type;
76
77export const RevokeAuthPairingLinkInput = Schema.Struct({
78 id: Schema.String,
79 revokedAt: Schema.DateTimeUtcFromString,
80});
81export type RevokeAuthPairingLinkInput = typeof RevokeAuthPairingLinkInput.Type;
82
83export const GetAuthPairingLinkByCredentialInput = Schema.Struct({
84 credential: Schema.String,
85});
86export type GetAuthPairingLinkByCredentialInput = typeof GetAuthPairingLinkByCredentialInput.Type;
87
88export const GetActiveAuthPairingLinkByIdInput = Schema.Struct({
89 id: Schema.String,
90 now: Schema.DateTimeUtcFromString,
91});
92export type GetActiveAuthPairingLinkByIdInput = typeof GetActiveAuthPairingLinkByIdInput.Type;
93
94export const FindPendingConnectPairingLinkInput = Schema.Struct({
95 proofKeyThumbprint: Schema.String,
96 now: Schema.DateTimeUtcFromString,
97});
98export type FindPendingConnectPairingLinkInput = typeof FindPendingConnectPairingLinkInput.Type;
99
100/** Unspent links bound to `proofKeyThumbprint`, or with `keepProofKeyThumbprint` every other bound one. */
101export const RevokeUnspentByProofKeyInput = Schema.Struct({
102 proofKeyThumbprint: Schema.NullOr(Schema.String),
103 keepProofKeyThumbprint: Schema.NullOr(Schema.String),
104 revokedAt: Schema.DateTimeUtcFromString,
105});
106export type RevokeUnspentByProofKeyInput = typeof RevokeUnspentByProofKeyInput.Type;
107
108export const RecordConnectRequestClientInput = Schema.Struct({
109 id: Schema.String,
110 client: Schema.fromJsonString(AuthClientMetadata),
111});
112export type RecordConnectRequestClientInput = typeof RecordConnectRequestClientInput.Type;
113
114const AuthPairingLinkRawDbRow = Schema.Struct({
115 id: Schema.String,
116 credential: Schema.Unknown,
117 method: Schema.Unknown,
118 scopes: Schema.Unknown,
119 subject: Schema.Unknown,
120 label: Schema.Unknown,
121 proofKeyThumbprint: Schema.Unknown,
122 createdAt: Schema.Unknown,
123 expiresAt: Schema.Unknown,
124 consumedAt: Schema.Unknown,
125 revokedAt: Schema.Unknown,
126 requiresConnectApproval: Schema.Unknown,
127 connectApproved: Schema.Unknown,
128 requestedClient: Schema.Unknown,
129});
130
131const decodeAuthPairingLinkDbRow = Schema.decodeUnknownEffect(AuthPairingLinkRecord);
132
133export class AuthPairingLinkRepository extends Context.Service<
134 AuthPairingLinkRepository,
135 {
136 readonly create: (
137 input: CreateAuthPairingLinkInput,
138 ) => Effect.Effect<void, AuthPairingLinkRepositoryError>;
139 readonly consumeAvailable: (
140 input: ConsumeAuthPairingLinkInput,
141 ) => Effect.Effect<Option.Option<AuthPairingLinkRecord>, AuthPairingLinkRepositoryError>;
142 readonly listActive: (
143 input: ListActiveAuthPairingLinksInput,
144 ) => Effect.Effect<ReadonlyArray<AuthPairingLinkRecord>, AuthPairingLinkRepositoryError>;
145 readonly revoke: (
146 input: RevokeAuthPairingLinkInput,
147 ) => Effect.Effect<boolean, AuthPairingLinkRepositoryError>;
148 readonly getByCredential: (
149 input: GetAuthPairingLinkByCredentialInput,
150 ) => Effect.Effect<Option.Option<AuthPairingLinkRecord>, AuthPairingLinkRepositoryError>;
151 readonly getActiveById: (
152 input: GetActiveAuthPairingLinkByIdInput,
153 ) => Effect.Effect<Option.Option<AuthPairingLinkRecord>, AuthPairingLinkRepositoryError>;
154 /** The device's open or denied request, so its retries do not stack up or re-prompt. */
155 readonly findPendingConnect: (
156 input: FindPendingConnectPairingLinkInput,
157 ) => Effect.Effect<Option.Option<AuthPairingLinkRecord>, AuthPairingLinkRepositoryError>;
158 /** Keeps the first description a device gave, so it cannot be swapped while someone decides. */
159 readonly recordConnectRequestClient: (
160 input: RecordConnectRequestClientInput,
161 ) => Effect.Effect<boolean, AuthPairingLinkRepositoryError>;
162 readonly revokeUnspentByProofKey: (
163 input: RevokeUnspentByProofKeyInput,
164 ) => Effect.Effect<ReadonlyArray<string>, AuthPairingLinkRepositoryError>;
165 }
166>()("t3/persistence/AuthPairingLinks/AuthPairingLinkRepository") {}
167
168function toPersistenceSqlOrDecodeError(
169 sqlOperation: string,
170 decodeOperation: string,
171 correlation?: PersistenceErrorCorrelation,
172) {
173 return (cause: unknown): AuthPairingLinkRepositoryError =>
174 Schema.isSchemaError(cause)
175 ? PersistenceDecodeError.fromSchemaError(decodeOperation, cause, correlation)
176 : new PersistenceSqlError({
177 operation: sqlOperation,
178 ...(correlation === undefined ? {} : { correlation }),
179 cause,
180 });
181}
182
183/** @public */
184export const make = Effect.gen(function* () {
185 const sql = yield* SqlClient.SqlClient;
186
187 const createPairingLinkRow = SqlSchema.void({
188 Request: CreateAuthPairingLinkInput,
189 execute: (input) =>
190 sql`
191 INSERT INTO auth_pairing_links (
192 id,
193 credential,
194 method,
195 scopes,
196 subject,
197 label,
198 proof_key_thumbprint,
199 requires_connect_approval,
200 created_at,
201 expires_at,
202 consumed_at,
203 revoked_at
204 )
205 VALUES (
206 ${input.id},
207 ${input.credential},
208 ${input.method},
209 ${JSON.stringify(input.scopes)},
210 ${input.subject},
211 ${input.label},
212 ${input.proofKeyThumbprint},
213 ${input.requiresConnectApproval ? 1 : 0},
214 ${input.createdAt},
215 ${input.expiresAt},
216 NULL,
217 NULL
218 )
219 `,
220 });
221
222 const consumeAvailablePairingLinkRow = SqlSchema.findOneOption({
223 Request: ConsumeAuthPairingLinkInput,
224 Result: AuthPairingLinkRawDbRow,
225 execute: ({
226 credential,
227 proofKeyThumbprint,
228 requestedScopes,
229 requiredScopes,
230 mcpApprovalSubject,
231 consumedAt,
232 now,
233 }) =>
234 sql`
235 UPDATE auth_pairing_links
236 SET consumed_at = ${consumedAt}
237 WHERE credential = ${credential}
238 AND revoked_at IS NULL
239 AND consumed_at IS NULL
240 AND expires_at > ${now}
241 AND (
242 subject NOT LIKE ${`${MCP_APPROVAL_SUBJECT_PREFIX}%`}
243 OR subject = ${mcpApprovalSubject ?? null}
244 )
245 AND (
246 proof_key_thumbprint IS NULL
247 OR proof_key_thumbprint = ${proofKeyThumbprint}
248 )
249 AND (
250 requires_connect_approval = 0
251 OR proof_key_thumbprint IN (SELECT proof_key_thumbprint FROM auth_connect_devices)
252 )
253 AND (${requestedScopes === undefined ? 1 : 0} OR EXISTS (
254 SELECT 1
255 FROM json_each(${JSON.stringify(requestedScopes ?? [])}) AS requested
256 WHERE requested.value IN (
257 SELECT value FROM json_each(auth_pairing_links.scopes)
258 )
259 ))
260 AND NOT EXISTS (
261 SELECT 1
262 FROM json_each(${JSON.stringify(requiredScopes ?? [])}) AS required
263 WHERE required.value NOT IN (
264 SELECT value FROM json_each(auth_pairing_links.scopes)
265 )
266 )
267 RETURNING
268 id AS "id",
269 credential AS "credential",
270 method AS "method",
271 scopes AS "scopes",
272 subject AS "subject",
273 label AS "label",
274 proof_key_thumbprint AS "proofKeyThumbprint",
275 created_at AS "createdAt",
276 expires_at AS "expiresAt",
277 consumed_at AS "consumedAt",
278 revoked_at AS "revokedAt",
279 requires_connect_approval AS "requiresConnectApproval",
280 EXISTS (
281 SELECT 1 FROM auth_connect_devices
282 WHERE auth_connect_devices.proof_key_thumbprint = auth_pairing_links.proof_key_thumbprint
283 ) AS "connectApproved",
284 requested_client_json AS "requestedClient"
285 `,
286 });
287
288 const listActivePairingLinkRows = SqlSchema.findAll({
289 Request: ListActiveAuthPairingLinksInput,
290 Result: AuthPairingLinkRawDbRow,
291 execute: ({ now }) =>
292 sql`
293 SELECT
294 id AS "id",
295 credential AS "credential",
296 method AS "method",
297 scopes AS "scopes",
298 subject AS "subject",
299 label AS "label",
300 proof_key_thumbprint AS "proofKeyThumbprint",
301 created_at AS "createdAt",
302 expires_at AS "expiresAt",
303 consumed_at AS "consumedAt",
304 revoked_at AS "revokedAt",
305 requires_connect_approval AS "requiresConnectApproval",
306 EXISTS (
307 SELECT 1 FROM auth_connect_devices
308 WHERE auth_connect_devices.proof_key_thumbprint = auth_pairing_links.proof_key_thumbprint
309 ) AS "connectApproved",
310 requested_client_json AS "requestedClient"
311 FROM auth_pairing_links
312 WHERE revoked_at IS NULL
313 AND consumed_at IS NULL
314 AND expires_at > ${now}
315 ORDER BY created_at DESC, id DESC
316 `,
317 });
318
319 const revokePairingLinkRow = SqlSchema.findAll({
320 Request: RevokeAuthPairingLinkInput,
321 Result: Schema.Struct({ id: Schema.String }),
322 execute: ({ id, revokedAt }) =>
323 sql`
324 UPDATE auth_pairing_links
325 SET revoked_at = ${revokedAt},
326 -- Revoking a waiting approval request is a denial; see findPendingConnect.
327 connect_denied = requires_connect_approval
328 WHERE id = ${id}
329 AND revoked_at IS NULL
330 AND consumed_at IS NULL
331 RETURNING id AS "id"
332 `,
333 });
334
335 const getPairingLinkRowByCredential = SqlSchema.findOneOption({
336 Request: GetAuthPairingLinkByCredentialInput,
337 Result: AuthPairingLinkRawDbRow,
338 execute: ({ credential }) =>
339 sql`
340 SELECT
341 id AS "id",
342 credential AS "credential",
343 method AS "method",
344 scopes AS "scopes",
345 subject AS "subject",
346 label AS "label",
347 proof_key_thumbprint AS "proofKeyThumbprint",
348 created_at AS "createdAt",
349 expires_at AS "expiresAt",
350 consumed_at AS "consumedAt",
351 revoked_at AS "revokedAt",
352 requires_connect_approval AS "requiresConnectApproval",
353 EXISTS (
354 SELECT 1 FROM auth_connect_devices
355 WHERE auth_connect_devices.proof_key_thumbprint = auth_pairing_links.proof_key_thumbprint
356 ) AS "connectApproved",
357 requested_client_json AS "requestedClient"
358 FROM auth_pairing_links
359 WHERE credential = ${credential}
360 `,
361 });
362
363 const selectRow = sql`
364 SELECT
365 id AS "id",
366 credential AS "credential",
367 method AS "method",
368 scopes AS "scopes",
369 subject AS "subject",
370 label AS "label",
371 proof_key_thumbprint AS "proofKeyThumbprint",
372 created_at AS "createdAt",
373 expires_at AS "expiresAt",
374 consumed_at AS "consumedAt",
375 revoked_at AS "revokedAt",
376 requires_connect_approval AS "requiresConnectApproval",
377 EXISTS (
378 SELECT 1 FROM auth_connect_devices
379 WHERE auth_connect_devices.proof_key_thumbprint = auth_pairing_links.proof_key_thumbprint
380 ) AS "connectApproved",
381 requested_client_json AS "requestedClient"
382 FROM auth_pairing_links
383 `;
384
385 const getActivePairingLinkRowById = SqlSchema.findOneOption({
386 Request: GetActiveAuthPairingLinkByIdInput,
387 Result: AuthPairingLinkRawDbRow,
388 execute: ({ id, now }) =>
389 sql`
390 ${selectRow}
391 WHERE id = ${id}
392 AND revoked_at IS NULL
393 AND consumed_at IS NULL
394 AND expires_at > ${now}
395 `,
396 });
397
398 const findPendingConnectPairingLinkRow = SqlSchema.findOneOption({
399 Request: FindPendingConnectPairingLinkInput,
400 Result: AuthPairingLinkRawDbRow,
401 execute: ({ proofKeyThumbprint, now }) =>
402 sql`
403 ${selectRow}
404 WHERE proof_key_thumbprint = ${proofKeyThumbprint}
405 AND requires_connect_approval = 1
406 -- A denied request stays the device's answer until it expires, so retries get a
407 -- dead credential back instead of prompting the approver again.
408 AND (revoked_at IS NULL OR connect_denied = 1)
409 AND consumed_at IS NULL
410 AND expires_at > ${now}
411 ORDER BY created_at DESC, id DESC
412 LIMIT 1
413 `,
414 });
415
416 const recordConnectRequestClientRow = SqlSchema.findAll({
417 Request: RecordConnectRequestClientInput,
418 Result: Schema.Struct({ id: Schema.String }),
419 execute: ({ id, client }) =>
420 sql`
421 UPDATE auth_pairing_links
422 SET requested_client_json = ${client}
423 WHERE id = ${id}
424 AND requires_connect_approval = 1
425 AND requested_client_json IS NULL
426 RETURNING id AS "id"
427 `,
428 });
429
430 const decodeOptionalRow =
431 (operation: string) => (rowOption: Option.Option<typeof AuthPairingLinkRawDbRow.Type>) =>
432 Option.match(rowOption, {
433 onNone: () => Effect.succeedNone,
434 onSome: (row) =>
435 decodeAuthPairingLinkDbRow(row).pipe(
436 Effect.mapError((cause) =>
437 PersistenceDecodeError.fromSchemaError(operation, cause, { pairingLinkId: row.id }),
438 ),
439 Effect.asSome,
440 ),
441 });
442
443 const getActiveById: AuthPairingLinkRepository["Service"]["getActiveById"] = (input) =>
444 getActivePairingLinkRowById(input).pipe(
445 NodeSqliteClient.readOnly,
446 Effect.mapError(
447 toPersistenceSqlOrDecodeError(
448 "AuthPairingLinkRepository.getActiveById:query",
449 "AuthPairingLinkRepository.getActiveById:decodeRow",
450 { pairingLinkId: input.id },
451 ),
452 ),
453 Effect.flatMap(decodeOptionalRow("AuthPairingLinkRepository.getActiveById:decodeRow")),
454 );
455
456 const findPendingConnect: AuthPairingLinkRepository["Service"]["findPendingConnect"] = (input) =>
457 findPendingConnectPairingLinkRow(input).pipe(
458 NodeSqliteClient.readOnly,
459 Effect.mapError(
460 toPersistenceSqlOrDecodeError(
461 "AuthPairingLinkRepository.findPendingConnect:query",
462 "AuthPairingLinkRepository.findPendingConnect:decodeRow",
463 ),
464 ),
465 Effect.flatMap(decodeOptionalRow("AuthPairingLinkRepository.findPendingConnect:decodeRow")),
466 );
467
468 const recordConnectRequestClient: AuthPairingLinkRepository["Service"]["recordConnectRequestClient"] =
469 (input) =>
470 recordConnectRequestClientRow(input).pipe(
471 Effect.mapError(
472 toPersistenceSqlOrDecodeError(
473 "AuthPairingLinkRepository.recordConnectRequestClient:query",
474 "AuthPairingLinkRepository.recordConnectRequestClient:encodeRequest",
475 { pairingLinkId: input.id },
476 ),
477 ),
478 Effect.map((rows) => rows.length > 0),
479 );
480
481 const revokeUnspentByProofKeyRows = SqlSchema.findAll({
482 Request: RevokeUnspentByProofKeyInput,
483 Result: Schema.Struct({ id: Schema.String }),
484 execute: ({ proofKeyThumbprint, keepProofKeyThumbprint, revokedAt }) =>
485 sql`
486 -- Only T3 Connect mints bind a proof key, so these are that key's connect credentials.
487 UPDATE auth_pairing_links
488 SET revoked_at = ${revokedAt}
489 WHERE proof_key_thumbprint IS NOT NULL
490 AND revoked_at IS NULL
491 AND consumed_at IS NULL
492 AND (${proofKeyThumbprint} IS NULL OR proof_key_thumbprint = ${proofKeyThumbprint})
493 AND proof_key_thumbprint IS NOT ${keepProofKeyThumbprint}
494 RETURNING id AS "id"
495 `,
496 });
497
498 const revokeUnspentByProofKey: AuthPairingLinkRepository["Service"]["revokeUnspentByProofKey"] = (
499 input,
500 ) =>
501 revokeUnspentByProofKeyRows(input).pipe(
502 Effect.mapError(
503 toPersistenceSqlOrDecodeError(
504 "AuthPairingLinkRepository.revokeUnspentByProofKey:query",
505 "AuthPairingLinkRepository.revokeUnspentByProofKey:decodeRows",
506 ),
507 ),
508 Effect.map((rows) => rows.map((row) => row.id)),
509 );
510
511 const create: AuthPairingLinkRepository["Service"]["create"] = (input) =>
512 createPairingLinkRow(input).pipe(
513 Effect.mapError(
514 toPersistenceSqlOrDecodeError(
515 "AuthPairingLinkRepository.create:query",
516 "AuthPairingLinkRepository.create:encodeRequest",
517 { pairingLinkId: input.id },
518 ),
519 ),
520 );
521
522 const consumeAvailable: AuthPairingLinkRepository["Service"]["consumeAvailable"] = (input) =>
523 consumeAvailablePairingLinkRow(input).pipe(
524 Effect.mapError(
525 toPersistenceSqlOrDecodeError(
526 "AuthPairingLinkRepository.consumeAvailable:query",
527 "AuthPairingLinkRepository.consumeAvailable:decodeRow",
528 ),
529 ),
530 Effect.flatMap((rowOption) =>
531 Option.match(rowOption, {
532 onNone: () => Effect.succeedNone,
533 onSome: (row) =>
534 decodeAuthPairingLinkDbRow(row).pipe(
535 Effect.mapError((cause) =>
536 PersistenceDecodeError.fromSchemaError(
537 "AuthPairingLinkRepository.consumeAvailable:decodeRow",
538 cause,
539 { pairingLinkId: row.id },
540 ),
541 ),
542 Effect.asSome,
543 ),
544 }),
545 ),
546 );
547
548 const listActive: AuthPairingLinkRepository["Service"]["listActive"] = (input) =>
549 listActivePairingLinkRows(input).pipe(
550 NodeSqliteClient.readOnly,
551 Effect.mapError(
552 toPersistenceSqlOrDecodeError(
553 "AuthPairingLinkRepository.listActive:query",
554 "AuthPairingLinkRepository.listActive:decodeRows",
555 ),
556 ),
557 Effect.flatMap((rows) =>
558 Effect.forEach(rows, (row) =>
559 decodeAuthPairingLinkDbRow(row).pipe(
560 Effect.mapError((cause) =>
561 PersistenceDecodeError.fromSchemaError(
562 "AuthPairingLinkRepository.listActive:decodeRows",
563 cause,
564 { pairingLinkId: row.id },
565 ),
566 ),
567 ),
568 ),
569 ),
570 );
571
572 const revoke: AuthPairingLinkRepository["Service"]["revoke"] = (input) =>
573 revokePairingLinkRow(input).pipe(
574 Effect.mapError(
575 toPersistenceSqlOrDecodeError(
576 "AuthPairingLinkRepository.revoke:query",
577 "AuthPairingLinkRepository.revoke:decodeRows",
578 { pairingLinkId: input.id },
579 ),
580 ),
581 Effect.map((rows) => rows.length > 0),
582 );
583
584 const getByCredential: AuthPairingLinkRepository["Service"]["getByCredential"] = (input) =>
585 getPairingLinkRowByCredential(input).pipe(
586 NodeSqliteClient.readOnly,
587 Effect.mapError(
588 toPersistenceSqlOrDecodeError(
589 "AuthPairingLinkRepository.getByCredential:query",
590 "AuthPairingLinkRepository.getByCredential:decodeRow",
591 ),
592 ),
593 Effect.flatMap((rowOption) =>
594 Option.match(rowOption, {
595 onNone: () => Effect.succeedNone,
596 onSome: (row) =>
597 decodeAuthPairingLinkDbRow(row).pipe(
598 Effect.mapError((cause) =>
599 PersistenceDecodeError.fromSchemaError(
600 "AuthPairingLinkRepository.getByCredential:decodeRow",
601 cause,
602 { pairingLinkId: row.id },
603 ),
604 ),
605 Effect.asSome,
606 ),
607 }),
608 ),
609 );
610
611 return {
612 create,
613 consumeAvailable,
614 listActive,
615 revoke,
616 getByCredential,
617 getActiveById,
618 findPendingConnect,
619 recordConnectRequestClient,
620 revokeUnspentByProofKey,
621 } satisfies AuthPairingLinkRepository["Service"];
622});
623
624export const layer = Layer.effect(AuthPairingLinkRepository, make);