@tern-secure/backend 1.2.0-canary.v20250919134427 → 1.2.0-canary.v20251002175916

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 (78) hide show
  1. package/auth/package.json +5 -0
  2. package/dist/admin/index.d.ts +1 -1
  3. package/dist/admin/index.d.ts.map +1 -1
  4. package/dist/admin/index.js +200 -182
  5. package/dist/admin/index.js.map +1 -1
  6. package/dist/admin/index.mjs +23 -489
  7. package/dist/admin/index.mjs.map +1 -1
  8. package/dist/admin/nextSessionTernSecure.d.ts.map +1 -1
  9. package/dist/admin/sessionTernSecure.d.ts +27 -5
  10. package/dist/admin/sessionTernSecure.d.ts.map +1 -1
  11. package/dist/auth/getauth.d.ts +15 -0
  12. package/dist/auth/getauth.d.ts.map +1 -0
  13. package/dist/auth/index.d.ts +2 -0
  14. package/dist/auth/index.d.ts.map +1 -0
  15. package/dist/auth/index.js +694 -0
  16. package/dist/auth/index.js.map +1 -0
  17. package/dist/auth/index.mjs +53 -0
  18. package/dist/auth/index.mjs.map +1 -0
  19. package/dist/{chunk-ZIO4EKS5.mjs → chunk-4SGWLAJG.mjs} +8 -31
  20. package/dist/chunk-4SGWLAJG.mjs.map +1 -0
  21. package/dist/chunk-NEPV6OWI.mjs +550 -0
  22. package/dist/chunk-NEPV6OWI.mjs.map +1 -0
  23. package/dist/chunk-YKIA5EBF.mjs +142 -0
  24. package/dist/chunk-YKIA5EBF.mjs.map +1 -0
  25. package/dist/constants.d.ts +4 -5
  26. package/dist/constants.d.ts.map +1 -1
  27. package/dist/fireRestApi/createFireApi.d.ts +12 -0
  28. package/dist/fireRestApi/createFireApi.d.ts.map +1 -0
  29. package/dist/fireRestApi/emulator.d.ts +4 -0
  30. package/dist/fireRestApi/emulator.d.ts.map +1 -0
  31. package/dist/fireRestApi/endpointUrl.d.ts +6 -0
  32. package/dist/fireRestApi/endpointUrl.d.ts.map +1 -0
  33. package/dist/fireRestApi/endpoints/AbstractApi.d.ts +7 -0
  34. package/dist/fireRestApi/endpoints/AbstractApi.d.ts.map +1 -0
  35. package/dist/fireRestApi/endpoints/EmailApi.d.ts +14 -0
  36. package/dist/fireRestApi/endpoints/EmailApi.d.ts.map +1 -0
  37. package/dist/fireRestApi/endpoints/PasswordApi.d.ts +20 -0
  38. package/dist/fireRestApi/endpoints/PasswordApi.d.ts.map +1 -0
  39. package/dist/fireRestApi/endpoints/SignInTokenApi.d.ts +11 -0
  40. package/dist/fireRestApi/endpoints/SignInTokenApi.d.ts.map +1 -0
  41. package/dist/fireRestApi/endpoints/SignUpApi.d.ts +11 -0
  42. package/dist/fireRestApi/endpoints/SignUpApi.d.ts.map +1 -0
  43. package/dist/fireRestApi/endpoints/TokenApi.d.ts +21 -0
  44. package/dist/fireRestApi/endpoints/TokenApi.d.ts.map +1 -0
  45. package/dist/fireRestApi/endpoints/index.d.ts +6 -0
  46. package/dist/fireRestApi/endpoints/index.d.ts.map +1 -0
  47. package/dist/fireRestApi/index.d.ts +2 -0
  48. package/dist/fireRestApi/index.d.ts.map +1 -0
  49. package/dist/fireRestApi/request.d.ts +34 -0
  50. package/dist/fireRestApi/request.d.ts.map +1 -0
  51. package/dist/fireRestApi/resources/JSON.d.ts +50 -0
  52. package/dist/fireRestApi/resources/JSON.d.ts.map +1 -0
  53. package/dist/fireRestApi/resources/Token.d.ts +13 -0
  54. package/dist/fireRestApi/resources/Token.d.ts.map +1 -0
  55. package/dist/index.d.ts +1 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +271 -75
  58. package/dist/index.js.map +1 -1
  59. package/dist/index.mjs +257 -179
  60. package/dist/index.mjs.map +1 -1
  61. package/dist/instance/backendFireInstance.d.ts +4 -4
  62. package/dist/instance/backendFireInstance.d.ts.map +1 -1
  63. package/dist/instance/backendInstanceEdge.d.ts +2 -2
  64. package/dist/instance/backendInstanceEdge.d.ts.map +1 -1
  65. package/dist/tokens/authstate.d.ts +1 -1
  66. package/dist/tokens/authstate.d.ts.map +1 -1
  67. package/dist/tokens/keys.d.ts.map +1 -1
  68. package/dist/tokens/request.d.ts +3 -3
  69. package/dist/tokens/request.d.ts.map +1 -1
  70. package/dist/tokens/requestFire.d.ts.map +1 -1
  71. package/dist/tokens/types.d.ts +5 -2
  72. package/dist/tokens/types.d.ts.map +1 -1
  73. package/dist/utils/options.d.ts +1 -1
  74. package/dist/utils/options.d.ts.map +1 -1
  75. package/package.json +14 -3
  76. package/dist/admin/gemini.sessionTernSecure.d.ts +0 -8
  77. package/dist/admin/gemini.sessionTernSecure.d.ts.map +0 -1
  78. package/dist/chunk-ZIO4EKS5.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ __export(index_exports, {
40
40
  module.exports = __toCommonJS(index_exports);
41
41
 
42
42
  // src/constants.ts
43
- var SESSION_COOKIE_PUBLIC_KEYS_URL = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/publicKeys";
43
+ var GOOGLE_PUBLIC_KEYS_URL = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com";
44
44
  var MAX_CACHE_LAST_UPDATED_AT_SECONDS = 5 * 60;
45
45
  var DEFAULT_CACHE_DURATION = 3600 * 1e3;
46
46
  var CACHE_CONTROL_REGEX = /max-age=(\d+)/;
@@ -54,11 +54,10 @@ var Attributes = {
54
54
  };
55
55
  var Cookies = {
56
56
  Session: "__session",
57
- IdToken: "_tern",
58
- CsrfToken: "_session_terncf",
59
- SessionCookie: "_session_cookie",
60
- SessionToken: "_session_token",
61
- Refresh: "__refresh",
57
+ CsrfToken: "__session_terncf",
58
+ IdToken: "FIREBASE_[DEFAULT]",
59
+ Refresh: "FIREBASEID_[DEFAULT]",
60
+ Custom: "__custom",
62
61
  Handshake: "__ternsecure_handshake",
63
62
  DevBrowser: "__ternsecure_db_jwt",
64
63
  RedirectCount: "__ternsecure_redirect_count",
@@ -243,10 +242,11 @@ function signedIn(sessionClaims, headers = new Headers(), token) {
243
242
  headers
244
243
  };
245
244
  }
246
- function signedOut(reason, headers = new Headers()) {
245
+ function signedOut(reason, message = "", headers = new Headers()) {
247
246
  return decorateHeaders({
248
247
  status: AuthStatus.SignedOut,
249
248
  reason,
249
+ message,
250
250
  isSignedIn: false,
251
251
  auth: () => signedOutAuthObject(),
252
252
  token: null,
@@ -271,19 +271,139 @@ var decorateHeaders = (requestState) => {
271
271
  return requestState;
272
272
  };
273
273
 
274
- // src/api/endpoints/SessionApi.ts
275
- var rootPath = "/sessions";
276
- var SessionApi = class {
274
+ // src/fireRestApi/endpoints/AbstractApi.ts
275
+ var AbstractAPI = class {
277
276
  constructor(request) {
278
277
  this.request = request;
279
278
  }
280
- async createSession(params) {
279
+ requireApiKey(apiKey) {
280
+ if (!apiKey) {
281
+ throw new Error("A valid API key is required.");
282
+ }
283
+ }
284
+ };
285
+
286
+ // src/fireRestApi/endpoints/EmailApi.ts
287
+ var EmailApi = class extends AbstractAPI {
288
+ async verifyEmailVerification(apiKey, params) {
289
+ this.requireApiKey(apiKey);
290
+ const { ...restParams } = params;
291
+ return this.request({
292
+ endpoint: "sendOobCode",
293
+ method: "POST",
294
+ bodyParams: restParams
295
+ });
296
+ }
297
+ async confirmEmailVerification(apiKey, params) {
298
+ this.requireApiKey(apiKey);
299
+ const { ...restParams } = params;
300
+ return this.request({
301
+ endpoint: "sendOobCode",
302
+ method: "POST",
303
+ bodyParams: restParams
304
+ });
305
+ }
306
+ };
307
+
308
+ // src/fireRestApi/endpoints/PasswordApi.ts
309
+ var PasswordApi = class extends AbstractAPI {
310
+ async verifyPasswordResetCode(apiKey, params) {
311
+ this.requireApiKey(apiKey);
312
+ const { ...restParams } = params;
313
+ return this.request({
314
+ endpoint: "passwordReset",
315
+ method: "POST",
316
+ bodyParams: restParams
317
+ });
318
+ }
319
+ async confirmPasswordReset(apiKey, params) {
320
+ this.requireApiKey(apiKey);
321
+ const { ...restParams } = params;
322
+ return this.request({
323
+ endpoint: "passwordReset",
324
+ method: "POST",
325
+ bodyParams: restParams
326
+ });
327
+ }
328
+ async changePassword(apiKey, params) {
329
+ this.requireApiKey(apiKey);
330
+ const { ...restParams } = params;
331
+ return this.request({
332
+ endpoint: "passwordReset",
333
+ method: "POST",
334
+ bodyParams: restParams
335
+ });
336
+ }
337
+ };
338
+
339
+ // src/fireRestApi/endpoints/SignInTokenApi.ts
340
+ var SignInTokenApi = class extends AbstractAPI {
341
+ async createCustomToken(apiKey, params) {
342
+ try {
343
+ this.requireApiKey(apiKey);
344
+ const { ...restParams } = params;
345
+ const response = await this.request({
346
+ endpoint: "signInWithCustomToken",
347
+ method: "POST",
348
+ bodyParams: restParams
349
+ });
350
+ if (response.errors) {
351
+ const errorMessage = response.errors[0]?.message || "Failed to create custom token";
352
+ throw new Error(errorMessage);
353
+ }
354
+ return response.data;
355
+ } catch (error) {
356
+ const contextualMessage = `Failed to create custom token: ${error instanceof Error ? error.message : "Unknown error"}`;
357
+ throw new Error(contextualMessage);
358
+ }
359
+ }
360
+ };
361
+
362
+ // src/fireRestApi/endpoints/SignUpApi.ts
363
+ var SignUpApi = class extends AbstractAPI {
364
+ async createCustomToken(apiKey, params) {
365
+ this.requireApiKey(apiKey);
366
+ const { ...restParams } = params;
367
+ return this.request({
368
+ endpoint: "signUp",
369
+ method: "POST",
370
+ bodyParams: restParams
371
+ });
372
+ }
373
+ };
374
+
375
+ // src/fireRestApi/endpoints/TokenApi.ts
376
+ var TokenApi = class extends AbstractAPI {
377
+ async refreshToken(apiKey, params) {
378
+ this.requireApiKey(apiKey);
379
+ const { ...restParams } = params;
281
380
  return this.request({
381
+ endpoint: "refreshToken",
282
382
  method: "POST",
283
- path: rootPath,
284
- bodyParams: params
383
+ bodyParams: restParams
285
384
  });
286
385
  }
386
+ async exchangeCustomForIdAndRefreshTokens(apiKey, params) {
387
+ try {
388
+ this.requireApiKey(apiKey);
389
+ const { ...restParams } = params;
390
+ const response = await this.request({
391
+ endpoint: "signInWithCustomToken",
392
+ method: "POST",
393
+ apiKey,
394
+ bodyParams: restParams
395
+ });
396
+ if (response.errors) {
397
+ const errorMessage = response.errors[0]?.message || "Failed to create custom token";
398
+ console.error("Error response from exchangeCustomForIdAndRefreshTokens:", response.errors);
399
+ throw new Error(errorMessage);
400
+ }
401
+ return response.data;
402
+ } catch (error) {
403
+ const contextualMessage = `Failed to create custom token: ${error instanceof Error ? error.message : "Unknown error"}`;
404
+ throw new Error(contextualMessage);
405
+ }
406
+ }
287
407
  };
288
408
 
289
409
  // src/runtime.ts
@@ -302,20 +422,69 @@ var runtime = {
302
422
  Response: globalThis.Response
303
423
  };
304
424
 
305
- // src/utils/path.ts
306
- var SEPARATOR = "/";
307
- var MULTIPLE_SEPARATOR_REGEX = new RegExp("(?<!:)" + SEPARATOR + "{1,}", "g");
308
- function joinPaths(...args) {
309
- return args.filter((p) => p).join(SEPARATOR).replace(MULTIPLE_SEPARATOR_REGEX, SEPARATOR);
425
+ // src/fireRestApi/emulator.ts
426
+ var FIREBASE_AUTH_EMULATOR_HOST = process.env.FIREBASE_AUTH_EMULATOR_HOST;
427
+ function emulatorHost() {
428
+ if (typeof process === "undefined") return void 0;
429
+ return FIREBASE_AUTH_EMULATOR_HOST;
430
+ }
431
+ function useEmulator() {
432
+ return !!emulatorHost();
310
433
  }
311
434
 
312
- // src/api/request.ts
435
+ // src/fireRestApi/endpointUrl.ts
436
+ var getRefreshTokenEndpoint = (apiKey) => {
437
+ return `https://securetoken.googleapis.com/v1/token?key=${apiKey}`;
438
+ };
439
+ var signInWithPassword = (apiKey) => {
440
+ return `https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=${apiKey}`;
441
+ };
442
+ var signUpEndpoint = (apiKey) => {
443
+ return `https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=${apiKey}`;
444
+ };
445
+ var getCustomTokenEndpoint = (apiKey) => {
446
+ if (useEmulator() && FIREBASE_AUTH_EMULATOR_HOST) {
447
+ let protocol = "http://";
448
+ if (FIREBASE_AUTH_EMULATOR_HOST.startsWith("http://")) {
449
+ protocol = "";
450
+ }
451
+ return `${protocol}${FIREBASE_AUTH_EMULATOR_HOST}/identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${apiKey}`;
452
+ }
453
+ return `https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${apiKey}`;
454
+ };
455
+ var passwordResetEndpoint = (apiKey) => {
456
+ return `https://identitytoolkit.googleapis.com/v1/accounts:resetPassword?key=${apiKey}`;
457
+ };
458
+
459
+ // src/fireRestApi/request.ts
460
+ var FIREBASE_ENDPOINT_MAP = {
461
+ refreshToken: getRefreshTokenEndpoint,
462
+ signInWithPassword,
463
+ signUp: signUpEndpoint,
464
+ signInWithCustomToken: getCustomTokenEndpoint,
465
+ passwordReset: passwordResetEndpoint,
466
+ sendOobCode: signInWithPassword
467
+ };
313
468
  function createRequest(options) {
314
469
  const requestFn = async (requestOptions) => {
315
- const { apiUrl, apiVersion } = options;
316
- const { path, method, queryParams, headerParams, bodyParams, formData } = requestOptions;
317
- const url = joinPaths(apiUrl, apiVersion, path);
318
- const finalUrl = new URL(url);
470
+ const { endpoint, method, apiKey, queryParams, headerParams, bodyParams, formData } = requestOptions;
471
+ if (!apiKey) {
472
+ return {
473
+ data: null,
474
+ errors: [
475
+ {
476
+ code: "missing_api_key",
477
+ message: "Firebase API key is required"
478
+ }
479
+ ]
480
+ };
481
+ }
482
+ const endpointUrl = FIREBASE_ENDPOINT_MAP[endpoint](apiKey);
483
+ const finalUrl = new URL(endpointUrl);
484
+ console.log("endpoint url:", endpointUrl);
485
+ console.log("Final URL href:", finalUrl.href);
486
+ console.log("Final URL:", finalUrl);
487
+ console.log("Method:", method);
319
488
  if (queryParams) {
320
489
  Object.entries(queryParams).forEach(([key, value]) => {
321
490
  if (value) {
@@ -394,39 +563,20 @@ function parseError(error) {
394
563
  };
395
564
  }
396
565
 
397
- // src/api/createBackendApi.ts
398
- function createBackendApi(options) {
566
+ // src/fireRestApi/createFireApi.ts
567
+ function createFireApi(options) {
399
568
  const request = createRequest(options);
400
569
  return {
401
- sessions: new SessionApi(request)
402
- };
403
- }
404
-
405
- // src/utils/options.ts
406
- var defaultOptions = {
407
- apiUrl: void 0,
408
- apiVersion: void 0
409
- };
410
- function mergePreDefinedOptions(userOptions = {}) {
411
- return {
412
- ...defaultOptions,
413
- ...userOptions
570
+ email: new EmailApi(request),
571
+ password: new PasswordApi(request),
572
+ signIn: new SignInTokenApi(request),
573
+ signUp: new SignUpApi(request),
574
+ tokens: new TokenApi(request)
414
575
  };
415
576
  }
416
577
 
417
- // src/tokens/sessionConfig.ts
418
- var getSessionConfig = (options) => {
419
- const cookieConfig = options?.cookies?.session_cookie;
420
- return {
421
- COOKIE_NAME: cookieConfig?.name,
422
- DEFAULT_EXPIRES_IN_MS: cookieConfig?.attributes?.maxAge,
423
- DEFAULT_EXPIRES_IN_SECONDS: Math.floor((cookieConfig?.attributes?.maxAge || 0) / 1e3),
424
- REVOKE_REFRESH_TOKENS_ON_SIGNOUT: cookieConfig?.revokeRefreshTokensOnSignOut
425
- };
426
- };
427
-
428
- // src/jwt/verifyJwt.ts
429
- var import_jose2 = require("jose");
578
+ // src/tokens/request.ts
579
+ var import_cookie2 = require("@tern-secure/shared/cookie");
430
580
 
431
581
  // src/utils/errors.ts
432
582
  var TokenVerificationErrorReason = {
@@ -463,6 +613,22 @@ var TokenVerificationError = class _TokenVerificationError extends Error {
463
613
  }
464
614
  };
465
615
 
616
+ // src/utils/options.ts
617
+ var defaultOptions = {
618
+ apiKey: void 0,
619
+ apiUrl: void 0,
620
+ apiVersion: void 0
621
+ };
622
+ function mergePreDefinedOptions(userOptions = {}) {
623
+ return {
624
+ ...defaultOptions,
625
+ ...userOptions
626
+ };
627
+ }
628
+
629
+ // src/jwt/verifyJwt.ts
630
+ var import_jose2 = require("jose");
631
+
466
632
  // src/utils/rfc4648.ts
467
633
  var base64url = {
468
634
  parse(string, opts) {
@@ -755,7 +921,7 @@ async function fetchPublicKeys(keyUrl) {
755
921
  };
756
922
  }
757
923
  async function loadJWKFromRemote({
758
- keyURL = SESSION_COOKIE_PUBLIC_KEYS_URL,
924
+ keyURL = GOOGLE_PUBLIC_KEYS_URL,
759
925
  skipJwksCache,
760
926
  kid
761
927
  }) {
@@ -851,7 +1017,6 @@ async function verifyToken(token, options) {
851
1017
 
852
1018
  // src/tokens/request.ts
853
1019
  var BEARER_PREFIX = "Bearer ";
854
- var AUTH_COOKIE_NAME = "_session_cookie";
855
1020
  function extractTokenFromHeader(request) {
856
1021
  const authHeader = request.headers.get("Authorization");
857
1022
  if (!authHeader || !authHeader.startsWith(BEARER_PREFIX)) {
@@ -859,12 +1024,16 @@ function extractTokenFromHeader(request) {
859
1024
  }
860
1025
  return authHeader.slice(BEARER_PREFIX.length);
861
1026
  }
862
- function extractTokenFromCookie(request, opts) {
1027
+ function extractTokenFromCookie(request) {
863
1028
  const cookieHeader = request.headers.get("Cookie") || void 0;
864
- const sessionName = getSessionConfig(opts).COOKIE_NAME;
865
1029
  if (!cookieHeader) {
866
1030
  return null;
867
1031
  }
1032
+ const cookiePrefix = (0, import_cookie2.getCookiePrefix)();
1033
+ const idTokenCookieName = (0, import_cookie2.getCookieName)(
1034
+ constants.Cookies.IdToken,
1035
+ cookiePrefix
1036
+ );
868
1037
  const cookies = cookieHeader.split(";").reduce(
869
1038
  (acc, cookie) => {
870
1039
  const [name, value] = cookie.trim().split("=");
@@ -873,35 +1042,63 @@ function extractTokenFromCookie(request, opts) {
873
1042
  },
874
1043
  {}
875
1044
  );
876
- return cookies[AUTH_COOKIE_NAME] || null;
1045
+ return idTokenCookieName || null;
877
1046
  }
878
1047
  function hasAuthorizationHeader(request) {
879
1048
  return request.headers.has("Authorization");
880
1049
  }
881
1050
  async function authenticateRequest(request, options) {
1051
+ async function refreshToken() {
1052
+ try {
1053
+ const response = await options.apiClient?.tokens.refreshToken(options.firebaseConfig?.apiKey || "", {
1054
+ format: "cookie",
1055
+ refresh_token: "",
1056
+ expired_token: "",
1057
+ request_origin: options.apiUrl || ""
1058
+ });
1059
+ } catch (error) {
1060
+ console.error("Error refreshing token:", error);
1061
+ }
1062
+ }
882
1063
  async function authenticateRequestWithTokenInCookie() {
883
- const token = extractTokenFromCookie(request, options);
1064
+ const token = extractTokenFromCookie(request);
884
1065
  if (!token) {
885
1066
  return signedOut(AuthErrorReason.SessionTokenMissing);
886
1067
  }
887
- const { data, errors } = await verifyToken(token, options);
888
- if (errors) {
889
- throw errors[0];
1068
+ try {
1069
+ const { data, errors } = await verifyToken(token, options);
1070
+ if (errors) {
1071
+ throw errors[0];
1072
+ }
1073
+ const signedInRequestState = signedIn(data, void 0, token);
1074
+ return signedInRequestState;
1075
+ } catch (err) {
1076
+ return handleError(err, "cookie");
890
1077
  }
891
- const signedInRequestState = signedIn(data, void 0, token);
892
- return signedInRequestState;
893
1078
  }
894
1079
  async function authenticateRequestWithTokenInHeader() {
895
1080
  const token = extractTokenFromHeader(request);
896
1081
  if (!token) {
897
- return signedOut(AuthErrorReason.SessionTokenMissing);
1082
+ return signedOut(AuthErrorReason.SessionTokenMissing, "");
898
1083
  }
899
- const { data, errors } = await verifyToken(token, options);
900
- if (errors) {
901
- throw errors[0];
1084
+ try {
1085
+ const { data, errors } = await verifyToken(token, options);
1086
+ if (errors) {
1087
+ throw errors[0];
1088
+ }
1089
+ const signedInRequestState = signedIn(data, void 0, token);
1090
+ return signedInRequestState;
1091
+ } catch (err) {
1092
+ return handleError(err, "header");
902
1093
  }
903
- const signedInRequestState = signedIn(data, void 0, token);
904
- return signedInRequestState;
1094
+ }
1095
+ async function handleError(err, tokenCarrier) {
1096
+ if (!(err instanceof TokenVerificationError)) {
1097
+ return signedOut(AuthErrorReason.UnexpectedError);
1098
+ }
1099
+ let refreshError;
1100
+ err.tokenCarrier = tokenCarrier;
1101
+ return signedOut(err.reason, err.getFullMessage());
905
1102
  }
906
1103
  if (hasAuthorizationHeader(request)) {
907
1104
  return authenticateRequestWithTokenInHeader();
@@ -923,7 +1120,7 @@ function createAuthenticateRequest(params) {
923
1120
  // src/instance/backendInstanceEdge.ts
924
1121
  function createBackendInstanceClient(options) {
925
1122
  const opts = { ...options };
926
- const apiClient = createBackendApi(opts);
1123
+ const apiClient = createFireApi(opts);
927
1124
  const requestState = createAuthenticateRequest({ options: opts, apiClient });
928
1125
  return {
929
1126
  ...apiClient,
@@ -947,7 +1144,7 @@ function mergePreDefinedOptions2(preDefinedOptions, options) {
947
1144
  );
948
1145
  }
949
1146
  var BEARER_PREFIX2 = "Bearer ";
950
- var AUTH_COOKIE_NAME2 = "_session_cookie";
1147
+ var AUTH_COOKIE_NAME = "_session_cookie";
951
1148
  function extractTokenFromHeader2(request) {
952
1149
  const authHeader = request.headers.get("Authorization");
953
1150
  if (!authHeader || !authHeader.startsWith(BEARER_PREFIX2)) {
@@ -955,9 +1152,8 @@ function extractTokenFromHeader2(request) {
955
1152
  }
956
1153
  return authHeader.slice(BEARER_PREFIX2.length);
957
1154
  }
958
- function extractTokenFromCookie2(request, opts) {
1155
+ function extractTokenFromCookie2(request) {
959
1156
  const cookieHeader = request.headers.get("Cookie") || void 0;
960
- const sessionName = getSessionConfig(opts).COOKIE_NAME;
961
1157
  if (!cookieHeader) {
962
1158
  return null;
963
1159
  }
@@ -969,14 +1165,14 @@ function extractTokenFromCookie2(request, opts) {
969
1165
  },
970
1166
  {}
971
1167
  );
972
- return cookies[AUTH_COOKIE_NAME2] || null;
1168
+ return cookies[AUTH_COOKIE_NAME] || null;
973
1169
  }
974
1170
  function hasAuthorizationHeader2(request) {
975
1171
  return request.headers.has("Authorization");
976
1172
  }
977
1173
  async function authenticateRequest2(request, options) {
978
1174
  async function authenticateRequestWithTokenInCookie() {
979
- const token = extractTokenFromCookie2(request, options);
1175
+ const token = extractTokenFromCookie2(request);
980
1176
  if (!token) {
981
1177
  return signedOut(AuthErrorReason.SessionTokenMissing);
982
1178
  }
@@ -1018,7 +1214,7 @@ function createFireAuthenticateRequest(params) {
1018
1214
  // src/instance/backendFireInstance.ts
1019
1215
  function createFireClient(options) {
1020
1216
  const opts = { ...options };
1021
- const apiClient = createBackendApi(opts);
1217
+ const apiClient = createFireApi(opts);
1022
1218
  const requestState = createFireAuthenticateRequest({ options: opts });
1023
1219
  return {
1024
1220
  ...apiClient,