@treeseed/sdk 0.12.38 → 0.12.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1249,8 +1249,8 @@ function shouldManageCloudflareWebCacheRules(deployConfig, target) {
1249
1249
  if ((deployConfig.surfaces?.web?.provider ?? deployConfig.providers?.deploy) !== "cloudflare") {
1250
1250
  return false;
1251
1251
  }
1252
- const webTarget2 = resolvePublicWebCacheTarget(deployConfig);
1253
- return Boolean(webTarget2?.host && !webTarget2.host.endsWith(".workers.dev") && !webTarget2.host.endsWith(".pages.dev"));
1252
+ const webTarget = resolvePublicWebCacheTarget(deployConfig);
1253
+ return Boolean(webTarget?.host && !webTarget.host.endsWith(".workers.dev") && !webTarget.host.endsWith(".pages.dev"));
1254
1254
  }
1255
1255
  function cloudflareApiRequest(path, { method = "GET", body, env, allowFailure = false } = {}) {
1256
1256
  const token = env?.TREESEED_CLOUDFLARE_API_TOKEN ?? env?.CLOUDFLARE_API_TOKEN ?? process.env.TREESEED_CLOUDFLARE_API_TOKEN ?? "";
@@ -1568,10 +1568,10 @@ function reconcileCloudflareCacheRulesForTarget(role, deployConfig, state, cache
1568
1568
  }
1569
1569
  function reconcileCloudflareWebCacheRules(tenantRoot, deployConfig, state, target, { planOnly = false, env: providedEnv } = {}) {
1570
1570
  if (!shouldManageCloudflareWebCacheRules(deployConfig, target)) {
1571
- const webTarget3 = resolvePublicWebCacheTarget(deployConfig);
1572
- const contentTarget3 = resolvePublicContentCacheTarget(deployConfig);
1573
- state.webCache.webHost = webTarget3?.host ?? null;
1574
- state.webCache.contentHost = contentTarget3?.host ?? null;
1571
+ const webTarget2 = resolvePublicWebCacheTarget(deployConfig);
1572
+ const contentTarget2 = resolvePublicContentCacheTarget(deployConfig);
1573
+ state.webCache.webHost = webTarget2?.host ?? null;
1574
+ state.webCache.contentHost = contentTarget2?.host ?? null;
1575
1575
  state.webCache.rulesManaged = false;
1576
1576
  state.webCache.lastError = null;
1577
1577
  return { managed: false, skipped: true, reason: "unsupported_target_or_host" };
@@ -1586,15 +1586,15 @@ function reconcileCloudflareWebCacheRules(tenantRoot, deployConfig, state, targe
1586
1586
  state.webCache.lastError = "CLOUDFLARE_API_TOKEN is required to manage Cloudflare Cache Rules.";
1587
1587
  return { managed: false, skipped: true, reason: "missing_api_token" };
1588
1588
  }
1589
- const webTarget2 = resolvePublicWebCacheTarget(deployConfig);
1590
- const contentTarget2 = resolvePublicContentCacheTarget(deployConfig);
1589
+ const webTarget = resolvePublicWebCacheTarget(deployConfig);
1590
+ const contentTarget = resolvePublicContentCacheTarget(deployConfig);
1591
1591
  try {
1592
1592
  const results = [];
1593
- if (webTarget2?.host) {
1594
- results.push(reconcileCloudflareCacheRulesForTarget("web", deployConfig, state, webTarget2, env, { planOnly }));
1593
+ if (webTarget?.host) {
1594
+ results.push(reconcileCloudflareCacheRulesForTarget("web", deployConfig, state, webTarget, env, { planOnly }));
1595
1595
  }
1596
- if (contentTarget2?.host) {
1597
- results.push(reconcileCloudflareCacheRulesForTarget("content", deployConfig, state, contentTarget2, env, { planOnly }));
1596
+ if (contentTarget?.host) {
1597
+ results.push(reconcileCloudflareCacheRulesForTarget("content", deployConfig, state, contentTarget, env, { planOnly }));
1598
1598
  }
1599
1599
  state.webCache.rulesManaged = true;
1600
1600
  state.webCache.lastSyncedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -1700,7 +1700,7 @@ function recordCachePurgeResult(targetState, results, error = null) {
1700
1700
  return;
1701
1701
  }
1702
1702
  targetState.lastPurgedAt = (/* @__PURE__ */ new Date()).toISOString();
1703
- targetState.purgeCount = Array.isArray(results) ? results.reduce((sum, result) => sum + (result?.count ?? 0), 0) : 0;
1703
+ targetState.purgeCount = Array.isArray(results) ? results.reduce((sum, result) => sum + (typeof result?.count === "number" ? result.count : 0), 0) : 0;
1704
1704
  targetState.lastError = null;
1705
1705
  }
1706
1706
  function resolveCloudflareCachePurgeEnv(options = {}) {
@@ -1728,7 +1728,8 @@ function purgeSourcePageCaches(tenantRoot, options = {}) {
1728
1728
  const results = purgeCloudflareCacheByUrls(urls, deployConfig, {
1729
1729
  env
1730
1730
  });
1731
- const allResults = target.scope === "prod" ? purgeCloudflareCacheEverythingByHosts([webTarget.host, contentTarget?.host], deployConfig, { env }) : [];
1731
+ const hosts = [...new Set(urls.map((url) => safeUrl(url)?.hostname).filter(Boolean))];
1732
+ const allResults = target.scope === "prod" ? purgeCloudflareCacheEverythingByHosts(hosts, deployConfig, { env }) : [];
1732
1733
  assertCloudflareCachePurgeSucceeded([...results, ...allResults]);
1733
1734
  recordCachePurgeResult(state.webCache.deployPurge, [...results, ...allResults]);
1734
1735
  writeDeployState(tenantRoot, state, { target });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.12.38",
3
+ "version": "0.12.39",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {