@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.
- package/README.md +958 -2
- package/dist/admin-accounting-evidence.d.ts +48 -0
- package/dist/admin-accounting-evidence.js +24 -0
- package/dist/admin-app-releases.d.ts +116 -0
- package/dist/admin-app-releases.js +8 -0
- package/dist/admin-apps.d.ts +120 -0
- package/dist/admin-apps.js +47 -0
- package/dist/admin-auth-project-domain.d.ts +125 -0
- package/dist/admin-auth-project-domain.js +37 -0
- package/dist/admin-auth-projects.d.ts +989 -0
- package/dist/admin-auth-projects.js +527 -0
- package/dist/admin-campaign-email.d.ts +120 -0
- package/dist/admin-campaign-email.js +64 -0
- package/dist/admin-client-setup.d.ts +122 -0
- package/dist/admin-client-setup.js +408 -0
- package/dist/admin-data-labels.d.ts +124 -0
- package/dist/admin-data-labels.js +51 -0
- package/dist/admin-data-scopes.d.ts +93 -0
- package/dist/admin-data-scopes.js +154 -0
- package/dist/admin-email-relay.d.ts +66 -0
- package/dist/admin-email-relay.js +25 -0
- package/dist/admin-environment-policy.d.ts +32 -0
- package/dist/admin-environment-policy.js +26 -0
- package/dist/admin-error-issues.d.ts +91 -0
- package/dist/admin-error-issues.js +52 -0
- package/dist/admin-event-types.d.ts +57 -0
- package/dist/admin-event-types.js +28 -0
- package/dist/admin-impersonation.d.ts +48 -0
- package/dist/admin-impersonation.js +27 -0
- package/dist/admin-ingest-claims.d.ts +35 -0
- package/dist/admin-ingest-claims.js +26 -0
- package/dist/admin-managed-audit.d.ts +13 -0
- package/dist/admin-managed-audit.js +13 -0
- package/dist/admin-measurement-projects.d.ts +166 -0
- package/dist/admin-measurement-projects.js +120 -0
- package/dist/admin-notification-destinations.d.ts +31 -0
- package/dist/admin-notification-destinations.js +19 -0
- package/dist/admin-notification-webhooks.d.ts +64 -0
- package/dist/admin-notification-webhooks.js +42 -0
- package/dist/admin-oauth-client-admissions.d.ts +65 -0
- package/dist/admin-oauth-client-admissions.js +46 -0
- package/dist/admin-offboarding.d.ts +123 -0
- package/dist/admin-offboarding.js +129 -0
- package/dist/admin-predictions.d.ts +266 -0
- package/dist/admin-predictions.js +93 -0
- package/dist/admin-privacy-erasures.d.ts +74 -0
- package/dist/admin-privacy-erasures.js +73 -0
- package/dist/admin-retention.d.ts +99 -0
- package/dist/admin-retention.js +60 -0
- package/dist/admin-rls.d.ts +94 -0
- package/dist/admin-rls.js +33 -0
- package/dist/admin-sdk-usage.d.ts +41 -0
- package/dist/admin-sdk-usage.js +23 -0
- package/dist/admin-site-ai.d.ts +72 -0
- package/dist/admin-site-ai.js +1 -0
- package/dist/admin-site-analytics.d.ts +52 -0
- package/dist/admin-site-analytics.js +14 -0
- package/dist/admin-site-audit-pages.d.ts +76 -0
- package/dist/admin-site-audit-pages.js +27 -0
- package/dist/admin-site-campaign-links.d.ts +40 -0
- package/dist/admin-site-campaign-links.js +9 -0
- package/dist/admin-site-domains.d.ts +733 -0
- package/dist/admin-site-domains.js +768 -0
- package/dist/admin-site-export.d.ts +76 -0
- package/dist/admin-site-export.js +15 -0
- package/dist/admin-site-insights-tasks.d.ts +44 -0
- package/dist/admin-site-insights-tasks.js +28 -0
- package/dist/admin-site-insights.d.ts +527 -0
- package/dist/admin-site-insights.js +61 -0
- package/dist/admin-site-links.d.ts +87 -0
- package/dist/admin-site-links.js +16 -0
- package/dist/admin-site-monitors.d.ts +110 -0
- package/dist/admin-site-monitors.js +25 -0
- package/dist/admin-site-next-actions.d.ts +93 -0
- package/dist/admin-site-next-actions.js +36 -0
- package/dist/admin-site-page-queries.d.ts +63 -0
- package/dist/admin-site-page-queries.js +20 -0
- package/dist/admin-site-rankings.d.ts +98 -0
- package/dist/admin-site-rankings.js +46 -0
- package/dist/admin-site-regional-trends.d.ts +30 -0
- package/dist/admin-site-regional-trends.js +1 -0
- package/dist/admin-site-saved-reports.d.ts +45 -0
- package/dist/admin-site-saved-reports.js +13 -0
- package/dist/admin-site-search-pool.d.ts +77 -0
- package/dist/admin-site-search-pool.js +41 -0
- package/dist/admin-site-search-value.d.ts +97 -0
- package/dist/admin-site-search-value.js +29 -0
- package/dist/admin-site-status-page.d.ts +57 -0
- package/dist/admin-site-status-page.js +10 -0
- package/dist/admin-site-traffic.d.ts +145 -0
- package/dist/admin-site-traffic.js +32 -0
- package/dist/admin-site-web-data.d.ts +258 -0
- package/dist/admin-site-web-data.js +60 -0
- package/dist/admin-subject-exports.d.ts +79 -0
- package/dist/admin-subject-exports.js +44 -0
- package/dist/admin-support-access.d.ts +32 -0
- package/dist/admin-support-access.js +21 -0
- package/dist/admin-system.d.ts +283 -0
- package/dist/admin-system.js +65 -0
- package/dist/admin-tenant-storage.d.ts +35 -0
- package/dist/admin-tenant-storage.js +24 -0
- package/dist/admin-timeplans.d.ts +512 -0
- package/dist/admin-timeplans.js +200 -0
- package/dist/admin-uncertainty-models.d.ts +42 -0
- package/dist/admin-uncertainty-models.js +53 -0
- package/dist/admin-usage.d.ts +124 -0
- package/dist/admin-usage.js +169 -0
- package/dist/admin-users.d.ts +124 -0
- package/dist/admin-users.js +82 -0
- package/dist/admin-workflow-timings.d.ts +367 -0
- package/dist/admin-workflow-timings.js +117 -0
- package/dist/analytics-events.d.ts +167 -0
- package/dist/analytics-events.js +197 -0
- package/dist/analytics-reads.d.ts +81 -0
- package/dist/analytics-reads.js +5 -0
- package/dist/app-account.d.ts +84 -0
- package/dist/app-account.js +177 -0
- package/dist/app-alerts.d.ts +120 -0
- package/dist/app-alerts.js +44 -0
- package/dist/app-items.d.ts +786 -0
- package/dist/app-items.js +524 -0
- package/dist/app-live.d.ts +84 -0
- package/dist/app-live.js +228 -0
- package/dist/app-meetings.d.ts +95 -0
- package/dist/app-meetings.js +26 -0
- package/dist/app-models.d.ts +271 -0
- package/dist/app-models.js +83 -0
- package/dist/app-push.d.ts +64 -0
- package/dist/app-push.js +178 -0
- package/dist/backend-lifecycle.d.ts +85 -0
- package/dist/backend-lifecycle.js +212 -0
- package/dist/browser-manifest.json +7 -0
- package/dist/browser-script-BWnwDjAC.js +711 -0
- package/dist/browser-script.d.ts +1 -0
- package/dist/browser-script.js +5 -0
- package/dist/browser-sign-in.d.ts +153 -0
- package/dist/browser-sign-in.js +410 -0
- package/dist/browser-tracker.d.ts +142 -0
- package/dist/browser-tracker.js +775 -0
- package/dist/browser-web-vitals.d.ts +22 -0
- package/dist/browser-web-vitals.js +116 -0
- package/dist/browser.d.ts +10 -0
- package/dist/browser.js +10 -0
- package/dist/download-stream.d.ts +16 -0
- package/dist/download-stream.js +55 -0
- package/dist/error-capture.d.ts +62 -0
- package/dist/error-capture.js +168 -0
- package/dist/hosted-app.d.ts +115 -0
- package/dist/hosted-app.js +275 -0
- package/dist/index.d.ts +2324 -0
- package/dist/index.js +2226 -0
- package/dist/ingest-operations.d.ts +483 -0
- package/dist/ingest-operations.js +154 -0
- package/dist/measurement.d.ts +164 -0
- package/dist/measurement.js +104 -0
- package/dist/mobile-adapter.d.ts +25 -0
- package/dist/mobile-adapter.js +57 -0
- package/dist/mobile-context.d.ts +32 -0
- package/dist/mobile-context.js +156 -0
- package/dist/mobile-queue.d.ts +22 -0
- package/dist/mobile-queue.js +73 -0
- package/dist/oauth.d.ts +1 -0
- package/dist/oauth.js +8 -0
- package/dist/parsers.d.ts +149 -0
- package/dist/parsers.js +115 -0
- package/dist/public-reads.d.ts +79 -0
- package/dist/public-reads.js +57 -0
- package/dist/reporting-catalogue.d.ts +264 -0
- package/dist/reporting-catalogue.js +5 -0
- package/dist/reporting-state.d.ts +46 -0
- package/dist/reporting-state.js +76 -0
- package/dist/response-lists.d.ts +16 -0
- package/dist/response-lists.generated.d.ts +7 -0
- package/dist/response-lists.generated.js +1927 -0
- package/dist/response-lists.js +70 -0
- package/dist/response-validation.d.ts +30 -0
- package/dist/response-validation.js +94 -0
- package/dist/runtime-readiness.d.ts +30 -0
- package/dist/runtime-readiness.js +150 -0
- package/dist/schema-registry.d.ts +45 -0
- package/dist/schema-registry.js +9 -0
- package/dist/secure-url.d.ts +4 -0
- package/dist/secure-url.js +23 -0
- package/dist/site-ai-owner.d.ts +34 -0
- package/dist/site-ai-owner.js +99 -0
- package/dist/site-monitor-reports.d.ts +15 -0
- package/dist/site-monitor-reports.js +87 -0
- package/dist/testing/fake-custd.d.ts +150 -0
- package/dist/testing/fake-custd.js +842 -0
- package/dist/testing/fake-results.d.ts +30 -0
- package/dist/testing/fake-results.js +293 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +3 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.js +10 -0
- package/package.json +57 -4
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
/** Re-runs the allocator conformance vectors and reports whether every one passed. */
|
|
137
|
+
async getDefinitionMathProof(companySlug, options) {
|
|
138
|
+
const proof = await this.request("GET", collectionPath("/time-plans/operations/definition-math", companySlug), undefined, options);
|
|
139
|
+
return {
|
|
140
|
+
...proof,
|
|
141
|
+
definitions: proof.definitions ?? [],
|
|
142
|
+
allocations: (proof.allocations ?? []).map((row) => ({ ...row, allocations: row.allocations ?? [] })),
|
|
143
|
+
adjustments: (proof.adjustments ?? []).map((row) => ({ ...row, allocations: row.allocations ?? [] })),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
getOperationalStatus(companySlug, options) {
|
|
147
|
+
return this.request("GET", collectionPath("/time-plans/operations/status", companySlug), undefined, options);
|
|
148
|
+
}
|
|
149
|
+
/** Re-queues failed outbox events for publication. */
|
|
150
|
+
replayOutbox(companySlug, body = {}, options) {
|
|
151
|
+
return this.request("POST", collectionPath("/time-plans/operations/outbox/replay", companySlug), body, options);
|
|
152
|
+
}
|
|
153
|
+
async getPublishedVersion(companySlug, planUuid, versionUuid, options) {
|
|
154
|
+
const path = resourcePath(`/time-plans/plans/${planUuid}/versions/${versionUuid}`, companySlug);
|
|
155
|
+
const version = await this.request("GET", path, undefined, options);
|
|
156
|
+
return { ...version, allocations: version.allocations ?? [] };
|
|
157
|
+
}
|
|
158
|
+
async listDurationObservations(companySlug, runUuid, options) {
|
|
159
|
+
const path = resourcePath(`/time-plans/runs/${runUuid}/duration-observations`, companySlug);
|
|
160
|
+
const list = await this.request("GET", path, undefined, options);
|
|
161
|
+
return { ...list, observations: list.observations ?? [] };
|
|
162
|
+
}
|
|
163
|
+
async listRunPredictions(companySlug, runUuid, limit, options) {
|
|
164
|
+
const path = resourcePath(`/time-plans/runs/${runUuid}/predictions`, companySlug, limit);
|
|
165
|
+
const list = await this.request("GET", path, undefined, options);
|
|
166
|
+
return { snapshots: (list.snapshots ?? []).map((row) => ({ ...row, warnings: row.warnings ?? [] })) };
|
|
167
|
+
}
|
|
168
|
+
async getCompletedDurationReport(companySlug, runUuid, options) {
|
|
169
|
+
const path = resourcePath(`/time-plans/runs/${runUuid}/report`, companySlug);
|
|
170
|
+
const report = await this.request("GET", path, undefined, options);
|
|
171
|
+
return {
|
|
172
|
+
...report,
|
|
173
|
+
blocks: report.blocks ?? [],
|
|
174
|
+
adjustments: report.adjustments ?? [],
|
|
175
|
+
annotations: report.annotations ?? [],
|
|
176
|
+
prediction_comparisons: report.prediction_comparisons ?? [],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/** Drops a run's read projection so it is rebuilt from the event stream. */
|
|
180
|
+
deleteRunProjection(companySlug, runUuid, options) {
|
|
181
|
+
const path = resourcePath(`/time-plans/runs/${runUuid}/projection-loss`, companySlug);
|
|
182
|
+
return this.request("POST", path, undefined, options);
|
|
183
|
+
}
|
|
184
|
+
/** Rebuilds a run's projection from its event stream. The run names its tenant. */
|
|
185
|
+
async repairRun(runUuid, options) {
|
|
186
|
+
const path = `/time-plans/runs/${encodeURIComponent(runUuid)}/repair`;
|
|
187
|
+
const repair = await this.request("POST", path, undefined, options);
|
|
188
|
+
return { ...repair, run: { ...repair.run, blocks: repair.run.blocks ?? [] } };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function collectionPath(path, companySlug, limit) {
|
|
192
|
+
const query = new URLSearchParams({ companySlug });
|
|
193
|
+
if (limit !== undefined)
|
|
194
|
+
query.set("limit", String(limit));
|
|
195
|
+
return `${path}?${query.toString()}`;
|
|
196
|
+
}
|
|
197
|
+
function resourcePath(path, companySlug, limit) {
|
|
198
|
+
const segments = path.split("/").map((segment, index) => (index === 0 ? segment : encodeURIComponent(segment)));
|
|
199
|
+
return collectionPath(segments.join("/"), companySlug, limit);
|
|
200
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin uncertainty models: named quantity models, their immutable versions and copies. Runs are
|
|
3
|
+
* read and started through the analytics API (`CustdClient.measurement.uncertaintyModels`).
|
|
4
|
+
*/
|
|
5
|
+
import type { AppModelCopyRequest, AppModelCreate, AppModelQuantity, AppModelVersion, AppUncertaintyModel } from "./app-models.js";
|
|
6
|
+
import type { RequestOptions } from "./index.js";
|
|
7
|
+
type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
|
|
8
|
+
/** Which models a list returns: those made in the admin console, by apps, or both. */
|
|
9
|
+
export type UncertaintyModelSource = "all" | "admin" | "app";
|
|
10
|
+
/** One model in a list, without its version. */
|
|
11
|
+
export type UncertaintyModelSummary = Omit<AppUncertaintyModel, "version" | "queuedRunFailure">;
|
|
12
|
+
export type UncertaintyModelList = {
|
|
13
|
+
models: UncertaintyModelSummary[];
|
|
14
|
+
};
|
|
15
|
+
/** A new immutable version: the whole quantity list. */
|
|
16
|
+
export type UncertaintyModelVersionCreate = {
|
|
17
|
+
quantities: AppModelQuantity[];
|
|
18
|
+
note?: string;
|
|
19
|
+
};
|
|
20
|
+
export type UncertaintyModelVersionSummary = {
|
|
21
|
+
versionUuid: string;
|
|
22
|
+
versionNumber: number;
|
|
23
|
+
note: string;
|
|
24
|
+
quantityCount: number;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
};
|
|
27
|
+
export type UncertaintyModelVersionList = {
|
|
28
|
+
versions: UncertaintyModelVersionSummary[];
|
|
29
|
+
};
|
|
30
|
+
export declare class UncertaintyModelAdminClient {
|
|
31
|
+
private readonly request;
|
|
32
|
+
constructor(request: AdminRequester);
|
|
33
|
+
list(source?: UncertaintyModelSource, companySlug?: string): Promise<UncertaintyModelList>;
|
|
34
|
+
get(modelUuid: string, companySlug?: string): Promise<AppUncertaintyModel>;
|
|
35
|
+
create(body: AppModelCreate, companySlug?: string): Promise<AppUncertaintyModel>;
|
|
36
|
+
copy(modelUuid: string, body?: AppModelCopyRequest, companySlug?: string): Promise<AppUncertaintyModel>;
|
|
37
|
+
delete(modelUuid: string, companySlug?: string): Promise<void>;
|
|
38
|
+
listVersions(modelUuid: string, companySlug?: string): Promise<UncertaintyModelVersionList>;
|
|
39
|
+
getVersion(modelUuid: string, versionNumber: number, companySlug?: string): Promise<AppModelVersion>;
|
|
40
|
+
createVersion(modelUuid: string, body: UncertaintyModelVersionCreate, companySlug?: string): Promise<AppModelVersion>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin uncertainty models: named quantity models, their immutable versions and copies. Runs are
|
|
3
|
+
* read and started through the analytics API (`CustdClient.measurement.uncertaintyModels`).
|
|
4
|
+
*/
|
|
5
|
+
export class UncertaintyModelAdminClient {
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
async list(source, companySlug) {
|
|
10
|
+
const list = await this.request("GET", modelPath("", companySlug, source));
|
|
11
|
+
return { models: list.models ?? [] };
|
|
12
|
+
}
|
|
13
|
+
async get(modelUuid, companySlug) {
|
|
14
|
+
return model(await this.request("GET", modelPath(`/${encodeURIComponent(modelUuid)}`, companySlug)));
|
|
15
|
+
}
|
|
16
|
+
async create(body, companySlug) {
|
|
17
|
+
return model(await this.request("POST", modelPath("", companySlug), body));
|
|
18
|
+
}
|
|
19
|
+
async copy(modelUuid, body = {}, companySlug) {
|
|
20
|
+
return model(await this.request("POST", modelPath(`/${encodeURIComponent(modelUuid)}/copy`, companySlug), body));
|
|
21
|
+
}
|
|
22
|
+
async delete(modelUuid, companySlug) {
|
|
23
|
+
await this.request("DELETE", modelPath(`/${encodeURIComponent(modelUuid)}`, companySlug));
|
|
24
|
+
}
|
|
25
|
+
async listVersions(modelUuid, companySlug) {
|
|
26
|
+
const path = modelPath(`/${encodeURIComponent(modelUuid)}/versions`, companySlug);
|
|
27
|
+
const list = await this.request("GET", path);
|
|
28
|
+
return { versions: list.versions ?? [] };
|
|
29
|
+
}
|
|
30
|
+
async getVersion(modelUuid, versionNumber, companySlug) {
|
|
31
|
+
const path = modelPath(`/${encodeURIComponent(modelUuid)}/versions/${versionNumber}`, companySlug);
|
|
32
|
+
return version(await this.request("GET", path));
|
|
33
|
+
}
|
|
34
|
+
async createVersion(modelUuid, body, companySlug) {
|
|
35
|
+
const path = modelPath(`/${encodeURIComponent(modelUuid)}/versions`, companySlug);
|
|
36
|
+
return version(await this.request("POST", path, body));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function version(wire) {
|
|
40
|
+
return { ...wire, quantities: wire.quantities ?? [] };
|
|
41
|
+
}
|
|
42
|
+
function model(wire) {
|
|
43
|
+
return wire.version ? { ...wire, version: version(wire.version) } : wire;
|
|
44
|
+
}
|
|
45
|
+
function modelPath(path, companySlug, source) {
|
|
46
|
+
const query = new URLSearchParams();
|
|
47
|
+
if (companySlug)
|
|
48
|
+
query.set("companySlug", companySlug);
|
|
49
|
+
if (source)
|
|
50
|
+
query.set("source", source);
|
|
51
|
+
const encoded = query.toString();
|
|
52
|
+
return `/uncertainty-models${path}${encoded ? `?${encoded}` : ""}`;
|
|
53
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { RequestOptions, StorageLimit, StorageMeasurementState } from "./index.js";
|
|
2
|
+
/** The row cap the service applies when a request omits a limit. */
|
|
3
|
+
export declare const USAGE_DEFAULT_LIMIT = 500;
|
|
4
|
+
/** The most rows the usage endpoint returns in one request. */
|
|
5
|
+
export declare const USAGE_MAX_LIMIT = 5000;
|
|
6
|
+
/** How final one usage row is. The server derives it and owns its meaning. */
|
|
7
|
+
export type UsageCompletenessState = "provisional" | "final" | "corrected" | "incomplete";
|
|
8
|
+
/** One attributed usage quantity for one half-open UTC window. */
|
|
9
|
+
export type UsageRow = {
|
|
10
|
+
accountCompanySlug: string;
|
|
11
|
+
dataSpaceCompanySlug: string;
|
|
12
|
+
meterSlug: string;
|
|
13
|
+
meterVersion: number;
|
|
14
|
+
unit: string;
|
|
15
|
+
windowStart: string;
|
|
16
|
+
windowEnd: string;
|
|
17
|
+
quantity: number;
|
|
18
|
+
sourceWatermark: number;
|
|
19
|
+
completenessState: UsageCompletenessState;
|
|
20
|
+
correctionGeneration: number;
|
|
21
|
+
calculationVersion: number;
|
|
22
|
+
};
|
|
23
|
+
/** A meter total across every row returned for the window. */
|
|
24
|
+
export type UsageTotal = {
|
|
25
|
+
accountCompanySlug: string;
|
|
26
|
+
dataSpaceCompanySlug: string;
|
|
27
|
+
meterSlug: string;
|
|
28
|
+
unit: string;
|
|
29
|
+
quantity: number;
|
|
30
|
+
};
|
|
31
|
+
/** Attributed usage for the token's own tenant. */
|
|
32
|
+
export type UsageReport = {
|
|
33
|
+
schemaVersion: string;
|
|
34
|
+
companySlug?: string;
|
|
35
|
+
start: string;
|
|
36
|
+
end: string;
|
|
37
|
+
rows: UsageRow[];
|
|
38
|
+
totals: UsageTotal[];
|
|
39
|
+
sourceWatermark: number;
|
|
40
|
+
containsProvisional: boolean;
|
|
41
|
+
containsIncomplete: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Narrows and bounds the usage window.
|
|
45
|
+
*
|
|
46
|
+
* Omitting `start` and `end` uses the service default, the trailing 30 days
|
|
47
|
+
* ending now; omitting `limit` uses {@link USAGE_DEFAULT_LIMIT}.
|
|
48
|
+
*/
|
|
49
|
+
export type UsageQuery = {
|
|
50
|
+
meterSlug?: string;
|
|
51
|
+
/** Inclusive RFC3339 UTC window start. */
|
|
52
|
+
start?: string;
|
|
53
|
+
/** Exclusive RFC3339 UTC window end. */
|
|
54
|
+
end?: string;
|
|
55
|
+
/** Maximum rows, between 1 and {@link USAGE_MAX_LIMIT}. */
|
|
56
|
+
limit?: number;
|
|
57
|
+
};
|
|
58
|
+
/** A usage window for the system-admin views, optionally narrowed to one company. */
|
|
59
|
+
export type UsageAdminQuery = UsageQuery & {
|
|
60
|
+
companySlug?: string;
|
|
61
|
+
};
|
|
62
|
+
/** Where a tenant's retained bytes are held. */
|
|
63
|
+
export type StorageUsageBreakdown = {
|
|
64
|
+
dbCoreLogicalBytes: number;
|
|
65
|
+
dbRawInlineLogicalBytes: number;
|
|
66
|
+
s3RawBytes: number;
|
|
67
|
+
s3RawObjectCount: number;
|
|
68
|
+
s3ParquetArchiveBytes: number;
|
|
69
|
+
s3ParquetArchiveObjectCount: number;
|
|
70
|
+
parquetArchiveAttribution: string;
|
|
71
|
+
};
|
|
72
|
+
/** One tenant's retained storage against its limit. */
|
|
73
|
+
export type TenantStorageUsage = {
|
|
74
|
+
companySlug: string;
|
|
75
|
+
companyName: string;
|
|
76
|
+
attributedStorageBytes: number;
|
|
77
|
+
retainedLogicalBytes: number;
|
|
78
|
+
retainedEventCount: number;
|
|
79
|
+
effectiveLimitBytes: number;
|
|
80
|
+
remainingBytes: number;
|
|
81
|
+
percentUsed: number;
|
|
82
|
+
warning: boolean;
|
|
83
|
+
warningState: string;
|
|
84
|
+
limit: StorageLimit;
|
|
85
|
+
measuredAt: string;
|
|
86
|
+
measurementState: StorageMeasurementState;
|
|
87
|
+
breakdown?: StorageUsageBreakdown;
|
|
88
|
+
};
|
|
89
|
+
/** Retained storage across every tenant. */
|
|
90
|
+
export type StorageUsageSummary = {
|
|
91
|
+
tenantCount: number;
|
|
92
|
+
attributedStorageBytes: number;
|
|
93
|
+
retainedLogicalBytes: number;
|
|
94
|
+
retainedEventCount: number;
|
|
95
|
+
effectiveLimitBytes: number;
|
|
96
|
+
remainingBytes: number;
|
|
97
|
+
percentUsed: number;
|
|
98
|
+
warning: boolean;
|
|
99
|
+
warningState: string;
|
|
100
|
+
measuredAt: string;
|
|
101
|
+
measurementState: StorageMeasurementState;
|
|
102
|
+
breakdown?: StorageUsageBreakdown;
|
|
103
|
+
tenants: TenantStorageUsage[];
|
|
104
|
+
};
|
|
105
|
+
type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
|
|
106
|
+
export declare class UsageAdminClient {
|
|
107
|
+
private readonly request;
|
|
108
|
+
constructor(request: AdminRequester);
|
|
109
|
+
/**
|
|
110
|
+
* Return the attributed usage for the token's own tenant. The tenant is
|
|
111
|
+
* derived from the credential, so the caller never supplies a company slug.
|
|
112
|
+
*/
|
|
113
|
+
get(query?: UsageQuery, options?: RequestOptions): Promise<UsageReport>;
|
|
114
|
+
/** System administrators: attributed usage across tenants, or one company's. */
|
|
115
|
+
listUsage(query?: UsageAdminQuery, options?: RequestOptions): Promise<UsageReport>;
|
|
116
|
+
/** System administrators: the same rows as `listUsage`, as a JSON billing export. */
|
|
117
|
+
exportUsage(query?: UsageAdminQuery, options?: RequestOptions): Promise<UsageReport>;
|
|
118
|
+
/** System administrators: retained storage for every tenant. */
|
|
119
|
+
listStorageUsage(options?: RequestOptions): Promise<StorageUsageSummary>;
|
|
120
|
+
/** The token's own tenant's retained storage. */
|
|
121
|
+
getRetainedUsage(options?: RequestOptions): Promise<TenantStorageUsage>;
|
|
122
|
+
private adminUsage;
|
|
123
|
+
}
|
|
124
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// UsageAdminClient reads attributed usage and retained storage. `get` reads the
|
|
2
|
+
// authenticated tenant's own usage through GET /api/v1/admin/usage/me; the
|
|
3
|
+
// tenant is derived from the credential. `listUsage` and `exportUsage` are the
|
|
4
|
+
// system-admin views that may name a company, and `listStorageUsage` /
|
|
5
|
+
// `getRetainedUsage` report retained storage against each tenant's limit.
|
|
6
|
+
//
|
|
7
|
+
// Usage is server-derived and includes provisional, final, and corrected state.
|
|
8
|
+
// `containsProvisional` and `containsIncomplete` are the server's own assessment
|
|
9
|
+
// of the returned rows, so a caller deciding whether a number is settled reads
|
|
10
|
+
// them rather than assuming every row is final.
|
|
11
|
+
import { optionalString, requireBoolean, requireInteger, requireObjectList, requireRecord, requireString, } from "./response-validation.js";
|
|
12
|
+
/** The row cap the service applies when a request omits a limit. */
|
|
13
|
+
export const USAGE_DEFAULT_LIMIT = 500;
|
|
14
|
+
/** The most rows the usage endpoint returns in one request. */
|
|
15
|
+
export const USAGE_MAX_LIMIT = 5000;
|
|
16
|
+
export class UsageAdminClient {
|
|
17
|
+
constructor(request) {
|
|
18
|
+
this.request = request;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Return the attributed usage for the token's own tenant. The tenant is
|
|
22
|
+
* derived from the credential, so the caller never supplies a company slug.
|
|
23
|
+
*/
|
|
24
|
+
get(query = {}, options) {
|
|
25
|
+
let params;
|
|
26
|
+
try {
|
|
27
|
+
params = usageQueryParams(query).toString();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return Promise.reject(error);
|
|
31
|
+
}
|
|
32
|
+
return this.request("GET", `/usage/me${params.length > 0 ? `?${params}` : ""}`, undefined, options).then(assertUsageReport);
|
|
33
|
+
}
|
|
34
|
+
/** System administrators: attributed usage across tenants, or one company's. */
|
|
35
|
+
listUsage(query = {}, options) {
|
|
36
|
+
return this.adminUsage("/usage", query, options);
|
|
37
|
+
}
|
|
38
|
+
/** System administrators: the same rows as `listUsage`, as a JSON billing export. */
|
|
39
|
+
exportUsage(query = {}, options) {
|
|
40
|
+
return this.adminUsage("/usage/export", query, options, { format: "json" });
|
|
41
|
+
}
|
|
42
|
+
/** System administrators: retained storage for every tenant. */
|
|
43
|
+
async listStorageUsage(options) {
|
|
44
|
+
const summary = await this.request("GET", "/storage-usage", undefined, options);
|
|
45
|
+
return { ...summary, tenants: summary.tenants ?? [] };
|
|
46
|
+
}
|
|
47
|
+
/** The token's own tenant's retained storage. */
|
|
48
|
+
getRetainedUsage(options) {
|
|
49
|
+
return this.request("GET", "/storage-usage/me", undefined, options);
|
|
50
|
+
}
|
|
51
|
+
adminUsage(path, query, options, fixed = {}) {
|
|
52
|
+
const { companySlug, ...window } = query;
|
|
53
|
+
let params;
|
|
54
|
+
try {
|
|
55
|
+
params = usageQueryParams(window);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return Promise.reject(error);
|
|
59
|
+
}
|
|
60
|
+
if (companySlug)
|
|
61
|
+
params.set("companySlug", companySlug);
|
|
62
|
+
for (const [name, value] of Object.entries(fixed))
|
|
63
|
+
params.set(name, value);
|
|
64
|
+
const encoded = params.toString();
|
|
65
|
+
return this.request("GET", encoded ? `${path}?${encoded}` : path, undefined, options).then(assertUsageReport);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// assertUsageReport validates the named response DTO. The service emits every
|
|
69
|
+
// required field, so a truncated or wrongly shaped body fails here instead of
|
|
70
|
+
// surfacing as a zero-valued report.
|
|
71
|
+
function assertUsageReport(value) {
|
|
72
|
+
const context = "usage response";
|
|
73
|
+
const report = requireRecord(value, context);
|
|
74
|
+
requireString(report, "schemaVersion", context);
|
|
75
|
+
requireString(report, "start", context);
|
|
76
|
+
requireString(report, "end", context);
|
|
77
|
+
requireInteger(report, "sourceWatermark", context);
|
|
78
|
+
requireBoolean(report, "containsProvisional", context);
|
|
79
|
+
requireBoolean(report, "containsIncomplete", context);
|
|
80
|
+
optionalString(report, "companySlug", context);
|
|
81
|
+
for (const [index, row] of requireObjectList(report, "rows", context).entries()) {
|
|
82
|
+
const rowContext = `${context} rows[${index}]`;
|
|
83
|
+
requireString(row, "accountCompanySlug", rowContext);
|
|
84
|
+
requireString(row, "dataSpaceCompanySlug", rowContext);
|
|
85
|
+
requireString(row, "meterSlug", rowContext);
|
|
86
|
+
requireInteger(row, "meterVersion", rowContext);
|
|
87
|
+
requireString(row, "unit", rowContext);
|
|
88
|
+
requireString(row, "windowStart", rowContext);
|
|
89
|
+
requireString(row, "windowEnd", rowContext);
|
|
90
|
+
requireInteger(row, "quantity", rowContext);
|
|
91
|
+
requireInteger(row, "sourceWatermark", rowContext);
|
|
92
|
+
requireString(row, "completenessState", rowContext);
|
|
93
|
+
requireInteger(row, "correctionGeneration", rowContext);
|
|
94
|
+
requireInteger(row, "calculationVersion", rowContext);
|
|
95
|
+
}
|
|
96
|
+
for (const [index, total] of requireObjectList(report, "totals", context).entries()) {
|
|
97
|
+
const totalContext = `${context} totals[${index}]`;
|
|
98
|
+
requireString(total, "accountCompanySlug", totalContext);
|
|
99
|
+
requireString(total, "dataSpaceCompanySlug", totalContext);
|
|
100
|
+
requireString(total, "meterSlug", totalContext);
|
|
101
|
+
requireString(total, "unit", totalContext);
|
|
102
|
+
requireInteger(total, "quantity", totalContext);
|
|
103
|
+
}
|
|
104
|
+
return report;
|
|
105
|
+
}
|
|
106
|
+
// RFC3339_PATTERN is the documented usage-window grammar: a full timestamp with
|
|
107
|
+
// the T separator, an explicit Z or numeric offset, and captured date and clock
|
|
108
|
+
// components. It rejects values Date.parse accepts, such as a date-only string
|
|
109
|
+
// or a space-separated timestamp.
|
|
110
|
+
const RFC3339_PATTERN = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
111
|
+
function parseInstant(value, field) {
|
|
112
|
+
const match = RFC3339_PATTERN.exec(value);
|
|
113
|
+
if (match === null) {
|
|
114
|
+
throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
|
|
115
|
+
}
|
|
116
|
+
// Date.parse normalizes values that are not valid RFC3339 clock times: hour 24
|
|
117
|
+
// rolls to the next day and second 60 rolls to the next minute. Bound the
|
|
118
|
+
// clock components before trusting the parse, exactly as the calendar date is
|
|
119
|
+
// checked below.
|
|
120
|
+
const hour = Number(match[4]);
|
|
121
|
+
const minute = Number(match[5]);
|
|
122
|
+
const second = Number(match[6]);
|
|
123
|
+
if (hour > 23 || minute > 59 || second > 59) {
|
|
124
|
+
throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
|
|
125
|
+
}
|
|
126
|
+
// Date.parse normalizes an impossible day such as February 30, so verify the
|
|
127
|
+
// calendar date itself before trusting the parsed instant.
|
|
128
|
+
const year = Number(match[1]);
|
|
129
|
+
const month = Number(match[2]);
|
|
130
|
+
const day = Number(match[3]);
|
|
131
|
+
const utc = new Date(Date.UTC(year, month - 1, day));
|
|
132
|
+
if (utc.getUTCFullYear() !== year || utc.getUTCMonth() !== month - 1 || utc.getUTCDate() !== day) {
|
|
133
|
+
throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
|
|
134
|
+
}
|
|
135
|
+
const parsed = Date.parse(value);
|
|
136
|
+
if (Number.isNaN(parsed)) {
|
|
137
|
+
throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
|
|
138
|
+
}
|
|
139
|
+
return parsed;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Build the query string and reject locally what the service would reject
|
|
143
|
+
* anyway, so an invalid window never costs a round trip.
|
|
144
|
+
*/
|
|
145
|
+
function usageQueryParams(query) {
|
|
146
|
+
if (query.limit !== undefined &&
|
|
147
|
+
(!Number.isInteger(query.limit) || query.limit < 1 || query.limit > USAGE_MAX_LIMIT)) {
|
|
148
|
+
throw new RangeError(`custd: usage limit must be between 1 and ${USAGE_MAX_LIMIT}`);
|
|
149
|
+
}
|
|
150
|
+
const start = query.start === undefined ? undefined : parseInstant(query.start, "start");
|
|
151
|
+
const end = query.end === undefined ? undefined : parseInstant(query.end, "end");
|
|
152
|
+
if (start !== undefined && end !== undefined && start >= end) {
|
|
153
|
+
throw new RangeError("custd: usage start must be before end");
|
|
154
|
+
}
|
|
155
|
+
const params = new URLSearchParams();
|
|
156
|
+
if (query.end !== undefined) {
|
|
157
|
+
params.set("end", query.end);
|
|
158
|
+
}
|
|
159
|
+
if (query.limit !== undefined) {
|
|
160
|
+
params.set("limit", String(query.limit));
|
|
161
|
+
}
|
|
162
|
+
if (query.meterSlug !== undefined) {
|
|
163
|
+
params.set("meter", query.meterSlug);
|
|
164
|
+
}
|
|
165
|
+
if (query.start !== undefined) {
|
|
166
|
+
params.set("start", query.start);
|
|
167
|
+
}
|
|
168
|
+
return params;
|
|
169
|
+
}
|