@docyrus/signin 0.15.0 → 0.17.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.
@@ -0,0 +1,774 @@
1
+ import { OAuth2Tokens, OAuth2TokenStorage, CryptoProvider, RestApiClient } from '@docyrus/api-client';
2
+
3
+ type IframeAuthCallback = (tokens: OAuth2Tokens) => void;
4
+ /**
5
+ * Iframe / WebView authentication via postMessage.
6
+ *
7
+ * Protocol:
8
+ * - App → Host: { type: "signin-ready" } (on start)
9
+ * - Host → App: { type: "signin", accessToken, refreshToken }
10
+ * - App → Host: { type: "token-refresh-request" }
11
+ * - Host → App: { type: "navigation", url }
12
+ * - Host → App: { type: "notification", notification }
13
+ * - App → Host: { type: "route-change", path, search, hash, url }
14
+ * - App → Host: { type: "navigation-request", url, replace?, newTab? }
15
+ *
16
+ * Every incoming message's event.origin is validated against
17
+ * the allowed host pattern before processing.
18
+ * In WebView mode, origin validation is skipped (ReactNativeWebView bridge).
19
+ */
20
+ declare class IframeAuth {
21
+ private allowedOrigins;
22
+ private allowedPattern;
23
+ private isWebView;
24
+ private onTokensReceived;
25
+ private navigationHandlers;
26
+ private notificationHandlers;
27
+ private guidyHandlers;
28
+ private routeSyncEnabled;
29
+ private originalPushState;
30
+ private originalReplaceState;
31
+ private routeChangeListener;
32
+ private stopped;
33
+ private refreshPromise;
34
+ private messageHandler;
35
+ /**
36
+ * In-flight app→host requests awaiting a correlated host reply, keyed by
37
+ * requestId. Powers Send to Docy / Send to Chat / the MS Graph bridge.
38
+ */
39
+ private pendingRequests;
40
+ /** Fallback monotonic counter for request ids when crypto.randomUUID is absent. */
41
+ private requestCounter;
42
+ constructor(allowedOrigins?: string[], allowedPattern?: RegExp);
43
+ /**
44
+ * Start listening for postMessage events from the host.
45
+ * The callback is invoked every time valid tokens are received.
46
+ */
47
+ start(onTokensReceived: IframeAuthCallback): void;
48
+ /** Stop listening for postMessage events. */
49
+ stop(): void;
50
+ /**
51
+ * Patch history methods + listen for popstate/hashchange so every
52
+ * route change posts a `route-change` message to the host.
53
+ * Idempotent. Fires an immediate message with the current route.
54
+ */
55
+ enableRouteSync(): void;
56
+ /**
57
+ * Post a single `route-change` message. With no argument, reads
58
+ * `window.location`. Pass a payload from a router subscription to
59
+ * report a known route instead.
60
+ */
61
+ notifyRouteChange(payload?: RouteChangePayload): void;
62
+ /**
63
+ * Ask the host shell to navigate to a path/URL. The reverse of the
64
+ * host → app `navigation` message: posts a `navigation-request` over the
65
+ * same validated channel. The host decides how to honour it.
66
+ */
67
+ requestHostNavigation(url: string, options?: HostNavigationRequestOptions): void;
68
+ private teardownRouteSync;
69
+ /**
70
+ * Subscribe to host navigation messages.
71
+ * Returns an unsubscribe function.
72
+ */
73
+ onNavigation(handler: HostNavigationHandler): () => void;
74
+ /**
75
+ * Subscribe to host notification messages.
76
+ * Returns an unsubscribe function.
77
+ */
78
+ onNotification(handler: HostNotificationHandler): () => void;
79
+ /**
80
+ * Subscribe to host `guidy:*` command messages (point/scan).
81
+ * Returns an unsubscribe function. Used by the Guidy bridge runtime.
82
+ */
83
+ onGuidyCommand(handler: GuidyCommandHandler): () => void;
84
+ /**
85
+ * Post an app → host message over the same validated channel used for
86
+ * route-change and token-refresh. Used by the Guidy bridge to push its
87
+ * element inventory and point acknowledgements.
88
+ */
89
+ sendToHost(message: AppToHostMessage): void;
90
+ /**
91
+ * Hand a payload to the host AI assistant (Docy). Resolves when the host
92
+ * acknowledges delivery, rejects on host error or timeout.
93
+ */
94
+ sendToDocy(payload: DocyrusSharePayload): Promise<void>;
95
+ /**
96
+ * Hand a payload to the host team-chat app. Resolves when the host
97
+ * acknowledges delivery, rejects on host error or timeout.
98
+ */
99
+ sendToChat(payload: DocyrusSharePayload): Promise<void>;
100
+ /**
101
+ * Hand a draft email to the host. Resolves when the host acknowledges,
102
+ * rejects on host error or timeout.
103
+ */
104
+ sendToEmail(payload: DocyrusEmailPayload): Promise<void>;
105
+ /**
106
+ * Hand a calendar event to the host. Resolves when the host acknowledges,
107
+ * rejects on host error or timeout.
108
+ */
109
+ sendToCalendar(payload: DocyrusCalendarEventPayload): Promise<void>;
110
+ /** Ask the host whether its MSAL session is signed in. */
111
+ requestMsGraphStatus(): Promise<MsGraphStatus>;
112
+ /** Perform a Microsoft Graph request through the host's MSAL session. */
113
+ requestMsGraph(request: MsGraphRequest): Promise<MsGraphResponse>;
114
+ /**
115
+ * Post a correlated app→host request and await the matching host reply.
116
+ * The reply is matched by `requestId` in `handleMessage`. Rejects on timeout
117
+ * or when the bridge is stopped.
118
+ */
119
+ private request;
120
+ /** Generate a correlation id, preferring crypto.randomUUID when available. */
121
+ private nextRequestId;
122
+ private resolvePendingRequest;
123
+ private rejectPendingRequest;
124
+ private rejectAllPendingRequests;
125
+ /**
126
+ * Request fresh tokens from the host.
127
+ * Posts a "token-refresh-request" to the host, then waits for
128
+ * a "signin" response.
129
+ *
130
+ * Only one refresh request can be in-flight at a time.
131
+ * Additional callers share the same promise.
132
+ */
133
+ requestTokenRefresh(): Promise<OAuth2Tokens>;
134
+ private isOriginAllowed;
135
+ private handleMessage;
136
+ private handleActionAck;
137
+ private handleMsGraphStatusResponse;
138
+ private handleMsGraphResponse;
139
+ private handleGuidyCommand;
140
+ private handleSignin;
141
+ private handleNavigation;
142
+ private handleNotification;
143
+ private rejectPendingRefresh;
144
+ }
145
+
146
+ /** Extra per-call options for the ergonomic Graph helpers. */
147
+ interface MsGraphRequestOptions {
148
+ /** Extra request headers (the host may filter these). */
149
+ headers?: Record<string, string>;
150
+ /** Optional scopes hint for the token the host should acquire. */
151
+ scopes?: string[];
152
+ }
153
+ /**
154
+ * A client for the host's Microsoft Graph (MSAL) session, usable from an
155
+ * embedded app. Every call is **proxied** through the host: the host acquires
156
+ * the token via MSAL, performs the Graph request, and returns only the
157
+ * response. The MSAL access token never crosses the frame boundary.
158
+ *
159
+ * Obtain one via `useDocyrusMsGraph()` (React), `getDocyrusAuth().msGraph`
160
+ * (Vue), or `AuthManager.getMsGraphClient()`. Only available in iframe/WebView
161
+ * mode — it is `null` elsewhere.
162
+ */
163
+ declare class MsGraphClient {
164
+ private iframeAuth;
165
+ constructor(iframeAuth: IframeAuth);
166
+ /** Whether the host's MSAL session is signed in, plus optional account info. */
167
+ status(): Promise<MsGraphStatus>;
168
+ /** Convenience: resolves to whether the host's MSAL session is signed in. */
169
+ isSignedIn(): Promise<boolean>;
170
+ /** Perform an arbitrary Microsoft Graph request via the host's MSAL session. */
171
+ request(request: MsGraphRequest): Promise<MsGraphResponse>;
172
+ /** GET a Graph resource, e.g. `get('/me/messages?$top=5')`. */
173
+ get(path: string, options?: MsGraphRequestOptions): Promise<MsGraphResponse>;
174
+ /** POST a JSON body to a Graph resource. */
175
+ post(path: string, body?: unknown, options?: MsGraphRequestOptions): Promise<MsGraphResponse>;
176
+ /** PATCH a JSON body to a Graph resource. */
177
+ patch(path: string, body?: unknown, options?: MsGraphRequestOptions): Promise<MsGraphResponse>;
178
+ /** PUT a JSON body to a Graph resource. */
179
+ put(path: string, body?: unknown, options?: MsGraphRequestOptions): Promise<MsGraphResponse>;
180
+ /** DELETE a Graph resource. */
181
+ delete(path: string, options?: MsGraphRequestOptions): Promise<MsGraphResponse>;
182
+ /** Convenience: GET `/me` — the signed-in user's profile. */
183
+ getMe(): Promise<MsGraphResponse>;
184
+ }
185
+
186
+ /** Authentication mode detected at runtime */
187
+ type AuthMode = 'standalone' | 'iframe' | 'react-native';
188
+ /** Result from the native auth session (e.g., expo-web-browser) */
189
+ interface AuthSessionResult {
190
+ type: string;
191
+ url?: string;
192
+ }
193
+ /** Function signature for opening an auth session in a native browser */
194
+ type OpenAuthSessionFn = (url: string, redirectUri: string) => Promise<AuthSessionResult>;
195
+ /** Authentication state exposed to consumers */
196
+ type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';
197
+ /** Configuration for the DocyrusAuthProvider */
198
+ interface DocyrusAuthConfig {
199
+ /** OAuth2 client ID. Defaults to the Docyrus public client ID */
200
+ clientId?: string;
201
+ /** API base URL. Defaults to https://alpha-api.docyrus.com */
202
+ apiUrl?: string;
203
+ /** OAuth2 scopes. Defaults to offline_access Read.All Users.Read Users.Read.All DS.Read.All */
204
+ scopes?: string[];
205
+ /** The redirect URI for OAuth2 callback. Defaults to `${window.location.origin}/auth/callback` */
206
+ redirectUri?: string;
207
+ /** The path where the OAuth2 callback is handled. Defaults to '/auth/callback' */
208
+ callbackPath?: string;
209
+ /** Allowed host origins for iframe mode. Used alongside the default *.docyrus.app pattern */
210
+ allowedHostOrigins?: string[];
211
+ /** localStorage key prefix for token storage. Defaults to 'docyrus_oauth2' */
212
+ storageKeyPrefix?: string;
213
+ /** Custom token storage implementation (e.g., Electron IPC storage). Overrides storageKeyPrefix */
214
+ tokenStorage?: OAuth2TokenStorage;
215
+ /** Override auto-detection: force a specific auth mode */
216
+ forceMode?: AuthMode;
217
+ /**
218
+ * Bootstrap an authenticated session from tokens obtained elsewhere
219
+ * (for example, a prior device flow). When provided, these tokens
220
+ * replace any currently stored standalone/react-native session.
221
+ */
222
+ initialTokens?: OAuth2Tokens;
223
+ /**
224
+ * Automatically refresh the access token before/at expiry. Default: true.
225
+ *
226
+ * When `false`, the provider never refreshes tokens on its own — it
227
+ * disables the proactive pre-expiry timer, the pre-request refresh in
228
+ * the API client's token getter, and the reactive 401 refresh. The
229
+ * current access token is used as-is until replaced via
230
+ * `signInWithTokens`. Use this when an external system owns the token
231
+ * lifecycle (e.g. a Supabase session whose refresh token is not a valid
232
+ * Docyrus OAuth2 grant) and pushes fresh tokens in through
233
+ * `signInWithTokens`.
234
+ */
235
+ autoRefresh?: boolean;
236
+ /** Enable SSR: sync access token to a cookie readable by server components. Default: false */
237
+ ssr?: boolean;
238
+ /** Cookie name for SSR token sync. Default: 'docyrus-token' */
239
+ ssrCookieKey?: string;
240
+ /**
241
+ * Iframe/WebView mode: post a `route-change` message to the host on
242
+ * every history change so the host can reflect the embedded app's
243
+ * route in its address bar. Patches `history.pushState/replaceState`
244
+ * and listens for `popstate`/`hashchange`. No-op outside iframe mode.
245
+ * Default: false.
246
+ */
247
+ syncRouteToHost?: boolean;
248
+ /**
249
+ * Iframe mode: let the host assistant (Guidy) inspect and drive this app's
250
+ * visible UI — scan its clickable elements, highlight/annotate them, and
251
+ * click them on the user's behalf — over the existing postMessage channel.
252
+ *
253
+ * Opt-in: the app must consent to being driven. The bridge only exposes
254
+ * already-visible interactive elements and only runs a fixed command
255
+ * vocabulary (scan / point / click); no arbitrary script is accepted from
256
+ * the host. No-op outside iframe mode. Default: false.
257
+ */
258
+ enableGuidyBridge?: boolean;
259
+ /**
260
+ * Iframe mode: routes the host assistant (Guidy) may navigate the user to
261
+ * inside this app. The host turns each into a deep link it can drive via the
262
+ * existing host→app `navigation` message. Update at runtime with
263
+ * `setGuidyRoutes` (e.g. when routes depend on permissions). Requires
264
+ * `enableGuidyBridge`. Default: none.
265
+ */
266
+ guidyRoutes?: GuidyRoute[];
267
+ /** React Native: custom URI scheme redirect (e.g., 'myapp://auth/callback'). Required when forceMode is 'react-native' */
268
+ nativeRedirectUri?: string;
269
+ /** React Native: function to open an in-app browser auth session (e.g., WebBrowser.openAuthSessionAsync from expo-web-browser) */
270
+ openAuthSession?: OpenAuthSessionFn;
271
+ /** Custom crypto provider for PKCE operations in non-browser environments (e.g., ReactNativeCryptoProvider from @docyrus/api-client/react-native) */
272
+ cryptoProvider?: CryptoProvider;
273
+ }
274
+ /** The shape of the React context value */
275
+ interface DocyrusAuthContextValue {
276
+ /** Current auth state */
277
+ status: AuthStatus;
278
+ /** The detected authentication mode */
279
+ mode: AuthMode | null;
280
+ /** Pre-configured RestApiClient with valid tokens */
281
+ client: RestApiClient | null;
282
+ /** Current tokens (null when unauthenticated) */
283
+ tokens: OAuth2Tokens | null;
284
+ /** Current user data (null when not authenticated or not yet fetched) */
285
+ user: DocyrusUser | null;
286
+ /** Initiate sign-in (only relevant in standalone mode) */
287
+ signIn: () => void;
288
+ /** Bootstrap an authenticated session from existing tokens */
289
+ signInWithTokens: (tokens: OAuth2Tokens) => Promise<void>;
290
+ /** Get the OAuth2 authorization URL without navigating. For Electron apps */
291
+ getAuthorizationUrl: () => Promise<string | null>;
292
+ /** Sign out and clear tokens */
293
+ signOut: () => Promise<void>;
294
+ /** Check if the current user has a specific role (by slug or uid) */
295
+ hasRole: (role: string | string[] | null | undefined) => boolean;
296
+ /** Check if the current user has permission for an operation on a data source */
297
+ hasPermission: (operation: string, dataSourceId?: string | null) => boolean;
298
+ /** Re-fetch the current user from the API */
299
+ refreshUser: () => Promise<void>;
300
+ /**
301
+ * Subscribe to host `navigation` messages (iframe/WebView mode only).
302
+ * Returns an unsubscribe function. No-op in non-iframe modes.
303
+ */
304
+ onHostNavigation: (handler: HostNavigationHandler) => () => void;
305
+ /**
306
+ * Subscribe to host `notification` messages (iframe/WebView mode only).
307
+ * Returns an unsubscribe function. No-op in non-iframe modes.
308
+ */
309
+ onHostNotification: (handler: HostNotificationHandler) => () => void;
310
+ /**
311
+ * Iframe/WebView mode: start auto-syncing the embedded app's route
312
+ * to the host. Patches `history.pushState/replaceState` and listens
313
+ * for `popstate`/`hashchange`. Safe to call multiple times. No-op in
314
+ * non-iframe modes.
315
+ */
316
+ enableHostRouteSync: () => void;
317
+ /**
318
+ * Iframe/WebView mode: post a single `route-change` message to the host.
319
+ * When called with no argument, the current `window.location` is read.
320
+ * Pass a payload to report a specific route (useful with router
321
+ * subscriptions). No-op in non-iframe modes.
322
+ */
323
+ notifyRouteChange: (payload?: RouteChangePayload) => void;
324
+ /**
325
+ * Iframe/WebView mode: ask the host shell to navigate to a path/URL.
326
+ * The reverse of `onHostNavigation` — lets an in-app action drive the
327
+ * host's own routing (deep link, switch view, open a sibling app). The
328
+ * host decides how to honour the request. No-op in non-iframe modes.
329
+ */
330
+ requestHostNavigation: (url: string, options?: HostNavigationRequestOptions) => void;
331
+ /**
332
+ * Iframe mode (Guidy bridge): replace the routes the host assistant may
333
+ * navigate the user to inside this app. No-op unless `enableGuidyBridge`
334
+ * is set. Use for routes that depend on runtime state (e.g. permissions).
335
+ */
336
+ setGuidyRoutes: (routes: GuidyRoute[]) => void;
337
+ /**
338
+ * Iframe/WebView mode: hand a payload to the host AI assistant (Docy).
339
+ * Resolves when the host acknowledges delivery; rejects on host error or
340
+ * timeout. Rejects immediately outside iframe mode.
341
+ */
342
+ sendToDocy: (payload: DocyrusSharePayload) => Promise<void>;
343
+ /**
344
+ * Iframe/WebView mode: hand a payload to the host team-chat app.
345
+ * Resolves when the host acknowledges delivery; rejects on host error or
346
+ * timeout. Rejects immediately outside iframe mode.
347
+ */
348
+ sendToChat: (payload: DocyrusSharePayload) => Promise<void>;
349
+ /**
350
+ * Iframe/WebView mode: hand a draft email (to/subject/body/cc) to the host
351
+ * to send or compose. Resolves when the host acknowledges; rejects on host
352
+ * error or timeout. Rejects immediately outside iframe mode.
353
+ */
354
+ sendToEmail: (payload: DocyrusEmailPayload) => Promise<void>;
355
+ /**
356
+ * Iframe/WebView mode: hand a calendar event (subject/description/
357
+ * participants/start/end) to the host to create. Resolves when the host
358
+ * acknowledges; rejects on host error or timeout. Rejects immediately
359
+ * outside iframe mode.
360
+ */
361
+ sendToCalendar: (payload: DocyrusCalendarEventPayload) => Promise<void>;
362
+ /**
363
+ * Iframe/WebView mode: a client for the host's Microsoft Graph (MSAL)
364
+ * session. Check `isSignedIn()` and make host-proxied Graph requests — the
365
+ * host performs the call and returns the response; the MSAL access token
366
+ * never crosses the frame boundary. `null` outside iframe mode.
367
+ */
368
+ msGraph: MsGraphClient | null;
369
+ /** Any error that occurred during auth */
370
+ error: Error | null;
371
+ }
372
+ /** PostMessage payload: host sends tokens to the embedded app */
373
+ interface HostSignInMessage {
374
+ type: 'signin';
375
+ accessToken: string;
376
+ refreshToken: string;
377
+ }
378
+ /** PostMessage payload: app requests fresh tokens from the host */
379
+ interface TokenRefreshRequestMessage {
380
+ type: 'token-refresh-request';
381
+ }
382
+ /**
383
+ * PostMessage payload: app reports its current route to the host.
384
+ * Sent on every history change so the host can reflect it in the
385
+ * browser address bar.
386
+ */
387
+ interface AppRouteChangeMessage {
388
+ type: 'route-change';
389
+ /** location.pathname (e.g. "/customers/123") */
390
+ path: string;
391
+ /** location.search including leading "?" — empty string if none */
392
+ search: string;
393
+ /** location.hash including leading "#" — empty string if none */
394
+ hash: string;
395
+ /** Convenience: `path + search + hash` */
396
+ url: string;
397
+ }
398
+ /** Payload for manual `notifyRouteChange` calls */
399
+ interface RouteChangePayload {
400
+ path?: string;
401
+ search?: string;
402
+ hash?: string;
403
+ }
404
+ /** PostMessage payload: host asks the embedded app to navigate to a URL */
405
+ interface HostNavigationMessage {
406
+ type: 'navigation';
407
+ url: string;
408
+ }
409
+ /**
410
+ * PostMessage payload: the embedded app asks the host shell to navigate to a
411
+ * path/URL. The reverse of `HostNavigationMessage` — used when an in-app action
412
+ * needs to drive the host's own routing (deep link, switch view, open a
413
+ * sibling app). The host decides how to honour it. Unlike `route-change`, which
414
+ * passively reports the app's current route, this is an explicit request.
415
+ */
416
+ interface AppNavigationRequestMessage {
417
+ type: 'navigation-request';
418
+ /** Target path or absolute URL for the host shell to navigate to. */
419
+ url: string;
420
+ /** Hint the host to replace the current history entry instead of pushing. */
421
+ replace?: boolean;
422
+ /** Hint the host to open the target in a new tab/window instead of in place. */
423
+ newTab?: boolean;
424
+ }
425
+ /** Options for `requestHostNavigation` (app → host navigation request). */
426
+ interface HostNavigationRequestOptions {
427
+ /** Hint the host to replace the current history entry instead of pushing. */
428
+ replace?: boolean;
429
+ /** Hint the host to open the target in a new tab/window instead of in place. */
430
+ newTab?: boolean;
431
+ }
432
+ /**
433
+ * Notification payload pushed from the host into the embedded app.
434
+ * Mirrors the NotificationEntity API contract.
435
+ */
436
+ interface DocyrusNotification {
437
+ id: string;
438
+ subject: string;
439
+ message: string;
440
+ status: string;
441
+ seen: boolean;
442
+ created_on: string;
443
+ notify_on: string;
444
+ created_by: string;
445
+ record_owner: string;
446
+ created_by_id: string;
447
+ created_by_fullname: string;
448
+ created_by_photo: string;
449
+ params?: Record<string, unknown> | null;
450
+ tenant_app_id?: string | null;
451
+ output_render_template?: Record<string, unknown> | null;
452
+ }
453
+ /** PostMessage payload: host pushes a notification to the embedded app */
454
+ interface HostNotificationMessage {
455
+ type: 'notification';
456
+ notification: DocyrusNotification;
457
+ }
458
+ /**
459
+ * A visible, interactive element the host assistant (Guidy) can target by id.
460
+ * Mirrors the host-side clickable inventory so the model can reference real
461
+ * in-app buttons and links the same way it references shell chrome.
462
+ */
463
+ interface GuidyElement {
464
+ /** Stable DOM id used as the target for `guidy:point`. */
465
+ id: string;
466
+ /** Human-readable label (aria-label, text, or title). */
467
+ label: string;
468
+ /** Element kind, so the model can phrase guidance naturally. */
469
+ tag: 'a' | 'button';
470
+ }
471
+ /**
472
+ * App → Host: the embedded app's current clickable inventory.
473
+ * Pushed proactively on mount, route change, and DOM mutation so the host
474
+ * can keep a fresh snapshot without a request round-trip.
475
+ */
476
+ interface GuidyElementsMessage {
477
+ type: 'guidy:elements';
478
+ /** The app's current `location.pathname` when the scan was taken. */
479
+ path: string;
480
+ elements: GuidyElement[];
481
+ }
482
+ /**
483
+ * A navigable route the host assistant (Guidy) can send the user to. Unlike
484
+ * elements, routes cannot be auto-discovered from the DOM, so the app declares
485
+ * them (via `guidyRoutes` / `setGuidyRoutes`). The host turns these into deep
486
+ * links it can drive through the existing host→app `navigation` message.
487
+ */
488
+ interface GuidyRoute {
489
+ /** App-internal path, e.g. `/leads` or `leads/new`. */
490
+ path: string;
491
+ /** Human-readable label, e.g. `Leads`. */
492
+ label: string;
493
+ }
494
+ /**
495
+ * App → Host: the embedded app's declared navigable routes.
496
+ * Pushed on start and whenever the app updates its route catalog.
497
+ */
498
+ interface GuidyRoutesMessage {
499
+ type: 'guidy:routes';
500
+ routes: GuidyRoute[];
501
+ }
502
+ /**
503
+ * Host → App: scroll to, highlight, and optionally annotate/click an element.
504
+ * The app renders the highlight/annotation itself — the host cannot draw into
505
+ * a cross-origin iframe.
506
+ */
507
+ interface GuidyPointMessage {
508
+ type: 'guidy:point';
509
+ /** Target element id (must match a `GuidyElement.id`). */
510
+ id: string;
511
+ /** When true, dispatch a click after highlighting. Default: false. */
512
+ click?: boolean;
513
+ /** Optional short message shown in an annotation bubble near the element. */
514
+ message?: string;
515
+ }
516
+ /**
517
+ * Host → App: request a fresh element inventory. Used to recover from a late
518
+ * host mount that missed the app's proactive push. The app replies with a
519
+ * `guidy:elements` message.
520
+ */
521
+ interface GuidyScanMessage {
522
+ type: 'guidy:scan';
523
+ }
524
+ /** App → Host: result of a `guidy:point` command. */
525
+ interface GuidyPointAckMessage {
526
+ type: 'guidy:point-ack';
527
+ /** The id that was targeted. */
528
+ id: string;
529
+ /** Whether the element was found and acted upon. */
530
+ ok: boolean;
531
+ }
532
+ /** Host → App: commands the Guidy bridge runtime handles. */
533
+ type GuidyCommandMessage = GuidyPointMessage | GuidyScanMessage;
534
+ /** Handler invoked when the host sends a Guidy command. */
535
+ type GuidyCommandHandler = (message: GuidyCommandMessage) => void;
536
+ /**
537
+ * A minimal structural type for a raw Adaptive Card document
538
+ * (schema http://adaptivecards.io/schemas/adaptive-card.json). Kept
539
+ * dependency-free on purpose — the host renders the card, so the SDK does not
540
+ * import an Adaptive Card library. Pass the card JSON through as-is.
541
+ */
542
+ interface AdaptiveCard {
543
+ type: 'AdaptiveCard';
544
+ version?: string;
545
+ body?: unknown[];
546
+ actions?: unknown[];
547
+ [key: string]: unknown;
548
+ }
549
+ /** Plain-text (or markdown) payload handed to a host surface. */
550
+ interface DocyrusShareTextPayload {
551
+ kind: 'text';
552
+ /** The text/markdown body. */
553
+ text: string;
554
+ /** Optional short title/subject shown by the host surface. */
555
+ title?: string;
556
+ }
557
+ /** Adaptive Card payload handed to a host surface. */
558
+ interface DocyrusShareAdaptiveCardPayload {
559
+ kind: 'adaptiveCard';
560
+ /** Raw Adaptive Card JSON the host will render. */
561
+ card: AdaptiveCard;
562
+ /** Fallback text for hosts that cannot render the card. */
563
+ fallbackText?: string;
564
+ }
565
+ /**
566
+ * The payload an embedded app can hand off to a host surface (Docy or Chat).
567
+ * Two kinds: plain `text` or an `adaptiveCard`.
568
+ */
569
+ type DocyrusSharePayload = DocyrusShareTextPayload | DocyrusShareAdaptiveCardPayload;
570
+ /** App → Host: hand a payload to the host AI assistant (Docy). */
571
+ interface DocySendMessage {
572
+ type: 'docy:send';
573
+ /** Correlation id — the host echoes it in the matching `docy:send-ack`. */
574
+ requestId: string;
575
+ payload: DocyrusSharePayload;
576
+ }
577
+ /** App → Host: hand a payload to the host team-chat app. */
578
+ interface ChatSendMessage {
579
+ type: 'chat:send';
580
+ /** Correlation id — the host echoes it in the matching `chat:send-ack`. */
581
+ requestId: string;
582
+ payload: DocyrusSharePayload;
583
+ }
584
+ /** Host → App: acknowledgement of a `docy:send`. */
585
+ interface DocySendAckMessage {
586
+ type: 'docy:send-ack';
587
+ requestId: string;
588
+ /** Whether the host accepted and delivered the payload. */
589
+ ok: boolean;
590
+ /** Failure reason when `ok` is false. */
591
+ error?: string;
592
+ }
593
+ /** Host → App: acknowledgement of a `chat:send`. */
594
+ interface ChatSendAckMessage {
595
+ type: 'chat:send-ack';
596
+ requestId: string;
597
+ /** Whether the host accepted and delivered the payload. */
598
+ ok: boolean;
599
+ /** Failure reason when `ok` is false. */
600
+ error?: string;
601
+ }
602
+ /** A draft email an embedded app hands to the host to send/compose. */
603
+ interface DocyrusEmailPayload {
604
+ /** Recipient address(es). */
605
+ to: string | string[];
606
+ /** Subject line. */
607
+ subject: string;
608
+ /** Body (plain text or HTML — the host decides how to render/send). */
609
+ body: string;
610
+ /** Carbon-copy recipient(s). */
611
+ cc?: string | string[];
612
+ }
613
+ /** A calendar event an embedded app hands to the host to create. */
614
+ interface DocyrusCalendarEventPayload {
615
+ /** Event title/subject. */
616
+ subject: string;
617
+ /** Event description/body. */
618
+ description?: string;
619
+ /** Participant address(es). */
620
+ participants?: string | string[];
621
+ /** Event start — ISO 8601 datetime string (e.g. '2026-07-14T09:00:00Z'). */
622
+ start: string;
623
+ /** Event end — ISO 8601 datetime string. */
624
+ end: string;
625
+ }
626
+ /** App → Host: hand a draft email to the host. */
627
+ interface EmailSendMessage {
628
+ type: 'email:send';
629
+ /** Correlation id — the host echoes it in the matching `email:send-ack`. */
630
+ requestId: string;
631
+ payload: DocyrusEmailPayload;
632
+ }
633
+ /** App → Host: hand a calendar event to the host. */
634
+ interface CalendarSendMessage {
635
+ type: 'calendar:send';
636
+ /** Correlation id — the host echoes it in the matching `calendar:send-ack`. */
637
+ requestId: string;
638
+ payload: DocyrusCalendarEventPayload;
639
+ }
640
+ /** Host → App: acknowledgement of an `email:send`. */
641
+ interface EmailSendAckMessage {
642
+ type: 'email:send-ack';
643
+ requestId: string;
644
+ /** Whether the host accepted the email. */
645
+ ok: boolean;
646
+ /** Failure reason when `ok` is false. */
647
+ error?: string;
648
+ }
649
+ /** Host → App: acknowledgement of a `calendar:send`. */
650
+ interface CalendarSendAckMessage {
651
+ type: 'calendar:send-ack';
652
+ requestId: string;
653
+ /** Whether the host accepted the calendar event. */
654
+ ok: boolean;
655
+ /** Failure reason when `ok` is false. */
656
+ error?: string;
657
+ }
658
+ /**
659
+ * A Microsoft Graph request the host performs on the app's behalf using the
660
+ * host's MSAL session (proxy-only — the access token never crosses the frame
661
+ * boundary).
662
+ */
663
+ interface MsGraphRequest {
664
+ /** HTTP method. Default: 'GET'. */
665
+ method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
666
+ /** Graph resource path or absolute URL, e.g. '/me' or '/me/messages?$top=5'. */
667
+ path: string;
668
+ /** Extra request headers (the host may filter these). */
669
+ headers?: Record<string, string>;
670
+ /** JSON body for write operations. */
671
+ body?: unknown;
672
+ /** Optional scopes hint for the token the host should acquire. */
673
+ scopes?: string[];
674
+ }
675
+ /** The result of a host-proxied Microsoft Graph call. */
676
+ interface MsGraphResponse {
677
+ /** True when the Graph call returned a 2xx status. */
678
+ ok: boolean;
679
+ /** HTTP status code (0 when the host could not perform the request at all). */
680
+ status: number;
681
+ /** Parsed JSON (or text) response body. */
682
+ data?: unknown;
683
+ /** Error message when the host could not perform the request. */
684
+ error?: string;
685
+ }
686
+ /** Minimal account info the host chooses to share about the MSAL session. */
687
+ interface MsGraphAccount {
688
+ username?: string;
689
+ name?: string;
690
+ tenantId?: string;
691
+ }
692
+ /** Whether the host's MSAL session is signed in, plus optional account info. */
693
+ interface MsGraphStatus {
694
+ signedIn: boolean;
695
+ account?: MsGraphAccount | null;
696
+ }
697
+ /** App → Host: is the host's MSAL session signed in? */
698
+ interface MsGraphStatusRequestMessage {
699
+ type: 'msgraph:status-request';
700
+ requestId: string;
701
+ }
702
+ /** App → Host: perform a Microsoft Graph request via the host's MSAL session. */
703
+ interface MsGraphRequestMessage {
704
+ type: 'msgraph:request';
705
+ requestId: string;
706
+ request: MsGraphRequest;
707
+ }
708
+ /** Host → App: MSAL sign-in status reply. */
709
+ interface MsGraphStatusResponseMessage {
710
+ type: 'msgraph:status-response';
711
+ requestId: string;
712
+ signedIn: boolean;
713
+ account?: MsGraphAccount | null;
714
+ /** Present when the host could not resolve status. */
715
+ error?: string;
716
+ }
717
+ /** Host → App: the result of a proxied Microsoft Graph request. */
718
+ interface MsGraphResponseMessage {
719
+ type: 'msgraph:response';
720
+ requestId: string;
721
+ ok: boolean;
722
+ status: number;
723
+ data?: unknown;
724
+ /** Present when the host could not perform the request (transport-level). */
725
+ error?: string;
726
+ }
727
+ type AppToHostMessage = TokenRefreshRequestMessage | AppRouteChangeMessage | AppNavigationRequestMessage | GuidyElementsMessage | GuidyRoutesMessage | GuidyPointAckMessage | DocySendMessage | ChatSendMessage | EmailSendMessage | CalendarSendMessage | MsGraphStatusRequestMessage | MsGraphRequestMessage;
728
+ /** Handler invoked when the host sends a navigation message */
729
+ type HostNavigationHandler = (message: HostNavigationMessage) => void;
730
+ /** Handler invoked when the host sends a notification message */
731
+ type HostNotificationHandler = (notification: DocyrusNotification) => void;
732
+ /** A role object as returned by GET /v1/users/me */
733
+ interface DocyrusRole {
734
+ uid: string;
735
+ slug: string;
736
+ rules: DocyrusAclRule[];
737
+ }
738
+ /** An ACL rule — maps a data source to its allowed operations */
739
+ interface DocyrusAclRule {
740
+ dataSourceId: string;
741
+ allowedOperations: string[];
742
+ }
743
+ /** The user object as returned by GET /v1/users/me */
744
+ interface DocyrusUser {
745
+ id: string;
746
+ email: string;
747
+ firstname?: string | null;
748
+ lastname?: string | null;
749
+ photo?: string | null;
750
+ primaryRole: DocyrusRole | null;
751
+ roles: DocyrusRole[];
752
+ aclRules: DocyrusAclRule[];
753
+ tenant?: {
754
+ id: string;
755
+ name: string;
756
+ no: number;
757
+ logo_url?: string | null;
758
+ isDevelopmentAccount: boolean;
759
+ } | null;
760
+ [key: string]: unknown;
761
+ }
762
+ /** ACL operation identifier */
763
+ type AclOperation = 'view' | 'create' | 'edit' | 'delete' | 'create_bulk' | 'delete_bulk' | 'export' | 'export_bulk' | 'import' | 'print' | 'print_bulk';
764
+ /** Configuration for permission checking behavior */
765
+ interface PermissionConfig {
766
+ /**
767
+ * Data sources that are always permitted for certain operations,
768
+ * keyed by data source UUID to an array of allowed operations.
769
+ * Defaults to the standard Docyrus system data sources.
770
+ */
771
+ alwaysPermittedDataSources?: Record<string, AclOperation[]>;
772
+ }
773
+
774
+ export { type MsGraphStatusRequestMessage as $, type AclOperation as A, type DocySendMessage as B, type CalendarSendAckMessage as C, type DocyrusAuthConfig as D, type DocyrusNotification as E, type EmailSendAckMessage as F, type GuidyRoute as G, type HostNavigationHandler as H, type EmailSendMessage as I, type GuidyCommandHandler as J, type GuidyCommandMessage as K, type GuidyElement as L, type MsGraphAccount as M, type GuidyElementsMessage as N, type OpenAuthSessionFn as O, type PermissionConfig as P, type GuidyPointAckMessage as Q, type RouteChangePayload as R, type GuidyPointMessage as S, type GuidyRoutesMessage as T, type GuidyScanMessage as U, type HostNavigationMessage as V, type HostNotificationMessage as W, type HostSignInMessage as X, IframeAuth as Y, type MsGraphRequestMessage as Z, type MsGraphResponseMessage as _, type AdaptiveCard as a, type MsGraphStatusResponseMessage as a0, type TokenRefreshRequestMessage as a1, type AuthMode as b, type AuthSessionResult as c, type AuthStatus as d, type DocyrusAclRule as e, type DocyrusAuthContextValue as f, type DocyrusCalendarEventPayload as g, type DocyrusEmailPayload as h, type DocyrusRole as i, type DocyrusShareAdaptiveCardPayload as j, type DocyrusSharePayload as k, type DocyrusShareTextPayload as l, type DocyrusUser as m, MsGraphClient as n, type MsGraphRequest as o, type MsGraphRequestOptions as p, type MsGraphResponse as q, type MsGraphStatus as r, type HostNotificationHandler as s, type HostNavigationRequestOptions as t, type AppNavigationRequestMessage as u, type AppRouteChangeMessage as v, type CalendarSendMessage as w, type ChatSendAckMessage as x, type ChatSendMessage as y, type DocySendAckMessage as z };