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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,30 @@
1
1
  /**
2
+ * The outcome of credential resolution: the headers to present on the WebSocket upgrade and
3
+ * the scope the caller belongs to. {@link authHeaders} undefined means the connection
4
+ * authenticates with the browser session cookie instead of headers.
5
+ */
6
+ interface ResolvedCredentials {
7
+ authHeaders?: Record<string, string>;
8
+ organizationId?: string;
9
+ applicationId?: string;
10
+ }
11
+ /**
12
+ * Finds the credentials a Kinotic connection authenticates with. Consulted on every
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
15
+ * {@link ChainedCredentialsResolver} the next resolver tries; at the top level the connect
16
+ * fails naming every resolver consulted.
17
+ */
18
+ interface CredentialsResolver {
19
+ /** Short name shown in the connect failure that lists the resolvers consulted. */
20
+ readonly name: string;
21
+ /**
22
+ * Resolves credentials for a connection to the given server, or null when this resolver
23
+ * has none to offer.
24
+ */
25
+ resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
26
+ }
27
+ /**
2
28
  * Structural shape of a WebSocket used by the underlying STOMP client.
3
29
  * Copied from the WebSocket interface to avoid pulling in the DOM typelib,
4
30
  * so this type stays usable in Node environments where `lib: dom` is not set.
@@ -34,19 +60,29 @@ declare enum SessionKeepAliveMode {
34
60
  CONNECTION = "CONNECTION"
35
61
  }
36
62
  /**
37
- * ConnectionInfo provides the information needed to connect to the kinoitc server.
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).
38
69
  *
39
- * Authentication is performed during the WebSocket upgrade (handshake), not in
40
- * the STOMP CONNECT frame. In the browser, log in via the REST endpoints first
41
- * and the established session cookie will be used. In Node, supply a
42
- * {@link WebSocketFactory} that attaches the required upgrade headers.
70
+ * Authentication is performed during the WebSocket upgrade (handshake), not in the STOMP
71
+ * CONNECT frame: the resolved credentials supply the upgrade headers, or none for
72
+ * session-cookie auth.
43
73
  */
