@innvoid/getmarket-sdk 0.2.7 → 0.2.8
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.
- package/dist/{chunk-WM2QICZQ.js → chunk-DT3AM34L.js} +171 -175
- package/dist/chunk-DT3AM34L.js.map +1 -0
- package/dist/express.d.cts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/index.cjs +176 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -24
- package/dist/index.d.ts +17 -24
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/middlewares/index.cjs +193 -68
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.js +1 -1
- package/dist/{types-CRECQuHp.d.cts → types-Cc_McZgD.d.cts} +12 -10
- package/dist/{types-CRECQuHp.d.ts → types-Cc_McZgD.d.ts} +12 -10
- package/package.json +2 -2
- package/dist/chunk-WM2QICZQ.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,6 @@ __export(src_exports, {
|
|
|
52
52
|
buildInternalHeaders: () => buildInternalHeaders,
|
|
53
53
|
closeCache: () => closeCache,
|
|
54
54
|
createAuthMiddleware: () => createAuthMiddleware,
|
|
55
|
-
createAuthMiddlewareLegacySimple: () => createAuthMiddleware2,
|
|
56
55
|
createBulkRefsClient: () => createBulkRefsClient,
|
|
57
56
|
createFisClient: () => createFisClient,
|
|
58
57
|
createHttpClient: () => createHttpClient,
|
|
@@ -63,6 +62,9 @@ __export(src_exports, {
|
|
|
63
62
|
createPayClient: () => createPayClient,
|
|
64
63
|
createPlatformClient: () => createPlatformClient,
|
|
65
64
|
createResClient: () => createResClient,
|
|
65
|
+
extractCustomerUid: () => extractCustomerUid,
|
|
66
|
+
extractEmployeeUid: () => extractEmployeeUid,
|
|
67
|
+
getBearerToken: () => getBearerToken,
|
|
66
68
|
getOrSet: () => getOrSet,
|
|
67
69
|
getRequestContextFromHeaders: () => getRequestContextFromHeaders,
|
|
68
70
|
getTwoLevelCache: () => getTwoLevelCache,
|
|
@@ -71,6 +73,7 @@ __export(src_exports, {
|
|
|
71
73
|
mapAxiosToUpstreamError: () => mapAxiosToUpstreamError,
|
|
72
74
|
newUid: () => newUid,
|
|
73
75
|
newUidV4: () => newUidV4,
|
|
76
|
+
normalizeUid: () => normalizeUid,
|
|
74
77
|
parseHeaders: () => parseHeaders,
|
|
75
78
|
readRs256PublicKey: () => readRs256PublicKey,
|
|
76
79
|
readServiceEnv: () => readServiceEnv,
|
|
@@ -792,12 +795,26 @@ function readFileIfExists(path) {
|
|
|
792
795
|
return null;
|
|
793
796
|
}
|
|
794
797
|
}
|
|
798
|
+
function getBearerToken(req) {
|
|
799
|
+
const auth = String(req?.headers?.authorization || "");
|
|
800
|
+
if (!auth.startsWith("Bearer ")) return null;
|
|
801
|
+
const token = auth.slice(7).trim();
|
|
802
|
+
return token.length ? token : null;
|
|
803
|
+
}
|
|
804
|
+
function normalizeUid(v) {
|
|
805
|
+
const s = String(v ?? "").trim();
|
|
806
|
+
return s.length ? s : null;
|
|
807
|
+
}
|
|
795
808
|
function readRs256PublicKey() {
|
|
796
809
|
const fromFile = readFileIfExists(process.env.JWT_PUBLIC_KEY_PATH);
|
|
797
810
|
if (fromFile) return fromFile;
|
|
798
|
-
const fromEnv = String(
|
|
811
|
+
const fromEnv = String(
|
|
812
|
+
process.env.AUTH_JWT_PUBLIC_KEY || process.env.AUTH_RSA_PUBLIC_KEY || ""
|
|
813
|
+
).replace(/\\n/g, "\n").trim();
|
|
799
814
|
if (fromEnv) return fromEnv;
|
|
800
|
-
throw new Error(
|
|
815
|
+
throw new Error(
|
|
816
|
+
"Missing RS256 public key (JWT_PUBLIC_KEY_PATH / AUTH_JWT_PUBLIC_KEY / AUTH_RSA_PUBLIC_KEY)"
|
|
817
|
+
);
|
|
801
818
|
}
|
|
802
819
|
function verifyBackendJwtRS256(raw) {
|
|
803
820
|
const publicKey = readRs256PublicKey();
|
|
@@ -809,20 +826,31 @@ function verifyBackendJwtRS256(raw) {
|
|
|
809
826
|
issuer
|
|
810
827
|
});
|
|
811
828
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const
|
|
816
|
-
if (!
|
|
817
|
-
const
|
|
818
|
-
return
|
|
829
|
+
function extractEmployeeUid(decoded) {
|
|
830
|
+
const direct = normalizeUid(decoded?.employee_uid) ?? normalizeUid(decoded?.employee?.uid);
|
|
831
|
+
if (direct) return direct;
|
|
832
|
+
const sub = normalizeUid(decoded?.sub);
|
|
833
|
+
if (!sub) return null;
|
|
834
|
+
const match = /^emp:(.+)$/i.exec(sub);
|
|
835
|
+
return match?.[1] ? normalizeUid(match[1]) : null;
|
|
819
836
|
}
|
|
820
|
-
function
|
|
821
|
-
const
|
|
822
|
-
|
|
837
|
+
function extractCustomerUid(decoded) {
|
|
838
|
+
const direct = normalizeUid(decoded?.customer_uid) ?? normalizeUid(decoded?.customer?.uid);
|
|
839
|
+
if (direct) return direct;
|
|
840
|
+
const sub = normalizeUid(decoded?.sub);
|
|
841
|
+
if (!sub) return null;
|
|
842
|
+
const match = /^cus:(.+)$/i.exec(sub);
|
|
843
|
+
return match?.[1] ? normalizeUid(match[1]) : null;
|
|
823
844
|
}
|
|
845
|
+
|
|
846
|
+
// src/auth/middleware.ts
|
|
824
847
|
function createAuthMiddleware(opts) {
|
|
825
|
-
const {
|
|
848
|
+
const {
|
|
849
|
+
subject,
|
|
850
|
+
allowFirebaseIdToken = false,
|
|
851
|
+
requireSubject = true,
|
|
852
|
+
hydrate
|
|
853
|
+
} = opts;
|
|
826
854
|
return async (req, res, next) => {
|
|
827
855
|
const token = getBearerToken(req);
|
|
828
856
|
if (!token) {
|
|
@@ -851,8 +879,33 @@ function createAuthMiddleware(opts) {
|
|
|
851
879
|
expires_at: decoded?.exp
|
|
852
880
|
}
|
|
853
881
|
};
|
|
854
|
-
|
|
882
|
+
if (subject === "employee") {
|
|
883
|
+
baseCtx.employee_uid = extractEmployeeUid(decoded) ?? void 0;
|
|
884
|
+
} else {
|
|
885
|
+
baseCtx.customer_uid = extractCustomerUid(decoded) ?? void 0;
|
|
886
|
+
}
|
|
887
|
+
const hydrated = await hydrate({
|
|
888
|
+
decoded,
|
|
889
|
+
req,
|
|
890
|
+
subject,
|
|
891
|
+
company_uid,
|
|
892
|
+
branch_uid
|
|
893
|
+
});
|
|
855
894
|
Object.assign(baseCtx, hydrated);
|
|
895
|
+
if (subject === "employee" && !baseCtx.employee_uid) {
|
|
896
|
+
return res.status(401).json({
|
|
897
|
+
ok: false,
|
|
898
|
+
code: "AUTH_EMPLOYEE_UID_MISSING",
|
|
899
|
+
message: "employee_uid missing in token/context (expected employee_uid or sub=emp:<uid>)"
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
if (subject === "customer" && !baseCtx.customer_uid) {
|
|
903
|
+
return res.status(401).json({
|
|
904
|
+
ok: false,
|
|
905
|
+
code: "AUTH_CUSTOMER_UID_MISSING",
|
|
906
|
+
message: "customer_uid missing in token/context (expected customer_uid or sub=cus:<uid>)"
|
|
907
|
+
});
|
|
908
|
+
}
|
|
856
909
|
if (requireSubject) {
|
|
857
910
|
if (subject === "employee" && !baseCtx.employee) {
|
|
858
911
|
return res.status(401).json({
|
|
@@ -880,8 +933,8 @@ function createAuthMiddleware(opts) {
|
|
|
880
933
|
});
|
|
881
934
|
}
|
|
882
935
|
try {
|
|
883
|
-
const { default:
|
|
884
|
-
const firebaseDecoded = await
|
|
936
|
+
const { default: admin } = await import("firebase-admin");
|
|
937
|
+
const firebaseDecoded = await admin.auth().verifyIdToken(token);
|
|
885
938
|
if (firebaseDecoded.email && firebaseDecoded.email_verified === false) {
|
|
886
939
|
return res.status(401).json({
|
|
887
940
|
ok: false,
|
|
@@ -913,169 +966,112 @@ function createAuthMiddleware(opts) {
|
|
|
913
966
|
}
|
|
914
967
|
|
|
915
968
|
// src/auth/authentication.ts
|
|
916
|
-
var import_firebase_admin = __toESM(require("firebase-admin"), 1);
|
|
917
|
-
var import_jsonwebtoken2 = __toESM(require("jsonwebtoken"), 1);
|
|
918
|
-
var import_fs3 = __toESM(require("fs"), 1);
|
|
919
|
-
function getBearerToken2(req) {
|
|
920
|
-
const auth = String(req.headers?.authorization || "");
|
|
921
|
-
if (!auth.startsWith("Bearer ")) return null;
|
|
922
|
-
const token = auth.slice(7).trim();
|
|
923
|
-
return token.length ? token : null;
|
|
924
|
-
}
|
|
925
|
-
function readPublicKey() {
|
|
926
|
-
const publicKeyPath = process.env.JWT_PUBLIC_KEY_PATH;
|
|
927
|
-
const publicKeyEnv = process.env.AUTH_JWT_PUBLIC_KEY || process.env.AUTH_RSA_PUBLIC_KEY || "";
|
|
928
|
-
if (publicKeyPath) {
|
|
929
|
-
const v = import_fs3.default.readFileSync(publicKeyPath, "utf8").trim();
|
|
930
|
-
if (v) return v;
|
|
931
|
-
}
|
|
932
|
-
const envKey = publicKeyEnv.replace(/\\n/g, "\n").trim();
|
|
933
|
-
if (envKey) return envKey;
|
|
934
|
-
throw new Error("Missing RS256 public key (JWT_PUBLIC_KEY_PATH / AUTH_JWT_PUBLIC_KEY / AUTH_RSA_PUBLIC_KEY)");
|
|
935
|
-
}
|
|
936
|
-
function verifyBackendJwtRS2562(raw) {
|
|
937
|
-
const publicKey = readPublicKey();
|
|
938
|
-
const audience = process.env.JWT_AUDIENCE || process.env.AUTH_JWT_AUDIENCE || "getmarket.api";
|
|
939
|
-
const issuer = process.env.JWT_ISSUER || process.env.AUTH_JWT_ISSUER || "getmarket-auth";
|
|
940
|
-
return import_jsonwebtoken2.default.verify(raw, publicKey, {
|
|
941
|
-
algorithms: ["RS256"],
|
|
942
|
-
audience,
|
|
943
|
-
issuer
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
function normalizeUid2(v) {
|
|
947
|
-
const s = String(v ?? "").trim();
|
|
948
|
-
return s.length ? s : null;
|
|
949
|
-
}
|
|
950
969
|
function deriveCompanyBranch(decoded, companyUid, branchUid) {
|
|
951
970
|
const companiesFromToken = Array.isArray(decoded?.companies) ? decoded.companies : [];
|
|
952
971
|
const company = decoded?.company ?? (companyUid ? companiesFromToken.find((c) => c?.uid === companyUid) : null) ?? null;
|
|
953
972
|
const branch = decoded?.branch ?? (branchUid && company?.branches ? (company.branches || []).find((b) => b?.uid === branchUid) : null) ?? null;
|
|
954
|
-
return {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
if (direct) return direct;
|
|
959
|
-
const sub = normalizeUid2(decoded?.sub);
|
|
960
|
-
if (!sub) return null;
|
|
961
|
-
const m = /^emp:(.+)$/i.exec(sub);
|
|
962
|
-
return m?.[1] ? normalizeUid2(m[1]) : null;
|
|
963
|
-
}
|
|
964
|
-
function extractCustomerUid(decoded) {
|
|
965
|
-
const direct = normalizeUid2(decoded?.customer_uid);
|
|
966
|
-
if (direct) return direct;
|
|
967
|
-
const sub = normalizeUid2(decoded?.sub);
|
|
968
|
-
if (!sub) return null;
|
|
969
|
-
const m = /^cus:(.+)$/i.exec(sub);
|
|
970
|
-
return m?.[1] ? normalizeUid2(m[1]) : null;
|
|
971
|
-
}
|
|
972
|
-
function createAuthMiddleware2(opts) {
|
|
973
|
-
const { subject, allowFirebaseIdToken = false } = opts;
|
|
974
|
-
return async (req, res, next) => {
|
|
975
|
-
const token = getBearerToken2(req);
|
|
976
|
-
if (!token) {
|
|
977
|
-
return res.status(401).json({
|
|
978
|
-
ok: false,
|
|
979
|
-
code: "AUTH_MISSING_TOKEN",
|
|
980
|
-
message: "Missing Authorization Bearer token"
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
try {
|
|
984
|
-
const decoded = verifyBackendJwtRS2562(token);
|
|
985
|
-
const headerCtx = req.context || {};
|
|
986
|
-
const companyUid = normalizeUid2(headerCtx.company_uid);
|
|
987
|
-
const branchUid = normalizeUid2(headerCtx.branch_uid);
|
|
988
|
-
const { companiesFromToken, company, branch } = deriveCompanyBranch(decoded, companyUid, branchUid);
|
|
989
|
-
const ctx = {
|
|
990
|
-
tokenType: "backend",
|
|
991
|
-
subject,
|
|
992
|
-
company_uid: companyUid ?? void 0,
|
|
993
|
-
branch_uid: branchUid ?? void 0,
|
|
994
|
-
companies: companiesFromToken,
|
|
995
|
-
company,
|
|
996
|
-
branch,
|
|
997
|
-
roles: Array.isArray(decoded?.roles) ? decoded.roles : [],
|
|
998
|
-
permissions: Array.isArray(decoded?.permissions) ? decoded.permissions : [],
|
|
999
|
-
denied_permissions: Array.isArray(decoded?.denied_permissions) ? decoded.denied_permissions : [],
|
|
1000
|
-
session: {
|
|
1001
|
-
jti: decoded?.jti,
|
|
1002
|
-
device_id: decoded?.device_id,
|
|
1003
|
-
expires_at: decoded?.exp
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
if (subject === "employee") {
|
|
1007
|
-
const employee_uid = extractEmployeeUid(decoded);
|
|
1008
|
-
if (!employee_uid) {
|
|
1009
|
-
return res.status(401).json({
|
|
1010
|
-
ok: false,
|
|
1011
|
-
code: "AUTH_EMPLOYEE_UID_MISSING",
|
|
1012
|
-
message: "employee_uid missing in token (expected employee_uid or sub=emp:<uid>)"
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
ctx.employee_uid = employee_uid;
|
|
1016
|
-
const embedded = decoded?.employee ?? decoded?.user ?? null;
|
|
1017
|
-
ctx.employee = embedded && typeof embedded === "object" ? embedded : { uid: employee_uid, email: decoded?.email ?? null };
|
|
1018
|
-
} else {
|
|
1019
|
-
const customer_uid = extractCustomerUid(decoded);
|
|
1020
|
-
if (!customer_uid) {
|
|
1021
|
-
return res.status(401).json({
|
|
1022
|
-
ok: false,
|
|
1023
|
-
code: "AUTH_CUSTOMER_UID_MISSING",
|
|
1024
|
-
message: "customer_uid missing in token (expected customer_uid or sub=cus:<uid>)"
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
ctx.customer_uid = customer_uid;
|
|
1028
|
-
const embedded = decoded?.customer ?? null;
|
|
1029
|
-
ctx.customer = embedded && typeof embedded === "object" ? embedded : { uid: customer_uid };
|
|
1030
|
-
}
|
|
1031
|
-
req.auth = ctx;
|
|
1032
|
-
return next();
|
|
1033
|
-
} catch {
|
|
1034
|
-
if (!allowFirebaseIdToken) {
|
|
1035
|
-
return res.status(401).json({
|
|
1036
|
-
ok: false,
|
|
1037
|
-
code: "AUTH_INVALID_TOKEN",
|
|
1038
|
-
message: "Invalid or expired token"
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
try {
|
|
1042
|
-
const firebaseDecoded = await import_firebase_admin.default.auth().verifyIdToken(token);
|
|
1043
|
-
if (firebaseDecoded.email && firebaseDecoded.email_verified === false) {
|
|
1044
|
-
return res.status(401).json({
|
|
1045
|
-
ok: false,
|
|
1046
|
-
code: "AUTH_EMAIL_NOT_VERIFIED",
|
|
1047
|
-
message: "Email not verified"
|
|
1048
|
-
});
|
|
1049
|
-
}
|
|
1050
|
-
const headerCtx = req.context || {};
|
|
1051
|
-
const companyUid = normalizeUid2(headerCtx.company_uid);
|
|
1052
|
-
const branchUid = normalizeUid2(headerCtx.branch_uid);
|
|
1053
|
-
req.auth = {
|
|
1054
|
-
tokenType: "backend",
|
|
1055
|
-
subject,
|
|
1056
|
-
firebase: firebaseDecoded,
|
|
1057
|
-
company_uid: companyUid ?? void 0,
|
|
1058
|
-
branch_uid: branchUid ?? void 0,
|
|
1059
|
-
companies: [],
|
|
1060
|
-
roles: [],
|
|
1061
|
-
permissions: [],
|
|
1062
|
-
denied_permissions: []
|
|
1063
|
-
};
|
|
1064
|
-
return next();
|
|
1065
|
-
} catch {
|
|
1066
|
-
return res.status(401).json({
|
|
1067
|
-
ok: false,
|
|
1068
|
-
code: "AUTH_INVALID_TOKEN",
|
|
1069
|
-
message: "Invalid or expired token"
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
973
|
+
return {
|
|
974
|
+
companiesFromToken,
|
|
975
|
+
company,
|
|
976
|
+
branch
|
|
1073
977
|
};
|
|
1074
978
|
}
|
|
1075
|
-
var authEmployeeRequired =
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
979
|
+
var authEmployeeRequired = createAuthMiddleware({
|
|
980
|
+
subject: "employee",
|
|
981
|
+
allowFirebaseIdToken: false,
|
|
982
|
+
requireSubject: false,
|
|
983
|
+
hydrate: async ({ decoded, company_uid, branch_uid }) => {
|
|
984
|
+
const employee_uid = extractEmployeeUid(decoded) ?? normalizeUid(decoded?.employee?.uid);
|
|
985
|
+
const { companiesFromToken, company, branch } = deriveCompanyBranch(
|
|
986
|
+
decoded,
|
|
987
|
+
company_uid,
|
|
988
|
+
branch_uid
|
|
989
|
+
);
|
|
990
|
+
const employee = decoded?.employee && typeof decoded.employee === "object" ? decoded.employee : employee_uid ? { uid: employee_uid, email: decoded?.email ?? null } : void 0;
|
|
991
|
+
return {
|
|
992
|
+
employee_uid: employee_uid ?? void 0,
|
|
993
|
+
employee,
|
|
994
|
+
companies: companiesFromToken,
|
|
995
|
+
company,
|
|
996
|
+
branch,
|
|
997
|
+
roles: Array.isArray(decoded?.roles) ? decoded.roles : [],
|
|
998
|
+
permissions: Array.isArray(decoded?.permissions) ? decoded.permissions : [],
|
|
999
|
+
denied_permissions: Array.isArray(decoded?.denied_permissions) ? decoded.denied_permissions : []
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
var authCustomerRequired = createAuthMiddleware({
|
|
1004
|
+
subject: "customer",
|
|
1005
|
+
allowFirebaseIdToken: false,
|
|
1006
|
+
requireSubject: false,
|
|
1007
|
+
hydrate: async ({ decoded, company_uid, branch_uid }) => {
|
|
1008
|
+
const customer_uid = extractCustomerUid(decoded) ?? normalizeUid(decoded?.customer?.uid);
|
|
1009
|
+
const { companiesFromToken, company, branch } = deriveCompanyBranch(
|
|
1010
|
+
decoded,
|
|
1011
|
+
company_uid,
|
|
1012
|
+
branch_uid
|
|
1013
|
+
);
|
|
1014
|
+
const customer = decoded?.customer && typeof decoded.customer === "object" ? decoded.customer : customer_uid ? { uid: customer_uid } : void 0;
|
|
1015
|
+
return {
|
|
1016
|
+
customer_uid: customer_uid ?? void 0,
|
|
1017
|
+
customer,
|
|
1018
|
+
companies: companiesFromToken,
|
|
1019
|
+
company,
|
|
1020
|
+
branch,
|
|
1021
|
+
roles: Array.isArray(decoded?.roles) ? decoded.roles : [],
|
|
1022
|
+
permissions: Array.isArray(decoded?.permissions) ? decoded.permissions : [],
|
|
1023
|
+
denied_permissions: Array.isArray(decoded?.denied_permissions) ? decoded.denied_permissions : []
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
var authEmployeeAllowFirebase = createAuthMiddleware({
|
|
1028
|
+
subject: "employee",
|
|
1029
|
+
allowFirebaseIdToken: true,
|
|
1030
|
+
requireSubject: false,
|
|
1031
|
+
hydrate: async ({ decoded, company_uid, branch_uid }) => {
|
|
1032
|
+
const employee_uid = extractEmployeeUid(decoded) ?? normalizeUid(decoded?.employee?.uid);
|
|
1033
|
+
const { companiesFromToken, company, branch } = deriveCompanyBranch(
|
|
1034
|
+
decoded,
|
|
1035
|
+
company_uid,
|
|
1036
|
+
branch_uid
|
|
1037
|
+
);
|
|
1038
|
+
const employee = decoded?.employee && typeof decoded.employee === "object" ? decoded.employee : employee_uid ? { uid: employee_uid, email: decoded?.email ?? null } : void 0;
|
|
1039
|
+
return {
|
|
1040
|
+
employee_uid: employee_uid ?? void 0,
|
|
1041
|
+
employee,
|
|
1042
|
+
companies: companiesFromToken,
|
|
1043
|
+
company,
|
|
1044
|
+
branch,
|
|
1045
|
+
roles: Array.isArray(decoded?.roles) ? decoded.roles : [],
|
|
1046
|
+
permissions: Array.isArray(decoded?.permissions) ? decoded.permissions : [],
|
|
1047
|
+
denied_permissions: Array.isArray(decoded?.denied_permissions) ? decoded.denied_permissions : []
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
var authCustomerAllowFirebase = createAuthMiddleware({
|
|
1052
|
+
subject: "customer",
|
|
1053
|
+
allowFirebaseIdToken: true,
|
|
1054
|
+
requireSubject: false,
|
|
1055
|
+
hydrate: async ({ decoded, company_uid, branch_uid }) => {
|
|
1056
|
+
const customer_uid = extractCustomerUid(decoded) ?? normalizeUid(decoded?.customer?.uid);
|
|
1057
|
+
const { companiesFromToken, company, branch } = deriveCompanyBranch(
|
|
1058
|
+
decoded,
|
|
1059
|
+
company_uid,
|
|
1060
|
+
branch_uid
|
|
1061
|
+
);
|
|
1062
|
+
const customer = decoded?.customer && typeof decoded.customer === "object" ? decoded.customer : customer_uid ? { uid: customer_uid } : void 0;
|
|
1063
|
+
return {
|
|
1064
|
+
customer_uid: customer_uid ?? void 0,
|
|
1065
|
+
customer,
|
|
1066
|
+
companies: companiesFromToken,
|
|
1067
|
+
company,
|
|
1068
|
+
branch,
|
|
1069
|
+
roles: Array.isArray(decoded?.roles) ? decoded.roles : [],
|
|
1070
|
+
permissions: Array.isArray(decoded?.permissions) ? decoded.permissions : [],
|
|
1071
|
+
denied_permissions: Array.isArray(decoded?.denied_permissions) ? decoded.denied_permissions : []
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1079
1075
|
|
|
1080
1076
|
// src/middlewares/guards.ts
|
|
1081
1077
|
function normalizeRole(r) {
|
|
@@ -1195,7 +1191,7 @@ function allowAuthAdminOrPerm(permission) {
|
|
|
1195
1191
|
}
|
|
1196
1192
|
|
|
1197
1193
|
// src/internalHttpClient.ts
|
|
1198
|
-
var
|
|
1194
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
1199
1195
|
var InternalHttpError = class extends Error {
|
|
1200
1196
|
status;
|
|
1201
1197
|
code;
|
|
@@ -1210,7 +1206,7 @@ var InternalHttpError = class extends Error {
|
|
|
1210
1206
|
function readSecretFile2(path) {
|
|
1211
1207
|
if (!path) return null;
|
|
1212
1208
|
try {
|
|
1213
|
-
const v =
|
|
1209
|
+
const v = import_fs3.default.readFileSync(path, "utf8").trim();
|
|
1214
1210
|
return v.length ? v : null;
|
|
1215
1211
|
} catch {
|
|
1216
1212
|
return null;
|
|
@@ -1901,7 +1897,6 @@ function isUid(value) {
|
|
|
1901
1897
|
buildInternalHeaders,
|
|
1902
1898
|
closeCache,
|
|
1903
1899
|
createAuthMiddleware,
|
|
1904
|
-
createAuthMiddlewareLegacySimple,
|
|
1905
1900
|
createBulkRefsClient,
|
|
1906
1901
|
createFisClient,
|
|
1907
1902
|
createHttpClient,
|
|
@@ -1912,6 +1907,9 @@ function isUid(value) {
|
|
|
1912
1907
|
createPayClient,
|
|
1913
1908
|
createPlatformClient,
|
|
1914
1909
|
createResClient,
|
|
1910
|
+
extractCustomerUid,
|
|
1911
|
+
extractEmployeeUid,
|
|
1912
|
+
getBearerToken,
|
|
1915
1913
|
getOrSet,
|
|
1916
1914
|
getRequestContextFromHeaders,
|
|
1917
1915
|
getTwoLevelCache,
|
|
@@ -1920,6 +1918,7 @@ function isUid(value) {
|
|
|
1920
1918
|
mapAxiosToUpstreamError,
|
|
1921
1919
|
newUid,
|
|
1922
1920
|
newUidV4,
|
|
1921
|
+
normalizeUid,
|
|
1923
1922
|
parseHeaders,
|
|
1924
1923
|
readRs256PublicKey,
|
|
1925
1924
|
readServiceEnv,
|