From 8c39928f0c7df7138f5b1f725e8f1a0cb95a78d3 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Thu, 30 Dec 2021 13:31:22 +0100 Subject: [PATCH] Added check on boardingPass in examples to not make crash the request if we are creating a boarding pass --- examples/self-hosted/src/PKPass.from.ts | 5 +++++ examples/self-hosted/src/localize.ts | 5 +++++ examples/self-hosted/src/setBarcodes.ts | 5 +++++ examples/self-hosted/src/setExpirationDate.ts | 5 +++++ examples/serverless/src/functions/barcodes.ts | 4 ++-- examples/serverless/src/shared.ts | 5 +++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/examples/self-hosted/src/PKPass.from.ts b/examples/self-hosted/src/PKPass.from.ts index d46943f..ebacd57 100644 --- a/examples/self-hosted/src/PKPass.from.ts +++ b/examples/self-hosted/src/PKPass.from.ts @@ -128,6 +128,11 @@ app.route("/pkpassfrom/:modelName").get(async (request, response) => { request.body || request.params || request.query, ); + if (pass.type === "boardingPass" && !pass.transitType) { + // Just to not make crash the creation if we use a boardingPass + pass.transitType = "PKTransitTypeAir"; + } + const stream = pass.getAsStream(); response.set({ diff --git a/examples/self-hosted/src/localize.ts b/examples/self-hosted/src/localize.ts index 82f0ca7..cc3832b 100644 --- a/examples/self-hosted/src/localize.ts +++ b/examples/self-hosted/src/localize.ts @@ -51,6 +51,11 @@ app.route("/localize/:modelName").get(async (request, response) => { console.log("Added languages", Object.keys(pass.languages).join(", ")); + if (pass.type === "boardingPass" && !pass.transitType) { + // Just to not make crash the creation if we use a boardingPass + pass.transitType = "PKTransitTypeAir"; + } + const stream = pass.getAsStream(); response.set({ diff --git a/examples/self-hosted/src/setBarcodes.ts b/examples/self-hosted/src/setBarcodes.ts index a184df0..6b79e90 100644 --- a/examples/self-hosted/src/setBarcodes.ts +++ b/examples/self-hosted/src/setBarcodes.ts @@ -62,6 +62,11 @@ app.route("/barcodes/:modelName").get(async (request, response) => { ); } + if (pass.type === "boardingPass" && !pass.transitType) { + // Just to not make crash the creation if we use a boardingPass + pass.transitType = "PKTransitTypeAir"; + } + const stream = pass.getAsStream(); response.set({ diff --git a/examples/self-hosted/src/setExpirationDate.ts b/examples/self-hosted/src/setExpirationDate.ts index 26b530b..e2ece50 100644 --- a/examples/self-hosted/src/setExpirationDate.ts +++ b/examples/self-hosted/src/setExpirationDate.ts @@ -62,6 +62,11 @@ app.route("/expirationDate/:modelName").get(async (request, response) => { ); } + if (pass.type === "boardingPass" && !pass.transitType) { + // Just to not make crash the creation if we use a boardingPass + pass.transitType = "PKTransitTypeAir"; + } + const stream = pass.getAsStream(); response.set({ diff --git a/examples/serverless/src/functions/barcodes.ts b/examples/serverless/src/functions/barcodes.ts index ccb8044..3fd089d 100644 --- a/examples/serverless/src/functions/barcodes.ts +++ b/examples/serverless/src/functions/barcodes.ts @@ -13,7 +13,7 @@ export async function barcodes(event: ALBEvent) { const passGenerator = createPassGenerator(modelName, passOptions); - const pass = (await passGenerator.next()).value as PKPass; + const pass = (await passGenerator.next()).value as unknown as PKPass; if (alt === "true") { // After this, pass.props["barcodes"] will have support for all the formats @@ -39,5 +39,5 @@ export async function barcodes(event: ALBEvent) { ); } - return (await passGenerator.next(pass as PKPass)).value as ALBResult; + return (await passGenerator.next()).value as ALBResult; } diff --git a/examples/serverless/src/shared.ts b/examples/serverless/src/shared.ts index 3e555ed..3d83015 100644 --- a/examples/serverless/src/shared.ts +++ b/examples/serverless/src/shared.ts @@ -143,6 +143,11 @@ export async function* createPassGenerator( ); } + if (pass.type === "boardingPass" && !pass.transitType) { + // Just to not make crash the creation if we use a boardingPass + pass.transitType = "PKTransitTypeAir"; + } + pass = yield pass; const buffer = pass.getAsBuffer();