@tern-secure/backend 1.2.0-canary.v20251127235234 → 1.2.0-canary.v20251202164451

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 (91) hide show
  1. package/dist/adapters/index.d.ts +1 -1
  2. package/dist/adapters/index.d.ts.map +1 -1
  3. package/dist/adapters/types.d.ts +42 -0
  4. package/dist/adapters/types.d.ts.map +1 -1
  5. package/dist/admin/index.d.ts +1 -1
  6. package/dist/admin/index.d.ts.map +1 -1
  7. package/dist/admin/index.js +8 -1
  8. package/dist/admin/index.js.map +1 -1
  9. package/dist/admin/index.mjs +24 -598
  10. package/dist/admin/index.mjs.map +1 -1
  11. package/dist/app-check/AppCheckApi.d.ts +14 -0
  12. package/dist/app-check/AppCheckApi.d.ts.map +1 -0
  13. package/dist/app-check/generator.d.ts +9 -0
  14. package/dist/app-check/generator.d.ts.map +1 -0
  15. package/dist/app-check/index.d.ts +18 -0
  16. package/dist/app-check/index.d.ts.map +1 -0
  17. package/dist/app-check/index.js +1135 -0
  18. package/dist/app-check/index.js.map +1 -0
  19. package/dist/app-check/index.mjs +13 -0
  20. package/dist/app-check/index.mjs.map +1 -0
  21. package/dist/app-check/serverAppCheck.d.ts +33 -0
  22. package/dist/app-check/serverAppCheck.d.ts.map +1 -0
  23. package/dist/app-check/types.d.ts +21 -0
  24. package/dist/app-check/types.d.ts.map +1 -0
  25. package/dist/app-check/verifier.d.ts +16 -0
  26. package/dist/app-check/verifier.d.ts.map +1 -0
  27. package/dist/auth/credential.d.ts +5 -5
  28. package/dist/auth/credential.d.ts.map +1 -1
  29. package/dist/auth/getauth.d.ts +2 -1
  30. package/dist/auth/getauth.d.ts.map +1 -1
  31. package/dist/auth/index.d.ts +2 -0
  32. package/dist/auth/index.d.ts.map +1 -1
  33. package/dist/auth/index.js +902 -394
  34. package/dist/auth/index.js.map +1 -1
  35. package/dist/auth/index.mjs +5 -3
  36. package/dist/chunk-34QENCWP.mjs +784 -0
  37. package/dist/chunk-34QENCWP.mjs.map +1 -0
  38. package/dist/{chunk-NXYWC6YO.mjs → chunk-TUYCJY35.mjs} +182 -6
  39. package/dist/chunk-TUYCJY35.mjs.map +1 -0
  40. package/dist/chunk-UCSJDX6Y.mjs +778 -0
  41. package/dist/chunk-UCSJDX6Y.mjs.map +1 -0
  42. package/dist/constants.d.ts +10 -1
  43. package/dist/constants.d.ts.map +1 -1
  44. package/dist/fireRestApi/endpoints/AppCheckApi.d.ts.map +1 -1
  45. package/dist/index.d.ts +4 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1275 -856
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +97 -137
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/jwt/crypto-signer.d.ts +21 -0
  52. package/dist/jwt/crypto-signer.d.ts.map +1 -0
  53. package/dist/jwt/index.d.ts +2 -1
  54. package/dist/jwt/index.d.ts.map +1 -1
  55. package/dist/jwt/index.js +119 -2
  56. package/dist/jwt/index.js.map +1 -1
  57. package/dist/jwt/index.mjs +7 -3
  58. package/dist/jwt/signJwt.d.ts +8 -2
  59. package/dist/jwt/signJwt.d.ts.map +1 -1
  60. package/dist/jwt/types.d.ts +6 -0
  61. package/dist/jwt/types.d.ts.map +1 -1
  62. package/dist/jwt/verifyJwt.d.ts +7 -1
  63. package/dist/jwt/verifyJwt.d.ts.map +1 -1
  64. package/dist/tokens/authstate.d.ts +2 -0
  65. package/dist/tokens/authstate.d.ts.map +1 -1
  66. package/dist/tokens/c-authenticateRequestProcessor.d.ts +2 -2
  67. package/dist/tokens/c-authenticateRequestProcessor.d.ts.map +1 -1
  68. package/dist/tokens/keys.d.ts.map +1 -1
  69. package/dist/tokens/request.d.ts.map +1 -1
  70. package/dist/tokens/types.d.ts +6 -4
  71. package/dist/tokens/types.d.ts.map +1 -1
  72. package/dist/utils/config.d.ts.map +1 -1
  73. package/dist/{auth/utils.d.ts → utils/fetcher.d.ts} +2 -1
  74. package/dist/utils/fetcher.d.ts.map +1 -0
  75. package/dist/utils/mapDecode.d.ts +2 -1
  76. package/dist/utils/mapDecode.d.ts.map +1 -1
  77. package/dist/utils/token-generator.d.ts +4 -0
  78. package/dist/utils/token-generator.d.ts.map +1 -0
  79. package/package.json +13 -3
  80. package/dist/auth/constants.d.ts +0 -6
  81. package/dist/auth/constants.d.ts.map +0 -1
  82. package/dist/auth/utils.d.ts.map +0 -1
  83. package/dist/chunk-DJLDUW7J.mjs +0 -414
  84. package/dist/chunk-DJLDUW7J.mjs.map +0 -1
  85. package/dist/chunk-GFH5CXQR.mjs +0 -71
  86. package/dist/chunk-GFH5CXQR.mjs.map +0 -1
  87. package/dist/chunk-NXYWC6YO.mjs.map +0 -1
  88. package/dist/chunk-WIVOBOZR.mjs +0 -86
  89. package/dist/chunk-WIVOBOZR.mjs.map +0 -1
  90. package/dist/utils/gemini_admin-init.d.ts +0 -10
  91. package/dist/utils/gemini_admin-init.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,20 +1,18 @@
