@open-mercato/shared 0.5.1-develop.2762.90c271efe2 → 0.5.1-develop.2769.2495d0c533

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.
@@ -1,9 +1,9 @@
1
1
  var _a, _b;
2
2
  const CRUD_HTTP_ERROR_MARKER = /* @__PURE__ */ Symbol.for("@open-mercato/CrudHttpError");
3
3
  class CrudHttpError extends (_b = Error, _a = CRUD_HTTP_ERROR_MARKER, _b) {
4
- constructor(status, body) {
4
+ constructor(status, body, options) {
5
5
  const normalizedBody = typeof body === "string" ? { error: body } : body ?? {};
6
- super(typeof body === "string" ? body : normalizedBody.error ?? "Request failed");
6
+ super(typeof body === "string" ? body : normalizedBody.error ?? "Request failed", options);
7
7
  this[_a] = true;
8
8
  this.status = status;
9
9
  this.body = normalizedBody;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/crud/errors.ts"],
4
- "sourcesContent": ["// Use Symbol.for so the marker survives module duplication across bundle boundaries\n// (same behaviour as globalThis-based registries used for DI registrars)\nconst CRUD_HTTP_ERROR_MARKER = Symbol.for('@open-mercato/CrudHttpError')\n\nexport class CrudHttpError extends Error {\n readonly [CRUD_HTTP_ERROR_MARKER] = true\n status: number\n body: Record<string, any>\n\n constructor(status: number, body?: Record<string, any> | string) {\n const normalizedBody = typeof body === 'string' ? { error: body } : body ?? {}\n super(typeof body === 'string' ? body : normalizedBody.error ?? 'Request failed')\n this.status = status\n this.body = normalizedBody\n }\n}\n\n/**\n * Type-safe check for CrudHttpError that works across module/bundle boundaries.\n * Prefer this over `instanceof CrudHttpError` whenever the error may originate\n * from a different module bundle (e.g. enterprise packages, dynamic imports).\n */\nexport function isCrudHttpError(err: unknown): err is CrudHttpError {\n return !!err && typeof err === 'object' && (err as Record<symbol, unknown>)[CRUD_HTTP_ERROR_MARKER] === true\n}\n\nexport function badRequest(message: string): CrudHttpError {\n return new CrudHttpError(400, { error: message })\n}\n\nexport function forbidden(message = 'Forbidden'): CrudHttpError {\n return new CrudHttpError(403, { error: message })\n}\n\nexport function notFound(message = 'Not found'): CrudHttpError {\n return new CrudHttpError(404, { error: message })\n}\n\nexport function assertFound<T>(value: T | null | undefined, message: string): T {\n if (!value) throw notFound(message)\n return value\n}\n"],
5
- "mappings": "AAAA;AAEA,MAAM,yBAAyB,uBAAO,IAAI,6BAA6B;AAEhE,MAAM,uBAAsB,YACvB,6BADuB,IAAM;AAAA,EAKvC,YAAY,QAAgB,MAAqC;AAC/D,UAAM,iBAAiB,OAAO,SAAS,WAAW,EAAE,OAAO,KAAK,IAAI,QAAQ,CAAC;AAC7E,UAAM,OAAO,SAAS,WAAW,OAAO,eAAe,SAAS,gBAAgB;AANlF,SAAU,MAA0B;AAOlC,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAOO,SAAS,gBAAgB,KAAoC;AAClE,SAAO,CAAC,CAAC,OAAO,OAAO,QAAQ,YAAa,IAAgC,sBAAsB,MAAM;AAC1G;AAEO,SAAS,WAAW,SAAgC;AACzD,SAAO,IAAI,cAAc,KAAK,EAAE,OAAO,QAAQ,CAAC;AAClD;AAEO,SAAS,UAAU,UAAU,aAA4B;AAC9D,SAAO,IAAI,cAAc,KAAK,EAAE,OAAO,QAAQ,CAAC;AAClD;AAEO,SAAS,SAAS,UAAU,aAA4B;AAC7D,SAAO,IAAI,cAAc,KAAK,EAAE,OAAO,QAAQ,CAAC;AAClD;AAEO,SAAS,YAAe,OAA6B,SAAoB;AAC9E,MAAI,CAAC,MAAO,OAAM,SAAS,OAAO;AAClC,SAAO;AACT;",
4
+ "sourcesContent": ["// Use Symbol.for so the marker survives module duplication across bundle boundaries\n// (same behaviour as globalThis-based registries used for DI registrars)\nconst CRUD_HTTP_ERROR_MARKER = Symbol.for('@open-mercato/CrudHttpError')\n\nexport class CrudHttpError extends Error {\n readonly [CRUD_HTTP_ERROR_MARKER] = true\n status: number\n body: Record<string, any>\n\n constructor(\n status: number,\n body?: Record<string, any> | string,\n options?: { cause?: unknown },\n ) {\n const normalizedBody = typeof body === 'string' ? { error: body } : body ?? {}\n super(typeof body === 'string' ? body : normalizedBody.error ?? 'Request failed', options)\n this.status = status\n this.body = normalizedBody\n }\n}\n\n/**\n * Type-safe check for CrudHttpError that works across module/bundle boundaries.\n * Prefer this over `instanceof CrudHttpError` whenever the error may originate\n * from a different module bundle (e.g. enterprise packages, dynamic imports).\n */\nexport function isCrudHttpError(err: unknown): err is CrudHttpError {\n return !!err && typeof err === 'object' && (err as Record<symbol, unknown>)[CRUD_HTTP_ERROR_MARKER] === true\n}\n\nexport function badRequest(message: string): CrudHttpError {\n return new CrudHttpError(400, { error: message })\n}\n\nexport function forbidden(message = 'Forbidden'): CrudHttpError {\n return new CrudHttpError(403, { error: message })\n}\n\nexport function notFound(message = 'Not found'): CrudHttpError {\n return new CrudHttpError(404, { error: message })\n}\n\nexport function assertFound<T>(value: T | null | undefined, message: string): T {\n if (!value) throw notFound(message)\n return value\n}\n"],
5
+ "mappings": "AAAA;AAEA,MAAM,yBAAyB,uBAAO,IAAI,6BAA6B;AAEhE,MAAM,uBAAsB,YACvB,6BADuB,IAAM;AAAA,EAKvC,YACE,QACA,MACA,SACA;AACA,UAAM,iBAAiB,OAAO,SAAS,WAAW,EAAE,OAAO,KAAK,IAAI,QAAQ,CAAC;AAC7E,UAAM,OAAO,SAAS,WAAW,OAAO,eAAe,SAAS,kBAAkB,OAAO;AAV3F,SAAU,MAA0B;AAWlC,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAOO,SAAS,gBAAgB,KAAoC;AAClE,SAAO,CAAC,CAAC,OAAO,OAAO,QAAQ,YAAa,IAAgC,sBAAsB,MAAM;AAC1G;AAEO,SAAS,WAAW,SAAgC;AACzD,SAAO,IAAI,cAAc,KAAK,EAAE,OAAO,QAAQ,CAAC;AAClD;AAEO,SAAS,UAAU,UAAU,aAA4B;AAC9D,SAAO,IAAI,cAAc,KAAK,EAAE,OAAO,QAAQ,CAAC;AAClD;AAEO,SAAS,SAAS,UAAU,aAA4B;AAC7D,SAAO,IAAI,cAAc,KAAK,EAAE,OAAO,QAAQ,CAAC;AAClD;AAEO,SAAS,YAAe,OAA6B,SAAoB;AAC9E,MAAI,CAAC,MAAO,OAAM,SAAS,OAAO;AAClC,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- const APP_VERSION = "0.5.1-develop.2762.90c271efe2";
1
+ const APP_VERSION = "0.5.1-develop.2769.2495d0c533";
2
2
  const appVersion = APP_VERSION;
3
3
  export {
4
4
  APP_VERSION,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/version.ts"],
4
- "sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.5.1-develop.2762.90c271efe2'\nexport const appVersion = APP_VERSION\n"],
4
+ "sourcesContent": ["// Build-time generated version\nexport const APP_VERSION = '0.5.1-develop.2769.2495d0c533'\nexport const appVersion = APP_VERSION\n"],
5
5
  "mappings": "AACO,MAAM,cAAc;AACpB,MAAM,aAAa;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/shared",
3
- "version": "0.5.1-develop.2762.90c271efe2",
3
+ "version": "0.5.1-develop.2769.2495d0c533",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -92,7 +92,7 @@
92
92
  "@mikro-orm/core": "^7.0.10",
93
93
  "@mikro-orm/decorators": "^7.0.10",
94
94
  "@mikro-orm/postgresql": "^7.0.10",
95
- "@open-mercato/cache": "0.5.1-develop.2762.90c271efe2",
95
+ "@open-mercato/cache": "0.5.1-develop.2769.2495d0c533",
96
96
  "dotenv": "^17.4.2",
97
97
  "rate-limiter-flexible": "^11.0.1",
98
98
  "reflect-metadata": "^0.2.2",
@@ -0,0 +1,36 @@
1
+ import { CrudHttpError, isCrudHttpError } from '../errors'
2
+
3
+ describe('CrudHttpError', () => {
4
+ it('builds from string body', () => {
5
+ const err = new CrudHttpError(400, 'Bad thing')
6
+ expect(err.status).toBe(400)
7
+ expect(err.body).toEqual({ error: 'Bad thing' })
8
+ expect(err.message).toBe('Bad thing')
9
+ expect(isCrudHttpError(err)).toBe(true)
10
+ })
11
+
12
+ it('builds from object body', () => {
13
+ const err = new CrudHttpError(422, { error: 'nope', field: 'x' })
14
+ expect(err.body).toEqual({ error: 'nope', field: 'x' })
15
+ expect(err.message).toBe('nope')
16
+ })
17
+
18
+ it('forwards cause to Error constructor', () => {
19
+ const upstream = new Error('upstream boom')
20
+ const err = new CrudHttpError(502, { error: 'Upstream API error' }, { cause: upstream })
21
+ expect(err.cause).toBe(upstream)
22
+ expect(err.status).toBe(502)
23
+ expect(err.body).toEqual({ error: 'Upstream API error' })
24
+ })
25
+
26
+ it('accepts cause with string body', () => {
27
+ const upstream = new Error('root')
28
+ const err = new CrudHttpError(500, 'Failed', { cause: upstream })
29
+ expect(err.cause).toBe(upstream)
30
+ })
31
+
32
+ it('cause defaults to undefined when options omitted', () => {
33
+ const err = new CrudHttpError(400, 'x')
34
+ expect(err.cause).toBeUndefined()
35
+ })
36
+ })
@@ -7,9 +7,13 @@ export class CrudHttpError extends Error {
7
7
  status: number
8
8
  body: Record<string, any>
9
9
 
10
- constructor(status: number, body?: Record<string, any> | string) {
10
+ constructor(
11
+ status: number,
12
+ body?: Record<string, any> | string,
13
+ options?: { cause?: unknown },
14
+ ) {
11
15
  const normalizedBody = typeof body === 'string' ? { error: body } : body ?? {}
12
- super(typeof body === 'string' ? body : normalizedBody.error ?? 'Request failed')
16
+ super(typeof body === 'string' ? body : normalizedBody.error ?? 'Request failed', options)
13
17
  this.status = status
14
18
  this.body = normalizedBody
15
19
  }