Skip to content

Commit 79aa79c

Browse files
Merge pull request #294 from contentstack/development
DX | 17-03-2025
2 parents 5785fde + d730451 commit 79aa79c

Some content is hidden

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

77 files changed

+2383
-4509
lines changed

.eslintrc.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = {
2-
// "env": {
3-
// "browser": true,
4-
// "amd": true
5-
// },
2+
env: {
3+
"es2020": true
4+
},
65
extends: 'standard',
76
// "globals": {
87
// "Atomics": "readonly",
@@ -15,6 +14,7 @@ module.exports = {
1514
// "ecmaVersion": 2015,
1615
// "sourceType": "module"
1716
// },
17+
parser: "@babel/eslint-parser", // Use Babel parser to handle modern JS syntax
1818
plugins: [
1919
'standard',
2020
'promise'

.github/workflows/lint-check.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint Check on PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: '22.x'
19+
registry-url: 'https://registry.npmjs.org'
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Run ESLint
25+
run: npm run lint

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [v1.19.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.5) (2025-03-17)
4+
- Fix
5+
- Added AuditLog in the stack class
6+
- Fixed the Unit Test cases and added sanity test case for audit log
7+
38
## [v1.19.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.4) (2025-03-10)
49
- Fix
510
- added fix for variants import

lib/app/installation/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,4 @@ export function InstallationCollection (http, data) {
250250
return obj.map((installationData) => {
251251
return new Installation(http, { data: installationData })
252252
})
253-
}
253+
}

lib/contentstackCollection.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export default class ContentstackCollection {
1010
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
1111
data.stackHeaders = {
1212
...data.stackHeaders,
13-
responseHeaders: response.headers,
14-
};
13+
responseHeaders: response.headers
14+
}
1515
}
1616
if (wrapperCollection) {
1717
this.items = wrapperCollection(http, data)

lib/core/concurrency-queue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function ConcurrencyQueue ({ axios, config }) {
156156
message: 'Unable to refresh token',
157157
name: 'Token Error',
158158
config: queueItem.request,
159-
stack: (error instanceof Error) ? error.stack : null,
159+
stack: (error instanceof Error) ? error.stack : null
160160
})
161161
})
162162
this.queue = []

