mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Fixed Serverless examples: they were not returning 400 if model name was not provided
This commit is contained in:
@@ -1,13 +1,20 @@
|
|||||||
import { ALBEvent, ALBResult } from "aws-lambda";
|
import { ALBEvent, ALBResult } from "aws-lambda";
|
||||||
import { PKPass } from "../../../../lib";
|
import { PKPass } from "../../../../lib";
|
||||||
import { finish400WithoutModelName, createPassGenerator } from "../shared";
|
import {
|
||||||
|
throwClientErrorWithoutModelName,
|
||||||
|
createPassGenerator,
|
||||||
|
} from "../shared";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lambda for barcodes example
|
* Lambda for barcodes example
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function barcodes(event: ALBEvent) {
|
export async function barcodes(event: ALBEvent) {
|
||||||
finish400WithoutModelName(event);
|
try {
|
||||||
|
throwClientErrorWithoutModelName(event);
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
const { modelName, alt, ...passOptions } = event.queryStringParameters;
|
const { modelName, alt, ...passOptions } = event.queryStringParameters;
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import { ALBEvent, ALBResult } from "aws-lambda";
|
import { ALBEvent, ALBResult, Context } from "aws-lambda";
|
||||||
import { Context } from "vm";
|
|
||||||
import { PKPass } from "passkit-generator";
|
import { PKPass } from "passkit-generator";
|
||||||
import { finish400WithoutModelName, createPassGenerator } from "../shared";
|
import {
|
||||||
|
throwClientErrorWithoutModelName,
|
||||||
|
createPassGenerator,
|
||||||
|
} from "../shared";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lambda for expirationDate example
|
* Lambda for expirationDate example
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function expirationDate(event: ALBEvent, context: Context) {
|
export async function expirationDate(event: ALBEvent, context: Context) {
|
||||||
finish400WithoutModelName(event);
|
try {
|
||||||
|
throwClientErrorWithoutModelName(event);
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
const { modelName, ...passOptions } = event.queryStringParameters;
|
const { modelName, ...passOptions } = event.queryStringParameters;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { finish400WithoutModelName, createPassGenerator } from "../shared";
|
import {
|
||||||
|
throwClientErrorWithoutModelName,
|
||||||
|
createPassGenerator,
|
||||||
|
} from "../shared";
|
||||||
import type { ALBEvent, ALBResult } from "aws-lambda";
|
import type { ALBEvent, ALBResult } from "aws-lambda";
|
||||||
import type { PKPass } from "passkit-generator";
|
import type { PKPass } from "passkit-generator";
|
||||||
|
|
||||||
@@ -7,7 +10,11 @@ import type { PKPass } from "passkit-generator";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export async function localize(event: ALBEvent) {
|
export async function localize(event: ALBEvent) {
|
||||||
finish400WithoutModelName(event);
|
try {
|
||||||
|
throwClientErrorWithoutModelName(event);
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
const { modelName, ...passOptions } = event.queryStringParameters;
|
const { modelName, ...passOptions } = event.queryStringParameters;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* PKPasses generation through PKPass.pack static method
|
||||||
|
* example.
|
||||||
|
* Here it is showed manual model reading and
|
||||||
|
* creating through another PKPass because in the other
|
||||||
|
* examples, creation through templates is already shown
|
||||||
|
*
|
||||||
|
* PLEASE NOTE THAT, AT TIME OF WRITING, THIS EXAMPLE WORKS
|
||||||
|
* ONLY IF PASSES ARE DOWNLOADED FROM SAFARI, due to the
|
||||||
|
* support of PKPasses archives. To test this, you might
|
||||||
|
* need to open a tunnel through NGROK if you cannot access
|
||||||
|
* to your local machine (in my personal case, developing
|
||||||
|
* under WSL is a pretty big limitation sometimes).
|
||||||
|
*
|
||||||
|
* PLEASE ALSO NOTE that, AT TIME OF WRITING (iOS 15.0 - 15.2)
|
||||||
|
* Pass Viewer suffers of a really curious bug: issuing several
|
||||||
|
* passes within the same pkpasses archive, all with the same
|
||||||
|
* serialNumber, will lead to have a broken view and to add
|
||||||
|
* just one pass. You can see the screenshots below:
|
||||||
|
*
|
||||||
|
* https://imgur.com/bDTbcDg.jpg
|
||||||
|
* https://imgur.com/Y4GpuHT.jpg
|
||||||
|
* https://i.imgur.com/qbJMy1d.jpg
|
||||||
|
*
|
||||||
|
* - "Alberto, come to look at APPLE."
|
||||||
|
* **Alberto looks**
|
||||||
|
* - "MAMMA MIA!""
|
||||||
|
*
|
||||||
|
* A feedback to Apple have been sent for this.
|
||||||
|
*/
|
||||||
|
|
||||||
import { ALBEvent } from "aws-lambda";
|
import { ALBEvent } from "aws-lambda";
|
||||||
import { PKPass } from "passkit-generator";
|
import { PKPass } from "passkit-generator";
|
||||||
import {
|
import {
|
||||||
@@ -5,7 +36,7 @@ import {
|
|||||||
getSpecificFileInModel,
|
getSpecificFileInModel,
|
||||||
getS3Instance,
|
getS3Instance,
|
||||||
getRandomColorPart,
|
getRandomColorPart,
|
||||||
finish400WithoutModelName,
|
throwClientErrorWithoutModelName,
|
||||||
} from "../shared";
|
} from "../shared";
|
||||||
import config from "../../config.json";
|
import config from "../../config.json";
|
||||||
|
|
||||||
@@ -14,7 +45,13 @@ import config from "../../config.json";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export async function pkpasses(event: ALBEvent) {
|
export async function pkpasses(event: ALBEvent) {
|
||||||
finish400WithoutModelName(event);
|
try {
|
||||||
|
throwClientErrorWithoutModelName(event);
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(event.queryStringParameters);
|
||||||
|
|
||||||
const [certificates, iconFromModel, s3] = await Promise.all([
|
const [certificates, iconFromModel, s3] = await Promise.all([
|
||||||
getCertificates(),
|
getCertificates(),
|
||||||
|
|||||||
@@ -7,17 +7,15 @@ import { PKPass } from "passkit-generator";
|
|||||||
|
|
||||||
const S3: { instance: AWS.S3 } = { instance: undefined };
|
const S3: { instance: AWS.S3 } = { instance: undefined };
|
||||||
|
|
||||||
export function finish400WithoutModelName(event: ALBEvent) {
|
export function throwClientErrorWithoutModelName(event: ALBEvent) {
|
||||||
if (event.queryStringParameters?.modelName) {
|
if (!event.queryStringParameters?.modelName) {
|
||||||
return;
|
throw {
|
||||||
|
statusCode: 400,
|
||||||
|
body: JSON.stringify({
|
||||||
|
message: "modelName is missing in query params",
|
||||||
|
}),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
statusCode: 400,
|
|
||||||
body: JSON.stringify({
|
|
||||||
message: "modelName is missing in query params",
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRandomColorPart() {
|
export function getRandomColorPart() {
|
||||||
|
|||||||
Reference in New Issue
Block a user