From 1d16db9ee0c628a4a76ca6eebb0bf489a58ce5e5 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Tue, 14 May 2024 11:50:08 +0530 Subject: [PATCH 1/2] feat: :sparkles: updateAssetURL method added --- .talismanrc | 2 ++ CHANGELOG.md | 5 +++++ index.d.ts | 1 + package.json | 4 ++-- src/core/contentstack.js | 30 +++++++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.talismanrc b/.talismanrc index 2fcb7ba9..32440f30 100644 --- a/.talismanrc +++ b/.talismanrc @@ -11,4 +11,6 @@ fileignoreconfig: checksum: c88b336f9a271397ffedcf8c5085941ceb0bd1cd7e25ed9ada3acd8ce4f8970c - filename: test/typescript/stack.test.ts checksum: bbb3c425f8e1a63d4793f69ee9eaba9559294ff53f163a28f70ae54b1792276a +- filename: src/core/contentstack.js + checksum: 90a3b07300155a34f67dc3df87363107eec202123a21bc0cefda324e477a676d version: "" diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e66f408..81ca5708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change log +### 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 1bad8345..75c7d691 100644 --- a/index.d.ts +++ b/index.d.ts @@ -161,6 +161,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.json b/package.json index 59b0b324..c7577ff0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.19.2", + "version": "3.19.3", "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", diff --git a/src/core/contentstack.js b/src/core/contentstack.js index fffc5f7a..9bb3c0ba 100755 --- a/src/core/contentstack.js +++ b/src/core/contentstack.js @@ -27,13 +27,37 @@ 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); + correspondingAsset.attrs['asset-link'] = item.url; + } + }); + } + } + } } module.exports = new Contentstack(); From 781ac65edc9bee6ee831ab588a5d23e7b8c565ca Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Tue, 14 May 2024 12:06:05 +0530 Subject: [PATCH 2/2] fix: :adhesive_bandage: object validation added --- src/core/contentstack.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/contentstack.js b/src/core/contentstack.js index 9bb3c0ba..bcffa3a3 100755 --- a/src/core/contentstack.js +++ b/src/core/contentstack.js @@ -52,7 +52,9 @@ class Contentstack { if (item._content_type_uid == 'sys_assets' && item.filename) { const correspondingAsset = entry[key].children.find(child => child.attrs['asset-uid'] === item.uid); - correspondingAsset.attrs['asset-link'] = item.url; + if (correspondingAsset) { + correspondingAsset.attrs['asset-link'] = item.url; + } } }); }