@innvoid/getmarket-sdk 0.2.6 → 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/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,
@@ -82,7 +85,8 @@ __export(src_exports, {
82
85
  requireRolesOrAnyPermission: () => requireRolesOrAnyPermission,
83
86
  sendError: () => sendError,
84
87
  sendOk: () => sendOk,
85
- verifyBackendJwtRS256: () => verifyBackendJwtRS256
88
+ verifyBackendJwtRS256: () => verifyBackendJwtRS256,
89
+ withRequestIdConfig: () => withRequestIdConfig
86
90
  });
87
91
  module.exports = __toCommonJS(src_exports);
88
92
 
@@ -414,6 +418,16 @@ function createHttpClient(opts) {
414
418
  headers: opts.headers ?? {}
415
419
  });
416
420
  }
421
+ function withRequestIdConfig(config = {}, requestId2) {
422
+ if (!requestId2) return config;
423
+ return {
424
+ ...config,
425
+ headers: {
426
+ ...config.headers ?? {},
427
+ "x-request-id": requestId2
428
+ }
429
+ };
430
+ }
417
431
 
418
432
  // src/core/internalHttp.ts
419
433
  var DEFAULT_RETRY = {
@@ -781,12 +795,26 @@ function readFileIfExists(path) {
781
795
  return null;
782
796
  }
783
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
+ }
784
808
  function readRs256PublicKey() {
785
809
  const fromFile = readFileIfExists(process.env.JWT_PUBLIC_KEY_PATH);
786
810
  if (fromFile) return fromFile;
787
- const fromEnv = String(process.env.AUTH_JWT_PUBLIC_KEY || process.env.AUTH_RSA_PUBLIC_KEY || "").replace(/\\n/g, "\n").trim();
811
+ const fromEnv = String(
812
+ process.env.AUTH_JWT_PUBLIC_KEY || process.env.AUTH_RSA_PUBLIC_KEY || ""
813
+ ).replace(/\\n/g, "\n").trim();
788
814
  if (fromEnv) return fromEnv;
789
- throw new Error("Missing RS256 public key (JWT_PUBLIC_KEY_PATH / AUTH_JWT_PUBLIC_KEY / AUTH_RSA_PUBLIC_KEY)");
815
+ throw new Error(
816
+ "Missing RS256 public key (JWT_PUBLIC_KEY_PATH / AUTH_JWT_PUBLIC_KEY / AUTH_RSA_PUBLIC_KEY)"
817
+ );
790
818
  }
791
819
  function verifyBackendJwtRS256(raw) {
792
820
  const publicKey = readRs256PublicKey();
@@ -798,20 +826,31 @@ function verifyBackendJwtRS256(raw) {
798
826
  issuer
799
827
  });
800
828
  }
801
-
802
- // src/auth/middleware.ts
803
- function getBearerToken(req) {
804
- const auth = String(req.headers?.authorization || "");
805
- if (!auth.startsWith("Bearer ")) return null;
806
- const token = auth.slice(7).trim();
807
- return token.length ? token : null;
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;
808
836
  }
809
- function normalizeUid(v) {
810
- const s = String(v ?? "").trim();
811
- return s.length ? s : null;
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;
812
844
  }
