@haakco/custd-sdk 0.0.0-stage → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +412 -2
- package/dist/admin-client-setup.d.ts +100 -0
- package/dist/admin-client-setup.js +398 -0
- package/dist/admin-data-labels.d.ts +124 -0
- package/dist/admin-data-labels.js +51 -0
- package/dist/admin-offboarding.d.ts +109 -0
- package/dist/admin-offboarding.js +108 -0
- package/dist/admin-predictions.d.ts +147 -0
- package/dist/admin-predictions.js +83 -0
- package/dist/admin-privacy-erasures.d.ts +62 -0
- package/dist/admin-privacy-erasures.js +72 -0
- package/dist/admin-retention.d.ts +51 -0
- package/dist/admin-retention.js +35 -0
- package/dist/admin-subject-exports.d.ts +48 -0
- package/dist/admin-subject-exports.js +28 -0
- package/dist/admin-tenant-storage.d.ts +27 -0
- package/dist/admin-tenant-storage.js +25 -0
- package/dist/admin-timeplans.d.ts +238 -0
- package/dist/admin-timeplans.js +146 -0
- package/dist/analytics-events.d.ts +85 -0
- package/dist/analytics-events.js +40 -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-BvgjdZSO.js +429 -0
- package/dist/browser-script.d.ts +1 -0
- package/dist/browser-script.js +5 -0
- package/dist/browser-tracker.d.ts +47 -0
- package/dist/browser-tracker.js +453 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +1 -0
- package/dist/fixtures.d.ts +10 -0
- package/dist/fixtures.js +57 -0
- package/dist/index.d.ts +1310 -0
- package/dist/index.js +1706 -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/reporting-state.d.ts +46 -0
- package/dist/reporting-state.js +76 -0
- package/dist/runtime-readiness.d.ts +30 -0
- package/dist/runtime-readiness.js +150 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.js +10 -0
- package/package.json +46 -4
package/README.md
CHANGED
|
@@ -1,3 +1,413 @@
|
|
|
1
|
-
#
|
|
1
|
+
# custd SDK (TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ingestion client with retry, batching, and optional offline queueing.
|
|
4
|
+
|
|
5
|
+
## Compatibility
|
|
6
|
+
|
|
7
|
+
Version `1.0.0` targets the canonical ingest endpoint
|
|
8
|
+
`POST /api/v1/events`. The legacy `POST /v1/events` path is not supported.
|
|
9
|
+
This SDK was not released against the legacy path, so there is no compatibility
|
|
10
|
+
alias or deprecation window.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
Use the GitHub package path when installing into HaakCo apps:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add '@haakco/custd-sdk@github:haakco/custd-sdk#v1.4.0&path:/sdk-js'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Pin the tag to the SDK version you want. The package is also published to the
|
|
21
|
+
HaakCo Verdaccio registry during the transition. To install from Verdaccio,
|
|
22
|
+
point the project at that registry, then install:
|
|
23
|
+
|
|
24
|
+
```ini
|
|
25
|
+
# .npmrc
|
|
26
|
+
registry=https://verdaccio.k8.haak.co/
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @haakco/custd-sdk
|
|
31
|
+
# or: npm install @haakco/custd-sdk --registry=https://verdaccio.k8.haak.co/
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Reads are anonymous; no token is required to install.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { createDogfoodEvent, CustdClient, LocalStorageQueueStorage } from "@haakco/custd-sdk";
|
|
40
|
+
|
|
41
|
+
const client = new CustdClient({
|
|
42
|
+
baseUrl: "http://localhost:8087",
|
|
43
|
+
oauth: {
|
|
44
|
+
clientId: "producer-client",
|
|
45
|
+
clientSecret: process.env.CUSTD_CLIENT_SECRET ?? "",
|
|
46
|
+
tokenUrl: "http://localhost:4444/oauth2/token",
|
|
47
|
+
audience: "custd",
|
|
48
|
+
scopes: ["events.write"],
|
|
49
|
+
},
|
|
50
|
+
retry: { maxAttempts: 3 },
|
|
51
|
+
batch: { maxBatchSize: 25, flushIntervalMs: 5000 },
|
|
52
|
+
queue: {
|
|
53
|
+
enabled: true,
|
|
54
|
+
storage: new LocalStorageQueueStorage("custd_queue"),
|
|
55
|
+
maxQueueSize: 1000,
|
|
56
|
+
},
|
|
57
|
+
// Batch request bodies are gzip-compressed by default once they reach
|
|
58
|
+
// `thresholdBytes`. Disable with `{ enabled: false }`. Compression is skipped
|
|
59
|
+
// automatically in runtimes without `CompressionStream`. (zstd is a planned
|
|
60
|
+
// follow-up.)
|
|
61
|
+
compression: { enabled: true, thresholdBytes: 1024 },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await client.track({
|
|
65
|
+
eventUuid: "...",
|
|
66
|
+
eventTypeSlug: "page-view",
|
|
67
|
+
schemaVersion: "1.0.0",
|
|
68
|
+
timestamp: new Date().toISOString(),
|
|
69
|
+
sessionId: "...",
|
|
70
|
+
anonymousId: "...",
|
|
71
|
+
companySlug: "acme",
|
|
72
|
+
context: {
|
|
73
|
+
page: { path: "/start" },
|
|
74
|
+
device: { type: "desktop" },
|
|
75
|
+
locale: "en-US",
|
|
76
|
+
timezone: "UTC",
|
|
77
|
+
ip: "127.0.0.1",
|
|
78
|
+
},
|
|
79
|
+
payload: { example: true },
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
When Custd provisions a producer it returns a flat credential bundle. Pass it
|
|
84
|
+
straight to `fromProvisionedProducer` — no OAuth wiring required:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const client = CustdClient.fromProvisionedProducer(credentials);
|
|
88
|
+
await client.track({
|
|
89
|
+
eventTypeSlug: "order.completed",
|
|
90
|
+
schemaVersion: "1.0.0",
|
|
91
|
+
companySlug: credentials.companySlug,
|
|
92
|
+
context: { device: { type: "server" } },
|
|
93
|
+
payload: { orderTotal: 42 }
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Use `redactedProvisionedProducer(credentials)` to show the bundle on a dashboard
|
|
98
|
+
without exposing the client secret.
|
|
99
|
+
|
|
100
|
+
The client also accepts `getToken: () => "<token>"` for existing static-token
|
|
101
|
+
or callback integrations. Producer clients should prefer the OAuth2
|
|
102
|
+
`client_credentials` config above so token refresh stays inside the SDK.
|
|
103
|
+
|
|
104
|
+
Trusted broker services can build an admin/provisioning client directly from
|
|
105
|
+
Custd provisioning environment variables:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const broker = CustdClient.fromBrokerEnv(env);
|
|
109
|
+
|
|
110
|
+
await broker.admin.tenants.create({
|
|
111
|
+
slug: "agency-store-001",
|
|
112
|
+
companyName: "Agency Store 001",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const credentials = await broker.provisioning.producers.provision({
|
|
116
|
+
companySlug: "agency-store-001",
|
|
117
|
+
producerSlug: "woocommerce",
|
|
118
|
+
scopeTemplate: "managed-audit-reporting-read",
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`fromBrokerEnv` reads `CUSTD_PROVISIONING_CLIENT_ID`,
|
|
123
|
+
`CUSTD_PROVISIONING_CLIENT_SECRET`, `CUSTD_PROVISIONING_TOKEN_URL`,
|
|
124
|
+
`CUSTD_PROVISIONING_AUDIENCE`, and either `CUSTD_BASE_URL` or an existing
|
|
125
|
+
Custd endpoint such as `CUSTD_PROVISIONING_ENDPOINT`. It defaults the OAuth
|
|
126
|
+
request scopes to `admin producers.provision`; pass `{ scopes: [...] }` when a
|
|
127
|
+
broker should request a narrower token.
|
|
128
|
+
|
|
129
|
+
Dogfood producers can use `createDogfoodEvent`:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
const event = createDogfoodEvent({
|
|
133
|
+
eventTypeSlug: "dogfood.producer.metric",
|
|
134
|
+
schemaVersion: "1.0.0",
|
|
135
|
+
companySlug: "haakco",
|
|
136
|
+
sourceSystem: "vorrent",
|
|
137
|
+
sourceCompany: "haakco",
|
|
138
|
+
environment: "production",
|
|
139
|
+
correlationId: "run-123",
|
|
140
|
+
payload: { metric: "media_cache.queue_depth", value: 7 },
|
|
141
|
+
strictPayloadKeys: true,
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`strictPayloadKeys: true` throws if the dogfood sanitizer would drop payload
|
|
146
|
+
keys such as `token`, `password`, `signedUrl`, `environment`, or
|
|
147
|
+
`sourceSystem`. Leave it off only when backward compatibility with existing
|
|
148
|
+
payloads is more important than surfacing dropped data.
|
|
149
|
+
|
|
150
|
+
The SDK requires `companySlug` and rejects plaintext non-local Custd/token URLs.
|
|
151
|
+
Localhost HTTP is allowed for development.
|
|
152
|
+
|
|
153
|
+
## Browser Tracker
|
|
154
|
+
|
|
155
|
+
Use the browser entrypoint for public website analytics. It sends to the
|
|
156
|
+
collector endpoints, not the producer OAuth endpoint:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { createBrowserTracker } from "@haakco/custd-sdk/browser";
|
|
160
|
+
|
|
161
|
+
const tracker = createBrowserTracker({
|
|
162
|
+
baseUrl: "https://custd.example.com",
|
|
163
|
+
siteUuid: "site-uuid",
|
|
164
|
+
writeKey: "site_pk_public_write_key",
|
|
165
|
+
allowedOrigins: ["https://www.example.com"],
|
|
166
|
+
batchSize: 25,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
tracker.installSpaTracking();
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`installSpaTracking()` sends an initial page view by default, tracks
|
|
173
|
+
`pushState`, `replaceState`, and `popstate`, and is idempotent. Pass
|
|
174
|
+
`trackInitialPageView: false` when the application already sends the first page
|
|
175
|
+
view during hydration.
|
|
176
|
+
|
|
177
|
+
Script-tag installs read `data-site-uuid` and `data-write-key`, then load site
|
|
178
|
+
identity/origin config from `/api/v1/sites/{siteUuid}/config`. That platform
|
|
179
|
+
endpoint must exist before script-tag installs are usable in production. Until
|
|
180
|
+
then, use `createBrowserTracker()` with explicit `allowedOrigins`. When the
|
|
181
|
+
endpoint is available, the site config response must include the current origin
|
|
182
|
+
in `allowedOrigins`; the browser tracker refuses to run without an
|
|
183
|
+
allowed-origin match. Script attributes cannot expand the server-provided origin
|
|
184
|
+
list.
|
|
185
|
+
|
|
186
|
+
```html
|
|
187
|
+
<script
|
|
188
|
+
type="module"
|
|
189
|
+
src="https://custd.com/custd-sdk/browser-script.js"
|
|
190
|
+
data-site-uuid="site-uuid"
|
|
191
|
+
data-write-key="site_pk_public_write_key"
|
|
192
|
+
></script>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Load the stable entry, not a content-hashed artifact name.
|
|
196
|
+
`browser-script.js` aliases whatever build the deployed manifest
|
|
197
|
+
(`/custd-sdk/browser-manifest.json`) names and is served with a one-hour bounded
|
|
198
|
+
cache, so a host picks up new SDK builds without editing its markup, and it can
|
|
199
|
+
never be left pointing at a retired artifact. A pinned
|
|
200
|
+
`browser-script-<content-hash>.js` URL changes on every release: the markup has
|
|
201
|
+
to be edited by hand to upgrade, and the old name stops resolving once the
|
|
202
|
+
artifact is gone.
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
await window.custd.track("purchase", { amount: 12.99 });
|
|
206
|
+
await window.custd.trackPageView();
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The default mode is cookieless: `anonymousId` and `sessionId` are sent as empty
|
|
210
|
+
strings. For consented identity, opt in explicitly:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
const tracker = createBrowserTracker({
|
|
214
|
+
baseUrl: "https://custd.example.com",
|
|
215
|
+
siteUuid: "site-uuid",
|
|
216
|
+
writeKey: "site_pk_public_write_key",
|
|
217
|
+
allowedOrigins: ["https://www.example.com"],
|
|
218
|
+
identityMode: "extended",
|
|
219
|
+
consent: "required",
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
tracker.setConsent("granted");
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Extended mode starts with consent required for script-tag installs unless
|
|
226
|
+
`data-consent="granted"` is present. It stores an anonymous ID in
|
|
227
|
+
`localStorage`, a session ID in `sessionStorage`, and all modes honor browser Do
|
|
228
|
+
Not Track. Page-exit flushes use `fetch` with `keepalive: true` so the tracker
|
|
229
|
+
can keep `credentials: "omit"` on collector requests; normal flushes also use
|
|
230
|
+
`fetch` with bearer write-key auth and omitted credentials. Queued events are
|
|
231
|
+
kept in memory by default so page URLs and payloads are not persisted; pass
|
|
232
|
+
`persistentQueue: true` to opt into `localStorage` queueing, and `maxQueueSize`
|
|
233
|
+
to lower the default limit of 1000 queued events. Script-tag installs can opt
|
|
234
|
+
into persistent queueing with `data-persistent-queue="true"`. Calling
|
|
235
|
+
`setConsent("denied")` clears extended-mode identifiers and queued events.
|
|
236
|
+
|
|
237
|
+
The browser-side origin check is a guardrail, not the security boundary.
|
|
238
|
+
Collectors must enforce `allowedOrigins`, write-key validity, and rate limits
|
|
239
|
+
server-side.
|
|
240
|
+
|
|
241
|
+
## Browser Site Admin Helpers
|
|
242
|
+
|
|
243
|
+
Server-side admin code can use `client.admin.sites` to create, list, get,
|
|
244
|
+
delete, and rotate browser tracker Sites. `create` returns the public write key
|
|
245
|
+
once. `list` and `get` return Site metadata without the write key.
|
|
246
|
+
`rotateWriteKey` returns the replacement write key once; update tracker config
|
|
247
|
+
and stop using the old key after rotation.
|
|
248
|
+
|
|
249
|
+
## Schema Admin Helpers
|
|
250
|
+
|
|
251
|
+
Server-side setup code can use `client.admin.schemas`:
|
|
252
|
+
|
|
253
|
+
Supported feature parity and intentionally missing helpers are documented in the SDK
|
|
254
|
+
root README.
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
await client.admin.schemas.register({
|
|
258
|
+
eventTypeSlug: "courib.delivery.created",
|
|
259
|
+
version: "1.0.0",
|
|
260
|
+
jsonSchema: { type: "object" },
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
await client.admin.schemas.createVersion("courib.delivery.created", {
|
|
264
|
+
version: "1.1.0",
|
|
265
|
+
jsonSchema: { type: "object" },
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## React Native
|
|
270
|
+
|
|
271
|
+
Mobile applications must not contain Custd producer credentials, provisioned
|
|
272
|
+
producer bundles, or tenant-wide `reporting:read` tokens. Send events to an
|
|
273
|
+
application-authenticated relay instead. The relay owns its Custd client and
|
|
274
|
+
producer credentials; the app sends only allowlisted, pseudonymous event data.
|
|
275
|
+
Likewise, have the relay render or authorize reporting results rather than
|
|
276
|
+
shipping a tenant-wide reporting token to the app.
|
|
277
|
+
|
|
278
|
+
The SDK provides dependency-free async queue and lifecycle primitives for Expo
|
|
279
|
+
or React Native. Pass your installed AsyncStorage-, AppState-, and
|
|
280
|
+
NetInfo-shaped implementations in; the SDK does not import or require those
|
|
281
|
+
packages. The queue keeps event IDs and ordering across storage restarts,
|
|
282
|
+
evicts oldest events at its configured bound, and retains unacknowledged events
|
|
283
|
+
after a partial batch response.
|
|
284
|
+
|
|
285
|
+
Use `createMobileEvent()` for app-originated events. It accepts only iOS or
|
|
286
|
+
Android platform context, a semantic app version, BCP 47 locale, IANA timezone,
|
|
287
|
+
network state, and exactly one explicit anonymous or authenticated subject.
|
|
288
|
+
The helper rejects unknown context fields and credential-shaped payload fields
|
|
289
|
+
such as producer secrets, client secrets, or reporting tokens. Mobile apps send
|
|
290
|
+
these allowlisted event envelopes to an application-authenticated relay; they
|
|
291
|
+
must not contain Custd producer credentials or reporting-read credentials.
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import { AppState } from "react-native";
|
|
295
|
+
import NetInfo from "@react-native-community/netinfo";
|
|
296
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
297
|
+
import {
|
|
298
|
+
AsyncEventQueue,
|
|
299
|
+
createMobileAsyncQueueStorage,
|
|
300
|
+
createMobileFlushTriggers,
|
|
301
|
+
} from "@haakco/custd-sdk";
|
|
302
|
+
|
|
303
|
+
const queue = new AsyncEventQueue(
|
|
304
|
+
createMobileAsyncQueueStorage(AsyncStorage, "custd.mobile.events"),
|
|
305
|
+
1_000,
|
|
306
|
+
);
|
|
307
|
+
await queue.load();
|
|
308
|
+
|
|
309
|
+
const removeLifecycleTriggers = createMobileFlushTriggers({
|
|
310
|
+
appState: AppState,
|
|
311
|
+
network: NetInfo,
|
|
312
|
+
})(async () => {
|
|
313
|
+
// Send a bounded `await queue.peek(limit)` batch to the authenticated
|
|
314
|
+
// application relay. Acknowledge only event UUIDs accepted by that relay.
|
|
315
|
+
const events = await queue.peek(50);
|
|
316
|
+
const acceptedIDs = await sendEventsToApplicationRelay(events);
|
|
317
|
+
await queue.acknowledge(acceptedIDs);
|
|
318
|
+
});
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Call `removeLifecycleTriggers()` during application shutdown. A manual flush
|
|
322
|
+
uses the same bounded relay path; do not call a Custd producer endpoint from
|
|
323
|
+
the app or persist credentials alongside queued events.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
const events = await queue.peek(50);
|
|
327
|
+
await queue.acknowledge(await sendEventsToApplicationRelay(events));
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Dev smoke test (Hydra)
|
|
331
|
+
|
|
332
|
+
Requires dev stack running with Hydra using JWT access tokens and ingest-api configured with `AUTH_JWKS_URL`.
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
export AUTH_JWKS_URL="http://localhost:4444/.well-known/jwks.json"
|
|
336
|
+
cd sdk-js
|
|
337
|
+
pnpm run smoke:dev
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The smoke test uses `scripts/dev-hydra-token.sh` and `scripts/dev-seed-core.sh` to create a dev OAuth client and seed core tables (company, device type, event type, schema).
|
|
341
|
+
|
|
342
|
+
To run all SDK checks, use `mise exec -- just check` from the repository root.
|
|
343
|
+
|
|
344
|
+
## Lifecycle administration
|
|
345
|
+
|
|
346
|
+
The TypeScript SDK exposes typed admin clients for the five lifecycle
|
|
347
|
+
namespaces. Forward-only: no deprecated aliases.
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
const admin = client.admin();
|
|
351
|
+
|
|
352
|
+
// Tenant storage: list/get/create/revoke.
|
|
353
|
+
const loc = await admin.tenantStorage.create({
|
|
354
|
+
tenantSlug: "acme",
|
|
355
|
+
clientLocation: "s3://acme-prod-warehouse/events/",
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// Subject exports: full request lifecycle.
|
|
359
|
+
const exp = await admin.subjectExports.create({
|
|
360
|
+
tenantSlug: "acme",
|
|
361
|
+
subject: { type: "userUuid", value: "01J5..." },
|
|
362
|
+
scope: "portability",
|
|
363
|
+
idempotencyKey: "acme-2026-07-31",
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// Physical erasures: NO cancel/retry.
|
|
367
|
+
const force = await admin.privacyErasures.force("pe_01J5...");
|
|
368
|
+
|
|
369
|
+
// Retention policies: list/get/upsert/delete + preview/apply/listRuns.
|
|
370
|
+
const runs = await admin.retention.listRuns("acme");
|
|
371
|
+
|
|
372
|
+
// Offboarding: full request lifecycle + schedules.
|
|
373
|
+
const sched = await admin.offboarding.schedule({
|
|
374
|
+
tenantSlug: "acme",
|
|
375
|
+
effectiveAt: "2026-12-31T00:00:00Z",
|
|
376
|
+
gracePeriodDays: 30,
|
|
377
|
+
reason: "contract_end",
|
|
378
|
+
status: "scheduled",
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const request = await admin.offboarding.requestOffboarding(
|
|
382
|
+
{ confirmation: "acme" },
|
|
383
|
+
{ idempotencyKey: "acme-offboarding-2026-12-31" },
|
|
384
|
+
);
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## Time-plan administration
|
|
388
|
+
|
|
389
|
+
`client.admin.timePlans` exposes typed `TimePlan*` types for plan
|
|
390
|
+
drafts/revisions, previews, publication and retirement, runs, commands,
|
|
391
|
+
history, and annotation correction/redaction. Every call takes a company slug;
|
|
392
|
+
the server remains authoritative for allocations and command results.
|
|
393
|
+
|
|
394
|
+
```ts
|
|
395
|
+
import { type TimePlanDefinition } from "@haakco/custd-sdk";
|
|
396
|
+
|
|
397
|
+
const definition: TimePlanDefinition = {
|
|
398
|
+
horizonMs: 60_000,
|
|
399
|
+
blocks: [{ uuid: "block-1", semanticKey: "focus", title: "Focus", basis: "absolute" }],
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const preview = await client.admin.timePlans.preview("acme", definition);
|
|
403
|
+
const plan = await client.admin.timePlans.create("acme", {
|
|
404
|
+
planKey: "focus",
|
|
405
|
+
name: "Focus",
|
|
406
|
+
definition,
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
The typed clients are available in `v1.8.25` and later.
|
|
411
|
+
|
|
412
|
+
SDKs never log signed URLs, raw personal data, export bytes, or
|
|
413
|
+
subject identifiers outside opaque IDs.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PackDefinition, RequestOptions } from "./index.js";
|
|
2
|
+
export type ClientSetupOAuthPurposeProfile = "ingest" | "schema" | "reporting" | "lifecycle" | "broker";
|
|
3
|
+
export type ClientSetupOAuthClientDesiredState = {
|
|
4
|
+
name?: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
purposeProfile: ClientSetupOAuthPurposeProfile;
|
|
7
|
+
};
|
|
8
|
+
export type ClientSetupSchemaDesiredState = {
|
|
9
|
+
eventTypeSlug: string;
|
|
10
|
+
version: string;
|
|
11
|
+
schemaJson: Record<string, unknown>;
|
|
12
|
+
dialect?: "jsonschema" | "avro";
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ClientSetupPrivacyRule = {
|
|
16
|
+
fieldPath: string;
|
|
17
|
+
action: string;
|
|
18
|
+
truncateLength?: number;
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type ClientSetupPrivacyDesiredState = {
|
|
22
|
+
applyMode?: string;
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
rules?: ClientSetupPrivacyRule[];
|
|
25
|
+
};
|
|
26
|
+
export type ClientSetupRetentionDesiredState = {
|
|
27
|
+
maxAgeDays: number;
|
|
28
|
+
classes: string[];
|
|
29
|
+
};
|
|
30
|
+
export type ClientSetupReportingPackDesiredState = {
|
|
31
|
+
definition: PackDefinition;
|
|
32
|
+
expectedRevision?: number;
|
|
33
|
+
};
|
|
34
|
+
export type ClientSetupManifest = {
|
|
35
|
+
schemas?: ClientSetupSchemaDesiredState[];
|
|
36
|
+
privacy?: ClientSetupPrivacyDesiredState;
|
|
37
|
+
retention?: ClientSetupRetentionDesiredState;
|
|
38
|
+
reportingPacks?: ClientSetupReportingPackDesiredState[];
|
|
39
|
+
oauthClients?: ClientSetupOAuthClientDesiredState[];
|
|
40
|
+
};
|
|
41
|
+
export type ClientSetupResourceStatus = {
|
|
42
|
+
kind: string;
|
|
43
|
+
key: string;
|
|
44
|
+
state: string;
|
|
45
|
+
ready: boolean;
|
|
46
|
+
safeNextAction: string;
|
|
47
|
+
safeNextActionCode: string;
|
|
48
|
+
};
|
|
49
|
+
export type ClientSetupOperationStatus = {
|
|
50
|
+
uuid: string;
|
|
51
|
+
idempotencyKey: string;
|
|
52
|
+
state: string;
|
|
53
|
+
errorCode?: string;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
completedAt?: string;
|
|
57
|
+
};
|
|
58
|
+
export type ClientSetupApplyResponse = {
|
|
59
|
+
tenantSlug: string;
|
|
60
|
+
manifestDigest: string;
|
|
61
|
+
ready: boolean;
|
|
62
|
+
state: string;
|
|
63
|
+
resources: ClientSetupResourceStatus[];
|
|
64
|
+
safeNextAction: string;
|
|
65
|
+
safeNextActionCode: string;
|
|
66
|
+
observedAt: string;
|
|
67
|
+
operation?: ClientSetupOperationStatus;
|
|
68
|
+
};
|
|
69
|
+
export type ClientSetupReadinessResponse = {
|
|
70
|
+
tenantSlug: string;
|
|
71
|
+
manifestDigest: string;
|
|
72
|
+
ready: boolean;
|
|
73
|
+
state: string;
|
|
74
|
+
resources: ClientSetupResourceStatus[];
|
|
75
|
+
safeNextAction: string;
|
|
76
|
+
safeNextActionCode: string;
|
|
77
|
+
observedAt: string;
|
|
78
|
+
operation?: ClientSetupOperationStatus;
|
|
79
|
+
};
|
|
80
|
+
export type ClientSetupApplyOptions = RequestOptions & {
|
|
81
|
+
idempotencyKey: string;
|
|
82
|
+
};
|
|
83
|
+
export type ClientSetupApplyAndWaitOptions = ClientSetupApplyOptions & {
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
intervalMs?: number;
|
|
86
|
+
};
|
|
87
|
+
export type ClientSetupApplyAndWaitResult = {
|
|
88
|
+
apply: ClientSetupApplyResponse;
|
|
89
|
+
readiness: ClientSetupReadinessResponse;
|
|
90
|
+
};
|
|
91
|
+
export declare function validateClientSetupManifest(manifest: ClientSetupManifest): void;
|
|
92
|
+
type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
|
|
93
|
+
export declare class ClientSetupClient {
|
|
94
|
+
private readonly request;
|
|
95
|
+
constructor(request: AdminRequester);
|
|
96
|
+
apply(tenantSlug: string, manifest: ClientSetupManifest, options: ClientSetupApplyOptions): Promise<ClientSetupApplyResponse>;
|
|
97
|
+
readiness(tenantSlug: string, options?: RequestOptions): Promise<ClientSetupReadinessResponse>;
|
|
98
|
+
applyAndWait(tenantSlug: string, manifest: ClientSetupManifest, options: ClientSetupApplyAndWaitOptions): Promise<ClientSetupApplyAndWaitResult>;
|
|
99
|
+
}
|
|
100
|
+
export {};
|