perimeterx-js-core 0.6.1 → 0.7.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/README.md +1 -0
- package/lib/action/ActionData.d.ts +1 -1
- package/lib/action/Decision.d.ts +1 -1
- package/lib/action/ProductAction.d.ts +5 -0
- package/lib/action/ProductAction.js +1 -0
- package/lib/action/index.d.ts +2 -0
- package/lib/action/index.js +2 -0
- package/lib/action/utils.d.ts +6 -0
- package/lib/action/utils.js +34 -0
- package/lib/activities/HttpActivityClient.js +3 -3
- package/lib/activities/IActivityClient.d.ts +2 -1
- package/lib/activities/model/Activity.d.ts +1 -1
- package/lib/activities/model/ActivityDetails.d.ts +5 -5
- package/lib/activities/utils.js +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
- package/lib/config/ConfigurationParams.d.ts +1 -1
- package/lib/context/DefaultContext.d.ts +4 -1
- package/lib/context/DefaultContext.js +6 -3
- package/lib/context/interfaces/MobileData.d.ts +1 -1
- package/lib/context/interfaces/ReadonlyContext.d.ts +1 -1
- package/lib/context/interfaces/RequestData.d.ts +6 -1
- package/lib/context/interfaces/RiskApiData.d.ts +1 -1
- package/lib/context/interfaces/ServerData.d.ts +1 -1
- package/lib/context/interfaces/TlsData.d.ts +1 -1
- package/lib/context/interfaces/TokenData.d.ts +1 -1
- package/lib/cors/CustomBlockResponseHeadersHandler.d.ts +1 -1
- package/lib/cors/CustomPreflightHandler.d.ts +1 -1
- package/lib/cors/ICors.d.ts +4 -4
- package/lib/custom_parameters/CustomParameters.d.ts +1 -1
- package/lib/custom_parameters/CustomParametersFunction.d.ts +1 -1
- package/lib/enforcer/options/EnforcerBaseOptions.d.ts +1 -1
- package/lib/enforcer/options/EnforcerOptionsType.d.ts +1 -1
- package/lib/enforcer/options/EnforcerV2Options.d.ts +1 -1
- package/lib/enforcer/options/EnforcerV3Options.d.ts +1 -1
- package/lib/filter/FilterReason.d.ts +2 -1
- package/lib/filter/FilterReason.js +1 -0
- package/lib/first_party/FirstPartyData.d.ts +1 -1
- package/lib/first_party/IFirstParty.d.ts +2 -1
- package/lib/graphql/IGraphQLParser.d.ts +2 -1
- package/lib/graphql/model/GraphQLData.d.ts +1 -1
- package/lib/graphql/model/GraphQLOperation.d.ts +1 -1
- package/lib/http/impl/FormDataImpl.js +2 -2
- package/lib/http/impl/MinimalResponseImpl.d.ts +1 -1
- package/lib/http/impl/OutgoingRequestImpl.d.ts +1 -1
- package/lib/http/interfaces/IHttpClient.d.ts +3 -2
- package/lib/http/interfaces/ReadonlyHeaders.d.ts +1 -1
- package/lib/phase/IPhase.d.ts +2 -1
- package/lib/phase/PhaseResult.d.ts +1 -1
- package/lib/phase/impl/DecideActionPhase.d.ts +0 -9
- package/lib/phase/impl/DecideActionPhase.js +2 -29
- package/lib/products/account_defender/AccountDefender.d.ts +1 -1
- package/lib/products/account_defender/AccountDefenderData.d.ts +1 -1
- package/lib/products/account_defender/JwtData.d.ts +1 -1
- package/lib/products/bot_defender/BotDefender.d.ts +1 -1
- package/lib/products/bot_defender/BotDefenderData.d.ts +1 -1
- package/lib/products/bot_defender/block/model/BlockData.d.ts +1 -1
- package/lib/products/bot_defender/block/model/JsonBlockPayload.d.ts +1 -1
- package/lib/products/bot_defender/block/model/MobileBlockPayload.d.ts +1 -1
- package/lib/products/bot_defender/block/utils.js +5 -4
- package/lib/products/bot_defender/reasons/BotDefenderReasonType.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/ICredentialEndpoint.d.ts +3 -3
- package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +3 -14
- package/lib/products/credential_intelligence/endpoint/extractor/ICredentialExtractor.d.ts +2 -2
- package/lib/products/credential_intelligence/endpoint/hash_protocol/ICredentialIntelligenceHashProtocol.d.ts +3 -3
- package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulCallback.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/login_successful/ILoginSuccessfulParser.d.ts +2 -1
- package/lib/products/credential_intelligence/model/CredentialData.d.ts +1 -1
- package/lib/products/credential_intelligence/model/CredentialIntelligenceData.d.ts +1 -1
- package/lib/products/credential_intelligence/model/Credentials.d.ts +1 -1
- package/lib/products/credential_intelligence/model/CustomExtractionCallback.d.ts +1 -1
- package/lib/products/interfaces/IProduct.d.ts +6 -5
- package/lib/products/interfaces/ProductData.d.ts +1 -1
- package/lib/products/interfaces/ProductDataType.d.ts +1 -1
- package/lib/products/interfaces/ProductType.d.ts +1 -1
- package/lib/products/interfaces/Products.d.ts +1 -1
- package/lib/pxde/IDataEnrichment.d.ts +3 -2
- package/lib/pxde/model/PXDE.d.ts +1 -1
- package/lib/pxde/model/PxdeData.d.ts +1 -1
- package/lib/pxhd/model/PXHD.d.ts +1 -1
- package/lib/risk_api/client/IRiskApiClient.d.ts +2 -1
- package/lib/risk_api/client/PostRiskApiClientBase.js +1 -1
- package/lib/risk_api/model/RiskActivity.d.ts +5 -5
- package/lib/risk_api/risk_response/RiskResponsePayloadType.d.ts +1 -1
- package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -1
- package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -1
- package/lib/risk_token/parser/DefaultTokenV2Parser.d.ts +1 -1
- package/lib/risk_token/parser/DefaultTokenV3Parser.d.ts +1 -1
- package/lib/risk_token/parser/ITokenParser.d.ts +2 -1
- package/lib/risk_token/parser/TokenParserOptions.d.ts +1 -1
- package/lib/risk_token/token/TokenPayloadType.d.ts +1 -1
- package/lib/risk_token/token/v2/TokenV2Payload.d.ts +1 -1
- package/lib/risk_token/token/v3/TokenV3Payload.d.ts +1 -1
- package/lib/telemetry/ITelemetry.d.ts +3 -2
- package/lib/telemetry/model/TelemetryActivity.d.ts +2 -2
- package/lib/utils/cipher/ICipherUtils.d.ts +1 -1
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/lib/utils/hash/CryptoJSHashUtils.d.ts +5 -0
- package/lib/utils/hash/CryptoJSHashUtils.js +12 -0
- package/lib/utils/hash/index.d.ts +1 -0
- package/lib/utils/hash/index.js +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/url_parser/DefaultUrlParser.d.ts +13 -0
- package/lib/utils/url_parser/DefaultUrlParser.js +21 -0
- package/lib/utils/url_parser/IURLParser.d.ts +4 -0
- package/lib/utils/url_parser/IURLParser.js +1 -0
- package/lib/utils/url_parser/index.d.ts +2 -0
- package/lib/utils/url_parser/index.js +2 -0
- package/lib/utils/utils.d.ts +5 -0
- package/lib/utils/utils.js +5 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -122,6 +122,7 @@ are provided:
|
|
|
122
122
|
|
|
123
123
|
`IHashUtils` - Represents a hashing utility that is required by Credential Intelligence. The following implementations are provided:
|
|
124
124
|
* `CryptoHashUtils`, which relies on the native NodeJS `crypto` package.
|
|
125
|
+
* `CryptoJSHashUtils`, which uses the `crypto-js` dependency.
|
|
125
126
|
* `SubtleCryptoHashUtils`, which relies on an object implementing the `SubtleCrypto` interface. By default, it is assumed that the global `crypto.subtle` implements this interface.
|
|
126
127
|
|
|
127
128
|
|
package/lib/action/Decision.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/action/index.d.ts
CHANGED
package/lib/action/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Decision } from './Decision';
|
|
2
|
+
import { IContext } from '../context';
|
|
3
|
+
import { ProductAction } from './ProductAction';
|
|
4
|
+
export declare const getDecisionFromContext: <Req, Res>(context: IContext<Req, Res>) => Decision;
|
|
5
|
+
export declare const getProductActions: <Req, Res>(context: IContext<Req, Res>) => ProductAction[];
|
|
6
|
+
export declare const getDecisionFromActions: (productActions: ProductAction[]) => Decision;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Action } from './Action';
|
|
2
|
+
import { ACTION_PRIORITY_ORDER } from './ActionPriorityOrder';
|
|
3
|
+
export const getDecisionFromContext = (context) => {
|
|
4
|
+
return getDecisionFromActions(getProductActions(context));
|
|
5
|
+
};
|
|
6
|
+
export const getProductActions = (context) => {
|
|
7
|
+
return Object.entries(context.productData)
|
|
8
|
+
.filter(([_, data]) => (data === null || data === void 0 ? void 0 : data.action) != null && (data === null || data === void 0 ? void 0 : data.reason) != null)
|
|
9
|
+
.map(([productName, data]) => ({
|
|
10
|
+
action: data.action,
|
|
11
|
+
reason: data.reason,
|
|
12
|
+
productName: productName,
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
export const getDecisionFromActions = (productActions) => {
|
|
16
|
+
return createDecision(reduce(productActions));
|
|
17
|
+
};
|
|
18
|
+
const reduce = (actions) => {
|
|
19
|
+
return actions.reduce((tally, { action, reason, productName }) => {
|
|
20
|
+
if (!tally[action]) {
|
|
21
|
+
tally[action] = {};
|
|
22
|
+
}
|
|
23
|
+
tally[action][productName] = reason;
|
|
24
|
+
return tally;
|
|
25
|
+
}, {});
|
|
26
|
+
};
|
|
27
|
+
const createDecision = (tally) => {
|
|
28
|
+
for (const action of ACTION_PRIORITY_ORDER) {
|
|
29
|
+
if (tally[action]) {
|
|
30
|
+
return { action, reasons: tally[action] };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { action: Action.PASS_REQUEST };
|
|
34
|
+
};
|
|
@@ -62,9 +62,9 @@ export class HttpActivityClient {
|
|
|
62
62
|
};
|
|
63
63
|
const body = activities.length === 1 ? JSON.stringify(activities[0]) : JSON.stringify(activities);
|
|
64
64
|
this.config.logger.debug(`sending ${activities.map(({ type }) => `${type} activity`).join(', ')} to ${url}`);
|
|
65
|
-
const req = new OutgoingRequestImpl({ url
|
|
66
|
-
const
|
|
67
|
-
return status === 200;
|
|
65
|
+
const req = new OutgoingRequestImpl({ url, method, headers, body });
|
|
66
|
+
const res = yield this.httpClient.send(req);
|
|
67
|
+
return (res === null || res === void 0 ? void 0 : res.status) === 200;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../context';
|
|
2
3
|
export interface IActivityClient<Req, Res> {
|
|
3
4
|
/**
|
|
4
5
|
* @param context - The request context.
|
|
5
6
|
* @returns Promise<boolean> - Whether sending the activities was successful or not.
|
|
6
7
|
*/
|
|
7
|
-
sendActivities(context: ReadonlyContext<Req, Res>):
|
|
8
|
+
sendActivities(context: ReadonlyContext<Req, Res>): AsyncOrSync<boolean>;
|
|
8
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLData } from '../../graphql';
|
|
2
2
|
import { BlockAction } from '../../blocker';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type ActivityTypeDetails = PageRequestedActivityDetails | BlockActivityDetails | AdditionalS2SActivityDetails;
|
|
4
|
+
export type ActivityDetails = ActivityTypeDetails & {
|
|
5
5
|
client_uuid: string;
|
|
6
6
|
request_id: string;
|
|
7
7
|
module_version: string;
|
|
@@ -26,20 +26,20 @@ export declare type ActivityDetails = ActivityTypeDetails & {
|
|
|
26
26
|
app_user_id?: string;
|
|
27
27
|
jwt_additional_fields?: Record<string, any>;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
29
|
+
export type PageRequestedActivityDetails = {
|
|
30
30
|
pass_reason: string;
|
|
31
31
|
px_cookie?: string;
|
|
32
32
|
error_message?: string;
|
|
33
33
|
s2s_error_reason?: string;
|
|
34
34
|
s2s_error_http_status?: number;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type BlockActivityDetails = {
|
|
37
37
|
block_reason: string;
|
|
38
38
|
block_action: BlockAction;
|
|
39
39
|
block_score: number;
|
|
40
40
|
simulated_block: boolean;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export type AdditionalS2SActivityDetails = {
|
|
43
43
|
http_status_code: number;
|
|
44
44
|
login_successful: boolean;
|
|
45
45
|
raw_username?: string;
|
package/lib/activities/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ export const createActivity = (activityType, config, context) => {
|
|
|
8
8
|
return {
|
|
9
9
|
type: activityType,
|
|
10
10
|
px_app_id: config.appId,
|
|
11
|
-
url: context.requestData.
|
|
11
|
+
url: context.requestData.rawUrl,
|
|
12
12
|
headers: activityType !== ActivityType.ADDITIONAL_S2S
|
|
13
13
|
? joinHeaderValues(removeSensitiveHeaders(context.requestData.headers, config.sensitiveHeaders))
|
|
14
14
|
: undefined,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ConfigurationParams } from '../config';
|
|
2
2
|
import { ReadonlyContext } from '../context';
|
|
3
|
-
export
|
|
3
|
+
export type AdditionalActivityHandler = <Req, Res>(config: ConfigurationParams<Req, Res>, context: ReadonlyContext<Req, Res>, request: Req) => void | Promise<void>;
|
|
@@ -12,7 +12,7 @@ export var AdditionalActivityHandlerUtils;
|
|
|
12
12
|
AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler = (config, context) => __awaiter(this, void 0, void 0, function* () {
|
|
13
13
|
if (config.additionalActivityHandler && typeof config.additionalActivityHandler === 'function') {
|
|
14
14
|
try {
|
|
15
|
-
yield config.additionalActivityHandler(config.toParams(), context);
|
|
15
|
+
yield config.additionalActivityHandler(config.toParams(), context, context.requestData.request.getUnderlyingRequest());
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
18
|
config.logger.error(`caught additional activity handler error - ${e}`);
|
|
@@ -5,7 +5,7 @@ import { CredentialEndpointConfiguration, CredentialIntelligenceVersion, CustomL
|
|
|
5
5
|
import { LoggerSeverity } from '../logger';
|
|
6
6
|
import { ModuleMode } from '../utils';
|
|
7
7
|
import { GraphQLOperationType } from '../graphql';
|
|
8
|
-
export
|
|
8
|
+
export type ConfigurationParams<Req, Res> = {
|
|
9
9
|
px_app_id: string;
|
|
10
10
|
px_auth_token: string;
|
|
11
11
|
px_cookie_secret: string;
|
|
@@ -9,9 +9,11 @@ import { ICookieParser, IRequestIdGenerator, VidSource } from '../utils';
|
|
|
9
9
|
import { IContext, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
|
|
10
10
|
import { ProductData, ProductName } from '../products';
|
|
11
11
|
import { Action } from '../action';
|
|
12
|
-
|
|
12
|
+
import { IURLParser } from '../utils/url_parser';
|
|
13
|
+
export type DefaultContextOptions = {
|
|
13
14
|
cookieParser?: ICookieParser;
|
|
14
15
|
requestIdGenerator: IRequestIdGenerator;
|
|
16
|
+
urlParser?: IURLParser;
|
|
15
17
|
};
|
|
16
18
|
export declare class DefaultContext<Req, Res> implements IContext<Req, Res> {
|
|
17
19
|
readonly requestId: string;
|
|
@@ -35,6 +37,7 @@ export declare class DefaultContext<Req, Res> implements IContext<Req, Res> {
|
|
|
35
37
|
customParameters?: CustomParameters;
|
|
36
38
|
response?: IOutgoingResponse<Res>;
|
|
37
39
|
protected readonly config: IConfiguration<Req, Res>;
|
|
40
|
+
protected readonly urlParser: IURLParser;
|
|
38
41
|
constructor(config: IConfiguration<Req, Res>, request: IIncomingRequest<Req>, options: DefaultContextOptions);
|
|
39
42
|
get isMobile(): boolean;
|
|
40
43
|
protected createRequestData(config: IConfiguration<Req, Res>, request: IIncomingRequest<Req>, cookieParser?: ICookieParser): RequestData<Req>;
|
|
@@ -3,10 +3,12 @@ import { PXHDSource } from '../pxhd';
|
|
|
3
3
|
import { TokenOrigin, TokenParseResult } from '../risk_token';
|
|
4
4
|
import { RiskApiCallResult } from '../risk_api';
|
|
5
5
|
import { COOKIE_HEADER_NAME, toReadonlyHeaders, USER_AGENT_HEADER_NAME, } from '../http';
|
|
6
|
-
import { StringSplitCookieParser,
|
|
6
|
+
import { StringSplitCookieParser, PXHD_COOKIE_NAME, PXVID_COOKIE_NAME, X_PX_AUTHORIZATION_HEADER_NAME, } from '../utils';
|
|
7
|
+
import { DefaultUrlParser } from '../utils/url_parser';
|
|
7
8
|
export class DefaultContext {
|
|
8
9
|
constructor(config, request, options) {
|
|
9
10
|
this.config = config;
|
|
11
|
+
this.urlParser = options.urlParser || new DefaultUrlParser();
|
|
10
12
|
this.tokenData = {
|
|
11
13
|
tokenParseResult: TokenParseResult.NONE,
|
|
12
14
|
};
|
|
@@ -29,7 +31,8 @@ export class DefaultContext {
|
|
|
29
31
|
return this.tokenOrigin === TokenOrigin.HEADER;
|
|
30
32
|
}
|
|
31
33
|
createRequestData(config, request, cookieParser = new StringSplitCookieParser()) {
|
|
32
|
-
const
|
|
34
|
+
const rawUrl = request.url;
|
|
35
|
+
const url = this.urlParser.parse(rawUrl);
|
|
33
36
|
const method = request.method;
|
|
34
37
|
const headers = request.headers;
|
|
35
38
|
const cookies = DefaultContext.getCookies(cookieParser, request.headers.get(COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
|
|
@@ -37,7 +40,7 @@ export class DefaultContext {
|
|
|
37
40
|
const readOnlyHeaders = toReadonlyHeaders(headers);
|
|
38
41
|
const userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
|
|
39
42
|
const ip = this.extractIpFromHeader(config, readOnlyHeaders) || request.clientIP;
|
|
40
|
-
return { url, method, headers: readOnlyHeaders, cookies, ip, userAgent, requestCookieNames, request };
|
|
43
|
+
return { url, rawUrl, method, headers: readOnlyHeaders, cookies, ip, userAgent, requestCookieNames, request };
|
|
41
44
|
}
|
|
42
45
|
static getCookies(cookieParser, ...cookieHeaderValues) {
|
|
43
46
|
const cookies = {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { HttpMethod, IIncomingRequest, IURL, ReadonlyHeaders } from '../../http';
|
|
2
|
-
export
|
|
2
|
+
export type RequestData<Req> = {
|
|
3
3
|
/**
|
|
4
4
|
* The request URL.
|
|
5
5
|
*/
|
|
6
6
|
url: IURL;
|
|
7
|
+
/**
|
|
8
|
+
* The native url fetched from the environment.
|
|
9
|
+
* It should contain "..", duplicate slashes and un-decoded ascii characters (%XX) if possible.
|
|
10
|
+
*/
|
|
11
|
+
rawUrl: string;
|
|
7
12
|
/**
|
|
8
13
|
* The request method, capitalized.
|
|
9
14
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ReadonlyHeaders } from '../http';
|
|
2
|
-
export
|
|
2
|
+
export type CustomBlockResponseHeadersHandler<Req> = (request: Req) => ReadonlyHeaders | Promise<ReadonlyHeaders>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IMinimalResponse } from '../http';
|
|
2
|
-
export
|
|
2
|
+
export type CustomPreflightHandler<Req> = (request: Req) => IMinimalResponse | Promise<IMinimalResponse>;
|
package/lib/cors/ICors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../context';
|
|
2
|
-
import { IMinimalResponse } from '../http';
|
|
3
|
-
import { ReadonlyHeaders } from '../http';
|
|
3
|
+
import { IMinimalResponse, ReadonlyHeaders } from '../http';
|
|
4
4
|
export interface ICors<Req, Res> {
|
|
5
5
|
/**
|
|
6
6
|
* @param context
|
|
@@ -11,7 +11,7 @@ export interface ICors<Req, Res> {
|
|
|
11
11
|
* @param context- The request context.
|
|
12
12
|
* @returns IMinimalResponse- The response that return to client for preflight request.
|
|
13
13
|
*/
|
|
14
|
-
runPreflightCustomHandler(context: ReadonlyContext<Req, Res>):
|
|
14
|
+
runPreflightCustomHandler(context: ReadonlyContext<Req, Res>): AsyncOrSync<IMinimalResponse> | null;
|
|
15
15
|
/**
|
|
16
16
|
* @param context- The request context.
|
|
17
17
|
* @returns boolean - Whether the request is CORS.
|
|
@@ -22,5 +22,5 @@ export interface ICors<Req, Res> {
|
|
|
22
22
|
* @param context - The request context.
|
|
23
23
|
* @returns ReadOnlyHeaders - headers to be added to the block response.
|
|
24
24
|
*/
|
|
25
|
-
getCorsBlockHeaders(context: ReadonlyContext<Req, Res>):
|
|
25
|
+
getCorsBlockHeaders(context: ReadonlyContext<Req, Res>): AsyncOrSync<ReadonlyHeaders>;
|
|
26
26
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ConfigurationParams } from '../config';
|
|
2
2
|
import { CustomParameters } from './CustomParameters';
|
|
3
|
-
export
|
|
3
|
+
export type CustomParametersFunction<Req, Res> = (config: ConfigurationParams<Req, Res>, request: Req) => CustomParameters | Promise<CustomParameters>;
|
|
@@ -8,7 +8,7 @@ import { IRiskApiClient } from '../../risk_api';
|
|
|
8
8
|
import { IActivityClient } from '../../activities';
|
|
9
9
|
import { Products } from '../../products';
|
|
10
10
|
import { IGraphQLParser } from '../../graphql';
|
|
11
|
-
export
|
|
11
|
+
export type EnforcerBaseOptions<Req, Res> = {
|
|
12
12
|
httpClient: IHttpClient;
|
|
13
13
|
base64Utils: IBase64Utils;
|
|
14
14
|
hmacUtils: IHmacUtils;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { EnforcerV2Options } from './EnforcerV2Options';
|
|
3
3
|
import { EnforcerV3Options } from './EnforcerV3Options';
|
|
4
|
-
export
|
|
4
|
+
export type EnforcerOptionsType<TokenV extends TokenVersion, Req, Res> = TokenV extends TokenVersion.V2 ? EnforcerV2Options<Req, Res> : TokenV extends TokenVersion.V3 ? EnforcerV3Options<Req, Res> : never;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { EnforcerBaseOptions } from './EnforcerBaseOptions';
|
|
3
|
-
export
|
|
3
|
+
export type EnforcerV2Options<Req, Res> = {
|
|
4
4
|
tokenVersion: TokenVersion.V2;
|
|
5
5
|
} & EnforcerBaseOptions<Req, Res>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TokenVersion } from '../../risk_token';
|
|
2
2
|
import { ICipherUtils } from '../../utils';
|
|
3
3
|
import { EnforcerBaseOptions } from './EnforcerBaseOptions';
|
|
4
|
-
export
|
|
4
|
+
export type EnforcerV3Options<Req, Res> = {
|
|
5
5
|
tokenVersion: TokenVersion.V3;
|
|
6
6
|
cipherUtils: ICipherUtils;
|
|
7
7
|
} & EnforcerBaseOptions<Req, Res>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../context';
|
|
2
3
|
import { FirstPartyData } from './FirstPartyData';
|
|
3
4
|
export interface IFirstParty<Req, Res> {
|
|
@@ -5,5 +6,5 @@ export interface IFirstParty<Req, Res> {
|
|
|
5
6
|
* @param context - The request context
|
|
6
7
|
* @returns Promise<FirstPartyData | null> - If the request is not a first party request, it will return null.
|
|
7
8
|
*/
|
|
8
|
-
handleFirstPartyRequest(context: ReadonlyContext<Req, Res>):
|
|
9
|
+
handleFirstPartyRequest(context: ReadonlyContext<Req, Res>): AsyncOrSync<FirstPartyData | null>;
|
|
9
10
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../context';
|
|
2
3
|
import { GraphQLData } from './model';
|
|
3
4
|
export interface IGraphQLParser<Req, Res> {
|
|
4
5
|
isGraphQLRequest(context: ReadonlyContext<Req, Res>): boolean;
|
|
5
|
-
parseGraphQLRequest(context: ReadonlyContext<Req, Res>):
|
|
6
|
+
parseGraphQLRequest(context: ReadonlyContext<Req, Res>): AsyncOrSync<GraphQLData[]>;
|
|
6
7
|
}
|
|
@@ -29,8 +29,8 @@ export class FormDataImpl {
|
|
|
29
29
|
if (typeof value === 'string') {
|
|
30
30
|
this.data[name] = [value];
|
|
31
31
|
}
|
|
32
|
-
else {
|
|
33
|
-
this.data[name] = [
|
|
32
|
+
else if (File) {
|
|
33
|
+
this.data[name] = [new File([value], filename)];
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { IOutgoingRequest } from './IOutgoingRequest';
|
|
2
3
|
import { IIncomingResponse } from './IIncomingResponse';
|
|
3
|
-
export
|
|
4
|
+
export type HttpSendOptions = {
|
|
4
5
|
timeoutMs?: number;
|
|
5
6
|
};
|
|
6
7
|
export interface IHttpClient {
|
|
7
|
-
send(request: IOutgoingRequest, options?: HttpSendOptions):
|
|
8
|
+
send(request: IOutgoingRequest, options?: HttpSendOptions): AsyncOrSync<IIncomingResponse>;
|
|
8
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepReadonly } from 'ts-essentials';
|
|
2
2
|
import { IHeaders } from './IHeaders';
|
|
3
|
-
export
|
|
3
|
+
export type ReadonlyHeaders = DeepReadonly<Record<string, string[]>>;
|
|
4
4
|
export declare const toReadonlyHeaders: (headers: IHeaders) => ReadonlyHeaders;
|
|
5
5
|
export declare const toMutableHeaders: (headers: ReadonlyHeaders) => Record<string, string[]>;
|
|
6
6
|
export declare const joinHeaderValues: (headers: ReadonlyHeaders) => Record<string, string>;
|
package/lib/phase/IPhase.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { IContext } from '../context';
|
|
2
3
|
import { PhaseResult } from './PhaseResult';
|
|
3
4
|
export interface IPhase<Req, Res> {
|
|
4
|
-
execute(context: IContext<Req, Res>):
|
|
5
|
+
execute(context: IContext<Req, Res>): AsyncOrSync<PhaseResult>;
|
|
5
6
|
}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { IConfiguration } from '../../config';
|
|
2
2
|
import { IContext } from '../../context';
|
|
3
|
-
import { ProductName } from '../../products';
|
|
4
|
-
import { Action, ActionData, Decision } from '../../action';
|
|
5
3
|
import { IPhase } from '../IPhase';
|
|
6
4
|
import { PhaseResult } from '../PhaseResult';
|
|
7
|
-
declare type ProductAction = ActionData & {
|
|
8
|
-
productName: ProductName;
|
|
9
|
-
};
|
|
10
5
|
export declare abstract class DecideActionPhase<Req, Res> implements IPhase<Req, Res> {
|
|
11
6
|
protected readonly config: IConfiguration<Req, Res>;
|
|
12
7
|
protected constructor(config: IConfiguration<Req, Res>);
|
|
13
8
|
abstract execute(context: IContext<Req, Res>): Promise<PhaseResult>;
|
|
14
9
|
protected updateContextDecision(context: IContext<Req, Res>): Promise<void>;
|
|
15
|
-
protected getProductActions(context: IContext<Req, Res>): ProductAction[];
|
|
16
|
-
protected reduce(actions: ProductAction[]): Partial<Record<Action, Partial<Record<ProductName, string>>>>;
|
|
17
|
-
protected createDecision(tally: Partial<Record<Action, Partial<Record<ProductName, string>>>>): Decision;
|
|
18
10
|
}
|
|
19
|
-
export {};
|
|
@@ -7,16 +7,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { Action, ACTION_PRIORITY_ORDER } from '../../action';
|
|
11
10
|
import { LoggerSeverity } from '../../logger';
|
|
11
|
+
import { getDecisionFromContext } from '../../action';
|
|
12
12
|
export class DecideActionPhase {
|
|
13
13
|
constructor(config) {
|
|
14
14
|
this.config = config;
|
|
15
15
|
}
|
|
16
16
|
updateContextDecision(context) {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const
|
|
19
|
-
const { action, reasons } = this.createDecision(this.reduce(actions));
|
|
18
|
+
const { action, reasons } = getDecisionFromContext(context);
|
|
20
19
|
if (this.config.logger.getLoggerSeverity() === LoggerSeverity.DEBUG) {
|
|
21
20
|
const productReasons = Object.entries(reasons)
|
|
22
21
|
.map(([prod, reason]) => `${prod} -> ${reason}`)
|
|
@@ -27,30 +26,4 @@ export class DecideActionPhase {
|
|
|
27
26
|
context.reasons = reasons;
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
|
-
getProductActions(context) {
|
|
31
|
-
return Object.entries(context.productData)
|
|
32
|
-
.filter(([_, data]) => (data === null || data === void 0 ? void 0 : data.action) != null && (data === null || data === void 0 ? void 0 : data.reason) != null)
|
|
33
|
-
.map(([productName, data]) => ({
|
|
34
|
-
action: data.action,
|
|
35
|
-
reason: data.reason,
|
|
36
|
-
productName: productName,
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
reduce(actions) {
|
|
40
|
-
return actions.reduce((tally, { action, reason, productName }) => {
|
|
41
|
-
if (!tally[action]) {
|
|
42
|
-
tally[action] = {};
|
|
43
|
-
}
|
|
44
|
-
tally[action][productName] = reason;
|
|
45
|
-
return tally;
|
|
46
|
-
}, {});
|
|
47
|
-
}
|
|
48
|
-
createDecision(tally) {
|
|
49
|
-
for (const action of ACTION_PRIORITY_ORDER) {
|
|
50
|
-
if (tally[action]) {
|
|
51
|
-
return { action, reasons: tally[action] };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return { action: Action.PASS_REQUEST };
|
|
55
|
-
}
|
|
56
29
|
}
|
|
@@ -5,7 +5,7 @@ import { IBase64Utils } from '../../utils';
|
|
|
5
5
|
import { IAccountDefender } from './IAccountDefender';
|
|
6
6
|
import { AccountDefenderData } from './AccountDefenderData';
|
|
7
7
|
import { JwtData } from './JwtData';
|
|
8
|
-
export
|
|
8
|
+
export type AccountDefenderOptions = {
|
|
9
9
|
base64Utils: IBase64Utils;
|
|
10
10
|
};
|
|
11
11
|
export declare class AccountDefender<Req, Res> implements IAccountDefender<Req, Res> {
|