@venizia/ignis-kernel 0.4.8-16 → 0.4.8-18
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,12 @@
|
|
|
1
|
+
import type { TJsonValue } from '@venizia/ignis-helpers/common';
|
|
1
2
|
import type { ApplicationError, TResponsedError } from '@venizia/ignis-helpers/core';
|
|
2
3
|
/**
|
|
3
4
|
* What an IGNIS server answers - `Content-Range`, the error envelope - read once, here, for every
|
|
4
5
|
* client of that server: the http connector, and a client that reads it without the connector.
|
|
5
6
|
*/
|
|
6
7
|
export declare class HttpResponseReader {
|
|
8
|
+
/** A content type that names JSON: `application/json`, `application/problem+json`, `application/ld+json`. */
|
|
9
|
+
static readonly JSON_CONTENT_TYPE_PATTERN: RegExp;
|
|
7
10
|
static isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
8
11
|
/** An empty string reads as absent, so a fallback still applies. */
|
|
9
12
|
static toText(value: unknown): string | undefined;
|
|
@@ -51,6 +54,33 @@ export declare class HttpResponseReader {
|
|
|
51
54
|
context: string;
|
|
52
55
|
rootKey?: string;
|
|
53
56
|
}): Promise<ApplicationError>;
|
|
57
|
+
/**
|
|
58
|
+
* The body as text: `''` for a 204 or an empty body. `response.json()` throws on those, and each client
|
|
59
|
+
* that reads a response has copied the guard.
|
|
60
|
+
*/
|
|
61
|
+
static readText(opts: {
|
|
62
|
+
response: Response;
|
|
63
|
+
}): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* The body of a success answer, by what it says it is: `null` for a 204 or an empty body, the parsed
|
|
66
|
+
* value when the content type names JSON (`application/json`, `application/problem+json`), the text itself
|
|
67
|
+
* for any other type (`text/plain`, `text/csv`). A body that claims JSON and is not is a `502` that names
|
|
68
|
+
* `context` (where it happened, e.g. `[Client][read] 200 | /tickets`), its size and its content type; its
|
|
69
|
+
* content stays out of the message, which a relaying server may pass to its own clients.
|
|
70
|
+
*/
|
|
71
|
+
static readBody(opts: {
|
|
72
|
+
response: Response;
|
|
73
|
+
context: string;
|
|
74
|
+
}): Promise<TJsonValue>;
|
|
75
|
+
/**
|
|
76
|
+
* The body as JSON whatever its content type says, `null` for a 204 or an empty body: for a route that
|
|
77
|
+
* answers JSON under a type a proxy rewrote. Errors as `readBody` does.
|
|
78
|
+
*/
|
|
79
|
+
static readJson(opts: {
|
|
80
|
+
response: Response;
|
|
81
|
+
context: string;
|
|
82
|
+
}): Promise<TJsonValue>;
|
|
83
|
+
private static parseJson;
|
|
54
84
|
/**
|
|
55
85
|
* A body the server marked with `x-response-extra` carries `extra` beside its rows. `body` is what
|
|
56
86
|
* the route answers without extras: the `{ count, data }` envelope when the count was asked for in
|
|
@@ -5,6 +5,8 @@ import { getError } from '@venizia/ignis-helpers/core';
|
|
|
5
5
|
* client of that server: the http connector, and a client that reads it without the connector.
|
|
6
6
|
*/
|
|
7
7
|
export class HttpResponseReader {
|
|
8
|
+
/** A content type that names JSON: `application/json`, `application/problem+json`, `application/ld+json`. */
|
|
9
|
+
static { this.JSON_CONTENT_TYPE_PATTERN = /json/i; }
|
|
8
10
|
static isPlainObject(value) {
|
|
9
11
|
return (!!value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype);
|
|
10
12
|
}
|
|
@@ -118,6 +120,57 @@ export class HttpResponseReader {
|
|
|
118
120
|
transform: ({ message }) => ({ ...message, text: displayText }),
|
|
119
121
|
});
|
|
120
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The body as text: `''` for a 204 or an empty body. `response.json()` throws on those, and each client
|
|
125
|
+
* that reads a response has copied the guard.
|
|
126
|
+
*/
|
|
127
|
+
static async readText(opts) {
|
|
128
|
+
const { response } = opts;
|
|
129
|
+
return response.status === HTTP.ResultCodes.RS_2.NoContent ? '' : response.text();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The body of a success answer, by what it says it is: `null` for a 204 or an empty body, the parsed
|
|
133
|
+
* value when the content type names JSON (`application/json`, `application/problem+json`), the text itself
|
|
134
|
+
* for any other type (`text/plain`, `text/csv`). A body that claims JSON and is not is a `502` that names
|
|
135
|
+
* `context` (where it happened, e.g. `[Client][read] 200 | /tickets`), its size and its content type; its
|
|
136
|
+
* content stays out of the message, which a relaying server may pass to its own clients.
|
|
137
|
+
*/
|
|
138
|
+
static async readBody(opts) {
|
|
139
|
+
const { response, context } = opts;
|
|
140
|
+
const text = await HttpResponseReader.readText({ response });
|
|
141
|
+
if (!text) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (!HttpResponseReader.JSON_CONTENT_TYPE_PATTERN.test(response.headers.get(HTTP.Headers.CONTENT_TYPE) ?? '')) {
|
|
145
|
+
return text;
|
|
146
|
+
}
|
|
147
|
+
return HttpResponseReader.parseJson({ text, response, context });
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The body as JSON whatever its content type says, `null` for a 204 or an empty body: for a route that
|
|
151
|
+
* answers JSON under a type a proxy rewrote. Errors as `readBody` does.
|
|
152
|
+
*/
|
|
153
|
+
static async readJson(opts) {
|
|
154
|
+
const { response, context } = opts;
|
|
155
|
+
const text = await HttpResponseReader.readText({ response });
|
|
156
|
+
if (!text) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return HttpResponseReader.parseJson({ text, response, context });
|
|
160
|
+
}
|
|
161
|
+
static parseJson(opts) {
|
|
162
|
+
const { text, response, context } = opts;
|
|
163
|
+
try {
|
|
164
|
+
return JSON.parse(text);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
const contentType = response.headers.get(HTTP.Headers.CONTENT_TYPE) ?? 'none';
|
|
168
|
+
throw getError({
|
|
169
|
+
statusCode: HTTP.ResultCodes.RS_5.BadGateway,
|
|
170
|
+
message: `${context} | The response body is not JSON (${text.length} chars, content-type: ${contentType})`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
121
174
|
/**
|
|
122
175
|
* A body the server marked with `x-response-extra` carries `extra` beside its rows. `body` is what
|
|
123
176
|
* the route answers without extras: the `{ count, data }` envelope when the count was asked for in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-reader.js","sourceRoot":"","sources":["../../../../../src/base/repositories/common/response-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC7B,MAAM,CAAC,aAAa,CAAC,KAAc;QACjC,OAAO,CACL,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS,CAC1F,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,MAAM,CAAC,MAAM,CAAC,KAAc;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAExB;QACC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAE7D,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAEpD,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,EA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S,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;SAChE,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,IAAsD;QAIrE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAE1D,IACE,CAAC,QAAQ;YACT,CAAC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC;YACvC,CAAC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAC7C,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEpC,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC;IACvF,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { ApplicationError, TResponsedError } from '@venizia/ignis-helpers/core';\n\n/**\n * What an IGNIS server answers - `Content-Range`, the error envelope - read once, here, for every\n * client of that server: the http connector, and a client that reads it without the connector.\n */\nexport class HttpResponseReader {\n static isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n !!value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype\n );\n }\n\n /** An empty string reads as absent, so a fallback still applies. */\n static toText(value: unknown): string | undefined {\n return typeof value === 'string' && value !== '' ? value : undefined;\n }\n\n /**\n * A `Content-Range` header as the IGNIS server writes it: `records 0-24/137` -> skip 0, total 137;\n * an empty page, `records *\\/137` -> total 137. Anything else, including an absent header or an\n * unknown total, is `undefined`.\n */\n static parseContentRange(opts: {\n header?: string | null;\n }): { skip?: number; total: number } | undefined {\n const { header } = opts;\n\n if (!header) {\n return undefined;\n }\n\n const range = header.match(/(\\d+)\\s*-\\s*(\\d+)\\s*\\/\\s*(\\d+)/);\n\n if (range) {\n return { skip: Number(range[1]), total: Number(range[3]) };\n }\n\n const unsatisfied = header.match(/\\*\\s*\\/\\s*(\\d+)/);\n\n if (unsatisfied) {\n return { total: Number(unsatisfied[1]) };\n }\n\n return undefined;\n }\n\n /**\n * The IGNIS error envelope - `{ message, statusCode, normalized: { text, code, args }, requestId,\n * extra, details }` - read off a parsed response body. A server configured with `error.rootKey`\n * wraps it under that key; pass the same `rootKey` to unwrap it. A body without that key, or with a\n * non-object under it (a proxy's `{ error: 'Bad Gateway' }`), is read as it stands.\n *\n * A body that is not a plain object yields `{}`; any other body yields its known fields, each\n * `undefined` when absent or mistyped. An empty string reads as absent.\n */\n static readErrorEnvelope(opts: { body: unknown; rootKey?: string }): TResponsedError {\n const { body, rootKey } = opts;\n\n const wrapped = rootKey && HttpResponseReader.isPlainObject(body) ? body[rootKey] : undefined;\n const envelope = HttpResponseReader.isPlainObject(wrapped) ? wrapped : body;\n\n if (!HttpResponseReader.isPlainObject(envelope)) {\n return {};\n }\n\n const { message, statusCode, normalized, requestId, extra, details } = envelope;\n const normalizedRecord = HttpResponseReader.isPlainObject(normalized) ? normalized : {};\n const { text, code, args } = normalizedRecord;\n\n return {\n message: HttpResponseReader.toText(message),\n statusCode: typeof statusCode === 'number' ? statusCode : undefined,\n normalized: {\n text: HttpResponseReader.toText(text),\n code: HttpResponseReader.toText(code),\n args: HttpResponseReader.isPlainObject(args) ? { ...args } : undefined,\n },\n requestId: HttpResponseReader.toText(requestId),\n extra: HttpResponseReader.isPlainObject(extra) ? { ...extra } : undefined,\n details: HttpResponseReader.isPlainObject(details) ? { ...details } : undefined,\n };\n }\n\n /** A failed response's envelope. A body that is not JSON yields `{}`, and the status alone still describes it. */\n static async readError(opts: { response: Response; rootKey?: string }): Promise<TResponsedError> {\n let text;\n\n try {\n const result = await opts.response.text();\n text = result;\n // eslint-disable-next-line venizia/no-silent-catch -- an unreadable body is read as no text; the status alone still describes the failure\n } catch {\n text = '';\n }\n\n let body: unknown;\n\n try {\n body = text ? JSON.parse(text) : undefined;\n // eslint-disable-next-line venizia/no-silent-catch -- a body that is not JSON yields `{}`; the status alone still describes the failure\n } catch {\n return {};\n }\n\n return HttpResponseReader.readErrorEnvelope({ body, rootKey: opts.rootKey });\n }\n\n /**\n * A failed response as the error the server threw: its status, code, args and text, and its\n * `extra` with the `requestId` added. `message` is `context` plus the server's text, for logs;\n * `normalized.text` stays the server's, for display - `HTTP <status>` when the server sent none.\n * `cause` is the server's `details.cause` - a 422's per-field issues, `{ path, message, code }`.\n *\n * `requestId` names the request this client made. A relaying server's `extra` carries the id of\n * the request it made upstream: it joins `upstreamRequestIds`, nearest first, at every hop.\n */\n static async toApplicationError(opts: {\n response: Response;\n /** Where it failed, for logs - e.g. `[HttpDataSource][read] 404 | /tickets`. */\n context: string;\n rootKey?: string;\n }): Promise<ApplicationError> {\n const { response, context, rootKey } = opts;\n const server = await HttpResponseReader.readError({ response, rootKey });\n const serverText = server.normalized?.text ?? server.message;\n const displayText = serverText ?? `HTTP ${response.status}`;\n\n const extra: Record<string, unknown> = { ...server.extra };\n\n if (server.requestId) {\n const upstreamRequestId = extra.requestId;\n extra.requestId = server.requestId;\n\n if (upstreamRequestId !== undefined && upstreamRequestId !== server.requestId) {\n const known = Array.isArray(extra.upstreamRequestIds) ? extra.upstreamRequestIds : [];\n extra.upstreamRequestIds = [upstreamRequestId, ...known];\n }\n }\n\n return getError({\n statusCode: response.status,\n message: serverText ? `${context} | ${serverText}` : context,\n messageCode: server.normalized?.code,\n messageArgs: server.normalized?.args,\n extra: Object.keys(extra).length > 0 ? extra : undefined,\n cause: server.details?.cause,\n transform: ({ message }) => ({ ...message, text: displayText }),\n });\n }\n\n /**\n * A body the server marked with `x-response-extra` carries `extra` beside its rows. `body` is what\n * the route answers without extras: the `{ count, data }` envelope when the count was asked for in\n * the body, the rows otherwise. Any other body is returned as it stands - an unmarked object is\n * never unwrapped, so a row that has `data` and `extra` columns of its own is never misread.\n */\n static readExtra(opts: { body: unknown; headers: Pick<Headers, 'has'> }): {\n body: unknown;\n extra?: Record<string, unknown>;\n } {\n const { body, headers } = opts;\n const isMarked = headers.has(HTTP.Headers.RESPONSE_EXTRA);\n\n if (\n !isMarked ||\n !HttpResponseReader.isPlainObject(body) ||\n !HttpResponseReader.isPlainObject(body.extra)\n ) {\n return { body };\n }\n\n const { extra, ...envelope } = body;\n\n return { body: 'count' in envelope ? envelope : envelope.data, extra: { ...extra } };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"response-reader.js","sourceRoot":"","sources":["../../../../../src/base/repositories/common/response-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC7B,6GAA6G;aAC7F,8BAAyB,GAAG,OAAO,CAAC;IAEpD,MAAM,CAAC,aAAa,CAAC,KAAc;QACjC,OAAO,CACL,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS,CAC1F,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,MAAM,CAAC,MAAM,CAAC,KAAc;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAExB;QACC,MAAM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AM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAE1D,IACE,CAAC,QAAQ;YACT,CAAC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC;YACvC,CAAC,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAC7C,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEpC,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC;IACvF,CAAC","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport type { TJsonValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { ApplicationError, TResponsedError } from '@venizia/ignis-helpers/core';\n\n/**\n * What an IGNIS server answers - `Content-Range`, the error envelope - read once, here, for every\n * client of that server: the http connector, and a client that reads it without the connector.\n */\nexport class HttpResponseReader {\n /** A content type that names JSON: `application/json`, `application/problem+json`, `application/ld+json`. */\n static readonly JSON_CONTENT_TYPE_PATTERN = /json/i;\n\n static isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n !!value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype\n );\n }\n\n /** An empty string reads as absent, so a fallback still applies. */\n static toText(value: unknown): string | undefined {\n return typeof value === 'string' && value !== '' ? value : undefined;\n }\n\n /**\n * A `Content-Range` header as the IGNIS server writes it: `records 0-24/137` -> skip 0, total 137;\n * an empty page, `records *\\/137` -> total 137. Anything else, including an absent header or an\n * unknown total, is `undefined`.\n */\n static parseContentRange(opts: {\n header?: string | null;\n }): { skip?: number; total: number } | undefined {\n const { header } = opts;\n\n if (!header) {\n return undefined;\n }\n\n const range = header.match(/(\\d+)\\s*-\\s*(\\d+)\\s*\\/\\s*(\\d+)/);\n\n if (range) {\n return { skip: Number(range[1]), total: Number(range[3]) };\n }\n\n const unsatisfied = header.match(/\\*\\s*\\/\\s*(\\d+)/);\n\n if (unsatisfied) {\n return { total: Number(unsatisfied[1]) };\n }\n\n return undefined;\n }\n\n /**\n * The IGNIS error envelope - `{ message, statusCode, normalized: { text, code, args }, requestId,\n * extra, details }` - read off a parsed response body. A server configured with `error.rootKey`\n * wraps it under that key; pass the same `rootKey` to unwrap it. A body without that key, or with a\n * non-object under it (a proxy's `{ error: 'Bad Gateway' }`), is read as it stands.\n *\n * A body that is not a plain object yields `{}`; any other body yields its known fields, each\n * `undefined` when absent or mistyped. An empty string reads as absent.\n */\n static readErrorEnvelope(opts: { body: unknown; rootKey?: string }): TResponsedError {\n const { body, rootKey } = opts;\n\n const wrapped = rootKey && HttpResponseReader.isPlainObject(body) ? body[rootKey] : undefined;\n const envelope = HttpResponseReader.isPlainObject(wrapped) ? wrapped : body;\n\n if (!HttpResponseReader.isPlainObject(envelope)) {\n return {};\n }\n\n const { message, statusCode, normalized, requestId, extra, details } = envelope;\n const normalizedRecord = HttpResponseReader.isPlainObject(normalized) ? normalized : {};\n const { text, code, args } = normalizedRecord;\n\n return {\n message: HttpResponseReader.toText(message),\n statusCode: typeof statusCode === 'number' ? statusCode : undefined,\n normalized: {\n text: HttpResponseReader.toText(text),\n code: HttpResponseReader.toText(code),\n args: HttpResponseReader.isPlainObject(args) ? { ...args } : undefined,\n },\n requestId: HttpResponseReader.toText(requestId),\n extra: HttpResponseReader.isPlainObject(extra) ? { ...extra } : undefined,\n details: HttpResponseReader.isPlainObject(details) ? { ...details } : undefined,\n };\n }\n\n /** A failed response's envelope. A body that is not JSON yields `{}`, and the status alone still describes it. */\n static async readError(opts: { response: Response; rootKey?: string }): Promise<TResponsedError> {\n let text;\n\n try {\n const result = await opts.response.text();\n text = result;\n // eslint-disable-next-line venizia/no-silent-catch -- an unreadable body is read as no text; the status alone still describes the failure\n } catch {\n text = '';\n }\n\n let body: unknown;\n\n try {\n body = text ? JSON.parse(text) : undefined;\n // eslint-disable-next-line venizia/no-silent-catch -- a body that is not JSON yields `{}`; the status alone still describes the failure\n } catch {\n return {};\n }\n\n return HttpResponseReader.readErrorEnvelope({ body, rootKey: opts.rootKey });\n }\n\n /**\n * A failed response as the error the server threw: its status, code, args and text, and its\n * `extra` with the `requestId` added. `message` is `context` plus the server's text, for logs;\n * `normalized.text` stays the server's, for display - `HTTP <status>` when the server sent none.\n * `cause` is the server's `details.cause` - a 422's per-field issues, `{ path, message, code }`.\n *\n * `requestId` names the request this client made. A relaying server's `extra` carries the id of\n * the request it made upstream: it joins `upstreamRequestIds`, nearest first, at every hop.\n */\n static async toApplicationError(opts: {\n response: Response;\n /** Where it failed, for logs - e.g. `[HttpDataSource][read] 404 | /tickets`. */\n context: string;\n rootKey?: string;\n }): Promise<ApplicationError> {\n const { response, context, rootKey } = opts;\n const server = await HttpResponseReader.readError({ response, rootKey });\n const serverText = server.normalized?.text ?? server.message;\n const displayText = serverText ?? `HTTP ${response.status}`;\n\n const extra: Record<string, unknown> = { ...server.extra };\n\n if (server.requestId) {\n const upstreamRequestId = extra.requestId;\n extra.requestId = server.requestId;\n\n if (upstreamRequestId !== undefined && upstreamRequestId !== server.requestId) {\n const known = Array.isArray(extra.upstreamRequestIds) ? extra.upstreamRequestIds : [];\n extra.upstreamRequestIds = [upstreamRequestId, ...known];\n }\n }\n\n return getError({\n statusCode: response.status,\n message: serverText ? `${context} | ${serverText}` : context,\n messageCode: server.normalized?.code,\n messageArgs: server.normalized?.args,\n extra: Object.keys(extra).length > 0 ? extra : undefined,\n cause: server.details?.cause,\n transform: ({ message }) => ({ ...message, text: displayText }),\n });\n }\n\n /**\n * The body as text: `''` for a 204 or an empty body. `response.json()` throws on those, and each client\n * that reads a response has copied the guard.\n */\n static async readText(opts: { response: Response }): Promise<string> {\n const { response } = opts;\n\n return response.status === HTTP.ResultCodes.RS_2.NoContent ? '' : response.text();\n }\n\n /**\n * The body of a success answer, by what it says it is: `null` for a 204 or an empty body, the parsed\n * value when the content type names JSON (`application/json`, `application/problem+json`), the text itself\n * for any other type (`text/plain`, `text/csv`). A body that claims JSON and is not is a `502` that names\n * `context` (where it happened, e.g. `[Client][read] 200 | /tickets`), its size and its content type; its\n * content stays out of the message, which a relaying server may pass to its own clients.\n */\n static async readBody(opts: { response: Response; context: string }): Promise<TJsonValue> {\n const { response, context } = opts;\n const text = await HttpResponseReader.readText({ response });\n\n if (!text) {\n return null;\n }\n\n if (\n !HttpResponseReader.JSON_CONTENT_TYPE_PATTERN.test(\n response.headers.get(HTTP.Headers.CONTENT_TYPE) ?? '',\n )\n ) {\n return text;\n }\n\n return HttpResponseReader.parseJson({ text, response, context });\n }\n\n /**\n * The body as JSON whatever its content type says, `null` for a 204 or an empty body: for a route that\n * answers JSON under a type a proxy rewrote. Errors as `readBody` does.\n */\n static async readJson(opts: { response: Response; context: string }): Promise<TJsonValue> {\n const { response, context } = opts;\n const text = await HttpResponseReader.readText({ response });\n\n if (!text) {\n return null;\n }\n\n return HttpResponseReader.parseJson({ text, response, context });\n }\n\n private static parseJson(opts: {\n text: string;\n response: Response;\n context: string;\n }): TJsonValue {\n const { text, response, context } = opts;\n\n try {\n return JSON.parse(text);\n } catch {\n const contentType = response.headers.get(HTTP.Headers.CONTENT_TYPE) ?? 'none';\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.BadGateway,\n message: `${context} | The response body is not JSON (${text.length} chars, content-type: ${contentType})`,\n });\n }\n }\n\n /**\n * A body the server marked with `x-response-extra` carries `extra` beside its rows. `body` is what\n * the route answers without extras: the `{ count, data }` envelope when the count was asked for in\n * the body, the rows otherwise. Any other body is returned as it stands - an unmarked object is\n * never unwrapped, so a row that has `data` and `extra` columns of its own is never misread.\n */\n static readExtra(opts: { body: unknown; headers: Pick<Headers, 'has'> }): {\n body: unknown;\n extra?: Record<string, unknown>;\n } {\n const { body, headers } = opts;\n const isMarked = headers.has(HTTP.Headers.RESPONSE_EXTRA);\n\n if (\n !isMarked ||\n !HttpResponseReader.isPlainObject(body) ||\n !HttpResponseReader.isPlainObject(body.extra)\n ) {\n return { body };\n }\n\n const { extra, ...envelope } = body;\n\n return { body: 'count' in envelope ? envelope : envelope.data, extra: { ...extra } };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-kernel",
|
|
3
|
-
"version": "0.4.8-
|
|
3
|
+
"version": "0.4.8-18",
|
|
4
4
|
"description": "Browser-pure kernel of the IGNIS framework: dependency injection, lifecycle, REST controllers, repository and datasource abstractions, and the authentication and authorization seams. No node builtin and no server-only peer, so the same kernel serves a Bun server and a browser Worker.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@venizia/ignis-filter": "0.4.7-
|
|
77
|
-
"@venizia/ignis-helpers": "0.4.8-
|
|
76
|
+
"@venizia/ignis-filter": "0.4.7-7",
|
|
77
|
+
"@venizia/ignis-helpers": "0.4.8-15",
|
|
78
78
|
"@venizia/ignis-inversion": "0.4.7-5",
|
|
79
79
|
"reflect-metadata": "^0.2.2"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/bun": "^1.4.3",
|
|
83
|
-
"@venizia/dev-configs": "0.4.8-
|
|
83
|
+
"@venizia/dev-configs": "0.4.8-11",
|
|
84
84
|
"casbin": "^5.51.1",
|
|
85
85
|
"eslint": "^10.13.0",
|
|
86
86
|
"oxlint": "1.89.0",
|