mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Updated existing examples
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* .barcode() and .barcodes() methods example
|
* .barcodes() methods example
|
||||||
* Here we set the barcode. To see all the results, you can
|
* Here we set the barcode. To see all the results, you can
|
||||||
* both unzip .pkpass file or check the properties before
|
* both unzip .pkpass file or check the properties before
|
||||||
* generating the whole bundle
|
* generating the whole bundle
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import app from "./webserver";
|
import app from "./webserver";
|
||||||
import { createPass } from "passkit-generator";
|
import { PKPass } from "passkit-generator";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
app.all(async function manageRequest(request, response) {
|
app.all(async function manageRequest(request, response) {
|
||||||
@@ -19,7 +19,7 @@ app.all(async function manageRequest(request, response) {
|
|||||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pass = await createPass({
|
const pass = await PKPass.from({
|
||||||
model: path.resolve(
|
model: path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
`../models/${request.params.modelName}`,
|
`../models/${request.params.modelName}`,
|
||||||
@@ -30,27 +30,33 @@ app.all(async function manageRequest(request, response) {
|
|||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerCert.pem",
|
"../../certificates/signerCert.pem",
|
||||||
),
|
),
|
||||||
signerKey: {
|
signerKey: path.resolve(
|
||||||
keyFile: path.resolve(
|
|
||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerKey.pem",
|
"../../certificates/signerKey.pem",
|
||||||
),
|
),
|
||||||
passphrase: "123456",
|
signerKeyPassphrase: "123456",
|
||||||
},
|
},
|
||||||
|
props: Object.assign(
|
||||||
|
{
|
||||||
|
voided: request.query.fn === "void",
|
||||||
},
|
},
|
||||||
overrides: request.body || request.params || request.query,
|
{ ...(request.body || request.params || request.query || {}) },
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (request.query.alt === true) {
|
if (request.query.alt === "true") {
|
||||||
// After this, pass.props["barcodes"] will have support for all the formats
|
// After this, pass.props["barcodes"] will have support for all the formats
|
||||||
// while pass.props["barcode"] will be the first of barcodes.
|
pass.setBarcodes("Thank you for using this package <3");
|
||||||
|
|
||||||
pass.barcodes("Thank you for using this package <3");
|
console.log(
|
||||||
|
"Barcodes support is autocompleted:",
|
||||||
|
pass.props["barcodes"],
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// After this, pass.props["barcodes"] will have support for just two of three
|
// After this, pass.props["barcodes"] will have support for just two of three
|
||||||
// of the passed format (the valid ones);
|
// of the passed format (the valid ones);
|
||||||
|
|
||||||
pass.barcodes(
|
pass.setBarcodes(
|
||||||
{
|
{
|
||||||
message: "Thank you for using this package <3",
|
message: "Thank you for using this package <3",
|
||||||
format: "PKBarcodeFormatCode128",
|
format: "PKBarcodeFormatCode128",
|
||||||
@@ -61,26 +67,16 @@ app.all(async function manageRequest(request, response) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "Thank you for using this package <3",
|
message: "Thank you for using this package <3",
|
||||||
|
// @ts-expect-error
|
||||||
format: "PKBarcodeFormatMock44617",
|
format: "PKBarcodeFormatMock44617",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can change the format chosen for barcode prop support by calling .barcode()
|
const stream = pass.getAsStream();
|
||||||
// or cancel the support by calling empty .barcode
|
|
||||||
// like pass.barcode().
|
|
||||||
|
|
||||||
pass.barcode("PKBarcodeFormatPDF417");
|
|
||||||
|
|
||||||
console.log("Barcode property is now:", pass.props["barcode"]);
|
|
||||||
console.log(
|
|
||||||
"Barcodes support is autocompleted:",
|
|
||||||
pass.props["barcodes"],
|
|
||||||
);
|
|
||||||
|
|
||||||
const stream = pass.generate();
|
|
||||||
response.set({
|
response.set({
|
||||||
"Content-type": "application/vnd.apple.pkpass",
|
"Content-type": pass.mimeType,
|
||||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* .void() and .expiration() methods example
|
* .expiration() method and voided prop example
|
||||||
* To check if a ticket is void, look at the barcode;
|
* To check if a ticket is void, look at the barcode;
|
||||||
* If it is grayed, the ticket is voided. May not be showed on macOS.
|
* If it is grayed, the ticket is voided. May not be showed on macOS.
|
||||||
*
|
*
|
||||||
* To check if a ticket has an expiration date, you'll
|
* To check if a ticket has an expiration date, you'll
|
||||||
* have to wait two minutes.
|
* have to wait two minutes.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import app from "./webserver";
|
import app from "./webserver";
|
||||||
import { createPass } from "passkit-generator";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { PKPass } from "passkit-generator";
|
||||||
|
|
||||||
app.all(async function manageRequest(request, response) {
|
app.all(async function manageRequest(request, response) {
|
||||||
if (!request.query.fn) {
|
if (!request.query.fn) {
|
||||||
@@ -20,13 +19,13 @@ app.all(async function manageRequest(request, response) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let passName =
|
const passName =
|
||||||
request.params.modelName +
|
request.params.modelName +
|
||||||
"_" +
|
"_" +
|
||||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let pass = await createPass({
|
const pass = await PKPass.from({
|
||||||
model: path.resolve(
|
model: path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
`../models/${request.params.modelName}`,
|
`../models/${request.params.modelName}`,
|
||||||
@@ -37,31 +36,33 @@ app.all(async function manageRequest(request, response) {
|
|||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerCert.pem",
|
"../../certificates/signerCert.pem",
|
||||||
),
|
),
|
||||||
signerKey: {
|
signerKey: path.resolve(
|
||||||
keyFile: path.resolve(
|
|
||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerKey.pem",
|
"../../certificates/signerKey.pem",
|
||||||
),
|
),
|
||||||
passphrase: "123456",
|
signerKeyPassphrase: "123456",
|
||||||
},
|
},
|
||||||
|
props: Object.assign(
|
||||||
|
{
|
||||||
|
voided: request.query.fn === "void",
|
||||||
},
|
},
|
||||||
overrides: request.body || request.params || request.query,
|
{ ...(request.body || request.params || request.query || {}) },
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (request.query.fn === "void") {
|
if (request.query.fn === "expiration") {
|
||||||
pass.void();
|
|
||||||
} else if (request.query.fn === "expiration") {
|
|
||||||
// 2 minutes later...
|
// 2 minutes later...
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
d.setMinutes(d.getMinutes() + 2);
|
d.setMinutes(d.getMinutes() + 2);
|
||||||
|
|
||||||
// setting the expiration
|
// setting the expiration
|
||||||
pass.expiration(d);
|
pass.setExpirationDate(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = pass.generate();
|
const stream = pass.getAsStream();
|
||||||
|
|
||||||
response.set({
|
response.set({
|
||||||
"Content-type": "application/vnd.apple.pkpass",
|
"Content-type": pass.mimeType,
|
||||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,16 +10,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import app from "./webserver";
|
import app from "./webserver";
|
||||||
import { createPass } from "passkit-generator";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { PKPass } from "passkit-generator";
|
||||||
|
|
||||||
app.all(async function manageRequest(request, response) {
|
app.all(async function manageRequest(request, response) {
|
||||||
let passName =
|
const passName =
|
||||||
"exampleBooking" +
|
"exampleBooking" +
|
||||||
"_" +
|
"_" +
|
||||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let pass = await createPass({
|
const pass = await PKPass.from({
|
||||||
model: path.resolve(__dirname, "../models/exampleBooking"),
|
model: path.resolve(__dirname, "../models/exampleBooking"),
|
||||||
certificates: {
|
certificates: {
|
||||||
wwdr: path.resolve(__dirname, "../../certificates/WWDR.pem"),
|
wwdr: path.resolve(__dirname, "../../certificates/WWDR.pem"),
|
||||||
@@ -27,15 +28,13 @@ app.all(async function manageRequest(request, response) {
|
|||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerCert.pem",
|
"../../certificates/signerCert.pem",
|
||||||
),
|
),
|
||||||
signerKey: {
|
signerKey: path.resolve(
|
||||||
keyFile: path.resolve(
|
|
||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerKey.pem",
|
"../../certificates/signerKey.pem",
|
||||||
),
|
),
|
||||||
passphrase: "123456",
|
signerKeyPassphrase: "123456",
|
||||||
},
|
},
|
||||||
},
|
props: request.body || request.params || request.query,
|
||||||
overrides: request.body || request.params || request.query,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pass.transitType = "PKTransitTypeAir";
|
pass.transitType = "PKTransitTypeAir";
|
||||||
@@ -134,8 +133,7 @@ app.all(async function manageRequest(request, response) {
|
|||||||
{
|
{
|
||||||
key: "checkIn",
|
key: "checkIn",
|
||||||
label: "",
|
label: "",
|
||||||
value:
|
value: "Le uscite d'imbarco chiudono 30 minuti prima della partenza, quindi sii puntuale. In questo aeroporto puoi utilizzare la corsia Fast Track ai varchi di sicurezza.",
|
||||||
"Le uscite d'imbarco chiudono 30 minuti prima della partenza, quindi sii puntuale. In questo aeroporto puoi utilizzare la corsia Fast Track ai varchi di sicurezza.",
|
|
||||||
textAlignment: "PKTextAlignmentLeft",
|
textAlignment: "PKTextAlignmentLeft",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -147,8 +145,7 @@ app.all(async function manageRequest(request, response) {
|
|||||||
{
|
{
|
||||||
key: "Require special assistance",
|
key: "Require special assistance",
|
||||||
label: "Assistenza speciale",
|
label: "Assistenza speciale",
|
||||||
value:
|
value: "Se hai richiesto assistenza speciale, presentati a un membro del personale nell'area di Consegna bagagli almeno 90 minuti prima del volo.",
|
||||||
"Se hai richiesto assistenza speciale, presentati a un membro del personale nell'area di Consegna bagagli almeno 90 minuti prima del volo.",
|
|
||||||
textAlignment: "PKTextAlignmentLeft",
|
textAlignment: "PKTextAlignmentLeft",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -160,22 +157,19 @@ app.all(async function manageRequest(request, response) {
|
|||||||
{
|
{
|
||||||
key: "photoId",
|
key: "photoId",
|
||||||
label: "Un documento d’identità corredato di fotografia",
|
label: "Un documento d’identità corredato di fotografia",
|
||||||
value:
|
value: "è obbligatorio su TUTTI i voli. Per un viaggio internazionale è necessario un passaporto valido o, dove consentita, una carta d’identità.",
|
||||||
"è obbligatorio su TUTTI i voli. Per un viaggio internazionale è necessario un passaporto valido o, dove consentita, una carta d’identità.",
|
|
||||||
textAlignment: "PKTextAlignmentLeft",
|
textAlignment: "PKTextAlignmentLeft",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "yourSeat",
|
key: "yourSeat",
|
||||||
label: "Il tuo posto:",
|
label: "Il tuo posto:",
|
||||||
value:
|
value: "verifica il tuo numero di posto nella parte superiore. Durante l’imbarco utilizza le scale anteriori e posteriori: per le file 1-10 imbarcati dalla parte anteriore; per le file 11-31 imbarcati dalla parte posteriore. Colloca le borse di dimensioni ridotte sotto il sedile davanti a te.",
|
||||||
"verifica il tuo numero di posto nella parte superiore. Durante l’imbarco utilizza le scale anteriori e posteriori: per le file 1-10 imbarcati dalla parte anteriore; per le file 11-31 imbarcati dalla parte posteriore. Colloca le borse di dimensioni ridotte sotto il sedile davanti a te.",
|
|
||||||
textAlignment: "PKTextAlignmentLeft",
|
textAlignment: "PKTextAlignmentLeft",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "Pack safely",
|
key: "Pack safely",
|
||||||
label: "Bagaglio sicuro",
|
label: "Bagaglio sicuro",
|
||||||
value:
|
value: "Fai clic http://easyjet.com/it/articoli-pericolosi per maggiori informazioni sulle merci pericolose oppure visita il sito CAA http://www.caa.co.uk/default.aspx?catid=2200",
|
||||||
"Fai clic http://easyjet.com/it/articoli-pericolosi per maggiori informazioni sulle merci pericolose oppure visita il sito CAA http://www.caa.co.uk/default.aspx?catid=2200",
|
|
||||||
textAlignment: "PKTextAlignmentLeft",
|
textAlignment: "PKTextAlignmentLeft",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -186,9 +180,10 @@ app.all(async function manageRequest(request, response) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const stream = pass.generate();
|
const stream = pass.getAsStream();
|
||||||
|
|
||||||
response.set({
|
response.set({
|
||||||
"Content-type": "application/vnd.apple.pkpass",
|
"Content-type": pass.mimeType,
|
||||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import app from "./webserver";
|
import app from "./webserver";
|
||||||
import { createPass } from "passkit-generator";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { PKPass } from "passkit-generator";
|
||||||
|
/** Symbols are exported just for tests and examples. Replicate only if really needed. */
|
||||||
|
import { localizationSymbol } from "passkit-generator/lib/PKPass";
|
||||||
|
|
||||||
app.all(async function manageRequest(request, response) {
|
app.all(async function manageRequest(request, response) {
|
||||||
const passName =
|
const passName =
|
||||||
@@ -15,7 +17,7 @@ app.all(async function manageRequest(request, response) {
|
|||||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pass = await createPass({
|
const pass = await PKPass.from({
|
||||||
model: path.resolve(
|
model: path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
`../models/${request.params.modelName}`,
|
`../models/${request.params.modelName}`,
|
||||||
@@ -26,36 +28,40 @@ app.all(async function manageRequest(request, response) {
|
|||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerCert.pem",
|
"../../certificates/signerCert.pem",
|
||||||
),
|
),
|
||||||
signerKey: {
|
signerKey: path.resolve(
|
||||||
keyFile: path.resolve(
|
|
||||||
__dirname,
|
__dirname,
|
||||||
"../../certificates/signerKey.pem",
|
"../../certificates/signerKey.pem",
|
||||||
),
|
),
|
||||||
passphrase: "123456",
|
signerKeyPassphrase: "123456",
|
||||||
},
|
},
|
||||||
},
|
props: request.body || request.params || request.query,
|
||||||
overrides: request.body || request.params || request.query,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// For each language you include, an .lproj folder in pass bundle
|
/**
|
||||||
// is created or included. You may not want to add translations but
|
* For each language you include, an .lproj folder in pass bundle
|
||||||
// only images for a specific language. So you create manually
|
* is created or included. You may not want to add translations
|
||||||
// an .lproj folder in your pass model then add the language here below.
|
* but only images for a specific language. So you create manually
|
||||||
// If no translations were added, the folder
|
* an .lproj folder in your pass model then add the language here
|
||||||
// is included or created but without pass.strings file
|
* below. If no translations does not get added, the folder is
|
||||||
|
* included or created but without pass.strings file.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* In this example, English does not have an .lproj folder yet and
|
||||||
|
* doesn't have nor receive translations.
|
||||||
|
*
|
||||||
|
* Text placeholders may not be showed for the english language
|
||||||
|
* (e.g. "Event" and "Location" as literal) and another language may be used instead
|
||||||
|
*/
|
||||||
|
|
||||||
// English, does not has an .lproj folder and no translation
|
|
||||||
// Text placeholders may not be showed for the english language
|
|
||||||
// (e.g. "Event" and "Location" as literal) and another language may be used instead
|
|
||||||
pass.localize("en");
|
pass.localize("en");
|
||||||
|
|
||||||
// Italian, already has an .lproj which gets included
|
// Italian, already has an .lproj which gets included...
|
||||||
pass.localize("it", {
|
pass.localize("it", {
|
||||||
EVENT: "Evento",
|
EVENT: "Evento",
|
||||||
LOCATION: "Dove",
|
LOCATION: "Dove",
|
||||||
});
|
});
|
||||||
|
|
||||||
// German, doesn't, so is created
|
// ...while German doesn't, so it gets created
|
||||||
pass.localize("de", {
|
pass.localize("de", {
|
||||||
EVENT: "Ereignis",
|
EVENT: "Ereignis",
|
||||||
LOCATION: "Ort",
|
LOCATION: "Ort",
|
||||||
@@ -64,15 +70,15 @@ app.all(async function manageRequest(request, response) {
|
|||||||
// This language does not exist but is still added as .lproj folder
|
// This language does not exist but is still added as .lproj folder
|
||||||
pass.localize("zu", {});
|
pass.localize("zu", {});
|
||||||
|
|
||||||
// @ts-ignore - ignoring for logging purposes. Do not replicate
|
|
||||||
console.log(
|
console.log(
|
||||||
"Added languages",
|
"Added languages",
|
||||||
Object.keys(pass["l10nTranslations"]).join(", "),
|
Object.keys(pass[localizationSymbol]).join(", "),
|
||||||
);
|
);
|
||||||
|
|
||||||
const stream = pass.generate();
|
const stream = pass.getAsStream();
|
||||||
|
|
||||||
response.set({
|
response.set({
|
||||||
"Content-type": "application/vnd.apple.pkpass",
|
"Content-type": pass.mimeType,
|
||||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user