@docyrus/signin 0.14.1 → 0.16.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,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-D4ZAVj-B.js';
3
+ import { D as DocyrusAuthConfig, f as DocyrusAuthContextValue } from './types-C_i-KhUS.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-D4ZAVj-B.js';
5
- export { D as DocyrusAuthConfig } from '../types-D4ZAVj-B.js';
4
+ import { b as AuthMode, d as AuthStatus, H as HostNavigationHandler, s as HostNotificationHandler, R as RouteChangePayload, t as HostNavigationRequestOptions, k as DocyrusSharePayload, h as DocyrusEmailPayload, g as DocyrusCalendarEventPayload, n as MsGraphClient } from '../types-C_i-KhUS.js';
5
+ export { a as AdaptiveCard, D as DocyrusAuthConfig, j as DocyrusShareAdaptiveCardPayload, l as DocyrusShareTextPayload, M as MsGraphAccount, o as MsGraphRequest, p as MsGraphRequestOptions, q as MsGraphResponse, r as MsGraphStatus } from '../types-C_i-KhUS.js';
6
6
 
7
7
  interface DocyrusAuthState {
8
8
  status: AuthStatus;
@@ -18,6 +18,12 @@ interface DocyrusAuthState {
18
18
  onHostNotification: (handler: HostNotificationHandler) => () => void;
19
19
  enableHostRouteSync: () => void;
20
20
  notifyRouteChange: (payload?: RouteChangePayload) => void;
21
+ requestHostNavigation: (url: string, options?: HostNavigationRequestOptions) => void;
22
+ sendToDocy: (payload: DocyrusSharePayload) => Promise<void>;
23
+ sendToChat: (payload: DocyrusSharePayload) => Promise<void>;
24
+ sendToEmail: (payload: DocyrusEmailPayload) => Promise<void>;
25
+ sendToCalendar: (payload: DocyrusCalendarEventPayload) => Promise<void>;
26
+ msGraph: MsGraphClient | null;
21
27
  }
22
28
  /**
23
29
  * Vue composable to access Docyrus auth state.
@@ -201,4 +207,4 @@ declare const SignInButton: vue.DefineComponent<vue.ExtractPropTypes<{
201
207
  disabled: boolean;
202
208
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
203
209
 
204
- export { AuthMode, AuthStatus, DocyrusAuthProvider, type DocyrusAuthState, SignInButton, getDocyrusAuth, getDocyrusClient, useDocyrusAuth, useDocyrusClient };
210
+ export { AuthMode, AuthStatus, DocyrusAuthProvider, type DocyrusAuthState, DocyrusCalendarEventPayload, DocyrusEmailPayload, DocyrusSharePayload, MsGraphClient, SignInButton, getDocyrusAuth, getDocyrusClient, useDocyrusAuth, useDocyrusClient };
package/dist/vue/index.js CHANGED
@@ -17,6 +17,8 @@ var DEFAULT_ALLOWED_HOST_PATTERN = /^https:\/\/[^/]+\.docyrus\.app$/;
17
17
  var REDIRECT_RETURN_KEY = "docyrus_auth_return_url";
18
18
  var TOKEN_EXPIRY_BUFFER_SECONDS = 60;
19
19
  var IFRAME_TOKEN_REFRESH_TIMEOUT_MS = 1e4;
20
+ var HOST_ACTION_TIMEOUT_MS = 15e3;
21
+ var MSGRAPH_REQUEST_TIMEOUT_MS = 3e4;
20
22
  var SSO_TOKEN_PARAM = "sso_token";
21
23
 
22
24
  // src/core/auth-detector.ts
@@ -190,6 +192,13 @@ var IframeAuth = class {
190
192
  stopped = false;
191
193
  refreshPromise = null;
192
194
  messageHandler = null;
195
+ /**
196
+ * In-flight app→host requests awaiting a correlated host reply, keyed by
197
+ * requestId. Powers Send to Docy / Send to Chat / the MS Graph bridge.
198
+ */
199
+ pendingRequests = /* @__PURE__ */ new Map();
200
+ /** Fallback monotonic counter for request ids when crypto.randomUUID is absent. */
201
+ requestCounter = 0;
193
202
  constructor(allowedOrigins, allowedPattern) {
194
203
  this.allowedOrigins = allowedOrigins ?? [];
195
204
  this.allowedPattern = allowedPattern ?? DEFAULT_ALLOWED_HOST_PATTERN;
@@ -213,6 +222,7 @@ var IframeAuth = class {
213
222
  this.messageHandler = null;
214
223
  }
215
224
  this.rejectPendingRefresh("IframeAuth stopped");
225
+ this.rejectAllPendingRequests("IframeAuth stopped");
216
226
  this.navigationHandlers.clear();
217
227
  this.notificationHandlers.clear();
218
228
  this.guidyHandlers.clear();
@@ -271,6 +281,19 @@ var IframeAuth = class {
271
281
  url: `${path}${search}${hash}`
272
282
  });
273
283
  }
