Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNI-572 Personal Data Catalog #773

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "21.1.0",
"version": "22.0.0",
"description": "Schemas for MaaS infrastructure",
"main": "index.js",
"engine": {
Expand Down
12 changes: 12 additions & 0 deletions maas-schemas/schemas/core/components/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@
"type": "object",
"properties": {},
"additionalProperties": false
},
"nationality": {
"description": "ISO 3166-1 alpha-2 country code, see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2",
"type": "string",
"pattern": "^[A-Z]{2,2}$",
"examples": ["FI", "GB"],
"invalid": {
"IiI=": "empty string",
"IvCfkqki": "emoji",
"ImZpIg==": "lower case alpha-2 country code",
"IkZJTiI=": "alpha-3 country code"
}
}
}
}
3 changes: 3 additions & 0 deletions maas-schemas/schemas/core/customer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
"zipCode": {
"$ref": "https://schemas.maas.global/core/components/address.json#/definitions/zipCode"
},
"nationality": {
"$ref": "https://schemas.maas.global/core/components/common.json#/definitions/nationality"
},
"locale": {
"$ref": "https://schemas.maas.global/core/components/i18n.json#/definitions/locale"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schemas.maas.global/maas-backend/customers/personalDataCatalog.json",
"description": "MaaS customer personal data catalog schema",
"definitions": {
"regionRestriction": {
"type": "array",
"description": "Restrict to the specified list of regions",
"items": {
"$ref": "https://schemas.maas.global/core/region.json#/definitions/regionId"
}
},
"dependsOnRestriction": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of another personal data item that this item depends on. I.e. the dependee item must have a value for this item to be enabled"
},
"values": {
"type": "array",
"description": "A list of possible values of the dependee item which enable the dependency",
"items": {
"type": "string"
}
}
},
"required": ["name"]
},
"personalDataCatalogItem": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["string", "ISODate", "ISODatetime", "ISOCountryAlpha2"]
},
"enum": {
"type": "array",
"description": "The value is limited to a fixed set of possible values",
"items": {
"type": "string"
}
},
"canShowPlain": {
"type": "boolean",
"description": "True if the client should show the value in plain text. False if the value should be obfuscated."
},
"regionRestriction": {
"$ref": "#/definitions/regionRestriction"
},
"dependsOn": {
"type": "array",
"items": {
"$ref": "#/definitions/dependsOnRestriction"
}
}
},
"required": ["name", "type", "canShowPlain"],
"additionalProperties": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
"properties": {
"customer": {
"$ref": "https://schemas.maas.global/maas-backend/customers/customer.json"
},
"personalDataCatalog": {
"type": "array",
"items": {
"$ref": "https://schemas.maas.global/maas-backend/customers/personalDataCatalog.json#/definitions/personalDataCatalogItem"
}
}
},
"additionalProperties": false,
"required": ["customer"]
"required": ["customer", "personalDataCatalog"]
}
1 change: 1 addition & 0 deletions maas-schemas/src/ajv/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const registry: mjsv.Registry = {
require('../../schemas/maas-backend/customers/personal-documents/update/request.json'),
require('../../schemas/maas-backend/customers/personal-documents/update/response.json'),
require('../../schemas/maas-backend/customers/personalData.json'),
require('../../schemas/maas-backend/customers/personalDataCatalog.json'),
require('../../schemas/maas-backend/customers/retrieve/request.json'),
require('../../schemas/maas-backend/customers/retrieve/response.json'),
require('../../schemas/maas-backend/customers/stats/request.json'),
Expand Down
14 changes: 14 additions & 0 deletions maas-schemas/src/io-ts/_translation.log
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,20 @@ INFO: missing description
in schemas/maas-backend/customers/personalData.json
INFO: missing description
in schemas/maas-backend/customers/personalData.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: primitive type "string" used outside top-level definitions
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: missing description
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: missing description
in schemas/maas-backend/customers/personalDataCatalog.json
INFO: primitive type "integer" used outside top-level definitions
in schemas/maas-backend/customers/stats/response.json
WARNING: minimum field not supported outside top-level definitions
Expand Down
27 changes: 27 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 @@ -459,6 +459,33 @@ export type EmptyObjectBrand = {
readonly EmptyObject: unique symbol;
};

// Nationality
// ISO 3166-1 alpha-2 country code, see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
export type Nationality = t.Branded<string, NationalityBrand>;
export type NationalityC = t.BrandC<t.StringC, NationalityBrand>;
export const Nationality: NationalityC = t.brand(
t.string,
(x): x is t.Branded<string, NationalityBrand> =>
typeof x !== 'string' || x.match(RegExp('^[A-Z]{2,2}$', 'u')) !== null,
'Nationality',
);
export type NationalityBrand = {
readonly Nationality: unique symbol;
};
/** require('io-ts-validator').validator(nonEmptyArray(Nationality)).decodeSync(examplesNationality) // => examplesNationality */
export const examplesNationality: NonEmptyArray<Nationality> = [
'FI',
'GB',
] as unknown as NonEmptyArray<Nationality>;
// NEGATIVE Test Case: empty string
/** require('io-ts-validator').validator(Nationality).decodeEither("")._tag // => 'Left' */
// NEGATIVE Test Case: emoji
/** require('io-ts-validator').validator(Nationality).decodeEither("💩")._tag // => 'Left' */
// NEGATIVE Test Case: lower case alpha-2 country code
/** require('io-ts-validator').validator(Nationality).decodeEither("fi")._tag // => 'Left' */
// NEGATIVE Test Case: alpha-3 country code
/** require('io-ts-validator').validator(Nationality).decodeEither("FIN")._tag // => 'Left' */

// Common
// The default export. More information at the top.
export type Common = t.Branded<unknown, CommonBrand>;
Expand Down
4 changes: 4 additions & 0 deletions maas-schemas/src/io-ts/_types/core/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type Customer = t.Branded<
state?: Address_2d0a_.State;
country?: Address_2d0a_.Country;
zipCode?: Address_2d0a_.ZipCode;
nationality?: Common_ffba_.Nationality;
locale?: I18n_b70d_.Locale;
appInstanceId?: Common_ffba_.AppInstanceId;
opaqueId?: Common_ffba_.OpaqueId;
Expand Down Expand Up @@ -118,6 +119,7 @@ export type CustomerC = t.BrandC<
state: typeof Address_2d0a_.State;
country: typeof Address_2d0a_.Country;
zipCode: typeof Address_2d0a_.ZipCode;
nationality: typeof Common_ffba_.Nationality;
locale: typeof I18n_b70d_.Locale;
appInstanceId: typeof Common_ffba_.AppInstanceId;
opaqueId: typeof Common_ffba_.OpaqueId;
Expand Down Expand Up @@ -204,6 +206,7 @@ export const Customer: CustomerC = t.brand(
state: Address_2d0a_.State,
country: Address_2d0a_.Country,
zipCode: Address_2d0a_.ZipCode,
nationality: Common_ffba_.Nationality,
locale: I18n_b70d_.Locale,
appInstanceId: Common_ffba_.AppInstanceId,
opaqueId: Common_ffba_.OpaqueId,
Expand Down Expand Up @@ -274,6 +277,7 @@ export const Customer: CustomerC = t.brand(
state?: Address_2d0a_.State;
country?: Address_2d0a_.Country;
zipCode?: Address_2d0a_.ZipCode;
nationality?: Common_ffba_.Nationality;
locale?: I18n_b70d_.Locale;
appInstanceId?: Common_ffba_.AppInstanceId;
opaqueId?: Common_ffba_.OpaqueId;
Expand Down
Loading