New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.0-beta.1 to 0.5.0

32

dist/cjs/Client/Client.js

@@ -36,10 +36,15 @@ "use strict";

const configuredConsole = config.console ?? constants_js_1.DEFAULTS.console;
const configuredLogPrefix = config.logPrefix ?? constants_js_1.DEFAULTS.logPrefix;
if (typeof config.logVerbosity === 'undefined') {
configuredConsole.warn("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 ? '' : ' '}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('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 ? '' : ' '}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.`);
}
const configuredLogVerbosity = config.logVerbosity ?? constants_js_1.DEFAULTS.logVerbosity;
this.logger = new index_js_3.Logger(configuredLogVerbosity, configuredConsole);
this.logger = new index_js_3.Logger({
console: configuredConsole,
prefix: configuredLogPrefix,
verbosity: configuredLogVerbosity
});
this.logger.info('Configuring client.');

@@ -91,5 +96,6 @@ if ('clientId' in config) {

includedGroups: config.includedGroups ?? constants_js_1.DEFAULTS.includedGroups,
logPrefix: configuredLogPrefix,
logVerbosity: configuredLogVerbosity,
maxSubscriptionsPerWebSocket: config.maxSubscriptionsPerWebSocket ?? constants_js_1.DEFAULTS.maxSubscriptionsPerWebSocket,
maxWorkerConcurrency: config.maxWorkerConcurrency ?? constants_js_1.DEFAULTS.maxWorkerConcurrency,
maxSubscriptionsPerWebSocket: config.maxSubscriptionsPerWebSocket ?? constants_js_1.DEFAULTS.maxSubscriptionsPerWebSocket,
restBaseUrl: config.restBaseUrl ?? constants_js_1.DEFAULTS.restBaseUrl,

@@ -133,2 +139,5 @@ serverConnectionRecoveryDelay: config.serverConnectionRecoveryDelay ?? constants_js_1.DEFAULTS.serverConnectionRecoveryDelay,

const { id, name } = message.content;
if (typeof id === 'undefined') {
throw new Error('me-group-invite-create subscription message did not contain group information.');
}
this.logger.info(`Accepting invite to group ${id} (${name})`);

@@ -144,2 +153,5 @@ this.api.acceptGroupInvite(id);

const { group, member } = message.content;
if (typeof group === 'undefined' || typeof member === 'undefined') {
throw new Error('me-group-create subscription message did not contain group or member information.');
}
this.logger.info(`Client was added to group ${group.id} (${group.name}).`);

@@ -154,6 +166,8 @@ this.addGroup(group, member);

try {
const groupId = message.content.group.id;
const groupName = message.content.group.name;
this.logger.info(`Client was removed from group ${groupId} (${groupName}).`);
this.removeGroup(groupId);
const { group } = message.content;
if (typeof group === 'undefined') {
throw new Error('me-group-delete subscription message did not contain group information.');
}
this.logger.info(`Client was removed from group ${group.id} (${group.name}).`);
this.removeGroup(group.id);
}

@@ -244,3 +258,3 @@ catch (error) {

const { access_token: accessToken } = data;
this.logger.debug('Found access token.', accessToken);
this.logger.debug('Found access token.');
return accessToken;

@@ -247,0 +261,0 @@ }

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

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

@@ -13,3 +13,3 @@ const SECOND = 1000;

const MAX_WORKER_CONCURRENCY = 5;
const MAX_SUBSCRIPTIONS_PER_WEBSOCKET = 50;
const MAX_SUBSCRIPTIONS_PER_WEBSOCKET = 500;
exports.MAX_WORKER_CONCURRENCY_WARNING = 10;

@@ -35,2 +35,3 @@ const REST_BASE_URL = 'https://webapi.townshiptale.com/api';

includedGroups: [],
logPrefix: '[att-client]',
logVerbosity: 2,

@@ -37,0 +38,0 @@ restBaseUrl: REST_BASE_URL,

@@ -7,2 +7,6 @@ "use strict";

class Logger {
logError;
logWarn;
logInfo;
logDebug;
error;

@@ -12,9 +16,14 @@ warn;

debug;
constructor(verbosity, console = nativeConsole) {
this.error = verbosity >= 1 ? console.error : noOpFn;
this.warn = verbosity >= 2 ? console.warn : noOpFn;
this.info = verbosity >= 3 ? console.info : noOpFn;
this.debug = verbosity >= 4 ? console.debug : noOpFn;
constructor({ verbosity, console = nativeConsole, prefix }) {
this.logError = verbosity >= 1 ? console.error : noOpFn;
this.logWarn = verbosity >= 2 ? console.warn : noOpFn;
this.logInfo = verbosity >= 3 ? console.info : noOpFn;
this.logDebug = verbosity >= 4 ? console.debug : noOpFn;
const separator = prefix.length === 0 ? '' : ' ';
this.error = (...args) => this.logError(`${prefix}${separator}${args.shift()}`, ...args);
this.warn = (...args) => this.logWarn(`${prefix}${separator}${args.shift()}`, ...args);
this.info = (...args) => this.logInfo(`${prefix}${separator}${args.shift()}`, ...args);
this.debug = (...args) => this.logDebug(`${prefix}${separator}${args.shift()}`, ...args);
}
}
exports.Logger = Logger;

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

});
this.client.logger.debug(`Sending message-${id}.`, message);
this.client.logger.debug(`Sending message-${id}.`, JSON.stringify({ id, method, path, content: JSON.stringify(payload) }));
this.ws.send(message, error => error && reject(this.createErrorMessage(error.message ?? 'Unknown error.')));

@@ -313,0 +313,0 @@ }).catch((message) => {

@@ -41,4 +41,6 @@ "use strict";

this.subscriptionsMap.delete(subscription);
if (subscriptions.getSize() === 0)
if (subscriptions.getSize() === 0) {
this.client.logger.debug(`Subscriptions instance ${instanceId} is empty. Cleaning up.`);
this.instances.delete(instanceId);
}
return unsubscribeResult;

@@ -55,2 +57,3 @@ }

}
this.client.logger.debug('Increasing the Subscriptions instance pool.');
const subscriptions = new Subscriptions_js_1.Subscriptions(this.client);

