@flowcore/sdk 1.10.3 → 1.11.2

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 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,IAAI,CAAC;AAM1C,eAAO,MAAM,aAAa;;;CAA2C,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { Deno } from "@deno/shim-deno";
2
+ export { Deno } from "@deno/shim-deno";
3
+ import { default as WebSocket } from "ws";
4
+ export { default as WebSocket } from "ws";
5
+ const dntGlobals = {
6
+ Deno,
7
+ WebSocket,
8
+ };
9
+ export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
10
+ function createMergeProxy(baseObj, extObj) {
11
+ return new Proxy(baseObj, {
12
+ get(_target, prop, _receiver) {
13
+ if (prop in extObj) {
14
+ return extObj[prop];
15
+ }
16
+ else {
17
+ return baseObj[prop];
18
+ }
19
+ },
20
+ set(_target, prop, value) {
21
+ if (prop in extObj) {
22
+ delete extObj[prop];
23
+ }
24
+ baseObj[prop] = value;
25
+ return true;
26
+ },
27
+ deleteProperty(_target, prop) {
28
+ let success = false;
29
+ if (prop in extObj) {
30
+ delete extObj[prop];
31
+ success = true;
32
+ }
33
+ if (prop in baseObj) {
34
+ delete baseObj[prop];
35
+ success = true;
36
+ }
37
+ return success;
38
+ },
39
+ ownKeys(_target) {
40
+ const baseKeys = Reflect.ownKeys(baseObj);
41
+ const extKeys = Reflect.ownKeys(extObj);
42
+ const extKeysSet = new Set(extKeys);
43
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
44
+ },
45
+ defineProperty(_target, prop, desc) {
46
+ if (prop in extObj) {
47
+ delete extObj[prop];
48
+ }
49
+ Reflect.defineProperty(baseObj, prop, desc);
50
+ return true;
51
+ },
52
+ getOwnPropertyDescriptor(_target, prop) {
53
+ if (prop in extObj) {
54
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
55
+ }
56
+ else {
57
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
58
+ }
59
+ },
60
+ has(_target, prop) {
61
+ return prop in extObj || prop in baseObj;
62
+ },
63
+ });
64
+ }
@@ -0,0 +1,80 @@
1
+ import type { Subject } from "rxjs";
2
+ import { type Logger } from "../utils/logger.js";
3
+ /**
4
+ * Represents an event notification from the Flowcore system
5
+ */
6
+ export type NotificationEvent = {
7
+ pattern: string;
8
+ data: {
9
+ tenant: string;
10
+ eventId: string;
11
+ dataCoreId: string;
12
+ flowType: string;
13
+ eventType: string;
14
+ validTime: string;
15
+ };
16
+ };
17
+ /**
18
+ * Interface for OIDC authentication client
19
+ */
20
+ export type OidcClient = {
21
+ getToken: () => Promise<{
22
+ accessToken: string;
23
+ }>;
24
+ };
25
+ /**
26
+ * Configuration options for the NotificationClient
27
+ */
28
+ export type NotificationClientOptions = {
29
+ reconnectInterval: number;
30
+ maxReconnects?: number;
31
+ maxEvents?: number;
32
+ logger?: Logger;
33
+ };
34
+ /**
35
+ * Client for handling WebSocket connections to the Flowcore notification system.
36
+ * Manages connection lifecycle, authentication, and event handling.
37
+ */
38
+ export declare class NotificationClient {
39
+ private readonly observer;
40
+ private readonly oidcClient;
41
+ private readonly subscriptionSpec;
42
+ private url;
43
+ private webSocket;
44
+ private options;
45
+ private logger;
46
+ private eventCount;
47
+ private reconnectInterval;
48
+ private reconnectAttempts;
49
+ /**
50
+ * Creates a new NotificationClient instance
51
+ * @param observer - RxJS Subject for emitting notification events
52
+ * @param oidcClient - Client for handling OIDC authentication
53
+ * @param subscriptionSpec - Specification for what notifications to subscribe to
54
+ * @param options - Configuration options for the client
55
+ */
56
+ constructor(observer: Subject<NotificationEvent>, oidcClient: OidcClient, subscriptionSpec: {
57
+ tenant: string;
58
+ dataCore: string;
59
+ flowType?: string;
60
+ eventType?: string;
61
+ }, options?: Partial<NotificationClientOptions>);
62
+ /**
63
+ * Establishes WebSocket connection and sets up event handlers
64
+ */
65
+ connect(): Promise<void>;
66
+ /**
67
+ * Attempts to reconnect to the WebSocket server using exponential backoff
68
+ */
69
+ private attemptReconnect;
70
+ /**
71
+ * Closes the WebSocket connection
72
+ */
73
+ disconnect(): void;
74
+ /**
75
+ * Overrides the base WebSocket URL for testing or different environments
76
+ * @param url - The new base URL to use
77
+ */
78
+ overrideBaseUrl(url: string): void;
79
+ }
80
+ //# sourceMappingURL=notification-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-client.d.ts","sourceRoot":"","sources":["../../src/common/notification-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AASnC,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAM/D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;QACf,UAAU,EAAE,MAAM,CAAA;QAClB,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,OAAO,CAAC;QACtB,WAAW,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;CACH,CAAA;AAcD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAKD;;;GAGG;AACH,qBAAa,kBAAkB;IAiB3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAlBnC,OAAO,CAAC,GAAG,CAA+C;IAC1D,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,iBAAiB,CAAI;IAE7B;;;;;;OAMG;gBAEgB,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACpC,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE;QACjC,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE,MAAM,CAAA;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,EACD,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC;IAU9C;;OAEG;IACG,OAAO;IAyHb;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAqBxB;;OAEG;IACH,UAAU;IAMV;;;OAGG;IACI,eAAe,CAAC,GAAG,EAAE,MAAM;CAGnC"}
@@ -0,0 +1,213 @@
1
+ import * as dntShim from "../_dnt.shims.js";
2
+ import { DataCoreFetchCommand, EventTypeFetchCommand, FlowTypeFetchCommand, TenantFetchCommand, } from "../mod.js";
3
+ import { defaultLogger } from "../utils/logger.js";
4
+ import { FlowcoreClient } from "./flowcore-client.js";
5
+ import { Buffer } from "node:buffer";
6
+ // Maximum reconnection interval in milliseconds
7
+ const MAX_RECONNECT_INTERVAL = 30_000;
8
+ /**
9
+ * Client for handling WebSocket connections to the Flowcore notification system.
10
+ * Manages connection lifecycle, authentication, and event handling.
11
+ */
12
+ export class NotificationClient {
13
+ /**
14
+ * Creates a new NotificationClient instance
15
+ * @param observer - RxJS Subject for emitting notification events
16
+ * @param oidcClient - Client for handling OIDC authentication
17
+ * @param subscriptionSpec - Specification for what notifications to subscribe to
18
+ * @param options - Configuration options for the client
19
+ */
20
+ constructor(observer, oidcClient, subscriptionSpec, options) {
21
+ Object.defineProperty(this, "observer", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: observer
26
+ });
27
+ Object.defineProperty(this, "oidcClient", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: oidcClient
32
+ });
33
+ Object.defineProperty(this, "subscriptionSpec", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: subscriptionSpec
38
+ });
39
+ Object.defineProperty(this, "url", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: "wss://tenant.api.flowcore.io/notifications"
44
+ });
45
+ Object.defineProperty(this, "webSocket", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "options", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "logger", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "eventCount", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: 0
68
+ });
69
+ Object.defineProperty(this, "reconnectInterval", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ Object.defineProperty(this, "reconnectAttempts", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: 0
80
+ });
81
+ this.options = {
82
+ reconnectInterval: 1000,
83
+ ...options,
84
+ };
85
+ this.logger = options?.logger ?? defaultLogger;
86
+ this.reconnectInterval = options?.reconnectInterval ?? 1000;
87
+ }
88
+ /**
89
+ * Establishes WebSocket connection and sets up event handlers
90
+ */
91
+ async connect() {
92
+ const token = await this.oidcClient.getToken();
93
+ const flowcoreClient = new FlowcoreClient({
94
+ getBearerToken: () => Promise.resolve(token.accessToken),
95
+ });
96
+ const tenant = await flowcoreClient.execute(new TenantFetchCommand({
97
+ tenant: this.subscriptionSpec.tenant,
98
+ }));
99
+ const dataCore = await flowcoreClient.execute(new DataCoreFetchCommand({
100
+ tenantId: tenant.id,
101
+ dataCore: this.subscriptionSpec.dataCore,
102
+ }));
103
+ let flowType;
104
+ let eventType;
105
+ if (this.subscriptionSpec.flowType) {
106
+ flowType = await flowcoreClient.execute(new FlowTypeFetchCommand({
107
+ dataCoreId: dataCore.id,
108
+ flowType: this.subscriptionSpec.flowType,
109
+ }));
110
+ if (this.subscriptionSpec.eventType) {
111
+ eventType = await flowcoreClient.execute(new EventTypeFetchCommand({
112
+ flowTypeId: flowType?.id,
113
+ eventType: this.subscriptionSpec.eventType,
114
+ }));
115
+ }
116
+ }
117
+ this.webSocket = new dntShim.WebSocket(`${this.url}?token=${encodeURIComponent(token.accessToken)}`);
118
+ this.webSocket.onopen = () => {
119
+ this.logger.info("WebSocket connection opened.");
120
+ this.reconnectInterval = this.options.reconnectInterval;
121
+ this.reconnectAttempts = 0;
122
+ this.webSocket.send(JSON.stringify({
123
+ tenant: this.subscriptionSpec.tenant,
124
+ dataCoreId: dataCore.id,
125
+ flowTypeId: flowType?.id,
126
+ eventTypeId: eventType?.id,
127
+ }));
128
+ };
129
+ this.webSocket.onmessage = (event) => {
130
+ let parsedData;
131
+ if (event.data instanceof ArrayBuffer) {
132
+ parsedData = new TextDecoder().decode(event.data);
133
+ }
134
+ else if (Buffer.isBuffer(event.data)) {
135
+ parsedData = event.data.toString();
136
+ }
137
+ else if (Array.isArray(event.data)) {
138
+ // Handle Buffer arrays by concatenating them
139
+ parsedData = Buffer.concat(event.data).toString();
140
+ }
141
+ else {
142
+ parsedData = event.data;
143
+ }
144
+ const data = JSON.parse(parsedData);
145
+ if (data.type === "validation") {
146
+ this.logger.error(`Bad request: ${data.summary} - ${data.message} - ${data.found} - ${data.errors}`);
147
+ return;
148
+ }
149
+ const parsed = JSON.parse(data.message);
150
+ this.logger.debug(`Received event: ${parsed.pattern}`);
151
+ this.observer.next({
152
+ pattern: parsed.pattern,
153
+ data: {
154
+ tenant: parsed.data.tenantId,
155
+ eventId: parsed.data.eventId,
156
+ dataCoreId: parsed.data.dataCore,
157
+ flowType: parsed.data.aggregator,
158
+ eventType: parsed.data.eventType,
159
+ validTime: parsed.data.validTime,
160
+ },
161
+ });
162
+ this.eventCount++;
163
+ if (this.options.maxEvents && this.options.maxEvents <= this.eventCount) {
164
+ this.observer.complete();
165
+ this.eventCount = 0;
166
+ this.webSocket.close(1000, "Max events received");
167
+ }
168
+ };
169
+ this.webSocket.onclose = (event) => {
170
+ this.logger.info(`Connection closed: Code [${event.code}], Reason: ${event.reason}`);
171
+ if (event.code !== 1000) {
172
+ this.attemptReconnect();
173
+ return;
174
+ }
175
+ this.observer.complete();
176
+ };
177
+ this.webSocket.onerror = (error) => {
178
+ this.logger.error(`WebSocket encountered error: ${error}`);
179
+ this.observer.error(error);
180
+ this.webSocket.close();
181
+ };
182
+ }
183
+ /**
184
+ * Attempts to reconnect to the WebSocket server using exponential backoff
185
+ */
186
+ attemptReconnect() {
187
+ if (this.options.maxReconnects && this.reconnectAttempts >= this.options.maxReconnects) {
188
+ this.logger.error(`Max reconnect attempts ${this.reconnectAttempts}/${this.options.maxReconnects} reached. Giving up.`);
189
+ return;
190
+ }
191
+ this.reconnectAttempts++;
192
+ this.logger.info(`Attempting reconnection ${this.reconnectAttempts}${this.options.maxReconnects ? `/${this.options.maxReconnects}` : ""} in ${this.reconnectInterval} ms...`);
193
+ setTimeout(() => {
194
+ this.connect();
195
+ }, this.reconnectInterval);
196
+ this.reconnectInterval = Math.min(MAX_RECONNECT_INTERVAL, this.reconnectInterval * 2);
197
+ }
198
+ /**
199
+ * Closes the WebSocket connection
200
+ */
201
+ disconnect() {
202
+ if (this.webSocket) {
203
+ this.webSocket.close();
204
+ }
205
+ }
206
+ /**
207
+ * Overrides the base WebSocket URL for testing or different environments
208
+ * @param url - The new base URL to use
209
+ */
210
+ overrideBaseUrl(url) {
211
+ this.url = url;
212
+ }
213
+ }
package/esm/mod.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./commands/index.js";
2
2
  export * from "./common/command.js";
