perimeterx-js-core 0.6.1 → 0.6.2
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/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/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
- package/lib/cors/ICors.d.ts +4 -4
- package/lib/filter/FilterReason.d.ts +2 -1
- package/lib/filter/FilterReason.js +1 -0
- package/lib/first_party/IFirstParty.d.ts +2 -1
- package/lib/graphql/IGraphQLParser.d.ts +2 -1
- package/lib/http/interfaces/IHttpClient.d.ts +2 -1
- package/lib/phase/IPhase.d.ts +2 -1
- package/lib/phase/impl/DecideActionPhase.d.ts +0 -9
- package/lib/phase/impl/DecideActionPhase.js +2 -29
- 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/ILoginSuccessfulParser.d.ts +2 -1
- package/lib/products/interfaces/IProduct.d.ts +6 -5
- package/lib/pxde/IDataEnrichment.d.ts +3 -2
- package/lib/risk_api/client/IRiskApiClient.d.ts +2 -1
- package/lib/risk_api/model/RiskActivity.d.ts +1 -1
- package/lib/risk_token/parser/ITokenParser.d.ts +2 -1
- package/lib/telemetry/ITelemetry.d.ts +3 -2
- 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/package.json +2 -2
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
|
|
|
@@ -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,3 +1,3 @@
|
|
|
1
1
|
import { ConfigurationParams } from '../config';
|
|
2
2
|
import { ReadonlyContext } from '../context';
|
|
3
|
-
export declare type AdditionalActivityHandler = <Req, Res>(config: ConfigurationParams<Req, Res>, context: ReadonlyContext<Req, Res
|
|
3
|
+
export declare 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}`);
|
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,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
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { IOutgoingRequest } from './IOutgoingRequest';
|
|
2
3
|
import { IIncomingResponse } from './IIncomingResponse';
|
|
3
4
|
export declare 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
|
}
|
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
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
1
|
+
import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
2
2
|
import { IIncomingRequest, IOutgoingResponse } from '../../../http';
|
|
3
3
|
import { RequestData } from '../../../context';
|
|
4
4
|
import { CredentialData } from '../model';
|
|
5
5
|
export interface ICredentialEndpoint<Req, Res> {
|
|
6
6
|
matches(requestData: DeepReadonly<RequestData<Req>>): boolean;
|
|
7
|
-
getCredentialData(request: DeepReadonly<IIncomingRequest<Req>>):
|
|
8
|
-
isLoginSuccessful(response: DeepReadonly<IOutgoingResponse<Res>>):
|
|
7
|
+
getCredentialData(request: DeepReadonly<IIncomingRequest<Req>>): AsyncOrSync<CredentialData>;
|
|
8
|
+
isLoginSuccessful(response: DeepReadonly<IOutgoingResponse<Res>>): AsyncOrSync<boolean>;
|
|
9
9
|
}
|
package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare class HeaderCredentialExtractor<Req> implements ICredentialExtrac
|
|
|
6
6
|
protected readonly userField: string;
|
|
7
7
|
protected readonly passField: string;
|
|
8
8
|
constructor(userField: string, passField: string);
|
|
9
|
-
extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>):
|
|
9
|
+
extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>): Credentials | null;
|
|
10
10
|
}
|
package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.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
|
export class HeaderCredentialExtractor {
|
|
11
2
|
constructor(userField, passField) {
|
|
12
3
|
this.userField = userField;
|
|
13
4
|
this.passField = passField;
|
|
14
5
|
}
|
|
15
6
|
extractCredentials(request) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return typeof user === 'string' || typeof pass === 'string' ? { user, pass } : null;
|
|
20
|
-
});
|
|
7
|
+
const user = request.headers.get(this.userField);
|
|
8
|
+
const pass = request.headers.get(this.passField);
|
|
9
|
+
return typeof user === 'string' || typeof pass === 'string' ? { user, pass } : null;
|
|
21
10
|
}
|
|
22
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
1
|
+
import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
2
2
|
import { IIncomingRequest } from '../../../../http';
|
|
3
3
|
import { Credentials } from '../../model';
|
|
4
4
|
export interface ICredentialExtractor<Req> {
|
|
5
|
-
extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>):
|
|
5
|
+
extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>): AsyncOrSync<Credentials | null>;
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Credentials } from '../../model
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
2
|
+
import { CredentialData, Credentials } from '../../model';
|
|
3
3
|
export interface ICredentialIntelligenceHashProtocol {
|
|
4
|
-
hashCredentials(credentials: Credentials):
|
|
4
|
+
hashCredentials(credentials: Credentials): AsyncOrSync<CredentialData>;
|
|
5
5
|
}
|
package/lib/products/credential_intelligence/endpoint/login_successful/ILoginSuccessfulParser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { IOutgoingResponse } from '../../../../http';
|
|
2
3
|
export interface ILoginSuccessfulParser<Res> {
|
|
3
|
-
isLoginSuccessful(response: IOutgoingResponse<Res>):
|
|
4
|
+
isLoginSuccessful(response: IOutgoingResponse<Res>): AsyncOrSync<boolean>;
|
|
4
5
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../../context';
|
|
2
3
|
import { ProductName } from '../utils';
|
|
3
4
|
import { ProductDataType } from './ProductDataType';
|
|
4
5
|
export interface IProduct<Name extends ProductName, Req, Res> {
|
|
5
|
-
enrichContextFromRequest(context: ReadonlyContext<Req, Res>):
|
|
6
|
-
enrichContextFromRiskApi(context: ReadonlyContext<Req, Res>):
|
|
7
|
-
modifyIncomingRequest(context: ReadonlyContext<Req, Res>):
|
|
8
|
-
enrichContextFromResponse(context: ReadonlyContext<Req, Res>):
|
|
9
|
-
modifyOutgoingResponse(context: ReadonlyContext<Req, Res>):
|
|
6
|
+
enrichContextFromRequest(context: ReadonlyContext<Req, Res>): AsyncOrSync<ProductDataType<Name>>;
|
|
7
|
+
enrichContextFromRiskApi(context: ReadonlyContext<Req, Res>): AsyncOrSync<Partial<ProductDataType<Name>>>;
|
|
8
|
+
modifyIncomingRequest(context: ReadonlyContext<Req, Res>): AsyncOrSync<void>;
|
|
9
|
+
enrichContextFromResponse(context: ReadonlyContext<Req, Res>): AsyncOrSync<Partial<ProductDataType<Name>>>;
|
|
10
|
+
modifyOutgoingResponse(context: ReadonlyContext<Req, Res>): AsyncOrSync<void>;
|
|
10
11
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../context';
|
|
2
|
-
import { PxdeData } from './model
|
|
3
|
+
import { PxdeData } from './model';
|
|
3
4
|
export interface IDataEnrichment<Req, Res> {
|
|
4
5
|
/**
|
|
5
6
|
* If the PXDE cookie is present on the request, parses it and enriches the context with its contents.
|
|
6
7
|
* @param context - The request context.
|
|
7
8
|
* @returns Promise<PxdeData|null>
|
|
8
9
|
*/
|
|
9
|
-
handlePxde(context: ReadonlyContext<Req, Res>):
|
|
10
|
+
handlePxde(context: ReadonlyContext<Req, Res>): AsyncOrSync<PxdeData | null>;
|
|
10
11
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext, RiskApiData } from '../../context';
|
|
2
3
|
export interface IRiskApiClient<Req, Res> {
|
|
3
|
-
executeRiskApi(context: ReadonlyContext<Req, Res>):
|
|
4
|
+
executeRiskApi(context: ReadonlyContext<Req, Res>): AsyncOrSync<RiskApiData>;
|
|
4
5
|
}
|
|
@@ -40,7 +40,7 @@ export declare type RiskAdditionalData = {
|
|
|
40
40
|
server_info_datacenter?: string;
|
|
41
41
|
cross_tab_session?: string;
|
|
42
42
|
app_user_id?: string;
|
|
43
|
-
jwt_additional_fields?: string
|
|
43
|
+
jwt_additional_fields?: Record<string, any>;
|
|
44
44
|
graphql_operations?: GraphQLData[];
|
|
45
45
|
user?: string;
|
|
46
46
|
pass?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext, TokenData } from '../../context';
|
|
2
3
|
export interface ITokenParser<Req, Res> {
|
|
3
|
-
parseToken(context: ReadonlyContext<Req, Res>):
|
|
4
|
+
parseToken(context: ReadonlyContext<Req, Res>): AsyncOrSync<TokenData<Req, Res>>;
|
|
4
5
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
1
2
|
import { ReadonlyContext } from '../context';
|
|
2
3
|
export interface ITelemetry<Req, Res> {
|
|
3
4
|
/**
|
|
4
5
|
* @param context - The request context.
|
|
5
6
|
* @returns Promise<boolean> - A Promise resolving to a boolean that indicates whether the request is a valid telemetry request.
|
|
6
7
|
*/
|
|
7
|
-
isValidTelemetryRequest(context: ReadonlyContext<Req, Res>):
|
|
8
|
+
isValidTelemetryRequest(context: ReadonlyContext<Req, Res>): AsyncOrSync<boolean>;
|
|
8
9
|
/**
|
|
9
10
|
* @param context - The request context.
|
|
10
11
|
* @returns void
|
|
11
12
|
*/
|
|
12
|
-
sendTelemetry(context: ReadonlyContext<Req, Res>):
|
|
13
|
+
sendTelemetry(context: ReadonlyContext<Req, Res>): AsyncOrSync<void>;
|
|
13
14
|
}
|
package/lib/utils/constants.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export declare const X_PX_AUTHORIZATION_HEADER_NAME = "x-px-authorization";
|
|
|
8
8
|
export declare const X_PX_ORIGINAL_TOKEN_HEADER_NAME = "x-px-original-token";
|
|
9
9
|
export declare const X_PX_BYPASS_REASON_HEADER_NAME = "x-px-bypass-reason";
|
|
10
10
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
11
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.6.
|
|
11
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.6.2";
|
package/lib/utils/constants.js
CHANGED
|
@@ -8,4 +8,4 @@ export const X_PX_AUTHORIZATION_HEADER_NAME = 'x-px-authorization';
|
|
|
8
8
|
export const X_PX_ORIGINAL_TOKEN_HEADER_NAME = 'x-px-original-token';
|
|
9
9
|
export const X_PX_BYPASS_REASON_HEADER_NAME = 'x-px-bypass-reason';
|
|
10
10
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
11
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.6.
|
|
11
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.6.2';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import cryptoJs from 'crypto-js';
|
|
2
|
+
import { Algorithm } from '../Algorithm';
|
|
3
|
+
export class CryptoJSHashUtils {
|
|
4
|
+
hashString(text, algo) {
|
|
5
|
+
switch (algo) {
|
|
6
|
+
case Algorithm.SHA256:
|
|
7
|
+
return cryptoJs.SHA256(text).toString(cryptoJs.enc.Hex);
|
|
8
|
+
default:
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
package/lib/utils/hash/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perimeterx-js-core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"ip-range-check": "^0.2.0",
|
|
26
26
|
"js-base64": "^3.7.2",
|
|
27
27
|
"phin": "^3.7.0",
|
|
28
|
+
"ts-essentials": "^9.3.2",
|
|
28
29
|
"uuid": "^9.0.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
@@ -49,7 +50,6 @@
|
|
|
49
50
|
"nyc": "^15.1.0",
|
|
50
51
|
"prettier": "^2.7.1",
|
|
51
52
|
"sinon": "^14.0.1",
|
|
52
|
-
"ts-essentials": "^9.3.2",
|
|
53
53
|
"ts-loader": "^9.4.1",
|
|
54
54
|
"ts-node": "^10.9.1",
|
|
55
55
|
"typescript": "^4.4.4"
|