mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 23:25:26 +00:00
Improved typings and type checkings
This commit is contained in:
@@ -27,20 +27,20 @@ interface RequestWithBody extends functions.Request {
|
|||||||
textColor: string;
|
textColor: string;
|
||||||
backgroundColor: string;
|
backgroundColor: string;
|
||||||
labelColor: string;
|
labelColor: string;
|
||||||
relevantDate: string;
|
relevantDate?: string;
|
||||||
expiryDate: string;
|
expiryDate?: string;
|
||||||
relevantLocationLat: number | "Blank";
|
relevantLocationLat?: number;
|
||||||
relevantLocationLong: number | "Blank";
|
relevantLocationLong?: number;
|
||||||
header: { value: string; label: string }[];
|
header?: { value: string; label: string }[];
|
||||||
primary: { value: string; label: string }[];
|
primary?: { value: string; label: string }[];
|
||||||
secondary: { value: string; label: string }[];
|
secondary?: { value: string; label: string }[];
|
||||||
auxiliary: { value: string; label: string }[];
|
auxiliary?: { value: string; label: string }[];
|
||||||
codeAlt: string;
|
codeAlt?: string;
|
||||||
qrText: string;
|
qrText?: string;
|
||||||
transitType: TransitType;
|
transitType?: TransitType;
|
||||||
codeType: Barcode["format"];
|
codeType?: Barcode["format"];
|
||||||
thumbnailFile: string;
|
thumbnailFile?: string;
|
||||||
logoFile: string;
|
logoFile?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +84,11 @@ export const pass = functions.https.onRequest(
|
|||||||
|
|
||||||
const newPass = await PKPass.from(
|
const newPass = await PKPass.from(
|
||||||
{
|
{
|
||||||
// Get relevant pass model from model folder (see passkit-generator/examples/models/)
|
/**
|
||||||
model: `./model/${request.body.passModel}.pass`,
|
* Get relevant pass model from model folder (see passkit-generator/examples/models/)
|
||||||
|
* Path seems to get read like the function is in "firebase/" folder and not in "firebase/functions/"
|
||||||
|
*/
|
||||||
|
model: `../../models/${request.body.passModel}.pass`,
|
||||||
certificates: {
|
certificates: {
|
||||||
// Assigning certificates from certs folder (you will need to provide these yourself)
|
// Assigning certificates from certs folder (you will need to provide these yourself)
|
||||||
wwdr: process.env.WWDR,
|
wwdr: process.env.WWDR,
|
||||||
@@ -105,20 +108,29 @@ export const pass = functions.https.onRequest(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (newPass.type == "boardingPass") {
|
if (newPass.type == "boardingPass") {
|
||||||
|
if (!request.body.transitType) {
|
||||||
|
response.status(400);
|
||||||
|
response.send({
|
||||||
|
error: "transitType is required",
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
newPass.transitType = request.body.transitType;
|
newPass.transitType = request.body.transitType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.body.relevantDate !== "Blank") {
|
if (typeof request.body.relevantDate === "string") {
|
||||||
newPass.setRelevantDate(new Date(request.body.relevantDate));
|
newPass.setRelevantDate(new Date(request.body.relevantDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.body.expiryDate !== "Blank") {
|
if (typeof request.body.expiryDate === "string") {
|
||||||
newPass.setExpirationDate(new Date(request.body.expiryDate));
|
newPass.setExpirationDate(new Date(request.body.expiryDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
request.body.relevantLocationLat !== "Blank" &&
|
request.body.relevantLocationLat &&
|
||||||
request.body.relevantLocationLong !== "Blank"
|
request.body.relevantLocationLong
|
||||||
) {
|
) {
|
||||||
newPass.setLocations({
|
newPass.setLocations({
|
||||||
latitude: request.body.relevantLocationLat,
|
latitude: request.body.relevantLocationLat,
|
||||||
@@ -126,6 +138,7 @@ export const pass = functions.https.onRequest(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(request.body.header)) {
|
||||||
for (let i = 0; i < request.body.header.length; i++) {
|
for (let i = 0; i < request.body.header.length; i++) {
|
||||||
const field = request.body.header[i];
|
const field = request.body.header[i];
|
||||||
|
|
||||||
@@ -139,7 +152,9 @@ export const pass = functions.https.onRequest(
|
|||||||
value: field.value,
|
value: field.value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(request.body.primary)) {
|
||||||
for (let i = 0; i < request.body.primary.length; i++) {
|
for (let i = 0; i < request.body.primary.length; i++) {
|
||||||
const field = request.body.primary[i];
|
const field = request.body.primary[i];
|
||||||
|
|
||||||
@@ -156,7 +171,9 @@ export const pass = functions.https.onRequest(
|
|||||||
: field.value,
|
: field.value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(request.body.secondary)) {
|
||||||
for (let i = 0; i < request.body.secondary.length; i++) {
|
for (let i = 0; i < request.body.secondary.length; i++) {
|
||||||
const field = request.body.secondary[i];
|
const field = request.body.secondary[i];
|
||||||
|
|
||||||
@@ -177,7 +194,9 @@ export const pass = functions.https.onRequest(
|
|||||||
: "PKTextAlignmentLeft",
|
: "PKTextAlignmentLeft",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(request.body.auxiliary)) {
|
||||||
for (let i = 0; i < request.body.auxiliary.length; i++) {
|
for (let i = 0; i < request.body.auxiliary.length; i++) {
|
||||||
const field = request.body.auxiliary[i];
|
const field = request.body.auxiliary[i];
|
||||||
|
|
||||||
@@ -198,19 +217,14 @@ export const pass = functions.https.onRequest(
|
|||||||
: "PKTextAlignmentLeft",
|
: "PKTextAlignmentLeft",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!request.body.codeAlt || request.body.codeAlt.trim() === "") {
|
if (request.body.qrText && request.body.codeType) {
|
||||||
newPass.setBarcodes({
|
newPass.setBarcodes({
|
||||||
message: request.body.qrText,
|
message: request.body.qrText,
|
||||||
format: request.body.codeType,
|
format: request.body.codeType,
|
||||||
messageEncoding: "iso-8859-1",
|
messageEncoding: "iso-8859-1",
|
||||||
});
|
altText: request.body.codeAlt?.trim() ?? "",
|
||||||
} else {
|
|
||||||
newPass.setBarcodes({
|
|
||||||
message: request.body.qrText,
|
|
||||||
format: request.body.codeType,
|
|
||||||
messageEncoding: "iso-8859-1",
|
|
||||||
altText: request.body.codeAlt,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user