diff --git a/index.d.ts b/index.d.ts index d4764ed..dfd19ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,7 +5,7 @@ export function createPass(options: Schema.FactoryOptions): Promise; export declare class Pass { constructor(options: Schema.PassInstance); - public transitType: "PKTransitTypeAir" | "PKTransitTypeBoat" | "PKTransitTypeBus" | "PKTransitTypeGeneric" | "PKTransitTypeTrain"; + public transitType: Schema.TransitType; public headerFields: Schema.Field[]; public primaryFields: Schema.Field[]; public secondaryFields: Schema.Field[]; @@ -32,7 +32,7 @@ export declare class Pass { * * @see https://apple.co/2KOv0OW - Passes support localization */ - localize(lang: string, translations: Object): this; + localize(lang: string, translations?: { [key: string]: string }): this; /** * Sets expirationDate property to a W3C-formatted date @@ -41,7 +41,7 @@ export declare class Pass { * @params date * @returns {this} */ - expiration(date: Date): this; + expiration(date: Date | null): this; /** * Sets voided property to true @@ -54,49 +54,65 @@ export declare class Pass { /** * Sets current pass' relevancy through beacons * @param data - * @returns Pass instance with `length` property to check the - * valid structures added + * @returns {Pass} */ - beacons(...data: Schema.Beacon[]): PassWithLengthField; + beacons(...data: Schema.Beacon[] | null): this; /** * Sets current pass' relevancy through locations * @param data - * @returns Pass instance with `length` property to check the - * valid structures added + * @returns {Pass} */ - locations(...data: Schema.Location[]): PassWithLengthField; + locations(...data: Schema.Location[] | null): this; /** * Sets current pass' relevancy through a date * @param data * @returns {Pass} */ - relevantDate(date: Date): this; + relevantDate(date: Date | null): this; /** - * Adds barcode to the pass. If data is an Object, will be treated as one-element array. - * @param first - data to be used to generate a barcode. If string, Barcode will contain structures for all the supported types. - * @param data - the other Barcode structures to be used - * @see https://apple.co/2C74kbm + * Adds barcodes "barcodes" property. + * It allows to pass a string to autogenerate all the structures. + * + * @method barcode + * @params first - a structure or the string (message) that will generate + * all the barcodes + * @params data - other barcodes support + * @return {this} Improved this with length property and other methods */ - barcode(first: string | Schema.Barcode, ...data: Schema.Barcode[]): PassWithBarcodeMethods; + barcodes(first: null | string | Schema.Barcode, ...data: Schema.Barcode[]): this; /** - * Sets nfc infos for the pass - * @param data - NFC data + * Given an index <= the amount of already set "barcodes", + * this let you choose which structure to use for retrocompatibility + * property "barcode". + * + * @method barcode + * @params format - the format to be used + * @return {this} + */ + barcode(chosenFormat: Schema.BarcodeFormat | null): this; + + /** + * Sets nfc fields in properties + * + * @method nfc + * @params data - the data to be pushed in the pass + * @returns {this} * @see https://apple.co/2wTxiaC */ - nfc(data: Schema.NFC): this; -} + nfc(data: Schema.NFC | null): this; -declare interface PassWithLengthField extends Pass { - length: number; -} - -declare interface PassWithBarcodeMethods extends PassWithLengthField { - backward: (format: Schema.BarcodeFormat | null) => Pass; - autocomplete: () => Pass; + /** + * Allows to get the current inserted props; + * will return all props from valid overrides, + * template's pass.json and methods-inserted ones; + * + * @returns The properties will be inserted in the pass. + */ + readonly props: Readonly; } declare namespace Schema { @@ -105,8 +121,8 @@ declare namespace Schema { type DateTimeStyle = "PKDateStyleNone" | "PKDateStyleShort" | "PKDateStyleMedium" | "PKDateStyleLong" | "PKDateStyleFull"; type NumberStyle = "PKNumberStyleDecimal" | "PKNumberStylePercent" | "PKNumberStyleScientific" | "PKNumberStyleSpellOut"; type BarcodeFormat = "PKBarcodeFormatQR" | "PKBarcodeFormatPDF417" | "PKBarcodeFormatAztec" | "PKBarcodeFormatCode128"; - type RelevanceType = "beacons" | "locations" | "maxDistance" | "relevantDate"; type SemanticsEventType = "PKEventTypeGeneric" | "PKEventTypeLivePerformance" | "PKEventTypeMovie" | "PKEventTypeSports" | "PKEventTypeConference" | "PKEventTypeConvention" | "PKEventTypeWorkshop" | "PKEventTypeSocialGathering"; + type TransitType = "PKTransitTypeAir" | "PKTransitTypeBoat" | "PKTransitTypeBus" | "PKTransitTypeGeneric" | "PKTransitTypeTrain"; interface Certificates { wwdr?: string; @@ -178,6 +194,34 @@ declare namespace Schema { semantics?: Semantics; } + interface PassFields { + auxiliaryFields: Field[]; + backFields: Field[]; + headerFields: Field[]; + primaryFields: Field[]; + secondaryFields: Field[]; + } + + interface ValidPassType { + boardingPass?: PassFields & { transitType: TransitType }; + eventTicket?: PassFields; + coupon?: PassFields; + generic?: PassFields; + storeCard?: PassFields; + } + + interface ValidPass extends OverridesSupportedOptions, ValidPassType { + barcode?: Barcode; + barcodes?: Barcode[]; + beacons?: Beacon[]; + locations?: Location[]; + maxDistance?: number; + relevantDate?: string; + nfc?: NFC; + expirationDate?: string; + voided?: boolean; + } + interface Beacon { major?: number; minor?: number; diff --git a/package-lock.json b/package-lock.json index 2ea2871..a65cc85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,34 +4,71 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@hapi/address": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.0.0.tgz", + "integrity": "sha512-mV6T0IYqb0xL1UALPFplXYQmR0twnXG0M6jUswpquqT2sD12BOiCiLy3EvMp/Fy7s3DZElC4/aPjEjo2jeZpvw==" + }, + "@hapi/hoek": { + "version": "6.2.4", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-6.2.4.tgz", + "integrity": "sha512-HOJ20Kc93DkDVvjwHyHawPwPkX44sIrbXazAUDiUXaY2R9JwQGo2PhFfnQtdrsIe4igjG2fPgMra7NYw7qhy0A==" + }, + "@hapi/joi": { + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-15.1.0.tgz", + "integrity": "sha512-n6kaRQO8S+kepUTbXL9O/UOL788Odqs38/VOfoCrATDtTvyfiO3fgjlSRaNkHabpTLgM7qru9ifqXlXbXk8SeQ==", + "requires": { + "@hapi/address": "2.x.x", + "@hapi/hoek": "6.x.x", + "@hapi/marker": "1.x.x", + "@hapi/topo": "3.x.x" + } + }, + "@hapi/marker": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@hapi/marker/-/marker-1.0.0.tgz", + "integrity": "sha512-JOfdekTXnJexfE8PyhZFyHvHjt81rBFSAbTIRAhF2vv/2Y1JzoKsGqxH/GpZJoF7aEfYok8JVcAHmSz1gkBieA==" + }, + "@hapi/topo": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-3.1.0.tgz", + "integrity": "sha512-gZDI/eXOIk8kP2PkUKjWu9RW8GGVd2Hkgjxyr/S7Z+JF+0mr7bAlbw+DkTRxnD580o8Kqxlnba9wvqp5aOHBww==", + "requires": { + "@hapi/hoek": "6.x.x" + } + }, "@types/debug": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.4.tgz", "integrity": "sha512-D9MyoQFI7iP5VdpEyPZyjjqIJ8Y8EDNQFIFVLOmeg1rI1xiHOChyUPMPRUVfqFCerxfE+yS3vMyj37F6IdtOoQ==", "dev": true }, + "@types/hapi__joi": { + "version": "15.0.2", + "resolved": "https://registry.npmjs.org/@types/hapi__joi/-/hapi__joi-15.0.2.tgz", + "integrity": "sha512-EsOuX8cbAdSgp/9mo5NoI4vMnZ68c8Jk1fl3tyA07zd9aOq4q4udsJ2/YjhaFw0u2Zp6hBonUBrKEWotZg7PDQ==", + "dev": true, + "requires": { + "@types/hapi__joi": "*" + } + }, "@types/jasmine": { "version": "3.3.13", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.3.13.tgz", "integrity": "sha512-iczmLoIiVymaD1TIr2UctxjFkNEslVE/QtNAUmpDsD71cZfZBAsPCUv1Y+8AwsfA8bLx2ccr7d95T9w/UAirlQ==", "dev": true }, - "@types/joi": { - "version": "14.3.3", - "resolved": "https://registry.npmjs.org/@types/joi/-/joi-14.3.3.tgz", - "integrity": "sha512-6gAT/UkIzYb7zZulAbcof3lFxpiD5EI6xBeTvkL1wYN12pnFQ+y/+xl9BvnVgxkmaIDN89xWhGZLD9CvuOtZ9g==", - "dev": true - }, "@types/node": { - "version": "12.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.0.tgz", - "integrity": "sha512-Jrb/x3HT4PTJp6a4avhmJCDEVrPdqLfl3e8GGMbpkGGdwAV5UGlIs4vVEfsHHfylZVOKZWpOqmqFH8CbfOZ6kg==", + "version": "12.0.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.10.tgz", + "integrity": "sha512-LcsGbPomWsad6wmMNv7nBLw7YYYyfdYcz6xryKYQhx89c3XXan+8Q6AJ43G5XDIaklaVkK3mE4fCb0SBvMiPSQ==", "dev": true }, "@types/node-forge": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-0.8.3.tgz", - "integrity": "sha512-cDc9enmIRJdF5b3rkKsDMBhE/UrvwbDEwCYL8y9k/v7HUWPaSeK6lG2LF1SrrkqFyKPkQBTFL940YZGO+OSbaQ==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-0.8.4.tgz", + "integrity": "sha512-bueB7eD1EUkWaz7SW57QYor6nZSQtH0gJwfcp9kuXhdnypYy6Frnqa73LNXqX41E71ANffBK9EJX+aQH2/eTrQ==", "dev": true, "requires": { "@types/node": "*" @@ -74,9 +111,9 @@ "dev": true }, "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "requires": { "ms": "^2.1.1" } @@ -87,11 +124,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "hoek": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-5.0.4.tgz", - "integrity": "sha512-Alr4ZQgoMlnere5FZJsIyfIjORBqZll5POhDsF4q64dPuJR6rNxXdDxtHSQq8OXRurhmx+PWYEE8bXRROY8h0w==" - }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -108,14 +140,6 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, - "isemail": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/isemail/-/isemail-3.2.0.tgz", - "integrity": "sha512-zKqkK+O+dGqevc93KNsbZ/TqTUFd46MwWjYOoMrjIMZ51eU7DtQG3Wmd9SQQT7i7RVnuTPEiYEWHU3MSbxC1Tg==", - "requires": { - "punycode": "2.x.x" - } - }, "jasmine": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.4.0.tgz", @@ -148,16 +172,6 @@ "integrity": "sha512-HU/YxV4i6GcmiH4duATwAbJQMlE0MsDIR5XmSVxURxKHn3aGAdbY1/ZJFmVRbKtnLwIxxMJD7gYaPsypcbYimg==", "dev": true }, - "joi": { - "version": "13.7.0", - "resolved": "https://registry.npmjs.org/joi/-/joi-13.7.0.tgz", - "integrity": "sha512-xuY5VkHfeOYK3Hdi91ulocfuFopwgbSORmIwzcwHKESQhC7w1kD5jaVSPnqDxS2I8t3RZ9omCKAxNwXN5zG1/Q==", - "requires": { - "hoek": "5.x.x", - "isemail": "3.x.x", - "topo": "3.x.x" - } - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -173,14 +187,14 @@ "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node-forge": { - "version": "0.7.6", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz", - "integrity": "sha512-sol30LUpz1jQFBjOKwbjxijiE3b6pjd74YwfD0fJOKPjF+fONKb2Yg8rYgS6+bK6VDl+/wfr4IYpC7jDzLUIfw==" + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.8.5.tgz", + "integrity": "sha512-vFMQIWt+J/7FLNyKouZ9TazT74PRV3wgv9UT4cRjC8BffxFbKXkgIWR42URCPSnHm/QDz6BOlb2Q0U4+VQT67Q==" }, "once": { "version": "1.4.0", @@ -197,30 +211,10 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, - "punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" - }, - "topo": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/topo/-/topo-3.0.3.tgz", - "integrity": "sha512-IgpPtvD4kjrJ7CRA3ov2FhWQADwv+Tdqbsf1ZnPUSAtCJ9e1Z44MmoSGDXGk4IppoZA7jd/QRkNddlLJWlUZsQ==", - "requires": { - "hoek": "6.x.x" - }, - "dependencies": { - "hoek": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-6.0.3.tgz", - "integrity": "sha512-TU6RyZ/XaQCTWRLrdqZZtZqwxUVr6PDMfi6MlWNURZ7A6czanQqX4pFE1mdOUQR9FdPCsZ0UzL8jI/izZ+eBSQ==" - } - } - }, "typescript": { - "version": "3.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", - "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz", + "integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==", "dev": true }, "wrappy": { diff --git a/package.json b/package.json index 1db65ed..387e304 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,10 @@ "Pass" ], "dependencies": { - "debug": "^3.2.6", - "joi": "^13.7.0", + "@hapi/joi": "^15.1.0", + "debug": "^4.1.1", "moment": "^2.24.0", - "node-forge": "^0.7.6", + "node-forge": "^0.8.5", "yazl": "^2.5.1" }, "engines": { @@ -30,12 +30,12 @@ }, "devDependencies": { "@types/debug": "^4.1.4", + "@types/hapi__joi": "^15.0.2", "@types/jasmine": "^3.3.13", - "@types/joi": "^14.3.3", - "@types/node": "^12.0.0", - "@types/node-forge": "^0.8.3", + "@types/node": "^12.0.10", + "@types/node-forge": "^0.8.4", "@types/yazl": "^2.4.1", "jasmine": "^3.4.0", - "typescript": "^3.4.5" + "typescript": "^3.5.2" } } diff --git a/src/schema.ts b/src/schema.ts index 7c6ff28..f9ca5fb 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1,4 +1,4 @@ -import Joi from "joi"; +import Joi from "@hapi/joi"; import debug from "debug"; const schemaDebug = debug("Schema");