mirror of
https://github.com/covidpass-org/covidpass.git
synced 2025-02-18 04:30:53 +01:00
Improve pass fields and add fallback romanization
This commit is contained in:
parent
8e38eb3550
commit
af77280202
@ -239,7 +239,7 @@ function Form(): JSX.Element {
|
|||||||
{t('index:addToWallet')}
|
{t('index:addToWallet')}
|
||||||
</button>
|
</button>
|
||||||
<div id="spin" className={loading ? undefined : "hidden"}>
|
<div id="spin" className={loading ? undefined : "hidden"}>
|
||||||
<svg className="animate-spin h-5 w-5 ml-2" viewBox="0 0 24 24">
|
<svg className="animate-spin h-5 w-5 ml-3" viewBox="0 0 24 24">
|
||||||
<circle className="opacity-0" cx="12" cy="12" r="10" stroke="currentColor"
|
<circle className="opacity-0" cx="12" cy="12" r="10" stroke="currentColor"
|
||||||
strokeWidth="4"/>
|
strokeWidth="4"/>
|
||||||
<path className="opacity-75" fill="currentColor"
|
<path className="opacity-75" fill="currentColor"
|
||||||
|
115
src/payload.ts
115
src/payload.ts
@ -2,7 +2,7 @@ import {ValueSets} from "./value_sets";
|
|||||||
import {Constants} from "./constants";
|
import {Constants} from "./constants";
|
||||||
|
|
||||||
enum CertificateType {
|
enum CertificateType {
|
||||||
Vaccination = 'Vaccination',
|
Vaccine = 'Vaccine',
|
||||||
Test = 'Test',
|
Test = 'Test',
|
||||||
Recovery = 'Recovery',
|
Recovery = 'Recovery',
|
||||||
}
|
}
|
||||||
@ -63,25 +63,35 @@ export class Payload {
|
|||||||
throw new Error('certificateData');
|
throw new Error('certificateData');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get name and date of birth information
|
// Get name information
|
||||||
const nameInformation = covidCertificate['nam'];
|
const nameInformation = covidCertificate['nam'];
|
||||||
const dateOfBirthInformation = covidCertificate['dob'];
|
|
||||||
|
|
||||||
if (nameInformation == undefined) {
|
if (nameInformation == undefined) {
|
||||||
throw new Error('nameMissing');
|
throw new Error('nameMissing');
|
||||||
}
|
}
|
||||||
if (dateOfBirthInformation == undefined) {
|
|
||||||
throw new Error('dobMissing');
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = `${nameInformation['fn']}, ${nameInformation['gn']}`;
|
const firstName = nameInformation['gn'];
|
||||||
const dateOfBirth = dateOfBirthInformation;
|
const lastName = nameInformation['fn'];
|
||||||
|
|
||||||
|
const transliteratedFirstName = nameInformation['gnt'];
|
||||||
|
const transliteratedLastName = nameInformation['fnt'];
|
||||||
|
|
||||||
|
// Check if name contains non-latin characters
|
||||||
|
const nameRegex = new RegExp('^(\\p{Script=Latin}|[ -\'`´])+$', 'u');
|
||||||
|
|
||||||
|
let name: string;
|
||||||
|
|
||||||
|
if (nameRegex.test(firstName) && nameRegex.test(lastName)) {
|
||||||
|
name = `${firstName} ${lastName}`;
|
||||||
|
} else {
|
||||||
|
name = `${transliteratedFirstName} ${transliteratedLastName}`;
|
||||||
|
}
|
||||||
|
|
||||||
let properties: object;
|
let properties: object;
|
||||||
|
|
||||||
// Set certificate type and properties
|
// Set certificate type and properties
|
||||||
if (covidCertificate['v'] !== undefined) {
|
if (covidCertificate['v'] !== undefined) {
|
||||||
this.certificateType = CertificateType.Vaccination;
|
this.certificateType = CertificateType.Vaccine;
|
||||||
properties = covidCertificate['v'][0];
|
properties = covidCertificate['v'][0];
|
||||||
}
|
}
|
||||||
if (covidCertificate['t'] !== undefined) {
|
if (covidCertificate['t'] !== undefined) {
|
||||||
@ -96,23 +106,16 @@ export class Payload {
|
|||||||
throw new Error('certificateType')
|
throw new Error('certificateType')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get country code, identifier and issuer
|
// Get identifier and issuer
|
||||||
const countryCode = properties['co'];
|
|
||||||
const uvci = properties['ci'];
|
const uvci = properties['ci'];
|
||||||
const certificateIssuer = properties['is'];
|
const certificateIssuer = properties['is'];
|
||||||
|
|
||||||
if (!(countryCode in valueSets.countryCodes)) {
|
|
||||||
throw new Error('invalidCountryCode');
|
|
||||||
}
|
|
||||||
|
|
||||||
const country = valueSets.countryCodes[countryCode].display;
|
|
||||||
|
|
||||||
const generic: PassDictionary = {
|
const generic: PassDictionary = {
|
||||||
headerFields: [
|
headerFields: [
|
||||||
{
|
{
|
||||||
key: "type",
|
key: "type",
|
||||||
label: "Certificate Type",
|
label: "EU Digital COVID",
|
||||||
value: this.certificateType
|
value: this.certificateType + " Certificate"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
primaryFields: [
|
primaryFields: [
|
||||||
@ -123,14 +126,7 @@ export class Payload {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
secondaryFields: [],
|
secondaryFields: [],
|
||||||
auxiliaryFields: [
|
auxiliaryFields: [],
|
||||||
{
|
|
||||||
key: "dob",
|
|
||||||
label: "Date of Birth",
|
|
||||||
value: dateOfBirth,
|
|
||||||
textAlignment: TextAlignment.right
|
|
||||||
}
|
|
||||||
],
|
|
||||||
backFields: [
|
backFields: [
|
||||||
{
|
{
|
||||||
key: "uvci",
|
key: "uvci",
|
||||||
@ -141,11 +137,6 @@ export class Payload {
|
|||||||
key: "issuer",
|
key: "issuer",
|
||||||
label: "Certificate Issuer",
|
label: "Certificate Issuer",
|
||||||
value: certificateIssuer
|
value: certificateIssuer
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "country",
|
|
||||||
label: "Country",
|
|
||||||
value: country
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -164,8 +155,17 @@ export class Payload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fillPassData(type: CertificateType, data: PassDictionary, properties: Object, valueSets: ValueSets): PassDictionary {
|
static fillPassData(type: CertificateType, data: PassDictionary, properties: Object, valueSets: ValueSets): PassDictionary {
|
||||||
|
// Get country name
|
||||||
|
const countryCode = properties['co'];
|
||||||
|
|
||||||
|
if (!(countryCode in valueSets.countryCodes)) {
|
||||||
|
throw new Error('invalidCountryCode');
|
||||||
|
}
|
||||||
|
|
||||||
|
const country = valueSets.countryCodes[countryCode].display;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CertificateType.Vaccination:
|
case CertificateType.Vaccine:
|
||||||
const dose = `${properties['dn']}/${properties['sd']}`;
|
const dose = `${properties['dn']}/${properties['sd']}`;
|
||||||
const dateOfVaccination = properties['dt'];
|
const dateOfVaccination = properties['dt'];
|
||||||
const medialProductKey = properties['mp'];
|
const medialProductKey = properties['mp'];
|
||||||
@ -178,7 +178,7 @@ export class Payload {
|
|||||||
throw new Error('invalidManufacturer')
|
throw new Error('invalidManufacturer')
|
||||||
}
|
}
|
||||||
|
|
||||||
const vaccineName = valueSets.medicalProducts[medialProductKey].display;
|
const vaccineName = valueSets.medicalProducts[medialProductKey].display.replace(/\s*\([^)]*\)\s*/g, "");
|
||||||
const manufacturer = valueSets.manufacturers[manufacturerKey].display;
|
const manufacturer = valueSets.manufacturers[manufacturerKey].display;
|
||||||
|
|
||||||
data.secondaryFields.push(...[
|
data.secondaryFields.push(...[
|
||||||
@ -194,11 +194,19 @@ export class Payload {
|
|||||||
textAlignment: TextAlignment.right
|
textAlignment: TextAlignment.right
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
data.auxiliaryFields.splice(0, 0, {
|
data.auxiliaryFields.push(...[
|
||||||
key: "vaccine",
|
{
|
||||||
label: "Vaccine",
|
key: "vaccine",
|
||||||
value: vaccineName
|
label: "Vaccine",
|
||||||
});
|
value: vaccineName
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "cov",
|
||||||
|
label: "Country of Vaccination",
|
||||||
|
value: country,
|
||||||
|
textAlignment: TextAlignment.right
|
||||||
|
}
|
||||||
|
]);
|
||||||
data.backFields.push(...[
|
data.backFields.push(...[
|
||||||
{
|
{
|
||||||
key: "manufacturer",
|
key: "manufacturer",
|
||||||
@ -234,7 +242,7 @@ export class Payload {
|
|||||||
data.secondaryFields.push(...[
|
data.secondaryFields.push(...[
|
||||||
{
|
{
|
||||||
key: "result",
|
key: "result",
|
||||||
label: "Result",
|
label: "Test Result",
|
||||||
value: testResult
|
value: testResult
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -244,7 +252,6 @@ export class Payload {
|
|||||||
textAlignment: TextAlignment.right
|
textAlignment: TextAlignment.right
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
data.auxiliaryFields.pop();
|
|
||||||
data.auxiliaryFields.push(...[
|
data.auxiliaryFields.push(...[
|
||||||
{
|
{
|
||||||
key: "test",
|
key: "test",
|
||||||
@ -258,6 +265,11 @@ export class Payload {
|
|||||||
textAlignment: TextAlignment.right
|
textAlignment: TextAlignment.right
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
data.backFields.push({
|
||||||
|
key: "cot",
|
||||||
|
label: "Country of Test",
|
||||||
|
value: country
|
||||||
|
});
|
||||||
if (testingCentre !== undefined)
|
if (testingCentre !== undefined)
|
||||||
data.backFields.push({
|
data.backFields.push({
|
||||||
key: "centre",
|
key: "centre",
|
||||||
@ -276,29 +288,28 @@ export class Payload {
|
|||||||
const validUntil = properties['du'];
|
const validUntil = properties['du'];
|
||||||
|
|
||||||
data.secondaryFields.push(...[
|
data.secondaryFields.push(...[
|
||||||
{
|
|
||||||
key: "result",
|
|
||||||
label: "Test Result",
|
|
||||||
value: "Detected"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: "from",
|
key: "from",
|
||||||
label: "Valid From",
|
label: "Valid From",
|
||||||
value: validFrom,
|
value: validFrom,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "dov",
|
||||||
|
label: "Date of positive Test",
|
||||||
|
value: firstPositiveTestDate,
|
||||||
textAlignment: TextAlignment.right
|
textAlignment: TextAlignment.right
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
data.auxiliaryFields.pop();
|
|
||||||
data.auxiliaryFields.push(...[
|
data.auxiliaryFields.push(...[
|
||||||
{
|
|
||||||
key: "testdate",
|
|
||||||
label: "Test Date",
|
|
||||||
value: firstPositiveTestDate
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: "until",
|
key: "until",
|
||||||
label: "Valid Until",
|
label: "Valid Until",
|
||||||
value: validUntil,
|
value: validUntil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "cov",
|
||||||
|
label: "Country of Test",
|
||||||
|
value: country,
|
||||||
textAlignment: TextAlignment.right
|
textAlignment: TextAlignment.right
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "ES2018",
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
"dom.iterable",
|
"dom.iterable",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user