lib/entity.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu
4646
if (response.data) {
4747
const data = response.data || {}
4848
if (headers) {
49-
data.stackHeaders = headers;
49+
data.stackHeaders = headers
5050
}
5151
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
5252
data.stackHeaders = {
5353
...data.stackHeaders,
54-
responseHeaders: response.headers,
55-
};
54+
responseHeaders: response.headers
55+
}
5656
}
5757
return data
5858
} else {
@@ -81,10 +81,10 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me
8181

8282
export const create = ({ http, params }) => {
8383
return async function (data, param) {
84-
this.stackHeaders = {
85-
...this.stackHeaders,
84+
this.stackHeaders = {
85+
...this.stackHeaders,
8686
...(http.httpClientParams.headers?.api_version && { api_version: http.httpClientParams.headers.api_version })
87-
};
87+
}
8888
const headers = {
8989
headers: {
9090
...cloneDeep(params),
@@ -152,8 +152,8 @@ export const update = (http, type, params = {}) => {
152152
delete json.updated_by
153153
delete json.updated_at
154154
if (type) {
155-
updateData[type] = json;
156-
if (type === "entry") updateData[type] = cleanAssets(updateData[type]);
155+
updateData[type] = json
156+
if (type === 'entry') updateData[type] = cleanAssets(updateData[type])
157157
} else {
158158
updateData = json
159159
}
@@ -257,22 +257,22 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {
257257
}
258258
}
259259

260-
export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, http) {
260+
export function parseData (response, stackHeaders, contentTypeUID, taxonomyUid, http) {
261261
const data = response.data || {}
262262
if (stackHeaders) {
263263
data.stackHeaders = stackHeaders
264264
}
265265
if (contentTypeUID) {
266266
data.content_type_uid = contentTypeUID
267267
}
268-
if (taxonomy_uid) {
269-
data.taxonomy_uid = taxonomy_uid
268+
if (taxonomyUid) {
269+
data.taxonomy_uid = taxonomyUid
270270
}
271271
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
272272
data.stackHeaders = {
273273
...data.stackHeaders,
274-
responseHeaders: response.headers,
275-
};
274+
responseHeaders: response.headers
275+
}
276276
}
277277
return data
278278
}
@@ -332,22 +332,22 @@ export const move = (http, type, force = false, params = {}) => {
332332
}
333333

334334
function isAsset (data) {
335-
const element = (Array.isArray(data) && data.length > 0) ? data[0] : data;
336-
return (!!element.file_size || !!element.content_type) && !!element.uid;
335+
const element = (Array.isArray(data) && data.length > 0) ? data[0] : data
336+
return (!!element.file_size || !!element.content_type) && !!element.uid
337337
}
338338

339339
export function cleanAssets (data) {
340-
if (data && typeof data === "object") {
341-
const keys = Object.keys(data);
340+
if (data && typeof data === 'object') {
341+
const keys = Object.keys(data)
342342
for (const key of keys) {
343-
if (data[key] !== null && data[key] !== undefined && typeof data[key] === "object") {
343+
if (data[key] !== null && data[key] !== undefined && typeof data[key] === 'object') {
344344
if (isAsset(data[key])) {
345-
data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid;
345+
data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid
346346
} else {
347-
cleanAssets(data[key]);
347+
cleanAssets(data[key])
348348
}
349349
}
350350
}
351351
}
352-
return data;
352+
return data
353353
}

lib/stack/auditlog/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cloneDeep from 'lodash/cloneDeep'
22
import error from '../../core/contentstackError'
3-
import { fetchAll, parseData } from '../../entity'
3+
import { fetchAll } from '../../entity'
44

55
/**
66
*
@@ -36,7 +36,7 @@ export function AuditLog (http, data = {}) {
3636
} || {}
3737
const response = await http.get(this.urlPath, headers)
3838
if (response.data) {
39-
return new AuditLog(http, parseData(response, this.stackHeaders))
39+
return response.data
4040
} else {
4141
throw error(response)
4242
}

lib/stack/bulkOperation/index.js

+48-31
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,25 @@ export function BulkOperation (http, data = {}) {
2828
* client.stack({ api_key: 'api_key'}).bulkOperation().addItems({ data: itemsData })
2929
* .then((response) => { console.log(response) })
3030
*/
31-
this.addItems = async ({ data, bulk_version = "" }) => {
32-
this.urlPath = `/bulk/release/items`;
31+
// eslint-disable-next-line camelcase
32+
this.addItems = async ({ data, bulk_version = '' }) => {
33+
this.urlPath = `/bulk/release/items`
3334
const headers = {
3435
headers: {
35-
...cloneDeep(this.stackHeaders),
36-
},
37-
};
38-
if (bulk_version) headers.headers.bulk_version = bulk_version;
36+
...cloneDeep(this.stackHeaders)
37+
}
38+
}
39+
// eslint-disable-next-line camelcase
40+
if (bulk_version) headers.headers.bulk_version = bulk_version
3941
try {
40-
const response = await http.post(this.urlPath, data, headers);
42+
const response = await http.post(this.urlPath, data, headers)
4143
if (response.data) {
42-
return response.data;
44+
return response.data
4345
}
4446
} catch (error) {
45-
console.error(error);
47+
console.error(error)
4648
}
47-
};
49+
}
4850

4951
/**
5052
* The updateItems request allows you to update multiple items in a release in bulk.
@@ -65,23 +67,25 @@ export function BulkOperation (http, data = {}) {
6567
* client.stack({ api_key: 'api_key'}).bulkOperation().updateItems({ data: itemsData })
6668
* .then((response) => { console.log(response) })
6769
*/
68-
this.updateItems = async ({ data, bulk_version = "" }) => {
69-
this.urlPath = `/bulk/release/update_items`;
70+
// eslint-disable-next-line camelcase
71+
this.updateItems = async ({ data, bulk_version = '' }) => {
72+
this.urlPath = `/bulk/release/update_items`
7073
const headers = {
7174
headers: {
72-
...cloneDeep(this.stackHeaders),
73-
},
74-
};
75-
if (bulk_version) headers.headers.bulk_version = bulk_version;
75+
...cloneDeep(this.stackHeaders)
76+
}
77+
}
78+
// eslint-disable-next-line camelcase
79+
if (bulk_version) headers.headers.bulk_version = bulk_version
7680
try {
77-
const response = await http.put(this.urlPath, data, headers);
81+
const response = await http.put(this.urlPath, data, headers)
7882
if (response.data) {
79-
return response.data;
83+
return response.data
8084
}
8185
} catch (error) {
82-
console.error(error);
86+
console.error(error)
8387
}
84-
};
88+
}
8589

8690
/**
8791
* The jobStatus request allows you to check the status of a bulk job.
@@ -94,23 +98,26 @@ export function BulkOperation (http, data = {}) {
9498
* client.stack({ api_key: 'api_key'}).bulkOperation().jobStatus({ job_id: 'job_id' })
9599
* .then((response) => { console.log(response) })
96100
*/
97-
this.jobStatus = async ({ job_id, bulk_version = "" }) => {
98-
this.urlPath = `/bulk/jobs/${job_id}`;
101+
// eslint-disable-next-line camelcase
102+
this.jobStatus = async ({ job_id, bulk_version = '' }) => {
103+
// eslint-disable-next-line camelcase
104+
this.urlPath = `/bulk/jobs/${job_id}`
99105
const headers = {
100106
headers: {
101-
...cloneDeep(this.stackHeaders),
102-
},
103-
};
104-
if (bulk_version) headers.headers.bulk_version = bulk_version;
107+
...cloneDeep(this.stackHeaders)
108+
}
109+
}
110+
// eslint-disable-next-line camelcase
111+
if (bulk_version) headers.headers.bulk_version = bulk_version
105112
try {
106-
const response = await http.get(this.urlPath, headers);
113+
const response = await http.get(this.urlPath, headers)
107114
if (response.data) {
108-
return response.data;
115+
return response.data
109116
}
110117
} catch (error) {
111-
console.error(error);
118+
console.error(error)
112119
}
113-
};
120+
}
114121

