@processfocus/plugin-aws-lambda 0.1.0-next.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/LICENSE.md ADDED
@@ -0,0 +1,28 @@
1
+ # O'Saasy License Agreement
2
+
3
+ Copyright © 2026, Xplain Technology Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ 1. The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+ 2. No licensee or downstream recipient may use the Software (including
16
+ any modified or derivative versions) to directly compete with the
17
+ original Licensor by offering it to third parties as a hosted,
18
+ managed, or Software-as-a-Service (SaaS) product or cloud service
19
+ where the primary value of the service is the functionality of the
20
+ Software itself.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @processfocus/plugin-aws-lambda
2
+
3
+ Official Process Focus plugin for invoking AWS Lambda functions from a
4
+ `SystemStep`.
5
+
6
+ ```ts
7
+ import { AwsFunctionStep } from "@processfocus/plugin-aws-lambda"
8
+ ```
9
+
10
+ The package root is authoring-safe. It contains no private AWS runtime stacks,
11
+ account configuration, or operator tooling.
12
+
13
+ ## Build
14
+
15
+ Run `bun scripts/nx-quiet.ts run @processfocus/plugin-aws-lambda:build` from the
16
+ workspace root.
17
+
18
+ ## Test
19
+
20
+ Run `bun scripts/nx-quiet.ts run @processfocus/plugin-aws-lambda:test` from the
21
+ workspace root.
@@ -0,0 +1 @@
1
+ export * from "./lib/aws-function-step.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./lib/aws-function-step.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { type FlowPath, type FormStepMeta, type IStepScope, type InferSchemaType, type Process, type StepMeta, SystemStep, type SystemStepProps } from "processfocus";
3
+ /**
4
+ * Props for AwsFunctionStep - invokes an AWS Lambda function.
5
+ *
6
+ * @typeParam TState - Accumulated state from previous steps
7
+ * @typeParam TSteps - Record of completed step metadata for ctx.step access
8
+ * @typeParam TInput - Input derived from state (must be JSON-serializable)
9
+ * @typeParam TOutput - Output schema fields merged into process state
10
+ * @typeParam TIsForEach - Whether this step uses forEach semantics
11
+ */
12
+ export type AwsFunctionStepProps<TState = Record<string, never>, TSteps extends Record<string, StepMeta | FormStepMeta> = Record<string, never>, TInput = unknown, TOutput extends Schema.Struct.Fields = Schema.Struct.Fields, TIsForEach extends boolean = false> = SystemStepProps<TState, TSteps, TInput, TOutput, TIsForEach> & {
13
+ /**
14
+ * Name of the AWS Lambda function to invoke.
15
+ * Can be a function name or a full ARN.
16
+ */
17
+ readonly functionName: string;
18
+ };
19
+ /**
20
+ * AwsFunctionStep invokes an AWS Lambda function during step execution.
21
+ *
22
+ * The input is JSON-serialized and passed to the Lambda function.
23
+ * The Lambda response is parsed and returned as the step output.
24
+ *
25
+ * @typeParam TState - Accumulated state from previous steps
26
+ * @typeParam TSteps - Record of completed step metadata for ctx.step access
27
+ * @typeParam TInput - Input derived from state (must be JSON-serializable)
28
+ * @typeParam TOutput - Output schema fields merged into process state
29
+ * @typeParam TId - Step identifier literal type
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const addNumbers = new AwsFunctionStep(register, "AddNumbers", {
34
+ * functionName: "demo-add-numbers",
35
+ * input: (state) => Effect.succeed({ a: state.x, b: state.y }),
36
+ * output: { result: Schema.Number },
37
+ * })
38
+ * ```
39
+ */
40
+ export declare class AwsFunctionStep<TState = Record<string, never>, TSteps extends Record<string, StepMeta | FormStepMeta> = Record<string, never>, TInput = unknown, TOutput extends Schema.Struct.Fields = Schema.Struct.Fields, TId extends string = string, TIsForEach extends boolean = false> extends SystemStep<TState, TSteps, TInput, TOutput, TId, TIsForEach> {
41
+ /**
42
+ * Name of the AWS Lambda function to invoke.
43
+ * Exposed for CDK to discover and grant permissions.
44
+ */
45
+ readonly functionName: string;
46
+ constructor(scope: Process | IStepScope<TState, TSteps> | FlowPath<TState, Schema.Struct.Fields | undefined, TSteps>, id: TId, props: AwsFunctionStepProps<TState, TSteps, TInput, TOutput, any>);
47
+ /**
48
+ * Execute the Lambda function with the derived input.
49
+ *
50
+ * The input is JSON-serialized and sent to the Lambda function.
51
+ * The Lambda's response payload is parsed as JSON and returned.
52
+ *
53
+ * Error handling:
54
+ * - SDK errors are wrapped in Effect.fail
55
+ * - Lambda execution errors (FunctionError field) are detected and failed
56
+ */
57
+ execute(input: TInput): Effect.Effect<InferSchemaType<TOutput>, AwsFunctionError, unknown>;
58
+ }
59
+ declare const AwsFunctionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
60
+ readonly _tag: "AwsFunctionError";
61
+ } & Readonly<A>;
62
+ /**
63
+ * Error thrown when AWS Lambda function invocation fails.
64
+ */
65
+ export declare class AwsFunctionError extends AwsFunctionError_base<{
66
+ readonly message: string;
67
+ readonly cause?: unknown;
68
+ }> {
69
+ }
70
+ export {};
@@ -0,0 +1,111 @@
1
+ import { InvokeCommand, LambdaClient } from "@aws-sdk/client-lambda";
2
+ import { Data, Effect, Schema } from "effect";
3
+ import { SystemStep, } from "processfocus";
4
+ // Lazily cached Lambda client at module level
5
+ let lambdaClient;
6
+ const JsonValue = Schema.parseJson(Schema.Unknown);
7
+ function getLambdaClient() {
8
+ if (!lambdaClient) {
9
+ lambdaClient = new LambdaClient({});
10
+ }
11
+ return lambdaClient;
12
+ }
13
+ /**
14
+ * AwsFunctionStep invokes an AWS Lambda function during step execution.
15
+ *
16
+ * The input is JSON-serialized and passed to the Lambda function.
17
+ * The Lambda response is parsed and returned as the step output.
18
+ *
19
+ * @typeParam TState - Accumulated state from previous steps
20
+ * @typeParam TSteps - Record of completed step metadata for ctx.step access
21
+ * @typeParam TInput - Input derived from state (must be JSON-serializable)
22
+ * @typeParam TOutput - Output schema fields merged into process state
23
+ * @typeParam TId - Step identifier literal type
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const addNumbers = new AwsFunctionStep(register, "AddNumbers", {
28
+ * functionName: "demo-add-numbers",
29
+ * input: (state) => Effect.succeed({ a: state.x, b: state.y }),
30
+ * output: { result: Schema.Number },
31
+ * })
32
+ * ```
33
+ */
34
+ export class AwsFunctionStep extends SystemStep {
35
+ /**
36
+ * Name of the AWS Lambda function to invoke.
37
+ * Exposed for CDK to discover and grant permissions.
38
+ */
39
+ functionName;
40
+ constructor(scope, id,
41
+ // biome-ignore lint/suspicious/noExplicitAny: Discriminated union requires relaxed typing in constructor
42
+ props) {
43
+ super(scope, id, props);
44
+ this.functionName = props.functionName;
45
+ }
46
+ /**
47
+ * Execute the Lambda function with the derived input.
48
+ *
49
+ * The input is JSON-serialized and sent to the Lambda function.
50
+ * The Lambda's response payload is parsed as JSON and returned.
51
+ *
52
+ * Error handling:
53
+ * - SDK errors are wrapped in Effect.fail
54
+ * - Lambda execution errors (FunctionError field) are detected and failed
55
+ */
56
+ execute(input) {
57
+ return Effect.gen(this, function* () {
58
+ const client = getLambdaClient();
59
+ const payloadJson = yield* Schema.encode(JsonValue)(input).pipe(Effect.mapError((cause) => new AwsFunctionError({
60
+ message: `Failed to encode Lambda payload for "${this.functionName}"`,
61
+ cause,
62
+ })));
63
+ const payload = new TextEncoder().encode(payloadJson);
64
+ yield* Effect.log(`Invoking Lambda function: ${this.functionName}`, {
65
+ input: payloadJson,
66
+ });
67
+ const command = new InvokeCommand({
68
+ FunctionName: this.functionName,
69
+ Payload: payload,
70
+ });
71
+ const response = yield* Effect.tryPromise({
72
+ try: () => client.send(command),
73
+ catch: (error) => new AwsFunctionError({
74
+ message: `Failed to invoke Lambda function "${this.functionName}": ${error instanceof Error ? error.message : String(error)}`,
75
+ cause: error,
76
+ }),
77
+ });
78
+ // Check for Lambda execution errors (e.g., function threw an exception)
79
+ if (response.FunctionError) {
80
+ const errorPayload = response.Payload
81
+ ? new TextDecoder().decode(response.Payload)
82
+ : "Unknown error";
83
+ return yield* new AwsFunctionError({
84
+ message: `Lambda function "${this.functionName}" returned an error: ${errorPayload}`,
85
+ });
86
+ }
87
+ // Parse the response payload as JSON
88
+ if (!response.Payload || response.Payload.length === 0) {
89
+ return yield* new AwsFunctionError({
90
+ message: `Lambda function "${this.functionName}" returned empty response`,
91
+ });
92
+ }
93
+ const responseText = new TextDecoder().decode(response.Payload);
94
+ yield* Effect.log(`Lambda function ${this.functionName} returned response`, {
95
+ responseLength: responseText.length,
96
+ });
97
+ const result = yield* Schema.decodeUnknown(JsonValue)(responseText).pipe(Effect.map((value) => value), Effect.mapError((error) => new AwsFunctionError({
98
+ message: `Failed to parse Lambda response from "${this.functionName}": ${String(error)}. Response: ${responseText.slice(0, 200)}`,
99
+ cause: error,
100
+ })));
101
+ yield* Effect.log(`Lambda function ${this.functionName} completed successfully`);
102
+ return result;
103
+ });
104
+ }
105
+ }
106
+ /**
107
+ * Error thrown when AWS Lambda function invocation fails.
108
+ */
109
+ export class AwsFunctionError extends Data.TaggedError("AwsFunctionError") {
110
+ }
111
+ //# sourceMappingURL=aws-function-step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-function-step.js","sourceRoot":"","sources":["../../src/lib/aws-function-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAOL,UAAU,GAEX,MAAM,aAAa,CAAA;AA4BpB,8CAA8C;AAC9C,IAAI,YAAsC,CAAA;AAE1C,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAElD,SAAS,eAAe;IACtB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,YAAY,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,eAUX,SAAQ,UAA4D;IACpE;;;OAGG;IACM,YAAY,CAAQ;IAE7B,YACE,KAG8D,EAC9D,EAAO;IACP,yGAAyG;IACzG,KAAiE;QAEjE,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,CAAA;QACvB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAA;IACxC,CAAC;IAED;;;;;;;;;OASG;IACH,OAAO,CACL,KAAa;QAEb,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;YAC/B,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;YAEhC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,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;CAAG"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@processfocus/plugin-aws-lambda",
3
+ "version": "0.1.0-next.0",
4
+ "type": "module",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/processfocus/processfocus.git",
9
+ "directory": "plugins/aws"
10
+ },
11
+ "main": "./dist/index.js",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ "./package.json": "./package.json",
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE.md",
26
+ "!**/*.tsbuildinfo"
27
+ ],
28
+ "dependencies": {
29
+ "@aws-sdk/client-lambda": "^3.1131.0",
30
+ "effect": "^3.22.2"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "tag": "next"
35
+ },
36
+ "peerDependencies": {
37
+ "processfocus": "0.1.0-next.0"
38
+ }
39
+ }