• This repository has been archived on 16/Dec/2023
  • Stars
    star
    280
  • Rank 147,492 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

iOS Passbook for the Node hacker

Get your certificates

To start with, you'll need a certificate issued by the iOS Provisioning Portal. You need one certificate per Passbook Type ID.

After adding this certificate to your Keychain, you need to export it as a .p12 file and copy it into the keys directory.

You will also need the 'Apple Worldwide Developer Relations Certification Authority' certificate and to conver the .p12 files into .pem files. You can do both using the node-passbook prepare-keys command:

node-passbook prepare-keys -p keys

This is the same directory into which you placet the .p12 files.

Start with a template

Start with a template. A template has all the common data fields that will be shared between your passes, and also defines the keys to use for signing it.

var createTemplate = require("passbook");

var template = createTemplate("coupon", {
  passTypeIdentifier: "pass.com.example.passbook",
  teamIdentifier:     "MXL",
  backgroundColor:   "rgb(255,255,255)"
});

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.fields.passTypeIdentifier = "pass.com.example.passbook";

console.log(template.passTypeIdentifier());

template.teamIdentifier("MXL").
  passTypeIdentifier("pass.com.example.passbook")

The following template fields are required: passTypeIdentifier - The Passbook Type ID, begins with "pass." teamIdentifier - May contain an I

Optional fields that you can set on the template (or pass): backgroundColor, foregroundColor, labelColor, logoText, organizationName, suppressStripShine and webServiceURL.

In addition, you need to tell the template where to find the key files and where to load images from:

template.keys("/etc/passbook/keys", "secret");
template.loadImagesFrom("images");

The last part is optional, but if you have images that are common to all passes, you may want to specify them once in the template.

Create your pass

To create a new pass from a template:

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

Just like template, you can access pass fields directly, or from chained accessor methods, e.g:

pass.fields.serialNumber = "12345";
console.log(pass.serialNumber());
pass.serialNumber("12345").
  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 like add, get and remove that will do the logical thing. For example, to add a primary field:

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

You can also call add with an array of triplets or array of objects.

To get one or all fields:

var dateField = pass.primaryFields.get("date");
var allFields = pass.primaryFields.all();

To remove one or all fields:

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

Adding images to a pass is the same as adding images to a template:

pass.images.icon = iconFilename;
pass.icon(iconFilename);
pass.loadImagesFrom("images");

You can add the image itself (a Buffer), or provide the name of a file or an HTTP/S URL for retrieving the image. You can also provide a function that will be called when it's time to load the image, and should pass an error, or null and a buffer to its callback.

Generate the file

To generate a file:

var file = fs.createWriteStream("mypass.pkpass");
pass.on("error", function(error) {
  console.error(error);
  process.exit(1);
})
pass.pipe(file);

Your pass will emit the error event if it fails to generate a valid Passbook file, and emit the end event when it successfuly completed generating the file.

You can pipe to any writeable stream. When working with HTTP, the render method will set the content type, pipe to the HTTP response, and make use of a callback (if supplied).

server.get("/mypass", function(request, response) {
  pass.render(response, function(error) {
    if (error)
      console.error(error);
  });
});

More Repositories

1

zombie

Insanely fast, full-stack, headless browser testing using node.js
JavaScript
5,656
star
2

vanity

Experiment Driven Development for Ruby
Ruby
1,546
star
3

node-replay

When API testing slows you down: record and replay HTTP responses like a boss
JavaScript
522
star
4

uuid

Generates universally unique identifiers (UUIDs) for use in distributed applications.
Ruby
480
star
5

rack-oauth2-server

LOOKING FOR MAINTAINER โ€” OAuth 2.0 Authorization Server as a Rack module
Ruby
232
star
6

scrapi

LOOKING FOR A MAINTAINER
Ruby
157
star
7

fine-tune

๐Ÿ‘‹ The missing UI for working with OpenAI: manage your files, and fine tune models.
TypeScript
76
star
8

ironium

Job queues and scheduled jobs for Node.js, Beanstalkd and/or Iron.io.
JavaScript
72
star
9

sideline

Sideline, a CoffeeScript shell for your server (NO LONGER MAINTAINED)
CoffeeScript
39
star
10

whisper-to-me

SVG graphs from Whisper files
CoffeeScript
37
star
11

necktie

NO LONGER MAINTAINED
Ruby
30
star
12

ruby-in-practice

Source code and examples from the book Ruby In Practice
Ruby
29
star
13

queue-run

๐Ÿ‘‹ Web 2.0 framework to make building back-ends and APIs easy and fun: HTTP, FIFO queues, WebSocket, and more โ€ฆ
TypeScript
26
star
14

pipemaster

NO LONGER MAINTAINED
Ruby
24
star
15

css-annotate

The Annotated CSS tells you which style to use where
Ruby
23
star
16

octolog

Github is our single sign-on octopus
CoffeeScript
20
star
17

reliable-msg

NO LONGER MAINTAINED
Ruby
15
star
18

dailyhi

Start the morning with a friendly Hi in your inbox.
Ruby
12
star
19

archive-2005

Ruby
10
star
20

highfive

HTML 5/CSS 3/jQuery goodness
Ruby
9
star
21

vanity.js

NO LONGER MAINTAINED
CoffeeScript
8
star
22

lazybird

Lazy promises using Bluebird (NO LONGER MAINTAINED)
JavaScript
4
star
23

react-one-tap

Google One Tap sign-in for React
TypeScript
4
star
24

assaf

1
star