mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +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
|
||||
* both unzip .pkpass file or check the properties before
|
||||
* generating the whole bundle
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
import app from "./webserver";
|
||||
import { createPass } from "passkit-generator";
|
||||
import { PKPass } from "passkit-generator";
|
||||
import path from "path";
|
||||
|
||||
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, "");
|
||||
|
||||
try {
|
||||
const pass = await createPass({
|
||||
const pass = await PKPass.from({
|
||||
model: path.resolve(
|
||||
__dirname,
|
||||
`../models/${request.params.modelName}`,
|
||||
@@ -30,27 +30,33 @@ app.all(async function manageRequest(request, response) {
|
||||
__dirname,
|
||||
"../../certificates/signerCert.pem",
|
||||
),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
passphrase: "123456",
|
||||
},
|
||||
signerKey: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
signerKeyPassphrase: "123456",
|
||||
},
|
||||
overrides: request.body || request.params || request.query,
|
||||
props: Object.assign(
|
||||
{
|
||||
voided: request.query.fn === "void",
|
||||
},
|
||||
{ ...(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
|
||||
// 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 {
|
||||
// After this, pass.props["barcodes"] will have support for just two of three
|
||||
// of the passed format (the valid ones);
|
||||
|
||||
pass.barcodes(
|
||||
pass.setBarcodes(
|
||||
{
|
||||
message: "Thank you for using this package <3",
|
||||
format: "PKBarcodeFormatCode128",
|
||||
@@ -61,26 +67,16 @@ app.all(async function manageRequest(request, response) {
|
||||
},
|
||||
{
|
||||
message: "Thank you for using this package <3",
|
||||
// @ts-expect-error
|
||||
format: "PKBarcodeFormatMock44617",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// You can change the format chosen for barcode prop support by calling .barcode()
|
||||
// or cancel the support by calling empty .barcode
|
||||
// like pass.barcode().
|
||||
const stream = pass.getAsStream();
|
||||
|
||||
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({
|
||||
"Content-type": "application/vnd.apple.pkpass",
|
||||
"Content-type": pass.mimeType,
|
||||
"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;
|
||||
* 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
|
||||
* have to wait two minutes.
|
||||
*
|
||||
*/
|
||||
|
||||
import app from "./webserver";
|
||||
import { createPass } from "passkit-generator";
|
||||
import path from "path";
|
||||
import { PKPass } from "passkit-generator";
|
||||
|
||||
app.all(async function manageRequest(request, response) {
|
||||
if (!request.query.fn) {
|
||||
@@ -20,13 +19,13 @@ app.all(async function manageRequest(request, response) {
|
||||
return;
|
||||
}
|
||||
|
||||
let passName =
|
||||
const passName =
|
||||
request.params.modelName +
|
||||
"_" +
|
||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||
|
||||
try {
|
||||
let pass = await createPass({
|
||||
const pass = await PKPass.from({
|
||||
model: path.resolve(
|
||||
__dirname,
|
||||
`../models/${request.params.modelName}`,
|
||||
@@ -37,31 +36,33 @@ app.all(async function manageRequest(request, response) {
|
||||
__dirname,
|
||||
"../../certificates/signerCert.pem",
|
||||
),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
passphrase: "123456",
|
||||
},
|
||||
signerKey: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
signerKeyPassphrase: "123456",
|
||||
},
|
||||
overrides: request.body || request.params || request.query,
|
||||
props: Object.assign(
|
||||
{
|
||||
voided: request.query.fn === "void",
|
||||
},
|
||||
{ ...(request.body || request.params || request.query || {}) },
|
||||
),
|
||||
});
|
||||
|
||||
if (request.query.fn === "void") {
|
||||
pass.void();
|
||||
} else if (request.query.fn === "expiration") {
|
||||
if (request.query.fn === "expiration") {
|
||||
// 2 minutes later...
|
||||
const d = new Date();
|
||||
d.setMinutes(d.getMinutes() + 2);
|
||||
|
||||
// setting the expiration
|
||||
pass.expiration(d);
|
||||
pass.setExpirationDate(d);
|
||||
}
|
||||
|
||||
const stream = pass.generate();
|
||||
const stream = pass.getAsStream();
|
||||
|
||||
response.set({
|
||||
"Content-type": "application/vnd.apple.pkpass",
|
||||
"Content-type": pass.mimeType,
|
||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||
});
|
||||
|
||||
|
||||
@@ -10,16 +10,17 @@
|
||||
*/
|
||||
|
||||
import app from "./webserver";
|
||||
import { createPass } from "passkit-generator";
|
||||
import path from "path";
|
||||
import { PKPass } from "passkit-generator";
|
||||
|
||||
app.all(async function manageRequest(request, response) {
|
||||
let passName =
|
||||
const passName =
|
||||
"exampleBooking" +
|
||||
"_" +
|
||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||
|
||||
try {
|
||||
let pass = await createPass({
|
||||
const pass = await PKPass.from({
|
||||
model: path.resolve(__dirname, "../models/exampleBooking"),
|
||||
certificates: {
|
||||
wwdr: path.resolve(__dirname, "../../certificates/WWDR.pem"),
|
||||
@@ -27,15 +28,13 @@ app.all(async function manageRequest(request, response) {
|
||||
__dirname,
|
||||
"../../certificates/signerCert.pem",
|
||||
),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
passphrase: "123456",
|
||||
},
|
||||
signerKey: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
signerKeyPassphrase: "123456",
|
||||
},
|
||||
overrides: request.body || request.params || request.query,
|
||||
props: request.body || request.params || request.query,
|
||||
});
|
||||
|
||||
pass.transitType = "PKTransitTypeAir";
|
||||
@@ -134,8 +133,7 @@ app.all(async function manageRequest(request, response) {
|
||||
{
|
||||
key: "checkIn",
|
||||
label: "",
|
||||
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.",
|
||||
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.",
|
||||
textAlignment: "PKTextAlignmentLeft",
|
||||
},
|
||||
{
|
||||
@@ -147,8 +145,7 @@ app.all(async function manageRequest(request, response) {
|
||||
{
|
||||
key: "Require special assistance",
|
||||
label: "Assistenza speciale",
|
||||
value:
|
||||
"Se hai richiesto assistenza speciale, presentati a un membro del personale nell'area di Consegna bagagli almeno 90 minuti prima del volo.",
|
||||
value: "Se hai richiesto assistenza speciale, presentati a un membro del personale nell'area di Consegna bagagli almeno 90 minuti prima del volo.",
|
||||
textAlignment: "PKTextAlignmentLeft",
|
||||
},
|
||||
{
|
||||
@@ -160,22 +157,19 @@ app.all(async function manageRequest(request, response) {
|
||||
{
|
||||
key: "photoId",
|
||||
label: "Un documento d’identità corredato di fotografia",
|
||||
value:
|
||||
"è obbligatorio su TUTTI i voli. Per un viaggio internazionale è necessario un passaporto valido o, dove consentita, una carta d’identità.",
|
||||
value: "è obbligatorio su TUTTI i voli. Per un viaggio internazionale è necessario un passaporto valido o, dove consentita, una carta d’identità.",
|
||||
textAlignment: "PKTextAlignmentLeft",
|
||||
},
|
||||
{
|
||||
key: "yourSeat",
|
||||
label: "Il tuo posto:",
|
||||
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.",
|
||||
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.",
|
||||
textAlignment: "PKTextAlignmentLeft",
|
||||
},
|
||||
{
|
||||
key: "Pack safely",
|
||||
label: "Bagaglio sicuro",
|
||||
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",
|
||||
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",
|
||||
textAlignment: "PKTextAlignmentLeft",
|
||||
},
|
||||
{
|
||||
@@ -186,9 +180,10 @@ app.all(async function manageRequest(request, response) {
|
||||
},
|
||||
);
|
||||
|
||||
const stream = pass.generate();
|
||||
const stream = pass.getAsStream();
|
||||
|
||||
response.set({
|
||||
"Content-type": "application/vnd.apple.pkpass",
|
||||
"Content-type": pass.mimeType,
|
||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||
});
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
*/
|
||||
|
||||
import app from "./webserver";
|
||||
import { createPass } from "passkit-generator";
|
||||
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) {
|
||||
const passName =
|
||||
@@ -15,7 +17,7 @@ app.all(async function manageRequest(request, response) {
|
||||
new Date().toISOString().split("T")[0].replace(/-/gi, "");
|
||||
|
||||
try {
|
||||
const pass = await createPass({
|
||||
const pass = await PKPass.from({
|
||||
model: path.resolve(
|
||||
__dirname,
|
||||
`../models/${request.params.modelName}`,
|
||||
@@ -26,36 +28,40 @@ app.all(async function manageRequest(request, response) {
|
||||
__dirname,
|
||||
"../../certificates/signerCert.pem",
|
||||
),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
passphrase: "123456",
|
||||
},
|
||||
signerKey: path.resolve(
|
||||
__dirname,
|
||||
"../../certificates/signerKey.pem",
|
||||
),
|
||||
signerKeyPassphrase: "123456",
|
||||
},
|
||||
overrides: request.body || request.params || request.query,
|
||||
props: 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
|
||||
// only images for a specific language. So you create manually
|
||||
// an .lproj folder in your pass model then add the language here below.
|
||||
// If no translations were added, the folder
|
||||
// is included or created but without pass.strings file
|
||||
/**
|
||||
* For each language you include, an .lproj folder in pass bundle
|
||||
* is created or included. You may not want to add translations
|
||||
* but only images for a specific language. So you create manually
|
||||
* an .lproj folder in your pass model then add the language here
|
||||
* 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");
|
||||
|
||||
// Italian, already has an .lproj which gets included
|
||||
// Italian, already has an .lproj which gets included...
|
||||
pass.localize("it", {
|
||||
EVENT: "Evento",
|
||||
LOCATION: "Dove",
|
||||
});
|
||||
|
||||
// German, doesn't, so is created
|
||||
// ...while German doesn't, so it gets created
|
||||
pass.localize("de", {
|
||||
EVENT: "Ereignis",
|
||||
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
|
||||
pass.localize("zu", {});
|
||||
|
||||
// @ts-ignore - ignoring for logging purposes. Do not replicate
|
||||
console.log(
|
||||
"Added languages",
|
||||
Object.keys(pass["l10nTranslations"]).join(", "),
|
||||
Object.keys(pass[localizationSymbol]).join(", "),
|
||||
);
|
||||
|
||||
const stream = pass.generate();
|
||||
const stream = pass.getAsStream();
|
||||
|
||||
response.set({
|
||||
"Content-type": "application/vnd.apple.pkpass",
|
||||
"Content-type": pass.mimeType,
|
||||
"Content-disposition": `attachment; filename=${passName}.pkpass`,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user