@moonbase.sh/storefront-api 0.1.121 → 0.1.123

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
@@ -239,13 +239,18 @@ var NotFoundError = class extends Error {
239
239
  }
240
240
  };
241
241
  var MoonbaseError = class extends Error {
242
- constructor(title, detail, status) {
242
+ constructor(title, detail, status, errors) {
243
243
  super();
244
244
  this.title = title;
245
245
  this.detail = detail;
246
246
  this.status = status;
247
+ this.errors = errors;
247
248
  this.name = "MoonbaseError";
248
- this.message = detail != null ? detail : title;
249
+ if (errors && Object.values(errors).length === 1) {
250
+ this.message = Object.values(errors)[0];
251
+ } else {
252
+ this.message = detail != null ? detail : title;
253
+ }
249
254
  }
250
255
  };
251
256
 
@@ -254,8 +259,17 @@ var problemDetailsSchema = import_zod6.z.object({
254
259
  type: import_zod6.z.string(),
255
260
  title: import_zod6.z.string(),
256
261
  detail: import_zod6.z.string().optional(),
257
- status: import_zod6.z.number()
262
+ status: import_zod6.z.number(),
263
+ errors: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.string().array()).optional()
258
264
  });
265
+ function camelCase(str) {
266
+ return str.split(".").map((word, index) => {
267
+ let [firstLetter, ...restOfLetters] = word;
268
+ firstLetter = index !== 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
269
+ restOfLetters = [restOfLetters.join("").toLowerCase()];
270
+ return firstLetter + restOfLetters[0];
271
+ }).join("");
272
+ }
259
273
  async function handleResponseProblem(response) {
260
274
  if (response.status === 404)
261
275
  throw new NotFoundError();
@@ -270,7 +284,12 @@ async function handleResponseProblem(response) {
270
284
  } catch (e) {
271
285
  throw new Error("An unknown problem occurred");
272
286
  }
273
- throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
287
+ throw new MoonbaseError(
288
+ problemDetails.title,
289
+ problemDetails.detail,
290
+ problemDetails.status,
291
+ problemDetails.errors ? Object.fromEntries(Object.entries(problemDetails.errors).map(([field, errors]) => [camelCase(field), errors.join(", ")])) : void 0
292
+ );
274
293
  }
275
294
 
276
295
  // src/identity/schemas.ts
package/dist/index.d.cts CHANGED
@@ -13149,7 +13149,8 @@ declare class MoonbaseError extends Error {
13149
13149
  readonly title: string;
13150
13150
  readonly detail: string | undefined;
13151
13151
  readonly status: number;
13152
- constructor(title: string, detail: string | undefined, status: number);
13152
+ readonly errors: Record<string, string> | undefined;
13153
+ constructor(title: string, detail: string | undefined, status: number, errors: Record<string, string> | undefined);
13153
13154
  }
13154
13155
 
13155
13156
  interface MoonbaseConfiguration {
package/dist/index.d.ts CHANGED
@@ -13149,7 +13149,8 @@ declare class MoonbaseError extends Error {
13149
13149
  readonly title: string;
13150
13150
  readonly detail: string | undefined;
13151
13151
  readonly status: number;
13152
- constructor(title: string, detail: string | undefined, status: number);
13152
+ readonly errors: Record<string, string> | undefined;
13153
+ constructor(title: string, detail: string | undefined, status: number, errors: Record<string, string> | undefined);
13153
13154
  }
13154
13155
 
13155
13156
  interface MoonbaseConfiguration {
package/dist/index.js CHANGED
@@ -192,13 +192,18 @@ var NotFoundError = class extends Error {
192
192
  }
193
193
  };
194
194
  var MoonbaseError = class extends Error {
195
- constructor(title, detail, status) {
195
+ constructor(title, detail, status, errors) {
196
196
  super();
197
197
  this.title = title;
198
198
  this.detail = detail;
199
199
  this.status = status;
200
+ this.errors = errors;
200
201
  this.name = "MoonbaseError";
201
- this.message = detail != null ? detail : title;
202
+ if (errors && Object.values(errors).length === 1) {
203
+ this.message = Object.values(errors)[0];
204
+ } else {
205
+ this.message = detail != null ? detail : title;
206
+ }
202
207
  }
203
208
  };
204
209
 
@@ -207,8 +212,17 @@ var problemDetailsSchema = z6.object({
207
212
  type: z6.string(),
208
213
  title: z6.string(),
209
214
  detail: z6.string().optional(),
210
- status: z6.number()
215
+ status: z6.number(),
216
+ errors: z6.record(z6.string(), z6.string().array()).optional()
211
217
  });
218
+ function camelCase(str) {
219
+ return str.split(".").map((word, index) => {
220
+ let [firstLetter, ...restOfLetters] = word;
221
+ firstLetter = index !== 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
222
+ restOfLetters = [restOfLetters.join("").toLowerCase()];
223
+ return firstLetter + restOfLetters[0];
224
+ }).join("");
225
+ }
212
226
  async function handleResponseProblem(response) {
213
227
  if (response.status === 404)
214
228
  throw new NotFoundError();
@@ -223,7 +237,12 @@ async function handleResponseProblem(response) {
223
237
  } catch (e) {
224
238
  throw new Error("An unknown problem occurred");
225
239
  }
226
- throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
240
+ throw new MoonbaseError(
241
+ problemDetails.title,
242
+ problemDetails.detail,
243
+ problemDetails.status,
244
+ problemDetails.errors ? Object.fromEntries(Object.entries(problemDetails.errors).map(([field, errors]) => [camelCase(field), errors.join(", ")])) : void 0
245
+ );
227
246
  }
228
247
 
229
248
  // src/identity/schemas.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.1.121",
4
+ "version": "0.1.123",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",