@pegasimed.com/pegasi-sail-connect-shared 0.2.0-dev.1 → 0.2.0-dev.2
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 +76 -10
- package/dist/authorization/index.d.ts +1 -0
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +1 -0
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/work-grants.d.ts +151 -0
- package/dist/authorization/work-grants.d.ts.map +1 -0
- package/dist/authorization/work-grants.js +306 -0
- package/dist/authorization/work-grants.js.map +1 -0
- package/dist/capabilities/canonical-json.d.ts +3 -0
- package/dist/capabilities/canonical-json.d.ts.map +1 -0
- package/dist/capabilities/canonical-json.js +83 -0
- package/dist/capabilities/canonical-json.js.map +1 -0
- package/dist/capabilities/catalog-data.d.ts +386 -221
- package/dist/capabilities/catalog-data.d.ts.map +1 -1
- package/dist/capabilities/catalog-data.js +401 -226
- package/dist/capabilities/catalog-data.js.map +1 -1
- package/dist/capabilities/catalog.d.ts.map +1 -1
- package/dist/capabilities/catalog.js +4 -4
- package/dist/capabilities/catalog.js.map +1 -1
- package/dist/capabilities/migration-data.d.ts +51 -27
- package/dist/capabilities/migration-data.d.ts.map +1 -1
- package/dist/capabilities/migration-data.js +54 -27
- package/dist/capabilities/migration-data.js.map +1 -1
- package/dist/capabilities/migration.d.ts.map +1 -1
- package/dist/capabilities/migration.js +3 -6
- package/dist/capabilities/migration.js.map +1 -1
- package/dist/capabilities/sha256.d.ts +18 -0
- package/dist/capabilities/sha256.d.ts.map +1 -0
- package/dist/capabilities/sha256.js +180 -0
- package/dist/capabilities/sha256.js.map +1 -0
- package/dist/worker-logger.d.ts +46 -4
- package/dist/worker-logger.d.ts.map +1 -1
- package/dist/worker-logger.js +33 -11
- package/dist/worker-logger.js.map +1 -1
- package/package.json +3 -3
package/dist/worker-logger.d.ts
CHANGED
|
@@ -1,14 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import type { LevelWithSilent, Logger } from "pino";
|
|
2
|
+
/** What createWorkerLogger passes to pino (or to the injected factory). */
|
|
3
|
+
export interface WorkerLoggerConfig {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly level: LevelWithSilent;
|
|
6
|
+
readonly redact: {
|
|
7
|
+
readonly paths: string[];
|
|
8
|
+
readonly censor: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Minimal contract of an injected logger factory: called once with
|
|
13
|
+
* WorkerLoggerConfig, it returns the logger, and createWorkerLogger returns
|
|
14
|
+
* that same logger with the factory's exact type `L`. The `pino` default
|
|
15
|
+
* export itself satisfies it: `createWorkerLogger(service, component, { pino })`
|
|
16
|
+
* is typed `Logger<string, boolean>` by pino's declarations, which is not
|
|
17
|
+
* assignable to the default `Logger`; when exactly `Logger` is needed, pass
|
|
18
|
+
* the lambda `(config) => pino(config)`.
|
|
19
|
+
*/
|
|
20
|
+
export type WorkerLoggerFactory<L = Logger> = (config: WorkerLoggerConfig) => L;
|
|
21
|
+
export interface WorkerLoggerOptions<L = Logger> {
|
|
3
22
|
/** Override the LOG_LEVEL env default. */
|
|
4
|
-
readonly level?:
|
|
23
|
+
readonly level?: LevelWithSilent;
|
|
24
|
+
/**
|
|
25
|
+
* Factory to use instead of loading the optional peer dependency `pino`
|
|
26
|
+
* (for example the service's own `import pino from "pino"`, or a bundler
|
|
27
|
+
* where `require` is not available).
|
|
28
|
+
*/
|
|
29
|
+
readonly pino?: WorkerLoggerFactory<L>;
|
|
30
|
+
}
|
|
31
|
+
/** Thrown by createWorkerLogger when pino is not installed and no factory was passed. */
|
|
32
|
+
export declare class WorkerLoggerUnavailableError extends Error {
|
|
33
|
+
readonly code: "WORKER_LOGGER_UNAVAILABLE";
|
|
34
|
+
constructor(cause: unknown);
|
|
5
35
|
}
|
|
6
36
|
/**
|
|
7
37
|
* Build a Pino logger pre-configured with the shared PHI redact paths
|
|
8
38
|
* and a `<service>/<component>` name.
|
|
9
39
|
*
|
|
40
|
+
* With a factory in `options.pino` it returns what the factory returns, with
|
|
41
|
+
* the factory's exact type `L` (that overload is resolved first). Any other
|
|
42
|
+
* options (none, a variable or parameter typed WorkerLoggerOptions, or
|
|
43
|
+
* `{ pino: factory | undefined }`) give pino's `Logger`, as in 0.2.0-dev.1. A
|
|
44
|
+
* type argument without a factory does not compile.
|
|
45
|
+
*
|
|
10
46
|
* @param service e.g. "commercial-core-api" — the npm package name root
|
|
11
47
|
* @param component e.g. "outbox-worker" — the worker's role
|
|
48
|
+
* @throws WorkerLoggerUnavailableError when pino is not installed and options.pino is not set
|
|
12
49
|
*/
|
|
13
|
-
export declare function createWorkerLogger(service: string, component: string, options
|
|
50
|
+
export declare function createWorkerLogger<L>(service: string, component: string, options: WorkerLoggerOptions<L> & {
|
|
51
|
+
readonly pino: WorkerLoggerFactory<L>;
|
|
52
|
+
}): L;
|
|
53
|
+
export declare function createWorkerLogger(service: string, component: string, options?: Omit<WorkerLoggerOptions, "pino"> & {
|
|
54
|
+
readonly pino?: WorkerLoggerFactory | undefined;
|
|
55
|
+
}): Logger;
|
|
14
56
|
//# sourceMappingURL=worker-logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-logger.d.ts","sourceRoot":"","sources":["../src/worker-logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-logger.d.ts","sourceRoot":"","sources":["../src/worker-logger.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAInE,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACxE;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,kBAAkB,KAAK,CAAC,CAAC;AAEhF,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,MAAM;IAC7C,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACxC;AAED,yFAAyF;AACzF,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,QAAQ,CAAC,IAAI,EAAG,2BAA2B,CAAU;gBAEzC,KAAK,EAAE,OAAO;CAI3B;AAkBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAA;CAAE,GAC1E,CAAC,CAAC;AACL,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAA;CAAE,GAChG,MAAM,CAAC"}
|
package/dist/worker-logger.js
CHANGED
|
@@ -5,24 +5,46 @@
|
|
|
5
5
|
// need the shared PHI_LOG_REDACT_PATHS applied so accidentally
|
|
6
6
|
// logging a PHI field gets redacted just like in the HTTP path.
|
|
7
7
|
//
|
|
8
|
-
// Pino is
|
|
9
|
-
//
|
|
8
|
+
// Pino is an OPTIONAL peer dependency (0.2.0-dev.2, PKG-06): importing the
|
|
9
|
+
// package (or any subpath) never loads it. createWorkerLogger loads it
|
|
10
|
+
// lazily on its first call, from the consumer's installation, or uses the
|
|
11
|
+
// factory passed in `options.pino`. Without either it throws
|
|
12
|
+
// WorkerLoggerUnavailableError. Only types are imported from pino here, and
|
|
13
|
+
// they are erased from the compiled JavaScript.
|
|
10
14
|
//
|
|
11
15
|
// Usage:
|
|
12
16
|
// import { createWorkerLogger } from "@pegasimed.com/pegasi-sail-connect-shared";
|
|
13
17
|
// const log = createWorkerLogger("commercial-core-api", "outbox-worker");
|
|
14
18
|
// log.info({ result }, "cycle done");
|
|
15
|
-
import
|
|
19
|
+
import { createRequire } from "node:module";
|
|
16
20
|
import { PHI_LOG_REDACT_CENSOR, PHI_LOG_REDACT_PATHS } from "./phi-redaction.js";
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/** Thrown by createWorkerLogger when pino is not installed and no factory was passed. */
|
|
22
|
+
export class WorkerLoggerUnavailableError extends Error {
|
|
23
|
+
code = "WORKER_LOGGER_UNAVAILABLE";
|
|
24
|
+
constructor(cause) {
|
|
25
|
+
super('createWorkerLogger needs the optional peer dependency "pino" (^10): install it or pass options.pino.', { cause });
|
|
26
|
+
this.name = "WorkerLoggerUnavailableError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const requireFromPackage = createRequire(import.meta.url);
|
|
30
|
+
let loadedPino;
|
|
31
|
+
// Loads pino on first use only (never at import time) and keeps it.
|
|
32
|
+
function loadPino() {
|
|
33
|
+
if (loadedPino === undefined) {
|
|
34
|
+
try {
|
|
35
|
+
const loaded = requireFromPackage("pino");
|
|
36
|
+
loadedPino = (config) => loaded(config);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new WorkerLoggerUnavailableError(error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return loadedPino;
|
|
43
|
+
}
|
|
24
44
|
export function createWorkerLogger(service, component, options = {}) {
|
|
25
|
-
|
|
45
|
+
// Without a defined factory the second overload applies: L is pino's own Logger.
|
|
46
|
+
const factory = options.pino ?? loadPino();
|
|
47
|
+
return factory({
|
|
26
48
|
name: `${service}/${component}`,
|
|
27
49
|
level: options.level ?? process.env.LOG_LEVEL ?? "info",
|
|
28
50
|
redact: { paths: [...PHI_LOG_REDACT_PATHS], censor: PHI_LOG_REDACT_CENSOR }
|
|
@@ -1 +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,
|
|
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,2EAA2E;AAC3E,uEAAuE;AACvE,0EAA0E;AAC1E,6DAA6D;AAC7D,4EAA4E;AAC5E,gDAAgD;AAChD,EAAE;AACF,SAAS;AACT,oFAAoF;AACpF,4EAA4E;AAC5E,wCAAwC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AA+BjF,yFAAyF;AACzF,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAC5C,IAAI,GAAG,2BAAoC,CAAC;IAErD,YAAY,KAAc;QACxB,KAAK,CAAC,sGAAsG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzH,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAED,MAAM,kBAAkB,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1D,IAAI,UAA2C,CAAC;AAEhD,oEAAoE;AACpE,SAAS,QAAQ;IACf,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAuC,CAAC;YAChF,UAAU,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,4BAA4B,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AA0BD,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,SAAiB,EACjB,UAAyG,EAAE;IAE3G,iFAAiF;IACjF,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,IAAK,QAAQ,EAAwC,CAAC;IAClF,OAAO,OAAO,CAAC;QACb,IAAI,EAAE,GAAG,OAAO,IAAI,SAAS,EAAE;QAC/B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAK,OAAO,CAAC,GAAG,CAAC,SAAyC,IAAI,MAAM;QACxF,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,oBAAoB,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE;KAC5E,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pegasimed.com/pegasi-sail-connect-shared",
|
|
3
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"version": "0.2.0-dev.2",
|
|
4
4
|
"description": "Versioned shared TypeScript helpers for PEGASI SAIL/CONNECT services.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsc -p tsconfig.json",
|
|
73
|
-
"check": "tsc -p tsconfig.json --noEmit && tsc -p test/capabilities/tsconfig.json && tsc -p test/authorization/tsconfig.json",
|
|
73
|
+
"check": "tsc -p tsconfig.json --noEmit && tsc -p test/tsconfig.json && tsc -p test/capabilities/tsconfig.json && tsc -p test/authorization/tsconfig.json",
|
|
74
74
|
"prepare": "npm run build",
|
|
75
75
|
"lint": "eslint .",
|
|
76
76
|
"test": "vitest run --coverage",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"optional": true
|
|
93
93
|
},
|
|
94
94
|
"pino": {
|
|
95
|
-
"optional":
|
|
95
|
+
"optional": true
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|