perimeterx-js-core 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/activities/utils.js +6 -1
- package/lib/cjs/blocker/MobileBlocker.js +1 -1
- package/lib/cjs/blocker/model/BlockActionToWordMap.js +1 -0
- package/lib/cjs/blocker/utils.js +3 -2
- package/lib/cjs/config/ConfigurationBase.js +7 -0
- package/lib/cjs/config/defaults/DefaultCommonConfigurationParams.js +1 -0
- package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +23 -11
- package/lib/cjs/context/DefaultContext.js +18 -3
- package/lib/cjs/enforcer/EnforcerBase.js +6 -5
- package/lib/cjs/http/interfaces/index.js +0 -2
- package/lib/cjs/http/utils/FormDataImpl.js +2 -5
- package/lib/cjs/http/utils/index.js +0 -3
- package/lib/cjs/impl/cipher/CryptoCipherUtils.js +2 -1
- package/lib/cjs/impl/hash/CryptoHashUtils.js +2 -1
- package/lib/cjs/impl/hash/SubtleCryptoHashUtils.js +1 -32
- package/lib/cjs/impl/hmac/CryptoHmacUtils.js +5 -10
- package/lib/cjs/impl/hmac/SubtleCryptoHmacUtils.js +72 -0
- package/lib/cjs/impl/http/phin/PhinIncomingResponse.js +5 -2
- package/lib/cjs/impl/url/CustomImplUrlUtils.js +71 -0
- package/lib/cjs/impl/url/DefaultUrlUtils.js +27 -0
- package/lib/cjs/{http/utils → impl/url}/UrlImpl.js +3 -2
- package/lib/cjs/{http/utils → impl/url}/UrlSearchParamsImpl.js +8 -9
- package/lib/cjs/logger/HttpLogServiceClient.js +4 -5
- package/lib/cjs/phase/impl/DecideActionPhase.js +8 -0
- package/lib/cjs/phase/impl/RiskApiPhase.js +1 -0
- package/lib/cjs/products/bot_defender/BotDefender.js +2 -1
- package/lib/cjs/products/bot_defender/block/captcha/CaptchaBlocker.js +2 -2
- package/lib/cjs/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +3 -2
- package/lib/cjs/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +3 -2
- package/lib/cjs/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +3 -2
- package/lib/cjs/products/credential_intelligence/CredentialIntelligence.js +5 -5
- package/lib/cjs/products/credential_intelligence/endpoint/CredentialEndpoint.js +17 -3
- package/lib/cjs/products/credential_intelligence/endpoint/extractor/CredentialExtractorFactory.js +2 -2
- package/lib/cjs/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +3 -3
- package/lib/cjs/products/hype_sale_challenge/HypeSaleChallenge.js +15 -7
- package/lib/cjs/products/hype_sale_challenge/block/JsonHypeSaleChallengeBlocker.js +3 -2
- package/lib/cjs/pxde/DefaultDataEnrichment.js +14 -8
- package/lib/cjs/risk_api/client/PostRiskApiClientBase.js +2 -2
- package/lib/cjs/risk_token/token/TokenBase.js +1 -1
- package/lib/cjs/risk_token/token/v2/DefaultTokenV2.js +5 -4
- package/lib/cjs/risk_token/token/v3/DefaultTokenV3.js +34 -16
- package/lib/cjs/utils/Algorithm.js +2 -2
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/index.js +1 -1
- package/lib/cjs/utils/timestamp_hmac_header_validator/DefaultTimestampHmacHeaderValidator.js +81 -25
- package/lib/cjs/utils/{url_parser → url}/index.js +3 -1
- package/lib/cjs/utils/utils.js +19 -2
- package/lib/esm/activities/utils.js +6 -1
- package/lib/esm/blocker/MobileBlocker.js +1 -1
- package/lib/esm/blocker/model/BlockActionToWordMap.js +1 -0
- package/lib/esm/blocker/utils.js +3 -2
- package/lib/esm/config/ConfigurationBase.js +3 -0
- package/lib/esm/config/defaults/DefaultCommonConfigurationParams.js +1 -0
- package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +3 -3
- package/lib/esm/context/DefaultContext.js +20 -4
- package/lib/esm/enforcer/EnforcerBase.js +7 -6
- package/lib/esm/http/interfaces/index.js +0 -2
- package/lib/esm/http/utils/FormDataImpl.js +2 -5
- package/lib/esm/http/utils/index.js +0 -3
- package/lib/esm/impl/cipher/CryptoCipherUtils.js +2 -1
- package/lib/esm/impl/hash/CryptoHashUtils.js +2 -1
- package/lib/esm/impl/hash/SubtleCryptoHashUtils.js +2 -10
- package/lib/esm/impl/hmac/CryptoHmacUtils.js +6 -11
- package/lib/esm/impl/hmac/SubtleCryptoHmacUtils.js +19 -0
- package/lib/esm/impl/http/phin/PhinIncomingResponse.js +4 -2
- package/lib/esm/impl/url/CustomImplUrlUtils.js +64 -0
- package/lib/esm/impl/url/DefaultUrlUtils.js +20 -0
- package/lib/esm/{http/utils → impl/url}/UrlImpl.js +3 -2
- package/lib/esm/{http/utils → impl/url}/UrlSearchParamsImpl.js +8 -9
- package/lib/esm/logger/HttpLogServiceClient.js +5 -6
- package/lib/esm/phase/impl/DecideActionPhase.js +9 -1
- package/lib/esm/phase/impl/RiskApiPhase.js +1 -0
- package/lib/esm/products/bot_defender/BotDefender.js +2 -1
- package/lib/esm/products/bot_defender/block/captcha/CaptchaBlocker.js +2 -2
- package/lib/esm/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +4 -2
- package/lib/esm/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +4 -2
- package/lib/esm/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +5 -3
- package/lib/esm/products/credential_intelligence/CredentialIntelligence.js +5 -5
- package/lib/esm/products/credential_intelligence/endpoint/CredentialEndpoint.js +18 -6
- package/lib/esm/products/credential_intelligence/endpoint/extractor/CredentialExtractorFactory.js +2 -2
- package/lib/esm/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +4 -3
- package/lib/esm/products/hype_sale_challenge/HypeSaleChallenge.js +13 -6
- package/lib/esm/products/hype_sale_challenge/block/JsonHypeSaleChallengeBlocker.js +4 -2
- package/lib/esm/pxde/DefaultDataEnrichment.js +2 -1
- package/lib/esm/risk_api/client/PostRiskApiClientBase.js +2 -1
- package/lib/esm/risk_token/token/TokenBase.js +2 -2
- package/lib/esm/risk_token/token/v2/DefaultTokenV2.js +5 -4
- package/lib/esm/risk_token/token/v3/DefaultTokenV3.js +19 -5
- package/lib/esm/utils/Algorithm.js +2 -2
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/index.js +1 -1
- package/lib/esm/utils/timestamp_hmac_header_validator/DefaultTimestampHmacHeaderValidator.js +4 -4
- package/lib/esm/utils/url/index.js +3 -0
- package/lib/esm/utils/utils.js +16 -1
- package/lib/types/activities/model/CommonActivityDetails.d.ts +2 -0
- package/lib/types/activities/utils.d.ts +153 -62
- package/lib/types/blocker/utils.d.ts +17 -7
- package/lib/types/config/ConfigurationBase.d.ts +6 -5
- package/lib/types/config/IConfiguration.d.ts +10 -6
- package/lib/types/config/params/CommonConfigurationParams.d.ts +6 -5
- package/lib/types/config/remote_config/DefaultRemoteConfigUpdater.d.ts +1 -1
- package/lib/types/context/DefaultContext.d.ts +6 -5
- package/lib/types/context/interfaces/IContext.d.ts +4 -0
- package/lib/types/context/interfaces/RequestData.d.ts +7 -2
- package/lib/types/context/interfaces/RiskApiData.d.ts +4 -0
- package/lib/types/enforcer/EnforcerBase.d.ts +2 -2
- package/lib/types/enforcer/options/EnforcerBaseOptions.d.ts +2 -1
- package/lib/types/http/interfaces/IBody.d.ts +2 -2
- package/lib/types/http/interfaces/IFormData.d.ts +1 -7
- package/lib/types/http/interfaces/index.d.ts +0 -2
- package/lib/types/http/utils/FormDataImpl.d.ts +7 -7
- package/lib/types/http/utils/index.d.ts +0 -3
- package/lib/types/impl/hash/SubtleCryptoHashUtils.d.ts +0 -1
- package/lib/types/impl/hmac/SubtleCryptoHmacUtils.d.ts +7 -0
- package/lib/types/impl/http/phin/PhinIncomingResponse.d.ts +3 -2
- package/lib/types/impl/url/CustomImplUrlUtils.d.ts +10 -0
- package/lib/types/impl/url/DefaultUrlUtils.d.ts +9 -0
- package/lib/types/{http/utils → impl/url}/UrlImpl.d.ts +3 -3
- package/lib/types/{http/utils → impl/url}/UrlSearchParamsImpl.d.ts +5 -4
- package/lib/types/phase/impl/DecideActionPhase.d.ts +1 -0
- package/lib/types/products/bot_defender/BotDefender.d.ts +7 -2
- package/lib/types/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +3 -1
- package/lib/types/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +3 -1
- package/lib/types/products/bot_defender/first_party/DefaultBotDefenderFirstParty.d.ts +7 -2
- package/lib/types/products/credential_intelligence/CredentialIntelligence.d.ts +7 -3
- package/lib/types/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +3 -2
- package/lib/types/products/credential_intelligence/endpoint/extractor/CredentialExtractorFactory.d.ts +2 -1
- package/lib/types/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +5 -3
- package/lib/types/products/hype_sale_challenge/HypeSaleChallenge.d.ts +4 -2
- package/lib/types/products/hype_sale_challenge/block/JsonHypeSaleChallengeBlocker.d.ts +3 -1
- package/lib/types/risk_api/model/RiskActivity.d.ts +1 -0
- package/lib/types/risk_token/token/TokenBase.d.ts +1 -2
- package/lib/types/utils/Algorithm.d.ts +2 -2
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/hmac/IHmacUtils.d.ts +2 -1
- package/lib/types/utils/index.d.ts +1 -1
- package/lib/types/utils/timestamp_hmac_header_validator/DefaultTimestampHmacHeaderValidator.d.ts +2 -2
- package/lib/types/utils/timestamp_hmac_header_validator/ITimestampHmacHeaderValidator.d.ts +2 -1
- package/lib/types/utils/url/IUrl.d.ts +9 -0
- package/lib/types/{http/interfaces/IURLSearchParams.d.ts → utils/url/IUrlSearchParams.d.ts} +2 -2
- package/lib/types/utils/url/IUrlUtils.d.ts +10 -0
- package/lib/types/utils/url/index.d.ts +3 -0
- package/lib/types/utils/utils.d.ts +3 -0
- package/package.json +5 -4
- package/lib/cjs/http/utils/URLUtils.js +0 -65
- package/lib/cjs/impl/url_parser/DefaultUrlParser.js +0 -39
- package/lib/esm/http/utils/URLUtils.js +0 -62
- package/lib/esm/impl/url_parser/DefaultUrlParser.js +0 -28
- package/lib/esm/utils/url_parser/index.js +0 -1
- package/lib/types/http/interfaces/IURL.d.ts +0 -9
- package/lib/types/http/utils/URLUtils.d.ts +0 -7
- package/lib/types/impl/url_parser/DefaultUrlParser.d.ts +0 -13
- package/lib/types/utils/url_parser/IURLParser.d.ts +0 -4
- package/lib/types/utils/url_parser/index.d.ts +0 -1
- /package/lib/cjs/{http/interfaces/IURL.js → utils/url/IUrl.js} +0 -0
- /package/lib/cjs/{http/interfaces/IURLSearchParams.js → utils/url/IUrlSearchParams.js} +0 -0
- /package/lib/cjs/utils/{url_parser/IURLParser.js → url/IUrlUtils.js} +0 -0
- /package/lib/esm/{http/interfaces/IURL.js → utils/url/IUrl.js} +0 -0
- /package/lib/esm/{http/interfaces/IURLSearchParams.js → utils/url/IUrlSearchParams.js} +0 -0
- /package/lib/esm/utils/{url_parser/IURLParser.js → url/IUrlUtils.js} +0 -0
|
@@ -11,7 +11,7 @@ var createAsyncActivity = function (activityType, config, context) {
|
|
|
11
11
|
return {
|
|
12
12
|
type: activityType,
|
|
13
13
|
px_app_id: config.appId,
|
|
14
|
-
url: context.requestData.
|
|
14
|
+
url: context.requestData.url.href,
|
|
15
15
|
headers: activityType !== ActivityType_1.ActivityType.ADDITIONAL_S2S
|
|
16
16
|
? (0, exports.toHeaderEntryArray)((0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders))
|
|
17
17
|
: undefined,
|
|
@@ -74,6 +74,7 @@ var addRootContextDataToDetails = function (details, context) {
|
|
|
74
74
|
tokenOrigin: 'cookie_origin',
|
|
75
75
|
vidSource: 'enforcer_vid_source',
|
|
76
76
|
graphqlData: 'graphql_operations',
|
|
77
|
+
enforcerStartTime: 'enforcer_start_time',
|
|
77
78
|
});
|
|
78
79
|
};
|
|
79
80
|
exports.addRootContextDataToDetails = addRootContextDataToDetails;
|
|
@@ -131,6 +132,9 @@ var addRequestDataToDetails = function (details, requestData) {
|
|
|
131
132
|
method: 'http_method',
|
|
132
133
|
requestCookieNames: 'request_cookie_names',
|
|
133
134
|
});
|
|
135
|
+
if (requestData.isUrlDifferentFromRawUrl) {
|
|
136
|
+
details.raw_url = requestData.rawUrl;
|
|
137
|
+
}
|
|
134
138
|
};
|
|
135
139
|
exports.addRequestDataToDetails = addRequestDataToDetails;
|
|
136
140
|
var addTokenDataToDetails = function (details, _a) {
|
|
@@ -163,6 +167,7 @@ var addRiskApiDataToAsyncActivityCommonDetails = function (details, context) {
|
|
|
163
167
|
(0, utils_1.transferExistingProperties)(context.riskApiData, details, {
|
|
164
168
|
riskRtt: 'risk_rtt',
|
|
165
169
|
s2sCallReason: 's2s_call_reason',
|
|
170
|
+
riskStartTime: 'risk_start_time',
|
|
166
171
|
});
|
|
167
172
|
if ((_a = context.riskApiData.riskResponse) === null || _a === void 0 ? void 0 : _a.additionalRiskInfo) {
|
|
168
173
|
details.additional_risk_info = context.riskApiData.riskResponse.additionalRiskInfo;
|
|
@@ -32,7 +32,7 @@ var MobileBlocker = /** @class */ (function (_super) {
|
|
|
32
32
|
return context.isMobile;
|
|
33
33
|
};
|
|
34
34
|
MobileBlocker.prototype.createBlockBody = function (context) {
|
|
35
|
-
var blockData = (0, blocker_1.createBlockData)(this.config, context);
|
|
35
|
+
var blockData = (0, blocker_1.createBlockData)(this.config, context, this.base64Utils);
|
|
36
36
|
var html = (0, blocker_1.renderHtml)(this.template, blockData);
|
|
37
37
|
return JSON.stringify({
|
|
38
38
|
action: blocker_1.BLOCK_ACTION_TO_WORD_MAP.get(blockData.blockAction),
|
|
@@ -6,4 +6,5 @@ exports.BLOCK_ACTION_TO_WORD_MAP = new Map([
|
|
|
6
6
|
[BlockAction_1.BlockAction.CAPTCHA, 'captcha'],
|
|
7
7
|
[BlockAction_1.BlockAction.RATE_LIMIT, 'ratelimit'],
|
|
8
8
|
[BlockAction_1.BlockAction.CHALLENGE, 'challenge'],
|
|
9
|
+
[BlockAction_1.BlockAction.HYPE_SALE_CHALLENGE, 'captcha'], // this is what mobile HSC expects
|
|
9
10
|
]);
|
package/lib/cjs/blocker/utils.js
CHANGED
|
@@ -16,10 +16,11 @@ var renderHtml = function (htmlTemplate, blockData) {
|
|
|
16
16
|
return htmlTemplate;
|
|
17
17
|
};
|
|
18
18
|
exports.renderHtml = renderHtml;
|
|
19
|
-
var createBlockData = function (config, context) {
|
|
19
|
+
var createBlockData = function (config, context, base64Utils) {
|
|
20
20
|
var _a, _b;
|
|
21
21
|
var captchaScriptSuffix = '/captcha.js';
|
|
22
|
-
var
|
|
22
|
+
var b64EncodedUrl = base64Utils.base64Encode(context.requestData.url.href);
|
|
23
|
+
var captchaParams = "?a=".concat(context.blockAction, "&u=").concat(context.uuid, "&v=").concat(context.vid || '', "&m=").concat(context.isMobile ? '1' : '0', "&b=").concat(b64EncodedUrl);
|
|
23
24
|
var jsClientSrc = "".concat(config.backendClientUrl, "/").concat(config.appId, "/main.min.js");
|
|
24
25
|
var blockScript = "".concat(config.backendCaptchaUrl, "/").concat(config.appId).concat(captchaScriptSuffix).concat(captchaParams);
|
|
25
26
|
var hostUrl = config.backendCollectorUrl;
|
|
@@ -620,6 +620,13 @@ var ConfigurationBase = /** @class */ (function () {
|
|
|
620
620
|
enumerable: false,
|
|
621
621
|
configurable: true
|
|
622
622
|
});
|
|
623
|
+
Object.defineProperty(ConfigurationBase.prototype, "urlDecodeReservedCharacters", {
|
|
624
|
+
get: function () {
|
|
625
|
+
return this.configParams.px_url_decode_reserved_characters;
|
|
626
|
+
},
|
|
627
|
+
enumerable: false,
|
|
628
|
+
configurable: true
|
|
629
|
+
});
|
|
623
630
|
return ConfigurationBase;
|
|
624
631
|
}());
|
|
625
632
|
exports.ConfigurationBase = ConfigurationBase;
|
|
@@ -64,23 +64,25 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
|
|
|
64
64
|
switch (_b.label) {
|
|
65
65
|
case 0:
|
|
66
66
|
this.config.logger.debug('identified an update remote config request');
|
|
67
|
-
|
|
67
|
+
return [4 /*yield*/, this.isUpdateRequestValid(request)];
|
|
68
|
+
case 1:
|
|
69
|
+
if (!(_b.sent())) {
|
|
68
70
|
return [2 /*return*/, false];
|
|
69
71
|
}
|
|
70
72
|
return [4 /*yield*/, this.getUpdateRequestData(request)];
|
|
71
|
-
case
|
|
73
|
+
case 2:
|
|
72
74
|
updateRequestData = _b.sent();
|
|
73
75
|
if (!updateRequestData) {
|
|
74
76
|
return [2 /*return*/, false];
|
|
75
77
|
}
|
|
76
78
|
return [4 /*yield*/, this.fetchRemoteConfig(updateRequestData)];
|
|
77
|
-
case
|
|
79
|
+
case 3:
|
|
78
80
|
remoteConfig = _b.sent();
|
|
79
81
|
if (!remoteConfig) {
|
|
80
82
|
return [2 /*return*/, false];
|
|
81
83
|
}
|
|
82
84
|
return [4 /*yield*/, this.storageClient.save(remoteConfig)];
|
|
83
|
-
case
|
|
85
|
+
case 4:
|
|
84
86
|
_b.sent();
|
|
85
87
|
this.config.logger.debug("successfully updated with remote config version ".concat(remoteConfig.version));
|
|
86
88
|
return [2 /*return*/, true];
|
|
@@ -89,14 +91,24 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
|
|
|
89
91
|
});
|
|
90
92
|
};
|
|
91
93
|
DefaultRemoteConfigUpdater.prototype.isUpdateRequestValid = function (request) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
var timestampHmacHeader, isValid;
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0:
|
|
99
|
+
timestampHmacHeader = request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
|
|
100
|
+
return [4 /*yield*/, this.timestampHmacHeaderValidator.isValid(timestampHmacHeader)];
|
|
101
|
+
case 1:
|
|
102
|
+
isValid = _a.sent();
|
|
103
|
+
if (!isValid) {
|
|
104
|
+
this.config.logger.error("invalid timestamp hmac header received: ".concat(timestampHmacHeader), {
|
|
105
|
+
errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return [2 /*return*/, isValid];
|
|
109
|
+
}
|
|
97
110
|
});
|
|
98
|
-
}
|
|
99
|
-
return isValid;
|
|
111
|
+
});
|
|
100
112
|
};
|
|
101
113
|
DefaultRemoteConfigUpdater.prototype.getUpdateRequestData = function (request) {
|
|
102
114
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -7,12 +7,12 @@ var risk_token_1 = require("../risk_token");
|
|
|
7
7
|
var risk_api_1 = require("../risk_api");
|
|
8
8
|
var http_1 = require("../http");
|
|
9
9
|
var utils_1 = require("../utils");
|
|
10
|
-
var DefaultUrlParser_1 = require("../impl/url_parser/DefaultUrlParser");
|
|
11
10
|
var logger_1 = require("../logger");
|
|
12
11
|
var DefaultContext = /** @class */ (function () {
|
|
13
12
|
function DefaultContext(config, request, options) {
|
|
13
|
+
this.enforcerStartTime = Date.now();
|
|
14
14
|
this.config = config;
|
|
15
|
-
this.
|
|
15
|
+
this.urlUtils = options.urlUtils;
|
|
16
16
|
this.tokenData = {
|
|
17
17
|
tokenParseResult: risk_token_1.TokenParseResult.NONE,
|
|
18
18
|
};
|
|
@@ -42,7 +42,8 @@ var DefaultContext = /** @class */ (function () {
|
|
|
42
42
|
DefaultContext.prototype.createRequestData = function (config, request, cookieParser) {
|
|
43
43
|
if (cookieParser === void 0) { cookieParser = new utils_1.StringSplitCookieParser(); }
|
|
44
44
|
var rawUrl = request.url;
|
|
45
|
-
var url = this.
|
|
45
|
+
var url = this.normalizeUrl(rawUrl);
|
|
46
|
+
var isUrlDifferentFromRawUrl = rawUrl !== url.href;
|
|
46
47
|
var method = request.method;
|
|
47
48
|
var headers = request.headers;
|
|
48
49
|
var cookies = DefaultContext.getCookies(cookieParser, request.headers.get(http_1.COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
|
|
@@ -62,6 +63,7 @@ var DefaultContext = /** @class */ (function () {
|
|
|
62
63
|
requestCookieNames: requestCookieNames,
|
|
63
64
|
request: request,
|
|
64
65
|
httpVersion: httpVersion,
|
|
66
|
+
isUrlDifferentFromRawUrl: isUrlDifferentFromRawUrl,
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
69
|
DefaultContext.getCookies = function (cookieParser) {
|
|
@@ -75,6 +77,19 @@ var DefaultContext = /** @class */ (function () {
|
|
|
75
77
|
});
|
|
76
78
|
return cookies;
|
|
77
79
|
};
|
|
80
|
+
DefaultContext.prototype.normalizeUrl = function (rawUrl) {
|
|
81
|
+
var url = this.urlUtils.createUrl(rawUrl);
|
|
82
|
+
if (this.config.urlDecodeReservedCharacters) {
|
|
83
|
+
try {
|
|
84
|
+
url = this.urlUtils.createUrl("".concat(url.origin).concat(this.urlUtils.decodeUriComponent(url.pathname)).concat(url.search));
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
this.config.logger.debug("unable to URL decode reserved characters: ".concat(e));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
url.pathname = url.pathname.replace(/\/+$/, '').replace(/\/+/g, '/');
|
|
91
|
+
return url;
|
|
92
|
+
};
|
|
78
93
|
DefaultContext.prototype.extractUserAgentFromHeader = function (config, headers) {
|
|
79
94
|
var _a;
|
|
80
95
|
var userAgent = ((_a = headers[http_1.USER_AGENT_HEADER_NAME]) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
@@ -227,7 +227,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
227
227
|
* @protected
|
|
228
228
|
*/
|
|
229
229
|
EnforcerBase.prototype.getInitializationBlock = function (config, options) {
|
|
230
|
-
var tokenVersion = options.tokenVersion, httpClient = options.httpClient, base64Utils = options.base64Utils, hmacUtils = options.hmacUtils, hashUtils = options.hashUtils, ipRangeChecker = options.ipRangeChecker;
|
|
230
|
+
var tokenVersion = options.tokenVersion, httpClient = options.httpClient, base64Utils = options.base64Utils, hmacUtils = options.hmacUtils, hashUtils = options.hashUtils, urlUtils = options.urlUtils, ipRangeChecker = options.ipRangeChecker;
|
|
231
231
|
var cipherUtils = tokenVersion === risk_token_1.TokenVersion.V2 ? null : options.cipherUtils;
|
|
232
232
|
var cors = options.cors || new cors_1.DefaultCors(config);
|
|
233
233
|
var telemetry = options.telemetry || new telemetry_1.DefaultTelemetry(config, httpClient, base64Utils, hmacUtils);
|
|
@@ -263,6 +263,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
263
263
|
base64Utils: base64Utils,
|
|
264
264
|
hmacUtils: hmacUtils,
|
|
265
265
|
hashUtils: hashUtils,
|
|
266
|
+
urlUtils: urlUtils,
|
|
266
267
|
ipRangeChecker: ipRangeChecker,
|
|
267
268
|
cors: cors,
|
|
268
269
|
telemetry: telemetry,
|
|
@@ -276,15 +277,15 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
276
277
|
remoteConfigServiceClient: remoteConfigServiceClient,
|
|
277
278
|
remoteConfigUpdater: remoteConfigUpdater,
|
|
278
279
|
};
|
|
279
|
-
var products = this.initializeProducts(config, options.products, base64Utils, hashUtils, ipRangeChecker);
|
|
280
|
+
var products = this.initializeProducts(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
|
|
280
281
|
return __assign({ products: products }, allOptions);
|
|
281
282
|
};
|
|
282
|
-
EnforcerBase.prototype.initializeProducts = function (config, products, base64Utils, hashUtils, ipRangeChecker) {
|
|
283
|
+
EnforcerBase.prototype.initializeProducts = function (config, products, base64Utils, hashUtils, urlUtils, ipRangeChecker) {
|
|
283
284
|
var _a;
|
|
284
|
-
var botDefender = (products === null || products === void 0 ? void 0 : products.bd) || new products_1.BotDefender(config, { base64Utils: base64Utils, ipRangeChecker: ipRangeChecker });
|
|
285
|
+
var botDefender = (products === null || products === void 0 ? void 0 : products.bd) || new products_1.BotDefender(config, { base64Utils: base64Utils, ipRangeChecker: ipRangeChecker, urlUtils: urlUtils });
|
|
285
286
|
var accountDefender = (products === null || products === void 0 ? void 0 : products.ad) || new products_1.AccountDefender(config, { base64Utils: base64Utils });
|
|
286
287
|
var credentialIntelligence = config.ciEnabled
|
|
287
|
-
? (products === null || products === void 0 ? void 0 : products.ci) || new products_1.CredentialIntelligence(config, hashUtils)
|
|
288
|
+
? (products === null || products === void 0 ? void 0 : products.ci) || new products_1.CredentialIntelligence(config, { hashUtils: hashUtils, urlUtils: urlUtils })
|
|
288
289
|
: null;
|
|
289
290
|
var hypeSaleChallenge = (products === null || products === void 0 ? void 0 : products.hsc) || new products_2.HypeSaleChallenge(config, { base64Utils: base64Utils });
|
|
290
291
|
return _a = {},
|
|
@@ -24,5 +24,3 @@ __exportStar(require("./IBody"), exports);
|
|
|
24
24
|
__exportStar(require("./IHeaders"), exports);
|
|
25
25
|
__exportStar(require("./IFormData"), exports);
|
|
26
26
|
__exportStar(require("./ReadonlyHeaders"), exports);
|
|
27
|
-
__exportStar(require("./IURL"), exports);
|
|
28
|
-
__exportStar(require("./IURLSearchParams"), exports);
|
|
@@ -5,7 +5,7 @@ var FormDataImpl = /** @class */ (function () {
|
|
|
5
5
|
function FormDataImpl(data) {
|
|
6
6
|
this.data = data !== null && data !== void 0 ? data : {};
|
|
7
7
|
}
|
|
8
|
-
FormDataImpl.prototype.append = function (name, value
|
|
8
|
+
FormDataImpl.prototype.append = function (name, value) {
|
|
9
9
|
this.data[name] = (this.data[name] || []).concat(value);
|
|
10
10
|
};
|
|
11
11
|
FormDataImpl.prototype.delete = function (name) {
|
|
@@ -30,13 +30,10 @@ var FormDataImpl = /** @class */ (function () {
|
|
|
30
30
|
FormDataImpl.prototype.has = function (name) {
|
|
31
31
|
return this.get(name) !== null;
|
|
32
32
|
};
|
|
33
|
-
FormDataImpl.prototype.set = function (name, value
|
|
33
|
+
FormDataImpl.prototype.set = function (name, value) {
|
|
34
34
|
if (typeof value === 'string') {
|
|
35
35
|
this.data[name] = [value];
|
|
36
36
|
}
|
|
37
|
-
else if (File) {
|
|
38
|
-
this.data[name] = [new File([value], filename)];
|
|
39
|
-
}
|
|
40
37
|
};
|
|
41
38
|
return FormDataImpl;
|
|
42
39
|
}());
|
|
@@ -22,6 +22,3 @@ __exportStar(require("./MultipartFormDataUtils"), exports);
|
|
|
22
22
|
__exportStar(require("./FormDataImpl"), exports);
|
|
23
23
|
__exportStar(require("./MinimalResponseImpl"), exports);
|
|
24
24
|
__exportStar(require("./OutgoingRequestImpl"), exports);
|
|
25
|
-
__exportStar(require("./UrlImpl"), exports);
|
|
26
|
-
__exportStar(require("./UrlSearchParamsImpl"), exports);
|
|
27
|
-
__exportStar(require("./URLUtils"), exports);
|
|
@@ -61,6 +61,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
62
|
exports.CryptoCipherUtils = void 0;
|
|
63
63
|
var crypto = __importStar(require("crypto"));
|
|
64
|
+
var utils_1 = require("../../utils");
|
|
64
65
|
var CryptoCipherUtils = /** @class */ (function () {
|
|
65
66
|
function CryptoCipherUtils(cryptoModule) {
|
|
66
67
|
if (cryptoModule === void 0) { cryptoModule = crypto; }
|
|
@@ -72,7 +73,7 @@ var CryptoCipherUtils = /** @class */ (function () {
|
|
|
72
73
|
return __generator(this, function (_a) {
|
|
73
74
|
keylen = (options === null || options === void 0 ? void 0 : options.keylen) || 32;
|
|
74
75
|
ivlen = (options === null || options === void 0 ? void 0 : options.ivlen) || 16;
|
|
75
|
-
derivation = this.crypto.pbkdf2Sync(secret, Buffer.from(salt, 'base64'), iterations, keylen + ivlen,
|
|
76
|
+
derivation = this.crypto.pbkdf2Sync(secret, Buffer.from(salt, 'base64'), iterations, keylen + ivlen, (0, utils_1.algoToCryptoString)(utils_1.Algorithm.SHA256));
|
|
76
77
|
key = derivation.subarray(0, keylen);
|
|
77
78
|
iv = derivation.subarray(keylen);
|
|
78
79
|
cipher = this.crypto.createDecipheriv('aes-256-cbc', key, iv);
|
|
@@ -61,6 +61,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
62
|
exports.CryptoHashUtils = void 0;
|
|
63
63
|
var crypto = __importStar(require("crypto"));
|
|
64
|
+
var utils_1 = require("../../utils");
|
|
64
65
|
var CryptoHashUtils = /** @class */ (function () {
|
|
65
66
|
function CryptoHashUtils(cryptoModule) {
|
|
66
67
|
if (cryptoModule === void 0) { cryptoModule = crypto; }
|
|
@@ -69,7 +70,7 @@ var CryptoHashUtils = /** @class */ (function () {
|
|
|
69
70
|
CryptoHashUtils.prototype.hashString = function (text, algo) {
|
|
70
71
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
72
|
return __generator(this, function (_a) {
|
|
72
|
-
return [2 /*return*/, this.crypto.createHash(algo).update(text).digest('hex')];
|
|
73
|
+
return [2 /*return*/, this.crypto.createHash((0, utils_1.algoToCryptoString)(algo)).update(text).digest('hex')];
|
|
73
74
|
});
|
|
74
75
|
});
|
|
75
76
|
};
|
|
@@ -1,27 +1,4 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -60,7 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
60
37
|
};
|
|
61
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
39
|
exports.SubtleCryptoHashUtils = void 0;
|
|
63
|
-
var crypto = __importStar(require("crypto"));
|
|
64
40
|
var utils_1 = require("../../utils");
|
|
65
41
|
var SubtleCryptoHashUtils = /** @class */ (function () {
|
|
66
42
|
function SubtleCryptoHashUtils(subtleCrypto) {
|
|
@@ -74,7 +50,7 @@ var SubtleCryptoHashUtils = /** @class */ (function () {
|
|
|
74
50
|
switch (_a.label) {
|
|
75
51
|
case 0:
|
|
76
52
|
textUint8 = new TextEncoder().encode(text);
|
|
77
|
-
return [4 /*yield*/, this.subtle.digest(
|
|
53
|
+
return [4 /*yield*/, this.subtle.digest((0, utils_1.algoToSubtleCryptoString)(algo), textUint8)];
|
|
78
54
|
case 1:
|
|
79
55
|
hashBuffer = _a.sent();
|
|
80
56
|
hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
@@ -83,13 +59,6 @@ var SubtleCryptoHashUtils = /** @class */ (function () {
|
|
|
83
59
|
});
|
|
84
60
|
});
|
|
85
61
|
};
|
|
86
|
-
SubtleCryptoHashUtils.prototype.convertAlgo = function (algo) {
|
|
87
|
-
switch (algo) {
|
|
88
|
-
case utils_1.Algorithm.SHA256:
|
|
89
|
-
default:
|
|
90
|
-
return 'SHA-256';
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
62
|
return SubtleCryptoHashUtils;
|
|
94
63
|
}());
|
|
95
64
|
exports.SubtleCryptoHashUtils = SubtleCryptoHashUtils;
|
|
@@ -32,16 +32,11 @@ var CryptoHmacUtils = /** @class */ (function () {
|
|
|
32
32
|
this.crypto = cryptoModule;
|
|
33
33
|
}
|
|
34
34
|
CryptoHmacUtils.prototype.createHmac = function (algo, payload, secret) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
hmac.end();
|
|
41
|
-
return hmac.read();
|
|
42
|
-
default:
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
35
|
+
var hmac = this.crypto.createHmac((0, utils_1.algoToCryptoString)(algo), secret);
|
|
36
|
+
hmac.setEncoding('hex');
|
|
37
|
+
hmac.write(payload);
|
|
38
|
+
hmac.end();
|
|
39
|
+
return hmac.read();
|
|
45
40
|
};
|
|
46
41
|
return CryptoHmacUtils;
|
|
47
42
|
}());
|
|
@@ -0,0 +1,72 @@
|
|
|
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.SubtleCryptoHmacUtils = void 0;
|
|
40
|
+
var utils_1 = require("../../utils");
|
|
41
|
+
var SubtleCryptoHmacUtils = /** @class */ (function () {
|
|
42
|
+
function SubtleCryptoHmacUtils(subtleCrypto) {
|
|
43
|
+
if (subtleCrypto === void 0) { subtleCrypto = crypto.subtle; }
|
|
44
|
+
this.subtle = subtleCrypto;
|
|
45
|
+
}
|
|
46
|
+
SubtleCryptoHmacUtils.prototype.createHmac = function (algo, payload, secret) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var encodedStr, encodedPassword, importedKey, signature;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
encodedStr = new TextEncoder().encode(payload);
|
|
53
|
+
encodedPassword = new TextEncoder().encode(secret);
|
|
54
|
+
return [4 /*yield*/, this.subtle.importKey('raw', encodedPassword, { name: 'HMAC', hash: { name: (0, utils_1.algoToSubtleCryptoString)(algo) } }, false, ['sign'])];
|
|
55
|
+
case 1:
|
|
56
|
+
importedKey = _a.sent();
|
|
57
|
+
return [4 /*yield*/, this.subtle.sign({ name: 'HMAC' }, importedKey, encodedStr)];
|
|
58
|
+
case 2:
|
|
59
|
+
signature = _a.sent();
|
|
60
|
+
return [2 /*return*/, this.bufferToHex(signature)];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
SubtleCryptoHmacUtils.prototype.bufferToHex = function (buffer) {
|
|
66
|
+
return Array.prototype.map
|
|
67
|
+
.call(new Uint8Array(buffer), function (x) { return ('00' + x.toString(16)).slice(-2); })
|
|
68
|
+
.join('');
|
|
69
|
+
};
|
|
70
|
+
return SubtleCryptoHmacUtils;
|
|
71
|
+
}());
|
|
72
|
+
exports.SubtleCryptoHmacUtils = SubtleCryptoHmacUtils;
|
|
@@ -38,6 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.PhinIncomingResponse = void 0;
|
|
40
40
|
var http_1 = require("../../../http");
|
|
41
|
+
var DefaultUrlUtils_1 = require("../../url/DefaultUrlUtils");
|
|
41
42
|
var PhinIncomingResponse = /** @class */ (function () {
|
|
42
43
|
function PhinIncomingResponse(response) {
|
|
43
44
|
this.status = response.statusCode;
|
|
@@ -67,9 +68,11 @@ var PhinIncomingResponse = /** @class */ (function () {
|
|
|
67
68
|
return __generator(this, function (_c) {
|
|
68
69
|
switch (_c.label) {
|
|
69
70
|
case 0:
|
|
70
|
-
_b = (_a =
|
|
71
|
+
_b = (_a = new DefaultUrlUtils_1.DefaultUrlUtils()).createUrlSearchParams;
|
|
71
72
|
return [4 /*yield*/, this.text()];
|
|
72
|
-
case 1:
|
|
73
|
+
case 1:
|
|
74
|
+
// Using DefaultUrlUtils since Phin safely assumes Node.js environment
|
|
75
|
+
return [2 /*return*/, _b.apply(_a, [_c.sent()])];
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
78
|
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomImplUrlUtils = void 0;
|
|
4
|
+
var utils_1 = require("../../utils");
|
|
5
|
+
var UrlImpl_1 = require("./UrlImpl");
|
|
6
|
+
var UrlSearchParamsImpl_1 = require("./UrlSearchParamsImpl");
|
|
7
|
+
var CustomImplUrlUtils = /** @class */ (function () {
|
|
8
|
+
function CustomImplUrlUtils() {
|
|
9
|
+
}
|
|
10
|
+
CustomImplUrlUtils.prototype.createUrl = function (rawUrl) {
|
|
11
|
+
return new UrlImpl_1.UrlImpl(rawUrl);
|
|
12
|
+
};
|
|
13
|
+
CustomImplUrlUtils.prototype.createUrlSearchParams = function (params) {
|
|
14
|
+
return new UrlSearchParamsImpl_1.UrlSearchParamsImpl(this, params);
|
|
15
|
+
};
|
|
16
|
+
CustomImplUrlUtils.prototype.decodeUriComponent = function (uriComponent) {
|
|
17
|
+
// https://www.npmjs.com/package/as-uri-encode-decode
|
|
18
|
+
// Note: Does not work well with multibyte characters
|
|
19
|
+
var result = '';
|
|
20
|
+
for (var i = 0; i < uriComponent.length; i++) {
|
|
21
|
+
if (uriComponent.charAt(i) === '+') {
|
|
22
|
+
result += ' ';
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (uriComponent.charAt(i) === '%' &&
|
|
26
|
+
uriComponent.charAt(i + 1) !== '%' &&
|
|
27
|
+
uriComponent.charAt(i + 2) !== '%') {
|
|
28
|
+
var charCode = parseInt(uriComponent.charAt(i + 1) + uriComponent.charAt(i + 2), 16);
|
|
29
|
+
var char = String.fromCharCode(charCode);
|
|
30
|
+
result += char;
|
|
31
|
+
i += 2;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
result += uriComponent.charAt(i);
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
CustomImplUrlUtils.prototype.encodeUriComponent = function (uriComponent) {
|
|
39
|
+
// https://www.npmjs.com/package/as-uri-encode-decode
|
|
40
|
+
// Note: Does not work well with multibyte characters
|
|
41
|
+
var result = '';
|
|
42
|
+
for (var i = 0; i < uriComponent.length; i++) {
|
|
43
|
+
var c = uriComponent.charAt(i);
|
|
44
|
+
if (this.isSafe(c)) {
|
|
45
|
+
result += c;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
result += '%' + c.charCodeAt(0).toString(16).toUpperCase();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
CustomImplUrlUtils.prototype.encodeUri = function (uri) {
|
|
54
|
+
throw new utils_1.EnforcerError('method not implemented: CustomImplUrlUtils.encodeUri()');
|
|
55
|
+
};
|
|
56
|
+
CustomImplUrlUtils.prototype.decodeUri = function (uri) {
|
|
57
|
+
throw new utils_1.EnforcerError('method not implemented: CustomImplUrlUtils.decodeUri()');
|
|
58
|
+
};
|
|
59
|
+
CustomImplUrlUtils.prototype.isSafe = function (c) {
|
|
60
|
+
return ((c >= 'a' && c <= 'z') ||
|
|
61
|
+
(c >= 'A' && c <= 'Z') ||
|
|
62
|
+
(c >= '0' && c <= '9') ||
|
|
63
|
+
c == '-' ||
|
|
64
|
+
c == '_' ||
|
|
65
|
+
c == '.' ||
|
|
66
|
+
c == '*' ||
|
|
67
|
+
c == '!');
|
|
68
|
+
};
|
|
69
|
+
return CustomImplUrlUtils;
|
|
70
|
+
}());
|
|
71
|
+
exports.CustomImplUrlUtils = CustomImplUrlUtils;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultUrlUtils = void 0;
|
|
4
|
+
var DefaultUrlUtils = /** @class */ (function () {
|
|
5
|
+
function DefaultUrlUtils() {
|
|
6
|
+
}
|
|
7
|
+
DefaultUrlUtils.prototype.createUrl = function (rawUrl) {
|
|
8
|
+
return new URL(rawUrl);
|
|
9
|
+
};
|
|
10
|
+
DefaultUrlUtils.prototype.createUrlSearchParams = function (params) {
|
|
11
|
+
return new URLSearchParams(params);
|
|
12
|
+
};
|
|
13
|
+
DefaultUrlUtils.prototype.decodeUriComponent = function (uriComponent) {
|
|
14
|
+
return decodeURIComponent(uriComponent);
|
|
15
|
+
};
|
|
16
|
+
DefaultUrlUtils.prototype.encodeUriComponent = function (uriComponent) {
|
|
17
|
+
return encodeURIComponent(uriComponent);
|
|
18
|
+
};
|
|
19
|
+
DefaultUrlUtils.prototype.decodeUri = function (uri) {
|
|
20
|
+
return decodeURI(uri);
|
|
21
|
+
};
|
|
22
|
+
DefaultUrlUtils.prototype.encodeUri = function (uri) {
|
|
23
|
+
return encodeURI(uri);
|
|
24
|
+
};
|
|
25
|
+
return DefaultUrlUtils;
|
|
26
|
+
}());
|
|
27
|
+
exports.DefaultUrlUtils = DefaultUrlUtils;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UrlImpl = void 0;
|
|
4
4
|
var utils_1 = require("../../utils");
|
|
5
|
-
var
|
|
5
|
+
var UrlSearchParamsImpl_1 = require("./UrlSearchParamsImpl");
|
|
6
|
+
var CustomImplUrlUtils_1 = require("./CustomImplUrlUtils");
|
|
6
7
|
var UrlImpl = /** @class */ (function () {
|
|
7
8
|
function UrlImpl(rawUrl) {
|
|
8
9
|
var match = rawUrl.match(utils_1.URL_REGEX);
|
|
@@ -56,7 +57,7 @@ var UrlImpl = /** @class */ (function () {
|
|
|
56
57
|
});
|
|
57
58
|
Object.defineProperty(UrlImpl.prototype, "searchParams", {
|
|
58
59
|
get: function () {
|
|
59
|
-
return
|
|
60
|
+
return new UrlSearchParamsImpl_1.UrlSearchParamsImpl(new CustomImplUrlUtils_1.CustomImplUrlUtils(), this.search);
|
|
60
61
|
},
|
|
61
62
|
enumerable: false,
|
|
62
63
|
configurable: true
|