@contentstack/management
Version:
The Content Management API is used to manage the content of your Contentstack account
133 lines (128 loc) • 5.18 kB
JavaScript
;
var _interopRequireDefault3 = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault2 = _interopRequireDefault3(require("@babel/runtime/helpers/interopRequireDefault"));
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Environment = Environment;
exports.EnvironmentCollection = EnvironmentCollection;
var _cloneDeep = require("lodash/cloneDeep");
var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep);
var _entity = require("../../entity");
/**
* A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Read more about <a href='https://www.contentstack.com/docs/developers/set-up-environments'>Environment</a>.
* @namespace Environment
* */
function Environment(http) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.stackHeaders = data.stackHeaders;
this.urlPath = "/environments";
if (data.environment) {
Object.assign(this, (0, _cloneDeep2["default"])(data.environment));
this.urlPath = "/environments/".concat(this.name);
/**
* @description The Update Environment call lets you update the name and description of an existing Environment.
* @memberof Environment
* @func update
* @returns {Promise<Environment>} Promise for Environment instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment('uid').fetch()
* .then((environment) => {
* environment.name = 'My New Environment'
* environment.description = 'Environment description'
* return environment.update()
* })
* .then((environment) => console.log(environment))
*
*/
this.update = (0, _entity.update)(http, 'environment');
/**
* @description The Delete Environment call is used to delete an existing Environment permanently from your Stack.
* @memberof Environment
* @func delete
* @returns {Promise<Object>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment('uid').delete()
* .then((response) => console.log(response.notice))
*/
this["delete"] = (0, _entity.deleteEntity)(http);
/**
* @description The fetch Environment call fetches Environment details.
* @memberof Environment
* @func fetch
* @returns {Promise<Environment>} Promise for Environment instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment('uid').fetch()
* .then((environment) => console.log(environment))
*
*/
this.fetch = (0, _entity.fetch)(http, 'environment');
} else {
/**
* @description The Create a Environment call creates a new environment in a particular stack of your Contentstack account.
* @memberof Environment
* @func create
* @returns {Promise<Environment>} Promise for Environment instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const environment = {
* name: 'development',
* servers: [
* {
* name: 'default'
* }
* ],
* urls: [
* {
* locale: 'en-us',
* url: 'http://example.com/'
* }
* ],
* deploy_content: true
* }
* client.stack({ api_key: 'api_key'}).environment().create({ environment })
* .then((environment) => console.log(environment))
*/
this.create = (0, _entity.create)({
http: http
});
/**
* @description The Query on Environment will allow you to fetch details of all or specific Environments.
* @memberof Environment
* @func query
* @returns {Object} Query builder object with find(), count(), and findOne() methods.
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment().query({ query: { name: 'Environment Name' } }).find()
* .then((environments) => console.log(environments))
*/
this.query = (0, _entity.query)({
http: http,
wrapperCollection: EnvironmentCollection
});
}
}
function EnvironmentCollection(http, data) {
var obj = (0, _cloneDeep2["default"])(data.environments) || [];
var environmentCollection = obj.map(function (userdata) {
return new Environment(http, {
environment: userdata,
stackHeaders: data.stackHeaders
});
});
return environmentCollection;
}