845
+
846
+ // src/auth/middleware.ts
813
847
  function createAuthMiddleware(opts) {
814
- const { subject, allowFirebaseIdToken = false, requireSubject = true, hydrate } = opts;
848
+ const {
849
+ subject,
850
+ allowFirebaseIdToken = false,
851
+ requireSubject = true,
852
+ hydrate
853
+ } = opts;
815
854
  return async (req, res, next) => {
816
855
  const token = getBearerToken(req);
817
856
  if (!token) {
@@ -840,8 +879,33 @@ function createAuthMiddleware(opts) {
840
879
  expires_at: decoded?.exp
841
880
  }
842
881
  };
843
- const hydrated = await hydrate({ decoded, req, subject, company_uid, branch_uid });
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
+ });
844
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
+ }
845
909
  if (requireSubject) {
846
910
  if (subject === "employee" && !baseCtx.employee) {
847
911
  return res.status(401).json({
@@ -869,8 +933,8 @@ function createAuthMiddleware(opts) {
869
933
  });
870
934
  }
871
935
  try {
872
- const { default: admin2 } = await import("firebase-admin");
873
- const firebaseDecoded = await admin2.auth().verifyIdToken(token);
936
+ const { default: admin } = await import("firebase-admin");
937
+ const firebaseDecoded = await admin.auth().verifyIdToken(token);
874
938
  if (firebaseDecoded.email && firebaseDecoded.email_verified === false) {
875
939
  return res.status(401).json({
876
940
  ok: false,
@@ -902,169 +966,112 @@ function createAuthMiddleware(opts) {
902
966
  }
903
967
 
904
968
  // src/auth/authentication.ts
905
- var import_firebase_admin = __toESM(require("firebase-admin"), 1);
906
- var import_jsonwebtoken2 = __toESM(require("jsonwebtoken"), 1);
907
- var import_fs3 = __toESM(require("fs"), 1);
908
- function getBearerToken2(req) {
909
- const auth = String(req.headers?.authorization || "");
910
- if (!auth.startsWith("Bearer ")) return null;
911
- const token = auth.slice(7).trim();
912
- return token.length ? token : null;
913
- }
914
- function readPublicKey() {
915
- const publicKeyPath = process.env.JWT_PUBLIC_KEY_PATH;
916
- const publicKeyEnv = process.env.AUTH_JWT_PUBLIC_KEY || process.env.AUTH_RSA_PUBLIC_KEY || "";
917
- if (publicKeyPath) {
918
- const v = import_fs3.default.readFileSync(publicKeyPath, "utf8").trim();
919
- if (v) return v;
920
- }
921
- const envKey = publicKeyEnv.replace(/\\n/g, "\n").trim();
922
- if (envKey) return envKey;
923
- throw new Error("Missing RS256 public key (JWT_PUBLIC_KEY_PATH / AUTH_JWT_PUBLIC_KEY / AUTH_RSA_PUBLIC_KEY)");
924
- }
925
- function verifyBackendJwtRS2562(raw) {
926
- const publicKey = readPublicKey();
927
- const audience = process.env.JWT_AUDIENCE || process.env.AUTH_JWT_AUDIENCE || "getmarket.api";
928
- const issuer = process.env.JWT_ISSUER || process.env.AUTH_JWT_ISSUER || "getmarket-auth";
929
- return import_jsonwebtoken2.default.verify(raw, publicKey, {
930
- algorithms: ["RS256"],
931
- audience,
932
- issuer
933
- });
934
- }
935
- function normalizeUid2(v) {
936
- const s = String(v ?? "").trim();
937
- return s.length ? s : null;
938
- }
939
969
  function deriveCompanyBranch(decoded, companyUid, branchUid) {
940
970
  const companiesFromToken = Array.isArray(decoded?.companies) ? decoded.companies : [];
941
971
  const company = decoded?.company ?? (companyUid ? companiesFromToken.find((c) => c?.uid === companyUid) : null) ?? null;
942
972
  const branch = decoded?.branch ?? (branchUid && company?.branches ? (company.branches || []).find((b) => b?.uid === branchUid) : null) ?? null;
943
- return { companiesFromToken, company, branch };
944
- }
945
- function extractEmployeeUid(decoded) {
946
- const direct = normalizeUid2(decoded?.employee_uid);
947
- if (direct) return direct;
948
- const sub = normalizeUid2(decoded?.sub);
949
- if (!sub) return null;
950
- const m = /^emp:(.+)$/i.exec(sub);
951
- return m?.[1] ? normalizeUid2(m[1]) : null;
952
- }
953
- function extractCustomerUid(decoded) {
954
- const direct = normalizeUid2(decoded?.customer_uid);
955
- if (direct) return direct;
956
- const sub = normalizeUid2(decoded?.sub);
957
- if (!sub) return null;
958
- const m = /^cus:(.+)$/i.exec(sub);
959
- return m?.[1] ? normalizeUid2(m[1]) : null;
960
- }
961
- function createAuthMiddleware2(opts) {
962
- const { subject, allowFirebaseIdToken = false } = opts;
963
- return async (req, res, next) => {
964
- const token = getBearerToken2(req);
965
- if (!token) {
966
- return res.status(401).json({
967
- ok: false,
968
- code: "AUTH_MISSING_TOKEN",
969
- message: "Missing Authorization Bearer token"
970
- });
971
- }
972
- try {
973
- const decoded = verifyBackendJwtRS2562(token);
974
- const headerCtx = req.context || {};
975
- const companyUid = normalizeUid2(headerCtx.company_uid);
976
- const branchUid = normalizeUid2(headerCtx.branch_uid);
977
- const { companiesFromToken, company, branch } = deriveCompanyBranch(decoded, companyUid, branchUid);
978
- const ctx = {
979
- tokenType: "backend",
980
- subject,
981
- company_uid: companyUid ?? void 0,
982
- branch_uid: branchUid ?? void 0,
983
- companies: companiesFromToken,
984
- company,
985
- branch,
986
- roles: Array.isArray(decoded?.roles) ? decoded.roles : [],
987
- permissions: Array.isArray(decoded?.permissions) ? decoded.permissions : [],
988
- denied_permissions: Array.isArray(decoded?.denied_permissions) ? decoded.denied_permissions : [],
989
- session: {
990
- jti: decoded?.jti,
991
- device_id: decoded?.device_id,
992
- expires_at: decoded?.exp
993
- }
994
- };
995
- if (subject === "employee") {
996
- const employee_uid = extractEmployeeUid(decoded);
997
- if (!employee_uid) {
998
- return res.status(401).json({
999
- ok: false,
1000
- code: "AUTH_EMPLOYEE_UID_MISSING",
1001
- message: "employee_uid missing in token (expected employee_uid or sub=emp:<uid>)"
1002
- });
1003
- }
1004
- ctx.employee_uid = employee_uid;
1005
- const embedded = decoded?.employee ?? decoded?.user ?? null;
1006
- ctx.employee = embedded && typeof embedded === "object" ? embedded : { uid: employee_uid, email: decoded?.email ?? null };
1007
- } else {
1008
- const customer_uid = extractCustomerUid(decoded);
1009
- if (!customer_uid) {
1010
- return res.status(401).json({
1011
- ok: false,
1012
- code: "AUTH_CUSTOMER_UID_MISSING",
1013
- message: "customer_uid missing in token (expected customer_uid or sub=cus:<uid>)"
1014
- });
1015
- }
1016
- ctx.customer_uid = customer_uid;
1017
- const embedded = decoded?.customer ?? null;
1018
- ctx.customer = embedded && typeof embedded === "object" ? embedded : { uid: customer_uid };
1019
- }
1020
- req.auth = ctx;
1021
- return next();
1022
- } catch {
1023
- if (!allowFirebaseIdToken) {
1024
- return res.status(401).json({
1025
- ok: false,
1026
- code: "AUTH_INVALID_TOKEN",
1027
- message: "Invalid or expired token"
1028
- });
1029
- }
1030
- try {
1031
- const firebaseDecoded = await import_firebase_admin.default.auth().verifyIdToken(token);
1032
- if (firebaseDecoded.email && firebaseDecoded.email_verified === false) {
1033
- return res.status(401).json({
1034
- ok: false,
1035
- code: "AUTH_EMAIL_NOT_VERIFIED",
1036
- message: "Email not verified"
1037
- });
1038
- }
1039
- const headerCtx = req.context || {};
1040
- const companyUid = normalizeUid2(headerCtx.company_uid);
1041
- const branchUid = normalizeUid2(headerCtx.branch_uid);
1042
- req.auth = {
1043
- tokenType: "backend",
1044
- subject,
1045
- firebase: firebaseDecoded,
1046
- company_uid: companyUid ?? void 0,
1047
- branch_uid: branchUid ?? void 0,
1048
- companies: [],
1049
- roles: [],
1050
- permissions: [],
1051
- denied_permissions: []
1052
- };
1053
- return next();
1054
- } catch {
1055
- return res.status(401).json({
1056
- ok: false,
1057
- code: "AUTH_INVALID_TOKEN",
1058
- message: "Invalid or expired token"
1059
- });
1060
- }
1061
- }
973
+ return {
974
+ companiesFromToken,
975
+ company,
976
+ branch
1062
977
  };
1063
978
  }
1064
- var authEmployeeRequired = createAuthMiddleware2({ subject: "employee", allowFirebaseIdToken: false });
1065
- var authCustomerRequired = createAuthMiddleware2({ subject: "customer", allowFirebaseIdToken: false });
1066
- var authEmployeeAllowFirebase = createAuthMiddleware2({ subject: "employee", allowFirebaseIdToken: true });
1067
- var authCustomerAllowFirebase = createAuthMiddleware2({ subject: "customer", allowFirebaseIdToken: true });
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
+ });
1068
1075
 
1069
1076
  // src/middlewares/guards.ts
1070
1077
  function normalizeRole(r) {
@@ -1184,7 +1191,7 @@ function allowAuthAdminOrPerm(permission) {
1184
1191
  }
1185
1192
 
1186
1193
  // src/internalHttpClient.ts
1187
- var import_fs4 = __toESM(require("fs"), 1);
1194
+ var import_fs3 = __toESM(require("fs"), 1);
1188
1195
  var InternalHttpError = class extends Error {
1189
1196
  status;
1190
1197
  code;
@@ -1199,7 +1206,7 @@ var InternalHttpError = class extends Error {
1199
1206
  function readSecretFile2(path) {
1200
1207
  if (!path) return null;
1201
1208
  try {
1202
- const v = import_fs4.default.readFileSync(path, "utf8").trim();
1209
+ const v = import_fs3.default.readFileSync(path, "utf8").trim();
1203
1210
  return v.length ? v : null;
1204
1211
  } catch {
1205
1212
  return null;
@@ -1481,8 +1488,43 @@ function createResClient() {
1481
1488
  apiPrefix: env.apiPrefix,
1482
1489
  path: "/refs/varieties"
1483
1490
  });
1491
+ const resources = createBulkRefsClient({
1492
+ namespace: "res:resource",
1493
+ baseURL: env.baseURL,
1494
+ apiPrefix: env.apiPrefix,
1495
+ path: "/refs/resources"
1496
+ });
1497
+ const categories = createBulkRefsClient({
1498
+ namespace: "res:category",
1499
+ baseURL: env.baseURL,
1500
+ apiPrefix: env.apiPrefix,
1501
+ path: "/refs/categories"
1502
+ });
1503
+ const attributes = createBulkRefsClient({
1504
+ namespace: "res:attribute",
1505
+ baseURL: env.baseURL,
1506
+ apiPrefix: env.apiPrefix,
1507
+ path: "/refs/attributes"
1508
+ });
1509
+ const attributeOptions = createBulkRefsClient({
1510
+ namespace: "res:attribute_option",
1511
+ baseURL: env.baseURL,
1512
+ apiPrefix: env.apiPrefix,
1513
+ path: "/refs/attribute-options"
1514
+ });
1515
+ const attributeValues = createBulkRefsClient({
1516
+ namespace: "res:attribute_value",
1517
+ baseURL: env.baseURL,
1518
+ apiPrefix: env.apiPrefix,
1519
+ path: "/refs/attribute-values"
1520
+ });
1484
1521
  return {
1485
- varietiesRefs: (uids, opts) => varieties.bulkRefs(uids, opts)
1522
+ varietiesRefs: (uids, opts) => varieties.bulkRefs(uids, opts),
1523
+ resourcesRefs: (uids, opts) => resources.bulkRefs(uids, opts),
1524
+ categoriesRefs: (uids, opts) => categories.bulkRefs(uids, opts),
1525
+ attributesRefs: (uids, opts) => attributes.bulkRefs(uids, opts),
1526
+ attributeOptionsRefs: (uids, opts) => attributeOptions.bulkRefs(uids, opts),
1527
+ attributeValuesRefs: (uids, opts) => attributeValues.bulkRefs(uids, opts)
1486
1528
  };
1487
1529
  }
1488
1530
 
@@ -1507,10 +1549,31 @@ function createMdClient() {
1507
1549
  apiPrefix: env.apiPrefix,
1508
1550
  path: "/refs/countries"
1509
1551
  });
1552
+ const currencies = createBulkRefsClient({
1553
+ namespace: "md:currency",
1554
+ baseURL: env.baseURL,
1555
+ apiPrefix: env.apiPrefix,
1556
+ path: "/refs/currencies"
1557
+ });
1558
+ const regions = createBulkRefsClient({
1559
+ namespace: "md:region",
1560
+ baseURL: env.baseURL,
1561
+ apiPrefix: env.apiPrefix,
1562
+ path: "/refs/regions"
1563
+ });
1564
+ const communes = createBulkRefsClient({
1565
+ namespace: "md:commune",
1566
+ baseURL: env.baseURL,
1567
+ apiPrefix: env.apiPrefix,
1568
+ path: "/refs/communes"
1569
+ });
1510
1570
  return {
1511
1571
  measuresRefs: (uids, opts) => measures.bulkRefs(uids, opts),
1512
1572
  measureTypesRefs: (uids, opts) => measureTypes.bulkRefs(uids, opts),
1513
- countriesRefs: (uids, opts) => countries.bulkRefs(uids, opts)
1573
+ countriesRefs: (uids, opts) => countries.bulkRefs(uids, opts),
1574
+ currenciesRefs: (uids, opts) => currencies.bulkRefs(uids, opts),
1575
+ regionsRefs: (uids, opts) => regions.bulkRefs(uids, opts),
1576
+ communesRefs: (uids, opts) => communes.bulkRefs(uids, opts)
1514
1577
  };
1515
1578
  }
1516
1579
 
@@ -1521,11 +1584,11 @@ function createFisClient() {
1521
1584
  baseURL: `${env.baseURL}${env.apiPrefix}`,
1522
1585
  timeoutMs: 8e3
1523
1586
  });
1524
- const taxes = createBulkRefsClient({
1525
- namespace: "fis:tax",
1587
+ const profiles = createBulkRefsClient({
1588
+ namespace: "fis:profile",
1526
1589
  baseURL: env.baseURL,
1527
1590
  apiPrefix: env.apiPrefix,
1528
- path: "/refs/taxes"
1591
+ path: "/refs/profiles"
1529
1592
  });
1530
1593
  const documents = createBulkRefsClient({
1531
1594
  namespace: "fis:document",
@@ -1533,77 +1596,113 @@ function createFisClient() {
1533
1596
  apiPrefix: env.apiPrefix,
1534
1597
  path: "/refs/documents"
1535
1598
  });
1599
+ const snapshots = createBulkRefsClient({
1600
+ namespace: "fis:snapshot",
1601
+ baseURL: env.baseURL,
1602
+ apiPrefix: env.apiPrefix,
1603
+ path: "/refs/snapshots"
1604
+ });
1536
1605
  const submissions = createBulkRefsClient({
1537
1606
  namespace: "fis:submission",
1538
1607
  baseURL: env.baseURL,
1539
1608
  apiPrefix: env.apiPrefix,
1540
1609
  path: "/refs/submissions"
1541
1610
  });
1611
+ const folioPools = createBulkRefsClient({
1612
+ namespace: "fis:folio_pool",
1613
+ baseURL: env.baseURL,
1614
+ apiPrefix: env.apiPrefix,
1615
+ path: "/refs/folio-pools"
1616
+ });
1617
+ const taxRules = createBulkRefsClient({
1618
+ namespace: "fis:tax_rule",
1619
+ baseURL: env.baseURL,
1620
+ apiPrefix: env.apiPrefix,
1621
+ path: "/refs/tax-rules"
1622
+ });
1542
1623
  return {
1543
1624
  // -----------------------------------------------------------------------
1544
1625
  // Bulk refs
1545
1626
  // -----------------------------------------------------------------------
1546
- taxesRefs: (uids, opts) => taxes.bulkRefs(uids, opts),
1627
+ profilesRefs: (uids, opts) => profiles.bulkRefs(uids, opts),
1547
1628
  documentsRefs: (uids, opts) => documents.bulkRefs(uids, opts),
1629
+ snapshotsRefs: (uids, opts) => snapshots.bulkRefs(uids, opts),
1548
1630
  submissionsRefs: (uids, opts) => submissions.bulkRefs(uids, opts),
1631
+ folioPoolsRefs: (uids, opts) => folioPools.bulkRefs(uids, opts),
1632
+ taxRulesRefs: (uids, opts) => taxRules.bulkRefs(uids, opts),
1549
1633
  // -----------------------------------------------------------------------
1550
1634
  // Fiscal calculation / build / lifecycle
1551
1635
  // -----------------------------------------------------------------------
1552
- calculate: async (body) => {
1636
+ async calculate(body) {
1553
1637
  const { data } = await http.post("/calculate", body);
1554
1638
  return data;
1555
1639
  },
1556
- buildDocument: async (body) => {
1557
- const { data } = await http.post("/documents/build", body);
1640
+ async calculateTaxes(body) {
1641
+ const { data } = await http.post("/tax/calculate", body);
1558
1642
  return data;
1559
1643
  },
1560
- signDocument: async (body) => {
1561
- const { data } = await http.post("/documents/sign", body);
1644
+ async buildDocument(body) {
1645
+ const { data } = await http.post("/documents", body);
1562
1646
  return data;
1563
1647
  },
1564
- submitDocument: async (body) => {
1565
- const { data } = await http.post("/documents/submit", body);
1648
+ async signDocument(body) {
1649
+ const { data } = await http.post(
1650
+ `/documents/${body.document_uid}/sign`,
1651
+ body
1652
+ );
1566
1653
  return data;
1567
1654
  },
1568
- cancelDocument: async (body) => {
1569
- const { data } = await http.post("/documents/cancel", body);
1655
+ async submitDocument(body) {
1656
+ const { data } = await http.post(
1657
+ `/documents/${body.document_uid}/submit`,
1658
+ body
1659
+ );
1660
+ return data;
1661
+ },
1662
+ async cancelDocument(body) {
1663
+ const { data } = await http.post(
1664
+ `/documents/${body.document_uid}/cancel`,
1665
+ body
1666
+ );
1570
1667
  return data;
1571
1668
  },
1572
1669
  // -----------------------------------------------------------------------
1573
1670
  // Folios / series
1574
1671
  // -----------------------------------------------------------------------
1575
- reserveFolio: async (body) => {
1672
+ async reserveFolio(body) {
1576
1673
  const { data } = await http.post("/folios/reserve", body);
1577
1674
  return data;
1578
1675
  },
1579
- consumeFolio: async (body) => {
1676
+ async consumeFolio(body) {
1580
1677
  const { data } = await http.post("/folios/consume", body);
1581
1678
  return data;
1582
1679
  },
1583
1680
  // -----------------------------------------------------------------------
1584
1681
  // Queries / detail
1585
1682
  // -----------------------------------------------------------------------
1586
- queryDocuments: async (params) => {
1587
- const { data } = await http.get("/documents", { params });
1683
+ async queryDocuments(body) {
1684
+ const { data } = await http.post("/documents/query", body);
1588
1685
  return data;
1589
1686
  },
1590
- getDocumentByUid: async (uid) => {
1687
+ async getDocumentByUid(uid) {
1591
1688
  const { data } = await http.get(`/documents/${uid}`);
1592
1689
  return data;
1593
1690
  },
1594
- getSnapshotByUid: async (uid) => {
1691
+ async getSnapshotByUid(uid) {
1595
1692
  const { data } = await http.get(`/snapshots/${uid}`);
1596
1693
  return data;
1597
1694
  },
1598
- getSubmissionByUid: async (uid) => {
1695
+ async getSubmissionByUid(uid) {
1599
1696
  const { data } = await http.get(`/submissions/${uid}`);
1600
1697
  return data;
1601
1698
  },
1602
- getStatusEventsByDocumentUid: async (documentUid) => {
1603
- const { data } = await http.get(`/documents/${documentUid}/status-events`);
1699
+ async getStatusEventsByDocumentUid(documentUid) {
1700
+ const { data } = await http.get(
1701
+ `/documents/${documentUid}/status-events`
1702
+ );
1604
1703
  return data;
1605
1704
  },
1606
- retrySubmission: async (body) => {
1705
+ async retrySubmission(body) {
1607
1706
  const { data } = await http.post("/submissions/retry", body);
1608
1707
  return data;
1609
1708
  }
@@ -1659,25 +1758,107 @@ function createPayClient() {
1659
1758
  baseURL: `${env.baseURL}${env.apiPrefix}`,
1660
1759
  timeoutMs: 8e3
1661
1760
  });
1761
+ const intents = createBulkRefsClient({
1762
+ namespace: "pay:intent",
1763
+ baseURL: env.baseURL,
1764
+ apiPrefix: env.apiPrefix,
1765
+ path: "/refs/intents"
1766
+ });
1767
+ const attempts = createBulkRefsClient({
1768
+ namespace: "pay:attempt",
1769
+ baseURL: env.baseURL,
1770
+ apiPrefix: env.apiPrefix,
1771
+ path: "/refs/attempts"
1772
+ });
1773
+ const transactions = createBulkRefsClient({
1774
+ namespace: "pay:transaction",
1775
+ baseURL: env.baseURL,
1776
+ apiPrefix: env.apiPrefix,
1777
+ path: "/refs/transactions"
1778
+ });
1779
+ const refunds = createBulkRefsClient({
1780
+ namespace: "pay:refund",
1781
+ baseURL: env.baseURL,
1782
+ apiPrefix: env.apiPrefix,
1783
+ path: "/refs/refunds"
1784
+ });
1785
+ const allocations = createBulkRefsClient({
1786
+ namespace: "pay:allocation",
1787
+ baseURL: env.baseURL,
1788
+ apiPrefix: env.apiPrefix,
1789
+ path: "/refs/allocations"
1790
+ });
1791
+ const providerAccounts = createBulkRefsClient({
1792
+ namespace: "pay:provider_account",
1793
+ baseURL: env.baseURL,
1794
+ apiPrefix: env.apiPrefix,
1795
+ path: "/refs/provider-accounts"
1796
+ });
1797
+ const paymentMethods = createBulkRefsClient({
1798
+ namespace: "pay:payment_method",
1799
+ baseURL: env.baseURL,
1800
+ apiPrefix: env.apiPrefix,
1801
+ path: "/refs/payment-methods"
1802
+ });
1662
1803
  return {
1804
+ // -----------------------------------------------------------------------
1805
+ // Payment intents
1806
+ // -----------------------------------------------------------------------
1663
1807
  async createIntent(body) {
1664
- const { data } = await http.post("/intents", body);
1808
+ const { data } = await http.post("/payment-intents", body);
1809
+ return data;
1810
+ },
1811
+ async getIntentByUid(uid) {
1812
+ const { data } = await http.get(`/payment-intents/${uid}`);
1813
+ return data;
1814
+ },
1815
+ async confirmIntent(body) {
1816
+ const { data } = await http.post(
1817
+ `/payment-intents/${body.intent_uid}/confirm`,
1818
+ body
1819
+ );
1665
1820
  return data;
1666
1821
  },
1822
+ // -----------------------------------------------------------------------
1823
+ // Attempts
1824
+ // -----------------------------------------------------------------------
1667
1825
  async startAttempt(body) {
1668
1826
  const { data } = await http.post("/attempts", body);
1669
1827
  return data;
1670
1828
  },
1829
+ // -----------------------------------------------------------------------
1830
+ // Methods / availability
1831
+ // -----------------------------------------------------------------------
1671
1832
  async getAvailableMethods(params) {
1672
1833
  const { data } = await http.get("/methods/available", {
1673
1834
  params
1674
1835
  });
1675
1836
  return data;
1676
1837
  },
1677
- async getIntentByUid(uid) {
1678
- const { data } = await http.get(`/intents/${uid}`);
1838
+ // -----------------------------------------------------------------------
1839
+ // Queries / allocations
1840
+ // -----------------------------------------------------------------------
1841
+ async queryPayments(body) {
1842
+ const { data } = await http.post("/payments/query", body);
1679
1843
  return data;
1680
- }
1844
+ },
1845
+ async getAllocationsByTarget(body) {
1846
+ const { data } = await http.post(
1847
+ "/allocations/by-target",
1848
+ body
1849
+ );
1850
+ return data;
1851
+ },
1852
+ // -----------------------------------------------------------------------
1853
+ // Bulk refs
1854
+ // -----------------------------------------------------------------------
1855
+ intentsRefs: (uids, opts) => intents.bulkRefs(uids, opts),
1856
+ attemptsRefs: (uids, opts) => attempts.bulkRefs(uids, opts),
1857
+ transactionsRefs: (uids, opts) => transactions.bulkRefs(uids, opts),
1858
+ refundsRefs: (uids, opts) => refunds.bulkRefs(uids, opts),
1859
+ allocationsRefs: (uids, opts) => allocations.bulkRefs(uids, opts),
1860
+ providerAccountsRefs: (uids, opts) => providerAccounts.bulkRefs(uids, opts),
1861
+ paymentMethodsRefs: (uids, opts) => paymentMethods.bulkRefs(uids, opts)
1681
1862
  };
1682
1863
  }
1683
1864
 
@@ -1716,7 +1897,6 @@ function isUid(value) {
1716
1897
  buildInternalHeaders,
1717
1898
  closeCache,
1718
1899
  createAuthMiddleware,
1719
- createAuthMiddlewareLegacySimple,
1720
1900
  createBulkRefsClient,
1721
1901
  createFisClient,
1722
1902
  createHttpClient,
@@ -1727,6 +1907,9 @@ function isUid(value) {
1727
1907
  createPayClient,
1728
1908
  createPlatformClient,
1729
1909
  createResClient,
1910
+ extractCustomerUid,
1911
+ extractEmployeeUid,
1912
+ getBearerToken,
1730
1913
  getOrSet,
1731
1914
  getRequestContextFromHeaders,
1732
1915
  getTwoLevelCache,
@@ -1735,6 +1918,7 @@ function isUid(value) {
1735
1918
  mapAxiosToUpstreamError,
1736
1919
  newUid,
1737
1920
  newUidV4,
1921
+ normalizeUid,
1738
1922
  parseHeaders,
1739
1923
  readRs256PublicKey,
1740
1924
  readServiceEnv,
@@ -1746,6 +1930,7 @@ function isUid(value) {
1746
1930
  requireRolesOrAnyPermission,
1747
1931
  sendError,
1748
1932
  sendOk,
1749
- verifyBackendJwtRS256
1933
+ verifyBackendJwtRS256,
1934
+ withRequestIdConfig
1750
1935
  });
1751
1936
  //# sourceMappingURL=index.cjs.map