@bettercms-ai/sdk 1.21.0 → 1.22.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/dist/index.cjs CHANGED
@@ -402,7 +402,8 @@ var BetterCMSDeliveryClient = class {
402
402
  };
403
403
 
404
404
  // src/methods/webhooks.ts
405
- function addWebhookMethods(client) {
405
+ function addWebhookMethods(client, projectId) {
406
+ const root = `/projects/${encodeURIComponent(projectId)}/webhooks`;
406
407
  return {
407
408
  /**
408
409
  * List webhooks for a project.
@@ -412,7 +413,7 @@ function addWebhookMethods(client) {
412
413
  if (options?.page) params2.set("page", String(options.page));
413
414
  if (options?.limit) params2.set("limit", String(options.limit));
414
415
  return client.fetchJSON(
415
- client.url(`/webhooks?${params2}`),
416
+ client.url(`${root}?${params2}`),
416
417
  { method: "GET" }
417
418
  );
418
419
  },
@@ -420,43 +421,46 @@ function addWebhookMethods(client) {
420
421
  * Create a new webhook. Returns the webhook with secret (shown once).
421
422
  */
422
423
  create: async (input) => {
423
- return client.fetchJSON(
424
- client.url("/webhooks"),
424
+ const response = await client.fetchJSON(
425
+ client.url(root),
425
426
  {
426
427
  method: "POST",
427
428
  headers: { "Content-Type": "application/json" },
428
429
  body: JSON.stringify(input)
429
430
  }
430
431
  );
432
+ return response.data;
431
433
  },
432
434
  /**
433
435
  * Get a single webhook.
434
436
  */
435
437
  get: async (webhookId) => {
436
- return client.fetchJSON(
437
- client.url(`/webhooks/${webhookId}`),
438
+ const response = await client.fetchJSON(
439
+ client.url(`${root}/${encodeURIComponent(webhookId)}`),
438
440
  { method: "GET" }
439
441
  );
442
+ return response.data;
440
443
  },
441
444
  /**
442
445
  * Update a webhook.
443
446
  */
444
447
  update: async (webhookId, input) => {
445
- return client.fetchJSON(
446
- client.url(`/webhooks/${webhookId}`),
448
+ const response = await client.fetchJSON(
449
+ client.url(`${root}/${encodeURIComponent(webhookId)}`),
447
450
  {
448
451
  method: "PATCH",
449
452
  headers: { "Content-Type": "application/json" },
450
453
  body: JSON.stringify(input)
451
454
  }
452
455
  );
456
+ return response.data;
453
457
  },
454
458
  /**
455
459
  * Delete a webhook.
456
460
  */
457
461
  delete: async (webhookId) => {
458
462
  return client.fetchJSON(
459
- client.url(`/webhooks/${webhookId}`),
463
+ client.url(`${root}/${encodeURIComponent(webhookId)}`),
460
464
  { method: "DELETE" }
461
465
  );
462
466
  },
@@ -465,7 +469,7 @@ function addWebhookMethods(client) {
465
469
  */
466
470
  test: async (webhookId, event) => {
467
471
  return client.fetchJSON(
468
- client.url(`/webhooks/${webhookId}/test`),
472
+ client.url(`${root}/${encodeURIComponent(webhookId)}/test`),
469
473
  {
470
474
  method: "POST",
471
475
  headers: { "Content-Type": "application/json" },
@@ -543,9 +547,9 @@ var BetterCMSAdminClient = class extends BetterCMSDeliveryClient {
543
547
  url(path) {
544
548
  return `${this.baseUrl}${path}`;
545
549
  }
546
- /** Webhook management methods. */
547
- webhooks() {
548
- return addWebhookMethods(this);
550
+ /** Project-scoped webhook management methods. */
551
+ webhooks(projectId) {
552
+ return addWebhookMethods(this, projectId);
549
553
  }
550
554
  };
551
555
 
@@ -576,7 +580,11 @@ async function createManagedPage(client, input) {
576
580
  client.url("/management/pages"),
577
581
  { method: "POST", body: JSON.stringify(input) }
578
582
  );
579
- return res.data;
583
+ return {
584
+ ...res.data,
585
+ ...res.warnings?.length ? { warnings: res.warnings } : {},
586
+ ...res.seedErrors ? { seedErrors: res.seedErrors } : {}
587
+ };
580
588
  }
581
589
  async function addPageFields(client, id, input) {
582
590
  const res = await client.fetchJSON(