@autofleet/rabbit 3.0.1-alpha6 → 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 -7
- 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 -7
- 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,16 +125,13 @@ class RabbitMq {
|
|
|
125
125
|
}
|
|
126
126
|
static getPublishOptions(customHeaders = {}) {
|
|
127
127
|
const trace = zehut_1.getCurrentPayload();
|
|
128
|
-
|
|
129
|
-
trace,
|
|
130
|
-
context1: trace?.context?.get(consts_1.TRACING_HEADER),
|
|
131
|
-
context2: trace?.context?.get('userObject'),
|
|
132
|
-
});
|
|
128
|
+
const user = trace?.context?.get(consts_1.USER_OBJECT);
|
|
133
129
|
return {
|
|
134
130
|
timestamp: moment_1.default().unix(),
|
|
135
131
|
headers: {
|
|
136
132
|
creationTimestamp: moment_1.default().valueOf(),
|
|
137
133
|
...customHeaders,
|
|
134
|
+
[consts_1.USER_TRACING_HEADER]: user?.id,
|
|
138
135
|
[consts_1.TRACING_HEADER]: trace?.context?.get(consts_1.TRACING_HEADER),
|
|
139
136
|
},
|
|
140
137
|
};
|
|
@@ -340,11 +337,15 @@ class RabbitMq {
|
|
|
340
337
|
return null;
|
|
341
338
|
}
|
|
342
339
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
340
|
+
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
343
341
|
if (traceId) {
|
|
344
342
|
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
345
343
|
trace?.context?.set(consts_1.TRACING_HEADER, traceId);
|
|
346
|
-
|
|
347
|
-
|
|
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,
|
|
348
349
|
});
|
|
349
350
|
}
|
|
350
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,16 +111,13 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
109
111
|
|
|
110
112
|
static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
|
|
111
113
|
const trace = getCurrentPayload();
|
|
112
|
-
|
|
113
|
-
trace,
|
|
114
|
-
context1: trace?.context?.get(TRACING_HEADER),
|
|
115
|
-
context2: trace?.context?.get('userObject'),
|
|
116
|
-
});
|
|
114
|
+
const user = trace?.context?.get(USER_OBJECT);
|
|
117
115
|
return {
|
|
118
116
|
timestamp: moment().unix(),
|
|
119
117
|
headers: {
|
|
120
118
|
creationTimestamp: moment().valueOf(),
|
|
121
119
|
...customHeaders,
|
|
120
|
+
[USER_TRACING_HEADER]: user?.id,
|
|
122
121
|
[TRACING_HEADER]: trace?.context?.get(TRACING_HEADER),
|
|
123
122
|
},
|
|
124
123
|
};
|
|
@@ -480,11 +479,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
480
479
|
}
|
|
481
480
|
|
|
482
481
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
482
|
+
const userId = msg.properties.headers[USER_TRACING_HEADER];
|
|
483
483
|
if (traceId) {
|
|
484
484
|
const trace = newTrace(traceTypes.RABBIT);
|
|
485
485
|
(trace as any)?.context?.set(TRACING_HEADER, traceId);
|
|
486
|
-
|
|
487
|
-
|
|
486
|
+
} else if (userId) {
|
|
487
|
+
const trace = newTrace(traceTypes.RABBIT);
|
|
488
|
+
(trace as any)?.context?.set(USER_OBJECT, {
|
|
489
|
+
id: userId,
|
|
488
490
|
});
|
|
489
491
|
}
|
|
490
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 = {
|