@baijimu/cmodel 1.1.2 → 1.1.4

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Strict TypeScript types and parser for Baijimu CModel Error Contract `1.0.0`.
4
4
 
5
5
  ```bash
6
- npm install @baijimu/cmodel@1.1.2
6
+ npm install @baijimu/cmodel@1.1.4
7
7
  ```
8
8
 
9
9
  ```ts
@@ -12,4 +12,10 @@ import { parseCModelResponse } from "@baijimu/cmodel";
12
12
  const response = parseCModelResponse(httpStatus, body, (value) => value);
13
13
  ```
14
14
 
15
+ CModel producers return HTTP `200` for both success and business failure. Consumers determine the
16
+ business outcome only from `errorCode`; non-zero values are failures. The parser temporarily accepts
17
+ legacy non-`200` failure envelopes so services can roll forward without an atomic fleet deployment.
18
+
19
+ An absent `contractVersion` is interpreted as CModel Error Contract `1.0.0`. Explicit versions are validated strictly and unsupported versions are rejected.
20
+
15
21
  The public package contains only the protocol types and validation logic. It does not include Baijimu's internal service catalog or internal data models. See <https://docs.baijimu.com/integration/cmodel-error-model/>.
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,YAAY,CAAC;AAIpB,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;AAEhE,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAwCnB"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,YAAY,CAAC;AAIpB,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;AAEhE,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAoCnB"}
package/dist/parser.js CHANGED
@@ -11,9 +11,9 @@ export class CModelContractError extends Error {
11
11
  export function parseCModelResponse(httpStatus, input, parseData) {
12
12
  const envelope = envelopeAt(input, "$");
13
13
  requiredKeys(envelope, "$", ["errorCode", "data"]);
14
- const contractVersion = envelope.contractVersion === undefined
15
- ? CONTRACT_VERSION
16
- : stringAt(envelope.contractVersion, "$.contractVersion", 1, 64);
14
+ const contractVersion = "contractVersion" in envelope
15
+ ? stringAt(envelope.contractVersion, "$.contractVersion", 1, 64)
16
+ : CONTRACT_VERSION;
17
17
  if (contractVersion !== CONTRACT_VERSION) {
18
18
  fail("$.contractVersion", `unsupported contract version ${contractVersion}`);
19
19
  }
@@ -21,13 +21,12 @@ export function parseCModelResponse(httpStatus, input, parseData) {
21
21
  if (!codePattern.test(errorCode)) {
22
22
  fail("$.errorCode", "must be 0 or upper snake case");
23
23
  }
24
- const httpSuccess = httpStatus >= 200 && httpStatus < 300;
25
- if (httpStatus === 204) {
26
- fail("$httpStatus", "CModel responses cannot use 204 No Content");
24
+ if (httpStatus !== 200 && (httpStatus < 400 || httpStatus > 599)) {
25
+ fail("$httpStatus", "a CModel response must use HTTP 200; only legacy 4xx/5xx failures are accepted during migration");
27
26
  }
28
27
  if (errorCode === "0") {
29
- if (!httpSuccess) {
30
- fail("$httpStatus", "non-2xx status cannot carry a success envelope");
28
+ if (httpStatus !== 200) {
29
+ fail("$httpStatus", "a CModel success response must use HTTP 200");
31
30
  }
32
31
  const data = envelope.data === null ? null : parseData(envelope.data, "$.data");
33
32
  return {
@@ -36,9 +35,6 @@ export function parseCModelResponse(httpStatus, input, parseData) {
36
35
  data,
37
36
  };
38
37
  }
39
- if (httpSuccess) {
40
- fail("$httpStatus", "2xx status cannot carry a failure envelope");
41
- }
42
38
  if (envelope.data !== null) {
43
39
  fail("$.data", "failure response data must be null");
44
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baijimu/cmodel",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Strict TypeScript parser and types for the Baijimu CModel Error Contract",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",