@forklaunch/interfaces-worker 1.0.3 → 1.0.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.
- package/lib/eject/domain/interfaces/decryptingWorker.consumer.ts +12 -3
- package/lib/eject/domain/interfaces/encryptingWorker.producer.ts +14 -10
- package/lib/eject/domain/types/eventEncryptor.types.ts +1 -0
- package/lib/eject/domain/types/workerEventEntity.types.ts +0 -1
- package/lib/interfaces/index.d.mts +7 -6
- package/lib/interfaces/index.d.ts +7 -6
- package/lib/interfaces/index.js +17 -6
- package/lib/interfaces/index.mjs +17 -6
- package/lib/types/index.d.mts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -59,7 +59,9 @@ export function withDecryptionFailureHandler<T extends WorkerEventEntity>(
|
|
|
59
59
|
handler: WorkerFailureHandler<T>,
|
|
60
60
|
encryptor: EventEncryptor
|
|
61
61
|
): WorkerFailureHandler<EncryptedEventEnvelope> {
|
|
62
|
-
return async (
|
|
62
|
+
return async (
|
|
63
|
+
results: WorkerProcessFailureResult<EncryptedEventEnvelope>[]
|
|
64
|
+
) => {
|
|
63
65
|
const decrypted = results.map((r) => ({
|
|
64
66
|
...r,
|
|
65
67
|
value: decryptEvent<T>(r.value, encryptor)
|
|
@@ -72,8 +74,15 @@ function decryptEvent<T extends WorkerEventEntity>(
|
|
|
72
74
|
envelope: EncryptedEventEnvelope,
|
|
73
75
|
encryptor: EventEncryptor
|
|
74
76
|
): T {
|
|
75
|
-
const {
|
|
76
|
-
|
|
77
|
+
const {
|
|
78
|
+
id,
|
|
79
|
+
tenantId,
|
|
80
|
+
retryCount,
|
|
81
|
+
processed,
|
|
82
|
+
createdAt,
|
|
83
|
+
updatedAt,
|
|
84
|
+
encryptedPayload
|
|
85
|
+
} = envelope;
|
|
77
86
|
|
|
78
87
|
const decrypted = encryptor.decrypt(encryptedPayload, tenantId);
|
|
79
88
|
const payload = JSON.parse(decrypted!);
|
|
@@ -7,37 +7,41 @@ import type { WorkerProducer } from './worker.producer.interface';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Wraps any WorkerProducer to encrypt the entire event payload before enqueueing.
|
|
10
|
-
* Base WorkerEventEntity fields (id,
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Base WorkerEventEntity fields (id, retryCount, processed, createdAt, updatedAt)
|
|
11
|
+
* are preserved in the clear for queue infrastructure. All remaining fields are
|
|
12
|
+
* JSON-serialized and encrypted into a single `encryptedPayload` field.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* tenantId is injected at construction (from request scope context) and stored
|
|
15
|
+
* on the envelope for key derivation during decryption.
|
|
16
16
|
*/
|
|
17
17
|
export class EncryptingWorkerProducer<T extends WorkerEventEntity>
|
|
18
18
|
implements WorkerProducer<T>
|
|
19
19
|
{
|
|
20
20
|
constructor(
|
|
21
21
|
private readonly inner: WorkerProducer<EncryptedEventEnvelope>,
|
|
22
|
-
private readonly encryptor: EventEncryptor
|
|
22
|
+
private readonly encryptor: EventEncryptor,
|
|
23
|
+
private readonly tenantId: string
|
|
23
24
|
) {}
|
|
24
25
|
|
|
25
26
|
async enqueueJob(job: T): Promise<void> {
|
|
26
|
-
await this.inner.enqueueJob(
|
|
27
|
+
await this.inner.enqueueJob(
|
|
28
|
+
encryptEvent(job, this.encryptor, this.tenantId)
|
|
29
|
+
);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
async enqueueBatchJobs(jobs: T[]): Promise<void> {
|
|
30
33
|
await this.inner.enqueueBatchJobs(
|
|
31
|
-
jobs.map((job) => encryptEvent(job, this.encryptor))
|
|
34
|
+
jobs.map((job) => encryptEvent(job, this.encryptor, this.tenantId))
|
|
32
35
|
);
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
function encryptEvent<T extends WorkerEventEntity>(
|
|
37
40
|
event: T,
|
|
38
|
-
encryptor: EventEncryptor
|
|
41
|
+
encryptor: EventEncryptor,
|
|
42
|
+
tenantId: string
|
|
39
43
|
): EncryptedEventEnvelope {
|
|
40
|
-
const { id,
|
|
44
|
+
const { id, retryCount, processed, createdAt, updatedAt, ...payload } =
|
|
41
45
|
event as WorkerEventEntity & Record<string, unknown>;
|
|
42
46
|
|
|
43
47
|
return {
|
|
@@ -12,17 +12,18 @@ interface WorkerProducer<T> {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Wraps any WorkerProducer to encrypt the entire event payload before enqueueing.
|
|
15
|
-
* Base WorkerEventEntity fields (id,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Base WorkerEventEntity fields (id, retryCount, processed, createdAt, updatedAt)
|
|
16
|
+
* are preserved in the clear for queue infrastructure. All remaining fields are
|
|
17
|
+
* JSON-serialized and encrypted into a single `encryptedPayload` field.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* tenantId is injected at construction (from request scope context) and stored
|
|
20
|
+
* on the envelope for key derivation during decryption.
|
|
21
21
|
*/
|
|
22
22
|
declare class EncryptingWorkerProducer<T extends WorkerEventEntity> implements WorkerProducer<T> {
|
|
23
23
|
private readonly inner;
|
|
24
24
|
private readonly encryptor;
|
|
25
|
-
|
|
25
|
+
private readonly tenantId;
|
|
26
|
+
constructor(inner: WorkerProducer<EncryptedEventEnvelope>, encryptor: EventEncryptor, tenantId: string);
|
|
26
27
|
enqueueJob(job: T): Promise<void>;
|
|
27
28
|
enqueueBatchJobs(jobs: T[]): Promise<void>;
|
|
28
29
|
}
|
|
@@ -12,17 +12,18 @@ interface WorkerProducer<T> {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Wraps any WorkerProducer to encrypt the entire event payload before enqueueing.
|
|
15
|
-
* Base WorkerEventEntity fields (id,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Base WorkerEventEntity fields (id, retryCount, processed, createdAt, updatedAt)
|
|
16
|
+
* are preserved in the clear for queue infrastructure. All remaining fields are
|
|
17
|
+
* JSON-serialized and encrypted into a single `encryptedPayload` field.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* tenantId is injected at construction (from request scope context) and stored
|
|
20
|
+
* on the envelope for key derivation during decryption.
|
|
21
21
|
*/
|
|
22
22
|
declare class EncryptingWorkerProducer<T extends WorkerEventEntity> implements WorkerProducer<T> {
|
|
23
23
|
private readonly inner;
|
|
24
24
|
private readonly encryptor;
|
|
25
|
-
|
|
25
|
+
private readonly tenantId;
|
|
26
|
+
constructor(inner: WorkerProducer<EncryptedEventEnvelope>, encryptor: EventEncryptor, tenantId: string);
|
|
26
27
|
enqueueJob(job: T): Promise<void>;
|
|
27
28
|
enqueueBatchJobs(jobs: T[]): Promise<void>;
|
|
28
29
|
}
|
package/lib/interfaces/index.js
CHANGED
|
@@ -29,21 +29,24 @@ module.exports = __toCommonJS(interfaces_exports);
|
|
|
29
29
|
|
|
30
30
|
// interfaces/encryptingWorker.producer.ts
|
|
31
31
|
var EncryptingWorkerProducer = class {
|
|
32
|
-
constructor(inner, encryptor) {
|
|
32
|
+
constructor(inner, encryptor, tenantId) {
|
|
33
33
|
this.inner = inner;
|
|
34
34
|
this.encryptor = encryptor;
|
|
35
|
+
this.tenantId = tenantId;
|
|
35
36
|
}
|
|
36
37
|
async enqueueJob(job) {
|
|
37
|
-
await this.inner.enqueueJob(
|
|
38
|
+
await this.inner.enqueueJob(
|
|
39
|
+
encryptEvent(job, this.encryptor, this.tenantId)
|
|
40
|
+
);
|
|
38
41
|
}
|
|
39
42
|
async enqueueBatchJobs(jobs) {
|
|
40
43
|
await this.inner.enqueueBatchJobs(
|
|
41
|
-
jobs.map((job) => encryptEvent(job, this.encryptor))
|
|
44
|
+
jobs.map((job) => encryptEvent(job, this.encryptor, this.tenantId))
|
|
42
45
|
);
|
|
43
46
|
}
|
|
44
47
|
};
|
|
45
|
-
function encryptEvent(event, encryptor) {
|
|
46
|
-
const { id,
|
|
48
|
+
function encryptEvent(event, encryptor, tenantId) {
|
|
49
|
+
const { id, retryCount, processed, createdAt, updatedAt, ...payload } = event;
|
|
47
50
|
return {
|
|
48
51
|
id,
|
|
49
52
|
tenantId,
|
|
@@ -89,7 +92,15 @@ function withDecryptionFailureHandler(handler, encryptor) {
|
|
|
89
92
|
};
|
|
90
93
|
}
|
|
91
94
|
function decryptEvent(envelope, encryptor) {
|
|
92
|
-
const {
|
|
95
|
+
const {
|
|
96
|
+
id,
|
|
97
|
+
tenantId,
|
|
98
|
+
retryCount,
|
|
99
|
+
processed,
|
|
100
|
+
createdAt,
|
|
101
|
+
updatedAt,
|
|
102
|
+
encryptedPayload
|
|
103
|
+
} = envelope;
|
|
93
104
|
const decrypted = encryptor.decrypt(encryptedPayload, tenantId);
|
|
94
105
|
const payload = JSON.parse(decrypted);
|
|
95
106
|
return {
|
package/lib/interfaces/index.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// interfaces/encryptingWorker.producer.ts
|
|
2
2
|
var EncryptingWorkerProducer = class {
|
|
3
|
-
constructor(inner, encryptor) {
|
|
3
|
+
constructor(inner, encryptor, tenantId) {
|
|
4
4
|
this.inner = inner;
|
|
5
5
|
this.encryptor = encryptor;
|
|
6
|
+
this.tenantId = tenantId;
|
|
6
7
|
}
|
|
7
8
|
async enqueueJob(job) {
|
|
8
|
-
await this.inner.enqueueJob(
|
|
9
|
+
await this.inner.enqueueJob(
|
|
10
|
+
encryptEvent(job, this.encryptor, this.tenantId)
|
|
11
|
+
);
|
|
9
12
|
}
|
|
10
13
|
async enqueueBatchJobs(jobs) {
|
|
11
14
|
await this.inner.enqueueBatchJobs(
|
|
12
|
-
jobs.map((job) => encryptEvent(job, this.encryptor))
|
|
15
|
+
jobs.map((job) => encryptEvent(job, this.encryptor, this.tenantId))
|
|
13
16
|
);
|
|
14
17
|
}
|
|
15
18
|
};
|
|
16
|
-
function encryptEvent(event, encryptor) {
|
|
17
|
-
const { id,
|
|
19
|
+
function encryptEvent(event, encryptor, tenantId) {
|
|
20
|
+
const { id, retryCount, processed, createdAt, updatedAt, ...payload } = event;
|
|
18
21
|
return {
|
|
19
22
|
id,
|
|
20
23
|
tenantId,
|
|
@@ -60,7 +63,15 @@ function withDecryptionFailureHandler(handler, encryptor) {
|
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
65
|
function decryptEvent(envelope, encryptor) {
|
|
63
|
-
const {
|
|
66
|
+
const {
|
|
67
|
+
id,
|
|
68
|
+
tenantId,
|
|
69
|
+
retryCount,
|
|
70
|
+
processed,
|
|
71
|
+
createdAt,
|
|
72
|
+
updatedAt,
|
|
73
|
+
encryptedPayload
|
|
74
|
+
} = envelope;
|
|
64
75
|
const decrypted = encryptor.decrypt(encryptedPayload, tenantId);
|
|
65
76
|
const payload = JSON.parse(decrypted);
|
|
66
77
|
return {
|
package/lib/types/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
type WorkerEventEntity = {
|
|
2
2
|
id: string;
|
|
3
|
-
tenantId: string;
|
|
4
3
|
retryCount: number;
|
|
5
4
|
processed: boolean;
|
|
6
5
|
createdAt: Date;
|
|
@@ -22,6 +21,7 @@ interface EventEncryptor {
|
|
|
22
21
|
* payload fields are serialized and encrypted into `encryptedPayload`.
|
|
23
22
|
*/
|
|
24
23
|
type EncryptedEventEnvelope = WorkerEventEntity & {
|
|
24
|
+
tenantId: string;
|
|
25
25
|
encryptedPayload: string;
|
|
26
26
|
};
|
|
27
27
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
type WorkerEventEntity = {
|
|
2
2
|
id: string;
|
|
3
|
-
tenantId: string;
|
|
4
3
|
retryCount: number;
|
|
5
4
|
processed: boolean;
|
|
6
5
|
createdAt: Date;
|
|
@@ -22,6 +21,7 @@ interface EventEncryptor {
|
|
|
22
21
|
* payload fields are serialized and encrypted into `encryptedPayload`.
|
|
23
22
|
*/
|
|
24
23
|
type EncryptedEventEnvelope = WorkerEventEntity & {
|
|
24
|
+
tenantId: string;
|
|
25
25
|
encryptedPayload: string;
|
|
26
26
|
};
|
|
27
27
|
|