3
3
  export * from "./common/flowcore-client.js";
4
+ export * from "./common/notification-client.js";
4
5
  export * from "./contracts/index.js";
5
6
  export * from "./exceptions/index.js";
6
7
  export * from "./utils/parse-response-helper.js";
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kCAAkC,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kCAAkC,CAAA"}
package/esm/mod.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./commands/index.js";
2
2
  export * from "./common/command.js";
3
3
  export * from "./common/flowcore-client.js";
4
+ export * from "./common/notification-client.js";
4
5
  export * from "./contracts/index.js";
5
6
  export * from "./exceptions/index.js";
6
7
  export * from "./utils/parse-response-helper.js";
@@ -0,0 +1,8 @@
1
+ export type Logger = {
2
+ debug: (message: string, meta?: Record<string, unknown>) => void;
3
+ info: (message: string, meta?: Record<string, unknown>) => void;
4
+ warn: (message: string, meta?: Record<string, unknown>) => void;
5
+ error: (message: string | Error, meta?: Record<string, unknown>) => void;
6
+ };
7
+ export declare const defaultLogger: Logger;
8
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAChE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAC/D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAC/D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CACzE,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,MAa3B,CAAA"}
@@ -0,0 +1,14 @@
1
+ export const defaultLogger = {
2
+ debug: (message, meta) => {
3
+ console.debug(message, meta);
4
+ },
5
+ info: (message, meta) => {
6
+ console.info(message, meta);
7
+ },
8
+ warn: (message, meta) => {
9
+ console.warn(message, meta);
10
+ },
11
+ error: (message, meta) => {
12
+ console.error(message, meta);
13
+ },
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowcore/sdk",
3
- "version": "1.10.3",
3
+ "version": "1.11.2",
4
4
  "description": "Flowcore SDK",
5
5
  "homepage": "https://github.com/flowcore-io/flowcore-sdk#readme",
6
6
  "repository": {
@@ -20,10 +20,14 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@sinclair/typebox": "0.32.15"
23
+ "@sinclair/typebox": "0.32.15",
24
+ "rxjs": "^7.8.1",
25
+ "@deno/shim-deno": "~0.18.0",
26
+ "ws": "^8.13.0"
24
27
  },
25
28
  "devDependencies": {
26
- "@types/node": "^20.9.0"
29
+ "@types/node": "^20.9.0",
30
+ "@types/ws": "^8.5.10"
27
31
  },
28
32
  "_generatedBy": "dnt@dev"
29
33
  }
