@gpt-core/admin 0.1.0-alpha.1 → 0.1.0-alpha.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/README.md +237 -18
- package/dist/index.d.mts +13972 -1159
- package/dist/index.d.ts +13972 -1159
- package/dist/index.js +1408 -609
- package/dist/index.mjs +1386 -557
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @gpt-core/admin
|
|
2
2
|
|
|
3
|
-
The official TypeScript Admin SDK for the GPT Core Platform.
|
|
4
|
-
|
|
3
|
+
The official TypeScript Admin SDK for the GPT Core Platform - platform administration, webhook management, and system monitoring.
|
|
4
|
+
|
|
5
|
+
⚠️ **This SDK requires admin privileges and should only be used in secure server environments.**
|
|
5
6
|
|
|
6
7
|
## Installation
|
|
7
8
|
|
|
@@ -15,33 +16,251 @@ npm install @gpt-core/admin
|
|
|
15
16
|
import { GptAdmin } from '@gpt-core/admin';
|
|
16
17
|
|
|
17
18
|
const admin = new GptAdmin({
|
|
18
|
-
baseUrl: 'https://api.gpt-core.com
|
|
19
|
-
|
|
19
|
+
baseUrl: 'https://api.gpt-core.com',
|
|
20
|
+
token: 'admin-jwt-token', // Must be admin user
|
|
21
|
+
applicationId: 'your-app-id',
|
|
20
22
|
});
|
|
21
23
|
|
|
22
|
-
//
|
|
24
|
+
// Get storage statistics
|
|
23
25
|
const stats = await admin.storage.stats();
|
|
24
|
-
console.log(
|
|
26
|
+
console.log(`Total storage: ${stats.total_size} bytes`);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
✅ **Webhook Management** - Configure and monitor webhooks
|
|
32
|
+
✅ **Storage Administration** - Monitor storage usage across workspaces
|
|
33
|
+
✅ **Account Operations** - Credit/debit account balances
|
|
34
|
+
✅ **Document Bulk Operations** - Bulk delete and reprocess documents
|
|
35
|
+
✅ **API Key Management** - Allocate, revoke, rotate API keys
|
|
36
|
+
✅ **Fully Typed** - Complete TypeScript support
|
|
37
|
+
✅ **Runtime Validation** - Zod schemas for request validation
|
|
38
|
+
|
|
39
|
+
## API Reference
|
|
40
|
+
|
|
41
|
+
### Webhooks
|
|
42
|
+
|
|
43
|
+
#### List Webhook Configs
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const configs = await admin.webhooks.configs.list();
|
|
25
47
|
```
|
|
26
48
|
|
|
27
|
-
|
|
49
|
+
#### Create Webhook
|
|
28
50
|
|
|
29
|
-
### Storage Management
|
|
30
|
-
Monitor storage usage across tenants.
|
|
31
51
|
```typescript
|
|
32
|
-
await admin.
|
|
52
|
+
const webhook = await admin.webhooks.configs.create(
|
|
53
|
+
'My Webhook', // name
|
|
54
|
+
'https://your-server.com/webhook', // url
|
|
55
|
+
['document.analyzed', 'thread.message.created'], // events
|
|
56
|
+
'app-123', // application_id
|
|
57
|
+
'your-webhook-secret', // secret (optional)
|
|
58
|
+
true // enabled
|
|
59
|
+
);
|
|
33
60
|
```
|
|
34
61
|
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
#### Update Webhook Config
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const config = await admin.webhooks.configs.update('webhook-id', {
|
|
66
|
+
enabled: false,
|
|
67
|
+
events: ['document.analyzed'],
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Delete Webhook Config
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
await admin.webhooks.configs.delete('webhook-id');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Test Webhook Config
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const result = await admin.webhooks.configs.test('webhook-id');
|
|
81
|
+
console.log('Test delivery ID:', result.delivery_id);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Webhook Deliveries
|
|
85
|
+
|
|
37
86
|
```typescript
|
|
38
|
-
|
|
39
|
-
await admin.webhooks.
|
|
87
|
+
// List deliveries
|
|
88
|
+
const deliveries = await admin.webhooks.deliveries.list();
|
|
89
|
+
|
|
90
|
+
// Get delivery details
|
|
91
|
+
const delivery = await admin.webhooks.deliveries.get('delivery-id');
|
|
92
|
+
|
|
93
|
+
// Retry failed delivery
|
|
94
|
+
await admin.webhooks.deliveries.retry('delivery-id');
|
|
40
95
|
```
|
|
41
96
|
|
|
42
|
-
###
|
|
43
|
-
|
|
97
|
+
### Storage Administration
|
|
98
|
+
|
|
44
99
|
```typescript
|
|
45
|
-
|
|
46
|
-
await admin.
|
|
100
|
+
// Get overall storage stats
|
|
101
|
+
const stats = await admin.storage.stats();
|
|
102
|
+
console.log(stats.total_size, stats.file_count);
|
|
103
|
+
|
|
104
|
+
// Get stats for specific workspace
|
|
105
|
+
const workspaceStats = await admin.storage.stats('workspace-id');
|
|
106
|
+
|
|
107
|
+
// List all buckets
|
|
108
|
+
const buckets = await admin.storage.buckets.list();
|
|
109
|
+
|
|
110
|
+
// Get bucket details
|
|
111
|
+
const bucket = await admin.storage.buckets.get('bucket-id');
|
|
112
|
+
|
|
113
|
+
// Get bucket stats
|
|
114
|
+
const bucketStats = await admin.storage.buckets.stats('bucket-id');
|
|
115
|
+
|
|
116
|
+
// List bucket objects
|
|
117
|
+
const objects = await admin.storage.buckets.objects('bucket-id');
|
|
47
118
|
```
|
|
119
|
+
|
|
120
|
+
### Account Management
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// List all accounts
|
|
124
|
+
const accounts = await admin.accounts.list();
|
|
125
|
+
|
|
126
|
+
// Get account details
|
|
127
|
+
const account = await admin.accounts.get('account-id');
|
|
128
|
+
|
|
129
|
+
// Credit an account
|
|
130
|
+
await admin.accounts.credit('account-id', 1000, 'Bonus credits');
|
|
131
|
+
|
|
132
|
+
// Debit an account
|
|
133
|
+
await admin.accounts.debit('account-id', 500, 'Usage charge');
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Document Administration
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// List documents
|
|
140
|
+
const documents = await admin.documents.list();
|
|
141
|
+
|
|
142
|
+
// Get document details
|
|
143
|
+
const document = await admin.documents.get('doc-id');
|
|
144
|
+
|
|
145
|
+
// Bulk delete documents
|
|
146
|
+
await admin.documents.bulkDelete(['doc-id-1', 'doc-id-2']);
|
|
147
|
+
|
|
148
|
+
// Bulk reprocess documents
|
|
149
|
+
await admin.documents.bulkReprocess(['doc-id-1', 'doc-id-2']);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### API Key Management
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// List API keys
|
|
156
|
+
const keys = await admin.apiKeys.list();
|
|
157
|
+
|
|
158
|
+
// Get API key details
|
|
159
|
+
const key = await admin.apiKeys.get('key-id');
|
|
160
|
+
|
|
161
|
+
// Allocate credits to API key
|
|
162
|
+
await admin.apiKeys.allocate('key-id', 5000, 'Monthly allocation');
|
|
163
|
+
|
|
164
|
+
// Revoke API key
|
|
165
|
+
await admin.apiKeys.revoke('key-id');
|
|
166
|
+
|
|
167
|
+
// Rotate API key
|
|
168
|
+
await admin.apiKeys.rotate('key-id');
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Webhook Events
|
|
172
|
+
|
|
173
|
+
Available webhook events:
|
|
174
|
+
- `document.uploaded`
|
|
175
|
+
- `document.analyzed`
|
|
176
|
+
- `document.deleted`
|
|
177
|
+
- `thread.created`
|
|
178
|
+
- `thread.message.created`
|
|
179
|
+
- `extraction.completed`
|
|
180
|
+
- `workspace.created`
|
|
181
|
+
- `user.registered`
|
|
182
|
+
|
|
183
|
+
[See full webhook documentation](docs/WEBHOOKS.md)
|
|
184
|
+
|
|
185
|
+
## Bulk Operations
|
|
186
|
+
|
|
187
|
+
All bulk operations support:
|
|
188
|
+
- Minimum: 1 item
|
|
189
|
+
- Maximum: 100 items per request
|
|
190
|
+
- Validation via Zod schemas
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// Bulk delete up to 100 documents
|
|
194
|
+
const documentIds = ['doc-1', 'doc-2', 'doc-3'];
|
|
195
|
+
await admin.documents.bulkDelete(documentIds);
|
|
196
|
+
|
|
197
|
+
// Bulk reprocess documents
|
|
198
|
+
await admin.documents.bulkReprocess(documentIds);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Security
|
|
202
|
+
|
|
203
|
+
⚠️ **Admin SDK should NEVER be used in client-side code.**
|
|
204
|
+
|
|
205
|
+
- Use only in secure server environments
|
|
206
|
+
- Never expose admin tokens in client code
|
|
207
|
+
- Rotate admin tokens regularly
|
|
208
|
+
- Audit admin actions
|
|
209
|
+
- Limit admin access to essential operations
|
|
210
|
+
|
|
211
|
+
## Error Handling
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
try {
|
|
215
|
+
await admin.accounts.credit('account-id', 1000);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error instanceof ZodError) {
|
|
218
|
+
console.error('Validation error:', error.errors);
|
|
219
|
+
} else {
|
|
220
|
+
console.error('API error:', error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Configuration
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const admin = new GptAdmin({
|
|
229
|
+
baseUrl: 'https://api.gpt-core.com', // API base URL
|
|
230
|
+
token: 'admin-jwt-token', // Admin JWT token
|
|
231
|
+
applicationId: 'app-id', // Application ID
|
|
232
|
+
apiKey: 'api-key', // Optional: API key
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## TypeScript Support
|
|
237
|
+
|
|
238
|
+
Full TypeScript definitions included:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import type {
|
|
242
|
+
WebhookConfig,
|
|
243
|
+
WebhookDelivery,
|
|
244
|
+
Account,
|
|
245
|
+
Document,
|
|
246
|
+
ApiKey,
|
|
247
|
+
Bucket
|
|
248
|
+
} from '@gpt-core/admin';
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Testing
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
# Run tests
|
|
255
|
+
npm test
|
|
256
|
+
|
|
257
|
+
# Watch mode
|
|
258
|
+
npm run test:watch
|
|
259
|
+
|
|
260
|
+
# Coverage
|
|
261
|
+
npm run test:coverage
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT © GPT Integrators
|