All Projects → walletpass → Pass Js

walletpass / Pass Js

Licence: mit
Apple Wallet Passes generating library for Node.JS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Pass Js

Jpasskit
jPasskit is an Java™ implementation of the Apple™ PassKit Web Service.
Stars: ✭ 184 (-20%)
Mutual labels:  wallet, apple
Passkit Generator
The easiest way to generate custom Apple Wallet passes in Node.js
Stars: ✭ 157 (-31.74%)
Mutual labels:  wallet, apple
Apple Store Helper
Apple Store iPhone预约助手
Stars: ✭ 215 (-6.52%)
Mutual labels:  apple
Swiftvalidators
String (and more) validation for iOS
Stars: ✭ 226 (-1.74%)
Mutual labels:  apple
React Native Header View
Fully customizable Header View with multiple design options for React Native.
Stars: ✭ 221 (-3.91%)
Mutual labels:  apple
Rplibs
Refs.cn 原型设计元件库,基于Axure RP 10/9/8,支持 Android、Apple、Windows、微信,移动、桌面平台的应用和网站原型设计。五年历程 2.6k+ star,感谢大家使用。
Stars: ✭ 2,622 (+1040%)
Mutual labels:  apple
Language Manager Ios
Language Manager iOS
Stars: ✭ 222 (-3.48%)
Mutual labels:  apple
Igrphototweaks
Drag, Rotate, Scale and Crop
Stars: ✭ 212 (-7.83%)
Mutual labels:  apple
Wwdc
You don't have the time to watch all the WWDC session videos yourself? No problem me and many contributors extracted the gist for you 🥳
Stars: ✭ 2,561 (+1013.48%)
Mutual labels:  apple
Hellosilicon
An attempt with ARM64 assembly on Apple Silicon Macs
Stars: ✭ 220 (-4.35%)
Mutual labels:  apple
Doesitarm
🦾 A list of reported app support for Apple Silicon and the new Apple M1 Macs
Stars: ✭ 3,200 (+1291.3%)
Mutual labels:  apple
Bcoin
Javascript bitcoin library for node.js and browsers
Stars: ✭ 2,625 (+1041.3%)
Mutual labels:  wallet
Notificato
Takes care of Apple push notifications (APNS) in your PHP projects.
Stars: ✭ 217 (-5.65%)
Mutual labels:  apple
Apns2
⚡ HTTP/2 Apple Push Notification Service (APNs) push provider for Go — Send push notifications to iOS, tvOS, Safari and OSX apps, using the APNs HTTP/2 protocol.
Stars: ✭ 2,569 (+1016.96%)
Mutual labels:  apple
Spark Wallet
⚡️ A minimalistic wallet GUI for c-lightning, accessible over the web or through mobile and desktop apps.
Stars: ✭ 215 (-6.52%)
Mutual labels:  wallet
Slideovercard
A SwiftUI card view, made great for setup interactions.
Stars: ✭ 228 (-0.87%)
Mutual labels:  apple
Periphery
A tool to identify unused code in Swift projects.
Stars: ✭ 3,017 (+1211.74%)
Mutual labels:  apple
Bit Preserve
Project for capturing vintage, classic, aka old computer schematics in KiCad.
Stars: ✭ 219 (-4.78%)
Mutual labels:  apple
Piwallet
piWallet is an open source program developed by Johnathan Martin that allows almost anyone to setup an online web wallet for a cryptocurrency.
Stars: ✭ 222 (-3.48%)
Mutual labels:  wallet
Multisigwallet
Ethereum MultiSigWallet
Stars: ✭ 230 (+0%)
Mutual labels:  wallet

npm (scoped) codecov Known Vulnerabilities DeepScan grade Maintainability Rating tested with jest install size

Apple Wallet logo

@walletpass/pass-js

A Node.js library for generating Apple Wallet passes with localizations, NFC and web service push updates support. Written in Typescript.




Installation

Install with NPM or yarn:

npm install @walletpass/pass-js --save

yarn add @walletpass/pass-js

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 passkit-keys command:

./bin/passkit-keys ./pathToKeysFolder

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 } = require("@walletpass/pass-js");

// 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 too
const template = await Template.load(
  "./path/to/templateFolder",
  "secretKeyPasswod"
);

// or
// create a Template from a Buffer with ZIP content
const s3 = new AWS.S3({ apiVersion: "2006-03-01", region: "us-west-2" });
const s3file = await s3
  .getObject({
    Bucket: "bucket",
    Key: "pass-template.zip"
  })
  .promise();
const template = await Template.fromBuffer(s3file.Body);

