@apillon/sdk
Version:
▶◀ Apillon SDK for NodeJS ▶◀
127 lines • 4.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostingWebsite = void 0;
const common_1 = require("../../lib/common");
const hosting_1 = require("../../types/hosting");
const deployment_1 = require("./deployment");
const apillon_api_1 = require("../../lib/apillon-api");
const apillon_logger_1 = require("../../lib/apillon-logger");
const file_utils_1 = require("../../util/file-utils");
const apillon_1 = require("../../lib/apillon");
class HostingWebsite extends apillon_1.ApillonModel {
/**
* Constructor which should only be called via Hosting class.
* @param uuid Unique identifier of the website.
* @param data Data to populate the website with.
*/
constructor(uuid, data) {
super(uuid);
/**
* User assigned name of the website.
*/
this.name = null;
/**
* User assigned description of the website.
*/
this.description = null;
/**
* Domain on which this website lives.
*/
this.domain = null;
/**
* Unique identifier of a storage bucket in which this website files reside.
*/
this.bucketUuid = null;
/**
* IPNS CID for staging environment.
* @deprecated - Use `cidStaging` instead
*/
this.ipnsStaging = null;
/**
* IPFS CID for staging environment.
*/
this.cidStaging = null;
/**
* IPFS CID for production environment.
*/
this.cidProduction = null;
/**
* IPNS CID for production environment.
*/
this.ipnsProduction = null;
/**
* Link to staging version of the website
*/
this.w3StagingLink = null;
/**
* Link to production version of the website
*/
this.w3ProductionLink = null;
/**
* Website last deployment (to any environment) unique identifier
*/
this.lastDeploymentUuid = null;
/**
* Status of last deployment
*/
this.lastDeploymentStatus = null;
this.API_PREFIX = `/hosting/websites/${uuid}`;
this.populate(data);
}
/**
* Uploads website files inside a folder via path.
* @param folderPath Path to the folder to upload.
* @param {IFileUploadRequest} params - Optional parameters to be used for uploading files
*/
async uploadFromFolder(folderPath, params) {
await (0, file_utils_1.uploadFiles)({ apiPrefix: this.API_PREFIX, folderPath, params });
}
/**
* Uploads files to the hosting bucket.
* @param {FileMetadata[]} files - The files to be uploaded
* @param {IFileUploadRequest} params - Optional parameters to be used for uploading files
*/
async uploadFiles(files, params) {
await (0, file_utils_1.uploadFiles)({ apiPrefix: this.API_PREFIX, params, files });
}
/**
* Deploy a website to a new environment.
* @param {DeployToEnvironment} toEnvironment The environment to deploy to
* @returns Newly created deployment
*/
async deploy(toEnvironment) {
apillon_logger_1.ApillonLogger.log(`Deploying website ${this.uuid} to IPFS (${toEnvironment === hosting_1.DeployToEnvironment.TO_STAGING
? 'preview'
: 'production'})`);
apillon_logger_1.ApillonLogger.logWithTime('Initiating deployment');
const data = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/deploy`, { environment: toEnvironment });
apillon_logger_1.ApillonLogger.logWithTime('Deployment in progress');
return new deployment_1.Deployment(this.uuid, data.deploymentUuid, data);
}
/**
* @param {IWebsiteFilters} params Query filters for listing websites
* @returns A list of all deployments instances.
*/
async listDeployments(params) {
const url = (0, common_1.constructUrlWithQueryParams)(`${this.API_PREFIX}/deployments`, params);
const data = await apillon_api_1.ApillonApi.get(url);
return Object.assign(Object.assign({}, data), { items: data.items.map((item) => new deployment_1.Deployment(item.websiteUuid, item.deploymentUuid, item)) });
}
/**
* Gets a deployment instance.
* @param deploymentUuid Uuid of the deployment.
* @returns Instance of a deployment.
*/
deployment(deploymentUuid) {
return new deployment_1.Deployment(this.uuid, deploymentUuid, {});
}
serializeFilter(key, value) {
const serialized = super.serializeFilter(key, value);
const enums = {
lastDeploymentStatus: hosting_1.DeploymentStatus[value],
};
return Object.keys(enums).includes(key) ? enums[key] : serialized;
}
}
exports.HostingWebsite = HostingWebsite;
//# sourceMappingURL=hosting-website.js.map