@docyrus/signin 0.9.0 → 0.10.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 +92 -0
- package/dist/{constants-BV7OGKHl.d.ts → constants-CPdSNbYg.d.ts} +20 -1
- package/dist/core-index.d.ts +21 -4
- package/dist/core-index.js +129 -6
- package/dist/core-index.js.map +1 -1
- package/dist/index.d.ts +20 -7
- package/dist/index.js +166 -7
- package/dist/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -5
- package/dist/react-native/index.js +145 -6
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-CmD-7GqC.d.ts → types-vd0OGryp.d.ts} +46 -1
- package/dist/{use-docyrus-client-BgaKblAo.d.ts → use-docyrus-client-y3Jm5PFJ.d.ts} +2 -3
- package/dist/vue/index.d.ts +4 -2
- package/dist/vue/index.js +140 -7
- package/dist/vue/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -87,6 +87,16 @@ interface DocyrusAuthContextValue {
|
|
|
87
87
|
hasPermission: (operation: string, dataSourceId?: string | null) => boolean;
|
|
88
88
|
/** Re-fetch the current user from the API */
|
|
89
89
|
refreshUser: () => Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Subscribe to host `navigation` messages (iframe/WebView mode only).
|
|
92
|
+
* Returns an unsubscribe function. No-op in non-iframe modes.
|
|
93
|
+
*/
|
|
94
|
+
onHostNavigation: (handler: HostNavigationHandler) => () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe to host `notification` messages (iframe/WebView mode only).
|
|
97
|
+
* Returns an unsubscribe function. No-op in non-iframe modes.
|
|
98
|
+
*/
|
|
99
|
+
onHostNotification: (handler: HostNotificationHandler) => () => void;
|
|
90
100
|
/** Any error that occurred during auth */
|
|
91
101
|
error: Error | null;
|
|
92
102
|
}
|
|
@@ -100,6 +110,41 @@ interface HostSignInMessage {
|
|
|
100
110
|
interface TokenRefreshRequestMessage {
|
|
101
111
|
type: 'token-refresh-request';
|
|
102
112
|
}
|
|
113
|
+
/** PostMessage payload: host asks the embedded app to navigate to a URL */
|
|
114
|
+
interface HostNavigationMessage {
|
|
115
|
+
type: 'navigation';
|
|
116
|
+
url: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Notification payload pushed from the host into the embedded app.
|
|
120
|
+
* Mirrors the NotificationEntity API contract.
|
|
121
|
+
*/
|
|
122
|
+
interface DocyrusNotification {
|
|
123
|
+
id: string;
|
|
124
|
+
subject: string;
|
|
125
|
+
message: string;
|
|
126
|
+
status: string;
|
|
127
|
+
seen: boolean;
|
|
128
|
+
created_on: string;
|
|
129
|
+
notify_on: string;
|
|
130
|
+
created_by: string;
|
|
131
|
+
record_owner: string;
|
|
132
|
+
created_by_id: string;
|
|
133
|
+
created_by_fullname: string;
|
|
134
|
+
created_by_photo: string;
|
|
135
|
+
params?: Record<string, unknown> | null;
|
|
136
|
+
tenant_app_id?: string | null;
|
|
137
|
+
output_render_template?: Record<string, unknown> | null;
|
|
138
|
+
}
|
|
139
|
+
/** PostMessage payload: host pushes a notification to the embedded app */
|
|
140
|
+
interface HostNotificationMessage {
|
|
141
|
+
type: 'notification';
|
|
142
|
+
notification: DocyrusNotification;
|
|
143
|
+
}
|
|
144
|
+
/** Handler invoked when the host sends a navigation message */
|
|
145
|
+
type HostNavigationHandler = (message: HostNavigationMessage) => void;
|
|
146
|
+
/** Handler invoked when the host sends a notification message */
|
|
147
|
+
type HostNotificationHandler = (notification: DocyrusNotification) => void;
|
|
103
148
|
/** A role object as returned by GET /v1/users/me */
|
|
104
149
|
interface DocyrusRole {
|
|
105
150
|
uid: string;
|
|
@@ -141,4 +186,4 @@ interface PermissionConfig {
|
|
|
141
186
|
alwaysPermittedDataSources?: Record<string, AclOperation[]>;
|
|
142
187
|
}
|
|
143
188
|
|
|
144
|
-
export type { AclOperation as A, DocyrusAuthConfig as D,
|
|
189
|
+
export type { AclOperation as A, DocyrusAuthConfig as D, HostNavigationHandler as H, OpenAuthSessionFn as O, PermissionConfig as P, 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, DocyrusNotification as i, HostNavigationMessage as j, HostNotificationMessage as k, HostSignInMessage as l };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import * as react from 'react';
|
|
3
2
|
import { ReactNode } from 'react';
|
|
4
|
-
import { D as DocyrusAuthConfig, e as DocyrusAuthContextValue } from './types-
|
|
3
|
+
import { D as DocyrusAuthConfig, e as DocyrusAuthContextValue } from './types-vd0OGryp.js';
|
|
5
4
|
import { RestApiClient } from '@docyrus/api-client';
|
|
6
5
|
|
|
7
6
|
interface DocyrusAuthProviderProps extends DocyrusAuthConfig {
|
|
8
7
|
children: ReactNode;
|
|
9
8
|
}
|
|
10
|
-
declare function DocyrusAuthProvider({ children, ...config }: DocyrusAuthProviderProps):
|
|
9
|
+
declare function DocyrusAuthProvider({ children, ...config }: DocyrusAuthProviderProps): react.JSX.Element;
|
|
11
10
|
|
|
12
11
|
declare const DocyrusAuthContext: react.Context<DocyrusAuthContextValue | null>;
|
|
13
12
|
|
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 } from '../types-
|
|
5
|
-
export { D as DocyrusAuthConfig } from '../types-
|
|
4
|
+
import { a as AuthMode, c as AuthStatus, H as HostNavigationHandler, h as HostNotificationHandler } from '../types-vd0OGryp.js';
|
|
5
|
+
export { D as DocyrusAuthConfig } from '../types-vd0OGryp.js';
|
|
6
6
|
|
|
7
7
|
interface DocyrusAuthState {
|
|
8
8
|
status: AuthStatus;
|
|
@@ -14,6 +14,8 @@ interface DocyrusAuthState {
|
|
|
14
14
|
signInWithTokens: (tokens: OAuth2Tokens) => Promise<void>;
|
|
15
15
|
getAuthorizationUrl: () => Promise<string | null>;
|
|
16
16
|
signOut: () => Promise<void>;
|
|
17
|
+
onHostNavigation: (handler: HostNavigationHandler) => () => void;
|
|
18
|
+
onHostNotification: (handler: HostNotificationHandler) => () => void;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Vue composable to access Docyrus auth state.
|
package/dist/vue/index.js
CHANGED
|
@@ -163,6 +163,8 @@ var IframeAuth = class {
|
|
|
163
163
|
allowedPattern;
|
|
164
164
|
isWebView;
|
|
165
165
|
onTokensReceived = null;
|
|
166
|
+
navigationHandlers = /* @__PURE__ */ new Set();
|
|
167
|
+
notificationHandlers = /* @__PURE__ */ new Set();
|
|
166
168
|
refreshPromise = null;
|
|
167
169
|
messageHandler = null;
|
|
168
170
|
constructor(allowedOrigins, allowedPattern) {
|
|
@@ -187,6 +189,28 @@ var IframeAuth = class {
|
|
|
187
189
|
this.messageHandler = null;
|
|
188
190
|
}
|
|
189
191
|
this.rejectPendingRefresh("IframeAuth stopped");
|
|
192
|
+
this.navigationHandlers.clear();
|
|
193
|
+
this.notificationHandlers.clear();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Subscribe to host navigation messages.
|
|
197
|
+
* Returns an unsubscribe function.
|
|
198
|
+
*/
|
|
199
|
+
onNavigation(handler) {
|
|
200
|
+
this.navigationHandlers.add(handler);
|
|
201
|
+
return () => {
|
|
202
|
+
this.navigationHandlers.delete(handler);
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Subscribe to host notification messages.
|
|
207
|
+
* Returns an unsubscribe function.
|
|
208
|
+
*/
|
|
209
|
+
onNotification(handler) {
|
|
210
|
+
this.notificationHandlers.add(handler);
|
|
211
|
+
return () => {
|
|
212
|
+
this.notificationHandlers.delete(handler);
|
|
213
|
+
};
|
|
190
214
|
}
|
|
191
215
|
/**
|
|
192
216
|
* Request fresh tokens from the host.
|
|
@@ -229,8 +253,20 @@ var IframeAuth = class {
|
|
|
229
253
|
handleMessage(ev) {
|
|
230
254
|
if (!this.isOriginAllowed(ev.origin)) return;
|
|
231
255
|
const data = ev.data;
|
|
232
|
-
if (!data || typeof data !== "object" || data.type !== "
|
|
233
|
-
|
|
256
|
+
if (!data || typeof data !== "object" || typeof data.type !== "string") return;
|
|
257
|
+
if (data.type === "signin") {
|
|
258
|
+
this.handleSignin(data);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (data.type === "navigation") {
|
|
262
|
+
this.handleNavigation(data);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (data.type === "notification") {
|
|
266
|
+
this.handleNotification(data);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
handleSignin(signinData) {
|
|
234
270
|
if (!signinData.accessToken) return;
|
|
235
271
|
const tokens = {
|
|
236
272
|
accessToken: signinData.accessToken,
|
|
@@ -245,6 +281,29 @@ var IframeAuth = class {
|
|
|
245
281
|
this.refreshPromise = null;
|
|
246
282
|
}
|
|
247
283
|
}
|
|
284
|
+
handleNavigation(message) {
|
|
285
|
+
if (typeof message.url !== "string" || message.url.length === 0) return;
|
|
286
|
+
for (const handler of this.navigationHandlers) {
|
|
287
|
+
try {
|
|
288
|
+
handler(message);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
console.warn("[docyrus-signin] host navigation handler threw:", err);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
handleNotification(message) {
|
|
295
|
+
const notification = message.notification;
|
|
296
|
+
if (!notification || typeof notification !== "object" || typeof notification.id !== "string") {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
for (const handler of this.notificationHandlers) {
|
|
300
|
+
try {
|
|
301
|
+
handler(notification);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
console.warn("[docyrus-signin] host notification handler threw:", err);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
248
307
|
rejectPendingRefresh(reason) {
|
|
249
308
|
if (this.refreshPromise) {
|
|
250
309
|
clearTimeout(this.refreshPromise.timeoutId);
|
|
@@ -417,6 +476,8 @@ var AuthManager = class {
|
|
|
417
476
|
reactNativeAuth = null;
|
|
418
477
|
tokenRefreshTimer = null;
|
|
419
478
|
listeners = /* @__PURE__ */ new Set();
|
|
479
|
+
navigationHandlers = /* @__PURE__ */ new Set();
|
|
480
|
+
notificationHandlers = /* @__PURE__ */ new Set();
|
|
420
481
|
config;
|
|
421
482
|
constructor(config = {}) {
|
|
422
483
|
this.config = config;
|
|
@@ -555,6 +616,46 @@ var AuthManager = class {
|
|
|
555
616
|
this.iframeAuth.start((tokens) => {
|
|
556
617
|
this.setAuthenticated(tokens);
|
|
557
618
|
});
|
|
619
|
+
this.iframeAuth.onNavigation((message) => {
|
|
620
|
+
for (const handler of this.navigationHandlers) {
|
|
621
|
+
try {
|
|
622
|
+
handler(message);
|
|
623
|
+
} catch (err) {
|
|
624
|
+
console.warn("[docyrus-signin] host navigation handler threw:", err);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
this.iframeAuth.onNotification((notification) => {
|
|
629
|
+
for (const handler of this.notificationHandlers) {
|
|
630
|
+
try {
|
|
631
|
+
handler(notification);
|
|
632
|
+
} catch (err) {
|
|
633
|
+
console.warn("[docyrus-signin] host notification handler threw:", err);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Subscribe to host `navigation` messages. Returns an unsubscribe function.
|
|
640
|
+
* Handlers registered before iframe mode is initialized are retained and
|
|
641
|
+
* will fire once messages arrive. No-op in non-iframe modes.
|
|
642
|
+
*/
|
|
643
|
+
onHostNavigation(handler) {
|
|
644
|
+
this.navigationHandlers.add(handler);
|
|
645
|
+
return () => {
|
|
646
|
+
this.navigationHandlers.delete(handler);
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Subscribe to host `notification` messages. Returns an unsubscribe function.
|
|
651
|
+
* Handlers registered before iframe mode is initialized are retained and
|
|
652
|
+
* will fire once messages arrive. No-op in non-iframe modes.
|
|
653
|
+
*/
|
|
654
|
+
onHostNotification(handler) {
|
|
655
|
+
this.notificationHandlers.add(handler);
|
|
656
|
+
return () => {
|
|
657
|
+
this.notificationHandlers.delete(handler);
|
|
658
|
+
};
|
|
558
659
|
}
|
|
559
660
|
/**
|
|
560
661
|
* React Native mode initialization.
|
|
@@ -725,9 +826,10 @@ var AuthManager = class {
|
|
|
725
826
|
*/
|
|
726
827
|
async getValidToken() {
|
|
727
828
|
if (!this.tokens) return null;
|
|
728
|
-
|
|
829
|
+
const expiresAt = this.resolveExpiry(this.tokens);
|
|
830
|
+
if (this.autoRefreshEnabled && expiresAt) {
|
|
729
831
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
730
|
-
if (nowSec >=
|
|
832
|
+
if (nowSec >= expiresAt - TOKEN_EXPIRY_BUFFER_SECONDS) {
|
|
731
833
|
try {
|
|
732
834
|
const freshToken = await this.handleTokenRefresh();
|
|
733
835
|
return freshToken;
|
|
@@ -771,8 +873,9 @@ var AuthManager = class {
|
|
|
771
873
|
scheduleTokenRefresh(tokens) {
|
|
772
874
|
this.clearTokenRefreshTimer();
|
|
773
875
|
if (!this.autoRefreshEnabled) return;
|
|
774
|
-
|
|
775
|
-
|
|
876
|
+
const expiresAt = this.resolveExpiry(tokens);
|
|
877
|
+
if (!expiresAt) return;
|
|
878
|
+
const expiresAtMs = expiresAt * 1e3;
|
|
776
879
|
const bufferMs = TOKEN_EXPIRY_BUFFER_SECONDS * 1e3;
|
|
777
880
|
const refreshInMs = expiresAtMs - bufferMs - Date.now();
|
|
778
881
|
if (refreshInMs <= 0) {
|
|
@@ -797,11 +900,31 @@ var AuthManager = class {
|
|
|
797
900
|
this.tokenRefreshTimer = null;
|
|
798
901
|
}
|
|
799
902
|
}
|
|
903
|
+
/**
|
|
904
|
+
* Resolve token expiry from stored expiresAt, falling back to the JWT exp
|
|
905
|
+
* claim when expiresAt is absent (e.g. server omitted expires_in).
|
|
906
|
+
*/
|
|
907
|
+
resolveExpiry(tokens) {
|
|
908
|
+
if (tokens.expiresAt) return tokens.expiresAt;
|
|
909
|
+
const parts = tokens.accessToken?.split(".");
|
|
910
|
+
if (parts?.length >= 2) {
|
|
911
|
+
try {
|
|
912
|
+
const payload = JSON.parse(
|
|
913
|
+
atob(parts[1].replace(/-/g, "+").replace(/_/g, "/"))
|
|
914
|
+
);
|
|
915
|
+
if (typeof payload["exp"] === "number") return payload["exp"];
|
|
916
|
+
} catch {
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return null;
|
|
920
|
+
}
|
|
800
921
|
/** Cleanup: remove listeners, timers, stop iframe auth. */
|
|
801
922
|
destroy() {
|
|
802
923
|
this.clearTokenRefreshTimer();
|
|
803
924
|
if (this.iframeAuth) this.iframeAuth.stop();
|
|
804
925
|
this.listeners.clear();
|
|
926
|
+
this.navigationHandlers.clear();
|
|
927
|
+
this.notificationHandlers.clear();
|
|
805
928
|
}
|
|
806
929
|
};
|
|
807
930
|
|
|
@@ -855,6 +978,14 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
855
978
|
const getAuthorizationUrl = async () => {
|
|
856
979
|
return manager?.getAuthorizationUrl() ?? null;
|
|
857
980
|
};
|
|
981
|
+
const onHostNavigation = (handler) => {
|
|
982
|
+
return manager?.onHostNavigation(handler) ?? (() => {
|
|
983
|
+
});
|
|
984
|
+
};
|
|
985
|
+
const onHostNotification = (handler) => {
|
|
986
|
+
return manager?.onHostNotification(handler) ?? (() => {
|
|
987
|
+
});
|
|
988
|
+
};
|
|
858
989
|
const authState = {
|
|
859
990
|
get status() {
|
|
860
991
|
return status.value;
|
|
@@ -874,7 +1005,9 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
874
1005
|
signIn,
|
|
875
1006
|
signInWithTokens,
|
|
876
1007
|
getAuthorizationUrl,
|
|
877
|
-
signOut
|
|
1008
|
+
signOut,
|
|
1009
|
+
onHostNavigation,
|
|
1010
|
+
onHostNotification
|
|
878
1011
|
};
|
|
879
1012
|
provide(DOCYRUS_AUTH_KEY, authState);
|
|
880
1013
|
onMounted(() => {
|