diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 4c087e59..2332f0d0 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ 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: | - 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 e263e517..ec2ed050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### Version: 2.16.0 +#### Date: Oct-11-2024 + +##### Feat: +- Live Preview 2.0 Implementation +##### Fix: +- Removed exclusion of env when adding headers + ### Version: 2.15.0 #### Date: Jul-30-2024 diff --git a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj index 41f678c1..dcd0c984 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.Tests/EntryTest.cs b/Contentstack.Core.Tests/EntryTest.cs index e35bcba8..ea9fbd46 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"]); } }); } diff --git a/Contentstack.Core/Configuration/LivePreviewConfig.cs b/Contentstack.Core/Configuration/LivePreviewConfig.cs index 84510fe7..240db8e1 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/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index 7583d3e3..030a3a79 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -31,7 +31,7 @@ - + diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 436c82a6..d8b949ad 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -118,12 +118,20 @@ public ContentstackClient(IOptions options) this.LivePreviewConfig = new LivePreviewConfig() { Enable = false, - }; } - if (this.LivePreviewConfig.Host == null) + if (this.LivePreviewConfig.Host == null && this.LivePreviewConfig.Enable) { - 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 +355,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 70410c62..095ee04f 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 20bed0cf..c8a87886 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -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. /// @@ -1377,15 +1393,19 @@ 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; } - 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 636ebbdd..1c59087d 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -1848,13 +1848,19 @@ 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; } - 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 c39d5907..0b3a5c94 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 2.15.0 + 2.16.0