@innvoid/getmarket-sdk 0.2.2 → 0.2.4
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/cache/index.js +1 -1
- package/dist/{chunk-OSYBK5AN.js → chunk-5S2JP7PR.js} +4 -22
- package/dist/chunk-5S2JP7PR.js.map +1 -0
- package/dist/{chunk-IYFWQDHD.js → chunk-QVPPDOXY.js} +2 -1
- package/dist/chunk-UK6LHHJQ.js +413 -0
- package/dist/chunk-UK6LHHJQ.js.map +1 -0
- package/dist/{chunk-S44JVJZS.js → chunk-WM2QICZQ.js} +16 -1
- package/dist/{chunk-S44JVJZS.js.map → chunk-WM2QICZQ.js.map} +1 -1
- package/dist/clients/index.cjs +699 -0
- package/dist/clients/index.cjs.map +1 -0
- package/dist/clients/index.d.cts +75 -0
- package/dist/clients/index.d.ts +75 -0
- package/dist/clients/index.js +23 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/core/index.cjs +5 -26
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +5 -17
- package/dist/core/index.d.ts +5 -17
- package/dist/core/index.js +3 -8
- package/dist/headers/index.d.cts +3 -16
- package/dist/headers/index.d.ts +3 -16
- package/dist/index.cjs +428 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -3
- package/dist/index.d.ts +52 -3
- package/dist/index.js +34 -16
- package/dist/middlewares/index.cjs +4 -7
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.js +2 -4
- package/dist/parse-C4vk-fmH.d.cts +16 -0
- package/dist/parse-C4vk-fmH.d.ts +16 -0
- package/package.json +11 -3
- package/dist/chunk-KJ64O2EG.js +0 -19
- package/dist/chunk-KJ64O2EG.js.map +0 -1
- package/dist/chunk-OSYBK5AN.js.map +0 -1
- /package/dist/{chunk-IYFWQDHD.js.map → chunk-QVPPDOXY.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(src_exports, {
|
|
|
37
37
|
HEADER_INTERNAL_API_KEY: () => HEADER_INTERNAL_API_KEY,
|
|
38
38
|
HEADER_REQUEST_ID: () => HEADER_REQUEST_ID,
|
|
39
39
|
InternalHttp: () => InternalHttp,
|
|
40
|
+
InternalHttpError: () => InternalHttpError,
|
|
40
41
|
TwoLevelCache: () => TwoLevelCache,
|
|
41
42
|
UpstreamError: () => UpstreamError,
|
|
42
43
|
allowAuthAdminOrPerm: () => allowAuthAdminOrPerm,
|
|
@@ -48,10 +49,19 @@ __export(src_exports, {
|
|
|
48
49
|
authCustomerRequired: () => authCustomerRequired,
|
|
49
50
|
authEmployeeAllowFirebase: () => authEmployeeAllowFirebase,
|
|
50
51
|
authEmployeeRequired: () => authEmployeeRequired,
|
|
52
|
+
buildInternalHeaders: () => buildInternalHeaders,
|
|
51
53
|
closeCache: () => closeCache,
|
|
52
54
|
createAuthMiddleware: () => createAuthMiddleware,
|
|
53
55
|
createAuthMiddlewareLegacySimple: () => createAuthMiddleware2,
|
|
56
|
+
createBulkRefsClient: () => createBulkRefsClient,
|
|
57
|
+
createFisClient: () => createFisClient,
|
|
54
58
|
createHttpClient: () => createHttpClient,
|
|
59
|
+
createInternalHttpClient: () => createInternalHttpClient,
|
|
60
|
+
createMdClient: () => createMdClient,
|
|
61
|
+
createMediaClient: () => createMediaClient,
|
|
62
|
+
createMkpClient: () => createMkpClient,
|
|
63
|
+
createPlatformClient: () => createPlatformClient,
|
|
64
|
+
createResClient: () => createResClient,
|
|
55
65
|
getOrSet: () => getOrSet,
|
|
56
66
|
getRequestContextFromHeaders: () => getRequestContextFromHeaders,
|
|
57
67
|
getTwoLevelCache: () => getTwoLevelCache,
|
|
@@ -59,6 +69,7 @@ __export(src_exports, {
|
|
|
59
69
|
mapAxiosToUpstreamError: () => mapAxiosToUpstreamError,
|
|
60
70
|
parseHeaders: () => parseHeaders,
|
|
61
71
|
readRs256PublicKey: () => readRs256PublicKey,
|
|
72
|
+
readServiceEnv: () => readServiceEnv,
|
|
62
73
|
requestId: () => requestId,
|
|
63
74
|
requireAnyPermission: () => requireAnyPermission,
|
|
64
75
|
requireAuthContext: () => requireAuthContext,
|
|
@@ -67,9 +78,7 @@ __export(src_exports, {
|
|
|
67
78
|
requireRolesOrAnyPermission: () => requireRolesOrAnyPermission,
|
|
68
79
|
sendError: () => sendError,
|
|
69
80
|
sendOk: () => sendOk,
|
|
70
|
-
verifyBackendJwtRS256: () => verifyBackendJwtRS256
|
|
71
|
-
withRequestId: () => withRequestId,
|
|
72
|
-
withRequestIdConfig: () => withRequestIdConfig
|
|
81
|
+
verifyBackendJwtRS256: () => verifyBackendJwtRS256
|
|
73
82
|
});
|
|
74
83
|
module.exports = __toCommonJS(src_exports);
|
|
75
84
|
|
|
@@ -394,39 +403,11 @@ function mapAxiosToUpstreamError(err, svc) {
|
|
|
394
403
|
|
|
395
404
|
// src/core/http.ts
|
|
396
405
|
var import_axios = __toESM(require("axios"), 1);
|
|
397
|
-
|
|
398
|
-
// src/middlewares/requestId.ts
|
|
399
|
-
var import_crypto = require("crypto");
|
|
400
|
-
var REQUEST_ID_HEADER = "x-request-id";
|
|
401
|
-
var REQUEST_ID_HEADER_ALT = "x-requestid";
|
|
402
|
-
var RESPONSE_REQUEST_ID_HEADER = "X-Request-Id";
|
|
403
|
-
function requestId(req, res, next) {
|
|
404
|
-
const headerId = req.headers[REQUEST_ID_HEADER] || req.headers[REQUEST_ID_HEADER_ALT];
|
|
405
|
-
const id = headerId?.trim() || (0, import_crypto.randomUUID)();
|
|
406
|
-
req.requestId = id;
|
|
407
|
-
res.locals.requestId = id;
|
|
408
|
-
res.setHeader(RESPONSE_REQUEST_ID_HEADER, id);
|
|
409
|
-
next();
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// src/core/http.ts
|
|
413
|
-
function withRequestId(headers, requestId2) {
|
|
414
|
-
const h2 = headers && typeof headers === "object" ? { ...headers } : {};
|
|
415
|
-
const rid = (requestId2 || "").trim();
|
|
416
|
-
if (rid) h2[REQUEST_ID_HEADER] = rid;
|
|
417
|
-
return h2;
|
|
418
|
-
}
|
|
419
|
-
function withRequestIdConfig(config = {}, requestId2) {
|
|
420
|
-
return {
|
|
421
|
-
...config,
|
|
422
|
-
headers: withRequestId(config.headers, requestId2)
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
406
|
function createHttpClient(opts) {
|
|
426
407
|
return import_axios.default.create({
|
|
427
|
-
baseURL: opts.baseURL,
|
|
428
|
-
timeout: opts.timeoutMs ??
|
|
429
|
-
headers:
|
|
408
|
+
baseURL: opts.baseURL.replace(/\/+$/, ""),
|
|
409
|
+
timeout: opts.timeoutMs ?? 8e3,
|
|
410
|
+
headers: opts.headers ?? {}
|
|
430
411
|
});
|
|
431
412
|
}
|
|
432
413
|
|
|
@@ -569,6 +550,20 @@ function parseHeaders(req, _res, next) {
|
|
|
569
550
|
next();
|
|
570
551
|
}
|
|
571
552
|
|
|
553
|
+
// src/middlewares/requestId.ts
|
|
554
|
+
var import_crypto = require("crypto");
|
|
555
|
+
var REQUEST_ID_HEADER = "x-request-id";
|
|
556
|
+
var REQUEST_ID_HEADER_ALT = "x-requestid";
|
|
557
|
+
var RESPONSE_REQUEST_ID_HEADER = "X-Request-Id";
|
|
558
|
+
function requestId(req, res, next) {
|
|
559
|
+
const headerId = req.headers[REQUEST_ID_HEADER] || req.headers[REQUEST_ID_HEADER_ALT];
|
|
560
|
+
const id = headerId?.trim() || (0, import_crypto.randomUUID)();
|
|
561
|
+
req.requestId = id;
|
|
562
|
+
res.locals.requestId = id;
|
|
563
|
+
res.setHeader(RESPONSE_REQUEST_ID_HEADER, id);
|
|
564
|
+
next();
|
|
565
|
+
}
|
|
566
|
+
|
|
572
567
|
// src/middlewares/internalAuth.ts
|
|
573
568
|
var import_fs = __toESM(require("fs"), 1);
|
|
574
569
|
var import_crypto2 = __toESM(require("crypto"), 1);
|
|
@@ -1183,6 +1178,393 @@ function allowSysAdminOrRolesOrAnyPermission(roles, permissions) {
|
|
|
1183
1178
|
function allowAuthAdminOrPerm(permission) {
|
|
1184
1179
|
return allowSysAdminOrRolesOrAnyPermission(["AUTH_ADMIN"], [permission]);
|
|
1185
1180
|
}
|
|
1181
|
+
|
|
1182
|
+
// src/internalHttpClient.ts
|
|
1183
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
1184
|
+
var InternalHttpError = class extends Error {
|
|
1185
|
+
status;
|
|
1186
|
+
code;
|
|
1187
|
+
details;
|
|
1188
|
+
constructor(status, code, message, details) {
|
|
1189
|
+
super(message);
|
|
1190
|
+
this.status = status;
|
|
1191
|
+
this.code = code;
|
|
1192
|
+
this.details = details ?? null;
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
function readSecretFile2(path) {
|
|
1196
|
+
if (!path) return null;
|
|
1197
|
+
try {
|
|
1198
|
+
const v = import_fs4.default.readFileSync(path, "utf8").trim();
|
|
1199
|
+
return v.length ? v : null;
|
|
1200
|
+
} catch {
|
|
1201
|
+
return null;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function splitKeys2(v) {
|
|
1205
|
+
if (!v) return [];
|
|
1206
|
+
return v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1207
|
+
}
|
|
1208
|
+
function getInternalApiKey(override) {
|
|
1209
|
+
if (override && override.trim()) return override.trim();
|
|
1210
|
+
const fileKey = readSecretFile2(process.env.INTERNAL_API_KEY_FILE);
|
|
1211
|
+
const envKey = (process.env.INTERNAL_API_KEY || "").trim();
|
|
1212
|
+
const raw = fileKey || envKey;
|
|
1213
|
+
const keys = splitKeys2(raw);
|
|
1214
|
+
return keys[0] || null;
|
|
1215
|
+
}
|
|
1216
|
+
function normalizeBaseURL(baseURL) {
|
|
1217
|
+
const b = (baseURL || "").trim();
|
|
1218
|
+
if (!b) throw new Error("InternalHttpClient: baseURL is required");
|
|
1219
|
+
return b.replace(/\/+$/g, "");
|
|
1220
|
+
}
|
|
1221
|
+
function normalizePrefix(prefix) {
|
|
1222
|
+
const p = (prefix || "").trim();
|
|
1223
|
+
if (!p) return "";
|
|
1224
|
+
const withSlash = p.startsWith("/") ? p : `/${p}`;
|
|
1225
|
+
return withSlash.replace(/\/+$/g, "");
|
|
1226
|
+
}
|
|
1227
|
+
function buildQuery(query) {
|
|
1228
|
+
if (!query) return "";
|
|
1229
|
+
const params = new URLSearchParams();
|
|
1230
|
+
for (const [k, v] of Object.entries(query)) {
|
|
1231
|
+
if (v === null || v === void 0) continue;
|
|
1232
|
+
params.set(k, String(v));
|
|
1233
|
+
}
|
|
1234
|
+
const s = params.toString();
|
|
1235
|
+
return s ? `?${s}` : "";
|
|
1236
|
+
}
|
|
1237
|
+
function buildInternalHeaders(ctx, extra, idempotencyKey) {
|
|
1238
|
+
const h2 = {
|
|
1239
|
+
"Content-Type": "application/json"
|
|
1240
|
+
};
|
|
1241
|
+
if (ctx?.requestId) h2[HEADER_REQUEST_ID] = String(ctx.requestId);
|
|
1242
|
+
if (ctx?.company_uid) h2[HEADER_COMPANY_UID] = String(ctx.company_uid);
|
|
1243
|
+
if (ctx?.branch_uid) h2[HEADER_BRANCH_UID] = String(ctx.branch_uid);
|
|
1244
|
+
if (ctx?.employee_uid) h2[HEADER_EMPLOYEE_UID] = String(ctx.employee_uid);
|
|
1245
|
+
if (idempotencyKey && idempotencyKey.trim()) {
|
|
1246
|
+
h2["Idempotency-Key"] = idempotencyKey.trim();
|
|
1247
|
+
}
|
|
1248
|
+
for (const [k, v] of Object.entries(extra || {})) {
|
|
1249
|
+
if (v === void 0) continue;
|
|
1250
|
+
const vv = String(v).trim();
|
|
1251
|
+
if (!vv) continue;
|
|
1252
|
+
h2[k] = vv;
|
|
1253
|
+
}
|
|
1254
|
+
return h2;
|
|
1255
|
+
}
|
|
1256
|
+
async function sleep2(ms) {
|
|
1257
|
+
await new Promise((r) => setTimeout(r, ms));
|
|
1258
|
+
}
|
|
1259
|
+
function shouldRetry(status, err) {
|
|
1260
|
+
if (err?.name === "AbortError") return true;
|
|
1261
|
+
if (!status) return true;
|
|
1262
|
+
if (status >= 500) return true;
|
|
1263
|
+
if (status === 429) return true;
|
|
1264
|
+
return false;
|
|
1265
|
+
}
|
|
1266
|
+
async function safeReadJson(res) {
|
|
1267
|
+
const text = await res.text();
|
|
1268
|
+
if (!text) return null;
|
|
1269
|
+
try {
|
|
1270
|
+
return JSON.parse(text);
|
|
1271
|
+
} catch {
|
|
1272
|
+
return { raw: text };
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function createInternalHttpClient(opts) {
|
|
1276
|
+
const baseURL = normalizeBaseURL(opts.baseURL);
|
|
1277
|
+
const apiPrefix = normalizePrefix(opts.apiPrefix);
|
|
1278
|
+
const timeoutMs = typeof opts.timeoutMs === "number" ? opts.timeoutMs : 15e3;
|
|
1279
|
+
const retries = typeof opts.retries === "number" ? opts.retries : 2;
|
|
1280
|
+
const retryDelayMs = typeof opts.retryDelayMs === "number" ? opts.retryDelayMs : 250;
|
|
1281
|
+
const apiKey = getInternalApiKey(opts.apiKey ?? null);
|
|
1282
|
+
if (!apiKey) {
|
|
1283
|
+
throw new Error(
|
|
1284
|
+
"InternalHttpClient: INTERNAL_API_KEY or INTERNAL_API_KEY_FILE is required to call internal endpoints."
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
async function request(r) {
|
|
1288
|
+
const path = (r.path || "").trim();
|
|
1289
|
+
if (!path.startsWith("/")) {
|
|
1290
|
+
throw new Error(`InternalHttpClient: path must start with '/': ${path}`);
|
|
1291
|
+
}
|
|
1292
|
+
const url = `${baseURL}${apiPrefix}${path}${buildQuery(r.query)}`;
|
|
1293
|
+
const headers = buildInternalHeaders(r.ctx ?? null, r.headers, r.idempotencyKey ?? null);
|
|
1294
|
+
if (apiKey != null) {
|
|
1295
|
+
headers[HEADER_INTERNAL_API_KEY] = apiKey;
|
|
1296
|
+
}
|
|
1297
|
+
const method = r.method;
|
|
1298
|
+
const expectJson = r.expectJson !== false;
|
|
1299
|
+
const body = method === "GET" || method === "DELETE" ? void 0 : r.body !== void 0 ? JSON.stringify(r.body) : void 0;
|
|
1300
|
+
let attempt = 0;
|
|
1301
|
+
let lastErr = null;
|
|
1302
|
+
while (attempt <= retries) {
|
|
1303
|
+
attempt++;
|
|
1304
|
+
const ac = new AbortController();
|
|
1305
|
+
const to = setTimeout(() => ac.abort(), timeoutMs);
|
|
1306
|
+
try {
|
|
1307
|
+
const res = await fetch(url, {
|
|
1308
|
+
method,
|
|
1309
|
+
headers,
|
|
1310
|
+
body,
|
|
1311
|
+
signal: ac.signal
|
|
1312
|
+
});
|
|
1313
|
+
clearTimeout(to);
|
|
1314
|
+
if (res.ok) {
|
|
1315
|
+
if (!expectJson) return void 0;
|
|
1316
|
+
const data = await safeReadJson(res);
|
|
1317
|
+
return data;
|
|
1318
|
+
}
|
|
1319
|
+
const errBody = await safeReadJson(res);
|
|
1320
|
+
const status = res.status;
|
|
1321
|
+
if (attempt <= retries && shouldRetry(status, null)) {
|
|
1322
|
+
lastErr = new InternalHttpError(
|
|
1323
|
+
status,
|
|
1324
|
+
"INTERNAL_HTTP_RETRY",
|
|
1325
|
+
`Retryable internal HTTP error (${status})`,
|
|
1326
|
+
{ url, status, response: errBody, attempt }
|
|
1327
|
+
);
|
|
1328
|
+
await sleep2(retryDelayMs * attempt);
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
throw new InternalHttpError(
|
|
1332
|
+
status,
|
|
1333
|
+
"INTERNAL_HTTP_ERROR",
|
|
1334
|
+
`Internal HTTP error (${status})`,
|
|
1335
|
+
{ url, status, response: errBody }
|
|
1336
|
+
);
|
|
1337
|
+
} catch (e) {
|
|
1338
|
+
clearTimeout(to);
|
|
1339
|
+
if (attempt <= retries && shouldRetry(null, e)) {
|
|
1340
|
+
lastErr = e;
|
|
1341
|
+
await sleep2(retryDelayMs * attempt);
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
if (e instanceof InternalHttpError) throw e;
|
|
1345
|
+
throw new InternalHttpError(
|
|
1346
|
+
0,
|
|
1347
|
+
"INTERNAL_HTTP_NETWORK_ERROR",
|
|
1348
|
+
e?.message || "Internal HTTP network error",
|
|
1349
|
+
{ url, attempt, error: String(e) }
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
throw lastErr || new InternalHttpError(0, "INTERNAL_HTTP_FAILED", "Internal request failed");
|
|
1354
|
+
}
|
|
1355
|
+
return {
|
|
1356
|
+
request,
|
|
1357
|
+
get: (path, o) => request({ ...o || {}, method: "GET", path }),
|
|
1358
|
+
post: (path, body, o) => request({ ...o || {}, method: "POST", path, body }),
|
|
1359
|
+
put: (path, body, o) => request({ ...o || {}, method: "PUT", path, body }),
|
|
1360
|
+
patch: (path, body, o) => request({ ...o || {}, method: "PATCH", path, body }),
|
|
1361
|
+
del: (path, o) => request({ ...o || {}, method: "DELETE", path })
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// src/clients/env.ts
|
|
1366
|
+
function must(v, name) {
|
|
1367
|
+
const s = (v || "").trim();
|
|
1368
|
+
if (!s) throw new Error(`Missing env var: ${name}`);
|
|
1369
|
+
return s;
|
|
1370
|
+
}
|
|
1371
|
+
function readServiceEnv(prefix, defaults) {
|
|
1372
|
+
const baseURL = (process.env[`${prefix}_BASE_URL`] || defaults?.baseURL || "").trim();
|
|
1373
|
+
const apiPrefix = (process.env[`${prefix}_API_PREFIX`] || defaults?.apiPrefix || "/internal/v1").trim();
|
|
1374
|
+
return {
|
|
1375
|
+
baseURL: must(baseURL, `${prefix}_BASE_URL`),
|
|
1376
|
+
apiPrefix
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// src/clients/cacheFactory.ts
|
|
1381
|
+
function makeRefsCache(namespace) {
|
|
1382
|
+
const l2 = createCacheProvider();
|
|
1383
|
+
return new TwoLevelCache(l2, {
|
|
1384
|
+
namespace,
|
|
1385
|
+
ttlMsL1: 3e4,
|
|
1386
|
+
ttlMsL2: 3e5,
|
|
1387
|
+
negativeTtlMsL1: 3e4,
|
|
1388
|
+
negativeTtlMsL2: 3e4
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/clients/bulkRefsClient.ts
|
|
1393
|
+
function uniq(arr) {
|
|
1394
|
+
return Array.from(new Set(arr.filter(Boolean)));
|
|
1395
|
+
}
|
|
1396
|
+
function createBulkRefsClient(args) {
|
|
1397
|
+
const http = createInternalHttpClient({
|
|
1398
|
+
baseURL: args.baseURL,
|
|
1399
|
+
apiPrefix: args.apiPrefix
|
|
1400
|
+
});
|
|
1401
|
+
const cache = makeRefsCache(args.namespace);
|
|
1402
|
+
async function bulkRefs(uids, opts) {
|
|
1403
|
+
const list = uniq(uids);
|
|
1404
|
+
if (list.length === 0) {
|
|
1405
|
+
return { ok: true, refs: [], meta: { requested: 0, returned: 0, missing: [] } };
|
|
1406
|
+
}
|
|
1407
|
+
const hits = [];
|
|
1408
|
+
const missing = [];
|
|
1409
|
+
for (const uid of list) {
|
|
1410
|
+
const v = await cache.get(uid);
|
|
1411
|
+
if (v) hits.push(v);
|
|
1412
|
+
else missing.push(uid);
|
|
1413
|
+
}
|
|
1414
|
+
let fetched = [];
|
|
1415
|
+
if (missing.length) {
|
|
1416
|
+
const resp = await http.post(
|
|
1417
|
+
args.path,
|
|
1418
|
+
{ uids: missing },
|
|
1419
|
+
{
|
|
1420
|
+
ctx: opts?.ctx ?? null
|
|
1421
|
+
}
|
|
1422
|
+
);
|
|
1423
|
+
const refs = resp.refs ?? resp.items ?? [];
|
|
1424
|
+
fetched = refs;
|
|
1425
|
+
const ttlMsL1 = opts?.ttlMsL1 ?? args.defaultTtlMsL1;
|
|
1426
|
+
const ttlMsL2 = opts?.ttlMsL2 ?? args.defaultTtlMsL2;
|
|
1427
|
+
for (const ref of refs) {
|
|
1428
|
+
const uid = String(ref?.uid || "").trim();
|
|
1429
|
+
if (!uid) continue;
|
|
1430
|
+
await cache.set(uid, ref, {
|
|
1431
|
+
ttlMsL1,
|
|
1432
|
+
ttlMsL2
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
const all = [...hits, ...fetched];
|
|
1437
|
+
const returnedSet = new Set(all.map((r) => String(r?.uid || "")));
|
|
1438
|
+
const missingFinal = list.filter((u) => !returnedSet.has(u));
|
|
1439
|
+
return {
|
|
1440
|
+
ok: true,
|
|
1441
|
+
refs: all,
|
|
1442
|
+
meta: {
|
|
1443
|
+
requested: list.length,
|
|
1444
|
+
returned: all.length,
|
|
1445
|
+
missing: missingFinal
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
return { bulkRefs };
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// src/clients/platformClient.ts
|
|
1453
|
+
function createPlatformClient(env) {
|
|
1454
|
+
const http = createInternalHttpClient(env);
|
|
1455
|
+
const cache = makeRefsCache("platform:tenant");
|
|
1456
|
+
async function resolveTenant(input, ctx) {
|
|
1457
|
+
const key = `${input.company_uid}:${input.service}`;
|
|
1458
|
+
const cached = await cache.get(key);
|
|
1459
|
+
if (cached) return cached;
|
|
1460
|
+
const resp = await http.post(
|
|
1461
|
+
"/tenants/resolve",
|
|
1462
|
+
input,
|
|
1463
|
+
{ ctx: ctx ?? null }
|
|
1464
|
+
);
|
|
1465
|
+
await cache.set(key, resp);
|
|
1466
|
+
return resp;
|
|
1467
|
+
}
|
|
1468
|
+
return { resolveTenant };
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
// src/clients/resClient.ts
|
|
1472
|
+
function createResClient() {
|
|
1473
|
+
const env = readServiceEnv("RES", { apiPrefix: "/internal/v1" });
|
|
1474
|
+
const varieties = createBulkRefsClient({
|
|
1475
|
+
namespace: "res:variety",
|
|
1476
|
+
baseURL: env.baseURL,
|
|
1477
|
+
apiPrefix: env.apiPrefix,
|
|
1478
|
+
path: "/refs/varieties"
|
|
1479
|
+
});
|
|
1480
|
+
return {
|
|
1481
|
+
varietiesRefs: (uids, opts) => varieties.bulkRefs(uids, opts)
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// src/clients/mdClient.ts
|
|
1486
|
+
function createMdClient() {
|
|
1487
|
+
const env = readServiceEnv("MD", { apiPrefix: "/internal/v1" });
|
|
1488
|
+
const measures = createBulkRefsClient({
|
|
1489
|
+
namespace: "md:measure",
|
|
1490
|
+
baseURL: env.baseURL,
|
|
1491
|
+
apiPrefix: env.apiPrefix,
|
|
1492
|
+
path: "/refs/measures"
|
|
1493
|
+
});
|
|
1494
|
+
const measureTypes = createBulkRefsClient({
|
|
1495
|
+
namespace: "md:measure_type",
|
|
1496
|
+
baseURL: env.baseURL,
|
|
1497
|
+
apiPrefix: env.apiPrefix,
|
|
1498
|
+
path: "/refs/measure-types"
|
|
1499
|
+
});
|
|
1500
|
+
const countries = createBulkRefsClient({
|
|
1501
|
+
namespace: "md:country",
|
|
1502
|
+
baseURL: env.baseURL,
|
|
1503
|
+
apiPrefix: env.apiPrefix,
|
|
1504
|
+
path: "/refs/countries"
|
|
1505
|
+
});
|
|
1506
|
+
return {
|
|
1507
|
+
measuresRefs: (uids, opts) => measures.bulkRefs(uids, opts),
|
|
1508
|
+
measureTypesRefs: (uids, opts) => measureTypes.bulkRefs(uids, opts),
|
|
1509
|
+
countriesRefs: (uids, opts) => countries.bulkRefs(uids, opts)
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// src/clients/fisClient.ts
|
|
1514
|
+
function createFisClient() {
|
|
1515
|
+
const env = readServiceEnv("FIS", { apiPrefix: "/internal/v1" });
|
|
1516
|
+
const taxes = createBulkRefsClient({
|
|
1517
|
+
namespace: "fis:tax",
|
|
1518
|
+
baseURL: env.baseURL,
|
|
1519
|
+
apiPrefix: env.apiPrefix,
|
|
1520
|
+
path: "/refs/taxes"
|
|
1521
|
+
});
|
|
1522
|
+
return {
|
|
1523
|
+
taxesRefs: (uids, opts) => taxes.bulkRefs(uids, opts)
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/clients/mediaClient.ts
|
|
1528
|
+
function createMediaClient() {
|
|
1529
|
+
const env = readServiceEnv("MEDIA", { apiPrefix: "/internal/v1" });
|
|
1530
|
+
const files = createBulkRefsClient({
|
|
1531
|
+
namespace: "media:file",
|
|
1532
|
+
baseURL: env.baseURL,
|
|
1533
|
+
apiPrefix: env.apiPrefix,
|
|
1534
|
+
path: "/refs/files"
|
|
1535
|
+
});
|
|
1536
|
+
return {
|
|
1537
|
+
filesRefs: (uids, opts) => files.bulkRefs(uids, opts)
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// src/clients/mkpClient.ts
|
|
1542
|
+
function createMkpClient() {
|
|
1543
|
+
const env = readServiceEnv("MKP", { apiPrefix: "/internal/v1" });
|
|
1544
|
+
const publications = createBulkRefsClient({
|
|
1545
|
+
namespace: "mkp:publication",
|
|
1546
|
+
baseURL: env.baseURL,
|
|
1547
|
+
apiPrefix: env.apiPrefix,
|
|
1548
|
+
path: "/refs/publications"
|
|
1549
|
+
});
|
|
1550
|
+
const events = createBulkRefsClient({
|
|
1551
|
+
namespace: "mkp:event",
|
|
1552
|
+
baseURL: env.baseURL,
|
|
1553
|
+
apiPrefix: env.apiPrefix,
|
|
1554
|
+
path: "/refs/events"
|
|
1555
|
+
});
|
|
1556
|
+
const promotions = createBulkRefsClient({
|
|
1557
|
+
namespace: "mkp:promotion",
|
|
1558
|
+
baseURL: env.baseURL,
|
|
1559
|
+
apiPrefix: env.apiPrefix,
|
|
1560
|
+
path: "/refs/promotions"
|
|
1561
|
+
});
|
|
1562
|
+
return {
|
|
1563
|
+
publicationsRefs: (uids, opts) => publications.bulkRefs(uids, opts),
|
|
1564
|
+
eventsRefs: (uids, opts) => events.bulkRefs(uids, opts),
|
|
1565
|
+
promotionsRefs: (uids, opts) => promotions.bulkRefs(uids, opts)
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1186
1568
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1187
1569
|
0 && (module.exports = {
|
|
1188
1570
|
HEADER_AUTHORIZATION,
|
|
@@ -1192,6 +1574,7 @@ function allowAuthAdminOrPerm(permission) {
|
|
|
1192
1574
|
HEADER_INTERNAL_API_KEY,
|
|
1193
1575
|
HEADER_REQUEST_ID,
|
|
1194
1576
|
InternalHttp,
|
|
1577
|
+
InternalHttpError,
|
|
1195
1578
|
TwoLevelCache,
|
|
1196
1579
|
UpstreamError,
|
|
1197
1580
|
allowAuthAdminOrPerm,
|
|
@@ -1203,10 +1586,19 @@ function allowAuthAdminOrPerm(permission) {
|
|
|
1203
1586
|
authCustomerRequired,
|
|
1204
1587
|
authEmployeeAllowFirebase,
|
|
1205
1588
|
authEmployeeRequired,
|
|
1589
|
+
buildInternalHeaders,
|
|
1206
1590
|
closeCache,
|
|
1207
1591
|
createAuthMiddleware,
|
|
1208
1592
|
createAuthMiddlewareLegacySimple,
|
|
1593
|
+
createBulkRefsClient,
|
|
1594
|
+
createFisClient,
|
|
1209
1595
|
createHttpClient,
|
|
1596
|
+
createInternalHttpClient,
|
|
1597
|
+
createMdClient,
|
|
1598
|
+
createMediaClient,
|
|
1599
|
+
createMkpClient,
|
|
1600
|
+
createPlatformClient,
|
|
1601
|
+
createResClient,
|
|
1210
1602
|
getOrSet,
|
|
1211
1603
|
getRequestContextFromHeaders,
|
|
1212
1604
|
getTwoLevelCache,
|
|
@@ -1214,6 +1606,7 @@ function allowAuthAdminOrPerm(permission) {
|
|
|
1214
1606
|
mapAxiosToUpstreamError,
|
|
1215
1607
|
parseHeaders,
|
|
1216
1608
|
readRs256PublicKey,
|
|
1609
|
+
readServiceEnv,
|
|
1217
1610
|
requestId,
|
|
1218
1611
|
requireAnyPermission,
|
|
1219
1612
|
requireAuthContext,
|
|
@@ -1222,8 +1615,6 @@ function allowAuthAdminOrPerm(permission) {
|
|
|
1222
1615
|
requireRolesOrAnyPermission,
|
|
1223
1616
|
sendError,
|
|
1224
1617
|
sendOk,
|
|
1225
|
-
verifyBackendJwtRS256
|
|
1226
|
-
withRequestId,
|
|
1227
|
-
withRequestIdConfig
|
|
1618
|
+
verifyBackendJwtRS256
|
|
1228
1619
|
});
|
|
1229
1620
|
//# sourceMappingURL=index.cjs.map
|