@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,167 @@
|
|
|
1
|
+
import type { AnalyticsActiveNow, AnalyticsDashboardSummary, AnalyticsEventCount, AnalyticsEventCountQuery } from "./analytics-reads.js";
|
|
2
|
+
import type { RequestOptions } from "./index.js";
|
|
3
|
+
/** Sources the server may answer a query from. */
|
|
4
|
+
export type AnalyticsQuerySource = "auto" | "postgres" | "duckdb" | "rollup" | "materialized";
|
|
5
|
+
/**
|
|
6
|
+
* Sources the range query accepts. The range API accepts only omitted, empty,
|
|
7
|
+
* `auto`, or `duckdb`; the single-day query's retired `postgres`, `rollup`, and
|
|
8
|
+
* `materialized` sources are not part of the range contract. An empty string is
|
|
9
|
+
* accepted as the default and normalized to an omitted `source`.
|
|
10
|
+
*/
|
|
11
|
+
export type AnalyticsRangeQuerySource = "" | "auto" | "duckdb";
|
|
12
|
+
/**
|
|
13
|
+
* One exact tenant-vocabulary key/value filter.
|
|
14
|
+
*
|
|
15
|
+
* The server accepts at most ANALYTICS_MAX_LABEL_FILTERS of these; more is a request
|
|
16
|
+
* error, so the client rejects the overflow before it leaves the process.
|
|
17
|
+
*/
|
|
18
|
+
export type AnalyticsLabelFilter = {
|
|
19
|
+
key: string;
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
export type AnalyticsEventQueryRequest = {
|
|
23
|
+
/** UTC day to query, formatted YYYY-MM-DD. The server requires this. */
|
|
24
|
+
date: string;
|
|
25
|
+
/** Exact event-type slug to match. */
|
|
26
|
+
eventType?: string;
|
|
27
|
+
/** Maximum rows to return. The server clamps this and reports the applied count. */
|
|
28
|
+
limit?: number;
|
|
29
|
+
source?: AnalyticsQuerySource;
|
|
30
|
+
labelFilters?: AnalyticsLabelFilter[];
|
|
31
|
+
/**
|
|
32
|
+
* Optional promoted log-dimension filters. Each is an exact equality match
|
|
33
|
+
* against the matching typed column (max 256 bytes server-side); an empty
|
|
34
|
+
* value is omitted so an unset filter never narrows the query.
|
|
35
|
+
*/
|
|
36
|
+
severity?: string;
|
|
37
|
+
service?: string;
|
|
38
|
+
subClient?: string;
|
|
39
|
+
resource?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* One tenant event.
|
|
43
|
+
*
|
|
44
|
+
* The wire shape is an extensible column bag, but the canonical event payload is always
|
|
45
|
+
* a JSON object. Custd normalises its internal Parquet representation at the API boundary
|
|
46
|
+
* so consumers never need to parse an escaped JSON string.
|
|
47
|
+
*/
|
|
48
|
+
export type AnalyticsEventRow = {
|
|
49
|
+
payload?: Record<string, unknown>;
|
|
50
|
+
[column: string]: unknown;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* How one source contributed to a query.
|
|
54
|
+
*
|
|
55
|
+
* `complete` and `fresh` are the server's own assessment of whether that source answered
|
|
56
|
+
* the whole request and whether its data sat inside the freshness window. They are the
|
|
57
|
+
* authority for how far a result may be trusted, so they are surfaced unchanged; the
|
|
58
|
+
* client must not substitute its own confidence heuristic.
|
|
59
|
+
*/
|
|
60
|
+
export type AnalyticsEventSourceSummary = {
|
|
61
|
+
name: AnalyticsQuerySource;
|
|
62
|
+
count: number;
|
|
63
|
+
parquetUriCount?: number;
|
|
64
|
+
complete: boolean;
|
|
65
|
+
fresh: boolean;
|
|
66
|
+
queryDurationMs: number;
|
|
67
|
+
freshnessLagMs: number;
|
|
68
|
+
message?: string;
|
|
69
|
+
};
|
|
70
|
+
/** Server-measured lag and coverage for a query. */
|
|
71
|
+
export type AnalyticsEventTiming = {
|
|
72
|
+
eventLagP50Ms: number;
|
|
73
|
+
eventLagP95Ms: number;
|
|
74
|
+
eventLagMaxMs: number;
|
|
75
|
+
queryDurationMs: number;
|
|
76
|
+
oldestEventTimestamp?: string;
|
|
77
|
+
newestEventTimestamp?: string;
|
|
78
|
+
snapshotAgeMs: number;
|
|
79
|
+
};
|
|
80
|
+
export type AnalyticsEventQueryResponse = {
|
|
81
|
+
results: AnalyticsEventRow[];
|
|
82
|
+
count: number;
|
|
83
|
+
sources: AnalyticsEventSourceSummary[];
|
|
84
|
+
timing: AnalyticsEventTiming;
|
|
85
|
+
};
|
|
86
|
+
/** The longest inclusive range the service accepts, in days. */
|
|
87
|
+
export declare const ANALYTICS_MAX_RANGE_DAYS = 120;
|
|
88
|
+
/** The only bucket granularity the service supports today. */
|
|
89
|
+
export declare const ANALYTICS_RANGE_GROUP_BY = "day";
|
|
90
|
+
export type AnalyticsEventRangeQueryRequest = {
|
|
91
|
+
/** Inclusive range start, formatted YYYY-MM-DD. The server requires this. */
|
|
92
|
+
from: string;
|
|
93
|
+
/** Inclusive range end, formatted YYYY-MM-DD. The server requires this. */
|
|
94
|
+
to: string;
|
|
95
|
+
/** Exact event-type slug to match. */
|
|
96
|
+
eventType?: string;
|
|
97
|
+
/** Maximum rows across the whole range. The server clamps this and reports the applied count. */
|
|
98
|
+
limit?: number;
|
|
99
|
+
/** Query source. Omitted, `auto`, or `duckdb` only. */
|
|
100
|
+
source?: AnalyticsRangeQuerySource;
|
|
101
|
+
/** Bucket granularity. Omit, or set to {@link ANALYTICS_RANGE_GROUP_BY}. */
|
|
102
|
+
groupBy?: typeof ANALYTICS_RANGE_GROUP_BY;
|
|
103
|
+
labelFilters?: AnalyticsLabelFilter[];
|
|
104
|
+
/**
|
|
105
|
+
* Optional promoted log-dimension filters, shared with the single-day query.
|
|
106
|
+
* Each filters exactly like the day query it summarizes; an empty value is
|
|
107
|
+
* omitted from the wire.
|
|
108
|
+
*/
|
|
109
|
+
severity?: string;
|
|
110
|
+
service?: string;
|
|
111
|
+
subClient?: string;
|
|
112
|
+
resource?: string;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* One day's coverage inside a range query.
|
|
116
|
+
*
|
|
117
|
+
* `complete` is the server's own assessment of whether that day's source answered the
|
|
118
|
+
* whole request, so it is surfaced unchanged; the client must not substitute its own
|
|
119
|
+
* confidence heuristic.
|
|
120
|
+
*/
|
|
121
|
+
export type AnalyticsEventRangeBucket = {
|
|
122
|
+
date: string;
|
|
123
|
+
count: number;
|
|
124
|
+
source: AnalyticsQuerySource;
|
|
125
|
+
complete: boolean;
|
|
126
|
+
queryDurationMs: number;
|
|
127
|
+
parquetUriCount?: number;
|
|
128
|
+
message?: string;
|
|
129
|
+
};
|
|
130
|
+
export type AnalyticsEventRangeQueryResponse = {
|
|
131
|
+
rows: AnalyticsEventRow[];
|
|
132
|
+
count: number;
|
|
133
|
+
buckets: AnalyticsEventRangeBucket[];
|
|
134
|
+
sources: AnalyticsEventSourceSummary[];
|
|
135
|
+
timing: AnalyticsEventTiming;
|
|
136
|
+
};
|
|
137
|
+
/** The server accepts at most this many label filters on one query. */
|
|
138
|
+
export declare const ANALYTICS_MAX_LABEL_FILTERS = 4;
|
|
139
|
+
type AnalyticsRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
|
|
140
|
+
export declare class AnalyticsEventClient {
|
|
141
|
+
private readonly request;
|
|
142
|
+
constructor(request: AnalyticsRequester);
|
|
143
|
+
/**
|
|
144
|
+
* Query this tenant's own events.
|
|
145
|
+
*
|
|
146
|
+
* Only the documented public fields are serialised. The service also accepts an
|
|
147
|
+
* internal `anonymousId` exact-subject predicate and a `countOnly` flag, but both are
|
|
148
|
+
* deliberately absent from its public JSON contract, so this client must not transmit
|
|
149
|
+
* them even when a caller passes extra properties.
|
|
150
|
+
*/
|
|
151
|
+
query(request: AnalyticsEventQueryRequest, options?: RequestOptions): Promise<AnalyticsEventQueryResponse>;
|
|
152
|
+
/**
|
|
153
|
+
* Query this tenant's own events across an inclusive date range.
|
|
154
|
+
*
|
|
155
|
+
* Only the documented public fields are serialised. As with {@link query}, the internal
|
|
156
|
+
* `anonymousId` predicate and `countOnly` flag are absent from the service's public JSON
|
|
157
|
+
* contract and cannot be transmitted by a caller passing extra properties.
|
|
158
|
+
*/
|
|
159
|
+
queryRange(request: AnalyticsEventRangeQueryRequest, options?: RequestOptions): Promise<AnalyticsEventRangeQueryResponse>;
|
|
160
|
+
/** Counts the sessions active on one site now. A 503 means realtime counts are unavailable: hide them. */
|
|
161
|
+
activeNow(siteUuid: string, options?: RequestOptions): Promise<AnalyticsActiveNow>;
|
|
162
|
+
/** Returns the tenant's stored-event overview. */
|
|
163
|
+
dashboardSummary(options?: RequestOptions): Promise<AnalyticsDashboardSummary>;
|
|
164
|
+
/** Counts the tenant's events on one UTC day, optionally of one event type. */
|
|
165
|
+
eventCount(query: AnalyticsEventCountQuery, options?: RequestOptions): Promise<AnalyticsEventCount>;
|
|
166
|
+
}
|
|
167
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
import { optionalInteger, optionalRecord, optionalString, requireBoolean, requireInteger, requireObjectList, requireRecord, requireString, } from "./response-validation.js";
|
|
7
|
+
const ANALYTICS_RANGE_QUERY_SOURCES = ["", "auto", "duckdb"];
|
|
8
|
+
/** The longest inclusive range the service accepts, in days. */
|
|
9
|
+
export const ANALYTICS_MAX_RANGE_DAYS = 120;
|
|
10
|
+
/** The only bucket granularity the service supports today. */
|
|
11
|
+
export const ANALYTICS_RANGE_GROUP_BY = "day";
|
|
12
|
+
/** The server accepts at most this many label filters on one query. */
|
|
13
|
+
export const ANALYTICS_MAX_LABEL_FILTERS = 4;
|
|
14
|
+
export class AnalyticsEventClient {
|
|
15
|
+
constructor(request) {
|
|
16
|
+
this.request = request;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Query this tenant's own events.
|
|
20
|
+
*
|
|
21
|
+
* Only the documented public fields are serialised. The service also accepts an
|
|
22
|
+
* internal `anonymousId` exact-subject predicate and a `countOnly` flag, but both are
|
|
23
|
+
* deliberately absent from its public JSON contract, so this client must not transmit
|
|
24
|
+
* them even when a caller passes extra properties.
|
|
25
|
+
*/
|
|
26
|
+
query(request, options) {
|
|
27
|
+
const labelFilters = request.labelFilters ?? [];
|
|
28
|
+
if (labelFilters.length > ANALYTICS_MAX_LABEL_FILTERS) {
|
|
29
|
+
return Promise.reject(new RangeError(`custd: analytics query accepts at most ${ANALYTICS_MAX_LABEL_FILTERS} label filters, received ${labelFilters.length}`));
|
|
30
|
+
}
|
|
31
|
+
const body = { date: request.date };
|
|
32
|
+
if (request.eventType !== undefined) {
|
|
33
|
+
body.eventType = request.eventType;
|
|
34
|
+
}
|
|
35
|
+
if (request.limit !== undefined) {
|
|
36
|
+
body.limit = request.limit;
|
|
37
|
+
}
|
|
38
|
+
if (request.source !== undefined) {
|
|
39
|
+
body.source = request.source;
|
|
40
|
+
}
|
|
41
|
+
if (labelFilters.length > 0) {
|
|
42
|
+
body.labelFilters = labelFilters;
|
|
43
|
+
}
|
|
44
|
+
appendLogDimensionFilters(body, request);
|
|
45
|
+
return this.request("POST", "/analytics/query", body, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Query this tenant's own events across an inclusive date range.
|
|
49
|
+
*
|
|
50
|
+
* Only the documented public fields are serialised. As with {@link query}, the internal
|
|
51
|
+
* `anonymousId` predicate and `countOnly` flag are absent from the service's public JSON
|
|
52
|
+
* contract and cannot be transmitted by a caller passing extra properties.
|
|
53
|
+
*/
|
|
54
|
+
async queryRange(request, options) {
|
|
55
|
+
const labelFilters = request.labelFilters ?? [];
|
|
56
|
+
if (labelFilters.length > ANALYTICS_MAX_LABEL_FILTERS) {
|
|
57
|
+
throw new RangeError(`custd: analytics range query accepts at most ${ANALYTICS_MAX_LABEL_FILTERS} label filters, received ${labelFilters.length}`);
|
|
58
|
+
}
|
|
59
|
+
if (request.groupBy !== undefined && request.groupBy !== ANALYTICS_RANGE_GROUP_BY) {
|
|
60
|
+
throw new RangeError(`custd: analytics range query groupBy must be "${ANALYTICS_RANGE_GROUP_BY}"`);
|
|
61
|
+
}
|
|
62
|
+
if (request.source !== undefined && !ANALYTICS_RANGE_QUERY_SOURCES.includes(request.source)) {
|
|
63
|
+
throw new RangeError(`custd: analytics range query source must be one of ${ANALYTICS_RANGE_QUERY_SOURCES.filter((value) => value !== "").join(", ")}`);
|
|
64
|
+
}
|
|
65
|
+
assertRangeWithinLimit(request.from, request.to);
|
|
66
|
+
const body = { from: request.from, to: request.to };
|
|
67
|
+
if (request.eventType !== undefined) {
|
|
68
|
+
body.eventType = request.eventType;
|
|
69
|
+
}
|
|
70
|
+
if (request.limit !== undefined) {
|
|
71
|
+
body.limit = request.limit;
|
|
72
|
+
}
|
|
73
|
+
if (request.source !== undefined && request.source !== "") {
|
|
74
|
+
body.source = request.source;
|
|
75
|
+
}
|
|
76
|
+
if (request.groupBy !== undefined) {
|
|
77
|
+
body.groupBy = request.groupBy;
|
|
78
|
+
}
|
|
79
|
+
if (labelFilters.length > 0) {
|
|
80
|
+
body.labelFilters = labelFilters;
|
|
81
|
+
}
|
|
82
|
+
appendLogDimensionFilters(body, request);
|
|
83
|
+
const value = await this.request("POST", "/analytics/query-range", body, options);
|
|
84
|
+
return assertRangeQueryResponse(value);
|
|
85
|
+
}
|
|
86
|
+
/** Counts the sessions active on one site now. A 503 means realtime counts are unavailable: hide them. */
|
|
87
|
+
activeNow(siteUuid, options) {
|
|
88
|
+
if (siteUuid.trim() === "")
|
|
89
|
+
return Promise.reject(new Error("custd: active-now requires a site"));
|
|
90
|
+
return this.request("GET", `/analytics/active-now?${new URLSearchParams({ site: siteUuid })}`, undefined, options);
|
|
91
|
+
}
|
|
92
|
+
/** Returns the tenant's stored-event overview. */
|
|
93
|
+
async dashboardSummary(options) {
|
|
94
|
+
const wire = await this.request("GET", "/analytics/dashboard-summary", undefined, options);
|
|
95
|
+
return decodeAnalyticsDashboardSummary(wire);
|
|
96
|
+
}
|
|
97
|
+
/** Counts the tenant's events on one UTC day, optionally of one event type. */
|
|
98
|
+
eventCount(query, options) {
|
|
99
|
+
if (query.date.trim() === "")
|
|
100
|
+
return Promise.reject(new Error("custd: event count requires a date"));
|
|
101
|
+
const params = new URLSearchParams({ date: query.date });
|
|
102
|
+
if (query.eventType)
|
|
103
|
+
params.set("eventType", query.eventType);
|
|
104
|
+
return this.request("GET", `/telemetry/event-count?${params}`, undefined, options);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// appendLogDimensionFilters copies the promoted log-dimension filters onto the
|
|
108
|
+
// body, omitting each unset or empty one so it never narrows the query. It is
|
|
109
|
+
// shared by the day and range queries, which carry the same filter set.
|
|
110
|
+
function appendLogDimensionFilters(body, request) {
|
|
111
|
+
if (request.severity) {
|
|
112
|
+
body.severity = request.severity;
|
|
113
|
+
}
|
|
114
|
+
if (request.service) {
|
|
115
|
+
body.service = request.service;
|
|
116
|
+
}
|
|
117
|
+
if (request.subClient) {
|
|
118
|
+
body.subClient = request.subClient;
|
|
119
|
+
}
|
|
120
|
+
if (request.resource) {
|
|
121
|
+
body.resource = request.resource;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Reject locally what the service would reject anyway, so it never costs a round trip. */
|
|
125
|
+
function assertRangeWithinLimit(from, to) {
|
|
126
|
+
const fromMs = parseUTCDay(from, "from");
|
|
127
|
+
const toMs = parseUTCDay(to, "to");
|
|
128
|
+
if (toMs < fromMs) {
|
|
129
|
+
throw new RangeError("custd: analytics range query to must not be before from");
|
|
130
|
+
}
|
|
131
|
+
const days = Math.round((toMs - fromMs) / 86400000) + 1;
|
|
132
|
+
if (days > ANALYTICS_MAX_RANGE_DAYS) {
|
|
133
|
+
throw new RangeError(`custd: analytics range query spans ${days} days, the maximum is ${ANALYTICS_MAX_RANGE_DAYS}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function parseUTCDay(value, field) {
|
|
137
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
138
|
+
if (match === null) {
|
|
139
|
+
throw new RangeError(`custd: analytics range query ${field} must be YYYY-MM-DD`);
|
|
140
|
+
}
|
|
141
|
+
const ms = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
|
|
142
|
+
if (new Date(ms).toISOString().slice(0, 10) !== value) {
|
|
143
|
+
throw new RangeError(`custd: analytics range query ${field} must be YYYY-MM-DD`);
|
|
144
|
+
}
|
|
145
|
+
return ms;
|
|
146
|
+
}
|
|
147
|
+
// assertRangeQueryResponse validates the named range response DTO. The service
|
|
148
|
+
// emits every required field, so a truncated or wrongly shaped body fails here
|
|
149
|
+
// instead of surfacing as a zero-valued result.
|
|
150
|
+
function assertRangeQueryResponse(value) {
|
|
151
|
+
const context = "analytics range response";
|
|
152
|
+
const response = requireRecord(value, context);
|
|
153
|
+
for (const [index, row] of requireObjectList(response, "rows", context).entries()) {
|
|
154
|
+
// A row is an open column bag, but `payload` is a declared object field, so
|
|
155
|
+
// a present null or array fails instead of being passed through.
|
|
156
|
+
optionalRecord(row, "payload", `${context} rows[${index}]`);
|
|
157
|
+
}
|
|
158
|
+
requireInteger(response, "count", context);
|
|
159
|
+
for (const [index, bucket] of requireObjectList(response, "buckets", context).entries()) {
|
|
160
|
+
const bucketContext = `${context} buckets[${index}]`;
|
|
161
|
+
requireString(bucket, "date", bucketContext);
|
|
162
|
+
requireInteger(bucket, "count", bucketContext);
|
|
163
|
+
requireString(bucket, "source", bucketContext);
|
|
164
|
+
requireBoolean(bucket, "complete", bucketContext);
|
|
165
|
+
requireInteger(bucket, "queryDurationMs", bucketContext);
|
|
166
|
+
optionalInteger(bucket, "parquetUriCount", bucketContext);
|
|
167
|
+
optionalString(bucket, "message", bucketContext);
|
|
168
|
+
}
|
|
169
|
+
for (const [index, source] of requireObjectList(response, "sources", context).entries()) {
|
|
170
|
+
const sourceContext = `${context} sources[${index}]`;
|
|
171
|
+
requireString(source, "name", sourceContext);
|
|
172
|
+
requireInteger(source, "count", sourceContext);
|
|
173
|
+
requireBoolean(source, "complete", sourceContext);
|
|
174
|
+
requireBoolean(source, "fresh", sourceContext);
|
|
175
|
+
requireInteger(source, "queryDurationMs", sourceContext);
|
|
176
|
+
requireInteger(source, "freshnessLagMs", sourceContext);
|
|
177
|
+
optionalInteger(source, "parquetUriCount", sourceContext);
|
|
178
|
+
optionalString(source, "message", sourceContext);
|
|
179
|
+
}
|
|
180
|
+
const timing = requireRecord(response.timing, `${context} timing`);
|
|
181
|
+
requireInteger(timing, "eventLagP50Ms", `${context} timing`);
|
|
182
|
+
requireInteger(timing, "eventLagP95Ms", `${context} timing`);
|
|
183
|
+
requireInteger(timing, "eventLagMaxMs", `${context} timing`);
|
|
184
|
+
requireInteger(timing, "queryDurationMs", `${context} timing`);
|
|
185
|
+
requireInteger(timing, "snapshotAgeMs", `${context} timing`);
|
|
186
|
+
optionalString(timing, "oldestEventTimestamp", `${context} timing`);
|
|
187
|
+
optionalString(timing, "newestEventTimestamp", `${context} timing`);
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
/** Decodes a dashboard summary, turning JSON null lists into empty ones. */
|
|
191
|
+
function decodeAnalyticsDashboardSummary(wire) {
|
|
192
|
+
return {
|
|
193
|
+
...wire,
|
|
194
|
+
loadedDays: wire.loadedDays ?? [],
|
|
195
|
+
dogfood: { sources: wire.dogfood?.sources ?? [], metrics: wire.dogfood?.metrics ?? [] },
|
|
196
|
+
};
|
|
197
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant analytics reads beside the event query: the realtime active-visitor count, the
|
|
3
|
+
* stored-event dashboard summary and the per-day event count. The credential names the tenant.
|
|
4
|
+
*/
|
|
5
|
+
/** How many sessions were active on one site within the window. */
|
|
6
|
+
export type AnalyticsActiveNow = {
|
|
7
|
+
activeNow: number;
|
|
8
|
+
windowSeconds: number;
|
|
9
|
+
};
|
|
10
|
+
export type AnalyticsDashboardTenant = {
|
|
11
|
+
companySlug: string;
|
|
12
|
+
};
|
|
13
|
+
/** The tenant's stored events. The timestamps are null while nothing is stored. */
|
|
14
|
+
export type AnalyticsDashboardEvents = {
|
|
15
|
+
total: number;
|
|
16
|
+
oldestEventAt: string | null;
|
|
17
|
+
latestEventAt: string | null;
|
|
18
|
+
latestReceivedAt: string | null;
|
|
19
|
+
loadedDayCount: number;
|
|
20
|
+
};
|
|
21
|
+
/** The span of days with stored events. */
|
|
22
|
+
export type AnalyticsDashboardCoverage = {
|
|
23
|
+
firstDay: string;
|
|
24
|
+
lastDay: string;
|
|
25
|
+
loadedDayCount: number;
|
|
26
|
+
};
|
|
27
|
+
/** One stored day and its archive state. */
|
|
28
|
+
export type AnalyticsDashboardLoadedDay = {
|
|
29
|
+
date: string;
|
|
30
|
+
eventCount: number;
|
|
31
|
+
archiveStatus: string;
|
|
32
|
+
archiveVerifiedAt: string | null;
|
|
33
|
+
queryHref: string;
|
|
34
|
+
};
|
|
35
|
+
/** One internal source's delivery health. */
|
|
36
|
+
export type AnalyticsDashboardDogfoodSource = {
|
|
37
|
+
sourceSystem: string;
|
|
38
|
+
sourceCompany: string;
|
|
39
|
+
environment: string;
|
|
40
|
+
eventCount: number;
|
|
41
|
+
latestEventAt: string | null;
|
|
42
|
+
latestEventType: string;
|
|
43
|
+
failureCount: number;
|
|
44
|
+
rejectionCount: number;
|
|
45
|
+
status: string;
|
|
46
|
+
};
|
|
47
|
+
/** One internal operational metric. */
|
|
48
|
+
export type AnalyticsDashboardDogfoodMetric = {
|
|
49
|
+
sourceSystem: string;
|
|
50
|
+
service: string;
|
|
51
|
+
metricName: string;
|
|
52
|
+
metricKind: string;
|
|
53
|
+
value: number;
|
|
54
|
+
unit: string;
|
|
55
|
+
windowStart: string | null;
|
|
56
|
+
windowEnd: string | null;
|
|
57
|
+
route?: string;
|
|
58
|
+
status?: string;
|
|
59
|
+
};
|
|
60
|
+
/** The internal dogfood view; empty for client tenants. */
|
|
61
|
+
export type AnalyticsDashboardDogfood = {
|
|
62
|
+
sources: AnalyticsDashboardDogfoodSource[];
|
|
63
|
+
metrics: AnalyticsDashboardDogfoodMetric[];
|
|
64
|
+
};
|
|
65
|
+
/** The tenant's stored-event overview. */
|
|
66
|
+
export type AnalyticsDashboardSummary = {
|
|
67
|
+
tenant: AnalyticsDashboardTenant;
|
|
68
|
+
events: AnalyticsDashboardEvents;
|
|
69
|
+
coverage: AnalyticsDashboardCoverage;
|
|
70
|
+
loadedDays: AnalyticsDashboardLoadedDay[];
|
|
71
|
+
dogfood: AnalyticsDashboardDogfood;
|
|
72
|
+
generatedAt: string;
|
|
73
|
+
};
|
|
74
|
+
/** Counts the tenant's events on one UTC day (YYYY-MM-DD), optionally of one event type. */
|
|
75
|
+
export type AnalyticsEventCountQuery = {
|
|
76
|
+
date: string;
|
|
77
|
+
eventType?: string;
|
|
78
|
+
};
|
|
79
|
+
export type AnalyticsEventCount = {
|
|
80
|
+
count: number;
|
|
81
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type CreateAppAccountEntryOptions = {
|
|
2
|
+
/** The trusted issuer that authenticated this application session. */
|
|
3
|
+
issuer: string;
|
|
4
|
+
/** The registered application's serialized HTTPS origin. */
|
|
5
|
+
applicationOrigin: string;
|
|
6
|
+
accessToken: string;
|
|
7
|
+
/**
|
|
8
|
+
* The page on the application origin hosted settings links back to, such as "/mine". Defaults to
|
|
9
|
+
* the application's home. Never pass the current URL blindly: a fragment or path may hold a link token.
|
|
10
|
+
*/
|
|
11
|
+
returnPath?: string;
|
|
12
|
+
fetch?: typeof globalThis.fetch;
|
|
13
|
+
};
|
|
14
|
+
export type AppAccountEntry = {
|
|
15
|
+
actionUrl: string;
|
|
16
|
+
/** A short-lived, one-use credential for the form body. Keep it out of URLs and logs. */
|
|
17
|
+
ticket: string;
|
|
18
|
+
};
|
|
19
|
+
/** Issue a hosted settings entry ticket for the remembered application session. */
|
|
20
|
+
export declare function createAppAccountEntry(options: CreateAppAccountEntryOptions): Promise<AppAccountEntry>;
|
|
21
|
+
export type OpenAppAccountSettingsOptions = Omit<CreateAppAccountEntryOptions, "applicationOrigin"> & {
|
|
22
|
+
/** Defaults to the page's own origin, which must be registered for the application. */
|
|
23
|
+
applicationOrigin?: string;
|
|
24
|
+
/** Defaults to the page's document; pass one in tests. */
|
|
25
|
+
document?: Document;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Open hosted account settings in the same tab from a browser app. It asks the issuer for a one-use
|
|
29
|
+
* ticket and posts it in a native form, so settings shows a verified link back to the app.
|
|
30
|
+
*/
|
|
31
|
+
export declare function openAppAccountSettings(options: OpenAppAccountSettingsOptions): Promise<void>;
|
|
32
|
+
export declare class AppAccountEntryError extends Error {
|
|
33
|
+
readonly status: number;
|
|
34
|
+
constructor(status: number);
|
|
35
|
+
}
|
|
36
|
+
export type CurrentAppProfileField = {
|
|
37
|
+
fieldKey: string;
|
|
38
|
+
value?: string;
|
|
39
|
+
present: boolean;
|
|
40
|
+
/** Remains true after an explicit clear so apps do not import the old value again. */
|
|
41
|
+
initialized: boolean;
|
|
42
|
+
required: boolean;
|
|
43
|
+
editableBy: string;
|
|
44
|
+
editable: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type CurrentAppProfile = {
|
|
47
|
+
fields: CurrentAppProfileField[];
|
|
48
|
+
managedPhoto?: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type CurrentAppProfileUpdate = {
|
|
51
|
+
values: {
|
|
52
|
+
fieldKey: string;
|
|
53
|
+
value: string;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
export type CurrentAppProfileClientConfig = {
|
|
57
|
+
apiBaseUrl: string;
|
|
58
|
+
/** Returns the current end-user access token with the application's profile scope. */
|
|
59
|
+
accessToken: () => string | Promise<string>;
|
|
60
|
+
fetch?: typeof globalThis.fetch;
|
|
61
|
+
};
|
|
62
|
+
export declare class CurrentAppProfileError extends Error {
|
|
63
|
+
readonly status: number;
|
|
64
|
+
constructor(status: number);
|
|
65
|
+
}
|
|
66
|
+
export declare class CurrentAppProfileClient {
|
|
67
|
+
private readonly config;
|
|
68
|
+
private readonly origin;
|
|
69
|
+
private readonly fetch;
|
|
70
|
+
constructor(config: CurrentAppProfileClientConfig);
|
|
71
|
+
read(): Promise<CurrentAppProfile>;
|
|
72
|
+
update(update: CurrentAppProfileUpdate): Promise<CurrentAppProfile>;
|
|
73
|
+
/** Fill only previously uninitialized fields and return the current profile. */
|
|
74
|
+
initialize(update: CurrentAppProfileUpdate): Promise<CurrentAppProfile>;
|
|
75
|
+
private writeFields;
|
|
76
|
+
readPhoto(): Promise<Blob>;
|
|
77
|
+
uploadPhoto(photo: Blob): Promise<CurrentAppProfile>;
|
|
78
|
+
/** Fill a previously uninitialized photo and return the current profile. */
|
|
79
|
+
initializePhoto(photo: Blob): Promise<CurrentAppProfile>;
|
|
80
|
+
private writePhoto;
|
|
81
|
+
removePhoto(): Promise<CurrentAppProfile>;
|
|
82
|
+
private profile;
|
|
83
|
+
private request;
|
|
84
|
+
}
|