@@ -60,2 +63,3 @@ const instanceId = this.getInstanceId();

await subscriptions.init();
this.client.logger.debug(`Created new Subscriptions instance with ID ${instanceId}.`);
return [instanceId, subscriptions];

@@ -62,0 +66,0 @@ }

@@ -30,10 +30,15 @@ import { createHash } from 'node:crypto';

const configuredConsole = config.console ?? DEFAULTS.console;
const configuredLogPrefix = config.logPrefix ?? DEFAULTS.logPrefix;
if (typeof config.logVerbosity === 'undefined') {
configuredConsole.warn("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 ? '' : ' '}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('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 ? '' : ' '}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.`);
}
const configuredLogVerbosity = config.logVerbosity ?? DEFAULTS.logVerbosity;
this.logger = new Logger(configuredLogVerbosity, configuredConsole);
this.logger = new Logger({
console: configuredConsole,
prefix: configuredLogPrefix,
verbosity: configuredLogVerbosity
});
this.logger.info('Configuring client.');

@@ -85,5 +90,6 @@ if ('clientId' in config) {

includedGroups: config.includedGroups ?? DEFAULTS.includedGroups,
logPrefix: configuredLogPrefix,
logVerbosity: configuredLogVerbosity,
maxSubscriptionsPerWebSocket: config.maxSubscriptionsPerWebSocket ?? DEFAULTS.maxSubscriptionsPerWebSocket,
maxWorkerConcurrency: config.maxWorkerConcurrency ?? DEFAULTS.maxWorkerConcurrency,
maxSubscriptionsPerWebSocket: config.maxSubscriptionsPerWebSocket ?? DEFAULTS.maxSubscriptionsPerWebSocket,
restBaseUrl: config.restBaseUrl ?? DEFAULTS.restBaseUrl,

@@ -127,2 +133,5 @@ serverConnectionRecoveryDelay: config.serverConnectionRecoveryDelay ?? DEFAULTS.serverConnectionRecoveryDelay,

const { id, name } = message.content;
if (typeof id === 'undefined') {
throw new Error('me-group-invite-create subscription message did not contain group information.');
}
this.logger.info(`Accepting invite to group ${id} (${name})`);

@@ -138,2 +147,5 @@ this.api.acceptGroupInvite(id);

const { group, member } = message.content;
if (typeof group === 'undefined' || typeof member === 'undefined') {
throw new Error('me-group-create subscription message did not contain group or member information.');
}
this.logger.info(`Client was added to group ${group.id} (${group.name}).`);

@@ -148,6 +160,8 @@ this.addGroup(group, member);

try {
const groupId = message.content.group.id;
const groupName = message.content.group.name;
this.logger.info(`Client was removed from group ${groupId} (${groupName}).`);
this.removeGroup(groupId);
const { group } = message.content;
if (typeof group === 'undefined') {
throw new Error('me-group-delete subscription message did not contain group information.');
}
this.logger.info(`Client was removed from group ${group.id} (${group.name}).`);
this.removeGroup(group.id);
}

@@ -238,3 +252,3 @@ catch (error) {

const { access_token: accessToken } = data;
this.logger.debug('Found access token.', accessToken);
this.logger.debug('Found access token.');
return accessToken;

@@ -241,0 +255,0 @@ }

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

@@ -9,3 +9,3 @@ const SECOND = 1000;

const MAX_WORKER_CONCURRENCY = 5;
const MAX_SUBSCRIPTIONS_PER_WEBSOCKET = 50;
const MAX_SUBSCRIPTIONS_PER_WEBSOCKET = 500;
export const MAX_WORKER_CONCURRENCY_WARNING = 10;

@@ -31,2 +31,3 @@ const REST_BASE_URL = 'https://webapi.townshiptale.com/api';

includedGroups: [],
logPrefix: '[att-client]',
logVerbosity: 2,

@@ -33,0 +34,0 @@ restBaseUrl: REST_BASE_URL,

const nativeConsole = console;
const noOpFn = (...args) => void 0;
export class Logger {
logError;
logWarn;
logInfo;
logDebug;
error;

@@ -8,8 +12,13 @@ warn;

debug;
constructor(verbosity, console = nativeConsole) {
this.error = verbosity >= 1 ? console.error : noOpFn;
this.warn = verbosity >= 2 ? console.warn : noOpFn;
this.info = verbosity >= 3 ? console.info : noOpFn;
this.debug = verbosity >= 4 ? console.debug : noOpFn;
constructor({ verbosity, console = nativeConsole, prefix }) {
this.logError = verbosity >= 1 ? console.error : noOpFn;
this.logWarn = verbosity >= 2 ? console.warn : noOpFn;
this.logInfo = verbosity >= 3 ? console.info : noOpFn;
this.logDebug = verbosity >= 4 ? console.debug : noOpFn;
const separator = prefix.length === 0 ? '' : ' ';
this.error = (...args) => this.logError(`${prefix}${separator}${args.shift()}`, ...args);
this.warn = (...args) => this.logWarn(`${prefix}${separator}${args.shift()}`, ...args);
this.info = (...args) => this.logInfo(`${prefix}${separator}${args.shift()}`, ...args);
this.debug = (...args) => this.logDebug(`${prefix}${separator}${args.shift()}`, ...args);
}
}

@@ -307,3 +307,3 @@ import { EventEmitter } from 'node:events';

});
this.client.logger.debug(`Sending message-${id}.`, message);
this.client.logger.debug(`Sending message-${id}.`, JSON.stringify({ id, method, path, content: JSON.stringify(payload) }));
this.ws.send(message, error => error && reject(this.createErrorMessage(error.message ?? 'Unknown error.')));

@@ -310,0 +310,0 @@ }).catch((message) => {

@@ -38,4 +38,6 @@ import { Subscriptions } from '../Subscriptions/Subscriptions.js';

this.subscriptionsMap.delete(subscription);
if (subscriptions.getSize() === 0)
if (subscriptions.getSize() === 0) {
this.client.logger.debug(`Subscriptions instance ${instanceId} is empty. Cleaning up.`);
this.instances.delete(instanceId);
}
return unsubscribeResult;

@@ -52,2 +54,3 @@ }

}
this.client.logger.debug('Increasing the Subscriptions instance pool.');
const subscriptions = new Subscriptions(this.client);