284
+ /**
285
+ * Ask the host shell to navigate to a path/URL. The reverse of the
286
+ * host → app `navigation` message: posts a `navigation-request` over the
287
+ * same validated channel. The host decides how to honour it.
288
+ */
289
+ requestHostNavigation(url, options) {
290
+ if (this.stopped) return;
291
+ if (typeof url !== "string" || url.length === 0) return;
292
+ const message = { type: "navigation-request", url };
293
+ if (options?.replace) message.replace = true;
294
+ if (options?.newTab) message.newTab = true;
295
+ this.sendToHost(message);
296
+ }
274
297
  teardownRouteSync() {
275
298
  if (!this.routeSyncEnabled) return;
276
299
  if (typeof window !== "undefined") {
@@ -326,6 +349,119 @@ var IframeAuth = class {
326
349
  if (this.stopped) return;
327
350
  postToHost(message);
328
351
  }
352
+ /**
353
+ * Hand a payload to the host AI assistant (Docy). Resolves when the host
354
+ * acknowledges delivery, rejects on host error or timeout.
355
+ */
356
+ sendToDocy(payload) {
357
+ const requestId = this.nextRequestId();
358
+ return this.request(
359
+ { type: "docy:send", requestId, payload },
360
+ HOST_ACTION_TIMEOUT_MS
361
+ );
362
+ }
363
+ /**
364
+ * Hand a payload to the host team-chat app. Resolves when the host
365
+ * acknowledges delivery, rejects on host error or timeout.
366
+ */
367
+ sendToChat(payload) {
368
+ const requestId = this.nextRequestId();
369
+ return this.request(
370
+ { type: "chat:send", requestId, payload },
371
+ HOST_ACTION_TIMEOUT_MS
372
+ );
373
+ }
374
+ /**
375
+ * Hand a draft email to the host. Resolves when the host acknowledges,
376
+ * rejects on host error or timeout.
377
+ */
378
+ sendToEmail(payload) {
379
+ const requestId = this.nextRequestId();
380
+ return this.request(
381
+ { type: "email:send", requestId, payload },
382
+ HOST_ACTION_TIMEOUT_MS
383
+ );
384
+ }
385
+ /**
386
+ * Hand a calendar event to the host. Resolves when the host acknowledges,
387
+ * rejects on host error or timeout.
388
+ */
389
+ sendToCalendar(payload) {
390
+ const requestId = this.nextRequestId();
391
+ return this.request(
392
+ { type: "calendar:send", requestId, payload },
393
+ HOST_ACTION_TIMEOUT_MS
394
+ );
395
+ }
396
+ /** Ask the host whether its MSAL session is signed in. */
397
+ requestMsGraphStatus() {
398
+ const requestId = this.nextRequestId();
399
+ return this.request(
400
+ { type: "msgraph:status-request", requestId },
401
+ HOST_ACTION_TIMEOUT_MS
402
+ );
403
+ }
404
+ /** Perform a Microsoft Graph request through the host's MSAL session. */
405
+ requestMsGraph(request) {
406
+ const requestId = this.nextRequestId();
407
+ return this.request(
408
+ { type: "msgraph:request", requestId, request },
409
+ MSGRAPH_REQUEST_TIMEOUT_MS
410
+ );
411
+ }
412
+ /**
413
+ * Post a correlated app→host request and await the matching host reply.
414
+ * The reply is matched by `requestId` in `handleMessage`. Rejects on timeout
415
+ * or when the bridge is stopped.
416
+ */
417
+ request(message, timeoutMs) {
418
+ if (this.stopped) {
419
+ return Promise.reject(new Error("Cannot send host request: iframe bridge stopped"));
420
+ }
421
+ const { requestId } = message;
422
+ return new Promise((resolve, reject) => {
423
+ const timeoutId = setTimeout(() => {
424
+ this.pendingRequests.delete(requestId);
425
+ reject(new Error(`Host request "${message.type}" timed out`));
426
+ }, timeoutMs);
427
+ this.pendingRequests.set(requestId, {
428
+ resolve,
429
+ reject,
430
+ timeoutId
431
+ });
432
+ this.sendToHost(message);
433
+ });
434
+ }
435
+ /** Generate a correlation id, preferring crypto.randomUUID when available. */
436
+ nextRequestId() {
437
+ const cryptoObj = typeof crypto !== "undefined" ? crypto : void 0;
438
+ if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
439
+ return cryptoObj.randomUUID();
440
+ }
441
+ this.requestCounter += 1;
442
+ return `req-${Date.now().toString(36)}-${this.requestCounter}-${Math.random().toString(36).slice(2, 10)}`;
443
+ }
444
+ resolvePendingRequest(requestId, value) {
445
+ const pending = this.pendingRequests.get(requestId);
446
+ if (!pending) return;
447
+ clearTimeout(pending.timeoutId);
448
+ this.pendingRequests.delete(requestId);
449
+ pending.resolve(value);
450
+ }
451
+ rejectPendingRequest(requestId, error) {
452
+ const pending = this.pendingRequests.get(requestId);
453
+ if (!pending) return;
454
+ clearTimeout(pending.timeoutId);
455
+ this.pendingRequests.delete(requestId);
456
+ pending.reject(error);
457
+ }
458
+ rejectAllPendingRequests(reason) {
459
+ for (const pending of this.pendingRequests.values()) {
460
+ clearTimeout(pending.timeoutId);
461
+ pending.reject(new Error(reason));
462
+ }
463
+ this.pendingRequests.clear();
464
+ }
329
465
  /**
330
466
  * Request fresh tokens from the host.
331
467
  * Posts a "token-refresh-request" to the host, then waits for
@@ -382,8 +518,57 @@ var IframeAuth = class {
382
518
  }
383
519
  if (data.type === "guidy:point" || data.type === "guidy:scan") {
384
520
  this.handleGuidyCommand(data);
521
+ return;
522
+ }
523
+ if (data.type === "docy:send-ack" || data.type === "chat:send-ack" || data.type === "email:send-ack" || data.type === "calendar:send-ack") {
524
+ this.handleActionAck(data);
525
+ return;
526
+ }
527
+ if (data.type === "msgraph:status-response") {
528
+ this.handleMsGraphStatusResponse(data);
529
+ return;
530
+ }
531
+ if (data.type === "msgraph:response") {
532
+ this.handleMsGraphResponse(data);
385
533
  }
386
534
  }
535
+ handleActionAck(message) {
536
+ if (typeof message.requestId !== "string") return;
537
+ if (message.ok) {
538
+ this.resolvePendingRequest(message.requestId, void 0);
539
+ } else {
540
+ this.rejectPendingRequest(
541
+ message.requestId,
542
+ new Error(message.error || `Host rejected ${message.type}`)
543
+ );
544
+ }
545
+ }
546
+ handleMsGraphStatusResponse(message) {
547
+ if (typeof message.requestId !== "string") return;
548
+ if (message.error) {
549
+ this.rejectPendingRequest(message.requestId, new Error(message.error));
550
+ return;
551
+ }
552
+ const status = {
553
+ signedIn: !!message.signedIn,
554
+ account: message.account ?? null
555
+ };
556
+ this.resolvePendingRequest(message.requestId, status);
557
+ }
558
+ handleMsGraphResponse(message) {
559
+ if (typeof message.requestId !== "string") return;
560
+ if (message.error && typeof message.status !== "number") {
561
+ this.rejectPendingRequest(message.requestId, new Error(message.error));
562
+ return;
563
+ }
564
+ const response = {
565
+ ok: !!message.ok,
566
+ status: typeof message.status === "number" ? message.status : 0,
567
+ data: message.data,
568
+ error: message.error
569
+ };
570
+ this.resolvePendingRequest(message.requestId, response);
571
+ }
387
572
  handleGuidyCommand(message) {
388
573
  for (const handler of this.guidyHandlers) {
389
574
  try {
@@ -685,6 +870,66 @@ var GuidyBridge = class {
685
870
  }
686
871
  };
687
872
 
873
+ // src/core/ms-graph-client.ts
874
+ var MsGraphClient = class {
875
+ iframeAuth;
876
+ constructor(iframeAuth) {
877
+ this.iframeAuth = iframeAuth;
878
+ }
879
+ /** Whether the host's MSAL session is signed in, plus optional account info. */
880
+ status() {
881
+ return this.iframeAuth.requestMsGraphStatus();
882
+ }
883
+ /** Convenience: resolves to whether the host's MSAL session is signed in. */
884
+ async isSignedIn() {
885
+ const status = await this.iframeAuth.requestMsGraphStatus();
886
+ return status.signedIn;
887
+ }
888
+ /** Perform an arbitrary Microsoft Graph request via the host's MSAL session. */
889
+ request(request) {
890
+ return this.iframeAuth.requestMsGraph(request);
891
+ }
892
+ /** GET a Graph resource, e.g. `get('/me/messages?$top=5')`. */
893
+ get(path, options) {
894
+ return this.iframeAuth.requestMsGraph({ method: "GET", path, ...options });
895
+ }
896
+ /** POST a JSON body to a Graph resource. */
897
+ post(path, body, options) {
898
+ return this.iframeAuth.requestMsGraph({
899
+ method: "POST",
900
+ path,
901
+ body,
902
+ ...options
903
+ });
904
+ }
905
+ /** PATCH a JSON body to a Graph resource. */
906
+ patch(path, body, options) {
907
+ return this.iframeAuth.requestMsGraph({
908
+ method: "PATCH",
909
+ path,
910
+ body,
911
+ ...options
912
+ });
913
+ }
914
+ /** PUT a JSON body to a Graph resource. */
915
+ put(path, body, options) {
916
+ return this.iframeAuth.requestMsGraph({
917
+ method: "PUT",
918
+ path,
919
+ body,
920
+ ...options
921
+ });
922
+ }
923
+ /** DELETE a Graph resource. */
924
+ delete(path, options) {
925
+ return this.iframeAuth.requestMsGraph({ method: "DELETE", path, ...options });
926
+ }
927
+ /** Convenience: GET `/me` — the signed-in user's profile. */
928
+ getMe() {
929
+ return this.iframeAuth.requestMsGraph({ method: "GET", path: "/me" });
930
+ }
931
+ };
932
+
688
933
  // src/core/sso-auth.ts
