@dads-framework/client 0.0.0-stage → 0.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.
Files changed (152) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +83 -2
  3. package/dist/client.tsbuildinfo +1 -0
  4. package/dist/index.d.ts +16 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +15 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/lib/access-refusal.d.ts +8 -0
  9. package/dist/lib/access-refusal.d.ts.map +1 -0
  10. package/dist/lib/access-refusal.js +11 -0
  11. package/dist/lib/access-refusal.js.map +1 -0
  12. package/dist/lib/api-error.d.ts +86 -0
  13. package/dist/lib/api-error.d.ts.map +1 -0
  14. package/dist/lib/api-error.js +124 -0
  15. package/dist/lib/api-error.js.map +1 -0
  16. package/dist/lib/api-exchange-channel.d.ts +47 -0
  17. package/dist/lib/api-exchange-channel.d.ts.map +1 -0
  18. package/dist/lib/api-exchange-channel.js +43 -0
  19. package/dist/lib/api-exchange-channel.js.map +1 -0
  20. package/dist/lib/api-verbs.d.ts +115 -0
  21. package/dist/lib/api-verbs.d.ts.map +1 -0
  22. package/dist/lib/api-verbs.js +148 -0
  23. package/dist/lib/api-verbs.js.map +1 -0
  24. package/dist/lib/build-client-context.d.ts +44 -0
  25. package/dist/lib/build-client-context.d.ts.map +1 -0
  26. package/dist/lib/build-client-context.js +74 -0
  27. package/dist/lib/build-client-context.js.map +1 -0
  28. package/dist/lib/call-api.d.ts +77 -0
  29. package/dist/lib/call-api.d.ts.map +1 -0
  30. package/dist/lib/call-api.js +149 -0
  31. package/dist/lib/call-api.js.map +1 -0
  32. package/dist/lib/client-context.d.ts +32 -0
  33. package/dist/lib/client-context.d.ts.map +1 -0
  34. package/dist/lib/client-context.js +33 -0
  35. package/dist/lib/client-context.js.map +1 -0
  36. package/dist/lib/create-request-id.d.ts +14 -0
  37. package/dist/lib/create-request-id.d.ts.map +1 -0
  38. package/dist/lib/create-request-id.js +25 -0
  39. package/dist/lib/create-request-id.js.map +1 -0
  40. package/dist/lib/failure-presentation.d.ts +21 -0
  41. package/dist/lib/failure-presentation.d.ts.map +1 -0
  42. package/dist/lib/failure-presentation.js +9 -0
  43. package/dist/lib/failure-presentation.js.map +1 -0
  44. package/dist/lib/optimistic-cache.d.ts +84 -0
  45. package/dist/lib/optimistic-cache.d.ts.map +1 -0
  46. package/dist/lib/optimistic-cache.js +117 -0
  47. package/dist/lib/optimistic-cache.js.map +1 -0
  48. package/dist/lib/read-client-environment.d.ts +67 -0
  49. package/dist/lib/read-client-environment.d.ts.map +1 -0
  50. package/dist/lib/read-client-environment.js +85 -0
  51. package/dist/lib/read-client-environment.js.map +1 -0
  52. package/dist/lib/request-locale.d.ts +6 -0
  53. package/dist/lib/request-locale.d.ts.map +1 -0
  54. package/dist/lib/request-locale.js +31 -0
  55. package/dist/lib/request-locale.js.map +1 -0
  56. package/dist/lib/request-metadata.d.ts +22 -0
  57. package/dist/lib/request-metadata.d.ts.map +1 -0
  58. package/dist/lib/request-metadata.js +26 -0
  59. package/dist/lib/request-metadata.js.map +1 -0
  60. package/dist/lib/save-with-refresh.d.ts +13 -0
  61. package/dist/lib/save-with-refresh.d.ts.map +1 -0
  62. package/dist/lib/save-with-refresh.js +16 -0
  63. package/dist/lib/save-with-refresh.js.map +1 -0
  64. package/dist/lib/search-params.d.ts +11 -0
  65. package/dist/lib/search-params.d.ts.map +1 -0
  66. package/dist/lib/search-params.js +41 -0
  67. package/dist/lib/search-params.js.map +1 -0
  68. package/dist/lib/send-api-request.d.ts +24 -0
  69. package/dist/lib/send-api-request.d.ts.map +1 -0
  70. package/dist/lib/send-api-request.js +98 -0
  71. package/dist/lib/send-api-request.js.map +1 -0
  72. package/dist/lib/signed-url-upload.d.ts +18 -0
  73. package/dist/lib/signed-url-upload.d.ts.map +1 -0
  74. package/dist/lib/signed-url-upload.js +26 -0
  75. package/dist/lib/signed-url-upload.js.map +1 -0
  76. package/dist/lib/unauthorized-response-channel.d.ts +30 -0
  77. package/dist/lib/unauthorized-response-channel.d.ts.map +1 -0
  78. package/dist/lib/unauthorized-response-channel.js +38 -0
  79. package/dist/lib/unauthorized-response-channel.js.map +1 -0
  80. package/dist/telemetry/core/index.d.ts +3 -0
  81. package/dist/telemetry/core/index.d.ts.map +1 -0
  82. package/dist/telemetry/core/index.js +3 -0
  83. package/dist/telemetry/core/index.js.map +1 -0
  84. package/dist/telemetry/core/lib/client-telemetry-conformance.d.ts +13 -0
  85. package/dist/telemetry/core/lib/client-telemetry-conformance.d.ts.map +1 -0
  86. package/dist/telemetry/core/lib/client-telemetry-conformance.js +38 -0
  87. package/dist/telemetry/core/lib/client-telemetry-conformance.js.map +1 -0
  88. package/dist/telemetry/core/lib/client-telemetry.d.ts +48 -0
  89. package/dist/telemetry/core/lib/client-telemetry.d.ts.map +1 -0
  90. package/dist/telemetry/core/lib/client-telemetry.js +26 -0
  91. package/dist/telemetry/core/lib/client-telemetry.js.map +1 -0
  92. package/dist/telemetry/core/lib/in-memory-client-telemetry.d.ts +20 -0
  93. package/dist/telemetry/core/lib/in-memory-client-telemetry.d.ts.map +1 -0
  94. package/dist/telemetry/core/lib/in-memory-client-telemetry.js +23 -0
  95. package/dist/telemetry/core/lib/in-memory-client-telemetry.js.map +1 -0
  96. package/dist/telemetry/core/lib/none-client-telemetry.d.ts +16 -0
  97. package/dist/telemetry/core/lib/none-client-telemetry.d.ts.map +1 -0
  98. package/dist/telemetry/core/lib/none-client-telemetry.js +22 -0
  99. package/dist/telemetry/core/lib/none-client-telemetry.js.map +1 -0
  100. package/dist/telemetry/index.d.ts +19 -0
  101. package/dist/telemetry/index.d.ts.map +1 -0
  102. package/dist/telemetry/index.js +19 -0
  103. package/dist/telemetry/index.js.map +1 -0
  104. package/dist/telemetry/lib/create-client-telemetry.d.ts +38 -0
  105. package/dist/telemetry/lib/create-client-telemetry.d.ts.map +1 -0
  106. package/dist/telemetry/lib/create-client-telemetry.js +65 -0
  107. package/dist/telemetry/lib/create-client-telemetry.js.map +1 -0
  108. package/dist/telemetry/lib/fan-out-client-telemetry.d.ts +24 -0
  109. package/dist/telemetry/lib/fan-out-client-telemetry.d.ts.map +1 -0
  110. package/dist/telemetry/lib/fan-out-client-telemetry.js +56 -0
  111. package/dist/telemetry/lib/fan-out-client-telemetry.js.map +1 -0
  112. package/dist/telemetry/lib/install-global-error-reporting.d.ts +27 -0
  113. package/dist/telemetry/lib/install-global-error-reporting.d.ts.map +1 -0
  114. package/dist/telemetry/lib/install-global-error-reporting.js +43 -0
  115. package/dist/telemetry/lib/install-global-error-reporting.js.map +1 -0
  116. package/dist/telemetry/lib/local-client-telemetry.d.ts +44 -0
  117. package/dist/telemetry/lib/local-client-telemetry.d.ts.map +1 -0
  118. package/dist/telemetry/lib/local-client-telemetry.js +120 -0
  119. package/dist/telemetry/lib/local-client-telemetry.js.map +1 -0
  120. package/dist/telemetry/lib/logic/describe-client-error.d.ts +24 -0
  121. package/dist/telemetry/lib/logic/describe-client-error.d.ts.map +1 -0
  122. package/dist/telemetry/lib/logic/describe-client-error.js +124 -0
  123. package/dist/telemetry/lib/logic/describe-client-error.js.map +1 -0
  124. package/dist/telemetry/lib/logic/is-chunk-load-failure.d.ts +16 -0
  125. package/dist/telemetry/lib/logic/is-chunk-load-failure.d.ts.map +1 -0
  126. package/dist/telemetry/lib/logic/is-chunk-load-failure.js +34 -0
  127. package/dist/telemetry/lib/logic/is-chunk-load-failure.js.map +1 -0
  128. package/dist/telemetry/lib/logic/refused-read.d.ts +24 -0
  129. package/dist/telemetry/lib/logic/refused-read.d.ts.map +1 -0
  130. package/dist/telemetry/lib/logic/refused-read.js +33 -0
  131. package/dist/telemetry/lib/logic/refused-read.js.map +1 -0
  132. package/dist/telemetry/lib/logic/sentry-configuration.d.ts +67 -0
  133. package/dist/telemetry/lib/logic/sentry-configuration.d.ts.map +1 -0
  134. package/dist/telemetry/lib/logic/sentry-configuration.js +74 -0
  135. package/dist/telemetry/lib/logic/sentry-configuration.js.map +1 -0
  136. package/dist/telemetry/lib/logic/should-report-failure.d.ts +19 -0
  137. package/dist/telemetry/lib/logic/should-report-failure.d.ts.map +1 -0
  138. package/dist/telemetry/lib/logic/should-report-failure.js +41 -0
  139. package/dist/telemetry/lib/logic/should-report-failure.js.map +1 -0
  140. package/dist/telemetry/lib/optional-peer.d.ts +12 -0
  141. package/dist/telemetry/lib/optional-peer.d.ts.map +1 -0
  142. package/dist/telemetry/lib/optional-peer.js +37 -0
  143. package/dist/telemetry/lib/optional-peer.js.map +1 -0
  144. package/dist/telemetry/lib/sentry-client-telemetry.d.ts +74 -0
  145. package/dist/telemetry/lib/sentry-client-telemetry.d.ts.map +1 -0
  146. package/dist/telemetry/lib/sentry-client-telemetry.js +189 -0
  147. package/dist/telemetry/lib/sentry-client-telemetry.js.map +1 -0
  148. package/dist/telemetry/testing.d.ts +3 -0
  149. package/dist/telemetry/testing.d.ts.map +1 -0
  150. package/dist/telemetry/testing.js +3 -0
  151. package/dist/telemetry/testing.js.map +1 -0
  152. package/package.json +58 -4
