@flapsdk/vault-runtime 0.1.36-next.0 → 0.1.37

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.
Files changed (37) hide show
  1. package/README.md +45 -0
  2. package/{chunk-FWYBGHBX.js → chunk-22KTLOYH.js} +4 -17
  3. package/chunk-22KTLOYH.js.map +1 -0
  4. package/{chunk-SAG36LUR.js → chunk-27VBKY3J.js} +4 -3
  5. package/chunk-27VBKY3J.js.map +1 -0
  6. package/{chunk-MLAOJT5Q.js → chunk-3X2K7YYU.js} +524 -367
  7. package/chunk-3X2K7YYU.js.map +1 -0
  8. package/chunk-AGLB72HK.js +61 -0
  9. package/chunk-AGLB72HK.js.map +1 -0
  10. package/{chunk-V7U4QTMT.js → chunk-HYBZWS6U.js} +279 -104
  11. package/chunk-HYBZWS6U.js.map +1 -0
  12. package/{chunk-PU7VEZWA.js → chunk-SRZFHGSO.js} +3 -3
  13. package/{chunk-PU7VEZWA.js.map → chunk-SRZFHGSO.js.map} +1 -1
  14. package/host-client.d.mts +2 -9
  15. package/host-client.js +5 -5
  16. package/host.d.mts +5 -5
  17. package/host.js +4 -4
  18. package/{hostRuntimeConfig-DibvcxHE.d.mts → hostRuntimeConfig-DM6JjbeO.d.mts} +1 -1
  19. package/{mpegts-J2J6JTD7.js → mpegts-536UQHCG.js} +6 -6
  20. package/{mpegts-J2J6JTD7.js.map → mpegts-536UQHCG.js.map} +1 -1
  21. package/package.json +3 -4
  22. package/runtime-contract.json +3 -3
  23. package/sdk.d.mts +6 -40
  24. package/sdk.js +9 -39
  25. package/sdk.js.map +1 -1
  26. package/server.d.mts +3 -3
  27. package/server.js +2 -2
  28. package/{txError-OBuRV8xN.d.mts → txError-vvvBIsa-.d.mts} +2 -15
  29. package/{types-DUZWZ3mC.d.mts → types-cyAEoeXa.d.mts} +6 -98
  30. package/ui.d.mts +13 -5
  31. package/ui.js +2 -2
  32. package/chunk-A3ER7XYN.js +0 -408
  33. package/chunk-A3ER7XYN.js.map +0 -1
  34. package/chunk-FWYBGHBX.js.map +0 -1
  35. package/chunk-MLAOJT5Q.js.map +0 -1
  36. package/chunk-SAG36LUR.js.map +0 -1
  37. package/chunk-V7U4QTMT.js.map +0 -1
package/README.md CHANGED
@@ -6,6 +6,8 @@ Generated from `flap-vault-ui-template`.
6
6
 
7
7
  This package is the shared runtime surface that local preview, Artifact Workbench, and `flap.sh` should agree on.
8
8
 
9
+ Package version: `0.1.37`. Source commit: `ad40bab7dfc976d20dd82050aeec17fef18a39b3`.
10
+
9
11
  ## Exports
10
12
 
11
13
  - `./sdk`: component-facing SDK hooks, helpers, types, and local oracle reader helper
@@ -14,3 +16,46 @@ This package is the shared runtime surface that local preview, Artifact Workbenc
14
16
  - `./server`: server-side presentation, runtime oracle-registry helpers, controlled image/text upload handler, and the Vault V2 NFT metadata/media resolver
15
17
 
16
18
  See `runtime-contract.json` for the machine-readable subpath contract.
