Skip to content

Commit

Permalink
NXJS-153: follow updated eslint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
troger committed Aug 14, 2018
1 parent c5a16ea commit c30d10d
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 75 deletions.
16 changes: 8 additions & 8 deletions lib/auth/oauth2.js
Expand Up @@ -12,14 +12,14 @@ const fetchAccessToken = (baseURL, body) => {
body: qs.stringify(body),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})
.then((res) => res.json())
.then((token) => {
if (token.error) {
return reject(token.error);
}
return resolve(token);
})
.catch((e) => reject(e))
.then((res) => res.json())
.then((token) => {
if (token.error) {
return reject(token.error);
}
return resolve(token);
})
.catch((e) => reject(e))
));
};

Expand Down
2 changes: 1 addition & 1 deletion lib/base.js
Expand Up @@ -236,7 +236,7 @@ class Base {
return this;
}

/**
/**
* Computes a full options object from an optional `opts` object and the ones from this object.
* `schemas`, `enrichers`, `fetchProperties` and `headers` are not merged but the ones from the `opts` object
* override the ones from this object.
Expand Down
2 changes: 1 addition & 1 deletion lib/deps/fetch-browser.js
@@ -1,3 +1,3 @@
require('whatwg-fetch');
/* eslint no-undef: 0 */
/* eslint no-undef: 0, no-restricted-globals: 0 */
module.exports = self.fetch.bind(self);
2 changes: 1 addition & 1 deletion lib/deps/fetch-react-native.js
@@ -1,3 +1,3 @@
/* eslint no-undef: 0 */
/* eslint no-undef: 0, no-restricted-globals: 0 */
const globalObject = typeof self === 'undefined' ? global : self;
module.exports = globalObject.fetch.bind(globalObject);
2 changes: 1 addition & 1 deletion lib/deps/utils/base64.js
@@ -1,7 +1,7 @@
const Buffer = require('./buffer');

function btoa(str) {
return new Buffer(str).toString('base64');
return Buffer.from(str).toString('base64');
}

