{"_id":"@addario-org/currencycloud-js-client","_rev":"1-2d6bd3afa6344b15e731465ed5c903bf","name":"@addario-org/currencycloud-js-client","dist-tags":{"latest":"3.4.0-ea"},"versions":{"3.4.0-ea":{"name":"@addario-org/currencycloud-js-client","description":"Currencycloud API v2 JavaScript client (FORK)","version":"3.4.0-ea","author":{"name":"Ed Addario"},"contributors":[{"name":"Irina Gudkova","email":"irina.gudkova@gmail.com"},{"name":"Ed Addario","email":"ed.addario@currencycloud.com"},{"name":"Ed Addario","email":"eaddario@hotmail.com"}],"license":"MIT","repository":{"type":"git","url":"git://github.com/addario-org/currencycloud-js-client.git"},"bugs":{"url":"https://github.com/addario-org/currencycloud-js-client/issues"},"homepage":"https://www.addario.org","keywords":["currency cloud","currencycloud","api","client","client library"],"main":"./lib/currency-cloud","engines":{"node":">=4.0.0"},"dependencies":{"combined-stream":"^1.0.8","request":"^2.88.2","request-promise":"^4.2.5","retry":"^0.12.0","uuid":"^8.2.0"},"devDependencies":{"chai":"^4.2.0","@types/chai":"^4.2.11","jshint":"^2.11.1","mocha":"^8.0.1","@types/mocha":"^8.0.0","nock":"^13.0.2"},"scripts":{"lint":"jshint examples lib test","test":"mocha test/api/ --timeout 15000","pretest":"npm run lint"},"settings":{"environment":{"demo":"https://devapi.currencycloud.com","production":"https://api.currencycloud.com"}},"gitHead":"379451a89ffb8c272cc2411a0d3ca011beb52dea","_id":"@addario-org/currencycloud-js-client@3.4.0-ea","_nodeVersion":"14.6.0","_npmVersion":"6.14.7","dist":{"integrity":"sha512-3uqLEyYwBsItylry0Ij9+CxHhXHdpRpnTnEBHJCpzlUzPFwtwjfoUwLb+nqUk7Qnxi+K4f56/G6sP1ULBSwKyg==","shasum":"3e2d8f2142668255c84182eec0da6f98f973de2b","tarball":"https://registry.npmjs.org/@addario-org/currencycloud-js-client/-/currencycloud-js-client-3.4.0-ea.tgz","fileCount":25,"unpackedSize":91333,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfID/hCRA9TVsSAnZWagAAUmMP/j/DHK3TzfsDl4tMTsZy\nHgMJKs0zWqUc5xhdBL+4D195S6tEnVOIinh4SZhSNSKAIhEjn4CrhThF+fUj\nb6BcqmevoJ6BqAVCfOtK6xp+HmIYsWJqzG90BaC+81Te0N9+gcdPks4uGrjD\nEjD5srBPhKmpk+q0ac0dNAgvPkI9CfeAsrFV/I3P9GSUTmirO8ElKCIzNzdK\n8RXvdlGxVJGe8f4OL1vA7WE5650MzzBCmKakoptFZ9A5RYrPg5gQL7QxAYoL\no8gvuBcy2U2mMdVh5WZDXG9/RVNpqE3NbNSKbQvbdfa7XmBVFYT7+k6j5z+v\n0jJrUK3Gnvm0WfHYlSBvPXJnOsYpUUs4fp1BhuAfDUzthoA7CvA2VPHxaw6g\nIMcB+SYb+qoLBjxmCVLUoTXKAPght/qzYRQDZT27hM1+PX/I8/QKcnivGX74\n/dx5et2086eF1KEFj0/qV8qpYgKbpJZ/5yK2fl7187YHnuyAkbyLlE/qC0mG\nR2ZGxqowxNN9UabkMCH4gYW5WLFeUTXRGuuKElJF/EmpT4WVZXcVOgT2DG/9\nxeqoBM8n9pTal5ov3FZIduxVMNKknFpWLUtE71TSFBT1mym0DH1D8pUKRJox\nuzpotslT3w/fRTJQImEKnsUGEJ0Pru8EkTh2CAI7IJvs+EaOjiUvEMPqjMso\nyz4u\r\n=vQFw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD65apRtBwCku+8Gv9DPTd74SR30H2zFoF7X4kj3NVOnQIhAOBMfGuP1J0903sxnTO3w701X1I9OpCMxMpxUTrSvyrG"}]},"maintainers":[{"name":"eaddario","email":"eaddario@hotmail.com"}],"_npmUser":{"name":"eaddario","email":"eaddario@hotmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/currencycloud-js-client_3.4.0-ea_1595949024751_0.8386444222178171"},"_hasShrinkwrap":false}},"time":{"created":"2020-07-28T15:10:24.501Z","3.4.0-ea":"2020-07-28T15:10:24.947Z","modified":"2022-04-04T11:27:47.502Z"},"maintainers":[{"name":"eaddario","email":"eaddario@hotmail.com"}],"description":"Currencycloud API v2 JavaScript client (FORK)","homepage":"https://www.addario.org","keywords":["currency cloud","currencycloud","api","client","client library"],"repository":{"type":"git","url":"git://github.com/addario-org/currencycloud-js-client.git"},"contributors":[{"name":"Irina Gudkova","email":"irina.gudkova@gmail.com"},{"name":"Ed Addario","email":"ed.addario@currencycloud.com"},{"name":"Ed Addario","email":"eaddario@hotmail.com"}],"author":{"name":"Ed Addario"},"bugs":{"url":"https://github.com/addario-org/currencycloud-js-client/issues"},"license":"MIT","readme":"[![Build Status](https://travis-ci.org/addario-org/currencycloud-js-client.svg?branch=master)](https://travis-ci.org/github/addario-org/currencycloud-js-client)\n[![Github Package](https://img.shields.io/badge/github%20package-v3.4.0--ea-brightgreen)](https://github.com/addario-org/currencycloud-js-client/packages/329885)\n[![Issues](https://img.shields.io/github/issues/addario-org/currencycloud-js-client)](https://github.com/addario-org/currencycloud-js-client/issues)\n[![License](https://img.shields.io/github/license/addario-org/currencycloud-js-client)](https://github.com/addario-org/currencycloud-js-client/blob/master/LICENSE.md)\n[![Last Commit](https://img.shields.io/github/last-commit/addario-org/currencycloud-js-client)](https://github.com/addario-org/currencycloud-js-client/commits/master)\n\n# Currencycloud API v2 JavaScript client\n\n## Version: 3.4.0-ea (FORK)\nThis is a **FORK** from the official [Javascript SDK for v2 of Currencycloud's API.][original] While it tries to keep in sync with the upstream version, it does also include enhancements and modifications ranging from bugfixes to usability features.\n\nAdditional documentation for each API endpoint can be found at [Currencycloud API documentation][introduction]. If you have any queries or you require support, please contact their development team at development@currencycloud.com\n\n## Installation\nThis library is distributed on [GitHub Packages][gitpack]. In order to add it as a dependency follow these steps:\n1. In the same directory as your `package.json` file create or edit an `.npmrc` file to include a line specifying GitHub Packages URL\n```sh\nregistry=https://npm.pkg.github.com/addario-org\n```\n\n2. Configure your project's `package.json` file to include the `currencycloud-js-client` dependency\n\n```sh\n\"dependencies\": {\n    \"@addario-org/currencycloud-js-client\": \"3.4.0-ea\"\n  }\n```\n\n3. You can then install it in the usual way\n\n```sh\n$ npm install currencycloud-js-client --save\n```\n\n## Supported Node versions\nThe least supported Node version is 6.0.0.\n\n# Usage\nThe following example retrieves all tradeable currencies list:\n```js\nvar currencyCloud = require('currency-cloud');\n\ncurrencyCloud.authentication.login({\n  environment: 'demo', \n  loginId: 'valid_login_id', \n  apiKey: 'valid_api_key'\n})\n.then(currencyCloud.reference.getAvailableCurrencies)\n.then(function(res) {\n  console.log('available currencies: ' + JSON.stringify(res.currencies, null, 2));    \n})\n.then(currencyCloud.balances.find)\n.then(function(res) {\n  console.log('balances: ' + JSON.stringify(res.balances, null, 2));    \n})\n.then(currencyCloud.authentication.logout)\n.catch(console.log);\n```\nMore extensive examples can be found in the [examples] folder.\n\n## Service client\nTo interact with the various Currencycloud's APIs a service client object must be created; then a particular API can be accessed via the corresponding property of this object:\n```js\n// create service client object\nvar currencyCloud = require('currency-cloud');\n\n// access authentication API\ncurrencyCloud.authentication.login({\n  environment: 'demo', \n  loginId: 'valid_login_id', \n  apiKey: 'valid_api_key'\n})\n.then(function() {\n  // access reference API\n  return currencyCloud.reference.getBeneficiaryRequiredDetails({\n    currency: 'EUR',\n    bankAccountCountry: 'DE'\n  });\n})\n.then(console.log)\n.then(currencyCloud.authentication.logout);\n```\nSupported APIs are listed in the [Currencycloud API overview][overview].\n\n## Authentication\nPrior to calling API functions authentication is required. It is performed as follows:\n```js\nvar currencyCloud = require('currency-cloud');\n\ncurrencyCloud.authentication.login({\n  environment: 'demo', // environment to run API calls against, one of those listed in 'settings' section of package.json \n  loginId: 'login_id', // login id of the API user, as specified during registration\n  apiKey: 'api_key'    // corresponding API key, obtained upon registration\n})\n.then(function(token) {\n  ...\n});\n```\nThe above code retrieves authentication token, which is passed with all subsequent API calls. If a call fails due to token is expired, then re-authentication is attempted, so that the token is refreshed and the failed request is retried.\n\nWhen working with API is finished, it is recommended to close the session by calling `currencyCloud.authentication.logout()`.\n\n## Passing parameters\nSDK functions accept arguments as a single object, which holds both required and optional parameters: \n```js\nvar currencyCloud = require('currency-cloud');\n\ncurrencyCloud.accounts.create({\n  /* required parameters */\n  accountName: 'Firma AB',\n  legalEntityType: 'company',\n  \n  /* optional parameters */\n  status: 'enabled',\n  street: 'Sergels Torg 2',\n  city: 'Stockholm',\n  postalCode: '10640',\n  country: 'SE',\n  spreadTable: 'no_markup',\n  identificationType: 'none'\n})\n.then(console.log);\n```\nFunction arguments as well as return objects and errors are camelCased.\n\n## Promises\nEach API call is an asynchronous operation, so Promises/A+ pattern is used heavily throughout the SDK. Every function, if not synchronously throwing an Error, returns a then-able promise.\n\n## Exponential Backoff & Retry Strategy\nRequests over the internet will fail on occasion for seemingly no apparent reason, and the SDK includes a comprehensive set of error handling capabilities to help troubleshoot those situations. Sometimes however, the best strategy is simply to retry. This is the case particularly with transient errors like **HTTP 429 - Too Many Requests**, but wrapping calls in for/while loops is discouraged as in some extreme cases this may trigger our anti-DoS defences.\n\nAs of version 1.14.1 we have introduced an Exponential Backoff with Jitter retry feature which we recommend you use to safely handle retries.\n\n### retry(fn, [options])\nCalls **_fn_** until the returned promise ends up fulfilled or rejected with an error different than `TooManyRequestsError`. The optional **_options_** argument is an object which maps to the following values:\n\n* _retries_: The maximum amount of times to retry the operation. Default is `7`.\n* _factor_: The exponential factor to use. Default is `2`.\n* _minTimeout_: The number of milliseconds before starting the first retry. Default is a random value between `0` and `750` ms.\n* _maxTimeout_: The maximum number of milliseconds between two retries. Default is a random value between `30` and `60` sec.\n* _randomize_: Randomizes the timeouts by multiplying with a factor between `1` and `2`. Default is `true`.\n* _log_: Logs retries to console if `true`. Default is `false`\n* _name_: The name of **_fn_**. Helpful for logging and troubleshooting.\n\nThe **_fn_** function will receive a retry function as an argument that should be called with an error whenever you want to retry **_fn_**. The retry function will always throw an error.\nIf there're retries left, it will throw a special retry error that will be handled internally to call fn again. If there're no retries left, it will throw the actual error passed to it.\n\nA typical use case is presented below. For more information see the [Cookbook examples][examples].\n\n```js\nvar currencyCloud = require('currency-cloud');\nconst opts = {\n  retries: 5, //Retry up to five times before giving up\n  factor: 2, // Use an exponential wait\n  minTimeout: Math.random() * 750, // Initial wait in ms\n  maxTimeout: Math.random() * 30000 + 30000, // Maximum wait period in ms\n  randomize: true // Apply a random jitter on each iteration\n  log: true // Log retries to the console \n};\n\nlet findBalances = () => {\n  return currencyCloud.retry(\n    () => {\n      return currencyCloud.balances.find()\n        .then(function (res) {\n          console.log('findBalance: ' + JSON.stringify(res, null, 2));\n        })\n    },\n    opts,\n    \"currencyCloud.balances.find\"\n  );\n};\n```\n\n## On Behalf Of\nSome API calls can be executed on behalf of another user (e.g. someone who has a sub-account with the logged in user). For this sake, `onBehalfOf` field with a value of corresponding contact id should be added to a parameters object of a SDK function:\n```js\nvar currencyCloud = require('currency-cloud');\n\ncurrencyCloud.rates.get({\n  buyCurrency: 'SEK', \n  sellurrency: 'GBP', \n  fixedSide: 'buy',\n  amount: 1000.5,\n  onBehalfOf: '8f639ab2-2b85-4327-9eb1-01ee4f0c77bc'\n})\n.then(console.log);\n```\nAnother option is to run a bunch of API calls using `onBehalfOf(id, promise)` method; it expects contact id and a promise as parameters and returns the given promise resolved:\n```js\nvar currencyCloud = require('currency-cloud');\n\ncurrencyCloud.onBehalfOf('8f639ab2-2b85-4327-9eb1-01ee4f0c77bc', function() {\n  var beneficiary = {\n    ...\n  };\n  var conversion = {\n    ...\n  };\n  var payment = {\n    ...\n  };\n\n  return currencyCloud.beneficiaries.create(beneficiary)\n  .then(function(res) {\n    payment.beneficiaryId = res.id;\n  })\n  .then(function() {\n    return currencyCloud.conversions.create(conversion);\n  })\n  .then(function(res) {\n    payment.conversionId = res.id\n  })\n  .then(function() {\n    return currencyCloud.payments.create(payment);\n  });\n})\n.then(console.log);\n```\n## Errors\nIf an API call fails, the SDK function returns rejected promise with the error wrapped into `APIerror` class object. More specifically, it's an object of one of the classes, inheriting from `APIerror` and representing different types of errors. Apart from standard serialization methods they expose `toYAML()` method, which converts error object to human-readable YAML string:\n```js\nvar currencyCloud = require('currency-cloud');\n\ncurrencyCloud.balances.get({\n  currency: 'XYZ'\n})\n.catch(function(err) {\n  // the error might be not of APIerror type (e.g connection error)\n  if(err instanceof currencyCloud.APIerror) {\n    console.log(err.toYAML());\n  } \n  else {\n    console.log(err);\n  }  \n});\n\n/* outputs\nBadRequestError\n---\nplatform: node v4.1.1\nrequest:\n  parameters: {}\n  verb: GET\n  url: https://devapi.currencycloud.com/v2/balances/XYZ\nresponse:\n  statusCode: 400\n  date: Mon, 09 Nov 2017 15:06:11 GMT\n  requestId: 2914269054259094430\nerrors:\n- field: currency\n  code: currency_is_in_invalid_format\n  message: currency is not a valid ISO 4217 currency code\n  params:\n    type: currency\n*/\n```\n\n# Development\n\n## Dependencies\n* [combined-stream][combined-stream]\n* [request][request]\n* [request-promise][request-promise]\n* [retry][retry]\n* [uuid][uuid]\n\n## Contributing\n**We welcome pull requests from everyone!** Please see [CONTRIBUTING][contr]\n\nOur sincere thanks for [helping us][hof] create the best API for moving money anywhere around the world!\n\n## Versioning\nThis project uses [semantic versioning][semver]. You can safely express a dependency on a major version and expect all minor and patch versions to be backwards compatible.\n\n## Deprecation Policy\nTechnology evolves quickly and we are always looking for better ways to serve our customers. From time to time we need to make room for innovation by removing sections of code that are no longer necessary. We understand this can be disruptive and consequently we have designed a Deprecation Policy that protects our customers' investment and that allows us to take advantage of modern tools, frameworks and practices in developing software.\n\nDeprecation means that we discourage the use of a feature, design or practice because it has been superseded or is no longer considered efficient or safe but instead of removing it immediately, we mark it as **@deprecated** to provide backwards compatibility and time for you to update your projects. While the deprecated feature remains in the SDK for a period of time, we advise that you replace it with the recommended alternative which is explained in the relevant section of the code.\n\nWe remove deprecated features after **three months** from the time of announcement.\n\nThe security of our customers' assets is of paramount importance to us and sometimes we have to deprecate features because they may pose a security threat or because new, more secure, ways are available. On such occasions we reserve the right to set a different deprecation period which may range from **immediate removal** to the standard **three months**. \n\nOnce a feature has been marked as deprecated, we no longer develop the code or implement bug fixes. We only do security fixes.\n\n### List of features being deprecated\n```\n(No features are currently being deprecated)\n```\n\n# Support\nWe actively support the latest version of the SDK. We support the immediate previous version on best-efforts basis. All other versions are no longer supported nor maintained.\n\n# Testing\nTesting of the SDK relies on the [Mocha][mocha] test framework, [Chai][chai] assertions library and [Nock][nock] HTTP mocking and expectations library. To run all test cases simply execute:\n``` sh\n$ npm run test\n```\nThe SDK includes valid mocked HTTP responses in `./test/api/fixtures`. If you would like to test against the live API, please ensure there are no `js` files in that folder. The Nock library will regenerate them by recording the responses from the live run and use those next time the tests are executed.\n\nIMPORTANT: Remember to change the `loginId` and `apiKey` properties in `./test/mocks.js` to use your login ID and API key.\n\nIf you don't have a valid login or key, you can get them [here][registration]\n\n# Copyright\nCopyright  &copy; 2015-2020 Currencycloud. See [LICENSE][license] for details.\nCopyright &copy; modifications 2020, Ed Addario\n\n[introduction]:    https://developer.currencycloud.com/documentation/getting-started/introduction\n[original]:        https://github.com/CurrencyCloud/currencycloud-js\n[overview]:        https://developer.currencycloud.com/documentation/api-docs/overview/\n[examples]:        examples\n[request-promise]: https://www.npmjs.com/package/request-promise\n[combined-stream]: https://www.npmjs.com/package/combined-stream\n[request]:         https://www.npmjs.com/package/request\n[semver]:          http://semver.org/\n[mocha]:           https://mochajs.org/\n[chai]:            http://chaijs.com/\n[nock]:            https://github.com/node-nock/nock\n[registration]:    https://developer.currencycloud.com/api-register/\n[license]:         LICENSE.md\n[contr]:           CONTRIBUTING.md\n[hof]:             HALL_OF_FAME.md\n[retry]:          https://www.npmjs.com/package/retry\n[uuid]:           https://www.npmjs.com/package/uuid\n[gitpack]:        https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages\n","readmeFilename":"README.md"}