Skip to content

Commit

Permalink
Merge pull request #29 from contentstack/bugfix/CS-40717
Browse files Browse the repository at this point in the history
Fix: Cannot read properties of undefined (reading 'hasOwnProperty') at stack.js
  • Loading branch information
abhinav-from-contentstack authored Aug 29, 2023
2 parents 11db6d5 + 149fd00 commit 77e9825
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 44 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datasync-filesystem-sdk",
"version": "1.0.9",
"version": "1.0.10",
"description": "JavaScript filesystem SDK to query data synced via @contentstack/datasync-content-store-filesystem",
"main": "dist/index.js",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"dependencies": {
"json-mask": "2.0.0",
"lodash": "^4.17.21",
"mkdirp": "^2.1.6",
"mkdirp": "^3.0.1",
"sift": "16.0.1"
},
"devDependencies": {
Expand Down
19 changes: 11 additions & 8 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,12 @@ export class Stack {
if (flag) {
for (let e = 0, f = oldShelf[i].path.length; e < f; e++) {
// tslint:disable-next-line: max-line-length
if (oldShelf[i].path[e].hasOwnProperty('_content_type_uid') && Object.keys(oldShelf[i].path[e]).length === 2) {
(oldShelf[i].path as any).splice(e, 1)
break
if (
oldShelf[i].path[e]?.hasOwnProperty("_content_type_uid") &&
Object.keys(oldShelf[i].path[e]).length === 2
) {
(oldShelf[i].path as any).splice(e, 1);
break;
}
}
}
Expand Down Expand Up @@ -1587,7 +1590,7 @@ export class Stack {

result.docs.forEach((doc) => {
this.projections.forEach((key) => {
if (doc.hasOwnProperty(key) && this.contentStore.projections[key] === 0) {
if (doc?.hasOwnProperty(key) && this.contentStore.projections[key] === 0) {
delete doc[key]
}
})
Expand Down Expand Up @@ -1698,7 +1701,7 @@ export class Stack {

filteredAssets.forEach((doc) => {
this.projections.forEach((key) => {
if (doc.hasOwnProperty(key) && this.contentStore.projections[key] === 0) {
if (doc?.hasOwnProperty(key) && this.contentStore.projections[key] === 0) {
delete doc[key]
}
})
Expand Down Expand Up @@ -1758,7 +1761,7 @@ export class Stack {
if (flag) {
for (let e = 0, f = oldObjectPointerList[i].path.length; e < f; e++) {
// tslint:disable-next-line: max-line-length
if (oldObjectPointerList[i].path[e].hasOwnProperty('_content_type_uid') && Object.keys(oldObjectPointerList[i].path[e]).length === 2) {
if (oldObjectPointerList[i].path[e]?.hasOwnProperty('_content_type_uid') && Object.keys(oldObjectPointerList[i].path[e]).length === 2) {
(oldObjectPointerList[i].path as any).splice(e, 1)
break
}
Expand Down Expand Up @@ -1809,11 +1812,11 @@ export class Stack {
for (let i = 0, j = filteredContents.length; i < j; i++) {
let assetFieldPaths: string[]
let entryReferencePaths: string[]
if (filteredContents[i].hasOwnProperty(this.types.assets)) {
if (filteredContents[i]?.hasOwnProperty(this.types.assets)) {
assetFieldPaths = Object.keys(filteredContents[i][this.types.assets])
paths = paths.concat(assetFieldPaths)
}
if (filteredContents[i].hasOwnProperty('_references')) {
if (filteredContents[i]?.hasOwnProperty('_references')) {
entryReferencePaths = Object.keys(filteredContents[i][this.types.references])
paths = paths.concat(entryReferencePaths)

Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { existsSync } from './fs'
import {
getConfig,
} from './index'
import mkdirp from 'mkdirp';
import { sync } from 'mkdirp';
const localePaths = Object.create(null)

export const difference = (obj, baseObj) => {
Expand Down Expand Up @@ -66,14 +66,14 @@ export const getBaseDir = ({baseDir}) => {
let contentDir: string
if (isAbsolute(baseDir)) {
if (!existsSync(baseDir)) {
mkdirp.sync(baseDir)
sync(baseDir)
}
contentDir = baseDir
} else {
const appPath = join(__dirname, '..', '..', '..')
contentDir = join(appPath, baseDir)
if (!existsSync(contentDir)) {
mkdirp.sync(contentDir)
sync(contentDir)
}
}

Expand Down

0 comments on commit 77e9825

Please sign in to comment.