@attraccess/plugins-backend-sdk 1.11.0-beta.0 → 1.11.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/index.d.ts +4 -0
- package/src/index.js +4 -0
- package/src/index.js.map +1 -1
- package/src/internal.d.ts +6 -0
- package/src/internal.js +11 -0
- package/src/internal.js.map +1 -0
- package/src/lib/auth-decorator.d.ts +4 -3
- package/src/lib/auth-decorator.js.map +1 -1
- package/src/lib/auth.types.d.ts +5 -1
- package/src/lib/dual-auth.guard.js +4 -0
- package/src/lib/dual-auth.guard.js.map +1 -1
- package/src/lib/plugin-audit.d.ts +16 -2
- package/src/lib/plugin-audit.js +8 -3
- package/src/lib/plugin-audit.js.map +1 -1
- package/src/lib/plugin-backend-module.d.ts +15 -1
- package/src/lib/plugin-ble-fake-clock.d.ts +15 -0
- package/src/lib/plugin-ble-fake-clock.js +52 -0
- package/src/lib/plugin-ble-fake-clock.js.map +1 -0
- package/src/lib/plugin-ble-fake.d.ts +102 -0
- package/src/lib/plugin-ble-fake.js +424 -0
- package/src/lib/plugin-ble-fake.js.map +1 -0
- package/src/lib/plugin-ble-notification-stream.d.ts +30 -0
- package/src/lib/plugin-ble-notification-stream.js +123 -0
- package/src/lib/plugin-ble-notification-stream.js.map +1 -0
- package/src/lib/plugin-ble-session-engine.d.ts +151 -0
- package/src/lib/plugin-ble-session-engine.js +465 -0
- package/src/lib/plugin-ble-session-engine.js.map +1 -0
- package/src/lib/plugin-ble-validation.d.ts +71 -0
- package/src/lib/plugin-ble-validation.js +453 -0
- package/src/lib/plugin-ble-validation.js.map +1 -0
- package/src/lib/plugin-ble.d.ts +258 -0
- package/src/lib/plugin-ble.js +88 -0
- package/src/lib/plugin-ble.js.map +1 -0
- package/src/lib/plugin-context.d.ts +6 -0
- package/src/lib/plugin-context.js.map +1 -1
- package/src/lib/plugin-permissions.d.ts +65 -0
- package/src/lib/plugin-permissions.js +107 -0
- package/src/lib/plugin-permissions.js.map +1 -0
- package/src/lib/plugin-resource-access.d.ts +2 -1
- package/src/lib/plugin.interface.d.ts +20 -2
- package/src/lib/plugin.interface.js +8 -0
- package/src/lib/plugin.interface.js.map +1 -1
- package/src/lib/reader-ui.d.ts +42 -0
- package/src/lib/reader-ui.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@attraccess/plugins-backend-sdk",
|
|
3
|
-
"version": "1.11.0-beta.
|
|
3
|
+
"version": "1.11.0-beta.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/Attraccess/Attraccess.git",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"tslib": "^2.8.1",
|
|
29
|
-
"@attraccess/database-entities": "1.11.0-beta.
|
|
30
|
-
"@nestjs/common": "^
|
|
31
|
-
"@nestjs/event-emitter": "^
|
|
29
|
+
"@attraccess/database-entities": "1.11.0-beta.2",
|
|
30
|
+
"@nestjs/common": "^12.0.0",
|
|
31
|
+
"@nestjs/event-emitter": "^12.0.0",
|
|
32
32
|
"rxjs": "^7.8.2",
|
|
33
|
-
"@nestjs/core": "^
|
|
33
|
+
"@nestjs/core": "^12.0.0",
|
|
34
34
|
"typeorm": "0.3.31",
|
|
35
|
-
"@nestjs/swagger": "^
|
|
36
|
-
"express": "
|
|
37
|
-
"@nestjs/passport": "^
|
|
35
|
+
"@nestjs/swagger": "^12.0.0",
|
|
36
|
+
"express": "5.3.0",
|
|
37
|
+
"@nestjs/passport": "^12.0.0",
|
|
38
38
|
"@attraccess/shared": "*"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './lib/plugin-context';
|
|
|
4
4
|
export * from './lib/plugin-live-updates';
|
|
5
5
|
export * from './lib/shared-live-sampler';
|
|
6
6
|
export * from './lib/plugin-audit';
|
|
7
|
+
export * from './lib/plugin-permissions';
|
|
7
8
|
export * from './lib/mqtt-credential-provisioning';
|
|
8
9
|
export * from './lib/plugin-migrations';
|
|
9
10
|
export * from './lib/entity';
|
|
@@ -11,6 +12,9 @@ export * from './lib/semver';
|
|
|
11
12
|
export * from './lib/reader-ui';
|
|
12
13
|
export * from './lib/plugin-notifications';
|
|
13
14
|
export * from './lib/plugin-resource-access';
|
|
15
|
+
export * from './lib/plugin-ble';
|
|
16
|
+
export * from './lib/plugin-ble-validation';
|
|
17
|
+
export * from './lib/plugin-ble-fake';
|
|
14
18
|
export * from './lib/auth-decorator';
|
|
15
19
|
export * from '@attraccess/database-entities';
|
|
16
20
|
export * as entities from '@attraccess/database-entities';
|
package/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ tslib_1.__exportStar(require("./lib/plugin-context"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./lib/plugin-live-updates"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./lib/shared-live-sampler"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./lib/plugin-audit"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/plugin-permissions"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./lib/mqtt-credential-provisioning"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./lib/plugin-migrations"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./lib/entity"), exports);
|
|
@@ -15,6 +16,9 @@ tslib_1.__exportStar(require("./lib/semver"), exports);
|
|
|
15
16
|
tslib_1.__exportStar(require("./lib/reader-ui"), exports);
|
|
16
17
|
tslib_1.__exportStar(require("./lib/plugin-notifications"), exports);
|
|
17
18
|
tslib_1.__exportStar(require("./lib/plugin-resource-access"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./lib/plugin-ble"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./lib/plugin-ble-validation"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./lib/plugin-ble-fake"), exports);
|
|
18
22
|
tslib_1.__exportStar(require("./lib/auth-decorator"), exports);
|
|
19
23
|
tslib_1.__exportStar(require("@attraccess/database-entities"), exports);
|
|
20
24
|
exports.entities = tslib_1.__importStar(require("@attraccess/database-entities"));
|
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,iEAAuC;AACvC,+DAAqC;AACrC,oEAA0C;AAC1C,oEAA0C;AAC1C,6DAAmC;AACnC,6EAAmD;AACnD,kEAAwC;AACxC,uDAA6B;AAC7B,uDAA6B;AAC7B,0DAAgC;AAChC,qEAA2C;AAC3C,uEAA6C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/plugins-backend-sdk/src/index.ts"],"names":[],"mappings":";;;;AAAA,iEAAuC;AACvC,iEAAuC;AACvC,+DAAqC;AACrC,oEAA0C;AAC1C,oEAA0C;AAC1C,6DAAmC;AACnC,mEAAyC;AACzC,6EAAmD;AACnD,kEAAwC;AACxC,uDAA6B;AAC7B,uDAA6B;AAC7B,0DAAgC;AAChC,qEAA2C;AAC3C,uEAA6C;AAC7C,2DAAiC;AACjC,sEAA4C;AAC5C,gEAAsC;AAEtC,+DAAqC;AACrC,wEAA8C;AAC9C,kFAA0D;AAC1D,2DAAiC;AACjC,gEAAsC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-internal building blocks shared by the API host and the SDK fake. This entry is reachable only through the
|
|
3
|
+
* workspace path alias `@attraccess/plugins-backend-sdk/internal`; it is not part of the published package
|
|
4
|
+
* exports, so plugins cannot import it. Plugins use `context.ble` instead.
|
|
5
|
+
*/
|
|
6
|
+
export { BleSessionEngine, type BleSessionClock, type BleSessionEngineDeps, type BleSessionLink, } from './lib/plugin-ble-session-engine';
|
package/src/internal.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BleSessionEngine = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Host-internal building blocks shared by the API host and the SDK fake. This entry is reachable only through the
|
|
6
|
+
* workspace path alias `@attraccess/plugins-backend-sdk/internal`; it is not part of the published package
|
|
7
|
+
* exports, so plugins cannot import it. Plugins use `context.ble` instead.
|
|
8
|
+
*/
|
|
9
|
+
var plugin_ble_session_engine_1 = require("./lib/plugin-ble-session-engine");
|
|
10
|
+
Object.defineProperty(exports, "BleSessionEngine", { enumerable: true, get: function () { return plugin_ble_session_engine_1.BleSessionEngine; } });
|
|
11
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../libs/plugins-backend-sdk/src/internal.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,6EAKyC;AAJvC,6HAAA,gBAAgB,OAAA"}
|
|
@@ -2,10 +2,11 @@ import { ExecutionContext, CanActivate } from '@nestjs/common';
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { Reflector } from '@nestjs/core';
|
|
4
4
|
import { SystemPermission } from '@attraccess/shared';
|
|
5
|
+
import type { PermissionKey } from './plugin-permissions';
|
|
5
6
|
export type { SystemPermission };
|
|
6
|
-
export declare function Auth(...permissions:
|
|
7
|
-
export declare function AuthAny(...permissions:
|
|
8
|
-
export declare function SessionAuth(...permissions:
|
|
7
|
+
export declare function Auth(...permissions: PermissionKey[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
8
|
+
export declare function AuthAny(...permissions: PermissionKey[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
9
|
+
export declare function SessionAuth(...permissions: PermissionKey[]): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
9
10
|
export declare class EffectivePermissionsGuard implements CanActivate {
|
|
10
11
|
private reflector;
|
|
11
12
|
private readonly logger;
|
|
@@ -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":";;;;AAwBA,oBAOC;AAED,0BAOC;AAED,kCAOC;;AAjDD,2CASwB;AAExB,uCAAyC;AAEzC,6CAAyE;AACzE,uDAAkD;AAOlD,MAAM,gBAAgB,GAAG,gBAAS,CAAC,eAAe,EAAmB,CAAC;AACtE,MAAM,kBAAkB,GAAG,gBAAS,CAAC,eAAe,EAAmB,CAAC;AAExE,SAAgB,IAAI,CAAC,GAAG,WAA4B;IAClD,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,WAA4B;IACrD,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,WAA4B;IACzD,OAAO,IAAA,wBAAe,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ACpD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAqC,CAAC;QAE3D,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,oBAAoB,MAAK,SAAS,EAAE,CAAC;YAC7C,MAAM,IAAI,2BAAkB,CAAC,iCAAiC,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAXY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;GACA,gBAAgB,CAW5B;AAEY,QAAA,sBAAsB,GAAG,yBAAyB,CAAC"}
|
package/src/lib/auth.types.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { AuthenticationMethod } from '@attraccess/database-entities';
|
|
1
2
|
import { User } from '@attraccess/database-entities';
|
|
3
|
+
export type { AuthenticationMethod };
|
|
2
4
|
import { Request as BaseRequest } from 'express';
|
|
3
5
|
export interface AuthenticatedUser extends User {
|
|
4
6
|
jwtTokenId: string;
|
|
5
|
-
authenticationMethod?:
|
|
7
|
+
authenticationMethod?: AuthenticationMethod;
|
|
6
8
|
apiTokenId?: number;
|
|
9
|
+
/** API token or MCP grant only: the keys it was granted, before they were intersected with the owner's. */
|
|
10
|
+
permissionScope?: readonly string[];
|
|
7
11
|
/**
|
|
8
12
|
* Effective permissions for this user. Stored as a Set for O(1) has() lookups.
|
|
9
13
|
* Note: A plain Set serializes as {} in JSON — spread to an array before including in any HTTP response.
|
|
@@ -39,6 +39,10 @@ let DualAuthGuard = DualAuthGuard_1 = class DualAuthGuard extends (0, passport_1
|
|
|
39
39
|
*/
|
|
40
40
|
handleRequest(err, user, info, context) {
|
|
41
41
|
var _a, _b;
|
|
42
|
+
// A server-side failure (e.g. 503 while the session store is unreachable) is not a failed sign-in.
|
|
43
|
+
if (err instanceof common_1.HttpException && err.getStatus() >= 500) {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
42
46
|
if (err || !user) {
|
|
43
47
|
const request = context.switchToHttp().getRequest();
|
|
44
48
|
const hasAuthHeader = (_a = request.headers.authorization) === null || _a === void 0 ? void 0 : _a.startsWith('Bearer ');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dual-auth.guard.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/dual-auth.guard.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"dual-auth.guard.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/dual-auth.guard.ts"],"names":[],"mappings":";;;;;AAAA,2CAA4G;AAC5G,+CAA6C;AAGtC,IAAM,aAAa,qBAAnB,MAAM,aAAc,SAAQ,IAAA,oBAAS,EAAC,SAAS,CAAC;IAAhD;;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAC;IAmD3D,CAAC;IAjDC;;;;OAIG;IACG,WAAW,CAAC,OAAyB;;;;;YACzC,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,OAAM,WAAW,YAAC,OAAO,CAAC,CAAC;gBAChD,OAAO,MAAiB,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAE7D,6EAA6E;gBAC7E,IAAI,KAAK,YAAY,8BAAqB,EAAE,CAAC;oBAC3C,MAAM,IAAI,8BAAqB,CAAC,yBAAyB,CAAC,CAAC;gBAC7D,CAAC;gBAED,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;IAED;;OAEG;IACH,aAAa,CAAkB,GAAY,EAAE,IAAa,EAAE,IAAa,EAAE,OAAyB;;QAClG,mGAAmG;QACnG,IAAI,GAAG,YAAY,sBAAa,IAAI,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,EAAE,CAAC;YAC3D,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YACpD,MAAM,aAAa,GAAG,MAAA,OAAO,CAAC,OAAO,CAAC,aAAa,0CAAE,UAAU,CAAC,SAAS,CAAC,CAAC;YAC3E,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,OAAO,0CAAG,cAAc,CAAC,CAAC;YAEpD,IAAI,YAAY,GAAG,yBAAyB,CAAC;YAE7C,IAAI,aAAa,EAAE,CAAC;gBAClB,YAAY,GAAG,wCAAwC,CAAC;YAC1D,CAAC;iBAAM,IAAI,SAAS,EAAE,CAAC;gBACrB,YAAY,GAAG,mCAAmC,CAAC;YACrD,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,YAAY,EAAE,CAAC,CAAC;YAC5D,MAAM,IAAI,8BAAqB,CAAC,YAAY,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,IAAa,CAAC;IACvB,CAAC;CACF,CAAA;AApDY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAoDzB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AuthenticationMethod } from './auth.types';
|
|
1
2
|
/**
|
|
2
3
|
* Declarative audit policy a plugin contributes through `PluginBackendModule.auditDomains`.
|
|
3
4
|
* The host registers the declaration, then enforces it on every event the plugin records:
|
|
@@ -55,15 +56,28 @@ export interface PluginAuditDomainDeclaration {
|
|
|
55
56
|
}
|
|
56
57
|
/** Implemented by the generic audit foundation, not by individual plugins. */
|
|
57
58
|
export declare const PLUGIN_AUDIT_HOST_PROVIDER: unique symbol;
|
|
59
|
+
/** The user (session or API token) an event is attributed to. */
|
|
58
60
|
export interface PluginAuditPrincipal {
|
|
59
61
|
userId: number;
|
|
60
|
-
authenticationMethod:
|
|
62
|
+
authenticationMethod: AuthenticationMethod;
|
|
61
63
|
apiTokenId?: number;
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* An event no user started, such as a scheduled job or a reconciliation the plugin ran on its own. The audit log
|
|
67
|
+
* shows "System" as the actor. Never attribute such an event to a user instead, and do not audit state changes the
|
|
68
|
+
* plugin merely observed. Requires host 1.11.0-beta.1 or newer; older hosts drop these events.
|
|
69
|
+
*/
|
|
70
|
+
export interface PluginAuditSystemPrincipal {
|
|
71
|
+
kind: 'system';
|
|
72
|
+
}
|
|
73
|
+
export declare const PLUGIN_AUDIT_SYSTEM_PRINCIPAL: PluginAuditSystemPrincipal;
|
|
74
|
+
/** Who an audit event is attributed to: a user, or the system. */
|
|
75
|
+
export type PluginAuditActor = PluginAuditPrincipal | PluginAuditSystemPrincipal;
|
|
76
|
+
export declare function isPluginAuditSystemPrincipal(actor: PluginAuditActor | null | undefined): actor is PluginAuditSystemPrincipal;
|
|
63
77
|
export interface PluginAuditEvent {
|
|
64
78
|
action: string;
|
|
65
79
|
operationId: string;
|
|
66
|
-
principal:
|
|
80
|
+
principal: PluginAuditActor;
|
|
67
81
|
outcome: 'attempted' | 'succeeded' | 'failed';
|
|
68
82
|
subject: {
|
|
69
83
|
type: string;
|
package/src/lib/plugin-audit.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLUGIN_AUDIT_SYSTEM_PRINCIPAL = exports.PLUGIN_AUDIT_HOST_PROVIDER = exports.PLUGIN_AUDIT_LIMITS = exports.PLUGIN_AUDIT_FIELD_PATTERN = exports.PLUGIN_AUDIT_SEGMENT_PATTERN = exports.PLUGIN_AUDIT_DOMAIN_PATTERN = void 0;
|
|
4
|
+
exports.isPluginAuditSystemPrincipal = isPluginAuditSystemPrincipal;
|
|
5
|
+
exports.validatePluginAuditDomainDeclaration = validatePluginAuditDomainDeclaration;
|
|
2
6
|
/**
|
|
3
7
|
* Declarative audit policy a plugin contributes through `PluginBackendModule.auditDomains`.
|
|
4
8
|
* The host registers the declaration, then enforces it on every event the plugin records:
|
|
@@ -7,9 +11,6 @@
|
|
|
7
11
|
* bounds (identifier shapes, detail size) and rejects events whose pluginId does not own
|
|
8
12
|
* the domain.
|
|
9
13
|
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.PLUGIN_AUDIT_HOST_PROVIDER = exports.PLUGIN_AUDIT_LIMITS = exports.PLUGIN_AUDIT_FIELD_PATTERN = exports.PLUGIN_AUDIT_SEGMENT_PATTERN = exports.PLUGIN_AUDIT_DOMAIN_PATTERN = void 0;
|
|
12
|
-
exports.validatePluginAuditDomainDeclaration = validatePluginAuditDomainDeclaration;
|
|
13
14
|
/** Domain identifiers are lowercase snake_case and prefix every action and subject type. */
|
|
14
15
|
exports.PLUGIN_AUDIT_DOMAIN_PATTERN = /^[a-z][a-z_]{0,31}$/;
|
|
15
16
|
/** One dot-separated segment of an action or subject type name. */
|
|
@@ -87,6 +88,10 @@ function validateFieldPolicy(path, policy) {
|
|
|
87
88
|
}
|
|
88
89
|
/** Implemented by the generic audit foundation, not by individual plugins. */
|
|
89
90
|
exports.PLUGIN_AUDIT_HOST_PROVIDER = Symbol.for('attraccess.plugin.auditHostProvider');
|
|
91
|
+
exports.PLUGIN_AUDIT_SYSTEM_PRINCIPAL = Object.freeze({ kind: 'system' });
|
|
92
|
+
function isPluginAuditSystemPrincipal(actor) {
|
|
93
|
+
return !!actor && actor.kind === 'system';
|
|
94
|
+
}
|
|
90
95
|
const dottedName = (prefix, value, maxLength) => {
|
|
91
96
|
if (typeof value !== 'string' || value.length > maxLength || !value.startsWith(`${prefix}.`))
|
|
92
97
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-audit.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin-audit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin-audit.js","s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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"}
|
|
@@ -5,7 +5,8 @@ import type { MqttCredentialProvisioningProviderFactory } from './mqtt-credentia
|
|
|
5
5
|
import type { PluginAuditDomainDeclaration } from './plugin-audit';
|
|
6
6
|
import type { PluginFlowNodeDefinition } from './plugin-flow-node';
|
|
7
7
|
import type { PluginEmailTemplate, PluginNotificationCategory } from './plugin-notifications';
|
|
8
|
-
import type {
|
|
8
|
+
import type { PluginPermissionsDeclaration } from './plugin-permissions';
|
|
9
|
+
import type { PreStartHook, ReaderUiProvider, SessionEndHook, StartBlockedQuery, StartCapacityHook } from './reader-ui';
|
|
9
10
|
/**
|
|
10
11
|
* Shape every backend plugin's default export must satisfy. The host calls
|
|
11
12
|
* register(context) at load time to obtain the plugin's Nest module definition.
|
|
@@ -49,6 +50,11 @@ export interface PluginBackendModule {
|
|
|
49
50
|
* shows in place of the start button. Informational; the pre-start hook stays the gate. Requires ACCESS_HOOKS.
|
|
50
51
|
*/
|
|
51
52
|
startBlockedQuery?: StartBlockedQuery;
|
|
53
|
+
/**
|
|
54
|
+
* Optional atomic capacity hook: tells the host how many slots of a shared machine the plugin holds back from the
|
|
55
|
+
* starter. The host evaluates it inside its serialized start transaction. Requires ACCESS_HOOKS and DATABASE_ACCESS.
|
|
56
|
+
*/
|
|
57
|
+
startCapacityHook?: StartCapacityHook;
|
|
52
58
|
/** Optional advisory hook after a session ended. Requires ACCESS_HOOKS. */
|
|
53
59
|
sessionEndHook?: SessionEndHook;
|
|
54
60
|
/**
|
|
@@ -63,4 +69,12 @@ export interface PluginBackendModule {
|
|
|
63
69
|
* SEND_NOTIFICATIONS permission; without it the plugin is quarantined.
|
|
64
70
|
*/
|
|
65
71
|
emailTemplates?: PluginEmailTemplate[];
|
|
72
|
+
/**
|
|
73
|
+
* Optional RBAC permission keys this plugin guards its routes and live topics with. The host validates them at
|
|
74
|
+
* load time (format, reserved core namespaces, collisions) and registers them in the permission catalog, so they
|
|
75
|
+
* appear in the role editor and the API-token picker. Declare them with {@link definePluginPermissions} to get
|
|
76
|
+
* typed keys for `@Auth`. A plugin that is uninstalled or fails to load keeps its keys and their grants, hidden
|
|
77
|
+
* and granting nothing until it loads again. Requires host 1.11.0-beta.1 or newer; older hosts ignore the field.
|
|
78
|
+
*/
|
|
79
|
+
permissions?: PluginPermissionsDeclaration;
|
|
66
80
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Deterministic clock for the fake BLE transport: time only moves when a test calls `advance`. */
|
|
2
|
+
export declare class FakeBleClock {
|
|
3
|
+
private readonly epoch;
|
|
4
|
+
private current;
|
|
5
|
+
private sequence;
|
|
6
|
+
/** `epoch` is the wall-clock time (ms since 1970) at which the clock starts. */
|
|
7
|
+
constructor(epoch?: number);
|
|
8
|
+
private timers;
|
|
9
|
+
now(): number;
|
|
10
|
+
/** Schedules `fn`; returns a function that cancels it. */
|
|
11
|
+
setTimeout(fn: () => void, ms: number): () => void;
|
|
12
|
+
/** Moves time forward, firing due timers in order and letting their promise chains settle in between. */
|
|
13
|
+
advance(ms: number): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare function flushMicrotasks(rounds?: number): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FakeBleClock = void 0;
|
|
4
|
+
exports.flushMicrotasks = flushMicrotasks;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
/** Deterministic clock for the fake BLE transport: time only moves when a test calls `advance`. */
|
|
7
|
+
class FakeBleClock {
|
|
8
|
+
/** `epoch` is the wall-clock time (ms since 1970) at which the clock starts. */
|
|
9
|
+
constructor(epoch = 0) {
|
|
10
|
+
this.epoch = epoch;
|
|
11
|
+
this.current = 0;
|
|
12
|
+
this.sequence = 0;
|
|
13
|
+
this.timers = [];
|
|
14
|
+
}
|
|
15
|
+
now() {
|
|
16
|
+
return this.epoch + this.current;
|
|
17
|
+
}
|
|
18
|
+
/** Schedules `fn`; returns a function that cancels it. */
|
|
19
|
+
setTimeout(fn, ms) {
|
|
20
|
+
const timer = { due: this.current + ms, seq: this.sequence++, fn };
|
|
21
|
+
this.timers.push(timer);
|
|
22
|
+
return () => {
|
|
23
|
+
this.timers = this.timers.filter((candidate) => candidate !== timer);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Moves time forward, firing due timers in order and letting their promise chains settle in between. */
|
|
27
|
+
advance(ms) {
|
|
28
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const target = this.current + ms;
|
|
30
|
+
yield flushMicrotasks();
|
|
31
|
+
for (;;) {
|
|
32
|
+
const next = this.timers.filter((timer) => timer.due <= target).sort((a, b) => a.due - b.due || a.seq - b.seq)[0];
|
|
33
|
+
if (!next)
|
|
34
|
+
break;
|
|
35
|
+
this.timers = this.timers.filter((timer) => timer !== next);
|
|
36
|
+
this.current = Math.max(this.current, next.due);
|
|
37
|
+
next.fn();
|
|
38
|
+
yield flushMicrotasks();
|
|
39
|
+
}
|
|
40
|
+
this.current = target;
|
|
41
|
+
yield flushMicrotasks();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.FakeBleClock = FakeBleClock;
|
|
46
|
+
function flushMicrotasks() {
|
|
47
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (rounds = 100) {
|
|
48
|
+
for (let index = 0; index < rounds; index++)
|
|
49
|
+
yield Promise.resolve();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=plugin-ble-fake-clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-ble-fake-clock.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/plugin-ble-fake-clock.ts"],"names":[],"mappings":";;;AAuCA,0CAEC;;AAzCD,mGAAmG;AACnG,MAAa,YAAY;IAIvB,gFAAgF;IAChF,YAA6B,QAAQ,CAAC;QAAT,UAAK,GAAL,KAAK,CAAI;QAJ9B,YAAO,GAAG,CAAC,CAAC;QACZ,aAAQ,GAAG,CAAC,CAAC;QAIb,WAAM,GAAwD,EAAE,CAAC;IADhC,CAAC;IAG1C,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC;IACnC,CAAC;IAED,0DAA0D;IAC1D,UAAU,CAAC,EAAc,EAAE,EAAU;QACnC,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,GAAG,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC;QACnE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC;QACvE,CAAC,CAAC;IACJ,CAAC;IAED,yGAAyG;IACnG,OAAO,CAAC,EAAU;;YACtB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;YACjC,MAAM,eAAe,EAAE,CAAC;YACxB,SAAS,CAAC;gBACR,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClH,IAAI,CAAC,IAAI;oBAAE,MAAM;gBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;gBAC5D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;gBAChD,IAAI,CAAC,EAAE,EAAE,CAAC;gBACV,MAAM,eAAe,EAAE,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YACtB,MAAM,eAAe,EAAE,CAAC;QAC1B,CAAC;KAAA;CACF;AApCD,oCAoCC;AAED,SAAsB,eAAe;iEAAC,MAAM,GAAG,GAAG;QAChD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE;YAAE,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IACvE,CAAC;CAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { PluginBleAddressType, PluginBleContext, PluginBleErrorCode } from './plugin-ble';
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic fake of the host BLE transport for plugin unit and integration tests. It has no Nest, database
|
|
4
|
+
* or network dependency, enforces the same validation and error codes as the host, and moves time only when a
|
|
5
|
+
* test calls `advance`.
|
|
6
|
+
*/
|
|
7
|
+
export type FakeBleOperation = 'scan' | 'connect' | 'disconnect' | 'read' | 'write' | 'subscribe' | 'unsubscribe';
|
|
8
|
+
export interface FakeBleCharacteristic {
|
|
9
|
+
/** Current value returned by reads (and updated by writes without an `onWrite`). */
|
|
10
|
+
value?: Uint8Array;
|
|
11
|
+
onRead?: () => Uint8Array | Promise<Uint8Array>;
|
|
12
|
+
onWrite?: (value: Uint8Array, options: {
|
|
13
|
+
withoutResponse: boolean;
|
|
14
|
+
}) => void | Promise<void>;
|
|
15
|
+
/** Answers only after this many ms of fake time. Use it to provoke timeouts. */
|
|
16
|
+
delayMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface FakeBlePeripheral {
|
|
19
|
+
readerId?: number;
|
|
20
|
+
readerIds?: number[];
|
|
21
|
+
address: string;
|
|
22
|
+
addressType: PluginBleAddressType;
|
|
23
|
+
advertisement: {
|
|
24
|
+
name?: string;
|
|
25
|
+
rssi?: number;
|
|
26
|
+
serviceUuids?: string[];
|
|
27
|
+
manufacturerData?: Array<{
|
|
28
|
+
companyId: number;
|
|
29
|
+
data: Uint8Array;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
/** Keyed by characteristic UUID (any accepted form). */
|
|
33
|
+
characteristics?: Record<string, FakeBleCharacteristic>;
|
|
34
|
+
}
|
|
35
|
+
export interface FakeBleReaderInput {
|
|
36
|
+
readerId: number;
|
|
37
|
+
name: string;
|
|
38
|
+
/** Default false, like production. */
|
|
39
|
+
allowPluginBle?: boolean;
|
|
40
|
+
/** Default true. */
|
|
41
|
+
available?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** One validated primitive that reached the (fake) transport. */
|
|
44
|
+
export interface FakeBleTranscriptEntry {
|
|
45
|
+
op: FakeBleOperation;
|
|
46
|
+
readerId: number;
|
|
47
|
+
address?: string;
|
|
48
|
+
addressType?: PluginBleAddressType;
|
|
49
|
+
serviceUuid?: string;
|
|
50
|
+
characteristicUuid?: string;
|
|
51
|
+
bytes?: Uint8Array;
|
|
52
|
+
withoutResponse?: boolean;
|
|
53
|
+
durationMs?: number;
|
|
54
|
+
indicate?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface FakeBleOpenSession {
|
|
57
|
+
id: string;
|
|
58
|
+
pluginId: string;
|
|
59
|
+
endpointId: string;
|
|
60
|
+
readerId: number;
|
|
61
|
+
address: string;
|
|
62
|
+
}
|
|
63
|
+
export interface FakeBleHostOptions {
|
|
64
|
+
/** Default true. Use false to simulate calls before the host finished bootstrapping (`NOT_READY`). */
|
|
65
|
+
ready?: boolean;
|
|
66
|
+
/** Wall-clock start of the fake clock (ms since 1970). Default 2026-01-01T00:00:00Z. */
|
|
67
|
+
startTime?: number;
|
|
68
|
+
/** ATT MTU every new connection negotiates, clamped to 23..517. Default 247. */
|
|
69
|
+
mtu?: number;
|
|
70
|
+
}
|
|
71
|
+
/** The MTU the fake negotiates unless a test sets another one. */
|
|
72
|
+
export declare const FAKE_BLE_DEFAULT_MTU = 247;
|
|
73
|
+
export interface FakeBleHost {
|
|
74
|
+
contextFor(pluginId: string): PluginBleContext;
|
|
75
|
+
addReader(reader: FakeBleReaderInput): void;
|
|
76
|
+
removeReader(readerId: number): Promise<void>;
|
|
77
|
+
setReaderAccess(readerId: number, allowed: boolean): Promise<void>;
|
|
78
|
+
setReaderAvailable(readerId: number, available: boolean): void;
|
|
79
|
+
/** `false` simulates reader firmware without plugin BLE support (`READER_UNSUPPORTED` with `detail`). */
|
|
80
|
+
setReaderSupported(readerId: number, supported: boolean, detail?: string): void;
|
|
81
|
+
/** `false` simulates a host without a transport driver (`TRANSPORT_UNAVAILABLE`). */
|
|
82
|
+
setTransportAvailable(available: boolean): void;
|
|
83
|
+
setReady(ready: boolean): void;
|
|
84
|
+
addPeripheral(peripheral: FakeBlePeripheral): void;
|
|
85
|
+
notify(address: string, uuid: string, bytes: Uint8Array): void;
|
|
86
|
+
/** The peripheral drops the link: sessions to it close with `disconnected`. */
|
|
87
|
+
disconnect(address: string): Promise<void>;
|
|
88
|
+
/** ATT MTU for connections opened from now on, clamped to 23..517. */
|
|
89
|
+
setMtu(mtu: number): void;
|
|
90
|
+
/** Makes the next occurrence of `op` fail with `code`. */
|
|
91
|
+
failNext(op: FakeBleOperation, code: PluginBleErrorCode, options?: {
|
|
92
|
+
detail?: string;
|
|
93
|
+
}): void;
|
|
94
|
+
advance(ms: number): Promise<void>;
|
|
95
|
+
/** Simulates the plugin module being destroyed: closes its sessions with `shutdown`. */
|
|
96
|
+
shutdownPlugin(pluginId: string): Promise<void>;
|
|
97
|
+
/** Simulates plugin uninstall: closes its sessions and deletes its endpoints. */
|
|
98
|
+
uninstallPlugin(pluginId: string): Promise<void>;
|
|
99
|
+
readonly transcript: FakeBleTranscriptEntry[];
|
|
100
|
+
openSessions(): FakeBleOpenSession[];
|
|
101
|
+
}
|
|
102
|
+
export declare function createFakeBleHost(options?: FakeBleHostOptions): FakeBleHost;
|