@@ -57,4 +60,5 @@ const instanceId = this.getInstanceId();

await subscriptions.init();
this.client.logger.debug(`Created new Subscriptions instance with ID ${instanceId}.`);
return [instanceId, subscriptions];
}
}

@@ -8,5 +8,6 @@ import type { ServerFleet } from '../Api/index.js';

includedGroups?: number[];
logPrefix?: string;
logVerbosity?: Verbosity;
maxSubscriptionsPerWebSocket?: number;
maxWorkerConcurrency?: number;
maxSubscriptionsPerWebSocket?: number;
restBaseUrl?: string;

@@ -13,0 +14,0 @@ serverConnectionRecoveryDelay?: number;

@@ -8,3 +8,12 @@ export declare const enum Verbosity {

}
interface LoggerArgs {
console?: Pick<Console, 'error' | 'warn' | 'info' | 'debug'>;
prefix: string;
verbosity: Verbosity;
}
export declare class Logger {
private logError;
private logWarn;
private logInfo;
private logDebug;
error: Console['error'];

@@ -14,3 +23,4 @@ warn: Console['warn'];

debug: Console['debug'];
constructor(verbosity: Verbosity, console?: Pick<Console, 'error' | 'warn' | 'info' | 'debug'>);
constructor({ verbosity, console, prefix }: LoggerArgs);
}
export {};

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

