@sincpro/client-framework 1.3.0 → 1.5.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.
Files changed (34) hide show
  1. package/AGENTS.md +26 -13
  2. package/MANIFESTO.md +2 -1
  3. package/README.md +67 -19
  4. package/dist/core/domain/consumers.d.ts +19 -0
  5. package/dist/core/domain/consumers.js +1 -0
  6. package/dist/core/domain/pipeline.d.ts +2 -1
  7. package/dist/core/domain/services.d.ts +59 -2
  8. package/dist/core/domain/services.js +36 -1
  9. package/dist/core/entrypoint/bounded-context.d.ts +32 -0
  10. package/dist/core/entrypoint/bounded-context.js +104 -19
  11. package/dist/core/index.d.ts +4 -2
  12. package/dist/core/index.js +2 -2
  13. package/dist/core/infrastructure/process.d.ts +16 -0
  14. package/dist/core/infrastructure/process.js +12 -1
  15. package/dist/core/services/event-handlers.d.ts +57 -0
  16. package/dist/core/services/event-handlers.js +114 -0
  17. package/dist/core/services/execution.d.ts +6 -1
  18. package/dist/core/services/execution.js +19 -2
  19. package/dist/event_driven/entrypoint/subscriber.d.ts +82 -28
  20. package/dist/event_driven/entrypoint/subscriber.js +203 -55
  21. package/dist/event_driven/index.d.ts +1 -1
  22. package/dist/observability/adapters/sentry.js +2 -0
  23. package/dist/observability/domain/errors.d.ts +4 -0
  24. package/dist/observability/domain/identity.d.ts +37 -0
  25. package/dist/observability/domain/identity.js +51 -0
  26. package/dist/observability/domain/logging.d.ts +5 -1
  27. package/dist/observability/index.d.ts +2 -1
  28. package/dist/observability/index.js +1 -0
  29. package/dist/observability/infrastructure/registry.d.ts +3 -0
  30. package/dist/observability/infrastructure/registry.js +1 -0
  31. package/dist/observability/services/logging.d.ts +2 -2
  32. package/dist/observability/services/logging.js +25 -11
  33. package/dist/observability/services/reporting.js +6 -1
  34. package/package.json +1 -1
@@ -2,13 +2,14 @@
2
2
  * Observability: the ports a platform plugs (`Tracer`, `ErrorReporter`, `Logger`), the console
3
3
  * engine logs go to by default, and how code writes and reports.
4
4
  *
5
- * domain/ the ports: tracing, errors, logging
5
+ * domain/ the ports: tracing, errors, logging; who is running (`identity`)
6
6
  * adapters/ console (default), memory (`./testing`), OpenTelemetry and Sentry (optional
7
7
  * entries `./opentelemetry`, `./sentry`)
8
8
  * infrastructure/ the ports this process runs with (`configureProcess` plugs them)
9
9
  * services/ the loggers, `reportError`, the default `outcomeOf`
10
10
  */
11
11
  export type { ErrorAbout, ErrorReporter, } from "./domain/errors.js";
12
+ export { identityOf, type ProcessIdentity, RELEASE, TENANT, tenantOf, } from "./domain/identity.js";
12
13
  export type { LayerLogger, Logger, LogLayer, LogLevel, LogRecord, } from "./domain/logging.js";
13
14
  export { type Attributes, NO_TRACER, type Outcome, type Span, type Tracer, } from "./domain/tracing.js";
14
15
  export { combineLoggers, logger, loggerAdapter, } from "./services/logging.js";
@@ -1,3 +1,4 @@
1
+ export { identityOf, RELEASE, TENANT, tenantOf, } from "./domain/identity.js";
1
2
  export { NO_TRACER, } from "./domain/tracing.js";
2
3
  export { combineLoggers, logger, loggerAdapter, } from "./services/logging.js";
3
4
  export { outcomeOf } from "./services/outcome.js";
@@ -1,4 +1,5 @@
1
1
  import type { ErrorReporter } from "../domain/errors.js";
2
+ import type { ProcessIdentity } from "../domain/identity.js";
2
3
  import type { Logger } from "../domain/logging.js";
3
4
  import { type Outcome, type Tracer } from "../domain/tracing.js";
4
5
  /**
@@ -10,6 +11,8 @@ import { type Outcome, type Tracer } from "../domain/tracing.js";
10
11
  * nothing reports, and logs go to the console in development mode.
11
12
  */
