@hadoku/service-kernel 0.1.68 → 0.1.69
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.
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
*
|
|
26
26
|
* Imports only; nothing runs at import.
|
|
27
27
|
*/
|
|
28
|
-
import { createHmac } from 'node:crypto';
|
|
29
28
|
import { readdir, readFile } from 'node:fs/promises';
|
|
30
29
|
import { join } from 'node:path';
|
|
30
|
+
import { archivebotPost } from "./archivebot.js";
|
|
31
31
|
/** ArchiveBot's per-embed description cap. */
|
|
32
32
|
const DESCRIPTION_MAX = 4096;
|
|
33
33
|
/** The newest release notes in `dir`, by `ordering`, or null when there are none. */
|
|
@@ -203,21 +203,6 @@ function notesPayload(service, notes, appUrl, now) {
|
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
const creditsKey = (service, version) => `${service}-credits-${version}`;
|
|
206
|
-
async function postSigned(options, path, body) {
|
|
207
|
-
const signature = createHmac('sha256', options.secret).update(body).digest('hex');
|
|
208
|
-
return (options.fetch ?? fetch)(`${options.archivebotUrl}${path}`, {
|
|
209
|
-
method: 'POST',
|
|
210
|
-
headers: { 'Content-Type': 'application/json', 'X-Hadoku-Signature': `sha256=${signature}` },
|
|
211
|
-
body,
|
|
212
|
-
signal: AbortSignal.timeout(10_000),
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
/** POST `body` to ArchiveBot's `path`: the status, the raw reply, and a 2xx reply parsed (`{}` otherwise). */
|
|
216
|
-
async function call(options, path, body) {
|
|
217
|
-
const res = await postSigned(options, path, body);
|
|
218
|
-
const raw = await res.text();
|
|
219
|
-
return { status: res.status, ok: res.ok, raw, answer: res.ok ? JSON.parse(raw) : {} };
|
|
220
|
-
}
|
|
221
206
|
async function readEarlierCredits(file) {
|
|
222
207
|
if (file === undefined)
|
|
223
208
|
return [];
|
|
@@ -259,7 +244,7 @@ export async function announceRelease(options) {
|
|
|
259
244
|
}
|
|
260
245
|
for (const older of releases.slice(1)) {
|
|
261
246
|
try {
|
|
262
|
-
const res = await
|
|
247
|
+
const res = await archivebotPost(options, '/api/messages/delete', JSON.stringify({ idempotencyKey: creditsKey(service, older.version), timestamp: now().getTime(), source: service }));
|
|
263
248
|
if (res.status === 404)
|
|
264
249
|
continue;
|
|
265
250
|
log({ event: 'release-credits', outcome: res.ok ? 'deleted' : 'failed', version: older.version, ...(res.ok ? {} : { status: res.status, reply: res.raw.slice(0, 500) }) });
|
|
@@ -269,7 +254,7 @@ export async function announceRelease(options) {
|
|
|
269
254
|
}
|
|
270
255
|
}
|
|
271
256
|
try {
|
|
272
|
-
const res = await
|
|
257
|
+
const res = await archivebotPost(options, '/api/messages/send', notesPayload(service, notes, options.appUrl, now()));
|
|
273
258
|
if (!res.ok) {
|
|
274
259
|
log({ event: 'release-announce', outcome: 'failed', version: notes.version, status: res.status, reply: res.raw.slice(0, 500) });
|
|
275
260
|
return;
|
|
@@ -282,7 +267,7 @@ export async function announceRelease(options) {
|
|
|
282
267
|
}
|
|
283
268
|
for (const release of releases) {
|
|
284
269
|
try {
|
|
285
|
-
const res = await
|
|
270
|
+
const res = await archivebotPost(options, '/api/messages/edit', notesPayload(service, release, options.appUrl, now()));
|
|
286
271
|
// 404: no post for it, on record or in the channel's history: nothing to change.
|
|
287
272
|
if (res.status === 404)
|
|
288
273
|
continue;
|
|
@@ -308,7 +293,7 @@ export async function announceRelease(options) {
|
|
|
308
293
|
retain: true,
|
|
309
294
|
embeds: splitBody(body).map((description, i) => ({ ...(i === 0 ? { title: CREDITS_TITLE } : {}), description, url: options.appUrl, color: 0x2f855a })),
|
|
310
295
|
});
|
|
311
|
-
const sent = await
|
|
296
|
+
const sent = await archivebotPost(options, '/api/messages/send', payload(now()));
|
|
312
297
|
if (!sent.ok) {
|
|
313
298
|
log({ event: 'release-credits', outcome: 'failed', version: notes.version, status: sent.status, reply: sent.raw.slice(0, 500) });
|
|
314
299
|
return;
|
|
@@ -317,7 +302,7 @@ export async function announceRelease(options) {
|
|
|
317
302
|
log({ event: 'release-credits', outcome: 'posted', version: notes.version });
|
|
318
303
|
return;
|
|
319
304
|
}
|
|
320
|
-
const edited = await
|
|
305
|
+
const edited = await archivebotPost(options, '/api/messages/edit', payload(now()));
|
|
321
306
|
if (!edited.ok)
|
|
322
307
|
log({ event: 'release-credits', outcome: 'failed', version: notes.version, status: edited.status, reply: edited.raw.slice(0, 500) });
|
|
323
308
|
else if (edited.answer.edited === true)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ArchivebotTarget {
|
|
2
|
+
/** The app's ArchiveBot webhook secret; the caller decides what an empty one means. */
|
|
3
|
+
secret: string;
|
|
4
|
+
archivebotUrl: string;
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
}
|
|
7
|
+
export interface ArchivebotReply {
|
|
8
|
+
status: number;
|
|
9
|
+
ok: boolean;
|
|
10
|
+
/** The reply as sent, for a log line. */
|
|
11
|
+
raw: string;
|
|
12
|
+
/** The reply's JSON object, or `{}` when it was not one. */
|
|
13
|
+
answer: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/** POST `body` (already JSON) to ArchiveBot's `path`, signed. Throws only when ArchiveBot could not be reached. */
|
|
16
|
+
export declare function archivebotPost(target: ArchivebotTarget, path: string, body: string): Promise<ArchivebotReply>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* One signed POST to ArchiveBot: the body is HMAC-SHA256'd with the app's webhook secret and sent
|
|
3
|
+
* as `X-Hadoku-Signature: sha256=<hex>` (contract: docs/requests/ARCHIVEBOT_DISCORD_INTEGRATION_REPLY.md).
|
|
4
|
+
* Every caller that writes to the app's Discord through ArchiveBot goes through here: the release
|
|
5
|
+
* announce (`announce.ts`) and the scheduled-event mirror (game-server's `room/discord-events.ts`).
|
|
6
|
+
*
|
|
7
|
+
* Imports only; nothing runs at import.
|
|
8
|
+
*/
|
|
9
|
+
import { createHmac } from 'node:crypto';
|
|
10
|
+
const TIMEOUT_MS = 10_000;
|
|
11
|
+
function parsed(raw) {
|
|
12
|
+
try {
|
|
13
|
+
const value = JSON.parse(raw);
|
|
14
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** POST `body` (already JSON) to ArchiveBot's `path`, signed. Throws only when ArchiveBot could not be reached. */
|
|
21
|
+
export async function archivebotPost(target, path, body) {
|
|
22
|
+
const signature = createHmac('sha256', target.secret).update(body).digest('hex');
|
|
23
|
+
const res = await (target.fetch ?? fetch)(`${target.archivebotUrl}${path}`, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: { 'Content-Type': 'application/json', 'X-Hadoku-Signature': `sha256=${signature}` },
|
|
26
|
+
body,
|
|
27
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
28
|
+
});
|
|
29
|
+
const raw = await res.text();
|
|
30
|
+
return { status: res.status, ok: res.ok, raw, answer: parsed(raw) };
|
|
31
|
+
}
|
|
@@ -2,3 +2,4 @@ export { arrivedVia, busyHandler, isLocalProbe, type BusyReport, type BusyRun }
|
|
|
2
2
|
export { bootClock } from './bootClock.js';
|
|
3
3
|
export { closeConnections, sendThenFlush, type Closable, type Flushable } from './flush-sockets.js';
|
|
4
4
|
export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, releaseEmbeds, showCredits, splitBody, type AnnounceOptions, type CreditCount, type Embed, type ReleaseNotes, type ReleaseOrdering, } from './announce.js';
|
|
5
|
+
export { archivebotPost, type ArchivebotReply, type ArchivebotTarget } from './archivebot.js';
|
package/dist/lifecycle/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { arrivedVia, busyHandler, isLocalProbe } from "./busy.js";
|
|
|
2
2
|
export { bootClock } from "./bootClock.js";
|
|
3
3
|
export { closeConnections, sendThenFlush } from "./flush-sockets.js";
|
|
4
4
|
export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, releaseEmbeds, showCredits, splitBody, } from "./announce.js";
|
|
5
|
+
export { archivebotPost } from "./archivebot.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/service-kernel",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.69",
|
|
4
|
+
"gitHead": "0042b4a6b48122971a996d7f469677d4b0e105ea",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any game keeps: edge auth and the tier gate, base path and bundle check, health and the busy probe, lifecycle, the JSON logger, the state directory, telemetry and capacity, per-caller limits, the browser relays, the erase registry, and createGameServer, which boots a game from its config and plugins. Knows no game; the app binds its service id, prefix and env names. MIT; imports only node built-ins, express, socket.io and @wolffm/*.",
|