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.
Files changed (115) hide show
  1. package/README.md +1 -0
  2. package/lib/action/ActionData.d.ts +1 -1
  3. package/lib/action/Decision.d.ts +1 -1
  4. package/lib/action/ProductAction.d.ts +5 -0
  5. package/lib/action/ProductAction.js +1 -0
  6. package/lib/action/index.d.ts +2 -0
  7. package/lib/action/index.js +2 -0
  8. package/lib/action/utils.d.ts +6 -0
  9. package/lib/action/utils.js +34 -0
  10. package/lib/activities/HttpActivityClient.js +3 -3
  11. package/lib/activities/IActivityClient.d.ts +2 -1
  12. package/lib/activities/model/Activity.d.ts +1 -1
  13. package/lib/activities/model/ActivityDetails.d.ts +5 -5
  14. package/lib/activities/utils.js +1 -1
  15. package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
  16. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
  17. package/lib/config/ConfigurationParams.d.ts +1 -1
  18. package/lib/context/DefaultContext.d.ts +4 -1
  19. package/lib/context/DefaultContext.js +6 -3
  20. package/lib/context/interfaces/MobileData.d.ts +1 -1
  21. package/lib/context/interfaces/ReadonlyContext.d.ts +1 -1
  22. package/lib/context/interfaces/RequestData.d.ts +6 -1
  23. package/lib/context/interfaces/RiskApiData.d.ts +1 -1
  24. package/lib/context/interfaces/ServerData.d.ts +1 -1
  25. package/lib/context/interfaces/TlsData.d.ts +1 -1
  26. package/lib/context/interfaces/TokenData.d.ts +1 -1
  27. package/lib/cors/CustomBlockResponseHeadersHandler.d.ts +1 -1
  28. package/lib/cors/CustomPreflightHandler.d.ts +1 -1
  29. package/lib/cors/ICors.d.ts +4 -4
  30. package/lib/custom_parameters/CustomParameters.d.ts +1 -1
  31. package/lib/custom_parameters/CustomParametersFunction.d.ts +1 -1
  32. package/lib/enforcer/options/EnforcerBaseOptions.d.ts +1 -1
  33. package/lib/enforcer/options/EnforcerOptionsType.d.ts +1 -1
  34. package/lib/enforcer/options/EnforcerV2Options.d.ts +1 -1
  35. package/lib/enforcer/options/EnforcerV3Options.d.ts +1 -1
  36. package/lib/filter/FilterReason.d.ts +2 -1
  37. package/lib/filter/FilterReason.js +1 -0
  38. package/lib/first_party/FirstPartyData.d.ts +1 -1
  39. package/lib/first_party/IFirstParty.d.ts +2 -1
  40. package/lib/graphql/IGraphQLParser.d.ts +2 -1
  41. package/lib/graphql/model/GraphQLData.d.ts +1 -1
  42. package/lib/graphql/model/GraphQLOperation.d.ts +1 -1
  43. package/lib/http/impl/FormDataImpl.js +2 -2
  44. package/lib/http/impl/MinimalResponseImpl.d.ts +1 -1
  45. package/lib/http/impl/OutgoingRequestImpl.d.ts +1 -1
  46. package/lib/http/interfaces/IHttpClient.d.ts +3 -2
  47. package/lib/http/interfaces/ReadonlyHeaders.d.ts +1 -1
  48. package/lib/phase/IPhase.d.ts +2 -1
  49. package/lib/phase/PhaseResult.d.ts +1 -1
  50. package/lib/phase/impl/DecideActionPhase.d.ts +0 -9
  51. package/lib/phase/impl/DecideActionPhase.js +2 -29
  52. package/lib/products/account_defender/AccountDefender.d.ts +1 -1
  53. package/lib/products/account_defender/AccountDefenderData.d.ts +1 -1
  54. package/lib/products/account_defender/JwtData.d.ts +1 -1
  55. package/lib/products/bot_defender/BotDefender.d.ts +1 -1
  56. package/lib/products/bot_defender/BotDefenderData.d.ts +1 -1
  57. package/lib/products/bot_defender/block/model/BlockData.d.ts +1 -1
  58. package/lib/products/bot_defender/block/model/JsonBlockPayload.d.ts +1 -1
  59. package/lib/products/bot_defender/block/model/MobileBlockPayload.d.ts +1 -1
  60. package/lib/products/bot_defender/block/utils.js +5 -4
  61. package/lib/products/bot_defender/reasons/BotDefenderReasonType.d.ts +1 -1
  62. package/lib/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
  63. package/lib/products/credential_intelligence/endpoint/ICredentialEndpoint.d.ts +3 -3
  64. package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.d.ts +1 -1
  65. package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +3 -14
  66. package/lib/products/credential_intelligence/endpoint/extractor/ICredentialExtractor.d.ts +2 -2
  67. package/lib/products/credential_intelligence/endpoint/hash_protocol/ICredentialIntelligenceHashProtocol.d.ts +3 -3
  68. package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulCallback.d.ts +1 -1
  69. package/lib/products/credential_intelligence/endpoint/login_successful/ILoginSuccessfulParser.d.ts +2 -1
  70. package/lib/products/credential_intelligence/model/CredentialData.d.ts +1 -1
  71. package/lib/products/credential_intelligence/model/CredentialIntelligenceData.d.ts +1 -1
  72. package/lib/products/credential_intelligence/model/Credentials.d.ts +1 -1
  73. package/lib/products/credential_intelligence/model/CustomExtractionCallback.d.ts +1 -1
  74. package/lib/products/interfaces/IProduct.d.ts +6 -5
  75. package/lib/products/interfaces/ProductData.d.ts +1 -1
  76. package/lib/products/interfaces/ProductDataType.d.ts +1 -1
  77. package/lib/products/interfaces/ProductType.d.ts +1 -1
  78. package/lib/products/interfaces/Products.d.ts +1 -1
  79. package/lib/pxde/IDataEnrichment.d.ts +3 -2
  80. package/lib/pxde/model/PXDE.d.ts +1 -1
  81. package/lib/pxde/model/PxdeData.d.ts +1 -1
  82. package/lib/pxhd/model/PXHD.d.ts +1 -1
  83. package/lib/risk_api/client/IRiskApiClient.d.ts +2 -1
  84. package/lib/risk_api/client/PostRiskApiClientBase.js +1 -1
  85. package/lib/risk_api/model/RiskActivity.d.ts +5 -5
  86. package/lib/risk_api/risk_response/RiskResponsePayloadType.d.ts +1 -1
  87. package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -1
  88. package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -1
  89. package/lib/risk_token/parser/DefaultTokenV2Parser.d.ts +1 -1
  90. package/lib/risk_token/parser/DefaultTokenV3Parser.d.ts +1 -1
  91. package/lib/risk_token/parser/ITokenParser.d.ts +2 -1
  92. package/lib/risk_token/parser/TokenParserOptions.d.ts +1 -1
  93. package/lib/risk_token/token/TokenPayloadType.d.ts +1 -1
  94. package/lib/risk_token/token/v2/TokenV2Payload.d.ts +1 -1
  95. package/lib/risk_token/token/v3/TokenV3Payload.d.ts +1 -1
  96. package/lib/telemetry/ITelemetry.d.ts +3 -2
  97. package/lib/telemetry/model/TelemetryActivity.d.ts +2 -2
  98. package/lib/utils/cipher/ICipherUtils.d.ts +1 -1
  99. package/lib/utils/constants.d.ts +1 -1
  100. package/lib/utils/constants.js +1 -1
  101. package/lib/utils/hash/CryptoJSHashUtils.d.ts +5 -0
  102. package/lib/utils/hash/CryptoJSHashUtils.js +12 -0
  103. package/lib/utils/hash/index.d.ts +1 -0
  104. package/lib/utils/hash/index.js +1 -0
  105. package/lib/utils/index.d.ts +1 -0
  106. package/lib/utils/index.js +1 -0
  107. package/lib/utils/url_parser/DefaultUrlParser.d.ts +13 -0
  108. package/lib/utils/url_parser/DefaultUrlParser.js +21 -0
  109. package/lib/utils/url_parser/IURLParser.d.ts +4 -0
  110. package/lib/utils/url_parser/IURLParser.js +1 -0
  111. package/lib/utils/url_parser/index.d.ts +2 -0
  112. package/lib/utils/url_parser/index.js +2 -0
  113. package/lib/utils/utils.d.ts +5 -0
  114. package/lib/utils/utils.js +5 -1
  115. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- export declare type JwtData = {
1
+ export type JwtData = {
2
2
  appUserId?: string;
3
3
  additionalFields?: Record<string, any>;
4
4
  };
@@ -11,7 +11,7 @@ import { IBase64Utils, IIpRangeChecker } from '../../utils';
11
11
  import { IBotDefender } from '../';
12
12
  import { BotDefenderData } from './BotDefenderData';
13
13
  import { BotDefenderS2SCallReason } from './reasons';
14
- export declare type BotDefenderOptions<Req, Res> = {
14
+ export type BotDefenderOptions<Req, Res> = {
15
15
  base64Utils: IBase64Utils;
16
16
  firstParty?: IFirstParty<Req, Res>;
17
17
  blocker?: IConditionalBlocker<Req, Res>;
@@ -1,5 +1,5 @@
1
1
  import { ActionData } from '../../action';
2
- export declare type BotDefenderData = ActionData & {
2
+ export type BotDefenderData = ActionData & {
3
3
  /**
4
4
  * Whether the request should go through the enforcement flow in monitor mode.
5
5
  * This depends on various configurations including the module mode, monitored routes, enforced
@@ -1,5 +1,5 @@
1
1
  import { BlockAction } from '../../../../blocker/BlockAction';
2
- export declare type BlockData = {
2
+ export type BlockData = {
3
3
  appId: string;
4
4
  hostUrl: string;
5
5
  jsClientSrc: string;
@@ -1,4 +1,4 @@
1
- export declare type JsonBlockPayload = {
1
+ export type JsonBlockPayload = {
2
2
  appId: string;
3
3
  jsClientSrc: string;
4
4
  firstPartyEnabled: boolean;
@@ -1,4 +1,4 @@
1
- export declare type MobileBlockPayload = {
1
+ export type MobileBlockPayload = {
2
2
  action: string;
3
3
  uuid: string;
4
4
  vid: string;
@@ -13,18 +13,19 @@ export const renderHtml = (htmlTemplate, blockData) => {
13
13
  };
14
14
  export const createBlockData = (config, context) => {
15
15
  var _a, _b;
16
- const captchaParams = `/captcha.js?a=${context.blockAction}&u=${context.uuid}&v=${context.vid || ''}&m=${context.isMobile ? '1' : '0'}`;
16
+ const captchaScriptSuffix = '/captcha.js';
17
+ const captchaParams = `?a=${context.blockAction}&u=${context.uuid}&v=${context.vid || ''}&m=${context.isMobile ? '1' : '0'}`;
17
18
  let jsClientSrc = `${config.backendClientUrl}/${config.appId}/main.min.js`;
18
- let blockScript = `${config.backendCaptchaUrl}/${config.appId}${captchaParams}`;
19
+ let blockScript = `${config.backendCaptchaUrl}/${config.appId}${captchaScriptSuffix}${captchaParams}`;
19
20
  let hostUrl = config.backendCollectorUrl;
20
21
  if (config.firstPartyEnabled && !context.isMobile) {
21
22
  jsClientSrc = getMostCustomizedFirstPartyPath(config, FirstPartySuffix.SENSOR);
22
- blockScript = `${getMostCustomizedFirstPartyPath(config, FirstPartySuffix.CAPTCHA)}${captchaParams}`;
23
+ blockScript = `${getMostCustomizedFirstPartyPath(config, FirstPartySuffix.CAPTCHA)}${config.customFirstPartyCaptchaEndpoint ? captchaParams : `${captchaScriptSuffix}${captchaParams}`}`;
23
24
  hostUrl = getMostCustomizedFirstPartyPath(config, FirstPartySuffix.XHR);
24
25
  }
25
26
  const cssRef = config.cssRef ? `<link rel="stylesheet" type="text/css" href="${config.cssRef}" />` : '';
26
27
  const jsRef = config.jsRef ? `<script src="${config.jsRef}"></script>` : '';
27
- const altBlockScript = `${config.altBackendCaptchaUrl}/${config.appId}${captchaParams}`;
28
+ const altBlockScript = `${config.altBackendCaptchaUrl}/${config.appId}${captchaScriptSuffix}${captchaParams}`;
28
29
  return {
29
30
  appId: config.appId,
30
31
  vid: context.vid || ((_b = (_a = context.requestData) === null || _a === void 0 ? void 0 : _a.cookies) === null || _b === void 0 ? void 0 : _b[PXVID_COOKIE_NAME]) || '',
@@ -2,4 +2,4 @@ import { Action } from '../../../action';
2
2
  import { BotDefenderBlockReason } from './BotDefenderBlockReason';
3
3
  import { BotDefenderPassReason } from './BotDefenderPassReason';
4
4
  import { BotDefenderS2SCallReason } from './BotDefenderS2SCallReason';
5
- export declare type BotDefenderReasonType<A extends Action> = A extends Action.BLOCK ? BotDefenderBlockReason : A extends Action.SIMULATED_BLOCK ? BotDefenderBlockReason : A extends Action.PASS_REQUEST ? BotDefenderPassReason : A extends Action.TRIGGER_RISK_API ? BotDefenderS2SCallReason : never;
5
+ export type BotDefenderReasonType<A extends Action> = A extends Action.BLOCK ? BotDefenderBlockReason : A extends Action.SIMULATED_BLOCK ? BotDefenderBlockReason : A extends Action.PASS_REQUEST ? BotDefenderPassReason : A extends Action.TRIGGER_RISK_API ? BotDefenderS2SCallReason : never;
@@ -2,7 +2,7 @@ import { HttpMethod } from '../../../http';
2
2
  import { CustomExtractionCallback } from '../model';
3
3
  import { PathType, SentThrough, CredentialIntelligenceVersion } from './index';
4
4
  import { CustomLoginSuccessfulCallback, LoginSuccessfulReportingMethod } from './login_successful';
5
- export declare type CredentialEndpointConfiguration<Req, Res> = {
5
+ export type CredentialEndpointConfiguration<Req, Res> = {
6
6
  /**
7
7
  * The URI of the request that contains the credentials.
8
8
  */
@@ -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>>): Promise<CredentialData>;
8
- isLoginSuccessful(response: DeepReadonly<IOutgoingResponse<Res>>): Promise<boolean>;
7
+ getCredentialData(request: DeepReadonly<IIncomingRequest<Req>>): AsyncOrSync<CredentialData>;
8
+ isLoginSuccessful(response: DeepReadonly<IOutgoingResponse<Res>>): AsyncOrSync<boolean>;
9
9
  }
@@ -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>>): Promise<Credentials | null>;
9
+ extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>): Credentials | null;
10
10
  }
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
17
- const user = request.headers.get(this.userField);
18
- const pass = request.headers.get(this.passField);
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>>): Promise<Credentials | null>;
5
+ extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>): AsyncOrSync<Credentials | null>;
6
6
  }
