@medialane/ui 0.4.2 → 0.4.3

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.
@@ -22,11 +22,18 @@ __export(ipfs_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(ipfs_exports);
24
24
  const DEFAULT_GATEWAY = "https://ipfs.io/ipfs/";
25
+ const ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "ipfs:"]);
25
26
  function ipfsToHttp(uri, gateway = DEFAULT_GATEWAY) {
26
27
  if (!uri) return "";
27
28
  if (uri.startsWith("ipfs://")) {
28
29
  return uri.replace("ipfs://", gateway);
29
30
  }
31
+ try {
32
+ const { protocol } = new URL(uri);
33
+ if (!ALLOWED_PROTOCOLS.has(protocol)) return "";
34
+ } catch {
35
+ return "";
36
+ }
30
37
  return uri;
31
38
  }
32
39
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["const DEFAULT_GATEWAY = \"https://ipfs.io/ipfs/\";\n\n/**\n * Convert an IPFS URI to an HTTP URL.\n * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP URLs (returned as-is).\n *\n * @param uri - The IPFS URI or HTTP URL to convert.\n * @param gateway - Gateway base URL (default: ipfs.io). Should end without a trailing slash.\n */\nexport function ipfsToHttp(\n uri: string | null | undefined,\n gateway = DEFAULT_GATEWAY\n): string {\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return uri.replace(\"ipfs://\", gateway);\n }\n return uri;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,kBAAkB;AASjB,SAAS,WACd,KACA,UAAU,iBACF;AACR,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,SAAS,GAAG;AAC7B,WAAO,IAAI,QAAQ,WAAW,OAAO;AAAA,EACvC;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["const DEFAULT_GATEWAY = \"https://ipfs.io/ipfs/\";\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\", \"ipfs:\"]);\n\n/**\n * Convert an IPFS URI to an HTTP URL.\n * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP/HTTPS URLs.\n * Rejects javascript:, data:, blob:, and any other non-allowlisted protocols.\n *\n * @param uri - The IPFS URI or HTTP URL to convert.\n * @param gateway - Gateway base URL (default: ipfs.io). Should end without a trailing slash.\n */\nexport function ipfsToHttp(\n uri: string | null | undefined,\n gateway = DEFAULT_GATEWAY\n): string {\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return uri.replace(\"ipfs://\", gateway);\n }\n try {\n const { protocol } = new URL(uri);\n if (!ALLOWED_PROTOCOLS.has(protocol)) return \"\";\n } catch {\n return \"\";\n }\n return uri;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,kBAAkB;AAExB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,SAAS,UAAU,OAAO,CAAC;AAUvD,SAAS,WACd,KACA,UAAU,iBACF;AACR,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,SAAS,GAAG;AAC7B,WAAO,IAAI,QAAQ,WAAW,OAAO;AAAA,EACvC;AACA,MAAI;AACF,UAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAChC,QAAI,CAAC,kBAAkB,IAAI,QAAQ,EAAG,QAAO;AAAA,EAC/C,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Convert an IPFS URI to an HTTP URL.
3
- * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP URLs (returned as-is).
3
+ * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP/HTTPS URLs.
4
+ * Rejects javascript:, data:, blob:, and any other non-allowlisted protocols.
4
5
  *
5
6
  * @param uri - The IPFS URI or HTTP URL to convert.
6
7
  * @param gateway - Gateway base URL (default: ipfs.io). Should end without a trailing slash.
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Convert an IPFS URI to an HTTP URL.
3
- * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP URLs (returned as-is).
3
+ * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP/HTTPS URLs.
4
+ * Rejects javascript:, data:, blob:, and any other non-allowlisted protocols.
4
5
  *
5
6
  * @param uri - The IPFS URI or HTTP URL to convert.
6
7
  * @param gateway - Gateway base URL (default: ipfs.io). Should end without a trailing slash.
@@ -1,9 +1,16 @@
1
1
  const DEFAULT_GATEWAY = "https://ipfs.io/ipfs/";
2
+ const ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "ipfs:"]);
2
3
  function ipfsToHttp(uri, gateway = DEFAULT_GATEWAY) {
3
4
  if (!uri) return "";
4
5
  if (uri.startsWith("ipfs://")) {
5
6
  return uri.replace("ipfs://", gateway);
6
7
  }
8
+ try {
9
+ const { protocol } = new URL(uri);
10
+ if (!ALLOWED_PROTOCOLS.has(protocol)) return "";
11
+ } catch {
12
+ return "";
13
+ }
7
14
  return uri;
8
15
  }
9
16
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["const DEFAULT_GATEWAY = \"https://ipfs.io/ipfs/\";\n\n/**\n * Convert an IPFS URI to an HTTP URL.\n * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP URLs (returned as-is).\n *\n * @param uri - The IPFS URI or HTTP URL to convert.\n * @param gateway - Gateway base URL (default: ipfs.io). Should end without a trailing slash.\n */\nexport function ipfsToHttp(\n uri: string | null | undefined,\n gateway = DEFAULT_GATEWAY\n): string {\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return uri.replace(\"ipfs://\", gateway);\n }\n return uri;\n}\n"],"mappings":"AAAA,MAAM,kBAAkB;AASjB,SAAS,WACd,KACA,UAAU,iBACF;AACR,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,SAAS,GAAG;AAC7B,WAAO,IAAI,QAAQ,WAAW,OAAO;AAAA,EACvC;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/ipfs.ts"],"sourcesContent":["const DEFAULT_GATEWAY = \"https://ipfs.io/ipfs/\";\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\", \"ipfs:\"]);\n\n/**\n * Convert an IPFS URI to an HTTP URL.\n * Accepts ipfs://<cid>, ipfs://<cid>/<path>, or plain HTTP/HTTPS URLs.\n * Rejects javascript:, data:, blob:, and any other non-allowlisted protocols.\n *\n * @param uri - The IPFS URI or HTTP URL to convert.\n * @param gateway - Gateway base URL (default: ipfs.io). Should end without a trailing slash.\n */\nexport function ipfsToHttp(\n uri: string | null | undefined,\n gateway = DEFAULT_GATEWAY\n): string {\n if (!uri) return \"\";\n if (uri.startsWith(\"ipfs://\")) {\n return uri.replace(\"ipfs://\", gateway);\n }\n try {\n const { protocol } = new URL(uri);\n if (!ALLOWED_PROTOCOLS.has(protocol)) return \"\";\n } catch {\n return \"\";\n }\n return uri;\n}\n"],"mappings":"AAAA,MAAM,kBAAkB;AAExB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,SAAS,UAAU,OAAO,CAAC;AAUvD,SAAS,WACd,KACA,UAAU,iBACF;AACR,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,IAAI,WAAW,SAAS,GAAG;AAC7B,WAAO,IAAI,QAAQ,WAAW,OAAO;AAAA,EACvC;AACA,MAAI;AACF,UAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAChC,QAAI,CAAC,kBAAkB,IAAI,QAAQ,EAAG,QAAO;AAAA,EAC/C,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medialane/ui",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Shared UI components for Medialane apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",