Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passkit-generator

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passkit-generator - npm Package Compare versions

Comparing version 3.1.9 to 3.1.10

14

lib/Bundle.d.ts
/// <reference types="node" />
/// <reference types="node" />
import { Stream } from "stream";

@@ -48,3 +49,3 @@ export declare const filesSymbol: unique symbol;

*/
protected [freezeSymbol](): void;
private [freezeSymbol];
/**

@@ -56,2 +57,13 @@ * Tells if this bundle still allows files to be added.

/**
* Returns a copy of the current list of buffers
* that have been added to the class.
*
* It does not include translation files, manifest
* and signature.
*
* Final files list might differ due to export
* conditions.
*/
get files(): string[];
/**
* Allows files to be added to the bundle.

@@ -58,0 +70,0 @@ * If the bundle is closed, it will throw an error.

@@ -73,2 +73,15 @@ "use strict";

/**
* Returns a copy of the current list of buffers
* that have been added to the class.
*
* It does not include translation files, manifest
* and signature.
*
* Final files list might differ due to export
* conditions.
*/
get files() {
return Object.keys(this[exports.filesSymbol]);
}
/**
* Allows files to be added to the bundle.

@@ -75,0 +88,0 @@ * If the bundle is closed, it will throw an error.

@@ -62,3 +62,8 @@ "use strict";

catch (err) {
console.warn(err.message ? err.message : err);
if (err instanceof Error) {
console.warn(err.message ? err.message : err);
}
else {
console.warn(err);
}
}

@@ -65,0 +70,0 @@ }

98

lib/getModelFolderContents.js

@@ -19,33 +19,18 @@ "use strict";

const modelFilesList = await fs_1.promises.readdir(modelPath);
// No dot-starting files, manifest and signature
const filteredModelRecords = Utils.removeHidden(modelFilesList).filter((f) => !/(manifest|signature)/i.test(f) &&
// No dot-starting files, manifest and signature and only files with an extension
const modelSuitableRootPaths = Utils.removeHidden(modelFilesList).filter((f) => !/(manifest|signature)/i.test(f) &&
/.+$/.test(path.parse(f).ext));
const modelRecords = (await Promise.all(
/**
* Obtaining flattened array of buffer records
* containing file name and the buffer itself.
*
* This goes also to read every nested l10n
* subfolder.
*/
filteredModelRecords.map((fileOrDirectoryPath) => {
const fullPath = path.resolve(modelPath, fileOrDirectoryPath);
return readFileOrDirectory(fullPath);
})))
.flat(1)
.reduce((acc, current) => ({ ...acc, ...current }), {});
return modelRecords;
const modelRecords = await Promise.all(modelSuitableRootPaths.map((fileOrDirectoryPath) => readFileOrDirectory(path.resolve(modelPath, fileOrDirectoryPath))));
return Object.fromEntries(modelRecords.flat(1));
}
catch (_err) {
const err = _err;
if ((err === null || err === void 0 ? void 0 : err.code) === "ENOENT") {
if (err.syscall === "open") {
// file opening failed
throw new Error(Messages.format(Messages.MODELS.FILE_NO_OPEN, JSON.stringify(err)));
}
else if (err.syscall === "scandir") {
// directory reading failed
throw new Error(Messages.format(Messages.MODELS.DIR_NOT_FOUND, err.path));
}
catch (err) {
if (!isErrorErrNoException(err) || !isMissingFileError(err)) {
throw err;
}
if (isFileReadingFailure(err)) {
throw new Error(Messages.format(Messages.MODELS.FILE_NO_OPEN, JSON.stringify(err)));
}
if (isDirectoryReadingFailure(err)) {
throw new Error(Messages.format(Messages.MODELS.DIR_NOT_FOUND, err.path));
}
throw err;

@@ -55,4 +40,18 @@ }

exports.default = getModelFolderContents;
function isErrorErrNoException(err) {
return Object.prototype.hasOwnProperty.call(err, "errno");
}
function isMissingFileError(err) {
return err.code === "ENOENT";
}
function isDirectoryReadingFailure(err) {
return err.syscall === "scandir";
}
function isFileReadingFailure(err) {
return err.syscall === "open";
}
/**
* Reads sequentially
* Allows reading both a whole directory or a set of
* file in the same flow
*
* @param filePath

@@ -62,41 +61,34 @@ * @returns

async function readFileOrDirectory(filePath) {
if ((await fs_1.promises.lstat(filePath)).isDirectory()) {
return Promise.all(await readDirectory(filePath));
const stats = await fs_1.promises.lstat(filePath);
if (stats.isDirectory()) {
return readFilesInDirectory(filePath);
}
else {
return fs_1.promises
.readFile(filePath)
.then((content) => getObjectFromModelFile(filePath, content, 1));
return getFileContents(filePath).then((result) => [result]);
}
}
/**
* Returns an object containing the parsed fileName
* from a path along with its content.
* Reads a directory and returns all
* the files in it
*
* @param filePath
* @param content
* @param depthFromEnd - used to preserve localization lproj content
* @returns
*/
function getObjectFromModelFile(filePath, content, depthFromEnd) {
const fileComponents = filePath.split(path.sep);
const fileName = fileComponents
.slice(fileComponents.length - depthFromEnd)
.join("/");
return { [fileName]: content };
async function readFilesInDirectory(filePath) {
const dirContent = await fs_1.promises.readdir(filePath).then(Utils.removeHidden);
return Promise.all(dirContent.map((fileName) => getFileContents(path.resolve(filePath, fileName), 2)));
}
/**
* Reads a directory and returns all the files in it
* as an Array<Promise>
*
* @param filePath
* @param pathSlicesDepthFromEnd used to preserve localization lproj content
* @returns
*/
async function readDirectory(filePath) {
const dirContent = await fs_1.promises.readdir(filePath).then(Utils.removeHidden);
return dirContent.map(async (fileName) => {
const content = await fs_1.promises.readFile(path.resolve(filePath, fileName));
return getObjectFromModelFile(path.resolve(filePath, fileName), content, 2);
});
async function getFileContents(filePath, pathSlicesDepthFromEnd = 1) {
const fileComponents = filePath.split(path.sep);
const fileName = fileComponents
.slice(fileComponents.length - pathSlicesDepthFromEnd)
.join("/");
const content = await fs_1.promises.readFile(filePath);
return [fileName, content];
}
//# sourceMappingURL=getModelFolderContents.js.map
/// <reference types="node" />
/// <reference types="node" />
import { Stream } from "stream";

@@ -6,10 +7,9 @@ import { Buffer } from "buffer";

import * as Schemas from "./schemas";
/** Exporting for tests specs */
export declare const propsSymbol: unique symbol;
export declare const localizationSymbol: unique symbol;
export declare const importMetadataSymbol: unique symbol;
export declare const createManifestSymbol: unique symbol;
export declare const closePassSymbol: unique symbol;
export declare const passTypeSymbol: unique symbol;
export declare const certificatesSymbol: unique symbol;
declare const propsSymbol: unique symbol;
declare const localizationSymbol: unique symbol;
declare const importMetadataSymbol: unique symbol;
declare const createManifestSymbol: unique symbol;
declare const closePassSymbol: unique symbol;
declare const passTypeSymbol: unique symbol;
declare const certificatesSymbol: unique symbol;
export default class PKPass extends Bundle {

@@ -68,5 +68,3 @@ private [certificatesSymbol];

*
* It will (automatically) throw an exception
* if current type is not "boardingPass".
*
* @throws if current type is not "boardingPass".
* @param value

@@ -79,4 +77,3 @@ */

*
* It will (automatically) throw an exception
* if current type is not "boardingPass".
* @throws (automatically) if current type is not "boardingPass".
*/

@@ -87,5 +84,5 @@ get transitType(): Schemas.TransitType;

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if it has not a valid type.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/

@@ -96,6 +93,5 @@ get primaryFields(): Schemas.Field[];

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/

@@ -106,7 +102,2 @@ get secondaryFields(): Schemas.Field[];

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
*
* For Typescript users: this signature allows

@@ -116,2 +107,6 @@ * in any case to add the 'row' field, but on

* passes.
*
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/

@@ -122,6 +117,5 @@ get auxiliaryFields(): Schemas.FieldWithRow[];

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/

@@ -132,6 +126,5 @@ get headerFields(): Schemas.Field[];

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/

@@ -143,5 +136,5 @@ get backFields(): Schemas.Field[];

* **Warning**: setting a type with this setter,
* will reset all the imported or manually
* setted fields (primaryFields, secondaryFields,
* headerFields, auxiliaryFields, backFields)
* will reset all the fields (primaryFields,
* secondaryFields, headerFields, auxiliaryFields, backFields),
* both imported or manually set.
*/

@@ -151,17 +144,18 @@ set type(nextType: Schemas.PassTypesProps | undefined);

/**
* Allows adding a new asset inside the pass / bundle;
* If an empty buffer is passed, it won't be added to
* the bundle.
* Allows adding a new asset inside the pass / bundle with
* the following exceptions:
*
* `manifest.json` and `signature` files will be ignored.
* - Empty buffers are ignored;
* - `manifest.json` and `signature` files will be ignored;
* - `pass.json` will be read validated and merged in the
* current instance, if it wasn't added previously.
* It's properties will overwrite the instance ones.
* You might loose data;
* - `pass.strings` files will be read, parsed and merged
* with the current translations. Comments will be ignored;
* - `personalization.json` will be read, validated and added.
* They will be stripped out when exporting the pass if
* it won't have NFC details or if any of the personalization
* files is missing;
*
* If a `pass.json` is passed to this method (and it has
* not been added previously), it will be read, validated
* and merged in the current instance. Its properties
* will overwrite the ones setted through methods.
*
* If a `pass.strings` file is passed, it will be read, parsed
* and merged with the translations added previously.
* Comments will be ignored.
*
* @param pathName

@@ -175,7 +169,2 @@ * @param buffer

*
* **Warning**: if this file contains a type (boardingPass,
* coupon, and so on), it will replace the current one,
* causing, therefore, the destroy of the fields added
* previously.
*
* @param data

@@ -235,3 +224,3 @@ */

*
* Setting `translations` to `null`, fully deletes a language,
* Setting `translations` to `null` fully deletes a language,
* its translations and its files.

@@ -249,3 +238,6 @@ *

*
* Pass `null` to remove the expiration date.
*
* @param date
* @throws if pass is frozen due to previous export
* @returns

@@ -270,2 +262,3 @@ */

* @param beacons
* @throws if pass is frozen due to previous export
* @returns

@@ -292,2 +285,3 @@ */

* @param locations
* @throws if pass is frozen due to previous export
* @returns

@@ -301,5 +295,8 @@ */

*
* @param date
* Pass `null` to remove relevant date from this pass.
*
* @param {Date | null} date
* @throws if pass is frozen due to previous export
*/
setRelevantDate(date: Date): void;
setRelevantDate(date: Date | null): void;
/**

@@ -311,4 +308,11 @@ * Allows to specify some barcodes formats.

*
* It accepts either a string from which all formats will
* be generated or a specific set of barcodes objects
* to be validated and used.
*
* Pass `null` to remove all the barcodes.
*
* @see https://developer.apple.com/documentation/walletpasses/pass/barcodes
* @param barcodes
* @throws if pass is frozen due to previous export
* @returns

@@ -327,2 +331,3 @@ */

* @param data
* @throws if pass is frozen due to previous export
* @returns

@@ -332,1 +337,2 @@ */

}
export {};
"use strict";
var _a, _b, _c;
Object.defineProperty(exports, "__esModule", { value: true });
exports.certificatesSymbol = exports.passTypeSymbol = exports.closePassSymbol = exports.createManifestSymbol = exports.importMetadataSymbol = exports.localizationSymbol = exports.propsSymbol = void 0;
const tslib_1 = require("tslib");

@@ -16,10 +15,9 @@ const buffer_1 = require("buffer");

const Messages = tslib_1.__importStar(require("./messages"));
/** Exporting for tests specs */
exports.propsSymbol = Symbol("props");
exports.localizationSymbol = Symbol("pass.l10n");
exports.importMetadataSymbol = Symbol("import.pass.metadata");
exports.createManifestSymbol = Symbol("pass.manifest");
exports.closePassSymbol = Symbol("pass.close");
exports.passTypeSymbol = Symbol("pass.type");
exports.certificatesSymbol = Symbol("pass.certificates");
const propsSymbol = Symbol("props");
const localizationSymbol = Symbol("pass.l10n");
const importMetadataSymbol = Symbol("import.pass.metadata");
const createManifestSymbol = Symbol("pass.manifest");
const closePassSymbol = Symbol("pass.close");
const passTypeSymbol = Symbol("pass.type");
const certificatesSymbol = Symbol("pass.certificates");
const RegExps = {

@@ -36,29 +34,2 @@ PASS_JSON: /pass\.json/,

class PKPass extends Bundle_1.default {
// **************** //
// *** INSTANCE *** //
// **************** //
constructor(buffers, certificates, props) {
super("application/vnd.apple.pkpass");
this[_a] = {};
this[_b] = {};
this[_c] = undefined;
if (buffers && typeof buffers === "object") {
const buffersEntries = Object.entries(buffers);
for (let i = buffersEntries.length, buffer; (buffer = buffersEntries[--i]);) {
const [fileName, contentBuffer] = buffer;
this.addBuffer(fileName, contentBuffer);
}
}
else {
console.warn(Messages.format(Messages.INIT.INVALID_BUFFERS, typeof buffers));
}
if (props) {
/** Overrides validation and pushing in props */
const overridesValidation = Schemas.validate(Schemas.OverridablePassProps, props);
Object.assign(this[exports.propsSymbol], overridesValidation);
}
if (certificates) {
this.certificates = certificates;
}
}
/**

@@ -79,3 +50,3 @@ * Either create a pass from another one

/** Cloning is happening here */
certificates = source[exports.certificatesSymbol];
certificates = source[certificatesSymbol];
buffers = {};

@@ -94,3 +65,3 @@ const buffersEntries = Object.entries(source[Bundle_1.filesSymbol]);

*/
buffers["pass.json"] = buffer_1.Buffer.from(JSON.stringify(source[exports.propsSymbol]));
buffers["pass.json"] = buffer_1.Buffer.from(JSON.stringify(source[propsSymbol]));
}

@@ -128,2 +99,29 @@ else {

}
// **************** //
// *** INSTANCE *** //
// **************** //
constructor(buffers, certificates, props) {
super("application/vnd.apple.pkpass");
this[_a] = {};
this[_b] = {};
this[_c] = undefined;
if (buffers && typeof buffers === "object") {
const buffersEntries = Object.entries(buffers);
for (let i = buffersEntries.length, buffer; (buffer = buffersEntries[--i]);) {
const [fileName, contentBuffer] = buffer;
this.addBuffer(fileName, contentBuffer);
}
}
else {
console.warn(Messages.format(Messages.INIT.INVALID_BUFFERS, typeof buffers));
}
if (props) {
/** Overrides validation and pushing in props */
const overridesValidation = Schemas.validate(Schemas.OverridablePassProps, props);
Object.assign(this[propsSymbol], overridesValidation);
}
if (certificates) {
this.certificates = certificates;
}
}
/**

@@ -144,3 +142,3 @@ * Allows changing the certificates, if needed.

Schemas.assertValidity(Schemas.CertificatesSchema, certs, Messages.CERTIFICATES.INVALID);
this[exports.certificatesSymbol] = certs;
this[certificatesSymbol] = certs;
}

@@ -151,3 +149,3 @@ /**

get languages() {
return Object.keys(this[exports.localizationSymbol]);
return Object.keys(this[localizationSymbol]);
}

@@ -159,3 +157,3 @@ /**

get props() {
return Utils.cloneRecursive(this[exports.propsSymbol]);
return Utils.cloneRecursive(this[propsSymbol]);
}

@@ -166,5 +164,3 @@ /**

*
* It will (automatically) throw an exception
* if current type is not "boardingPass".
*
* @throws if current type is not "boardingPass".
* @param value

@@ -178,3 +174,3 @@ */

Schemas.assertValidity(Schemas.TransitType, value, Messages.TRANSIT_TYPE.INVALID);
this[exports.propsSymbol]["boardingPass"].transitType = value;
this[propsSymbol]["boardingPass"].transitType = value;
}

@@ -185,7 +181,6 @@ /**

*
* It will (automatically) throw an exception
* if current type is not "boardingPass".
* @throws (automatically) if current type is not "boardingPass".
*/
get transitType() {
return this[exports.propsSymbol]["boardingPass"].transitType;
return this[propsSymbol]["boardingPass"].transitType;
}

@@ -195,8 +190,8 @@ /**

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if it has not a valid type.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/
get primaryFields() {
return this[exports.propsSymbol][this.type].primaryFields;
return this[propsSymbol][this.type].primaryFields;
}

@@ -206,9 +201,8 @@ /**

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/
get secondaryFields() {
return this[exports.propsSymbol][this.type].secondaryFields;
return this[propsSymbol][this.type].secondaryFields;
}

@@ -218,7 +212,2 @@ /**

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
*
* For Typescript users: this signature allows

@@ -228,5 +217,9 @@ * in any case to add the 'row' field, but on

* passes.
*
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/
get auxiliaryFields() {
return this[exports.propsSymbol][this.type].auxiliaryFields;
return this[propsSymbol][this.type].auxiliaryFields;
}

@@ -236,9 +229,8 @@ /**

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/
get headerFields() {
return this[exports.propsSymbol][this.type].headerFields;
return this[propsSymbol][this.type].headerFields;
}

@@ -248,9 +240,8 @@ /**

*
* It will (automatically) throw an exception
* if no valid pass.json has been parsed yet
* or, anyway, if a valid type has not been
* set yet.
* @throws (automatically) if no valid pass.json
* has been parsed yet or, anyway, if current
* instance has not a valid type set yet.
*/
get backFields() {
return this[exports.propsSymbol][this.type].backFields;
return this[propsSymbol][this.type].backFields;
}

@@ -261,5 +252,5 @@ /**

* **Warning**: setting a type with this setter,
* will reset all the imported or manually
* setted fields (primaryFields, secondaryFields,
* headerFields, auxiliaryFields, backFields)
* will reset all the fields (primaryFields,
* secondaryFields, headerFields, auxiliaryFields, backFields),
* both imported or manually set.
*/

@@ -277,7 +268,7 @@ set type(nextType) {

*/
this[exports.propsSymbol][this.type] = undefined;
this[propsSymbol][this.type] = undefined;
}
const sharedKeysPool = new Set();
this[exports.passTypeSymbol] = type;
this[exports.propsSymbol][type] = {
this[passTypeSymbol] = type;
this[propsSymbol][type] = {
headerFields /******/: new FieldsArray_1.default(this, sharedKeysPool, Schemas.Field),

@@ -293,3 +284,3 @@ primaryFields /*****/: new FieldsArray_1.default(this, sharedKeysPool, Schemas.Field),

var _d;
return (_d = this[exports.passTypeSymbol]) !== null && _d !== void 0 ? _d : undefined;
return (_d = this[passTypeSymbol]) !== null && _d !== void 0 ? _d : undefined;
}

@@ -300,17 +291,18 @@ // **************************** //

/**
* Allows adding a new asset inside the pass / bundle;
* If an empty buffer is passed, it won't be added to
* the bundle.
* Allows adding a new asset inside the pass / bundle with
* the following exceptions:
*
* `manifest.json` and `signature` files will be ignored.
* - Empty buffers are ignored;
* - `manifest.json` and `signature` files will be ignored;
* - `pass.json` will be read validated and merged in the
* current instance, if it wasn't added previously.
* It's properties will overwrite the instance ones.
* You might loose data;
* - `pass.strings` files will be read, parsed and merged
* with the current translations. Comments will be ignored;
* - `personalization.json` will be read, validated and added.
* They will be stripped out when exporting the pass if
* it won't have NFC details or if any of the personalization
* files is missing;
*
* If a `pass.json` is passed to this method (and it has
* not been added previously), it will be read, validated
* and merged in the current instance. Its properties
* will overwrite the ones setted through methods.
*
* If a `pass.strings` file is passed, it will be read, parsed
* and merged with the translations added previously.
* Comments will be ignored.
*
* @param pathName

@@ -320,3 +312,3 @@ * @param buffer

addBuffer(pathName, buffer) {
if (!buffer) {
if (!(buffer === null || buffer === void 0 ? void 0 : buffer.length)) {
return;

@@ -336,3 +328,3 @@ }

try {
this[exports.importMetadataSymbol](validateJSONBuffer(buffer, Schemas.PassProps));
this[importMetadataSymbol](validateJSONBuffer(buffer, Schemas.PassProps));
}

@@ -391,10 +383,5 @@ catch (err) {

*
* **Warning**: if this file contains a type (boardingPass,
* coupon, and so on), it will replace the current one,
* causing, therefore, the destroy of the fields added
* previously.
*
* @param data
*/
[(_a = exports.propsSymbol, _b = exports.localizationSymbol, _c = exports.passTypeSymbol, exports.importMetadataSymbol)](data) {
[(_a = propsSymbol, _b = localizationSymbol, _c = passTypeSymbol, importMetadataSymbol)](data) {
const possibleTypes = [

@@ -409,8 +396,8 @@ "boardingPass",

const { boardingPass, coupon, storeCard, generic, eventTicket, ...otherPassData } = data;
if (Object.keys(this[exports.propsSymbol]).length) {
if (Object.keys(this[propsSymbol]).length) {
console.warn(Messages.PASS_SOURCE.JOIN);
}
Object.assign(this[exports.propsSymbol], otherPassData);
Object.assign(this[propsSymbol], otherPassData);
if (!type) {
if (!this[exports.passTypeSymbol]) {
if (!this[passTypeSymbol]) {
console.warn(Messages.PASS_SOURCE.UNKNOWN_TYPE);

@@ -436,3 +423,3 @@ }

*/
[exports.createManifestSymbol]() {
[createManifestSymbol]() {
const manifest = Object.entries(this[Bundle_1.filesSymbol]).reduce((acc, [fileName, buffer]) => ({

@@ -450,3 +437,3 @@ ...acc,

*/
[exports.closePassSymbol](__test_disable_manifest_signature_generation__ = false) {
[closePassSymbol]() {
if (!this.type) {

@@ -456,3 +443,3 @@ throw new TypeError(Messages.CLOSE.MISSING_TYPE);

const fileNames = Object.keys(this[Bundle_1.filesSymbol]);
const passJson = buffer_1.Buffer.from(JSON.stringify(this[exports.propsSymbol]));
const passJson = buffer_1.Buffer.from(JSON.stringify(this[propsSymbol]));
super.addBuffer("pass.json", passJson);

@@ -465,3 +452,3 @@ if (!fileNames.some((fileName) => RegExps.PASS_ICON.test(fileName))) {

// *********************************** //
const localizationEntries = Object.entries(this[exports.localizationSymbol]);
const localizationEntries = Object.entries(this[localizationSymbol]);
for (let i = localizationEntries.length - 1; i >= 0; i--) {

@@ -477,3 +464,3 @@ const [lang, translations] = localizationEntries[i];

// *********************** //
const meetsPersonalizationRequirements = Boolean(this[exports.propsSymbol]["nfc"] &&
const meetsPersonalizationRequirements = Boolean(this[propsSymbol]["nfc"] &&
this[Bundle_1.filesSymbol]["personalization.json"] &&

@@ -502,8 +489,5 @@ fileNames.find((file) => RegExps.PERSONALIZATION.LOGO.test(file)));

// ****************************** //
if (__test_disable_manifest_signature_generation__) {
return;
}
const manifestBuffer = this[exports.createManifestSymbol]();
const manifestBuffer = this[createManifestSymbol]();
super.addBuffer("manifest.json", manifestBuffer);
const signatureBuffer = Signature.create(manifestBuffer, this[exports.certificatesSymbol]);
const signatureBuffer = Signature.create(manifestBuffer, this[certificatesSymbol]);
super.addBuffer("signature", signatureBuffer);

@@ -523,3 +507,3 @@ }

if (!this.isFrozen) {
this[exports.closePassSymbol]();
this[closePassSymbol]();
}

@@ -537,3 +521,3 @@ return super.getAsBuffer();

if (!this.isFrozen) {
this[exports.closePassSymbol]();
this[closePassSymbol]();
}

@@ -557,3 +541,3 @@ return super.getAsStream();

if (!this.isFrozen) {
this[exports.closePassSymbol]();
this[closePassSymbol]();
}

@@ -572,3 +556,3 @@ return super.getAsRaw();

*
* Setting `translations` to `null`, fully deletes a language,
* Setting `translations` to `null` fully deletes a language,
* its translations and its files.

@@ -588,3 +572,3 @@ *

if (translations === null) {
delete this[exports.localizationSymbol][lang];
delete this[localizationSymbol][lang];
const allFilesKeys = Object.keys(this[Bundle_1.filesSymbol]);

@@ -604,5 +588,5 @@ const langFolderIdentifier = `${lang}.lproj`;

}
(_d = (_e = this[exports.localizationSymbol])[lang]) !== null && _d !== void 0 ? _d : (_e[lang] = {});
(_d = (_e = this[localizationSymbol])[lang]) !== null && _d !== void 0 ? _d : (_e[lang] = {});
if (typeof translations === "object" && !Array.isArray(translations)) {
Object.assign(this[exports.localizationSymbol][lang], translations);
Object.assign(this[localizationSymbol][lang], translations);
}

@@ -613,3 +597,6 @@ }

*
* Pass `null` to remove the expiration date.
*
* @param date
* @throws if pass is frozen due to previous export
* @returns

@@ -620,7 +607,7 @@ */

if (date === null) {
delete this[exports.propsSymbol]["expirationDate"];
delete this[propsSymbol]["expirationDate"];
return;
}
try {
this[exports.propsSymbol]["expirationDate"] = Utils.processDate(date);
this[propsSymbol]["expirationDate"] = Utils.processDate(date);
}

@@ -634,6 +621,6 @@ catch (err) {

if (beacons[0] === null) {
delete this[exports.propsSymbol]["beacons"];
delete this[propsSymbol]["beacons"];
return;
}
this[exports.propsSymbol]["beacons"] = Schemas.filterValid(Schemas.Beacon, beacons);
this[propsSymbol]["beacons"] = Schemas.filterValid(Schemas.Beacon, beacons);
}

@@ -643,6 +630,6 @@ setLocations(...locations) {

if (locations[0] === null) {
delete this[exports.propsSymbol]["locations"];
delete this[propsSymbol]["locations"];
return;
}
this[exports.propsSymbol]["locations"] = Schemas.filterValid(Schemas.Location, locations);
this[propsSymbol]["locations"] = Schemas.filterValid(Schemas.Location, locations);
}

@@ -653,3 +640,6 @@ /**

*
* @param date
* Pass `null` to remove relevant date from this pass.
*
* @param {Date | null} date
* @throws if pass is frozen due to previous export
*/

@@ -659,7 +649,7 @@ setRelevantDate(date) {

if (date === null) {
delete this[exports.propsSymbol]["relevantDate"];
delete this[propsSymbol]["relevantDate"];
return;
}
try {
this[exports.propsSymbol]["relevantDate"] = Utils.processDate(date);
this[propsSymbol]["relevantDate"] = Utils.processDate(date);
}

@@ -676,3 +666,3 @@ catch (err) {

if (barcodes[0] === null) {
delete this[exports.propsSymbol]["barcodes"];
delete this[propsSymbol]["barcodes"];
return;

@@ -700,3 +690,3 @@ }

}
this[exports.propsSymbol]["barcodes"] = finalBarcodes;
this[propsSymbol]["barcodes"] = finalBarcodes;
}

@@ -711,2 +701,3 @@ /**

* @param data
* @throws if pass is frozen due to previous export
* @returns

@@ -718,6 +709,6 @@ */

if (nfc === null) {
delete this[exports.propsSymbol]["nfc"];
delete this[propsSymbol]["nfc"];
return;
}
this[exports.propsSymbol]["nfc"] =
this[propsSymbol]["nfc"] =
(_d = Schemas.validate(Schemas.NFC, nfc)) !== null && _d !== void 0 ? _d : undefined;

@@ -724,0 +715,0 @@ }

@@ -5,3 +5,3 @@ import Joi from "joi";

*/
export declare type BarcodeFormat = "PKBarcodeFormatQR" | "PKBarcodeFormatPDF417" | "PKBarcodeFormatAztec" | "PKBarcodeFormatCode128";
export type BarcodeFormat = "PKBarcodeFormatQR" | "PKBarcodeFormatPDF417" | "PKBarcodeFormatAztec" | "PKBarcodeFormatCode128";
export interface Barcode {

@@ -8,0 +8,0 @@ altText?: string;

import Joi from "joi";
import { Semantics } from "./Semantics";
export declare type PKDataDetectorType = "PKDataDetectorTypePhoneNumber" | "PKDataDetectorTypeLink" | "PKDataDetectorTypeAddress" | "PKDataDetectorTypeCalendarEvent";
export declare type PKTextAlignmentType = "PKTextAlignmentLeft" | "PKTextAlignmentCenter" | "PKTextAlignmentRight" | "PKTextAlignmentNatural";
export declare type PKDateStyleType = "PKDateStyleNone" | "PKDateStyleShort" | "PKDateStyleMedium" | "PKDateStyleLong" | "PKDateStyleFull";
export declare type PKNumberStyleType = "PKNumberStyleDecimal" | "PKNumberStylePercent" | "PKNumberStyleScientific" | "PKNumberStyleSpellOut";
export type PKDataDetectorType = "PKDataDetectorTypePhoneNumber" | "PKDataDetectorTypeLink" | "PKDataDetectorTypeAddress" | "PKDataDetectorTypeCalendarEvent";
export type PKTextAlignmentType = "PKTextAlignmentLeft" | "PKTextAlignmentCenter" | "PKTextAlignmentRight" | "PKTextAlignmentNatural";
export type PKDateStyleType = "PKDateStyleNone" | "PKDateStyleShort" | "PKDateStyleMedium" | "PKDateStyleLong" | "PKDateStyleFull";
export type PKNumberStyleType = "PKNumberStyleDecimal" | "PKNumberStylePercent" | "PKNumberStyleScientific" | "PKNumberStyleSpellOut";
/**

@@ -8,0 +8,0 @@ * @see https://developer.apple.com/documentation/walletpasses/passfieldcontent

@@ -65,12 +65,12 @@ /// <reference types="node" />

*/
declare type PassMethodsProps = "nfc" | "beacons" | "barcodes" | "relevantDate" | "expirationDate" | "locations";
export declare type PassTypesProps = "boardingPass" | "eventTicket" | "coupon" | "generic" | "storeCard";
export declare type OverridablePassProps = Omit<PassProps, PassMethodsProps | PassTypesProps>;
export declare type PassPropsFromMethods = {
type PassMethodsProps = "nfc" | "beacons" | "barcodes" | "relevantDate" | "expirationDate" | "locations";
export type PassTypesProps = "boardingPass" | "eventTicket" | "coupon" | "generic" | "storeCard";
export type OverridablePassProps = Omit<PassProps, PassMethodsProps | PassTypesProps>;
export type PassPropsFromMethods = {
[K in PassMethodsProps]: PassProps[K];
};
export declare type PassKindsProps = {
export type PassKindsProps = {
[K in PassTypesProps]: PassProps[K];
};
export declare type PassColors = Pick<OverridablePassProps, "backgroundColor" | "foregroundColor" | "labelColor">;
export type PassColors = Pick<OverridablePassProps, "backgroundColor" | "foregroundColor" | "labelColor">;
export declare const PassPropsFromMethods: Joi.ObjectSchema<PassPropsFromMethods>;

@@ -77,0 +77,0 @@ export declare const PassKindsProps: Joi.ObjectSchema<PassKindsProps>;

import Joi from "joi";
import { Field, FieldWithRow } from "./Field";
export declare type TransitType = "PKTransitTypeAir" | "PKTransitTypeBoat" | "PKTransitTypeBus" | "PKTransitTypeGeneric" | "PKTransitTypeTrain";
export type TransitType = "PKTransitTypeAir" | "PKTransitTypeBoat" | "PKTransitTypeBus" | "PKTransitTypeGeneric" | "PKTransitTypeTrain";
export declare const TransitType: Joi.StringSchema;

@@ -5,0 +5,0 @@ export interface PassFields {

@@ -5,3 +5,3 @@ import Joi from "joi";

*/
declare type RequiredPersonalizationFields = "PKPassPersonalizationFieldName" | "PKPassPersonalizationFieldPostalCode" | "PKPassPersonalizationFieldEmailAddress" | "PKPassPersonalizationFieldPhoneNumber";
type RequiredPersonalizationFields = "PKPassPersonalizationFieldName" | "PKPassPersonalizationFieldPostalCode" | "PKPassPersonalizationFieldEmailAddress" | "PKPassPersonalizationFieldPhoneNumber";
export interface Personalize {

@@ -8,0 +8,0 @@ description: string;

import type Bundle from "./Bundle";
/**
* Acts as a wrapper for converting date to W3C string
* Converts a date to W3C / UTC string
* @param date

@@ -22,2 +22,4 @@ * @returns

export declare function cloneRecursive<T extends Object>(object: T): Record<keyof T, any>;
export declare function assertUnfrozen(instance: InstanceType<typeof Bundle>): void;
export declare function assertUnfrozen(instance: InstanceType<typeof Bundle>): asserts instance is Bundle & {
isFrozen: false;
};

@@ -7,3 +7,3 @@ "use strict";

/**
* Acts as a wrapper for converting date to W3C string
* Converts a date to W3C / UTC string
* @param date

@@ -13,51 +13,11 @@ * @returns

function processDate(date) {
if (!(date instanceof Date)) {
if (!(date instanceof Date) || Number.isNaN(Number(date))) {
throw "Invalid date";
}
const dateParse = dateToW3CString(date);
if (!dateParse) {
throw "Invalid date";
}
return dateParse;
}
exports.processDate = processDate;
/**
* Converts a date to W3C Standard format
*
* @function dateToW3Cstring
* @params date - The date to be parsed
* @returns - The parsed string if the parameter is valid,
* undefined otherwise
*/
function dateToW3CString(date) {
// if it is NaN, it is "Invalid Date"
if (isNaN(Number(date))) {
return undefined;
}
const paddedMonth = padMeTwo(date.getMonth() + 1);
const paddedDay = padMeTwo(date.getDate());
const paddedHour = padMeTwo(date.getHours());
const paddedMinutes = padMeTwo(date.getMinutes());
const paddedSeconds = padMeTwo(date.getSeconds());
/**
* Date.prototype.getTimezoneOffset returns the timezone UTC offset in
* minutes of the local machine.
*
* That value should then be used to calculate the effective timezone as
* string, but still that would be related to the machine and not to the
* specified date.
*
* For this reason we are completing date with "Z" TimeZoneDesignator (TZD)
* to say it to use local timezone.
*
* In the future we might think to integrate another parameter to represent
* a custom timezone.
*
* @see https://www.w3.org/TR/NOTE-datetime
*/
return `${date.getFullYear()}-${paddedMonth}-${paddedDay}T${paddedHour}:${paddedMinutes}:${paddedSeconds}Z`;
return date.toISOString();
}
function padMeTwo(original) {
return String(original).padStart(2, "0");
}
exports.processDate = processDate;
/**

@@ -64,0 +24,0 @@ * Removes hidden files from a list (those starting with dot)

{
"name": "passkit-generator",
"version": "3.1.9",
"version": "3.1.10",
"description": "The easiest way to generate custom Apple Wallet passes in Node.js",

@@ -8,7 +8,6 @@ "main": "lib/index.js",

"build": "npm run build:src",
"build:all": "npm run build:src && npm run build:examples && npm run build:spec",
"build:all": "npm run build:src && npm run build:examples",
"build:src": "rimraf lib && npx tsc -p tsconfig.dist.json",
"build:spec": "rimraf \"./spec/*.!(ts)\" && npx tsc -p tsconfig.spec.json",
"prepublishOnly": "npm run build",
"test": "npm run build:spec && npx jasmine"
"prepublishOnly": "npm run build && npm run test",
"test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest -c jest.config.cjs --silent"
},

@@ -36,9 +35,9 @@ "author": "Alexander Patrick Cerutti",

"@types/do-not-zip": "^1.0.0",
"@types/jasmine": "^3.10.4",
"@types/node": "^16.11.26",
"@types/node-forge": "^1.0.1",
"jasmine": "^4.0.2",
"jest": "^29.5.0",
"jest-environment-node": "^29.5.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"typescript": "^4.6.3"
"typescript": "^5.0.4"
},

@@ -45,0 +44,0 @@ "files": [

@@ -125,11 +125,19 @@ <div align="center">

#### Folder Model
Importing:
```typescript
/**
* Use `const { PKPass } = require("passkit-generator");`
* for usage in CommonJS (Node.js)
*/
/** CommonJS **/
const { PKPass } = require("passkit-generator");
/** Typescript **/
import { PKPass } from "passkit-generator";
/** ESM **/
import passkit from "passkit-generator";
const PKPass = passkit.PKPass;
```
### Folder Model
```typescript
try {

@@ -173,11 +181,5 @@ /** Each, but last, can be either a string or a Buffer. See API Documentation for more */

#### Buffer Model
### Buffer Model
```typescript
/**
* Use `const { PKPass } = require("passkit-generator");`
* for usage in CommonJS (Node.js)
*/
import { PKPass } from "passkit-generator";
try {

@@ -184,0 +186,0 @@ /** Each, but last, can be either a string or a Buffer. See API Documentation for more */

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc