@opensecret/react 0.3.4 → 0.4.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/README.md CHANGED
@@ -12,14 +12,19 @@ npm install @opensecret/react
12
12
 
13
13
  ## Usage
14
14
 
15
- Wrap your application in the `OpenSecretProvider` component and provide the URL of your OpenSecret backend:
15
+ Wrap your application in the `OpenSecretProvider` component and provide:
16
+ 1. The URL of your OpenSecret backend
17
+ 2. Your project's client ID (a UUID that identifies your project)
16
18
 
17
19
  ```tsx
18
20
  import { OpenSecretProvider } from "@opensecret/react";
19
21
 
20
22
  function App() {
21
23
  return (
22
- <OpenSecretProvider apiUrl="{URL}">
24
+ <OpenSecretProvider
25
+ apiUrl="{URL}"
26
+ clientId="{PROJECT_UUID}"
27
+ >
23
28
  <App />
24
29
  </OpenSecretProvider>
25
30
  );
@@ -52,10 +57,15 @@ function App() {
52
57
 
53
58
  ### `OpenSecretProvider`
54
59
 
55
- 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.
60
+ The `OpenSecretProvider` component is the main entry point for the SDK. It requires two props:
61
+ - `apiUrl`: The URL of your OpenSecret backend
62
+ - `clientId`: A UUID that identifies your project/tenant. This is used to scope user accounts and data to your specific project.
56
63
 
57
64
  ```tsx
58
- <OpenSecretProvider apiUrl="{URL}">
65
+ <OpenSecretProvider
66
+ apiUrl="{URL}"
67
+ clientId="{PROJECT_UUID}"
68
+ >
59
69
  <App />
60
70
  </OpenSecretProvider>
61
71
  ```
@@ -67,9 +77,9 @@ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an ob
67
77
  #### Authentication Methods
68
78
  - `signIn(email: string, password: string): Promise<void>`: Signs in a user with the provided email and password.
69
79
  - `signUp(email: string, password: string, inviteCode: string, name?: string): Promise<void>`: Signs up a new user with the provided email, password, invite code, and optional name.
70
- - `signInGuest(id: string, password: string): Promise<void>`: Signs in a guest user with their ID and password.
71
- - `signUpGuest(password: string, inviteCode: string): Promise<LoginResponse>`: Creates a new guest account with just a password and invite code. Returns a response containing the guest's ID, access token, and refresh token.
72
- - `convertGuestToUserAccount(email: string, password: string, name?: string): Promise<void>`: Converts current guest account to a regular account with email authentication. Optionally sets the user's name.
80
+ - `signInGuest(id: string, password: string): Promise<void>`: Signs in a guest user with their ID and password. Guest accounts are scoped to the project specified by `clientId`.
81
+ - `signUpGuest(password: string, inviteCode: string): Promise<LoginResponse>`: Creates a new guest account with just a password and invite code. Returns a response containing the guest's ID, access token, and refresh token. The guest account will be associated with the project specified by `clientId`.
82
+ - `convertGuestToUserAccount(email: string, password: string, name?: string): Promise<void>`: Converts current guest account to a regular account with email authentication. Optionally sets the user's name. The account remains associated with the same project it was created under.
73
83
  - `signOut(): Promise<void>`: Signs out the current user.
74
84
 
75
85
  #### Key-Value Storage Methods
@@ -173,6 +183,12 @@ To build the library, run the following command:
173
183
  bun run build
174
184
  ```
175
185
 
