@pikku/inspector 0.12.87 → 0.12.88

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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 0.12.88
2
+
3
+ ### Patch Changes
4
+
5
+ - 55ab4d1: An addon's metadata now resolves from the package that calls `wireAddon`, as well as from the repo root, so a workspace addon listed only in `packages/functions` loads. When it still cannot be found, the warning names the package, the directories tried and the fix: add the dependency and install, or build the addon if it is installed but has no generated metadata.
6
+ - f6c1dd6: A fresh project with Better Auth no longer gets PKU951 for `BETTER_AUTH_SECRET` on its first `pikku all`. The secret is declared by the generated `auth-secrets.gen.ts`, which did not exist yet when the first inspection ran.
7
+ - 0210e96: Review fixes for the OpenAPI addon onboarding:
8
+
9
+ - A delegated sign-in whose email the upstream did not return, including a login typed as an email, never links to an existing user. An authenticator that omits `syntheticEmail` counts as synthetic.
10
+ - `pikkuActor` credentials take an optional `remove`, which drops a credential the environment no longer sets. The actor log line names the user id, not the email.
11
+ - Basic credentials are UTF-8 encoded, and a Swagger 2 `application` OAuth flow keeps its token URL.
12
+ - `pikku new addon` writes a `file:` path relative to each package when the app is not a workspace, and reports an auth.ts factory it cannot edit instead of half-wiring it.
13
+ - The inspector reads an addon from the package that declares it before the root.
14
+ - The dev credentials key file is created exclusively, so two `pikku dev` processes agree on one key.
15
+
16
+ - 86c2f1d: `pikku dev` keeps stored credentials in the dev database, so connected accounts and delegated sign-ins survive a restart. The key comes from `PIKKU_DEV_CREDENTIALS_KEY`, or is generated once into `.pikku-runtime/dev-credentials.key`. A project that declares a credential now gets the credential tables in its generated migration; without them dev falls back to the in-memory store and says so once.
17
+ - da9b931: An inline `input`/`output` schema (PKU489) is now an `error` diagnostic instead of a critical one, so `pikku dev` keeps running. The function is validated against its TypeScript type until the schema is extracted to an exported variable; `--fail-on-error` still blocks it.
18
+ - Updated dependencies [e84abd0]
19
+ - @pikku/core@0.12.121
20
+
1
21
  ## 0.12.87
2
22
 
3
23
  ### Patch Changes
@@ -629,12 +629,16 @@ export const addFunctions = (logger, node, checker, state, options) => {
629
629
  }
630
630
  }
