mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Changed how colors validation happens: now they will make validation throw if they have an incorrect value
This commit is contained in:
@@ -5,7 +5,7 @@ import * as Signature from "./Signature";
|
|||||||
import * as Strings from "./StringsUtils";
|
import * as Strings from "./StringsUtils";
|
||||||
import { getModelFolderContents } from "./parser";
|
import { getModelFolderContents } from "./parser";
|
||||||
import { Stream } from "stream";
|
import { Stream } from "stream";
|
||||||
import { isValidRGB, processDate } from "./utils";
|
import { processDate } from "./utils";
|
||||||
|
|
||||||
/** Exporting for tests specs */
|
/** Exporting for tests specs */
|
||||||
export const propsSymbol = Symbol("props");
|
export const propsSymbol = Symbol("props");
|
||||||
@@ -516,30 +516,6 @@ export default class PKPass extends Bundle {
|
|||||||
) {
|
) {
|
||||||
const fileNames = Object.keys(this[filesSymbol]);
|
const fileNames = Object.keys(this[filesSymbol]);
|
||||||
|
|
||||||
/**
|
|
||||||
* Filtering colors props that have an
|
|
||||||
* invalid RGB value
|
|
||||||
*/
|
|
||||||
|
|
||||||
const passColors = [
|
|
||||||
"backgroundColor",
|
|
||||||
"foregroundColor",
|
|
||||||
"labelColor",
|
|
||||||
] as Array<keyof Schemas.PassColors>;
|
|
||||||
|
|
||||||
for (let i = 0; i < passColors.length; i++) {
|
|
||||||
const colorProperty = passColors[i];
|
|
||||||
const colorInProps = this[propsSymbol][colorProperty];
|
|
||||||
|
|
||||||
if (colorInProps && !isValidRGB(colorInProps)) {
|
|
||||||
console.warn(
|
|
||||||
`'${colorProperty}' property has been removed from pass.json as it has not a valid RGB-string value.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
delete this[propsSymbol][colorProperty];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const passJson = Buffer.from(JSON.stringify(this[propsSymbol]));
|
const passJson = Buffer.from(JSON.stringify(this[propsSymbol]));
|
||||||
super.addBuffer("pass.json", passJson);
|
super.addBuffer("pass.json", passJson);
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ import { Barcode } from "./Barcodes";
|
|||||||
import { Location } from "./Location";
|
import { Location } from "./Location";
|
||||||
import { Beacon } from "./Beacons";
|
import { Beacon } from "./Beacons";
|
||||||
import { NFC } from "./NFC";
|
import { NFC } from "./NFC";
|
||||||
import { Field } from "./PassFieldContent";
|
|
||||||
import { PassFields, TransitType } from "./PassFields";
|
import { PassFields, TransitType } from "./PassFields";
|
||||||
import { Semantics } from "./SemanticTags";
|
import { Semantics } from "./SemanticTags";
|
||||||
import { CertificatesSchema } from "./Certificates";
|
import { CertificatesSchema } from "./Certificates";
|
||||||
|
|
||||||
|
const RGB_COLOR_REGEX =
|
||||||
|
/rgb\(\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*,\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*,\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*\)/;
|
||||||
|
|
||||||
export interface FileBuffers {
|
export interface FileBuffers {
|
||||||
[key: string]: Buffer;
|
[key: string]: Buffer;
|
||||||
}
|
}
|
||||||
@@ -128,10 +130,10 @@ export const OverridablePassProps = Joi.object<OverridablePassProps>({
|
|||||||
groupingIdentifier: Joi.string(),
|
groupingIdentifier: Joi.string(),
|
||||||
suppressStripShine: Joi.boolean(),
|
suppressStripShine: Joi.boolean(),
|
||||||
maxDistance: Joi.number().positive(),
|
maxDistance: Joi.number().positive(),
|
||||||
labelColor: Joi.string().min(10).max(16),
|
|
||||||
authenticationToken: Joi.string().min(16),
|
authenticationToken: Joi.string().min(16),
|
||||||
backgroundColor: Joi.string().min(10).max(16),
|
labelColor: Joi.string().regex(RGB_COLOR_REGEX),
|
||||||
foregroundColor: Joi.string().min(10).max(16),
|
backgroundColor: Joi.string().regex(RGB_COLOR_REGEX),
|
||||||
|
foregroundColor: Joi.string().regex(RGB_COLOR_REGEX),
|
||||||
associatedStoreIdentifiers: Joi.array().items(Joi.number()),
|
associatedStoreIdentifiers: Joi.array().items(Joi.number()),
|
||||||
userInfo: Joi.alternatives(Joi.object().unknown(), Joi.array()),
|
userInfo: Joi.alternatives(Joi.object().unknown(), Joi.array()),
|
||||||
// parsing url as set of words and nums followed by dots, optional port and any possible path after
|
// parsing url as set of words and nums followed by dots, optional port and any possible path after
|
||||||
|
|||||||
Reference in New Issue
Block a user