12
13
  export type ObservabilityPorts = {
14
+ /** Who is running: its release and the deployment's tenant, on every signal. */
15
+ readonly identity: ProcessIdentity | undefined;
13
16
  readonly tracer: Tracer;
14
17
  readonly reporter: ErrorReporter | undefined;
15
18
  readonly logger: Logger | undefined;
@@ -2,6 +2,7 @@ import { consoleLogger } from "../adapters/console.js";
2
2
  import { NO_TRACER, } from "../domain/tracing.js";
3
3
  import { outcomeOf } from "../services/outcome.js";
4
4
  const DEFAULTS = {
5
+ identity: undefined,
5
6
  tracer: NO_TRACER,
6
7
  reporter: undefined,
7
8
  logger: consoleLogger({ mode: "development" }),
@@ -7,8 +7,8 @@ export declare const logger: LayerLogger;
7
7
  export declare const loggerAdapter: LayerLogger;
8
8
  /** @internal — a bounded context's own logger (`projectBoundedContext.logger`). */
9
9
  export declare function boundedContextLogger(name: string): LayerLogger;
10
- /** A run's layer: a Feature's or an ApplicationService's. */
11
- type RunLogLayer = Extract<LogLayer, "feature" | "application_service">;
10
+ /** A run's layer: a Feature's, an ApplicationService's or an event handler's. */
11
+ type RunLogLayer = Extract<LogLayer, "feature" | "application_service" | "event_handler">;
12
12
  /** @internal — what a Feature or ApplicationService finds as `this.logger` while it runs. */
13
13
  export declare function executionLogger(layer: RunLogLayer, execution: Execution): LayerLogger;
14
14
  /** Each destination keeps its own policy; one failing sink does not hold back the others. */
@@ -1,4 +1,5 @@
1
1
  import { BIND } from "../../context/domain/execution.js";
2
+ import { tenantOf } from "../domain/identity.js";
2
3
  import { observabilityNow } from "../infrastructure/registry.js";
3
4
  const processSink = () => observabilityNow().logger;
4
5
  /** Sink failures cannot replace a business outcome or cause unhandled async rejections. */
@@ -14,8 +15,24 @@ function deliver(logger, record) {
14
15
  // Logging adapters are best-effort, as are tracing and error-reporting adapters.
15
16
  }
16
17
  }
18
+ /**
19
+ * A line as it is delivered: where it was written, and who was running — the process's release
20
+ * and the tenant (the run's context's, else the deployment's), when there is one.
21
+ */
22
+ function recordOf(fields, correlation) {
23
+ const { runContext, ...where } = correlation;
24
+ const identity = observabilityNow().identity;
25
+ const tenant = tenantOf(runContext ?? {}, identity);
26
+ return {
27
+ ...fields,
28
+ ...where,
29
+ ...(identity ? { release: identity.release } : {}),
30
+ ...(tenant ? { tenant } : {}),
31
+ };
32
+ }
17
33
  function correlationOf(execution) {
18
34
  return {
35
+ runContext: execution.context,
19
36
  boundedContext: execution.boundedContext,
20
37
  useCase: execution.useCase,
21
38
  executionId: execution.id,
@@ -26,14 +43,13 @@ function correlationOf(execution) {
26
43
  }
27
44
  function layerLogger(layer, sink, correlation = {}) {
28
45
  const write = (level, message, attributes) => {
29
- deliver(sink(), {
46
+ deliver(sink(), recordOf({
30
47
  timestamp: new Date().toISOString(),
31
48
  level,
32
49
  layer,
33
50
  message,
34
51
  ...(attributes ? { attributes: { ...attributes } } : {}),
35
- ...correlation,
36
- });
52
+ }, correlation));
37
53
  };
38
54
  const logger = {
39
55
  debug: (message, attributes) => write("debug", message, attributes),
@@ -78,29 +94,27 @@ export function logExecution(layer, execution, completed) {
78
94
  : completed
79
95
  ? "info"
80
96
  : "debug";
81
- deliver(processSink(), {
97
+ deliver(processSink(), recordOf({
82
98
  timestamp: new Date().toISOString(),
83
99
  level,
84
100
  layer,
85
101
  event: completed ? "execution.finished" : "execution.started",
86
102
  message: completed ? `Execution ${completed.outcome}` : "Execution started",
87
- ...correlationOf(execution),
88
103
  ...(completed ? completed : {}),
89
- });
104
+ }, correlationOf(execution)));
90
105
  }
91
106
  /**
92
107
  * @internal — an error a handler of the bounded context answered instead of raising: said once,
93
108
  * with where it was handled, never with the error itself.
94
109
  */
95
110
  export function logHandled(layer, correlation) {
96
- deliver(processSink(), {
111
+ deliver(processSink(), recordOf({
97
112
  timestamp: new Date().toISOString(),
98
113
  level: "info",
99
114
  layer,
100
115
  event: "error.handled",
101
116
  message: "Error handled",
102
- ...("execution" in correlation
103
- ? correlationOf(correlation.execution)
104
- : { boundedContext: correlation.boundedContext }),
105
- });
117
+ }, "execution" in correlation
118
+ ? correlationOf(correlation.execution)
119
+ : { boundedContext: correlation.boundedContext }));
106
120
  }
@@ -1,5 +1,6 @@
1
1
  import { newEntityId } from "../../common/ids.js";
2
2
  import { processContext } from "../../context/infrastructure/process.js";
3
+ import { tenantOf } from "../domain/identity.js";
3
4
  import { observabilityNow } from "../infrastructure/registry.js";
4
5
  /**
5
6
  * Whether this is the first time this error is reported. A Feature that fails inside an
@@ -41,11 +42,15 @@ export function reportError(error, where) {
41
42
  if (!firstReport(error))
42
43
  return;
43
44
  try {
45
+ const context = processContext.values;
46
+ const tenant = tenantOf(context, settings.identity);
44
47
  settings.reporter?.report(error, {
45
48
  useCase: where,
46
49
  traceId: "",
47
50
  executionId: newEntityId(),
48
- context: processContext.values,
51
+ context,
52
+ ...(settings.identity ? { release: settings.identity.release } : {}),
53
+ ...(tenant ? { tenant } : {}),
49
54
  });
50
55
  }
51
56
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/client-framework",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",