module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions lib/document.js
Expand Up @@ -241,7 +241,7 @@ class Document extends Base {
* @returns {Promise} A promise object resolved with the rendition definitions.
*/
fetchRenditions(opts = {}) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (this.contextParameters && this.contextParameters.renditions) {
return Promise.resolve(this.contextParameters.renditions);
}
Expand Down Expand Up @@ -278,7 +278,7 @@ class Document extends Base {
* @returns {Promise} A promise object resolved with the ACLs.
*/
fetchACLs(opts = {}) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (this.contextParameters && this.contextParameters.acls) {
return Promise.resolve(this.contextParameters.acls);
}
Expand All @@ -304,7 +304,7 @@ class Document extends Base {
* @returns {Promise} A promise object resolved with true or false.
*/
hasPermission(name, opts = {}) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (this.contextParameters && this.contextParameters.permissions) {
return Promise.resolve(this.contextParameters.permissions.indexOf(name) !== -1);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/nuxeo.js
@@ -1,4 +1,6 @@
const extend = require('extend');
const qs = require('querystring');

const Base = require('./base');
const ServerVersion = require('./server-version');
const Operation = require('./operation');
Expand All @@ -11,7 +13,6 @@ const Directory = require('./directory/directory');
const Workflows = require('./workflow/workflows');
const join = require('./deps/utils/join');
const Promise = require('./deps/promise');
const qs = require('querystring');
const FormData = require('./deps/form-data');
const Authentication = require('./auth/auth');
const Unmarshallers = require('./unmarshallers/unmarshallers');
Expand Down Expand Up @@ -254,7 +255,7 @@ class Nuxeo extends Base {

_computeTimeouts(options) {
const transactionTimeout = options.transactionTimeout || options.timeout;
let httpTimeout = options.httpTimeout;
let { httpTimeout } = options;
if (!httpTimeout && transactionTimeout) {
// make the http timeout a bit longer than the transaction timeout
httpTimeout = 5 + transactionTimeout;
Expand Down
15 changes: 10 additions & 5 deletions lib/operation.js
Expand Up @@ -130,18 +130,19 @@ class Operation extends Base {
}

_computeRequestURL() {
const input = this._automationParams.input;
const { input } = this._automationParams;
if (input instanceof BatchBlob) {
return join(this._nuxeo._restURL, 'upload', input['upload-batch'], input['upload-fileId'], 'execute', this._id);
} else if (input instanceof BatchUpload) {
}
if (input instanceof BatchUpload) {
return join(this._nuxeo._restURL, 'upload', input._batchId, 'execute', this._id);
}

return join(this._url, encodePath(this._id));
}

_computeRequestBody() {
const input = this._automationParams.input;
const { input } = this._automationParams;
if (this._isBatchInput(input)) {
// no input needed
const body = extend(true, {}, this._automationParams);
Expand All @@ -157,11 +158,15 @@ class Operation extends Base {
const docs = input.map((doc) => doc.uid);
this._automationParams.input = `docs:${docs.join(',')}`;
return this._automationParams;
} else if (typeof first === 'string') {
}

if (typeof first === 'string') {
// assume ref list
this._automationParams.input = `docs:${input.join(',')}`;
return this._automationParams;
} else if (first instanceof Blob) {
}

if (first instanceof Blob) {
// blob list => multipart
const automationParams = {
params: this._automationParams.params,
Expand Down
2 changes: 1 addition & 1 deletion lib/repository.js
Expand Up @@ -136,7 +136,7 @@ class Repository extends Base {
}

_computeQueryPath(queryOpts) {
const serverVersion = this._nuxeo.serverVersion;
const { serverVersion } = this._nuxeo;
const isSearchEndPoint = serverVersion && serverVersion.gte(LTS_2016);
const path = isSearchEndPoint
? join('search', queryOpts.query ? 'lang/NXQL' : `pp/${queryOpts.pageProvider}`, 'execute')
Expand Down
2 changes: 1 addition & 1 deletion lib/request.js
Expand Up @@ -121,7 +121,7 @@ class Request extends Base {
const options = this._computeOptions(opts);

let path = this._path;
const repositoryName = options.repositoryName;
const { repositoryName } = options;
if (repositoryName !== undefined) {
path = join('repo', repositoryName, path);
}
Expand Down
1 change: 0 additions & 1 deletion lib/server-version.js
Expand Up @@ -11,7 +11,6 @@ const SERVER_VERSION_PATTERN = /(\d+)\.(\d+)(?:-HF(\d+))?/;
* - '9.10-20180101_1212' is considered equals to '9.10'
*/
class ServerVersion {

constructor(version) {
const match = version.match(SERVER_VERSION_PATTERN);
if (!match) {
Expand Down
17 changes: 9 additions & 8 deletions lib/upload/batch.js
@@ -1,8 +1,9 @@
const extend = require('extend');
const Queue = require('promise-queue');

const Base = require('../base');
const join = require('../deps/utils/join');
const flatten = require('../deps/utils/flatten');
const Queue = require('promise-queue');
const BatchBlob = require('./blob');

const DEFAULT_OPTS = {
Expand Down Expand Up @@ -86,7 +87,7 @@ class BatchUpload extends Base {
return promises[0];
}

const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
return Promise.all(promises).then((batchBlobs) => {
return {
blobs: batchBlobs.map((batchBlob) => batchBlob.blob),
Expand Down Expand Up @@ -134,7 +135,7 @@ class BatchUpload extends Base {
url: this._url,
};

const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (this._batchId) {
return Promise.resolve(this);
}
Expand Down Expand Up @@ -166,7 +167,7 @@ class BatchUpload extends Base {
* });
*/
done() {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
return Promise.all(this._promises).then((batchBlobs) => {
return {
blobs: batchBlobs.map((batchBlob) => batchBlob.blob),
Expand All @@ -188,7 +189,7 @@ class BatchUpload extends Base {
* @returns {Promise} A Promise object resolved with the BatchUpload itself.
*/
cancel(opts) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (!this._batchIdPromise) {
return Promise.resolve(this);
}
Expand All @@ -210,7 +211,7 @@ class BatchUpload extends Base {
* @returns {Promise} A Promise object resolved with the BatchUpload itself and the BatchBlob.
*/
fetchBlob(index, opts = {}) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (!this._batchId) {
return Promise.reject(new Error('No \'batchId\' set'));
}
Expand All @@ -236,7 +237,7 @@ class BatchUpload extends Base {
* @returns {Promise} A Promise object resolved with the result of the DELETE request.
*/
removeBlob(index, opts = {}) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (!this._batchId) {
return Promise.reject(new Error('No \'batchId\' set'));
}
Expand All @@ -255,7 +256,7 @@ class BatchUpload extends Base {
* @returns {Promise} A Promise object resolved with the BatchUpload itself and the BatchBlobs.
*/
fetchBlobs(opts = {}) {
const Promise = this._nuxeo.Promise;
const { Promise } = this._nuxeo;
if (!this._batchId) {
return Promise.reject(new Error('No \'batchId\' set'));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/workflow/workflows.js
Expand Up @@ -74,7 +74,7 @@ class Workflows extends Base {
.get(options);
}

/**
/**
* Deletes a workflow instance given a workflow instance id.
* @param {string} workflowInstanceId - The workflow instance id.
* @param {object} [opts] - Options overriding the ones from this object.
Expand Down
23 changes: 11 additions & 12 deletions test/document.spec.js
Expand Up @@ -103,8 +103,7 @@ describe('Document', () => {
properties: {
'dc:title': 'collection',
},
})
.then((doc) => {
}).then((doc) => {
expect(doc.isCollection()).to.be.true();
})
));
Expand Down Expand Up @@ -621,16 +620,16 @@ describe('Document', () => {
return new Nuxeo.Promise((resolve, reject) => {
function poll() {
sleep(1000)
.then(() => doc.fetchAudit())
.then((res) => {
if (res.entries.length > 0) {
resolve(res);
} else {
// let's try again
poll();
}
})
.catch((err) => reject(err));
.then(() => doc.fetchAudit())
.then((res) => {
if (res.entries.length > 0) {
resolve(res);
} else {
// let's try again
poll();
}
})
.catch((err) => reject(err));
}
poll();
});
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/setup-logging.js
@@ -1,12 +1,12 @@
(() => {
const getParentTitles = (currentTest) => {
const titles = [];
let parent = currentTest.parent;
let { parent } = currentTest;
while (parent) {
if (typeof parent.title === 'string' && parent.title.trim().length > 0) {
titles.push(parent.title.trim());
}
parent = parent.parent;
({ parent } = parent);
}
return titles.reverse();
};
Expand Down
4 changes: 3 additions & 1 deletion test/helpers/setup-node-es5.js
@@ -1,7 +1,9 @@
/* eslint import/no-unresolved: 0 */
const Nuxeo = require('../../dist/es5');
const chai = require('chai');

const Nuxeo = require('../../dist/es5');


global.Nuxeo = Nuxeo;
global.expect = chai.expect;
global.isBrowser = false;
3 changes: 2 additions & 1 deletion test/helpers/setup-node.js
@@ -1,6 +1,7 @@
const Nuxeo = require('../..');
const chai = require('chai');

const Nuxeo = require('../..');

global.Nuxeo = Nuxeo;
global.expect = chai.expect;
global.isBrowser = false;
1 change: 1 addition & 0 deletions test/multi-repository.spec.js
@@ -1,3 +1,4 @@
/* eslint function-paren-newline: 0 */
const OTHER_DOC_NAME = 'foo';
const OTHER_DOC_PATH = '/foo';

Expand Down
2 changes: 1 addition & 1 deletion test/nuxeo.spec.js
Expand Up @@ -88,7 +88,7 @@ describe('Nuxeo', () => {
expect(n.connected).to.be.true();
expect(nuxeo.connected).to.be.true();

const user = n.user;
const { user } = n;
expect(user['entity-type']).to.be.equal('user');
expect(user.id).to.be.equal('Administrator');
expect(user.properties.username).to.be.equal('Administrator');
Expand Down
24 changes: 12 additions & 12 deletions test/oauth2.spec.js
Expand Up @@ -35,12 +35,12 @@ describe('OAuth2 spec', () => {
.then((entry) => { oauth2Client = entry; });
});

after(() => (
nuxeo.directory(OAUTH2_CLIENTS_DIRECTORY_NAME).delete(oauth2Client.properties.id)
.then(() => nuxeo.directory(OAUTH2_TOKENS_DIRECTORY_NAME).fetchAll())
.then(({ entries }) =>
Promise.all(entries.map((entry) => nuxeo.directory(OAUTH2_TOKENS_DIRECTORY_NAME).delete(entry.properties.id))))
));
after(() => {
const oaurth2TokensDir = nuxeo.directory(OAUTH2_TOKENS_DIRECTORY_NAME);
return nuxeo.directory(OAUTH2_CLIENTS_DIRECTORY_NAME).delete(oauth2Client.properties.id)
.then(() => oaurth2TokensDir.fetchAll())
.then(({ entries }) => Promise.all(entries.map((entry) => oaurth2TokensDir.delete(entry.properties.id))));
});

describe('Authorization URL', () => {
before(function f() {
Expand Down Expand Up @@ -91,8 +91,7 @@ describe('OAuth2 spec', () => {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: authorization,
},
})
.then((res) => {
}).then((res) => {
const queryParameters = res.url.substring(res.url.indexOf('?') + 1);
const parameters = qs.parse(queryParameters);
return Nuxeo.oauth2.fetchAccessToken('http://localhost:8080/nuxeo', CLIENT_ID, parameters.code);
Expand Down Expand Up @@ -139,8 +138,9 @@ describe('OAuth2 spec', () => {
return Nuxeo.oauth2.refreshAccessToken('http://localhost:8080/nuxeo', CLIENT_ID, firstToken.refresh_token);
})
.then((token) => {
const bearerNuxeo =
new Nuxeo({ auth: { clientId: CLIENT_ID, method: 'bearerToken', token: token.access_token } });
const bearerNuxeo = new Nuxeo({
auth: { clientId: CLIENT_ID, method: 'bearerToken', token: token.access_token },
});
return bearerNuxeo.repository().fetch('/');
})
.then((doc) => {
Expand Down Expand Up @@ -199,8 +199,8 @@ describe('OAuth2 spec', () => {
return nuxeo.directory(OAUTH2_TOKENS_DIRECTORY_NAME).fetchAll();
})
.then(({ entries }) => {
const dirEntry =
entries.find((entry) => entry.properties.accessToken === bearerNuxeo._auth.token.access_token);
const cb = (entry) => entry.properties.accessToken === bearerNuxeo._auth.token.access_token;
const dirEntry = entries.find(cb);
// delete the token
return nuxeo.directory(OAUTH2_TOKENS_DIRECTORY_NAME).delete(dirEntry.properties.id);
})
Expand Down
3 changes: 1 addition & 2 deletions test/operation.spec.js
Expand Up @@ -254,8 +254,7 @@ describe('Operation', () => {
.input(blob)
.context({ currentDocument: WS_JS_TESTS_2_PATH })
.execute({ schemas: ['dublincore', 'note'] })
))
.then((res) => {
)).then((res) => {
expect(res['entity-type']).to.be.equal('document');
expect(res.title).to.be.equal('bar.txt');
expect(res.type).to.be.equal('Note');
Expand Down

0 comments on commit c30d10d

Please sign in to comment.