Skip to content

Commit a305538

Browse files
authored
Merge pull request #68 from contentstack/enhc/DX-9232
fix: replace refresh-region.cs with refresh-region.py
2 parents c238c67 + e8f274a commit a305538

6 files changed

Lines changed: 82 additions & 99 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
### Version: 2.0.0
2-
#### Date: June-15-2026
3-
- **Breaking:** Replaced **Newtonsoft.Json** with **System.Text.Json** across the package. The `Newtonsoft.Json` package reference is removed; add `System.Text.Json` (or rely on the BCL on supported runtimes) as needed in consuming projects.
4-
- **Breaking:** Variant metadata APIs that previously took `JObject` / `JArray` now use `System.Text.Json.Nodes.JsonObject` and `JsonArray` (`GetVariantAliases`, `GetVariantMetadataTags`, and obsolete `GetDataCsvariantsAttribute` overloads).
5-
- JSON serialization uses the same model attributes with `System.Text.Json.Serialization` (`JsonPropertyName`, `JsonConverter`), including custom converters for RTE/GQL-shaped JSON and **path-mapped** embedded models (`PathMappedJsonConverter<T>`).
6-
- RTE JSON deserialization tolerates **trailing commas** when using the documented test/helper patterns (`AllowTrailingCommas`); attribute dictionaries may surface **`JsonElement`** values instead of boxed strings—use helpers or unwrap explicitly if you access `Node.attrs` directly.
7-
- Internal: `LangVersion` set to **latest** for multi-target builds; utilities normalize attribute values where the HTML pipeline expects strings.
1+
### Version: 2.0.0-beta.2
2+
#### Date: June-22-2026
83
- **New:** Multi-region endpoint resolution via `Endpoint.GetContentstackEndpoint(region, service)` — resolves Contentstack service URLs for all 7 supported regions (NA, EU, AU, Azure-NA, Azure-EU, GCP-NA, GCP-EU) and 18 service keys (contentDelivery, contentManagement, auth, graphqlDelivery, preview, images, assets, automate, launch, developerHub, brandKit, genAI, personalizeManagement, personalizeEdge, composableStudio, assetManagement, and more).
94
- **New:** `Utils.GetContentstackEndpoint(region, service)` proxy — access endpoint resolution directly from the `Utils` class without importing `Contentstack.Utils.Endpoints`.
105
- **New:** `omitHttps` flag strips the `https://` scheme from returned URLs — pass directly to SDK host configuration (e.g. `new ContentstackOptions { Host = Endpoint.GetContentstackEndpoint("eu", "contentDelivery", omitHttps: true) }`).
116
- **New:** Case-insensitive region alias support — `"us"`, `"NA"`, `"AWS-NA"`, `"azure_na"` all resolve correctly to the same region.
127
- **New:** `regions.json` registry auto-downloaded from `artifacts.contentstack.com` on first use and cached on disk — no setup required. The SDK self-heals if the file is missing.
13-
- **New:** `Scripts/refresh-region.cs` bundled inside the NuGet package — automatically placed in your project's `Scripts/` folder on first `dotnet build`. Run `dotnet run Scripts/refresh-region.cs` anytime to pull the latest regions from CDN.
8+
- **New:** `Scripts/refresh-region.py` bundled inside the NuGet package — automatically placed in your project's `Scripts/` folder on first `dotnet build`. Run `python3 Scripts/refresh-region.py` (Mac/Linux) or `python Scripts/refresh-region.py` (Windows) anytime to pull the latest regions from CDN.
149

1510
### Version: 2.0.0-beta.1
1611
#### Date: April-27-2026

Contentstack.Utils/Contentstack.Utils.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@
4545
<PackageReference Include="System.Text.Json" Version="8.0.5" />
4646
</ItemGroup>
4747

48-
<!-- Ship refresh-region.cs inside the NuGet package.
49-
The .targets file copies it into the consumer's Scripts/ folder on first build.
50-
Customer runs: dotnet run Scripts/refresh-region.cs -->
5148
<ItemGroup>
52-
<Content Include="..\Scripts\refresh-region.cs">
49+
<Content Include="..\Scripts\refresh-region.py">
5350
<Pack>true</Pack>
54-
<PackagePath>contentFiles/cs/any/Scripts/refresh-region.cs</PackagePath>
51+
<PackagePath>contentFiles/cs/any/Scripts/refresh-region.py</PackagePath>
5552
<BuildAction>Content</BuildAction>
5653
<CopyToOutput>false</CopyToOutput>
5754
</Content>

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.0.0</Version>
3+
<Version>2.0.0-beta.2</Version>
44
</PropertyGroup>
55
</Project>

Scripts/refresh-region.cs

Lines changed: 0 additions & 77 deletions
This file was deleted.

