alexandercerutti / passkit-generator

The easiest way to generate custom Apple Wallet passes in Node.js
MIT License
897 stars 109 forks source link

webServiceURL can't be overridden #8

Closed teawithfruit closed 5 years ago

teawithfruit commented 5 years ago

Hello.

Thanks for this cool package! Is it a bug or a feature, that it is not possible to webServiceURL overridden?

Thanks

alexandercerutti commented 5 years ago

Hi! Thanks to you for using it! What do you mean with "overridden"? What error do you get?

teawithfruit commented 5 years ago

If I do something like this.

let pass = new Pass({
  model: 'ticket',
  certificates: {
    wwdr: 'wwdr.pem',
    signerCert: 'signerCert.pem',
    signerKey: {
      keyFile: 'signerKey.pem',
      passphrase: '123456'
    }
  },
  overrides: {
    serialNumber: hash,
    webServiceURL: url,
    authenticationToken: token
  },
  shouldOverwrite: true
})

webServiceURL is not being used and the pkpass file can't be opend. But if I set the parameter in the pass.json file, everything works fine.

alexandercerutti commented 5 years ago

It should be a bug, but I have to understand the reason behind this behavior. Since I'm not able to do tests right now, can you please download the generated pass, rename it from .pkpass to .zip, unzip it and put here the package-patched pass.json available inside? Thank you.

teawithfruit commented 5 years ago

Sure.

{
  "formatVersion": 1,
  "passTypeIdentifier": "pass.net.test.ticket",
  "serialNumber": "jd3bb6611a17ced10d84631b6782f367",
  "teamIdentifier": "ABCDEFGHI",
  "webServiceURL": "",
  "authenticationToken": "fb9c32b79ff1a537cb93891cbda3eea7",
  "relevantDate": "2019-11-13T00:00:00+00:00",
  "locations": [
    {
      "longitude": -122.3748889,
      "latitude": 37.6189722
    },
    {
      "longitude": -122.03118,
      "latitude": 37.33182
    }
  ],
  "organizationName": "Test",
  "description": "Ticket",
  "foregroundColor": "rgb(255, 255, 255)",
  "backgroundColor": "rgb(60, 65, 76)",
  "eventTicket": {
    "primaryFields": [
      {
        "key": "event",
        "label": "EVENT",
        "value": "Test"
      }
    ],
    "secondaryFields": [
      {
        "key": "loc",
        "label": "LOCATION",
        "value": "Test"
      }
    ],
    "transitType": ""
  },
  "barcode": {
    "message": "https://test.local.de/fb9c32b79ff1a537cb93891cbda3eea7",
    "format": "PKBarcodeFormatQR",
    "messageEncoding": "iso-8859-1"
  },
  "barcodes": [
    {
      "message": "https://test.local.de/fb9c32b79ff1a537cb93891cbda3eea7",
      "format": "PKBarcodeFormatQR",
      "messageEncoding": "iso-8859-1"
    }
  ]
}

Unfortunately the webServiceURL field is empty.

alexandercerutti commented 5 years ago

Are you sure url variable you are putting in overrides has content? Just to not exclude anything. I'll investigate asap. There may be problems with schema validation.

teawithfruit commented 5 years ago

Yes, I'm sure. I've checked it a minute ago.

Thank you for your very quick response!

alexandercerutti commented 5 years ago

Okay! I'll try to investigate this evening (GMT+1). Thank you for your patience.

You are free to make some tests too since you already have a web server setted.

alexandercerutti commented 5 years ago

Have you tried to execute the node process with the flag DEBUG=* as specified in the API Reference? It may give us more informations about the problem. Let me know.

alexandercerutti commented 5 years ago

I had a moment and tried to execute a fast test. webServiceURL failed the regex validation and got this error:

Schema validation failed due to error: child "webServiceURL" fails because ["webServiceURL" with value "https://google.com" fails to match the required pattern: /^https?:\/\/(?:[a-z0-9]+\.[a-z0-9]+\.[a-z]+(?:\.[a-z]+)?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/?(?:[a-z\/_%0-9A-Z.]+)?/]

I have to understand what regex put inside there or what to fix.

alexandercerutti commented 5 years ago

I created a new regex: https?:\/\/(?:(?:[a-z0-9]+\.?)+(?::\d)?(?:\/[\S]+)*)*

Can you please try to replace the current regex in your local schema.js, as below, and test again if it works?

webServiceURL: Joi.string().regex(/https?:\/\/(?:(?:[a-z0-9]+\.?)+(?::\d)?(?:\/[\S]+)*)*/),

Validation may give another error about the required "authenticationToken" but you can ignore it right now (I already fixed it, I'll publish the fix with the next update).

teawithfruit commented 5 years ago

Thank's again for your quick response. I did a bit more debugging and I found out, that webServiceURL do not pass if authenticationToken is set inside the schema file. If I remove the following lines, it also works with the old webServiceURL regex.

authenticationToken: Joi.string().token().min(16).when("webServiceURL", {
  is: Joi.exist(),
  then: Joi.required()
}),
alexandercerutti commented 5 years ago

In fact I'm going to change the approach to verify if both are available, in the next update. I'll release an update this afternoon or this evening in a new branch called "bugfix". I'll update you there once done and you'll have to try to use that and tell me if it fixed the issue, okay? If done I'll publish the update on NPM.

alexandercerutti commented 5 years ago

Okay @teawithfruit, I've pushed to a new branch bugfix. Try with this version and let me know 👍

alexandercerutti commented 5 years ago

Hi @teawithfruit, any news?

teawithfruit commented 5 years ago

Sorry for the late response. Yes, I've tested it and it's working now. Thank you!

alexandercerutti commented 5 years ago

Awesome! I'm going to push this update on NPM asap 😊

Closing!

EDIT: Published in 1.5.5