Skip to content

Commit

Permalink
Merge pull request #3780 from terascope/update-awesome-phonenumber
Browse files Browse the repository at this point in the history
[data-mate, ts-transforms, utils] update awesome-phonenumber from 2.70.0 to 7.1.0
  • Loading branch information
jsnoble authored Oct 1, 2024
2 parents 8c934f0 + 4b6f55a commit df37d49
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/data-mate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@terascope/types": "^1.1.0",
"@terascope/utils": "^1.2.0",
"@types/validator": "^13.12.2",
"awesome-phonenumber": "^2.70.0",
"awesome-phonenumber": "^7.1.0",
"date-fns": "^2.30.0",
"ip-bigint": "^3.0.3",
"ip6addr": "^0.2.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/data-mate/src/transforms/field-transform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from '@terascope/utils';
import { FieldType } from '@terascope/types';
import crypto from 'node:crypto';
import PhoneValidator from 'awesome-phonenumber';
import { parsePhoneNumber as _parsePhoneNumber } from 'awesome-phonenumber';
import { format as dateFormat, parse } from 'date-fns';
import { ReplaceLiteralConfig, ReplaceRegexConfig, ExtractFieldConfig } from './interfaces.js';
import {
Expand Down Expand Up @@ -599,7 +599,7 @@ function parsePhoneNumber(str: any) {
// needs to start with a +
if (testNumber.charAt(0) !== '+') testNumber = `+${testNumber}`;

const fullNumber = new PhoneValidator(testNumber).getNumber();
const fullNumber = _parsePhoneNumber(testNumber).number?.e164;
if (fullNumber) return String(fullNumber).slice(1);

throw Error('Could not determine the incoming phone number');
Expand Down
10 changes: 5 additions & 5 deletions packages/data-mate/src/validations/field-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ts from '@terascope/utils';
import ipaddr from 'ipaddr.js';
import { isIP as _isIP, isIPv6 } from 'is-ip';
import ip6addr from 'ip6addr';
import PhoneValidator from 'awesome-phonenumber';
import { parsePhoneNumber } from 'awesome-phonenumber';
import validator from 'validator';
import url from 'valid-url';
import { FieldType, GeoShapePoint, MACDelimiter } from '@terascope/types';
Expand Down Expand Up @@ -675,15 +675,15 @@ export function isISDN(input: unknown, _parentContext?: unknown): boolean {
if (ts.isNil(input)) return false;
if (isArray(input)) {
const fn = (data: any) => {
const phoneNumber = new PhoneValidator(`+${data}`);
return phoneNumber.isValid();
const phoneNumber = parsePhoneNumber(`+${data}`);
return phoneNumber.valid;
};

return _lift(fn, input, _parentContext);
}

const phoneNumber = new PhoneValidator(`+${input}`);
return phoneNumber.isValid();
const phoneNumber = parsePhoneNumber(`+${input}`);
return phoneNumber.valid;
}

interface MACAddressArgs {
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-transforms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@terascope/data-mate": "^1.2.0",
"@terascope/types": "^1.1.0",
"@terascope/utils": "^1.2.0",
"awesome-phonenumber": "^2.70.0",
"awesome-phonenumber": "^7.1.0",
"graphlib": "^2.1.8",
"is-ip": "^5.0.1",
"jexl": "^2.2.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/ts-transforms/src/operations/lib/validations/isdn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PhoneValidator from 'awesome-phonenumber';
import { parsePhoneNumber } from 'awesome-phonenumber';
import ValidationOpBase from './base.js';
import { PostProcessConfig } from '../../../interfaces.js';

Expand All @@ -8,14 +8,14 @@ export default class ISDN extends ValidationOpBase<any> {
}

normalize(data: any) {
const phoneNumber = new PhoneValidator(`+${data}`);
const fullNumber = phoneNumber.getNumber();
const phoneNumber = parsePhoneNumber(`+${data}`);
const fullNumber = phoneNumber.number?.e164;
if (fullNumber) return String(fullNumber).slice(1);
throw Error('could not normalize');
}

validate(value: string) {
if (!new PhoneValidator(`+${value}`).isValid()) return false;
if (!parsePhoneNumber(`+${value}`).valid) return false;
return true;
}
}
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@turf/line-to-polygon": "^7.1.0",
"@types/lodash-es": "^4.17.12",
"@types/validator": "^13.12.2",
"awesome-phonenumber": "^2.70.0",
"awesome-phonenumber": "^7.1.0",
"date-fns": "^2.30.0",
"date-fns-tz": "^1.3.7",
"datemath-parser": "^1.0.6",
Expand Down
9 changes: 4 additions & 5 deletions packages/utils/src/phone-number.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import PhoneValidator from 'awesome-phonenumber';
import { parsePhoneNumber as _parsePhoneNumber } from 'awesome-phonenumber';
import { toString, isString } from './strings.js';

import { isNumber, inNumberRange } from './numbers.js';

export function parsePhoneNumber(input: string | number): string {
const preppedInput = _prepPhoneNumber(toString(input).trim());

const fullNumber = new PhoneValidator(preppedInput).getNumber();

const fullNumber = _parsePhoneNumber(preppedInput).number?.e164;
if (fullNumber) return String(fullNumber).slice(1);

throw Error('Could not determine the incoming phone number');
Expand All @@ -25,9 +24,9 @@ function _prepPhoneNumber(input: string): string {

export function isISDN(input: unknown, country?: string): boolean {
if (isString(input) || isNumber(input)) {
const isdn = country ? new PhoneValidator(toString(input), country) : new PhoneValidator(`+${input}`);
const isdn = country ? _parsePhoneNumber(toString(input), { regionCode: country }) : _parsePhoneNumber(`+${input}`);

return isdn.isValid();
return isdn.valid;
}

return false;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3785,10 +3785,10 @@ available-typed-arrays@^1.0.7:
dependencies:
possible-typed-array-names "^1.0.0"

awesome-phonenumber@^2.70.0:
version "2.73.0"
resolved "https://registry.yarnpkg.com/awesome-phonenumber/-/awesome-phonenumber-2.73.0.tgz#c921f47450ba10bb2e4a6305cc85d802f57a96cf"
integrity sha512-zirkzWFUheNnnPY1QE05PQd+5drn+5kVy76gZ3WyXnLwzXOguw6sqksyZGO1qyNnYj3Y/SDITXnS/TCk/hJXpQ==
awesome-phonenumber@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/awesome-phonenumber/-/awesome-phonenumber-7.1.0.tgz#700be60aa6dff96c45ce35a3389304d283cb381d"
integrity sha512-i/pC5xvaNVrduufGtnw8O+abLWq70wd6YutiPYR2NqrnwtjBMk7rG/vJTktnAivSok+ZqlkFZzuVICgObpQi4w==

aws-sign2@~0.7.0:
version "0.7.0"
Expand Down

0 comments on commit df37d49

Please sign in to comment.