@bettercms-ai/sdk 1.18.0 → 1.19.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
@@ -154,13 +154,24 @@ var BetterCMSError = class _BetterCMSError extends Error {
154
154
  * hint which field or rule failed (FLO-474). Mirrors the forms client's `fieldErrors`.
155
155
  */
156
156
  fieldErrors;
157
- constructor(message, status, code, bodyCode, fieldErrors) {
157
+ /**
158
+ * The parsed response body, when there was one.
159
+ *
160
+ * Several refusals carry STRUCTURED detail that neither `message` nor `fieldErrors` can hold,
161
+ * and which is the whole point of the refusal: a component publish 409s with the full
162
+ * `readiness` tuple (what evidence is missing, whether a human still has to approve it) and
163
+ * 422s with the `issues` naming the Layouts it would break. Collapsing those to a sentence
164
+ * leaves a caller able to report that something failed and not what to do about it.
165
+ */
166
+ body;
167
+ constructor(message, status, code, bodyCode, fieldErrors, body) {
158
168
  super(message);
159
169
  this.name = "BetterCMSError";
160
170
  this.status = status;
161
171
  this.code = code;
162
172
  this.bodyCode = bodyCode;
163
173
  this.fieldErrors = fieldErrors;
174
+ this.body = body;
164
175
  if (Error.captureStackTrace) {
165
176
  Error.captureStackTrace(this, _BetterCMSError);
166
177
  }
@@ -187,6 +198,7 @@ var BetterCMSError = class _BetterCMSError extends Error {
187
198
  let bodyCode;
188
199
  let fieldErrors;
189
200
  let code = statusToCode(res.status);
201
+ let raw;
190
202
  try {
191
203
  const body = await res.json();
192
204
  if (body?.errors && typeof body.errors === "object") {
@@ -202,9 +214,10 @@ var BetterCMSError = class _BetterCMSError extends Error {
202
214
  if (field) message = `${field}: ${detail}`;
203
215
  }
204
216
  if (body?.code) bodyCode = body.code;
217
+ raw = body;
205
218
  } catch {
206
219
  }
207
- return new _BetterCMSError(message, res.status, code, bodyCode, fieldErrors);
220
+ return new _BetterCMSError(message, res.status, code, bodyCode, fieldErrors, raw);
208
221
  }
209
222
  };
210
223
 
@@ -825,9 +838,10 @@ async function updateForm(client, id, input) {
825
838
  }
826
839
 
827
840
  // src/methods/management/components.ts
828
- async function listComponents(client) {
841
+ async function listComponents(client, options) {
842
+ const query = options?.select ? `?select=${options.select}` : "";
829
843
  const res = await client.fetchJSON(
830
- client.url("/management/components"),
844
+ client.url(`/management/components${query}`),
831
845
  { method: "GET" }
832
846
  );
833
847
  return res.data;
@@ -1068,9 +1082,8 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
1068
1082
  updateForm(id, input) {
1069
1083
  return updateForm(this, id, input);
1070
1084
  }
1071
- // ── Components: discover + author reusable symbols ──
1072
- listComponents() {
1073
- return listComponents(this);
1085
+ listComponents(options) {
1086
+ return options?.select ? listComponents(this, { select: options.select }) : listComponents(this);
1074
1087
  }
1075
1088
  getComponent(id) {
1076
1089
  return getComponent(this, id);