@xylex-group/athena 2.12.1 → 2.13.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.
Files changed (96) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1190 -1184
  3. package/bin/athena-js.js +104 -76
  4. package/dist/admin.cjs +45 -0
  5. package/dist/admin.cjs.map +1 -0
  6. package/dist/admin.d.cts +64 -0
  7. package/dist/admin.d.ts +64 -0
  8. package/dist/admin.js +41 -0
  9. package/dist/admin.js.map +1 -0
  10. package/dist/athena-auth-url-oLux_57a.d.cts +377 -0
  11. package/dist/athena-auth-url-oLux_57a.d.ts +377 -0
  12. package/dist/browser.cjs +33 -49
  13. package/dist/browser.cjs.map +1 -1
  14. package/dist/browser.d.cts +12 -10
  15. package/dist/browser.d.ts +12 -10
  16. package/dist/browser.js +33 -49
  17. package/dist/browser.js.map +1 -1
  18. package/dist/cli/index.cjs +150 -51
  19. package/dist/cli/index.cjs.map +1 -1
  20. package/dist/cli/index.d.cts +14 -5
  21. package/dist/cli/index.d.ts +14 -5
  22. package/dist/cli/index.js +150 -52
  23. package/dist/cli/index.js.map +1 -1
  24. package/dist/{client-CMtx5P4D.d.cts → client-BJjUwDSg.d.cts} +109 -1448
  25. package/dist/{client-Dre8H24u.d.ts → client-DVOKSYDI.d.ts} +109 -1448
  26. package/dist/cookies.cjs +18 -0
  27. package/dist/cookies.cjs.map +1 -1
  28. package/dist/cookies.d.cts +2 -1
  29. package/dist/cookies.d.ts +2 -1
  30. package/dist/cookies.js +17 -1
  31. package/dist/cookies.js.map +1 -1
  32. package/dist/{index-CVcQCGyG.d.ts → index-CFL9xbFR.d.cts} +2 -0
  33. package/dist/{index-CVcQCGyG.d.cts → index-UKJpunc6.d.ts} +2 -0
  34. package/dist/index.cjs +101 -49
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +13 -10
  37. package/dist/index.d.ts +13 -10
  38. package/dist/index.js +101 -50
  39. package/dist/index.js.map +1 -1
  40. package/dist/{model-form-DfTi8-D1.d.cts → model-form-Dw4zEL5a.d.cts} +2 -2
  41. package/dist/{model-form-CU0mWrF9.d.ts → model-form-yRg71q3H.d.ts} +2 -2
  42. package/dist/{module-DBGmbIuh.d.ts → module-DBteUIob.d.ts} +12 -9
  43. package/dist/{module-GoijrBXV.d.cts → module-yoX49uQC.d.cts} +12 -9
  44. package/dist/next/client.cjs +452 -49
  45. package/dist/next/client.cjs.map +1 -1
  46. package/dist/next/client.d.cts +7 -4
  47. package/dist/next/client.d.ts +7 -4
  48. package/dist/next/client.js +430 -50
  49. package/dist/next/client.js.map +1 -1
  50. package/dist/next/server.cjs +292 -49
  51. package/dist/next/server.cjs.map +1 -1
  52. package/dist/next/server.d.cts +81 -5
  53. package/dist/next/server.d.ts +81 -5
  54. package/dist/next/server.js +280 -50
  55. package/dist/next/server.js.map +1 -1
  56. package/dist/organization.cjs +72 -0
  57. package/dist/organization.cjs.map +1 -0
  58. package/dist/organization.d.cts +43 -0
  59. package/dist/organization.d.ts +43 -0
  60. package/dist/organization.js +70 -0
  61. package/dist/organization.js.map +1 -0
  62. package/dist/payload-BzVbUgY_.d.cts +219 -0
  63. package/dist/payload-DEOWN_oo.d.ts +219 -0
  64. package/dist/{pipeline-DrjU2vNA.d.ts → pipeline-Bj6RWt1A.d.ts} +1 -1
  65. package/dist/{pipeline-c7Gdm0qv.d.cts → pipeline-Dwck-wZO.d.cts} +1 -1
  66. package/dist/react.cjs +2 -13
  67. package/dist/react.cjs.map +1 -1
  68. package/dist/react.d.cts +26 -7
  69. package/dist/react.d.ts +26 -7
  70. package/dist/react.js +2 -13
  71. package/dist/react.js.map +1 -1
  72. package/dist/session-cookie-detection-BqOp9mO6.d.cts +46 -0
  73. package/dist/session-cookie-detection-BqOp9mO6.d.ts +46 -0
  74. package/dist/social-providers.cjs +4189 -0
  75. package/dist/social-providers.cjs.map +1 -0
  76. package/dist/social-providers.d.cts +4948 -0
  77. package/dist/social-providers.d.ts +4948 -0
  78. package/dist/social-providers.js +4117 -0
  79. package/dist/social-providers.js.map +1 -0
  80. package/dist/{types-Bez4HSbI.d.cts → types-BRP7sfSF.d.ts} +50 -2
  81. package/dist/{types-kPaHUqUa.d.ts → types-BU8uJH_b.d.cts} +50 -2
  82. package/dist/{types-BRUHGXo2.d.ts → types-CH78O90i.d.cts} +2 -2
  83. package/dist/{types-BRUHGXo2.d.cts → types-CH78O90i.d.ts} +2 -2
  84. package/dist/{types-BLizCLd1.d.cts → types-CjC9_5ZQ.d.cts} +3 -3
  85. package/dist/{types-DRRb0Fd0.d.ts → types-DPgejxYC.d.ts} +3 -3
  86. package/dist/types-eAKAh71s.d.cts +1476 -0
  87. package/dist/types-eAKAh71s.d.ts +1476 -0
  88. package/dist/utils.cjs +438 -15
  89. package/dist/utils.cjs.map +1 -1
  90. package/dist/utils.d.cts +76 -11
  91. package/dist/utils.d.ts +76 -11
  92. package/dist/utils.js +390 -16
  93. package/dist/utils.js.map +1 -1
  94. package/package.json +49 -22
  95. package/dist/shared-DZSGAmXs.d.cts +0 -35
  96. package/dist/shared-MMnVBBfy.d.ts +0 -35
