@docyrus/signin 0.13.0 → 0.14.1
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.
- package/README.md +37 -1
- package/dist/{constants-BBGO2aU5.d.ts → constants-DDOgvbL5.d.ts} +19 -3
- package/dist/core-index.d.ts +13 -8
- package/dist/core-index.js +68 -22
- package/dist/core-index.js.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.js +82 -23
- package/dist/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/react-native/index.js +75 -22
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-WOgdg9b0.d.ts → types-D4ZAVj-B.d.ts} +36 -2
- package/dist/{use-docyrus-client-DqdJWKrF.d.ts → use-docyrus-client-o9nPwayd.d.ts} +1 -1
- package/dist/vue/index.d.ts +2 -2
- package/dist/vue/index.js +68 -22
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -73,6 +73,14 @@ interface DocyrusAuthConfig {
|
|
|
73
73
|
* the host. No-op outside iframe mode. Default: false.
|
|
74
74
|
*/
|
|
75
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[];
|
|
76
84
|
/** React Native: custom URI scheme redirect (e.g., 'myapp://auth/callback'). Required when forceMode is 'react-native' */
|
|
77
85
|
nativeRedirectUri?: string;
|
|
78
86
|
/** React Native: function to open an in-app browser auth session (e.g., WebBrowser.openAuthSessionAsync from expo-web-browser) */
|
|
@@ -130,6 +138,12 @@ interface DocyrusAuthContextValue {
|
|
|
130
138
|
* subscriptions). No-op in non-iframe modes.
|
|
131
139
|
*/
|
|
132
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;
|
|
133
147
|
/** Any error that occurred during auth */
|
|
134
148
|
error: Error | null;
|
|
135
149
|
}
|
|
@@ -220,6 +234,26 @@ interface GuidyElementsMessage {
|
|
|
220
234
|
path: string;
|
|
221
235
|
elements: GuidyElement[];
|
|
222
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
|
+
}
|
|
223
257
|
/**
|
|
224
258
|
* Host → App: scroll to, highlight, and optionally annotate/click an element.
|
|
225
259
|
* The app renders the highlight/annotation itself — the host cannot draw into
|
|
@@ -254,7 +288,7 @@ interface GuidyPointAckMessage {
|
|
|
254
288
|
type GuidyCommandMessage = GuidyPointMessage | GuidyScanMessage;
|
|
255
289
|
/** Handler invoked when the host sends a Guidy command. */
|
|
256
290
|
type GuidyCommandHandler = (message: GuidyCommandMessage) => void;
|
|
257
|
-
type AppToHostMessage = TokenRefreshRequestMessage | AppRouteChangeMessage | GuidyElementsMessage | GuidyPointAckMessage;
|
|
291
|
+
type AppToHostMessage = TokenRefreshRequestMessage | AppRouteChangeMessage | GuidyElementsMessage | GuidyRoutesMessage | GuidyPointAckMessage;
|
|
258
292
|
/** Handler invoked when the host sends a navigation message */
|
|
259
293
|
type HostNavigationHandler = (message: HostNavigationMessage) => void;
|
|
260
294
|
/** Handler invoked when the host sends a notification message */
|
|
@@ -300,4 +334,4 @@ interface PermissionConfig {
|
|
|
300
334
|
alwaysPermittedDataSources?: Record<string, AclOperation[]>;
|
|
301
335
|
}
|
|
302
336
|
|
|
303
|
-
export type { AclOperation as A, DocyrusAuthConfig as D,
|
|
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-
|
|
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 {
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -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-
|
|
5
|
-
export { D as DocyrusAuthConfig } from '../types-
|
|
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
|
@@ -149,6 +149,20 @@ var StandaloneOAuth2Auth = class {
|
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
// src/core/jwt.ts
|
|
153
|
+
function parseJwtExp(accessToken) {
|
|
154
|
+
const parts = accessToken?.split(".");
|
|
155
|
+
if (!parts || parts.length < 2) return null;
|
|
156
|
+
try {
|
|
157
|
+
const payload = JSON.parse(
|
|
158
|
+
atob(parts[1].replace(/-/g, "+").replace(/_/g, "/"))
|
|
159
|
+
);
|
|
160
|
+
return typeof payload["exp"] === "number" ? payload["exp"] : null;
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
152
166
|
// src/core/iframe-auth.ts
|
|
153
167
|
function postToHost(data) {
|
|
154
168
|
const rnwv = window.ReactNativeWebView;
|
|
@@ -381,10 +395,11 @@ var IframeAuth = class {
|
|
|
381
395
|
}
|
|
382
396
|
handleSignin(signinData) {
|
|
383
397
|
if (!signinData.accessToken) return;
|
|
398
|
+
const exp = parseJwtExp(signinData.accessToken);
|
|
384
399
|
const tokens = {
|
|
385
400
|
accessToken: signinData.accessToken,
|
|
386
401
|
refreshToken: signinData.refreshToken,
|
|
387
|
-
expiresAt: Math.floor(Date.now() / 1e3) + 3600,
|
|
402
|
+
expiresAt: exp ?? Math.floor(Date.now() / 1e3) + 3600,
|
|
388
403
|
scope: ""
|
|
389
404
|
};
|
|
390
405
|
this.onTokensReceived?.(tokens);
|
|
@@ -449,6 +464,7 @@ function isVisible(node) {
|
|
|
449
464
|
}
|
|
450
465
|
var GuidyBridge = class {
|
|
451
466
|
send;
|
|
467
|
+
routes;
|
|
452
468
|
started = false;
|
|
453
469
|
observer = null;
|
|
454
470
|
scanTimer = null;
|
|
@@ -456,8 +472,14 @@ var GuidyBridge = class {
|
|
|
456
472
|
highlightTimer = null;
|
|
457
473
|
clickTimer = null;
|
|
458
474
|
annotationTimer = null;
|
|
459
|
-
constructor(send) {
|
|
475
|
+
constructor(send, routes = []) {
|
|
460
476
|
this.send = send;
|
|
477
|
+
this.routes = routes;
|
|
478
|
+
}
|
|
479
|
+
/** Replace the declared navigable routes and re-post them to the host. */
|
|
480
|
+
setRoutes(routes) {
|
|
481
|
+
this.routes = routes;
|
|
482
|
+
this.postRoutes();
|
|
461
483
|
}
|
|
462
484
|
/**
|
|
463
485
|
* Begin reporting the element inventory and watching for changes.
|
|
@@ -468,6 +490,7 @@ var GuidyBridge = class {
|
|
|
468
490
|
this.started = true;
|
|
469
491
|
this.ensureStyle();
|
|
470
492
|
this.postElements();
|
|
493
|
+
this.postRoutes();
|
|
471
494
|
this.observer = new MutationObserver(() => this.scheduleScan());
|
|
472
495
|
this.observer.observe(document.body, {
|
|
473
496
|
childList: true,
|
|
@@ -507,6 +530,7 @@ var GuidyBridge = class {
|
|
|
507
530
|
handleCommand(message) {
|
|
508
531
|
if (message.type === "guidy:scan") {
|
|
509
532
|
this.postElements();
|
|
533
|
+
this.postRoutes();
|
|
510
534
|
return;
|
|
511
535
|
}
|
|
512
536
|
if (message.type === "guidy:point") {
|
|
@@ -543,6 +567,10 @@ var GuidyBridge = class {
|
|
|
543
567
|
elements: this.collectElements()
|
|
544
568
|
});
|
|
545
569
|
}
|
|
570
|
+
postRoutes() {
|
|
571
|
+
if (!this.started) return;
|
|
572
|
+
this.send({ type: "guidy:routes", routes: this.routes });
|
|
573
|
+
}
|
|
546
574
|
scheduleScan() {
|
|
547
575
|
if (this.scanTimer) return;
|
|
548
576
|
this.scanTimer = setTimeout(() => {
|
|
@@ -820,6 +848,8 @@ var AuthManager = class {
|
|
|
820
848
|
guidyBridge = null;
|
|
821
849
|
reactNativeAuth = null;
|
|
822
850
|
tokenRefreshTimer = null;
|
|
851
|
+
/** Shared in-flight refresh, so concurrent requests don't trigger parallel refreshes. */
|
|
852
|
+
refreshInFlight = null;
|
|
823
853
|
listeners = /* @__PURE__ */ new Set();
|
|
824
854
|
navigationHandlers = /* @__PURE__ */ new Set();
|
|
825
855
|
notificationHandlers = /* @__PURE__ */ new Set();
|
|
@@ -992,11 +1022,22 @@ var AuthManager = class {
|
|
|
992
1022
|
*/
|
|
993
1023
|
startGuidyBridge() {
|
|
994
1024
|
if (!this.iframeAuth || this.guidyBridge) return;
|
|
995
|
-
const bridge = new GuidyBridge(
|
|
1025
|
+
const bridge = new GuidyBridge(
|
|
1026
|
+
(message) => this.iframeAuth?.sendToHost(message),
|
|
1027
|
+
this.config.guidyRoutes ?? []
|
|
1028
|
+
);
|
|
996
1029
|
this.iframeAuth.onGuidyCommand((message) => bridge.handleCommand(message));
|
|
997
1030
|
bridge.start();
|
|
998
1031
|
this.guidyBridge = bridge;
|
|
999
1032
|
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Iframe mode: replace the routes the Guidy bridge advertises to the host.
|
|
1035
|
+
* No-op unless the bridge is running (`enableGuidyBridge`).
|
|
1036
|
+
*/
|
|
1037
|
+
setGuidyRoutes(routes) {
|
|
1038
|
+
this.config.guidyRoutes = routes;
|
|
1039
|
+
this.guidyBridge?.setRoutes(routes);
|
|
1040
|
+
}
|
|
1000
1041
|
/**
|
|
1001
1042
|
* Iframe/WebView mode: start auto-syncing the embedded app's route
|
|
1002
1043
|
* to the host. Patches history methods and listens for popstate /
|
|
@@ -1209,26 +1250,41 @@ var AuthManager = class {
|
|
|
1209
1250
|
*/
|
|
1210
1251
|
async getValidToken() {
|
|
1211
1252
|
if (!this.tokens) return null;
|
|
1212
|
-
|
|
1213
|
-
|
|
1253
|
+
if (this.autoRefreshEnabled) {
|
|
1254
|
+
const expiresAt = this.resolveExpiry(this.tokens);
|
|
1214
1255
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
1215
|
-
|
|
1256
|
+
const needsRefresh = expiresAt === null || nowSec >= expiresAt - TOKEN_EXPIRY_BUFFER_SECONDS;
|
|
1257
|
+
if (needsRefresh) {
|
|
1216
1258
|
try {
|
|
1217
|
-
|
|
1218
|
-
return freshToken;
|
|
1259
|
+
return await this.handleTokenRefresh();
|
|
1219
1260
|
} catch {
|
|
1220
|
-
return null;
|
|
1261
|
+
return expiresAt === null ? this.tokens.accessToken : null;
|
|
1221
1262
|
}
|
|
1222
1263
|
}
|
|
1223
1264
|
}
|
|
1224
1265
|
return this.tokens.accessToken;
|
|
1225
1266
|
}
|
|
1226
1267
|
/**
|
|
1227
|
-
* Handle token refresh depending on mode
|
|
1268
|
+
* Handle token refresh depending on mode, sharing a single in-flight
|
|
1269
|
+
* request across concurrent callers. Multiple requests crossing the expiry
|
|
1270
|
+
* buffer at once (e.g. a dashboard firing several queries) would otherwise
|
|
1271
|
+
* each trigger their own refresh; with refresh-token rotation only the first
|
|
1272
|
+
* succeeds and the rest can leave us holding an expired token — exactly the
|
|
1273
|
+
* backend "JWTExpired" the proactive path is meant to prevent.
|
|
1274
|
+
*/
|
|
1275
|
+
handleTokenRefresh() {
|
|
1276
|
+
if (this.refreshInFlight) return this.refreshInFlight;
|
|
1277
|
+
this.refreshInFlight = this.performTokenRefresh().finally(() => {
|
|
1278
|
+
this.refreshInFlight = null;
|
|
1279
|
+
});
|
|
1280
|
+
return this.refreshInFlight;
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Refresh depending on mode.
|
|
1228
1284
|
* Standalone: use OAuth2Client.getValidAccessToken() which auto-refreshes.
|
|
1229
1285
|
* Iframe: send postMessage to host requesting new tokens.
|
|
1230
1286
|
*/
|
|
1231
|
-
async
|
|
1287
|
+
async performTokenRefresh() {
|
|
1232
1288
|
if (this.mode === "standalone" && this.standaloneAuth) {
|
|
1233
1289
|
const newTokens = await this.standaloneAuth.refreshToken();
|
|
1234
1290
|
this.tokens = newTokens;
|
|
@@ -1289,17 +1345,7 @@ var AuthManager = class {
|
|
|
1289
1345
|
*/
|
|
1290
1346
|
resolveExpiry(tokens) {
|
|
1291
1347
|
if (tokens.expiresAt) return tokens.expiresAt;
|
|
1292
|
-
|
|
1293
|
-
if (parts?.length >= 2) {
|
|
1294
|
-
try {
|
|
1295
|
-
const payload = JSON.parse(
|
|
1296
|
-
atob(parts[1].replace(/-/g, "+").replace(/_/g, "/"))
|
|
1297
|
-
);
|
|
1298
|
-
if (typeof payload["exp"] === "number") return payload["exp"];
|
|
1299
|
-
} catch {
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
return null;
|
|
1348
|
+
return parseJwtExp(tokens.accessToken);
|
|
1303
1349
|
}
|
|
1304
1350
|
/** Cleanup: remove listeners, timers, stop iframe auth. */
|
|
1305
1351
|
destroy() {
|