1
1
  import {
2
2
  getAuth,
3
3
  verifyToken
4
- } from "./chunk-DJLDUW7J.mjs";
4
+ } from "./chunk-UCSJDX6Y.mjs";
5
5
  import {
6
+ constants,
6
7
  createTernSecureRequest
7
- } from "./chunk-GFH5CXQR.mjs";
8
- import {
9
- constants
10
- } from "./chunk-WIVOBOZR.mjs";
8
+ } from "./chunk-34QENCWP.mjs";
11
9
  import {
12
10
  RefreshTokenErrorReason,
13
11
  TokenVerificationError,
14
12
  TokenVerificationErrorReason,
15
13
  mapJwtPayloadToDecodedIdToken,
16
14
  ternDecodeJwt
17
- } from "./chunk-NXYWC6YO.mjs";
15
+ } from "./chunk-TUYCJY35.mjs";
18
16
 
19
17
  // src/createRedirect.ts
20
18
  var buildUrl = (_baseUrl, _targetUrl, _returnBackUrl) => {
@@ -74,6 +72,82 @@ var createRedirect = (params) => {
74
72
  return { redirectToSignUp, redirectToSignIn };
75
73
  };
76
74
 
75
+ // src/tokens/c-authenticateRequestProcessor.ts
76
+ var RequestProcessorContext = class {
77
+ constructor(ternSecureRequest, options) {
78
+ this.ternSecureRequest = ternSecureRequest;
79
+ this.options = options;
80
+ this.initHeaderValues();
81
+ this.initCookieValues();
82
+ this.initHandshakeValues();
83
+ this.initUrlValues();
84
+ Object.assign(this, options);
85
+ this.ternUrl = this.ternSecureRequest.ternUrl;
86
+ }
87
+ get request() {
88
+ return this.ternSecureRequest;
89
+ }
90
+ initHeaderValues() {
91
+ this.sessionTokenInHeader = this.parseAuthorizationHeader(
92
+ this.getHeader(constants.Headers.Authorization)
93
+ );
94
+ this.origin = this.getHeader(constants.Headers.Origin);
95
+ this.host = this.getHeader(constants.Headers.Host);
96
+ this.forwardedHost = this.getHeader(constants.Headers.ForwardedHost);
97
+ this.forwardedProto = this.getHeader(constants.Headers.CloudFrontForwardedProto) || this.getHeader(constants.Headers.ForwardedProto);
98
+ this.referrer = this.getHeader(constants.Headers.Referrer);
99
+ this.userAgent = this.getHeader(constants.Headers.UserAgent);
100
+ this.secFetchDest = this.getHeader(constants.Headers.SecFetchDest);
101
+ this.accept = this.getHeader(constants.Headers.Accept);
102
+ this.appCheckToken = this.getHeader(constants.Headers.AppCheckToken);
103
+ }
104
+ initCookieValues() {
105
+ const isProduction = process.env.NODE_ENV === "production";
106
+ const defaultPrefix = isProduction ? "__HOST-" : "__dev_";
107
+ this.sessionTokenInCookie = this.getCookie(constants.Cookies.Session);
108
+ this.idTokenInCookie = this.getCookie(`${defaultPrefix}${constants.Cookies.IdToken}`);
109
+ this.refreshTokenInCookie = this.getCookie(`${defaultPrefix}${constants.Cookies.Refresh}`);
110
+ this.csrfTokenInCookie = this.getCookie(constants.Cookies.CsrfToken);
111
+ this.customTokenInCookie = this.getCookie(constants.Cookies.Custom);
112
+ this.ternAuth = Number.parseInt(this.getCookie(constants.Cookies.TernAut) || "0", 10);
113
+ }
114
+ initHandshakeValues() {
115
+ this.handshakeToken = this.getQueryParam(constants.QueryParameters.Handshake) || this.getCookie(constants.Cookies.Handshake);
116
+ this.handshakeNonce = this.getQueryParam(constants.QueryParameters.HandshakeNonce) || this.getCookie(constants.Cookies.HandshakeNonce);
117
+ }
118
+ initUrlValues() {
119
+ this.method = this.ternSecureRequest.method;
120
+ this.pathSegments = this.ternSecureRequest.ternUrl.pathname.split("/").filter(Boolean);
121
+ this.endpoint = this.pathSegments[2];
122
+ this.subEndpoint = this.pathSegments[3];
123
+ }
124
+ getQueryParam(name) {
125
+ return this.ternSecureRequest.ternUrl.searchParams.get(name);
126
+ }
127
+ getHeader(name) {
128
+ return this.ternSecureRequest.headers.get(name) || void 0;
129
+ }
130
+ getCookie(name) {
131
+ return this.ternSecureRequest.cookies.get(name) || void 0;
132
+ }
133
+ parseAuthorizationHeader(authorizationHeader) {
134
+ if (!authorizationHeader) {
135
+ return void 0;
136
+ }
137
+ const [scheme, token] = authorizationHeader.split(" ", 2);
138
+ if (!token) {
139
+ return scheme;
140
+ }
141
+ if (scheme === "Bearer") {
142
+ return token;
143
+ }
144
+ return void 0;
145
+ }
146
+ };
147
+ var createRequestProcessor = (ternSecureRequest, options) => {
148
+ return new RequestProcessorContext(ternSecureRequest, options);
149
+ };
150
+
77
151
  // src/tokens/authstate.ts
78
152
  var AuthStatus = {
79
153
  SignedIn: "signed-in",
@@ -162,6 +236,7 @@ function signedOut(authCtx, reason, message = "", headers = new Headers()) {
162
236
  isSignedIn: false,
163
237
  auth: () => signedOutAuthObject(),
164
238
  token: null,
239
+ appCheckToken: authCtx.appCheckToken,
165
240
  headers
166
241
  });
167
242
  }
