diff --git a/lib/StripeResource.js b/lib/StripeResource.js index cb25c7eade..1cf9e9932e 100644 --- a/lib/StripeResource.js +++ b/lib/StripeResource.js @@ -3,7 +3,6 @@ const http = require('http'); const https = require('https'); const path = require('path'); -const uuid = require('uuid/v4'); const utils = require('./utils'); const Error = require('./Error'); @@ -265,7 +264,7 @@ StripeResource.prototype = { _defaultIdempotencyKey(method) { // If this is a POST and we allow multiple retries, ensure an idempotency key. if (method === 'POST' && this._stripe.getMaxNetworkRetries() > 0) { - return uuid(); + return `stripe-node-retry-${utils.uuid4()}`; } return null; }, diff --git a/lib/utils.js b/lib/utils.js index f62c7e83eb..4489ef15c6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -341,6 +341,17 @@ const utils = (module.exports = { return result; }, + + /** + * https://stackoverflow.com/a/2117523 + */ + uuid4: () => { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0; + const v = c === 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); + }, }); function emitWarning(warning) { diff --git a/package.json b/package.json index b7a4c61271..89559056b3 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,7 @@ }, "dependencies": { "lodash.isplainobject": "^4.0.6", - "qs": "^6.6.0", - "uuid": "^3.3.2" + "qs": "^6.6.0" }, "license": "MIT", "scripts": { diff --git a/test/StripeResource.spec.js b/test/StripeResource.spec.js index 94dadc8681..6aea57b87d 100644 --- a/test/StripeResource.spec.js +++ b/test/StripeResource.spec.js @@ -1,7 +1,6 @@ 'use strict'; const utils = require('../testUtils'); -const uuid = require('uuid/v4'); const nock = require('nock'); @@ -357,7 +356,7 @@ describe('StripeResource', () => { }); it('should reuse the given idempotency key provided for retries', (done) => { - const key = uuid(); + const key = 'i-am-a-key'; let headers; nock(`https://${options.host}`)