@contentstack/management
Advanced tools
Comparing version 1.14.1 to 1.15.0
# Changelog | ||
## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13) | ||
## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23) | ||
- Feature | ||
- Taxonomy Import/Export feature added | ||
## [v1.14.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.1) (2024-11-23) | ||
- Fixes | ||
- Fix for issue while updating entries with assets | ||
- Fix for validating the data while updating entries with assets | ||
## [v1.14.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.0) (2023-12-19) | ||
- Feature | ||
- Management token feature added | ||
## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13) | ||
- Fixes | ||
- Fix for issue while updating entries with assets | ||
## [v1.13.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.0) (2023-11-21) | ||
@@ -10,0 +15,0 @@ - Feature |
@@ -529,3 +529,3 @@ import _typeof from "@babel/runtime/helpers/typeof"; | ||
export function cleanAssets(data) { | ||
if (_typeof(data) === "object" && Object.keys(data).length > 0) { | ||
if (data && _typeof(data) === "object" && Object.keys(data).length > 0) { | ||
var keys = Object.keys(data); | ||
@@ -532,0 +532,0 @@ for (var _i = 0, _keys = keys; _i < _keys.length; _i++) { |
@@ -0,5 +1,13 @@ | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
/* eslint-disable camelcase */ | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import { create, fetch, query, update, deleteEntity } from '../../entity'; | ||
import { create, fetch, query, update, deleteEntity, upload, parseData } from '../../entity'; | ||
import { Terms, TermsCollection } from './terms'; | ||
import FormData from 'form-data'; | ||
import { createReadStream } from 'fs'; | ||
import error from '../../core/contentstackError'; | ||
export function Taxonomy(http) { | ||
@@ -68,2 +76,49 @@ var _this = this; | ||
this.fetch = fetch(http, 'taxonomy'); | ||
/** | ||
* @description The Export taxonomy call is used to export an existing taxonomy. | ||
* @memberof Taxonomy | ||
* @func export | ||
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').export() | ||
* .then((taxonomy) => console.log(taxonomy)) | ||
* | ||
*/ | ||
this["export"] = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var headers, response; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
headers = { | ||
headers: _objectSpread({}, cloneDeep(_this.stackHeaders)) | ||
}; | ||
_context.next = 4; | ||
return http.get("".concat(_this.urlPath, "/export"), headers); | ||
case 4: | ||
response = _context.sent; | ||
if (!response.data) { | ||
_context.next = 9; | ||
break; | ||
} | ||
return _context.abrupt("return", response.data); | ||
case 9: | ||
throw error(response); | ||
case 10: | ||
_context.next = 15; | ||
break; | ||
case 12: | ||
_context.prev = 12; | ||
_context.t0 = _context["catch"](0); | ||
throw error(_context.t0); | ||
case 15: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, null, [[0, 12]]); | ||
})); | ||
this.terms = function () { | ||
@@ -123,2 +178,63 @@ var uid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
}); | ||
/** | ||
* @description The 'Import taxonomy' import a single entry by uploading JSON or CSV files. | ||
* @memberof Taxonomy | ||
* @func import | ||
* @param {String} data.taxonomy path to file | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* const data = { | ||
* taxonomy: 'path/to/file.json', | ||
* } | ||
* // Import a Taxonomy | ||
* client.stack({ api_key: 'api_key'}).taxonomy().import(data) | ||
* .then((taxonomy) => console.log(taxonomy)) | ||
*/ | ||
this["import"] = /*#__PURE__*/function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) { | ||
var params, | ||
response, | ||
_args2 = arguments; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
params = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return upload({ | ||
http: http, | ||
urlPath: "".concat(this.urlPath, "/import"), | ||
stackHeaders: this.stackHeaders, | ||
formData: createFormData(data), | ||
params: params | ||
}); | ||
case 4: | ||
response = _context2.sent; | ||
if (!response.data) { | ||
_context2.next = 9; | ||
break; | ||
} | ||
return _context2.abrupt("return", new this.constructor(http, parseData(response, this.stackHeaders))); | ||
case 9: | ||
throw error(response); | ||
case 10: | ||
_context2.next = 15; | ||
break; | ||
case 12: | ||
_context2.prev = 12; | ||
_context2.t0 = _context2["catch"](1); | ||
throw error(_context2.t0); | ||
case 15: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this, [[1, 12]]); | ||
})); | ||
return function (_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); | ||
} | ||
@@ -135,2 +251,10 @@ } | ||
return taxonomyCollection; | ||
} | ||
export function createFormData(data) { | ||
return function () { | ||
var formData = new FormData(); | ||
var uploadStream = createReadStream(data.taxonomy); | ||
formData.append('taxonomy', uploadStream); | ||
return formData; | ||
}; | ||
} |
@@ -548,3 +548,3 @@ "use strict"; | ||
function cleanAssets(data) { | ||
if ((0, _typeof3["default"])(data) === "object" && Object.keys(data).length > 0) { | ||
if (data && (0, _typeof3["default"])(data) === "object" && Object.keys(data).length > 0) { | ||
var keys = Object.keys(data); | ||
@@ -551,0 +551,0 @@ for (var _i = 0, _keys = keys; _i < _keys.length; _i++) { |
@@ -8,4 +8,11 @@ "use strict"; | ||
}); | ||
var _defineProperty2 = require("@babel/runtime/helpers/defineProperty"); | ||
var _defineProperty3 = (0, _interopRequireDefault2["default"])(_defineProperty2); | ||
var _asyncToGenerator2 = require("@babel/runtime/helpers/asyncToGenerator"); | ||
var _asyncToGenerator3 = (0, _interopRequireDefault2["default"])(_asyncToGenerator2); | ||
exports.Taxonomy = Taxonomy; | ||
exports.TaxonomyCollection = TaxonomyCollection; | ||
exports.createFormData = createFormData; | ||
var _regenerator = require("@babel/runtime/regenerator"); | ||
var _regenerator2 = (0, _interopRequireDefault2["default"])(_regenerator); | ||
var _cloneDeep = require("lodash/cloneDeep"); | ||
@@ -15,4 +22,9 @@ var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep); | ||
var _terms = require("./terms"); | ||
/* eslint-disable camelcase */ | ||
var _formData = require("form-data"); | ||
var _formData2 = (0, _interopRequireDefault2["default"])(_formData); | ||
var _fs = require("fs"); | ||
var _contentstackError = require("../../core/contentstackError"); | ||
var _contentstackError2 = (0, _interopRequireDefault2["default"])(_contentstackError); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty3["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /* eslint-disable camelcase */ | ||
function Taxonomy(http) { | ||
@@ -81,2 +93,49 @@ var _this = this; | ||
this.fetch = (0, _entity.fetch)(http, 'taxonomy'); | ||
/** | ||
* @description The Export taxonomy call is used to export an existing taxonomy. | ||
* @memberof Taxonomy | ||
* @func export | ||
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').export() | ||
* .then((taxonomy) => console.log(taxonomy)) | ||
* | ||
*/ | ||
this["export"] = /*#__PURE__*/(0, _asyncToGenerator3["default"])( /*#__PURE__*/_regenerator2["default"].mark(function _callee() { | ||
var headers, response; | ||
return _regenerator2["default"].wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
headers = { | ||
headers: _objectSpread({}, (0, _cloneDeep2["default"])(_this.stackHeaders)) | ||
}; | ||
_context.next = 4; | ||
return http.get("".concat(_this.urlPath, "/export"), headers); | ||
case 4: | ||
response = _context.sent; | ||
if (!response.data) { | ||
_context.next = 9; | ||
break; | ||
} | ||
return _context.abrupt("return", response.data); | ||
case 9: | ||
throw (0, _contentstackError2["default"])(response); | ||
case 10: | ||
_context.next = 15; | ||
break; | ||
case 12: | ||
_context.prev = 12; | ||
_context.t0 = _context["catch"](0); | ||
throw (0, _contentstackError2["default"])(_context.t0); | ||
case 15: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, null, [[0, 12]]); | ||
})); | ||
this.terms = function () { | ||
@@ -136,2 +195,63 @@ var uid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
}); | ||
/** | ||
* @description The 'Import taxonomy' import a single entry by uploading JSON or CSV files. | ||
* @memberof Taxonomy | ||
* @func import | ||
* @param {String} data.taxonomy path to file | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* const data = { | ||
* taxonomy: 'path/to/file.json', | ||
* } | ||
* // Import a Taxonomy | ||
* client.stack({ api_key: 'api_key'}).taxonomy().import(data) | ||
* .then((taxonomy) => console.log(taxonomy)) | ||
*/ | ||
this["import"] = /*#__PURE__*/function () { | ||
var _ref2 = (0, _asyncToGenerator3["default"])( /*#__PURE__*/_regenerator2["default"].mark(function _callee2(data) { | ||
var params, | ||
response, | ||
_args2 = arguments; | ||
return _regenerator2["default"].wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
params = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return (0, _entity.upload)({ | ||
http: http, | ||
urlPath: "".concat(this.urlPath, "/import"), | ||
stackHeaders: this.stackHeaders, | ||
formData: createFormData(data), | ||
params: params | ||
}); | ||
case 4: | ||
response = _context2.sent; | ||
if (!response.data) { | ||
_context2.next = 9; | ||
break; | ||
} | ||
return _context2.abrupt("return", new this.constructor(http, (0, _entity.parseData)(response, this.stackHeaders))); | ||
case 9: | ||
throw (0, _contentstackError2["default"])(response); | ||
case 10: | ||
_context2.next = 15; | ||
break; | ||
case 12: | ||
_context2.prev = 12; | ||
_context2.t0 = _context2["catch"](1); | ||
throw (0, _contentstackError2["default"])(_context2.t0); | ||
case 15: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this, [[1, 12]]); | ||
})); | ||
return function (_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); | ||
} | ||
@@ -148,2 +268,10 @@ } | ||
return taxonomyCollection; | ||
} | ||
function createFormData(data) { | ||
return function () { | ||
var formData = new _formData2["default"](); | ||
var uploadStream = (0, _fs.createReadStream)(data.taxonomy); | ||
formData.append('taxonomy', uploadStream); | ||
return formData; | ||
}; | ||
} |
{ | ||
"name": "@contentstack/management", | ||
"version": "1.14.1", | ||
"version": "1.15.0", | ||
"description": "The Content Management API is used to manage the content of your Contentstack account", | ||
@@ -33,4 +33,4 @@ "main": "./dist/node/contentstack-management.js", | ||
"test": "npm run test:api && npm run test:unit", | ||
"test:sanity": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill", | ||
"test:sanity-report": "node sanity-report.mjs", | ||
"test:sanity": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json && marge mochawesome-report/mochawesome.json -f sanity-report.html --inline", | ||
"test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs", | ||
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill", | ||
@@ -96,2 +96,3 @@ "test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill", | ||
"mocha": "^9.2.2", | ||
"mocha-html-reporter": "^0.0.1", | ||
"mochawesome": "^7.1.3", | ||
@@ -98,0 +99,0 @@ "multiparty": "^4.2.3", |
@@ -107,3 +107,3 @@ [![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) | ||
### The MIT License (MIT) | ||
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved | ||
Copyright © 2012-2024 [Contentstack](https://www.contentstack.com/). All Rights Reserved | ||
@@ -110,0 +110,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2034265
23210
43
35