@attraccess/plugins-backend-sdk 1.10.0 → 1.11.0-beta.1
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 +13 -8
- package/src/index.d.ts +8 -0
- package/src/index.js +8 -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.types.d.ts +3 -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 +34 -33
- package/src/lib/plugin-audit.js +9 -9
- package/src/lib/plugin-audit.js.map +1 -1
- package/src/lib/plugin-backend-module.d.ts +71 -0
- package/src/lib/plugin-backend-module.js +3 -0
- package/src/lib/plugin-backend-module.js.map +1 -0
- 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 +94 -0
- package/src/lib/plugin-ble-fake.js +406 -0
- package/src/lib/plugin-ble-fake.js.map +1 -0
- package/src/lib/plugin-ble-notification-stream.d.ts +28 -0
- package/src/lib/plugin-ble-notification-stream.js +119 -0
- package/src/lib/plugin-ble-notification-stream.js.map +1 -0
- package/src/lib/plugin-ble-session-engine.d.ts +119 -0
- package/src/lib/plugin-ble-session-engine.js +410 -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 +249 -0
- package/src/lib/plugin-ble.js +85 -0
- package/src/lib/plugin-ble.js.map +1 -0
- package/src/lib/plugin-context.d.ts +58 -54
- package/src/lib/plugin-context.js +6 -6
- package/src/lib/plugin-context.js.map +1 -1
- package/src/lib/plugin-flow-node.d.ts +52 -3
- package/src/lib/plugin-live-updates.d.ts +21 -0
- package/src/lib/plugin-live-updates.js +3 -0
- package/src/lib/plugin-live-updates.js.map +1 -0
- package/src/lib/plugin-notifications.d.ts +83 -0
- package/src/lib/plugin-notifications.js +3 -0
- package/src/lib/plugin-notifications.js.map +1 -0
- package/src/lib/plugin-resource-access.d.ts +89 -0
- package/src/lib/plugin-resource-access.js +3 -0
- package/src/lib/plugin-resource-access.js.map +1 -0
- package/src/lib/plugin.interface.d.ts +92 -5
- package/src/lib/plugin.interface.js +28 -1
- package/src/lib/plugin.interface.js.map +1 -1
- package/src/lib/reader-ui.d.ts +359 -0
- package/src/lib/reader-ui.js +115 -0
- package/src/lib/reader-ui.js.map +1 -0
- package/src/lib/shared-live-sampler.d.ts +11 -0
- package/src/lib/shared-live-sampler.js +33 -0
- package/src/lib/shared-live-sampler.js.map +1 -0
|
@@ -0,0 +1,359 @@
|
|
|
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 { EntityManager } from 'typeorm';
|
|
10
|
+
import type { PluginAccessPrincipal } from './plugin-resource-access';
|
|
11
|
+
export type ReaderUiTone = 'primary' | 'success' | 'warning' | 'danger';
|
|
12
|
+
export type ReaderUiIconName = 'ok' | 'warning' | 'bell' | 'lock' | 'clock';
|
|
13
|
+
export type ReaderUiTextStyle = 'title' | 'body' | 'small';
|
|
14
|
+
export type ReaderUiNode = {
|
|
15
|
+
t: 'col' | 'row';
|
|
16
|
+
c?: ReaderUiNode[];
|
|
17
|
+
gap?: number;
|
|
18
|
+
pad?: number;
|
|
19
|
+
fill?: boolean;
|
|
20
|
+
tone?: ReaderUiTone;
|
|
21
|
+
} | {
|
|
22
|
+
t: 'text';
|
|
23
|
+
text: string;
|
|
24
|
+
style?: ReaderUiTextStyle;
|
|
25
|
+
fill?: boolean;
|
|
26
|
+
} | {
|
|
27
|
+
t: 'badge';
|
|
28
|
+
text: string;
|
|
29
|
+
tone?: ReaderUiTone;
|
|
30
|
+
} | {
|
|
31
|
+
t: 'icon';
|
|
32
|
+
name: ReaderUiIconName;
|
|
33
|
+
tone?: ReaderUiTone;
|
|
34
|
+
}
|
|
35
|
+
/** Steps only. Slot trees must not contain buttons. */
|
|
36
|
+
| {
|
|
37
|
+
t: 'button';
|
|
38
|
+
id: string;
|
|
39
|
+
text: string;
|
|
40
|
+
variant?: 'primary' | 'secondary';
|
|
41
|
+
} | {
|
|
42
|
+
t: 'progress';
|
|
43
|
+
value: number;
|
|
44
|
+
tone?: ReaderUiTone;
|
|
45
|
+
}
|
|
46
|
+
/** Plugin-facing form takes a Date; the wire form carries epoch milliseconds in `toMs`. */
|
|
47
|
+
| {
|
|
48
|
+
t: 'countdown';
|
|
49
|
+
to: Date;
|
|
50
|
+
tone?: ReaderUiTone;
|
|
51
|
+
} | {
|
|
52
|
+
t: 'spacer';
|
|
53
|
+
h?: number;
|
|
54
|
+
};
|
|
55
|
+
/** Wire form of a node tree: `countdown.to` is replaced by `toMs`. */
|
|
56
|
+
export type ReaderUiWireNode = Exclude<ReaderUiNode, {
|
|
57
|
+
t: 'countdown' | 'col' | 'row';
|
|
58
|
+
}> | {
|
|
59
|
+
t: 'col' | 'row';
|
|
60
|
+
c?: ReaderUiWireNode[];
|
|
61
|
+
gap?: number;
|
|
62
|
+
pad?: number;
|
|
63
|
+
fill?: boolean;
|
|
64
|
+
tone?: ReaderUiTone;
|
|
65
|
+
} | {
|
|
66
|
+
t: 'countdown';
|
|
67
|
+
toMs: number;
|
|
68
|
+
tone?: ReaderUiTone;
|
|
69
|
+
};
|
|
70
|
+
export declare const READER_UI_SCHEMA_VERSION = 1;
|
|
71
|
+
export declare const READER_UI_COMPONENTS: readonly ["col", "row", "text", "badge", "icon", "button", "progress", "countdown", "spacer"];
|
|
72
|
+
export type ReaderUiComponent = (typeof READER_UI_COMPONENTS)[number];
|
|
73
|
+
export declare const READER_UI_TONES: readonly ReaderUiTone[];
|
|
74
|
+
export declare const READER_UI_ICONS: readonly ReaderUiIconName[];
|
|
75
|
+
export declare const READER_UI_TEXT_STYLES: readonly ReaderUiTextStyle[];
|
|
76
|
+
export declare const READER_UI_SLOTS: {
|
|
77
|
+
readonly RESOURCE_LIST_ROW_STATUS: "resourceList.row.status";
|
|
78
|
+
readonly RESOURCE_DETAILS_HEADER: "resource.details.header";
|
|
79
|
+
readonly RESOURCE_DETAILS_BODY: "resource.details.body";
|
|
80
|
+
readonly RESOURCE_DETAILS_SESSION: "resource.details.session";
|
|
81
|
+
};
|
|
82
|
+
export type ReaderUiSlotId = (typeof READER_UI_SLOTS)[keyof typeof READER_UI_SLOTS];
|
|
83
|
+
export declare const READER_UI_SLOT_IDS: readonly ReaderUiSlotId[];
|
|
84
|
+
/** Node budget per slot. The list row slot takes a single text or badge. */
|
|
85
|
+
export declare const READER_UI_SLOT_NODE_BUDGET: Record<ReaderUiSlotId, number>;
|
|
86
|
+
export declare const READER_UI_STEP_KINDS: readonly ["confirm", "choose", "info"];
|
|
87
|
+
export type ReaderUiStepKind = (typeof READER_UI_STEP_KINDS)[number];
|
|
88
|
+
export type ReaderUiStepRole = 'cancel' | 'confirm' | 'ok' | 'choice';
|
|
89
|
+
export declare const READER_UI_LIMITS: {
|
|
90
|
+
/** UTF-8 bytes of the sanitized UI payload. */
|
|
91
|
+
readonly maxPayloadBytes: 3072;
|
|
92
|
+
/** Whole websocket frame; legacy token readers cannot reassemble. */
|
|
93
|
+
readonly maxFrameBytes: 4096;
|
|
94
|
+
readonly maxNodes: 32;
|
|
95
|
+
readonly maxDepth: 5;
|
|
96
|
+
readonly maxLiveNodes: 64;
|
|
97
|
+
readonly maxTextChars: 80;
|
|
98
|
+
readonly maxLabelBytes: 31;
|
|
99
|
+
readonly maxListRowChars: 24;
|
|
100
|
+
readonly maxChoices: 4;
|
|
101
|
+
readonly maxSlotContributionsPerResource: 8;
|
|
102
|
+
readonly idPattern: RegExp;
|
|
103
|
+
};
|
|
104
|
+
export declare const READER_UI_TIMING: {
|
|
105
|
+
readonly stepDefaultTtlSec: 60;
|
|
106
|
+
readonly stepMaxTtlSec: 120;
|
|
107
|
+
readonly stepGraceSec: 5;
|
|
108
|
+
readonly postStopDefaultTtlSec: 15;
|
|
109
|
+
readonly postStopMaxTtlSec: 30;
|
|
110
|
+
readonly hookDefaultTimeoutMs: 1500;
|
|
111
|
+
readonly hookMaxTimeoutMs: 3000;
|
|
112
|
+
readonly breakerThreshold: 5;
|
|
113
|
+
readonly breakerProbeAfterMs: 60000;
|
|
114
|
+
readonly crashLoopSuspendMs: number;
|
|
115
|
+
readonly slotUpdateMinIntervalMs: 2000;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Strings that only the host may show (core status). Plugin text is rejected when it equals one after lower-casing,
|
|
119
|
+
* collapsing whitespace and stripping non-letters at both ends.
|
|
120
|
+
*/
|
|
121
|
+
export declare const READER_UI_RESERVED_STATUS_STRINGS: readonly string[];
|
|
122
|
+
export type NoScreenPolicy = 'block' | 'card-confirm' | 'allow-with-warning';
|
|
123
|
+
export declare const NO_SCREEN_POLICIES: readonly NoScreenPolicy[];
|
|
124
|
+
export declare const DEFAULT_NO_SCREEN_POLICY: NoScreenPolicy;
|
|
125
|
+
export type HookFailurePolicy = 'fail-closed' | 'fail-open';
|
|
126
|
+
/** Reset reasons shared with READER_CRASH_REPORT. */
|
|
127
|
+
export declare const PANIC_CLASS_RESET_REASONS: readonly ["PANIC", "INT_WDT", "TASK_WDT", "WDT", "CPU_LOCKUP"];
|
|
128
|
+
/** What a reader reports in `READER_FIRMWARE_INFO.capabilities.ui`. Missing = schemaVersion 0. */
|
|
129
|
+
export interface ReaderUiCapabilities {
|
|
130
|
+
schemaVersion: number;
|
|
131
|
+
components: string[];
|
|
132
|
+
slots: string[];
|
|
133
|
+
/** Touch: confirm/choose/info. Lite: [] or ['card-confirm']. */
|
|
134
|
+
steps: string[];
|
|
135
|
+
maxPayloadBytes: number;
|
|
136
|
+
maxNodes: number;
|
|
137
|
+
maxDepth: number;
|
|
138
|
+
maxLiveNodes: number;
|
|
139
|
+
display: {
|
|
140
|
+
w: number;
|
|
141
|
+
h: number;
|
|
142
|
+
touch: boolean;
|
|
143
|
+
} | null;
|
|
144
|
+
input: {
|
|
145
|
+
touch: boolean;
|
|
146
|
+
buttons: number;
|
|
147
|
+
cardHold: boolean;
|
|
148
|
+
};
|
|
149
|
+
feedback: {
|
|
150
|
+
leds: boolean;
|
|
151
|
+
beeper: boolean;
|
|
152
|
+
};
|
|
153
|
+
charset: 'latin1';
|
|
154
|
+
images: boolean;
|
|
155
|
+
}
|
|
156
|
+
export declare const READER_UI_CAPABILITIES_NONE: ReaderUiCapabilities;
|
|
157
|
+
export interface ReaderUiContext {
|
|
158
|
+
readerId: number;
|
|
159
|
+
resourceId: number;
|
|
160
|
+
/** Set whenever a card session is live; never for a signed-out reader. */
|
|
161
|
+
userId?: number;
|
|
162
|
+
/**
|
|
163
|
+
* The resource has an active usage visible on this reader. The reader shows `resource.details.session` only
|
|
164
|
+
* while this is true, so a provider that wants a fact in one block puts it in the session slot when this is true
|
|
165
|
+
* and in the details body otherwise. The host re-evaluates the provider when a usage starts, ends or is taken
|
|
166
|
+
* over. Optional for compatibility: when unset, treat it as `false`.
|
|
167
|
+
*/
|
|
168
|
+
sessionActive?: boolean;
|
|
169
|
+
capabilities: ReaderUiCapabilities;
|
|
170
|
+
language: 'en' | 'de';
|
|
171
|
+
}
|
|
172
|
+
export interface ReaderSlotContribution {
|
|
173
|
+
slotId: ReaderUiSlotId;
|
|
174
|
+
/** Plugin-local, unique per slot and resource. */
|
|
175
|
+
key: string;
|
|
176
|
+
tree: ReaderUiNode;
|
|
177
|
+
/** The host re-evaluates the provider at this time and removes the contribution. */
|
|
178
|
+
expiresAt?: Date;
|
|
179
|
+
/** Sent instead of `tree` when the reader cannot render it. */
|
|
180
|
+
fallback?: {
|
|
181
|
+
text: string;
|
|
182
|
+
tone?: ReaderUiTone;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export interface ReaderUiProvider {
|
|
186
|
+
getSlotContributions(ctx: ReaderUiContext): ReaderSlotContribution[] | Promise<ReaderSlotContribution[]>;
|
|
187
|
+
/**
|
|
188
|
+
* The IANA time zone (e.g. `Europe/Berlin`) this plugin writes times in on readers for the resource, or `undefined`
|
|
189
|
+
* for no opinion. The host sends one zone per reader, so the reader's clock and the plugin's texts agree: the first
|
|
190
|
+
* valid zone in host order wins (the reader's resources by id, and for each resource the plugins in host order,
|
|
191
|
+
* alphabetically by plugin name; a slower plugin that answers within the time limit still wins over a faster one
|
|
192
|
+
* ranked lower), otherwise the server's `TZ` applies. An invalid name is ignored; two different zones for one reader
|
|
193
|
+
* raise an admin alert. Called with the slot timeout; an error or timeout counts as no opinion. Call
|
|
194
|
+
* `readerUi.invalidate` when the zone changes.
|
|
195
|
+
*/
|
|
196
|
+
getTimeZone?(ctx: {
|
|
197
|
+
readerId: number;
|
|
198
|
+
resourceId: number;
|
|
199
|
+
}): string | undefined | Promise<string | undefined>;
|
|
200
|
+
}
|
|
201
|
+
export type PreStartOrigin = 'web' | 'api' | 'reader' | 'supervision';
|
|
202
|
+
export interface PreStartContext {
|
|
203
|
+
resourceId: number;
|
|
204
|
+
userId: number;
|
|
205
|
+
/**
|
|
206
|
+
* The starter as a `resourceAccess` principal. Web and API starts carry the request's permissions (an API token's
|
|
207
|
+
* scope), reader and supervision starts the plain user id. Pass it to `resourceAccess` instead of `userId`, so
|
|
208
|
+
* permission checks in the hook apply the same scope as core's own start checks.
|
|
209
|
+
*/
|
|
210
|
+
principal: PluginAccessPrincipal;
|
|
211
|
+
action: 'start' | 'takeover';
|
|
212
|
+
projectId?: number;
|
|
213
|
+
origin: PreStartOrigin;
|
|
214
|
+
/** Only this plugin's step keys, checked by the host. */
|
|
215
|
+
confirmedStepKeys: string[];
|
|
216
|
+
/** Language for texts: the card user's on a reader, the user's preferred language elsewhere. */
|
|
217
|
+
language: 'en' | 'de';
|
|
218
|
+
now: Date;
|
|
219
|
+
}
|
|
220
|
+
export interface PluginConfirmation {
|
|
221
|
+
/** Stable per plugin; the host issues a random stepId per step. */
|
|
222
|
+
stepKey: string;
|
|
223
|
+
title: string;
|
|
224
|
+
body: string;
|
|
225
|
+
tone?: ReaderUiTone;
|
|
226
|
+
confirmLabel?: string;
|
|
227
|
+
cancelLabel?: string;
|
|
228
|
+
countdownTo?: Date;
|
|
229
|
+
/** Host clamps to [10, 120]. */
|
|
230
|
+
expiresInSec?: number;
|
|
231
|
+
/** Plugin default for readers without a screen. */
|
|
232
|
+
noScreenPolicy?: NoScreenPolicy;
|
|
233
|
+
}
|
|
234
|
+
export interface PluginBlockReason {
|
|
235
|
+
code: string;
|
|
236
|
+
title: string;
|
|
237
|
+
body: string;
|
|
238
|
+
}
|
|
239
|
+
export type PreStartResult = {
|
|
240
|
+
decision: 'allow';
|
|
241
|
+
} | {
|
|
242
|
+
decision: 'confirm';
|
|
243
|
+
confirmation: PluginConfirmation;
|
|
244
|
+
} | {
|
|
245
|
+
decision: 'block';
|
|
246
|
+
reason: PluginBlockReason;
|
|
247
|
+
};
|
|
248
|
+
export type PreStartHook = (ctx: PreStartContext) => PreStartResult | Promise<PreStartResult>;
|
|
249
|
+
export interface StartBlockedContext {
|
|
250
|
+
resourceId: number;
|
|
251
|
+
/** The user looking at the resource. Apply your own visibility rules before naming anybody in the reason. */
|
|
252
|
+
userId: number;
|
|
253
|
+
/** The viewer as a `resourceAccess` principal, with the request's permissions (an API token's scope). */
|
|
254
|
+
principal: PluginAccessPrincipal;
|
|
255
|
+
/** Language for texts: the user's preferred language. */
|
|
256
|
+
language: 'en' | 'de';
|
|
257
|
+
now: Date;
|
|
258
|
+
}
|
|
259
|
+
/** A start that is refused right now. Same reason shape as a `preStartHook` block. */
|
|
260
|
+
export interface StartBlockedState {
|
|
261
|
+
reason: PluginBlockReason;
|
|
262
|
+
/** When the block ends, if known. The host UI refreshes itself then and shows the time. */
|
|
263
|
+
until?: Date;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Query-side counterpart of `preStartHook`: tells the UI that a start by this user is blocked right now, so it
|
|
267
|
+
* can show the reason in place of the start button instead of letting the user press it. Return null when
|
|
268
|
+
* nothing blocks. It is informational only: `preStartHook` stays the authoritative gate and must still block.
|
|
269
|
+
* Keep it cheap and side-effect free; it is called whenever a resource page is open. Failures and timeouts
|
|
270
|
+
* count as "not blocked". Requires ACCESS_HOOKS.
|
|
271
|
+
*/
|
|
272
|
+
export type StartBlockedQuery = (ctx: StartBlockedContext) => StartBlockedState | null | Promise<StartBlockedState | null>;
|
|
273
|
+
/** Lets a plugin tell the host UI that the answer of its `startBlockedQuery` may have changed. */
|
|
274
|
+
export interface PluginStartBlockedApi {
|
|
275
|
+
/** Open resource pages ask again. Call it when bookings or rules that decide the block change. */
|
|
276
|
+
invalidate(scope: {
|
|
277
|
+
resourceId: number;
|
|
278
|
+
}): void;
|
|
279
|
+
}
|
|
280
|
+
export interface StartCapacityContext {
|
|
281
|
+
resourceId: number;
|
|
282
|
+
/** The starter. */
|
|
283
|
+
userId: number;
|
|
284
|
+
/** The starter as a `resourceAccess` principal (see {@link PreStartContext.principal}). */
|
|
285
|
+
principal: PluginAccessPrincipal;
|
|
286
|
+
/**
|
|
287
|
+
* The host's serialized start transaction. Read through it and never start `runSerialized` inside the hook: the
|
|
288
|
+
* transaction would wait for itself.
|
|
289
|
+
*/
|
|
290
|
+
manager: EntityManager;
|
|
291
|
+
/** Always `start` for now: the hook only runs when a start adds a session (shared machines have no takeover). */
|
|
292
|
+
action: 'start' | 'takeover';
|
|
293
|
+
origin: PreStartOrigin;
|
|
294
|
+
/** Effective session limit of the machine (always above 1 here). */
|
|
295
|
+
sessionLimit: number;
|
|
296
|
+
/** Slots taken by sessions and by starts that are in progress, read in the same transaction. */
|
|
297
|
+
occupiedSlots: number;
|
|
298
|
+
/** The users behind `occupiedSlots` (sessions and starts in progress), read in the same transaction. */
|
|
299
|
+
usersInSession: number[];
|
|
300
|
+
/** Only this plugin's step keys confirmed in the same start attempt. */
|
|
301
|
+
confirmedStepKeys: string[];
|
|
302
|
+
/** Language for texts: the card user's on a reader, the user's preferred language elsewhere. */
|
|
303
|
+
language: 'en' | 'de';
|
|
304
|
+
now: Date;
|
|
305
|
+
}
|
|
306
|
+
export interface StartCapacityResult {
|
|
307
|
+
/** Slots the plugin holds back from this starter (a non-negative integer). */
|
|
308
|
+
heldSlots: number;
|
|
309
|
+
/** Shown when the host refuses the start because `occupiedSlots + heldSlots` reaches the limit. */
|
|
310
|
+
reason?: PluginBlockReason;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Atomic capacity counterpart of `preStartHook`: on machines with more than one parallel session the host calls it
|
|
314
|
+
* INSIDE the serialized start transaction, after its own capacity check. The host refuses the start with the plugin's
|
|
315
|
+
* block reason when `occupiedSlots + heldSlots >= sessionLimit`, so simultaneous starts can never take a held slot.
|
|
316
|
+
* Keep it to one indexed query on `ctx.manager`. Failure, timeout and an open breaker follow the per-resource failure
|
|
317
|
+
* policy of the plugin, like `preStartHook`. Requires ACCESS_HOOKS and DATABASE_ACCESS (it is handed the host's
|
|
318
|
+
* transaction).
|
|
319
|
+
*/
|
|
320
|
+
export type StartCapacityHook = (ctx: StartCapacityContext) => StartCapacityResult | Promise<StartCapacityResult>;
|
|
321
|
+
export interface SessionEndContext {
|
|
322
|
+
resourceId: number;
|
|
323
|
+
userId: number;
|
|
324
|
+
sessionId: number;
|
|
325
|
+
origin: 'web' | 'api' | 'reader';
|
|
326
|
+
/** Language for texts: the card user's on a reader, the user's preferred language elsewhere. */
|
|
327
|
+
language: 'en' | 'de';
|
|
328
|
+
now: Date;
|
|
329
|
+
}
|
|
330
|
+
export interface PluginChoice {
|
|
331
|
+
stepKey: string;
|
|
332
|
+
title: string;
|
|
333
|
+
body: string;
|
|
334
|
+
/** Max 4. */
|
|
335
|
+
choices: {
|
|
336
|
+
id: string;
|
|
337
|
+
label: string;
|
|
338
|
+
}[];
|
|
339
|
+
/** Applied on timeout, disconnect, cancel and readers without a screen. */
|
|
340
|
+
defaultOnTimeout: string;
|
|
341
|
+
/** How long the reader shows the question. Default 15, host clamps to [5, 30]. */
|
|
342
|
+
expiresInSec?: number;
|
|
343
|
+
/** Called once with the answer or the default; runs with the hook timeout, errors are logged. */
|
|
344
|
+
onAnswer(choiceId: string): void | Promise<void>;
|
|
345
|
+
}
|
|
346
|
+
export type SessionEndResult = {
|
|
347
|
+
decision: 'none';
|
|
348
|
+
} | {
|
|
349
|
+
decision: 'choose';
|
|
350
|
+
choice: PluginChoice;
|
|
351
|
+
};
|
|
352
|
+
export type SessionEndHook = (ctx: SessionEndContext) => SessionEndResult | Promise<SessionEndResult>;
|
|
353
|
+
export interface PluginReaderUiApi {
|
|
354
|
+
/** Re-evaluate and push contributions for a resource or reader. */
|
|
355
|
+
invalidate(scope: {
|
|
356
|
+
resourceId?: number;
|
|
357
|
+
readerId?: number;
|
|
358
|
+
}): void;
|
|
359
|
+
}
|
|
@@ -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;;;AA2BU,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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 +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,EAAE,CAAC;YACZ,MAAM,GAAG,IAAA,YAAK,EAAC,CAAC,EAAE,UAAU,CAAC,CAAC,IAAI;YAChC,+EAA+E;YAC/E,IAAA,iBAAU,EAAC,GAAG,EAAE,CACd,IAAA,YAAK,EAAC,GAAG,EAAE;gBACT,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,OAAO,YAAK,CAAC;gBACpC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAClB,OAAO,OAAO,CAAC,OAAO,EAAE;qBACrB,IAAI,CAAC,IAAI,CAAC;qBACV,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACzC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