@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.
Files changed (196) hide show
  1. package/README.md +958 -2
  2. package/dist/admin-accounting-evidence.d.ts +48 -0
  3. package/dist/admin-accounting-evidence.js +24 -0
  4. package/dist/admin-app-releases.d.ts +116 -0
  5. package/dist/admin-app-releases.js +8 -0
  6. package/dist/admin-apps.d.ts +120 -0
  7. package/dist/admin-apps.js +47 -0
  8. package/dist/admin-auth-project-domain.d.ts +125 -0
  9. package/dist/admin-auth-project-domain.js +37 -0
  10. package/dist/admin-auth-projects.d.ts +989 -0
  11. package/dist/admin-auth-projects.js +527 -0
  12. package/dist/admin-campaign-email.d.ts +120 -0
  13. package/dist/admin-campaign-email.js +64 -0
  14. package/dist/admin-client-setup.d.ts +122 -0
  15. package/dist/admin-client-setup.js +408 -0
  16. package/dist/admin-data-labels.d.ts +124 -0
  17. package/dist/admin-data-labels.js +51 -0
  18. package/dist/admin-data-scopes.d.ts +93 -0
  19. package/dist/admin-data-scopes.js +154 -0
  20. package/dist/admin-email-relay.d.ts +66 -0
  21. package/dist/admin-email-relay.js +25 -0
  22. package/dist/admin-environment-policy.d.ts +32 -0
  23. package/dist/admin-environment-policy.js +26 -0
  24. package/dist/admin-error-issues.d.ts +91 -0
  25. package/dist/admin-error-issues.js +52 -0
  26. package/dist/admin-event-types.d.ts +57 -0
  27. package/dist/admin-event-types.js +28 -0
  28. package/dist/admin-impersonation.d.ts +48 -0
  29. package/dist/admin-impersonation.js +27 -0
  30. package/dist/admin-ingest-claims.d.ts +35 -0
  31. package/dist/admin-ingest-claims.js +26 -0
  32. package/dist/admin-managed-audit.d.ts +13 -0
  33. package/dist/admin-managed-audit.js +13 -0
  34. package/dist/admin-measurement-projects.d.ts +166 -0
  35. package/dist/admin-measurement-projects.js +120 -0
  36. package/dist/admin-notification-destinations.d.ts +31 -0
  37. package/dist/admin-notification-destinations.js +19 -0
  38. package/dist/admin-notification-webhooks.d.ts +64 -0
  39. package/dist/admin-notification-webhooks.js +42 -0
  40. package/dist/admin-oauth-client-admissions.d.ts +65 -0
  41. package/dist/admin-oauth-client-admissions.js +46 -0
  42. package/dist/admin-offboarding.d.ts +123 -0
  43. package/dist/admin-offboarding.js +129 -0
  44. package/dist/admin-predictions.d.ts +266 -0
  45. package/dist/admin-predictions.js +93 -0
  46. package/dist/admin-privacy-erasures.d.ts +74 -0
  47. package/dist/admin-privacy-erasures.js +73 -0
  48. package/dist/admin-retention.d.ts +99 -0
  49. package/dist/admin-retention.js +60 -0
  50. package/dist/admin-rls.d.ts +94 -0
  51. package/dist/admin-rls.js +33 -0
  52. package/dist/admin-sdk-usage.d.ts +41 -0
  53. package/dist/admin-sdk-usage.js +23 -0
  54. package/dist/admin-site-ai.d.ts +72 -0
  55. package/dist/admin-site-ai.js +1 -0
  56. package/dist/admin-site-analytics.d.ts +52 -0
  57. package/dist/admin-site-analytics.js +14 -0
  58. package/dist/admin-site-audit-pages.d.ts +76 -0
  59. package/dist/admin-site-audit-pages.js +27 -0
  60. package/dist/admin-site-campaign-links.d.ts +40 -0
  61. package/dist/admin-site-campaign-links.js +9 -0
  62. package/dist/admin-site-domains.d.ts +733 -0
  63. package/dist/admin-site-domains.js +768 -0
  64. package/dist/admin-site-export.d.ts +76 -0
  65. package/dist/admin-site-export.js +15 -0
  66. package/dist/admin-site-insights-tasks.d.ts +44 -0
  67. package/dist/admin-site-insights-tasks.js +28 -0
  68. package/dist/admin-site-insights.d.ts +527 -0
  69. package/dist/admin-site-insights.js +61 -0
  70. package/dist/admin-site-links.d.ts +87 -0
  71. package/dist/admin-site-links.js +16 -0
  72. package/dist/admin-site-monitors.d.ts +110 -0
  73. package/dist/admin-site-monitors.js +25 -0
  74. package/dist/admin-site-next-actions.d.ts +93 -0
  75. package/dist/admin-site-next-actions.js +36 -0
  76. package/dist/admin-site-page-queries.d.ts +63 -0
  77. package/dist/admin-site-page-queries.js +20 -0
  78. package/dist/admin-site-rankings.d.ts +98 -0
  79. package/dist/admin-site-rankings.js +46 -0
  80. package/dist/admin-site-regional-trends.d.ts +30 -0
  81. package/dist/admin-site-regional-trends.js +1 -0
  82. package/dist/admin-site-saved-reports.d.ts +45 -0
  83. package/dist/admin-site-saved-reports.js +13 -0
  84. package/dist/admin-site-search-pool.d.ts +77 -0
  85. package/dist/admin-site-search-pool.js +41 -0
  86. package/dist/admin-site-search-value.d.ts +97 -0
  87. package/dist/admin-site-search-value.js +29 -0
  88. package/dist/admin-site-status-page.d.ts +57 -0
  89. package/dist/admin-site-status-page.js +10 -0
  90. package/dist/admin-site-traffic.d.ts +145 -0
  91. package/dist/admin-site-traffic.js +32 -0
  92. package/dist/admin-site-web-data.d.ts +258 -0
  93. package/dist/admin-site-web-data.js +60 -0
  94. package/dist/admin-subject-exports.d.ts +79 -0
  95. package/dist/admin-subject-exports.js +44 -0
  96. package/dist/admin-support-access.d.ts +32 -0
  97. package/dist/admin-support-access.js +21 -0
  98. package/dist/admin-system.d.ts +283 -0
  99. package/dist/admin-system.js +65 -0
  100. package/dist/admin-tenant-storage.d.ts +35 -0
  101. package/dist/admin-tenant-storage.js +24 -0
  102. package/dist/admin-timeplans.d.ts +512 -0
  103. package/dist/admin-timeplans.js +200 -0
  104. package/dist/admin-uncertainty-models.d.ts +42 -0
  105. package/dist/admin-uncertainty-models.js +53 -0
  106. package/dist/admin-usage.d.ts +124 -0
  107. package/dist/admin-usage.js +169 -0
  108. package/dist/admin-users.d.ts +124 -0
  109. package/dist/admin-users.js +82 -0
  110. package/dist/admin-workflow-timings.d.ts +367 -0
  111. package/dist/admin-workflow-timings.js +117 -0
  112. package/dist/analytics-events.d.ts +167 -0
  113. package/dist/analytics-events.js +197 -0
  114. package/dist/analytics-reads.d.ts +81 -0
  115. package/dist/analytics-reads.js +5 -0
  116. package/dist/app-account.d.ts +84 -0
  117. package/dist/app-account.js +177 -0
  118. package/dist/app-alerts.d.ts +120 -0
  119. package/dist/app-alerts.js +44 -0
  120. package/dist/app-items.d.ts +786 -0
  121. package/dist/app-items.js +524 -0
  122. package/dist/app-live.d.ts +84 -0
  123. package/dist/app-live.js +228 -0
  124. package/dist/app-meetings.d.ts +95 -0
  125. package/dist/app-meetings.js +26 -0
  126. package/dist/app-models.d.ts +271 -0
  127. package/dist/app-models.js +83 -0
  128. package/dist/app-push.d.ts +64 -0
  129. package/dist/app-push.js +178 -0
  130. package/dist/backend-lifecycle.d.ts +85 -0
  131. package/dist/backend-lifecycle.js +212 -0
  132. package/dist/browser-manifest.json +7 -0
  133. package/dist/browser-script-BWnwDjAC.js +711 -0
  134. package/dist/browser-script.d.ts +1 -0
  135. package/dist/browser-script.js +5 -0
  136. package/dist/browser-sign-in.d.ts +153 -0
  137. package/dist/browser-sign-in.js +410 -0
  138. package/dist/browser-tracker.d.ts +142 -0
  139. package/dist/browser-tracker.js +775 -0
  140. package/dist/browser-web-vitals.d.ts +22 -0
  141. package/dist/browser-web-vitals.js +116 -0
  142. package/dist/browser.d.ts +10 -0
  143. package/dist/browser.js +10 -0
  144. package/dist/download-stream.d.ts +16 -0
  145. package/dist/download-stream.js +55 -0
  146. package/dist/error-capture.d.ts +62 -0
  147. package/dist/error-capture.js +168 -0
  148. package/dist/hosted-app.d.ts +115 -0
  149. package/dist/hosted-app.js +275 -0
  150. package/dist/index.d.ts +2324 -0
  151. package/dist/index.js +2226 -0
  152. package/dist/ingest-operations.d.ts +483 -0
  153. package/dist/ingest-operations.js +154 -0
  154. package/dist/measurement.d.ts +164 -0
  155. package/dist/measurement.js +104 -0
  156. package/dist/mobile-adapter.d.ts +25 -0
  157. package/dist/mobile-adapter.js +57 -0
  158. package/dist/mobile-context.d.ts +32 -0
  159. package/dist/mobile-context.js +156 -0
  160. package/dist/mobile-queue.d.ts +22 -0
  161. package/dist/mobile-queue.js +73 -0
  162. package/dist/oauth.d.ts +1 -0
  163. package/dist/oauth.js +8 -0
  164. package/dist/parsers.d.ts +149 -0
  165. package/dist/parsers.js +115 -0
  166. package/dist/public-reads.d.ts +79 -0
  167. package/dist/public-reads.js +57 -0
  168. package/dist/reporting-catalogue.d.ts +264 -0
  169. package/dist/reporting-catalogue.js +5 -0
  170. package/dist/reporting-state.d.ts +46 -0
  171. package/dist/reporting-state.js +76 -0
  172. package/dist/response-lists.d.ts +16 -0
  173. package/dist/response-lists.generated.d.ts +7 -0
  174. package/dist/response-lists.generated.js +1927 -0
  175. package/dist/response-lists.js +70 -0
  176. package/dist/response-validation.d.ts +30 -0
  177. package/dist/response-validation.js +94 -0
  178. package/dist/runtime-readiness.d.ts +30 -0
  179. package/dist/runtime-readiness.js +150 -0
  180. package/dist/schema-registry.d.ts +45 -0
  181. package/dist/schema-registry.js +9 -0
  182. package/dist/secure-url.d.ts +4 -0
  183. package/dist/secure-url.js +23 -0
  184. package/dist/site-ai-owner.d.ts +34 -0
  185. package/dist/site-ai-owner.js +99 -0
  186. package/dist/site-monitor-reports.d.ts +15 -0
  187. package/dist/site-monitor-reports.js +87 -0
  188. package/dist/testing/fake-custd.d.ts +150 -0
  189. package/dist/testing/fake-custd.js +842 -0
  190. package/dist/testing/fake-results.d.ts +30 -0
  191. package/dist/testing/fake-results.js +293 -0
  192. package/dist/testing.d.ts +2 -0
  193. package/dist/testing.js +3 -0
  194. package/dist/version.d.ts +10 -0
  195. package/dist/version.js +10 -0
  196. package/package.json +57 -4
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Measurement reads and runs served by the analytics API: the tenant overview, prediction
3
+ * definitions with their runs, outcomes and evaluations, project forecasts and forecast stories,
4
+ * decision simulations, and uncertainty model runs. The credential names the tenant.
5
+ */
6
+ import type { AppForecastRun, AppForecastRunRequest, AppForecastStory, AppForecastWarning } from "./app-items.js";
7
+ import type { AppModelRun, AppModelRunRequest, AppModelRunTrigger } from "./app-models.js";
8
+ import type { RequestOptions } from "./index.js";
9
+ type APIRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
10
+ export type MeasurementOverviewPoint = {
11
+ label: string;
12
+ value: string;
13
+ };
14
+ /** One area of the tenant's measurement overview, shaped for one widget. */
15
+ export type MeasurementOverviewArea = {
16
+ key: string;
17
+ title: string;
18
+ headline: string;
19
+ value: string;
20
+ detail: string;
21
+ state: string;
22
+ widgetKind: string;
23
+ provenance?: string;
24
+ points: MeasurementOverviewPoint[];
25
+ };
26
+ export type MeasurementOverview = {
27
+ generatedAt: string;
28
+ tenant: {
29
+ companySlug: string;
30
+ label: string;
31
+ };
32
+ areas: MeasurementOverviewArea[];
33
+ };
34
+ /** One active prediction definition. */
35
+ export type PredictionDefinitionRead = {
36
+ uuid: string;
37
+ definitionKey: string;
38
+ displayName: string;
39
+ status: string;
40
+ isPaused: boolean;
41
+ updatedAt: string;
42
+ };
43
+ export type PredictionDefinitionReadList = {
44
+ items: PredictionDefinitionRead[];
45
+ };
46
+ /** One run of a prediction definition. */
47
+ export type PredictionRunRead = {
48
+ runUuid: string;
49
+ asOf: string;
50
+ horizonEnd: string;
51
+ output: number;
52
+ baseline: number;
53
+ overrideApplied: boolean;
54
+ inputHash: string;
55
+ contributionCount: number;
56
+ generatedAt: string;
57
+ };
58
+ export type PredictionRunReadList = {
59
+ items: PredictionRunRead[];
60
+ };
61
+ /** How one run resolved. */
62
+ export type PredictionOutcomeRead = {
63
+ runUuid: string;
64
+ resolution: string;
65
+ outcomeKind: string;
66
+ resolvedAt?: string;
67
+ observedValue: number;
68
+ isLateEvidence: boolean;
69
+ };
70
+ export type PredictionOutcomeReadList = {
71
+ items: PredictionOutcomeRead[];
72
+ };
73
+ /** The latest scored window of a definition's resolved runs. */
74
+ export type PredictionEvaluationRead = {
75
+ windowStartAt: string;
76
+ windowEndAt: string;
77
+ resolvedRunCount: number;
78
+ positiveCount: number;
79
+ negativeCount: number;
80
+ brierScore?: number;
81
+ logLoss?: number;
82
+ sparseBucketCount: number;
83
+ };
84
+ /** A decision simulation. A zero or absent seed and sample count use the server defaults. */
85
+ export type MeasurementSimulationRunRequest = {
86
+ seed?: number;
87
+ sampleCount?: number;
88
+ };
89
+ /** One variable's value of information, ranked. */
90
+ export type MeasurementSimulationVariable = {
91
+ variableUuid: string;
92
+ name: string;
93
+ rank: number;
94
+ evpi: number;
95
+ evppi?: number;
96
+ measurementCost: number;
97
+ worthMeasuring: boolean;
98
+ };
99
+ export type MeasurementSimulationRun = {
100
+ simulationRunUuid: string;
101
+ projectUuid: string;
102
+ decisionUuid: string;
103
+ status: string;
104
+ method: string;
105
+ generatedAt: string;
106
+ completedAt: string;
107
+ sampleCount: number;
108
+ seed: number;
109
+ variables: MeasurementSimulationVariable[];
110
+ warnings: AppForecastWarning[];
111
+ provenance: Record<string, string>;
112
+ };
113
+ /** One stored uncertainty model run, without its results. */
114
+ export type UncertaintyModelRunSummary = {
115
+ runUuid: string;
116
+ modelUuid: string;
117
+ versionNumber: number;
118
+ trigger: AppModelRunTrigger;
119
+ sourceForecastRunUuid?: string;
120
+ seed: number;
121
+ sampleCount: number;
122
+ createdAt: string;
123
+ };
124
+ export type UncertaintyModelRunList = {
125
+ runs: UncertaintyModelRunSummary[];
126
+ };
127
+ export declare class MeasurementClient {
128
+ private readonly request;
129
+ readonly predictions: MeasurementPredictionReads;
130
+ readonly projects: MeasurementProjectRuns;
131
+ readonly uncertaintyModels: MeasurementUncertaintyModelRuns;
132
+ constructor(request: APIRequester);
133
+ overview(): Promise<MeasurementOverview>;
134
+ }
135
+ /** The tenant's prediction definitions as the analytics API serves them; changes go through admin. */
136
+ export declare class MeasurementPredictionReads {
137
+ private readonly request;
138
+ constructor(request: APIRequester);
139
+ listDefinitions(): Promise<PredictionDefinitionReadList>;
140
+ getDefinition(definitionUuid: string): Promise<PredictionDefinitionRead>;
141
+ /** A definition's runs, newest first; `since` (RFC 3339) keeps only runs as of that time or later. */
142
+ listRuns(definitionUuid: string, since?: string): Promise<PredictionRunReadList>;
143
+ listOutcomes(definitionUuid: string): Promise<PredictionOutcomeReadList>;
144
+ getLatestEvaluation(definitionUuid: string): Promise<PredictionEvaluationRead>;
145
+ }
146
+ /** A measurement project's forecasts, forecast story and decision simulations. */
147
+ export declare class MeasurementProjectRuns {
148
+ private readonly request;
149
+ constructor(request: APIRequester);
150
+ runForecast(projectUuid: string, body?: AppForecastRunRequest): Promise<AppForecastRun>;
151
+ getForecastRun(projectUuid: string, runUuid: string): Promise<AppForecastRun>;
152
+ getForecastStory(projectUuid: string): Promise<AppForecastStory>;
153
+ runDecisionSimulation(projectUuid: string, decisionUuid: string, body?: MeasurementSimulationRunRequest): Promise<MeasurementSimulationRun>;
154
+ getDecisionSimulationRun(projectUuid: string, decisionUuid: string, runUuid: string): Promise<MeasurementSimulationRun>;
155
+ }
156
+ /** Runs of an uncertainty model; the model itself is managed through admin. */
157
+ export declare class MeasurementUncertaintyModelRuns {
158
+ private readonly request;
159
+ constructor(request: APIRequester);
160
+ createRun(modelUuid: string, body: AppModelRunRequest): Promise<AppModelRun>;
161
+ listRuns(modelUuid: string): Promise<UncertaintyModelRunList>;
162
+ getRun(modelUuid: string, runUuid: string): Promise<AppModelRun>;
163
+ }
164
+ export {};
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Measurement reads and runs served by the analytics API: the tenant overview, prediction
3
+ * definitions with their runs, outcomes and evaluations, project forecasts and forecast stories,
4
+ * decision simulations, and uncertainty model runs. The credential names the tenant.
5
+ */
6
+ export class MeasurementClient {
7
+ constructor(request) {
8
+ this.request = request;
9
+ this.predictions = new MeasurementPredictionReads(request);
10
+ this.projects = new MeasurementProjectRuns(request);
11
+ this.uncertaintyModels = new MeasurementUncertaintyModelRuns(request);
12
+ }
13
+ async overview() {
14
+ const wire = await this.request("GET", "/measurement/overview");
15
+ return { ...wire, areas: (wire.areas ?? []).map((area) => ({ ...area, points: area.points ?? [] })) };
16
+ }
17
+ }
18
+ /** The tenant's prediction definitions as the analytics API serves them; changes go through admin. */
19
+ export class MeasurementPredictionReads {
20
+ constructor(request) {
21
+ this.request = request;
22
+ }
23
+ async listDefinitions() {
24
+ return items(await this.request("GET", definitionPath()));
25
+ }
26
+ getDefinition(definitionUuid) {
27
+ return this.request("GET", definitionPath(definitionUuid));
28
+ }
29
+ /** A definition's runs, newest first; `since` (RFC 3339) keeps only runs as of that time or later. */
30
+ async listRuns(definitionUuid, since) {
31
+ const query = since ? `?since=${encodeURIComponent(since)}` : "";
32
+ return items(await this.request("GET", `${definitionPath(definitionUuid, "/runs")}${query}`));
33
+ }
34
+ async listOutcomes(definitionUuid) {
35
+ return items(await this.request("GET", definitionPath(definitionUuid, "/outcomes")));
36
+ }
37
+ getLatestEvaluation(definitionUuid) {
38
+ return this.request("GET", definitionPath(definitionUuid, "/evaluations"));
39
+ }
40
+ }
41
+ /** A measurement project's forecasts, forecast story and decision simulations. */
42
+ export class MeasurementProjectRuns {
43
+ constructor(request) {
44
+ this.request = request;
45
+ }
46
+ runForecast(projectUuid, body = {}) {
47
+ return this.request("POST", projectPath(projectUuid, "/forecast-runs"), body);
48
+ }
49
+ getForecastRun(projectUuid, runUuid) {
50
+ return this.request("GET", projectPath(projectUuid, `/forecast-runs/${encodeURIComponent(runUuid)}`));
51
+ }
52
+ async getForecastStory(projectUuid) {
53
+ const story = await this.request("GET", projectPath(projectUuid, "/forecast-story"));
54
+ return {
55
+ ...story,
56
+ observations: story.observations ?? [],
57
+ snapshots: story.snapshots ?? [],
58
+ delivery: { ...story.delivery, estimates: story.delivery?.estimates ?? [] },
59
+ };
60
+ }
61
+ async runDecisionSimulation(projectUuid, decisionUuid, body = {}) {
62
+ const path = projectPath(projectUuid, `/decisions/${encodeURIComponent(decisionUuid)}/simulation-runs`);
63
+ return simulationRun(await this.request("POST", path, body));
64
+ }
65
+ async getDecisionSimulationRun(projectUuid, decisionUuid, runUuid) {
66
+ const resource = `/decisions/${encodeURIComponent(decisionUuid)}/simulation-runs/${encodeURIComponent(runUuid)}`;
67
+ return simulationRun(await this.request("GET", projectPath(projectUuid, resource)));
68
+ }
69
+ }
70
+ /** Runs of an uncertainty model; the model itself is managed through admin. */
71
+ export class MeasurementUncertaintyModelRuns {
72
+ constructor(request) {
73
+ this.request = request;
74
+ }
75
+ async createRun(modelUuid, body) {
76
+ return modelRun(await this.request("POST", runsPath(modelUuid), body));
77
+ }
78
+ async listRuns(modelUuid) {
79
+ const list = await this.request("GET", runsPath(modelUuid));
80
+ return { runs: list.runs ?? [] };
81
+ }
82
+ async getRun(modelUuid, runUuid) {
83
+ return modelRun(await this.request("GET", `${runsPath(modelUuid)}/${encodeURIComponent(runUuid)}`));
84
+ }
85
+ }
86
+ function items(wire) {
87
+ return { items: wire.items ?? [] };
88
+ }
89
+ function simulationRun(wire) {
90
+ return { ...wire, variables: wire.variables ?? [], warnings: wire.warnings ?? [] };
91
+ }
92
+ function modelRun(wire) {
93
+ return { ...wire, quantities: wire.quantities ?? [], boundInputs: wire.boundInputs ?? [] };
94
+ }
95
+ function definitionPath(definitionUuid, resource = "") {
96
+ const base = "/measurement/predictions/definitions";
97
+ return definitionUuid === undefined ? base : `${base}/${encodeURIComponent(definitionUuid)}${resource}`;
98
+ }
99
+ function projectPath(projectUuid, resource) {
100
+ return `/measurement/projects/${encodeURIComponent(projectUuid)}${resource}`;
101
+ }
102
+ function runsPath(modelUuid) {
103
+ return `/measurement/uncertainty-models/${encodeURIComponent(modelUuid)}/runs`;
104
+ }
@@ -0,0 +1,25 @@
1
+ import type { AsyncQueueStorage } from "./mobile-queue.js";
2
+ export type MobileKeyValueStorage = {
3
+ getItem: (key: string) => Promise<string | null>;
4
+ setItem: (key: string, value: string) => Promise<void>;
5
+ removeItem: (key: string) => Promise<void>;
6
+ };
7
+ export type MobileAppState = {
8
+ addEventListener: (event: "change", listener: (state: string) => void) => MobileSubscription;
9
+ };
10
+ export type MobileNetworkState = {
11
+ isConnected: boolean | null;
12
+ isInternetReachable?: boolean | null;
13
+ };
14
+ export type MobileNetwork = {
15
+ addEventListener: (listener: (state: MobileNetworkState) => void) => MobileSubscription;
16
+ };
17
+ export type MobileSubscription = {
18
+ remove: () => void;
19
+ } | (() => void);
20
+ export type MobileFlushTriggerOptions = {
21
+ appState: MobileAppState;
22
+ network: MobileNetwork;
23
+ };
24
+ export declare function createMobileAsyncQueueStorage(storage: MobileKeyValueStorage, key: string): AsyncQueueStorage;
25
+ export declare function createMobileFlushTriggers(options: MobileFlushTriggerOptions): (flush: () => Promise<void>) => () => void;
@@ -0,0 +1,57 @@
1
+ export function createMobileAsyncQueueStorage(storage, key) {
2
+ if (!key) {
3
+ throw new Error("custd: mobile queue storage key is required");
4
+ }
5
+ return {
6
+ async load() {
7
+ const raw = await storage.getItem(key);
8
+ if (!raw) {
9
+ return [];
10
+ }
11
+ try {
12
+ const events = JSON.parse(raw);
13
+ return Array.isArray(events) ? events : [];
14
+ }
15
+ catch {
16
+ return [];
17
+ }
18
+ },
19
+ save(events) {
20
+ return storage.setItem(key, JSON.stringify(events));
21
+ },
22
+ clear() {
23
+ return storage.removeItem(key);
24
+ },
25
+ };
26
+ }
27
+ export function createMobileFlushTriggers(options) {
28
+ return (flush) => {
29
+ const flushSafely = () => {
30
+ void flush().catch(() => undefined);
31
+ };
32
+ const appSubscription = options.appState.addEventListener("change", (state) => {
33
+ if (state === "active") {
34
+ flushSafely();
35
+ }
36
+ });
37
+ const networkSubscription = options.network.addEventListener((state) => {
38
+ if (isReachable(state)) {
39
+ flushSafely();
40
+ }
41
+ });
42
+ return () => {
43
+ removeMobileSubscription(appSubscription);
44
+ removeMobileSubscription(networkSubscription);
45
+ };
46
+ };
47
+ }
48
+ function isReachable(state) {
49
+ return state.isConnected === true && state.isInternetReachable !== false;
50
+ }
51
+ function removeMobileSubscription(subscription) {
52
+ if (typeof subscription === "function") {
53
+ subscription();
54
+ return;
55
+ }
56
+ subscription.remove();
57
+ }
@@ -0,0 +1,32 @@
1
+ import type { EventEnvelope } from "./index.js";
2
+ declare const mobilePlatforms: readonly ["android", "ios"];
3
+ declare const mobileNetworkStates: readonly ["offline", "online", "unknown"];
4
+ export type MobilePlatform = (typeof mobilePlatforms)[number];
5
+ export type MobileNetworkState = (typeof mobileNetworkStates)[number];
6
+ export type MobileSubject = {
7
+ kind: "anonymous";
8
+ anonymousId: string;
9
+ } | {
10
+ kind: "authenticated";
11
+ userUuid: string;
12
+ };
13
+ export type MobileEventContext = {
14
+ appVersion: string;
15
+ platform: MobilePlatform;
16
+ locale: string;
17
+ timezone: string;
18
+ networkState: MobileNetworkState;
19
+ };
20
+ export type MobileEventInput = {
21
+ eventUuid?: string;
22
+ eventTypeSlug: string;
23
+ schemaVersion: string;
24
+ timestamp: string;
25
+ sessionId?: string;
26
+ companySlug?: string;
27
+ subject: MobileSubject;
28
+ context: MobileEventContext;
29
+ payload: Record<string, unknown>;
30
+ };
31
+ export declare function createMobileEvent(input: MobileEventInput): EventEnvelope;
32
+ export {};
@@ -0,0 +1,156 @@
1
+ const mobilePlatforms = ["android", "ios"];
2
+ const mobileNetworkStates = ["offline", "online", "unknown"];
3
+ const sensitiveMobilePayloadKeys = new Set([
4
+ "secret",
5
+ "clientsecret",
6
+ "producersecret",
7
+ "reportingsecret",
8
+ "token",
9
+ "authtoken",
10
+ "idtoken",
11
+ "oauthtoken",
12
+ "refreshtoken",
13
+ "reportingtoken",
14
+ "accesstoken",
15
+ "bearertoken",
16
+ "apikey",
17
+ "authorization",
18
+ "password",
19
+ "credential",
20
+ "privatekey",
21
+ ]);
22
+ // createMobileEvent deliberately accepts only event metadata safe for an app
23
+ // binary. Producer credentials and reporting-read credentials belong on the
24
+ // authenticated application relay, never in a mobile event envelope.
25
+ export function createMobileEvent(input) {
26
+ assertExactKeys(input, [
27
+ "eventUuid",
28
+ "eventTypeSlug",
29
+ "schemaVersion",
30
+ "timestamp",
31
+ "sessionId",
32
+ "companySlug",
33
+ "subject",
34
+ "context",
35
+ "payload",
36
+ ], "mobile event");
37
+ assertRequiredEventFields(input);
38
+ assertMobileSubject(input.subject);
39
+ assertMobileContext(input.context);
40
+ assertNoSensitiveFields(input.payload);
41
+ return {
42
+ eventUuid: input.eventUuid,
43
+ eventTypeSlug: input.eventTypeSlug,
44
+ schemaVersion: input.schemaVersion,
45
+ timestamp: input.timestamp,
46
+ sessionId: input.sessionId,
47
+ anonymousId: input.subject.kind === "anonymous" ? input.subject.anonymousId : undefined,
48
+ userUuid: input.subject.kind === "authenticated" ? input.subject.userUuid : null,
49
+ companySlug: input.companySlug,
50
+ context: {
51
+ device: { type: "mobile", os: input.context.platform },
52
+ appVersion: input.context.appVersion,
53
+ locale: input.context.locale,
54
+ timezone: input.context.timezone,
55
+ networkState: input.context.networkState,
56
+ },
57
+ payload: input.payload,
58
+ };
59
+ }
60
+ function assertRequiredEventFields(input) {
61
+ for (const [field, value] of Object.entries({
62
+ eventTypeSlug: input.eventTypeSlug,
63
+ schemaVersion: input.schemaVersion,
64
+ timestamp: input.timestamp,
65
+ })) {
66
+ if (!isNonBlankString(value)) {
67
+ throw new Error(`custd: mobile ${field} is required`);
68
+ }
69
+ }
70
+ if (Number.isNaN(Date.parse(input.timestamp))) {
71
+ throw new Error("custd: mobile timestamp must be an ISO timestamp");
72
+ }
73
+ if (!input.payload || typeof input.payload !== "object" || Array.isArray(input.payload)) {
74
+ throw new Error("custd: mobile payload must be an object");
75
+ }
76
+ }
77
+ function assertMobileSubject(subject) {
78
+ if (!subject || typeof subject !== "object") {
79
+ throw new Error("custd: mobile subject is required");
80
+ }
81
+ if (subject.kind === "anonymous") {
82
+ assertExactKeys(subject, ["kind", "anonymousId"], "anonymous mobile subject");
83
+ if (!isNonBlankString(subject.anonymousId)) {
84
+ throw new Error("custd: mobile anonymousId is required");
85
+ }
86
+ return;
87
+ }
88
+ if (subject.kind === "authenticated") {
89
+ assertExactKeys(subject, ["kind", "userUuid"], "authenticated mobile subject");
90
+ if (!isNonBlankString(subject.userUuid)) {
91
+ throw new Error("custd: mobile userUuid is required");
92
+ }
93
+ return;
94
+ }
95
+ throw new Error("custd: mobile subject kind must be anonymous or authenticated");
96
+ }
97
+ function assertMobileContext(context) {
98
+ assertExactKeys(context, ["appVersion", "platform", "locale", "timezone", "networkState"], "mobile context");
99
+ if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(context.appVersion)) {
100
+ throw new Error("custd: mobile appVersion must be a semantic version");
101
+ }
102
+ if (!mobilePlatforms.includes(context.platform)) {
103
+ throw new Error("custd: mobile platform must be ios or android");
104
+ }
105
+ if (!isLocale(context.locale)) {
106
+ throw new Error("custd: mobile locale must be a valid BCP 47 locale");
107
+ }
108
+ if (!isTimezone(context.timezone)) {
109
+ throw new Error("custd: mobile timezone must be a valid IANA timezone");
110
+ }
111
+ if (!mobileNetworkStates.includes(context.networkState)) {
112
+ throw new Error("custd: mobile networkState must be offline, online, or unknown");
113
+ }
114
+ }
115
+ function assertExactKeys(value, allowed, label) {
116
+ for (const key of Object.keys(value)) {
117
+ if (!allowed.includes(key)) {
118
+ throw new Error(`custd: unknown ${label} field: ${key}`);
119
+ }
120
+ }
121
+ }
122
+ function assertNoSensitiveFields(value) {
123
+ if (!value || typeof value !== "object") {
124
+ return;
125
+ }
126
+ for (const [key, child] of Object.entries(value)) {
127
+ if (isSensitiveKey(key)) {
128
+ throw new Error(`custd: mobile event contains sensitive field: ${key}`);
129
+ }
130
+ assertNoSensitiveFields(child);
131
+ }
132
+ }
133
+ function isSensitiveKey(key) {
134
+ const normalized = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
135
+ return sensitiveMobilePayloadKeys.has(normalized);
136
+ }
137
+ function isLocale(value) {
138
+ try {
139
+ return Intl.getCanonicalLocales(value).length === 1;
140
+ }
141
+ catch {
142
+ return false;
143
+ }
144
+ }
145
+ function isTimezone(value) {
146
+ try {
147
+ Intl.DateTimeFormat("en", { timeZone: value });
148
+ return true;
149
+ }
150
+ catch {
151
+ return false;
152
+ }
153
+ }
154
+ function isNonBlankString(value) {
155
+ return typeof value === "string" && value.trim().length > 0;
156
+ }
@@ -0,0 +1,22 @@
1
+ import type { EventEnvelope } from "./index.js";
2
+ export type AsyncQueueStorage = {
3
+ load: () => Promise<EventEnvelope[]>;
4
+ save: (events: EventEnvelope[]) => Promise<void>;
5
+ clear: () => Promise<void>;
6
+ };
7
+ export declare class AsyncEventQueue {
8
+ private readonly storage;
9
+ private readonly maxQueueSize;
10
+ private events;
11
+ private loaded;
12
+ private pending;
13
+ constructor(storage: AsyncQueueStorage, maxQueueSize: number);
14
+ load(): Promise<void>;
15
+ enqueue(event: EventEnvelope): Promise<void>;
16
+ peek(limit: number): Promise<EventEnvelope[]>;
17
+ acknowledge(eventUUIDs: readonly string[]): Promise<void>;
18
+ clear(): Promise<void>;
19
+ private run;
20
+ private requireLoaded;
21
+ private trimToCapacity;
22
+ }
@@ -0,0 +1,73 @@
1
+ // AsyncEventQueue serializes storage mutations so an offline client retains
2
+ // event IDs and ordering across restart, retry, and partial batch outcomes.
3
+ export class AsyncEventQueue {
4
+ constructor(storage, maxQueueSize) {
5
+ this.storage = storage;
6
+ this.maxQueueSize = maxQueueSize;
7
+ this.events = [];
8
+ this.loaded = false;
9
+ this.pending = Promise.resolve();
10
+ if (!Number.isSafeInteger(maxQueueSize) || maxQueueSize <= 0) {
11
+ throw new Error("custd: async queue maxQueueSize must be a positive integer");
12
+ }
13
+ }
14
+ load() {
15
+ return this.run(async () => {
16
+ const stored = await this.storage.load();
17
+ this.events = Array.isArray(stored) ? [...stored] : [];
18
+ this.trimToCapacity();
19
+ this.loaded = true;
20
+ await this.storage.save(this.events);
21
+ });
22
+ }
23
+ enqueue(event) {
24
+ return this.run(async () => {
25
+ this.requireLoaded();
26
+ this.events.push(event);
27
+ this.trimToCapacity();
28
+ await this.storage.save(this.events);
29
+ });
30
+ }
31
+ peek(limit) {
32
+ return this.run(async () => {
33
+ this.requireLoaded();
34
+ return this.events.slice(0, normalizeLimit(limit, this.events.length));
35
+ });
36
+ }
37
+ acknowledge(eventUUIDs) {
38
+ return this.run(async () => {
39
+ this.requireLoaded();
40
+ const accepted = new Set(eventUUIDs);
41
+ this.events = this.events.filter((event) => !accepted.has(event.eventUuid ?? ""));
42
+ await this.storage.save(this.events);
43
+ });
44
+ }
45
+ clear() {
46
+ return this.run(async () => {
47
+ this.requireLoaded();
48
+ this.events = [];
49
+ await this.storage.clear();
50
+ });
51
+ }
52
+ run(operation) {
53
+ const result = this.pending.then(operation, operation);
54
+ this.pending = result.then(() => undefined, () => undefined);
55
+ return result;
56
+ }
57
+ requireLoaded() {
58
+ if (!this.loaded) {
59
+ throw new Error("custd: async queue must load before use");
60
+ }
61
+ }
62
+ trimToCapacity() {
63
+ if (this.events.length > this.maxQueueSize) {
64
+ this.events = this.events.slice(-this.maxQueueSize);
65
+ }
66
+ }
67
+ }
68
+ function normalizeLimit(limit, available) {
69
+ if (!Number.isSafeInteger(limit) || limit <= 0) {
70
+ throw new Error("custd: async queue limit must be a positive integer");
71
+ }
72
+ return Math.min(limit, available);
73
+ }
@@ -0,0 +1 @@
1
+ export declare function basicAuthorization(clientId: string, clientSecret: string): string;
package/dist/oauth.js ADDED
@@ -0,0 +1,8 @@
1
+ export function basicAuthorization(clientId, clientSecret) {
2
+ const bytes = new TextEncoder().encode(`${clientId}:${clientSecret}`);
3
+ let binary = "";
4
+ for (const byte of bytes) {
5
+ binary += String.fromCharCode(byte);
6
+ }
7
+ return `Basic ${btoa(binary)}`;
8
+ }