perimeterx-js-core 0.24.0 → 0.24.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.
Files changed (53) hide show
  1. package/lib/cjs/context/DefaultContext.js +2 -0
  2. package/lib/cjs/context/SerializedContext.js +1 -0
  3. package/lib/cjs/graphql/DefaultGraphQLParser.js +22 -27
  4. package/lib/cjs/phase/flow/EndEnforcerFlow.js +4 -4
  5. package/lib/cjs/phase/flow/FilterFlow.js +1 -1
  6. package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +61 -0
  7. package/lib/cjs/phase/impl/RiskApiPhase.js +1 -0
  8. package/lib/cjs/phase/impl/{TelemetryPhase.js → SendTelemetryActivityPhase.js} +12 -13
  9. package/lib/cjs/phase/impl/index.js +2 -1
  10. package/lib/cjs/risk_api/client/PostRiskApiClientBase.js +5 -4
  11. package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +9 -0
  12. package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +1 -0
  13. package/lib/cjs/utils/constants.js +1 -1
  14. package/lib/cjs/utils/request_id_generator/SimpleRequestIdGenerator.js +13 -0
  15. package/lib/cjs/utils/request_id_generator/index.js +1 -0
  16. package/lib/esm/context/DefaultContext.js +3 -0
  17. package/lib/esm/context/SerializedContext.js +2 -0
  18. package/lib/esm/graphql/DefaultGraphQLParser.js +21 -26
  19. package/lib/esm/phase/flow/EndEnforcerFlow.js +3 -3
  20. package/lib/esm/phase/flow/FilterFlow.js +2 -2
  21. package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +13 -0
  22. package/lib/esm/phase/impl/RiskApiPhase.js +1 -0
  23. package/lib/esm/phase/impl/{TelemetryPhase.js → SendTelemetryActivityPhase.js} +3 -4
  24. package/lib/esm/phase/impl/index.js +2 -1
  25. package/lib/esm/risk_api/client/PostRiskApiClientBase.js +5 -4
  26. package/lib/esm/risk_api/risk_response/RiskResponseBase.js +4 -0
  27. package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +2 -0
  28. package/lib/esm/utils/constants.js +1 -1
  29. package/lib/esm/utils/request_id_generator/SimpleRequestIdGenerator.js +9 -0
  30. package/lib/esm/utils/request_id_generator/index.js +1 -0
  31. package/lib/types/config/ConfigurationBuilderBase.d.ts +1 -1
  32. package/lib/types/context/ContextJson.d.ts +1 -0
  33. package/lib/types/context/DefaultContext.d.ts +1 -0
  34. package/lib/types/context/SerializedContext.d.ts +1 -0
  35. package/lib/types/context/interfaces/IContext.d.ts +4 -0
  36. package/lib/types/graphql/DefaultGraphQLParser.d.ts +8 -8
  37. package/lib/types/graphql/ExtractGraphQLKeywordsFunction.d.ts +1 -1
  38. package/lib/types/graphql/model/GraphQLData.d.ts +1 -1
  39. package/lib/types/graphql/model/GraphQLOperation.d.ts +1 -1
  40. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +3 -1
  41. package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +9 -0
  42. package/lib/types/phase/impl/{TelemetryPhase.d.ts → SendTelemetryActivityPhase.d.ts} +1 -1
  43. package/lib/types/phase/impl/index.d.ts +2 -1
  44. package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +1 -1
  45. package/lib/types/risk_api/risk_response/CommonRiskResponsePayload.d.ts +1 -0
  46. package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +1 -0
  47. package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
  48. package/lib/types/risk_api/risk_response/serialize/RiskResponseJson.d.ts +1 -0
  49. package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
  50. package/lib/types/utils/constants.d.ts +1 -1
  51. package/lib/types/utils/request_id_generator/SimpleRequestIdGenerator.d.ts +6 -0
  52. package/lib/types/utils/request_id_generator/index.d.ts +1 -0
  53. 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;
