Skip to content

Commit

Permalink
Merge pull request #762 from konker/mode-taxi-phone-loosen
Browse files Browse the repository at this point in the history
Mode taxi phone loosen
  • Loading branch information
konker authored Sep 28, 2023
2 parents db7eeb8 + 480c987 commit 0bf24be
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion maas-schemas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maas-schemas",
"version": "20.3.0",
"version": "20.4.0",
"description": "Schemas for MaaS infrastructure",
"main": "index.js",
"engine": {
Expand Down
5 changes: 5 additions & 0 deletions maas-schemas/schemas/core/components/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion maas-schemas/schemas/core/modes/MODE_TAXI.json
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down
14 changes: 14 additions & 0 deletions maas-schemas/src/io-ts/_types/core/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ export type RawPhoneBrand = {
readonly RawPhone: unique symbol;
};

// LoosePhone
// Loose definition of phone number
export type LoosePhone = t.Branded<string, LoosePhoneBrand>;
export type LoosePhoneC = t.BrandC<t.StringC, LoosePhoneBrand>;
export const LoosePhone: LoosePhoneC = t.brand(
t.string,
(x): x is t.Branded<string, LoosePhoneBrand> =>
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<string, EmailBrand>;
Expand Down
8 changes: 4 additions & 4 deletions maas-schemas/src/io-ts/_types/core/modes/MODE_TAXI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
messageToDriver?: string;
Expand Down Expand Up @@ -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<t.StringC, t.UnknownC>,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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<string, unknown>;
messageToDriver?: string;
Expand Down

0 comments on commit 0bf24be

Please sign in to comment.