@docyrus/signin 0.15.0 → 0.16.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 +193 -0
- package/dist/{constants-BoAqIz2O.d.ts → constants-BhPyFHNf.d.ts} +27 -1
- package/dist/core-index.d.ts +4 -102
- package/dist/core-index.js +284 -1
- package/dist/core-index.js.map +1 -1
- package/dist/index.d.ts +41 -6
- package/dist/index.js +337 -1
- package/dist/index.js.map +1 -1
- package/dist/nextjs/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/react-native/index.js +316 -0
- package/dist/react-native/index.js.map +1 -1
- package/dist/types-C_i-KhUS.d.ts +773 -0
- package/dist/{use-docyrus-client-pU5z5ZHe.d.ts → use-docyrus-client-BfbEowBC.d.ts} +1 -1
- package/dist/vue/index.d.ts +8 -3
- package/dist/vue/index.js +303 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/types-DzwC4Dk7.d.ts +0 -367
package/dist/nextjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants.ts","../../src/nextjs/server-client.ts","../../src/nextjs/session.ts","../../src/nextjs/middleware.ts"],"names":["MemoryTokenManager","RestApiClient"],"mappings":";;;;;AAAO,IAAM,eAAA,GAAkB,+BAAA;AAwBxB,IAAM,sBAAA,GAAyB,eAAA;;;ACY/B,SAAS,kBAAA,CACd,WAAA,EACA,MAAA,GAA6B,EAAC,EACf;AACf,EAAA,MAAM,MAAA,GAAS,OAAO,MAAA,IAAU,eAAA;AAChC,EAAA,MAAM,SAAA,GAAY,OAAO,SAAA,IAAa,sBAAA;AAEtC,EAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,GAAA,CAAI,SAAS,GAAG,KAAA,IAAS,IAAA;AACnD,EAAA,MAAM,YAAA,GAAe,KAAA,GAAQ,kBAAA,CAAmB,KAAK,CAAA,GAAI,IAAA;AAEzD,EAAA,M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S,CAAA;AAEvD,IAAA,MAAM,aAAA,GAAgB,YAAA,CAAa,QAAA,EAAU,eAAe,CAAA;AAC5D,IAAA,MAAM,mBAAmB,eAAA,GAAkB,YAAA,CAAa,QAAA,EAAU,eAAe,IAAI,CAAC,aAAA;AAGtF,IAAA,IAAI,OAAA,CAAQ,eAAA,IAAmB,QAAA,KAAa,SAAA,EAAW;AACrD,MAAA,OAAO,SAAS,QAAA,CAAS,IAAI,IAAI,cAAA,EAAgB,OAAA,CAAQ,GAAG,CAAC,CAAA;AAAA,IAC/D;AAGA,IAAA,IAAI,CAAC,OAAA,CAAQ,eAAA,IAAmB,gBAAA,EAAkB;AAChD,MAAA,OAAO,SAAS,QAAA,CAAS,IAAI,IAAI,SAAA,EAAW,OAAA,CAAQ,GAAG,CAAC,CAAA;AAAA,IAC1D;AAGA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF","file":"index.js","sourcesContent":["export const DEFAULT_API_URL = 'https://alpha-api.docyrus.com';\n\nexport const DEFAULT_OAUTH_SCOPES = [\n 'offline_access',\n 'Read.All',\n 'User.Read',\n 'Users.Read.All',\n 'DS.Read.All'\n];\n\nexport const DEFAULT_CALLBACK_PATH = '/auth/callback';\n\nexport const DEFAULT_ALLOWED_HOST_PATTERN = /^https:\\/\\/[^/]+\\.docyrus\\.app$/;\n\n/** localStorage key to persist the pre-redirect location */\nexport const REDIRECT_RETURN_KEY = 'docyrus_auth_return_url';\n\n/** Buffer in seconds before token expiration to trigger refresh */\nexport const TOKEN_EXPIRY_BUFFER_SECONDS = 60;\n\n/** Timeout for iframe token refresh requests (ms) */\nexport const IFRAME_TOKEN_REFRESH_TIMEOUT_MS = 10_000;\n\n/** Default cookie name for SSR token sync */\nexport const DEFAULT_SSR_COOKIE_KEY = 'docyrus-token';\n\n/** URL query parameter name for SSO session tokens */\nexport const SSO_TOKEN_PARAM = 'sso_token';\n","import { RestApiClient, MemoryTokenManager } from '@docyrus/api-client';\n\nimport { DEFAULT_API_URL, DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport { type ReadonlyCookieStore, type ServerClientConfig } from './types';\n\n/**\n * Create an authenticated `RestApiClient` for use in Next.js\n * Server Components, Server Actions, and Route Handlers.\n *\n * Reads the access token from cookies. The client cannot refresh tokens —\n * that is handled client-side by `DocyrusAuthProvider`.\n *\n * @example Server Component\n * ```ts\n * import { cookies } from 'next/headers';\n * import { createServerClient } from '@docyrus/signin/nextjs';\n *\n * export default async function Page() {\n * const client = createServerClient(await cookies());\n * const { data: user } = await client.get('/v1/users/me');\n * return <div>{user.name}</div>;\n * }\n * ```\n *\n * @example Server Action\n * ```ts\n * 'use server';\n * import { cookies } from 'next/headers';\n * import { createServerClient } from '@docyrus/signin/nextjs';\n *\n * export async function getUser() {\n * const client = createServerClient(await cookies());\n * return client.get('/v1/users/me');\n * }\n * ```\n */\nexport function createServerClient(\n cookieStore: ReadonlyCookieStore,\n config: ServerClientConfig = {}\n): RestApiClient {\n const apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n const cookieKey = config.cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n\n const token = cookieStore.get(cookieKey)?.value ?? null;\n const decodedToken = token ? decodeURIComponent(token) : null;\n\n const tokenManager = new MemoryTokenManager();\n\n if (decodedToken) {\n tokenManager.setToken(decodedToken);\n }\n\n return new RestApiClient({\n baseURL: apiUrl,\n tokenManager\n });\n}\n","import { DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport { type ReadonlyCookieStore, type AuthSession } from './types';\n\n/**\n * Read the current auth session from cookies.\n *\n * Because the SSR cookie is written with `max-age` matching the token\n * lifetime, the browser automatically removes it once the token expires.\n * If the cookie is present the token is considered valid.\n *\n * Works in Server Components, Server Actions, Route Handlers, and Middleware.\n *\n * @example\n * ```ts\n * import { cookies } from 'next/headers';\n * import { getSession } from '@docyrus/signin/nextjs';\n * import { redirect } from 'next/navigation';\n *\n * export default async function Page() {\n * const session = getSession(await cookies());\n * if (!session.isAuthenticated) redirect('/login');\n * // ...\n * }\n * ```\n */\nexport function getSession(\n cookieStore: ReadonlyCookieStore,\n cookieKey?: string\n): AuthSession {\n const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n const tokenCookie = cookieStore.get(key);\n\n const accessToken = tokenCookie?.value ? decodeURIComponent(tokenCookie.value) : null;\n\n return {\n accessToken,\n isAuthenticated: accessToken !== null\n };\n}\n","import { RestApiClient, MemoryTokenManager } from '@docyrus/api-client';\n\nimport { DEFAULT_API_URL, DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport {\n type MiddlewareRequest,\n type ServerClientConfig,\n type AuthMiddlewareConfig,\n type AuthSession\n} from './types';\n\n/**\n * Read the auth session from middleware request cookies.\n *\n * Use this when you need full control over your middleware logic.\n *\n * @example\n * ```ts\n * import { NextResponse, type NextRequest } from 'next/server';\n * import { getMiddlewareSession } from '@docyrus/signin/nextjs';\n *\n * export function middleware(request: NextRequest) {\n * const session = getMiddlewareSession(request);\n * if (!session.isAuthenticated && request.nextUrl.pathname.startsWith('/dashboard')) {\n * return NextResponse.redirect(new URL('/login', request.url));\n * }\n * return NextResponse.next();\n * }\n * ```\n */\nexport function getMiddlewareSession(\n request: MiddlewareRequest,\n cookieKey?: string\n): AuthSession {\n const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n const tokenCookie = request.cookies.get(key);\n\n const accessToken = tokenCookie?.value ? decodeURIComponent(tokenCookie.value) : null;\n\n return {\n accessToken,\n isAuthenticated: accessToken !== null\n };\n}\n\n/**\n * Create an authenticated `RestApiClient` for use in Next.js middleware.\n *\n * @example\n * ```ts\n * import { type NextRequest } from 'next/server';\n * import { createMiddlewareClient } from '@docyrus/signin/nextjs';\n *\n * export function middleware(request: NextRequest) {\n * const client = createMiddlewareClient(request);\n * // use client for API calls if needed\n * }\n * ```\n */\nexport function createMiddlewareClient(\n request: MiddlewareRequest,\n config: ServerClientConfig = {}\n): RestApiClient {\n const apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n const cookieKey = config.cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n\n const token = request.cookies.get(cookieKey)?.value ?? null;\n const decodedToken = token ? decodeURIComponent(token) : null;\n\n const tokenManager = new MemoryTokenManager();\n\n if (decodedToken) {\n tokenManager.setToken(decodedToken);\n }\n\n return new RestApiClient({\n baseURL: apiUrl,\n tokenManager\n });\n}\n\n/**\n * Check if a pathname matches any of the given route patterns.\n * Supports `(.*)` suffix for catch-all matching.\n */\nfunction matchesRoute(pathname: string, patterns: string[]): boolean {\n return patterns.some((pattern) => {\n const regexStr = pattern\n .replace(/[.+?^${}|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\\\\\(\\\\\\.\\\\\\*\\\\\\)/g, '.*')\n .replace(/\\\\\\*/g, '[^/]*');\n\n return new RegExp(`^${regexStr}$`).test(pathname);\n });\n}\n\nconst DEFAULT_PUBLIC_ROUTES = ['/login', '/auth/callback'];\n\n/**\n * Pre-built auth middleware for route protection.\n *\n * Uses standard `Response.redirect()` for redirects and returns `undefined`\n * for pass-through (Next.js treats this as \"continue to next middleware/page\").\n *\n * @example\n * ```ts\n * // middleware.ts\n * import { authMiddleware } from '@docyrus/signin/nextjs';\n *\n * export default authMiddleware({\n * publicRoutes: ['/login', '/callback'],\n * loginPath: '/login',\n * });\n *\n * export const config = {\n * matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\\\..*).*)'],\n * };\n * ```\n */\nexport function authMiddleware(config: AuthMiddlewareConfig = {}) {\n const {\n protectedRoutes,\n publicRoutes = DEFAULT_PUBLIC_ROUTES,\n loginPath = '/login',\n afterLoginPath = '/',\n cookieKey = DEFAULT_SSR_COOKIE_KEY\n } = config;\n\n const allPublicRoutes = publicRoutes.includes(loginPath) ? publicRoutes : [...publicRoutes, loginPath];\n\n return (request: MiddlewareRequest): Response | undefined => {\n const { pathname } = request.nextUrl;\n const session = getMiddlewareSession(request, cookieKey);\n\n const isPublicRoute = matchesRoute(pathname, allPublicRoutes);\n const isProtectedRoute = protectedRoutes ? matchesRoute(pathname, protectedRoutes) : !isPublicRoute;\n\n // Redirect authenticated users away from login page\n if (session.isAuthenticated && pathname === loginPath) {\n return Response.redirect(new URL(afterLoginPath, request.url));\n }\n\n // Redirect unauthenticated users to login\n if (!session.isAuthenticated && isProtectedRoute) {\n return Response.redirect(new URL(loginPath, request.url));\n }\n\n // Pass through\n return undefined;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts","../../src/nextjs/server-client.ts","../../src/nextjs/session.ts","../../src/nextjs/middleware.ts"],"names":["MemoryTokenManager","RestApiClient"],"mappings":";;;;;AAAO,IAAM,eAAA,GAAkB,+BAAA;AA8BxB,IAAM,sBAAA,GAAyB,eAAA;;;ACM/B,SAAS,kBAAA,CACd,WAAA,EACA,MAAA,GAA6B,EAAC,EACf;AACf,EAAA,MAAM,MAAA,GAAS,OAAO,MAAA,IAAU,eAAA;AAChC,EAAA,MAAM,SAAA,GAAY,OAAO,SAAA,IAAa,sBAAA;AAEtC,EAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,GAAA,CAAI,SAAS,GAAG,KAAA,IAAS,IAAA;AACnD,EAAA,MAAM,YAAA,GAAe,KAAA,GAAQ,kBAAA,CAAmB,KAAK,CAAA,GAAI,IAAA;AAEzD,EAAA,MAAM,YAAA,GAAe,IAAI,kBAAA,EAAmB;AAE5C,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,YAAA,CAAa,SAAS,YAAY,CAAA;AAAA,EACpC;AAEA,EAAA,OAAO,IAAI,aAAA,CAAc;AAAA,IACvB,OAAA,EAAS,MAAA;AAAA,IACT;AAAA,GACD,CAAA;AACH;;;AC/BO,SAAS,UAAA,CACd,aACA,SAAA,EACa;AACb,EAAA,MAAM,MAAM,SAAA,IAAa,sBAAA;AACzB,EAAA,MAAM,WAAA,GAAc,WAAA,CAAY,GAAA,CAAI,GAAG,CAAA;AAEvC,EAAA,MAAM,cAAc,WAAA,EAAa,KAAA,GAAQ,kBAAA,CAAmB,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CAAS,IAAI,IAAI,SAAA,EAAW,OAAA,CAAQ,GAAG,CAAC,CAAA;AAAA,IAC1D;AAGA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF","file":"index.js","sourcesContent":["export const DEFAULT_API_URL = 'https://alpha-api.docyrus.com';\n\nexport const DEFAULT_OAUTH_SCOPES = [\n 'offline_access',\n 'Read.All',\n 'User.Read',\n 'Users.Read.All',\n 'DS.Read.All'\n];\n\nexport const DEFAULT_CALLBACK_PATH = '/auth/callback';\n\nexport const DEFAULT_ALLOWED_HOST_PATTERN = /^https:\\/\\/[^/]+\\.docyrus\\.app$/;\n\n/** localStorage key to persist the pre-redirect location */\nexport const REDIRECT_RETURN_KEY = 'docyrus_auth_return_url';\n\n/** Buffer in seconds before token expiration to trigger refresh */\nexport const TOKEN_EXPIRY_BUFFER_SECONDS = 60;\n\n/** Timeout for iframe token refresh requests (ms) */\nexport const IFRAME_TOKEN_REFRESH_TIMEOUT_MS = 10_000;\n\n/** Timeout for app→host action acks (Send to Docy / Send to Chat) (ms) */\nexport const HOST_ACTION_TIMEOUT_MS = 15_000;\n\n/** Timeout for host-proxied Microsoft Graph requests (ms) — Graph can be slow */\nexport const MSGRAPH_REQUEST_TIMEOUT_MS = 30_000;\n\n/** Default cookie name for SSR token sync */\nexport const DEFAULT_SSR_COOKIE_KEY = 'docyrus-token';\n\n/** URL query parameter name for SSO session tokens */\nexport const SSO_TOKEN_PARAM = 'sso_token';\n","import { RestApiClient, MemoryTokenManager } from '@docyrus/api-client';\n\nimport { DEFAULT_API_URL, DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport { type ReadonlyCookieStore, type ServerClientConfig } from './types';\n\n/**\n * Create an authenticated `RestApiClient` for use in Next.js\n * Server Components, Server Actions, and Route Handlers.\n *\n * Reads the access token from cookies. The client cannot refresh tokens —\n * that is handled client-side by `DocyrusAuthProvider`.\n *\n * @example Server Component\n * ```ts\n * import { cookies } from 'next/headers';\n * import { createServerClient } from '@docyrus/signin/nextjs';\n *\n * export default async function Page() {\n * const client = createServerClient(await cookies());\n * const { data: user } = await client.get('/v1/users/me');\n * return <div>{user.name}</div>;\n * }\n * ```\n *\n * @example Server Action\n * ```ts\n * 'use server';\n * import { cookies } from 'next/headers';\n * import { createServerClient } from '@docyrus/signin/nextjs';\n *\n * export async function getUser() {\n * const client = createServerClient(await cookies());\n * return client.get('/v1/users/me');\n * }\n * ```\n */\nexport function createServerClient(\n cookieStore: ReadonlyCookieStore,\n config: ServerClientConfig = {}\n): RestApiClient {\n const apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n const cookieKey = config.cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n\n const token = cookieStore.get(cookieKey)?.value ?? null;\n const decodedToken = token ? decodeURIComponent(token) : null;\n\n const tokenManager = new MemoryTokenManager();\n\n if (decodedToken) {\n tokenManager.setToken(decodedToken);\n }\n\n return new RestApiClient({\n baseURL: apiUrl,\n tokenManager\n });\n}\n","import { DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport { type ReadonlyCookieStore, type AuthSession } from './types';\n\n/**\n * Read the current auth session from cookies.\n *\n * Because the SSR cookie is written with `max-age` matching the token\n * lifetime, the browser automatically removes it once the token expires.\n * If the cookie is present the token is considered valid.\n *\n * Works in Server Components, Server Actions, Route Handlers, and Middleware.\n *\n * @example\n * ```ts\n * import { cookies } from 'next/headers';\n * import { getSession } from '@docyrus/signin/nextjs';\n * import { redirect } from 'next/navigation';\n *\n * export default async function Page() {\n * const session = getSession(await cookies());\n * if (!session.isAuthenticated) redirect('/login');\n * // ...\n * }\n * ```\n */\nexport function getSession(\n cookieStore: ReadonlyCookieStore,\n cookieKey?: string\n): AuthSession {\n const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n const tokenCookie = cookieStore.get(key);\n\n const accessToken = tokenCookie?.value ? decodeURIComponent(tokenCookie.value) : null;\n\n return {\n accessToken,\n isAuthenticated: accessToken !== null\n };\n}\n","import { RestApiClient, MemoryTokenManager } from '@docyrus/api-client';\n\nimport { DEFAULT_API_URL, DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport {\n type MiddlewareRequest,\n type ServerClientConfig,\n type AuthMiddlewareConfig,\n type AuthSession\n} from './types';\n\n/**\n * Read the auth session from middleware request cookies.\n *\n * Use this when you need full control over your middleware logic.\n *\n * @example\n * ```ts\n * import { NextResponse, type NextRequest } from 'next/server';\n * import { getMiddlewareSession } from '@docyrus/signin/nextjs';\n *\n * export function middleware(request: NextRequest) {\n * const session = getMiddlewareSession(request);\n * if (!session.isAuthenticated && request.nextUrl.pathname.startsWith('/dashboard')) {\n * return NextResponse.redirect(new URL('/login', request.url));\n * }\n * return NextResponse.next();\n * }\n * ```\n */\nexport function getMiddlewareSession(\n request: MiddlewareRequest,\n cookieKey?: string\n): AuthSession {\n const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n const tokenCookie = request.cookies.get(key);\n\n const accessToken = tokenCookie?.value ? decodeURIComponent(tokenCookie.value) : null;\n\n return {\n accessToken,\n isAuthenticated: accessToken !== null\n };\n}\n\n/**\n * Create an authenticated `RestApiClient` for use in Next.js middleware.\n *\n * @example\n * ```ts\n * import { type NextRequest } from 'next/server';\n * import { createMiddlewareClient } from '@docyrus/signin/nextjs';\n *\n * export function middleware(request: NextRequest) {\n * const client = createMiddlewareClient(request);\n * // use client for API calls if needed\n * }\n * ```\n */\nexport function createMiddlewareClient(\n request: MiddlewareRequest,\n config: ServerClientConfig = {}\n): RestApiClient {\n const apiUrl = config.apiUrl ?? DEFAULT_API_URL;\n const cookieKey = config.cookieKey ?? DEFAULT_SSR_COOKIE_KEY;\n\n const token = request.cookies.get(cookieKey)?.value ?? null;\n const decodedToken = token ? decodeURIComponent(token) : null;\n\n const tokenManager = new MemoryTokenManager();\n\n if (decodedToken) {\n tokenManager.setToken(decodedToken);\n }\n\n return new RestApiClient({\n baseURL: apiUrl,\n tokenManager\n });\n}\n\n/**\n * Check if a pathname matches any of the given route patterns.\n * Supports `(.*)` suffix for catch-all matching.\n */\nfunction matchesRoute(pathname: string, patterns: string[]): boolean {\n return patterns.some((pattern) => {\n const regexStr = pattern\n .replace(/[.+?^${}|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\\\\\(\\\\\\.\\\\\\*\\\\\\)/g, '.*')\n .replace(/\\\\\\*/g, '[^/]*');\n\n return new RegExp(`^${regexStr}$`).test(pathname);\n });\n}\n\nconst DEFAULT_PUBLIC_ROUTES = ['/login', '/auth/callback'];\n\n/**\n * Pre-built auth middleware for route protection.\n *\n * Uses standard `Response.redirect()` for redirects and returns `undefined`\n * for pass-through (Next.js treats this as \"continue to next middleware/page\").\n *\n * @example\n * ```ts\n * // middleware.ts\n * import { authMiddleware } from '@docyrus/signin/nextjs';\n *\n * export default authMiddleware({\n * publicRoutes: ['/login', '/callback'],\n * loginPath: '/login',\n * });\n *\n * export const config = {\n * matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\\\..*).*)'],\n * };\n * ```\n */\nexport function authMiddleware(config: AuthMiddlewareConfig = {}) {\n const {\n protectedRoutes,\n publicRoutes = DEFAULT_PUBLIC_ROUTES,\n loginPath = '/login',\n afterLoginPath = '/',\n cookieKey = DEFAULT_SSR_COOKIE_KEY\n } = config;\n\n const allPublicRoutes = publicRoutes.includes(loginPath) ? publicRoutes : [...publicRoutes, loginPath];\n\n return (request: MiddlewareRequest): Response | undefined => {\n const { pathname } = request.nextUrl;\n const session = getMiddlewareSession(request, cookieKey);\n\n const isPublicRoute = matchesRoute(pathname, allPublicRoutes);\n const isProtectedRoute = protectedRoutes ? matchesRoute(pathname, protectedRoutes) : !isPublicRoute;\n\n // Redirect authenticated users away from login page\n if (session.isAuthenticated && pathname === loginPath) {\n return Response.redirect(new URL(afterLoginPath, request.url));\n }\n\n // Redirect unauthenticated users to login\n if (!session.isAuthenticated && isProtectedRoute) {\n return Response.redirect(new URL(loginPath, request.url));\n }\n\n // Pass through\n return undefined;\n };\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OAuth2Tokens } from '@docyrus/api-client';
|
|
2
|
-
import { D as DocyrusAuthConfig } from '../types-
|
|
3
|
-
export { A as AclOperation, a as
|
|
4
|
-
export { D as DocyrusAuthContext, a as DocyrusAuthProvider, b as DocyrusAuthProviderProps, u as useDocyrusAuth, c as useDocyrusClient } from '../use-docyrus-client-
|
|
5
|
-
export { A as AuthManager, D as DEFAULT_API_URL, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, h as hasPermission, b as hasRole } from '../constants-
|
|
2
|
+
import { D as DocyrusAuthConfig } from '../types-C_i-KhUS.js';
|
|
3
|
+
export { A as AclOperation, a as AdaptiveCard, b as AuthMode, c as AuthSessionResult, d as AuthStatus, e as DocyrusAclRule, f as DocyrusAuthContextValue, g as DocyrusCalendarEventPayload, h as DocyrusEmailPayload, i as DocyrusRole, j as DocyrusShareAdaptiveCardPayload, k as DocyrusSharePayload, l as DocyrusShareTextPayload, m as DocyrusUser, M as MsGraphAccount, n as MsGraphClient, o as MsGraphRequest, p as MsGraphRequestOptions, q as MsGraphResponse, r as MsGraphStatus, O as OpenAuthSessionFn, P as PermissionConfig } from '../types-C_i-KhUS.js';
|
|
4
|
+
export { D as DocyrusAuthContext, a as DocyrusAuthProvider, b as DocyrusAuthProviderProps, u as useDocyrusAuth, c as useDocyrusClient } from '../use-docyrus-client-BfbEowBC.js';
|
|
5
|
+
export { A as AuthManager, D as DEFAULT_API_URL, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, h as hasPermission, b as hasRole } from '../constants-BhPyFHNf.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -18,6 +18,8 @@ var DEFAULT_ALLOWED_HOST_PATTERN = /^https:\/\/[^/]+\.docyrus\.app$/;
|
|
|
18
18
|
var REDIRECT_RETURN_KEY = "docyrus_auth_return_url";
|
|
19
19
|
var TOKEN_EXPIRY_BUFFER_SECONDS = 60;
|
|
20
20
|
var IFRAME_TOKEN_REFRESH_TIMEOUT_MS = 1e4;
|
|
21
|
+
var HOST_ACTION_TIMEOUT_MS = 15e3;
|
|
22
|
+
var MSGRAPH_REQUEST_TIMEOUT_MS = 3e4;
|
|
21
23
|
var SSO_TOKEN_PARAM = "sso_token";
|
|
22
24
|
|
|
23
25
|
// src/react-native/rn-oauth2-auth.ts
|
|
@@ -269,6 +271,13 @@ var IframeAuth = class {
|
|
|
269
271
|
stopped = false;
|
|
270
272
|
refreshPromise = null;
|
|
271
273
|
messageHandler = null;
|
|
274
|
+
/**
|
|
275
|
+
* In-flight app→host requests awaiting a correlated host reply, keyed by
|
|
276
|
+
* requestId. Powers Send to Docy / Send to Chat / the MS Graph bridge.
|
|
277
|
+
*/
|
|
278
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
279
|
+
/** Fallback monotonic counter for request ids when crypto.randomUUID is absent. */
|
|
280
|
+
requestCounter = 0;
|
|
272
281
|
constructor(allowedOrigins, allowedPattern) {
|
|
273
282
|
this.allowedOrigins = allowedOrigins ?? [];
|
|
274
283
|
this.allowedPattern = allowedPattern ?? DEFAULT_ALLOWED_HOST_PATTERN;
|
|
@@ -292,6 +301,7 @@ var IframeAuth = class {
|
|
|
292
301
|
this.messageHandler = null;
|
|
293
302
|
}
|
|
294
303
|
this.rejectPendingRefresh("IframeAuth stopped");
|
|
304
|
+
this.rejectAllPendingRequests("IframeAuth stopped");
|
|
295
305
|
this.navigationHandlers.clear();
|
|
296
306
|
this.notificationHandlers.clear();
|
|
297
307
|
this.guidyHandlers.clear();
|
|
@@ -418,6 +428,119 @@ var IframeAuth = class {
|
|
|
418
428
|
if (this.stopped) return;
|
|
419
429
|
postToHost(message);
|
|
420
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Hand a payload to the host AI assistant (Docy). Resolves when the host
|
|
433
|
+
* acknowledges delivery, rejects on host error or timeout.
|
|
434
|
+
*/
|
|
435
|
+
sendToDocy(payload) {
|
|
436
|
+
const requestId = this.nextRequestId();
|
|
437
|
+
return this.request(
|
|
438
|
+
{ type: "docy:send", requestId, payload },
|
|
439
|
+
HOST_ACTION_TIMEOUT_MS
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Hand a payload to the host team-chat app. Resolves when the host
|
|
444
|
+
* acknowledges delivery, rejects on host error or timeout.
|
|
445
|
+
*/
|
|
446
|
+
sendToChat(payload) {
|
|
447
|
+
const requestId = this.nextRequestId();
|
|
448
|
+
return this.request(
|
|
449
|
+
{ type: "chat:send", requestId, payload },
|
|
450
|
+
HOST_ACTION_TIMEOUT_MS
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Hand a draft email to the host. Resolves when the host acknowledges,
|
|
455
|
+
* rejects on host error or timeout.
|
|
456
|
+
*/
|
|
457
|
+
sendToEmail(payload) {
|
|
458
|
+
const requestId = this.nextRequestId();
|
|
459
|
+
return this.request(
|
|
460
|
+
{ type: "email:send", requestId, payload },
|
|
461
|
+
HOST_ACTION_TIMEOUT_MS
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Hand a calendar event to the host. Resolves when the host acknowledges,
|
|
466
|
+
* rejects on host error or timeout.
|
|
467
|
+
*/
|
|
468
|
+
sendToCalendar(payload) {
|
|
469
|
+
const requestId = this.nextRequestId();
|
|
470
|
+
return this.request(
|
|
471
|
+
{ type: "calendar:send", requestId, payload },
|
|
472
|
+
HOST_ACTION_TIMEOUT_MS
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
/** Ask the host whether its MSAL session is signed in. */
|
|
476
|
+
requestMsGraphStatus() {
|
|
477
|
+
const requestId = this.nextRequestId();
|
|
478
|
+
return this.request(
|
|
479
|
+
{ type: "msgraph:status-request", requestId },
|
|
480
|
+
HOST_ACTION_TIMEOUT_MS
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
/** Perform a Microsoft Graph request through the host's MSAL session. */
|
|
484
|
+
requestMsGraph(request) {
|
|
485
|
+
const requestId = this.nextRequestId();
|
|
486
|
+
return this.request(
|
|
487
|
+
{ type: "msgraph:request", requestId, request },
|
|
488
|
+
MSGRAPH_REQUEST_TIMEOUT_MS
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Post a correlated app→host request and await the matching host reply.
|
|
493
|
+
* The reply is matched by `requestId` in `handleMessage`. Rejects on timeout
|
|
494
|
+
* or when the bridge is stopped.
|
|
495
|
+
*/
|
|
496
|
+
request(message, timeoutMs) {
|
|
497
|
+
if (this.stopped) {
|
|
498
|
+
return Promise.reject(new Error("Cannot send host request: iframe bridge stopped"));
|
|
499
|
+
}
|
|
500
|
+
const { requestId } = message;
|
|
501
|
+
return new Promise((resolve, reject) => {
|
|
502
|
+
const timeoutId = setTimeout(() => {
|
|
503
|
+
this.pendingRequests.delete(requestId);
|
|
504
|
+
reject(new Error(`Host request "${message.type}" timed out`));
|
|
505
|
+
}, timeoutMs);
|
|
506
|
+
this.pendingRequests.set(requestId, {
|
|
507
|
+
resolve,
|
|
508
|
+
reject,
|
|
509
|
+
timeoutId
|
|
510
|
+
});
|
|
511
|
+
this.sendToHost(message);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/** Generate a correlation id, preferring crypto.randomUUID when available. */
|
|
515
|
+
nextRequestId() {
|
|
516
|
+
const cryptoObj = typeof crypto !== "undefined" ? crypto : void 0;
|
|
517
|
+
if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
|
|
518
|
+
return cryptoObj.randomUUID();
|
|
519
|
+
}
|
|
520
|
+
this.requestCounter += 1;
|
|
521
|
+
return `req-${Date.now().toString(36)}-${this.requestCounter}-${Math.random().toString(36).slice(2, 10)}`;
|
|
522
|
+
}
|
|
523
|
+
resolvePendingRequest(requestId, value) {
|
|
524
|
+
const pending = this.pendingRequests.get(requestId);
|
|
525
|
+
if (!pending) return;
|
|
526
|
+
clearTimeout(pending.timeoutId);
|
|
527
|
+
this.pendingRequests.delete(requestId);
|
|
528
|
+
pending.resolve(value);
|
|
529
|
+
}
|
|
530
|
+
rejectPendingRequest(requestId, error) {
|
|
531
|
+
const pending = this.pendingRequests.get(requestId);
|
|
532
|
+
if (!pending) return;
|
|
533
|
+
clearTimeout(pending.timeoutId);
|
|
534
|
+
this.pendingRequests.delete(requestId);
|
|
535
|
+
pending.reject(error);
|
|
536
|
+
}
|
|
537
|
+
rejectAllPendingRequests(reason) {
|
|
538
|
+
for (const pending of this.pendingRequests.values()) {
|
|
539
|
+
clearTimeout(pending.timeoutId);
|
|
540
|
+
pending.reject(new Error(reason));
|
|
541
|
+
}
|
|
542
|
+
this.pendingRequests.clear();
|
|
543
|
+
}
|
|
421
544
|
/**
|
|
422
545
|
* Request fresh tokens from the host.
|
|
423
546
|
* Posts a "token-refresh-request" to the host, then waits for
|
|
@@ -474,8 +597,57 @@ var IframeAuth = class {
|
|
|
474
597
|
}
|
|
475
598
|
if (data.type === "guidy:point" || data.type === "guidy:scan") {
|
|
476
599
|
this.handleGuidyCommand(data);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (data.type === "docy:send-ack" || data.type === "chat:send-ack" || data.type === "email:send-ack" || data.type === "calendar:send-ack") {
|
|
603
|
+
this.handleActionAck(data);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (data.type === "msgraph:status-response") {
|
|
607
|
+
this.handleMsGraphStatusResponse(data);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (data.type === "msgraph:response") {
|
|
611
|
+
this.handleMsGraphResponse(data);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
handleActionAck(message) {
|
|
615
|
+
if (typeof message.requestId !== "string") return;
|
|
616
|
+
if (message.ok) {
|
|
617
|
+
this.resolvePendingRequest(message.requestId, void 0);
|
|
618
|
+
} else {
|
|
619
|
+
this.rejectPendingRequest(
|
|
620
|
+
message.requestId,
|
|
621
|
+
new Error(message.error || `Host rejected ${message.type}`)
|
|
622
|
+
);
|
|
477
623
|
}
|
|
478
624
|
}
|
|
625
|
+
handleMsGraphStatusResponse(message) {
|
|
626
|
+
if (typeof message.requestId !== "string") return;
|
|
627
|
+
if (message.error) {
|
|
628
|
+
this.rejectPendingRequest(message.requestId, new Error(message.error));
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const status = {
|
|
632
|
+
signedIn: !!message.signedIn,
|
|
633
|
+
account: message.account ?? null
|
|
634
|
+
};
|
|
635
|
+
this.resolvePendingRequest(message.requestId, status);
|
|
636
|
+
}
|
|
637
|
+
handleMsGraphResponse(message) {
|
|
638
|
+
if (typeof message.requestId !== "string") return;
|
|
639
|
+
if (message.error && typeof message.status !== "number") {
|
|
640
|
+
this.rejectPendingRequest(message.requestId, new Error(message.error));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const response = {
|
|
644
|
+
ok: !!message.ok,
|
|
645
|
+
status: typeof message.status === "number" ? message.status : 0,
|
|
646
|
+
data: message.data,
|
|
647
|
+
error: message.error
|
|
648
|
+
};
|
|
649
|
+
this.resolvePendingRequest(message.requestId, response);
|
|
650
|
+
}
|
|
479
651
|
handleGuidyCommand(message) {
|
|
480
652
|
for (const handler of this.guidyHandlers) {
|
|
481
653
|
try {
|
|
@@ -777,6 +949,66 @@ var GuidyBridge = class {
|
|
|
777
949
|
}
|
|
778
950
|
};
|
|
779
951
|
|
|
952
|
+
// src/core/ms-graph-client.ts
|
|
953
|
+
var MsGraphClient = class {
|
|
954
|
+
iframeAuth;
|
|
955
|
+
constructor(iframeAuth) {
|
|
956
|
+
this.iframeAuth = iframeAuth;
|
|
957
|
+
}
|
|
958
|
+
/** Whether the host's MSAL session is signed in, plus optional account info. */
|
|
959
|
+
status() {
|
|
960
|
+
return this.iframeAuth.requestMsGraphStatus();
|
|
961
|
+
}
|
|
962
|
+
/** Convenience: resolves to whether the host's MSAL session is signed in. */
|
|
963
|
+
async isSignedIn() {
|
|
964
|
+
const status = await this.iframeAuth.requestMsGraphStatus();
|
|
965
|
+
return status.signedIn;
|
|
966
|
+
}
|
|
967
|
+
/** Perform an arbitrary Microsoft Graph request via the host's MSAL session. */
|
|
968
|
+
request(request) {
|
|
969
|
+
return this.iframeAuth.requestMsGraph(request);
|
|
970
|
+
}
|
|
971
|
+
/** GET a Graph resource, e.g. `get('/me/messages?$top=5')`. */
|
|
972
|
+
get(path, options) {
|
|
973
|
+
return this.iframeAuth.requestMsGraph({ method: "GET", path, ...options });
|
|
974
|
+
}
|
|
975
|
+
/** POST a JSON body to a Graph resource. */
|
|
976
|
+
post(path, body, options) {
|
|
977
|
+
return this.iframeAuth.requestMsGraph({
|
|
978
|
+
method: "POST",
|
|
979
|
+
path,
|
|
980
|
+
body,
|
|
981
|
+
...options
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
/** PATCH a JSON body to a Graph resource. */
|
|
985
|
+
patch(path, body, options) {
|
|
986
|
+
return this.iframeAuth.requestMsGraph({
|
|
987
|
+
method: "PATCH",
|
|
988
|
+
path,
|
|
989
|
+
body,
|
|
990
|
+
...options
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
/** PUT a JSON body to a Graph resource. */
|
|
994
|
+
put(path, body, options) {
|
|
995
|
+
return this.iframeAuth.requestMsGraph({
|
|
996
|
+
method: "PUT",
|
|
997
|
+
path,
|
|
998
|
+
body,
|
|
999
|
+
...options
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
/** DELETE a Graph resource. */
|
|
1003
|
+
delete(path, options) {
|
|
1004
|
+
return this.iframeAuth.requestMsGraph({ method: "DELETE", path, ...options });
|
|
1005
|
+
}
|
|
1006
|
+
/** Convenience: GET `/me` — the signed-in user's profile. */
|
|
1007
|
+
getMe() {
|
|
1008
|
+
return this.iframeAuth.requestMsGraph({ method: "GET", path: "/me" });
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
|
|
780
1012
|
// src/core/sso-auth.ts
|
|
781
1013
|
var SsoAuth = class {
|
|
782
1014
|
config;
|
|
@@ -862,6 +1094,7 @@ var AuthManager = class {
|
|
|
862
1094
|
standaloneAuth = null;
|
|
863
1095
|
iframeAuth = null;
|
|
864
1096
|
guidyBridge = null;
|
|
1097
|
+
msGraphClient = null;
|
|
865
1098
|
reactNativeAuth = null;
|
|
866
1099
|
tokenRefreshTimer = null;
|
|
867
1100
|
/** Shared in-flight refresh, so concurrent requests don't trigger parallel refreshes. */
|
|
@@ -1004,6 +1237,7 @@ var AuthManager = class {
|
|
|
1004
1237
|
*/
|
|
1005
1238
|
initializeIframeMode() {
|
|
1006
1239
|
this.iframeAuth = new IframeAuth(this.config.allowedHostOrigins);
|
|
1240
|
+
this.msGraphClient = new MsGraphClient(this.iframeAuth);
|
|
1007
1241
|
this.iframeAuth.start((tokens) => {
|
|
1008
1242
|
this.setAuthenticated(tokens);
|
|
1009
1243
|
});
|
|
@@ -1079,6 +1313,53 @@ var AuthManager = class {
|
|
|
1079
1313
|
requestHostNavigation(url, options) {
|
|
1080
1314
|
this.iframeAuth?.requestHostNavigation(url, options);
|
|
1081
1315
|
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Iframe/WebView mode: hand a payload to the host AI assistant (Docy).
|
|
1318
|
+
* Resolves when the host acknowledges delivery. Rejects outside iframe mode.
|
|
1319
|
+
*/
|
|
1320
|
+
sendToDocy(payload) {
|
|
1321
|
+
if (!this.iframeAuth) {
|
|
1322
|
+
return Promise.reject(new Error("sendToDocy() is only available in iframe/WebView mode"));
|
|
1323
|
+
}
|
|
1324
|
+
return this.iframeAuth.sendToDocy(payload);
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Iframe/WebView mode: hand a payload to the host team-chat app.
|
|
1328
|
+
* Resolves when the host acknowledges delivery. Rejects outside iframe mode.
|
|
1329
|
+
*/
|
|
1330
|
+
sendToChat(payload) {
|
|
1331
|
+
if (!this.iframeAuth) {
|
|
1332
|
+
return Promise.reject(new Error("sendToChat() is only available in iframe/WebView mode"));
|
|
1333
|
+
}
|
|
1334
|
+
return this.iframeAuth.sendToChat(payload);
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Iframe/WebView mode: hand a draft email to the host. Resolves when the
|
|
1338
|
+
* host acknowledges. Rejects outside iframe mode.
|
|
1339
|
+
*/
|
|
1340
|
+
sendToEmail(payload) {
|
|
1341
|
+
if (!this.iframeAuth) {
|
|
1342
|
+
return Promise.reject(new Error("sendToEmail() is only available in iframe/WebView mode"));
|
|
1343
|
+
}
|
|
1344
|
+
return this.iframeAuth.sendToEmail(payload);
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Iframe/WebView mode: hand a calendar event to the host. Resolves when the
|
|
1348
|
+
* host acknowledges. Rejects outside iframe mode.
|
|
1349
|
+
*/
|
|
1350
|
+
sendToCalendar(payload) {
|
|
1351
|
+
if (!this.iframeAuth) {
|
|
1352
|
+
return Promise.reject(new Error("sendToCalendar() is only available in iframe/WebView mode"));
|
|
1353
|
+
}
|
|
1354
|
+
return this.iframeAuth.sendToCalendar(payload);
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Iframe/WebView mode: get the client for the host's Microsoft Graph (MSAL)
|
|
1358
|
+
* session. Returns `null` outside iframe mode.
|
|
1359
|
+
*/
|
|
1360
|
+
getMsGraphClient() {
|
|
1361
|
+
return this.msGraphClient;
|
|
1362
|
+
}
|
|
1082
1363
|
/**
|
|
1083
1364
|
* Subscribe to host `navigation` messages. Returns an unsubscribe function.
|
|
1084
1365
|
* Handlers registered before iframe mode is initialized are retained and
|
|
@@ -1200,6 +1481,7 @@ var AuthManager = class {
|
|
|
1200
1481
|
this.guidyBridge = null;
|
|
1201
1482
|
}
|
|
1202
1483
|
this.iframeAuth.stop();
|
|
1484
|
+
this.msGraphClient = null;
|
|
1203
1485
|
}
|
|
1204
1486
|
if (this.config.ssr) {
|
|
1205
1487
|
clearTokenCookie(this.config.ssrCookieKey);
|
|
@@ -1379,6 +1661,7 @@ var AuthManager = class {
|
|
|
1379
1661
|
this.guidyBridge = null;
|
|
1380
1662
|
}
|
|
1381
1663
|
if (this.iframeAuth) this.iframeAuth.stop();
|
|
1664
|
+
this.msGraphClient = null;
|
|
1382
1665
|
this.listeners.clear();
|
|
1383
1666
|
this.navigationHandlers.clear();
|
|
1384
1667
|
this.notificationHandlers.clear();
|
|
@@ -1579,6 +1862,29 @@ function DocyrusAuthProvider({
|
|
|
1579
1862
|
managerRef.current?.setGuidyRoutes(routes);
|
|
1580
1863
|
};
|
|
1581
1864
|
}, []);
|
|
1865
|
+
const sendToDocy = useMemo(() => {
|
|
1866
|
+
return (payload) => {
|
|
1867
|
+
return managerRef.current?.sendToDocy(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
|
|
1868
|
+
};
|
|
1869
|
+
}, []);
|
|
1870
|
+
const sendToChat = useMemo(() => {
|
|
1871
|
+
return (payload) => {
|
|
1872
|
+
return managerRef.current?.sendToChat(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
|
|
1873
|
+
};
|
|
1874
|
+
}, []);
|
|
1875
|
+
const sendToEmail = useMemo(() => {
|
|
1876
|
+
return (payload) => {
|
|
1877
|
+
return managerRef.current?.sendToEmail(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
|
|
1878
|
+
};
|
|
1879
|
+
}, []);
|
|
1880
|
+
const sendToCalendar = useMemo(() => {
|
|
1881
|
+
return (payload) => {
|
|
1882
|
+
return managerRef.current?.sendToCalendar(payload) ?? Promise.reject(new Error("Auth manager not initialized"));
|
|
1883
|
+
};
|
|
1884
|
+
}, []);
|
|
1885
|
+
const msGraph = useMemo(() => {
|
|
1886
|
+
return managerRef.current?.getMsGraphClient() ?? null;
|
|
1887
|
+
}, []);
|
|
1582
1888
|
const value = useMemo(() => ({
|
|
1583
1889
|
status,
|
|
1584
1890
|
mode,
|
|
@@ -1598,6 +1904,11 @@ function DocyrusAuthProvider({
|
|
|
1598
1904
|
notifyRouteChange,
|
|
1599
1905
|
requestHostNavigation,
|
|
1600
1906
|
setGuidyRoutes,
|
|
1907
|
+
sendToDocy,
|
|
1908
|
+
sendToChat,
|
|
1909
|
+
sendToEmail,
|
|
1910
|
+
sendToCalendar,
|
|
1911
|
+
msGraph,
|
|
1601
1912
|
error
|
|
1602
1913
|
}), [
|
|
1603
1914
|
status,
|
|
@@ -1618,6 +1929,11 @@ function DocyrusAuthProvider({
|
|
|
1618
1929
|
notifyRouteChange,
|
|
1619
1930
|
requestHostNavigation,
|
|
1620
1931
|
setGuidyRoutes,
|
|
1932
|
+
sendToDocy,
|
|
1933
|
+
sendToChat,
|
|
1934
|
+
sendToEmail,
|
|
1935
|
+
sendToCalendar,
|
|
1936
|
+
msGraph,
|
|
1621
1937
|
error
|
|
1622
1938
|
]);
|
|
1623
1939
|
return /* @__PURE__ */ jsx(DocyrusAuthContext, { value, children });
|