New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@squarecloud/api

Package Overview
Dependencies
Maintainers
2
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@squarecloud/api - npm Package Compare versions

Comparing version
1.1.0
to
1.1.1
+12
lib/APIManager.d.ts
import { APIResponse, RawUserData } from './typings';
import { AxiosRequestConfig } from 'axios';
export declare class SquareCloudAPIError extends Error {
constructor(code: string);
}
export declare class APIManager {
private apiKey;
constructor(apiKey: string);
private fetch;
user(id?: string, options?: AxiosRequestConfig): Promise<RawUserData>;
application(path: string, id: string, options?: AxiosRequestConfig | boolean): Promise<APIResponse>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.APIManager = exports.SquareCloudAPIError = void 0;
const axios_1 = __importDefault(require("axios"));
class SquareCloudAPIError extends Error {
constructor(code) {
super();
this.name = 'SquareCloudAPIError';
this.message = code
.replaceAll('_', ' ')
.toLowerCase()
.replace(/(^|\s)\S/g, (L) => L.toUpperCase());
}
}
exports.SquareCloudAPIError = SquareCloudAPIError;
class APIManager {
apiKey;
constructor(apiKey) {
this.apiKey = apiKey;
}
async fetch(path, options = {}) {
options.headers = {
...(options.headers || {}),
Authorization: this.apiKey,
};
options.method = options.method || 'GET';
const { data } = await (0, axios_1.default)('https://api.squarecloud.app/v1/public/' + path, options).catch((r) => r.response);
if (data.status === 'error') {
throw new SquareCloudAPIError(data.code);
}
return data;
}
user(id, options = {}) {
return this.fetch('user' + (id ? `/${id}` : ''), options).then((e) => e.response);
}
application(path, id, options = {}) {
return this.fetch(`${path}/${id}`, typeof options === 'boolean'
? options
? { method: 'POST' }
: {}
: options);
}
}
exports.APIManager = APIManager;
/// <reference types="node" />
import { ReadStream } from 'fs';
export declare function validateString(value: any): asserts value is string;
export declare function validateBoolean(value: any): asserts value is boolean;
export declare function validateCommitLike(value: any): asserts value is string | ReadStream;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCommitLike = exports.validateBoolean = exports.validateString = void 0;
const fs_1 = require("fs");
const zod_1 = __importDefault(require("zod"));
function validateString(value) {
zod_1.default.string().parse(value);
}
exports.validateString = validateString;
function validateBoolean(value) {
zod_1.default.boolean().parse(value);
}
exports.validateBoolean = validateBoolean;
function validateCommitLike(value) {
zod_1.default.string()
.or(zod_1.default.custom((value) => value instanceof fs_1.ReadStream))
.parse(value);
}
exports.validateCommitLike = validateCommitLike;
import { Application } from './structures/Application';
import { User } from './structures/User';
export declare class SquareCloudAPI {
static apiInfo: {
version: string;
baseUrl: string;
};
private apiManager;
/**
* Creates an API instance
*
* @param apiKey - Your API Token (you can get it at [SquareCloud Dashboard](https://squarecloud.app/dashboard))
*/
constructor(apiKey: string);
/**
* Gets a user's informations
*
* @param userId - The user id, if not provided it will get your own information
*/
getUser(userId?: string): Promise<User>;
/**
* Returns an application that you can manage or get information
*
* @param appId - The application id, you must own the application
*/
getApplication(appId: string): Promise<Application>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SquareCloudAPI = void 0;
const APIManager_1 = require("./APIManager");
const Application_1 = require("./structures/Application");
const User_1 = require("./structures/User");
const Assertions_1 = require("./Assertions");
class SquareCloudAPI {
static apiInfo = {
version: 'v1',
baseUrl: 'https://api.squarecloud.app/v1/public/',
};
apiManager;
/**
* Creates an API instance
*
* @param apiKey - Your API Token (you can get it at [SquareCloud Dashboard](https://squarecloud.app/dashboard))
*/
constructor(apiKey) {
(0, Assertions_1.validateString)(apiKey);
this.apiManager = new APIManager_1.APIManager(apiKey);
}
/**
* Gets a user's informations
*
* @param userId - The user id, if not provided it will get your own information
*/
async getUser(userId) {
(0, Assertions_1.validateString)(userId);
const userData = await this.apiManager.user(userId);
const hasAccess = userData.user.email !== 'Access denied';
return new (hasAccess ? User_1.FullUser : User_1.User)(this.apiManager, userData);
}
/**
* Returns an application that you can manage or get information
*
* @param appId - The application id, you must own the application
*/
async getApplication(appId) {
(0, Assertions_1.validateString)(appId);
const { applications } = await this.apiManager.user();
const appData = applications.find((app) => app.id === appId);
if (!appData) {
throw new APIManager_1.SquareCloudAPIError('APP_NOT_FOUND');
}
return new Application_1.Application(this.apiManager, appData);
}
}
exports.SquareCloudAPI = SquareCloudAPI;
/// <reference types="node" />
import { RawApplicationData, ApplicationStatusData } from '../typings';
import { ReadStream } from 'fs';
import { APIManager } from '../APIManager';
/**
* Represents a SquareCloud application
*
* @constructor
* @param apiManager - The APIManager for this application
* @param data - The data from this application
*/
export declare class Application {
private apiManager;
/** The application id */
id: string;
/** The application Discord tag */
tag: string;
/** The application total ram */
ram: number;
/**
* The application programming language
*
* - 'javascript'
* - 'typescript'
* - 'python'
* - 'java'
*/
lang: 'javascript' | 'typescript' | 'python' | 'java';
/** The application plan type (free' or 'paid') */
type: 'free' | 'paid';
/** The application avatar URL */
avatar: string;
/** The application current cluster */
cluster: string;
/** Whether the application is a website or not */
isWebsite: boolean;
constructor(apiManager: APIManager, data: RawApplicationData);
/** Gets the application's current information */
getStatus(): Promise<ApplicationStatusData>;
/** Gets the application logs
*
* @param full - Whether you want the complete logs (true) or the recent ones (false)
*/
getLogs(full?: boolean): Promise<any>;
/** Generates the backup download URL */
backup(): Promise<string>;
/** Starts up the application */
start(): Promise<boolean>;
/** Stops the application */
stop(): Promise<boolean>;
/** Restarts the application */
restart(): Promise<boolean>;
/**
* Deletes your whole application
*
* - This action is irreversible.
*/
delete(): Promise<boolean>;
/**
* Commit changes to a specific file inside your application folder
*
* - This action is irreversible.
* - Tip: use `require('path').join(__dirname, 'fileName')` to get an absolute path.
* - Tip2: use zip file to commit more than one file
*
* @param file - The absolute file path or a ReadStream
*/
commit(file: string | ReadStream): Promise<boolean>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Application = void 0;
const Assertions_1 = require("../Assertions");
const fs_1 = require("fs");
const form_data_1 = __importDefault(require("form-data"));
/**
* Represents a SquareCloud application
*
* @constructor
* @param apiManager - The APIManager for this application
* @param data - The data from this application
*/
class Application {
apiManager;
/** The application id */
id;
/** The application Discord tag */
tag;
/** The application total ram */
ram;
/**
* The application programming language
*
* - 'javascript'
* - 'typescript'
* - 'python'
* - 'java'
*/
lang;
/** The application plan type (free' or 'paid') */
type;
/** The application avatar URL */
avatar;
/** The application current cluster */
cluster;
/** Whether the application is a website or not */
isWebsite;
constructor(apiManager, data) {
this.apiManager = apiManager;
this.id = data.id;
this.tag = data.tag;
this.ram = data.ram;
this.lang = data.lang;
this.type = data.type;
this.avatar = data.avatar;
this.cluster = data.cluster;
this.isWebsite = data.isWebsite;
}
/** Gets the application's current information */
async getStatus() {
const { network, cpu, ram, storage, requests, running, status, uptime, time, } = (await this.apiManager.application('status', this.id)).response;
return {
status,
running,
network,
requests,
cpuUsage: cpu,
ramUsage: ram,
storageUsage: storage,
uptimeTimestamp: uptime || 0,
uptime: uptime ? new Date(uptime) : null,
lastCheckTimestamp: time,
lastCheck: time ? new Date(time) : undefined,
};
}
/** Gets the application logs
*
* @param full - Whether you want the complete logs (true) or the recent ones (false)
*/
async getLogs(full = false) {
(0, Assertions_1.validateBoolean)(full);
return (await this.apiManager.application(`${full ? 'full-' : ''}logs`, this.id)).response.logs;
}
/** Generates the backup download URL */
async backup() {
return (await this.apiManager.application('backup', this.id)).response
.downloadURL;
}
/** Starts up the application */
async start() {
const { code } = await this.apiManager.application('start', this.id, true);
return code === 'ACTION_SENT';
}
/** Stops the application */
async stop() {
const { code } = await this.apiManager.application('stop', this.id, true);
return code === 'ACTION_SENT';
}
/** Restarts the application */
async restart() {
const { code } = await this.apiManager.application('restart', this.id, true);
return code === 'ACTION_SENT';
}
/**
* Deletes your whole application
*
* - This action is irreversible.
*/
async delete() {
const { code } = await this.apiManager.application('delete', this.id, true);
return code === 'APP_DELETED';
}
/**
* Commit changes to a specific file inside your application folder
*
* - This action is irreversible.
* - Tip: use `require('path').join(__dirname, 'fileName')` to get an absolute path.
* - Tip2: use zip file to commit more than one file
*
* @param file - The absolute file path or a ReadStream
*/
async commit(file) {
(0, Assertions_1.validateCommitLike)(file);
const formData = new form_data_1.default();
formData.append('file', file instanceof fs_1.ReadStream ? file : (0, fs_1.createReadStream)(file));
const { code } = await this.apiManager.application('commit', this.id, {
method: 'POST',
data: formData,
headers: { ...formData.getHeaders() },
});
return code === 'SUCCESS';
}
}
exports.Application = Application;
import { AccountPlan, RawUserData } from '../typings';
import { Application } from './Application';
import { APIManager } from '../APIManager';
/**
* Represents a SquareCloud user
*
* @constructor
* @param apiManager - The APIManager for this user
* @param data - The data from this user
*/
export declare class User {
private apiManager;
/** The user's id */
id: string;
/** The user's Discord tag */
tag: string;
/** The user's current plan */
plan: AccountPlan;
/** Whether you have access to private information or not */
hasAccess: () => this is FullUser;
constructor(apiManager: APIManager, data: RawUserData);
/** Fetches the user data again and returns a new User */
fetch(): Promise<User>;
}
export declare class FullUser extends User {
/** The user's registered email */
email: string;
/** The user's registered applications */
applications: Application[];
constructor(apiManager: APIManager, data: RawUserData);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FullUser = exports.User = void 0;
const Application_1 = require("./Application");
/**
* Represents a SquareCloud user
*
* @constructor
* @param apiManager - The APIManager for this user
* @param data - The data from this user
*/
class User {
apiManager;
/** The user's id */
id;
/** The user's Discord tag */
tag;
/** The user's current plan */
plan;
/** Whether you have access to private information or not */
hasAccess;
constructor(apiManager, data) {
this.apiManager = apiManager;
this.id = data.user.id;
this.tag = data.user.tag;
this.plan = {
...data.user.plan,
duration: {
formatted: data.user.plan.duration.formatted,
timestamp: data.user.plan.duration.raw,
},
};
this.hasAccess = () => data.user.email !== 'Access denied';
}
/** Fetches the user data again and returns a new User */
fetch() {
return this.apiManager
.user(this.id)
.then((data) => new (this.hasAccess() ? FullUser : User)(this.apiManager, data));
}
}
exports.User = User;
class FullUser extends User {
/** The user's registered email */
email;
/** The user's registered applications */
applications;
constructor(apiManager, data) {
super(apiManager, data);
this.email = data.user.email;
this.applications = data.applications.map((data) => new Application_1.Application(apiManager, data));
}
}
exports.FullUser = FullUser;
/**
* USER
*/
declare type AccountPlanName = 'free' | 'medium' | 'advanced' | 'senior' | 'deluxe' | 'orion' | 'ultimate';
export interface AccountPlan {
name: AccountPlanName;
memory: {
limit: number;
available: number;
used: number;
};
duration: {
formatted: string;
timestamp: number | null;
};
}
/**
* APPLICATION
*/
declare type ApplicationLang = 'javascript' | 'typescript' | 'java' | 'python';
declare type ApplicationStatus = 'exited' | 'created' | 'starting' | 'restarting' | 'deleting' | 'running';
export interface ApplicationStatusData {
/** The application's network status */
network: {
total: string;
now: string;
};
/** How much storage the application is currently using */
storageUsage: string;
/** How much cpu the application is currently using */
cpuUsage: string;
/** How much memory the application is currently using */
ramUsage: string;
/**
* The status of the application
*
* - 'exited' (stopped)
* - 'created' (being created)
* - 'running'
* - 'starting'
* - 'restarting'
* - 'deleting'
*/
status: ApplicationStatus;
/** Whether the application is running or not */
running: boolean;
/** How many requests have been made since the last start up */
requests: 0;
/** For how long the app is running in millisseconds */
uptimeTimestamp: number;
/** For how long the app is running */
uptime: Date | null;
/** The last time this information has been checked in millisseconds */
lastCheckTimestamp?: number;
/** The last time this information has been checked */
lastCheck?: Date;
}
/** API */
export declare type APIResponse<T = any> = {
status: 'success';
code: string;
response: T;
};
export interface RawUserData {
user: {
id: string;
tag: string;
email: string;
plan: {
name: AccountPlanName;
memory: {
limit: number;
available: number;
used: number;
};
duration: {
formatted: string;
raw: number | null;
};
};
};
applications: RawApplicationData[];
}
export interface RawApplicationData {
id: string;
tag: string;
ram: number;
lang: ApplicationLang;
type: 'free' | 'paid';
cluster: string;
isWebsite: boolean;
avatar: string;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+2
-1
{
"name": "@squarecloud/api",
"version": "1.1.0",
"version": "1.1.1",
"description": "A JavaScript Wrapper for SquareCloud API",

@@ -35,4 +35,5 @@ "main": "lib/index.js",

"scripts": {
"latest": "pnpm build && pnpm publish",
"build": "tsc"
}
}