@keboola/api-client-react 27.0.0 → 31.0.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/CHANGELOG.md +337 -0
- package/dist/index.cjs +152 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +171 -170
- package/dist/index.d.ts +171 -170
- package/dist/index.js +151 -128
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context.ts","../src/ApiClientProvider.tsx","../src/AuthProvider.tsx","../src/LegacyAuthProvider.tsx"],"names":["createContext","use","jsx","useState","useRef","useEffect"],"mappings":";;;;;;AAIA,IAAM,wBAAA,GAA2B,wDAAA;AACjC,IAAM,qBAAA,GAAwB,sDAAA;AAC9B,IAAM,mBAAA,GAAsB,oDAAA;AAC5B,IAAM,kBAAA,GAAqB,8CAAA;AAC3B,IAAM,yBAAA,GAA4B,0DAAA;AAIlC,IAAM,UAAA,GAAaA,oBAAiC,IAAI,CAAA;AACjD,IAAM,WAAA,GAAc,UAAA;AAI3B,IAAM,WAAA,GAAcA,oBAAoC,IAAI,CAAA;AACrD,IAAM,mBAAA,GAAsB,WAAA;AAEnC,IAAM,iBAAA,GAAoBA,oBAAoC,IAAI,CAAA;AAC3D,IAAM,yBAAA,GAA4B,iBAAA;AAElC,IAAM,eAAe,MAAM;AAChC,EAAA,MAAM,GAAA,GAAMC,UAAI,UAAU,CAAA;AAC1B,EAAA,IAAI,GAAA,KAAQ,IAAA,EAAM,MAAM,IAAI,MAAM,wBAAwB,CAAA;AAC1D,EAAA,OAAO,GAAA;AACT;AAEO,IAAM,aAAa,MAAM;AAC9B,EAAA,MAAM,GAAA,GAAMA,UAAI,UAAU,CAAA;AAC1B,EAAA,IAAI,GAAA,KAAQ,IAAA,EAAM,MAAM,IAAI,MAAM,qBAAqB,CAAA;AACvD,EAAA,OAAO,IAAI,OAAA,C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AAC,YAAY,CAAC,CAAA;AAEjB,EAAA,MAAM,WAAW,MAAM;AACrB,IAAA,IAAI,YAAA,KAAiB,SAAS,OAAO,QAAA;AACrC,IAAA,IAAI,YAAA,KAAiB,WAAW,OAAO,aAAA;AACvC,IAAA,OAAO,QAAA;AAAA,EACT,CAAA,GAAG;AAEH,EAAA,uBAAOH,cAAAA,CAAC,yBAAA,EAAA,EAA0B,KAAA,EAAO,SAAU,QAAA,EAAA,OAAA,EAAQ,CAAA;AAC7D","file":"index.cjs","sourcesContent":["import { createContext, use } from 'react';\n\nimport type { BearerSession, KeboolaApi, LegacySession } from '@keboola/api-client';\n\nconst MISSING_API_CLIENT_ERROR = 'useApiClient must be used within <ApiClientProvider />';\nconst MISSING_PROJECT_ERROR = 'useProject must be used within <ApiClientProvider />';\nconst MISSING_STACK_ERROR = 'useStack must be used within <ApiClientProvider />';\nconst MISSING_AUTH_ERROR = 'useAuth must be used within <AuthProvider />';\nconst MISSING_LEGACY_AUTH_ERROR = 'useLegacyAuth must be used within <LegacyAuthProvider />';\n\n// The product API (`auth` + `management` + every product namespace), flow-agnostic. Both the\n// bearer and legacy flows produce the same `KeboolaApi` surface, so consumers never branch on flow.\nconst ApiContext = createContext<KeboolaApi | null>(null);\nexport const ApiProvider = ApiContext;\n\n// The lifecycle sessions live in their own, flow-specific contexts so the auth surface a component\n// reaches for is explicit. Only the matching provider is mounted per flow.\nconst AuthContext = createContext<BearerSession | null>(null);\nexport const AuthContextProvider = AuthContext;\n\nconst LegacyAuthContext = createContext<LegacySession | null>(null);\nexport const LegacyAuthContextProvider = LegacyAuthContext;\n\nexport const useApiClient = () => {\n const api = use(ApiContext);\n if (api === null) throw new Error(MISSING_API_CLIENT_ERROR);\n return api;\n};\n\nexport const useProject = () => {\n const api = use(ApiContext);\n if (api === null) throw new Error(MISSING_PROJECT_ERROR);\n return api.context.project;\n};\n\nexport const useStack = () => {\n const api = use(ApiContext);\n if (api === null) throw new Error(MISSING_STACK_ERROR);\n return api.context.stack;\n};\n\n/** The bearer (OAuth) lifecycle session. Throws outside `<AuthProvider />`. */\nexport const useAuth = () => {\n const session = use(AuthContext);\n if (session === null) throw new Error(MISSING_AUTH_ERROR);\n return session;\n};\n\n/** The legacy (SAPI) lifecycle session. Throws outside `<LegacyAuthProvider />`. */\nexport const useLegacyAuth = () => {\n const session = use(LegacyAuthContext);\n if (session === null) throw new Error(MISSING_LEGACY_AUTH_ERROR);\n return session;\n};\n","import type { ReactNode } from 'react';\n\nimport type { KeboolaApi } from '@keboola/api-client';\n\nimport { ApiProvider } from './context';\n\ntype Props = {\n /** The flow-agnostic product API — the `api` half of a keboola client. */\n api: KeboolaApi;\n children: ReactNode;\n};\n\n/**\n * Provides the product API to `useApiClient()`. A pure pass-through: the auth lifecycle (driving\n * to ready, gating on a fallback) belongs to `AuthProvider` / `LegacyAuthProvider`, which mount\n * this provider once their session is ready.\n */\nexport const ApiClientProvider = ({ api, children }: Props) => (\n <ApiProvider value={api}>{children}</ApiProvider>\n);\n","import { useEffect, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport type { BearerSession } from '@keboola/api-client';\n\nimport { AuthContextProvider } from './context';\n\ntype BearerCredential = Parameters<BearerSession['authenticate']>[0];\ntype Snapshot = ReturnType<BearerSession['debug']>;\ntype RestoreStatus = Awaited<ReturnType<BearerSession['restore']>>['status'];\n\n/** The session state guaranteed to exist once the storage build is ready. */\ntype ScopedState = { projectId: number; baseUrl: string };\n\ntype BaseProps = {\n session: BearerSession;\n onAccessTokenChange?: (accessToken: string) => void;\n /** Rendered while a persisted session is being restored, or the bootstrap is in flight. */\n loadingFallback?: ReactNode;\n /** Rendered when the storage build fails. */\n errorFallback?: ReactNode;\n /**\n * Rendered only once the session is scoped and the storage build is ready. Pass a function to\n * receive the scoped state (the project the session settled on) without re-narrowing it yourself.\n */\n children: ReactNode | ((scoped: ScopedState) => ReactNode);\n};\n\n/**\n * Two mutually exclusive bootstrap modes, discriminated by whether a credential is supplied:\n * - **programmatic** — `credential` + `projectId` given, so `baseUrl` is **required**: a credential\n * is bound to the stack that issued it and `authenticate` refuses an unconfigured session.\n * - **interactive** — none of the three given; the stack comes from the session instead — `restore()`\n * adopts the persisted one, otherwise the login UI sets it. `anonymousFallback` is **required**\n * here (a missing login UI would leave the app on a permanently blank screen).\n */\ntype Props = BaseProps &\n (\n | {\n credential: BearerCredential;\n projectId: number;\n baseUrl: string;\n anonymousFallback?: never;\n }\n | {\n credential?: undefined;\n projectId?: undefined;\n baseUrl?: never;\n anonymousFallback: ReactNode;\n }\n );\n\nexport const AuthProvider = ({\n session,\n baseUrl,\n credential,\n projectId,\n onAccessTokenChange,\n loadingFallback = null,\n errorFallback = null,\n anonymousFallback = null,\n children,\n}: Props) => {\n const [snapshot, setSnapshot] = useState<Snapshot>(() => session.debug());\n const [isRestoring, setIsRestoring] = useState(() => session.hasPersistedValue());\n const [restoreStatus, setRestoreStatus] = useState<RestoreStatus | null>(null);\n const restoreStartedRef = useRef(false);\n\n useEffect(() => session.subscribe(setSnapshot), [session]);\n\n // Programmatic only. Interactive leaves the stack unset: `restore()` adopts the persisted one, and\n // failing that the login UI picks it — so there is nothing to configure up front.\n useEffect(() => {\n if (baseUrl === undefined) return;\n if (snapshot.config.baseUrl !== null) return;\n session.setBaseUrl(baseUrl);\n }, [session, baseUrl, snapshot.config.baseUrl]);\n\n // Runs regardless of whether a stack is configured — with none, `restore()` adopts the stack the\n // persisted session belongs to. (Declared after the effect above, so programmatic mode has already\n // configured its stack by the time this runs.) The ref guards StrictMode's double-invoked effect:\n // `restoreStatus` only lands asynchronously, so it cannot prevent a second synchronous call.\n useEffect(() => {\n if (restoreStartedRef.current) return;\n restoreStartedRef.current = true;\n session\n .restore()\n .then((result) => setRestoreStatus(result.status))\n .catch((error) => {\n console.error('Keboola bearer session restore failed', error);\n setRestoreStatus('empty');\n })\n .finally(() => setIsRestoring(false));\n }, [session]);\n\n useEffect(() => {\n if (restoreStatus === null || restoreStatus === 'restored') return;\n if (credential === undefined) return;\n if (snapshot.config.status !== 'anonymous') return;\n session.authenticate(credential);\n }, [session, restoreStatus, credential, snapshot.config.status]);\n\n useEffect(() => {\n if (restoreStatus === null || restoreStatus === 'restored') return;\n if (projectId === undefined) return;\n if (snapshot.config.status !== 'authenticated') return;\n session.setProject(projectId);\n }, [session, restoreStatus, projectId, snapshot.config.status]);\n\n const accessToken =\n snapshot.config.status === 'anonymous' ? undefined : snapshot.config.credential.accessToken;\n\n useEffect(() => {\n if (accessToken !== undefined) onAccessTokenChange?.(accessToken);\n }, [accessToken, onAccessTokenChange]);\n\n // Programmatic mode drives itself to ready, so it must never fall through to `anonymousFallback`.\n const isProgrammatic = credential !== undefined && projectId !== undefined;\n\n const content = (() => {\n if (snapshot.storage === 'ready') {\n if (typeof children !== 'function') return children;\n // A ready storage build implies a scoped session; narrowing here is for the type checker.\n if (snapshot.config.status !== 'scoped') return null;\n const { projectId: scopedProjectId, baseUrl: scopedBaseUrl } = snapshot.config;\n return children({ projectId: scopedProjectId, baseUrl: scopedBaseUrl });\n }\n if (snapshot.storage === 'errored') return errorFallback;\n if (isRestoring || snapshot.storage === 'pending' || isProgrammatic) return loadingFallback;\n return anonymousFallback;\n })();\n\n return <AuthContextProvider value={session}>{content}</AuthContextProvider>;\n};\n","import { useEffect, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport type { LegacySession } from '@keboola/api-client';\n\nimport { LegacyAuthContextProvider } from './context';\n\ntype Props = {\n session: LegacySession;\n /** Stack base URL. */\n baseUrl: string;\n /** SAPI token — drives the storage build to ready. */\n storageToken: string;\n /** Optional manage-api token — unlocks `api.management`. */\n managementToken?: string;\n /** Rendered until the storage build reaches ready. */\n fallback?: ReactNode;\n /** Rendered when the storage build fails — e.g. the SAPI token is expired or revoked. */\n errorFallback?: ReactNode;\n children: ReactNode;\n};\n\n/**\n * Owns the legacy (SAPI) lifecycle: on mount it configures the stack and drives the session to\n * ready, rendering `fallback` until the storage build resolves. The backend-injected SAPI token is\n * known up front, so this drives itself (unlike the interactive bearer `AuthProvider`). Exposes the\n * session via `useLegacyAuth()` and gates `children` behind readiness.\n */\nexport const LegacyAuthProvider = ({\n session,\n baseUrl,\n storageToken,\n managementToken,\n fallback = null,\n errorFallback = fallback,\n children,\n}: Props) => {\n // The build state, not just readiness: `errored` and `pending` render differently.\n const [storageState, setStorageState] = useState(() => session.debug().storage);\n // Guards the once-only drive against React StrictMode's double-mounted effect.\n const startedRef = useRef<boolean>(false);\n\n useEffect(() => {\n const unsubscribe = session.subscribe((snapshot) => setStorageState(snapshot.storage));\n\n if (!startedRef.current) {\n startedRef.current = true;\n session.setBaseUrl(baseUrl);\n if (managementToken) session.authenticateManagement(managementToken);\n // Fire-and-forget: `subscribe` moves `storageState` once the build resolves. A failed build\n // resolves rather than rejects, so this catch only covers a synchronous throw.\n void session\n .authenticateStorageAsync(storageToken)\n .catch((error) => console.error('Keboola session bootstrap failed', error));\n }\n\n return unsubscribe;\n // drive to ready only on initial mount\n // oxlint-disable-next-line react/exhaustive-deps\n }, []);\n\n // The only place a failed build is observable — nothing rejects, so without this it is silent.\n useEffect(() => {\n if (storageState === 'errored') {\n console.error('Keboola session bootstrap failed: the storage build errored.');\n }\n }, [storageState]);\n\n const content = (() => {\n if (storageState === 'ready') return children;\n if (storageState === 'errored') return errorFallback;\n return fallback;\n })();\n\n return <LegacyAuthContextProvider value={session}>{content}</LegacyAuthContextProvider>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","use","useState","useRef","useState","useRef"],"sources":["../src/context.ts","../src/ApiClientProvider.tsx","../src/AuthProvider.tsx","../src/LegacyAuthProvider.tsx"],"sourcesContent":["import { createContext, use } from 'react';\n\nimport type { BearerSession, KeboolaApi, LegacySession } from '@keboola/api-client';\n\nconst MISSING_API_CLIENT_ERROR = 'useApiClient must be used within <ApiClientProvider />';\nconst MISSING_PROJECT_ERROR = 'useProject must be used within <ApiClientProvider />';\nconst MISSING_STACK_ERROR = 'useStack must be used within <ApiClientProvider />';\nconst MISSING_AUTH_ERROR = 'useAuth must be used within <AuthProvider />';\nconst MISSING_LEGACY_AUTH_ERROR = 'useLegacyAuth must be used within <LegacyAuthProvider />';\n\n// The product API (`auth` + `management` + every product namespace), flow-agnostic. Both the\n// bearer and legacy flows produce the same `KeboolaApi` surface, so consumers never branch on flow.\nconst ApiContext = createContext<KeboolaApi | null>(null);\nexport const ApiProvider = ApiContext;\n\n// The lifecycle sessions live in their own, flow-specific contexts so the auth surface a component\n// reaches for is explicit. Only the matching provider is mounted per flow.\nconst AuthContext = createContext<BearerSession | null>(null);\nexport const AuthContextProvider = AuthContext;\n\nconst LegacyAuthContext = createContext<LegacySession | null>(null);\nexport const LegacyAuthContextProvider = LegacyAuthContext;\n\nexport const useApiClient = () => {\n const api = use(ApiContext);\n if (api === null) throw new Error(MISSING_API_CLIENT_ERROR);\n return api;\n};\n\nexport const useProject = () => {\n const api = use(ApiContext);\n if (api === null) throw new Error(MISSING_PROJECT_ERROR);\n return api.context.project;\n};\n\nexport const useStack = () => {\n const api = use(ApiContext);\n if (api === null) throw new Error(MISSING_STACK_ERROR);\n return api.context.stack;\n};\n\n/** The bearer (OAuth) lifecycle session. Throws outside `<AuthProvider />`. */\nexport const useAuth = () => {\n const session = use(AuthContext);\n if (session === null) throw new Error(MISSING_AUTH_ERROR);\n return session;\n};\n\n/** The legacy (SAPI) lifecycle session. Throws outside `<LegacyAuthProvider />`. */\nexport const useLegacyAuth = () => {\n const session = use(LegacyAuthContext);\n if (session === null) throw new Error(MISSING_LEGACY_AUTH_ERROR);\n return session;\n};\n","import type { ReactNode } from 'react';\n\nimport type { KeboolaApi } from '@keboola/api-client';\n\nimport { ApiProvider } from './context';\n\ntype Props = {\n /** The flow-agnostic product API — the `api` half of a keboola client. */\n api: KeboolaApi;\n children: ReactNode;\n};\n\n/**\n * Provides the product API to `useApiClient()`. A pure pass-through: the auth lifecycle (driving\n * to ready, gating on a fallback) belongs to `AuthProvider` / `LegacyAuthProvider`, which mount\n * this provider once their session is ready.\n */\nexport const ApiClientProvider = ({ api, children }: Props) => (\n <ApiProvider value={api}>{children}</ApiProvider>\n);\n","import { useEffect, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport type { BearerSession } from '@keboola/api-client';\n\nimport { AuthContextProvider } from './context';\n\ntype BearerCredential = Parameters<BearerSession['authenticate']>[0];\ntype Snapshot = ReturnType<BearerSession['debug']>;\ntype RestoreStatus = Awaited<ReturnType<BearerSession['restore']>>['status'];\n\n/** The session state guaranteed to exist once the storage build is ready. */\ntype ScopedState = { projectId: number; baseUrl: string };\n\ntype BaseProps = {\n session: BearerSession;\n onAccessTokenChange?: (accessToken: string) => void;\n /** Rendered while a persisted session is being restored, or the bootstrap is in flight. */\n loadingFallback?: ReactNode;\n /** Rendered when the storage build fails. */\n errorFallback?: ReactNode;\n /**\n * Rendered only once the session is scoped and the storage build is ready. Pass a function to\n * receive the scoped state (the project the session settled on) without re-narrowing it yourself.\n */\n children: ReactNode | ((scoped: ScopedState) => ReactNode);\n};\n\n/**\n * Two mutually exclusive bootstrap modes, discriminated by whether a credential is supplied:\n * - **programmatic** — `credential` + `projectId` given, so `baseUrl` is **required**: a credential\n * is bound to the stack that issued it and `authenticate` refuses an unconfigured session.\n * - **interactive** — none of the three given; the stack comes from the session instead — `restore()`\n * adopts the persisted one, otherwise the login UI sets it. `anonymousFallback` is **required**\n * here (a missing login UI would leave the app on a permanently blank screen).\n */\ntype Props = BaseProps &\n (\n | {\n credential: BearerCredential;\n projectId: number;\n baseUrl: string;\n anonymousFallback?: never;\n }\n | {\n credential?: undefined;\n projectId?: undefined;\n baseUrl?: never;\n anonymousFallback: ReactNode;\n }\n );\n\nexport const AuthProvider = ({\n session,\n baseUrl,\n credential,\n projectId,\n onAccessTokenChange,\n loadingFallback = null,\n errorFallback = null,\n anonymousFallback = null,\n children,\n}: Props) => {\n const [snapshot, setSnapshot] = useState<Snapshot>(() => session.debug());\n const [isRestoring, setIsRestoring] = useState(() => session.hasPersistedValue());\n const [restoreStatus, setRestoreStatus] = useState<RestoreStatus | null>(null);\n const restoreStartedRef = useRef(false);\n\n useEffect(() => session.subscribe(setSnapshot), [session]);\n\n // Programmatic only. Interactive leaves the stack unset: `restore()` adopts the persisted one, and\n // failing that the login UI picks it — so there is nothing to configure up front.\n useEffect(() => {\n if (baseUrl === undefined) return;\n if (snapshot.config.baseUrl !== null) return;\n session.setBaseUrl(baseUrl);\n }, [session, baseUrl, snapshot.config.baseUrl]);\n\n // Runs regardless of whether a stack is configured — with none, `restore()` adopts the stack the\n // persisted session belongs to. (Declared after the effect above, so programmatic mode has already\n // configured its stack by the time this runs.) The ref guards StrictMode's double-invoked effect:\n // `restoreStatus` only lands asynchronously, so it cannot prevent a second synchronous call.\n useEffect(() => {\n if (restoreStartedRef.current) return;\n restoreStartedRef.current = true;\n session\n .restore()\n .then((result) => setRestoreStatus(result.status))\n .catch((error) => {\n console.error('Keboola bearer session restore failed', error);\n setRestoreStatus('empty');\n })\n .finally(() => setIsRestoring(false));\n }, [session]);\n\n useEffect(() => {\n if (restoreStatus === null || restoreStatus === 'restored') return;\n if (credential === undefined) return;\n if (snapshot.config.status !== 'anonymous') return;\n session.authenticate(credential);\n }, [session, restoreStatus, credential, snapshot.config.status]);\n\n useEffect(() => {\n if (restoreStatus === null || restoreStatus === 'restored') return;\n if (projectId === undefined) return;\n if (snapshot.config.status !== 'authenticated') return;\n session.setProject(projectId);\n }, [session, restoreStatus, projectId, snapshot.config.status]);\n\n const accessToken =\n snapshot.config.status === 'anonymous' ? undefined : snapshot.config.credential.accessToken;\n\n useEffect(() => {\n if (accessToken !== undefined) onAccessTokenChange?.(accessToken);\n }, [accessToken, onAccessTokenChange]);\n\n // Programmatic mode drives itself to ready, so it must never fall through to `anonymousFallback`.\n const isProgrammatic = credential !== undefined && projectId !== undefined;\n\n const content = (() => {\n if (snapshot.storage === 'ready') {\n if (typeof children !== 'function') return children;\n // A ready storage build implies a scoped session; narrowing here is for the type checker.\n if (snapshot.config.status !== 'scoped') return null;\n const { projectId: scopedProjectId, baseUrl: scopedBaseUrl } = snapshot.config;\n return children({ projectId: scopedProjectId, baseUrl: scopedBaseUrl });\n }\n if (snapshot.storage === 'errored') return errorFallback;\n if (isRestoring || snapshot.storage === 'pending' || isProgrammatic) return loadingFallback;\n return anonymousFallback;\n })();\n\n return <AuthContextProvider value={session}>{content}</AuthContextProvider>;\n};\n","import { useEffect, useRef, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport type { LegacySession } from '@keboola/api-client';\n\nimport { LegacyAuthContextProvider } from './context';\n\ntype Props = {\n session: LegacySession;\n /** Stack base URL. */\n baseUrl: string;\n /** SAPI token — drives the storage build to ready. */\n storageToken: string;\n /** Optional manage-api token — unlocks `api.management`. */\n managementToken?: string;\n /** Rendered until the storage build reaches ready. */\n fallback?: ReactNode;\n /** Rendered when the storage build fails — e.g. the SAPI token is expired or revoked. */\n errorFallback?: ReactNode;\n children: ReactNode;\n};\n\n/**\n * Owns the legacy (SAPI) lifecycle: on mount it configures the stack and drives the session to\n * ready, rendering `fallback` until the storage build resolves. The backend-injected SAPI token is\n * known up front, so this drives itself (unlike the interactive bearer `AuthProvider`). Exposes the\n * session via `useLegacyAuth()` and gates `children` behind readiness.\n */\nexport const LegacyAuthProvider = ({\n session,\n baseUrl,\n storageToken,\n managementToken,\n fallback = null,\n errorFallback = fallback,\n children,\n}: Props) => {\n // The build state, not just readiness: `errored` and `pending` render differently.\n const [storageState, setStorageState] = useState(() => session.debug().storage);\n // Guards the once-only drive against React StrictMode's double-mounted effect.\n const startedRef = useRef<boolean>(false);\n\n useEffect(() => {\n const unsubscribe = session.subscribe((snapshot) => setStorageState(snapshot.storage));\n\n if (!startedRef.current) {\n startedRef.current = true;\n session.setBaseUrl(baseUrl);\n if (managementToken) session.authenticateManagement(managementToken);\n // Fire-and-forget: `subscribe` moves `storageState` once the build resolves. A failed build\n // resolves rather than rejects, so this catch only covers a synchronous throw.\n void session\n .authenticateStorageAsync(storageToken)\n .catch((error) => console.error('Keboola session bootstrap failed', error));\n }\n\n return unsubscribe;\n // drive to ready only on initial mount\n // oxlint-disable-next-line react/exhaustive-deps\n }, []);\n\n // The only place a failed build is observable — nothing rejects, so without this it is silent.\n useEffect(() => {\n if (storageState === 'errored') {\n console.error('Keboola session bootstrap failed: the storage build errored.');\n }\n }, [storageState]);\n\n const content = (() => {\n if (storageState === 'ready') return children;\n if (storageState === 'errored') return errorFallback;\n return fallback;\n })();\n\n return <LegacyAuthContextProvider value={session}>{content}</LegacyAuthContextProvider>;\n};\n"],"mappings":";;;;AAIA,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,4BAA4B;AAIlC,MAAM,cAAA,GAAaA,MAAAA,cAAAA,CAAiC,IAAI;AACxD,MAAa,cAAc;AAI3B,MAAM,eAAA,GAAcA,MAAAA,cAAAA,CAAoC,IAAI;AAC5D,MAAa,sBAAsB;AAEnC,MAAM,qBAAA,GAAoBA,MAAAA,cAAAA,CAAoC,IAAI;AAClE,MAAa,4BAA4B;AAEzC,MAAa,qBAAqB;CAChC,MAAM,OAAA,GAAMC,MAAAA,IAAAA,CAAI,UAAU;CAC1B,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,wBAAwB;CAC1D,OAAO;AACT;AAEA,MAAa,mBAAmB;CAC9B,MAAM,OAAA,GAAMA,MAAAA,IAAAA,CAAI,UAAU;CAC1B,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,qBAAqB;CACvD,OAAO,IAAI,QAAQ;AACrB;AAEA,MAAa,iBAAiB;CAC5B,MAAM,OAAA,GAAMA,MAAAA,IAAAA,CAAI,UAAU;CAC1B,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,mBAAmB;CACrD,OAAO,IAAI,QAAQ;AACrB;;AAGA,MAAa,gBAAgB;CAC3B,MAAM,WAAA,GAAUA,MAAAA,IAAAA,CAAI,W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B,CAAA;AAC5E;;;;;;;;;ACzGA,MAAa,sBAAsB,EACjC,SACA,SACA,cACA,iBACA,WAAW,MACX,gBAAgB,UAChB,eACW;CAEX,MAAM,CAAC,cAAc,oBAAA,GAAmBC,MAAAA,SAAAA,OAAe,QAAQ,MAAM,CAAC,CAAC,OAAO;CAE9E,MAAM,cAAA,GAAaC,MAAAA,OAAAA,CAAgB,KAAK;CAExC,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,cAAc,QAAQ,WAAW,aAAa,gBAAgB,SAAS,OAAO,CAAC;EAErF,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,QAAQ,WAAW,OAAO;GAC1B,IAAI,iBAAiB,QAAQ,uBAAuB,eAAe;GAGnE,QACG,yBAAyB,YAAY,CAAC,CACtC,OAAO,UAAU,QAAQ,MAAM,oCAAoC,KAAK,CAAC;EAC9E;EAEA,OAAO;CAGT,GAAG,CAAC,CAAC;CAGL,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,iBAAiB,WACnB,QAAQ,MAAM,8DAA8D;CAEhF,GAAG,CAAC,YAAY,CAAC;CAQjB,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,2BAAD;EAA2B,OAAO;EANlB,iBAAA;GACrB,IAAI,iBAAiB,SAAS,OAAO;GACrC,IAAI,iBAAiB,WAAW,OAAO;GACvC,OAAO;EACT,EAAA,CAEyD;CAA6B,CAAA;AACxF"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,177 +1,176 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
-
import { ReactNode } from 'react';
|
|
6
|
-
|
|
1
|
+
import { BearerSession, KeboolaApi, LegacySession } from "@keboola/api-client";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/context.d.ts
|
|
7
4
|
declare const useApiClient: () => KeboolaApi;
|
|
8
5
|
declare const useProject: () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
hasFeature: (...feature: string[]) => boolean;
|
|
7
|
+
hasAdminFeature: (...feature: string[]) => boolean;
|
|
8
|
+
hasBackend: (backend: import("@keboola/api-client/storage/types").Backend) => boolean;
|
|
9
|
+
sapiToken: import("@keboola/api-client/storage/types").StorageToken;
|
|
13
10
|
};
|
|
14
11
|
declare const useStack: () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
api: string;
|
|
13
|
+
documentation: string;
|
|
14
|
+
host: string;
|
|
15
|
+
revision: string;
|
|
16
|
+
stack: string;
|
|
17
|
+
urlTemplates: {
|
|
18
|
+
orchestrationJob: string;
|
|
19
|
+
};
|
|
20
|
+
version: string;
|
|
21
|
+
services: import("@keboola/api-client/storage/types").Service[];
|
|
22
|
+
features: string[];
|
|
23
|
+
components: import("@keboola/api-client/storage/types").StackComponent[];
|
|
24
|
+
hasFeature: (...feature: string[]) => boolean;
|
|
25
|
+
getServiceUrl: (serviceId: import("@keboola/api-client/storage/types").ServiceId) => string | null;
|
|
26
|
+
hasService: (serviceId: import("@keboola/api-client/storage/types").ServiceId) => boolean;
|
|
27
|
+
getComponent: (componentId: string) => import("@keboola/api-client/storage/types").StackComponent | null;
|
|
28
|
+
hasComponent: (...componentId: string[]) => boolean;
|
|
32
29
|
};
|
|
33
30
|
/** The bearer (OAuth) lifecycle session. Throws outside `<AuthProvider />`. */
|
|
34
31
|
declare const useAuth: () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
hasPersistedValue: () => boolean;
|
|
33
|
+
setBaseUrl: (baseUrl: string) => void;
|
|
34
|
+
isStorageReady: () => boolean;
|
|
35
|
+
authenticate: (tokens: {
|
|
36
|
+
accessToken: string;
|
|
37
|
+
refreshToken: string;
|
|
38
|
+
expiresIn: number;
|
|
39
|
+
}) => void;
|
|
40
|
+
setProject: (projectId: number) => void;
|
|
41
|
+
setProjectAsync: (projectId: number) => Promise<void>;
|
|
42
|
+
clearProject: () => void;
|
|
43
|
+
reset: () => void;
|
|
44
|
+
debugForceRefresh: () => void;
|
|
45
|
+
restore: () => Promise<{
|
|
46
|
+
status: 'empty' | 'restored' | 'expired';
|
|
47
|
+
}>;
|
|
48
|
+
subscribe: (listener: (snapshot: {
|
|
49
|
+
type: 'Bearer';
|
|
50
|
+
config: {
|
|
51
|
+
status: 'anonymous';
|
|
52
|
+
baseUrl: string | null;
|
|
53
|
+
} | {
|
|
54
|
+
status: 'authenticated';
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
credential: {
|
|
57
|
+
accessToken: string;
|
|
58
|
+
refreshToken: string;
|
|
59
|
+
expiresIn: number;
|
|
60
|
+
} & {
|
|
61
|
+
issuedAt: number;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
status: 'scoped';
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
credential: {
|
|
67
|
+
accessToken: string;
|
|
68
|
+
refreshToken: string;
|
|
69
|
+
expiresIn: number;
|
|
70
|
+
} & {
|
|
71
|
+
issuedAt: number;
|
|
72
|
+
};
|
|
73
|
+
projectId: number;
|
|
74
|
+
};
|
|
75
|
+
authReady: boolean;
|
|
76
|
+
managementReady: boolean;
|
|
77
|
+
storage: import("@keboola/api-client").AsyncState<unknown>['state'];
|
|
78
|
+
}) => void) => () => void;
|
|
79
|
+
debug: () => {
|
|
80
|
+
type: 'Bearer';
|
|
81
|
+
config: {
|
|
82
|
+
status: 'anonymous';
|
|
83
|
+
baseUrl: string | null;
|
|
84
|
+
} | {
|
|
85
|
+
status: 'authenticated';
|
|
86
|
+
baseUrl: string;
|
|
87
|
+
credential: {
|
|
88
|
+
accessToken: string;
|
|
89
|
+
refreshToken: string;
|
|
90
|
+
expiresIn: number;
|
|
91
|
+
} & {
|
|
92
|
+
issuedAt: number;
|
|
93
|
+
};
|
|
94
|
+
} | {
|
|
95
|
+
status: 'scoped';
|
|
96
|
+
baseUrl: string;
|
|
97
|
+
credential: {
|
|
39
98
|
accessToken: string;
|
|
40
99
|
refreshToken: string;
|
|
41
100
|
expiresIn: number;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
reset: () => void;
|
|
47
|
-
debugForceRefresh: () => void;
|
|
48
|
-
restore: () => Promise<{
|
|
49
|
-
status: "empty" | "restored" | "expired";
|
|
50
|
-
}>;
|
|
51
|
-
subscribe: (listener: (snapshot: {
|
|
52
|
-
type: "Bearer";
|
|
53
|
-
config: {
|
|
54
|
-
status: "anonymous";
|
|
55
|
-
baseUrl: string | null;
|
|
56
|
-
} | {
|
|
57
|
-
status: "authenticated";
|
|
58
|
-
baseUrl: string;
|
|
59
|
-
credential: {
|
|
60
|
-
accessToken: string;
|
|
61
|
-
refreshToken: string;
|
|
62
|
-
expiresIn: number;
|
|
63
|
-
} & {
|
|
64
|
-
issuedAt: number;
|
|
65
|
-
};
|
|
66
|
-
} | {
|
|
67
|
-
status: "scoped";
|
|
68
|
-
baseUrl: string;
|
|
69
|
-
credential: {
|
|
70
|
-
accessToken: string;
|
|
71
|
-
refreshToken: string;
|
|
72
|
-
expiresIn: number;
|
|
73
|
-
} & {
|
|
74
|
-
issuedAt: number;
|
|
75
|
-
};
|
|
76
|
-
projectId: number;
|
|
77
|
-
};
|
|
78
|
-
authReady: boolean;
|
|
79
|
-
managementReady: boolean;
|
|
80
|
-
storage: _keboola_api_client.AsyncState<unknown>["state"];
|
|
81
|
-
}) => void) => () => void;
|
|
82
|
-
debug: () => {
|
|
83
|
-
type: "Bearer";
|
|
84
|
-
config: {
|
|
85
|
-
status: "anonymous";
|
|
86
|
-
baseUrl: string | null;
|
|
87
|
-
} | {
|
|
88
|
-
status: "authenticated";
|
|
89
|
-
baseUrl: string;
|
|
90
|
-
credential: {
|
|
91
|
-
accessToken: string;
|
|
92
|
-
refreshToken: string;
|
|
93
|
-
expiresIn: number;
|
|
94
|
-
} & {
|
|
95
|
-
issuedAt: number;
|
|
96
|
-
};
|
|
97
|
-
} | {
|
|
98
|
-
status: "scoped";
|
|
99
|
-
baseUrl: string;
|
|
100
|
-
credential: {
|
|
101
|
-
accessToken: string;
|
|
102
|
-
refreshToken: string;
|
|
103
|
-
expiresIn: number;
|
|
104
|
-
} & {
|
|
105
|
-
issuedAt: number;
|
|
106
|
-
};
|
|
107
|
-
projectId: number;
|
|
108
|
-
};
|
|
109
|
-
authReady: boolean;
|
|
110
|
-
managementReady: boolean;
|
|
111
|
-
storage: _keboola_api_client.AsyncState<unknown>["state"];
|
|
101
|
+
} & {
|
|
102
|
+
issuedAt: number;
|
|
103
|
+
};
|
|
104
|
+
projectId: number;
|
|
112
105
|
};
|
|
106
|
+
authReady: boolean;
|
|
107
|
+
managementReady: boolean;
|
|
108
|
+
storage: import("@keboola/api-client").AsyncState<unknown>['state'];
|
|
109
|
+
};
|
|
113
110
|
};
|
|
114
111
|
/** The legacy (SAPI) lifecycle session. Throws outside `<LegacyAuthProvider />`. */
|
|
115
112
|
declare const useLegacyAuth: () => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
};
|
|
139
|
-
authReady: boolean;
|
|
140
|
-
managementReady: boolean;
|
|
141
|
-
storage: _keboola_api_client.AsyncState<unknown>["state"];
|
|
113
|
+
setBaseUrl: (baseUrl: string) => void;
|
|
114
|
+
isStorageReady: () => boolean;
|
|
115
|
+
authenticateStorage: (sapiToken: string) => void;
|
|
116
|
+
authenticateStorageAsync: (sapiToken: string) => Promise<void>;
|
|
117
|
+
authenticateManagement: (managementToken: string) => void;
|
|
118
|
+
subscribe: (listener: (snapshot: {
|
|
119
|
+
type: 'Sapi';
|
|
120
|
+
config: {
|
|
121
|
+
baseUrl: string | null;
|
|
122
|
+
sapiToken: string | null;
|
|
123
|
+
managementToken: string | null;
|
|
124
|
+
};
|
|
125
|
+
authReady: boolean;
|
|
126
|
+
managementReady: boolean;
|
|
127
|
+
storage: import("@keboola/api-client").AsyncState<unknown>['state'];
|
|
128
|
+
}) => void) => () => void;
|
|
129
|
+
debug: () => {
|
|
130
|
+
type: 'Sapi';
|
|
131
|
+
config: {
|
|
132
|
+
baseUrl: string | null;
|
|
133
|
+
sapiToken: string | null;
|
|
134
|
+
managementToken: string | null;
|
|
142
135
|
};
|
|
136
|
+
authReady: boolean;
|
|
137
|
+
managementReady: boolean;
|
|
138
|
+
storage: import("@keboola/api-client").AsyncState<unknown>['state'];
|
|
139
|
+
};
|
|
143
140
|
};
|
|
144
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/ApiClientProvider.d.ts
|
|
145
143
|
type Props$2 = {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
144
|
+
/** The flow-agnostic product API — the `api` half of a keboola client. */
|
|
145
|
+
api: KeboolaApi;
|
|
146
|
+
children: ReactNode;
|
|
149
147
|
};
|
|
150
148
|
/**
|
|
151
149
|
* Provides the product API to `useApiClient()`. A pure pass-through: the auth lifecycle (driving
|
|
152
150
|
* to ready, gating on a fallback) belongs to `AuthProvider` / `LegacyAuthProvider`, which mount
|
|
153
151
|
* this provider once their session is ready.
|
|
154
152
|
*/
|
|
155
|
-
declare const ApiClientProvider: ({ api, children }: Props$2) =>
|
|
156
|
-
|
|
153
|
+
declare const ApiClientProvider: ({ api, children }: Props$2) => import("react/jsx-runtime").JSX.Element;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/AuthProvider.d.ts
|
|
157
156
|
type BearerCredential = Parameters<BearerSession['authenticate']>[0];
|
|
158
157
|
/** The session state guaranteed to exist once the storage build is ready. */
|
|
159
158
|
type ScopedState = {
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
projectId: number;
|
|
160
|
+
baseUrl: string;
|
|
162
161
|
};
|
|
163
162
|
type BaseProps = {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
163
|
+
session: BearerSession;
|
|
164
|
+
onAccessTokenChange?: (accessToken: string) => void;
|
|
165
|
+
/** Rendered while a persisted session is being restored, or the bootstrap is in flight. */
|
|
166
|
+
loadingFallback?: ReactNode;
|
|
167
|
+
/** Rendered when the storage build fails. */
|
|
168
|
+
errorFallback?: ReactNode;
|
|
169
|
+
/**
|
|
170
|
+
* Rendered only once the session is scoped and the storage build is ready. Pass a function to
|
|
171
|
+
* receive the scoped state (the project the session settled on) without re-narrowing it yourself.
|
|
172
|
+
*/
|
|
173
|
+
children: ReactNode | ((scoped: ScopedState) => ReactNode);
|
|
175
174
|
};
|
|
176
175
|
/**
|
|
177
176
|
* Two mutually exclusive bootstrap modes, discriminated by whether a credential is supplied:
|
|
@@ -182,31 +181,32 @@ type BaseProps = {
|
|
|
182
181
|
* here (a missing login UI would leave the app on a permanently blank screen).
|
|
183
182
|
*/
|
|
184
183
|
type Props$1 = BaseProps & ({
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
credential: BearerCredential;
|
|
185
|
+
projectId: number;
|
|
186
|
+
baseUrl: string;
|
|
187
|
+
anonymousFallback?: never;
|
|
189
188
|
} | {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
credential?: undefined;
|
|
190
|
+
projectId?: undefined;
|
|
191
|
+
baseUrl?: never;
|
|
192
|
+
anonymousFallback: ReactNode;
|
|
194
193
|
});
|
|
195
|
-
declare const AuthProvider: ({ session, baseUrl, credential, projectId, onAccessTokenChange, loadingFallback, errorFallback, anonymousFallback, children
|
|
196
|
-
|
|
194
|
+
declare const AuthProvider: ({ session, baseUrl, credential, projectId, onAccessTokenChange, loadingFallback, errorFallback, anonymousFallback, children }: Props$1) => import("react/jsx-runtime").JSX.Element;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/LegacyAuthProvider.d.ts
|
|
197
197
|
type Props = {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
session: LegacySession;
|
|
199
|
+
/** Stack base URL. */
|
|
200
|
+
baseUrl: string;
|
|
201
|
+
/** SAPI token — drives the storage build to ready. */
|
|
202
|
+
storageToken: string;
|
|
203
|
+
/** Optional manage-api token — unlocks `api.management`. */
|
|
204
|
+
managementToken?: string;
|
|
205
|
+
/** Rendered until the storage build reaches ready. */
|
|
206
|
+
fallback?: ReactNode;
|
|
207
|
+
/** Rendered when the storage build fails — e.g. the SAPI token is expired or revoked. */
|
|
208
|
+
errorFallback?: ReactNode;
|
|
209
|
+
children: ReactNode;
|
|
210
210
|
};
|
|
211
211
|
/**
|
|
212
212
|
* Owns the legacy (SAPI) lifecycle: on mount it configures the stack and drives the session to
|
|
@@ -214,6 +214,7 @@ type Props = {
|
|
|
214
214
|
* known up front, so this drives itself (unlike the interactive bearer `AuthProvider`). Exposes the
|
|
215
215
|
* session via `useLegacyAuth()` and gates `children` behind readiness.
|
|
216
216
|
*/
|
|
217
|
-
declare const LegacyAuthProvider: ({ session, baseUrl, storageToken, managementToken, fallback, errorFallback, children
|
|
218
|
-
|
|
217
|
+
declare const LegacyAuthProvider: ({ session, baseUrl, storageToken, managementToken, fallback, errorFallback, children }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
218
|
+
//#endregion
|
|
219
219
|
export { ApiClientProvider, AuthProvider, LegacyAuthProvider, useApiClient, useAuth, useLegacyAuth, useProject, useStack };
|
|
220
|
+
//# sourceMappingURL=index.d.cts.map
|