Repository: stripe/stripe-node
Pull request #664 (2019-07-26 23:29:27)

Expose and use `once`
Fixes a misspelling in EventEmitter property declaration, exposes `once` method and uses `once` where it's more appropriate than `on`


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 96fa3a40..fcf72bb1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,26 +1,38 @@
 # CHANGELOG
 
+## 7.5.1 - 2019-07-30
+
+- [#662](https://github.com/stripe/stripe-node/pull/662) Remove `safe-buffer` dependency
+- [#666](https://github.com/stripe/stripe-node/pull/666) Bump lodash from 4.17.11 to 4.17.15
+- [#668](https://github.com/stripe/stripe-node/pull/668) Move Balance History to /v1/balance_transactions
+
 ## 7.5.0 - 2019-07-24
-* [#660](https://github.com/stripe/stripe-node/pull/660) Interpret any string in args as API Key instead of a regex
+
+- [#660](https://github.com/stripe/stripe-node/pull/660) Interpret any string in args as API Key instead of a regex
   - ⚠️ Careful: passing strings which are not API Keys as as the final argument to a request previously would have ignored those strings, and would now result in the request failing with an authentication error.
   - ⚠️ Careful: The private api `utils.isAuthKey` was removed.
-* [#658](https://github.com/stripe/stripe-node/pull/658) Update README retry code sample to use two retries
-* [#653](https://github.com/stripe/stripe-node/pull/653) Reorder customer methods
+- [#658](https://github.com/stripe/stripe-node/pull/658) Update README retry code sample to use two retries
+- [#653](https://github.com/stripe/stripe-node/pull/653) Reorder customer methods
 
 ## 7.4.0 - 2019-06-27
-* [#652](https://github.com/stripe/stripe-node/pull/652) Add support for the `SetupIntent` resource and APIs
+
+- [#652](https://github.com/stripe/stripe-node/pull/652) Add support for the `SetupIntent` resource and APIs
 
 ## 7.3.0 - 2019-06-24
-* [#649](https://github.com/stripe/stripe-node/pull/649) Enable request latency telemetry by default
+
+- [#649](https://github.com/stripe/stripe-node/pull/649) Enable request latency telemetry by default
 
 ## 7.2.0 - 2019-06-17
-* [#608](https://github.com/stripe/stripe-node/pull/608) Add support for `CustomerBalanceTransaction` resource and APIs
+
+- [#608](https://github.com/stripe/stripe-node/pull/608) Add support for `CustomerBalanceTransaction` resource and APIs
 
 ## 7.1.0 - 2019-05-23
-* [#632](https://github.com/stripe/stripe-node/pull/632) Add support for `radar.early_fraud_warning` resource
+
+- [#632](https://github.com/stripe/stripe-node/pull/632) Add support for `radar.early_fraud_warning` resource
 
 ## 7.0.1 - 2019-05-22
-* [#631](https://github.com/stripe/stripe-node/pull/631) Make autopagination functions work for `listLineItems` and `listUpcomingLineItems`
+
+- [#631](https://github.com/stripe/stripe-node/pull/631) Make autopagination functions work for `listLineItems` and `listUpcomingLineItems`
 
 ## 7.0.0 - 2019-05-14
 
diff --git a/VERSION b/VERSION
index 18bb4182..a5f017a0 100644
--- a/VERSION
+++ b/VERSION
@@ -1,1 +1,1 @@
-7.5.0
+7.5.1
diff --git a/lib/StripeResource.js b/lib/StripeResource.js
index 6bc17dd3..2deaf167 100644
--- a/lib/StripeResource.js
+++ b/lib/StripeResource.js
@@ -113,7 +113,7 @@ StripeResource.prototype = {
       res.on('data', (chunk) => {
         response += chunk;
       });
-      res.on('end', () => {
+      res.once('end', () => {
         const headers = res.headers || {};
         // NOTE: Stripe responds with lowercase header names/keys.
 
@@ -365,7 +365,7 @@ StripeResource.prototype = {
 
       req.setTimeout(timeout, this._timeoutHandler(timeout, req, callback));
 
-      req.on('response', (res) => {
+      req.once('response', (res) => {
         if (this._shouldRetry(res, requestRetries)) {
           return retryRequest(makeRequest, apiVersion, headers, requestRetries);
         } else {
@@ -381,13 +381,16 @@ StripeResource.prototype = {
         }
       });
 
-      req.on('socket', (socket) => {
+      req.once('socket', (socket) => {
         if (socket.connecting) {
-          socket.on(isInsecureConnection ? 'connect' : 'secureConnect', () => {
-            // Send payload; we're safe:
-            req.write(requestData);
-            req.end();
-          });
+          socket.once(
+            isInsecureConnection ? 'connect' : 'secureConnect',
+            () => {
+              // Send payload; we're safe:
+              req.write(requestData);
+              req.end();
+            }
+          );
         } else {
           // we're already connected
           req.write(requestData);
diff --git a/lib/resources/BalanceTransactions.js b/lib/resources/BalanceTransactions.js
index 3e3a6c7d..cad69117 100644
--- a/lib/resources/BalanceTransactions.js
+++ b/lib/resources/BalanceTransactions.js
@@ -3,7 +3,7 @@
 const StripeResource = require('../StripeResource');
 
 module.exports = StripeResource.extend({
-  path: 'balance/history',
+  path: 'balance_transactions',
 
   includeBasic: ['list', 'retrieve'],
 });
diff --git a/lib/resources/Files.js b/lib/resources/Files.js
index d2541b8e..518120a5 100644
--- a/lib/resources/Files.js
+++ b/lib/resources/Files.js
@@ -36,7 +36,7 @@ module.exports = StripeResource.extend({
         .on('data', (line) => {
           bufferArray.push(line);
         })
-        .on('end', () => {
+        .once('end', () => {
           const bufferData = Object.assign({}, data);
           bufferData.file.data = Buffer.concat(bufferArray);
           const buffer = fn(method, bufferData, headers);
diff --git a/lib/stripe.js b/lib/stripe.js
index 9a467d3a..5e9e7e5c 100644
--- a/lib/stripe.js
+++ b/lib/stripe.js
@@ -43,10 +43,11 @@ function Stripe(key, version) {
     value: new EventEmitter(),
     enumerable: false,
     configurable: false,
-    writeable: false,
+    writable: false,
   });
 
   this.on = this._emitter.on.bind(this._emitter);
+  this.once = this._emitter.once.bind(this._emitter);
   this.off = this._emitter.removeListener.bind(this._emitter);
 
   this._api = {
diff --git a/package.json b/package.json
index d63c89f4..65e5cf47 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "stripe",
-  "version": "7.5.0",
+  "version": "7.5.1",
   "description": "Stripe API wrapper",
   "keywords": [
     "stripe",
diff --git a/yarn.lock b/yarn.lock
index de84b5f9..015a6eb3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1253,9 +1253,9 @@ lodash.isplainobject@^4.0.6:
   integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=
 
 lodash@^4.17.11, lodash@^4.17.5:
-  version "4.17.11"
-  resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
-  integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
+  version "4.17.15"
+  resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
+  integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
 
 log-driver@^1.2.7:
   version "1.2.7"


Test patch:
diff --git a/test/flows.spec.js b/test/flows.spec.js
index 28a98be4..65d70f45 100644
--- a/test/flows.spec.js
+++ b/test/flows.spec.js
@@ -326,8 +326,6 @@ describe('Flows', function() {
         .slice(2);
 
       function onRequest(request) {
-        stripe.off('request', onRequest);
-
         expect(request).to.eql({
           api_version: 'latest',
           idempotency_key: idempotencyKey,
@@ -339,7 +337,7 @@ describe('Flows', function() {
         done();
       }
 
-      stripe.on('request', onRequest);
+      stripe.once('request', onRequest);
 
       stripe.charges
         .create(
@@ -411,7 +409,7 @@ describe('Flows', function() {
         done(new Error('How did you get here?'));
       }
 
-      stripe.on('response', onResponse);
+      stripe.once('response', onResponse);
       stripe.off('response', onResponse);
 
       stripe.charges
diff --git a/test/resources/BalanceTransactions.spec.js b/test/resources/BalanceTransactions.spec.js
index 72ede8cc..05b569ba 100644
--- a/test/resources/BalanceTransactions.spec.js
+++ b/test/resources/BalanceTransactions.spec.js
@@ -9,7 +9,7 @@ describe('BalanceTransactions Resource', function() {
       stripe.balanceTransactions.retrieve('txn_123');
       expect(stripe.LAST_REQUEST).to.deep.equal({
         method: 'GET',
-        url: '/v1/balance/history/txn_123',
+        url: '/v1/balance_transactions/txn_123',
         headers: {},
         data: {},
       });
@@ -21,7 +21,7 @@ describe('BalanceTransactions Resource', function() {
       stripe.balanceTransactions.list();
       expect(stripe.LAST_REQUEST).to.deep.equal({
         method: 'GET',
-        url: '/v1/balance/history',
+        url: '/v1/balance_transactions',
         headers: {},
         data: {},
       });