kitcn 0.12.27 → 0.13.1

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 (73) hide show
  1. package/dist/aggregate/index.d.ts +1 -1
  2. package/dist/aggregate/index.js +1 -1
  3. package/dist/auth/client/index.d.ts +312 -4
  4. package/dist/auth/client/index.js +17 -5
  5. package/dist/auth/config/index.d.ts +1 -1
  6. package/dist/auth/generated/index.d.ts +1 -1
  7. package/dist/auth/generated/index.js +1 -1
  8. package/dist/auth/http/index.d.ts +12 -9
  9. package/dist/auth/http/index.js +35 -6
  10. package/dist/auth/index.d.ts +292 -8
  11. package/dist/auth/index.js +29 -23
  12. package/dist/auth/nextjs/index.d.ts +4 -3
  13. package/dist/auth/nextjs/index.js +9 -4
  14. package/dist/auth/start/index.d.ts +13 -3
  15. package/dist/auth/start/index.js +97 -8
  16. package/dist/{backend-core-DqCCa0nr.mjs → backend-core-yq-eWLRJ.mjs} +140 -54
  17. package/dist/{builder-Cb6gloDB.js → builder-DBgto1yn.js} +4 -3
  18. package/dist/{caller-factory-cTXNvYdz.js → caller-factory-NEfgD5E0.js} +3 -3
  19. package/dist/cli.mjs +26 -26
  20. package/dist/convex-plugin-C3N9BB-J.js +275 -0
  21. package/dist/convex-plugin-tWTDqoKJ.mjs +276 -0
  22. package/dist/{create-schema-orm-DOyiNDCx.js → create-schema-orm-B3f2Kc8O.js} +1 -1
  23. package/dist/crpc/index.d.ts +2 -2
  24. package/dist/crpc/index.js +3 -3
  25. package/dist/{customFunctions-C0voKmtx.js → customFunctions-DxEEO4Dq.js} +2 -1
  26. package/dist/{generated-contract-disabled-21YxPk5W.d.ts → generated-contract-disabled-C_-KWRfT.d.ts} +4 -2
  27. package/dist/{http-types-BLFA9zS7.d.ts → http-types-zsMHb_QN.d.ts} +2 -2
  28. package/dist/{middleware-DkIhQXwg.js → middleware-Bg-PdtrI.js} +1 -1
  29. package/dist/{middleware-nS_qXecO.d.ts → middleware-DrtexzF3.d.ts} +1 -1
  30. package/dist/orm/index.d.ts +3 -3
  31. package/dist/orm/index.js +3 -3
  32. package/dist/plugins/index.d.ts +1 -1
  33. package/dist/plugins/index.js +1 -1
  34. package/dist/{procedure-caller-AjLfkHyF.js → procedure-caller-DplSC7Us.js} +2 -2
  35. package/dist/{procedure-name-D-fDCBlo.d.ts → procedure-name-BCRBr6Po.d.ts} +3 -3
  36. package/dist/ratelimit/index.d.ts +2 -2
  37. package/dist/ratelimit/index.js +3 -3
  38. package/dist/react/index.d.ts +18 -14
  39. package/dist/react/index.js +14 -27
  40. package/dist/rsc/index.d.ts +4 -4
  41. package/dist/rsc/index.js +4 -4
  42. package/dist/{runtime-CtvJPkur.js → runtime-i6t-HoZn.js} +1 -1
  43. package/dist/server/index.d.ts +4 -4
  44. package/dist/server/index.js +4 -4
  45. package/dist/solid/index.d.ts +300 -4
  46. package/dist/token-B9Bjcqug.d.ts +13 -0
  47. package/dist/token-tpipF-7y.js +47 -0
  48. package/dist/{types-C6pQrnzD.d.ts → types-YHpe0rsb.d.ts} +1 -1
  49. package/dist/upstream-BR6sBLg3.js +84 -0
  50. package/dist/upstream-BUCdbLok.mjs +26 -0
  51. package/dist/{validators-B7oIJCAp.js → validators-C7LelqTN.js} +2 -84
  52. package/dist/watcher.mjs +1 -1
  53. package/dist/{where-clause-compiler-DdjN63Io.d.ts → where-clause-compiler-TMppDl9g.d.ts} +51 -51
  54. package/package.json +5 -4
  55. package/skills/convex/references/features/auth.md +20 -0
  56. package/skills/convex/references/features/orm.md +9 -0
  57. package/skills/convex/references/setup/auth.md +2 -0
  58. package/skills/convex/references/setup/index.md +5 -5
  59. package/skills/convex/references/setup/server.md +1 -1
  60. /package/dist/{api-entry-BUAh_K4k.js → api-entry-N3nBOlI2.js} +0 -0
  61. /package/dist/{context-utils-BvWW0Ilq.d.ts → context-utils-OMkMGhBk.d.ts} +0 -0
  62. /package/dist/{create-schema-odyF4kCy.js → create-schema-BXrKE2YY.js} +0 -0
  63. /package/dist/{error-BZEnI7Sq.js → error-Bvo7YEhk.js} +0 -0
  64. /package/dist/{generated-contract-disabled-Cih4eITO.js → generated-contract-disabled-BXaz7JCE.js} +0 -0
  65. /package/dist/{meta-utils-0Pu0Nrap.js → meta-utils-D9K4fICl.js} +0 -0
  66. /package/dist/{query-context-CFZqIvD7.d.ts → query-context-CNo9ffvI.d.ts} +0 -0
  67. /package/dist/{query-context-B8o6-8kC.js → query-context-ydn9kb6P.js} +0 -0
  68. /package/dist/{query-options-Dw7cOyXl.js → query-options-C96zLANM.js} +0 -0
  69. /package/dist/{transformer-DtDhR3Lc.js → transformer-C6pGVHqx.js} +0 -0
  70. /package/dist/{types-BiJE7qxR.d.ts → types-BCl8gfGy.d.ts} +0 -0
  71. /package/dist/{types-a-RHmrDZ.d.ts → types-CnTpHR1F.d.ts} +0 -0
  72. /package/dist/{types-BTb_4BaU.d.ts → types-DF2cg_w0.d.ts} +0 -0
  73. /package/dist/{validators-vzRKjBJC.d.ts → validators-BhsByJeg.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial, dn as ConvexTableWithColumns, tr as ConvexTextBuilderInitial } from "../where-clause-compiler-DdjN63Io.js";
