@astram/guard 0.33.0 → 0.34.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.
@@ -9,6 +9,7 @@
9
9
  * AuthorizationDeniedError (incl. ADR-0034 `create_outside_write_scope`) → 403
10
10
  * ValidationError → 400
11
11
  * EngineUnavailableError → 503
12
+ * UniqueConflictError (GAPS #58) → 409 `unique_conflict`
12
13
  *
13
14
  * with FIXED, id-free messages (ADR-0012): the engine's own message carries reason codes, record
14
15
  * ids and detail meant for logs, never for clients. There is deliberately no 404 mapping: the
@@ -28,13 +29,23 @@
28
29
  * structural match also keeps working when a consumer's tree holds two copies of
29
30
  * `@astram/engine` (version skew), where `instanceof` silently fails and the 500 returns. An
30
31
  * error matches only when ALL hold: it is an `Error`, its prototype chain contains a class named
31
- * `EngineError` (the engine's base), its `name` is one of the three classes above (the engine
32
- * sets `name = new.target.name`), and it carries that class's field (`reason` / `field`). A
32
+ * `EngineError` (the engine's base), its `name` is one of the four classes above (the engine
33
+ * sets `name = new.target.name`), and it carries that class's field (`reason` / `field` /
34
+ * `typeKey`). A
33
35
  * third-party error that merely shares a name is not mapped.
34
36
  */
35
37
  import { type ArgumentsHost } from '@nestjs/common';
36
38
  import { BaseExceptionFilter } from '@nestjs/core';
37
- type EngineErrorKind = 'denied' | 'invalid' | 'unavailable';
39
+ type EngineErrorKind = 'denied' | 'invalid' | 'unavailable' | 'conflict';
40
+ /**
41
+ * GAPS #58 (SPEC `docs/features/unique-conflict-error/SPEC.md` §5 D, decision Q1): the fixed 409
42
+ * body for `UniqueConflictError`. No index name, type key or value: those stay server-side.
43
+ */
44
+ export declare const UNIQUE_CONFLICT_BODY: {
45
+ readonly statusCode: 409;
46
+ readonly code: "unique_conflict";
47
+ readonly message: "This record conflicts with an existing one.";
48
+ };
38
49
  /** Classify an engine error this filter maps, or `null` for anything else. */
39
50
  export declare function classifyEngineError(err: unknown): EngineErrorKind | null;
