Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
// "env": {
// "browser": true,
// "amd": true
// },
env: {
"es2020": true
},
extends: 'standard',
// "globals": {
// "Atomics": "readonly",
Expand All @@ -15,6 +14,7 @@ module.exports = {
// "ecmaVersion": 2015,
// "sourceType": "module"
// },
parser: "@babel/eslint-parser", // Use Babel parser to handle modern JS syntax
plugins: [
'standard',
'promise'
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint Check on PR

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm install

- name: Run ESLint
run: npm run lint
2 changes: 1 addition & 1 deletion lib/app/installation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ export function InstallationCollection (http, data) {
return obj.map((installationData) => {
return new Installation(http, { data: installationData })
})
}
}
4 changes: 2 additions & 2 deletions lib/contentstackCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default class ContentstackCollection {
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
data.stackHeaders = {
...data.stackHeaders,
responseHeaders: response.headers,
};
responseHeaders: response.headers
}
}
if (wrapperCollection) {
this.items = wrapperCollection(http, data)
Expand Down
2 changes: 1 addition & 1 deletion lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function ConcurrencyQueue ({ axios, config }) {
message: 'Unable to refresh token',
name: 'Token Error',
config: queueItem.request,
stack: (error instanceof Error) ? error.stack : null,
stack: (error instanceof Error) ? error.stack : null
})
})
this.queue = []
Expand Down
42 changes: 21 additions & 21 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu
if (response.data) {
const data = response.data || {}
if (headers) {
data.stackHeaders = headers;
data.stackHeaders = headers
}
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
data.stackHeaders = {
...data.stackHeaders,
responseHeaders: response.headers,
};
responseHeaders: response.headers
}
}
return data
} else {
Expand Down Expand Up @@ -81,10 +81,10 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me

export const create = ({ http, params }) => {
return async function (data, param) {
this.stackHeaders = {
...this.stackHeaders,
this.stackHeaders = {
...this.stackHeaders,
...(http.httpClientParams.headers?.api_version && { api_version: http.httpClientParams.headers.api_version })
};
}
const headers = {
headers: {
...cloneDeep(params),
Expand Down Expand Up @@ -152,8 +152,8 @@ export const update = (http, type, params = {}) => {
delete json.updated_by
delete json.updated_at
if (type) {
updateData[type] = json;
if (type === "entry") updateData[type] = cleanAssets(updateData[type]);
updateData[type] = json
if (type === 'entry') updateData[type] = cleanAssets(updateData[type])
} else {
updateData = json
}
Expand Down Expand Up @@ -257,22 +257,22 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {
}
}

export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, http) {
export function parseData (response, stackHeaders, contentTypeUID, taxonomyUid, http) {
const data = response.data || {}
if (stackHeaders) {
data.stackHeaders = stackHeaders
}
if (contentTypeUID) {
data.content_type_uid = contentTypeUID
}
if (taxonomy_uid) {
data.taxonomy_uid = taxonomy_uid
if (taxonomyUid) {
data.taxonomy_uid = taxonomyUid
}
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
data.stackHeaders = {
...data.stackHeaders,
responseHeaders: response.headers,
};
responseHeaders: response.headers
}
}
return data
}
Expand Down Expand Up @@ -332,22 +332,22 @@ export const move = (http, type, force = false, params = {}) => {
}

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

export function cleanAssets (data) {
if (data && typeof data === "object") {
const keys = Object.keys(data);
if (data && typeof data === 'object') {
const keys = Object.keys(data)
for (const key of keys) {
if (data[key] !== null && data[key] !== undefined && typeof data[key] === "object") {
if (data[key] !== null && data[key] !== undefined && typeof data[key] === 'object') {
if (isAsset(data[key])) {
data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid;
data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid
} else {
cleanAssets(data[key]);
cleanAssets(data[key])
}
}
}
}
return data;
return data
}
2 changes: 1 addition & 1 deletion lib/stack/auditlog/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cloneDeep from 'lodash/cloneDeep'
import error from '../../core/contentstackError'
import { fetchAll, parseData } from '../../entity'
import { fetchAll } from '../../entity'

/**
*
Expand Down
79 changes: 48 additions & 31 deletions lib/stack/bulkOperation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,25 @@ export function BulkOperation (http, data = {}) {
* client.stack({ api_key: 'api_key'}).bulkOperation().addItems({ data: itemsData })
* .then((response) => { console.log(response) })
*/
this.addItems = async ({ data, bulk_version = "" }) => {
this.urlPath = `/bulk/release/items`;
// eslint-disable-next-line camelcase
this.addItems = async ({ data, bulk_version = '' }) => {
this.urlPath = `/bulk/release/items`
const headers = {
headers: {
...cloneDeep(this.stackHeaders),
},
};
if (bulk_version) headers.headers.bulk_version = bulk_version;
...cloneDeep(this.stackHeaders)
}
}
// eslint-disable-next-line camelcase
if (bulk_version) headers.headers.bulk_version = bulk_version
try {
const response = await http.post(this.urlPath, data, headers);
const response = await http.post(this.urlPath, data, headers)
if (response.data) {
return response.data;
return response.data
}
} catch (error) {
console.error(error);
console.error(error)
}
};
}

/**
* The updateItems request allows you to update multiple items in a release in bulk.
Expand All @@ -65,23 +67,25 @@ export function BulkOperation (http, data = {}) {
* client.stack({ api_key: 'api_key'}).bulkOperation().updateItems({ data: itemsData })
* .then((response) => { console.log(response) })
*/
this.updateItems = async ({ data, bulk_version = "" }) => {
this.urlPath = `/bulk/release/update_items`;
// eslint-disable-next-line camelcase
this.updateItems = async ({ data, bulk_version = '' }) => {
this.urlPath = `/bulk/release/update_items`
const headers = {
headers: {
...cloneDeep(this.stackHeaders),
},
};
if (bulk_version) headers.headers.bulk_version = bulk_version;
...cloneDeep(this.stackHeaders)
}
}
// eslint-disable-next-line camelcase
if (bulk_version) headers.headers.bulk_version = bulk_version
try {
const response = await http.put(this.urlPath, data, headers);
const response = await http.put(this.urlPath, data, headers)
if (response.data) {
return response.data;
return response.data
}
} catch (error) {
console.error(error);
console.error(error)
}
};
}

/**
* The jobStatus request allows you to check the status of a bulk job.
Expand All @@ -94,23 +98,26 @@ export function BulkOperation (http, data = {}) {
* client.stack({ api_key: 'api_key'}).bulkOperation().jobStatus({ job_id: 'job_id' })
* .then((response) => { console.log(response) })
*/
this.jobStatus = async ({ job_id, bulk_version = "" }) => {
this.urlPath = `/bulk/jobs/${job_id}`;
// eslint-disable-next-line camelcase
this.jobStatus = async ({ job_id, bulk_version = '' }) => {
// eslint-disable-next-line camelcase
this.urlPath = `/bulk/jobs/${job_id}`
const headers = {
headers: {
...cloneDeep(this.stackHeaders),
},
};
if (bulk_version) headers.headers.bulk_version = bulk_version;
...cloneDeep(this.stackHeaders)
}
}
// eslint-disable-next-line camelcase
if (bulk_version) headers.headers.bulk_version = bulk_version
try {
const response = await http.get(this.urlPath, headers);
const response = await http.get(this.urlPath, headers)
if (response.data) {
return response.data;
return response.data
}
} catch (error) {
console.error(error);
console.error(error)
}
};
}

