@kivacore/signin 0.0.0 → 0.21.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 +1208 -1
- package/dist/auth-detector-CRKg56LT.d.ts +122 -0
- package/dist/constants-DbICcNnA.d.ts +271 -0
- package/dist/core-index.d.ts +33 -0
- package/dist/core-index.js +1936 -0
- package/dist/core-index.js.map +1 -0
- package/dist/electron/index.d.ts +38 -0
- package/dist/electron/index.js +78 -0
- package/dist/electron/index.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.js +2292 -0
- package/dist/index.js.map +1 -0
- package/dist/nextjs/index.d.ts +180 -0
- package/dist/nextjs/index.js +93 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/react-native/index.d.ts +79 -0
- package/dist/react-native/index.js +2137 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/types-DF2C4eb6.d.ts +816 -0
- package/dist/use-kiva-client-JxGnfblw.d.ts +32 -0
- package/dist/vue/index.d.ts +345 -0
- package/dist/vue/index.js +2026 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +73 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { MemoryTokenManager, RestApiClient } from '@kivacore/api-client';
|
|
2
|
+
|
|
3
|
+
// src/nextjs/server-client.ts
|
|
4
|
+
|
|
5
|
+
// src/constants.ts
|
|
6
|
+
var DEFAULT_API_URL = "https://alpha-api.docyrus.com";
|
|
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
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/nextjs/server-client.ts
|
|
20
|
+
function createServerClient(cookieStore, config = {}) {
|
|
21
|
+
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
22
|
+
const decodedToken = readTokenCookie(cookieStore, config.cookieKey);
|
|
23
|
+
const tokenManager = new MemoryTokenManager();
|
|
24
|
+
if (decodedToken) {
|
|
25
|
+
tokenManager.setToken(decodedToken);
|
|
26
|
+
}
|
|
27
|
+
return new RestApiClient({
|
|
28
|
+
baseURL: apiUrl,
|
|
29
|
+
tokenManager
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/nextjs/session.ts
|
|
34
|
+
function getSession(cookieStore, cookieKey) {
|
|
35
|
+
const accessToken = readTokenCookie(cookieStore, cookieKey);
|
|
36
|
+
return {
|
|
37
|
+
accessToken,
|
|
38
|
+
isAuthenticated: accessToken !== null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function getMiddlewareSession(request, cookieKey) {
|
|
42
|
+
const accessToken = readTokenCookie(request.cookies, cookieKey);
|
|
43
|
+
return {
|
|
44
|
+
accessToken,
|
|
45
|
+
isAuthenticated: accessToken !== null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function createMiddlewareClient(request, config = {}) {
|
|
49
|
+
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
50
|
+
const decodedToken = readTokenCookie(request.cookies, config.cookieKey);
|
|
51
|
+
const tokenManager = new MemoryTokenManager();
|
|
52
|
+
if (decodedToken) {
|
|
53
|
+
tokenManager.setToken(decodedToken);
|
|
54
|
+
}
|
|
55
|
+
return new RestApiClient({
|
|
56
|
+
baseURL: apiUrl,
|
|
57
|
+
tokenManager
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function matchesRoute(pathname, patterns) {
|
|
61
|
+
return patterns.some((pattern) => {
|
|
62
|
+
const regexStr = pattern.replace(/[.+?^${}|[\]\\]/g, "\\$&").replace(/\\\(\\\.\\\*\\\)/g, ".*").replace(/\\\*/g, "[^/]*");
|
|
63
|
+
return new RegExp(`^${regexStr}$`).test(pathname);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
var DEFAULT_PUBLIC_ROUTES = ["/login", "/auth/callback"];
|
|
67
|
+
function authMiddleware(config = {}) {
|
|
68
|
+
const {
|
|
69
|
+
protectedRoutes,
|
|
70
|
+
publicRoutes = DEFAULT_PUBLIC_ROUTES,
|
|
71
|
+
loginPath = "/login",
|
|
72
|
+
afterLoginPath = "/",
|
|
73
|
+
cookieKey = DEFAULT_SSR_COOKIE_KEY
|
|
74
|
+
} = config;
|
|
75
|
+
const allPublicRoutes = publicRoutes.includes(loginPath) ? publicRoutes : [...publicRoutes, loginPath];
|
|
76
|
+
return (request) => {
|
|
77
|
+
const { pathname } = request.nextUrl;
|
|
78
|
+
const session = getMiddlewareSession(request, cookieKey);
|
|
79
|
+
const isPublicRoute = matchesRoute(pathname, allPublicRoutes);
|
|
80
|
+
const isProtectedRoute = protectedRoutes ? matchesRoute(pathname, protectedRoutes) : !isPublicRoute;
|
|
81
|
+
if (session.isAuthenticated && pathname === loginPath) {
|
|
82
|
+
return Response.redirect(new URL(afterLoginPath, request.url));
|
|
83
|
+
}
|
|
84
|
+
if (!session.isAuthenticated && isProtectedRoute) {
|
|
85
|
+
return Response.redirect(new URL(loginPath, request.url));
|
|
86
|
+
}
|
|
87
|
+
return void 0;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { authMiddleware, createMiddlewareClient, createServerClient, getMiddlewareSession, getSession };
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { OAuth2Tokens } from '@kivacore/api-client';
|
|
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';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* React Native OAuth2 authorization code flow with PKCE.
|
|
11
|
+
*
|
|
12
|
+
* Instead of browser redirects (`window.location.href`), this class uses
|
|
13
|
+
* an injected `openAuthSession` function (e.g., expo-web-browser's
|
|
14
|
+
* `WebBrowser.openAuthSessionAsync`) that opens an in-app browser,
|
|
15
|
+
* waits for the callback, and returns the callback URL directly.
|
|
16
|
+
*
|
|
17
|
+
* No DOM, no localStorage, no window.location — fully RN compatible.
|
|
18
|
+
*/
|
|
19
|
+
declare class ReactNativeOAuth2Auth {
|
|
20
|
+
private oauth2Client;
|
|
21
|
+
private storage;
|
|
22
|
+
private openAuthSession;
|
|
23
|
+
private redirectUri;
|
|
24
|
+
constructor(config: KivaAuthConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Initiate login by opening an in-app browser for OAuth2 authorization.
|
|
27
|
+
* Unlike the browser version, this does NOT navigate the app — it opens
|
|
28
|
+
* a modal browser and waits for the callback URL.
|
|
29
|
+
*/
|
|
30
|
+
initiateLogin(): Promise<OAuth2Tokens>;
|
|
31
|
+
/** Get currently stored tokens. */
|
|
32
|
+
getStoredTokens(): Promise<OAuth2Tokens | null>;
|
|
33
|
+
/** Persist externally obtained tokens for immediate authenticated use. */
|
|
34
|
+
setTokens(tokens: OAuth2Tokens): Promise<void>;
|
|
35
|
+
/** Check if the stored token is expired (with 60s buffer). */
|
|
36
|
+
isTokenExpired(): Promise<boolean>;
|
|
37
|
+
/** Refresh the access token using the stored refresh token. */
|
|
38
|
+
refreshToken(): Promise<OAuth2Tokens>;
|
|
39
|
+
/** Get a valid access token, refreshing if needed. */
|
|
40
|
+
getValidAccessToken(): Promise<string>;
|
|
41
|
+
/** Logout: revoke token and clear storage. */
|
|
42
|
+
logout(): Promise<void>;
|
|
43
|
+
}
|
|
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 };
|