@basictech/react 0.7.0 → 0.8.0-beta.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/.turbo/turbo-build.log +13 -12
- package/AUTH_IMPLEMENTATION_GUIDE.md +20 -18
- package/changelog.md +24 -2
- package/dist/index.d.mts +121 -48
- package/dist/index.d.ts +121 -48
- package/dist/index.js +1996 -758
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1981 -749
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/readme.md +50 -1
- package/src/AuthContext.tsx +294 -818
- package/src/config.ts +1 -19
- package/src/context.tsx +104 -0
- package/src/core/auth/AuthManager.ts +858 -0
- package/src/core/db/RemoteCollection.ts +30 -16
- package/src/core/db/index.ts +1 -1
- package/src/core/db/types.ts +13 -1
- package/src/dev/BasicDevToolbar.tsx +665 -0
- package/src/index.ts +10 -3
- package/src/sync/index.ts +15 -29
- package/src/sync/syncProtocol.js +84 -22
- package/src/sync/tokenRegistry.ts +20 -0
- package/src/updater/updateMigrations.ts +3 -3
- package/src/updater/versionUpdater.ts +3 -10
- package/src/utils/network.ts +68 -15
- package/src/utils/normalizeClientId.ts +22 -0
- package/src/utils/resolveDid.ts +101 -0
- package/src/utils/schema.ts +3 -4
- package/src/utils/storage.ts +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
2
|
+
import react from 'react';
|
|
3
3
|
export { useLiveQuery as useQuery } from 'dexie-react-hooks';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -92,6 +92,10 @@ interface AuthError {
|
|
|
92
92
|
status: number;
|
|
93
93
|
message: string;
|
|
94
94
|
response?: any;
|
|
95
|
+
/** Classifies the error for UI display (e.g. "session expired" vs "forbidden") */
|
|
96
|
+
errorType: 'expired' | 'forbidden' | 'revoked' | 'network' | 'unknown';
|
|
97
|
+
/** True if this error occurred after a retry with a refreshed token */
|
|
98
|
+
afterRetry: boolean;
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
97
101
|
* Custom error class for Remote DB API errors
|
|
@@ -102,13 +106,20 @@ declare class RemoteDBError extends Error {
|
|
|
102
106
|
response?: any;
|
|
103
107
|
constructor(message: string, status: number, response?: any);
|
|
104
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Options for getToken (e.g. force refresh after 401)
|
|
111
|
+
*/
|
|
112
|
+
interface GetTokenOptions$1 {
|
|
113
|
+
/** When true, refresh the access token before returning (e.g. after server returned 401) */
|
|
114
|
+
forceRefresh?: boolean;
|
|
115
|
+
}
|
|
105
116
|
/**
|
|
106
117
|
* Configuration for RemoteDB
|
|
107
118
|
*/
|
|
108
119
|
interface RemoteDBConfig {
|
|
109
120
|
serverUrl: string;
|
|
110
121
|
projectId: string;
|
|
111
|
-
getToken: () => Promise<string>;
|
|
122
|
+
getToken: (options?: GetTokenOptions$1) => Promise<string>;
|
|
112
123
|
schema?: any;
|
|
113
124
|
/** Enable debug logging (default: false) */
|
|
114
125
|
debug?: boolean;
|
|
@@ -233,57 +244,45 @@ declare const STORAGE_KEYS: {
|
|
|
233
244
|
readonly AUTH_STATE: "basic_auth_state";
|
|
234
245
|
readonly REDIRECT_URI: "basic_redirect_uri";
|
|
235
246
|
readonly SERVER_URL: "basic_server_url";
|
|
247
|
+
readonly PDS_ENDPOINTS: "basic_pds_endpoints";
|
|
248
|
+
readonly LAST_CONNECT_REPORT: "basic_last_connect_report";
|
|
236
249
|
readonly DEBUG: "basic_debug";
|
|
250
|
+
readonly CODE_VERIFIER: "basic_code_verifier";
|
|
237
251
|
};
|
|
238
252
|
|
|
239
|
-
type
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
type User = {
|
|
254
|
+
sub?: string;
|
|
255
|
+
name?: string;
|
|
256
|
+
email?: string;
|
|
257
|
+
picture?: string;
|
|
243
258
|
};
|
|
244
|
-
type
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/** The Basic schema object containing project_id and table definitions */
|
|
252
|
-
schema?: any;
|
|
253
|
-
debug?: boolean;
|
|
254
|
-
storage?: BasicStorage;
|
|
255
|
-
auth?: AuthConfig;
|
|
256
|
-
/**
|
|
257
|
-
* Database mode - determines which implementation is used
|
|
258
|
-
* - 'sync': Uses Dexie + WebSocket for local-first sync (default)
|
|
259
|
-
* - 'remote': Uses REST API calls directly to server
|
|
260
|
-
*/
|
|
261
|
-
dbMode?: DBMode;
|
|
259
|
+
type AuthResult = {
|
|
260
|
+
success: boolean;
|
|
261
|
+
error?: string;
|
|
262
|
+
code?: string;
|
|
263
|
+
};
|
|
264
|
+
type GetTokenOptions = {
|
|
265
|
+
forceRefresh?: boolean;
|
|
262
266
|
};
|
|
267
|
+
|
|
263
268
|
declare enum DBStatus {
|
|
264
269
|
LOADING = "LOADING",
|
|
265
270
|
OFFLINE = "OFFLINE",
|
|
266
271
|
CONNECTING = "CONNECTING",
|
|
267
272
|
ONLINE = "ONLINE",
|
|
268
273
|
SYNCING = "SYNCING",
|
|
269
|
-
ERROR = "ERROR"
|
|
274
|
+
ERROR = "ERROR",
|
|
275
|
+
ERROR_WILL_RETRY = "ERROR_WILL_RETRY",
|
|
276
|
+
ERROR_TOKEN_EXPIRED = "ERROR_TOKEN_EXPIRED"
|
|
270
277
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
fullName?: string;
|
|
279
|
-
};
|
|
280
|
-
/**
|
|
281
|
-
* Auth result type for signInWithCode
|
|
282
|
-
*/
|
|
283
|
-
type AuthResult = {
|
|
284
|
-
success: boolean;
|
|
278
|
+
/** Snapshot of local schema vs server (for dev toolbar and debugging). */
|
|
279
|
+
type BasicSchemaDevInfo = {
|
|
280
|
+
projectId: string | null;
|
|
281
|
+
localVersion: number | undefined;
|
|
282
|
+
status: string;
|
|
283
|
+
valid: boolean;
|
|
284
|
+
lastCheckedAt: number;
|
|
285
285
|
error?: string;
|
|
286
|
-
code?: string;
|
|
287
286
|
};
|
|
288
287
|
/**
|
|
289
288
|
* Context type for useBasic hook
|
|
@@ -292,26 +291,100 @@ type BasicContextType = {
|
|
|
292
291
|
isReady: boolean;
|
|
293
292
|
isSignedIn: boolean;
|
|
294
293
|
user: User | null;
|
|
294
|
+
did: string | null;
|
|
295
|
+
scope: string | null;
|
|
296
|
+
hasScope: (scope: string) => boolean;
|
|
297
|
+
missingScopes: () => string[];
|
|
295
298
|
signIn: () => Promise<void>;
|
|
299
|
+
signInWithHandle: (handle: string) => Promise<void>;
|
|
296
300
|
signOut: () => Promise<void>;
|
|
297
301
|
signInWithCode: (code: string, state?: string) => Promise<AuthResult>;
|
|
298
|
-
getToken: () => Promise<string>;
|
|
302
|
+
getToken: (options?: GetTokenOptions) => Promise<string>;
|
|
299
303
|
getSignInUrl: (redirectUri?: string) => Promise<string>;
|
|
300
304
|
db: BasicDB;
|
|
301
305
|
dbStatus: DBStatus;
|
|
302
306
|
dbMode: DBMode;
|
|
303
|
-
/**
|
|
307
|
+
/** Local schema vs server status; null if no schema on the provider. */
|
|
308
|
+
devInfo: BasicSchemaDevInfo | null;
|
|
309
|
+
/** Re-run remote schema check (dev toolbar). */
|
|
310
|
+
refreshSchemaStatus: () => Promise<void>;
|
|
304
311
|
isAuthReady: boolean;
|
|
305
|
-
/** @deprecated Use signIn instead */
|
|
306
312
|
signin: () => Promise<void>;
|
|
307
|
-
/** @deprecated Use signOut instead */
|
|
308
313
|
signout: () => Promise<void>;
|
|
309
|
-
/** @deprecated Use signInWithCode instead */
|
|
310
314
|
signinWithCode: (code: string, state?: string) => Promise<AuthResult>;
|
|
311
|
-
/** @deprecated Use getSignInUrl instead */
|
|
312
315
|
getSignInLink: (redirectUri?: string) => Promise<string>;
|
|
313
316
|
};
|
|
314
|
-
declare function BasicProvider({ children, project_id: project_id_prop, schema, debug, storage, auth, dbMode }: BasicProviderProps): react_jsx_runtime.JSX.Element;
|
|
315
317
|
declare function useBasic(): BasicContextType;
|
|
316
318
|
|
|
317
|
-
|
|
319
|
+
type AuthConfig = {
|
|
320
|
+
scopes?: string | string[];
|
|
321
|
+
/** @deprecated Use pds_url instead */
|
|
322
|
+
server_url?: string;
|
|
323
|
+
/** PDS URL for auth and data (default: https://pds.basic.id) */
|
|
324
|
+
pds_url?: string;
|
|
325
|
+
/** Admin server URL for connect reporting (default: https://api.basic.tech) */
|
|
326
|
+
admin_url?: string;
|
|
327
|
+
ws_url?: string;
|
|
328
|
+
};
|
|
329
|
+
type BasicProviderProps = {
|
|
330
|
+
children: react.ReactNode;
|
|
331
|
+
/**
|
|
332
|
+
* @deprecated Project ID is now extracted from schema.project_id.
|
|
333
|
+
* This prop is kept for backward compatibility but can be omitted.
|
|
334
|
+
*/
|
|
335
|
+
project_id?: string;
|
|
336
|
+
/** The Basic schema object containing project_id and table definitions */
|
|
337
|
+
schema?: any;
|
|
338
|
+
debug?: boolean;
|
|
339
|
+
storage?: BasicStorage;
|
|
340
|
+
auth?: AuthConfig;
|
|
341
|
+
/**
|
|
342
|
+
* Database mode - determines which implementation is used
|
|
343
|
+
* - 'sync': Uses Dexie + WebSocket for local-first sync (default)
|
|
344
|
+
* - 'remote': Uses REST API calls directly to server
|
|
345
|
+
*/
|
|
346
|
+
dbMode?: DBMode;
|
|
347
|
+
/** Show floating dev toolbar (localhost, NODE_ENV=development, or debug=true). */
|
|
348
|
+
devToolbar?: boolean;
|
|
349
|
+
};
|
|
350
|
+
declare function BasicProvider({ children, project_id: project_id_prop, schema, debug, storage, auth, dbMode, devToolbar, }: BasicProviderProps): react_jsx_runtime.JSX.Element;
|
|
351
|
+
|
|
352
|
+
type BasicDevToolbarProps = {
|
|
353
|
+
/** When false, toolbar does not render. Defaults to true when used standalone. */
|
|
354
|
+
enabled?: boolean;
|
|
355
|
+
/** Same as BasicProvider `debug` — when true, toolbar shows even off localhost. */
|
|
356
|
+
debug?: boolean;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Floating dev-only toolbar: auth, DB/sync, and schema status. Requires `BasicProvider` with `debug` or localhost / NODE_ENV=development for visibility unless `enabled` is forced.
|
|
360
|
+
*/
|
|
361
|
+
declare function BasicDevToolbar({ enabled, debug }: BasicDevToolbarProps): react_jsx_runtime.JSX.Element | null;
|
|
362
|
+
|
|
363
|
+
type ResolvedDid = {
|
|
364
|
+
did: string;
|
|
365
|
+
handle?: string;
|
|
366
|
+
didDocument: Record<string, unknown>;
|
|
367
|
+
pdsUrl: string;
|
|
368
|
+
authorization_endpoint: string;
|
|
369
|
+
token_endpoint: string;
|
|
370
|
+
userinfo_endpoint: string;
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Convert a did:web DID to the HTTPS URL where its DID document lives.
|
|
374
|
+
*
|
|
375
|
+
* did:web:pds.basic.id:did:abc123 -> https://pds.basic.id/did/abc123/did.json
|
|
376
|
+
* did:web:example.com -> https://example.com/.well-known/did.json
|
|
377
|
+
*/
|
|
378
|
+
declare function resolveDidWebUrl(did: string): string | null;
|
|
379
|
+
/**
|
|
380
|
+
* Fetch a DID document by DID, extract the PDS URL, and discover OAuth endpoints.
|
|
381
|
+
*/
|
|
382
|
+
declare function resolveDid(did: string): Promise<ResolvedDid>;
|
|
383
|
+
/**
|
|
384
|
+
* Resolve a handle (e.g. "alice.basic.id") to a DID and discover PDS + OAuth endpoints.
|
|
385
|
+
*
|
|
386
|
+
* Fetches https://{handle}/.well-known/did.json per the did:web spec.
|
|
387
|
+
*/
|
|
388
|
+
declare function resolveHandle(handle: string): Promise<ResolvedDid>;
|
|
389
|
+
|
|
390
|
+
export { type AuthConfig, type AuthError, type AuthResult, type BasicContextType, type BasicDB, BasicDevToolbar, type BasicDevToolbarProps, BasicProvider, type BasicProviderProps, type BasicSchemaDevInfo, type BasicStorage, type Collection, type DBMode, DBStatus, type GetTokenOptions$1 as GetTokenOptions, LocalStorageAdapter, NotAuthenticatedError, RemoteCollection, RemoteDB, type RemoteDBConfig, RemoteDBError, type ResolvedDid, STORAGE_KEYS, resolveDid, resolveDidWebUrl, resolveHandle, useBasic };
|