@@ -126,16 +126,8 @@ var DefaultGraphQLParser = /** @class */ (function () {
126
126
  return __awaiter(this, void 0, void 0, function () {
127
127
  var operationNameToTypeMap;
128
128
  return __generator(this, function (_a) {
129
- if (!operation.query || typeof operation.query !== 'string') {
130
- context.logger.debug('no query found');
131
- return [2 /*return*/, null];
132
- }
133
- operationNameToTypeMap = this.getOperationNameToTypeMap(operation.query);
134
- if (!operationNameToTypeMap) {
135
- context.logger.debug('operationNameToTypeMap returned null');
136
- return [2 /*return*/, null];
137
- }
138
- return [2 /*return*/, this.getGraphQLData(operationNameToTypeMap, operation, context)];
129
+ operationNameToTypeMap = operation.query ? this.getOperationNameToTypeMap(operation.query) : null;
130
+ return [2 /*return*/, this.getGraphQLData(operation, context, operationNameToTypeMap)];
139
131
  });
140
132
  });
141
133
  };
@@ -147,17 +139,17 @@ var DefaultGraphQLParser = /** @class */ (function () {
147
139
  while ((match = pattern.exec(query)) !== null) {
148
140
  var operationType = match[1];
149
141
  var operationName = match[2];
150
- if ((0, utils_1.isNullOrUndefined)(operationName) || map[operationName]) {
151
- // query contains two operations with the same name which is illegal
152
- return null;
153
- }
154
- else {
155
- map[operationName] = operationType;
142
+ if (!(0, utils_1.isNullOrUndefined)(operationName)) {
143
+ // if already exists in map, then query contains two operations with
144
+ // the same name which is illegal, so we use the first one only
145
+ if (!map[operationName]) {
146
+ map[operationName] = operationType;
147
+ }
156
148
  }
157
149
  }
158
150
  return map;
159
151
  };
160
- DefaultGraphQLParser.prototype.getGraphQLData = function (operationNameToTypeMap, operation, context) {
152
+ DefaultGraphQLParser.prototype.getGraphQLData = function (operation, context, operationNameToTypeMap) {
161
153
  return __awaiter(this, void 0, void 0, function () {
162
154
  var name, type, data, keywords;
163
155
  return __generator(this, function (_a) {
@@ -165,9 +157,6 @@ var DefaultGraphQLParser = /** @class */ (function () {
165
157
  case 0:
166
158
  name = this.getOperationName(operationNameToTypeMap, operation);
167
159
  type = this.getOperationType(operation, name, operationNameToTypeMap);
168
- if (!type) {
169
- return [2 /*return*/, null];
170
- }
171
160
  data = { type: type };
172
161
  if (name) {
173
162
  data.name = name;
@@ -190,25 +179,31 @@ var DefaultGraphQLParser = /** @class */ (function () {
190
179
  });
191
180
  };
192
181
  DefaultGraphQLParser.prototype.getOperationType = function (operation, operationName, operationNameToTypeMap) {
193
- if (operationName && operationNameToTypeMap[operationName]) {
182
+ var _a;
183
+ if (operationName && (operationNameToTypeMap === null || operationNameToTypeMap === void 0 ? void 0 : operationNameToTypeMap[operationName])) {
194
184
  return operationNameToTypeMap[operationName];
195
185
  }
196
186
  if (this.isGraphqlQueryShorthand(operation.query)) {
197
187
  return model_1.GraphQLOperationType.QUERY;
198
188
  }
199
- var match = operation.query.match(new RegExp("^\\s*(".concat(Object.values(model_1.GraphQLOperationType).join('|'), ")(?:\\s|{)")));
189
+ var match = (_a = operation.query) === null || _a === void 0 ? void 0 : _a.match(new RegExp("^\\s*(".concat(Object.values(model_1.GraphQLOperationType).join('|'), ")(?:\\s|{)")));
200
190
  if ((match === null || match === void 0 ? void 0 : match[1]) && !operationName) {
201
191
  return match[1];
202
192
  }
203
193
  return null;
204
194
  };
205
195
  DefaultGraphQLParser.prototype.isGraphqlQueryShorthand = function (query) {
206
- return /^\s*{/.test(query);
196
+ return query ? /^\s*{/.test(query) : false;
207
197
  };
208
198
  DefaultGraphQLParser.prototype.getOperationName = function (operationNameToTypeMap, operation) {
209
- var _a;
210
- return (operation.operationName ||
211
- (Object.keys(operationNameToTypeMap).length === 1 ? (_a = Object.keys(operationNameToTypeMap)) === null || _a === void 0 ? void 0 : _a[0] : undefined));
199
+ if (operation.operationName) {
200
+ return operation.operationName;
201
+ }
202
+ if (operationNameToTypeMap) {
203
+ var operationNames = Object.keys(operationNameToTypeMap);
204
+ return operationNames.length === 1 ? operationNames[0] : undefined;
205
+ }
206
+ return undefined;
212
207
  };
213
208
  DefaultGraphQLParser.prototype.getQueryKeywords = function (query, context) {
214
209
  return __awaiter(this, void 0, void 0, function () {
@@ -260,7 +255,7 @@ var DefaultGraphQLParser = /** @class */ (function () {
260
255
  try {
261
256
  this.config.graphqlKeywords.forEach(function (keyword) {
262
257
  var pattern = _this.toGlobalRegExp(keyword);
263
- var matchGroup = query.match(pattern);
258
+ var matchGroup = query === null || query === void 0 ? void 0 : query.match(pattern);
264
259
  if (!matchGroup) {
265
260
  return;
266
261
  }
@@ -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 ClearLogsPhase_1 = require("../impl/ClearLogsPhase");
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 ClearLogsPhase_1.ClearLogsPhase());
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.TelemetryPhase(telemetry));
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;
@@ -129,6 +129,7 @@ var RiskApiPhase = /** @class */ (function (_super) {
129
129
  uuid: 'uuid',
130
130
  action: 'blockAction',
131
131
  dataEnrichment: 'pxde',
132
+ telemetryRequested: 'shouldSendTelemetry',
132
133
  });
133
134
  if (riskResponse.dataEnrichment) {
134
135
  context.pxdeVerified = true;
@@ -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.TelemetryPhase = void 0;
40
- var TelemetryPhase = /** @class */ (function () {
41
- function TelemetryPhase(telemetry) {
39
+ exports.SendTelemetryActivityPhase = void 0;
40
+ var SendTelemetryActivityPhase = /** @class */ (function () {
41
+ function SendTelemetryActivityPhase(telemetry) {
42
42
  this.telemetry = telemetry;
43
43
  }
44
- TelemetryPhase.prototype.execute = function (context) {
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: return [4 /*yield*/, this.telemetry.isValidTelemetryRequest(context)];
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
- return [2 /*return*/, { done: true }];
55
- case 3: return [2 /*return*/, { done: false }];
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
- TelemetryPhase.prototype.sendTelemetry = function (context) {
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 TelemetryPhase;
72
+ return SendTelemetryActivityPhase;
74
73
  }());
75
- exports.TelemetryPhase = TelemetryPhase;
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.0';
17
+ exports.CORE_MODULE_VERSION = 'JS Core 0.24.2';
@@ -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;
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./IRequestIdGenerator"), exports);
18
+ __exportStar(require("./SimpleRequestIdGenerator"), exports);
@@ -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 {
@@ -54,16 +54,8 @@ export class DefaultGraphQLParser {
54
54
  return data.filter((el) => !isNullOrUndefined(el));
55
55
  }
56
56
  async parseGraphQLOperation(operation, context) {
57
- if (!operation.query || typeof operation.query !== 'string') {
58
- context.logger.debug('no query found');
59
- return null;
60
- }
61
- const operationNameToTypeMap = this.getOperationNameToTypeMap(operation.query);
62
- if (!operationNameToTypeMap) {
63
- context.logger.debug('operationNameToTypeMap returned null');
64
- return null;
65
- }
66
- return this.getGraphQLData(operationNameToTypeMap, operation, context);
57
+ const operationNameToTypeMap = operation.query ? this.getOperationNameToTypeMap(operation.query) : null;
58
+ return this.getGraphQLData(operation, context, operationNameToTypeMap);
67
59
  }
68
60
  getOperationNameToTypeMap(query) {
69
61
  const operationTypesString = Object.values(GraphQLOperationType).join('|');
@@ -73,22 +65,19 @@ export class DefaultGraphQLParser {
73
65
  while ((match = pattern.exec(query)) !== null) {
74
66
  const operationType = match[1];
75
67
  const operationName = match[2];
76
- if (isNullOrUndefined(operationName) || map[operationName]) {
77
- // query contains two operations with the same name which is illegal
78
- return null;
79
- }
80
- else {
81
- map[operationName] = operationType;
68
+ if (!isNullOrUndefined(operationName)) {
69
+ // if already exists in map, then query contains two operations with
70
+ // the same name which is illegal, so we use the first one only
71
+ if (!map[operationName]) {
72
+ map[operationName] = operationType;
73
+ }
82
74
  }
83
75
  }
84
76
  return map;
85
77
  }
86
- async getGraphQLData(operationNameToTypeMap, operation, context) {
78
+ async getGraphQLData(operation, context, operationNameToTypeMap) {
87
79
  const name = this.getOperationName(operationNameToTypeMap, operation);
88
80
  const type = this.getOperationType(operation, name, operationNameToTypeMap);
89
- if (!type) {
90
- return null;
91
- }
92
81
  const data = { type };
93
82
  if (name) {
94
83
  data.name = name;
@@ -106,24 +95,30 @@ export class DefaultGraphQLParser {
106
95
  return data;
107
96
  }
108
97
  getOperationType(operation, operationName, operationNameToTypeMap) {
109
- if (operationName && operationNameToTypeMap[operationName]) {
98
+ if (operationName && operationNameToTypeMap?.[operationName]) {
110
99
  return operationNameToTypeMap[operationName];
111
100
  }
112
101
  if (this.isGraphqlQueryShorthand(operation.query)) {
113
102
  return GraphQLOperationType.QUERY;
114
103
  }
115
- const match = operation.query.match(new RegExp(`^\\s*(${Object.values(GraphQLOperationType).join('|')})(?:\\s|{)`));
104
+ const match = operation.query?.match(new RegExp(`^\\s*(${Object.values(GraphQLOperationType).join('|')})(?:\\s|{)`));
116
105
  if (match?.[1] && !operationName) {
117
106
  return match[1];
118
107
  }
119
108
  return null;
120
109
  }
121
110
  isGraphqlQueryShorthand(query) {
122
- return /^\s*{/.test(query);
111
+ return query ? /^\s*{/.test(query) : false;
123
112
  }
124
113
  getOperationName(operationNameToTypeMap, operation) {
125
- return (operation.operationName ||
126
- (Object.keys(operationNameToTypeMap).length === 1 ? Object.keys(operationNameToTypeMap)?.[0] : undefined));
114
+ if (operation.operationName) {
115
+ return operation.operationName;
116
+ }
117
+ if (operationNameToTypeMap) {
118
+ const operationNames = Object.keys(operationNameToTypeMap);
119
+ return operationNames.length === 1 ? operationNames[0] : undefined;
120
+ }
121
+ return undefined;
127
122
  }
128
123
  async getQueryKeywords(query, context) {
129
124
  if (this.config.extractGraphQLKeywords && typeof this.config.extractGraphQLKeywords === 'function') {
@@ -156,7 +151,7 @@ export class DefaultGraphQLParser {
156
151
  try {
157
152
  this.config.graphqlKeywords.forEach((keyword) => {
158
153
  const pattern = this.toGlobalRegExp(keyword);
159
- let matchGroup = query.match(pattern);
154
+ let matchGroup = query?.match(pattern);
160
155
  if (!matchGroup) {
161
156
  return;
162
157
  }
@@ -1,8 +1,8 @@
1
1
  import { CompositePhase, SendLogsPhase } from '../impl';
2
- import { ClearLogsPhase } from '../impl/ClearLogsPhase';
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, TelemetryPhase, UpdateRemoteConfigPhase, } from '../impl';
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 TelemetryPhase(telemetry));
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
+ }
@@ -41,6 +41,7 @@ export class RiskApiPhase extends DecideActionPhase {
41
41
  uuid: 'uuid',
42
42
  action: 'blockAction',
43
43
  dataEnrichment: 'pxde',
44
+ telemetryRequested: 'shouldSendTelemetry',
44
45
  });
45
46
  if (riskResponse.dataEnrichment) {
46
47
  context.pxdeVerified = true;
@@ -1,12 +1,11 @@
1
- export class TelemetryPhase {
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 (await this.telemetry.isValidTelemetryRequest(context)) {
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.0';
14
+ export const CORE_MODULE_VERSION = 'JS Core 0.24.2';
@@ -0,0 +1,9 @@
1
+ export class SimpleRequestIdGenerator {
2
+ requestId;
3
+ constructor(requestId) {
4
+ this.requestId = requestId;
5
+ }
6
+ generateRequestId() {
7
+ return this.requestId;
8
+ }
9
+ }
@@ -1 +1,2 @@
1
1
  export * from './IRequestIdGenerator';
2
+ export * from './SimpleRequestIdGenerator';
@@ -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>;
@@ -41,5 +41,6 @@ export type ContextJson<Req = unknown, Res = unknown> = {
41
41
  logger?: {
42
42
  logs: LogRecord[];
43
43
  };
44
+ shouldSendTelemetry: boolean;
44
45
  };
45
46
  export {};
@@ -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>;
@@ -129,4 +129,8 @@ export interface IContext<Req, Res> {
129
129
  * The time the Enforcer process started
130
130
  */
131
131
  readonly enforcerStartTime?: number;
132
+ /**
133
+ * Whether to send telemetry activity for the current request.
134
+ */
135
+ shouldSendTelemetry: boolean;
132
136
  }
@@ -15,15 +15,15 @@ export declare class DefaultGraphQLParser<Req, Res, Added, Removed> implements I
15
15
  protected parseGraphQLOperations(operations: GraphQLOperation[], context: ReadonlyContext<Req, Res>): Promise<GraphQLData[]>;
16
16
  protected parseGraphQLOperation(operation: GraphQLOperation, context: ReadonlyContext<Req, Res>): Promise<GraphQLData | null>;
17
17
  protected getOperationNameToTypeMap(query: string): Record<string, GraphQLOperationType> | null;
18
- protected getGraphQLData(operationNameToTypeMap: Record<string, GraphQLOperationType>, operation: GraphQLOperation, context: ReadonlyContext<Req, Res>): Promise<GraphQLData | null>;
19
- protected getOperationType(operation: GraphQLOperation, operationName: string | undefined, operationNameToTypeMap: Record<string, GraphQLOperationType>): GraphQLOperationType | null;
20
- protected isGraphqlQueryShorthand(query: string): boolean;
21
- protected getOperationName(operationNameToTypeMap: Record<string, GraphQLOperationType>, operation: GraphQLOperation): string | undefined;
22
- protected getQueryKeywords(query: string, context: ReadonlyContext<Req, Res>): Promise<string[] | null>;
18
+ protected getGraphQLData(operation: GraphQLOperation, context: ReadonlyContext<Req, Res>, operationNameToTypeMap: Record<string, GraphQLOperationType> | null): Promise<GraphQLData | null>;
19
+ protected getOperationType(operation: GraphQLOperation, operationName: string | undefined, operationNameToTypeMap: Record<string, GraphQLOperationType> | null): GraphQLOperationType | null;
20
+ protected isGraphqlQueryShorthand(query: string | undefined): boolean;
21
+ protected getOperationName(operationNameToTypeMap: Record<string, GraphQLOperationType> | null, operation: GraphQLOperation): string | undefined;
22
+ protected getQueryKeywords(query: string | undefined, context: ReadonlyContext<Req, Res>): Promise<string[] | null>;
23
23
  protected cleanKeywords(keywords: string[]): string[];
24
- protected getQueryKeywordsFromCustomFunction(query: string, context: ReadonlyContext<Req, Res>, extractKeywords: ExtractGraphQLKeywordsFunction): Promise<string[] | null>;
25
- protected getQueryKeywordsFromArray(query: string, context: ReadonlyContext<Req, Res>): string[] | null;
26
- protected isSensitiveOperation(operationName: string | undefined, operationType: GraphQLOperationType, keywords: string[] | null): boolean;
24
+ protected getQueryKeywordsFromCustomFunction(query: string | undefined, context: ReadonlyContext<Req, Res>, extractKeywords: ExtractGraphQLKeywordsFunction): Promise<string[] | null>;
25
+ protected getQueryKeywordsFromArray(query: string | undefined, context: ReadonlyContext<Req, Res>): string[] | null;
26
+ protected isSensitiveOperation(operationName: string | undefined, operationType: GraphQLOperationType | null, keywords: string[] | null): boolean;
27
27
  protected extractGraphQLVariableNames(variables: Record<string, unknown>): string[];
28
28
  protected toGlobalRegExp(pattern: string | RegExp): RegExp;
29
29
  }
@@ -1 +1 @@
1
- export type ExtractGraphQLKeywordsFunction = (graphqlQuery: string) => string[] | Promise<string[]>;
1
+ export type ExtractGraphQLKeywordsFunction = (graphqlQuery: string | undefined) => string[] | Promise<string[]>;
@@ -1,6 +1,6 @@
1
1
  import { GraphQLOperationType } from './GraphQLOperationType';
2
2
  export type GraphQLData = {
3
- type?: GraphQLOperationType;
3
+ type?: GraphQLOperationType | null;
4
4
  keywords?: string[];
5
5
  name?: string;
6
6
  sensitive?: boolean;
@@ -1,5 +1,5 @@
1
1
  export type GraphQLOperation = {
2
- query: string;
2
+ query?: string;
3
3
  operationName?: string;
4
4
  variables?: Record<string, unknown>;
5
5
  };
@@ -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>>, 'logServiceClient'>);
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 TelemetryPhase<Req, Res> implements IPhase<Req, Res> {
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;
@@ -11,4 +11,5 @@ export type CommonRiskResponsePayload = {
11
11
  data_enrichment?: PXDE;
12
12
  drc?: number;
13
13
  additional_risk_info?: string;
14
+ telemetry_requested?: boolean;
14
15
  };
@@ -13,5 +13,6 @@ export interface IRiskResponse {
13
13
  readonly dataEnrichment?: PXDE;
14
14
  readonly drc?: number;
15
15
  readonly additionalRiskInfo?: string;
16
+ readonly telemetryRequested?: boolean;
16
17
  validate(): AsyncOrSync<boolean>;
17
18
  }
@@ -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
  }
@@ -12,4 +12,5 @@ export type RiskResponseJson = {
12
12
  readonly dataEnrichment?: PXDE;
13
13
  readonly drc?: number;
14
14
  readonly additionalRiskInfo?: string;
15
+ readonly telemetryRequested?: boolean;
15
16
  };
@@ -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.0";
14
+ export declare const CORE_MODULE_VERSION = "JS Core 0.24.2";
@@ -0,0 +1,6 @@
1
+ import { IRequestIdGenerator } from './IRequestIdGenerator';
2
+ export declare class SimpleRequestIdGenerator implements IRequestIdGenerator {
3
+ protected readonly requestId: string;
4
+ constructor(requestId: string);
5
+ generateRequestId(): string;
6
+ }
@@ -1 +1,2 @@
1
1
  export * from './IRequestIdGenerator';
2
+ export * from './SimpleRequestIdGenerator';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perimeterx-js-core",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "typesVersions": {