Scripts/refresh-region.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
# Refresh regions.json from the Contentstack CDN.
3+
# Usage (run from your project root):
4+
# python3 Scripts/refresh-region.py
5+
# python Scripts/refresh-region.py
6+
7+
import glob
8+
import json
9+
import os
10+
import ssl
11+
import sys
12+
import urllib.request
13+
14+
REGIONS_URL = "https://artifacts.contentstack.com/regions.json"
15+
16+
print(f"Fetching {REGIONS_URL} ...")
17+
18+
19+
def _fetch(url):
20+
# First attempt: normal SSL verification
21+
try:
22+
with urllib.request.urlopen(url, timeout=30) as r:
23+
return r.read().decode("utf-8")
24+
except urllib.error.URLError as e:
25+
if "CERTIFICATE_VERIFY_FAILED" not in str(e):
26+
raise
27+
# macOS python.org builds often lack system certs — retry without verification
28+
print("WARNING: SSL certificate verification failed. Retrying without verification.", file=sys.stderr)
29+
print(" To fix permanently, run: /Applications/Python*/Install\\ Certificates.command", file=sys.stderr)
30+
ctx = ssl.create_default_context()
31+
ctx.check_hostname = False
32+
ctx.verify_mode = ssl.CERT_NONE
33+
with urllib.request.urlopen(url, timeout=30, context=ctx) as r:
34+
return r.read().decode("utf-8")
35+
36+
37+
try:
38+
raw = _fetch(REGIONS_URL)
39+
except Exception as e:
40+
print(f"ERROR: Could not download regions.json: {e}", file=sys.stderr)
41+
sys.exit(1)
42+
43+
try:
44+
data = json.loads(raw)
45+
except json.JSONDecodeError as e:
46+
print(f"ERROR: Downloaded content is not valid JSON: {e}", file=sys.stderr)
47+
sys.exit(1)
48+
49+
if "regions" not in data:
50+
print("ERROR: Downloaded JSON does not contain a 'regions' key.", file=sys.stderr)
51+
sys.exit(1)
52+
53+
region_count = len(data["regions"])
54+
55+
# Scan bin/ for every copy of the DLL (covers Debug/Release, any TFM, any nesting).
56+
dll_pattern = os.path.join(os.getcwd(), "**", "Contentstack.Utils.dll")
57+
found = [
58+
os.path.dirname(dll)
59+
for dll in glob.glob(dll_pattern, recursive=True)
60+
if os.sep + "bin" + os.sep in dll
61+
]
62+
63+
if not found:
64+
print("[bin] No build output found — run 'dotnet build' first, then re-run this script.")
65+
sys.exit(1)
66+
67+
for bin_dir in found:
68+
assets_dir = os.path.join(bin_dir, "Assets")
69+
os.makedirs(assets_dir, exist_ok=True)
70+
dest = os.path.join(assets_dir, "regions.json")
71+
with open(dest, "w", encoding="utf-8") as f:
72+
f.write(raw)
73+
print(f"[bin] Wrote {region_count} regions → {dest}")

build/contentstack.utils.targets

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
<Project>
2-
<!--
3-
Copies refresh-region.cs into the consuming project's Scripts/ folder
4-
on first build. Customer then runs:
5-
dotnet run Scripts/refresh-region.cs
6-
-->
72
<PropertyGroup>
8-
<_RefreshScriptDest>$(MSBuildProjectDirectory)/Scripts/refresh-region.cs</_RefreshScriptDest>
9-
<_RefreshScriptSrc>$(MSBuildThisFileDirectory)../contentFiles/cs/any/Scripts/refresh-region.cs</_RefreshScriptSrc>
3+
<_RefreshScriptDest>$(MSBuildProjectDirectory)/Scripts/refresh-region.py</_RefreshScriptDest>
4+
<_RefreshScriptSrc>$(MSBuildThisFileDirectory)../contentFiles/cs/any/Scripts/refresh-region.py</_RefreshScriptSrc>
105
</PropertyGroup>
116

127
<Target Name="ContentstackUtils_PlaceRefreshScript"
138
AfterTargets="ResolvePackageDependenciesForBuild"
149
Condition="!Exists('$(_RefreshScriptDest)')">
1510
<MakeDir Directories="$(MSBuildProjectDirectory)/Scripts" />
1611
<Copy SourceFiles="$(_RefreshScriptSrc)" DestinationFiles="$(_RefreshScriptDest)" />
17-
<Message Text="contentstack.utils: Scripts/refresh-region.cs added to your project. Run 'dotnet run Scripts/refresh-region.cs' to refresh regions." Importance="High" />
12+
<Message Text="contentstack.utils: Scripts/refresh-region.py added to your project. Run 'python3 Scripts/refresh-region.py' to refresh regions." Importance="High" />
1813
</Target>
1914
</Project>

0 commit comments

Comments
 (0)