@diia-inhouse/workflow 1.17.7 → 2.5.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/dist/activities/index.d.ts +1 -0
- package/dist/activities/index.js +2 -18
- package/dist/activities/proxy.d.ts +34 -0
- package/dist/activities/proxy.js +16 -24
- package/dist/activity.d.ts +2 -0
- package/dist/activity.js +2 -15
- package/dist/cli/checkWorkflowDeterminism.js +249 -275
- package/dist/cli/determinism/errorClassifier.js +56 -60
- package/dist/cli/determinism/historyFiles.js +68 -97
- package/dist/cli/determinism/index.js +7 -19
- package/dist/cli/determinism/replayExecutor.js +114 -133
- package/dist/cli/determinism/replayOptions.js +13 -22
- package/dist/cli/determinism/report.js +55 -45
- package/dist/cli/determinism/reportPrinter.js +101 -138
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +79 -119
- package/dist/cli/syncTemporalSchedules.js +74 -91
- package/dist/cli/updateTemporalSchedule.js +43 -53
- package/dist/client.d.ts +3 -0
- package/dist/client.js +3 -19
- package/dist/common.d.ts +2 -0
- package/dist/common.js +2 -13
- package/dist/encryption/crypto.d.ts +7 -0
- package/dist/encryption/crypto.js +20 -22
- package/dist/encryption/dataConverter.d.ts +7 -0
- package/dist/encryption/dataConverter.js +15 -22
- package/dist/encryption/encryptionCodec.d.ts +31 -0
- package/dist/encryption/encryptionCodec.js +108 -124
- package/dist/encryption/index.d.ts +3 -0
- package/dist/encryption/index.js +4 -20
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -42
- package/dist/instrumentation.js +6 -10
- package/dist/interceptors/asyncLocalStorageBridge.js +29 -66
- package/dist/interceptors/traceLogAttributes.d.ts +6 -0
- package/dist/interceptors/traceLogAttributes.js +16 -54
- package/dist/interceptors.d.ts +6 -0
- package/dist/interceptors.js +6 -8
- package/dist/interfaces/config.d.ts +58 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/services/schedulesExporter.d.ts +96 -0
- package/dist/interfaces/services/worker.d.ts +60 -0
- package/dist/operations.d.ts +9 -0
- package/dist/operations.js +11 -75
- package/dist/services/client.d.ts +24 -0
- package/dist/services/client.js +89 -96
- package/dist/services/schedulesExporter.d.ts +101 -0
- package/dist/services/schedulesExporter.js +456 -0
- package/dist/services/worker/identity.d.ts +4 -0
- package/dist/services/worker/identity.js +6 -9
- package/dist/services/worker.d.ts +124 -0
- package/dist/services/worker.js +324 -304
- package/dist/services/workerHealth.d.ts +15 -0
- package/dist/services/workerHealth.js +26 -35
- package/dist/testing.d.ts +42 -0
- package/dist/testing.js +43 -54
- package/dist/worker.d.ts +9 -0
- package/dist/worker.js +7 -25
- package/package.json +40 -38
- package/dist/activities/index.js.map +0 -1
- package/dist/activities/proxy.js.map +0 -1
- package/dist/activity.js.map +0 -1
- package/dist/cli/checkWorkflowDeterminism.js.map +0 -1
- package/dist/cli/determinism/errorClassifier.js.map +0 -1
- package/dist/cli/determinism/historyFiles.js.map +0 -1
- package/dist/cli/determinism/index.js.map +0 -1
- package/dist/cli/determinism/replayExecutor.js.map +0 -1
- package/dist/cli/determinism/replayOptions.js.map +0 -1
- package/dist/cli/determinism/report.js.map +0 -1
- package/dist/cli/determinism/reportPrinter.js.map +0 -1
- package/dist/cli/determinism/types.js +0 -3
- package/dist/cli/determinism/types.js.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/syncTemporalSchedules.js.map +0 -1
- package/dist/cli/updateTemporalSchedule.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/common.js.map +0 -1
- package/dist/encryption/crypto.js.map +0 -1
- package/dist/encryption/dataConverter.js.map +0 -1
- package/dist/encryption/encryptionCodec.js.map +0 -1
- package/dist/encryption/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation.js.map +0 -1
- package/dist/interceptors/asyncLocalStorageBridge.js.map +0 -1
- package/dist/interceptors/index.js +0 -8
- package/dist/interceptors/index.js.map +0 -1
- package/dist/interceptors/traceLogAttributes.js.map +0 -1
- package/dist/interceptors.js.map +0 -1
- package/dist/interfaces/config.js +0 -3
- package/dist/interfaces/config.js.map +0 -1
- package/dist/interfaces/index.js +0 -18
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/services/worker.js +0 -3
- package/dist/interfaces/services/worker.js.map +0 -1
- package/dist/operations.js.map +0 -1
- package/dist/services/client.js.map +0 -1
- package/dist/services/index.js +0 -19
- package/dist/services/index.js.map +0 -1
- package/dist/services/worker/identity.js.map +0 -1
- package/dist/services/worker/index.js +0 -18
- package/dist/services/worker/index.js.map +0 -1
- package/dist/services/worker.js.map +0 -1
- package/dist/services/workerHealth.js.map +0 -1
- package/dist/testing.js.map +0 -1
- package/dist/types/activities/index.d.ts +0 -1
- package/dist/types/activities/proxy.d.ts +0 -35
- package/dist/types/activity.d.ts +0 -1
- package/dist/types/cli/checkWorkflowDeterminism.d.ts +0 -19
- package/dist/types/cli/determinism/errorClassifier.d.ts +0 -15
- package/dist/types/cli/determinism/historyFiles.d.ts +0 -18
- package/dist/types/cli/determinism/index.d.ts +0 -10
- package/dist/types/cli/determinism/replayExecutor.d.ts +0 -9
- package/dist/types/cli/determinism/replayOptions.d.ts +0 -7
- package/dist/types/cli/determinism/report.d.ts +0 -16
- package/dist/types/cli/determinism/reportPrinter.d.ts +0 -5
- package/dist/types/cli/determinism/types.d.ts +0 -44
- package/dist/types/cli/index.d.ts +0 -2
- package/dist/types/cli/syncTemporalSchedules.d.ts +0 -12
- package/dist/types/cli/updateTemporalSchedule.d.ts +0 -9
- package/dist/types/client.d.ts +0 -2
- package/dist/types/common.d.ts +0 -1
- package/dist/types/encryption/crypto.d.ts +0 -3
- package/dist/types/encryption/dataConverter.d.ts +0 -3
- package/dist/types/encryption/encryptionCodec.d.ts +0 -27
- package/dist/types/encryption/index.d.ts +0 -3
- package/dist/types/index.d.ts +0 -3
- package/dist/types/instrumentation.d.ts +0 -2
- package/dist/types/interceptors/asyncLocalStorageBridge.d.ts +0 -21
- package/dist/types/interceptors/index.d.ts +0 -2
- package/dist/types/interceptors/traceLogAttributes.d.ts +0 -2
- package/dist/types/interceptors.d.ts +0 -2
- package/dist/types/interfaces/config.d.ts +0 -38
- package/dist/types/interfaces/index.d.ts +0 -1
- package/dist/types/interfaces/services/worker.d.ts +0 -37
- package/dist/types/operations.d.ts +0 -5
- package/dist/types/services/client.d.ts +0 -20
- package/dist/types/services/index.d.ts +0 -2
- package/dist/types/services/worker/identity.d.ts +0 -1
- package/dist/types/services/worker/index.d.ts +0 -1
- package/dist/types/services/worker.d.ts +0 -113
- package/dist/types/services/workerHealth.d.ts +0 -11
- package/dist/types/testing.d.ts +0 -42
- package/dist/types/worker.d.ts +0 -3
- package/dist/worker.js.map +0 -1
|
@@ -1,92 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { TemporalClient } from "../services/client.js";
|
|
2
|
+
import { EnvService } from "@diia-inhouse/env";
|
|
3
|
+
import { ScheduleAlreadyRunning } from "@temporalio/client";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { utils } from "@diia-inhouse/utils";
|
|
7
|
+
//#region src/cli/syncTemporalSchedules.ts
|
|
8
|
+
var SyncTemporalSchedulesCommand = class {
|
|
9
|
+
logger;
|
|
10
|
+
envService;
|
|
11
|
+
constructor(logger, envService) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.envService = envService;
|
|
14
|
+
}
|
|
15
|
+
async run(schedulesPath = "worker/schedules", taskQueueParam) {
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
this.logger.info("Starting sync temporal schedules", {
|
|
18
|
+
schedulesPath,
|
|
19
|
+
taskQueue: taskQueueParam
|
|
20
|
+
});
|
|
21
|
+
const schedules = await this.loadSchedules(schedulesPath);
|
|
22
|
+
if (!schedules) {
|
|
23
|
+
this.logger.info("Temporal schedules not found under provided path", { schedulesPath });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const taskQueue = taskQueueParam || this.getTaskQueue();
|
|
27
|
+
if (!taskQueue) throw new Error("Task queue is not provided");
|
|
28
|
+
const client = new TemporalClient({
|
|
29
|
+
address: EnvService.getVar("TEMPORAL_ADDRESS"),
|
|
30
|
+
namespace: EnvService.getVar("TEMPORAL_NAMESPACE", "string", "default"),
|
|
31
|
+
taskQueue,
|
|
32
|
+
encryptionEnabled: EnvService.getVar("TEMPORAL_ENCRYPTION_ENABLED", "boolean", false),
|
|
33
|
+
encryptionKeyId: EnvService.getVar("TEMPORAL_ENCRYPTION_KEY_ID", "string", "")
|
|
34
|
+
}, this.envService, this.logger);
|
|
35
|
+
await client.onInit();
|
|
36
|
+
await this.syncSchedules(client, schedules);
|
|
37
|
+
this.logger.info(`Sync temporal schedules finished! It took ${((Date.now() - startTime) / 1e3).toFixed(1)} seconds`);
|
|
38
|
+
await client.nativeClient.connection.close();
|
|
39
|
+
process.exit(0);
|
|
40
|
+
}
|
|
41
|
+
async loadSchedules(schedulesPath) {
|
|
42
|
+
const fullSchedulesPath = this.resolveSchedulesPath(schedulesPath);
|
|
43
|
+
if (!existsSync(fullSchedulesPath)) return;
|
|
44
|
+
const { default: _default, ...schedules } = await import(fullSchedulesPath);
|
|
45
|
+
return schedules;
|
|
46
|
+
}
|
|
47
|
+
resolveSchedulesPath(schedulesPath) {
|
|
48
|
+
const baseDir = path.resolve("./dist");
|
|
49
|
+
const fullPath = path.resolve(baseDir, schedulesPath, "index.js");
|
|
50
|
+
if (!fullPath.startsWith(baseDir + path.sep)) throw new Error(`Invalid schedules path: path traversal detected in '${schedulesPath}'`);
|
|
51
|
+
return fullPath;
|
|
52
|
+
}
|
|
53
|
+
async syncSchedules(client, schedules) {
|
|
54
|
+
try {
|
|
55
|
+
const scheduleNames = Object.keys(schedules);
|
|
56
|
+
this.logger.info(`Found ${scheduleNames.length} schedules to sync: ${scheduleNames.join(", ")}`);
|
|
57
|
+
await client.syncSchedules(schedules);
|
|
58
|
+
this.logger.info("Successfully synced temporal schedules");
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if (err instanceof ScheduleAlreadyRunning) {
|
|
61
|
+
this.logger.info("Schedule already running, skipping creation");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.logger.error("Failed to sync temporal schedules", { err });
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
getTaskQueue() {
|
|
69
|
+
const taskQueue = EnvService.getVar("TEMPORAL_TASK_QUEUE", "string", "");
|
|
70
|
+
if (!taskQueue) return utils.getServiceName();
|
|
71
|
+
return taskQueue;
|
|
72
|
+
}
|
|
4
73
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const client_1 = require("@temporalio/client");
|
|
10
|
-
const ts_node_1 = require("ts-node");
|
|
11
|
-
const env_1 = require("@diia-inhouse/env");
|
|
12
|
-
const utils_1 = require("@diia-inhouse/utils");
|
|
13
|
-
const client_2 = require("../services/client");
|
|
14
|
-
(0, ts_node_1.register)();
|
|
15
|
-
class SyncTemporalSchedulesCommand {
|
|
16
|
-
logger;
|
|
17
|
-
envService;
|
|
18
|
-
constructor(logger, envService) {
|
|
19
|
-
this.logger = logger;
|
|
20
|
-
this.envService = envService;
|
|
21
|
-
}
|
|
22
|
-
async run(schedulesPath = 'worker/schedules', taskQueueParam) {
|
|
23
|
-
const startTime = Date.now();
|
|
24
|
-
this.logger.info('Starting sync temporal schedules', { schedulesPath, taskQueue: taskQueueParam });
|
|
25
|
-
const schedules = await this.loadSchedules(schedulesPath);
|
|
26
|
-
if (!schedules) {
|
|
27
|
-
this.logger.info('Temporal schedules not found under provided path', { schedulesPath });
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const taskQueue = taskQueueParam || this.getTaskQueue();
|
|
31
|
-
if (!taskQueue) {
|
|
32
|
-
throw new Error('Task queue is not provided');
|
|
33
|
-
}
|
|
34
|
-
const temporalConfig = {
|
|
35
|
-
address: env_1.EnvService.getVar('TEMPORAL_ADDRESS'),
|
|
36
|
-
namespace: env_1.EnvService.getVar('TEMPORAL_NAMESPACE', 'string', 'default'),
|
|
37
|
-
taskQueue,
|
|
38
|
-
encryptionEnabled: env_1.EnvService.getVar('TEMPORAL_ENCRYPTION_ENABLED', 'boolean', false),
|
|
39
|
-
encryptionKeyId: env_1.EnvService.getVar('TEMPORAL_ENCRYPTION_KEY_ID', 'string', ''),
|
|
40
|
-
};
|
|
41
|
-
const client = new client_2.TemporalClient(temporalConfig, this.envService, this.logger);
|
|
42
|
-
await client.onInit();
|
|
43
|
-
await this.syncSchedules(client, schedules);
|
|
44
|
-
this.logger.info(`Sync temporal schedules finished! It took ${((Date.now() - startTime) / 1000).toFixed(1)} seconds`);
|
|
45
|
-
await client.nativeClient.connection.close();
|
|
46
|
-
// eslint-disable-next-line unicorn/no-process-exit
|
|
47
|
-
process.exit(0);
|
|
48
|
-
}
|
|
49
|
-
async loadSchedules(schedulesPath) {
|
|
50
|
-
const fullSchedulesPath = this.resolveSchedulesPath(schedulesPath);
|
|
51
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
52
|
-
const schedulesExist = (0, node_fs_1.existsSync)(fullSchedulesPath); // nosemgrep: eslint.detect-non-literal-fs-filename
|
|
53
|
-
if (!schedulesExist) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const module = await import(fullSchedulesPath);
|
|
57
|
-
return module.default;
|
|
58
|
-
}
|
|
59
|
-
resolveSchedulesPath(schedulesPath) {
|
|
60
|
-
const baseDir = node_path_1.default.resolve('./dist');
|
|
61
|
-
const fullPath = node_path_1.default.resolve(baseDir, schedulesPath, 'index.js');
|
|
62
|
-
if (!fullPath.startsWith(baseDir + node_path_1.default.sep)) {
|
|
63
|
-
throw new Error(`Invalid schedules path: path traversal detected in '${schedulesPath}'`);
|
|
64
|
-
}
|
|
65
|
-
return fullPath;
|
|
66
|
-
}
|
|
67
|
-
async syncSchedules(client, schedules) {
|
|
68
|
-
try {
|
|
69
|
-
const scheduleNames = Object.keys(schedules);
|
|
70
|
-
this.logger.info(`Found ${scheduleNames.length} schedules to sync: ${scheduleNames.join(', ')}`);
|
|
71
|
-
await client.syncSchedules(schedules);
|
|
72
|
-
this.logger.info('Successfully synced temporal schedules');
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
if (err instanceof client_1.ScheduleAlreadyRunning) {
|
|
76
|
-
this.logger.info('Schedule already running, skipping creation');
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
this.logger.error('Failed to sync temporal schedules', { err });
|
|
80
|
-
throw err;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
getTaskQueue() {
|
|
84
|
-
const taskQueue = env_1.EnvService.getVar('TEMPORAL_TASK_QUEUE', 'string', '');
|
|
85
|
-
if (!taskQueue) {
|
|
86
|
-
return utils_1.utils.getServiceName();
|
|
87
|
-
}
|
|
88
|
-
return taskQueue;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.SyncTemporalSchedulesCommand = SyncTemporalSchedulesCommand;
|
|
92
|
-
//# sourceMappingURL=syncTemporalSchedules.js.map
|
|
74
|
+
//#endregion
|
|
75
|
+
export { SyncTemporalSchedulesCommand };
|
|
@@ -1,53 +1,43 @@
|
|
|
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
|
-
getTaskQueue() {
|
|
45
|
-
const taskQueue = env_1.EnvService.getVar('TEMPORAL_TASK_QUEUE', 'string', '');
|
|
46
|
-
if (!taskQueue) {
|
|
47
|
-
return utils_1.utils.getServiceName();
|
|
48
|
-
}
|
|
49
|
-
return taskQueue;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.UpdateTemporalScheduleCommand = UpdateTemporalScheduleCommand;
|
|
53
|
-
//# sourceMappingURL=updateTemporalSchedule.js.map
|
|
1
|
+
import { TemporalClient } from "../services/client.js";
|
|
2
|
+
import { EnvService } from "@diia-inhouse/env";
|
|
3
|
+
import { utils } from "@diia-inhouse/utils";
|
|
4
|
+
//#region src/cli/updateTemporalSchedule.ts
|
|
5
|
+
var UpdateTemporalScheduleCommand = class {
|
|
6
|
+
logger;
|
|
7
|
+
envService;
|
|
8
|
+
constructor(logger, envService) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.envService = envService;
|
|
11
|
+
}
|
|
12
|
+
async run(scheduleId, updateData) {
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
this.logger.info("Starting update temporal schedule", { scheduleId });
|
|
15
|
+
const taskQueue = this.getTaskQueue();
|
|
16
|
+
if (!taskQueue) throw new Error("Task queue is not provided");
|
|
17
|
+
const client = new TemporalClient({
|
|
18
|
+
address: EnvService.getVar("TEMPORAL_ADDRESS"),
|
|
19
|
+
namespace: EnvService.getVar("TEMPORAL_NAMESPACE", "string", "default"),
|
|
20
|
+
taskQueue,
|
|
21
|
+
encryptionEnabled: EnvService.getVar("TEMPORAL_ENCRYPTION_ENABLED", "boolean", false),
|
|
22
|
+
encryptionKeyId: EnvService.getVar("TEMPORAL_ENCRYPTION_KEY_ID", "string", "")
|
|
23
|
+
}, this.envService, this.logger);
|
|
24
|
+
await client.onInit();
|
|
25
|
+
try {
|
|
26
|
+
await client.updateSchedule(scheduleId, updateData);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
this.logger.error("Failed to update temporal schedule", { err });
|
|
29
|
+
throw err;
|
|
30
|
+
} finally {
|
|
31
|
+
await client.nativeClient.connection.close();
|
|
32
|
+
}
|
|
33
|
+
this.logger.info(`Update temporal schedule finished! It took ${((Date.now() - startTime) / 1e3).toFixed(1)} seconds`);
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
getTaskQueue() {
|
|
37
|
+
const taskQueue = EnvService.getVar("TEMPORAL_TASK_QUEUE", "string", "");
|
|
38
|
+
if (!taskQueue) return utils.getServiceName();
|
|
39
|
+
return taskQueue;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { UpdateTemporalScheduleCommand };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TemporalClient } from "./services/client.js";
|
|
2
|
+
import { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, Client, DAYS_OF_WEEK, DayOfWeek, MONTHS, Month, ProtoFailure, ScheduleOptions, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, WorkflowClient, WorkflowHandleWithFirstExecutionRunId } from "@temporalio/client";
|
|
3
|
+
export { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, Client, DAYS_OF_WEEK, type DayOfWeek, MONTHS, type Month, type ProtoFailure, type ScheduleOptions, ServerFailure, TemporalClient, TemporalFailure, TerminatedFailure, TimeoutFailure, WorkflowClient, type WorkflowHandleWithFirstExecutionRunId };
|
package/dist/client.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var client_1 = require("@temporalio/client");
|
|
5
|
-
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
6
|
-
Object.defineProperty(exports, "DAYS_OF_WEEK", { enumerable: true, get: function () { return client_1.DAYS_OF_WEEK; } });
|
|
7
|
-
Object.defineProperty(exports, "MONTHS", { enumerable: true, get: function () { return client_1.MONTHS; } });
|
|
8
|
-
Object.defineProperty(exports, "WorkflowClient", { enumerable: true, get: function () { return client_1.WorkflowClient; } });
|
|
9
|
-
Object.defineProperty(exports, "ActivityFailure", { enumerable: true, get: function () { return client_1.ActivityFailure; } });
|
|
10
|
-
Object.defineProperty(exports, "ServerFailure", { enumerable: true, get: function () { return client_1.ServerFailure; } });
|
|
11
|
-
Object.defineProperty(exports, "TimeoutFailure", { enumerable: true, get: function () { return client_1.TimeoutFailure; } });
|
|
12
|
-
Object.defineProperty(exports, "TemporalFailure", { enumerable: true, get: function () { return client_1.TemporalFailure; } });
|
|
13
|
-
Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return client_1.CancelledFailure; } });
|
|
14
|
-
Object.defineProperty(exports, "TerminatedFailure", { enumerable: true, get: function () { return client_1.TerminatedFailure; } });
|
|
15
|
-
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return client_1.ApplicationFailure; } });
|
|
16
|
-
Object.defineProperty(exports, "ChildWorkflowFailure", { enumerable: true, get: function () { return client_1.ChildWorkflowFailure; } });
|
|
17
|
-
var client_2 = require("./services/client");
|
|
18
|
-
Object.defineProperty(exports, "TemporalClient", { enumerable: true, get: function () { return client_2.TemporalClient; } });
|
|
19
|
-
//# sourceMappingURL=client.js.map
|
|
1
|
+
import { TemporalClient } from "./services/client.js";
|
|
2
|
+
import { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, Client, DAYS_OF_WEEK, MONTHS, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, WorkflowClient } from "@temporalio/client";
|
|
3
|
+
export { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, Client, DAYS_OF_WEEK, MONTHS, ServerFailure, TemporalClient, TemporalFailure, TerminatedFailure, TimeoutFailure, WorkflowClient };
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { DataConverter, WorkflowExecutionAlreadyStartedError, arrayFromPayloads, cutoffStackTrace, defaultFailureConverter, ensureApplicationFailure, ensureTemporalFailure, extractWorkflowType, rootCause } from "@temporalio/common";
|
|
2
|
+
export { type DataConverter, WorkflowExecutionAlreadyStartedError, arrayFromPayloads, cutoffStackTrace, defaultFailureConverter, ensureApplicationFailure, ensureTemporalFailure, extractWorkflowType, rootCause };
|
package/dist/common.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.WorkflowExecutionAlreadyStartedError = exports.rootCause = exports.defaultFailureConverter = exports.extractWorkflowType = exports.ensureTemporalFailure = exports.ensureApplicationFailure = exports.cutoffStackTrace = exports.arrayFromPayloads = void 0;
|
|
4
|
-
var common_1 = require("@temporalio/common");
|
|
5
|
-
Object.defineProperty(exports, "arrayFromPayloads", { enumerable: true, get: function () { return common_1.arrayFromPayloads; } });
|
|
6
|
-
Object.defineProperty(exports, "cutoffStackTrace", { enumerable: true, get: function () { return common_1.cutoffStackTrace; } });
|
|
7
|
-
Object.defineProperty(exports, "ensureApplicationFailure", { enumerable: true, get: function () { return common_1.ensureApplicationFailure; } });
|
|
8
|
-
Object.defineProperty(exports, "ensureTemporalFailure", { enumerable: true, get: function () { return common_1.ensureTemporalFailure; } });
|
|
9
|
-
Object.defineProperty(exports, "extractWorkflowType", { enumerable: true, get: function () { return common_1.extractWorkflowType; } });
|
|
10
|
-
Object.defineProperty(exports, "defaultFailureConverter", { enumerable: true, get: function () { return common_1.defaultFailureConverter; } });
|
|
11
|
-
Object.defineProperty(exports, "rootCause", { enumerable: true, get: function () { return common_1.rootCause; } });
|
|
12
|
-
Object.defineProperty(exports, "WorkflowExecutionAlreadyStartedError", { enumerable: true, get: function () { return common_1.WorkflowExecutionAlreadyStartedError; } });
|
|
13
|
-
//# sourceMappingURL=common.js.map
|
|
1
|
+
import { WorkflowExecutionAlreadyStartedError, arrayFromPayloads, cutoffStackTrace, defaultFailureConverter, ensureApplicationFailure, ensureTemporalFailure, extractWorkflowType, rootCause } from "@temporalio/common";
|
|
2
|
+
export { WorkflowExecutionAlreadyStartedError, arrayFromPayloads, cutoffStackTrace, defaultFailureConverter, ensureApplicationFailure, ensureTemporalFailure, extractWorkflowType, rootCause };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { webcrypto } from "crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/encryption/crypto.d.ts
|
|
4
|
+
declare function encrypt(data: Uint8Array, key: webcrypto.CryptoKey): Promise<Uint8Array>;
|
|
5
|
+
declare function decrypt(encryptedData: Uint8Array, key: webcrypto.CryptoKey): Promise<Uint8Array>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { decrypt, encrypt };
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.decrypt = decrypt;
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
6
|
-
const CIPHER = 'AES-GCM';
|
|
1
|
+
import { webcrypto } from "crypto";
|
|
2
|
+
//#region src/encryption/crypto.ts
|
|
3
|
+
const CIPHER = "AES-GCM";
|
|
7
4
|
const IV_LENGTH_BYTES = 12;
|
|
8
5
|
const TAG_LENGTH_BYTES = 16;
|
|
9
6
|
async function encrypt(data, key) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const iv = webcrypto.getRandomValues(new Uint8Array(IV_LENGTH_BYTES));
|
|
8
|
+
const encrypted = await webcrypto.subtle.encrypt({
|
|
9
|
+
name: CIPHER,
|
|
10
|
+
iv,
|
|
11
|
+
tagLength: TAG_LENGTH_BYTES * 8
|
|
12
|
+
}, key, data);
|
|
13
|
+
return Buffer.concat([iv, new Uint8Array(encrypted)]);
|
|
17
14
|
}
|
|
18
15
|
async function decrypt(encryptedData, key) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
const iv = encryptedData.subarray(0, IV_LENGTH_BYTES);
|
|
17
|
+
const ciphertext = encryptedData.subarray(IV_LENGTH_BYTES);
|
|
18
|
+
const decrypted = await webcrypto.subtle.decrypt({
|
|
19
|
+
name: CIPHER,
|
|
20
|
+
iv,
|
|
21
|
+
tagLength: TAG_LENGTH_BYTES * 8
|
|
22
|
+
}, key, ciphertext);
|
|
23
|
+
return new Uint8Array(decrypted);
|
|
27
24
|
}
|
|
28
|
-
//#
|
|
25
|
+
//#endregion
|
|
26
|
+
export { decrypt, encrypt };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EnvService } from "@diia-inhouse/env";
|
|
2
|
+
import { DataConverter } from "@temporalio/common";
|
|
3
|
+
|
|
4
|
+
//#region src/encryption/dataConverter.d.ts
|
|
5
|
+
declare function getDataConverter(keyId: string, envService: EnvService, refreshInterval?: number): Promise<DataConverter>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { getDataConverter };
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const types_1 = require("@diia-inhouse/types");
|
|
6
|
-
const encryptionCodec_1 = require("./encryptionCodec");
|
|
1
|
+
import { EncryptionCodec } from "./encryptionCodec.js";
|
|
2
|
+
import { EnvService } from "@diia-inhouse/env";
|
|
3
|
+
import { DurationMs } from "@diia-inhouse/types";
|
|
4
|
+
//#region src/encryption/dataConverter.ts
|
|
7
5
|
let dataConverterPromise;
|
|
8
|
-
const defaultRefreshInterval =
|
|
6
|
+
const defaultRefreshInterval = DurationMs.Day;
|
|
9
7
|
async function getDataConverter(keyId, envService, refreshInterval) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return await dataConverterPromise;
|
|
8
|
+
if (!dataConverterPromise) dataConverterPromise = createDataConverter(keyId, envService, refreshInterval);
|
|
9
|
+
return await dataConverterPromise;
|
|
14
10
|
}
|
|
15
11
|
async function createDataConverter(keyId, envService, refreshInterval = defaultRefreshInterval) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
payloadCodecs: [codec],
|
|
25
|
-
};
|
|
12
|
+
const vaultEnabled = EnvService.getVar("VAULT_ENABLED", "boolean", false);
|
|
13
|
+
const codec = await EncryptionCodec.create(keyId, envService, { vaultEnabled });
|
|
14
|
+
if (vaultEnabled && refreshInterval > 0) setInterval(async () => {
|
|
15
|
+
await codec?.refreshDefaultKey();
|
|
16
|
+
}, refreshInterval);
|
|
17
|
+
return { payloadCodecs: [codec] };
|
|
26
18
|
}
|
|
27
|
-
//#
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getDataConverter };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EnvService } from "@diia-inhouse/env";
|
|
2
|
+
import { Logger } from "@diia-inhouse/types";
|
|
3
|
+
import { webcrypto } from "node:crypto";
|
|
4
|
+
import { Payload, PayloadCodec } from "@temporalio/common";
|
|
5
|
+
|
|
6
|
+
//#region src/encryption/encryptionCodec.d.ts
|
|
7
|
+
declare class EncryptionCodec implements PayloadCodec {
|
|
8
|
+
private readonly keys;
|
|
9
|
+
private defaultKeyId;
|
|
10
|
+
private readonly envService;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly batchSize;
|
|
13
|
+
private readonly encoding;
|
|
14
|
+
private readonly metadataEncryptionKeyId;
|
|
15
|
+
constructor(keys: Map<string, webcrypto.CryptoKey>, defaultKeyId: string, envService: EnvService, logger: Logger, options?: {
|
|
16
|
+
batchSize?: number;
|
|
17
|
+
vaultEnabled?: boolean;
|
|
18
|
+
});
|
|
19
|
+
static create(keyId: string, envService: EnvService, options: {
|
|
20
|
+
batchSize?: number;
|
|
21
|
+
vaultEnabled?: boolean;
|
|
22
|
+
}, logger?: Logger): Promise<EncryptionCodec>;
|
|
23
|
+
private static createCryptoKey;
|
|
24
|
+
refreshDefaultKey(): Promise<void>;
|
|
25
|
+
encode(payloads: Payload[]): Promise<Payload[]>;
|
|
26
|
+
decode(payloads: Payload[]): Promise<Payload[]>;
|
|
27
|
+
private processBatch;
|
|
28
|
+
private splitKeyId;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { EncryptionCodec };
|