@gpt-platform/admin 0.1.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 +416 -0
- package/dist/index.d.mts +98747 -0
- package/dist/index.d.ts +98747 -0
- package/dist/index.js +2086 -0
- package/dist/index.mjs +2032 -0
- package/llms.txt +1214 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
# @gpt-platform/admin
|
|
2
|
+
|
|
3
|
+
The official TypeScript Admin SDK for the GPT Core Platform - platform administration, webhook management, and system monitoring.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@gpt-platform/admin)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
⚠️ **This SDK requires admin privileges and should only be used in secure server environments.**
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<!-- AI_CONTEXT_START
|
|
14
|
+
This SDK provides TypeScript bindings for GPT Core ADMIN operations.
|
|
15
|
+
Use this for: webhooks, storage admin, account credits, bulk operations, API key management.
|
|
16
|
+
NOT for: user-facing operations (use @gpt-platform/client instead).
|
|
17
|
+
SECURITY: Server-side only. Never expose admin tokens in client code.
|
|
18
|
+
|
|
19
|
+
Quick patterns:
|
|
20
|
+
- Initialize: new GptAdmin({ baseUrl, token, applicationId? })
|
|
21
|
+
- Webhooks: admin.webhooks.configs.list() / .create(name, url, events, appId)
|
|
22
|
+
- Storage: admin.storage.stats() / .buckets.list()
|
|
23
|
+
- Accounts: admin.accounts.credit(id, amount, description)
|
|
24
|
+
- Documents: admin.documents.bulkDelete(ids[])
|
|
25
|
+
- API Keys: admin.apiKeys.allocate(id, amount) / .revoke(id) / .rotate(id)
|
|
26
|
+
|
|
27
|
+
All methods return typed responses. Uses class-based API with namespaced methods.
|
|
28
|
+
AI_CONTEXT_END -->
|
|
29
|
+
|
|
30
|
+
## For AI Coding Assistants
|
|
31
|
+
|
|
32
|
+
> **TL;DR for Claude, Cursor, Copilot, and other AI assistants:**
|
|
33
|
+
>
|
|
34
|
+
> ```typescript
|
|
35
|
+
> import { GptAdmin } from "@gpt-platform/admin";
|
|
36
|
+
> const admin = new GptAdmin({
|
|
37
|
+
> baseUrl: "https://api.example.com",
|
|
38
|
+
> token: "admin-jwt",
|
|
39
|
+
> });
|
|
40
|
+
> ```
|
|
41
|
+
>
|
|
42
|
+
> **Common operations:**
|
|
43
|
+
> | Task | Code |
|
|
44
|
+
> |------|------|
|
|
45
|
+
> | Storage stats | `await admin.storage.stats()` |
|
|
46
|
+
> | List webhooks | `await admin.webhooks.configs.list()` |
|
|
47
|
+
> | Create webhook | `await admin.webhooks.configs.create(name, url, events, appId)` |
|
|
48
|
+
> | Credit account | `await admin.accounts.credit(id, amount, 'reason')` |
|
|
49
|
+
> | Bulk delete docs | `await admin.documents.bulkDelete(ids)` |
|
|
50
|
+
> | Rotate API key | `await admin.apiKeys.rotate(keyId)` |
|
|
51
|
+
>
|
|
52
|
+
> **See [llms.txt](llms.txt) for complete AI-readable SDK reference.**
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
✅ **Fully Typed** - Complete TypeScript support with auto-generated types from OpenAPI specs
|
|
59
|
+
✅ **Runtime Validation** - Zod schemas for request validation
|
|
60
|
+
✅ **Bulk Operations** - Efficient batch processing for documents and webhooks
|
|
61
|
+
✅ **Webhook Management** - Configure, monitor, and test webhook configurations
|
|
62
|
+
✅ **Storage Administration** - Monitor storage usage across workspaces and buckets
|
|
63
|
+
✅ **Account Operations** - Credit/debit account balances with audit trails
|
|
64
|
+
✅ **Document Management** - Bulk delete and reprocess documents
|
|
65
|
+
✅ **API Key Management** - Allocate, revoke, and rotate API keys
|
|
66
|
+
✅ **Error Handling** - Comprehensive error handling with detailed context
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm install @gpt-platform/admin
|
|
72
|
+
# or
|
|
73
|
+
yarn add @gpt-platform/admin
|
|
74
|
+
# or
|
|
75
|
+
pnpm add @gpt-platform/admin
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { GptAdmin } from "@gpt-platform/admin";
|
|
82
|
+
|
|
83
|
+
// Initialize admin client
|
|
84
|
+
const admin = new GptAdmin({
|
|
85
|
+
baseUrl: "https://api.gpt-platform.com",
|
|
86
|
+
token: process.env.ADMIN_JWT_TOKEN, // Admin JWT token
|
|
87
|
+
applicationId: process.env.APPLICATION_ID, // Your application ID
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Get storage statistics
|
|
91
|
+
const stats = await admin.storage.stats();
|
|
92
|
+
console.log(`Total storage: ${(stats.total_size / 1024 / 1024).toFixed(2)} MB`);
|
|
93
|
+
console.log(`Total files: ${stats.file_count}`);
|
|
94
|
+
|
|
95
|
+
// List webhook configurations
|
|
96
|
+
const webhooks = await admin.webhooks.configs.list();
|
|
97
|
+
console.log(
|
|
98
|
+
`Active webhooks: ${webhooks.filter((w) => w.attributes.enabled).length}`,
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const admin = new GptAdmin({
|
|
106
|
+
// Required: API base URL
|
|
107
|
+
baseUrl: "https://api.gpt-platform.com",
|
|
108
|
+
|
|
109
|
+
// Required: Admin JWT token
|
|
110
|
+
token: "admin-jwt-token",
|
|
111
|
+
|
|
112
|
+
// Required: Application ID
|
|
113
|
+
applicationId: "your-app-id",
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Environment Variables (Recommended)
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# .env or .env.local
|
|
121
|
+
ADMIN_API_URL=https://api.gpt-platform.com
|
|
122
|
+
ADMIN_JWT_TOKEN=your-admin-jwt-token
|
|
123
|
+
APPLICATION_ID=your-application-id
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// lib/admin-client.ts
|
|
128
|
+
import { GptAdmin } from "@gpt-platform/admin";
|
|
129
|
+
|
|
130
|
+
export const admin = new GptAdmin({
|
|
131
|
+
baseUrl: process.env.ADMIN_API_URL!,
|
|
132
|
+
token: process.env.ADMIN_JWT_TOKEN!,
|
|
133
|
+
applicationId: process.env.APPLICATION_ID!,
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API Versioning
|
|
138
|
+
|
|
139
|
+
The SDK uses Stripe-style API versioning. A default API version is sent with every request via the `Accept` header.
|
|
140
|
+
|
|
141
|
+
### Default Behavior
|
|
142
|
+
|
|
143
|
+
Every request automatically includes the SDK's built-in API version:
|
|
144
|
+
|
|
145
|
+
```http
|
|
146
|
+
Accept: application/vnd.api+json; version=2025-12-03
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
No configuration is needed -- the SDK sends `DEFAULT_API_VERSION` from `base-client.ts` automatically.
|
|
150
|
+
|
|
151
|
+
### Pinning a Version (Recommended for Production)
|
|
152
|
+
|
|
153
|
+
Pin a specific API version to protect your integration from breaking changes:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const admin = new GptAdmin({
|
|
157
|
+
baseUrl: "https://api.gpt-platform.com",
|
|
158
|
+
token: process.env.ADMIN_JWT_TOKEN,
|
|
159
|
+
applicationId: process.env.APPLICATION_ID,
|
|
160
|
+
apiVersion: "2025-12-03", // Pin to this version
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Reading the Active Version
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// The version the SDK is configured to send
|
|
168
|
+
console.log(admin.apiVersion);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Response Header
|
|
172
|
+
|
|
173
|
+
Every API response includes the version that was used to process the request:
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
x-api-version: 2025-12-03
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Discovering Available Versions
|
|
180
|
+
|
|
181
|
+
List all supported API versions and their changelogs:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
GET /api-versions
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
This returns the full list of versions with descriptions and deprecation status.
|
|
188
|
+
|
|
189
|
+
## API Reference
|
|
190
|
+
|
|
191
|
+
### Webhooks
|
|
192
|
+
|
|
193
|
+
#### List Webhook Configs
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const configs = await admin.webhooks.configs.list();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### Create Webhook
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
const webhook = await admin.webhooks.configs.create(
|
|
203
|
+
"My Webhook", // name
|
|
204
|
+
"https://your-server.com/webhook", // url
|
|
205
|
+
["document.analyzed", "thread.message.created"], // events
|
|
206
|
+
"app-123", // application_id
|
|
207
|
+
"your-webhook-secret", // secret (optional)
|
|
208
|
+
true, // enabled
|
|
209
|
+
);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### Update Webhook Config
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
const config = await admin.webhooks.configs.update("webhook-id", {
|
|
216
|
+
enabled: false,
|
|
217
|
+
events: ["document.analyzed"],
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Delete Webhook Config
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
await admin.webhooks.configs.delete("webhook-id");
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### Test Webhook Config
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const result = await admin.webhooks.configs.test("webhook-id");
|
|
231
|
+
console.log("Test delivery ID:", result.delivery_id);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Webhook Deliveries
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// List deliveries
|
|
238
|
+
const deliveries = await admin.webhooks.deliveries.list();
|
|
239
|
+
|
|
240
|
+
// Get delivery details
|
|
241
|
+
const delivery = await admin.webhooks.deliveries.get("delivery-id");
|
|
242
|
+
|
|
243
|
+
// Retry failed delivery
|
|
244
|
+
await admin.webhooks.deliveries.retry("delivery-id");
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Storage Administration
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
// Get overall storage stats
|
|
251
|
+
const stats = await admin.storage.stats();
|
|
252
|
+
console.log(stats.total_size, stats.file_count);
|
|
253
|
+
|
|
254
|
+
// Get stats for specific workspace
|
|
255
|
+
const workspaceStats = await admin.storage.stats("workspace-id");
|
|
256
|
+
|
|
257
|
+
// List all buckets
|
|
258
|
+
const buckets = await admin.storage.buckets.list();
|
|
259
|
+
|
|
260
|
+
// Get bucket details
|
|
261
|
+
const bucket = await admin.storage.buckets.get("bucket-id");
|
|
262
|
+
|
|
263
|
+
// Get bucket stats
|
|
264
|
+
const bucketStats = await admin.storage.buckets.stats("bucket-id");
|
|
265
|
+
|
|
266
|
+
// List bucket objects
|
|
267
|
+
const objects = await admin.storage.buckets.objects("bucket-id");
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Account Management
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
// List all accounts
|
|
274
|
+
const accounts = await admin.accounts.list();
|
|
275
|
+
|
|
276
|
+
// Get account details
|
|
277
|
+
const account = await admin.accounts.get("account-id");
|
|
278
|
+
|
|
279
|
+
// Credit an account
|
|
280
|
+
await admin.accounts.credit("account-id", 1000, "Bonus credits");
|
|
281
|
+
|
|
282
|
+
// Debit an account
|
|
283
|
+
await admin.accounts.debit("account-id", 500, "Usage charge");
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Document Administration
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
// List documents
|
|
290
|
+
const documents = await admin.documents.list();
|
|
291
|
+
|
|
292
|
+
// Get document details
|
|
293
|
+
const document = await admin.documents.get("doc-id");
|
|
294
|
+
|
|
295
|
+
// Bulk delete documents
|
|
296
|
+
await admin.documents.bulkDelete(["doc-id-1", "doc-id-2"]);
|
|
297
|
+
|
|
298
|
+
// Bulk reprocess documents
|
|
299
|
+
await admin.documents.bulkReprocess(["doc-id-1", "doc-id-2"]);
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### API Key Management
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
// List API keys
|
|
306
|
+
const keys = await admin.apiKeys.list();
|
|
307
|
+
|
|
308
|
+
// Get API key details
|
|
309
|
+
const key = await admin.apiKeys.get("key-id");
|
|
310
|
+
|
|
311
|
+
// Allocate credits to API key
|
|
312
|
+
await admin.apiKeys.allocate("key-id", 5000, "Monthly allocation");
|
|
313
|
+
|
|
314
|
+
// Revoke API key
|
|
315
|
+
await admin.apiKeys.revoke("key-id");
|
|
316
|
+
|
|
317
|
+
// Rotate API key
|
|
318
|
+
await admin.apiKeys.rotate("key-id");
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Webhook Events
|
|
322
|
+
|
|
323
|
+
Available webhook events:
|
|
324
|
+
|
|
325
|
+
- `document.uploaded`
|
|
326
|
+
- `document.analyzed`
|
|
327
|
+
- `document.deleted`
|
|
328
|
+
- `thread.created`
|
|
329
|
+
- `thread.message.created`
|
|
330
|
+
- `extraction.completed`
|
|
331
|
+
- `workspace.created`
|
|
332
|
+
- `user.registered`
|
|
333
|
+
|
|
334
|
+
## Bulk Operations
|
|
335
|
+
|
|
336
|
+
All bulk operations support:
|
|
337
|
+
|
|
338
|
+
- Minimum: 1 item
|
|
339
|
+
- Maximum: 100 items per request
|
|
340
|
+
- Validation via Zod schemas
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
// Bulk delete up to 100 documents
|
|
344
|
+
const documentIds = ["doc-1", "doc-2", "doc-3"];
|
|
345
|
+
await admin.documents.bulkDelete(documentIds);
|
|
346
|
+
|
|
347
|
+
// Bulk reprocess documents
|
|
348
|
+
await admin.documents.bulkReprocess(documentIds);
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Security
|
|
352
|
+
|
|
353
|
+
⚠️ **Admin SDK should NEVER be used in client-side code.**
|
|
354
|
+
|
|
355
|
+
- Use only in secure server environments
|
|
356
|
+
- Never expose admin tokens in client code
|
|
357
|
+
- Rotate admin tokens regularly
|
|
358
|
+
- Audit admin actions
|
|
359
|
+
- Limit admin access to essential operations
|
|
360
|
+
|
|
361
|
+
## Error Handling
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
try {
|
|
365
|
+
await admin.accounts.credit("account-id", 1000);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
if (error instanceof ZodError) {
|
|
368
|
+
console.error("Validation error:", error.errors);
|
|
369
|
+
} else {
|
|
370
|
+
console.error("API error:", error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Configuration
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
const admin = new GptAdmin({
|
|
379
|
+
baseUrl: "https://api.gpt-platform.com", // API base URL
|
|
380
|
+
token: "admin-jwt-token", // Admin JWT token
|
|
381
|
+
applicationId: "app-id", // Application ID
|
|
382
|
+
apiKey: "api-key", // Optional: API key
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
## TypeScript Support
|
|
387
|
+
|
|
388
|
+
Full TypeScript definitions included:
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
import type {
|
|
392
|
+
WebhookConfig,
|
|
393
|
+
WebhookDelivery,
|
|
394
|
+
Account,
|
|
395
|
+
Document,
|
|
396
|
+
ApiKey,
|
|
397
|
+
Bucket,
|
|
398
|
+
} from "@gpt-platform/admin";
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
## Testing
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
# Run tests
|
|
405
|
+
npm test
|
|
406
|
+
|
|
407
|
+
# Watch mode
|
|
408
|
+
npm run test:watch
|
|
409
|
+
|
|
410
|
+
# Coverage
|
|
411
|
+
npm run test:coverage
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## License
|
|
415
|
+
|
|
416
|
+
MIT © GPT Integrators
|