Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: swellstores/swell-node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.1
Choose a base ref
...
head repository: swellstores/swell-node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.2
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 14, 2023

  1. Revert "Fix: handle promise rejection in auth stage (#26)"

    This reverts commit 1842398.
    swellmike committed Nov 14, 2023
    Copy the full SHA
    c4efa51 View commit details
  2. 5.4.2

    swellmike committed Nov 14, 2023
    Copy the full SHA
    acca672 View commit details
Showing with 21 additions and 30 deletions.
  1. +18 −27 lib/client.js
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
45 changes: 18 additions & 27 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -263,7 +263,7 @@ class Client extends EventEmitter {
*/
get(url, data, callback) {
if (!url) {
return Promise.reject(new Error('url is required'));
throw new Error('url is required');
}

if (typeof data === 'function') {
@@ -277,8 +277,10 @@ class Client extends EventEmitter {
}

if (!this.authed) {
// If not connected, do auth to get updated versions first
return this.getPendingAuth(url, data, callback);
return new Promise((resolve) => {
// If not connected, do auth to get updated versions first
this.getPendingAuth(url, data, callback, resolve);
});
}

// Indicates whether to check the request cache or not
@@ -299,33 +301,22 @@ class Client extends EventEmitter {
return this.request('get', url, data, callback);
}

getPendingAuth(url, data, callback) {
return new Promise((resolve, reject) => {
if (this.requestsPendingAuth) {
this.requestsPendingAuth.push({ url, data, callback, resolve });
return;
}

this.requestsPendingAuth = [];

this.authWithKey(() => {
this.get(url, data, (err, result, headers) => {
if (typeof callback === 'function') {
callback(err, result, headers);
}
getPendingAuth(url, data, callback, resolve) {
if (this.requestsPendingAuth) {
this.requestsPendingAuth.push({ url, data, callback, resolve });
return;
}

if (err) {
reject(err);
return;
}
this.requestsPendingAuth = [];

resolve(result);
})
.catch((err) => {
reject(err.message);
});
this.authWithKey(() => {
this.get(url, data, (_err, result, headers) => {
if (callback) {
callback(null, result, headers);
}
resolve(result);
});
}).then(() => {

this.flushRequestsPendingAuth();
});
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swell-node",
"version": "5.4.1",
"version": "5.4.2",
"description": "Swell API library for NodeJS",
"engines": {
"node": ">=14.19.1",