@keboola/api-client-react 27.0.0 → 32.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/dist/index.d.cts CHANGED
@@ -1,177 +1,188 @@
1
- import * as _keboola_api_client_storage_types from '@keboola/api-client/storage/types';
2
- import * as _keboola_api_client from '@keboola/api-client';
3
- import { KeboolaApi, BearerSession, LegacySession } from '@keboola/api-client';
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
- hasFeature: (...feature: string[]) => boolean;
10
- hasAdminFeature: (...feature: string[]) => boolean;
11
- hasBackend: (backend: _keboola_api_client_storage_types.Backend) => boolean;
12
- sapiToken: _keboola_api_client_storage_types.StorageToken;
6
+ hasFeature: (...feature: string[]) => boolean;
7
+ hasAdminFeature: (...feature: string[]) => boolean;
8
+ hasBackend: (backend: import("@keboola/api-client/constants").Backend) => boolean;
9
+ sapiToken: import("@keboola/api-client/storage/types").StorageToken;
13
10
  };
14
11
  declare const useStack: () => {
15
- services: _keboola_api_client_storage_types.Service[];
16
- features: string[];
17
- components: _keboola_api_client_storage_types.StackComponent[];
18
- hasFeature: (...feature: string[]) => boolean;
19
- getServiceUrl: (serviceId: _keboola_api_client_storage_types.ServiceId) => string | null;
20
- hasService: (serviceId: _keboola_api_client_storage_types.ServiceId) => boolean;
21
- getComponent: (componentId: string) => _keboola_api_client_storage_types.StackComponent | null;
22
- hasComponent: (...componentId: string[]) => boolean;
23
- api: string;
24
- documentation: string;
25
- host: string;
26
- revision: string;
27
- stack: string;
28
- urlTemplates: {
29
- orchestrationJob: string;
30
- };
31
- version: string;
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/constants").ServiceId) => string | null;
26
+ hasService: (serviceId: import("@keboola/api-client/constants").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
- hasPersistedValue: () => boolean;
36
- setBaseUrl: (baseUrl: string) => void;
37
- isStorageReady: () => boolean;
38
- authenticate: (tokens: {
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
+ getAuthHeaders: () => Promise<Record<string, string>>;
46
+ restore: () => Promise<{
47
+ status: 'empty' | 'restored' | 'expired';
48
+ }>;
49
+ subscribe: (listener: (snapshot: {
50
+ type: 'Bearer';
51
+ config: {
52
+ status: 'anonymous';
53
+ baseUrl: string | null;
54
+ } | {
55
+ status: 'authenticated';
56
+ baseUrl: string;
57
+ credential: {
58
+ accessToken: string;
59
+ refreshToken: string;
60
+ expiresIn: number;
61
+ } & {
62
+ issuedAt: number;
63
+ };
64
+ } | {
65
+ status: 'scoped';
66
+ baseUrl: string;
67
+ credential: {
68
+ accessToken: string;
69
+ refreshToken: string;
70
+ expiresIn: number;
71
+ } & {
72
+ issuedAt: number;
73
+ };
74
+ projectId: number;
75
+ };
76
+ authReady: boolean;
77
+ managementReady: boolean;
78
+ storage: import("@keboola/api-client").AsyncState<unknown>['state'];
79
+ }) => void) => () => void;
80
+ debug: () => {
81
+ type: 'Bearer';
82
+ config: {
83
+ status: 'anonymous';
84
+ baseUrl: string | null;
85
+ } | {
86
+ status: 'authenticated';
87
+ baseUrl: string;
88
+ credential: {
89
+ accessToken: string;
90
+ refreshToken: string;
91
+ expiresIn: number;
92
+ } & {
93
+ issuedAt: number;
94
+ };
95
+ } | {
96
+ status: 'scoped';
97
+ baseUrl: string;
98
+ credential: {
39
99
  accessToken: string;
40
100
  refreshToken: string;
41
101
  expiresIn: number;
42
- }) => void;
43
- setProject: (projectId: number) => void;
44
- setProjectAsync: (projectId: number) => Promise<void>;
45
- clearProject: () => void;
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"];
102
+ } & {
103
+ issuedAt: number;
104
+ };
105
+ projectId: number;
112
106
  };
107
+ authReady: boolean;
108
+ managementReady: boolean;
109
+ storage: import("@keboola/api-client").AsyncState<unknown>['state'];
110
+ };
113
111
  };
114
112
  /** The legacy (SAPI) lifecycle session. Throws outside `<LegacyAuthProvider />`. */
115
113
  declare const useLegacyAuth: () => {
116
- setBaseUrl: (baseUrl: string) => void;
117
- isStorageReady: () => boolean;
118
- authenticateStorage: (sapiToken: string) => void;
119
- authenticateStorageAsync: (sapiToken: string) => Promise<void>;
120
- authenticateManagement: (managementToken: string) => void;
121
- subscribe: (listener: (snapshot: {
122
- type: "Sapi";
123
- config: {
124
- baseUrl: string | null;
125
- sapiToken: string | null;
126
- managementToken: string | null;
127
- };
128
- authReady: boolean;
129
- managementReady: boolean;
130
- storage: _keboola_api_client.AsyncState<unknown>["state"];
131
- }) => void) => () => void;
132
- debug: () => {
133
- type: "Sapi";
134
- config: {
135
- baseUrl: string | null;
136
- sapiToken: string | null;
137
- managementToken: string | null;
138
- };
139
- authReady: boolean;
140
- managementReady: boolean;
141
- storage: _keboola_api_client.AsyncState<unknown>["state"];
114
+ setBaseUrl: (baseUrl: string) => void;
115
+ isStorageReady: () => boolean;
116
+ authenticateStorage: (sapiToken: string) => void;
117
+ authenticateStorageAsync: (sapiToken: string) => Promise<void>;
118
+ authenticateManagement: (managementToken: string) => void;
119
+ subscribe: (listener: (snapshot: {
120
+ type: 'Sapi';
121
+ config: {
122
+ baseUrl: string | null;
123
+ sapiToken: string | null;
124
+ managementToken: string | null;
125
+ };
126
+ authReady: boolean;
127
+ managementReady: boolean;
128
+ storage: import("@keboola/api-client").AsyncState<unknown>['state'];
129
+ }) => void) => () => void;
130
+ debug: () => {
131
+ type: 'Sapi';
132
+ config: {
133
+ baseUrl: string | null;
134
+ sapiToken: string | null;
135
+ managementToken: string | null;
142
136
  };
137
+ authReady: boolean;
138
+ managementReady: boolean;
139
+ storage: import("@keboola/api-client").AsyncState<unknown>['state'];
140
+ };
143
141
  };
144
-
142
+ //#endregion
143
+ //#region src/ApiClientProvider.d.ts
145
144
  type Props$2 = {
146
- /** The flow-agnostic product API — the `api` half of a keboola client. */
147
- api: KeboolaApi;
148
- children: ReactNode;
145
+ /** The flow-agnostic product API — the `api` half of a keboola client. */
146
+ api: KeboolaApi;
147
+ children: ReactNode;
149
148
  };
150
149
  /**
151
150
  * Provides the product API to `useApiClient()`. A pure pass-through: the auth lifecycle (driving
152
151
  * to ready, gating on a fallback) belongs to `AuthProvider` / `LegacyAuthProvider`, which mount
153
152
  * this provider once their session is ready.
154
153
  */
155
- declare const ApiClientProvider: ({ api, children }: Props$2) => react_jsx_runtime.JSX.Element;
156
-
154
+ declare const ApiClientProvider: ({ api, children }: Props$2) => import("react/jsx-runtime").JSX.Element;
155
+ //#endregion
156
+ //#region src/AuthProvider.d.ts
157
157
  type BearerCredential = Parameters<BearerSession['authenticate']>[0];
158
+ type RestoreResult = Awaited<ReturnType<BearerSession['restore']>>;
158
159
  /** The session state guaranteed to exist once the storage build is ready. */
159
160
  type ScopedState = {
160
- projectId: number;
161
- baseUrl: string;
161
+ projectId: number;
162
+ baseUrl: string;
162
163
  };
163
164
  type BaseProps = {
164
- session: BearerSession;
165
- onAccessTokenChange?: (accessToken: string) => void;
166
- /** Rendered while a persisted session is being restored, or the bootstrap is in flight. */
167
- loadingFallback?: ReactNode;
168
- /** Rendered when the storage build fails. */
169
- errorFallback?: ReactNode;
170
- /**
171
- * Rendered only once the session is scoped and the storage build is ready. Pass a function to
172
- * receive the scoped state (the project the session settled on) without re-narrowing it yourself.
173
- */
174
- children: ReactNode | ((scoped: ScopedState) => ReactNode);
165
+ session: BearerSession;
166
+ onAccessTokenChange?: (accessToken: string) => void;
167
+ /**
168
+ * Fires once with the outcome of the boot `restore()`.
169
+ *
170
+ * - `empty`, `restored` and `expired` are three different things to say to a user, and the slot
171
+ * that renders cannot tell them apart: `expired` and `empty` both land in `anonymousFallback`,
172
+ * and so does a `restored` session that carried no project.
173
+ * - A `restore()` that throws (offline, a 5xx) reports `empty` — the same value the provider acts
174
+ * on — so a caller never reads a transport failure as an expiry.
175
+ */
176
+ onRestore?: (result: RestoreResult) => void;
177
+ /** Rendered while a persisted session is being restored, or the bootstrap is in flight. */
178
+ loadingFallback?: ReactNode;
179
+ /** Rendered when the storage build fails. */
180
+ errorFallback?: ReactNode;
181
+ /**
182
+ * Rendered only once the session is scoped and the storage build is ready. Pass a function to
183
+ * receive the scoped state (the project the session settled on) without re-narrowing it yourself.
184
+ */
185
+ children: ReactNode | ((scoped: ScopedState) => ReactNode);
175
186
  };
176
187
  /**
177
188
  * Two mutually exclusive bootstrap modes, discriminated by whether a credential is supplied:
@@ -182,31 +193,32 @@ type BaseProps = {
182
193
  * here (a missing login UI would leave the app on a permanently blank screen).
183
194
  */
184
195
  type Props$1 = BaseProps & ({
185
- credential: BearerCredential;
186
- projectId: number;
187
- baseUrl: string;
188
- anonymousFallback?: never;
196
+ credential: BearerCredential;
197
+ projectId: number;
198
+ baseUrl: string;
199
+ anonymousFallback?: never;
189
200
  } | {
190
- credential?: undefined;
191
- projectId?: undefined;
192
- baseUrl?: never;
193
- anonymousFallback: ReactNode;
201
+ credential?: undefined;
202
+ projectId?: undefined;
203
+ baseUrl?: never;
204
+ anonymousFallback: ReactNode;
194
205
  });
195
- declare const AuthProvider: ({ session, baseUrl, credential, projectId, onAccessTokenChange, loadingFallback, errorFallback, anonymousFallback, children, }: Props$1) => react_jsx_runtime.JSX.Element;
196
-
206
+ declare const AuthProvider: ({ session, baseUrl, credential, projectId, onAccessTokenChange, onRestore, loadingFallback, errorFallback, anonymousFallback, children }: Props$1) => import("react/jsx-runtime").JSX.Element;
207
+ //#endregion
208
+ //#region src/LegacyAuthProvider.d.ts
197
209
  type Props = {
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
+ session: LegacySession;
211
+ /** Stack base URL. */
212
+ baseUrl: string;
213
+ /** SAPI token — drives the storage build to ready. */
214
+ storageToken: string;
215
+ /** Optional manage-api token — unlocks `api.management`. */
216
+ managementToken?: string;
217
+ /** Rendered until the storage build reaches ready. */
218
+ fallback?: ReactNode;
219
+ /** Rendered when the storage build fails — e.g. the SAPI token is expired or revoked. */
220
+ errorFallback?: ReactNode;
221
+ children: ReactNode;
210
222
  };
211
223
  /**
212
224
  * Owns the legacy (SAPI) lifecycle: on mount it configures the stack and drives the session to
@@ -214,6 +226,7 @@ type Props = {
214
226
  * known up front, so this drives itself (unlike the interactive bearer `AuthProvider`). Exposes the
215
227
  * session via `useLegacyAuth()` and gates `children` behind readiness.
216
228
  */
217
- declare const LegacyAuthProvider: ({ session, baseUrl, storageToken, managementToken, fallback, errorFallback, children, }: Props) => react_jsx_runtime.JSX.Element;
218
-
229
+ declare const LegacyAuthProvider: ({ session, baseUrl, storageToken, managementToken, fallback, errorFallback, children }: Props) => import("react/jsx-runtime").JSX.Element;
230
+ //#endregion
219
231
  export { ApiClientProvider, AuthProvider, LegacyAuthProvider, useApiClient, useAuth, useLegacyAuth, useProject, useStack };
232
+ //# sourceMappingURL=index.d.cts.map