@coffer-org/server 1.6.0 → 1.7.0

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/dist/index.js CHANGED
@@ -229,7 +229,7 @@ app.post('/api/plugins/:id/update', async (req, reply) => {
229
229
  const { id } = req.params;
230
230
  const assets = await discoverPluginAssets();
231
231
  const rec = assets.find((a) => a.id === id);
232
- const latest = rec ? await checkLatestVersion(rec.packageName) : null;
232
+ const latest = rec && !rec.local ? await checkLatestVersion(rec.packageName) : null;
233
233
  const target = resolveUpdateTarget(assets, id, latest);
234
234
  if (!target.ok) {
235
235
  return reply.code(target.error === 'unknown_plugin' ? 404 : 400).send({ error: target.error });
@@ -245,7 +245,7 @@ app.post('/api/plugins/update-all', async (req, reply) => {
245
245
  if (!requireAdmin(req, reply))
246
246
  return;
247
247
  const assets = await discoverPluginAssets();
248
- const latestById = new Map(await Promise.all(assets.map(async (a) => [a.id, await checkLatestVersion(a.packageName)])));
248
+ const latestById = new Map(await Promise.all(assets.map(async (a) => [a.id, a.local ? null : await checkLatestVersion(a.packageName)])));
249
249
  const targets = resolveAllUpdateTargets(assets, latestById);
250
250
  if (targets.length === 0)
251
251
  return reply.code(400).send({ error: 'no_update_available' });
package/dist/log.js CHANGED
@@ -1,5 +1,22 @@
1
1
  import { pino } from 'pino';
2
2
  import { setRootLogger, LOG_LEVEL, getLogger } from '@coffer-org/sdk/logger';
3
- export const rootLogger = pino({ level: LOG_LEVEL });
3
+ const prettyEnv = process.env.COFFER_LOG_PRETTY;
4
+ const pretty = prettyEnv !== undefined ? prettyEnv !== '0' && prettyEnv !== '' : process.stdout.isTTY;
5
+ export const rootLogger = pino({
6
+ level: LOG_LEVEL,
7
+ ...(pretty
8
+ ? {
9
+ transport: {
10
+ target: 'pino-pretty',
11
+ options: {
12
+ colorize: true,
13
+ translateTime: 'SYS:HH:MM:ss',
14
+ ignore: 'pid,hostname,tag',
15
+ messageFormat: '{if tag}[{tag}] {end}{msg}',
16
+ },
17
+ },
18
+ }
19
+ : {}),
20
+ });
4
21
  setRootLogger(rootLogger);
5
22
  export { getLogger };
@@ -19,6 +19,7 @@ export interface PluginAssetRecord {
19
19
  schema: string;
20
20
  web?: string;
21
21
  css?: string;
22
+ local?: boolean;
22
23
  }
23
24
  export declare function discoverPluginAssets(): Promise<PluginAssetRecord[]>;
24
25
  export declare function discoverPlugins(): Promise<PluginManifest[]>;
@@ -6,8 +6,8 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import { readdir, readFile } from 'node:fs/promises';
10
- import { join } from 'node:path';
9
+ import { readdir, readFile, realpath } from 'node:fs/promises';
10
+ import { join, sep } from 'node:path';
11
11
  import { pathToFileURL } from 'node:url';
12
12
  import { getLogger } from '@coffer-org/sdk/logger';
13
13
  const log = getLogger('discovery');
@@ -40,6 +40,15 @@ export function resolveAssetUrls(id, coffer) {
40
40
  out.css = `${base}/web.css`;
41
41
  return out;
42
42
  }
43
+ async function isLocalPackage(dir) {
44
+ try {
45
+ const real = await realpath(dir);
46
+ return !real.includes(`${sep}node_modules${sep}`);
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
43
52
  export async function discoverPluginAssets() {
44
53
  const nm = join(process.cwd(), 'node_modules');
45
54
  const names = await pkgNames(nm);
@@ -62,6 +71,7 @@ export async function discoverPluginAssets() {
62
71
  schema: urls.schema,
63
72
  web: urls.web,
64
73
  css: urls.css,
74
+ local: await isLocalPackage(join(nm, name)),
65
75
  });
66
76
  }
67
77
  catch (e) {
@@ -1,6 +1,7 @@
1
1
  import type { EntityManager } from '@mikro-orm/core';
2
2
  import type { z } from 'zod';
3
3
  import type { ColumnType } from '@coffer-org/sdk/fields';
4
+ import { type Logger } from '@coffer-org/sdk/logger';
4
5
  export interface TableOps {
5
6
  renameColumn(from: string, to: string): Promise<void>;
6
7
  fill(column: string, value: string | number | boolean | null, opts?: {
@@ -20,7 +21,9 @@ export interface Migration {
20
21
  }
21
22
  export interface PluginCtx {
22
23
  em: EntityManager;
24
+ log: Logger;
23
25
  }
26
+ export declare function pluginCtx(id: string, em: EntityManager): PluginCtx;
24
27
  export interface Seed {
25
28
  name: string;
26
29
  run(ctx: PluginCtx): Promise<void> | void;
@@ -1 +1,5 @@
1
+ import { getLogger } from '@coffer-org/sdk/logger';
2
+ export function pluginCtx(id, em) {
3
+ return { em, log: getLogger(id) };
4
+ }
1
5
  export const pluginHooks = {};
@@ -4,7 +4,7 @@ import { getLogger } from '@coffer-org/sdk/logger';
4
4
  import { initDb, getOrm, getEm } from "./db.js";
5
5
  import { syncSchema } from "./schema-sync.js";
6
6
  import { systemEntities, buildPluginEntities, moduleTableName } from "./entity-schema.js";
7
- import { pluginHooks } from "./plugin-hooks.js";
7
+ import { pluginHooks, pluginCtx } from "./plugin-hooks.js";
8
8
  import { discoverPlugins, loadServerHooks } from "./plugin-discovery.js";
9
9
  import { runMigrations, assertSafeRequired } from "./migrations.js";
10
10
  import { runSeeds } from "./seeds.js";
@@ -78,7 +78,7 @@ export async function initPlugins() {
78
78
  const h = pluginHooks[p.id];
79
79
  try {
80
80
  if (h?.init) {
81
- await h.init({ em: getEm().fork() });
81
+ await h.init(pluginCtx(p.id, getEm().fork()));
82
82
  log.debug(`${p.id}: init ✓`);
83
83
  }
84
84
  }
@@ -100,7 +100,7 @@ export async function teardownPlugins() {
100
100
  if (!h?.teardown)
101
101
  continue;
102
102
  try {
103
- await h.teardown({ em: getEm().fork() });
103
+ await h.teardown(pluginCtx(p.id, getEm().fork()));
104
104
  log.debug(`${p.id}: teardown ✓`);
105
105
  }
106
106
  catch (e) {
@@ -111,7 +111,7 @@ export async function teardownPlugins() {
111
111
  export async function teardownPlugin(id) {
112
112
  const h = pluginHooks[id];
113
113
  if (h?.teardown) {
114
- await h.teardown({ em: getEm().fork() });
114
+ await h.teardown(pluginCtx(id, getEm().fork()));
115
115
  log.debug(`${id}: teardown ✓`);
116
116
  }
117
117
  }
@@ -12,7 +12,7 @@ export async function buildPluginListResponse(plugins, assets, disabled) {
12
12
  return {
13
13
  id: p.id,
14
14
  installedVersion: a?.version ?? p.version,
15
- latestVersion: a ? await checkLatestVersion(a.packageName) : null,
15
+ latestVersion: a && !a.local ? await checkLatestVersion(a.packageName) : null,
16
16
  packageName: a?.packageName ?? null,
17
17
  dependsOn: p.dependsOn,
18
18
  enabled: !disabled.has(p.id),
package/dist/seeds.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { EntityManager } from '@mikro-orm/core';
2
- import type { PluginHooks } from './plugin-hooks.ts';
2
+ import { type PluginHooks } from './plugin-hooks.ts';
3
3
  export declare function validateSeeds(pluginId: string, list: {
4
4
  name: string;
5
5
  }[]): void;
package/dist/seeds.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { pluginCtx } from "./plugin-hooks.js";
1
2
  import { getLogger } from '@coffer-org/sdk/logger';
2
3
  const log = getLogger('seeds');
3
4
  export function validateSeeds(pluginId, list) {
@@ -16,7 +17,7 @@ export async function runSeeds({ em, plugins, hooks }) {
16
17
  const applied = new Set((await conn.execute(`SELECT name FROM _seeds WHERE plugin_id = ?`, [p.id])).map((r) => r.name));
17
18
  const pending = list.filter((s) => !applied.has(s.name));
18
19
  for (const s of pending) {
19
- await s.run({ em: em.fork() });
20
+ await s.run(pluginCtx(p.id, em.fork()));
20
21
  await conn.execute(`INSERT INTO _seeds (plugin_id, name) VALUES (?, ?)`, [p.id, s.name]);
21
22
  }
22
23
  if (pending.length)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffer-org/server",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -35,6 +35,7 @@
35
35
  "fastify": "^5.2.1",
36
36
  "open-graph-scraper": "^6.11.0",
37
37
  "pino": "^9.14.0",
38
+ "pino-pretty": "^13.1.3",
38
39
  "zod": "^4.4.3"
39
40
  },
40
41
  "optionalDependencies": {