@kinotic-ai/core 5.0.0-beta.2 → 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 CHANGED
@@ -69,6 +69,8 @@ __export(exports_src, {
69
69
  receivesContext: () => receivesContext,
70
70
  isAdvertised: () => isAdvertised,
71
71
  createCRI: () => createCRI,
72
+ buildServerUrl: () => buildServerUrl,
73
+ buildBrokerUrl: () => buildBrokerUrl,
72
74
  Zone: () => Zone,
73
75
  Version: () => Version,
74
76
  TextEventFactory: () => TextEventFactory,
@@ -113,6 +115,12 @@ class ServerInfo {
113
115
  port;
114
116
  useSSL;
115
117
  }
118
+ function buildServerUrl(server, scheme) {
119
+ return scheme + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "");
120
+ }
121
+ function buildBrokerUrl(server) {
122
+ return buildServerUrl(server, "ws") + "/v1";
123
+ }
116
124
  var SessionKeepAliveMode;
117
125
  ((SessionKeepAliveMode2) => {
118
126
  SessionKeepAliveMode2["NONE"] = "NONE";
@@ -187,13 +195,13 @@ class StompConnectionManager {
187
195
  return this._fatalErrors;
188
196
  }
189
197
  async activate(options) {
190
- if (!options?.host) {
198
+ if (!options?.server?.host) {
191
199
  throw new Error("No host provided");
192
200
  }
193
201
  if (this.rxStomp) {
194
202
  throw new Error("Stomp connection already active");
195
203
  }
196
- const server = { host: options.host, port: options.port, useSSL: options.useSSL };
204
+ const server = options.server;
197
205
  const credentialsResolver = options.credentials;
198
206
  let headerAuth = false;
199
207
  if (!options.webSocketFactory) {
@@ -211,7 +219,7 @@ class StompConnectionManager {
211
219
  this.initialConnectionSuccessful = false;
212
220
  this.lastWebsocketError = null;
213
221
  this.maxConnectionAttemptsReached = false;
214
- const url = Util.buildBrokerUrl(server);
222
+ const url = buildBrokerUrl(server);
215
223
  this.rxStomp = new import_rx_stomp.RxStomp;
216
224
  let preparedSocket = null;
217
225
  const userWebSocketFactory = options.webSocketFactory;
@@ -229,7 +237,7 @@ class StompConnectionManager {
229
237
  webSocketFactory: usesPreparedSocket ? () => preparedSocket : undefined,
230
238
  beforeConnect: async () => {
231
239
  if (!usesPreparedSocket) {
232
- const sessionCheckUrl = "http" + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "") + SESSION_CHECK_PATH;
240
+ const sessionCheckUrl = buildServerUrl(server, "http") + SESSION_CHECK_PATH;
233
241
  try {
234
242
  const res = await fetch(sessionCheckUrl, { credentials: "include" });
235
243
  if (res.status === 401) {
@@ -432,10 +440,7 @@ class EventBus {
432
440
  if (!this.stompConnectionManager.active) {
433
441
  this.cleanup();
434
442
  const connectedInfo = await this.stompConnectionManager.activate(options);
435
- this.serverInfo = new ServerInfo;
436
- this.serverInfo.host = options.host;
437
- this.serverInfo.port = options.port;
438
- this.serverInfo.useSSL = options.useSSL;
443
+ this.serverInfo = { ...options.server };
439
444
  this.replyToCri = this.stompConnectionManager.replyToCri;
440
445
  return connectedInfo;
441
446
  } else {
@@ -620,28 +625,46 @@ class ChainedCredentialsResolver {
620
625
  }
621
626
  }
622
627
 
628
+ // packages/core/src/api/security/BasicCredentialsResolver.ts
629
+ class BasicCredentialsResolver {
630
+ name = "BasicCredentialsResolver";
631
+ credentials;
632
+ constructor(clientId, clientSecret, organizationId, applicationId) {
633
+ const authHeaders = { clientId, clientSecret };
634
+ if (organizationId != null)
635
+ authHeaders.organizationId = organizationId;
636
+ if (applicationId != null)
637
+ authHeaders.applicationId = applicationId;
638
+ this.credentials = { authHeaders, organizationId, applicationId };
639
+ }
640
+ async resolve(_server) {
641
+ return this.credentials;
642
+ }
643
+ }
644
+
645
+ // packages/core/src/api/security/BearerCredentialsResolver.ts
646
+ class BearerCredentialsResolver {
647
+ name = "BearerCredentialsResolver";
648
+ token;
649
+ constructor(token) {
650
+ this.token = token;
651
+ }
652
+ async resolve(_server) {
653
+ const token = typeof this.token === "function" ? await this.token() : this.token;
654
+ return { authHeaders: { Authorization: `Bearer ${token}` } };
655
+ }
656
+ }
657
+
623
658
  // packages/core/src/api/security/EnvCredentialsResolver.ts
624
659
  class EnvCredentialsResolver {
625
660
  name = "EnvCredentialsResolver";
626
- async resolve(_server) {
661
+ async resolve(server) {
627
662
  const env = typeof process !== "undefined" ? process.env : undefined;
628
663
  let ret = null;
629
664
  if (env?.KINOTIC_CLIENT_ID && env?.KINOTIC_CLIENT_SECRET) {
630
- const authHeaders = {
631
- clientId: env.KINOTIC_CLIENT_ID,
632
- clientSecret: env.KINOTIC_CLIENT_SECRET
633
- };
634
- if (env.KINOTIC_ORGANIZATION_ID)
635
- authHeaders.organizationId = env.KINOTIC_ORGANIZATION_ID;
636
- if (env.KINOTIC_APPLICATION_ID)
637
- authHeaders.applicationId = env.KINOTIC_APPLICATION_ID;
638
- ret = {
639
- authHeaders,
640
- organizationId: env.KINOTIC_ORGANIZATION_ID,
641
- applicationId: env.KINOTIC_APPLICATION_ID
642
- };
665
+ ret = await new BasicCredentialsResolver(env.KINOTIC_CLIENT_ID, env.KINOTIC_CLIENT_SECRET, env.KINOTIC_ORGANIZATION_ID || undefined, env.KINOTIC_APPLICATION_ID || undefined).resolve(server);
643
666
  } else if (env?.KINOTIC_TOKEN) {
644
- ret = { authHeaders: { Authorization: `Bearer ${env.KINOTIC_TOKEN}` } };
667
+ ret = await new BearerCredentialsResolver(env.KINOTIC_TOKEN).resolve(server);
645
668
  }
646
669
  return ret;
647
670
  }
@@ -681,20 +704,18 @@ class Util {
681
704
  }
682
705
  return new Event(replyCRI, newHeaders, body || undefined);
683
706
  }
684
- static buildBrokerUrl(serverInfo) {
685
- return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
686
- }
687
707
  static resolveConnectOptions(options) {
688
708
  const opts = options ?? {};
709
+ const server = opts.server ?? {};
689
710
  const env = typeof process !== "undefined" ? process.env : undefined;
690
711
  const location = typeof window !== "undefined" ? window.location : undefined;
691
- let host = opts.host ?? env?.KINOTIC_SERVER_HOST;
712
+ let host = server.host ?? env?.KINOTIC_SERVER_HOST;
692
713
  const hostFromLocation = host == null && location != null;
693
714
  const hostDefaulted = host == null && location == null;
694
715
  if (host == null) {
695
716
  host = location?.hostname ?? DEFAULT_HOST;
696
717
  }
697
- let useSSL = opts.useSSL;
718
+ let useSSL = server.useSSL;
698
719
  if (useSSL == null) {
699
720
  if (env?.KINOTIC_SERVER_USE_SSL != null) {
700
721
  useSSL = env.KINOTIC_SERVER_USE_SSL === "true";
@@ -704,7 +725,7 @@ class Util {
704
725
  useSSL = hostDefaulted;
705
726
  }
706
727
  }
707
- let port = opts.port;
728
+ let port = server.port;
708
729
  if (port === undefined) {
709
730
  if (env?.KINOTIC_SERVER_PORT != null) {
710
731
  port = Number(env.KINOTIC_SERVER_PORT);
@@ -716,9 +737,7 @@ class Util {
716
737
  }
717
738
  return {
718
739
  ...opts,
719
- host,
720
- port,
721
- useSSL,
740
+ server: { host, port, useSSL },
722
741
  sessionKeepAlive: opts.sessionKeepAlive ?? "ACTIVITY" /* ACTIVITY */,
723
742
  credentials: opts.credentials ?? new ChainedCredentialsResolver(new EnvCredentialsResolver, new SessionCredentialsResolver)
724
743
  };
@@ -1273,7 +1292,7 @@ var import_operators2 = require("rxjs/operators");
1273
1292
  // packages/core/package.json
1274
1293
  var package_default = {
1275
1294
  name: "@kinotic-ai/core",
1276
- version: "5.0.0-beta.2",
1295
+ version: "5.0.0-beta.3",
1277
1296
  type: "module",
1278
1297
  files: [
1279
1298
  "dist"
@@ -1765,34 +1784,6 @@ class Order {
1765
1784
  class Sort {
1766
1785
  orders = [];
1767
1786
  }
1768
- // packages/core/src/api/security/BasicCredentialsResolver.ts
1769
- class BasicCredentialsResolver {
1770
- name = "BasicCredentialsResolver";
1771
- credentials;
1772
- constructor(clientId, clientSecret, organizationId, applicationId) {
1773
- const authHeaders = { clientId, clientSecret };
1774
- if (organizationId != null)
1775
- authHeaders.organizationId = organizationId;
1776
- if (applicationId != null)
1777
- authHeaders.applicationId = applicationId;
1778
- this.credentials = { authHeaders, organizationId, applicationId };
1779
- }
1780
- async resolve(_server) {
1781
- return this.credentials;
1782
- }
1783
- }
1784
- // packages/core/src/api/security/BearerCredentialsResolver.ts
1785
- class BearerCredentialsResolver {
1786
- name = "BearerCredentialsResolver";
1787
- token;
1788
- constructor(token) {
1789
- this.token = token;
1790
- }
1791
- async resolve(_server) {
1792
- const token = typeof this.token === "function" ? await this.token() : this.token;
1793
- return { authHeaders: { Authorization: `Bearer ${token}` } };
1794
- }
1795
- }
1796
1787
  // packages/core/src/api/security/ConnectedInfo.ts
1797
1788
  class ConnectedInfo {
1798
1789
  replyToId;
package/dist/index.d.cts CHANGED
@@ -11,7 +11,9 @@ interface ResolvedCredentials {
11
11
  /**
12
12
  * Finds the credentials a Kinotic connection authenticates with. Consulted on every
13
13
  * (re)connect, so an implementation backing short-lived credentials can refresh them each
14
- * time. Returning null means this resolver found nothing — in a
14
+ * time; one whose resolution is expensive — a network round-trip, a disk read — must cache
15
+ * the result internally and refresh only as expiry nears, since reconnects pay the cost of
16
+ * every resolve. Returning null means this resolver found nothing — in a
15
17
  * {@link ChainedCredentialsResolver} the next resolver tries; at the top level the connect
16
18
  * fails naming every resolver consulted.
17
19
  */
@@ -54,27 +56,37 @@ declare class ServerInfo {
54
56
  port?: number | null;
55
57
  useSSL?: boolean | null;
56
58
  }
59
+ /**
60
+ * Builds the base URL of a server for the given scheme stem ({@code 'ws'} or {@code 'http'}):
61
+ * TLS appends {@code s}, and the port is omitted when absent so the scheme default applies.
62
+ */
63
+ declare function buildServerUrl(server: ServerInfo, scheme: "ws" | "http"): string;
64
+ /**
65
+ * Builds the WebSocket broker URL the STOMP client connects to for a given server — the
66
+ * single source of truth for the broker path, so a caller supplying its own
67
+ * {@link WebSocketFactory} never re-types it and drifts from core.
68
+ */
69
+ declare function buildBrokerUrl(server: ServerInfo): string;
57
70
  declare enum SessionKeepAliveMode {
58
71
  NONE = "NONE",
59
72
  ACTIVITY = "ACTIVITY",
60
73
  CONNECTION = "CONNECTION"
61
74
  }
62
75
  /**
63
- * Options for {@link IKinotic#connect}. Every field is optional: absent server fields resolve
64
- * from the environment (the {@code KINOTIC_SERVER_HOST} / {@code KINOTIC_SERVER_PORT} /
65
- * {@code KINOTIC_SERVER_USE_SSL} variables, the browser's own location, then
66
- * {@code https://api.kinotic.com}), and absent {@link credentials} resolve through the
67
- * default {@link ChainedCredentialsResolver} (environment variables, then the browser
68
- * session).
76
+ * Options for {@link IKinotic#connect}. Every field is optional: absent {@link server}
77
+ * fields resolve from the environment (the {@code KINOTIC_SERVER_HOST} /
78
+ * {@code KINOTIC_SERVER_PORT} / {@code KINOTIC_SERVER_USE_SSL} variables, the browser's own
79
+ * location, then {@code https://api.kinotic.com}), and absent {@link credentials} resolve
80
+ * through the default {@link ChainedCredentialsResolver} (environment variables, then the
81
+ * browser session).
69
82
  *
70
83
  * Authentication is performed during the WebSocket upgrade (handshake), not in the STOMP
71
84
  * CONNECT frame: the resolved credentials supply the upgrade headers, or none for
72
85
  * session-cookie auth.
73
86
  */
74
87
  interface ConnectOptions {
75
- host?: string;
76
- port?: number | null;
77
- useSSL?: boolean | null;
88
+ /** The server to connect to; absent fields resolve from the environment. */
89
+ server?: Partial<ServerInfo>;
78
90
  /**
79
91
  * Finds the credentials this connection authenticates with, consulted on every
80
92
  * (re)connect. Absent, the default resolution chain applies.
@@ -1290,7 +1302,7 @@ declare class ChainedCredentialsResolver implements CredentialsResolver {
1290
1302
  */
1291
1303
  declare class EnvCredentialsResolver implements CredentialsResolver {
1292
1304
  readonly name: string;
1293
- resolve(_server: ServerInfo): Promise<ResolvedCredentials | null>;
1305
+ resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
1294
1306
  }
1295
1307
  /**
1296
1308
  * The browser's session cookie, established by a prior REST login. Resolves to credentials
@@ -1315,4 +1327,4 @@ declare class ParticipantConstants {
1315
1327
  /** The clientId TestSecurityService (clienttest profile) maps to the ANONYMOUS role in core package tests. */
1316
1328
  static readonly CLI_PARTICIPANT_ID: string;
1317
1329
  }
1318
- export { validateZone, validateLabel, receivesContext, isAdvertised, createCRI, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceContext, ServerInfo, Scope, ResolvedCredentials, 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, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AbstractIterablePage };
1330
+ export { validateZone, validateLabel, receivesContext, isAdvertised, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceContext, ServerInfo, Scope, ResolvedCredentials, 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, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AbstractIterablePage };
package/dist/index.d.ts CHANGED
@@ -11,7 +11,9 @@ interface ResolvedCredentials {
11
11
  /**
12
12
  * Finds the credentials a Kinotic connection authenticates with. Consulted on every
13
13
  * (re)connect, so an implementation backing short-lived credentials can refresh them each
14
- * time. Returning null means this resolver found nothing — in a
14
+ * time; one whose resolution is expensive — a network round-trip, a disk read — must cache
15
+ * the result internally and refresh only as expiry nears, since reconnects pay the cost of
16
+ * every resolve. Returning null means this resolver found nothing — in a
15
17
  * {@link ChainedCredentialsResolver} the next resolver tries; at the top level the connect
16
18
  * fails naming every resolver consulted.
17
19
  */
@@ -54,27 +56,37 @@ declare class ServerInfo {
54
56
  port?: number | null;
55
57
  useSSL?: boolean | null;
56
58
  }
59
+ /**
60
+ * Builds the base URL of a server for the given scheme stem ({@code 'ws'} or {@code 'http'}):
61
+ * TLS appends {@code s}, and the port is omitted when absent so the scheme default applies.
62
+ */
63
+ declare function buildServerUrl(server: ServerInfo, scheme: "ws" | "http"): string;
64
+ /**
65
+ * Builds the WebSocket broker URL the STOMP client connects to for a given server — the
66
+ * single source of truth for the broker path, so a caller supplying its own
67
+ * {@link WebSocketFactory} never re-types it and drifts from core.
68
+ */
69
+ declare function buildBrokerUrl(server: ServerInfo): string;
57
70
  declare enum SessionKeepAliveMode {
58
71
  NONE = "NONE",
59
72
  ACTIVITY = "ACTIVITY",
60
73
  CONNECTION = "CONNECTION"
61
74
  }
62
75
  /**
63
- * Options for {@link IKinotic#connect}. Every field is optional: absent server fields resolve
64
- * from the environment (the {@code KINOTIC_SERVER_HOST} / {@code KINOTIC_SERVER_PORT} /
65
- * {@code KINOTIC_SERVER_USE_SSL} variables, the browser's own location, then
66
- * {@code https://api.kinotic.com}), and absent {@link credentials} resolve through the
67
- * default {@link ChainedCredentialsResolver} (environment variables, then the browser
68
- * session).
76
+ * Options for {@link IKinotic#connect}. Every field is optional: absent {@link server}
77
+ * fields resolve from the environment (the {@code KINOTIC_SERVER_HOST} /
78
+ * {@code KINOTIC_SERVER_PORT} / {@code KINOTIC_SERVER_USE_SSL} variables, the browser's own
79
+ * location, then {@code https://api.kinotic.com}), and absent {@link credentials} resolve
80
+ * through the default {@link ChainedCredentialsResolver} (environment variables, then the
81
+ * browser session).
69
82
  *
70
83
  * Authentication is performed during the WebSocket upgrade (handshake), not in the STOMP
71
84
  * CONNECT frame: the resolved credentials supply the upgrade headers, or none for
72
85
  * session-cookie auth.
73
86
  */
74
87
  interface ConnectOptions {
75
- host?: string;
76
- port?: number | null;
77
- useSSL?: boolean | null;
88
+ /** The server to connect to; absent fields resolve from the environment. */
89
+ server?: Partial<ServerInfo>;
78
90
  /**
79
91
  * Finds the credentials this connection authenticates with, consulted on every
80
92
  * (re)connect. Absent, the default resolution chain applies.
@@ -1290,7 +1302,7 @@ declare class ChainedCredentialsResolver implements CredentialsResolver {
1290
1302
  */
1291
1303
  declare class EnvCredentialsResolver implements CredentialsResolver {
1292
1304
  readonly name: string;
1293
- resolve(_server: ServerInfo): Promise<ResolvedCredentials | null>;
1305
+ resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
1294
1306
  }
1295
1307
  /**
1296
1308
  * The browser's session cookie, established by a prior REST login. Resolves to credentials
@@ -1315,4 +1327,4 @@ declare class ParticipantConstants {
1315
1327
  /** The clientId TestSecurityService (clienttest profile) maps to the ANONYMOUS role in core package tests. */
1316
1328
  static readonly CLI_PARTICIPANT_ID: string;
1317
1329
  }
1318
- export { validateZone, validateLabel, receivesContext, isAdvertised, createCRI, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceContext, ServerInfo, Scope, ResolvedCredentials, 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, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AbstractIterablePage };
1330
+ export { validateZone, validateLabel, receivesContext, isAdvertised, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceContext, ServerInfo, Scope, ResolvedCredentials, 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, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AbstractIterablePage };
package/dist/index.js CHANGED
@@ -4,6 +4,12 @@ class ServerInfo {
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";
@@ -78,13 +84,13 @@ class StompConnectionManager {
78
84
  return this._fatalErrors;
79
85
  }
80
86
  async activate(options) {
81
- if (!options?.host) {
87
+ if (!options?.server?.host) {
82
88
  throw new Error("No host provided");
83
89
  }
84
90
  if (this.rxStomp) {
85
91
  throw new Error("Stomp connection already active");
86
92
  }
87
- const server = { host: options.host, port: options.port, useSSL: options.useSSL };
93
+ const server = options.server;
88
94
  const credentialsResolver = options.credentials;
89
95
  let headerAuth = false;
90
96
  if (!options.webSocketFactory) {
@@ -102,7 +108,7 @@ class StompConnectionManager {
102
108
  this.initialConnectionSuccessful = false;
103
109
  this.lastWebsocketError = null;
104
110
  this.maxConnectionAttemptsReached = false;
105
- const url = Util.buildBrokerUrl(server);
111
+ const url = buildBrokerUrl(server);
106
112
  this.rxStomp = new RxStomp;
107
113
  let preparedSocket = null;
108
114
  const userWebSocketFactory = options.webSocketFactory;
@@ -120,7 +126,7 @@ class StompConnectionManager {
120
126
  webSocketFactory: usesPreparedSocket ? () => preparedSocket : undefined,
121
127
  beforeConnect: async () => {
122
128
  if (!usesPreparedSocket) {
123
- const sessionCheckUrl = "http" + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "") + SESSION_CHECK_PATH;
129
+ const sessionCheckUrl = buildServerUrl(server, "http") + SESSION_CHECK_PATH;
124
130
  try {
125
131
  const res = await fetch(sessionCheckUrl, { credentials: "include" });
126
132
  if (res.status === 401) {
@@ -323,10 +329,7 @@ class EventBus {
323
329
  if (!this.stompConnectionManager.active) {
324
330
  this.cleanup();
325
331
  const connectedInfo = await this.stompConnectionManager.activate(options);
326
- this.serverInfo = new ServerInfo;
327
- this.serverInfo.host = options.host;
328
- this.serverInfo.port = options.port;
329
- this.serverInfo.useSSL = options.useSSL;
332
+ this.serverInfo = { ...options.server };
330
333
  this.replyToCri = this.stompConnectionManager.replyToCri;
331
334
  return connectedInfo;
332
335
  } else {
@@ -511,28 +514,46 @@ class ChainedCredentialsResolver {
511
514
  }
512
515
  }
513
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
+
514
547
  // packages/core/src/api/security/EnvCredentialsResolver.ts
515
548
  class EnvCredentialsResolver {
516
549
  name = "EnvCredentialsResolver";
517
- async resolve(_server) {
550
+ async resolve(server) {
518
551
  const env = typeof process !== "undefined" ? process.env : undefined;
519
552
  let ret = null;
520
553
  if (env?.KINOTIC_CLIENT_ID && env?.KINOTIC_CLIENT_SECRET) {
521
- const authHeaders = {
522
- clientId: env.KINOTIC_CLIENT_ID,
523
- clientSecret: env.KINOTIC_CLIENT_SECRET
524
- };
525
- if (env.KINOTIC_ORGANIZATION_ID)
526
- authHeaders.organizationId = env.KINOTIC_ORGANIZATION_ID;
527
- if (env.KINOTIC_APPLICATION_ID)
528
- authHeaders.applicationId = env.KINOTIC_APPLICATION_ID;
529
- ret = {
530
- authHeaders,
531
- organizationId: env.KINOTIC_ORGANIZATION_ID,
532
- applicationId: env.KINOTIC_APPLICATION_ID
533
- };
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);
534
555
  } else if (env?.KINOTIC_TOKEN) {
535
- ret = { authHeaders: { Authorization: `Bearer ${env.KINOTIC_TOKEN}` } };
556
+ ret = await new BearerCredentialsResolver(env.KINOTIC_TOKEN).resolve(server);
536
557
  }
537
558
  return ret;
538
559
  }
@@ -572,20 +593,18 @@ class Util {
572
593
  }
573
594
  return new Event(replyCRI, newHeaders, body || undefined);
574
595
  }
575
- static buildBrokerUrl(serverInfo) {
576
- return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
577
- }
578
596
  static resolveConnectOptions(options) {
579
597
  const opts = options ?? {};
598
+ const server = opts.server ?? {};
580
599
  const env = typeof process !== "undefined" ? process.env : undefined;
581
600
  const location = typeof window !== "undefined" ? window.location : undefined;
582
- let host = opts.host ?? env?.KINOTIC_SERVER_HOST;
601
+ let host = server.host ?? env?.KINOTIC_SERVER_HOST;
583
602
  const hostFromLocation = host == null && location != null;
584
603
  const hostDefaulted = host == null && location == null;
585
604
  if (host == null) {
586
605
  host = location?.hostname ?? DEFAULT_HOST;
587
606
  }
588
- let useSSL = opts.useSSL;
607
+ let useSSL = server.useSSL;
589
608
  if (useSSL == null) {
590
609
  if (env?.KINOTIC_SERVER_USE_SSL != null) {
591
610
  useSSL = env.KINOTIC_SERVER_USE_SSL === "true";
@@ -595,7 +614,7 @@ class Util {
595
614
  useSSL = hostDefaulted;
596
615
  }
597
616
  }
598
- let port = opts.port;
617
+ let port = server.port;
599
618
  if (port === undefined) {
600
619
  if (env?.KINOTIC_SERVER_PORT != null) {
601
620
  port = Number(env.KINOTIC_SERVER_PORT);
@@ -607,9 +626,7 @@ class Util {
607
626
  }
608
627
  return {
609
628
  ...opts,
610
- host,
611
- port,
612
- useSSL,
629
+ server: { host, port, useSSL },
613
630
  sessionKeepAlive: opts.sessionKeepAlive ?? "ACTIVITY" /* ACTIVITY */,
614
631
  credentials: opts.credentials ?? new ChainedCredentialsResolver(new EnvCredentialsResolver, new SessionCredentialsResolver)
615
632
  };
@@ -1167,7 +1184,7 @@ import { first, map as map2 } from "rxjs/operators";
1167
1184
  // packages/core/package.json
1168
1185
  var package_default = {
1169
1186
  name: "@kinotic-ai/core",
1170
- version: "5.0.0-beta.2",
1187
+ version: "5.0.0-beta.3",
1171
1188
  type: "module",
1172
1189
  files: [
1173
1190
  "dist"
@@ -1659,34 +1676,6 @@ class Order {
1659
1676
  class Sort {
1660
1677
  orders = [];
1661
1678
  }
1662
- // packages/core/src/api/security/BasicCredentialsResolver.ts
1663
- class BasicCredentialsResolver {
1664
- name = "BasicCredentialsResolver";
1665
- credentials;
1666
- constructor(clientId, clientSecret, organizationId, applicationId) {
1667
- const authHeaders = { clientId, clientSecret };
1668
- if (organizationId != null)
1669
- authHeaders.organizationId = organizationId;
1670
- if (applicationId != null)
1671
- authHeaders.applicationId = applicationId;
1672
- this.credentials = { authHeaders, organizationId, applicationId };
1673
- }
1674
- async resolve(_server) {
1675
- return this.credentials;
1676
- }
1677
- }
1678
- // packages/core/src/api/security/BearerCredentialsResolver.ts
1679
- class BearerCredentialsResolver {
1680
- name = "BearerCredentialsResolver";
1681
- token;
1682
- constructor(token) {
1683
- this.token = token;
1684
- }
1685
- async resolve(_server) {
1686
- const token = typeof this.token === "function" ? await this.token() : this.token;
1687
- return { authHeaders: { Authorization: `Bearer ${token}` } };
1688
- }
1689
- }
1690
1679
  // packages/core/src/api/security/ConnectedInfo.ts
1691
1680
  class ConnectedInfo {
1692
1681
  replyToId;
@@ -1706,6 +1695,8 @@ export {
1706
1695
  receivesContext,
1707
1696
  isAdvertised,
1708
1697
  createCRI,
1698
+ buildServerUrl,
1699
+ buildBrokerUrl,
1709
1700
  Zone,
1710
1701
  Version,
1711
1702
  TextEventFactory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"