@kinotic-ai/core 1.6.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -65,6 +65,7 @@ var __export = (target, all) => {
65
65
  var exports_src = {};
66
66
  __export(exports_src, {
67
67
  createCRI: () => createCRI,
68
+ createAuthenticatedWebSocketFactory: () => createAuthenticatedWebSocketFactory,
68
69
  Version: () => Version,
69
70
  TextEventFactory: () => TextEventFactory,
70
71
  Sort: () => Sort,
@@ -95,6 +96,8 @@ __export(exports_src, {
95
96
  ConnectionInfo: () => ConnectionInfo,
96
97
  ConnectedInfo: () => ConnectedInfo,
97
98
  CONTEXT_METADATA_KEY: () => CONTEXT_METADATA_KEY,
99
+ BearerTokenAuthProvider: () => BearerTokenAuthProvider,
100
+ BasicAuthProvider: () => BasicAuthProvider,
98
101
  AbstractIterablePage: () => AbstractIterablePage
99
102
  });
100
103
  module.exports = __toCommonJS(exports_src);
@@ -145,13 +148,41 @@ var EventConstants;
145
148
  EventConstants2["TRACESTATE_HEADER"] = "tracestate";
146
149
  })(EventConstants ||= {});
147
150
 
151
+ // packages/core/src/internal/api/Util.ts
152
+ class Util {
153
+ static createReplyEvent(incomingHeaders, headers, body) {
154
+ if (!incomingHeaders) {
155
+ throw new Error("incomingHeaders cannot be null");
156
+ }
157
+ const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
158
+ if (!replyCRI || replyCRI.trim() === "") {
159
+ throw new Error("No reply-to header found, cannot create outgoing message");
160
+ }
161
+ const newHeaders = new Map;
162
+ for (const [key, value] of incomingHeaders) {
163
+ if (key.startsWith("__")) {
164
+ newHeaders.set(key, value);
165
+ }
166
+ }
167
+ if (headers) {
168
+ for (const [key, value] of headers) {
169
+ newHeaders.set(key, value);
170
+ }
171
+ }
172
+ return new Event(replyCRI, newHeaders, body || undefined);
173
+ }
174
+ static buildBrokerUrl(serverInfo) {
175
+ return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
176
+ }
177
+ }
178
+
148
179
  // packages/core/src/internal/api/event/StompConnectionManager.ts
149
180
  var import_rx_stomp = require("@stomp/rx-stomp");
150
181
  var import_stompjs = require("@stomp/stompjs");
151
182
  var import_debug = __toESM(require("debug"));
152
183
  var import_rxjs = require("rxjs");
153
184
  var import_uuid = require("uuid");
154
- var SESSION_CHECK_PATH = "/api/me";
185
+ var SESSION_CHECK_PATH = "/api/auth/me";
155
186
 
156
187
  class StompConnectionManager {
157
188
  lastWebsocketError = null;
@@ -200,7 +231,7 @@ class StompConnectionManager {
200
231
  this.initialConnectionSuccessful = false;
201
232
  this.lastWebsocketError = null;
202
233
  this.maxConnectionAttemptsReached = false;
203
- const url = "ws" + (connectionInfo.useSSL ? "s" : "") + "://" + connectionInfo.host + (connectionInfo.port ? ":" + connectionInfo.port : "") + "/v1";
234
+ const url = Util.buildBrokerUrl(connectionInfo);
204
235
  this.rxStomp = new import_rx_stomp.RxStomp;
205
236
  let preparedSocket = null;
206
237
  const userWebSocketFactory = connectionInfo.webSocketFactory;
@@ -698,35 +729,10 @@ class JsonArgumentResolver {
698
729
  }
699
730
  }
700
731
 
701
- // packages/core/src/internal/api/EventUtil.ts
702
- class EventUtil {
703
- static createReplyEvent(incomingHeaders, headers, body) {
704
- if (!incomingHeaders) {
705
- throw new Error("incomingHeaders cannot be null");
706
- }
707
- const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
708
- if (!replyCRI || replyCRI.trim() === "") {
709
- throw new Error("No reply-to header found, cannot create outgoing message");
710
- }
711
- const newHeaders = new Map;
712
- for (const [key, value] of incomingHeaders) {
713
- if (key.startsWith("__")) {
714
- newHeaders.set(key, value);
715
- }
716
- }
717
- if (headers) {
718
- for (const [key, value] of headers) {
719
- newHeaders.set(key, value);
720
- }
721
- }
722
- return new Event(replyCRI, newHeaders, body || undefined);
723
- }
724
- }
725
-
726
732
  // packages/core/src/internal/api/ReturnValueConverter.ts
727
733
  class BasicReturnValueConverter {
728
734
  convert(incomingMetadata, returnValue) {
729
- return EventUtil.createReplyEvent(incomingMetadata, new Map([["content-type" /* CONTENT_TYPE_HEADER */, "application/json"]]), new TextEncoder().encode(JSON.stringify(returnValue)));
735
+ return Util.createReplyEvent(incomingMetadata, new Map([["content-type" /* CONTENT_TYPE_HEADER */, "application/json"]]), new TextEncoder().encode(JSON.stringify(returnValue)));
730
736
  }
731
737
  }
732
738
 
@@ -973,7 +979,7 @@ class ServiceInvocationSupervisor {
973
979
  this._eventBus.send(outgoingEvent);
974
980
  }
975
981
  handleException(event, error) {
976
- const errorEvent = EventUtil.createReplyEvent(event.headers, new Map([
982
+ const errorEvent = Util.createReplyEvent(event.headers, new Map([
977
983
  ["error" /* ERROR_HEADER */, error.message || "Unknown error"],
978
984
  ["content-type" /* CONTENT_TYPE_HEADER */, "application/json"]
979
985
  ]), new TextEncoder().encode(JSON.stringify({ message: error.message })));
@@ -1004,7 +1010,7 @@ var import_operators2 = require("rxjs/operators");
1004
1010
  // packages/core/package.json
1005
1011
  var package_default = {
1006
1012
  name: "@kinotic-ai/core",
1007
- version: "1.6.2",
1013
+ version: "1.8.0",
1008
1014
  type: "module",
1009
1015
  files: [
1010
1016
  "dist"
@@ -1032,7 +1038,7 @@ var package_default = {
1032
1038
  },
1033
1039
  scripts: {
1034
1040
  "type-check": "tsc --noEmit",
1035
- test: "vitest run --mode development",
1041
+ test: "vitest run",
1036
1042
  coverage: "vitest run --coverage",
1037
1043
  "ui-test": "vitest --ui --coverage.enabled=true --mode development"
1038
1044
  },
@@ -1482,6 +1488,37 @@ class Order {
1482
1488
  class Sort {
1483
1489
  orders = [];
1484
1490
  }
1491
+ // packages/core/src/api/security/AuthenticatedWebSocketFactory.ts
1492
+ function createAuthenticatedWebSocketFactory(serverInfo, authProvider) {
1493
+ const brokerUrl = Util.buildBrokerUrl(serverInfo);
1494
+ return async () => {
1495
+ const headers = await authProvider.getAuthHeaders();
1496
+ const WS = WebSocket;
1497
+ return new WS(brokerUrl, { headers });
1498
+ };
1499
+ }
1500
+ // packages/core/src/api/security/BasicAuthProvider.ts
1501
+ class BasicAuthProvider {
1502
+ authHeader;
1503
+ constructor(login, passcode) {
1504
+ const encoded = Buffer.from(`${login}:${passcode}`).toString("base64");
1505
+ this.authHeader = `Basic ${encoded}`;
1506
+ }
1507
+ getAuthHeaders() {
1508
+ return { Authorization: this.authHeader };
1509
+ }
1510
+ }
1511
+ // packages/core/src/api/security/BearerTokenAuthProvider.ts
1512
+ class BearerTokenAuthProvider {
1513
+ token;
1514
+ constructor(token) {
1515
+ this.token = token;
1516
+ }
1517
+ async getAuthHeaders() {
1518
+ const token = typeof this.token === "function" ? await this.token() : this.token;
1519
+ return { Authorization: `Bearer ${token}` };
1520
+ }
1521
+ }
1485
1522
  // packages/core/src/api/security/ConnectedInfo.ts
1486
1523
  class ConnectedInfo {
1487
1524
  replyToId;
package/dist/index.d.cts CHANGED
@@ -1100,6 +1100,52 @@ declare class EventBus implements IEventBus {
1100
1100
  private _observe;
1101
1101
  }
1102
1102
  /**
1103
+ * Supplies the headers attached to the WebSocket upgrade request when a Node/Bun
1104
+ * client authenticates during the handshake. Implementations are consulted on every
1105
+ * (re)connect, so a provider backing short-lived credentials can refresh them each time.
1106
+ */
1107
+ interface IAuthProvider {
1108
+ /**
1109
+ * Returns the headers to attach to the WebSocket upgrade request.
1110
+ * Invoked on every (re)connect.
1111
+ */
1112
+ getAuthHeaders(): Promise<Record<string, string>> | Record<string, string>;
1113
+ }
1114
+ /**
1115
+ * Builds a {@link WebSocketFactory} that authenticates during the WebSocket upgrade
1116
+ * by attaching the headers from {@link IAuthProvider#getAuthHeaders} to the request.
1117
+ * The provider is consulted on every (re)connect, so short-lived credentials are
1118
+ * refreshed each time. Supply the result as {@link ConnectionInfo#webSocketFactory}.
1119
+ *
1120
+ * For Node/Bun callers: the returned factory creates the socket with the runtime
1121
+ * WebSocket's `headers` option, which the DOM `WebSocket` typings omit and the
1122
+ * browser WebSocket does not support. Browser callers continue to omit
1123
+ * `webSocketFactory` and authenticate via the session cookie from a prior REST login.
1124
+ */
1125
+ declare function createAuthenticatedWebSocketFactory(serverInfo: ServerInfo, authProvider: IAuthProvider): WebSocketFactory;
1126
+ /**
1127
+ * {@link IAuthProvider} that authenticates with HTTP Basic, sending
1128
+ * `Authorization: Basic base64(login:passcode)` on every (re)connect.
1129
+ */
1130
+ declare class BasicAuthProvider implements IAuthProvider {
1131
+ private readonly authHeader;
1132
+ constructor(login: string, passcode: string);
1133
+ getAuthHeaders(): Record<string, string>;
1134
+ }
1135
+ /**
1136
+ * {@link IAuthProvider} that authenticates with a bearer token, sending
1137
+ * `Authorization: Bearer <token>` on every (re)connect.
1138
+ *
1139
+ * Pass a string for a static token, or a supplier when the token is short-lived
1140
+ * and must be refreshed before each connect (for example, an OAuth device-grant
1141
+ * access token). The supplier may be async and is invoked on every (re)connect.
1142
+ */
1143
+ declare class BearerTokenAuthProvider implements IAuthProvider {
1144
+ private readonly token;
1145
+ constructor(token: string | (() => Promise<string> | string));
1146
+ getAuthHeaders(): Promise<Record<string, string>>;
1147
+ }
1148
+ /**
1103
1149
  * Some common constants used for the {@link Participant} and {@link Participant#getMetadata()}
1104
1150
  * Created by navid on 2/3/20
1105
1151
  */
@@ -1111,4 +1157,4 @@ declare class ParticipantConstants {
1111
1157
  static readonly PARTICIPANT_TYPE_NODE: string;
1112
1158
  static readonly CLI_PARTICIPANT_ID: string;
1113
1159
  }
1114
- export { createCRI, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, CONTEXT_METADATA_KEY, AbstractIterablePage };
1160
+ export { createCRI, createAuthenticatedWebSocketFactory, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, CONTEXT_METADATA_KEY, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
package/dist/index.d.ts CHANGED
@@ -1100,6 +1100,52 @@ declare class EventBus implements IEventBus {
1100
1100
  private _observe;
1101
1101
  }
1102
1102
  /**
1103
+ * Supplies the headers attached to the WebSocket upgrade request when a Node/Bun
1104
+ * client authenticates during the handshake. Implementations are consulted on every
1105
+ * (re)connect, so a provider backing short-lived credentials can refresh them each time.
1106
+ */
1107
+ interface IAuthProvider {
1108
+ /**
1109
+ * Returns the headers to attach to the WebSocket upgrade request.
1110
+ * Invoked on every (re)connect.
1111
+ */
1112
+ getAuthHeaders(): Promise<Record<string, string>> | Record<string, string>;
1113
+ }
1114
+ /**
1115
+ * Builds a {@link WebSocketFactory} that authenticates during the WebSocket upgrade
1116
+ * by attaching the headers from {@link IAuthProvider#getAuthHeaders} to the request.
1117
+ * The provider is consulted on every (re)connect, so short-lived credentials are
1118
+ * refreshed each time. Supply the result as {@link ConnectionInfo#webSocketFactory}.
1119
+ *
1120
+ * For Node/Bun callers: the returned factory creates the socket with the runtime
1121
+ * WebSocket's `headers` option, which the DOM `WebSocket` typings omit and the
1122
+ * browser WebSocket does not support. Browser callers continue to omit
1123
+ * `webSocketFactory` and authenticate via the session cookie from a prior REST login.
1124
+ */
1125
+ declare function createAuthenticatedWebSocketFactory(serverInfo: ServerInfo, authProvider: IAuthProvider): WebSocketFactory;
1126
+ /**
1127
+ * {@link IAuthProvider} that authenticates with HTTP Basic, sending
1128
+ * `Authorization: Basic base64(login:passcode)` on every (re)connect.
1129
+ */
1130
+ declare class BasicAuthProvider implements IAuthProvider {
1131
+ private readonly authHeader;
1132
+ constructor(login: string, passcode: string);
1133
+ getAuthHeaders(): Record<string, string>;
1134
+ }
1135
+ /**
1136
+ * {@link IAuthProvider} that authenticates with a bearer token, sending
1137
+ * `Authorization: Bearer <token>` on every (re)connect.
1138
+ *
1139
+ * Pass a string for a static token, or a supplier when the token is short-lived
1140
+ * and must be refreshed before each connect (for example, an OAuth device-grant
1141
+ * access token). The supplier may be async and is invoked on every (re)connect.
1142
+ */
1143
+ declare class BearerTokenAuthProvider implements IAuthProvider {
1144
+ private readonly token;
1145
+ constructor(token: string | (() => Promise<string> | string));
1146
+ getAuthHeaders(): Promise<Record<string, string>>;
1147
+ }
1148
+ /**
1103
1149
  * Some common constants used for the {@link Participant} and {@link Participant#getMetadata()}
1104
1150
  * Created by navid on 2/3/20
1105
1151
  */
@@ -1111,4 +1157,4 @@ declare class ParticipantConstants {
1111
1157
  static readonly PARTICIPANT_TYPE_NODE: string;
1112
1158
  static readonly CLI_PARTICIPANT_ID: string;
1113
1159
  }
1114
- export { createCRI, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, CONTEXT_METADATA_KEY, AbstractIterablePage };
1160
+ export { createCRI, createAuthenticatedWebSocketFactory, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, CONTEXT_METADATA_KEY, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
package/dist/index.js CHANGED
@@ -47,13 +47,41 @@ var EventConstants;
47
47
  EventConstants2["TRACESTATE_HEADER"] = "tracestate";
48
48
  })(EventConstants ||= {});
49
49
 
50
+ // packages/core/src/internal/api/Util.ts
51
+ class Util {
52
+ static createReplyEvent(incomingHeaders, headers, body) {
53
+ if (!incomingHeaders) {
54
+ throw new Error("incomingHeaders cannot be null");
55
+ }
56
+ const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
57
+ if (!replyCRI || replyCRI.trim() === "") {
58
+ throw new Error("No reply-to header found, cannot create outgoing message");
59
+ }
60
+ const newHeaders = new Map;
61
+ for (const [key, value] of incomingHeaders) {
62
+ if (key.startsWith("__")) {
63
+ newHeaders.set(key, value);
64
+ }
65
+ }
66
+ if (headers) {
67
+ for (const [key, value] of headers) {
68
+ newHeaders.set(key, value);
69
+ }
70
+ }
71
+ return new Event(replyCRI, newHeaders, body || undefined);
72
+ }
73
+ static buildBrokerUrl(serverInfo) {
74
+ return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
75
+ }
76
+ }
77
+
50
78
  // packages/core/src/internal/api/event/StompConnectionManager.ts
51
79
  import { RxStomp } from "@stomp/rx-stomp";
52
80
  import { ReconnectionTimeMode } from "@stomp/stompjs";
53
81
  import debug from "debug";
54
82
  import { Subject } from "rxjs";
55
83
  import { v4 as uuidv4 } from "uuid";
56
- var SESSION_CHECK_PATH = "/api/me";
84
+ var SESSION_CHECK_PATH = "/api/auth/me";
57
85
 
58
86
  class StompConnectionManager {
59
87
  lastWebsocketError = null;
@@ -102,7 +130,7 @@ class StompConnectionManager {
102
130
  this.initialConnectionSuccessful = false;
103
131
  this.lastWebsocketError = null;
104
132
  this.maxConnectionAttemptsReached = false;
105
- const url = "ws" + (connectionInfo.useSSL ? "s" : "") + "://" + connectionInfo.host + (connectionInfo.port ? ":" + connectionInfo.port : "") + "/v1";
133
+ const url = Util.buildBrokerUrl(connectionInfo);
106
134
  this.rxStomp = new RxStomp;
107
135
  let preparedSocket = null;
108
136
  const userWebSocketFactory = connectionInfo.webSocketFactory;
@@ -600,35 +628,10 @@ class JsonArgumentResolver {
600
628
  }
601
629
  }
602
630
 
603
- // packages/core/src/internal/api/EventUtil.ts
604
- class EventUtil {
605
- static createReplyEvent(incomingHeaders, headers, body) {
606
- if (!incomingHeaders) {
607
- throw new Error("incomingHeaders cannot be null");
608
- }
609
- const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
610
- if (!replyCRI || replyCRI.trim() === "") {
611
- throw new Error("No reply-to header found, cannot create outgoing message");
612
- }
613
- const newHeaders = new Map;
614
- for (const [key, value] of incomingHeaders) {
615
- if (key.startsWith("__")) {
616
- newHeaders.set(key, value);
617
- }
618
- }
619
- if (headers) {
620
- for (const [key, value] of headers) {
621
- newHeaders.set(key, value);
622
- }
623
- }
624
- return new Event(replyCRI, newHeaders, body || undefined);
625
- }
626
- }
627
-
628
631
  // packages/core/src/internal/api/ReturnValueConverter.ts
629
632
  class BasicReturnValueConverter {
630
633
  convert(incomingMetadata, returnValue) {
631
- return EventUtil.createReplyEvent(incomingMetadata, new Map([["content-type" /* CONTENT_TYPE_HEADER */, "application/json"]]), new TextEncoder().encode(JSON.stringify(returnValue)));
634
+ return Util.createReplyEvent(incomingMetadata, new Map([["content-type" /* CONTENT_TYPE_HEADER */, "application/json"]]), new TextEncoder().encode(JSON.stringify(returnValue)));
632
635
  }
633
636
  }
634
637
 
@@ -875,7 +878,7 @@ class ServiceInvocationSupervisor {
875
878
  this._eventBus.send(outgoingEvent);
876
879
  }
877
880
  handleException(event, error) {
878
- const errorEvent = EventUtil.createReplyEvent(event.headers, new Map([
881
+ const errorEvent = Util.createReplyEvent(event.headers, new Map([
879
882
  ["error" /* ERROR_HEADER */, error.message || "Unknown error"],
880
883
  ["content-type" /* CONTENT_TYPE_HEADER */, "application/json"]
881
884
  ]), new TextEncoder().encode(JSON.stringify({ message: error.message })));
@@ -909,7 +912,7 @@ import { first, map as map2 } from "rxjs/operators";
909
912
  // packages/core/package.json
910
913
  var package_default = {
911
914
  name: "@kinotic-ai/core",
912
- version: "1.6.2",
915
+ version: "1.8.0",
913
916
  type: "module",
914
917
  files: [
915
918
  "dist"
@@ -937,7 +940,7 @@ var package_default = {
937
940
  },
938
941
  scripts: {
939
942
  "type-check": "tsc --noEmit",
940
- test: "vitest run --mode development",
943
+ test: "vitest run",
941
944
  coverage: "vitest run --coverage",
942
945
  "ui-test": "vitest --ui --coverage.enabled=true --mode development"
943
946
  },
@@ -1387,6 +1390,37 @@ class Order {
1387
1390
  class Sort {
1388
1391
  orders = [];
1389
1392
  }
1393
+ // packages/core/src/api/security/AuthenticatedWebSocketFactory.ts
1394
+ function createAuthenticatedWebSocketFactory(serverInfo, authProvider) {
1395
+ const brokerUrl = Util.buildBrokerUrl(serverInfo);
1396
+ return async () => {
1397
+ const headers = await authProvider.getAuthHeaders();
1398
+ const WS = WebSocket;
1399
+ return new WS(brokerUrl, { headers });
1400
+ };
1401
+ }
1402
+ // packages/core/src/api/security/BasicAuthProvider.ts
1403
+ class BasicAuthProvider {
1404
+ authHeader;
1405
+ constructor(login, passcode) {
1406
+ const encoded = Buffer.from(`${login}:${passcode}`).toString("base64");
1407
+ this.authHeader = `Basic ${encoded}`;
1408
+ }
1409
+ getAuthHeaders() {
1410
+ return { Authorization: this.authHeader };
1411
+ }
1412
+ }
1413
+ // packages/core/src/api/security/BearerTokenAuthProvider.ts
1414
+ class BearerTokenAuthProvider {
1415
+ token;
1416
+ constructor(token) {
1417
+ this.token = token;
1418
+ }
1419
+ async getAuthHeaders() {
1420
+ const token = typeof this.token === "function" ? await this.token() : this.token;
1421
+ return { Authorization: `Bearer ${token}` };
1422
+ }
1423
+ }
1390
1424
  // packages/core/src/api/security/ConnectedInfo.ts
1391
1425
  class ConnectedInfo {
1392
1426
  replyToId;
@@ -1403,6 +1437,7 @@ class ParticipantConstants {
1403
1437
  }
1404
1438
  export {
1405
1439
  createCRI,
1440
+ createAuthenticatedWebSocketFactory,
1406
1441
  Version,
1407
1442
  TextEventFactory,
1408
1443
  Sort,
@@ -1433,5 +1468,7 @@ export {
1433
1468
  ConnectionInfo,
1434
1469
  ConnectedInfo,
1435
1470
  CONTEXT_METADATA_KEY,
1471
+ BearerTokenAuthProvider,
1472
+ BasicAuthProvider,
1436
1473
  AbstractIterablePage
1437
1474
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "1.6.2",
3
+ "version": "1.8.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "scripts": {
30
30
  "type-check": "tsc --noEmit",
31
- "test": "vitest run --mode development",
31
+ "test": "vitest run",
32
32
  "coverage": "vitest run --coverage",
33
33
  "ui-test": "vitest --ui --coverage.enabled=true --mode development"
34
34
  },