@docyrus/signin 0.12.0 → 0.14.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.
@@ -62,6 +62,25 @@ interface DocyrusAuthConfig {
62
62
  * Default: false.
63
63
  */
64
64
  syncRouteToHost?: boolean;
65
+ /**
66
+ * Iframe mode: let the host assistant (Guidy) inspect and drive this app's
67
+ * visible UI — scan its clickable elements, highlight/annotate them, and
68
+ * click them on the user's behalf — over the existing postMessage channel.
69
+ *
70
+ * Opt-in: the app must consent to being driven. The bridge only exposes
71
+ * already-visible interactive elements and only runs a fixed command
72
+ * vocabulary (scan / point / click); no arbitrary script is accepted from
73
+ * the host. No-op outside iframe mode. Default: false.
74
+ */
75
+ enableGuidyBridge?: boolean;
76
+ /**
77
+ * Iframe mode: routes the host assistant (Guidy) may navigate the user to
78
+ * inside this app. The host turns each into a deep link it can drive via the
79
+ * existing host→app `navigation` message. Update at runtime with
80
+ * `setGuidyRoutes` (e.g. when routes depend on permissions). Requires
81
+ * `enableGuidyBridge`. Default: none.
82
+ */
83
+ guidyRoutes?: GuidyRoute[];
65
84
  /** React Native: custom URI scheme redirect (e.g., 'myapp://auth/callback'). Required when forceMode is 'react-native' */
66
85
  nativeRedirectUri?: string;
67
86
  /** React Native: function to open an in-app browser auth session (e.g., WebBrowser.openAuthSessionAsync from expo-web-browser) */
@@ -119,6 +138,12 @@ interface DocyrusAuthContextValue {
119
138
  * subscriptions). No-op in non-iframe modes.
120
139
  */
121
140
  notifyRouteChange: (payload?: RouteChangePayload) => void;
141
+ /**
142
+ * Iframe mode (Guidy bridge): replace the routes the host assistant may
143
+ * navigate the user to inside this app. No-op unless `enableGuidyBridge`
144
+ * is set. Use for routes that depend on runtime state (e.g. permissions).
145
+ */
146
+ setGuidyRoutes: (routes: GuidyRoute[]) => void;
122
147
  /** Any error that occurred during auth */
123
148
  error: Error | null;
124
149
  }
@@ -185,6 +210,85 @@ interface HostNotificationMessage {
185
210
  type: 'notification';
186
211
  notification: DocyrusNotification;
187
212
  }
