@teamkeel/client-react 0.365.2 → 0.365.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamkeel/client-react",
3
- "version": "0.365.2",
3
+ "version": "0.365.5",
4
4
  "description": "React helpers for Keel clients",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,5 +20,8 @@
20
20
  "@types/react-dom": "18.2.0",
21
21
  "react": "18.2.0",
22
22
  "typescript": "5.1.6"
23
- }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ]
24
27
  }
package/pnpm-lock.yaml DELETED
@@ -1,71 +0,0 @@
1
- lockfileVersion: '6.0'
2
-
3
- settings:
4
- autoInstallPeers: true
5
- excludeLinksFromLockfile: false
6
-
7
- devDependencies:
8
- '@types/react':
9
- specifier: 18.2.0
10
- version: 18.2.0
11
- '@types/react-dom':
12
- specifier: 18.2.0
13
- version: 18.2.0
14
- react:
15
- specifier: 18.2.0
16
- version: 18.2.0
17
- typescript:
18
- specifier: 5.1.6
19
- version: 5.1.6
20
-
21
- packages:
22
-
23
- /@types/prop-types@15.7.5:
24
- resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==}
25
- dev: true
26
-
27
- /@types/react-dom@18.2.0:
28
- resolution: {integrity: sha512-8yQrvS6sMpSwIovhPOwfyNf2Wz6v/B62LFSVYQ85+Rq3tLsBIG7rP5geMxaijTUxSkrO6RzN/IRuIAADYQsleA==}
29
- dependencies:
30
- '@types/react': 18.2.0
31
- dev: true
32
-
33
- /@types/react@18.2.0:
34
- resolution: {integrity: sha512-0FLj93y5USLHdnhIhABk83rm8XEGA7kH3cr+YUlvxoUGp1xNt/DINUMvqPxLyOQMzLmZe8i4RTHbvb8MC7NmrA==}
35
- dependencies:
36
- '@types/prop-types': 15.7.5
37
- '@types/scheduler': 0.16.3
38
- csstype: 3.1.2
39
- dev: true
40
-
41
- /@types/scheduler@0.16.3:
42
- resolution: {integrity: sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==}
43
- dev: true
44
-
45
- /csstype@3.1.2:
46
- resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==}
47
- dev: true
48
-
49
- /js-tokens@4.0.0:
50
- resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
51
- dev: true
52
-
53
- /loose-envify@1.4.0:
54
- resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
55
- hasBin: true
56
- dependencies:
57
- js-tokens: 4.0.0
58
- dev: true
59
-
60
- /react@18.2.0:
61
- resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
62
- engines: {node: '>=0.10.0'}
63
- dependencies:
64
- loose-envify: 1.4.0
65
- dev: true
66
-
67
- /typescript@5.1.6:
68
- resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==}
69
- engines: {node: '>=14.17'}
70
- hasBin: true
71
- dev: true
package/src/index.tsx DELETED
@@ -1,65 +0,0 @@
1
- import React, { createContext, useContext, useEffect, useRef } from "react";
2
-
3
- interface KeelContextType<T> {
4
- client: T;
5
- }
6
-
7
- const KeelContext = createContext<KeelContextType<any>>({
8
- client: null,
9
- });
10
-
11
- interface KeelProviderProps<
12
- T extends new (...args: any[]) => any,
13
- U = Omit<ConstructorParameters<T>[0], "endpoint">
14
- > {
15
- /**
16
- * The base URL for the client.
17
- */
18
- baseUrl: string;
19
- /**
20
- * Additional config options for the client.
21
- */
22
- config?: U;
23
- children: React.ReactNode;
24
- }
25
-
26
- export const keel = <T extends new (...args: any[]) => any>(Client: T) => {
27
- function KeelProvider<T extends new (...args: any[]) => any>({
28
- baseUrl,
29
- config,
30
- children,
31
- }: KeelProviderProps<T>) {
32
- if (typeof Client !== "function") {
33
- throw new Error("Client must be a Keel class");
34
- }
35
-
36
- const clientConstructor = Client as new (args: any) => any;
37
- const clientArgs = { baseUrl, ...config };
38
- const clientRef = useRef(new clientConstructor(clientArgs));
39
-
40
- const client = clientRef.current;
41
-
42
- useEffect(() => {
43
- client.client.setBaseUrl(baseUrl);
44
- }, [baseUrl, client]);
45
-
46
- return (
47
- <KeelContext.Provider value={{ client }}>{children}</KeelContext.Provider>
48
- );
49
- }
50
-
51
- return {
52
- KeelProvider: KeelProvider<T>,
53
- useKeel: useKeel<T>,
54
- };
55
- };
56
-
57
- function useKeel<T extends new (...args: any) => any>() {
58
- const keelContext = useContext<KeelContextType<InstanceType<T>>>(KeelContext);
59
-
60
- if (!keelContext) {
61
- throw new Error("useKeel must be used within a KeelProvider");
62
- }
63
-
64
- return keelContext.client;
65
- }
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "jsx": "react",
9
- "lib": ["ESNext", "dom"],
10
- "esModuleInterop": true,
11
- "sourceMap": true
12
- },
13
- "include": ["src"],
14
- "exclude": ["node_modules", "**/__tests__/*"]
15
- }