@squarecloud/api
Advanced tools
@@ -9,5 +9,5 @@ import { APIResponse, RawUserData } from './typings'; | ||
| constructor(apiKey: string); | ||
| private fetch; | ||
| fetch(path: string, options?: AxiosRequestConfig): Promise<any>; | ||
| user(id?: string, options?: AxiosRequestConfig): Promise<RawUserData>; | ||
| application(path: string, id: string, options?: AxiosRequestConfig | boolean): Promise<APIResponse>; | ||
| } |
| /// <reference types="node" /> | ||
| /// <reference types="node" /> | ||
| import { ReadStream } from 'fs'; | ||
| export declare function validateString(value: any, code?: string, starts?: string): asserts value is string; | ||
| export declare function validateBoolean(value: any, code?: string): asserts value is boolean; | ||
| export declare function validateCommitLike(value: any, code?: string): asserts value is string | ReadStream | Buffer; | ||
| export declare function validatePathLike(value: any, code?: string): asserts value is string | Buffer; |
@@ -6,5 +6,4 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.validateCommitLike = exports.validateBoolean = exports.validateString = void 0; | ||
| exports.validatePathLike = exports.validateBoolean = exports.validateString = void 0; | ||
| const APIManager_1 = require("./APIManager"); | ||
| const fs_1 = require("fs"); | ||
| const zod_1 = __importDefault(require("zod")); | ||
@@ -21,11 +20,9 @@ function validateString(value, code, starts = '') { | ||
| exports.validateBoolean = validateBoolean; | ||
| function validateCommitLike(value, code) { | ||
| function validatePathLike(value, code) { | ||
| handleParser(() => zod_1.default | ||
| .string() | ||
| .or(zod_1.default | ||
| .custom((value) => value instanceof fs_1.ReadStream) | ||
| .or(zod_1.default.custom((value) => value instanceof Buffer))) | ||
| .parse(value), 'Expect string, ReadStream or Buffer, got ' + typeof value, code); | ||
| .or(zod_1.default.custom((value) => value instanceof Buffer)) | ||
| .parse(value), 'Expect string or Buffer, got ' + typeof value, code); | ||
| } | ||
| exports.validateCommitLike = validateCommitLike; | ||
| exports.validatePathLike = validatePathLike; | ||
| function handleParser(func, message, code) { | ||
@@ -32,0 +29,0 @@ try { |
+19
-2
@@ -0,1 +1,2 @@ | ||
| /// <reference types="node" /> | ||
| import { APIManager } from './APIManager'; | ||
@@ -19,3 +20,3 @@ import { Application } from './structures/Application'; | ||
| * | ||
| * @param userId - The user id, if not provided it will get your own information | ||
| * @param userId - The user ID, if not provided it will get your own information | ||
| */ | ||
@@ -27,7 +28,23 @@ getUser(): Promise<FullUser>; | ||
| * | ||
| * @param appId - The application id, you must own the application | ||
| * @param appId - The application ID, you must own the application | ||
| */ | ||
| getApplication(appId: string): Promise<Application>; | ||
| /** | ||
| * Upload a new application to Square Cloud | ||
| * | ||
| * - Don't forget the [configuration file](https://config.squarecloud.app/). | ||
| * - This only accepts .zip files. | ||
| * | ||
| * - Tip: use this to get an absolute path. | ||
| * ```ts | ||
| * require('path').join(__dirname, 'fileName') | ||
| * ``` | ||
| * | ||
| * @param file - Buffer or absolute path to the file | ||
| * | ||
| * @returns The uploaded application ID | ||
| */ | ||
| uploadApplication(file: string | Buffer): Promise<string>; | ||
| } | ||
| export default SquareCloudAPI; | ||
| export type { Application, FullUser, User }; |
+36
-2
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const form_data_1 = __importDefault(require("form-data")); | ||
| const promises_1 = require("fs/promises"); | ||
| const APIManager_1 = require("./APIManager"); | ||
| const Assertions_1 = require("./Assertions"); | ||
| const Application_1 = require("./structures/Application"); | ||
| const User_1 = require("./structures/User"); | ||
| const Assertions_1 = require("./Assertions"); | ||
| class SquareCloudAPI { | ||
@@ -32,3 +37,3 @@ static apiInfo = { | ||
| * | ||
| * @param appId - The application id, you must own the application | ||
| * @param appId - The application ID, you must own the application | ||
| */ | ||
@@ -45,4 +50,33 @@ async getApplication(appId) { | ||
| } | ||
| /** | ||
| * Upload a new application to Square Cloud | ||
| * | ||
| * - Don't forget the [configuration file](https://config.squarecloud.app/). | ||
| * - This only accepts .zip files. | ||
| * | ||
| * - Tip: use this to get an absolute path. | ||
| * ```ts | ||
| * require('path').join(__dirname, 'fileName') | ||
| * ``` | ||
| * | ||
| * @param file - Buffer or absolute path to the file | ||
| * | ||
| * @returns The uploaded application ID | ||
| */ | ||
| async uploadApplication(file) { | ||
| (0, Assertions_1.validatePathLike)(file, 'UPLOAD_DATA'); | ||
| if (!(file instanceof Buffer)) { | ||
| file = await (0, promises_1.readFile)(file); | ||
| } | ||
| const formData = new form_data_1.default(); | ||
| formData.append('file', file, { filename: 'app.zip' }); | ||
| const { app } = await this.apiManager.fetch('upload', { | ||
| method: 'POST', | ||
| data: formData.getBuffer(), | ||
| headers: formData.getHeaders(), | ||
| }); | ||
| return app?.id; | ||
| } | ||
| } | ||
| module.exports = Object.assign(SquareCloudAPI, { default: SquareCloudAPI }); | ||
| exports.default = SquareCloudAPI; |
| /// <reference types="node" /> | ||
| /// <reference types="node" /> | ||
| import { RawApplicationData, ApplicationStatusData } from '../typings'; | ||
| import { ReadStream } from 'fs'; | ||
| import { ApplicationStatusData, RawApplicationData } from '../typings'; | ||
| import { APIManager } from '../APIManager'; | ||
@@ -15,3 +13,3 @@ /** | ||
| #private; | ||
| /** The application id */ | ||
| /** The application ID */ | ||
| id: string; | ||
@@ -46,3 +44,3 @@ /** The application Discord tag */ | ||
| */ | ||
| getLogs(full?: boolean): Promise<any>; | ||
| getLogs(full?: boolean): Promise<string>; | ||
| /** Generates the backup download URL */ | ||
@@ -66,2 +64,3 @@ backup(): Promise<string>; | ||
| * - This action is irreversible. | ||
| * | ||
| * - Tip: use this to get an absolute path. | ||
@@ -73,7 +72,6 @@ * ```ts | ||
| * | ||
| * @param file - The absolute file path, a Buffer or a ReadStream | ||
| * @param fileName - If a Buffer is provided you must provide the file name and extension too | ||
| * @param file - Buffer or absolute path to the file | ||
| * @param fileName - The file name (e.g.: "index.js") | ||
| */ | ||
| commit(file: string | ReadStream): Promise<boolean>; | ||
| commit(file: Buffer, fileName: string): Promise<boolean>; | ||
| commit(file: string | Buffer, fileName?: string): Promise<boolean>; | ||
| } |
@@ -8,4 +8,4 @@ "use strict"; | ||
| const Assertions_1 = require("../Assertions"); | ||
| const fs_1 = require("fs"); | ||
| const form_data_1 = __importDefault(require("form-data")); | ||
| const promises_1 = require("fs/promises"); | ||
| /** | ||
@@ -19,3 +19,3 @@ * Represents a SquareCloud application | ||
| class Application { | ||
| /** The application id */ | ||
| /** The application ID */ | ||
| id; | ||
@@ -67,4 +67,4 @@ /** The application Discord tag */ | ||
| uptimeTimestamp: uptime || 0, | ||
| uptime: uptime ? new Date(uptime) : null, | ||
| lastCheckTimestamp: time, | ||
| uptime: uptime ? new Date(uptime) : undefined, | ||
| lastCheckTimestamp: time || 0, | ||
| lastCheck: time ? new Date(time) : undefined, | ||
@@ -110,12 +110,26 @@ }; | ||
| } | ||
| /** | ||
| * Commit changes to a specific file inside your application folder | ||
| * | ||
| * - This action is irreversible. | ||
| * | ||
| * - Tip: use this to get an absolute path. | ||
| * ```ts | ||
| * require('path').join(__dirname, 'fileName') | ||
| * ``` | ||
| * - Tip2: use zip file to commit more than one file | ||
| * | ||
| * @param file - Buffer or absolute path to the file | ||
| * @param fileName - The file name (e.g.: "index.js") | ||
| */ | ||
| async commit(file, fileName) { | ||
| (0, Assertions_1.validateCommitLike)(file, 'COMMIT_DATA'); | ||
| const formData = new form_data_1.default(); | ||
| if (file instanceof Buffer) { | ||
| (0, Assertions_1.validatePathLike)(file, 'COMMIT_DATA'); | ||
| if (fileName) { | ||
| (0, Assertions_1.validateString)(fileName, 'FILE_NAME'); | ||
| formData.append('file', file, { filename: fileName }); | ||
| } | ||
| else { | ||
| formData.append('file', file instanceof fs_1.ReadStream ? file : (0, fs_1.createReadStream)(file)); | ||
| if (!(file instanceof Buffer)) { | ||
| file = await (0, promises_1.readFile)(file); | ||
| } | ||
| const formData = new form_data_1.default(); | ||
| formData.append('file', file, { filename: fileName }); | ||
| const { code } = await this.#apiManager.application('commit', this.id, { | ||
@@ -122,0 +136,0 @@ method: 'POST', |
@@ -28,6 +28,7 @@ "use strict"; | ||
| ...data.user.plan, | ||
| duration: { | ||
| formatted: data.user.plan.duration.formatted, | ||
| timestamp: data.user.plan.duration.raw, | ||
| }, | ||
| duration: data.user.plan.duration.formatted, | ||
| purchasedTimestamp: data.user.plan.duration.raw, | ||
| purchased: data.user.plan.duration.raw | ||
| ? new Date(data.user.plan.duration.raw) | ||
| : undefined, | ||
| }; | ||
@@ -34,0 +35,0 @@ this.hasAccess = () => data.user.email !== 'Access denied'; |
+4
-5
@@ -12,6 +12,5 @@ /** | ||
| }; | ||
| duration: { | ||
| formatted: string; | ||
| timestamp: number | null; | ||
| }; | ||
| duration: string; | ||
| purchasedTimestamp: number | null; | ||
| purchased?: Date; | ||
| } | ||
@@ -53,3 +52,3 @@ /** | ||
| /** For how long the app is running */ | ||
| uptime: Date | null; | ||
| uptime?: Date; | ||
| /** The last time this information has been checked in millisseconds */ | ||
@@ -56,0 +55,0 @@ lastCheckTimestamp?: number; |
+2
-2
| { | ||
| "name": "@squarecloud/api", | ||
| "version": "1.1.15", | ||
| "description": "A JavaScript Wrapper for SquareCloud API", | ||
| "version": "2.0.0", | ||
| "description": "A JavaScript Wrapper for the SquareCloud API", | ||
| "main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "types": "lib/index.d.ts", |
+1
-1
@@ -21,3 +21,3 @@ # **Installation** | Instalação | ||
| ```js | ||
| import { SquareCloudAPI } from '@squarecloud/api'; // JavaScript: const { SquareCloudAPI } = require('@squarecloud/api') | ||
| import SquareCloudAPI from '@squarecloud/api'; // JavaScript: const SquareCloudAPI = require('@squarecloud/api') | ||
@@ -24,0 +24,0 @@ const api = new SquareCloudAPI('Your API Key'); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
51562
4.02%1050
5.85%3
-40%7
16.67%