213
+ /**
214
+ * A visible, interactive element the host assistant (Guidy) can target by id.
215
+ * Mirrors the host-side clickable inventory so the model can reference real
216
+ * in-app buttons and links the same way it references shell chrome.
217
+ */
218
+ interface GuidyElement {
219
+ /** Stable DOM id used as the target for `guidy:point`. */
220
+ id: string;
221
+ /** Human-readable label (aria-label, text, or title). */
222
+ label: string;
223
+ /** Element kind, so the model can phrase guidance naturally. */
224
+ tag: 'a' | 'button';
225
+ }
226
+ /**
227
+ * App → Host: the embedded app's current clickable inventory.
228
+ * Pushed proactively on mount, route change, and DOM mutation so the host
229
+ * can keep a fresh snapshot without a request round-trip.
230
+ */
231
+ interface GuidyElementsMessage {
232
+ type: 'guidy:elements';
233
+ /** The app's current `location.pathname` when the scan was taken. */
234
+ path: string;
235
+ elements: GuidyElement[];
236
+ }
237
+ /**
238
+ * A navigable route the host assistant (Guidy) can send the user to. Unlike
239
+ * elements, routes cannot be auto-discovered from the DOM, so the app declares
240
+ * them (via `guidyRoutes` / `setGuidyRoutes`). The host turns these into deep
241
+ * links it can drive through the existing host→app `navigation` message.
242
+ */
243
+ interface GuidyRoute {
244
+ /** App-internal path, e.g. `/leads` or `leads/new`. */
245
+ path: string;
246
+ /** Human-readable label, e.g. `Leads`. */
247
+ label: string;
248
+ }
249
+ /**
250
+ * App → Host: the embedded app's declared navigable routes.
251
+ * Pushed on start and whenever the app updates its route catalog.
252
+ */
253
+ interface GuidyRoutesMessage {
254
+ type: 'guidy:routes';
255
+ routes: GuidyRoute[];
256
+ }
257
+ /**
258
+ * Host → App: scroll to, highlight, and optionally annotate/click an element.
259
+ * The app renders the highlight/annotation itself — the host cannot draw into
260
+ * a cross-origin iframe.
261
+ */
262
+ interface GuidyPointMessage {
263
+ type: 'guidy:point';
264
+ /** Target element id (must match a `GuidyElement.id`). */
265
+ id: string;
266
+ /** When true, dispatch a click after highlighting. Default: false. */
267
+ click?: boolean;
268
+ /** Optional short message shown in an annotation bubble near the element. */
269
+ message?: string;
270
+ }
271
+ /**
272
+ * Host → App: request a fresh element inventory. Used to recover from a late
273
+ * host mount that missed the app's proactive push. The app replies with a
274
+ * `guidy:elements` message.
275
+ */
276
+ interface GuidyScanMessage {
277
+ type: 'guidy:scan';
278
+ }
279
+ /** App → Host: result of a `guidy:point` command. */
280
+ interface GuidyPointAckMessage {
281
+ type: 'guidy:point-ack';
282
+ /** The id that was targeted. */
283
+ id: string;
284
+ /** Whether the element was found and acted upon. */
285
+ ok: boolean;
286
+ }
287
+ /** Host → App: commands the Guidy bridge runtime handles. */
288
+ type GuidyCommandMessage = GuidyPointMessage | GuidyScanMessage;
289
+ /** Handler invoked when the host sends a Guidy command. */
290
+ type GuidyCommandHandler = (message: GuidyCommandMessage) => void;
291
+ type AppToHostMessage = TokenRefreshRequestMessage | AppRouteChangeMessage | GuidyElementsMessage | GuidyRoutesMessage | GuidyPointAckMessage;
188
292
  /** Handler invoked when the host sends a navigation message */
189
293
  type HostNavigationHandler = (message: HostNavigationMessage) => void;
190
294
  /** Handler invoked when the host sends a notification message */
@@ -230,4 +334,4 @@ interface PermissionConfig {
230
334
  alwaysPermittedDataSources?: Record<string, AclOperation[]>;
231
335
  }
232
336
 
233
- export type { AclOperation as A, DocyrusAuthConfig as D, HostNavigationHandler as H, OpenAuthSessionFn as O, PermissionConfig as P, RouteChangePayload as R, TokenRefreshRequestMessage as T, AuthMode as a, AuthSessionResult as b, AuthStatus as c, DocyrusAclRule as d, DocyrusAuthContextValue as e, DocyrusRole as f, DocyrusUser as g, HostNotificationHandler as h, AppRouteChangeMessage as i, DocyrusNotification as j, HostNavigationMessage as k, HostNotificationMessage as l, HostSignInMessage as m };
337
+ export type { AclOperation as A, DocyrusAuthConfig as D, GuidyRoute as G, HostNavigationHandler as H, OpenAuthSessionFn as O, PermissionConfig as P, RouteChangePayload as R, TokenRefreshRequestMessage as T, AuthMode as a, AuthSessionResult as b, AuthStatus as c, DocyrusAclRule as d, DocyrusAuthContextValue as e, DocyrusRole as f, DocyrusUser as g, HostNotificationHandler as h, AppRouteChangeMessage as i, DocyrusNotification as j, GuidyCommandHandler as k, GuidyCommandMessage as l, GuidyElement as m, GuidyElementsMessage as n, GuidyPointAckMessage as o, GuidyPointMessage as p, GuidyRoutesMessage as q, GuidyScanMessage as r, HostNavigationMessage as s, HostNotificationMessage as t, HostSignInMessage as u, AppToHostMessage as v };
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { D as DocyrusAuthConfig, e as DocyrusAuthContextValue } from './types-DjG8tL1X.js';
3
+ import { D as DocyrusAuthConfig, e as DocyrusAuthContextValue } from './types-D4ZAVj-B.js';
4
4
  import { RestApiClient } from '@docyrus/api-client';
