@jettacargo/activity-handler 1.0.0-alpha.2 → 1.0.0-alpha.20
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/README.md +79 -0
- package/build/constants/Constants.d.ts +2 -0
- package/build/constants/Constants.js +3 -0
- package/build/constants/Constants.js.map +1 -0
- package/build/error/Fatal.d.ts +3 -0
- package/build/error/Fatal.js +7 -0
- package/build/error/Fatal.js.map +1 -0
- package/build/error/HandleWorkflowErrorSignal.d.ts +1 -0
- package/build/error/HandleWorkflowErrorSignal.js +19 -0
- package/build/error/HandleWorkflowErrorSignal.js.map +1 -0
- package/build/error/Temporary.d.ts +3 -0
- package/build/error/Temporary.js +7 -0
- package/build/error/Temporary.js.map +1 -0
- package/build/exceptions/ErrorTypeMismatch.d.ts +4 -0
- package/build/exceptions/ErrorTypeMismatch.js +7 -0
- package/build/exceptions/ErrorTypeMismatch.js.map +1 -0
- package/build/exceptions/FailedRetrievingFileFromS3Exception.d.ts +4 -0
- package/build/exceptions/FailedRetrievingFileFromS3Exception.js +7 -0
- package/build/exceptions/FailedRetrievingFileFromS3Exception.js.map +1 -0
- package/build/handler/ActivityHandler.d.ts +11 -0
- package/build/handler/ActivityHandler.js +43 -0
- package/build/handler/ActivityHandler.js.map +1 -0
- package/build/handler/InputReader.d.ts +9 -0
- package/build/handler/InputReader.js +39 -0
- package/build/handler/InputReader.js.map +1 -0
- package/build/handler/OutputWriter.d.ts +8 -0
- package/build/handler/OutputWriter.js +16 -0
- package/build/handler/OutputWriter.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/package.json +33 -20
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @jettacargo/activity-handler
|
|
2
|
+
|
|
3
|
+
A standardized, resilient Temporal activity handler for the Jetta Cargo ecosystem.
|
|
4
|
+
|
|
5
|
+
This package provides a robust abstraction to handle Temporal activities by automatically managing input retrieval from AWS S3, executing a custom business logic callback, logging with consistent contextual cargo information, and securely saving the resulting output back to S3.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Automated S3 I/O**: Seamlessly reads inputs and writes outputs via S3 URIs, abstracting away the boilerplate of object storage management.
|
|
10
|
+
- **Resilient Error Handling**: Automatically categorizes exceptions into Temporal's `ApplicationFailure` (Retryable vs. Non-Retryable) based on whether they are expected `TemporaryError` or `FatalError` variants.
|
|
11
|
+
- **Contextual Logging**: Automatically injects standard Cargo information (Company and Cargo ID) into your application logs using `@jetta/logger`.
|
|
12
|
+
- **Strict Typing**: Built with TypeScript, ensuring full type-safety for event metadata, callback signatures, and payload interfaces.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @jettacargo/activity-handler
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
The core entry point of this library is the `handle_activity` function. It takes event metadata containing an S3 input URI, a source identifier, and your business logic callback.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import handle_activity from '@jettacargo/activity-handler';
|
|
26
|
+
import { ActivityCallback, CommonInput, EventMetadata } from '@jettacargo/load-models';
|
|
27
|
+
|
|
28
|
+
// 1. Define your business logic callback
|
|
29
|
+
const my_activity_callback: ActivityCallback = async (input: CommonInput) => {
|
|
30
|
+
// Input data has already been retrieved and parsed from S3
|
|
31
|
+
console.log(`Processing cargo ${input.cargo_info.cargo_id}`);
|
|
32
|
+
|
|
33
|
+
// Perform your core activity logic here...
|
|
34
|
+
const result = { success: true, processed_items: 42 };
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// 2. Export the temporal activity wrapper
|
|
40
|
+
export async function my_temporal_activity(event_metadata: EventMetadata): Promise<EventMetadata> {
|
|
41
|
+
const source = 'MY_SERVICE_NAME';
|
|
42
|
+
|
|
43
|
+
// handle_activity will take care of reading the input, running the callback,
|
|
44
|
+
// handling potential Temporal retries, and writing the final output to S3.
|
|
45
|
+
return await handle_activity(event_metadata, source, my_activity_callback);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Architecture Flow
|
|
50
|
+
|
|
51
|
+
1. **Input Stage (`InputReader`)**: Retrieves the S3 URI provided in the `EventMetadata`, downloads the JSON payload from the bucket, and parses it into a strongly typed `CommonInput`.
|
|
52
|
+
2. **Execution Stage (`handle_activity`)**: The `ActivityCallback` is invoked with the parsed input. The logger is configured using the cargo information context.
|
|
53
|
+
3. **Output Stage (`OutputWriter`)**: The result of the callback is stringified and uploaded to the default S3 bucket. A new S3 URI is generated.
|
|
54
|
+
4. **Response Stage**: A new `EventMetadata` object is constructed, encapsulating the generated S3 Output URI and the status (`SUCCESS` or `FAILURE`).
|
|
55
|
+
|
|
56
|
+
## Error Handling
|
|
57
|
+
|
|
58
|
+
If your callback throws an error, the handler will catch it and properly signal Temporal by translating it into an `ApplicationFailure`. By extending `FatalError` (for unrecoverable errors like `ErrorTypeMismatch`) or `TemporaryError` (for transient network failures), you control whether Temporal should trigger a retry or fail the workflow immediately.
|
|
59
|
+
|
|
60
|
+
## Development Commands
|
|
61
|
+
|
|
62
|
+
This project strictly adheres to `snake_case` conventions and minimal function structures as defined in `GEMINI.md`.
|
|
63
|
+
|
|
64
|
+
* **Build**: Compiles the TypeScript source into the `build/` directory.
|
|
65
|
+
```bash
|
|
66
|
+
npm run build
|
|
67
|
+
```
|
|
68
|
+
* **Test**: Executes the Mocha test suite validating handler pathways.
|
|
69
|
+
```bash
|
|
70
|
+
npm run test
|
|
71
|
+
```
|
|
72
|
+
* **Lint**: Runs ESLint to verify codebase standards.
|
|
73
|
+
```bash
|
|
74
|
+
npm run lint
|
|
75
|
+
```
|
|
76
|
+
* **Lint Fix**: Automatically fixes code formatting style errors.
|
|
77
|
+
```bash
|
|
78
|
+
npm run lint:fix
|
|
79
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/constants/Constants.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,WAAW,CAAA;AAElC,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Fatal.js","sourceRoot":"","sources":["../../src/error/Fatal.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAEjC,YAAY,OAAe;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;IAC5B,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handle_workflow_error_signal(err: Error): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ApplicationFailure } from '@temporalio/workflow';
|
|
2
|
+
import { FatalError } from './Fatal.js';
|
|
3
|
+
import { TemporaryError } from './Temporary.js';
|
|
4
|
+
function check_non_retryable(err, target_type, label) {
|
|
5
|
+
if (err instanceof target_type) {
|
|
6
|
+
throw ApplicationFailure.nonRetryable(err.message, label, undefined, err);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function check_retryable(err, target_type, label) {
|
|
10
|
+
if (err instanceof target_type) {
|
|
11
|
+
throw ApplicationFailure.retryable(err.message, label, undefined, err);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function handle_workflow_error_signal(err) {
|
|
15
|
+
check_non_retryable(err, FatalError, 'FatalError');
|
|
16
|
+
check_retryable(err, TemporaryError, 'TemporaryError');
|
|
17
|
+
check_non_retryable(err, Error, 'UnknownError');
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=HandleWorkflowErrorSignal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandleWorkflowErrorSignal.js","sourceRoot":"","sources":["../../src/error/HandleWorkflowErrorSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,SAAS,mBAAmB,CAAC,GAAO,EAAE,WAAe,EAAE,KAAY;IAE/D,IAAI,GAAG,YAAY,WAAW,EAC9B,CAAC;QACG,MAAM,kBAAkB,CAAC,YAAY,CACjC,GAAG,CAAC,OAAO,EACX,KAAK,EACL,SAAS,EACT,GAAG,CACN,CAAA;IACL,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAC,GAAO,EAAE,WAAe,EAAE,KAAY;IAE3D,IAAI,GAAG,YAAY,WAAW,EAC9B,CAAC;QACG,MAAM,kBAAkB,CAAC,SAAS,CAC9B,GAAG,CAAC,OAAO,EACX,KAAK,EACL,SAAS,EACT,GAAG,CACN,CAAA;IACL,CAAC;AACL,CAAC;AACD,MAAM,UAAU,4BAA4B,CAAC,GAAW;IAEpD,mBAAmB,CAAC,GAAG,EAAE,UAAU,EAAE,YAAY,CAAC,CAAA;IAClD,eAAe,CAAC,GAAG,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAA;IACtD,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,cAAc,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Temporary.js","sourceRoot":"","sources":["../../src/error/Temporary.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAErC,YAAY,OAAe;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAChC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorTypeMismatch.js","sourceRoot":"","sources":["../../src/exceptions/ErrorTypeMismatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU;IAErD;QAEI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IACpD,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FailedRetrievingFileFromS3Exception.js","sourceRoot":"","sources":["../../src/exceptions/FailedRetrievingFileFromS3Exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,CAAC,OAAO,OAAO,mCAAoC,SAAQ,UAAU;IAEvE,YAAY,OAAe;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ActivityCallback, EventMetadata } from '@jettacargo/load-models';
|
|
2
|
+
/**
|
|
3
|
+
* Handles an incoming activity by reading its input, executing the provided callback,
|
|
4
|
+
* writing the output, and building the final workflow response.
|
|
5
|
+
*
|
|
6
|
+
* @param {EventMetadata} event_metadata The metadata of the incoming event containing the input data reference.
|
|
7
|
+
* @param {string} source The source identifier for the activity.
|
|
8
|
+
* @param {ActivityCallback} callback The callback function to execute with the read input data.
|
|
9
|
+
* @returns {Promise<EventMetadata>} A promise that resolves to the metadata of the resulting event.
|
|
10
|
+
*/
|
|
11
|
+
export default function handle_activity(event_metadata: EventMetadata, source: string, callback: ActivityCallback): Promise<EventMetadata>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EventStatus } from '@jettacargo/load-models';
|
|
2
|
+
import read_input from './InputReader.js';
|
|
3
|
+
import write_output from './OutputWriter.js';
|
|
4
|
+
import ErrorTypeMismatch from '../exceptions/ErrorTypeMismatch.js';
|
|
5
|
+
import { handle_workflow_error_signal } from '../error/HandleWorkflowErrorSignal.js';
|
|
6
|
+
import { Logger } from '@jetta/logger';
|
|
7
|
+
/**
|
|
8
|
+
* Handles an incoming activity by reading its input, executing the provided callback,
|
|
9
|
+
* writing the output, and building the final workflow response.
|
|
10
|
+
*
|
|
11
|
+
* @param {EventMetadata} event_metadata The metadata of the incoming event containing the input data reference.
|
|
12
|
+
* @param {string} source The source identifier for the activity.
|
|
13
|
+
* @param {ActivityCallback} callback The callback function to execute with the read input data.
|
|
14
|
+
* @returns {Promise<EventMetadata>} A promise that resolves to the metadata of the resulting event.
|
|
15
|
+
*/
|
|
16
|
+
export default async function handle_activity(event_metadata, source, callback) {
|
|
17
|
+
try {
|
|
18
|
+
const input_data = await read_input(event_metadata.data);
|
|
19
|
+
const output = await Logger.run_with_cargo_info(input_data.cargo_info.company, input_data.cargo_info.cargo_id, async () => await callback(input_data));
|
|
20
|
+
const uri = await write_output(output.data);
|
|
21
|
+
return build_workflow_response(output.status, uri, source);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err instanceof Error) {
|
|
25
|
+
return await handle_error(err, source);
|
|
26
|
+
}
|
|
27
|
+
throw new ErrorTypeMismatch();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function handle_error(err, source) {
|
|
31
|
+
handle_workflow_error_signal(err);
|
|
32
|
+
const error_data = { message: err.message, stack: err.stack };
|
|
33
|
+
const output = {
|
|
34
|
+
status: EventStatus.FAILURE,
|
|
35
|
+
data: JSON.stringify(error_data)
|
|
36
|
+
};
|
|
37
|
+
const uri = await write_output(output);
|
|
38
|
+
return build_workflow_response(EventStatus.FAILURE, uri, source);
|
|
39
|
+
}
|
|
40
|
+
function build_workflow_response(status, uri, source) {
|
|
41
|
+
return { type: status, data: uri, source: source };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=ActivityHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivityHandler.js","sourceRoot":"","sources":["../../src/handler/ActivityHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,WAAW,EAEd,MAAM,yBAAyB,CAAA;AAChC,OAAO,UAAU,MAAM,kBAAkB,CAAA;AACzC,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAC5C,OAAO,iBAAiB,MAAM,oCAAoC,CAAA;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAA;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,eAAe,CACzC,cAA6B,EAAE,MAAc,EAAE,QAA0B;IAGzE,IACA,CAAC;QACG,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QACxD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAC3C,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,EAC7D,KAAK,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,CACzB,CAAA;QACjB,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAW,CAAC,CAAA;QAClD,OAAO,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,GAAG,EACV,CAAC;QACG,IAAI,GAAG,YAAY,KAAK,EACxB,CAAC;YACG,OAAO,MAAM,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC1C,CAAC;QACD,MAAM,IAAI,iBAAiB,EAAE,CAAA;IACjC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,GAAU,EAAE,MAAc;IAElD,4BAA4B,CAAC,GAAG,CAAC,CAAA;IACjC,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAA;IAC7D,MAAM,MAAM,GAAiB;QACzB,MAAM,EAAE,WAAW,CAAC,OAAO;QAC3B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;KACnC,CAAA;IACD,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAA;IACtC,OAAO,uBAAuB,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AACpE,CAAC;AAED,SAAS,uBAAuB,CAAC,MAAmB,EAAE,GAAuB,EAAE,MAAc;IAEzF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonInput } from '@jettacargo/load-models';
|
|
2
|
+
/**
|
|
3
|
+
* Reads and parses the input data from a specified S3 URI.
|
|
4
|
+
*
|
|
5
|
+
* @param {string | undefined} uri The S3 URI (e.g., s3://bucket/key) indicating where the input data is stored.
|
|
6
|
+
* @returns {Promise<CommonInput>} A promise that resolves to the parsed CommonInput data.
|
|
7
|
+
* @throws {FailedRetrievingFileFromS3Exception} Thrown if the URI is undefined, invalid, S3 retrieval fails, or the data is not valid JSON.
|
|
8
|
+
*/
|
|
9
|
+
export default function read_input(uri: string | undefined): Promise<CommonInput>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Object_Store_Driver } from '@jettacargo/s3';
|
|
2
|
+
import FailedRetrievingFileFromS3Exception from '../exceptions/FailedRetrievingFileFromS3Exception.js';
|
|
3
|
+
function split_uri(uri) {
|
|
4
|
+
const splitted = uri.match(/^s3:\/\/([^\/]+)\/(.+)$/);
|
|
5
|
+
if (!splitted || splitted.length < 3) {
|
|
6
|
+
throw new FailedRetrievingFileFromS3Exception('S3 URI invalid.');
|
|
7
|
+
}
|
|
8
|
+
const bucket = splitted[1];
|
|
9
|
+
const key = splitted[2];
|
|
10
|
+
return { bucket, key };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads and parses the input data from a specified S3 URI.
|
|
14
|
+
*
|
|
15
|
+
* @param {string | undefined} uri The S3 URI (e.g., s3://bucket/key) indicating where the input data is stored.
|
|
16
|
+
* @returns {Promise<CommonInput>} A promise that resolves to the parsed CommonInput data.
|
|
17
|
+
* @throws {FailedRetrievingFileFromS3Exception} Thrown if the URI is undefined, invalid, S3 retrieval fails, or the data is not valid JSON.
|
|
18
|
+
*/
|
|
19
|
+
export default async function read_input(uri) {
|
|
20
|
+
if (uri === undefined) {
|
|
21
|
+
const message = `Failed retrieving data from s3 at address: ${uri}`;
|
|
22
|
+
throw new FailedRetrievingFileFromS3Exception(message);
|
|
23
|
+
}
|
|
24
|
+
const { bucket, key } = split_uri(uri);
|
|
25
|
+
const raw_input = await Object_Store_Driver.get_object(bucket, key);
|
|
26
|
+
if (raw_input === undefined) {
|
|
27
|
+
const message = `Failed when retrieving data from s3: no data returned.`;
|
|
28
|
+
throw new FailedRetrievingFileFromS3Exception(message);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const input_data = JSON.parse(raw_input);
|
|
32
|
+
return input_data;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
const message = `JSON retrieved from s3 is in invalid format.`;
|
|
36
|
+
throw new FailedRetrievingFileFromS3Exception(message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=InputReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputReader.js","sourceRoot":"","sources":["../../src/handler/InputReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,mCAAmC,MAAM,sDAAsD,CAAA;AAGtG,SAAS,SAAS,CAAC,GAAY;IAE3B,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;IACrD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EACpC,CAAC;QACG,MAAM,IAAI,mCAAmC,CAAC,iBAAiB,CAAC,CAAA;IACpE,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC1B,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACvB,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAA;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,UAAU,CAAC,GAAuB;IAE5D,IAAI,GAAG,KAAK,SAAS,EACrB,CAAC;QACG,MAAM,OAAO,GAAG,8CAA8C,GAAG,EAAE,CAAA;QACnE,MAAM,IAAI,mCAAmC,CAAC,OAAO,CAAC,CAAA;IAC1D,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;IACtC,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEnE,IAAI,SAAS,KAAK,SAAS,EAC3B,CAAC;QACG,MAAM,OAAO,GAAG,wDAAwD,CAAA;QACxE,MAAM,IAAI,mCAAmC,CAAC,OAAO,CAAC,CAAA;IAC1D,CAAC;IAED,IACA,CAAC;QACG,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAgB,CAAA;QACvD,OAAO,UAAU,CAAA;IACrB,CAAC;IACD,MACA,CAAC;QACG,MAAM,OAAO,GAAG,8CAA8C,CAAA;QAC9D,MAAM,IAAI,mCAAmC,CAAC,OAAO,CAAC,CAAA;IAC1D,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CommonOutput } from '@jettacargo/load-models';
|
|
2
|
+
/**
|
|
3
|
+
* Serializes the provided output payload and writes it to the default S3 bucket.
|
|
4
|
+
*
|
|
5
|
+
* @param {CommonOutput} output The standardized output payload containing the result or error state of the activity.
|
|
6
|
+
* @returns {Promise<string>} A promise that resolves to the generated S3 URI string where the output was saved.
|
|
7
|
+
*/
|
|
8
|
+
export default function write_output(output: CommonOutput): Promise<string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Object_Store_Driver } from '@jettacargo/s3';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
import { DEFAULT_BUCKET } from '../constants/Constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Serializes the provided output payload and writes it to the default S3 bucket.
|
|
6
|
+
*
|
|
7
|
+
* @param {CommonOutput} output The standardized output payload containing the result or error state of the activity.
|
|
8
|
+
* @returns {Promise<string>} A promise that resolves to the generated S3 URI string where the output was saved.
|
|
9
|
+
*/
|
|
10
|
+
export default async function write_output(output) {
|
|
11
|
+
const payload = JSON.stringify(output);
|
|
12
|
+
const key = `${randomUUID()}.json`;
|
|
13
|
+
await Object_Store_Driver.put_object(DEFAULT_BUCKET, key, payload);
|
|
14
|
+
return `s3://${DEFAULT_BUCKET}/${key}`;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=OutputWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutputWriter.js","sourceRoot":"","sources":["../../src/handler/OutputWriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CAAC,MAAoB;IAE3D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACtC,MAAM,GAAG,GAAO,GAAG,UAAU,EAAE,OAAO,CAAA;IACtC,MAAM,mBAAmB,CAAC,UAAU,CAAC,cAAc,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IAClE,OAAO,QAAQ,cAAc,IAAI,GAAG,EAAE,CAAA;AAC1C,CAAC"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as handle_activity } from './handler/ActivityHandler.js';
|
|
2
|
+
export { FatalError } from './error/Fatal.js';
|
|
3
|
+
export { TemporaryError } from './error/Temporary.js';
|
|
4
|
+
export { handle_workflow_error_signal } from './error/HandleWorkflowErrorSignal.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jettacargo/activity-handler",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
6
11
|
"scripts": {
|
|
12
|
+
"prebuild": "rm -rf build/*",
|
|
13
|
+
"build": "tsc",
|
|
7
14
|
"test": "tsx ./node_modules/mocha/bin/mocha \"test/**/*.ts\"",
|
|
8
15
|
"lint": "eslint src --ext .ts",
|
|
9
|
-
"lint:fix": "eslint
|
|
16
|
+
"lint:fix": "eslint src/**/*.{js,ts} --fix",
|
|
10
17
|
"audit": "npm audit --omit=dev",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
18
|
+
"preversion": "git fetch --prune --tags",
|
|
19
|
+
"version": "npm run build",
|
|
20
|
+
"postversion": "git push origin HEAD --follow-tags && rm -rf build/",
|
|
21
|
+
"publish:alpha": "npm version --tag-version-prefix=alpha-v",
|
|
22
|
+
"publish:stable": "npm version",
|
|
23
|
+
"prerelease:alpha": "npm version prerelease --tag-version-prefix=alpha-v",
|
|
24
|
+
"coverage": "c8 --check-coverage --lines 80 --functions 80 --branches 80 --statements 80 --reporter=html --reporter=text npm run test"
|
|
13
25
|
},
|
|
14
|
-
"type": "module",
|
|
15
26
|
"repository": {
|
|
16
27
|
"type": "git",
|
|
17
28
|
"url": "git+ssh://git@bitbucket.org/jettasoft_dev/activity-handler.git"
|
|
@@ -28,27 +39,29 @@
|
|
|
28
39
|
},
|
|
29
40
|
"homepage": "https://bitbucket.org/jettasoft_dev/activity-handler#readme",
|
|
30
41
|
"dependencies": {
|
|
31
|
-
"@jettacargo/load-models": "^0.4.
|
|
42
|
+
"@jettacargo/load-models": "^0.4.3-alpha.22",
|
|
32
43
|
"@jettacargo/s3": "0.0.4",
|
|
33
|
-
"@temporalio/worker": "1.
|
|
44
|
+
"@temporalio/worker": "^1.15.0",
|
|
45
|
+
"@temporalio/workflow": "^1.13.2",
|
|
46
|
+
"@jetta/logger": "^2.0.0"
|
|
34
47
|
},
|
|
35
48
|
"devDependencies": {
|
|
36
|
-
"@types/chai": "5.2.2",
|
|
49
|
+
"@types/chai": "^5.2.2",
|
|
37
50
|
"@types/chai-as-promised": "^8.0.2",
|
|
38
|
-
"@types/mocha": "10.0.10",
|
|
39
|
-
"@types/node": "24.7.2",
|
|
51
|
+
"@types/mocha": "^10.0.10",
|
|
52
|
+
"@types/node": "^24.7.2",
|
|
40
53
|
"@types/sinon": "^21.0.0",
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "8.46.0",
|
|
42
|
-
"@typescript-eslint/parser": "8.46.0",
|
|
43
|
-
"c8": "10.1.3",
|
|
44
|
-
"chai": "6.2.0",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
55
|
+
"@typescript-eslint/parser": "^8.46.0",
|
|
56
|
+
"c8": "^10.1.3",
|
|
57
|
+
"chai": "^6.2.0",
|
|
45
58
|
"chai-as-promised": "^8.0.2",
|
|
46
|
-
"eslint": "9.37.0",
|
|
47
|
-
"eslint-config-prettier": "10.1.8",
|
|
48
|
-
"mocha": "11.7.4",
|
|
59
|
+
"eslint": "^9.37.0",
|
|
60
|
+
"eslint-config-prettier": "^10.1.8",
|
|
61
|
+
"mocha": "^11.7.4",
|
|
49
62
|
"sinon": "^21.0.0",
|
|
50
|
-
"ts-node": "10.9.2",
|
|
51
|
-
"tsx": "4.20.6",
|
|
52
|
-
"typescript": "5.9.3"
|
|
63
|
+
"ts-node": "^10.9.2",
|
|
64
|
+
"tsx": "^4.20.6",
|
|
65
|
+
"typescript": "^5.9.3"
|
|
53
66
|
}
|
|
54
67
|
}
|