diff --git a/src/factory.ts b/src/factory.ts index 4463937..8d4a261 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -103,6 +103,7 @@ async function getModelFolderContents(model: string): Promise ) ]).then(buffers => // Assigning each file path to its buffer + // and discarding the empty ones validFiles.reduce((acc, file, index) => { if (!buffers[index].length) { return acc; diff --git a/src/pass.ts b/src/pass.ts index 0e3e358..538716e 100644 --- a/src/pass.ts +++ b/src/pass.ts @@ -15,7 +15,6 @@ import { const barcodeDebug = debug("passkit:barcode"); const genericDebug = debug("passkit:generic"); - const noop = () => {}; const transitType = Symbol("transitType"); const barcodesFillMissing = Symbol("bfm"); @@ -35,7 +34,6 @@ export interface PassWithBarcodeMethods extends PassWithLengthField { } export class Pass implements PassIndexSignature { - // private model: string; private bundle: schema.BundleUnit; private l10nBundles: schema.PartitionedBundle["l10nBundle"]; private _fields: (keyof schema.PassFields)[]; @@ -214,7 +212,7 @@ export class Pass implements PassIndexSignature { return this; } - this._props.expirationDate = dateParse; + this._props["expirationDate"] = dateParse; return this; } @@ -227,7 +225,7 @@ export class Pass implements PassIndexSignature { */ void(): this { - this._props.voided = true; + this._props["voided"] = true; return this; } @@ -295,16 +293,16 @@ export class Pass implements PassIndexSignature { relevantDate(date: Date): this { if (!(date instanceof Date)) { - genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date")); - return this; - } + genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date")); + return this; + } const parsedDate = dateToW3CString(date); if (!parsedDate) { // @TODO: create message "Unable to format date" return this; - } + } this._props["relevantDate"] = parsedDate; return this; @@ -405,7 +403,7 @@ export class Pass implements PassIndexSignature { * @returns {this} Improved this, with length property and retroCompatibility method. */ - [barcodesFillMissing](): this { + private [barcodesFillMissing](): this { const props = this._props["barcodes"]; if (props.length === 4 || !props.length) { @@ -433,7 +431,7 @@ export class Pass implements PassIndexSignature { * @return {this} */ - [barcodesSetBackward](format: schema.BarcodeFormat | null): this { + private [barcodesSetBackward](format: schema.BarcodeFormat | null): this { if (format === null) { this._props["barcode"] = undefined; return this; @@ -488,7 +486,7 @@ export class Pass implements PassIndexSignature { * @returns {Buffer} */ - _sign(manifest: { [key: string]: string }): Buffer { + private _sign(manifest: { [key: string]: string }): Buffer { let signature = forge.pkcs7.createSignedData(); signature.content = forge.util.createBuffer(JSON.stringify(manifest), "utf8"); @@ -551,7 +549,7 @@ export class Pass implements PassIndexSignature { * @returns {Promise} Edited pass.json buffer or Object containing error. */ - _patch(passCoreBuffer: Buffer): Buffer { + private _patch(passCoreBuffer: Buffer): Buffer { const passFile = JSON.parse(passCoreBuffer.toString()); if (Object.keys(this._props).length) { @@ -564,9 +562,9 @@ export class Pass implements PassIndexSignature { Object.keys(this._props).forEach(prop => { if (passFile[prop] && passFile[prop] instanceof Array) { - passFile[prop].push(...this._props[prop]); + passFile[prop] = [ ...passFile[prop], ...this._props[prop] ]; } else if (passFile[prop] && passFile[prop] instanceof Object) { - Object.assign(passFile[prop], this._props[prop]); + passFile[prop] = { ...passFile[prop], ...this._props[prop] }; } else { passFile[prop] = this._props[prop]; } diff --git a/src/schema.ts b/src/schema.ts index db22a2b..30ca83f 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -276,7 +276,7 @@ const semantics = Joi.object().keys({ balance: currencyAmount }); -interface ValidPassType { +export interface ValidPassType { boardingPass?: PassFields & { transitType: TransitType }; eventTicket?: PassFields; coupon?: PassFields;