@sincpro/web-framework 2.2.0 → 2.4.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 +5 -3
- package/dist/core/cache.d.ts +2 -2
- package/dist/core/cache.js +2 -1
- package/dist/core/history.d.ts +4 -3
- package/dist/errors/index.d.ts +2 -1
- package/dist/react/useHistory.js +11 -14
- package/dist/telemetry/index.d.ts +17 -6
- package/dist/telemetry/index.js +19 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ flowchart LR
|
|
|
92
92
|
subgraph cf["@sincpro/client-framework · every platform"]
|
|
93
93
|
direction TB
|
|
94
94
|
wire["Transport · restTransport · entity()<br/>client contract · model definitions"]
|
|
95
|
-
services["
|
|
95
|
+
services["BoundedContext · Feature · ApplicationService · EventHandler<br/>configureProcess · processContext · ContextStore<br/>a span, a report, a context per run"]
|
|
96
96
|
generator["sincpro-client generate<br/>domain · client · entities"]
|
|
97
97
|
end
|
|
98
98
|
subgraph fw["@sincpro/web-framework · the web"]
|
|
@@ -225,7 +225,7 @@ export const invoices = entity<Invoice>("sales:invoice", {
|
|
|
225
225
|
create: "POST /invoices",
|
|
226
226
|
save: "PUT /invoices/{id}",
|
|
227
227
|
commands: { post: "POST /invoices/{id}/post" },
|
|
228
|
-
history:
|
|
228
|
+
history: "/invoices/{id}/events", // its DomainEvents: a record's facts
|
|
229
229
|
});
|
|
230
230
|
```
|
|
231
231
|
|
|
@@ -373,8 +373,10 @@ import { configureProcess, processContext } from "@sincpro/client-framework";
|
|
|
373
373
|
import { glitchtipReporter } from "@sincpro/web-framework/errors"; // optional
|
|
374
374
|
import { browserTracer } from "@sincpro/web-framework/telemetry"; // optional
|
|
375
375
|
|
|
376
|
+
const release = "my-app:1.0.0"; // <name>:<version>, the backend's APP_RELEASE
|
|
376
377
|
configureProcess({
|
|
377
|
-
|
|
378
|
+
identity: { release }, // + tenant, when the deployment serves one
|
|
379
|
+
tracer: browserTracer({ endpoint: settings.otlp, release }),
|
|
378
380
|
reporter: glitchtipReporter({ dsn: settings.glitchtip, release }),
|
|
379
381
|
});
|
|
380
382
|
processContext.set({ tenant_id: session.tenant }); // every use case runs with it and sends it
|
package/dist/core/cache.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ import { type Entity, type Transport } from "@sincpro/client-framework";
|
|
|
15
15
|
*
|
|
16
16
|
* A write forgets every collection its route NAMES, not only the first: «leave a tenant»
|
|
17
17
|
* (`POST /users/{email}/tenants/{tenant}/leave`) changes the tenant's members as much as the
|
|
18
|
-
* user. And
|
|
19
|
-
* `entities`, a write under an entity's list also forgets its history.
|
|
18
|
+
* user. And a record's business events live on a route of their own (`/issues/{id}/events`):
|
|
19
|
+
* with `entities`, a write under an entity's list also forgets its history, wherever it lives.
|
|
20
20
|
*
|
|
21
21
|
* const transport = cachedTransport(restTransport({ base: "/v1" }), { ttl: 30_000 });
|
|
22
22
|
* transport.invalidate("/facturas"); // forget an entity by hand (a push from the server)
|
package/dist/core/cache.js
CHANGED
|
@@ -14,7 +14,8 @@ function touchedBy(route, entities) {
|
|
|
14
14
|
const segments = path.split("/").filter((one) => one !== "");
|
|
15
15
|
const history = entities
|
|
16
16
|
.filter((one) => one.history !== undefined && under(path, pathOf(one.list)))
|
|
17
|
-
|
|
17
|
+
// The route up to its first key: `/issue-events/{id}` forgets `/issue-events`.
|
|
18
|
+
.map((one) => pathOf(one.history ?? "").split("/{")[0] ?? "");
|
|
18
19
|
return [...segments.map((one) => `/${one}`), ...history];
|
|
19
20
|
}
|
|
20
21
|
export function cachedTransport(transport, options = {}) {
|
package/dist/core/history.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
|
2
2
|
/**
|
|
3
3
|
* A record's history as people read it — its business events, newest first.
|
|
4
4
|
*
|
|
5
|
-
* Context: sincpro_framework keeps every context's facts in one event table,
|
|
6
|
-
* `GET
|
|
7
|
-
* `entity_id`) and carrying a `label` in
|
|
5
|
+
* Context: sincpro_framework keeps every context's facts in one event table, and answers a
|
|
6
|
+
* record's own with `DomainEvents` (`GET /issues/{id}/events`, the entity's `history`), each
|
|
7
|
+
* fact naming the record it is about (`entity_type`, `entity_id`) and carrying a `label` in
|
|
8
|
+
* every language.
|
|
8
9
|
* forge's console read it with a dictionary of field names written by hand; here the words for
|
|
9
10
|
* the rest of a fact come from the events' own model definition, like any other field.
|
|
10
11
|
*
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { ErrorReporter } from "@sincpro/client-framework";
|
|
|
7
7
|
* // the application — domains/common/infrastructure/telemetry.ts
|
|
8
8
|
* import { glitchtipReporter } from "./index.js";
|
|
9
9
|
* const reporter = glitchtipReporter({ dsn: settings.glitchtip, release, environment });
|
|
10
|
-
* configureProcess({ tracer, reporter });
|
|
10
|
+
* configureProcess({ identity: { release }, tracer, reporter }); // entrypoints/main.tsx
|
|
11
11
|
*
|
|
12
12
|
* Context: optional on every count, like `./telemetry`: an entry of its own, `@sentry/browser`
|
|
13
13
|
* an optional peer, and only a convenience — an application with its own client wraps it with
|
|
@@ -26,6 +26,7 @@ import type { ErrorReporter } from "@sincpro/client-framework";
|
|
|
26
26
|
export type GlitchtipOptions = {
|
|
27
27
|
/** The application's DSN. Public by nature: it ships to the browser. */
|
|
28
28
|
dsn: string;
|
|
29
|
+
/** `<name>:<version>`, the same text as `configureProcess({ identity })`: GlitchTip's release. */
|
|
29
30
|
release?: string;
|
|
30
31
|
environment?: string;
|
|
31
32
|
/** Fraction of errors sent, 0 to 1. Default 1. */
|
package/dist/react/useHistory.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {} from "@sincpro/client-framework";
|
|
2
|
+
import { listRoute } from "@sincpro/client-framework";
|
|
3
3
|
import { historyOf } from "../core/history.js";
|
|
4
4
|
import { useFramework } from "./context.js";
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
/**
|
|
7
7
|
* A record's business events, newest first — what `Record.Activity` draws.
|
|
8
8
|
*
|
|
9
|
-
* Context: the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* Context: the backend answers a record's events itself — sincpro_framework's `DomainEvents`,
|
|
10
|
+
* the entity's `history` route (`/issues/{id}/events`), which the generator writes from the
|
|
11
|
+
* contract — so it is read like any list, with the same transport, newest first. `undefined`
|
|
12
|
+
* while it is not read, for a record not saved yet, or when it cannot be read: an empty history
|
|
13
|
+
* says «nothing happened», which is a different claim from «you may not see it». Pass the
|
|
14
|
+
* record among `deps` so a write that reloads it reads its new facts too.
|
|
14
15
|
*
|
|
15
16
|
* Named after sincpro_framework's `history_of`; web-ui's `useActivity` is something else (the
|
|
16
17
|
* panel's open state).
|
|
@@ -21,20 +22,16 @@ export function useHistory(entity, id, deps = []) {
|
|
|
21
22
|
const [entries, setEntries] = useState(undefined);
|
|
22
23
|
const history = entity.history;
|
|
23
24
|
useEffect(() => {
|
|
24
|
-
if (history === undefined)
|
|
25
|
+
if (history === undefined || id === "") {
|
|
26
|
+
setEntries(undefined);
|
|
25
27
|
return;
|
|
28
|
+
}
|
|
26
29
|
const aborter = new AbortController();
|
|
27
30
|
const criteria = {
|
|
28
|
-
selection: {
|
|
29
|
-
all: [
|
|
30
|
-
{ field: "entity_type", operator: "=", value: history.type },
|
|
31
|
-
{ field: "entity_id", operator: "=", value: id },
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
31
|
order: [{ field: "created_at", descending: true }],
|
|
35
32
|
pagination: { limit: SHOWN },
|
|
36
33
|
};
|
|
37
|
-
transport.list(history
|
|
34
|
+
transport.list(listRoute(history, { id }), criteria, aborter.signal).then((page) => aborter.signal.aborted || setEntries(historyOf(page.rows, page.meta, locale)), () => aborter.signal.aborted || setEntries(undefined));
|
|
38
35
|
return () => aborter.abort();
|
|
39
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- the caller names what reloads it
|
|
40
37
|
}, [transport, history, id, locale, context, ...deps]);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Attributes, type Tracer } from "@sincpro/client-framework";
|
|
2
2
|
/**
|
|
3
3
|
* A `Tracer` for the browser, built from the application's own settings: OpenTelemetry's SDK
|
|
4
4
|
* exporting OTLP/HTTP to the endpoint the application names.
|
|
5
5
|
*
|
|
6
6
|
* // the application — domains/common/infrastructure/telemetry.ts
|
|
7
7
|
* import { browserTracer } from "./index.js";
|
|
8
|
-
* const
|
|
9
|
-
*
|
|
8
|
+
* const release = "forge-web:1.4.0"; // the backend's APP_RELEASE
|
|
9
|
+
* const tracer = browserTracer({ endpoint: settings.otlp, release });
|
|
10
|
+
* configureProcess({ identity: { release }, tracer, reporter }); // entrypoints/main.tsx
|
|
10
11
|
*
|
|
11
12
|
* Context: optional on every count. It is an entry of its own that nothing else in this package
|
|
12
13
|
* imports, and its SDK (`@opentelemetry/sdk-trace`, `@opentelemetry/exporter-trace-otlp-http`,
|
|
@@ -24,10 +25,14 @@ import type { Attributes, Tracer } from "@sincpro/client-framework";
|
|
|
24
25
|
export type BrowserTracerOptions = {
|
|
25
26
|
/** The application's OTLP/HTTP traces endpoint (`https://collector.example.com/v1/traces`). */
|
|
26
27
|
endpoint: string;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* `<name>:<version>` as deployed — the backend's `APP_RELEASE`, the same text
|
|
30
|
+
* `configureProcess({ identity })` takes. The resource's `release`, and `service.name` and
|
|
31
|
+
* `service.version` read out of it with the backend's rules (`identityOf`).
|
|
32
|
+
*/
|
|
30
33
|
release?: string;
|
|
34
|
+
/** `service.name`, when it is not the release's name. One of the two is needed. */
|
|
35
|
+
service?: string;
|
|
31
36
|
/** `deployment.environment.name`: `production`, `staging`… */
|
|
32
37
|
environment?: string;
|
|
33
38
|
/** Headers the endpoint asks for. Never a secret: whatever ships to a browser is public. */
|
|
@@ -42,4 +47,10 @@ export type BrowserTracer = Tracer & {
|
|
|
42
47
|
/** Sends what is buffered now. Called by itself when the page is hidden or left. */
|
|
43
48
|
flush: () => Promise<void>;
|
|
44
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Who sends the traces, with sincpro_framework's keys: `service.name` and `service.version` read
|
|
52
|
+
* out of the release (`sincpro-forge-web:1.4.0` → `sincpro-forge-web`, `1.4.0`), the release
|
|
53
|
+
* itself, the environment and the application's own attributes.
|
|
54
|
+
*/
|
|
55
|
+
export declare function tracerResource(options: BrowserTracerOptions): Attributes;
|
|
45
56
|
export declare function browserTracer(options: BrowserTracerOptions): BrowserTracer;
|
package/dist/telemetry/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { identityOf, } from "@sincpro/client-framework";
|
|
1
2
|
const SILENT = {
|
|
2
3
|
traceId: "",
|
|
3
4
|
spanId: "",
|
|
@@ -5,6 +6,21 @@ const SILENT = {
|
|
|
5
6
|
set: () => undefined,
|
|
6
7
|
end: () => undefined,
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Who sends the traces, with sincpro_framework's keys: `service.name` and `service.version` read
|
|
11
|
+
* out of the release (`sincpro-forge-web:1.4.0` → `sincpro-forge-web`, `1.4.0`), the release
|
|
12
|
+
* itself, the environment and the application's own attributes.
|
|
13
|
+
*/
|
|
14
|
+
export function tracerResource(options) {
|
|
15
|
+
const identity = options.release ? identityOf(options.release) : undefined;
|
|
16
|
+
return {
|
|
17
|
+
"service.name": options.service ?? identity?.serviceName ?? "unknown_service",
|
|
18
|
+
...(identity?.serviceVersion ? { "service.version": identity.serviceVersion } : {}),
|
|
19
|
+
...(identity ? { release: identity.release } : {}),
|
|
20
|
+
...(options.environment ? { "deployment.environment.name": options.environment } : {}),
|
|
21
|
+
...options.attributes,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
8
24
|
export function browserTracer(options) {
|
|
9
25
|
let ready = null;
|
|
10
26
|
let flush = () => Promise.resolve();
|
|
@@ -20,21 +36,15 @@ export function browserTracer(options) {
|
|
|
20
36
|
url: options.endpoint,
|
|
21
37
|
...(options.headers ? { headers: { ...options.headers } } : {}),
|
|
22
38
|
});
|
|
39
|
+
const resource = tracerResource(options);
|
|
23
40
|
const provider = new TracerProvider({
|
|
24
|
-
resource: resourceFromAttributes(
|
|
25
|
-
"service.name": options.service,
|
|
26
|
-
...(options.release ? { "service.version": options.release } : {}),
|
|
27
|
-
...(options.environment
|
|
28
|
-
? { "deployment.environment.name": options.environment }
|
|
29
|
-
: {}),
|
|
30
|
-
...options.attributes,
|
|
31
|
-
}),
|
|
41
|
+
resource: resourceFromAttributes(resource),
|
|
32
42
|
sampler: new ParentBasedSampler({
|
|
33
43
|
root: new TraceIdRatioBasedSampler(options.sampling ?? 1),
|
|
34
44
|
}),
|
|
35
45
|
spanProcessors: [new BatchSpanProcessor({ exporter })],
|
|
36
46
|
});
|
|
37
|
-
ready = openTelemetryTracer(provider.getTracer(
|
|
47
|
+
ready = openTelemetryTracer(provider.getTracer(String(resource["service.name"])));
|
|
38
48
|
flush = () => provider.forceFlush();
|
|
39
49
|
// A page that is hidden may never come back: what is buffered goes now.
|
|
40
50
|
const leave = () => void flush().catch(() => undefined);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@opentelemetry/resources": "^3.1.0",
|
|
41
41
|
"@opentelemetry/sdk-trace": "^3.1.0",
|
|
42
42
|
"@sentry/browser": "^11.11.0",
|
|
43
|
-
"@sincpro/client-framework": "^
|
|
43
|
+
"@sincpro/client-framework": "^1.5.0",
|
|
44
44
|
"@sincpro/criteria": "^2.1.0",
|
|
45
45
|
"@sincpro/criteria-react": "^2.1.0",
|
|
46
46
|
"@sincpro/web-composer": "^1.6.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@opentelemetry/resources": "3.1.0",
|
|
73
73
|
"@opentelemetry/sdk-trace": "3.1.0",
|
|
74
74
|
"@sentry/browser": "11.11.0",
|
|
75
|
-
"@sincpro/client-framework": "^
|
|
75
|
+
"@sincpro/client-framework": "^1.5.0",
|
|
76
76
|
"@sincpro/criteria": "^2.1.0",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
78
|
"@sincpro/web-composer": "^1.6.0",
|