When trying to generate my Apple Pass using @walletpass/pass-js package, I'm getting Bag Attributes SyntaxError: Unexpected identifier
. I have created the right .p12
certificate for the designated passType
and converted to .pem
as stated in the documentation.
My controller for generating Apple Pass:
var Shopper = require("../models/shopper");
const { Template } = require("@walletpass/pass-js");
const { toHTTPError } = require("../util/utils");
const { s3AppleCertificatePassword } = require("../services/config");
class ApplePassController {
async getById(req, res) {
// Functions regarding user accounts
let accountId = req.query.accountId;
....
// Create the template manually
const template = new Template("storeCard", {
passTypeIdentifier: "pass.com.identifier",
teamIdentifier: "TEAMIDENTIFIER",
organizationName: "ORGANIZATIONNAME",
logoText: "LOGOTEXT",
});
// Find the certificate
let pemEncodedPassCertificate = require("../services/applePass/Certificates.pem");
template.setCertificate(pemEncodedPassCertificate);
template.setPrivateKey(s3AppleCertificatePassword);
// Setting the images
await template.images.add("logo", "../image/applePass/logo.png", "1x");
await template.images.add("icon", "../image/applePass/icon.png", "1x");
await template.images.add("icon", "../image/applePass/icon@2x.png", "2x");
await template.images.add("strip", "../image/applePass/strip.png", "1x");
await template.images.add("strip", "../image/applePass/strip@2x.png", "2x");
// Create a new pass from a template
const pass = template.createPass({
serialNumber: "SERIALNUMBER",
description: "DESCRIPTION"
});
// Add the required fields to the pass
pass.headerFields.add({ key: "key", label: "label", value: value });
pass.secondaryFields.add({ key: "key", label: "label", value: value });
pass.secondaryFields.add({ key: "key", label: "label", value: value });
// To generate the file
const buf = await pass.asBuffer();
await fs.writeline("pkpass", buf);
// Send the buffer directly to an HTTP server response
return res.status(200).body(await pass.asBuffer());
}
}
const applePassController = new ApplePassController();
module.exports = applePassController;
The error:
(node:38515) UnhandledPromiseRejectionWarning: /Users/path/to/services/applePass/Certificates.pem:1
Bag Attributes
^^^^^^^^^^
SyntaxError: Unexpected identifier
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
Thanks for the help!