@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.
- package/README.md +2 -0
- package/dist/addresses.d.ts +12 -0
- package/dist/addresses.js +105 -0
- package/dist/admin-links.d.ts +17 -0
- package/dist/admin-links.js +22 -0
- package/dist/app.d.ts +1 -1
- package/dist/app.js +1 -1
- package/dist/capture-backfill.d.ts +95 -0
- package/dist/capture-backfill.js +198 -0
- package/dist/capture.d.ts +110 -0
- package/dist/capture.js +321 -0
- package/dist/client.d.ts +14 -3
- package/dist/client.js +41 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/manifest.d.ts +127 -4
- package/dist/manifest.js +149 -11
- package/dist/protocol.d.ts +268 -14
- package/dist/signature.d.ts +8 -0
- package/package.json +17 -1
package/dist/manifest.js
CHANGED
|
@@ -40,6 +40,10 @@ export const APP_SCOPES = [
|
|
|
40
40
|
// Engagement signals (delivered, opened, clicked …) a sending tool reports per person, kept by
|
|
41
41
|
// the core as aggregates per person and channel, never one record per message.
|
|
42
42
|
'kennra:engagement:write',
|
|
43
|
+
// Historical consent with evidence (decision 21 November 2026): moving a list from another
|
|
44
|
+
// sending tool brings opt-ins older than 30 days. Only with this scope (per purpose), only with
|
|
45
|
+
// evidence of the opt-in, never over a newer withdrawal, capped per installation and day.
|
|
46
|
+
'kennra:consent:import',
|
|
43
47
|
];
|
|
44
48
|
/** The scope that lets an app pass on a member's decision on a suggestion (21 November 2026). */
|
|
45
49
|
export const SUGGESTIONS_DECIDE_SCOPE = 'kennra:suggestions:decide';
|
|
@@ -49,9 +53,15 @@ export const SENSITIVE_SCOPES = [
|
|
|
49
53
|
'kennra:export',
|
|
50
54
|
SUGGESTIONS_DECIDE_SCOPE,
|
|
51
55
|
'kennra:consent:grant',
|
|
56
|
+
'kennra:consent:import',
|
|
52
57
|
];
|
|
53
58
|
/** The scope that lets an app record consent a person gave in it (decision 21 November 2026). */
|
|
54
59
|
export const CONSENT_GRANT_SCOPE = 'kennra:consent:grant';
|
|
60
|
+
/**
|
|
61
|
+
* The scope that lets an app import consent a person gave before Kennra knew them, with evidence
|
|
62
|
+
* (decision 21 November 2026, docs/15 §4.10). Apps only: agents and roles never hold it.
|
|
63
|
+
*/
|
|
64
|
+
export const CONSENT_IMPORT_SCOPE = 'kennra:consent:import';
|
|
55
65
|
/** The scope for engagement signals (decision 21 November 2026). */
|
|
56
66
|
export const ENGAGEMENT_WRITE_SCOPE = 'kennra:engagement:write';
|
|
57
67
|
/** Engagement signals an app can report (`recordEngagement`). */
|
|
@@ -73,6 +83,9 @@ export const TARGET_CONTACT_CHANNELS = ['email', 'sms'];
|
|
|
73
83
|
export const LOOKUP_OBJECTS = [
|
|
74
84
|
'order.details',
|
|
75
85
|
'subscription.details',
|
|
86
|
+
// An invoice from an accounting app: lines, payments, reminders and a short-lived link to the
|
|
87
|
+
// PDF the app serves from the source (decision 21 November 2026). Kennra stores none of it.
|
|
88
|
+
'invoice.details',
|
|
76
89
|
'interaction.details',
|
|
77
90
|
'organization.search',
|
|
78
91
|
// A company's public profile from a business register or similar source, by domain or registry
|
|
@@ -81,7 +94,20 @@ export const LOOKUP_OBJECTS = [
|
|
|
81
94
|
// A company's logo by domain or registry identifier (docs/15 §4.2): an https URL on the app's
|
|
82
95
|
// `ui.domains` that Kennra fetches once, scales and keeps (decision 21 November 2026).
|
|
83
96
|
'organization.logo',
|
|
97
|
+
// A document in the app's file store (docs/15 §4.13): metadata, a link, a thumbnail and a
|
|
98
|
+
// download link, live; the file itself is never stored in Kennra.
|
|
99
|
+
'document.details',
|
|
100
|
+
// A contact's profile picture by a SHA-256 hash of their email address, never the address
|
|
101
|
+
// (docs/15 §4.2). Asked only while the workspace turned on contactPhotoLookup.
|
|
102
|
+
'person.photo',
|
|
103
|
+
// External objects (`capabilities.objects`, decision 27 November 2026): a search for the picker
|
|
104
|
+
// of an `external` trait field, and the objects by id (live data and snapshot refresh). The ref
|
|
105
|
+
// is `<type>:…`; the question is in the request's `query`.
|
|
106
|
+
'object.search',
|
|
107
|
+
'object.resolve',
|
|
84
108
|
];
|
|
109
|
+
/** The envelope every external object has; typed fields can't reuse these keys. */
|
|
110
|
+
export const ENVELOPE_KEYS = ['id', 'title', 'subtitle', 'imageUrl', 'url'];
|
|
85
111
|
/** Kinds an app may declare it writes. */
|
|
86
112
|
export const WRITABLE_KINDS = [
|
|
87
113
|
'Person',
|
|
@@ -140,9 +166,54 @@ const Lookup = z.object({
|
|
|
140
166
|
timeoutMs: z.number().int().positive().max(1_000).default(300),
|
|
141
167
|
cacheTtlSeconds: z.number().int().min(0).max(3_600).default(60),
|
|
142
168
|
purposes: z.array(z.string()).min(1),
|
|
143
|
-
/** Answers with
|
|
169
|
+
/** Answers with a member's own connection (calendar, mailbox): the core decides access first. */
|
|
144
170
|
delegated: z.boolean().default(false),
|
|
145
171
|
});
|
|
172
|
+
/** The types a typed field of an external object can have (docs/15 §4.14). */
|
|
173
|
+
export const OBJECT_FIELD_TYPES = [
|
|
174
|
+
'text',
|
|
175
|
+
'number',
|
|
176
|
+
'boolean',
|
|
177
|
+
'date',
|
|
178
|
+
'money',
|
|
179
|
+
'textList',
|
|
180
|
+
'attributes',
|
|
181
|
+
];
|
|
182
|
+
/**
|
|
183
|
+
* An object type the app provides (`capabilities.objects`, decision 27 November 2026): a value of
|
|
184
|
+
* an `external` trait field points at one object of this type in the app's system. `contract` is
|
|
185
|
+
* versioned (`<app id>.<type>@<n>`): a later version that changes the meaning of a field is a new
|
|
186
|
+
* contract. `fields` are the typed snapshot fields Kennra keeps next to the envelope (id, title,
|
|
187
|
+
* subtitle, image, link); `scope` the filters a field may set (pickers use them, writes are
|
|
188
|
+
* checked against them on the snapshot field they name).
|
|
189
|
+
*/
|
|
190
|
+
const ObjectType = z.object({
|
|
191
|
+
type: z.string().regex(/^[a-z][a-z0-9_]{1,39}$/),
|
|
192
|
+
contract: z.string().regex(/^[a-z][a-z0-9-]*\.[a-z][a-z0-9_]*@[1-9]\d{0,3}$/),
|
|
193
|
+
label: Localized,
|
|
194
|
+
description: Localized.optional(),
|
|
195
|
+
fields: z
|
|
196
|
+
.array(z.object({
|
|
197
|
+
key: z.string().regex(/^[a-z][A-Za-z0-9]{0,39}$/),
|
|
198
|
+
type: z.enum(OBJECT_FIELD_TYPES),
|
|
199
|
+
label: Localized,
|
|
200
|
+
description: Localized.optional(),
|
|
201
|
+
}))
|
|
202
|
+
.max(30)
|
|
203
|
+
.default([]),
|
|
204
|
+
scope: z
|
|
205
|
+
.array(z.object({
|
|
206
|
+
key: z.string().regex(/^[a-z][A-Za-z0-9]{0,39}$/),
|
|
207
|
+
label: Localized,
|
|
208
|
+
description: Localized.optional(),
|
|
209
|
+
/** The snapshot field the filter is checked on (a text or textList field). */
|
|
210
|
+
field: z.string(),
|
|
211
|
+
/** `equals`: one of the values; `prefix`: starts with one of them (a folder path). */
|
|
212
|
+
match: z.enum(['equals', 'prefix']),
|
|
213
|
+
}))
|
|
214
|
+
.max(10)
|
|
215
|
+
.default([]),
|
|
216
|
+
});
|
|
146
217
|
const Schedule = z.object({
|
|
147
218
|
id: z.string().regex(/^[a-z][a-z0-9-]{0,39}$/),
|
|
148
219
|
/** Interval like `15m`, `1h`, `1d`. Minimum 5 minutes. */
|
|
@@ -311,7 +382,9 @@ export const AppManifestSchema = z.object({
|
|
|
311
382
|
.object({
|
|
312
383
|
ingest: z
|
|
313
384
|
.object({
|
|
314
|
-
factTypes: z
|
|
385
|
+
factTypes: z
|
|
386
|
+
.array(z.enum(['ORDER', 'QUOTE', 'SUBSCRIPTION', 'INVOICE', 'INTERACTION']))
|
|
387
|
+
.default([]),
|
|
315
388
|
/** The provenance label in data, e.g. `shop`. */
|
|
316
389
|
sourceSystem: z.string().regex(/^[a-z][a-z0-9_-]{1,39}$/),
|
|
317
390
|
urn: z.string().optional(),
|
|
@@ -333,6 +406,11 @@ export const AppManifestSchema = z.object({
|
|
|
333
406
|
})
|
|
334
407
|
.optional(),
|
|
335
408
|
lookups: z.array(Lookup).default([]),
|
|
409
|
+
/**
|
|
410
|
+
* Object types the app provides for `external` trait fields (docs/15 §4.14). Needs the
|
|
411
|
+
* lookups `object.search` (the picker) and `object.resolve` (live data and refresh).
|
|
412
|
+
*/
|
|
413
|
+
objects: z.array(ObjectType).max(20).default([]),
|
|
336
414
|
schedules: z.array(Schedule).default([]),
|
|
337
415
|
webhooks: z.object({ url: Url, events: z.array(z.string()).min(1) }).optional(),
|
|
338
416
|
segmentSync: SegmentSync.optional(),
|
|
@@ -362,28 +440,28 @@ export const AppManifestSchema = z.object({
|
|
|
362
440
|
definitions: z.array(TraitDefinitionRef).default([]),
|
|
363
441
|
})
|
|
364
442
|
.optional(),
|
|
365
|
-
/** Per-
|
|
443
|
+
/** Per-member connections (calendar, mailbox): each member connects their own (docs/15 §9.3). */
|
|
366
444
|
userConnections: z
|
|
367
445
|
.array(z.object({
|
|
368
446
|
kind: z.enum(['calendar', 'mailbox', 'drive', 'transcripts']),
|
|
369
447
|
label: Localized,
|
|
370
|
-
/** Where
|
|
448
|
+
/** Where a member starts the app's own OAuth flow. */
|
|
371
449
|
connectUrl: Url,
|
|
372
450
|
/**
|
|
373
|
-
* Kennra calls this (signed POST) when
|
|
451
|
+
* Kennra calls this (signed POST) when a member disconnects in Kennra: the app
|
|
374
452
|
* revokes the token at the provider and deletes it. The core stops capture at once.
|
|
375
453
|
*/
|
|
376
454
|
disconnectUrl: Url.optional(),
|
|
377
455
|
/**
|
|
378
456
|
* A boolean setting (under `settings.schema.properties`) that must be on before
|
|
379
|
-
*
|
|
457
|
+
* members can connect this kind, e.g. an opt-in feature the admin turns on first.
|
|
380
458
|
* While it is off, Kennra doesn't offer the connection and refuses to start it.
|
|
381
459
|
*/
|
|
382
460
|
requiresSetting: z.string().optional(),
|
|
383
461
|
/**
|
|
384
|
-
* The permission the
|
|
462
|
+
* The permission the member ticks on the provider's consent screen, in the
|
|
385
463
|
* provider's words. When the provider grants less than the connection needs, Kennra
|
|
386
|
-
* asks the
|
|
464
|
+
* asks the member to connect again and tick it.
|
|
387
465
|
*/
|
|
388
466
|
consentLabel: Localized.optional(),
|
|
389
467
|
}))
|
|
@@ -409,6 +487,33 @@ export const AppManifestSchema = z.object({
|
|
|
409
487
|
connects: z.enum(['calendar', 'mailbox', 'drive', 'transcripts']).optional(),
|
|
410
488
|
})
|
|
411
489
|
.optional(),
|
|
490
|
+
/**
|
|
491
|
+
* Documents (docs/15 §4.13): the app is a file store or signing service whose files people
|
|
492
|
+
* link to records. `hosts`: the hosts of the app's file links (lowercase, no wildcards), so a
|
|
493
|
+
* link a person pastes is shown as the app's. `picker`: a page of the app's own where a member
|
|
494
|
+
* picks files (Kennra opens it with a signed ticket naming the record; the app links what was
|
|
495
|
+
* picked with `POST /apps/documents/link`). Linking needs kennra:work:write.
|
|
496
|
+
*/
|
|
497
|
+
documents: z
|
|
498
|
+
.object({
|
|
499
|
+
label: Localized,
|
|
500
|
+
hosts: z
|
|
501
|
+
.array(z.string().regex(/^[a-z0-9.-]+$/))
|
|
502
|
+
.max(20)
|
|
503
|
+
.default([]),
|
|
504
|
+
picker: z
|
|
505
|
+
.object({
|
|
506
|
+
url: Url,
|
|
507
|
+
label: Localized.optional(),
|
|
508
|
+
/**
|
|
509
|
+
* A boolean setting that must be on before Kennra offers the picker (e.g. the admin
|
|
510
|
+
* turns it on once the provider's picker is configured). Pasted links work regardless.
|
|
511
|
+
*/
|
|
512
|
+
requiresSetting: z.string().optional(),
|
|
513
|
+
})
|
|
514
|
+
.optional(),
|
|
515
|
+
})
|
|
516
|
+
.optional(),
|
|
412
517
|
/**
|
|
413
518
|
* The app is an MCP client (docs/15 §4.8): installing it lets that client connect to the
|
|
414
519
|
* workspace through Kennra's OAuth, each connection an agent acting for the person who
|
|
@@ -431,7 +536,7 @@ export const AppManifestSchema = z.object({
|
|
|
431
536
|
/** CommerceFact only: the fact types the link applies to (all when left out). */
|
|
432
537
|
when: z
|
|
433
538
|
.object({
|
|
434
|
-
factType: z.preprocess((v) => (typeof v === 'string' ? [v] : v), z.array(z.enum(['ORDER', 'QUOTE', 'SUBSCRIPTION'])).min(1)),
|
|
539
|
+
factType: z.preprocess((v) => (typeof v === 'string' ? [v] : v), z.array(z.enum(['ORDER', 'QUOTE', 'SUBSCRIPTION', 'INVOICE'])).min(1)),
|
|
435
540
|
})
|
|
436
541
|
.optional(),
|
|
437
542
|
}))
|
|
@@ -446,7 +551,7 @@ export const AppManifestSchema = z.object({
|
|
|
446
551
|
})
|
|
447
552
|
.optional(),
|
|
448
553
|
})
|
|
449
|
-
.default({ lookups: [], schedules: [], userConnections: [] }),
|
|
554
|
+
.default({ lookups: [], objects: [], schedules: [], userConnections: [] }),
|
|
450
555
|
settings: z
|
|
451
556
|
.object({
|
|
452
557
|
schema: z.object({
|
|
@@ -674,6 +779,36 @@ export function validateManifest(input) {
|
|
|
674
779
|
if (s.every && intervalMs(s.every) < 5 * 60_000)
|
|
675
780
|
p(`capabilities.schedules.${i}.every`, 'SCHEDULE_TOO_FREQUENT', 'The minimum interval is 5 minutes');
|
|
676
781
|
});
|
|
782
|
+
const objectTypes = new Set();
|
|
783
|
+
c.objects.forEach((o, i) => {
|
|
784
|
+
const path = `capabilities.objects.${i}`;
|
|
785
|
+
if (objectTypes.has(o.type))
|
|
786
|
+
p(`${path}.type`, 'DUPLICATE_OBJECT_TYPE', `${o.type} is declared twice`);
|
|
787
|
+
objectTypes.add(o.type);
|
|
788
|
+
if (!o.contract.startsWith(`${m.id}.`))
|
|
789
|
+
p(`${path}.contract`, 'CONTRACT_NOT_OWNED', `A contract is named after the app: ${m.id}.${o.type}@1`);
|
|
790
|
+
const keys = new Set();
|
|
791
|
+
o.fields.forEach((f, j) => {
|
|
792
|
+
if (keys.has(f.key) || ENVELOPE_KEYS.includes(f.key))
|
|
793
|
+
p(`${path}.fields.${j}.key`, 'DUPLICATE_FIELD', `${f.key} is declared twice or is an envelope key`);
|
|
794
|
+
keys.add(f.key);
|
|
795
|
+
});
|
|
796
|
+
const filters = new Set();
|
|
797
|
+
o.scope.forEach((f, j) => {
|
|
798
|
+
if (filters.has(f.key))
|
|
799
|
+
p(`${path}.scope.${j}.key`, 'DUPLICATE_FILTER', `${f.key} is declared twice`);
|
|
800
|
+
filters.add(f.key);
|
|
801
|
+
const field = o.fields.find((x) => x.key === f.field);
|
|
802
|
+
if (!field || (field.type !== 'text' && field.type !== 'textList'))
|
|
803
|
+
p(`${path}.scope.${j}.field`, 'UNKNOWN_FIELD', `A filter is checked on a text or textList field of the object: ${f.field} is not one`);
|
|
804
|
+
});
|
|
805
|
+
});
|
|
806
|
+
if (c.objects.length)
|
|
807
|
+
for (const object of ['object.search', 'object.resolve'])
|
|
808
|
+
if (!c.lookups.some((l) => l.object === object))
|
|
809
|
+
p('capabilities.objects', 'OBJECTS_WITHOUT_LOOKUPS', `Object types need the lookup ${object}`);
|
|
810
|
+
if (c.documents?.picker && !granted.has('kennra:work:write'))
|
|
811
|
+
p('capabilities.documents', 'DOCUMENTS_WITHOUT_SCOPE', 'Linking documents needs kennra:work:write');
|
|
677
812
|
if (c.segmentSync && !granted.has('kennra:segment:read'))
|
|
678
813
|
p('capabilities.segmentSync', 'SEGMENT_SYNC_WITHOUT_SCOPE', 'Segment sync needs kennra:segment:read');
|
|
679
814
|
const targetIds = new Set();
|
|
@@ -696,6 +831,8 @@ export function validateManifest(input) {
|
|
|
696
831
|
p('access.piiLevel', 'CONTACT_POINTS_NEED_PII', 'A target with contactPoints sends addresses, so the app needs piiLevel contact_basic or full');
|
|
697
832
|
if (granted.has(CONSENT_GRANT_SCOPE) && !granted.has('kennra:consent:write'))
|
|
698
833
|
p('access.scopes', 'CONSENT_GRANT_WITHOUT_WRITE', `${CONSENT_GRANT_SCOPE} adds grants to consent changes, so the app also asks for kennra:consent:write`);
|
|
834
|
+
if (granted.has(CONSENT_IMPORT_SCOPE) && !granted.has(CONSENT_GRANT_SCOPE))
|
|
835
|
+
p('access.scopes', 'CONSENT_IMPORT_WITHOUT_GRANT', `${CONSENT_IMPORT_SCOPE} imports earlier grants, so the app also asks for ${CONSENT_GRANT_SCOPE} and kennra:consent:write`);
|
|
699
836
|
const bf = c.ingest?.backfill;
|
|
700
837
|
if (bf) {
|
|
701
838
|
if (!granted.has('kennra:interaction:write'))
|
|
@@ -815,7 +952,7 @@ export function settingOn(m, settings, key) {
|
|
|
815
952
|
return v === true;
|
|
816
953
|
}
|
|
817
954
|
/**
|
|
818
|
-
* The `userConnections` kinds
|
|
955
|
+
* The `userConnections` kinds members can connect now: a kind with `requiresSetting` only while
|
|
819
956
|
* that setting is on.
|
|
820
957
|
*/
|
|
821
958
|
export function availableConnectionKinds(m, settings) {
|
|
@@ -828,6 +965,7 @@ export function declaredHosts(m) {
|
|
|
828
965
|
return new Set([
|
|
829
966
|
...(ui?.domains ?? []).map((d) => d.toLowerCase()),
|
|
830
967
|
...(ui?.links ?? []).map((l) => templateHost(l.url)).filter((h) => !!h),
|
|
968
|
+
...(m.capabilities.documents?.hosts ?? []).map((h) => h.toLowerCase()),
|
|
831
969
|
]);
|
|
832
970
|
}
|
|
833
971
|
/**
|