Skip to content

Commit 4e288a8

Browse files
authored
Merge pull request #16 from contentstack/bug/orgs-stack-and-entry-fetch
Bug/orgs stack and entry fetch
2 parents 3638b20 + ec4a95d commit 4e288a8

File tree

89 files changed

+720
-1196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+720
-1196
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Changelog
2+
3+
## [v1.2.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.2) (2021-05-26)
4+
- Bug Fix
5+
- Organization Specific get all Stack: Get Stack for specific organization from org_uid
6+
- Resolved: Entry Publish and Update not work after find function
7+
- Resolved: Workflow update issue on fetchAll function
8+
- Document Update
9+
- `update` Entry example code update
10+
211
## [v1.2.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.1) (2021-03-19)
312
- Bug Fix
413
- User get details: Include organization functions for `is_owner` of the organization

dist/es-modules/contentstack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import httpClient from './core/contentstackHTTPClient.js';
4949
* import * as contentstack from '@contentstack/management'
5050
* const client = contentstack.client({ maxRequests: 5 })
5151
*
52-
* @prop {boolean=} params.retryOnError - Optional boolean for retry on failuer. Default is true
52+
* @prop {boolean=} params.retryOnError - Optional boolean for retry on failure. Default is true
5353
* @example //Set the `retryOnError` to false
5454
* import * as contentstack from '@contentstack/management'
5555
* const client = contentstack.client({ retryOnError: false })
@@ -59,7 +59,7 @@ import httpClient from './core/contentstackHTTPClient.js';
5959
* import * as contentstack from '@contentstack/management'
6060
* const client = contentstack.client({ retryLimit: 2 })
6161
*
62-
* @prop {number=} params.retryDelay - The number of miliseconds to use for operation retries. Default is 300ms
62+
* @prop {number=} params.retryDelay - The number of milliseconds to use for operation retries. Default is 300ms
6363
* @example //Set the `retryDelay` to 500ms
6464
* import * as contentstack from '@contentstack/management'
6565
* const client = contentstack.client({ retryDelay: 500 })
@@ -98,7 +98,7 @@ import httpClient from './core/contentstackHTTPClient.js';
9898
* const client = contentstack.client({ maxContentLength: 1024 ** 3 })
9999
*
100100
* @prop {number=} params.maxBodyLength - Optional maximum body length in bytes (default: 10 MB)
101-
* @example //Set the `maxContentLength` to 1024 ** 2 * 10 // 10 MB
101+
* @example //Set the `maxBodyLength` to 1024 ** 2 * 10 // 10 MB
102102
* import * as contentstack from '@contentstack/management'
103103
* const client = contentstack.client({ maxBodyLength: 1024 ** 2 * 10 })
104104
*

dist/es-modules/contentstackCollection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
22

3+
/**
4+
* @namespace ContentstackCollection
5+
*/
36
var ContentstackCollection = function ContentstackCollection(response, http) {
47
var stackHeaders = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
58
var wrapperCollection = arguments.length > 3 ? arguments[3] : undefined;

dist/es-modules/entity.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
99
import error from './core/contentstackError';
1010
import cloneDeep from 'lodash/cloneDeep';
1111
import Query from './query/index';
12+
import ContentstackCollection from './contentstackCollection';
1213
export var publish = function publish(http, type) {
1314
return /*#__PURE__*/function () {
1415
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
@@ -197,7 +198,7 @@ export var create = function create(_ref8) {
197198
break;
198199
}
199200

200-
return _context5.abrupt("return", new this.constructor(http, parseData(response, this.stackHeaders)));
201+
return _context5.abrupt("return", new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid)));
201202

202203
case 9:
203204
throw error(response);
@@ -249,7 +250,7 @@ export var exportObject = function exportObject(_ref10) {
249250
break;
250251
}
251252

252-
return _context6.abrupt("return", new this.constructor(http, parseData(response, this.stackHeaders)));
253+
return _context6.abrupt("return", new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid)));
253254

