UNPKG

@apillon/sdk

Version:

▶◀ Apillon SDK for NodeJS ▶◀

70 lines 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CloudFunction = void 0; const cloud_function_job_1 = require("./cloud-function-job"); const apillon_api_1 = require("../../lib/apillon-api"); const apillon_1 = require("../../lib/apillon"); const apillon_logger_1 = require("../../lib/apillon-logger"); class CloudFunction extends apillon_1.ApillonModel { /** * Constructor which should only be called via CloudFunctions class * @param data Data to populate cloud function with */ constructor(uuid, data) { super(uuid); /** * Unique identifier of the bucket where the cloud function code is stored */ this.bucketUuid = null; /** * Name of the cloud function */ this.name = null; /** * Description of the cloud function */ this.description = null; /** * Gateway URL of the cloud function, for triggering job execution */ this.gatewayUrl = null; /** * List of jobs associated with the cloud function */ this.jobs = []; this.API_PREFIX = `/cloud-functions/${this.uuid}`; this.populate(data); this.gatewayUrl = `https://${this.uuid}.${process.env.ACURAST_GATEWAY_URL}`; } /** * Gets and populates cloud function details. * @returns CloudFunction instance */ async get() { const data = await apillon_api_1.ApillonApi.get(this.API_PREFIX); this.jobs = data.jobs.map((job) => new cloud_function_job_1.CloudFunctionJob(job.jobUuid, job)); return this.populate(data); } /** * Sets environment variables for a specific cloud function * @param {{ key: string; value: string }[]} variables Environment variables to set * @returns {Promise<void>} */ async setEnvironment(variables) { await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/environment`, { variables, }); apillon_logger_1.ApillonLogger.log(`Environment variables for cloud function with UUID: ${this.uuid} successfully set`); } /** * Creates a new job for a specific cloud function * @param {CreateJobDto} body Data for creating the job * @returns {Promise<CloudFunctionJob>} Newly created cloud function job */ async createJob(body) { const job = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/jobs`, body); return new cloud_function_job_1.CloudFunctionJob(job.jobUuid, job); } } exports.CloudFunction = CloudFunction; //# sourceMappingURL=cloud-function.js.map