@attraccess/plugins-backend-sdk 1.9.0 → 1.11.0-beta.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.
Files changed (41) hide show
  1. package/package.json +8 -3
  2. package/src/index.d.ts +8 -0
  3. package/src/index.js +8 -0
  4. package/src/index.js.map +1 -1
  5. package/src/lib/auth-decorator.d.ts +4 -0
  6. package/src/lib/auth-decorator.js +20 -5
  7. package/src/lib/auth-decorator.js.map +1 -1
  8. package/src/lib/auth.types.d.ts +2 -0
  9. package/src/lib/mqtt-credential-provisioning.d.ts +52 -0
  10. package/src/lib/mqtt-credential-provisioning.js +5 -0
  11. package/src/lib/mqtt-credential-provisioning.js.map +1 -0
  12. package/src/lib/plugin-audit.d.ts +94 -0
  13. package/src/lib/plugin-audit.js +170 -0
  14. package/src/lib/plugin-audit.js.map +1 -0
  15. package/src/lib/plugin-backend-module.d.ts +66 -0
  16. package/src/lib/plugin-backend-module.js +3 -0
  17. package/src/lib/plugin-backend-module.js.map +1 -0
  18. package/src/lib/plugin-context.d.ts +109 -33
  19. package/src/lib/plugin-context.js +6 -6
  20. package/src/lib/plugin-context.js.map +1 -1
  21. package/src/lib/plugin-flow-node.d.ts +172 -0
  22. package/src/lib/plugin-flow-node.js +12 -0
  23. package/src/lib/plugin-flow-node.js.map +1 -0
  24. package/src/lib/plugin-live-updates.d.ts +21 -0
  25. package/src/lib/plugin-live-updates.js +3 -0
  26. package/src/lib/plugin-live-updates.js.map +1 -0
  27. package/src/lib/plugin-notifications.d.ts +83 -0
  28. package/src/lib/plugin-notifications.js +3 -0
  29. package/src/lib/plugin-notifications.js.map +1 -0
  30. package/src/lib/plugin-resource-access.d.ts +89 -0
  31. package/src/lib/plugin-resource-access.js +3 -0
  32. package/src/lib/plugin-resource-access.js.map +1 -0
  33. package/src/lib/plugin.interface.d.ts +78 -5
  34. package/src/lib/plugin.interface.js +26 -1
  35. package/src/lib/plugin.interface.js.map +1 -1
  36. package/src/lib/reader-ui.d.ts +317 -0
  37. package/src/lib/reader-ui.js +115 -0
  38. package/src/lib/reader-ui.js.map +1 -0
  39. package/src/lib/shared-live-sampler.d.ts +11 -0
  40. package/src/lib/shared-live-sampler.js +33 -0
  41. package/src/lib/shared-live-sampler.js.map +1 -0
@@ -1,7 +1,66 @@
1
- import { Resource, User } from '@attraccess/database-entities';
1
+ import { Resource, ResourceHealthStatus, User } from '@attraccess/database-entities';
2
2
  export declare enum SystemEvent {
3
3
  RESOURCE_USAGE_STARTED = "RESOURCE_USAGE_STARTED",
4
- RESOURCE_USAGE_ENDED = "RESOURCE_USAGE_ENDED"
4
+ RESOURCE_USAGE_ENDED = "RESOURCE_USAGE_ENDED",
5
+ /** A maintenance window was created, updated or finished. See {@link MaintenanceChangedPayload}. */
6
+ MAINTENANCE_CHANGED = "MAINTENANCE_CHANGED",
7
+ /** A resource health entry changed status. See {@link ResourceHealthChangedPayload}. */
8
+ RESOURCE_HEALTH_CHANGED = "RESOURCE_HEALTH_CHANGED",
9
+ /** A user started a session on an idle resource (not a takeover). */
10
+ RESOURCE_USAGE_SESSION_STARTED = "RESOURCE_USAGE_SESSION_STARTED",
11
+ /** A user took over a running session. Fires for the NEW user. */
12
+ RESOURCE_USAGE_SESSION_TAKEN_OVER = "RESOURCE_USAGE_SESSION_TAKEN_OVER",
13
+ /** A session ended, either explicitly or because it was taken over. */
14
+ RESOURCE_USAGE_SESSION_ENDED = "RESOURCE_USAGE_SESSION_ENDED"
15
+ }
16
+ /** Emitted after a maintenance window was created, updated or finished (committed to the database). */
17
+ export interface MaintenanceChangedPayload {
18
+ resourceId: number;
19
+ maintenanceId: number;
20
+ /**
21
+ * Core currently emits only `created` and `finished`; maintenance windows have no edit path yet.
22
+ * `updated` is reserved for forward compatibility, so handle it like `created` (re-read the window).
23
+ */
24
+ action: 'created' | 'updated' | 'finished';
25
+ startTime: Date;
26
+ /** Null while the maintenance is open-ended (no end set, not finished). */
27
+ endTime: Date | null;
28
+ }
29
+ /** Emitted after a resource health entry changed status. Only real status transitions fire. */
30
+ export interface ResourceHealthChangedPayload {
31
+ resourceId: number;
32
+ status: ResourceHealthStatus;
33
+ previousStatus: ResourceHealthStatus | null;
34
+ reason: string | null;
35
+ /** Identifier of the health entry (resources can carry several independent entries). */
36
+ identifier: string;
37
+ }
38
+ export interface ResourceUsageSessionStartedPayload {
39
+ resourceId: number;
40
+ usageId: number;
41
+ userId: number;
42
+ startTime: Date;
43
+ /** Set when the session was started under supervision. */
44
+ supervisorUserId: number | null;
45
+ }
46
+ export interface ResourceUsageSessionTakenOverPayload {
47
+ resourceId: number;
48
+ /** The new session. */
49
+ usageId: number;
50
+ /** The user who took over (the new session owner). */
51
+ userId: number;
52
+ startTime: Date;
53
+ previousUsageId: number;
54
+ previousUserId: number;
55
+ }
56
+ export interface ResourceUsageSessionEndedPayload {
57
+ resourceId: number;
58
+ usageId: number;
59
+ userId: number;
60
+ startTime: Date;
61
+ endTime: Date | null;
62
+ /** 'taken_over' when the session ended because another user took it over. */
63
+ reason: 'ended' | 'taken_over';
5
64
  }