689
934
  var SsoAuth = class {
690
935
  config;
@@ -846,6 +1091,7 @@ var AuthManager = class {
846
1091
  standaloneAuth = null;
847
1092
  iframeAuth = null;
848
1093
  guidyBridge = null;
1094
+ msGraphClient = null;
849
1095
  reactNativeAuth = null;
850
1096
  tokenRefreshTimer = null;
851
1097
  /** Shared in-flight refresh, so concurrent requests don't trigger parallel refreshes. */
@@ -988,6 +1234,7 @@ var AuthManager = class {
988
1234
  */
989
1235
  initializeIframeMode() {
990
1236
  this.iframeAuth = new IframeAuth(this.config.allowedHostOrigins);
1237
+ this.msGraphClient = new MsGraphClient(this.iframeAuth);
991
1238
  this.iframeAuth.start((tokens) => {
992
1239
  this.setAuthenticated(tokens);
993
1240
  });
@@ -1055,6 +1302,61 @@ var AuthManager = class {
1055
1302
  notifyHostRouteChange(payload) {
1056
1303
  this.iframeAuth?.notifyRouteChange(payload);
1057
1304
  }
1305
+ /**
1306
+ * Iframe/WebView mode: ask the host shell to navigate to a path/URL.
1307
+ * Posts a `navigation-request` message; the host decides how to honour it.
1308
+ * No-op outside iframe mode.
1309
+ */
1310
+ requestHostNavigation(url, options) {
1311
+ this.iframeAuth?.requestHostNavigation(url, options);
1312
+ }
1313
+ /**
1314
+ * Iframe/WebView mode: hand a payload to the host AI assistant (Docy).
1315
+ * Resolves when the host acknowledges delivery. Rejects outside iframe mode.
1316
+ */
1317
+ sendToDocy(payload) {
1318
+ if (!this.iframeAuth) {
1319
+ return Promise.reject(new Error("sendToDocy() is only available in iframe/WebView mode"));
1320
+ }
1321
+ return this.iframeAuth.sendToDocy(payload);
1322
+ }
1323
+ /**
1324
+ * Iframe/WebView mode: hand a payload to the host team-chat app.
1325
+ * Resolves when the host acknowledges delivery. Rejects outside iframe mode.
1326
+ */
1327
+ sendToChat(payload) {
1328
+ if (!this.iframeAuth) {
1329
+ return Promise.reject(new Error("sendToChat() is only available in iframe/WebView mode"));
1330
+ }
1331
+ return this.iframeAuth.sendToChat(payload);
1332
+ }
1333
+ /**
1334
+ * Iframe/WebView mode: hand a draft email to the host. Resolves when the
1335
+ * host acknowledges. Rejects outside iframe mode.
1336
+ */
1337
+ sendToEmail(payload) {
1338
+ if (!this.iframeAuth) {
1339
+ return Promise.reject(new Error("sendToEmail() is only available in iframe/WebView mode"));
1340
+ }
1341
+ return this.iframeAuth.sendToEmail(payload);
1342
+ }
1343
+ /**
1344
+ * Iframe/WebView mode: hand a calendar event to the host. Resolves when the
1345
+ * host acknowledges. Rejects outside iframe mode.
1346
+ */
1347
+ sendToCalendar(payload) {
1348
+ if (!this.iframeAuth) {
1349
+ return Promise.reject(new Error("sendToCalendar() is only available in iframe/WebView mode"));
1350
+ }
1351
+ return this.iframeAuth.sendToCalendar(payload);
1352
+ }
1353
+ /**
1354
+ * Iframe/WebView mode: get the client for the host's Microsoft Graph (MSAL)
1355
+ * session. Returns `null` outside iframe mode.
1356
+ */
1357
+ getMsGraphClient() {
1358
+ return this.msGraphClient;
1359
+ }
1058
1360
  /**
1059
1361
  * Subscribe to host `navigation` messages. Returns an unsubscribe function.
1060
1362
  * Handlers registered before iframe mode is initialized are retained and
@@ -1176,6 +1478,7 @@ var AuthManager = class {
1176
1478
  this.guidyBridge = null;
1177
1479
  }
1178
1480
  this.iframeAuth.stop();
1481
+ this.msGraphClient = null;
1179
1482
  }
1180
1483
  if (this.config.ssr) {
1181
1484
  clearTokenCookie(this.config.ssrCookieKey);
@@ -1355,6 +1658,7 @@ var AuthManager = class {
1355
1658
  this.guidyBridge = null;
1356
1659
  }
1357
1660
  if (this.iframeAuth) this.iframeAuth.stop();
1661
+ this.msGraphClient = null;
1358
1662
  this.listeners.clear();
1359
1663
  this.navigationHandlers.clear();
1360
1664
  this.notificationHandlers.clear();
@@ -1426,6 +1730,21 @@ var DocyrusAuthProvider = defineComponent({
1426
1730
  const notifyRouteChange = (payload) => {
1427
1731
  manager?.notifyHostRouteChange(payload);
1428
1732
  };
1733
+ const requestHostNavigation = (url, options) => {
1734
+ manager?.requestHostNavigation(url, options);
1735
+ };
1736
+ const sendToDocy = (payload) => {
1737
+ return manager?.sendToDocy(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
1738
+ };
1739
+ const sendToChat = (payload) => {
1740
+ return manager?.sendToChat(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
1741
+ };
1742
+ const sendToEmail = (payload) => {
1743
+ return manager?.sendToEmail(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
1744
+ };
1745
+ const sendToCalendar = (payload) => {
1746
+ return manager?.sendToCalendar(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
1747
+ };
1429
1748
  const authState = {
1430
1749
  get status() {
1431
1750
  return status.value;
@@ -1442,6 +1761,9 @@ var DocyrusAuthProvider = defineComponent({
1442
1761
  get error() {
1443
1762
  return error.value;
1444
1763
  },
1764
+ get msGraph() {
1765
+ return manager?.getMsGraphClient() ?? null;
1766
+ },
1445
1767
  signIn,
1446
1768
  signInWithTokens,
1447
1769
  getAuthorizationUrl,
@@ -1449,7 +1771,12 @@ var DocyrusAuthProvider = defineComponent({
1449
1771
  onHostNavigation,
1450
1772
  onHostNotification,
1451
1773
  enableHostRouteSync,
1452
- notifyRouteChange
1774
+ notifyRouteChange,
1775
+ requestHostNavigation,
1776
+ sendToDocy,
1777
+ sendToChat,
1778
+ sendToEmail,
1779
+ sendToCalendar
1453
1780
  };
1454
1781
  provide(DOCYRUS_AUTH_KEY, authState);
1455
1782
  onMounted(() => {