New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zum/flash-client

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zum/flash-client - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

junit.xml

6

dist/connect/flashSocket.d.ts

@@ -6,8 +6,6 @@ import { Socket } from 'socket.io-client';

private readonly socket;
private readonly commandQueue;
private readonly EXECUTE_ONE_AT_A_TIME;
constructor(config: FlashConfig);
/**
* In the case when we manually disconnect (e.g. logout), we must connect again manually.
*/
private connect;
/**
* Invoked on both connect and reconnect cases

@@ -14,0 +12,0 @@ */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const async_1 = require("async");
const socket_io_client_1 = require("socket.io-client");

@@ -9,20 +10,4 @@ const types_1 = require("./types");

this.config = config;
this.EXECUTE_ONE_AT_A_TIME = 1;
/**
* In the case when we manually disconnect (e.g. logout), we must connect again manually.
*/
this.connect = async () => {
// TODO(Sreejith): this is probably not needed if we have only "connect" and "disconnect" public package methods
// Check if it is already connected since the connection is
// automatically made when it is initialized for the first time.
// This can be added to login lifecycle, which happens if the socket is
// already initialized or not.
if (!this.socket.connected) {
this.socket.connect();
await new Promise((resolve, reject) => {
this.socket.on('connect', resolve);
this.socket.on('disconnect', reject);
});
}
};
/**
* Invoked on both connect and reconnect cases

@@ -39,19 +24,7 @@ */

this.execute = async (operationArgument) => {
return new Promise((resolve, reject) => {
this.socket.emit(operationArgument.operation, operationArgument.args, (response) => {
switch (response.status) {
case types_1.FlashOperationResponseEnum.SUCCESS:
resolve();
break;
case types_1.FlashOperationResponseEnum.ERROR:
case types_1.FlashOperationResponseEnum.UNAUTHORIZED:
reject(response);
break;
default:
throw Error(`Unsupported status received`);
}
});
});
console.log(`Executing ${JSON.stringify(operationArgument)}`);
await this.commandQueue.pushAsync(operationArgument);
};
this.disconnect = () => {
this.commandQueue.kill();
this.socket.disconnect();

@@ -69,15 +42,13 @@ };

return async (callback) => {
let accessToken;
try {
accessToken = await this.config.accessTokenIssuer();
const accessToken = await this.config.accessTokenIssuer();
callback({
role: this.config.appRole,
access_token: accessToken,
});
}
catch (e) {
console.error(`[Flash] Unable to get the access token, possibly forgot to disconnect on logout`);
console.error(`[Flash] Unable to get the access token, possibly forgot to disconnect on logout`, e);
this.disconnect();
throw e; // TODO(Sreejith): is it safe to throw or better return w/o a callback?
}
callback({
role: this.config.appRole,
access_token: accessToken,
});
};

@@ -94,2 +65,17 @@ };

this.socket = this.newConnection();
this.commandQueue = async_1.queue((operationArgument, operationCompleteHandler) => {
this.socket.emit(operationArgument.operation, operationArgument.args, (response) => {
switch (response.status) {
case types_1.FlashOperationResponseEnum.SUCCESS:
operationCompleteHandler();
break;
case types_1.FlashOperationResponseEnum.ERROR:
case types_1.FlashOperationResponseEnum.UNAUTHORIZED:
operationCompleteHandler(new types_1.FlashOperationError(response.status));
break;
default:
operationCompleteHandler(new types_1.FlashOperationError(`Unsupported status received`));
}
});
}, this.EXECUTE_ONE_AT_A_TIME);
this.reConnectOnError();

@@ -96,0 +82,0 @@ }

@@ -16,3 +16,4 @@ "use strict";

this.unsubscribeTopic = async (topic) => {
var _a;
const subscription = this.subscriptions.get(topic);
this.subscriptions.delete(topic);
await this.flashSocket.execute({

@@ -22,3 +23,3 @@ operation: types_1.FlashOperation.UNSUBSCRIBE_ALL,

});
(_a = this.subscriptions.get(topic)) === null || _a === void 0 ? void 0 : _a.subscriber.complete();
subscription === null || subscription === void 0 ? void 0 : subscription.subscriber.complete();
};

@@ -25,0 +26,0 @@ this.disconnect = () => {

@@ -7,2 +7,5 @@ import { EntityId, Topic } from './flashEvent';

}
export declare class FlashOperationError extends Error {
name: string;
}
export declare type FlashOperationArgument = {

@@ -9,0 +12,0 @@ operation: FlashOperation.SUBSCRIBE;

@@ -9,2 +9,9 @@ "use strict";

})(FlashOperation = exports.FlashOperation || (exports.FlashOperation = {}));
class FlashOperationError extends Error {
constructor() {
super(...arguments);
this.name = 'FlashOperationError';
}
}
exports.FlashOperationError = FlashOperationError;
var FlashOperationResponseEnum;

