Skip to content

Commit 9f4e267

Browse files
authored
Merge pull request #61 from contentstack/feat/DX-1240-Live-Preview-2.0
feat: ✨ Live Preview 2.0 Implementation
2 parents b60eccb + c944b8a commit 9f4e267

File tree

9 files changed

+51
-16
lines changed

9 files changed

+51
-16
lines changed

.github/workflows/check-branch.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
uses: thollander/actions-comment-pull-request@v2
1313
with:
1414
message: |
15-
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.
15+
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.
1616
- name: Check branch
17-
if: github.base_ref == 'master' && github.head_ref != 'next'
17+
if: github.base_ref == 'master' && github.head_ref != 'staging'
1818
run: |
19-
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."
19+
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."
2020
exit 1

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
### Version: 2.15.1
2-
#### Date: Oct-08-2024
1+
### Version: 2.16.0
2+
#### Date: Oct-11-2024
33

4+
##### Feat:
5+
- Live Preview 2.0 Implementation
46
##### Fix:
57
- Removed exclusion of env when adding headers
68

Contentstack.AspNetCore/Contentstack.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2"><PrivateAssets>all</PrivateAssets>
3232
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3333
</PackageReference>
34-
<PackageReference Include="contentstack.csharp" Version="2.13.0" />
34+
<PackageReference Include="contentstack.csharp" Version="2.15.0" />
3535
</ItemGroup>
3636
</Project>

Contentstack.Core/Configuration/LivePreviewConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Contentstack.Core.Configuration
77
public class LivePreviewConfig
88
{
99
public string ManagementToken { get; set; }
10+
public string PreviewToken { get; set; }
1011
public bool Enable { get; set; }
1112
public string Host { get; set; }
1213
internal string LivePreview { get; set; }

Contentstack.Core/ContentstackClient.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,16 @@ public ContentstackClient(IOptions<ContentstackOptions> options)
123123
}
124124
if (this.LivePreviewConfig.Host == null)
125125
{
126-
this.LivePreviewConfig.Host = "api.contentstack.io";
126+
if (this.LivePreviewConfig.ManagementToken != null)
127+
{
128+
this.LivePreviewConfig.Host = "api.contentstack.io";
129+
}
130+
else if (this.LivePreviewConfig.PreviewToken != null)
131+
{
132+
this.LivePreviewConfig.Host = "rest-preview.contentstack.com";
133+
} else {
134+
throw new InvalidOperationException("Add PreviewToken or ManagementToken in LivePreviewConfig");
135+
}
127136
}
128137
this.SerializerSettings.DateParseHandling = DateParseHandling.None;
129138
this.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
@@ -347,7 +356,14 @@ private async Task<JObject> GetLivePreviewData()
347356
}
348357
}
349358
mainJson.Add("live_preview", this.LivePreviewConfig.LivePreview ?? "init");
350-
headerAll["authorization"] = this.LivePreviewConfig.ManagementToken;
359+
360+
if (!string.IsNullOrEmpty(this.LivePreviewConfig.ManagementToken)) {
361+
headerAll["authorization"] = this.LivePreviewConfig.ManagementToken;
362+
} else if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewToken)) {
363+
headerAll["preview_token"] = this.LivePreviewConfig.PreviewToken;
364+
} else {
365+
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
366+
}
351367

352368
try
353369
{

Contentstack.Core/Internals/HttpRequestHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task<string> ProcessRequest(string Url, Dictionary<string, object>
4848
var request = (HttpWebRequest)WebRequest.Create(uri);
4949
request.Method = "GET";
5050
request.ContentType = "application/json";
51-
request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.12.0";
51+
request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.16.0";
5252
request.Timeout = timeout;
5353

5454
if (proxy != null)

Contentstack.Core/Models/Entry.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private string _Url
4848

4949
internal Dictionary<string, object> _metadata = new Dictionary<string, object>();
5050
#endregion
51-
51+
5252
#region Public Properties
5353
/// <summary>
5454
/// Title of an entry
@@ -123,9 +123,9 @@ private string _Url
123123
/// });
124124
/// </code>
125125
/// </example>
126-
public Dictionary<string, object> _variant { get; set; }
127-
128-
126+
public Dictionary<string, object> _variant { get; set; }
127+
128+
129129
/// <summary>
130130
/// Set key/value attributes of an current entry instance.
131131
/// </summary>
@@ -1393,7 +1393,15 @@ public async Task<T> Fetch<T>()
13931393
if (this.ContentTypeInstance.StackInstance.LivePreviewConfig.Enable == true && this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId)
13941394
{
13951395
mainJson.Add("live_preview", this.ContentTypeInstance.StackInstance.LivePreviewConfig.LivePreview ?? "init");
1396-
headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken;
1396+
1397+
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken)) {
1398+
headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken;
1399+
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) {
1400+
headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken;
1401+
} else {
1402+
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
1403+
}
1404+
13971405
isLivePreview = true;
13981406
}
13991407

Contentstack.Core/Models/Query.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,15 @@ private async Task<JObject> Exec()
18481848
&& this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId)
18491849
{
18501850
mainJson.Add("live_preview", this.ContentTypeInstance.StackInstance.LivePreviewConfig.LivePreview ?? "init");
1851-
headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken;
1851+
1852+
if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken)) {
1853+
headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken;
1854+
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) {
1855+
headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken;
1856+
} else {
1857+
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
1858+
}
1859+
18521860
isLivePreview = true;
18531861
}
18541862

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>2.15.1</Version>
3+
<Version>2.16.0</Version>
44
</PropertyGroup>
55
</Project>

0 commit comments

Comments
 (0)