115122
/**
116123
* The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.
@@ -172,6 +179,7 @@ export function BulkOperation (http, data = {}) {
172179
* .then((response) => { console.log(response.notice) })
173180
*
174181
*/
182+
// eslint-disable-next-line camelcase
175183
this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
176184
var httpBody = {}
177185
if (details) {
@@ -182,19 +190,23 @@ export function BulkOperation (http, data = {}) {
182190
...cloneDeep(this.stackHeaders)
183191
}
184192
}
193+
// eslint-disable-next-line camelcase
185194
if (is_nested) {
186195
headers.params = {
187196
nested: true,
188197
event_type: 'bulk'
189198
}
190199
}
200+
// eslint-disable-next-line camelcase
191201
if (skip_workflow_stage) {
202+
// eslint-disable-next-line camelcase
192203
headers.headers.skip_workflow_stage_check = skip_workflow_stage
193204
}
194205
if (approvals) {
195206
headers.headers.approvals = approvals
196207
}
197208

209+
// eslint-disable-next-line camelcase
198210
if (api_version) headers.headers.api_version = api_version
199211

200212
return publishUnpublish(http, '/bulk/publish', httpBody, headers)
@@ -259,7 +271,8 @@ export function BulkOperation (http, data = {}) {
259271
* client.stack({ api_key: 'api_key'}).bulkOperation().unpublish({ details: publishDetails, is_nested: true })
260272
* .then((response) => { console.log(response.notice) })
261273
*/
262-
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = ''}) => {
274+
// eslint-disable-next-line camelcase
275+
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
263276
var httpBody = {}
264277
if (details) {
265278
httpBody = cloneDeep(details)
@@ -269,18 +282,22 @@ export function BulkOperation (http, data = {}) {
269282
...cloneDeep(this.stackHeaders)
270283
}
271284
}
285+
// eslint-disable-next-line camelcase
272286
if (is_nested) {
273287
headers.params = {
274288
nested: true,
275289
event_type: 'bulk'
276290
}
277291
}
292+
// eslint-disable-next-line camelcase
278293
if (skip_workflow_stage) {
294+
// eslint-disable-next-line camelcase
279295
headers.headers.skip_workflow_stage_check = skip_workflow_stage
280296
}
281297
if (approvals) {
282298
headers.headers.approvals = approvals
283299
}
300+
// eslint-disable-next-line camelcase
284301
if (api_version) headers.headers.api_version = api_version
285302
return publishUnpublish(http, '/bulk/unpublish', httpBody, headers)
286303
}

0 commit comments

Comments
 (0)