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