perimeterx-js-core 0.37.2 → 0.38.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.
@@ -127,18 +127,15 @@ var AccountDefender = /** @class */ (function () {
127
127
  : null;
128
128
  };
129
129
  AccountDefender.prototype.extractJwtData = function (jwt, userIdFieldName, additionalFieldNames, context) {
130
+ var _this = this;
130
131
  try {
131
132
  var decodedJwt_1 = this.getDecodedJwt(jwt, context);
132
133
  if (decodedJwt_1) {
133
- var appUserId = utils_1.getPropertyFromObject.apply(void 0, __spreadArray([decodedJwt_1], userIdFieldName.split('.'), false));
134
+ var appUserId = this.lookupJwtField(decodedJwt_1, userIdFieldName).value;
134
135
  var additionalFields = additionalFieldNames.reduce(function (matchedFields, fieldName) {
135
- var fieldNameParts = fieldName.split('.');
136
- var value = utils_1.getPropertyFromObject.apply(void 0, __spreadArray([decodedJwt_1], fieldNameParts, false));
136
+ var _a = _this.lookupJwtField(decodedJwt_1, fieldName), value = _a.value, key = _a.key;
137
137
  if (value) {
138
- var key = fieldNameParts[fieldNameParts.length - 1];
139
- if (key !== undefined) {
140
- matchedFields[key] = value;
141
- }
138
+ matchedFields[key] = value;
142
139
  }
143
140
  return matchedFields;
144
141
  }, {});
@@ -150,6 +147,14 @@ var AccountDefender = /** @class */ (function () {
150
147
  }
151
148
  return null;
152
149
  };
150
+ AccountDefender.prototype.lookupJwtField = function (decodedJwt, fieldName) {
151
+ if (Object.prototype.hasOwnProperty.call(decodedJwt, fieldName)) {
152
+ return { value: decodedJwt[fieldName], key: fieldName };
153
+ }
154
+ var parts = fieldName.split('.');
155
+ var value = utils_1.getPropertyFromObject.apply(void 0, __spreadArray([decodedJwt], parts, false));
156
+ return { value: value, key: fieldName };
157
+ };
153
158
  AccountDefender.prototype.getDecodedJwt = function (jwt, context) {
154
159
  var _a, _b;
155
160
  try {
@@ -15,4 +15,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
15
15
  exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
16
16
  exports.URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
17
17
  exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
18
- exports.CORE_MODULE_VERSION = 'JS Core 0.37.2';
18
+ exports.CORE_MODULE_VERSION = 'JS Core 0.38.0';
@@ -51,15 +51,11 @@ export class AccountDefender {
51
51
  try {
52
52
  const decodedJwt = this.getDecodedJwt(jwt, context);
53
53
  if (decodedJwt) {
54
- const appUserId = getPropertyFromObject(decodedJwt, ...userIdFieldName.split('.'));
54
+ const { value: appUserId } = this.lookupJwtField(decodedJwt, userIdFieldName);
55
55
  const additionalFields = additionalFieldNames.reduce((matchedFields, fieldName) => {
56
- const fieldNameParts = fieldName.split('.');
57
- const value = getPropertyFromObject(decodedJwt, ...fieldNameParts);
56
+ const { value, key } = this.lookupJwtField(decodedJwt, fieldName);
58
57
  if (value) {
59
- const key = fieldNameParts[fieldNameParts.length - 1];
60
- if (key !== undefined) {
61
- matchedFields[key] = value;
62
- }
58
+ matchedFields[key] = value;
63
59
  }
64
60
  return matchedFields;
65
61
  }, {});
@@ -71,6 +67,14 @@ export class AccountDefender {
71
67
  }
72
68
  return null;
73
69
  }
70
+ lookupJwtField(decodedJwt, fieldName) {
71
+ if (Object.prototype.hasOwnProperty.call(decodedJwt, fieldName)) {
72
+ return { value: decodedJwt[fieldName], key: fieldName };
73
+ }
74
+ const parts = fieldName.split('.');
75
+ const value = getPropertyFromObject(decodedJwt, ...parts);
76
+ return { value, key: fieldName };
77
+ }
74
78
  getDecodedJwt(jwt, context) {
75
79
  try {
76
80
  const encodedPayload = jwt.split('.')?.[1];
@@ -12,4 +12,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
12
12
  export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
13
13
  export const URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
14
14
  export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
15
- export const CORE_MODULE_VERSION = 'JS Core 0.37.2';
15
+ export const CORE_MODULE_VERSION = 'JS Core 0.38.0';
@@ -18,5 +18,9 @@ export declare class AccountDefender<Req, Res, Supported extends string, Added>
18
18
  modifyOutgoingResponse(_context: ReadonlyContext<Req, Res>): Promise<void>;
19
19
  protected getJwtData(context: ReadonlyContext<Req, Res>): JwtData | null;
20
20
  protected extractJwtData(jwt: string, userIdFieldName: string, additionalFieldNames: string[], context: ReadonlyContext<Req, Res>): JwtData | null;
21
+ protected lookupJwtField(decodedJwt: any, fieldName: string): {
22
+ value: any;
23
+ key: string;
24
+ };
21
25
  protected getDecodedJwt(jwt: string, context: ReadonlyContext<Req, Res>): any | null;
22
26
  }
@@ -12,4 +12,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
12
12
  export declare const EMAIL_ADDRESS_REGEX: RegExp;
13
13
  export declare const URL_REGEX: RegExp;
14
14
  export declare const REGEX_STRUCTURE: RegExp;
15
- export declare const CORE_MODULE_VERSION = "JS Core 0.37.2";
15
+ export declare const CORE_MODULE_VERSION = "JS Core 0.38.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perimeterx-js-core",
3
- "version": "0.37.2",
3
+ "version": "0.38.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "typesVersions": {