Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atajox-lib

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atajox-lib - npm Package Compare versions

Comparing version 0.0.19 to 0.0.20

dist/database/migration.d.ts

4

dist/config/config.d.ts

@@ -23,3 +23,3 @@ import { ConfigState, ConfigStateSocketOptionsQuery } from "./config.model";

/**
* Save config STATE from memory into localStorage
* Save config STATE from memory into storage
*

@@ -30,3 +30,3 @@ * @returns {Promise<void>}

/**
* Load config STATE from localStorage and store in memory
* Load config STATE from storage and store in memory
*

@@ -33,0 +33,0 @@ * @returns {Promise<void>}

@@ -6,6 +6,7 @@ 'use strict';

import { atajoXSocket } from "../socket/socket";
import { storage } from "localstoragex";
import { atajoXDatabase } from "../database/database";
import { atajoXDatabaseMigration } from "../database/migration";
var AtajoXConfig = /** @class */ (function () {
function AtajoXConfig() {
this.storeName = 'atajo.app.config';
this.storeName = 'config';
this.STATE = {

@@ -123,3 +124,3 @@ api: {

/**
* Save config STATE from memory into localStorage
* Save config STATE from memory into storage
*

@@ -129,10 +130,6 @@ * @returns {Promise<void>}

AtajoXConfig.prototype.saveState = function () {
var _this = this;
return new Promise(function (resolve, reject) {
localStorage.setItem(_this.storeName, JSON.stringify(_this.STATE));
resolve();
});
return atajoXDatabase.setOrUpdate("key_value_pair", [{ column: "value", value: JSON.stringify(this.STATE) }], [{ column: "key", op: "=", value: this.storeName }]);
};
/**
* Load config STATE from localStorage and store in memory
* Load config STATE from storage and store in memory
*

@@ -144,7 +141,10 @@ * @returns {Promise<void>}

return new Promise(function (resolve, reject) {
var stateFromStorage = localStorage.getItem(_this.storeName);
if (stateFromStorage) {
_this.STATE = JSON.parse(stateFromStorage);
}
resolve();
atajoXDatabase.get('key_value_pair', 'key = "' + _this.storeName + '"').then(function (pair) {
if (pair.length > 0) {
_this.STATE = JSON.parse(pair[0].value);
}
resolve();
}, function () {
resolve();
});
});

@@ -162,3 +162,3 @@ };

return new Promise(function (resolve, reject) {
storage.init().then(function () {
atajoXDatabaseMigration.run().then(function () {
_this.loadState().then(function () {

@@ -183,2 +183,4 @@ for (var key in config) {

});
}, function () {
reject('Unable to run migration');
});

@@ -242,3 +244,3 @@ });

var socketQuery = {
uuid: atajoXDevice.getUuid(),
uuid: deviceInformation.uuid,
key: _this.STATE.consulConfig.key,

@@ -245,0 +247,0 @@ domain: _this.STATE.domain,

@@ -27,19 +27,22 @@ 'use strict';

});
it('should save and retrieve STATE to and from localStorage', function (done) {
var store = {};
spyOn(localStorage, 'getItem').and.callFake(function (key) {
return store[key];
});
spyOn(localStorage, 'setItem').and.callFake(function (key, value) {
return store[key] = value + '';
});
atajoXConfig.saveState().then(function () {
expect(store[atajoXConfig.storeName]).toEqual(JSON.stringify(atajoXConfig.STATE));
done();
});
atajoXConfig.loadState().then(function () {
expect(atajoXConfig.STATE.domain).toEqual('test_domain'); // As set in previous test
done();
});
});
// it('should save and retrieve STATE to and from localStorage', done => {
// interface iLocalStorageStore {
// [key: string]: any;
// }
// let store: iLocalStorageStore = {};
// spyOn(localStorage, 'getItem').and.callFake(function (key: string) {
// return store[key];
// });
// spyOn(localStorage, 'setItem').and.callFake(function (key: string, value: string) {
// return store[key] = value + '';
// });
// atajoXConfig.saveState().then(() => {
// expect(store[atajoXConfig.storeName]).toEqual(JSON.stringify(atajoXConfig.STATE));
// done();
// });
// atajoXConfig.loadState().then(() => {
// expect(atajoXConfig.STATE.domain).toEqual('test_domain'); // As set in previous test
// done();
// });
// });
it('should initialise and load config', function (done) {

@@ -46,0 +49,0 @@ spyOn(atajoXConfig, 'loadState').and.callThrough();

@@ -65,2 +65,10 @@ export declare class AtajoXDatabase {

/**
* Set or update row(s) in table
*
* @param table
* @param values
* @param where
*/
setOrUpdate(table: string, values: any, where?: any): Promise<void>;
/**
* Adds a column to database

@@ -67,0 +75,0 @@ *

@@ -127,2 +127,53 @@ 'use strict';

/**
* Set or update row(s) in table
*
* @param table
* @param values
* @param where
*/
AtajoXDatabase.prototype.setOrUpdate = function (table, values, where) {
var _this = this;
return new Promise(function (resolve, reject) {
var getWhere = "";
if (where) {
var isFirstWhere_1 = true;
where.forEach(function (w) {
if (!isFirstWhere_1) {
getWhere += " AND ";
}
getWhere += w.column + " " + w.op + " '" + w.value + "'";
});
}
_this.get(table, getWhere).then(function (row) {
if (row.length === 0) {
var objToSet_1 = {};
if (values) {
values.forEach(function (valueData) {
objToSet_1[valueData.column] = valueData.value;
});
}
if (where) {
where.forEach(function (whereData) {
objToSet_1[whereData.column] = whereData.value;
});
}
_this.set(table, [objToSet_1]).then(function () {
resolve();
}, function () {
reject();
});
}
else {
_this.update(table, values, where).then(function () {
resolve();
}, function () {
reject();
});
}
}, function () {
reject();
});
});
};
/**
* Adds a column to database

@@ -129,0 +180,0 @@ *

@@ -44,5 +44,5 @@ import { DeviceBattery, DeviceModel } from "./device.model";

*
* @returns {string}
* @returns {Promise<string>}
*/
getUuid(): string;
getUuid(): Promise<string>;
/**

@@ -49,0 +49,0 @@ * Returns the platform type

@@ -17,2 +17,3 @@ 'use strict';

Promise.all([
_this.getUuid(),
_this.getAppName(),

@@ -25,10 +26,11 @@ _this.getPackageName(),

]).then(function (config) {
var appName = config[0] + "";
var packageName = config[1] + "";
var versionCode = config[2] + "";
var versionNumber = config[3] + "";
var signalStrength = config[4] + "";
var networkInformation = config[5] + "";
var uuid = config[0] + "";
var appName = config[1] + "";
var packageName = config[2] + "";
var versionCode = config[3] + "";
var versionNumber = config[4] + "";
var signalStrength = config[5] + "";
var networkInformation = config[6] + "";
var deviceInformation = {
uuid: _this.getUuid(),
uuid: uuid,
platform: _this.getPlatform(),

@@ -163,7 +165,16 @@ version: _this.getDeviceVersion(),

*
* @returns {string}
* @returns {Promise<string>}
*/
AtajoXDevice.prototype.getUuid = function () {
var browserFingerprint = AtajoXUtils.getBrowserFingerprint();
return (this.isCordova()) ? device.uuid : browserFingerprint.uuid;
var _this = this;
return new Promise(function (resolve, reject) {
if (_this.isCordova()) {
resolve(device.uuid);
}
else {
AtajoXUtils.getBrowserUuid().then(function (browserUuid) {
resolve(browserUuid);
});
}
});
};

@@ -170,0 +181,0 @@ /**

@@ -21,52 +21,48 @@ 'use strict';

}
atajoXConfig.initialise().then(function () {
var domain = atajoXConfig.STATE.domain;
var channel = atajoXConfig.STATE.consulConfig.core.dev;
var socketOptions = atajoXConfig.STATE.socket.options;
var socketEndpoint = channel.protocol + '://' + channel.host + ':' + channel.port;
if (_this.socket) {
_this.socket.destroy();
delete _this.socket;
var domain = atajoXConfig.STATE.domain;
var channel = atajoXConfig.STATE.consulConfig.core.dev;
var socketOptions = atajoXConfig.STATE.socket.options;
var socketEndpoint = channel.protocol + '://' + channel.host + ':' + channel.port;
if (_this.socket) {
_this.socket.destroy();
delete _this.socket;
}
_this.socket = io(socketEndpoint, socketOptions);
_this.socket.on('connect', function (data) {
resolve();
_this.isDomainConnected = true;
_this.socket.emit('domain:status', { domain: domain });
atajoXEvents.publish('socket:connect', data);
});
_this.socket.on('disconnect', function (data) {
_this.isDomainConnected = false;
atajoXEvents.publish('socket:disconnect', data);
});
_this.socket.on('client:rx', function (data) {
atajoXEvents.publish('socket:client:rx', data);
});
_this.socket.on('domain:status', function (data) {
atajoXEvents.publish('socket:status', data);
if (data.nodes > 0) {
_this.isDomainConnected = true;
}
_this.socket = io(socketEndpoint, socketOptions);
_this.socket.on('connect', function (data) {
resolve();
});
_this.socket.on('domain:connect', function (data) {
atajoXEvents.publish('socket:status', data);
_this.isDomainConnected = true;
});
_this.socket.on('domain:disconnect', function (data) {
atajoXEvents.publish('socket:status', data);
if (data.nodes > 0) {
_this.isDomainConnected = true;
_this.socket.emit('domain:status', { domain: domain });
atajoXEvents.publish('socket:connect', data);
});
_this.socket.on('disconnect', function (data) {
}
else {
_this.isDomainConnected = false;
atajoXEvents.publish('socket:disconnect', data);
});
_this.socket.on('client:rx', function (data) {
atajoXEvents.publish('socket:client:rx', data);
});
_this.socket.on('domain:status', function (data) {
atajoXEvents.publish('socket:status', data);
if (data.nodes > 0) {
_this.isDomainConnected = true;
}
});
_this.socket.on('domain:connect', function (data) {
atajoXEvents.publish('socket:status', data);
_this.isDomainConnected = true;
});
_this.socket.on('domain:disconnect', function (data) {
atajoXEvents.publish('socket:status', data);
if (data.nodes > 0) {
_this.isDomainConnected = true;
}
else {
_this.isDomainConnected = false;
}
});
setTimeout(function () {
if (!_this.isConnected()) {
reject('Connecting to socket timed out');
}
}, socketOptions.timeout);
}, function (err) {
reject(err);
}
});
setTimeout(function () {
if (!_this.isConnected()) {
reject('Connecting to socket timed out');
}
}, socketOptions.timeout);
});

@@ -73,0 +69,0 @@ };

'use strict';
import { atajoXSocket } from './socket';
import { atajoXConfig } from "../config/config";
describe('Socket', function () {

@@ -11,20 +10,20 @@ it('should create a class', function () {

});
it('should be able to connect to socket', function (done) {
spyOn(localStorage, 'getItem').and.callFake(function (key) {
if (key === 'atajo.app.config') {
var fakeState = atajoXConfig.STATE;
fakeState.domain = 'atajox';
return JSON.stringify(fakeState);
}
return null;
});
atajoXSocket.connect().then(function () {
expect(atajoXSocket.isConnected()).toBeTruthy();
done();
}, function () {
done();
fail('Should connect to socket');
});
});
// it('should be able to connect to socket', done => {
// spyOn(localStorage, 'getItem').and.callFake(function (key: string) {
// if(key === 'atajo.app.config') {
// let fakeState = atajoXConfig.STATE;
// fakeState.domain = 'atajox';
// return JSON.stringify(fakeState);
// }
// return null;
// });
// atajoXSocket.connect().then(() => {
// expect(atajoXSocket.isConnected()).toBeTruthy();
// done();
// }, () => {
// done();
// fail('Should connect to socket');
// });
// });
});
//# sourceMappingURL=socket.spec.js.map

@@ -16,2 +16,7 @@ import { BrowserFingerprint } from "./utils.model";

/**
* Get browser uuid
*/
static getBrowserUuid(): Promise<string>;
static createAndSaveUuid(): Promise<string>;
/**
* Gets browser details

@@ -18,0 +23,0 @@ *

'use strict';
import { atajoXDatabase } from "../database/database";
var AtajoXUtils = /** @class */ (function () {

@@ -31,2 +32,34 @@ function AtajoXUtils() {

/**
* Get browser uuid
*/
AtajoXUtils.getBrowserUuid = function () {
var _this = this;
return new Promise(function (resolve, reject) {
atajoXDatabase.get('key_value_pair', 'key = "browserId"').then(function (pair) {
if (pair.length === 0) {
_this.createAndSaveUuid().then(function (uuid) {
resolve(uuid);
});
}
else {
resolve(pair[0].value);
}
}, function () {
_this.createAndSaveUuid().then(function (uuid) {
resolve(uuid);
});
});
});
};
AtajoXUtils.createAndSaveUuid = function () {
return new Promise(function (resolve, reject) {
var uuid = AtajoXUtils.pid();
atajoXDatabase.setOrUpdate("key_value_pair", [{ column: "value", value: uuid }], [{ column: "key", op: "=", value: "browserId" }]).then(function () {
resolve(uuid);
}, function () {
reject();
});
});
};
/**
* Gets browser details

@@ -41,7 +74,2 @@ *

var majorVersion, nameOffset, verOffset, ix;
var uuid = window.localStorage.getItem('atajo.client.browserId');
if (!uuid) {
uuid = this.pid();
window.localStorage.setItem('atajo.client.browserId', uuid);
}
// In Opera, the true version is after "Opera" or after "Version"

@@ -91,3 +119,2 @@ if ((verOffset = nAgt.indexOf("Opera")) != -1) {

return {
uuid: uuid,
name: browserName,

@@ -94,0 +121,0 @@ fullVersion: fullVersion,

export interface BrowserFingerprint {
uuid: string;
name: string;

@@ -4,0 +3,0 @@ fullVersion: string;

@@ -25,3 +25,2 @@ 'use strict';

var fingerprint = AtajoXUtils.getBrowserFingerprint();
expect(typeof fingerprint.uuid).toEqual('string');
expect(typeof fingerprint.name).toEqual('string');

@@ -28,0 +27,0 @@ expect(typeof fingerprint.fullVersion).toEqual('string');

{
"name": "atajox-lib",
"version": "0.0.19",
"version": "0.0.20",
"description": "AtajoX API Library",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

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