@opensecret/react 0.1.2

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 ADDED
@@ -0,0 +1,100 @@
1
+ # OpenSecret React SDK
2
+
3
+ This is a React SDK for the [OpenSecret](https://opensecret.cloud) platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @opensecret/react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Wrap your application in the `OpenSecretProvider` component and provide the URL of your OpenSecret backend:
14
+
15
+ ```tsx
16
+ import { OpenSecretProvider } from "@opensecret/react";
17
+
18
+ function App() {
19
+ return (
20
+ <OpenSecretProvider apiUrl="https://preview.opensecret.ai">
21
+ <App />
22
+ </OpenSecretProvider>
23
+ );
24
+ }
25
+ ```
26
+
27
+ Now import the `useOpenSecret` hook and use it to access the OpenSecret API:
28
+
29
+ ```tsx
30
+ import { useOpenSecret } from "@opensecret/react";
31
+
32
+ function App() {
33
+ const os = useOpenSecret();
34
+
35
+ return (
36
+ <div>
37
+ <button onClick={() => os.signIn("email", "password")}>Sign In</button>
38
+ <button onClick={() => os.signUp("name", "email", "password", "inviteCode")}>Sign Up</button>
39
+ <button onClick={() => os.signOut()}>Sign Out</button>
40
+ <button onClick={() => os.get("key")}>Get Value</button>
41
+ <button onClick={() => os.put("key", "value")}>Put Value</button>
42
+ <button onClick={() => os.list()}>List Values</button>
43
+ <button onClick={() => os.del("key")}>Delete Value</button>
44
+ </div>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ## API Reference
50
+
51
+ ### `OpenSecretProvider`
52
+
53
+ The `OpenSecretProvider` component is the main entry point for the SDK. It requires a single prop, `apiUrl`, which should be set to the URL of your OpenSecret backend.
54
+
55
+ ```tsx
56
+ <OpenSecretProvider apiUrl="https://preview.opensecret.ai">
57
+ <App />
58
+ </OpenSecretProvider>
59
+ ```
60
+
61
+ ### `useOpenSecret`
62
+
63
+ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an object with the following methods:
64
+
65
+ - `signIn(email: string, password: string): Promise<void>`: Signs in a user with the provided email and password.
66
+ - `signUp(name: string, email: string, password: string, inviteCode: string): Promise<void>`: Signs up a new user with the provided name, email, password, and invite code.
67
+ - `signOut(): Promise<void>`: Signs out the current user.
68
+ - `get(key: string): Promise<string | undefined>`: Retrieves the value associated with the provided key.
69
+ - `put(key: string, value: string): Promise<string>`: Stores the provided value with the provided key.
70
+ - `list(): Promise<KVListItem[]>`: Retrieves all key-value pairs stored by the user.
71
+ - `del(key: string): Promise<void>`: Deletes the value associated with the provided key.
72
+ - `refetchUser(): Promise<void>`: Refreshes the user's authentication state.
73
+ - `changePassword(currentPassword: string, newPassword: string): Promise<void>`: Changes the user's password.
74
+
75
+ ### Library development
76
+
77
+ This library uses [Bun](https://bun.sh/) for development.
78
+
79
+ To run the demo app, run the following commands:
80
+
81
+ ```bash
82
+ bun install
83
+ bun run dev
84
+ ```
85
+
86
+ To build the library, run the following command:
87
+
88
+ ```bash
89
+ bun run build
90
+ ```
91
+
92
+ To pack the library, run the following command:
93
+
94
+ ```bash
95
+ bun run pack
96
+ ```
97
+
98
+ ## License
99
+
100
+ This project is licensed under the MIT License.