UNPKG

@1amageek/passkit

Version:
68 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const PassKit = require("./index"); const Format = require("dateformat"); /// Template class Template { /// constructor constructor(organizationName, description, serialNumber, pass) { this.formatVersion = 1; this.passTypeIdentifier = PassKit.certificates.options.passTypeIdentifier; this.teamIdentifier = PassKit.certificates.options.teamIdentifier; this.organizationName = organizationName; this.description = description; this.serialNumber = serialNumber; this.boardingPass = pass.boardingPass; this.coupon = pass.coupon; this.eventTicket = pass.eventTicket; this.generic = pass.generic; this.storeCard = pass.storeCard; } validate() { // Required keys const requireKeys = [ 'description', 'formatVersion', 'organizationName', 'passTypeIdentifier', 'serialNumber', 'teamIdentifier', 'authenticationToken', ]; for (const key of requireKeys) { if (!this[key]) { throw Error(`Missing ${key}, ${key} is required`); } if (key === 'authenticationToken') { if (this[key].length < 16) { throw Error(`${key} must be 16 characters or longer.`); } } } // ATS if (this['webServiceURL']) { if (this['webServiceURL'].includes('http:')) { throw Error(`webServiceURL must use https. ${this['webServiceURL']}`); } } } toPass() { this.validate(); const pass = {}; for (const key in this) { const value = this[key]; if (value instanceof PassKit.RGB) { pass[key] = value.toString(); } else if (value instanceof Date) { pass[key] = Format(value, 'isoUtcDateTime'); } else { pass[key] = value; } } return pass; } } exports.default = Template; //# sourceMappingURL=template.js.map