@blueraiz/integrati-client 0.0.0-stage → 0.5.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.
@@ -0,0 +1,162 @@
1
+ import type { CloudEvent } from "./cloudevent.ts";
2
+ import { type ClientCredentialsOptions, type TokenSource } from "./tokens.ts";
3
+ import type { Manifest, ManifestPushResult, ManifestStatus } from "./manifest.ts";
4
+ export interface IntegratiClientOptions extends Partial<ClientCredentialsOptions> {
5
+ /** Integrati's base URL, e.g. https://integrati.example.com. */
6
+ baseUrl: string;
7
+ /** Where tokens come from; by default client credentials from the options. */
8
+ tokenSource?: TokenSource;
9
+ fetch?: typeof fetch;
10
+ /** Limit for one request in milliseconds (default 70 000; long polls wait at most 30 s). Streams have none. */
11
+ requestTimeoutMs?: number;
12
+ }
13
+ export interface PublishResult {
14
+ id: string;
15
+ recordId: string;
16
+ /** "accepted", or "duplicate" when Integrati already had a message with this id from this app. */
17
+ status: "accepted" | "duplicate";
18
+ warnings?: string[];
19
+ }
20
+ export interface CommandAccepted {
21
+ commandId: string;
22
+ id: string;
23
+ status: "accepted" | "duplicate";
24
+ warnings?: string[];
25
+ }
26
+ export interface CommandState<TReply = unknown> {
27
+ commandId: string;
28
+ eventId: string;
29
+ type: string;
30
+ caller: string;
31
+ target: string;
32
+ status: "Pending" | "Replied" | "Expired";
33
+ correlationId: string;
34
+ tenantId: string | null;
35
+ createdAt: string;
36
+ expiresAt: string;
37
+ repliedAt: string | null;
38
+ replyType: string | null;
39
+ reply: CloudEvent<TReply> | null;
40
+ }
41
+ /** A message leased from a pull subscription's inbox. Ack it before `leasedUntil` or it is handed out again. */
42
+ /** The range a backfill would cover and how many stored events it holds. */
43
+ export interface BackfillPreview {
44
+ from: string;
45
+ to: string;
46
+ typePattern: string | null;
47
+ events: number;
48
+ }
49
+ /** A backfill of one of this app's subscriptions. */
50
+ export interface BackfillJob {
51
+ id: string;
52
+ subscriptionId: string;
53
+ from: string;
54
+ to: string;
55
+ typePattern: string | null;
56
+ status: "Queued" | "Running" | "Paused" | "Completed" | "Cancelled" | "Failed";
57
+ total: number;
58
+ sent: number;
59
+ position: string | null;
60
+ requestedBy: string;
61
+ lastError: string | null;
62
+ createdAt: string;
63
+ startedAt: string | null;
64
+ finishedAt: string | null;
65
+ }
66
+ /** What to send again: events received in [from, to); to defaults to now. typePattern narrows the subscription's types. */
67
+ export interface BackfillRange {
68
+ from: Date | string;
69
+ to?: Date | string;
70
+ typePattern?: string;
71
+ signal?: AbortSignal;
72
+ }
73
+ export interface InboxMessage<T = unknown> {
74
+ receipt: string;
75
+ attempt: number;
76
+ leasedUntil: string;
77
+ event: CloudEvent<T>;
78
+ }
79
+ export interface ReceiveOptions {
80
+ /** Messages per request, 1-100 (default 10). */
81
+ max?: number;
82
+ /** Seconds to wait for the first message, up to 30 (default 0). */
83
+ waitSeconds?: number;
84
+ /** Seconds the lease lasts (default 60). */
85
+ visibilitySeconds?: number;
86
+ signal?: AbortSignal;
87
+ }
88
+ export interface ProcessInboxOptions {
89
+ batchSize?: number;
90
+ /** How long a handler may take before the message is handed out again (seconds, default 60). */
91
+ visibilitySeconds?: number;
92
+ /** Wait after a failed request to Integrati, in milliseconds (default 5000). */
93
+ errorDelayMs?: number;
94
+ signal?: AbortSignal;
95
+ }
96
+ export declare class IntegratiClient {
97
+ private readonly baseUrl;
98
+ private readonly tokens;
99
+ private readonly fetch;
100
+ private readonly requestTimeoutMs;
101
+ constructor(options: IntegratiClientOptions);
102
+ /** Publishes an event to every matching subscription. Resolves once Integrati's broker has it; safe to retry. */
103
+ publish(event: CloudEvent, signal?: AbortSignal): Promise<PublishResult>;
104
+ /** Sends a command to `target`. The reply comes to this app's direct subscriptions, and through getCommand. */
105
+ sendCommand(target: string, command: CloudEvent, options?: {
106
+ ttlSeconds?: number;
107
+ signal?: AbortSignal;
108
+ }): Promise<CommandAccepted>;
109
+ /** A command this app sent or received; with waitSeconds (up to 30), waits for a pending one to be answered. */
110
+ getCommand<TReply = unknown>(commandId: string, options?: {
111
+ waitSeconds?: number;
112
+ signal?: AbortSignal;
113
+ }): Promise<CommandState<TReply>>;
114
+ /** Sends a command and waits up to `timeoutSeconds` for its reply. Resolves to null if none came in time. */
115
+ call<TReply = unknown>(target: string, command: CloudEvent, timeoutSeconds: number, options?: {
116
+ ttlSeconds?: number;
117
+ signal?: AbortSignal;
118
+ }): Promise<CloudEvent<TReply> | null>;
119
+ /** Answers a command addressed to this app, once. Give the command as received, or its id. */
120
+ reply(command: CloudEvent | string, reply: CloudEvent, signal?: AbortSignal): Promise<PublishResult>;
121
+ /** Leases up to `max` messages, waiting up to `waitSeconds` for the first. */
122
+ receive<T = unknown>(subscriptionId: string, options?: ReceiveOptions): Promise<InboxMessage<T>[]>;
123
+ ack(subscriptionId: string, receipts: string[], signal?: AbortSignal): Promise<number>;
124
+ /** Gives messages back: they come again after retryAfterSeconds, or after Integrati's retry delay. */
125
+ nack(subscriptionId: string, receipts: string[], options?: {
126
+ error?: string;
127
+ retryAfterSeconds?: number;
128
+ signal?: AbortSignal;
129
+ }): Promise<number>;
130
+ /**
131
+ * Handles a pull subscription's messages until `signal` aborts: fetches (long polling), calls
132
+ * `handler` for each, acks it when the handler resolves and nacks it when it throws. Handlers
133
+ * must be idempotent: a message can come more than once.
134
+ */
135
+ processInbox<T = unknown>(subscriptionId: string, handler: (event: CloudEvent<T>) => Promise<void> | void, options?: ProcessInboxOptions): Promise<void>;
136
+ /** Server-sent events: the inbox's messages as they arrive, at most `max` unacknowledged at a time. Ack each one. */
137
+ stream<T = unknown>(subscriptionId: string, options?: {
138
+ max?: number;
139
+ visibilitySeconds?: number;
140
+ signal?: AbortSignal;
141
+ }): AsyncGenerator<InboxMessage<T>>;
142
+ /** This app's registration, subscriptions and grants, as Integrati sees them. */
143
+ /** How many stored events a backfill of one of this app's subscriptions would send. */
144
+ previewBackfill(subscriptionId: string, range: BackfillRange): Promise<BackfillPreview>;
145
+ /**
146
+ * Has the subscription's stored events from a time range sent again, marked with `backfill`
147
+ * (see `isBackfill`). An admin must have allowed backfill for the subscription.
148
+ */
149
+ startBackfill(subscriptionId: string, range: BackfillRange): Promise<BackfillJob>;
150
+ getBackfill(jobId: string, signal?: AbortSignal): Promise<BackfillJob>;
151
+ /** Stops a backfill for good; events already sent are not taken back. */
152
+ cancelBackfill(jobId: string, signal?: AbortSignal): Promise<BackfillJob>;
153
+ me(signal?: AbortSignal): Promise<Record<string, unknown>>;
154
+ /** Sends the app's manifest (see ManifestBuilder). Unchanged manifests change nothing; status is "Pending" until an admin approves the app. */
155
+ pushManifest(manifest: Manifest, signal?: AbortSignal): Promise<ManifestPushResult>;
156
+ /** What is connected for the app, with its subscriptions' signing secrets and its API's assertion secret. */
157
+ manifestStatus(signal?: AbortSignal): Promise<ManifestStatus>;
158
+ private json;
159
+ /** Sends with the current token; on 401 renews it once and tries again. Throws IntegratiError on failure. */
160
+ private send;
161
+ private problem;
162
+ }
package/dist/client.js ADDED
@@ -0,0 +1,242 @@
1
+ import { IntegratiError } from "./errors.js";
2
+ import { ClientCredentialsTokenSource } from "./tokens.js";
3
+ const CLOUDEVENTS_JSON = "application/cloudevents+json";
4
+ function sleep(ms, signal) {
5
+ return new Promise(resolve => {
6
+ const timer = setTimeout(done, ms);
7
+ function done() {
8
+ clearTimeout(timer);
9
+ signal?.removeEventListener("abort", done);
10
+ resolve();
11
+ }
12
+ signal?.addEventListener("abort", done, { once: true });
13
+ });
14
+ }
15
+ function describe(error) {
16
+ const text = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
17
+ return text.slice(0, 500);
18
+ }
19
+ /** Client for an app connected to Integrati. Create one per app and reuse it. */
20
+ const enc = encodeURIComponent;
21
+ function backfillBody(range) {
22
+ const iso = (value) => value instanceof Date ? value.toISOString() : value;
23
+ return { from: iso(range.from), to: iso(range.to), typePattern: range.typePattern };
24
+ }
25
+ export class IntegratiClient {
26
+ baseUrl;
27
+ tokens;
28
+ fetch;
29
+ requestTimeoutMs;
30
+ constructor(options) {
31
+ this.baseUrl = options.baseUrl.replace(/\/+$/, "");
32
+ this.fetch = options.fetch ?? globalThis.fetch;
33
+ this.requestTimeoutMs = options.requestTimeoutMs ?? 70_000;
34
+ if (options.tokenSource) {
35
+ this.tokens = options.tokenSource;
36
+ }
37
+ else {
38
+ if (!options.clientId || !options.clientSecret)
39
+ throw new Error("Give clientId and clientSecret, or a tokenSource.");
40
+ this.tokens = new ClientCredentialsTokenSource({ ...options, clientId: options.clientId, clientSecret: options.clientSecret, fetch: this.fetch });
41
+ }
42
+ }
43
+ // ---------- events ----------
44
+ /** Publishes an event to every matching subscription. Resolves once Integrati's broker has it; safe to retry. */
45
+ async publish(event, signal) {
46
+ return this.json("POST", "/events", { event, signal });
47
+ }
48
+ // ---------- commands ----------
49
+ /** Sends a command to `target`. The reply comes to this app's direct subscriptions, and through getCommand. */
50
+ async sendCommand(target, command, options = {}) {
51
+ const query = options.ttlSeconds === undefined ? "" : `?ttl=${Math.floor(options.ttlSeconds)}`;
52
+ return this.json("POST", `/commands/${encodeURIComponent(target)}${query}`, { event: command, signal: options.signal });
53
+ }
54
+ /** A command this app sent or received; with waitSeconds (up to 30), waits for a pending one to be answered. */
55
+ async getCommand(commandId, options = {}) {
56
+ const query = options.waitSeconds ? `?wait=${Math.ceil(options.waitSeconds)}` : "";
57
+ return this.json("GET", `/commands/${encodeURIComponent(commandId)}${query}`, { signal: options.signal });
58
+ }
59
+ /** Sends a command and waits up to `timeoutSeconds` for its reply. Resolves to null if none came in time. */
60
+ async call(target, command, timeoutSeconds, options = {}) {
61
+ const { commandId } = await this.sendCommand(target, command, options);
62
+ const deadline = Date.now() + timeoutSeconds * 1000;
63
+ for (;;) {
64
+ const remaining = Math.max(0, (deadline - Date.now()) / 1000);
65
+ const state = await this.getCommand(commandId, { waitSeconds: Math.min(remaining, 30), signal: options.signal });
66
+ if (state.status !== "Pending" || Date.now() >= deadline)
67
+ return state.reply;
68
+ }
69
+ }
70
+ /** Answers a command addressed to this app, once. Give the command as received, or its id. */
71
+ async reply(command, reply, signal) {
72
+ const commandId = typeof command === "string" ? command : command.commandid;
73
+ if (!commandId)
74
+ throw new Error("The event is not a command (it has no commandid).");
75
+ return this.json("POST", `/commands/${encodeURIComponent(commandId)}/reply`, { event: reply, signal });
76
+ }
77
+ // ---------- inbox (pull subscriptions) ----------
78
+ /** Leases up to `max` messages, waiting up to `waitSeconds` for the first. */
79
+ async receive(subscriptionId, options = {}) {
80
+ const query = new URLSearchParams({ max: String(options.max ?? 10), wait: String(options.waitSeconds ?? 0) });
81
+ if (options.visibilitySeconds !== undefined)
82
+ query.set("visibility", String(options.visibilitySeconds));
83
+ const result = await this.json("POST", `/inbox/${subscriptionId}/receive?${query}`, { signal: options.signal });
84
+ return result.messages;
85
+ }
86
+ async ack(subscriptionId, receipts, signal) {
87
+ const result = await this.json("POST", `/inbox/${subscriptionId}/ack`, { body: { receipts }, signal });
88
+ return result.acknowledged;
89
+ }
90
+ /** Gives messages back: they come again after retryAfterSeconds, or after Integrati's retry delay. */
91
+ async nack(subscriptionId, receipts, options = {}) {
92
+ const body = { receipts, error: options.error, retryAfterSeconds: options.retryAfterSeconds };
93
+ const result = await this.json("POST", `/inbox/${subscriptionId}/nack`, { body, signal: options.signal });
94
+ return result.released;
95
+ }
96
+ /**
97
+ * Handles a pull subscription's messages until `signal` aborts: fetches (long polling), calls
98
+ * `handler` for each, acks it when the handler resolves and nacks it when it throws. Handlers
99
+ * must be idempotent: a message can come more than once.
100
+ */
101
+ async processInbox(subscriptionId, handler, options = {}) {
102
+ const { signal } = options;
103
+ while (!signal?.aborted) {
104
+ let messages;
105
+ try {
106
+ messages = await this.receive(subscriptionId, { max: options.batchSize ?? 10, waitSeconds: 20, visibilitySeconds: options.visibilitySeconds, signal });
107
+ }
108
+ catch (error) {
109
+ if (signal?.aborted)
110
+ return;
111
+ if (error instanceof IntegratiError && !error.isTransient)
112
+ throw error;
113
+ await sleep(options.errorDelayMs ?? 5000, signal);
114
+ continue;
115
+ }
116
+ const done = [];
117
+ for (const message of messages) {
118
+ if (signal?.aborted)
119
+ break; // Unfinished messages come back when their leases end.
120
+ try {
121
+ await handler(message.event);
122
+ done.push(message.receipt);
123
+ }
124
+ catch (error) {
125
+ await this.nack(subscriptionId, [message.receipt], { error: describe(error) }).catch(() => undefined);
126
+ }
127
+ }
128
+ if (done.length > 0)
129
+ await this.ack(subscriptionId, done).catch(() => undefined);
130
+ }
131
+ }
132
+ /** Server-sent events: the inbox's messages as they arrive, at most `max` unacknowledged at a time. Ack each one. */
133
+ async *stream(subscriptionId, options = {}) {
134
+ const query = new URLSearchParams({ max: String(options.max ?? 10) });
135
+ if (options.visibilitySeconds !== undefined)
136
+ query.set("visibility", String(options.visibilitySeconds));
137
+ const response = await this.send("GET", `/inbox/${subscriptionId}/stream?${query}`, { signal: options.signal, stream: true });
138
+ if (!response.body)
139
+ return;
140
+ const decoder = new TextDecoder();
141
+ let buffer = "";
142
+ let eventName;
143
+ let data = "";
144
+ for await (const chunk of response.body) {
145
+ buffer += decoder.decode(chunk, { stream: true });
146
+ let newline;
147
+ while ((newline = buffer.indexOf("\n")) >= 0) {
148
+ const line = buffer.slice(0, newline).replace(/\r$/, "");
149
+ buffer = buffer.slice(newline + 1);
150
+ if (line === "") {
151
+ if (eventName === "message" && data)
152
+ yield JSON.parse(data);
153
+ if (eventName === "closed")
154
+ return;
155
+ eventName = undefined;
156
+ data = "";
157
+ }
158
+ else if (line.startsWith("event:")) {
159
+ eventName = line.slice(6).trim();
160
+ }
161
+ else if (line.startsWith("data:")) {
162
+ data += line.slice(5).trimStart();
163
+ }
164
+ }
165
+ }
166
+ }
167
+ /** This app's registration, subscriptions and grants, as Integrati sees them. */
168
+ // ---------- backfill ----------
169
+ /** How many stored events a backfill of one of this app's subscriptions would send. */
170
+ async previewBackfill(subscriptionId, range) {
171
+ return this.json("POST", `/subscriptions/${enc(subscriptionId)}/backfills/preview`, { body: backfillBody(range), signal: range.signal });
172
+ }
173
+ /**
174
+ * Has the subscription's stored events from a time range sent again, marked with `backfill`
175
+ * (see `isBackfill`). An admin must have allowed backfill for the subscription.
176
+ */
177
+ async startBackfill(subscriptionId, range) {
178
+ return this.json("POST", `/subscriptions/${enc(subscriptionId)}/backfills`, { body: backfillBody(range), signal: range.signal });
179
+ }
180
+ async getBackfill(jobId, signal) {
181
+ return this.json("GET", `/backfills/${enc(jobId)}`, { signal });
182
+ }
183
+ /** Stops a backfill for good; events already sent are not taken back. */
184
+ async cancelBackfill(jobId, signal) {
185
+ return this.json("POST", `/backfills/${enc(jobId)}/cancel`, { body: {}, signal });
186
+ }
187
+ async me(signal) {
188
+ return this.json("GET", "/me", { signal });
189
+ }
190
+ // ---------- manifest ----------
191
+ /** Sends the app's manifest (see ManifestBuilder). Unchanged manifests change nothing; status is "Pending" until an admin approves the app. */
192
+ async pushManifest(manifest, signal) {
193
+ return this.json("PUT", "/manifest", { body: manifest, signal });
194
+ }
195
+ /** What is connected for the app, with its subscriptions' signing secrets and its API's assertion secret. */
196
+ async manifestStatus(signal) {
197
+ return this.json("GET", "/manifest/status", { signal });
198
+ }
199
+ // ---------- plumbing ----------
200
+ async json(method, path, options) {
201
+ const response = await this.send(method, path, options);
202
+ return (await response.json());
203
+ }
204
+ /** Sends with the current token; on 401 renews it once and tries again. Throws IntegratiError on failure. */
205
+ async send(method, path, options) {
206
+ const signals = [options.signal, options.stream ? undefined : AbortSignal.timeout(this.requestTimeoutMs)].filter((s) => s !== undefined);
207
+ const signal = signals.length === 0 ? undefined : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
208
+ const headers = {};
209
+ let body;
210
+ if (options.event) {
211
+ headers["content-type"] = CLOUDEVENTS_JSON;
212
+ body = JSON.stringify(options.event);
213
+ }
214
+ else if (options.body !== undefined) {
215
+ headers["content-type"] = "application/json";
216
+ body = JSON.stringify(options.body);
217
+ }
218
+ for (let attempt = 1;; attempt++) {
219
+ headers.authorization = `Bearer ${await this.tokens.getToken(signal)}`;
220
+ const response = await this.fetch(this.baseUrl + path, { method, headers, body, signal });
221
+ if (response.status === 401 && attempt === 1) {
222
+ await response.body?.cancel();
223
+ this.tokens.invalidate();
224
+ continue;
225
+ }
226
+ if (!response.ok)
227
+ throw await this.problem(response);
228
+ return response;
229
+ }
230
+ }
231
+ async problem(response) {
232
+ const text = await response.text();
233
+ try {
234
+ const problem = JSON.parse(text);
235
+ return new IntegratiError(response.status, problem.title ?? response.statusText, problem.detail, problem.errors);
236
+ }
237
+ catch {
238
+ return new IntegratiError(response.status, response.statusText || "Request failed", text.slice(0, 500));
239
+ }
240
+ }
241
+ }
242
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAmD,MAAM,aAAa,CAAC;AAyG5G,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AAExD,SAAS,KAAK,CAAC,EAAU,EAAE,MAAoB;IAC7C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnC,SAAS,IAAI;YACX,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3C,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC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O,GAAG,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAC1F,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;gBAC7C,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;gBAC9B,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;gBACzB,SAAS;YACX,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,MAAM,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,QAAkB;QACtC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA2E,CAAC;YAC3G,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACnH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,IAAI,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAC1G,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A CloudEvents 1.0 message as Integrati carries it (structured JSON mode), with Integrati's
3
+ * extension attributes `tenantid`, `correlationid` and `commandid`. Other extension attributes
4
+ * (lowercase letters and digits) may be added as extra properties.
5
+ */
6
+ export interface CloudEvent<T = unknown> {
7
+ specversion: "1.0";
8
+ /** Unique per sending app. Sending the same id again is a no-op at Integrati, so retries are safe. */
9
+ id: string;
10
+ type: string;
11
+ /** The sending app's key. Integrati sets it; any value you give is replaced. */
12
+ source?: string;
13
+ subject?: string;
14
+ time?: string;
15
+ datacontenttype?: string;
16
+ dataschema?: string;
17
+ tenantid?: string;
18
+ correlationid?: string;
19
+ /** On a command: its id at Integrati. On a reply: the id of the command it answers. Set by Integrati. */
20
+ commandid?: string;
21
+ /** Set by Integrati when the event is sent again from its history: the backfill's id. */
22
+ backfill?: string;
23
+ data?: T;
24
+ [extension: string]: unknown;
25
+ }
26
+ export type CloudEventInit<T> = Partial<Omit<CloudEvent<T>, "specversion" | "type" | "data">>;
27
+ /** True when Integrati sent the event again from its history (it may have been handled before). */
28
+ export declare function isBackfill(event: CloudEvent): boolean;
29
+ /** A new event of `type` (e.g. "blueraiz.wfm.shift.assigned.v1") with a fresh id. */
30
+ export declare function cloudEvent<T>(type: string, data?: T, init?: CloudEventInit<T>): CloudEvent<T>;
@@ -0,0 +1,13 @@
1
+ import { randomUUID } from "node:crypto";
2
+ /** True when Integrati sent the event again from its history (it may have been handled before). */
3
+ export function isBackfill(event) {
4
+ return typeof event.backfill === "string";
5
+ }
6
+ /** A new event of `type` (e.g. "blueraiz.wfm.shift.assigned.v1") with a fresh id. */
7
+ export function cloudEvent(type, data, init = {}) {
8
+ const event = { ...init, specversion: "1.0", id: init.id ?? randomUUID(), type };
9
+ if (data !== undefined)
10
+ event.data = data;
11
+ return event;
12
+ }
13
+ //# sourceMappingURL=cloudevent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudevent.js","sourceRoot":"","sources":["../src/cloudevent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA8BzC,mGAAmG;AACnG,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,OAAO,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC5C,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,UAAU,CAAI,IAAY,EAAE,IAAQ,EAAE,OAA0B,EAAE;IAChF,MAAM,KAAK,GAAkB,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,EAAG,IAAI,CAAC,EAAyB,IAAI,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC;IACxH,IAAI,IAAI,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;IAC1C,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,15 @@
1
+ /** Integrati (or the token endpoint) refused a request. Title, detail and errors come from the problem details response. */
2
+ export declare class IntegratiError extends Error {
3
+ readonly status: number;
4
+ readonly title: string;
5
+ readonly detail?: string;
6
+ /** Validation errors by field, e.g. "data/lines/0/qty". */
7
+ readonly errors: Record<string, string[]>;
8
+ constructor(status: number, title: string, detail?: string, errors?: Record<string, string[]>);
9
+ /** Worth retrying later (broker or dependency unavailable, rate limited). Everything else needs a change. */
10
+ get isTransient(): boolean;
11
+ }
12
+ /** A request that failed verification: not from Integrati, altered, or too old. */
13
+ export declare class VerificationError extends Error {
14
+ constructor(message: string);
15
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ /** Integrati (or the token endpoint) refused a request. Title, detail and errors come from the problem details response. */
2
+ export class IntegratiError extends Error {
3
+ status;
4
+ title;
5
+ detail;
6
+ /** Validation errors by field, e.g. "data/lines/0/qty". */
7
+ errors;
8
+ constructor(status, title, detail, errors) {
9
+ let message = `${status} ${title}`;
10
+ if (detail)
11
+ message += `: ${detail}`;
12
+ const list = Object.entries(errors ?? {});
13
+ if (list.length > 0)
14
+ message += ` (${list.map(([field, messages]) => `${field}: ${messages.join(" ")}`).join("; ")})`;
15
+ super(message);
16
+ this.name = "IntegratiError";
17
+ this.status = status;
18
+ this.title = title;
19
+ this.detail = detail;
20
+ this.errors = errors ?? {};
21
+ }
22
+ /** Worth retrying later (broker or dependency unavailable, rate limited). Everything else needs a change. */
23
+ get isTransient() {
24
+ return this.status >= 500 || this.status === 429 || this.status === 408;
25
+ }
26
+ }
27
+ /** A request that failed verification: not from Integrati, altered, or too old. */
28
+ export class VerificationError extends Error {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = "VerificationError";
32
+ }
33
+ }
34
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,MAAM,CAAS;IACf,KAAK,CAAS;IACd,MAAM,CAAU;IACzB,2DAA2D;IAClD,MAAM,CAA2B;IAE1C,YAAY,MAAc,EAAE,KAAa,EAAE,MAAe,EAAE,MAAiC;QAC3F,IAAI,OAAO,GAAG,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;QACnC,IAAI,MAAM;YAAE,OAAO,IAAI,KAAK,MAAM,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC1C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACtH,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,6GAA6G;IAC7G,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC;IAC1E,CAAC;CACF;AAED,mFAAmF;AACnF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export { cloudEvent, isBackfill, type CloudEvent, type CloudEventInit } from "./cloudevent.ts";
2
+ export { IntegratiClient, type IntegratiClientOptions, type PublishResult, type CommandAccepted, type CommandState, type InboxMessage, type BackfillJob, type BackfillPreview, type BackfillRange, type ReceiveOptions, type ProcessInboxOptions } from "./client.ts";
3
+ export { ClientCredentialsTokenSource, StaticTokenSource, type TokenSource, type ClientCredentialsOptions } from "./tokens.ts";
4
+ export { verifyWebhook, signWebhook, verifyGatewayAssertion, type GatewayCaller, type HeaderSource, type VerifyWebhookOptions, type VerifyAssertionOptions } from "./verify.ts";
5
+ export { OutboxRelay, type OutboxMessage, type OutboxStore, type OutboxRelayOptions } from "./outbox.ts";
6
+ export { IntegratiError, VerificationError } from "./errors.ts";
7
+ export { ManifestBuilder, IntegratiApp, defineEvent, type Manifest, type ManifestDelivery, type ManifestPushResult, type ManifestStatus, type ManifestSubscription, type EventDefinition, type IntegratiAppOptions } from "./manifest.ts";
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { cloudEvent, isBackfill } from "./cloudevent.js";
2
+ export { IntegratiClient } from "./client.js";
3
+ export { ClientCredentialsTokenSource, StaticTokenSource } from "./tokens.js";
4
+ export { verifyWebhook, signWebhook, verifyGatewayAssertion } from "./verify.js";
5
+ export { OutboxRelay } from "./outbox.js";
6
+ export { IntegratiError, VerificationError } from "./errors.js";
7
+ export { ManifestBuilder, IntegratiApp, defineEvent } from "./manifest.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwC,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EACL,eAAe,EAWhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAmD,MAAM,aAAa,CAAC;AAC/H,OAAO,EACL,aAAa,EACb,WAAW,EACX,sBAAsB,EAKvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAiE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,eAAe,EACf,YAAY,EACZ,WAAW,EAQZ,MAAM,eAAe,CAAC"}