@docyrus/signin 0.9.1 → 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.
@@ -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, HostSignInMessage 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 };
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-CmD-7GqC.js';
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): react_jsx_runtime.JSX.Element;
9
+ declare function DocyrusAuthProvider({ children, ...config }: DocyrusAuthProviderProps): react.JSX.Element;
11
10
 
12
11
  declare const DocyrusAuthContext: react.Context<DocyrusAuthContextValue | null>;
13
12
 
@@ -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-CmD-7GqC.js';
5
- export { D as DocyrusAuthConfig } from '../types-CmD-7GqC.js';
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 !== "signin") return;
233
- const signinData = data;
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.
@@ -822,6 +923,8 @@ var AuthManager = class {
822
923
  this.clearTokenRefreshTimer();
823
924
  if (this.iframeAuth) this.iframeAuth.stop();
824
925
  this.listeners.clear();
926
+ this.navigationHandlers.clear();
927
+ this.notificationHandlers.clear();
825
928
  }
826
929
  };
827
930
 
@@ -875,6 +978,14 @@ var DocyrusAuthProvider = defineComponent({
875
978
  const getAuthorizationUrl = async () => {
876
979
  return manager?.getAuthorizationUrl() ?? null;
877
980
  };
981
+ const onHostNavigation = (handler) => {
982
+ return manager?.onHostNavigation(handler) ?? (() => {
983
+ });
984
+ };
985
+ const onHostNotification = (handler) => {
986
+ return manager?.onHostNotification(handler) ?? (() => {
987
+ });
988
+ };
878
989
  const authState = {
879
990
  get status() {
880
991
  return status.value;
@@ -894,7 +1005,9 @@ var DocyrusAuthProvider = defineComponent({
894
1005
  signIn,
895
1006
  signInWithTokens,
896
1007
  getAuthorizationUrl,
897
- signOut
1008
+ signOut,
1009
+ onHostNavigation,
1010
+ onHostNotification
898
1011
  };
899
1012
  provide(DOCYRUS_AUTH_KEY, authState);
900
1013
  onMounted(() => {