@docyrus/signin 0.12.0 → 0.13.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.
@@ -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-WOgdg9b0.js';
5
+ export { D as DocyrusAuthConfig } from '../types-WOgdg9b0.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,237 @@ 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
+ started = false;
453
+ observer = null;
454
+ scanTimer = null;
455
+ routeListener = null;
456
+ highlightTimer = null;
457
+ clickTimer = null;
458
+ annotationTimer = null;
459
+ constructor(send) {
460
+ this.send = send;
461
+ }
462
+ /**
463
+ * Begin reporting the element inventory and watching for changes.
464
+ * Idempotent. No-op outside a browser document.
465
+ */
466
+ start() {
467
+ if (this.started || typeof document === "undefined") return;
468
+ this.started = true;
469
+ this.ensureStyle();
470
+ this.postElements();
471
+ this.observer = new MutationObserver(() => this.scheduleScan());
472
+ this.observer.observe(document.body, {
473
+ childList: true,
474
+ subtree: true,
475
+ attributes: true,
476
+ attributeFilter: [
477
+ "id",
478
+ "hidden",
479
+ "aria-label",
480
+ "title",
481
+ "style"
482
+ ]
483
+ });
484
+ this.routeListener = () => this.scheduleScan();
485
+ window.addEventListener("popstate", this.routeListener);
486
+ window.addEventListener("hashchange", this.routeListener);
487
+ }
488
+ /** Stop watching and tear down any injected overlay. Idempotent. */
489
+ stop() {
490
+ if (!this.started) return;
491
+ this.started = false;
492
+ this.observer?.disconnect();
493
+ this.observer = null;
494
+ if (this.routeListener) {
495
+ window.removeEventListener("popstate", this.routeListener);
496
+ window.removeEventListener("hashchange", this.routeListener);
497
+ this.routeListener = null;
498
+ }
499
+ this.clearTimer("scanTimer");
500
+ this.clearTimer("highlightTimer");
501
+ this.clearTimer("clickTimer");
502
+ this.clearTimer("annotationTimer");
503
+ this.clearHighlight();
504
+ this.clearAnnotation();
505
+ }
506
+ /** Dispatch a host `guidy:*` command. Wired to `IframeAuth.onGuidyCommand`. */
507
+ handleCommand(message) {
508
+ if (message.type === "guidy:scan") {
509
+ this.postElements();
510
+ return;
511
+ }
512
+ if (message.type === "guidy:point") {
513
+ this.handlePoint(message);
514
+ }
515
+ }
516
+ /** Collect every visible anchor/button that exposes an id and a label. */
517
+ collectElements() {
518
+ if (typeof document === "undefined") return [];
519
+ const nodes = document.querySelectorAll("a[id], button[id]");
520
+ const seen = /* @__PURE__ */ new Set();
521
+ const result = [];
522
+ nodes.forEach((node) => {
523
+ const { id } = node;
524
+ if (!id || id.startsWith(GUIDY_INTERNAL_PREFIX) || seen.has(id)) return;
525
+ if (!isVisible(node)) return;
526
+ const label = elementLabel(node);
527
+ if (!label) return;
528
+ seen.add(id);
529
+ result.push({
530
+ id,
531
+ label,
532
+ tag: node.tagName.toLowerCase() === "a" ? "a" : "button"
533
+ });
534
+ });
535
+ return result;
536
+ }
537
+ postElements() {
538
+ if (!this.started) return;
539
+ const path = typeof window === "undefined" ? "" : window.location.pathname;
540
+ this.send({
541
+ type: "guidy:elements",
542
+ path,
543
+ elements: this.collectElements()
544
+ });
545
+ }
546
+ scheduleScan() {
547
+ if (this.scanTimer) return;
548
+ this.scanTimer = setTimeout(() => {
549
+ this.scanTimer = null;
550
+ this.postElements();
551
+ }, SCAN_DEBOUNCE_MS);
552
+ }
553
+ handlePoint(message) {
554
+ const element = typeof document === "undefined" ? null : document.getElementById(message.id);
555
+ if (!element) {
556
+ this.send({ type: "guidy:point-ack", id: message.id, ok: false });
557
+ return;
558
+ }
559
+ element.scrollIntoView({ block: "center", behavior: "smooth" });
560
+ this.highlight(element);
561
+ if (message.message) {
562
+ this.annotate(element, message.message);
563
+ }
564
+ if (message.click) {
565
+ this.clearTimer("clickTimer");
566
+ this.clickTimer = setTimeout(() => {
567
+ this.clickTimer = null;
568
+ element.click();
569
+ }, CLICK_DELAY_MS);
570
+ }
571
+ this.send({ type: "guidy:point-ack", id: message.id, ok: true });
572
+ }
573
+ ensureStyle() {
574
+ if (typeof document === "undefined") return;
575
+ if (document.getElementById(HIGHLIGHT_STYLE_ID)) return;
576
+ const style = document.createElement("style");
577
+ style.id = HIGHLIGHT_STYLE_ID;
578
+ style.textContent = `
579
+ .${HIGHLIGHT_CLASS} {
580
+ outline: 2px solid #3b82f6 !important;
581
+ outline-offset: 2px;
582
+ border-radius: 8px;
583
+ animation: guidy-bridge-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
584
+ }
585
+ @keyframes guidy-bridge-ping {
586
+ 0% {
587
+ box-shadow: 0 0 0 0 color-mix(in srgb, #3b82f6 50%, transparent);
588
+ }
589
+ 75%, 100% {
590
+ box-shadow: 0 0 0 10px color-mix(in srgb, #3b82f6 0%, transparent);
591
+ }
592
+ }
593
+ #${ANNOTATION_ID} {
594
+ position: fixed;
595
+ z-index: 2147483647;
596
+ max-width: 240px;
597
+ padding: 8px 12px;
598
+ border-radius: 10px;
599
+ background: #111827;
600
+ color: #f9fafb;
601
+ font: 13px/1.4 system-ui, -apple-system, sans-serif;
602
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
603
+ pointer-events: none;
604
+ }
605
+ `;
606
+ document.head.appendChild(style);
607
+ }
608
+ highlight(element) {
609
+ this.clearTimer("highlightTimer");
610
+ this.clearHighlight();
611
+ element.classList.add(HIGHLIGHT_CLASS);
612
+ this.highlightTimer = setTimeout(() => {
613
+ this.highlightTimer = null;
614
+ this.clearHighlight();
615
+ }, HIGHLIGHT_DURATION_MS);
616
+ }
617
+ clearHighlight() {
618
+ if (typeof document === "undefined") return;
619
+ document.querySelectorAll(`.${HIGHLIGHT_CLASS}`).forEach((node) => node.classList.remove(HIGHLIGHT_CLASS));
620
+ }
621
+ annotate(element, message) {
622
+ if (typeof document === "undefined") return;
623
+ this.clearTimer("annotationTimer");
624
+ this.clearAnnotation();
625
+ const bubble = document.createElement("div");
626
+ bubble.id = ANNOTATION_ID;
627
+ bubble.textContent = message;
628
+ document.body.appendChild(bubble);
629
+ const rect = element.getBoundingClientRect();
630
+ const bubbleRect = bubble.getBoundingClientRect();
631
+ const gap = 10;
632
+ let top = rect.bottom + gap;
633
+ if (top + bubbleRect.height > window.innerHeight) {
634
+ top = Math.max(gap, rect.top - bubbleRect.height - gap);
635
+ }
636
+ const left = Math.min(
637
+ Math.max(gap, rect.left),
638
+ window.innerWidth - bubbleRect.width - gap
639
+ );
640
+ bubble.style.top = `${Math.round(top)}px`;
641
+ bubble.style.left = `${Math.round(left)}px`;
642
+ this.annotationTimer = setTimeout(() => {
643
+ this.annotationTimer = null;
644
+ this.clearAnnotation();
645
+ }, HIGHLIGHT_DURATION_MS);
646
+ }
647
+ clearAnnotation() {
648
+ if (typeof document === "undefined") return;
649
+ document.getElementById(ANNOTATION_ID)?.remove();
650
+ }
651
+ clearTimer(key) {
652
+ const timer = this[key];
653
+ if (timer) {
654
+ clearTimeout(timer);
655
+ this[key] = null;
656
+ }
657
+ }
658
+ };
659
+
395
660
  // src/core/sso-auth.ts
