New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

passkit-generator

Package Overview
Dependencies
Maintainers
1
Versions
55
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 1.5.0 to 1.5.1

4

index.d.ts

@@ -63,7 +63,7 @@ import { Stream } from "stream";

* @param resource - url
* @param name - name to be used inside the archive
* @param name - name (or path) to be used inside the archive
* @returns this;
*/
load(resource, name): this;
load(resource: string, name: string): this;
}

@@ -70,0 +70,0 @@

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

let errors = {
const errors = {
PASSFILE_VALIDATION_FAILED: "Validation of pass type failed. Pass file is not a valid buffer or (more probabily) does not respect the schema. Refer to https://apple.co/2Nvshvn to build a correct pass.",

@@ -8,9 +8,27 @@ REQUIR_VALID_FAILED: "The options passed to Pass constructor does not meet the requirements. Refer to the documentation to compile them correctly.",

INVALID_CERTS: "Invalid certificate(s) loaded: %s. Please provide valid WWDR certificates and developer signer certificate and key (with passphrase). Refer to docs to obtain them.",
INVALID_CERT_PATH: "Invalid certificate loaded. %s does not exist."
INVALID_CERT_PATH: "Invalid certificate loaded. %s does not exist.",
TRSTYPE_REQUIRED: "Cannot proceed with pass creation. transitType field is required for boardingPasses.",
};
function format(errorName, ...values) {
const debugMessages = {
TRSTYPE_NOT_VALID: "Transit type changing rejected as not compliant with Apple Specifications. Transit type would become \"%s\" but should be in [PKTransitTypeAir, PKTransitTypeBoat, PKTransitTypeBus, PKTransitTypeGeneric, PKTransitTypeTrain]",
BRC_NOT_SUPPORTED: "Format not found among barcodes. Cannot set backward compatibility.",
BRC_FORMATTYPE_UNMATCH: "Format must be a string or null. Cannot set backward compatibility.",
BRC_AUTC_MISSING_DATA: "Unable to autogenerate barcodes. Data is not an object or has not message field.",
DATE_FORMAT_UNMATCH: "%s was not set due to incorrect date format.",
LOAD_TYPES_UNMATCH: "Resource and name are not valid strings. No action will be taken for the specified medias.",
LOAD_MIME: "Picture MIME-type: %s",
LOAD_NORES: "Was not able to fetch resource %s. Error: %s"
};
/**
* Creates a message with replaced values
* @param {string} messageName
* @param {any[]} values
*/
function format(messageName, ...values) {
// reversing because it is better popping than shifting.
let replaceValues = values.reverse();
return resolveErrorName(errorName).replace(/%s/, () => {
return resolveMessageName(messageName).replace(/%s/g, () => {
let next = replaceValues.pop();

@@ -21,10 +39,15 @@ return next !== undefined ? next : "<passedValueIsUndefined>";

function resolveErrorName(name) {
if (!errors[name]) {
return `<ErrorName ${name} is not linked to any error messages>`;
/**
* Looks among errors and debugMessages for the specified message name
* @param {string} name
*/
function resolveMessageName(name) {
if (!errors[name] && !debugMessages[name]) {
return `<ErrorName "${name}" is not linked to any error messages>`;
}
return errors[name];
return errors[name] || debugMessages[name];
}
module.exports = format;

@@ -16,3 +16,3 @@ const fs = require("fs");

const schema = require("./schema");
const formatError = require("./messages");
const formatMessage = require("./messages");
const FieldsContainer = require("./fields");

@@ -62,5 +62,3 @@

if (err.code && err.code === "ENOENT") {
let eMessage = formatError("MODEL_NOT_FOUND", this.model);
throw new Error(eMessage);
throw new Error(formatMessage("MODEL_NOT_FOUND", this.model));
}

@@ -75,25 +73,23 @@

let buffersPromise = [
...this._remoteResources.map((r) =>
got(r[0], { encoding: null })
.then(response => {
loadDebug(`Picture MIME-type: ${response.headers["content-type"]}`);
let buffersPromise = this._remoteResources.map((r) => {
return got(r[0], { encoding: null })
.then(response => {
loadDebug(formatMessage("LOAD_MIME", response.headers["content-type"]));
if (!Buffer.isBuffer(response.body)) {
throw "NOTABUFFER";
}
if (!Buffer.isBuffer(response.body)) {
throw "LOADED_RESOURCE_NOT_A_BUFFER";
}
if (!response.headers["content-type"].includes("image/")) {
throw "NOTAPICTURE";
}
if (!response.headers["content-type"].includes("image/")) {
throw "LOADED_RESOURCE_NOT_A_PICTURE";
}
return response.body;
})
.catch(e => {
loadDebug(`Was not able to fetch resource ${r[1]}. Error: ${e}`);
// here we are adding undefined values, that will be removed later.
return undefined;
})
)
];
return response.body;
})
.catch(e => {
loadDebug(formatMessage("LOAD_NORES", r[1], e));
// here we are adding undefined values, that will be removed later.
return undefined;
});
});

@@ -112,3 +108,3 @@ // forwarding model files list, remote files list and remote buffers.

if (!noDynList.length || ![...noDynList, ...remoteFilesList].some(f => f.toLowerCase().includes("icon"))) {
let eMessage = formatError("MODEL_UNINITIALIZED", path.parse(this.model).name);
let eMessage = formatMessage("MODEL_UNINITIALIZED", path.parse(this.model).name);
throw new Error(eMessage);

@@ -134,3 +130,3 @@ }

if (!this._validateType(passStructBuffer)) {
let eMessage = formatError("PASSFILE_VALIDATION_FAILED");
let eMessage = formatMessage("PASSFILE_VALIDATION_FAILED");
throw new Error(eMessage);

@@ -263,3 +259,3 @@ }

if (!dateParse) {
genericDebug("Expiration Date was not set due to invalid format.");
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Expiration date"));
} else {

@@ -333,3 +329,3 @@ this._props.expirationDate = dateParse;

if (!dateParse) {
genericDebug("Relevant Date was not set due to incorrect date format.");
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
} else {

@@ -416,3 +412,3 @@ this._props[type] = dateParse;

if (!data || !(data instanceof Object) || !data.message) {
barcodeDebug("Unable to autogenerate barcodes. Data is not an object or has not message field.");
barcodeDebug(formatMessage("BRC_AUTC_MISSING_DATA"));
return [];

@@ -474,3 +470,3 @@ }

if (typeof format !== "string") {
barcodeDebug("format must be a string or null. Cannot set backward compatibility.");
barcodeDebug(formatMessage("BRC_FORMAT_UNMATCH"));
return this;

@@ -483,3 +479,3 @@ }

if (index === -1) {
barcodeDebug("format not found among barcodes. Cannot set backward compatibility.");
barcodeDebug(formatMessage("BRC_NOT_SUPPORTED"));
return this;

@@ -523,3 +519,3 @@ }

if (typeof resource !== "string" && typeof name !== "string") {
loadDebug("resource and name are not valid strings. No action will be taken.");
loadDebug(formatMessage("LOAD_TYPES_UNMATCH"));
return;

@@ -662,4 +658,4 @@ }

if (!this.transitType && this.type === "boardingPass") {
throw new Error("Cannot proceed with pass creation. transitType field is required for boardingPasses.");
if (this.type === "boardingPass" && !this.transitType) {
throw new Error(formatMessage("TRSTYPE_REQUIRED"));
}

@@ -681,11 +677,8 @@

_parseSettings(options) {
let eMessage = null;
if (!schema.isValid(options, "instance")) {
eMessage = formatError("REQUIR_VALID_FAILED");
throw new Error(eMessage);
throw new Error(formatMessage("REQUIR_VALID_FAILED"));
}
if (!options.model || typeof options.model !== "string") {
eMessage = formatError("MODEL_NOT_STRING");
throw new Error(eMessage);
throw new Error(formatMessage("MODEL_NOT_STRING"));
}

@@ -707,2 +700,3 @@

} else {
genericDebug(formatMessage("TRSTYPE_NOT_VALID", v));
this._transitType = this._transitType || "";

@@ -744,2 +738,5 @@ }

.then(contents => {
// Mapping each file content to a PEM structure, returned in form of one-key-object
// which is conjoint later with the other pems
return Object.assign(

@@ -751,3 +748,3 @@ ...contents.map((file, index) => {

if (!pem) {
throw new Error(formatError("INVALID_CERTS", certName));
throw new Error(formatMessage("INVALID_CERTS", certName));
}

@@ -764,3 +761,3 @@

throw new Error(formatError("INVALID_CERT_PATH", path.parse(err.path).base));
throw new Error(formatMessage("INVALID_CERT_PATH", path.parse(err.path).base));
});

@@ -767,0 +764,0 @@ }

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