186
+ To test the library, run the following command:
187
+
188
+ ```bash
189
+ bun test --env-file .env.local
190
+ ```
191
+
176
192
  Currently this build step requires `npx` because of [a Bun incompatibility with `vite-plugin-dts`](https://github.com/OpenSecretCloud/OpenSecret-SDK/issues/16).
177
193
 
178
194
  To pack the library (for publishing) run the following command:
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { z } from 'zod';
5
5
  declare namespace api {
6
6
  export {
7
7
  setApiUrl,
8
+ getApiUrl,
8
9
  fetchLogin,
9
10
  fetchGuestLogin,
10
11
  fetchSignUp,
@@ -93,9 +94,9 @@ declare const AWS_ROOT_CERT_DER: Uint8Array;
93
94
 
94
95
  declare function changePassword(currentPassword: string, newPassword: string): Promise<void>;
95
96
 
96
- declare function confirmPasswordReset(email: string, alphanumericCode: string, plaintextSecret: string, newPassword: string): Promise<void>;
97
+ declare function confirmPasswordReset(email: string, alphanumericCode: string, plaintextSecret: string, newPassword: string, client_id: string): Promise<void>;
97
98
 
98
- declare function convertGuestToEmailAccount(email: string, password: string, name?: string): Promise<void>;
99
+ declare function convertGuestToEmailAccount(email: string, password: string, name?: string | null): Promise<void>;
99
100
 
100
101
  declare const EXPECTED_ROOT_CERT_HASH = "641a0321a3e244efe456463195d606317ed7cdcc3c1756e09893f3c68f79bb5b";
101
102
 
@@ -105,13 +106,13 @@ declare function fetchDelete(key: string): Promise<void>;
105
106
 
106
107
  declare function fetchGet(key: string): Promise<string | undefined>;
107
108
 
108
- declare function fetchGuestLogin(id: string, password: string): Promise<LoginResponse>;
109
+ declare function fetchGuestLogin(id: string, password: string, client_id: string): Promise<LoginResponse>;
109
110
 
110
- declare function fetchGuestSignUp(password: string, inviteCode: string): Promise<LoginResponse>;
111
+ declare function fetchGuestSignUp(password: string, inviteCode: string, client_id: string): Promise<LoginResponse>;
111
112
 
112
113
  declare function fetchList(): Promise<KVListItem[]>;
113
114
 
114
- declare function fetchLogin(email: string, password: string): Promise<LoginResponse>;
115
+ declare function fetchLogin(email: string, password: string, client_id: string): Promise<LoginResponse>;
115
116
 
116
117
  declare function fetchLogout(refresh_token: string): Promise<void>;
117
118
 
@@ -150,7 +151,7 @@ declare function fetchPublicKey(algorithm: SigningAlgorithm, derivationPath?: st
150
151
 
151
152
  declare function fetchPut(key: string, value: string): Promise<string>;
152
153
 
153
- declare function fetchSignUp(email: string, password: string, inviteCode: string, name?: string | null): Promise<LoginResponse>;
154
+ declare function fetchSignUp(email: string, password: string, inviteCode: string, client_id: string, name?: string | null): Promise<LoginResponse>;
154
155
 
155
156
  declare function fetchUser(): Promise<UserResponse>;
156
157
 
@@ -158,6 +159,8 @@ export declare function generateSecureSecret(): string;
158
159
 
159
160
  declare function generateThirdPartyToken(audience: string): Promise<ThirdPartyTokenResponse>;
160
161
 
162
+ declare function getApiUrl(): string;
163
+
161
164
  declare function getAttestation(forceRefresh?: boolean, apiUrl?: string): Promise<Attestation>;
162
165
 
163
166
  export declare type GithubAuthResponse = {
@@ -176,9 +179,9 @@ declare function handleGoogleCallback(code: string, state: string, inviteCode: s
176
179
 
177
180
  export declare function hashSecret(secret: string): Promise<string>;
178
181
 
179
- declare function initiateGitHubAuth(inviteCode?: string): Promise<GithubAuthResponse>;
182
+ declare function initiateGitHubAuth(client_id: string, inviteCode?: string): Promise<GithubAuthResponse>;
180
183
 
181
- declare function initiateGoogleAuth(inviteCode?: string): Promise<GoogleAuthResponse>;
184
+ declare function initiateGoogleAuth(client_id: string, inviteCode?: string): Promise<GoogleAuthResponse>;
182
185
 
183
186
  declare function keyExchange(clientPublicKey: string, nonce: string): Promise<{
184
187
  encrypted_session_key: string;
@@ -208,6 +211,11 @@ export declare const OpenSecretContext: default_2.Context<OpenSecretContextType>
208
211
 
209
212
  export declare type OpenSecretContextType = {
210
213
  auth: OpenSecretAuthState;
214
+ /**
215
+ * The client ID for this project/tenant
216
+ * @description A UUID that identifies which project/tenant this instance belongs to
217
+ */
218
+ clientId: string;
211
219
  /**
212
220
  * Authenticates a user with email and password
213
221
  * @param email - User's email address
@@ -216,7 +224,7 @@ export declare type OpenSecretContextType = {
216
224
  * @throws {Error} If login fails
217
225
  *
218
226
  * @description
219
- * - Calls the login API endpoint
227
+ * - Calls the login API endpoint with the configured clientId
220
228
  * - Stores access_token and refresh_token in localStorage
221
229
  * - Updates the auth state with user information
222
230
  * - Throws an error if authentication fails
@@ -283,7 +291,7 @@ export declare type OpenSecretContextType = {
283
291
  * - Updates the auth state with new user information
284
292
  * - Preserves all existing data associated with the guest account
285
293
  */
286
- convertGuestToUserAccount: (email: string, password: string, name?: string) => Promise<void>;
294
+ convertGuestToUserAccount: (email: string, password: string, name?: string | null) => Promise<void>;
287
295
  /**
288
296
  * Logs out the current user
289
297
  * @returns A promise that resolves when logout is complete
@@ -355,8 +363,8 @@ export declare type OpenSecretContextType = {
355
363
  refetchUser: () => Promise<void>;
356
364
  changePassword: typeof api.changePassword;
357
365
  refreshAccessToken: typeof api.refreshToken;
358
- requestPasswordReset: typeof api.requestPasswordReset;
359
- confirmPasswordReset: typeof api.confirmPasswordReset;
366
+ requestPasswordReset: (email: string, hashedSecret: string) => Promise<void>;
367
+ confirmPasswordReset: (email: string, alphanumericCode: string, plaintextSecret: string, newPassword: string) => Promise<void>;
360
368
  initiateGitHubAuth: (inviteCode: string) => Promise<api.GithubAuthResponse>;
361
369
  handleGitHubCallback: (code: string, state: string, inviteCode: string) => Promise<void>;
362
370
  initiateGoogleAuth: (inviteCode: string) => Promise<api.GoogleAuthResponse>;
@@ -488,23 +496,30 @@ export declare type OpenSecretContextType = {
488
496
  * @param props - Configuration properties for the OpenSecret provider
489
497
  * @param props.children - React child components to be wrapped by the provider
490
498
  * @param props.apiUrl - URL of OpenSecret enclave backend
499
+ * @param props.clientId - UUID identifying which project/tenant this instance belongs to
500
+ * @param props.pcrConfig - Optional PCR configuration for attestation validation
491
501
  *
492
502
  * @remarks
493
503
  * This provider manages:
494
504
  * - User authentication state
495
505
  * - Authentication methods (sign in, sign up, sign out)
496
506
  * - Key-value storage operations
507
+ * - Project/tenant identification via clientId
497
508
  *
498
509
  * @example
499
510
  * ```tsx
500
- * <OpenSecretProvider apiUrl='https://preview.opensecret.ai'>
511
+ * <OpenSecretProvider
512
+ * apiUrl='https://preview.opensecret.ai'
513
+ * clientId='550e8400-e29b-41d4-a716-446655440000'
514
+ * >
501
515
  * <App />
502
516
  * </OpenSecretProvider>
503
517
  * ```
504
518
  */
505
- export declare function OpenSecretProvider({ children, apiUrl, pcrConfig }: {
519
+ export declare function OpenSecretProvider({ children, apiUrl, clientId, pcrConfig }: {
506
520
  children: default_2.ReactNode;
507
521
  apiUrl: string;
522
+ clientId: string;
508
523
  pcrConfig?: PcrConfig;
509
524
  }): JSX_2.Element;
510
525
 
@@ -566,7 +581,7 @@ declare function refreshToken(): Promise<RefreshResponse>;
566
581
 
567
582
  declare function requestNewVerificationCode(): Promise<void>;
568
583
 
569
- declare function requestPasswordReset(email: string, hashedSecret: string): Promise<void>;
584
+ declare function requestPasswordReset(email: string, hashedSecret: string, client_id: string): Promise<void>;
570
585
 
571
586
  declare function setApiUrl(url: string): void;
572
587