@haakco/custd-sdk 0.0.0-stage → 3.71.1

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 (196) hide show
  1. package/README.md +958 -2
  2. package/dist/admin-accounting-evidence.d.ts +48 -0
  3. package/dist/admin-accounting-evidence.js +24 -0
  4. package/dist/admin-app-releases.d.ts +116 -0
  5. package/dist/admin-app-releases.js +8 -0
  6. package/dist/admin-apps.d.ts +120 -0
  7. package/dist/admin-apps.js +47 -0
  8. package/dist/admin-auth-project-domain.d.ts +125 -0
  9. package/dist/admin-auth-project-domain.js +37 -0
  10. package/dist/admin-auth-projects.d.ts +989 -0
  11. package/dist/admin-auth-projects.js +527 -0
  12. package/dist/admin-campaign-email.d.ts +120 -0
  13. package/dist/admin-campaign-email.js +64 -0
  14. package/dist/admin-client-setup.d.ts +122 -0
  15. package/dist/admin-client-setup.js +408 -0
  16. package/dist/admin-data-labels.d.ts +124 -0
  17. package/dist/admin-data-labels.js +51 -0
  18. package/dist/admin-data-scopes.d.ts +93 -0
  19. package/dist/admin-data-scopes.js +154 -0
  20. package/dist/admin-email-relay.d.ts +66 -0
  21. package/dist/admin-email-relay.js +25 -0
  22. package/dist/admin-environment-policy.d.ts +32 -0
  23. package/dist/admin-environment-policy.js +26 -0
  24. package/dist/admin-error-issues.d.ts +91 -0
  25. package/dist/admin-error-issues.js +52 -0
  26. package/dist/admin-event-types.d.ts +57 -0
  27. package/dist/admin-event-types.js +28 -0
  28. package/dist/admin-impersonation.d.ts +48 -0
  29. package/dist/admin-impersonation.js +27 -0
  30. package/dist/admin-ingest-claims.d.ts +35 -0
  31. package/dist/admin-ingest-claims.js +26 -0
  32. package/dist/admin-managed-audit.d.ts +13 -0
  33. package/dist/admin-managed-audit.js +13 -0
  34. package/dist/admin-measurement-projects.d.ts +166 -0
  35. package/dist/admin-measurement-projects.js +120 -0
  36. package/dist/admin-notification-destinations.d.ts +31 -0
  37. package/dist/admin-notification-destinations.js +19 -0
  38. package/dist/admin-notification-webhooks.d.ts +64 -0
  39. package/dist/admin-notification-webhooks.js +42 -0
  40. package/dist/admin-oauth-client-admissions.d.ts +65 -0
  41. package/dist/admin-oauth-client-admissions.js +46 -0
  42. package/dist/admin-offboarding.d.ts +123 -0
  43. package/dist/admin-offboarding.js +129 -0
  44. package/dist/admin-predictions.d.ts +266 -0
  45. package/dist/admin-predictions.js +93 -0
  46. package/dist/admin-privacy-erasures.d.ts +74 -0
  47. package/dist/admin-privacy-erasures.js +73 -0
  48. package/dist/admin-retention.d.ts +99 -0
  49. package/dist/admin-retention.js +60 -0
  50. package/dist/admin-rls.d.ts +94 -0
  51. package/dist/admin-rls.js +33 -0
  52. package/dist/admin-sdk-usage.d.ts +41 -0
  53. package/dist/admin-sdk-usage.js +23 -0
  54. package/dist/admin-site-ai.d.ts +72 -0
  55. package/dist/admin-site-ai.js +1 -0
  56. package/dist/admin-site-analytics.d.ts +52 -0
  57. package/dist/admin-site-analytics.js +14 -0
  58. package/dist/admin-site-audit-pages.d.ts +76 -0
  59. package/dist/admin-site-audit-pages.js +27 -0
  60. package/dist/admin-site-campaign-links.d.ts +40 -0
  61. package/dist/admin-site-campaign-links.js +9 -0
  62. package/dist/admin-site-domains.d.ts +733 -0
  63. package/dist/admin-site-domains.js +768 -0
  64. package/dist/admin-site-export.d.ts +76 -0
  65. package/dist/admin-site-export.js +15 -0
  66. package/dist/admin-site-insights-tasks.d.ts +44 -0
  67. package/dist/admin-site-insights-tasks.js +28 -0
  68. package/dist/admin-site-insights.d.ts +527 -0
  69. package/dist/admin-site-insights.js +61 -0
  70. package/dist/admin-site-links.d.ts +87 -0
  71. package/dist/admin-site-links.js +16 -0
  72. package/dist/admin-site-monitors.d.ts +110 -0
  73. package/dist/admin-site-monitors.js +25 -0
  74. package/dist/admin-site-next-actions.d.ts +93 -0
  75. package/dist/admin-site-next-actions.js +36 -0
  76. package/dist/admin-site-page-queries.d.ts +63 -0
  77. package/dist/admin-site-page-queries.js +20 -0
  78. package/dist/admin-site-rankings.d.ts +98 -0
  79. package/dist/admin-site-rankings.js +46 -0
  80. package/dist/admin-site-regional-trends.d.ts +30 -0
  81. package/dist/admin-site-regional-trends.js +1 -0
  82. package/dist/admin-site-saved-reports.d.ts +45 -0
  83. package/dist/admin-site-saved-reports.js +13 -0
  84. package/dist/admin-site-search-pool.d.ts +77 -0
  85. package/dist/admin-site-search-pool.js +41 -0
  86. package/dist/admin-site-search-value.d.ts +97 -0
  87. package/dist/admin-site-search-value.js +29 -0
  88. package/dist/admin-site-status-page.d.ts +57 -0
  89. package/dist/admin-site-status-page.js +10 -0
  90. package/dist/admin-site-traffic.d.ts +145 -0
  91. package/dist/admin-site-traffic.js +32 -0
  92. package/dist/admin-site-web-data.d.ts +258 -0
  93. package/dist/admin-site-web-data.js +60 -0
  94. package/dist/admin-subject-exports.d.ts +79 -0
  95. package/dist/admin-subject-exports.js +44 -0
  96. package/dist/admin-support-access.d.ts +32 -0
  97. package/dist/admin-support-access.js +21 -0
  98. package/dist/admin-system.d.ts +283 -0
  99. package/dist/admin-system.js +65 -0
  100. package/dist/admin-tenant-storage.d.ts +35 -0
  101. package/dist/admin-tenant-storage.js +24 -0
  102. package/dist/admin-timeplans.d.ts +512 -0
  103. package/dist/admin-timeplans.js +200 -0
  104. package/dist/admin-uncertainty-models.d.ts +42 -0
  105. package/dist/admin-uncertainty-models.js +53 -0
  106. package/dist/admin-usage.d.ts +124 -0
  107. package/dist/admin-usage.js +169 -0
  108. package/dist/admin-users.d.ts +124 -0
  109. package/dist/admin-users.js +82 -0
  110. package/dist/admin-workflow-timings.d.ts +367 -0
  111. package/dist/admin-workflow-timings.js +117 -0
  112. package/dist/analytics-events.d.ts +167 -0
  113. package/dist/analytics-events.js +197 -0
  114. package/dist/analytics-reads.d.ts +81 -0
  115. package/dist/analytics-reads.js +5 -0
  116. package/dist/app-account.d.ts +84 -0
  117. package/dist/app-account.js +177 -0
  118. package/dist/app-alerts.d.ts +120 -0
  119. package/dist/app-alerts.js +44 -0
  120. package/dist/app-items.d.ts +786 -0
  121. package/dist/app-items.js +524 -0
  122. package/dist/app-live.d.ts +84 -0
  123. package/dist/app-live.js +228 -0
  124. package/dist/app-meetings.d.ts +95 -0
  125. package/dist/app-meetings.js +26 -0
  126. package/dist/app-models.d.ts +271 -0
  127. package/dist/app-models.js +83 -0
  128. package/dist/app-push.d.ts +64 -0
  129. package/dist/app-push.js +178 -0
  130. package/dist/backend-lifecycle.d.ts +85 -0
  131. package/dist/backend-lifecycle.js +212 -0
  132. package/dist/browser-manifest.json +7 -0
  133. package/dist/browser-script-BWnwDjAC.js +711 -0
  134. package/dist/browser-script.d.ts +1 -0
  135. package/dist/browser-script.js +5 -0
  136. package/dist/browser-sign-in.d.ts +153 -0
  137. package/dist/browser-sign-in.js +410 -0
  138. package/dist/browser-tracker.d.ts +142 -0
  139. package/dist/browser-tracker.js +775 -0
  140. package/dist/browser-web-vitals.d.ts +22 -0
  141. package/dist/browser-web-vitals.js +116 -0
  142. package/dist/browser.d.ts +10 -0
  143. package/dist/browser.js +10 -0
  144. package/dist/download-stream.d.ts +16 -0
  145. package/dist/download-stream.js +55 -0
  146. package/dist/error-capture.d.ts +62 -0
  147. package/dist/error-capture.js +168 -0
  148. package/dist/hosted-app.d.ts +115 -0
  149. package/dist/hosted-app.js +275 -0
  150. package/dist/index.d.ts +2324 -0
  151. package/dist/index.js +2226 -0
  152. package/dist/ingest-operations.d.ts +483 -0
  153. package/dist/ingest-operations.js +154 -0
  154. package/dist/measurement.d.ts +164 -0
  155. package/dist/measurement.js +104 -0
  156. package/dist/mobile-adapter.d.ts +25 -0
  157. package/dist/mobile-adapter.js +57 -0
  158. package/dist/mobile-context.d.ts +32 -0
  159. package/dist/mobile-context.js +156 -0
  160. package/dist/mobile-queue.d.ts +22 -0
  161. package/dist/mobile-queue.js +73 -0
  162. package/dist/oauth.d.ts +1 -0
  163. package/dist/oauth.js +8 -0
  164. package/dist/parsers.d.ts +149 -0
  165. package/dist/parsers.js +115 -0
  166. package/dist/public-reads.d.ts +79 -0
  167. package/dist/public-reads.js +57 -0
  168. package/dist/reporting-catalogue.d.ts +264 -0
  169. package/dist/reporting-catalogue.js +5 -0
  170. package/dist/reporting-state.d.ts +46 -0
  171. package/dist/reporting-state.js +76 -0
  172. package/dist/response-lists.d.ts +16 -0
  173. package/dist/response-lists.generated.d.ts +7 -0
  174. package/dist/response-lists.generated.js +1927 -0
  175. package/dist/response-lists.js +70 -0
  176. package/dist/response-validation.d.ts +30 -0
  177. package/dist/response-validation.js +94 -0
  178. package/dist/runtime-readiness.d.ts +30 -0
  179. package/dist/runtime-readiness.js +150 -0
  180. package/dist/schema-registry.d.ts +45 -0
  181. package/dist/schema-registry.js +9 -0
  182. package/dist/secure-url.d.ts +4 -0
  183. package/dist/secure-url.js +23 -0
  184. package/dist/site-ai-owner.d.ts +34 -0
  185. package/dist/site-ai-owner.js +99 -0
  186. package/dist/site-monitor-reports.d.ts +15 -0
  187. package/dist/site-monitor-reports.js +87 -0
  188. package/dist/testing/fake-custd.d.ts +150 -0
  189. package/dist/testing/fake-custd.js +842 -0
  190. package/dist/testing/fake-results.d.ts +30 -0
  191. package/dist/testing/fake-results.js +293 -0
  192. package/dist/testing.d.ts +2 -0
  193. package/dist/testing.js +3 -0
  194. package/dist/version.d.ts +10 -0
  195. package/dist/version.js +10 -0
  196. package/package.json +57 -4
