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

att-client

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

att-client - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3-beta.1

54

dist/cjs/Client/Client.js

@@ -31,2 +31,4 @@ "use strict";

decodedToken;
groupAllowlist;
groupDenylist;
readyState;

@@ -39,6 +41,6 @@ refreshTokensDelay;

if (typeof config.logVerbosity === 'undefined') {
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}Using Warning log verbosity. You will only see Errors and Warnings. If you want to see more verbose logs, create your client with a higher 'logVerbosity'.`);
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}[CLIENT] Using Warning log verbosity. You will only see Errors and Warnings. If you want to see more verbose logs, create your client with a higher 'logVerbosity'.`);
}
else if (config.logVerbosity >= 4) {
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}You are using Debug log verbosity. This is not recommended for production environments as sensitive information like configured credentials will appear in your logs. Please consider using Info log verbosity or lower for production.`);
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}[CLIENT] You are using Debug log verbosity. This is not recommended for production environments as sensitive information like configured credentials will appear in your logs. Please consider using Info log verbosity or lower for production.`);
}

@@ -51,3 +53,2 @@ const configuredLogVerbosity = config.logVerbosity ?? constants_js_1.DEFAULTS.logVerbosity;

});
this.logger.info('Configuring client.');
if ('clientId' in config) {

@@ -57,3 +58,3 @@ if (typeof config.clientId === 'undefined' ||

typeof config.scope === 'undefined') {
this.logger.error("Cannot create bot client without 'clientId', 'clientSecret', and 'scope'.");
this.logger.error(`[CLIENT] Cannot create bot client without 'clientId', 'clientSecret', and 'scope'.`);
throw new Error('Invalid client configuration.');

@@ -64,3 +65,3 @@ }

if (typeof config.username === 'undefined' || typeof config.password === 'undefined') {
this.logger.error("Cannot create user client without 'username' and 'password'.");
this.logger.error(`[CLIENT] Cannot create user client without 'username' and 'password'.`);
throw new Error('Invalid client configuration.');

@@ -70,3 +71,3 @@ }

else {
this.logger.error('Cannot create client without either bot credentials or user credentials.');
this.logger.error(`[CLIENT] Cannot create client without either bot credentials or user credentials.`);
throw new Error('Invalid client configuration.');

@@ -78,7 +79,7 @@ }

config.includedGroups.length > 0) {
this.logger.warn('Client configuration contains both included and excluded groups. Ignoring excluded groups.');
this.logger.warn(`[CLIENT] Configuration contains both included and excluded groups. Ignoring excluded groups.`);
}
if (typeof config.maxWorkerConcurrency !== 'undefined' &&
config.maxWorkerConcurrency > constants_js_1.MAX_WORKER_CONCURRENCY_WARNING) {
this.logger.warn('Maximum concurrency is set above recommended level. Client may experience issues with WebSocket migrations as a result of too many concurrent requests.');
this.logger.warn(`[CLIENT] Maximum concurrency is set above recommended level. Client may experience issues with WebSocket migrations as a result of too many concurrent requests.`);
}

@@ -127,2 +128,4 @@ const credentials = 'clientId' in config

this.api = new index_js_1.Api(this);
this.groupAllowlist = new Set(this.config.includedGroups);
this.groupDenylist = new Set(this.config.excludedGroups);
this.groups = {};

@@ -139,3 +142,3 @@ this.name = `${constants_js_1.AGENT.name} v${constants_js_1.AGENT.version}`;

this.readyState = ReadyState.Starting;
this.logger.info(`[CLIENT] Initialising.`);
this.logger.info(`[CLIENT] Initialising...`);
const decodedToken = await this.refreshTokens();

