From 636ae9c7305f589b65566c546ea8818edd44becc Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 24 Feb 2025 14:53:08 +0530 Subject: [PATCH] Feat: Added Support for timeline preview --- CHANGELOG.md | 6 +++ .../Configuration/LivePreviewConfig.cs | 2 + Contentstack.Core/ContentstackClient.cs | 37 ++++++++++++++----- .../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, 54 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae8dc8ea..8e5cf092 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 0fbecdf9..8e78cc19 100644 --- a/Contentstack.Core/Configuration/LivePreviewConfig.cs +++ b/Contentstack.Core/Configuration/LivePreviewConfig.cs @@ -12,5 +12,7 @@ public class LivePreviewConfig internal string ContentTypeUID { get; set; } internal string EntryUID { get; set; } internal JsonElement 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 e76fe32c..c408140a 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -66,19 +66,22 @@ private string _Url private Dictionary _StackHeaders = new Dictionary(); public List Plugins { get; set; } = new List(); /// - /// Initializes a instance of the class. + /// Initializes a new instance of the class. /// - /// used to get stack details via class to create client. + /// + /// The configuration options used to retrieve stack details, provided through the class. + /// /// + /// This example demonstrates how to create a instance and retrieve a content type: /// - /// var options = new ContentstackOptions() - /// { - /// ApiKey = "api_key", - /// DeliveryToken = "delivery_token" - /// Environment = "environment" - /// } - /// ContentstackClient stack = new ContentstackClient(options); - /// ContentType contentType = stack.ContentType("contentType_name"); + /// var options = new ContentstackOptions + /// { + /// ApiKey = "api_key", + /// DeliveryToken = "delivery_token", + /// Environment = "environment" + /// }; + /// ContentstackClient stack = new ContentstackClient(options); + /// ContentType contentType = stack.ContentType("contentType_name"); /// /// public ContentstackClient(IOptions options) @@ -359,6 +362,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 +583,16 @@ public async Task LivePreviewQueryAsync(Dictionary query) 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 e8710f00..cbed5db3 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 c8a87886..e8e1db80 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 a6b453ed..d034b8ea 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 2beb17eb..402aa0e3 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 ec1403b1..e1238b51 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