254255
case 9:
255256
throw error(response);
@@ -283,9 +284,17 @@ export var query = function query(_ref12) {
283284
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
284285

285286
if (this.organization_uid) {
287+
if (!params.query) {
288+
params.query = {};
289+
}
290+
286291
params.query['org_uid'] = this.organization_uid;
287292
}
288293

294+
if (this.content_type_uid) {
295+
params.content_type_uid = this.content_type_uid;
296+
}
297+
289298
return Query(http, this.urlPath, params, this.stackHeaders, wrapperCollection);
290299
};
291300
};
@@ -455,6 +464,61 @@ export var fetch = function fetch(http, type) {
455464
}, _callee9, this, [[1, 14]]);
456465
}));
457466
};
467+
export var fetchAll = function fetchAll(http, wrapperCollection) {
468+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
469+
var params,
470+
headers,
471+
response,
472+
_args10 = arguments;
473+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
474+
while (1) {
475+
switch (_context10.prev = _context10.next) {
476+
case 0:
477+
params = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
478+
headers = {};
479+
480+
if (this.stackHeaders) {
481+
headers.headers = this.stackHeaders;
482+
}
483+
484+
if (params) {
485+
headers.params = _objectSpread({}, cloneDeep(params));
486+
}
487+
488+
_context10.prev = 4;
489+
_context10.next = 7;
490+
return http.get(this.urlPath, headers);
491+
492+
case 7:
493+
response = _context10.sent;
494+
495+
if (!response.data) {
496+
_context10.next = 12;
497+
break;
498+
}
499+
500+
return _context10.abrupt("return", new ContentstackCollection(response, http, this.stackHeaders, wrapperCollection));
501+
502+
case 12:
503+
throw error(response);
504+
505+
case 13:
506+
_context10.next = 18;
507+
break;
508+
509+
case 15:
510+
_context10.prev = 15;
511+
_context10.t0 = _context10["catch"](4);
512+
throw error(_context10.t0);
513+
514+
case 18:
515+
case "end":
516+
return _context10.stop();
517+
}
518+
}
519+
}, _callee10, this, [[4, 15]]);
520+
}));
521+
};
458522
export function parseData(response, stackHeaders, contentTypeUID) {
459523
var data = response.data || {};
460524

dist/es-modules/organization/index.js

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
88

99
import cloneDeep from 'lodash/cloneDeep';
1010
import error from '../core/contentstackError';
11-
import { fetch } from '../entity';
11+
import { fetch, fetchAll } from '../entity';
1212
import ContentstackCollection from '../contentstackCollection';
1313
import { RoleCollection } from '../stack/roles';
1414
import { StackCollection } from '../stack';
@@ -448,61 +448,14 @@ export function Organization(http, data) {
448448
* .then((collection) => console.log(collection))
449449
*
450450
*/
451-
this.fetchAll = /*#__PURE__*/function () {
452-
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(parmas) {
453-
var response;
454-
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
455-
while (1) {
456-
switch (_context7.prev = _context7.next) {
457-
case 0:
458-
_context7.prev = 0;
459-
_context7.next = 3;
460-
return http.get(_this.urlPath, {
461-
params: parmas
462-
});
463-
464-
case 3:
465-
response = _context7.sent;
466-
467-
if (!response.data) {
468-
_context7.next = 8;
469-
break;
470-
}
471-
472-
return _context7.abrupt("return", new ContentstackCollection(response, http, null, OrganizationCollection));
473-
474-
case 8:
475-
throw error(response);
476-
477-
case 9:
478-
_context7.next = 14;
479-
break;
480-
481-
case 11:
482-
_context7.prev = 11;
483-
_context7.t0 = _context7["catch"](0);
484-
throw error(_context7.t0);
485-
486-
case 14:
487-
case "end":
488-
return _context7.stop();
489-
}
490-
}
491-
}, _callee7, null, [[0, 11]]);
492-
}));
493-
494-
return function (_x7) {
495-
return _ref7.apply(this, arguments);
496-
};
497-
}();
451+
this.fetchAll = fetchAll(http, OrganizationCollection);
498452
}
499453
}
500454
export function OrganizationCollection(http, data) {
501455
var obj = cloneDeep(data.organizations || []);
502-
var organizationCollection = obj.map(function (userdata) {
456+
return obj.map(function (userdata) {
503457
return new Organization(http, {
504458
organization: userdata
505459
});
506460
});
507-
return organizationCollection;
508461
}

dist/es-modules/query/index.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ export default function Query(http, urlPath, param) {
1818
headers.headers = stackHeaders;
1919
}
2020

21+
var contentTypeUid = null;
22+
2123
if (param) {
24+
if (param.content_type_uid) {
25+
contentTypeUid = param.content_type_uid;
26+
delete param.content_type_uid;
27+
}
28+
2229
headers.params = _objectSpread({}, cloneDeep(param));
2330
}
2431
/**
@@ -56,30 +63,34 @@ export default function Query(http, urlPath, param) {
5663
response = _context.sent;
5764

5865
if (!response.data) {
59-
_context.next = 8;
66+
_context.next = 9;
6067
break;
6168
}
6269

70+
if (contentTypeUid) {
71+
response.data.content_type_uid = contentTypeUid;
72+
}
73+
6374
return _context.abrupt("return", new ContentstackCollection(response, http, stackHeaders, wrapperCollection));
6475

65-
case 8:
76+
case 9:
6677
throw error(response);
6778

68-
case 9:
69-
_context.next = 14;
79+
case 10:
80+
_context.next = 15;
7081
break;
7182

72-
case 11:
73-
_context.prev = 11;
83+
case 12:
84+
_context.prev = 12;
7485
_context.t0 = _context["catch"](0);
7586
throw error(_context.t0);
7687

77-
case 14:
88+
case 15:
7889
case "end":
7990
return _context.stop();
8091
}
8192
}
82-
}, _callee, null, [[0, 11]]);
93+
}, _callee, null, [[0, 12]]);
8394
}));
8495

8596
return function find() {
@@ -191,30 +202,34 @@ export default function Query(http, urlPath, param) {
191202
response = _context3.sent;
192203

193204
if (!response.data) {
194-
_context3.next = 10;
205+
_context3.next = 11;
195206
break;
196207
}
197208

209+
if (contentTypeUid) {
210+
response.data.content_type_uid = contentTypeUid;
211+
}
212+
198213
return _context3.abrupt("return", new ContentstackCollection(response, http, stackHeaders, wrapperCollection));
199214

200-
case 10:
215+
case 11:
201216
throw error(response);
202217

203-
case 11:
204-
_context3.next = 16;
218+
case 12:
219+
_context3.next = 17;
205220
break;
206221

207-
case 13:
208-
_context3.prev = 13;
222+
case 14:
223+
_context3.prev = 14;
209224
_context3.t0 = _context3["catch"](2);
210225
throw error(_context3.t0);
211226

212-
case 16:
227+
case 17:
213228
case "end":
214229
return _context3.stop();
215230
}
216231
}
217-
}, _callee3, null, [[2, 13]]);
232+
}, _callee3, null, [[2, 14]]);
218233
}));
219234

220235
return function findOne() {

dist/es-modules/stack/contentType/entry/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function Entry(http, data) {
3434
* .then((entry) => {
3535
* entry.title = 'My New Entry'
3636
* entry.description = 'Entry description'
37-
* return Entry.update()
37+
* return entry.update()
3838
* })
3939
* .then((entry) => console.log(entry))
4040
*
@@ -145,13 +145,13 @@ export function Entry(http, data) {
145145
* @example
146146
* import * as contentstack from '@contentstack/management'
147147
* const client = contentstack.client()
148-
*
148+
*
149149
* const publishing_rule = {
150-
* "uid": "blt9b9253297f117e84",
151-
* "action": "publish", //(‘publish’, ‘unpublish’, or ’both’)
152-
* "status": 1, //(this could be ‘0’ for Approval Requested, ‘1’ for ‘Approval Accepted’, and ‘-1’ for ‘Approval Rejected’),
153-
* "notify": false,
154-
* "comment": "Please review this."
150+
* "uid": "blt9b9253297f117e84",
151+
* "action": "publish" //(‘publish’, ‘unpublish’, or ’both’)
152+
* "status": 1, //(this could be ‘0’ for Approval Requested, ‘1’ for ‘Approval Accepted’, and ‘-1’ for ‘Approval Rejected’),
153+
* "notify": false,
154+
* comment": "Please review this."
155155
* }
156156
* client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').publishRequest({ publishing_rule, locale: 'en-us'})
157157
* .then((response) => console.log(response.notice))
@@ -348,7 +348,7 @@ export function EntryCollection(http, data) {
348348
var entryCollection = obj.map(function (entry) {
349349
return new Entry(http, {
350350
entry: entry,
351-
content_type_uid: 'uid',
351+
content_type_uid: data.content_type_uid,
352352
stackHeaders: data.stackHeaders
353353
});
354354
});

dist/es-modules/stack/deliveryToken/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import cloneDeep from 'lodash/cloneDeep';
2-
import { create, update, deleteEntity, fetch, query } from '../../entity'; // import ContentstackCollection from '../../contentstackCollection'
3-
// import error from '../../core/contentstackError'
2+
import { create, update, deleteEntity, fetch, query } from '../../entity';
3+
/**
4+
* Delivery tokens provide read-only access to the associated environments. Read more about <a href='https://www.contentstack.com/docs/developers/create-tokens/about-delivery-tokens'>DeliveryToken</a>.
5+
* @namespace DeliveryToken
6+
*/
47

58
export function DeliveryToken(http) {
69
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

dist/es-modules/stack/environment/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import cloneDeep from 'lodash/cloneDeep';
22
import { create, update, deleteEntity, fetch, query } from '../../entity';
3+
/**
4+
* 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>.
5+
* @namespace Environment
6+
* */
7+
38
export function Environment(http) {
49
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
510
this.stackHeaders = data.stackHeaders;

0 commit comments

Comments
 (0)