1
+ import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial, dn as ConvexTableWithColumns, tr as ConvexTextBuilderInitial } from "../where-clause-compiler-TMppDl9g.js";
2
2
  import * as convex_values0 from "convex/values";
3
3
  import { GenericId, Infer, Value } from "convex/values";
4
4
  import { DocumentByName, GenericDataModel, GenericDatabaseReader, GenericDatabaseWriter, TableNamesInDataModel } from "convex/server";
@@ -1,4 +1,4 @@
1
- import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-CtvJPkur.js";
1
+ import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-i6t-HoZn.js";
2
2
 
3
3
  //#region src/aggregate/index.ts
4
4
  const wrapTriggerFactory = (methodName, factory) => ((...args) => {
@@ -1,15 +1,323 @@
1
1
  'use client';
2
- import { convexClient } from "@convex-dev/better-auth/client/plugins";
3
2
  import { ConvexReactClient } from "convex/react";
4
3
  import { ReactNode } from "react";
5
4
  import * as react_jsx_runtime0 from "react/jsx-runtime";
6
- import { AuthClient, AuthClient as AuthClient$1 } from "@convex-dev/better-auth/react";
5
+ import { AuthConfig } from "convex/server";
6
+ import * as better_auth0 from "better-auth";
7
+ import { BetterAuthClientPlugin, Session, User } from "better-auth";
8
+ import * as better_auth_api0 from "better-auth/api";
9
+ import * as better_auth_plugins_oidc_provider0 from "better-auth/plugins/oidc-provider";
10
+ import * as jose from "jose";
11
+ import { BetterAuthOptions } from "better-auth/minimal";
12
+ import { createAuthClient } from "better-auth/react";
7
13
 
14
+ //#region src/auth/internal/convex-plugin.d.ts
15
+ declare const convex: (opts: {
16
+ authConfig: AuthConfig;
17
+ jwks?: string;
18
+ jwksRotateOnTokenGenerationError?: boolean;
19
+ jwt?: {
20
+ definePayload?: (session: {
21
+ session: Session & Record<string, any>;
22
+ user: User & Record<string, any>;
23
+ }) => Promise<Record<string, any>> | Record<string, any> | undefined;
24
+ expirationSeconds?: number;
25
+ };
26
+ /**
27
+ * @deprecated Use jwt.expirationSeconds instead.
28
+ */
29
+ jwtExpirationSeconds?: number;
30
+ options?: BetterAuthOptions;
31
+ }) => {
32
+ id: "convex";
33
+ init: (ctx: better_auth0.AuthContext) => void;
34
+ hooks: {
35
+ before: ({
36
+ matcher(context: better_auth0.HookEndpointContext): boolean;
37
+ handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<{
38
+ context: {
39
+ headers: Headers;
40
+ };
41
+ } | undefined>;
42
+ } | {
43
+ matcher: (ctx: better_auth0.HookEndpointContext) => boolean;
44
+ handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<{
45
+ context: better_auth0.MiddlewareContext<better_auth0.MiddlewareOptions, {
46
+ returned?: unknown | undefined;
47
+ responseHeaders?: Headers | undefined;
48
+ } & better_auth0.PluginContext<BetterAuthOptions> & better_auth0.InfoContext & {
49
+ options: BetterAuthOptions;
50
+ trustedOrigins: string[];
51
+ trustedProviders: string[];
52
+ isTrustedOrigin: (url: string, settings?: {
53
+ allowRelativePaths: boolean;
54
+ }) => boolean;
55
+ oauthConfig: {
56
+ skipStateCookieCheck?: boolean | undefined;
57
+ storeStateStrategy: "database" | "cookie";
58
+ };
59
+ newSession: {
60
+ session: {
61
+ id: string;
62
+ createdAt: Date;
63
+ updatedAt: Date;
64
+ userId: string;
65
+ expiresAt: Date;
66
+ token: string;
67
+ ipAddress?: string | null | undefined;
68
+ userAgent?: string | null | undefined;
69
+ } & Record<string, any>;
70
+ user: {
71
+ id: string;
72
+ createdAt: Date;
73
+ updatedAt: Date;
74
+ email: string;
75
+ emailVerified: boolean;
76
+ name: string;
77
+ image?: string | null | undefined;
78
+ } & Record<string, any>;
79
+ } | null;
80
+ session: {
81
+ session: {
82
+ id: string;
83
+ createdAt: Date;
84
+ updatedAt: Date;
85
+ userId: string;
86
+ expiresAt: Date;
87
+ token: string;
88
+ ipAddress?: string | null | undefined;
89
+ userAgent?: string | null | undefined;
90
+ } & Record<string, any>;
91
+ user: {
92
+ id: string;
93
+ createdAt: Date;
94
+ updatedAt: Date;
95
+ email: string;
96
+ emailVerified: boolean;
97
+ name: string;
98
+ image?: string | null | undefined;
99
+ } & Record<string, any>;
100
+ } | null;
101
+ setNewSession: (session: {
102
+ session: {
103
+ id: string;
104
+ createdAt: Date;
105
+ updatedAt: Date;
106
+ userId: string;
107
+ expiresAt: Date;
108
+ token: string;
109
+ ipAddress?: string | null | undefined;
110
+ userAgent?: string | null | undefined;
111
+ } & Record<string, any>;
112
+ user: {
113
+ id: string;
114
+ createdAt: Date;
115
+ updatedAt: Date;
116
+ email: string;
117
+ emailVerified: boolean;
118
+ name: string;
119
+ image?: string | null | undefined;
120
+ } & Record<string, any>;
121
+ } | null) => void;
122
+ socialProviders: better_auth0.OAuthProvider[];
123
+ authCookies: better_auth0.BetterAuthCookies;
124
+ logger: ReturnType<(options?: better_auth0.Logger | undefined) => better_auth0.InternalLogger>;
125
+ rateLimit: {
126
+ enabled: boolean;
127
+ window: number;
128
+ max: number;
129
+ storage: "memory" | "database" | "secondary-storage";
130
+ } & Omit<better_auth0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
131
+ adapter: better_auth0.DBAdapter<BetterAuthOptions>;
132
+ internalAdapter: better_auth0.InternalAdapter<BetterAuthOptions>;
133
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_auth0.CookieOptions> | undefined) => better_auth0.BetterAuthCookie;
134
+ secret: string;
135
+ secretConfig: string | better_auth0.SecretConfig;
136
+ sessionConfig: {
137
+ updateAge: number;
138
+ expiresIn: number;
139
+ freshAge: number;
140
+ cookieRefreshCache: false | {
141
+ enabled: true;
142
+ updateAge: number;
143
+ };
144
+ };
145
+ generateId: (options: {
146
+ model: better_auth0.ModelNames;
147
+ size?: number | undefined;
148
+ }) => string | false;
149
+ secondaryStorage: better_auth0.SecondaryStorage | undefined;
150
+ password: {
151
+ hash: (password: string) => Promise<string>;
152
+ verify: (data: {
153
+ password: string;
154
+ hash: string;
155
+ }) => Promise<boolean>;
156
+ config: {
157
+ minPasswordLength: number;
158
+ maxPasswordLength: number;
159
+ };
160
+ checkPassword: (userId: string, ctx: better_auth0.GenericEndpointContext<BetterAuthOptions>) => Promise<boolean>;
161
+ };
162
+ tables: better_auth0.BetterAuthDBSchema;
163
+ runMigrations: () => Promise<void>;
164
+ publishTelemetry: (event: {
165
+ type: string;
166
+ anonymousId?: string | undefined;
167
+ payload: Record<string, any>;
168
+ }) => Promise<void>;
169
+ skipOriginCheck: boolean | string[];
170
+ skipCSRFCheck: boolean;
171
+ runInBackground: (promise: Promise<unknown>) => void;
172
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => better_auth0.Awaitable<unknown>;
173
+ }>;
174
+ }>;
175
+ })[];
176
+ after: {
177
+ matcher: (context: better_auth0.HookEndpointContext) => boolean;
178
+ handler: better_auth_api0.AuthMiddleware;
179
+ }[];
180
+ };
181
+ endpoints: {
182
+ getOpenIdConfig: better_auth0.StrictEndpoint<"/convex/.well-known/openid-configuration", {
183
+ method: "GET";
184
+ metadata: {
185
+ isAction: false;
186
+ };
187
+ }, better_auth_plugins_oidc_provider0.OIDCMetadata>;
188
+ getJwks: better_auth0.StrictEndpoint<"/convex/jwks", {
189
+ method: "GET";
190
+ metadata: {
191
+ openapi: {
192
+ description: string;
193
+ responses: {
194
+ '200': {
195
+ description: string;
196
+ };
197
+ };
198
+ };
199
+ };
200
+ }, jose.JSONWebKeySet>;
201
+ getLatestJwks: better_auth0.StrictEndpoint<"/convex/latest-jwks", {
202
+ isAction: boolean;
203
+ method: "POST";
204
+ metadata: {
205
+ SERVER_ONLY: true;
206
+ openapi: {
207
+ description: string;
208
+ };
209
+ };
210
+ }, any[]>;
211
+ rotateKeys: better_auth0.StrictEndpoint<"/convex/rotate-keys", {
212
+ isAction: boolean;
213
+ method: "POST";
214
+ metadata: {
215
+ SERVER_ONLY: true;
216
+ openapi: {
217
+ description: string;
218
+ };
219
+ };
220
+ }, any[]>;
221
+ getToken: better_auth0.StrictEndpoint<"/convex/token", {
222
+ method: "GET";
223
+ requireHeaders: true;
224
+ use: ((inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<{
225
+ session: {
226
+ session: Record<string, any> & {
227
+ id: string;
228
+ createdAt: Date;
229
+ updatedAt: Date;
230
+ userId: string;
231
+ expiresAt: Date;
232
+ token: string;
233
+ ipAddress?: string | null | undefined;
234
+ userAgent?: string | null | undefined;
235
+ };
236
+ user: Record<string, any> & {
237
+ id: string;
238
+ createdAt: Date;
239
+ updatedAt: Date;
240
+ email: string;
241
+ emailVerified: boolean;
242
+ name: string;
243
+ image?: string | null | undefined;
244
+ };
245
+ };
246
+ }>)[];
247
+ metadata: {
248
+ openapi: {
249
+ description: string;
250
+ };
251
+ };
252
+ }, {
253
+ token: string;
254
+ }>;
255
+ };
256
+ schema: {
257
+ jwks: {
258
+ fields: {
259
+ publicKey: {
260
+ type: "string";
261
+ required: true;
262
+ };
263
+ privateKey: {
264
+ type: "string";
265
+ required: true;
266
+ };
267
+ createdAt: {
268
+ type: "date";
269
+ required: true;
270
+ };
271
+ expiresAt: {
272
+ type: "date";
273
+ required: false;
274
+ };
275
+ };
276
+ };
277
+ user: {
278
+ readonly fields: {
279
+ readonly userId: {
280
+ readonly type: "string";
281
+ readonly required: false;
282
+ readonly input: false;
283
+ };
284
+ };
285
+ };
286
+ };
287
+ };
288
+ //#endregion
289
+ //#region src/auth/internal/convex-client.d.ts
290
+ declare const convexClient: () => {
291
+ id: "convex";
292
+ $InferServerPlugin: ReturnType<typeof convex>;
293
+ };
294
+ //#endregion
295
+ //#region src/auth-client/types.d.ts
296
+ type ConvexClient = ReturnType<typeof convexClient>;
297
+ type CrossDomainClient = BetterAuthClientPlugin & {
298
+ id: 'cross-domain';
299
+ getActions: (...args: never[]) => {
300
+ crossDomain: {
301
+ oneTimeToken: {
302
+ verify: (args: unknown) => Promise<unknown>;
303
+ };
304
+ };
305
+ getCookie: () => string;
306
+ notifySessionSignal: () => void;
307
+ };
308
+ };
309
+ type PluginsWithCrossDomain = (CrossDomainClient | ConvexClient | BetterAuthClientPlugin)[];
310
+ type PluginsWithoutCrossDomain = (ConvexClient | BetterAuthClientPlugin)[];
311
+ type AuthClientWithPlugins<Plugins extends PluginsWithCrossDomain | PluginsWithoutCrossDomain> = ReturnType<typeof createAuthClient<BetterAuthClientPlugin & {
312
+ plugins: Plugins;
313
+ }>>;
314
+ type AuthClient = AuthClientWithPlugins<PluginsWithCrossDomain> | AuthClientWithPlugins<PluginsWithoutCrossDomain>;
315
+ //#endregion
8
316
  //#region src/auth-client/convex-auth-provider.d.ts
9
317
  type ConvexAuthProviderProps = {
10
318
  children: ReactNode; /** Convex client instance */
11
319
  client: ConvexReactClient; /** Better Auth client instance */
12
- authClient: AuthClient$1; /** Initial session token (from SSR) */
320
+ authClient: AuthClient; /** Initial session token (from SSR) */
13
321
  initialToken?: string; /** Callback when mutation called while unauthorized */
14
322
  onMutationUnauthorized?: () => void; /** Callback when query called while unauthorized */
15
323
  onQueryUnauthorized?: (info: {
@@ -34,4 +342,4 @@ declare function ConvexAuthProvider({
34
342
  isUnauthorized
35
343
  }: ConvexAuthProviderProps): react_jsx_runtime0.JSX.Element;
36
344
  //#endregion
37
- export { type AuthClient, ConvexAuthProvider, ConvexAuthProviderProps, convexClient };
345
+ export { type AuthClient, type AuthClientWithPlugins, ConvexAuthProvider, ConvexAuthProviderProps, type PluginsWithCrossDomain, type PluginsWithoutCrossDomain, convexClient };
@@ -1,10 +1,18 @@
1
1
  'use client';
2
2
  import { C as readAuthSessionFallbackData, D as CRPCClientError, O as defaultIsUnauthorized, S as clearAuthSessionFallback, T as writeAuthSessionFallbackData, d as isSessionSyncGraceActive, g as useAuthValue, h as useAuthStore, n as AuthProvider, o as FetchAccessTokenContext, t as AUTH_SESSION_SYNC_GRACE_MS, u as decodeJwtExp, w as readAuthSessionFallbackToken } from "../../auth-store-CwGbvP_s.js";
3
- import { convexClient } from "@convex-dev/better-auth/client/plugins";
4
3
  import { ConvexProviderWithAuth, useConvexAuth } from "convex/react";
5
4
  import { useCallback, useEffect, useMemo, useRef } from "react";
6
5
  import { jsx } from "react/jsx-runtime";
7
6
 
7
+ //#region src/auth/internal/convex-client.ts
8
+ const convexClient = () => {
9
+ return {
10
+ id: "convex",
11
+ $InferServerPlugin: {}
12
+ };
13
+ };
14
+
15
+ //#endregion
8
16
  //#region src/auth-client/convex-auth-provider.tsx
9
17
  const defaultMutationHandler = () => {
10
18
  throw new CRPCClientError({
@@ -19,17 +27,21 @@ const hasActiveSessionData = (session) => {
19
27
  const wait = (ms) => new Promise((resolve) => {
20
28
  setTimeout(resolve, ms);
21
29
  });
30
+ const readAuthResultData = (result) => {
31
+ if (!result || typeof result !== "object") return;
32
+ return result.data;
33
+ };
22
34
  const getSessionFromPersistedToken = async (authClient, token) => {
23
35
  await wait(250);
24
36
  for (let attempt = 0; attempt < 10; attempt += 1) {
25
- const result = authClient.$fetch ? await authClient.$fetch("/get-session", {
37
+ const data = readAuthResultData(authClient.$fetch ? await authClient.$fetch("/get-session", {
26
38
  credentials: "omit",
27
39
  headers: { Authorization: `Bearer ${token}` }
28
40
  }) : await authClient.getSession?.({ fetchOptions: {
29
41
  credentials: "omit",
30
42
  headers: { Authorization: `Bearer ${token}` }
31
- } });
32
- if (result?.data) return result.data;
43
+ } }));
44
+ if (data) return data;
33
45
  if (attempt < 9) await wait(100);
34
46
  }
35
47
  return null;
@@ -306,7 +318,7 @@ function useOTTHandler(authClient) {
306
318
  url.searchParams.delete("ott");
307
319
  window.history.replaceState({}, "", url);
308
320
  const session = (await authClientWithCrossDomain.crossDomain.oneTimeToken.verify({ token })).data?.session;
309
- if (session) {
321
+ if (session && typeof authClient.getSession === "function") {
310
322
  await authClient.getSession({ fetchOptions: {
311
323
  credentials: "omit",
312
324
  headers: { Authorization: `Bearer ${session.token}` }
@@ -1,4 +1,4 @@
1
- import { JwtOptions } from "better-auth/plugins";
1
+ import { JwtOptions } from "better-auth/plugins/jwt";
2
2
 
3
3
  //#region src/auth/auth-config.d.ts
4
4
  type JwksDoc = {
@@ -1,2 +1,2 @@
1
- import { S as defineAuth, _ as GenericAuthBeforeResult, b as GenericAuthTriggerHandlers, g as BetterAuthOptionsWithoutDatabase, i as getGeneratedAuthDisabledReason, n as GeneratedAuthDisabledReasonKind, r as createDisabledAuthRuntime, t as AuthRuntime, v as GenericAuthDefinition, x as GenericAuthTriggers, y as GenericAuthTriggerChange } from "../../generated-contract-disabled-21YxPk5W.js";
1
+ import { S as defineAuth, _ as GenericAuthBeforeResult, b as GenericAuthTriggerHandlers, g as BetterAuthOptionsWithoutDatabase, i as getGeneratedAuthDisabledReason, n as GeneratedAuthDisabledReasonKind, r as createDisabledAuthRuntime, t as AuthRuntime, v as GenericAuthDefinition, x as GenericAuthTriggers, y as GenericAuthTriggerChange } from "../../generated-contract-disabled-C_-KWRfT.js";
2
2
  export { type AuthRuntime, BetterAuthOptionsWithoutDatabase, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, createDisabledAuthRuntime, defineAuth, getGeneratedAuthDisabledReason };
@@ -1,3 +1,3 @@
1
- import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason } from "../../generated-contract-disabled-Cih4eITO.js";
1
+ import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason } from "../../generated-contract-disabled-BXaz7JCE.js";
2
2
 
3
3
  export { createDisabledAuthRuntime, defineAuth, getGeneratedAuthDisabledReason };
@@ -1,4 +1,4 @@
1
- import { t as GetAuth } from "../../types-BiJE7qxR.js";
1
+ import { t as GetAuth } from "../../types-BCl8gfGy.js";
2
2
  import { HttpRouter } from "convex/server";
3
3
  import { MiddlewareHandler } from "hono";
4
4
  import { BaseURLConfig, BetterAuthOptions } from "better-auth";
@@ -33,6 +33,16 @@ declare function authMiddleware<Ctx = unknown>(getAuth: GetAuth<Ctx, {
33
33
  //#endregion
34
34
  //#region src/auth/registerRoutes.d.ts
35
35
  type TrustedOriginsOption = BetterAuthOptions['trustedOrigins'];
36
+ type RouteCorsOptions = {
37
+ allowedHeaders?: string[];
38
+ allowedOrigins?: string[];
39
+ exposedHeaders?: string[];
40
+ } | boolean;
41
+ type RegisterRoutesOptions = {
42
+ basePath?: string;
43
+ cors?: RouteCorsOptions;
44
+ verbose?: boolean;
45
+ };
36
46
  type AuthRouteContract = {
37
47
  $context: Promise<{
38
48
  options: {
@@ -46,14 +56,7 @@ type AuthRouteContract = {
46
56
  trustedOrigins?: TrustedOriginsOption;
47
57
  };
48
58
  };
49
- declare const registerRoutes: <Ctx>(http: HttpRouter, getAuth: GetAuth<Ctx, AuthRouteContract>, opts?: {
50
- cors?: {
51
- allowedHeaders?: string[];
52
- allowedOrigins?: string[];
53
- exposedHeaders?: string[];
54
- } | boolean;
55
- verbose?: boolean;
56
- }) => void;
59
+ declare const registerRoutes: <Ctx>(http: HttpRouter, getAuth: GetAuth<Ctx, AuthRouteContract>, opts?: RegisterRoutesOptions) => void;
57
60
  //#endregion
58
61
  //#region src/auth-http/index.d.ts
59
62
  /**
@@ -328,6 +328,23 @@ const LOCAL_CONVEX_AUTH_IP_PATHS = new Set([
328
328
  "/convex/jwks",
329
329
  "/convex/token"
330
330
  ]);
331
+ const restoreOriginalForwardedHeaders = (request) => {
332
+ const originalHost = request.headers.get("x-better-auth-forwarded-host");
333
+ const originalProto = request.headers.get("x-better-auth-forwarded-proto");
334
+ if (!originalHost && !originalProto) return request;
335
+ const headers = new Headers(request.headers);
336
+ if (originalHost) headers.set("x-forwarded-host", originalHost);
337
+ if (originalProto) headers.set("x-forwarded-proto", originalProto);
338
+ const init = {
339
+ headers,
340
+ method: request.method
341
+ };
342
+ if (request.method !== "GET" && request.method !== "HEAD") {
343
+ init.body = request.body;
344
+ init.duplex = "half";
345
+ }
346
+ return new Request(request.url, init);
347
+ };
331
348
  const withLocalConvexAuthIp = (request, basePath) => {
332
349
  if (request.headers.get("x-forwarded-for")) return request;
333
350
  let url;
@@ -348,16 +365,15 @@ const withLocalConvexAuthIp = (request, basePath) => {
348
365
  method: request.method
349
366
  });
350
367
  };
351
- const registerRoutes = (http, getAuth, opts = {}) => {
352
- const staticAuth = getAuth({});
353
- const path = staticAuth.options.basePath ?? "/api/auth";
368
+ const registerAuthRoutes = (http, registration, opts = {}) => {
369
+ const { getAuth, getRegistrationAuth, path } = registration;
354
370
  const authRequestHandler = httpActionGeneric(async (ctx, request) => {
355
371
  if (opts?.verbose) {
356
- console.log("options.baseURL", staticAuth.options.baseURL);
372
+ console.log("options.baseURL", getRegistrationAuth().options.baseURL);
357
373
  console.log("request headers", request.headers);
358
374
  }
359
375
  const auth = getAuth(ctx);
360
- const authRequest = withLocalConvexAuthIp(request, path);
376
+ const authRequest = restoreOriginalForwardedHeaders(withLocalConvexAuthIp(request, path));
361
377
  let response;
362
378
  try {
363
379
  response = await auth.handler(authRequest);
@@ -407,7 +423,7 @@ const registerRoutes = (http, getAuth, opts = {}) => {
407
423
  enforceAllowOrigins: false,
408
424
  exposedHeaders: ["Set-Better-Auth-Cookie"].concat(corsOpts.exposedHeaders ?? []),
409
425
  allowedOrigins: async (request) => {
410
- const resolvedTrustedOrigins = trustedOriginsOption ?? (await staticAuth.$context).options.trustedOrigins ?? [];
426
+ const resolvedTrustedOrigins = trustedOriginsOption ?? (await getRegistrationAuth().$context).options.trustedOrigins ?? [];
411
427
  trustedOriginsOption = resolvedTrustedOrigins;
412
428
  return (Array.isArray(resolvedTrustedOrigins) ? resolvedTrustedOrigins : await resolvedTrustedOrigins(request) ?? []).filter((origin) => typeof origin === "string").map((origin) => origin.endsWith("*") && origin.length > 1 ? origin.slice(0, -1) : origin).concat(corsOpts.allowedOrigins ?? []);
413
429
  }
@@ -423,6 +439,19 @@ const registerRoutes = (http, getAuth, opts = {}) => {
423
439
  pathPrefix: `${path}/`
424
440
  });
425
441
  };
442
+ const registerRoutes = (http, getAuth, opts = {}) => {
443
+ return registerAuthRoutes(http, {
444
+ getAuth,
445
+ getRegistrationAuth: (() => {
446
+ let registrationAuth;
447
+ return () => {
448
+ registrationAuth ??= getAuth({});
449
+ return registrationAuth;
450
+ };
451
+ })(),
452
+ path: opts.basePath ?? "/api/auth"
453
+ }, opts);
454
+ };
426
455
 
427
456
  //#endregion
428
457
  //#region src/auth-http/index.ts