5
5
 
6
6
  interface DocyrusAuthProviderProps extends DocyrusAuthConfig {
@@ -1,8 +1,8 @@
1
1
  import * as vue from 'vue';
2
2
  import { PropType } from 'vue';
3
3
  import { OAuth2TokenStorage, OAuth2Tokens, RestApiClient } from '@docyrus/api-client';
4
- import { a as AuthMode, c as AuthStatus, H as HostNavigationHandler, h as HostNotificationHandler, R as RouteChangePayload } from '../types-DjG8tL1X.js';
5
- export { D as DocyrusAuthConfig } from '../types-DjG8tL1X.js';
4
+ import { a as AuthMode, c as AuthStatus, H as HostNavigationHandler, h as HostNotificationHandler, R as RouteChangePayload } from '../types-D4ZAVj-B.js';
5
+ export { D as DocyrusAuthConfig } from '../types-D4ZAVj-B.js';
6
6
 
7
7
  interface DocyrusAuthState {
8
8
  status: AuthStatus;
package/dist/vue/index.js CHANGED
@@ -168,6 +168,7 @@ var IframeAuth = class {
168
168
  onTokensReceived = null;
169
169
  navigationHandlers = /* @__PURE__ */ new Set();
170
170
  notificationHandlers = /* @__PURE__ */ new Set();
171
+ guidyHandlers = /* @__PURE__ */ new Set();
171
172
  routeSyncEnabled = false;
172
173
  originalPushState = null;
173
174
  originalReplaceState = null;
@@ -200,6 +201,7 @@ var IframeAuth = class {
200
201
  this.rejectPendingRefresh("IframeAuth stopped");
201
202
  this.navigationHandlers.clear();
202
203
  this.notificationHandlers.clear();
204
+ this.guidyHandlers.clear();
203
205
  this.teardownRouteSync();
204
206
  }
205
207
  /**
@@ -291,6 +293,25 @@ var IframeAuth = class {
291
293
  this.notificationHandlers.delete(handler);
292
294
  };
293
295
  }
296
+ /**
297
+ * Subscribe to host `guidy:*` command messages (point/scan).
298
+ * Returns an unsubscribe function. Used by the Guidy bridge runtime.
299
+ */
300
+ onGuidyCommand(handler) {
301
+ this.guidyHandlers.add(handler);
302
+ return () => {
303
+ this.guidyHandlers.delete(handler);
304
+ };
305
+ }
306
+ /**
307
+ * Post an app → host message over the same validated channel used for
308
+ * route-change and token-refresh. Used by the Guidy bridge to push its
309
+ * element inventory and point acknowledgements.
310
+ */
311
+ sendToHost(message) {
312
+ if (this.stopped) return;
313
+ postToHost(message);
314
+ }
294
315
  /**
295
316
  * Request fresh tokens from the host.
296
317
  * Posts a "token-refresh-request" to the host, then waits for
@@ -343,6 +364,19 @@ var IframeAuth = class {
343
364
  }
344
365
  if (data.type === "notification") {
345
366
  this.handleNotification(data);
367
+ return;
368
+ }
369
+ if (data.type === "guidy:point" || data.type === "guidy:scan") {
370
+ this.handleGuidyCommand(data);
371
+ }
372
+ }
373
+ handleGuidyCommand(message) {
374
+ for (const handler of this.guidyHandlers) {
375
+ try {
376
+ handler(message);
377
+ } catch (err) {
378
+ console.warn("[docyrus-signin] guidy command handler threw:", err);
379
+ }
346
380
  }
347
381
  }
348
382
  handleSignin(signinData) {
@@ -392,6 +426,250 @@ var IframeAuth = class {
392
426
  }
393
427
  };
394
428
 
429
+ // src/core/guidy-bridge.ts
430
+ var GUIDY_INTERNAL_PREFIX = "guidy-";
431
+ var HIGHLIGHT_CLASS = "guidy-bridge-highlight";
432
+ var HIGHLIGHT_STYLE_ID = "guidy-bridge-style";
433
+ var ANNOTATION_ID = "guidy-bridge-annotation";
434
+ var HIGHLIGHT_DURATION_MS = 5200;
435
+ var SCAN_DEBOUNCE_MS = 250;
436
+ var CLICK_DELAY_MS = 450;
437
+ function elementLabel(node) {
438
+ const aria = node.getAttribute("aria-label")?.trim();
439
+ if (aria) return aria;
440
+ const text = node.textContent?.replace(/\s+/g, " ").trim();
441
+ if (text) return text;
442
+ return node.getAttribute("title")?.trim() ?? "";
443
+ }
444
+ function isVisible(node) {
445
+ const rect = node.getBoundingClientRect();
446
+ if (rect.width === 0 && rect.height === 0) return false;
447
+ const style = window.getComputedStyle(node);
448
+ return style.visibility !== "hidden" && style.display !== "none";
449
+ }
450
+ var GuidyBridge = class {
451
+ send;
452
+ routes;
453
+ started = false;
454
+ observer = null;
455
+ scanTimer = null;
456
+ routeListener = null;
457
+ highlightTimer = null;
458
+ clickTimer = null;
459
+ annotationTimer = null;
460
+ constructor(send, routes = []) {
461
+ this.send = send;
462
+ this.routes = routes;
463
+ }
464
+ /** Replace the declared navigable routes and re-post them to the host. */
465
+ setRoutes(routes) {
466
+ this.routes = routes;
467
+ this.postRoutes();
468
+ }
469
+ /**
470
+ * Begin reporting the element inventory and watching for changes.
471
+ * Idempotent. No-op outside a browser document.
472
+ */
473
+ start() {
474
+ if (this.started || typeof document === "undefined") return;
475
+ this.started = true;
476
+ this.ensureStyle();
477
+ this.postElements();
478
+ this.postRoutes();
479
+ this.observer = new MutationObserver(() => this.scheduleScan());
480
+ this.observer.observe(document.body, {
481
+ childList: true,
482
+ subtree: true,
483
+ attributes: true,
484
+ attributeFilter: [
485
+ "id",
486
+ "hidden",
487
+ "aria-label",
488
+ "title",
489
+ "style"
490
+ ]
491
+ });
492
+ this.routeListener = () => this.scheduleScan();
493
+ window.addEventListener("popstate", this.routeListener);
494
+ window.addEventListener("hashchange", this.routeListener);
495
+ }
496
+ /** Stop watching and tear down any injected overlay. Idempotent. */
497
+ stop() {
498
+ if (!this.started) return;
499
+ this.started = false;
500
+ this.observer?.disconnect();
501
+ this.observer = null;
502
+ if (this.routeListener) {
503
+ window.removeEventListener("popstate", this.routeListener);
504
+ window.removeEventListener("hashchange", this.routeListener);
505
+ this.routeListener = null;
506
+ }
507
+ this.clearTimer("scanTimer");
508
+ this.clearTimer("highlightTimer");
509
+ this.clearTimer("clickTimer");
510
+ this.clearTimer("annotationTimer");
511
+ this.clearHighlight();
512
+ this.clearAnnotation();
513
+ }
514
+ /** Dispatch a host `guidy:*` command. Wired to `IframeAuth.onGuidyCommand`. */
515
+ handleCommand(message) {
516
+ if (message.type === "guidy:scan") {
517
+ this.postElements();
518
+ this.postRoutes();
519
+ return;
520
+ }
521
+ if (message.type === "guidy:point") {
522
+ this.handlePoint(message);
523
+ }
524
+ }
525
+ /** Collect every visible anchor/button that exposes an id and a label. */
526
+ collectElements() {
527
+ if (typeof document === "undefined") return [];
528
+ const nodes = document.querySelectorAll("a[id], button[id]");
529
+ const seen = /* @__PURE__ */ new Set();
530
+ const result = [];
531
+ nodes.forEach((node) => {
532
+ const { id } = node;
533
+ if (!id || id.startsWith(GUIDY_INTERNAL_PREFIX) || seen.has(id)) return;
534
+ if (!isVisible(node)) return;
535
+ const label = elementLabel(node);
536
+ if (!label) return;
537
+ seen.add(id);
538
+ result.push({
539
+ id,
540
+ label,
541
+ tag: node.tagName.toLowerCase() === "a" ? "a" : "button"
542
+ });
543
+ });
544
+ return result;
545
+ }
546
+ postElements() {
547
+ if (!this.started) return;
548
+ const path = typeof window === "undefined" ? "" : window.location.pathname;
549
+ this.send({
550
+ type: "guidy:elements",
551
+ path,
552
+ elements: this.collectElements()
553
+ });
554
+ }
555
+ postRoutes() {
556
+ if (!this.started) return;
557
+ this.send({ type: "guidy:routes", routes: this.routes });
558
+ }
559
+ scheduleScan() {
560
+ if (this.scanTimer) return;
561
+ this.scanTimer = setTimeout(() => {
562
+ this.scanTimer = null;
563
+ this.postElements();
564
+ }, SCAN_DEBOUNCE_MS);
565
+ }
566
+ handlePoint(message) {
567
+ const element = typeof document === "undefined" ? null : document.getElementById(message.id);
568
+ if (!element) {
569
+ this.send({ type: "guidy:point-ack", id: message.id, ok: false });
570
+ return;
571
+ }
572
+ element.scrollIntoView({ block: "center", behavior: "smooth" });
573
+ this.highlight(element);
574
+ if (message.message) {
575
+ this.annotate(element, message.message);
576
+ }
577
+ if (message.click) {
578
+ this.clearTimer("clickTimer");
579
+ this.clickTimer = setTimeout(() => {
580
+ this.clickTimer = null;
581
+ element.click();
582
+ }, CLICK_DELAY_MS);
583
+ }
584
+ this.send({ type: "guidy:point-ack", id: message.id, ok: true });
585
+ }
586
+ ensureStyle() {
587
+ if (typeof document === "undefined") return;
588
+ if (document.getElementById(HIGHLIGHT_STYLE_ID)) return;
589
+ const style = document.createElement("style");
590
+ style.id = HIGHLIGHT_STYLE_ID;
591
+ style.textContent = `
592
+ .${HIGHLIGHT_CLASS} {
593
+ outline: 2px solid #3b82f6 !important;
594
+ outline-offset: 2px;
595
+ border-radius: 8px;
596
+ animation: guidy-bridge-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
597
+ }
598
+ @keyframes guidy-bridge-ping {
599
+ 0% {
600
+ box-shadow: 0 0 0 0 color-mix(in srgb, #3b82f6 50%, transparent);
601
+ }
602
+ 75%, 100% {
603
+ box-shadow: 0 0 0 10px color-mix(in srgb, #3b82f6 0%, transparent);
604
+ }
605
+ }
606
+ #${ANNOTATION_ID} {
607
+ position: fixed;
608
+ z-index: 2147483647;
609
+ max-width: 240px;
610
+ padding: 8px 12px;
611
+ border-radius: 10px;
612
+ background: #111827;
613
+ color: #f9fafb;
614
+ font: 13px/1.4 system-ui, -apple-system, sans-serif;
615
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
616
+ pointer-events: none;
617
+ }
618
+ `;
619
+ document.head.appendChild(style);
620
+ }
621
+ highlight(element) {
622
+ this.clearTimer("highlightTimer");
623
+ this.clearHighlight();
624
+ element.classList.add(HIGHLIGHT_CLASS);
625
+ this.highlightTimer = setTimeout(() => {
626
+ this.highlightTimer = null;
627
+ this.clearHighlight();
628
+ }, HIGHLIGHT_DURATION_MS);
629
+ }
630
+ clearHighlight() {
631
+ if (typeof document === "undefined") return;
632
+ document.querySelectorAll(`.${HIGHLIGHT_CLASS}`).forEach((node) => node.classList.remove(HIGHLIGHT_CLASS));
633
+ }
634
+ annotate(element, message) {
635
+ if (typeof document === "undefined") return;
636
+ this.clearTimer("annotationTimer");
637
+ this.clearAnnotation();
638
+ const bubble = document.createElement("div");
639
+ bubble.id = ANNOTATION_ID;
640
+ bubble.textContent = message;
641
+ document.body.appendChild(bubble);
642
+ const rect = element.getBoundingClientRect();
643
+ const bubbleRect = bubble.getBoundingClientRect();
644
+ const gap = 10;
645
+ let top = rect.bottom + gap;
646
+ if (top + bubbleRect.height > window.innerHeight) {
647
+ top = Math.max(gap, rect.top - bubbleRect.height - gap);
648
+ }
649
+ const left = Math.min(
650
+ Math.max(gap, rect.left),
651
+ window.innerWidth - bubbleRect.width - gap
652
+ );
653
+ bubble.style.top = `${Math.round(top)}px`;
654
+ bubble.style.left = `${Math.round(left)}px`;
655
+ this.annotationTimer = setTimeout(() => {
656
+ this.annotationTimer = null;
657
+ this.clearAnnotation();
658
+ }, HIGHLIGHT_DURATION_MS);
659
+ }
660
+ clearAnnotation() {
661
+ if (typeof document === "undefined") return;
662
+ document.getElementById(ANNOTATION_ID)?.remove();
663
+ }
664
+ clearTimer(key) {
665
+ const timer = this[key];
666
+ if (timer) {
667
+ clearTimeout(timer);
668
+ this[key] = null;
669
+ }
670
+ }
671
+ };
672
+
395
673
  // src/core/sso-auth.ts
396
674
  var SsoAuth = class {
397
675
  config;
@@ -552,6 +830,7 @@ var AuthManager = class {
552
830
  user = null;
553
831
  standaloneAuth = null;
554
832
  iframeAuth = null;
833
+ guidyBridge = null;
555
834
  reactNativeAuth = null;
556
835
  tokenRefreshTimer = null;
557
836
  listeners = /* @__PURE__ */ new Set();
@@ -716,6 +995,31 @@ var AuthManager = class {
716
995
  if (this.config.syncRouteToHost) {
717
996
  this.iframeAuth.enableRouteSync();
718
997
  }
998
+ if (this.config.enableGuidyBridge) {
999
+ this.startGuidyBridge();
1000
+ }
1001
+ }
1002
+ /**
1003
+ * Start the Guidy bridge runtime: report the app's clickable inventory to
1004
+ * the host and execute host scan/point/click commands. Iframe mode only.
1005
+ */
1006
+ startGuidyBridge() {
1007
+ if (!this.iframeAuth || this.guidyBridge) return;
1008
+ const bridge = new GuidyBridge(
1009
+ (message) => this.iframeAuth?.sendToHost(message),
1010
+ this.config.guidyRoutes ?? []
1011
+ );
1012
+ this.iframeAuth.onGuidyCommand((message) => bridge.handleCommand(message));
1013
+ bridge.start();
1014
+ this.guidyBridge = bridge;
1015
+ }
1016
+ /**
1017
+ * Iframe mode: replace the routes the Guidy bridge advertises to the host.
1018
+ * No-op unless the bridge is running (`enableGuidyBridge`).
1019
+ */
1020
+ setGuidyRoutes(routes) {
1021
+ this.config.guidyRoutes = routes;
1022
+ this.guidyBridge?.setRoutes(routes);
719
1023
  }
720
1024
  /**
721
1025
  * Iframe/WebView mode: start auto-syncing the embedded app's route
@@ -850,6 +1154,10 @@ var AuthManager = class {
850
1154
  await this.reactNativeAuth.logout();
851
1155
  }
852
1156
  if (this.mode === "iframe" && this.iframeAuth) {
1157
+ if (this.guidyBridge) {
1158
+ this.guidyBridge.stop();
1159
+ this.guidyBridge = null;
1160
+ }
853
1161
  this.iframeAuth.stop();
854
1162
  }
855
1163
  if (this.config.ssr) {
@@ -1020,6 +1328,10 @@ var AuthManager = class {
1020
1328
  /** Cleanup: remove listeners, timers, stop iframe auth. */
1021
1329
  destroy() {
1022
1330
  this.clearTokenRefreshTimer();
1331
+ if (this.guidyBridge) {
1332
+ this.guidyBridge.stop();
1333
+ this.guidyBridge = null;
1334
+ }
1023
1335
  if (this.iframeAuth) this.iframeAuth.stop();
1024
1336
  this.listeners.clear();
1025
1337
  this.navigationHandlers.clear();