@kennra/app-sdk 0.0.0-stage → 0.1.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.
@@ -0,0 +1,851 @@
1
+ /**
2
+ * The wire contract between the Kennra core and apps (docs/15 §3–4). Types only; the core and the
3
+ * SDK both use them, so a change here is a contract change.
4
+ */
5
+ export type Lane = 'live' | 'import';
6
+ /** `POST /apps/token`: client credentials for one installation (dev; the identity provider in production). */
7
+ export interface TokenRequest {
8
+ /**
9
+ * `client_credentials`: the installation acts as itself. Token exchange (RFC 8693): the app acts
10
+ * for the employee whose Kennra token is `subject_token` (manifest `access.actsForMembers`), or,
11
+ * for a private app with delegation, for the member named in `requested_subject`.
12
+ */
13
+ grant_type: 'client_credentials' | 'urn:ietf:params:oauth:grant-type:token-exchange';
14
+ client_id: string;
15
+ client_secret: string;
16
+ installation: string;
17
+ subject_token?: string;
18
+ /**
19
+ * Delegation (private apps): the member's email or user id (`usr_…`). Kennra trusts the app's
20
+ * own sign-in; the member must be active and on the app's delegation list.
21
+ */
22
+ requested_subject?: string;
23
+ /**
24
+ * Space-separated scopes the token should carry: narrows the grant (OAuth semantics). Without
25
+ * it, the token carries the whole grant, except that a private app's `kennra:import:backdate`
26
+ * (Keep original dates) applies only when it is asked for here. Asking for a scope outside the
27
+ * grant is refused with `invalid_scope`.
28
+ */
29
+ scope?: string;
30
+ }
31
+ export interface TokenResponse {
32
+ access_token: string;
33
+ token_type: 'Bearer';
34
+ expires_in: number;
35
+ workspace: string;
36
+ installation: string;
37
+ /** The member the token acts for (token exchange and delegation). */
38
+ on_behalf_of?: string;
39
+ /** The scopes the token carries, space-separated. */
40
+ scope?: string;
41
+ }
42
+ /** `GET /apps/installation`: what the installation token may read about its installation. */
43
+ export interface InstallationInfo {
44
+ installationId: string;
45
+ workspace: string;
46
+ app: {
47
+ id: string;
48
+ version: string;
49
+ };
50
+ status: 'active' | 'paused' | 'suspended' | 'uninstalled';
51
+ settings: Record<string, unknown>;
52
+ /**
53
+ * The app's secrets (e.g. an API key, employees' refresh tokens). Only when asked for
54
+ * (`GET /apps/installation?include=secrets`); empty otherwise.
55
+ */
56
+ secrets: Record<string, string>;
57
+ /** The names of the stored secrets (always). */
58
+ secretKeys: string[];
59
+ /** Verifies requests from Kennra (Standard Webhooks). Current first, then the previous during rotation. */
60
+ signingSecrets: string[];
61
+ grant: {
62
+ scopes: {
63
+ scope: string;
64
+ purposes: string[];
65
+ }[];
66
+ piiLevel: string;
67
+ };
68
+ }
69
+ export type ExternalIdentifierInput = {
70
+ type: 'external';
71
+ issuer: string;
72
+ scheme: string;
73
+ value: string;
74
+ };
75
+ export type IdentifierInput = ExternalIdentifierInput | {
76
+ type: 'email' | 'phone';
77
+ value: string;
78
+ }
79
+ /**
80
+ * A company registration identifier: `country` ISO 3166-1 alpha-2 (omitted: NO, deprecated),
81
+ * `scheme` national (default), lei, vat, duns or ein.
82
+ */
83
+ | {
84
+ type: 'org_number';
85
+ value: string;
86
+ country?: string;
87
+ scheme?: string;
88
+ } | {
89
+ type: 'auth_subject';
90
+ issuer: string;
91
+ value: string;
92
+ };
93
+ /** One item in `POST /ingest`. Each carries one semantic command. */
94
+ export type IngestItem = {
95
+ /**
96
+ * Stable across retries and versions: `(installation, idempotencyKey)` is idempotent, per member
97
+ * for a delegated token (the app for itself and for each member have separate keys).
98
+ */
99
+ idempotencyKey: string;
100
+ /** The purpose the write is for; must be granted with the command's scope. Default: the first granted. */
101
+ purpose?: string;
102
+ /** Valid time in the world. A past time needs `kennra:import:backdate`. */
103
+ occurredAt?: string;
104
+ /** Provenance: the object in the source system. */
105
+ sourceRef?: string;
106
+ sourceTenant?: string;
107
+ } & ({
108
+ command: 'resolveIdentity';
109
+ input: {
110
+ partyType: 'person' | 'organization';
111
+ identifiers: IdentifierInput[];
112
+ givenName?: string;
113
+ familyName?: string;
114
+ legalName?: string;
115
+ createIfMissing?: boolean;
116
+ /** A person who is a contact at the company with this identifier (role, default `user`). */
117
+ memberOf?: {
118
+ identifier: IdentifierInput;
119
+ role?: string;
120
+ };
121
+ };
122
+ } | {
123
+ command: 'recordMirroredFact';
124
+ input: {
125
+ snapshot: Record<string, unknown>;
126
+ sourceVersion: number;
127
+ observedAt?: string;
128
+ };
129
+ } | {
130
+ command: 'attributeMirroredFacts';
131
+ input: {
132
+ partyId: string;
133
+ };
134
+ } | {
135
+ command: 'captureInteraction';
136
+ input: CaptureInput;
137
+ } | {
138
+ command: 'captureMeetingNotes';
139
+ input: MeetingNotesCapture;
140
+ } | {
141
+ command: 'setTraitValues';
142
+ input: {
143
+ entityId: string;
144
+ trait: string;
145
+ values: {
146
+ field: string;
147
+ value: unknown;
148
+ itemKey?: string;
149
+ }[];
150
+ };
151
+ } | {
152
+ command: 'linkIdentifier';
153
+ input: {
154
+ partyId: string;
155
+ identifier: IdentifierInput;
156
+ verified?: boolean;
157
+ };
158
+ } | {
159
+ command: 'recordConsentChange';
160
+ input: ConsentChangeInput;
161
+ } | {
162
+ command: 'recordEngagement';
163
+ input: EngagementSignalInput;
164
+ });
165
+ /** Who an app's consent change or engagement signal is about: a party id or an identifier. */
166
+ export type PersonRef = {
167
+ partyId: string;
168
+ } | {
169
+ identifier: IdentifierInput;
170
+ };
171
+ /**
172
+ * `recordConsentChange` (scope `kennra:consent:write`, purpose = the consent purpose, decision 21
173
+ * November 2026): a person changed their consent in the app (unsubscribed, resubscribed, a bounce or
174
+ * complaint the app suppressed). Rules in the core:
175
+ * - `withdrawn` and `suppressed` always apply (a suppression is recorded as a withdrawal with
176
+ * `suppression` set);
177
+ * - `granted` applies only when the grant also holds `kennra:consent:grant` for the purpose, and
178
+ * the change is newer than the latest consent event Kennra has for the purpose and channel, so it
179
+ * never overrides a newer withdrawal. Otherwise the result is `ignored` with a reason.
180
+ */
181
+ export type ConsentChangeInput = PersonRef & {
182
+ channel: 'email' | 'sms';
183
+ /** The consent purpose, e.g. `marketing.email`. Also the item's `purpose` (default). */
184
+ purpose: string;
185
+ state: 'granted' | 'withdrawn' | 'suppressed';
186
+ /** For `suppressed`: why the app stopped sending. */
187
+ suppression?: 'bounce' | 'complaint';
188
+ /** The change in the app (e.g. its webhook event id), kept as evidence. */
189
+ externalRef: string;
190
+ /** When it happened in the app (ISO 8601). Never in the future. */
191
+ occurredAt: string;
192
+ /** For `granted`: the notice the person accepted (`notice:<name>@v<n>`); default `notice:app-<appId>@v1`. */
193
+ noticeRef?: string;
194
+ };
195
+ /** One of `ENGAGEMENT_SIGNALS` (manifest.ts). */
196
+ export type EngagementSignal = 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | 'unsubscribed';
197
+ /**
198
+ * `recordEngagement` (scope `kennra:engagement:write`): one signal from a sending tool. The core
199
+ * keeps aggregates per person and channel (counts per day, last engaged, last campaign), never one
200
+ * record per message. Deduplicated by `eventId` per installation (send it as the item's
201
+ * idempotencyKey too).
202
+ */
203
+ export type EngagementSignalInput = PersonRef & {
204
+ channel: 'email' | 'sms';
205
+ signal: EngagementSignal;
206
+ /** The app's own id of the event (e.g. its webhook event id). */
207
+ eventId: string;
208
+ occurredAt: string;
209
+ /** The campaign, broadcast or flow the message belonged to. */
210
+ campaignRef?: string;
211
+ /** A display name for the campaign (no personal data). */
212
+ campaignName?: string;
213
+ /** The message in the app (not stored per message; used for dedup only). */
214
+ messageRef?: string;
215
+ };
216
+ /**
217
+ * A captured meeting or message in source-neutral form. The core decides what is stored
218
+ * (docs/15 §9.3): the employee must have connected, private and internal items are skipped,
219
+ * only items with known external people or companies are kept, the text is summarized and dropped.
220
+ */
221
+ export interface CaptureInput {
222
+ /** The employee whose calendar or mailbox it came from (their Kennra user id). */
223
+ userId: string;
224
+ /** The employee's connection in this installation (as reported with reportUserConnection). */
225
+ connectionKey: string;
226
+ sourceRef: string;
227
+ sourceVersion: number;
228
+ kind?: 'meeting' | 'video' | 'email' | 'call';
229
+ status: 'confirmed' | 'cancelled';
230
+ /** Marked private or confidential in the source: never captured (and removed if it was). */
231
+ private?: boolean;
232
+ startsAt?: string;
233
+ endsAt?: string;
234
+ subject?: string;
235
+ attendees: {
236
+ email: string;
237
+ /**
238
+ * The display name as the provider gave it (`"Kari Nordmann" <kari@…>`, a calendar attendee's
239
+ * displayName). Used only for a suggested contact the mailbox owner sees (docs/15 §9.3), never
240
+ * stored with the interaction.
241
+ */
242
+ name?: string;
243
+ responseStatus?: string;
244
+ organizer?: boolean;
245
+ self?: boolean;
246
+ resource?: boolean;
247
+ }[];
248
+ organizerEmail?: string;
249
+ organizerSelf?: boolean;
250
+ conference?: boolean;
251
+ attachmentCount?: number;
252
+ /** Description or body: summarized by the core's LLM gateway and discarded, never stored. */
253
+ transientText?: string;
254
+ /**
255
+ * The source's own id of the message or event, the same in every mailbox or calendar that has a
256
+ * copy (an email's RFC 822 `Message-ID`, a calendar event's iCalendar UID). Metadata, never
257
+ * content. The core summarizes one message once: a copy with the same id and text reuses the
258
+ * summary and costs no AI credit.
259
+ */
260
+ contentId?: string;
261
+ }
262
+ /** One spoken turn of a meeting transcript, as the source recorded it. */
263
+ export interface TranscriptTurn {
264
+ /** The speaker's name as the source shows it (masked by the core before any model sees it). */
265
+ speaker?: string;
266
+ /** The speaker's email when the app could match them to an attendee. */
267
+ speakerEmail?: string;
268
+ text: string;
269
+ startsAt?: string;
270
+ }
271
+ /**
272
+ * `captureMeetingNotes`: the transcript of a meeting that ended, for a meeting the app already
273
+ * captured with `captureInteraction` (the same employee's `interactionSourceRef`). The core
274
+ * decides: the employee must have connected (`userId` + `connectionKey`), the meeting must be a
275
+ * captured, not cancelled interaction they own. It summarizes the transcript with its own LLM
276
+ * gateway (summary, decisions, next steps), writes the summary as a note marked aiGenerated on the
277
+ * interaction and its companies, people and deals, and suggests a task per next step (never
278
+ * accepted on its own). The transcript is never stored; `transcriptUrl` (a link to it in the
279
+ * source) is.
280
+ */
281
+ export interface MeetingNotesCapture {
282
+ userId: string;
283
+ /** The employee's transcripts connection in this installation (reportUserConnection). */
284
+ connectionKey: string;
285
+ /** The `sourceRef` the meeting was captured with (`captureInteraction`). */
286
+ interactionSourceRef: string;
287
+ /** The source's own id of this recording or transcript (idempotency and the source trail). */
288
+ sourceRef: string;
289
+ /** The turns, in order. Summarized and dropped, never stored. At most 2,000 turns. */
290
+ turns: TranscriptTurn[];
291
+ /** Where people with access read the transcript in the source. Stored and shown as a link. */
292
+ transcriptUrl?: string;
293
+ /** The transcript's language (BCP 47), when the source says. */
294
+ language?: string;
295
+ endedAt?: string;
296
+ }
297
+ export interface IngestRequest {
298
+ lane?: Lane;
299
+ items: IngestItem[];
300
+ }
301
+ export interface IngestItemResult {
302
+ idempotencyKey: string;
303
+ ok: boolean;
304
+ replay?: boolean;
305
+ outcome?: string;
306
+ entityId?: string;
307
+ data?: Record<string, unknown>;
308
+ error?: {
309
+ code: string;
310
+ message: string;
311
+ problems?: {
312
+ path: string;
313
+ code: string;
314
+ message: string;
315
+ }[];
316
+ };
317
+ }
318
+ export interface IngestResponse {
319
+ batchId: string;
320
+ lane: Lane;
321
+ results: IngestItemResult[];
322
+ }
323
+ /**
324
+ * How a run ended (docs/15 §4.7). `partial`: it stopped before it was done (its maximum duration
325
+ * or the app asked it to) and saved its cursor, so the next tick goes on. `interrupted`: the app's
326
+ * host shut down (a deploy) and the run saved its cursor first. `abandoned` is set by Kennra only,
327
+ * when a run's lease ran out without a heartbeat.
328
+ */
329
+ export type SyncRunStatus = 'completed' | 'failed' | 'partial' | 'interrupted';
330
+ /**
331
+ * `POST /apps/runs`: the outcome of a schedule tick or a sync (reportSyncRun). Status `running`
332
+ * is a heartbeat: it extends the run's lease, and `counters` are its progress so far.
333
+ */
334
+ export interface SyncRunReport {
335
+ runId: string;
336
+ scheduleId?: string;
337
+ status: SyncRunStatus | 'running';
338
+ counters?: Record<string, number | Record<string, number>>;
339
+ errors?: {
340
+ stream?: string;
341
+ sourceId?: string;
342
+ message: string;
343
+ code?: string;
344
+ }[];
345
+ }
346
+ /**
347
+ * The answer to `POST /apps/runs`. `status` is the run's status in Kennra after the report:
348
+ * `abandoned` means its lease ran out, and the report was kept as information only (the run
349
+ * stays abandoned; the app should stop). `leaseExpiresAt` while it runs.
350
+ */
351
+ export interface SyncRunAck {
352
+ ok: true;
353
+ runId: string;
354
+ status: SyncRunStatus | 'running' | 'abandoned' | 'unknown';
355
+ leaseExpiresAt?: string;
356
+ }
357
+ /**
358
+ * `GET /apps/capture-backfills` (capabilities.ingest.backfill, docs/15 §9.3): a person or company
359
+ * that became known, whose history the app should look for. `emails` only when the grant's PII
360
+ * level allows contact data; `domains` are business domains only. Report on `backfillId`.
361
+ */
362
+ export interface CaptureBackfillRequest {
363
+ backfillId: string;
364
+ partyId: string;
365
+ partyType: 'person' | 'organization';
366
+ reason: string;
367
+ requestedAt: string;
368
+ emails: string[];
369
+ domains: string[];
370
+ /** What this installation reported on this request so far (a resumed run). */
371
+ progress: {
372
+ status: string;
373
+ counters: Record<string, number>;
374
+ } | null;
375
+ }
376
+ /**
377
+ * `POST /apps/capture-backfills/report`: progress on a request. `counters.meetings` and
378
+ * `counters.emails` are what members see ("found 14 meetings and 32 emails so far"): the items
379
+ * now in Kennra, captured in this run or already there.
380
+ */
381
+ export interface CaptureBackfillReport {
382
+ backfillId: string;
383
+ status: 'running' | 'done' | 'failed';
384
+ counters?: Record<string, number>;
385
+ /** How far back the app looks (ISO time). */
386
+ since?: string;
387
+ error?: string;
388
+ }
389
+ /**
390
+ * `capabilities.connectionTest`: an admin tests the settings in the form before (or without)
391
+ * saving them. `settings` are the values typed in the form; `secrets` only the secrets typed
392
+ * there (the app uses the saved ones for the rest). Nothing is stored.
393
+ */
394
+ export interface ConnectionTestRequest {
395
+ type: 'connection.test';
396
+ installationId: string;
397
+ workspace: string;
398
+ settings: Record<string, unknown>;
399
+ secrets: Record<string, string>;
400
+ }
401
+ /**
402
+ * The answer to a connection test. `code` is one of a small vendor-neutral set the admin explains
403
+ * in its own words: `ok`, `invalid_credentials`, `forbidden`, `not_found`, `unreachable`,
404
+ * `invalid_settings`, `error`. `details` are short facts to show (never secrets or personal data).
405
+ */
406
+ export interface ConnectionTestResult {
407
+ ok: boolean;
408
+ code: 'ok' | 'invalid_credentials' | 'forbidden' | 'not_found' | 'unreachable' | 'invalid_settings' | 'error';
409
+ message?: string;
410
+ details?: {
411
+ key: string;
412
+ value: string;
413
+ }[];
414
+ }
415
+ /** `POST /apps/user-connections` (reportUserConnection). */
416
+ export interface UserConnectionReport {
417
+ userId: string;
418
+ connectionKey: string;
419
+ kind: 'calendar' | 'mailbox' | 'drive' | 'transcripts';
420
+ status: 'connected' | 'revoked' | 'error';
421
+ shareLevel?: 'private' | 'metadata' | 'summary' | 'full';
422
+ error?: string;
423
+ }
424
+ /**
425
+ * `POST /apps/installation/setup`: the app finished its own setup flow (`capabilities.setup`)
426
+ * for the admin named in the setup ticket. The core verifies the ticket, records who approved
427
+ * which provider scopes and when (the consent record), and stores the settings the app detected
428
+ * (validated against the manifest; secrets never).
429
+ */
430
+ export interface SetupReport {
431
+ /** The setup ticket Kennra gave the admin (signed with the installation's secret). */
432
+ ticket: string;
433
+ /** Scopes the admin approved at the provider (e.g. OAuth scopes), for the consent record. */
434
+ externalScopes: string[];
435
+ /** The provider organization the admin signed in to (e.g. a Workspace domain). Not personal data. */
436
+ externalOrganization?: string;
437
+ /** Settings the app detected (only keys the manifest declares; never secrets). */
438
+ settings?: Record<string, unknown>;
439
+ }
440
+ /**
441
+ * An employee disconnected in Kennra (`userConnections[].disconnectUrl`): revoke the token at the
442
+ * provider and delete it. The core has already stopped capture for the connection.
443
+ */
444
+ export interface DisconnectRequest {
445
+ type: 'user_connection.disconnected';
446
+ installationId: string;
447
+ workspace: string;
448
+ userId: string;
449
+ connectionKey: string;
450
+ kind: string;
451
+ /** Why: the employee disconnected (default), or the app is being uninstalled (revoke everything). */
452
+ reason?: 'user' | 'app_uninstalled';
453
+ }
454
+ export interface LifecycleEvent {
455
+ type: 'app.installed' | 'app.updated' | 'app.paused' | 'app.resumed'
456
+ /** Sent before the uninstall, while the installation can still be read: clean up at the provider. */
457
+ | 'app.uninstalling' | 'app.uninstalled'
458
+ /** An admin saved new settings or secrets: reconnect with them. */
459
+ | 'app.settings_updated' | 'workspace.redact';
460
+ installationId: string;
461
+ workspace: string;
462
+ appId: string;
463
+ appVersion: string;
464
+ at: string;
465
+ }
466
+ export interface LookupRequest {
467
+ type: 'lookup';
468
+ object: string;
469
+ ref: string;
470
+ /**
471
+ * The structured question for objects that are looked up by attributes rather than a source ref
472
+ * (`organization.profile`: `{ domain?, identifier?: { type, country, value } }`). `ref` then
473
+ * carries the same question as a string (`domain:acme.no`, `identifier:ORG_NUMBER:NO:923609016`),
474
+ * which is what `refPattern` matches and the cache keys on.
475
+ */
476
+ query?: Record<string, unknown>;
477
+ installationId: string;
478
+ workspace: string;
479
+ purposeClass: string;
480
+ /** A stable pseudonym for the caller, never the identity. */
481
+ requestedBy: {
482
+ type: string;
483
+ pseudonym: string;
484
+ };
485
+ /** Delegated lookups: the employee's connection the app answers with. */
486
+ onBehalfOf?: {
487
+ userId: string;
488
+ connectionKey: string;
489
+ };
490
+ deadline: string;
491
+ }
492
+ export interface LookupResponse<T = unknown> {
493
+ data: T;
494
+ fetchedAt?: string;
495
+ }
496
+ export interface ScheduleTick {
497
+ type: 'schedule.tick';
498
+ scheduleId: string;
499
+ runId: string;
500
+ lane: Lane;
501
+ installationId: string;
502
+ workspace: string;
503
+ lastRunId?: string;
504
+ manual?: boolean;
505
+ /**
506
+ * The longest the run may take (the schedule's `maxRunSeconds`, default 600). The SDK aborts
507
+ * the handler's signal then; the run saves its cursor and reports `partial`.
508
+ */
509
+ maxRunSeconds?: number;
510
+ /** When the run's lease runs out unless the app sends a heartbeat (`run.heartbeat()`). */
511
+ leaseExpiresAt?: string;
512
+ }
513
+ export interface WebhookEvent {
514
+ specversion: '1.0';
515
+ id: string;
516
+ type: string;
517
+ source: string;
518
+ subject?: string;
519
+ time: string;
520
+ installationId: string;
521
+ workspace: string;
522
+ data: Record<string, unknown>;
523
+ /**
524
+ * The event type declares no personal data fields and the installation's PII level is below
525
+ * `full`: `data` is withheld (fail-closed) rather than sent unfiltered.
526
+ */
527
+ dataWithheld?: true;
528
+ /**
529
+ * A test event a person sent from Developers → Webhooks or `kennra webhooks test`: sample data,
530
+ * no recorded event behind it. Signed like real deliveries; don't act on it in production.
531
+ */
532
+ test?: true;
533
+ }
534
+ /** A member in a delta: the party id and its identifiers under the app's own issuer. */
535
+ export interface SegmentSyncMember {
536
+ partyId: string;
537
+ identifiers: {
538
+ scheme: string;
539
+ value: string;
540
+ }[];
541
+ /**
542
+ * The member's usable address on the channels the target declares (`contactPoints`), when the
543
+ * grant's PII level allows contact data. A removed member carries it too while Kennra still has it.
544
+ */
545
+ contact?: {
546
+ email?: string;
547
+ phone?: string;
548
+ };
549
+ /** The person's given name, for personalization (target with contactPoints, PII level allowing). */
550
+ givenName?: string;
551
+ familyName?: string;
552
+ }
553
+ /**
554
+ * Membership changes for one sync target. Kennra resends a delivery with the same `deliveryId`
555
+ * and `idempotencyKey` until it gets a receipt, so applying it must be idempotent.
556
+ */
557
+ export interface SegmentSyncDelta {
558
+ type: 'segment.delta';
559
+ deliveryId: string;
560
+ idempotencyKey: string;
561
+ sequence: number;
562
+ installationId: string;
563
+ workspace: string;
564
+ segment: {
565
+ id: string;
566
+ name: string;
567
+ version: number;
568
+ purpose: string;
569
+ kind: 'person' | 'organization';
570
+ };
571
+ /** `id` is the sync target (one per segment and connection); `kind` the target the manifest declares. */
572
+ target: {
573
+ id: string;
574
+ kind: string;
575
+ config: Record<string, string>;
576
+ };
577
+ added: SegmentSyncMember[];
578
+ removed: SegmentSyncMember[];
579
+ /** The target was removed (or the segment archived): this delta removes everything it held. */
580
+ final?: boolean;
581
+ }
582
+ /** The app's answer: what it applied, and members it could not place (with a reason). */
583
+ export interface SegmentSyncReceipt {
584
+ deliveryId: string;
585
+ applied: {
586
+ added: number;
587
+ removed: number;
588
+ };
589
+ skipped: {
590
+ partyId: string;
591
+ reason: string;
592
+ }[];
593
+ externalRef?: string;
594
+ }
595
+ /** An enrollment in a program delta. */
596
+ export interface ProgramTargetMember extends SegmentSyncMember {
597
+ enrollmentId: string;
598
+ /** The stage the enrollment is at now (for `left`: the stage it was at). */
599
+ stage: string;
600
+ }
601
+ /**
602
+ * Enrollments that entered the target (a new active enrollment, or one that moved into the
603
+ * target's stage), moved between stages (a target for the whole program), or left it (moved
604
+ * out, completed, dropped, unenrolled, or lost the required consent). Resent unchanged until the
605
+ * app answers with a receipt; apply it idempotently.
606
+ */
607
+ export interface ProgramTargetDelta {
608
+ type: 'program.delta';
609
+ deliveryId: string;
610
+ idempotencyKey: string;
611
+ sequence: number;
612
+ installationId: string;
613
+ workspace: string;
614
+ program: {
615
+ id: string;
616
+ name: string;
617
+ version: number;
618
+ purpose: string;
619
+ };
620
+ target: {
621
+ id: string;
622
+ kind: string;
623
+ config: Record<string, string>;
624
+ stage: string | null;
625
+ };
626
+ entered: ProgramTargetMember[];
627
+ moved: ProgramTargetMember[];
628
+ left: ProgramTargetMember[];
629
+ /** The target was removed (or the program archived): this delta lets everyone leave. */
630
+ final?: boolean;
631
+ }
632
+ export interface ProgramTargetReceipt {
633
+ deliveryId: string;
634
+ applied: {
635
+ entered: number;
636
+ moved: number;
637
+ left: number;
638
+ };
639
+ skipped: {
640
+ partyId: string;
641
+ reason: string;
642
+ }[];
643
+ externalRef?: string;
644
+ }
645
+ /**
646
+ * `kennra.consent.changed` (webhook, decision 21 November 2026): a consent change for a person the
647
+ * installation holds in a segment sync or program target. No personal data beyond the app's own
648
+ * identifiers; the app stops sending at once and the next delta removes the person.
649
+ */
650
+ export interface ConsentChangedData {
651
+ partyId: string;
652
+ purpose: string;
653
+ channels: string[];
654
+ status: 'granted' | 'withdrawn';
655
+ suppression?: 'bounce' | 'complaint';
656
+ /** The app that reported the change, when an app did. */
657
+ sourceApp?: string;
658
+ occurredAt: string;
659
+ identifiers: {
660
+ scheme: string;
661
+ value: string;
662
+ }[];
663
+ }
664
+ export interface Money {
665
+ amountMinor: number;
666
+ currency: string;
667
+ }
668
+ /**
669
+ * A booked line (a rental, a reservation): the period (ISO 8601) and the source's id of the booked
670
+ * unit, when the line names one.
671
+ */
672
+ export interface LineBooking {
673
+ start: string;
674
+ end: string;
675
+ unitId?: string | null;
676
+ }
677
+ export interface OrderDetails {
678
+ paymentStatus: string | null;
679
+ paymentProviders: string[];
680
+ lines: {
681
+ name: string | null;
682
+ sku: string | null;
683
+ quantity: number;
684
+ imageUrl: string | null;
685
+ unitPrice: Money | null;
686
+ subTotal: Money | null;
687
+ /** Set when the line books something for a period (a rental). */
688
+ booking?: LineBooking | null;
689
+ }[];
690
+ meta: {
691
+ key: string;
692
+ value: string | null;
693
+ }[];
694
+ /** The order in the app's own UI ("Open in <app>"): https, on the manifest's declared hosts. */
695
+ url?: string | null;
696
+ }
697
+ export interface SubscriptionDetails {
698
+ state: string;
699
+ renewAt: string | null;
700
+ activeUntil: string | null;
701
+ item: {
702
+ sku: string;
703
+ name: string | null;
704
+ quantity: number | null;
705
+ imageUrl: string | null;
706
+ };
707
+ phases: {
708
+ name: string;
709
+ price: Money;
710
+ period: number;
711
+ unit: string;
712
+ }[];
713
+ meta: {
714
+ key: string;
715
+ value: string | null;
716
+ }[];
717
+ /** The contract in the app's own UI ("Open in <app>"): https, on the manifest's declared hosts. */
718
+ url?: string | null;
719
+ }
720
+ export interface InteractionDetails {
721
+ description: string | null;
722
+ location: string | null;
723
+ conferenceUrl: string | null;
724
+ htmlLink: string | null;
725
+ attendeeCount: number;
726
+ }
727
+ /**
728
+ * `organization.search`: companies in a public register that match what a person typed (a name
729
+ * or an organization number), at most 10, best match first. Public register data only.
730
+ */
731
+ export interface OrganizationSearchResult {
732
+ results: OrganizationSearchHit[];
733
+ }
734
+ export interface OrganizationSearchHit {
735
+ /** The registered legal name. */
736
+ name: string;
737
+ /** The national organization number, digits only. */
738
+ orgNumber: string;
739
+ /** ISO 3166-1 alpha-2. */
740
+ country: string;
741
+ /** The legal form's code and name in the register (e.g. `AS`, `Aksjeselskap`). */
742
+ organizationFormCode: string | null;
743
+ organizationFormName: string | null;
744
+ /** The town of the business address (or the postal address). */
745
+ city: string | null;
746
+ /** The main industry code's text. */
747
+ industry: string | null;
748
+ employees: number | null;
749
+ /** `active`, or why the company no longer trades normally. */
750
+ status: 'active' | 'bankrupt' | 'liquidation' | 'deleted';
751
+ }
752
+ export interface MirroredFactLine {
753
+ productRef?: string;
754
+ sku?: string;
755
+ quantity: number;
756
+ netMinor?: number;
757
+ grossMinor?: number;
758
+ categoryPath?: string;
759
+ /** Set when the line books something for a period (a rental): the period and the unit. */
760
+ booking?: {
761
+ start: string;
762
+ end: string;
763
+ unitId?: string;
764
+ };
765
+ }
766
+ export interface MirroredFactSnapshot {
767
+ contract: string;
768
+ factType: 'order' | 'quote' | 'subscription';
769
+ /** Must equal the app's `capabilities.ingest.sourceSystem`. */
770
+ sourceSystem: string;
771
+ sourceTenant: string;
772
+ sourceId: string;
773
+ /** `{system}:{tenant}:{type}:{id}` */
774
+ ref: string;
775
+ /** The customer's id in the source (personal data for individuals; encrypted by the core). */
776
+ customerRef?: string;
777
+ customerType?: 'individual' | 'organization';
778
+ organizationRef?: string;
779
+ /** The issuer of customerRef/organizationRef: the app's registered issuer. */
780
+ identifierIssuer?: string;
781
+ customerScheme?: string;
782
+ organizationScheme?: string;
783
+ status: string;
784
+ occurredAt: string;
785
+ updatedAt?: string;
786
+ orderType?: string;
787
+ reference?: string;
788
+ channel?: string;
789
+ storeId?: string;
790
+ amounts?: {
791
+ currency: string;
792
+ netMinor?: number;
793
+ grossMinor?: number;
794
+ taxMinor?: number;
795
+ discountMinor?: number;
796
+ shippingMinor?: number;
797
+ };
798
+ lines: MirroredFactLine[];
799
+ validUntil?: string;
800
+ /** A Kennra deal id carried by a quote. */
801
+ dealRef?: string;
802
+ relatedRefs?: string[];
803
+ subscription?: {
804
+ planRef: string;
805
+ planName?: string;
806
+ periodName?: string;
807
+ sku?: string;
808
+ quantity?: number;
809
+ priceMinor: number;
810
+ currency: string;
811
+ period: number;
812
+ unit: 'day' | 'week' | 'month' | 'year';
813
+ state: 'active' | 'cancelled' | 'paused' | 'pendingActivation' | 'pendingDeactivation';
814
+ recurringMrrMinor: number;
815
+ mrrMinor: number;
816
+ startsAt?: string;
817
+ renewAt?: string;
818
+ activeUntil?: string;
819
+ cancelledAt?: string;
820
+ };
821
+ }
822
+ /** Kennra asks an app to erase a person (docs/16 §6.2). Signed like every call to the app. */
823
+ export interface ErasureRequest {
824
+ type: 'privacy.erasure_requested';
825
+ requestId: string;
826
+ installationId: string;
827
+ workspace: string;
828
+ partyId: string;
829
+ /** The person's external identifiers (e.g. the app's own customer id), sent before Kennra shreds them. */
830
+ identifiers: {
831
+ issuer: string | null;
832
+ scheme: string | null;
833
+ value: string | null;
834
+ }[];
835
+ at: string;
836
+ }
837
+ /** The app's answer: done, anonymized, not found, failed, or pending (it will report later). */
838
+ export interface ErasureReceipt {
839
+ status: 'completed' | 'anonymized' | 'not_found' | 'failed' | 'pending';
840
+ detail?: string;
841
+ }
842
+ /** A later receipt from the app (POST /apps/privacy/receipts). */
843
+ export interface ErasureReceiptReport extends ErasureReceipt {
844
+ requestId: string;
845
+ }
846
+ /**
847
+ * A `fetch`-compatible function: what Kennra clients call and what tests inject. Narrower than
848
+ * `typeof fetch`, whose runtime typings add extras (Bun's `fetch.preconnect`) that a plain
849
+ * function or a test double does not have.
850
+ */
851
+ export type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;