@@ -0,0 +1,56 @@
1
+ /**
2
+ * "Own the data, rent the tooling" as one class.
3
+ *
4
+ * A fault goes to every destination, not to the best one. Our own API is
5
+ * always first and always present, so the ground truth exists whether or not
6
+ * a vendor is configured, whether or not the user's browser will load it, and
7
+ * whether or not we are still paying for it next year. The vendor is an
8
+ * addition to that record, never a replacement for it.
9
+ *
10
+ * The isolation is the point: one destination throwing, hanging, or being
11
+ * blocked by an extension must not cost the others a single report. So every
12
+ * call is wrapped per destination, and `flush` waits on all of them rather
13
+ * than stopping at the first that fails.
14
+ */
15
+ import { ClientTelemetry } from "../core/index.js";
16
+ export class FanOutClientTelemetry extends ClientTelemetry {
17
+ #destinations;
18
+ constructor(destinations) {
19
+ super();
20
+ this.#destinations = destinations;
21
+ }
22
+ reportError(error, context) {
23
+ for (const destination of this.#destinations) {
24
+ try {
25
+ destination.reportError(error, context);
26
+ }
27
+ catch {
28
+ // Drivers already swallow their own faults; this is the wall for one
29
+ // that does not, so a new destination cannot silence the old ones.
30
+ }
31
+ }
32
+ }
33
+ addBreadcrumb(crumb) {
34
+ for (const destination of this.#destinations) {
35
+ try {
36
+ destination.addBreadcrumb(crumb);
37
+ }
38
+ catch {
39
+ // As above.
40
+ }
41
+ }
42
+ }
43
+ /** True only when every destination delivered; a partial flush is a failure. */
44
+ async flush(timeoutMs) {
45
+ const results = await Promise.all(this.#destinations.map(async (destination) => {
46
+ try {
47
+ return await destination.flush(timeoutMs);
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }));
53
+ return results.every((delivered) => delivered);
54
+ }
55
+ }
56
+ //# sourceMappingURL=fan-out-client-telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fan-out-client-telemetry.js","sourceRoot":"","sources":["../../../src/telemetry/lib/fan-out-client-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,eAAe,EAAmD,MAAM,kBAAkB,CAAC;AAEpG,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IAC/C,aAAa,CAA6B;IAEnD,YAAY,YAAwC;QAClD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAEQ,WAAW,CAAC,KAAc,EAAE,OAAyB;QAC5D,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC7C,IAAI,CAAC;gBACH,WAAW,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,qEAAqE;gBACrE,mEAAmE;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAEQ,aAAa,CAAC,KAA0B;QAC/C,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC7C,IAAI,CAAC;gBACH,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,gFAAgF;IACvE,KAAK,CAAC,KAAK,CAAC,SAAiB;QACpC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YAC3C,IAAI,CAAC;gBACH,OAAO,MAAM,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAC5C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC,CAAC,CACH,CAAC;QACF,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The two faults that reach no framework callback.
3
+ *
4
+ * React tells the app about errors thrown while rendering, and the data layer
5
+ * tells it about failed queries and mutations. Neither sees an exception from
6
+ * an event handler, a `setTimeout`, or a promise nobody awaited — those go to
7
+ * `window`, and without these two listeners they go nowhere at all.
8
+ *
9
+ * A function in the library rather than four lines in `main.tsx`, because the
10
+ * app is composition only and because the rules about what to report belong
11
+ * beside the other rules about what to report.
12
+ */
13
+ import type { ClientTelemetry } from "../core/index.js";
14
+ export type GlobalErrorReportingOptions = {
15
+ readonly telemetry: ClientTelemetry;
16
+ /** Where listeners attach; injected so a test needs no DOM. */
17
+ readonly target: Pick<Window, "addEventListener" | "removeEventListener">;
18
+ /**
19
+ * Asked whenever a chunk fails to load. A deploy replacing the bundle under
20
+ * an open tab is the ordinary cause and is not a fault; returning `true`
21
+ * says the reload path has this and the fault should not be reported.
22
+ */
23
+ readonly staleBuildExplains?: () => boolean;
24
+ };
25
+ /** Installs the listeners and returns the function that removes them. */
26
+ export declare function installGlobalErrorReporting(options: GlobalErrorReportingOptions): () => void;
27
+ //# sourceMappingURL=install-global-error-reporting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-global-error-reporting.d.ts","sourceRoot":"","sources":["../../../src/telemetry/lib/install-global-error-reporting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIxD,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,kBAAkB,GAAG,qBAAqB,CAAC,CAAC;IAC1E;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC;CAC7C,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,2BAA2B,GAAG,MAAM,IAAI,CA0B5F"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The two faults that reach no framework callback.
3
+ *
4
+ * React tells the app about errors thrown while rendering, and the data layer
5
+ * tells it about failed queries and mutations. Neither sees an exception from
6
+ * an event handler, a `setTimeout`, or a promise nobody awaited — those go to
7
+ * `window`, and without these two listeners they go nowhere at all.
8
+ *
9
+ * A function in the library rather than four lines in `main.tsx`, because the
10
+ * app is composition only and because the rules about what to report belong
11
+ * beside the other rules about what to report.
12
+ */
13
+ import { isChunkLoadFailure } from "./logic/is-chunk-load-failure.js";
14
+ import { shouldReportFailure } from "./logic/should-report-failure.js";
15
+ /** Installs the listeners and returns the function that removes them. */
16
+ export function installGlobalErrorReporting(options) {
17
+ const report = (error, kind) => {
18
+ if (isChunkLoadFailure(error)) {
19
+ if (options.staleBuildExplains?.() === true)
20
+ return;
21
+ // The reload path did NOT explain it, so this is the rare real one: a
22
+ // bad deploy or a broken asset path, and exactly worth waking up for.
23
+ options.telemetry.reportError(error, { kind: "chunk-load" });
24
+ return;
25
+ }
26
+ if (shouldReportFailure(error) !== "report")
27
+ return;
28
+ options.telemetry.reportError(error, { kind });
29
+ };
30
+ const onError = (event) => {
31
+ report(event.error ?? event.message, "window-error");
32
+ };
33
+ const onRejection = (event) => {
34
+ report(event.reason, "unhandled-rejection");
35
+ };
36
+ options.target.addEventListener("error", onError);
37
+ options.target.addEventListener("unhandledrejection", onRejection);
38
+ return () => {
39
+ options.target.removeEventListener("error", onError);
40
+ options.target.removeEventListener("unhandledrejection", onRejection);
41
+ };
42
+ }
43
+ //# sourceMappingURL=install-global-error-reporting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-global-error-reporting.js","sourceRoot":"","sources":["../../../src/telemetry/lib/install-global-error-reporting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAcvE,yEAAyE;AACzE,MAAM,UAAU,2BAA2B,CAAC,OAAoC;IAC9E,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,IAA4C,EAAE,EAAE;QAC9E,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,IAAI,OAAO,CAAC,kBAAkB,EAAE,EAAE,KAAK,IAAI;gBAAE,OAAO;YACpD,sEAAsE;YACtE,sEAAsE;YACtE,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YAC7D,OAAO;QACT,CAAC;QACD,IAAI,mBAAmB,CAAC,KAAK,CAAC,KAAK,QAAQ;YAAE,OAAO;QACpD,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,CAAC,KAAiB,EAAQ,EAAE;QAC1C,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACvD,CAAC,CAAC;IACF,MAAM,WAAW,GAAG,CAAC,KAA4B,EAAQ,EAAE;QACzD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;IACnE,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;IACxE,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The driver that reports to our own API.
3
+ *
4
+ * "Own the data" in one class: faults go to `/api/client-diagnostics`, which
5
+ * is same-origin with the app in every deployment, so there is no CORS
6
+ * preflight, no third-party host, and nothing for an ad blocker to drop. What
7
+ * the server does with the envelope afterwards — store it, forward it to a
8
+ * vendor, both — is the server's decision, not the browser's.
9
+ *
10
+ * Three properties it has to hold, and how:
11
+ *
12
+ * - **A report never disturbs the page.** Every path is wrapped; a failure to
13
+ * report is dropped silently, because the alternative is an error handler
14
+ * that throws.
15
+ * - **A burst costs one request.** Events buffer and flush together, so a
16
+ * component failing in a loop does not become a request storm on an API
17
+ * that may already be the thing that is unwell.
18
+ * - **A crash still delivers.** The flush uses `keepalive`, so a report
19
+ * survives the navigation or unload that often follows a fatal client
20
+ * error. That is also why this driver uses `fetch` directly rather than the
21
+ * typed transport: `keepalive` is the whole point, and the transport does
22
+ * not expose it.
23
+ */
24
+ import { type ClientContext } from "@dads-framework/core/contract";
25
+ import { ClientTelemetry, type TelemetryBreadcrumb, type TelemetryContext } from "../core/index.js";
26
+ export type LocalClientTelemetryOptions = {
27
+ /** Where to report. Same-origin in every deployment. */
28
+ readonly endpoint: string;
29
+ /** The build that is running — the git SHA the SPA was stamped with. */
30
+ readonly release: string;
31
+ /** The environment snapshot, asked for per report so it stays current. */
32
+ readonly clientContext: () => ClientContext | undefined;
33
+ readonly now?: () => Date;
34
+ /** Injected so a test can prove the request without a network. */
35
+ readonly send?: typeof fetch;
36
+ };
37
+ export declare class LocalClientTelemetry extends ClientTelemetry {
38
+ #private;
39
+ constructor(options: LocalClientTelemetryOptions);
40
+ reportError(error: unknown, context: TelemetryContext): void;
41
+ addBreadcrumb(crumb: TelemetryBreadcrumb): void;
42
+ flush(timeoutMs: number): Promise<boolean>;
43
+ }
44
+ //# sourceMappingURL=local-client-telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-client-telemetry.d.ts","sourceRoot":"","sources":["../../../src/telemetry/lib/local-client-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAQpG,MAAM,MAAM,2BAA2B,GAAG;IACxC,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,aAAa,EAAE,MAAM,aAAa,GAAG,SAAS,CAAC;IACxD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,kEAAkE;IAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,CAAC;CAC9B,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,eAAe;;IAMvD,YAAY,OAAO,EAAE,2BAA2B,EAG/C;IAEQ,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAYpE;IAEQ,aAAa,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAOvD;IAEc,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAyBxD;CA6BF"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The driver that reports to our own API.
3
+ *
4
+ * "Own the data" in one class: faults go to `/api/client-diagnostics`, which
5
+ * is same-origin with the app in every deployment, so there is no CORS
6
+ * preflight, no third-party host, and nothing for an ad blocker to drop. What
7
+ * the server does with the envelope afterwards — store it, forward it to a
8
+ * vendor, both — is the server's decision, not the browser's.
9
+ *
10
+ * Three properties it has to hold, and how:
11
+ *
12
+ * - **A report never disturbs the page.** Every path is wrapped; a failure to
13
+ * report is dropped silently, because the alternative is an error handler
14
+ * that throws.
15
+ * - **A burst costs one request.** Events buffer and flush together, so a
16
+ * component failing in a loop does not become a request storm on an API
17
+ * that may already be the thing that is unwell.
18
+ * - **A crash still delivers.** The flush uses `keepalive`, so a report
19
+ * survives the navigation or unload that often follows a fatal client
20
+ * error. That is also why this driver uses `fetch` directly rather than the
21
+ * typed transport: `keepalive` is the whole point, and the transport does
22
+ * not expose it.
23
+ */
24
+ import { CLIENT_DIAGNOSTIC_MAX_EVENTS, } from "@dads-framework/core/contract";
25
+ import { ClientTelemetry } from "../core/index.js";
26
+ import { describeClientError } from "./logic/describe-client-error.js";
27
+ /** Breadcrumbs older than this say nothing about the fault that just happened. */
28
+ const MAX_BREADCRUMBS = 30;
29
+ /** Long enough to coalesce a burst, short enough to deliver before a reload. */
30
+ const FLUSH_DELAY_MS = 2_000;
31
+ export class LocalClientTelemetry extends ClientTelemetry {
32
+ #options;
33
+ #pending = [];
34
+ #breadcrumbs = [];
35
+ #scheduled = undefined;
36
+ constructor(options) {
37
+ super();
38
+ this.#options = options;
39
+ }
40
+ reportError(error, context) {
41
+ try {
42
+ this.#pending.push(this.#eventFor(error, context));
43
+ if (this.#pending.length >= CLIENT_DIAGNOSTIC_MAX_EVENTS) {
44
+ void this.flush(FLUSH_DELAY_MS);
45
+ return;
46
+ }
47
+ this.#scheduleFlush();
48
+ }
49
+ catch {
50
+ // A reporter that throws inside an error handler replaces a diagnosable
51
+ // fault with an undiagnosable one.
52
+ }
53
+ }
54
+ addBreadcrumb(crumb) {
55
+ try {
56
+ this.#breadcrumbs.push(crumb);
57
+ if (this.#breadcrumbs.length > MAX_BREADCRUMBS)
58
+ this.#breadcrumbs.shift();
59
+ }
60
+ catch {
61
+ // As above.
62
+ }
63
+ }
64
+ async flush(timeoutMs) {
65
+ if (this.#scheduled !== undefined) {
66
+ clearTimeout(this.#scheduled);
67
+ this.#scheduled = undefined;
68
+ }
69
+ const events = this.#pending.splice(0, this.#pending.length);
70
+ if (events.length === 0)
71
+ return true;
72
+ try {
73
+ const send = this.#options.send ?? fetch;
74
+ const response = await send(this.#options.endpoint, {
75
+ method: "POST",
76
+ credentials: "include",
77
+ headers: { "Content-Type": "application/json" },
78
+ body: JSON.stringify({ events }),
79
+ // Survives the unload that usually follows a fatal client error.
80
+ keepalive: true,
81
+ signal: AbortSignal.timeout(timeoutMs),
82
+ });
83
+ return response.ok;
84
+ }
85
+ catch {
86
+ // Dropped on purpose. Re-buffering would grow without bound on a client
87
+ // that is offline by design, and retrying a report is never worth
88
+ // competing with the real requests the user is waiting on.
89
+ return false;
90
+ }
91
+ }
92
+ #scheduleFlush() {
93
+ if (this.#scheduled !== undefined)
94
+ return;
95
+ this.#scheduled = setTimeout(() => {
96
+ this.#scheduled = undefined;
97
+ void this.flush(FLUSH_DELAY_MS);
98
+ }, FLUSH_DELAY_MS);
99
+ }
100
+ #eventFor(error, context) {
101
+ const described = describeClientError(error);
102
+ const now = this.#options.now?.() ?? new Date();
103
+ const clientContext = this.#options.clientContext();
104
+ return {
105
+ version: 1,
106
+ occurredAt: now.toISOString(),
107
+ fingerprint: described.fingerprint,
108
+ kind: context.kind,
109
+ severity: context.severity ?? "error",
110
+ name: described.name,
111
+ message: described.message,
112
+ frames: [...described.frames],
113
+ breadcrumbs: [...this.#breadcrumbs],
114
+ release: this.#options.release,
115
+ ...(context.requestId === undefined ? {} : { requestId: context.requestId }),
116
+ ...(clientContext === undefined ? {} : { context: clientContext }),
117
+ };
118
+ }
119
+ }
120
+ //# sourceMappingURL=local-client-telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-client-telemetry.js","sourceRoot":"","sources":["../../../src/telemetry/lib/local-client-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,4BAA4B,GAG7B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAmD,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,kFAAkF;AAClF,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,gFAAgF;AAChF,MAAM,cAAc,GAAG,KAAK,CAAC;AAc7B,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IAC9C,QAAQ,CAA8B;IACtC,QAAQ,GAA4B,EAAE,CAAC;IACvC,YAAY,GAA0B,EAAE,CAAC;IAClD,UAAU,GAA8C,SAAS,CAAC;IAElE,YAAY,OAAoC;QAC9C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEQ,WAAW,CAAC,KAAc,EAAE,OAAyB;QAC5D,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;YACnD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,4BAA4B,EAAE,CAAC;gBACzD,KAAK,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;gBAChC,OAAO;YACT,CAAC;YACD,IAAI,CAAC,cA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AAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;SACnE,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A thrown value, reduced to something reportable.
3
+ *
4
+ * Pure, and the only place in the client that reads a stack. Two things it is
5
+ * careful about:
6
+ *
7
+ * - **Frames are locations, never a blob.** A stack string is parsed into
8
+ * `{function, file, line, column}` so the server stores structure it can
9
+ * group and query, and so nothing accidentally ships a stack containing a
10
+ * `file://` path or a query string.
11
+ * - **The fingerprint never uses the message.** Grouping has to survive
12
+ * wording changes, and a message can carry a value that differs every time
13
+ * ("order 12345 not found"), which would make every occurrence its own
14
+ * group. Name plus the top frames is stable.
15
+ */
16
+ import type { ClientDiagnosticFrame } from "@dads-framework/core/contract";
17
+ export type DescribedClientError = {
18
+ readonly name: string;
19
+ readonly message: string;
20
+ readonly frames: readonly ClientDiagnosticFrame[];
21
+ readonly fingerprint: string;
22
+ };
23
+ export declare function describeClientError(error: unknown): DescribedClientError;
24
+ //# sourceMappingURL=describe-client-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe-client-error.d.ts","sourceRoot":"","sources":["../../../../src/telemetry/lib/logic/describe-client-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAQ3E,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAClD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAUxE"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * A thrown value, reduced to something reportable.
3
+ *
4
+ * Pure, and the only place in the client that reads a stack. Two things it is
5
+ * careful about:
6
+ *
7
+ * - **Frames are locations, never a blob.** A stack string is parsed into
8
+ * `{function, file, line, column}` so the server stores structure it can
9
+ * group and query, and so nothing accidentally ships a stack containing a
10
+ * `file://` path or a query string.
11
+ * - **The fingerprint never uses the message.** Grouping has to survive
12
+ * wording changes, and a message can carry a value that differs every time
13
+ * ("order 12345 not found"), which would make every occurrence its own
14
+ * group. Name plus the top frames is stable.
15
+ */
16
+ /** How many frames identify a fault; deeper ones are framework noise. */
17
+ const FINGERPRINT_FRAMES = 3;
18
+ const MAX_FRAMES = 50;
19
+ const MAX_MESSAGE = 1_000;
20
+ const MAX_NAME = 200;
21
+ export function describeClientError(error) {
22
+ const name = errorName(error);
23
+ const message = errorMessage(error);
24
+ const frames = parseFrames(error);
25
+ return {
26
+ name,
27
+ message,
28
+ frames,
29
+ fingerprint: fingerprintOf(name, frames),
30
+ };
31
+ }
32
+ function errorName(error) {
33
+ if (error instanceof Error)
34
+ return clamp(error.name, MAX_NAME);
35
+ return typeof error;
36
+ }
37
+ function errorMessage(error) {
38
+ if (error instanceof Error)
39
+ return clamp(error.message, MAX_MESSAGE);
40
+ if (typeof error === "string")
41
+ return clamp(error, MAX_MESSAGE);
42
+ // A thrown non-Error carries no message worth guessing at, and stringifying
43
+ // an arbitrary object is how user data ends up in a telemetry field.
44
+ return "";
45
+ }
46
+ /**
47
+ * A stack, as frames.
48
+ *
49
+ * Deliberately forgiving: stack formats differ by engine and none of them are
50
+ * a contract. A line that does not parse is skipped rather than failing the
51
+ * report — a fault with three frames is worth far more than no fault at all.
52
+ */
53
+ function parseFrames(error) {
54
+ if (!(error instanceof Error) || typeof error.stack !== "string")
55
+ return [];
56
+ const frames = [];
57
+ for (const line of error.stack.split("\n").slice(1)) {
58
+ const frame = parseFrame(line.trim());
59
+ if (frame !== undefined)
60
+ frames.push(frame);
61
+ if (frames.length >= MAX_FRAMES)
62
+ break;
63
+ }
64
+ return frames;
65
+ }
66
+ /** `at fn (url:line:col)` and the bare `at url:line:col` both appear. */
67
+ const FRAME_WITH_FUNCTION = /^at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)$/;
68
+ const FRAME_WITHOUT_FUNCTION = /^at\s+(.+?):(\d+):(\d+)$/;
69
+ function parseFrame(line) {
70
+ const named = FRAME_WITH_FUNCTION.exec(line);
71
+ if (named !== null) {
72
+ return {
73
+ function: clamp(named[1] ?? "", MAX_NAME),
74
+ file: fileOf(named[2] ?? ""),
75
+ line: Number(named[3]),
76
+ column: Number(named[4]),
77
+ };
78
+ }
79
+ const anonymous = FRAME_WITHOUT_FUNCTION.exec(line);
80
+ if (anonymous !== null) {
81
+ return {
82
+ file: fileOf(anonymous[1] ?? ""),
83
+ line: Number(anonymous[2]),
84
+ column: Number(anonymous[3]),
85
+ };
86
+ }
87
+ return undefined;
88
+ }
89
+ /**
90
+ * The path part of a frame's url.
91
+ *
92
+ * A bundle url can carry a query string, and a query string can carry
93
+ * whatever a router put there. The asset path is what symbolication needs;
94
+ * the rest is not ours to ship.
95
+ */
96
+ function fileOf(location) {
97
+ const withoutQuery = location.split("?")[0] ?? location;
98
+ return clamp(withoutQuery, 500);
99
+ }
100
+ /**
101
+ * A stable group key: the error's name and where it came from.
102
+ *
103
+ * A small non-cryptographic hash, because this identifies a group and
104
+ * guards nothing. It has to be identical for the same fault across reloads
105
+ * and across clients, which rules out anything seeded per session.
106
+ */
107
+ function fingerprintOf(name, frames) {
108
+ const signature = [
109
+ name,
110
+ ...frames
111
+ .slice(0, FINGERPRINT_FRAMES)
112
+ .map((frame) => `${frame.function ?? ""}@${frame.file ?? ""}:${String(frame.line ?? 0)}`),
113
+ ].join("|");
114
+ let hash = 2_166_136_261;
115
+ for (let at = 0; at < signature.length; at += 1) {
116
+ hash ^= signature.charCodeAt(at);
117
+ hash = Math.imul(hash, 16_777_619);
118
+ }
119
+ return (hash >>> 0).toString(16).padStart(8, "0");
120
+ }
121
+ function clamp(value, maximum) {
122
+ return value.length > maximum ? value.slice(0, maximum) : value;
123
+ }
124
+ //# sourceMappingURL=describe-client-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe-client-error.js","sourceRoot":"","sources":["../../../../src/telemetry/lib/logic/describe-client-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,QAAQ,GAAG,GAAG,CAAC;AASrB,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAClC,OAAO;QACL,IAAI;QACJ,OAAO;QACP,MAAM;QACN,WAAW,EAAE,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC;KACzC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/D,OAAO,OAAO,KAAK,CAAC;AACtB,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACrE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAChE,4EAA4E;IAC5E,qEAAqE;IACrE,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW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,GAAG,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,KAAK,CAAC,KAAa,EAAE,OAAe;IAC3C,OAAO,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAClE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Whether a failure is a code-split chunk that would not load.
3
+ *
4
+ * Worth telling apart because it is usually NOT a bug. The common cause is an
5
+ * open tab whose bundle was replaced by a deploy: the browser asks for a
6
+ * hashed asset that no longer exists, and the right answer is to reload, which
7
+ * `subscribeSpaVersionReload` already does. Reporting those would bury the
8
+ * rare real one — a bad deploy, a broken CDN path — under routine noise.
9
+ *
10
+ * Matching on message text, which is ugly and deliberate: browsers give
11
+ * dynamic-import failures no error class and no code, and the wording differs
12
+ * per engine. The list below is what Chrome, Firefox, Safari and Vite's own
13
+ * preload helper actually say.
14
+ */
15
+ export declare function isChunkLoadFailure(error: unknown): boolean;
16
+ //# sourceMappingURL=is-chunk-load-failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-chunk-load-failure.d.ts","sourceRoot":"","sources":["../../../../src/telemetry/lib/logic/is-chunk-load-failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAWH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI1D"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Whether a failure is a code-split chunk that would not load.
3
+ *
4
+ * Worth telling apart because it is usually NOT a bug. The common cause is an
5
+ * open tab whose bundle was replaced by a deploy: the browser asks for a
6
+ * hashed asset that no longer exists, and the right answer is to reload, which
7
+ * `subscribeSpaVersionReload` already does. Reporting those would bury the
8
+ * rare real one — a bad deploy, a broken CDN path — under routine noise.
9
+ *
10
+ * Matching on message text, which is ugly and deliberate: browsers give
11
+ * dynamic-import failures no error class and no code, and the wording differs
12
+ * per engine. The list below is what Chrome, Firefox, Safari and Vite's own
13
+ * preload helper actually say.
14
+ */
15
+ const CHUNK_LOAD_SIGNATURES = [
16
+ "failed to fetch dynamically imported module",
17
+ "error loading dynamically imported module",
18
+ "importing a module script failed",
19
+ "unable to preload css",
20
+ "loading chunk",
21
+ "loading css chunk",
22
+ ];
23
+ export function isChunkLoadFailure(error) {
24
+ const message = messageOf(error).toLowerCase();
25
+ if (message.length === 0)
26
+ return false;
27
+ return CHUNK_LOAD_SIGNATURES.some((signature) => message.includes(signature));
28
+ }
29
+ function messageOf(error) {
30
+ if (error instanceof Error)
31
+ return error.message;
32
+ return typeof error === "string" ? error : "";
33
+ }
34
+ //# sourceMappingURL=is-chunk-load-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-chunk-load-failure.js","sourceRoot":"","sources":["../../../../src/telemetry/lib/logic/is-chunk-load-failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,qBAAqB,GAAG;IAC5B,6CAA6C;IAC7C,2CAA2C;IAC3C,kCAAkC;IAClC,uBAAuB;IACvB,eAAe;IACf,mBAAmB;CACpB,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A page read something its user may not read.
3
+ *
4
+ * `shouldReportFailure` keeps refusals out of telemetry because a refused
5
+ * WRITE is the product saying no. A refused READ is different: the page was
6
+ * opened, so its user was meant to see it, and a page that reads past what
7
+ * opened it shows a default or an empty list instead of the truth, silently.
8
+ * That is a defect in the page, so it is reported, once per call, whether or
9
+ * not the screen handled the error (docs/enforcement.md, "Refused page reads").
10
+ *
11
+ * Only answers the access edge marked (`x-access-refusal: refused`, read by
12
+ * the transport into `refusedForAccess`) count; a handler's plain 404 for a
13
+ * record it did not find never does. The edge cannot tell a record removed
14
+ * since the page loaded from one the user may not reach (both have no
15
+ * relationship to check), so a stale link can raise one of these too; the
16
+ * message says so.
17
+ */
18
+ import type { ApiExchange } from "../../../index.js";
19
+ export declare class RefusedReadError extends Error {
20
+ constructor(message: string);
21
+ }
22
+ /** The error to report for an exchange, or null when it is not a refused read. */
23
+ export declare function refusedReadOf(exchange: ApiExchange): RefusedReadError | null;
24
+ //# sourceMappingURL=refused-read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refused-read.d.ts","sourceRoot":"","sources":["../../../../src/telemetry/lib/logic/refused-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAKD,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI,CAM5E"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A page read something its user may not read.
3
+ *
4
+ * `shouldReportFailure` keeps refusals out of telemetry because a refused
5
+ * WRITE is the product saying no. A refused READ is different: the page was
6
+ * opened, so its user was meant to see it, and a page that reads past what
7
+ * opened it shows a default or an empty list instead of the truth, silently.
8
+ * That is a defect in the page, so it is reported, once per call, whether or
9
+ * not the screen handled the error (docs/enforcement.md, "Refused page reads").
10
+ *
11
+ * Only answers the access edge marked (`x-access-refusal: refused`, read by
12
+ * the transport into `refusedForAccess`) count; a handler's plain 404 for a
13
+ * record it did not find never does. The edge cannot tell a record removed
14
+ * since the page loaded from one the user may not reach (both have no
15
+ * relationship to check), so a stale link can raise one of these too; the
16
+ * message says so.
17
+ */
18
+ export class RefusedReadError extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = "RefusedReadError";
22
+ }
23
+ }
24
+ /** Ids (uuids, long numbers) in a path, so one read groups as one issue. */
25
+ const ID_SEGMENT = /\/(?:[0-9a-f]{8}-[0-9a-f-]{27}|\d{4,})(?=\/|$)/gi;
26
+ /** The error to report for an exchange, or null when it is not a refused read. */
27
+ export function refusedReadOf(exchange) {
28
+ if (exchange.method !== "GET" || !exchange.refusedForAccess)
29
+ return null;
30
+ const path = exchange.path.replace(ID_SEGMENT, "/:id");
31
+ return new RefusedReadError(`Refused read: GET ${path} answered a marked ${String(exchange.status)} to a page its user opened (or the record was removed since the page loaded)`);
32
+ }
33
+ //# sourceMappingURL=refused-read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refused-read.js","sourceRoot":"","sources":["../../../../src/telemetry/lib/logic/refused-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,UAAU,GAAG,kDAAkD,CAAC;AAEtE,kFAAkF;AAClF,MAAM,UAAU,aAAa,CAAC,QAAqB;IACjD,IAAI,QAAQ,CAAC,MAAM,KAAK,KAAK,IAAI,CAAC,QAAQ,CAAC,gBAAgB;QAAE,OAAO,IAAI,CAAC;IACzE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACvD,OAAO,IAAI,gBAAgB,CACzB,qBAAqB,IAAI,sBAAsB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,8EAA8E,CACrJ,CAAC;AACJ,CAAC"}