pitney-bowes
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -9,5 +9,9 @@ # Changelog | ||
## [0.3.1] - 2021-08-13 | ||
### Added | ||
- Added support for creating manifests: https://shipping.pitneybowes.com/api/post-manifests.html | ||
## [0.3.0] - 2021-07-31 | ||
### Changed | ||
- Changed the default base URL for the sandbox environment to match https://shipping.pitneybowes.com/overview.html#sandbox-environment | ||
- Changed the way OAuth tokens are cached so that they vary by environment. | ||
- Changed the way OAuth tokens are cached so they vary by environment. |
34
index.js
@@ -55,2 +55,36 @@ const cache = require('memory-cache'); | ||
this.createManifest = function(manifest, _options, callback) { | ||
this.getOAuthToken(function(err, oAuthToken) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
const req = { | ||
auth: { | ||
bearer: oAuthToken.access_token | ||
}, | ||
headers: {}, | ||
json: manifest, | ||
method: 'POST', | ||
url: `${options.baseUrl}/v1/manifests` | ||
}; | ||
if (_options.transactionId) { | ||
req.headers['X-PB-TransactionId'] = _options.transactionId; | ||
} | ||
request(req, function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (res.statusCode !== 201) { | ||
return callback(createError(res.statusCode, body && body.length && body[0].message ? body[0] : body)); | ||
} | ||
callback(null, body); | ||
}); | ||
}); | ||
}; | ||
this.getOAuthToken = function(callback) { | ||
@@ -57,0 +91,0 @@ const url = `${options.baseUrl.replace('/shippingservices', '')}/oauth/token`; |
@@ -30,3 +30,3 @@ { | ||
}, | ||
"version": "0.3.0" | ||
"version": "0.3.1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24274
191
5