@haakco/custd-sdk 0.0.0-stage → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +412 -2
  2. package/dist/admin-client-setup.d.ts +100 -0
  3. package/dist/admin-client-setup.js +398 -0
  4. package/dist/admin-data-labels.d.ts +124 -0
  5. package/dist/admin-data-labels.js +51 -0
  6. package/dist/admin-offboarding.d.ts +109 -0
  7. package/dist/admin-offboarding.js +108 -0
  8. package/dist/admin-predictions.d.ts +147 -0
  9. package/dist/admin-predictions.js +83 -0
  10. package/dist/admin-privacy-erasures.d.ts +62 -0
  11. package/dist/admin-privacy-erasures.js +72 -0
  12. package/dist/admin-retention.d.ts +51 -0
  13. package/dist/admin-retention.js +35 -0
  14. package/dist/admin-subject-exports.d.ts +48 -0
  15. package/dist/admin-subject-exports.js +28 -0
  16. package/dist/admin-tenant-storage.d.ts +27 -0
  17. package/dist/admin-tenant-storage.js +25 -0
  18. package/dist/admin-timeplans.d.ts +238 -0
  19. package/dist/admin-timeplans.js +146 -0
  20. package/dist/analytics-events.d.ts +85 -0
  21. package/dist/analytics-events.js +40 -0
  22. package/dist/backend-lifecycle.d.ts +85 -0
  23. package/dist/backend-lifecycle.js +212 -0
  24. package/dist/browser-manifest.json +7 -0
  25. package/dist/browser-script-BvgjdZSO.js +429 -0
  26. package/dist/browser-script.d.ts +1 -0
  27. package/dist/browser-script.js +5 -0
  28. package/dist/browser-tracker.d.ts +47 -0
  29. package/dist/browser-tracker.js +453 -0
  30. package/dist/browser.d.ts +1 -0
  31. package/dist/browser.js +1 -0
  32. package/dist/fixtures.d.ts +10 -0
  33. package/dist/fixtures.js +57 -0
  34. package/dist/index.d.ts +1310 -0
  35. package/dist/index.js +1706 -0
  36. package/dist/mobile-adapter.d.ts +25 -0
  37. package/dist/mobile-adapter.js +57 -0
  38. package/dist/mobile-context.d.ts +32 -0
  39. package/dist/mobile-context.js +156 -0
  40. package/dist/mobile-queue.d.ts +22 -0
  41. package/dist/mobile-queue.js +73 -0
  42. package/dist/oauth.d.ts +1 -0
  43. package/dist/oauth.js +8 -0
  44. package/dist/reporting-state.d.ts +46 -0
  45. package/dist/reporting-state.js +76 -0
  46. package/dist/runtime-readiness.d.ts +30 -0
  47. package/dist/runtime-readiness.js +150 -0
  48. package/dist/version.d.ts +10 -0
  49. package/dist/version.js +10 -0
  50. package/package.json +46 -4