@@ -11,0 +18,0 @@ (function (FlashOperationResponseEnum) {

@@ -15,3 +15,2 @@ "use strict";

};
// TODO(Sreejith): how to prevent a race condition b/w subscribe and unsubscribe?
exports.unsubscribeToRidesPrimary = () => unsubscribe(topicTypes_1.FlashTopic.RIDE_LIST_PRIMARY);

@@ -18,0 +17,0 @@ exports.subscribeToRidesSecondary = (rideIds, getRideImpl) => {

@@ -0,1 +1,2 @@

import { AsyncQueue, queue } from 'async';
import { io as socketIO, Socket } from 'socket.io-client';

@@ -7,2 +8,3 @@ import {

FlashOperationArgument,
FlashOperationError,
FlashOperationResponse,

@@ -16,5 +18,25 @@ FlashOperationResponseEnum,

private readonly socket: Socket;
private readonly commandQueue: AsyncQueue<FlashOperationArgument>;
private readonly EXECUTE_ONE_AT_A_TIME: 1 = 1;
constructor(private config: FlashConfig) {
this.socket = this.newConnection();
this.commandQueue = queue<FlashOperationArgument, FlashOperationError>(
(operationArgument, operationCompleteHandler) => {
this.socket.emit(operationArgument.operation, operationArgument.args, (response: FlashOperationResponse) => {
switch (response.status) {
case FlashOperationResponseEnum.SUCCESS:
operationCompleteHandler();
break;
case FlashOperationResponseEnum.ERROR:
case FlashOperationResponseEnum.UNAUTHORIZED:
operationCompleteHandler(new FlashOperationError(response.status));
break;
default:
operationCompleteHandler(new FlashOperationError(`Unsupported status received`));
}
});
},
this.EXECUTE_ONE_AT_A_TIME,
);
this.reConnectOnError();

@@ -24,20 +46,2 @@ }

/**
* In the case when we manually disconnect (e.g. logout), we must connect again manually.
*/
private connect = async (): Promise<void> => {
// TODO(Sreejith): this is probably not needed if we have only "connect" and "disconnect" public package methods
// Check if it is already connected since the connection is
// automatically made when it is initialized for the first time.
// This can be added to login lifecycle, which happens if the socket is
// already initialized or not.
if (!this.socket.connected) {
this.socket.connect();
await new Promise<void>((resolve, reject) => {
this.socket.on('connect', resolve);
this.socket.on('disconnect', reject);
});
}
};
/**
* Invoked on both connect and reconnect cases

@@ -56,20 +60,8 @@ */

public execute = async (operationArgument: FlashOperationArgument): Promise<void> => {
return new Promise((resolve, reject) => {
this.socket.emit(operationArgument.operation, operationArgument.args, (response: FlashOperationResponse) => {
switch (response.status) {
case FlashOperationResponseEnum.SUCCESS:
resolve();
break;
case FlashOperationResponseEnum.ERROR:
case FlashOperationResponseEnum.UNAUTHORIZED:
reject(response);
break;
default:
throw Error(`Unsupported status received`);
}
});
});
console.log(`Executing ${JSON.stringify(operationArgument)}`);
await this.commandQueue.pushAsync(operationArgument);
};
public disconnect = (): void => {
this.commandQueue.kill();
this.socket.disconnect();

@@ -89,14 +81,12 @@ };

return async (callback: (data: Record<string, string>) => void) => {
let accessToken;
try {
accessToken = await this.config.accessTokenIssuer();
const accessToken = await this.config.accessTokenIssuer();
callback({
role: this.config.appRole,
access_token: accessToken,
});
} catch (e) {
console.error(`[Flash] Unable to get the access token, possibly forgot to disconnect on logout`);
console.error(`[Flash] Unable to get the access token, possibly forgot to disconnect on logout`, e);
this.disconnect();
throw e; // TODO(Sreejith): is it safe to throw or better return w/o a callback?
}
callback({
role: this.config.appRole,
access_token: accessToken,
});
};

@@ -103,0 +93,0 @@ };

@@ -30,2 +30,4 @@ import { Observable, Subscriber } from 'rxjs';

public unsubscribeTopic = async (topic: Topic): Promise<void> => {
const subscription = this.subscriptions.get(topic);
this.subscriptions.delete(topic);
await this.flashSocket.execute({

@@ -35,3 +37,3 @@ operation: FlashOperation.UNSUBSCRIBE_ALL,

});
this.subscriptions.get(topic)?.subscriber.complete();
subscription?.subscriber.complete();
};

@@ -38,0 +40,0 @@

@@ -8,2 +8,7 @@ import { EntityId, Topic } from './flashEvent';

}
export class FlashOperationError extends Error {
name = 'FlashOperationError';
}
export type FlashOperationArgument =

@@ -10,0 +15,0 @@ | {

@@ -26,3 +26,2 @@ import { asyncScheduler, merge, Observable } from 'rxjs';

};
// TODO(Sreejith): how to prevent a race condition b/w subscribe and unsubscribe?
export const unsubscribeToRidesPrimary = (): Promise<void> => unsubscribe(FlashTopic.RIDE_LIST_PRIMARY);

@@ -29,0 +28,0 @@

{
"name": "@zum/flash-client",
"version": "0.0.13",
"version": "0.0.14",
"description": "Client for connecting to Zum Flash server",

@@ -17,5 +17,7 @@ "license": "UNLICENSED",

"dependencies": {
"rxjs": "~6.5.5",
"socket.io": "^3.1.0",
"socket.io-client": "^3.1.0"
"@types/async": "^3.2.5",
"async": "^3.2.0",
"rxjs": "^6.5.5",
"socket.io": "^3.1.1",
"socket.io-client": "^3.1.1"
},

@@ -22,0 +24,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc