perimeterx-js-core 0.24.4 → 0.25.0

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 (92) hide show
  1. package/lib/cjs/config/ConfigurationBase.js +9 -6
  2. package/lib/cjs/config/index.js +0 -1
  3. package/lib/cjs/config/remote_config/RemoteConfigUtils.js +12 -2
  4. package/lib/cjs/config/remote_config/index.js +2 -2
  5. package/lib/cjs/config/remote_config/manager/DefaultRemoteConfigManager.js +191 -0
  6. package/lib/cjs/config/remote_config/manager/index.js +18 -0
  7. package/lib/cjs/config/remote_config/model/index.js +1 -1
  8. package/lib/cjs/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.js +139 -0
  9. package/lib/cjs/config/remote_config/update_parser/IRemoteConfigUpdateParser.js +2 -0
  10. package/lib/cjs/config/remote_config/update_parser/index.js +18 -0
  11. package/lib/cjs/context/DefaultContext.js +22 -4
  12. package/lib/cjs/context/SerializedContext.js +1 -1
  13. package/lib/cjs/context/interfaces/RemoteConfigUpdateData.js +2 -0
  14. package/lib/cjs/context/interfaces/index.js +1 -0
  15. package/lib/cjs/enforcer/EnforcerBase.js +16 -10
  16. package/lib/cjs/enforcer/utils.js +34 -38
  17. package/lib/cjs/phase/flow/EndEnforcerFlow.js +6 -4
  18. package/lib/cjs/phase/flow/FilterFlow.js +3 -4
  19. package/lib/cjs/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +75 -0
  20. package/lib/cjs/phase/impl/UpdateRemoteConfigPhase.js +7 -14
  21. package/lib/cjs/phase/impl/index.js +2 -1
  22. package/lib/cjs/utils/constants.js +1 -1
  23. package/lib/esm/config/ConfigurationBase.js +10 -8
  24. package/lib/esm/config/index.js +0 -1
  25. package/lib/esm/config/remote_config/RemoteConfigUtils.js +11 -2
  26. package/lib/esm/config/remote_config/index.js +2 -2
  27. package/lib/esm/config/remote_config/manager/DefaultRemoteConfigManager.js +87 -0
  28. package/lib/esm/config/remote_config/manager/index.js +2 -0
  29. package/lib/esm/config/remote_config/model/index.js +1 -1
  30. package/lib/esm/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.js +60 -0
  31. package/lib/esm/config/remote_config/update_parser/IRemoteConfigUpdateParser.js +1 -0
  32. package/lib/esm/config/remote_config/update_parser/index.js +2 -0
  33. package/lib/esm/context/DefaultContext.js +19 -6
  34. package/lib/esm/context/SerializedContext.js +2 -2
  35. package/lib/esm/context/interfaces/RemoteConfigUpdateData.js +1 -0
  36. package/lib/esm/context/interfaces/index.js +1 -0
  37. package/lib/esm/enforcer/EnforcerBase.js +3 -0
  38. package/lib/esm/enforcer/utils.js +32 -17
  39. package/lib/esm/logger/LoggerBase.js +1 -1
  40. package/lib/esm/phase/flow/EndEnforcerFlow.js +5 -3
  41. package/lib/esm/phase/flow/FilterFlow.js +4 -5
  42. package/lib/esm/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +24 -0
  43. package/lib/esm/phase/impl/UpdateRemoteConfigPhase.js +6 -13
  44. package/lib/esm/phase/impl/index.js +2 -1
  45. package/lib/esm/utils/constants.js +1 -1
  46. package/lib/types/config/ConfigurationBase.d.ts +3 -2
  47. package/lib/types/config/IConfiguration.d.ts +3 -2
  48. package/lib/types/config/index.d.ts +0 -1
  49. package/lib/types/config/params/CoreConfigurationParams.d.ts +1 -1
  50. package/lib/types/config/remote_config/RemoteConfigUtils.d.ts +2 -1
  51. package/lib/types/config/remote_config/index.d.ts +2 -2
  52. package/lib/types/config/remote_config/manager/DefaultRemoteConfigManager.d.ts +23 -0
  53. package/lib/types/config/remote_config/manager/IRemoteConfigManager.d.ts +7 -0
  54. package/lib/types/config/remote_config/manager/index.d.ts +2 -0
  55. package/lib/types/config/remote_config/model/RemoteConfigNotifyRequestPayload.d.ts +3 -0
  56. package/lib/types/config/remote_config/model/index.d.ts +1 -1
  57. package/lib/types/config/remote_config/service_client/HttpRemoteConfigServiceClient.d.ts +2 -2
  58. package/lib/types/config/remote_config/service_client/IRemoteConfigServiceClient.d.ts +2 -2
  59. package/lib/types/config/remote_config/storage_client/IRemoteConfigStorageClient.d.ts +1 -1
  60. package/lib/types/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.d.ts +22 -0
  61. package/lib/types/config/remote_config/update_parser/IRemoteConfigUpdateParser.d.ts +5 -0
  62. package/lib/types/config/remote_config/update_parser/index.d.ts +2 -0
  63. package/lib/types/context/ContextJson.d.ts +2 -2
  64. package/lib/types/context/DefaultContext.d.ts +5 -3
  65. package/lib/types/context/SerializedContext.d.ts +2 -2
  66. package/lib/types/context/interfaces/IContext.d.ts +4 -3
  67. package/lib/types/context/interfaces/RemoteConfigUpdateData.d.ts +4 -0
  68. package/lib/types/context/interfaces/index.d.ts +1 -0
  69. package/lib/types/enforcer/EnforcerBase.d.ts +2 -1
  70. package/lib/types/enforcer/EnforcerOptions.d.ts +3 -2
  71. package/lib/types/enforcer/utils.d.ts +7 -1
  72. package/lib/types/logger/ILogger.d.ts +4 -0
  73. package/lib/types/logger/LoggerBase.d.ts +1 -1
  74. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +2 -2
  75. package/lib/types/phase/flow/FilterFlow.d.ts +1 -1
  76. package/lib/types/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.d.ts +9 -0
  77. package/lib/types/phase/impl/UpdateRemoteConfigPhase.d.ts +3 -5
  78. package/lib/types/phase/impl/index.d.ts +2 -1
  79. package/lib/types/utils/constants.d.ts +1 -1
  80. package/package.json +13 -13
  81. package/lib/cjs/config/ConfigurationBuilderBase.js +0 -135
  82. package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +0 -200
  83. package/lib/esm/config/ConfigurationBuilderBase.js +0 -66
  84. package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +0 -99
  85. package/lib/types/config/ConfigurationBuilderBase.d.ts +0 -13
  86. package/lib/types/config/remote_config/DefaultRemoteConfigUpdater.d.ts +0 -34
  87. package/lib/types/config/remote_config/IRemoteConfigUpdater.d.ts +0 -6
  88. package/lib/types/config/remote_config/model/RemoteConfigUpdateRequestData.d.ts +0 -3
  89. /package/lib/cjs/config/remote_config/{IRemoteConfigUpdater.js → manager/IRemoteConfigManager.js} +0 -0
  90. /package/lib/cjs/config/remote_config/model/{RemoteConfigUpdateRequestData.js → RemoteConfigNotifyRequestPayload.js} +0 -0
  91. /package/lib/esm/config/remote_config/{IRemoteConfigUpdater.js → manager/IRemoteConfigManager.js} +0 -0
  92. /package/lib/esm/config/remote_config/model/{RemoteConfigUpdateRequestData.js → RemoteConfigNotifyRequestPayload.js} +0 -0
@@ -83,12 +83,13 @@ var ConfigurationBase = /** @class */ (function () {
83
83
  }
84
84
  };
85
85
  ConfigurationBase.prototype.createInternalLogger = function (params) {
86
- return new logger_1.DefaultLogger(params.px_logger_severity, false);
86
+ var _a;
87
+ return new logger_1.DefaultLogger(params.px_logger_severity, false, (_a = this.logger) === null || _a === void 0 ? void 0 : _a.getLogs());
87
88
  };
88
- ConfigurationBase.prototype.addRemoteConfig = function (remoteConfigParams) {
89
- this.remoteConfigParams = remoteConfigParams;
90
- var mergedParams = __assign(__assign({}, this.staticConfigParams), remote_config_1.RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigParams, this.logger));
91
- this.configParams = this.createActiveConfiguration(mergedParams, this.defaultConfigParams);
89
+ ConfigurationBase.prototype.setRemoteConfigData = function (remoteConfigData) {
90
+ this.remoteConfigData = remoteConfigData;
91
+ var params = __assign(__assign({}, this.staticConfigParams), remote_config_1.RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigData, this.logger));
92
+ this.configParams = this.createActiveConfiguration(params, this.defaultConfigParams);
92
93
  };
93
94
  ConfigurationBase.prototype.getActiveConfig = function () {
94
95
  var activeConfig = Object.assign({}, this.configParams);
@@ -102,7 +103,9 @@ var ConfigurationBase = /** @class */ (function () {
102
103
  return Object.assign({}, this.staticConfigParams);
103
104
  };
104
105
  ConfigurationBase.prototype.getRemoteConfig = function () {
105
- return Object.assign({}, this.remoteConfigParams);
106
+ return this.remoteConfigData
107
+ ? remote_config_1.RemoteConfigUtils.prepareRemoteConfigParams(this.remoteConfigData, this.logger)
108
+ : {};
106
109
  };
107
110
  Object.defineProperty(ConfigurationBase.prototype, "moduleVersion", {
108
111
  get: function () {
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./IConfiguration.js"), exports);
18
18
  __exportStar(require("./ConfigurationBase.js"), exports);
19
- __exportStar(require("./ConfigurationBuilderBase.js"), exports);
20
19
  __exportStar(require("./CustomRequestFunction.js"), exports);
21
20
  __exportStar(require("./remote_config/index.js"), exports);
22
21
  __exportStar(require("./params/index.js"), exports);
@@ -20,8 +20,18 @@ var RemoteConfigUtils;
20
20
  request.headers.get(utils_1.PUSH_DATA_FEATURE_HEADER_NAME) === constants_1.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
21
21
  !!request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
22
22
  };
23
- RemoteConfigUtils.prepareRemoteConfigParams = function (remoteConfigParams, logger) {
24
- var remoteConfig = Object.assign({}, remoteConfigParams);
23
+ RemoteConfigUtils.prepareRemoteConfigParams = function (_a, logger) {
24
+ var version = _a.version, configValue = _a.configValue;
25
+ var remoteConfig = {
26
+ px_remote_config_version: version,
27
+ px_remote_config_enabled: configValue.px_remote_config_enabled,
28
+ };
29
+ if (!configValue.px_remote_config_enabled) {
30
+ // returning only the version and the fact that remote config is disabled
31
+ // so we can report the version on async activities without merging the rest of the remote configs
32
+ return remoteConfig;
33
+ }
34
+ Object.assign(remoteConfig, configValue);
25
35
  // Remote config receives strings and regexes in separate fields (px_sensitive_routes, px_sensitive_routes_regex)
26
36
  // Before initializing a new active configuration, we merge the two into the more generic field (px_sensitive_routes)
27
37
  constants_1.CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG.forEach(function (k) {
@@ -18,6 +18,6 @@ __exportStar(require("./constants.js"), exports);
18
18
  __exportStar(require("./model/index.js"), exports);
19
19
  __exportStar(require("./service_client/index.js"), exports);
20
20
  __exportStar(require("./storage_client/index.js"), exports);
21
- __exportStar(require("./DefaultRemoteConfigUpdater.js"), exports);
22
- __exportStar(require("./IRemoteConfigUpdater.js"), exports);
21
+ __exportStar(require("./manager/index.js"), exports);
22
+ __exportStar(require("./update_parser/index.js"), exports);
23
23
  __exportStar(require("./RemoteConfigUtils.js"), exports);
@@ -0,0 +1,191 @@
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.DefaultRemoteConfigManager = void 0;
40
+ var utils_1 = require("../../../utils/index.js");
41
+ var constants_1 = require("../constants.js");
42
+ var DefaultRemoteConfigManager = /** @class */ (function () {
43
+ function DefaultRemoteConfigManager(config, options) {
44
+ this.config = config;
45
+ this.serviceClient = options.serviceClient;
46
+ this.storageClient = options.storageClient;
47
+ }
48
+ DefaultRemoteConfigManager.prototype.loadRemoteConfig = function () {
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var remoteConfigData, e_1;
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0:
54
+ if (!this.config.remoteConfigId || !this.config.remoteConfigAuthToken) {
55
+ this.config.logger.debug('no remote config id or auth token provided, skipping remote config load');
56
+ return [2 /*return*/];
57
+ }
58
+ _a.label = 1;
59
+ case 1:
60
+ _a.trys.push([1, 3, , 4]);
61
+ return [4 /*yield*/, this.loadRemoteConfigData()];
62
+ case 2:
63
+ remoteConfigData = _a.sent();
64
+ if (!!(remoteConfigData === null || remoteConfigData === void 0 ? void 0 : remoteConfigData.version) && remoteConfigData.version > this.config.remoteConfigVersion) {
65
+ this.config.setRemoteConfigData(remoteConfigData);
66
+ }
67
+ return [3 /*break*/, 4];
68
+ case 3:
69
+ e_1 = _a.sent();
70
+ this.config.logger.debug("caught error loading remote config: ".concat(e_1));
71
+ return [3 /*break*/, 4];
72
+ case 4: return [2 /*return*/];
73
+ }
74
+ });
75
+ });
76
+ };
77
+ DefaultRemoteConfigManager.prototype.loadRemoteConfigData = function () {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ var remoteConfigData;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0: return [4 /*yield*/, this.storageClient.load()];
83
+ case 1:
84
+ remoteConfigData = _a.sent();
85
+ if (!remoteConfigData) {
86
+ this.config.logger.debug('unable to load remote config from storage');
87
+ return [2 /*return*/, null];
88
+ }
89
+ if (!this.isValidRemoteConfigId(remoteConfigData.id)) {
90
+ this.config.logger.debug("remote config ID in static config does not match ID found in storage ".concat(remoteConfigData.id));
91
+ return [2 /*return*/, null];
92
+ }
93
+ return [2 /*return*/, remoteConfigData];
94
+ }
95
+ });
96
+ });
97
+ };
98
+ DefaultRemoteConfigManager.prototype.isValidRemoteConfigId = function (remoteConfigId) {
99
+ return remoteConfigId === this.config.remoteConfigId;
100
+ };
101
+ DefaultRemoteConfigManager.prototype.shouldUpdateRemoteConfig = function (context) {
102
+ return context.remoteConfigUpdateData.shouldUpdate;
103
+ };
104
+ DefaultRemoteConfigManager.prototype.updateRemoteConfig = function (context) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var desiredVersion, remoteConfigData, e_2;
107
+ var _a;
108
+ return __generator(this, function (_b) {
109
+ switch (_b.label) {
110
+ case 0:
111
+ desiredVersion = (_a = context.remoteConfigUpdateData.desiredVersion) !== null && _a !== void 0 ? _a : 0;
112
+ return [4 /*yield*/, this.fetchRemoteConfigData(desiredVersion, context)];
113
+ case 1:
114
+ remoteConfigData = _b.sent();
115
+ if (!remoteConfigData) {
116
+ return [2 /*return*/];
117
+ }
118
+ _b.label = 2;
119
+ case 2:
120
+ _b.trys.push([2, 4, , 5]);
121
+ return [4 /*yield*/, this.storageClient.save(remoteConfigData)];
122
+ case 3:
123
+ _b.sent();
124
+ context.logger.debug("successfully updated remote config to version ".concat(remoteConfigData.version));
125
+ return [3 /*break*/, 5];
126
+ case 4:
127
+ e_2 = _b.sent();
128
+ context.logger.debug("unable to save remote config version ".concat(remoteConfigData.version, " to storage: ").concat(e_2), {
129
+ errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
130
+ });
131
+ return [3 /*break*/, 5];
132
+ case 5: return [2 /*return*/];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ DefaultRemoteConfigManager.prototype.fetchRemoteConfigData = function (desiredVersion, context) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var _a, remoteConfigMaxFetchAttempts, remoteConfigRetryIntervalMs, i, remoteConfigData, e_3;
140
+ return __generator(this, function (_b) {
141
+ switch (_b.label) {
142
+ case 0:
143
+ _b.trys.push([0, 7, , 8]);
144
+ _a = this.config, remoteConfigMaxFetchAttempts = _a.remoteConfigMaxFetchAttempts, remoteConfigRetryIntervalMs = _a.remoteConfigRetryIntervalMs;
145
+ i = 0;
146
+ _b.label = 1;
147
+ case 1:
148
+ if (!(i < remoteConfigMaxFetchAttempts)) return [3 /*break*/, 6];
149
+ return [4 /*yield*/, this.serviceClient.fetch({ version: desiredVersion })];
150
+ case 2:
151
+ remoteConfigData = _b.sent();
152
+ if (!(!!remoteConfigData && remoteConfigData.version >= desiredVersion)) return [3 /*break*/, 3];
153
+ return [2 /*return*/, remoteConfigData];
154
+ case 3: return [4 /*yield*/, this.sleepBetweenFetchAttempts(remoteConfigRetryIntervalMs)];
155
+ case 4:
156
+ _b.sent();
157
+ _b.label = 5;
158
+ case 5:
159
+ i++;
160
+ return [3 /*break*/, 1];
161
+ case 6:
162
+ context.logger.debug("unable to fetch remote config version ".concat(desiredVersion, " or higher: reached ").concat(remoteConfigMaxFetchAttempts, " fetch attempts"), {
163
+ errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
164
+ });
165
+ return [3 /*break*/, 8];
166
+ case 7:
167
+ e_3 = _b.sent();
168
+ context.logger.debug("unable to fetch remote config version ".concat(desiredVersion, " or higher: ").concat(e_3), {
169
+ errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
170
+ });
171
+ return [3 /*break*/, 8];
172
+ case 8: return [2 /*return*/, null];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ DefaultRemoteConfigManager.prototype.sleepBetweenFetchAttempts = function (ms) {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0: return [4 /*yield*/, (0, utils_1.sleep)(ms)];
182
+ case 1:
183
+ _a.sent();
184
+ return [2 /*return*/];
185
+ }
186
+ });
187
+ });
188
+ };
189
+ return DefaultRemoteConfigManager;
190
+ }());
191
+ exports.DefaultRemoteConfigManager = DefaultRemoteConfigManager;
@@ -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("./IRemoteConfigManager.js"), exports);
18
+ __exportStar(require("./DefaultRemoteConfigManager.js"), exports);
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./RemoteConfigData.js"), exports);
18
- __exportStar(require("./RemoteConfigUpdateRequestData.js"), exports);
18
+ __exportStar(require("./RemoteConfigNotifyRequestPayload.js"), exports);
@@ -0,0 +1,139 @@
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.DefaultNotifyRemoteConfigUpdateParser = void 0;
40
+ var utils_1 = require("../../../utils/index.js");
41
+ var constants_1 = require("../constants.js");
42
+ var http_1 = require("../../../http/index.js");
43
+ var DefaultNotifyRemoteConfigUpdateParser = /** @class */ (function () {
44
+ function DefaultNotifyRemoteConfigUpdateParser(config, options) {
45
+ var _a;
46
+ this.config = config;
47
+ this.timestampHmacHeaderValidator =
48
+ (_a = options.timestampHmacHeaderValidator) !== null && _a !== void 0 ? _a : new utils_1.DefaultTimestampHmacHeaderValidator(config, config.remoteConfigAuthToken, options.base64Utils, options.hmacUtils);
49
+ }
50
+ DefaultNotifyRemoteConfigUpdateParser.prototype.isUpdateRequest = function (_a) {
51
+ return __awaiter(this, arguments, void 0, function (_b) {
52
+ var request = _b.requestData.request;
53
+ return __generator(this, function (_c) {
54
+ return [2 /*return*/, (request.method === http_1.HttpMethod.POST &&
55
+ request.headers.get(utils_1.PUSH_DATA_FEATURE_HEADER_NAME) === constants_1.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
56
+ !!request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME))];
57
+ });
58
+ });
59
+ };
60
+ DefaultNotifyRemoteConfigUpdateParser.prototype.parseUpdate = function (context) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var updateData, desiredVersion;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0: return [4 /*yield*/, this.isNotifyRequestValid(context)];
66
+ case 1:
67
+ if (!(_a.sent())) {
68
+ return [2 /*return*/, { shouldUpdate: false }];
69
+ }
70
+ updateData = { shouldUpdate: true };
71
+ return [4 /*yield*/, this.getDesiredRemoteConfigVersion(context)];
72
+ case 2:
73
+ desiredVersion = _a.sent();
74
+ context.logger.debug("got notify request for remote config version ".concat(desiredVersion));
75
+ if (desiredVersion) {
76
+ updateData.desiredVersion = desiredVersion;
77
+ }
78
+ return [2 /*return*/, updateData];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ DefaultNotifyRemoteConfigUpdateParser.prototype.isNotifyRequestValid = function (context) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var timestampHmacHeader, isValid, _a;
86
+ return __generator(this, function (_b) {
87
+ switch (_b.label) {
88
+ case 0:
89
+ timestampHmacHeader = context.requestData.request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
90
+ _a = !!timestampHmacHeader;
91
+ if (!_a) return [3 /*break*/, 2];
92
+ return [4 /*yield*/, this.timestampHmacHeaderValidator.isValid(timestampHmacHeader, context.logger)];
93
+ case 1:
94
+ _a = (_b.sent());
95
+ _b.label = 2;
96
+ case 2:
97
+ isValid = _a;
98
+ if (!isValid) {
99
+ context.logger.debug("invalid remote config notify request hmac header received: ".concat(timestampHmacHeader), {
100
+ errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
101
+ });
102
+ }
103
+ return [2 /*return*/, isValid];
104
+ }
105
+ });
106
+ });
107
+ };
108
+ DefaultNotifyRemoteConfigUpdateParser.prototype.getDesiredRemoteConfigVersion = function (context) {
109
+ return __awaiter(this, void 0, void 0, function () {
110
+ var notifyRequestPayload, e_1;
111
+ return __generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0:
114
+ _a.trys.push([0, 2, , 3]);
115
+ return [4 /*yield*/, context.requestData.request.json()];
116
+ case 1:
117
+ notifyRequestPayload = _a.sent();
118
+ return [3 /*break*/, 3];
119
+ case 2:
120
+ e_1 = _a.sent();
121
+ context.logger.debug("could not parse update request body: ".concat(e_1), {
122
+ errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
123
+ });
124
+ return [2 /*return*/, null];
125
+ case 3:
126
+ if (!(notifyRequestPayload === null || notifyRequestPayload === void 0 ? void 0 : notifyRequestPayload.version)) {
127
+ context.logger.debug("no version on update request body: ".concat(notifyRequestPayload), {
128
+ errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
129
+ });
130
+ return [2 /*return*/, null];
131
+ }
132
+ return [2 /*return*/, notifyRequestPayload.version];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ return DefaultNotifyRemoteConfigUpdateParser;
138
+ }());
139
+ exports.DefaultNotifyRemoteConfigUpdateParser = DefaultNotifyRemoteConfigUpdateParser;
@@ -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("./DefaultNotifyRemoteConfigUpdateParser.js"), exports);
18
+ __exportStar(require("./IRemoteConfigUpdateParser.js"), exports);
@@ -12,7 +12,6 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.DefaultContext = void 0;
15
- var config_1 = require("../config/index.js");
16
15
  var blocker_1 = require("../blocker/index.js");
