@bunbase-ae/js 2.13.2 → 2.13.3-next.300.4a69028

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/admin.ts +80 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunbase-ae/js",
3
- "version": "2.13.2",
3
+ "version": "2.13.3-next.300.4a69028",
4
4
  "type": "module",
5
5
  "description": "TypeScript/JavaScript SDK for BunBase",
6
6
  "license": "UNLICENSED",
package/src/admin.ts CHANGED
@@ -1179,6 +1179,84 @@ class AdminNamedQueriesClient {
1179
1179
  }
1180
1180
  }
1181
1181
 
1182
+ // ─── Write hooks ──────────────────────────────────────────────────────────────
1183
+
1184
+ export type HookEvent =
1185
+ | "beforeCreate"
1186
+ | "afterCreate"
1187
+ | "beforeUpdate"
1188
+ | "afterUpdate"
1189
+ | "beforeDelete"
1190
+ | "afterDelete";
1191
+
1192
+ export interface HookConfig {
1193
+ id: string;
1194
+ collection: string;
1195
+ event: HookEvent;
1196
+ handler_url: string;
1197
+ /** True when a signing secret is configured. Secret value is write-only. */
1198
+ has_handler_secret: boolean;
1199
+ timeout_ms: number;
1200
+ enabled: boolean;
1201
+ sort_order: number;
1202
+ created_at: number;
1203
+ }
1204
+
1205
+ export interface CreateHookInput {
1206
+ collection: string;
1207
+ event: HookEvent;
1208
+ handler_url: string;
1209
+ /** Optional HMAC-SHA256 signing secret. Write-only — never returned. */
1210
+ handler_secret?: string | null;
1211
+ /** Per-call timeout. Default 5000. */
1212
+ timeout_ms?: number;
1213
+ /** When false, the hook is skipped at delivery time. Default true. */
1214
+ enabled?: boolean;
1215
+ /** Ascending order for hooks sharing the same (collection, event). Default 0. */
1216
+ sort_order?: number;
1217
+ }
1218
+
1219
+ export type UpdateHookInput = Partial<Omit<CreateHookInput, "collection" | "event">>;
1220
+
1221
+ class AdminHooksClient {
1222
+ constructor(private readonly http: HttpClient) {}
1223
+
1224
+ async list(opts?: { collection?: string }): Promise<HookConfig[]> {
1225
+ const params: Record<string, string> = {};
1226
+ if (opts?.collection) params.collection = opts.collection;
1227
+ const res = await this.http.request<{ items: HookConfig[] }>("GET", "/api/v1/admin/hooks", {
1228
+ query: params,
1229
+ });
1230
+ return res.items;
1231
+ }
1232
+
1233
+ async get(id: string): Promise<HookConfig | null> {
1234
+ try {
1235
+ return await this.http.request<HookConfig>(
1236
+ "GET",
1237
+ `/api/v1/admin/hooks/${encodeURIComponent(id)}`,
1238
+ );
1239
+ } catch (err) {
1240
+ if (err instanceof BunBaseError && err.status === 404) return null;
1241
+ throw err;
1242
+ }
1243
+ }
1244
+
1245
+ async create(input: CreateHookInput): Promise<HookConfig> {
1246
+ return this.http.request<HookConfig>("POST", "/api/v1/admin/hooks", { body: input });
1247
+ }
1248
+
1249
+ async update(id: string, patch: UpdateHookInput): Promise<HookConfig> {
1250
+ return this.http.request<HookConfig>("PATCH", `/api/v1/admin/hooks/${encodeURIComponent(id)}`, {
1251
+ body: patch,
1252
+ });
1253
+ }
1254
+
1255
+ async delete(id: string): Promise<void> {
1256
+ await this.http.request("DELETE", `/api/v1/admin/hooks/${encodeURIComponent(id)}`);
1257
+ }
1258
+ }
1259
+
1182
1260
  // Tenant membership management — surfaces the /api/v1/admin/tenants/* endpoints
1183
1261
  // added in v2.5.2 (#277/#323) so operators don't need to hand-roll fetch calls
1184
1262
  // to onboard a tenant member.
@@ -1243,6 +1321,7 @@ export class AdminClient {
1243
1321
  readonly backups: AdminBackupsClient;
1244
1322
  readonly migrations: AdminMigrationsClient;
1245
1323
  readonly queries: AdminNamedQueriesClient;
1324
+ readonly hooks: AdminHooksClient;
1246
1325
  readonly logs: AdminLogsClient;
1247
1326
  readonly system: AdminSystemClient;
1248
1327
  readonly tenants: AdminTenantsClient;
@@ -1257,6 +1336,7 @@ export class AdminClient {
1257
1336
  this.backups = new AdminBackupsClient(http);
1258
1337
  this.migrations = new AdminMigrationsClient(http);
1259
1338
  this.queries = new AdminNamedQueriesClient(http);
1339
+ this.hooks = new AdminHooksClient(http);
1260
1340
  this.logs = new AdminLogsClient(http);
1261
1341
  this.system = new AdminSystemClient(http);
1262
1342
  this.tenants = new AdminTenantsClient(http);