@kinotic-ai/core 5.0.0-beta.2 → 5.0.0-beta.21
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/README.md +2 -2
- package/dist/index.cjs +851 -409
- package/dist/index.d.cts +316 -33
- package/dist/index.d.ts +316 -33
- package/dist/index.js +849 -407
- package/package.json +17 -18
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
|
|
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
|
|
64
|
-
* from the environment (the {@code KINOTIC_SERVER_HOST} /
|
|
65
|
-
* {@code KINOTIC_SERVER_USE_SSL} variables, the browser's own
|
|
66
|
-
* {@code https://api.kinotic.
|
|
67
|
-
* default {@link ChainedCredentialsResolver} (environment variables, then the
|
|
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.ai}), 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
|
-
|
|
76
|
-
|
|
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.
|
|
@@ -112,7 +124,7 @@ interface Identifiable<T> {
|
|
|
112
124
|
*
|
|
113
125
|
* This is the base shape every participant shares, regardless of scope, and is what RPC-only
|
|
114
126
|
* consumers work with directly. The Kinotic OS contract layers scope-typed participants on top
|
|
115
|
-
* of it — see the participant types in {@code @kinotic-ai/
|
|
127
|
+
* of it — see the participant types in {@code @kinotic-ai/management-api}.
|
|
116
128
|
*
|
|
117
129
|
* Mirrors the server {@code org.kinotic.core.api.security.Participant}.
|
|
118
130
|
*
|
|
@@ -134,7 +146,7 @@ interface IParticipant extends Identifiable<string> {
|
|
|
134
146
|
}
|
|
135
147
|
/**
|
|
136
148
|
* A logged-in participant on the RPC layer. Alias of {@link IParticipant}; the Kinotic OS contract
|
|
137
|
-
* ({@code @kinotic-ai/
|
|
149
|
+
* ({@code @kinotic-ai/management-api}) narrows this to scope-typed participants.
|
|
138
150
|
*
|
|
139
151
|
* Created by Navid Mitchell on 6/2/20
|
|
140
152
|
*/
|
|
@@ -147,7 +159,7 @@ declare class ConnectedInfo {
|
|
|
147
159
|
participant: Participant;
|
|
148
160
|
}
|
|
149
161
|
/**
|
|
150
|
-
* Part of the low level portion of
|
|
162
|
+
* Part of the low level portion of kinotic representing data to be processed
|
|
151
163
|
*
|
|
152
164
|
* This is similar to a Stomp Frame but with more required information and no control plane semantics.
|
|
153
165
|
*
|
|
@@ -203,17 +215,27 @@ interface IEvent {
|
|
|
203
215
|
setHeader(key: string, value: string): void;
|
|
204
216
|
}
|
|
205
217
|
/**
|
|
206
|
-
* Part of the low level portion of
|
|
218
|
+
* Part of the low level portion of kinotic representing a connection to a kinotic server
|
|
207
219
|
* This is similar to a Stomp Client but with more required information and no control plane semantics.
|
|
208
220
|
*
|
|
209
221
|
* Created by Navid Mitchell on 2019-01-04.
|
|
210
222
|
*/
|
|
211
223
|
interface IEventBus {
|
|
212
224
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
225
|
+
* Emits when the connection ends: an established connection drops before any reconnect, a failure
|
|
226
|
+
* closes it, or {@link disconnect} is called. It carries the failure that ended the connection, or
|
|
227
|
+
* null when nothing failed. The server releases everything it held for the connection at that moment:
|
|
228
|
+
* every request made on it is failed to its caller, and every invocation it was serving is failed to
|
|
229
|
+
* its requester. An end the client reconnects from leaves {@link IEventBus#isConnectionActive} true;
|
|
230
|
+
* one that needs a fresh {@link IEventBus#connect} leaves it false.
|
|
215
231
|
*/
|
|
216
|
-
|
|
232
|
+
connectionEnded: Observable<Error | null>;
|
|
233
|
+
/**
|
|
234
|
+
* Emits each time a connection is established: the first {@link connect}, and every reconnect the
|
|
235
|
+
* client makes after one ends. It carries the {@link ConnectedInfo} the server issued for that
|
|
236
|
+
* connection, which names the session the requests made on it belong to.
|
|
237
|
+
*/
|
|
238
|
+
connectionEstablished: Observable<ConnectedInfo>;
|
|
217
239
|
/**
|
|
218
240
|
* The {@link ServerInfo} used when connecting, if connected or null
|
|
219
241
|
*/
|
|
@@ -237,14 +259,15 @@ interface IEventBus {
|
|
|
237
259
|
disconnect(force?: boolean): Promise<void>;
|
|
238
260
|
/**
|
|
239
261
|
* Determines if the connection is connected.
|
|
240
|
-
* This means that there is an open connection to the
|
|
262
|
+
* This means that there is an open connection to the Kinotic server
|
|
241
263
|
* @return true if the connection is active false if not
|
|
242
264
|
*/
|
|
243
265
|
isConnected(): boolean;
|
|
244
266
|
/**
|
|
245
267
|
* Determines if the connection is active.
|
|
246
268
|
* This means {@link IEventBus#connect()} was called and was successful. The underlying connection may not be established yet.
|
|
247
|
-
*
|
|
269
|
+
* Subscriptions made while active are established once the connection comes up; sends require
|
|
270
|
+
* {@link IEventBus#isConnected}
|
|
248
271
|
* @return true if the connection is active false if not
|
|
249
272
|
*/
|
|
250
273
|
isConnectionActive(): boolean;
|
|
@@ -276,8 +299,11 @@ interface IEventBus {
|
|
|
276
299
|
*/
|
|
277
300
|
requestStream(event: IEvent, sendControlEvents: boolean): Observable<IEvent>;
|
|
278
301
|
/**
|
|
279
|
-
* Send a single {@link IEvent} to the connected server
|
|
302
|
+
* Send a single {@link IEvent} to the connected server. Events are never held for a later
|
|
303
|
+
* connection, so the caller decides what an event it could not send means — see
|
|
304
|
+
* {@link isConnected}.
|
|
280
305
|
* @param event to send
|
|
306
|
+
* @throws if the connection is not established
|
|
281
307
|
*/
|
|
282
308
|
send(event: IEvent): void;
|
|
283
309
|
}
|
|
@@ -290,6 +316,12 @@ declare enum EventConstants {
|
|
|
290
316
|
CONTENT_LENGTH_HEADER = "content-length",
|
|
291
317
|
REPLY_TO_HEADER = "reply-to",
|
|
292
318
|
/**
|
|
319
|
+
* The participant that sent the event, as JSON. The gateway writes it on every event it delivers to a
|
|
320
|
+
* client, from the participant authenticated on the connection the event came from, and drops any a
|
|
321
|
+
* client supplies; an event that originated inside the platform with no participant bound carries none.
|
|
322
|
+
*/
|
|
323
|
+
SENDER_HEADER = "sender",
|
|
324
|
+
/**
|
|
293
325
|
* Header provided by the server on connection to provide the {@link ConnectedInfo} as a JSON string
|
|
294
326
|
*/
|
|
295
327
|
CONNECTED_INFO_HEADER = "connected-info",
|
|
@@ -351,16 +383,25 @@ declare enum EventConstants {
|
|
|
351
383
|
TRACESTATE_HEADER = "tracestate"
|
|
352
384
|
}
|
|
353
385
|
/**
|
|
354
|
-
*
|
|
386
|
+
* The request context a {@link Context} method receives as its final parameter: the calling participant,
|
|
387
|
+
* plus whatever the registered {@link ContextInterceptor} adds. Extend it for type-safe context data.
|
|
355
388
|
*
|
|
356
389
|
* @author Navid Mitchell 🤝Grok
|
|
357
390
|
* @since 3/25/2025
|
|
358
391
|
*/
|
|
359
392
|
interface ServiceContext {
|
|
393
|
+
/**
|
|
394
|
+
* The participant that invoked the service method, as authenticated by the gateway on the calling
|
|
395
|
+
* connection. Absent when the invocation originated inside the platform with no participant bound,
|
|
396
|
+
* such as a scheduled job.
|
|
397
|
+
*/
|
|
398
|
+
participant?: Participant;
|
|
360
399
|
[key: string]: any;
|
|
361
400
|
}
|
|
362
401
|
/**
|
|
363
402
|
* Interface for interceptors that create or modify the ServiceContext before service method invocation.
|
|
403
|
+
* The context handed in already carries the calling participant; the context returned is the one the
|
|
404
|
+
* method receives.
|
|
364
405
|
*
|
|
365
406
|
* @author Navid Mitchell 🤝Grok
|
|
366
407
|
* @since 3/25/2025
|
|
@@ -369,9 +410,9 @@ interface ContextInterceptor<T extends ServiceContext> {
|
|
|
369
410
|
intercept(event: IEvent, context: T): Promise<T> | T;
|
|
370
411
|
}
|
|
371
412
|
/**
|
|
372
|
-
* `CRI` is a
|
|
413
|
+
* `CRI` is a Kinotic Resource Identifier used by Kinotic to route requests appropriately.
|
|
373
414
|
*
|
|
374
|
-
* The `CRI` is a URI where the parts are named differently for clarity as to their purpose within
|
|
415
|
+
* The `CRI` is a URI where the parts are named differently for clarity as to their purpose within Kinotic.
|
|
375
416
|
*
|
|
376
417
|
* Will be in a format as follows where anything surrounded with `[]` is optional:
|
|
377
418
|
*
|
|
@@ -409,7 +450,7 @@ interface CRI {
|
|
|
409
450
|
* The zone this `CRI` is addressed in, or `null` if un-zoned.
|
|
410
451
|
*
|
|
411
452
|
* The zone is the isolation boundary routing is validated against, such as
|
|
412
|
-
* `app.acme-org.orders-app` or `
|
|
453
|
+
* `app.acme-org.orders-app` or `management-api`.
|
|
413
454
|
*
|
|
414
455
|
* For the following CRI, `zone` would be the portion specified by `zone`:
|
|
415
456
|
*
|
|
@@ -528,6 +569,12 @@ declare class ServiceIdentifier {
|
|
|
528
569
|
* @return the cri for this {@link ServiceIdentifier}
|
|
529
570
|
*/
|
|
530
571
|
cri(): CRI;
|
|
572
|
+
/**
|
|
573
|
+
* The {@link CRI} of this service's shared, unscoped address. Every instance of a scoped
|
|
574
|
+
* service may listen here for the methods any instance can answer.
|
|
575
|
+
* @return the cri without the scope part
|
|
576
|
+
*/
|
|
577
|
+
unscopedCri(): CRI;
|
|
531
578
|
}
|
|
532
579
|
import { Observable as Observable2 } from "rxjs";
|
|
533
580
|
/**
|
|
@@ -600,6 +647,7 @@ interface IServiceRegistry {
|
|
|
600
647
|
*/
|
|
601
648
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
602
649
|
}
|
|
650
|
+
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
603
651
|
/**
|
|
604
652
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
605
653
|
*/
|
|
@@ -613,11 +661,20 @@ declare class TextEventFactory implements IEventFactory {
|
|
|
613
661
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
614
662
|
}
|
|
615
663
|
/**
|
|
664
|
+
* Declares the definitions of the project's published services, as `kinotic sync` generates them into the
|
|
665
|
+
* project's ServiceDefinitions module, so every registry registers each service in the platform's service
|
|
666
|
+
* directory with its definition when the service comes online. A definition declared again for a qualified
|
|
667
|
+
* name replaces the one held.
|
|
668
|
+
* @param definitions the generated definitions
|
|
669
|
+
*/
|
|
670
|
+
declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
|
|
671
|
+
/**
|
|
616
672
|
* The default implementation of {@link IServiceRegistry}
|
|
617
673
|
*/
|
|
618
674
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
619
675
|
private _eventBus;
|
|
620
676
|
private supervisors;
|
|
677
|
+
private entries;
|
|
621
678
|
private contextInterceptor;
|
|
622
679
|
private debugLogger;
|
|
623
680
|
constructor(eventBus: IEventBus);
|
|
@@ -626,6 +683,14 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
626
683
|
serviceProxy(serviceIdentifier: string): IServiceProxy;
|
|
627
684
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
628
685
|
unRegister(serviceIdentifier: ServiceIdentifier): void;
|
|
686
|
+
/**
|
|
687
|
+
* Registers every application service registered so far in the platform's service directory, with the
|
|
688
|
+
* definition the project declared for it, so the directory lists the service and the platform checks
|
|
689
|
+
* requests to it; a service the platform refuses fails the registration. A service registered later is
|
|
690
|
+
* registered in the directory as it registers here.
|
|
691
|
+
*/
|
|
692
|
+
registerEntries(): Promise<void>;
|
|
693
|
+
private registerEntry;
|
|
629
694
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
630
695
|
}
|
|
631
696
|
/**
|
|
@@ -693,8 +758,9 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
693
758
|
get eventBus(): IEventBus;
|
|
694
759
|
set eventBus(eventBus: IEventBus);
|
|
695
760
|
/**
|
|
696
|
-
* Connects to a Kinotic server
|
|
697
|
-
*
|
|
761
|
+
* Connects to a Kinotic server and registers the application services registered so far in the platform's
|
|
762
|
+
* service directory. Every option is optional: absent server fields and credentials resolve from the
|
|
763
|
+
* environment — see {@link ConnectOptions}.
|
|
698
764
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
699
765
|
* @return Promise containing the result of the initial connection attempt
|
|
700
766
|
*/
|
|
@@ -722,12 +788,99 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
722
788
|
*/
|
|
723
789
|
declare const Kinotic: KinoticSingleton;
|
|
724
790
|
/**
|
|
791
|
+
* A role a service declares for its resource type beside the built-in `viewer`, `editor` and `admin`: a bundle
|
|
792
|
+
* of the type's own permissions, defined by the generated model, named like a built-in role and granted the
|
|
793
|
+
* same way.
|
|
794
|
+
*/
|
|
795
|
+
interface AuthzRoleDeclaration {
|
|
796
|
+
/** The role's id, `<type>.<level>`, with a lowercase identifier no built-in role of the type uses as the level. */
|
|
797
|
+
id: string;
|
|
798
|
+
/** The short names of the permissions the role bundles, each one a permission a function of the type needs. */
|
|
799
|
+
permissions: string[];
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* What a service declares about the resource its functions act on, as {@link AuthzResource} declares it.
|
|
803
|
+
*/
|
|
804
|
+
interface AuthzResourceDeclaration {
|
|
805
|
+
/**
|
|
806
|
+
* The resource type, a single lowercase identifier such as `report`: it names the type in the model, prefixes
|
|
807
|
+
* the type's permissions (`report_can_view`) and roles (`report.editor`), and is the type of the object every
|
|
808
|
+
* function is checked on unless the function names another with {@link AuthzCheck}.
|
|
809
|
+
*/
|
|
810
|
+
value: string;
|
|
811
|
+
/**
|
|
812
|
+
* The type that contains this one, such as `tenant` for `report`: a grant made on an object of the parent type
|
|
813
|
+
* inherits to every object of this type inside it, and a function naming no object of its own, such as a
|
|
814
|
+
* listing or a create, is checked on the parent. Absent for a root type.
|
|
815
|
+
*/
|
|
816
|
+
parent?: string | null;
|
|
817
|
+
/**
|
|
818
|
+
* The object every function of the service is checked on, for a service whose functions act on one object the
|
|
819
|
+
* request does not name: a template over the caller's scope, `{@applicationId}` or `{@tenantId}`, or a literal
|
|
820
|
+
* id. A function naming its own object with {@link AuthzCheck} is unaffected.
|
|
821
|
+
*/
|
|
822
|
+
objectId?: string | null;
|
|
823
|
+
/**
|
|
824
|
+
* The permission every function of the service needs, as a short name such as `can_manage`, for a service whose
|
|
825
|
+
* functions all need the one permission whatever their names. A function declaring a permission of its own with
|
|
826
|
+
* {@link AuthzCheck} keeps it. Name the service's strictest permission.
|
|
827
|
+
*/
|
|
828
|
+
permission?: string | null;
|
|
829
|
+
/** Roles of this type beside the built-in ones, each bundling permissions the type's functions need. */
|
|
830
|
+
roles?: AuthzRoleDeclaration[] | null;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* What a function declares about its check, as {@link AuthzCheck} declares it; whatever is left out is derived
|
|
834
|
+
* from the function's name and parameters, as described on {@link AuthzResource}.
|
|
835
|
+
*/
|
|
836
|
+
interface AuthzCheckDeclaration {
|
|
837
|
+
/**
|
|
838
|
+
* The permission the function needs, as a short name such as `can_generate`. In the model it is prefixed by
|
|
839
|
+
* the type it is about, so `can_generate` on a `report` service is `report_can_generate`.
|
|
840
|
+
*/
|
|
841
|
+
permission?: string | null;
|
|
842
|
+
/**
|
|
843
|
+
* The type of the object the check is made on, when it is not the service's own type: the parent for a
|
|
844
|
+
* create, or a template such as `{definitionId}` for a function whose type is an argument.
|
|
845
|
+
*/
|
|
846
|
+
resource?: string | null;
|
|
847
|
+
/**
|
|
848
|
+
* The id of the object the check is made on, as a template over the function's parameters and the caller's
|
|
849
|
+
* scope: `{reportId}` is a parameter's value, `{registration.id}` a property of an object parameter, and
|
|
850
|
+
* `{@applicationId}` or `{@tenantId}` the matching id of the caller's scope.
|
|
851
|
+
*/
|
|
852
|
+
objectId?: string | null;
|
|
853
|
+
/**
|
|
854
|
+
* Short names of permissions on the same type that this permission also grants, so a role bundling
|
|
855
|
+
* `can_generate` declared with `implies: ['can_view']` views what it generates.
|
|
856
|
+
*/
|
|
857
|
+
implies?: string[] | null;
|
|
858
|
+
/**
|
|
859
|
+
* True for a function whose check must not be answered from the engine's caches, because a stale allow would
|
|
860
|
+
* be a security event.
|
|
861
|
+
*/
|
|
862
|
+
consistent?: boolean;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
725
865
|
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
726
866
|
* specific instance of the service, such as the copy running on a particular node. It is
|
|
727
867
|
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
728
868
|
*/
|
|
729
869
|
declare function Scope(value: Function, _context: ClassGetterDecoratorContext | ClassMethodDecoratorContext): void;
|
|
730
870
|
/**
|
|
871
|
+
* Marks a method of a scoped published service that any instance may answer, because its
|
|
872
|
+
* result does not depend on which instance executes it - typically a read of shared state
|
|
873
|
+
* rather than of the instance's own.
|
|
874
|
+
*
|
|
875
|
+
* A scoped service normally listens only at its scoped address, so every invocation must name
|
|
876
|
+
* an instance. When at least one method carries ScopeOptional, each instance also listens on
|
|
877
|
+
* the service's shared unscoped address, where only the annotated methods may be invoked: an
|
|
878
|
+
* unscoped invocation of any other method is rejected, since it would execute on whichever
|
|
879
|
+
* instance happened to receive it.
|
|
880
|
+
*/
|
|
881
|
+
declare function ScopeOptional(value: Function, _context: ClassMethodDecoratorContext): void;
|
|
882
|
+
declare function scopeOptionalMethodNames(instance: object): Set<string>;
|
|
883
|
+
/**
|
|
731
884
|
* Sets the semantic version a service registers under.
|
|
732
885
|
* @param version the version in X.Y.Z[-optional] format
|
|
733
886
|
*/
|
|
@@ -760,6 +913,56 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
760
913
|
*/
|
|
761
914
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
762
915
|
/**
|
|
916
|
+
* Marks a published service as acting on one type of resource, which `kinotic sync` reads from the class's
|
|
917
|
+
* source into the service's definition, which the runtime registers in the platform's service directory when
|
|
918
|
+
* the service comes online, so every request to the service is authorized before the service sees it. The type
|
|
919
|
+
* and the permissions its functions need become part of the application's authorization model, where roles
|
|
920
|
+
* bundle permissions and grants bind roles to callers.
|
|
921
|
+
*
|
|
922
|
+
* A function's check has three parts: the permission it needs, the type of the object it is checked on, and
|
|
923
|
+
* the id of that object. Each part is derived from the function's name and parameters where it can be;
|
|
924
|
+
* {@link AuthzCheck} states a part derivation gets wrong or cannot know, and {@link AuthzUnchecked} marks a
|
|
925
|
+
* function served with no check. A function left with no check and no marker fails the service's registration.
|
|
926
|
+
*
|
|
927
|
+
* The permission is derived from the first word of the function's name: `find`, `get`, `count`, `search` and
|
|
928
|
+
* `list` need `can_view`; `save`, `update` and `set` need `can_edit`; `delete` and `remove` need `can_delete`;
|
|
929
|
+
* `create` needs `can_edit` of this type on the parent. The object's id is the parameter named `id` or
|
|
930
|
+
* `<type>Id` (`reportId` for the type `report`), else the `id` of the first object parameter; a function with
|
|
931
|
+
* neither is checked on the parent, whose id is found the same way with the parent's name, else on the caller's
|
|
932
|
+
* own scope.
|
|
933
|
+
*
|
|
934
|
+
* Example: with `@AuthzResource({value: 'report', parent: 'tenant'})`, `findById(id: string)` is checked for
|
|
935
|
+
* `report_can_view` on the report `id` names, `save(report: Report)` for `report_can_edit` on the report
|
|
936
|
+
* `report.id` names, and `findReports()` for `report_can_view` on the caller's tenant, with nothing declared on
|
|
937
|
+
* them. A runtime holding no definition for a service declaring a resource refuses to serve it.
|
|
938
|
+
* @param declaration the resource type, or the type with its parent, object, permission and roles
|
|
939
|
+
*/
|
|
940
|
+
declare function AuthzResource(declaration: AuthzResourceDeclaration | string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
941
|
+
/**
|
|
942
|
+
* States a part of one function's check that derivation gets wrong or cannot know, which `kinotic sync` reads
|
|
943
|
+
* into the service's definition: the permission, the type of the object, or its id. Every part left out keeps
|
|
944
|
+
* the derived value, or the one the service declares with {@link AuthzResource}, so a function states only the
|
|
945
|
+
* part derivation misses. A function served with no check is marked {@link AuthzUnchecked} instead.
|
|
946
|
+
*
|
|
947
|
+
* Example: `@AuthzCheck({permission: 'can_report', objectId: '{registration.id}'})` on
|
|
948
|
+
* `heartbeat(registration: Registration)`, whose name derives no permission and whose id is inside the body.
|
|
949
|
+
* @param declaration the parts of the check derivation cannot read from the function's name and parameters
|
|
950
|
+
*/
|
|
951
|
+
declare function AuthzCheck(declaration: AuthzCheckDeclaration): (_value: Function, _context: ClassMethodDecoratorContext) => void;
|
|
952
|
+
/**
|
|
953
|
+
* Marks a function of an {@link AuthzResource} service that is served with no authorization check, which
|
|
954
|
+
* `kinotic sync` reads into the service's definition: any caller the service's zone admits may call it, and the
|
|
955
|
+
* service itself is responsible for answering only what the caller may see or do. It is for a function that has
|
|
956
|
+
* no object to check, such as a listing of the caller's own grants. A function carrying this and
|
|
957
|
+
* {@link AuthzCheck} fails the service's registration.
|
|
958
|
+
*/
|
|
959
|
+
declare function AuthzUnchecked(_value: Function, _context: ClassMethodDecoratorContext): void;
|
|
960
|
+
/**
|
|
961
|
+
* Returns whether the given service instance's class, or a class it extends, declares an {@link AuthzResource}.
|
|
962
|
+
* @param serviceInstance the service instance to inspect
|
|
963
|
+
*/
|
|
964
|
+
declare function declaresAuthzResource(serviceInstance: object): boolean;
|
|
965
|
+
/**
|
|
763
966
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
764
967
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
765
968
|
* on the same class refine the registration.
|
|
@@ -769,6 +972,35 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
|
|
|
769
972
|
* so it appears in directory listings
|
|
770
973
|
*/
|
|
771
974
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
975
|
+
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
976
|
+
/**
|
|
977
|
+
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
978
|
+
* it belongs to, where it is addressed, whether it is advertised, and its definition with the decorators it
|
|
979
|
+
* declares. The platform owns everything else about the directory's entry: the checks it derives, the tools the
|
|
980
|
+
* functions declare, and the service's liveness.
|
|
981
|
+
*/
|
|
982
|
+
interface ServiceDirectoryEntry {
|
|
983
|
+
/**
|
|
984
|
+
* The application the service belongs to, which its zone names.
|
|
985
|
+
*/
|
|
986
|
+
applicationId: string;
|
|
987
|
+
/**
|
|
988
|
+
* The zone the service is addressed in, the application's or a label under it.
|
|
989
|
+
*/
|
|
990
|
+
zone: string;
|
|
991
|
+
/**
|
|
992
|
+
* The version the service registers under, or null for none.
|
|
993
|
+
*/
|
|
994
|
+
version: string | null;
|
|
995
|
+
/**
|
|
996
|
+
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
997
|
+
*/
|
|
998
|
+
advertised: boolean;
|
|
999
|
+
/**
|
|
1000
|
+
* The service's definition: its functions, and the decorators it declares.
|
|
1001
|
+
*/
|
|
1002
|
+
serviceDefinition: ServiceDefinition2;
|
|
1003
|
+
}
|
|
772
1004
|
/**
|
|
773
1005
|
* Validates that the given zone satisfies the zone grammar
|
|
774
1006
|
* @param zone the zone to validate
|
|
@@ -1081,6 +1313,16 @@ interface ICrudServiceProxy<T extends Identifiable<string>> extends IEditableDat
|
|
|
1081
1313
|
*/
|
|
1082
1314
|
deleteById(id: string): Promise<void>;
|
|
1083
1315
|
/**
|
|
1316
|
+
* Deletes the entity with the given id and waits for the deletion to be visible in search
|
|
1317
|
+
* results before returning.
|
|
1318
|
+
* Use this when you need read-your-write consistency immediately after deletion.
|
|
1319
|
+
*
|
|
1320
|
+
* @param id must not be {@literal null}.
|
|
1321
|
+
* @return a {@link Promise} signaling when the deletion is visible to search.
|
|
1322
|
+
* @throws IllegalArgumentException in case the given {@literal identity} is {@literal null}.
|
|
1323
|
+
*/
|
|
1324
|
+
deleteByIdSync(id: string): Promise<void>;
|
|
1325
|
+
/**
|
|
1084
1326
|
* Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
|
|
1085
1327
|
*
|
|
1086
1328
|
* @param pageable the page settings to be used
|
|
@@ -1111,6 +1353,7 @@ declare class CrudServiceProxy<T extends Identifiable<string>> implements ICrudS
|
|
|
1111
1353
|
create(entity: T): Promise<T>;
|
|
1112
1354
|
createSync(entity: T): Promise<T>;
|
|
1113
1355
|
deleteById(id: string): Promise<void>;
|
|
1356
|
+
deleteByIdSync(id: string): Promise<void>;
|
|
1114
1357
|
findAll(pageable: Pageable): Promise<IterablePage<T>>;
|
|
1115
1358
|
findAllSinglePage(pageable: Pageable): Promise<Page<T>>;
|
|
1116
1359
|
findById(id: string): Promise<T>;
|
|
@@ -1200,17 +1443,20 @@ declare class Event implements IEvent {
|
|
|
1200
1443
|
*/
|
|
1201
1444
|
declare class EventBus implements IEventBus {
|
|
1202
1445
|
serverInfo: ServerInfo | null;
|
|
1446
|
+
private readonly log;
|
|
1203
1447
|
private stompConnectionManager;
|
|
1204
1448
|
private connectionLifecycle;
|
|
1205
|
-
private
|
|
1449
|
+
private disconnectRequests;
|
|
1206
1450
|
private requestRepliesObservable;
|
|
1207
1451
|
private requestRepliesSubject;
|
|
1208
1452
|
private requestRepliesSubscription;
|
|
1209
1453
|
private readonly activeCorrelationIds;
|
|
1210
1454
|
private readonly recentlyReaped;
|
|
1455
|
+
private readonly connectionEndedSubject;
|
|
1211
1456
|
private static readonly REAP_DEBOUNCE_MS;
|
|
1212
1457
|
constructor();
|
|
1213
|
-
get
|
|
1458
|
+
get connectionEnded(): Observable3<Error | null>;
|
|
1459
|
+
get connectionEstablished(): Observable3<ConnectedInfo>;
|
|
1214
1460
|
isConnectionActive(): boolean;
|
|
1215
1461
|
isConnected(): boolean;
|
|
1216
1462
|
connect(options: ConnectOptions): Promise<ConnectedInfo>;
|
|
@@ -1222,7 +1468,6 @@ declare class EventBus implements IEventBus {
|
|
|
1222
1468
|
requestStream(event: IEvent, sendControlEvents?: boolean): Observable3<IEvent>;
|
|
1223
1469
|
listen(_serverInfo: ServerInfo): Promise<void>;
|
|
1224
1470
|
observe(cri: string): Observable3<IEvent>;
|
|
1225
|
-
private cleanup;
|
|
1226
1471
|
/**
|
|
1227
1472
|
* Cancels a server stream whose reply arrived for a correlationId we no longer track. The server can't
|
|
1228
1473
|
* detect this itself since all requests share one reply destination, so the cancel is sent to the
|
|
@@ -1230,8 +1475,14 @@ declare class EventBus implements IEventBus {
|
|
|
1230
1475
|
*/
|
|
1231
1476
|
private cancelIfUnexpected;
|
|
1232
1477
|
/**
|
|
1478
|
+
* Sends the control event that stops the server stream identified by the correlationId.
|
|
1479
|
+
* @param cri the service the stream originates from
|
|
1480
|
+
* @param correlationId the correlationId of the stream to cancel
|
|
1481
|
+
*/
|
|
1482
|
+
private sendCancel;
|
|
1483
|
+
/**
|
|
1233
1484
|
* Tears down the shared request-replies stream so the next request rebuilds it against the
|
|
1234
|
-
*
|
|
1485
|
+
* connection's reply destination. Any in-flight requests are failed with the given reason since
|
|
1235
1486
|
* their replies can no longer be delivered.
|
|
1236
1487
|
*/
|
|
1237
1488
|
private resetRequestReplies;
|
|
@@ -1248,6 +1499,38 @@ declare class EventBus implements IEventBus {
|
|
|
1248
1499
|
private _observe;
|
|
1249
1500
|
}
|
|
1250
1501
|
/**
|
|
1502
|
+
* The error a service call fails with when the server answered it with an error reply. The reply body
|
|
1503
|
+
* describes the exception the server caught, so a caller can branch on which exception it was rather than
|
|
1504
|
+
* on a message written for people: a call that failed because the node serving it left the cluster carries
|
|
1505
|
+
* `RpcServiceUnavailableException`, one rejected because nothing served its address
|
|
1506
|
+
* `RpcMissingServiceException`.
|
|
1507
|
+
*/
|
|
1508
|
+
declare class RpcError extends Error {
|
|
1509
|
+
/**
|
|
1510
|
+
* The simple name of the exception the server caught, such as `RpcServiceUnavailableException`.
|
|
1511
|
+
*/
|
|
1512
|
+
readonly exceptionName: string;
|
|
1513
|
+
/**
|
|
1514
|
+
* The fully qualified class name of the exception the server caught.
|
|
1515
|
+
*/
|
|
1516
|
+
readonly exceptionClass: string;
|
|
1517
|
+
constructor(message: string, exceptionName: string, exceptionClass: string);
|
|
1518
|
+
/**
|
|
1519
|
+
* Builds the error an error reply carries. The body is the server's description of the exception when
|
|
1520
|
+
* it is JSON; otherwise the error header alone names the failure.
|
|
1521
|
+
* @param reply the error reply, which carries the error header
|
|
1522
|
+
*/
|
|
1523
|
+
static fromEvent(reply: IEvent): RpcError;
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Thrown when the calling participant is not permitted to do what it asked. A service that throws it
|
|
1527
|
+
* fails the invocation with an error reply named {@code AuthorizationException}, the name a Java
|
|
1528
|
+
* service's refusal carries, so a caller reads both the same way.
|
|
1529
|
+
*/
|
|
1530
|
+
declare class AuthorizationException extends Error {
|
|
1531
|
+
constructor(message?: string);
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1251
1534
|
* Kinotic client credentials: a clientId/clientSecret pair presented as upgrade headers —
|
|
1252
1535
|
* a user's email and password, or a machine identity's id and provisioned secret. Scope is
|
|
1253
1536
|
* structural, determined by which ids are given: neither → SYSTEM, organizationId only →
|
|
@@ -1290,7 +1573,7 @@ declare class ChainedCredentialsResolver implements CredentialsResolver {
|
|
|
1290
1573
|
*/
|
|
1291
1574
|
declare class EnvCredentialsResolver implements CredentialsResolver {
|
|
1292
1575
|
readonly name: string;
|
|
1293
|
-
resolve(
|
|
1576
|
+
resolve(server: ServerInfo): Promise<ResolvedCredentials | null>;
|
|
1294
1577
|
}
|
|
1295
1578
|
/**
|
|
1296
1579
|
* The browser's session cookie, established by a prior REST login. Resolves to credentials
|
|
@@ -1312,7 +1595,7 @@ declare class ParticipantConstants {
|
|
|
1312
1595
|
static readonly PARTICIPANT_TYPE_DELEGATE: string;
|
|
1313
1596
|
/** A non-human caller with its own credential — a platform daemon or an external API client. */
|
|
1314
1597
|
static readonly PARTICIPANT_TYPE_MACHINE: string;
|
|
1315
|
-
/** The clientId
|
|
1598
|
+
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1316
1599
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1317
1600
|
}
|
|
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 };
|
|
1601
|
+
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declaresAuthzResource, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, 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, AuthzUnchecked, AuthzRoleDeclaration, AuthzResourceDeclaration, AuthzResource, AuthzCheckDeclaration, AuthzCheck, AuthorizationException, AbstractIterablePage };
|