@harborclient/team-hub-api 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.
@@ -0,0 +1,353 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Supported HTTP methods for saved and live requests.
4
+ */
5
+ export const httpMethod = z.enum([
6
+ 'GET',
7
+ 'POST',
8
+ 'PUT',
9
+ 'PATCH',
10
+ 'DELETE',
11
+ 'HEAD',
12
+ 'OPTIONS'
13
+ ]);
14
+ /**
15
+ * Supported request body content types.
16
+ */
17
+ export const bodyType = z.enum([
18
+ 'none',
19
+ 'json',
20
+ 'text',
21
+ 'multipart',
22
+ 'urlencoded'
23
+ ]);
24
+ /**
25
+ * Header or query parameter key-value row.
26
+ */
27
+ export const keyValue = z.object({
28
+ key: z.string(),
29
+ value: z.string(),
30
+ enabled: z.boolean()
31
+ });
32
+ /**
33
+ * Collection or environment variable row.
34
+ */
35
+ export const variable = z.object({
36
+ key: z.string(),
37
+ value: z.string(),
38
+ defaultValue: z.string(),
39
+ share: z.boolean()
40
+ });
41
+ /**
42
+ * Authorization settings returned by Team Hub entity routes.
43
+ */
44
+ export const teamHubAuthConfigSchema = z.object({
45
+ type: z.enum(['none', 'basic', 'bearer']),
46
+ basic: z.object({
47
+ username: z.string(),
48
+ password: z.string()
49
+ }),
50
+ bearer: z.object({
51
+ token: z.string()
52
+ })
53
+ });
54
+ /**
55
+ * Standard error body returned by HarborClient Server API routes.
56
+ */
57
+ export const errorResponseSchema = z.object({
58
+ error: z.string()
59
+ });
60
+ /**
61
+ * ISO 8601 timestamp strings returned in JSON responses.
62
+ */
63
+ export const timestampSchema = z.iso.datetime();
64
+ /**
65
+ * Parses deletion lock flags from Team Hub responses.
66
+ *
67
+ * Older hub versions omit this field; treat missing values as unlocked.
68
+ */
69
+ export const deletionLockedSchema = z.boolean().optional().default(false);
70
+ /**
71
+ * JSON shape for a persisted collection record.
72
+ */
73
+ export const collectionRecordSchema = z.object({
74
+ id: z.string(),
75
+ name: z.string(),
76
+ variables: z.array(variable),
77
+ headers: z.array(keyValue),
78
+ auth: teamHubAuthConfigSchema,
79
+ preRequestScript: z.string(),
80
+ postRequestScript: z.string(),
81
+ createdAt: timestampSchema,
82
+ deletionLocked: deletionLockedSchema
83
+ });
84
+ /**
85
+ * JSON shape for a persisted environment record.
86
+ */
87
+ export const environmentRecordSchema = z.object({
88
+ id: z.string(),
89
+ name: z.string(),
90
+ variables: z.array(variable),
91
+ createdAt: timestampSchema,
92
+ deletionLocked: deletionLockedSchema
93
+ });
94
+ /**
95
+ * JSON shape for a persisted folder record.
96
+ */
97
+ export const folderRecordSchema = z.object({
98
+ id: z.string(),
99
+ collectionId: z.string(),
100
+ name: z.string(),
101
+ sortOrder: z.number().int(),
102
+ createdAt: timestampSchema
103
+ });
104
+ /**
105
+ * JSON shape for a persisted saved request record.
106
+ */
107
+ export const savedRequestRecordSchema = z.object({
108
+ id: z.string(),
109
+ collectionId: z.string(),
110
+ name: z.string(),
111
+ method: httpMethod,
112
+ url: z.string(),
113
+ headers: z.array(keyValue),
114
+ params: z.array(keyValue),
115
+ auth: teamHubAuthConfigSchema,
116
+ body: z.string(),
117
+ bodyType: bodyType,
118
+ preRequestScript: z.string(),
119
+ postRequestScript: z.string(),
120
+ comment: z.string(),
121
+ folderId: z.string().nullable(),
122
+ sortOrder: z.number().int(),
123
+ createdAt: timestampSchema,
124
+ updatedAt: timestampSchema
125
+ });
126
+ /**
127
+ * Response body schema for `GET /health`.
128
+ */
129
+ export const healthResponseSchema = z.object({
130
+ status: z.literal('ok'),
131
+ version: z.string()
132
+ });
133
+ /**
134
+ * Response body schema for `GET /auth/session`.
135
+ */
136
+ export const sessionResponseSchema = z.object({
137
+ user: z.object({
138
+ id: z.string(),
139
+ name: z.string(),
140
+ role: z.enum(['admin', 'user'])
141
+ }),
142
+ token: z.object({
143
+ id: z.string(),
144
+ prefix: z.string()
145
+ }),
146
+ capabilities: z.object({
147
+ dataApi: z.boolean(),
148
+ managementApi: z.boolean(),
149
+ llm: z.boolean()
150
+ })
151
+ });
152
+ /**
153
+ * JSON shape for a Team Hub user account returned by management routes.
154
+ */
155
+ export const hubUserRecordSchema = z.object({
156
+ id: z.string(),
157
+ name: z.string(),
158
+ role: z.enum(['admin', 'user']),
159
+ collectionAccess: z.array(z.string()),
160
+ environmentAccess: z.array(z.string()),
161
+ llmAccess: z.boolean(),
162
+ llmModels: z.array(z.string()),
163
+ llmMonthlyTokenLimit: z.number().int().nonnegative().nullable(),
164
+ createdAt: timestampSchema,
165
+ updatedAt: timestampSchema
166
+ });
167
+ /**
168
+ * List response wrapper for admin user listings.
169
+ */
170
+ export const listAdminUsersResponseSchema = z.object({
171
+ users: z.array(hubUserRecordSchema)
172
+ });
173
+ /**
174
+ * Lightweight id/name record returned by admin list routes.
175
+ */
176
+ export const adminResourceOptionSchema = z.object({
177
+ id: z.string(),
178
+ name: z.string(),
179
+ deletionLocked: deletionLockedSchema
180
+ });
181
+ /**
182
+ * Response body schema for admin entity configuration updates.
183
+ */
184
+ export const adminEntityConfigSchema = z.object({
185
+ id: z.string(),
186
+ name: z.string(),
187
+ deletionLocked: deletionLockedSchema
188
+ });
189
+ /**
190
+ * Request body schema for `PUT /admin/collections/:id`.
191
+ */
192
+ export const updateAdminCollectionBodySchema = z.object({
193
+ deletionLocked: z.boolean()
194
+ });
195
+ /**
196
+ * Request body schema for `PUT /admin/environments/:id`.
197
+ */
198
+ export const updateAdminEnvironmentBodySchema = z.object({
199
+ deletionLocked: z.boolean()
200
+ });
201
+ /**
202
+ * List response wrapper for admin collection listings.
203
+ */
204
+ export const listAdminCollectionsResponseSchema = z.object({
205
+ collections: z.array(adminResourceOptionSchema)
206
+ });
207
+ /**
208
+ * List response wrapper for admin environment listings.
209
+ */
210
+ export const listAdminEnvironmentsResponseSchema = z.object({
211
+ environments: z.array(adminResourceOptionSchema)
212
+ });
213
+ /**
214
+ * Request body schema for `PUT /admin/users/:id`.
215
+ */
216
+ export const updateAdminUserBodySchema = z.object({
217
+ name: z.string().trim().min(1).optional(),
218
+ role: z.enum(['admin', 'user']).optional(),
219
+ collectionAccess: z.array(z.string()).optional(),
220
+ environmentAccess: z.array(z.string()).optional(),
221
+ llmAccess: z.boolean().optional(),
222
+ llmModels: z.array(z.string()).optional(),
223
+ llmMonthlyTokenLimit: z.number().int().nonnegative().nullable().optional()
224
+ });
225
+ /**
226
+ * Request body schema for `POST /admin/users`.
227
+ */
228
+ export const createAdminUserBodySchema = z.object({
229
+ name: z.string().trim().min(1),
230
+ role: z.enum(['admin', 'user']),
231
+ collectionAccess: z.array(z.string()).optional(),
232
+ environmentAccess: z.array(z.string()).optional(),
233
+ llmAccess: z.boolean().optional(),
234
+ llmModels: z.array(z.string()).optional(),
235
+ llmMonthlyTokenLimit: z.number().int().nonnegative().nullable().optional()
236
+ });
237
+ /**
238
+ * JSON shape for an API token record returned by admin token routes.
239
+ */
240
+ export const hubApiTokenRecordSchema = z.object({
241
+ id: z.string(),
242
+ userId: z.string(),
243
+ name: z.string(),
244
+ tokenPrefix: z.string(),
245
+ createdAt: timestampSchema,
246
+ lastUsedAt: timestampSchema.nullable(),
247
+ revokedAt: timestampSchema.nullable()
248
+ });
249
+ /**
250
+ * Response body schema for `POST /admin/users`.
251
+ */
252
+ export const createAdminUserResponseSchema = z.object({
253
+ user: hubUserRecordSchema,
254
+ token: hubApiTokenRecordSchema,
255
+ secret: z.string()
256
+ });
257
+ /**
258
+ * Request body schema for `POST /admin/users/:id/tokens`.
259
+ */
260
+ export const createAdminTokenBodySchema = z.object({
261
+ name: z.string().trim().min(1)
262
+ });
263
+ /**
264
+ * Response body schema for `POST /admin/users/:id/tokens`.
265
+ */
266
+ export const createdApiTokenResponseSchema = z.object({
267
+ token: hubApiTokenRecordSchema,
268
+ secret: z.string()
269
+ });
270
+ /**
271
+ * List response wrapper for admin token listings.
272
+ */
273
+ export const listAdminTokensResponseSchema = z.object({
274
+ tokens: z.array(hubApiTokenRecordSchema)
275
+ });
276
+ /**
277
+ * Per-section outcome reported by config reload routes.
278
+ */
279
+ export const reloadConfigSectionResultSchema = z.object({
280
+ section: z.enum(['db', 'redis', 'llm', 'plugins', 'server']),
281
+ status: z.enum(['reloaded', 'unchanged', 'failed', 'restart-required']),
282
+ error: z.string().optional()
283
+ });
284
+ /**
285
+ * Response body schema for `POST /admin/config/reload`.
286
+ */
287
+ export const reloadConfigResponseSchema = z.object({
288
+ sections: z.array(reloadConfigSectionResultSchema),
289
+ fatalError: z.string().optional()
290
+ });
291
+ /**
292
+ * List response wrapper for collections.
293
+ */
294
+ export const listCollectionsResponseSchema = z.object({
295
+ collections: z.array(collectionRecordSchema)
296
+ });
297
+ /**
298
+ * List response wrapper for environments.
299
+ */
300
+ export const listEnvironmentsResponseSchema = z.object({
301
+ environments: z.array(environmentRecordSchema)
302
+ });
303
+ /**
304
+ * List response wrapper for folders.
305
+ */
306
+ export const listFoldersResponseSchema = z.object({
307
+ folders: z.array(folderRecordSchema)
308
+ });
309
+ /**
310
+ * List response wrapper for saved requests.
311
+ */
312
+ export const listRequestsResponseSchema = z.object({
313
+ requests: z.array(savedRequestRecordSchema)
314
+ });
315
+ /**
316
+ * JSON shape for one hub-offered LLM model.
317
+ */
318
+ export const hubLlmModelSchema = z.object({
319
+ id: z.string(),
320
+ label: z.string(),
321
+ provider: z.enum(['openai', 'claude', 'gemini'])
322
+ });
323
+ /**
324
+ * JSON shape for GET /llm/models response body.
325
+ */
326
+ export const listHubLlmModelsResponseSchema = z.object({
327
+ models: z.array(hubLlmModelSchema)
328
+ });
329
+ /**
330
+ * JSON shape for GET /plugins/sources response body.
331
+ */
332
+ export const pluginSourcesResponseSchema = z.object({
333
+ catalogs: z.array(z.string()),
334
+ trusted: z.array(z.string())
335
+ });
336
+ /**
337
+ * JSON shape for POST /llm/chat/step response body.
338
+ */
339
+ export const hubChatStepResponseSchema = z.object({
340
+ content: z.string().nullable(),
341
+ toolCalls: z
342
+ .array(z.object({
343
+ id: z.string(),
344
+ name: z.string(),
345
+ arguments: z.string()
346
+ }))
347
+ .optional(),
348
+ usage: z.object({
349
+ promptTokens: z.number().int().nonnegative(),
350
+ completionTokens: z.number().int().nonnegative(),
351
+ totalTokens: z.number().int().nonnegative()
352
+ })
353
+ });