@picobase_app/client 0.2.0 → 0.5.1
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 +40 -7
- package/dist/index.d.mts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +68 -981
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -982
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ TypeScript SDK for PicoBase — add auth, database, realtime, and file storage t
|
|
|
8
8
|
npm install @picobase_app/client
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
> ⚠️ **Important:**
|
|
11
|
+
> ⚠️ **Important:** Always install `@picobase_app/client`. If you accidentally installed `pocketbase`, remove it — that's an internal dependency, not the user-facing SDK.
|
|
12
12
|
|
|
13
13
|
## Quickstart
|
|
14
14
|
|
|
@@ -178,11 +178,11 @@ const results = await pb.rpc('search_products', {
|
|
|
178
178
|
})
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
RPC calls are mapped to custom
|
|
181
|
+
RPC calls are mapped to custom endpoints at `/api/rpc/{functionName}`. You can implement these routes in your PicoBase instance.
|
|
182
182
|
|
|
183
183
|
## File Storage
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
PicoBase stores files as fields on records. Use the storage module to get URLs.
|
|
186
186
|
|
|
187
187
|
```typescript
|
|
188
188
|
const user = await pb.collection('users').getOne('USER_ID')
|
|
@@ -198,6 +198,39 @@ const token = await pb.storage.getFileToken()
|
|
|
198
198
|
const protectedUrl = pb.storage.getFileUrl(user, 'document.pdf', { token })
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
+
## Admin API (Collection Management)
|
|
202
|
+
|
|
203
|
+
The SDK provides an admin module that allows you to programmatically manage your PicoBase collections. **This requires an admin API key** to be used during client initialization.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// Initializing with an admin API key
|
|
207
|
+
const adminPb = createClient('https://myapp.picobase.com', 'pbk_admin_xxxxxxxx')
|
|
208
|
+
|
|
209
|
+
// Create a new collection
|
|
210
|
+
const usersCollection = await adminPb.admin.createCollection({
|
|
211
|
+
name: "custom_users",
|
|
212
|
+
type: "base",
|
|
213
|
+
schema: [
|
|
214
|
+
{ name: "full_name", type: "text", required: true },
|
|
215
|
+
{ name: "age", type: "number" }
|
|
216
|
+
]
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
// List all collections
|
|
220
|
+
const collections = await adminPb.admin.listCollections()
|
|
221
|
+
|
|
222
|
+
// Get a single collection
|
|
223
|
+
const collection = await adminPb.admin.getCollection('custom_users')
|
|
224
|
+
|
|
225
|
+
// Update an existing collection
|
|
226
|
+
const updated = await adminPb.admin.updateCollection('custom_users', {
|
|
227
|
+
name: "users_updated"
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
// Delete a collection
|
|
231
|
+
const success = await adminPb.admin.deleteCollection('users_updated')
|
|
232
|
+
```
|
|
233
|
+
|
|
201
234
|
## Advanced
|
|
202
235
|
|
|
203
236
|
### Custom auth collection
|
|
@@ -208,12 +241,12 @@ pb.auth.setCollection('members')
|
|
|
208
241
|
await pb.auth.signIn({ email: 'member@example.com', password: 'pass' })
|
|
209
242
|
```
|
|
210
243
|
|
|
211
|
-
### Raw
|
|
244
|
+
### Raw access (advanced)
|
|
212
245
|
|
|
213
|
-
The underlying
|
|
246
|
+
The underlying client instance is exposed for advanced use cases.
|
|
214
247
|
|
|
215
248
|
```typescript
|
|
216
|
-
// Access the
|
|
249
|
+
// Access the internal client directly
|
|
217
250
|
const health = await pb.pb.health.check()
|
|
218
251
|
|
|
219
252
|
// Custom API endpoint
|
|
@@ -299,4 +332,4 @@ result.items[0].title // string — fully typed!
|
|
|
299
332
|
| `pb.collection(name)` | `PicoBaseCollection` | CRUD operations on a collection |
|
|
300
333
|
| `pb.realtime` | `PicoBaseRealtime` | Realtime subscriptions |
|
|
301
334
|
| `pb.storage` | `PicoBaseStorage` | File URLs and tokens |
|
|
302
|
-
| `pb.pb` | `PocketBase` | Underlying
|
|
335
|
+
| `pb.pb` | `PocketBase` | Underlying internal client instance |
|
package/dist/index.d.mts
CHANGED
|
@@ -57,6 +57,33 @@ interface FileOptions {
|
|
|
57
57
|
token?: string;
|
|
58
58
|
download?: boolean;
|
|
59
59
|
}
|
|
60
|
+
type CollectionType = 'base' | 'auth' | 'view';
|
|
61
|
+
interface CollectionModel {
|
|
62
|
+
id: string;
|
|
63
|
+
created: string;
|
|
64
|
+
updated: string;
|
|
65
|
+
name: string;
|
|
66
|
+
type: CollectionType;
|
|
67
|
+
system: boolean;
|
|
68
|
+
schema: SchemaField[];
|
|
69
|
+
indexes: string[];
|
|
70
|
+
listRule: string | null;
|
|
71
|
+
viewRule: string | null;
|
|
72
|
+
createRule: string | null;
|
|
73
|
+
updateRule: string | null;
|
|
74
|
+
deleteRule: string | null;
|
|
75
|
+
options: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface SchemaField {
|
|
78
|
+
system: boolean;
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
required: boolean;
|
|
83
|
+
presentable: boolean;
|
|
84
|
+
unique: boolean;
|
|
85
|
+
options: Record<string, unknown>;
|
|
86
|
+
}
|
|
60
87
|
|
|
61
88
|
/**
|
|
62
89
|
* Auth module — handles user sign-up, sign-in, OAuth, and session management.
|
|
@@ -384,6 +411,31 @@ declare class PicoBaseStorage {
|
|
|
384
411
|
getFileToken(): Promise<string>;
|
|
385
412
|
}
|
|
386
413
|
|
|
414
|
+
declare class PicoBaseAdmin {
|
|
415
|
+
private pb;
|
|
416
|
+
constructor(pb: PocketBase);
|
|
417
|
+
/**
|
|
418
|
+
* Fetch a list of all collections.
|
|
419
|
+
*/
|
|
420
|
+
listCollections(): Promise<CollectionModel[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Fetch a single collection by ID or name.
|
|
423
|
+
*/
|
|
424
|
+
getCollection(idOrName: string): Promise<CollectionModel>;
|
|
425
|
+
/**
|
|
426
|
+
* Create a new collection.
|
|
427
|
+
*/
|
|
428
|
+
createCollection(data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
429
|
+
/**
|
|
430
|
+
* Update an existing collection.
|
|
431
|
+
*/
|
|
432
|
+
updateCollection(idOrName: string, data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
433
|
+
/**
|
|
434
|
+
* Delete a collection.
|
|
435
|
+
*/
|
|
436
|
+
deleteCollection(idOrName: string): Promise<boolean>;
|
|
437
|
+
}
|
|
438
|
+
|
|
387
439
|
declare class PicoBaseClient {
|
|
388
440
|
/** The underlying PocketBase SDK instance. Exposed for advanced usage. */
|
|
389
441
|
readonly pb: PocketBase;
|
|
@@ -393,6 +445,8 @@ declare class PicoBaseClient {
|
|
|
393
445
|
readonly realtime: PicoBaseRealtime;
|
|
394
446
|
/** Storage module — get file URLs and tokens. */
|
|
395
447
|
readonly storage: PicoBaseStorage;
|
|
448
|
+
/** Admin module — manage collections (requires admin API key). */
|
|
449
|
+
readonly admin: PicoBaseAdmin;
|
|
396
450
|
private readonly apiKey;
|
|
397
451
|
private readonly options;
|
|
398
452
|
constructor(url: string, apiKey: string, options?: PicoBaseClientOptions);
|
|
@@ -548,4 +602,4 @@ declare class RpcError extends PicoBaseError {
|
|
|
548
602
|
constructor(functionName: string, status: number, details?: unknown);
|
|
549
603
|
}
|
|
550
604
|
|
|
551
|
-
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
|
605
|
+
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAdmin, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,33 @@ interface FileOptions {
|
|
|
57
57
|
token?: string;
|
|
58
58
|
download?: boolean;
|
|
59
59
|
}
|
|
60
|
+
type CollectionType = 'base' | 'auth' | 'view';
|
|
61
|
+
interface CollectionModel {
|
|
62
|
+
id: string;
|
|
63
|
+
created: string;
|
|
64
|
+
updated: string;
|
|
65
|
+
name: string;
|
|
66
|
+
type: CollectionType;
|
|
67
|
+
system: boolean;
|
|
68
|
+
schema: SchemaField[];
|
|
69
|
+
indexes: string[];
|
|
70
|
+
listRule: string | null;
|
|
71
|
+
viewRule: string | null;
|
|
72
|
+
createRule: string | null;
|
|
73
|
+
updateRule: string | null;
|
|
74
|
+
deleteRule: string | null;
|
|
75
|
+
options: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface SchemaField {
|
|
78
|
+
system: boolean;
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
required: boolean;
|
|
83
|
+
presentable: boolean;
|
|
84
|
+
unique: boolean;
|
|
85
|
+
options: Record<string, unknown>;
|
|
86
|
+
}
|
|
60
87
|
|
|
61
88
|
/**
|
|
62
89
|
* Auth module — handles user sign-up, sign-in, OAuth, and session management.
|
|
@@ -384,6 +411,31 @@ declare class PicoBaseStorage {
|
|
|
384
411
|
getFileToken(): Promise<string>;
|
|
385
412
|
}
|
|
386
413
|
|
|
414
|
+
declare class PicoBaseAdmin {
|
|
415
|
+
private pb;
|
|
416
|
+
constructor(pb: PocketBase);
|
|
417
|
+
/**
|
|
418
|
+
* Fetch a list of all collections.
|
|
419
|
+
*/
|
|
420
|
+
listCollections(): Promise<CollectionModel[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Fetch a single collection by ID or name.
|
|
423
|
+
*/
|
|
424
|
+
getCollection(idOrName: string): Promise<CollectionModel>;
|
|
425
|
+
/**
|
|
426
|
+
* Create a new collection.
|
|
427
|
+
*/
|
|
428
|
+
createCollection(data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
429
|
+
/**
|
|
430
|
+
* Update an existing collection.
|
|
431
|
+
*/
|
|
432
|
+
updateCollection(idOrName: string, data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
433
|
+
/**
|
|
434
|
+
* Delete a collection.
|
|
435
|
+
*/
|
|
436
|
+
deleteCollection(idOrName: string): Promise<boolean>;
|
|
437
|
+
}
|
|
438
|
+
|
|
387
439
|
declare class PicoBaseClient {
|
|
388
440
|
/** The underlying PocketBase SDK instance. Exposed for advanced usage. */
|
|
389
441
|
readonly pb: PocketBase;
|
|
@@ -393,6 +445,8 @@ declare class PicoBaseClient {
|
|
|
393
445
|
readonly realtime: PicoBaseRealtime;
|
|
394
446
|
/** Storage module — get file URLs and tokens. */
|
|
395
447
|
readonly storage: PicoBaseStorage;
|
|
448
|
+
/** Admin module — manage collections (requires admin API key). */
|
|
449
|
+
readonly admin: PicoBaseAdmin;
|
|
396
450
|
private readonly apiKey;
|
|
397
451
|
private readonly options;
|
|
398
452
|
constructor(url: string, apiKey: string, options?: PicoBaseClientOptions);
|
|
@@ -548,4 +602,4 @@ declare class RpcError extends PicoBaseError {
|
|
|
548
602
|
constructor(functionName: string, status: number, details?: unknown);
|
|
549
603
|
}
|
|
550
604
|
|
|
551
|
-
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
|
605
|
+
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAdmin, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|