@kennra/app-sdk 0.1.0 → 0.2.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.
@@ -7,7 +7,7 @@ export type Lane = 'live' | 'import';
7
7
  export interface TokenRequest {
8
8
  /**
9
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,
10
+ * for the member whose Kennra token is `subject_token` (manifest `access.actsForMembers`), or,
11
11
  * for a private app with delegation, for the member named in `requested_subject`.
12
12
  */
13
13
  grant_type: 'client_credentials' | 'urn:ietf:params:oauth:grant-type:token-exchange';
@@ -50,7 +50,7 @@ export interface InstallationInfo {
50
50
  status: 'active' | 'paused' | 'suspended' | 'uninstalled';
51
51
  settings: Record<string, unknown>;
52
52
  /**
53
- * The app's secrets (e.g. an API key, employees' refresh tokens). Only when asked for
53
+ * The app's secrets (e.g. an API key, members' refresh tokens). Only when asked for
54
54
  * (`GET /apps/installation?include=secrets`); empty otherwise.
55
55
  */
56
56
  secrets: Record<string, string>;
@@ -113,10 +113,18 @@ export type IngestItem = {
113
113
  familyName?: string;
114
114
  legalName?: string;
115
115
  createIfMissing?: boolean;
116
- /** A person who is a contact at the company with this identifier (role, default `user`). */
116
+ /**
117
+ * A person who is a contact at a company (role, default `user`): the company with this
118
+ * identifier, or the company that has this business domain (e.g. the part after `@` of
119
+ * the person's address). Consumer mail domains and unknown domains attach nothing; no
120
+ * company is created.
121
+ */
117
122
  memberOf?: {
118
123
  identifier: IdentifierInput;
119
124
  role?: string;
125
+ } | {
126
+ domain: string;
127
+ role?: string;
120
128
  };
121
129
  };
122
130
  } | {
@@ -191,7 +199,49 @@ export type ConsentChangeInput = PersonRef & {
191
199
  occurredAt: string;
192
200
  /** For `granted`: the notice the person accepted (`notice:<name>@v<n>`); default `notice:app-<appId>@v1`. */
193
201
  noticeRef?: string;
202
+ /**
203
+ * A change from before Kennra knew the person (decision 21 November 2026, docs/15 §4.10): a
204
+ * list moved from another sending tool. `occurredAt` may then be older than 30 days.
205
+ * - a historical `granted` needs `kennra:consent:import` for the purpose (else `SCOPE_REQUIRED`)
206
+ * and `evidence` (else `EVIDENCE_REQUIRED`), and is refused when Kennra has a newer
207
+ * withdrawal for the purpose and channel (`NEWER_WITHDRAWAL_WINS`);
208
+ * - a historical `withdrawn` or `suppressed` only narrows, so it needs no more than
209
+ * `kennra:consent:write`.
210
+ * Idempotent per person, purpose, channel and `externalRef` (send the provider's own record id).
211
+ */
212
+ historical?: boolean;
213
+ /** The proof of a historical opt-in. Required for a historical `granted`. */
214
+ evidence?: ConsentEvidence;
194
215
  };
216
+ /**
217
+ * The proof of an opt-in that happened in another tool (decision 21 November 2026). `provider` and
218
+ * at least one of `ipAddress`, `source` / `form` / `url`, `confirmedAt` or `providerRecordId`.
219
+ * `occurredAt` on the change is the opt-in time (for double opt-in, the confirmation). Kennra keeps
220
+ * the evidence with the consent event: IP addresses encrypted with the person's key (gone when
221
+ * the person is erased), a URL without its query string, and returns it in a data subject export.
222
+ */
223
+ export interface ConsentEvidence {
224
+ /** The tool the opt-in happened in, as a display name (e.g. the sending tool's name). */
225
+ provider: string;
226
+ /** The provider's own id of the subscriber or opt-in record. */
227
+ providerRecordId?: string;
228
+ /** The IP address the opt-in came from. */
229
+ ipAddress?: string;
230
+ /** How the person signed up in the provider (e.g. `form`, `api`, `import`, `checkout`). */
231
+ source?: string;
232
+ /** The name of the signup form. */
233
+ form?: string;
234
+ /** The page the signup form was on (stored without query string or fragment). */
235
+ url?: string;
236
+ /** When the person submitted the signup (before a double opt-in confirmation). */
237
+ signupAt?: string;
238
+ /** The IP address of the signup, when it differs from the opt-in. */
239
+ signupIpAddress?: string;
240
+ /** When the person confirmed a double opt-in. */
241
+ confirmedAt?: string;
242
+ /** The text or version of the consent the person accepted in the provider, if known. */
243
+ consentText?: string;
244
+ }
195
245
  /** One of `ENGAGEMENT_SIGNALS` (manifest.ts). */
196
246
  export type EngagementSignal = 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | 'unsubscribed';
197
247
  /**
@@ -215,13 +265,13 @@ export type EngagementSignalInput = PersonRef & {
215
265
  };
216
266
  /**
217
267
  * 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,
268
+ * (docs/15 §9.3): the member must have connected, private and internal items are skipped,
219
269
  * only items with known external people or companies are kept, the text is summarized and dropped.
220
270
  */
221
271
  export interface CaptureInput {
222
- /** The employee whose calendar or mailbox it came from (their Kennra user id). */
272
+ /** The member whose calendar or mailbox it came from (their Kennra user id). */
223
273
  userId: string;
224
- /** The employee's connection in this installation (as reported with reportUserConnection). */
274
+ /** The member's connection in this installation (as reported with reportUserConnection). */
225
275
  connectionKey: string;
226
276
  sourceRef: string;
227
277
  sourceVersion: number;
@@ -270,8 +320,8 @@ export interface TranscriptTurn {
270
320
  }
271
321
  /**
272
322
  * `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
323
+ * captured with `captureInteraction` (the same member's `interactionSourceRef`). The core
324
+ * decides: the member must have connected (`userId` + `connectionKey`), the meeting must be a
275
325
  * captured, not cancelled interaction they own. It summarizes the transcript with its own LLM
276
326
  * gateway (summary, decisions, next steps), writes the summary as a note marked aiGenerated on the
277
327
  * interaction and its companies, people and deals, and suggests a task per next step (never
@@ -280,7 +330,7 @@ export interface TranscriptTurn {
280
330
  */
281
331
  export interface MeetingNotesCapture {
282
332
  userId: string;
283
- /** The employee's transcripts connection in this installation (reportUserConnection). */
333
+ /** The member's transcripts connection in this installation (reportUserConnection). */
284
334
  connectionKey: string;
285
335
  /** The `sourceRef` the meeting was captured with (`captureInteraction`). */
286
336
  interactionSourceRef: string;
@@ -380,8 +430,15 @@ export interface CaptureBackfillRequest {
380
430
  */
381
431
  export interface CaptureBackfillReport {
382
432
  backfillId: string;
383
- status: 'running' | 'done' | 'failed';
433
+ /**
434
+ * `running`: the app is working on it. `partial`: the app did what it could for now and the rest
435
+ * waits for the provider (say which in `waiting`); it goes on by itself on later runs, so Kennra
436
+ * keeps serving the request. `done` and `failed` are final.
437
+ */
438
+ status: 'running' | 'partial' | 'done' | 'failed';
384
439
  counters?: Record<string, number>;
440
+ /** What is still waiting for the provider (a rate limit): meetings, emails or both. */
441
+ waiting?: ('meetings' | 'emails')[];
385
442
  /** How far back the app looks (ISO time). */
386
443
  since?: string;
387
444
  error?: string;
@@ -420,6 +477,13 @@ export interface UserConnectionReport {
420
477
  status: 'connected' | 'revoked' | 'error';
421
478
  shareLevel?: 'private' | 'metadata' | 'summary' | 'full';
422
479
  error?: string;
480
+ /**
481
+ * The member's profile photo at the provider (for example the `picture` claim of the ID token
482
+ * the connection already returned; never a new scope for it). https on a host in the app's
483
+ * `capabilities.ui.domains`: Kennra fetches it once with the image proxy's rules, keeps a scaled
484
+ * copy and shows it as the member's avatar. Ignored unless `status` is `connected`.
485
+ */
486
+ photoUrl?: string;
423
487
  }
424
488
  /**
425
489
  * `POST /apps/installation/setup`: the app finished its own setup flow (`capabilities.setup`)
@@ -438,7 +502,7 @@ export interface SetupReport {
438
502
  settings?: Record<string, unknown>;
439
503
  }
440
504
  /**
441
- * An employee disconnected in Kennra (`userConnections[].disconnectUrl`): revoke the token at the
505
+ * A member disconnected in Kennra (`userConnections[].disconnectUrl`): revoke the token at the
442
506
  * provider and delete it. The core has already stopped capture for the connection.
443
507
  */
444
508
  export interface DisconnectRequest {
@@ -448,7 +512,7 @@ export interface DisconnectRequest {
448
512
  userId: string;
449
513
  connectionKey: string;
450
514
  kind: string;
451
- /** Why: the employee disconnected (default), or the app is being uninstalled (revoke everything). */
515
+ /** Why: the member disconnected (default), or the app is being uninstalled (revoke everything). */
452
516
  reason?: 'user' | 'app_uninstalled';
453
517
  }
454
518
  export interface LifecycleEvent {
@@ -482,7 +546,7 @@ export interface LookupRequest {
482
546
  type: string;
483
547
  pseudonym: string;
484
548
  };
485
- /** Delegated lookups: the employee's connection the app answers with. */
549
+ /** Delegated lookups: the member's connection the app answers with. */
486
550
  onBehalfOf?: {
487
551
  userId: string;
488
552
  connectionKey: string;
@@ -717,12 +781,112 @@ export interface SubscriptionDetails {
717
781
  /** The contract in the app's own UI ("Open in <app>"): https, on the manifest's declared hosts. */
718
782
  url?: string | null;
719
783
  }
784
+ /**
785
+ * `invoice.details` (decision 21 November 2026): what an accounting app answers about an invoice
786
+ * now. Nothing of it is stored. `pdfUrl` is a short-lived link the app serves itself (https on the
787
+ * manifest's declared hosts); `url` is the invoice in the app's own UI, when there is one.
788
+ */
789
+ export interface InvoiceDetails {
790
+ lines: {
791
+ description: string | null;
792
+ sku: string | null;
793
+ quantity: number | null;
794
+ unitPrice: Money | null;
795
+ /** Percent, e.g. 25. */
796
+ vatRate?: number | null;
797
+ net: Money | null;
798
+ }[];
799
+ payments: {
800
+ date: string;
801
+ amount: Money;
802
+ method: string | null;
803
+ }[];
804
+ reminders: {
805
+ date: string;
806
+ kind: 'soft_reminder' | 'reminder' | 'notice_of_debt_collection' | 'debt_collection' | 'other';
807
+ fee?: Money | null;
808
+ }[];
809
+ /** The payment reference (KID in Norway), when the invoice has one. */
810
+ kid?: string | null;
811
+ pdfUrl?: string | null;
812
+ url?: string | null;
813
+ }
814
+ /**
815
+ * `interaction.details`: what the source shows of a captured meeting or email now, read with the
816
+ * owner's own connection (delegated) and never stored. For an email, `description` is the body as
817
+ * plain text; Kennra renders it as text, never as HTML.
818
+ */
720
819
  export interface InteractionDetails {
820
+ /** A meeting's description or agenda; an email's body as plain text. */
721
821
  description: string | null;
722
822
  location: string | null;
723
823
  conferenceUrl: string | null;
824
+ /** Deprecated: use `url`. */
724
825
  htmlLink: string | null;
725
826
  attendeeCount: number;
827
+ /** The meeting or message in the app's own UI ("Open in <app>"): https, on the manifest's declared hosts. */
828
+ url?: string | null;
829
+ /** An email's attachments: names and sizes only, never their content. */
830
+ attachments?: {
831
+ name: string;
832
+ size: number | null;
833
+ mimeType: string | null;
834
+ }[];
835
+ /** A meeting's attendees as the calendar has them now, with their responses. */
836
+ attendees?: {
837
+ name: string | null;
838
+ email: string | null;
839
+ responseStatus: 'accepted' | 'declined' | 'tentative' | 'needsAction' | null;
840
+ organizer?: boolean;
841
+ }[];
842
+ }
843
+ /**
844
+ * `document.details` (docs/15 §4.13): a document in the app's file store, live. `url` opens it in
845
+ * the app (https on the app's `ui.domains`); `thumbnailUrl` is an image Kennra shows through its
846
+ * media proxy (https on `ui.domains`) or a `data:image/…` URL; `downloadUrl` like `url`.
847
+ */
848
+ export interface DocumentDetails {
849
+ title: string;
850
+ mimeType?: string | null;
851
+ sizeBytes?: number | null;
852
+ modifiedAt?: string | null;
853
+ owner?: string | null;
854
+ url?: string | null;
855
+ thumbnailUrl?: string | null;
856
+ downloadUrl?: string | null;
857
+ }
858
+ /** One file a member picked, as the app links it (`POST /apps/documents/link`). */
859
+ export interface PickedDocument {
860
+ /** The file's id in the app (stable). */
861
+ externalId: string;
862
+ title: string;
863
+ /** The ref the app's `document.details` lookup answers. */
864
+ lookupRef?: string;
865
+ url?: string;
866
+ mimeType?: string;
867
+ sizeBytes?: number;
868
+ modifiedAt?: string;
869
+ owner?: string;
870
+ kind?: 'contract' | 'proposal' | 'other';
871
+ /** The member's connection in the app the file was picked with (delegated lookups use it). */
872
+ connectionKey?: string;
873
+ /** The document's text, in transit only: Kennra reads suggested contract terms and drops it. */
874
+ transientText?: string;
875
+ }
876
+ /** `POST /apps/documents/link`: what a member picked on the app's picker page (signed ticket). */
877
+ export interface DocumentLinkRequest {
878
+ ticket: string;
879
+ documents: PickedDocument[];
880
+ }
881
+ export interface DocumentLinkResult {
882
+ documents: {
883
+ externalId: string;
884
+ documentId: string | null;
885
+ ok: boolean;
886
+ error?: string;
887
+ }[];
888
+ /** Where to send the member back in Kennra (the record), when the ticket named it. */
889
+ returnTo?: string;
726
890
  }
727
891
  /**
728
892
  * `organization.search`: companies in a public register that match what a person typed (a name
@@ -749,6 +913,65 @@ export interface OrganizationSearchHit {
749
913
  /** `active`, or why the company no longer trades normally. */
750
914
  status: 'active' | 'bankrupt' | 'liquidation' | 'deleted';
751
915
  }
916
+ /**
917
+ * A filter value of a field's scope: one value or several (any of them matches). The keys are the
918
+ * filters the object type declares (`capabilities.objects[].scope`), e.g. `{ folder: '/machines' }`.
919
+ */
920
+ export type ExternalObjectScope = Record<string, string | string[]>;
921
+ /**
922
+ * `object.search` (the picker of an `external` field): `LookupRequest.query` is
923
+ * `{ type, text, scope, limit }` and `ref` is `<type>:<text>` with the scope, for the cache. The
924
+ * answer is at most `limit` (≤ 20) objects inside the scope, best match first. An empty `text`
925
+ * asks for the first objects in the scope.
926
+ */
927
+ export interface ExternalObjectSearchQuery {
928
+ type: string;
929
+ text: string;
930
+ scope: ExternalObjectScope;
931
+ limit: number;
932
+ }
933
+ export interface ExternalObjectSearchResult {
934
+ results: ExternalObject[];
935
+ }
936
+ /**
937
+ * `object.resolve` (live data, writes and refresh): `query` is `{ type, ids }` (at most 50 ids)
938
+ * and `ref` is `<type>:<ids, sorted, comma separated>`. The answer has the objects that exist; an
939
+ * id that is not in `objects` no longer exists at the source (Kennra shows "no longer exists" and
940
+ * keeps the value).
941
+ */
942
+ export interface ExternalObjectResolveQuery {
943
+ type: string;
944
+ ids: string[];
945
+ }
946
+ export interface ExternalObjectResolveResult {
947
+ objects: ExternalObject[];
948
+ }
949
+ /**
950
+ * An object in the app's system: the envelope every object has (`id`, `title`, and optionally
951
+ * `subtitle`, `imageUrl`, `url`), the typed fields its type declares (`fields`, others are
952
+ * dropped), and for live answers the objects it is made of (`related`, e.g. a product's variants).
953
+ * `url` must be https on the app's declared hosts; `imageUrl` too, or a `data:image/…` URL: Kennra
954
+ * never hands it to a browser as is, it serves a signed short-lived link through its media proxy.
955
+ * Keep the data minimal: product data, never personal data.
956
+ */
957
+ export interface ExternalObject {
958
+ id: string;
959
+ title: string;
960
+ subtitle?: string | null;
961
+ imageUrl?: string | null;
962
+ url?: string | null;
963
+ fields?: Record<string, unknown>;
964
+ related?: {
965
+ type: string;
966
+ items: ExternalObjectRef[];
967
+ } | null;
968
+ }
969
+ export interface ExternalObjectRef {
970
+ id: string;
971
+ title: string;
972
+ subtitle?: string | null;
973
+ imageUrl?: string | null;
974
+ }
752
975
  export interface MirroredFactLine {
753
976
  productRef?: string;
754
977
  sku?: string;
@@ -765,7 +988,7 @@ export interface MirroredFactLine {
765
988
  }
766
989
  export interface MirroredFactSnapshot {
767
990
  contract: string;
768
- factType: 'order' | 'quote' | 'subscription';
991
+ factType: 'order' | 'quote' | 'subscription' | 'invoice';
769
992
  /** Must equal the app's `capabilities.ingest.sourceSystem`. */
770
993
  sourceSystem: string;
771
994
  sourceTenant: string;
@@ -816,7 +1039,38 @@ export interface MirroredFactSnapshot {
816
1039
  startsAt?: string;
817
1040
  renewAt?: string;
818
1041
  activeUntil?: string;
1042
+ /**
1043
+ * When a cancelled contract stopped (valid time), from the best source the app has. Leave it
1044
+ * out when the source gives no date: Kennra then ends the contract at its last evidence of
1045
+ * payment, never at the time it read it.
1046
+ */
819
1047
  cancelledAt?: string;
1048
+ /**
1049
+ * How `cancelledAt` is known: `exact` (the source's cancellation date or event),
1050
+ * `activeUntil` (the end of the paid period), `lastRenewal` (last renewal order + one period),
1051
+ * `updatedAt` (the contract's last change), `unknown` (no date). Only the first two are not
1052
+ * estimates.
1053
+ */
1054
+ endDateSource?: 'exact' | 'activeUntil' | 'lastRenewal' | 'updatedAt' | 'unknown';
1055
+ };
1056
+ /**
1057
+ * Invoices and credit notes (factType `invoice`, decision 21 November 2026). `status` is one of
1058
+ * draft, sent, paid, partially_paid, overdue, credited, cancelled; amounts go in `amounts`
1059
+ * (negative for a credit note).
1060
+ */
1061
+ invoice?: {
1062
+ number: string;
1063
+ kind?: 'invoice' | 'credit_note';
1064
+ /** ISO dates (YYYY-MM-DD). */
1065
+ issueDate: string;
1066
+ dueDate?: string;
1067
+ /** Still to be paid, minor units of `amounts.currency`. */
1068
+ outstandingMinor: number;
1069
+ remindersSent?: number;
1070
+ lastReminderAt?: string;
1071
+ paidAt?: string;
1072
+ /** A credit note: the ref of the invoice it credits. */
1073
+ creditedInvoiceRef?: string;
820
1074
  };
821
1075
  }
822
1076
  /** Kennra asks an app to erase a person (docs/16 §6.2). Signed like every call to the app. */
@@ -41,6 +41,14 @@ export interface ConnectTicket {
41
41
  returnTo?: string;
42
42
  /** Setup only: also connect the admin's own account of this kind (they opted in). */
43
43
  connect?: string;
44
+ /**
45
+ * `document_pick` tickets (docs/15 §4.13): the record the member links documents to, and the
46
+ * purpose they work under. The app passes the ticket back with what was picked.
47
+ */
48
+ entityId?: string;
49
+ purpose?: string;
50
+ /** The member's connection key in the app for documents, when Kennra knows one (e.g. `drive:<address>`). */
51
+ connectionKey?: string;
44
52
  /** Unique ticket id: apps accept a ticket once (single use, review M5). Added when signing. */
45
53
  jti?: string;
46
54
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kennra/app-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Build Kennra apps: manifest types and validation, installation tokens, ingest helpers, signed lookups, schedules and webhooks, and a test harness. Web-standard Request/Response.",
5
5
  "keywords": [
6
6
  "kennra",
@@ -65,6 +65,22 @@
65
65
  "types": "./dist/hosting.d.ts",
66
66
  "default": "./dist/hosting.js"
67
67
  },
68
+ "./addresses": {
69
+ "types": "./dist/addresses.d.ts",
70
+ "default": "./dist/addresses.js"
71
+ },
72
+ "./admin-links": {
73
+ "types": "./dist/admin-links.d.ts",
74
+ "default": "./dist/admin-links.js"
75
+ },
76
+ "./capture": {
77
+ "types": "./dist/capture.d.ts",
78
+ "default": "./dist/capture.js"
79
+ },
80
+ "./capture-backfill": {
81
+ "types": "./dist/capture-backfill.d.ts",
82
+ "default": "./dist/capture-backfill.js"
83
+ },
68
84
  "./package.json": "./package.json"
69
85
  },
70
86
  "files": [