@kivacore/signin 0.20.0 → 0.21.1
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 +119 -102
- package/dist/auth-detector-CRKg56LT.d.ts +122 -0
- package/dist/{constants-jx2_MXlr.d.ts → constants-DbICcNnA.d.ts} +15 -15
- package/dist/core-index.d.ts +31 -122
- package/dist/core-index.js +32 -20
- package/dist/core-index.js.map +1 -1
- package/dist/electron/index.d.ts +3 -0
- package/dist/electron/index.js +22 -3
- package/dist/electron/index.js.map +1 -1
- package/dist/index.d.ts +76 -20
- package/dist/index.js +96 -67
- package/dist/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +3 -3
- package/dist/nextjs/index.js +15 -13
- package/dist/nextjs/index.js.map +1 -1
- package/dist/react-native/index.d.ts +42 -7
- package/dist/react-native/index.js +48 -30
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-DmIgZa_v.d.ts → types-DF2C4eb6.d.ts} +42 -42
- package/dist/use-kiva-client-JxGnfblw.d.ts +32 -0
- package/dist/vue/index.d.ts +154 -23
- package/dist/vue/index.js +62 -42
- package/dist/vue/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/use-docyrus-client-QqgMT3b9.d.ts +0 -32
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ interface MiddlewareRequest {
|
|
|
31
31
|
interface ServerClientConfig {
|
|
32
32
|
/** API base URL. Defaults to `https://alpha-api.docyrus.com` */
|
|
33
33
|
apiUrl?: string;
|
|
34
|
-
/** Cookie key for the access token. Default: `'
|
|
34
|
+
/** Cookie key for the access token. Default: `'kiva-token'` */
|
|
35
35
|
cookieKey?: string;
|
|
36
36
|
}
|
|
37
37
|
/** Auth session information available on the server */
|
|
@@ -57,7 +57,7 @@ interface AuthMiddlewareConfig {
|
|
|
57
57
|
loginPath?: string;
|
|
58
58
|
/** Path to redirect authenticated users when they visit loginPath. Default: `'/'` */
|
|
59
59
|
afterLoginPath?: string;
|
|
60
|
-
/** Cookie key for the access token. Default: `'
|
|
60
|
+
/** Cookie key for the access token. Default: `'kiva-token'` */
|
|
61
61
|
cookieKey?: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -66,7 +66,7 @@ interface AuthMiddlewareConfig {
|
|
|
66
66
|
* Server Components, Server Actions, and Route Handlers.
|
|
67
67
|
*
|
|
68
68
|
* Reads the access token from cookies. The client cannot refresh tokens —
|
|
69
|
-
* that is handled client-side by `
|
|
69
|
+
* that is handled client-side by `KivaAuthProvider`.
|
|
70
70
|
*
|
|
71
71
|
* @example Server Component
|
|
72
72
|
* ```ts
|
package/dist/nextjs/index.js
CHANGED
|
@@ -4,14 +4,22 @@ import { MemoryTokenManager, RestApiClient } from '@kivacore/api-client';
|
|
|
4
4
|
|
|
5
5
|
// src/constants.ts
|
|
6
6
|
var DEFAULT_API_URL = "https://alpha-api.docyrus.com";
|
|
7
|
-
var DEFAULT_SSR_COOKIE_KEY = "
|
|
7
|
+
var DEFAULT_SSR_COOKIE_KEY = "kiva-token";
|
|
8
|
+
var LEGACY_SSR_COOKIE_KEY = "docyrus-token";
|
|
9
|
+
|
|
10
|
+
// src/nextjs/token-cookie.ts
|
|
11
|
+
function readTokenCookie(cookieStore, cookieKey = DEFAULT_SSR_COOKIE_KEY) {
|
|
12
|
+
let value = cookieStore.get(cookieKey)?.value;
|
|
13
|
+
if (!value && cookieKey === DEFAULT_SSR_COOKIE_KEY) {
|
|
14
|
+
value = cookieStore.get(LEGACY_SSR_COOKIE_KEY)?.value;
|
|
15
|
+
}
|
|
16
|
+
return value ? decodeURIComponent(value) : null;
|
|
17
|
+
}
|
|
8
18
|
|
|
9
19
|
// src/nextjs/server-client.ts
|
|
10
20
|
function createServerClient(cookieStore, config = {}) {
|
|
11
21
|
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
12
|
-
const
|
|
13
|
-
const token = cookieStore.get(cookieKey)?.value ?? null;
|
|
14
|
-
const decodedToken = token ? decodeURIComponent(token) : null;
|
|
22
|
+
const decodedToken = readTokenCookie(cookieStore, config.cookieKey);
|
|
15
23
|
const tokenManager = new MemoryTokenManager();
|
|
16
24
|
if (decodedToken) {
|
|
17
25
|
tokenManager.setToken(decodedToken);
|
|
@@ -24,18 +32,14 @@ function createServerClient(cookieStore, config = {}) {
|
|
|
24
32
|
|
|
25
33
|
// src/nextjs/session.ts
|
|
26
34
|
function getSession(cookieStore, cookieKey) {
|
|
27
|
-
const
|
|
28
|
-
const tokenCookie = cookieStore.get(key);
|
|
29
|
-
const accessToken = tokenCookie?.value ? decodeURIComponent(tokenCookie.value) : null;
|
|
35
|
+
const accessToken = readTokenCookie(cookieStore, cookieKey);
|
|
30
36
|
return {
|
|
31
37
|
accessToken,
|
|
32
38
|
isAuthenticated: accessToken !== null
|
|
33
39
|
};
|
|
34
40
|
}
|
|
35
41
|
function getMiddlewareSession(request, cookieKey) {
|
|
36
|
-
const
|
|
37
|
-
const tokenCookie = request.cookies.get(key);
|
|
38
|
-
const accessToken = tokenCookie?.value ? decodeURIComponent(tokenCookie.value) : null;
|
|
42
|
+
const accessToken = readTokenCookie(request.cookies, cookieKey);
|
|
39
43
|
return {
|
|
40
44
|
accessToken,
|
|
41
45
|
isAuthenticated: accessToken !== null
|
|
@@ -43,9 +47,7 @@ function getMiddlewareSession(request, cookieKey) {
|
|
|
43
47
|
}
|
|
44
48
|
function createMiddlewareClient(request, config = {}) {
|
|
45
49
|
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
46
|
-
const
|
|
47
|
-
const token = request.cookies.get(cookieKey)?.value ?? null;
|
|
48
|
-
const decodedToken = token ? decodeURIComponent(token) : null;
|
|
50
|
+
const decodedToken = readTokenCookie(request.cookies, config.cookieKey);
|
|
49
51
|
const tokenManager = new MemoryTokenManager();
|
|
50
52
|
if (decodedToken) {
|
|
51
53
|
tokenManager.setToken(decodedToken);
|
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":"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","file":"index.js","sourcesContent":["export const DEFAULT_API_URL = 'https://alpha-api.docyrus.com';\nexport const INVALID_HOST_API_URL = 'invalid-host-api-url';\nexport const UNTRUSTED_BACKEND_MESSAGE = 'This app can’t run because its host gave it an untrusted backend address.';\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/**\n * Minimum gap between two proactive token refreshes (ms). Stops a refresh that\n * returns a token still inside the expiry buffer from re-triggering itself.\n */\nexport const MIN_TOKEN_REFRESH_INTERVAL_MS = 10_000;\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 '@kivacore/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 '@kivacore/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 '@kivacore/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 '@kivacore/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 '@kivacore/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 '@kivacore/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 '@kivacore/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 '@kivacore/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/token-cookie.ts","../../src/nextjs/server-client.ts","../../src/nextjs/session.ts","../../src/nextjs/middleware.ts"],"names":["MemoryTokenManager","RestApiClient"],"mappings":"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","file":"index.js","sourcesContent":["export const DEFAULT_API_URL = 'https://alpha-api.docyrus.com';\nexport const INVALID_HOST_API_URL = 'invalid-host-api-url';\nexport const UNTRUSTED_BACKEND_MESSAGE = 'This app can’t run because its host gave it an untrusted backend address.';\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\n/** Default trusted iframe hosts: *.kiva.app and the pre-rename *.docyrus.app */\nexport const DEFAULT_ALLOWED_HOST_PATTERN = /^https:\\/\\/[^/]+\\.(?:kiva|docyrus)\\.app$/;\n\n/** localStorage key to persist the pre-redirect location */\nexport const REDIRECT_RETURN_KEY = 'kiva_auth_return_url';\n\n/** Pre-redirect location key used before the Kiva rename (read once after upgrading) */\nexport const LEGACY_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/**\n * Minimum gap between two proactive token refreshes (ms). Stops a refresh that\n * returns a token still inside the expiry buffer from re-triggering itself.\n */\nexport const MIN_TOKEN_REFRESH_INTERVAL_MS = 10_000;\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 = 'kiva-token';\n\n/** Cookie name used before the Kiva rename. Server helpers still read it, and the client removes it. */\nexport const LEGACY_SSR_COOKIE_KEY = 'docyrus-token';\n\n/** URL query parameter name for SSO session tokens */\nexport const SSO_TOKEN_PARAM = 'sso_token';\n","import { DEFAULT_SSR_COOKIE_KEY, LEGACY_SSR_COOKIE_KEY } from '../constants';\nimport { type ReadonlyCookieStore } from './types';\n\n/**\n * Read the access token cookie. With the default cookie name, also accept the cookie\n * set before the Kiva rename, until the client replaces it on its next token sync.\n */\nexport function readTokenCookie(\n cookieStore: ReadonlyCookieStore,\n cookieKey: string = DEFAULT_SSR_COOKIE_KEY\n): string | null {\n let value = cookieStore.get(cookieKey)?.value;\n\n if (!value && cookieKey === DEFAULT_SSR_COOKIE_KEY) {\n value = cookieStore.get(LEGACY_SSR_COOKIE_KEY)?.value;\n }\n\n return value ? decodeURIComponent(value) : null;\n}\n","import { RestApiClient, MemoryTokenManager } from '@kivacore/api-client';\n\nimport { DEFAULT_API_URL } from '../constants';\nimport { readTokenCookie } from './token-cookie';\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 `KivaAuthProvider`.\n *\n * @example Server Component\n * ```ts\n * import { cookies } from 'next/headers';\n * import { createServerClient } from '@kivacore/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 '@kivacore/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 decodedToken = readTokenCookie(cookieStore, config.cookieKey);\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 { readTokenCookie } from './token-cookie';\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 '@kivacore/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 accessToken = readTokenCookie(cookieStore, cookieKey);\n\n return {\n accessToken,\n isAuthenticated: accessToken !== null\n };\n}\n","import { RestApiClient, MemoryTokenManager } from '@kivacore/api-client';\n\nimport { DEFAULT_API_URL, DEFAULT_SSR_COOKIE_KEY } from '../constants';\nimport { readTokenCookie } from './token-cookie';\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 '@kivacore/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 accessToken = readTokenCookie(request.cookies, cookieKey);\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 '@kivacore/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 decodedToken = readTokenCookie(request.cookies, config.cookieKey);\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 '@kivacore/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,9 +1,10 @@
|
|
|
1
1
|
import { OAuth2Tokens } from '@kivacore/api-client';
|
|
2
|
-
import {
|
|
3
|
-
export { A as AclOperation,
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
|
|
2
|
+
import { a as KivaAuthConfig, K as KivaAclRule, b as KivaAuthContextValue, c as KivaCalendarEventPayload, d as KivaEmailPayload, f as KivaPermission, g as KivaRole, h as KivaShareAdaptiveCardPayload, i as KivaSharePayload, j as KivaShareTextPayload, k as KivaUser } from '../types-DF2C4eb6.js';
|
|
3
|
+
export { A as AclOperation, l as AclTargetType, m as AdaptiveCard, p as AuthMode, a3 as AuthSessionResult, q as AuthStatus, R as MsGraphAccount, S as MsGraphClient, T as MsGraphRequest, V as MsGraphRequestOptions, W as MsGraphResponse, Y as MsGraphStatus, a4 as OpenAuthSessionFn, $ as PermissionConfig, a0 as PermissionScope } from '../types-DF2C4eb6.js';
|
|
4
|
+
import { K as KivaAuthProvider, a as KivaAuthProviderProps, u as useKivaAuth, b as useKivaClient } from '../use-kiva-client-JxGnfblw.js';
|
|
5
|
+
export { c as KivaAuthContext } from '../use-kiva-client-JxGnfblw.js';
|
|
6
|
+
export { A as AuthManager, D as DEFAULT_API_URL, c as DEFAULT_OAUTH_SCOPES, g as getAllRoles, d as getAllowedOperations, h as hasPermission, e as hasRole } from '../constants-DbICcNnA.js';
|
|
7
|
+
import * as react from 'react';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* React Native OAuth2 authorization code flow with PKCE.
|
|
@@ -20,7 +21,7 @@ declare class ReactNativeOAuth2Auth {
|
|
|
20
21
|
private storage;
|
|
21
22
|
private openAuthSession;
|
|
22
23
|
private redirectUri;
|
|
23
|
-
constructor(config:
|
|
24
|
+
constructor(config: KivaAuthConfig);
|
|
24
25
|
/**
|
|
25
26
|
* Initiate login by opening an in-app browser for OAuth2 authorization.
|
|
26
27
|
* Unlike the browser version, this does NOT navigate the app — it opens
|
|
@@ -41,4 +42,38 @@ declare class ReactNativeOAuth2Auth {
|
|
|
41
42
|
logout(): Promise<void>;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
/** @deprecated Use `KivaAuthProvider` instead. */
|
|
46
|
+
declare const DocyrusAuthProvider: typeof KivaAuthProvider;
|
|
47
|
+
/** @deprecated Use `KivaAuthContext` instead. */
|
|
48
|
+
declare const DocyrusAuthContext: react.Context<KivaAuthContextValue | null>;
|
|
49
|
+
/** @deprecated Use `KivaAuthProviderProps` instead. */
|
|
50
|
+
type DocyrusAuthProviderProps = KivaAuthProviderProps;
|
|
51
|
+
/** @deprecated Use `useKivaAuth` instead. */
|
|
52
|
+
declare const useDocyrusAuth: typeof useKivaAuth;
|
|
53
|
+
/** @deprecated Use `useKivaClient` instead. */
|
|
54
|
+
declare const useDocyrusClient: typeof useKivaClient;
|
|
55
|
+
/** @deprecated Use `KivaAuthContextValue` instead. */
|
|
56
|
+
type DocyrusAuthContextValue = KivaAuthContextValue;
|
|
57
|
+
/** @deprecated Use `KivaAuthConfig` instead. */
|
|
58
|
+
type DocyrusAuthConfig = KivaAuthConfig;
|
|
59
|
+
/** @deprecated Use `KivaUser` instead. */
|
|
60
|
+
type DocyrusUser = KivaUser;
|
|
61
|
+
/** @deprecated Use `KivaRole` instead. */
|
|
62
|
+
type DocyrusRole = KivaRole;
|
|
63
|
+
/** @deprecated Use `KivaAclRule` instead. */
|
|
64
|
+
type DocyrusAclRule = KivaAclRule;
|
|
65
|
+
/** @deprecated Use `KivaPermission` instead. */
|
|
66
|
+
type DocyrusPermission = KivaPermission;
|
|
67
|
+
/** @deprecated Use `KivaSharePayload` instead. */
|
|
68
|
+
type DocyrusSharePayload = KivaSharePayload;
|
|
69
|
+
/** @deprecated Use `KivaShareTextPayload` instead. */
|
|
70
|
+
type DocyrusShareTextPayload = KivaShareTextPayload;
|
|
71
|
+
/** @deprecated Use `KivaShareAdaptiveCardPayload` instead. */
|
|
72
|
+
type DocyrusShareAdaptiveCardPayload = KivaShareAdaptiveCardPayload;
|
|
73
|
+
/** @deprecated Use `KivaEmailPayload` instead. */
|
|
74
|
+
type DocyrusEmailPayload = KivaEmailPayload;
|
|
75
|
+
/** @deprecated Use `KivaCalendarEventPayload` instead. */
|
|
76
|
+
type DocyrusCalendarEventPayload = KivaCalendarEventPayload;
|
|
77
|
+
|
|
78
|
+
export { DocyrusAuthContext, DocyrusAuthProvider, KivaAclRule, KivaAuthConfig, KivaAuthContextValue, KivaAuthProvider, KivaAuthProviderProps, KivaCalendarEventPayload, KivaEmailPayload, KivaPermission, KivaRole, KivaShareAdaptiveCardPayload, KivaSharePayload, KivaShareTextPayload, KivaUser, ReactNativeOAuth2Auth, useDocyrusAuth, useDocyrusClient, useKivaAuth, useKivaClient };
|
|
79
|
+
export type { DocyrusAclRule, DocyrusAuthConfig, DocyrusAuthContextValue, DocyrusAuthProviderProps, DocyrusCalendarEventPayload, DocyrusEmailPayload, DocyrusPermission, DocyrusRole, DocyrusShareAdaptiveCardPayload, DocyrusSharePayload, DocyrusShareTextPayload, DocyrusUser };
|
|
@@ -16,8 +16,9 @@ var DEFAULT_OAUTH_SCOPES = [
|
|
|
16
16
|
"DS.Read.All"
|
|
17
17
|
];
|
|
18
18
|
var DEFAULT_CALLBACK_PATH = "/auth/callback";
|
|
19
|
-
var DEFAULT_ALLOWED_HOST_PATTERN = /^https:\/\/[^/]+\.docyrus\.app$/;
|
|
20
|
-
var REDIRECT_RETURN_KEY = "
|
|
19
|
+
var DEFAULT_ALLOWED_HOST_PATTERN = /^https:\/\/[^/]+\.(?:kiva|docyrus)\.app$/;
|
|
20
|
+
var REDIRECT_RETURN_KEY = "kiva_auth_return_url";
|
|
21
|
+
var LEGACY_REDIRECT_RETURN_KEY = "docyrus_auth_return_url";
|
|
21
22
|
var TOKEN_EXPIRY_BUFFER_SECONDS = 60;
|
|
22
23
|
var MIN_TOKEN_REFRESH_INTERVAL_MS = 1e4;
|
|
23
24
|
var IFRAME_TOKEN_REFRESH_TIMEOUT_MS = 1e4;
|
|
@@ -35,17 +36,17 @@ var ReactNativeOAuth2Auth = class {
|
|
|
35
36
|
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
36
37
|
if (!config.clientId) {
|
|
37
38
|
throw new Error(
|
|
38
|
-
'
|
|
39
|
+
'KivaAuthProvider: "clientId" is required for React Native mode.'
|
|
39
40
|
);
|
|
40
41
|
}
|
|
41
42
|
if (!config.nativeRedirectUri) {
|
|
42
43
|
throw new Error(
|
|
43
|
-
`
|
|
44
|
+
`KivaAuthProvider: "nativeRedirectUri" is required for React Native mode. Set it to your app's deep link URI (e.g., "myapp://auth/callback").`
|
|
44
45
|
);
|
|
45
46
|
}
|
|
46
47
|
if (!config.openAuthSession) {
|
|
47
48
|
throw new Error(
|
|
48
|
-
'
|
|
49
|
+
'KivaAuthProvider: "openAuthSession" is required for React Native mode. Pass WebBrowser.openAuthSessionAsync from expo-web-browser.'
|
|
49
50
|
);
|
|
50
51
|
}
|
|
51
52
|
const scopes = config.scopes ?? DEFAULT_OAUTH_SCOPES;
|
|
@@ -140,7 +141,7 @@ var StandaloneOAuth2Auth = class {
|
|
|
140
141
|
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
141
142
|
if (!config.clientId) {
|
|
142
143
|
throw new Error(
|
|
143
|
-
'
|
|
144
|
+
'KivaAuthProvider: "clientId" is required. Set it via the clientId prop or the VITE_KIVA_CLIENT_ID / NEXT_PUBLIC_KIVA_CLIENT_ID environment variable.'
|
|
144
145
|
);
|
|
145
146
|
}
|
|
146
147
|
const { clientId } = config;
|
|
@@ -149,7 +150,7 @@ var StandaloneOAuth2Auth = class {
|
|
|
149
150
|
const redirectUri = config.redirectUri ?? `${window.location.origin}${this.callbackPath}`;
|
|
150
151
|
this.storage = config.tokenStorage ?? new BrowserOAuth2TokenStorage(
|
|
151
152
|
window.localStorage,
|
|
152
|
-
config.storageKeyPrefix ?? "
|
|
153
|
+
config.storageKeyPrefix ?? "kiva_oauth2"
|
|
153
154
|
);
|
|
154
155
|
this.oauth2Client = new OAuth2Client({
|
|
155
156
|
baseURL: apiUrl,
|
|
@@ -203,8 +204,9 @@ var StandaloneOAuth2Auth = class {
|
|
|
203
204
|
* Clears the stored value after retrieval.
|
|
204
205
|
*/
|
|
205
206
|
getReturnUrl() {
|
|
206
|
-
const url = window.localStorage.getItem(REDIRECT_RETURN_KEY);
|
|
207
|
+
const url = window.localStorage.getItem(REDIRECT_RETURN_KEY) ?? window.localStorage.getItem(LEGACY_REDIRECT_RETURN_KEY);
|
|
207
208
|
window.localStorage.removeItem(REDIRECT_RETURN_KEY);
|
|
209
|
+
window.localStorage.removeItem(LEGACY_REDIRECT_RETURN_KEY);
|
|
208
210
|
return url;
|
|
209
211
|
}
|
|
210
212
|
/** Get currently stored tokens (e.g., on page reload). */
|
|
@@ -266,7 +268,7 @@ function getJwtSessionKey(accessToken) {
|
|
|
266
268
|
// src/core/iframe-auth.ts
|
|
267
269
|
function postToHost(data) {
|
|
268
270
|
const rnwv = window.ReactNativeWebView;
|
|
269
|
-
const tap = window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__;
|
|
271
|
+
const tap = window.__KIVA_DEVTOOLS_MESSAGE_TAP__ ?? window.__DOCYRUS_DEVTOOLS_MESSAGE_TAP__;
|
|
270
272
|
if (rnwv && typeof rnwv.postMessage === "function") {
|
|
271
273
|
if (typeof tap === "function") tap("out", data, { transport: "webview" });
|
|
272
274
|
rnwv.postMessage(JSON.stringify(data));
|
|
@@ -672,7 +674,7 @@ var IframeAuth = class {
|
|
|
672
674
|
try {
|
|
673
675
|
handler(message);
|
|
674
676
|
} catch (err) {
|
|
675
|
-
console.warn("[
|
|
677
|
+
console.warn("[kiva-signin] guidy command handler threw:", err);
|
|
676
678
|
}
|
|
677
679
|
}
|
|
678
680
|
}
|
|
@@ -698,7 +700,7 @@ var IframeAuth = class {
|
|
|
698
700
|
try {
|
|
699
701
|
handler(message);
|
|
700
702
|
} catch (err) {
|
|
701
|
-
console.warn("[
|
|
703
|
+
console.warn("[kiva-signin] host navigation handler threw:", err);
|
|
702
704
|
}
|
|
703
705
|
}
|
|
704
706
|
}
|
|
@@ -711,7 +713,7 @@ var IframeAuth = class {
|
|
|
711
713
|
try {
|
|
712
714
|
handler(notification);
|
|
713
715
|
} catch (err) {
|
|
714
|
-
console.warn("[
|
|
716
|
+
console.warn("[kiva-signin] host notification handler threw:", err);
|
|
715
717
|
}
|
|
716
718
|
}
|
|
717
719
|
}
|
|
@@ -1083,7 +1085,12 @@ var SsoAuth = class {
|
|
|
1083
1085
|
};
|
|
1084
1086
|
|
|
1085
1087
|
// src/core/cookie-sync.ts
|
|
1086
|
-
var DEFAULT_SSR_COOKIE_KEY = "
|
|
1088
|
+
var DEFAULT_SSR_COOKIE_KEY = "kiva-token";
|
|
1089
|
+
var LEGACY_SSR_COOKIE_KEY = "docyrus-token";
|
|
1090
|
+
function removeCookie(key) {
|
|
1091
|
+
const secure = window.location.protocol === "https:" ? ";Secure" : "";
|
|
1092
|
+
document.cookie = `${key}=;path=/;max-age=0;SameSite=Lax${secure}`;
|
|
1093
|
+
}
|
|
1087
1094
|
function syncTokenToCookie(accessToken, cookieKey, expiresAt) {
|
|
1088
1095
|
if (typeof document === "undefined") return;
|
|
1089
1096
|
const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;
|
|
@@ -1094,12 +1101,13 @@ function syncTokenToCookie(accessToken, cookieKey, expiresAt) {
|
|
|
1094
1101
|
if (seconds > 0) maxAge = `;max-age=${seconds}`;
|
|
1095
1102
|
}
|
|
1096
1103
|
document.cookie = `${key}=${encodeURIComponent(accessToken)};path=/;SameSite=Lax${secure}${maxAge}`;
|
|
1104
|
+
if (key === DEFAULT_SSR_COOKIE_KEY) removeCookie(LEGACY_SSR_COOKIE_KEY);
|
|
1097
1105
|
}
|
|
1098
1106
|
function clearTokenCookie(cookieKey) {
|
|
1099
1107
|
if (typeof document === "undefined") return;
|
|
1100
1108
|
const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;
|
|
1101
|
-
|
|
1102
|
-
|
|
1109
|
+
removeCookie(key);
|
|
1110
|
+
if (key === DEFAULT_SSR_COOKIE_KEY) removeCookie(LEGACY_SSR_COOKIE_KEY);
|
|
1103
1111
|
}
|
|
1104
1112
|
|
|
1105
1113
|
// src/core/host-api-url.ts
|
|
@@ -1108,7 +1116,11 @@ var LOOPBACK_HOSTS = [
|
|
|
1108
1116
|
"127.0.0.1",
|
|
1109
1117
|
"[::1]"
|
|
1110
1118
|
];
|
|
1111
|
-
var TRUSTED_DOMAINS = [
|
|
1119
|
+
var TRUSTED_DOMAINS = [
|
|
1120
|
+
"kiva.app",
|
|
1121
|
+
"docyrus.com",
|
|
1122
|
+
"attornaid.com"
|
|
1123
|
+
];
|
|
1112
1124
|
function readHostApiUrl() {
|
|
1113
1125
|
if (typeof window === "undefined" || !window.location) return void 0;
|
|
1114
1126
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -1216,7 +1228,7 @@ var AuthManager = class {
|
|
|
1216
1228
|
/** Initialize the auth manager. Must be called once on mount. */
|
|
1217
1229
|
async initialize() {
|
|
1218
1230
|
if (this.status === "error") {
|
|
1219
|
-
console.error("[
|
|
1231
|
+
console.error("[kiva-signin]", UNTRUSTED_BACKEND_MESSAGE);
|
|
1220
1232
|
this.notify();
|
|
1221
1233
|
return;
|
|
1222
1234
|
}
|
|
@@ -1258,7 +1270,7 @@ var AuthManager = class {
|
|
|
1258
1270
|
ssoAuth.cleanUrl();
|
|
1259
1271
|
return;
|
|
1260
1272
|
} catch (err) {
|
|
1261
|
-
console.warn("[
|
|
1273
|
+
console.warn("[kiva-signin] SSO token exchange failed:", err);
|
|
1262
1274
|
}
|
|
1263
1275
|
}
|
|
1264
1276
|
}
|
|
@@ -1314,7 +1326,7 @@ var AuthManager = class {
|
|
|
1314
1326
|
try {
|
|
1315
1327
|
handler(message);
|
|
1316
1328
|
} catch (err) {
|
|
1317
|
-
console.warn("[
|
|
1329
|
+
console.warn("[kiva-signin] host navigation handler threw:", err);
|
|
1318
1330
|
}
|
|
1319
1331
|
}
|
|
1320
1332
|
});
|
|
@@ -1323,7 +1335,7 @@ var AuthManager = class {
|
|
|
1323
1335
|
try {
|
|
1324
1336
|
handler(notification);
|
|
1325
1337
|
} catch (err) {
|
|
1326
|
-
console.warn("[
|
|
1338
|
+
console.warn("[kiva-signin] host notification handler threw:", err);
|
|
1327
1339
|
}
|
|
1328
1340
|
}
|
|
1329
1341
|
});
|
|
@@ -1922,8 +1934,8 @@ function hasPermission(user, operation, scope, config) {
|
|
|
1922
1934
|
}
|
|
1923
1935
|
return getAllowedOperations(user, resolved).includes(operation);
|
|
1924
1936
|
}
|
|
1925
|
-
var
|
|
1926
|
-
function
|
|
1937
|
+
var KivaAuthContext = createContext(null);
|
|
1938
|
+
function KivaAuthProvider({
|
|
1927
1939
|
children,
|
|
1928
1940
|
renderAuthError,
|
|
1929
1941
|
...config
|
|
@@ -2096,24 +2108,30 @@ function DocyrusAuthProvider({
|
|
|
2096
2108
|
if (status === "error" && error) {
|
|
2097
2109
|
content = renderAuthError ? renderAuthError(error) : /* @__PURE__ */ jsx("p", { role: "alert", children: UNTRUSTED_BACKEND_MESSAGE });
|
|
2098
2110
|
}
|
|
2099
|
-
return /* @__PURE__ */ jsx(
|
|
2111
|
+
return /* @__PURE__ */ jsx(KivaAuthContext, { value, children: content });
|
|
2100
2112
|
}
|
|
2101
|
-
function
|
|
2102
|
-
const context = use(
|
|
2113
|
+
function useKivaAuth() {
|
|
2114
|
+
const context = use(KivaAuthContext);
|
|
2103
2115
|
if (!context) {
|
|
2104
2116
|
throw new Error(
|
|
2105
|
-
"
|
|
2117
|
+
"useKivaAuth must be used within a <KivaAuthProvider>. Wrap your app with <KivaAuthProvider> to provide auth context."
|
|
2106
2118
|
);
|
|
2107
2119
|
}
|
|
2108
2120
|
return context;
|
|
2109
2121
|
}
|
|
2110
2122
|
|
|
2111
|
-
// src/hooks/use-
|
|
2112
|
-
function
|
|
2113
|
-
const { client } =
|
|
2123
|
+
// src/hooks/use-kiva-client.ts
|
|
2124
|
+
function useKivaClient() {
|
|
2125
|
+
const { client } = useKivaAuth();
|
|
2114
2126
|
return client;
|
|
2115
2127
|
}
|
|
2116
2128
|
|
|
2117
|
-
|
|
2129
|
+
// src/react-native/deprecated-aliases.ts
|
|
2130
|
+
var DocyrusAuthProvider = KivaAuthProvider;
|
|
2131
|
+
var DocyrusAuthContext = KivaAuthContext;
|
|
2132
|
+
var useDocyrusAuth = useKivaAuth;
|
|
2133
|
+
var useDocyrusClient = useKivaClient;
|
|
2134
|
+
|
|
2135
|
+
export { AuthManager, DEFAULT_API_URL, DEFAULT_OAUTH_SCOPES, DocyrusAuthContext, DocyrusAuthProvider, KivaAuthContext, KivaAuthProvider, ReactNativeOAuth2Auth, getAllRoles, getAllowedOperations, hasPermission, hasRole, useDocyrusAuth, useDocyrusClient, useKivaAuth, useKivaClient };
|
|
2118
2136
|
//# sourceMappingURL=index.js.map
|
|
2119
2137
|
//# sourceMappingURL=index.js.map
|