44
- declare class ConnectionInfo extends ServerInfo {
74
+ interface ConnectOptions {
75
+ host?: string;
76
+ port?: number | null;
77
+ useSSL?: boolean | null;
78
+ /**
79
+ * Finds the credentials this connection authenticates with, consulted on every
80
+ * (re)connect. Absent, the default resolution chain applies.
81
+ */
82
+ credentials?: CredentialsResolver;
45
83
  /**
46
- * Optional factory used to create the underlying WebSocket. Use this in
47
- * Node to attach custom headers (such as Authorization) to the upgrade
48
- * request. If omitted, a default WebSocket is created and authentication
49
- * is expected to come from the session cookie.
84
+ * Escape hatch: fully replaces socket construction and credential resolution. When set,
85
+ * {@link credentials} is ignored and the factory owns the upgrade request.
50
86
  */
51
87
  webSocketFactory?: WebSocketFactory;
52
88
  /**
@@ -60,7 +96,7 @@ declare class ConnectionInfo extends ServerInfo {
60
96
  * Defaults to {@link SessionKeepAliveMode.ACTIVITY}.
61
97
  * Use {@link SessionKeepAliveMode.NONE} to remove the session when the websocket connection closes.
62
98
  */
63
- sessionKeepAlive: SessionKeepAliveMode;
99
+ sessionKeepAlive?: SessionKeepAliveMode;
64
100
  }
65
101
  import { Optional } from "typescript-optional";
66
102
  import { Observable } from "rxjs";
@@ -183,11 +219,12 @@ interface IEventBus {
183
219
  */
184
220
  serverInfo: ServerInfo | null;
185
221
  /**
186
- * Requests a connection to the given Stomp url
187
- * @param connectionInfo provides the information needed to connect to the kinoitc server
222
+ * Connects to a Kinotic server using fully resolved options — {@link IKinotic#connect}
223
+ * performs the resolution.
224
+ * @param options the resolved connection options
188
225
  * @return Promise containing the result of the initial connection attempt
189
226
  */
190
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
227
+ connect(options: ConnectOptions): Promise<ConnectedInfo>;
191
228
  /**
192
229
  * Disconnects the client from the server
193
230
  * This will clear any subscriptions and close the connection
@@ -253,7 +290,7 @@ declare enum EventConstants {
253
290
  CONTENT_LENGTH_HEADER = "content-length",
254
291
  REPLY_TO_HEADER = "reply-to",
255
292
  /**
256
- * Header provided by the server on connection to provide the {@link ConnectionInfo} as a JSON string
293
+ * Header provided by the server on connection to provide the {@link ConnectedInfo} as a JSON string
257
294
  */
258
295
  CONNECTED_INFO_HEADER = "connected-info",
259
296
  /**
@@ -613,11 +650,12 @@ interface IKinotic {
613
650
  */
614
651
  defaultZone: string | null;
615
652
  /**
616
- * Requests a connection to the given Stomp url
617
- * @param connectionInfo provides the information needed to connect to the kinoitc server
653
+ * Connects to a Kinotic server. Every option is optional: absent server fields and
654
+ * credentials resolve from the environment — see {@link ConnectOptions}.
655
+ * @param options overrides for the resolved connection, or nothing to resolve everything
618
656
  * @return Promise containing the result of the initial connection attempt
619
657
  */
620
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
658
+ connect(options?: ConnectOptions): Promise<ConnectedInfo>;
621
659
  /**
622
660
  * Disconnects the client from the server
623
661
  * This will clear any subscriptions and close the connection
@@ -655,11 +693,12 @@ declare class KinoticSingleton implements IKinotic {
655
693
  get eventBus(): IEventBus;
656
694
  set eventBus(eventBus: IEventBus);
657
695
  /**
658
- * Requests a connection to the given Stomp url
659
- * @param connectionInfo provides the information needed to connect to the kinoitc server
696
+ * Connects to a Kinotic server. Every option is optional: absent server fields and
697
+ * credentials resolve from the environment — see {@link ConnectOptions}.
698
+ * @param options overrides for the resolved connection, or nothing to resolve everything
660
699
  * @return Promise containing the result of the initial connection attempt
661
700
  */
662
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
701
+ connect(options?: ConnectOptions): Promise<ConnectedInfo>;
663
702
  /**
664
703
  * Disconnects the client from the server
665
704
  * This will clear any subscriptions and close the connection
@@ -1174,7 +1213,7 @@ declare class EventBus implements IEventBus {
1174
1213
  get fatalErrors(): Observable3<Error>;
1175
1214
  isConnectionActive(): boolean;
1176
1215
  isConnected(): boolean;
1177
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
1216
+ connect(options: ConnectOptions): Promise<ConnectedInfo>;
1178
1217
  disconnect(force?: boolean): Promise<void>;
1179
1218
  /** Runs connect and disconnect one at a time so they never overlap on the shared socket. */
1180
1219
  private serializeLifecycle;
@@ -1209,50 +1248,58 @@ declare class EventBus implements IEventBus {
1209
1248
  private _observe;
1210
1249
  }
1211
1250
  /**
1212
- * Supplies the headers attached to the WebSocket upgrade request when a Node/Bun
1213
- * client authenticates during the handshake. Implementations are consulted on every
1214
- * (re)connect, so a provider backing short-lived credentials can refresh them each time.
1251
+ * Kinotic client credentials: a clientId/clientSecret pair presented as upgrade headers —
1252
+ * a user's email and password, or a machine identity's id and provisioned secret. Scope is
1253
+ * structural, determined by which ids are given: neither → SYSTEM, organizationId only →
1254
+ * ORGANIZATION, both → APPLICATION. For machines the ids are optional; when supplied they
1255
+ * must agree with the machine's own scope.
1215
1256
  */
1216
- interface IAuthProvider {
1217
- /**
1218
- * Returns the headers to attach to the WebSocket upgrade request.
1219
- * Invoked on every (re)connect.
1220
- */
1221
- getAuthHeaders(): Promise<Record<string, string>> | Record<string, string>;
1257
+ declare class BasicCredentialsResolver implements CredentialsResolver {
1258
+ readonly name: string;
1259
+ private readonly credentials;
1260
+ constructor(clientId: string, clientSecret: string, organizationId?: string, applicationId?: string);
1261
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials>;
1222
1262
  }
1223
1263
  /**
1224
- * Builds a {@link WebSocketFactory} that authenticates during the WebSocket upgrade
1225
- * by attaching the headers from {@link IAuthProvider#getAuthHeaders} to the request.
1226
- * The provider is consulted on every (re)connect, so short-lived credentials are
1227
- * refreshed each time. Supply the result as {@link ConnectionInfo#webSocketFactory}.
1228
- *
1229
- * For Node/Bun callers: the returned factory creates the socket with the runtime
1230
- * WebSocket's `headers` option, which the DOM `WebSocket` typings omit and the
1231
- * browser WebSocket does not support. Browser callers continue to omit
1232
- * `webSocketFactory` and authenticate via the session cookie from a prior REST login.
1264
+ * A bearer token presented as the {@code Authorization} upgrade header. The supplier form is
1265
+ * invoked on every (re)connect, so short-lived tokens can be refreshed each time.
1266
+ */
1267
+ declare class BearerCredentialsResolver implements CredentialsResolver {
1268
+ readonly name: string;
1269
+ private readonly token;
1270
+ constructor(token: string | (() => Promise<string> | string));
1271
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials>;
1272
+ }
1273
+ /**
1274
+ * Consults each resolver in order and returns the first non-null result. The default
1275
+ * credential resolution every {@code Kinotic.connect()} without explicit credentials uses is
1276
+ * a chain; supply your own to control the sources or their order.
1233
1277
  */
1234
- declare function createAuthenticatedWebSocketFactory(serverInfo: ServerInfo, authProvider: IAuthProvider): WebSocketFactory;
1278
+ declare class ChainedCredentialsResolver implements CredentialsResolver {
1279
+ readonly name: string;
1280
+ private readonly resolvers;
1281
+ constructor(...resolvers: CredentialsResolver[]);
1282
+ resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
1283
+ }
1235
1284
  /**
1236
- * {@link IAuthProvider} that authenticates with HTTP Basic, sending
1237
- * `Authorization: Basic base64(login:passcode)` on every (re)connect.
1285
+ * Credentials from environment variables — the zero-code path for machines and services:
1286
+ * {@code KINOTIC_CLIENT_ID} + {@code KINOTIC_CLIENT_SECRET} (with optional
1287
+ * {@code KINOTIC_ORGANIZATION_ID} / {@code KINOTIC_APPLICATION_ID}) resolve as client
1288
+ * credentials, or {@code KINOTIC_TOKEN} as a bearer token. Resolves to null in a browser or
1289
+ * when none of the variables are set.
1238
1290
  */
1239
- declare class BasicAuthProvider implements IAuthProvider {
1240
- private readonly authHeader;
1241
- constructor(login: string, passcode: string);
1242
- getAuthHeaders(): Record<string, string>;
1291
+ declare class EnvCredentialsResolver implements CredentialsResolver {
1292
+ readonly name: string;
1293
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials | null>;
1243
1294
  }
1244
1295
  /**
1245
- * {@link IAuthProvider} that authenticates with a bearer token, sending
1246
- * `Authorization: Bearer <token>` on every (re)connect.
1247
- *
1248
- * Pass a string for a static token, or a supplier when the token is short-lived
1249
- * and must be refreshed before each connect (for example, an OAuth device-grant
1250
- * access token). The supplier may be async and is invoked on every (re)connect.
1296
+ * The browser's session cookie, established by a prior REST login. Resolves to credentials
1297
+ * with no headers — the cookie rides the upgrade request on its own — and only in an
1298
+ * environment that has one (a browser); elsewhere it passes to the next resolver.
1251
1299
  */
1252
- declare class BearerTokenAuthProvider implements IAuthProvider {
1253
- private readonly token;
1254
- constructor(token: string | (() => Promise<string> | string));
1255
- getAuthHeaders(): Promise<Record<string, string>>;
1300
+ declare class SessionCredentialsResolver implements CredentialsResolver {
1301
+ readonly name: string;
1302
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials | null>;
1256
1303
  }
1257
1304
  /**
1258
1305
  * Some common constants used for the {@link Participant} and {@link Participant#getMetadata()}
@@ -1268,4 +1315,4 @@ declare class ParticipantConstants {
1268
1315
  /** The clientId TestSecurityService (clienttest profile) maps to the ANONYMOUS role in core package tests. */
1269
1316
  static readonly CLI_PARTICIPANT_ID: string;
1270
1317
  }
1271
- export { validateZone, validateLabel, receivesContext, isAdvertised, createCRI, createAuthenticatedWebSocketFactory, Zone, 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, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,30 @@
1
1
  /**
2
+ * The outcome of credential resolution: the headers to present on the WebSocket upgrade and
3
+ * the scope the caller belongs to. {@link authHeaders} undefined means the connection
4
+ * authenticates with the browser session cookie instead of headers.
5
+ */
6
+ interface ResolvedCredentials {
7
+ authHeaders?: Record<string, string>;
8
+ organizationId?: string;
9
+ applicationId?: string;
10
+ }
11
+ /**
12
+ * Finds the credentials a Kinotic connection authenticates with. Consulted on every
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
15
+ * {@link ChainedCredentialsResolver} the next resolver tries; at the top level the connect
16
+ * fails naming every resolver consulted.
17
+ */
18
+ interface CredentialsResolver {
19
+ /** Short name shown in the connect failure that lists the resolvers consulted. */
20
+ readonly name: string;
21
+ /**
22
+ * Resolves credentials for a connection to the given server, or null when this resolver
23
+ * has none to offer.
24
+ */
25
+ resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
26
+ }
27
+ /**
2
28
  * Structural shape of a WebSocket used by the underlying STOMP client.
3
29
  * Copied from the WebSocket interface to avoid pulling in the DOM typelib,
4
30
  * so this type stays usable in Node environments where `lib: dom` is not set.
@@ -34,19 +60,29 @@ declare enum SessionKeepAliveMode {
34
60
  CONNECTION = "CONNECTION"
35
61
  }
36
62
  /**
37
- * ConnectionInfo provides the information needed to connect to the kinoitc server.
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).
38
69
  *
39
- * Authentication is performed during the WebSocket upgrade (handshake), not in
40
- * the STOMP CONNECT frame. In the browser, log in via the REST endpoints first
41
- * and the established session cookie will be used. In Node, supply a
42
- * {@link WebSocketFactory} that attaches the required upgrade headers.
70
+ * Authentication is performed during the WebSocket upgrade (handshake), not in the STOMP
71
+ * CONNECT frame: the resolved credentials supply the upgrade headers, or none for
72
+ * session-cookie auth.
43
73
  */
44
- declare class ConnectionInfo extends ServerInfo {
74
+ interface ConnectOptions {
75
+ host?: string;
76
+ port?: number | null;
77
+ useSSL?: boolean | null;
78
+ /**
79
+ * Finds the credentials this connection authenticates with, consulted on every
80
+ * (re)connect. Absent, the default resolution chain applies.
81
+ */
82
+ credentials?: CredentialsResolver;
45
83
  /**
46
- * Optional factory used to create the underlying WebSocket. Use this in
47
- * Node to attach custom headers (such as Authorization) to the upgrade
48
- * request. If omitted, a default WebSocket is created and authentication
49
- * is expected to come from the session cookie.
84
+ * Escape hatch: fully replaces socket construction and credential resolution. When set,
85
+ * {@link credentials} is ignored and the factory owns the upgrade request.
50
86
  */
51
87
  webSocketFactory?: WebSocketFactory;
52
88
  /**
@@ -60,7 +96,7 @@ declare class ConnectionInfo extends ServerInfo {
60
96
  * Defaults to {@link SessionKeepAliveMode.ACTIVITY}.
61
97
  * Use {@link SessionKeepAliveMode.NONE} to remove the session when the websocket connection closes.
62
98
  */
63
- sessionKeepAlive: SessionKeepAliveMode;
99
+ sessionKeepAlive?: SessionKeepAliveMode;
64
100
  }
65
101
  import { Optional } from "typescript-optional";
66
102
  import { Observable } from "rxjs";
@@ -183,11 +219,12 @@ interface IEventBus {
183
219
  */
184
220
  serverInfo: ServerInfo | null;
185
221
  /**
186
- * Requests a connection to the given Stomp url
187
- * @param connectionInfo provides the information needed to connect to the kinoitc server
222
+ * Connects to a Kinotic server using fully resolved options — {@link IKinotic#connect}
223
+ * performs the resolution.
224
+ * @param options the resolved connection options
188
225
  * @return Promise containing the result of the initial connection attempt
189
226
  */
190
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
227
+ connect(options: ConnectOptions): Promise<ConnectedInfo>;
191
228
  /**
192
229
  * Disconnects the client from the server
193
230
  * This will clear any subscriptions and close the connection
@@ -253,7 +290,7 @@ declare enum EventConstants {
253
290
  CONTENT_LENGTH_HEADER = "content-length",
254
291
  REPLY_TO_HEADER = "reply-to",
255
292
  /**
256
- * Header provided by the server on connection to provide the {@link ConnectionInfo} as a JSON string
293
+ * Header provided by the server on connection to provide the {@link ConnectedInfo} as a JSON string
257
294
  */
258
295
  CONNECTED_INFO_HEADER = "connected-info",
259
296
  /**
@@ -613,11 +650,12 @@ interface IKinotic {
613
650
  */
614
651
  defaultZone: string | null;
615
652
  /**
616
- * Requests a connection to the given Stomp url
617
- * @param connectionInfo provides the information needed to connect to the kinoitc server
653
+ * Connects to a Kinotic server. Every option is optional: absent server fields and
654
+ * credentials resolve from the environment — see {@link ConnectOptions}.
655
+ * @param options overrides for the resolved connection, or nothing to resolve everything
618
656
  * @return Promise containing the result of the initial connection attempt
619
657
  */
620
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
658
+ connect(options?: ConnectOptions): Promise<ConnectedInfo>;
621
659
  /**
622
660
  * Disconnects the client from the server
623
661
  * This will clear any subscriptions and close the connection
@@ -655,11 +693,12 @@ declare class KinoticSingleton implements IKinotic {
655
693
  get eventBus(): IEventBus;
656
694
  set eventBus(eventBus: IEventBus);
657
695
  /**
658
- * Requests a connection to the given Stomp url
659
- * @param connectionInfo provides the information needed to connect to the kinoitc server
696
+ * Connects to a Kinotic server. Every option is optional: absent server fields and
697
+ * credentials resolve from the environment — see {@link ConnectOptions}.
698
+ * @param options overrides for the resolved connection, or nothing to resolve everything
660
699
  * @return Promise containing the result of the initial connection attempt
661
700
  */
662
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
701
+ connect(options?: ConnectOptions): Promise<ConnectedInfo>;
663
702
  /**
664
703
  * Disconnects the client from the server
665
704
  * This will clear any subscriptions and close the connection
@@ -1174,7 +1213,7 @@ declare class EventBus implements IEventBus {
1174
1213
  get fatalErrors(): Observable3<Error>;
1175
1214
  isConnectionActive(): boolean;
1176
1215
  isConnected(): boolean;
1177
- connect(connectionInfo: ConnectionInfo): Promise<ConnectedInfo>;
1216
+ connect(options: ConnectOptions): Promise<ConnectedInfo>;
1178
1217
  disconnect(force?: boolean): Promise<void>;
1179
1218
  /** Runs connect and disconnect one at a time so they never overlap on the shared socket. */
1180
1219
  private serializeLifecycle;
@@ -1209,50 +1248,58 @@ declare class EventBus implements IEventBus {
1209
1248
  private _observe;
1210
1249
  }
1211
1250
  /**
1212
- * Supplies the headers attached to the WebSocket upgrade request when a Node/Bun
1213
- * client authenticates during the handshake. Implementations are consulted on every
1214
- * (re)connect, so a provider backing short-lived credentials can refresh them each time.
1251
+ * Kinotic client credentials: a clientId/clientSecret pair presented as upgrade headers —
1252
+ * a user's email and password, or a machine identity's id and provisioned secret. Scope is
1253
+ * structural, determined by which ids are given: neither → SYSTEM, organizationId only →
1254
+ * ORGANIZATION, both → APPLICATION. For machines the ids are optional; when supplied they
1255
+ * must agree with the machine's own scope.
1215
1256
  */
1216
- interface IAuthProvider {
1217
- /**
1218
- * Returns the headers to attach to the WebSocket upgrade request.
1219
- * Invoked on every (re)connect.
1220
- */
1221
- getAuthHeaders(): Promise<Record<string, string>> | Record<string, string>;
1257
+ declare class BasicCredentialsResolver implements CredentialsResolver {
1258
+ readonly name: string;
1259
+ private readonly credentials;
1260
+ constructor(clientId: string, clientSecret: string, organizationId?: string, applicationId?: string);
1261
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials>;
1222
1262
  }
1223
1263
  /**
1224
- * Builds a {@link WebSocketFactory} that authenticates during the WebSocket upgrade
1225
- * by attaching the headers from {@link IAuthProvider#getAuthHeaders} to the request.
1226
- * The provider is consulted on every (re)connect, so short-lived credentials are
1227
- * refreshed each time. Supply the result as {@link ConnectionInfo#webSocketFactory}.
1228
- *
1229
- * For Node/Bun callers: the returned factory creates the socket with the runtime
1230
- * WebSocket's `headers` option, which the DOM `WebSocket` typings omit and the
1231
- * browser WebSocket does not support. Browser callers continue to omit
1232
- * `webSocketFactory` and authenticate via the session cookie from a prior REST login.
1264
+ * A bearer token presented as the {@code Authorization} upgrade header. The supplier form is
1265
+ * invoked on every (re)connect, so short-lived tokens can be refreshed each time.
1266
+ */
1267
+ declare class BearerCredentialsResolver implements CredentialsResolver {
1268
+ readonly name: string;
1269
+ private readonly token;
1270
+ constructor(token: string | (() => Promise<string> | string));
1271
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials>;
1272
+ }
1273
+ /**
1274
+ * Consults each resolver in order and returns the first non-null result. The default
1275
+ * credential resolution every {@code Kinotic.connect()} without explicit credentials uses is
1276
+ * a chain; supply your own to control the sources or their order.
1233
1277
  */
1234
- declare function createAuthenticatedWebSocketFactory(serverInfo: ServerInfo, authProvider: IAuthProvider): WebSocketFactory;
1278
+ declare class ChainedCredentialsResolver implements CredentialsResolver {
1279
+ readonly name: string;
1280
+ private readonly resolvers;
1281
+ constructor(...resolvers: CredentialsResolver[]);
1282
+ resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
1283
+ }
1235
1284
  /**
1236
- * {@link IAuthProvider} that authenticates with HTTP Basic, sending
1237
- * `Authorization: Basic base64(login:passcode)` on every (re)connect.
1285
+ * Credentials from environment variables — the zero-code path for machines and services:
1286
+ * {@code KINOTIC_CLIENT_ID} + {@code KINOTIC_CLIENT_SECRET} (with optional
1287
+ * {@code KINOTIC_ORGANIZATION_ID} / {@code KINOTIC_APPLICATION_ID}) resolve as client
1288
+ * credentials, or {@code KINOTIC_TOKEN} as a bearer token. Resolves to null in a browser or
1289
+ * when none of the variables are set.
1238
1290
  */
1239
- declare class BasicAuthProvider implements IAuthProvider {
1240
- private readonly authHeader;
1241
- constructor(login: string, passcode: string);
1242
- getAuthHeaders(): Record<string, string>;
1291
+ declare class EnvCredentialsResolver implements CredentialsResolver {
1292
+ readonly name: string;
1293
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials | null>;
1243
1294
  }
1244
1295
  /**
1245
- * {@link IAuthProvider} that authenticates with a bearer token, sending
1246
- * `Authorization: Bearer <token>` on every (re)connect.
1247
- *
1248
- * Pass a string for a static token, or a supplier when the token is short-lived
1249
- * and must be refreshed before each connect (for example, an OAuth device-grant
1250
- * access token). The supplier may be async and is invoked on every (re)connect.
1296
+ * The browser's session cookie, established by a prior REST login. Resolves to credentials
1297
+ * with no headers — the cookie rides the upgrade request on its own — and only in an
1298
+ * environment that has one (a browser); elsewhere it passes to the next resolver.
1251
1299
  */
1252
- declare class BearerTokenAuthProvider implements IAuthProvider {
1253
- private readonly token;
1254
- constructor(token: string | (() => Promise<string> | string));
1255
- getAuthHeaders(): Promise<Record<string, string>>;
1300
+ declare class SessionCredentialsResolver implements CredentialsResolver {
1301
+ readonly name: string;
1302
+ resolve(_server: ServerInfo): Promise<ResolvedCredentials | null>;
1256
1303
  }
1257
1304
  /**
1258
1305
  * Some common constants used for the {@link Participant} and {@link Participant#getMetadata()}
@@ -1268,4 +1315,4 @@ declare class ParticipantConstants {
1268
1315
  /** The clientId TestSecurityService (clienttest profile) maps to the ANONYMOUS role in core package tests. */
1269
1316
  static readonly CLI_PARTICIPANT_ID: string;
1270
1317
  }
1271
- export { validateZone, validateLabel, receivesContext, isAdvertised, createCRI, createAuthenticatedWebSocketFactory, Zone, 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, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
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 };