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

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.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/auth/index.ts
@@ -742,14 +732,6 @@ var ONE_HOUR_IN_SECONDS = 60 * 60;
742
732
  var ONE_MINUTE_IN_SECONDS = 60;
743
733
  var ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1e3;
744
734
  var ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1e3;
745
- var Attributes = {
746
- AuthToken: "__ternsecureAuthToken",
747
- AuthSignature: "__ternsecureAuthSignature",
748
- AuthStatus: "__ternsecureAuthStatus",
749
- AuthReason: "__ternsecureAuthReason",
750
- AuthMessage: "__ternsecureAuthMessage",
751
- TernSecureUrl: "__ternsecureUrl"
752
- };
753
735
  var Cookies = {
754
736
  Session: "__session",
755
737
  CsrfToken: "__terncf",
@@ -774,46 +756,6 @@ var QueryParameters = {
774
756
  HandshakeReason: "__tern_hs_reason",
775
757
  HandshakeNonce: Cookies.HandshakeNonce
776
758
  };
777
- var Headers2 = {
778
- Accept: "accept",
779
- AppCheckToken: "x-ternsecure-appcheck",
780
- AuthMessage: "x-ternsecure-auth-message",
781
- Authorization: "authorization",
782
- AuthReason: "x-ternsecure-auth-reason",
783
- AuthSignature: "x-ternsecure-auth-signature",
784
- AuthStatus: "x-ternsecure-auth-status",
785
- AuthToken: "x-ternsecure-auth-token",
786
- CacheControl: "cache-control",
787
- TernSecureRedirectTo: "x-ternsecure-redirect-to",
788
- TernSecureRequestData: "x-ternsecure-request-data",
789
- TernSecureUrl: "x-ternsecure-url",
790
- CloudFrontForwardedProto: "cloudfront-forwarded-proto",
791
- ContentType: "content-type",
792
- ContentSecurityPolicy: "content-security-policy",
793
- ContentSecurityPolicyReportOnly: "content-security-policy-report-only",
794
- EnableDebug: "x-ternsecure-debug",
795
- ForwardedHost: "x-forwarded-host",
796
- ForwardedPort: "x-forwarded-port",
797
- ForwardedProto: "x-forwarded-proto",
798
- Host: "host",
799
- Location: "location",
800
- Nonce: "x-nonce",
801
- Origin: "origin",
802
- Referrer: "referer",
803
- SecFetchDest: "sec-fetch-dest",
804
- UserAgent: "user-agent",
805
- ReportingEndpoints: "reporting-endpoints"
806
- };
807
- var ContentTypes = {
808
- Json: "application/json"
809
- };
810
- var constants = {
811
- Attributes,
812
- Cookies,
813
- Headers: Headers2,
814
- ContentTypes,
815
- QueryParameters
816
- };
817
759
 
818
760
  // src/app-check/generator.ts
819
761
  function transformMillisecondsToSecondsString(milliseconds) {
@@ -875,99 +817,12 @@ var AppCheckTokenGenerator = class {
875
817
  // src/app-check/serverAppCheck.ts
876
818
  var import_redis = require("@upstash/redis");
877
819
 
878
- // src/admin/sessionTernSecure.ts
879
- var import_errors4 = require("@tern-secure/shared/errors");
880
-
881
- // src/utils/admin-init.ts
882
- var import_firebase_admin = __toESM(require("firebase-admin"));
883
- var import_app_check = require("firebase-admin/app-check");
884
-
885
820
  // src/utils/config.ts
886
821
  var loadAdminConfig = () => ({
887
822
  projectId: process.env.FIREBASE_PROJECT_ID || "",
888
823
  clientEmail: process.env.FIREBASE_CLIENT_EMAIL || "",
889
824
  privateKey: process.env.FIREBASE_PRIVATE_KEY || ""
890
825
  });
891
- var validateAdminConfig = (config) => {
892
- const requiredFields = [
893
- "projectId",
894
- "clientEmail",
895
- "privateKey"
896
- ];
897
- const errors = [];
898
- requiredFields.forEach((field) => {
899
- if (!config[field]) {
900
- errors.push(`Missing required field: FIREBASE_${String(field).toUpperCase()}`);
901
- }
902
- });
903
- return {
904
- isValid: errors.length === 0,
905
- errors,
906
- config
907
- };
908
- };
909
- var initializeAdminConfig = () => {
910
- const config = loadAdminConfig();
911
- const validationResult = validateAdminConfig(config);
912
- if (!validationResult.isValid) {
913
- throw new Error(
914
- `Firebase Admin configuration validation failed:
915
- ${validationResult.errors.join("\n")}`
916
- );
917
- }
918
- return config;
919
- };
920
-
921
- // src/utils/admin-init.ts
922
- if (!import_firebase_admin.default.apps.length) {
923
- try {
924
- const config = initializeAdminConfig();
925
- import_firebase_admin.default.initializeApp({
926
- credential: import_firebase_admin.default.credential.cert({
927
- ...config,
928
- privateKey: config.privateKey.replace(/\\n/g, "\n")
929
- })
930
- });
931
- } catch (error) {
932
- console.error("Firebase admin initialization error", error);
933
- }
934
- }
935
- var adminTernSecureAuth = import_firebase_admin.default.auth();
936
- var adminTernSecureDb = import_firebase_admin.default.firestore();
937
- var TernSecureTenantManager = import_firebase_admin.default.auth().tenantManager();
938
- var appCheckAdmin = (0, import_app_check.getAppCheck)();
939
-
940
- // src/admin/sessionTernSecure.ts
941
- var DEFAULT_COOKIE_CONFIG = {
942
- DEFAULT_EXPIRES_IN_MS: 5 * 60 * 1e3,
943
- // 5 minutes
944
- DEFAULT_EXPIRES_IN_SECONDS: 5 * 60,
945
- REVOKE_REFRESH_TOKENS_ON_SIGNOUT: true
946
- };
947
- var DEFAULT_COOKIE_OPTIONS = {
948
- httpOnly: true,
949
- secure: process.env.NODE_ENV === "production",
950
- sameSite: "strict",
951
- path: "/"
952
- };
953
-
954
- // src/admin/nextSessionTernSecure.ts
955
- var import_cookie = require("@tern-secure/shared/cookie");
956
- var import_errors5 = require("@tern-secure/shared/errors");
957
- var import_headers = require("next/headers");
958
- var SESSION_CONSTANTS = {
959
- COOKIE_NAME: constants.Cookies.Session,
960
- DEFAULT_EXPIRES_IN_MS: 60 * 60 * 24 * 5 * 1e3,
961
- // 5 days
962
- DEFAULT_EXPIRES_IN_SECONDS: 60 * 60 * 24 * 5,
963
- REVOKE_REFRESH_TOKENS_ON_SIGNOUT: true
964
- };
965
-
966
- // src/tokens/ternSecureRequest.ts
967
- var import_cookie2 = require("cookie");
968
-
969
- // src/admin/user.ts
970
- var import_errors6 = require("@tern-secure/shared/errors");
971
826
 
972
827
  // src/app-check/verifier.ts
973
828
  var import_jose6 = require("jose");
@@ -1047,7 +902,7 @@ var AppCheck = class {
1047
902
  });
1048
903
  };
1049
904
  };
