fabric-ias
Version:
Node.JS Service for Microsoft Fabric supporting infrastructure as code
95 lines (90 loc) • 3.62 kB
JavaScript
"use strict";
const Base = require("./base");
const Libraries = require("./libraries");
/**
* @class Environement
* @classdesc
* Represents a Microsoft Fabric Environment.
* Provides methods to manage and publish environment changes.
* Extends the Base class for authentication and API request handling.
*
* @extends Base
*
* @property {string} id - The environment ID.
* @property {string} endpoint - The API endpoint for the environment.
* @property {Libraries} libraries - Instance for managing environment libraries.
*/
class Environment extends Base {
/**
* Constructs an Environement instance for a given workspace and environment.
* @param {AzOauth} OAuthHandler - OAuth handler for authentication.
* @param {string} workspace_id - The workspace ID.
* @param {string} environment_id - The environment ID.
*/
constructor(OAuthHandler, handler, workspace_id, environment_id) {
super(OAuthHandler, handler);
this.id = environment_id || '';
this.display = '';
this.publishState = '';
this.endpoint = `${this.endpoint}/workspaces/${workspace_id}/environments/${this.id}`;
this.libraries = new Libraries(OAuthHandler, handler, workspace_id, environment_id);
this.get();
}
isPublishing() {
return ['Running', 'Waiting', 'Cancelling'].includes(this.publishState);
}
/**
* Instructs Fabric Environment to publish changes.
* Sends a publish request to the API and processes the response headers.
*
* @returns {Promise<string|Error>} True if publish initiated successfully, otherwise throws an error.
* @throws {Error} If the API response is invalid or contains an error.
*/
async get() {
const response = await this._get('');
this.display = response.data.displayName;
this.publishState = response.data.properties.publishDetails.state;
// Cancelled | Cancelling | Failed | Running | Success | Waiting
return response.data;
}
/**
* Instructs Fabric Environment to publish changes.
* Sends a publish request to the API and processes the response headers.
*
* @returns {Promise<string|Error>} True if publish initiated successfully, otherwise throws an error.
* @throws {Error} If the API response is invalid or contains an error.
*/
async publish() {
const response = await this._post('/staging/publish');
this.publishState = response.data.publishDetails.state;
return response.data;
}
/**
* Instructs Fabric Environment to Cancel publishing changes.
* Sends a publish cancel request to the API and processes the response headers.
*
* @returns {Promise<string|Error>} The publish state if cancelled successfully.
*/
async cancelPublish() {
// {
// "publishDetails": {
// "state": "Cancelled",
// "targetVersion": "d9d95b01-248f-4ef4-bd7e-9d3f1f6447be",
// "startTime": "2024-03-29T15:00:33.4359355Z",
// "endTime": "2024-03-29T15:00:47.1407904Z",
// "componentPublishInfo": {
// "sparkLibraries": {
// "state": "Cancelled" :: Cancelled | Cancelling | Failed | Running | Success | Waiting
// },
// "sparkSettings": {
// "state": "Cancelled" :: Cancelled | Cancelling | Failed | Running | Success | Waiting
// }
// }
// }
// }
const response = await this._post('/staging/cancelPublish');
this.publishState = response.data.publishDetails.state;
return response.data;
}
}
module.exports = Environment;