@@ -1,7 +1,83 @@
1
- import { an as AthenaAuthSessionResponse, bI as AthenaClientSessionLike, cA as AthenaSdkClientWithStorage, cz as AthenaSdkClientWithAuth } from '../client-CMtx5P4D.cjs';
2
- import { A as AthenaAdapterBaseOptions, b as AthenaServerRequestOptions, a as AthenaAdapterExperimentalOptions } from '../shared-DZSGAmXs.cjs';
3
- import '../types-BRUHGXo2.cjs';
4
- import '../types-Bez4HSbI.cjs';
1
+ import { al as AthenaClientSessionLike, aX as AthenaSdkClientWithStorage, aW as AthenaSdkClientWithAuth } from '../client-BJjUwDSg.cjs';
2
+ import { ae as AthenaAuthSessionResponse } from '../types-eAKAh71s.cjs';
3
+ import { i as AthenaAuthSessionBridgeOptions, j as AthenaAuthSessionBridgePathOptions, A as AthenaAdapterBaseOptions, k as AthenaServerRequestOptions, a as AthenaAdapterExperimentalOptions } from '../payload-BzVbUgY_.cjs';
4
+ export { b as ATHENA_AUTH_SESSION_BRIDGE_ROUTE, c as ATHENA_AUTH_SESSION_COOKIE_NAME, d as ATHENA_AUTH_SESSION_COOKIE_NAMES, e as AthenaAuthSessionBridgeClientOptions, f as AthenaAuthSessionBridgePayload, g as AthenaAuthSessionBridgeSource, h as clearAthenaAuthSessionOnAppHost, p as persistAthenaAuthSessionOnAppHost, r as resolveSessionBridgePayload } from '../payload-BzVbUgY_.cjs';
5
+ export { S as SESSION_COOKIE_PATTERNS, h as hasAuthSessionCookie } from '../session-cookie-detection-BqOp9mO6.cjs';
6
+ import '../types-CH78O90i.cjs';
7
+ import '../types-BU8uJH_b.cjs';
8
+
9
+ /**
10
+ * Handle bridge `POST` — set an httpOnly session cookie from JSON body.
11
+ *
12
+ * Expected body: `{ "token": string, "expiresAt"?: string }`.
13
+ *
14
+ * @param request - Incoming request (JSON body)
15
+ * @param options - Cookie / route configuration
16
+ * @returns `200` on success, `400` when token is missing
17
+ */
18
+ declare function handleAthenaAuthSessionBridgePost(request: Request, options?: AthenaAuthSessionBridgeOptions): Promise<Response>;
19
+ /**
20
+ * Handle bridge `DELETE` — clear bridged session cookie name variants.
21
+ *
22
+ * @param request - Incoming request (used for Secure detection)
23
+ * @param options - Cookie / route configuration
24
+ * @returns `200` with clear `Set-Cookie` headers
25
+ */
26
+ declare function handleAthenaAuthSessionBridgeDelete(request: Request, options?: AthenaAuthSessionBridgeOptions): Response;
27
+ /**
28
+ * Create dedicated App Router handlers for the session bridge.
29
+ *
30
+ * Drop into a route file with no additional wiring:
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // app/api/athena-auth/session/route.ts
35
+ * import { createAthenaAuthSessionBridgeHandlers } from '@xylex-group/athena/next/server'
36
+ *
37
+ * export const { POST, DELETE } = createAthenaAuthSessionBridgeHandlers()
38
+ * ```
39
+ *
40
+ * @param options - Optional cookie name, path, SameSite, Secure overrides
41
+ * @returns Object with `POST` and `DELETE` route handlers
42
+ */
43
+ declare function createAthenaAuthSessionBridgeHandlers(options?: AthenaAuthSessionBridgeOptions): {
44
+ POST: (request: Request) => Promise<Response>;
45
+ DELETE: (request: Request) => Response;
46
+ };
47
+ /**
48
+ * Whether this request should be handled as a session bridge call.
49
+ *
50
+ * Returns true when:
51
+ * - the pathname equals the configured `route`, or
52
+ * - the final path segment is listed in `matchPaths` (default `session`)
53
+ *
54
+ * @param request - Incoming request
55
+ * @param options - Route + matchPaths configuration
56
+ */
57
+ declare function isAthenaAuthSessionBridgePath(request: Request, options?: AthenaAuthSessionBridgePathOptions): boolean;
58
+ /**
59
+ * Create catch-all / `[path]` handlers that only service session-bridge paths.
60
+ *
61
+ * Non-matching paths return `404` with `{ error: 'Not found' }` so you can
62
+ * mount under `/api/auth/[...path]` without implementing a full auth proxy.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * // app/api/auth/[...path]/route.ts
67
+ * import { createAthenaAuthSessionBridgePathHandlers } from '@xylex-group/athena/next/server'
68
+ *
69
+ * export const { POST, DELETE } = createAthenaAuthSessionBridgePathHandlers({
70
+ * route: '/api/auth/session',
71
+ * })
72
+ * ```
73
+ *
74
+ * @param options - Bridge options plus `matchPaths`
75
+ * @returns Object with `POST` and `DELETE` route handlers
76
+ */
77
+ declare function createAthenaAuthSessionBridgePathHandlers(options?: AthenaAuthSessionBridgePathOptions): {
78
+ POST: (request: Request) => Promise<Response>;
79
+ DELETE: (request: Request) => Response;
80
+ };
5
81
 
