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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 711d3a0..ec2ed05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ -### Version: 2.15.1 -#### Date: Oct-08-2024 +### Version: 2.16.0 +#### Date: Oct-11-2024 +##### Feat: +- Live Preview 2.0 Implementation ##### Fix: - Removed exclusion of env when adding headers 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/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/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/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; } 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