@docyrus/signin 0.14.0 → 0.15.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.
- package/README.md +57 -0
- package/dist/{constants-DtyJKJgJ.d.ts → constants-BoAqIz2O.d.ts} +20 -3
- package/dist/core-index.d.ts +11 -4
- package/dist/core-index.js +63 -20
- package/dist/core-index.js.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.js +75 -21
- package/dist/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/react-native/index.js +70 -20
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-D4ZAVj-B.d.ts → types-DzwC4Dk7.d.ts} +32 -2
- package/dist/{use-docyrus-client-o9nPwayd.d.ts → use-docyrus-client-pU5z5ZHe.d.ts} +1 -1
- package/dist/vue/index.d.ts +3 -2
- package/dist/vue/index.js +68 -21
- package/dist/vue/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -138,6 +138,13 @@ interface DocyrusAuthContextValue {
|
|
|
138
138
|
* subscriptions). No-op in non-iframe modes.
|
|
139
139
|
*/
|
|
140
140
|
notifyRouteChange: (payload?: RouteChangePayload) => void;
|
|
141
|
+
/**
|
|
142
|
+
* Iframe/WebView mode: ask the host shell to navigate to a path/URL.
|
|
143
|
+
* The reverse of `onHostNavigation` — lets an in-app action drive the
|
|
144
|
+
* host's own routing (deep link, switch view, open a sibling app). The
|
|
145
|
+
* host decides how to honour the request. No-op in non-iframe modes.
|
|
146
|
+
*/
|
|
147
|
+
requestHostNavigation: (url: string, options?: HostNavigationRequestOptions) => void;
|
|
141
148
|
/**
|
|
142
149
|
* Iframe mode (Guidy bridge): replace the routes the host assistant may
|
|
143
150
|
* navigate the user to inside this app. No-op unless `enableGuidyBridge`
|
|
@@ -184,6 +191,29 @@ interface HostNavigationMessage {
|
|
|
184
191
|
type: 'navigation';
|
|
185
192
|
url: string;
|
|
186
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* PostMessage payload: the embedded app asks the host shell to navigate to a
|
|
196
|
+
* path/URL. The reverse of `HostNavigationMessage` — used when an in-app action
|
|
197
|
+
* needs to drive the host's own routing (deep link, switch view, open a
|
|
198
|
+
* sibling app). The host decides how to honour it. Unlike `route-change`, which
|
|
199
|
+
* passively reports the app's current route, this is an explicit request.
|
|
200
|
+
*/
|
|
201
|
+
interface AppNavigationRequestMessage {
|
|
202
|
+
type: 'navigation-request';
|
|
203
|
+
/** Target path or absolute URL for the host shell to navigate to. */
|
|
204
|
+
url: string;
|
|
205
|
+
/** Hint the host to replace the current history entry instead of pushing. */
|
|
206
|
+
replace?: boolean;
|
|
207
|
+
/** Hint the host to open the target in a new tab/window instead of in place. */
|
|
208
|
+
newTab?: boolean;
|
|
209
|
+
}
|
|
210
|
+
/** Options for `requestHostNavigation` (app → host navigation request). */
|
|
211
|
+
interface HostNavigationRequestOptions {
|
|
212
|
+
/** Hint the host to replace the current history entry instead of pushing. */
|
|
213
|
+
replace?: boolean;
|
|
214
|
+
/** Hint the host to open the target in a new tab/window instead of in place. */
|
|
215
|
+
newTab?: boolean;
|
|
216
|
+
}
|
|
187
217
|
/**
|
|
188
218
|
* Notification payload pushed from the host into the embedded app.
|
|
189
219
|
* Mirrors the NotificationEntity API contract.
|
|
@@ -288,7 +318,7 @@ interface GuidyPointAckMessage {
|
|
|
288
318
|
type GuidyCommandMessage = GuidyPointMessage | GuidyScanMessage;
|
|
289
319
|
/** Handler invoked when the host sends a Guidy command. */
|
|
290
320
|
type GuidyCommandHandler = (message: GuidyCommandMessage) => void;
|
|
291
|
-
type AppToHostMessage = TokenRefreshRequestMessage | AppRouteChangeMessage | GuidyElementsMessage | GuidyRoutesMessage | GuidyPointAckMessage;
|
|
321
|
+
type AppToHostMessage = TokenRefreshRequestMessage | AppRouteChangeMessage | AppNavigationRequestMessage | GuidyElementsMessage | GuidyRoutesMessage | GuidyPointAckMessage;
|
|
292
322
|
/** Handler invoked when the host sends a navigation message */
|
|
293
323
|
type HostNavigationHandler = (message: HostNavigationMessage) => void;
|
|
294
324
|
/** Handler invoked when the host sends a notification message */
|
|
@@ -334,4 +364,4 @@ interface PermissionConfig {
|
|
|
334
364
|
alwaysPermittedDataSources?: Record<string, AclOperation[]>;
|
|
335
365
|
}
|
|
336
366
|
|
|
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,
|
|
367
|
+
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, HostNavigationRequestOptions as i, AppNavigationRequestMessage as j, AppRouteChangeMessage as k, DocyrusNotification as l, GuidyCommandHandler as m, GuidyCommandMessage as n, GuidyElement as o, GuidyElementsMessage as p, GuidyPointAckMessage as q, GuidyPointMessage as r, GuidyRoutesMessage as s, GuidyScanMessage as t, HostNavigationMessage as u, HostNotificationMessage as v, HostSignInMessage as w, AppToHostMessage as x };
|
|
@@ -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-DzwC4Dk7.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, i as HostNavigationRequestOptions } from '../types-DzwC4Dk7.js';
|
|
5
|
+
export { D as DocyrusAuthConfig } from '../types-DzwC4Dk7.js';
|
|
6
6
|
|
|
7
7
|
interface DocyrusAuthState {
|
|
8
8
|
status: AuthStatus;
|
|
@@ -18,6 +18,7 @@ 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;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Vue composable to access Docyrus auth state.
|
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;
|
|
@@ -257,6 +271,19 @@ var IframeAuth = class {
|
|
|
257
271
|
url: `${path}${search}${hash}`
|
|
258
272
|
});
|
|
259
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Ask the host shell to navigate to a path/URL. The reverse of the
|
|
276
|
+
* host → app `navigation` message: posts a `navigation-request` over the
|
|
277
|
+
* same validated channel. The host decides how to honour it.
|
|
278
|
+
*/
|
|
279
|
+
requestHostNavigation(url, options) {
|
|
280
|
+
if (this.stopped) return;
|
|
281
|
+
if (typeof url !== "string" || url.length === 0) return;
|
|
282
|
+
const message = { type: "navigation-request", url };
|
|
283
|
+
if (options?.replace) message.replace = true;
|
|
284
|
+
if (options?.newTab) message.newTab = true;
|
|
285
|
+
this.sendToHost(message);
|
|
286
|
+
}
|
|
260
287
|
teardownRouteSync() {
|
|
261
288
|
if (!this.routeSyncEnabled) return;
|
|
262
289
|
if (typeof window !== "undefined") {
|
|
@@ -381,10 +408,11 @@ var IframeAuth = class {
|
|
|
381
408
|
}
|
|
382
409
|
handleSignin(signinData) {
|
|
383
410
|
if (!signinData.accessToken) return;
|
|
411
|
+
const exp = parseJwtExp(signinData.accessToken);
|
|
384
412
|
const tokens = {
|
|
385
413
|
accessToken: signinData.accessToken,
|
|
386
414
|
refreshToken: signinData.refreshToken,
|
|
387
|
-
expiresAt: Math.floor(Date.now() / 1e3) + 3600,
|
|
415
|
+
expiresAt: exp ?? Math.floor(Date.now() / 1e3) + 3600,
|
|
388
416
|
scope: ""
|
|
389
417
|
};
|
|
390
418
|
this.onTokensReceived?.(tokens);
|
|
@@ -833,6 +861,8 @@ var AuthManager = class {
|
|
|
833
861
|
guidyBridge = null;
|
|
834
862
|
reactNativeAuth = null;
|
|
835
863
|
tokenRefreshTimer = null;
|
|
864
|
+
/** Shared in-flight refresh, so concurrent requests don't trigger parallel refreshes. */
|
|
865
|
+
refreshInFlight = null;
|
|
836
866
|
listeners = /* @__PURE__ */ new Set();
|
|
837
867
|
navigationHandlers = /* @__PURE__ */ new Set();
|
|
838
868
|
notificationHandlers = /* @__PURE__ */ new Set();
|
|
@@ -1038,6 +1068,14 @@ var AuthManager = class {
|
|
|
1038
1068
|
notifyHostRouteChange(payload) {
|
|
1039
1069
|
this.iframeAuth?.notifyRouteChange(payload);
|
|
1040
1070
|
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Iframe/WebView mode: ask the host shell to navigate to a path/URL.
|
|
1073
|
+
* Posts a `navigation-request` message; the host decides how to honour it.
|
|
1074
|
+
* No-op outside iframe mode.
|
|
1075
|
+
*/
|
|
1076
|
+
requestHostNavigation(url, options) {
|
|
1077
|
+
this.iframeAuth?.requestHostNavigation(url, options);
|
|
1078
|
+
}
|
|
1041
1079
|
/**
|
|
1042
1080
|
* Subscribe to host `navigation` messages. Returns an unsubscribe function.
|
|
1043
1081
|
* Handlers registered before iframe mode is initialized are retained and
|
|
@@ -1233,26 +1271,41 @@ var AuthManager = class {
|
|
|
1233
1271
|
*/
|
|
1234
1272
|
async getValidToken() {
|
|
1235
1273
|
if (!this.tokens) return null;
|
|
1236
|
-
|
|
1237
|
-
|
|
1274
|
+
if (this.autoRefreshEnabled) {
|
|
1275
|
+
const expiresAt = this.resolveExpiry(this.tokens);
|
|
1238
1276
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
1239
|
-
|
|
1277
|
+
const needsRefresh = expiresAt === null || nowSec >= expiresAt - TOKEN_EXPIRY_BUFFER_SECONDS;
|
|
1278
|
+
if (needsRefresh) {
|
|
1240
1279
|
try {
|
|
1241
|
-
|
|
1242
|
-
return freshToken;
|
|
1280
|
+
return await this.handleTokenRefresh();
|
|
1243
1281
|
} catch {
|
|
1244
|
-
return null;
|
|
1282
|
+
return expiresAt === null ? this.tokens.accessToken : null;
|
|
1245
1283
|
}
|
|
1246
1284
|
}
|
|
1247
1285
|
}
|
|
1248
1286
|
return this.tokens.accessToken;
|
|
1249
1287
|
}
|
|
1250
1288
|
/**
|
|
1251
|
-
* Handle token refresh depending on mode
|
|
1289
|
+
* Handle token refresh depending on mode, sharing a single in-flight
|
|
1290
|
+
* request across concurrent callers. Multiple requests crossing the expiry
|
|
1291
|
+
* buffer at once (e.g. a dashboard firing several queries) would otherwise
|
|
1292
|
+
* each trigger their own refresh; with refresh-token rotation only the first
|
|
1293
|
+
* succeeds and the rest can leave us holding an expired token — exactly the
|
|
1294
|
+
* backend "JWTExpired" the proactive path is meant to prevent.
|
|
1295
|
+
*/
|
|
1296
|
+
handleTokenRefresh() {
|
|
1297
|
+
if (this.refreshInFlight) return this.refreshInFlight;
|
|
1298
|
+
this.refreshInFlight = this.performTokenRefresh().finally(() => {
|
|
1299
|
+
this.refreshInFlight = null;
|
|
1300
|
+
});
|
|
1301
|
+
return this.refreshInFlight;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Refresh depending on mode.
|
|
1252
1305
|
* Standalone: use OAuth2Client.getValidAccessToken() which auto-refreshes.
|
|
1253
1306
|
* Iframe: send postMessage to host requesting new tokens.
|
|
1254
1307
|
*/
|
|
1255
|
-
async
|
|
1308
|
+
async performTokenRefresh() {
|
|
1256
1309
|
if (this.mode === "standalone" && this.standaloneAuth) {
|
|
1257
1310
|
const newTokens = await this.standaloneAuth.refreshToken();
|
|
1258
1311
|
this.tokens = newTokens;
|
|
@@ -1313,17 +1366,7 @@ var AuthManager = class {
|
|
|
1313
1366
|
*/
|
|
1314
1367
|
resolveExpiry(tokens) {
|
|
1315
1368
|
if (tokens.expiresAt) return tokens.expiresAt;
|
|
1316
|
-
|
|
1317
|
-
if (parts?.length >= 2) {
|
|
1318
|
-
try {
|
|
1319
|
-
const payload = JSON.parse(
|
|
1320
|
-
atob(parts[1].replace(/-/g, "+").replace(/_/g, "/"))
|
|
1321
|
-
);
|
|
1322
|
-
if (typeof payload["exp"] === "number") return payload["exp"];
|
|
1323
|
-
} catch {
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
return null;
|
|
1369
|
+
return parseJwtExp(tokens.accessToken);
|
|
1327
1370
|
}
|
|
1328
1371
|
/** Cleanup: remove listeners, timers, stop iframe auth. */
|
|
1329
1372
|
destroy() {
|
|
@@ -1404,6 +1447,9 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1404
1447
|
const notifyRouteChange = (payload) => {
|
|
1405
1448
|
manager?.notifyHostRouteChange(payload);
|
|
1406
1449
|
};
|
|
1450
|
+
const requestHostNavigation = (url, options) => {
|
|
1451
|
+
manager?.requestHostNavigation(url, options);
|
|
1452
|
+
};
|
|
1407
1453
|
const authState = {
|
|
1408
1454
|
get status() {
|
|
1409
1455
|
return status.value;
|
|
@@ -1427,7 +1473,8 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1427
1473
|
onHostNavigation,
|
|
1428
1474
|
onHostNotification,
|
|
1429
1475
|
enableHostRouteSync,
|
|
1430
|
-
notifyRouteChange
|
|
1476
|
+
notifyRouteChange,
|
|
1477
|
+
requestHostNavigation
|
|
1431
1478
|
};
|
|
1432
1479
|
provide(DOCYRUS_AUTH_KEY, authState);
|
|
1433
1480
|
onMounted(() => {
|