@@ -185,6 +260,12 @@ var decorateHeaders = (requestState) => {
185
260
  } catch {
186
261
  }
187
262
  }
263
+ if (requestState.appCheckToken) {
264
+ try {
265
+ headers.set(constants.Headers.AppCheckToken, requestState.appCheckToken);
266
+ } catch {
267
+ }
268
+ }
188
269
  requestState.headers = headers;
189
270
  return requestState;
190
271
  };
@@ -219,15 +300,11 @@ var AppCheckApi = class extends AbstractAPI {
219
300
  "Content-Type": "application/json",
220
301
  "Authorization": `Bearer ${accessToken}`
221
302
  };
222
- const body = {
223
- customToken,
224
- limitedUse
225
- };
226
303
  try {
227
304
  const response = await fetch(endpoint, {
228
305
  method: "POST",
229
306
  headers,
230
- body: JSON.stringify(body)
307
+ body: JSON.stringify({ customToken, limitedUse })
231
308
  });
232
309
  if (!response.ok) {
233
310
  const errorText = await response.text();
@@ -690,82 +767,6 @@ function mergePreDefinedOptions(userOptions = {}) {
690
767
  // src/tokens/request.ts
691
768
  import { ms } from "@tern-secure/shared/ms";
692
769
 
693
- // src/tokens/c-authenticateRequestProcessor.ts
694
- var RequestProcessorContext = class {
695
- constructor(ternSecureRequest, options) {
696
- this.ternSecureRequest = ternSecureRequest;
697
- this.options = options;
698
- this.initHeaderValues();
699
- this.initCookieValues();
700
- this.initHandshakeValues();
701
- this.initUrlValues();
702
- Object.assign(this, options);
703
- this.ternUrl = this.ternSecureRequest.ternUrl;
704
- }
705
- get request() {
706
- return this.ternSecureRequest;
707
- }
708
- initHeaderValues() {
709
- this.sessionTokenInHeader = this.parseAuthorizationHeader(
710
- this.getHeader(constants.Headers.Authorization)
711
- );
712
- this.origin = this.getHeader(constants.Headers.Origin);
713
- this.host = this.getHeader(constants.Headers.Host);
714
- this.forwardedHost = this.getHeader(constants.Headers.ForwardedHost);
715
- this.forwardedProto = this.getHeader(constants.Headers.CloudFrontForwardedProto) || this.getHeader(constants.Headers.ForwardedProto);
716
- this.referrer = this.getHeader(constants.Headers.Referrer);
717
- this.userAgent = this.getHeader(constants.Headers.UserAgent);
718
- this.secFetchDest = this.getHeader(constants.Headers.SecFetchDest);
719
- this.accept = this.getHeader(constants.Headers.Accept);
720
- this.appCheckToken = this.getHeader(constants.Headers.AppCheckToken);
721
- }
722
- initCookieValues() {
723
- const isProduction = process.env.NODE_ENV === "production";
724
- const defaultPrefix = isProduction ? "__HOST-" : "__dev_";
725
- this.sessionTokenInCookie = this.getCookie(constants.Cookies.Session);
726
- this.idTokenInCookie = this.getCookie(`${defaultPrefix}${constants.Cookies.IdToken}`);
727
- this.refreshTokenInCookie = this.getCookie(`${defaultPrefix}${constants.Cookies.Refresh}`);
728
- this.csrfTokenInCookie = this.getCookie(constants.Cookies.CsrfToken);
729
- this.customTokenInCookie = this.getCookie(constants.Cookies.Custom);
730
- this.ternAuth = Number.parseInt(this.getCookie(constants.Cookies.TernAut) || "0", 10);
731
- }
732
- initHandshakeValues() {
733
- this.handshakeToken = this.getQueryParam(constants.QueryParameters.Handshake) || this.getCookie(constants.Cookies.Handshake);
734
- this.handshakeNonce = this.getQueryParam(constants.QueryParameters.HandshakeNonce) || this.getCookie(constants.Cookies.HandshakeNonce);
735
- }
736
- initUrlValues() {
737
- this.method = this.ternSecureRequest.method;
738
- this.pathSegments = this.ternSecureRequest.ternUrl.pathname.split("/").filter(Boolean);
739
- this.endpoint = this.pathSegments[2];
740
- this.subEndpoint = this.pathSegments[3];
741
- }
742
- getQueryParam(name) {
743
- return this.ternSecureRequest.ternUrl.searchParams.get(name);
744
- }
745
- getHeader(name) {
746
- return this.ternSecureRequest.headers.get(name) || void 0;
747
- }
748
- getCookie(name) {
749
- return this.ternSecureRequest.cookies.get(name) || void 0;
750
- }
751
- parseAuthorizationHeader(authorizationHeader) {
752
- if (!authorizationHeader) {
753
- return void 0;
754
- }
755
- const [scheme, token] = authorizationHeader.split(" ", 2);
756
- if (!token) {
757
- return scheme;
758
- }
759
- if (scheme === "Bearer") {
760
- return token;
761
- }
762
- return void 0;
763
- }
764
- };
765
- var createRequestProcessor = (ternSecureRequest, options) => {
766
- return new RequestProcessorContext(ternSecureRequest, options);
767
- };
768
-
769
770
  // src/tokens/cookie.ts
770
771
  import { getCookieName as getCookieNameEnvironment, getCookiePrefix } from "@tern-secure/shared/cookie";
771
772
 
@@ -781,7 +782,7 @@ function isRequestForRefresh(error, context, request) {
781
782
  }
782
783
  async function authenticateRequest(request, options) {
783
784
  const context = createRequestProcessor(createTernSecureRequest(request), options);
784
- const { refreshTokenInCookie, appCheckToken } = context;
785
+ const { refreshTokenInCookie } = context;
785
786
  const { refreshExpiredIdToken } = getAuth(options);
786
787
  function checkSessionTimeout(authTimeValue) {
787
788
  const defaultMaxAgeSeconds = convertToSeconds("5 days");
@@ -804,8 +805,7 @@ async function authenticateRequest(request, options) {
804
805
  };
805
806
  }
806
807
  return await refreshExpiredIdToken(refreshTokenInCookie, {
807
- referer: context.ternUrl.origin,
808
- appCheckToken
808
+ referer: context.ternUrl.origin
809
809
  });
810
810
  }
811
811
  async function handleRefresh() {
@@ -907,24 +907,7 @@ async function authenticateRequest(request, options) {
907
907
  if (errors) {
908
908
  throw errors[0];
909
909
  }
910
- const { exchangeAppCheckToken } = getAuth(options);
911
- let appCheckTokenValue;
912
- try {
913
- const idToken = context.idTokenInCookie || "";
914
- const appCheckResult = await exchangeAppCheckToken(idToken);
915
- console.log("[authenticateRequest] App Check exchange result:", appCheckResult);
916
- if (appCheckResult.data?.token) {
917
- appCheckTokenValue = appCheckResult.data.token;
918
- }
919
- } catch (error) {
920
- console.warn("App Check token exchange failed:", error);
921
- }
922
- const headers = new Headers();
923
- headers.set(
924
- constants.Headers.AppCheckToken,
925
- appCheckTokenValue || ""
926
- );
927
- const signedInRequestState = signedIn(context, data, headers, context.idTokenInCookie);
910
+ const signedInRequestState = signedIn(context, data, void 0, context.idTokenInCookie);
928
911
  return signedInRequestState;
929
912
  } catch (err) {
930
913
  return handleError(err, "cookie");
@@ -938,23 +921,7 @@ async function authenticateRequest(request, options) {
938
921
  if (errors) {
939
922
  throw errors[0];
940
923
  }
941
- const { exchangeAppCheckToken } = getAuth(options);
942
- let appCheckTokenValue;
943
- try {
944
- const token = sessionTokenInHeader || "";
945
- const appCheckResult = await exchangeAppCheckToken(token);
946
- if (appCheckResult.data?.token) {
947
- appCheckTokenValue = appCheckResult.data.token;
948
- }
949
- } catch (error) {
950
- console.warn("App Check token exchange failed:", error);
951
- }
952
- const headers = new Headers();
953
- headers.set(
954
- constants.Headers.AppCheckToken,
955
- appCheckTokenValue || ""
956
- );
957
- const signedInRequestState = signedIn(context, data, headers, sessionTokenInHeader);
924
+ const signedInRequestState = signedIn(context, data, void 0, sessionTokenInHeader);
958
925
  return signedInRequestState;
959
926
  } catch (err) {
960
927
  return handleError(err, "header");
@@ -968,17 +935,8 @@ async function authenticateRequest(request, options) {
968
935
  if (isRequestForRefresh(err, context, request)) {
969
936
  const { data, error } = await handleRefresh();
970
937
  if (data) {
971
- const { exchangeAppCheckToken } = getAuth(options);
972
- let appCheckTokenValue;
973
- try {
974
- const appCheckResult = await exchangeAppCheckToken(data.token);
975
- if (appCheckResult.data?.token) {
976
- appCheckTokenValue = appCheckResult.data.token;
977
- }
978
- } catch (error2) {
979
- console.warn("App Check token exchange failed in error handler:", error2);
980
- }
981
- return signedIn(context, data.decoded, data.headers, data.token);
938
+ const signedInState = signedIn(context, data.decoded, data.headers, data.token);
939
+ return signedInState;
982
940
  }
983
941
  if (error?.cause?.reason) {
984
942
  refreshError = error.cause.reason;
@@ -1294,6 +1252,7 @@ export {
1294
1252
  createAdapter,
1295
1253
  createBackendInstanceClient,
1296
1254
  createRedirect,
1255
+ createRequestProcessor,
1297
1256
  createTernSecureRequest,
1298
1257
  disableDebugLogging,
1299
1258
  enableDebugLogging,
@@ -1301,6 +1260,7 @@ export {
1301
1260
  signedIn,
1302
1261
  signedInAuthObject,
1303
1262
  signedOutAuthObject,
1304
- validateCheckRevokedOptions
1263
+ validateCheckRevokedOptions,
1264
+ verifyToken
1305
1265
  };
1306
1266
  //# sourceMappingURL=index.mjs.map