@teamblind/axeda-better-auth 0.0.0-stage → 0.1.0-alpha.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.
@@ -0,0 +1,555 @@
1
+ import { z } from 'zod';
2
+ import { type Actor, type AssignmentScope, type Axeda } from '@teamblind/axeda-core';
3
+ import { type UserLookup } from './principal.js';
4
+ /** Lo que cada endpoint exige, para la prueba que recorre todos y para la documentación. */
5
+ export interface EndpointAccess {
6
+ readonly requires: string;
7
+ /** Alcance en el que se comprueba el permiso. */
8
+ readonly scope: 'own' | 'any' | 'global' | 'scope-parameter' | 'per-target';
9
+ }
10
+ export declare const access: (requires: string, scope: EndpointAccess["scope"]) => {
11
+ axeda: {
12
+ requires: string;
13
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
14
+ };
15
+ };
16
+ export declare const id: z.ZodString;
17
+ export declare const cursor: z.ZodString;
18
+ export declare const limit: z.ZodCoercedNumber<unknown>;
19
+ export declare const scopeBody: z.ZodUnion<readonly [z.ZodObject<{
20
+ type: z.ZodLiteral<"global">;
21
+ }, z.core.$strict>, z.ZodObject<{
22
+ type: z.ZodEnum<{
23
+ company: "company";
24
+ business: "business";
25
+ }>;
26
+ id: z.ZodString;
27
+ }, z.core.$strict>]>;
28
+ export declare const scopeQuery: {
29
+ scopeType: z.ZodOptional<z.ZodEnum<{
30
+ company: "company";
31
+ business: "business";
32
+ global: "global";
33
+ }>>;
34
+ scopeId: z.ZodOptional<z.ZodString>;
35
+ };
36
+ export declare function scopeFromQuery(query: {
37
+ scopeType?: 'global' | 'company' | 'business' | undefined;
38
+ scopeId?: string | undefined;
39
+ }): AssignmentScope | undefined;
40
+ export declare const pageOf: (query: {
41
+ cursor?: string | undefined;
42
+ limit?: number | undefined;
43
+ }) => {
44
+ cursor?: string;
45
+ limit: number;
46
+ };
47
+ interface SessionContext {
48
+ readonly context: {
49
+ readonly session: {
50
+ readonly user: {
51
+ readonly id: string;
52
+ };
53
+ };
54
+ /** Si hay `secondaryStorage`, el usuario se relee de la base de datos (ver `currentUserRow`). */
55
+ readonly options?: object | undefined;
56
+ readonly internalAdapter?: UserLookup | undefined;
57
+ };
58
+ readonly headers?: Headers | undefined;
59
+ readonly request?: Request | undefined;
60
+ }
61
+ /**
62
+ * Quien actúa, a partir de la sesión: el `Principal` (ver `principalFromUser`) más los datos de la
63
+ * petición para la auditoría.
64
+ */
65
+ export declare function actorFromSession(ctx: SessionContext): Promise<Actor>;
66
+ export type CoreProvider = () => Axeda;
67
+ /** Ejecuta un caso de uso con el actor de la sesión y traduce sus errores a respuestas HTTP. */
68
+ export declare function run<T>(ctx: SessionContext, core: CoreProvider, work: (axeda: Axeda, actor: Actor) => Promise<T>): Promise<T>;
69
+ /**
70
+ * Los endpoints del plugin. Todos exigen sesión (`sessionMiddleware`) y declaran su permiso en
71
+ * `metadata.axeda`; el permiso lo impone el caso de uso, no el endpoint. Los endpoints de Better
72
+ * Auth solo admiten GET y POST.
73
+ */
74
+ export declare function createEndpoints(core: CoreProvider): {
75
+ axedaMe: import("better-call").StrictEndpoint<"/axeda/me", {
76
+ method: "GET";
77
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
78
+ session: {
79
+ session: Record<string, any> & {
80
+ id: string;
81
+ createdAt: Date;
82
+ updatedAt: Date;
83
+ userId: string;
84
+ expiresAt: Date;
85
+ token: string;
86
+ ipAddress?: string | null | undefined;
87
+ userAgent?: string | null | undefined;
88
+ };
89
+ user: Record<string, any> & {
90
+ id: string;
91
+ createdAt: Date;
92
+ updatedAt: Date;
93
+ email: string;
94
+ emailVerified: boolean;
95
+ name: string;
96
+ image?: string | null | undefined;
97
+ };
98
+ };
99
+ }>>[];
100
+ metadata: {
101
+ axeda: {
102
+ requires: string;
103
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
104
+ };
105
+ };
106
+ }, {
107
+ userId: string;
108
+ twoFactorEnabled: boolean;
109
+ globalPermissions: string[];
110
+ assignments: import("./dto.js").AssignmentDto[];
111
+ }>;
112
+ axedaPermissionList: import("better-call").StrictEndpoint<"/axeda/permission/list", {
113
+ method: "GET";
114
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
115
+ session: {
116
+ session: Record<string, any> & {
117
+ id: string;
118
+ createdAt: Date;
119
+ updatedAt: Date;
120
+ userId: string;
121
+ expiresAt: Date;
122
+ token: string;
123
+ ipAddress?: string | null | undefined;
124
+ userAgent?: string | null | undefined;
125
+ };
126
+ user: Record<string, any> & {
127
+ id: string;
128
+ createdAt: Date;
129
+ updatedAt: Date;
130
+ email: string;
131
+ emailVerified: boolean;
132
+ name: string;
133
+ image?: string | null | undefined;
134
+ };
135
+ };
136
+ }>>[];
137
+ metadata: {
138
+ axeda: {
139
+ requires: string;
140
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
141
+ };
142
+ };
143
+ }, {
144
+ permissions: string[];
145
+ }>;
146
+ axedaRoleList: import("better-call").StrictEndpoint<"/axeda/role/list", {
147
+ method: "GET";
148
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
149
+ session: {
150
+ session: Record<string, any> & {
151
+ id: string;
152
+ createdAt: Date;
153
+ updatedAt: Date;
154
+ userId: string;
155
+ expiresAt: Date;
156
+ token: string;
157
+ ipAddress?: string | null | undefined;
158
+ userAgent?: string | null | undefined;
159
+ };
160
+ user: Record<string, any> & {
161
+ id: string;
162
+ createdAt: Date;
163
+ updatedAt: Date;
164
+ email: string;
165
+ emailVerified: boolean;
166
+ name: string;
167
+ image?: string | null | undefined;
168
+ };
169
+ };
170
+ }>>[];
171
+ query: z.ZodObject<{
172
+ cursor: z.ZodOptional<z.ZodString>;
173
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
174
+ }, z.core.$strict>;
175
+ metadata: {
176
+ axeda: {
177
+ requires: string;
178
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
179
+ };
180
+ };
181
+ }, {
182
+ items: import("./dto.js").RoleDto[];
183
+ nextCursor: string | null;
184
+ }>;
185
+ axedaRoleGet: import("better-call").StrictEndpoint<"/axeda/role/get", {
186
+ method: "GET";
187
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
188
+ session: {
189
+ session: Record<string, any> & {
190
+ id: string;
191
+ createdAt: Date;
192
+ updatedAt: Date;
193
+ userId: string;
194
+ expiresAt: Date;
195
+ token: string;
196
+ ipAddress?: string | null | undefined;
197
+ userAgent?: string | null | undefined;
198
+ };
199
+ user: Record<string, any> & {
200
+ id: string;
201
+ createdAt: Date;
202
+ updatedAt: Date;
203
+ email: string;
204
+ emailVerified: boolean;
205
+ name: string;
206
+ image?: string | null | undefined;
207
+ };
208
+ };
209
+ }>>[];
210
+ query: z.ZodObject<{
211
+ id: z.ZodString;
212
+ }, z.core.$strict>;
213
+ metadata: {
214
+ axeda: {
215
+ requires: string;
216
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
217
+ };
218
+ };
219
+ }, import("./dto.js").RoleDto>;
220
+ axedaRoleCreate: import("better-call").StrictEndpoint<"/axeda/role/create", {
221
+ method: "POST";
222
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
223
+ session: {
224
+ session: Record<string, any> & {
225
+ id: string;
226
+ createdAt: Date;
227
+ updatedAt: Date;
228
+ userId: string;
229
+ expiresAt: Date;
230
+ token: string;
231
+ ipAddress?: string | null | undefined;
232
+ userAgent?: string | null | undefined;
233
+ };
234
+ user: Record<string, any> & {
235
+ id: string;
236
+ createdAt: Date;
237
+ updatedAt: Date;
238
+ email: string;
239
+ emailVerified: boolean;
240
+ name: string;
241
+ image?: string | null | undefined;
242
+ };
243
+ };
244
+ }>>[];
245
+ body: z.ZodObject<{
246
+ key: z.ZodString;
247
+ name: z.ZodString;
248
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
249
+ permissions: z.ZodArray<z.ZodString>;
250
+ requireMfa: z.ZodOptional<z.ZodBoolean>;
251
+ }, z.core.$strict>;
252
+ metadata: {
253
+ axeda: {
254
+ requires: string;
255
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
256
+ };
257
+ };
258
+ }, import("./dto.js").RoleDto>;
259
+ axedaRoleUpdate: import("better-call").StrictEndpoint<"/axeda/role/update", {
260
+ method: "POST";
261
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
262
+ session: {
263
+ session: Record<string, any> & {
264
+ id: string;
265
+ createdAt: Date;
266
+ updatedAt: Date;
267
+ userId: string;
268
+ expiresAt: Date;
269
+ token: string;
270
+ ipAddress?: string | null | undefined;
271
+ userAgent?: string | null | undefined;
272
+ };
273
+ user: Record<string, any> & {
274
+ id: string;
275
+ createdAt: Date;
276
+ updatedAt: Date;
277
+ email: string;
278
+ emailVerified: boolean;
279
+ name: string;
280
+ image?: string | null | undefined;
281
+ };
282
+ };
283
+ }>>[];
284
+ body: z.ZodObject<{
285
+ id: z.ZodString;
286
+ version: z.ZodNumber;
287
+ name: z.ZodOptional<z.ZodString>;
288
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
289
+ permissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
290
+ requireMfa: z.ZodOptional<z.ZodBoolean>;
291
+ }, z.core.$strict>;
292
+ metadata: {
293
+ axeda: {
294
+ requires: string;
295
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
296
+ };
297
+ };
298
+ }, import("./dto.js").RoleDto>;
299
+ axedaRoleSetStatus: import("better-call").StrictEndpoint<"/axeda/role/set-status", {
300
+ method: "POST";
301
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
302
+ session: {
303
+ session: Record<string, any> & {
304
+ id: string;
305
+ createdAt: Date;
306
+ updatedAt: Date;
307
+ userId: string;
308
+ expiresAt: Date;
309
+ token: string;
310
+ ipAddress?: string | null | undefined;
311
+ userAgent?: string | null | undefined;
312
+ };
313
+ user: Record<string, any> & {
314
+ id: string;
315
+ createdAt: Date;
316
+ updatedAt: Date;
317
+ email: string;
318
+ emailVerified: boolean;
319
+ name: string;
320
+ image?: string | null | undefined;
321
+ };
322
+ };
323
+ }>>[];
324
+ body: z.ZodObject<{
325
+ id: z.ZodString;
326
+ version: z.ZodNumber;
327
+ status: z.ZodEnum<{
328
+ active: "active";
329
+ inactive: "inactive";
330
+ }>;
331
+ }, z.core.$strict>;
332
+ metadata: {
333
+ axeda: {
334
+ requires: string;
335
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
336
+ };
337
+ };
338
+ }, import("./dto.js").RoleDto>;
339
+ axedaRoleDelete: import("better-call").StrictEndpoint<"/axeda/role/delete", {
340
+ method: "POST";
341
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
342
+ session: {
343
+ session: Record<string, any> & {
344
+ id: string;
345
+ createdAt: Date;
346
+ updatedAt: Date;
347
+ userId: string;
348
+ expiresAt: Date;
349
+ token: string;
350
+ ipAddress?: string | null | undefined;
351
+ userAgent?: string | null | undefined;
352
+ };
353
+ user: Record<string, any> & {
354
+ id: string;
355
+ createdAt: Date;
356
+ updatedAt: Date;
357
+ email: string;
358
+ emailVerified: boolean;
359
+ name: string;
360
+ image?: string | null | undefined;
361
+ };
362
+ };
363
+ }>>[];
364
+ body: z.ZodObject<{
365
+ id: z.ZodString;
366
+ }, z.core.$strict>;
367
+ metadata: {
368
+ axeda: {
369
+ requires: string;
370
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
371
+ };
372
+ };
373
+ }, {
374
+ deleted: true;
375
+ }>;
376
+ axedaAssignmentList: import("better-call").StrictEndpoint<"/axeda/assignment/list", {
377
+ method: "GET";
378
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
379
+ session: {
380
+ session: Record<string, any> & {
381
+ id: string;
382
+ createdAt: Date;
383
+ updatedAt: Date;
384
+ userId: string;
385
+ expiresAt: Date;
386
+ token: string;
387
+ ipAddress?: string | null | undefined;
388
+ userAgent?: string | null | undefined;
389
+ };
390
+ user: Record<string, any> & {
391
+ id: string;
392
+ createdAt: Date;
393
+ updatedAt: Date;
394
+ email: string;
395
+ emailVerified: boolean;
396
+ name: string;
397
+ image?: string | null | undefined;
398
+ };
399
+ };
400
+ }>>[];
401
+ query: z.ZodObject<{
402
+ cursor: z.ZodOptional<z.ZodString>;
403
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
404
+ scopeType: z.ZodOptional<z.ZodEnum<{
405
+ company: "company";
406
+ business: "business";
407
+ global: "global";
408
+ }>>;
409
+ scopeId: z.ZodOptional<z.ZodString>;
410
+ userId: z.ZodOptional<z.ZodString>;
411
+ }, z.core.$strict>;
412
+ metadata: {
413
+ axeda: {
414
+ requires: string;
415
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
416
+ };
417
+ };
418
+ }, {
419
+ items: import("./dto.js").AssignmentDto[];
420
+ nextCursor: string | null;
421
+ }>;
422
+ axedaAssignmentCreate: import("better-call").StrictEndpoint<"/axeda/assignment/create", {
423
+ method: "POST";
424
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
425
+ session: {
426
+ session: Record<string, any> & {
427
+ id: string;
428
+ createdAt: Date;
429
+ updatedAt: Date;
430
+ userId: string;
431
+ expiresAt: Date;
432
+ token: string;
433
+ ipAddress?: string | null | undefined;
434
+ userAgent?: string | null | undefined;
435
+ };
436
+ user: Record<string, any> & {
437
+ id: string;
438
+ createdAt: Date;
439
+ updatedAt: Date;
440
+ email: string;
441
+ emailVerified: boolean;
442
+ name: string;
443
+ image?: string | null | undefined;
444
+ };
445
+ };
446
+ }>>[];
447
+ body: z.ZodObject<{
448
+ userId: z.ZodString;
449
+ roleId: z.ZodString;
450
+ scope: z.ZodUnion<readonly [z.ZodObject<{
451
+ type: z.ZodLiteral<"global">;
452
+ }, z.core.$strict>, z.ZodObject<{
453
+ type: z.ZodEnum<{
454
+ company: "company";
455
+ business: "business";
456
+ }>;
457
+ id: z.ZodString;
458
+ }, z.core.$strict>]>;
459
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
460
+ }, z.core.$strict>;
461
+ metadata: {
462
+ axeda: {
463
+ requires: string;
464
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
465
+ };
466
+ };
467
+ }, import("./dto.js").AssignmentDto>;
468
+ axedaAssignmentRevoke: import("better-call").StrictEndpoint<"/axeda/assignment/revoke", {
469
+ method: "POST";
470
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
471
+ session: {
472
+ session: Record<string, any> & {
473
+ id: string;
474
+ createdAt: Date;
475
+ updatedAt: Date;
476
+ userId: string;
477
+ expiresAt: Date;
478
+ token: string;
479
+ ipAddress?: string | null | undefined;
480
+ userAgent?: string | null | undefined;
481
+ };
482
+ user: Record<string, any> & {
483
+ id: string;
484
+ createdAt: Date;
485
+ updatedAt: Date;
486
+ email: string;
487
+ emailVerified: boolean;
488
+ name: string;
489
+ image?: string | null | undefined;
490
+ };
491
+ };
492
+ }>>[];
493
+ body: z.ZodObject<{
494
+ id: z.ZodString;
495
+ }, z.core.$strict>;
496
+ metadata: {
497
+ axeda: {
498
+ requires: string;
499
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
500
+ };
501
+ };
502
+ }, {
503
+ revoked: true;
504
+ }>;
505
+ axedaAuditList: import("better-call").StrictEndpoint<"/axeda/audit/list", {
506
+ method: "GET";
507
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
508
+ session: {
509
+ session: Record<string, any> & {
510
+ id: string;
511
+ createdAt: Date;
512
+ updatedAt: Date;
513
+ userId: string;
514
+ expiresAt: Date;
515
+ token: string;
516
+ ipAddress?: string | null | undefined;
517
+ userAgent?: string | null | undefined;
518
+ };
519
+ user: Record<string, any> & {
520
+ id: string;
521
+ createdAt: Date;
522
+ updatedAt: Date;
523
+ email: string;
524
+ emailVerified: boolean;
525
+ name: string;
526
+ image?: string | null | undefined;
527
+ };
528
+ };
529
+ }>>[];
530
+ query: z.ZodObject<{
531
+ cursor: z.ZodOptional<z.ZodString>;
532
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
533
+ scopeType: z.ZodOptional<z.ZodEnum<{
534
+ company: "company";
535
+ business: "business";
536
+ global: "global";
537
+ }>>;
538
+ scopeId: z.ZodOptional<z.ZodString>;
539
+ actorId: z.ZodOptional<z.ZodString>;
540
+ action: z.ZodOptional<z.ZodString>;
541
+ targetType: z.ZodOptional<z.ZodString>;
542
+ targetId: z.ZodOptional<z.ZodString>;
543
+ }, z.core.$strict>;
544
+ metadata: {
545
+ axeda: {
546
+ requires: string;
547
+ scope: "own" | "any" | "global" | "scope-parameter" | "per-target";
548
+ };
549
+ };
550
+ }, {
551
+ items: import("./dto.js").AuditEventDto[];
552
+ nextCursor: string | null;
553
+ }>;
554
+ };
555
+ export {};