// or create it manually
const template = new Template("coupon", {
  passTypeIdentifier: "pass.com.example.passbook",
  teamIdentifier: "MXL",
  backgroundColor: "red",
  sharingProhibited: true
});
await template.images.add("icon", iconPngFileBuffer)
                     .add("logo", pathToLogoPNGfile)

The first argument is the pass style (coupon, 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:

template.passTypeIdentifier = "pass.com.example.passbook";
template.teamIdentifier = "MXL";

The following template fields are required:

  • passTypeIdentifier - The Apple Pass Type ID, which has the prefix pass.
  • teamIdentifier - May contain an I

You can set any available fields either on a template or pass instance, such as: backgroundColor, foregroundColor, labelColor, logoText, organizationName, suppressStripShine and webServiceURL.

In addition, you need to tell the template where to find the key file:

await template.loadCertificate(
  "/etc/passbook/certificate_and_key.pem",
  "secret"
);
// or set them as strings
template.setCertificate(pemEncodedPassCertificate);
template.setPrivateKey(pemEncodedPrivateKey, optionalKeyPassword);

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 localization
await pass.images.add("icon", iconFilename, "2x", "ru");
// load all appropriate images in all densities and localizations
await template.images.load("./images");

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.load(
  "./path/to/templateFolder",
  "secretKeyPasswod"
);

You can use the options parameter of the template factory functions to set the allowHttp property. This enables you to use a webServiceUrl in your pass.json that uses the HTTP protocol instead of HTTPS for development purposes:

const template = await Template.load(
  "./path/to/templateFolder",
  "secretKeyPasswod",
  {
    allowHttp: true,
  },
);

Create your pass

To create a new pass from a template:

const pass = template.createPass({
  serialNumber: "123456",
  description: "20% off"
});

Just like the template, you can access pass fields directly, e.g:

pass.serialNumber = "12345";
pass.description = "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 add that will do the logical thing. For example, to add a primary field:

pass.primaryFields.add({ key: "time", label: "Time", value: "10:00AM" });

To get one or all fields:

const dateField = pass.primaryFields.get("date");
for (const [key, { value }] of pass.primaryFields.entries()) {
  // ...
}

To remove one or all fields:

pass.primaryFields.delete("date");
pass.primaryFields.clear();

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 Date instance. For example:

const { constants } = require('@destinationstransfers/passkit');

pass.primaryFields.add({ key: "updated", label: "Updated at", value: new Date(), dateStyle: constants.dateTimeFormat.SHORT, timeStyle: constants.dateTimeFormat.SHORT });

// there is also a helper setDateTime method
pass.auxiliaryFields.setDateTime(
  'serviceDate',
  'DATE',
  serviceMoment.toDate(),
  {
    dateStyle: constants.dateTimeFormat.MEDIUM,
    timeStyle: constants.dateTimeFormat.NONE,
    changeMessage: 'Service date changed to %@.',
  },
);
// main fields also accept Date objects
pass.relevantDate = new Date(2020, 1, 1, 10, 0);
template.expirationDate = new Date(2020, 10, 10, 10, 10);

Localizations

This library fully supports both string localization and/or images localization:

// everything from template
// will load all localized images and strings from folders like ru.lproj/ or fr-CA.lproj/
await template.load(folderPath);

// Strings

pass.localizations
  .add("en-GB", {
    GATE: "GATE",
    DEPART: "DEPART",
    ARRIVE: "ARRIVE",
    SEAT: "SEAT",
    PASSENGER: "PASSENGER",
    FLIGHT: "FLIGHT"
  })
  .add("ru", {
    GATE: "ВЫХОД",
    DEPART: "ВЫЛЕТ",
    ARRIVE: "ПРИЛЁТ",
    SEAT: "МЕСТО",
    PASSENGER: "ПАССАЖИР",
    FLIGHT: "РЕЙС"
  });

// Images

await template.images.add(
  "logo" | "icon" | etc,
  imageFilePathOrBufferWithPNGdata,
  "1x" | "2x" | "3x" | undefined,
  "ru"
);

Localization applies for all fields' label and value. There is a note about that in documentation.

Generate the file

To generate a file:

const buf = await pass.asBuffer();
await fs.writeFile("pathToPass.pass", buf);

You can send the buffer directly to an HTTP server response:

app.use(async (ctx, next) => {
  ctx.status = 200;
  ctx.type = passkit.constants.PASS_MIME_TYPE;
  ctx.body = await pass.asBuffer();
});

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.

Stay in touch

License

@walletpass/pass-js is MIT licensed.

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].