@gpt-core/admin 0.1.0-alpha.1 → 0.2.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.
Files changed (6) hide show
  1. package/README.md +339 -17
  2. package/dist/index.d.mts +19861 -1179
  3. package/dist/index.d.ts +19861 -1179
  4. package/dist/index.js +1408 -609
  5. package/dist/index.mjs +1386 -557
  6. package/package.json +10 -3
package/README.md CHANGED
@@ -1,12 +1,33 @@
1
1
  # @gpt-core/admin
2
2
 
3
- The official TypeScript Admin SDK for the GPT Core Platform.
4
- **Intended for backend services and internal tools only.**
3
+ The official TypeScript Admin SDK for the GPT Core Platform - platform administration, webhook management, and system monitoring.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@gpt-core/admin.svg)](https://www.npmjs.com/package/@gpt-core/admin)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)](https://www.typescriptlang.org/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ⚠️ **This SDK requires admin privileges and should only be used in secure server environments.**
10
+
11
+ ## Features
12
+
13
+ ✅ **Fully Typed** - Complete TypeScript support with auto-generated types from OpenAPI specs
14
+ ✅ **Runtime Validation** - Zod schemas for request validation
15
+ ✅ **Bulk Operations** - Efficient batch processing for documents and webhooks
16
+ ✅ **Webhook Management** - Configure, monitor, and test webhook configurations
17
+ ✅ **Storage Administration** - Monitor storage usage across workspaces and buckets
18
+ ✅ **Account Operations** - Credit/debit account balances with audit trails
19
+ ✅ **Document Management** - Bulk delete and reprocess documents
20
+ ✅ **API Key Management** - Allocate, revoke, and rotate API keys
21
+ ✅ **Error Handling** - Comprehensive error handling with detailed context
5
22
 
6
23
  ## Installation
7
24
 
8
25
  ```bash
9
26
  npm install @gpt-core/admin
27
+ # or
28
+ yarn add @gpt-core/admin
29
+ # or
30
+ pnpm add @gpt-core/admin
10
31
  ```
11
32
 
12
33
  ## Quick Start
@@ -14,34 +35,335 @@ npm install @gpt-core/admin
14
35
  ```typescript
15
36
  import { GptAdmin } from '@gpt-core/admin';
16
37
 
38
+ // Initialize admin client
17
39
  const admin = new GptAdmin({
18
- baseUrl: 'https://api.gpt-core.com/admin',
19
- apiKey: 'your-secret-admin-key'
40
+ baseUrl: 'https://api.gpt-core.com',
41
+ token: process.env.ADMIN_JWT_TOKEN, // Admin JWT token
42
+ applicationId: process.env.APPLICATION_ID, // Your application ID
20
43
  });
21
44
 
22
- // Check System Health
45
+ // Get storage statistics
23
46
  const stats = await admin.storage.stats();
24
- console.log('Total Storage Used:', stats.total_bytes);
47
+ console.log(`Total storage: ${(stats.total_size / 1024 / 1024).toFixed(2)} MB`);
48
+ console.log(`Total files: ${stats.file_count}`);
49
+
50
+ // List webhook configurations
51
+ const webhooks = await admin.webhooks.configs.list();
52
+ console.log(`Active webhooks: ${webhooks.filter(w => w.attributes.enabled).length}`);
25
53
  ```
26
54
 
27
- ## Domains
55
+ ## Configuration
56
+
57
+ ```typescript
58
+ const admin = new GptAdmin({
59
+ // Required: API base URL
60
+ baseUrl: 'https://api.gpt-core.com',
61
+
62
+ // Required: Admin JWT token
63
+ token: 'admin-jwt-token',
64
+
65
+ // Required: Application ID
66
+ applicationId: 'your-app-id',
67
+ });
68
+ ```
69
+
70
+ ### Environment Variables (Recommended)
71
+
72
+ ```bash
73
+ # .env or .env.local
74
+ ADMIN_API_URL=https://api.gpt-core.com
75
+ ADMIN_JWT_TOKEN=your-admin-jwt-token
76
+ APPLICATION_ID=your-application-id
77
+ ```
28
78
 
29
- ### Storage Management
30
- Monitor storage usage across tenants.
31
79
  ```typescript
32
- await admin.storage.stats();
80
+ // lib/admin-client.ts
81
+ import { GptAdmin } from '@gpt-core/admin';
82
+
83
+ export const admin = new GptAdmin({
84
+ baseUrl: process.env.ADMIN_API_URL!,
85
+ token: process.env.ADMIN_JWT_TOKEN!,
86
+ applicationId: process.env.APPLICATION_ID!,
87
+ });
33
88
  ```
34
89
 
90
+ ## API Reference
91
+
35
92
  ### Webhooks
36
- Manage functionality of webhooks system-wide.
93
+
94
+ #### List Webhook Configs
95
+
96
+ ```typescript
97
+ const configs = await admin.webhooks.configs.list();
98
+ ```
99
+
100
+ #### Create Webhook
101
+
102
+ ```typescript
103
+ const webhook = await admin.webhooks.configs.create(
104
+ 'My Webhook', // name
105
+ 'https://your-server.com/webhook', // url
106
+ ['document.analyzed', 'thread.message.created'], // events
107
+ 'app-123', // application_id
108
+ 'your-webhook-secret', // secret (optional)
109
+ true // enabled
110
+ );
111
+ ```
112
+
113
+ #### Update Webhook Config
114
+
115
+ ```typescript
116
+ const config = await admin.webhooks.configs.update('webhook-id', {
117
+ enabled: false,
118
+ events: ['document.analyzed'],
119
+ });
120
+ ```
121
+
122
+ #### Delete Webhook Config
123
+
124
+ ```typescript
125
+ await admin.webhooks.configs.delete('webhook-id');
126
+ ```
127
+
128
+ #### Test Webhook Config
129
+
130
+ ```typescript
131
+ const result = await admin.webhooks.configs.test('webhook-id');
132
+ console.log('Test delivery ID:', result.delivery_id);
133
+ ```
134
+
135
+ #### Webhook Deliveries
136
+
137
+ ```typescript
138
+ // List deliveries
139
+ const deliveries = await admin.webhooks.deliveries.list();
140
+
141
+ // Get delivery details
142
+ const delivery = await admin.webhooks.deliveries.get('delivery-id');
143
+
144
+ // Retry failed delivery
145
+ await admin.webhooks.deliveries.retry('delivery-id');
146
+ ```
147
+
148
+ ### Storage Administration
149
+
150
+ ```typescript
151
+ // Get overall storage stats
152
+ const stats = await admin.storage.stats();
153
+ console.log(stats.total_size, stats.file_count);
154
+
155
+ // Get stats for specific workspace
156
+ const workspaceStats = await admin.storage.stats('workspace-id');
157
+
158
+ // List all buckets
159
+ const buckets = await admin.storage.buckets.list();
160
+
161
+ // Get bucket details
162
+ const bucket = await admin.storage.buckets.get('bucket-id');
163
+
164
+ // Get bucket stats
165
+ const bucketStats = await admin.storage.buckets.stats('bucket-id');
166
+
167
+ // List bucket objects
168
+ const objects = await admin.storage.buckets.objects('bucket-id');
169
+ ```
170
+
171
+ ### Account Management
172
+
173
+ ```typescript
174
+ // List all accounts
175
+ const accounts = await admin.accounts.list();
176
+
177
+ // Get account details
178
+ const account = await admin.accounts.get('account-id');
179
+
180
+ // Credit an account
181
+ await admin.accounts.credit('account-id', 1000, 'Bonus credits');
182
+
183
+ // Debit an account
184
+ await admin.accounts.debit('account-id', 500, 'Usage charge');
185
+ ```
186
+
187
+ ### Document Administration
188
+
189
+ ```typescript
190
+ // List documents
191
+ const documents = await admin.documents.list();
192
+
193
+ // Get document details
194
+ const document = await admin.documents.get('doc-id');
195
+
196
+ // Bulk delete documents
197
+ await admin.documents.bulkDelete(['doc-id-1', 'doc-id-2']);
198
+
199
+ // Bulk reprocess documents
200
+ await admin.documents.bulkReprocess(['doc-id-1', 'doc-id-2']);
201
+ ```
202
+
203
+ ### API Key Management
204
+
205
+ ```typescript
206
+ // List API keys
207
+ const keys = await admin.apiKeys.list();
208
+
209
+ // Get API key details
210
+ const key = await admin.apiKeys.get('key-id');
211
+
212
+ // Allocate credits to API key
213
+ await admin.apiKeys.allocate('key-id', 5000, 'Monthly allocation');
214
+
215
+ // Revoke API key
216
+ await admin.apiKeys.revoke('key-id');
217
+
218
+ // Rotate API key
219
+ await admin.apiKeys.rotate('key-id');
220
+ ```
221
+
222
+ ## Webhook Events
223
+
224
+ Available webhook events:
225
+ - `document.uploaded`
226
+ - `document.analyzed`
227
+ - `document.deleted`
228
+ - `thread.created`
229
+ - `thread.message.created`
230
+ - `extraction.completed`
231
+ - `workspace.created`
232
+ - `user.registered`
233
+
234
+ [See full webhook documentation](docs/WEBHOOKS.md)
235
+
236
+ ## Bulk Operations
237
+
238
+ All bulk operations support:
239
+ - Minimum: 1 item
240
+ - Maximum: 100 items per request
241
+ - Validation via Zod schemas
242
+
243
+ ```typescript
244
+ // Bulk delete up to 100 documents
245
+ const documentIds = ['doc-1', 'doc-2', 'doc-3'];
246
+ await admin.documents.bulkDelete(documentIds);
247
+
248
+ // Bulk reprocess documents
249
+ await admin.documents.bulkReprocess(documentIds);
250
+ ```
251
+
252
+ ## Security
253
+
254
+ ⚠️ **Admin SDK should NEVER be used in client-side code.**
255
+
256
+ - Use only in secure server environments
257
+ - Never expose admin tokens in client code
258
+ - Rotate admin tokens regularly
259
+ - Audit admin actions
260
+ - Limit admin access to essential operations
261
+
262
+ ## Error Handling
263
+
37
264
  ```typescript
38
- await admin.webhooks.stats();
39
- await admin.webhooks.bulkEnable(['config-1', 'config-2']);
265
+ try {
266
+ await admin.accounts.credit('account-id', 1000);
267
+ } catch (error) {
268
+ if (error instanceof ZodError) {
269
+ console.error('Validation error:', error.errors);
270
+ } else {
271
+ console.error('API error:', error);
272
+ }
273
+ }
40
274
  ```
41
275
 
42
- ### Agents
43
- Import/Export Agent configurations.
276
+ ## Configuration
277
+
44
278
  ```typescript
45
- const dump = await admin.agents.export('agent-id');
46
- await admin.agents.import(dump);
279
+ const admin = new GptAdmin({
280
+ baseUrl: 'https://api.gpt-core.com', // API base URL
281
+ token: 'admin-jwt-token', // Admin JWT token
282
+ applicationId: 'app-id', // Application ID
283
+ apiKey: 'api-key', // Optional: API key
284
+ });
285
+ ```
286
+
287
+ ## TypeScript Support
288
+
289
+ Full TypeScript definitions included:
290
+
291
+ ```typescript
292
+ import type {
293
+ WebhookConfig,
294
+ WebhookDelivery,
295
+ Account,
296
+ Document,
297
+ ApiKey,
298
+ Bucket
299
+ } from '@gpt-core/admin';
300
+ ```
301
+
302
+ ## Documentation
303
+
304
+ ### For ISV Developers
305
+
306
+ - **[ISV Integration Guide](docs/ISV_GUIDE.md)** - Complete production-ready integration guide
307
+ - Environment setup and authentication
308
+ - Common workflows (webhooks, storage, billing, bulk ops)
309
+ - Production best practices and security
310
+ - Monitoring, observability, error handling
311
+ - Rate limiting and troubleshooting
312
+
313
+ - **[AI-Assisted Integration](docs/AI_INTEGRATION_GUIDE.md)** - Quick-start for AI coding assistants
314
+ - Copy-paste integration patterns
315
+ - Ready-to-use code snippets for common use cases
316
+ - AI prompt templates for Cursor/Copilot/Claude
317
+
318
+ ### Topic Guides
319
+
320
+ - **[Authentication](docs/AUTHENTICATION.md)** - Admin token management and security
321
+ - JWT token authentication
322
+ - Token refresh strategies
323
+ - Secret management integration (AWS, Vault, GCP)
324
+ - Multi-environment configuration
325
+
326
+ - **[Error Handling](docs/ERROR_HANDLING.md)** - Comprehensive error handling strategies
327
+ - Validation errors (Zod)
328
+ - HTTP errors (401, 403, 404, 429, 500)
329
+ - Retry strategies (exponential backoff, jitter)
330
+ - Circuit breaker pattern
331
+ - Graceful degradation
332
+
333
+ - **[Bulk Operations](docs/BULK_OPERATIONS.md)** - Efficient batch processing guide
334
+ - Document bulk delete and reprocess
335
+ - Webhook bulk enable/disable
336
+ - Batching strategies and performance optimization
337
+ - Progress tracking and monitoring
338
+ - Error handling for partial failures
339
+
340
+ - **[Webhook Management](docs/WEBHOOKS.md)** - Webhook configuration and monitoring
341
+ - Creating and configuring webhooks
342
+ - Signature verification
343
+ - Event handling
344
+ - Monitoring deliveries
345
+ - Troubleshooting
346
+
347
+ ### For SDK Contributors
348
+
349
+ - **[llms.txt](llms.txt)** - AI agent context for SDK maintenance
350
+ - SDK architecture and patterns
351
+ - Generated vs handwritten code
352
+ - Development workflows
353
+
354
+ ## Testing
355
+
356
+ ```bash
357
+ # Run tests
358
+ npm test
359
+
360
+ # Watch mode
361
+ npm run test:watch
362
+
363
+ # Coverage
364
+ npm run test:coverage
47
365
  ```
366
+
367
+ ## License
368
+
369
+ MIT © GPT Integrators