Skip to content

Commit d75b4fc

Browse files
committed
Linting update
1 parent 7c87c12 commit d75b4fc

File tree

18 files changed

+141
-30
lines changed

18 files changed

+141
-30
lines changed

components/pryv-monitor/src/Monitor.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Monitor extends EventEmitter {
2222
*/
2323
constructor (apiEndpointOrConnection, eventsGetScope = {}) {
2424
super();
25+
// @ts-ignore - pryv is set at runtime by extendPryvMonitor
2526
if (!Monitor.pryv) {
2627
throw new Error('package \'@pryv/monitor\' must loaded after package \'pryv\'');
2728
}
@@ -33,9 +34,11 @@ class Monitor extends EventEmitter {
3334
};
3435
Object.assign(this.eventsGetScope, eventsGetScope);
3536

37+
// @ts-ignore - pryv is set at runtime
3638
if (apiEndpointOrConnection instanceof Monitor.pryv.Connection) {
3739
this.connection = apiEndpointOrConnection;
3840
} else {
41+
// @ts-ignore - pryv is set at runtime
3942
this.connection = new Monitor.pryv.Connection(apiEndpointOrConnection);
4043
}
4144
this.states = {
@@ -160,17 +163,11 @@ class Monitor extends EventEmitter {
160163
return this.states.started;
161164
}
162165

163-
/**
164-
* Initialize the updateMethods with this Monitor
165-
* @callback Monitor~UpdateMethod
166-
* @param {Monitor} setMonitor
167-
*/
168-
169166
/**
170167
* @private
171-
* Called my UpdateMethod to share cross references
168+
* Called by UpdateMethod to share cross references
172169
* Set a custom update method
173-
* @param {Monitor~UpdateMethod} updateMethod - the auto-update method
170+
* @param {Object} updateMethod - the auto-update method
174171
* @returns {Monitor} this
175172
*/
176173
addUpdateMethod (updateMethod) {

components/pryv-monitor/src/UpdateMethod/Socket.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const Changes = require('../lib/Changes');
1515
class Socket extends UpdateMethod {
1616
async ready () {
1717
if (this.socket) return;
18+
// @ts-ignore - socket is added by @pryv/socket.io extension
1819
if (!this.monitor.connection.socket) {
1920
throw new Error('You should load package @pryv/socket.io to use monitor with websockets');
2021
}
22+
// @ts-ignore - socket is added by @pryv/socket.io extension
2123
this.socket = await this.monitor.connection.socket.open();
2224
this.socket.on('eventsChanged', () => { this.monitor.updateEvents(); });
2325
this.socket.on('streamsChanged', () => { this.monitor.updateStreams(); });

components/pryv-monitor/src/UpdateMethod/UpdateMethod.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class UpdateMethod {
1919
throw new Error('An update Method can be assigned to one monitor only');
2020
}
2121
this.monitor = monitor;
22+
// @ts-ignore - Changes.READY and Changes.STOP are valid event names
2223
monitor.on(Changes.READY, this.ready.bind(this));
24+
// @ts-ignore
2325
monitor.on(Changes.STOP, this.stop.bind(this));
2426
if (monitor.started) {
2527
this.ready();

components/pryv-monitor/src/lib/Changes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Enum trigger messages
77
* @readonly
8-
* @enum {pryv.Monitor.Changes}
8+
* @enum {string}
99
*/
1010
const Changes = {
1111
EVENT: 'event',

components/pryv-monitor/src/lib/updateStreams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Changes = require('./Changes');
77
module.exports = async function _updateStreams (monitor) {
88
try {
99
const result = await monitor.connection.get('streams');
10-
if (!result.streams) { throw new Error('Invalid response ' + JSON.streams(result)); }
10+
if (!result.streams) { throw new Error('Invalid response ' + JSON.stringify(result)); }
1111
monitor.emit(Changes.STREAMS, result.streams);
1212
} catch (e) {
1313
monitor.emit(Changes.ERROR, e);

components/pryv-socket.io/src/SocketIO.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SocketIO extends EventEmitter {
4040
this.connection.username()
4141
.then(username => {
4242
const socketEndpoint = this.connection.endpoint + username + '?auth=' + this.connection.token;
43+
// @ts-ignore - io is callable in socket.io-client
4344
this._io = io(socketEndpoint, { forceNew: true });
4445

4546
// handle failure
@@ -87,11 +88,13 @@ class SocketIO extends EventEmitter {
8788
* @param {Function} listener - The callback function
8889
* @returns {SocketIO} this
8990
*/
91+
// @ts-ignore - overriding EventEmitter.on with restricted signature
9092
on (eventName, listener) {
9193
checkOpen(this);
9294
if (EVENTS.indexOf(eventName) < 0) {
9395
throw new Error('Unkown event [' + eventName + ']. Allowed events are: ' + EVENTS);
9496
}
97+
// @ts-ignore
9598
return super.on(eventName, listener);
9699
}
97100

components/pryv/src/Auth/AuthController.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class AuthController {
7474
}
7575

7676
if (loginButton != null && loginButton.finishAuthProcessAfterRedirection != null) {
77+
// @ts-ignore - this is a valid AuthController
7778
await loginButton.finishAuthProcessAfterRedirection(this);
7879
}
7980

@@ -159,18 +160,22 @@ class AuthController {
159160

160161
/**
161162
* Start the authentication request and polling process
162-
* @returns {Promise<AuthRequestResponse>} Promise resolving to the auth request response
163+
* @returns {Promise<void>}
163164
* @see https://pryv.github.io/reference/#auth-request
164165
*/
165166
async startAuthRequest () {
167+
// @ts-ignore - postAccess uses .call(this) for context
166168
this.state = await postAccess.call(this);
167169

168170
await doPolling.call(this);
169171

172+
/** @this {AuthController} */
170173
async function postAccess () {
171174
try {
172175
const { response, body } = await utils.fetchPost(
176+
// @ts-ignore - this is bound via .call()
173177
this.serviceInfo.access,
178+
// @ts-ignore - this is bound via .call()
174179
this.settings.authRequest
175180
);
176181
if (!response.ok) {
@@ -187,14 +192,18 @@ class AuthController {
187192
}
188193
}
189194

195+
/** @this {AuthController} */
190196
async function doPolling () {
191-
if (this.state.status !== AuthStates.NEED_SIGNIN) {
197+
// @ts-ignore - this is bound via .call()
198+
if (this.state?.status !== AuthStates.NEED_SIGNIN) {
192199
return;
193200
}
194-
const pollResponse = await pollAccess(this.state.poll);
201+
// @ts-ignore - this is bound via .call()
202+
const pollResponse = await pollAccess(this.state?.poll);
195203

196204
if (pollResponse.status === AuthStates.NEED_SIGNIN) {
197-
setTimeout(await doPolling.bind(this), this.state.poll_rate_ms);
205+
// @ts-ignore - this is bound via .call()
206+
setTimeout(await doPolling.bind(this), this.state?.poll_rate_ms);
198207
} else {
199208
this.state = pollResponse;
200209
}

components/pryv/src/Auth/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ module.exports = {
2929
* @param {string | boolean} settings.authRequest.returnURL : false, // set this if you don't want a popup
3030
* @param {string} [settings.authRequest.referer] To track registration source
3131
* @param {string} settings.spanButtonID set and <span> id in DOM to insert default login button or null for custom
32-
* @param {Browser.AuthStateChangeHandler} settings.onStateChange
33-
* @param {string} [settings.returnURL=auto#] Set to "self#" to disable popup and force using the same page. Set a custom url when process is finished (specific use cases). Should always end by # ? or &
32+
* @param {Function} settings.onStateChange
33+
* @param {string} [settings.returnURL] Set to "self#" to disable popup and force using the same page
3434
* @param {string} serviceInfoUrl
3535
* @param {Object} [serviceCustomizations] override properties of serviceInfoUrl
36-
* @returns {pryv.Service}
36+
* @returns {Promise<Service>}
3737
*/
3838
async function setupAuth (settings, serviceInfoUrl, serviceCustomizations, HumanInteraction = LoginButton) {
3939
const service = new Service(serviceInfoUrl, serviceCustomizations);

components/pryv/src/Browser/CookieUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function set (cookieKey, value, expireInDays) {
3232
myDate.setDate(myDate.getDate() + expireInDays);
3333
let cookieStr = encodeURIComponent(cookieKey) + '=' +
3434
encodeURIComponent(JSON.stringify(value)) +
35-
';expires=' + myDate.toGMTString() +
35+
';expires=' + myDate.toUTCString() +
3636
';domain=.' + hostName + ';path=' + path;
3737
// do not add SameSite when removing a cookie
3838
if (expireInDays >= 0) cookieStr += ';SameSite=Strict';

components/pryv/src/Browser/LoginButton.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class LoginButton {
2828
setupButton(this);
2929
this.languageCode = this.authSettings.authRequest.languageCode || 'en';
3030
this.messages = Messages(this.languageCode);
31+
// @ts-ignore - loginButtonText is set by setupButton
3132
if (this.loginButtonText) {
3233
await loadAssets(this);
3334
}
@@ -84,7 +85,9 @@ class LoginButton {
8485
default:
8586
console.log('WARNING Unhandled state for Login: ' + state.status);
8687
}
88+
// @ts-ignore - loginButtonText is set by setupButton
8789
if (this.loginButtonText) {
90+
// @ts-ignore
8891
this.loginButtonText.innerHTML = this.text;
8992
}
9093
}
@@ -148,8 +151,8 @@ async function startLoginScreen (loginButton, authUrl) {
148151
const outerHeight = typeof window.outerHeight !== 'undefined' ? window.outerHeight : (document.body.clientHeight - 22);
149152
const width = 400;
150153
const height = 620;
151-
const left = parseInt(screenX + ((outerWidth - width) / 2), 10);
152-
const top = parseInt(screenY + ((outerHeight - height) / 2.5), 10);
154+
const left = Math.floor(screenX + ((outerWidth - width) / 2));
155+
const top = Math.floor(screenY + ((outerHeight - height) / 2.5));
153156
const features = (
154157
'width=' + width +
155158
',height=' + height +

0 commit comments

Comments
 (0)