@@ -289,15 +292,13 @@ if ('client_sub' in decodedToken) {

isAllowedGroup(groupId) {
const mustBeIncluded = this.config.includedGroups.length > 0;
const isIncluded = this.config.includedGroups.includes(groupId);
const isExcluded = this.config.excludedGroups.includes(groupId);
const mustBeIncluded = this.groupAllowlist.size > 0;
const isIncluded = this.groupAllowlist.has(groupId);
const isExcluded = this.groupDenylist.has(groupId);
return mustBeIncluded ? isIncluded : !isExcluded;
}
async addGroup(group, member) {
this.logger.info(`[CLIENT] Managing group ${group.id} (${group.name}).`);
if (Object.keys(this.groups).map(Number).includes(group.id)) {
this.logger.error(`[CLIENT] Can't manage group ${group.id} (${group.name}) more than once.`);
return;
}
if (!this.isAllowedGroup(group.id)) {
this.logger.warn(`[CLIENT] Client is a member of group ${group.id} (${group.name}) which is either not configured as an included group, or is configured as an excluded group.`);
this.logger.debug(`[CLIENT] Refused to manage denylisted group ${group.id} (${group.name}).`);
return;

@@ -310,14 +311,33 @@ }

};
this.logger.info(`[CLIENT] Managing group ${group.id} (${group.name}).`);
return await managedGroup.init();
}
async allowGroup(groupId, force = false) {
if (typeof this.decodedToken === 'undefined' || !('client_sub' in this.decodedToken)) {
throw new Error(`[CLIENT] Cannot dynamically allowlist group while client is not initialised with bot credentials.`);
}
const userId = this.decodedToken.client_sub;
const [group, member] = await Promise.all([
this.api.getGroupInfo(groupId),
this.api.getGroupMember(groupId, userId)
]);
this.groupDenylist.delete(groupId);
if (this.groupAllowlist.size > 0 || force)
this.groupAllowlist.add(groupId);
await this.addGroup(group, member);
}
async removeGroup(groupId) {
this.logger.info(`[CLIENT] Removing group ${groupId}.`);
const group = this.groups[groupId];
if (typeof group === 'undefined') {
this.logger.error(`[CLIENT] Can't remove an unmanaged group with ID ${groupId}.`);
return;
}
this.logger.info(`[CLIENT] Removing group ${groupId}.`);
await group.dispose();
delete this.groups[groupId];
}
async denyGroup(groupId) {
this.groupDenylist.add(groupId);
this.groupAllowlist.delete(groupId);
await this.removeGroup(groupId);
}
hashPassword(password) {

@@ -324,0 +344,0 @@ if (/^[0-9a-f]{128}$/i.test(password)) {

@@ -7,3 +7,3 @@ "use strict";

name: 'att-client',
version: '0.5.2'
version: '0.5.3-beta.1'
};

@@ -10,0 +10,0 @@ const SECOND = 1000;

@@ -25,2 +25,4 @@ import { createHash } from 'node:crypto';

decodedToken;
groupAllowlist;
groupDenylist;
readyState;

@@ -33,6 +35,6 @@ refreshTokensDelay;

if (typeof config.logVerbosity === 'undefined') {
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}Using Warning log verbosity. You will only see Errors and Warnings. If you want to see more verbose logs, create your client with a higher 'logVerbosity'.`);
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}[CLIENT] Using Warning log verbosity. You will only see Errors and Warnings. If you want to see more verbose logs, create your client with a higher 'logVerbosity'.`);
}
else if (config.logVerbosity >= 4) {
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}You are using Debug log verbosity. This is not recommended for production environments as sensitive information like configured credentials will appear in your logs. Please consider using Info log verbosity or lower for production.`);
configuredConsole.warn(`${configuredLogPrefix}${configuredLogPrefix.length === 0 ? '' : ' '}[CLIENT] You are using Debug log verbosity. This is not recommended for production environments as sensitive information like configured credentials will appear in your logs. Please consider using Info log verbosity or lower for production.`);
}

@@ -45,3 +47,2 @@ const configuredLogVerbosity = config.logVerbosity ?? DEFAULTS.logVerbosity;

});
this.logger.info('Configuring client.');
if ('clientId' in config) {

@@ -51,3 +52,3 @@ if (typeof config.clientId === 'undefined' ||

typeof config.scope === 'undefined') {
this.logger.error("Cannot create bot client without 'clientId', 'clientSecret', and 'scope'.");
this.logger.error(`[CLIENT] Cannot create bot client without 'clientId', 'clientSecret', and 'scope'.`);
throw new Error('Invalid client configuration.');

@@ -58,3 +59,3 @@ }

if (typeof config.username === 'undefined' || typeof config.password === 'undefined') {
this.logger.error("Cannot create user client without 'username' and 'password'.");
this.logger.error(`[CLIENT] Cannot create user client without 'username' and 'password'.`);
throw new Error('Invalid client configuration.');

@@ -64,3 +65,3 @@ }

else {
this.logger.error('Cannot create client without either bot credentials or user credentials.');
this.logger.error(`[CLIENT] Cannot create client without either bot credentials or user credentials.`);
throw new Error('Invalid client configuration.');

@@ -72,7 +73,7 @@ }

config.includedGroups.length > 0) {
this.logger.warn('Client configuration contains both included and excluded groups. Ignoring excluded groups.');
this.logger.warn(`[CLIENT] Configuration contains both included and excluded groups. Ignoring excluded groups.`);
}
if (typeof config.maxWorkerConcurrency !== 'undefined' &&
config.maxWorkerConcurrency > MAX_WORKER_CONCURRENCY_WARNING) {
this.logger.warn('Maximum concurrency is set above recommended level. Client may experience issues with WebSocket migrations as a result of too many concurrent requests.');
this.logger.warn(`[CLIENT] Maximum concurrency is set above recommended level. Client may experience issues with WebSocket migrations as a result of too many concurrent requests.`);
}

@@ -121,2 +122,4 @@ const credentials = 'clientId' in config

this.api = new Api(this);
this.groupAllowlist = new Set(this.config.includedGroups);
this.groupDenylist = new Set(this.config.excludedGroups);
this.groups = {};

@@ -133,3 +136,3 @@ this.name = `${AGENT.name} v${AGENT.version}`;

this.readyState = ReadyState.Starting;
this.logger.info(`[CLIENT] Initialising.`);
this.logger.info(`[CLIENT] Initialising...`);
const decodedToken = await this.refreshTokens();

@@ -283,15 +286,13 @@ if ('client_sub' in decodedToken) {

isAllowedGroup(groupId) {
const mustBeIncluded = this.config.includedGroups.length > 0;
const isIncluded = this.config.includedGroups.includes(groupId);
const isExcluded = this.config.excludedGroups.includes(groupId);
const mustBeIncluded = this.groupAllowlist.size > 0;
const isIncluded = this.groupAllowlist.has(groupId);
const isExcluded = this.groupDenylist.has(groupId);
return mustBeIncluded ? isIncluded : !isExcluded;
}
async addGroup(group, member) {
this.logger.info(`[CLIENT] Managing group ${group.id} (${group.name}).`);
if (Object.keys(this.groups).map(Number).includes(group.id)) {
this.logger.error(`[CLIENT] Can't manage group ${group.id} (${group.name}) more than once.`);
return;
}
if (!this.isAllowedGroup(group.id)) {
this.logger.warn(`[CLIENT] Client is a member of group ${group.id} (${group.name}) which is either not configured as an included group, or is configured as an excluded group.`);
this.logger.debug(`[CLIENT] Refused to manage denylisted group ${group.id} (${group.name}).`);
return;

@@ -304,14 +305,33 @@ }

};
this.logger.info(`[CLIENT] Managing group ${group.id} (${group.name}).`);
return await managedGroup.init();
}
async allowGroup(groupId, force = false) {
if (typeof this.decodedToken === 'undefined' || !('client_sub' in this.decodedToken)) {
throw new Error(`[CLIENT] Cannot dynamically allowlist group while client is not initialised with bot credentials.`);
}
const userId = this.decodedToken.client_sub;
const [group, member] = await Promise.all([
this.api.getGroupInfo(groupId),
this.api.getGroupMember(groupId, userId)
]);
this.groupDenylist.delete(groupId);
if (this.groupAllowlist.size > 0 || force)
this.groupAllowlist.add(groupId);
await this.addGroup(group, member);
}
async removeGroup(groupId) {
this.logger.info(`[CLIENT] Removing group ${groupId}.`);
const group = this.groups[groupId];
if (typeof group === 'undefined') {
this.logger.error(`[CLIENT] Can't remove an unmanaged group with ID ${groupId}.`);
return;
}
this.logger.info(`[CLIENT] Removing group ${groupId}.`);
await group.dispose();
delete this.groups[groupId];
}
async denyGroup(groupId) {
this.groupDenylist.add(groupId);
this.groupAllowlist.delete(groupId);
await this.removeGroup(groupId);
}
hashPassword(password) {

@@ -318,0 +338,0 @@ if (/^[0-9a-f]{128}$/i.test(password)) {

import './Logger/index.js';
export const AGENT = {
name: 'att-client',
version: '0.5.2'
version: '0.5.3-beta.1'
};

@@ -6,0 +6,0 @@ const SECOND = 1000;

@@ -22,2 +22,4 @@ import type { Config } from './Config.js';

private decodedToken?;
private groupAllowlist;
private groupDenylist;
private readyState;

@@ -32,3 +34,5 @@ private refreshTokensDelay?;

private addGroup;
allowGroup(groupId: number, force?: boolean): Promise<void>;
private removeGroup;
denyGroup(groupId: number): Promise<void>;
private hashPassword;

@@ -35,0 +39,0 @@ openServerConnection(serverId: number): Promise<ServerConnection>;

{
"name": "att-client",
"version": "0.5.2",
"version": "0.5.3-beta.1",
"description": "Node bot library for A Township Tale, a VR game by Alta",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/mdingena/att-client#readme",

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