perimeterx-js-core 0.7.1 → 0.8.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.
- package/lib/action/utils.js +1 -1
- package/lib/activities/HttpActivityClient.d.ts +5 -5
- package/lib/activities/HttpActivityClient.js +28 -39
- package/lib/activities/HttpBatchedActivityClient.d.ts +2 -2
- package/lib/activities/HttpBatchedActivityClient.js +19 -32
- package/lib/activities/model/AsyncActivity.d.ts +14 -0
- package/lib/activities/model/{ActivityDetails.d.ts → AsyncActivityDetails.d.ts} +6 -23
- package/lib/activities/model/CommonActivityDetails.d.ts +40 -0
- package/lib/activities/model/CommonActivityDetails.js +1 -0
- package/lib/activities/model/HeaderEntry.d.ts +4 -0
- package/lib/activities/model/HeaderEntry.js +1 -0
- package/lib/activities/model/index.d.ts +4 -2
- package/lib/activities/model/index.js +4 -2
- package/lib/activities/utils.d.ts +6071 -9
- package/lib/activities/utils.js +111 -35
- package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +4 -12
- package/lib/config/ConfigurationParams.d.ts +1 -1
- package/lib/config/IConfiguration.d.ts +1 -1
- package/lib/config/StaticConfigurationBase.d.ts +1 -1
- package/lib/config/StaticConfigurationBase.js +3 -1
- package/lib/context/DefaultContext.d.ts +1 -1
- package/lib/context/DefaultContext.js +40 -8
- package/lib/context/interfaces/RiskApiData.d.ts +4 -0
- package/lib/cors/DefaultCors.js +21 -31
- package/lib/custom_parameters/CustomParametersUtils.js +3 -12
- package/lib/enforcer/EnforcerBase.js +51 -62
- package/lib/graphql/DefaultGraphQLParser.js +30 -39
- package/lib/http/index.d.ts +0 -1
- package/lib/http/index.js +0 -1
- package/lib/http/interfaces/IBody.d.ts +3 -2
- package/lib/http/interfaces/IIncomingRequest.d.ts +4 -0
- package/lib/http/interfaces/IURL.d.ts +3 -0
- package/lib/http/interfaces/IURLSearchParams.d.ts +9 -0
- package/lib/http/interfaces/IURLSearchParams.js +1 -0
- package/lib/http/interfaces/index.d.ts +1 -0
- package/lib/http/interfaces/index.js +1 -0
- package/lib/http/{impl → utils}/FormDataImpl.js +4 -4
- package/lib/http/{impl → utils}/MinimalResponseImpl.js +3 -0
- package/lib/http/utils/MinimalResponseUtils.js +5 -7
- package/lib/http/utils/MultipartFormDataUtils.js +4 -5
- package/lib/http/{impl → utils}/OutgoingRequestImpl.d.ts +1 -1
- package/lib/http/{impl → utils}/OutgoingRequestImpl.js +5 -1
- package/lib/http/utils/URLUtils.d.ts +7 -0
- package/lib/http/utils/URLUtils.js +62 -0
- package/lib/http/utils/UrlImpl.d.ts +18 -0
- package/lib/http/utils/UrlImpl.js +54 -0
- package/lib/http/utils/UrlSearchParamsImpl.d.ts +19 -0
- package/lib/http/utils/UrlSearchParamsImpl.js +116 -0
- package/lib/http/utils/index.d.ts +6 -0
- package/lib/http/utils/index.js +6 -0
- package/lib/{utils → impl}/base64/AtobBase64Utils.d.ts +1 -1
- package/lib/{utils → impl}/base64/BufferBase64Utils.d.ts +1 -1
- package/lib/{utils → impl}/base64/BufferBase64Utils.js +1 -1
- package/lib/{utils → impl}/base64/JSBase64Base64Utils.d.ts +1 -1
- package/lib/{utils → impl}/cipher/CryptoCipherUtils.d.ts +1 -1
- package/lib/impl/cipher/CryptoCipherUtils.js +18 -0
- package/lib/{utils → impl}/cipher/SubtleCryptoCipherUtils.d.ts +1 -2
- package/lib/impl/cipher/SubtleCryptoCipherUtils.js +38 -0
- package/lib/{utils → impl}/hash/CryptoHashUtils.d.ts +1 -2
- package/lib/impl/hash/CryptoHashUtils.js +10 -0
- package/lib/{utils → impl}/hash/CryptoJSHashUtils.d.ts +1 -2
- package/lib/{utils → impl}/hash/CryptoJSHashUtils.js +1 -1
- package/lib/{utils → impl}/hash/SubtleCryptoHashUtils.d.ts +1 -2
- package/lib/impl/hash/SubtleCryptoHashUtils.js +21 -0
- package/lib/{utils → impl}/hmac/CryptoHmacUtils.d.ts +1 -2
- package/lib/{utils → impl}/hmac/CryptoHmacUtils.js +2 -1
- package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.d.ts +1 -2
- package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.js +1 -1
- package/lib/{http/impl → impl/http}/phin/PhinHttpClient.d.ts +1 -1
- package/lib/impl/http/phin/PhinHttpClient.js +31 -0
- package/lib/{http/impl → impl/http}/phin/PhinIncomingResponse.d.ts +2 -2
- package/lib/impl/http/phin/PhinIncomingResponse.js +23 -0
- package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.d.ts +1 -1
- package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.d.ts +1 -1
- package/lib/{utils → impl}/url_parser/DefaultUrlParser.d.ts +4 -4
- package/lib/{utils → impl}/url_parser/DefaultUrlParser.js +9 -2
- package/lib/logger/HttpLogServiceClient.js +27 -35
- package/lib/logger/LoggerBase.js +2 -0
- package/lib/phase/impl/AdditionalActivityHandlerPhase.js +4 -15
- package/lib/phase/impl/CompositePhase.js +9 -19
- package/lib/phase/impl/CreateBlockResponsePhase.js +24 -35
- package/lib/phase/impl/DecideActionPhase.js +11 -21
- package/lib/phase/impl/EnrichContextFromRequestPhase.js +28 -45
- package/lib/phase/impl/EnrichContextFromResponsePhase.js +12 -23
- package/lib/phase/impl/FilterPhase.js +3 -13
- package/lib/phase/impl/FirstPartyPhase.js +21 -32
- package/lib/phase/impl/ModifyIncomingRequestPhase.js +4 -14
- package/lib/phase/impl/ModifyOutgoingResponsePhase.js +7 -18
- package/lib/phase/impl/ParseTokenPhase.js +5 -15
- package/lib/phase/impl/PreflightPhase.js +12 -20
- package/lib/phase/impl/RiskApiPhase.js +24 -36
- package/lib/phase/impl/SendAsyncActivitiesOnRequestPhase.js +8 -20
- package/lib/phase/impl/SendAsyncActivitiesOnResponsePhase.js +4 -14
- package/lib/phase/impl/SendLogsPhase.js +8 -18
- package/lib/phase/impl/TelemetryPhase.js +9 -21
- package/lib/products/account_defender/AccountDefender.js +16 -35
- package/lib/products/bot_defender/BotDefender.js +51 -72
- package/lib/products/bot_defender/BotDefenderActionData.js +2 -0
- package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.d.ts +4 -4
- package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.js +5 -3
- package/lib/products/bot_defender/block/captcha/CaptchaBlocker.d.ts +7 -4
- package/lib/products/bot_defender/block/captcha/CaptchaBlocker.js +12 -8
- package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +1 -1
- package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +1 -0
- package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +1 -1
- package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +5 -4
- package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.d.ts +2 -2
- package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.js +2 -0
- package/lib/products/bot_defender/block/utils.js +1 -2
- package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +2 -0
- package/lib/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +51 -68
- package/lib/products/bot_defender/first_party/constants.d.ts +0 -4
- package/lib/products/bot_defender/first_party/constants.js +0 -7
- package/lib/products/credential_intelligence/CredentialIntelligence.js +42 -63
- package/lib/products/credential_intelligence/endpoint/CredentialEndpoint.js +15 -23
- package/lib/products/credential_intelligence/endpoint/CredentialEndpointManager.js +9 -22
- package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +5 -5
- package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +22 -33
- package/lib/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +8 -18
- package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +2 -0
- package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +11 -16
- package/lib/products/credential_intelligence/endpoint/hash_protocol/MultistepHashProtocol.js +11 -21
- package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepAndMultistepHashProtocol.js +9 -18
- package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepHashProtocol.js +13 -25
- package/lib/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -14
- package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulParser.js +10 -20
- package/lib/products/credential_intelligence/endpoint/login_successful/HeaderLoginSuccessfulParser.js +7 -16
- package/lib/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +7 -6
- package/lib/products/credential_intelligence/endpoint/login_successful/StatusLoginSuccessfulParser.js +3 -13
- package/lib/products/credential_intelligence/endpoint/matcher/ExactPathEndpointMatcher.js +2 -0
- package/lib/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +2 -0
- package/lib/pxde/DefaultDataEnrichment.js +47 -61
- package/lib/pxhd/PXHDUtils.js +2 -2
- package/lib/risk_api/client/PostRiskApiClientBase.d.ts +7 -12
- package/lib/risk_api/client/PostRiskApiClientBase.js +70 -171
- package/lib/risk_api/model/RiskActivity.d.ts +5 -45
- package/lib/risk_api/risk_response/IRiskResponse.d.ts +1 -0
- package/lib/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
- package/lib/risk_api/risk_response/RiskResponseBase.js +20 -33
- package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.d.ts +1 -1
- package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.js +3 -5
- package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -0
- package/lib/risk_api/risk_response/v3/DefaultRiskResponseV3.js +2 -4
- package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -0
- package/lib/risk_token/parser/TokenParserBase.js +25 -36
- package/lib/risk_token/token/TokenBase.js +24 -29
- package/lib/risk_token/token/v2/DefaultTokenV2.js +34 -49
- package/lib/risk_token/token/v3/DefaultTokenV3.js +63 -77
- package/lib/telemetry/DefaultTelemetry.js +46 -58
- package/lib/utils/base64/index.d.ts +0 -3
- package/lib/utils/base64/index.js +0 -3
- package/lib/utils/cipher/index.d.ts +1 -3
- package/lib/utils/cipher/index.js +1 -2
- package/lib/utils/constants.d.ts +2 -1
- package/lib/utils/constants.js +2 -1
- package/lib/utils/hash/index.d.ts +0 -3
- package/lib/utils/hash/index.js +0 -3
- package/lib/utils/hmac/index.d.ts +0 -2
- package/lib/utils/hmac/index.js +0 -2
- package/lib/utils/ip_range_checker/index.d.ts +1 -2
- package/lib/utils/ip_range_checker/index.js +1 -1
- package/lib/utils/request_id_generator/index.d.ts +1 -2
- package/lib/utils/request_id_generator/index.js +1 -1
- package/lib/utils/url_parser/index.d.ts +0 -1
- package/lib/utils/url_parser/index.js +0 -1
- package/lib/utils/utils.d.ts +1 -7
- package/lib/utils/utils.js +3 -25
- package/package.json +12 -6
- package/lib/activities/model/Activity.d.ts +0 -13
- package/lib/http/impl/index.d.ts +0 -4
- package/lib/http/impl/index.js +0 -4
- package/lib/http/impl/phin/PhinHttpClient.js +0 -41
- package/lib/http/impl/phin/PhinIncomingResponse.js +0 -38
- package/lib/utils/cipher/CryptoCipherUtils.js +0 -28
- package/lib/utils/cipher/SubtleCryptoCipherUtils.js +0 -47
- package/lib/utils/hash/CryptoHashUtils.js +0 -20
- package/lib/utils/hash/SubtleCryptoHashUtils.js +0 -31
- /package/lib/activities/model/{Activity.js → AsyncActivity.js} +0 -0
- /package/lib/activities/model/{ActivityDetails.js → AsyncActivityDetails.js} +0 -0
- /package/lib/http/{impl → utils}/FormDataImpl.d.ts +0 -0
- /package/lib/http/{impl → utils}/MinimalResponseImpl.d.ts +0 -0
- /package/lib/{utils → impl}/base64/AtobBase64Utils.js +0 -0
- /package/lib/{utils → impl}/base64/JSBase64Base64Utils.js +0 -0
- /package/lib/{http/impl → impl/http}/phin/index.d.ts +0 -0
- /package/lib/{http/impl → impl/http}/phin/index.js +0 -0
- /package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.js +0 -0
- /package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.js +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class SubtleCryptoCipherUtils {
|
|
2
|
+
base64Utils;
|
|
3
|
+
subtleCrypto;
|
|
4
|
+
constructor(base64Utils, subtleCrypto = crypto.subtle) {
|
|
5
|
+
this.subtleCrypto = subtleCrypto;
|
|
6
|
+
this.base64Utils = base64Utils;
|
|
7
|
+
}
|
|
8
|
+
async pbkdf2Decrypt(secret, encryptedString, iterations, salt, options) {
|
|
9
|
+
const ivlen = options?.ivlen || 16;
|
|
10
|
+
const keylen = options?.keylen || 32;
|
|
11
|
+
const bitsLength = (ivlen + keylen) * 8;
|
|
12
|
+
const encodedPassword = new TextEncoder().encode(secret);
|
|
13
|
+
const encodedSalt = this.base64ToArrayBuffer(salt);
|
|
14
|
+
const importedKey = await this.subtleCrypto.importKey('raw', encodedPassword, 'PBKDF2', false, ['deriveBits']);
|
|
15
|
+
const params = { name: 'PBKDF2', hash: 'SHA-256', salt: encodedSalt, iterations: iterations };
|
|
16
|
+
const derivation = await this.subtleCrypto.deriveBits(params, importedKey, bitsLength);
|
|
17
|
+
const derivedKey = derivation.slice(0, keylen);
|
|
18
|
+
const iv = derivation.slice(keylen);
|
|
19
|
+
const cookieBuffer = this.base64ToArrayBuffer(encryptedString);
|
|
20
|
+
const importedDecryptionKey = await this.subtleCrypto.importKey('raw', derivedKey, { name: 'AES-CBC' }, false, [
|
|
21
|
+
'decrypt',
|
|
22
|
+
]);
|
|
23
|
+
const decrypted = await this.subtleCrypto.decrypt({
|
|
24
|
+
name: 'AES-CBC',
|
|
25
|
+
iv: iv,
|
|
26
|
+
}, importedDecryptionKey, cookieBuffer);
|
|
27
|
+
return new TextDecoder('utf-8').decode(decrypted);
|
|
28
|
+
}
|
|
29
|
+
base64ToArrayBuffer(base64String) {
|
|
30
|
+
const binaryString = this.base64Utils.base64Decode(base64String);
|
|
31
|
+
const length = binaryString.length;
|
|
32
|
+
const bytes = new Uint8Array(length);
|
|
33
|
+
binaryString.split('').forEach((char, index) => {
|
|
34
|
+
bytes[index] = char.charCodeAt(0);
|
|
35
|
+
});
|
|
36
|
+
return bytes.buffer;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as crypto from 'crypto';
|
|
3
|
-
import { IHashUtils } from '
|
|
4
|
-
import { Algorithm } from '../Algorithm';
|
|
3
|
+
import { Algorithm, IHashUtils } from '../../utils';
|
|
5
4
|
declare type CryptoModule = typeof crypto;
|
|
6
5
|
export declare class CryptoHashUtils implements IHashUtils {
|
|
7
6
|
private readonly crypto;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Algorithm } from '
|
|
2
|
-
import { IHashUtils } from './IHashUtils';
|
|
1
|
+
import { Algorithm, IHashUtils } from '../../utils';
|
|
3
2
|
export declare class SubtleCryptoHashUtils implements IHashUtils {
|
|
4
3
|
private readonly subtle;
|
|
5
4
|
constructor(subtleCrypto?: SubtleCrypto);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
import { Algorithm } from '../../utils';
|
|
3
|
+
export class SubtleCryptoHashUtils {
|
|
4
|
+
subtle;
|
|
5
|
+
constructor(subtleCrypto = crypto.subtle) {
|
|
6
|
+
this.subtle = subtleCrypto;
|
|
7
|
+
}
|
|
8
|
+
async hashString(text, algo) {
|
|
9
|
+
const textUint8 = new TextEncoder().encode(text);
|
|
10
|
+
const hashBuffer = await this.subtle.digest(this.convertAlgo(algo), textUint8);
|
|
11
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
12
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
13
|
+
}
|
|
14
|
+
convertAlgo(algo) {
|
|
15
|
+
switch (algo) {
|
|
16
|
+
case Algorithm.SHA256:
|
|
17
|
+
default:
|
|
18
|
+
return 'SHA-256';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as crypto from 'crypto';
|
|
3
|
-
import { IHmacUtils } from '
|
|
4
|
-
import { Algorithm } from '../Algorithm';
|
|
3
|
+
import { Algorithm, IHmacUtils } from '../../utils';
|
|
5
4
|
declare type CryptoModule = typeof crypto;
|
|
6
5
|
export declare class CryptoHmacUtils implements IHmacUtils {
|
|
7
6
|
private readonly crypto;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IHmacUtils } from '
|
|
2
|
-
import { Algorithm } from '../Algorithm';
|
|
1
|
+
import { Algorithm, IHmacUtils } from '../../utils';
|
|
3
2
|
export declare class CryptoJSHmacUtils implements IHmacUtils {
|
|
4
3
|
createHmac(algo: Algorithm, payload: string, secret: string): string;
|
|
5
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpSendOptions, IHttpClient, IIncomingResponse, IOutgoingRequest } from '
|
|
1
|
+
import { HttpSendOptions, IHttpClient, IIncomingResponse, IOutgoingRequest } from '../../../http/interfaces';
|
|
2
2
|
export declare class PhinHttpClient implements IHttpClient {
|
|
3
3
|
private readonly httpsKeepAliveAgent;
|
|
4
4
|
constructor();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Agent as HttpAgent } from 'http';
|
|
2
|
+
import { Agent as HttpsAgent } from 'https';
|
|
3
|
+
import phin from 'phin';
|
|
4
|
+
import { EnforcerTimeoutError } from '../../../utils';
|
|
5
|
+
import { joinHeaderValues, } from '../../../http/interfaces';
|
|
6
|
+
import { PhinIncomingResponse } from './PhinIncomingResponse';
|
|
7
|
+
export class PhinHttpClient {
|
|
8
|
+
httpsKeepAliveAgent;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.httpsKeepAliveAgent = new HttpsAgent({ keepAlive: true });
|
|
11
|
+
}
|
|
12
|
+
async send(request, options) {
|
|
13
|
+
try {
|
|
14
|
+
const res = await phin.promisified({
|
|
15
|
+
url: request.url,
|
|
16
|
+
method: request.method,
|
|
17
|
+
headers: joinHeaderValues(request.headers),
|
|
18
|
+
data: request.body,
|
|
19
|
+
timeout: options?.timeoutMs || null,
|
|
20
|
+
core: {
|
|
21
|
+
agent: request.url.startsWith('https://') ? this.httpsKeepAliveAgent : new HttpAgent(),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return new PhinIncomingResponse(res);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
const isTimeout = e.toString().toLowerCase().includes('timeout');
|
|
28
|
+
throw isTimeout ? new EnforcerTimeoutError(options.timeoutMs) : e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IResponse } from 'phin';
|
|
3
|
-
import { IFormData, IIncomingResponse, ReadonlyHeaders } from '
|
|
3
|
+
import { IFormData, IIncomingResponse, IURLSearchParams, ReadonlyHeaders } from '../../../http';
|
|
4
4
|
export declare class PhinIncomingResponse implements IIncomingResponse {
|
|
5
5
|
readonly status: number;
|
|
6
6
|
readonly headers: ReadonlyHeaders;
|
|
7
7
|
readonly body: Buffer;
|
|
8
8
|
constructor(response: IResponse);
|
|
9
9
|
formData(): Promise<IFormData>;
|
|
10
|
-
formUrlEncoded(): Promise<
|
|
10
|
+
formUrlEncoded(): Promise<IURLSearchParams>;
|
|
11
11
|
json(): Promise<any>;
|
|
12
12
|
text(): Promise<string>;
|
|
13
13
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CONTENT_TYPE_HEADER_NAME, MultipartFormDataUtils, URLUtils, } from '../../../http';
|
|
2
|
+
export class PhinIncomingResponse {
|
|
3
|
+
status;
|
|
4
|
+
headers;
|
|
5
|
+
body;
|
|
6
|
+
constructor(response) {
|
|
7
|
+
this.status = response.statusCode;
|
|
8
|
+
this.body = response.body;
|
|
9
|
+
this.headers = Object.fromEntries(Object.entries(response.headers).map(([key, val]) => [key, typeof val === 'string' ? [val] : val]));
|
|
10
|
+
}
|
|
11
|
+
async formData() {
|
|
12
|
+
return MultipartFormDataUtils.createFormDataWithoutFiles(await this.text(), this.headers[CONTENT_TYPE_HEADER_NAME]?.[0]);
|
|
13
|
+
}
|
|
14
|
+
async formUrlEncoded() {
|
|
15
|
+
return URLUtils.parseSearchParams(await this.text());
|
|
16
|
+
}
|
|
17
|
+
async json() {
|
|
18
|
+
return JSON.parse(await this.text());
|
|
19
|
+
}
|
|
20
|
+
async text() {
|
|
21
|
+
return this.body.toString();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { IURLParser } from './IURLParser';
|
|
2
1
|
import { IURL } from '../../http';
|
|
2
|
+
import { IURLParser } from '../../utils';
|
|
3
3
|
export type UrlParserOptions = {
|
|
4
4
|
normalize?: boolean;
|
|
5
5
|
reverseCharactersEncoding?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare class DefaultUrlParser implements IURLParser {
|
|
8
|
-
|
|
8
|
+
protected options: UrlParserOptions;
|
|
9
9
|
constructor(options?: UrlParserOptions);
|
|
10
10
|
parse(rawUrl: string): IURL;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
protected reverseCharactersEncoding(path: string): string;
|
|
12
|
+
protected normalize(path: string): string;
|
|
13
13
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { URLUtils } from '../../http';
|
|
1
2
|
export class DefaultUrlParser {
|
|
3
|
+
options;
|
|
2
4
|
constructor(options) {
|
|
3
|
-
this.options =
|
|
5
|
+
this.options = {
|
|
6
|
+
normalize: true,
|
|
7
|
+
reverseCharactersEncoding: false,
|
|
8
|
+
...options,
|
|
9
|
+
};
|
|
4
10
|
}
|
|
5
11
|
parse(rawUrl) {
|
|
6
|
-
const url =
|
|
12
|
+
const url = URLUtils.parseURL(rawUrl);
|
|
7
13
|
if (this.options.reverseCharactersEncoding) {
|
|
8
14
|
url.pathname = this.reverseCharactersEncoding(url.pathname);
|
|
9
15
|
}
|
|
@@ -13,6 +19,7 @@ export class DefaultUrlParser {
|
|
|
13
19
|
return url;
|
|
14
20
|
}
|
|
15
21
|
reverseCharactersEncoding(path) {
|
|
22
|
+
// NOTICE: Find a suitable polyfill in case decodeURI doesn't exist in the global scope
|
|
16
23
|
return decodeURI(path);
|
|
17
24
|
}
|
|
18
25
|
normalize(path) {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { EXTERNAL_LOGGER_SERVICE_PATH } from './constants';
|
|
11
|
-
import { AUTHORIZATION_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, ContentType, HttpMethod, OutgoingRequestImpl, } from '../http';
|
|
2
|
+
import { AUTHORIZATION_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, ContentType, HttpMethod, OutgoingRequestImpl, URLUtils, } from '../http';
|
|
12
3
|
import { getAuthorizationHeader } from '../utils';
|
|
13
4
|
export class HttpLogServiceClient {
|
|
5
|
+
appId;
|
|
6
|
+
backendUrl;
|
|
7
|
+
loggerAuthToken;
|
|
8
|
+
logger;
|
|
9
|
+
httpClient;
|
|
14
10
|
constructor(config, httpClient) {
|
|
15
11
|
this.appId = config.appId;
|
|
16
12
|
this.backendUrl = config.backendScoreApiUrl;
|
|
@@ -18,20 +14,18 @@ export class HttpLogServiceClient {
|
|
|
18
14
|
this.logger = config.logger;
|
|
19
15
|
this.httpClient = httpClient;
|
|
20
16
|
}
|
|
21
|
-
sendLogs(context, logs) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
17
|
+
async sendLogs(context, logs) {
|
|
18
|
+
try {
|
|
19
|
+
const enrichedLogs = logs.map((log) => this.enrichLogRecord(context, log));
|
|
20
|
+
await this.postLogs(enrichedLogs);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
this.logger.error(`unable to send logs: ${e}`);
|
|
24
|
+
}
|
|
31
25
|
}
|
|
32
26
|
enrichLogRecord(context, log) {
|
|
33
27
|
const requestData = context.requestData;
|
|
34
|
-
const url =
|
|
28
|
+
const url = URLUtils.parseURL(requestData.rawUrl);
|
|
35
29
|
const logMeta = {
|
|
36
30
|
container: 'enforcer',
|
|
37
31
|
appID: this.appId,
|
|
@@ -41,20 +35,18 @@ export class HttpLogServiceClient {
|
|
|
41
35
|
path: url.pathname + requestData.url.search,
|
|
42
36
|
requestId: context.requestId,
|
|
43
37
|
};
|
|
44
|
-
return
|
|
38
|
+
return { ...logMeta, ...log };
|
|
45
39
|
}
|
|
46
|
-
postLogs(logRecords) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return (res === null || res === void 0 ? void 0 : res.status) === 200;
|
|
58
|
-
});
|
|
40
|
+
async postLogs(logRecords) {
|
|
41
|
+
const url = `${this.backendUrl}${EXTERNAL_LOGGER_SERVICE_PATH}`;
|
|
42
|
+
const method = HttpMethod.POST;
|
|
43
|
+
const headers = {
|
|
44
|
+
[CONTENT_TYPE_HEADER_NAME]: [ContentType.APPLICATION_JSON],
|
|
45
|
+
[AUTHORIZATION_HEADER_NAME]: [getAuthorizationHeader(this.loggerAuthToken)],
|
|
46
|
+
};
|
|
47
|
+
const body = JSON.stringify(logRecords);
|
|
48
|
+
const req = new OutgoingRequestImpl({ url, method, headers, body });
|
|
49
|
+
const res = await this.httpClient.send(req);
|
|
50
|
+
return res?.status === 200;
|
|
59
51
|
}
|
|
60
52
|
}
|
package/lib/logger/LoggerBase.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { AdditionalActivityHandlerUtils } from '../../additional_activity_handler';
|
|
11
2
|
export class AdditionalActivityHandlerPhase {
|
|
3
|
+
config;
|
|
12
4
|
constructor(config) {
|
|
13
5
|
this.config = config;
|
|
14
6
|
}
|
|
15
|
-
execute(context) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
yield AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler(this.config, context);
|
|
19
|
-
return { done: false };
|
|
20
|
-
});
|
|
7
|
+
async execute(context) {
|
|
8
|
+
await AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler(this.config, context);
|
|
9
|
+
return { done: false };
|
|
21
10
|
}
|
|
22
11
|
}
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
export class CompositePhase {
|
|
2
|
+
phases;
|
|
11
3
|
constructor(phases) {
|
|
12
4
|
this.phases = phases;
|
|
13
5
|
}
|
|
14
|
-
execute(context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
6
|
+
async execute(context) {
|
|
7
|
+
let result;
|
|
8
|
+
for (const phase of this.phases) {
|
|
9
|
+
result = await phase.execute(context);
|
|
10
|
+
if (result.done) {
|
|
11
|
+
break;
|
|
22
12
|
}
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
25
15
|
}
|
|
26
16
|
}
|
|
@@ -1,42 +1,34 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { MinimalResponseUtils } from '../../http';
|
|
11
2
|
import { PXHDSource, PXHDUtils } from '../../pxhd';
|
|
12
3
|
import { Action } from '../../action';
|
|
13
4
|
import { PRODUCT_PRIORITY_ORDER } from '../../products';
|
|
14
5
|
export class CreateBlockResponsePhase {
|
|
6
|
+
config;
|
|
7
|
+
blockers;
|
|
8
|
+
cors;
|
|
15
9
|
constructor(config, blockers, cors) {
|
|
16
10
|
this.config = config;
|
|
17
11
|
this.blockers = blockers;
|
|
18
12
|
this.cors = cors;
|
|
19
13
|
}
|
|
20
|
-
execute(context) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return { done: true, response };
|
|
32
|
-
});
|
|
14
|
+
async execute(context) {
|
|
15
|
+
if (context.action !== Action.BLOCK) {
|
|
16
|
+
return { done: false };
|
|
17
|
+
}
|
|
18
|
+
this.config.logger.debug('create block response phase');
|
|
19
|
+
let response = this.createBlockResponse(context);
|
|
20
|
+
if (!response) {
|
|
21
|
+
return { done: false };
|
|
22
|
+
}
|
|
23
|
+
response = await this.addHeadersToResponse(response, context);
|
|
24
|
+
return { done: true, response };
|
|
33
25
|
}
|
|
34
26
|
createBlockResponse(context) {
|
|
35
27
|
let response = null;
|
|
36
28
|
for (const name of PRODUCT_PRIORITY_ORDER) {
|
|
37
29
|
if (context.reasons[name]) {
|
|
38
30
|
const blocker = this.blockers[name];
|
|
39
|
-
if (blocker
|
|
31
|
+
if (blocker?.shouldBlock(context)) {
|
|
40
32
|
this.config.logger.debug(`returning ${name} block response`);
|
|
41
33
|
response = blocker.createBlockResponse(context);
|
|
42
34
|
break;
|
|
@@ -45,17 +37,14 @@ export class CreateBlockResponsePhase {
|
|
|
45
37
|
}
|
|
46
38
|
return response;
|
|
47
39
|
}
|
|
48
|
-
addHeadersToResponse(response, context) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
return response;
|
|
59
|
-
});
|
|
40
|
+
async addHeadersToResponse(response, context) {
|
|
41
|
+
if (!context.isMobile && context.pxhd?.source === PXHDSource.RISK) {
|
|
42
|
+
response = PXHDUtils.addPxhdToMinimalResponse(context, response);
|
|
43
|
+
}
|
|
44
|
+
if (this.config.corsSupportEnabled && this.cors?.isCorsRequest(context)) {
|
|
45
|
+
const corsHeaders = await this.cors.getCorsBlockHeaders(context);
|
|
46
|
+
response = MinimalResponseUtils.appendHeaders(response, corsHeaders);
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
60
49
|
}
|
|
61
50
|
}
|
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { LoggerSeverity } from '../../logger';
|
|
11
2
|
import { getDecisionFromContext } from '../../action';
|
|
12
3
|
export class DecideActionPhase {
|
|
4
|
+
config;
|
|
13
5
|
constructor(config) {
|
|
14
6
|
this.config = config;
|
|
15
7
|
}
|
|
16
|
-
updateContextDecision(context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
context.reasons = reasons;
|
|
27
|
-
});
|
|
8
|
+
async updateContextDecision(context) {
|
|
9
|
+
const { action, reasons } = getDecisionFromContext(context);
|
|
10
|
+
if (this.config.logger.getLoggerSeverity() === LoggerSeverity.DEBUG) {
|
|
11
|
+
const productReasons = Object.entries(reasons)
|
|
12
|
+
.map(([prod, reason]) => `${prod} -> ${reason}`)
|
|
13
|
+
.join(', ');
|
|
14
|
+
this.config.logger.debug(`decision: ${action}, reasons: ${productReasons}`);
|
|
15
|
+
}
|
|
16
|
+
context.action = action;
|
|
17
|
+
context.reasons = reasons;
|
|
28
18
|
}
|
|
29
19
|
}
|