@keemakr/event-sdk 0.2.0-dev-20261012160211
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 +41 -0
- package/dist/apps/channels.d.ts +400 -0
- package/dist/apps/channels.js +180 -0
- package/dist/apps/define.d.ts +29 -0
- package/dist/apps/define.js +41 -0
- package/dist/apps/index.d.ts +16 -0
- package/dist/apps/index.js +27 -0
- package/dist/apps/smartlead.d.ts +52 -0
- package/dist/apps/smartlead.js +45 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +576 -0
- package/package.json +59 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EventContract } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The event contracts of the Apps Core maintains, by `key@version`. An App event
|
|
4
|
+
* is a fact an outside platform reported through a Core-maintained integration.
|
|
5
|
+
* Its contract ships with Core, so it lives here in code.
|
|
6
|
+
*
|
|
7
|
+
* A Pack event is the other kind: a Pack declares it in its manifest and Pack
|
|
8
|
+
* publish registers it in the database, because a Pack can arrive at any time.
|
|
9
|
+
* It is never listed here. A new Core App adds its events to this list.
|
|
10
|
+
*
|
|
11
|
+
* The four channel families (widget, whatsapp, email, sms) and the contact and
|
|
12
|
+
* conversation families are Core's own conversation contracts: a Channel
|
|
13
|
+
* Binding delivers them to the inbound handler that subscribes to them.
|
|
14
|
+
*/
|
|
15
|
+
export declare const APP_EVENT_CONTRACTS: ReadonlyMap<string, EventContract>;
|
|
16
|
+
export { CHANNEL_MESSAGE_RECEIVED, CHANNEL_MESSAGE_SENT, contactEvents, conversationEvents, type ChannelMessageReceived, type ChannelMessageSent, type ContactVerified, type ConversationOwnerChanged, type ConversationActionRequested, } from './channels.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { contactEvents, conversationEvents, emailEvents, smsEvents, whatsappEvents, widgetEvents, } from './channels.js';
|
|
2
|
+
import { smartleadEvents } from './smartlead.js';
|
|
3
|
+
/**
|
|
4
|
+
* The event contracts of the Apps Core maintains, by `key@version`. An App event
|
|
5
|
+
* is a fact an outside platform reported through a Core-maintained integration.
|
|
6
|
+
* Its contract ships with Core, so it lives here in code.
|
|
7
|
+
*
|
|
8
|
+
* A Pack event is the other kind: a Pack declares it in its manifest and Pack
|
|
9
|
+
* publish registers it in the database, because a Pack can arrive at any time.
|
|
10
|
+
* It is never listed here. A new Core App adds its events to this list.
|
|
11
|
+
*
|
|
12
|
+
* The four channel families (widget, whatsapp, email, sms) and the contact and
|
|
13
|
+
* conversation families are Core's own conversation contracts: a Channel
|
|
14
|
+
* Binding delivers them to the inbound handler that subscribes to them.
|
|
15
|
+
*/
|
|
16
|
+
export const APP_EVENT_CONTRACTS = new Map([
|
|
17
|
+
smartleadEvents,
|
|
18
|
+
widgetEvents,
|
|
19
|
+
whatsappEvents,
|
|
20
|
+
emailEvents,
|
|
21
|
+
smsEvents,
|
|
22
|
+
contactEvents,
|
|
23
|
+
conversationEvents,
|
|
24
|
+
]
|
|
25
|
+
.flatMap((events) => Object.values(events))
|
|
26
|
+
.map((contract) => [`${contract.key}@${contract.version}`, contract]));
|
|
27
|
+
export { CHANNEL_MESSAGE_RECEIVED, CHANNEL_MESSAGE_SENT, contactEvents, conversationEvents, } from './channels.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* What Smartlead reports about one email to one lead. A reply is not here: it is
|
|
4
|
+
* a conversation message and belongs to `email.message.received`.
|
|
5
|
+
*
|
|
6
|
+
* Smartlead reports an open or a click once per email, and a mail security
|
|
7
|
+
* scanner usually takes that first click within seconds of the send. An event
|
|
8
|
+
* here is the provider's report, not proof that a person acted.
|
|
9
|
+
*/
|
|
10
|
+
declare const email: z.ZodObject<{
|
|
11
|
+
campaign_id: z.ZodString;
|
|
12
|
+
lead_id: z.ZodString;
|
|
13
|
+
email: z.ZodString;
|
|
14
|
+
occurred_at: z.ZodISODateTime;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
declare const linkClicked: z.ZodObject<{
|
|
17
|
+
campaign_id: z.ZodString;
|
|
18
|
+
lead_id: z.ZodString;
|
|
19
|
+
email: z.ZodString;
|
|
20
|
+
occurred_at: z.ZodISODateTime;
|
|
21
|
+
link_url: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export type SmartleadEmailEvent = z.infer<typeof email>;
|
|
24
|
+
export type SmartleadLinkClickedEvent = z.infer<typeof linkClicked>;
|
|
25
|
+
export declare const smartleadEvents: {
|
|
26
|
+
readonly 'email.opened': import("../index.js").EventContract<{
|
|
27
|
+
campaign_id: string;
|
|
28
|
+
lead_id: string;
|
|
29
|
+
email: string;
|
|
30
|
+
occurred_at: string;
|
|
31
|
+
}>;
|
|
32
|
+
readonly 'email.link_clicked': import("../index.js").EventContract<{
|
|
33
|
+
campaign_id: string;
|
|
34
|
+
lead_id: string;
|
|
35
|
+
email: string;
|
|
36
|
+
occurred_at: string;
|
|
37
|
+
link_url?: string | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
readonly 'email.bounced': import("../index.js").EventContract<{
|
|
40
|
+
campaign_id: string;
|
|
41
|
+
lead_id: string;
|
|
42
|
+
email: string;
|
|
43
|
+
occurred_at: string;
|
|
44
|
+
}>;
|
|
45
|
+
readonly 'lead.unsubscribed': import("../index.js").EventContract<{
|
|
46
|
+
campaign_id: string;
|
|
47
|
+
lead_id: string;
|
|
48
|
+
email: string;
|
|
49
|
+
occurred_at: string;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineAppEvents } from './define.js';
|
|
3
|
+
/**
|
|
4
|
+
* What Smartlead reports about one email to one lead. A reply is not here: it is
|
|
5
|
+
* a conversation message and belongs to `email.message.received`.
|
|
6
|
+
*
|
|
7
|
+
* Smartlead reports an open or a click once per email, and a mail security
|
|
8
|
+
* scanner usually takes that first click within seconds of the send. An event
|
|
9
|
+
* here is the provider's report, not proof that a person acted.
|
|
10
|
+
*/
|
|
11
|
+
const email = z.strictObject({
|
|
12
|
+
campaign_id: z.string().min(1),
|
|
13
|
+
lead_id: z.string().min(1),
|
|
14
|
+
// A natural person's address: every event below is personal data.
|
|
15
|
+
email: z.string().min(1),
|
|
16
|
+
occurred_at: z.iso.datetime(),
|
|
17
|
+
});
|
|
18
|
+
const linkClicked = email.extend({ link_url: z.string().min(1).optional() });
|
|
19
|
+
const common = {
|
|
20
|
+
version: 1,
|
|
21
|
+
sensitivity: 'personal',
|
|
22
|
+
subject: ['campaign_id', 'lead_id'],
|
|
23
|
+
};
|
|
24
|
+
export const smartleadEvents = defineAppEvents('smartlead', {
|
|
25
|
+
'email.opened': {
|
|
26
|
+
...common,
|
|
27
|
+
description: 'Smartlead reported that a lead opened an email.',
|
|
28
|
+
schema: email,
|
|
29
|
+
},
|
|
30
|
+
'email.link_clicked': {
|
|
31
|
+
...common,
|
|
32
|
+
description: 'Smartlead reported that a tracked link in an email was clicked.',
|
|
33
|
+
schema: linkClicked,
|
|
34
|
+
},
|
|
35
|
+
'email.bounced': {
|
|
36
|
+
...common,
|
|
37
|
+
description: 'Smartlead reported that an email bounced.',
|
|
38
|
+
schema: email,
|
|
39
|
+
},
|
|
40
|
+
'lead.unsubscribed': {
|
|
41
|
+
...common,
|
|
42
|
+
description: 'Smartlead reported that a lead unsubscribed.',
|
|
43
|
+
schema: email,
|
|
44
|
+
},
|
|
45
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type JsonSchema = Record<string, unknown>;
|
|
3
|
+
export type EventSensitivity = 'none' | 'personal' | 'phi';
|
|
4
|
+
export interface EventDefinitionInput {
|
|
5
|
+
owner: string;
|
|
6
|
+
key: string;
|
|
7
|
+
version: number;
|
|
8
|
+
description: string;
|
|
9
|
+
payloadSchema: JsonSchema;
|
|
10
|
+
sensitivity?: EventSensitivity;
|
|
11
|
+
subjects?: {
|
|
12
|
+
primary: readonly string[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface EventContract<P = unknown> {
|
|
16
|
+
readonly owner: string;
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly version: number;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
readonly payloadSchema: Readonly<JsonSchema>;
|
|
21
|
+
readonly sensitivity: EventSensitivity;
|
|
22
|
+
readonly subjects?: {
|
|
23
|
+
readonly primary: readonly string[];
|
|
24
|
+
};
|
|
25
|
+
readonly fingerprint: string;
|
|
26
|
+
validate(value: unknown): P;
|
|
27
|
+
}
|
|
28
|
+
export interface EventContractArtifact {
|
|
29
|
+
owner: string;
|
|
30
|
+
event_key: string;
|
|
31
|
+
version: number;
|
|
32
|
+
description: string;
|
|
33
|
+
payload_schema: JsonSchema;
|
|
34
|
+
primary_subject_fields: string[];
|
|
35
|
+
sensitivity: EventSensitivity;
|
|
36
|
+
fingerprint: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fetch a contract-only build artifact with a short-lived tenant access token.
|
|
40
|
+
* The exact release pin is checked before the artifact reaches build tooling.
|
|
41
|
+
*/
|
|
42
|
+
export declare function fetchEventContractArtifact(input: {
|
|
43
|
+
coreUrl: string;
|
|
44
|
+
accessToken: string;
|
|
45
|
+
owner: string;
|
|
46
|
+
key: string;
|
|
47
|
+
version: number;
|
|
48
|
+
fingerprint: string;
|
|
49
|
+
fetch?: typeof fetch;
|
|
50
|
+
}): Promise<EventContractArtifact>;
|
|
51
|
+
export declare function canonicalEventJson(value: unknown): string;
|
|
52
|
+
export declare function eventPrimarySubject(payload: unknown, fields: readonly string[]): string | null;
|
|
53
|
+
export declare function defineEvent<P = Record<string, unknown>>(input: EventDefinitionInput): EventContract<P>;
|
|
54
|
+
export declare function eventContractFingerprint(identity: {
|
|
55
|
+
owner: string;
|
|
56
|
+
key: string;
|
|
57
|
+
version: number;
|
|
58
|
+
description: string;
|
|
59
|
+
payloadSchema: JsonSchema;
|
|
60
|
+
sensitivity: EventSensitivity;
|
|
61
|
+
subjects?: {
|
|
62
|
+
primary: readonly string[];
|
|
63
|
+
};
|
|
64
|
+
}): string;
|
|
65
|
+
export interface EventEnvelope<P = unknown> {
|
|
66
|
+
id: string;
|
|
67
|
+
owner: string;
|
|
68
|
+
key: string;
|
|
69
|
+
version: number;
|
|
70
|
+
fingerprint: string;
|
|
71
|
+
payloadDigest: string;
|
|
72
|
+
tenantId: string;
|
|
73
|
+
correlationId: string;
|
|
74
|
+
causation: {
|
|
75
|
+
rootEventId: string;
|
|
76
|
+
parentEventId: string | null;
|
|
77
|
+
};
|
|
78
|
+
payload: P;
|
|
79
|
+
}
|
|
80
|
+
export interface EventDelivery<P = unknown> {
|
|
81
|
+
deliveryId: string;
|
|
82
|
+
attemptNumber: number;
|
|
83
|
+
bindingId?: string;
|
|
84
|
+
consumer?: {
|
|
85
|
+
installId: string;
|
|
86
|
+
packVersion: number;
|
|
87
|
+
deploymentRevision: string;
|
|
88
|
+
};
|
|
89
|
+
handlerId: string;
|
|
90
|
+
event: EventEnvelope<P>;
|
|
91
|
+
}
|
|
92
|
+
/** What core posts to a Pack's `/events/v1/deliver`: a delivery with its binding and consumer named. */
|
|
93
|
+
export type EventDeliveryEnvelope<P = unknown> = EventDelivery<P> & {
|
|
94
|
+
bindingId: string;
|
|
95
|
+
consumer: NonNullable<EventDelivery['consumer']>;
|
|
96
|
+
};
|
|
97
|
+
export declare const CoreAppEventProducerSchema: z.ZodObject<{
|
|
98
|
+
kind: z.ZodLiteral<"core_app">;
|
|
99
|
+
app: z.ZodEnum<{
|
|
100
|
+
email: "email";
|
|
101
|
+
whatsapp: "whatsapp";
|
|
102
|
+
widget: "widget";
|
|
103
|
+
}>;
|
|
104
|
+
integrationId: z.ZodString;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
/**
|
|
107
|
+
* The exclusive channel lane. It is intentionally not an EventDelivery variant:
|
|
108
|
+
* generic Event handlers cannot accept it by widening their existing contract.
|
|
109
|
+
*/
|
|
110
|
+
export declare const ChannelEventDeliverySchema: z.ZodObject<{
|
|
111
|
+
deliveryId: z.ZodString;
|
|
112
|
+
eventId: z.ZodString;
|
|
113
|
+
tenantId: z.ZodString;
|
|
114
|
+
installId: z.ZodString;
|
|
115
|
+
bindingId: z.ZodString;
|
|
116
|
+
bindingRevisionId: z.ZodString;
|
|
117
|
+
conversationId: z.ZodString;
|
|
118
|
+
audience: z.ZodURL;
|
|
119
|
+
ownerEpoch: z.ZodNumber;
|
|
120
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
121
|
+
kind: z.ZodLiteral<"agent">;
|
|
122
|
+
key: z.ZodString;
|
|
123
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
124
|
+
kind: z.ZodLiteral<"team">;
|
|
125
|
+
key: z.ZodString;
|
|
126
|
+
}, z.core.$strip>], "kind">;
|
|
127
|
+
producer: z.ZodObject<{
|
|
128
|
+
kind: z.ZodLiteral<"core_app">;
|
|
129
|
+
app: z.ZodEnum<{
|
|
130
|
+
email: "email";
|
|
131
|
+
whatsapp: "whatsapp";
|
|
132
|
+
widget: "widget";
|
|
133
|
+
}>;
|
|
134
|
+
integrationId: z.ZodString;
|
|
135
|
+
}, z.core.$strip>;
|
|
136
|
+
externalPrincipal: z.ZodObject<{
|
|
137
|
+
kind: z.ZodLiteral<"external">;
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
}, z.core.$strip>;
|
|
140
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
export type CoreAppEventProducer = z.infer<typeof CoreAppEventProducerSchema>;
|
|
143
|
+
export type ChannelEventDelivery<P = Record<string, unknown>> = Omit<z.infer<typeof ChannelEventDeliverySchema>, 'payload'> & {
|
|
144
|
+
payload: P;
|
|
145
|
+
};
|
|
146
|
+
export interface EventDeliveryGrant {
|
|
147
|
+
tenantId: string;
|
|
148
|
+
installId: string;
|
|
149
|
+
packVersion: number;
|
|
150
|
+
deploymentRevision: string;
|
|
151
|
+
audience: string;
|
|
152
|
+
handlerId: string;
|
|
153
|
+
contract: {
|
|
154
|
+
owner: string;
|
|
155
|
+
key: string;
|
|
156
|
+
version: number;
|
|
157
|
+
fingerprint: string;
|
|
158
|
+
};
|
|
159
|
+
bindingId: string;
|
|
160
|
+
deliveryId: string;
|
|
161
|
+
attemptNumber: number;
|
|
162
|
+
eventId: string;
|
|
163
|
+
payloadDigest: string;
|
|
164
|
+
/** The capability scopes core minted for this delivery; what `kee` may call back with. */
|
|
165
|
+
scopes: readonly string[];
|
|
166
|
+
traceId: string | null;
|
|
167
|
+
authority: Readonly<{
|
|
168
|
+
agents?: readonly string[];
|
|
169
|
+
teams?: readonly string[];
|
|
170
|
+
core_operations?: readonly string[];
|
|
171
|
+
publishes?: readonly {
|
|
172
|
+
key: string;
|
|
173
|
+
version: number;
|
|
174
|
+
fingerprint: string;
|
|
175
|
+
}[];
|
|
176
|
+
}>;
|
|
177
|
+
}
|
|
178
|
+
export declare function verifyEventDeliveryGrant(token: string, options: {
|
|
179
|
+
audience: string;
|
|
180
|
+
jwksUrl?: string;
|
|
181
|
+
coreUrl?: string;
|
|
182
|
+
}): Promise<EventDeliveryGrant | null>;
|
|
183
|
+
/**
|
|
184
|
+
* Delivery is at least once: a lease can expire, a runtime can answer late, a
|
|
185
|
+
* sweep can die, and core sends the same delivery again. A handler's effects
|
|
186
|
+
* must be safe to repeat for one `deliveryId`; `eventEffectIdempotencyKey`
|
|
187
|
+
* gives the key. `attemptNumber` says which try this is.
|
|
188
|
+
*/
|
|
189
|
+
export interface EventHandlerContext {
|
|
190
|
+
deliveryId: string;
|
|
191
|
+
attemptNumber: number;
|
|
192
|
+
tenantId: string;
|
|
193
|
+
correlationId: string;
|
|
194
|
+
causation: EventEnvelope['causation'];
|
|
195
|
+
publication: EventPublishContext | null;
|
|
196
|
+
authority: EventDeliveryGrant['authority'];
|
|
197
|
+
/**
|
|
198
|
+
* The bearer core sent and the scopes it carries: what the handler hands to
|
|
199
|
+
* its Kee client to reach the tenant's Tables. Null when the handler is run
|
|
200
|
+
* without a grant (a local test).
|
|
201
|
+
*/
|
|
202
|
+
grant: {
|
|
203
|
+
token: string;
|
|
204
|
+
scopes: readonly string[];
|
|
205
|
+
traceId: string | null;
|
|
206
|
+
} | null;
|
|
207
|
+
}
|
|
208
|
+
export declare function eventEffectIdempotencyKey(context: Pick<EventHandlerContext, 'deliveryId'>, operation: string, discriminator?: string): string;
|
|
209
|
+
/** A handler failure whose retry policy is explicit and portable across runtimes. */
|
|
210
|
+
export declare class EventHandlerError extends Error {
|
|
211
|
+
readonly code: string;
|
|
212
|
+
readonly retryable: boolean;
|
|
213
|
+
readonly detail?: Readonly<Record<string, unknown>>;
|
|
214
|
+
constructor(input: {
|
|
215
|
+
code: string;
|
|
216
|
+
message: string;
|
|
217
|
+
retryable: boolean;
|
|
218
|
+
detail?: Record<string, unknown>;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
export declare function terminalEventError(code: string, message: string, detail?: Record<string, unknown>): EventHandlerError;
|
|
222
|
+
export declare function retryableEventError(code: string, message: string, detail?: Record<string, unknown>): EventHandlerError;
|
|
223
|
+
export interface EventHandler<P = any, R = unknown> {
|
|
224
|
+
readonly id: string;
|
|
225
|
+
readonly event: EventContract<P>;
|
|
226
|
+
readonly consumes: Readonly<{
|
|
227
|
+
owner: string;
|
|
228
|
+
key: string;
|
|
229
|
+
version: number;
|
|
230
|
+
fingerprint: string;
|
|
231
|
+
}>;
|
|
232
|
+
readonly run: (event: EventEnvelope<P>, context: EventHandlerContext) => Promise<R>;
|
|
233
|
+
readonly authority: Readonly<EventHandlerAuthority>;
|
|
234
|
+
}
|
|
235
|
+
export interface EventHandlerAuthority {
|
|
236
|
+
agents?: readonly string[];
|
|
237
|
+
teams?: readonly string[];
|
|
238
|
+
coreOperations?: readonly string[];
|
|
239
|
+
publishes?: readonly EventContract[];
|
|
240
|
+
}
|
|
241
|
+
export declare function handleEvent<P = unknown, R = unknown>(input: {
|
|
242
|
+
id: string;
|
|
243
|
+
event: EventContract<P>;
|
|
244
|
+
authority?: EventHandlerAuthority;
|
|
245
|
+
run: EventHandler<P, R>['run'];
|
|
246
|
+
}): EventHandler<P, R>;
|
|
247
|
+
/** Build the Event-only manifest fragment. Pack build tooling writes this output to entry.json. */
|
|
248
|
+
export declare function eventManifest(input: {
|
|
249
|
+
events?: readonly EventContract[];
|
|
250
|
+
handlers?: readonly EventHandler<any, any>[];
|
|
251
|
+
}): {
|
|
252
|
+
events: {
|
|
253
|
+
owner: string;
|
|
254
|
+
key: string;
|
|
255
|
+
version: number;
|
|
256
|
+
description: string;
|
|
257
|
+
payload_schema: Readonly<JsonSchema>;
|
|
258
|
+
primary_subject_fields: string[];
|
|
259
|
+
sensitivity: EventSensitivity;
|
|
260
|
+
fingerprint: string;
|
|
261
|
+
}[];
|
|
262
|
+
eventHandlers: {
|
|
263
|
+
id: string;
|
|
264
|
+
consumes: {
|
|
265
|
+
owner: string;
|
|
266
|
+
key: string;
|
|
267
|
+
version: number;
|
|
268
|
+
fingerprint: string;
|
|
269
|
+
};
|
|
270
|
+
authority: {
|
|
271
|
+
publishes?: {
|
|
272
|
+
key: string;
|
|
273
|
+
version: number;
|
|
274
|
+
fingerprint: string;
|
|
275
|
+
}[] | undefined;
|
|
276
|
+
core_operations?: string[] | undefined;
|
|
277
|
+
teams?: string[] | undefined;
|
|
278
|
+
agents?: string[] | undefined;
|
|
279
|
+
};
|
|
280
|
+
}[];
|
|
281
|
+
};
|
|
282
|
+
export declare function dispatchEventDelivery(delivery: EventDelivery, handlers: readonly EventHandler<any, any>[], context?: {
|
|
283
|
+
publication?: EventPublishContext | null;
|
|
284
|
+
authority?: EventDeliveryGrant['authority'];
|
|
285
|
+
grant?: EventHandlerContext['grant'];
|
|
286
|
+
}): Promise<unknown>;
|
|
287
|
+
/**
|
|
288
|
+
* The Pack's `/events/v1/deliver` route. Verifies core's delivery grant for
|
|
289
|
+
* this runtime, checks that it names exactly this delivery, and runs the
|
|
290
|
+
* handler. The answer is the HTTP status: any 2xx means delivered (the body is
|
|
291
|
+
* the handler's result, or empty with 204); a failure is a non-2xx with
|
|
292
|
+
* `{ code, message, retryable }`, and `retryable` tells core whether to try again.
|
|
293
|
+
* Core may post one delivery more than once (see `EventHandlerContext`).
|
|
294
|
+
*/
|
|
295
|
+
export declare function handleEventDeliveryRequest(request: Request, handlers: readonly EventHandler<any, any>[], options: {
|
|
296
|
+
audience: string;
|
|
297
|
+
coreUrl?: string;
|
|
298
|
+
verifyGrant?: (token: string, options: {
|
|
299
|
+
audience: string;
|
|
300
|
+
coreUrl?: string;
|
|
301
|
+
}) => Promise<EventDeliveryGrant | null>;
|
|
302
|
+
}): Promise<Response>;
|
|
303
|
+
export interface EventPublishContext {
|
|
304
|
+
coreUrl: string;
|
|
305
|
+
token: string;
|
|
306
|
+
deliveryId: string;
|
|
307
|
+
eventId: string;
|
|
308
|
+
tenantId: string;
|
|
309
|
+
correlationId: string;
|
|
310
|
+
causation: EventEnvelope['causation'];
|
|
311
|
+
}
|
|
312
|
+
export declare function publishEvent<P>(context: EventPublishContext, contract: EventContract<P>, payload: P, options: {
|
|
313
|
+
idempotencyKey: string;
|
|
314
|
+
}, dependencies?: {
|
|
315
|
+
fetch?: typeof fetch;
|
|
316
|
+
}): Promise<{
|
|
317
|
+
status: string;
|
|
318
|
+
eventId: string;
|
|
319
|
+
deliveryIds: string[];
|
|
320
|
+
}>;
|
|
321
|
+
/** What a run outside any delivery needs to publish a root event: Core's URL and its own grant. */
|
|
322
|
+
export interface EventRootPublishContext {
|
|
323
|
+
coreUrl: string;
|
|
324
|
+
token: string;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Publishes a root event: one no incoming delivery caused, from a scheduled or
|
|
328
|
+
* standalone run of the Pack. The grant must be a run grant carrying
|
|
329
|
+
* `events:publish`, which the tenant puts there by allowing it on the install;
|
|
330
|
+
* a delivery grant is refused here (`delivery_grant_required` is the other
|
|
331
|
+
* door's answer to a run grant). The same key from the same install returns
|
|
332
|
+
* the same root and never a second.
|
|
333
|
+
*/
|
|
334
|
+
export declare function publishRootEvent<P>(context: EventRootPublishContext, contract: EventContract<P>, payload: P, options: {
|
|
335
|
+
idempotencyKey: string;
|
|
336
|
+
}, dependencies?: {
|
|
337
|
+
fetch?: typeof fetch;
|
|
338
|
+
}): Promise<{
|
|
339
|
+
status: string;
|
|
340
|
+
eventId: string;
|
|
341
|
+
deliveryIds: string[];
|
|
342
|
+
}>;
|