perimeterx-js-core 0.23.3 → 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.
Files changed (93) hide show
  1. package/lib/cjs/activities/utils.js +4 -3
  2. package/lib/cjs/config/ConfigurationBase.js +14 -0
  3. package/lib/cjs/config/defaults/DefaultConfigurationParams.js +2 -0
  4. package/lib/cjs/context/DefaultContext.js +2 -0
  5. package/lib/cjs/context/SerializedContext.js +1 -0
  6. package/lib/cjs/enforcer/utils.js +6 -1
  7. package/lib/cjs/index.js +1 -0
  8. package/lib/cjs/phase/flow/EndEnforcerFlow.js +4 -4
  9. package/lib/cjs/phase/flow/FilterFlow.js +1 -1
  10. package/lib/cjs/phase/flow/PostEnforceFlow.js +2 -2
  11. package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +61 -0
  12. package/lib/cjs/phase/impl/ModifyOutgoingResponsePhase.js +32 -1
  13. package/lib/cjs/phase/impl/RiskApiPhase.js +1 -0
  14. package/lib/cjs/phase/impl/{TelemetryPhase.js → SendTelemetryActivityPhase.js} +12 -13
  15. package/lib/cjs/phase/impl/index.js +2 -1
  16. package/lib/cjs/risk_api/client/PostRiskApiClientBase.js +5 -4
  17. package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +9 -0
  18. package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +1 -0
  19. package/lib/cjs/snippet_injection/CustomSnippetFunction.js +2 -0
  20. package/lib/cjs/snippet_injection/index.js +20 -0
  21. package/lib/cjs/snippet_injection/snippet_injector/ISnippetInjector.js +2 -0
  22. package/lib/cjs/snippet_injection/snippet_injector/index.js +17 -0
  23. package/lib/cjs/snippet_injection/snippet_retriever/DefaultSnippetRetriever.js +95 -0
  24. package/lib/cjs/snippet_injection/snippet_retriever/ISnippetRetriever.js +2 -0
  25. package/lib/cjs/snippet_injection/snippet_retriever/index.js +18 -0
  26. package/lib/cjs/snippet_injection/utils.js +5 -0
  27. package/lib/cjs/utils/constants.js +1 -1
  28. package/lib/cjs/utils/request_id_generator/SimpleRequestIdGenerator.js +13 -0
  29. package/lib/cjs/utils/request_id_generator/index.js +1 -0
  30. package/lib/esm/activities/utils.js +4 -3
  31. package/lib/esm/config/ConfigurationBase.js +6 -0
  32. package/lib/esm/config/defaults/DefaultConfigurationParams.js +2 -0
  33. package/lib/esm/context/DefaultContext.js +3 -0
  34. package/lib/esm/context/SerializedContext.js +2 -0
  35. package/lib/esm/enforcer/utils.js +5 -0
  36. package/lib/esm/index.js +1 -0
  37. package/lib/esm/phase/flow/EndEnforcerFlow.js +3 -3
  38. package/lib/esm/phase/flow/FilterFlow.js +2 -2
  39. package/lib/esm/phase/flow/PostEnforceFlow.js +2 -2
  40. package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +13 -0
  41. package/lib/esm/phase/impl/ModifyOutgoingResponsePhase.js +17 -1
  42. package/lib/esm/phase/impl/RiskApiPhase.js +1 -0
  43. package/lib/esm/phase/impl/{TelemetryPhase.js → SendTelemetryActivityPhase.js} +3 -4
  44. package/lib/esm/phase/impl/index.js +2 -1
  45. package/lib/esm/risk_api/client/PostRiskApiClientBase.js +5 -4
  46. package/lib/esm/risk_api/risk_response/RiskResponseBase.js +4 -0
  47. package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +2 -0
  48. package/lib/esm/snippet_injection/CustomSnippetFunction.js +1 -0
  49. package/lib/esm/snippet_injection/index.js +4 -0
  50. package/lib/esm/snippet_injection/snippet_injector/ISnippetInjector.js +1 -0
  51. package/lib/esm/snippet_injection/snippet_injector/index.js +1 -0
  52. package/lib/esm/snippet_injection/snippet_retriever/DefaultSnippetRetriever.js +36 -0
  53. package/lib/esm/snippet_injection/snippet_retriever/ISnippetRetriever.js +1 -0
  54. package/lib/esm/snippet_injection/snippet_retriever/index.js +2 -0
  55. package/lib/esm/snippet_injection/utils.js +9 -0
  56. package/lib/esm/utils/constants.js +1 -1
  57. package/lib/esm/utils/request_id_generator/SimpleRequestIdGenerator.js +9 -0
  58. package/lib/esm/utils/request_id_generator/index.js +1 -0
  59. package/lib/types/activities/model/CommonActivityDetails.d.ts +1 -0
  60. package/lib/types/config/ConfigurationBase.d.ts +3 -0
  61. package/lib/types/config/ConfigurationBuilderBase.d.ts +1 -1
  62. package/lib/types/config/IConfiguration.d.ts +9 -0
  63. package/lib/types/config/params/CoreConfigurationParams.d.ts +6 -1
  64. package/lib/types/context/ContextJson.d.ts +1 -0
  65. package/lib/types/context/DefaultContext.d.ts +1 -0
  66. package/lib/types/context/SerializedContext.d.ts +1 -0
  67. package/lib/types/context/interfaces/IContext.d.ts +4 -0
  68. package/lib/types/enforcer/EnforcerOptions.d.ts +3 -0
  69. package/lib/types/index.d.ts +1 -0
  70. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +3 -1
  71. package/lib/types/phase/flow/PostEnforceFlow.d.ts +1 -1
  72. package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +9 -0
  73. package/lib/types/phase/impl/ModifyOutgoingResponsePhase.d.ts +5 -1
  74. package/lib/types/phase/impl/{TelemetryPhase.d.ts → SendTelemetryActivityPhase.d.ts} +1 -1
  75. package/lib/types/phase/impl/index.d.ts +2 -1
  76. package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +1 -1
  77. package/lib/types/risk_api/risk_response/CommonRiskResponsePayload.d.ts +1 -0
  78. package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +1 -0
  79. package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
  80. package/lib/types/risk_api/risk_response/serialize/RiskResponseJson.d.ts +1 -0
  81. package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
  82. package/lib/types/snippet_injection/CustomSnippetFunction.d.ts +2 -0
  83. package/lib/types/snippet_injection/index.d.ts +4 -0
  84. package/lib/types/snippet_injection/snippet_injector/ISnippetInjector.d.ts +5 -0
  85. package/lib/types/snippet_injection/snippet_injector/index.d.ts +1 -0
  86. package/lib/types/snippet_injection/snippet_retriever/DefaultSnippetRetriever.d.ts +10 -0
  87. package/lib/types/snippet_injection/snippet_retriever/ISnippetRetriever.d.ts +5 -0
  88. package/lib/types/snippet_injection/snippet_retriever/index.d.ts +2 -0
  89. package/lib/types/snippet_injection/utils.d.ts +1 -0
  90. package/lib/types/utils/constants.d.ts +1 -1
  91. package/lib/types/utils/request_id_generator/SimpleRequestIdGenerator.d.ts +6 -0
  92. package/lib/types/utils/request_id_generator/index.d.ts +1 -0
  93. package/package.json +1 -1
