@cubicecho/server-kit 0.3.0 → 0.4.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.
@@ -35,6 +35,7 @@ const auth = betterAuth({
35
35
  ```
36
36
 
37
37
  - Set every `id` column with `id()`: the preset leaves ids to the database.
38
+ - OIDC is on by default. A server without it says `oidc: false`, and then needs no `sso_providers` table.
38
39
  - `deliver: undefined` is an instance that cannot email. `sendsMagicLinks(auth)` says which it is.
39
40
  - `paths` moves the app's `login`, `verify` and `signedIn` pages.
40
41
  - An option after the spread replaces the preset's whole value, so `session: { … }` has to repeat `expiresIn`.
@@ -1,4 +1,4 @@
1
1
  export { AUTH_DEFAULTS, AUTH_PATHS, type AuthPaths, type AuthSettings, RATE_LIMIT_DEFAULTS, type RateLimitSettings, } from './defaults.ts';
2
- export { type MagicLink, type SignInOptions, sendsMagicLinks, signInPlugins } from './plugins.ts';
2
+ export { type MagicLink, type OidcOptions, type SignInOptions, sendsMagicLinks, signInPlugins } from './plugins.ts';
3
3
  export { type AuthPresetOptions, type AuthTables, authPreset } from './preset.ts';
4
4
  export { createRateLimiter, type RateLimiter, type ThrottleContext, throttle } from './rate-limit.ts';
@@ -7,14 +7,14 @@ export interface MagicLink {
7
7
  url: string;
8
8
  token: string;
9
9
  }
10
- /** What an app gives `signInPlugins`. */
10
+ /** OIDC sign-in and pairing, without the two URLs, which follow from `appUrl`. */
11
+ export type OidcOptions = Omit<Parameters<typeof oidcPairingPlugins>[0], 'signedInURL' | 'errorURL'>;
12
+ /** What an app gives `signInPlugins`, besides OIDC. */
11
13
  export interface SignInOptions extends Partial<Pick<AuthSettings, 'magicLinkTtlMinutes'>> {
12
14
  /** Where users reach the app. */
13
15
  appUrl: string;
14
16
  /** Delivers a sign-in link, or undefined on an instance that cannot email. */
15
17
  deliver: ((link: MagicLink) => Promise<void>) | undefined;
16
- /** OIDC sign-in and pairing, without the two URLs, which follow from `appUrl`. */
17
- oidc: Omit<Parameters<typeof oidcPairingPlugins>[0], 'signedInURL' | 'errorURL'>;
18
18
  /**
19
19
  * Pages that are somewhere else in this app.
20
20
  *
@@ -23,12 +23,145 @@ export interface SignInOptions extends Partial<Pick<AuthSettings, 'magicLinkTtlM
23
23
  paths?: Partial<AuthPaths>;
24
24
  }
25
25
  /**
26
- * How people sign in: bearer sessions, OIDC with pairing, and emailed links. Never a password.
26
+ * The plugins every server has: bearer sessions, and emailed links when there is a way to deliver them.
27
27
  *
28
- * @param options - The app's links and provider.
29
- * @returns The plugins, to spread into `plugins`.
28
+ * @param options - The app's links.
29
+ * @returns The plugins.
30
30
  */
31
- export declare function signInPlugins({ appUrl, deliver, oidc, paths, magicLinkTtlMinutes, }: SignInOptions): ({
31
+ declare function linkPlugins({ appUrl, deliver, paths, magicLinkTtlMinutes, }: SignInOptions): ({
32
+ id: "bearer";
33
+ version: string;
34
+ hooks: {
35
+ before: {
36
+ matcher(context: import("better-auth").HookEndpointContext): boolean;
37
+ handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
38
+ context: {
39
+ headers: Headers;
40
+ };
41
+ } | undefined>>;
42
+ }[];
43
+ after: {
44
+ matcher(context: import("better-auth").HookEndpointContext): true;
45
+ handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
46
+ }[];
47
+ };
48
+ options: import("better-auth/plugins").BearerOptions | undefined;
49
+ } | {
50
+ id: "magic-link";
51
+ version: string;
52
+ endpoints: {
53
+ signInMagicLink: import("better-call").StrictEndpoint<"/sign-in/magic-link", {
54
+ method: "POST";
55
+ requireHeaders: true;
56
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
57
+ body: import("zod").ZodObject<{
58
+ email: import("zod").ZodEmail;
59
+ name: import("zod").ZodOptional<import("zod").ZodString>;
60
+ callbackURL: import("zod").ZodOptional<import("zod").ZodString>;
61
+ newUserCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
62
+ errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
63
+ metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
64
+ }, import("zod/v4/core").$strip>;
65
+ metadata: {
66
+ openapi: {
67
+ operationId: string;
68
+ description: string;
69
+ responses: {
70
+ 200: {
71
+ description: string;
72
+ content: {
73
+ "application/json": {
74
+ schema: {
75
+ type: "object";
76
+ properties: {
77
+ status: {
78
+ type: string;
79
+ };
80
+ };
81
+ };
82
+ };
83
+ };
84
+ };
85
+ };
86
+ };
87
+ };
88
+ }, {
89
+ status: boolean;
90
+ }>;
91
+ magicLinkVerify: import("better-call").StrictEndpoint<"/magic-link/verify", {
92
+ method: "GET";
93
+ query: import("zod").ZodObject<{
94
+ token: import("zod").ZodString;
95
+ callbackURL: import("zod").ZodOptional<import("zod").ZodString>;
96
+ errorCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
97
+ newUserCallbackURL: import("zod").ZodOptional<import("zod").ZodString>;
98
+ }, import("zod/v4/core").$strip>;
99
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
100
+ requireHeaders: true;
101
+ metadata: {
102
+ openapi: {
103
+ operationId: string;
104
+ description: string;
105
+ responses: {
106
+ 200: {
107
+ description: string;
108
+ content: {
109
+ "application/json": {
110
+ schema: {
111
+ type: "object";
112
+ properties: {
113
+ session: {
114
+ $ref: string;
115
+ };
116
+ user: {
117
+ $ref: string;
118
+ };
119
+ };
120
+ };
121
+ };
122
+ };
123
+ };
124
+ };
125
+ };
126
+ };
127
+ }, {
128
+ token: string;
129
+ user: {
130
+ id: string;
131
+ createdAt: Date;
132
+ updatedAt: Date;
133
+ email: string;
134
+ emailVerified: boolean;
135
+ name: string;
136
+ image?: string | null | undefined;
137
+ };
138
+ session: {
139
+ id: string;
140
+ createdAt: Date;
141
+ updatedAt: Date;
142
+ userId: string;
143
+ expiresAt: Date;
144
+ token: string;
145
+ ipAddress?: string | null | undefined;
146
+ userAgent?: string | null | undefined;
147
+ };
148
+ }>;
149
+ };
150
+ rateLimit: {
151
+ pathMatcher(path: string): boolean;
152
+ window: number;
153
+ max: number;
154
+ }[];
155
+ options: import("better-auth/plugins").MagicLinkOptions;
156
+ })[];
157
+ /**
158
+ * Those, with OIDC sign-in and pairing.
159
+ *
160
+ * @param options - The app's links.
161
+ * @param oidc - The app's OIDC options.
162
+ * @returns The plugins.
163
+ */
164
+ declare function oidcPlugins(options: SignInOptions, oidc: OidcOptions): ({
32
165
  id: "sso";
33
166
  version: string;
34
167
  endpoints: {
@@ -1255,6 +1388,19 @@ export declare function signInPlugins({ appUrl, deliver, oidc, paths, magicLinkT
1255
1388
  }[];
1256
1389
  options: import("better-auth/plugins").MagicLinkOptions;
1257
1390
  })[];
1391
+ /**
1392
+ * How people sign in: bearer sessions, emailed links, and OIDC with pairing. Never a password.
1393
+ *
1394
+ * @param options - The app's links, and its OIDC options.
1395
+ * @param options.oidc - `false` for a server without OIDC. It has to be said, so that it is never left out by accident.
1396
+ * @returns The plugins, to spread into `plugins`.
1397
+ */
1398
+ export declare function signInPlugins(options: SignInOptions & {
1399
+ oidc: OidcOptions;
1400
+ }): ReturnType<typeof oidcPlugins>;
1401
+ export declare function signInPlugins(options: SignInOptions & {
1402
+ oidc: false;
1403
+ }): ReturnType<typeof linkPlugins>;
1258
1404
  /**
1259
1405
  * Whether an instance emails sign-in links.
1260
1406
  *
@@ -1268,3 +1414,4 @@ export declare function sendsMagicLinks(auth: {
1268
1414
  }[];
1269
1415
  };
1270
1416
  }): boolean;
1417
+ export {};
@@ -5,13 +5,13 @@ const SECONDS_PER_MINUTE = 60;
5
5
  /** better-auth's id for the magic-link plugin. */
6
6
  const MAGIC_LINK_PLUGIN_ID = 'magic-link';
7
7
  /**
8
- * How people sign in: bearer sessions, OIDC with pairing, and emailed links. Never a password.
8
+ * The plugins every server has: bearer sessions, and emailed links when there is a way to deliver them.
9
9
  *
10
- * @param options - The app's links and provider.
11
- * @returns The plugins, to spread into `plugins`.
10
+ * @param options - The app's links.
11
+ * @returns The plugins.
12
12
  */
13
- export function signInPlugins({ appUrl, deliver, oidc, paths, magicLinkTtlMinutes = AUTH_DEFAULTS.magicLinkTtlMinutes, }) {
14
- const { login, verify, signedIn } = { ...AUTH_PATHS, ...paths };
13
+ function linkPlugins({ appUrl, deliver, paths, magicLinkTtlMinutes = AUTH_DEFAULTS.magicLinkTtlMinutes, }) {
14
+ const { verify } = { ...AUTH_PATHS, ...paths };
15
15
  const links = deliver === undefined
16
16
  ? []
17
17
  : [
@@ -22,12 +22,26 @@ export function signInPlugins({ appUrl, deliver, oidc, paths, magicLinkTtlMinute
22
22
  sendMagicLink: ({ email, token }) => deliver({ email, token, url: `${appUrl}${verify}?token=${encodeURIComponent(token)}` }),
23
23
  }),
24
24
  ];
25
+ return [bearer(), ...links];
26
+ }
27
+ /**
28
+ * Those, with OIDC sign-in and pairing.
29
+ *
30
+ * @param options - The app's links.
31
+ * @param oidc - The app's OIDC options.
32
+ * @returns The plugins.
33
+ */
34
+ function oidcPlugins(options, oidc) {
35
+ const { appUrl, paths } = options;
36
+ const { login, signedIn } = { ...AUTH_PATHS, ...paths };
25
37
  return [
26
- bearer(),
38
+ ...linkPlugins(options),
27
39
  ...oidcPairingPlugins({ ...oidc, signedInURL: `${appUrl}${signedIn}`, errorURL: `${appUrl}${login}` }),
28
- ...links,
29
40
  ];
30
41
  }
42
+ export function signInPlugins({ oidc, ...options }) {
43
+ return oidc === false ? linkPlugins(options) : oidcPlugins(options, oidc);
44
+ }
31
45
  /**
32
46
  * Whether an instance emails sign-in links.
33
47
  *
package/llms.txt CHANGED
@@ -24,9 +24,10 @@ Requires Node >=22. Peer dependencies: `@better-auth/sso` >=1.7.28 <1.8.0, `@ele
24
24
  - `RATE_LIMIT_DEFAULTS`: What `createRateLimiter` uses when the app overrides nothing.
25
25
  - `RateLimitSettings` (type): The sign-in throttle.
26
26
  - `MagicLink` (type): What delivering one sign-in link is given.
27
- - `SignInOptions` (type): What an app gives `signInPlugins`.
27
+ - `OidcOptions` (type): OIDC sign-in and pairing, without the two URLs, which follow from `appUrl`.
28
+ - `SignInOptions` (type): What an app gives `signInPlugins`, besides OIDC.
28
29
  - `sendsMagicLinks`: Whether an instance emails sign-in links.
29
- - `signInPlugins`: How people sign in: bearer sessions, OIDC with pairing, and emailed links.
30
+ - `signInPlugins`: How people sign in: bearer sessions, emailed links, and OIDC with pairing.
30
31
  - `AuthPresetOptions` (type): What an app gives the preset.
31
32
  - `AuthTables` (type): The tables better-auth keeps, by its own model names.
32
33
  - `authPreset`: The better-auth options every server shares.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubicecho/server-kit",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The server code every cubicecho GraphQL backend shares: database boot, id columns and the checks that keep a schema to the standard.",
5
5
  "license": "MIT",
6
6
  "author": "Benjamin Van Treese",