A Node.js library for generating Apple Wallet passes with localizations, NFC and web service push updates support. Written in Typescript.
npm install @destinationstransfers/passkit --saveyarn add @destinationstransfers/passkit
Get your certificates
To start with, you'll need a certificate issued by the iOS Provisioning Portal. You need one certificate per Pass Type ID.
After adding this certificate to your Keychain, you need to export it as a
.p12 file first, then convert that file into a
.pem file using the
and copy it into the keys directory.
The Apple Worldwide Developer Relations Certification Authority certificate is not needed anymore since it is already included in this package.
Start with a template
Start with a template. A template has all the common data fields that will be shared between your passes.
const Template = ;// Create a Template from local folder, see __test__/resources/passes for examples// .load will load all fields from pass.json,// as well as all images and com.example.passbook.pem file as key// and localization string tooconst template = await Template;// or// create a Template from a Buffer with ZIP contentconst s3 = apiVersion: "2006-03-01" region: "us-west-2" ;const s3file = await s3;const template = await Template;// or create it manuallyconst template = "coupon"passTypeIdentifier: "pass.com.example.passbook"teamIdentifier: "MXL"backgroundColor: "red"sharingProhibited: true;await templateimages
The first argument is the pass style (
eventTicket, etc), and the
second optional argument has any fields you want to set on the template.
You can access template fields directly, or from chained accessor methods, e.g:
templatepassTypeIdentifier = "pass.com.example.passbook";templateteamIdentifier = "MXL";
The following template fields are required:
passTypeIdentifier- The Apple Pass Type ID, which has the prefix
teamIdentifier- May contain an I
You can set any available fields either on a template or pass instance, such as:
In addition, you need to tell the template where to find the key file:
await template;// or set them as stringstemplate;template;
If you have images that are common to all passes, you may want to specify them once in the template:
// specify a single image with specific density and localizationawait passimages;// load all appropriate images in all densities and localizationsawait templateimages;
You can add the image itself or a
Buffer. Image format is enforced to be PNG.
Alternatively, if you have one directory containing the template file
pass.json, the key
com.example.passbook.pem and all the needed images, you can just use this single command:
const template = await Template;
Create your pass
To create a new pass from a template:
const pass = template;
Just like the template, you can access pass fields directly, e.g:
passserialNumber = "12345";passdescription = "20% off";
In the JSON specification, structure fields (primary fields, secondary fields, etc) are represented as arrays, but items must have distinct key properties. Le sigh.
To make it easier, you can use methods of standard Map object or
will do the logical thing. For example, to add a primary field:
To get one or all fields:
const dateField = passprimaryFields;for const key value of passprimaryFields// ...
To remove one or all fields:
Adding images to a pass is the same as adding images to a template (see above).
Working with Dates
If you have dates in your fields make sure they are in ISO 8601 format with timezone or a
const constants = ;passprimaryFields;// there is also a helper setDateTime methodpassauxiliaryFields;// main fields also accept Date objectspassrelevantDate = 2020 1 1 10 0;templateexpirationDate = 2020 10 10 10 10;
// everything from template// will load all localized images and strings from folders like ru.lproj/ or fr-CA.lproj/await template;// Stringspasslocalizations;// Imagesawait templateimages;
Localization applies for all fields'
value. There is a note about that in documentation.
Generate the file
To generate a file:
const buf = await pass;await fs;
You can send the buffer directly to an HTTP server response:
Troubleshooting with Console app
If the pass file generates without errors but you aren't able to open your pass on an iPhone, plug the iPhone into a Mac with macOS 10.14+ and open the 'Console' application. On the left, you can select your iPhone. You will then be able to inspect any errors that occur while adding the pass.
- Targeting Node >= 10 and rewritten in Typescript, removing deprecated calls (
new Buffer, etc)
Template.pushUpdates(pushToken)that sends APN update request for a given pass type to a pushToken (get
pushTokenat your PassKit Web Service implementation)
- Adds constants for dictionary fields string values
- Migrated tests to Jest
- Increased test coverage
- Adds strict dictionary fields values validation (where possible) to prevent errors earlier
- Adding support for geolocation fields and Beacon fields
- Adding easy template and localization load from JSON file
- We use it in production at Transfers.do