{"_id":"@andrevantunes/fetch-hmac","_rev":"1-4f722490ab58a4a43eb305bf5fbc2fa1","name":"@andrevantunes/fetch-hmac","dist-tags":{"latest":"2.4.10"},"versions":{"2.4.9":{"name":"@andrevantunes/fetch-hmac","version":"2.4.9","keywords":["Me Salva!","HMAC","fetch","JSON","API"],"author":{"name":"Andre Antunes Vieira"},"license":"ISC","_id":"@andrevantunes/fetch-hmac@2.4.9","maintainers":[{"name":"andrevantunes","email":"andreantunesv@gmail.com"}],"dist":{"shasum":"26eb7ee1ed032957e0ad41588dfcf7f26e2cce78","tarball":"https://registry.npmjs.org/@andrevantunes/fetch-hmac/-/fetch-hmac-2.4.9.tgz","fileCount":4,"integrity":"sha512-yGxd7jApdADXX6+wqXII17j9OLuCdz3pFlGFU8foKSbPjd6keHqLXE/4z2bfcksbDVpF8PiKuT+zTfVla7OFqw==","signatures":[{"sig":"MEUCIQDToEP5dzAuzgZjs9xOPvSpinTyH6Ua/HRefetI4B/+fgIgVFWZ2alJRHimNmp6l0g3S/4bBO5tZ+jKW4Qwnh26Se0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18774},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">= 16"},"gitHead":"caac506406e1d64cb58947f48a68c59ae5227c81","scripts":{"lint":"prettier --write \"{src,__tests__}/**/*.{ts,js}\"","test":"jest","build":"bin/build.sh","prepare":"yarn build","coverage":"jest --updateSnapshot --coverage","lint:check":"prettier -l \"{src,__tests__}/**/*.{ts,js}\"","test:watch":"jest --watch","build:export":"cp -r dist ../front-lps/node_modules/@mesalva/api","test:coverage":"jest --coverage --updateSnapshot"},"_npmUser":{"name":"andrevantunes","email":"andreantunesv@gmail.com"},"_npmVersion":"10.9.0","description":"Lib para realizar os requests para a API de qualquer aplicação javascript, implementando HMAC e Serializer","directories":{},"_nodeVersion":"20.16.0","dependencies":{"encoding":"0.1.13","crypto-js":"3.1.9-1","js-cookie":"^2.2.1","cross-fetch":"3.1.5","express-useragent":"1.0.8","jsonapi-serializer":"3.5.5"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.1","rollup":"^2.32.1","ts-jest":"^26.4.2","prettier":"^2.1.2","uglify-js":"^3.11.4","dts-bundle":"^0.7.3","typescript":"^4.0.3","@types/jest":"^26.0.15","@types/node":"^14.14.3","@types/crypto-js":"^4.0.1","@types/js-cookie":"^2.2.6","@types/jsonapi-serializer":"^3.6.3"},"_npmOperationalInternal":{"tmp":"tmp/fetch-hmac_2.4.9_1732750514145_0.27990881877077656","host":"s3://npm-registry-packages"}},"2.4.10":{"name":"@andrevantunes/fetch-hmac","version":"2.4.10","description":"Lib para realizar os requests para a API de qualquer aplicação javascript, implementando HMAC e Serializer","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"jest","test:coverage":"jest --coverage --updateSnapshot","test:watch":"jest --watch","coverage":"jest --updateSnapshot --coverage","build":"bin/build.sh","build:export":"cp -r dist ../front-lps/node_modules/@andrevantunes/fetch-hmac","lint":"prettier --write \"{src,__tests__}/**/*.{ts,js}\"","lint:check":"prettier -l \"{src,__tests__}/**/*.{ts,js}\"","prepare":"yarn build"},"license":"ISC","keywords":["Me Salva!","HMAC","fetch","JSON","API"],"author":{"name":"Andre Antunes Vieira"},"dependencies":{"cross-fetch":"3.1.5","crypto-js":"3.1.9-1","encoding":"0.1.13","express-useragent":"1.0.8","js-cookie":"^2.2.1","jsonapi-serializer":"3.5.5"},"devDependencies":{"@types/crypto-js":"^4.0.1","@types/jest":"^26.0.15","@types/js-cookie":"^2.2.6","@types/jsonapi-serializer":"^3.6.3","@types/node":"^14.14.3","dts-bundle":"^0.7.3","jest":"^26.6.1","prettier":"^2.1.2","rollup":"^2.32.1","ts-jest":"^26.4.2","typescript":"^4.0.3","uglify-js":"^3.11.4"},"engines":{"node":">= 16"},"publishConfig":{"access":"public"},"_id":"@andrevantunes/fetch-hmac@2.4.10","gitHead":"caac506406e1d64cb58947f48a68c59ae5227c81","_nodeVersion":"20.16.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-/TzjHZF6IU3bxFXhQO8OX8+rkFyxHz1CpUBC4jkD5OxJsaX4JOwRzKQtxX0tkVvoc1Y6rDqWujSZJrLZBlKR6Q==","shasum":"91abd09276289a0e4fa49e642bf478050b7aed73","tarball":"https://registry.npmjs.org/@andrevantunes/fetch-hmac/-/fetch-hmac-2.4.10.tgz","fileCount":4,"unpackedSize":18892,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDq8T5JTzx0k7uwwhZqtIulLNhxFxsQ35cF62x6PKQt3wIhAPfOK6W6ACqQS0BREbMGbIWUWBWA7ttIbV/BXgSWy5XY"}]},"_npmUser":{"name":"andrevantunes","email":"andreantunesv@gmail.com"},"directories":{},"maintainers":[{"name":"andrevantunes","email":"andreantunesv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetch-hmac_2.4.10_1732750789508_0.7029996036903081"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-27T23:35:14.053Z","modified":"2024-11-27T23:39:49.870Z","2.4.9":"2024-11-27T23:35:14.336Z","2.4.10":"2024-11-27T23:39:49.687Z"},"author":{"name":"Andre Antunes Vieira"},"license":"ISC","keywords":["Me Salva!","HMAC","fetch","JSON","API"],"description":"Lib para realizar os requests para a API de qualquer aplicação javascript, implementando HMAC e Serializer","maintainers":[{"name":"andrevantunes","email":"andreantunesv@gmail.com"}],"readme":"# npm package \"@andrevantunes/fetch-hmac\"\n\n[![npm version](https://badge.fury.io/js/%40mesalva%2Fapi.svg)](https://badge.fury.io/js/%40mesalva%2Fapi)\n[![Build Status](https://semaphoreci.com/api/v1/mesalva/js-api-request/branches/master/shields_badge.svg)](https://semaphoreci.com/mesalva/js-api-request)\n[![Maintainability](https://api.codeclimate.com/v1/badges/e0f21a4009a4f14e633d/maintainability)](https://codeclimate.com/repos/59ee40ab36611f02950005c3/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/e0f21a4009a4f14e633d/test_coverage)](https://codeclimate.com/repos/59ee40ab36611f02950005c3/test_coverage)\n\n## Introduction\n\nThis package is used by [Me Salva Engineering Team](https://mesalva.com) to make requests to Api,\nusing [HMAC authentication protocol](https://pt.wikipedia.org/wiki/HMAC) + [universal fetch](https://www.npmjs.com/package/universal-fetch) to make requests by\nserver side (we use [express](https://www.npmjs.com/package/express)) + \n[Json Api Serializer](https://www.npmjs.com/package/json-api-serializer) to parse the api [JSON API BASED](http://jsonapi.org)\nto simple Javascript [Camel Case](https://en.wikipedia.org/wiki/Camel_case) Based objects\n\n## Installation\n\n### yarn way\n\n```bash\nyarn add @andrevantunes/fetch-hmac\n```\n\n### npm way\n\n```bash\nnpm install --save @andrevantunes/fetch-hmac\n```\n\n## Configurations\n\n### .env file\n\nOn project root folder add a file called `.env.js` with the structure below:\n \n```js\nmodule.exports = {\n  API_HOST: 'https://API_HOST',\n  CLIENT: 'WEB|ANDROID|IOS|...',\n  HMAC_KEY: 'HMAC_KEY',\n}\n```\n\n## Usage\n\nCreating a model\n\n[./examples/ExampleModelA.js](https://github.com/mesalva/js-api-request/blob/doc/readme/examples/ExampleModelA.js)\n```js\nimport MSApiRequest from '@andrevantunes/fetch-hmac'\n\nconst ExampleA = new MSApiRequest('some_api_route')\n\nexport default ExampleA\n```\n\nThis model allow you to use the methods below:\n\n[./examples/ExampleUsage1.js](https://github.com/mesalva/js-api-request/blob/doc/readme/examples/ExampleUsage1.js)\n```js\nimport Example1 from './examples/ExampleModelA'\n\nExample1.request({\n  method: 'GET|POST|PUT|DELETE|PATCH', //default = GET\n  route: 'additional route', //default = GET\n  data: {...OBJECT_WITH_REQUEST_PARAMS}, //default = undefined\n  headers: {...OBJECT_WITH_ADDICTIONAL_HEADERS}, // default = undefined\n  only: 'data|headers|status|meta', // default = undefined\n}).then(response => {\n  console.log(response.data)\n  console.log(response.meta)\n  console.log(response.headers)\n  console.log(response.status)\n})\n```\n\n### Custom ENVS\n\nYou can pass some custom env vars on MsApiRequest initialization. This will allow to use two or more api accesses in the same project.\n\n```js\nimport MSApiRequest from '@andrevantunes/fetch-hmac'\n\nconst ExampleA = new MSApiRequest('some_api_route', {\n  API_HOST: 'https://some.another.host',\n  HMAC_KEY: 'SomeAnotherHmacKey'\n})\n\nexport default ExampleA\n```\n\n### Some alias\n\n[./examples/ExampleUsage2.js](https://github.com/mesalva/js-api-request/blob/doc/readme/examples/ExampleUsage2.js)\n```js\nimport Example2 from './examples/ExampleModelA'\n\nExample2.get().then(data => console.log(data))\n// will make a GET request to: https://api_host/some_api_route\n\n// is the same that:\nExample2.request({ method: 'GET', only: 'data' }).then(data => console.log(data))\n// or the same that:\nExample2.request({ method: 'GET' }).then(response => console.log(response.data))\n\n\nExample2.post({ data: {someField: 'someValue'}}).then(data => console.log(data))\n// is the same that:\nExample2.request({\n  method: 'POST',\n  only: 'data',\n  data: {someField: 'someValue'},\n}).then(data => console.log(data))\n// will make a POST request to: https://api_host/some_api_route, sending as payload  {\"someField\": \"someValue'}\n```\n\nThese are the valid alias: [ post, put, delete, get, patch ]\n\n\n### Explaining request params\n- method - Set request [HTTP method](https://developer.mozilla.org/pt-BR/docs/Web/HTTP/Methods), \nthe allow methods are: GET, POST, PUT, PATCH, DELETE.\n\n- data - For GET method, means that will add as a url [query string params](https://en.wikipedia.org/wiki/Query_string),\nto other methods send as payload in JSON hyphen-saparated format\n\n- headers - add headers to request. This lib will automatic add the headers below, so, this headers can't be overflowed.\n  - X-DATE - Some enviroments don't allow to send DATE header, so we send this header by security\n  - CLIENT - the same client provided on .env.js file\n  - CONTENT-TYPE - application/json\n  - PLATFORM - Send to api which platform is requesting\n  - DEVICE - Send to api which device is requesting\n  - USER-AGENT - Send to api the user-agent of the device that is requesting\n  - CONTENT-MD5 - Encrypted data, using HMAC KEY\n  - AUTHORIZATION - [HMAC authentication protocol](https://pt.wikipedia.org/wiki/HMAC) implementation created using the canonical string composed by: method + content type + Content-MD5 + pathname + date \n  \n  - UID - user authenticated uid (if is not guest user)\n  - ACCESS-TOKEN - user authenticated access-token (if is not guest user)\n  \n## Code Quality\nThe project have 100% test coverage and no lint issues! All master interactions must have the same code quality\n![Coverage](bin/coverage.png?raw=true \"Coverage And Lint Print\")\n\n\n\n","readmeFilename":"README.md"}