@bettercms-ai/sdk 1.20.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 +25 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +207 -91
- package/dist/index.d.ts +207 -91
- package/dist/index.js +25 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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(
|
|
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
|
-
|
|
424
|
-
client.url(
|
|
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
|
-
|
|
437
|
-
client.url(
|
|
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
|
-
|
|
446
|
-
client.url(
|
|
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(
|
|
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(
|
|
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
|
-
/**
|
|
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
|
|
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(
|
|
@@ -639,12 +647,13 @@ async function updateModel(client, id, input) {
|
|
|
639
647
|
);
|
|
640
648
|
return res.data;
|
|
641
649
|
}
|
|
650
|
+
var withWarnings = (res) => res.warnings?.length ? { ...res.data, warnings: res.warnings } : res.data;
|
|
642
651
|
async function createEntry(client, input) {
|
|
643
652
|
const res = await client.fetchJSON(
|
|
644
653
|
client.url("/management/content/entries"),
|
|
645
654
|
{ method: "POST", body: JSON.stringify(input) }
|
|
646
655
|
);
|
|
647
|
-
return res
|
|
656
|
+
return withWarnings(res);
|
|
648
657
|
}
|
|
649
658
|
async function updateEntry(client, id, input, opts) {
|
|
650
659
|
const headers = {};
|
|
@@ -653,7 +662,7 @@ async function updateEntry(client, id, input, opts) {
|
|
|
653
662
|
client.url(`/management/content/entries/${id}`),
|
|
654
663
|
{ method: "PATCH", body: JSON.stringify(input), headers }
|
|
655
664
|
);
|
|
656
|
-
return res
|
|
665
|
+
return withWarnings(res);
|
|
657
666
|
}
|
|
658
667
|
async function deleteManagedPage(client, id) {
|
|
659
668
|
const res = await client.fetchJSON(
|