19
+
20
+ ## Dynamic IPFS content
21
+
22
+ Stable runtime `0.1.37` introduces `sdk.readIpfsText(cid, path?)`, which returns
23
+ UTF-8 text or JSON as a string, and `IpfsText` for escaped plain-text display.
24
+ `IpfsImage` accepts dynamic bare CIDs from FSI, contract state, or SDK uploads.
25
+ The SDK exports `IPFS_CONTENT_VERSION = 1`; the runtime contract advertises
26
+ `sdkFeatures.ipfsContent = 1`. Stable `0.1.36` lacks the text API/component.
27
+
28
+ Vault source keeps the `@/src/sdk` and `@/src/ui` authoring aliases. Obtain
29
+ `sdk` with `useFlapSdk()`, then call the reader from an async effect or event
30
+ handler. Import `IpfsText` and `IpfsImage` from the UI alias for rendering:
31
+
32
+ ```tsx
33
+ const body = await sdk.readIpfsText(textCid);
34
+ // Parse JSON only if the application expects JSON content.
35
+ const post = JSON.parse(await sdk.readIpfsText(jsonCid));
36
+ ```
37
+
38
+ ```tsx
39
+ <IpfsText cid={item.textCid} fallback={i18n.t("contentLoading")} />
40
+ <IpfsImage cid={item.imageCid} alt={i18n.t("postImageAlt")} />
41
+ ```
42
+
43
+ Use safe relative `path` values for directory CIDs, never a gateway URL or
44
+ `ipfs://` URI. The runtime controls gateways and validates every CID/path.
45
+ Text reads omit credentials/referrers, reject redirects and HTML responses,
46
+ enforce UTF-8 and a 256 KiB limit, and have an 8-second network/body deadline
47
+ after acquiring an active slot. Reads are deduplicated, cached and concurrency
48
+ limited. `IpfsText` does not interpret HTML or Markdown. Localize loading/error
49
+ and alt text, and paginate feeds. `IpfsBackground` remains static CID-only.
50
+
51
+ Dynamic content sources require human review. Upgrade Workbench and Flap hosts
52
+ to the published runtime and deploy Workbench's matching static checker before
53
+ accepting new components. Reads use platform gateways without a new host route;
54
+ uploads continue through the existing host-owned upload service. Automated
55
+ upload fixtures are mocked and do not verify live gateway availability.
56
+
57
+ Source documentation:
58
+
59
+ - [API guide](https://github.com/flap-sh/flap-vault-component-template/blob/main/docs/ipfs-content.md)
60
+ - [API 说明](https://github.com/flap-sh/flap-vault-component-template/blob/main/docs/ipfs-content.zh-CN.md)
61
+ - [Release and upgrade notes](https://github.com/flap-sh/flap-vault-component-template/blob/main/docs/releases/0.1.37.md)
@@ -1,20 +1,7 @@
1
1
  import { erc20Abi } from 'viem';
2
2
  export { erc20Abi } from 'viem';
3
3
 
4
- // src/sdk/miniApp.ts
5
- var MINI_APP_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
6
- var RESERVED_SLUGS = /* @__PURE__ */ new Set(["api", "apps", "admin", "www", "app", "launch", "preview", "login", "settings"]);
7
- function isMiniAppSlug(value) {
8
- return typeof value === "string" && value.length >= 3 && value.length <= 64 && MINI_APP_SLUG_PATTERN.test(value) && !RESERVED_SLUGS.has(value);
9
- }
10
- function isStandaloneMiniApp(manifest) {
11
- if (!manifest || typeof manifest !== "object") return false;
12
- const value = manifest;
13
- const match = value.match;
14
- const chains = value.walletChains;
15
- if (chains !== void 0 && (!Array.isArray(chains) || !chains.length || chains.length > 8 || chains.some((id) => !Number.isSafeInteger(id) || id <= 0) || new Set(chains).size !== chains.length)) return false;
16
- return value.schemaVersion === 2 && value.mode === "mini-app" && value.appModel === "standalone" && isMiniAppSlug(value.slug) && typeof value.artifactId === "string" && Array.isArray(match?.bindings) && match.bindings.length === 0;
17
- }
4
+ // src/sdk/erc20.ts
18
5
  var standardErc20Abi = erc20Abi;
19
6
 
20
7
  // src/sdk/txError.ts
@@ -81,6 +68,6 @@ function handleTxError(error, messages) {
81
68
  return messages?.[kind] ?? defaultMessages[kind];
82
69
  }
83
70
 
84
- export { MINI_APP_SLUG_PATTERN, getTxErrorKind, handleTxError, isMiniAppSlug, isStandaloneMiniApp, standardErc20Abi };
85
- //# sourceMappingURL=chunk-FWYBGHBX.js.map
86
- //# sourceMappingURL=chunk-FWYBGHBX.js.map
71
+ export { getTxErrorKind, handleTxError, standardErc20Abi };
72
+ //# sourceMappingURL=chunk-22KTLOYH.js.map
73
+ //# sourceMappingURL=chunk-22KTLOYH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sdk/erc20.ts","../../src/sdk/txError.ts"],"names":[],"mappings":";;;;AAGO,IAAM,gBAAA,GAAmB;;;ACChC,IAAM,eAAA,GAA+C;AAAA,EACnD,YAAA,EAAc,kCAAA;AAAA,EACd,kBAAA,EAAoB,mDAAA;AAAA,EACpB,YAAA,EAAc,0EAAA;AAAA,EACd,iBAAA,EAAmB,2DAAA;AAAA,EACnB,gBAAA,EAAkB,4CAAA;AAAA,EAClB,QAAA,EAAU,yCAAA;AAAA,EACV,OAAA,EAAS;AACX,CAAA;AAEA,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAA,CAAQ,KAAK,CAAA,IAAK,OAAO,KAAA,KAAU,QAAA;AAC5C;AAEA,SAAS,WAAW,KAAA,EAAgB;AAClC,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,EAAA;AAC7C;AAEA,SAAS,gBAAgB,KAAA,EAAgB,KAAA,GAAQ,GAAG,IAAA,mB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OYH.js","sourcesContent":["import { erc20Abi } from \"viem\";\n\nexport { erc20Abi };\nexport const standardErc20Abi = erc20Abi;\n","export type TxErrorKind = \"userRejected\" | \"walletDisconnected\" | \"wrongNetwork\" | \"insufficientFunds\" | \"simulationFailed\" | \"reverted\" | \"unknown\";\n\ntype TxErrorMessageMap = Partial<Record<TxErrorKind, string>>;\n\nconst defaultMessages: Record<TxErrorKind, string> = {\n userRejected: \"You rejected the wallet request.\",\n walletDisconnected: \"Connect a wallet before sending this transaction.\",\n wrongNetwork: \"Switch the wallet to the required chain before sending this transaction.\",\n insufficientFunds: \"Insufficient wallet balance to complete this transaction.\",\n simulationFailed: \"The transaction could not pass simulation.\",\n reverted: \"The contract rejected this transaction.\",\n unknown: \"Transaction failed. Please check your wallet and try again.\",\n};\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\";\n}\n\nfunction readString(value: unknown) {\n return typeof value === \"string\" ? value : \"\";\n}\n\nfunction collectMessages(error: unknown, depth = 0, seen = new Set<unknown>()): string[] {\n if (depth > 4 || error == null || seen.has(error)) return [];\n seen.add(error);\n\n if (typeof error === \"string\") return [error];\n if (!isObject(error)) return [];\n\n const messages = [\n readString(error.shortMessage),\n readString(error.message),\n readString(error.details),\n readString(error.reason),\n ].filter(Boolean);\n\n return [...messages, ...collectMessages(error.cause, depth + 1, seen)];\n}\n\nfunction collectCodes(error: unknown, depth = 0, seen = new Set<unknown>()): Array<string | number> {\n if (depth > 4 || error == null || seen.has(error)) return [];\n seen.add(error);\n if (!isObject(error)) return [];\n\n const codes = [error.code, error.name].filter((value) => typeof value === \"string\" || typeof value === \"number\");\n return [...codes, ...collectCodes(error.cause, depth + 1, seen)];\n}\n\nexport function getTxErrorKind(error: unknown): TxErrorKind {\n const message = collectMessages(error).join(\" \").toLowerCase();\n const codes = collectCodes(error)\n .map((value: string | number) => String(value).toLowerCase())\n .join(\" \");\n\n if (\n codes.includes(\"4001\") ||\n codes.includes(\"action_rejected\") ||\n codes.includes(\"userrejectedrequesterror\") ||\n /user rejected|user denied|rejected the request|denied transaction|request rejected|cancelled/i.test(message)\n ) {\n return \"userRejected\";\n }\n\n if (/wallet is not connected|connector not connected|account not found|no wallet client/i.test(message)) {\n return \"walletDisconnected\";\n }\n\n if (/wrong network|switch wallet to|switch network to|required chain/i.test(message)) {\n return \"wrongNetwork\";\n }\n\n if (/insufficient funds|exceeds the balance|gas \\* price \\+ value/i.test(message)) {\n return \"insufficientFunds\";\n }\n\n if (/simulation failed|simulatecontract|execution reverted during simulation/i.test(message)) {\n return \"simulationFailed\";\n }\n\n if (/execution reverted|reverted with the following reason|contract function .* reverted|call exception/i.test(message)) {\n return \"reverted\";\n }\n\n return \"unknown\";\n}\n\nexport function handleTxError(error: unknown, messages?: TxErrorMessageMap) {\n const kind = getTxErrorKind(error);\n return messages?.[kind] ?? defaultMessages[kind];\n}\n"]}
@@ -6,10 +6,11 @@ var IPFS_IMAGE_GATEWAYS = ["https://flap.mypinata.cloud", "https://magenta-naval
6
6
  var CID_RE = /^(?:Qm[1-9A-HJ-NP-Za-km-z]{44}|b[a-z2-7]{20,})$/;
7
7
  var PATH_SEGMENT_RE = /^[A-Za-z0-9._~-]+$/;
8
8
  function isIpfsImageCid(value) {
9
- return CID_RE.test(value.trim());
9
+ return typeof value === "string" && value.length <= 128 && CID_RE.test(value.trim());
10
10
  }
11
11
  function normalizeIpfsImagePath(value) {
12
12
  if (value === void 0) return "";
13
+ if (typeof value !== "string") return void 0;
13
14
  const trimmed = value.trim();
14
15
  if (!trimmed || trimmed.length > 512 || trimmed.startsWith("/") || trimmed.endsWith("/")) return void 0;
15
16
  const segments = trimmed.split("/");
@@ -31,5 +32,5 @@ function resolveIpfsImageUrls(cid, chainId = 56, path) {
31
32
  }
32
33
 
33
34
  export { isIpfsImageCid, normalizeIpfsImagePath, resolveIpfsImageUrl, resolveIpfsImageUrls };
34
- //# sourceMappingURL=chunk-SAG36LUR.js.map
35
- //# sourceMappingURL=chunk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DEFAULT_IPFS_IMAGE_GATEWAY = \"https://flap.mypinata.cloud\";\nconst IPFS_IMAGE_GATEWAYS = [\"https://flap.mypinata.cloud\", \"https://magenta-naval-penguin-822.mypinata.cloud\"] as const;\nconst CID_RE = /^(?:Qm[1-9A-HJ-NP-Za-km-z]{44}|b[a-z2-7]{20,})$/;\nconst PATH_SEGMENT_RE = /^[A-Za-z0-9._~-]+$/;\n\nexport function isIpfsImageCid(value: string) {\n return typeof value === \"string\" && value.length <= 128 && CID_RE.test(value.trim());\n}\n\nexport function normalizeIpfsImagePath(value: string | undefined) {\n if (value === undefined) return \"\";\n if (typeof value !== \"string\") return undefined;\n const trimmed = value.trim();\n if (!trimmed || trimmed.length > 512 || trimmed.startsWith(\"/\") || trimmed.endsWith(\"/\")) return undefined;\n const segments = trimmed.split(\"/\");\n if (segments.some((segment) => !segment || segment === \".\" || segment === \"..\" || !PATH_SEGMENT_RE.test(segment))) return undefined;\n return segments.join(\"/\");\n}\n\nexport function resolveIpfsImageUrl(cid: string, chainId = 56, path?: string) {\n const normalizedPath = normalizeIpfsImagePath(path);\n if (!isIpfsImageCid(cid) || normalizedPath === undefined) return undefined;\n const gateway = (getTaxVaultHostChainConfig(chainId)?.ipfsGateway ?? DEFAULT_IPFS_IMAGE_GATEWAY).replace(/\\/+$/, \"\");\n return `${gateway}/ipfs/${cid.trim()}${normalizedPath ? `/${normalizedPath}` : \"\"}`;\n}\n\nexport function resolveIpfsImageUrls(cid: string, chainId = 56, path?: string) {\n const normalizedPath = normalizeIpfsImagePath(path);\n if (!isIpfsImageCid(cid) || normalizedPath === undefined) return [];\n const preferred = (getTaxVaultHostChainConfig(chainId)?.ipfsGateway ?? DEFAULT_IPFS_IMAGE_GATEWAY).replace(/\\/+$/, \"\");\n const gateways = [preferred, ...IPFS_IMAGE_GATEWAYS.map((gateway) => gateway.replace(/\\/+$/, \"\"))];\n return [...new Set(gateways)].map((gateway) => `${gateway}/ipfs/${cid.trim()}${normalizedPath ? `/${normalizedPath}` : \"\"}`);\n}\n"]}