From d56f658d5ab2a9e7275eaab6eb000e6112d704ad Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 30 Sep 2024 16:13:00 +0530 Subject: [PATCH 01/14] fix: adds environment to entry and query irrespective of Live Preview config --- CHANGELOG.md | 6 ++++++ Contentstack.Core/Models/Entry.cs | 6 +----- Contentstack.Core/Models/Query.cs | 6 ++---- Directory.Build.props | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e263e51..711d3a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### Version: 2.15.1 +#### Date: Oct-08-2024 + +##### Fix: +- Removed exclusion of env when adding headers + ### Version: 2.15.0 #### Date: Jul-30-2024 diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 20bed0c..401a7d7 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -1380,12 +1380,8 @@ public async Task Fetch() headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; isLivePreview = true; } - else - { - mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment); - } - + mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment); foreach (var kvp in UrlQueries) { mainJson.Add(kvp.Key, kvp.Value); diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index 636ebbd..2710007 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1851,10 +1851,8 @@ private async Task Exec() headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; isLivePreview = true; } - else - { - mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment); - } + + mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment); if (QueryValueJson != null && QueryValueJson.Count > 0) mainJson.Add("query", QueryValueJson); diff --git a/Directory.Build.props b/Directory.Build.props index c39d590..e18626e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 2.15.0 + 2.15.1 From 2e615c0a26a9f1e2b4eb802cbb14879099a2eb25 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 30 Sep 2024 16:13:53 +0530 Subject: [PATCH 02/14] fix: gh workflow fixed for branches --- .github/workflows/check-branch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 4c087e5..e341da3 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' uses: thollander/actions-comment-pull-request@v2 with: message: | From 7789daa39d08e55fba0dffc685f04d0df9ce5004 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Thu, 3 Oct 2024 07:06:45 +0530 Subject: [PATCH 03/14] fix: tests for variants entries --- Contentstack.Core.Tests/EntryTest.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index e35bcba..ec578eb 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -98,6 +98,8 @@ await sourceEntry else { Assert.True(result.Uid == sourceEntry.Uid); + Assert.NotNull(result._variant); + Assert.NotNull(result._variant.uid); } }); } @@ -120,6 +122,8 @@ await sourceEntry else { Assert.True(result.Uid == sourceEntry.Uid); + Assert.NotNull(result._variant); + Assert.NotNull(result._variant.uid); } }); } From 5dc688f6219c0dadb757b9f3eec682aa402d96f6 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Thu, 3 Oct 2024 07:17:26 +0530 Subject: [PATCH 04/14] chore: add net70 for codeql workflow --- Contentstack.Core.Tests/Contentstack.Core.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index 3fc0fee..0cb855a 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0;net70; false $(Version) From f1840dbf6f4e4f8cfddf3aa251118bd7576da4ca Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 7 Oct 2024 16:43:15 +0530 Subject: [PATCH 05/14] fix: fix: github workflow failing fixed --- .../Contentstack.Core.Tests.csproj | 2 +- Contentstack.Core.Tests/EntryTest.cs | 2 +- Contentstack.Core/Models/Entry.cs | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index 0cb855a..e4f7ede 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net70; + net8.0;net70; false $(Version) diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index ec578eb..2312422 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -99,7 +99,7 @@ await sourceEntry { Assert.True(result.Uid == sourceEntry.Uid); Assert.NotNull(result._variant); - Assert.NotNull(result._variant.uid); + Assert.NotNull(result._variant["uid"]); } }); } diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 401a7d7..945a7ea 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -48,7 +48,7 @@ private string _Url internal Dictionary _metadata = new Dictionary(); #endregion - + #region Public Properties /// /// Title of an entry @@ -110,6 +110,22 @@ private string _Url /// public Dictionary Metadata { get; set; } + /// + /// Set key/value attributes of an current entry instance. + /// + /// + /// + /// ContentstackClient stack = new ContentstackClinet("api_key", "delivery_token", "environment"); + /// Entry entry = stack.ContentType("contentType_id").Entry("entry_uid"); + /// entry.Fetch<Product>().ContinueWith((entryResult) => { + /// //Your callback code. + /// //var result = entryResult.Result.Object; + /// }); + /// + /// + public Dictionary _variant { get; set; } + + /// /// Set key/value attributes of an current entry instance. /// From cce0a5ccdbc920119d08308aba59bf919cc1f981 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 7 Oct 2024 16:44:40 +0530 Subject: [PATCH 06/14] fix: github workflow failing fixed --- Contentstack.Core.Tests/EntryTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index 2312422..fb5d41c 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -123,7 +123,7 @@ await sourceEntry { Assert.True(result.Uid == sourceEntry.Uid); Assert.NotNull(result._variant); - Assert.NotNull(result._variant.uid); + Assert.NotNull(result._variant["uid"]); } }); } From 6adfccf69b789ebb85c581362c0d182fc8248fe1 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 7 Oct 2024 16:47:32 +0530 Subject: [PATCH 07/14] fix: reverted test proj to use net7.0 --- Contentstack.Core.Tests/Contentstack.Core.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index e4f7ede..3fc0fee 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net70; + net7.0 false $(Version) From 59f9adc0b2d177e63243a6480db8a6ff7044f19b Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 7 Oct 2024 18:31:29 +0530 Subject: [PATCH 08/14] fix: corrected uid to _uid in case of variants --- Contentstack.Core.Tests/EntryTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Contentstack.Core.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index fb5d41c..ea9fbd4 100644 --- a/Contentstack.Core.Tests/EntryTest.cs +++ b/Contentstack.Core.Tests/EntryTest.cs @@ -99,7 +99,7 @@ await sourceEntry { Assert.True(result.Uid == sourceEntry.Uid); Assert.NotNull(result._variant); - Assert.NotNull(result._variant["uid"]); + Assert.NotNull(result._variant["_uid"]); } }); } @@ -123,7 +123,7 @@ await sourceEntry { Assert.True(result.Uid == sourceEntry.Uid); Assert.NotNull(result._variant); - Assert.NotNull(result._variant["uid"]); + Assert.NotNull(result._variant["_uid"]); } }); } From 983f66418a810be3044b8617afc1008ed59839e7 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Wed, 9 Oct 2024 13:28:06 +0530 Subject: [PATCH 09/14] feat: :sparkles: Live Preview 2.0 Implementation --- .../Configuration/LivePreviewConfig.cs | 1 + Contentstack.Core/ContentstackClient.cs | 20 +++++++++++++++++-- Contentstack.Core/Models/Entry.cs | 18 ++++++++++++----- Contentstack.Core/Models/Query.cs | 10 +++++++++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Contentstack.Core/Configuration/LivePreviewConfig.cs b/Contentstack.Core/Configuration/LivePreviewConfig.cs index 84510fe..240db8e 100644 --- a/Contentstack.Core/Configuration/LivePreviewConfig.cs +++ b/Contentstack.Core/Configuration/LivePreviewConfig.cs @@ -7,6 +7,7 @@ namespace Contentstack.Core.Configuration public class LivePreviewConfig { public string ManagementToken { get; set; } + public string PreviewToken { get; set; } public bool Enable { get; set; } public string Host { get; set; } internal string LivePreview { get; set; } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 436c82a..f22ffb8 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -123,7 +123,16 @@ public ContentstackClient(IOptions options) } if (this.LivePreviewConfig.Host == null) { - this.LivePreviewConfig.Host = "api.contentstack.io"; + if (this.LivePreviewConfig.ManagementToken != null) + { + this.LivePreviewConfig.Host = "api.contentstack.io"; + } + else if (this.LivePreviewConfig.PreviewToken != null) + { + this.LivePreviewConfig.Host = "rest-preview.contentstack.com"; + } else { + throw new InvalidOperationException("Add PreviewToken or ManagementToken in LivePreviewConfig"); + } } this.SerializerSettings.DateParseHandling = DateParseHandling.None; this.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat; @@ -347,7 +356,14 @@ private async Task GetLivePreviewData() } } mainJson.Add("live_preview", this.LivePreviewConfig.LivePreview ?? "init"); - headerAll["authorization"] = this.LivePreviewConfig.ManagementToken; + + if (!string.IsNullOrEmpty(this.LivePreviewConfig.ManagementToken)) { + headerAll["authorization"] = this.LivePreviewConfig.ManagementToken; + } else if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewToken)) { + headerAll["preview_token"] = this.LivePreviewConfig.PreviewToken; + } else { + throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); + } try { diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 945a7ea..c8a8788 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -48,7 +48,7 @@ private string _Url internal Dictionary _metadata = new Dictionary(); #endregion - + #region Public Properties /// /// Title of an entry @@ -123,9 +123,9 @@ private string _Url /// }); /// /// - public Dictionary _variant { get; set; } - - + public Dictionary _variant { get; set; } + + /// /// Set key/value attributes of an current entry instance. /// @@ -1393,7 +1393,15 @@ public async Task Fetch() if (this.ContentTypeInstance.StackInstance.LivePreviewConfig.Enable == true && this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId) { mainJson.Add("live_preview", this.ContentTypeInstance.StackInstance.LivePreviewConfig.LivePreview ?? "init"); - headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; + + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken)) { + 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 { + throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); + } + isLivePreview = true; } diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index 2710007..1c59087 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1848,7 +1848,15 @@ private async Task Exec() && this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId) { mainJson.Add("live_preview", this.ContentTypeInstance.StackInstance.LivePreviewConfig.LivePreview ?? "init"); - headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken; + + if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken)) { + 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 { + throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); + } + isLivePreview = true; } From 269660803e897ecb14839e43a801702719d51172 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 11 Oct 2024 10:17:14 +0530 Subject: [PATCH 10/14] chore: version bump --- CHANGELOG.md | 6 ++++++ Contentstack.AspNetCore/Contentstack.AspNetCore.csproj | 2 +- Contentstack.Core/Internals/HttpRequestHandler.cs | 2 +- Directory.Build.props | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 711d3a0..e8f9e81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### Version: 2.16.0 +#### Date: Oct-11-2024 + +##### Feat: +- Live Preview 2.0 Implementation + ### Version: 2.15.1 #### Date: Oct-08-2024 diff --git a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj index 41f678c..dcd0c98 100644 --- a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj +++ b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj @@ -31,6 +31,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Contentstack.Core/Internals/HttpRequestHandler.cs b/Contentstack.Core/Internals/HttpRequestHandler.cs index 70410c6..095ee04 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.12.0"; + request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.16.0"; request.Timeout = timeout; if (proxy != null) diff --git a/Directory.Build.props b/Directory.Build.props index e18626e..0b3a5c9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 2.15.1 + 2.16.0 From fcf323ebb03660158017c5f223f9fadc2dfb19d5 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 11 Oct 2024 12:14:32 +0530 Subject: [PATCH 11/14] fix: Changelog update --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8f9e81..ec2ed05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,6 @@ ##### Feat: - Live Preview 2.0 Implementation - -### Version: 2.15.1 -#### Date: Oct-08-2024 - ##### Fix: - Removed exclusion of env when adding headers From c944b8a5bf810777dd9343b00d02c6fb80fed391 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 11 Oct 2024 12:16:40 +0530 Subject: [PATCH 12/14] fix: workflow fix for check branch --- .github/workflows/check-branch.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index e341da3..2332f0d 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -12,9 +12,9 @@ jobs: uses: thollander/actions-comment-pull-request@v2 with: message: | - We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. + We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the staging branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' run: | - echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." + echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the staging branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." exit 1 From 71ec291ff13536029c74971207d1e1bfbbd4d097 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 11 Oct 2024 12:30:41 +0530 Subject: [PATCH 13/14] chore: update utils package version --- Contentstack.Core/Contentstack.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index 7583d3e..030a3a7 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -31,7 +31,7 @@ - + From 768baf13c4a2fc16ffcd2259ee716d4fe6076392 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 11 Oct 2024 15:23:06 +0530 Subject: [PATCH 14/14] fix: check for LivePreviewConfig Host only when its enabled --- Contentstack.Core/ContentstackClient.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index f22ffb8..d8b949a 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -118,10 +118,9 @@ public ContentstackClient(IOptions options) this.LivePreviewConfig = new LivePreviewConfig() { Enable = false, - }; } - if (this.LivePreviewConfig.Host == null) + if (this.LivePreviewConfig.Host == null && this.LivePreviewConfig.Enable) { if (this.LivePreviewConfig.ManagementToken != null) {