leadstoloyals / node-agcod

Node.js api for the Amazon Gift Codes On Demand Web Services
5 stars 7 forks source link

TypeError: Cannot read property 'NA' of undefined #6

Open ekkis opened 2 years ago

ekkis commented 2 years ago

followed the simple instructions in the README. I have a file with the sample code and when I run it I get the following:

$ node acogd.js 

/Users/ekkis/dev/node_modules/agcod/index.js:80 const endpoint = this.config.endpoint[region] ^

TypeError: Cannot read property 'NA' of undefined at module.exports._getSignedRequest (/Users/ekkis/dev/node_modules/agcod/index.js:80:42) at module.exports.createGiftCard (/Users/ekkis/dev/node_modules/agcod/index.js:15:32) at Object. (/Users/ekkis/dev/acogd.js:4:8) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47

what am I missing?

ekkis commented 2 years ago

I've had a gander at the code. I can see that the missing information is in the config/default.json in the package but I don't see that the code loads that anywhere

ekkis commented 2 years ago

changing the constructor to something like this makes it work:

module.exports = class {
  constructor(cfg = {}) {
    this.config = Object.assign(require('./config/default.json'), cfg);
  }
ekkis commented 2 years ago

also missing from the documentation is the fact that the client initialisation needs to be given credentials. something like this:

const client = new Client(require('./config/sandbox.json'))

with a little modification to the code it could be called without a parameter. my recommendation would be that for niladic calls the code look in ./acogd for the files and that it use the NODE_ENV environment variable to look for the name of the file, defaulting to development if not set

ekkis commented 2 years ago

if the above is acceptable I'm happy to submit a PR

ekkis commented 2 years ago

as a nice enhancement, I would make the call to createGiftCard accept a country code instead of a region. this would allow developers to create a list of the supported countries, so they can present them to the user since users don't know and don't care about regions, then that can be fed to the call. again, if these enhancements are welcome, I'm happy to submit a PR. please advise

ekkis commented 2 years ago

also, I don't know if it's possible to create a USD card for Japan. probably not. in that case we should codify the currencies for the countries involved so the createGiftCard doesn't have to be supplied it

ekkis commented 2 years ago

see 'Sundry fixes' PR