@docyrus/signin 0.10.0 → 0.12.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 +60 -0
- package/dist/{constants-CPdSNbYg.d.ts → constants-DuNDcs9I.d.ts} +14 -1
- package/dist/core-index.d.ts +23 -4
- package/dist/core-index.js +99 -0
- package/dist/core-index.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js +120 -1
- package/dist/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/react-native/index.js +113 -0
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-vd0OGryp.d.ts → types-DjG8tL1X.d.ts} +45 -1
- package/dist/{use-docyrus-client-y3Jm5PFJ.d.ts → use-docyrus-client-CQ0J_msv.d.ts} +1 -1
- package/dist/vue/index.d.ts +13 -2
- package/dist/vue/index.js +112 -3
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -54,6 +54,14 @@ interface DocyrusAuthConfig {
|
|
|
54
54
|
ssr?: boolean;
|
|
55
55
|
/** Cookie name for SSR token sync. Default: 'docyrus-token' */
|
|
56
56
|
ssrCookieKey?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Iframe/WebView mode: post a `route-change` message to the host on
|
|
59
|
+
* every history change so the host can reflect the embedded app's
|
|
60
|
+
* route in its address bar. Patches `history.pushState/replaceState`
|
|
61
|
+
* and listens for `popstate`/`hashchange`. No-op outside iframe mode.
|
|
62
|
+
* Default: false.
|
|
63
|
+
*/
|
|
64
|
+
syncRouteToHost?: boolean;
|
|
57
65
|
/** React Native: custom URI scheme redirect (e.g., 'myapp://auth/callback'). Required when forceMode is 'react-native' */
|
|
58
66
|
nativeRedirectUri?: string;
|
|
59
67
|
/** React Native: function to open an in-app browser auth session (e.g., WebBrowser.openAuthSessionAsync from expo-web-browser) */
|
|
@@ -97,6 +105,20 @@ interface DocyrusAuthContextValue {
|
|
|
97
105
|
* Returns an unsubscribe function. No-op in non-iframe modes.
|
|
98
106
|
*/
|
|
99
107
|
onHostNotification: (handler: HostNotificationHandler) => () => void;
|
|
108
|
+
/**
|
|
109
|
+
* Iframe/WebView mode: start auto-syncing the embedded app's route
|
|
110
|
+
* to the host. Patches `history.pushState/replaceState` and listens
|
|
111
|
+
* for `popstate`/`hashchange`. Safe to call multiple times. No-op in
|
|
112
|
+
* non-iframe modes.
|
|
113
|
+
*/
|
|
114
|
+
enableHostRouteSync: () => void;
|
|
115
|
+
/**
|
|
116
|
+
* Iframe/WebView mode: post a single `route-change` message to the host.
|
|
117
|
+
* When called with no argument, the current `window.location` is read.
|
|
118
|
+
* Pass a payload to report a specific route (useful with router
|
|
119
|
+
* subscriptions). No-op in non-iframe modes.
|
|
120
|
+
*/
|
|
121
|
+
notifyRouteChange: (payload?: RouteChangePayload) => void;
|
|
100
122
|
/** Any error that occurred during auth */
|
|
101
123
|
error: Error | null;
|
|
102
124
|
}
|
|
@@ -110,6 +132,28 @@ interface HostSignInMessage {
|
|
|
110
132
|
interface TokenRefreshRequestMessage {
|
|
111
133
|
type: 'token-refresh-request';
|
|
112
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* PostMessage payload: app reports its current route to the host.
|
|
137
|
+
* Sent on every history change so the host can reflect it in the
|
|
138
|
+
* browser address bar.
|
|
139
|
+
*/
|
|
140
|
+
interface AppRouteChangeMessage {
|
|
141
|
+
type: 'route-change';
|
|
142
|
+
/** location.pathname (e.g. "/customers/123") */
|
|
143
|
+
path: string;
|
|
144
|
+
/** location.search including leading "?" — empty string if none */
|
|
145
|
+
search: string;
|
|
146
|
+
/** location.hash including leading "#" — empty string if none */
|
|
147
|
+
hash: string;
|
|
148
|
+
/** Convenience: `path + search + hash` */
|
|
149
|
+
url: string;
|
|
150
|
+
}
|
|
151
|
+
/** Payload for manual `notifyRouteChange` calls */
|
|
152
|
+
interface RouteChangePayload {
|
|
153
|
+
path?: string;
|
|
154
|
+
search?: string;
|
|
155
|
+
hash?: string;
|
|
156
|
+
}
|
|
113
157
|
/** PostMessage payload: host asks the embedded app to navigate to a URL */
|
|
114
158
|
interface HostNavigationMessage {
|
|
115
159
|
type: 'navigation';
|
|
@@ -186,4 +230,4 @@ interface PermissionConfig {
|
|
|
186
230
|
alwaysPermittedDataSources?: Record<string, AclOperation[]>;
|
|
187
231
|
}
|
|
188
232
|
|
|
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,
|
|
233
|
+
export type { AclOperation as A, DocyrusAuthConfig as D, 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, HostNavigationMessage as k, HostNotificationMessage as l, HostSignInMessage as m };
|
|
@@ -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-DjG8tL1X.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 } 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-DjG8tL1X.js';
|
|
5
|
+
export { D as DocyrusAuthConfig } from '../types-DjG8tL1X.js';
|
|
6
6
|
|
|
7
7
|
interface DocyrusAuthState {
|
|
8
8
|
status: AuthStatus;
|
|
@@ -16,6 +16,8 @@ interface DocyrusAuthState {
|
|
|
16
16
|
signOut: () => Promise<void>;
|
|
17
17
|
onHostNavigation: (handler: HostNavigationHandler) => () => void;
|
|
18
18
|
onHostNotification: (handler: HostNotificationHandler) => () => void;
|
|
19
|
+
enableHostRouteSync: () => void;
|
|
20
|
+
notifyRouteChange: (payload?: RouteChangePayload) => void;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Vue composable to access Docyrus auth state.
|
|
@@ -90,6 +92,10 @@ declare const DocyrusAuthProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
90
92
|
type: PropType<OAuth2Tokens>;
|
|
91
93
|
default: undefined;
|
|
92
94
|
};
|
|
95
|
+
syncRouteToHost: {
|
|
96
|
+
type: BooleanConstructor;
|
|
97
|
+
default: boolean;
|
|
98
|
+
};
|
|
93
99
|
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
94
100
|
[key: string]: any;
|
|
95
101
|
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
@@ -133,6 +139,10 @@ declare const DocyrusAuthProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
133
139
|
type: PropType<OAuth2Tokens>;
|
|
134
140
|
default: undefined;
|
|
135
141
|
};
|
|
142
|
+
syncRouteToHost: {
|
|
143
|
+
type: BooleanConstructor;
|
|
144
|
+
default: boolean;
|
|
145
|
+
};
|
|
136
146
|
}>> & Readonly<{}>, {
|
|
137
147
|
clientId: string;
|
|
138
148
|
apiUrl: string;
|
|
@@ -144,6 +154,7 @@ declare const DocyrusAuthProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
144
154
|
tokenStorage: OAuth2TokenStorage;
|
|
145
155
|
forceMode: AuthMode;
|
|
146
156
|
initialTokens: OAuth2Tokens;
|
|
157
|
+
syncRouteToHost: boolean;
|
|
147
158
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
148
159
|
/**
|
|
149
160
|
* "Sign in with Docyrus" button component.
|
package/dist/vue/index.js
CHANGED
|
@@ -152,10 +152,13 @@ var StandaloneOAuth2Auth = class {
|
|
|
152
152
|
// src/core/iframe-auth.ts
|
|
153
153
|
function postToHost(data) {
|
|
154
154
|
const rnwv = window.ReactNativeWebView;
|
|
155
|
+
const tap = window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__;
|
|
155
156
|
if (rnwv && typeof rnwv.postMessage === "function") {
|
|
157
|
+
if (typeof tap === "function") tap("out", data, { transport: "webview" });
|
|
156
158
|
rnwv.postMessage(JSON.stringify(data));
|
|
157
159
|
return;
|
|
158
160
|
}
|
|
161
|
+
if (typeof tap === "function") tap("out", data, { transport: "iframe", targetOrigin: "*" });
|
|
159
162
|
window.parent.postMessage(data, "*");
|
|
160
163
|
}
|
|
161
164
|
var IframeAuth = class {
|
|
@@ -165,6 +168,11 @@ var IframeAuth = class {
|
|
|
165
168
|
onTokensReceived = null;
|
|
166
169
|
navigationHandlers = /* @__PURE__ */ new Set();
|
|
167
170
|
notificationHandlers = /* @__PURE__ */ new Set();
|
|
171
|
+
routeSyncEnabled = false;
|
|
172
|
+
originalPushState = null;
|
|
173
|
+
originalReplaceState = null;
|
|
174
|
+
routeChangeListener = null;
|
|
175
|
+
stopped = false;
|
|
168
176
|
refreshPromise = null;
|
|
169
177
|
messageHandler = null;
|
|
170
178
|
constructor(allowedOrigins, allowedPattern) {
|
|
@@ -184,6 +192,7 @@ var IframeAuth = class {
|
|
|
184
192
|
}
|
|
185
193
|
/** Stop listening for postMessage events. */
|
|
186
194
|
stop() {
|
|
195
|
+
this.stopped = true;
|
|
187
196
|
if (this.messageHandler) {
|
|
188
197
|
window.removeEventListener("message", this.messageHandler);
|
|
189
198
|
this.messageHandler = null;
|
|
@@ -191,6 +200,76 @@ var IframeAuth = class {
|
|
|
191
200
|
this.rejectPendingRefresh("IframeAuth stopped");
|
|
192
201
|
this.navigationHandlers.clear();
|
|
193
202
|
this.notificationHandlers.clear();
|
|
203
|
+
this.teardownRouteSync();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Patch history methods + listen for popstate/hashchange so every
|
|
207
|
+
* route change posts a `route-change` message to the host.
|
|
208
|
+
* Idempotent. Fires an immediate message with the current route.
|
|
209
|
+
*/
|
|
210
|
+
enableRouteSync() {
|
|
211
|
+
if (this.routeSyncEnabled || typeof window === "undefined") return;
|
|
212
|
+
this.routeSyncEnabled = true;
|
|
213
|
+
const { history } = window;
|
|
214
|
+
this.originalPushState = history.pushState.bind(history);
|
|
215
|
+
this.originalReplaceState = history.replaceState.bind(history);
|
|
216
|
+
history.pushState = (...args) => {
|
|
217
|
+
const result = this.originalPushState?.(...args);
|
|
218
|
+
this.notifyRouteChange();
|
|
219
|
+
return result;
|
|
220
|
+
};
|
|
221
|
+
history.replaceState = (...args) => {
|
|
222
|
+
const result = this.originalReplaceState?.(...args);
|
|
223
|
+
this.notifyRouteChange();
|
|
224
|
+
return result;
|
|
225
|
+
};
|
|
226
|
+
this.routeChangeListener = () => this.notifyRouteChange();
|
|
227
|
+
window.addEventListener("popstate", this.routeChangeListener);
|
|
228
|
+
window.addEventListener("hashchange", this.routeChangeListener);
|
|
229
|
+
this.notifyRouteChange();
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Post a single `route-change` message. With no argument, reads
|
|
233
|
+
* `window.location`. Pass a payload from a router subscription to
|
|
234
|
+
* report a known route instead.
|
|
235
|
+
*/
|
|
236
|
+
notifyRouteChange(payload) {
|
|
237
|
+
if (this.stopped) return;
|
|
238
|
+
let path;
|
|
239
|
+
let search;
|
|
240
|
+
let hash;
|
|
241
|
+
if (payload) {
|
|
242
|
+
path = payload.path ?? "";
|
|
243
|
+
search = payload.search ?? "";
|
|
244
|
+
hash = payload.hash ?? "";
|
|
245
|
+
} else if (typeof window !== "undefined") {
|
|
246
|
+
({ pathname: path, search, hash } = window.location);
|
|
247
|
+
} else {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
postToHost({
|
|
251
|
+
type: "route-change",
|
|
252
|
+
path,
|
|
253
|
+
search,
|
|
254
|
+
hash,
|
|
255
|
+
url: `${path}${search}${hash}`
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
teardownRouteSync() {
|
|
259
|
+
if (!this.routeSyncEnabled) return;
|
|
260
|
+
if (typeof window !== "undefined") {
|
|
261
|
+
const { history } = window;
|
|
262
|
+
if (this.originalPushState) history.pushState = this.originalPushState;
|
|
263
|
+
if (this.originalReplaceState) history.replaceState = this.originalReplaceState;
|
|
264
|
+
if (this.routeChangeListener) {
|
|
265
|
+
window.removeEventListener("popstate", this.routeChangeListener);
|
|
266
|
+
window.removeEventListener("hashchange", this.routeChangeListener);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this.originalPushState = null;
|
|
270
|
+
this.originalReplaceState = null;
|
|
271
|
+
this.routeChangeListener = null;
|
|
272
|
+
this.routeSyncEnabled = false;
|
|
194
273
|
}
|
|
195
274
|
/**
|
|
196
275
|
* Subscribe to host navigation messages.
|
|
@@ -634,6 +713,26 @@ var AuthManager = class {
|
|
|
634
713
|
}
|
|
635
714
|
}
|
|
636
715
|
});
|
|
716
|
+
if (this.config.syncRouteToHost) {
|
|
717
|
+
this.iframeAuth.enableRouteSync();
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Iframe/WebView mode: start auto-syncing the embedded app's route
|
|
722
|
+
* to the host. Patches history methods and listens for popstate /
|
|
723
|
+
* hashchange. Idempotent. No-op outside iframe mode.
|
|
724
|
+
*/
|
|
725
|
+
enableHostRouteSync() {
|
|
726
|
+
this.iframeAuth?.enableRouteSync();
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Iframe/WebView mode: post a single `route-change` message to the
|
|
730
|
+
* host. With no argument, reads `window.location`. Pass a payload
|
|
731
|
+
* from a router subscription to report a known route. No-op outside
|
|
732
|
+
* iframe mode.
|
|
733
|
+
*/
|
|
734
|
+
notifyHostRouteChange(payload) {
|
|
735
|
+
this.iframeAuth?.notifyRouteChange(payload);
|
|
637
736
|
}
|
|
638
737
|
/**
|
|
639
738
|
* Subscribe to host `navigation` messages. Returns an unsubscribe function.
|
|
@@ -957,7 +1056,8 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
957
1056
|
storageKeyPrefix: { type: String, default: void 0 },
|
|
958
1057
|
tokenStorage: { type: Object, default: void 0 },
|
|
959
1058
|
forceMode: { type: String, default: void 0 },
|
|
960
|
-
initialTokens: { type: Object, default: void 0 }
|
|
1059
|
+
initialTokens: { type: Object, default: void 0 },
|
|
1060
|
+
syncRouteToHost: { type: Boolean, default: false }
|
|
961
1061
|
},
|
|
962
1062
|
setup(props, { slots }) {
|
|
963
1063
|
const status = ref("loading");
|
|
@@ -986,6 +1086,12 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
986
1086
|
return manager?.onHostNotification(handler) ?? (() => {
|
|
987
1087
|
});
|
|
988
1088
|
};
|
|
1089
|
+
const enableHostRouteSync = () => {
|
|
1090
|
+
manager?.enableHostRouteSync();
|
|
1091
|
+
};
|
|
1092
|
+
const notifyRouteChange = (payload) => {
|
|
1093
|
+
manager?.notifyHostRouteChange(payload);
|
|
1094
|
+
};
|
|
989
1095
|
const authState = {
|
|
990
1096
|
get status() {
|
|
991
1097
|
return status.value;
|
|
@@ -1007,7 +1113,9 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1007
1113
|
getAuthorizationUrl,
|
|
1008
1114
|
signOut,
|
|
1009
1115
|
onHostNavigation,
|
|
1010
|
-
onHostNotification
|
|
1116
|
+
onHostNotification,
|
|
1117
|
+
enableHostRouteSync,
|
|
1118
|
+
notifyRouteChange
|
|
1011
1119
|
};
|
|
1012
1120
|
provide(DOCYRUS_AUTH_KEY, authState);
|
|
1013
1121
|
onMounted(() => {
|
|
@@ -1021,7 +1129,8 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1021
1129
|
storageKeyPrefix: props.storageKeyPrefix,
|
|
1022
1130
|
tokenStorage: props.tokenStorage,
|
|
1023
1131
|
forceMode: props.forceMode,
|
|
1024
|
-
initialTokens: props.initialTokens
|
|
1132
|
+
initialTokens: props.initialTokens,
|
|
1133
|
+
syncRouteToHost: props.syncRouteToHost
|
|
1025
1134
|
};
|
|
1026
1135
|
manager = new AuthManager(config);
|
|
1027
1136
|
mode.value = manager.getMode();
|