@pegasimed.com/pegasi-sail-connect-shared 0.1.0-dev.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/README.md +125 -0
- package/dist/audit.d.ts +100 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +112 -0
- package/dist/audit.js.map +1 -0
- package/dist/clinical-operations.d.ts +81 -0
- package/dist/clinical-operations.d.ts.map +1 -0
- package/dist/clinical-operations.js +254 -0
- package/dist/clinical-operations.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/ids.d.ts +3 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +22 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt.d.ts +57 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +219 -0
- package/dist/jwt.js.map +1 -0
- package/dist/phi-redaction.d.ts +47 -0
- package/dist/phi-redaction.d.ts.map +1 -0
- package/dist/phi-redaction.js +126 -0
- package/dist/phi-redaction.js.map +1 -0
- package/dist/stable-json.d.ts +2 -0
- package/dist/stable-json.d.ts.map +1 -0
- package/dist/stable-json.js +28 -0
- package/dist/stable-json.js.map +1 -0
- package/dist/worker-logger.d.ts +14 -0
- package/dist/worker-logger.d.ts.map +1 -0
- package/dist/worker-logger.js +31 -0
- package/dist/worker-logger.js.map +1 -0
- package/package.json +102 -0
- package/scripts/lint-phi.mjs +266 -0
package/dist/jwt.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { createHmac, createPublicKey, createVerify, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export function parseBearerAuthorization(authorization) {
|
|
3
|
+
if (!authorization) {
|
|
4
|
+
throw new Error("Authorization header is required.");
|
|
5
|
+
}
|
|
6
|
+
const [scheme, token, extra] = authorization.split(/\s+/);
|
|
7
|
+
if (scheme !== "Bearer" || !token || extra) {
|
|
8
|
+
throw new Error("Authorization header must use Bearer token format.");
|
|
9
|
+
}
|
|
10
|
+
return token;
|
|
11
|
+
}
|
|
12
|
+
export async function verifyBearerJwt(token, options) {
|
|
13
|
+
const mode = options.mode ?? "hs256";
|
|
14
|
+
const alg = readJwtAlgorithm(token);
|
|
15
|
+
if (alg === "HS256") {
|
|
16
|
+
if (mode === "oidc" || !options.hs256) {
|
|
17
|
+
throw new Error("HS256 JWT verification is not enabled.");
|
|
18
|
+
}
|
|
19
|
+
return verifyHs256JwtWithRotation(token, options.hs256);
|
|
20
|
+
}
|
|
21
|
+
if (mode === "hs256" || !options.oidc) {
|
|
22
|
+
throw new Error(`${alg} JWT verification is not enabled.`);
|
|
23
|
+
}
|
|
24
|
+
return verifyOidcJwt(token, options.oidc);
|
|
25
|
+
}
|
|
26
|
+
export async function verifyBearerAuthorization(authorization, options) {
|
|
27
|
+
return verifyBearerJwt(parseBearerAuthorization(authorization), options);
|
|
28
|
+
}
|
|
29
|
+
export function verifyHs256Jwt(token, options) {
|
|
30
|
+
const minSecretBytes = options.minSecretBytes ?? 32;
|
|
31
|
+
if (Buffer.byteLength(options.secret, "utf8") < minSecretBytes) {
|
|
32
|
+
throw new Error(`HS256 secret must be at least ${minSecretBytes} bytes.`);
|
|
33
|
+
}
|
|
34
|
+
const [encodedHeader, encodedPayload, encodedSignature] = token.split(".");
|
|
35
|
+
if (!encodedHeader || !encodedPayload || !encodedSignature) {
|
|
36
|
+
throw new Error("JWT must have three parts.");
|
|
37
|
+
}
|
|
38
|
+
const header = parseJwtPart(encodedHeader);
|
|
39
|
+
if (header.alg !== "HS256") {
|
|
40
|
+
throw new Error("JWT alg must be HS256.");
|
|
41
|
+
}
|
|
42
|
+
if (header.typ !== undefined && header.typ !== "JWT") {
|
|
43
|
+
throw new Error("JWT typ must be JWT when present.");
|
|
44
|
+
}
|
|
45
|
+
const expectedSignature = hmacSha256Base64Url(`${encodedHeader}.${encodedPayload}`, options.secret);
|
|
46
|
+
if (!constantTimeEqual(encodedSignature, expectedSignature)) {
|
|
47
|
+
throw new Error("JWT signature is invalid.");
|
|
48
|
+
}
|
|
49
|
+
const claims = parseJwtPart(encodedPayload);
|
|
50
|
+
if (typeof claims.sub !== "string" || claims.sub.length === 0) {
|
|
51
|
+
throw new Error("JWT sub claim is required.");
|
|
52
|
+
}
|
|
53
|
+
if (claims.exp !== undefined) {
|
|
54
|
+
if (typeof claims.exp !== "number") {
|
|
55
|
+
throw new Error("JWT exp claim must be numeric.");
|
|
56
|
+
}
|
|
57
|
+
const nowSeconds = options.nowSeconds ?? Math.floor(Date.now() / 1000);
|
|
58
|
+
if (claims.exp <= nowSeconds) {
|
|
59
|
+
throw new Error("JWT is expired.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return claims;
|
|
63
|
+
}
|
|
64
|
+
export async function verifyOidcJwt(token, options) {
|
|
65
|
+
const [encodedHeader, encodedPayload, encodedSignature] = token.split(".");
|
|
66
|
+
if (!encodedHeader || !encodedPayload || !encodedSignature) {
|
|
67
|
+
throw new Error("JWT must have three parts.");
|
|
68
|
+
}
|
|
69
|
+
const header = parseJwtPart(encodedHeader);
|
|
70
|
+
const alg = expectString(header.alg, "JWT alg is required.");
|
|
71
|
+
const allowedAlgorithms = options.allowedAlgorithms ?? ["RS256"];
|
|
72
|
+
if (!allowedAlgorithms.includes(alg)) {
|
|
73
|
+
throw new Error(`JWT alg must be one of ${allowedAlgorithms.join(", ")}.`);
|
|
74
|
+
}
|
|
75
|
+
const kid = expectString(header.kid, "OIDC JWT kid is required.");
|
|
76
|
+
const claims = parseJwtPart(encodedPayload);
|
|
77
|
+
validateRegisteredClaims(claims, options);
|
|
78
|
+
const jwk = await findJwk(kid, options);
|
|
79
|
+
if (!jwk) {
|
|
80
|
+
throw new Error("OIDC signing key was not found in JWKS.");
|
|
81
|
+
}
|
|
82
|
+
const verifier = createVerify("RSA-SHA256");
|
|
83
|
+
verifier.update(`${encodedHeader}.${encodedPayload}`);
|
|
84
|
+
verifier.end();
|
|
85
|
+
const key = createPublicKey({ key: jwk, format: "jwk" });
|
|
86
|
+
if (!verifier.verify(key, Buffer.from(encodedSignature, "base64url"))) {
|
|
87
|
+
throw new Error("JWT signature is invalid.");
|
|
88
|
+
}
|
|
89
|
+
if (typeof claims.sub !== "string" || claims.sub.length === 0) {
|
|
90
|
+
throw new Error("JWT sub claim is required.");
|
|
91
|
+
}
|
|
92
|
+
return claims;
|
|
93
|
+
}
|
|
94
|
+
export function extractJwtRoles(claims, roleClaim = "roles", clientId) {
|
|
95
|
+
const direct = stringArrayClaim(claims[roleClaim]);
|
|
96
|
+
if (direct.length > 0)
|
|
97
|
+
return direct;
|
|
98
|
+
const realmAccess = recordClaim(claims.realm_access);
|
|
99
|
+
const realmRoles = realmAccess ? stringArrayClaim(realmAccess.roles) : [];
|
|
100
|
+
if (realmRoles.length > 0)
|
|
101
|
+
return realmRoles;
|
|
102
|
+
const resourceAccess = recordClaim(claims.resource_access);
|
|
103
|
+
const clientAccess = resourceAccess && clientId ? recordClaim(resourceAccess[clientId]) : null;
|
|
104
|
+
return clientAccess ? stringArrayClaim(clientAccess.roles) : [];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validates an HS256 JWT against {@link VerifyHs256JwtWithRotationOptions.currentSecret}
|
|
108
|
+
* first; if signature verification fails AND a `previousSecret` is provided,
|
|
109
|
+
* retries with that one. Use this in services during the rotation grace
|
|
110
|
+
* period so tokens minted with the old key keep validating until the
|
|
111
|
+
* rotator Lambda flips the previous slot off.
|
|
112
|
+
*
|
|
113
|
+
* Other validation steps (alg, typ, sub, exp) are unchanged. Only the
|
|
114
|
+
* signature verification is dual-key.
|
|
115
|
+
*/
|
|
116
|
+
export function verifyHs256JwtWithRotation(token, options) {
|
|
117
|
+
try {
|
|
118
|
+
return verifyHs256Jwt(token, {
|
|
119
|
+
secret: options.currentSecret,
|
|
120
|
+
...(options.nowSeconds !== undefined ? { nowSeconds: options.nowSeconds } : {}),
|
|
121
|
+
...(options.minSecretBytes !== undefined ? { minSecretBytes: options.minSecretBytes } : {})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
// Only fall back to previous on signature failures, never on alg/typ/sub/exp.
|
|
126
|
+
// That keeps the validation surface identical between the two keys.
|
|
127
|
+
if (!options.previousSecret ||
|
|
128
|
+
!(err instanceof Error) ||
|
|
129
|
+
!err.message.includes("signature is invalid")) {
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
return verifyHs256Jwt(token, {
|
|
133
|
+
secret: options.previousSecret,
|
|
134
|
+
...(options.nowSeconds !== undefined ? { nowSeconds: options.nowSeconds } : {}),
|
|
135
|
+
...(options.minSecretBytes !== undefined ? { minSecretBytes: options.minSecretBytes } : {})
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function readJwtAlgorithm(token) {
|
|
140
|
+
const encodedHeader = token.split(".")[0];
|
|
141
|
+
if (!encodedHeader) {
|
|
142
|
+
throw new Error("JWT must have three parts.");
|
|
143
|
+
}
|
|
144
|
+
return expectString(parseJwtPart(encodedHeader).alg, "JWT alg is required.");
|
|
145
|
+
}
|
|
146
|
+
function parseJwtPart(encoded) {
|
|
147
|
+
try {
|
|
148
|
+
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
149
|
+
const parsed = JSON.parse(decoded);
|
|
150
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
151
|
+
throw new Error("JWT part must decode to an object.");
|
|
152
|
+
}
|
|
153
|
+
return parsed;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
throw new Error("JWT part is not valid base64url JSON.");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function findJwk(kid, options) {
|
|
160
|
+
const jwksUri = options.jwksUri ?? `${options.issuer.replace(/\/+$/, "")}/protocol/openid-connect/certs`;
|
|
161
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
162
|
+
const response = await fetchImpl(jwksUri);
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
throw new Error(`JWKS fetch failed with HTTP ${response.status}.`);
|
|
165
|
+
}
|
|
166
|
+
const document = (await response.json());
|
|
167
|
+
return document.keys?.find((key) => key.kid === kid);
|
|
168
|
+
}
|
|
169
|
+
function validateRegisteredClaims(claims, options) {
|
|
170
|
+
const issuer = options.issuer.replace(/\/+$/, "");
|
|
171
|
+
if (claims.iss !== issuer) {
|
|
172
|
+
throw new Error("JWT iss claim is invalid.");
|
|
173
|
+
}
|
|
174
|
+
if (!audienceMatches(claims.aud, options.audience)) {
|
|
175
|
+
throw new Error("JWT aud claim is invalid.");
|
|
176
|
+
}
|
|
177
|
+
const nowSeconds = options.nowSeconds ?? Math.floor(Date.now() / 1000);
|
|
178
|
+
if (typeof claims.exp !== "number" || claims.exp <= nowSeconds) {
|
|
179
|
+
throw new Error("JWT is expired.");
|
|
180
|
+
}
|
|
181
|
+
if (claims.nbf !== undefined && (typeof claims.nbf !== "number" || claims.nbf > nowSeconds)) {
|
|
182
|
+
throw new Error("JWT nbf claim is invalid.");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function audienceMatches(value, expected) {
|
|
186
|
+
const expectedSet = new Set(Array.isArray(expected) ? expected : [expected]);
|
|
187
|
+
if (typeof value === "string") {
|
|
188
|
+
return expectedSet.has(value);
|
|
189
|
+
}
|
|
190
|
+
if (!Array.isArray(value)) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return value.some((entry) => typeof entry === "string" && expectedSet.has(entry));
|
|
194
|
+
}
|
|
195
|
+
function expectString(value, message) {
|
|
196
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
197
|
+
throw new Error(message);
|
|
198
|
+
}
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
function stringArrayClaim(value) {
|
|
202
|
+
if (!Array.isArray(value))
|
|
203
|
+
return [];
|
|
204
|
+
return value.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
205
|
+
}
|
|
206
|
+
function recordClaim(value) {
|
|
207
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
208
|
+
? value
|
|
209
|
+
: null;
|
|
210
|
+
}
|
|
211
|
+
function hmacSha256Base64Url(input, secret) {
|
|
212
|
+
return createHmac("sha256", secret).update(input).digest("base64url");
|
|
213
|
+
}
|
|
214
|
+
function constantTimeEqual(actual, expected) {
|
|
215
|
+
const actualBuffer = Buffer.from(actual, "utf8");
|
|
216
|
+
const expectedBuffer = Buffer.from(expected, "utf8");
|
|
217
|
+
return actualBuffer.length === expectedBuffer.length && timingSafeEqual(actualBuffer, expectedBuffer);
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=jwt.js.map
|
package/dist/jwt.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmDzF,MAAM,UAAU,wBAAwB,CAAC,aAAiC;IACxE,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1D,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAa,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,EAAE,MAAc;IACxD,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc,EAAE,QAAgB;IACzD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,YAAY,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,IAAI,eAAe,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AACxG,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PHI / PII redaction baseline for PEGASI SAIL/CONNECT structured logs.
|
|
3
|
+
*
|
|
4
|
+
* This module exports the canonical list of JSON paths that should be
|
|
5
|
+
* masked anywhere a payload might be serialized into a log line — the
|
|
6
|
+
* Fastify logger config in each service should pass `PHI_LOG_REDACT_PATHS`
|
|
7
|
+
* (and the matching `redact.censor`) into `pino`. We keep the list here
|
|
8
|
+
* (in pegasi-sail-connect-shared) so consuming services do not drift.
|
|
9
|
+
*
|
|
10
|
+
* The list is intentionally narrow at first: it only covers the obvious
|
|
11
|
+
* direct-identifier fields we ship across the network. The next pass adds
|
|
12
|
+
* a runtime guard that recursively scans request/response payloads for
|
|
13
|
+
* patterns (e.g. "rut", "ssn", "dni", "email", "phone") and warns when an
|
|
14
|
+
* unredacted match shows up.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Fastify uses these as `redact.paths` for its pino logger. The shape is
|
|
18
|
+
* pino's documented JSONpath-lite (no leading "$.", supports wildcards).
|
|
19
|
+
*
|
|
20
|
+
* @see https://getpino.io/#/docs/redaction
|
|
21
|
+
*/
|
|
22
|
+
export declare const PHI_LOG_REDACT_PATHS: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* pino-style censor token. Use `[REDACTED]` so log scanners can grep for
|
|
25
|
+
* accidental misses (an unredacted PHI field will not contain this token).
|
|
26
|
+
*/
|
|
27
|
+
export declare const PHI_LOG_REDACT_CENSOR = "[REDACTED]";
|
|
28
|
+
/**
|
|
29
|
+
* Field-name patterns we treat as suspicious if they appear unredacted.
|
|
30
|
+
* Used by the runtime guard helper below to surface drift between the
|
|
31
|
+
* service's logger config and the canonical list.
|
|
32
|
+
*/
|
|
33
|
+
export declare const PHI_FIELD_NAME_PATTERNS: readonly RegExp[];
|
|
34
|
+
/**
|
|
35
|
+
* Walks an arbitrary value and returns the dotted paths of any keys whose
|
|
36
|
+
* names match {@link PHI_FIELD_NAME_PATTERNS}. Use this in unit tests to
|
|
37
|
+
* fail the build if a service starts emitting PHI through a new field
|
|
38
|
+
* the redact list does not yet cover.
|
|
39
|
+
*
|
|
40
|
+
* Caps recursion depth at 10 and array index inspection at 50 entries to
|
|
41
|
+
* avoid blowing up on large payloads.
|
|
42
|
+
*/
|
|
43
|
+
export declare function findUnredactedPhiPaths(value: unknown, options?: {
|
|
44
|
+
readonly maxDepth?: number;
|
|
45
|
+
readonly maxArray?: number;
|
|
46
|
+
}): readonly string[];
|
|
47
|
+
//# sourceMappingURL=phi-redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phi-redaction.d.ts","sourceRoot":"","sources":["../src/phi-redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,mBAmC/B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,mBAmBlC,CAAC;AAEH;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACvE,SAAS,MAAM,EAAE,CA6BnB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PHI / PII redaction baseline for PEGASI SAIL/CONNECT structured logs.
|
|
3
|
+
*
|
|
4
|
+
* This module exports the canonical list of JSON paths that should be
|
|
5
|
+
* masked anywhere a payload might be serialized into a log line — the
|
|
6
|
+
* Fastify logger config in each service should pass `PHI_LOG_REDACT_PATHS`
|
|
7
|
+
* (and the matching `redact.censor`) into `pino`. We keep the list here
|
|
8
|
+
* (in pegasi-sail-connect-shared) so consuming services do not drift.
|
|
9
|
+
*
|
|
10
|
+
* The list is intentionally narrow at first: it only covers the obvious
|
|
11
|
+
* direct-identifier fields we ship across the network. The next pass adds
|
|
12
|
+
* a runtime guard that recursively scans request/response payloads for
|
|
13
|
+
* patterns (e.g. "rut", "ssn", "dni", "email", "phone") and warns when an
|
|
14
|
+
* unredacted match shows up.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Fastify uses these as `redact.paths` for its pino logger. The shape is
|
|
18
|
+
* pino's documented JSONpath-lite (no leading "$.", supports wildcards).
|
|
19
|
+
*
|
|
20
|
+
* @see https://getpino.io/#/docs/redaction
|
|
21
|
+
*/
|
|
22
|
+
export const PHI_LOG_REDACT_PATHS = Object.freeze([
|
|
23
|
+
// Direct identifiers carried in admission requests + activation runs.
|
|
24
|
+
"*.patient_identifier",
|
|
25
|
+
"*.patient_id",
|
|
26
|
+
"*.mrn",
|
|
27
|
+
"*.medical_record_number",
|
|
28
|
+
"*.rut",
|
|
29
|
+
"*.dni",
|
|
30
|
+
"*.ssn",
|
|
31
|
+
"*.passport_number",
|
|
32
|
+
"*.email",
|
|
33
|
+
"*.phone",
|
|
34
|
+
"*.phone_number",
|
|
35
|
+
"*.date_of_birth",
|
|
36
|
+
"*.dob",
|
|
37
|
+
"*.address",
|
|
38
|
+
"*.full_name",
|
|
39
|
+
"*.given_name",
|
|
40
|
+
"*.family_name",
|
|
41
|
+
// Auth / secret material that must never land in logs.
|
|
42
|
+
"*.password",
|
|
43
|
+
"*.password_hash",
|
|
44
|
+
"*.secret",
|
|
45
|
+
"*.access_token",
|
|
46
|
+
"*.refresh_token",
|
|
47
|
+
"*.id_token",
|
|
48
|
+
"*.jwt",
|
|
49
|
+
"*.private_key",
|
|
50
|
+
"*.api_key",
|
|
51
|
+
"*.client_secret",
|
|
52
|
+
"*.authorization",
|
|
53
|
+
"req.headers.authorization",
|
|
54
|
+
"headers.authorization",
|
|
55
|
+
// Inline payload bodies sometimes contain PHI directly.
|
|
56
|
+
"*.local_payload_inline_base64"
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* pino-style censor token. Use `[REDACTED]` so log scanners can grep for
|
|
60
|
+
* accidental misses (an unredacted PHI field will not contain this token).
|
|
61
|
+
*/
|
|
62
|
+
export const PHI_LOG_REDACT_CENSOR = "[REDACTED]";
|
|
63
|
+
/**
|
|
64
|
+
* Field-name patterns we treat as suspicious if they appear unredacted.
|
|
65
|
+
* Used by the runtime guard helper below to surface drift between the
|
|
66
|
+
* service's logger config and the canonical list.
|
|
67
|
+
*/
|
|
68
|
+
export const PHI_FIELD_NAME_PATTERNS = Object.freeze([
|
|
69
|
+
/^patient[_-]?(id|identifier)$/i,
|
|
70
|
+
/^mrn$/i,
|
|
71
|
+
/^medical[_-]?record[_-]?number$/i,
|
|
72
|
+
/^rut$/i,
|
|
73
|
+
/^dni$/i,
|
|
74
|
+
/^ssn$/i,
|
|
75
|
+
/^email$/i,
|
|
76
|
+
/^phone(_number)?$/i,
|
|
77
|
+
/^date[_-]?of[_-]?birth$/i,
|
|
78
|
+
/^dob$/i,
|
|
79
|
+
/^address$/i,
|
|
80
|
+
/^(full|given|family)[_-]?name$/i,
|
|
81
|
+
/^password(_hash)?$/i,
|
|
82
|
+
/^(access|refresh|id)[_-]?token$/i,
|
|
83
|
+
/^(api|client)[_-]?(key|secret)$/i,
|
|
84
|
+
/^private[_-]?key$/i,
|
|
85
|
+
/^jwt$/i,
|
|
86
|
+
/^authorization$/i
|
|
87
|
+
]);
|
|
88
|
+
/**
|
|
89
|
+
* Walks an arbitrary value and returns the dotted paths of any keys whose
|
|
90
|
+
* names match {@link PHI_FIELD_NAME_PATTERNS}. Use this in unit tests to
|
|
91
|
+
* fail the build if a service starts emitting PHI through a new field
|
|
92
|
+
* the redact list does not yet cover.
|
|
93
|
+
*
|
|
94
|
+
* Caps recursion depth at 10 and array index inspection at 50 entries to
|
|
95
|
+
* avoid blowing up on large payloads.
|
|
96
|
+
*/
|
|
97
|
+
export function findUnredactedPhiPaths(value, options = {}) {
|
|
98
|
+
const maxDepth = options.maxDepth ?? 10;
|
|
99
|
+
const maxArray = options.maxArray ?? 50;
|
|
100
|
+
const matches = [];
|
|
101
|
+
visit(value, "", 0);
|
|
102
|
+
return matches;
|
|
103
|
+
function visit(node, path, depth) {
|
|
104
|
+
if (depth > maxDepth || node === null || node === undefined) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(node)) {
|
|
108
|
+
const limit = Math.min(node.length, maxArray);
|
|
109
|
+
for (let i = 0; i < limit; i += 1) {
|
|
110
|
+
visit(node[i], `${path}[${i}]`, depth + 1);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (typeof node !== "object") {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const [key, child] of Object.entries(node)) {
|
|
118
|
+
const childPath = path ? `${path}.${key}` : key;
|
|
119
|
+
if (PHI_FIELD_NAME_PATTERNS.some((rx) => rx.test(key))) {
|
|
120
|
+
matches.push(childPath);
|
|
121
|
+
}
|
|
122
|
+
visit(child, childPath, depth + 1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=phi-redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phi-redaction.js","sourceRoot":"","sources":["../src/phi-redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,sEAAsE;IACtE,sBAAsB;IACtB,cAAc;IACd,OAAO;IACP,yBAAyB;IACzB,OAAO;IACP,OAAO;IACP,OAAO;IACP,mBAAmB;IACnB,SAAS;IACT,SAAS;IACT,gBAAgB;IAChB,iBAAiB;IACjB,OAAO;IACP,WAAW;IACX,aAAa;IACb,cAAc;IACd,eAAe;IACf,uDAAuD;IACvD,YAAY;IACZ,iBAAiB;IACjB,UAAU;IACV,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IACZ,OAAO;IACP,eAAe;IACf,WAAW;IACX,iBAAiB;IACjB,iBAAiB;IACjB,2BAA2B;IAC3B,uBAAuB;IACvB,wDAAwD;IACxD,+BAA+B;CAChC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAoB;IACtE,gCAAgC;IAChC,QAAQ;IACR,kCAAkC;IAClC,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,oBAAoB;IACpB,0BAA0B;IAC1B,QAAQ;IACR,YAAY;IACZ,iCAAiC;IACjC,qBAAqB;IACrB,kCAAkC;IAClC,kCAAkC;IAClC,oBAAoB;IACpB,QAAQ;IACR,kBAAkB;CACnB,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAc,EACd,UAAsE,EAAE;IAExE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAA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,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stable-json.d.ts","sourceRoot":"","sources":["../src/stable-json.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function stableStringify(value) {
|
|
2
|
+
return JSON.stringify(toStableJsonValue(value, new WeakSet()));
|
|
3
|
+
}
|
|
4
|
+
function toStableJsonValue(value, seen) {
|
|
5
|
+
if (value === null || typeof value !== "object") {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (seen.has(value)) {
|
|
9
|
+
throw new Error("Cannot stableStringify circular data.");
|
|
10
|
+
}
|
|
11
|
+
seen.add(value);
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
const result = value.map((item) => toStableJsonValue(item, seen));
|
|
14
|
+
seen.delete(value);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
const object = value;
|
|
18
|
+
const result = {};
|
|
19
|
+
for (const key of Object.keys(object).sort()) {
|
|
20
|
+
const item = object[key];
|
|
21
|
+
if (item !== undefined) {
|
|
22
|
+
result[key] = toStableJsonValue(item, seen);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
seen.delete(value);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=stable-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stable-json.js","sourceRoot":"","sources":["../src/stable-json.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc,EAAE,IAAqB;IAC9D,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import pino from "pino";
|
|
2
|
+
export interface WorkerLoggerOptions {
|
|
3
|
+
/** Override the LOG_LEVEL env default. */
|
|
4
|
+
readonly level?: pino.LevelWithSilent;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Build a Pino logger pre-configured with the shared PHI redact paths
|
|
8
|
+
* and a `<service>/<component>` name.
|
|
9
|
+
*
|
|
10
|
+
* @param service e.g. "commercial-core-api" — the npm package name root
|
|
11
|
+
* @param component e.g. "outbox-worker" — the worker's role
|
|
12
|
+
*/
|
|
13
|
+
export declare function createWorkerLogger(service: string, component: string, options?: WorkerLoggerOptions): pino.Logger;
|
|
14
|
+
//# sourceMappingURL=worker-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-logger.d.ts","sourceRoot":"","sources":["../src/worker-logger.ts"],"names":[],"mappings":"AAeA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC;CACvC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,mBAAwB,GAChC,IAAI,CAAC,MAAM,CAMb"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Standalone Pino factory for non-Fastify worker processes
|
|
2
|
+
// (events-consumer, outbox dispatcher, projection workers, etc).
|
|
3
|
+
// They run as separate Node processes and don't get the app.log
|
|
4
|
+
// instance configured in each service's platform.ts, but they still
|
|
5
|
+
// need the shared PHI_LOG_REDACT_PATHS applied so accidentally
|
|
6
|
+
// logging a PHI field gets redacted just like in the HTTP path.
|
|
7
|
+
//
|
|
8
|
+
// Pino is bundled with Fastify (peerDependency); we declare it as
|
|
9
|
+
// our own peerDependency too so consumers don't pull a duplicate copy.
|
|
10
|
+
//
|
|
11
|
+
// Usage:
|
|
12
|
+
// import { createWorkerLogger } from "@pegasimed.com/pegasi-sail-connect-shared";
|
|
13
|
+
// const log = createWorkerLogger("commercial-core-api", "outbox-worker");
|
|
14
|
+
// log.info({ result }, "cycle done");
|
|
15
|
+
import pino from "pino";
|
|
16
|
+
import { PHI_LOG_REDACT_CENSOR, PHI_LOG_REDACT_PATHS } from "./phi-redaction.js";
|
|
17
|
+
/**
|
|
18
|
+
* Build a Pino logger pre-configured with the shared PHI redact paths
|
|
19
|
+
* and a `<service>/<component>` name.
|
|
20
|
+
*
|
|
21
|
+
* @param service e.g. "commercial-core-api" — the npm package name root
|
|
22
|
+
* @param component e.g. "outbox-worker" — the worker's role
|
|
23
|
+
*/
|
|
24
|
+
export function createWorkerLogger(service, component, options = {}) {
|
|
25
|
+
return pino({
|
|
26
|
+
name: `${service}/${component}`,
|
|
27
|
+
level: options.level ?? process.env.LOG_LEVEL ?? "info",
|
|
28
|
+
redact: { paths: [...PHI_LOG_REDACT_PATHS], censor: PHI_LOG_REDACT_CENSOR }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=worker-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-logger.js","sourceRoot":"","sources":["../src/worker-logger.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,iEAAiE;AACjE,gEAAgE;AAChE,oEAAoE;AACpE,+DAA+D;AAC/D,gEAAgE;AAChE,EAAE;AACF,kEAAkE;AAClE,uEAAuE;AACvE,EAAE;AACF,SAAS;AACT,oFAAoF;AACpF,4EAA4E;AAC5E,wCAAwC;AAExC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAOjF;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,SAAiB,EACjB,UAA+B,EAAE;IAEjC,OAAO,IAAI,CAAC;QACV,IAAI,EAAE,GAAG,OAAO,IAAI,SAAS,EAAE;QAC/B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAK,OAAO,CAAC,GAAG,CAAC,SAA8C,IAAI,MAAM;QAC7F,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,oBAAoB,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE;KAC5E,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pegasimed.com/pegasi-sail-connect-shared",
|
|
3
|
+
"version": "0.1.0-dev.0",
|
|
4
|
+
"description": "Versioned shared TypeScript helpers for PEGASI SAIL/CONNECT services.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/devops-pegasi/pegasi-sail-connect-shared"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/devops-pegasi/pegasi-sail-connect-shared/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/devops-pegasi/pegasi-sail-connect-shared#readme",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./config": {
|
|
22
|
+
"types": "./dist/config.d.ts",
|
|
23
|
+
"import": "./dist/config.js"
|
|
24
|
+
},
|
|
25
|
+
"./ids": {
|
|
26
|
+
"types": "./dist/ids.d.ts",
|
|
27
|
+
"import": "./dist/ids.js"
|
|
28
|
+
},
|
|
29
|
+
"./audit": {
|
|
30
|
+
"types": "./dist/audit.d.ts",
|
|
31
|
+
"import": "./dist/audit.js"
|
|
32
|
+
},
|
|
33
|
+
"./clinical-operations": {
|
|
34
|
+
"types": "./dist/clinical-operations.d.ts",
|
|
35
|
+
"import": "./dist/clinical-operations.js"
|
|
36
|
+
},
|
|
37
|
+
"./jwt": {
|
|
38
|
+
"types": "./dist/jwt.d.ts",
|
|
39
|
+
"import": "./dist/jwt.js"
|
|
40
|
+
},
|
|
41
|
+
"./phi-redaction": {
|
|
42
|
+
"types": "./dist/phi-redaction.d.ts",
|
|
43
|
+
"import": "./dist/phi-redaction.js"
|
|
44
|
+
},
|
|
45
|
+
"./stable-json": {
|
|
46
|
+
"types": "./dist/stable-json.d.ts",
|
|
47
|
+
"import": "./dist/stable-json.js"
|
|
48
|
+
},
|
|
49
|
+
"./worker-logger": {
|
|
50
|
+
"types": "./dist/worker-logger.d.ts",
|
|
51
|
+
"import": "./dist/worker-logger.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"scripts",
|
|
57
|
+
"README.md"
|
|
58
|
+
],
|
|
59
|
+
"bin": {
|
|
60
|
+
"lint-phi": "./scripts/lint-phi.mjs"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsc -p tsconfig.json",
|
|
64
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
65
|
+
"prepare": "npm run build",
|
|
66
|
+
"lint": "eslint .",
|
|
67
|
+
"test": "vitest run --coverage",
|
|
68
|
+
"validate": "npm run check && npm run lint && npm test"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=22"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public",
|
|
75
|
+
"registry": "https://registry.npmjs.org/"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"fastify": "^5.0.0",
|
|
79
|
+
"pino": "^10.0.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"fastify": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"pino": {
|
|
86
|
+
"optional": false
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@types/node": "^24.10.1",
|
|
91
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
92
|
+
"eslint": "^10.4.1",
|
|
93
|
+
"fastify": "^5.6.2",
|
|
94
|
+
"pino": "^10.3.1",
|
|
95
|
+
"typescript": "^5.9.3",
|
|
96
|
+
"typescript-eslint": "^8.61.0",
|
|
97
|
+
"vitest": "^4.0.14"
|
|
98
|
+
},
|
|
99
|
+
"overrides": {
|
|
100
|
+
"fast-uri": "3.1.2"
|
|
101
|
+
}
|
|
102
|
+
}
|