@backwrite/sdk 0.2.2 → 0.3.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.
package/src/services.ts CHANGED
@@ -240,22 +240,19 @@ export class BranchesService {
240
240
  });
241
241
  }
242
242
 
243
- delete(branchId: string, projectId?: string): Promise<unknown> {
244
- const pid = requireId(projectId ?? this.client.projectId, "projectId");
245
- return this.client.request("DELETE", `/v1/projects/${pid}/branches/${encodeURIComponent(branchId)}`);
243
+ delete(branchId: string, _projectId?: string): Promise<unknown> {
244
+ return this.client.request("DELETE", `/v1/branches/${encodeURIComponent(branchId)}`, { body: {} });
246
245
  }
247
246
 
248
247
  listSnapshots(scope: ScopeOptions = {}): Promise<unknown> {
249
- const pid = requireId(scope.projectId ?? this.client.projectId, "projectId");
250
248
  const bid = requireId(scope.branchId ?? this.client.branchId, "branchId");
251
- return this.client.request("GET", `/v1/projects/${pid}/branches/${bid}/snapshots`);
249
+ return this.client.request("GET", `/v1/branches/${bid}/snapshots`);
252
250
  }
253
251
 
254
- createSnapshot(label: string, scope: ScopeOptions = {}): Promise<unknown> {
255
- const pid = requireId(scope.projectId ?? this.client.projectId, "projectId");
252
+ createSnapshot(kind = "manual", scope: ScopeOptions = {}): Promise<unknown> {
256
253
  const bid = requireId(scope.branchId ?? this.client.branchId, "branchId");
257
- return this.client.request("POST", `/v1/projects/${pid}/branches/${bid}/snapshots`, {
258
- body: { label, name: label },
254
+ return this.client.request("POST", `/v1/branches/${bid}/snapshot`, {
255
+ body: { kind },
259
256
  });
260
257
  }
261
258
  }
@@ -275,28 +272,28 @@ export class StorageService {
275
272
  });
276
273
  }
277
274
 
278
- upload(bucket: string, key: string, data: Uint8Array | ArrayBuffer | string, branchId?: string): Promise<unknown> {
275
+ upload(_bucket: string, key: string, data: Uint8Array | ArrayBuffer | string, branchId?: string): Promise<unknown> {
279
276
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
280
277
  return this.client.request(
281
278
  "PUT",
282
- `/v1/storage/${bid}/${encodeURIComponent(bucket)}/${key.replace(/^\/+/, "")}`,
279
+ `/v1/storage/${bid}/objects/${key.replace(/^\/+/, "")}`,
283
280
  { body: data },
284
281
  );
285
282
  }
286
283
 
287
- download(bucket: string, key: string, branchId?: string): Promise<unknown> {
284
+ download(_bucket: string, key: string, branchId?: string): Promise<unknown> {
288
285
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
289
286
  return this.client.request(
290
287
  "GET",
291
- `/v1/storage/${bid}/${encodeURIComponent(bucket)}/${key.replace(/^\/+/, "")}`,
288
+ `/v1/storage/${bid}/objects/${key.replace(/^\/+/, "")}`,
292
289
  );
293
290
  }
294
291
 
295
- deleteObject(bucket: string, key: string, branchId?: string): Promise<unknown> {
292
+ deleteObject(_bucket: string, key: string, branchId?: string): Promise<unknown> {
296
293
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
297
294
  return this.client.request(
298
295
  "DELETE",
299
- `/v1/storage/${bid}/${encodeURIComponent(bucket)}/${key.replace(/^\/+/, "")}`,
296
+ `/v1/storage/${bid}/objects/${key.replace(/^\/+/, "")}`,
300
297
  );
301
298
  }
302
299
  }
@@ -306,19 +303,20 @@ export class CacheService {
306
303
 
307
304
  get(key: string, branchId?: string): Promise<unknown> {
308
305
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
309
- return this.client.request("GET", `/v1/cache/${bid}/kv/${encodeURIComponent(key)}`);
306
+ return this.client.request("GET", `/v1/cache/${bid}/entries/${encodeURIComponent(key)}`);
310
307
  }
311
308
 
312
309
  set(key: string, value: unknown, ttlSeconds?: number, branchId?: string): Promise<unknown> {
313
310
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
314
- return this.client.request("PUT", `/v1/cache/${bid}/kv/${encodeURIComponent(key)}`, {
315
- body: { value, ...(ttlSeconds !== undefined ? { ttl_seconds: ttlSeconds } : {}) },
311
+ return this.client.request("PUT", `/v1/cache/${bid}/entries/${encodeURIComponent(key)}`, {
312
+ query: ttlSeconds !== undefined ? { ttl: ttlSeconds } : undefined,
313
+ body: { value },
316
314
  });
317
315
  }
318
316
 
319
317
  del(key: string, branchId?: string): Promise<unknown> {
320
318
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
321
- return this.client.request("DELETE", `/v1/cache/${bid}/kv/${encodeURIComponent(key)}`);
319
+ return this.client.request("DELETE", `/v1/cache/${bid}/entries/${encodeURIComponent(key)}`);
322
320
  }
323
321
  }
324
322
 
@@ -327,14 +325,14 @@ export class QueuesService {
327
325
 
328
326
  publish(queue: string, payload: unknown, branchId?: string): Promise<unknown> {
329
327
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
330
- return this.client.request("POST", `/v1/queues/${bid}/${encodeURIComponent(queue)}/messages`, {
328
+ return this.client.request("POST", `/v1/queues/${bid}/${encodeURIComponent(queue)}`, {
331
329
  body: { payload },
332
330
  });
333
331
  }
334
332
 
335
333
  pull(queue: string, batch = 1, branchId?: string): Promise<unknown> {
336
334
  const bid = requireId(branchId ?? this.client.branchId, "branchId");
337
- return this.client.request("POST", `/v1/queues/${bid}/${encodeURIComponent(queue)}/pull`, {
335
+ return this.client.request("POST", `/v1/queues/${bid}/${encodeURIComponent(queue)}/fetch`, {
338
336
  body: { batch },
339
337
  });
340
338
  }
@@ -346,9 +344,9 @@ export class QueuesService {
346
344
  });
347
345
  }
348
346
 
349
- stats(queue = "default", projectId?: string): Promise<unknown> {
350
- const pid = requireId(projectId ?? this.client.projectId, "projectId");
351
- return this.client.request("GET", `/v1/projects/${pid}/queues/${encodeURIComponent(queue)}/stats`);
347
+ stats(queue = "default", branchId?: string): Promise<unknown> {
348
+ const bid = requireId(branchId ?? this.client.branchId, "branchId");
349
+ return this.client.request("GET", `/v1/queues/${bid}/${encodeURIComponent(queue)}/stats`);
352
350
  }
353
351
  }
354
352
 
@@ -403,17 +401,18 @@ export class SecretsService {
403
401
 
404
402
  list(projectId?: string): Promise<unknown> {
405
403
  const pid = requireId(projectId ?? this.client.projectId, "projectId");
406
- return this.client.request("GET", `/v1/projects/${pid}/config/secrets`);
404
+ return this.client.request("GET", `/v1/projects/${pid}/secrets`);
407
405
  }
408
406
 
409
- set(key: string, value: string, projectId?: string): Promise<unknown> {
407
+ set(name: string, value: string, projectId?: string, environment = "production"): Promise<unknown> {
410
408
  const pid = requireId(projectId ?? this.client.projectId, "projectId");
411
- return this.client.request("POST", `/v1/projects/${pid}/config/secrets`, { body: { key, value } });
409
+ return this.client.request("POST", `/v1/projects/${pid}/secrets`, { body: { name, value, environment } });
412
410
  }
413
411
 
414
- delete(key: string, projectId?: string): Promise<unknown> {
412
+ /** Delete by secret id (`sec_…`). */
413
+ delete(secretId: string, projectId?: string): Promise<unknown> {
415
414
  const pid = requireId(projectId ?? this.client.projectId, "projectId");
416
- return this.client.request("DELETE", `/v1/projects/${pid}/config/secrets/${encodeURIComponent(key)}`);
415
+ return this.client.request("DELETE", `/v1/projects/${pid}/secrets/${encodeURIComponent(secretId)}`);
417
416
  }
418
417
  }
419
418