6
65
  export type SystemEventPayload = {
7
66
  [SystemEvent.RESOURCE_USAGE_STARTED]: {
@@ -12,10 +71,14 @@ export type SystemEventPayload = {
12
71
  resource: Resource;
13
72
  user: User;
14
73
  };
74
+ [SystemEvent.MAINTENANCE_CHANGED]: MaintenanceChangedPayload;
75
+ [SystemEvent.RESOURCE_HEALTH_CHANGED]: ResourceHealthChangedPayload;
76
+ [SystemEvent.RESOURCE_USAGE_SESSION_STARTED]: ResourceUsageSessionStartedPayload;
77
+ [SystemEvent.RESOURCE_USAGE_SESSION_TAKEN_OVER]: ResourceUsageSessionTakenOverPayload;
78
+ [SystemEvent.RESOURCE_USAGE_SESSION_ENDED]: ResourceUsageSessionEndedPayload;
15
79
  };
16
80
  export type SystemEventResponse = {
17
- [SystemEvent.RESOURCE_USAGE_STARTED]: null;
18
- [SystemEvent.RESOURCE_USAGE_ENDED]: null;
81
+ [E in SystemEvent]: null;
19
82
  };
20
83
  /**
21
84
  * Typed handler a plugin registers for a given SystemEvent. It receives the
@@ -51,7 +114,17 @@ export declare enum PluginPermission {
51
114
  /** Resolve arbitrary host providers by token via context.get(). */
52
115
  RESOLVE_HOST_PROVIDERS = "RESOLVE_HOST_PROVIDERS",
53
116
  /** Read an MQTT server's connection config + resolved credentials via getMqttServerConfig(). */
54
- ACCESS_MQTT_SERVERS = "ACCESS_MQTT_SERVERS"
117
+ ACCESS_MQTT_SERVERS = "ACCESS_MQTT_SERVERS",
118
+ /** Start flows from plugin-declared trigger nodes via flows.trigger(). */
119
+ TRIGGER_FLOWS = "TRIGGER_FLOWS",
120
+ /** Encrypt and decrypt plugin-owned secret material through the host key service. */
121
+ MANAGE_SECRETS = "MANAGE_SECRETS",
122
+ /** Contribute reader UI slots and call readerUi.invalidate(). */
123
+ READER_UI = "READER_UI",
124
+ /** Register pre-start and session-end hooks that can confirm or block session starts. */
125
+ ACCESS_HOOKS = "ACCESS_HOOKS",
126
+ /** Send in-app, push and email notifications to users via notifications.dispatch(). */
127
+ SEND_NOTIFICATIONS = "SEND_NOTIFICATIONS"
55
128
  }
56
129
  /**
57
130
  * Human-readable description of each permission, surfaced to admins and plugin
@@ -6,6 +6,16 @@ var SystemEvent;
6
6
  (function (SystemEvent) {
7
7
  SystemEvent["RESOURCE_USAGE_STARTED"] = "RESOURCE_USAGE_STARTED";
8
8
  SystemEvent["RESOURCE_USAGE_ENDED"] = "RESOURCE_USAGE_ENDED";
9
+ /** A maintenance window was created, updated or finished. See {@link MaintenanceChangedPayload}. */
10
+ SystemEvent["MAINTENANCE_CHANGED"] = "MAINTENANCE_CHANGED";
11
+ /** A resource health entry changed status. See {@link ResourceHealthChangedPayload}. */
12
+ SystemEvent["RESOURCE_HEALTH_CHANGED"] = "RESOURCE_HEALTH_CHANGED";
13
+ /** A user started a session on an idle resource (not a takeover). */
14
+ SystemEvent["RESOURCE_USAGE_SESSION_STARTED"] = "RESOURCE_USAGE_SESSION_STARTED";
15
+ /** A user took over a running session. Fires for the NEW user. */
16
+ SystemEvent["RESOURCE_USAGE_SESSION_TAKEN_OVER"] = "RESOURCE_USAGE_SESSION_TAKEN_OVER";
17
+ /** A session ended, either explicitly or because it was taken over. */
18
+ SystemEvent["RESOURCE_USAGE_SESSION_ENDED"] = "RESOURCE_USAGE_SESSION_ENDED";
9
19
  })(SystemEvent || (exports.SystemEvent = SystemEvent = {}));
