@trymellon/js 2.2.0 → 2.3.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.
@@ -7,7 +7,7 @@ declare const INITIAL_UI_STATE: "IDLE";
7
7
  /** UI FSM types — presentation layer. No DOM/core deps (types only). Aligned to 01-arquitectura §4. */
8
8
 
9
9
  /** UI state machine states. */
10
- type UIState = 'IDLE' | 'EVALUATING_ENV' | 'READY' | 'READY_REGISTER' | 'READY_LOGIN' | 'AUTHENTICATING' | 'SUCCESS' | 'ERROR' | 'FALLBACK' | 'FALLBACK_EMAIL' | 'FALLBACK_QR';
10
+ type UIState = 'IDLE' | 'EVALUATING_ENV' | 'READY' | 'READY_REGISTER' | 'READY_LOGIN' | 'AUTHENTICATING' | 'SUCCESS' | 'ERROR' | 'FALLBACK' | 'FALLBACK_EMAIL' | 'FALLBACK_QR' | 'ENROLLMENT_READY' | 'ENROLLING' | 'ENROLLMENT_SUCCESS' | 'ENROLLMENT_ERROR';
11
11
  /** Component mode (mode attribute). */
12
12
  type UIMode = 'login' | 'register' | 'auto';
13
13
  /** Client status in UI layer (port/adapter map from core). */
@@ -54,6 +54,19 @@ type FSMEvent = {
54
54
  type: 'AUTH_FALLBACK_EMAIL';
55
55
  } | {
56
56
  type: 'AUTH_FALLBACK_QR';
57
+ } | {
58
+ type: 'ENROLLMENT_READY_SET';
59
+ payload?: {
60
+ ticketId?: string;
61
+ };
62
+ } | {
63
+ type: 'START_ENROLL';
64
+ } | {
65
+ type: 'ENROLL_SUCCESS';
66
+ } | {
67
+ type: 'ENROLL_ERROR';
68
+ } | {
69
+ type: 'ENROLL_RETRY';
57
70
  };
58
71
 
59
72
  /**
@@ -104,6 +117,8 @@ type ParsedAttributes = {
104
117
  buttonLabel?: string | null;
105
118
  /** Optional aria-label for the trigger button (default = TRIGGER_ARIA_LABEL). */
106
119
  buttonAriaLabel?: string | null;
120
+ /** When set, WC runs in enrollment mode: emits context-ready and exposes enroll(). */
121
+ ticketId?: string | null;
107
122
  };
108
123
  /** Modal display mode: overlay vs inline. */
109
124
  type ModalDisplayMode = 'modal' | 'inline';
@@ -158,13 +173,18 @@ type RenderOptions = {
158
173
  primaryButtonAriaLabel?: string;
159
174
  };
160
175
 
176
+ type EnrollOptions = {
177
+ ticketId: string;
178
+ signal?: AbortSignal;
179
+ };
180
+
161
181
  /**
162
182
  * Port: core event subscription and re-emission on host. Source of truth for modal WC event contract (names, detail types).
163
183
  * Contract only; implementation in adapters. No import from ../core.
164
184
  */
165
185
 
166
- /** Public auth operation for host (login | register). */
167
- type AuthOperation = TabKind;
186
+ /** Public auth operation for host (login | register | enroll). */
187
+ type AuthOperation = TabKind | 'enroll';
168
188
  /** Optional user info in mellon:success; minimal shape for host without coupling to core. */
169
189
  type MellonSuccessUserInfo = {
170
190
  userId: string;
@@ -216,10 +236,12 @@ interface CoreWithEvents {
216
236
  interface CoreEventsPort {
217
237
  subscribe(core: CoreWithEvents, host: HTMLElement): () => void;
218
238
  }
219
- /** Minimal core surface for UI: start auth and subscribe to events. */
239
+ /** Minimal core surface for UI: start auth, enrollment, context hash, and subscribe to events. */
220
240
  interface CoreAuthPort extends CoreWithEvents {
221
241
  authenticate(options?: CoreAuthOptions): void;
222
242
  register(options?: CoreAuthOptions): void;
243
+ enroll(options?: EnrollOptions): void;
244
+ getContextHash(): string;
223
245
  }
224
246
  /** Options when starting auth from UI. */
225
247
  interface CoreAuthOptions {
@@ -253,8 +275,13 @@ declare class AuthController {
253
275
  consumeCancelledDetailIfAuthenticating(): MellonOperationDetail | null;
254
276
  handleAuthSuccess(): void;
255
277
  handleAuthError(): void;
278
+ handleEnrollSuccess(): void;
279
+ handleEnrollError(): void;
256
280
  onStartEvent(detail: MellonOperationDetail | undefined): void;
257
281
  startAuthFromClick(core: CoreAuthPort | null, tab: TabKind, options?: CoreAuthOptions): void;
282
+ startEnrollment(core: CoreAuthPort | null, options: {
283
+ ticketId: string;
284
+ }): void;
258
285
  runEnvEval(params: Omit<RunEnvEvalParams, 'currentState'>): Promise<UIState | null>;
259
286
  reset(): void;
260
287
  setStateForRender(state: UIState): void;
@@ -340,6 +367,8 @@ declare abstract class AuthElementBase extends HTMLElement {
340
367
  declare class TryMellonAuthElement extends AuthElementBase {
341
368
  static get observedAttributes(): string[];
342
369
  protected _parsed: ParsedAttributes;
370
+ /** When set, WC is in enrollment mode: emits context-ready and exposes enroll(). */
371
+ get ticketId(): string | null;
343
372
  private _internalModal;
344
373
  /** Element that opened the modal; single source for focus restore on close. */
345
374
  private _focusRestoreTarget;
@@ -348,6 +377,12 @@ declare class TryMellonAuthElement extends AuthElementBase {
348
377
  /** Re-dispatch modal success on this element so host can listen on <trymellon-auth> (modal is in body, events don't bubble here). */
349
378
  private _onInternalModalSuccess;
350
379
  private _restoreFocusToTrigger;
380
+ /** When ticket-id is set and core is attached, emits mellon:context-ready with contextHash (composed: true). */
381
+ private _emitContextReadyIfEnrollment;
382
+ /**
383
+ * Starts enrollment (only when ticket-id is set). No-op if no ticketId or core. Success/error re-dispatched via mellon:success / mellon:error.
384
+ */
385
+ enroll(): void;
351
386
  connectedCallback(): void;
352
387
  private _registerInteractions;
353
388
  attributeChangedCallback(name: string, _oldValue: string | null, _newValue: string | null): void;
@@ -389,6 +424,8 @@ declare class TryMellonAuthModalElement extends AuthElementBase {
389
424
  connectedCallback(): void;
390
425
  private _registerInteractions;
391
426
  attributeChangedCallback(name: string, oldValue: string | null, _newValue: string | null): void;
427
+ /** Clear any host-injected cross-device slot content so each open starts with a clean slot (avoids stacked QRs). */
428
+ private _clearCrossDeviceSlot;
392
429
  private _startQrLoadWait;
393
430
  private _clearQrLoadWait;
394
431
  /** Single path to IDLE: close event, cancelled if needed, reset FSM, structure, render, visibility. Called from open→false and reset(). */