17
16
  var pxhd_1 = require("../pxhd/index.js");
18
17
  var risk_token_1 = require("../risk_token/index.js");
@@ -23,6 +22,7 @@ var action_1 = require("../action/index.js");
23
22
  var logger_1 = require("../logger/index.js");
24
23
  var DefaultContext = /** @class */ (function () {
25
24
  function DefaultContext(config, request, options) {
25
+ this._shouldSendLogs = false;
26
26
  this.enforcerStartTime = Date.now();
27
27
  this.config = config;
28
28
  this.urlUtils = options.urlUtils;
@@ -40,8 +40,10 @@ var DefaultContext = /** @class */ (function () {
40
40
  this.pxdeVerified = false;
41
41
  this.action = action_1.Action.TRIGGER_RISK_API;
42
42
  this.reasons = {};
43
- this.isRemoteConfigUpdateRequest = config_1.RemoteConfigUtils.isRemoteConfigUpdateRequest(request);
44
- this.shouldSendLogs = this.isRemoteConfigUpdateRequest || this.isHeaderBasedLoggerRequest(config, request);
43
+ this.remoteConfigUpdateData = {
44
+ shouldUpdate: false,
45
+ };
46
+ this.shouldSendLogs = this.isHeaderBasedLoggerRequest(config, request);
45
47
  this.logger = this.createContextLogger(config, this.shouldSendLogs);
46
48
  this.requestData = this.createRequestData(config, request, options.cookieParser);
47
49
  this.tokenOrigin = this.getTokenOrigin(request);
@@ -50,6 +52,22 @@ var DefaultContext = /** @class */ (function () {
50
52
  }
51
53
  this.shouldSendTelemetry = false;
52
54
  }
55
+ Object.defineProperty(DefaultContext.prototype, "shouldSendLogs", {
56
+ get: function () {
57
+ return this._shouldSendLogs;
58
+ },
59
+ set: function (shouldSendLogs) {
60
+ if (this._shouldSendLogs === shouldSendLogs) {
61
+ return;
62
+ }
63
+ this._shouldSendLogs = shouldSendLogs;
64
+ if (this.logger) {
65
+ this.logger.shouldSaveLogs = shouldSendLogs;
66
+ }
67
+ },
68
+ enumerable: false,
69
+ configurable: true
70
+ });
53
71
  Object.defineProperty(DefaultContext.prototype, "isMobile", {
54
72
  get: function () {
55
73
  return this.tokenOrigin === risk_token_1.TokenOrigin.HEADER;
@@ -145,7 +163,7 @@ var DefaultContext = /** @class */ (function () {
145
163
  action: this.action,
146
164
  reasons: this.reasons,
147
165
  isMobile: this.isMobile,
148
- isRemoteConfigUpdateRequest: this.isRemoteConfigUpdateRequest,
166
+ remoteConfigUpdateData: this.remoteConfigUpdateData,
149
167
  productData: this.productData,
150
168
  requestData: __assign(__assign({}, this.requestData), { request: undefined, url: this.requestData.url.href }),
151
169
  requestId: this.requestId,
@@ -22,7 +22,7 @@ var SerializedContext = /** @class */ (function () {
22
22
  this.reasons = contextJson.reasons;
23
23
  this.isMobile = contextJson.isMobile;
24
24
  this.requestId = contextJson.requestId;
25
- this.isRemoteConfigUpdateRequest = contextJson.isRemoteConfigUpdateRequest;
25
+ this.remoteConfigUpdateData = contextJson.remoteConfigUpdateData;
26
26
  this.logger = this.createLogger(config, contextJson.shouldSendLogs, (_a = contextJson.logger) === null || _a === void 0 ? void 0 : _a.logs);
27
27
  this.productData = contextJson.productData;
28
28
  this.requestData = this.createRequestData(contextJson, request, urlUtils);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -20,5 +20,6 @@ __exportStar(require("./MobileData.js"), exports);
20
20
  __exportStar(require("./TokenData.js"), exports);
21
21
  __exportStar(require("./TlsData.js"), exports);
22
22
  __exportStar(require("./ServerData.js"), exports);
23
+ __exportStar(require("./RemoteConfigUpdateData.js"), exports);
23
24
  __exportStar(require("./IContext.js"), exports);
24
25
  __exportStar(require("./ReadonlyContext.js"), exports);
@@ -59,6 +59,7 @@ var EnforcerBase = /** @class */ (function () {
59
59
  this.config = config;
60
60
  var initializationBlock = (0, utils_1.createEnforcerInitializationBlock)(config, options);
61
61
  this.activityClient = initializationBlock.activityClient;
62
+ this.remoteConfigManager = initializationBlock.remoteConfigManager;
62
63
  this.filterFlow = this.createFilterFlow(config, initializationBlock);
63
64
  this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
64
65
  this.postEnforceFlow = this.createPostEnforceFlow(config, initializationBlock);
@@ -91,23 +92,28 @@ var EnforcerBase = /** @class */ (function () {
91
92
  }
92
93
  return __awaiter(this, void 0, void 0, function () {
93
94
  var context, e_1;
94
- return __generator(this, function (_a) {
95
- switch (_a.label) {
96
- case 0:
97
- _a.trys.push([0, 3, , 4]);
95
+ var _a;
96
+ return __generator(this, function (_b) {
97
+ switch (_b.label) {
98
+ case 0: return [4 /*yield*/, ((_a = this.remoteConfigManager) === null || _a === void 0 ? void 0 : _a.loadRemoteConfig())];
99
+ case 1:
100
+ _b.sent();
101
+ _b.label = 2;
102
+ case 2:
103
+ _b.trys.push([2, 5, , 6]);
98
104
  if (!this.config.moduleEnabled) {
99
105
  return [2 /*return*/, null];
100
106
  }
101
107
  return [4 /*yield*/, this.constructContext.apply(this, args)];
102
- case 1:
103
- context = _a.sent();
104
- return [4 /*yield*/, this.doEnforce.apply(this, __spreadArray([context], args, false))];
105
- case 2: return [2 /*return*/, _a.sent()];
106
108
  case 3:
107
- e_1 = _a.sent();
109
+ context = _b.sent();
110
+ return [4 /*yield*/, this.doEnforce.apply(this, __spreadArray([context], args, false))];
111
+ case 4: return [2 /*return*/, _b.sent()];
112
+ case 5:
113
+ e_1 = _b.sent();
108
114
  (context || this.config).logger.error("caught error in enforce - ".concat(e_1));
109
115
  return [2 /*return*/, null];
110
- case 4: return [2 /*return*/];
116
+ case 6: return [2 /*return*/];
111
117
  }
112
118
  });
113
119
  });