1050
- function getAppCheck2(serviceAccount, tenantId, limitedUse) {
905
+ function getAppCheck(serviceAccount, tenantId, limitedUse) {
1051
906
  return new AppCheck(new ServiceAccountManager(serviceAccount), tenantId, limitedUse);
1052
907
  }
1053
908
 
@@ -1280,7 +1135,7 @@ function getAuth(options) {
1280
1135
  async function createAppCheckToken() {
1281
1136
  const adminConfig = loadAdminConfig();
1282
1137
  const appId = process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "";
1283
- const appCheck = getAppCheck2(adminConfig, options.tenantId);
1138
+ const appCheck = getAppCheck(adminConfig, options.tenantId);
1284
1139
  try {
1285
1140
  const appCheckResponse = await appCheck.createToken(adminConfig.projectId, appId);
1286
1141
  return {
@@ -1296,7 +1151,7 @@ function getAuth(options) {
1296
1151
  }
1297
1152
  async function verifyAppCheckToken2(token) {
1298
1153
  const adminConfig = loadAdminConfig();
1299
- const appCheck = getAppCheck2(adminConfig, options.tenantId);
1154
+ const appCheck = getAppCheck(adminConfig, options.tenantId);
1300
1155
  try {
1301
1156
  const decodedToken = await appCheck.verifyToken(token, adminConfig.projectId, {});
1302
1157
  return {