@@ -0,0 +1,25 @@
1
+ // TenantStorageClient owns tenant-scoped storage location registration.
2
+ // Locations are server-prefixed: the SDK submits clientLocation and the
3
+ // server returns a serverAssignedPrefix that the SDK must use for raw
4
+ // landing writes. Tenant is derived from the auth context; wrong-tenant
5
+ // reads collapse to an empty list indistinguishable from "no locations".
6
+ export class TenantStorageClient {
7
+ constructor(request) {
8
+ this.request = request;
9
+ }
10
+ list(options) {
11
+ return this.request("GET", "/tenant-storage-locations", undefined, options);
12
+ }
13
+ create(body, options) {
14
+ return this.request("POST", "/tenant-storage-locations", body, options);
15
+ }
16
+ get(id, options) {
17
+ return this.request("GET", `/tenant-storage-locations/${encodeURIComponent(id)}`, undefined, options);
18
+ }
19
+ // Revoke removes a tenant storage location. The server is the authority for
20
+ // whether the prefix is immediately unusable; the SDK must not assume
21
+ // partial deletes are atomic.
22
+ revoke(id, options) {
23
+ return this.request("DELETE", `/tenant-storage-locations/${encodeURIComponent(id)}`, undefined, options);
24
+ }
25
+ }
@@ -0,0 +1,238 @@
1
+ import type { RequestOptions } from "./index.js";
2
+ export type TimePlanAllocationBasis = "absolute" | "horizon_fraction" | "remainder_weight";
3
+ export type TimePlanAnnotationType = "note" | "marker" | "decision" | "action";
4
+ export type TimePlanAnnotationField = "text" | "markerLabel" | "decisionStatus" | "assigneeRef" | "dueDate" | "actionStatus";
5
+ export type TimePlanThresholdCueSeverity = "info" | "warning" | "critical";
6
+ export type TimePlanAnnotationSchema = {
7
+ allowedTypes?: TimePlanAnnotationType[];
8
+ fields?: TimePlanAnnotationField[];
9
+ };
10
+ export type TimePlanThresholdCue = {
11
+ remainingMs: number;
12
+ remainingFractionBps?: never;
13
+ severity: TimePlanThresholdCueSeverity;
14
+ } | {
15
+ remainingFractionBps: number;
16
+ remainingMs?: never;
17
+ severity: TimePlanThresholdCueSeverity;
18
+ };
19
+ export type TimePlanRedactionRequest = {
20
+ reason: string;
21
+ };
22
+ export declare function validateTimePlanDefinition(definition: TimePlanDefinition): void;
23
+ export type TimePlanDefinitionBlock = {
24
+ uuid: string;
25
+ semanticKey: string;
26
+ title: string;
27
+ description?: string;
28
+ category?: string;
29
+ tags?: string[];
30
+ basis: TimePlanAllocationBasis;
31
+ durationMs?: number;
32
+ numerator?: number;
33
+ denominator?: number;
34
+ weight?: number;
35
+ };
36
+ export type TimePlanDefinition = {
37
+ horizonMs: number;
38
+ defaultStartsAt?: string;
39
+ defaultEndsAt?: string;
40
+ redistributionMode?: string;
41
+ autoAdvance?: boolean;
42
+ annotationSchema?: TimePlanAnnotationSchema;
43
+ thresholdCues?: TimePlanThresholdCue[];
44
+ blocks: TimePlanDefinitionBlock[];
45
+ };
46
+ export type TimePlanDraftRequest = {
47
+ planKey: string;
48
+ name: string;
49
+ description?: string;
50
+ definition: TimePlanDefinition;
51
+ };
52
+ export type TimePlanDraftRevisionRequest = TimePlanDraftRequest & {
53
+ expectedRevision: number;
54
+ };
55
+ export type TimePlanRevisionRequest = {
56
+ expectedRevision: number;
57
+ };
58
+ export type TimePlan = {
59
+ uuid: string;
60
+ planKey: string;
61
+ name: string;
62
+ description?: string;
63
+ status: string;
64
+ draftRevision: number;
65
+ definition: TimePlanDefinition;
66
+ updatedAt: string;
67
+ };
68
+ export type TimePlanListResponse = {
69
+ plans: TimePlan[];
70
+ };
71
+ export type TimePlanVersion = {
72
+ uuid: string;
73
+ planUuid: string;
74
+ versionNumber: number;
75
+ definitionHash: string;
76
+ publishedAt: string;
77
+ };
78
+ export type TimePlanRunRequest = {
79
+ planUuid: string;
80
+ versionUuid?: string;
81
+ scheduledStartsAt?: string;
82
+ scheduledEndsAt?: string;
83
+ };
84
+ export type TimePlanAllocation = {
85
+ blockId: string;
86
+ sequence: number;
87
+ durationMs: number;
88
+ };
89
+ export type TimePlanCreatedRun = {
90
+ uuid: string;
91
+ planUuid: string;
92
+ versionUuid: string;
93
+ status: string;
94
+ baselineHorizonMs: number;
95
+ blockAllocations: TimePlanAllocation[];
96
+ createdAt: string;
97
+ };
98
+ export type TimePlanRunBlock = {
99
+ uuid: string;
100
+ sequence: number;
101
+ status: string;
102
+ baselineMs: number;
103
+ currentMs: number;
104
+ allocatedAtStartMs?: number;
105
+ actualActiveMs: number;
106
+ wallStartedAt?: string;
107
+ wallEndedAt?: string;
108
+ outcomeCensored: boolean;
109
+ };
110
+ export type TimePlanRun = {
111
+ uuid: string;
112
+ planUuid: string;
113
+ status: string;
114
+ streamVersion: number;
115
+ scheduledStartsAt?: string;
116
+ scheduledEndsAt?: string;
117
+ effectiveStartsAt?: string;
118
+ effectiveEndsAt?: string;
119
+ startPolicy?: string;
120
+ baselineHorizonMs: number;
121
+ executableHorizonMs?: number;
122
+ lostMs: number;
123
+ unusedMs: number;
124
+ overrunMs: number;
125
+ currentBlockUuid?: string;
126
+ blocks: TimePlanRunBlock[];
127
+ };
128
+ export type TimePlanCommandRequest = {
129
+ commandId: string;
130
+ idempotencyKey: string;
131
+ expectedVersion: number;
132
+ type: string;
133
+ blockId?: string;
134
+ clientOccurredAt?: string;
135
+ boundaryEndsAt?: string;
136
+ scheduledStartsAt?: string;
137
+ scheduledEndsAt?: string;
138
+ startPolicy?: string;
139
+ reason?: string;
140
+ supersedesTransitionUuid?: string;
141
+ corrected?: TimePlanCorrectedCommand;
142
+ };
143
+ export type TimePlanCorrectedCommand = {
144
+ type: string;
145
+ blockId?: string;
146
+ effectiveAt: string;
147
+ boundaryEndsAt?: string;
148
+ startPolicy?: string;
149
+ };
150
+ export type TimePlanCalculationChange = {
151
+ blockId: string;
152
+ fromMs: number;
153
+ toMs: number;
154
+ };
155
+ export type TimePlanCalculationReceipt = {
156
+ allocatorVersion: string;
157
+ reason: string;
158
+ summary: string;
159
+ source: TimePlanAllocation[];
160
+ result: TimePlanAllocation[];
161
+ changes: TimePlanCalculationChange[];
162
+ };
163
+ export type TimePlanCommandResult = {
164
+ transitionUuid: string;
165
+ projection: TimePlanRun;
166
+ receipt: TimePlanCalculationReceipt;
167
+ duplicate: boolean;
168
+ };
169
+ export type TimePlanTransition = {
170
+ uuid: string;
171
+ runUuid: string;
172
+ streamVersion: number;
173
+ commandId: string;
174
+ type: string;
175
+ actorKind: string;
176
+ actorRef: string;
177
+ serverReceivedAt: string;
178
+ clientOccurredAt?: string;
179
+ reason?: string;
180
+ previousStatus?: string;
181
+ currentStatus: string;
182
+ allocatorVersion: string;
183
+ schemaVersion: string;
184
+ supersedesTransitionUuid?: string;
185
+ receipt: TimePlanCalculationReceipt;
186
+ };
187
+ export type TimePlanHistoryResponse = {
188
+ transitions: TimePlanTransition[];
189
+ };
190
+ export type TimePlanAnnotationInput = {
191
+ type: TimePlanAnnotationType | string;
192
+ runBlockUuid?: string;
193
+ text?: string;
194
+ markerLabel?: string;
195
+ decisionStatus?: string;
196
+ assigneeRef?: string;
197
+ dueDate?: string;
198
+ actionStatus?: string;
199
+ };
200
+ export type TimePlanAnnotation = TimePlanAnnotationInput & {
201
+ uuid: string;
202
+ runUuid: string;
203
+ supersedesUuid?: string;
204
+ recordedAt: string;
205
+ actorKind: string;
206
+ actorRef: string;
207
+ redactedAt?: string;
208
+ redactionReason?: string;
209
+ };
210
+ export type TimePlanAnnotationListResponse = {
211
+ annotations: TimePlanAnnotation[];
212
+ };
213
+ type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
214
+ export declare class TimePlanAdminClient {
215
+ private readonly request;
216
+ constructor(request: AdminRequester);
217
+ list(companySlug: string, limit?: number, options?: RequestOptions): Promise<TimePlanListResponse>;
218
+ get(companySlug: string, planUuid: string, options?: RequestOptions): Promise<TimePlan>;
219
+ create(companySlug: string, body: TimePlanDraftRequest, options?: RequestOptions): Promise<TimePlan>;
220
+ preview(companySlug: string, definition: TimePlanDefinition, options?: RequestOptions): Promise<TimePlanAllocationPreview>;
221
+ revise(companySlug: string, planUuid: string, body: TimePlanDraftRevisionRequest, options?: RequestOptions): Promise<TimePlan>;
222
+ publish(companySlug: string, planUuid: string, body: TimePlanRevisionRequest, options?: RequestOptions): Promise<TimePlanVersion>;
223
+ retire(companySlug: string, planUuid: string, options?: RequestOptions): Promise<TimePlan>;
224
+ createRun(companySlug: string, body: TimePlanRunRequest, options?: RequestOptions): Promise<TimePlanCreatedRun>;
225
+ getRun(companySlug: string, runUuid: string, options?: RequestOptions): Promise<TimePlanRun>;
226
+ history(companySlug: string, runUuid: string, limit?: number, options?: RequestOptions): Promise<TimePlanHistoryResponse>;
227
+ execute(companySlug: string, runUuid: string, body: TimePlanCommandRequest, options?: RequestOptions): Promise<TimePlanCommandResult>;
228
+ createAnnotation(companySlug: string, runUuid: string, body: TimePlanAnnotationInput, options?: RequestOptions): Promise<TimePlanAnnotation>;
229
+ listAnnotations(companySlug: string, runUuid: string, limit?: number, options?: RequestOptions): Promise<TimePlanAnnotationListResponse>;
230
+ correctAnnotation(companySlug: string, runUuid: string, annotationUuid: string, body: TimePlanAnnotationInput, options?: RequestOptions): Promise<TimePlanAnnotation>;
231
+ redactAnnotation(companySlug: string, runUuid: string, annotationUuid: string, request: TimePlanRedactionRequest, options?: RequestOptions): Promise<void>;
232
+ }
233
+ export type TimePlanAllocationPreview = {
234
+ allocatorVersion: string;
235
+ horizonMs: number;
236
+ allocations: TimePlanAllocation[];
237
+ };
238
+ export {};
@@ -0,0 +1,146 @@
1
+ const timePlanAnnotationTypes = ["note", "marker", "decision", "action"];
2
+ const timePlanAnnotationFields = [
3
+ "text",
4
+ "markerLabel",
5
+ "decisionStatus",
6
+ "assigneeRef",
7
+ "dueDate",
8
+ "actionStatus",
9
+ ];
10
+ const timePlanAllocationBases = [
11
+ "absolute",
12
+ "horizon_fraction",
13
+ "remainder_weight",
14
+ ];
15
+ const timePlanThresholdSeverities = ["info", "warning", "critical"];
16
+ const maxTimePlanThresholdCues = 16;
17
+ export function validateTimePlanDefinition(definition) {
18
+ if (!Number.isSafeInteger(definition.horizonMs) || definition.horizonMs <= 0) {
19
+ throw new Error("custd: time-plan horizonMs must be a positive integer");
20
+ }
21
+ if (definition.annotationSchema) {
22
+ validateTimePlanEnumList(definition.annotationSchema.allowedTypes, timePlanAnnotationTypes, "allowedTypes", 4);
23
+ validateTimePlanEnumList(definition.annotationSchema.fields, timePlanAnnotationFields, "fields", 6);
24
+ }
25
+ const thresholdCues = definition.thresholdCues ?? [];
26
+ if (thresholdCues.length > maxTimePlanThresholdCues) {
27
+ throw new Error("custd: time-plan thresholdCues cannot contain more than 16 values");
28
+ }
29
+ const seenTriggers = new Set();
30
+ for (const cue of thresholdCues) {
31
+ validateTimePlanThresholdCue(cue);
32
+ const trigger = cue.remainingMs !== undefined ? `ms:${cue.remainingMs}` : `bps:${cue.remainingFractionBps}`;
33
+ if (seenTriggers.has(trigger)) {
34
+ throw new Error("custd: time-plan thresholdCues must not contain duplicate triggers");
35
+ }
36
+ seenTriggers.add(trigger);
37
+ }
38
+ for (const block of definition.blocks) {
39
+ if (!timePlanAllocationBases.includes(block.basis)) {
40
+ throw new Error("custd: time-plan block basis is invalid");
41
+ }
42
+ }
43
+ }
44
+ function validateTimePlanThresholdCue(cue) {
45
+ const hasRemainingMs = cue.remainingMs !== undefined && cue.remainingMs !== null;
46
+ const hasRemainingFractionBps = cue.remainingFractionBps !== undefined && cue.remainingFractionBps !== null;
47
+ if (hasRemainingMs === hasRemainingFractionBps) {
48
+ throw new Error("custd: time-plan threshold cue must have one remaining threshold");
49
+ }
50
+ if (!timePlanThresholdSeverities.includes(cue.severity)) {
51
+ throw new Error("custd: time-plan threshold cue severity is invalid");
52
+ }
53
+ if (hasRemainingMs) {
54
+ const remainingMs = cue.remainingMs;
55
+ if (remainingMs === undefined ||
56
+ remainingMs === null ||
57
+ !Number.isSafeInteger(remainingMs) ||
58
+ remainingMs < 0 ||
59
+ remainingMs > 2419200000) {
60
+ throw new Error("custd: time-plan remainingMs is out of range");
61
+ }
62
+ }
63
+ if (hasRemainingFractionBps) {
64
+ const remainingFractionBps = cue.remainingFractionBps;
65
+ if (remainingFractionBps === undefined ||
66
+ remainingFractionBps === null ||
67
+ !Number.isSafeInteger(remainingFractionBps) ||
68
+ remainingFractionBps < 0 ||
69
+ remainingFractionBps > 10000) {
70
+ throw new Error("custd: time-plan remainingFractionBps is out of range");
71
+ }
72
+ }
73
+ }
74
+ function validateTimePlanEnumList(values, allowed, field, maxItems) {
75
+ if (!values)
76
+ return;
77
+ if (values.length > maxItems || new Set(values).size !== values.length) {
78
+ throw new Error(`custd: time-plan ${field} contains too many or duplicate values`);
79
+ }
80
+ if (values.some((value) => !allowed.includes(value))) {
81
+ throw new Error(`custd: time-plan ${field} contains an unsupported value`);
82
+ }
83
+ }
84
+ export class TimePlanAdminClient {
85
+ constructor(request) {
86
+ this.request = request;
87
+ }
88
+ list(companySlug, limit, options) {
89
+ return this.request("GET", collectionPath("/time-plans", companySlug, limit), undefined, options);
90
+ }
91
+ get(companySlug, planUuid, options) {
92
+ return this.request("GET", resourcePath(`/time-plans/${planUuid}`, companySlug), undefined, options);
93
+ }
94
+ create(companySlug, body, options) {
95
+ validateTimePlanDefinition(body.definition);
96
+ return this.request("POST", collectionPath("/time-plans", companySlug), body, options);
97
+ }
98
+ preview(companySlug, definition, options) {
99
+ validateTimePlanDefinition(definition);
100
+ return this.request("POST", collectionPath("/time-plans/preview", companySlug), definition, options);
101
+ }
102
+ revise(companySlug, planUuid, body, options) {
103
+ validateTimePlanDefinition(body.definition);
104
+ return this.request("PATCH", resourcePath(`/time-plans/${planUuid}`, companySlug), body, options);
105
+ }
106
+ publish(companySlug, planUuid, body, options) {
107
+ return this.request("POST", resourcePath(`/time-plans/${planUuid}/publish`, companySlug), body, options);
108
+ }
109
+ retire(companySlug, planUuid, options) {
110
+ return this.request("POST", resourcePath(`/time-plans/${planUuid}/retire`, companySlug), undefined, options);
111
+ }
112
+ createRun(companySlug, body, options) {
113
+ return this.request("POST", collectionPath("/time-plans/runs", companySlug), body, options);
114
+ }
115
+ getRun(companySlug, runUuid, options) {
116
+ return this.request("GET", resourcePath(`/time-plans/runs/${runUuid}`, companySlug), undefined, options);
117
+ }
118
+ history(companySlug, runUuid, limit, options) {
119
+ return this.request("GET", resourcePath(`/time-plans/runs/${runUuid}/history`, companySlug, limit), undefined, options);
120
+ }
121
+ execute(companySlug, runUuid, body, options) {
122
+ return this.request("POST", resourcePath(`/time-plans/runs/${runUuid}/commands`, companySlug), body, options);
123
+ }
124
+ createAnnotation(companySlug, runUuid, body, options) {
125
+ return this.request("POST", resourcePath(`/time-plans/runs/${runUuid}/annotations`, companySlug), body, options);
126
+ }
127
+ listAnnotations(companySlug, runUuid, limit, options) {
128
+ return this.request("GET", resourcePath(`/time-plans/runs/${runUuid}/annotations`, companySlug, limit), undefined, options);
129
+ }
130
+ correctAnnotation(companySlug, runUuid, annotationUuid, body, options) {
131
+ return this.request("POST", resourcePath(`/time-plans/runs/${runUuid}/annotations/${annotationUuid}/corrections`, companySlug), body, options);
132
+ }
133
+ redactAnnotation(companySlug, runUuid, annotationUuid, request, options) {
134
+ return this.request("POST", resourcePath(`/time-plans/runs/${runUuid}/annotations/${annotationUuid}/redact`, companySlug), request, options);
135
+ }
136
+ }
137
+ function collectionPath(path, companySlug, limit) {
138
+ const query = new URLSearchParams({ companySlug });
139
+ if (limit !== undefined)
140
+ query.set("limit", String(limit));
141
+ return `${path}?${query.toString()}`;
142
+ }
143
+ function resourcePath(path, companySlug, limit) {
144
+ const segments = path.split("/").map((segment, index) => (index === 0 ? segment : encodeURIComponent(segment)));
145
+ return collectionPath(segments.join("/"), companySlug, limit);
146
+ }
@@ -0,0 +1,85 @@
1
+ import type { RequestOptions } from "./index.js";
2
+ /** Sources the server may answer a query from. */
3
+ export type AnalyticsQuerySource = "auto" | "postgres" | "duckdb" | "rollup" | "materialized";
4
+ /**
5
+ * One exact tenant-vocabulary key/value filter.
6
+ *
7
+ * The server accepts at most ANALYTICS_MAX_LABEL_FILTERS of these; more is a request
8
+ * error, so the client rejects the overflow before it leaves the process.
9
+ */
10
+ export type AnalyticsLabelFilter = {
11
+ key: string;
12
+ value: string;
13
+ };
14
+ export type AnalyticsEventQueryRequest = {
15
+ /** UTC day to query, formatted YYYY-MM-DD. The server requires this. */
16
+ date: string;
17
+ /** Exact event-type slug to match. */
18
+ eventType?: string;
19
+ /** Maximum rows to return. The server clamps this and reports the applied count. */
20
+ limit?: number;
21
+ source?: AnalyticsQuerySource;
22
+ labelFilters?: AnalyticsLabelFilter[];
23
+ };
24
+ /**
25
+ * One tenant event.
26
+ *
27
+ * The wire shape is an extensible column bag, but the canonical event payload is always
28
+ * a JSON object. Custd normalises its internal Parquet representation at the API boundary
29
+ * so consumers never need to parse an escaped JSON string.
30
+ */
31
+ export type AnalyticsEventRow = {
32
+ payload?: Record<string, unknown>;
33
+ [column: string]: unknown;
34
+ };
35
+ /**
36
+ * How one source contributed to a query.
37
+ *
38
+ * `complete` and `fresh` are the server's own assessment of whether that source answered
39
+ * the whole request and whether its data sat inside the freshness window. They are the
40
+ * authority for how far a result may be trusted, so they are surfaced unchanged; the
41
+ * client must not substitute its own confidence heuristic.
42
+ */
43
+ export type AnalyticsEventSourceSummary = {
44
+ name: AnalyticsQuerySource;
45
+ count: number;
46
+ parquetUriCount?: number;
47
+ complete: boolean;
48
+ fresh: boolean;
49
+ queryDurationMs: number;
50
+ freshnessLagMs: number;
51
+ message?: string;
52
+ };
53
+ /** Server-measured lag and coverage for a query. */
54
+ export type AnalyticsEventTiming = {
55
+ eventLagP50Ms: number;
56
+ eventLagP95Ms: number;
57
+ eventLagMaxMs: number;
58
+ queryDurationMs: number;
59
+ oldestEventTimestamp?: string;
60
+ newestEventTimestamp?: string;
61
+ snapshotAgeMs: number;
62
+ };
63
+ export type AnalyticsEventQueryResponse = {
64
+ results: AnalyticsEventRow[];
65
+ count: number;
66
+ sources: AnalyticsEventSourceSummary[];
67
+ timing: AnalyticsEventTiming;
68
+ };
69
+ /** The server accepts at most this many label filters on one query. */
70
+ export declare const ANALYTICS_MAX_LABEL_FILTERS = 4;
71
+ type AnalyticsRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
72
+ export declare class AnalyticsEventClient {
73
+ private readonly request;
74
+ constructor(request: AnalyticsRequester);
75
+ /**
76
+ * Query this tenant's own events.
77
+ *
78
+ * Only the documented public fields are serialised. The service also accepts an
79
+ * internal `anonymousId` exact-subject predicate and a `countOnly` flag, but both are
80
+ * deliberately absent from its public JSON contract, so this client must not transmit
81
+ * them even when a caller passes extra properties.
82
+ */
83
+ query(request: AnalyticsEventQueryRequest, options?: RequestOptions): Promise<AnalyticsEventQueryResponse>;
84
+ }
85
+ export {};
@@ -0,0 +1,40 @@
1
+ // AnalyticsEventClient owns the tenant event query: POST /api/v1/analytics/query.
2
+ //
3
+ // It reads a tenant's own ingested events, including payloads, behind the dedicated
4
+ // `events.read` scope. Effective-tenant authority is enforced server-side, so the caller
5
+ // never supplies a tenant slug — the credential already names the tenant.
6
+ /** The server accepts at most this many label filters on one query. */
7
+ export const ANALYTICS_MAX_LABEL_FILTERS = 4;
8
+ export class AnalyticsEventClient {
9
+ constructor(request) {
10
+ this.request = request;
11
+ }
12
+ /**
13
+ * Query this tenant's own events.
14
+ *
15
+ * Only the documented public fields are serialised. The service also accepts an
16
+ * internal `anonymousId` exact-subject predicate and a `countOnly` flag, but both are
17
+ * deliberately absent from its public JSON contract, so this client must not transmit
18
+ * them even when a caller passes extra properties.
19
+ */
20
+ query(request, options) {
21
+ const labelFilters = request.labelFilters ?? [];
22
+ if (labelFilters.length > ANALYTICS_MAX_LABEL_FILTERS) {
23
+ return Promise.reject(new RangeError(`custd: analytics query accepts at most ${ANALYTICS_MAX_LABEL_FILTERS} label filters, received ${labelFilters.length}`));
24
+ }
25
+ const body = { date: request.date };
26
+ if (request.eventType !== undefined) {
27
+ body.eventType = request.eventType;
28
+ }
29
+ if (request.limit !== undefined) {
30
+ body.limit = request.limit;
31
+ }
32
+ if (request.source !== undefined) {
33
+ body.source = request.source;
34
+ }
35
+ if (labelFilters.length > 0) {
36
+ body.labelFilters = labelFilters;
37
+ }
38
+ return this.request("POST", "/analytics/query", body, options);
39
+ }
40
+ }
@@ -0,0 +1,85 @@
1
+ import { type OffboardingAcknowledgeResponse, type OffboardingDownloadResponse, type OffboardingExecuteResponse, type OffboardingExportResponse, type OffboardingPreviewResponse, type OffboardingReceiptResponse } from "./admin-offboarding.js";
2
+ import type { ClientSetupOAuthPurposeProfile, RequestOptions, RuntimeReadinessOptions, RuntimeReadinessResult } from "./index.js";
3
+ export type BackendLifecycleRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
4
+ export type BackendLifecycleDownloader = (path: string, options?: RequestOptions) => Promise<OffboardingDownloadResponse>;
5
+ export type OneTimeCredentialSecret = {
6
+ tenantSlug: string;
7
+ clientId: string;
8
+ purposeProfile: ClientSetupOAuthPurposeProfile;
9
+ clientSecret: string;
10
+ };
11
+ export type PersistOneTimeCredentialSecret = (credential: OneTimeCredentialSecret) => void | Promise<void>;
12
+ export type RotateCredentialOptions = RequestOptions & {
13
+ tenantSlug: string;
14
+ clientId: string;
15
+ purposeProfile: ClientSetupOAuthPurposeProfile;
16
+ persistSecret: PersistOneTimeCredentialSecret;
17
+ };
18
+ export type RotateCredentialResult = {
19
+ tenantSlug: string;
20
+ clientId: string;
21
+ purposeProfile: ClientSetupOAuthPurposeProfile;
22
+ secretPersisted: true;
23
+ };
24
+ export type ZeroStateReconciliationResult = {
25
+ zero: boolean;
26
+ remaining?: readonly string[];
27
+ };
28
+ export type VerifyZeroState = (input: {
29
+ tenantSlug: string;
30
+ requestUuid: string;
31
+ receipt: OffboardingReceiptResponse;
32
+ }) => ZeroStateReconciliationResult | Promise<ZeroStateReconciliationResult>;
33
+ export type ExportDeliveryVerificationResult = {
34
+ verified: boolean;
35
+ evidence?: string;
36
+ };
37
+ export type ReceiveAndVerifyOffboardingExport = (input: {
38
+ tenantSlug: string;
39
+ requestUuid: string;
40
+ download: OffboardingDownloadResponse;
41
+ export?: OffboardingExportResponse;
42
+ }) => ExportDeliveryVerificationResult | Promise<ExportDeliveryVerificationResult>;
43
+ export type PersistOffboardingExport = (input: {
44
+ tenantSlug: string;
45
+ requestUuid: string;
46
+ bytes: Uint8Array;
47
+ checksumSha256: string;
48
+ }) => string | undefined | Promise<string | undefined>;
49
+ export type VerifiedExportReceiverOptions = {
50
+ persist: PersistOffboardingExport;
51
+ };
52
+ export declare function createVerifiedOffboardingExportReceiver(options: VerifiedExportReceiverOptions): ReceiveAndVerifyOffboardingExport;
53
+ export type ZeroStateReconciliationOptions = {
54
+ tenantSlug: string;
55
+ requestUuid: string;
56
+ receipt: OffboardingReceiptResponse;
57
+ verifyZeroState: VerifyZeroState;
58
+ };
59
+ export type CompleteOffboardingOptions = RequestOptions & {
60
+ tenantSlug: string;
61
+ requestUuid: string;
62
+ receiveAndVerifyExport: ReceiveAndVerifyOffboardingExport;
63
+ verifyZeroState: VerifyZeroState;
64
+ };
65
+ export type CompleteOffboardingResult = {
66
+ tenantSlug: string;
67
+ requestUuid: string;
68
+ preview?: OffboardingPreviewResponse;
69
+ export?: OffboardingExportResponse;
70
+ download: OffboardingDownloadResponse;
71
+ exportDelivery: ExportDeliveryVerificationResult;
72
+ acknowledgement: OffboardingAcknowledgeResponse;
73
+ execution: OffboardingExecuteResponse;
74
+ receipt: OffboardingReceiptResponse;
75
+ zeroState: ZeroStateReconciliationResult;
76
+ };
77
+ export declare class BackendLifecycleClient {
78
+ private readonly request;
79
+ private readonly offboarding;
80
+ constructor(request: BackendLifecycleRequester, offboardingDownload: BackendLifecycleDownloader);
81
+ rotateCredential(options: RotateCredentialOptions): Promise<RotateCredentialResult>;
82
+ verifyReadiness(options: RuntimeReadinessOptions): Promise<RuntimeReadinessResult>;
83
+ reconcileZeroState(options: ZeroStateReconciliationOptions): Promise<ZeroStateReconciliationResult>;
84
+ completeOffboarding(options: CompleteOffboardingOptions): Promise<CompleteOffboardingResult>;
85
+ }