@mgamadeus/ddd-web 0.14.0 → 0.16.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.
@@ -0,0 +1,214 @@
1
+ import { b as CapturedFrame, D as DddClientIssueEvent, a as DddClientIssuesReportRequestBody, i as IssuesRuntime, I as IssuesTransport, d as CapturedIssueContext, c as CaptureExtra, l as IssuesWireAdapter, g as IssueKind, C as CapturedBreadcrumb } from './index-C0Auocn8.js';
2
+
3
+ /**
4
+ * Client-side redaction of everything a report carries as free text: the page URL, breadcrumb URLs and messages, the
5
+ * error message, the raw stack and tag values. The backend redacts again (mgamadeus/ddd `IssuesLogRedactor` and the
6
+ * client rules of `logClientIssue`); this pass keeps credentials from leaving the device at all.
7
+ */
8
+ /** One rule by value, applied to text and URLs alike. */
9
+ interface IssuesRedactionRule {
10
+ pattern: RegExp;
11
+ replacement: string;
12
+ }
13
+ interface IssuesRedactor {
14
+ /** For a URL (page, request, navigation from / to). */
15
+ redactUrl: (url: string) => string;
16
+ /** For free text (error message, breadcrumb message); URLs inside it get the token rules too. */
17
+ redactText: (text: string) => string;
18
+ }
19
+ interface IssuesRedactorOptions {
20
+ /**
21
+ * Path segments whose NEXT segment is the credential (an invitation, a password reset):
22
+ * `/invitations/abc` → `/invitations/[redacted]`. A segment may contain `/` (`r/confirm`). Default
23
+ * {@link DEFAULT_ISSUES_TOKEN_PATH_SEGMENTS}, the backend's default `redactPathSegments`.
24
+ */
25
+ tokenPathSegments?: readonly string[];
26
+ /** Applied after the built-in rules, e.g. a national phone-number format. */
27
+ additionalRules?: readonly IssuesRedactionRule[];
28
+ }
29
+ /** The backend's default `redactPathSegments` (`Common.Issues`). */
30
+ declare const DEFAULT_ISSUES_TOKEN_PATH_SEGMENTS: readonly string[];
31
+ /** Rules by value. Order matters: a bearer and a JWT go before the generic rules. */
32
+ declare const ISSUES_REDACTION_RULES: readonly IssuesRedactionRule[];
33
+ declare const createIssuesRedactor: (options?: IssuesRedactorOptions) => IssuesRedactor;
34
+ /** {@link IssuesRedactor.redactUrl} with the default rules. */
35
+ declare const redactUrl: (url: string) => string;
36
+ /** {@link IssuesRedactor.redactText} with the default rules. */
37
+ declare const redactText: (text: string) => string;
38
+
39
+ /**
40
+ * What the client never reports: noise that is not a failure of the app, or not actionable per event. The backend
41
+ * drops the chunk-load, `Script error.` and `ResizeObserver loop` patterns again (`clientIgnorePatterns`); dropping
42
+ * here saves the request.
43
+ */
44
+ interface IssueDropCandidate {
45
+ name: string;
46
+ message: string;
47
+ frames: readonly CapturedFrame[];
48
+ /** The page runs under automation (Playwright / WebDriver: `navigator.webdriver`) */
49
+ automated: boolean;
50
+ }
51
+ interface IssueDropRule {
52
+ id: string;
53
+ matches: (candidate: IssueDropCandidate) => boolean;
54
+ }
55
+ declare const ISSUE_DROP_RULES: readonly IssueDropRule[];
56
+ /** The id of the first rule that drops the candidate, or null when it is reported. */
57
+ declare const findIssueDropRule: (candidate: IssueDropCandidate, rules?: readonly IssueDropRule[]) => string | null;
58
+
59
+ /**
60
+ * Every limit of the issues reporter in one place. The backend enforces its own caps again (mgamadeus/ddd
61
+ * `ClientIssueReportNormalizer`); these keep a broken page from flooding the endpoint and keep requests small. The field
62
+ * caps equal the backend's.
63
+ */
64
+ /** Caps of a reporter that lives for one page session: per session, a hard stop after repeated failed sends. */
65
+ interface IssuesSessionLimits {
66
+ sendsPerFingerprint: number;
67
+ eventsPerSession: number;
68
+ failedSendsBeforeStop: number;
69
+ }
70
+ /** Caps of a long-lived reporter (a server, a mobile app): windows and an exponential backoff instead of a stop. */
71
+ interface IssuesWindowedLimits {
72
+ sendsPerFingerprintPerWindow: number;
73
+ fingerprintWindowMs: number;
74
+ eventsPerMinute: number;
75
+ backoffStartMs: number;
76
+ backoffMaxMs: number;
77
+ }
78
+ interface IssuesLimits {
79
+ /** Field caps per event (characters) */
80
+ nameLength: number;
81
+ messageLength: number;
82
+ framesPerEvent: number;
83
+ fileLength: number;
84
+ functionLength: number;
85
+ rawStackLength: number;
86
+ urlLength: number;
87
+ routePatternLength: number;
88
+ breadcrumbsPerEvent: number;
89
+ breadcrumbMessageLength: number;
90
+ breadcrumbUrlLength: number;
91
+ tagsPerEvent: number;
92
+ tagLength: number;
93
+ requestMethodLength: number;
94
+ clientFingerprintLength: number;
95
+ /** Batching */
96
+ flushDelayMs: number;
97
+ flushAtEvents: number;
98
+ /** The backend drops every event beyond 10 per request (`too-many-events`). */
99
+ eventsPerRequest: number;
100
+ /** Serialized UTF-8 per request; under the browser's 64 KiB keepalive budget */
101
+ requestBytes: number;
102
+ /** Serialized UTF-8 per event, before it is queued (the backend's file sink takes 16 KB per client event) */
103
+ eventBytes: number;
104
+ /** One retry on a network error or a 5xx, never on a 4xx */
105
+ retryDelayMs: number;
106
+ /** Events waiting to be sent; the oldest go first beyond it (a backend that is down for long) */
107
+ queuedEvents: number;
108
+ session: IssuesSessionLimits;
109
+ windowed: IssuesWindowedLimits;
110
+ }
111
+ type IssuesLimitsOverrides = Partial<Omit<IssuesLimits, 'session' | 'windowed'>> & {
112
+ session?: Partial<IssuesSessionLimits>;
113
+ windowed?: Partial<IssuesWindowedLimits>;
114
+ };
115
+ declare const ISSUES_LIMITS: Readonly<IssuesLimits>;
116
+ /** The default limits with the given ones on top (the nested `session` / `windowed` caps merged field by field). */
117
+ declare const mergeIssuesLimits: (overrides?: IssuesLimitsOverrides) => IssuesLimits;
118
+
119
+ /** The error-like value a reporter received, reduced to what a report carries. */
120
+ interface NormalizedError {
121
+ name: string;
122
+ message: string;
123
+ /** Innermost first */
124
+ frames: CapturedFrame[];
125
+ /** Only when the stack had lines but none could be parsed */
126
+ rawStack: string | null;
127
+ }
128
+ /** Decides whether a frame's file is the application's own code. */
129
+ type InAppFileTest = (file: string) => boolean;
130
+ declare const truncate: (value: string, maxLength: number) => string;
131
+ declare const isForeignFile: (file: string) => boolean;
132
+ /** Parses a stack string into frames, innermost first. Lines that are not frames (the message) are skipped. */
133
+ declare const parseStack: (stack: string, isInAppFile?: InAppFileTest, maxFrames?: number) => CapturedFrame[];
134
+ /** Any thrown value (an Error, a string, a rejected object) → name, message, frames. */
135
+ declare const normalizeError: (value: unknown, isInAppFile?: InAppFileTest) => NormalizedError;
136
+
137
+ /**
138
+ * The issues reporter: collect → redact → de-duplicate → cap → batch → send. Platform-free: the caller supplies the
139
+ * transport, the context and optionally the wire adapter. It never throws into its caller and never reports its own
140
+ * failures.
141
+ */
142
+ /**
143
+ * Header a client app's own server sends its shared secret in; the application's controller files such reports
144
+ * under the section WEB_SERVER. The header name is the application's choice — `serverTokenHeader` overrides it.
145
+ */
146
+ declare const DDD_ISSUES_SERVER_TOKEN_HEADER = "X-Issues-Server-Token";
147
+ /** How the reporter caps what it sends. */
148
+ type IssuesRateLimitMode =
149
+ /** One page session: per-fingerprint and per-session caps, a hard stop after repeated failed sends. */
150
+ 'session'
151
+ /** A long-lived process or app: windowed caps and an exponential backoff. */
152
+ | 'windowed';
153
+ interface IssuesClock {
154
+ now: () => number;
155
+ setTimeout: (callback: () => void, delayMs: number) => unknown;
156
+ clearTimeout: (handle: unknown) => void;
157
+ }
158
+ /** The running platform's timers, read when the reporter is created. On Node they are unref'd. */
159
+ declare const createPlatformIssuesClock: () => IssuesClock;
160
+ type IssuesContextValues = Partial<Omit<CapturedIssueContext, 'runtime' | 'app'>>;
161
+ interface IssuesReporterOptions<TWireEvent = DddClientIssueEvent, TRequestBody = DddClientIssuesReportRequestBody> {
162
+ runtime: IssuesRuntime;
163
+ /** The client app, e.g. `web`, `admin`, `mobile` */
164
+ app: string;
165
+ /** Full URL of the ingest endpoint, read at send time; null = not configured, nothing is sent. */
166
+ endpoint: () => string | null;
167
+ transport: IssuesTransport;
168
+ /** Read at send time (the release may only be known after the first render). Missing fields are null. */
169
+ context?: () => IssuesContextValues;
170
+ /** Read at capture time: tags every event carries (e.g. the deployed commit); a capture's own tags win on a clash. */
171
+ commonTags?: () => CaptureExtra['tags'];
172
+ /** Default: the DDD contract (`@mgamadeus/ddd-web/issues/wire`). Pass your own to type the body with your models. */
173
+ wire?: IssuesWireAdapter<TWireEvent, TRequestBody>;
174
+ /** A signed-in session's access token, so the backend attributes the error to the account. */
175
+ getAuthorization?: () => string | null | undefined;
176
+ /** The client app's own server only: the shared secret that makes the backend file reports as WEB_SERVER. */
177
+ serverToken?: string;
178
+ /** Default {@link DDD_ISSUES_SERVER_TOKEN_HEADER} */
179
+ serverTokenHeader?: string;
180
+ isInAppFile?: InAppFileTest;
181
+ /** True under automation (`navigator.webdriver`): nothing is reported. */
182
+ isAutomated?: () => boolean;
183
+ /** Default: `session` for `browser`, `windowed` for `node` and `react-native`. */
184
+ rateLimitMode?: IssuesRateLimitMode;
185
+ /** Attach the breadcrumb trail to events. Default: every runtime but `node` (a server's trail mixes requests). */
186
+ attachBreadcrumbs?: boolean;
187
+ /** Default {@link ISSUE_DROP_RULES}; spread them to add your own. */
188
+ dropRules?: readonly IssueDropRule[];
189
+ /** Default {@link createIssuesRedactor}() */
190
+ redactor?: IssuesRedactor;
191
+ limits?: IssuesLimitsOverrides;
192
+ clock?: IssuesClock;
193
+ }
194
+ interface IssuesReporter {
195
+ /** Reports anything thrown. `kind` says how it was caught; `manual` (default) is the one the backend counts as handled. */
196
+ captureError: (error: unknown, kind?: IssueKind, extra?: CaptureExtra) => void;
197
+ addBreadcrumb: (breadcrumb: CapturedBreadcrumb) => void;
198
+ /** The current route pattern (`/books/[bookId]`) and URL; both name every event captured after it. */
199
+ setRoute: (routePattern: string | null, url: string | null) => void;
200
+ /** Replaces `getAuthorization`, e.g. once the session store exists. */
201
+ setAuthorizationReader: (reader: (() => string | null | undefined) | null) => void;
202
+ /** Sends what is queued. `unloading`: the page is going away — keepalive, every batch at once, no awaiting. */
203
+ flush: (options?: {
204
+ unloading?: boolean;
205
+ }) => Promise<void>;
206
+ /** Events waiting to be sent. */
207
+ getQueuedEventCount: () => number;
208
+ }
209
+ /** UTF-8 length of a string, without TextEncoder (not in every runtime this targets). */
210
+ declare const utf8ByteLength: (value: string) => number;
211
+ declare const createIssuesReporter: <TWireEvent = DddClientIssueEvent, TRequestBody = DddClientIssuesReportRequestBody>(options: IssuesReporterOptions<TWireEvent, TRequestBody>) => IssuesReporter;
212
+
213
+ export { redactText as A, redactUrl as B, truncate as C, DDD_ISSUES_SERVER_TOKEN_HEADER as D, utf8ByteLength as E, DEFAULT_ISSUES_TOKEN_PATH_SEGMENTS as c, ISSUES_LIMITS as d, ISSUES_REDACTION_RULES as e, ISSUE_DROP_RULES as f, createIssuesRedactor as s, createIssuesReporter as t, createPlatformIssuesClock as u, findIssueDropRule as v, isForeignFile as w, mergeIssuesLimits as x, normalizeError as y, parseStack as z };
214
+ export type { IssuesReporterOptions as I, NormalizedError as N, IssuesReporter as a, IssuesRedactor as b, InAppFileTest as g, IssueDropCandidate as h, IssueDropRule as i, IssuesClock as j, IssuesContextValues as k, IssuesLimits as l, IssuesLimitsOverrides as m, IssuesRateLimitMode as n, IssuesRedactionRule as o, IssuesRedactorOptions as p, IssuesSessionLimits as q, IssuesWindowedLimits as r };
@@ -0,0 +1,31 @@
1
+ import { C as CapturedBreadcrumb } from './index-C0Auocn8.js';
2
+
3
+ /** Dynamic route params as routers hand them out (`string` per segment, `string[]` for a catch-all). */
4
+ type IssuesRouteParams = Record<string, string | readonly string[] | undefined>;
5
+ /**
6
+ * The route PATTERN of a page, rebuilt from its path and its dynamic params: `/books/12/chapters/3` with
7
+ * `{ bookId: '12', chapterId: '3' }` → `/books/[bookId]/chapters/[chapterId]`. The pattern names the issue (one bug on
8
+ * every book's chapter page is one issue) and carries no slug, id or token.
9
+ *
10
+ * Params are matched left to right, each against the first unmatched segment equal to its value, so
11
+ * `/books/3/chapters/3` with `{ bookId: '3', chapterId: '3' }` still comes out right. A catch-all (array value)
12
+ * replaces the run of segments it spans with `[...key]`.
13
+ */
14
+ declare const buildRoutePattern: (pathname: string, params: IssuesRouteParams | null | undefined) => string;
15
+ /** The part of a reporter a route tracker drives. */
16
+ interface IssuesRouteTarget {
17
+ setRoute: (routePattern: string | null, url: string | null) => void;
18
+ addBreadcrumb: (breadcrumb: CapturedBreadcrumb) => void;
19
+ }
20
+ interface IssuesRouteTracker {
21
+ /**
22
+ * Call on every route change: sets the reporter's route pattern and URL (the URL defaults to the path) and adds a
23
+ * navigation breadcrumb when the pattern changed. Returns the pattern.
24
+ */
25
+ trackRoute: (pathname: string, params?: IssuesRouteParams | null, url?: string | null) => string;
26
+ }
27
+ /** Platform-free: a web router, a React Native navigator or a test calls `trackRoute` itself. */
28
+ declare const createIssuesRouteTracker: (target: IssuesRouteTarget, now?: () => string) => IssuesRouteTracker;
29
+
30
+ export { buildRoutePattern as c, createIssuesRouteTracker as d };
31
+ export type { IssuesRouteParams as I, IssuesRouteTarget as a, IssuesRouteTracker as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mgamadeus/ddd-web",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "TypeScript web client for backends built with mgamadeus/ddd, the DDD entity framework for Symfony and Doctrine (Composer/Packagist). Generates a typed RTK Query SDK from the backend's OpenAPI document, builds DDD QueryOptions (filters, orderBy, expand, select, paging) and handles JWT auth with token refresh.",
5
5
  "keywords": [
6
6
  "ddd",
@@ -49,6 +49,22 @@
49
49
  "types": "./dist/fetch-api-request/index.d.ts",
50
50
  "import": "./dist/fetch-api-request/index.js"
51
51
  },
52
+ "./issues": {
53
+ "types": "./dist/issues/index.d.ts",
54
+ "import": "./dist/issues/index.js"
55
+ },
56
+ "./issues/browser": {
57
+ "types": "./dist/issues/browser/index.d.ts",
58
+ "import": "./dist/issues/browser/index.js"
59
+ },
60
+ "./issues/node": {
61
+ "types": "./dist/issues/node/index.d.ts",
62
+ "import": "./dist/issues/node/index.js"
63
+ },
64
+ "./issues/wire": {
65
+ "types": "./dist/issues/wire/index.d.ts",
66
+ "import": "./dist/issues/wire/index.js"
67
+ },
52
68
  "./vite": {
53
69
  "types": "./dist/vite/index.d.ts",
54
70
  "import": "./dist/vite/index.js"
@@ -98,7 +114,7 @@
98
114
  },
99
115
  "scripts": {
100
116
  "build": "node scripts/clean.mjs && tsup",
101
- "typecheck": "tsc -p .",
117
+ "typecheck": "tsc -p . && tsc -p tsconfig.issues-core.json",
102
118
  "test": "vitest run"
103
119
  }
104
120
  }