mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 17: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 {
|
||||
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 (!this[passTypeSymbol]) {
|
||||
console.warn(
|
||||
@@ -422,11 +453,19 @@ export default class PKPass extends Bundle {
|
||||
} else {
|
||||
this.type = type;
|
||||
|
||||
this.headerFields.push(...data[type]?.headerFields);
|
||||
this.primaryFields.push(...data[type]?.primaryFields);
|
||||
this.secondaryFields.push(...data[type]?.secondaryFields);
|
||||
this.auxiliaryFields.push(...data[type]?.auxiliaryFields);
|
||||
this.backFields.push(...data[type]?.backFields);
|
||||
const {
|
||||
headerFields = [],
|
||||
primaryFields = [],
|
||||
secondaryFields = [],
|
||||
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");
|
||||
|
||||
export const PassProps = Joi.object({
|
||||
export const PassProps = Joi.object<
|
||||
OverridablePassProps & PassKindsProps & PassPropsFromMethods
|
||||
>({
|
||||
...OverridablePassProps,
|
||||
...PassKindsProps,
|
||||
...PassPropsFromMethods,
|
||||
|
||||
Reference in New Issue
Block a user