@pikku/cli 0.12.82 → 0.12.83
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/cli.schema.json +1 -1
- package/console-app/assets/{index-ChcXIEhS.js → index-CN_U0k_D.js} +154 -144
- package/console-app/assets/{index-DwyRdRuZ.css → index-CpHRlBt-.css} +1 -1
- package/console-app/index.html +2 -2
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +3 -2
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.js +21 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +60 -3
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
- package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +6 -12
- package/dist/.pikku/function/pikku-function-types.gen.js +3 -12
- package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.json +190 -12
- package/dist/.pikku/function/pikku-functions.gen.js +15 -1
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +2 -24
- package/dist/.pikku/http/pikku-http-types.gen.js +2 -24
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
- package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
- package/dist/.pikku/pikku-meta-service.gen.js +1 -1
- package/dist/.pikku/pikku-services.gen.d.ts +4 -1
- package/dist/.pikku/pikku-services.gen.js +3 -0
- package/dist/.pikku/pikku-types.gen.d.ts +2 -1
- package/dist/.pikku/pikku-types.gen.js +3 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +9 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
- package/dist/.pikku/schemas/register.gen.js +13 -1
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuGraphWiringsOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuImportN8nInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuScopesInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuWebhookOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/ScopesAuditInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/ScopesPruneInput.schema.json +1 -0
- package/dist/.pikku/scopes/pikku-scope-types.gen.d.ts +5 -0
- package/dist/.pikku/scopes/pikku-scope-types.gen.js +4 -0
- package/dist/.pikku/scopes/pikku-scopes-meta.gen.json +1 -0
- package/dist/.pikku/scopes/pikku-scopes.gen.d.ts +35 -0
- package/dist/.pikku/scopes/pikku-scopes.gen.js +27 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
- package/dist/.pikku/secrets/pikku-secrets-meta.gen.json +1 -0
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +11 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.js +11 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variables-meta.gen.json +1 -0
- package/dist/.pikku/variables/pikku-variables.gen.d.ts +11 -1
- package/dist/.pikku/variables/pikku-variables.gen.js +13 -3
- package/dist/.pikku/workflow/meta/allWorkflow.gen.json +48 -6
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +4 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
- package/dist/bin/pikku-bin.mjs +2 -2
- package/dist/src/cli.wiring.js +47 -4
- package/dist/src/deploy/analyzer/analyzer.js +6 -0
- package/dist/src/fabric/fabric-commands.d.ts +3 -3
- package/dist/src/fabric/functions/llm-key.function.d.ts +4 -4
- package/dist/src/functions/commands/bootstrap.js +3 -0
- package/dist/src/functions/commands/dev.js +14 -3
- package/dist/src/functions/commands/enable.d.ts +1 -0
- package/dist/src/functions/commands/enable.js +10 -5
- package/dist/src/functions/commands/import-n8n.d.ts +10 -0
- package/dist/src/functions/commands/import-n8n.js +130 -0
- package/dist/src/functions/commands/info.js +0 -13
- package/dist/src/functions/commands/new-addon.js +33 -35
- package/dist/src/functions/commands/pikku-command-bootstrap.js +6 -0
- package/dist/src/functions/commands/scopes-audit.d.ts +1 -0
- package/dist/src/functions/commands/scopes-audit.js +37 -0
- package/dist/src/functions/commands/scopes-prune.d.ts +14 -0
- package/dist/src/functions/commands/scopes-prune.js +50 -0
- package/dist/src/functions/commands/scopes-shared.d.ts +39 -0
- package/dist/src/functions/commands/scopes-shared.js +83 -0
- package/dist/src/functions/commands/serve.js +4 -2
- package/dist/src/functions/commands/skills.js +18 -10
- package/dist/src/functions/wirings/ai-agent/serialize-ai-agent-types.js +2 -1
- package/dist/src/functions/wirings/console/serialize-console-functions.js +6 -0
- package/dist/src/functions/wirings/credentials/serialize-credentials-types.js +22 -0
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +2 -2
- package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +14 -16
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +6 -2
- package/dist/src/functions/wirings/graph/pikku-command-graph-wirings.d.ts +1 -0
- package/dist/src/functions/wirings/graph/pikku-command-graph-wirings.js +21 -0
- package/dist/src/functions/wirings/graph/serialize-graph-wirings.d.ts +5 -0
- package/dist/src/functions/wirings/graph/serialize-graph-wirings.js +14 -0
- package/dist/src/functions/wirings/http/serialize-http-types.js +2 -30
- package/dist/src/functions/wirings/package/pikku-command-package-types.d.ts +1 -0
- package/dist/src/functions/wirings/package/pikku-command-package-types.js +14 -1
- package/dist/src/functions/wirings/package/serialize-package-types.d.ts +1 -0
- package/dist/src/functions/wirings/package/serialize-package-types.js +5 -0
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.js +1 -3
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.d.ts +6 -1
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.js +7 -64
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.d.ts +5 -0
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +20 -0
- package/dist/src/functions/wirings/rpc/serialize-typed-rpc-map.d.ts +1 -0
- package/dist/src/functions/wirings/rpc/serialize-typed-rpc-map.js +8 -3
- package/dist/src/functions/wirings/scopes/pikku-command-scopes.d.ts +7 -0
- package/dist/src/functions/wirings/scopes/pikku-command-scopes.js +34 -0
- package/dist/src/functions/wirings/scopes/serialize-scopes-types.d.ts +15 -0
- package/dist/src/functions/wirings/scopes/serialize-scopes-types.js +86 -0
- package/dist/src/functions/wirings/secrets/serialize-secrets-types.js +13 -0
- package/dist/src/functions/wirings/variables/serialize-variables-types.js +15 -2
- package/dist/src/functions/wirings/webhook/pikku-command-webhook.d.ts +1 -0
- package/dist/src/functions/wirings/webhook/pikku-command-webhook.js +25 -0
- package/dist/src/functions/wirings/webhook/serialize-webhook.d.ts +14 -0
- package/dist/src/functions/wirings/webhook/serialize-webhook.js +34 -0
- package/dist/src/functions/wirings/workflow/serialize-workflow-routes.js +29 -0
- package/dist/src/functions/wirings/workflow/serialize-workflow-types.js +3 -0
- package/dist/src/functions/workflows/all.workflow.js +23 -3
- package/dist/src/services.d.ts +1 -0
- package/dist/src/services.js +1 -0
- package/dist/src/utils/pikku-cli-config.js +20 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/skills/pikku-addon/SKILL.md +7 -3
- package/skills/pikku-ai-agent/SKILL.md +6 -3
- package/skills/pikku-ai-vercel/SKILL.md +6 -3
- package/skills/pikku-ai-voice/SKILL.md +6 -3
- package/skills/pikku-audit/SKILL.md +10 -3
- package/skills/pikku-aws/SKILL.md +9 -5
- package/skills/pikku-backblaze/SKILL.md +4 -3
- package/skills/pikku-better-auth/SKILL.md +10 -5
- package/skills/pikku-cli/SKILL.md +6 -3
- package/skills/pikku-concepts/SKILL.md +9 -4
- package/skills/pikku-concepts/references/concept-mapping.md +12 -10
- package/skills/pikku-config/SKILL.md +9 -5
- package/skills/pikku-cron/SKILL.md +6 -3
- package/skills/pikku-deploy-azure/SKILL.md +5 -3
- package/skills/pikku-deploy-cloudflare/SKILL.md +5 -3
- package/skills/pikku-deploy-express/SKILL.md +6 -3
- package/skills/pikku-deploy-fastify/SKILL.md +6 -3
- package/skills/pikku-deploy-lambda/SKILL.md +6 -3
- package/skills/pikku-deploy-nextjs/SKILL.md +5 -3
- package/skills/pikku-deploy-uws/SKILL.md +7 -4
- package/skills/pikku-deps/SKILL.md +13 -6
- package/skills/pikku-emails/SKILL.md +10 -5
- package/skills/pikku-feature/SKILL.md +1 -1
- package/skills/pikku-gateway-slack/SKILL.md +6 -3
- package/skills/pikku-http/SKILL.md +15 -21
- package/skills/pikku-http/references/http-options.md +0 -2
- package/skills/pikku-info/SKILL.md +9 -4
- package/skills/pikku-jose/SKILL.md +6 -3
- package/skills/pikku-kysely/SKILL.md +13 -5
- package/skills/pikku-machine-auth/SKILL.md +9 -3
- package/skills/pikku-mcp/SKILL.md +7 -3
- package/skills/pikku-middleware/SKILL.md +11 -6
- package/skills/pikku-mongodb/SKILL.md +8 -5
- package/skills/pikku-n8n-import/SKILL.md +109 -0
- package/skills/pikku-n8n-import/SPEC.md +84 -0
- package/skills/pikku-n8n-import/references/addon-mapping.md +121 -0
- package/skills/pikku-n8n-import/references/code-translation.md +121 -0
- package/skills/pikku-n8n-import/references/loops-and-control.md +87 -0
- package/skills/pikku-permissions/SKILL.md +26 -15
- package/skills/pikku-pino/SKILL.md +5 -3
- package/skills/pikku-product-second-opinion/README.md +43 -0
- package/skills/pikku-product-second-opinion/SKILL.md +158 -0
- package/skills/pikku-product-second-opinion/example/sample-report.md +90 -0
- package/skills/pikku-product-second-opinion/references/report-template.md +73 -0
- package/skills/pikku-queue/SKILL.md +7 -4
- package/skills/pikku-redis/SKILL.md +9 -6
- package/skills/pikku-rpc/SKILL.md +7 -4
- package/skills/pikku-rtl/SKILL.md +1 -1
- package/skills/pikku-scenario/SKILL.md +215 -0
- package/skills/pikku-schedule/SKILL.md +6 -3
- package/skills/pikku-schema-ajv/SKILL.md +5 -3
- package/skills/pikku-schema-cfworker/SKILL.md +6 -3
- package/skills/pikku-security/SKILL.md +8 -4
- package/skills/pikku-services/SKILL.md +8 -4
- package/skills/pikku-software-archaeology/README.md +70 -0
- package/skills/pikku-software-archaeology/SKILL.md +186 -0
- package/skills/pikku-software-archaeology/references/blueprint.schema.json +625 -0
- package/skills/pikku-software-archaeology/references/pikku-mapping.md +49 -0
- package/skills/pikku-software-archaeology/scripts/validate.mjs +173 -0
- package/skills/pikku-template-clone/SKILL.md +1 -1
- package/skills/pikku-trigger/SKILL.md +7 -3
- package/skills/pikku-versioning/SKILL.md +7 -3
- package/skills/pikku-websocket/SKILL.md +8 -4
- package/skills/pikku-workflow/SKILL.md +7 -3
- package/skills/pikku-ws/SKILL.md +5 -3
- package/skills/pikku-n8n-addon-map/SKILL.md +0 -178
- package/skills/pikku-n8n-code-translate/SKILL.md +0 -166
- package/skills/pikku-testing/SKILL.md +0 -328
- package/skills/pikku-testing/references/cucumber-bdd-testing.md +0 -176
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates core function, middleware, and permission type definitions
|
|
3
3
|
*/
|
|
4
|
-
export const serializeFunctionTypes = (userSessionTypeImport, userSessionTypeName, singletonServicesTypeImport, singletonServicesTypeName, wireServicesTypeImport, wireServicesTypeName, rpcMapTypeImport, requiredServicesTypeImport, configTypeImport, packageName, workflowTypesImport, nodeCategories) => {
|
|
4
|
+
export const serializeFunctionTypes = (userSessionTypeImport, userSessionTypeName, singletonServicesTypeImport, singletonServicesTypeName, wireServicesTypeImport, wireServicesTypeName, rpcMapTypeImport, requiredServicesTypeImport, configTypeImport, packageName, workflowTypesImport, nodeCategories, scopesTypeImport) => {
|
|
5
5
|
const packageNameValue = packageName ? `'${packageName}'` : 'null';
|
|
6
6
|
const nodeCategoryType = nodeCategories?.length
|
|
7
7
|
? nodeCategories.map((c) => `'${c}'`).join(' | ')
|
|
8
8
|
: 'string';
|
|
9
9
|
const workflowImport = workflowTypesImport ||
|
|
10
10
|
`import type { TypedWorkflow, TypedScenario } from '../workflow/pikku-workflow-types.gen.js'`;
|
|
11
|
+
// Falls back to `string` when a project has no scopes codegen, so that
|
|
12
|
+
// `scopes` stays usable rather than resolving to an unbound type name.
|
|
13
|
+
const scopesImport = scopesTypeImport || `type ScopeId = string`;
|
|
11
14
|
return `/**
|
|
12
15
|
* Core function, middleware, and permission types for all wirings
|
|
13
16
|
*/
|
|
@@ -18,11 +21,11 @@ import { pikkuAuth as pikkuAuthCore } from '@pikku/core/function'
|
|
|
18
21
|
import {
|
|
19
22
|
addTagMiddleware as addTagMiddlewareCore,
|
|
20
23
|
addGlobalMiddleware as addGlobalMiddlewareCore,
|
|
21
|
-
addTagPermission as addTagPermissionCore,
|
|
22
24
|
addGlobalPermission as addGlobalPermissionCore,
|
|
23
25
|
} from '@pikku/core/middleware'
|
|
24
26
|
import { pikkuState as __pikkuState, CreateWireServices } from '@pikku/core/internal'
|
|
25
27
|
import type { NodeType } from '@pikku/core/node'
|
|
28
|
+
${scopesImport}
|
|
26
29
|
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
27
30
|
import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
|
|
28
31
|
|
|
@@ -329,7 +332,7 @@ export type PikkuFunctionConfig<
|
|
|
329
332
|
PikkuFunc extends PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires> = PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires>,
|
|
330
333
|
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
331
334
|
OutputSchema extends StandardSchemaV1 | undefined = undefined
|
|
332
|
-
> = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware, InputSchema, OutputSchema>
|
|
335
|
+
> = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware, InputSchema, OutputSchema, ScopeId>
|
|
333
336
|
|
|
334
337
|
/**
|
|
335
338
|
* Configuration object for Pikku functions with Zod schema validation.
|
|
@@ -351,7 +354,12 @@ export type PikkuFunctionConfigWithSchema<
|
|
|
351
354
|
> = Omit<
|
|
352
355
|
CorePikkuFunctionConfig<
|
|
353
356
|
| PikkuFunction<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>
|
|
354
|
-
| PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires
|
|
357
|
+
| PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires>,
|
|
358
|
+
CorePikkuPermission<any>,
|
|
359
|
+
PikkuMiddleware,
|
|
360
|
+
undefined,
|
|
361
|
+
undefined,
|
|
362
|
+
ScopeId
|
|
355
363
|
>,
|
|
356
364
|
'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'
|
|
357
365
|
> & {
|
|
@@ -681,16 +689,6 @@ export const addGlobalMiddleware = (middleware: PikkuMiddleware[]) => {
|
|
|
681
689
|
addGlobalMiddlewareCore(middleware as any, ${packageNameValue})
|
|
682
690
|
}
|
|
683
691
|
|
|
684
|
-
/**
|
|
685
|
-
* Tag-scoped permissions. Applies to any wiring that carries the matching tag.
|
|
686
|
-
*
|
|
687
|
-
* @example
|
|
688
|
-
* addTagPermission('admin', [adminPermission])
|
|
689
|
-
*/
|
|
690
|
-
export const addTagPermission = <In = unknown>(tag: string, permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
|
|
691
|
-
addTagPermissionCore(tag, permissions as any, ${packageNameValue})
|
|
692
|
-
}
|
|
693
|
-
|
|
694
692
|
/**
|
|
695
693
|
* Wire-agnostic global permissions. Runs at the top of every wiring's
|
|
696
694
|
* permission resolution — before wire-, tag-, and function-level entries.
|
|
@@ -704,7 +702,7 @@ export const addGlobalPermission = <In = unknown>(permissions: CorePermissionGro
|
|
|
704
702
|
addGlobalPermissionCore(permissions as any, ${packageNameValue})
|
|
705
703
|
}
|
|
706
704
|
|
|
707
|
-
export { wireAddon } from '@pikku/core/rpc'
|
|
708
|
-
export type { WireAddonConfig } from '@pikku/core/rpc'
|
|
705
|
+
export { wireAddon, wireRemoteAddon } from '@pikku/core/rpc'
|
|
706
|
+
export type { WireAddonConfig, WireRemoteAddonConfig, RemoteAddonAuth } from '@pikku/core/rpc'
|
|
709
707
|
`;
|
|
710
708
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates the main pikku-types.gen.ts file as a re-export hub
|
|
3
3
|
*/
|
|
4
|
-
export declare const serializePikkuTypesHub: (functionTypesImportPath: string, httpTypesImportPath: string | null, channelTypesImportPath: string | null, triggerTypesImportPath: string | null, schedulerTypesImportPath: string | null, queueTypesImportPath: string | null, mcpTypesImportPath: string | null, cliTypesImportPath: string | null, nodeTypesImportPath: string | null, secretTypesImportPath: string | null, addonTypesImportPath: string | null, authTypesImportPath?: string | null) => string;
|
|
4
|
+
export declare const serializePikkuTypesHub: (functionTypesImportPath: string, httpTypesImportPath: string | null, channelTypesImportPath: string | null, triggerTypesImportPath: string | null, schedulerTypesImportPath: string | null, queueTypesImportPath: string | null, mcpTypesImportPath: string | null, cliTypesImportPath: string | null, nodeTypesImportPath: string | null, secretTypesImportPath: string | null, addonTypesImportPath: string | null, authTypesImportPath?: string | null, scopeTypesImportPath?: string | null) => string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates the main pikku-types.gen.ts file as a re-export hub
|
|
3
3
|
*/
|
|
4
|
-
export const serializePikkuTypesHub = (functionTypesImportPath, httpTypesImportPath, channelTypesImportPath, triggerTypesImportPath, schedulerTypesImportPath, queueTypesImportPath, mcpTypesImportPath, cliTypesImportPath, nodeTypesImportPath, secretTypesImportPath, addonTypesImportPath, authTypesImportPath = null) => {
|
|
4
|
+
export const serializePikkuTypesHub = (functionTypesImportPath, httpTypesImportPath, channelTypesImportPath, triggerTypesImportPath, schedulerTypesImportPath, queueTypesImportPath, mcpTypesImportPath, cliTypesImportPath, nodeTypesImportPath, secretTypesImportPath, addonTypesImportPath, authTypesImportPath = null, scopeTypesImportPath = null) => {
|
|
5
5
|
const exports = [
|
|
6
6
|
{
|
|
7
7
|
comment: 'Core function, middleware, and permission types',
|
|
@@ -16,8 +16,12 @@ export const serializePikkuTypesHub = (functionTypesImportPath, httpTypesImportP
|
|
|
16
16
|
{ comment: 'CLI wiring types', path: cliTypesImportPath },
|
|
17
17
|
{ comment: 'Node wiring types', path: nodeTypesImportPath },
|
|
18
18
|
{ comment: 'Secret definition types', path: secretTypesImportPath },
|
|
19
|
+
{ comment: 'Scope definition types', path: scopeTypesImportPath },
|
|
19
20
|
{ comment: 'Addon types', path: addonTypesImportPath },
|
|
20
|
-
{
|
|
21
|
+
{
|
|
22
|
+
comment: 'Auth types (typed pikkuBetterAuth re-export)',
|
|
23
|
+
path: authTypesImportPath,
|
|
24
|
+
},
|
|
21
25
|
];
|
|
22
26
|
const exportStatements = exports
|
|
23
27
|
.filter((e) => e.path)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pikkuGraphWirings: import("#pikku").PikkuFunctionConfig<void, boolean, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, boolean, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, boolean, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { pikkuSessionlessFunc } from '#pikku';
|
|
2
|
+
import { getFileImportRelativePath } from '../../../utils/file-import-path.js';
|
|
3
|
+
import { writeFileInDir } from '../../../utils/file-writer.js';
|
|
4
|
+
import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js';
|
|
5
|
+
import { serializeGraphWirings } from './serialize-graph-wirings.js';
|
|
6
|
+
export const pikkuGraphWirings = pikkuSessionlessFunc({
|
|
7
|
+
func: async ({ logger, config }) => {
|
|
8
|
+
if (config.scaffold?.graph && config.graphWiringsFile) {
|
|
9
|
+
const pathToPikkuTypes = getFileImportRelativePath(config.graphWiringsFile, config.typesDeclarationFile, config.packageMappings);
|
|
10
|
+
await writeFileInDir(logger, config.graphWiringsFile, serializeGraphWirings(pathToPikkuTypes));
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
},
|
|
15
|
+
middleware: [
|
|
16
|
+
logCommandInfoAndTime({
|
|
17
|
+
commandStart: 'Generating Graph Wirings',
|
|
18
|
+
commandEnd: 'Generated Graph Wirings',
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire @pikku/addon-graph so `pikkuWorkflowGraph` nodes can reference its native
|
|
3
|
+
* transform functions (e.g. `graph:editFields`).
|
|
4
|
+
*/
|
|
5
|
+
export const serializeGraphWirings = (pathToPikkuTypes) => {
|
|
6
|
+
return `/**
|
|
7
|
+
* @pikku/addon-graph wiring
|
|
8
|
+
* Do not edit manually - regenerate with 'npx pikku'
|
|
9
|
+
*/
|
|
10
|
+
import { wireAddon } from '${pathToPikkuTypes}'
|
|
11
|
+
|
|
12
|
+
wireAddon({ name: 'graph', package: '@pikku/addon-graph' })
|
|
13
|
+
`;
|
|
14
|
+
};
|
|
@@ -6,7 +6,7 @@ export const serializeHTTPTypes = (functionTypesImportPath) => {
|
|
|
6
6
|
* HTTP-specific type definitions for tree-shaking optimization
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore,
|
|
9
|
+
import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore, wireHTTPRoutes as wireHTTPRoutesCore, defineHTTPRoutes as defineHTTPRoutesCore } from '@pikku/core/http'
|
|
10
10
|
import type { PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware, PikkuFunctionConfig } from '${functionTypesImportPath}'
|
|
11
11
|
import type { CoreHTTPFunctionWiring, HTTPMethod, HTTPRouteBaseConfig } from '@pikku/core/http'
|
|
12
12
|
|
|
@@ -60,32 +60,6 @@ export const addHTTPMiddleware = (
|
|
|
60
60
|
addHTTPMiddlewareCore(routeOrMiddleware as any, middleware as any)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* Registers HTTP permissions either globally or for a specific route pattern.
|
|
65
|
-
*
|
|
66
|
-
* When a string route pattern is provided along with permissions, the permissions
|
|
67
|
-
* are applied only to that route. Permissions can be passed as an array or as a
|
|
68
|
-
* permission group object.
|
|
69
|
-
*
|
|
70
|
-
* @param pattern - Route pattern string (e.g., '*' for all routes, '/api/*' for specific routes)
|
|
71
|
-
* @param permissions - The permissions to apply for the specified route pattern
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* \`\`\`typescript
|
|
75
|
-
* // Add global HTTP permissions
|
|
76
|
-
* addHTTPPermission('*', { global: globalPermission })
|
|
77
|
-
*
|
|
78
|
-
* // Add route-specific permissions
|
|
79
|
-
* addHTTPPermission('/api/admin/*', { admin: adminPermission })
|
|
80
|
-
* \`\`\`
|
|
81
|
-
*/
|
|
82
|
-
export const addHTTPPermission = <In = unknown>(
|
|
83
|
-
pattern: string,
|
|
84
|
-
permissions: Record<string, PikkuPermission<In>> | PikkuPermission<In>[]
|
|
85
|
-
) => {
|
|
86
|
-
addHTTPPermissionCore(pattern, permissions as any)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
63
|
/**
|
|
90
64
|
* Route configuration for wireHTTPRoutes with proper typing
|
|
91
65
|
*/
|
|
@@ -94,7 +68,6 @@ type HTTPRouteConfig = HTTPRouteBaseConfig & {
|
|
|
94
68
|
route: string
|
|
95
69
|
func: PikkuFunctionConfig<any, any, any, any, any, any>
|
|
96
70
|
auth?: boolean
|
|
97
|
-
permissions?: Record<string, PikkuPermission | PikkuPermission[]>
|
|
98
71
|
middleware?: PikkuMiddleware[]
|
|
99
72
|
sse?: boolean
|
|
100
73
|
}
|
|
@@ -114,14 +87,13 @@ type TypedHTTPRouteContract<T extends TypedHTTPRouteMap = TypedHTTPRouteMap> = T
|
|
|
114
87
|
}
|
|
115
88
|
|
|
116
89
|
/**
|
|
117
|
-
* Group config with typed middleware
|
|
90
|
+
* Group config with typed middleware
|
|
118
91
|
*/
|
|
119
92
|
type TypedHTTPRoutesGroupConfig = {
|
|
120
93
|
basePath?: string
|
|
121
94
|
tags?: string[]
|
|
122
95
|
auth?: boolean
|
|
123
96
|
middleware?: PikkuMiddleware[]
|
|
124
|
-
permissions?: Record<string, PikkuPermission | PikkuPermission[]>
|
|
125
97
|
}
|
|
126
98
|
|
|
127
99
|
/**
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const pikkuSecretDefinitionTypes: import("#pikku").PikkuFunctionConfig<void, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
2
|
+
export declare const pikkuScopeDefinitionTypes: import("#pikku").PikkuFunctionConfig<void, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
2
3
|
export declare const pikkuVariableDefinitionTypes: import("#pikku").PikkuFunctionConfig<void, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pikkuVoidFunc } from '#pikku';
|
|
2
2
|
import { writeFileInDir } from '../../../utils/file-writer.js';
|
|
3
3
|
import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js';
|
|
4
|
-
import { serializeSecretDefinitionTypes, serializeVariableDefinitionTypes, } from './serialize-package-types.js';
|
|
4
|
+
import { serializeScopeDefinitionTypes, serializeSecretDefinitionTypes, serializeVariableDefinitionTypes, } from './serialize-package-types.js';
|
|
5
5
|
export const pikkuSecretDefinitionTypes = pikkuVoidFunc({
|
|
6
6
|
func: async ({ logger, config }) => {
|
|
7
7
|
const { secretTypesFile } = config;
|
|
@@ -15,6 +15,19 @@ export const pikkuSecretDefinitionTypes = pikkuVoidFunc({
|
|
|
15
15
|
}),
|
|
16
16
|
],
|
|
17
17
|
});
|
|
18
|
+
export const pikkuScopeDefinitionTypes = pikkuVoidFunc({
|
|
19
|
+
func: async ({ logger, config }) => {
|
|
20
|
+
const { scopeTypesFile } = config;
|
|
21
|
+
const content = serializeScopeDefinitionTypes();
|
|
22
|
+
await writeFileInDir(logger, scopeTypesFile, content);
|
|
23
|
+
},
|
|
24
|
+
middleware: [
|
|
25
|
+
logCommandInfoAndTime({
|
|
26
|
+
commandStart: 'Creating Scope definition types',
|
|
27
|
+
commandEnd: 'Created Scope definition types',
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
});
|
|
18
31
|
export const pikkuVariableDefinitionTypes = pikkuVoidFunc({
|
|
19
32
|
func: async ({ logger, config }) => {
|
|
20
33
|
const { variableTypesFile } = config;
|
|
@@ -3,6 +3,11 @@ export const serializeSecretDefinitionTypes = () => {
|
|
|
3
3
|
export type { CoreSecret, SecretDefinitionMeta, SecretDefinitionsMeta } from '@pikku/core/secret'
|
|
4
4
|
`;
|
|
5
5
|
};
|
|
6
|
+
export const serializeScopeDefinitionTypes = () => {
|
|
7
|
+
return `export { wireScope } from '@pikku/core/scope'
|
|
8
|
+
export type { CoreScopes, CoreScopeNode, FlatScope, ScopeDefinitionMeta, ScopeDefinitionsMeta } from '@pikku/core/scope'
|
|
9
|
+
`;
|
|
10
|
+
};
|
|
6
11
|
export const serializeVariableDefinitionTypes = () => {
|
|
7
12
|
return `export { wireVariable } from '@pikku/core/variable'
|
|
8
13
|
export type { CoreVariable, VariableDefinitionMeta, VariableDefinitionsMeta } from '@pikku/core/variable'
|
|
@@ -8,10 +8,8 @@ export const pikkuPermissions = pikkuSessionlessFunc({
|
|
|
8
8
|
const { permissions } = state;
|
|
9
9
|
const { permissionsFile, packageMappings } = config;
|
|
10
10
|
let filesGenerated = false;
|
|
11
|
-
const hasHTTPGroups = state.http.routePermissions.size > 0;
|
|
12
|
-
const hasTagGroups = state.permissions.tagPermissions.size > 0;
|
|
13
11
|
const hasIndividual = Object.keys(state.permissions.definitions).length > 0;
|
|
14
|
-
if (
|
|
12
|
+
if (hasIndividual) {
|
|
15
13
|
const metaData = state.permissionsGroupsMeta;
|
|
16
14
|
await writeFileInDir(logger, config.permissionsGroupsMetaJsonFile, JSON.stringify(metaData, null, 2));
|
|
17
15
|
await writeFileInDir(logger, permissionsFile, serializePermissionsImports(permissionsFile, permissions, state.http, packageMappings));
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { InspectorPermissionState, InspectorHTTPState, InspectorState } from '@pikku/inspector';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Permissions are function-scoped only — they are imported and passed inline
|
|
4
|
+
* wherever a function declares them, so there are no permission groups to
|
|
5
|
+
* register at module evaluation. This generator therefore emits nothing.
|
|
6
|
+
*/
|
|
7
|
+
export declare const serializePermissionsImports: (_outputPath: string, _permissionsState: InspectorPermissionState, _httpState: InspectorHTTPState, _packageMappings?: Record<string, string>, _fullState?: InspectorState) => string;
|
|
@@ -1,65 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (groupMeta.exportName && groupMeta.isFactory) {
|
|
9
|
-
const filePath = getFileImportRelativePath(outputPath, groupMeta.sourceFile, packageMappings);
|
|
10
|
-
httpFactories.set(groupMeta.exportName, {
|
|
11
|
-
exportName: groupMeta.exportName,
|
|
12
|
-
filePath,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Collect factory imports and calls for tag permission groups
|
|
17
|
-
const tagFactories = new Map();
|
|
18
|
-
for (const [, groupMeta] of permissionsState.tagPermissions.entries()) {
|
|
19
|
-
if (groupMeta.exportName && groupMeta.isFactory) {
|
|
20
|
-
const filePath = getFileImportRelativePath(outputPath, groupMeta.sourceFile, packageMappings);
|
|
21
|
-
tagFactories.set(groupMeta.exportName, {
|
|
22
|
-
exportName: groupMeta.exportName,
|
|
23
|
-
filePath,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// Collect direct (non-factory) side-effect imports for HTTP permission groups
|
|
28
|
-
const directImports = new Set();
|
|
29
|
-
for (const [, groupMeta] of httpState.routePermissions.entries()) {
|
|
30
|
-
if (!groupMeta.isFactory) {
|
|
31
|
-
const filePath = getFileImportRelativePath(outputPath, groupMeta.sourceFile, packageMappings);
|
|
32
|
-
directImports.add(filePath);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Collect direct (non-factory) side-effect imports for tag permission groups
|
|
36
|
-
for (const [, groupMeta] of permissionsState.tagPermissions.entries()) {
|
|
37
|
-
if (!groupMeta.isFactory) {
|
|
38
|
-
const filePath = getFileImportRelativePath(outputPath, groupMeta.sourceFile, packageMappings);
|
|
39
|
-
directImports.add(filePath);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Combine all factories and deduplicate by exportName (same factory might be used in multiple groups)
|
|
43
|
-
const allFactories = new Map([...httpFactories, ...tagFactories]);
|
|
44
|
-
// Add direct side-effect imports (non-factory addPermission calls)
|
|
45
|
-
if (directImports.size > 0) {
|
|
46
|
-
serializedImports.push('/* Side-effect imports for direct addPermission calls */');
|
|
47
|
-
for (const filePath of directImports) {
|
|
48
|
-
serializedImports.push(`import '${filePath}'`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Add factory imports and calls
|
|
52
|
-
if (allFactories.size > 0) {
|
|
53
|
-
serializedImports.push('/* Call permission group factories to register at module evaluation */');
|
|
54
|
-
// Import factories
|
|
55
|
-
for (const [exportName, { filePath }] of allFactories) {
|
|
56
|
-
serializedImports.push(`import { ${exportName} } from '${filePath}'`);
|
|
57
|
-
}
|
|
58
|
-
// Call factories
|
|
59
|
-
for (const [exportName] of allFactories) {
|
|
60
|
-
serializedFactoryCalls.push(`${exportName}()`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Return combined output
|
|
64
|
-
return [...serializedImports, ...serializedFactoryCalls].join('\n');
|
|
1
|
+
/**
|
|
2
|
+
* Permissions are function-scoped only — they are imported and passed inline
|
|
3
|
+
* wherever a function declares them, so there are no permission groups to
|
|
4
|
+
* register at module evaluation. This generator therefore emits nothing.
|
|
5
|
+
*/
|
|
6
|
+
export const serializePermissionsImports = (_outputPath, _permissionsState, _httpState, _packageMappings = {}, _fullState) => {
|
|
7
|
+
return '';
|
|
65
8
|
};
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare const pikkuRPCInternalMap: import("#pikku").PikkuFunctionConfig<void, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
2
2
|
export declare const pikkuRPCExposedMap: import("#pikku").PikkuFunctionConfig<void, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
3
|
+
/**
|
|
4
|
+
* The `remote: true` surface — what a `wireRemoteAddon` consumer imports.
|
|
5
|
+
* Mirrors the exposed map but is fed from `rpc.remoteMeta`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const pikkuRPCRemoteMap: import("#pikku").PikkuFunctionConfig<void, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<void, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<void, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
@@ -35,3 +35,23 @@ export const pikkuRPCExposedMap = pikkuSessionlessFunc({
|
|
|
35
35
|
}),
|
|
36
36
|
],
|
|
37
37
|
});
|
|
38
|
+
/**
|
|
39
|
+
* The `remote: true` surface — what a `wireRemoteAddon` consumer imports.
|
|
40
|
+
* Mirrors the exposed map but is fed from `rpc.remoteMeta`.
|
|
41
|
+
*/
|
|
42
|
+
export const pikkuRPCRemoteMap = pikkuSessionlessFunc({
|
|
43
|
+
func: async ({ logger, config, getInspectorState }) => {
|
|
44
|
+
const { functions, rpc, resolvedIOTypes } = await getInspectorState();
|
|
45
|
+
const { rpcRemoteMapDeclarationFile, packageMappings, workflowMapDeclarationFile, agentMapDeclarationFile, } = config;
|
|
46
|
+
const workflowMapPath = getFileImportRelativePath(rpcRemoteMapDeclarationFile, workflowMapDeclarationFile, packageMappings);
|
|
47
|
+
const agentMapPath = getFileImportRelativePath(rpcRemoteMapDeclarationFile, agentMapDeclarationFile, packageMappings);
|
|
48
|
+
const content = serializeTypedRPCMap(logger, rpcRemoteMapDeclarationFile, packageMappings, functions.typesMap, rpc.remoteMeta, resolvedIOTypes, rpc.wireAddonDeclarations, workflowMapPath, agentMapPath);
|
|
49
|
+
await writeFileInDir(logger, rpcRemoteMapDeclarationFile, content);
|
|
50
|
+
},
|
|
51
|
+
middleware: [
|
|
52
|
+
logCommandInfoAndTime({
|
|
53
|
+
commandStart: 'Creating RPC remote map',
|
|
54
|
+
commandEnd: 'Created RPC remote map',
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
});
|
|
@@ -3,6 +3,7 @@ import type { Logger } from '@pikku/core/services';
|
|
|
3
3
|
type WireAddonDeclarations = Map<string, {
|
|
4
4
|
package: string;
|
|
5
5
|
rpcEndpoint?: string;
|
|
6
|
+
remote?: boolean;
|
|
6
7
|
}>;
|
|
7
8
|
export declare const serializeTypedRPCMap: (logger: Logger, relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, rpcMeta: Record<string, string>, resolvedIOTypes: Record<string, {
|
|
8
9
|
inputType: string;
|
|
@@ -106,9 +106,14 @@ function generateAddonImports(wireAddonDeclarations, relativeToPath) {
|
|
|
106
106
|
}
|
|
107
107
|
let imports = '\n// Addon package RPC maps\n';
|
|
108
108
|
for (const [namespace, decl] of wireAddonDeclarations.entries()) {
|
|
109
|
-
// Import the RPCMap from each addon package's
|
|
110
|
-
//
|
|
111
|
-
|
|
109
|
+
// Import the RPCMap from each addon package's RPC map.
|
|
110
|
+
// A `wireRemoteAddon` namespace imports the addon's `.remote.gen` map (only
|
|
111
|
+
// its `remote: true` surface); a local `wireAddon` imports `.internal.gen`.
|
|
112
|
+
// Use .js extension — package.json exports resolve it to .d.ts for types.
|
|
113
|
+
const mapFile = decl.remote
|
|
114
|
+
? 'pikku-rpc-wirings-map.remote.gen.js'
|
|
115
|
+
: 'pikku-rpc-wirings-map.internal.gen.js';
|
|
116
|
+
imports += `import type { RPCMap as ${toPascalCase(namespace)}RPCMap } from '${decl.package}/.pikku/rpc/${mapFile}'\n`;
|
|
112
117
|
}
|
|
113
118
|
return imports;
|
|
114
119
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const pikkuScopes: import("#pikku").PikkuFunctionConfig<{
|
|
2
|
+
bootstrap?: boolean;
|
|
3
|
+
}, void, "rpc" | "session", import("#pikku").PikkuFunctionSessionless<{
|
|
4
|
+
bootstrap?: boolean;
|
|
5
|
+
}, void, "rpc" | "session", import("#pikku").Services> | import("#pikku").PikkuFunction<{
|
|
6
|
+
bootstrap?: boolean;
|
|
7
|
+
}, void, "rpc" | "session", import("#pikku").Services>, undefined, undefined>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { pikkuSessionlessFunc } from '#pikku';
|
|
2
|
+
import { writeFileInDir } from '../../../utils/file-writer.js';
|
|
3
|
+
import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js';
|
|
4
|
+
import { serializeScopesTypes } from './serialize-scopes-types.js';
|
|
5
|
+
import { validateAndBuildScopeDefinitionsMeta } from '@pikku/core/scope';
|
|
6
|
+
export const pikkuScopes = pikkuSessionlessFunc({
|
|
7
|
+
func: async ({ logger, config, getInspectorState }, data) => {
|
|
8
|
+
const { scopesFile, scopesMetaJsonFile } = config;
|
|
9
|
+
if (!scopesFile) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// On a cold .pikku this runs before pikku-types.gen.ts exists, so it must
|
|
13
|
+
// take the zero state rather than a full inspect — inspecting here would
|
|
14
|
+
// try to import the project's zod schemas, which resolve '#pikku' and fail.
|
|
15
|
+
// The file only has to exist so function types can import ScopeId; the real
|
|
16
|
+
// Scopes step regenerates it with the declarations once setup has run.
|
|
17
|
+
const bootstrap = data?.bootstrap ?? false;
|
|
18
|
+
const state = await getInspectorState(false, bootstrap, bootstrap);
|
|
19
|
+
const content = serializeScopesTypes({
|
|
20
|
+
definitions: state.scopes.definitions,
|
|
21
|
+
});
|
|
22
|
+
await writeFileInDir(logger, scopesFile, content);
|
|
23
|
+
if (scopesMetaJsonFile) {
|
|
24
|
+
const meta = validateAndBuildScopeDefinitionsMeta(state.scopes.definitions);
|
|
25
|
+
await writeFileInDir(logger, scopesMetaJsonFile, JSON.stringify(meta, null, 2));
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
middleware: [
|
|
29
|
+
logCommandInfoAndTime({
|
|
30
|
+
commandStart: 'Creating PikkuScopes types',
|
|
31
|
+
commandEnd: 'Created PikkuScopes types',
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ScopeDefinitions } from '@pikku/core/scope';
|
|
2
|
+
export interface SerializeScopesOptions {
|
|
3
|
+
definitions: ScopeDefinitions;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Generates the `ScopeId` union and scope metadata from `wireScope`
|
|
7
|
+
* declarations.
|
|
8
|
+
*
|
|
9
|
+
* The union carries every declared node plus a wildcard form for each node that
|
|
10
|
+
* has descendants — `admin:*` is requirable when `admin` has children, but a
|
|
11
|
+
* leaf's wildcard would grant nothing beyond the leaf itself, so it is omitted.
|
|
12
|
+
* The bare `*` is never emitted: it is a valid grant but never a sensible
|
|
13
|
+
* requirement.
|
|
14
|
+
*/
|
|
15
|
+
export declare const serializeScopesTypes: ({ definitions, }: SerializeScopesOptions) => string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { flattenScopeDefinitions } from '@pikku/core/scope';
|
|
2
|
+
const quote = (value) => `'${value.replace(/'/g, "\\'")}'`;
|
|
3
|
+
/**
|
|
4
|
+
* Generates the `ScopeId` union and scope metadata from `wireScope`
|
|
5
|
+
* declarations.
|
|
6
|
+
*
|
|
7
|
+
* The union carries every declared node plus a wildcard form for each node that
|
|
8
|
+
* has descendants — `admin:*` is requirable when `admin` has children, but a
|
|
9
|
+
* leaf's wildcard would grant nothing beyond the leaf itself, so it is omitted.
|
|
10
|
+
* The bare `*` is never emitted: it is a valid grant but never a sensible
|
|
11
|
+
* requirement.
|
|
12
|
+
*/
|
|
13
|
+
export const serializeScopesTypes = ({ definitions, }) => {
|
|
14
|
+
const flat = flattenScopeDefinitions(definitions);
|
|
15
|
+
const ids = flat.map((s) => s.id);
|
|
16
|
+
const hasChildren = (id) => ids.some((other) => other.startsWith(`${id}:`));
|
|
17
|
+
const requirable = [
|
|
18
|
+
...ids,
|
|
19
|
+
...ids.filter(hasChildren).map((id) => `${id}:*`),
|
|
20
|
+
].sort();
|
|
21
|
+
const union = requirable.length > 0
|
|
22
|
+
? `\n${requirable.map((id) => ` | ${quote(id)}`).join('\n')}`
|
|
23
|
+
: ' never';
|
|
24
|
+
const displayNames = [...flat]
|
|
25
|
+
.sort((a, b) => a.id.localeCompare(b.id))
|
|
26
|
+
.flatMap((scope) => {
|
|
27
|
+
const displayName = definitions.find((d) => d.name === scope.id)?.displayName;
|
|
28
|
+
return displayName ? [` ${quote(scope.id)}: ${quote(displayName)},`] : [];
|
|
29
|
+
});
|
|
30
|
+
return `/**
|
|
31
|
+
* This file was generated by the @pikku/cli
|
|
32
|
+
*/
|
|
33
|
+
import type { FlatScope, ScopeDefinitionsMeta } from '@pikku/core/scope'
|
|
34
|
+
import { flattenScopeDefinitions } from '@pikku/core/scope'
|
|
35
|
+
import definitions from './pikku-scopes-meta.gen.json' with { type: 'json' }
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Every scope a function can require.
|
|
39
|
+
*
|
|
40
|
+
* A \`:*\` entry requires the scope and all of its descendants. Held grants are
|
|
41
|
+
* matched against this by \`verifyScopes\` — \`admin:*\` on a session satisfies
|
|
42
|
+
* any \`admin:...\` requirement.
|
|
43
|
+
*/
|
|
44
|
+
export type ScopeId =${union}
|
|
45
|
+
|
|
46
|
+
export interface ScopeMeta {
|
|
47
|
+
id: ScopeId
|
|
48
|
+
displayName?: string
|
|
49
|
+
description?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The declared scope set, for a ScopeService to sync into its store.
|
|
54
|
+
*
|
|
55
|
+
* Derived from the metadata sidecar rather than inlined, so that the import
|
|
56
|
+
* above forces tsc to emit the .json alongside this file. An addon publishes
|
|
57
|
+
* only its compiled output, and a host reads that .json to merge the addon's
|
|
58
|
+
* scopes into its own \`ScopeId\` union and declared set — an uncopied sidecar
|
|
59
|
+
* would leave the addon's scopes ungrantable.
|
|
60
|
+
*
|
|
61
|
+
* Additive: removing a declaration leaves an inert row rather than revoking a
|
|
62
|
+
* grant mid-deploy. Use \`pikku scopes prune\` to remove them deliberately.
|
|
63
|
+
*/
|
|
64
|
+
export const SCOPES: FlatScope[] = flattenScopeDefinitions(
|
|
65
|
+
Object.values(definitions as ScopeDefinitionsMeta)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const DISPLAY_NAMES: Record<string, string> = {
|
|
69
|
+
${displayNames.join('\n')}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Declared scopes, keyed by id. Rendered by the console when granting. */
|
|
73
|
+
export const SCOPES_META: Record<string, ScopeMeta> = Object.fromEntries(
|
|
74
|
+
SCOPES.map((scope) => [
|
|
75
|
+
scope.id,
|
|
76
|
+
{
|
|
77
|
+
id: scope.id as ScopeId,
|
|
78
|
+
...(DISPLAY_NAMES[scope.id]
|
|
79
|
+
? { displayName: DISPLAY_NAMES[scope.id] }
|
|
80
|
+
: {}),
|
|
81
|
+
...(scope.description ? { description: scope.description } : {}),
|
|
82
|
+
},
|
|
83
|
+
])
|
|
84
|
+
)
|
|
85
|
+
`;
|
|
86
|
+
};
|
|
@@ -32,6 +32,8 @@ export const serializeSecretsTypes = ({ definitions, schemaLookup, secretsFile,
|
|
|
32
32
|
const imports = [];
|
|
33
33
|
imports.push(`import { TypedSecretService as CoreTypedSecretService, type CredentialMeta } from '@pikku/core/services'`);
|
|
34
34
|
imports.push(`import type { SecretService } from '@pikku/core/services'`);
|
|
35
|
+
imports.push(`import type { SecretDefinitionsMeta } from '@pikku/core/secret'`);
|
|
36
|
+
imports.push(`import secretsMeta from './pikku-secrets-meta.gen.json' with { type: 'json' }`);
|
|
35
37
|
if (needsZod) {
|
|
36
38
|
imports.push(`import type { z } from 'zod'`);
|
|
37
39
|
}
|
|
@@ -45,6 +47,17 @@ export const serializeSecretsTypes = ({ definitions, schemaLookup, secretsFile,
|
|
|
45
47
|
}
|
|
46
48
|
return `${imports.join('\n')}
|
|
47
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Every secret declared in this package.
|
|
52
|
+
*
|
|
53
|
+
* Read from the metadata sidecar rather than inlined, so that the import above
|
|
54
|
+
* forces tsc to emit the .json alongside this file. An addon publishes only its
|
|
55
|
+
* compiled output, and a host reads that .json to discover the addon's declared
|
|
56
|
+
* secrets — an uncopied sidecar leaves them invisible to the host.
|
|
57
|
+
*/
|
|
58
|
+
export const SECRETS_META: SecretDefinitionsMeta =
|
|
59
|
+
secretsMeta as SecretDefinitionsMeta
|
|
60
|
+
|
|
48
61
|
export interface CredentialsMap {
|
|
49
62
|
${mapEntries.join('\n')}
|
|
50
63
|
}
|