@keboola/api-client-react 0.1.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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/index.cjs +64 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Keboola s.r.o.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @keboola/api-client-react
|
|
2
|
+
|
|
3
|
+
React bindings for [@keboola/api-client](https://www.npmjs.com/package/@keboola/api-client) — provider + hooks for accessing the Keboola SDK in a React tree.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@keboola/api-client-react)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @keboola/api-client @keboola/api-client-react react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Peer dependencies: `react ^18.3.1 || ^19.0.0`, `@keboola/api-client`.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Wrap your tree with `ApiClientProvider`, then read the client with `useApiClient` anywhere below it. The provider initialises the SDK once on mount and renders `fallback` until init resolves.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { createApiClient } from '@keboola/api-client';
|
|
21
|
+
import { ApiClientProvider, useApiClient } from '@keboola/api-client-react';
|
|
22
|
+
|
|
23
|
+
const client = createApiClient();
|
|
24
|
+
|
|
25
|
+
export const App = () => (
|
|
26
|
+
<ApiClientProvider
|
|
27
|
+
client={client}
|
|
28
|
+
baseUrl="https://connection.keboola.com"
|
|
29
|
+
token={{ storageApi: 'your-storage-token' }}
|
|
30
|
+
assetsBaseUrl="https://assets.keboola.com"
|
|
31
|
+
statusBaseUrl="https://status.keboola.com"
|
|
32
|
+
metastoreBaseUrl="https://metastore.keboola.com"
|
|
33
|
+
onError={(error) => console.error('API Error:', error)}
|
|
34
|
+
fallback={<div>Loading…</div>}
|
|
35
|
+
>
|
|
36
|
+
<Tables />
|
|
37
|
+
</ApiClientProvider>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const Tables = () => {
|
|
41
|
+
const api = useApiClient();
|
|
42
|
+
// api.storage.tables.list(), api.queue.searchJobs(), etc.
|
|
43
|
+
return null;
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Exported hooks
|
|
48
|
+
|
|
49
|
+
- `useApiClient()` — returns the initialised `ApiClient`.
|
|
50
|
+
- `useProject()` — returns `client.project` (project features + backend availability).
|
|
51
|
+
- `useStack()` — returns `client.stack` (service discovery + feature flags).
|
|
52
|
+
- `useDevApiClient()` — companion hook for `DevApiClientProvider`, used by tooling that needs the dev/raw client.
|
|
53
|
+
|
|
54
|
+
## Ownership
|
|
55
|
+
|
|
56
|
+
Owned by the **Keboola UI team**. Source of truth is the [`keboola/ui`](https://github.com/keboola/ui) monorepo.
|
|
57
|
+
|
|
58
|
+
Versioning follows semver via [Changesets](https://github.com/changesets/changesets); the package is linked to `@keboola/api-client` so a bump on either releases both together.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// src/context.ts
|
|
7
|
+
var MISSING_API_CLIENT_ERROR = "useApiClient must be used within <ApiClientProvider />";
|
|
8
|
+
var MISSING_PROJECT_ERROR = "useProject must be used within <ApiClientProvider />";
|
|
9
|
+
var MISSING_STACK_ERROR = "useStack must be used within <ApiClientProvider />";
|
|
10
|
+
var Context = react.createContext(null);
|
|
11
|
+
var Provider = Context.Provider;
|
|
12
|
+
var useApiClient = () => {
|
|
13
|
+
const client = react.useContext(Context);
|
|
14
|
+
if (client === null) throw new Error(MISSING_API_CLIENT_ERROR);
|
|
15
|
+
return client;
|
|
16
|
+
};
|
|
17
|
+
var useProject = () => {
|
|
18
|
+
const client = react.useContext(Context);
|
|
19
|
+
if (client === null) throw new Error(MISSING_PROJECT_ERROR);
|
|
20
|
+
return client.project;
|
|
21
|
+
};
|
|
22
|
+
var useStack = () => {
|
|
23
|
+
const client = react.useContext(Context);
|
|
24
|
+
if (client === null) throw new Error(MISSING_STACK_ERROR);
|
|
25
|
+
return client.stack;
|
|
26
|
+
};
|
|
27
|
+
var ApiClientProvider = ({
|
|
28
|
+
client,
|
|
29
|
+
children,
|
|
30
|
+
fallback = null,
|
|
31
|
+
onError,
|
|
32
|
+
onSuccess,
|
|
33
|
+
onSettled,
|
|
34
|
+
...rest
|
|
35
|
+
}) => {
|
|
36
|
+
const [isInitializing, setIsInitializing] = react.useState(true);
|
|
37
|
+
react.useEffect(() => {
|
|
38
|
+
client.init({
|
|
39
|
+
...rest,
|
|
40
|
+
callbacks: { onSuccess, onError, onSettled }
|
|
41
|
+
}).finally(() => {
|
|
42
|
+
setIsInitializing(false);
|
|
43
|
+
});
|
|
44
|
+
}, []);
|
|
45
|
+
return isInitializing ? fallback : /* @__PURE__ */ jsxRuntime.jsx(Provider, { value: client, children });
|
|
46
|
+
};
|
|
47
|
+
var MISSING_DEV_PROVIDER_ERROR = "useDevApiClient must be used within <DevApiClientProvider />";
|
|
48
|
+
var Context2 = react.createContext(null);
|
|
49
|
+
var Provider2 = Context2.Provider;
|
|
50
|
+
var useDevApiClient = () => {
|
|
51
|
+
const devApiClient = react.useContext(Context2);
|
|
52
|
+
if (devApiClient === null) throw new Error(MISSING_DEV_PROVIDER_ERROR);
|
|
53
|
+
return devApiClient;
|
|
54
|
+
};
|
|
55
|
+
var DevApiClientProvider = ({ client, children }) => /* @__PURE__ */ jsxRuntime.jsx(Provider2, { value: client, children });
|
|
56
|
+
|
|
57
|
+
exports.ApiClientProvider = ApiClientProvider;
|
|
58
|
+
exports.DevApiClientProvider = DevApiClientProvider;
|
|
59
|
+
exports.useApiClient = useApiClient;
|
|
60
|
+
exports.useDevApiClient = useDevApiClient;
|
|
61
|
+
exports.useProject = useProject;
|
|
62
|
+
exports.useStack = useStack;
|
|
63
|
+
//# sourceMappingURL=index.cjs.map
|
|
64
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context.ts","../src/ApiClientProvider.tsx","../src/devContext.ts","../src/DevApiClientProvider.tsx"],"names":["createContext","useContext","useState","useEffect","jsx","Context","Provider"],"mappings":";;;;;;AAIA,IAAM,wBAAA,GAA2B,wDAAA;AACjC,IAAM,qBAAA,GAAwB,sDAAA;AAC9B,IAAM,mBAAA,GAAsB,oDAAA;AAE5B,IAAM,OAAA,GAAUA,oBAAgC,IAAI,CAAA;AAE7C,IAAM,WAAW,OAAA,CAAQ,QAAA;AAEzB,IAAM,eAAe,MAAM;AAChC,EAAA,MAAM,MAAA,GAASC,iBAAW,OAAO,CAAA;AACjC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,MAAM,wBAAwB,CAAA;AAC7D,EAAA,OAAO,MAAA;AACT;AAEO,IAAM,aAAa,MAAM;AAC9B,EAAA,MAAM,MAAA,GAASA,iBAAW,OAAO,CAAA;AACjC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAC1D,EAAA,OAAO,MAAA,CAAO,OAAA;AAChB;AAEO,IAAM,WAAW,MAAM;AAC5B,EAAA,MAAM,MAAA,GAASA,iBAAW,OAAO,CAAA;AACjC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,MAAM,mBAAmB,CAAA;AACxD,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB;ACVO,IAAM,oBAAoB,CAAC;AAAA,EAChC,MAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA,GAAW,IAAA;AAAA,EAEX,OAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,KAAa;AACX,EAAA,MAAM,CAAC,cAAA,EAAgB,iBAAiB,CAAA,GAAIC,eAAkB,IAAI,CAAA;AAElE,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,MAAA,CACG,IAAA,CAAK;AAAA,MACJ,GAAG,IAAA;AAAA,MACH,SAAA,EAAW,EAAE,SAAA,EAAW,OAAA,EAAS,SAAA;AAAU,KAC5C,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,MAAA,iBAAA,CAAkB,KAAK,CAAA;AAAA,IACzB,CAAC,CAAA;AAAA,EAGL,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO,iBAAiB,QAAA,mBAAWC,cAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAO,QAAS,QAAA,EAAS,CAAA;AACxE;ACxCA,IAAM,0BAAA,GAA6B,8DAAA;AAEnC,IAAMC,QAAAA,GAAUL,oBAA4D,IAAI,CAAA;AAEzE,IAAMM,YAAWD,QAAAA,CAAQ,QAAA;AAEzB,IAAM,kBAAkB,MAAM;AACnC,EAAA,MAAM,YAAA,GAAeJ,iBAAWI,QAAO,CAAA;AACvC,EAAA,IAAI,YAAA,KAAiB,IAAA,EAAM,MAAM,IAAI,MAAM,0BAA0B,CAAA;AACrE,EAAA,OAAO,YAAA;AACT;ACDO,IAAM,oBAAA,GAAuB,CAAC,EAAE,MAAA,EAAQ,QAAA,EAAS,qBACtDD,cAAAA,CAACE,SAAAA,EAAA,EAAS,KAAA,EAAO,MAAA,EAAS,QAAA,EAAS","file":"index.cjs","sourcesContent":["import { createContext, useContext } from 'react';\n\nimport type { ApiClient } 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 />';\n\nconst Context = createContext<ApiClient | null>(null);\n\nexport const Provider = Context.Provider;\n\nexport const useApiClient = () => {\n const client = useContext(Context);\n if (client === null) throw new Error(MISSING_API_CLIENT_ERROR);\n return client;\n};\n\nexport const useProject = () => {\n const client = useContext(Context);\n if (client === null) throw new Error(MISSING_PROJECT_ERROR);\n return client.project;\n};\n\nexport const useStack = () => {\n const client = useContext(Context);\n if (client === null) throw new Error(MISSING_STACK_ERROR);\n return client.stack;\n};\n","import { useEffect, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport type {\n ApiClient,\n ApiClientOptions,\n CreateCallbackMiddlewareOptions,\n} from '@keboola/api-client';\n\nimport { Provider } from './context';\n\ntype Props = {\n client: ApiClient;\n children: ReactNode;\n fallback?: ReactNode;\n} & Omit<ApiClientOptions, 'callbacks'> &\n CreateCallbackMiddlewareOptions;\n\nexport const ApiClientProvider = ({\n client,\n children,\n fallback = null,\n\n onError,\n onSuccess,\n onSettled,\n ...rest\n}: Props) => {\n const [isInitializing, setIsInitializing] = useState<boolean>(true);\n\n useEffect(() => {\n client\n .init({\n ...rest,\n callbacks: { onSuccess, onError, onSettled },\n })\n .finally(() => {\n setIsInitializing(false);\n });\n // we want to init only on initial mount\n // oxlint-disable-next-line react/exhaustive-deps\n }, []);\n\n return isInitializing ? fallback : <Provider value={client}>{children}</Provider>;\n};\n","import { createContext, useContext } from 'react';\n\nimport type { createDevApiClient } from '@keboola/api-client';\n\nconst MISSING_DEV_PROVIDER_ERROR = 'useDevApiClient must be used within <DevApiClientProvider />';\n\nconst Context = createContext<ReturnType<typeof createDevApiClient> | null>(null);\n\nexport const Provider = Context.Provider;\n\nexport const useDevApiClient = () => {\n const devApiClient = useContext(Context);\n if (devApiClient === null) throw new Error(MISSING_DEV_PROVIDER_ERROR);\n return devApiClient;\n};\n","import type { ReactNode } from 'react';\n\nimport type { createDevApiClient } from '@keboola/api-client';\n\nimport { Provider } from './devContext';\n\ntype DevClient = ReturnType<typeof createDevApiClient>;\n\ntype Props = {\n client: DevClient;\n children: ReactNode;\n};\n\nexport const DevApiClientProvider = ({ client, children }: Props) => (\n <Provider value={client}>{children}</Provider>\n);\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _keboola_api_client_storage_types from '@keboola/api-client/storage/types';
|
|
2
|
+
import { ApiClient, ApiClientOptions, CreateCallbackMiddlewareOptions, createDevApiClient } from '@keboola/api-client';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import * as _keboola_api_client_verify_types from '@keboola/api-client/verify/types';
|
|
6
|
+
|
|
7
|
+
declare const useApiClient: () => ApiClient;
|
|
8
|
+
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;
|
|
13
|
+
};
|
|
14
|
+
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;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type Props$1 = {
|
|
35
|
+
client: ApiClient;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
fallback?: ReactNode;
|
|
38
|
+
} & Omit<ApiClientOptions, 'callbacks'> & CreateCallbackMiddlewareOptions;
|
|
39
|
+
declare const ApiClientProvider: ({ client, children, fallback, onError, onSuccess, onSettled, ...rest }: Props$1) => string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element | null;
|
|
40
|
+
|
|
41
|
+
type DevClient = ReturnType<typeof createDevApiClient>;
|
|
42
|
+
type Props = {
|
|
43
|
+
client: DevClient;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
declare const DevApiClientProvider: ({ client, children }: Props) => react_jsx_runtime.JSX.Element;
|
|
47
|
+
|
|
48
|
+
declare const useDevApiClient: () => {
|
|
49
|
+
verify: {
|
|
50
|
+
storageApiToken: (host: string, token: string, signal?: AbortSignal) => Promise<_keboola_api_client_storage_types.StorageToken>;
|
|
51
|
+
managementApiToken: (host: string, token: string, signal?: AbortSignal) => Promise<_keboola_api_client_verify_types.ManagementToken>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { ApiClientProvider, DevApiClientProvider, useApiClient, useDevApiClient, useProject, useStack };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _keboola_api_client_storage_types from '@keboola/api-client/storage/types';
|
|
2
|
+
import { ApiClient, ApiClientOptions, CreateCallbackMiddlewareOptions, createDevApiClient } from '@keboola/api-client';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import * as _keboola_api_client_verify_types from '@keboola/api-client/verify/types';
|
|
6
|
+
|
|
7
|
+
declare const useApiClient: () => ApiClient;
|
|
8
|
+
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;
|
|
13
|
+
};
|
|
14
|
+
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;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type Props$1 = {
|
|
35
|
+
client: ApiClient;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
fallback?: ReactNode;
|
|
38
|
+
} & Omit<ApiClientOptions, 'callbacks'> & CreateCallbackMiddlewareOptions;
|
|
39
|
+
declare const ApiClientProvider: ({ client, children, fallback, onError, onSuccess, onSettled, ...rest }: Props$1) => string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element | null;
|
|
40
|
+
|
|
41
|
+
type DevClient = ReturnType<typeof createDevApiClient>;
|
|
42
|
+
type Props = {
|
|
43
|
+
client: DevClient;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
declare const DevApiClientProvider: ({ client, children }: Props) => react_jsx_runtime.JSX.Element;
|
|
47
|
+
|
|
48
|
+
declare const useDevApiClient: () => {
|
|
49
|
+
verify: {
|
|
50
|
+
storageApiToken: (host: string, token: string, signal?: AbortSignal) => Promise<_keboola_api_client_storage_types.StorageToken>;
|
|
51
|
+
managementApiToken: (host: string, token: string, signal?: AbortSignal) => Promise<_keboola_api_client_verify_types.ManagementToken>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { ApiClientProvider, DevApiClientProvider, useApiClient, useDevApiClient, useProject, useStack };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createContext, useContext, useState, useEffect } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/context.ts
|
|
5
|
+
var MISSING_API_CLIENT_ERROR = "useApiClient must be used within <ApiClientProvider />";
|
|
6
|
+
var MISSING_PROJECT_ERROR = "useProject must be used within <ApiClientProvider />";
|
|
7
|
+
var MISSING_STACK_ERROR = "useStack must be used within <ApiClientProvider />";
|
|
8
|
+
var Context = createContext(null);
|
|
9
|
+
var Provider = Context.Provider;
|
|
10
|
+
var useApiClient = () => {
|
|
11
|
+
const client = useContext(Context);
|
|
12
|
+
if (client === null) throw new Error(MISSING_API_CLIENT_ERROR);
|
|
13
|
+
return client;
|
|
14
|
+
};
|
|
15
|
+
var useProject = () => {
|
|
16
|
+
const client = useContext(Context);
|
|
17
|
+
if (client === null) throw new Error(MISSING_PROJECT_ERROR);
|
|
18
|
+
return client.project;
|
|
19
|
+
};
|
|
20
|
+
var useStack = () => {
|
|
21
|
+
const client = useContext(Context);
|
|
22
|
+
if (client === null) throw new Error(MISSING_STACK_ERROR);
|
|
23
|
+
return client.stack;
|
|
24
|
+
};
|
|
25
|
+
var ApiClientProvider = ({
|
|
26
|
+
client,
|
|
27
|
+
children,
|
|
28
|
+
fallback = null,
|
|
29
|
+
onError,
|
|
30
|
+
onSuccess,
|
|
31
|
+
onSettled,
|
|
32
|
+
...rest
|
|
33
|
+
}) => {
|
|
34
|
+
const [isInitializing, setIsInitializing] = useState(true);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
client.init({
|
|
37
|
+
...rest,
|
|
38
|
+
callbacks: { onSuccess, onError, onSettled }
|
|
39
|
+
}).finally(() => {
|
|
40
|
+
setIsInitializing(false);
|
|
41
|
+
});
|
|
42
|
+
}, []);
|
|
43
|
+
return isInitializing ? fallback : /* @__PURE__ */ jsx(Provider, { value: client, children });
|
|
44
|
+
};
|
|
45
|
+
var MISSING_DEV_PROVIDER_ERROR = "useDevApiClient must be used within <DevApiClientProvider />";
|
|
46
|
+
var Context2 = createContext(null);
|
|
47
|
+
var Provider2 = Context2.Provider;
|
|
48
|
+
var useDevApiClient = () => {
|
|
49
|
+
const devApiClient = useContext(Context2);
|
|
50
|
+
if (devApiClient === null) throw new Error(MISSING_DEV_PROVIDER_ERROR);
|
|
51
|
+
return devApiClient;
|
|
52
|
+
};
|
|
53
|
+
var DevApiClientProvider = ({ client, children }) => /* @__PURE__ */ jsx(Provider2, { value: client, children });
|
|
54
|
+
|
|
55
|
+
export { ApiClientProvider, DevApiClientProvider, useApiClient, useDevApiClient, useProject, useStack };
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context.ts","../src/ApiClientProvider.tsx","../src/devContext.ts","../src/DevApiClientProvider.tsx"],"names":["Context","createContext","Provider","useContext","jsx"],"mappings":";;;;AAIA,IAAM,wBAAA,GAA2B,wDAAA;AACjC,IAAM,qBAAA,GAAwB,sDAAA;AAC9B,IAAM,mBAAA,GAAsB,oDAAA;AAE5B,IAAM,OAAA,GAAU,cAAgC,IAAI,CAAA;AAE7C,IAAM,WAAW,OAAA,CAAQ,QAAA;AAEzB,IAAM,eAAe,MAAM;AAChC,EAAA,MAAM,MAAA,GAAS,WAAW,OAAO,CAAA;AACjC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,MAAM,wBAAwB,CAAA;AAC7D,EAAA,OAAO,MAAA;AACT;AAEO,IAAM,aAAa,MAAM;AAC9B,EAAA,MAAM,MAAA,GAAS,WAAW,OAAO,CAAA;AACjC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAC1D,EAAA,OAAO,MAAA,CAAO,OAAA;AAChB;AAEO,IAAM,WAAW,MAAM;AAC5B,EAAA,MAAM,MAAA,GAAS,WAAW,OAAO,CAAA;AACjC,EAAA,IAAI,MAAA,KAAW,IAAA,EAAM,MAAM,IAAI,MAAM,mBAAmB,CAAA;AACxD,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB;ACVO,IAAM,oBAAoB,CAAC;AAAA,EAChC,MAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA,GAAW,IAAA;AAAA,EAEX,OAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,KAAa;AACX,EAAA,MAAM,CAAC,cAAA,EAAgB,iBAAiB,CAAA,GAAI,SAAkB,IAAI,CAAA;AAElE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAA,CACG,IAAA,CAAK;AAAA,MACJ,GAAG,IAAA;AAAA,MACH,SAAA,EAAW,EAAE,SAAA,EAAW,OAAA,EAAS,SAAA;AAAU,KAC5C,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,MAAA,iBAAA,CAAkB,KAAK,CAAA;AAAA,IACzB,CAAC,CAAA;AAAA,EAGL,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO,iBAAiB,QAAA,mBAAW,GAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAO,QAAS,QAAA,EAAS,CAAA;AACxE;ACxCA,IAAM,0BAAA,GAA6B,8DAAA;AAEnC,IAAMA,QAAAA,GAAUC,cAA4D,IAAI,CAAA;AAEzE,IAAMC,YAAWF,QAAAA,CAAQ,QAAA;AAEzB,IAAM,kBAAkB,MAAM;AACnC,EAAA,MAAM,YAAA,GAAeG,WAAWH,QAAO,CAAA;AACvC,EAAA,IAAI,YAAA,KAAiB,IAAA,EAAM,MAAM,IAAI,MAAM,0BAA0B,CAAA;AACrE,EAAA,OAAO,YAAA;AACT;ACDO,IAAM,oBAAA,GAAuB,CAAC,EAAE,MAAA,EAAQ,QAAA,EAAS,qBACtDI,GAAAA,CAACF,SAAAA,EAAA,EAAS,KAAA,EAAO,MAAA,EAAS,QAAA,EAAS","file":"index.js","sourcesContent":["import { createContext, useContext } from 'react';\n\nimport type { ApiClient } 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 />';\n\nconst Context = createContext<ApiClient | null>(null);\n\nexport const Provider = Context.Provider;\n\nexport const useApiClient = () => {\n const client = useContext(Context);\n if (client === null) throw new Error(MISSING_API_CLIENT_ERROR);\n return client;\n};\n\nexport const useProject = () => {\n const client = useContext(Context);\n if (client === null) throw new Error(MISSING_PROJECT_ERROR);\n return client.project;\n};\n\nexport const useStack = () => {\n const client = useContext(Context);\n if (client === null) throw new Error(MISSING_STACK_ERROR);\n return client.stack;\n};\n","import { useEffect, useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport type {\n ApiClient,\n ApiClientOptions,\n CreateCallbackMiddlewareOptions,\n} from '@keboola/api-client';\n\nimport { Provider } from './context';\n\ntype Props = {\n client: ApiClient;\n children: ReactNode;\n fallback?: ReactNode;\n} & Omit<ApiClientOptions, 'callbacks'> &\n CreateCallbackMiddlewareOptions;\n\nexport const ApiClientProvider = ({\n client,\n children,\n fallback = null,\n\n onError,\n onSuccess,\n onSettled,\n ...rest\n}: Props) => {\n const [isInitializing, setIsInitializing] = useState<boolean>(true);\n\n useEffect(() => {\n client\n .init({\n ...rest,\n callbacks: { onSuccess, onError, onSettled },\n })\n .finally(() => {\n setIsInitializing(false);\n });\n // we want to init only on initial mount\n // oxlint-disable-next-line react/exhaustive-deps\n }, []);\n\n return isInitializing ? fallback : <Provider value={client}>{children}</Provider>;\n};\n","import { createContext, useContext } from 'react';\n\nimport type { createDevApiClient } from '@keboola/api-client';\n\nconst MISSING_DEV_PROVIDER_ERROR = 'useDevApiClient must be used within <DevApiClientProvider />';\n\nconst Context = createContext<ReturnType<typeof createDevApiClient> | null>(null);\n\nexport const Provider = Context.Provider;\n\nexport const useDevApiClient = () => {\n const devApiClient = useContext(Context);\n if (devApiClient === null) throw new Error(MISSING_DEV_PROVIDER_ERROR);\n return devApiClient;\n};\n","import type { ReactNode } from 'react';\n\nimport type { createDevApiClient } from '@keboola/api-client';\n\nimport { Provider } from './devContext';\n\ntype DevClient = ReturnType<typeof createDevApiClient>;\n\ntype Props = {\n client: DevClient;\n children: ReactNode;\n};\n\nexport const DevApiClientProvider = ({ client, children }: Props) => (\n <Provider value={client}>{children}</Provider>\n);\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@keboola/api-client-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for @keboola/api-client",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"type-check": "tsc",
|
|
20
|
+
"lint": "yarn lint:format && yarn lint:oxlint",
|
|
21
|
+
"lint:fix": "oxlint --fix . && oxfmt",
|
|
22
|
+
"knip:check": "yarn --cwd ../.. exec knip --workspace packages/api-client-react",
|
|
23
|
+
"knip:fix": "yarn --cwd ../.. exec knip --workspace packages/api-client-react --fix-type types,exports,files",
|
|
24
|
+
"lint:oxlint": "oxlint . --quiet",
|
|
25
|
+
"lint:format": "oxfmt --check",
|
|
26
|
+
"transit": "yarn build",
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"build:check": "attw --pack .",
|
|
29
|
+
"prepublishOnly": "yarn build && yarn build:check",
|
|
30
|
+
"test": "vitest run --passWithNoTests --reporter=dot"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": "24.x"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/keboola/ui.git",
|
|
38
|
+
"directory": "packages/api-client-react"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/keboola/ui/tree/main/packages/api-client-react#readme",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/keboola/ui/issues"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"keboola",
|
|
46
|
+
"api",
|
|
47
|
+
"sdk",
|
|
48
|
+
"react",
|
|
49
|
+
"hooks",
|
|
50
|
+
"data-platform"
|
|
51
|
+
],
|
|
52
|
+
"exports": {
|
|
53
|
+
".": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/index.d.ts",
|
|
56
|
+
"default": "./dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/index.d.cts",
|
|
60
|
+
"default": "./dist/index.cjs"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@keboola/api-client": "workspace:^",
|
|
66
|
+
"react": "^18.3.1 || ^19.0.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
70
|
+
"@keboola/oxlint-config": "workspace:^",
|
|
71
|
+
"@keboola/tsconfig": "workspace:^",
|
|
72
|
+
"@types/node": "24.12.0",
|
|
73
|
+
"@types/react": "^18.3.24",
|
|
74
|
+
"esbuild": "^0.28.0",
|
|
75
|
+
"oxfmt": "^0.44.0",
|
|
76
|
+
"oxlint": "^1.56.0",
|
|
77
|
+
"tsup": "^8.5.1",
|
|
78
|
+
"typescript": "^6.0.3",
|
|
79
|
+
"vite": "^8.0.8",
|
|
80
|
+
"vitest": "^4.1.2"
|
|
81
|
+
}
|
|
82
|
+
}
|