@squarecloud/api
Version:
A NodeJS wrapper for Square Cloud API
210 lines (207 loc) • 6.04 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// src/structures/status.ts
var status_exports = {};
__export(status_exports, {
ApplicationStatus: () => ApplicationStatus,
SimpleApplicationStatus: () => SimpleApplicationStatus
});
module.exports = __toCommonJS(status_exports);
// src/lib/routes.ts
var Route = (route) => route;
var Routes = {
user: () => {
return Route("users/me");
},
service: {
status: () => {
return Route("service/status");
}
},
apps: {
upload: () => {
return Route("apps");
},
statusAll: () => {
return Route("apps/status");
},
info: (appId) => {
return Route(`apps/${appId}`);
},
status: (appId) => {
return Route(`apps/${appId}/status`);
},
logs: (appId) => {
return Route(`apps/${appId}/logs`);
},
delete: (appId) => {
return Route(`apps/${appId}`);
},
commit: (appId) => {
return Route(`apps/${appId}/commit`);
},
snapshots: (appId) => {
return Route(`apps/${appId}/snapshots`);
},
generateSnapshot: (appId) => {
return Route(`apps/${appId}/snapshots`);
},
start: (appId) => {
return Route(`apps/${appId}/start`);
},
restart: (appId) => {
return Route(`apps/${appId}/restart`);
},
stop: (appId) => {
return Route(`apps/${appId}/stop`);
},
files: {
read: (appId) => {
return Route(`apps/${appId}/files/content`);
},
list: (appId) => {
return Route(`apps/${appId}/files`);
},
upsert: (appId) => {
return Route(`apps/${appId}/files`);
},
move: (appId) => {
return Route(`apps/${appId}/files`);
},
delete: (appId) => {
return Route(`apps/${appId}/files`);
}
},
deployments: {
list: (appId) => {
return Route(`apps/${appId}/deployments`);
},
current: (appId) => {
return Route(
`apps/${appId}/deployments/current`
);
},
webhook: (appId) => {
return Route(
`apps/${appId}/deploy/webhook`
);
}
},
network: {
dns: (appId) => {
return Route(`apps/${appId}/network/dns`);
},
custom: (appId) => {
return Route(`apps/${appId}/network/custom`);
},
analytics: (appId) => {
return Route(
`apps/${appId}/network/analytics`
);
}
}
}
};
// src/structures/status.ts
var SimpleApplicationStatus = class {
/**
* Represents an application status fetched from status all endpoint
*
* @constructor
* @param client - The client for this status
* @param data - The data from this status
*/
constructor(client, data) {
this.client = client;
/** The application's ID this status came from */
__publicField(this, "applicationId");
/** Usage statuses for this application */
__publicField(this, "usage");
/** Whether the application is running or not */
__publicField(this, "running");
const { id, running } = data;
this.applicationId = id;
this.running = running;
if (running) {
const { cpu, ram } = data;
this.usage = { cpu, ram };
}
}
/**
* Fetches the full application status
*/
async fetch() {
const data = await this.client.api.request(
Routes.apps.status(this.applicationId)
);
return new ApplicationStatus(
this.client,
data.response,
this.applicationId
);
}
};
var ApplicationStatus = class {
/**
* Represents an application status
*
* @constructor
* @param client - The client for this status
* @param data - The data from this status
* @param applicationId - The application ID this status came from
*/
constructor(client, data, applicationId) {
this.client = client;
/** The application's ID this status came from */
__publicField(this, "applicationId");
/** Usage statuses for this application */
__publicField(this, "usage");
/** Whether the application is running or not */
__publicField(this, "running");
/**
* The status of the application
*
* - 'exited' (stopped)
* - 'created' (being created)
* - 'running'
* - 'starting'
* - 'restarting'
* - 'deleting'
*/
__publicField(this, "status");
/** For how long the app is running in millisseconds */
__publicField(this, "uptimeTimestamp");
/** For how long the app is running */
__publicField(this, "uptime");
const { cpu, ram, network, storage, running, status, uptime } = data;
this.applicationId = applicationId;
this.usage = { cpu, ram, network, storage };
this.running = running;
this.status = status;
this.uptime = uptime ? new Date(uptime) : void 0;
this.uptimeTimestamp = uptime ?? void 0;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ApplicationStatus,
SimpleApplicationStatus
});
//# sourceMappingURL=status.cjs.map