@smuzi/logger-ui 0.0.5 → 0.0.6
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/build/handlers.js +6 -59
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -1
- package/package.json +2 -2
package/build/handlers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { asObject, asString, HttpResponse, ResponseHttpHeaders, Some } from "@smuzi/std";
|
|
3
|
-
import {
|
|
3
|
+
import { logIdFromPath, logRetryAction as loggerLogRetryAction, logsQueryAction as loggerLogsQueryAction, } from "@smuzi/logger";
|
|
4
4
|
// Resolves to <package>/build/ui both from src/ (workspace) and from build/ (published).
|
|
5
5
|
const UI_DIR = new URL("../build/ui/", import.meta.url);
|
|
6
6
|
export var UiAsset;
|
|
@@ -44,6 +44,9 @@ async function htmlPageResponse(file, base_path) {
|
|
|
44
44
|
}
|
|
45
45
|
return textResponse(html.replaceAll("{{base}}", escapeHtmlAttribute(base_path)), "text/html; charset=utf-8");
|
|
46
46
|
}
|
|
47
|
+
function unauthorizedResponse() {
|
|
48
|
+
return HttpResponse.asJson({ error: "Unauthorized" }, 401);
|
|
49
|
+
}
|
|
47
50
|
function authErrorResponse(message) {
|
|
48
51
|
return HttpResponse.asJson({ error: message }, 500);
|
|
49
52
|
}
|
|
@@ -108,64 +111,8 @@ export function uiAssetAction(asset) {
|
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
113
|
export function logsQueryAction(auth, reader) {
|
|
111
|
-
return authenticated(auth,
|
|
112
|
-
const body = await context.request.body();
|
|
113
|
-
if (body.isErr()) {
|
|
114
|
-
return HttpResponse.asJson({ error: "Unable to read request body" }, 400);
|
|
115
|
-
}
|
|
116
|
-
const query = parseLogsQuery(body.unwrap());
|
|
117
|
-
if (query.isErr()) {
|
|
118
|
-
return HttpResponse.asJson({ error: query.unsafeSource() }, 422);
|
|
119
|
-
}
|
|
120
|
-
const page = await reader.queryGroups(query.unwrap());
|
|
121
|
-
return page.match({
|
|
122
|
-
Ok: (value) => HttpResponse.asJson(value),
|
|
123
|
-
Err: (error) => HttpResponse.asJson({ error: error.message }, 500),
|
|
124
|
-
});
|
|
125
|
-
}, () => HttpResponse.asJson({ error: "Unauthorized" }, 401));
|
|
126
|
-
}
|
|
127
|
-
function pathParam(context, name) {
|
|
128
|
-
return context.pathParams.get(name);
|
|
114
|
+
return authenticated(auth, loggerLogsQueryAction(reader), unauthorizedResponse);
|
|
129
115
|
}
|
|
130
116
|
export function logRetryAction(auth, reader, http_client) {
|
|
131
|
-
return authenticated(auth,
|
|
132
|
-
const id = Number(pathParam(context, "id").someOr(""));
|
|
133
|
-
if (!Number.isInteger(id) || id <= 0) {
|
|
134
|
-
return HttpResponse.asJson({ error: "Invalid log id" }, 400);
|
|
135
|
-
}
|
|
136
|
-
const found = await reader.getById(id);
|
|
137
|
-
if (found.isErr()) {
|
|
138
|
-
return HttpResponse.asJson({ error: found.unsafeSource().message }, 500);
|
|
139
|
-
}
|
|
140
|
-
const log = found.unwrap();
|
|
141
|
-
if (log.isNone()) {
|
|
142
|
-
return HttpResponse.asJson({ error: "Log not found" }, 404);
|
|
143
|
-
}
|
|
144
|
-
const retry = log.unwrap().retry;
|
|
145
|
-
if (retry === null) {
|
|
146
|
-
return HttpResponse.asJson({ error: "Log has no retry configuration" }, 422);
|
|
147
|
-
}
|
|
148
|
-
// Resends the original message as-is (raw string body, no wrapping). Uses plain
|
|
149
|
-
// fetch, so this goes out over HTTP/1 by default (no HTTP/2 dispatcher configured).
|
|
150
|
-
const response = await http_client.post(retry.url, {
|
|
151
|
-
body: Some(log.unwrap().message),
|
|
152
|
-
rawResponse: true,
|
|
153
|
-
});
|
|
154
|
-
const retries_count = await reader.incrementRetryCount(id);
|
|
155
|
-
const retries_count_value = retries_count.okOr(log.unwrap().retries_count);
|
|
156
|
-
return response.match({
|
|
157
|
-
Ok: (ok_response) => HttpResponse.asJson({
|
|
158
|
-
status: ok_response.status,
|
|
159
|
-
body: ok_response.body.someOr(""),
|
|
160
|
-
retries_count: retries_count_value,
|
|
161
|
-
}),
|
|
162
|
-
Err: (error) => error instanceof HttpResponse
|
|
163
|
-
? HttpResponse.asJson({
|
|
164
|
-
status: error.status,
|
|
165
|
-
body: error.body.someOr(""),
|
|
166
|
-
retries_count: retries_count_value,
|
|
167
|
-
})
|
|
168
|
-
: HttpResponse.asJson({ error: "Retry request failed: " + String(error) }, 502),
|
|
169
|
-
});
|
|
170
|
-
}, () => HttpResponse.asJson({ error: "Unauthorized" }, 401));
|
|
117
|
+
return authenticated(auth, loggerLogRetryAction(reader, http_client, logIdFromPath), unauthorizedResponse);
|
|
171
118
|
}
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smuzi/logger-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Web UI for browsing logs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@smuzi/database": "^0.0.15",
|
|
41
41
|
"@smuzi/http-client": "^0.0.13",
|
|
42
42
|
"@smuzi/http-server": "^0.0.14",
|
|
43
|
-
"@smuzi/logger": "^0.0.
|
|
43
|
+
"@smuzi/logger": "^0.0.9",
|
|
44
44
|
"@smuzi/std": "^0.2.16"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|