40
51
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"engine-error.filter.d.ts","sourceRoot":"","sources":["../../src/enforcement/engine-error.filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,KAAK,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,CAAC;AAa5D,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAaxE;AAED;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAGrD;AAKD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAsBvD;AAED,+FAA+F;AAC/F,qBACa,iBAAkB,SAAQ,mBAAmB;IAC/C,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;CAG9D"}
1
+ {"version":3,"file":"engine-error.filter.d.ts","sourceRoot":"","sources":["../../src/enforcement/engine-error.filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,EAOL,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,KAAK,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAC;AAaX,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAexE;AAED;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAGrD;AAKD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAwBvD;AAED,+FAA+F;AAC/F,qBACa,iBAAkB,SAAQ,mBAAmB;IAC/C,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;CAG9D"}
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.EngineErrorFilter = exports.EngineHttpMappableError = void 0;
9
+ exports.EngineErrorFilter = exports.EngineHttpMappableError = exports.UNIQUE_CONFLICT_BODY = void 0;
10
10
  exports.classifyEngineError = classifyEngineError;
11
11
  exports.toEngineHttpError = toEngineHttpError;
12
12
  /**
@@ -20,6 +20,7 @@ exports.toEngineHttpError = toEngineHttpError;
20
20
  * AuthorizationDeniedError (incl. ADR-0034 `create_outside_write_scope`) → 403
21
21
  * ValidationError → 400
22
22
  * EngineUnavailableError → 503
23
+ * UniqueConflictError (GAPS #58) → 409 `unique_conflict`
23
24
  *
24
25
  * with FIXED, id-free messages (ADR-0012): the engine's own message carries reason codes, record
25
26
  * ids and detail meant for logs, never for clients. There is deliberately no 404 mapping: the
@@ -39,12 +40,22 @@ exports.toEngineHttpError = toEngineHttpError;
39
40
  * structural match also keeps working when a consumer's tree holds two copies of
40
41
  * `@astram/engine` (version skew), where `instanceof` silently fails and the 500 returns. An
41
42
  * error matches only when ALL hold: it is an `Error`, its prototype chain contains a class named
42
- * `EngineError` (the engine's base), its `name` is one of the three classes above (the engine
43
- * sets `name = new.target.name`), and it carries that class's field (`reason` / `field`). A
43
+ * `EngineError` (the engine's base), its `name` is one of the four classes above (the engine
44
+ * sets `name = new.target.name`), and it carries that class's field (`reason` / `field` /
45
+ * `typeKey`). A
44
46
  * third-party error that merely shares a name is not mapped.
45
47
  */
46
48
  const common_1 = require("@nestjs/common");
47
49
  const core_1 = require("@nestjs/core");
50
+ /**
51
+ * GAPS #58 (SPEC `docs/features/unique-conflict-error/SPEC.md` §5 D, decision Q1): the fixed 409
52
+ * body for `UniqueConflictError`. No index name, type key or value: those stay server-side.
53
+ */
54
+ exports.UNIQUE_CONFLICT_BODY = {
55
+ statusCode: 409,
56
+ code: 'unique_conflict',
57
+ message: 'This record conflicts with an existing one.',
58
+ };
48
59
  /** True when `err`'s prototype chain contains the engine's `EngineError` base class. */
49
60
  function isEngineFamily(err) {
50
61
  let proto = Object.getPrototypeOf(err);
@@ -64,6 +75,8 @@ function classifyEngineError(err) {
64
75
  switch (err.name) {
65
76
  case 'AuthorizationDeniedError':
66
77
  return typeof fields.reason === 'string' ? 'denied' : null;
78
+ case 'UniqueConflictError':
79
+ return typeof fields.typeKey === 'string' ? 'conflict' : null;
67
80
  case 'ValidationError':
68
81
  return typeof fields.field === 'string' ? 'invalid' : null;
69
82
  case 'EngineUnavailableError':
@@ -102,6 +115,8 @@ function toEngineHttpError(err) {
102
115
  }
103
116
  case 'unavailable':
104
117
  return new common_1.ServiceUnavailableException('This operation is temporarily unavailable. Try again.');
118
+ case 'conflict':
119
+ return new common_1.ConflictException({ ...exports.UNIQUE_CONFLICT_BODY });
105
120
  default:
106
121
  return err;
107
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astram/guard",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "license": "MIT",
5
5
  "description": "Astram framework — the enforcement guard + real-world adapters (the 'hands'). One global deny-by-default gate every request passes through (ADR-0002), classification decorators, boot-pool assertion (ADR-0018), the forRoot() registration seam, and the DB/Redis/crypto adapters that connect the sealed core to a real backend. Depends on @astram/core (ADR-0003, ADR-0023).",
6
6
  "type": "commonjs",
@@ -37,7 +37,7 @@
37
37
  "ioredis": "^5.4.1",
38
38
  "mariadb": "^3.5.4",
39
39
  "@astram/core": "1.19.0",
40
- "@astram/engine": "0.19.0"
40
+ "@astram/engine": "0.20.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@nestjs/common": "^11",
@@ -45,7 +45,7 @@
45
45
  "@nestjs/platform-express": "^11",
46
46
  "reflect-metadata": "^0.2",
47
47
  "rxjs": "^7",
48
- "@astram/messaging": "^0.1.21"
48
+ "@astram/messaging": "^0.1.22"
49
49
  },
50
50
  "peerDependenciesMeta": {
51
51
  "@astram/messaging": {
@@ -68,7 +68,7 @@
68
68
  "typescript": "^5.7.0",
69
69
  "unplugin-swc": "^1.5.1",
70
70
  "vitest": "^2.1.8",
71
- "@astram/messaging": "0.1.21"
71
+ "@astram/messaging": "0.1.22"
72
72
  },
73
73
  "repository": {
74
74
  "type": "git",