From 0d6860bdbc18c3e6255b78f024e364aff0d8666a Mon Sep 17 00:00:00 2001 From: Konrad Markus Date: Thu, 28 Sep 2023 12:12:16 +0300 Subject: [PATCH 1/2] Add looser definition for MODE_TAXI.taxiCenter.phone --- maas-schemas/schemas/core/components/common.json | 5 +++++ maas-schemas/schemas/core/modes/MODE_TAXI.json | 2 +- .../src/io-ts/_types/core/components/common.ts | 14 ++++++++++++++ .../src/io-ts/_types/core/modes/MODE_TAXI.ts | 8 ++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/maas-schemas/schemas/core/components/common.json b/maas-schemas/schemas/core/components/common.json index 05d756291..e67024a43 100644 --- a/maas-schemas/schemas/core/components/common.json +++ b/maas-schemas/schemas/core/components/common.json @@ -91,6 +91,11 @@ "type": "string", "pattern": "^\\+?(?:\\d){6,14}\\d$" }, + "loosePhone": { + "description": "Loose definition of phone number", + "type": "string", + "pattern": "^\\+?[\\d\\s.-]+$" + }, "email": { "description": "Rough validation of a valid e-mail address, see https://davidcel.is/posts/stop-validating-email-addresses-with-regex/", "type": "string", diff --git a/maas-schemas/schemas/core/modes/MODE_TAXI.json b/maas-schemas/schemas/core/modes/MODE_TAXI.json index 091242953..f34104d40 100644 --- a/maas-schemas/schemas/core/modes/MODE_TAXI.json +++ b/maas-schemas/schemas/core/modes/MODE_TAXI.json @@ -84,7 +84,7 @@ "maxLength": 64 }, "phone": { - "$ref": "https://schemas.maas.global/core/components/common.json#/definitions/phone" + "$ref": "https://schemas.maas.global/core/components/common.json#/definitions/loosePhone" }, "supportUrl": { "description": "The taxi center support link. It can be for example: chat URL, FAQ url, etc...", diff --git a/maas-schemas/src/io-ts/_types/core/components/common.ts b/maas-schemas/src/io-ts/_types/core/components/common.ts index eb4f10282..4099fe01b 100644 --- a/maas-schemas/src/io-ts/_types/core/components/common.ts +++ b/maas-schemas/src/io-ts/_types/core/components/common.ts @@ -227,6 +227,20 @@ export type RawPhoneBrand = { readonly RawPhone: unique symbol; }; +// LoosePhone +// Loose definition of phone number +export type LoosePhone = t.Branded; +export type LoosePhoneC = t.BrandC; +export const LoosePhone: LoosePhoneC = t.brand( + t.string, + (x): x is t.Branded => + typeof x !== 'string' || x.match(RegExp('^\\+?[\\d\\s.-]+$', 'u')) !== null, + 'LoosePhone', +); +export type LoosePhoneBrand = { + readonly LoosePhone: unique symbol; +}; + // Email // Rough validation of a valid e-mail address, see https://davidcel.is/posts/stop-validating-email-addresses-with-regex/ export type Email = t.Branded; diff --git a/maas-schemas/src/io-ts/_types/core/modes/MODE_TAXI.ts b/maas-schemas/src/io-ts/_types/core/modes/MODE_TAXI.ts index 61045042d..61858c83a 100644 --- a/maas-schemas/src/io-ts/_types/core/modes/MODE_TAXI.ts +++ b/maas-schemas/src/io-ts/_types/core/modes/MODE_TAXI.ts @@ -44,7 +44,7 @@ export type MODE_TAXI = t.Branded< taxiCenter?: { image?: Units_c404_.Url; name?: string; - phone?: Common_ffba_.Phone; + phone?: Common_ffba_.LoosePhone; supportUrl?: Units_c404_.Url; } & Record; messageToDriver?: string; @@ -82,7 +82,7 @@ export type MODE_TAXIC = t.BrandC< t.PartialC<{ image: typeof Units_c404_.Url; name: t.StringC; - phone: typeof Common_ffba_.Phone; + phone: typeof Common_ffba_.LoosePhone; supportUrl: typeof Units_c404_.Url; }>, t.RecordC, @@ -120,7 +120,7 @@ export const MODE_TAXI: MODE_TAXIC = t.brand( t.partial({ image: Units_c404_.Url, name: t.string, - phone: Common_ffba_.Phone, + phone: Common_ffba_.LoosePhone, supportUrl: Units_c404_.Url, }), t.record(t.string, t.unknown), @@ -153,7 +153,7 @@ export const MODE_TAXI: MODE_TAXIC = t.brand( taxiCenter?: { image?: Units_c404_.Url; name?: string; - phone?: Common_ffba_.Phone; + phone?: Common_ffba_.LoosePhone; supportUrl?: Units_c404_.Url; } & Record; messageToDriver?: string; From 480c98709cd2ed655ef4286d3323fd637849788c Mon Sep 17 00:00:00 2001 From: Konrad Markus Date: Thu, 28 Sep 2023 12:23:05 +0300 Subject: [PATCH 2/2] v20.4.0 --- maas-schemas/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maas-schemas/package.json b/maas-schemas/package.json index 22b44a53d..cbde6f11f 100644 --- a/maas-schemas/package.json +++ b/maas-schemas/package.json @@ -1,6 +1,6 @@ { "name": "maas-schemas", - "version": "20.3.0", + "version": "20.4.0", "description": "Schemas for MaaS infrastructure", "main": "index.js", "engine": {