@haakco/custd-sdk 2.4.0 → 3.71.2

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +586 -40
  3. package/dist/admin-accounting-evidence.d.ts +48 -0
  4. package/dist/admin-accounting-evidence.js +24 -0
  5. package/dist/admin-app-releases.d.ts +116 -0
  6. package/dist/admin-app-releases.js +8 -0
  7. package/dist/admin-apps.d.ts +120 -0
  8. package/dist/admin-apps.js +47 -0
  9. package/dist/admin-auth-project-domain.d.ts +125 -0
  10. package/dist/admin-auth-project-domain.js +37 -0
  11. package/dist/admin-auth-projects.d.ts +989 -0
  12. package/dist/admin-auth-projects.js +527 -0
  13. package/dist/admin-campaign-email.d.ts +120 -0
  14. package/dist/admin-campaign-email.js +64 -0
  15. package/dist/admin-client-setup.d.ts +22 -0
  16. package/dist/admin-client-setup.js +11 -1
  17. package/dist/admin-data-scopes.d.ts +93 -0
  18. package/dist/admin-data-scopes.js +154 -0
  19. package/dist/admin-email-relay.d.ts +66 -0
  20. package/dist/admin-email-relay.js +25 -0
  21. package/dist/admin-environment-policy.d.ts +32 -0
  22. package/dist/admin-environment-policy.js +26 -0
  23. package/dist/admin-error-issues.d.ts +91 -0
  24. package/dist/admin-error-issues.js +52 -0
  25. package/dist/admin-event-types.d.ts +57 -0
  26. package/dist/admin-event-types.js +28 -0
  27. package/dist/admin-impersonation.d.ts +48 -0
  28. package/dist/admin-impersonation.js +27 -0
  29. package/dist/admin-ingest-claims.d.ts +35 -0
  30. package/dist/admin-ingest-claims.js +26 -0
  31. package/dist/admin-managed-audit.d.ts +13 -0
  32. package/dist/admin-managed-audit.js +13 -0
  33. package/dist/admin-measurement-projects.d.ts +166 -0
  34. package/dist/admin-measurement-projects.js +120 -0
  35. package/dist/admin-notification-destinations.d.ts +31 -0
  36. package/dist/admin-notification-destinations.js +19 -0
  37. package/dist/admin-notification-webhooks.d.ts +64 -0
  38. package/dist/admin-notification-webhooks.js +42 -0
  39. package/dist/admin-oauth-client-admissions.d.ts +65 -0
  40. package/dist/admin-oauth-client-admissions.js +46 -0
  41. package/dist/admin-offboarding.d.ts +20 -6
  42. package/dist/admin-offboarding.js +27 -6
  43. package/dist/admin-predictions.d.ts +127 -8
  44. package/dist/admin-predictions.js +22 -12
  45. package/dist/admin-privacy-erasures.d.ts +24 -12
  46. package/dist/admin-privacy-erasures.js +3 -2
  47. package/dist/admin-retention.d.ts +72 -24
  48. package/dist/admin-retention.js +38 -13
  49. package/dist/admin-rls.d.ts +94 -0
  50. package/dist/admin-rls.js +33 -0
  51. package/dist/admin-sdk-usage.d.ts +41 -0
  52. package/dist/admin-sdk-usage.js +23 -0
  53. package/dist/admin-site-ai.d.ts +72 -0
  54. package/dist/admin-site-ai.js +1 -0
  55. package/dist/admin-site-analytics.d.ts +52 -0
  56. package/dist/admin-site-analytics.js +14 -0
  57. package/dist/admin-site-audit-pages.d.ts +76 -0
  58. package/dist/admin-site-audit-pages.js +27 -0
  59. package/dist/admin-site-campaign-links.d.ts +40 -0
  60. package/dist/admin-site-campaign-links.js +9 -0
  61. package/dist/admin-site-domains.d.ts +733 -0
  62. package/dist/admin-site-domains.js +768 -0
  63. package/dist/admin-site-export.d.ts +76 -0
  64. package/dist/admin-site-export.js +15 -0
  65. package/dist/admin-site-insights-tasks.d.ts +44 -0
  66. package/dist/admin-site-insights-tasks.js +28 -0
  67. package/dist/admin-site-insights.d.ts +527 -0
  68. package/dist/admin-site-insights.js +61 -0
  69. package/dist/admin-site-links.d.ts +87 -0
  70. package/dist/admin-site-links.js +16 -0
  71. package/dist/admin-site-monitors.d.ts +110 -0
  72. package/dist/admin-site-monitors.js +25 -0
  73. package/dist/admin-site-next-actions.d.ts +93 -0
  74. package/dist/admin-site-next-actions.js +36 -0
  75. package/dist/admin-site-page-queries.d.ts +63 -0
  76. package/dist/admin-site-page-queries.js +20 -0
  77. package/dist/admin-site-rankings.d.ts +98 -0
  78. package/dist/admin-site-rankings.js +46 -0
  79. package/dist/admin-site-regional-trends.d.ts +30 -0
  80. package/dist/admin-site-regional-trends.js +1 -0
  81. package/dist/admin-site-saved-reports.d.ts +45 -0
  82. package/dist/admin-site-saved-reports.js +13 -0
  83. package/dist/admin-site-search-pool.d.ts +77 -0
  84. package/dist/admin-site-search-pool.js +41 -0
  85. package/dist/admin-site-search-value.d.ts +97 -0
  86. package/dist/admin-site-search-value.js +29 -0
  87. package/dist/admin-site-status-page.d.ts +57 -0
  88. package/dist/admin-site-status-page.js +10 -0
  89. package/dist/admin-site-traffic.d.ts +145 -0
  90. package/dist/admin-site-traffic.js +32 -0
  91. package/dist/admin-site-web-data.d.ts +258 -0
  92. package/dist/admin-site-web-data.js +60 -0
  93. package/dist/admin-subject-exports.d.ts +58 -27
  94. package/dist/admin-subject-exports.js +32 -16
  95. package/dist/admin-support-access.d.ts +32 -0
  96. package/dist/admin-support-access.js +21 -0
  97. package/dist/admin-system.d.ts +283 -0
  98. package/dist/admin-system.js +65 -0
  99. package/dist/admin-tenant-storage.d.ts +22 -14
  100. package/dist/admin-tenant-storage.js +13 -14
  101. package/dist/admin-timeplans.d.ts +276 -2
  102. package/dist/admin-timeplans.js +54 -0
  103. package/dist/admin-uncertainty-models.d.ts +42 -0
  104. package/dist/admin-uncertainty-models.js +53 -0
  105. package/dist/admin-usage.d.ts +124 -0
  106. package/dist/admin-usage.js +169 -0
  107. package/dist/admin-users.d.ts +124 -0
  108. package/dist/admin-users.js +82 -0
  109. package/dist/admin-workflow-timings.d.ts +367 -0
  110. package/dist/admin-workflow-timings.js +117 -0
  111. package/dist/analytics-events.d.ts +82 -0
  112. package/dist/analytics-events.js +157 -0
  113. package/dist/analytics-reads.d.ts +81 -0
  114. package/dist/analytics-reads.js +5 -0
  115. package/dist/app-account.d.ts +84 -0
  116. package/dist/app-account.js +177 -0
  117. package/dist/app-alerts.d.ts +120 -0
  118. package/dist/app-alerts.js +44 -0
  119. package/dist/app-items.d.ts +786 -0
  120. package/dist/app-items.js +524 -0
  121. package/dist/app-live.d.ts +84 -0
  122. package/dist/app-live.js +228 -0
  123. package/dist/app-meetings.d.ts +95 -0
  124. package/dist/app-meetings.js +26 -0
  125. package/dist/app-models.d.ts +271 -0
  126. package/dist/app-models.js +83 -0
  127. package/dist/app-push.d.ts +64 -0
  128. package/dist/app-push.js +178 -0
  129. package/dist/backend-lifecycle.d.ts +2 -2
  130. package/dist/browser-manifest.json +5 -5
  131. package/dist/browser-script-BWnwDjAC.js +711 -0
  132. package/dist/browser-sign-in.d.ts +153 -0
  133. package/dist/browser-sign-in.js +410 -0
  134. package/dist/browser-tracker.d.ts +95 -0
  135. package/dist/browser-tracker.js +362 -40
  136. package/dist/browser-web-vitals.d.ts +22 -0
  137. package/dist/browser-web-vitals.js +116 -0
  138. package/dist/browser.d.ts +9 -0
  139. package/dist/browser.js +9 -0
  140. package/dist/download-stream.d.ts +16 -0
  141. package/dist/download-stream.js +55 -0
  142. package/dist/error-capture.d.ts +62 -0
  143. package/dist/error-capture.js +168 -0
  144. package/dist/hosted-app.d.ts +115 -0
  145. package/dist/hosted-app.js +275 -0
  146. package/dist/index.d.ts +1168 -154
  147. package/dist/index.js +682 -162
  148. package/dist/ingest-operations.d.ts +483 -0
  149. package/dist/ingest-operations.js +154 -0
  150. package/dist/measurement.d.ts +164 -0
  151. package/dist/measurement.js +104 -0
  152. package/dist/parsers.d.ts +149 -0
  153. package/dist/parsers.js +115 -0
  154. package/dist/public-reads.d.ts +79 -0
  155. package/dist/public-reads.js +57 -0
  156. package/dist/reporting-catalogue.d.ts +264 -0
  157. package/dist/reporting-catalogue.js +5 -0
  158. package/dist/response-lists.d.ts +16 -0
  159. package/dist/response-lists.generated.d.ts +7 -0
  160. package/dist/response-lists.generated.js +1927 -0
  161. package/dist/response-lists.js +70 -0
  162. package/dist/response-validation.d.ts +30 -0
  163. package/dist/response-validation.js +94 -0
  164. package/dist/schema-registry.d.ts +45 -0
  165. package/dist/schema-registry.js +9 -0
  166. package/dist/secure-url.d.ts +4 -0
  167. package/dist/secure-url.js +23 -0
  168. package/dist/site-ai-owner.d.ts +34 -0
  169. package/dist/site-ai-owner.js +99 -0
  170. package/dist/site-monitor-reports.d.ts +15 -0
  171. package/dist/site-monitor-reports.js +87 -0
  172. package/dist/testing/fake-custd.d.ts +150 -0
  173. package/dist/testing/fake-custd.js +842 -0
  174. package/dist/testing/fake-results.d.ts +30 -0
  175. package/dist/testing/fake-results.js +293 -0
  176. package/dist/testing.d.ts +2 -0
  177. package/dist/testing.js +3 -0
  178. package/dist/version.d.ts +2 -2
  179. package/dist/version.js +1 -1
  180. package/package.json +25 -14
  181. package/dist/browser-script-BvgjdZSO.js +0 -429
  182. package/dist/fixtures.d.ts +0 -10
  183. package/dist/fixtures.js +0 -57