@@ -0,0 +1,30 @@
1
+ import type { AppForecastRun, AppForecastRunRequest, AppForecastStory, AppMeasurementProject, AppProjectEstimate, AppProjectEstimateList } from "../app-items.js";
2
+ import { type AppMeeting, type AppMeetingCreate } from "../app-meetings.js";
3
+ import type { AppModelQuantity, AppModelQuantityResult, AppModelSensitivity } from "../app-models.js";
4
+ /** A refusal the fake answers with as an RFC 9457 problem. */
5
+ export declare class FakeCustdProblem extends Error {
6
+ readonly status: number;
7
+ readonly code: string;
8
+ constructor(status: number, code: string);
9
+ }
10
+ export type FakeObservation = {
11
+ observedAt: string;
12
+ value: number;
13
+ };
14
+ /** The `n`th element from the end (1 is the last); `Array.prototype.at` is newer than the SDK's target. */
15
+ export declare function fromEnd<T>(list: T[], n: number): T | undefined;
16
+ /** A least-squares line through the measurements, projected to the target. Needs three points. */
17
+ export declare function fakeForecastRun(project: AppMeasurementProject, observations: FakeObservation[], request: AppForecastRunRequest, meta: {
18
+ runUuid: string;
19
+ now: number;
20
+ }): AppForecastRun;
21
+ export declare function fakeForecastStory(project: AppMeasurementProject, observations: FakeObservation[], now: number): AppForecastStory;
22
+ export declare function fakeEstimateList(estimates: AppProjectEstimate[], deliveryTargetDate: string | undefined, now: number): AppProjectEstimateList;
23
+ /** Each quantity's midpoint and spread, with formulas over earlier quantities. */
24
+ export declare function fakeModelResults(quantities: AppModelQuantity[]): AppModelQuantityResult[];
25
+ export declare function fakeSensitivity(quantities: AppModelQuantity[], output: string): AppModelSensitivity;
26
+ export declare function fakeMeeting(create: AppMeetingCreate, blockUuid: () => string): AppMeeting;
27
+ export declare function startFakeMeeting(meeting: AppMeeting, now: number): void;
28
+ /** Returns false for a repeat of the advance that just happened: the meeting is unchanged. */
29
+ export declare function advanceFakeMeeting(meeting: AppMeeting, blockUuid: string, now: number): boolean;
30
+ export declare function endFakeMeeting(meeting: AppMeeting, now: number): void;
@@ -0,0 +1,293 @@
1
+ // Deterministic stand-ins for the results Custd computes: a straight-line forecast, model runs from
2
+ // each input's midpoint and spread, estimate summaries and meeting steps. They are simple on purpose;
3
+ // they give pages realistic shapes to render, not real statistics.
4
+ import { APP_MEETING_BLOCK_STATUSES, APP_MEETING_ERROR_CODES, APP_MEETING_STATUSES, } from "../app-meetings.js";
5
+ const DAY_MS = 86400000;
6
+ const HISTOGRAM_COUNTS = [40, 140, 320, 300, 150, 50];
7
+ /** A refusal the fake answers with as an RFC 9457 problem. */
8
+ export class FakeCustdProblem extends Error {
9
+ constructor(status, code) {
10
+ super(code);
11
+ this.status = status;
12
+ this.code = code;
13
+ this.name = "FakeCustdProblem";
14
+ }
15
+ }
16
+ /** The `n`th element from the end (1 is the last); `Array.prototype.at` is newer than the SDK's target. */
17
+ export function fromEnd(list, n) {
18
+ return list[list.length - n];
19
+ }
20
+ function iso(ms) {
21
+ return new Date(ms).toISOString();
22
+ }
23
+ function slopeOf(points) {
24
+ const n = points.length;
25
+ const meanT = points.reduce((sum, point) => sum + point.t, 0) / n;
26
+ const meanV = points.reduce((sum, point) => sum + point.v, 0) / n;
27
+ const covariance = points.reduce((sum, point) => sum + (point.t - meanT) * (point.v - meanV), 0);
28
+ const variance = points.reduce((sum, point) => sum + (point.t - meanT) ** 2, 0);
29
+ return variance === 0 ? 0 : covariance / variance;
30
+ }
31
+ /** A least-squares line through the measurements, projected to the target. Needs three points. */
32
+ export function fakeForecastRun(project, observations, request, meta) {
33
+ const from = request.forecastFrom ? Date.parse(request.forecastFrom) : Number.NEGATIVE_INFINITY;
34
+ const points = observations
35
+ .map((row) => ({ t: Date.parse(row.observedAt), v: row.value }))
36
+ .filter((point) => point.t >= from)
37
+ .sort((a, b) => a.t - b.t);
38
+ const run = {
39
+ forecastRunUuid: meta.runUuid,
40
+ projectUuid: project.projectUuid,
41
+ status: "completed",
42
+ method: request.method ?? "bayesian_linear_regression",
43
+ generatedAt: iso(meta.now),
44
+ inputCount: points.length,
45
+ sampleCount: request.sampleCount ?? 1000,
46
+ seed: request.seed ?? 1,
47
+ percentiles: {},
48
+ provenance: { engine: "fake" },
49
+ ...(request.forecastFrom ? { forecastFrom: request.forecastFrom } : {}),
50
+ };
51
+ const last = fromEnd(points, 1);
52
+ const slope = points.length >= 3 ? slopeOf(points) : 0;
53
+ if (last && project.target && slope > 0)
54
+ addCounter(run, project.target, last, slope);
55
+ return run;
56
+ }
57
+ function addCounter(run, target, last, slope) {
58
+ const finish = last.t + (target.targetValue - last.v) / slope;
59
+ const spread = Math.max(DAY_MS, (finish - last.t) * 0.25);
60
+ const lower = finish - spread;
61
+ const upper = finish + spread;
62
+ const deadline = target.targetDate ? Date.parse(target.targetDate) : null;
63
+ const perDay = slope * DAY_MS;
64
+ run.percentiles = { p05: iso(lower), p50: iso(finish), p95: iso(upper) };
65
+ run.counter = {
66
+ completionInterval: { confidence: 0.9, lower: iso(lower), upper: iso(upper) },
67
+ ...(deadline === null
68
+ ? {}
69
+ : { deadlineProbability: Math.min(0.99, Math.max(0.01, 0.5 + (deadline - finish) / (4 * spread))) }),
70
+ rate: { perDay, perHour: perDay / 24, perMinute: perDay / 1440, perSecond: perDay / 86400 },
71
+ pooledRunCount: 1,
72
+ detail: {
73
+ arrivalHistogram: {
74
+ bins: HISTOGRAM_COUNTS.map((count, index) => ({
75
+ start: iso(lower + (index * (upper - lower)) / HISTOGRAM_COUNTS.length),
76
+ end: iso(lower + ((index + 1) * (upper - lower)) / HISTOGRAM_COUNTS.length),
77
+ count,
78
+ })),
79
+ neverCount: 0,
80
+ },
81
+ posteriorLines: [0.8, 0.9, 1, 1.1, 1.2].map((factor) => ({
82
+ points: [
83
+ { at: iso(last.t), value: last.v },
84
+ { at: iso(last.t + (target.targetValue - last.v) / (slope * factor)), value: target.targetValue },
85
+ ],
86
+ })),
87
+ },
88
+ };
89
+ }
90
+ export function fakeForecastStory(project, observations, now) {
91
+ const target = project.target;
92
+ return {
93
+ projectUuid: project.projectUuid,
94
+ projectName: project.name,
95
+ projectKind: project.kind,
96
+ state: "ready",
97
+ truncated: false,
98
+ target: {
99
+ available: target !== undefined,
100
+ label: target?.name ?? "",
101
+ value: target?.targetValue ?? 0,
102
+ ...(target?.targetDate ? { deadline: target.targetDate } : {}),
103
+ },
104
+ observations: [...observations],
105
+ snapshots: [],
106
+ delivery: { estimates: [] },
107
+ presentation: {
108
+ version: 1,
109
+ presetId: "forecast-story",
110
+ renderer: "svg",
111
+ caption: "",
112
+ summary: "",
113
+ nonColorEncoding: "",
114
+ width: 640,
115
+ height: 280,
116
+ layers: [],
117
+ references: [],
118
+ tableColumns: [],
119
+ tableRows: [],
120
+ },
121
+ trust: { state: "ok", evidence: "", observationCount: observations.length, snapshotCount: 0 },
122
+ provenance: { owner: "fake", generatedAt: iso(now) },
123
+ };
124
+ }
125
+ export function fakeEstimateList(estimates, deliveryTargetDate, now) {
126
+ const list = {
127
+ estimates: [...estimates],
128
+ ...(deliveryTargetDate ? { deliveryTargetDate } : {}),
129
+ };
130
+ const latest = fromEnd(estimates, 1);
131
+ if (!latest)
132
+ return list;
133
+ const low = Date.parse(latest.lowDate);
134
+ const high = Date.parse(latest.highDate);
135
+ list.latest = { estimate: latest, ageDays: (now - Date.parse(latest.estimatedAt)) / DAY_MS };
136
+ if (deliveryTargetDate) {
137
+ const chance = (Date.parse(deliveryTargetDate) - low) / Math.max(high - low, DAY_MS);
138
+ list.latest.chanceByDeliveryTarget = Math.min(1, Math.max(0, chance));
139
+ }
140
+ const previous = fromEnd(estimates, 2);
141
+ if (previous) {
142
+ const middle = (low + high) / 2;
143
+ const previousMiddle = (Date.parse(previous.lowDate) + Date.parse(previous.highDate)) / 2;
144
+ list.latest.movementDays = Math.round((middle - previousMiddle) / DAY_MS);
145
+ }
146
+ return list;
147
+ }
148
+ // ---- Models ----
149
+ function midAndSpread(quantity, centre) {
150
+ if (quantity.kind === "formula") {
151
+ // Products or sums of named quantities only; the real engine parses full formulas.
152
+ const values = (quantity.formula.match(/[A-Za-z_]\w*/g) ?? []).map((name) => centre.get(name) ?? 0);
153
+ const mid = quantity.formula.includes("*")
154
+ ? values.reduce((product, value) => product * value, 1)
155
+ : values.reduce((sum, value) => sum + value, 0);
156
+ return { mid, spread: Math.abs(mid) * 0.2 };
157
+ }
158
+ const input = quantity.input;
159
+ if (input.shape === "point")
160
+ return { mid: input.value, spread: 0 };
161
+ if (input.shape === "range")
162
+ return { mid: (input.low + input.high) / 2, spread: (input.high - input.low) / 2 };
163
+ if (input.shape === "proportion")
164
+ return { mid: input.trials === 0 ? 0 : input.successes / input.trials, spread: 0 };
165
+ if (input.shape === "samples")
166
+ return samplesMid(input.samples);
167
+ return { mid: 0, spread: 0 };
168
+ }
169
+ function samplesMid(samples) {
170
+ if (samples.length === 0)
171
+ return { mid: 0, spread: 0 };
172
+ const low = Math.min(...samples);
173
+ const high = Math.max(...samples);
174
+ return { mid: samples.reduce((sum, value) => sum + value, 0) / samples.length, spread: (high - low) / 2 };
175
+ }
176
+ /** Each quantity's midpoint and spread, with formulas over earlier quantities. */
177
+ export function fakeModelResults(quantities) {
178
+ const centre = new Map();
179
+ return quantities.map((quantity) => {
180
+ const { mid, spread } = midAndSpread(quantity, centre);
181
+ centre.set(quantity.name, mid);
182
+ return {
183
+ name: quantity.name,
184
+ summary: {
185
+ mean: mid,
186
+ stdDev: spread / 1.645,
187
+ percentiles: { p5: mid - spread, p25: mid - spread / 2, p50: mid, p75: mid + spread / 2, p95: mid + spread },
188
+ histogram: { min: mid - spread, max: mid + spread, counts: [1, 3, 8, 15, 22, 22, 15, 8, 3, 1] },
189
+ },
190
+ };
191
+ });
192
+ }
193
+ export function fakeSensitivity(quantities, output) {
194
+ const inputs = quantities.filter((quantity) => quantity.kind === "input").map((quantity) => quantity.name);
195
+ return {
196
+ output,
197
+ inputs: inputs.map((name, index) => ({ name, rankCorrelation: 0.8 / (index + 1), share: 1 / inputs.length })),
198
+ };
199
+ }
200
+ // ---- Meetings: start, advance block by block, end; an overrun comes out of the blocks after it ----
201
+ const refused = () => new FakeCustdProblem(409, APP_MEETING_ERROR_CODES.stepRefused);
202
+ export function fakeMeeting(create, blockUuid) {
203
+ const blocks = create.blocks.map((block, position) => ({
204
+ blockUuid: blockUuid(),
205
+ position,
206
+ title: block.title,
207
+ status: APP_MEETING_BLOCK_STATUSES.pending,
208
+ predictedMs: block.predictedMs,
209
+ allocatedMs: block.predictedMs,
210
+ actualMs: 0,
211
+ }));
212
+ return summarise({ name: create.name, status: APP_MEETING_STATUSES.ready, blocks, summary: emptySummary() });
213
+ }
214
+ function emptySummary() {
215
+ return { predictedMs: 0, finishedPredictedMs: 0, finishedActualMs: 0, finishedBlocks: 0, overrunMs: 0 };
216
+ }
217
+ function summarise(meeting) {
218
+ const blocks = meeting.blocks ?? [];
219
+ const finished = blocks.filter((block) => block.status === APP_MEETING_BLOCK_STATUSES.completed);
220
+ const finishedPredictedMs = finished.reduce((sum, block) => sum + block.predictedMs, 0);
221
+ const finishedActualMs = finished.reduce((sum, block) => sum + block.actualMs, 0);
222
+ meeting.summary = {
223
+ predictedMs: blocks.reduce((sum, block) => sum + block.predictedMs, 0),
224
+ finishedPredictedMs,
225
+ finishedActualMs,
226
+ finishedBlocks: finished.length,
227
+ overrunMs: Math.max(0, finishedActualMs - finishedPredictedMs),
228
+ };
229
+ return meeting;
230
+ }
231
+ function activate(meeting, block, now) {
232
+ if (!block) {
233
+ meeting.status = APP_MEETING_STATUSES.completed;
234
+ delete meeting.currentBlockUuid;
235
+ return;
236
+ }
237
+ block.status = APP_MEETING_BLOCK_STATUSES.active;
238
+ block.startedAt = iso(now);
239
+ meeting.currentBlockUuid = block.blockUuid;
240
+ }
241
+ export function startFakeMeeting(meeting, now) {
242
+ if (meeting.status !== APP_MEETING_STATUSES.ready)
243
+ throw refused();
244
+ meeting.status = APP_MEETING_STATUSES.running;
245
+ meeting.startedAt = iso(now);
246
+ meeting.endsAt = iso(now + (meeting.blocks ?? []).reduce((sum, block) => sum + block.predictedMs, 0));
247
+ activate(meeting, meeting.blocks?.[0], now);
248
+ summarise(meeting);
249
+ }
250
+ function finish(block, now) {
251
+ block.status = APP_MEETING_BLOCK_STATUSES.completed;
252
+ block.endedAt = iso(now);
253
+ block.actualMs = now - Date.parse(block.startedAt ?? iso(now));
254
+ }
255
+ function takeOverrun(blocks, overrunMs) {
256
+ let left = overrunMs;
257
+ for (const block of blocks) {
258
+ const taken = Math.min(left, block.allocatedMs);
259
+ block.allocatedMs -= taken;
260
+ left -= taken;
261
+ }
262
+ }
263
+ /** Returns false for a repeat of the advance that just happened: the meeting is unchanged. */
264
+ export function advanceFakeMeeting(meeting, blockUuid, now) {
265
+ const blocks = meeting.blocks ?? [];
266
+ const current = blocks.find((block) => block.blockUuid === meeting.currentBlockUuid);
267
+ if (!current || current.blockUuid !== blockUuid) {
268
+ const lastFinished = fromEnd(blocks.filter((block) => block.status === APP_MEETING_BLOCK_STATUSES.completed), 1);
269
+ if (lastFinished?.blockUuid === blockUuid)
270
+ return false;
271
+ throw refused();
272
+ }
273
+ finish(current, now);
274
+ const later = blocks.filter((block) => block.position > current.position);
275
+ takeOverrun(later, Math.max(0, current.actualMs - current.allocatedMs));
276
+ activate(meeting, later[0], now);
277
+ summarise(meeting);
278
+ return true;
279
+ }
280
+ export function endFakeMeeting(meeting, now) {
281
+ if (meeting.status === APP_MEETING_STATUSES.completed || meeting.status === APP_MEETING_STATUSES.cancelled) {
282
+ throw refused();
283
+ }
284
+ for (const block of meeting.blocks ?? []) {
285
+ if (block.status === APP_MEETING_BLOCK_STATUSES.active)
286
+ finish(block, now);
287
+ if (block.status === APP_MEETING_BLOCK_STATUSES.pending)
288
+ block.status = APP_MEETING_BLOCK_STATUSES.notRun;
289
+ }
290
+ meeting.status = APP_MEETING_STATUSES.completed;
291
+ delete meeting.currentBlockUuid;
292
+ summarise(meeting);
293
+ }
@@ -0,0 +1,2 @@
1
+ export { FAKE_CUSTD_API_PATH, FAKE_CUSTD_AUTH_PATH, FAKE_CUSTD_ORIGIN, FAKE_CUSTD_SITE_KEY, type FakeCapturedError, FakeCustd, type FakeCustdOptions, type FakeCustdRecordedRequest, type FakeCustdRequest, type FakeCustdResponse, type FakeTrackedEvent, memorySignInStorage, signInWithFake, } from "./testing/fake-custd.js";
2
+ export { FakeCustdProblem } from "./testing/fake-results.js";
@@ -0,0 +1,3 @@
1
+ // `@haakco/custd-sdk/testing`: an in-memory Custd for app tests, typed against this SDK's DTOs.
2
+ export { FAKE_CUSTD_API_PATH, FAKE_CUSTD_AUTH_PATH, FAKE_CUSTD_ORIGIN, FAKE_CUSTD_SITE_KEY, FakeCustd, memorySignInStorage, signInWithFake, } from "./testing/fake-custd.js";
3
+ export { FakeCustdProblem } from "./testing/fake-results.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Released SDK version. scripts/check-sdk-version-identity.sh asserts it equals
3
+ * VERSION and scripts/bump-version.sh updates it, so a release cannot leave it
4
+ * behind.
5
+ */
6
+ export declare const SDK_VERSION = "3.71.1";
7
+ /** Product named in X-Custd-Sdk, so Custd can report which callers use which release. */
8
+ export declare const SDK_PRODUCT = "js";
9
+ /** Value sent in the X-Custd-Sdk header. */
10
+ export declare const SDK_IDENTITY = "js/3.71.1";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Released SDK version. scripts/check-sdk-version-identity.sh asserts it equals
3
+ * VERSION and scripts/bump-version.sh updates it, so a release cannot leave it
4
+ * behind.
5
+ */
6
+ export const SDK_VERSION = "3.71.1";
7
+ /** Product named in X-Custd-Sdk, so Custd can report which callers use which release. */
8
+ export const SDK_PRODUCT = "js";
9
+ /** Value sent in the X-Custd-Sdk header. */
10
+ export const SDK_IDENTITY = `${SDK_PRODUCT}/${SDK_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@haakco/custd-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "3.71.1",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=24 <27"
7
+ },
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./browser": {
18
+ "types": "./dist/browser.d.ts",
19
+ "import": "./dist/browser.js",
20
+ "default": "./dist/browser.js"
21
+ },
22
+ "./browser-script": {
23
+ "types": "./dist/browser-script.d.ts",
24
+ "import": "./dist/browser-script.js",
25
+ "default": "./dist/browser-script.js"
26
+ },
27
+ "./testing": {
28
+ "types": "./dist/testing.d.ts",
29
+ "import": "./dist/testing.js",
30
+ "default": "./dist/testing.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "build": "pnpm run build:ts && pnpm run build:browser",
38
+ "build:browser": "node scripts/build-browser.mjs",
39
+ "build:ts": "tsc -p tsconfig.build.json",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit",
41
+ "lint": "biome check src",
42
+ "lint:fix": "biome check --write src",
43
+ "test": "vitest run src",
44
+ "smoke:dev": "pnpm run build && node scripts/smoke-dev.js",
45
+ "generate:response-lists": "node scripts/generate-response-lists.ts"
46
+ },
47
+ "devDependencies": {
48
+ "@biomejs/biome": "^2.6.8",
49
+ "typescript": "^7.0.2",
50
+ "vite": "8.3.8",
51
+ "vitest": "^5.1.0"
52
+ },
53
+ "license": "UNLICENSED",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/haakco/custd-sdk.git",
57
+ "directory": "sdk-js"
58
+ }
59
+ }