@opensecret/react 0.3.5 → 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 +17 -7
- package/dist/index.d.ts +27 -15
- package/dist/opensecret-react.es.js +2207 -2187
- package/dist/opensecret-react.umd.js +30 -30
- package/package.json +4 -2
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
|
|
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
|
|
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
|
|
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
|
|
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
|
package/dist/index.d.ts
CHANGED
|
@@ -94,9 +94,9 @@ declare const AWS_ROOT_CERT_DER: Uint8Array;
|
|
|
94
94
|
|
|
95
95
|
declare function changePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
96
96
|
|
|
97
|
-
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>;
|
|
98
98
|
|
|
99
|
-
declare function convertGuestToEmailAccount(email: string, password: string, name?: string): Promise<void>;
|
|
99
|
+
declare function convertGuestToEmailAccount(email: string, password: string, name?: string | null): Promise<void>;
|
|
100
100
|
|
|
101
101
|
declare const EXPECTED_ROOT_CERT_HASH = "641a0321a3e244efe456463195d606317ed7cdcc3c1756e09893f3c68f79bb5b";
|
|
102
102
|
|
|
@@ -106,13 +106,13 @@ declare function fetchDelete(key: string): Promise<void>;
|
|
|
106
106
|
|
|
107
107
|
declare function fetchGet(key: string): Promise<string | undefined>;
|
|
108
108
|
|
|
109
|
-
declare function fetchGuestLogin(id: string, password: string): Promise<LoginResponse>;
|
|
109
|
+
declare function fetchGuestLogin(id: string, password: string, client_id: string): Promise<LoginResponse>;
|
|
110
110
|
|
|
111
|
-
declare function fetchGuestSignUp(password: string, inviteCode: string): Promise<LoginResponse>;
|
|
111
|
+
declare function fetchGuestSignUp(password: string, inviteCode: string, client_id: string): Promise<LoginResponse>;
|
|
112
112
|
|
|
113
113
|
declare function fetchList(): Promise<KVListItem[]>;
|
|
114
114
|
|
|
115
|
-
declare function fetchLogin(email: string, password: string): Promise<LoginResponse>;
|
|
115
|
+
declare function fetchLogin(email: string, password: string, client_id: string): Promise<LoginResponse>;
|
|
116
116
|
|
|
117
117
|
declare function fetchLogout(refresh_token: string): Promise<void>;
|
|
118
118
|
|
|
@@ -151,7 +151,7 @@ declare function fetchPublicKey(algorithm: SigningAlgorithm, derivationPath?: st
|
|
|
151
151
|
|
|
152
152
|
declare function fetchPut(key: string, value: string): Promise<string>;
|
|
153
153
|
|
|
154
|
-
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>;
|
|
155
155
|
|
|
156
156
|
declare function fetchUser(): Promise<UserResponse>;
|
|
157
157
|
|
|
@@ -179,9 +179,9 @@ declare function handleGoogleCallback(code: string, state: string, inviteCode: s
|
|
|
179
179
|
|
|
180
180
|
export declare function hashSecret(secret: string): Promise<string>;
|
|
181
181
|
|
|
182
|
-
declare function initiateGitHubAuth(inviteCode?: string): Promise<GithubAuthResponse>;
|
|
182
|
+
declare function initiateGitHubAuth(client_id: string, inviteCode?: string): Promise<GithubAuthResponse>;
|
|
183
183
|
|
|
184
|
-
declare function initiateGoogleAuth(inviteCode?: string): Promise<GoogleAuthResponse>;
|
|
184
|
+
declare function initiateGoogleAuth(client_id: string, inviteCode?: string): Promise<GoogleAuthResponse>;
|
|
185
185
|
|
|
186
186
|
declare function keyExchange(clientPublicKey: string, nonce: string): Promise<{
|
|
187
187
|
encrypted_session_key: string;
|
|
@@ -211,6 +211,11 @@ export declare const OpenSecretContext: default_2.Context<OpenSecretContextType>
|
|
|
211
211
|
|
|
212
212
|
export declare type OpenSecretContextType = {
|
|
213
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;
|
|
214
219
|
/**
|
|
215
220
|
* Authenticates a user with email and password
|
|
216
221
|
* @param email - User's email address
|
|
@@ -219,7 +224,7 @@ export declare type OpenSecretContextType = {
|
|
|
219
224
|
* @throws {Error} If login fails
|
|
220
225
|
*
|
|
221
226
|
* @description
|
|
222
|
-
* - Calls the login API endpoint
|
|
227
|
+
* - Calls the login API endpoint with the configured clientId
|
|
223
228
|
* - Stores access_token and refresh_token in localStorage
|
|
224
229
|
* - Updates the auth state with user information
|
|
225
230
|
* - Throws an error if authentication fails
|
|
@@ -286,7 +291,7 @@ export declare type OpenSecretContextType = {
|
|
|
286
291
|
* - Updates the auth state with new user information
|
|
287
292
|
* - Preserves all existing data associated with the guest account
|
|
288
293
|
*/
|
|
289
|
-
convertGuestToUserAccount: (email: string, password: string, name?: string) => Promise<void>;
|
|
294
|
+
convertGuestToUserAccount: (email: string, password: string, name?: string | null) => Promise<void>;
|
|
290
295
|
/**
|
|
291
296
|
* Logs out the current user
|
|
292
297
|
* @returns A promise that resolves when logout is complete
|
|
@@ -358,8 +363,8 @@ export declare type OpenSecretContextType = {
|
|
|
358
363
|
refetchUser: () => Promise<void>;
|
|
359
364
|
changePassword: typeof api.changePassword;
|
|
360
365
|
refreshAccessToken: typeof api.refreshToken;
|
|
361
|
-
requestPasswordReset:
|
|
362
|
-
confirmPasswordReset:
|
|
366
|
+
requestPasswordReset: (email: string, hashedSecret: string) => Promise<void>;
|
|
367
|
+
confirmPasswordReset: (email: string, alphanumericCode: string, plaintextSecret: string, newPassword: string) => Promise<void>;
|
|
363
368
|
initiateGitHubAuth: (inviteCode: string) => Promise<api.GithubAuthResponse>;
|
|
364
369
|
handleGitHubCallback: (code: string, state: string, inviteCode: string) => Promise<void>;
|
|
365
370
|
initiateGoogleAuth: (inviteCode: string) => Promise<api.GoogleAuthResponse>;
|
|
@@ -491,23 +496,30 @@ export declare type OpenSecretContextType = {
|
|
|
491
496
|
* @param props - Configuration properties for the OpenSecret provider
|
|
492
497
|
* @param props.children - React child components to be wrapped by the provider
|
|
493
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
|
|
494
501
|
*
|
|
495
502
|
* @remarks
|
|
496
503
|
* This provider manages:
|
|
497
504
|
* - User authentication state
|
|
498
505
|
* - Authentication methods (sign in, sign up, sign out)
|
|
499
506
|
* - Key-value storage operations
|
|
507
|
+
* - Project/tenant identification via clientId
|
|
500
508
|
*
|
|
501
509
|
* @example
|
|
502
510
|
* ```tsx
|
|
503
|
-
* <OpenSecretProvider
|
|
511
|
+
* <OpenSecretProvider
|
|
512
|
+
* apiUrl='https://preview.opensecret.ai'
|
|
513
|
+
* clientId='550e8400-e29b-41d4-a716-446655440000'
|
|
514
|
+
* >
|
|
504
515
|
* <App />
|
|
505
516
|
* </OpenSecretProvider>
|
|
506
517
|
* ```
|
|
507
518
|
*/
|
|
508
|
-
export declare function OpenSecretProvider({ children, apiUrl, pcrConfig }: {
|
|
519
|
+
export declare function OpenSecretProvider({ children, apiUrl, clientId, pcrConfig }: {
|
|
509
520
|
children: default_2.ReactNode;
|
|
510
521
|
apiUrl: string;
|
|
522
|
+
clientId: string;
|
|
511
523
|
pcrConfig?: PcrConfig;
|
|
512
524
|
}): JSX_2.Element;
|
|
513
525
|
|
|
@@ -569,7 +581,7 @@ declare function refreshToken(): Promise<RefreshResponse>;
|
|
|
569
581
|
|
|
570
582
|
declare function requestNewVerificationCode(): Promise<void>;
|
|
571
583
|
|
|
572
|
-
declare function requestPasswordReset(email: string, hashedSecret: string): Promise<void>;
|
|
584
|
+
declare function requestPasswordReset(email: string, hashedSecret: string, client_id: string): Promise<void>;
|
|
573
585
|
|
|
574
586
|
declare function setApiUrl(url: string): void;
|
|
575
587
|
|