@@ -0,0 +1,483 @@
1
+ /**
2
+ * Ingest operator surfaces: diagnostics, monitoring, integrity, reprocessing and cleanup.
3
+ * Every call is scoped to the credential's tenant unless it says otherwise.
4
+ */
5
+ import type { RequestOptions } from "./index.js";
6
+ type APIRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions, headers?: Record<string, string>) => Promise<T>;
7
+ /** The header the cleanup-job reads and cancel take their tenant from. */
8
+ export declare const CLEANUP_EFFECTIVE_COMPANY_HEADER = "X-Custd-Effective-Company";
9
+ /** The signed-in principal as ingest resolves it. `userUuid` is set only for a person. */
10
+ export type IngestAccount = {
11
+ userUuid?: string;
12
+ companySlug: string;
13
+ companyName?: string;
14
+ effectiveCompanySlug?: string;
15
+ email: string;
16
+ principalKind?: string;
17
+ roles: string[];
18
+ permissions: string[];
19
+ scopes: string[];
20
+ };
21
+ /** The replay result of one rejected event. */
22
+ export type IngestReprocessOutcome = {
23
+ uuid: string;
24
+ success: boolean;
25
+ error?: string;
26
+ };
27
+ /** One reprocess pass over up to 100 of the tenant's rejected events. */
28
+ export type IngestReprocessResult = {
29
+ processed: number;
30
+ succeeded: number;
31
+ failed: number;
32
+ outcomes: IngestReprocessOutcome[];
33
+ };
34
+ /** One managed audit event to redact, chosen by the pack's selector fields. */
35
+ export type ManagedAuditRedactionEvent = {
36
+ selectors: Record<string, string>;
37
+ fields: string[];
38
+ };
39
+ /** Redacts fields from managed audit events under a redaction rule the tenant's pack declares. */
40
+ export type ManagedAuditRedactionRequest = {
41
+ sourceSystem: string;
42
+ redactionId: string;
43
+ reason: string;
44
+ events: ManagedAuditRedactionEvent[];
45
+ };
46
+ export declare const MANAGED_AUDIT_REDACTION_STATUSES: {
47
+ readonly redacted: "redacted";
48
+ readonly notFound: "not_found";
49
+ };
50
+ export type ManagedAuditRedactionStatus = (typeof MANAGED_AUDIT_REDACTION_STATUSES)[keyof typeof MANAGED_AUDIT_REDACTION_STATUSES];
51
+ export type ManagedAuditRedactionResult = {
52
+ selectors: Record<string, string>;
53
+ status: ManagedAuditRedactionStatus;
54
+ };
55
+ export type ManagedAuditRedactionResponse = {
56
+ success: boolean;
57
+ redactionId: string;
58
+ resultShape: string;
59
+ results: ManagedAuditRedactionResult[];
60
+ };
61
+ /**
62
+ * How the tenant monitoring summary counts. `cached` (the default) serves fresh derived counters
63
+ * when it can; `measured` always counts the ledgers.
64
+ */
65
+ export type IngestMonitoringCounters = "cached" | "measured";
66
+ /** The tenant's ingest counters. Storage totals are platform-wide. */
67
+ export type IngestMonitoringSummary = {
68
+ ingestRequestsTotal: number;
69
+ ingestErrorsTotal: number;
70
+ eventSegmentsVerifiedRowsTotal: number;
71
+ rawEventsLandedTotal: number;
72
+ rawStorageS3Total: number;
73
+ rawLandingS3UploadFailuresTotal: number;
74
+ };
75
+ export type IngestAlertSeverity = "info" | "warning" | "error";
76
+ /** One active ingest alert for the tenant; an all-clear is an `info` alert. */
77
+ export type IngestMonitoringAlert = {
78
+ id: string;
79
+ severity: IngestAlertSeverity;
80
+ title: string;
81
+ message: string;
82
+ };
83
+ export type IngestMonitoringAlertList = {
84
+ alerts: IngestMonitoringAlert[];
85
+ };
86
+ /** Platform-wide ingest and storage counters. */
87
+ export type SystemMonitoringTotals = {
88
+ ingestRequestsTotal: number;
89
+ ingestErrorsTotal: number;
90
+ rawEventsLandedTotal: number;
91
+ rawLandingS3UploadFailuresTotal: number;
92
+ dataSafetyInvariantViolationsTotal: number;
93
+ storageUsageCollectorLastSuccessTimestamp: number;
94
+ claimBacklogCount: number;
95
+ claimBacklogOldestAgeSeconds: number;
96
+ };
97
+ export type SystemMonitoringRankReason = "largest-storage" | "most-rejects";
98
+ /** One tenant ranked as needing attention. */
99
+ export type SystemMonitoringTenant = {
100
+ companySlug: string;
101
+ companyName: string;
102
+ rankReason: SystemMonitoringRankReason;
103
+ attributedStorageBytes: number;
104
+ effectiveLimitBytes: number;
105
+ percentUsed: number;
106
+ rejectedEvents?: number;
107
+ };
108
+ export type SystemMonitoringSummary = {
109
+ generatedAt: string;
110
+ totals: SystemMonitoringTotals;
111
+ topTenants: SystemMonitoringTenant[];
112
+ };
113
+ /** The diagnostics sections ingest serves. Each returns the same full snapshot. */
114
+ export declare const INGEST_DIAGNOSTICS_SECTIONS: {
115
+ readonly ingest: "ingest";
116
+ readonly buffers: "buffers";
117
+ readonly database: "database";
118
+ readonly segments: "segments";
119
+ readonly reporting: "reporting";
120
+ };
121
+ export type IngestDiagnosticsSection = (typeof INGEST_DIAGNOSTICS_SECTIONS)[keyof typeof INGEST_DIAGNOSTICS_SECTIONS];
122
+ export type IngestHealthStatus = "healthy" | "degraded" | "failing" | "unknown";
123
+ export type IngestStatusCounts = {
124
+ "2xx": number;
125
+ "4xx": number;
126
+ "5xx": number;
127
+ };
128
+ export type IngestDiagnosticsIngestState = {
129
+ available: boolean;
130
+ requestRatePerSecond: number;
131
+ statusCounts: IngestStatusCounts;
132
+ p95LatencyMs: number;
133
+ activeRequests: number;
134
+ };
135
+ export type IngestJetStreamState = {
136
+ available: boolean;
137
+ stream?: string;
138
+ consumer?: string;
139
+ pending: number;
140
+ ackPending: number;
141
+ redelivered: number;
142
+ consumerActive: boolean;
143
+ retentionSecondsLeft: number;
144
+ streamState: {
145
+ messages: number;
146
+ bytes: number;
147
+ subjects: number;
148
+ cluster: {
149
+ replicaCount: number;
150
+ leader?: string;
151
+ replicated: boolean;
152
+ allReplicasCurrent: boolean;
153
+ };
154
+ };
155
+ consumerState: {
156
+ numWaiting: number;
157
+ maxAckPending: number;
158
+ ackPendingUtilization: number;
159
+ slowConsumer: boolean;
160
+ deliveredStreamSequence: number;
161
+ deliveredConsumerSequence: number;
162
+ ackFloorStreamSequence: number;
163
+ ackFloorConsumerSequence: number;
164
+ sequenceGap: number;
165
+ };
166
+ };
167
+ export type IngestSegmentState = {
168
+ available: boolean;
169
+ pending: number;
170
+ verified: number;
171
+ failed: number;
172
+ oldestPendingAgeSeconds: number;
173
+ compactedVerified: number;
174
+ compactedFailed: number;
175
+ rollupVerified: number;
176
+ rollupFailed: number;
177
+ compactionEligibleSources: number;
178
+ compactionEstimatedObjectReduction: number;
179
+ };
180
+ export type IngestRollupSchedulerState = {
181
+ intervalSeconds: number;
182
+ nextRunAt: string;
183
+ leaderWorkerId: string;
184
+ queuedRuns: number;
185
+ runningRuns: number;
186
+ failedRuns: number;
187
+ queuedJobs: number;
188
+ claimedJobs: number;
189
+ failedJobs: number;
190
+ latestRunStatus: string;
191
+ };
192
+ export type IngestWorkerState = {
193
+ available: boolean;
194
+ enabled: boolean;
195
+ backlog: number;
196
+ lagSeconds: number;
197
+ failed: number;
198
+ lastSuccessUnix: number;
199
+ lastFailureUnix: number;
200
+ lastFailureReason: string;
201
+ scheduler?: IngestRollupSchedulerState;
202
+ };
203
+ export type IngestObjectStorageState = {
204
+ available: boolean;
205
+ acceptedRawLandingPending: number;
206
+ acceptedRawLandingOldestPendingAgeSeconds: number;
207
+ acceptedRawLandingWritingLeases: number;
208
+ acceptedRawLandingFailedObjects: number;
209
+ acceptedRawLandingConsolidationEligibleWindows: number;
210
+ acceptedRawLandingConsolidationSourceObjects: number;
211
+ acceptedRawLandingConsolidationEstimatedObjectReduction: number;
212
+ acceptedRawLandingS3UploadFailuresTotal: number;
213
+ acceptedRawLandingObjectGroupsPerSecond: number;
214
+ acceptedRawLandingUploadDurationMs: number;
215
+ acceptedRawLandingVerificationDurationMs: number;
216
+ acceptedRawLandingDBMetadataDurationMs: number;
217
+ acceptedRawLandingObjectGroupSizeAverage: number;
218
+ acceptedRawLandingObjectGroupSizeMax: number;
219
+ acceptedRawLandingObjectLimiterSaturation: number;
220
+ };
221
+ export type IngestBufferState = {
222
+ jetstream: IngestJetStreamState;
223
+ segments: IngestSegmentState;
224
+ compaction: IngestWorkerState;
225
+ rollups: IngestWorkerState;
226
+ s3: IngestObjectStorageState;
227
+ };
228
+ export type IngestTopStatement = {
229
+ query: string;
230
+ calls: number;
231
+ totalExecMs: number;
232
+ meanExecMs: number;
233
+ rowsReturned: number;
234
+ walBytes: number;
235
+ };
236
+ export type IngestWaitEvent = {
237
+ type: string;
238
+ event: string;
239
+ count: number;
240
+ };
241
+ export type IngestTableSize = {
242
+ tableName: string;
243
+ rowEstimate: number;
244
+ totalBytes: number;
245
+ tableBytes: number;
246
+ indexBytes: number;
247
+ };
248
+ export type IngestDatabasePoolState = {
249
+ available: boolean;
250
+ active: number;
251
+ waiting: number;
252
+ walBytes: number;
253
+ topStatements?: IngestTopStatement[];
254
+ writeStatements: IngestTopStatement[];
255
+ waitEvents?: IngestWaitEvent[];
256
+ tableSizes?: IngestTableSize[];
257
+ };
258
+ export type IngestDatabaseState = {
259
+ core: IngestDatabasePoolState;
260
+ raw: IngestDatabasePoolState;
261
+ bytesPerEvent: number;
262
+ };
263
+ export type IngestReportingState = {
264
+ available: boolean;
265
+ freshSource: string;
266
+ archiveSource: string;
267
+ missingWindows: number;
268
+ };
269
+ export type IngestStageProgressClassification = "recovering" | "growing" | "steady" | "idle" | "disabled" | "unknown";
270
+ /** How a pipeline stage's backlog is trending. Estimates are present only when ingest has them. */
271
+ export type IngestStageProgress = {
272
+ classification: IngestStageProgressClassification;
273
+ depth: number;
274
+ drainRatePerSecond?: number;
275
+ etaSeconds?: number;
276
+ retentionExpirySeconds?: number;
277
+ note?: string;
278
+ };
279
+ /** One node of the data-path flow; `detailKey` names the snapshot section to drill into. */
280
+ export type IngestPipelineStage = {
281
+ name: string;
282
+ status: IngestHealthStatus;
283
+ headline: string;
284
+ detailKey: string;
285
+ progress?: IngestStageProgress;
286
+ };
287
+ /** The ingest data-path health snapshot: one overall status, then each stage and section. */
288
+ export type IngestDiagnosticsSnapshot = {
289
+ status: IngestHealthStatus;
290
+ generatedAt: string;
291
+ ingest: IngestDiagnosticsIngestState;
292
+ buffers: IngestBufferState;
293
+ database: IngestDatabaseState;
294
+ segments: IngestSegmentState;
295
+ reporting: IngestReportingState;
296
+ silentDrops: {
297
+ dropRatePerSecond: number;
298
+ };
299
+ pipeline: IngestPipelineStage[];
300
+ };
301
+ /** Rows one retention cleanup pass deleted for the tenant. */
302
+ export type IngestCleanupResult = {
303
+ deletedRaw: number;
304
+ deletedEvents: number;
305
+ deletedRejected: number;
306
+ };
307
+ /** Raw events checked against the accepted-landing ledger, and those with no landing. */
308
+ export type IngestIntegrityResult = {
309
+ checkedCount: number;
310
+ orphanedUuids: string[];
311
+ };
312
+ export declare const CLEANUP_MODES: {
313
+ readonly generatedData: "generated-data";
314
+ };
315
+ export type CleanupMode = (typeof CLEANUP_MODES)[keyof typeof CLEANUP_MODES];
316
+ /** A JetStream stream, and optionally its consumers, a cleanup selects. */
317
+ export type CleanupJetStreamSelection = {
318
+ stream: string;
319
+ consumers?: string[];
320
+ executionStatus?: string;
321
+ };
322
+ /** A dry-run or executable generated-data cleanup plan for the credential's tenant. */
323
+ export type CleanupPlanCreateRequest = {
324
+ mode: CleanupMode;
325
+ reason: string;
326
+ dryRun?: boolean;
327
+ execute?: boolean;
328
+ approvedBy?: string;
329
+ approvedS3Prefixes?: string[];
330
+ eventTypeSlug?: string;
331
+ startedAt?: string;
332
+ endedAt?: string;
333
+ jetStream?: CleanupJetStreamSelection[];
334
+ };
335
+ export type CleanupPlanScope = {
336
+ mode: CleanupMode;
337
+ reason?: string;
338
+ tenantSlug?: string;
339
+ eventTypeSlug?: string;
340
+ startedAt?: string;
341
+ endedAt?: string;
342
+ approvedS3Prefixes: string[];
343
+ jetStream?: CleanupJetStreamSelection[];
344
+ jetStreamExecution?: string;
345
+ };
346
+ export type CleanupPlanItem = {
347
+ phase: string;
348
+ dataClass: string;
349
+ storagePrefix?: string;
350
+ selectedCount: number;
351
+ selectedBytes: number;
352
+ executionStatus?: string;
353
+ };
354
+ export type CleanupPlan = {
355
+ planUuid: string;
356
+ mode: CleanupMode;
357
+ status: string;
358
+ reason?: string;
359
+ selectedRows: number;
360
+ selectedObjects: number;
361
+ estimatedBytes: number;
362
+ scope: CleanupPlanScope;
363
+ items: CleanupPlanItem[];
364
+ createdAt?: string;
365
+ };
366
+ export type CleanupPlanList = {
367
+ plans: CleanupPlan[];
368
+ };
369
+ /** Who approved a cleanup and until when the approval holds. */
370
+ export type CleanupApproval = {
371
+ identity: string;
372
+ expiresAt: string;
373
+ };
374
+ /** Enqueues a scoped cleanup job. An omitted tenantSlug uses the credential's tenant. */
375
+ export type CleanupJobCreateRequest = {
376
+ mode: CleanupMode;
377
+ reason: string;
378
+ tenantSlug?: string;
379
+ eventTypeSlug?: string;
380
+ startedAt?: string;
381
+ endedAt?: string;
382
+ approvedS3Prefixes: string[];
383
+ jetStream?: CleanupJetStreamSelection[];
384
+ approval: CleanupApproval;
385
+ };
386
+ export declare const CLEANUP_JOB_STATUSES: {
387
+ readonly queued: "queued";
388
+ readonly dryRun: "dry_run";
389
+ readonly running: "running";
390
+ readonly completed: "completed";
391
+ readonly failed: "failed";
392
+ };
393
+ export type CleanupJobStatus = (typeof CLEANUP_JOB_STATUSES)[keyof typeof CLEANUP_JOB_STATUSES];
394
+ /** How far an object-storage phase has deleted. */
395
+ export type CleanupObjectProgress = {
396
+ sourceKind: string;
397
+ cursorDirection: string;
398
+ cursorId: number;
399
+ cursorReceivedAt?: string;
400
+ batchNumber: number;
401
+ lastBatchIdentity?: string;
402
+ ledgerSelectedCount: number;
403
+ providerAcknowledgedCount: number;
404
+ providerRequestCount: number;
405
+ providerFailureCount: number;
406
+ selectedBytes: number;
407
+ retryCount: number;
408
+ pendingBatchIdentity?: string;
409
+ pendingBatchKeyCount: number;
410
+ pendingBatchAttemptCount?: number;
411
+ pendingBatchTerminal?: boolean;
412
+ lastProgressAt: string;
413
+ version: number;
414
+ };
415
+ export type CleanupJobItem = {
416
+ id: number;
417
+ jobId: number;
418
+ phase: string;
419
+ dataClass: string;
420
+ storagePrefix: string;
421
+ selectedCount: number;
422
+ selectedBytes: number;
423
+ deletedCount: number;
424
+ verifiedCount: number;
425
+ status: string;
426
+ failureReason?: string;
427
+ objectProgress?: CleanupObjectProgress;
428
+ };
429
+ export type CleanupJob = {
430
+ jobId: number;
431
+ jobUuid: string;
432
+ status: CleanupJobStatus;
433
+ tenantSlug: string;
434
+ scopeHash: string;
435
+ holdKind: string;
436
+ approval: CleanupApproval;
437
+ failureReason?: string;
438
+ items: CleanupJobItem[];
439
+ createdAt: string;
440
+ };
441
+ export type CleanupJobList = {
442
+ jobs: CleanupJob[];
443
+ };
444
+ /** The proof document the cleanup worker recorded; its fields are owned by the worker. */
445
+ export type CleanupJobProofDocument = {
446
+ [field: string]: unknown;
447
+ };
448
+ /** A completed job's proof. Ingest answers 409 until the job completes. */
449
+ export type CleanupJobProof = {
450
+ jobUuid: string;
451
+ status: CleanupJobStatus;
452
+ proof: CleanupJobProofDocument;
453
+ };
454
+ export declare class IngestOperationsClient {
455
+ private readonly request;
456
+ private readonly actingCompanySlug;
457
+ constructor(request: APIRequester, actingCompanySlug?: string);
458
+ private cleanupJobRequest;
459
+ /** The signed-in principal, tenant, roles and scopes. */
460
+ account(options?: RequestOptions): Promise<IngestAccount>;
461
+ /** Replays up to 100 of the tenant's rejected events through validation. */
462
+ reprocess(options?: RequestOptions): Promise<IngestReprocessResult>;
463
+ redactManagedAudit(body: ManagedAuditRedactionRequest, options?: RequestOptions): Promise<ManagedAuditRedactionResponse>;
464
+ monitoringSummary(counters?: IngestMonitoringCounters, options?: RequestOptions): Promise<IngestMonitoringSummary>;
465
+ monitoringAlerts(options?: RequestOptions): Promise<IngestMonitoringAlertList>;
466
+ /** The platform-wide view. System administrators only. */
467
+ systemMonitoringSummary(options?: RequestOptions): Promise<SystemMonitoringSummary>;
468
+ /** The data-path health snapshot, read through one of its section routes. System administrators only. */
469
+ diagnostics(section?: IngestDiagnosticsSection, options?: RequestOptions): Promise<IngestDiagnosticsSnapshot>;
470
+ /** Runs one retention cleanup pass for the tenant. */
471
+ cleanup(options?: RequestOptions): Promise<IngestCleanupResult>;
472
+ /** Checks recent raw events against the accepted-landing ledger. */
473
+ checkIntegrity(options?: RequestOptions): Promise<IngestIntegrityResult>;
474
+ listCleanupPlans(options?: RequestOptions): Promise<CleanupPlanList>;
475
+ createCleanupPlan(body: CleanupPlanCreateRequest, options?: RequestOptions): Promise<CleanupPlan>;
476
+ listCleanupJobs(options?: RequestOptions): Promise<CleanupJobList>;
477
+ createCleanupJob(body: CleanupJobCreateRequest, options?: RequestOptions): Promise<CleanupJob>;
478
+ getCleanupJob(jobUuid: string, options?: RequestOptions): Promise<CleanupJob>;
479
+ /** Cancels a job that has not started running and returns its state. */
480
+ cancelCleanupJob(jobUuid: string, options?: RequestOptions): Promise<CleanupJob>;
481
+ getCleanupJobProof(jobUuid: string, options?: RequestOptions): Promise<CleanupJobProof>;
482
+ }
483
+ export {};
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Ingest operator surfaces: diagnostics, monitoring, integrity, reprocessing and cleanup.
3
+ * Every call is scoped to the credential's tenant unless it says otherwise.
4
+ */
5
+ /** The header the cleanup-job reads and cancel take their tenant from. */
6
+ export const CLEANUP_EFFECTIVE_COMPANY_HEADER = "X-Custd-Effective-Company";
7
+ export const MANAGED_AUDIT_REDACTION_STATUSES = { redacted: "redacted", notFound: "not_found" };
8
+ /** The diagnostics sections ingest serves. Each returns the same full snapshot. */
9
+ export const INGEST_DIAGNOSTICS_SECTIONS = {
10
+ ingest: "ingest",
11
+ buffers: "buffers",
12
+ database: "database",
13
+ segments: "segments",
14
+ reporting: "reporting",
15
+ };
16
+ export const CLEANUP_MODES = { generatedData: "generated-data" };
17
+ export const CLEANUP_JOB_STATUSES = {
18
+ queued: "queued",
19
+ dryRun: "dry_run",
20
+ running: "running",
21
+ completed: "completed",
22
+ failed: "failed",
23
+ };
24
+ const cleanupJobsPath = "/cleanup/jobs";
25
+ const cleanupPlansPath = "/admin/cleanup/plans";
26
+ export class IngestOperationsClient {
27
+ constructor(request, actingCompanySlug = "") {
28
+ this.request = request;
29
+ this.actingCompanySlug = actingCompanySlug;
30
+ }
31
+ // cleanupJobRequest sends a cleanup-job read or cancel, naming the configured acting
32
+ // company in the only place those routes read a tenant from.
33
+ cleanupJobRequest(method, path, options) {
34
+ const headers = this.actingCompanySlug
35
+ ? { [CLEANUP_EFFECTIVE_COMPANY_HEADER]: this.actingCompanySlug }
36
+ : {};
37
+ return this.request(method, path, undefined, options, headers);
38
+ }
39
+ /** The signed-in principal, tenant, roles and scopes. */
40
+ async account(options) {
41
+ const wire = await this.request("GET", "/account/me", undefined, options);
42
+ return { ...wire, roles: wire.roles ?? [], permissions: wire.permissions ?? [], scopes: wire.scopes ?? [] };
43
+ }
44
+ /** Replays up to 100 of the tenant's rejected events through validation. */
45
+ async reprocess(options) {
46
+ const wire = await this.request("POST", "/reprocess", undefined, options);
47
+ return { ...wire, outcomes: wire.outcomes ?? [] };
48
+ }
49
+ async redactManagedAudit(body, options) {
50
+ const wire = await this.request("POST", "/managed-audit/redactions", body, options);
51
+ return { ...wire, results: wire.results ?? [] };
52
+ }
53
+ async monitoringSummary(counters = "cached", options) {
54
+ const query = counters === "measured" ? "?counters=measured" : "";
55
+ const wire = await this.request("GET", `/monitoring/summary${query}`, undefined, options);
56
+ return {
57
+ ingestRequestsTotal: wire.ingest_requests_total ?? 0,
58
+ ingestErrorsTotal: wire.ingest_errors_total ?? 0,
59
+ eventSegmentsVerifiedRowsTotal: wire.event_segments_verified_rows_total ?? 0,
60
+ rawEventsLandedTotal: wire.raw_events_landed_total ?? 0,
61
+ rawStorageS3Total: wire.raw_storage_s3_total ?? 0,
62
+ rawLandingS3UploadFailuresTotal: wire.raw_landing_s3_upload_failures_total ?? 0,
63
+ };
64
+ }
65
+ async monitoringAlerts(options) {
66
+ const wire = await this.request("GET", "/monitoring/alerts", undefined, options);
67
+ return { alerts: (wire ?? []).map(({ type, ...alert }) => ({ ...alert, severity: type })) };
68
+ }
69
+ /** The platform-wide view. System administrators only. */
70
+ async systemMonitoringSummary(options) {
71
+ const wire = await this.request("GET", "/system/monitoring/summary", undefined, options);
72
+ return {
73
+ generatedAt: wire.generatedAt,
74
+ totals: systemTotals(wire.totals ?? {}),
75
+ topTenants: wire.topTenants ?? [],
76
+ };
77
+ }
78
+ /** The data-path health snapshot, read through one of its section routes. System administrators only. */
79
+ async diagnostics(section = "ingest", options) {
80
+ const wire = await this.request("GET", `/diagnostics/${section}`, undefined, options);
81
+ return {
82
+ ...wire,
83
+ pipeline: wire.pipeline ?? [],
84
+ database: { ...wire.database, core: pool(wire.database.core), raw: pool(wire.database.raw) },
85
+ };
86
+ }
87
+ /** Runs one retention cleanup pass for the tenant. */
88
+ cleanup(options) {
89
+ return this.request("POST", "/admin/cleanup", undefined, options);
90
+ }
91
+ /** Checks recent raw events against the accepted-landing ledger. */
92
+ async checkIntegrity(options) {
93
+ const wire = await this.request("POST", "/admin/integrity", undefined, options);
94
+ return { checkedCount: wire.checkedCount, orphanedUuids: wire.orphanedUUIDs ?? [] };
95
+ }
96
+ async listCleanupPlans(options) {
97
+ const wire = await this.request("GET", cleanupPlansPath, undefined, options);
98
+ return { plans: (wire.plans ?? []).map(cleanupPlan) };
99
+ }
100
+ async createCleanupPlan(body, options) {
101
+ return cleanupPlan(await this.request("POST", cleanupPlansPath, body, options));
102
+ }
103
+ async listCleanupJobs(options) {
104
+ const wire = await this.cleanupJobRequest("GET", cleanupJobsPath, options);
105
+ return { jobs: (wire.jobs ?? []).map(cleanupJob) };
106
+ }
107
+ async createCleanupJob(body, options) {
108
+ return cleanupJob(await this.request("POST", cleanupJobsPath, body, options));
109
+ }
110
+ async getCleanupJob(jobUuid, options) {
111
+ return cleanupJob(await this.cleanupJobRequest("GET", cleanupJobPath(jobUuid), options));
112
+ }
113
+ /** Cancels a job that has not started running and returns its state. */
114
+ async cancelCleanupJob(jobUuid, options) {
115
+ return cleanupJob(await this.cleanupJobRequest("POST", cleanupJobPath(jobUuid), options));
116
+ }
117
+ getCleanupJobProof(jobUuid, options) {
118
+ return this.cleanupJobRequest("GET", `${cleanupJobPath(jobUuid)}/proof`, options);
119
+ }
120
+ }
121
+ function cleanupJobPath(jobUuid) {
122
+ return `${cleanupJobsPath}/${encodeURIComponent(jobUuid)}`;
123
+ }
124
+ function systemTotals(wire) {
125
+ return {
126
+ ingestRequestsTotal: wire.ingest_requests_total ?? 0,
127
+ ingestErrorsTotal: wire.ingest_errors_total ?? 0,
128
+ rawEventsLandedTotal: wire.raw_events_landed_total ?? 0,
129
+ rawLandingS3UploadFailuresTotal: wire.raw_landing_s3_upload_failures_total ?? 0,
130
+ dataSafetyInvariantViolationsTotal: wire.data_safety_invariant_violations_total ?? 0,
131
+ storageUsageCollectorLastSuccessTimestamp: wire.storage_usage_collector_last_success_timestamp ?? 0,
132
+ claimBacklogCount: wire.claim_backlog_count ?? 0,
133
+ claimBacklogOldestAgeSeconds: wire.claim_backlog_oldest_age_seconds ?? 0,
134
+ };
135
+ }
136
+ function pool(wire) {
137
+ return { ...wire, writeStatements: wire.writeStatements ?? [] };
138
+ }
139
+ function cleanupPlan(wire) {
140
+ return {
141
+ ...wire,
142
+ items: wire.items ?? [],
143
+ scope: { ...wire.scope, approvedS3Prefixes: wire.scope.approvedS3Prefixes ?? [] },
144
+ };
145
+ }
146
+ // Ingest serializes the approval without JSON tags, so its keys arrive capitalized.
147
+ function cleanupJob(wire) {
148
+ const { approval, ...job } = wire;
149
+ return {
150
+ ...job,
151
+ items: wire.items ?? [],
152
+ approval: { identity: approval.Identity, expiresAt: approval.ExpiresAt },
153
+ };
154
+ }