mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Added merging of pass.json props in this[propsSymbol] with an overwrite warning
This commit is contained in:
@@ -409,6 +409,37 @@ export default class PKPass extends Bundle {
|
|||||||
|
|
||||||
const type = possibleTypes.find((type) => Boolean(data[type]));
|
const type = possibleTypes.find((type) => Boolean(data[type]));
|
||||||
|
|
||||||
|
const {
|
||||||
|
boardingPass,
|
||||||
|
coupon,
|
||||||
|
storeCard,
|
||||||
|
generic,
|
||||||
|
eventTicket,
|
||||||
|
...otherPassData
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validating the rest of the data and
|
||||||
|
* importing all the props. They are going
|
||||||
|
* to overwrite props setted by user but
|
||||||
|
* we can't do much about.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const validation = Schemas.getValidated(
|
||||||
|
otherPassData,
|
||||||
|
Schemas.PassProps,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (validation) {
|
||||||
|
if (Object.keys(this[propsSymbol]).length) {
|
||||||
|
console.warn(
|
||||||
|
"The imported pass.json's properties will be joined with the current setted props. You might lose some data.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(this[propsSymbol], validation);
|
||||||
|
}
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
if (!this[passTypeSymbol]) {
|
if (!this[passTypeSymbol]) {
|
||||||
console.warn(
|
console.warn(
|
||||||
@@ -422,11 +453,19 @@ export default class PKPass extends Bundle {
|
|||||||
} else {
|
} else {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
this.headerFields.push(...data[type]?.headerFields);
|
const {
|
||||||
this.primaryFields.push(...data[type]?.primaryFields);
|
headerFields = [],
|
||||||
this.secondaryFields.push(...data[type]?.secondaryFields);
|
primaryFields = [],
|
||||||
this.auxiliaryFields.push(...data[type]?.auxiliaryFields);
|
secondaryFields = [],
|
||||||
this.backFields.push(...data[type]?.backFields);
|
auxiliaryFields = [],
|
||||||
|
backFields = [],
|
||||||
|
} = data[type];
|
||||||
|
|
||||||
|
this.headerFields.push(...headerFields);
|
||||||
|
this.primaryFields.push(...primaryFields);
|
||||||
|
this.secondaryFields.push(...secondaryFields);
|
||||||
|
this.auxiliaryFields.push(...auxiliaryFields);
|
||||||
|
this.backFields.push(...backFields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,9 @@ export const OverridablePassProps = Joi.object<OverridablePassProps>({
|
|||||||
),
|
),
|
||||||
}).with("webServiceURL", "authenticationToken");
|
}).with("webServiceURL", "authenticationToken");
|
||||||
|
|
||||||
export const PassProps = Joi.object({
|
export const PassProps = Joi.object<
|
||||||
|
OverridablePassProps & PassKindsProps & PassPropsFromMethods
|
||||||
|
>({
|
||||||
...OverridablePassProps,
|
...OverridablePassProps,
|
||||||
...PassKindsProps,
|
...PassKindsProps,
|
||||||
...PassPropsFromMethods,
|
...PassPropsFromMethods,
|
||||||
|
|||||||
Reference in New Issue
Block a user