@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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campaign email: published revisions and their rendering, scheduled runs, recipient permission, and
|
|
3
|
+
* the welcome journey (welcome then reminder) driven by confirmed signups and activations.
|
|
4
|
+
*/
|
|
5
|
+
export class CampaignEmailAdminClient {
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
createRevision(body, companySlug) {
|
|
10
|
+
return this.request("POST", scoped("/campaign-email-revisions", companySlug), body);
|
|
11
|
+
}
|
|
12
|
+
getRevision(revision, companySlug) {
|
|
13
|
+
return this.request("GET", scoped(revisionPath(revision), companySlug));
|
|
14
|
+
}
|
|
15
|
+
renderRevision(revision, body) {
|
|
16
|
+
return this.request("POST", `${revisionPath(revision)}/render`, body);
|
|
17
|
+
}
|
|
18
|
+
startRun(body, companySlug) {
|
|
19
|
+
return this.run("POST", "/campaign-email-runs", companySlug, body);
|
|
20
|
+
}
|
|
21
|
+
getRun(runId, companySlug) {
|
|
22
|
+
return this.run("GET", runPath(runId), companySlug);
|
|
23
|
+
}
|
|
24
|
+
cancelRun(runId, companySlug) {
|
|
25
|
+
return this.run("POST", `${runPath(runId)}/cancel`, companySlug);
|
|
26
|
+
}
|
|
27
|
+
checkPermission(body, companySlug) {
|
|
28
|
+
return this.request("POST", scoped("/campaign-email-permissions/check", companySlug), body);
|
|
29
|
+
}
|
|
30
|
+
confirmPermission(body, companySlug) {
|
|
31
|
+
return this.request("POST", scoped("/campaign-email-permissions/confirm", companySlug), body);
|
|
32
|
+
}
|
|
33
|
+
withdrawPermission(body, companySlug) {
|
|
34
|
+
return this.request("POST", scoped("/campaign-email-permissions/withdraw", companySlug), body);
|
|
35
|
+
}
|
|
36
|
+
putWelcomeDefinition(body, companySlug) {
|
|
37
|
+
return this.request("PUT", scoped("/campaign-email-welcome/definition", companySlug), body);
|
|
38
|
+
}
|
|
39
|
+
setWelcomePaused(body, companySlug) {
|
|
40
|
+
return this.request("PUT", scoped("/campaign-email-welcome/pause", companySlug), body);
|
|
41
|
+
}
|
|
42
|
+
recordWelcomeConfirmedSignup(body, companySlug) {
|
|
43
|
+
return this.request("POST", scoped("/campaign-email-welcome/confirmed-signup", companySlug), body);
|
|
44
|
+
}
|
|
45
|
+
recordWelcomeActivation(body, companySlug) {
|
|
46
|
+
return this.request("POST", scoped("/campaign-email-welcome/activation", companySlug), body);
|
|
47
|
+
}
|
|
48
|
+
getWelcomeContact(contactId, companySlug) {
|
|
49
|
+
return this.request("GET", scoped(`/campaign-email-welcome/contacts/${encodeURIComponent(contactId)}`, companySlug));
|
|
50
|
+
}
|
|
51
|
+
async run(method, path, companySlug, body) {
|
|
52
|
+
const status = await this.request(method, scoped(path, companySlug), body);
|
|
53
|
+
return { ...status, deliveries: status.deliveries ?? [] };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function revisionPath(revision) {
|
|
57
|
+
return `/campaign-email-revisions/${encodeURIComponent(revision)}`;
|
|
58
|
+
}
|
|
59
|
+
function runPath(runId) {
|
|
60
|
+
return `/campaign-email-runs/${encodeURIComponent(runId)}`;
|
|
61
|
+
}
|
|
62
|
+
function scoped(path, companySlug) {
|
|
63
|
+
return companySlug ? `${path}?companySlug=${encodeURIComponent(companySlug)}` : path;
|
|
64
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { EventRollupDimensionProfile } from "./admin-event-types.js";
|
|
2
|
+
import type { PackDefinition, RequestOptions } from "./index.js";
|
|
3
|
+
export type ClientSetupOAuthPurposeProfile = "ingest" | "schema" | "reporting" | "lifecycle" | "broker";
|
|
4
|
+
export type ClientSetupOAuthClientDesiredState = {
|
|
5
|
+
name?: string;
|
|
6
|
+
clientId: string;
|
|
7
|
+
purposeProfile: ClientSetupOAuthPurposeProfile;
|
|
8
|
+
/** The environment the client's events default to. */
|
|
9
|
+
environment?: string;
|
|
10
|
+
};
|
|
11
|
+
/** An event type's desired rollup dimensions. */
|
|
12
|
+
export type ClientSetupEventTypeDesiredState = {
|
|
13
|
+
eventTypeSlug: string;
|
|
14
|
+
rollupDimensions: EventRollupDimensionProfile;
|
|
15
|
+
};
|
|
16
|
+
export type ClientSetupSchemaDesiredState = {
|
|
17
|
+
eventTypeSlug: string;
|
|
18
|
+
version: string;
|
|
19
|
+
schemaJson: Record<string, unknown>;
|
|
20
|
+
dialect?: "jsonschema" | "avro";
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ClientSetupPrivacyRule = {
|
|
24
|
+
fieldPath: string;
|
|
25
|
+
action: string;
|
|
26
|
+
truncateLength?: number;
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type ClientSetupPrivacyDesiredState = {
|
|
30
|
+
applyMode?: string;
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
rules?: ClientSetupPrivacyRule[];
|
|
33
|
+
};
|
|
34
|
+
export type ClientSetupRetentionDesiredState = {
|
|
35
|
+
maxAgeDays: number;
|
|
36
|
+
classes: string[];
|
|
37
|
+
};
|
|
38
|
+
export type ClientSetupReportingPackDesiredState = {
|
|
39
|
+
definition: PackDefinition;
|
|
40
|
+
expectedRevision?: number;
|
|
41
|
+
};
|
|
42
|
+
export type ClientSetupManifest = {
|
|
43
|
+
schemas?: ClientSetupSchemaDesiredState[];
|
|
44
|
+
privacy?: ClientSetupPrivacyDesiredState;
|
|
45
|
+
retention?: ClientSetupRetentionDesiredState;
|
|
46
|
+
reportingPacks?: ClientSetupReportingPackDesiredState[];
|
|
47
|
+
oauthClients?: ClientSetupOAuthClientDesiredState[];
|
|
48
|
+
eventTypeConfigs?: ClientSetupEventTypeDesiredState[];
|
|
49
|
+
};
|
|
50
|
+
export type ClientSetupResourceStatus = {
|
|
51
|
+
kind: string;
|
|
52
|
+
key: string;
|
|
53
|
+
state: string;
|
|
54
|
+
ready: boolean;
|
|
55
|
+
safeNextAction: string;
|
|
56
|
+
safeNextActionCode: string;
|
|
57
|
+
detail?: string;
|
|
58
|
+
};
|
|
59
|
+
/** Why a pending operation is waiting, and when it tries again. */
|
|
60
|
+
export type ClientSetupOperationPending = {
|
|
61
|
+
nextAttemptAt: string;
|
|
62
|
+
lastFailure?: {
|
|
63
|
+
code: string;
|
|
64
|
+
observedAt: string;
|
|
65
|
+
resources: ClientSetupResourceStatus[] | null;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type ClientSetupOperationStatus = {
|
|
69
|
+
uuid: string;
|
|
70
|
+
idempotencyKey: string;
|
|
71
|
+
state: string;
|
|
72
|
+
errorCode?: string;
|
|
73
|
+
attemptCount: number;
|
|
74
|
+
leaseExpiresAt?: string;
|
|
75
|
+
pending?: ClientSetupOperationPending;
|
|
76
|
+
createdAt: string;
|
|
77
|
+
updatedAt: string;
|
|
78
|
+
completedAt?: string;
|
|
79
|
+
};
|
|
80
|
+
export type ClientSetupApplyResponse = {
|
|
81
|
+
tenantSlug: string;
|
|
82
|
+
manifestDigest: string;
|
|
83
|
+
ready: boolean;
|
|
84
|
+
state: string;
|
|
85
|
+
resources: ClientSetupResourceStatus[];
|
|
86
|
+
safeNextAction: string;
|
|
87
|
+
safeNextActionCode: string;
|
|
88
|
+
observedAt: string;
|
|
89
|
+
operation?: ClientSetupOperationStatus;
|
|
90
|
+
};
|
|
91
|
+
export type ClientSetupReadinessResponse = {
|
|
92
|
+
tenantSlug: string;
|
|
93
|
+
manifestDigest: string;
|
|
94
|
+
ready: boolean;
|
|
95
|
+
state: string;
|
|
96
|
+
resources: ClientSetupResourceStatus[];
|
|
97
|
+
safeNextAction: string;
|
|
98
|
+
safeNextActionCode: string;
|
|
99
|
+
observedAt: string;
|
|
100
|
+
operation?: ClientSetupOperationStatus;
|
|
101
|
+
};
|
|
102
|
+
export type ClientSetupApplyOptions = RequestOptions & {
|
|
103
|
+
idempotencyKey: string;
|
|
104
|
+
};
|
|
105
|
+
export type ClientSetupApplyAndWaitOptions = ClientSetupApplyOptions & {
|
|
106
|
+
timeoutMs?: number;
|
|
107
|
+
intervalMs?: number;
|
|
108
|
+
};
|
|
109
|
+
export type ClientSetupApplyAndWaitResult = {
|
|
110
|
+
apply: ClientSetupApplyResponse;
|
|
111
|
+
readiness: ClientSetupReadinessResponse;
|
|
112
|
+
};
|
|
113
|
+
export declare function validateClientSetupManifest(manifest: ClientSetupManifest): void;
|
|
114
|
+
type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
|
|
115
|
+
export declare class ClientSetupClient {
|
|
116
|
+
private readonly request;
|
|
117
|
+
constructor(request: AdminRequester);
|
|
118
|
+
apply(tenantSlug: string, manifest: ClientSetupManifest, options: ClientSetupApplyOptions): Promise<ClientSetupApplyResponse>;
|
|
119
|
+
readiness(tenantSlug: string, options?: RequestOptions): Promise<ClientSetupReadinessResponse>;
|
|
120
|
+
applyAndWait(tenantSlug: string, manifest: ClientSetupManifest, options: ClientSetupApplyAndWaitOptions): Promise<ClientSetupApplyAndWaitResult>;
|
|
121
|
+
}
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
const setupManifestKeys = new Set([
|
|
2
|
+
"schemas",
|
|
3
|
+
"privacy",
|
|
4
|
+
"retention",
|
|
5
|
+
"reportingPacks",
|
|
6
|
+
"oauthClients",
|
|
7
|
+
"eventTypeConfigs",
|
|
8
|
+
]);
|
|
9
|
+
const setupPurposeProfiles = [
|
|
10
|
+
"ingest",
|
|
11
|
+
"schema",
|
|
12
|
+
"reporting",
|
|
13
|
+
"lifecycle",
|
|
14
|
+
"broker",
|
|
15
|
+
];
|
|
16
|
+
const setupRetentionClasses = new Set(["raw", "archive", "materialized", "cache", "object"]);
|
|
17
|
+
const setupPrivacyActions = new Set(["keep", "hash", "truncate", "remove", "strip_query", "origin"]);
|
|
18
|
+
// Three independent runtime consumers reconcile on a 15-second interval. The
|
|
19
|
+
// last acknowledgement can require one further cycle before activation.
|
|
20
|
+
const defaultSetupReadinessTimeoutMs = 45000;
|
|
21
|
+
const defaultSetupReadinessIntervalMs = 1000;
|
|
22
|
+
// validateClientSetupManifest mirrors the manifest's client-visible shape so
|
|
23
|
+
// malformed configuration fails before it reaches the Admin API. Server-side
|
|
24
|
+
// validation remains authoritative for full reporting-pack semantics.
|
|
25
|
+
export function validateClientSetupManifest(manifest) {
|
|
26
|
+
if (!isRecord(manifest)) {
|
|
27
|
+
throw new Error("custd: tenant manifest must be an object");
|
|
28
|
+
}
|
|
29
|
+
for (const key of Object.keys(manifest)) {
|
|
30
|
+
if (!setupManifestKeys.has(key)) {
|
|
31
|
+
throw new Error(`custd: tenant manifest field ${key} is not supported`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
validateSetupSchemas(manifest.schemas);
|
|
35
|
+
validateSetupPrivacy(manifest.privacy);
|
|
36
|
+
validateSetupRetention(manifest.retention);
|
|
37
|
+
validateSetupReportingPacks(manifest.reportingPacks);
|
|
38
|
+
validateSetupOAuthClients(manifest.oauthClients);
|
|
39
|
+
}
|
|
40
|
+
function validateSetupSchemas(schemas) {
|
|
41
|
+
if (schemas === undefined)
|
|
42
|
+
return;
|
|
43
|
+
if (!Array.isArray(schemas))
|
|
44
|
+
throw new Error("custd: manifest schemas must be an array");
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
schemas.forEach((value, index) => {
|
|
47
|
+
const schema = setupRecord(value, `schemas[${index}]`);
|
|
48
|
+
const eventTypeSlug = setupString(schema.eventTypeSlug, `schemas[${index}].eventTypeSlug`);
|
|
49
|
+
const version = setupString(schema.version, `schemas[${index}].version`);
|
|
50
|
+
if (!isRecord(schema.schemaJson))
|
|
51
|
+
throw new Error(`custd: schemas[${index}].schemaJson must be an object`);
|
|
52
|
+
if (schema.dialect !== undefined && schema.dialect !== "jsonschema" && schema.dialect !== "avro") {
|
|
53
|
+
throw new Error(`custd: schemas[${index}].dialect is unsupported`);
|
|
54
|
+
}
|
|
55
|
+
if (typeof schema.enabled !== "boolean")
|
|
56
|
+
throw new Error(`custd: schemas[${index}].enabled must be a boolean`);
|
|
57
|
+
const key = `${eventTypeSlug}@${version}`;
|
|
58
|
+
if (seen.has(key))
|
|
59
|
+
throw new Error(`custd: duplicate schema ${key}`);
|
|
60
|
+
seen.add(key);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function validateSetupPrivacy(privacy) {
|
|
64
|
+
if (privacy === undefined)
|
|
65
|
+
return;
|
|
66
|
+
const value = setupRecord(privacy, "privacy");
|
|
67
|
+
if (value.applyMode !== undefined && typeof value.applyMode !== "string") {
|
|
68
|
+
throw new Error("custd: privacy.applyMode must be a string");
|
|
69
|
+
}
|
|
70
|
+
if (typeof value.enabled !== "boolean")
|
|
71
|
+
throw new Error("custd: privacy.enabled must be a boolean");
|
|
72
|
+
if (value.rules === undefined)
|
|
73
|
+
return;
|
|
74
|
+
if (!Array.isArray(value.rules))
|
|
75
|
+
throw new Error("custd: privacy.rules must be an array");
|
|
76
|
+
value.rules.forEach((entry, index) => {
|
|
77
|
+
const rule = setupRecord(entry, `privacy.rules[${index}]`);
|
|
78
|
+
setupString(rule.fieldPath, `privacy.rules[${index}].fieldPath`);
|
|
79
|
+
const action = setupString(rule.action, `privacy.rules[${index}].action`);
|
|
80
|
+
if (!setupPrivacyActions.has(action))
|
|
81
|
+
throw new Error(`custd: privacy.rules[${index}].action is unsupported`);
|
|
82
|
+
if (typeof rule.enabled !== "boolean") {
|
|
83
|
+
throw new Error(`custd: privacy.rules[${index}].enabled must be a boolean`);
|
|
84
|
+
}
|
|
85
|
+
if (rule.truncateLength !== undefined && (!isInteger(rule.truncateLength) || rule.truncateLength < 1)) {
|
|
86
|
+
throw new Error(`custd: privacy.rules[${index}].truncateLength must be positive`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function validateSetupRetention(retention) {
|
|
91
|
+
if (retention === undefined)
|
|
92
|
+
return;
|
|
93
|
+
const value = setupRecord(retention, "retention");
|
|
94
|
+
if (!isInteger(value.maxAgeDays) || value.maxAgeDays < 1) {
|
|
95
|
+
throw new Error("custd: retention.maxAgeDays must be positive");
|
|
96
|
+
}
|
|
97
|
+
if (!Array.isArray(value.classes) || value.classes.length === 0) {
|
|
98
|
+
throw new Error("custd: retention.classes must be a non-empty array");
|
|
99
|
+
}
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
value.classes.forEach((entry, index) => {
|
|
102
|
+
const className = setupString(entry, `retention.classes[${index}]`);
|
|
103
|
+
if (!setupRetentionClasses.has(className))
|
|
104
|
+
throw new Error(`custd: retention class ${className} is unsupported`);
|
|
105
|
+
if (seen.has(className))
|
|
106
|
+
throw new Error(`custd: duplicate retention class ${className}`);
|
|
107
|
+
seen.add(className);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function validateSetupReportingPacks(packs) {
|
|
111
|
+
if (packs === undefined)
|
|
112
|
+
return;
|
|
113
|
+
if (!Array.isArray(packs))
|
|
114
|
+
throw new Error("custd: manifest reportingPacks must be an array");
|
|
115
|
+
const seen = new Set();
|
|
116
|
+
packs.forEach((entry, index) => {
|
|
117
|
+
const desired = setupRecord(entry, `reportingPacks[${index}]`);
|
|
118
|
+
const definition = setupRecord(desired.definition, `reportingPacks[${index}].definition`);
|
|
119
|
+
const definitionField = `reportingPacks[${index}].definition`;
|
|
120
|
+
const key = validateSetupPackDefinition(definition, definitionField);
|
|
121
|
+
if (desired.expectedRevision !== undefined &&
|
|
122
|
+
(!isInteger(desired.expectedRevision) || desired.expectedRevision < 0)) {
|
|
123
|
+
throw new Error(`custd: reportingPacks[${index}].expectedRevision must be a non-negative integer`);
|
|
124
|
+
}
|
|
125
|
+
if (Object.keys(desired).includes("clientSecret")) {
|
|
126
|
+
throw new Error("custd: client secrets are managed by Custd");
|
|
127
|
+
}
|
|
128
|
+
if (seen.has(key))
|
|
129
|
+
throw new Error(`custd: duplicate reporting pack ${key}`);
|
|
130
|
+
seen.add(key);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function validateSetupPackDefinition(definition, field) {
|
|
134
|
+
const key = setupString(definition.key, `${field}.key`);
|
|
135
|
+
setupString(definition.displayName, `${field}.displayName`);
|
|
136
|
+
setupString(definition.owner, `${field}.owner`);
|
|
137
|
+
if (!isInteger(definition.version) || definition.version < 1) {
|
|
138
|
+
throw new Error(`custd: ${field}.version must be a positive integer`);
|
|
139
|
+
}
|
|
140
|
+
if (typeof definition.enabled !== "boolean") {
|
|
141
|
+
throw new Error(`custd: ${field}.enabled must be a boolean`);
|
|
142
|
+
}
|
|
143
|
+
setupStringArray(definition.eventTypes, `${field}.eventTypes`);
|
|
144
|
+
validateSetupPackMetrics(definition.metrics, `${field}.metrics`);
|
|
145
|
+
validateSetupPackDimensions(definition.dimensions, `${field}.dimensions`);
|
|
146
|
+
validateSetupPackTemplates(definition.templates, `${field}.templates`);
|
|
147
|
+
if (definition.flowRules !== undefined)
|
|
148
|
+
validateSetupFlowRules(definition.flowRules, `${field}.flowRules`);
|
|
149
|
+
validateSetupPackTrust(definition.trust, `${field}.trust`);
|
|
150
|
+
validateSetupPackProof(definition.proof, `${field}.proof`);
|
|
151
|
+
if (definition.identity !== undefined)
|
|
152
|
+
validateSetupPackIdentity(definition.identity, `${field}.identity`);
|
|
153
|
+
return key;
|
|
154
|
+
}
|
|
155
|
+
function validateSetupPackMetrics(metrics, field) {
|
|
156
|
+
if (!Array.isArray(metrics) || metrics.length === 0) {
|
|
157
|
+
throw new Error(`custd: ${field} must be a non-empty array`);
|
|
158
|
+
}
|
|
159
|
+
metrics.forEach((entry, index) => {
|
|
160
|
+
const metric = setupRecord(entry, `${field}[${index}]`);
|
|
161
|
+
setupString(metric.key, `${field}[${index}].key`);
|
|
162
|
+
setupString(metric.label, `${field}[${index}].label`);
|
|
163
|
+
setupString(metric.kind, `${field}[${index}].kind`);
|
|
164
|
+
setupString(metric.calculation, `${field}[${index}].calculation`);
|
|
165
|
+
if (metric.match !== undefined)
|
|
166
|
+
validateSetupMatchPredicates(metric.match, `${field}[${index}].match`);
|
|
167
|
+
if (metric.flowResult !== undefined)
|
|
168
|
+
setupString(metric.flowResult, `${field}[${index}].flowResult`);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function validateSetupPackDimensions(dimensions, field) {
|
|
172
|
+
if (!Array.isArray(dimensions))
|
|
173
|
+
throw new Error(`custd: ${field} must be an array`);
|
|
174
|
+
dimensions.forEach((entry, index) => {
|
|
175
|
+
const dimension = setupRecord(entry, `${field}[${index}]`);
|
|
176
|
+
const key = setupString(dimension.key, `${field}[${index}].key`);
|
|
177
|
+
setupString(dimension.label, `${field}[${index}].label`);
|
|
178
|
+
if (key !== "environment" || dimension.selector !== undefined) {
|
|
179
|
+
setupString(dimension.selector, `${field}[${index}].selector`);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function validateSetupPackTemplates(templates, field) {
|
|
184
|
+
if (!Array.isArray(templates) || templates.length === 0) {
|
|
185
|
+
throw new Error(`custd: ${field} must be a non-empty array`);
|
|
186
|
+
}
|
|
187
|
+
templates.forEach((entry, index) => {
|
|
188
|
+
const template = setupRecord(entry, `${field}[${index}]`);
|
|
189
|
+
const templateField = `${field}[${index}]`;
|
|
190
|
+
setupString(template.name, `${templateField}.name`);
|
|
191
|
+
setupStringArray(template.allowedMetrics, `${templateField}.allowedMetrics`);
|
|
192
|
+
setupStringArray(template.sourceModes, `${templateField}.sourceModes`);
|
|
193
|
+
if (!isInteger(template.maxRows) || template.maxRows < 1) {
|
|
194
|
+
throw new Error(`custd: ${templateField}.maxRows must be a positive integer`);
|
|
195
|
+
}
|
|
196
|
+
setupStringArray(template.eventTypes, `${templateField}.eventTypes`);
|
|
197
|
+
setupString(template.aggregation, `${templateField}.aggregation`);
|
|
198
|
+
if (template.flowRule !== undefined)
|
|
199
|
+
setupString(template.flowRule, `${templateField}.flowRule`);
|
|
200
|
+
if (template.allowedDimensions !== undefined) {
|
|
201
|
+
setupStringArray(template.allowedDimensions, `${templateField}.allowedDimensions`, false);
|
|
202
|
+
}
|
|
203
|
+
if (template.allowedFilters !== undefined) {
|
|
204
|
+
validateSetupPackFilters(template.allowedFilters, `${templateField}.allowedFilters`);
|
|
205
|
+
}
|
|
206
|
+
if (template.compositionRules !== undefined) {
|
|
207
|
+
setupStringArray(template.compositionRules, `${templateField}.compositionRules`, false);
|
|
208
|
+
}
|
|
209
|
+
if (template.defaultRange !== undefined)
|
|
210
|
+
setupString(template.defaultRange, `${templateField}.defaultRange`);
|
|
211
|
+
if (template.subjectScope !== undefined) {
|
|
212
|
+
const scope = setupRecord(template.subjectScope, `${templateField}.subjectScope`);
|
|
213
|
+
if (typeof scope.required !== "boolean") {
|
|
214
|
+
throw new Error(`custd: ${templateField}.subjectScope.required must be a boolean`);
|
|
215
|
+
}
|
|
216
|
+
setupString(scope.dimension, `${templateField}.subjectScope.dimension`);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function validateSetupMatchPredicates(predicates, field) {
|
|
221
|
+
if (!Array.isArray(predicates) || predicates.length === 0) {
|
|
222
|
+
throw new Error(`custd: ${field} must be a non-empty array`);
|
|
223
|
+
}
|
|
224
|
+
predicates.forEach((entry, index) => {
|
|
225
|
+
const predicate = setupRecord(entry, `${field}[${index}]`);
|
|
226
|
+
setupString(predicate.selector, `${field}[${index}].selector`);
|
|
227
|
+
if (predicate.exact !== undefined)
|
|
228
|
+
setupString(predicate.exact, `${field}[${index}].exact`);
|
|
229
|
+
if (predicate.anyOf !== undefined)
|
|
230
|
+
setupStringArray(predicate.anyOf, `${field}[${index}].anyOf`, false);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function validateSetupFlowRules(rules, field) {
|
|
234
|
+
if (!Array.isArray(rules) || rules.length === 0)
|
|
235
|
+
throw new Error(`custd: ${field} must be a non-empty array`);
|
|
236
|
+
rules.forEach((entry, index) => {
|
|
237
|
+
const rule = setupRecord(entry, `${field}[${index}]`);
|
|
238
|
+
const ruleField = `${field}[${index}]`;
|
|
239
|
+
setupString(rule.key, `${ruleField}.key`);
|
|
240
|
+
setupString(rule.correlationSelector, `${ruleField}.correlationSelector`);
|
|
241
|
+
setupString(rule.stepSelector, `${ruleField}.stepSelector`);
|
|
242
|
+
setupStringArray(rule.startMarkers, `${ruleField}.startMarkers`);
|
|
243
|
+
setupStringArray(rule.completionMarkers, `${ruleField}.completionMarkers`);
|
|
244
|
+
if (rule.familySelector !== undefined)
|
|
245
|
+
setupString(rule.familySelector, `${ruleField}.familySelector`);
|
|
246
|
+
if (rule.familyValue !== undefined)
|
|
247
|
+
setupString(rule.familyValue, `${ruleField}.familyValue`);
|
|
248
|
+
if (typeof rule.includeUncorrelated !== "boolean") {
|
|
249
|
+
throw new Error(`custd: ${ruleField}.includeUncorrelated must be a boolean`);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function validateSetupPackFilters(filters, field) {
|
|
254
|
+
if (!Array.isArray(filters))
|
|
255
|
+
throw new Error(`custd: ${field} must be an array`);
|
|
256
|
+
filters.forEach((entry, index) => {
|
|
257
|
+
const filter = setupRecord(entry, `${field}[${index}]`);
|
|
258
|
+
setupString(filter.dimension, `${field}[${index}].dimension`);
|
|
259
|
+
setupStringArray(filter.operators, `${field}[${index}].operators`);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function validateSetupPackTrust(trust, field) {
|
|
263
|
+
const value = setupRecord(trust, field);
|
|
264
|
+
setupStringArray(value.safeFields, `${field}.safeFields`, false);
|
|
265
|
+
setupStringArray(value.redactionGuard, `${field}.redactionGuard`, false);
|
|
266
|
+
}
|
|
267
|
+
function validateSetupPackProof(proof, field) {
|
|
268
|
+
const value = setupRecord(proof, field);
|
|
269
|
+
setupString(value.key, `${field}.key`);
|
|
270
|
+
setupStringArray(value.templates, `${field}.templates`, false);
|
|
271
|
+
setupStringArray(value.safeMetadataFields, `${field}.safeMetadataFields`, false);
|
|
272
|
+
setupStringArray(value.forbiddenFields, `${field}.forbiddenFields`, false);
|
|
273
|
+
setupString(value.outputLayout, `${field}.outputLayout`);
|
|
274
|
+
}
|
|
275
|
+
function validateSetupPackIdentity(identity, field) {
|
|
276
|
+
const value = setupRecord(identity, field);
|
|
277
|
+
for (const key of ["subject", "session", "entity", "cohort", "correlation"]) {
|
|
278
|
+
if (value[key] === undefined)
|
|
279
|
+
continue;
|
|
280
|
+
const selector = setupRecord(value[key], `${field}.${key}`);
|
|
281
|
+
// The platform serialises the whole identity block and leaves unset selectors empty, so a pack
|
|
282
|
+
// it exported always carries all five keys. Empty means unset; anything else must be complete.
|
|
283
|
+
if (selector.selector === "" && selector.type === "")
|
|
284
|
+
continue;
|
|
285
|
+
setupString(selector.selector, `${field}.${key}.selector`);
|
|
286
|
+
setupString(selector.type, `${field}.${key}.type`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function setupStringArray(value, field, requireEntries = true) {
|
|
290
|
+
if (!Array.isArray(value) ||
|
|
291
|
+
(requireEntries && value.length === 0) ||
|
|
292
|
+
!value.every((item) => typeof item === "string")) {
|
|
293
|
+
throw new Error(`custd: ${field} must be ${requireEntries ? "a non-empty " : "an "}array of strings`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function validateSetupOAuthClients(clients) {
|
|
297
|
+
if (clients === undefined)
|
|
298
|
+
return;
|
|
299
|
+
if (!Array.isArray(clients))
|
|
300
|
+
throw new Error("custd: manifest oauthClients must be an array");
|
|
301
|
+
const seen = new Set();
|
|
302
|
+
clients.forEach((entry, index) => {
|
|
303
|
+
const client = setupRecord(entry, `oauthClients[${index}]`);
|
|
304
|
+
const clientId = setupString(client.clientId, `oauthClients[${index}].clientId`);
|
|
305
|
+
if (!setupPurposeProfiles.includes(client.purposeProfile)) {
|
|
306
|
+
throw new Error(`custd: oauthClients[${index}].purposeProfile is unsupported`);
|
|
307
|
+
}
|
|
308
|
+
if (client.name !== undefined && typeof client.name !== "string") {
|
|
309
|
+
throw new Error(`custd: oauthClients[${index}].name must be a string`);
|
|
310
|
+
}
|
|
311
|
+
if (client.environment !== undefined && typeof client.environment !== "string") {
|
|
312
|
+
throw new Error(`custd: oauthClients[${index}].environment must be a string`);
|
|
313
|
+
}
|
|
314
|
+
if (Object.keys(client).includes("clientSecret")) {
|
|
315
|
+
throw new Error("custd: client secrets are managed by Custd");
|
|
316
|
+
}
|
|
317
|
+
if (seen.has(clientId))
|
|
318
|
+
throw new Error(`custd: duplicate oauth client ${clientId}`);
|
|
319
|
+
seen.add(clientId);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function setupRecord(value, field) {
|
|
323
|
+
if (!isRecord(value))
|
|
324
|
+
throw new Error(`custd: ${field} must be an object`);
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
function setupString(value, field) {
|
|
328
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
329
|
+
throw new Error(`custd: ${field} must be non-empty`);
|
|
330
|
+
return value;
|
|
331
|
+
}
|
|
332
|
+
function isInteger(value) {
|
|
333
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
334
|
+
}
|
|
335
|
+
function isRecord(value) {
|
|
336
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
337
|
+
}
|
|
338
|
+
function setupWaitDuration(value, fallback, field) {
|
|
339
|
+
const duration = value ?? fallback;
|
|
340
|
+
if (!Number.isFinite(duration) || duration <= 0) {
|
|
341
|
+
throw new Error(`custd: ${field} must be a positive finite number`);
|
|
342
|
+
}
|
|
343
|
+
return duration;
|
|
344
|
+
}
|
|
345
|
+
function setupApplyOptions(options) {
|
|
346
|
+
if (typeof options.idempotencyKey !== "string" || options.idempotencyKey.trim() === "") {
|
|
347
|
+
throw new Error("custd: tenant manifest idempotencyKey must be non-empty");
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
idempotencyKey: options.idempotencyKey,
|
|
351
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function waitForSetupReadiness(intervalMs, signal) {
|
|
355
|
+
return new Promise((resolve, reject) => {
|
|
356
|
+
let timer;
|
|
357
|
+
const onAbort = () => {
|
|
358
|
+
if (timer !== undefined)
|
|
359
|
+
clearTimeout(timer);
|
|
360
|
+
reject(signal?.reason ?? new Error("custd: tenant manifest readiness wait aborted"));
|
|
361
|
+
};
|
|
362
|
+
if (signal?.aborted) {
|
|
363
|
+
onAbort();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
timer = setTimeout(() => {
|
|
367
|
+
signal?.removeEventListener("abort", onAbort);
|
|
368
|
+
resolve();
|
|
369
|
+
}, intervalMs);
|
|
370
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
function readinessTimeoutError(tenantSlug, readiness, timeoutMs) {
|
|
374
|
+
const code = readiness.safeNextActionCode || "unknown";
|
|
375
|
+
return new Error(`custd: timed out waiting for tenant manifest readiness for "${tenantSlug}" after ${timeoutMs}ms ` +
|
|
376
|
+
`(action=${readiness.safeNextAction || "unknown"}, code=${code})`);
|
|
377
|
+
}
|
|
378
|
+
export class ClientSetupClient {
|
|
379
|
+
constructor(request) {
|
|
380
|
+
this.request = request;
|
|
381
|
+
}
|
|
382
|
+
async apply(tenantSlug, manifest, options) {
|
|
383
|
+
validateClientSetupManifest(manifest);
|
|
384
|
+
return this.request("PUT", `/tenant-manifest/${encodeURIComponent(tenantSlug)}`, manifest, setupApplyOptions(options));
|
|
385
|
+
}
|
|
386
|
+
readiness(tenantSlug, options) {
|
|
387
|
+
return this.request("GET", `/tenant-manifest/${encodeURIComponent(tenantSlug)}/readiness`, undefined, options);
|
|
388
|
+
}
|
|
389
|
+
async applyAndWait(tenantSlug, manifest, options) {
|
|
390
|
+
const timeoutMs = setupWaitDuration(options.timeoutMs, defaultSetupReadinessTimeoutMs, "timeoutMs");
|
|
391
|
+
const intervalMs = setupWaitDuration(options.intervalMs, defaultSetupReadinessIntervalMs, "intervalMs");
|
|
392
|
+
const requestOptions = setupApplyOptions(options);
|
|
393
|
+
const apply = await this.apply(tenantSlug, manifest, requestOptions);
|
|
394
|
+
let readiness = apply;
|
|
395
|
+
const deadline = Date.now() + timeoutMs;
|
|
396
|
+
while (!readiness.ready && readiness.safeNextAction === "retry") {
|
|
397
|
+
const remainingMs = deadline - Date.now();
|
|
398
|
+
if (remainingMs <= 0)
|
|
399
|
+
throw readinessTimeoutError(tenantSlug, readiness, timeoutMs);
|
|
400
|
+
await waitForSetupReadiness(Math.min(intervalMs, remainingMs), options.signal);
|
|
401
|
+
readiness = await this.readiness(tenantSlug, requestOptions);
|
|
402
|
+
}
|
|
403
|
+
if (!readiness.ready && readiness.safeNextAction === "retry") {
|
|
404
|
+
throw readinessTimeoutError(tenantSlug, readiness, timeoutMs);
|
|
405
|
+
}
|
|
406
|
+
return { apply, readiness };
|
|
407
|
+
}
|
|
408
|
+
}
|