6
82
  interface AthenaServerClientOptions extends AthenaAdapterBaseOptions, AthenaServerRequestOptions {
7
83
  session?: AthenaClientSessionLike | AthenaAuthSessionResponse | null;
@@ -50,4 +126,4 @@ declare function resolveAthenaServerContext(options: AthenaServerContextOptionsW
50
126
  declare function resolveAthenaServerContext(options: AthenaServerContextOptionsWithTypecheckedColumns): Promise<AthenaResolvedServerContext<AthenaSdkClientWithAuth<true>>>;
51
127
  declare function resolveAthenaServerContext(options?: AthenaServerContextOptions): Promise<AthenaResolvedServerContext<AthenaSdkClientWithAuth<false>>>;
52
128
 
53
- export { type AthenaResolvedServerContext, type AthenaServerClientOptions, type AthenaServerContextOptions, createAthenaServerClient, resolveAthenaServerContext };
129
+ export { AthenaAuthSessionBridgeOptions, AthenaAuthSessionBridgePathOptions, type AthenaResolvedServerContext, type AthenaServerClientOptions, type AthenaServerContextOptions, createAthenaAuthSessionBridgeHandlers, createAthenaAuthSessionBridgePathHandlers, createAthenaServerClient, handleAthenaAuthSessionBridgeDelete, handleAthenaAuthSessionBridgePost, isAthenaAuthSessionBridgePath, resolveAthenaServerContext };
@@ -1,7 +1,83 @@
1
- import { an as AthenaAuthSessionResponse, bI as AthenaClientSessionLike, cA as AthenaSdkClientWithStorage, cz as AthenaSdkClientWithAuth } from '../client-Dre8H24u.js';
2
- import { A as AthenaAdapterBaseOptions, b as AthenaServerRequestOptions, a as AthenaAdapterExperimentalOptions } from '../shared-MMnVBBfy.js';
3
- import '../types-BRUHGXo2.js';
4
- import '../types-kPaHUqUa.js';
1
+ import { al as AthenaClientSessionLike, aX as AthenaSdkClientWithStorage, aW as AthenaSdkClientWithAuth } from '../client-DVOKSYDI.js';
2
+ import { ae as AthenaAuthSessionResponse } from '../types-eAKAh71s.js';
3
+ import { i as AthenaAuthSessionBridgeOptions, j as AthenaAuthSessionBridgePathOptions, A as AthenaAdapterBaseOptions, k as AthenaServerRequestOptions, a as AthenaAdapterExperimentalOptions } from '../payload-DEOWN_oo.js';
4
+ export { b as ATHENA_AUTH_SESSION_BRIDGE_ROUTE, c as ATHENA_AUTH_SESSION_COOKIE_NAME, d as ATHENA_AUTH_SESSION_COOKIE_NAMES, e as AthenaAuthSessionBridgeClientOptions, f as AthenaAuthSessionBridgePayload, g as AthenaAuthSessionBridgeSource, h as clearAthenaAuthSessionOnAppHost, p as persistAthenaAuthSessionOnAppHost, r as resolveSessionBridgePayload } from '../payload-DEOWN_oo.js';
5
+ export { S as SESSION_COOKIE_PATTERNS, h as hasAuthSessionCookie } from '../session-cookie-detection-BqOp9mO6.js';
6
+ import '../types-CH78O90i.js';
7
+ import '../types-BRP7sfSF.js';
8
+
9
+ /**
10
+ * Handle bridge `POST` — set an httpOnly session cookie from JSON body.
11
+ *
12
+ * Expected body: `{ "token": string, "expiresAt"?: string }`.
13
+ *
14
+ * @param request - Incoming request (JSON body)
15
+ * @param options - Cookie / route configuration
16
+ * @returns `200` on success, `400` when token is missing
17
+ */
18
+ declare function handleAthenaAuthSessionBridgePost(request: Request, options?: AthenaAuthSessionBridgeOptions): Promise<Response>;
19
+ /**
20
+ * Handle bridge `DELETE` — clear bridged session cookie name variants.
21
+ *
22
+ * @param request - Incoming request (used for Secure detection)
23
+ * @param options - Cookie / route configuration
24
+ * @returns `200` with clear `Set-Cookie` headers
25
+ */
26
+ declare function handleAthenaAuthSessionBridgeDelete(request: Request, options?: AthenaAuthSessionBridgeOptions): Response;
27
+ /**
28
+ * Create dedicated App Router handlers for the session bridge.
29
+ *
30
+ * Drop into a route file with no additional wiring:
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // app/api/athena-auth/session/route.ts
35
+ * import { createAthenaAuthSessionBridgeHandlers } from '@xylex-group/athena/next/server'
36
+ *
37
+ * export const { POST, DELETE } = createAthenaAuthSessionBridgeHandlers()
38
+ * ```
39
+ *
40
+ * @param options - Optional cookie name, path, SameSite, Secure overrides
41
+ * @returns Object with `POST` and `DELETE` route handlers
42
+ */
43
+ declare function createAthenaAuthSessionBridgeHandlers(options?: AthenaAuthSessionBridgeOptions): {
44
+ POST: (request: Request) => Promise<Response>;
45
+ DELETE: (request: Request) => Response;
46
+ };
47
+ /**
48
+ * Whether this request should be handled as a session bridge call.
49
+ *
50
+ * Returns true when:
51
+ * - the pathname equals the configured `route`, or
52
+ * - the final path segment is listed in `matchPaths` (default `session`)
53
+ *
54
+ * @param request - Incoming request
55
+ * @param options - Route + matchPaths configuration
56
+ */
57
+ declare function isAthenaAuthSessionBridgePath(request: Request, options?: AthenaAuthSessionBridgePathOptions): boolean;
58
+ /**
59
+ * Create catch-all / `[path]` handlers that only service session-bridge paths.
60
+ *
61
+ * Non-matching paths return `404` with `{ error: 'Not found' }` so you can
62
+ * mount under `/api/auth/[...path]` without implementing a full auth proxy.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * // app/api/auth/[...path]/route.ts
67
+ * import { createAthenaAuthSessionBridgePathHandlers } from '@xylex-group/athena/next/server'
68
+ *
69
+ * export const { POST, DELETE } = createAthenaAuthSessionBridgePathHandlers({
70
+ * route: '/api/auth/session',
71
+ * })
72
+ * ```
73
+ *
74
+ * @param options - Bridge options plus `matchPaths`
75
+ * @returns Object with `POST` and `DELETE` route handlers
76
+ */
77
+ declare function createAthenaAuthSessionBridgePathHandlers(options?: AthenaAuthSessionBridgePathOptions): {
78
+ POST: (request: Request) => Promise<Response>;
79
+ DELETE: (request: Request) => Response;
80
+ };
5
81
 
6
82
  interface AthenaServerClientOptions extends AthenaAdapterBaseOptions, AthenaServerRequestOptions {
7
83
  session?: AthenaClientSessionLike | AthenaAuthSessionResponse | null;
@@ -50,4 +126,4 @@ declare function resolveAthenaServerContext(options: AthenaServerContextOptionsW
50
126
  declare function resolveAthenaServerContext(options: AthenaServerContextOptionsWithTypecheckedColumns): Promise<AthenaResolvedServerContext<AthenaSdkClientWithAuth<true>>>;
51
127
  declare function resolveAthenaServerContext(options?: AthenaServerContextOptions): Promise<AthenaResolvedServerContext<AthenaSdkClientWithAuth<false>>>;
52
128
 
53
- export { type AthenaResolvedServerContext, type AthenaServerClientOptions, type AthenaServerContextOptions, createAthenaServerClient, resolveAthenaServerContext };
129
+ export { AthenaAuthSessionBridgeOptions, AthenaAuthSessionBridgePathOptions, type AthenaResolvedServerContext, type AthenaServerClientOptions, type AthenaServerContextOptions, createAthenaAuthSessionBridgeHandlers, createAthenaAuthSessionBridgePathHandlers, createAthenaServerClient, handleAthenaAuthSessionBridgeDelete, handleAthenaAuthSessionBridgePost, isAthenaAuthSessionBridgePath, resolveAthenaServerContext };
@@ -136,6 +136,22 @@ function parseCookies(cookieHeader) {
136
136
  });
137
137
  return cookieMap;
138
138
  }
139
+
140
+ // src/cookies/session-cookie-detection.ts
141
+ var SESSION_COOKIE_PATTERNS = [
142
+ /(?:^|;\s*)(?:__Secure-)?better-auth\.session_token=/,
143
+ /(?:^|;\s*)(?:__Secure-)?better-auth-session_token=/,
144
+ /(?:^|;\s*)(?:__Secure-)?athena-auth\.session-token=/,
145
+ /(?:^|;\s*)(?:__Secure-)?athena-auth-session-token=/,
146
+ /(?:^|;\s*)(?:__Secure-)?athena-auth\.session_token=/,
147
+ /(?:^|;\s*)(?:__Secure-)?athena-auth-session_token=/
148
+ ];
149
+ function hasAuthSessionCookie(cookieHeader) {
150
+ if (!cookieHeader) {
151
+ return false;
152
+ }
153
+ return SESSION_COOKIE_PATTERNS.some((pattern) => pattern.test(cookieHeader));
154
+ }
139
155
  var getSessionCookie = (request2, config) => {
140
156
  const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
141
157
  if (!cookies) {
@@ -160,7 +176,7 @@ var getSessionCookie = (request2, config) => {
160
176
 
161
177
  // src/utils/athena-request-headers.ts
162
178
  var NO_CACHE_HEADER_VALUE = "no-cache";
163
- var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
179
+ var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
164
180
  var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
165
181
  var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
166
182
  var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
@@ -262,17 +278,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
262
278
  });
263
279
  }
264
280
  function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
265
- if (apiKey) {
266
- if (!hasHeaderIgnoreCase(headers, "apikey")) {
267
- headers.apikey = apiKey;
268
- }
269
- if (!Object.hasOwn(headers, "x-api-key")) {
270
- headers["x-api-key"] = apiKey;
271
- }
272
- if (!Object.hasOwn(headers, "X-Api-Key")) {
273
- headers["X-Api-Key"] = apiKey;
274
- }
275
- }
276
281
  const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
277
282
  if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
278
283
  headers["X-Athena-Key"] = resolvedAthenaKey;
@@ -398,7 +403,7 @@ function buildAthenaRequestHeaders(input) {
398
403
 
399
404
  // package.json
400
405
  var package_default = {
401
- version: "2.12.1"
406
+ version: "2.13.0"
402
407
  };
403
408
 
404
409
  // src/sdk-version.ts
@@ -2827,38 +2832,6 @@ async function withRetry(config, fn) {
2827
2832
  throw new Error("withRetry reached an unexpected state");
2828
2833
  }
2829
2834
 
2830
- // src/db/module.ts
2831
- function createDbModule(input) {
2832
- const db = {
2833
- from: input.from,
2834
- select(table, first, second) {
2835
- if (first && typeof first === "object" && !Array.isArray(first)) {
2836
- return input.from(table).select(void 0, first);
2837
- }
2838
- return input.from(table).select(first, second);
2839
- },
2840
- insert(table, values, options) {
2841
- return Array.isArray(values) ? input.from(table).insert(values, options) : input.from(table).insert(values, options);
2842
- },
2843
- upsert(table, values, options) {
2844
- return Array.isArray(values) ? input.from(table).upsert(values, options) : input.from(table).upsert(values, options);
2845
- },
2846
- update(table, values, options) {
2847
- return input.from(table).update(values, options);
2848
- },
2849
- delete(table, options) {
2850
- return input.from(table).delete(options);
2851
- },
2852
- rpc(fn, args, options) {
2853
- return input.rpc(fn, args, options);
2854
- },
2855
- query(query, options) {
2856
- return input.query(query, options);
2857
- }
2858
- };
2859
- return db;
2860
- }
2861
-
2862
2835
  // src/storage/file.ts
2863
2836
  function createStorageFileModule(base, config = {}) {
2864
2837
  const upload = async (input, options) => {
@@ -8437,7 +8410,30 @@ function createClientFromConfig(config, sourceConfig) {
8437
8410
  config.experimental,
8438
8411
  queryTracer
8439
8412
  );
8440
- const db = createDbModule({ from, rpc, query });
8413
+ const untypedDbFrom = from;
8414
+ const db = {
8415
+ from,
8416
+ select(table, first, second) {
8417
+ if (first && typeof first === "object" && !Array.isArray(first)) {
8418
+ return untypedDbFrom(table).select(void 0, first);
8419
+ }
8420
+ return untypedDbFrom(table).select(first, second);
8421
+ },
8422
+ insert(table, values, options) {
8423
+ return Array.isArray(values) ? untypedDbFrom(table).insert(values, options) : untypedDbFrom(table).insert(values, options);
8424
+ },
8425
+ upsert(table, values, options) {
8426
+ return Array.isArray(values) ? untypedDbFrom(table).upsert(values, options) : untypedDbFrom(table).upsert(values, options);
8427
+ },
8428
+ update(table, values, options) {
8429
+ return untypedDbFrom(table).update(values, options);
8430
+ },
8431
+ delete(table, options) {
8432
+ return untypedDbFrom(table).delete(options);
8433
+ },
8434
+ rpc,
8435
+ query
8436
+ };
8441
8437
  const chat = createChatModule({
8442
8438
  baseUrl: config.chatUrl,
8443
8439
  apiKey: config.apiKey,
@@ -8588,7 +8584,9 @@ function createClientFromConfig(config, sourceConfig) {
8588
8584
  var AthenaClient = class {
8589
8585
  /** Create a fluent builder for a strongly-typed Athena SDK client. */
8590
8586
  static builder() {
8591
- return createAthenaClientBuilder((config) => createClientFromInput(config));
8587
+ return createAthenaClientBuilder(
8588
+ (config) => createClientFromInput(config)
8589
+ );
8592
8590
  }
8593
8591
  static fromEnvironment(options = {}) {
8594
8592
  const env = options.env ?? process.env;
@@ -8619,11 +8617,12 @@ var AthenaClient = class {
8619
8617
  });
8620
8618
  }
8621
8619
  };
8622
- function createClient(configOrUrl, apiKey, options) {
8620
+ function createClient(...args) {
8621
+ const [configOrUrl, apiKey, options] = args;
8623
8622
  if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
8624
8623
  return createClientFromInput({
8625
8624
  url: configOrUrl,
8626
- key: "",
8625
+ key: apiKey ?? "",
8627
8626
  ...options
8628
8627
  });
8629
8628
  }
@@ -8759,6 +8758,237 @@ function buildSessionClientOptions(context, options) {
8759
8758
  };
8760
8759
  }
8761
8760
 
8761
+ // src/next/session-bridge/constants.ts
8762
+ var ATHENA_AUTH_SESSION_BRIDGE_ROUTE = "/api/athena-auth/session";
8763
+ var ATHENA_AUTH_SESSION_COOKIE_NAME = "athena-auth.session-token";
8764
+ var ATHENA_AUTH_SESSION_COOKIE_NAMES = [
8765
+ ATHENA_AUTH_SESSION_COOKIE_NAME,
8766
+ "athena-auth.session_token"
8767
+ ];
8768
+
8769
+ // src/next/session-bridge/client.ts
8770
+ var JSON_CONTENT_TYPE = "application/json";
8771
+ function isBrowserRuntime() {
8772
+ return typeof globalThis !== "undefined" && "window" in globalThis;
8773
+ }
8774
+ async function persistAthenaAuthSessionOnAppHost(payload, options) {
8775
+ if (!(payload && isBrowserRuntime())) {
8776
+ return;
8777
+ }
8778
+ const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
8779
+ const fetchImpl = options?.fetch ?? fetch;
8780
+ const response = await fetchImpl(route, {
8781
+ body: JSON.stringify(payload),
8782
+ credentials: "same-origin",
8783
+ headers: {
8784
+ "Content-Type": JSON_CONTENT_TYPE
8785
+ },
8786
+ method: "POST"
8787
+ });
8788
+ if (!response.ok) {
8789
+ throw new Error("Failed to persist the Athena Auth session on the app host");
8790
+ }
8791
+ }
8792
+ async function clearAthenaAuthSessionOnAppHost(options) {
8793
+ if (!isBrowserRuntime()) {
8794
+ return;
8795
+ }
8796
+ const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
8797
+ const fetchImpl = options?.fetch ?? fetch;
8798
+ const response = await fetchImpl(route, {
8799
+ credentials: "same-origin",
8800
+ method: "DELETE"
8801
+ });
8802
+ if (!response.ok) {
8803
+ throw new Error("Failed to clear the Athena Auth session on the app host");
8804
+ }
8805
+ }
8806
+
8807
+ // src/next/session-bridge/payload.ts
8808
+ function resolveSessionBridgePayload(payload) {
8809
+ const token = payload?.session?.token ?? payload?.token;
8810
+ if (typeof token !== "string") {
8811
+ return null;
8812
+ }
8813
+ const normalizedToken = token.trim();
8814
+ if (!normalizedToken) {
8815
+ return null;
8816
+ }
8817
+ return {
8818
+ token: normalizedToken,
8819
+ expiresAt: typeof payload?.session?.expiresAt === "string" ? payload.session.expiresAt : void 0
8820
+ };
8821
+ }
8822
+
8823
+ // src/next/session-bridge/cookie.ts
8824
+ var EXPIRED_AT = /* @__PURE__ */ new Date(0);
8825
+ function resolveRequestIsSecure(request2) {
8826
+ const forwardedProto = request2.headers.get("x-forwarded-proto")?.trim();
8827
+ if (forwardedProto) {
8828
+ const first = forwardedProto.split(",")[0]?.trim().toLowerCase();
8829
+ if (first === "https") return true;
8830
+ if (first === "http") return false;
8831
+ }
8832
+ return new URL(request2.url).protocol === "https:";
8833
+ }
8834
+ function resolveSessionCookieExpiresAt(value) {
8835
+ if (typeof value !== "string") {
8836
+ return void 0;
8837
+ }
8838
+ const expiresAt = new Date(value);
8839
+ return Number.isNaN(expiresAt.getTime()) ? void 0 : expiresAt;
8840
+ }
8841
+ function serializeCookie(name, value, options) {
8842
+ const parts = [
8843
+ `${encodeURIComponent(name)}=${encodeURIComponent(value)}`,
8844
+ `Path=${options.path}`,
8845
+ "HttpOnly",
8846
+ `SameSite=${options.sameSite === "none" ? "None" : options.sameSite === "strict" ? "Strict" : "Lax"}`
8847
+ ];
8848
+ if (options.secure) {
8849
+ parts.push("Secure");
8850
+ }
8851
+ if (options.expires) {
8852
+ parts.push(`Expires=${options.expires.toUTCString()}`);
8853
+ }
8854
+ return parts.join("; ");
8855
+ }
8856
+ function resolveBridgeCookieConfig(options) {
8857
+ return {
8858
+ cookieName: options?.cookieName ?? ATHENA_AUTH_SESSION_COOKIE_NAME,
8859
+ cookieNames: options?.cookieNames ?? ATHENA_AUTH_SESSION_COOKIE_NAMES,
8860
+ cookiePath: options?.cookiePath ?? "/",
8861
+ sameSite: options?.sameSite ?? "lax"
8862
+ };
8863
+ }
8864
+ function appendSessionCookie(headers, request2, token, expiresAt, options) {
8865
+ const config = resolveBridgeCookieConfig(options);
8866
+ const secure = options?.secure ?? resolveRequestIsSecure(request2);
8867
+ headers.append(
8868
+ "set-cookie",
8869
+ serializeCookie(config.cookieName, token, {
8870
+ path: config.cookiePath,
8871
+ sameSite: config.sameSite,
8872
+ secure,
8873
+ expires: expiresAt
8874
+ })
8875
+ );
8876
+ }
8877
+ function appendClearSessionCookies(headers, request2, options) {
8878
+ const config = resolveBridgeCookieConfig(options);
8879
+ const secure = options?.secure ?? resolveRequestIsSecure(request2);
8880
+ const names = /* @__PURE__ */ new Set([config.cookieName, ...config.cookieNames]);
8881
+ for (const name of names) {
8882
+ headers.append(
8883
+ "set-cookie",
8884
+ serializeCookie(name, "", {
8885
+ path: config.cookiePath,
8886
+ sameSite: config.sameSite,
8887
+ secure,
8888
+ expires: EXPIRED_AT
8889
+ })
8890
+ );
8891
+ }
8892
+ }
8893
+
8894
+ // src/next/session-bridge/handlers.ts
8895
+ function json(body, init) {
8896
+ const headers = init?.headers ?? new Headers();
8897
+ if (!headers.has("content-type")) {
8898
+ headers.set("content-type", "application/json; charset=utf-8");
8899
+ }
8900
+ return new Response(JSON.stringify(body), {
8901
+ status: init?.status ?? 200,
8902
+ headers
8903
+ });
8904
+ }
8905
+ function resolveRoute(options) {
8906
+ return options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
8907
+ }
8908
+ async function handleAthenaAuthSessionBridgePost(request2, options) {
8909
+ const payload = await request2.json().catch(() => null);
8910
+ const token = typeof payload?.token === "string" ? payload.token.trim() : "";
8911
+ if (!token) {
8912
+ return json(
8913
+ {
8914
+ error: "Missing Athena Auth session token"
8915
+ },
8916
+ { status: 400 }
8917
+ );
8918
+ }
8919
+ const headers = new Headers();
8920
+ appendSessionCookie(
8921
+ headers,
8922
+ request2,
8923
+ token,
8924
+ resolveSessionCookieExpiresAt(payload?.expiresAt),
8925
+ options
8926
+ );
8927
+ return json(
8928
+ {
8929
+ ok: true,
8930
+ route: resolveRoute(options)
8931
+ },
8932
+ { headers }
8933
+ );
8934
+ }
8935
+ function handleAthenaAuthSessionBridgeDelete(request2, options) {
8936
+ const headers = new Headers();
8937
+ appendClearSessionCookies(headers, request2, options);
8938
+ return json(
8939
+ {
8940
+ ok: true,
8941
+ route: resolveRoute(options)
8942
+ },
8943
+ { headers }
8944
+ );
8945
+ }
8946
+ function createAthenaAuthSessionBridgeHandlers(options) {
8947
+ return {
8948
+ POST: (request2) => handleAthenaAuthSessionBridgePost(request2, options),
8949
+ DELETE: (request2) => handleAthenaAuthSessionBridgeDelete(request2, options)
8950
+ };
8951
+ }
8952
+ function normalizePathname(pathname) {
8953
+ if (pathname.length > 1 && pathname.endsWith("/")) {
8954
+ return pathname.slice(0, -1);
8955
+ }
8956
+ return pathname || "/";
8957
+ }
8958
+ function isAthenaAuthSessionBridgePath(request2, options) {
8959
+ const pathname = normalizePathname(new URL(request2.url).pathname);
8960
+ const route = normalizePathname(resolveRoute(options));
8961
+ if (pathname === route) {
8962
+ return true;
8963
+ }
8964
+ const matchPaths = options?.matchPaths ?? ["session"];
8965
+ const segments = pathname.split("/").filter(Boolean);
8966
+ const tail = segments[segments.length - 1];
8967
+ return typeof tail === "string" && matchPaths.includes(tail);
8968
+ }
8969
+ function createAthenaAuthSessionBridgePathHandlers(options) {
8970
+ const notFound = () => json(
8971
+ {
8972
+ error: "Not found"
8973
+ },
8974
+ { status: 404 }
8975
+ );
8976
+ return {
8977
+ POST: async (request2) => {
8978
+ if (!isAthenaAuthSessionBridgePath(request2, options)) {
8979
+ return notFound();
8980
+ }
8981
+ return handleAthenaAuthSessionBridgePost(request2, options);
8982
+ },
8983
+ DELETE: (request2) => {
8984
+ if (!isAthenaAuthSessionBridgePath(request2, options)) {
8985
+ return notFound();
8986
+ }
8987
+ return handleAthenaAuthSessionBridgeDelete(request2, options);
8988
+ }
8989
+ };
8990
+ }
8991
+
8762
8992
  // src/next/server.ts
8763
8993
  function resolveUserId(session) {
8764
8994
  return session?.user?.id ?? null;
@@ -8797,6 +9027,6 @@ async function resolveAthenaServerContext(options) {
8797
9027
  };
8798
9028
  }
8799
9029
 
8800
- export { createAthenaServerClient, resolveAthenaServerContext };
9030
+ export { ATHENA_AUTH_SESSION_BRIDGE_ROUTE, ATHENA_AUTH_SESSION_COOKIE_NAME, ATHENA_AUTH_SESSION_COOKIE_NAMES, SESSION_COOKIE_PATTERNS, clearAthenaAuthSessionOnAppHost, createAthenaAuthSessionBridgeHandlers, createAthenaAuthSessionBridgePathHandlers, createAthenaServerClient, handleAthenaAuthSessionBridgeDelete, handleAthenaAuthSessionBridgePost, hasAuthSessionCookie, isAthenaAuthSessionBridgePath, persistAthenaAuthSessionOnAppHost, resolveAthenaServerContext, resolveSessionBridgePayload };
8801
9031
  //# sourceMappingURL=server.js.map
8802
9032
  //# sourceMappingURL=server.js.map