@touchcastllc/napster-companion-api-dev 1.6.0-alpha.2 → 1.6.0-alpha.3

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.
@@ -21,6 +21,13 @@ export interface MicGateOptions {
21
21
  onError?: (error: Error) => void;
22
22
  /** Fires immediately before the recovery card mounts. */
23
23
  onBeforeRecovery?: () => void;
24
+ /**
25
+ * Staleness probe, checked after every await before the gate touches the DOM
26
+ * or calls back. A session destroyed — or superseded by a new init() — while
27
+ * the browser prompt was open must not mount a recovery card into its own
28
+ * detached root, and must not drive the session that replaced it.
29
+ */
30
+ isStale?: () => boolean;
24
31
  }
25
32
  /**
26
33
  * Gate a session on microphone access (CA-622): try once, and on denial keep
@@ -400,21 +400,73 @@ export interface PersistenceOptions {
400
400
  trapBackNavigation?: boolean;
401
401
  }
402
402
  /**
403
- * Main configuration object passed to `init(token, config)`.
403
+ * Click-to-start configuration. Opt in with `enabled: true`; without it `init()`
404
+ * connects immediately, exactly as it does with no `button` block at all.
405
+ */
406
+ export interface ButtonConfig {
407
+ /** Opt in to click-to-start. Default `false`. */
408
+ enabled?: boolean;
409
+ /**
410
+ * Host-owned trigger — an element, or a selector resolved once at `init()`.
411
+ * When set the SDK renders no card of its own and `label`, `avatarUrl` and
412
+ * `description` are ignored. The SDK never moves or reparents the node; it
413
+ * sets `data-np-state`, toggles `disabled`, and hides it while a session is
414
+ * live, restoring it on end.
415
+ */
416
+ element?: HTMLElement | string;
417
+ /** Card text. Default: `"Talk to an agent"`. Ignored when `element` is set. */
418
+ label?: string;
419
+ /** Optional companion picture on the card. Ignored when `element` is set. */
420
+ avatarUrl?: string;
421
+ /** Supporting line under the label (Figma entry-point card). Ignored when `element` is set. */
422
+ description?: string;
423
+ }
424
+ /**
425
+ * Returned by `init()` in button mode. Nothing is connected when you receive it:
426
+ * the session starts on a click, or on `start()`.
427
+ */
428
+ export interface NapsterCompanionApiController {
429
+ /**
430
+ * The current session's instance: `null` before the first `start()` and after
431
+ * `end()`/`destroy()`, non-null from the moment an attempt gets past the
432
+ * microphone gate. Non-null does **not** mean the avatar is live — a denied
433
+ * microphone leaves the attempt parked behind the recovery card with an
434
+ * instance already handed back. Use `onAvatarReady` for "the session is up".
435
+ */
436
+ getInstance(): NapsterCompanionApiInstance | null;
437
+ /**
438
+ * Start a session, as if the trigger was clicked. Resolves with the instance once
439
+ * connected, or `null` if the attempt failed — the failure is reported through
440
+ * `onError` — or if the controller has already been destroyed. It never rejects:
441
+ * the click path has no caller to catch one.
442
+ */
443
+ start(): Promise<NapsterCompanionApiInstance | null>;
444
+ /** End the session. The trigger returns to idle and can start another. */
445
+ end(): void;
446
+ /** Remove the SDK card (or release the host's node) and tear down any session. */
447
+ destroy(): void;
448
+ }
449
+ /**
450
+ * Main configuration object passed to `init(getToken, config)`.
404
451
  * All fields are optional; sensible defaults are used by the SDK.
405
452
  */
406
453
  export interface NapsterCompanionApiConfig {
407
454
  /**
408
- * Connection transport. Only `"webrtc"` exists today — any other value is a
409
- * compile-time error. Reserved for future transports (e.g. WebSocket); until
410
- * then the SDK defaults to `"webrtc"` and there is no reason to set this.
455
+ * Connection transport. Optional — the SDK defaults to `"webrtc"`, which is
456
+ * the only transport that exists today, so there is no reason to set this
457
+ * yet. Any other value is a compile-time error, and an unsupported
458
+ * transport/modality combination is rejected at init() with a clear error.
459
+ *
460
+ * Reserved for future transports (e.g. WebSocket).
411
461
  */
412
462
  transport?: "webrtc";
413
463
  /**
414
- * Connection modality. Only `"video"` exists today — any other value is a
415
- * compile-time error. Reserved for future modalities (e.g. audio-only,
416
- * text); until then the SDK defaults to `"video"` and there is no reason to
417
- * set this.
464
+ * Connection modality. Optional — the SDK defaults to `"video"`, the only
465
+ * modality that exists today. Paired with {@link transport}: see that field
466
+ * for how invalid combinations are handled.
467
+ *
468
+ * Note this is the *connection* modality, not the UI being shown — how the
469
+ * session presents is a separate, runtime-changeable axis.
418
470
  */
419
471
  modality?: "video";
420
472
  /** Position of the avatar on screen. See `Position` enum. */
@@ -477,6 +529,8 @@ export interface NapsterCompanionApiConfig {
477
529
  * When on, `mountContainer` is ignored — the avatar must live in the top document.
478
530
  */
479
531
  persistence?: PersistenceOptions;
532
+ /** Click-to-start configuration. Omit for the default connect-immediately behaviour. */
533
+ button?: ButtonConfig;
480
534
  /** Lifecycle callbacks. All are optional. */
481
535
  /** Called when the SDK has finished initialization and is ready to render. */
482
536
  onReady?: () => void;
@@ -592,10 +646,26 @@ export interface NapsterCompanionApiInstance {
592
646
  */
593
647
  export interface NapsterCompanionApiSDK {
594
648
  /**
595
- * Initialize the SDK. `getToken` is called by the SDK itself once the microphone
596
- * permission has settled, so the connection token is always fresh when signaling
597
- * starts. A pre-minted token string is not accepted — minting it before the mic
598
- * prompt lets it go stale while the user is deciding.
649
+ * Initialize the SDK in click-to-start mode: resolves with a controller, and
650
+ * nothing connects until `start()` or a click on the entry point.
651
+ *
652
+ * `getToken` is called by the SDK itself once the microphone permission has
653
+ * settled — on every attempt, including a "Check again" retry — so the
654
+ * connection token is always fresh when signaling starts. A pre-minted token
655
+ * string is not accepted: minting it before the mic prompt lets it go stale
656
+ * while the user is deciding.
657
+ */
658
+ init(getToken: () => Promise<string>, config: Partial<NapsterCompanionApiConfig> & {
659
+ button: ButtonConfig & {
660
+ enabled: true;
661
+ };
662
+ }): Promise<NapsterCompanionApiController>;
663
+ /**
664
+ * Initialize the SDK and connect immediately: resolves once the session is up.
665
+ *
666
+ * `getToken` is called by the SDK itself once the microphone permission has
667
+ * settled, so the connection token is always fresh when signaling starts. A
668
+ * pre-minted token string is not accepted.
599
669
  */
600
670
  init(getToken: () => Promise<string>, config?: Partial<NapsterCompanionApiConfig>): Promise<NapsterCompanionApiInstance>;
601
671
  /** The SDK version string (useful for diagnostics). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@touchcastllc/napster-companion-api-dev",
3
- "version": "1.6.0-alpha.2",
3
+ "version": "1.6.0-alpha.3",
4
4
  "keywords": [
5
5
  "napster",
6
6
  "companion-api",