@attraccess/plugins-backend-sdk 1.8.1 → 1.10.0
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/package.json +5 -4
- package/src/index.d.ts +3 -0
- package/src/index.js +3 -0
- package/src/index.js.map +1 -1
- package/src/lib/auth-decorator.d.ts +9 -3
- package/src/lib/auth-decorator.js +54 -22
- package/src/lib/auth-decorator.js.map +1 -1
- package/src/lib/auth.types.d.ts +9 -0
- package/src/lib/mqtt-credential-provisioning.d.ts +52 -0
- package/src/lib/mqtt-credential-provisioning.js +5 -0
- package/src/lib/mqtt-credential-provisioning.js.map +1 -0
- package/src/lib/plugin-audit.d.ts +94 -0
- package/src/lib/plugin-audit.js +170 -0
- package/src/lib/plugin-audit.js.map +1 -0
- package/src/lib/plugin-context.d.ts +79 -1
- package/src/lib/plugin-context.js.map +1 -1
- package/src/lib/plugin-flow-node.d.ts +123 -0
- package/src/lib/plugin-flow-node.js +12 -0
- package/src/lib/plugin-flow-node.js.map +1 -0
- package/src/lib/plugin.interface.d.ts +5 -1
- package/src/lib/plugin.interface.js +6 -0
- package/src/lib/plugin.interface.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@attraccess/plugins-backend-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -26,9 +26,10 @@
|
|
|
26
26
|
"@nestjs/event-emitter": "^3.1.0",
|
|
27
27
|
"rxjs": "^7.8.2",
|
|
28
28
|
"@nestjs/core": "^11.1.0",
|
|
29
|
-
"typeorm": "0.3.
|
|
29
|
+
"typeorm": "0.3.31",
|
|
30
30
|
"@nestjs/swagger": "^11.2.0",
|
|
31
|
-
"express": "4.22.
|
|
32
|
-
"@nestjs/passport": "^11.0.5"
|
|
31
|
+
"express": "4.22.2",
|
|
32
|
+
"@nestjs/passport": "^11.0.5",
|
|
33
|
+
"@attraccess/shared": "*"
|
|
33
34
|
}
|
|
34
35
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from './lib/plugin.interface';
|
|
2
|
+
export * from './lib/plugin-flow-node';
|
|
2
3
|
export * from './lib/plugin-context';
|
|
4
|
+
export * from './lib/plugin-audit';
|
|
5
|
+
export * from './lib/mqtt-credential-provisioning';
|
|
3
6
|
export * from './lib/plugin-migrations';
|
|
4
7
|
export * from './lib/entity';
|
|
5
8
|
export * from './lib/semver';
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.entities = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./lib/plugin.interface"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/plugin-flow-node"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/plugin-context"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/plugin-audit"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/mqtt-credential-provisioning"), exports);
|
|
7
10
|
tslib_1.__exportStar(require("./lib/plugin-migrations"), exports);
|
|
8
11
|
tslib_1.__exportStar(require("./lib/entity"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./lib/semver"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/plugins-backend-sdk/src/index.ts"],"names":[],"mappings":";;;;AAAA,iEAAuC;AACvC,+DAAqC;AACrC,kEAAwC;AACxC,uDAA6B;AAC7B,uDAA6B;AAE7B,+DAAqC;AACrC,wEAA8C;AAC9C,kFAA0D;AAC1D,2DAAiC;AACjC,gEAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/plugins-backend-sdk/src/index.ts"],"names":[],"mappings":";;;;AAAA,iEAAuC;AACvC,iEAAuC;AACvC,+DAAqC;AACrC,6DAAmC;AACnC,6EAAmD;AACnD,kEAAwC;AACxC,uDAA6B;AAC7B,uDAA6B;AAE7B,+DAAqC;AACrC,wEAA8C;AAC9C,kFAA0D;AAC1D,2DAAiC;AACjC,gEAAsC"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { ExecutionContext, CanActivate } from '@nestjs/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { Reflector } from '@nestjs/core';
|
|
4
|
-
import { SystemPermission } from '@attraccess/
|
|
4
|
+
import { SystemPermission } from '@attraccess/shared';
|
|
5
|
+
export type { SystemPermission };
|
|
5
6
|
export declare function Auth(...permissions: SystemPermission[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
6
|
-
export declare
|
|
7
|
+
export declare function AuthAny(...permissions: SystemPermission[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
8
|
+
export declare function SessionAuth(...permissions: SystemPermission[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
9
|
+
export declare class EffectivePermissionsGuard implements CanActivate {
|
|
7
10
|
private reflector;
|
|
8
11
|
private readonly logger;
|
|
9
12
|
constructor(reflector: Reflector);
|
|
10
13
|
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
|
|
11
|
-
private matchPermissions;
|
|
12
14
|
}
|
|
15
|
+
export declare class SessionOnlyGuard implements CanActivate {
|
|
16
|
+
canActivate(context: ExecutionContext): boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const SystemPermissionsGuard: typeof EffectivePermissionsGuard;
|
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var EffectivePermissionsGuard_1;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.SystemPermissionsGuard = void 0;
|
|
4
|
+
exports.SystemPermissionsGuard = exports.SessionOnlyGuard = exports.EffectivePermissionsGuard = void 0;
|
|
5
5
|
exports.Auth = Auth;
|
|
6
|
+
exports.AuthAny = AuthAny;
|
|
7
|
+
exports.SessionAuth = SessionAuth;
|
|
6
8
|
const tslib_1 = require("tslib");
|
|
7
9
|
const common_1 = require("@nestjs/common");
|
|
8
10
|
const core_1 = require("@nestjs/core");
|
|
9
11
|
const swagger_1 = require("@nestjs/swagger");
|
|
10
12
|
const dual_auth_guard_1 = require("./dual-auth.guard");
|
|
11
|
-
const
|
|
13
|
+
const NeedsPermissions = core_1.Reflector.createDecorator();
|
|
14
|
+
const NeedsAnyPermission = core_1.Reflector.createDecorator();
|
|
12
15
|
function Auth(...permissions) {
|
|
13
|
-
return (0, common_1.applyDecorators)(
|
|
16
|
+
return (0, common_1.applyDecorators)(NeedsPermissions(permissions), (0, common_1.UseGuards)(dual_auth_guard_1.DualAuthGuard, EffectivePermissionsGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }));
|
|
14
17
|
}
|
|
15
|
-
|
|
18
|
+
function AuthAny(...permissions) {
|
|
19
|
+
return (0, common_1.applyDecorators)(NeedsAnyPermission(permissions), (0, common_1.UseGuards)(dual_auth_guard_1.DualAuthGuard, EffectivePermissionsGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }));
|
|
20
|
+
}
|
|
21
|
+
function SessionAuth(...permissions) {
|
|
22
|
+
return (0, common_1.applyDecorators)(NeedsPermissions(permissions), (0, common_1.UseGuards)(dual_auth_guard_1.DualAuthGuard, EffectivePermissionsGuard, SessionOnlyGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }));
|
|
23
|
+
}
|
|
24
|
+
let EffectivePermissionsGuard = EffectivePermissionsGuard_1 = class EffectivePermissionsGuard {
|
|
16
25
|
constructor(reflector) {
|
|
17
26
|
this.reflector = reflector;
|
|
18
|
-
this.logger = new common_1.Logger(
|
|
27
|
+
this.logger = new common_1.Logger(EffectivePermissionsGuard_1.name);
|
|
19
28
|
}
|
|
20
29
|
canActivate(context) {
|
|
21
|
-
const
|
|
22
|
-
|
|
30
|
+
const requiredAll = this.reflector.getAllAndOverride(NeedsPermissions, [context.getHandler(), context.getClass()]);
|
|
31
|
+
const requiredAny = this.reflector.getAllAndOverride(NeedsAnyPermission, [
|
|
32
|
+
context.getHandler(),
|
|
33
|
+
context.getClass(),
|
|
34
|
+
]);
|
|
35
|
+
if ((!requiredAll || requiredAll.length === 0) && (!requiredAny || requiredAny.length === 0)) {
|
|
23
36
|
return true;
|
|
24
37
|
}
|
|
25
38
|
const request = context.switchToHttp().getRequest();
|
|
@@ -28,22 +41,41 @@ let SystemPermissionsGuard = SystemPermissionsGuard_1 = class SystemPermissionsG
|
|
|
28
41
|
this.logger.warn('Auth check - No user found in request');
|
|
29
42
|
throw new common_1.UnauthorizedException();
|
|
30
43
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
if (requiredAll && requiredAll.length > 0) {
|
|
45
|
+
const missing = requiredAll.filter((p) => { var _a; return !((_a = user.effectivePermissions) === null || _a === void 0 ? void 0 : _a.has(p)); });
|
|
46
|
+
if (missing.length > 0) {
|
|
47
|
+
this.logger.debug(`User ${user.id} missing permissions: ${missing.join(', ')}`);
|
|
48
|
+
throw new common_1.ForbiddenException('Insufficient permissions');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (requiredAny && requiredAny.length > 0) {
|
|
52
|
+
const hasAny = requiredAny.some((p) => { var _a; return (_a = user.effectivePermissions) === null || _a === void 0 ? void 0 : _a.has(p); });
|
|
53
|
+
if (!hasAny) {
|
|
54
|
+
this.logger.debug(`User ${user.id} has none of the required permissions: ${requiredAny.join(', ')}`);
|
|
55
|
+
throw new common_1.ForbiddenException('Insufficient permissions');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
42
59
|
}
|
|
43
60
|
};
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
61
|
+
exports.EffectivePermissionsGuard = EffectivePermissionsGuard;
|
|
62
|
+
exports.EffectivePermissionsGuard = EffectivePermissionsGuard = EffectivePermissionsGuard_1 = tslib_1.__decorate([
|
|
46
63
|
(0, common_1.Injectable)(),
|
|
47
64
|
tslib_1.__metadata("design:paramtypes", [core_1.Reflector])
|
|
48
|
-
],
|
|
65
|
+
], EffectivePermissionsGuard);
|
|
66
|
+
let SessionOnlyGuard = class SessionOnlyGuard {
|
|
67
|
+
canActivate(context) {
|
|
68
|
+
const request = context.switchToHttp().getRequest();
|
|
69
|
+
const user = request.user;
|
|
70
|
+
if ((user === null || user === void 0 ? void 0 : user.authenticationMethod) !== 'session') {
|
|
71
|
+
throw new common_1.ForbiddenException('Session authentication required');
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.SessionOnlyGuard = SessionOnlyGuard;
|
|
77
|
+
exports.SessionOnlyGuard = SessionOnlyGuard = tslib_1.__decorate([
|
|
78
|
+
(0, common_1.Injectable)()
|
|
79
|
+
], SessionOnlyGuard);
|
|
80
|
+
exports.SystemPermissionsGuard = EffectivePermissionsGuard;
|
|
49
81
|
//# sourceMappingURL=auth-decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-decorator.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/auth-decorator.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"auth-decorator.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/auth-decorator.ts"],"names":[],"mappings":";;;;AAuBA,oBAOC;AAED,0BAOC;AAED,kCAOC;;AAhDD,2CASwB;AAExB,uCAAyC;AAEzC,6CAAyE;AACzE,uDAAkD;AAMlD,MAAM,gBAAgB,GAAG,gBAAS,CAAC,eAAe,EAAsB,CAAC;AACzE,MAAM,kBAAkB,GAAG,gBAAS,CAAC,eAAe,EAAsB,CAAC;AAE3E,SAAgB,IAAI,CAAC,GAAG,WAA+B;IACrD,OAAO,IAAA,wBAAe,EACpB,gBAAgB,CAAC,WAAW,CAAC,EAC7B,IAAA,kBAAS,EAAC,+BAAa,EAAE,yBAAyB,CAAC,EACnD,IAAA,uBAAa,GAAE,EACf,IAAA,iCAAuB,EAAC,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC,CACzD,CAAC;AACJ,CAAC;AAED,SAAgB,OAAO,CAAC,GAAG,WAA+B;IACxD,OAAO,IAAA,wBAAe,EACpB,kBAAkB,CAAC,WAAW,CAAC,EAC/B,IAAA,kBAAS,EAAC,+BAAa,EAAE,yBAAyB,CAAC,EACnD,IAAA,uBAAa,GAAE,EACf,IAAA,iCAAuB,EAAC,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC,CACzD,CAAC;AACJ,CAAC;AAED,SAAgB,WAAW,CAAC,GAAG,WAA+B;IAC5D,OAAO,IAAA,wBAAe,EACpB,gBAAgB,CAAC,WAAW,CAAC,EAC7B,IAAA,kBAAS,EAAC,+BAAa,EAAE,yBAAyB,EAAE,gBAAgB,CAAC,EACrE,IAAA,uBAAa,GAAE,EACf,IAAA,iCAAuB,EAAC,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC,CACzD,CAAC;AACJ,CAAC;AAGM,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAGpC,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;Q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GACA,gBAAgB,CAW5B;AAEY,QAAA,sBAAsB,GAAG,yBAAyB,CAAC"}
|
package/src/lib/auth.types.d.ts
CHANGED
|
@@ -2,6 +2,15 @@ import { User } from '@attraccess/database-entities';
|
|
|
2
2
|
import { Request as BaseRequest } from 'express';
|
|
3
3
|
export interface AuthenticatedUser extends User {
|
|
4
4
|
jwtTokenId: string;
|
|
5
|
+
authenticationMethod?: 'session' | 'api-token';
|
|
6
|
+
apiTokenId?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Effective permissions for this user. Stored as a Set for O(1) has() lookups.
|
|
9
|
+
* Note: A plain Set serializes as {} in JSON — spread to an array before including in any HTTP response.
|
|
10
|
+
* In practice the runtime value is a SerializableSet whose toJSON() emits an array,
|
|
11
|
+
* but callers should not rely on that implementation detail.
|
|
12
|
+
*/
|
|
13
|
+
effectivePermissions?: Set<string>;
|
|
5
14
|
}
|
|
6
15
|
export interface AuthenticatedRequest extends Omit<BaseRequest, 'logout'> {
|
|
7
16
|
user: AuthenticatedUser;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { MqttServerConnectionConfig, PluginContext } from './plugin-context';
|
|
2
|
+
/** Broker-neutral topic policy supplied by an integration for one MQTT identity. */
|
|
3
|
+
export interface MqttTopicPolicy {
|
|
4
|
+
readonly publish: readonly string[];
|
|
5
|
+
readonly subscribe: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
/** The broker identity an integration wants to install on a device. */
|
|
8
|
+
export interface MqttCredentialRequest {
|
|
9
|
+
readonly mqttServerId: number;
|
|
10
|
+
readonly identity: string;
|
|
11
|
+
readonly username: string;
|
|
12
|
+
readonly vhost: string;
|
|
13
|
+
readonly topicPolicy: MqttTopicPolicy;
|
|
14
|
+
}
|
|
15
|
+
/** The password is deliberately present only on create and rotate responses. */
|
|
16
|
+
export interface ProvisionedMqttCredential {
|
|
17
|
+
readonly providerId: string;
|
|
18
|
+
readonly identity: string;
|
|
19
|
+
readonly username: string;
|
|
20
|
+
readonly vhost: string;
|
|
21
|
+
readonly password: string;
|
|
22
|
+
}
|
|
23
|
+
/** A provider supplied by a broker plugin. It never exposes broker details to integrations. */
|
|
24
|
+
export interface MqttCredentialProvisioningProvider {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly displayName: string;
|
|
27
|
+
supports(config: MqttServerConnectionConfig): Promise<boolean>;
|
|
28
|
+
provision(request: MqttCredentialRequest): Promise<ProvisionedMqttCredential>;
|
|
29
|
+
rotate(request: MqttCredentialRequest): Promise<ProvisionedMqttCredential>;
|
|
30
|
+
revoke(request: Pick<MqttCredentialRequest, 'mqttServerId' | 'identity' | 'username' | 'vhost'>): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare const MQTT_CREDENTIAL_PROVISIONING_HOST_PROVIDER: unique symbol;
|
|
33
|
+
/** Host seam through which integrations discover and use broker providers. */
|
|
34
|
+
export interface MqttCredentialProvisioningHostProvider {
|
|
35
|
+
availableProviders(mqttServerId: number): Promise<readonly {
|
|
36
|
+
providerId: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
}[]>;
|
|
39
|
+
provision(request: MqttCredentialRequest): Promise<ProvisionedMqttCredential | ManualMqttCredentialInstructions>;
|
|
40
|
+
rotate(request: MqttCredentialRequest): Promise<ProvisionedMqttCredential | ManualMqttCredentialInstructions>;
|
|
41
|
+
revoke(request: Pick<MqttCredentialRequest, 'mqttServerId' | 'identity' | 'username' | 'vhost'>): Promise<void | ManualMqttCredentialInstructions>;
|
|
42
|
+
}
|
|
43
|
+
export interface ManualMqttCredentialInstructions {
|
|
44
|
+
readonly mqttServerId: number;
|
|
45
|
+
readonly username: string;
|
|
46
|
+
readonly vhost: string;
|
|
47
|
+
readonly publishTopics: readonly string[];
|
|
48
|
+
readonly subscribeTopics: readonly string[];
|
|
49
|
+
readonly instructions: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
/** Factory keeps provider dependencies private to the plugin that owns them. */
|
|
52
|
+
export type MqttCredentialProvisioningProviderFactory = (context: PluginContext) => MqttCredentialProvisioningProvider;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MQTT_CREDENTIAL_PROVISIONING_HOST_PROVIDER = void 0;
|
|
4
|
+
exports.MQTT_CREDENTIAL_PROVISIONING_HOST_PROVIDER = Symbol.for('attraccess.plugin.mqttCredentialProvisioningHostProvider');
|
|
5
|
+
//# sourceMappingURL=mqtt-credential-provisioning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mqtt-credential-provisioning.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/mqtt-credential-provisioning.ts"],"names":[],"mappings":";;;AAoCa,QAAA,0CAA0C,GAAG,MAAM,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Implemented by the generic audit foundation, not by individual plugins. */
|
|
2
|
+
export declare const PLUGIN_AUDIT_HOST_PROVIDER: unique symbol;
|
|
3
|
+
export interface PluginAuditPrincipal {
|
|
4
|
+
userId: number;
|
|
5
|
+
authenticationMethod: 'session' | 'api-token';
|
|
6
|
+
apiTokenId?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PluginAuditEvent {
|
|
9
|
+
action: string;
|
|
10
|
+
operationId: string;
|
|
11
|
+
principal: PluginAuditPrincipal;
|
|
12
|
+
outcome: 'attempted' | 'succeeded' | 'failed';
|
|
13
|
+
subject: {
|
|
14
|
+
type: string;
|
|
15
|
+
id: number;
|
|
16
|
+
};
|
|
17
|
+
/** Callers must project domain data through an explicit allowlist. */
|
|
18
|
+
details: Readonly<Record<string, string | number | boolean | null>>;
|
|
19
|
+
}
|
|
20
|
+
/** Only `recorded` means the host durably accepted the event. */
|
|
21
|
+
export type PluginAuditReceipt = {
|
|
22
|
+
status: 'recorded';
|
|
23
|
+
} | {
|
|
24
|
+
status: 'unavailable';
|
|
25
|
+
};
|
|
26
|
+
export interface PluginAuditContext {
|
|
27
|
+
record(event: PluginAuditEvent): Promise<PluginAuditReceipt>;
|
|
28
|
+
}
|
|
29
|
+
export interface PluginAuditHostProvider {
|
|
30
|
+
record(event: PluginAuditEvent & {
|
|
31
|
+
pluginId: string;
|
|
32
|
+
}): Promise<PluginAuditReceipt>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Declarative audit policy a plugin contributes through `PluginBackendModule.auditDomains`.
|
|
36
|
+
* The host registers the declaration, then enforces it on every event the plugin records:
|
|
37
|
+
* only declared actions, subject types and detail fields are accepted, so a plugin can
|
|
38
|
+
* never write arbitrary JSON into the audit log. The host additionally applies generic
|
|
39
|
+
* bounds (identifier shapes, detail size) and rejects events whose pluginId does not own
|
|
40
|
+
* the domain.
|
|
41
|
+
*/
|
|
42
|
+
/** Domain identifiers are lowercase snake_case and prefix every action and subject type. */
|
|
43
|
+
export declare const PLUGIN_AUDIT_DOMAIN_PATTERN: RegExp;
|
|
44
|
+
/** One dot-separated segment of an action or subject type name. */
|
|
45
|
+
export declare const PLUGIN_AUDIT_SEGMENT_PATTERN: RegExp;
|
|
46
|
+
/** Detail field name: camelCase segments, optionally dot-prefixed (e.g. `before.count`). */
|
|
47
|
+
export declare const PLUGIN_AUDIT_FIELD_PATTERN: RegExp;
|
|
48
|
+
export declare const PLUGIN_AUDIT_LIMITS: {
|
|
49
|
+
readonly domainsPerPlugin: 4;
|
|
50
|
+
readonly actionsPerDomain: 64;
|
|
51
|
+
readonly subjectTypesPerAction: 8;
|
|
52
|
+
readonly fieldsPerAction: 32;
|
|
53
|
+
readonly oneOfEntries: 64;
|
|
54
|
+
readonly patternLength: 512;
|
|
55
|
+
readonly maxLengthCeiling: 4096;
|
|
56
|
+
readonly labelLocales: 8;
|
|
57
|
+
readonly labelLength: 120;
|
|
58
|
+
readonly actionLength: 128;
|
|
59
|
+
};
|
|
60
|
+
export interface PluginAuditFieldPolicy {
|
|
61
|
+
readonly type: 'string' | 'number' | 'boolean';
|
|
62
|
+
/** Full-match regex source; the host anchors it. Strings only. */
|
|
63
|
+
readonly pattern?: string;
|
|
64
|
+
/** Closed value set; entries must match `type`. */
|
|
65
|
+
readonly oneOf?: readonly (string | number)[];
|
|
66
|
+
/** Inclusive numeric bounds. Numbers only. */
|
|
67
|
+
readonly min?: number;
|
|
68
|
+
readonly max?: number;
|
|
69
|
+
/** Reject non-integers. Numbers only. */
|
|
70
|
+
readonly integer?: boolean;
|
|
71
|
+
/** Inclusive UTF-16 code-unit bound. Strings only. */
|
|
72
|
+
readonly maxLength?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface PluginAuditActionPolicy {
|
|
75
|
+
/** Full action name; must start with `${domain}.`. */
|
|
76
|
+
readonly action: string;
|
|
77
|
+
/** Subject types accepted for this action; each must start with `${domain}.`. */
|
|
78
|
+
readonly subjectTypes: readonly string[];
|
|
79
|
+
/** Allowed detail fields. Events carrying any other field are rejected. */
|
|
80
|
+
readonly details?: Readonly<Record<string, PluginAuditFieldPolicy>>;
|
|
81
|
+
}
|
|
82
|
+
export interface PluginAuditDomainDeclaration {
|
|
83
|
+
/** Lowercase identifier; becomes the audit domain and the action/subject-type prefix. */
|
|
84
|
+
readonly domain: string;
|
|
85
|
+
/** Optional human-readable domain labels keyed by locale (e.g. `{ en: 'Demo devices' }`). */
|
|
86
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
87
|
+
readonly actions: readonly PluginAuditActionPolicy[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Validates one plugin-contributed audit domain declaration and returns it unchanged.
|
|
91
|
+
* Throws a descriptive error on any violation; hosts quarantine the plugin in that case.
|
|
92
|
+
* Cross-domain concerns (collisions with core or other plugins) are checked by the host registry.
|
|
93
|
+
*/
|
|
94
|
+
export declare function validatePluginAuditDomainDeclaration<T extends PluginAuditDomainDeclaration>(declaration: T): T;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLUGIN_AUDIT_LIMITS = exports.PLUGIN_AUDIT_FIELD_PATTERN = exports.PLUGIN_AUDIT_SEGMENT_PATTERN = exports.PLUGIN_AUDIT_DOMAIN_PATTERN = exports.PLUGIN_AUDIT_HOST_PROVIDER = void 0;
|
|
4
|
+
exports.validatePluginAuditDomainDeclaration = validatePluginAuditDomainDeclaration;
|
|
5
|
+
/** Implemented by the generic audit foundation, not by individual plugins. */
|
|
6
|
+
exports.PLUGIN_AUDIT_HOST_PROVIDER = Symbol.for('attraccess.plugin.auditHostProvider');
|
|
7
|
+
/**
|
|
8
|
+
* Declarative audit policy a plugin contributes through `PluginBackendModule.auditDomains`.
|
|
9
|
+
* The host registers the declaration, then enforces it on every event the plugin records:
|
|
10
|
+
* only declared actions, subject types and detail fields are accepted, so a plugin can
|
|
11
|
+
* never write arbitrary JSON into the audit log. The host additionally applies generic
|
|
12
|
+
* bounds (identifier shapes, detail size) and rejects events whose pluginId does not own
|
|
13
|
+
* the domain.
|
|
14
|
+
*/
|
|
15
|
+
/** Domain identifiers are lowercase snake_case and prefix every action and subject type. */
|
|
16
|
+
exports.PLUGIN_AUDIT_DOMAIN_PATTERN = /^[a-z][a-z_]{0,31}$/;
|
|
17
|
+
/** One dot-separated segment of an action or subject type name. */
|
|
18
|
+
exports.PLUGIN_AUDIT_SEGMENT_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
19
|
+
/** Detail field name: camelCase segments, optionally dot-prefixed (e.g. `before.count`). */
|
|
20
|
+
exports.PLUGIN_AUDIT_FIELD_PATTERN = /^[a-z][a-zA-Z0-9]*(?:\.[a-z][a-zA-Z0-9]*)*$/;
|
|
21
|
+
exports.PLUGIN_AUDIT_LIMITS = {
|
|
22
|
+
domainsPerPlugin: 4,
|
|
23
|
+
actionsPerDomain: 64,
|
|
24
|
+
subjectTypesPerAction: 8,
|
|
25
|
+
fieldsPerAction: 32,
|
|
26
|
+
oneOfEntries: 64,
|
|
27
|
+
patternLength: 512,
|
|
28
|
+
maxLengthCeiling: 4096,
|
|
29
|
+
labelLocales: 8,
|
|
30
|
+
labelLength: 120,
|
|
31
|
+
actionLength: 128,
|
|
32
|
+
};
|
|
33
|
+
const isPlainRecord = (value) => {
|
|
34
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
35
|
+
return false;
|
|
36
|
+
const prototype = Object.getPrototypeOf(value);
|
|
37
|
+
return prototype === Object.prototype || prototype === null;
|
|
38
|
+
};
|
|
39
|
+
const dottedName = (prefix, value, maxLength) => {
|
|
40
|
+
if (typeof value !== 'string' || value.length > maxLength || !value.startsWith(`${prefix}.`))
|
|
41
|
+
return false;
|
|
42
|
+
const segments = value.slice(prefix.length + 1).split('.');
|
|
43
|
+
return segments.length > 0 && segments.every((segment) => exports.PLUGIN_AUDIT_SEGMENT_PATTERN.test(segment));
|
|
44
|
+
};
|
|
45
|
+
function validateFieldChoices(path, policy, declared) {
|
|
46
|
+
if (policy.pattern !== undefined) {
|
|
47
|
+
if (declared !== 'string')
|
|
48
|
+
throw new Error(`${path}: pattern requires type 'string'`);
|
|
49
|
+
if (typeof policy.pattern !== 'string' || policy.pattern.length > exports.PLUGIN_AUDIT_LIMITS.patternLength)
|
|
50
|
+
throw new Error(`${path}: pattern must be a string of at most ${exports.PLUGIN_AUDIT_LIMITS.patternLength} characters`);
|
|
51
|
+
try {
|
|
52
|
+
new RegExp(policy.pattern);
|
|
53
|
+
}
|
|
54
|
+
catch (_a) {
|
|
55
|
+
throw new Error(`${path}: pattern is not a valid regular expression`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (policy.oneOf !== undefined) {
|
|
59
|
+
const entries = policy.oneOf;
|
|
60
|
+
if (!Array.isArray(entries) ||
|
|
61
|
+
entries.length === 0 ||
|
|
62
|
+
entries.length > exports.PLUGIN_AUDIT_LIMITS.oneOfEntries ||
|
|
63
|
+
entries.some((entry) => typeof entry !== declared))
|
|
64
|
+
throw new Error(`${path}: oneOf must be 1-${exports.PLUGIN_AUDIT_LIMITS.oneOfEntries} values of type '${declared}'`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function validateFieldPolicy(path, policy) {
|
|
68
|
+
if (!isPlainRecord(policy))
|
|
69
|
+
throw new Error(`${path}: field policy must be a plain object`);
|
|
70
|
+
const declared = policy.type;
|
|
71
|
+
if (declared !== 'string' && declared !== 'number' && declared !== 'boolean')
|
|
72
|
+
throw new Error(`${path}: field type must be 'string', 'number' or 'boolean'`);
|
|
73
|
+
const keys = Object.keys(policy);
|
|
74
|
+
for (const key of keys)
|
|
75
|
+
if (!['type', 'pattern', 'oneOf', 'min', 'max', 'integer', 'maxLength'].includes(key))
|
|
76
|
+
throw new Error(`${path}: unknown field policy property "${key}"`);
|
|
77
|
+
validateFieldChoices(path, policy, declared);
|
|
78
|
+
for (const bound of ['min', 'max'])
|
|
79
|
+
if (policy[bound] !== undefined) {
|
|
80
|
+
if (declared !== 'number' || typeof policy[bound] !== 'number' || !Number.isFinite(policy[bound]))
|
|
81
|
+
throw new Error(`${path}: ${bound} requires a finite number and type 'number'`);
|
|
82
|
+
}
|
|
83
|
+
if (policy.integer !== undefined) {
|
|
84
|
+
if (declared !== 'number' || typeof policy.integer !== 'boolean')
|
|
85
|
+
throw new Error(`${path}: integer requires a boolean and type 'number'`);
|
|
86
|
+
}
|
|
87
|
+
if (policy.maxLength !== undefined) {
|
|
88
|
+
if (declared !== 'string' ||
|
|
89
|
+
typeof policy.maxLength !== 'number' ||
|
|
90
|
+
!Number.isSafeInteger(policy.maxLength) ||
|
|
91
|
+
policy.maxLength < 1 ||
|
|
92
|
+
policy.maxLength > exports.PLUGIN_AUDIT_LIMITS.maxLengthCeiling)
|
|
93
|
+
throw new Error(`${path}: maxLength requires an integer 1-${exports.PLUGIN_AUDIT_LIMITS.maxLengthCeiling} and type 'string'`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function validateDomainLabels(declaration, prefix) {
|
|
97
|
+
if (declaration.labels !== undefined) {
|
|
98
|
+
if (!isPlainRecord(declaration.labels))
|
|
99
|
+
throw new Error(`Audit domain "${prefix}": labels must be a plain object`);
|
|
100
|
+
const locales = Object.keys(declaration.labels);
|
|
101
|
+
if (locales.length > exports.PLUGIN_AUDIT_LIMITS.labelLocales)
|
|
102
|
+
throw new Error(`Audit domain "${prefix}": at most ${exports.PLUGIN_AUDIT_LIMITS.labelLocales} label locales`);
|
|
103
|
+
for (const locale of locales) {
|
|
104
|
+
const label = declaration.labels[locale];
|
|
105
|
+
if (!/^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/.test(locale))
|
|
106
|
+
throw new Error(`Audit domain "${prefix}": invalid label locale "${locale}"`);
|
|
107
|
+
if (typeof label !== 'string' || label.trim().length === 0 || label.length > exports.PLUGIN_AUDIT_LIMITS.labelLength)
|
|
108
|
+
throw new Error(`Audit domain "${prefix}": label for "${locale}" must be 1-${exports.PLUGIN_AUDIT_LIMITS.labelLength} characters`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Validates one plugin-contributed audit domain declaration and returns it unchanged.
|
|
114
|
+
* Throws a descriptive error on any violation; hosts quarantine the plugin in that case.
|
|
115
|
+
* Cross-domain concerns (collisions with core or other plugins) are checked by the host registry.
|
|
116
|
+
*/
|
|
117
|
+
function validatePluginAuditDomainDeclaration(declaration) {
|
|
118
|
+
if (!isPlainRecord(declaration))
|
|
119
|
+
throw new Error('Audit domain declaration must be a plain object');
|
|
120
|
+
const where = typeof declaration.domain === 'string' ? declaration.domain : '(unknown)';
|
|
121
|
+
if (typeof declaration.domain !== 'string' || !exports.PLUGIN_AUDIT_DOMAIN_PATTERN.test(declaration.domain))
|
|
122
|
+
throw new Error(`Audit domain "${where}": domain must match ${exports.PLUGIN_AUDIT_DOMAIN_PATTERN.source}`);
|
|
123
|
+
const prefix = declaration.domain;
|
|
124
|
+
validateDomainLabels(declaration, prefix);
|
|
125
|
+
if (!Array.isArray(declaration.actions) || declaration.actions.length === 0)
|
|
126
|
+
throw new Error(`Audit domain "${prefix}": actions must be a non-empty array`);
|
|
127
|
+
if (declaration.actions.length > exports.PLUGIN_AUDIT_LIMITS.actionsPerDomain)
|
|
128
|
+
throw new Error(`Audit domain "${prefix}": at most ${exports.PLUGIN_AUDIT_LIMITS.actionsPerDomain} actions`);
|
|
129
|
+
const seenActions = new Set();
|
|
130
|
+
for (const entry of declaration.actions) {
|
|
131
|
+
if (!isPlainRecord(entry))
|
|
132
|
+
throw new Error(`Audit domain "${prefix}": action policy must be a plain object`);
|
|
133
|
+
const action = entry.action;
|
|
134
|
+
if (typeof action !== 'string' || !dottedName(prefix, action, exports.PLUGIN_AUDIT_LIMITS.actionLength))
|
|
135
|
+
throw new Error(`Audit domain "${prefix}": action must be a "${prefix}."-prefixed dotted lowercase name`);
|
|
136
|
+
if (seenActions.has(action))
|
|
137
|
+
throw new Error(`Audit domain "${prefix}": duplicate action "${action}"`);
|
|
138
|
+
seenActions.add(action);
|
|
139
|
+
const entryKeys = Object.keys(entry);
|
|
140
|
+
for (const key of entryKeys)
|
|
141
|
+
if (!['action', 'subjectTypes', 'details'].includes(key))
|
|
142
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": unknown property "${key}"`);
|
|
143
|
+
if (!Array.isArray(entry.subjectTypes) || entry.subjectTypes.length === 0)
|
|
144
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": subjectTypes must be a non-empty array`);
|
|
145
|
+
if (entry.subjectTypes.length > exports.PLUGIN_AUDIT_LIMITS.subjectTypesPerAction)
|
|
146
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": at most ${exports.PLUGIN_AUDIT_LIMITS.subjectTypesPerAction} subject types`);
|
|
147
|
+
const seenSubjects = new Set();
|
|
148
|
+
for (const subjectType of entry.subjectTypes) {
|
|
149
|
+
if (!dottedName(prefix, subjectType, exports.PLUGIN_AUDIT_LIMITS.actionLength))
|
|
150
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": subject type must be a "${prefix}."-prefixed dotted lowercase name`);
|
|
151
|
+
if (seenSubjects.has(subjectType))
|
|
152
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": duplicate subject type "${subjectType}"`);
|
|
153
|
+
seenSubjects.add(subjectType);
|
|
154
|
+
}
|
|
155
|
+
if (entry.details !== undefined) {
|
|
156
|
+
if (!isPlainRecord(entry.details))
|
|
157
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": details must be a plain object`);
|
|
158
|
+
const fields = Object.keys(entry.details);
|
|
159
|
+
if (fields.length > exports.PLUGIN_AUDIT_LIMITS.fieldsPerAction)
|
|
160
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": at most ${exports.PLUGIN_AUDIT_LIMITS.fieldsPerAction} detail fields`);
|
|
161
|
+
for (const field of fields) {
|
|
162
|
+
if (!exports.PLUGIN_AUDIT_FIELD_PATTERN.test(field))
|
|
163
|
+
throw new Error(`Audit domain "${prefix}", action "${action}": detail field "${field}" must match ${exports.PLUGIN_AUDIT_FIELD_PATTERN.source}`);
|
|
164
|
+
validateFieldPolicy(`Audit domain "${prefix}", action "${action}", field "${field}"`, entry.details[field]);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return declaration;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=plugin-audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-audit.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin-audit.ts"],"names":[],"mappings":";;;AAsLA,oFAyDC;AA/OD,8EAA8E;AACjE,QAAA,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;AA6B5F;;;;;;;GAOG;AAEH,4FAA4F;AAC/E,QAAA,2BAA2B,GAAG,qBAAqB,CAAC;AACjE,mEAAmE;AACtD,QAAA,4BAA4B,GA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B,MAAM,mCAAmC,CACnH,CAAC;YACJ,IAAI,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,iBAAiB,MAAM,cAAc,MAAM,8BAA8B,WAAW,GAAG,CAAC,CAAC;YAC3G,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAChC,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,iBAAiB,MAAM,cAAc,MAAM,mCAAmC,CAAC,CAAC;YAClG,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,MAAM,CAAC,MAAM,GAAG,2BAAmB,CAAC,eAAe;gBACrD,MAAM,IAAI,KAAK,CACb,iBAAiB,MAAM,cAAc,MAAM,cAAc,2BAAmB,CAAC,eAAe,gBAAgB,CAC7G,CAAC;YACJ,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,IAAI,CAAC,kCAA0B,CAAC,IAAI,CAAC,KAAK,CAAC;oBACzC,MAAM,IAAI,KAAK,CACb,iBAAiB,MAAM,cAAc,MAAM,oBAAoB,KAAK,gBAAgB,kCAA0B,CAAC,MAAM,EAAE,CACxH,CAAC;gBACJ,mBAAmB,CAAC,iBAAiB,MAAM,cAAc,MAAM,aAAa,KAAK,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9G,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { DynamicModule, LoggerService, Type } from '@nestjs/common';
|
|
2
|
+
import type { PluginFlowNodeDefinition } from './plugin-flow-node';
|
|
2
3
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
4
|
import { DataSource, EntityTarget, ObjectLiteral, Repository } from 'typeorm';
|
|
4
5
|
import { SystemEvent, SystemEventHandler, SystemEventPayload, SystemEventSubscription } from './plugin.interface';
|
|
5
6
|
import type { PluginEntityClass } from './entity';
|
|
7
|
+
import type { MqttCredentialProvisioningProviderFactory } from './mqtt-credential-provisioning';
|
|
8
|
+
import type { MqttCredentialProvisioningHostProvider } from './mqtt-credential-provisioning';
|
|
9
|
+
import type { PluginAuditContext, PluginAuditDomainDeclaration } from './plugin-audit';
|
|
6
10
|
/**
|
|
7
11
|
* DI token under which a plugin's own services can inject the PluginContext.
|
|
8
12
|
* The host publishes the context as a module-scoped provider with this token.
|
|
@@ -34,7 +38,14 @@ export interface MqttServerConnectionConfig {
|
|
|
34
38
|
readonly name: string;
|
|
35
39
|
readonly host: string;
|
|
36
40
|
readonly port: number;
|
|
41
|
+
/** Management API port on the same host (1-65535). Null/omitted uses the provider default. */
|
|
42
|
+
readonly managementPort?: number | null;
|
|
37
43
|
readonly useTls: boolean;
|
|
44
|
+
/** PEM trust anchors for private PKI. Omitted by older hosts. */
|
|
45
|
+
readonly caCert?: string | null;
|
|
46
|
+
/** Integrations requiring authenticated TLS must reject this setting. */
|
|
47
|
+
readonly tlsInsecure?: boolean;
|
|
48
|
+
readonly tlsServername?: string | null;
|
|
38
49
|
readonly username: string | null;
|
|
39
50
|
/** Resolved (decrypted) password. Only ever provided to permitted plugins. */
|
|
40
51
|
readonly password: string | null;
|
|
@@ -49,12 +60,52 @@ export interface MqttServerConnectionConfig {
|
|
|
49
60
|
export interface MqttServerHostProvider {
|
|
50
61
|
getServerConfig(serverId: number): Promise<MqttServerConnectionConfig | null>;
|
|
51
62
|
}
|
|
63
|
+
/** A message delivered to a plugin's MQTT subscription. */
|
|
64
|
+
export interface PluginMqttMessage {
|
|
65
|
+
readonly serverId: number;
|
|
66
|
+
readonly topic: string;
|
|
67
|
+
readonly payload: Buffer;
|
|
68
|
+
}
|
|
69
|
+
/** Handle returned from an MQTT subscription. */
|
|
70
|
+
export interface PluginMqttSubscription {
|
|
71
|
+
unsubscribe(): void;
|
|
72
|
+
}
|
|
73
|
+
export interface PluginMqttClient {
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe through the host's shared MQTT connection. MQTT wildcards `+`
|
|
76
|
+
* and `#` are supported. Resolves after the broker acknowledges the
|
|
77
|
+
* subscription. Handlers run serially; each subscription buffers up to 100
|
|
78
|
+
* messages and drops new messages while full. The returned handle detaches
|
|
79
|
+
* the handler.
|
|
80
|
+
*/
|
|
81
|
+
subscribe(serverId: number, topicFilter: string, handler: (message: PluginMqttMessage) => void | Promise<void>): Promise<PluginMqttSubscription>;
|
|
82
|
+
/** Publish through the host's shared MQTT connection. */
|
|
83
|
+
publish(serverId: number, topic: string, payload: string | Buffer, options?: {
|
|
84
|
+
qos?: 0 | 1 | 2;
|
|
85
|
+
retain?: boolean;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
/** Host flow functionality available to plugins with the TRIGGER_FLOWS permission. */
|
|
89
|
+
export interface PluginFlowsContext {
|
|
90
|
+
/**
|
|
91
|
+
* Starts a flow from every persisted trigger node of nodeType whose saved
|
|
92
|
+
* configuration matches the supplied external event.
|
|
93
|
+
*/
|
|
94
|
+
trigger(nodeType: string, matches: (config: Record<string, unknown>, nodeId: string) => boolean, payload: object): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/** Host-managed encryption for secret material owned by this plugin. */
|
|
97
|
+
export interface PluginSecretsContext {
|
|
98
|
+
encrypt(plaintext: string): string;
|
|
99
|
+
decrypt(ciphertext: string): string;
|
|
100
|
+
}
|
|
52
101
|
/**
|
|
53
102
|
* Curated facade handed to a backend plugin at load time. It is the single,
|
|
54
103
|
* versioned seam between plugin code and the host application. Adding a field is
|
|
55
104
|
* a minor SDK bump; removing/changing one is a major bump.
|
|
56
105
|
*/
|
|
57
106
|
export interface PluginContext {
|
|
107
|
+
/** Optional for compatibility with hosts predating generic plugin audit support. */
|
|
108
|
+
readonly audit?: PluginAuditContext;
|
|
58
109
|
/** This plugin's own manifest (name, version, directory, id). */
|
|
59
110
|
readonly manifest: PluginManifestInfo;
|
|
60
111
|
/** Shared application event bus — the same EventEmitter2 instance the host uses. */
|
|
@@ -63,6 +114,8 @@ export interface PluginContext {
|
|
|
63
114
|
readonly dataSource: DataSource;
|
|
64
115
|
/** Scoped logger, prefixed with the plugin name. */
|
|
65
116
|
readonly logger: LoggerService;
|
|
117
|
+
/** Shared MQTT connection access. Requires ACCESS_MQTT_SERVERS. */
|
|
118
|
+
readonly mqtt: PluginMqttClient;
|
|
66
119
|
/** Typed repository accessor over the shared DataSource. */
|
|
67
120
|
getRepository<T extends ObjectLiteral>(entity: EntityTarget<T>): Repository<T>;
|
|
68
121
|
/**
|
|
@@ -86,9 +139,15 @@ export interface PluginContext {
|
|
|
86
139
|
* (decrypted) credentials. Requires the ACCESS_MQTT_SERVERS permission.
|
|
87
140
|
* Returns null when no server with the given id exists. The host performs all
|
|
88
141
|
* credential decryption; the plugin only ever receives the mapped config — it
|
|
89
|
-
* stays broker-agnostic (no
|
|
142
|
+
* stays broker-agnostic (no broker-vendor awareness).
|
|
90
143
|
*/
|
|
91
144
|
getMqttServerConfig(serverId: number): Promise<MqttServerConnectionConfig | null>;
|
|
145
|
+
/** Discover and use the host-selected broker credential provider. Requires ACCESS_MQTT_SERVERS. */
|
|
146
|
+
getMqttCredentialProvisioning(): MqttCredentialProvisioningHostProvider;
|
|
147
|
+
/** Start matching flows from a plugin-declared trigger node. Requires TRIGGER_FLOWS. */
|
|
148
|
+
readonly flows: PluginFlowsContext;
|
|
149
|
+
/** Encrypt and decrypt this plugin's secret material. Requires MANAGE_SECRETS. */
|
|
150
|
+
readonly secrets: PluginSecretsContext;
|
|
92
151
|
}
|
|
93
152
|
/**
|
|
94
153
|
* Shape every backend plugin's default export must satisfy. The host calls
|
|
@@ -105,4 +164,23 @@ export interface PluginBackendModule {
|
|
|
105
164
|
* the DATABASE_ACCESS permission. See `docs/en/plugins/database-migrations.md`.
|
|
106
165
|
*/
|
|
107
166
|
entities?: PluginEntityClass[];
|
|
167
|
+
/**
|
|
168
|
+
* Optional custom flow node types this plugin contributes. The host registers
|
|
169
|
+
* them into the flow engine so they appear in the frontend node catalog and
|
|
170
|
+
* can be executed like built-in node types. No extra permission is required.
|
|
171
|
+
*
|
|
172
|
+
* Type naming convention: "plugin.<pluginName>.<nodeName>".
|
|
173
|
+
*/
|
|
174
|
+
flowNodes?: PluginFlowNodeDefinition[] | ((context: PluginContext) => PluginFlowNodeDefinition[]);
|
|
175
|
+
/**
|
|
176
|
+
* Optional audit domains this plugin contributes. The host registers the
|
|
177
|
+
* declarations at load time and enforces them on every event the plugin
|
|
178
|
+
* records through {@link PluginContext.audit}: only declared actions, subject
|
|
179
|
+
* types and detail fields are accepted, and events are stored under the
|
|
180
|
+
* declared domain. Domains must not collide with host domains or with other
|
|
181
|
+
* plugins. No extra permission is required.
|
|
182
|
+
*/
|
|
183
|
+
auditDomains?: PluginAuditDomainDeclaration[] | ((context: PluginContext) => PluginAuditDomainDeclaration[]);
|
|
184
|
+
/** Optional broker credential provider offered to other integrations by this plugin. */
|
|
185
|
+
credentialProvisioningProvider?: MqttCredentialProvisioningProviderFactory;
|
|
108
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-context.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin-context.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plugin-context.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin-context.ts"],"names":[],"mappings":";;;AAUA;;;GAGG;AACU,QAAA,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAatE;;;;GAIG;AACU,QAAA,yBAAyB,GAAG,MAAM,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract for backend plugins to register custom flow node types.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* export default {
|
|
6
|
+
* register(context) { ... },
|
|
7
|
+
* flowNodes: [demoOnNode, demoOffNode],
|
|
8
|
+
* } satisfies PluginBackendModule;
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Minimal execution context passed to a plugin node's execute() function.
|
|
12
|
+
* Mirrors the subset of NodeExecutionContext that is useful to plugins;
|
|
13
|
+
* the host satisfies this interface structurally.
|
|
14
|
+
*/
|
|
15
|
+
export interface PluginNodeExecutionContext {
|
|
16
|
+
/**
|
|
17
|
+
* Compile a Handlebars template string against the current payload data.
|
|
18
|
+
* Supports the same template variables as built-in node types
|
|
19
|
+
* ({{resource.id}}, {{payload.*}}, etc.).
|
|
20
|
+
*/
|
|
21
|
+
compileTemplate(template: string, data: object): string;
|
|
22
|
+
}
|
|
23
|
+
export type PluginFlowFailureKind = 'transport-dispatch' | 'acknowledgement-timeout' | 'controller-rejection' | 'node-failure';
|
|
24
|
+
export type PluginFlowFailureBehavior = 'fail-flow' | 'failure-output' | 'log-and-continue';
|
|
25
|
+
export interface PluginFlowNodeValidationError {
|
|
26
|
+
field: string;
|
|
27
|
+
message: string;
|
|
28
|
+
value?: unknown;
|
|
29
|
+
}
|
|
30
|
+
/** Request-scoped storage shared while validating all nodes in a flow. */
|
|
31
|
+
export type PluginFlowNodeValidationContext = Map<string, unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* Describes a single custom flow node contributed by a plugin.
|
|
34
|
+
*
|
|
35
|
+
* Node type naming convention: use "plugin.<pluginName>.<nodeName>" to
|
|
36
|
+
* guarantee no collision with core node types, e.g. "plugin.demo.send-on".
|
|
37
|
+
*/
|
|
38
|
+
interface PluginFlowNodeDefinitionBase {
|
|
39
|
+
/**
|
|
40
|
+
* Unique type string. Must be stable across plugin versions — it is stored
|
|
41
|
+
* in the database alongside saved flows. Convention: "plugin.<name>.<node>".
|
|
42
|
+
*/
|
|
43
|
+
readonly type: string;
|
|
44
|
+
/**
|
|
45
|
+
* Human-readable display name. Used in the frontend node catalog and on the
|
|
46
|
+
* canvas as a fallback when no i18n translation key is found for this type.
|
|
47
|
+
*/
|
|
48
|
+
readonly label: string;
|
|
49
|
+
/** Optional description shown in the catalog node preview. */
|
|
50
|
+
readonly description?: string;
|
|
51
|
+
/**
|
|
52
|
+
* JSON Schema object describing the node's configuration fields.
|
|
53
|
+
* The host uses this to render the config form in the frontend editor.
|
|
54
|
+
*
|
|
55
|
+
* Supports the same meta extensions as built-in schemas:
|
|
56
|
+
* { selectFromEntity: 'mqttServer', entityProperty: 'id' }
|
|
57
|
+
* { stringVariant: 'multiline' }
|
|
58
|
+
* { helpText: '...' }
|
|
59
|
+
*/
|
|
60
|
+
readonly configSchema?: Record<string, unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* Builds a configuration schema from the values selected so far. The returned
|
|
63
|
+
* schema must set `dynamic: true`; fields that should trigger a refresh set
|
|
64
|
+
* `refreshesSchema: true`.
|
|
65
|
+
*/
|
|
66
|
+
resolveConfigSchema?(currentConfig: Record<string, unknown>, context: {
|
|
67
|
+
resourceId: number;
|
|
68
|
+
}): Promise<Record<string, unknown>>;
|
|
69
|
+
/** Handle IDs accepted as inputs (e.g. ['input']). Empty for trigger nodes. */
|
|
70
|
+
readonly inputs: readonly string[];
|
|
71
|
+
/** Handle IDs produced as outputs (e.g. ['output']). Empty for terminal nodes. */
|
|
72
|
+
readonly outputs: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* Whether the node is available for all resource types.
|
|
75
|
+
* Defaults to true. Set false to hide it from the catalog for all resources.
|
|
76
|
+
*/
|
|
77
|
+
readonly supportedByAllResources?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Set to true for nodes that terminate a flow branch (no further chaining
|
|
80
|
+
* expected). Controls the direction indicator in the catalog UI.
|
|
81
|
+
*/
|
|
82
|
+
readonly isOutput?: boolean;
|
|
83
|
+
/** Validates persisted configuration independently of the editor schema. */
|
|
84
|
+
validateConfig?(config: Record<string, unknown>, context: PluginFlowNodeValidationContext): Promise<PluginFlowNodeValidationError[]>;
|
|
85
|
+
/** Enables the host's shared external-effect failure policy for this node. */
|
|
86
|
+
getFailureBehavior?(config: Record<string, unknown>): PluginFlowFailureBehavior | undefined;
|
|
87
|
+
/** Classifies an execution failure for flow logs and failure outputs. */
|
|
88
|
+
getFailureKind?(error: unknown): PluginFlowFailureKind;
|
|
89
|
+
}
|
|
90
|
+
/** A plugin node that starts a flow when the plugin calls context.flows.trigger(). */
|
|
91
|
+
export interface PluginFlowTriggerNodeDefinition extends PluginFlowNodeDefinitionBase {
|
|
92
|
+
/** Marks this node as a flow trigger rather than an executable node. */
|
|
93
|
+
readonly isInput: true;
|
|
94
|
+
/** Trigger nodes do not consume a preceding node's output. */
|
|
95
|
+
readonly inputs: readonly [];
|
|
96
|
+
/** Trigger nodes always continue from the standard output handle. */
|
|
97
|
+
readonly outputs: readonly ['output'];
|
|
98
|
+
/** Trigger nodes are passthrough nodes, so the host never calls execute(). */
|
|
99
|
+
readonly execute?: never;
|
|
100
|
+
}
|
|
101
|
+
/** A plugin node executed after a flow has already started. */
|
|
102
|
+
export interface PluginFlowExecutionNodeDefinition extends PluginFlowNodeDefinitionBase {
|
|
103
|
+
readonly isInput?: false;
|
|
104
|
+
/**
|
|
105
|
+
* Execute the node. Called by the host flow engine when this node is reached
|
|
106
|
+
* during flow execution.
|
|
107
|
+
*
|
|
108
|
+
* @param node The persisted node record (id, type, data as saved config).
|
|
109
|
+
* @param input The payload object forwarded from the previous node.
|
|
110
|
+
* @param ctx Host utilities available during execution.
|
|
111
|
+
* @returns The output payload and, for multi-output nodes, the chosen handle.
|
|
112
|
+
*/
|
|
113
|
+
execute(node: {
|
|
114
|
+
id: string;
|
|
115
|
+
type: string;
|
|
116
|
+
data: Record<string, unknown>;
|
|
117
|
+
}, input: object, ctx: PluginNodeExecutionContext): Promise<{
|
|
118
|
+
payload: object;
|
|
119
|
+
outputHandle?: string;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
export type PluginFlowNodeDefinition = PluginFlowTriggerNodeDefinition | PluginFlowExecutionNodeDefinition;
|
|
123
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Contract for backend plugins to register custom flow node types.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* export default {
|
|
7
|
+
* register(context) { ... },
|
|
8
|
+
* flowNodes: [demoOnNode, demoOffNode],
|
|
9
|
+
* } satisfies PluginBackendModule;
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
//# sourceMappingURL=plugin-flow-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-flow-node.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin-flow-node.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG"}
|
|
@@ -51,7 +51,11 @@ export declare enum PluginPermission {
|
|
|
51
51
|
/** Resolve arbitrary host providers by token via context.get(). */
|
|
52
52
|
RESOLVE_HOST_PROVIDERS = "RESOLVE_HOST_PROVIDERS",
|
|
53
53
|
/** Read an MQTT server's connection config + resolved credentials via getMqttServerConfig(). */
|
|
54
|
-
ACCESS_MQTT_SERVERS = "ACCESS_MQTT_SERVERS"
|
|
54
|
+
ACCESS_MQTT_SERVERS = "ACCESS_MQTT_SERVERS",
|
|
55
|
+
/** Start flows from plugin-declared trigger nodes via flows.trigger(). */
|
|
56
|
+
TRIGGER_FLOWS = "TRIGGER_FLOWS",
|
|
57
|
+
/** Encrypt and decrypt plugin-owned secret material through the host key service. */
|
|
58
|
+
MANAGE_SECRETS = "MANAGE_SECRETS"
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* Human-readable description of each permission, surfaced to admins and plugin
|
|
@@ -30,6 +30,10 @@ var PluginPermission;
|
|
|
30
30
|
PluginPermission["RESOLVE_HOST_PROVIDERS"] = "RESOLVE_HOST_PROVIDERS";
|
|
31
31
|
/** Read an MQTT server's connection config + resolved credentials via getMqttServerConfig(). */
|
|
32
32
|
PluginPermission["ACCESS_MQTT_SERVERS"] = "ACCESS_MQTT_SERVERS";
|
|
33
|
+
/** Start flows from plugin-declared trigger nodes via flows.trigger(). */
|
|
34
|
+
PluginPermission["TRIGGER_FLOWS"] = "TRIGGER_FLOWS";
|
|
35
|
+
/** Encrypt and decrypt plugin-owned secret material through the host key service. */
|
|
36
|
+
PluginPermission["MANAGE_SECRETS"] = "MANAGE_SECRETS";
|
|
33
37
|
})(PluginPermission || (exports.PluginPermission = PluginPermission = {}));
|
|
34
38
|
/**
|
|
35
39
|
* Human-readable description of each permission, surfaced to admins and plugin
|
|
@@ -44,6 +48,8 @@ exports.PLUGIN_PERMISSION_DESCRIPTIONS = {
|
|
|
44
48
|
[PluginPermission.LISTEN_EVENTS]: 'Subscribe to events on the shared application event bus.',
|
|
45
49
|
[PluginPermission.RESOLVE_HOST_PROVIDERS]: 'Resolve arbitrary host services by injection token.',
|
|
46
50
|
[PluginPermission.ACCESS_MQTT_SERVERS]: "Read an MQTT server's connection configuration and resolved credentials.",
|
|
51
|
+
[PluginPermission.TRIGGER_FLOWS]: 'Start flows from plugin-declared trigger nodes.',
|
|
52
|
+
[PluginPermission.MANAGE_SECRETS]: 'Encrypt and decrypt plugin-owned secret material through the host key service.',
|
|
47
53
|
};
|
|
48
54
|
/**
|
|
49
55
|
* Returns true when the given string is a known PluginPermission value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.interface.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin.interface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plugin.interface.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin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