@pikku/core 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- package/dist/errors/error-handler.js +3 -3
- package/dist/errors/errors.d.ts +8 -0
- package/dist/errors/errors.js +16 -0
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/function/function-runner.d.ts +10 -3
- package/dist/function/function-runner.js +136 -31
- package/dist/function/functions.types.d.ts +35 -12
- package/dist/function/functions.types.js +16 -6
- package/dist/function/index.d.ts +2 -2
- package/dist/function/index.js +1 -2
- package/dist/handle-error.js +1 -10
- package/dist/index.d.ts +30 -24
- package/dist/index.js +19 -27
- package/dist/middleware/auth-apikey.d.ts +1 -1
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-bearer.js +3 -6
- package/dist/middleware/auth-cookie.d.ts +1 -1
- package/dist/middleware/auth-cookie.js +6 -8
- package/dist/middleware/cors.d.ts +46 -0
- package/dist/middleware/cors.js +73 -0
- package/dist/middleware/index.d.ts +5 -3
- package/dist/middleware/index.js +5 -3
- package/dist/middleware/remote-auth.d.ts +5 -0
- package/dist/middleware/remote-auth.js +55 -0
- package/dist/middleware/timeout.d.ts +1 -1
- package/dist/middleware-runner.d.ts +3 -14
- package/dist/middleware-runner.js +14 -16
- package/dist/permissions.d.ts +3 -86
- package/dist/permissions.js +20 -80
- package/dist/pikku-state.d.ts +33 -104
- package/dist/pikku-state.js +150 -66
- package/dist/schema.d.ts +8 -6
- package/dist/schema.js +31 -18
- package/dist/services/ai-agent-runner-service.d.ts +24 -0
- package/dist/services/ai-agent-runner-service.js +1 -0
- package/dist/services/ai-run-state-service.d.ts +13 -0
- package/dist/services/ai-run-state-service.js +1 -0
- package/dist/services/ai-storage-service.d.ts +18 -0
- package/dist/services/ai-storage-service.js +1 -0
- package/dist/services/deployment-service.d.ts +19 -0
- package/dist/services/deployment-service.js +1 -0
- package/dist/services/gopass-secrets.d.ts +47 -0
- package/dist/services/gopass-secrets.js +94 -0
- package/dist/services/in-memory-trigger-service.d.ts +23 -0
- package/dist/services/in-memory-trigger-service.js +50 -0
- package/dist/services/in-memory-workflow-service.d.ts +59 -0
- package/dist/services/in-memory-workflow-service.js +287 -0
- package/dist/services/index.d.ts +25 -11
- package/dist/services/index.js +10 -13
- package/dist/services/local-secrets.d.ts +23 -0
- package/dist/services/local-secrets.js +45 -0
- package/dist/services/local-variables.d.ts +5 -0
- package/dist/services/local-variables.js +18 -0
- package/dist/services/scheduler-service.d.ts +21 -1
- package/dist/services/scheduler-service.js +14 -0
- package/dist/services/schema-service.d.ts +6 -0
- package/dist/services/scoped-secret-service.d.ts +16 -0
- package/dist/services/scoped-secret-service.js +35 -0
- package/dist/services/secret-service.d.ts +25 -4
- package/dist/services/trigger-service.d.ts +23 -0
- package/dist/services/trigger-service.js +1 -0
- package/dist/services/typed-secret-service.d.ts +30 -0
- package/dist/services/typed-secret-service.js +40 -0
- package/dist/services/typed-variables-service.d.ts +27 -0
- package/dist/services/typed-variables-service.js +46 -0
- package/dist/services/user-session-service.d.ts +13 -0
- package/dist/services/user-session-service.js +17 -0
- package/dist/services/variables-service.d.ts +5 -0
- package/dist/services/workflow-service.d.ts +43 -0
- package/dist/services/workflow-service.js +1 -0
- package/dist/types/core.types.d.ts +54 -10
- package/dist/types/core.types.js +7 -0
- package/dist/types/state.types.d.ts +127 -0
- package/dist/types/state.types.js +1 -0
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +60 -3
- package/dist/version.d.ts +6 -0
- package/dist/version.js +19 -0
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +29 -0
- package/dist/wirings/ai-agent/ai-agent-memory.js +199 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +9 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.js +36 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +60 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.js +312 -0
- package/dist/wirings/ai-agent/ai-agent-registry.d.ts +15 -0
- package/dist/wirings/ai-agent/ai-agent-registry.js +47 -0
- package/dist/wirings/ai-agent/ai-agent-runner.d.ts +3 -0
- package/dist/wirings/ai-agent/ai-agent-runner.js +96 -0
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +11 -0
- package/dist/wirings/ai-agent/ai-agent-stream.js +503 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +254 -0
- package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
- package/dist/wirings/ai-agent/index.d.ts +5 -0
- package/dist/wirings/ai-agent/index.js +4 -0
- package/dist/wirings/channel/channel-common.d.ts +7 -4
- package/dist/wirings/channel/channel-common.js +15 -8
- package/dist/wirings/channel/channel-handler.js +13 -4
- package/dist/wirings/channel/channel-middleware-runner.d.ts +9 -0
- package/dist/wirings/channel/channel-middleware-runner.js +73 -0
- package/dist/wirings/channel/channel-runner.js +12 -12
- package/dist/wirings/channel/channel.types.d.ts +5 -1
- package/dist/wirings/channel/define-channel-routes.d.ts +21 -0
- package/dist/wirings/channel/define-channel-routes.js +23 -0
- package/dist/wirings/channel/index.d.ts +10 -8
- package/dist/wirings/channel/index.js +7 -8
- package/dist/wirings/channel/local/index.d.ts +3 -3
- package/dist/wirings/channel/local/index.js +3 -3
- package/dist/wirings/channel/local/local-channel-runner.js +18 -6
- package/dist/wirings/channel/log-channels.js +1 -1
- package/dist/wirings/channel/serverless/index.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +17 -6
- package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
- package/dist/wirings/cli/channel/index.d.ts +1 -1
- package/dist/wirings/cli/channel/index.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +1 -1
- package/dist/wirings/cli/cli-runner.js +22 -18
- package/dist/wirings/cli/cli.types.d.ts +7 -6
- package/dist/wirings/cli/define-cli-commands.d.ts +19 -0
- package/dist/wirings/cli/define-cli-commands.js +20 -0
- package/dist/wirings/cli/index.d.ts +2 -3
- package/dist/wirings/cli/index.js +1 -3
- package/dist/wirings/http/http-routes.d.ts +69 -0
- package/dist/wirings/http/http-routes.js +139 -0
- package/dist/wirings/http/http-runner.d.ts +2 -2
- package/dist/wirings/http/http-runner.js +62 -27
- package/dist/wirings/http/http.types.d.ts +77 -24
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- package/dist/wirings/http/log-http-routes.js +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +2 -2
- package/dist/wirings/mcp/index.d.ts +4 -3
- package/dist/wirings/mcp/index.js +3 -3
- package/dist/wirings/mcp/mcp-runner.d.ts +1 -3
- package/dist/wirings/mcp/mcp-runner.js +42 -56
- package/dist/wirings/mcp/mcp.types.d.ts +3 -3
- package/dist/wirings/node/index.d.ts +2 -0
- package/dist/wirings/node/index.js +1 -0
- package/dist/wirings/node/node.types.d.ts +20 -0
- package/dist/wirings/node/node.types.js +1 -0
- package/dist/wirings/oauth2/index.d.ts +3 -0
- package/dist/wirings/oauth2/index.js +2 -0
- package/dist/wirings/oauth2/oauth2-client.d.ts +47 -0
- package/dist/wirings/oauth2/oauth2-client.js +267 -0
- package/dist/wirings/oauth2/oauth2.types.d.ts +65 -0
- package/dist/wirings/oauth2/oauth2.types.js +4 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.d.ts +20 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.js +21 -0
- package/dist/wirings/queue/index.d.ts +2 -2
- package/dist/wirings/queue/index.js +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +7 -0
- package/dist/wirings/queue/queue-runner.js +23 -12
- package/dist/wirings/queue/queue.types.d.ts +8 -2
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +40 -13
- package/dist/wirings/rpc/rpc-runner.js +191 -25
- package/dist/wirings/rpc/rpc-types.d.ts +15 -4
- package/dist/wirings/scheduler/index.d.ts +3 -3
- package/dist/wirings/scheduler/index.js +2 -3
- package/dist/wirings/scheduler/log-schedulers.js +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +5 -0
- package/dist/wirings/scheduler/scheduler-runner.js +28 -10
- package/dist/wirings/secret/index.d.ts +3 -0
- package/dist/wirings/secret/index.js +2 -0
- package/dist/wirings/secret/secret.types.d.ts +27 -0
- package/dist/wirings/secret/secret.types.js +1 -0
- package/dist/wirings/secret/validate-secret-definitions.d.ts +6 -0
- package/dist/wirings/secret/validate-secret-definitions.js +55 -0
- package/dist/wirings/trigger/index.d.ts +3 -0
- package/dist/wirings/trigger/index.js +2 -0
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +26 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +75 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +42 -0
- package/dist/wirings/trigger/trigger-runner.js +85 -0
- package/dist/wirings/trigger/trigger.types.d.ts +130 -0
- package/dist/wirings/trigger/trigger.types.js +40 -0
- package/dist/wirings/variable/index.d.ts +3 -0
- package/dist/wirings/variable/index.js +2 -0
- package/dist/wirings/variable/validate-variable-definitions.d.ts +6 -0
- package/dist/wirings/variable/validate-variable-definitions.js +45 -0
- package/dist/wirings/variable/variable.types.d.ts +18 -0
- package/dist/wirings/variable/variable.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +5 -0
- package/dist/wirings/workflow/dsl/index.js +4 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +292 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.js +23 -0
- package/dist/wirings/workflow/graph/graph-node.d.ts +117 -0
- package/dist/wirings/workflow/graph/graph-node.js +58 -0
- package/dist/wirings/workflow/graph/graph-runner.d.ts +9 -0
- package/dist/wirings/workflow/graph/graph-runner.js +540 -0
- package/dist/wirings/workflow/graph/index.d.ts +4 -0
- package/dist/wirings/workflow/graph/index.js +3 -0
- package/dist/wirings/workflow/graph/template.d.ts +15 -0
- package/dist/wirings/workflow/graph/template.js +27 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +15 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.js +8 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +82 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
- package/dist/wirings/workflow/index.d.ts +7 -12
- package/dist/wirings/workflow/index.js +8 -11
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +114 -10
- package/dist/wirings/workflow/pikku-workflow-service.js +386 -115
- package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
- package/dist/wirings/workflow/workflow-helpers.js +38 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +1 -0
- package/dist/wirings/workflow/workflow-utils.js +1 -0
- package/dist/wirings/workflow/workflow.types.d.ts +83 -214
- package/package.json +13 -6
- package/run-tests.sh +4 -1
- package/src/crypto-utils.ts +99 -0
- package/src/errors/error-handler.ts +3 -3
- package/src/errors/errors.ts +17 -0
- package/src/errors/index.ts +0 -1
- package/src/factory-functions.test.ts +42 -2
- package/src/function/function-runner.test.ts +5 -12
- package/src/function/function-runner.ts +195 -40
- package/src/function/functions.types.ts +66 -14
- package/src/function/index.ts +5 -2
- package/src/handle-error.ts +2 -10
- package/src/index.ts +106 -27
- package/src/middleware/auth-apikey.test.ts +15 -12
- package/src/middleware/auth-apikey.ts +3 -3
- package/src/middleware/auth-bearer.test.ts +17 -14
- package/src/middleware/auth-bearer.ts +25 -27
- package/src/middleware/auth-cookie.test.ts +16 -13
- package/src/middleware/auth-cookie.ts +6 -8
- package/src/middleware/cors.ts +96 -0
- package/src/middleware/index.ts +5 -3
- package/src/middleware/remote-auth.ts +68 -0
- package/src/middleware-runner.test.ts +122 -0
- package/src/middleware-runner.ts +24 -17
- package/src/permissions.test.ts +102 -86
- package/src/permissions.ts +32 -93
- package/src/pikku-state.ts +168 -201
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.ts +50 -18
- package/src/services/ai-agent-runner-service.ts +29 -0
- package/src/services/ai-run-state-service.ts +20 -0
- package/src/services/ai-storage-service.ts +39 -0
- package/src/services/deployment-service.ts +22 -0
- package/src/services/gopass-secrets.ts +95 -0
- package/src/services/in-memory-trigger-service.ts +68 -0
- package/src/services/in-memory-workflow-service.ts +395 -0
- package/src/services/index.ts +49 -14
- package/src/services/local-secrets.ts +51 -0
- package/src/services/local-variables.ts +22 -0
- package/src/services/scheduler-service.ts +29 -1
- package/src/services/schema-service.ts +7 -0
- package/src/services/scoped-secret-service.ts +41 -0
- package/src/services/secret-service.ts +25 -4
- package/src/services/trigger-service.ts +38 -0
- package/src/services/typed-secret-service.ts +70 -0
- package/src/services/typed-variables-service.ts +81 -0
- package/src/services/user-session-service.ts +23 -0
- package/src/services/variables-service.ts +5 -0
- package/src/services/workflow-service.ts +94 -0
- package/src/types/core.types.ts +82 -8
- package/src/types/state.types.ts +169 -0
- package/src/utils.ts +74 -5
- package/src/version.test.ts +80 -0
- package/src/version.ts +25 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
- package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +470 -0
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +37 -0
- package/src/wirings/ai-agent/ai-agent-registry.ts +82 -0
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +75 -0
- package/src/wirings/ai-agent/ai-agent-runner.ts +137 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +246 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +774 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +273 -0
- package/src/wirings/ai-agent/index.ts +28 -0
- package/src/wirings/channel/channel-common.ts +32 -19
- package/src/wirings/channel/channel-handler.ts +18 -5
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +14 -15
- package/src/wirings/channel/channel.types.ts +17 -1
- package/src/wirings/channel/define-channel-routes.ts +25 -0
- package/src/wirings/channel/index.ts +23 -8
- package/src/wirings/channel/local/index.ts +3 -3
- package/src/wirings/channel/local/local-channel-runner.test.ts +47 -2
- package/src/wirings/channel/local/local-channel-runner.ts +22 -6
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +22 -6
- package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +28 -28
- package/src/wirings/cli/cli-runner.ts +27 -19
- package/src/wirings/cli/cli.types.ts +12 -11
- package/src/wirings/cli/command-parser.test.ts +8 -8
- package/src/wirings/cli/define-cli-commands.ts +24 -0
- package/src/wirings/cli/index.ts +10 -4
- package/src/wirings/http/http-routes.test.ts +322 -0
- package/src/wirings/http/http-routes.ts +198 -0
- package/src/wirings/http/http-runner.test.ts +5 -5
- package/src/wirings/http/http-runner.ts +80 -29
- package/src/wirings/http/http.types.ts +121 -23
- package/src/wirings/http/index.ts +16 -4
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
- package/src/wirings/http/routers/path-to-regex.ts +2 -2
- package/src/wirings/mcp/index.ts +27 -3
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
- package/src/wirings/mcp/mcp-runner.ts +56 -67
- package/src/wirings/mcp/mcp.types.ts +3 -3
- package/src/wirings/node/index.ts +2 -0
- package/src/wirings/node/node.types.ts +23 -0
- package/src/wirings/oauth2/index.ts +3 -0
- package/src/wirings/oauth2/oauth2-client.test.ts +929 -0
- package/src/wirings/oauth2/oauth2-client.ts +335 -0
- package/src/wirings/oauth2/oauth2.types.ts +69 -0
- package/src/wirings/oauth2/wire-oauth2-credential.ts +23 -0
- package/src/wirings/queue/index.ts +14 -2
- package/src/wirings/queue/queue-runner.test.ts +115 -73
- package/src/wirings/queue/queue-runner.ts +39 -13
- package/src/wirings/queue/queue.types.ts +12 -2
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +270 -34
- package/src/wirings/rpc/rpc-types.ts +21 -4
- package/src/wirings/scheduler/index.ts +7 -4
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +97 -53
- package/src/wirings/scheduler/scheduler-runner.ts +50 -10
- package/src/wirings/secret/index.ts +9 -0
- package/src/wirings/secret/secret.types.ts +32 -0
- package/src/wirings/secret/validate-secret-definitions.ts +82 -0
- package/src/wirings/trigger/index.ts +10 -0
- package/src/wirings/trigger/pikku-trigger-service.ts +134 -0
- package/src/wirings/trigger/trigger-runner.ts +138 -0
- package/src/wirings/trigger/trigger.types.ts +178 -0
- package/src/wirings/variable/index.ts +8 -0
- package/src/wirings/variable/validate-variable-definitions.ts +69 -0
- package/src/wirings/variable/variable.types.ts +22 -0
- package/src/wirings/workflow/dsl/index.ts +31 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +320 -0
- package/src/wirings/workflow/dsl/workflow-runner.ts +28 -0
- package/src/wirings/workflow/graph/graph-node.ts +222 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +495 -0
- package/src/wirings/workflow/graph/graph-runner.ts +816 -0
- package/src/wirings/workflow/graph/index.ts +14 -0
- package/src/wirings/workflow/graph/template.ts +42 -0
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +29 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +104 -0
- package/src/wirings/workflow/index.ts +64 -26
- package/src/wirings/workflow/pikku-workflow-service.test.ts +212 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +571 -136
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow-utils.ts +0 -0
- package/src/wirings/workflow/workflow.types.ts +123 -279
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/workflow/workflow-runner.d.ts +0 -34
- package/dist/wirings/workflow/workflow-runner.js +0 -65
- package/src/function/function-runner.ts.bak +0 -188
- package/src/wirings/workflow/workflow-runner.ts +0 -72
package/dist/permissions.d.ts
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
1
|
import { CoreServices, PikkuWiringTypes, PermissionMetadata, PikkuWire } from './types/core.types.js';
|
|
2
2
|
import { CorePermissionGroup, CorePikkuPermission } from './function/functions.types.js';
|
|
3
|
-
/**
|
|
4
|
-
* This function validates permissions by iterating over permission groups and executing the corresponding permission functions. If all functions in at least one group return true, the permission is considered valid.
|
|
5
|
-
* @param services - The core services required for permission validation.
|
|
6
|
-
* @param data - The data to be used in the permission validation functions.
|
|
7
|
-
* @param wire - The wire object containing request/response context and session.
|
|
8
|
-
* @returns A promise that resolves to void.
|
|
9
|
-
*/
|
|
10
|
-
export declare const verifyPermissions: <Out = any>(permissions: CorePermissionGroup, services: CoreServices, data: any, wire: PikkuWire<any, never, any, never, never, never>) => Promise<boolean>;
|
|
11
|
-
/**
|
|
12
|
-
* Registers a single permission function by name in the global permission store.
|
|
13
|
-
*
|
|
14
|
-
* This function is used by CLI-generated code to register permission functions
|
|
15
|
-
* that can be referenced by name in metadata. It stores permissions in a special
|
|
16
|
-
* namespace to avoid conflicts with tag-based permissions.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} name - The unique name (pikkuFuncName) of the permission function.
|
|
19
|
-
* @param {CorePikkuPermission} permission - The permission function to register.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // Called by CLI-generated pikku-permissions.gen.ts
|
|
24
|
-
* registerPermission('adminPermission_src_permissions_ts_10_5', adminPermission)
|
|
25
|
-
* registerPermission('readPermission_src_permissions_ts_20_10', readPermission)
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare const registerPermission: (name: string, permission: CorePikkuPermission<any>) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Retrieves a registered permission function by its name.
|
|
31
|
-
*
|
|
32
|
-
* This function looks up permissions that was registered with registerPermission.
|
|
33
|
-
* It's used internally by the framework to resolve permission references in metadata.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} name - The unique name (pikkuFuncName) of the permission function.
|
|
36
|
-
* @returns {CorePikkuPermission | undefined} The permission function, or undefined if not found.
|
|
37
|
-
*
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
export declare const getPermissionByName: (name: string) => CorePikkuPermission | undefined;
|
|
41
3
|
/**
|
|
42
4
|
* Adds global permissions for a specific tag.
|
|
43
5
|
*
|
|
@@ -66,58 +28,12 @@ export declare const getPermissionByName: (name: string) => CorePikkuPermission
|
|
|
66
28
|
* ])
|
|
67
29
|
* ```
|
|
68
30
|
*/
|
|
69
|
-
export declare const addPermission: (tag: string, permissions: CorePermissionGroup | CorePikkuPermission[]) => CorePermissionGroup | CorePikkuPermission[];
|
|
70
|
-
/**
|
|
71
|
-
* Retrieves permissions for a given set of tags.
|
|
72
|
-
*
|
|
73
|
-
* This function looks up all permissions registered for any of the provided tags
|
|
74
|
-
* and returns them as a flattened array.
|
|
75
|
-
*
|
|
76
|
-
* @param {string[]} tags - Array of tags to look up permissions for.
|
|
77
|
-
* @returns {any[]} Array of permission functions that apply to the given tags.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* // Get all permissions for tags 'api' and 'auth'
|
|
82
|
-
* const permissions = getPermissionsForTags(['api', 'auth'])
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare const getPermissionsForTags: (tags?: string[]) => readonly (CorePermissionGroup | CorePikkuPermission)[];
|
|
86
|
-
/**
|
|
87
|
-
* Combines wiring-specific permissions with function-level permissions.
|
|
88
|
-
*
|
|
89
|
-
* This function resolves permission metadata into actual permission functions and combines them.
|
|
90
|
-
* It filters out wire permissions without tags from inheritedPermissions to avoid duplication
|
|
91
|
-
* (those are passed separately as wirePermissions).
|
|
92
|
-
*
|
|
93
|
-
* @param {object} options - Configuration object for combining permissions.
|
|
94
|
-
* @param {PermissionMetadata[] | undefined} options.wireInheritedPermissions - Metadata from wiring (HTTP + tags + wire with tags).
|
|
95
|
-
* @param {CorePermissionGroup | CorePikkuPermission[] | undefined} options.wirePermissions - Inline wire permissions.
|
|
96
|
-
* @param {PermissionMetadata[] | undefined} options.funcInheritedPermissions - Function permissions metadata (only tags).
|
|
97
|
-
* @param {CorePermissionGroup | CorePikkuPermission[] | undefined} options.funcPermissions - Inline function permissions.
|
|
98
|
-
* @returns {(CorePermissionGroup | CorePikkuPermission)[]} Combined array of resolved permissions.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const combined = combinePermissions(wireType, wireId, {
|
|
103
|
-
* wireInheritedPermissions: meta.permissions,
|
|
104
|
-
* wirePermissions: inlinePermissions,
|
|
105
|
-
* funcInheritedPermissions: funcMeta.permissions,
|
|
106
|
-
* funcPermissions: funcConfig.permissions
|
|
107
|
-
* })
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export declare const combinePermissions: (wireType: PikkuWiringTypes, uid: string, { wireInheritedPermissions, wirePermissions, funcInheritedPermissions, funcPermissions, }?: {
|
|
111
|
-
wireInheritedPermissions?: PermissionMetadata[];
|
|
112
|
-
wirePermissions?: CorePermissionGroup | CorePikkuPermission[];
|
|
113
|
-
funcInheritedPermissions?: PermissionMetadata[];
|
|
114
|
-
funcPermissions?: CorePermissionGroup | CorePikkuPermission[];
|
|
115
|
-
}) => readonly (CorePermissionGroup | CorePikkuPermission)[];
|
|
31
|
+
export declare const addPermission: (tag: string, permissions: CorePermissionGroup | CorePikkuPermission[], packageName?: string | null) => CorePermissionGroup | CorePikkuPermission[];
|
|
116
32
|
/**
|
|
117
33
|
* Runs permission checks using combined permissions from all sources.
|
|
118
34
|
* Combines permissions from wire and function levels, then validates them.
|
|
119
35
|
*/
|
|
120
|
-
export declare const runPermissions: (wireType: PikkuWiringTypes, uid: string, { wireInheritedPermissions, wirePermissions, funcInheritedPermissions, funcPermissions, services, wire, data, }: {
|
|
36
|
+
export declare const runPermissions: (wireType: PikkuWiringTypes, uid: string, { wireInheritedPermissions, wirePermissions, funcInheritedPermissions, funcPermissions, services, wire, data, packageName, }: {
|
|
121
37
|
wireInheritedPermissions?: PermissionMetadata[];
|
|
122
38
|
wirePermissions?: CorePermissionGroup | CorePikkuPermission[];
|
|
123
39
|
funcInheritedPermissions?: PermissionMetadata[];
|
|
@@ -125,4 +41,5 @@ export declare const runPermissions: (wireType: PikkuWiringTypes, uid: string, {
|
|
|
125
41
|
services: CoreServices;
|
|
126
42
|
wire: PikkuWire<any, never, any, never, never, never>;
|
|
127
43
|
data: any;
|
|
44
|
+
packageName?: string | null;
|
|
128
45
|
}) => Promise<void>;
|
package/dist/permissions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pikkuState } from './pikku-state.js';
|
|
2
2
|
import { ForbiddenError } from './errors/errors.js';
|
|
3
|
-
import { freezeDedupe } from './utils.js';
|
|
3
|
+
import { freezeDedupe, getTagGroups } from './utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* This function validates permissions by iterating over permission groups and executing the corresponding permission functions. If all functions in at least one group return true, the permission is considered valid.
|
|
6
6
|
* @param services - The core services required for permission validation.
|
|
@@ -8,7 +8,7 @@ import { freezeDedupe } from './utils.js';
|
|
|
8
8
|
* @param wire - The wire object containing request/response context and session.
|
|
9
9
|
* @returns A promise that resolves to void.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
const verifyPermissions = async (permissions, services, data, wire) => {
|
|
12
12
|
if (!permissions) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
@@ -33,40 +33,19 @@ export const verifyPermissions = async (permissions, services, data, wire) => {
|
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
};
|
|
36
|
-
/**
|
|
37
|
-
* Registers a single permission function by name in the global permission store.
|
|
38
|
-
*
|
|
39
|
-
* This function is used by CLI-generated code to register permission functions
|
|
40
|
-
* that can be referenced by name in metadata. It stores permissions in a special
|
|
41
|
-
* namespace to avoid conflicts with tag-based permissions.
|
|
42
|
-
*
|
|
43
|
-
* @param {string} name - The unique name (pikkuFuncName) of the permission function.
|
|
44
|
-
* @param {CorePikkuPermission} permission - The permission function to register.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* // Called by CLI-generated pikku-permissions.gen.ts
|
|
49
|
-
* registerPermission('adminPermission_src_permissions_ts_10_5', adminPermission)
|
|
50
|
-
* registerPermission('readPermission_src_permissions_ts_20_10', readPermission)
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export const registerPermission = (name, permission) => {
|
|
54
|
-
const permissionStore = pikkuState('misc', 'permissions');
|
|
55
|
-
permissionStore[name] = [permission];
|
|
56
|
-
};
|
|
57
36
|
/**
|
|
58
37
|
* Retrieves a registered permission function by its name.
|
|
59
38
|
*
|
|
60
39
|
* This function looks up permissions that was registered with registerPermission.
|
|
61
40
|
* It's used internally by the framework to resolve permission references in metadata.
|
|
62
41
|
*
|
|
63
|
-
* @param {string} name - The unique name (
|
|
42
|
+
* @param {string} name - The unique name (pikkuFuncId) of the permission function.
|
|
64
43
|
* @returns {CorePikkuPermission | undefined} The permission function, or undefined if not found.
|
|
65
44
|
*
|
|
66
45
|
* @internal
|
|
67
46
|
*/
|
|
68
|
-
|
|
69
|
-
const permissionStore = pikkuState('misc', 'permissions');
|
|
47
|
+
const getPermissionByName = (name) => {
|
|
48
|
+
const permissionStore = pikkuState(null, 'misc', 'permissions');
|
|
70
49
|
const permission = permissionStore[name];
|
|
71
50
|
if (Array.isArray(permission) && permission.length === 1) {
|
|
72
51
|
return permission[0];
|
|
@@ -101,57 +80,23 @@ export const getPermissionByName = (name) => {
|
|
|
101
80
|
* ])
|
|
102
81
|
* ```
|
|
103
82
|
*/
|
|
104
|
-
export const addPermission = (tag, permissions) => {
|
|
105
|
-
const tagGroups = pikkuState('permissions', 'tagGroup');
|
|
83
|
+
export const addPermission = (tag, permissions, packageName = null) => {
|
|
84
|
+
const tagGroups = pikkuState(packageName, 'permissions', 'tagGroup');
|
|
106
85
|
if (tagGroups[tag]) {
|
|
107
86
|
throw new Error(`Permissions for tag '${tag}' already exist. Use a different tag or remove the existing permissions first.`);
|
|
108
87
|
}
|
|
109
88
|
tagGroups[tag] = permissions;
|
|
110
89
|
return permissions;
|
|
111
90
|
};
|
|
112
|
-
const EMPTY = [];
|
|
113
|
-
/**
|
|
114
|
-
* Retrieves permissions for a given set of tags.
|
|
115
|
-
*
|
|
116
|
-
* This function looks up all permissions registered for any of the provided tags
|
|
117
|
-
* and returns them as a flattened array.
|
|
118
|
-
*
|
|
119
|
-
* @param {string[]} tags - Array of tags to look up permissions for.
|
|
120
|
-
* @returns {any[]} Array of permission functions that apply to the given tags.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* // Get all permissions for tags 'api' and 'auth'
|
|
125
|
-
* const permissions = getPermissionsForTags(['api', 'auth'])
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
export const getPermissionsForTags = (tags) => {
|
|
129
|
-
if (!tags || tags.length === 0) {
|
|
130
|
-
return EMPTY;
|
|
131
|
-
}
|
|
132
|
-
const permissionsStore = pikkuState('permissions', 'tagGroup');
|
|
133
|
-
const applicablePermissions = [];
|
|
134
|
-
// Collect permissions for all matching tags
|
|
135
|
-
for (const tag of new Set(tags)) {
|
|
136
|
-
const tagPermissions = permissionsStore[tag];
|
|
137
|
-
if (tagPermissions) {
|
|
138
|
-
if (Array.isArray(tagPermissions)) {
|
|
139
|
-
applicablePermissions.push(...tagPermissions);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
applicablePermissions.push(tagPermissions);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return applicablePermissions;
|
|
147
|
-
};
|
|
148
91
|
const combinedPermissionsCache = {
|
|
149
92
|
http: {},
|
|
150
93
|
rpc: {},
|
|
151
94
|
channel: {},
|
|
152
95
|
queue: {},
|
|
153
96
|
scheduler: {},
|
|
97
|
+
trigger: {},
|
|
154
98
|
mcp: {},
|
|
99
|
+
agent: {},
|
|
155
100
|
cli: {},
|
|
156
101
|
workflow: {},
|
|
157
102
|
};
|
|
@@ -179,7 +124,7 @@ const combinedPermissionsCache = {
|
|
|
179
124
|
* })
|
|
180
125
|
* ```
|
|
181
126
|
*/
|
|
182
|
-
|
|
127
|
+
const combinePermissions = (wireType, uid, { wireInheritedPermissions, wirePermissions, funcInheritedPermissions, funcPermissions, packageName = null, } = {}) => {
|
|
183
128
|
if (combinedPermissionsCache[wireType][uid]) {
|
|
184
129
|
return combinedPermissionsCache[wireType][uid];
|
|
185
130
|
}
|
|
@@ -189,7 +134,7 @@ export const combinePermissions = (wireType, uid, { wireInheritedPermissions, wi
|
|
|
189
134
|
for (const meta of wireInheritedPermissions) {
|
|
190
135
|
if (meta.type === 'http') {
|
|
191
136
|
// Look up HTTP permission group from pikkuState
|
|
192
|
-
const group = pikkuState('permissions', 'httpGroup')[meta.route];
|
|
137
|
+
const group = pikkuState(packageName, 'permissions', 'httpGroup')[meta.route];
|
|
193
138
|
if (group) {
|
|
194
139
|
if (Array.isArray(group)) {
|
|
195
140
|
resolved.push(...group);
|
|
@@ -200,9 +145,8 @@ export const combinePermissions = (wireType, uid, { wireInheritedPermissions, wi
|
|
|
200
145
|
}
|
|
201
146
|
}
|
|
202
147
|
else if (meta.type === 'tag') {
|
|
203
|
-
|
|
204
|
-
const group
|
|
205
|
-
if (group) {
|
|
148
|
+
const groups = getTagGroups(pikkuState(packageName, 'permissions', 'tagGroup'), meta.tag);
|
|
149
|
+
for (const group of groups) {
|
|
206
150
|
if (Array.isArray(group)) {
|
|
207
151
|
resolved.push(...group);
|
|
208
152
|
}
|
|
@@ -233,9 +177,8 @@ export const combinePermissions = (wireType, uid, { wireInheritedPermissions, wi
|
|
|
233
177
|
if (funcInheritedPermissions) {
|
|
234
178
|
for (const meta of funcInheritedPermissions) {
|
|
235
179
|
if (meta.type === 'tag') {
|
|
236
|
-
|
|
237
|
-
const group
|
|
238
|
-
if (group) {
|
|
180
|
+
const groups = getTagGroups(pikkuState(packageName, 'permissions', 'tagGroup'), meta.tag);
|
|
181
|
+
for (const group of groups) {
|
|
239
182
|
if (Array.isArray(group)) {
|
|
240
183
|
resolved.push(...group);
|
|
241
184
|
}
|
|
@@ -264,27 +207,24 @@ export const combinePermissions = (wireType, uid, { wireInheritedPermissions, wi
|
|
|
264
207
|
* Runs permission checks using combined permissions from all sources.
|
|
265
208
|
* Combines permissions from wire and function levels, then validates them.
|
|
266
209
|
*/
|
|
267
|
-
export const runPermissions = async (wireType, uid, { wireInheritedPermissions, wirePermissions, funcInheritedPermissions, funcPermissions, services, wire, data, }) => {
|
|
210
|
+
export const runPermissions = async (wireType, uid, { wireInheritedPermissions, wirePermissions, funcInheritedPermissions, funcPermissions, services, wire, data, packageName = null, }) => {
|
|
268
211
|
// Combine all permissions: wireInheritedPermissions → wirePermissions → funcInheritedPermissions → funcPermissions
|
|
269
212
|
const allPermissions = combinePermissions(wireType, uid, {
|
|
270
213
|
wireInheritedPermissions,
|
|
271
214
|
wirePermissions,
|
|
272
215
|
funcInheritedPermissions,
|
|
273
216
|
funcPermissions,
|
|
217
|
+
packageName,
|
|
274
218
|
});
|
|
275
219
|
// Check all combined permissions - at least one must pass if any exist
|
|
276
220
|
if (allPermissions.length > 0) {
|
|
277
|
-
let permissioned = false;
|
|
278
221
|
for (const permission of allPermissions) {
|
|
279
222
|
const result = await verifyPermissions(typeof permission === 'function' ? { permission } : permission, services, data, wire);
|
|
280
223
|
if (result) {
|
|
281
|
-
|
|
282
|
-
// Continue executing all permissions (don't break early)
|
|
224
|
+
return;
|
|
283
225
|
}
|
|
284
226
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
throw new ForbiddenError('Permission denied');
|
|
288
|
-
}
|
|
227
|
+
services.logger.debug('Permission denied - combined permissions');
|
|
228
|
+
throw new ForbiddenError('Permission denied');
|
|
289
229
|
}
|
|
290
230
|
};
|
package/dist/pikku-state.d.ts
CHANGED
|
@@ -1,106 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { CoreScheduledTask, ScheduledTasksMeta } from './wirings/scheduler/scheduler.types.js';
|
|
5
|
-
import { ErrorDetails, PikkuError } from './errors/error-handler.js';
|
|
6
|
-
import { CorePermissionGroup, CorePikkuFunctionConfig, CorePikkuPermission } from './function/functions.types.js';
|
|
7
|
-
import { QueueWorkersMeta, CoreQueueWorker } from './wirings/queue/queue.types.js';
|
|
8
|
-
import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from './wirings/mcp/mcp.types.js';
|
|
9
|
-
import { CLIMeta, CLIProgramState } from './wirings/cli/cli.types.js';
|
|
10
|
-
import { CoreWorkflow, WorkflowsMeta } from './wirings/workflow/workflow.types.js';
|
|
11
|
-
interface PikkuState {
|
|
12
|
-
function: {
|
|
13
|
-
meta: FunctionsMeta;
|
|
14
|
-
functions: Map<string, CorePikkuFunctionConfig<any, any>>;
|
|
15
|
-
};
|
|
16
|
-
rpc: {
|
|
17
|
-
meta: Record<string, string>;
|
|
18
|
-
files: Map<string, {
|
|
19
|
-
exportedName: string;
|
|
20
|
-
path: string;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
23
|
-
http: {
|
|
24
|
-
middleware: Map<string, CorePikkuMiddleware<any, any>[]>;
|
|
25
|
-
permissions: Map<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
26
|
-
routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>;
|
|
27
|
-
meta: HTTPWiringsMeta;
|
|
28
|
-
};
|
|
29
|
-
channel: {
|
|
30
|
-
channels: Map<string, CoreChannel<any, any>>;
|
|
31
|
-
meta: ChannelsMeta;
|
|
32
|
-
};
|
|
33
|
-
scheduler: {
|
|
34
|
-
tasks: Map<string, CoreScheduledTask>;
|
|
35
|
-
meta: ScheduledTasksMeta;
|
|
36
|
-
};
|
|
37
|
-
queue: {
|
|
38
|
-
registrations: Map<string, CoreQueueWorker>;
|
|
39
|
-
meta: QueueWorkersMeta;
|
|
40
|
-
};
|
|
41
|
-
workflows: {
|
|
42
|
-
registrations: Map<string, CoreWorkflow>;
|
|
43
|
-
meta: WorkflowsMeta;
|
|
44
|
-
};
|
|
45
|
-
mcp: {
|
|
46
|
-
resources: Map<string, CoreMCPResource>;
|
|
47
|
-
resourcesMeta: MCPResourceMeta;
|
|
48
|
-
tools: Map<string, CoreMCPTool>;
|
|
49
|
-
toolsMeta: MCPToolMeta;
|
|
50
|
-
prompts: Map<string, CoreMCPPrompt>;
|
|
51
|
-
promptsMeta: MCPPromptMeta;
|
|
52
|
-
};
|
|
53
|
-
cli: {
|
|
54
|
-
meta: CLIMeta | Record<string, any>;
|
|
55
|
-
programs: Record<string, CLIProgramState>;
|
|
56
|
-
};
|
|
57
|
-
middleware: {
|
|
58
|
-
tagGroup: Record<string, CorePikkuMiddlewareGroup>;
|
|
59
|
-
httpGroup: Record<string, CorePikkuMiddlewareGroup>;
|
|
60
|
-
tagGroupMeta: Record<string, {
|
|
61
|
-
exportName: string | null;
|
|
62
|
-
sourceFile: string;
|
|
63
|
-
position: number;
|
|
64
|
-
services: FunctionServicesMeta;
|
|
65
|
-
middlewareCount: number;
|
|
66
|
-
isFactory: boolean;
|
|
67
|
-
}>;
|
|
68
|
-
httpGroupMeta: Record<string, {
|
|
69
|
-
exportName: string | null;
|
|
70
|
-
sourceFile: string;
|
|
71
|
-
position: number;
|
|
72
|
-
services: FunctionServicesMeta;
|
|
73
|
-
middlewareCount: number;
|
|
74
|
-
isFactory: boolean;
|
|
75
|
-
}>;
|
|
76
|
-
};
|
|
77
|
-
permissions: {
|
|
78
|
-
tagGroup: Record<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
79
|
-
httpGroup: Record<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
80
|
-
tagGroupMeta: Record<string, {
|
|
81
|
-
exportName: string | null;
|
|
82
|
-
sourceFile: string;
|
|
83
|
-
position: number;
|
|
84
|
-
services: FunctionServicesMeta;
|
|
85
|
-
permissionCount: number;
|
|
86
|
-
isFactory: boolean;
|
|
87
|
-
}>;
|
|
88
|
-
httpGroupMeta: Record<string, {
|
|
89
|
-
exportName: string | null;
|
|
90
|
-
sourceFile: string;
|
|
91
|
-
position: number;
|
|
92
|
-
services: FunctionServicesMeta;
|
|
93
|
-
permissionCount: number;
|
|
94
|
-
isFactory: boolean;
|
|
95
|
-
}>;
|
|
96
|
-
};
|
|
97
|
-
misc: {
|
|
98
|
-
errors: Map<PikkuError, ErrorDetails>;
|
|
99
|
-
schemas: Map<string, any>;
|
|
100
|
-
middleware: Record<string, CorePikkuMiddleware[]>;
|
|
101
|
-
permissions: Record<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
102
|
-
};
|
|
1
|
+
import { PikkuPackageState } from './index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
var pikkuState: Map<string, PikkuPackageState> | undefined;
|
|
103
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Get or set package-scoped pikku state
|
|
7
|
+
*
|
|
8
|
+
* @param packageName - Package name (null for main package, '@scope/package' for external packages)
|
|
9
|
+
* @param type - State category (function, rpc, http, etc.)
|
|
10
|
+
* @param content - Content key within the category
|
|
11
|
+
* @param value - Optional value to set
|
|
12
|
+
* @returns The current value of the state
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Main package
|
|
16
|
+
* pikkuState(null, 'function', 'functions').get(funcName)
|
|
17
|
+
*
|
|
18
|
+
* // External package
|
|
19
|
+
* pikkuState('@acme/stripe-functions', 'rpc', 'meta')
|
|
20
|
+
*/
|
|
21
|
+
export declare const pikkuState: <Type extends keyof PikkuPackageState, Content extends keyof PikkuPackageState[Type]>(packageName: string | null, type: Type, content: Content, value?: PikkuPackageState[Type][Content]) => PikkuPackageState[Type][Content];
|
|
22
|
+
/**
|
|
23
|
+
* Initialize state for a new package
|
|
24
|
+
*/
|
|
25
|
+
export declare const initializePikkuState: (packageName: string) => void;
|
|
104
26
|
export declare const resetPikkuState: () => void;
|
|
105
|
-
export declare const
|
|
106
|
-
|
|
27
|
+
export declare const getPikkuMetaDir: (packageName?: string | null) => string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Register service factories for an external package.
|
|
30
|
+
* These factories are used to create services when the package's functions are invoked.
|
|
31
|
+
*
|
|
32
|
+
* @param packageName - The package name (e.g., '@pikku/templates-function-external')
|
|
33
|
+
* @param factories - The service factory functions
|
|
34
|
+
*/
|
|
35
|
+
export declare const addPackageServiceFactories: (packageName: string, factories: NonNullable<PikkuPackageState["package"]["factories"]>) => void;
|
package/dist/pikku-state.js
CHANGED
|
@@ -1,72 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
httpGroup: {},
|
|
53
|
-
tagGroupMeta: {},
|
|
54
|
-
httpGroupMeta: {},
|
|
55
|
-
},
|
|
56
|
-
misc: {
|
|
57
|
-
errors: globalThis.pikkuState?.misc?.errors || new Map(),
|
|
58
|
-
schemas: new Map(),
|
|
59
|
-
middleware: {},
|
|
60
|
-
permissions: {},
|
|
1
|
+
/**
|
|
2
|
+
* Get or set package-scoped pikku state
|
|
3
|
+
*
|
|
4
|
+
* @param packageName - Package name (null for main package, '@scope/package' for external packages)
|
|
5
|
+
* @param type - State category (function, rpc, http, etc.)
|
|
6
|
+
* @param content - Content key within the category
|
|
7
|
+
* @param value - Optional value to set
|
|
8
|
+
* @returns The current value of the state
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Main package
|
|
12
|
+
* pikkuState(null, 'function', 'functions').get(funcName)
|
|
13
|
+
*
|
|
14
|
+
* // External package
|
|
15
|
+
* pikkuState('@acme/stripe-functions', 'rpc', 'meta')
|
|
16
|
+
*/
|
|
17
|
+
export const pikkuState = (packageName, type, content, value) => {
|
|
18
|
+
const resolvedPackageName = packageName ?? '__main__';
|
|
19
|
+
// Initialize package state if it doesn't exist
|
|
20
|
+
if (!globalThis.pikkuState ||
|
|
21
|
+
!globalThis.pikkuState.has(resolvedPackageName)) {
|
|
22
|
+
initializePikkuState(resolvedPackageName);
|
|
23
|
+
}
|
|
24
|
+
const packageState = globalThis.pikkuState.get(resolvedPackageName);
|
|
25
|
+
if (value !== undefined) {
|
|
26
|
+
packageState[type][content] = value;
|
|
27
|
+
}
|
|
28
|
+
return packageState[type][content];
|
|
29
|
+
};
|
|
30
|
+
const createEmptyPackageState = () => ({
|
|
31
|
+
function: {
|
|
32
|
+
meta: {},
|
|
33
|
+
functions: new Map(),
|
|
34
|
+
},
|
|
35
|
+
rpc: {
|
|
36
|
+
meta: {},
|
|
37
|
+
files: new Map(),
|
|
38
|
+
externalPackages: new Map(),
|
|
39
|
+
},
|
|
40
|
+
http: {
|
|
41
|
+
middleware: new Map(),
|
|
42
|
+
permissions: new Map(),
|
|
43
|
+
routes: new Map(),
|
|
44
|
+
meta: {
|
|
45
|
+
post: {},
|
|
46
|
+
get: {},
|
|
47
|
+
delete: {},
|
|
48
|
+
patch: {},
|
|
49
|
+
head: {},
|
|
50
|
+
put: {},
|
|
51
|
+
options: {},
|
|
61
52
|
},
|
|
62
|
-
}
|
|
53
|
+
},
|
|
54
|
+
channel: {
|
|
55
|
+
channels: new Map(),
|
|
56
|
+
meta: {},
|
|
57
|
+
},
|
|
58
|
+
scheduler: {
|
|
59
|
+
tasks: new Map(),
|
|
60
|
+
meta: [],
|
|
61
|
+
},
|
|
62
|
+
queue: {
|
|
63
|
+
registrations: new Map(),
|
|
64
|
+
meta: {},
|
|
65
|
+
},
|
|
66
|
+
workflows: {
|
|
67
|
+
registrations: new Map(),
|
|
68
|
+
meta: {},
|
|
69
|
+
},
|
|
70
|
+
trigger: {
|
|
71
|
+
functions: new Map(),
|
|
72
|
+
triggers: new Map(),
|
|
73
|
+
triggerSources: new Map(),
|
|
74
|
+
meta: {},
|
|
75
|
+
sourceMeta: {},
|
|
76
|
+
},
|
|
77
|
+
mcp: {
|
|
78
|
+
resources: new Map(),
|
|
79
|
+
resourcesMeta: {},
|
|
80
|
+
toolsMeta: {},
|
|
81
|
+
prompts: new Map(),
|
|
82
|
+
promptsMeta: {},
|
|
83
|
+
},
|
|
84
|
+
agent: {
|
|
85
|
+
agents: new Map(),
|
|
86
|
+
agentsMeta: {},
|
|
87
|
+
},
|
|
88
|
+
cli: {
|
|
89
|
+
meta: { programs: {}, renderers: {} },
|
|
90
|
+
programs: {},
|
|
91
|
+
},
|
|
92
|
+
middleware: {
|
|
93
|
+
tagGroup: {},
|
|
94
|
+
httpGroup: {},
|
|
95
|
+
},
|
|
96
|
+
channelMiddleware: {
|
|
97
|
+
tagGroup: {},
|
|
98
|
+
},
|
|
99
|
+
permissions: {
|
|
100
|
+
tagGroup: {},
|
|
101
|
+
httpGroup: {},
|
|
102
|
+
},
|
|
103
|
+
misc: {
|
|
104
|
+
errors: new Map(),
|
|
105
|
+
schemas: new Map(),
|
|
106
|
+
middleware: {},
|
|
107
|
+
channelMiddleware: {},
|
|
108
|
+
permissions: {},
|
|
109
|
+
},
|
|
110
|
+
models: {
|
|
111
|
+
config: null,
|
|
112
|
+
},
|
|
113
|
+
package: {
|
|
114
|
+
factories: null,
|
|
115
|
+
singletonServices: null,
|
|
116
|
+
metaDir: null,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Initialize state for a new package
|
|
121
|
+
*/
|
|
122
|
+
export const initializePikkuState = (packageName) => {
|
|
123
|
+
if (!globalThis.pikkuState) {
|
|
124
|
+
globalThis.pikkuState = new Map();
|
|
125
|
+
}
|
|
126
|
+
if (!globalThis.pikkuState.has(packageName)) {
|
|
127
|
+
globalThis.pikkuState.set(packageName, createEmptyPackageState());
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export const resetPikkuState = () => {
|
|
131
|
+
// Preserve the errors map before resetting
|
|
132
|
+
const existingErrors = globalThis.pikkuState?.get('__main__')?.misc.errors;
|
|
133
|
+
globalThis.pikkuState = new Map();
|
|
134
|
+
initializePikkuState('__main__');
|
|
135
|
+
// Restore the errors map if it existed
|
|
136
|
+
if (existingErrors) {
|
|
137
|
+
const mainState = globalThis.pikkuState.get('__main__');
|
|
138
|
+
mainState.misc.errors = existingErrors;
|
|
139
|
+
}
|
|
63
140
|
};
|
|
64
141
|
if (!globalThis.pikkuState) {
|
|
65
142
|
resetPikkuState();
|
|
66
143
|
}
|
|
67
|
-
export const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
144
|
+
export const getPikkuMetaDir = (packageName) => {
|
|
145
|
+
return pikkuState(packageName ?? null, 'package', 'metaDir');
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Register service factories for an external package.
|
|
149
|
+
* These factories are used to create services when the package's functions are invoked.
|
|
150
|
+
*
|
|
151
|
+
* @param packageName - The package name (e.g., '@pikku/templates-function-external')
|
|
152
|
+
* @param factories - The service factory functions
|
|
153
|
+
*/
|
|
154
|
+
export const addPackageServiceFactories = (packageName, factories) => {
|
|
155
|
+
pikkuState(packageName, 'package', 'factories', factories);
|
|
72
156
|
};
|