@digilogiclabs/platform-core 1.20.1 → 1.21.0
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/{ConsoleEmail-CO0OM4UT.d.ts → ConsoleEmail-BbdpINKx.d.ts} +4 -46
- package/dist/{ConsoleEmail-DDB28vyS.d.mts → ConsoleEmail-DpxhsG9C.d.mts} +4 -46
- package/dist/{IAI-D8wA_i8N.d.mts → IAI-CWd11dzL.d.mts} +1 -105
- package/dist/{IAI-D8wA_i8N.d.ts → IAI-CWd11dzL.d.ts} +1 -105
- package/dist/IEmail-CsOcaQcb.d.mts +45 -0
- package/dist/IEmail-CsOcaQcb.d.ts +45 -0
- package/dist/ILogger-DLDBZaH4.d.mts +105 -0
- package/dist/ILogger-DLDBZaH4.d.ts +105 -0
- package/dist/{agents-Cc65YUoW.d.ts → agents-C42rGwRl.d.ts} +2 -1
- package/dist/{agents-DGciJI27.d.mts → agents-CES-Aq1K.d.mts} +2 -1
- package/dist/agents.d.mts +3 -2
- package/dist/agents.d.ts +3 -2
- package/dist/auth.d.mts +238 -1
- package/dist/auth.d.ts +238 -1
- package/dist/auth.js +198 -0
- package/dist/auth.js.map +1 -1
- package/dist/auth.mjs +183 -0
- package/dist/auth.mjs.map +1 -1
- package/dist/circuit-breaker-CP6kw0P5.d.ts +351 -0
- package/dist/circuit-breaker-CsQivd57.d.mts +351 -0
- package/dist/email-templates.d.mts +106 -1
- package/dist/email-templates.d.ts +106 -1
- package/dist/email-templates.js +608 -0
- package/dist/email-templates.js.map +1 -1
- package/dist/email-templates.mjs +596 -0
- package/dist/email-templates.mjs.map +1 -1
- package/dist/index.d.mts +12 -355
- package/dist/index.d.ts +12 -355
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -7
- package/dist/index.mjs.map +1 -1
- package/dist/migrate.js +0 -0
- package/dist/pdf-exports/index.d.mts +63 -3
- package/dist/pdf-exports/index.d.ts +63 -3
- package/dist/pdf-exports/index.js +21 -4
- package/dist/pdf-exports/index.js.map +1 -1
- package/dist/pdf-exports/index.mjs +20 -4
- package/dist/pdf-exports/index.mjs.map +1 -1
- package/dist/testing.d.mts +5 -3
- package/dist/testing.d.ts +5 -3
- package/package.json +11 -11
package/dist/auth.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/auth/index.ts
|
|
@@ -61,6 +71,7 @@ __export(auth_exports, {
|
|
|
61
71
|
createBetaClient: () => createBetaClient,
|
|
62
72
|
createEnsureUser: () => createEnsureUser,
|
|
63
73
|
createFeatureFlags: () => createFeatureFlags,
|
|
74
|
+
createHealthRoute: () => createHealthRoute,
|
|
64
75
|
createLazyRateLimitStore: () => createLazyRateLimitStore,
|
|
65
76
|
createMemoryRateLimitStore: () => createMemoryRateLimitStore,
|
|
66
77
|
createRedisRateLimitStore: () => createRedisRateLimitStore,
|
|
@@ -92,6 +103,7 @@ __export(auth_exports, {
|
|
|
92
103
|
hasRole: () => hasRole,
|
|
93
104
|
isAllowlisted: () => isAllowlisted,
|
|
94
105
|
isApiError: () => isApiError,
|
|
106
|
+
isHoneypotFilled: () => isHoneypotFilled,
|
|
95
107
|
isTokenExpired: () => isTokenExpired,
|
|
96
108
|
isValidBearerToken: () => isValidBearerToken,
|
|
97
109
|
parseKeycloakRoles: () => parseKeycloakRoles,
|
|
@@ -100,8 +112,10 @@ __export(auth_exports, {
|
|
|
100
112
|
resetRateLimitForKey: () => resetRateLimitForKey,
|
|
101
113
|
resolveIdentifier: () => resolveIdentifier,
|
|
102
114
|
resolveRateLimitIdentifier: () => resolveRateLimitIdentifier,
|
|
115
|
+
safeRedirect: () => safeRedirect,
|
|
103
116
|
safeValidate: () => safeValidate,
|
|
104
117
|
sanitizeApiError: () => sanitizeApiError,
|
|
118
|
+
signToken: () => signToken,
|
|
105
119
|
storeBetaCode: () => storeBetaCode,
|
|
106
120
|
stripHtml: () => stripHtml,
|
|
107
121
|
stripNullBytes: () => stripNullBytes,
|
|
@@ -109,6 +123,7 @@ __export(auth_exports, {
|
|
|
109
123
|
validateBetaCode: () => validateBetaCode,
|
|
110
124
|
validateEnvVars: () => validateEnvVars,
|
|
111
125
|
verifyCronAuth: () => verifyCronAuth,
|
|
126
|
+
verifyToken: () => verifyToken,
|
|
112
127
|
zodErrorResponse: () => zodErrorResponse
|
|
113
128
|
});
|
|
114
129
|
module.exports = __toCommonJS(auth_exports);
|
|
@@ -1941,6 +1956,184 @@ function computeClaimDelta(current, newEmail, newName) {
|
|
|
1941
1956
|
return changed ? delta : null;
|
|
1942
1957
|
}
|
|
1943
1958
|
|
|
1959
|
+
// src/auth/tokens.ts
|
|
1960
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
1961
|
+
var HMAC_HEX_CHARS = 16;
|
|
1962
|
+
function validateSecret(secret) {
|
|
1963
|
+
if (typeof secret !== "string" || secret.length < 16) {
|
|
1964
|
+
throw new Error(
|
|
1965
|
+
"signToken/verifyToken require a secret of at least 16 characters"
|
|
1966
|
+
);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
function computeHmac(secret, signedPart) {
|
|
1970
|
+
return import_node_crypto.default.createHmac("sha256", secret).update(signedPart).digest("hex").slice(0, HMAC_HEX_CHARS);
|
|
1971
|
+
}
|
|
1972
|
+
function signToken(opts) {
|
|
1973
|
+
validateSecret(opts.secret);
|
|
1974
|
+
if (typeof opts.payload !== "string" || opts.payload.length === 0) {
|
|
1975
|
+
throw new Error("signToken requires a non-empty payload string");
|
|
1976
|
+
}
|
|
1977
|
+
const signedPart = opts.ttlSeconds !== void 0 ? `${opts.payload}.${Math.floor(Date.now() / 1e3)}` : opts.payload;
|
|
1978
|
+
const encoded = Buffer.from(signedPart, "utf-8").toString("base64url");
|
|
1979
|
+
const hmac = computeHmac(opts.secret, signedPart);
|
|
1980
|
+
return `${encoded}.${hmac}`;
|
|
1981
|
+
}
|
|
1982
|
+
function verifyToken(token, opts) {
|
|
1983
|
+
validateSecret(opts.secret);
|
|
1984
|
+
if (typeof token !== "string" || token.length === 0) {
|
|
1985
|
+
return { valid: false, reason: "malformed" };
|
|
1986
|
+
}
|
|
1987
|
+
const lastDot = token.lastIndexOf(".");
|
|
1988
|
+
if (lastDot <= 0 || lastDot === token.length - 1) {
|
|
1989
|
+
return { valid: false, reason: "malformed" };
|
|
1990
|
+
}
|
|
1991
|
+
const encoded = token.slice(0, lastDot);
|
|
1992
|
+
const providedHmac = token.slice(lastDot + 1);
|
|
1993
|
+
let signedPart;
|
|
1994
|
+
try {
|
|
1995
|
+
signedPart = Buffer.from(encoded, "base64url").toString("utf-8");
|
|
1996
|
+
} catch {
|
|
1997
|
+
return { valid: false, reason: "malformed" };
|
|
1998
|
+
}
|
|
1999
|
+
if (signedPart.length === 0) {
|
|
2000
|
+
return { valid: false, reason: "malformed" };
|
|
2001
|
+
}
|
|
2002
|
+
const expectedHmac = computeHmac(opts.secret, signedPart);
|
|
2003
|
+
if (providedHmac.length !== expectedHmac.length || !import_node_crypto.default.timingSafeEqual(
|
|
2004
|
+
Buffer.from(providedHmac, "utf-8"),
|
|
2005
|
+
Buffer.from(expectedHmac, "utf-8")
|
|
2006
|
+
)) {
|
|
2007
|
+
return { valid: false, reason: "bad_signature" };
|
|
2008
|
+
}
|
|
2009
|
+
const tsDot = signedPart.lastIndexOf(".");
|
|
2010
|
+
let payload = signedPart;
|
|
2011
|
+
let issuedAt;
|
|
2012
|
+
if (tsDot > 0) {
|
|
2013
|
+
const tsCandidate = signedPart.slice(tsDot + 1);
|
|
2014
|
+
const tsNum = Number(tsCandidate);
|
|
2015
|
+
if (Number.isFinite(tsNum) && /^\d+$/.test(tsCandidate)) {
|
|
2016
|
+
payload = signedPart.slice(0, tsDot);
|
|
2017
|
+
issuedAt = tsNum;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
if (opts.maxAgeSeconds !== void 0 && issuedAt !== void 0) {
|
|
2021
|
+
const ageSeconds = Math.floor(Date.now() / 1e3) - issuedAt;
|
|
2022
|
+
if (ageSeconds > opts.maxAgeSeconds) {
|
|
2023
|
+
return { valid: false, reason: "expired" };
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
return issuedAt !== void 0 ? { valid: true, payload, issuedAt } : { valid: true, payload };
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
// src/auth/redirect.ts
|
|
2030
|
+
var DANGEROUS_PROTOCOLS = /* @__PURE__ */ new Set([
|
|
2031
|
+
"javascript:",
|
|
2032
|
+
"data:",
|
|
2033
|
+
"vbscript:",
|
|
2034
|
+
"file:"
|
|
2035
|
+
]);
|
|
2036
|
+
function safeRedirect(candidate, opts) {
|
|
2037
|
+
if (typeof candidate !== "string" || candidate.length === 0) {
|
|
2038
|
+
return opts.fallback;
|
|
2039
|
+
}
|
|
2040
|
+
const trimmed = candidate.trim();
|
|
2041
|
+
if (trimmed.length === 0) {
|
|
2042
|
+
return opts.fallback;
|
|
2043
|
+
}
|
|
2044
|
+
if (trimmed.startsWith("//")) {
|
|
2045
|
+
return opts.fallback;
|
|
2046
|
+
}
|
|
2047
|
+
if (trimmed.startsWith("/")) {
|
|
2048
|
+
return trimmed;
|
|
2049
|
+
}
|
|
2050
|
+
let url;
|
|
2051
|
+
try {
|
|
2052
|
+
url = new URL(trimmed);
|
|
2053
|
+
} catch {
|
|
2054
|
+
return opts.fallback;
|
|
2055
|
+
}
|
|
2056
|
+
if (DANGEROUS_PROTOCOLS.has(url.protocol.toLowerCase())) {
|
|
2057
|
+
return opts.fallback;
|
|
2058
|
+
}
|
|
2059
|
+
const candidateOrigin = url.origin.toLowerCase();
|
|
2060
|
+
const allowed = opts.allowedOrigins.some(
|
|
2061
|
+
(o) => o.toLowerCase() === candidateOrigin
|
|
2062
|
+
);
|
|
2063
|
+
if (!allowed) {
|
|
2064
|
+
return opts.fallback;
|
|
2065
|
+
}
|
|
2066
|
+
return url.toString();
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
// src/auth/honeypot.ts
|
|
2070
|
+
var DEFAULT_FIELD_NAME = "_hp";
|
|
2071
|
+
function isHoneypotFilled(body, fieldName = DEFAULT_FIELD_NAME) {
|
|
2072
|
+
if (body == null) return false;
|
|
2073
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) {
|
|
2074
|
+
const value2 = body.get(fieldName);
|
|
2075
|
+
return typeof value2 === "string" && value2.trim().length > 0;
|
|
2076
|
+
}
|
|
2077
|
+
if (typeof body !== "object") return false;
|
|
2078
|
+
const value = body[fieldName];
|
|
2079
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
// src/auth/health-route.ts
|
|
2083
|
+
var DEFAULT_TIMEOUT_MS = 2e3;
|
|
2084
|
+
async function withTimeoutOrError(probe, timeoutMs) {
|
|
2085
|
+
try {
|
|
2086
|
+
const result = await Promise.race([
|
|
2087
|
+
probe(),
|
|
2088
|
+
new Promise(
|
|
2089
|
+
(_, reject) => setTimeout(() => reject(new Error("probe timed out")), timeoutMs)
|
|
2090
|
+
)
|
|
2091
|
+
]);
|
|
2092
|
+
return result;
|
|
2093
|
+
} catch {
|
|
2094
|
+
return { status: "error" };
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
function createHealthRoute(opts) {
|
|
2098
|
+
const names = Object.keys(opts.checks);
|
|
2099
|
+
return async function GET() {
|
|
2100
|
+
const probeResults = await Promise.all(
|
|
2101
|
+
names.map(async (name) => {
|
|
2102
|
+
const check = opts.checks[name];
|
|
2103
|
+
const result = await withTimeoutOrError(
|
|
2104
|
+
check.probe,
|
|
2105
|
+
check.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
2106
|
+
);
|
|
2107
|
+
return [name, result];
|
|
2108
|
+
})
|
|
2109
|
+
);
|
|
2110
|
+
const services = {};
|
|
2111
|
+
let degraded = false;
|
|
2112
|
+
for (const [name, result] of probeResults) {
|
|
2113
|
+
services[name] = result;
|
|
2114
|
+
const check = opts.checks[name];
|
|
2115
|
+
if (check.gating && result.status === "error") {
|
|
2116
|
+
degraded = true;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
const body = {
|
|
2120
|
+
status: degraded ? "degraded" : "healthy",
|
|
2121
|
+
services
|
|
2122
|
+
};
|
|
2123
|
+
if (opts.extraBody) {
|
|
2124
|
+
try {
|
|
2125
|
+
const extra = await opts.extraBody();
|
|
2126
|
+
Object.assign(body, extra);
|
|
2127
|
+
} catch {
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
return new Response(JSON.stringify(body), {
|
|
2131
|
+
status: degraded ? 503 : 200,
|
|
2132
|
+
headers: { "content-type": "application/json" }
|
|
2133
|
+
});
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
|
|
1944
2137
|
// src/env.ts
|
|
1945
2138
|
function getRequiredEnv(key) {
|
|
1946
2139
|
const value = process.env[key];
|
|
@@ -2074,6 +2267,7 @@ function getEnvSummary(keys) {
|
|
|
2074
2267
|
createBetaClient,
|
|
2075
2268
|
createEnsureUser,
|
|
2076
2269
|
createFeatureFlags,
|
|
2270
|
+
createHealthRoute,
|
|
2077
2271
|
createLazyRateLimitStore,
|
|
2078
2272
|
createMemoryRateLimitStore,
|
|
2079
2273
|
createRedisRateLimitStore,
|
|
@@ -2105,6 +2299,7 @@ function getEnvSummary(keys) {
|
|
|
2105
2299
|
hasRole,
|
|
2106
2300
|
isAllowlisted,
|
|
2107
2301
|
isApiError,
|
|
2302
|
+
isHoneypotFilled,
|
|
2108
2303
|
isTokenExpired,
|
|
2109
2304
|
isValidBearerToken,
|
|
2110
2305
|
parseKeycloakRoles,
|
|
@@ -2113,8 +2308,10 @@ function getEnvSummary(keys) {
|
|
|
2113
2308
|
resetRateLimitForKey,
|
|
2114
2309
|
resolveIdentifier,
|
|
2115
2310
|
resolveRateLimitIdentifier,
|
|
2311
|
+
safeRedirect,
|
|
2116
2312
|
safeValidate,
|
|
2117
2313
|
sanitizeApiError,
|
|
2314
|
+
signToken,
|
|
2118
2315
|
storeBetaCode,
|
|
2119
2316
|
stripHtml,
|
|
2120
2317
|
stripNullBytes,
|
|
@@ -2122,6 +2319,7 @@ function getEnvSummary(keys) {
|
|
|
2122
2319
|
validateBetaCode,
|
|
2123
2320
|
validateEnvVars,
|
|
2124
2321
|
verifyCronAuth,
|
|
2322
|
+
verifyToken,
|
|
2125
2323
|
zodErrorResponse
|
|
2126
2324
|
});
|
|
2127
2325
|
//# sourceMappingURL=auth.js.map
|