@arkyc/widget 1.2.11 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.mts CHANGED
@@ -3,7 +3,7 @@ import { FaceAnalyzer, FaceTuning } from "./face.mjs";
3
3
  import { AddressFormData } from "./ui.mjs";
4
4
  import { ProviderSignalHints } from "./client.mjs";
5
5
  import { WidgetRealtimeFactory } from "./realtime.mjs";
6
- import { DocumentType, LivenessChallenge, ProjectBranding, WidgetResult } from "@arkyc/types";
6
+ import { DocumentType, LivenessChallenge, ProjectBranding, SessionTransitionEvent, WidgetResult } from "@arkyc/types";
7
7
 
8
8
  //#region src/types.d.ts
9
9
  interface RgbData {
@@ -15,18 +15,58 @@ interface RgbData {
15
15
  str: string;
16
16
  }
17
17
  /**
18
- * An event surfaced to consumers through `onEvent` / `handle.on(name, cb)`. The
19
- * stream is a firehose: `session.transition` (live status changes, from the
20
- * configured transport) plus the lifecycle events `complete` / `error` / `close`.
18
+ * Payload for `session.transition` — a live verification status change relayed
19
+ * from the configured transport (pusher/firebase/polling). A widget-scoped
20
+ * subset of the server's {@link SessionTransitionEvent} (no org/project ids).
21
21
  */
22
- interface WidgetEvent {
23
- /** Event name, e.g. `session.transition`, `complete`, `error`, `close`. */
24
- name: string;
25
- /** Event payload (shape depends on `name`). */
26
- data?: unknown;
22
+ type WidgetSessionTransitionData = Pick<SessionTransitionEvent, 'session_id' | 'status' | 'previous_status'>;
23
+ /**
24
+ * Payload for `error` — a non-terminal failure surfaced as it happens (an
25
+ * expired session/token becomes knowable without waiting for the user to
26
+ * dismiss the screen). `status`/`error` are present only for typed API errors.
27
+ */
28
+ interface WidgetErrorData {
29
+ /** Human-readable failure message. */
30
+ message: string;
31
+ /** HTTP status code, when the failure came from a typed API error. */
32
+ status?: number;
33
+ /** Stable machine-readable error key, when the failure came from a typed API error. */
34
+ error?: string;
35
+ }
36
+ /**
37
+ * The set of widget events and the payload each delivers. This is the single
38
+ * source of truth for event names and their `data` shapes: `onEvent`,
39
+ * {@link WidgetEvent}, {@link WidgetEventListener}, and {@link WidgetHandle.on}
40
+ * are all derived from it, so a listener's `data` is typed from the name.
41
+ */
42
+ interface WidgetEventMap {
43
+ /** Live status change (fires on every real transition, once per change). */
44
+ 'session.transition': WidgetSessionTransitionData;
45
+ /** The flow settled successfully; carries the final verification result. */
46
+ complete: WidgetResult;
47
+ /** A failure occurred (may be recoverable; the flow has not necessarily ended). */
48
+ error: WidgetErrorData;
49
+ /** The widget was closed (camera released). No payload. */
50
+ close: undefined;
27
51
  }
28
- /** Subscribe to a named widget event; returns an unsubscribe function. */
29
- type WidgetEventListener = (data: unknown) => void;
52
+ /** A widget event name — one of the keys of {@link WidgetEventMap}. */
53
+ type WidgetEventName = keyof WidgetEventMap;
54
+ /**
55
+ * An event surfaced to consumers through `onEvent`. Discriminated on `name`, so
56
+ * a `switch (event.name)` narrows `event.data` to the matching payload. The
57
+ * stream is a firehose: `session.transition` (live status changes) plus the
58
+ * lifecycle events `complete` / `error` / `close`.
59
+ */
60
+ type WidgetEvent = { [K in WidgetEventName]: {
61
+ /** Event name (discriminant). */name: K; /** Event payload for this `name` (see {@link WidgetEventMap}). */
62
+ data: WidgetEventMap[K];
63
+ } }[WidgetEventName];
64
+ /**
65
+ * Subscribe callback for a single named widget event; receives that event's
66
+ * payload (typed from the name via {@link WidgetEventMap}). Defaults to the
67
+ * union of all payloads when the name isn't fixed.
68
+ */
69
+ type WidgetEventListener<K extends WidgetEventName = WidgetEventName> = (data: WidgetEventMap[K]) => void;
30
70
  /** Configuration for a {@link WidgetController}. */
31
71
  interface WidgetControllerConfig {
32
72
  /** Short-lived client token for this session. */
@@ -151,11 +191,13 @@ interface WidgetHandle {
151
191
  /** Close the widget and release the camera (fires `onClose`). */
152
192
  close: () => void;
153
193
  /**
154
- * Subscribe to a named widget event (e.g. `session.transition`, `complete`).
155
- * Returns an unsubscribe function. Registering a listener activates the event
156
- * stream (events are only delivered while at least one listener is active).
194
+ * Subscribe to a named widget event (`session.transition`, `complete`,
195
+ * `error`, `close`). The `listener`'s `data` is typed from the `event` name
196
+ * via {@link WidgetEventMap}. Returns an unsubscribe function. Registering a
197
+ * listener activates the event stream (events are only delivered while at
198
+ * least one listener is active).
157
199
  */
158
- on: (event: string, listener: WidgetEventListener) => () => void;
200
+ on: <K extends WidgetEventName>(event: K, listener: WidgetEventListener<K>) => () => void;
159
201
  }
160
202
  /** High-level events the view raises back to the controller. */
161
203
  interface ViewHandlers {
@@ -181,5 +223,5 @@ interface ViewHandlers {
181
223
  onShareLocation(): boolean | Promise<boolean>;
182
224
  }
183
225
  //#endregion
184
- export { BaseWidgetOptions, MountWidgetOptions, RgbData, ViewHandlers, WidgetControllerConfig, WidgetEvent, WidgetEventListener, WidgetHandle };
226
+ export { BaseWidgetOptions, MountWidgetOptions, RgbData, ViewHandlers, WidgetControllerConfig, WidgetErrorData, WidgetEvent, WidgetEventListener, WidgetEventMap, WidgetEventName, WidgetHandle, WidgetSessionTransitionData };
185
227
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;UAQiB,OAAA;EACf,GAAA;IAAO,CAAA;IAAW,CAAA;IAAW,CAAA;EAAA;EAC7B,GAAA;AAAA;;;;;AAAG;UAQY,WAAA;EAAW;EAE1B,IAAA;EAAA;EAEA,IAAI;AAAA;;KAIM,mBAAA,IAAuB,IAAa;;UAG/B,sBAAA;EAAA;EAEf,KAAA;;EAEA,OAAA;EAUU;EARV,OAAA;EAUkB;EARlB,UAAA;EACA,QAAA,GAAW,eAAA;EAsBL;;;;EAjBN,OAAA,GAAU,mBAAA;EACV,UAAA,IAAc,MAAA,EAAQ,YAAA;EACtB,OAAA,IAAW,KAAA,EAAO,KAAA;EAClB,OAAA;EAqCuC;;;;;EA/BvC,OAAA,IAAW,KAAA,EAAO,WAAA;EAdlB;EAgBA,QAAA;EAXA;E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AAoB,CAAA;AAAA;;UAIzD,YAAA;EACf,OAAA;EACA,OAAA;EACA,kBAAA,CAAmB,IAAA,EAAM,YAAA,EAAc,OAAA;EA7BpB;EA+BnB,OAAA,CAAQ,IAAA,EAAM,IAAA;EA7BG;;AAAc;AAIjC;EA8BE,gBAAA,CAAiB,KAAA,EAAO,IAAA,SAAa,SAAA,EAAW,iBAAA,IAAqB,MAAA,GAAS,IAAA;;EAE9E,aAAA;EAhC0C;EAkC1C,UAAA;EAhCoB;EAkCpB,cAAA;EAlC+B;EAoC/B,SAAA,CAAU,IAAA,EAAM,eAAA;EAhCW;EAkC3B,eAAA,cAA6B,OAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyc/widget",
3
- "version": "1.2.11",
3
+ "version": "2.0.0",
4
4
  "description": "Embeddable, framework-agnostic Arkyc identity-verification widget",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -39,8 +39,9 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
+ "@arkstack/realtime": "^0.19.4",
42
43
  "qrcode-generator": "^1.4.4",
43
- "@arkyc/types": "^1.2.11"
44
+ "@arkyc/types": "^2.0.0"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "firebase": "^11.0.0",