@kennra/app-sdk 0.0.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/LICENSE +21 -0
- package/README.md +50 -2
- 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 +190 -0
- package/dist/app.js +448 -0
- 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 +172 -0
- package/dist/client.js +300 -0
- package/dist/hosting.d.ts +56 -0
- package/dist/hosting.js +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +32 -0
- package/dist/manifest.d.ts +618 -0
- package/dist/manifest.js +1094 -0
- package/dist/operations.d.ts +8 -0
- package/dist/operations.js +9 -0
- package/dist/protocol.d.ts +1105 -0
- package/dist/protocol.js +5 -0
- package/dist/signature.d.ts +69 -0
- package/dist/signature.js +108 -0
- package/dist/testing.d.ts +80 -0
- package/dist/testing.js +226 -0
- package/package.json +81 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kennra AS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,52 @@
|
|
|
1
1
|
# @kennra/app-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@kennra/app-sdk)
|
|
4
|
+
|
|
5
|
+
Build apps for [Kennra](https://kennra.com), the headless customer memory. An app connects a
|
|
6
|
+
source system to Kennra through the public API: it answers live lookups, polls on a schedule,
|
|
7
|
+
reacts to webhooks and writes facts with stable idempotency keys.
|
|
8
|
+
|
|
9
|
+
The SDK uses web-standard `Request` and `Response`, so an app runs on Node, Bun, Deno, serverless
|
|
10
|
+
functions and edge runtimes.
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @kennra/app-sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What it gives you
|
|
17
|
+
|
|
18
|
+
- **Manifest:** types and a validator for `kennra-app.yaml` (`@kennra/app-sdk/manifest`).
|
|
19
|
+
- **Request verification:** checks the signature and timestamp of every call Kennra sends to your
|
|
20
|
+
app (`@kennra/app-sdk/signature`).
|
|
21
|
+
- **Client:** installation tokens, persisted GraphQL operations and batched ingest with retries.
|
|
22
|
+
- **Handlers:** `createApp({ manifest, kennra })` with `.lookup()`, `.schedule()`, `.on()` and
|
|
23
|
+
lifecycle hooks, returned as one `fetch` handler.
|
|
24
|
+
- **Testing:** `FakeKennra`, recorded HTTP fixtures and the conformance checks a listed app must
|
|
25
|
+
pass (`@kennra/app-sdk/testing`).
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { createApp } from '@kennra/app-sdk';
|
|
31
|
+
import manifest from './kennra-app.json';
|
|
32
|
+
|
|
33
|
+
const app = createApp({
|
|
34
|
+
manifest,
|
|
35
|
+
kennra: {
|
|
36
|
+
baseUrl: 'https://api.kennra.com',
|
|
37
|
+
clientId: process.env.KENNRA_CLIENT_ID!,
|
|
38
|
+
clientSecret: process.env.KENNRA_CLIENT_SECRET!,
|
|
39
|
+
},
|
|
40
|
+
}).lookup('order.details', async ({ ref }) => {
|
|
41
|
+
const order = await fetchOrder(ref);
|
|
42
|
+
return order ? { data: order } : { notFound: true };
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default { fetch: app.fetch };
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The guide and the manifest reference are at [kennra.com/docs/apps](https://kennra.com/docs/apps).
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT. See `LICENSE`. The SDK is open source; Kennra itself is proprietary.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Addresses that are not a person (decision 21 November 2026): automated senders and role
|
|
3
|
+
* addresses (shared mailboxes). Pure rules, shared by the core's suggested contacts (docs/15 §9.3)
|
|
4
|
+
* and by apps that add people from another system (a sending tool's subscribers, docs/15 §9.13),
|
|
5
|
+
* so neither invents a person called "Info" or "Noreply".
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Why an address is not a person: `automated` (no-reply, bounces, newsletters …) or `role_address`
|
|
9
|
+
* (info@, post@, support@ …), or null for an address that may be a person. The local part is read
|
|
10
|
+
* before any `+tag`, case-insensitive, with `-`, `_` and `.` ignored.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sharedMailboxReason(email: string): 'automated' | 'role_address' | null;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Addresses that are not a person (decision 21 November 2026): automated senders and role
|
|
3
|
+
* addresses (shared mailboxes). Pure rules, shared by the core's suggested contacts (docs/15 §9.3)
|
|
4
|
+
* and by apps that add people from another system (a sending tool's subscribers, docs/15 §9.13),
|
|
5
|
+
* so neither invents a person called "Info" or "Noreply".
|
|
6
|
+
*/
|
|
7
|
+
/** Automated senders: matched anywhere in the local part (`jira-noreply`, `bounces+123`). */
|
|
8
|
+
const AUTOMATED = [
|
|
9
|
+
'noreply',
|
|
10
|
+
'donotreply',
|
|
11
|
+
'dontreply',
|
|
12
|
+
'mailerdaemon',
|
|
13
|
+
'postmaster',
|
|
14
|
+
'bounce',
|
|
15
|
+
'notification',
|
|
16
|
+
'notifications',
|
|
17
|
+
'notify',
|
|
18
|
+
'newsletter',
|
|
19
|
+
'unsubscribe',
|
|
20
|
+
'autoreply',
|
|
21
|
+
'autoconfirm',
|
|
22
|
+
'daemon',
|
|
23
|
+
];
|
|
24
|
+
/** Role addresses: the whole local part (before a `+tag`) is one of these. */
|
|
25
|
+
const ROLES = new Set([
|
|
26
|
+
'abuse',
|
|
27
|
+
'accounting',
|
|
28
|
+
'accounts',
|
|
29
|
+
'admin',
|
|
30
|
+
'administrator',
|
|
31
|
+
'alert',
|
|
32
|
+
'alerts',
|
|
33
|
+
'billing',
|
|
34
|
+
'booking',
|
|
35
|
+
'bestilling',
|
|
36
|
+
'careers',
|
|
37
|
+
'contact',
|
|
38
|
+
'customerservice',
|
|
39
|
+
'dpo',
|
|
40
|
+
'faktura',
|
|
41
|
+
'firmapost',
|
|
42
|
+
'hallo',
|
|
43
|
+
'hei',
|
|
44
|
+
'hello',
|
|
45
|
+
'help',
|
|
46
|
+
'helpdesk',
|
|
47
|
+
'hostmaster',
|
|
48
|
+
'hr',
|
|
49
|
+
'info',
|
|
50
|
+
'invoice',
|
|
51
|
+
'invoices',
|
|
52
|
+
'jobb',
|
|
53
|
+
'jobs',
|
|
54
|
+
'kontakt',
|
|
55
|
+
'kontor',
|
|
56
|
+
'kundesenter',
|
|
57
|
+
'kundeservice',
|
|
58
|
+
'legal',
|
|
59
|
+
'mailer',
|
|
60
|
+
'marketing',
|
|
61
|
+
'mottak',
|
|
62
|
+
'news',
|
|
63
|
+
'office',
|
|
64
|
+
'order',
|
|
65
|
+
'orders',
|
|
66
|
+
'ordre',
|
|
67
|
+
'personvern',
|
|
68
|
+
'post',
|
|
69
|
+
'postmottak',
|
|
70
|
+
'presse',
|
|
71
|
+
'press',
|
|
72
|
+
'privacy',
|
|
73
|
+
'reception',
|
|
74
|
+
'regnskap',
|
|
75
|
+
'rekruttering',
|
|
76
|
+
'resepsjon',
|
|
77
|
+
'root',
|
|
78
|
+
'salg',
|
|
79
|
+
'sales',
|
|
80
|
+
'security',
|
|
81
|
+
'service',
|
|
82
|
+
'support',
|
|
83
|
+
'system',
|
|
84
|
+
'team',
|
|
85
|
+
'webmaster',
|
|
86
|
+
'okonomi',
|
|
87
|
+
'økonomi',
|
|
88
|
+
]);
|
|
89
|
+
/**
|
|
90
|
+
* Why an address is not a person: `automated` (no-reply, bounces, newsletters …) or `role_address`
|
|
91
|
+
* (info@, post@, support@ …), or null for an address that may be a person. The local part is read
|
|
92
|
+
* before any `+tag`, case-insensitive, with `-`, `_` and `.` ignored.
|
|
93
|
+
*/
|
|
94
|
+
export function sharedMailboxReason(email) {
|
|
95
|
+
const at = email.lastIndexOf('@');
|
|
96
|
+
if (at < 1)
|
|
97
|
+
return null;
|
|
98
|
+
const local = email.slice(0, at).toLowerCase().split('+')[0] ?? '';
|
|
99
|
+
const squashed = local.replace(/[-_.]/g, '');
|
|
100
|
+
if (AUTOMATED.some((w) => squashed.includes(w)))
|
|
101
|
+
return 'automated';
|
|
102
|
+
if (ROLES.has(squashed) || ROLES.has(local))
|
|
103
|
+
return 'role_address';
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links into Kennra's admin carry the workspace (decision 26 November 2026): every page lives
|
|
3
|
+
* under `/@<workspace identifier>/…`, e.g. `https://app.kennra.com/@fjellsport/people/p1`. A link
|
|
4
|
+
* without the prefix opens in whichever workspace the reader used last, so links Kennra and its
|
|
5
|
+
* apps build for people (MCP answers, mail, Slack, CLI) always name the workspace.
|
|
6
|
+
*
|
|
7
|
+
* Pages outside a workspace keep their plain address: `/login`, `/signup`, `/join`, `/welcome`,
|
|
8
|
+
* `/connect` and `/console`.
|
|
9
|
+
*/
|
|
10
|
+
/** The admin base of a workspace: `workspaceAdminBase('https://app.kennra.com/', 'fjellsport')` → `https://app.kennra.com/@fjellsport`. */
|
|
11
|
+
export declare function workspaceAdminBase(adminUrl: string, workspace: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* A page of the admin in a workspace: `workspaceAdminUrl('https://app.kennra.com', 'fjellsport',
|
|
14
|
+
* '/deals?deal=d1')` → `https://app.kennra.com/@fjellsport/deals?deal=d1`. Without a workspace
|
|
15
|
+
* (not known to the caller) the link has no prefix and the admin sends it to the reader's last one.
|
|
16
|
+
*/
|
|
17
|
+
export declare function workspaceAdminUrl(adminUrl: string, workspace: string | null | undefined, path: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links into Kennra's admin carry the workspace (decision 26 November 2026): every page lives
|
|
3
|
+
* under `/@<workspace identifier>/…`, e.g. `https://app.kennra.com/@fjellsport/people/p1`. A link
|
|
4
|
+
* without the prefix opens in whichever workspace the reader used last, so links Kennra and its
|
|
5
|
+
* apps build for people (MCP answers, mail, Slack, CLI) always name the workspace.
|
|
6
|
+
*
|
|
7
|
+
* Pages outside a workspace keep their plain address: `/login`, `/signup`, `/join`, `/welcome`,
|
|
8
|
+
* `/connect` and `/console`.
|
|
9
|
+
*/
|
|
10
|
+
/** The admin base of a workspace: `workspaceAdminBase('https://app.kennra.com/', 'fjellsport')` → `https://app.kennra.com/@fjellsport`. */
|
|
11
|
+
export function workspaceAdminBase(adminUrl, workspace) {
|
|
12
|
+
return `${adminUrl.replace(/\/+$/, '')}/@${encodeURIComponent(workspace)}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A page of the admin in a workspace: `workspaceAdminUrl('https://app.kennra.com', 'fjellsport',
|
|
16
|
+
* '/deals?deal=d1')` → `https://app.kennra.com/@fjellsport/deals?deal=d1`. Without a workspace
|
|
17
|
+
* (not known to the caller) the link has no prefix and the admin sends it to the reader's last one.
|
|
18
|
+
*/
|
|
19
|
+
export function workspaceAdminUrl(adminUrl, workspace, path) {
|
|
20
|
+
const p = path.startsWith('/') ? path : `/${path}`;
|
|
21
|
+
return workspace ? `${workspaceAdminBase(adminUrl, workspace)}${p}` : `${adminUrl.replace(/\/+$/, '')}${p}`;
|
|
22
|
+
}
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { type InstallationClient, KennraAppClient, type KennraClientOptions } from './client.js';
|
|
2
|
+
import { type AppManifest } from './manifest.js';
|
|
3
|
+
import type { ConnectionTestRequest, ConnectionTestResult, DisconnectRequest, ErasureReceipt, ErasureRequest, InstallationInfo, LifecycleEvent, LookupRequest, ProgramTargetDelta, ProgramTargetReceipt, ScheduleTick, SegmentSyncDelta, SegmentSyncReceipt, SyncRunReport, SyncRunStatus, WebhookEvent } from './protocol.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a handler gets: the installation, its settings and secrets, its state, a Kennra client and
|
|
6
|
+
* an abort signal. Long loops check `signal.aborted` between pages, save their cursor and return:
|
|
7
|
+
* it fires when the app stops (`app.stop()`, the host's SIGTERM) and, in a schedule handler, when
|
|
8
|
+
* the run reaches its maximum duration or Kennra abandoned it.
|
|
9
|
+
*/
|
|
10
|
+
export interface AppContext {
|
|
11
|
+
installationId: string;
|
|
12
|
+
workspace: string;
|
|
13
|
+
config: Record<string, unknown>;
|
|
14
|
+
secrets: Record<string, string>;
|
|
15
|
+
state: InstallationClient['state'];
|
|
16
|
+
kennra: InstallationClient;
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Why a run's signal fired (`signal.reason`): `max_duration` (the schedule's `maxRunSeconds`),
|
|
21
|
+
* `shutdown` (the app stops) or `abandoned` (Kennra gave the run up: its lease ran out).
|
|
22
|
+
*/
|
|
23
|
+
export type RunStopReason = 'max_duration' | 'shutdown' | 'abandoned';
|
|
24
|
+
/**
|
|
25
|
+
* The status for work whose signal fired (`partial` at its deadline, `interrupted` on shutdown),
|
|
26
|
+
* or null while it may go on. For an app's own runs outside a tick (reportRun with its own id).
|
|
27
|
+
*/
|
|
28
|
+
export declare function stoppedStatus(signal: AbortSignal): SyncRunStatus | null;
|
|
29
|
+
/** A schedule run in a handler: its lease and signal. */
|
|
30
|
+
export interface RunHandle {
|
|
31
|
+
runId: string;
|
|
32
|
+
scheduleId: string;
|
|
33
|
+
startedAt: Date;
|
|
34
|
+
/** When the run's signal fires at the latest (its maximum duration). */
|
|
35
|
+
deadline: Date;
|
|
36
|
+
/** The same signal as `ctx.signal`. */
|
|
37
|
+
signal: AbortSignal;
|
|
38
|
+
/** Why the signal fired, or null while the run may go on. */
|
|
39
|
+
readonly stopReason: RunStopReason | null;
|
|
40
|
+
/**
|
|
41
|
+
* Extends the run's lease in Kennra and records its progress so far (shown on the Apps page).
|
|
42
|
+
* The SDK also sends one every minute while the handler runs; calls closer than 5 seconds apart
|
|
43
|
+
* only keep the progress for the next one.
|
|
44
|
+
*/
|
|
45
|
+
heartbeat(progress?: Record<string, number>): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/** A run in progress in this process (the host's `/healthz`). */
|
|
48
|
+
export interface RunningJob {
|
|
49
|
+
runId: string;
|
|
50
|
+
scheduleId: string;
|
|
51
|
+
installationId: string;
|
|
52
|
+
startedAt: string;
|
|
53
|
+
lastHeartbeatAt: string | null;
|
|
54
|
+
deadline: string;
|
|
55
|
+
progress: Record<string, number> | null;
|
|
56
|
+
stopping: RunStopReason | null;
|
|
57
|
+
}
|
|
58
|
+
export type LookupResult<T> = {
|
|
59
|
+
data: T;
|
|
60
|
+
} | {
|
|
61
|
+
notFound: true;
|
|
62
|
+
} | {
|
|
63
|
+
noAccess: true;
|
|
64
|
+
};
|
|
65
|
+
export type LookupHandler = (a: {
|
|
66
|
+
req: LookupRequest;
|
|
67
|
+
ref: string;
|
|
68
|
+
ctx: AppContext;
|
|
69
|
+
}) => Promise<LookupResult<unknown>>;
|
|
70
|
+
export type ScheduleHandler = (a: {
|
|
71
|
+
tick: ScheduleTick;
|
|
72
|
+
lane: ScheduleTick['lane'];
|
|
73
|
+
ctx: AppContext;
|
|
74
|
+
run: RunHandle;
|
|
75
|
+
}) => Promise<Omit<SyncRunReport, 'runId' | 'scheduleId' | 'status'> & {
|
|
76
|
+
status?: SyncRunStatus;
|
|
77
|
+
}>;
|
|
78
|
+
export type SegmentSyncHandler = (a: {
|
|
79
|
+
delta: SegmentSyncDelta;
|
|
80
|
+
ctx: AppContext;
|
|
81
|
+
}) => Promise<Omit<SegmentSyncReceipt, 'deliveryId'>>;
|
|
82
|
+
export type ProgramTargetHandler = (a: {
|
|
83
|
+
delta: ProgramTargetDelta;
|
|
84
|
+
ctx: AppContext;
|
|
85
|
+
}) => Promise<Omit<ProgramTargetReceipt, 'deliveryId'>>;
|
|
86
|
+
export type EventHandler = (a: {
|
|
87
|
+
event: WebhookEvent;
|
|
88
|
+
ctx: AppContext;
|
|
89
|
+
}) => Promise<void>;
|
|
90
|
+
export type DisconnectHandler = (a: {
|
|
91
|
+
req: DisconnectRequest;
|
|
92
|
+
ctx: AppContext;
|
|
93
|
+
}) => Promise<void>;
|
|
94
|
+
export type LifecycleHandler = (a: {
|
|
95
|
+
event: LifecycleEvent;
|
|
96
|
+
ctx: AppContext | null;
|
|
97
|
+
}) => Promise<void>;
|
|
98
|
+
export type ErasureHandler = (a: {
|
|
99
|
+
request: ErasureRequest;
|
|
100
|
+
ctx: AppContext | null;
|
|
101
|
+
}) => Promise<ErasureReceipt>;
|
|
102
|
+
export type ConnectionTestHandler = (a: {
|
|
103
|
+
request: ConnectionTestRequest;
|
|
104
|
+
ctx: AppContext;
|
|
105
|
+
}) => Promise<ConnectionTestResult>;
|
|
106
|
+
export type RouteHandler = (req: Request, a: {
|
|
107
|
+
client: KennraAppClient;
|
|
108
|
+
manifest: AppManifest;
|
|
109
|
+
}) => Promise<Response>;
|
|
110
|
+
export interface CreateAppOptions {
|
|
111
|
+
/** The manifest: an object or YAML text, validated here (invalid manifests throw). */
|
|
112
|
+
manifest: unknown;
|
|
113
|
+
kennra: KennraClientOptions;
|
|
114
|
+
/** Run schedule handlers after answering the tick (default true), so ticks never time out. */
|
|
115
|
+
background?: boolean;
|
|
116
|
+
/** Timestamp tolerance for signatures in seconds (default 300). */
|
|
117
|
+
toleranceSeconds?: number;
|
|
118
|
+
/** How often a running schedule handler's lease is extended (default 60 s). */
|
|
119
|
+
heartbeatMs?: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A Kennra app as one web-standard `fetch` handler (Node, Bun, Deno, edge). Routes come from the
|
|
123
|
+
* manifest (lookup, schedule, webhook, lifecycle and health URLs); every request from Kennra is
|
|
124
|
+
* verified (Standard Webhooks) with the installation's signing secret before a handler runs.
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* export default createApp({ manifest, kennra: { baseUrl, clientId, clientSecret } })
|
|
128
|
+
* .lookup('order.details', async ({ ref, ctx }) => ({ data: await load(ref, ctx.secrets) }))
|
|
129
|
+
* .schedule('poll', async ({ ctx }) => ({ counters: { orders: 3 } }));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare class KennraApp {
|
|
133
|
+
private readonly opts;
|
|
134
|
+
readonly manifest: AppManifest;
|
|
135
|
+
readonly client: KennraAppClient;
|
|
136
|
+
private readonly lookups;
|
|
137
|
+
private readonly schedules;
|
|
138
|
+
private readonly events;
|
|
139
|
+
private readonly routes;
|
|
140
|
+
private readonly disconnects;
|
|
141
|
+
private lifecycleHandler;
|
|
142
|
+
private erasureHandler;
|
|
143
|
+
private segmentSyncHandler;
|
|
144
|
+
private programTargetHandler;
|
|
145
|
+
private connectionTestHandler;
|
|
146
|
+
/** Background work started by ticks (tests await it). */
|
|
147
|
+
readonly pending: Set<Promise<unknown>>;
|
|
148
|
+
/** Fires when the app stops (`stop()`): every handler's `ctx.signal` follows it. */
|
|
149
|
+
private readonly lifetime;
|
|
150
|
+
private readonly active;
|
|
151
|
+
constructor(opts: CreateAppOptions);
|
|
152
|
+
lookup(object: string, handler: LookupHandler): this;
|
|
153
|
+
schedule(id: string, handler: ScheduleHandler): this;
|
|
154
|
+
on(eventType: string, handler: EventHandler): this;
|
|
155
|
+
/** A member disconnected in Kennra (`userConnections[].disconnectUrl`): revoke and delete the token. */
|
|
156
|
+
onDisconnect(kind: string, handler: DisconnectHandler): this;
|
|
157
|
+
onLifecycle(handler: LifecycleHandler): this;
|
|
158
|
+
/** Erasure of a person (manifest `capabilities.privacy.erasure: receipt`): answer with a receipt. */
|
|
159
|
+
onErasure(handler: ErasureHandler): this;
|
|
160
|
+
/** Segment membership deltas (`capabilities.segmentSync`): apply them idempotently and answer with a receipt. */
|
|
161
|
+
segmentSync(handler: SegmentSyncHandler): this;
|
|
162
|
+
/** "Test connection" on the settings form (`capabilities.connectionTest`): try the typed settings. */
|
|
163
|
+
onConnectionTest(handler: ConnectionTestHandler): this;
|
|
164
|
+
/** Program enrollment deltas (`capabilities.programTargets`): apply them idempotently and answer with a receipt. */
|
|
165
|
+
programTarget(handler: ProgramTargetHandler): this;
|
|
166
|
+
/** An extra route the app serves itself (e.g. an OAuth callback). Not signed by Kennra. */
|
|
167
|
+
route(method: string, path: string, handler: RouteHandler): this;
|
|
168
|
+
/** The context for an installation (settings and secrets from the installation store). */
|
|
169
|
+
context(installationId: string, info?: InstallationInfo): Promise<AppContext>;
|
|
170
|
+
/** Fires when the app stops: for the app's own background work (a sync started by a connect). */
|
|
171
|
+
get signal(): AbortSignal;
|
|
172
|
+
/** True once `stop()` was called: new schedule ticks are refused (503). */
|
|
173
|
+
get stopping(): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Stops the app (graceful shutdown): new ticks get 503, and every handler's signal fires, so
|
|
176
|
+
* running work saves its cursor and reports `interrupted`. Await `idle()` after it.
|
|
177
|
+
*/
|
|
178
|
+
stop(reason?: RunStopReason): void;
|
|
179
|
+
/** The schedule runs in progress in this process, with their last heartbeat and progress. */
|
|
180
|
+
runs(): RunningJob[];
|
|
181
|
+
/** Runs one schedule tick: a lease kept alive by heartbeats, a deadline, a signal and the report. */
|
|
182
|
+
private runTick;
|
|
183
|
+
/** Verifies a request from Kennra and returns the body and the installation's context. */
|
|
184
|
+
private verified;
|
|
185
|
+
/** The fetch handler. */
|
|
186
|
+
fetch: (req: Request) => Promise<Response>;
|
|
187
|
+
/** Waits for background schedule work (tests). */
|
|
188
|
+
idle(): Promise<void>;
|
|
189
|
+
}
|
|
190
|
+
export declare function createApp(opts: CreateAppOptions): KennraApp;
|