@autofleet/rabbit 3.0.1-alpha5 → 3.0.1-alpha7
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/index.d.ts +2 -1
- package/dist/index.js +8 -5
- package/dist/lib/consts.d.ts +2 -0
- package/dist/lib/consts.js +3 -1
- package/package.json +1 -1
- package/src/index.ts +9 -5
- package/src/lib/consts.ts +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
import { AmqpConnectionManager, ChannelWrapper } from 'amqp-connection-manager';
|
|
4
4
|
import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
|
|
5
5
|
import { RedisConfig } from './lib/redis';
|
|
6
|
-
import { TRACING_HEADER } from './lib/consts';
|
|
6
|
+
import { TRACING_HEADER, USER_TRACING_HEADER } from './lib/consts';
|
|
7
7
|
import { CallbackFunction, ConsumeMessageOrNull, ConsumeOptions, CustomMessageHeaders, QueuesCache, RedisLockType, ExchangesCache } from './lib/types';
|
|
8
8
|
export interface IAfRabbitMq {
|
|
9
9
|
ack: any;
|
|
@@ -44,6 +44,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
44
44
|
static getPublishOptions(customHeaders?: CustomMessageHeaders): {
|
|
45
45
|
timestamp: number;
|
|
46
46
|
headers: {
|
|
47
|
+
"x-af-user-id": any;
|
|
47
48
|
"x-trace-id": any;
|
|
48
49
|
redisTimestampValidationKey?: string | undefined;
|
|
49
50
|
creationTimestamp: number;
|
package/dist/index.js
CHANGED
|
@@ -125,14 +125,13 @@ class RabbitMq {
|
|
|
125
125
|
}
|
|
126
126
|
static getPublishOptions(customHeaders = {}) {
|
|
127
127
|
const trace = zehut_1.getCurrentPayload();
|
|
128
|
-
|
|
129
|
-
trace,
|
|
130
|
-
});
|
|
128
|
+
const user = trace?.context?.get(consts_1.USER_OBJECT);
|
|
131
129
|
return {
|
|
132
130
|
timestamp: moment_1.default().unix(),
|
|
133
131
|
headers: {
|
|
134
132
|
creationTimestamp: moment_1.default().valueOf(),
|
|
135
133
|
...customHeaders,
|
|
134
|
+
[consts_1.USER_TRACING_HEADER]: user?.id,
|
|
136
135
|
[consts_1.TRACING_HEADER]: trace?.context?.get(consts_1.TRACING_HEADER),
|
|
137
136
|
},
|
|
138
137
|
};
|
|
@@ -338,11 +337,15 @@ class RabbitMq {
|
|
|
338
337
|
return null;
|
|
339
338
|
}
|
|
340
339
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
340
|
+
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
341
341
|
if (traceId) {
|
|
342
342
|
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
343
343
|
trace?.context?.set(consts_1.TRACING_HEADER, traceId);
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
}
|
|
345
|
+
else if (userId) {
|
|
346
|
+
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
347
|
+
trace?.context?.set(consts_1.USER_OBJECT, {
|
|
348
|
+
id: userId,
|
|
346
349
|
});
|
|
347
350
|
}
|
|
348
351
|
if (auditContext) {
|
package/dist/lib/consts.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export declare const DEFAULT_DEAD_TTL_TWO_DAYS: number;
|
|
|
2
2
|
export declare const DEFAULT_LOCK_TIMEOUT: number;
|
|
3
3
|
export declare const RETRY_HEADER = "x-retry-count";
|
|
4
4
|
export declare const TRACING_HEADER = "x-trace-id";
|
|
5
|
+
export declare const USER_TRACING_HEADER = "x-af-user-id";
|
|
6
|
+
export declare const USER_OBJECT = "userObject";
|
|
5
7
|
export declare const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
6
8
|
export declare const CONNECTION_CREATED_CONST = "connectionCreated";
|
|
7
9
|
export declare const DEFAULT_OPTIONS: {
|
package/dist/lib/consts.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_OPTIONS = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
|
|
3
|
+
exports.DEFAULT_OPTIONS = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.USER_OBJECT = exports.USER_TRACING_HEADER = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
|
|
4
4
|
exports.DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 12;
|
|
5
5
|
exports.DEFAULT_LOCK_TIMEOUT = 1000 * 5;
|
|
6
6
|
exports.RETRY_HEADER = 'x-retry-count';
|
|
7
7
|
exports.TRACING_HEADER = 'x-trace-id';
|
|
8
|
+
exports.USER_TRACING_HEADER = 'x-af-user-id';
|
|
9
|
+
exports.USER_OBJECT = 'userObject';
|
|
8
10
|
exports.DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
9
11
|
exports.CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
10
12
|
exports.DEFAULT_OPTIONS = {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
DEFAULT_OPTIONS,
|
|
20
20
|
RETRY_HEADER,
|
|
21
21
|
TRACING_HEADER,
|
|
22
|
+
USER_OBJECT,
|
|
23
|
+
USER_TRACING_HEADER,
|
|
22
24
|
} from './lib/consts';
|
|
23
25
|
import {
|
|
24
26
|
CallbackFunction,
|
|
@@ -109,14 +111,13 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
109
111
|
|
|
110
112
|
static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
|
|
111
113
|
const trace = getCurrentPayload();
|
|
112
|
-
|
|
113
|
-
trace,
|
|
114
|
-
});
|
|
114
|
+
const user = trace?.context?.get(USER_OBJECT);
|
|
115
115
|
return {
|
|
116
116
|
timestamp: moment().unix(),
|
|
117
117
|
headers: {
|
|
118
118
|
creationTimestamp: moment().valueOf(),
|
|
119
119
|
...customHeaders,
|
|
120
|
+
[USER_TRACING_HEADER]: user?.id,
|
|
120
121
|
[TRACING_HEADER]: trace?.context?.get(TRACING_HEADER),
|
|
121
122
|
},
|
|
122
123
|
};
|
|
@@ -478,11 +479,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
478
479
|
}
|
|
479
480
|
|
|
480
481
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
482
|
+
const userId = msg.properties.headers[USER_TRACING_HEADER];
|
|
481
483
|
if (traceId) {
|
|
482
484
|
const trace = newTrace(traceTypes.RABBIT);
|
|
483
485
|
(trace as any)?.context?.set(TRACING_HEADER, traceId);
|
|
484
|
-
|
|
485
|
-
|
|
486
|
+
} else if (userId) {
|
|
487
|
+
const trace = newTrace(traceTypes.RABBIT);
|
|
488
|
+
(trace as any)?.context?.set(USER_OBJECT, {
|
|
489
|
+
id: userId,
|
|
486
490
|
});
|
|
487
491
|
}
|
|
488
492
|
|
package/src/lib/consts.ts
CHANGED
|
@@ -2,6 +2,8 @@ export const DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 12;
|
|
|
2
2
|
export const DEFAULT_LOCK_TIMEOUT = 1000 * 5;
|
|
3
3
|
export const RETRY_HEADER = 'x-retry-count';
|
|
4
4
|
export const TRACING_HEADER = 'x-trace-id';
|
|
5
|
+
export const USER_TRACING_HEADER = 'x-af-user-id';
|
|
6
|
+
export const USER_OBJECT = 'userObject';
|
|
5
7
|
export const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
6
8
|
export const CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
7
9
|
export const DEFAULT_OPTIONS = {
|