perimeterx-js-core 0.24.0 → 0.24.1
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/context/DefaultContext.js +2 -0
- package/lib/cjs/context/SerializedContext.js +1 -0
- package/lib/cjs/phase/flow/EndEnforcerFlow.js +4 -4
- package/lib/cjs/phase/flow/FilterFlow.js +1 -1
- package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +61 -0
- package/lib/cjs/phase/impl/RiskApiPhase.js +1 -0
- package/lib/cjs/phase/impl/{TelemetryPhase.js → SendTelemetryActivityPhase.js} +12 -13
- package/lib/cjs/phase/impl/index.js +2 -1
- package/lib/cjs/risk_api/client/PostRiskApiClientBase.js +5 -4
- package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +9 -0
- package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +1 -0
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/request_id_generator/SimpleRequestIdGenerator.js +13 -0
- package/lib/cjs/utils/request_id_generator/index.js +1 -0
- package/lib/esm/context/DefaultContext.js +3 -0
- package/lib/esm/context/SerializedContext.js +2 -0
- package/lib/esm/phase/flow/EndEnforcerFlow.js +3 -3
- package/lib/esm/phase/flow/FilterFlow.js +2 -2
- package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +13 -0
- package/lib/esm/phase/impl/RiskApiPhase.js +1 -0
- package/lib/esm/phase/impl/{TelemetryPhase.js → SendTelemetryActivityPhase.js} +3 -4
- package/lib/esm/phase/impl/index.js +2 -1
- package/lib/esm/risk_api/client/PostRiskApiClientBase.js +5 -4
- package/lib/esm/risk_api/risk_response/RiskResponseBase.js +4 -0
- package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +2 -0
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/request_id_generator/SimpleRequestIdGenerator.js +9 -0
- package/lib/esm/utils/request_id_generator/index.js +1 -0
- package/lib/types/config/ConfigurationBuilderBase.d.ts +1 -1
- package/lib/types/context/ContextJson.d.ts +1 -0
- package/lib/types/context/DefaultContext.d.ts +1 -0
- package/lib/types/context/SerializedContext.d.ts +1 -0
- package/lib/types/context/interfaces/IContext.d.ts +4 -0
- package/lib/types/phase/flow/EndEnforcerFlow.d.ts +3 -1
- package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +9 -0
- package/lib/types/phase/impl/{TelemetryPhase.d.ts → SendTelemetryActivityPhase.d.ts} +1 -1
- package/lib/types/phase/impl/index.d.ts +2 -1
- package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +1 -1
- package/lib/types/risk_api/risk_response/CommonRiskResponsePayload.d.ts +1 -0
- package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +1 -0
- package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
- package/lib/types/risk_api/risk_response/serialize/RiskResponseJson.d.ts +1 -0
- package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/request_id_generator/SimpleRequestIdGenerator.d.ts +6 -0
- package/lib/types/utils/request_id_generator/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -48,6 +48,7 @@ var DefaultContext = /** @class */ (function () {
|
|
|
48
48
|
if (!this.isMobile) {
|
|
49
49
|
this.setCookiesOnContext();
|
|
50
50
|
}
|
|
51
|
+
this.shouldSendTelemetry = false;
|
|
51
52
|
}
|
|
52
53
|
Object.defineProperty(DefaultContext.prototype, "isMobile", {
|
|
53
54
|
get: function () {
|
|
@@ -165,6 +166,7 @@ var DefaultContext = /** @class */ (function () {
|
|
|
165
166
|
enforcerStartTime: this.enforcerStartTime,
|
|
166
167
|
blockAction: this.blockAction,
|
|
167
168
|
pxdeVerified: this.pxdeVerified,
|
|
169
|
+
shouldSendTelemetry: this.shouldSendTelemetry,
|
|
168
170
|
logger: this.shouldSendLogs
|
|
169
171
|
? {
|
|
170
172
|
logs: this.logger.getLogs(),
|
|
@@ -43,6 +43,7 @@ var SerializedContext = /** @class */ (function () {
|
|
|
43
43
|
this.graphqlData = contextJson.graphqlData;
|
|
44
44
|
this.enforcerStartTime = contextJson.enforcerStartTime;
|
|
45
45
|
this.blockAction = contextJson.blockAction;
|
|
46
|
+
this.shouldSendTelemetry = contextJson.shouldSendTelemetry;
|
|
46
47
|
}
|
|
47
48
|
SerializedContext.prototype.createRequestData = function (_a, request, urlUtils) {
|
|
48
49
|
var requestData = _a.requestData;
|
|
@@ -17,16 +17,16 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.EndEnforcerFlow = void 0;
|
|
19
19
|
var impl_1 = require("../impl");
|
|
20
|
-
var
|
|
20
|
+
var impl_2 = require("../impl");
|
|
21
21
|
var EndEnforcerFlow = /** @class */ (function (_super) {
|
|
22
22
|
__extends(EndEnforcerFlow, _super);
|
|
23
23
|
function EndEnforcerFlow(config, _a) {
|
|
24
|
-
var logServiceClient = _a.logServiceClient;
|
|
25
|
-
var phases = [];
|
|
24
|
+
var logServiceClient = _a.logServiceClient, telemetry = _a.telemetry;
|
|
25
|
+
var phases = [new impl_2.SendTelemetryActivityPhase(telemetry)];
|
|
26
26
|
if (logServiceClient) {
|
|
27
27
|
phases.push(new impl_1.SendLogsPhase(config, logServiceClient));
|
|
28
28
|
}
|
|
29
|
-
phases.push(new
|
|
29
|
+
phases.push(new impl_2.ClearLogsPhase());
|
|
30
30
|
return _super.call(this, phases) || this;
|
|
31
31
|
}
|
|
32
32
|
return EndEnforcerFlow;
|
|
@@ -33,7 +33,7 @@ var FilterFlow = /** @class */ (function (_super) {
|
|
|
33
33
|
phases.push(new impl_1.FilterPhase(filterProducts));
|
|
34
34
|
}
|
|
35
35
|
phases.push(new impl_1.PreflightPhase(config, cors));
|
|
36
|
-
phases.push(new impl_1.
|
|
36
|
+
phases.push(new impl_1.IdentifyTelemetryRequestPhase(telemetry));
|
|
37
37
|
if (remoteConfigUpdater) {
|
|
38
38
|
var updateRemoteConfigPhase = new impl_1.UpdateRemoteConfigPhase(config, remoteConfigUpdater);
|
|
39
39
|
phases.push(updateRemoteConfigPhase);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.IdentifyTelemetryRequestPhase = void 0;
|
|
40
|
+
var IdentifyTelemetryRequestPhase = /** @class */ (function () {
|
|
41
|
+
function IdentifyTelemetryRequestPhase(telemetry) {
|
|
42
|
+
this.telemetry = telemetry;
|
|
43
|
+
}
|
|
44
|
+
IdentifyTelemetryRequestPhase.prototype.execute = function (context) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0: return [4 /*yield*/, this.telemetry.isValidTelemetryRequest(context)];
|
|
49
|
+
case 1:
|
|
50
|
+
if (_a.sent()) {
|
|
51
|
+
context.shouldSendTelemetry = true;
|
|
52
|
+
return [2 /*return*/, { done: true }];
|
|
53
|
+
}
|
|
54
|
+
return [2 /*return*/, { done: false }];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
return IdentifyTelemetryRequestPhase;
|
|
60
|
+
}());
|
|
61
|
+
exports.IdentifyTelemetryRequestPhase = IdentifyTelemetryRequestPhase;
|
|
@@ -36,29 +36,28 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
var
|
|
41
|
-
function
|
|
39
|
+
exports.SendTelemetryActivityPhase = void 0;
|
|
40
|
+
var SendTelemetryActivityPhase = /** @class */ (function () {
|
|
41
|
+
function SendTelemetryActivityPhase(telemetry) {
|
|
42
42
|
this.telemetry = telemetry;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
SendTelemetryActivityPhase.prototype.execute = function (context) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function () {
|
|
46
46
|
return __generator(this, function (_a) {
|
|
47
47
|
switch (_a.label) {
|
|
48
|
-
case 0:
|
|
48
|
+
case 0:
|
|
49
|
+
if (!context.shouldSendTelemetry) return [3 /*break*/, 2];
|
|
50
|
+
return [4 /*yield*/, this.telemetry.sendTelemetry(context)];
|
|
49
51
|
case 1:
|
|
50
|
-
if (!_a.sent()) return [3 /*break*/, 3];
|
|
51
|
-
return [4 /*yield*/, this.sendTelemetry(context)];
|
|
52
|
-
case 2:
|
|
53
52
|
_a.sent();
|
|
54
|
-
|
|
55
|
-
case
|
|
53
|
+
_a.label = 2;
|
|
54
|
+
case 2: return [2 /*return*/, { done: false }];
|
|
56
55
|
}
|
|
57
56
|
});
|
|
58
57
|
});
|
|
59
58
|
};
|
|
60
59
|
// Note: If await is not necessary, can be overridden
|
|
61
|
-
|
|
60
|
+
SendTelemetryActivityPhase.prototype.sendTelemetry = function (context) {
|
|
62
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
63
62
|
return __generator(this, function (_a) {
|
|
64
63
|
switch (_a.label) {
|
|
@@ -70,6 +69,6 @@ var TelemetryPhase = /** @class */ (function () {
|
|
|
70
69
|
});
|
|
71
70
|
});
|
|
72
71
|
};
|
|
73
|
-
return
|
|
72
|
+
return SendTelemetryActivityPhase;
|
|
74
73
|
}());
|
|
75
|
-
exports.
|
|
74
|
+
exports.SendTelemetryActivityPhase = SendTelemetryActivityPhase;
|
|
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./FirstPartyPhase"), exports);
|
|
18
18
|
__exportStar(require("./FilterPhase"), exports);
|
|
19
19
|
__exportStar(require("./PreflightPhase"), exports);
|
|
20
|
-
__exportStar(require("./TelemetryPhase"), exports);
|
|
21
20
|
__exportStar(require("./EnrichContextFromRequestPhase"), exports);
|
|
22
21
|
__exportStar(require("./ParseTokenPhase"), exports);
|
|
23
22
|
__exportStar(require("./DecideActionPhase"), exports);
|
|
@@ -33,3 +32,5 @@ __exportStar(require("./CompositePhase"), exports);
|
|
|
33
32
|
__exportStar(require("./SendLogsPhase"), exports);
|
|
34
33
|
__exportStar(require(".//UpdateRemoteConfigPhase"), exports);
|
|
35
34
|
__exportStar(require("./ClearLogsPhase"), exports);
|
|
35
|
+
__exportStar(require("./IdentifyTelemetryRequestPhase"), exports);
|
|
36
|
+
__exportStar(require("./SendTelemetryActivityPhase"), exports);
|
|
@@ -78,7 +78,7 @@ var PostRiskApiClientBase = /** @class */ (function () {
|
|
|
78
78
|
case 2:
|
|
79
79
|
response = _a.sent();
|
|
80
80
|
if (!((response === null || response === void 0 ? void 0 : response.status) !== 200)) return [3 /*break*/, 4];
|
|
81
|
-
return [4 /*yield*/, this.handleS2SError(riskApiData, response)];
|
|
81
|
+
return [4 /*yield*/, this.handleS2SError(riskApiData, context, response)];
|
|
82
82
|
case 3: return [2 /*return*/, _a.sent()];
|
|
83
83
|
case 4:
|
|
84
84
|
riskResponse = this.createRiskResponse(response);
|
|
@@ -86,7 +86,7 @@ var PostRiskApiClientBase = /** @class */ (function () {
|
|
|
86
86
|
return [4 /*yield*/, riskResponse.validate()];
|
|
87
87
|
case 5:
|
|
88
88
|
if (!!(_a.sent())) return [3 /*break*/, 7];
|
|
89
|
-
return [4 /*yield*/, this.handleS2SError(riskApiData, response)];
|
|
89
|
+
return [4 /*yield*/, this.handleS2SError(riskApiData, context, response)];
|
|
90
90
|
case 6: return [2 /*return*/, _a.sent()];
|
|
91
91
|
case 7:
|
|
92
92
|
context.logger.debug("received risk response, score: ".concat(riskResponse.score, ", rtt: ").concat(riskApiData.riskRtt));
|
|
@@ -97,7 +97,7 @@ var PostRiskApiClientBase = /** @class */ (function () {
|
|
|
97
97
|
return [2 /*return*/, this.handleS2STimeout(riskApiData)];
|
|
98
98
|
}
|
|
99
99
|
context.logger.error("caught error in risk api: ".concat(err_1, " - ").concat(JSON.stringify(context.requestData.url)));
|
|
100
|
-
return [4 /*yield*/, this.handleS2SError(riskApiData, response, err_1)];
|
|
100
|
+
return [4 /*yield*/, this.handleS2SError(riskApiData, context, response, err_1)];
|
|
101
101
|
case 9: return [2 /*return*/, _a.sent()];
|
|
102
102
|
case 10: return [2 /*return*/];
|
|
103
103
|
}
|
|
@@ -176,7 +176,7 @@ var PostRiskApiClientBase = /** @class */ (function () {
|
|
|
176
176
|
riskApiData.riskApiCallResult = model_1.RiskApiCallResult.TIMEOUT;
|
|
177
177
|
return riskApiData;
|
|
178
178
|
};
|
|
179
|
-
PostRiskApiClientBase.prototype.handleS2SError = function (riskApiData, response, error) {
|
|
179
|
+
PostRiskApiClientBase.prototype.handleS2SError = function (riskApiData, context, response, error) {
|
|
180
180
|
return __awaiter(this, void 0, void 0, function () {
|
|
181
181
|
var _a, _b, _c, errorMessage, existingMessage;
|
|
182
182
|
var _d, _e, _f;
|
|
@@ -222,6 +222,7 @@ var PostRiskApiClientBase = /** @class */ (function () {
|
|
|
222
222
|
existingMessage = riskApiData.errorMessage;
|
|
223
223
|
riskApiData.errorMessage = existingMessage ? "".concat(existingMessage, ", ").concat(errorMessage) : errorMessage;
|
|
224
224
|
}
|
|
225
|
+
context.logger.debug("S2S error message: ".concat(riskApiData.errorMessage));
|
|
225
226
|
return [2 /*return*/, riskApiData];
|
|
226
227
|
}
|
|
227
228
|
});
|
|
@@ -126,6 +126,14 @@ var RiskResponseBase = /** @class */ (function () {
|
|
|
126
126
|
enumerable: false,
|
|
127
127
|
configurable: true
|
|
128
128
|
});
|
|
129
|
+
Object.defineProperty(RiskResponseBase.prototype, "telemetryRequested", {
|
|
130
|
+
get: function () {
|
|
131
|
+
var _a;
|
|
132
|
+
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.telemetry_requested;
|
|
133
|
+
},
|
|
134
|
+
enumerable: false,
|
|
135
|
+
configurable: true
|
|
136
|
+
});
|
|
129
137
|
Object.defineProperty(RiskResponseBase.prototype, "drc", {
|
|
130
138
|
get: function () {
|
|
131
139
|
var _a;
|
|
@@ -145,6 +153,7 @@ var RiskResponseBase = /** @class */ (function () {
|
|
|
145
153
|
score: this.score,
|
|
146
154
|
drc: this.drc,
|
|
147
155
|
additionalRiskInfo: this.additionalRiskInfo,
|
|
156
|
+
telemetryRequested: this.telemetryRequested,
|
|
148
157
|
uuid: this.uuid,
|
|
149
158
|
};
|
|
150
159
|
};
|
|
@@ -5,6 +5,7 @@ var SerializedRiskResponse = /** @class */ (function () {
|
|
|
5
5
|
function SerializedRiskResponse(riskResponseJson) {
|
|
6
6
|
this.action = riskResponseJson.action;
|
|
7
7
|
this.additionalRiskInfo = riskResponseJson.additionalRiskInfo;
|
|
8
|
+
this.telemetryRequested = riskResponseJson.telemetryRequested;
|
|
8
9
|
this.dataEnrichment = riskResponseJson.dataEnrichment;
|
|
9
10
|
this.drc = riskResponseJson.drc;
|
|
10
11
|
this.message = riskResponseJson.message;
|
|
@@ -14,4 +14,4 @@ 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]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
16
16
|
exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
17
|
-
exports.CORE_MODULE_VERSION = 'JS Core 0.24.
|
|
17
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.24.1';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleRequestIdGenerator = void 0;
|
|
4
|
+
var SimpleRequestIdGenerator = /** @class */ (function () {
|
|
5
|
+
function SimpleRequestIdGenerator(requestId) {
|
|
6
|
+
this.requestId = requestId;
|
|
7
|
+
}
|
|
8
|
+
SimpleRequestIdGenerator.prototype.generateRequestId = function () {
|
|
9
|
+
return this.requestId;
|
|
10
|
+
};
|
|
11
|
+
return SimpleRequestIdGenerator;
|
|
12
|
+
}());
|
|
13
|
+
exports.SimpleRequestIdGenerator = SimpleRequestIdGenerator;
|
|
@@ -34,6 +34,7 @@ export class DefaultContext {
|
|
|
34
34
|
enforcerStartTime;
|
|
35
35
|
logger;
|
|
36
36
|
usedCookieSecret;
|
|
37
|
+
shouldSendTelemetry;
|
|
37
38
|
config;
|
|
38
39
|
urlUtils;
|
|
39
40
|
constructor(config, request, options) {
|
|
@@ -62,6 +63,7 @@ export class DefaultContext {
|
|
|
62
63
|
if (!this.isMobile) {
|
|
63
64
|
this.setCookiesOnContext();
|
|
64
65
|
}
|
|
66
|
+
this.shouldSendTelemetry = false;
|
|
65
67
|
}
|
|
66
68
|
get isMobile() {
|
|
67
69
|
return this.tokenOrigin === TokenOrigin.HEADER;
|
|
@@ -175,6 +177,7 @@ export class DefaultContext {
|
|
|
175
177
|
enforcerStartTime: this.enforcerStartTime,
|
|
176
178
|
blockAction: this.blockAction,
|
|
177
179
|
pxdeVerified: this.pxdeVerified,
|
|
180
|
+
shouldSendTelemetry: this.shouldSendTelemetry,
|
|
178
181
|
logger: this.shouldSendLogs
|
|
179
182
|
? {
|
|
180
183
|
logs: this.logger.getLogs(),
|
|
@@ -27,6 +27,7 @@ export class SerializedContext {
|
|
|
27
27
|
vidSource;
|
|
28
28
|
tokenOrigin;
|
|
29
29
|
uuid;
|
|
30
|
+
shouldSendTelemetry;
|
|
30
31
|
constructor(config, contextJson, request, urlUtils) {
|
|
31
32
|
this.action = contextJson.action;
|
|
32
33
|
this.reasons = contextJson.reasons;
|
|
@@ -53,6 +54,7 @@ export class SerializedContext {
|
|
|
53
54
|
this.graphqlData = contextJson.graphqlData;
|
|
54
55
|
this.enforcerStartTime = contextJson.enforcerStartTime;
|
|
55
56
|
this.blockAction = contextJson.blockAction;
|
|
57
|
+
this.shouldSendTelemetry = contextJson.shouldSendTelemetry;
|
|
56
58
|
}
|
|
57
59
|
createRequestData({ requestData }, request, urlUtils) {
|
|
58
60
|
return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CompositePhase, SendLogsPhase } from '../impl';
|
|
2
|
-
import { ClearLogsPhase } from '../impl
|
|
2
|
+
import { ClearLogsPhase, SendTelemetryActivityPhase } from '../impl';
|
|
3
3
|
export class EndEnforcerFlow extends CompositePhase {
|
|
4
|
-
constructor(config, { logServiceClient }) {
|
|
5
|
-
const phases = [];
|
|
4
|
+
constructor(config, { logServiceClient, telemetry, }) {
|
|
5
|
+
const phases = [new SendTelemetryActivityPhase(telemetry)];
|
|
6
6
|
if (logServiceClient) {
|
|
7
7
|
phases.push(new SendLogsPhase(config, logServiceClient));
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProductName } from '../../products';
|
|
2
2
|
import { isNullOrUndefined } from '../../utils';
|
|
3
|
-
import { CompositePhase, FilterPhase, FirstPartyPhase, PreflightPhase,
|
|
3
|
+
import { CompositePhase, FilterPhase, FirstPartyPhase, PreflightPhase, UpdateRemoteConfigPhase, IdentifyTelemetryRequestPhase, } from '../impl';
|
|
4
4
|
export class FilterFlow extends CompositePhase {
|
|
5
5
|
constructor(config, { httpClient, products, cors, telemetry, remoteConfigUpdater, }) {
|
|
6
6
|
const phases = [];
|
|
@@ -13,7 +13,7 @@ export class FilterFlow extends CompositePhase {
|
|
|
13
13
|
phases.push(new FilterPhase(filterProducts));
|
|
14
14
|
}
|
|
15
15
|
phases.push(new PreflightPhase(config, cors));
|
|
16
|
-
phases.push(new
|
|
16
|
+
phases.push(new IdentifyTelemetryRequestPhase(telemetry));
|
|
17
17
|
if (remoteConfigUpdater) {
|
|
18
18
|
const updateRemoteConfigPhase = new UpdateRemoteConfigPhase(config, remoteConfigUpdater);
|
|
19
19
|
phases.push(updateRemoteConfigPhase);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class IdentifyTelemetryRequestPhase {
|
|
2
|
+
telemetry;
|
|
3
|
+
constructor(telemetry) {
|
|
4
|
+
this.telemetry = telemetry;
|
|
5
|
+
}
|
|
6
|
+
async execute(context) {
|
|
7
|
+
if (await this.telemetry.isValidTelemetryRequest(context)) {
|
|
8
|
+
context.shouldSendTelemetry = true;
|
|
9
|
+
return { done: true };
|
|
10
|
+
}
|
|
11
|
+
return { done: false };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class SendTelemetryActivityPhase {
|
|
2
2
|
telemetry;
|
|
3
3
|
constructor(telemetry) {
|
|
4
4
|
this.telemetry = telemetry;
|
|
5
5
|
}
|
|
6
6
|
async execute(context) {
|
|
7
|
-
if (
|
|
8
|
-
await this.sendTelemetry(context);
|
|
9
|
-
return { done: true };
|
|
7
|
+
if (context.shouldSendTelemetry) {
|
|
8
|
+
await this.telemetry.sendTelemetry(context);
|
|
10
9
|
}
|
|
11
10
|
return { done: false };
|
|
12
11
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './FirstPartyPhase';
|
|
2
2
|
export * from './FilterPhase';
|
|
3
3
|
export * from './PreflightPhase';
|
|
4
|
-
export * from './TelemetryPhase';
|
|
5
4
|
export * from './EnrichContextFromRequestPhase';
|
|
6
5
|
export * from './ParseTokenPhase';
|
|
7
6
|
export * from './DecideActionPhase';
|
|
@@ -17,3 +16,5 @@ export * from './CompositePhase';
|
|
|
17
16
|
export * from './SendLogsPhase';
|
|
18
17
|
export * from './/UpdateRemoteConfigPhase';
|
|
19
18
|
export * from './ClearLogsPhase';
|
|
19
|
+
export * from './IdentifyTelemetryRequestPhase';
|
|
20
|
+
export * from './SendTelemetryActivityPhase';
|
|
@@ -23,12 +23,12 @@ export class PostRiskApiClientBase {
|
|
|
23
23
|
const riskActivity = this.createRiskActivity(context);
|
|
24
24
|
response = await this.sendRiskActivity(riskActivity, riskApiData, context);
|
|
25
25
|
if (response?.status !== 200) {
|
|
26
|
-
return await this.handleS2SError(riskApiData, response);
|
|
26
|
+
return await this.handleS2SError(riskApiData, context, response);
|
|
27
27
|
}
|
|
28
28
|
riskResponse = this.createRiskResponse(response);
|
|
29
29
|
riskApiData.riskResponse = riskResponse;
|
|
30
30
|
if (!(await riskResponse.validate())) {
|
|
31
|
-
return await this.handleS2SError(riskApiData, response);
|
|
31
|
+
return await this.handleS2SError(riskApiData, context, response);
|
|
32
32
|
}
|
|
33
33
|
context.logger.debug(`received risk response, score: ${riskResponse.score}, rtt: ${riskApiData.riskRtt}`);
|
|
34
34
|
return riskApiData;
|
|
@@ -38,7 +38,7 @@ export class PostRiskApiClientBase {
|
|
|
38
38
|
return this.handleS2STimeout(riskApiData);
|
|
39
39
|
}
|
|
40
40
|
context.logger.error(`caught error in risk api: ${err} - ${JSON.stringify(context.requestData.url)}`);
|
|
41
|
-
return await this.handleS2SError(riskApiData, response, err);
|
|
41
|
+
return await this.handleS2SError(riskApiData, context, response, err);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -105,7 +105,7 @@ export class PostRiskApiClientBase {
|
|
|
105
105
|
riskApiData.riskApiCallResult = RiskApiCallResult.TIMEOUT;
|
|
106
106
|
return riskApiData;
|
|
107
107
|
}
|
|
108
|
-
async handleS2SError(riskApiData, response, error) {
|
|
108
|
+
async handleS2SError(riskApiData, context, response, error) {
|
|
109
109
|
riskApiData.riskApiCallResult = RiskApiCallResult.ERROR;
|
|
110
110
|
riskApiData.errorReason = S2SErrorReason.UNKNOWN_ERROR;
|
|
111
111
|
if (response) {
|
|
@@ -131,6 +131,7 @@ export class PostRiskApiClientBase {
|
|
|
131
131
|
const existingMessage = riskApiData.errorMessage;
|
|
132
132
|
riskApiData.errorMessage = existingMessage ? `${existingMessage}, ${errorMessage}` : errorMessage;
|
|
133
133
|
}
|
|
134
|
+
context.logger.debug(`S2S error message: ${riskApiData.errorMessage}`);
|
|
134
135
|
return riskApiData;
|
|
135
136
|
}
|
|
136
137
|
}
|
|
@@ -38,6 +38,9 @@ export class RiskResponseBase {
|
|
|
38
38
|
get additionalRiskInfo() {
|
|
39
39
|
return this.riskResponse?.additional_risk_info;
|
|
40
40
|
}
|
|
41
|
+
get telemetryRequested() {
|
|
42
|
+
return this.riskResponse?.telemetry_requested;
|
|
43
|
+
}
|
|
41
44
|
get drc() {
|
|
42
45
|
return this.riskResponse?.drc;
|
|
43
46
|
}
|
|
@@ -52,6 +55,7 @@ export class RiskResponseBase {
|
|
|
52
55
|
score: this.score,
|
|
53
56
|
drc: this.drc,
|
|
54
57
|
additionalRiskInfo: this.additionalRiskInfo,
|
|
58
|
+
telemetryRequested: this.telemetryRequested,
|
|
55
59
|
uuid: this.uuid,
|
|
56
60
|
};
|
|
57
61
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export class SerializedRiskResponse {
|
|
2
2
|
action;
|
|
3
3
|
additionalRiskInfo;
|
|
4
|
+
telemetryRequested;
|
|
4
5
|
dataEnrichment;
|
|
5
6
|
drc;
|
|
6
7
|
message;
|
|
@@ -12,6 +13,7 @@ export class SerializedRiskResponse {
|
|
|
12
13
|
constructor(riskResponseJson) {
|
|
13
14
|
this.action = riskResponseJson.action;
|
|
14
15
|
this.additionalRiskInfo = riskResponseJson.additionalRiskInfo;
|
|
16
|
+
this.telemetryRequested = riskResponseJson.telemetryRequested;
|
|
15
17
|
this.dataEnrichment = riskResponseJson.dataEnrichment;
|
|
16
18
|
this.drc = riskResponseJson.drc;
|
|
17
19
|
this.message = riskResponseJson.message;
|
|
@@ -11,4 +11,4 @@ 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]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
13
13
|
export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
14
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.24.
|
|
14
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.24.1';
|
|
@@ -4,7 +4,7 @@ import { CoreConfigurationParams, StaticConfigurationParams, RemoteConfiguration
|
|
|
4
4
|
import { IBase64Utils } from '../utils';
|
|
5
5
|
export declare abstract class ConfigurationBuilderBase<Req, Res, Added, Removed, ParamsType extends CoreConfigurationParams<Req, Res, Added, Removed>, ConfigurationType extends IConfiguration<Req, Res, Added, Removed>> {
|
|
6
6
|
protected readonly base64Utils: IBase64Utils;
|
|
7
|
-
protected abstract createRemoteConfigStorageClient(staticConfig: ConfigurationType): Promise<IRemoteConfigStorageClient<Req, Res, Added, Removed
|
|
7
|
+
protected abstract createRemoteConfigStorageClient(staticConfig: ConfigurationType): Promise<IRemoteConfigStorageClient<Req, Res, Added, Removed> | null>;
|
|
8
8
|
protected abstract createConfiguration(params: ParamsType | StaticConfigurationParams<Req, Res, Added, Removed>): ConfigurationType;
|
|
9
9
|
protected constructor(base64Utils: IBase64Utils);
|
|
10
10
|
build(params: StaticConfigurationParams<Req, Res, Added, Removed>): Promise<ConfigurationType>;
|
|
@@ -44,6 +44,7 @@ export declare class DefaultContext<Req, Res, Added, Removed> implements IContex
|
|
|
44
44
|
enforcerStartTime?: number;
|
|
45
45
|
logger: ILogger;
|
|
46
46
|
usedCookieSecret?: string;
|
|
47
|
+
shouldSendTelemetry: boolean;
|
|
47
48
|
protected readonly config: IConfiguration<Req, Res, Added, Removed>;
|
|
48
49
|
protected readonly urlUtils: IUrlUtils;
|
|
49
50
|
constructor(config: IConfiguration<Req, Res, Added, Removed>, request: IIncomingRequest<Req>, options: DefaultContextOptions);
|
|
@@ -38,6 +38,7 @@ export declare class SerializedContext<Req, Res, Added, Removed> implements ICon
|
|
|
38
38
|
vidSource?: VidSource;
|
|
39
39
|
tokenOrigin: TokenOrigin;
|
|
40
40
|
uuid?: string;
|
|
41
|
+
shouldSendTelemetry: boolean;
|
|
41
42
|
constructor(config: IConfiguration<Req, Res, Added, Removed>, contextJson: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils);
|
|
42
43
|
protected createRequestData({ requestData }: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils): RequestData<Req>;
|
|
43
44
|
protected createTokenData({ tokenData }: ContextJson<Req, Res>, config: IConfiguration<Req, Res, Added, Removed>): TokenData<Req, Res>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { CompositePhase } from '../impl';
|
|
3
3
|
import { EnforcerOptions } from '../../enforcer';
|
|
4
|
+
type RequiredEndEnforcerFlowOptions = 'logServiceClient' | 'telemetry';
|
|
4
5
|
export declare class EndEnforcerFlow<Req, Res, Added, Removed> extends CompositePhase<Req, Res> {
|
|
5
|
-
constructor(config: IConfiguration<Req, Res, Added, Removed>, { logServiceClient }: Pick<Required<EnforcerOptions<Req, Res, Added, Removed>>,
|
|
6
|
+
constructor(config: IConfiguration<Req, Res, Added, Removed>, { logServiceClient, telemetry, }: Pick<Required<EnforcerOptions<Req, Res, Added, Removed>>, RequiredEndEnforcerFlowOptions>);
|
|
6
7
|
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IPhase } from '../IPhase';
|
|
2
|
+
import { PhaseResult } from '../PhaseResult';
|
|
3
|
+
import { IContext } from '../../context';
|
|
4
|
+
import { ITelemetry } from '../../telemetry';
|
|
5
|
+
export declare class IdentifyTelemetryRequestPhase<Req, Res> implements IPhase<Req, Res> {
|
|
6
|
+
protected readonly telemetry: ITelemetry<Req, Res>;
|
|
7
|
+
constructor(telemetry: ITelemetry<Req, Res>);
|
|
8
|
+
execute(context: IContext<Req, Res>): Promise<PhaseResult>;
|
|
9
|
+
}
|
|
@@ -2,7 +2,7 @@ import { IPhase } from '../IPhase';
|
|
|
2
2
|
import { PhaseResult } from '../PhaseResult';
|
|
3
3
|
import { IContext } from '../../context';
|
|
4
4
|
import { ITelemetry } from '../../telemetry';
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class SendTelemetryActivityPhase<Req, Res> implements IPhase<Req, Res> {
|
|
6
6
|
protected readonly telemetry: ITelemetry<Req, Res>;
|
|
7
7
|
constructor(telemetry: ITelemetry<Req, Res>);
|
|
8
8
|
execute(context: IContext<Req, Res>): Promise<PhaseResult>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './FirstPartyPhase';
|
|
2
2
|
export * from './FilterPhase';
|
|
3
3
|
export * from './PreflightPhase';
|
|
4
|
-
export * from './TelemetryPhase';
|
|
5
4
|
export * from './EnrichContextFromRequestPhase';
|
|
6
5
|
export * from './ParseTokenPhase';
|
|
7
6
|
export * from './DecideActionPhase';
|
|
@@ -17,3 +16,5 @@ export * from './CompositePhase';
|
|
|
17
16
|
export * from './SendLogsPhase';
|
|
18
17
|
export * from './/UpdateRemoteConfigPhase';
|
|
19
18
|
export * from './ClearLogsPhase';
|
|
19
|
+
export * from './IdentifyTelemetryRequestPhase';
|
|
20
|
+
export * from './SendTelemetryActivityPhase';
|
|
@@ -35,6 +35,6 @@ export declare abstract class PostRiskApiClientBase<Req, Res, Added, Removed> im
|
|
|
35
35
|
protected getRiskUrl(): string;
|
|
36
36
|
protected getRiskHeaders(): ReadonlyHeaders;
|
|
37
37
|
protected handleS2STimeout(riskApiData: RiskApiData): RiskApiData;
|
|
38
|
-
protected handleS2SError(riskApiData: RiskApiData, response?: IIncomingResponse, error?: unknown): Promise<RiskApiData>;
|
|
38
|
+
protected handleS2SError(riskApiData: RiskApiData, context: ReadonlyContext<Req, Res>, response?: IIncomingResponse, error?: unknown): Promise<RiskApiData>;
|
|
39
39
|
}
|
|
40
40
|
export declare const isEnforcerTimeoutError: (err: unknown) => boolean;
|
|
@@ -21,6 +21,7 @@ export declare abstract class RiskResponseBase<TokenV extends TokenVersion> impl
|
|
|
21
21
|
get dataEnrichment(): PXDE | undefined;
|
|
22
22
|
get pxhdDomain(): string | undefined;
|
|
23
23
|
get additionalRiskInfo(): string | undefined;
|
|
24
|
+
get telemetryRequested(): boolean | undefined;
|
|
24
25
|
get drc(): number | undefined;
|
|
25
26
|
toJSON(): RiskResponseJson;
|
|
26
27
|
}
|
|
@@ -6,6 +6,7 @@ import { RiskResponseJson } from './RiskResponseJson';
|
|
|
6
6
|
export declare class SerializedRiskResponse implements IRiskResponse {
|
|
7
7
|
readonly action: BlockAction | undefined;
|
|
8
8
|
readonly additionalRiskInfo: string | undefined;
|
|
9
|
+
readonly telemetryRequested: boolean | undefined;
|
|
9
10
|
readonly dataEnrichment: PXDE | undefined;
|
|
10
11
|
readonly drc: number | undefined;
|
|
11
12
|
readonly message: string | undefined;
|
|
@@ -11,4 +11,4 @@ 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
13
|
export declare const REGEX_STRUCTURE: RegExp;
|
|
14
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.24.
|
|
14
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.24.1";
|