@squarecloud/api
Version:
A NodeJS wrapper for Square Cloud API
71 lines (70 loc) • 2.72 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/backup.ts
var backup_exports = {};
__export(backup_exports, {
Backup: () => Backup
});
module.exports = __toCommonJS(backup_exports);
var Backup = class {
/**
* Represents an application backup (snapshot)
*
* @constructor
* @param application - The application from which you fetched the backups
* @param data - The data from this backup
*/
constructor(application, data) {
this.application = application;
/** Size of the backup in bytes. */
__publicField(this, "size");
/** Date of the last modification of the backup. */
__publicField(this, "modifiedAt");
/** Date of the last modification of the backup in millisseconds. */
__publicField(this, "modifiedTimestamp");
/** AWS access key for the backup. */
__publicField(this, "key");
/** The URL for downloading this backup */
__publicField(this, "url");
const { name, size, modified, key } = data;
const { userId } = application.client.api;
this.size = size;
this.modifiedAt = new Date(modified);
this.modifiedTimestamp = this.modifiedAt.getTime();
this.key = key;
this.url = `https://snapshots.squarecloud.app/applications/${userId}/${name}.zip?${key}`;
}
/**
* Downloads this backup
* @returns The downloaded backup bufer
*/
async download() {
const res = await fetch(this.url).then((res2) => res2.arrayBuffer()).catch(() => void 0);
if (!res) {
throw new Error("BACKUP_DOWNLOAD_FAILED");
}
return Buffer.from(res);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Backup
});
//# sourceMappingURL=backup.cjs.map