@pikku/core 0.12.63 → 0.12.66
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 +368 -0
- package/dist/dev/hot-reload.js +13 -55
- package/dist/dev/module-runner.d.ts +14 -0
- package/dist/dev/module-runner.js +59 -0
- package/dist/dev/reload-meta.d.ts +13 -0
- package/dist/dev/reload-meta.js +22 -0
- package/dist/errors/errors.d.ts +12 -0
- package/dist/errors/errors.js +19 -0
- package/dist/function/function-runner.d.ts +5 -5
- package/dist/function/function-runner.js +39 -111
- package/dist/function/functions.types.d.ts +17 -7
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -1
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/cors.d.ts +1 -0
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/index.js +1 -1
- package/dist/middleware/remote-auth.d.ts +1 -0
- package/dist/middleware/telemetry.d.ts +2 -0
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/permissions.d.ts +42 -27
- package/dist/permissions.js +101 -203
- package/dist/pikku-state.js +0 -2
- package/dist/scopes.d.ts +17 -0
- package/dist/scopes.js +59 -0
- package/dist/services/ai-embedding-service.d.ts +31 -0
- package/dist/services/ai-embedding-service.js +1 -0
- package/dist/services/credential-wire-service.d.ts +3 -1
- package/dist/services/credential-wire-service.js +10 -4
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +2 -0
- package/dist/services/meta-service.d.ts +15 -2
- package/dist/services/meta-service.js +51 -1
- package/dist/services/queue-webhook-service.d.ts +55 -0
- package/dist/services/queue-webhook-service.js +136 -0
- package/dist/services/scope-service.d.ts +67 -0
- package/dist/services/scope-service.js +1 -0
- package/dist/services/typed-secret-service.d.ts +8 -0
- package/dist/services/typed-secret-service.js +39 -4
- package/dist/services/webhook-service.d.ts +140 -0
- package/dist/services/webhook-service.js +44 -0
- package/dist/services/workflow-service.d.ts +7 -0
- package/dist/testing/service-tests.js +37 -0
- package/dist/types/core.types.d.ts +34 -6
- package/dist/types/state.types.d.ts +20 -2
- package/dist/utils/hmac.d.ts +16 -0
- package/dist/utils/hmac.js +26 -0
- package/dist/utils/safe-fetch.d.ts +51 -0
- package/dist/utils/safe-fetch.js +192 -0
- package/dist/wirings/ai-agent/ai-agent-agui.d.ts +84 -0
- package/dist/wirings/ai-agent/ai-agent-agui.js +305 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +105 -1
- package/dist/wirings/ai-agent/ai-agent-prepare.js +249 -11
- package/dist/wirings/ai-agent/ai-agent-runner.js +10 -1
- package/dist/wirings/ai-agent/ai-agent-stream.js +88 -16
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +56 -2
- package/dist/wirings/ai-agent/index.d.ts +2 -1
- package/dist/wirings/ai-agent/index.js +2 -1
- package/dist/wirings/ai-agent/voice-input.d.ts +1 -0
- package/dist/wirings/ai-agent/voice-input.js +5 -41
- package/dist/wirings/ai-agent/voice-output.d.ts +1 -0
- package/dist/wirings/channel/channel-common.js +0 -1
- package/dist/wirings/channel/channel-handler.js +1 -4
- package/dist/wirings/channel/channel-middleware-runner.d.ts +12 -0
- package/dist/wirings/channel/channel-middleware-runner.js +34 -19
- package/dist/wirings/channel/channel.types.d.ts +2 -6
- package/dist/wirings/cli/cli-runner.js +3 -2
- package/dist/wirings/cli/cli.types.d.ts +1 -2
- package/dist/wirings/cli/command-parser.d.ts +2 -0
- package/dist/wirings/cli/command-parser.js +59 -2
- package/dist/wirings/credential/credential.types.d.ts +14 -0
- package/dist/wirings/credential/validate-credential-definitions.js +1 -0
- package/dist/wirings/gateway/gateway-runner.js +100 -50
- package/dist/wirings/gateway/gateway.types.d.ts +8 -5
- package/dist/wirings/http/http-routes.js +0 -3
- package/dist/wirings/http/http-runner.d.ts +9 -29
- package/dist/wirings/http/http-runner.js +9 -34
- package/dist/wirings/http/http.types.d.ts +4 -12
- package/dist/wirings/mcp/mcp-runner.js +0 -2
- package/dist/wirings/mcp/mcp.types.d.ts +5 -11
- package/dist/wirings/oauth2/index.d.ts +0 -3
- package/dist/wirings/oauth2/index.js +1 -2
- package/dist/wirings/rpc/addon-runner.d.ts +28 -0
- package/dist/wirings/rpc/addon-runner.js +173 -0
- package/dist/wirings/rpc/index.d.ts +5 -1
- package/dist/wirings/rpc/index.js +3 -1
- package/dist/wirings/rpc/remote-addon-auth.d.ts +26 -0
- package/dist/wirings/rpc/remote-addon-auth.js +43 -0
- package/dist/wirings/rpc/rpc-runner.d.ts +19 -0
- package/dist/wirings/rpc/rpc-runner.js +109 -3
- package/dist/wirings/rpc/rpc-types.d.ts +15 -1
- package/dist/wirings/rpc/wire-addon.js +9 -0
- package/dist/wirings/rpc/wire-remote-addon.d.ts +47 -0
- package/dist/wirings/rpc/wire-remote-addon.js +19 -0
- package/dist/wirings/scope/index.d.ts +3 -0
- package/dist/wirings/scope/index.js +2 -0
- package/dist/wirings/scope/scope.types.d.ts +39 -0
- package/dist/wirings/scope/scope.types.js +1 -0
- package/dist/wirings/scope/validate-scope-definitions.d.ts +16 -0
- package/dist/wirings/scope/validate-scope-definitions.js +76 -0
- package/dist/wirings/scope/wire-scope.d.ts +33 -0
- package/dist/wirings/scope/wire-scope.js +32 -0
- package/dist/wirings/secret/secret.types.d.ts +14 -0
- package/dist/wirings/secret/validate-secret-definitions.js +2 -0
- package/dist/wirings/variable/validate-variable-definitions.js +2 -0
- package/dist/wirings/variable/variable.types.d.ts +14 -0
- package/dist/wirings/workflow/dsl/index.d.ts +1 -1
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +89 -7
- package/dist/wirings/workflow/graph/graph-node.d.ts +2 -0
- package/dist/wirings/workflow/graph/graph-runner.js +3 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +6 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.js +1 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +5 -0
- package/dist/wirings/workflow/index.d.ts +2 -2
- package/dist/wirings/workflow/index.js +1 -1
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +59 -1
- package/dist/wirings/workflow/pikku-workflow-service.js +187 -0
- package/dist/wirings/workflow/workflow.types.d.ts +1 -3
- package/package.json +6 -1
- package/run-tests.sh +1 -0
- package/src/dev/hot-reload.ts +13 -68
- package/src/dev/module-runner.test.ts +169 -0
- package/src/dev/module-runner.ts +103 -0
- package/src/dev/reload-meta.test.ts +31 -2
- package/src/dev/reload-meta.ts +26 -0
- package/src/errors/errors.ts +24 -0
- package/src/function/function-runner.test.ts +276 -142
- package/src/function/function-runner.ts +52 -145
- package/src/function/functions.types.ts +28 -38
- package/src/index.ts +8 -6
- package/src/middleware/index.ts +1 -5
- package/src/permissions.test.ts +160 -373
- package/src/permissions.ts +137 -279
- package/src/pikku-state.ts +0 -2
- package/src/scopes.test.ts +167 -0
- package/src/scopes.ts +69 -0
- package/src/services/ai-embedding-service.ts +31 -0
- package/src/services/credential-wire-service.ts +10 -4
- package/src/services/index.ts +20 -0
- package/src/services/meta-service.ts +68 -3
- package/src/services/queue-webhook-service.test.ts +408 -0
- package/src/services/queue-webhook-service.ts +182 -0
- package/src/services/scope-service.ts +75 -0
- package/src/services/typed-secret-service.test.ts +35 -0
- package/src/services/typed-secret-service.ts +39 -4
- package/src/services/webhook-service.ts +180 -0
- package/src/services/workflow-service.ts +7 -0
- package/src/testing/service-tests.ts +49 -0
- package/src/types/core.types.ts +42 -14
- package/src/types/state.types.ts +23 -3
- package/src/utils/hmac.ts +27 -0
- package/src/utils/safe-fetch.test.ts +373 -0
- package/src/utils/safe-fetch.ts +213 -0
- package/src/wirings/ai-agent/ai-agent-agui.test.ts +1127 -0
- package/src/wirings/ai-agent/ai-agent-agui.ts +386 -0
- package/src/wirings/ai-agent/ai-agent-authorization.test.ts +204 -0
- package/src/wirings/ai-agent/ai-agent-prepare.test.ts +483 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +324 -13
- package/src/wirings/ai-agent/ai-agent-resume-authorization.test.ts +207 -0
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +48 -1
- package/src/wirings/ai-agent/ai-agent-runner.ts +28 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +301 -10
- package/src/wirings/ai-agent/ai-agent-stream.ts +122 -16
- package/src/wirings/ai-agent/ai-agent.types.ts +57 -0
- package/src/wirings/ai-agent/index.ts +5 -0
- package/src/wirings/ai-agent/voice-input.test.ts +90 -0
- package/src/wirings/ai-agent/voice-input.ts +9 -40
- package/src/wirings/channel/channel-common.ts +0 -1
- package/src/wirings/channel/channel-handler.ts +1 -9
- package/src/wirings/channel/channel-middleware-runner.test.ts +28 -2
- package/src/wirings/channel/channel-middleware-runner.ts +39 -27
- package/src/wirings/channel/channel.types.ts +0 -6
- package/src/wirings/cli/cli-runner.ts +4 -2
- package/src/wirings/cli/cli.types.ts +0 -2
- package/src/wirings/cli/command-parser.test.ts +130 -0
- package/src/wirings/cli/command-parser.ts +80 -2
- package/src/wirings/credential/credential.types.ts +14 -0
- package/src/wirings/credential/validate-credential-definitions.ts +1 -0
- package/src/wirings/gateway/gateway-authorization.test.ts +444 -0
- package/src/wirings/gateway/gateway-runner.ts +114 -68
- package/src/wirings/gateway/gateway.types.ts +7 -9
- package/src/wirings/http/http-routes.ts +0 -3
- package/src/wirings/http/http-runner.test.ts +1 -11
- package/src/wirings/http/http-runner.ts +16 -39
- package/src/wirings/http/http.types.ts +7 -14
- package/src/wirings/mcp/mcp-runner.ts +0 -2
- package/src/wirings/mcp/mcp.types.ts +3 -11
- package/src/wirings/oauth2/index.ts +0 -3
- package/src/wirings/rpc/addon-runner.ts +233 -0
- package/src/wirings/rpc/index.ts +17 -1
- package/src/wirings/rpc/remote-addon-auth.ts +69 -0
- package/src/wirings/rpc/rpc-runner.test.ts +319 -16
- package/src/wirings/rpc/rpc-runner.ts +155 -3
- package/src/wirings/rpc/rpc-types.ts +16 -5
- package/src/wirings/rpc/wire-addon.test.ts +6 -3
- package/src/wirings/rpc/wire-addon.ts +9 -0
- package/src/wirings/rpc/wire-remote-addon.ts +57 -0
- package/src/wirings/scope/index.ts +14 -0
- package/src/wirings/scope/scope.test.ts +135 -0
- package/src/wirings/scope/scope.types.ts +44 -0
- package/src/wirings/scope/validate-scope-definitions.ts +110 -0
- package/src/wirings/scope/wire-scope.ts +34 -0
- package/src/wirings/secret/secret.types.ts +14 -0
- package/src/wirings/secret/validate-secret-definitions.ts +2 -0
- package/src/wirings/variable/validate-variable-definitions.ts +2 -0
- package/src/wirings/variable/variable.types.ts +14 -0
- package/src/wirings/workflow/dsl/index.ts +4 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +97 -6
- package/src/wirings/workflow/graph/graph-node.ts +2 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +58 -0
- package/src/wirings/workflow/graph/graph-runner.ts +3 -0
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +7 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +5 -0
- package/src/wirings/workflow/index.ts +5 -0
- package/src/wirings/workflow/pikku-workflow-service.test.ts +341 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +272 -0
- package/src/wirings/workflow/workflow-on-error.test.ts +154 -0
- package/src/wirings/workflow/workflow-step-session.test.ts +21 -5
- package/src/wirings/workflow/workflow.types.ts +4 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/src/wirings/oauth2/oauth2-client.test.ts +0 -930
- package/src/wirings/oauth2/oauth2-client.ts +0 -331
- package/src/wirings/oauth2/oauth2-routes.ts +0 -234
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { compileFunction } from 'node:vm'
|
|
6
|
+
import type { transformSync as EsbuildTransformSync } from 'esbuild'
|
|
7
|
+
|
|
8
|
+
// Evictable module runner for hot-reload.
|
|
9
|
+
//
|
|
10
|
+
// Re-importing a changed user file through the native ESM loader (a fresh
|
|
11
|
+
// `data:` URL on Node, a fresh temp-file path on Bun) is unbounded: the loader
|
|
12
|
+
// keeps a `Map<url, moduleRecord>` for the realm lifetime with no eviction API,
|
|
13
|
+
// so every reload permanently leaks a module record and the dev server
|
|
14
|
+
// eventually OOMs (worse on Bun). Instead we own the registry: transpile the
|
|
15
|
+
// source to CJS (esbuild), run it as a plain function via `vm.compileFunction`
|
|
16
|
+
// — which produces a garbage-collectable function rather than a permanent
|
|
17
|
+
// loader entry — and store the resulting exports under a STABLE path key. A
|
|
18
|
+
// reload overwrites that one slot, so the previous module becomes unreachable
|
|
19
|
+
// and is collected. `import`s inside the user file are delegated to
|
|
20
|
+
// `createRequire`, whose resolution matches the native loader AND returns the
|
|
21
|
+
// same live singletons (Node/Bun share the require/import module cache), so
|
|
22
|
+
// top-level side effects (wireHTTP et al) mutate the same running services.
|
|
23
|
+
type EsbuildTransform = typeof EsbuildTransformSync
|
|
24
|
+
|
|
25
|
+
let transformSync: EsbuildTransform | undefined
|
|
26
|
+
|
|
27
|
+
const loadTransform = async (): Promise<EsbuildTransform> => {
|
|
28
|
+
if (transformSync) return transformSync
|
|
29
|
+
// esbuild is a dev-only dependency, hoisted from @pikku/cli at runtime — the
|
|
30
|
+
// same lazy pattern the reloader previously used for tsx. It is never loaded
|
|
31
|
+
// in production runtimes (the `./dev` export is dev-only).
|
|
32
|
+
const esbuild = await import('esbuild')
|
|
33
|
+
transformSync = esbuild.transformSync
|
|
34
|
+
return transformSync
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PikkuModuleRunner {
|
|
38
|
+
/** Run a user module by absolute path, returning its exports. Repeated runs
|
|
39
|
+
* of the same path overwrite a single registry slot (the previous module is
|
|
40
|
+
* collected). Returns `null` if transpile/compile/evaluation fails, so the
|
|
41
|
+
* caller can keep the previously-loaded code. */
|
|
42
|
+
run: (absPath: string) => Promise<Record<string, unknown> | null>
|
|
43
|
+
/** Drop a single module from the registry. */
|
|
44
|
+
evict: (absPath: string) => void
|
|
45
|
+
/** Drop every module from the registry. */
|
|
46
|
+
clear: () => void
|
|
47
|
+
/** Number of modules currently held. */
|
|
48
|
+
readonly size: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const createModuleRunner = (): PikkuModuleRunner => {
|
|
52
|
+
const registry = new Map<string, Record<string, unknown>>()
|
|
53
|
+
|
|
54
|
+
const run = async (
|
|
55
|
+
filePath: string
|
|
56
|
+
): Promise<Record<string, unknown> | null> => {
|
|
57
|
+
const absPath = resolve(filePath)
|
|
58
|
+
try {
|
|
59
|
+
const transform = await loadTransform()
|
|
60
|
+
const source = await readFile(absPath, 'utf-8')
|
|
61
|
+
// No sourcemap: an inline sourcemap embeds a base64 copy of the source
|
|
62
|
+
// that the engine retains per compile, reintroducing linear growth on
|
|
63
|
+
// Node — the exact leak this runner exists to remove. `filename` still
|
|
64
|
+
// anchors stack traces to the user file.
|
|
65
|
+
const { code } = transform(source, {
|
|
66
|
+
loader: absPath.endsWith('.ts') ? 'ts' : 'js',
|
|
67
|
+
format: 'cjs',
|
|
68
|
+
sourcefile: absPath,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const fn = compileFunction(
|
|
72
|
+
code,
|
|
73
|
+
['require', 'exports', 'module', '__filename', '__dirname'],
|
|
74
|
+
{ filename: absPath }
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
const require = createRequire(pathToFileURL(absPath))
|
|
78
|
+
const moduleObj: { exports: Record<string, unknown> } = { exports: {} }
|
|
79
|
+
fn(require, moduleObj.exports, moduleObj, absPath, dirname(absPath))
|
|
80
|
+
|
|
81
|
+
registry.set(absPath, moduleObj.exports)
|
|
82
|
+
return moduleObj.exports
|
|
83
|
+
} catch {
|
|
84
|
+
// Transpile/compile/evaluate failure (a bad edit, or the one known
|
|
85
|
+
// limitation — a file using top-level `await`, which can't be emitted in
|
|
86
|
+
// `cjs` form). Return null so the caller keeps the previously-loaded code.
|
|
87
|
+
return null
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
run,
|
|
93
|
+
evict: (filePath: string) => {
|
|
94
|
+
registry.delete(resolve(filePath))
|
|
95
|
+
},
|
|
96
|
+
clear: () => {
|
|
97
|
+
registry.clear()
|
|
98
|
+
},
|
|
99
|
+
get size() {
|
|
100
|
+
return registry.size
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -6,7 +6,8 @@ import { tmpdir } from 'node:os'
|
|
|
6
6
|
|
|
7
7
|
import { pikkuState, resetPikkuState } from '../pikku-state.js'
|
|
8
8
|
import { getSchema } from '../schema.js'
|
|
9
|
-
import {
|
|
9
|
+
import { wireAddon } from '../wirings/rpc/wire-addon.js'
|
|
10
|
+
import { reloadGeneratedMeta, reconcileAddonRegistry } from './reload-meta.js'
|
|
10
11
|
|
|
11
12
|
const createMockLogger = () => {
|
|
12
13
|
const logs: Array<{ level: string; message: string }> = []
|
|
@@ -96,7 +97,9 @@ describe('reloadGeneratedMeta', { concurrency: false }, () => {
|
|
|
96
97
|
)
|
|
97
98
|
await writeFile(
|
|
98
99
|
join(tmpDir, 'queue/pikku-queue-workers-wirings-meta.gen.json'),
|
|
99
|
-
JSON.stringify({
|
|
100
|
+
JSON.stringify({
|
|
101
|
+
userQueue: { pikkuFuncId: 'userFunc', name: 'userQueue' },
|
|
102
|
+
})
|
|
100
103
|
)
|
|
101
104
|
|
|
102
105
|
await reloadGeneratedMeta({
|
|
@@ -152,3 +155,29 @@ describe('reloadGeneratedMeta', { concurrency: false }, () => {
|
|
|
152
155
|
assert.deepEqual(errors, [])
|
|
153
156
|
})
|
|
154
157
|
})
|
|
158
|
+
|
|
159
|
+
describe('reconcileAddonRegistry', { concurrency: false }, () => {
|
|
160
|
+
beforeEach(() => resetPikkuState())
|
|
161
|
+
|
|
162
|
+
test('drops addons the fresh generation no longer declares', () => {
|
|
163
|
+
wireAddon({ name: 'gmail', package: '@pikku/addon-gmail' })
|
|
164
|
+
wireAddon({ name: 'mandrill-e2e', package: '@pikku/addon-mandrill' })
|
|
165
|
+
|
|
166
|
+
// gmail is still wired in source; mandrill-e2e's *.addon.ts was deleted.
|
|
167
|
+
reconcileAddonRegistry(['gmail'])
|
|
168
|
+
|
|
169
|
+
const addons = pikkuState(null, 'addons', 'packages')
|
|
170
|
+
assert.ok(addons.has('gmail'), 'still-declared addon is kept')
|
|
171
|
+
assert.ok(!addons.has('mandrill-e2e'), 'deleted addon is pruned')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('keeps every addon when all are still declared', () => {
|
|
175
|
+
wireAddon({ name: 'gmail', package: '@pikku/addon-gmail' })
|
|
176
|
+
wireAddon({ name: 'mailgun', package: '@pikku/addon-mailgun' })
|
|
177
|
+
|
|
178
|
+
reconcileAddonRegistry(['gmail', 'mailgun'])
|
|
179
|
+
|
|
180
|
+
const addons = pikkuState(null, 'addons', 'packages')
|
|
181
|
+
assert.equal(addons.size, 2)
|
|
182
|
+
})
|
|
183
|
+
})
|
package/src/dev/reload-meta.ts
CHANGED
|
@@ -136,3 +136,29 @@ export async function reloadGeneratedMeta(
|
|
|
136
136
|
)
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Prunes the live addon registry down to what the current source still declares.
|
|
142
|
+
*
|
|
143
|
+
* Dev hot-reload re-imports only changed/added files, so a deleted `*.addon.ts`
|
|
144
|
+
* leaves its `wireAddon` entry stranded in `pikkuState(null,'addons','packages')`
|
|
145
|
+
* until a full restart — the reason `getInstalledAddons` reports removed addons.
|
|
146
|
+
* The Map holds definitions (namespace → package config), not runtime state, so
|
|
147
|
+
* dropping any namespace the fresh inspection no longer declares is safe.
|
|
148
|
+
*
|
|
149
|
+
* `declaredNamespaces` is the set of `wireAddon` names from the just-regenerated
|
|
150
|
+
* inspection (`inspectorState.rpc.wireAddonDeclarations.keys()`).
|
|
151
|
+
*/
|
|
152
|
+
export function reconcileAddonRegistry(
|
|
153
|
+
declaredNamespaces: Iterable<string>,
|
|
154
|
+
logger?: Logger
|
|
155
|
+
): void {
|
|
156
|
+
const declared = new Set(declaredNamespaces)
|
|
157
|
+
const addons = pikkuState(null, 'addons', 'packages')
|
|
158
|
+
for (const namespace of [...addons.keys()]) {
|
|
159
|
+
if (!declared.has(namespace)) {
|
|
160
|
+
addons.delete(namespace)
|
|
161
|
+
logger?.info(`• Removed unwired addon "${namespace}"`)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
package/src/errors/errors.ts
CHANGED
|
@@ -120,6 +120,30 @@ addError(MissingCredentialError, {
|
|
|
120
120
|
message: 'A required credential is not configured.',
|
|
121
121
|
})
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* The session does not hold a scope required by the function. The payload
|
|
125
|
+
* names the missing scope so the client can surface what to request.
|
|
126
|
+
* @group Error
|
|
127
|
+
*/
|
|
128
|
+
export class MissingScopeError extends PikkuError {
|
|
129
|
+
public payload: {
|
|
130
|
+
error: 'missing_scope'
|
|
131
|
+
scope: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
constructor(scope: string) {
|
|
135
|
+
super(`Missing required scope: ${scope}`)
|
|
136
|
+
this.payload = {
|
|
137
|
+
error: 'missing_scope',
|
|
138
|
+
scope,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
addError(MissingScopeError, {
|
|
143
|
+
status: 403,
|
|
144
|
+
message: 'The session does not hold a scope required by this function.',
|
|
145
|
+
})
|
|
146
|
+
|
|
123
147
|
/**
|
|
124
148
|
* The session is readonly and cannot access a non-readonly function.
|
|
125
149
|
* @group Error
|