export type SubscriptionEvent = 'DebugLog' | 'ErrorLog' | 'FatalLog' | 'InfoLog' | 'InventoryChanged' | 'ObjectKilled' | 'PlayerJoined' | 'PlayerKilled' | 'PlayerLeft' | 'PlayerMovedChunk' | 'PlayerStateChanged' | 'PopulationModified' | 'ProfilingData' | 'SocialTabletPlayerReported' | 'TraceLog' | 'TradeDeckUsed' | 'TrialFinished' | 'TrialStarted' | 'WarnLog';
export type SubscriptionEvent = 'AtmBalanceChanged' | 'CommandExecuted' | 'DebugLog' | 'ErrorLog' | 'FatalLog' | 'InfoLog' | 'InventoryChanged' | 'ObjectKilled' | 'PlayerJoined' | 'PlayerKilled' | 'PlayerLeft' | 'PlayerMovedChunk' | 'PlayerStateChanged' | 'PopulationModified' | 'ProfilingData' | 'SocialTabletPlayerReported' | 'SocialTabletPlayerBanned' | 'TraceLog' | 'TradeDeckUsed' | 'TrialFinished' | 'TrialStarted' | 'WarnLog';
import type { CommonMessage } from './CommonMessage.js';
import type { SubscriptionEvent } from './SubscriptionEvent.js';
type AtmBalanceChangedEventMessage = CommonMessage<'Subscription'> & {
eventType: 'AtmBalanceChanged';
data: {
user: {
id: number;
username: string;
};
Change: number;
CurrentBalance: number;
};
};
type CommandExecutedEventMessage = CommonMessage<'Subscription'> & {
eventType: 'CommandExecuted';
data: {
Command: string;
WasSuccessful: boolean;
Message?: string;
};
};
type DebugLogSubscriptionEventMessage = CommonMessage<'Subscription'> & {

@@ -142,2 +161,16 @@ eventType: 'DebugLog';

};
type SocialTabletPlayerBannedEventMessage = CommonMessage<'Subscription'> & {
eventType: 'InventoryChanged';
data: {
BannedBy: {
id: number;
username: string;
};
BannedPlayer: {
id: number;
username: string;
};
isBan: boolean;
};
};
type TraceLogSubscriptionEventMessage = CommonMessage<'Subscription'> & {

@@ -174,3 +207,3 @@ eventType: 'TraceLog';

};
type SubscriptionEventMessageUnion = DebugLogSubscriptionEventMessage | ErrorLogSubscriptionEventMessage | FatalLogSubscriptionEventMessage | InfoLogSubscriptionEventMessage | InventoryChangedSubscriptionEventMessage | ObjectKilledSubscriptionEventMessage | PlayerJoinedSubscriptionEventMessage | PlayerKilledSubscriptionEventMessage | PlayerLeftSubscriptionEventMessage | PlayerMovedChunkSubscriptionEventMessage | PlayerStateChangedSubscriptionEventMessage | PopulationModifiedSubscriptionEventMessage | ProfilingDataSubscriptionEventMessage | TraceLogSubscriptionEventMessage | TradeDeckUsedSubscriptionEventMessage | TrialFinishedSubscriptionEventMessage | TrialStartedSubscriptionEventMessage | SocialTabletPlayerReportedSubscriptionEventMessage | WarnLogSubscriptionEventMessage;
type SubscriptionEventMessageUnion = AtmBalanceChangedEventMessage | CommandExecutedEventMessage | DebugLogSubscriptionEventMessage | ErrorLogSubscriptionEventMessage | FatalLogSubscriptionEventMessage | InfoLogSubscriptionEventMessage | InventoryChangedSubscriptionEventMessage | ObjectKilledSubscriptionEventMessage | PlayerJoinedSubscriptionEventMessage | PlayerKilledSubscriptionEventMessage | PlayerLeftSubscriptionEventMessage | PlayerMovedChunkSubscriptionEventMessage | PlayerStateChangedSubscriptionEventMessage | PopulationModifiedSubscriptionEventMessage | ProfilingDataSubscriptionEventMessage | TraceLogSubscriptionEventMessage | TradeDeckUsedSubscriptionEventMessage | TrialFinishedSubscriptionEventMessage | TrialStartedSubscriptionEventMessage | SocialTabletPlayerReportedSubscriptionEventMessage | SocialTabletPlayerBannedEventMessage | WarnLogSubscriptionEventMessage;
export type SubscriptionEventMessage<T extends SubscriptionEvent> = Extract<SubscriptionEventMessageUnion, {

@@ -177,0 +210,0 @@ eventType: T;

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

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

"engines": {
"node": ">=18.2.0 <19"
"node": ">=18.2.0 <19 || >=20"
},

@@ -60,0 +60,0 @@ "type": "module",

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