@baijimu/cmodel 1.1.3 → 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 +5 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +4 -8
- package/package.json +1 -1
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.
|
|
6
|
+
npm install @baijimu/cmodel@1.1.4
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```ts
|
|
@@ -12,6 +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
|
+
|
|
15
19
|
An absent `contractVersion` is interpreted as CModel Error Contract `1.0.0`. Explicit versions are validated strictly and unsupported versions are rejected.
|
|
16
20
|
|
|
17
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/>.
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
@@ -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
|
-
|
|
25
|
-
|
|
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 (
|
|
30
|
-
fail("$httpStatus", "
|
|
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
|
}
|