1.1.0 • Published 3 years ago

wmt-marketplace-auth-canada v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

wmt-marketplace-auth-canada

npm license github-issues

Generate the authentication headers required by Walmart Marketplace API.

nodei.co

stars forks

npm.io npm.io

Features

  • Returns the required authentication headers including the digital signature.
  • Defaults the Accept and Content-Type headers to application/json, which can be changed to application/xml if XML is preferred.
  • Generates a UUID for the CorrelationId if one is not specified for the request.
  • Timestamp can be directly set or default to current time.

Typical Usage

Set the custom headers, then use Authenticate.sign() for the specified request.

import { Authenticate } from 'wmt-marketplace-auth-canada';

let headers = new Authenticate.Custom;
headers.setCorrelationId('1234hfvgtr');
headers.setConsumer({
    Channel: { Type: '38b7eb6c-3672-4022-93a2-f47794f36338' },
    ConsumerId: 'f091ae58-774c-45ff-9d8a-e30a83344e42'
});

let request = {
  RequestUrl: 'https://marketplace.walmartapis.com/v3/feeds',
  PrivateKey: 'MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8A...',
  RequestMethod: 'GET'
}

let signedHeaders = Authenticate.sign(headers, request);

Outputs Authentication headers as an object.

{
  "WM_SVC.NAME": "Walmart Marketplace",
  "WM_QOS.CORRELATION_ID": "1234hfvgtr",
  "WM_SEC.TIMESTAMP": 1523287838530,
  "WM_SEC.AUTH_SIGNATURE": "E1EPWiqwuLYceSVr2XGmljo7qq1+EDI5++1XvFcVf+/klas+mLMAJbDihfAwkjyDxi3WkJDdTCNfle0O+4V/9g==",
  "WM_CONSUMER.CHANNEL.TYPE": "38b7eb6c-3672-4022-93a2-f47794f36338",
  "WM_CONSUMER.ID": "f091ae58-774c-45ff-9d8a-e30a83344e42",
  "Accept": "application/json",
  "Content-Type": "application/json"
}

Options

Change the Accept or Content-Type headers from JSON to XML.

headers.Accept = 'application/xml';
headers.ContentType = 'application/xml';

Set a custom timestamp.

headers.setTimestamp(1523287838530);

Install

npm install --save wmt-marketplace-auth-canada

Scripts

  • npm run build : rimraf ./lib/ && tsc -p .
  • npm run readme : rm ./README.md && node ./node_modules/.bin/node-readme
  • npm run package : npm run build && npm run readme
  • npm run test : mocha --require ts-node/register $(find ./test/ -name "*.spec.ts")

Dependencies

PackageVersionDev
uuid3.2.1
ts-node5.0.1
typescript2.8.1
tslint5.9.1
mocha5.0.5
chai4.1.2
nyc11.6.0
rimraf2.6.2
@types/mocha5.0.0
@types/chai4.1.2
@types/node9.6.2
@types/uuid3.4.3
node-readme0.1.9

Contributing

We are always excited when we can make our projects open source and allow contributors to build and work on these components. To make this possible, there are a few things we kindly ask all contributors to understand and follow. Please review the Contributing Guide.

Author

Kane McConnell kane@makanal.eu

License