631
631
  else if (ts.isCallExpression(prop.initializer)) {
632
- // Bad - it's an inline expression
633
632
  const schemaName = `${funcIdToTypeName(name)}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
634
- logger.critical(ErrorCode.INLINE_SCHEMA, `Inline schemas are not supported for '${propName}' in '${name}'.\n` +
635
- ` Extract to an exported variable:\n` +
636
- ` export const ${schemaName} = ${prop.initializer.getText()}\n` +
637
- ` Then use: ${propName}: ${schemaName}`);
633
+ logger.diagnostic({
634
+ severity: 'error',
635
+ code: ErrorCode.INLINE_SCHEMA,
636
+ message: `Inline schemas are not supported for '${propName}' in '${name}'; ` +
637
+ `it is validated against its TypeScript type only, so refinements are not enforced.\n` +
638
+ ` Extract to an exported variable:\n` +
639
+ ` export const ${schemaName} = ${prop.initializer.getText()}\n` +
640
+ ` Then use: ${propName}: ${schemaName}`,
641
+ });
638
642
  }
639
643
  }
640
644
  }
@@ -1,4 +1,5 @@
1
1
  import type { InspectorState, InspectorLogger } from '../types.js';
2
+ export declare const describeMissingAddonMeta: (namespace: string, packageName: string, dirs: string[], declFile?: string) => string;
2
3
  /**
3
4
  * After the setup sweep discovers wireAddon() declarations, load each addon
4
5
  * package's function metadata so that wiring handlers (channels, HTTP routes,
@@ -1,7 +1,7 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { readFile, readdir } from 'fs/promises';
3
3
  import { createRequire } from 'module';
4
- import { join, dirname } from 'path';
4
+ import { join, dirname, parse, relative } from 'path';
5
5
  import { ErrorCode } from '../error-codes.js';
6
6
  const isHTTPRouteConfig = (value) => typeof value === 'object' &&
7
7
  value !== null &&
@@ -90,6 +90,77 @@ const resolveAddonMeta = (require, packageName, baseName) => {
90
90
  }
91
91
  return null;
92
92
  };
93
+ const nearestPackageDir = (file) => {
94
+ const root = parse(file).root;
95
+ let dir = dirname(file);
96
+ while (dir && dir !== root) {
97
+ if (existsSync(join(dir, 'package.json')))
98
+ return dir;
99
+ const parent = dirname(dir);
100
+ if (parent === dir)
101
+ break;
102
+ dir = parent;
103
+ }
104
+ return null;
105
+ };
106
+ /**
107
+ * An addon is installed wherever the package that calls `wireAddon` lists it,
108
+ * which in a workspace is usually not the repo root. Resolve from the declaring
109
+ * package first, as its code does at runtime, then from the root.
110
+ */
111
+ const addonResolutionDirs = (rootDir, declFile) => {
112
+ const declDir = declFile ? nearestPackageDir(declFile) : null;
113
+ return declDir && declDir !== rootDir ? [declDir, rootDir] : [rootDir];
114
+ };
115
+ const createAddonResolver = (dirs) => {
116
+ const requires = dirs.map((dir) => createRequire(join(dir, 'package.json')));
117
+ return {
118
+ resolve: (id) => {
119
+ let lastError;
120
+ for (const req of requires) {
121
+ try {
122
+ return req.resolve(id);
123
+ }
124
+ catch (e) {
125
+ lastError = e;
126
+ }
127
+ }
128
+ throw lastError;
129
+ },
130
+ };
131
+ };
132
+ const findInstalledPackageDir = (dirs, packageName) => {
133
+ for (const start of dirs) {
134
+ const root = parse(start).root;
135
+ let dir = start;
136
+ while (dir) {
137
+ const candidate = join(dir, 'node_modules', packageName);
138
+ if (existsSync(join(candidate, 'package.json')))
139
+ return candidate;
140
+ if (dir === root)
141
+ break;
142
+ const parent = dirname(dir);
143
+ if (parent === dir)
144
+ break;
145
+ dir = parent;
146
+ }
147
+ }
148
+ return null;
149
+ };
150
+ export const describeMissingAddonMeta = (namespace, packageName, dirs, declFile) => {
151
+ const caller = declFile
152
+ ? relative(dirs[dirs.length - 1], declFile) || declFile
153
+ : undefined;
154
+ const declaredIn = caller ? ` (declared in ${caller})` : '';
155
+ const packageDir = findInstalledPackageDir(dirs, packageName);
156
+ if (!packageDir) {
157
+ const declaringPackage = dirs[0];
158
+ return (`wireAddon('${namespace}')${declaredIn} names ${packageName}, which is not installed where it can be resolved — tried ${dirs.join(', ')}. ` +
159
+ `Add "${packageName}": "workspace:*" (or a version) to the dependencies of ${join(declaringPackage, 'package.json')} and run install.`);
160
+ }
161
+ return (`wireAddon('${namespace}')${declaredIn}: ${packageName} is installed at ${packageDir} but has not been built — ` +
162
+ `its dist/.pikku/addon/function/pikku-functions-meta.gen.json does not exist. Run the addon's build (pikku all && tsc && pikku dist) in ${packageDir}.`);
163
+ };
93
164
  /**
94
165
  * Give the addon's input/output type names a declaration file to be imported
95
166
  * from, so a wiring that references an addon function can name its contract.
@@ -128,21 +199,24 @@ export async function loadAddonFunctionsMeta(logger, state) {
128
199
  const { wireAddonDeclarations } = state.rpc;
129
200
  if (wireAddonDeclarations.size === 0)
130
201
  return;
131
- const require = createRequire(join(state.rootDir, 'package.json'));
132
202
  for (const [namespace, decl] of wireAddonDeclarations) {
133
203
  // Remote addons (wireRemoteAddon) ship as a devDependency: types only.
134
204
  // Their functions, secrets, variables, schemas and services live on the
135
205
  // HOST that runs them — never load or require any of that here.
136
206
  if (decl.remote)
137
207
  continue;
208
+ const dirs = addonResolutionDirs(state.rootDir, decl.file);
209
+ const require = createAddonResolver(dirs);
138
210
  try {
139
211
  // Verbose first. `description` is one of the fields stripped from the
140
212
  // minimal copy, and it is what an addon's function is offered to a model
141
213
  // under — both as an MCP tool below and as an agent tool. Read the minimal
142
214
  // one and every addon function looks undescribed.
143
215
  const metaPath = resolveAddonMeta(require, decl.package, 'function/pikku-functions-meta');
144
- if (!metaPath)
145
- throw new Error('no function metadata');
216
+ if (!metaPath) {
217
+ logger.warn(describeMissingAddonMeta(namespace, decl.package, dirs, decl.file));
218
+ continue;
219
+ }
146
220
  const raw = await readFile(metaPath, 'utf-8');
147
221
  const meta = JSON.parse(raw);
148
222
  state.addonFunctions[namespace] = meta;
@@ -375,11 +449,11 @@ export async function loadAddonSchemas(logger, state) {
375
449
  const { wireAddonDeclarations } = state.rpc;
376
450
  if (wireAddonDeclarations.size === 0)
377
451
  return;
378
- const require = createRequire(join(state.rootDir, 'package.json'));
379
452
  for (const [namespace, decl] of wireAddonDeclarations) {
380
453
  // Remote addons carry no local schemas — their funcs run on the host.
381
454
  if (decl.remote)
382
455
  continue;
456
+ const require = createAddonResolver(addonResolutionDirs(state.rootDir, decl.file));
383
457
  try {
384
458
  const metaPath = require.resolve(`${decl.package}/.pikku/function/pikku-functions-meta.gen.json`);
385
459
  const schemasDir = join(dirname(metaPath), '..', 'schemas', 'schemas');
@@ -400,6 +474,10 @@ export async function loadAddonSchemas(logger, state) {
400
474
  }
401
475
  }
402
476
  catch (error) {
477
+ if (error?.code === 'MODULE_NOT_FOUND' ||
478
+ error?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
479
+ continue;
480
+ }
403
481
  logger.warn(`Failed to load addon schemas for '${namespace}' (${decl.package}): ${error.message}`);
404
482
  }
405
483
  }
@@ -287,6 +287,9 @@ export function aggregateRequiredServices(state) {
287
287
  if ((state.analytics?.length ?? 0) > 0) {
288
288
  requiredServices.add('analyticsService');
289
289
  }
290
+ if ((state.credentials?.definitions?.length ?? 0) > 0) {
291
+ requiredServices.add('credentialService');
292
+ }
290
293
  // 7. Services that consumed addons need from the parent project.
291
294
  const addonFnServices = new Map();
292
295
  for (const [namespace, fns] of Object.entries(state.addonFunctions ?? {})) {
@@ -1146,6 +1149,10 @@ export function validateSecretUsage(logger, state) {
1146
1149
  declared.add(definition.oauth2.tokenSecretId);
1147
1150
  }
1148
1151
  }
1152
+ // auth-secrets.gen.ts declares it, but that file is written after the first
1153
+ // inspection of a fresh project, so its defineSecret is not seen yet.
1154
+ if (state.auth?.definition)
1155
+ declared.add('BETTER_AUTH_SECRET');
1149
1156
  for (const [file, usage] of state.secrets.usage) {
1150
1157
  const relativeFile = relative(state.rootDir, file);
1151
1158
  const undeclared = usage.keys.filter((key) => !declared.has(key));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/inspector",
3
- "version": "0.12.87",
3
+ "version": "0.12.88",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/pikkujs/pikku.git",
@@ -55,10 +55,10 @@
55
55
  "zod-to-ts": "^2.1.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@pikku/core": "^0.12.120"
58
+ "@pikku/core": "^0.12.121"
59
59
  },
60
60
  "devDependencies": {
61
- "@pikku/core": "^0.12.120",
61
+ "@pikku/core": "^0.12.121",
62
62
  "@types/node": "^24.13.3"
63
63
  },
64
64
  "engines": {