@jettacargo/activity-handler 1.0.0-alpha.20 → 1.0.0-alpha.4

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.
Files changed (32) hide show
  1. package/build/constants/Constants.d.ts +1 -1
  2. package/build/constants/Constants.js +1 -1
  3. package/build/constants/Constants.js.map +1 -1
  4. package/build/exceptions/FailedRetrievingFileFromS3Exception.d.ts +1 -2
  5. package/build/exceptions/FailedRetrievingFileFromS3Exception.js +1 -2
  6. package/build/exceptions/FailedRetrievingFileFromS3Exception.js.map +1 -1
  7. package/build/handler/ActivityHandler.d.ts +0 -9
  8. package/build/handler/ActivityHandler.js +10 -31
  9. package/build/handler/ActivityHandler.js.map +1 -1
  10. package/build/handler/InputReader.d.ts +0 -7
  11. package/build/handler/InputReader.js +3 -19
  12. package/build/handler/InputReader.js.map +1 -1
  13. package/build/handler/OutputWriter.d.ts +0 -6
  14. package/build/handler/OutputWriter.js +3 -9
  15. package/build/handler/OutputWriter.js.map +1 -1
  16. package/build/index.d.ts +0 -3
  17. package/build/index.js +0 -3
  18. package/build/index.js.map +1 -1
  19. package/package.json +19 -22
  20. package/README.md +0 -79
  21. package/build/error/Fatal.d.ts +0 -3
  22. package/build/error/Fatal.js +0 -7
  23. package/build/error/Fatal.js.map +0 -1
  24. package/build/error/HandleWorkflowErrorSignal.d.ts +0 -1
  25. package/build/error/HandleWorkflowErrorSignal.js +0 -19
  26. package/build/error/HandleWorkflowErrorSignal.js.map +0 -1
  27. package/build/error/Temporary.d.ts +0 -3
  28. package/build/error/Temporary.js +0 -7
  29. package/build/error/Temporary.js.map +0 -1
  30. package/build/exceptions/ErrorTypeMismatch.d.ts +0 -4
  31. package/build/exceptions/ErrorTypeMismatch.js +0 -7
  32. package/build/exceptions/ErrorTypeMismatch.js.map +0 -1
@@ -1,2 +1,2 @@
1
- declare const DEFAULT_BUCKET = "tmp-daily";
1
+ declare const DEFAULT_BUCKET = "tmp-dailys";
2
2
  export { DEFAULT_BUCKET };
@@ -1,3 +1,3 @@
1
- const DEFAULT_BUCKET = 'tmp-daily';
1
+ const DEFAULT_BUCKET = 'tmp-dailys';
2
2
  export { DEFAULT_BUCKET };
3
3
  //# sourceMappingURL=Constants.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/constants/Constants.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,YAAY,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -1,4 +1,3 @@
