redclove 0.1.1 → 0.1.2

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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { addBlock, addBlocks, diffBlock, missingPackages, BlockNotFoundError, type AddOptions, type AddResult, type ConflictPolicy, type DiffResult } from "./add.js";
2
- export { fetchBlock, fetchIndex, registryUrl, DEFAULT_REGISTRY, type IndexEntry, type RegistryBlock, type EnvVar } from "./registry.js";
2
+ export { fetchBlock, fetchIndex, registryUrl, DEFAULT_REGISTRY, MIRRORS, type IndexEntry, type RegistryBlock, type EnvVar } from "./registry.js";
3
3
  export { readConfig, writeConfig, defaultConfig, detectPackageManager, addCommand, CONFIG_FILE, type Config } from "./project.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { addBlock, addBlocks, diffBlock, missingPackages, BlockNotFoundError } from "./add.js";
2
- export { fetchBlock, fetchIndex, registryUrl, DEFAULT_REGISTRY } from "./registry.js";
2
+ export { fetchBlock, fetchIndex, registryUrl, DEFAULT_REGISTRY, MIRRORS } from "./registry.js";
3
3
  export { readConfig, writeConfig, defaultConfig, detectPackageManager, addCommand, CONFIG_FILE } from "./project.js";
@@ -1,4 +1,9 @@
1
1
  export declare const DEFAULT_REGISTRY = "https://blocks.redclove.space/r";
2
+ /**
3
+ * Copies of the public registry, published to npm as @redclove/registry and served by CDNs.
4
+ * Used only when the default registry can't be reached, so installs keep working if the site is down.
5
+ */
6
+ export declare const MIRRORS: string[];
2
7
  export type IndexEntry = {
3
8
  slug: string;
4
9
  name: string;
package/dist/registry.js CHANGED
@@ -2,6 +2,11 @@ import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  export const DEFAULT_REGISTRY = "https://blocks.redclove.space/r";
5
+ /**
6
+ * Copies of the public registry, published to npm as @redclove/registry and served by CDNs.
7
+ * Used only when the default registry can't be reached, so installs keep working if the site is down.
8
+ */
9
+ export const MIRRORS = ["https://cdn.jsdelivr.net/npm/@redclove/registry@latest", "https://unpkg.com/@redclove/registry@latest"];
5
10
  /** The registry to read from: REDCLOVE_REGISTRY if set, otherwise the public one. It may be a URL or a local folder. */
6
11
  export const registryUrl = (override) => (override ?? process.env.REDCLOVE_REGISTRY ?? DEFAULT_REGISTRY).replace(/\/$/, "");
7
12
  async function load(registry, name) {
@@ -16,12 +21,24 @@ async function load(registry, name) {
16
21
  throw e;
17
22
  }
18
23
  }
19
- const res = await fetch(`${registry}/${name}`);
20
- if (res.status === 404)
21
- return null;
22
- if (!res.ok)
23
- throw new Error(`Registry answered ${res.status} for ${name}`);
24
- return (await res.json());
24
+ // Only the public default falls back to mirrors; a registry you chose yourself is used as-is.
25
+ const sources = registry === DEFAULT_REGISTRY ? [registry, ...MIRRORS] : [registry];
26
+ let lastError;
27
+ for (const source of sources) {
28
+ try {
29
+ const res = await fetch(`${source}/${name}`, { signal: AbortSignal.timeout(10_000) });
30
+ // A 404 is an answer ("no such block"); anything else that isn't 2xx means this source is unwell.
31
+ if (res.status === 404)
32
+ return null;
33
+ if (!res.ok)
34
+ throw new Error(`${new URL(source).host} answered ${res.status} for ${name}`);
35
+ return (await res.json());
36
+ }
37
+ catch (err) {
38
+ lastError = err;
39
+ }
40
+ }
41
+ throw lastError instanceof Error ? lastError : new Error(`Couldn't reach the block registry for ${name}`);
25
42
  }
26
43
  export async function fetchIndex(registry = registryUrl()) {
27
44
  const index = await load(registry, "index.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redclove",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Add tested backend blocks (auth, payments, uploads…) to your project: npx redclove add auth",
5
5
  "license": "MIT",
6
6
  "type": "module",