10
20
  /**
11
21
  * Discrete host capabilities a plugin may request in its manifest. A plugin can
@@ -30,6 +40,16 @@ var PluginPermission;
30
40
  PluginPermission["RESOLVE_HOST_PROVIDERS"] = "RESOLVE_HOST_PROVIDERS";
31
41
  /** Read an MQTT server's connection config + resolved credentials via getMqttServerConfig(). */
32
42
  PluginPermission["ACCESS_MQTT_SERVERS"] = "ACCESS_MQTT_SERVERS";
43
+ /** Start flows from plugin-declared trigger nodes via flows.trigger(). */
44
+ PluginPermission["TRIGGER_FLOWS"] = "TRIGGER_FLOWS";
45
+ /** Encrypt and decrypt plugin-owned secret material through the host key service. */
46
+ PluginPermission["MANAGE_SECRETS"] = "MANAGE_SECRETS";
47
+ /** Contribute reader UI slots and call readerUi.invalidate(). */
48
+ PluginPermission["READER_UI"] = "READER_UI";
49
+ /** Register pre-start and session-end hooks that can confirm or block session starts. */
50
+ PluginPermission["ACCESS_HOOKS"] = "ACCESS_HOOKS";
51
+ /** Send in-app, push and email notifications to users via notifications.dispatch(). */
52
+ PluginPermission["SEND_NOTIFICATIONS"] = "SEND_NOTIFICATIONS";
33
53
  })(PluginPermission || (exports.PluginPermission = PluginPermission = {}));
34
54
  /**
35
55
  * Human-readable description of each permission, surfaced to admins and plugin
@@ -37,13 +57,18 @@ var PluginPermission;
37
57
  */
38
58
  exports.PLUGIN_PERMISSION_DESCRIPTIONS = {
39
59
  [PluginPermission.READ_USERS]: 'Read user accounts from the database.',
40
- [PluginPermission.ACCESS_RESOURCES]: 'Read and write resources from the database.',
60
+ [PluginPermission.ACCESS_RESOURCES]: 'Read and write resources from the database and query resource access, maintenance windows and active sessions.',
41
61
  [PluginPermission.READ_SETTINGS]: 'Read application settings from the database.',
42
62
  [PluginPermission.DATABASE_ACCESS]: 'Access the raw database connection and any other entity repository.',
43
63
  [PluginPermission.EMIT_EVENTS]: 'Publish events on the shared application event bus.',
44
64
  [PluginPermission.LISTEN_EVENTS]: 'Subscribe to events on the shared application event bus.',
45
65
  [PluginPermission.RESOLVE_HOST_PROVIDERS]: 'Resolve arbitrary host services by injection token.',
46
66
  [PluginPermission.ACCESS_MQTT_SERVERS]: "Read an MQTT server's connection configuration and resolved credentials.",
67
+ [PluginPermission.TRIGGER_FLOWS]: 'Start flows from plugin-declared trigger nodes.',
68
+ [PluginPermission.MANAGE_SECRETS]: 'Encrypt and decrypt plugin-owned secret material through the host key service.',
69
+ [PluginPermission.READER_UI]: 'Show widgets on Attractap reader screens.',
70
+ [PluginPermission.ACCESS_HOOKS]: 'Ask users for confirmation or block resource session starts through pre-start hooks.',
71
+ [PluginPermission.SEND_NOTIFICATIONS]: 'Send notifications to users (in-app, push and email) under plugin-declared notification categories.',
47
72
  };
