@diia-inhouse/utils 6.0.98 → 6.1.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.
@@ -1,5 +1,5 @@
1
1
  import { InputPhoneCodeOrgParams } from "./interfaces/publicService.js";
2
- import { UserTokenData } from "@diia-inhouse/types";
2
+ import { Logger, UserTokenData } from "@diia-inhouse/types";
3
3
  import { ContactsResponse, DSBodyItem, InputPhoneCodeItem, InputPhoneCodeOrg, InputTextMlc, TextLabelMlc } from "@diia-inhouse/design-system";
4
4
 
5
5
  //#region src/publicService.d.ts
@@ -54,6 +54,7 @@ declare const PublicServiceUtils: {
54
54
  * extractPhoneNumber('380123456789', 'invalid') // throws Error(`Invalid country code`)
55
55
  */
56
56
  extractPhoneNumber(phoneNumber: string, phoneCodeValue: string): string | never;
57
+ extractPhoneNumberSafe(phoneNumber: string, phoneCodeValue: string, logger: Logger): string | undefined;
57
58
  };
58
59
  //#endregion
59
60
  export { PublicServiceUtils };
@@ -132,6 +132,17 @@ const PublicServiceUtils = {
132
132
  if (!countryCode) throw new Error("Invalid country code");
133
133
  if (!cleanPhoneNumber.startsWith(countryCode.value)) throw new Error(`Phone number must start with country code ${countryCode.value}`);
134
134
  return cleanPhoneNumber.slice(countryCode.value.length);
135
+ },
136
+ extractPhoneNumberSafe(phoneNumber, phoneCodeValue, logger) {
137
+ try {
138
+ return this.extractPhoneNumber(phoneNumber, phoneCodeValue);
139
+ } catch (err) {
140
+ logger.warn("Failed to extract phone number by country code", {
141
+ err,
142
+ phoneCodeValue
143
+ });
144
+ return;
145
+ }
135
146
  }
136
147
  };
137
148
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/utils",
3
- "version": "6.0.98",
3
+ "version": "6.1.0",
4
4
  "type": "module",
5
5
  "description": "Generic utils",
6
6
  "main": "dist/index.js",