diff --git a/.github/workflows/jira.yml b/.github/workflows/jira.yml index b6ddc58f..caa4bbdf 100644 --- a/.github/workflows/jira.yml +++ b/.github/workflows/jira.yml @@ -30,4 +30,4 @@ jobs: uses: atlassian/gajira-transition@v3 with: issue: ${{ steps.create.outputs.issue }} - transition: ${{ secrets.JIRA_TRANSITION }} \ No newline at end of file + transition: ${{ secrets.JIRA_TRANSITION }} diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index adb3107d..20dad4a4 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -31,4 +31,4 @@ jobs: - run: npm ci - run: npm publish env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/.github/workflows/sast-scan.yml b/.github/workflows/sast-scan.yml new file mode 100644 index 00000000..3b9521a5 --- /dev/null +++ b/.github/workflows/sast-scan.yml @@ -0,0 +1,11 @@ +name: SAST Scan +on: + pull_request: + types: [opened, synchronize, reopened] +jobs: + security-sast: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Semgrep Scan + run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto \ No newline at end of file diff --git a/.talismanrc b/.talismanrc index 641a0d6a..580bf496 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,6 +1,7 @@ fileignoreconfig: - filename: package-lock.json checksum: f3c78348e6bb5b0d9521aed5fab5eeff46ccc3b0d2a4c5e3b272c4b23cfa891b + checksum: 28f8e6d0e7856b4a568fd260dcc4deb531bcdbebbbff956b008ce7dd26a0475d - filename: test/typescript/taxonomy.test.ts checksum: e4bdf633e147fd60d929d379f20c814eed5f68b11421d7b53ec8826e9142de37 - filename: src/core/modules/taxonomy.js @@ -11,4 +12,7 @@ fileignoreconfig: checksum: c88b336f9a271397ffedcf8c5085941ceb0bd1cd7e25ed9ada3acd8ce4f8970c - filename: test/typescript/stack.test.ts checksum: f90544059eacaf20571f59bac90acd4e4c2178601a6f00ede49816a4621aefa8 + checksum: bbb3c425f8e1a63d4793f69ee9eaba9559294ff53f163a28f70ae54b1792276a +- filename: src/core/contentstack.js + checksum: 90a3b07300155a34f67dc3df87363107eec202123a21bc0cefda324e477a676d version: "" diff --git a/CHANGELOG.md b/CHANGELOG.md index e356c541..918b389a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,26 @@ ## Change log ### Version: 3.20.0 + #### Date: March-12-2024 ##### New Features: - Variants Feature support added + +#### Date: May-31-2024 +##### Enhanncement: + - Adds Timeline Preview changes + +### Version: 3.20.1 +#### Date: July-09-2024 +##### Fix: + - Type support for LivePreviewQuery method params + +### Version: 3.19.3 +#### Date: May-17-2024 +##### Enhanncement: + - Update Asset URL method added + ### Version: 3.19.2 #### Date: April-17-2024 ##### Dependency: diff --git a/index.d.ts b/index.d.ts index 5b97e516..89126d2f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -98,6 +98,8 @@ export interface LivePreviewConfigWithPreviewToken { export interface LivePreviewQuery { live_preview: string content_type_uid: string + preview_timestamp: string + release_id: string } export interface RetryDelayOption { @@ -170,6 +172,7 @@ export function Stack(config: Config): Stack; */ export function Stack(api_key: string, access_token: string, environment_name: string, region?: string, fetchOptions?: FetchOptions): Stack; +export function updateAssetURL(entry: object): object; export class ContentType { constructor(); content_type_uid: string diff --git a/package-lock.json b/package-lock.json index a6208978..d3cc2881 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.20.0", "license": "MIT", "dependencies": { - "@contentstack/utils": "^1.3.3", + "@contentstack/utils": "^1.3.8", "cheerio": "^1.0.0-rc.12", "es6-promise": "^4.1.1", "isomorphic-fetch": "^3.0.0", @@ -1800,9 +1800,9 @@ "dev": true }, "node_modules/@contentstack/utils": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.3.tgz", - "integrity": "sha512-Zj2ejyfbxZlXrF1Wl9lhwK2mCCWo5ooiDnSlNA8nupZ1nDsTfouYERgps8r/uyzm18Vda2wBitxloThxKAyzsA==" + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.8.tgz", + "integrity": "sha512-BKZcZs2/odh9nmugLmiNVBEbz34gjfgibZOsRlYV9ux7t+GkfjbELDjWJpKenL6G5Mb270VXVuDbNqkDLK96Zw==" }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", diff --git a/package.json b/package.json index 3c1c8bd7..9c8ef782 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.20.0", + "version": "4.0.0", "description": "Contentstack Javascript SDK", "homepage": "https://www.contentstack.com/", "author": { @@ -11,7 +11,7 @@ "browser": "dist/web/contentstack.js", "react-native": "dist/react-native/contentstack.js", "types": "./index.d.ts", - "_id": "contentstack@3.16.1", + "_id": "contentstack@3.19.3", "scripts": { "test": "npm run test:e2e && npm run test:typescript", "test:e2e": "tape test/index.js | tap-html --out ./tap-html.html", @@ -99,7 +99,7 @@ "webpack-node-externals": "^3.0.0" }, "dependencies": { - "@contentstack/utils": "^1.3.3", + "@contentstack/utils": "^1.3.8", "cheerio": "^1.0.0-rc.12", "es6-promise": "^4.1.1", "isomorphic-fetch": "^3.0.0", diff --git a/src/core/contentstack.js b/src/core/contentstack.js index fffc5f7a..bcffa3a3 100755 --- a/src/core/contentstack.js +++ b/src/core/contentstack.js @@ -27,13 +27,39 @@ class Contentstack { this.Utils = require('@contentstack/utils'); } -/** -* @memberOf Contentstack -*/ + /** + + * @memberOf Contentstack + */ Stack(...stack_arguments){ return new Stack(...stack_arguments); } + + updateAssetURL(entry) { + // check if entry consist of _embedded_items object + if (entry._embedded_items == undefined) { + throw new Error("_embedded_items not present in entry. Call includeEmbeddedItems() before fetching entry."); + } + + // Iterate through each object in _embedded_items and update the asset link + for (let key in entry._embedded_items) { + let embedded_item = entry._embedded_items[key]; + if (Array.isArray(embedded_item)) { + + embedded_item.forEach((item) => { + + if (item._content_type_uid == 'sys_assets' && item.filename) { + + const correspondingAsset = entry[key].children.find(child => child.attrs['asset-uid'] === item.uid); + if (correspondingAsset) { + correspondingAsset.attrs['asset-link'] = item.url; + } + } + }); + } + } + } } module.exports = new Contentstack(); diff --git a/src/core/lib/utils.js b/src/core/lib/utils.js index 1311ef0c..894284f3 100755 --- a/src/core/lib/utils.js +++ b/src/core/lib/utils.js @@ -91,7 +91,7 @@ export function merge(target, source) { // return true if process is running in browser else false export function isBrowser() { - return (typeof window !== "undefined" && typeof process === "object" && process.title === "browser"); + return (typeof window !== "undefined"); } diff --git a/src/core/stack.js b/src/core/stack.js index 59b105e6..f18a25ab 100755 --- a/src/core/stack.js +++ b/src/core/stack.js @@ -111,6 +111,7 @@ export default class Stack { }; if (typeof stack_arguments[0].live_preview == "object") { this.live_preview = Utils.mergeDeep(this.config.live_preview , stack_arguments[0].live_preview) + this.setLivePreviewTimelinePreviewForClient() } if (typeof stack_arguments[0].branch === "string" && stack_arguments[0].branch !== undefined) { this.headers.branch = stack_arguments[0].branch @@ -276,12 +277,35 @@ export default class Stack { } + setLivePreviewTimelinePreviewForClient() { + if (Utils.isBrowser()){ + const params = new URL(document.location.toString()).searchParams; + if (params.has('live_preview')) { + this.live_preview.live_preview = params.get('live_preview'); + } + if (params.has('release_id')) { + this.headers['release_id'] = params.get('release_id'); + } + if (params.has('preview_timestamp')) { + this.headers['preview_timestamp'] = params.get('preview_timestamp'); + } + } + } + + livePreviewQuery(query) { if (this.live_preview) { this.live_preview.live_preview = query.live_preview || 'init'; this.live_preview.content_type_uid = query.content_type_uid; this.live_preview.entry_uid = query.entry_uid } + + if (query.hasOwnProperty('release_id')) { + this.headers['release_id'] = query.release_id; + } + if (query.hasOwnProperty('preview_timestamp')) { + this.headers['preview_timestamp'] = query.preview_timestamp; + } } /**