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