@kinotic-ai/core 5.0.0-beta.1 → 5.0.0-beta.3
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/dist/index.cjs +216 -106
- package/dist/index.d.cts +117 -58
- package/dist/index.d.ts +117 -58
- package/dist/index.js +216 -106
- package/dist/node/index.cjs +79 -0
- package/dist/node/index.d.cts +9 -0
- package/dist/node/index.d.ts +9 -0
- package/dist/node/index.js +14 -0
- package/package.json +14 -3
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// packages/core/src/api/
|
|
1
|
+
// packages/core/src/api/ConnectOptions.ts
|
|
2
2
|
class ServerInfo {
|
|
3
3
|
host;
|
|
4
4
|
port;
|
|
5
5
|
useSSL;
|
|
6
6
|
}
|
|
7
|
+
function buildServerUrl(server, scheme) {
|
|
8
|
+
return scheme + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "");
|
|
9
|
+
}
|
|
10
|
+
function buildBrokerUrl(server) {
|
|
11
|
+
return buildServerUrl(server, "ws") + "/v1";
|
|
12
|
+
}
|
|
7
13
|
var SessionKeepAliveMode;
|
|
8
14
|
((SessionKeepAliveMode2) => {
|
|
9
15
|
SessionKeepAliveMode2["NONE"] = "NONE";
|
|
10
16
|
SessionKeepAliveMode2["ACTIVITY"] = "ACTIVITY";
|
|
11
17
|
SessionKeepAliveMode2["CONNECTION"] = "CONNECTION";
|
|
12
18
|
})(SessionKeepAliveMode ||= {});
|
|
13
|
-
|
|
14
|
-
class ConnectionInfo extends ServerInfo {
|
|
15
|
-
webSocketFactory;
|
|
16
|
-
maxConnectionAttempts;
|
|
17
|
-
sessionKeepAlive = "ACTIVITY" /* ACTIVITY */;
|
|
18
|
-
}
|
|
19
19
|
// packages/core/src/api/event/IEventBus.ts
|
|
20
20
|
var EventConstants;
|
|
21
21
|
((EventConstants2) => {
|
|
@@ -46,34 +46,6 @@ var EventConstants;
|
|
|
46
46
|
EventConstants2["TRACESTATE_HEADER"] = "tracestate";
|
|
47
47
|
})(EventConstants ||= {});
|
|
48
48
|
|
|
49
|
-
// packages/core/src/internal/api/Util.ts
|
|
50
|
-
class Util {
|
|
51
|
-
static createReplyEvent(incomingHeaders, headers, body) {
|
|
52
|
-
if (!incomingHeaders) {
|
|
53
|
-
throw new Error("incomingHeaders cannot be null");
|
|
54
|
-
}
|
|
55
|
-
const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
|
|
56
|
-
if (!replyCRI || replyCRI.trim() === "") {
|
|
57
|
-
throw new Error("No reply-to header found, cannot create outgoing message");
|
|
58
|
-
}
|
|
59
|
-
const newHeaders = new Map;
|
|
60
|
-
for (const [key, value] of incomingHeaders) {
|
|
61
|
-
if (key.startsWith("__")) {
|
|
62
|
-
newHeaders.set(key, value);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (headers) {
|
|
66
|
-
for (const [key, value] of headers) {
|
|
67
|
-
newHeaders.set(key, value);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return new Event(replyCRI, newHeaders, body || undefined);
|
|
71
|
-
}
|
|
72
|
-
static buildBrokerUrl(serverInfo) {
|
|
73
|
-
return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
49
|
// packages/core/src/internal/api/StompConnectionManager.ts
|
|
78
50
|
import { RxStomp } from "@stomp/rx-stomp";
|
|
79
51
|
import { ReconnectionTimeMode } from "@stomp/stompjs";
|
|
@@ -111,42 +83,50 @@ class StompConnectionManager {
|
|
|
111
83
|
get fatalErrors() {
|
|
112
84
|
return this._fatalErrors;
|
|
113
85
|
}
|
|
114
|
-
activate(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
86
|
+
async activate(options) {
|
|
87
|
+
if (!options?.server?.host) {
|
|
88
|
+
throw new Error("No host provided");
|
|
89
|
+
}
|
|
90
|
+
if (this.rxStomp) {
|
|
91
|
+
throw new Error("Stomp connection already active");
|
|
92
|
+
}
|
|
93
|
+
const server = options.server;
|
|
94
|
+
const credentialsResolver = options.credentials;
|
|
95
|
+
let headerAuth = false;
|
|
96
|
+
if (!options.webSocketFactory) {
|
|
97
|
+
if (!credentialsResolver) {
|
|
98
|
+
throw new Error("No credentials supplied and no default resolution applied");
|
|
123
99
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
const resolved = await credentialsResolver.resolve(server);
|
|
101
|
+
if (resolved === null) {
|
|
102
|
+
throw new Error("No Kinotic credentials found; consulted: " + credentialsResolver.name);
|
|
127
103
|
}
|
|
104
|
+
headerAuth = resolved.authHeaders != null;
|
|
105
|
+
}
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
128
107
|
this.connectionAttempts = 0;
|
|
129
108
|
this.initialConnectionSuccessful = false;
|
|
130
109
|
this.lastWebsocketError = null;
|
|
131
110
|
this.maxConnectionAttemptsReached = false;
|
|
132
|
-
const url =
|
|
111
|
+
const url = buildBrokerUrl(server);
|
|
133
112
|
this.rxStomp = new RxStomp;
|
|
134
113
|
let preparedSocket = null;
|
|
135
|
-
const userWebSocketFactory =
|
|
114
|
+
const userWebSocketFactory = options.webSocketFactory;
|
|
115
|
+
const usesPreparedSocket = userWebSocketFactory != null || headerAuth;
|
|
136
116
|
const stompConfig = {
|
|
137
117
|
brokerURL: url,
|
|
138
118
|
connectHeaders: {
|
|
139
|
-
["session-keep-alive" /* SESSION_KEEP_ALIVE_HEADER */]:
|
|
119
|
+
["session-keep-alive" /* SESSION_KEEP_ALIVE_HEADER */]: options.sessionKeepAlive ?? "ACTIVITY" /* ACTIVITY */
|
|
140
120
|
},
|
|
141
121
|
heartbeatIncoming: 120000,
|
|
142
122
|
heartbeatOutgoing: 30000,
|
|
143
123
|
reconnectDelay: this.INITIAL_RECONNECT_DELAY,
|
|
144
124
|
maxReconnectDelay: this.MAX_RECONNECT_DELAY,
|
|
145
125
|
reconnectTimeMode: ReconnectionTimeMode.EXPONENTIAL,
|
|
146
|
-
webSocketFactory:
|
|
126
|
+
webSocketFactory: usesPreparedSocket ? () => preparedSocket : undefined,
|
|
147
127
|
beforeConnect: async () => {
|
|
148
|
-
if (!
|
|
149
|
-
const sessionCheckUrl =
|
|
128
|
+
if (!usesPreparedSocket) {
|
|
129
|
+
const sessionCheckUrl = buildServerUrl(server, "http") + SESSION_CHECK_PATH;
|
|
150
130
|
try {
|
|
151
131
|
const res = await fetch(sessionCheckUrl, { credentials: "include" });
|
|
152
132
|
if (res.status === 401) {
|
|
@@ -155,9 +135,9 @@ class StompConnectionManager {
|
|
|
155
135
|
}
|
|
156
136
|
} catch {}
|
|
157
137
|
}
|
|
158
|
-
if (
|
|
138
|
+
if (options?.maxConnectionAttempts) {
|
|
159
139
|
this.connectionAttempts++;
|
|
160
|
-
if (this.connectionAttempts >
|
|
140
|
+
if (this.connectionAttempts > options.maxConnectionAttempts) {
|
|
161
141
|
this.maxConnectionAttemptsReached = true;
|
|
162
142
|
await this.signalFatal(new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
|
|
163
143
|
return;
|
|
@@ -173,6 +153,18 @@ class StompConnectionManager {
|
|
|
173
153
|
} catch (e) {
|
|
174
154
|
await this.signalFatal(new Error("WebSocket factory failed", { cause: e }));
|
|
175
155
|
}
|
|
156
|
+
} else if (headerAuth) {
|
|
157
|
+
try {
|
|
158
|
+
const resolved = await credentialsResolver.resolve(server);
|
|
159
|
+
if (resolved?.authHeaders == null) {
|
|
160
|
+
await this.signalFatal(new Error("Credentials resolver no longer supplies auth headers: " + credentialsResolver.name));
|
|
161
|
+
} else {
|
|
162
|
+
const WS = WebSocket;
|
|
163
|
+
preparedSocket = new WS(url, { headers: resolved.authHeaders });
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {
|
|
166
|
+
await this.signalFatal(new Error("Credential resolution failed", { cause: e }));
|
|
167
|
+
}
|
|
176
168
|
}
|
|
177
169
|
}
|
|
178
170
|
};
|
|
@@ -182,8 +174,12 @@ class StompConnectionManager {
|
|
|
182
174
|
};
|
|
183
175
|
}
|
|
184
176
|
this.rxStomp.configure(stompConfig);
|
|
185
|
-
this.rxStomp.webSocketErrors$.subscribe((value) => {
|
|
177
|
+
this.rxStomp.webSocketErrors$.subscribe(async (value) => {
|
|
186
178
|
this.lastWebsocketError = value;
|
|
179
|
+
if (options?.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
|
|
180
|
+
this.maxConnectionAttemptsReached = true;
|
|
181
|
+
await this.signalFatal(new Error("Max number of reconnection attempts reached", { cause: value ?? undefined }));
|
|
182
|
+
}
|
|
187
183
|
});
|
|
188
184
|
this.stompErrorsSubscription = this.rxStomp.stompErrors$.subscribe(async (frame) => {
|
|
189
185
|
const stompError = new Error(frame.headers["message"], { cause: frame });
|
|
@@ -328,15 +324,12 @@ class EventBus {
|
|
|
328
324
|
isConnected() {
|
|
329
325
|
return this.stompConnectionManager.connected;
|
|
330
326
|
}
|
|
331
|
-
connect(
|
|
327
|
+
connect(options) {
|
|
332
328
|
return this.serializeLifecycle(async () => {
|
|
333
329
|
if (!this.stompConnectionManager.active) {
|
|
334
330
|
this.cleanup();
|
|
335
|
-
const connectedInfo = await this.stompConnectionManager.activate(
|
|
336
|
-
this.serverInfo =
|
|
337
|
-
this.serverInfo.host = connectionInfo.host;
|
|
338
|
-
this.serverInfo.port = connectionInfo.port;
|
|
339
|
-
this.serverInfo.useSSL = connectionInfo.useSSL;
|
|
331
|
+
const connectedInfo = await this.stompConnectionManager.activate(options);
|
|
332
|
+
this.serverInfo = { ...options.server };
|
|
340
333
|
this.replyToCri = this.stompConnectionManager.replyToCri;
|
|
341
334
|
return connectedInfo;
|
|
342
335
|
} else {
|
|
@@ -502,6 +495,144 @@ class EventBus {
|
|
|
502
495
|
}
|
|
503
496
|
}
|
|
504
497
|
|
|
498
|
+
// packages/core/src/api/security/ChainedCredentialsResolver.ts
|
|
499
|
+
class ChainedCredentialsResolver {
|
|
500
|
+
name;
|
|
501
|
+
resolvers;
|
|
502
|
+
constructor(...resolvers) {
|
|
503
|
+
this.resolvers = resolvers;
|
|
504
|
+
this.name = `ChainedCredentialsResolver(${resolvers.map((r) => r.name).join(" -> ")})`;
|
|
505
|
+
}
|
|
506
|
+
async resolve(server) {
|
|
507
|
+
for (const resolver of this.resolvers) {
|
|
508
|
+
const resolved = await resolver.resolve(server);
|
|
509
|
+
if (resolved !== null) {
|
|
510
|
+
return resolved;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// packages/core/src/api/security/BasicCredentialsResolver.ts
|
|
518
|
+
class BasicCredentialsResolver {
|
|
519
|
+
name = "BasicCredentialsResolver";
|
|
520
|
+
credentials;
|
|
521
|
+
constructor(clientId, clientSecret, organizationId, applicationId) {
|
|
522
|
+
const authHeaders = { clientId, clientSecret };
|
|
523
|
+
if (organizationId != null)
|
|
524
|
+
authHeaders.organizationId = organizationId;
|
|
525
|
+
if (applicationId != null)
|
|
526
|
+
authHeaders.applicationId = applicationId;
|
|
527
|
+
this.credentials = { authHeaders, organizationId, applicationId };
|
|
528
|
+
}
|
|
529
|
+
async resolve(_server) {
|
|
530
|
+
return this.credentials;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// packages/core/src/api/security/BearerCredentialsResolver.ts
|
|
535
|
+
class BearerCredentialsResolver {
|
|
536
|
+
name = "BearerCredentialsResolver";
|
|
537
|
+
token;
|
|
538
|
+
constructor(token) {
|
|
539
|
+
this.token = token;
|
|
540
|
+
}
|
|
541
|
+
async resolve(_server) {
|
|
542
|
+
const token = typeof this.token === "function" ? await this.token() : this.token;
|
|
543
|
+
return { authHeaders: { Authorization: `Bearer ${token}` } };
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// packages/core/src/api/security/EnvCredentialsResolver.ts
|
|
548
|
+
class EnvCredentialsResolver {
|
|
549
|
+
name = "EnvCredentialsResolver";
|
|
550
|
+
async resolve(server) {
|
|
551
|
+
const env = typeof process !== "undefined" ? process.env : undefined;
|
|
552
|
+
let ret = null;
|
|
553
|
+
if (env?.KINOTIC_CLIENT_ID && env?.KINOTIC_CLIENT_SECRET) {
|
|
554
|
+
ret = await new BasicCredentialsResolver(env.KINOTIC_CLIENT_ID, env.KINOTIC_CLIENT_SECRET, env.KINOTIC_ORGANIZATION_ID || undefined, env.KINOTIC_APPLICATION_ID || undefined).resolve(server);
|
|
555
|
+
} else if (env?.KINOTIC_TOKEN) {
|
|
556
|
+
ret = await new BearerCredentialsResolver(env.KINOTIC_TOKEN).resolve(server);
|
|
557
|
+
}
|
|
558
|
+
return ret;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// packages/core/src/api/security/SessionCredentialsResolver.ts
|
|
563
|
+
class SessionCredentialsResolver {
|
|
564
|
+
name = "SessionCredentialsResolver";
|
|
565
|
+
async resolve(_server) {
|
|
566
|
+
return typeof document !== "undefined" ? {} : null;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// packages/core/src/internal/api/Util.ts
|
|
571
|
+
var DEFAULT_PORT = 58503;
|
|
572
|
+
var DEFAULT_HOST = "api.kinotic.com";
|
|
573
|
+
|
|
574
|
+
class Util {
|
|
575
|
+
static createReplyEvent(incomingHeaders, headers, body) {
|
|
576
|
+
if (!incomingHeaders) {
|
|
577
|
+
throw new Error("incomingHeaders cannot be null");
|
|
578
|
+
}
|
|
579
|
+
const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
|
|
580
|
+
if (!replyCRI || replyCRI.trim() === "") {
|
|
581
|
+
throw new Error("No reply-to header found, cannot create outgoing message");
|
|
582
|
+
}
|
|
583
|
+
const newHeaders = new Map;
|
|
584
|
+
for (const [key, value] of incomingHeaders) {
|
|
585
|
+
if (key.startsWith("__")) {
|
|
586
|
+
newHeaders.set(key, value);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (headers) {
|
|
590
|
+
for (const [key, value] of headers) {
|
|
591
|
+
newHeaders.set(key, value);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return new Event(replyCRI, newHeaders, body || undefined);
|
|
595
|
+
}
|
|
596
|
+
static resolveConnectOptions(options) {
|
|
597
|
+
const opts = options ?? {};
|
|
598
|
+
const server = opts.server ?? {};
|
|
599
|
+
const env = typeof process !== "undefined" ? process.env : undefined;
|
|
600
|
+
const location = typeof window !== "undefined" ? window.location : undefined;
|
|
601
|
+
let host = server.host ?? env?.KINOTIC_SERVER_HOST;
|
|
602
|
+
const hostFromLocation = host == null && location != null;
|
|
603
|
+
const hostDefaulted = host == null && location == null;
|
|
604
|
+
if (host == null) {
|
|
605
|
+
host = location?.hostname ?? DEFAULT_HOST;
|
|
606
|
+
}
|
|
607
|
+
let useSSL = server.useSSL;
|
|
608
|
+
if (useSSL == null) {
|
|
609
|
+
if (env?.KINOTIC_SERVER_USE_SSL != null) {
|
|
610
|
+
useSSL = env.KINOTIC_SERVER_USE_SSL === "true";
|
|
611
|
+
} else if (hostFromLocation) {
|
|
612
|
+
useSSL = location.protocol === "https:";
|
|
613
|
+
} else {
|
|
614
|
+
useSSL = hostDefaulted;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
let port = server.port;
|
|
618
|
+
if (port === undefined) {
|
|
619
|
+
if (env?.KINOTIC_SERVER_PORT != null) {
|
|
620
|
+
port = Number(env.KINOTIC_SERVER_PORT);
|
|
621
|
+
} else if (hostFromLocation) {
|
|
622
|
+
port = location.port ? Number(location.port) : null;
|
|
623
|
+
} else {
|
|
624
|
+
port = useSSL ? null : DEFAULT_PORT;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return {
|
|
628
|
+
...opts,
|
|
629
|
+
server: { host, port, useSSL },
|
|
630
|
+
sessionKeepAlive: opts.sessionKeepAlive ?? "ACTIVITY" /* ACTIVITY */,
|
|
631
|
+
credentials: opts.credentials ?? new ChainedCredentialsResolver(new EnvCredentialsResolver, new SessionCredentialsResolver)
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
505
636
|
// packages/core/src/api/ServiceRegistry.ts
|
|
506
637
|
import debug3 from "debug";
|
|
507
638
|
|
|
@@ -1053,7 +1184,7 @@ import { first, map as map2 } from "rxjs/operators";
|
|
|
1053
1184
|
// packages/core/package.json
|
|
1054
1185
|
var package_default = {
|
|
1055
1186
|
name: "@kinotic-ai/core",
|
|
1056
|
-
version: "5.0.0-beta.
|
|
1187
|
+
version: "5.0.0-beta.3",
|
|
1057
1188
|
type: "module",
|
|
1058
1189
|
files: [
|
|
1059
1190
|
"dist"
|
|
@@ -1072,6 +1203,16 @@ var package_default = {
|
|
|
1072
1203
|
default: "./dist/index.cjs"
|
|
1073
1204
|
}
|
|
1074
1205
|
},
|
|
1206
|
+
"./node": {
|
|
1207
|
+
import: {
|
|
1208
|
+
types: "./dist/node/index.d.ts",
|
|
1209
|
+
default: "./dist/node/index.js"
|
|
1210
|
+
},
|
|
1211
|
+
require: {
|
|
1212
|
+
types: "./dist/node/index.d.cts",
|
|
1213
|
+
default: "./dist/node/index.cjs"
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1075
1216
|
"./package.json": "./package.json"
|
|
1076
1217
|
},
|
|
1077
1218
|
homepage: "https://github.com/kinotic-ai/kinotic",
|
|
@@ -1093,7 +1234,7 @@ var package_default = {
|
|
|
1093
1234
|
"@opentelemetry/sdk-trace-node": "^2.6.1",
|
|
1094
1235
|
"@types/node": "^25.6.0",
|
|
1095
1236
|
"@types/uuid": "^11.0.0",
|
|
1096
|
-
"@types/ws": "^8.18.
|
|
1237
|
+
"@types/ws": "^8.18.0",
|
|
1097
1238
|
"@vitest/coverage-v8": "^4.1.4",
|
|
1098
1239
|
"@vitest/runner": "^4.1.4",
|
|
1099
1240
|
"@vitest/ui": "^4.1.4",
|
|
@@ -1117,7 +1258,8 @@ var package_default = {
|
|
|
1117
1258
|
"p-tap": "^4.0.0",
|
|
1118
1259
|
rxjs: "^7.8.2",
|
|
1119
1260
|
"typescript-optional": "3.0.0-alpha.3",
|
|
1120
|
-
uuid: "^13.0.0"
|
|
1261
|
+
uuid: "^13.0.0",
|
|
1262
|
+
ws: "^8.18.0"
|
|
1121
1263
|
},
|
|
1122
1264
|
peerDependenciesMeta: {
|
|
1123
1265
|
typescript: {
|
|
@@ -1290,8 +1432,8 @@ class KinoticSingleton {
|
|
|
1290
1432
|
this._eventBus = eventBus;
|
|
1291
1433
|
this.serviceRegistry.eventBus = eventBus;
|
|
1292
1434
|
}
|
|
1293
|
-
connect(
|
|
1294
|
-
return this._eventBus.connect(
|
|
1435
|
+
connect(options) {
|
|
1436
|
+
return this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1295
1437
|
}
|
|
1296
1438
|
disconnect(force) {
|
|
1297
1439
|
return this._eventBus.disconnect(force);
|
|
@@ -1534,41 +1676,6 @@ class Order {
|
|
|
1534
1676
|
class Sort {
|
|
1535
1677
|
orders = [];
|
|
1536
1678
|
}
|
|
1537
|
-
// packages/core/src/api/security/AuthenticatedWebSocketFactory.ts
|
|
1538
|
-
function createAuthenticatedWebSocketFactory(serverInfo, authProvider) {
|
|
1539
|
-
const brokerUrl = Util.buildBrokerUrl(serverInfo);
|
|
1540
|
-
return async () => {
|
|
1541
|
-
const headers = await authProvider.getAuthHeaders();
|
|
1542
|
-
const WS = WebSocket;
|
|
1543
|
-
return new WS(brokerUrl, { headers });
|
|
1544
|
-
};
|
|
1545
|
-
}
|
|
1546
|
-
// packages/core/src/api/security/BasicAuthProvider.ts
|
|
1547
|
-
class BasicAuthProvider {
|
|
1548
|
-
authHeader;
|
|
1549
|
-
constructor(login, passcode) {
|
|
1550
|
-
const bytes = new TextEncoder().encode(`${login}:${passcode}`);
|
|
1551
|
-
let binary = "";
|
|
1552
|
-
for (const byte of bytes) {
|
|
1553
|
-
binary += String.fromCharCode(byte);
|
|
1554
|
-
}
|
|
1555
|
-
this.authHeader = `Basic ${btoa(binary)}`;
|
|
1556
|
-
}
|
|
1557
|
-
getAuthHeaders() {
|
|
1558
|
-
return { Authorization: this.authHeader };
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
// packages/core/src/api/security/BearerTokenAuthProvider.ts
|
|
1562
|
-
class BearerTokenAuthProvider {
|
|
1563
|
-
token;
|
|
1564
|
-
constructor(token) {
|
|
1565
|
-
this.token = token;
|
|
1566
|
-
}
|
|
1567
|
-
async getAuthHeaders() {
|
|
1568
|
-
const token = typeof this.token === "function" ? await this.token() : this.token;
|
|
1569
|
-
return { Authorization: `Bearer ${token}` };
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
1679
|
// packages/core/src/api/security/ConnectedInfo.ts
|
|
1573
1680
|
class ConnectedInfo {
|
|
1574
1681
|
replyToId;
|
|
@@ -1588,12 +1695,14 @@ export {
|
|
|
1588
1695
|
receivesContext,
|
|
1589
1696
|
isAdvertised,
|
|
1590
1697
|
createCRI,
|
|
1591
|
-
|
|
1698
|
+
buildServerUrl,
|
|
1699
|
+
buildBrokerUrl,
|
|
1592
1700
|
Zone,
|
|
1593
1701
|
Version,
|
|
1594
1702
|
TextEventFactory,
|
|
1595
1703
|
Sort,
|
|
1596
1704
|
SessionKeepAliveMode,
|
|
1705
|
+
SessionCredentialsResolver,
|
|
1597
1706
|
ServiceRegistry,
|
|
1598
1707
|
ServerInfo,
|
|
1599
1708
|
Scope,
|
|
@@ -1610,6 +1719,7 @@ export {
|
|
|
1610
1719
|
EventConstants,
|
|
1611
1720
|
EventBus,
|
|
1612
1721
|
Event,
|
|
1722
|
+
EnvCredentialsResolver,
|
|
1613
1723
|
Direction,
|
|
1614
1724
|
DefaultCRI,
|
|
1615
1725
|
DataSourceUtils,
|
|
@@ -1617,9 +1727,9 @@ export {
|
|
|
1617
1727
|
CrudServiceProxyFactory,
|
|
1618
1728
|
CrudServiceProxy,
|
|
1619
1729
|
Context,
|
|
1620
|
-
ConnectionInfo,
|
|
1621
1730
|
ConnectedInfo,
|
|
1622
|
-
|
|
1623
|
-
|
|
1731
|
+
ChainedCredentialsResolver,
|
|
1732
|
+
BearerCredentialsResolver,
|
|
1733
|
+
BasicCredentialsResolver,
|
|
1624
1734
|
AbstractIterablePage
|
|
1625
1735
|
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var import_node_module = require("node:module");
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
13
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod, to);
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toCommonJS = (from) => {
|
|
34
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
35
|
+
if (entry)
|
|
36
|
+
return entry;
|
|
37
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
38
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
+
for (var key of __getOwnPropNames(from))
|
|
40
|
+
if (!__hasOwnProp.call(entry, key))
|
|
41
|
+
__defProp(entry, key, {
|
|
42
|
+
get: __accessProp.bind(from, key),
|
|
43
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
__moduleCache.set(from, entry);
|
|
47
|
+
return entry;
|
|
48
|
+
};
|
|
49
|
+
var __moduleCache;
|
|
50
|
+
var __returnValue = (v) => v;
|
|
51
|
+
function __exportSetter(name, newValue) {
|
|
52
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
+
}
|
|
54
|
+
var __export = (target, all) => {
|
|
55
|
+
for (var name in all)
|
|
56
|
+
__defProp(target, name, {
|
|
57
|
+
get: all[name],
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
set: __exportSetter.bind(all, name)
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// packages/core/src/node/index.ts
|
|
65
|
+
var exports_node = {};
|
|
66
|
+
__export(exports_node, {
|
|
67
|
+
ensureNodeWebSocket: () => ensureNodeWebSocket
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(exports_node);
|
|
70
|
+
var import_ws = require("ws");
|
|
71
|
+
function ensureNodeWebSocket() {
|
|
72
|
+
if (typeof globalThis.WebSocket === "undefined") {
|
|
73
|
+
Object.assign(globalThis, { WebSocket: import_ws.WebSocket });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (typeof process !== "undefined" && process.versions?.node && !process.versions?.bun) {
|
|
77
|
+
Object.assign(globalThis, { WebSocket: import_ws.WebSocket });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs the `ws` WebSocket as the global WebSocket when the runtime does not provide a
|
|
3
|
+
* header-capable one. Upgrade-header authentication (client credentials, bearer tokens)
|
|
4
|
+
* needs a WebSocket constructor that accepts a `headers` option — `ws` and Bun's built-in
|
|
5
|
+
* do; browsers and some Node versions do not. Call once before {@code Kinotic.connect()}
|
|
6
|
+
* in a Node process.
|
|
7
|
+
*/
|
|
8
|
+
declare function ensureNodeWebSocket(): void;
|
|
9
|
+
export { ensureNodeWebSocket };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs the `ws` WebSocket as the global WebSocket when the runtime does not provide a
|
|
3
|
+
* header-capable one. Upgrade-header authentication (client credentials, bearer tokens)
|
|
4
|
+
* needs a WebSocket constructor that accepts a `headers` option — `ws` and Bun's built-in
|
|
5
|
+
* do; browsers and some Node versions do not. Call once before {@code Kinotic.connect()}
|
|
6
|
+
* in a Node process.
|
|
7
|
+
*/
|
|
8
|
+
declare function ensureNodeWebSocket(): void;
|
|
9
|
+
export { ensureNodeWebSocket };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// packages/core/src/node/index.ts
|
|
2
|
+
import { WebSocket as NodeWebSocket } from "ws";
|
|
3
|
+
function ensureNodeWebSocket() {
|
|
4
|
+
if (typeof globalThis.WebSocket === "undefined") {
|
|
5
|
+
Object.assign(globalThis, { WebSocket: NodeWebSocket });
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (typeof process !== "undefined" && process.versions?.node && !process.versions?.bun) {
|
|
9
|
+
Object.assign(globalThis, { WebSocket: NodeWebSocket });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
ensureNodeWebSocket
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -19,6 +19,16 @@
|
|
|
19
19
|
"default": "./dist/index.cjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
+
"./node": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/node/index.d.ts",
|
|
25
|
+
"default": "./dist/node/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/node/index.d.cts",
|
|
29
|
+
"default": "./dist/node/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
22
32
|
"./package.json": "./package.json"
|
|
23
33
|
},
|
|
24
34
|
"homepage": "https://github.com/kinotic-ai/kinotic",
|
|
@@ -40,7 +50,7 @@
|
|
|
40
50
|
"@opentelemetry/sdk-trace-node": "^2.6.1",
|
|
41
51
|
"@types/node": "^25.6.0",
|
|
42
52
|
"@types/uuid": "^11.0.0",
|
|
43
|
-
"@types/ws": "^8.18.
|
|
53
|
+
"@types/ws": "^8.18.0",
|
|
44
54
|
"@vitest/coverage-v8": "^4.1.4",
|
|
45
55
|
"@vitest/runner": "^4.1.4",
|
|
46
56
|
"@vitest/ui": "^4.1.4",
|
|
@@ -64,7 +74,8 @@
|
|
|
64
74
|
"p-tap": "^4.0.0",
|
|
65
75
|
"rxjs": "^7.8.2",
|
|
66
76
|
"typescript-optional": "3.0.0-alpha.3",
|
|
67
|
-
"uuid": "^13.0.0"
|
|
77
|
+
"uuid": "^13.0.0",
|
|
78
|
+
"ws": "^8.18.0"
|
|
68
79
|
},
|
|
69
80
|
"peerDependenciesMeta": {
|
|
70
81
|
"typescript": {
|