Skip to content

Commit

Permalink
Merge pull request #60 from contentstack/staging
Browse files Browse the repository at this point in the history
DX | 11-10-2024 | Hotfix
  • Loading branch information
cs-raj authored Oct 11, 2024
2 parents 66a4df3 + 2100b15 commit 342d038
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 23 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/check-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion Contentstack.AspNetCore/Contentstack.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2"><PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="contentstack.csharp" Version="2.13.0" />
<PackageReference Include="contentstack.csharp" Version="2.15.0" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions Contentstack.Core.Tests/EntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ await sourceEntry
else
{
Assert.True(result.Uid == sourceEntry.Uid);
Assert.NotNull(result._variant);
Assert.NotNull(result._variant["_uid"]);
}
});
}
Expand All @@ -120,6 +122,8 @@ await sourceEntry
else
{
Assert.True(result.Uid == sourceEntry.Uid);
Assert.NotNull(result._variant);
Assert.NotNull(result._variant["_uid"]);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions Contentstack.Core/Configuration/LivePreviewConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Markdig" Version="0.36.2" />
<PackageReference Include="contentstack.utils" Version="1.0.2" />
<PackageReference Include="contentstack.utils" Version="1.0.5" />
</ItemGroup>
<ItemGroup>
<None Remove="Interfaces\" />
Expand Down
23 changes: 19 additions & 4 deletions Contentstack.Core/ContentstackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,20 @@ public ContentstackClient(IOptions<ContentstackOptions> 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;
Expand Down Expand Up @@ -347,7 +355,14 @@ private async Task<JObject> 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
{
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core/Internals/HttpRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<string> ProcessRequest(string Url, Dictionary<string, object>
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)
Expand Down
32 changes: 26 additions & 6 deletions Contentstack.Core/Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ private string _Url
/// </example>
public Dictionary<string, object> Metadata { get; set; }

/// <summary>
/// Set key/value attributes of an current entry instance.
/// </summary>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Entry entry = stack.ContentType(&quot;contentType_id&quot;).Entry(&quot;entry_uid&quot;);
/// entry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
/// //Your callback code.
/// //var result = entryResult.Result.Object;
/// });
/// </code>
/// </example>
public Dictionary<string, object> _variant { get; set; }


/// <summary>
/// Set key/value attributes of an current entry instance.
/// </summary>
Expand Down Expand Up @@ -1377,15 +1393,19 @@ public async Task<T> Fetch<T>()
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);
Expand Down
16 changes: 11 additions & 5 deletions Contentstack.Core/Models/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,13 +1848,19 @@ private async Task<JObject> 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);

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>2.15.0</Version>
<Version>2.16.0</Version>
</PropertyGroup>
</Project>

0 comments on commit 342d038

Please sign in to comment.