48
73
  /**
49
74
  * 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":";;;AA4EA,gDAEC;AA5ED,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gEAAiD,CAAA;IACjD,4DAA6C,CAAA;AAC/C,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AA6BD;;;;GAIG;AACH,IAAY,gBAiBX;AAjBD,WAAY,gBAAgB;IAC1B,wDAAwD;IACxD,6CAAyB,CAAA;IACzB,sEAAsE;IACtE,yDAAqC,CAAA;IACrC,8DAA8D;IAC9D,mDAA+B,CAAA;IAC/B,0DAA0D;IAC1D,uDAAmC,CAAA;IACnC,wEAAwE;IACxE,+CAA2B,CAAA;IAC3B,4EAA4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W,CAAC,EAAE,qDAAqD;IACrF,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,0DAA0D;IAC5F,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,qDAAqD;IAChG,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,EAAE,0EAA0E;IAClH,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,iDAAiD;IACnF,CAAC,gBAAgB,CAAC,cAAc,CAAC,EAAE,gFAAgF;IACnH,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,2CAA2C;IACzE,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAC7B,sFAAsF;IACxF,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,EACnC,qGAAqG;CACxG,CAAC;AAEF;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAAa;IAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,sCAA8B,EAAE,KAAK,CAAC,CAAC;AACrF,CAAC;AAED;;;;GAIG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAK9C,YAAY,UAAkB,EAAE,UAAkB,EAAE,kBAAoC;QACtF,KAAK,CACH,WAAW,UAAU,uBAAuB,UAAU,wBAAwB;YAC5E,IAAI,kBAAkB,6EAA6E,CACtG,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;CACF;AAfD,sDAeC"}
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Reader UI schema v1 and the pre-start / session-end hook contract.
3
+ *
4
+ * Plugins describe UI as plain data. Nothing here runs on the reader. The host
5
+ * validates, sanitizes (Latin-1) and size-checks everything before it is sent.
6
+ * The firmware mirrors the constants in `display/ui/ui_schema.hpp`; a Jest
7
+ * parity test keeps both in sync.
8
+ */
9
+ import type { PluginAccessPrincipal } from './plugin-resource-access';
10
+ export type ReaderUiTone = 'primary' | 'success' | 'warning' | 'danger';
11
+ export type ReaderUiIconName = 'ok' | 'warning' | 'bell' | 'lock' | 'clock';
12
+ export type ReaderUiTextStyle = 'title' | 'body' | 'small';
13
+ export type ReaderUiNode = {
14
+ t: 'col' | 'row';
15
+ c?: ReaderUiNode[];
16
+ gap?: number;
17
+ pad?: number;
18
+ fill?: boolean;
19
+ tone?: ReaderUiTone;
20
+ } | {
21
+ t: 'text';
22
+ text: string;
23
+ style?: ReaderUiTextStyle;
24
+ fill?: boolean;
25
+ } | {
26
+ t: 'badge';
27
+ text: string;
28
+ tone?: ReaderUiTone;
29
+ } | {
30
+ t: 'icon';
31
+ name: ReaderUiIconName;
32
+ tone?: ReaderUiTone;
33
+ }
34
+ /** Steps only. Slot trees must not contain buttons. */
35
+ | {
36
+ t: 'button';
37
+ id: string;
38
+ text: string;
39
+ variant?: 'primary' | 'secondary';
40
+ } | {
41
+ t: 'progress';
42
+ value: number;
43
+ tone?: ReaderUiTone;
44
+ }
45
+ /** Plugin-facing form takes a Date; the wire form carries epoch milliseconds in `toMs`. */
46
+ | {
47
+ t: 'countdown';
48
+ to: Date;
49
+ tone?: ReaderUiTone;
50
+ } | {
51
+ t: 'spacer';
52
+ h?: number;
53
+ };
54
+ /** Wire form of a node tree: `countdown.to` is replaced by `toMs`. */
55
+ export type ReaderUiWireNode = Exclude<ReaderUiNode, {
56
+ t: 'countdown' | 'col' | 'row';
57
+ }> | {
58
+ t: 'col' | 'row';
59
+ c?: ReaderUiWireNode[];
60
+ gap?: number;
61
+ pad?: number;
62
+ fill?: boolean;
63
+ tone?: ReaderUiTone;
64
+ } | {
65
+ t: 'countdown';
66
+ toMs: number;
67
+ tone?: ReaderUiTone;
68
+ };
69
+ export declare const READER_UI_SCHEMA_VERSION = 1;
70
+ export declare const READER_UI_COMPONENTS: readonly ["col", "row", "text", "badge", "icon", "button", "progress", "countdown", "spacer"];
71
+ export type ReaderUiComponent = (typeof READER_UI_COMPONENTS)[number];
72
+ export declare const READER_UI_TONES: readonly ReaderUiTone[];
73
+ export declare const READER_UI_ICONS: readonly ReaderUiIconName[];
74
+ export declare const READER_UI_TEXT_STYLES: readonly ReaderUiTextStyle[];
75
+ export declare const READER_UI_SLOTS: {
76
+ readonly RESOURCE_LIST_ROW_STATUS: "resourceList.row.status";
77
+ readonly RESOURCE_DETAILS_HEADER: "resource.details.header";
78
+ readonly RESOURCE_DETAILS_BODY: "resource.details.body";
79
+ readonly RESOURCE_DETAILS_SESSION: "resource.details.session";
80
+ };
81
+ export type ReaderUiSlotId = (typeof READER_UI_SLOTS)[keyof typeof READER_UI_SLOTS];
82
+ export declare const READER_UI_SLOT_IDS: readonly ReaderUiSlotId[];
83
+ /** Node budget per slot. The list row slot takes a single text or badge. */
84
+ export declare const READER_UI_SLOT_NODE_BUDGET: Record<ReaderUiSlotId, number>;
85
+ export declare const READER_UI_STEP_KINDS: readonly ["confirm", "choose", "info"];
86
+ export type ReaderUiStepKind = (typeof READER_UI_STEP_KINDS)[number];
87
+ export type ReaderUiStepRole = 'cancel' | 'confirm' | 'ok' | 'choice';
88
+ export declare const READER_UI_LIMITS: {
89
+ /** UTF-8 bytes of the sanitized UI payload. */
90
+ readonly maxPayloadBytes: 3072;
91
+ /** Whole websocket frame; legacy token readers cannot reassemble. */
92
+ readonly maxFrameBytes: 4096;
93
+ readonly maxNodes: 32;
94
+ readonly maxDepth: 5;
95
+ readonly maxLiveNodes: 64;
96
+ readonly maxTextChars: 80;
97
+ readonly maxLabelBytes: 31;
98
+ readonly maxListRowChars: 24;
99
+ readonly maxChoices: 4;
100
+ readonly maxSlotContributionsPerResource: 8;
101
+ readonly idPattern: RegExp;
102
+ };
103
+ export declare const READER_UI_TIMING: {
104
+ readonly stepDefaultTtlSec: 60;
105
+ readonly stepMaxTtlSec: 120;
106
+ readonly stepGraceSec: 5;
107
+ readonly postStopDefaultTtlSec: 15;
108
+ readonly postStopMaxTtlSec: 30;
109
+ readonly hookDefaultTimeoutMs: 1500;
110
+ readonly hookMaxTimeoutMs: 3000;
111
+ readonly breakerThreshold: 5;
112
+ readonly breakerProbeAfterMs: 60000;
113
+ readonly crashLoopSuspendMs: number;
114
+ readonly slotUpdateMinIntervalMs: 2000;
115
+ };
116
+ /**
117
+ * Strings that only the host may show (core status). Plugin text is rejected when it equals one after lower-casing,
118
+ * collapsing whitespace and stripping non-letters at both ends.
119
+ */
120
+ export declare const READER_UI_RESERVED_STATUS_STRINGS: readonly string[];
121
+ export type NoScreenPolicy = 'block' | 'card-confirm' | 'allow-with-warning';
122
+ export declare const NO_SCREEN_POLICIES: readonly NoScreenPolicy[];
123
+ export declare const DEFAULT_NO_SCREEN_POLICY: NoScreenPolicy;
124
+ export type HookFailurePolicy = 'fail-closed' | 'fail-open';
125
+ /** Reset reasons shared with READER_CRASH_REPORT. */
126
+ export declare const PANIC_CLASS_RESET_REASONS: readonly ["PANIC", "INT_WDT", "TASK_WDT", "WDT", "CPU_LOCKUP"];
127
+ /** What a reader reports in `READER_FIRMWARE_INFO.capabilities.ui`. Missing = schemaVersion 0. */
128
+ export interface ReaderUiCapabilities {
129
+ schemaVersion: number;
130
+ components: string[];
131
+ slots: string[];
132
+ /** Touch: confirm/choose/info. Lite: [] or ['card-confirm']. */
133
+ steps: string[];
134
+ maxPayloadBytes: number;
135
+ maxNodes: number;
136
+ maxDepth: number;
137
+ maxLiveNodes: number;
138
+ display: {
139
+ w: number;
140
+ h: number;
141
+ touch: boolean;
142
+ } | null;
143
+ input: {
144
+ touch: boolean;
145
+ buttons: number;
146
+ cardHold: boolean;
147
+ };
148
+ feedback: {
149
+ leds: boolean;
150
+ beeper: boolean;
151
+ };
152
+ charset: 'latin1';
153
+ images: boolean;
154
+ }
155
+ export declare const READER_UI_CAPABILITIES_NONE: ReaderUiCapabilities;
156
+ export interface ReaderUiContext {
157
+ readerId: number;
158
+ resourceId: number;
159
+ /** Set whenever a card session is live; never for a signed-out reader. */
160
+ userId?: number;
161
+ /**
162
+ * The resource has an active usage visible on this reader. The reader shows `resource.details.session` only
163
+ * while this is true, so a provider that wants a fact in one block puts it in the session slot when this is true
164
+ * and in the details body otherwise. The host re-evaluates the provider when a usage starts, ends or is taken
165
+ * over. Optional for compatibility: when unset, treat it as `false`.
166
+ */
167
+ sessionActive?: boolean;
168
+ capabilities: ReaderUiCapabilities;
169
+ language: 'en' | 'de';
170
+ }
171
+ export interface ReaderSlotContribution {
172
+ slotId: ReaderUiSlotId;
173
+ /** Plugin-local, unique per slot and resource. */
174
+ key: string;
175
+ tree: ReaderUiNode;
176
+ /** The host re-evaluates the provider at this time and removes the contribution. */
177
+ expiresAt?: Date;
178
+ /** Sent instead of `tree` when the reader cannot render it. */
179
+ fallback?: {
180
+ text: string;
181
+ tone?: ReaderUiTone;
182
+ };
183
+ }
184
+ export interface ReaderUiProvider {
185
+ getSlotContributions(ctx: ReaderUiContext): ReaderSlotContribution[] | Promise<ReaderSlotContribution[]>;
186
+ /**
187
+ * The IANA time zone (e.g. `Europe/Berlin`) this plugin writes times in on readers for the resource, or `undefined`
188
+ * for no opinion. The host sends one zone per reader, so the reader's clock and the plugin's texts agree: the first
189
+ * valid zone in host order wins (the reader's resources by id, and for each resource the plugins in host order,
190
+ * alphabetically by plugin name; a slower plugin that answers within the time limit still wins over a faster one
191
+ * ranked lower), otherwise the server's `TZ` applies. An invalid name is ignored; two different zones for one reader
192
+ * raise an admin alert. Called with the slot timeout; an error or timeout counts as no opinion. Call
193
+ * `readerUi.invalidate` when the zone changes.
194
+ */
195
+ getTimeZone?(ctx: {
196
+ readerId: number;
197
+ resourceId: number;
198
+ }): string | undefined | Promise<string | undefined>;
199
+ }
200
+ export type PreStartOrigin = 'web' | 'api' | 'reader' | 'supervision';
201
+ export interface PreStartContext {
202
+ resourceId: number;
203
+ userId: number;
204
+ /**
205
+ * The starter as a `resourceAccess` principal. Web and API starts carry the request's permissions (an API token's
206
+ * scope), reader and supervision starts the plain user id. Pass it to `resourceAccess` instead of `userId`, so
207
+ * permission checks in the hook apply the same scope as core's own start checks.
208
+ */
209
+ principal: PluginAccessPrincipal;
210
+ action: 'start' | 'takeover';
211
+ projectId?: number;
212
+ origin: PreStartOrigin;
213
+ /** Only this plugin's step keys, checked by the host. */
214
+ confirmedStepKeys: string[];
215
+ /** Language for texts: the card user's on a reader, the user's preferred language elsewhere. */
216
+ language: 'en' | 'de';
217
+ now: Date;
218
+ }
219
+ export interface PluginConfirmation {
220
+ /** Stable per plugin; the host issues a random stepId per step. */
221
+ stepKey: string;
222
+ title: string;
223
+ body: string;
224
+ tone?: ReaderUiTone;
225
+ confirmLabel?: string;
226
+ cancelLabel?: string;
227
+ countdownTo?: Date;
228
+ /** Host clamps to [10, 120]. */
229
+ expiresInSec?: number;
230
+ /** Plugin default for readers without a screen. */
231
+ noScreenPolicy?: NoScreenPolicy;
232
+ }
233
+ export interface PluginBlockReason {
234
+ code: string;
235
+ title: string;
236
+ body: string;
237
+ }
238
+ export type PreStartResult = {
239
+ decision: 'allow';
240
+ } | {
241
+ decision: 'confirm';
242
+ confirmation: PluginConfirmation;
243
+ } | {
244
+ decision: 'block';
245
+ reason: PluginBlockReason;
246
+ };
247
+ export type PreStartHook = (ctx: PreStartContext) => PreStartResult | Promise<PreStartResult>;
248
+ export interface StartBlockedContext {
249
+ resourceId: number;
250
+ /** The user looking at the resource. Apply your own visibility rules before naming anybody in the reason. */
251
+ userId: number;
252
+ /** The viewer as a `resourceAccess` principal, with the request's permissions (an API token's scope). */
253
+ principal: PluginAccessPrincipal;
254
+ /** Language for texts: the user's preferred language. */
255
+ language: 'en' | 'de';
256
+ now: Date;
257
+ }
258
+ /** A start that is refused right now. Same reason shape as a `preStartHook` block. */
259
+ export interface StartBlockedState {
260
+ reason: PluginBlockReason;
261
+ /** When the block ends, if known. The host UI refreshes itself then and shows the time. */
262
+ until?: Date;
263
+ }
264
+ /**
265
+ * Query-side counterpart of `preStartHook`: tells the UI that a start by this user is blocked right now, so it
266
+ * can show the reason in place of the start button instead of letting the user press it. Return null when
267
+ * nothing blocks. It is informational only: `preStartHook` stays the authoritative gate and must still block.
268
+ * Keep it cheap and side-effect free; it is called whenever a resource page is open. Failures and timeouts
269
+ * count as "not blocked". Requires ACCESS_HOOKS.
270
+ */
271
+ export type StartBlockedQuery = (ctx: StartBlockedContext) => StartBlockedState | null | Promise<StartBlockedState | null>;
272
+ /** Lets a plugin tell the host UI that the answer of its `startBlockedQuery` may have changed. */
273
+ export interface PluginStartBlockedApi {
274
+ /** Open resource pages ask again. Call it when bookings or rules that decide the block change. */
275
+ invalidate(scope: {
276
+ resourceId: number;
277
+ }): void;
278
+ }
279
+ export interface SessionEndContext {
280
+ resourceId: number;
281
+ userId: number;
282
+ sessionId: number;
283
+ origin: 'web' | 'api' | 'reader';
284
+ /** Language for texts: the card user's on a reader, the user's preferred language elsewhere. */
285
+ language: 'en' | 'de';
286
+ now: Date;
287
+ }
288
+ export interface PluginChoice {
289
+ stepKey: string;
290
+ title: string;
291
+ body: string;
292
+ /** Max 4. */
293
+ choices: {
294
+ id: string;
295
+ label: string;
296
+ }[];
297
+ /** Applied on timeout, disconnect, cancel and readers without a screen. */
298
+ defaultOnTimeout: string;
299
+ /** How long the reader shows the question. Default 15, host clamps to [5, 30]. */
300
+ expiresInSec?: number;
301
+ /** Called once with the answer or the default; runs with the hook timeout, errors are logged. */
302
+ onAnswer(choiceId: string): void | Promise<void>;
303
+ }
304
+ export type SessionEndResult = {
305
+ decision: 'none';
306
+ } | {
307
+ decision: 'choose';
308
+ choice: PluginChoice;
309
+ };
310
+ export type SessionEndHook = (ctx: SessionEndContext) => SessionEndResult | Promise<SessionEndResult>;
311
+ export interface PluginReaderUiApi {
312
+ /** Re-evaluate and push contributions for a resource or reader. */
313
+ invalidate(scope: {
314
+ resourceId?: number;
315
+ readerId?: number;
316
+ }): void;
317
+ }
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ /**
3
+ * Reader UI schema v1 and the pre-start / session-end hook contract.
4
+ *
5
+ * Plugins describe UI as plain data. Nothing here runs on the reader. The host
6
+ * validates, sanitizes (Latin-1) and size-checks everything before it is sent.
7
+ * The firmware mirrors the constants in `display/ui/ui_schema.hpp`; a Jest
8
+ * parity test keeps both in sync.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.READER_UI_CAPABILITIES_NONE = exports.PANIC_CLASS_RESET_REASONS = exports.DEFAULT_NO_SCREEN_POLICY = exports.NO_SCREEN_POLICIES = exports.READER_UI_RESERVED_STATUS_STRINGS = exports.READER_UI_TIMING = exports.READER_UI_LIMITS = exports.READER_UI_STEP_KINDS = exports.READER_UI_SLOT_NODE_BUDGET = exports.READER_UI_SLOT_IDS = exports.READER_UI_SLOTS = exports.READER_UI_TEXT_STYLES = exports.READER_UI_ICONS = exports.READER_UI_TONES = exports.READER_UI_COMPONENTS = exports.READER_UI_SCHEMA_VERSION = void 0;
12
+ exports.READER_UI_SCHEMA_VERSION = 1;
13
+ exports.READER_UI_COMPONENTS = [
14
+ 'col',
15
+ 'row',
16
+ 'text',
17
+ 'badge',
18
+ 'icon',
19
+ 'button',
20
+ 'progress',
21
+ 'countdown',
22
+ 'spacer',
23
+ ];
24
+ exports.READER_UI_TONES = ['primary', 'success', 'warning', 'danger'];
25
+ exports.READER_UI_ICONS = ['ok', 'warning', 'bell', 'lock', 'clock'];
26
+ exports.READER_UI_TEXT_STYLES = ['title', 'body', 'small'];
27
+ exports.READER_UI_SLOTS = {
28
+ RESOURCE_LIST_ROW_STATUS: 'resourceList.row.status',
29
+ RESOURCE_DETAILS_HEADER: 'resource.details.header',
30
+ RESOURCE_DETAILS_BODY: 'resource.details.body',
31
+ RESOURCE_DETAILS_SESSION: 'resource.details.session',
32
+ };
33
+ exports.READER_UI_SLOT_IDS = Object.values(exports.READER_UI_SLOTS);
34
+ /** Node budget per slot. The list row slot takes a single text or badge. */
35
+ exports.READER_UI_SLOT_NODE_BUDGET = {
36
+ 'resourceList.row.status': 1,
37
+ 'resource.details.header': 6,
38
+ 'resource.details.body': 8,
39
+ 'resource.details.session': 6,
40
+ };
41
+ exports.READER_UI_STEP_KINDS = ['confirm', 'choose', 'info'];
42
+ exports.READER_UI_LIMITS = {
43
+ /** UTF-8 bytes of the sanitized UI payload. */
44
+ maxPayloadBytes: 3072,
45
+ /** Whole websocket frame; legacy token readers cannot reassemble. */
46
+ maxFrameBytes: 4096,
47
+ maxNodes: 32,
48
+ maxDepth: 5,
49
+ maxLiveNodes: 64,
50
+ maxTextChars: 80,
51
+ maxLabelBytes: 31,
52
+ maxListRowChars: 24,
53
+ maxChoices: 4,
54
+ maxSlotContributionsPerResource: 8,
55
+ idPattern: /^[a-z0-9_-]{1,24}$/,
56
+ };
57
+ exports.READER_UI_TIMING = {
58
+ stepDefaultTtlSec: 60,
59
+ stepMaxTtlSec: 120,
60
+ stepGraceSec: 5,
61
+ postStopDefaultTtlSec: 15,
62
+ postStopMaxTtlSec: 30,
63
+ hookDefaultTimeoutMs: 1500,
64
+ hookMaxTimeoutMs: 3000,
65
+ breakerThreshold: 5,
66
+ breakerProbeAfterMs: 60000,
67
+ crashLoopSuspendMs: 30 * 60000,
68
+ slotUpdateMinIntervalMs: 2000,
69
+ };
70
+ /**
71
+ * Strings that only the host may show (core status). Plugin text is rejected when it equals one after lower-casing,
72
+ * collapsing whitespace and stripping non-letters at both ends.
73
+ */
74
+ exports.READER_UI_RESERVED_STATUS_STRINGS = [
75
+ 'maintenance',
76
+ 'under maintenance',
77
+ 'in use',
78
+ 'available',
79
+ 'access granted',
80
+ 'access denied',
81
+ 'unavailable',
82
+ 'introduction required',
83
+ 'emergency stop',
84
+ 'firmware update',
85
+ 'wartung',
86
+ 'in wartung',
87
+ 'in benutzung',
88
+ 'verfuegbar',
89
+ 'verfügbar',
90
+ 'zugriff gewaehrt',
91
+ 'zugriff gewährt',
92
+ 'zugriff verweigert',
93
+ 'einweisung erforderlich',
94
+ 'notaus',
95
+ ];
96
+ exports.NO_SCREEN_POLICIES = ['block', 'card-confirm', 'allow-with-warning'];
97
+ exports.DEFAULT_NO_SCREEN_POLICY = 'block';
98
+ /** Reset reasons shared with READER_CRASH_REPORT. */
99
+ exports.PANIC_CLASS_RESET_REASONS = ['PANIC', 'INT_WDT', 'TASK_WDT', 'WDT', 'CPU_LOCKUP'];
100
+ exports.READER_UI_CAPABILITIES_NONE = {
101
+ schemaVersion: 0,
102
+ components: [],
103
+ slots: [],
104
+ steps: [],
105
+ maxPayloadBytes: 0,
106
+ maxNodes: 0,
107
+ maxDepth: 0,
108
+ maxLiveNodes: 0,
109
+ display: null,
110
+ input: { touch: false, buttons: 0, cardHold: false },
111
+ feedback: { leds: false, beeper: false },
112
+ charset: 'latin1',
113
+ images: false,
114
+ };
115
+ //# sourceMappingURL=reader-ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader-ui.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/reader-ui.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA0BU,QAAA,wBAAwB,GAAG,CAAC,CAAC;AAE7B,QAAA,oBAAoB,GAAG;IAClC,KAAK;IACL,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,QAAQ;IACR,UAAU;IACV,WAAW;IACX,QAAQ;CACA,CAAC;AAGE,QAAA,eAAe,GAA4B,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACvF,QAAA,eAAe,GAAgC,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1F,QAAA,qBAAqB,GAAiC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjF,QAAA,eAAe,GAAG;IAC7B,wBAAwB,EAAE,yBAAyB;IACnD,uBAAuB,EAAE,yBAAyB;IAClD,qBAAqB,EAAE,uBAAuB;IAC9C,wBAAwB,EAAE,0BAA0B;C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;IACX,kBAAkB;IAClB,iBAAiB;IACjB,oBAAoB;IACpB,yBAAyB;IACzB,QAAQ;CACT,CAAC;AAGW,QAAA,kBAAkB,GAA8B,CAAC,OAAO,EAAE,cAAc,EAAE,oBAAoB,CAAC,CAAC;AAChG,QAAA,wBAAwB,GAAmB,OAAO,CAAC;AAIhE,qDAAqD;AACxC,QAAA,yBAAyB,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,CAAU,CAAC;AAoB3F,QAAA,2BAA2B,GAAyB;IAC/D,aAAa,EAAE,CAAC;IAChB,UAAU,EAAE,EAAE;IACd,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,eAAe,EAAE,CAAC;IAClB,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,YAAY,EAAE,CAAC;IACf,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;IACpD,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;IACxC,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,KAAK;CACd,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Observable } from 'rxjs';
2
+ export type LiveSample<Value> = {
3
+ data: {
4
+ eventType: 'snapshot';
5
+ value: Value;
6
+ } | {
7
+ eventType: 'unavailable';
8
+ };
9
+ };
10
+ /** Share status reads per key until the final subscriber leaves. */
11
+ export declare function createSharedLiveSampler<Key, Value = unknown>(): (key: Key, intervalMs: number, read: () => Promise<Value>) => Observable<LiveSample<Value>>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSharedLiveSampler = createSharedLiveSampler;
4
+ const rxjs_1 = require("rxjs");
5
+ /** Share status reads per key until the final subscriber leaves. */
6
+ function createSharedLiveSampler() {
7
+ const sources = new Map();
8
+ // Unsubscribing cannot cancel a device Promise. Keep only its guard until it settles.
9
+ const inFlight = new Set();
10
+ return (key, intervalMs, read) => (0, rxjs_1.defer)(() => {
11
+ let source = sources.get(key);
12
+ if (!source) {
13
+ source = (0, rxjs_1.timer)(0, intervalMs).pipe(
14
+ // Skip ticks while a read is pending; failures allow the next tick to recover.
15
+ (0, rxjs_1.exhaustMap)(() => (0, rxjs_1.defer)(() => {
16
+ if (inFlight.has(key))
17
+ return rxjs_1.EMPTY;
18
+ inFlight.add(key);
19
+ return Promise.resolve()
20
+ .then(read)
21
+ .finally(() => inFlight.delete(key));
22
+ }).pipe((0, rxjs_1.map)((value) => ({ data: { eventType: 'snapshot', value } })),
23
+ // Device errors may contain credentials, so only expose availability.
24
+ (0, rxjs_1.catchError)(() => (0, rxjs_1.of)({ data: { eventType: 'unavailable' } })))), (0, rxjs_1.finalize)(() => {
25
+ if (sources.get(key) === source)
26
+ sources.delete(key);
27
+ }), (0, rxjs_1.shareReplay)({ bufferSize: 1, refCount: true }));
28
+ sources.set(key, source);
29
+ }
30
+ return source;
31
+ });
32
+ }
33
+ //# sourceMappingURL=shared-live-sampler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-live-sampler.js","sourceRoot":"","sources":["../../../../../libs/plugins-backend-sdk/src/lib/shared-live-sampler.ts"],"names":[],"mappings":";;AAOA,0DAiCC;AAxCD,+BAA+G;AAM/G,oEAAoE;AACpE,SAAgB,uBAAuB;IACrC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC9D,sFAAsF;IACtF,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAO,CAAC;IAEhC,OAAO,CAAC,GAAQ,EAAE,UAAkB,EAAE,IAA0B,EAAiC,EAAE,CACjG,IAAA,YAAK,EAAC,GAAG,EAAE;QACT,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,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