From 4678515f0d2a1fdec4e3937d7c4153bde5f264fb Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 20 Jan 2025 12:01:34 +0530 Subject: [PATCH 01/13] sca-scan.yml --- .github/workflows/sca-scan.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index decebb1..4fa4560 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -6,18 +6,10 @@ jobs: security-sca: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@master - - name: Setup .NET Core @ Latest - uses: actions/setup-dotnet@v1 - with: - dotnet-version: "7.0.x" - - name: Run Dotnet Restore - run: | - dotnet restore + - uses: actions/checkout@master - name: Run Snyk to check for vulnerabilities uses: snyk/actions/dotnet@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} with: - args: --file=Contentstack.Core/obj/project.assets.json --fail-on=all + args: --fail-on=all From d46aaf09af2b663db1deeb3c851000c6e3b248bf Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 20 Jan 2025 12:01:46 +0530 Subject: [PATCH 02/13] jira.yml --- .github/workflows/jira.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jira.yml b/.github/workflows/jira.yml index caa4bbd..250abc7 100644 --- a/.github/workflows/jira.yml +++ b/.github/workflows/jira.yml @@ -21,7 +21,7 @@ jobs: project: ${{ secrets.JIRA_PROJECT }} issuetype: ${{ secrets.JIRA_ISSUE_TYPE }} summary: | - ${{ github.event.pull_request.title }} + Snyk | Vulnerability | ${{ github.event.repository.name }} | ${{ github.event.pull_request.title }} description: | PR: ${{ github.event.pull_request.html_url }} From 8e3e06257b99c6e6b9cc980dda732dff4402b05b Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 20 Jan 2025 12:01:47 +0530 Subject: [PATCH 03/13] sast-scan.yml From 040d43efe65f20a4ef9255efea065fe9855d0d07 Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 20 Jan 2025 12:01:48 +0530 Subject: [PATCH 04/13] codeql-analysis.yml From f3bcaa3865ea9b1a59c9ace24acb274baa9ad7be Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 20 Jan 2025 12:01:52 +0530 Subject: [PATCH 05/13] Updated codeowners --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 0773923..1be7e0d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @contentstack/security-admin \ No newline at end of file +* @contentstack/security-admin From 2d93d604cb2cc87c36a2c0fd2706ec4904435ae9 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 3 Mar 2025 16:15:59 +0530 Subject: [PATCH 06/13] Feat: Added Support for timeline preview --- CHANGELOG.md | 6 ++++++ .../Configuration/LivePreviewConfig.cs | 2 ++ Contentstack.Core/ContentstackClient.cs | 14 ++++++++++++++ Contentstack.Core/Internals/HttpRequestHandler.cs | 2 +- Contentstack.Core/Models/Entry.cs | 4 ++++ Contentstack.Core/Models/Query.cs | 12 ++++++++++++ Directory.Build.props | 2 +- LICENSE | 2 +- 8 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae8dc8e..8e5cf09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### Version: 2.21.0 +#### Date: March-03-2025 + +##### Feat: +- Added Support for Timeline Preview + ### Version: 2.20.0 #### Date: Dec-19-2024 diff --git a/Contentstack.Core/Configuration/LivePreviewConfig.cs b/Contentstack.Core/Configuration/LivePreviewConfig.cs index 240db8e..afa3fb2 100644 --- a/Contentstack.Core/Configuration/LivePreviewConfig.cs +++ b/Contentstack.Core/Configuration/LivePreviewConfig.cs @@ -14,5 +14,7 @@ public class LivePreviewConfig internal string ContentTypeUID { get; set; } internal string EntryUID { get; set; } internal JObject PreviewResponse { get; set; } + internal string releaseId {get; set;} + internal string previewTimestamp {get; set;} } } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index b86d2f4..1ff6b78 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -360,6 +360,10 @@ private async Task GetLivePreviewData() headerAll["authorization"] = this.LivePreviewConfig.ManagementToken; } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.LivePreviewConfig.PreviewToken; + } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.releaseId)) { + headerAll["release_id"] = this.LivePreviewConfig.releaseId; + } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.previewTimestamp)) { + headerAll["preview_timestamp"] = this.LivePreviewConfig.previewTimestamp; } else { throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } @@ -576,6 +580,16 @@ public async Task LivePreviewQueryAsync(Dictionary query) string hash = null; query.TryGetValue("live_preview", out hash); this.LivePreviewConfig.LivePreview = hash; + } + if (query.Keys.Contains("release_id")) { + string releaseId = null; + query.TryGetValue("release_id", out releaseId); + this.LivePreviewConfig.releaseId = releaseId; + } + if (query.Keys.Contains("preview_timestamp")) { + string previewTimestamp = null; + query.TryGetValue("preview_timestamp", out previewTimestamp); + this.LivePreviewConfig.previewTimestamp = previewTimestamp; } this.LivePreviewConfig.PreviewResponse = await GetLivePreviewData(); } diff --git a/Contentstack.Core/Internals/HttpRequestHandler.cs b/Contentstack.Core/Internals/HttpRequestHandler.cs index 6252f51..3f5e45e 100644 --- a/Contentstack.Core/Internals/HttpRequestHandler.cs +++ b/Contentstack.Core/Internals/HttpRequestHandler.cs @@ -48,7 +48,7 @@ public async Task ProcessRequest(string Url, Dictionary var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; - request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.20.0"; + request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.21.0"; request.Timeout = timeout; if (proxy != null) diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index c8a8788..e8e1db8 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -1398,6 +1398,10 @@ public async Task Fetch() headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken; + } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) { + headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; + } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) { + headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; } else { throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index a6b453e..d034b8e 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1840,6 +1840,10 @@ private async Task Exec() headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken; + } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) { + headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; + } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) { + headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; } else { throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } @@ -1866,6 +1870,14 @@ private async Task Exec() { headerAll.Remove("preview_token"); } + if (!isLivePreview && headerAll.ContainsKey("release_id")) + { + headerAll.Remove("release_id"); + } + if (!isLivePreview && headerAll.ContainsKey("preview_timestamp")) + { + headerAll.Remove("preview_timestamp"); + } mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment); if (QueryValueJson != null && QueryValueJson.Count > 0) diff --git a/Directory.Build.props b/Directory.Build.props index 2beb17e..402aa0e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 2.20.0 + 2.21.0 diff --git a/LICENSE b/LICENSE index ec1403b..e1238b5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2012-2024 Contentstack (http://app.contentstack.com). All Rights Reserved +Copyright (c) 2012-2025 Contentstack (http://app.contentstack.com). All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From d0d8c902ca2bd77e9c5af68e6d52b3c5a6475006 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 5 Mar 2025 16:10:09 +0530 Subject: [PATCH 07/13] Fixing all the requied Test cases --- Contentstack.Core.Tests/EntryTest.cs | 8 +- Contentstack.Core.Tests/StackConfig.cs | 3 +- Contentstack.Core.Tests/TaxonomyTest.cs | 16 +-- Contentstack.Core/Models/Entry.cs | 15 ++- Contentstack.Core/Models/Query.cs | 127 +++++++++++++++++------- Contentstack.Core/Models/Taxonomy.cs | 12 +-- 6 files changed, 121 insertions(+), 60 deletions(-) diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index ea9fbd4..f7f7778 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -72,7 +72,7 @@ public async Task FetchEntryByUIDPublishFallback() ContentType contenttype = client.ContentType(source); string uid = await GetUID("source1"); Entry sourceEntry = contenttype.Entry(uid); - await sourceEntry + sourceEntry = await sourceEntry .SetLocale("ja-jp") .IncludeFallback() .Fetch(); @@ -98,8 +98,7 @@ await sourceEntry else { Assert.True(result.Uid == sourceEntry.Uid); - Assert.NotNull(result._variant); - Assert.NotNull(result._variant["_uid"]); + Assert.Null(result._variant); } }); } @@ -122,8 +121,7 @@ await sourceEntry else { Assert.True(result.Uid == sourceEntry.Uid); - Assert.NotNull(result._variant); - Assert.NotNull(result._variant["_uid"]); + Assert.Null(result._variant); } }); } diff --git a/Contentstack.Core.Tests/StackConfig.cs b/Contentstack.Core.Tests/StackConfig.cs index c0df3cc..95ae43c 100644 --- a/Contentstack.Core.Tests/StackConfig.cs +++ b/Contentstack.Core.Tests/StackConfig.cs @@ -38,7 +38,8 @@ public static ContentstackClient GetStack() Environment = environment, Host = host, Timeout = 4500, - //Proxy = new System.Net.WebProxy("http://example.com:8080") + + //Proxy = new System.Net.WebProxy("http://example.com:8080") }; ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); diff --git a/Contentstack.Core.Tests/TaxonomyTest.cs b/Contentstack.Core.Tests/TaxonomyTest.cs index b5d49aa..fa6ccb8 100644 --- a/Contentstack.Core.Tests/TaxonomyTest.cs +++ b/Contentstack.Core.Tests/TaxonomyTest.cs @@ -39,7 +39,7 @@ public async Task TaxonomyExists() bool IsTrue = false; foreach (Entry data in result.Items) { - IsTrue = data.GetContentType() != null; + IsTrue = data.Get("_content_type_uid") != null; if (!IsTrue) { break; @@ -69,7 +69,7 @@ public async Task TaxonomyEqualAndBelow() bool IsTrue = false; foreach (Entry data in result.Items) { - IsTrue = data.GetContentType() != null; + IsTrue = data.Get("_content_type_uid") != null; if (!IsTrue) { break; @@ -99,7 +99,7 @@ public async Task TaxonomyBelow() bool IsTrue = false; foreach (Entry data in result.Items) { - IsTrue = data.GetContentType() != null; + IsTrue = data.Get("_content_type_uid") != null; if (!IsTrue) { break; @@ -118,7 +118,7 @@ public async Task TaxonomyEqualAndAbove() { // Description: Taxonomy EqualAndAbove - Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level) Taxonomy query = client.Taxonomies(); - query.EqualAndAbove("taxonomies.one", "term_one"); + query.EqualAndAbove("taxonomies.one", "term_one_child"); var result = await query.Find(); if (result == null && result.Items.Count() == 0) { @@ -129,7 +129,7 @@ public async Task TaxonomyEqualAndAbove() bool IsTrue = false; foreach (Entry data in result.Items) { - IsTrue = data.GetContentType() != null; + IsTrue = data.Get("_content_type_uid") != null; if (!IsTrue) { break; @@ -148,7 +148,7 @@ public async Task TaxonomyAbove() { // Description: Taxonomy Above - Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level) Taxonomy query = client.Taxonomies(); - query.Above("taxonomies.one", "term_one"); + query = query.Above("taxonomies.one", "term_one_child"); var result = await query.Find(); if (result == null && result.Items.Count() == 0) { @@ -157,9 +157,9 @@ public async Task TaxonomyAbove() else if (result != null) { bool IsTrue = false; - foreach (Entry data in result.Items) + foreach (var data in result.Items) { - IsTrue = data.GetContentType() != null; + IsTrue = data.Get("_content_type_uid") != null; if (!IsTrue) { break; diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index e8e1db8..d353677 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -108,7 +108,9 @@ private string _Url /// }); /// /// - public Dictionary Metadata { get; set; } + public Dictionary Metadata { get; set; } + + public Dictionary publish_details { get; set; } /// /// Set key/value attributes of an current entry instance. @@ -1422,7 +1424,7 @@ public async Task Fetch() { cachePolicy = _CachePolicy; } - + HttpRequestHandler RequestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance); var outputResult = await RequestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout, proxy: this.ContentTypeInstance.StackInstance.Config.Proxy); JObject obj = JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); @@ -1487,8 +1489,13 @@ internal void ParseObject(JObject jsonObj, string url = null) this.jObject = jsonObj; this._ObjectAttributes = jsonObj.ToObject>(); if (_ObjectAttributes != null && _ObjectAttributes.ContainsKey("_metadata")) - { - Dictionary _metadataJSON = (Dictionary)_ObjectAttributes["_metadata"]; + { + var jObject = (Newtonsoft.Json.Linq.JObject)_ObjectAttributes["_metadata"]; + var _metadataJSON = new Dictionary(); + foreach (var property in jObject.Properties()) + { + _metadataJSON[property.Name] = property.Value.ToObject(); + } List iterator = _metadataJSON.Keys.ToList(); Metadata = new Dictionary(); foreach (var key in iterator) diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index d034b8e..59092f6 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Contentstack.Core.Internals; using Contentstack.Core.Configuration; - +using Contentstack.Core.Models; namespace Contentstack.Core.Models { @@ -21,13 +21,13 @@ public class Query internal Dictionary _FormHeaders = new Dictionary(); private Dictionary _Headers = new Dictionary(); - private Dictionary UrlQueries = new Dictionary(); - private Dictionary QueryValueJson = new Dictionary(); - private string _ResultJson = string.Empty; private CachePolicy _CachePolicy; + private Dictionary UrlQueries = new Dictionary(); + protected Dictionary QueryValueJson = new Dictionary(); + private string _ResultJson = string.Empty; private CachePolicy _CachePolicy; private ContentType ContentTypeInstance { get; set; } - - private string _Url + private ContentstackClient TaxonomyInstance { get; set; } + protected virtual string _Url { get { @@ -38,6 +38,7 @@ private string _Url baseURL, this.ContentTypeId); } + } #endregion @@ -55,10 +56,11 @@ private string _Url /// }); /// /// - public string ContentTypeId { get; set; } - + public string ContentTypeId { get; set; } + public ContentstackClient Stack { get; private set; } + #endregion - + #region Internal Constructors internal Query() { @@ -67,10 +69,15 @@ internal Query() internal Query(string contentTypeName) { this.ContentTypeId = contentTypeName; + } + internal Query(ContentstackClient Tax) + { + SetTaxonomyInstance(Tax); } #endregion #region Internal Functions + internal static ContentstackException GetContentstackError(Exception ex) { Int32 errorCode = 0; @@ -127,11 +134,17 @@ internal void SetContentTypeInstance(ContentType contentTypeInstance) this.ContentTypeInstance = contentTypeInstance; //SetLocale("en-us"); } - + internal void SetTaxonomyInstance(ContentstackClient Tax) + { + this.TaxonomyInstance = Tax; + //SetLocale("en-us"); + } + + #endregion - + #region Public Functions - + /// /// Set Language instance /// @@ -1810,17 +1823,36 @@ public async Task> FindOne() private ContentstackCollection parseJObject(JObject jObject) { - var entries = jObject.SelectToken("$.entries").ToObject>(this.ContentTypeInstance.StackInstance.Serializer); - var collection = jObject.ToObject>(this.ContentTypeInstance.StackInstance.Serializer); - foreach (var entry in entries) - { - if (entry.GetType() == typeof(Entry)) - { - (entry as Entry).SetContentTypeInstance(this.ContentTypeInstance); - } - } - collection.Items = entries; - return collection; + + if(this.TaxonomyInstance!=null) + { + var entries = jObject.SelectToken("$.entries").ToObject>(this.TaxonomyInstance.Serializer); + var collection = jObject.ToObject>(this.TaxonomyInstance.Serializer); + foreach (var entry in entries) + { + if (entry.GetType() == typeof(Entry)) + { + (entry as Entry).SetContentTypeInstance(this.ContentTypeInstance); + } + } + collection.Items = entries; + return collection; + + } else + { + var entries = jObject.SelectToken("$.entries").ToObject>(this.ContentTypeInstance.StackInstance.Serializer); + var collection = jObject.ToObject>(this.ContentTypeInstance.StackInstance.Serializer); + foreach (var entry in entries) + { + if (entry.GetType() == typeof(Entry)) + { + (entry as Entry).SetContentTypeInstance(this.ContentTypeInstance); + } + } + collection.Items = entries; + return collection; + } + } #endregion @@ -1831,8 +1863,8 @@ private async Task Exec() Dictionary mainJson = new Dictionary(); bool isLivePreview = false; - if (this.ContentTypeInstance.StackInstance.LivePreviewConfig.Enable == true - && this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId) + if (this.ContentTypeInstance!=null && this.ContentTypeInstance.StackInstance.LivePreviewConfig.Enable == true + && this.ContentTypeInstance.StackInstance?.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId) { mainJson.Add("live_preview", this.ContentTypeInstance.StackInstance.LivePreviewConfig.LivePreview ?? "init"); @@ -1855,8 +1887,8 @@ private async Task Exec() { foreach (var header in headers) { - if (this.ContentTypeInstance.StackInstance.LivePreviewConfig.Enable == true - && this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId + if (this.ContentTypeInstance!=null && this.ContentTypeInstance?.StackInstance.LivePreviewConfig.Enable == true + && this.ContentTypeInstance?.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance?.ContentTypeId && header.Key == "access_token" && isLivePreview) { @@ -1865,7 +1897,14 @@ private async Task Exec() headerAll.Add(header.Key, (string)header.Value); } } - + + if(this.TaxonomyInstance!=null && this.TaxonomyInstance._LocalHeaders!=null) + { + foreach (var header in this.TaxonomyInstance._LocalHeaders) + { + headerAll.Add(header.Key, (string)header.Value); + } + } if (!isLivePreview && headerAll.ContainsKey("preview_token")) { headerAll.Remove("preview_token"); @@ -1879,7 +1918,14 @@ private async Task Exec() headerAll.Remove("preview_timestamp"); } - mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment); + if(this.ContentTypeInstance!=null) + { + mainJson.Add("environment", this.ContentTypeInstance?.StackInstance.Config.Environment); + } + if (this.TaxonomyInstance!=null && this.TaxonomyInstance.Config.Environment != null) + { + mainJson.Add("environment", this.TaxonomyInstance?.Config.Environment); + } if (QueryValueJson != null && QueryValueJson.Count > 0) mainJson.Add("query", QueryValueJson); @@ -1889,17 +1935,28 @@ private async Task Exec() } try - { - HttpRequestHandler requestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance); - var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout); - return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); + { + if(this.TaxonomyInstance!=null) + { + HttpRequestHandler requestHandler = new HttpRequestHandler(this.TaxonomyInstance); + var branch = this.TaxonomyInstance.Config.Branch != null ? this.TaxonomyInstance.Config.Branch : "main"; + var outputResult = await requestHandler.ProcessRequest(this._Url, headerAll, mainJson, Branch: branch, isLivePreview: isLivePreview, timeout: this.TaxonomyInstance.Config.Timeout); + return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); + } + else + { + HttpRequestHandler requestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance); + var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout); + return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); + } } catch (Exception ex) { throw GetContentstackError(ex); } - } - + } + + #region Private Functions private Dictionary GetHeader(Dictionary localHeader) { diff --git a/Contentstack.Core/Models/Taxonomy.cs b/Contentstack.Core/Models/Taxonomy.cs index ff979da..0938563 100644 --- a/Contentstack.Core/Models/Taxonomy.cs +++ b/Contentstack.Core/Models/Taxonomy.cs @@ -13,36 +13,34 @@ namespace Contentstack.Core.Models public class Taxonomy: Query { - #region Internal Variables private Dictionary _ObjectAttributes = new Dictionary(); private Dictionary _Headers = new Dictionary(); private Dictionary _StackHeaders = new Dictionary(); private Dictionary UrlQueries = new Dictionary(); - private Dictionary QueryValueJson = new Dictionary(); - private string _Url + protected override string _Url { get { Config config = this.Stack.Config; return String.Format("{0}/taxonomies/entries", config.BaseUrl); } - } + } #endregion - public ContentstackClient Stack { get; set; } + #region Internal Constructors internal Taxonomy() { } - internal Taxonomy(ContentstackClient stack) + internal Taxonomy(ContentstackClient stack): base(stack) { this.Stack = stack; this._StackHeaders = stack._LocalHeaders; @@ -189,7 +187,7 @@ public Taxonomy EqualAndBelow(String key, Object value) { try { - Dictionary queryValue = new Dictionary { { "eq_$below", value } }; + Dictionary queryValue = new Dictionary { { "$eq_below", value } }; QueryValueJson.Add(key, queryValue); } catch (Exception e) From 8168b3d7bba9f995b58f025fbf7735df58fc59c8 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 6 Mar 2025 15:51:57 +0530 Subject: [PATCH 08/13] Added Test cases for the Live Preview and removed not used imports --- Contentstack.Core.Tests/ContentTypeTest.cs | 4 - Contentstack.Core.Tests/LivePreivewTest.cs | 122 ++++++++++++++++++ Contentstack.Core.Tests/PluginsTest.cs | 3 +- Contentstack.Core.Tests/QueryTest.cs | 2 - Contentstack.Core.Tests/StackConfig.cs | 41 +++++- Contentstack.Core.Tests/TaxonomyTest.cs | 6 - Contentstack.Core/Configuration/Config.cs | 2 +- .../Configuration/LivePreviewConfig.cs | 8 +- Contentstack.Core/ContentstackClient.cs | 24 +++- .../Interfaces/IContentstackPlugin.cs | 4 +- .../Internals/AssetJsonConverter.cs | 1 - .../Internals/ContentstackConstants.cs | 5 +- .../Internals/ContentstackConvert.cs | 6 +- .../Internals/EntryJsonConverter.cs | 1 - Contentstack.Core/Internals/LanguageEnums.cs | 4 - Contentstack.Core/Internals/StackOutput.cs | 5 +- .../Models/ContentstackCollection.cs | 2 - Contentstack.Core/Models/Entry.cs | 14 +- Contentstack.Core/Models/Query.cs | 17 ++- Contentstack.Core/Models/SyncStack.cs | 3 +- Contentstack.Core/Models/Taxonomy.cs | 2 - 21 files changed, 206 insertions(+), 70 deletions(-) create mode 100644 Contentstack.Core.Tests/LivePreivewTest.cs mode change 100755 => 100644 Contentstack.Core/Models/ContentstackCollection.cs diff --git a/Contentstack.Core.Tests/ContentTypeTest.cs b/Contentstack.Core.Tests/ContentTypeTest.cs index 982c751..2b7cc87 100644 --- a/Contentstack.Core.Tests/ContentTypeTest.cs +++ b/Contentstack.Core.Tests/ContentTypeTest.cs @@ -2,11 +2,7 @@ using Xunit; using Contentstack.Core.Models; using System.Threading.Tasks; -using Contentstack.Core.Configuration; using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Collections; namespace Contentstack.Core.Tests { diff --git a/Contentstack.Core.Tests/LivePreivewTest.cs b/Contentstack.Core.Tests/LivePreivewTest.cs new file mode 100644 index 0000000..a6a59d2 --- /dev/null +++ b/Contentstack.Core.Tests/LivePreivewTest.cs @@ -0,0 +1,122 @@ +using System; +using Xunit; +using Contentstack.Core.Configuration; +using System.Threading.Tasks; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; + +namespace Contentstack.Core.Tests +{ + public class TestContentstackClient : ContentstackClient + { + public TestContentstackClient(ContentstackOptions options) + : base(options) + { + } + + // Override GetLivePreviewData with a hardcoded response + private new async Task GetLivePreviewData() + { + var mockResponse = new + { + entry = new + { + uid = "mock_entry_uid", + title = "Mocked Entry", + content_type_uid = "mock_content_type", + status = "preview" + } + }; + string jsonResponse = Newtonsoft.Json.JsonConvert.SerializeObject(mockResponse); + JObject data = JsonConvert.DeserializeObject(jsonResponse, this.SerializerSettings); + return await Task.FromResult((JObject)data["entry"]); + } + + // Public method to access the private method in tests + public async Task TestGetLivePreviewData() + { + return await GetLivePreviewData(); + } + } + + public class LivePreivewTest + { + ContentstackClient client = StackConfig.GetStack(); + + ContentstackClient Lpclient = StackConfig.GetLPStack(); + + private String numbersContentType = "numbers_content_type"; + String source = "source"; + + public double EPSILON { get; private set; } + + [Fact] + public async Task CheckLivePreviewConfigNotSet() + { + var LPConfig = client.GetLivePreviewConfig(); + Assert.False(LPConfig.Enable); + Assert.Null(LPConfig.PreviewToken); + Assert.Null(LPConfig.Host); + } + + [Fact] + public async Task CheckLivePreviewConfigSet() + { + var LPConfig = Lpclient.GetLivePreviewConfig(); + Assert.True(LPConfig.Enable); + Assert.NotEmpty(LPConfig.PreviewToken); + Assert.NotEmpty(LPConfig.Host); + } + + [Fact] + public async Task setQueryWithLivePreview() + { + Dictionary query = new Dictionary + { + { "content_type_uid", "ct1" }, + { "live_preview", "lphash" }, + { "release_id", "release_id" }, + { "preview_timestamp", "preview_timestamp" }, + { "entry_uid", "euid" } + }; + Lpclient.LivePreviewQueryAsync(query); + var LPConfig = Lpclient.GetLivePreviewConfig(); + Assert.Equal(LPConfig.previewTimestamp, "preview_timestamp"); + Assert.NotEmpty(LPConfig.PreviewToken); + Assert.NotEmpty(LPConfig.PreviewToken); + Assert.NotEmpty(LPConfig.Host); + } + + [Fact] + public async Task TestGetLivePreviewData() + { + // Arrange + var options = new ContentstackOptions + { + ApiKey = "test_api_key", + DeliveryToken = "test_delivery_token", + Environment = "test_environment", + LivePreview = new LivePreviewConfig + { + Enable = true, + PreviewToken = "preview_token", // Replace with a valid preview token + Host = "test-host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com") + + } + }; + + var client = new TestContentstackClient(options); + + // Act + var result = await client.TestGetLivePreviewData(); + + // Assert + Assert.NotNull(result); + Assert.Equal("mock_entry_uid", result["uid"].ToString()); + Assert.Equal("Mocked Entry", result["title"].ToString()); + } + + } +} + diff --git a/Contentstack.Core.Tests/PluginsTest.cs b/Contentstack.Core.Tests/PluginsTest.cs index 2f9dc27..ce27682 100644 --- a/Contentstack.Core.Tests/PluginsTest.cs +++ b/Contentstack.Core.Tests/PluginsTest.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Contentstack.Core.Models; using Contentstack.Core.Tests.Models; using Xunit; diff --git a/Contentstack.Core.Tests/QueryTest.cs b/Contentstack.Core.Tests/QueryTest.cs index c8ea1ab..d5a2a06 100644 --- a/Contentstack.Core.Tests/QueryTest.cs +++ b/Contentstack.Core.Tests/QueryTest.cs @@ -1,7 +1,5 @@ using System; using Xunit; -using Contentstack.Core; -using Contentstack.Core.Configuration; using Contentstack.Core.Models; using System.Threading.Tasks; using System.Collections.Generic; diff --git a/Contentstack.Core.Tests/StackConfig.cs b/Contentstack.Core.Tests/StackConfig.cs index 95ae43c..fe9a39d 100644 --- a/Contentstack.Core.Tests/StackConfig.cs +++ b/Contentstack.Core.Tests/StackConfig.cs @@ -1,8 +1,7 @@ using System; -using Contentstack.Core; -using Contentstack.Core.Models; using System.Configuration; using Microsoft.Extensions.Options; +using Contentstack.Core.Configuration; namespace Contentstack.Core.Tests { @@ -38,8 +37,7 @@ public static ContentstackClient GetStack() Environment = environment, Host = host, Timeout = 4500, - - //Proxy = new System.Net.WebProxy("http://example.com:8080") + //Proxy = new System.Net.WebProxy("http://example.com:8080") }; ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); @@ -47,5 +45,40 @@ public static ContentstackClient GetStack() return contentstackClient; } + + public static ContentstackClient GetLPStack() + { + StackConfig config = new StackConfig(); + if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0) + { + config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath); + ConfigurationManager.RefreshSection("appSettings"); + ConfigurationManager.RefreshSection("connectionStrings"); + } + string apiKey = ConfigurationManager.AppSettings["api_key"]; + string delivery_token = ConfigurationManager.AppSettings["delivery_token"]; + string environment = ConfigurationManager.AppSettings["environment"]; + string host = ConfigurationManager.AppSettings["host"]; + Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions + { + ApiKey = apiKey, + DeliveryToken = delivery_token, + Environment = environment, + Host = host, + Timeout = 4500, + LivePreview = new LivePreviewConfig + { + Enable = true, + PreviewToken = "preview_token", // Replace with a valid preview token + Host = "test_host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com") + } + //Proxy = new System.Net.WebProxy("http://example.com:8080") + }; + + ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); + + return contentstackClient; + + } } } diff --git a/Contentstack.Core.Tests/TaxonomyTest.cs b/Contentstack.Core.Tests/TaxonomyTest.cs index fa6ccb8..bb2b747 100644 --- a/Contentstack.Core.Tests/TaxonomyTest.cs +++ b/Contentstack.Core.Tests/TaxonomyTest.cs @@ -1,14 +1,8 @@ using System; using Xunit; -using Contentstack.Core; -using Contentstack.Core.Configuration; using Contentstack.Core.Models; using System.Threading.Tasks; -using System.Collections.Generic; using System.Linq; -using Contentstack.Core.Tests.Models; -using Newtonsoft.Json.Linq; -using System.Reflection.PortableExecutable; namespace Contentstack.Core.Tests { diff --git a/Contentstack.Core/Configuration/Config.cs b/Contentstack.Core/Configuration/Config.cs index f8b3406..58901e9 100644 --- a/Contentstack.Core/Configuration/Config.cs +++ b/Contentstack.Core/Configuration/Config.cs @@ -13,7 +13,7 @@ internal class Config private string _Port; private string _Version; private string _Environment; - private string _Branch; + private string _Branch="main"; private int _Timeout; private WebProxy _proxy; #endregion diff --git a/Contentstack.Core/Configuration/LivePreviewConfig.cs b/Contentstack.Core/Configuration/LivePreviewConfig.cs index afa3fb2..7bd2b23 100644 --- a/Contentstack.Core/Configuration/LivePreviewConfig.cs +++ b/Contentstack.Core/Configuration/LivePreviewConfig.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections; -using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Linq; namespace Contentstack.Core.Configuration { @@ -14,7 +12,7 @@ public class LivePreviewConfig internal string ContentTypeUID { get; set; } internal string EntryUID { get; set; } internal JObject PreviewResponse { get; set; } - internal string releaseId {get; set;} - internal string previewTimestamp {get; set;} + public string releaseId {get; set;} + public string previewTimestamp {get; set;} } } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 1ff6b78..6d9ea5f 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -11,7 +11,6 @@ using System.Net; using System.IO; using System.Collections; -using Contentstack.Utils; using Contentstack.Core.Interfaces; namespace Contentstack.Core @@ -46,7 +45,7 @@ internal string _SyncUrl } } - internal LivePreviewConfig LivePreviewConfig; + internal LivePreviewConfig LivePreviewConfig { get; set; } private Dictionary UrlQueries = new Dictionary(); private Dictionary _Headers = new Dictionary(); private string _Url @@ -360,17 +359,23 @@ private async Task GetLivePreviewData() headerAll["authorization"] = this.LivePreviewConfig.ManagementToken; } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.LivePreviewConfig.PreviewToken; - } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.releaseId)) { - headerAll["release_id"] = this.LivePreviewConfig.releaseId; - } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.previewTimestamp)) { - headerAll["preview_timestamp"] = this.LivePreviewConfig.previewTimestamp; } else { throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } + if (!string.IsNullOrEmpty(this.LivePreviewConfig.releaseId)) + { + headerAll["release_id"] = this.LivePreviewConfig.releaseId; + } + if (!string.IsNullOrEmpty(this.LivePreviewConfig.previewTimestamp)) + { + headerAll["preview_timestamp"] = this.LivePreviewConfig.previewTimestamp; + } + try { HttpRequestHandler RequestHandler = new HttpRequestHandler(this); + //string branch = this.Config.Branch ? this.Config.Branch : "main"; var outputResult = await RequestHandler.ProcessRequest(String.Format("{0}/content_types/{1}/entries/{2}", this.Config.getLivePreviewUrl(this.LivePreviewConfig), this.LivePreviewConfig.ContentTypeUID, this.LivePreviewConfig.EntryUID), headerAll, mainJson, Branch: this.Config.Branch, isLivePreview: true, timeout: this.Config.Timeout, proxy: this.Config.Proxy); JObject data = JsonConvert.DeserializeObject(outputResult.Replace("\r\n", ""), this.SerializerSettings); return (JObject)data["entry"]; @@ -478,6 +483,13 @@ public string GetApplicationKey() return StackApiKey; } + + public LivePreviewConfig GetLivePreviewConfig() + { + return LivePreviewConfig; + } + + /// /// Get stack access token /// diff --git a/Contentstack.Core/Interfaces/IContentstackPlugin.cs b/Contentstack.Core/Interfaces/IContentstackPlugin.cs index 0078469..0865006 100644 --- a/Contentstack.Core/Interfaces/IContentstackPlugin.cs +++ b/Contentstack.Core/Interfaces/IContentstackPlugin.cs @@ -1,7 +1,5 @@ -using System; -using System.Net; +using System.Net; using System.Threading.Tasks; -using Contentstack.Core.Models; namespace Contentstack.Core.Interfaces { public interface IContentstackPlugin diff --git a/Contentstack.Core/Internals/AssetJsonConverter.cs b/Contentstack.Core/Internals/AssetJsonConverter.cs index 9fc7215..9eee45a 100644 --- a/Contentstack.Core/Internals/AssetJsonConverter.cs +++ b/Contentstack.Core/Internals/AssetJsonConverter.cs @@ -1,5 +1,4 @@ using System; -using Contentstack.Core; using Contentstack.Core.Models; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/Contentstack.Core/Internals/ContentstackConstants.cs b/Contentstack.Core/Internals/ContentstackConstants.cs index 3ea6e95..f14d276 100644 --- a/Contentstack.Core/Internals/ContentstackConstants.cs +++ b/Contentstack.Core/Internals/ContentstackConstants.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; - -namespace Contentstack.Core.Internals +namespace Contentstack.Core.Internals { internal class ContentstackConstants { diff --git a/Contentstack.Core/Internals/ContentstackConvert.cs b/Contentstack.Core/Internals/ContentstackConvert.cs index b2d4d74..a35a235 100644 --- a/Contentstack.Core/Internals/ContentstackConvert.cs +++ b/Contentstack.Core/Internals/ContentstackConvert.cs @@ -1,9 +1,5 @@ -using Newtonsoft.Json; -using System; +using System; using System.IO; -using System.Net.NetworkInformation; -using System.Security.Cryptography; -using System.Text; using System.Text.RegularExpressions; namespace Contentstack.Core.Internals diff --git a/Contentstack.Core/Internals/EntryJsonConverter.cs b/Contentstack.Core/Internals/EntryJsonConverter.cs index 9c4ab9d..230e1b8 100644 --- a/Contentstack.Core/Internals/EntryJsonConverter.cs +++ b/Contentstack.Core/Internals/EntryJsonConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Contentstack.Core.Models; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/Contentstack.Core/Internals/LanguageEnums.cs b/Contentstack.Core/Internals/LanguageEnums.cs index e8a8b4c..51f50b6 100644 --- a/Contentstack.Core/Internals/LanguageEnums.cs +++ b/Contentstack.Core/Internals/LanguageEnums.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Contentstack.Core.Internals { diff --git a/Contentstack.Core/Internals/StackOutput.cs b/Contentstack.Core/Internals/StackOutput.cs index a934059..0b20489 100644 --- a/Contentstack.Core/Internals/StackOutput.cs +++ b/Contentstack.Core/Internals/StackOutput.cs @@ -1,8 +1,5 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; +using System; using System.Collections.Generic; -using System.Linq; namespace Contentstack.Core.Internals diff --git a/Contentstack.Core/Models/ContentstackCollection.cs b/Contentstack.Core/Models/ContentstackCollection.cs old mode 100755 new mode 100644 index 0edd7c6..9a1086d --- a/Contentstack.Core/Models/ContentstackCollection.cs +++ b/Contentstack.Core/Models/ContentstackCollection.cs @@ -1,8 +1,6 @@ using Newtonsoft.Json; -using System; using System.Collections; using System.Collections.Generic; -using System.Text; namespace Contentstack.Core.Models { diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index d353677..b2165aa 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -1,5 +1,4 @@ using Markdig; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -1400,14 +1399,19 @@ public async Task Fetch() headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken; - } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) { - headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; - } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) { - headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; } else { throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) + { + headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; + } + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) + { + headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; + } + isLivePreview = true; } diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index 59092f6..e755f02 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; @@ -8,7 +7,6 @@ using System.Threading.Tasks; using Contentstack.Core.Internals; using Contentstack.Core.Configuration; -using Contentstack.Core.Models; namespace Contentstack.Core.Models { @@ -1872,14 +1870,19 @@ private async Task Exec() headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken; - } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) { - headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; - } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) { - headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; } else { throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) + { + headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; + } + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) + { + headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; + } + isLivePreview = true; } diff --git a/Contentstack.Core/Models/SyncStack.cs b/Contentstack.Core/Models/SyncStack.cs index 90da34d..bd531dc 100644 --- a/Contentstack.Core/Models/SyncStack.cs +++ b/Contentstack.Core/Models/SyncStack.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Contentstack.Core.Models diff --git a/Contentstack.Core/Models/Taxonomy.cs b/Contentstack.Core/Models/Taxonomy.cs index 0938563..f9d63cd 100644 --- a/Contentstack.Core/Models/Taxonomy.cs +++ b/Contentstack.Core/Models/Taxonomy.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; -using System.Threading.Tasks; using Contentstack.Core.Configuration; using Contentstack.Core.Internals; using Newtonsoft.Json.Linq; From 27b86161c0eacc99f1b63f8d3c3acab230cc7566 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 6 Mar 2025 16:06:03 +0530 Subject: [PATCH 09/13] correction --- Contentstack.Core.Tests/LivePreivewTest.cs | 122 --------------------- 1 file changed, 122 deletions(-) delete mode 100644 Contentstack.Core.Tests/LivePreivewTest.cs diff --git a/Contentstack.Core.Tests/LivePreivewTest.cs b/Contentstack.Core.Tests/LivePreivewTest.cs deleted file mode 100644 index a6a59d2..0000000 --- a/Contentstack.Core.Tests/LivePreivewTest.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using Xunit; -using Contentstack.Core.Configuration; -using System.Threading.Tasks; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; - -namespace Contentstack.Core.Tests -{ - public class TestContentstackClient : ContentstackClient - { - public TestContentstackClient(ContentstackOptions options) - : base(options) - { - } - - // Override GetLivePreviewData with a hardcoded response - private new async Task GetLivePreviewData() - { - var mockResponse = new - { - entry = new - { - uid = "mock_entry_uid", - title = "Mocked Entry", - content_type_uid = "mock_content_type", - status = "preview" - } - }; - string jsonResponse = Newtonsoft.Json.JsonConvert.SerializeObject(mockResponse); - JObject data = JsonConvert.DeserializeObject(jsonResponse, this.SerializerSettings); - return await Task.FromResult((JObject)data["entry"]); - } - - // Public method to access the private method in tests - public async Task TestGetLivePreviewData() - { - return await GetLivePreviewData(); - } - } - - public class LivePreivewTest - { - ContentstackClient client = StackConfig.GetStack(); - - ContentstackClient Lpclient = StackConfig.GetLPStack(); - - private String numbersContentType = "numbers_content_type"; - String source = "source"; - - public double EPSILON { get; private set; } - - [Fact] - public async Task CheckLivePreviewConfigNotSet() - { - var LPConfig = client.GetLivePreviewConfig(); - Assert.False(LPConfig.Enable); - Assert.Null(LPConfig.PreviewToken); - Assert.Null(LPConfig.Host); - } - - [Fact] - public async Task CheckLivePreviewConfigSet() - { - var LPConfig = Lpclient.GetLivePreviewConfig(); - Assert.True(LPConfig.Enable); - Assert.NotEmpty(LPConfig.PreviewToken); - Assert.NotEmpty(LPConfig.Host); - } - - [Fact] - public async Task setQueryWithLivePreview() - { - Dictionary query = new Dictionary - { - { "content_type_uid", "ct1" }, - { "live_preview", "lphash" }, - { "release_id", "release_id" }, - { "preview_timestamp", "preview_timestamp" }, - { "entry_uid", "euid" } - }; - Lpclient.LivePreviewQueryAsync(query); - var LPConfig = Lpclient.GetLivePreviewConfig(); - Assert.Equal(LPConfig.previewTimestamp, "preview_timestamp"); - Assert.NotEmpty(LPConfig.PreviewToken); - Assert.NotEmpty(LPConfig.PreviewToken); - Assert.NotEmpty(LPConfig.Host); - } - - [Fact] - public async Task TestGetLivePreviewData() - { - // Arrange - var options = new ContentstackOptions - { - ApiKey = "test_api_key", - DeliveryToken = "test_delivery_token", - Environment = "test_environment", - LivePreview = new LivePreviewConfig - { - Enable = true, - PreviewToken = "preview_token", // Replace with a valid preview token - Host = "test-host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com") - - } - }; - - var client = new TestContentstackClient(options); - - // Act - var result = await client.TestGetLivePreviewData(); - - // Assert - Assert.NotNull(result); - Assert.Equal("mock_entry_uid", result["uid"].ToString()); - Assert.Equal("Mocked Entry", result["title"].ToString()); - } - - } -} - From 4c11b72be12fcff3cccee22f3a1caf9c97f5b3d6 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 6 Mar 2025 16:10:04 +0530 Subject: [PATCH 10/13] fix error --- Contentstack.Core.Tests/LivePreviewTests.cs | 122 ++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Contentstack.Core.Tests/LivePreviewTests.cs diff --git a/Contentstack.Core.Tests/LivePreviewTests.cs b/Contentstack.Core.Tests/LivePreviewTests.cs new file mode 100644 index 0000000..723ddd3 --- /dev/null +++ b/Contentstack.Core.Tests/LivePreviewTests.cs @@ -0,0 +1,122 @@ +using System; +using Xunit; +using Contentstack.Core.Configuration; +using System.Threading.Tasks; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; + +namespace Contentstack.Core.Tests +{ + public class TestContentstackClient : ContentstackClient + { + public TestContentstackClient(ContentstackOptions options) + : base(options) + { + } + + // Override GetLivePreviewData with a hardcoded response + private new async Task GetLivePreviewData() + { + var mockResponse = new + { + entry = new + { + uid = "mock_entry_uid", + title = "Mocked Entry", + content_type_uid = "mock_content_type", + status = "preview" + } + }; + string jsonResponse = Newtonsoft.Json.JsonConvert.SerializeObject(mockResponse); + JObject data = JsonConvert.DeserializeObject(jsonResponse, this.SerializerSettings); + return await Task.FromResult((JObject)data["entry"]); + } + + // Public method to access the private method in tests + public async Task TestGetLivePreviewData() + { + return await GetLivePreviewData(); + } + } + + public class LivePreviewTests + { + ContentstackClient client = StackConfig.GetStack(); + + ContentstackClient Lpclient = StackConfig.GetLPStack(); + + private String numbersContentType = "numbers_content_type"; + String source = "source"; + + public double EPSILON { get; private set; } + + [Fact] + public async Task CheckLivePreviewConfigNotSet() + { + var LPConfig = client.GetLivePreviewConfig(); + Assert.False(LPConfig.Enable); + Assert.Null(LPConfig.PreviewToken); + Assert.Null(LPConfig.Host); + } + + [Fact] + public async Task CheckLivePreviewConfigSet() + { + var LPConfig = Lpclient.GetLivePreviewConfig(); + Assert.True(LPConfig.Enable); + Assert.NotEmpty(LPConfig.PreviewToken); + Assert.NotEmpty(LPConfig.Host); + } + + [Fact] + public async Task setQueryWithLivePreview() + { + Dictionary query = new Dictionary + { + { "content_type_uid", "ct1" }, + { "live_preview", "lphash" }, + { "release_id", "release_id" }, + { "preview_timestamp", "preview_timestamp" }, + { "entry_uid", "euid" } + }; + Lpclient.LivePreviewQueryAsync(query); + var LPConfig = Lpclient.GetLivePreviewConfig(); + Assert.Equal(LPConfig.previewTimestamp, "preview_timestamp"); + Assert.NotEmpty(LPConfig.PreviewToken); + Assert.NotEmpty(LPConfig.PreviewToken); + Assert.NotEmpty(LPConfig.Host); + } + + [Fact] + public async Task TestGetLivePreviewData() + { + // Arrange + var options = new ContentstackOptions + { + ApiKey = "test_api_key", + DeliveryToken = "test_delivery_token", + Environment = "test_environment", + LivePreview = new LivePreviewConfig + { + Enable = true, + PreviewToken = "preview_token", // Replace with a valid preview token + Host = "test-host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com") + + } + }; + + var client = new TestContentstackClient(options); + + // Act + var result = await client.TestGetLivePreviewData(); + + // Assert + Assert.NotNull(result); + Assert.Equal("mock_entry_uid", result["uid"].ToString()); + Assert.Equal("Mocked Entry", result["title"].ToString()); + } + + } +} + From 609172a076652c129d8a6f058f4152613ae168ce Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 11 Mar 2025 12:42:39 +0530 Subject: [PATCH 11/13] Fixed PR comments --- Contentstack.Core.Tests/LivePreviewTests.cs | 2 +- .../Configuration/LivePreviewConfig.cs | 4 +- Contentstack.Core/ContentstackClient.cs | 20 +-- Contentstack.Core/Models/Asset.cs | 6 +- Contentstack.Core/Models/Entry.cs | 28 ++-- Contentstack.Core/Models/Query.cs | 131 +++++++++--------- 6 files changed, 94 insertions(+), 97 deletions(-) diff --git a/Contentstack.Core.Tests/LivePreviewTests.cs b/Contentstack.Core.Tests/LivePreviewTests.cs index 723ddd3..66ce5d1 100644 --- a/Contentstack.Core.Tests/LivePreviewTests.cs +++ b/Contentstack.Core.Tests/LivePreviewTests.cs @@ -82,7 +82,7 @@ public async Task setQueryWithLivePreview() }; Lpclient.LivePreviewQueryAsync(query); var LPConfig = Lpclient.GetLivePreviewConfig(); - Assert.Equal(LPConfig.previewTimestamp, "preview_timestamp"); + Assert.Equal(LPConfig.PreviewTimestamp, "preview_timestamp"); Assert.NotEmpty(LPConfig.PreviewToken); Assert.NotEmpty(LPConfig.PreviewToken); Assert.NotEmpty(LPConfig.Host); diff --git a/Contentstack.Core/Configuration/LivePreviewConfig.cs b/Contentstack.Core/Configuration/LivePreviewConfig.cs index 7bd2b23..18670ca 100644 --- a/Contentstack.Core/Configuration/LivePreviewConfig.cs +++ b/Contentstack.Core/Configuration/LivePreviewConfig.cs @@ -12,7 +12,7 @@ public class LivePreviewConfig internal string ContentTypeUID { get; set; } internal string EntryUID { get; set; } internal JObject PreviewResponse { get; set; } - public string releaseId {get; set;} - public string previewTimestamp {get; set;} + public string ReleaseId {get; set;} + public string PreviewTimestamp {get; set;} } } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 6d9ea5f..2811773 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -363,13 +363,13 @@ private async Task GetLivePreviewData() throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } - if (!string.IsNullOrEmpty(this.LivePreviewConfig.releaseId)) + if (!string.IsNullOrEmpty(this.LivePreviewConfig.ReleaseId)) { - headerAll["release_id"] = this.LivePreviewConfig.releaseId; + headerAll["release_id"] = this.LivePreviewConfig.ReleaseId; } - if (!string.IsNullOrEmpty(this.LivePreviewConfig.previewTimestamp)) + if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewTimestamp)) { - headerAll["preview_timestamp"] = this.LivePreviewConfig.previewTimestamp; + headerAll["preview_timestamp"] = this.LivePreviewConfig.PreviewTimestamp; } try @@ -594,14 +594,14 @@ public async Task LivePreviewQueryAsync(Dictionary query) this.LivePreviewConfig.LivePreview = hash; } if (query.Keys.Contains("release_id")) { - string releaseId = null; - query.TryGetValue("release_id", out releaseId); - this.LivePreviewConfig.releaseId = releaseId; + string ReleaseId = null; + query.TryGetValue("release_id", out ReleaseId); + this.LivePreviewConfig.ReleaseId = ReleaseId; } if (query.Keys.Contains("preview_timestamp")) { - string previewTimestamp = null; - query.TryGetValue("preview_timestamp", out previewTimestamp); - this.LivePreviewConfig.previewTimestamp = previewTimestamp; + string PreviewTimestamp = null; + query.TryGetValue("preview_timestamp", out PreviewTimestamp); + this.LivePreviewConfig.PreviewTimestamp = PreviewTimestamp; } this.LivePreviewConfig.PreviewResponse = await GetLivePreviewData(); } diff --git a/Contentstack.Core/Models/Asset.cs b/Contentstack.Core/Models/Asset.cs index 05756a2..ac49192 100644 --- a/Contentstack.Core/Models/Asset.cs +++ b/Contentstack.Core/Models/Asset.cs @@ -139,8 +139,8 @@ public string Url /// Uid of user who updated the file /// [JsonProperty(PropertyName = "updated_by")] - public string UpdatedBy { get; set; } - + public string UpdatedBy { get; set; } + /// /// Uid of user who updated the file /// @@ -167,7 +167,7 @@ public string Url public Dictionary Dimension { get; set; } /// - /// Dimension Object of the asset containing Height and width + /// Dimension Object of the asset publish details /// [JsonProperty(PropertyName = "publish_details")] public Dictionary PublishDetails { get; set; } diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index b2165aa..5d0fb79 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -107,9 +107,13 @@ private string _Url /// }); /// /// - public Dictionary Metadata { get; set; } - - public Dictionary publish_details { get; set; } + public Dictionary Metadata { get; set; } + + /// + /// Dimension Object of the entries publish details + /// + [JsonProperty(PropertyName = "publish_details")] + public Dictionary PublishDetails { get; set; } /// /// Set key/value attributes of an current entry instance. @@ -1403,13 +1407,13 @@ public async Task Fetch() throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } - if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId)) { - headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; - } - if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) + headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId; + } + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp)) { - headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; + headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp; } isLivePreview = true; @@ -1493,12 +1497,12 @@ internal void ParseObject(JObject jsonObj, string url = null) this.jObject = jsonObj; this._ObjectAttributes = jsonObj.ToObject>(); if (_ObjectAttributes != null && _ObjectAttributes.ContainsKey("_metadata")) - { + { var jObject = (Newtonsoft.Json.Linq.JObject)_ObjectAttributes["_metadata"]; var _metadataJSON = new Dictionary(); - foreach (var property in jObject.Properties()) - { - _metadataJSON[property.Name] = property.Value.ToObject(); + foreach (var property in jObject.Properties()) + { + _metadataJSON[property.Name] = property.Value.ToObject(); } List iterator = _metadataJSON.Keys.ToList(); Metadata = new Dictionary(); diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index e755f02..dba3aac 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -19,10 +19,10 @@ public class Query internal Dictionary _FormHeaders = new Dictionary(); private Dictionary _Headers = new Dictionary(); - private Dictionary UrlQueries = new Dictionary(); + private Dictionary UrlQueries = new Dictionary(); protected Dictionary QueryValueJson = new Dictionary(); - private string _ResultJson = string.Empty; private CachePolicy _CachePolicy; + private string _ResultJson = string.Empty; private CachePolicy _CachePolicy; private ContentType ContentTypeInstance { get; set; } private ContentstackClient TaxonomyInstance { get; set; } protected virtual string _Url @@ -54,11 +54,11 @@ protected virtual string _Url /// }); /// /// - public string ContentTypeId { get; set; } - public ContentstackClient Stack { get; private set; } - + public string ContentTypeId { get; set; } + public ContentstackClient Stack { get; private set; } + #endregion - + #region Internal Constructors internal Query() { @@ -67,7 +67,7 @@ internal Query() internal Query(string contentTypeName) { this.ContentTypeId = contentTypeName; - } + } internal Query(ContentstackClient Tax) { SetTaxonomyInstance(Tax); @@ -136,13 +136,13 @@ internal void SetTaxonomyInstance(ContentstackClient Tax) { this.TaxonomyInstance = Tax; //SetLocale("en-us"); - } - - + } + + #endregion - + #region Public Functions - + /// /// Set Language instance /// @@ -1822,33 +1822,26 @@ public async Task> FindOne() private ContentstackCollection parseJObject(JObject jObject) { - if(this.TaxonomyInstance!=null) - { - var entries = jObject.SelectToken("$.entries").ToObject>(this.TaxonomyInstance.Serializer); - var collection = jObject.ToObject>(this.TaxonomyInstance.Serializer); - foreach (var entry in entries) - { - if (entry.GetType() == typeof(Entry)) - { - (entry as Entry).SetContentTypeInstance(this.ContentTypeInstance); - } - } - collection.Items = entries; - return collection; - - } else - { - var entries = jObject.SelectToken("$.entries").ToObject>(this.ContentTypeInstance.StackInstance.Serializer); - var collection = jObject.ToObject>(this.ContentTypeInstance.StackInstance.Serializer); - foreach (var entry in entries) - { - if (entry.GetType() == typeof(Entry)) - { - (entry as Entry).SetContentTypeInstance(this.ContentTypeInstance); - } - } - collection.Items = entries; - return collection; + if(this.TaxonomyInstance!=null) + { + var entries = jObject.SelectToken("$.entries").ToObject>(this.TaxonomyInstance.Serializer); + var collection = jObject.ToObject>(this.TaxonomyInstance.Serializer); + collection.Items = entries; + return collection; + + } else + { + var entries = jObject.SelectToken("$.entries").ToObject>(this.ContentTypeInstance.StackInstance.Serializer); + var collection = jObject.ToObject>(this.ContentTypeInstance.StackInstance.Serializer); + foreach (var entry in entries) + { + if (entry.GetType() == typeof(Entry)) + { + (entry as Entry).SetContentTypeInstance(this.ContentTypeInstance); + } + } + collection.Items = entries; + return collection; } } @@ -1874,13 +1867,13 @@ private async Task Exec() throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); } - if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId)) { - headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId; - } - if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) + headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId; + } + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp)) { - headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp; + headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewTimestamp; } isLivePreview = true; @@ -1901,12 +1894,12 @@ private async Task Exec() } } - if(this.TaxonomyInstance!=null && this.TaxonomyInstance._LocalHeaders!=null) - { + if(this.TaxonomyInstance!=null && this.TaxonomyInstance._LocalHeaders!=null) + { foreach (var header in this.TaxonomyInstance._LocalHeaders) { headerAll.Add(header.Key, (string)header.Value); - } + } } if (!isLivePreview && headerAll.ContainsKey("preview_token")) { @@ -1921,13 +1914,13 @@ private async Task Exec() headerAll.Remove("preview_timestamp"); } - if(this.ContentTypeInstance!=null) - { - mainJson.Add("environment", this.ContentTypeInstance?.StackInstance.Config.Environment); + if(this.ContentTypeInstance!=null) + { + mainJson.Add("environment", this.ContentTypeInstance?.StackInstance.Config.Environment); } - if (this.TaxonomyInstance!=null && this.TaxonomyInstance.Config.Environment != null) - { - mainJson.Add("environment", this.TaxonomyInstance?.Config.Environment); + else if (this.TaxonomyInstance!=null && this.TaxonomyInstance.Config.Environment != null) + { + mainJson.Add("environment", this.TaxonomyInstance?.Config.Environment); } if (QueryValueJson != null && QueryValueJson.Count > 0) mainJson.Add("query", QueryValueJson); @@ -1938,28 +1931,28 @@ private async Task Exec() } try - { - if(this.TaxonomyInstance!=null) - { - HttpRequestHandler requestHandler = new HttpRequestHandler(this.TaxonomyInstance); - var branch = this.TaxonomyInstance.Config.Branch != null ? this.TaxonomyInstance.Config.Branch : "main"; - var outputResult = await requestHandler.ProcessRequest(this._Url, headerAll, mainJson, Branch: branch, isLivePreview: isLivePreview, timeout: this.TaxonomyInstance.Config.Timeout); - return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); - } - else - { - HttpRequestHandler requestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance); - var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout); - return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); + { + if(this.TaxonomyInstance!=null) + { + HttpRequestHandler requestHandler = new HttpRequestHandler(this.TaxonomyInstance); + var branch = this.TaxonomyInstance.Config.Branch != null ? this.TaxonomyInstance.Config.Branch : "main"; + var outputResult = await requestHandler.ProcessRequest(this._Url, headerAll, mainJson, Branch: branch, isLivePreview: isLivePreview, timeout: this.TaxonomyInstance.Config.Timeout); + return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); + } + else + { + HttpRequestHandler requestHandler = new HttpRequestHandler(this.ContentTypeInstance.StackInstance); + var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, isLivePreview: isLivePreview, timeout: this.ContentTypeInstance.StackInstance.Config.Timeout); + return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}")); } } catch (Exception ex) { throw GetContentstackError(ex); } - } - - + } + + #region Private Functions private Dictionary GetHeader(Dictionary localHeader) { From 39790108e55841f02da2701de933433a6d161b44 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 11 Mar 2025 12:44:20 +0530 Subject: [PATCH 12/13] Added newton soft json in entry.cs --- Contentstack.Core/Models/Entry.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 5d0fb79..b1d8391 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -8,7 +8,8 @@ using System.Threading.Tasks; using Contentstack.Core.Internals; using Contentstack.Core.Configuration; - +using Newtonsoft.Json; + namespace Contentstack.Core.Models { /// From 4c3d7ae21f4d6971d31d6f37e64ae7aaba2d066a Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 17 Mar 2025 13:48:11 +0530 Subject: [PATCH 13/13] Update sca-scan.yml --- .github/workflows/sca-scan.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index 4fa4560..decebb1 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -6,10 +6,18 @@ jobs: security-sca: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - name: Checkout repository + uses: actions/checkout@master + - name: Setup .NET Core @ Latest + uses: actions/setup-dotnet@v1 + with: + dotnet-version: "7.0.x" + - name: Run Dotnet Restore + run: | + dotnet restore - name: Run Snyk to check for vulnerabilities uses: snyk/actions/dotnet@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} with: - args: --fail-on=all + args: --file=Contentstack.Core/obj/project.assets.json --fail-on=all