@wopr-network/platform-core 1.14.4 → 1.14.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.
@@ -1,4 +1,5 @@
1
1
  import { Hono } from "hono";
2
+ import { logger } from "../../config/logger.js";
2
3
  import { safeAuditLog } from "./admin-audit-helper.js";
3
4
  export function createAdminOnboardingRoutes(getRepo, auditLogger) {
4
5
  const routes = new Hono();
@@ -23,7 +24,8 @@ export function createAdminOnboardingRoutes(getRepo, auditLogger) {
23
24
  try {
24
25
  body = (await c.req.json());
25
26
  }
26
- catch {
27
+ catch (err) {
28
+ logger.debug("Failed to parse onboarding script JSON body", { error: err });
27
29
  return c.json({ error: "Invalid JSON body" }, 400);
28
30
  }
29
31
  const content = body.content;
@@ -194,7 +194,11 @@ export async function runAuthMigrations() {
194
194
  try {
195
195
  ({ getMigrations } = (await import("better-auth/db/migration")));
196
196
  }
197
- catch {
197
+ catch (err) {
198
+ // Only fall back if the module path doesn't exist (ERR_MODULE_NOT_FOUND / ERR_PACKAGE_PATH_NOT_EXPORTED)
199
+ const code = err.code;
200
+ if (code !== "ERR_MODULE_NOT_FOUND" && code !== "ERR_PACKAGE_PATH_NOT_EXPORTED")
201
+ throw err;
198
202
  ({ getMigrations } = (await import("better-auth/db")));
199
203
  }
200
204
  const { runMigrations } = await getMigrations(authOptions(_config));
@@ -215,7 +215,8 @@ export class DhtBootstrapManager {
215
215
  const volume = this.docker.getVolume(name);
216
216
  await volume.inspect();
217
217
  }
218
- catch (_inspectErr) {
218
+ catch (inspectErr) {
219
+ logger.debug(`Volume inspect failed for ${name}, will attempt to create`, { error: inspectErr });
219
220
  try {
220
221
  await this.docker.createVolume({ Name: name });
221
222
  logger.info(`Created DHT state volume ${name}`);
@@ -93,6 +93,16 @@ describe("DhtBootstrapManager", () => {
93
93
  await manager.ensureNode(0);
94
94
  expect(docker.createVolume).toHaveBeenCalledWith({ Name: `${DHT_VOLUME_PREFIX}0` });
95
95
  });
96
+ it("logs at debug level when volume inspect fails", async () => {
97
+ const { logger } = await import("../config/logger.js");
98
+ const debugSpy = vi.spyOn(logger, "debug");
99
+ docker._volume.inspect.mockRejectedValue(new Error("no such volume"));
100
+ const container = mockContainer("c-0", `${DHT_CONTAINER_PREFIX}0`);
101
+ docker.createContainer.mockResolvedValue(container);
102
+ await manager.ensureNode(0);
103
+ expect(debugSpy).toHaveBeenCalledWith(expect.stringContaining("Volume inspect failed"), expect.objectContaining({ error: expect.any(Error) }));
104
+ debugSpy.mockRestore();
105
+ });
96
106
  it("passes DHT_PEERS env excluding self", async () => {
97
107
  const container = mockContainer("c-1", `${DHT_CONTAINER_PREFIX}1`);
98
108
  docker.createContainer.mockResolvedValue(container);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/platform-core",
3
- "version": "1.14.4",
3
+ "version": "1.14.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { Hono } from "hono";
2
2
  import type { AuthEnv } from "../../auth/index.js";
3
+ import { logger } from "../../config/logger.js";
3
4
  import type { IOnboardingScriptRepository } from "../../onboarding/drizzle-onboarding-script-repository.js";
4
5
  import type { AdminAuditLogger } from "./admin-audit-helper.js";
5
6
  import { safeAuditLog } from "./admin-audit-helper.js";
@@ -31,7 +32,8 @@ export function createAdminOnboardingRoutes(getRepo: RepoFactory, auditLogger?:
31
32
  let body: Record<string, unknown>;
32
33
  try {
33
34
  body = (await c.req.json()) as Record<string, unknown>;
34
- } catch {
35
+ } catch (err: unknown) {
36
+ logger.debug("Failed to parse onboarding script JSON body", { error: err });
35
37
  return c.json({ error: "Invalid JSON body" }, 400);
36
38
  }
37
39
 
@@ -268,7 +268,10 @@ export async function runAuthMigrations(): Promise<void> {
268
268
  let getMigrations: DbModule["getMigrations"];
269
269
  try {
270
270
  ({ getMigrations } = (await import("better-auth/db/migration")) as unknown as DbModule);
271
- } catch {
271
+ } catch (err: unknown) {
272
+ // Only fall back if the module path doesn't exist (ERR_MODULE_NOT_FOUND / ERR_PACKAGE_PATH_NOT_EXPORTED)
273
+ const code = (err as { code?: string }).code;
274
+ if (code !== "ERR_MODULE_NOT_FOUND" && code !== "ERR_PACKAGE_PATH_NOT_EXPORTED") throw err;
272
275
  ({ getMigrations } = (await import("better-auth/db")) as unknown as DbModule);
273
276
  }
274
277
  const { runMigrations } = await getMigrations(authOptions(_config));
@@ -115,6 +115,22 @@ describe("DhtBootstrapManager", () => {
115
115
  expect(docker.createVolume).toHaveBeenCalledWith({ Name: `${DHT_VOLUME_PREFIX}0` });
116
116
  });
117
117
 
118
+ it("logs at debug level when volume inspect fails", async () => {
119
+ const { logger } = await import("../config/logger.js");
120
+ const debugSpy = vi.spyOn(logger, "debug");
121
+ docker._volume.inspect.mockRejectedValue(new Error("no such volume"));
122
+ const container = mockContainer("c-0", `${DHT_CONTAINER_PREFIX}0`);
123
+ docker.createContainer.mockResolvedValue(container);
124
+
125
+ await manager.ensureNode(0);
126
+
127
+ expect(debugSpy).toHaveBeenCalledWith(
128
+ expect.stringContaining("Volume inspect failed"),
129
+ expect.objectContaining({ error: expect.any(Error) }),
130
+ );
131
+ debugSpy.mockRestore();
132
+ });
133
+
118
134
  it("passes DHT_PEERS env excluding self", async () => {
119
135
  const container = mockContainer("c-1", `${DHT_CONTAINER_PREFIX}1`);
120
136
  docker.createContainer.mockResolvedValue(container);
@@ -257,7 +257,8 @@ export class DhtBootstrapManager {
257
257
  try {
258
258
  const volume = this.docker.getVolume(name);
259
259
  await volume.inspect();
260
- } catch (_inspectErr: unknown) {
260
+ } catch (inspectErr: unknown) {
261
+ logger.debug(`Volume inspect failed for ${name}, will attempt to create`, { error: inspectErr });
261
262
  try {
262
263
  await this.docker.createVolume({ Name: name });
263
264
  logger.info(`Created DHT state volume ${name}`);