@@ -1,5 +1,5 @@
1
- import { CredentialData } from '../../model';
2
- import { Credentials } from '../../model/Credentials';
1
+ import { AsyncOrSync } from 'ts-essentials';
2
+ import { CredentialData, Credentials } from '../../model';
3
3
  export interface ICredentialIntelligenceHashProtocol {
4
- hashCredentials(credentials: Credentials): Promise<CredentialData>;
4
+ hashCredentials(credentials: Credentials): AsyncOrSync<CredentialData>;
5
5
  }
@@ -1 +1 @@
1
- export declare type CustomLoginSuccessfulCallback<Res> = (response: Res) => boolean | Promise<boolean>;
1
+ export type CustomLoginSuccessfulCallback<Res> = (response: Res) => boolean | Promise<boolean>;
@@ -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>): Promise<boolean>;
4
+ isLoginSuccessful(response: IOutgoingResponse<Res>): AsyncOrSync<boolean>;
4
5
  }
@@ -1,5 +1,5 @@
1
1
  import { CredentialIntelligenceVersion, SsoStep } from '../endpoint';
2
- export declare type CredentialData = {
2
+ export type CredentialData = {
3
3
  ciVersion?: CredentialIntelligenceVersion;
4
4
  hashedUsername?: string;
5
5
  hashedPassword?: string;
@@ -1,6 +1,6 @@
1
1
  import { ActionData } from '../../../action';
2
2
  import { CredentialData } from './CredentialData';
3
- export declare type CredentialIntelligenceData = ActionData & CredentialData & {
3
+ export type CredentialIntelligenceData = ActionData & CredentialData & {
4
4
  endpointIndex?: number;
5
5
  isLoginSuccessful?: boolean;
6
6
  isCompromised?: boolean;
@@ -1,4 +1,4 @@
1
- export declare type Credentials = {
1
+ export type Credentials = {
2
2
  user?: string;
3
3
  pass?: string;
4
4
  };
@@ -1,2 +1,2 @@
1
1
  import { Credentials } from './Credentials';
2
- export declare type CustomExtractionCallback<Req> = (request: Req) => Credentials | Promise<Credentials>;
2
+ export type CustomExtractionCallback<Req> = (request: Req) => Credentials | Promise<Credentials>;
@@ -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>): Promise<ProductDataType<Name>>;
6
- enrichContextFromRiskApi(context: ReadonlyContext<Req, Res>): Promise<Partial<ProductDataType<Name>>>;
7
- modifyIncomingRequest(context: ReadonlyContext<Req, Res>): Promise<void>;
8
- enrichContextFromResponse(context: ReadonlyContext<Req, Res>): Promise<Partial<ProductDataType<Name>>>;
9
- modifyOutgoingResponse(context: ReadonlyContext<Req, Res>): Promise<void>;
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,5 +1,5 @@
1
1
  import { ProductName } from '../utils';
2
2
  import { ProductDataType } from './ProductDataType';
3
- export declare type ProductData = {
3
+ export type ProductData = {
4
4
  [Name in ProductName]?: ProductDataType<Name>;
5
5
  };
@@ -2,4 +2,4 @@ import { ProductName } from '../utils';
2
2
  import { BotDefenderData } from '../bot_defender';
3
3
  import { CredentialIntelligenceData } from '../credential_intelligence';
4
4
  import { AccountDefenderData } from '../account_defender';
5
- export declare type ProductDataType<Name extends ProductName> = Name extends ProductName.BOT_DEFENDER ? BotDefenderData : Name extends ProductName.CREDENTIAL_INTELLIGENCE ? CredentialIntelligenceData : Name extends ProductName.CODE_DEFENDER ? never : Name extends ProductName.ACCOUNT_DEFENDER ? AccountDefenderData : Name extends ProductName.HYPE_SALE_CHALLENGE ? never : never;
5
+ export type ProductDataType<Name extends ProductName> = Name extends ProductName.BOT_DEFENDER ? BotDefenderData : Name extends ProductName.CREDENTIAL_INTELLIGENCE ? CredentialIntelligenceData : Name extends ProductName.CODE_DEFENDER ? never : Name extends ProductName.ACCOUNT_DEFENDER ? AccountDefenderData : Name extends ProductName.HYPE_SALE_CHALLENGE ? never : never;
@@ -2,4 +2,4 @@ import { ProductName } from '../utils';
2
2
  import { IBotDefender } from '../bot_defender';
3
3
  import { ICredentialIntelligence } from '../credential_intelligence';
4
4
  import { IAccountDefender } from '../account_defender';
5
- export declare type ProductType<Name extends ProductName, Req, Res> = Name extends ProductName.BOT_DEFENDER ? IBotDefender<Req, Res> : Name extends ProductName.CREDENTIAL_INTELLIGENCE ? ICredentialIntelligence<Req, Res> : Name extends ProductName.ACCOUNT_DEFENDER ? IAccountDefender<Req, Res> : never;
5
+ export type ProductType<Name extends ProductName, Req, Res> = Name extends ProductName.BOT_DEFENDER ? IBotDefender<Req, Res> : Name extends ProductName.CREDENTIAL_INTELLIGENCE ? ICredentialIntelligence<Req, Res> : Name extends ProductName.ACCOUNT_DEFENDER ? IAccountDefender<Req, Res> : never;
@@ -1,5 +1,5 @@
1
1
  import { ProductName } from '../utils';
2
2
  import { ProductType } from './ProductType';
3
- export declare type Products<Req, Res> = {
3
+ export type Products<Req, Res> = {
4
4
  [Name in ProductName]?: ProductType<Name, Req, Res>;
5
5
  };
@@ -1,10 +1,11 @@
1
+ import { AsyncOrSync } from 'ts-essentials';
1
2
  import { ReadonlyContext } from '../context';
2
- import { PxdeData } from './model/PxdeData';
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>): Promise<PxdeData | null>;
10
+ handlePxde(context: ReadonlyContext<Req, Res>): AsyncOrSync<PxdeData | null>;
10
11
  }
@@ -1,4 +1,4 @@
1
- export declare type PXDE = {
1
+ export type PXDE = {
2
2
  timestamp: number;
3
3
  f_kb: number;
4
4
  f_type?: string;
@@ -1,5 +1,5 @@
1
1
  import { PXDE } from './PXDE';
2
- export declare type PxdeData = {
2
+ export type PxdeData = {
3
3
  pxde: PXDE;
4
4
  pxdeVerified: boolean;
5
5
  };
@@ -1,5 +1,5 @@
1
1
  import { PXHDSource } from './PXHDSource';
2
- export declare type PXHD = {
2
+ export type PXHD = {
3
3
  value: string;
4
4
  domain?: string;
5
5
  source: PXHDSource;
@@ -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>): Promise<RiskApiData>;
4
+ executeRiskApi(context: ReadonlyContext<Req, Res>): AsyncOrSync<RiskApiData>;
4
5
  }
@@ -62,7 +62,7 @@ export class PostRiskApiClientBase {
62
62
  request: {
63
63
  ip: context.requestData.ip,
64
64
  headers: this.formatRiskHeadersField(context.requestData.headers),
65
- url: context.requestData.url.href,
65
+ url: context.requestData.rawUrl,
66
66
  },
67
67
  additional: {
68
68
  s2s_call_reason: ((_a = context.reasons) === null || _a === void 0 ? void 0 : _a[ProductName.BOT_DEFENDER]) ||
@@ -3,16 +3,16 @@ import { TokenOrigin } from '../../risk_token';
3
3
  import { CustomParameters } from '../../custom_parameters';
4
4
  import { GraphQLData } from '../../graphql/';
5
5
  import { CredentialIntelligenceVersion, SsoStep } from '../../products';
6
- export declare type HeaderEntry = {
6
+ export type HeaderEntry = {
7
7
  name: string;
8
8
  value: string;
9
9
  };
10
- export declare type RiskRequestData = {
10
+ export type RiskRequestData = {
11
11
  ip: string;
12
12
  url: string;
13
13
  headers: HeaderEntry[];
14
14
  };
15
- export declare type RiskAdditionalData = {
15
+ export type RiskAdditionalData = {
16
16
  request_id: string;
17
17
  module_version: string;
18
18
  s2s_call_reason: string;
@@ -40,14 +40,14 @@ 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;
47
47
  ci_version?: CredentialIntelligenceVersion;
48
48
  sso_step?: SsoStep;
49
49
  } & CustomParameters;
50
- export declare type RiskActivity = {
50
+ export type RiskActivity = {
51
51
  vid?: string;
52
52
  uuid?: string;
53
53
  pxhd?: string;
@@ -1,4 +1,4 @@
1
1
  import { TokenVersion } from '../../risk_token';
2
2
  import { RiskResponseV3Payload } from './v3';
3
3
  import { RiskResponseV2Payload } from './v2';
4
- export declare type RiskResponsePayloadType<TokenV extends TokenVersion> = TokenV extends TokenVersion.V3 ? RiskResponseV3Payload : TokenV extends TokenVersion.V2 ? RiskResponseV2Payload : never;
4
+ export type RiskResponsePayloadType<TokenV extends TokenVersion> = TokenV extends TokenVersion.V3 ? RiskResponseV3Payload : TokenV extends TokenVersion.V2 ? RiskResponseV2Payload : never;
@@ -1,7 +1,7 @@
1
1
  import { PXDE } from '../../../pxde';
2
2
  import { BlockAction } from '../../../blocker';
3
3
  import { RiskStatus } from '../../model';
4
- export declare type RiskResponseV2Payload = {
4
+ export type RiskResponseV2Payload = {
5
5
  status: RiskStatus;
6
6
  cookie_cfg_block_result?: '0' | '1';
7
7
  action?: BlockAction;
@@ -1,7 +1,7 @@
1
1
  import { BlockAction } from '../../../blocker';
2
2
  import { PXDE } from '../../../pxde';
3
3
  import { RiskStatus } from '../../model';
4
- export declare type RiskResponseV3Payload = {
4
+ export type RiskResponseV3Payload = {
5
5
  status: RiskStatus;
6
6
  score?: number;
7
7
  action?: BlockAction;
@@ -3,7 +3,7 @@ import { TokenParserBase } from './TokenParserBase';
3
3
  import { TokenVersion } from '../TokenVersion';
4
4
  import { IConfiguration } from '../../config';
5
5
  import { IToken } from '../token';
6
- export declare type DefaultTokenV2ParserOptions = {
6
+ export type DefaultTokenV2ParserOptions = {
7
7
  base64Utils: IBase64Utils;
8
8
  hmacUtils: IHmacUtils;
9
9
  };
@@ -3,7 +3,7 @@ import { ICipherUtils, IHmacUtils } from '../../utils';
3
3
  import { TokenVersion } from '../TokenVersion';
4
4
  import { IToken } from '../token';
5
5
  import { TokenParserBase } from './TokenParserBase';
6
- export declare type DefaultTokenV3ParserOptions = {
6
+ export type DefaultTokenV3ParserOptions = {
7
7
  cipherUtils: ICipherUtils;
8
8
  hmacUtils: IHmacUtils;
9
9
  };
@@ -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>): Promise<TokenData<Req, Res>>;
4
+ parseToken(context: ReadonlyContext<Req, Res>): AsyncOrSync<TokenData<Req, Res>>;
4
5
  }
@@ -1,4 +1,4 @@
1
1
  import { TokenVersion } from '../TokenVersion';
2
2
  import { DefaultTokenV3ParserOptions } from './DefaultTokenV3Parser';
3
3
  import { DefaultTokenV2ParserOptions } from './DefaultTokenV2Parser';
4
- export declare type TokenOptionsType<TokenV> = TokenV extends TokenVersion.V2 ? DefaultTokenV2ParserOptions : DefaultTokenV3ParserOptions;
4
+ export type TokenOptionsType<TokenV> = TokenV extends TokenVersion.V2 ? DefaultTokenV2ParserOptions : DefaultTokenV3ParserOptions;
@@ -1,4 +1,4 @@
1
1
  import { TokenVersion } from '../TokenVersion';
2
2
  import { TokenV3Payload } from './v3/TokenV3Payload';
3
3
  import { TokenV2Payload } from './v2/TokenV2Payload';
4
- export declare type TokenPayloadType<TokenV extends TokenVersion> = TokenV extends TokenVersion.V3 ? TokenV3Payload : TokenV extends TokenVersion.V2 ? TokenV2Payload : never;
4
+ export type TokenPayloadType<TokenV extends TokenVersion> = TokenV extends TokenVersion.V3 ? TokenV3Payload : TokenV extends TokenVersion.V2 ? TokenV2Payload : never;
@@ -1,4 +1,4 @@
1
- export declare type TokenV2Payload = {
1
+ export type TokenV2Payload = {
2
2
  h: string;
3
3
  u: string;
4
4
  t: number;
@@ -1,5 +1,5 @@
1
1
  import { BlockAction } from '../../../blocker';
2
- export declare type TokenV3Payload = {
2
+ export type TokenV3Payload = {
3
3
  a: BlockAction;
4
4
  s: number;
5
5
  t: number;
@@ -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>): Promise<boolean>;
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>): Promise<void>;
13
+ sendTelemetry(context: ReadonlyContext<Req, Res>): AsyncOrSync<void>;
13
14
  }
@@ -1,13 +1,13 @@
1
1
  import { ActivityType } from '../../activities';
2
2
  import { ConfigurationParams } from '../../config';
3
- export declare type TelemetryActivityDetails = {
3
+ export type TelemetryActivityDetails = {
4
4
  enforcer_configs: ConfigurationParams<unknown, unknown>;
5
5
  module_version: string;
6
6
  update_reason: 'command';
7
7
  node_name?: string;
8
8
  os_name?: string;
9
9
  };
10
- export declare type TelemetryActivity = {
10
+ export type TelemetryActivity = {
11
11
  type: ActivityType.ENFORCER_TELEMETRY;
12
12
  timestamp: number;
13
13
  px_app_id: string;
@@ -1,5 +1,5 @@
1
1
  import { AsyncOrSync } from 'ts-essentials';
2
- export declare type Pbkdf2DecryptOptions = {
2
+ export type Pbkdf2DecryptOptions = {
3
3
  keylen?: number;
4
4
  ivlen?: number;
5
5
  };
@@ -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.1";
11
+ export declare const CORE_MODULE_VERSION = "JS Core 0.7.0";
@@ -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.1';
11
+ export const CORE_MODULE_VERSION = 'JS Core 0.7.0';
@@ -0,0 +1,5 @@
1
+ import { IHashUtils } from './IHashUtils';
2
+ import { Algorithm } from '../Algorithm';
3
+ export declare class CryptoJSHashUtils implements IHashUtils {
4
+ hashString(text: string, algo: Algorithm): string;
5
+ }
@@ -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
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './IHashUtils';
2
2
  export * from './SubtleCryptoHashUtils';
3
3
  export * from './CryptoHashUtils';
4
+ export * from './CryptoJSHashUtils';
@@ -1,3 +1,4 @@
1
1
  export * from './IHashUtils';
2
2
  export * from './SubtleCryptoHashUtils';
3
3
  export * from './CryptoHashUtils';
4
+ export * from './CryptoJSHashUtils';
@@ -11,3 +11,4 @@ export * from './constants';
11
11
  export * from './ModuleMode';
12
12
  export * from './VidSource';
13
13
  export * from './Algorithm';
14
+ export * from './url_parser';
@@ -11,3 +11,4 @@ export * from './constants';
11
11
  export * from './ModuleMode';
12
12
  export * from './VidSource';
13
13
  export * from './Algorithm';
14
+ export * from './url_parser';
@@ -0,0 +1,13 @@
1
+ import { IURLParser } from './IURLParser';
2
+ import { IURL } from '../../http';
3
+ export type UrlParserOptions = {
4
+ normalize?: boolean;
5
+ reverseCharactersEncoding?: boolean;
6
+ };
7
+ export declare class DefaultUrlParser implements IURLParser {
8
+ private options;
9
+ constructor(options?: UrlParserOptions);
10
+ parse(rawUrl: string): IURL;
11
+ private reverseCharactersEncoding;
12
+ private normalize;
13
+ }
@@ -0,0 +1,21 @@
1
+ export class DefaultUrlParser {
2
+ constructor(options) {
3
+ this.options = Object.assign({ normalize: true, reverseCharactersEncoding: false }, options);
4
+ }
5
+ parse(rawUrl) {
6
+ const url = new URL(rawUrl);
7
+ if (this.options.reverseCharactersEncoding) {
8
+ url.pathname = this.reverseCharactersEncoding(url.pathname);
9
+ }
10
+ if (this.options.normalize) {
11
+ url.pathname = this.normalize(url.pathname);
12
+ }
13
+ return url;
14
+ }
15
+ reverseCharactersEncoding(path) {
16
+ return decodeURI(path);
17
+ }
18
+ normalize(path) {
19
+ return path.replace(/\/+$/, '').replace(/\/+/g, '/');
20
+ }
21
+ }
@@ -0,0 +1,4 @@
1
+ import { IURL } from '../../http';
2
+ export interface IURLParser {
3
+ parse(rawUrl: string): IURL;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './IURLParser';
2
+ export * from './DefaultUrlParser';
@@ -0,0 +1,2 @@
1
+ export * from './IURLParser';
2
+ export * from './DefaultUrlParser';
@@ -6,6 +6,11 @@ export declare const getScoreApiDomain: (appId: string) => string;
6
6
  export declare const getCollectorDomain: (appId: string) => string;
7
7
  export declare const getAuthorizationHeader: (authToken: string) => string;
8
8
  export declare const getExtension: (route: string) => string;
9
+ /**
10
+ *
11
+ * @param rawUrl
12
+ * @deprecated use {@link IURLParser} instead.
13
+ */
9
14
  export declare const getDecodedUrl: (rawUrl: string) => IURL;
10
15
  export declare const removeSensitiveFields: <T extends Record<string, any>>(object: T, sensitiveFields: (keyof T)[]) => T;
11
16
  export declare const removeSensitiveHeaders: (headers: ReadonlyHeaders, sensitiveHeaderNames: string[]) => Record<string, string[]>;