@sanoma-ai/connector-better-auth 0.1.4 → 0.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.
@@ -0,0 +1,636 @@
1
+ import { type BetterAuthOptions } from "better-auth";
2
+ import { PostgresDialect } from "kysely";
3
+ import { Pool } from "pg";
4
+ export type Protocol = "http" | "https";
5
+ /** What each login sets on top of what every instance shares. */
6
+ export type ExtraOptions = Omit<BetterAuthOptions, "database" | "secret" | "secrets" | "basePath" | "baseURL">;
7
+ export interface BetterAuthSetup<O extends ExtraOptions> {
8
+ databaseUrl: string;
9
+ /** The app's key for this login, 32 bytes as hex (`LoginContext.key`). */
10
+ key: string;
11
+ /** The schema its tables are in: `better_auth` for visitors, `better_auth_staff` for staff. */
12
+ schema: string;
13
+ /** Where its routes are: `/auth/better-auth`. */
14
+ basePath: string;
15
+ /** The hosts each protocol's instance answers, as Better Auth's `allowedHosts` takes them. */
16
+ hosts: ReadonlyMap<Protocol, readonly string[]>;
17
+ /** The rest of the options, the same for each protocol's instance. */
18
+ options: O;
19
+ }
20
+ /**
21
+ * Opens one Better Auth per protocol on the company's database, after its migrations: `auths` by
22
+ * protocol, the `pool` they share, and `close`, which ends it. Throws, the pool ended, when the
23
+ * key is not one the app derived or the migrations fail.
24
+ */
25
+ export declare function openBetterAuth<O extends ExtraOptions>({ databaseUrl, key, schema, basePath, hosts, options, }: BetterAuthSetup<O>): Promise<{
26
+ auths: Map<Protocol, import("better-auth").Auth<{
27
+ rateLimit: {
28
+ enabled: boolean;
29
+ };
30
+ logger: {
31
+ level: "warn";
32
+ };
33
+ } & O & {
34
+ database: {
35
+ dialect: PostgresDialect;
36
+ type: "postgres";
37
+ schemaName: string;
38
+ transaction: boolean;
39
+ };
40
+ secrets: {
41
+ version: number;
42
+ value: string;
43
+ }[];
44
+ secret: string;
45
+ basePath: string;
46
+ baseURL: {
47
+ allowedHosts: string[];
48
+ protocol: Protocol;
49
+ };
50
+ telemetry: {
51
+ enabled: boolean;
52
+ };
53
+ advanced: {
54
+ disableCSRFCheck?: boolean | undefined;
55
+ crossSubDomainCookies?: {
56
+ enabled: boolean;
57
+ additionalCookies?: string[];
58
+ domain?: string;
59
+ } | undefined;
60
+ cookies?: {
61
+ [key: string]: {
62
+ name?: string;
63
+ attributes?: import("better-auth").CookieOptions;
64
+ };
65
+ } | undefined;
66
+ defaultCookieAttributes?: import("better-auth").CookieOptions | undefined;
67
+ cookiePrefix?: string | undefined;
68
+ database?: {
69
+ defaultFindManyLimit?: number;
70
+ generateId?: import("better-auth").GenerateIdFn | false | "serial" | "uuid";
71
+ joins?: boolean;
72
+ validateSchema?: boolean;
73
+ } | undefined;
74
+ trustedProxyHeaders?: boolean | undefined;
75
+ backgroundTasks?: {
76
+ handler: (promise: Promise<unknown>) => void;
77
+ };
78
+ skipTrailingSlashes?: boolean;
79
+ ipAddress: {
80
+ ipAddressHeaders?: string[];
81
+ disableIpTracking?: boolean;
82
+ ipv6Subnet?: number;
83
+ trustedProxies?: string[];
84
+ };
85
+ useSecureCookies: boolean;
86
+ disableOriginCheck: boolean;
87
+ };
88
+ }>>;
89
+ pool: Pool;
90
+ close: () => Promise<void>;
91
+ }>;
92
+ /** A request's protocol: https when it came over TLS or through a proxy that says so (`x-forwarded-proto`). */
93
+ export declare const protocolOf: (request: Request) => Protocol;
94
+ /**
95
+ * The app's Sign out POSTs no body, which Better Auth's sign-out answers with 415: the request
96
+ * with an empty JSON body; any other request as it is.
97
+ */
98
+ export declare function withSignOutBody(request: Request, signOut: string): Request;
99
+ /**
100
+ * Better Auth's email OTP for the code `sendCode` mails: six digits, five minutes, three tries,
101
+ * kept hashed; a sign-in code only (no email verification or password reset, which nothing here
102
+ * offers). Without `sendCode` nothing is sent, and the login refuses its routes.
103
+ */
104
+ export declare const emailCode: (sendCode?: (email: string, code: string) => Promise<void>) => {
105
+ id: "email-otp";
106
+ version: string;
107
+ init(ctx: import("better-auth").AuthContext): {
108
+ options: {
109
+ emailVerification: {
110
+ sendVerificationEmail(data: {
111
+ user: import("better-auth").User;
112
+ url: string;
113
+ token: string;
114
+ }, request: Request | undefined): Promise<void>;
115
+ };
116
+ };
117
+ } | undefined;
118
+ endpoints: {
119
+ sendVerificationOTP: import("better-auth").StrictEndpoint<"/email-otp/send-verification-otp", {
120
+ method: "POST";
121
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>[];
122
+ body: import("better-auth").ZodObject<{
123
+ email: import("better-auth").ZodString;
124
+ type: import("better-auth").ZodEnum<{
125
+ "sign-in": "sign-in";
126
+ "change-email": "change-email";
127
+ "email-verification": "email-verification";
128
+ "forget-password": "forget-password";
129
+ }>;
130
+ }, import("zod/v4/core").$strip>;
131
+ metadata: {
132
+ openapi: {
133
+ operationId: string;
134
+ description: string;
135
+ responses: {
136
+ 200: {
137
+ description: string;
138
+ content: {
139
+ "application/json": {
140
+ schema: {
141
+ type: "object";
142
+ properties: {
143
+ success: {
144
+ type: string;
145
+ };
146
+ };
147
+ };
148
+ };
149
+ };
150
+ };
151
+ };
152
+ };
153
+ };
154
+ }, {
155
+ success: boolean;
156
+ }>;
157
+ createVerificationOTP: import("better-auth").StrictEndpoint<string, {
158
+ method: "POST";
159
+ body: import("better-auth").ZodObject<{
160
+ email: import("better-auth").ZodString;
161
+ type: import("better-auth").ZodEnum<{
162
+ "sign-in": "sign-in";
163
+ "change-email": "change-email";
164
+ "email-verification": "email-verification";
165
+ "forget-password": "forget-password";
166
+ }>;
167
+ }, import("zod/v4/core").$strip>;
168
+ metadata: {
169
+ openapi: {
170
+ operationId: string;
171
+ description: string;
172
+ responses: {
173
+ 200: {
174
+ description: string;
175
+ content: {
176
+ "application/json": {
177
+ schema: {
178
+ type: "string";
179
+ };
180
+ };
181
+ };
182
+ };
183
+ };
184
+ };
185
+ };
186
+ }, string>;
187
+ getVerificationOTP: import("better-auth").StrictEndpoint<string, {
188
+ method: "GET";
189
+ query: import("better-auth").ZodObject<{
190
+ email: import("better-auth").ZodString;
191
+ type: import("better-auth").ZodEnum<{
192
+ "sign-in": "sign-in";
193
+ "change-email": "change-email";
194
+ "email-verification": "email-verification";
195
+ "forget-password": "forget-password";
196
+ }>;
197
+ }, import("zod/v4/core").$strip>;
198
+ metadata: {
199
+ openapi: {
200
+ operationId: string;
201
+ description: string;
202
+ responses: {
203
+ "200": {
204
+ description: string;
205
+ content: {
206
+ "application/json": {
207
+ schema: {
208
+ type: "object";
209
+ properties: {
210
+ otp: {
211
+ type: string;
212
+ nullable: boolean;
213
+ description: string;
214
+ };
215
+ };
216
+ required: string[];
217
+ };
218
+ };
219
+ };
220
+ };
221
+ };
222
+ };
223
+ };
224
+ }, {
225
+ otp: null;
226
+ } | {
227
+ otp: string;
228
+ }>;
229
+ checkVerificationOTP: import("better-auth").StrictEndpoint<"/email-otp/check-verification-otp", {
230
+ method: "POST";
231
+ body: import("better-auth").ZodObject<{
232
+ email: import("better-auth").ZodString;
233
+ type: import("better-auth").ZodEnum<{
234
+ "sign-in": "sign-in";
235
+ "change-email": "change-email";
236
+ "email-verification": "email-verification";
237
+ "forget-password": "forget-password";
238
+ }>;
239
+ otp: import("better-auth").ZodString;
240
+ }, import("zod/v4/core").$strip>;
241
+ metadata: {
242
+ openapi: {
243
+ operationId: string;
244
+ description: string;
245
+ responses: {
246
+ 200: {
247
+ description: string;
248
+ content: {
249
+ "application/json": {
250
+ schema: {
251
+ type: "object";
252
+ properties: {
253
+ success: {
254
+ type: string;
255
+ };
256
+ };
257
+ };
258
+ };
259
+ };
260
+ };
261
+ };
262
+ };
263
+ };
264
+ }, {
265
+ success: boolean;
266
+ }>;
267
+ verifyEmailOTP: import("better-auth").StrictEndpoint<"/email-otp/verify-email", {
268
+ method: "POST";
269
+ body: import("better-auth").ZodObject<{
270
+ email: import("better-auth").ZodString;
271
+ otp: import("better-auth").ZodString;
272
+ }, import("zod/v4/core").$strip>;
273
+ metadata: {
274
+ openapi: {
275
+ description: string;
276
+ responses: {
277
+ 200: {
278
+ description: string;
279
+ content: {
280
+ "application/json": {
281
+ schema: {
282
+ type: "object";
283
+ properties: {
284
+ status: {
285
+ type: string;
286
+ description: string;
287
+ enum: boolean[];
288
+ };
289
+ token: {
290
+ type: string;
291
+ nullable: boolean;
292
+ description: string;
293
+ };
294
+ user: {
295
+ $ref: string;
296
+ };
297
+ };
298
+ required: string[];
299
+ };
300
+ };
301
+ };
302
+ };
303
+ };
304
+ };
305
+ };
306
+ }, {
307
+ status: boolean;
308
+ token: string;
309
+ user: {
310
+ id: string;
311
+ createdAt: Date;
312
+ updatedAt: Date;
313
+ email: string;
314
+ emailVerified: boolean;
315
+ name: string;
316
+ image?: string | null | undefined;
317
+ } & Record<string, any>;
318
+ } | {
319
+ status: boolean;
320
+ token: null;
321
+ user: {
322
+ id: string;
323
+ createdAt: Date;
324
+ updatedAt: Date;
325
+ email: string;
326
+ emailVerified: boolean;
327
+ name: string;
328
+ image?: string | null | undefined;
329
+ } & Record<string, any>;
330
+ }>;
331
+ signInEmailOTP: import("better-auth").StrictEndpoint<"/sign-in/email-otp", {
332
+ method: "POST";
333
+ body: import("better-auth").ZodIntersection<import("better-auth").ZodObject<{
334
+ email: import("better-auth").ZodString;
335
+ otp: import("better-auth").ZodString;
336
+ name: import("better-auth").ZodOptional<import("better-auth").ZodString>;
337
+ image: import("better-auth").ZodOptional<import("better-auth").ZodString>;
338
+ }, import("zod/v4/core").$strip>, import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
339
+ metadata: {
340
+ openapi: {
341
+ operationId: string;
342
+ description: string;
343
+ responses: {
344
+ 200: {
345
+ description: string;
346
+ content: {
347
+ "application/json": {
348
+ schema: {
349
+ type: "object";
350
+ properties: {
351
+ token: {
352
+ type: string;
353
+ description: string;
354
+ };
355
+ user: {
356
+ $ref: string;
357
+ };
358
+ };
359
+ required: string[];
360
+ };
361
+ };
362
+ };
363
+ };
364
+ };
365
+ };
366
+ };
367
+ }, {
368
+ token: string;
369
+ user: {
370
+ id: string;
371
+ createdAt: Date;
372
+ updatedAt: Date;
373
+ email: string;
374
+ emailVerified: boolean;
375
+ name: string;
376
+ image?: string | null | undefined;
377
+ };
378
+ }>;
379
+ requestPasswordResetEmailOTP: import("better-auth").StrictEndpoint<"/email-otp/request-password-reset", {
380
+ method: "POST";
381
+ body: import("better-auth").ZodObject<{
382
+ email: import("better-auth").ZodString;
383
+ }, import("zod/v4/core").$strip>;
384
+ metadata: {
385
+ openapi: {
386
+ operationId: string;
387
+ description: string;
388
+ responses: {
389
+ 200: {
390
+ description: string;
391
+ content: {
392
+ "application/json": {
393
+ schema: {
394
+ type: "object";
395
+ properties: {
396
+ success: {
397
+ type: string;
398
+ description: string;
399
+ };
400
+ };
401
+ };
402
+ };
403
+ };
404
+ };
405
+ };
406
+ };
407
+ };
408
+ }, {
409
+ success: boolean;
410
+ }>;
411
+ forgetPasswordEmailOTP: import("better-auth").StrictEndpoint<"/forget-password/email-otp", {
412
+ method: "POST";
413
+ body: import("better-auth").ZodObject<{
414
+ email: import("better-auth").ZodString;
415
+ }, import("zod/v4/core").$strip>;
416
+ metadata: {
417
+ openapi: {
418
+ operationId: string;
419
+ description: string;
420
+ responses: {
421
+ 200: {
422
+ description: string;
423
+ content: {
424
+ "application/json": {
425
+ schema: {
426
+ type: "object";
427
+ properties: {
428
+ success: {
429
+ type: string;
430
+ description: string;
431
+ };
432
+ };
433
+ };
434
+ };
435
+ };
436
+ };
437
+ };
438
+ };
439
+ };
440
+ }, {
441
+ success: boolean;
442
+ }>;
443
+ resetPasswordEmailOTP: import("better-auth").StrictEndpoint<"/email-otp/reset-password", {
444
+ method: "POST";
445
+ body: import("better-auth").ZodObject<{
446
+ email: import("better-auth").ZodString;
447
+ otp: import("better-auth").ZodString;
448
+ password: import("better-auth").ZodString;
449
+ }, import("zod/v4/core").$strip>;
450
+ metadata: {
451
+ openapi: {
452
+ operationId: string;
453
+ description: string;
454
+ responses: {
455
+ 200: {
456
+ description: string;
457
+ content: {
458
+ "application/json": {
459
+ schema: {
460
+ type: "object";
461
+ properties: {
462
+ success: {
463
+ type: string;
464
+ };
465
+ };
466
+ };
467
+ };
468
+ };
469
+ };
470
+ };
471
+ };
472
+ };
473
+ }, {
474
+ success: boolean;
475
+ }>;
476
+ requestEmailChangeEmailOTP: import("better-auth").StrictEndpoint<"/email-otp/request-email-change", {
477
+ method: "POST";
478
+ body: import("better-auth").ZodObject<{
479
+ newEmail: import("better-auth").ZodString;
480
+ otp: import("better-auth").ZodOptional<import("better-auth").ZodString>;
481
+ }, import("zod/v4/core").$strip>;
482
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
483
+ session: {
484
+ session: Record<string, any> & {
485
+ id: string;
486
+ createdAt: Date;
487
+ updatedAt: Date;
488
+ userId: string;
489
+ expiresAt: Date;
490
+ token: string;
491
+ ipAddress?: string | null | undefined;
492
+ userAgent?: string | null | undefined;
493
+ };
494
+ user: Record<string, any> & {
495
+ id: string;
496
+ createdAt: Date;
497
+ updatedAt: Date;
498
+ email: string;
499
+ emailVerified: boolean;
500
+ name: string;
501
+ image?: string | null | undefined;
502
+ };
503
+ };
504
+ }>>[];
505
+ metadata: {
506
+ openapi: {
507
+ operationId: string;
508
+ description: string;
509
+ responses: {
510
+ 200: {
511
+ description: string;
512
+ content: {
513
+ "application/json": {
514
+ schema: {
515
+ type: "object";
516
+ properties: {
517
+ success: {
518
+ type: string;
519
+ };
520
+ };
521
+ };
522
+ };
523
+ };
524
+ };
525
+ };
526
+ };
527
+ };
528
+ }, {
529
+ success: boolean;
530
+ }>;
531
+ changeEmailEmailOTP: import("better-auth").StrictEndpoint<"/email-otp/change-email", {
532
+ method: "POST";
533
+ body: import("better-auth").ZodObject<{
534
+ newEmail: import("better-auth").ZodString;
535
+ otp: import("better-auth").ZodString;
536
+ }, import("zod/v4/core").$strip>;
537
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
538
+ session: {
539
+ session: Record<string, any> & {
540
+ id: string;
541
+ createdAt: Date;
542
+ updatedAt: Date;
543
+ userId: string;
544
+ expiresAt: Date;
545
+ token: string;
546
+ ipAddress?: string | null | undefined;
547
+ userAgent?: string | null | undefined;
548
+ };
549
+ user: Record<string, any> & {
550
+ id: string;
551
+ createdAt: Date;
552
+ updatedAt: Date;
553
+ email: string;
554
+ emailVerified: boolean;
555
+ name: string;
556
+ image?: string | null | undefined;
557
+ };
558
+ };
559
+ }>>[];
560
+ metadata: {
561
+ openapi: {
562
+ operationId: string;
563
+ description: string;
564
+ responses: {
565
+ 200: {
566
+ description: string;
567
+ content: {
568
+ "application/json": {
569
+ schema: {
570
+ type: "object";
571
+ properties: {
572
+ success: {
573
+ type: string;
574
+ };
575
+ };
576
+ };
577
+ };
578
+ };
579
+ };
580
+ };
581
+ };
582
+ };
583
+ }, {
584
+ success: boolean;
585
+ }>;
586
+ };
587
+ hooks: {
588
+ after: {
589
+ matcher(context: import("better-auth").HookEndpointContext): boolean;
590
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
591
+ }[];
592
+ };
593
+ rateLimit: ({
594
+ pathMatcher(path: string): path is "/email-otp/send-verification-otp";
595
+ window: number;
596
+ max: number;
597
+ } | {
598
+ pathMatcher(path: string): path is "/email-otp/check-verification-otp";
599
+ window: number;
600
+ max: number;
601
+ } | {
602
+ pathMatcher(path: string): path is "/email-otp/verify-email";
603
+ window: number;
604
+ max: number;
605
+ } | {
606
+ pathMatcher(path: string): path is "/sign-in/email-otp";
607
+ window: number;
608
+ max: number;
609
+ } | {
610
+ pathMatcher(path: string): path is "/email-otp/request-password-reset";
611
+ window: number;
612
+ max: number;
613
+ } | {
614
+ pathMatcher(path: string): path is "/email-otp/reset-password";
615
+ window: number;
616
+ max: number;
617
+ } | {
618
+ pathMatcher(path: string): path is "/forget-password/email-otp";
619
+ window: number;
620
+ max: number;
621
+ } | {
622
+ pathMatcher(path: string): path is "/email-otp/request-email-change";
623
+ window: number;
624
+ max: number;
625
+ } | {
626
+ pathMatcher(path: string): path is "/email-otp/change-email";
627
+ window: number;
628
+ max: number;
629
+ })[];
630
+ options: import("better-auth/plugins/email-otp").EmailOTPOptions;
631
+ $ERROR_CODES: {
632
+ OTP_EXPIRED: import("better-auth").RawError<"OTP_EXPIRED">;
633
+ INVALID_OTP: import("better-auth").RawError<"INVALID_OTP">;
634
+ TOO_MANY_ATTEMPTS: import("better-auth").RawError<"TOO_MANY_ATTEMPTS">;
635
+ };
636
+ };