@kinotic-ai/core 5.0.0-beta.22 → 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 -99
- package/dist/index.d.cts +3 -175
- package/dist/index.d.ts +3 -175
- package/dist/index.js +4 -99
- 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
|
-
declaresAuthzResource: () => declaresAuthzResource,
|
|
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,7 +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
1183
|
function findInConstructorChain(registry, constructor) {
|
|
1190
1184
|
let current = constructor;
|
|
1191
1185
|
while (current) {
|
|
@@ -1276,24 +1270,6 @@ function resolveEffectiveZone(constructor) {
|
|
|
1276
1270
|
}
|
|
1277
1271
|
return effectiveZone;
|
|
1278
1272
|
}
|
|
1279
|
-
function AuthzResource(declaration) {
|
|
1280
|
-
return function(value, _context) {
|
|
1281
|
-
authzResourceClasses.add(value);
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
function AuthzCheck(declaration) {
|
|
1285
|
-
return function(_value, _context) {};
|
|
1286
|
-
}
|
|
1287
|
-
function AuthzUnchecked(_value, _context) {}
|
|
1288
|
-
function declaresAuthzResource(serviceInstance) {
|
|
1289
|
-
let ret = false;
|
|
1290
|
-
let current = serviceInstance.constructor;
|
|
1291
|
-
while (current && !ret) {
|
|
1292
|
-
ret = authzResourceClasses.has(current);
|
|
1293
|
-
current = Object.getPrototypeOf(current);
|
|
1294
|
-
}
|
|
1295
|
-
return ret;
|
|
1296
|
-
}
|
|
1297
1273
|
function Publish(namespace, name, advertise = false) {
|
|
1298
1274
|
return function(value, _context) {
|
|
1299
1275
|
advertisedRegistry.set(value, advertise);
|
|
@@ -1321,7 +1297,7 @@ var import_api2 = __toESM(require("@opentelemetry/api"));
|
|
|
1321
1297
|
// packages/core/package.json
|
|
1322
1298
|
var package_default = {
|
|
1323
1299
|
name: "@kinotic-ai/core",
|
|
1324
|
-
version: "5.0.0-beta.
|
|
1300
|
+
version: "5.0.0-beta.24",
|
|
1325
1301
|
type: "module",
|
|
1326
1302
|
files: [
|
|
1327
1303
|
"dist"
|
|
@@ -1390,7 +1366,6 @@ var package_default = {
|
|
|
1390
1366
|
vitest: "^4.1.4"
|
|
1391
1367
|
},
|
|
1392
1368
|
dependencies: {
|
|
1393
|
-
"@kinotic-ai/idl": "workspace:^",
|
|
1394
1369
|
"@opentelemetry/api": "^1.9.1",
|
|
1395
1370
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1396
1371
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1781,61 +1756,10 @@ class TextEventFactory {
|
|
|
1781
1756
|
return event;
|
|
1782
1757
|
}
|
|
1783
1758
|
}
|
|
1784
|
-
var SERVICE_DIRECTORY_SERVICE = "app-api~org.kinotic.app.api.services.ServiceDirectoryService";
|
|
1785
|
-
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1786
|
-
var declaredDefinitions = new Map;
|
|
1787
|
-
function declareServiceDefinitions(definitions) {
|
|
1788
|
-
for (const definition of definitions) {
|
|
1789
|
-
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
function qualifiedNameOf(namespace, name) {
|
|
1793
|
-
return namespace ? `${namespace}.${name}` : name;
|
|
1794
|
-
}
|
|
1795
|
-
function servedFunctions(serviceInstance) {
|
|
1796
|
-
const ret = new Set;
|
|
1797
|
-
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1798
|
-
while (proto && proto !== Object.prototype) {
|
|
1799
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1800
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1801
|
-
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1802
|
-
ret.add(key);
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
proto = Object.getPrototypeOf(proto);
|
|
1806
|
-
}
|
|
1807
|
-
return [...ret].sort();
|
|
1808
|
-
}
|
|
1809
|
-
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1810
|
-
let ret = null;
|
|
1811
|
-
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1812
|
-
if (application) {
|
|
1813
|
-
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1814
|
-
const definition = declaredDefinitions.get(qualifiedName);
|
|
1815
|
-
if (definition) {
|
|
1816
|
-
const declared = definition.functions.map((f) => f.name).sort();
|
|
1817
|
-
const served = servedFunctions(serviceInstance);
|
|
1818
|
-
if (declared.join() !== served.join()) {
|
|
1819
|
-
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1820
|
-
}
|
|
1821
|
-
ret = {
|
|
1822
|
-
applicationId: application[1],
|
|
1823
|
-
zone: serviceIdentifier.zone,
|
|
1824
|
-
version: serviceIdentifier.version ?? null,
|
|
1825
|
-
advertised: isAdvertised(serviceInstance),
|
|
1826
|
-
serviceDefinition: definition
|
|
1827
|
-
};
|
|
1828
|
-
} else if (declaresAuthzResource(serviceInstance)) {
|
|
1829
|
-
throw new Error(`${qualifiedName} declares a resource but the project declares no definition for it;` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
return ret;
|
|
1833
|
-
}
|
|
1834
1759
|
|
|
1835
1760
|
class ServiceRegistry {
|
|
1836
1761
|
_eventBus;
|
|
1837
1762
|
supervisors = new Map;
|
|
1838
|
-
entries = new Map;
|
|
1839
1763
|
contextInterceptor = null;
|
|
1840
1764
|
debugLogger = import_debug3.default("kinotic:serviceRegistry");
|
|
1841
1765
|
constructor(eventBus) {
|
|
@@ -1857,16 +1781,9 @@ class ServiceRegistry {
|
|
|
1857
1781
|
const criString = serviceIdentifier.cri().raw();
|
|
1858
1782
|
if (!this.supervisors.has(criString)) {
|
|
1859
1783
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1860
|
-
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1861
1784
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1862
1785
|
this.supervisors.set(criString, supervisor);
|
|
1863
1786
|
supervisor.start();
|
|
1864
|
-
if (entry) {
|
|
1865
|
-
this.entries.set(criString, entry);
|
|
1866
|
-
if (this.eventBus.isConnected()) {
|
|
1867
|
-
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
1787
|
}
|
|
1871
1788
|
}
|
|
1872
1789
|
unRegister(serviceIdentifier) {
|
|
@@ -1876,18 +1793,8 @@ class ServiceRegistry {
|
|
|
1876
1793
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1877
1794
|
supervisor.stop();
|
|
1878
1795
|
this.supervisors.delete(criString);
|
|
1879
|
-
this.entries.delete(criString);
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
async registerEntries() {
|
|
1883
|
-
for (const entry of this.entries.values()) {
|
|
1884
|
-
await this.registerEntry(entry);
|
|
1885
1796
|
}
|
|
1886
1797
|
}
|
|
1887
|
-
async registerEntry(entry) {
|
|
1888
|
-
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1889
|
-
await this.serviceProxy(SERVICE_DIRECTORY_SERVICE).invoke("register", [entry]);
|
|
1890
|
-
}
|
|
1891
1798
|
registerContextInterceptor(interceptor) {
|
|
1892
1799
|
this.contextInterceptor = interceptor;
|
|
1893
1800
|
}
|
|
@@ -1979,10 +1886,8 @@ class KinoticSingleton {
|
|
|
1979
1886
|
this._eventBus = eventBus;
|
|
1980
1887
|
this.serviceRegistry.eventBus = eventBus;
|
|
1981
1888
|
}
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
await this.serviceRegistry.registerEntries();
|
|
1985
|
-
return ret;
|
|
1889
|
+
connect(options) {
|
|
1890
|
+
return this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1986
1891
|
}
|
|
1987
1892
|
disconnect(force) {
|
|
1988
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: 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 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,56 +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 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 resource 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
|
-
/**
|
|
966
823
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
967
824
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
968
825
|
* on the same class refine the registration.
|
|
@@ -972,35 +829,6 @@ declare function declaresAuthzResource(serviceInstance: object): boolean;
|
|
|
972
829
|
* so it appears in directory listings
|
|
973
830
|
*/
|
|
974
831
|
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
|
-
}
|
|
1004
832
|
/**
|
|
1005
833
|
* Validates that the given zone satisfies the zone grammar
|
|
1006
834
|
* @param zone the zone to validate
|
|
@@ -1598,4 +1426,4 @@ declare class ParticipantConstants {
|
|
|
1598
1426
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1599
1427
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1600
1428
|
}
|
|
1601
|
-
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: 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 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,56 +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 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 resource 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
|
-
/**
|
|
966
823
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
967
824
|
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
968
825
|
* on the same class refine the registration.
|
|
@@ -972,35 +829,6 @@ declare function declaresAuthzResource(serviceInstance: object): boolean;
|
|
|
972
829
|
* so it appears in directory listings
|
|
973
830
|
*/
|
|
974
831
|
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
|
-
}
|
|
1004
832
|
/**
|
|
1005
833
|
* Validates that the given zone satisfies the zone grammar
|
|
1006
834
|
* @param zone the zone to validate
|
|
@@ -1598,4 +1426,4 @@ declare class ParticipantConstants {
|
|
|
1598
1426
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1599
1427
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1600
1428
|
}
|
|
1601
|
-
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,7 +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
1067
|
function findInConstructorChain(registry, constructor) {
|
|
1069
1068
|
let current = constructor;
|
|
1070
1069
|
while (current) {
|
|
@@ -1155,24 +1154,6 @@ function resolveEffectiveZone(constructor) {
|
|
|
1155
1154
|
}
|
|
1156
1155
|
return effectiveZone;
|
|
1157
1156
|
}
|
|
1158
|
-
function AuthzResource(declaration) {
|
|
1159
|
-
return function(value, _context) {
|
|
1160
|
-
authzResourceClasses.add(value);
|
|
1161
|
-
};
|
|
1162
|
-
}
|
|
1163
|
-
function AuthzCheck(declaration) {
|
|
1164
|
-
return function(_value, _context) {};
|
|
1165
|
-
}
|
|
1166
|
-
function AuthzUnchecked(_value, _context) {}
|
|
1167
|
-
function declaresAuthzResource(serviceInstance) {
|
|
1168
|
-
let ret = false;
|
|
1169
|
-
let current = serviceInstance.constructor;
|
|
1170
|
-
while (current && !ret) {
|
|
1171
|
-
ret = authzResourceClasses.has(current);
|
|
1172
|
-
current = Object.getPrototypeOf(current);
|
|
1173
|
-
}
|
|
1174
|
-
return ret;
|
|
1175
|
-
}
|
|
1176
1157
|
function Publish(namespace, name, advertise = false) {
|
|
1177
1158
|
return function(value, _context) {
|
|
1178
1159
|
advertisedRegistry.set(value, advertise);
|
|
@@ -1200,7 +1181,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
|
|
|
1200
1181
|
// packages/core/package.json
|
|
1201
1182
|
var package_default = {
|
|
1202
1183
|
name: "@kinotic-ai/core",
|
|
1203
|
-
version: "5.0.0-beta.
|
|
1184
|
+
version: "5.0.0-beta.24",
|
|
1204
1185
|
type: "module",
|
|
1205
1186
|
files: [
|
|
1206
1187
|
"dist"
|
|
@@ -1269,7 +1250,6 @@ var package_default = {
|
|
|
1269
1250
|
vitest: "^4.1.4"
|
|
1270
1251
|
},
|
|
1271
1252
|
dependencies: {
|
|
1272
|
-
"@kinotic-ai/idl": "workspace:^",
|
|
1273
1253
|
"@opentelemetry/api": "^1.9.1",
|
|
1274
1254
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1275
1255
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1663,61 +1643,10 @@ class TextEventFactory {
|
|
|
1663
1643
|
return event;
|
|
1664
1644
|
}
|
|
1665
1645
|
}
|
|
1666
|
-
var SERVICE_DIRECTORY_SERVICE = "app-api~org.kinotic.app.api.services.ServiceDirectoryService";
|
|
1667
|
-
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1668
|
-
var declaredDefinitions = new Map;
|
|
1669
|
-
function declareServiceDefinitions(definitions) {
|
|
1670
|
-
for (const definition of definitions) {
|
|
1671
|
-
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
function qualifiedNameOf(namespace, name) {
|
|
1675
|
-
return namespace ? `${namespace}.${name}` : name;
|
|
1676
|
-
}
|
|
1677
|
-
function servedFunctions(serviceInstance) {
|
|
1678
|
-
const ret = new Set;
|
|
1679
|
-
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1680
|
-
while (proto && proto !== Object.prototype) {
|
|
1681
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1682
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1683
|
-
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1684
|
-
ret.add(key);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
proto = Object.getPrototypeOf(proto);
|
|
1688
|
-
}
|
|
1689
|
-
return [...ret].sort();
|
|
1690
|
-
}
|
|
1691
|
-
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1692
|
-
let ret = null;
|
|
1693
|
-
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1694
|
-
if (application) {
|
|
1695
|
-
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1696
|
-
const definition = declaredDefinitions.get(qualifiedName);
|
|
1697
|
-
if (definition) {
|
|
1698
|
-
const declared = definition.functions.map((f) => f.name).sort();
|
|
1699
|
-
const served = servedFunctions(serviceInstance);
|
|
1700
|
-
if (declared.join() !== served.join()) {
|
|
1701
|
-
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1702
|
-
}
|
|
1703
|
-
ret = {
|
|
1704
|
-
applicationId: application[1],
|
|
1705
|
-
zone: serviceIdentifier.zone,
|
|
1706
|
-
version: serviceIdentifier.version ?? null,
|
|
1707
|
-
advertised: isAdvertised(serviceInstance),
|
|
1708
|
-
serviceDefinition: definition
|
|
1709
|
-
};
|
|
1710
|
-
} else if (declaresAuthzResource(serviceInstance)) {
|
|
1711
|
-
throw new Error(`${qualifiedName} declares a resource but the project declares no definition for it;` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
return ret;
|
|
1715
|
-
}
|
|
1716
1646
|
|
|
1717
1647
|
class ServiceRegistry {
|
|
1718
1648
|
_eventBus;
|
|
1719
1649
|
supervisors = new Map;
|
|
1720
|
-
entries = new Map;
|
|
1721
1650
|
contextInterceptor = null;
|
|
1722
1651
|
debugLogger = debug3("kinotic:serviceRegistry");
|
|
1723
1652
|
constructor(eventBus) {
|
|
@@ -1739,16 +1668,9 @@ class ServiceRegistry {
|
|
|
1739
1668
|
const criString = serviceIdentifier.cri().raw();
|
|
1740
1669
|
if (!this.supervisors.has(criString)) {
|
|
1741
1670
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1742
|
-
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1743
1671
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1744
1672
|
this.supervisors.set(criString, supervisor);
|
|
1745
1673
|
supervisor.start();
|
|
1746
|
-
if (entry) {
|
|
1747
|
-
this.entries.set(criString, entry);
|
|
1748
|
-
if (this.eventBus.isConnected()) {
|
|
1749
|
-
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
1674
|
}
|
|
1753
1675
|
}
|
|
1754
1676
|
unRegister(serviceIdentifier) {
|
|
@@ -1758,18 +1680,8 @@ class ServiceRegistry {
|
|
|
1758
1680
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1759
1681
|
supervisor.stop();
|
|
1760
1682
|
this.supervisors.delete(criString);
|
|
1761
|
-
this.entries.delete(criString);
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
async registerEntries() {
|
|
1765
|
-
for (const entry of this.entries.values()) {
|
|
1766
|
-
await this.registerEntry(entry);
|
|
1767
1683
|
}
|
|
1768
1684
|
}
|
|
1769
|
-
async registerEntry(entry) {
|
|
1770
|
-
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1771
|
-
await this.serviceProxy(SERVICE_DIRECTORY_SERVICE).invoke("register", [entry]);
|
|
1772
|
-
}
|
|
1773
1685
|
registerContextInterceptor(interceptor) {
|
|
1774
1686
|
this.contextInterceptor = interceptor;
|
|
1775
1687
|
}
|
|
@@ -1861,10 +1773,8 @@ class KinoticSingleton {
|
|
|
1861
1773
|
this._eventBus = eventBus;
|
|
1862
1774
|
this.serviceRegistry.eventBus = eventBus;
|
|
1863
1775
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
await this.serviceRegistry.registerEntries();
|
|
1867
|
-
return ret;
|
|
1776
|
+
connect(options) {
|
|
1777
|
+
return this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1868
1778
|
}
|
|
1869
1779
|
disconnect(force) {
|
|
1870
1780
|
return this._eventBus.disconnect(force);
|
|
@@ -2136,8 +2046,6 @@ export {
|
|
|
2136
2046
|
scopeOptionalMethodNames,
|
|
2137
2047
|
receivesContext,
|
|
2138
2048
|
isAdvertised,
|
|
2139
|
-
declaresAuthzResource,
|
|
2140
|
-
declareServiceDefinitions,
|
|
2141
2049
|
createCRI,
|
|
2142
2050
|
buildServerUrl,
|
|
2143
2051
|
buildBrokerUrl,
|
|
@@ -2178,9 +2086,6 @@ export {
|
|
|
2178
2086
|
ChainedCredentialsResolver,
|
|
2179
2087
|
BearerCredentialsResolver,
|
|
2180
2088
|
BasicCredentialsResolver,
|
|
2181
|
-
AuthzUnchecked,
|
|
2182
|
-
AuthzResource,
|
|
2183
|
-
AuthzCheck,
|
|
2184
2089
|
AuthorizationException,
|
|
2185
2090
|
AbstractIterablePage
|
|
2186
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",
|