@docyrus/signin 0.18.3 → 0.19.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 +21 -1
- package/dist/{constants-CvMiR-RM.d.ts → constants-DXgxjFEl.d.ts} +3 -2
- package/dist/core-index.d.ts +3 -3
- package/dist/core-index.js +48 -1
- package/dist/core-index.js.map +1 -1
- package/dist/electron/index.d.ts +2 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +69 -17
- package/dist/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +2 -1
- package/dist/nextjs/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/react-native/index.js +69 -17
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-BcLDyMdw.d.ts → types-C3TY5WcX.d.ts} +3 -2
- package/dist/{use-docyrus-client-C9uiHma9.d.ts → use-docyrus-client-D-oTYabD.d.ts} +6 -3
- package/dist/vue/index.d.ts +7 -3
- package/dist/vue/index.js +72 -19
- package/dist/vue/index.js.map +1 -1
- package/package.json +6 -4
|
@@ -193,7 +193,7 @@ interface AuthSessionResult {
|
|
|
193
193
|
/** Function signature for opening an auth session in a native browser */
|
|
194
194
|
type OpenAuthSessionFn = (url: string, redirectUri: string) => Promise<AuthSessionResult>;
|
|
195
195
|
/** Authentication state exposed to consumers */
|
|
196
|
-
type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';
|
|
196
|
+
type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated' | 'error';
|
|
197
197
|
/** Configuration for the DocyrusAuthProvider */
|
|
198
198
|
interface DocyrusAuthConfig {
|
|
199
199
|
/** OAuth2 client ID. Defaults to the Docyrus public client ID */
|
|
@@ -812,4 +812,5 @@ interface PermissionConfig {
|
|
|
812
812
|
alwaysPermittedDataSources?: Record<string, AclOperation[]>;
|
|
813
813
|
}
|
|
814
814
|
|
|
815
|
-
export { IframeAuth as $,
|
|
815
|
+
export { IframeAuth as $, MsGraphClient as p };
|
|
816
|
+
export type { AclOperation as A, ChatSendAckMessage as B, CalendarSendAckMessage as C, DocyrusAuthConfig as D, ChatSendMessage as E, DocySendAckMessage as F, GuidyRoute as G, HostNavigationHandler as H, DocySendMessage as I, DocyrusNotification as J, EmailSendAckMessage as K, EmailSendMessage as L, MsGraphAccount as M, GuidyCommandHandler as N, OpenAuthSessionFn as O, PermissionConfig as P, GuidyCommandMessage as Q, RouteChangePayload as R, GuidyElement as S, GuidyElementsMessage as T, GuidyPointAckMessage as U, GuidyPointMessage as V, GuidyRoutesMessage as W, GuidyScanMessage as X, HostNavigationMessage as Y, HostNotificationMessage as Z, HostSignInMessage as _, AclTargetType as a, MsGraphRequestMessage as a0, MsGraphResponseMessage as a1, MsGraphStatusRequestMessage as a2, MsGraphStatusResponseMessage as a3, TokenRefreshRequestMessage as a4, AdaptiveCard as b, AuthMode as c, AuthSessionResult as d, AuthStatus as e, DocyrusAclRule as f, DocyrusAuthContextValue as g, DocyrusCalendarEventPayload as h, DocyrusEmailPayload as i, DocyrusPermission as j, DocyrusRole as k, DocyrusShareAdaptiveCardPayload as l, DocyrusSharePayload as m, DocyrusShareTextPayload as n, DocyrusUser as o, MsGraphRequest as q, MsGraphRequestOptions as r, MsGraphResponse as s, MsGraphStatus as t, PermissionScope as u, HostNotificationHandler as v, HostNavigationRequestOptions as w, AppNavigationRequestMessage as x, AppRouteChangeMessage as y, CalendarSendMessage as z };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { D as DocyrusAuthConfig, g as DocyrusAuthContextValue } from './types-
|
|
3
|
+
import { D as DocyrusAuthConfig, g as DocyrusAuthContextValue } from './types-C3TY5WcX.js';
|
|
4
4
|
import { RestApiClient } from '@docyrus/api-client';
|
|
5
5
|
|
|
6
6
|
interface DocyrusAuthProviderProps extends DocyrusAuthConfig {
|
|
7
7
|
children: ReactNode;
|
|
8
|
+
/** Render a custom screen for a blocking auth error. */
|
|
9
|
+
renderAuthError?: (error: Error) => ReactNode;
|
|
8
10
|
}
|
|
9
|
-
declare function DocyrusAuthProvider({ children, ...config }: DocyrusAuthProviderProps): react.JSX.Element;
|
|
11
|
+
declare function DocyrusAuthProvider({ children, renderAuthError, ...config }: DocyrusAuthProviderProps): react.JSX.Element;
|
|
10
12
|
|
|
11
13
|
declare const DocyrusAuthContext: react.Context<DocyrusAuthContextValue | null>;
|
|
12
14
|
|
|
@@ -26,4 +28,5 @@ declare function useDocyrusAuth(): DocyrusAuthContextValue;
|
|
|
26
28
|
*/
|
|
27
29
|
declare function useDocyrusClient(): RestApiClient | null;
|
|
28
30
|
|
|
29
|
-
export { DocyrusAuthContext as D, DocyrusAuthProvider as a,
|
|
31
|
+
export { DocyrusAuthContext as D, DocyrusAuthProvider as a, useDocyrusClient as c, useDocyrusAuth as u };
|
|
32
|
+
export type { DocyrusAuthProviderProps as b };
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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 { c as AuthMode, e as AuthStatus,
|
|
5
|
-
|
|
4
|
+
import { c as AuthMode, e as AuthStatus, m as DocyrusSharePayload, i as DocyrusEmailPayload, h as DocyrusCalendarEventPayload, p as MsGraphClient } from '../types-C3TY5WcX.js';
|
|
5
|
+
import { HostNavigationHandler, HostNotificationHandler, RouteChangePayload, HostNavigationRequestOptions } from '../core-index.js';
|
|
6
|
+
export { b as AdaptiveCard, D as DocyrusAuthConfig, l as DocyrusShareAdaptiveCardPayload, n as DocyrusShareTextPayload, M as MsGraphAccount, q as MsGraphRequest, r as MsGraphRequestOptions, s as MsGraphResponse, t as MsGraphStatus } from '../types-C3TY5WcX.js';
|
|
6
7
|
|
|
7
8
|
interface DocyrusAuthState {
|
|
8
9
|
status: AuthStatus;
|
|
@@ -104,6 +105,8 @@ declare const DocyrusAuthProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
104
105
|
};
|
|
105
106
|
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
106
107
|
[key: string]: any;
|
|
108
|
+
}> | vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
109
|
+
[key: string]: any;
|
|
107
110
|
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
108
111
|
clientId: {
|
|
109
112
|
type: StringConstructor;
|
|
@@ -207,4 +210,5 @@ declare const SignInButton: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
207
210
|
disabled: boolean;
|
|
208
211
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
209
212
|
|
|
210
|
-
export { AuthMode, AuthStatus, DocyrusAuthProvider,
|
|
213
|
+
export { AuthMode, AuthStatus, DocyrusAuthProvider, DocyrusCalendarEventPayload, DocyrusEmailPayload, DocyrusSharePayload, MsGraphClient, SignInButton, getDocyrusAuth, getDocyrusClient, useDocyrusAuth, useDocyrusClient };
|
|
214
|
+
export type { DocyrusAuthState };
|
package/dist/vue/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { defineComponent, ref, shallowRef, provide, onMounted, onUnmounted,
|
|
1
|
+
import { defineComponent, ref, shallowRef, provide, onMounted, onUnmounted, h, inject, computed } from 'vue';
|
|
2
2
|
import { RestApiClient, BrowserOAuth2TokenStorage, OAuth2Client, MemoryOAuth2TokenStorage } from '@docyrus/api-client';
|
|
3
3
|
|
|
4
4
|
// src/vue/index.ts
|
|
5
5
|
|
|
6
6
|
// src/constants.ts
|
|
7
7
|
var DEFAULT_API_URL = "https://alpha-api.docyrus.com";
|
|
8
|
+
var INVALID_HOST_API_URL = "invalid-host-api-url";
|
|
9
|
+
var UNTRUSTED_BACKEND_MESSAGE = "This app can\u2019t run because its host gave it an untrusted backend address.";
|
|
8
10
|
var DEFAULT_OAUTH_SCOPES = [
|
|
9
11
|
"offline_access",
|
|
10
12
|
"Read.All",
|
|
@@ -1097,6 +1099,39 @@ function clearTokenCookie(cookieKey) {
|
|
|
1097
1099
|
document.cookie = `${key}=;path=/;max-age=0;SameSite=Lax${secure}`;
|
|
1098
1100
|
}
|
|
1099
1101
|
|
|
1102
|
+
// src/core/host-api-url.ts
|
|
1103
|
+
var LOOPBACK_HOSTS = [
|
|
1104
|
+
"localhost",
|
|
1105
|
+
"127.0.0.1",
|
|
1106
|
+
"[::1]"
|
|
1107
|
+
];
|
|
1108
|
+
var TRUSTED_DOMAINS = ["docyrus.com", "attornaid.com"];
|
|
1109
|
+
function readHostApiUrl() {
|
|
1110
|
+
if (typeof window === "undefined" || !window.location) return void 0;
|
|
1111
|
+
const params = new URLSearchParams(window.location.search);
|
|
1112
|
+
const value = params.get("apiUrl");
|
|
1113
|
+
if (params.get("embedded") !== "true" || value === null) return void 0;
|
|
1114
|
+
try {
|
|
1115
|
+
const url = new URL(value);
|
|
1116
|
+
const {
|
|
1117
|
+
protocol,
|
|
1118
|
+
hostname,
|
|
1119
|
+
username,
|
|
1120
|
+
password,
|
|
1121
|
+
search,
|
|
1122
|
+
hash
|
|
1123
|
+
} = url;
|
|
1124
|
+
const loopback = LOOPBACK_HOSTS.includes(hostname);
|
|
1125
|
+
const trustedDomain = TRUSTED_DOMAINS.some((domain) => hostname === domain || hostname.endsWith(`.${domain}`));
|
|
1126
|
+
if (username || password || search || hash) return null;
|
|
1127
|
+
if (protocol !== "https:" && !(loopback && protocol === "http:")) return null;
|
|
1128
|
+
if (!loopback && !trustedDomain) return null;
|
|
1129
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
1130
|
+
} catch {
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1100
1135
|
// src/core/auth-manager.ts
|
|
1101
1136
|
var AuthManager = class {
|
|
1102
1137
|
mode;
|
|
@@ -1124,7 +1159,12 @@ var AuthManager = class {
|
|
|
1124
1159
|
notificationHandlers = /* @__PURE__ */ new Set();
|
|
1125
1160
|
config;
|
|
1126
1161
|
constructor(config = {}) {
|
|
1127
|
-
|
|
1162
|
+
const hostApiUrl = readHostApiUrl();
|
|
1163
|
+
this.config = hostApiUrl ? { ...config, apiUrl: hostApiUrl } : config;
|
|
1164
|
+
if (hostApiUrl === null) {
|
|
1165
|
+
this.status = "error";
|
|
1166
|
+
this.error = new Error(INVALID_HOST_API_URL);
|
|
1167
|
+
}
|
|
1128
1168
|
this.mode = config.forceMode ?? detectAuthMode(config.allowedHostOrigins);
|
|
1129
1169
|
}
|
|
1130
1170
|
/** Whether the provider may refresh tokens on its own. Default: true. */
|
|
@@ -1172,6 +1212,11 @@ var AuthManager = class {
|
|
|
1172
1212
|
}
|
|
1173
1213
|
/** Initialize the auth manager. Must be called once on mount. */
|
|
1174
1214
|
async initialize() {
|
|
1215
|
+
if (this.status === "error") {
|
|
1216
|
+
console.error("[docyrus-signin]", UNTRUSTED_BACKEND_MESSAGE);
|
|
1217
|
+
this.notify();
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1175
1220
|
try {
|
|
1176
1221
|
if (this.mode === "iframe" && this.getInitialTokens()) {
|
|
1177
1222
|
throw new Error(
|
|
@@ -1454,6 +1499,7 @@ var AuthManager = class {
|
|
|
1454
1499
|
* browser redirect flow, such as a prior device authorization flow.
|
|
1455
1500
|
*/
|
|
1456
1501
|
async signInWithTokens(tokens) {
|
|
1502
|
+
if (this.status === "error") throw this.error;
|
|
1457
1503
|
if (this.mode === "iframe") {
|
|
1458
1504
|
throw new Error(
|
|
1459
1505
|
"signInWithTokens() is not supported in iframe mode. Use the host postMessage signin flow or force standalone mode."
|
|
@@ -1488,6 +1534,7 @@ var AuthManager = class {
|
|
|
1488
1534
|
* Iframe: clear local state (host manages the actual session).
|
|
1489
1535
|
*/
|
|
1490
1536
|
async signOut() {
|
|
1537
|
+
if (this.status === "error") return;
|
|
1491
1538
|
this.clearTokenRefreshTimer();
|
|
1492
1539
|
if (this.mode === "standalone" && this.standaloneAuth) {
|
|
1493
1540
|
await this.standaloneAuth.logout();
|
|
@@ -1758,11 +1805,25 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1758
1805
|
syncRouteToHost: { type: Boolean, default: false }
|
|
1759
1806
|
},
|
|
1760
1807
|
setup(props, { slots }) {
|
|
1761
|
-
const
|
|
1808
|
+
const config = {
|
|
1809
|
+
clientId: props.clientId,
|
|
1810
|
+
apiUrl: props.apiUrl,
|
|
1811
|
+
scopes: props.scopes,
|
|
1812
|
+
redirectUri: props.redirectUri,
|
|
1813
|
+
callbackPath: props.callbackPath,
|
|
1814
|
+
allowedHostOrigins: props.allowedHostOrigins,
|
|
1815
|
+
storageKeyPrefix: props.storageKeyPrefix,
|
|
1816
|
+
tokenStorage: props.tokenStorage,
|
|
1817
|
+
forceMode: props.forceMode,
|
|
1818
|
+
initialTokens: props.initialTokens,
|
|
1819
|
+
syncRouteToHost: props.syncRouteToHost
|
|
1820
|
+
};
|
|
1821
|
+
const bootManager = new AuthManager(config);
|
|
1822
|
+
const status = ref(bootManager.getStatus());
|
|
1762
1823
|
const mode = ref(null);
|
|
1763
1824
|
const tokens = shallowRef(null);
|
|
1764
1825
|
const client = shallowRef(null);
|
|
1765
|
-
const error = shallowRef(
|
|
1826
|
+
const error = shallowRef(bootManager.getError());
|
|
1766
1827
|
let manager = null;
|
|
1767
1828
|
const signIn = () => {
|
|
1768
1829
|
manager?.signIn();
|
|
@@ -1840,20 +1901,7 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1840
1901
|
};
|
|
1841
1902
|
provide(DOCYRUS_AUTH_KEY, authState);
|
|
1842
1903
|
onMounted(() => {
|
|
1843
|
-
|
|
1844
|
-
clientId: props.clientId,
|
|
1845
|
-
apiUrl: props.apiUrl,
|
|
1846
|
-
scopes: props.scopes,
|
|
1847
|
-
redirectUri: props.redirectUri,
|
|
1848
|
-
callbackPath: props.callbackPath,
|
|
1849
|
-
allowedHostOrigins: props.allowedHostOrigins,
|
|
1850
|
-
storageKeyPrefix: props.storageKeyPrefix,
|
|
1851
|
-
tokenStorage: props.tokenStorage,
|
|
1852
|
-
forceMode: props.forceMode,
|
|
1853
|
-
initialTokens: props.initialTokens,
|
|
1854
|
-
syncRouteToHost: props.syncRouteToHost
|
|
1855
|
-
};
|
|
1856
|
-
manager = new AuthManager(config);
|
|
1904
|
+
manager = bootManager;
|
|
1857
1905
|
mode.value = manager.getMode();
|
|
1858
1906
|
manager.subscribe((state) => {
|
|
1859
1907
|
status.value = state.status;
|
|
@@ -1867,7 +1915,12 @@ var DocyrusAuthProvider = defineComponent({
|
|
|
1867
1915
|
manager?.destroy();
|
|
1868
1916
|
manager = null;
|
|
1869
1917
|
});
|
|
1870
|
-
return () =>
|
|
1918
|
+
return () => {
|
|
1919
|
+
if (status.value === "error" && error.value) {
|
|
1920
|
+
return slots.error ? slots.error({ error: error.value }) : h("p", { role: "alert" }, UNTRUSTED_BACKEND_MESSAGE);
|
|
1921
|
+
}
|
|
1922
|
+
return slots.default?.();
|
|
1923
|
+
};
|
|
1871
1924
|
}
|
|
1872
1925
|
});
|
|
1873
1926
|
var ICON_SIZE = 20;
|