396
661
  var SsoAuth = class {
397
662
  config;
@@ -552,6 +817,7 @@ var AuthManager = class {
552
817
  user = null;
553
818
  standaloneAuth = null;
554
819
  iframeAuth = null;
820
+ guidyBridge = null;
555
821
  reactNativeAuth = null;
556
822
  tokenRefreshTimer = null;
557
823
  listeners = /* @__PURE__ */ new Set();
@@ -716,6 +982,20 @@ var AuthManager = class {
716
982
  if (this.config.syncRouteToHost) {
717
983
  this.iframeAuth.enableRouteSync();
718
984
  }
985
+ if (this.config.enableGuidyBridge) {
986
+ this.startGuidyBridge();
987
+ }
988
+ }
989
+ /**
990
+ * Start the Guidy bridge runtime: report the app's clickable inventory to
991
+ * the host and execute host scan/point/click commands. Iframe mode only.
992
+ */
993
+ startGuidyBridge() {
994
+ if (!this.iframeAuth || this.guidyBridge) return;
995
+ const bridge = new GuidyBridge((message) => this.iframeAuth?.sendToHost(message));
996
+ this.iframeAuth.onGuidyCommand((message) => bridge.handleCommand(message));
997
+ bridge.start();
998
+ this.guidyBridge = bridge;
719
999
  }
720
1000
  /**
721
1001
  * Iframe/WebView mode: start auto-syncing the embedded app's route
@@ -850,6 +1130,10 @@ var AuthManager = class {
850
1130
  await this.reactNativeAuth.logout();
851
1131
  }
852
1132
  if (this.mode === "iframe" && this.iframeAuth) {
1133
+ if (this.guidyBridge) {
1134
+ this.guidyBridge.stop();
1135
+ this.guidyBridge = null;
1136
+ }
853
1137
  this.iframeAuth.stop();
854
1138
  }
855
1139
  if (this.config.ssr) {
@@ -1020,6 +1304,10 @@ var AuthManager = class {
1020
1304
  /** Cleanup: remove listeners, timers, stop iframe auth. */
1021
1305
  destroy() {
1022
1306
  this.clearTokenRefreshTimer();
1307
+ if (this.guidyBridge) {
1308
+ this.guidyBridge.stop();
1309
+ this.guidyBridge = null;
1310
+ }
1023
1311
  if (this.iframeAuth) this.iframeAuth.stop();
1024
1312
  this.listeners.clear();
1025
1313
  this.navigationHandlers.clear();