@@ -0,0 +1,9 @@
1
+ import { Deno } from "@deno/shim-deno";
2
+ export { Deno } from "@deno/shim-deno";
3
+ import { default as WebSocket } from "ws";
4
+ export { default as WebSocket } from "ws";
5
+ export declare const dntGlobalThis: Omit<typeof globalThis, "Deno" | "WebSocket"> & {
6
+ Deno: typeof Deno;
7
+ WebSocket: typeof WebSocket;
8
+ };
9
+ //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,IAAI,CAAC;AAM1C,eAAO,MAAM,aAAa;;;CAA2C,CAAC"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dntGlobalThis = exports.WebSocket = exports.Deno = void 0;
7
+ const shim_deno_1 = require("@deno/shim-deno");
8
+ var shim_deno_2 = require("@deno/shim-deno");
9
+ Object.defineProperty(exports, "Deno", { enumerable: true, get: function () { return shim_deno_2.Deno; } });
10
+ const ws_1 = __importDefault(require("ws"));
11
+ var ws_2 = require("ws");
12
+ Object.defineProperty(exports, "WebSocket", { enumerable: true, get: function () { return __importDefault(ws_2).default; } });
13
+ const dntGlobals = {
14
+ Deno: shim_deno_1.Deno,
15
+ WebSocket: ws_1.default,
16
+ };
17
+ exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
18
+ function createMergeProxy(baseObj, extObj) {
19
+ return new Proxy(baseObj, {
20
+ get(_target, prop, _receiver) {
21
+ if (prop in extObj) {
22
+ return extObj[prop];
23
+ }
24
+ else {
25
+ return baseObj[prop];
26
+ }
27
+ },
28
+ set(_target, prop, value) {
29
+ if (prop in extObj) {
30
+ delete extObj[prop];
31
+ }
32
+ baseObj[prop] = value;
33
+ return true;
34
+ },
35
+ deleteProperty(_target, prop) {
36
+ let success = false;
37
+ if (prop in extObj) {
38
+ delete extObj[prop];
39
+ success = true;
40
+ }
41
+ if (prop in baseObj) {
42
+ delete baseObj[prop];
43
+ success = true;
44
+ }
45
+ return success;
46
+ },
47
+ ownKeys(_target) {
48
+ const baseKeys = Reflect.ownKeys(baseObj);
49
+ const extKeys = Reflect.ownKeys(extObj);
50
+ const extKeysSet = new Set(extKeys);
51
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
52
+ },
53
+ defineProperty(_target, prop, desc) {
54
+ if (prop in extObj) {
55
+ delete extObj[prop];
56
+ }
57
+ Reflect.defineProperty(baseObj, prop, desc);
58
+ return true;
59
+ },
60
+ getOwnPropertyDescriptor(_target, prop) {
61
+ if (prop in extObj) {
62
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
63
+ }
64
+ else {
65
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
66
+ }
67
+ },
68
+ has(_target, prop) {
69
+ return prop in extObj || prop in baseObj;
70
+ },
71
+ });
72
+ }
@@ -0,0 +1,80 @@
1
+ import type { Subject } from "rxjs";
2
+ import { type Logger } from "../utils/logger.js";
3
+ /**
4
+ * Represents an event notification from the Flowcore system
5
+ */
6
+ export type NotificationEvent = {
7
+ pattern: string;
8
+ data: {
9
+ tenant: string;
10
+ eventId: string;
11
+ dataCoreId: string;
12
+ flowType: string;
13
+ eventType: string;
14
+ validTime: string;
15
+ };
16
+ };
17
+ /**
18
+ * Interface for OIDC authentication client
19
+ */
20
+ export type OidcClient = {
21
+ getToken: () => Promise<{
22
+ accessToken: string;
23
+ }>;
24
+ };
25
+ /**
26
+ * Configuration options for the NotificationClient
27
+ */
28
+ export type NotificationClientOptions = {
29
+ reconnectInterval: number;
30
+ maxReconnects?: number;
31
+ maxEvents?: number;
32
+ logger?: Logger;
33
+ };
34
+ /**
35
+ * Client for handling WebSocket connections to the Flowcore notification system.
36
+ * Manages connection lifecycle, authentication, and event handling.
37
+ */
38
+ export declare class NotificationClient {
39
+ private readonly observer;
40
+ private readonly oidcClient;
41
+ private readonly subscriptionSpec;
42
+ private url;
43
+ private webSocket;
44
+ private options;
45
+ private logger;
46
+ private eventCount;
47
+ private reconnectInterval;
48
+ private reconnectAttempts;
49
+ /**
50
+ * Creates a new NotificationClient instance
51
+ * @param observer - RxJS Subject for emitting notification events
52
+ * @param oidcClient - Client for handling OIDC authentication
53
+ * @param subscriptionSpec - Specification for what notifications to subscribe to
54
+ * @param options - Configuration options for the client
55
+ */
56
+ constructor(observer: Subject<NotificationEvent>, oidcClient: OidcClient, subscriptionSpec: {
57
+ tenant: string;
58
+ dataCore: string;
59
+ flowType?: string;
60
+ eventType?: string;
61
+ }, options?: Partial<NotificationClientOptions>);
62
+ /**
63
+ * Establishes WebSocket connection and sets up event handlers
64
+ */
65
+ connect(): Promise<void>;
66
+ /**
67
+ * Attempts to reconnect to the WebSocket server using exponential backoff
68
+ */
69
+ private attemptReconnect;
70
+ /**
71
+ * Closes the WebSocket connection
72
+ */
73
+ disconnect(): void;
74
+ /**
75
+ * Overrides the base WebSocket URL for testing or different environments
76
+ * @param url - The new base URL to use
77
+ */
78
+ overrideBaseUrl(url: string): void;
79
+ }
80
+ //# sourceMappingURL=notification-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-client.d.ts","sourceRoot":"","sources":["../../src/common/notification-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AASnC,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAM/D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;QACf,UAAU,EAAE,MAAM,CAAA;QAClB,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,OAAO,CAAC;QACtB,WAAW,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;CACH,CAAA;AAcD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAKD;;;GAGG;AACH,qBAAa,kBAAkB;IAiB3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAlBnC,OAAO,CAAC,GAAG,CAA+C;IAC1D,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,iBAAiB,CAAI;IAE7B;;;;;;OAMG;gBAEgB,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACpC,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE;QACjC,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE,MAAM,CAAA;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,EACD,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC;IAU9C;;OAEG;IACG,OAAO;IAyHb;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAqBxB;;OAEG;IACH,UAAU;IAMV;;;OAGG;IACI,eAAe,CAAC,GAAG,EAAE,MAAM;CAGnC"}