/**
* The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.
Expand Down Expand Up @@ -172,6 +179,7 @@ export function BulkOperation (http, data = {}) {
* .then((response) => { console.log(response.notice) })
*
*/
// eslint-disable-next-line camelcase
this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
var httpBody = {}
if (details) {
Expand All @@ -182,19 +190,23 @@ export function BulkOperation (http, data = {}) {
...cloneDeep(this.stackHeaders)
}
}
// eslint-disable-next-line camelcase
if (is_nested) {
headers.params = {
nested: true,
event_type: 'bulk'
}
}
// eslint-disable-next-line camelcase
if (skip_workflow_stage) {
// eslint-disable-next-line camelcase
headers.headers.skip_workflow_stage_check = skip_workflow_stage
}
if (approvals) {
headers.headers.approvals = approvals
}

// eslint-disable-next-line camelcase
if (api_version) headers.headers.api_version = api_version

return publishUnpublish(http, '/bulk/publish', httpBody, headers)
Expand Down Expand Up @@ -259,7 +271,8 @@ export function BulkOperation (http, data = {}) {
* client.stack({ api_key: 'api_key'}).bulkOperation().unpublish({ details: publishDetails, is_nested: true })
* .then((response) => { console.log(response.notice) })
*/
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = ''}) => {
// eslint-disable-next-line camelcase
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
var httpBody = {}
if (details) {
httpBody = cloneDeep(details)
Expand All @@ -269,18 +282,22 @@ export function BulkOperation (http, data = {}) {
...cloneDeep(this.stackHeaders)
}
}
// eslint-disable-next-line camelcase
if (is_nested) {
headers.params = {
nested: true,
event_type: 'bulk'
}
}
// eslint-disable-next-line camelcase
if (skip_workflow_stage) {
// eslint-disable-next-line camelcase
headers.headers.skip_workflow_stage_check = skip_workflow_stage
}
if (approvals) {
headers.headers.approvals = approvals
}
// eslint-disable-next-line camelcase
if (api_version) headers.headers.api_version = api_version
return publishUnpublish(http, '/bulk/unpublish', httpBody, headers)
}
Expand Down
Loading
Loading