# API Reference
The flow of execution is really easy (once setted-up everything):
* You get your data from somewhere
* You set the needed data in the pass through methods, overrides and data in fields
* You generate the pass stream through `.generate()` method
* Hooray 😄🎉
Some details:
* Properties will be checked against schemas, which are built to reflect Apple's specifications, that can be found on Apple Developer Portal, at [PassKit Package Format Reference](https://apple.co/2MUHsm0).
* Here below are listed all the available methods that library will let you use.
* In case of troubleshooting, you can start your project with "debug flag" as follows:
```sh
$ DEBUG=* node index.js
```
For other OSs, see [Debug Documentation](https://www.npmjs.com/package/debug).
* Keep this as always valid for the reference:
```javascript
const { Pass } = require("passkit-generator");
```
___
### Index:
* [Instance](#method_constructor)
* [Localizing Passes](#localizing_passes)
* [.localize()](#method_localize)
* Setting barcode
* [.barcode()](#method_barcode)
* [.backward()](#method_bBackward)
* [.autocomplete()](#method_bAutocomplete)
* Setting expiration / voiding the pass
* [.expiration()](#method_expiration)
* [.void()](#method_void)
* Setting relevance
* [.relevance()](#method_relevance)
* Setting NFC
* [.nfc()](#method_nfc)
* [Setting Pass Structure Keys (primaryFields, secondaryFields, ...)](#prop_fields)
* [TransitType](#prop_transitType)
* Generating the compiled pass.
* [.generate()](#method_generate)
___
#### constructor()
```javascript
var pass = new Pass(options);
```
**Returns**:
`Object`
**Arguments**:
| Key | Type | Description | Optional | Default Value |
|-----|------|---------------|:-------------:|:-----------:|
| options | Object | The options to create the pass | false | -
| options.model | String/Path | The model path to be used to generate a new model. | false | -
| options.certificates | Object | The certificate object containing the paths to certs files. | false | -
| options.certificates.wwdr | String/Path | The path to Apple WWDR certificate or its content. | false | -
| options.certificates.signerCert | String/Path | The path to Developer certificate file or its content. | false | -
| options.certificates.signerKey | Object/String | The object containing developer certificate's key and passphrase. If string, it can be the path to the key file or its content. If object, must have `keyFile` key and might need `passphrase`. | false | -
| options.certificates.signerKey.keyFile | String/Path | The path to developer certificate key or its content. | false | -
| options.certificates.signerKey.passphrase | String \| Number | The passphrase to use to unlock the key. | false | -
| options.overrides | Object | Dictionary containing all the keys you can override in the pass.json file and does not have a method to get overridden. | true | { }
| options.shouldOverwrite | Boolean | Setting this property to false, will make properties in `overrides` and fields to be pushed along with the ones added through methods to the existing ones in pass.json. | true | true
___
**Localizing Passes**:
___
Following Apple Developer Documentation, localization (L10N) is done by creating a `.lproj` folder for each language you want to translate your pass, each named with the relative [ISO-3166-1 alpha-2](https://it.wikipedia.org/wiki/ISO_3166-1_alpha-2) code (e.g. `en.lproj`).
In this library, localization can be done in three ways: **media-only** (images), **translations-only** or both.
The only differences stands in the way the only method below is used and how the model is designed.
> If you are designing your pass for a language only, you can directly replace the placeholders in `pass.json` with translation.
#### .localize()
```javascript
pass.localize(lang, options);
```
**Returns**:
`Object (this)`
**Description**:
You may want to create the folder and add translated media and no translations; else you may want to add only translations without different medias or maybe both.
In the first case, create the `.lproj` folder in the model root folder and add the translated medias inside. Then use the method by passing only the first parameters, the code.
In the other two cases, you'll need to specify also the second argument (the translations to be added to `pass.strings` file, which will be added later).
**Arguments**:
| Key | Type | Description | Optional | Default Value |
|-----|------|-------------|----------|:-------------:|
| lang | String | The ISO-3166-1 language code | false | -
| options | Object | Translations in format PLACEHOLDER : TRANSLATED-VALUE. | true | undefined \| { }
**Example**:
```javascript
pass
.localize("it", {
"EVENT": "Evento",
"LOCATION": "Posizione"
})
.localize("de", {
"EVENT": "Ereignis",
"LOCATION": "Ort"
})
.localize("en")
```
___
**Setting barcodes**:
___
#### .barcode()
```javascript
pass.barcode(data);
```
**Returns**:
`Improved Object (this with some "private" methods available to be called under aliases, as below)`
**Description**:
Each object in `data` will be filtered against a schema ([Apple reference](https://apple.co/2myAbst)) validation and used if correctly formed.
If the argument is an Object, it will be treated as one-element Array.
If the argument is a String or an Object with `format` parameter missing, but `message` available, the structure will be **autogenerated** complete of all the fallbacks (4 dictionaries).
To support versions prior to iOS 9, `barcode` key is automatically supported as the first valid value of the provided (or generated) barcode. To change the key, see below.
**Arguments**:
| Key | Type | Description | Optional | Default Value |
|-----|------|-------------|----------|:-------------:|
| data | String \| Array\