@kinotic-ai/core 5.0.0-beta.23 → 5.0.0-beta.24
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 +4 -104
- package/dist/index.d.cts +3 -178
- package/dist/index.d.ts +3 -178
- package/dist/index.js +4 -104
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -69,8 +69,6 @@ __export(exports_src, {
|
|
|
69
69
|
scopeOptionalMethodNames: () => scopeOptionalMethodNames,
|
|
70
70
|
receivesContext: () => receivesContext,
|
|
71
71
|
isAdvertised: () => isAdvertised,
|
|
72
|
-
declaresAuthz: () => declaresAuthz,
|
|
73
|
-
declareServiceDefinitions: () => declareServiceDefinitions,
|
|
74
72
|
createCRI: () => createCRI,
|
|
75
73
|
buildServerUrl: () => buildServerUrl,
|
|
76
74
|
buildBrokerUrl: () => buildBrokerUrl,
|
|
@@ -111,9 +109,6 @@ __export(exports_src, {
|
|
|
111
109
|
ChainedCredentialsResolver: () => ChainedCredentialsResolver,
|
|
112
110
|
BearerCredentialsResolver: () => BearerCredentialsResolver,
|
|
113
111
|
BasicCredentialsResolver: () => BasicCredentialsResolver,
|
|
114
|
-
AuthzUnchecked: () => AuthzUnchecked,
|
|
115
|
-
AuthzResource: () => AuthzResource,
|
|
116
|
-
AuthzCheck: () => AuthzCheck,
|
|
117
112
|
AuthorizationException: () => AuthorizationException,
|
|
118
113
|
AbstractIterablePage: () => AbstractIterablePage
|
|
119
114
|
});
|
|
@@ -129,7 +124,7 @@ function buildServerUrl(server, scheme) {
|
|
|
129
124
|
return scheme + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "");
|
|
130
125
|
}
|
|
131
126
|
function buildBrokerUrl(server) {
|
|
132
|
-
return buildServerUrl(server, "ws") + "/v1";
|
|
127
|
+
return buildServerUrl(server, "ws") + "/api/v1";
|
|
133
128
|
}
|
|
134
129
|
var SessionKeepAliveMode;
|
|
135
130
|
((SessionKeepAliveMode2) => {
|
|
@@ -1185,8 +1180,6 @@ var versionRegistry = new WeakMap;
|
|
|
1185
1180
|
var zonesRegistry = new WeakMap;
|
|
1186
1181
|
var advertisedRegistry = new WeakMap;
|
|
1187
1182
|
var contextMarkedFunctions = new WeakSet;
|
|
1188
|
-
var authzResourceClasses = new WeakSet;
|
|
1189
|
-
var authzUncheckedClasses = new WeakSet;
|
|
1190
1183
|
function findInConstructorChain(registry, constructor) {
|
|
1191
1184
|
let current = constructor;
|
|
1192
1185
|
while (current) {
|
|
@@ -1277,28 +1270,6 @@ function resolveEffectiveZone(constructor) {
|
|
|
1277
1270
|
}
|
|
1278
1271
|
return effectiveZone;
|
|
1279
1272
|
}
|
|
1280
|
-
function AuthzResource(declaration) {
|
|
1281
|
-
return function(value, _context) {
|
|
1282
|
-
authzResourceClasses.add(value);
|
|
1283
|
-
};
|
|
1284
|
-
}
|
|
1285
|
-
function AuthzCheck(declaration) {
|
|
1286
|
-
return function(_value, _context) {};
|
|
1287
|
-
}
|
|
1288
|
-
function AuthzUnchecked(value, context2) {
|
|
1289
|
-
if (context2.kind === "class") {
|
|
1290
|
-
authzUncheckedClasses.add(value);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
function declaresAuthz(serviceInstance) {
|
|
1294
|
-
let ret = false;
|
|
1295
|
-
let current = serviceInstance.constructor;
|
|
1296
|
-
while (current && !ret) {
|
|
1297
|
-
ret = authzResourceClasses.has(current) || authzUncheckedClasses.has(current);
|
|
1298
|
-
current = Object.getPrototypeOf(current);
|
|
1299
|
-
}
|
|
1300
|
-
return ret;
|
|
1301
|
-
}
|
|
1302
1273
|
function Publish(namespace, name, advertise = false) {
|
|
1303
1274
|
return function(value, _context) {
|
|
1304
1275
|
advertisedRegistry.set(value, advertise);
|
|
@@ -1326,7 +1297,7 @@ var import_api2 = __toESM(require("@opentelemetry/api"));
|
|
|
1326
1297
|
// packages/core/package.json
|
|
1327
1298
|
var package_default = {
|
|
1328
1299
|
name: "@kinotic-ai/core",
|
|
1329
|
-
version: "5.0.0-beta.
|
|
1300
|
+
version: "5.0.0-beta.24",
|
|
1330
1301
|
type: "module",
|
|
1331
1302
|
files: [
|
|
1332
1303
|
"dist"
|
|
@@ -1395,7 +1366,6 @@ var package_default = {
|
|
|
1395
1366
|
vitest: "^4.1.4"
|
|
1396
1367
|
},
|
|
1397
1368
|
dependencies: {
|
|
1398
|
-
"@kinotic-ai/idl": "workspace:^",
|
|
1399
1369
|
"@opentelemetry/api": "^1.9.1",
|
|
1400
1370
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1401
1371
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1786,61 +1756,10 @@ class TextEventFactory {
|
|
|
1786
1756
|
return event;
|
|
1787
1757
|
}
|
|
1788
1758
|
}
|
|
1789
|
-
var SERVICE_DIRECTORY_SERVICE = "app-api~org.kinotic.app.api.services.ServiceDirectoryService";
|
|
1790
|
-
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1791
|
-
var declaredDefinitions = new Map;
|
|
1792
|
-
function declareServiceDefinitions(definitions) {
|
|
1793
|
-
for (const definition of definitions) {
|
|
1794
|
-
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
function qualifiedNameOf(namespace, name) {
|
|
1798
|
-
return namespace ? `${namespace}.${name}` : name;
|
|
1799
|
-
}
|
|
1800
|
-
function servedFunctions(serviceInstance) {
|
|
1801
|
-
const ret = new Set;
|
|
1802
|
-
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1803
|
-
while (proto && proto !== Object.prototype) {
|
|
1804
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1805
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1806
|
-
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1807
|
-
ret.add(key);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
proto = Object.getPrototypeOf(proto);
|
|
1811
|
-
}
|
|
1812
|
-
return [...ret].sort();
|
|
1813
|
-
}
|
|
1814
|
-
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1815
|
-
let ret = null;
|
|
1816
|
-
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1817
|
-
if (application) {
|
|
1818
|
-
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1819
|
-
const definition = declaredDefinitions.get(qualifiedName);
|
|
1820
|
-
if (definition) {
|
|
1821
|
-
const declared = definition.functions.map((f) => f.name).sort();
|
|
1822
|
-
const served = servedFunctions(serviceInstance);
|
|
1823
|
-
if (declared.join() !== served.join()) {
|
|
1824
|
-
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1825
|
-
}
|
|
1826
|
-
ret = {
|
|
1827
|
-
applicationId: application[1],
|
|
1828
|
-
zone: serviceIdentifier.zone,
|
|
1829
|
-
version: serviceIdentifier.version ?? null,
|
|
1830
|
-
advertised: isAdvertised(serviceInstance),
|
|
1831
|
-
serviceDefinition: definition
|
|
1832
|
-
};
|
|
1833
|
-
} else if (declaresAuthz(serviceInstance)) {
|
|
1834
|
-
throw new Error(`${qualifiedName} declares a resource or is marked unchecked, but the project declares no definition for it;` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
return ret;
|
|
1838
|
-
}
|
|
1839
1759
|
|
|
1840
1760
|
class ServiceRegistry {
|
|
1841
1761
|
_eventBus;
|
|
1842
1762
|
supervisors = new Map;
|
|
1843
|
-
entries = new Map;
|
|
1844
1763
|
contextInterceptor = null;
|
|
1845
1764
|
debugLogger = import_debug3.default("kinotic:serviceRegistry");
|
|
1846
1765
|
constructor(eventBus) {
|
|
@@ -1862,16 +1781,9 @@ class ServiceRegistry {
|
|
|
1862
1781
|
const criString = serviceIdentifier.cri().raw();
|
|
1863
1782
|
if (!this.supervisors.has(criString)) {
|
|
1864
1783
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1865
|
-
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1866
1784
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1867
1785
|
this.supervisors.set(criString, supervisor);
|
|
1868
1786
|
supervisor.start();
|
|
1869
|
-
if (entry) {
|
|
1870
|
-
this.entries.set(criString, entry);
|
|
1871
|
-
if (this.eventBus.isConnected()) {
|
|
1872
|
-
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
1787
|
}
|
|
1876
1788
|
}
|
|
1877
1789
|
unRegister(serviceIdentifier) {
|
|
@@ -1881,18 +1793,8 @@ class ServiceRegistry {
|
|
|
1881
1793
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1882
1794
|
supervisor.stop();
|
|
1883
1795
|
this.supervisors.delete(criString);
|
|
1884
|
-
this.entries.delete(criString);
|
|
1885
1796
|
}
|
|
1886
1797
|
}
|
|
1887
|
-
async registerEntries() {
|
|
1888
|
-
for (const entry of this.entries.values()) {
|
|
1889
|
-
await this.registerEntry(entry);
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
async registerEntry(entry) {
|
|
1893
|
-
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1894
|
-
await this.serviceProxy(SERVICE_DIRECTORY_SERVICE).invoke("register", [entry]);
|
|
1895
|
-
}
|
|
1896
1798
|
registerContextInterceptor(interceptor) {
|
|
1897
1799
|
this.contextInterceptor = interceptor;
|
|
1898
1800
|
}
|
|
@@ -1984,10 +1886,8 @@ class KinoticSingleton {
|
|
|
1984
1886
|
this._eventBus = eventBus;
|
|
1985
1887
|
this.serviceRegistry.eventBus = eventBus;
|
|
1986
1888
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
await this.serviceRegistry.registerEntries();
|
|
1990
|
-
return ret;
|
|
1889
|
+
connect(options) {
|
|
1890
|
+
return this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1991
1891
|
}
|
|
1992
1892
|
disconnect(force) {
|
|
1993
1893
|
return this._eventBus.disconnect(force);
|
package/dist/index.d.cts
CHANGED
|
@@ -647,7 +647,6 @@ interface IServiceRegistry {
|
|
|
647
647
|
*/
|
|
648
648
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
649
649
|
}
|
|
650
|
-
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
651
650
|
/**
|
|
652
651
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
653
652
|
*/
|
|
@@ -661,20 +660,11 @@ declare class TextEventFactory implements IEventFactory {
|
|
|
661
660
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
662
661
|
}
|
|
663
662
|
/**
|
|
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
|
-
/**
|
|
672
663
|
* The default implementation of {@link IServiceRegistry}
|
|
673
664
|
*/
|
|
674
665
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
675
666
|
private _eventBus;
|
|
676
667
|
private supervisors;
|
|
677
|
-
private entries;
|
|
678
668
|
private contextInterceptor;
|
|
679
669
|
private debugLogger;
|
|
680
670
|
constructor(eventBus: IEventBus);
|
|
@@ -683,14 +673,6 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
683
673
|
serviceProxy(serviceIdentifier: string): IServiceProxy;
|
|
684
674
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
685
675
|
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;
|
|
694
676
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
695
677
|
}
|
|
696
678
|
/**
|
|
@@ -758,9 +740,8 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
758
740
|
get eventBus(): IEventBus;
|
|
759
741
|
set eventBus(eventBus: IEventBus);
|
|
760
742
|
/**
|
|
761
|
-
* Connects to a Kinotic server
|
|
762
|
-
*
|
|
763
|
-
* environment — see {@link ConnectOptions}.
|
|
743
|
+
* Connects to a Kinotic server. Every option is optional: absent server fields and
|
|
744
|
+
* credentials resolve from the environment — see {@link ConnectOptions}.
|
|
764
745
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
765
746
|
* @return Promise containing the result of the initial connection attempt
|
|
766
747
|
*/
|
|
@@ -788,80 +769,6 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
788
769
|
*/
|
|
789
770
|
declare const Kinotic: KinoticSingleton;
|
|
790
771
|
/**
|
|
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 resource 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 a resource of the parent type
|
|
813
|
-
* inherits to every resource of this type inside it, and a function naming no resource 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 resource every function of the service is checked on, for a service whose functions act on one resource
|
|
819
|
-
* the request does not name: a template over the caller's scope, `{@applicationId}` or `{@tenantId}`, or a literal
|
|
820
|
-
* id. A function naming its own resource with {@link AuthzCheck} is unaffected.
|
|
821
|
-
*/
|
|
822
|
-
resourceId?: 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 resource the check is made on, when it is not the service's own type, such as the parent for a
|
|
844
|
-
* create. A type name, never a template.
|
|
845
|
-
*/
|
|
846
|
-
resource?: string | null;
|
|
847
|
-
/**
|
|
848
|
-
* The id of the resource 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
|
-
resourceId?: 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
|
-
/**
|
|
865
772
|
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
866
773
|
* specific instance of the service, such as the copy running on a particular node. It is
|
|
867
774
|
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
@@ -913,59 +820,6 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
913
820
|
*/
|
|
914
821
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
915
822
|
/**
|
|
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 resource it is checked on, and
|
|
923
|
-
* the id of that resource. 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 resource'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, resource id, 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 resource, 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', resourceId: '{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, or a whole class declaring no resource, as served with
|
|
954
|
-
* no authorization check, which `kinotic sync` reads into the service's definition: any caller the service's
|
|
955
|
-
* zone admits may call it, and the service itself is responsible for answering only what the caller may see or
|
|
956
|
-
* do. It is for a function that has no resource to check, such as a listing of the caller's own grants, and for a
|
|
957
|
-
* service whose every function answers for the caller alone. The mark is the only way a function is served
|
|
958
|
-
* unchecked: a function the definition neither checks nor marks is refused. A function carrying this and
|
|
959
|
-
* {@link AuthzCheck} fails the service's registration, as does a class carrying this and {@link AuthzResource}.
|
|
960
|
-
*/
|
|
961
|
-
declare function AuthzUnchecked(value: Function, context: ClassDecoratorContext<any> | ClassMethodDecoratorContext): void;
|
|
962
|
-
/**
|
|
963
|
-
* Returns whether the given service instance's class, or a class it extends, declares an {@link AuthzResource} or
|
|
964
|
-
* is marked {@link AuthzUnchecked}: either way the service's definition carries what the platform serves it by.
|
|
965
|
-
* @param serviceInstance the service instance to inspect
|
|
966
|
-
*/
|
|
967
|
-
declare function declaresAuthz(serviceInstance: object): boolean;
|
|
968
|
-
/**
|
|
969
823
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
970
824
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
971
825
|
* on the same class refine the registration.
|
|
@@ -975,35 +829,6 @@ declare function declaresAuthz(serviceInstance: object): boolean;
|
|
|
975
829
|
* so it appears in directory listings
|
|
976
830
|
*/
|
|
977
831
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
978
|
-
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
979
|
-
/**
|
|
980
|
-
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
981
|
-
* it belongs to, where it is addressed, whether it is advertised, and its definition with the decorators it
|
|
982
|
-
* declares. The platform owns everything else about the directory's entry: the checks it derives, the tools the
|
|
983
|
-
* functions declare, and the service's liveness.
|
|
984
|
-
*/
|
|
985
|
-
interface ServiceDirectoryEntry {
|
|
986
|
-
/**
|
|
987
|
-
* The application the service belongs to, which its zone names.
|
|
988
|
-
*/
|
|
989
|
-
applicationId: string;
|
|
990
|
-
/**
|
|
991
|
-
* The zone the service is addressed in, the application's or a label under it.
|
|
992
|
-
*/
|
|
993
|
-
zone: string;
|
|
994
|
-
/**
|
|
995
|
-
* The version the service registers under, or null for none.
|
|
996
|
-
*/
|
|
997
|
-
version: string | null;
|
|
998
|
-
/**
|
|
999
|
-
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
1000
|
-
*/
|
|
1001
|
-
advertised: boolean;
|
|
1002
|
-
/**
|
|
1003
|
-
* The service's definition: its functions, and the decorators it declares.
|
|
1004
|
-
*/
|
|
1005
|
-
serviceDefinition: ServiceDefinition2;
|
|
1006
|
-
}
|
|
1007
832
|
/**
|
|
1008
833
|
* Validates that the given zone satisfies the zone grammar
|
|
1009
834
|
* @param zone the zone to validate
|
|
@@ -1601,4 +1426,4 @@ declare class ParticipantConstants {
|
|
|
1601
1426
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1602
1427
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1603
1428
|
}
|
|
1604
|
-
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised,
|
|
1429
|
+
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, 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, AuthorizationException, AbstractIterablePage };
|
package/dist/index.d.ts
CHANGED
|
@@ -647,7 +647,6 @@ interface IServiceRegistry {
|
|
|
647
647
|
*/
|
|
648
648
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
649
649
|
}
|
|
650
|
-
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
651
650
|
/**
|
|
652
651
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
653
652
|
*/
|
|
@@ -661,20 +660,11 @@ declare class TextEventFactory implements IEventFactory {
|
|
|
661
660
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
662
661
|
}
|
|
663
662
|
/**
|
|
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
|
-
/**
|
|
672
663
|
* The default implementation of {@link IServiceRegistry}
|
|
673
664
|
*/
|
|
674
665
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
675
666
|
private _eventBus;
|
|
676
667
|
private supervisors;
|
|
677
|
-
private entries;
|
|
678
668
|
private contextInterceptor;
|
|
679
669
|
private debugLogger;
|
|
680
670
|
constructor(eventBus: IEventBus);
|
|
@@ -683,14 +673,6 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
683
673
|
serviceProxy(serviceIdentifier: string): IServiceProxy;
|
|
684
674
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
685
675
|
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;
|
|
694
676
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
695
677
|
}
|
|
696
678
|
/**
|
|
@@ -758,9 +740,8 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
758
740
|
get eventBus(): IEventBus;
|
|
759
741
|
set eventBus(eventBus: IEventBus);
|
|
760
742
|
/**
|
|
761
|
-
* Connects to a Kinotic server
|
|
762
|
-
*
|
|
763
|
-
* environment — see {@link ConnectOptions}.
|
|
743
|
+
* Connects to a Kinotic server. Every option is optional: absent server fields and
|
|
744
|
+
* credentials resolve from the environment — see {@link ConnectOptions}.
|
|
764
745
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
765
746
|
* @return Promise containing the result of the initial connection attempt
|
|
766
747
|
*/
|
|
@@ -788,80 +769,6 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
788
769
|
*/
|
|
789
770
|
declare const Kinotic: KinoticSingleton;
|
|
790
771
|
/**
|
|
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 resource 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 a resource of the parent type
|
|
813
|
-
* inherits to every resource of this type inside it, and a function naming no resource 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 resource every function of the service is checked on, for a service whose functions act on one resource
|
|
819
|
-
* the request does not name: a template over the caller's scope, `{@applicationId}` or `{@tenantId}`, or a literal
|
|
820
|
-
* id. A function naming its own resource with {@link AuthzCheck} is unaffected.
|
|
821
|
-
*/
|
|
822
|
-
resourceId?: 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 resource the check is made on, when it is not the service's own type, such as the parent for a
|
|
844
|
-
* create. A type name, never a template.
|
|
845
|
-
*/
|
|
846
|
-
resource?: string | null;
|
|
847
|
-
/**
|
|
848
|
-
* The id of the resource 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
|
-
resourceId?: 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
|
-
/**
|
|
865
772
|
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
866
773
|
* specific instance of the service, such as the copy running on a particular node. It is
|
|
867
774
|
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
@@ -913,59 +820,6 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
913
820
|
*/
|
|
914
821
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
915
822
|
/**
|
|
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 resource it is checked on, and
|
|
923
|
-
* the id of that resource. 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 resource'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, resource id, 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 resource, 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', resourceId: '{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, or a whole class declaring no resource, as served with
|
|
954
|
-
* no authorization check, which `kinotic sync` reads into the service's definition: any caller the service's
|
|
955
|
-
* zone admits may call it, and the service itself is responsible for answering only what the caller may see or
|
|
956
|
-
* do. It is for a function that has no resource to check, such as a listing of the caller's own grants, and for a
|
|
957
|
-
* service whose every function answers for the caller alone. The mark is the only way a function is served
|
|
958
|
-
* unchecked: a function the definition neither checks nor marks is refused. A function carrying this and
|
|
959
|
-
* {@link AuthzCheck} fails the service's registration, as does a class carrying this and {@link AuthzResource}.
|
|
960
|
-
*/
|
|
961
|
-
declare function AuthzUnchecked(value: Function, context: ClassDecoratorContext<any> | ClassMethodDecoratorContext): void;
|
|
962
|
-
/**
|
|
963
|
-
* Returns whether the given service instance's class, or a class it extends, declares an {@link AuthzResource} or
|
|
964
|
-
* is marked {@link AuthzUnchecked}: either way the service's definition carries what the platform serves it by.
|
|
965
|
-
* @param serviceInstance the service instance to inspect
|
|
966
|
-
*/
|
|
967
|
-
declare function declaresAuthz(serviceInstance: object): boolean;
|
|
968
|
-
/**
|
|
969
823
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
970
824
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
971
825
|
* on the same class refine the registration.
|
|
@@ -975,35 +829,6 @@ declare function declaresAuthz(serviceInstance: object): boolean;
|
|
|
975
829
|
* so it appears in directory listings
|
|
976
830
|
*/
|
|
977
831
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
978
|
-
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
979
|
-
/**
|
|
980
|
-
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
981
|
-
* it belongs to, where it is addressed, whether it is advertised, and its definition with the decorators it
|
|
982
|
-
* declares. The platform owns everything else about the directory's entry: the checks it derives, the tools the
|
|
983
|
-
* functions declare, and the service's liveness.
|
|
984
|
-
*/
|
|
985
|
-
interface ServiceDirectoryEntry {
|
|
986
|
-
/**
|
|
987
|
-
* The application the service belongs to, which its zone names.
|
|
988
|
-
*/
|
|
989
|
-
applicationId: string;
|
|
990
|
-
/**
|
|
991
|
-
* The zone the service is addressed in, the application's or a label under it.
|
|
992
|
-
*/
|
|
993
|
-
zone: string;
|
|
994
|
-
/**
|
|
995
|
-
* The version the service registers under, or null for none.
|
|
996
|
-
*/
|
|
997
|
-
version: string | null;
|
|
998
|
-
/**
|
|
999
|
-
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
1000
|
-
*/
|
|
1001
|
-
advertised: boolean;
|
|
1002
|
-
/**
|
|
1003
|
-
* The service's definition: its functions, and the decorators it declares.
|
|
1004
|
-
*/
|
|
1005
|
-
serviceDefinition: ServiceDefinition2;
|
|
1006
|
-
}
|
|
1007
832
|
/**
|
|
1008
833
|
* Validates that the given zone satisfies the zone grammar
|
|
1009
834
|
* @param zone the zone to validate
|
|
@@ -1601,4 +1426,4 @@ declare class ParticipantConstants {
|
|
|
1601
1426
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1602
1427
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1603
1428
|
}
|
|
1604
|
-
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised,
|
|
1429
|
+
export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, 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, AuthorizationException, AbstractIterablePage };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ function buildServerUrl(server, scheme) {
|
|
|
8
8
|
return scheme + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "");
|
|
9
9
|
}
|
|
10
10
|
function buildBrokerUrl(server) {
|
|
11
|
-
return buildServerUrl(server, "ws") + "/v1";
|
|
11
|
+
return buildServerUrl(server, "ws") + "/api/v1";
|
|
12
12
|
}
|
|
13
13
|
var SessionKeepAliveMode;
|
|
14
14
|
((SessionKeepAliveMode2) => {
|
|
@@ -1064,8 +1064,6 @@ var versionRegistry = new WeakMap;
|
|
|
1064
1064
|
var zonesRegistry = new WeakMap;
|
|
1065
1065
|
var advertisedRegistry = new WeakMap;
|
|
1066
1066
|
var contextMarkedFunctions = new WeakSet;
|
|
1067
|
-
var authzResourceClasses = new WeakSet;
|
|
1068
|
-
var authzUncheckedClasses = new WeakSet;
|
|
1069
1067
|
function findInConstructorChain(registry, constructor) {
|
|
1070
1068
|
let current = constructor;
|
|
1071
1069
|
while (current) {
|
|
@@ -1156,28 +1154,6 @@ function resolveEffectiveZone(constructor) {
|
|
|
1156
1154
|
}
|
|
1157
1155
|
return effectiveZone;
|
|
1158
1156
|
}
|
|
1159
|
-
function AuthzResource(declaration) {
|
|
1160
|
-
return function(value, _context) {
|
|
1161
|
-
authzResourceClasses.add(value);
|
|
1162
|
-
};
|
|
1163
|
-
}
|
|
1164
|
-
function AuthzCheck(declaration) {
|
|
1165
|
-
return function(_value, _context) {};
|
|
1166
|
-
}
|
|
1167
|
-
function AuthzUnchecked(value, context2) {
|
|
1168
|
-
if (context2.kind === "class") {
|
|
1169
|
-
authzUncheckedClasses.add(value);
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
function declaresAuthz(serviceInstance) {
|
|
1173
|
-
let ret = false;
|
|
1174
|
-
let current = serviceInstance.constructor;
|
|
1175
|
-
while (current && !ret) {
|
|
1176
|
-
ret = authzResourceClasses.has(current) || authzUncheckedClasses.has(current);
|
|
1177
|
-
current = Object.getPrototypeOf(current);
|
|
1178
|
-
}
|
|
1179
|
-
return ret;
|
|
1180
|
-
}
|
|
1181
1157
|
function Publish(namespace, name, advertise = false) {
|
|
1182
1158
|
return function(value, _context) {
|
|
1183
1159
|
advertisedRegistry.set(value, advertise);
|
|
@@ -1205,7 +1181,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
|
|
|
1205
1181
|
// packages/core/package.json
|
|
1206
1182
|
var package_default = {
|
|
1207
1183
|
name: "@kinotic-ai/core",
|
|
1208
|
-
version: "5.0.0-beta.
|
|
1184
|
+
version: "5.0.0-beta.24",
|
|
1209
1185
|
type: "module",
|
|
1210
1186
|
files: [
|
|
1211
1187
|
"dist"
|
|
@@ -1274,7 +1250,6 @@ var package_default = {
|
|
|
1274
1250
|
vitest: "^4.1.4"
|
|
1275
1251
|
},
|
|
1276
1252
|
dependencies: {
|
|
1277
|
-
"@kinotic-ai/idl": "workspace:^",
|
|
1278
1253
|
"@opentelemetry/api": "^1.9.1",
|
|
1279
1254
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1280
1255
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1668,61 +1643,10 @@ class TextEventFactory {
|
|
|
1668
1643
|
return event;
|
|
1669
1644
|
}
|
|
1670
1645
|
}
|
|
1671
|
-
var SERVICE_DIRECTORY_SERVICE = "app-api~org.kinotic.app.api.services.ServiceDirectoryService";
|
|
1672
|
-
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1673
|
-
var declaredDefinitions = new Map;
|
|
1674
|
-
function declareServiceDefinitions(definitions) {
|
|
1675
|
-
for (const definition of definitions) {
|
|
1676
|
-
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
function qualifiedNameOf(namespace, name) {
|
|
1680
|
-
return namespace ? `${namespace}.${name}` : name;
|
|
1681
|
-
}
|
|
1682
|
-
function servedFunctions(serviceInstance) {
|
|
1683
|
-
const ret = new Set;
|
|
1684
|
-
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1685
|
-
while (proto && proto !== Object.prototype) {
|
|
1686
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1687
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1688
|
-
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1689
|
-
ret.add(key);
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
proto = Object.getPrototypeOf(proto);
|
|
1693
|
-
}
|
|
1694
|
-
return [...ret].sort();
|
|
1695
|
-
}
|
|
1696
|
-
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1697
|
-
let ret = null;
|
|
1698
|
-
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1699
|
-
if (application) {
|
|
1700
|
-
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1701
|
-
const definition = declaredDefinitions.get(qualifiedName);
|
|
1702
|
-
if (definition) {
|
|
1703
|
-
const declared = definition.functions.map((f) => f.name).sort();
|
|
1704
|
-
const served = servedFunctions(serviceInstance);
|
|
1705
|
-
if (declared.join() !== served.join()) {
|
|
1706
|
-
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1707
|
-
}
|
|
1708
|
-
ret = {
|
|
1709
|
-
applicationId: application[1],
|
|
1710
|
-
zone: serviceIdentifier.zone,
|
|
1711
|
-
version: serviceIdentifier.version ?? null,
|
|
1712
|
-
advertised: isAdvertised(serviceInstance),
|
|
1713
|
-
serviceDefinition: definition
|
|
1714
|
-
};
|
|
1715
|
-
} else if (declaresAuthz(serviceInstance)) {
|
|
1716
|
-
throw new Error(`${qualifiedName} declares a resource or is marked unchecked, but the project declares no definition for it;` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
return ret;
|
|
1720
|
-
}
|
|
1721
1646
|
|
|
1722
1647
|
class ServiceRegistry {
|
|
1723
1648
|
_eventBus;
|
|
1724
1649
|
supervisors = new Map;
|
|
1725
|
-
entries = new Map;
|
|
1726
1650
|
contextInterceptor = null;
|
|
1727
1651
|
debugLogger = debug3("kinotic:serviceRegistry");
|
|
1728
1652
|
constructor(eventBus) {
|
|
@@ -1744,16 +1668,9 @@ class ServiceRegistry {
|
|
|
1744
1668
|
const criString = serviceIdentifier.cri().raw();
|
|
1745
1669
|
if (!this.supervisors.has(criString)) {
|
|
1746
1670
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1747
|
-
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1748
1671
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1749
1672
|
this.supervisors.set(criString, supervisor);
|
|
1750
1673
|
supervisor.start();
|
|
1751
|
-
if (entry) {
|
|
1752
|
-
this.entries.set(criString, entry);
|
|
1753
|
-
if (this.eventBus.isConnected()) {
|
|
1754
|
-
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
1674
|
}
|
|
1758
1675
|
}
|
|
1759
1676
|
unRegister(serviceIdentifier) {
|
|
@@ -1763,18 +1680,8 @@ class ServiceRegistry {
|
|
|
1763
1680
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1764
1681
|
supervisor.stop();
|
|
1765
1682
|
this.supervisors.delete(criString);
|
|
1766
|
-
this.entries.delete(criString);
|
|
1767
1683
|
}
|
|
1768
1684
|
}
|
|
1769
|
-
async registerEntries() {
|
|
1770
|
-
for (const entry of this.entries.values()) {
|
|
1771
|
-
await this.registerEntry(entry);
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
async registerEntry(entry) {
|
|
1775
|
-
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1776
|
-
await this.serviceProxy(SERVICE_DIRECTORY_SERVICE).invoke("register", [entry]);
|
|
1777
|
-
}
|
|
1778
1685
|
registerContextInterceptor(interceptor) {
|
|
1779
1686
|
this.contextInterceptor = interceptor;
|
|
1780
1687
|
}
|
|
@@ -1866,10 +1773,8 @@ class KinoticSingleton {
|
|
|
1866
1773
|
this._eventBus = eventBus;
|
|
1867
1774
|
this.serviceRegistry.eventBus = eventBus;
|
|
1868
1775
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
await this.serviceRegistry.registerEntries();
|
|
1872
|
-
return ret;
|
|
1776
|
+
connect(options) {
|
|
1777
|
+
return this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1873
1778
|
}
|
|
1874
1779
|
disconnect(force) {
|
|
1875
1780
|
return this._eventBus.disconnect(force);
|
|
@@ -2141,8 +2046,6 @@ export {
|
|
|
2141
2046
|
scopeOptionalMethodNames,
|
|
2142
2047
|
receivesContext,
|
|
2143
2048
|
isAdvertised,
|
|
2144
|
-
declaresAuthz,
|
|
2145
|
-
declareServiceDefinitions,
|
|
2146
2049
|
createCRI,
|
|
2147
2050
|
buildServerUrl,
|
|
2148
2051
|
buildBrokerUrl,
|
|
@@ -2183,9 +2086,6 @@ export {
|
|
|
2183
2086
|
ChainedCredentialsResolver,
|
|
2184
2087
|
BearerCredentialsResolver,
|
|
2185
2088
|
BasicCredentialsResolver,
|
|
2186
|
-
AuthzUnchecked,
|
|
2187
|
-
AuthzResource,
|
|
2188
|
-
AuthzCheck,
|
|
2189
2089
|
AuthorizationException,
|
|
2190
2090
|
AbstractIterablePage
|
|
2191
2091
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"vitest": "^4.1.4"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@kinotic-ai/idl": "^5.0.0-beta.4",
|
|
73
72
|
"@opentelemetry/api": "^1.9.1",
|
|
74
73
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
75
74
|
"@stomp/rx-stomp": "^2.4.0",
|