@kinotic-ai/core 5.0.0-beta.2 → 5.0.0-beta.4

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.4",
1277
1296
  type: "module",
1278
1297
  files: [
1279
1298
  "dist"
@@ -1305,6 +1324,11 @@ var package_default = {
1305
1324
  "./package.json": "./package.json"
1306
1325
  },
1307
1326
  homepage: "https://github.com/kinotic-ai/kinotic",
1327
+ repository: {
1328
+ type: "git",
1329
+ url: "git+https://github.com/kinotic-ai/kinotic.git",
1330
+ directory: "kinotic-js/workspace/packages/core"
1331
+ },
1308
1332
  license: "Elastic License 2.0",
1309
1333
  publishConfig: {
1310
1334
  access: "public"
@@ -1316,44 +1340,37 @@ var package_default = {
1316
1340
  "ui-test": "vitest --ui --coverage.enabled=true --mode development"
1317
1341
  },
1318
1342
  devDependencies: {
1319
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
1320
- "@opentelemetry/resources": "^2.6.1",
1321
- "@opentelemetry/sdk-metrics": "^2.6.1",
1322
- "@opentelemetry/sdk-node": "^0.214.0",
1323
- "@opentelemetry/sdk-trace-node": "^2.6.1",
1343
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.221.0",
1344
+ "@opentelemetry/resources": "^2.10.0",
1345
+ "@opentelemetry/sdk-metrics": "^2.10.0",
1346
+ "@opentelemetry/sdk-node": "^0.221.0",
1347
+ "@opentelemetry/sdk-trace-node": "^2.10.0",
1348
+ "@types/debug": "^4.1.13",
1324
1349
  "@types/node": "^25.6.0",
1325
- "@types/uuid": "^11.0.0",
1326
1350
  "@types/ws": "^8.18.0",
1327
1351
  "@vitest/coverage-v8": "^4.1.4",
1328
1352
  "@vitest/runner": "^4.1.4",
1329
1353
  "@vitest/ui": "^4.1.4",
1330
- allure: "^3.4.1",
1331
- "allure-vitest": "^3.7.1",
1354
+ allure: "^3.14.3",
1355
+ "allure-vitest": "^3.10.2",
1332
1356
  dotenv: "^17.4.1",
1333
1357
  "properties-file": "^4.0.0",
1334
1358
  testcontainers: "^11.14.0",
1335
1359
  tslib: "^2.8.1",
1336
1360
  typescript: "^6.0.2",
1337
- vitest: "^4.1.4",
1338
- ws: "^8.20.0"
1361
+ vitest: "^4.1.4"
1339
1362
  },
1340
1363
  dependencies: {
1341
1364
  "@opentelemetry/api": "^1.9.1",
1342
1365
  "@opentelemetry/semantic-conventions": "^1.40.0",
1343
1366
  "@stomp/rx-stomp": "^2.4.0",
1344
1367
  "@stomp/stompjs": "^7.3.0",
1345
- "@types/debug": "^4.1.13",
1346
1368
  debug: "^4.4.3",
1347
1369
  "p-tap": "^4.0.0",
1348
1370
  rxjs: "^7.8.2",
1349
1371
  "typescript-optional": "3.0.0-alpha.3",
1350
1372
  uuid: "^13.0.0",
1351
- ws: "^8.18.0"
1352
- },
1353
- peerDependenciesMeta: {
1354
- typescript: {
1355
- optional: true
1356
- }
1373
+ ws: "^8.21.0"
1357
1374
  }
1358
1375
  };
1359
1376
 
@@ -1765,34 +1782,6 @@ class Order {
1765
1782
  class Sort {
1766
1783
  orders = [];
1767
1784
  }
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
1785
  // packages/core/src/api/security/ConnectedInfo.ts
1797
1786
  class ConnectedInfo {
1798
1787
  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.4",
1171
1188
  type: "module",
1172
1189
  files: [
1173
1190
  "dist"
@@ -1199,6 +1216,11 @@ var package_default = {
1199
1216
  "./package.json": "./package.json"
1200
1217
  },
1201
1218
  homepage: "https://github.com/kinotic-ai/kinotic",
1219
+ repository: {
1220
+ type: "git",
1221
+ url: "git+https://github.com/kinotic-ai/kinotic.git",
1222
+ directory: "kinotic-js/workspace/packages/core"
1223
+ },
1202
1224
  license: "Elastic License 2.0",
1203
1225
  publishConfig: {
1204
1226
  access: "public"
@@ -1210,44 +1232,37 @@ var package_default = {
1210
1232
  "ui-test": "vitest --ui --coverage.enabled=true --mode development"
1211
1233
  },
1212
1234
  devDependencies: {
1213
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
1214
- "@opentelemetry/resources": "^2.6.1",
1215
- "@opentelemetry/sdk-metrics": "^2.6.1",
1216
- "@opentelemetry/sdk-node": "^0.214.0",
1217
- "@opentelemetry/sdk-trace-node": "^2.6.1",
1235
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.221.0",
1236
+ "@opentelemetry/resources": "^2.10.0",
1237
+ "@opentelemetry/sdk-metrics": "^2.10.0",
1238
+ "@opentelemetry/sdk-node": "^0.221.0",
1239
+ "@opentelemetry/sdk-trace-node": "^2.10.0",
1240
+ "@types/debug": "^4.1.13",
1218
1241
  "@types/node": "^25.6.0",
1219
- "@types/uuid": "^11.0.0",
1220
1242
  "@types/ws": "^8.18.0",
1221
1243
  "@vitest/coverage-v8": "^4.1.4",
1222
1244
  "@vitest/runner": "^4.1.4",
1223
1245
  "@vitest/ui": "^4.1.4",
1224
- allure: "^3.4.1",
1225
- "allure-vitest": "^3.7.1",
1246
+ allure: "^3.14.3",
1247
+ "allure-vitest": "^3.10.2",
1226
1248
  dotenv: "^17.4.1",
1227
1249
  "properties-file": "^4.0.0",
1228
1250
  testcontainers: "^11.14.0",
1229
1251
  tslib: "^2.8.1",
1230
1252
  typescript: "^6.0.2",
1231
- vitest: "^4.1.4",
1232
- ws: "^8.20.0"
1253
+ vitest: "^4.1.4"
1233
1254
  },
1234
1255
  dependencies: {
1235
1256
  "@opentelemetry/api": "^1.9.1",
1236
1257
  "@opentelemetry/semantic-conventions": "^1.40.0",
1237
1258
  "@stomp/rx-stomp": "^2.4.0",
1238
1259
  "@stomp/stompjs": "^7.3.0",
1239
- "@types/debug": "^4.1.13",
1240
1260
  debug: "^4.4.3",
1241
1261
  "p-tap": "^4.0.0",
1242
1262
  rxjs: "^7.8.2",
1243
1263
  "typescript-optional": "3.0.0-alpha.3",
1244
1264
  uuid: "^13.0.0",
1245
- ws: "^8.18.0"
1246
- },
1247
- peerDependenciesMeta: {
1248
- typescript: {
1249
- optional: true
1250
- }
1265
+ ws: "^8.21.0"
1251
1266
  }
1252
1267
  };
1253
1268
 
@@ -1659,34 +1674,6 @@ class Order {
1659
1674
  class Sort {
1660
1675
  orders = [];
1661
1676
  }
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
1677
  // packages/core/src/api/security/ConnectedInfo.ts
1691
1678
  class ConnectedInfo {
1692
1679
  replyToId;
@@ -1706,6 +1693,8 @@ export {
1706
1693
  receivesContext,
1707
1694
  isAdvertised,
1708
1695
  createCRI,
1696
+ buildServerUrl,
1697
+ buildBrokerUrl,
1709
1698
  Zone,
1710
1699
  Version,
1711
1700
  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.4",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -32,6 +32,11 @@
32
32
  "./package.json": "./package.json"
33
33
  },
34
34
  "homepage": "https://github.com/kinotic-ai/kinotic",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/kinotic-ai/kinotic.git",
38
+ "directory": "kinotic-js/workspace/packages/core"
39
+ },
35
40
  "license": "Elastic License 2.0",
36
41
  "publishConfig": {
37
42
  "access": "public"
@@ -43,43 +48,36 @@
43
48
  "ui-test": "vitest --ui --coverage.enabled=true --mode development"
44
49
  },
45
50
  "devDependencies": {
46
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
47
- "@opentelemetry/resources": "^2.6.1",
48
- "@opentelemetry/sdk-metrics": "^2.6.1",
49
- "@opentelemetry/sdk-node": "^0.214.0",
50
- "@opentelemetry/sdk-trace-node": "^2.6.1",
51
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.221.0",
52
+ "@opentelemetry/resources": "^2.10.0",
53
+ "@opentelemetry/sdk-metrics": "^2.10.0",
54
+ "@opentelemetry/sdk-node": "^0.221.0",
55
+ "@opentelemetry/sdk-trace-node": "^2.10.0",
56
+ "@types/debug": "^4.1.13",
51
57
  "@types/node": "^25.6.0",
52
- "@types/uuid": "^11.0.0",
53
58
  "@types/ws": "^8.18.0",
54
59
  "@vitest/coverage-v8": "^4.1.4",
55
60
  "@vitest/runner": "^4.1.4",
56
61
  "@vitest/ui": "^4.1.4",
57
- "allure": "^3.4.1",
58
- "allure-vitest": "^3.7.1",
62
+ "allure": "^3.14.3",
63
+ "allure-vitest": "^3.10.2",
59
64
  "dotenv": "^17.4.1",
60
65
  "properties-file": "^4.0.0",
61
66
  "testcontainers": "^11.14.0",
62
67
  "tslib": "^2.8.1",
63
68
  "typescript": "^6.0.2",
64
- "vitest": "^4.1.4",
65
- "ws": "^8.20.0"
69
+ "vitest": "^4.1.4"
66
70
  },
67
71
  "dependencies": {
68
72
  "@opentelemetry/api": "^1.9.1",
69
73
  "@opentelemetry/semantic-conventions": "^1.40.0",
70
74
  "@stomp/rx-stomp": "^2.4.0",
71
75
  "@stomp/stompjs": "^7.3.0",
72
- "@types/debug": "^4.1.13",
73
76
  "debug": "^4.4.3",
74
77
  "p-tap": "^4.0.0",
75
78
  "rxjs": "^7.8.2",
76
79
  "typescript-optional": "3.0.0-alpha.3",
77
80
  "uuid": "^13.0.0",
78
- "ws": "^8.18.0"
79
- },
80
- "peerDependenciesMeta": {
81
- "typescript": {
82
- "optional": true
83
- }
81
+ "ws": "^8.21.0"
84
82
  }
85
83
  }