1
- import { FatalError } from '../error/Fatal.js';
2
- export default class FailedRetrievingFileFromS3Exception extends FatalError {
1
+ export default class FailedRetrievingFileFromS3Exception extends Error {
3
2
  constructor(message: string);
4
3
  }
@@ -1,5 +1,4 @@
1
- import { FatalError } from '../error/Fatal.js';
2
- export default class FailedRetrievingFileFromS3Exception extends FatalError {
1
+ export default class FailedRetrievingFileFromS3Exception extends Error {
3
2
  constructor(message) {
4
3
  super(message);
5
4
  }
@@ -1 +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"}
1
+ {"version":3,"file":"FailedRetrievingFileFromS3Exception.js","sourceRoot":"","sources":["../../src/exceptions/FailedRetrievingFileFromS3Exception.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,mCAAoC,SAAQ,KAAK;IAElE,YAAY,OAAe;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;CACJ"}
@@ -1,11 +1,2 @@
1
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
2
  export default function handle_activity(event_metadata: EventMetadata, source: string, callback: ActivityCallback): Promise<EventMetadata>;
@@ -1,43 +1,22 @@
1
1
  import { EventStatus } from '@jettacargo/load-models';
2
2
  import read_input from './InputReader.js';
3
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
4
  export default async function handle_activity(event_metadata, source, callback) {
17
5
  try {
18
6
  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);
7
+ const output = callback(input_data);
8
+ const output_uri = await write_output(output.data);
9
+ return build_response(output.status, output_uri, source);
22
10
  }
23
- catch (err) {
24
- if (err instanceof Error) {
25
- return await handle_error(err, source);
26
- }
27
- throw new ErrorTypeMismatch();
11
+ catch {
12
+ return build_response(EventStatus.FAILURE, undefined, source);
28
13
  }
29
14
  }
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)
15
+ function build_response(status, uri, source) {
16
+ return {
17
+ type: status,
18
+ data: uri,
19
+ source: source
36
20
  };
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
21
  }
43
22
  //# sourceMappingURL=ActivityHandler.js.map
@@ -1 +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;Q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0B;IAG1B,IACA,CAAC;QACG,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QACxD,MAAM,MAAM,GAAO,QAAQ,CAAC,UAAU,CAAC,CAAA;QACvC,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,OAAO,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;IAC5D,CAAC;IACD,MACA,CAAC;QACG,OAAO,cAAc,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;IACjE,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,MAAmB,EAAE,GAAuB,EAAE,MAAc;IAEhF,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,MAAM;KACjB,CAAA;AACL,CAAC"}
@@ -1,9 +1,2 @@
1
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
2
  export default function read_input(uri: string | undefined): Promise<CommonInput>;
@@ -1,30 +1,14 @@
1
1
  import { Object_Store_Driver } from '@jettacargo/s3';
2
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
- */
3
+ import { DEFAULT_BUCKET } from '../constants/Constants.js';
19
4
  export default async function read_input(uri) {
20
5
  if (uri === undefined) {
21
6
  const message = `Failed retrieving data from s3 at address: ${uri}`;
22
7
  throw new FailedRetrievingFileFromS3Exception(message);
23
8
  }
24
- const { bucket, key } = split_uri(uri);
25
- const raw_input = await Object_Store_Driver.get_object(bucket, key);
9
+ const raw_input = await Object_Store_Driver.get_object(DEFAULT_BUCKET, uri);
26
10
  if (raw_input === undefined) {
27
- const message = `Failed when retrieving data from s3: no data returned.`;
11
+ const message = `Failed whe retrieving data from s3: undefined uri.`;
28
12
  throw new FailedRetrievingFileFromS3Exception(message);
29
13
  }
30
14
  try {
@@ -1 +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;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ED,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;IAE3E,IAAI,SAAS,KAAK,SAAS,EAC3B,CAAC;QACG,MAAM,OAAO,GAAG,oDAAoD,CAAA;QACpE,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"}
@@ -1,8 +1,2 @@
1
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
2
  export default function write_output(output: CommonOutput): Promise<string>;
@@ -1,16 +1,10 @@
1
1
  import { Object_Store_Driver } from '@jettacargo/s3';
2
2
  import { randomUUID } from 'crypto';
3
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
4
  export default async function write_output(output) {
11
5
  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}`;
6
+ const uri = `${randomUUID()}.json`;
7
+ await Object_Store_Driver.put_object(DEFAULT_BUCKET, uri, payload);
8
+ return uri;
15
9
  }
16
10
  //# sourceMappingURL=OutputWriter.js.map
@@ -1 +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"}
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,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,GAAG,CAAA;AACd,CAAC"}
package/build/index.d.ts CHANGED
@@ -1,4 +1 @@
1
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';
package/build/index.js CHANGED
@@ -1,5 +1,2 @@
1
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
2
  //# sourceMappingURL=index.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jettacargo/activity-handler",
3
- "version": "1.0.0-alpha.20",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -9,19 +9,18 @@
9
9
  ],
10
10
  "type": "module",
11
11
  "scripts": {
12
- "prebuild": "rm -rf build/*",
13
- "build": "tsc",
12
+ "build": "rm -rf dist/* && tsc",
14
13
  "test": "tsx ./node_modules/mocha/bin/mocha \"test/**/*.ts\"",
15
14
  "lint": "eslint src --ext .ts",
16
15
  "lint:fix": "eslint src/**/*.{js,ts} --fix",
17
16
  "audit": "npm audit --omit=dev",
18
17
  "preversion": "git fetch --prune --tags",
19
18
  "version": "npm run build",
20
- "postversion": "git push origin HEAD --follow-tags && rm -rf build/",
19
+ "postversion": "git push origin HEAD --follow-tags && rm -rf dist/",
21
20
  "publish:alpha": "npm version --tag-version-prefix=alpha-v",
22
21
  "publish:stable": "npm version",
23
22
  "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"
23
+ "coverage": "c8 --reporter=html --reporter=text node --loader=./node_modules/ts-node/esm.mjs --experimental-specifier-resolution=node ./node_modules/mocha/bin/mocha.js 'test/**/test_*.ts'"
25
24
  },
26
25
  "repository": {
27
26
  "type": "git",
@@ -39,29 +38,27 @@
39
38
  },
40
39
  "homepage": "https://bitbucket.org/jettasoft_dev/activity-handler#readme",
41
40
  "dependencies": {
42
- "@jettacargo/load-models": "^0.4.3-alpha.22",
41
+ "@jettacargo/load-models": "^0.4.1",
43
42
  "@jettacargo/s3": "0.0.4",
44
- "@temporalio/worker": "^1.15.0",
45
- "@temporalio/workflow": "^1.13.2",
46
- "@jetta/logger": "^2.0.0"
43
+ "@temporalio/worker": "1.13.2"
47
44
  },
48
45
  "devDependencies": {
49
- "@types/chai": "^5.2.2",
46
+ "@types/chai": "5.2.2",
50
47
  "@types/chai-as-promised": "^8.0.2",
51
- "@types/mocha": "^10.0.10",
52
- "@types/node": "^24.7.2",
48
+ "@types/mocha": "10.0.10",
49
+ "@types/node": "24.7.2",
53
50
  "@types/sinon": "^21.0.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",
51
+ "@typescript-eslint/eslint-plugin": "8.46.0",
52
+ "@typescript-eslint/parser": "8.46.0",
53
+ "c8": "10.1.3",
54
+ "chai": "6.2.0",
58
55
  "chai-as-promised": "^8.0.2",
59
- "eslint": "^9.37.0",
60
- "eslint-config-prettier": "^10.1.8",
61
- "mocha": "^11.7.4",
56
+ "eslint": "9.37.0",
57
+ "eslint-config-prettier": "10.1.8",
58
+ "mocha": "11.7.4",
62
59
  "sinon": "^21.0.0",
63
- "ts-node": "^10.9.2",
64
- "tsx": "^4.20.6",
65
- "typescript": "^5.9.3"
60
+ "ts-node": "10.9.2",
61
+ "tsx": "4.20.6",
62
+ "typescript": "5.9.3"
66
63
  }
67
64
  }
package/README.md DELETED
@@ -1,79 +0,0 @@
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
- ```
@@ -1,3 +0,0 @@
1
- export declare class FatalError extends Error {
2
- constructor(message: string);
3
- }
@@ -1,7 +0,0 @@
1
- export class FatalError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'FatalError';
5
- }
6
- }
7
- //# sourceMappingURL=Fatal.js.map
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- export declare function handle_workflow_error_signal(err: Error): void;
@@ -1,19 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- export declare class TemporaryError extends Error {
2
- constructor(message: string);
3
- }
@@ -1,7 +0,0 @@
1
- export class TemporaryError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'TemporaryError';
5
- }
6
- }
7
- //# sourceMappingURL=Temporary.js.map
@@ -1 +0,0 @@
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"}
@@ -1,4 +0,0 @@
1
- import { FatalError } from '../error/Fatal.js';
2
- export default class ErrorTypeMismatch extends FatalError {
3
- constructor();
4
- }
@@ -1,7 +0,0 @@
1
- import { FatalError } from '../error/Fatal.js';
2
- export default class ErrorTypeMismatch extends FatalError {
3
- constructor() {
4
- super('Only supports Error type for exception.');
5
- }
6
- }
7
- //# sourceMappingURL=ErrorTypeMismatch.js.map
@@ -1 +0,0 @@
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"}