All files stack.js

100% Statements 61/61
100% Branches 46/46
100% Functions 14/14
100% Lines 61/61

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184          62x 62x                   1x                   4x 1x   3x 3x 3x                   3x 3x 3x 3x 3x                     5x 1x   4x 1x   3x 3x 3x                     4x 1x   3x 3x 3x 3x 3x                   4x 1x   3x 3x 3x                   3x 3x 3x 3x 3x                   4x 1x   3x 3x 3x                   3x 3x 3x 3x 3x                   4x 1x   3x 3x 3x                   3x 3x 3x 3x 3x         20x 10x 10x       20x      
/** Class representing the current stack from contentstack ui. */
 
class Stack {
 
  constructor(data, connection) {
    this._connection = connection;
    this._data = data;
  }
 
 
/**
 * This method returns data of the current stack.
 * @return {Object} Returns stack data.
 */
 
  getData() {
    return this._data;
  }
 
  /**
   * This API allows users to interact with a content type of a stack using the Content Type Content Delivery API requests. Method returns a Promise object.
   * @param {string} uid Uid of the desired content type
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with content type details.
   */
  getContentType(uid, params) {
    if (!uid){
      return Promise.reject('uid is required');
    }
    params = params || {};
    let options = { uid, params, action: "getContentType" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with the content types of a stack using the Content Type Content Delivery API requests. Method returns a Promise object.
   * @param {Object} query query for the get call
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with details of content type.
   */
  getContentTypes(query, params) {
    query = query || {};
    params = params || {};
    params.query = query;
    let options = { params, action: "getContentTypes" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with an entry of a stack using the Entries Content Delivery API requests. Method returns a Promise object.
   * @param {string} uid Uid of the desired entry
   * @param {string} content_type_uid  Uid of the desired content type
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with entry details.
   */
  getEntry(uid, content_type_uid, params) {
    if (!uid){
      return Promise.reject('uid is required');
    }
    if (!content_type_uid){
      return Promise.reject('content_type_uid is required');
    }
    params = params || {};
    let options = { uid, content_type_uid, params, action: "getEntry" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with the entries of a stack using the Entries Content Delivery API requests. Method returns a Promise object.
   * @param {string} content_type_uid  Uid of the desired content type
   * @param {Object} query query for the get call
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with details of entries.
   */
  getEntries(content_type_uid, query, params) {
    if (!content_type_uid){
      return Promise.reject('content_type_uid is required');
    }
    query = query || {};
    params = params || {};
    params.query = query;
    let options = { content_type_uid, params, action: "getEntries" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with an asset of a stack using the Assets Content Delivery API requests. Method returns a Promise object.
   * @param {string} uid Uid of the desired asset
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with asset details.
   */
  getAsset(uid, params) {
    if (!uid){
      return Promise.reject('uid is required');
    }
    params = params || {};
    let options = { uid, params, action: "getAsset" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with the assets of a stack using the Assets Content Delivery API requests. Method returns a Promise object.
   * @param {Object} query query for the get call
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with details of assets.
   */
  getAssets(query, params) {
    query = query || {};
    params = params || {};
    params.query = query;
    let options = { params, action: "getAssets" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with an environment of a stack using the Environment Content Delivery API requests. Method returns a Promise object.
   * @param {string} name Name of the desired environment
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with environment details.
   */
  getEnvironment(name, params) {
    if (!name){
      return Promise.reject('name is required');
    }
    params = params || {};
    let options = {name, params, action: "getEnvironment" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with the environments of a stack using the Environment Content Delivery API requests. Method returns a Promise object.   
   * @param {Object} query query for the get call
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with details of environments.
   */
  getEnvironments(query, params) {
    query = query || {};
    params = params || {};
    params.query = query;
    let options = { params, action: "getEnvironments" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with a locale of a stack using the Languages Content Delivery API Requests. Method returns a Promise object.
   * @param {string} code Code of the desired locale
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with locale details.
   */
  getLocale(code, params) {
    if (!code){
      return Promise.reject('code is required');
    }
    params = params || {};
    let options = { code, params, action: "getLocale" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
 
  /**
   * This API allows users to interact with the locales of a stack using the Languages Content Delivery API Requests. Method returns a Promise object.
   * @param {Object} query query for the get call
   * @param {Object} params optional params for the get call
   * @return {Object} A Promise object which will resolve with details of locales.
   */
  getLocales(query, params) {
    query = query || {};
    params = params || {};
    params.query = query;
    let options = { params, action: "getLocales" };
    return this._connection.sendToParent('stackQuery', options).then(onData).catch(onError);
  }
}
 
function onData(data){
  if(typeof(data.data) === "string")
    return Promise.reject(data.data)
  return Promise.resolve(data.data)
}
 
function onError(error){
  return Promise.reject(error)
}
 
export default Stack;