Skip to content

Commit 0391d10

Browse files
authored
Merge pull request #60 from contentstack/staging
DX | 11-10-2024 | Hotfix
2 parents 1178398 + 3032f08 commit 0391d10

File tree

11 files changed

+77
-23
lines changed

11 files changed

+77
-23
lines changed

.github/workflows/check-branch.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Comment PR
11-
if: github.base_ref == 'master' && github.head_ref != 'next'
11+
if: github.base_ref == 'master' && github.head_ref != 'staging'
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Version: 2.16.0
2+
#### Date: Oct-11-2024
3+
4+
##### Feat:
5+
- Live Preview 2.0 Implementation
6+
##### Fix:
7+
- Removed exclusion of env when adding headers
8+
19
### Version: 2.15.0
210
#### Date: Jul-30-2024
311

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.Tests/EntryTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ await sourceEntry
9898
else
9999
{
100100
Assert.True(result.Uid == sourceEntry.Uid);
101+
Assert.NotNull(result._variant);
102+
Assert.NotNull(result._variant["_uid"]);
101103
}
102104
});
103105
}
@@ -120,6 +122,8 @@ await sourceEntry
120122
else
121123
{
122124
Assert.True(result.Uid == sourceEntry.Uid);
125+
Assert.NotNull(result._variant);
126+
Assert.NotNull(result._variant["_uid"]);
123127
}
124128
});
125129
}

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/Contentstack.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3232
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
3333
<PackageReference Include="Markdig" Version="0.36.2" />
34-
<PackageReference Include="contentstack.utils" Version="1.0.2" />
34+
<PackageReference Include="contentstack.utils" Version="1.0.5" />
3535
</ItemGroup>
3636
<ItemGroup>
3737
<None Remove="Interfaces\" />

Contentstack.Core/ContentstackClient.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,20 @@ public ContentstackClient(IOptions<ContentstackOptions> options)
118118
this.LivePreviewConfig = new LivePreviewConfig()
119119
{
120120
Enable = false,
121-
122121
};
123122
}
124-
if (this.LivePreviewConfig.Host == null)
123+
if (this.LivePreviewConfig.Host == null && this.LivePreviewConfig.Enable)
125124
{
126-
this.LivePreviewConfig.Host = "api.contentstack.io";
125+
if (this.LivePreviewConfig.ManagementToken != null)
126+
{
127+
this.LivePreviewConfig.Host = "api.contentstack.io";
128+
}
129+
else if (this.LivePreviewConfig.PreviewToken != null)
130+
{
131+
this.LivePreviewConfig.Host = "rest-preview.contentstack.com";
132+
} else {
133+
throw new InvalidOperationException("Add PreviewToken or ManagementToken in LivePreviewConfig");
134+
}
127135
}
128136
this.SerializerSettings.DateParseHandling = DateParseHandling.None;
129137
this.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
@@ -347,7 +355,14 @@ private async Task<JObject> GetLivePreviewData()
347355
}
348356
}
349357
mainJson.Add("live_preview", this.LivePreviewConfig.LivePreview ?? "init");
350-
headerAll["authorization"] = this.LivePreviewConfig.ManagementToken;
358+
359+
if (!string.IsNullOrEmpty(this.LivePreviewConfig.ManagementToken)) {
360+
headerAll["authorization"] = this.LivePreviewConfig.ManagementToken;
361+
} else if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewToken)) {
362+
headerAll["preview_token"] = this.LivePreviewConfig.PreviewToken;
363+
} else {
364+
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
365+
}
351366

352367
try
353368
{

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: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ private string _Url
110110
/// </example>
111111
public Dictionary<string, object> Metadata { get; set; }
112112

113+
/// <summary>
114+
/// Set key/value attributes of an current entry instance.
115+
/// </summary>
116+
/// <example>
117+
/// <code>
118+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
119+
/// Entry entry = stack.ContentType(&quot;contentType_id&quot;).Entry(&quot;entry_uid&quot;);
120+
/// entry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
121+
/// //Your callback code.
122+
/// //var result = entryResult.Result.Object;
123+
/// });
124+
/// </code>
125+
/// </example>
126+
public Dictionary<string, object> _variant { get; set; }
127+
128+
113129
/// <summary>
114130
/// Set key/value attributes of an current entry instance.
115131
/// </summary>
@@ -1377,15 +1393,19 @@ public async Task<T> Fetch<T>()
13771393
if (this.ContentTypeInstance.StackInstance.LivePreviewConfig.Enable == true && this.ContentTypeInstance.StackInstance.LivePreviewConfig.ContentTypeUID == this.ContentTypeInstance.ContentTypeId)
13781394
{
13791395
mainJson.Add("live_preview", this.ContentTypeInstance.StackInstance.LivePreviewConfig.LivePreview ?? "init");
1380-
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+
13811405
isLivePreview = true;
13821406
}
1383-
else
1384-
{
1385-
mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment);
1386-
}
13871407

1388-
1408+
mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment);
13891409
foreach (var kvp in UrlQueries)
13901410
{
13911411
mainJson.Add(kvp.Key, kvp.Value);

Contentstack.Core/Models/Query.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,13 +1848,19 @@ 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
}
1854-
else
1855-
{
1856-
mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment);
1857-
}
1862+
1863+
mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment);
18581864
if (QueryValueJson != null && QueryValueJson.Count > 0)
18591865
mainJson.Add("query", QueryValueJson);
18601866

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.0</Version>
3+
<Version>2.16.0</Version>
44
</PropertyGroup>
55
</Project>

0 commit comments

Comments
 (0)