perimeterx-js-core 0.15.1 → 0.15.2
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/cjs/activities/HttpBatchedActivityClient.js +12 -5
- package/lib/cjs/phase/flow/EndEnforcerFlow.js +1 -5
- package/lib/cjs/phase/impl/SendLogsPhase.js +6 -5
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/esm/activities/HttpBatchedActivityClient.js +11 -4
- package/lib/esm/phase/flow/EndEnforcerFlow.js +1 -5
- package/lib/esm/phase/impl/SendLogsPhase.js +1 -1
- package/lib/esm/utils/constants.js +1 -1
- package/lib/types/activities/HttpBatchedActivityClient.d.ts +2 -1
- package/lib/types/utils/constants.d.ts +1 -1
- package/package.json +1 -1
|
@@ -61,10 +61,12 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
|
|
|
61
61
|
_this.batchSize = config.maxActivityBatchSize;
|
|
62
62
|
_this.timeoutMs = config.activityBatchTimeoutMs;
|
|
63
63
|
_this.maxBufferSize = _this.batchSize * 2;
|
|
64
|
+
_this.shouldKill = false;
|
|
64
65
|
_this.startTimer();
|
|
65
66
|
return _this;
|
|
66
67
|
}
|
|
67
68
|
HttpBatchedActivityClient.prototype.stop = function () {
|
|
69
|
+
this.shouldKill = true;
|
|
68
70
|
this.stopTimer();
|
|
69
71
|
};
|
|
70
72
|
HttpBatchedActivityClient.prototype.postActivities = function (activities) {
|
|
@@ -99,7 +101,9 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
|
|
|
99
101
|
_b.label = 2;
|
|
100
102
|
case 2:
|
|
101
103
|
sentSuccessfully = _a;
|
|
102
|
-
this.
|
|
104
|
+
if (!this.shouldKill) {
|
|
105
|
+
this.startTimer();
|
|
106
|
+
}
|
|
103
107
|
return [2 /*return*/, sentSuccessfully];
|
|
104
108
|
}
|
|
105
109
|
});
|
|
@@ -107,14 +111,17 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
|
|
|
107
111
|
};
|
|
108
112
|
HttpBatchedActivityClient.prototype.flush = function () {
|
|
109
113
|
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
-
var sentSuccessfully;
|
|
114
|
+
var bufferCopy, sentSuccessfully;
|
|
111
115
|
return __generator(this, function (_a) {
|
|
112
116
|
switch (_a.label) {
|
|
113
|
-
case 0:
|
|
117
|
+
case 0:
|
|
118
|
+
bufferCopy = this.buffer.concat();
|
|
119
|
+
this.clear();
|
|
120
|
+
return [4 /*yield*/, _super.prototype.postActivities.call(this, bufferCopy)];
|
|
114
121
|
case 1:
|
|
115
122
|
sentSuccessfully = _a.sent();
|
|
116
|
-
if (sentSuccessfully) {
|
|
117
|
-
this.
|
|
123
|
+
if (!sentSuccessfully) {
|
|
124
|
+
this.buffer = this.buffer.concat(bufferCopy);
|
|
118
125
|
}
|
|
119
126
|
return [2 /*return*/, sentSuccessfully];
|
|
120
127
|
}
|
|
@@ -21,11 +21,7 @@ var EndEnforcerFlow = /** @class */ (function (_super) {
|
|
|
21
21
|
__extends(EndEnforcerFlow, _super);
|
|
22
22
|
function EndEnforcerFlow(config, _a) {
|
|
23
23
|
var logServiceClient = _a.logServiceClient;
|
|
24
|
-
|
|
25
|
-
if (logServiceClient) {
|
|
26
|
-
phasesArray.push(new impl_1.SendLogsPhase(config, logServiceClient));
|
|
27
|
-
}
|
|
28
|
-
return _super.call(this, phasesArray) || this;
|
|
24
|
+
return _super.call(this, [new impl_1.SendLogsPhase(config, logServiceClient)]) || this;
|
|
29
25
|
}
|
|
30
26
|
return EndEnforcerFlow;
|
|
31
27
|
}(impl_1.CompositePhase));
|
|
@@ -43,15 +43,16 @@ var SendLogsPhase = /** @class */ (function () {
|
|
|
43
43
|
this.logServiceClient = logServiceClient;
|
|
44
44
|
}
|
|
45
45
|
SendLogsPhase.prototype.execute = function (context) {
|
|
46
|
+
var _a;
|
|
46
47
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
return __generator(this, function (
|
|
48
|
-
switch (
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
switch (_b.label) {
|
|
49
50
|
case 0:
|
|
50
51
|
if (!context.shouldSendLogs) return [3 /*break*/, 2];
|
|
51
|
-
return [4 /*yield*/, this.logServiceClient.sendLogs(context, this.config.logger.getLogs())];
|
|
52
|
+
return [4 /*yield*/, ((_a = this.logServiceClient) === null || _a === void 0 ? void 0 : _a.sendLogs(context, this.config.logger.getLogs()))];
|
|
52
53
|
case 1:
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
_b.sent();
|
|
55
|
+
_b.label = 2;
|
|
55
56
|
case 2:
|
|
56
57
|
this.config.logger.clearLogs();
|
|
57
58
|
return [2 /*return*/, { done: false }];
|
|
@@ -13,4 +13,4 @@ exports.PUSH_DATA_HMAC_HEADER_NAME = 'x-px-pushdata';
|
|
|
13
13
|
exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
14
14
|
exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
15
15
|
exports.URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
16
|
-
exports.CORE_MODULE_VERSION = 'JS Core 0.15.
|
|
16
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.15.2';
|
|
@@ -5,15 +5,18 @@ export class HttpBatchedActivityClient extends HttpActivityClient {
|
|
|
5
5
|
maxBufferSize;
|
|
6
6
|
buffer;
|
|
7
7
|
timeoutId;
|
|
8
|
+
shouldKill;
|
|
8
9
|
constructor(config, httpClient) {
|
|
9
10
|
super(config, httpClient);
|
|
10
11
|
this.buffer = [];
|
|
11
12
|
this.batchSize = config.maxActivityBatchSize;
|
|
12
13
|
this.timeoutMs = config.activityBatchTimeoutMs;
|
|
13
14
|
this.maxBufferSize = this.batchSize * 2;
|
|
15
|
+
this.shouldKill = false;
|
|
14
16
|
this.startTimer();
|
|
15
17
|
}
|
|
16
18
|
stop() {
|
|
19
|
+
this.shouldKill = true;
|
|
17
20
|
this.stopTimer();
|
|
18
21
|
}
|
|
19
22
|
async postActivities(activities) {
|
|
@@ -32,13 +35,17 @@ export class HttpBatchedActivityClient extends HttpActivityClient {
|
|
|
32
35
|
async triggerFlush() {
|
|
33
36
|
this.stopTimer();
|
|
34
37
|
const sentSuccessfully = this.buffer.length > 0 && (await this.flush());
|
|
35
|
-
this.
|
|
38
|
+
if (!this.shouldKill) {
|
|
39
|
+
this.startTimer();
|
|
40
|
+
}
|
|
36
41
|
return sentSuccessfully;
|
|
37
42
|
}
|
|
38
43
|
async flush() {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
const bufferCopy = this.buffer.concat();
|
|
45
|
+
this.clear();
|
|
46
|
+
const sentSuccessfully = await super.postActivities(bufferCopy);
|
|
47
|
+
if (!sentSuccessfully) {
|
|
48
|
+
this.buffer = this.buffer.concat(bufferCopy);
|
|
42
49
|
}
|
|
43
50
|
return sentSuccessfully;
|
|
44
51
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { CompositePhase, SendLogsPhase } from '../impl';
|
|
2
2
|
export class EndEnforcerFlow extends CompositePhase {
|
|
3
3
|
constructor(config, { logServiceClient }) {
|
|
4
|
-
|
|
5
|
-
if (logServiceClient) {
|
|
6
|
-
phasesArray.push(new SendLogsPhase(config, logServiceClient));
|
|
7
|
-
}
|
|
8
|
-
super(phasesArray);
|
|
4
|
+
super([new SendLogsPhase(config, logServiceClient)]);
|
|
9
5
|
}
|
|
10
6
|
}
|
|
@@ -7,7 +7,7 @@ export class SendLogsPhase {
|
|
|
7
7
|
}
|
|
8
8
|
async execute(context) {
|
|
9
9
|
if (context.shouldSendLogs) {
|
|
10
|
-
await this.logServiceClient
|
|
10
|
+
await this.logServiceClient?.sendLogs(context, this.config.logger.getLogs());
|
|
11
11
|
}
|
|
12
12
|
this.config.logger.clearLogs();
|
|
13
13
|
return { done: false };
|
|
@@ -10,4 +10,4 @@ export const PUSH_DATA_HMAC_HEADER_NAME = 'x-px-pushdata';
|
|
|
10
10
|
export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
11
11
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
12
12
|
export const URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
13
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.15.
|
|
13
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.15.2';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpActivityClient } from './HttpActivityClient';
|
|
2
2
|
import { IConfiguration } from '../config';
|
|
3
|
-
import { AsyncActivity } from './model
|
|
3
|
+
import { AsyncActivity } from './model';
|
|
4
4
|
import { IHttpClient } from '../http';
|
|
5
5
|
export declare class HttpBatchedActivityClient<Req, Res> extends HttpActivityClient<Req, Res> {
|
|
6
6
|
private readonly batchSize;
|
|
@@ -8,6 +8,7 @@ export declare class HttpBatchedActivityClient<Req, Res> extends HttpActivityCli
|
|
|
8
8
|
private readonly maxBufferSize;
|
|
9
9
|
private buffer;
|
|
10
10
|
private timeoutId;
|
|
11
|
+
private shouldKill;
|
|
11
12
|
constructor(config: IConfiguration<Req, Res>, httpClient: IHttpClient);
|
|
12
13
|
stop(): void;
|
|
13
14
|
protected postActivities(activities: AsyncActivity[]): Promise<boolean>;
|
|
@@ -10,4 +10,4 @@ export declare const PUSH_DATA_HMAC_HEADER_NAME = "x-px-pushdata";
|
|
|
10
10
|
export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
|
|
11
11
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
12
12
|
export declare const URL_REGEX: RegExp;
|
|
13
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.15.
|
|
13
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.15.2";
|