@@ -86,9 +86,10 @@ function redactCookieSecret(secret) {
86
86
  return '***'.concat(secret.substring(secret.length - 3, secret.length));
87
87
  }
88
88
  var addConfigDataToDetails = function (details, config) {
89
- if (config.remoteConfigVersion) {
90
- details.remote_config_version = config.remoteConfigVersion;
91
- }
89
+ (0, utils_1.transferExistingProperties)(config, details, {
90
+ remoteConfigId: 'remote_config_id',
91
+ remoteConfigVersion: 'remote_config_version',
92
+ });
92
93
  };
93
94
  exports.addConfigDataToDetails = addConfigDataToDetails;
94
95
  var addCustomParametersToDetails = function (details, customParameters) {
@@ -717,6 +717,20 @@ var ConfigurationBase = /** @class */ (function () {
717
717
  enumerable: false,
718
718
  configurable: true
719
719
  });
720
+ Object.defineProperty(ConfigurationBase.prototype, "snippetInjectionEnabled", {
721
+ get: function () {
722
+ return this.configParams.px_snippet_injection_enabled;
723
+ },
724
+ enumerable: false,
725
+ configurable: true
726
+ });
727
+ Object.defineProperty(ConfigurationBase.prototype, "createCustomSnippet", {
728
+ get: function () {
729
+ return this.configParams.px_create_custom_snippet;
730
+ },
731
+ enumerable: false,
732
+ configurable: true
733
+ });
720
734
  Object.defineProperty(ConfigurationBase.prototype, "enableBlockedUrlOnCaptchaBlockPage", {
721
735
  get: function () {
722
736
  return true;
@@ -130,6 +130,8 @@ var defaultConfigurationParams = function () { return ({
130
130
  px_remote_config_retry_interval_ms: 1000,
131
131
  px_url_decode_reserved_characters: false,
132
132
  px_secured_pxhd_enabled: false,
133
+ px_snippet_injection_enabled: false,
134
+ px_create_custom_snippet: null,
133
135
  px_custom_is_sensitive_request: null,
134
136
  px_custom_is_monitored_request: null,
135
137
  px_custom_is_enforced_request: null,
@@ -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;
@@ -23,8 +23,9 @@ var activities_1 = require("../activities");
23
23
  var logger_1 = require("../logger");
24
24
  var products_1 = require("../products");
25
25
  var utils_1 = require("../utils");
26
+ var snippet_injection_1 = require("../snippet_injection");
26
27
  var createEnforcerInitializationBlock = function (config, options) {
27
- var _a, _b;
28
+ var _a, _b, _c;
28
29
  var tokenVersion = config.tokenVersion;
29
30
  if (!(0, utils_1.isValidTokenVersion)(tokenVersion)) {
30
31
  throw new utils_1.EnforcerError("error initializing enforcer: token version ".concat(tokenVersion, " is invalid (must be one of ").concat(Object.values(risk_token_1.TokenVersion)
@@ -65,6 +66,8 @@ var createEnforcerInitializationBlock = function (config, options) {
65
66
  hmacUtils: hmacUtils,
66
67
  })
67
68
  : null);
69
+ var snippetInjector = (_c = options.snippetInjector) !== null && _c !== void 0 ? _c : null;
70
+ var snippetRetriever = options.snippetRetriever || (snippetInjector ? new snippet_injection_1.DefaultSnippetRetriever(config) : null);
68
71
  var allOptions = {
69
72
  httpClient: httpClient,
70
73
  base64Utils: base64Utils,
@@ -84,6 +87,8 @@ var createEnforcerInitializationBlock = function (config, options) {
84
87
  remoteConfigStorageClient: remoteConfigStorageClient,
85
88
  remoteConfigServiceClient: remoteConfigServiceClient,
86
89
  remoteConfigUpdater: remoteConfigUpdater,
90
+ snippetInjector: snippetInjector,
91
+ snippetRetriever: snippetRetriever,
87
92
  };
88
93
  var products = (0, exports.createEnforcerProducts)(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
89
94
  return __assign({ products: products }, allOptions);
package/lib/cjs/index.js CHANGED
@@ -23,6 +23,7 @@ __exportStar(require("./context"), exports);
23
23
  __exportStar(require("./custom_parameters"), exports);
24
24
  __exportStar(require("./sensitive_request"), exports);
25
25
  __exportStar(require("./monitored_request"), exports);
26
+ __exportStar(require("./snippet_injection"), exports);
26
27
  __exportStar(require("./cors"), exports);
27
28
  __exportStar(require("./enforcer"), exports);
28
29
  __exportStar(require("./filter"), exports);
@@ -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);
@@ -20,10 +20,10 @@ var impl_1 = require("../impl");
20
20
  var PostEnforceFlow = /** @class */ (function (_super) {
21
21
  __extends(PostEnforceFlow, _super);
22
22
  function PostEnforceFlow(config, _a) {
23
- var products = _a.products, activityClient = _a.activityClient;
23
+ var products = _a.products, activityClient = _a.activityClient, snippetRetriever = _a.snippetRetriever, snippetInjector = _a.snippetInjector;
24
24
  return _super.call(this, [
25
25
  new impl_1.EnrichContextFromResponsePhase(config, products),
26
- new impl_1.ModifyOutgoingResponsePhase(config, Object.values(products)),
26
+ new impl_1.ModifyOutgoingResponsePhase(config, Object.values(products), snippetRetriever, snippetInjector),
27
27
  new impl_1.SendAsyncActivitiesOnResponsePhase(activityClient),
28
28
  ]) || this;
29
29
  }
@@ -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;
@@ -38,10 +38,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ModifyOutgoingResponsePhase = void 0;
40
40
  var pxhd_1 = require("../../pxhd");
41
+ var http_1 = require("../../http");
41
42
  var ModifyOutgoingResponsePhase = /** @class */ (function () {
42
- function ModifyOutgoingResponsePhase(config, products) {
43
+ function ModifyOutgoingResponsePhase(config, products, snippetRetriever, snippetInjector) {
43
44
  this.config = config;
44
45
  this.products = products;
46
+ this.snippetRetriever = snippetRetriever;
47
+ this.snippetInjector = snippetInjector;
45
48
  }
46
49
  ModifyOutgoingResponsePhase.prototype.execute = function (context) {
47
50
  return __awaiter(this, void 0, void 0, function () {
@@ -54,11 +57,39 @@ var ModifyOutgoingResponsePhase = /** @class */ (function () {
54
57
  if (((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.source) === pxhd_1.PXHDSource.RISK && context.response) {
55
58
  pxhd_1.PXHDUtils.addPxhdToOutgoingResponse(this.config, context, context.response);
56
59
  }
60
+ return [4 /*yield*/, this.handleSnippetInjection(context)];
61
+ case 2:
62
+ _b.sent();
57
63
  return [2 /*return*/, { done: false }];
58
64
  }
59
65
  });
60
66
  });
61
67
  };
68
+ ModifyOutgoingResponsePhase.prototype.handleSnippetInjection = function (context) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var snippet, _a;
71
+ var _b, _c, _d;
72
+ return __generator(this, function (_e) {
73
+ switch (_e.label) {
74
+ case 0:
75
+ if (!(this.snippetRetriever &&
76
+ this.snippetInjector &&
77
+ this.config.snippetInjectionEnabled &&
78
+ !!((_d = (_c = (_b = context.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.get(http_1.CONTENT_TYPE_HEADER_NAME)) === null || _d === void 0 ? void 0 : _d.includes(http_1.ContentType.TEXT_HTML)))) return [3 /*break*/, 3];
79
+ context.logger.debug('snippet injection enabled');
80
+ return [4 /*yield*/, this.snippetRetriever.retrieveSnippet(context)];
81
+ case 1:
82
+ snippet = _e.sent();
83
+ _a = context;
84
+ return [4 /*yield*/, this.snippetInjector.injectSnippet(context.response, snippet)];
85
+ case 2:
86
+ _a.response = _e.sent();
87
+ _e.label = 3;
88
+ case 3: return [2 /*return*/];
89
+ }
90
+ });
91
+ });
92
+ };
62
93
  return ModifyOutgoingResponsePhase;
63
94
  }());
64
95
  exports.ModifyOutgoingResponsePhase = ModifyOutgoingResponsePhase;
@@ -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;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./snippet_injector"), exports);
18
+ __exportStar(require("./snippet_retriever"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ __exportStar(require("./CustomSnippetFunction"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ISnippetInjector"), exports);
@@ -0,0 +1,95 @@
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.DefaultSnippetRetriever = void 0;
40
+ var products_1 = require("../../products");
41
+ var utils_1 = require("../utils");
42
+ var DefaultSnippetRetriever = /** @class */ (function () {
43
+ function DefaultSnippetRetriever(config) {
44
+ this.config = config;
45
+ }
46
+ DefaultSnippetRetriever.prototype.retrieveSnippet = function (context) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4 /*yield*/, this.retrieveCustomSnippet(context)];
51
+ case 1: return [2 /*return*/, (_a.sent()) || this.retrieveDefaultSnippet(context)];
52
+ }
53
+ });
54
+ });
55
+ };
56
+ DefaultSnippetRetriever.prototype.retrieveCustomSnippet = function (context) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var snippet, e_1;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ if (!this.config.createCustomSnippet) {
63
+ return [2 /*return*/, null];
64
+ }
65
+ _a.label = 1;
66
+ case 1:
67
+ _a.trys.push([1, 3, , 4]);
68
+ return [4 /*yield*/, this.config.createCustomSnippet(this.config.getActiveConfig(), context.requestData.request.getUnderlyingRequest(), context.response.getUnderlyingResponse())];
69
+ case 2:
70
+ snippet = _a.sent();
71
+ if (!snippet || typeof snippet !== 'string') {
72
+ context.logger.debug("invalid custom snippet of type ".concat(typeof snippet));
73
+ return [2 /*return*/, null];
74
+ }
75
+ context.logger.debug('retrieving custom snippet');
76
+ return [2 /*return*/, snippet];
77
+ case 3:
78
+ e_1 = _a.sent();
79
+ context.logger.debug("failed retrieving custom snippet: ".concat(e_1));
80
+ return [3 /*break*/, 4];
81
+ case 4: return [2 /*return*/, null];
82
+ }
83
+ });
84
+ });
85
+ };
86
+ DefaultSnippetRetriever.prototype.retrieveDefaultSnippet = function (context) {
87
+ var sensorSrc = this.config.firstPartyEnabled
88
+ ? (0, products_1.getMostCustomizedFirstPartyPath)(this.config, products_1.FirstPartySuffix.SENSOR)
89
+ : "".concat(this.config.backendClientUrl, "/").concat(this.config.appId, "/main.min.js");
90
+ context.logger.debug("retrieving default snippet with src ".concat(sensorSrc));
91
+ return (0, utils_1.createDefaultSnippet)(this.config.appId, sensorSrc);
92
+ };
93
+ return DefaultSnippetRetriever;
94
+ }());
95
+ exports.DefaultSnippetRetriever = DefaultSnippetRetriever;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ISnippetRetriever"), exports);
18
+ __exportStar(require("./DefaultSnippetRetriever"), exports);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDefaultSnippet = void 0;
4
+ var createDefaultSnippet = function (appId, sensorSrc) { return "<script type=\"text/javascript\">\n (function(){\n window._pxAppId = '".concat(appId, "';\n var p = document.getElementsByTagName('script')[0], s = document.createElement('script');\n s.async = 1;\n s.src = '").concat(sensorSrc, "';\n p.parentNode.insertBefore(s,p);\n }());\n</script>"); };
5
+ exports.createDefaultSnippet = createDefaultSnippet;
@@ -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.23.3';
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;
@@ -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);