@pikku/inspector 0.12.60 → 0.12.61
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 +301 -0
- package/OPTIMIZATION-PLAN.md +19 -19
- package/dist/add/add-auth.js +1 -1
- package/dist/add/add-channel.d.ts +1 -1
- package/dist/add/add-cli.js +5 -0
- package/dist/add/add-functions.js +10 -1
- package/dist/add/add-http-route.js +18 -18
- package/dist/add/add-keyed-wiring.d.ts +2 -0
- package/dist/add/add-keyed-wiring.js +3 -1
- package/dist/add/add-personas.js +4 -1
- package/dist/add/add-secret.js +1 -0
- package/dist/add/add-variable.js +1 -0
- package/dist/add/add-wire-remote-addon.js +2 -1
- package/dist/add/add-workflow-graph.js +63 -6
- package/dist/add/add-workflow.d.ts +1 -1
- package/dist/error-codes.d.ts +3 -1
- package/dist/error-codes.js +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/inspector.js +12 -2
- package/dist/types.d.ts +25 -21
- package/dist/utils/annotate-http-route-auth.js +2 -1
- package/dist/utils/check-secret-sinks.js +2 -1
- package/dist/utils/compute-required-schemas.d.ts +1 -1
- package/dist/utils/contract-hashes.d.ts +2 -2
- package/dist/utils/contract-hashes.js +1 -1
- package/dist/utils/extract-function-name.js +1 -1
- package/dist/utils/extract-services.d.ts +1 -1
- package/dist/utils/extract-surface-usage.d.ts +29 -0
- package/dist/utils/extract-surface-usage.js +97 -0
- package/dist/utils/filter-inspector-state.js +53 -16
- package/dist/utils/filter-utils.d.ts +1 -1
- package/dist/utils/get-property-value.js +42 -3
- package/dist/utils/load-addon-functions-meta.js +31 -0
- package/dist/utils/middleware.d.ts +1 -1
- package/dist/utils/permissions.d.ts +1 -1
- package/dist/utils/post-process.d.ts +27 -7
- package/dist/utils/post-process.js +79 -14
- package/dist/utils/resolve-deploy-target.d.ts +1 -1
- package/dist/utils/resolve-function-meta.d.ts +1 -1
- package/dist/utils/resolve-function-types.d.ts +1 -1
- package/dist/utils/resolve-versions.js +1 -1
- package/dist/utils/schema-generator.d.ts +1 -1
- package/dist/utils/serialize-inspector-state.d.ts +2 -1
- package/dist/utils/serialize-inspector-state.js +2 -0
- package/dist/utils/serialize-openapi-json.d.ts +2 -2
- package/dist/utils/validate-auth-sessionless.js +2 -1
- package/dist/utils/workflow/derive-workflow-plan.d.ts +1 -1
- package/dist/utils/workflow/dsl/extract-dsl-workflow.d.ts +1 -1
- package/dist/utils/workflow/graph/convert-dsl-to-graph.d.ts +1 -1
- package/dist/utils/workflow/graph/finalize-workflows.js +1 -1
- package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +6 -1
- package/dist/utils/workflow/graph/serialize-workflow-graph.js +26 -2
- package/dist/utils/workflow/graph/workflow-graph.types.d.ts +11 -2
- package/package.json +10 -10
- package/run-tests.sh +0 -0
- package/src/add/add-agent.ts +2 -4
- package/src/add/add-auth.ts +2 -2
- package/src/add/add-channel.ts +1 -4
- package/src/add/add-cli.ts +7 -1
- package/src/add/add-credential.ts +3 -6
- package/src/add/add-file-with-factory.ts +2 -6
- package/src/add/add-functions.ts +24 -31
- package/src/add/add-gateway.ts +1 -1
- package/src/add/add-http-route-ref.test.ts +149 -0
- package/src/add/add-http-route.ts +26 -29
- package/src/add/add-keyed-wiring.ts +8 -7
- package/src/add/add-permission.ts +1 -1
- package/src/add/add-personas.test.ts +26 -2
- package/src/add/add-personas.ts +4 -3
- package/src/add/add-scenario-step.test.ts +37 -2
- package/src/add/add-scope.test.ts +15 -15
- package/src/add/add-scope.ts +5 -9
- package/src/add/add-secret.ts +1 -0
- package/src/add/add-system-role.test.ts +4 -4
- package/src/add/add-system-role.ts +2 -4
- package/src/add/add-variable.ts +1 -0
- package/src/add/add-wire-remote-addon.ts +4 -1
- package/src/add/add-workflow-graph-foreach.test.ts +174 -0
- package/src/add/add-workflow-graph-input.test.ts +1 -1
- package/src/add/add-workflow-graph.ts +78 -6
- package/src/add/add-workflow-sleep-expression.test.ts +3 -4
- package/src/add/add-workflow.ts +1 -4
- package/src/add/addon-contracts.test.ts +1 -1
- package/src/add/config-value-metadata.test.ts +94 -0
- package/src/add/secret-sink-check.test.ts +4 -1
- package/src/error-codes.ts +3 -1
- package/src/index.ts +3 -4
- package/src/inspector.ts +19 -2
- package/src/types.ts +25 -28
- package/src/utils/annotate-http-route-auth.test.ts +5 -7
- package/src/utils/annotate-http-route-auth.ts +2 -1
- package/src/utils/check-secret-sinks.ts +4 -1
- package/src/utils/compute-required-schemas.ts +1 -1
- package/src/utils/contract-hashes.test.ts +1 -1
- package/src/utils/contract-hashes.ts +3 -3
- package/src/utils/extract-function-name.ts +1 -1
- package/src/utils/extract-services.ts +1 -2
- package/src/utils/extract-surface-usage.test.ts +147 -0
- package/src/utils/extract-surface-usage.ts +121 -0
- package/src/utils/filter-inspector-state.test.ts +138 -12
- package/src/utils/filter-inspector-state.ts +82 -21
- package/src/utils/filter-utils.ts +1 -1
- package/src/utils/get-property-value.ts +43 -5
- package/src/utils/load-addon-functions-meta.ts +40 -0
- package/src/utils/middleware.ts +1 -1
- package/src/utils/permissions.ts +1 -1
- package/src/utils/post-process.test.ts +59 -2
- package/src/utils/post-process.ts +88 -25
- package/src/utils/resolve-deploy-target.ts +1 -1
- package/src/utils/resolve-function-meta.ts +1 -4
- package/src/utils/resolve-function-types.ts +1 -1
- package/src/utils/resolve-versions.ts +2 -5
- package/src/utils/schema-generator.ts +3 -3
- package/src/utils/serialize-inspector-state.ts +4 -1
- package/src/utils/serialize-mcp-json.ts +1 -1
- package/src/utils/serialize-openapi-json.ts +2 -2
- package/src/utils/validate-auth-sessionless.ts +2 -1
- package/src/utils/validate-tags-resolve-to-middleware.test.ts +4 -1
- package/src/utils/workflow/derive-workflow-plan.test.ts +1 -1
- package/src/utils/workflow/derive-workflow-plan.ts +1 -1
- package/src/utils/workflow/dsl/extract-approval-policy.test.ts +1 -1
- package/src/utils/workflow/dsl/extract-dsl-workflow.ts +2 -2
- package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +1 -1
- package/src/utils/workflow/graph/convert-dsl-to-graph.ts +1 -4
- package/src/utils/workflow/graph/finalize-workflow-wires.ts +1 -1
- package/src/utils/workflow/graph/finalize-workflows.ts +2 -2
- package/src/utils/workflow/graph/serialize-workflow-graph.ts +34 -3
- package/src/utils/workflow/graph/workflow-graph.types.ts +12 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/add/add-ai-agent.d.ts +0 -4
- package/dist/add/add-ai-agent.js +0 -442
- package/dist/add/add-ai-scorer.d.ts +0 -2
- package/dist/add/add-ai-scorer.js +0 -61
- package/dist/utils/secret-brokers.d.ts +0 -2
- package/dist/utils/secret-brokers.js +0 -9
|
@@ -7,13 +7,15 @@ import {
|
|
|
7
7
|
import type { AddWiring, InspectorState } from '../types.js'
|
|
8
8
|
import { ErrorCode } from '../error-codes.js'
|
|
9
9
|
import { detectSchemaVendorOrError } from '../utils/detect-schema-vendor.js'
|
|
10
|
-
import { parseDurationString } from '@pikku/core/
|
|
10
|
+
import { parseDurationString } from '@pikku/core/utils'
|
|
11
11
|
|
|
12
12
|
export interface KeyedWiringConfig {
|
|
13
13
|
functionName: string
|
|
14
14
|
idField: string
|
|
15
15
|
label: string
|
|
16
16
|
schemaPrefix: string
|
|
17
|
+
/** Boolean property carrying this wiring kind's deploy-gate opt-in/opt-out. */
|
|
18
|
+
flagField: string
|
|
17
19
|
getState: (state: InspectorState) => {
|
|
18
20
|
definitions: any[]
|
|
19
21
|
files: Set<string>
|
|
@@ -49,17 +51,15 @@ export const createAddKeyedWiring = (config: KeyedWiringConfig): AddWiring => {
|
|
|
49
51
|
|
|
50
52
|
const nameValue = getPropertyValue(obj, 'name') as string | null
|
|
51
53
|
const displayNameValue = getPropertyValue(obj, 'displayName') as
|
|
52
|
-
|
|
|
53
|
-
| null
|
|
54
|
+
string | null
|
|
54
55
|
const descriptionValue = getPropertyValue(obj, 'description') as
|
|
55
|
-
|
|
|
56
|
-
| null
|
|
56
|
+
string | null
|
|
57
57
|
const rotationPeriodValue = getPropertyValue(obj, 'rotationPeriod') as
|
|
58
|
-
|
|
|
59
|
-
| null
|
|
58
|
+
string | null
|
|
60
59
|
const docsUrlValue = getPropertyValue(obj, 'docsUrl') as string | null
|
|
61
60
|
const allowedHostsValue = getArrayPropertyValue(obj, 'allowedHosts')
|
|
62
61
|
const idValue = getPropertyValue(obj, config.idField) as string | null
|
|
62
|
+
const flagValue = getPropertyValue(obj, config.flagField) === true
|
|
63
63
|
|
|
64
64
|
let schemaVariableName: string | null = null
|
|
65
65
|
let schemaSourceFile: string | null = null
|
|
@@ -171,6 +171,7 @@ export const createAddKeyedWiring = (config: KeyedWiringConfig): AddWiring => {
|
|
|
171
171
|
docsUrl: docsUrlValue || undefined,
|
|
172
172
|
allowedHosts: allowedHostsValue || undefined,
|
|
173
173
|
[config.idField]: idValue,
|
|
174
|
+
[config.flagField]: flagValue || undefined,
|
|
174
175
|
schema: schemaLookupName,
|
|
175
176
|
sourceFile,
|
|
176
177
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from 'typescript'
|
|
2
|
-
import type { FunctionWiresMeta } from '@pikku/core/
|
|
2
|
+
import type { FunctionWiresMeta } from '@pikku/core/function'
|
|
3
3
|
import type { AddWiring } from '../types.js'
|
|
4
4
|
import { extractFunctionName } from '../utils/extract-function-name.js'
|
|
5
5
|
import {
|
|
@@ -57,8 +57,8 @@ const inspectSources = async (sources: Record<string, string>) => {
|
|
|
57
57
|
/** The declared world every persona below is checked against. */
|
|
58
58
|
const withRoles = (...lines: string[]) =>
|
|
59
59
|
[
|
|
60
|
-
"import { defineScope } from '@pikku/core/
|
|
61
|
-
"import { defineSystemRole } from '@pikku/core/
|
|
60
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
61
|
+
"import { defineSystemRole } from '@pikku/core/role'",
|
|
62
62
|
"import { definePersonas } from '@pikku/core/persona'",
|
|
63
63
|
'defineScope({ catalogue: { scopes: { read: {} } }, admin: {} })',
|
|
64
64
|
'defineSystemRole({',
|
|
@@ -108,6 +108,30 @@ describe('addPersonas inspector', () => {
|
|
|
108
108
|
assert.equal(susan.runnable, true)
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
+
test('the app a person signs into survives into the meta', async () => {
|
|
112
|
+
const { state, criticals } = await inspectSource(
|
|
113
|
+
withRoles(
|
|
114
|
+
'definePersonas({',
|
|
115
|
+
' susan: {',
|
|
116
|
+
" name: 'Susan',",
|
|
117
|
+
" app: 'storefront',",
|
|
118
|
+
' },',
|
|
119
|
+
'})'
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
assert.deepEqual(criticals, [])
|
|
124
|
+
assert.equal(state.personas.definitions[0]!.app, 'storefront')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('a person who names no app has none, rather than a guessed one', async () => {
|
|
128
|
+
const { state } = await inspectSource(
|
|
129
|
+
withRoles('definePersonas({', " susan: { name: 'Susan' },", '})')
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
assert.equal(state.personas.definitions[0]!.app, undefined)
|
|
133
|
+
})
|
|
134
|
+
|
|
111
135
|
test('extracts a declared avatar', async () => {
|
|
112
136
|
const { state } = await inspectSource(
|
|
113
137
|
withRoles(
|
package/src/add/add-personas.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as ts from 'typescript'
|
|
2
|
-
import { DISPOSITIONS } from '@pikku/core/
|
|
2
|
+
import { DISPOSITIONS } from '@pikku/core/virtual-user'
|
|
3
3
|
import { isRunnablePersona } from '@pikku/core/persona'
|
|
4
|
-
import type { PersonaMeta } from '@pikku/core/persona'
|
|
5
|
-
import type { PersonaAccountMeta } from '@pikku/core/ecosystem/persona'
|
|
4
|
+
import type { PersonaMeta, PersonaAccountMeta } from '@pikku/core/persona'
|
|
6
5
|
import { ErrorCode } from '../error-codes.js'
|
|
7
6
|
import { claimSingleDeclaration } from '../utils/single-declaration.js'
|
|
8
7
|
import type { AddWiring, InspectorLogger } from '../types.js'
|
|
@@ -266,6 +265,8 @@ export const addPersonas: AddWiring = (logger, node, _checker, state) => {
|
|
|
266
265
|
if (avatarUrl !== undefined) persona.avatarUrl = avatarUrl
|
|
267
266
|
const personality = stringProperty(config, 'personality')
|
|
268
267
|
if (personality !== undefined) persona.personality = personality
|
|
268
|
+
const app = stringProperty(config, 'app')
|
|
269
|
+
if (app !== undefined) persona.app = app
|
|
269
270
|
if (disposition !== undefined) {
|
|
270
271
|
persona.disposition = disposition as PersonaMeta['disposition']
|
|
271
272
|
}
|
|
@@ -5,8 +5,8 @@ import { tmpdir } from 'node:os'
|
|
|
5
5
|
import { join } from 'node:path'
|
|
6
6
|
import { inspect } from '../inspector.js'
|
|
7
7
|
import type { InspectorLogger } from '../types.js'
|
|
8
|
-
import type { WorkflowStepMeta } from '@pikku/core/
|
|
9
|
-
import type { ScenarioStepMeta } from '@pikku/core/
|
|
8
|
+
import type { WorkflowStepMeta } from '@pikku/core/workflow'
|
|
9
|
+
import type { ScenarioStepMeta } from '@pikku/core/scenario'
|
|
10
10
|
|
|
11
11
|
function makeLogger(
|
|
12
12
|
criticals: Array<{ code: string; message: string }>
|
|
@@ -39,6 +39,12 @@ const STEPS = [
|
|
|
39
39
|
" description: 'sees a receipt',",
|
|
40
40
|
' default: async ({ logger }) => ({ ok: true }),',
|
|
41
41
|
'})',
|
|
42
|
+
'export const asksForTheReceipt = pikkuScenarioStep({',
|
|
43
|
+
" name: 'asksForTheReceipt',",
|
|
44
|
+
" description: 'asks for the receipt',",
|
|
45
|
+
' actor: true,',
|
|
46
|
+
' default: async ({ logger }) => ({ ok: true }),',
|
|
47
|
+
'})',
|
|
42
48
|
].join('\n')
|
|
43
49
|
|
|
44
50
|
const scenarioSource = (body: string[], preamble: string[] = []) =>
|
|
@@ -210,6 +216,35 @@ describe('pikkuScenarioStep', () => {
|
|
|
210
216
|
}
|
|
211
217
|
})
|
|
212
218
|
|
|
219
|
+
test('a step declaring `actor: true` called without one is a PKU677 critical', async () => {
|
|
220
|
+
const { criticals, cleanup } = await run([
|
|
221
|
+
"await scenario.then('asks for the receipt', 'asksForTheReceipt', {})",
|
|
222
|
+
])
|
|
223
|
+
try {
|
|
224
|
+
assert.ok(
|
|
225
|
+
criticals.find((c) => c.code === 'PKU677'),
|
|
226
|
+
`a step that says it runs as somebody must be given somebody, browser binding or not, got: ${JSON.stringify(criticals)}`
|
|
227
|
+
)
|
|
228
|
+
} finally {
|
|
229
|
+
await cleanup()
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('a step that declares no actor is not flagged for running without one', async () => {
|
|
234
|
+
const { criticals, cleanup } = await run([
|
|
235
|
+
"await scenario.then('sees a receipt', 'seesAReceipt', {})",
|
|
236
|
+
])
|
|
237
|
+
try {
|
|
238
|
+
assert.equal(
|
|
239
|
+
criticals.filter((c) => c.code === 'PKU677').length,
|
|
240
|
+
0,
|
|
241
|
+
`an assertion over an earlier step's value has nobody to be, got: ${JSON.stringify(criticals)}`
|
|
242
|
+
)
|
|
243
|
+
} finally {
|
|
244
|
+
await cleanup()
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
213
248
|
test('a scenario that never asserts is a PKU680 critical', async () => {
|
|
214
249
|
const { criticals, cleanup } = await run([
|
|
215
250
|
"await scenario.given('buys an apple', 'buysAnApple', { qty: 1 }, { actor: actors.shopper })",
|
|
@@ -58,7 +58,7 @@ describe('addScope inspector', () => {
|
|
|
58
58
|
test('extracts a flat scope', async () => {
|
|
59
59
|
const { state, criticals } = await inspectSource(
|
|
60
60
|
[
|
|
61
|
-
"import { defineScope } from '@pikku/core/
|
|
61
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
62
62
|
'defineScope({',
|
|
63
63
|
' admin: {',
|
|
64
64
|
" displayName: 'Administration',",
|
|
@@ -81,7 +81,7 @@ describe('addScope inspector', () => {
|
|
|
81
81
|
test('extracts a displayName at every depth', async () => {
|
|
82
82
|
const { state, criticals } = await inspectSource(
|
|
83
83
|
[
|
|
84
|
-
"import { defineScope } from '@pikku/core/
|
|
84
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
85
85
|
'defineScope({',
|
|
86
86
|
' admin: {',
|
|
87
87
|
" displayName: 'Administration',",
|
|
@@ -109,7 +109,7 @@ describe('addScope inspector', () => {
|
|
|
109
109
|
test('extracts a nested scope tree', async () => {
|
|
110
110
|
const { state, criticals } = await inspectSource(
|
|
111
111
|
[
|
|
112
|
-
"import { defineScope } from '@pikku/core/
|
|
112
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
113
113
|
'defineScope({',
|
|
114
114
|
' admin: {',
|
|
115
115
|
' scopes: {',
|
|
@@ -139,7 +139,7 @@ describe('addScope inspector', () => {
|
|
|
139
139
|
test('records the source file', async () => {
|
|
140
140
|
const { state, file } = await inspectSource(
|
|
141
141
|
[
|
|
142
|
-
"import { defineScope } from '@pikku/core/
|
|
142
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
143
143
|
'defineScope({ admin: {} })',
|
|
144
144
|
].join('\n')
|
|
145
145
|
)
|
|
@@ -153,7 +153,7 @@ describe('addScope inspector', () => {
|
|
|
153
153
|
test('extracts several roots from one declaration', async () => {
|
|
154
154
|
const { state, criticals } = await inspectSource(
|
|
155
155
|
[
|
|
156
|
-
"import { defineScope } from '@pikku/core/
|
|
156
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
157
157
|
'defineScope({ admin: {}, billing: { scopes: { read: {} } } })',
|
|
158
158
|
].join('\n')
|
|
159
159
|
)
|
|
@@ -169,7 +169,7 @@ describe('addScope inspector', () => {
|
|
|
169
169
|
test('extracts several declarations', async () => {
|
|
170
170
|
const { state } = await inspectSource(
|
|
171
171
|
[
|
|
172
|
-
"import { defineScope } from '@pikku/core/
|
|
172
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
173
173
|
'defineScope({ admin: {} })',
|
|
174
174
|
'defineScope({ billing: {} })',
|
|
175
175
|
].join('\n')
|
|
@@ -188,11 +188,11 @@ describe('addScope inspector', () => {
|
|
|
188
188
|
test('declarations in separate files all survive', async () => {
|
|
189
189
|
const { state, criticals } = await inspectSources({
|
|
190
190
|
'user-admin.gen.ts': [
|
|
191
|
-
"import { defineScope } from '@pikku/core/
|
|
191
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
192
192
|
'defineScope({ admin: {} })',
|
|
193
193
|
].join('\n'),
|
|
194
194
|
'scopes.ts': [
|
|
195
|
-
"import { defineScope } from '@pikku/core/
|
|
195
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
196
196
|
'defineScope({ billing: {} })',
|
|
197
197
|
].join('\n'),
|
|
198
198
|
})
|
|
@@ -214,11 +214,11 @@ describe('addScope inspector', () => {
|
|
|
214
214
|
test('a generated declaration neither claims the slot nor conflicts', async () => {
|
|
215
215
|
const { state, criticals } = await inspectSources({
|
|
216
216
|
'user-admin.gen.ts': [
|
|
217
|
-
"import { defineScope } from '@pikku/core/
|
|
217
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
218
218
|
'defineScope({ admin: {} })',
|
|
219
219
|
].join('\n'),
|
|
220
220
|
'scopes.ts': [
|
|
221
|
-
"import { defineScope } from '@pikku/core/
|
|
221
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
222
222
|
'defineScope({ billing: {} })',
|
|
223
223
|
].join('\n'),
|
|
224
224
|
})
|
|
@@ -238,7 +238,7 @@ describe('addScope inspector', () => {
|
|
|
238
238
|
test('is critical when a root embeds the separator', async () => {
|
|
239
239
|
const { criticals } = await inspectSource(
|
|
240
240
|
[
|
|
241
|
-
"import { defineScope } from '@pikku/core/
|
|
241
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
242
242
|
"defineScope({ 'admin:users': {} })",
|
|
243
243
|
].join('\n')
|
|
244
244
|
)
|
|
@@ -252,7 +252,7 @@ describe('addScope inspector', () => {
|
|
|
252
252
|
test('is critical when a root is the wildcard', async () => {
|
|
253
253
|
const { criticals } = await inspectSource(
|
|
254
254
|
[
|
|
255
|
-
"import { defineScope } from '@pikku/core/
|
|
255
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
256
256
|
"defineScope({ '*': {} })",
|
|
257
257
|
].join('\n')
|
|
258
258
|
)
|
|
@@ -266,7 +266,7 @@ describe('addScope inspector', () => {
|
|
|
266
266
|
test('is critical when a root key is not a literal', async () => {
|
|
267
267
|
const { criticals } = await inspectSource(
|
|
268
268
|
[
|
|
269
|
-
"import { defineScope } from '@pikku/core/
|
|
269
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
270
270
|
'const k = String(1)',
|
|
271
271
|
'defineScope({ [k]: {} } as any)',
|
|
272
272
|
].join('\n')
|
|
@@ -281,7 +281,7 @@ describe('addScope inspector', () => {
|
|
|
281
281
|
test('is critical when a root is not an object literal', async () => {
|
|
282
282
|
const { criticals } = await inspectSource(
|
|
283
283
|
[
|
|
284
|
-
"import { defineScope } from '@pikku/core/
|
|
284
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
285
285
|
"defineScope({ admin: 'nope' } as any)",
|
|
286
286
|
].join('\n')
|
|
287
287
|
)
|
|
@@ -296,7 +296,7 @@ describe('addScope inspector', () => {
|
|
|
296
296
|
describe('validateScopeReferences', () => {
|
|
297
297
|
const funcSource = (scopes: string, decls: string[] = []) =>
|
|
298
298
|
[
|
|
299
|
-
"import { defineScope } from '@pikku/core/
|
|
299
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
300
300
|
"import { pikkuSessionlessFunc } from '@pikku/core'",
|
|
301
301
|
...decls,
|
|
302
302
|
'export const f = pikkuSessionlessFunc({',
|
package/src/add/add-scope.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as ts from 'typescript'
|
|
|
2
2
|
import { getPropertyValue } from '../utils/get-property-value.js'
|
|
3
3
|
import type { AddWiring, InspectorLogger } from '../types.js'
|
|
4
4
|
import { ErrorCode } from '../error-codes.js'
|
|
5
|
-
import type { ScopeNodeMeta } from '@pikku/core/
|
|
5
|
+
import type { ScopeNodeMeta } from '@pikku/core/scope'
|
|
6
6
|
|
|
7
7
|
const SEPARATOR = ':'
|
|
8
8
|
const WILDCARD = '*'
|
|
@@ -88,14 +88,12 @@ const extractScopeNodes = (
|
|
|
88
88
|
|
|
89
89
|
const node: ScopeNodeMeta = {}
|
|
90
90
|
const displayName = getPropertyValue(prop.initializer, 'displayName') as
|
|
91
|
-
|
|
|
92
|
-
| null
|
|
91
|
+
string | null
|
|
93
92
|
if (displayName) {
|
|
94
93
|
node.displayName = displayName
|
|
95
94
|
}
|
|
96
95
|
const description = getPropertyValue(prop.initializer, 'description') as
|
|
97
|
-
|
|
|
98
|
-
| null
|
|
96
|
+
string | null
|
|
99
97
|
if (description) {
|
|
100
98
|
node.description = description
|
|
101
99
|
}
|
|
@@ -192,11 +190,9 @@ export const addScope: AddWiring = (logger, node, checker, state, _options) => {
|
|
|
192
190
|
|
|
193
191
|
const root = prop.initializer
|
|
194
192
|
const displayNameValue = getPropertyValue(root, 'displayName') as
|
|
195
|
-
|
|
|
196
|
-
| null
|
|
193
|
+
string | null
|
|
197
194
|
const descriptionValue = getPropertyValue(root, 'description') as
|
|
198
|
-
|
|
|
199
|
-
| null
|
|
195
|
+
string | null
|
|
200
196
|
|
|
201
197
|
let scopes: Record<string, ScopeNodeMeta> | undefined
|
|
202
198
|
const scopesProp = root.properties.find(
|
package/src/add/add-secret.ts
CHANGED
|
@@ -55,8 +55,8 @@ const inspectSources = async (sources: Record<string, string>) => {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const IMPORTS = [
|
|
58
|
-
"import { defineScope } from '@pikku/core/
|
|
59
|
-
"import { defineSystemRole } from '@pikku/core/
|
|
58
|
+
"import { defineScope } from '@pikku/core/scope'",
|
|
59
|
+
"import { defineSystemRole } from '@pikku/core/role'",
|
|
60
60
|
]
|
|
61
61
|
|
|
62
62
|
const withScopes = (...lines: string[]) =>
|
|
@@ -132,7 +132,7 @@ describe('addSystemRole inspector', () => {
|
|
|
132
132
|
"defineSystemRole({ buyer: { scopes: ['catalogue:read'] } })"
|
|
133
133
|
),
|
|
134
134
|
'more-roles.ts': [
|
|
135
|
-
"import { defineSystemRole } from '@pikku/core/
|
|
135
|
+
"import { defineSystemRole } from '@pikku/core/role'",
|
|
136
136
|
"defineSystemRole({ admin: { scopes: ['admin'] } })",
|
|
137
137
|
].join('\n'),
|
|
138
138
|
})
|
|
@@ -153,7 +153,7 @@ describe('addSystemRole inspector', () => {
|
|
|
153
153
|
test('a generated declaration neither claims the slot nor conflicts', async () => {
|
|
154
154
|
const { state, criticals } = await inspectSources({
|
|
155
155
|
'roles.gen.ts': [
|
|
156
|
-
"import { defineSystemRole } from '@pikku/core/
|
|
156
|
+
"import { defineSystemRole } from '@pikku/core/role'",
|
|
157
157
|
'defineSystemRole({ admin: { scopes: [] } })',
|
|
158
158
|
].join('\n'),
|
|
159
159
|
'roles.ts': withScopes(
|
|
@@ -146,11 +146,9 @@ export const addSystemRole: AddWiring = (
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
const displayName = getPropertyValue(prop.initializer, 'displayName') as
|
|
149
|
-
|
|
|
150
|
-
| null
|
|
149
|
+
string | null
|
|
151
150
|
const description = getPropertyValue(prop.initializer, 'description') as
|
|
152
|
-
|
|
|
153
|
-
| null
|
|
151
|
+
string | null
|
|
154
152
|
|
|
155
153
|
state.systemRoles.files.add(sourceFile)
|
|
156
154
|
state.systemRoles.definitions.push({
|
package/src/add/add-variable.ts
CHANGED
|
@@ -45,7 +45,10 @@ export function addWireRemoteAddon(
|
|
|
45
45
|
) {
|
|
46
46
|
hasAuth = true
|
|
47
47
|
for (const authProp of prop.initializer.properties) {
|
|
48
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
!ts.isPropertyAssignment(authProp) ||
|
|
50
|
+
!ts.isIdentifier(authProp.name)
|
|
51
|
+
)
|
|
49
52
|
continue
|
|
50
53
|
if (
|
|
51
54
|
authProp.name.text === 'credentialId' &&
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { strict as assert } from 'assert'
|
|
2
|
+
import { describe, test } from 'node:test'
|
|
3
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { inspect } from '../inspector.js'
|
|
7
|
+
import type { InspectorLogger } from '../types.js'
|
|
8
|
+
|
|
9
|
+
function makeLogger(): InspectorLogger {
|
|
10
|
+
return {
|
|
11
|
+
debug: () => {},
|
|
12
|
+
info: () => {},
|
|
13
|
+
warn: () => {},
|
|
14
|
+
error: () => {},
|
|
15
|
+
diagnostic: () => {},
|
|
16
|
+
critical: () => {},
|
|
17
|
+
hasCriticalErrors: () => false,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function inspectGraph(graphSource: string[], graphName: string) {
|
|
22
|
+
const rootDir = await mkdtemp(join(tmpdir(), 'pikku-graph-foreach-'))
|
|
23
|
+
const stepFile = join(rootDir, 'my.steps.ts')
|
|
24
|
+
const graphFile = join(rootDir, 'my.graph.ts')
|
|
25
|
+
|
|
26
|
+
await writeFile(
|
|
27
|
+
stepFile,
|
|
28
|
+
[
|
|
29
|
+
"import { pikkuSessionlessFunc } from '@pikku/core'",
|
|
30
|
+
'export const listRows = pikkuSessionlessFunc({ func: async () => ({ rows: [] }) })',
|
|
31
|
+
'export const postVideo = pikkuSessionlessFunc({ func: async () => ({ ok: true }) })',
|
|
32
|
+
].join('\n')
|
|
33
|
+
)
|
|
34
|
+
await writeFile(graphFile, graphSource.join('\n'))
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const state = await inspect(makeLogger(), [stepFile, graphFile], {
|
|
38
|
+
rootDir,
|
|
39
|
+
})
|
|
40
|
+
const graph = state.workflows.graphMeta[graphName]
|
|
41
|
+
assert.ok(graph, `graph meta '${graphName}' should be registered`)
|
|
42
|
+
return graph
|
|
43
|
+
} finally {
|
|
44
|
+
await rm(rootDir, { recursive: true, force: true })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('addWorkflowGraph — forEach extraction', () => {
|
|
49
|
+
test('forEach node id and $item() lower into the serialized meta', async () => {
|
|
50
|
+
const graph = await inspectGraph(
|
|
51
|
+
[
|
|
52
|
+
"import { pikkuWorkflowGraph } from '@pikku/core/workflow'",
|
|
53
|
+
'export const myGraph = pikkuWorkflowGraph({',
|
|
54
|
+
" name: 'foreach-graph',",
|
|
55
|
+
" nodes: { listRows: 'listRows', postVideo: 'postVideo' },",
|
|
56
|
+
' config: {',
|
|
57
|
+
" listRows: { next: 'postVideo' },",
|
|
58
|
+
' postVideo: {',
|
|
59
|
+
" forEach: 'listRows',",
|
|
60
|
+
' input: (ref, template, $item) => ({',
|
|
61
|
+
" url: $item('URL VIDEO'),",
|
|
62
|
+
' whole: $item(),',
|
|
63
|
+
" listed: ref('listRows'),",
|
|
64
|
+
' }),',
|
|
65
|
+
' },',
|
|
66
|
+
' },',
|
|
67
|
+
'})',
|
|
68
|
+
],
|
|
69
|
+
'foreach-graph'
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const node = graph.nodes['postVideo'] as any
|
|
73
|
+
assert.deepEqual(node.forEach, { $ref: 'listRows' })
|
|
74
|
+
assert.equal(node.mode, undefined)
|
|
75
|
+
assert.deepEqual(node.input, {
|
|
76
|
+
url: { $ref: '$item', path: 'URL VIDEO' },
|
|
77
|
+
whole: { $ref: '$item', path: undefined },
|
|
78
|
+
listed: { $ref: 'listRows', path: undefined },
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('forEach accepts a (ref) callback with a path, plus a sequential mode', async () => {
|
|
83
|
+
const graph = await inspectGraph(
|
|
84
|
+
[
|
|
85
|
+
"import { pikkuWorkflowGraph } from '@pikku/core/workflow'",
|
|
86
|
+
'export const myGraph = pikkuWorkflowGraph({',
|
|
87
|
+
" name: 'foreach-callback-graph',",
|
|
88
|
+
" nodes: { listRows: 'listRows', postVideo: 'postVideo' },",
|
|
89
|
+
' config: {',
|
|
90
|
+
" listRows: { next: 'postVideo' },",
|
|
91
|
+
' postVideo: {',
|
|
92
|
+
" forEach: (ref) => ref('listRows', 'rows'),",
|
|
93
|
+
" mode: 'sequential',",
|
|
94
|
+
" input: (ref, template, $item) => ({ url: $item('URL') }),",
|
|
95
|
+
' },',
|
|
96
|
+
' },',
|
|
97
|
+
'})',
|
|
98
|
+
],
|
|
99
|
+
'foreach-callback-graph'
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
const node = graph.nodes['postVideo'] as any
|
|
103
|
+
assert.deepEqual(node.forEach, { $ref: 'listRows', path: 'rows' })
|
|
104
|
+
assert.equal(node.mode, 'sequential')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('an existing (ref) => ... node keeps its exact input and gains no forEach', async () => {
|
|
108
|
+
const graph = await inspectGraph(
|
|
109
|
+
[
|
|
110
|
+
"import { pikkuWorkflowGraph } from '@pikku/core/workflow'",
|
|
111
|
+
"import { template } from '@pikku/core/workflow'",
|
|
112
|
+
'export const myGraph = pikkuWorkflowGraph({',
|
|
113
|
+
" name: 'plain-graph',",
|
|
114
|
+
" nodes: { listRows: 'listRows', postVideo: 'postVideo' },",
|
|
115
|
+
' config: {',
|
|
116
|
+
" listRows: { next: 'postVideo' },",
|
|
117
|
+
' postVideo: {',
|
|
118
|
+
' input: (ref) => ({',
|
|
119
|
+
" rows: ref('listRows', 'rows'),",
|
|
120
|
+
" label: template('rows: $0', [ref('listRows', 'rows')]),",
|
|
121
|
+
' }),',
|
|
122
|
+
' },',
|
|
123
|
+
' },',
|
|
124
|
+
'})',
|
|
125
|
+
],
|
|
126
|
+
'plain-graph'
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const node = graph.nodes['postVideo'] as any
|
|
130
|
+
assert.equal(node.forEach, undefined)
|
|
131
|
+
assert.equal(node.mode, undefined)
|
|
132
|
+
assert.deepEqual(node.input, {
|
|
133
|
+
rows: { $ref: 'listRows', path: 'rows' },
|
|
134
|
+
label: {
|
|
135
|
+
$template: {
|
|
136
|
+
parts: ['rows: ', ''],
|
|
137
|
+
expressions: [{ $ref: 'listRows', path: 'rows' }],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('an existing (ref, template) => ... node still resolves template from the 2nd param', async () => {
|
|
144
|
+
const graph = await inspectGraph(
|
|
145
|
+
[
|
|
146
|
+
"import { pikkuWorkflowGraph } from '@pikku/core/workflow'",
|
|
147
|
+
'export const myGraph = pikkuWorkflowGraph({',
|
|
148
|
+
" name: 'two-param-graph',",
|
|
149
|
+
" nodes: { listRows: 'listRows', postVideo: 'postVideo' },",
|
|
150
|
+
' config: {',
|
|
151
|
+
" listRows: { next: 'postVideo' },",
|
|
152
|
+
' postVideo: {',
|
|
153
|
+
' input: (ref, template) => ({',
|
|
154
|
+
" label: template('rows: $0', [ref('listRows', 'rows')]),",
|
|
155
|
+
' }),',
|
|
156
|
+
' },',
|
|
157
|
+
' },',
|
|
158
|
+
'})',
|
|
159
|
+
],
|
|
160
|
+
'two-param-graph'
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
const node = graph.nodes['postVideo'] as any
|
|
164
|
+
assert.equal(node.forEach, undefined)
|
|
165
|
+
assert.deepEqual(node.input, {
|
|
166
|
+
label: {
|
|
167
|
+
$template: {
|
|
168
|
+
parts: ['rows: ', ''],
|
|
169
|
+
expressions: [{ $ref: 'listRows', path: 'rows' }],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
})
|
|
@@ -36,7 +36,7 @@ describe('addWorkflowGraph — node input extraction', () => {
|
|
|
36
36
|
graphFile,
|
|
37
37
|
[
|
|
38
38
|
"import { pikkuWorkflowGraph } from '@pikku/core/workflow'",
|
|
39
|
-
"import { template } from '@pikku/core/
|
|
39
|
+
"import { template } from '@pikku/core/workflow'",
|
|
40
40
|
'export const myGraph = pikkuWorkflowGraph({',
|
|
41
41
|
" name: 'input-graph',",
|
|
42
42
|
" nodes: { edit: 'edit' },",
|