@tinycloud/web-sdk 3.12.0-beta.10 → 3.12.0-beta.12
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.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/space-hosting-entry.d.ts +1 -1
- package/dist/space-hosting.cjs +1 -1
- package/dist/space-hosting.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** Space hosting probe and space creation, loaded when the first hosting check or creation runs. */
|
|
2
|
-
export { askSpaceHosting, createPrimarySpace } from "@tinycloud/node-sdk/space-hosting";
|
|
2
|
+
export { askSpaceHosting, createPrimarySpace, withHostExpiry } from "@tinycloud/node-sdk/space-hosting";
|
|
3
3
|
//# sourceMappingURL=space-hosting-entry.d.ts.map
|
package/dist/space-hosting.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(t,a)=>{for(var s in a)e.o(a,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:a[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{askSpaceHosting:()=>u,createPrimarySpace:()=>w});var a=new WeakMap,s=5e3,
|
|
1
|
+
(()=>{"use strict";var e={d:(t,a)=>{for(var s in a)e.o(a,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:a[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{askSpaceHosting:()=>u,createPrimarySpace:()=>w,withHostExpiry:()=>f});var a=new WeakMap,s=5e3,n="tinycloud.kv/list",o="tinycloud.kv/metadata",i="tinycloud.kv/get",r="tinycloud.space/info",c=e=>""===e||e.endsWith("/")||e.endsWith("/*")||e.endsWith("/**"),d=e=>e.endsWith("/**")?e.slice(0,-2):e.endsWith("/*")?e.slice(0,-1):"/"===e?"":e,p=e=>c(e)?`${d(e)}.tinycloud-space-probe`:e;async function h(e,t){try{const{spaceId:a}=e,n=await e.fetch(`${e.host}/invoke`,{method:"POST",headers:{...e.sign([{spaceId:a,service:t.service,path:t.path,action:t.action}]),...t.headers},body:t.body,signal:AbortSignal.timeout(s)});return n.ok?(n.body instanceof ReadableStream&&await n.body.cancel().catch(()=>{}),"hosted"):401===n.status||403===n.status?"refused":404===n.status?/space not found/i.test(await n.text())?"not-hosted":"hosted":"unknown"}catch{return"unknown"}}async function u(e){const t=function({spaceId:e,operations:t,covers:a}){const s=t.filter(t=>!t.caveats?.length&&a(t,{spaceId:e,service:t.service,path:t.path,action:t.action})),h=(t,n)=>s.filter(s=>a(s,{spaceId:e,service:t,path:s.path,action:n}));return[...h("kv",n).map(e=>({service:"kv",path:c(e.path)?d(e.path):e.path,action:n,headers:{"x-tinycloud-limit":"1"}})),...h("kv",o).map(e=>({service:"kv",path:p(e.path),action:o})),...h("space",r).map(()=>({service:"space",path:"",action:r,body:"{}"})),...h("kv",i).map(e=>({service:"kv",path:p(e.path),action:i}))].find(t=>s.some(s=>a(s,{spaceId:e,service:t.service,path:t.path,action:t.action})))}(e);if(!t)return"unknown";const u=`${e.host} ${e.spaceId.replace(/^(tinycloud:pkh:eip155:\d+:)(0x[0-9a-fA-F]{40})/,(e,t,a)=>t+a.toLowerCase())}`;if(a.get(e.scope)?.has(u))return"hosted";let l=await h(e,t);if("refused"===l){try{await e.activate(AbortSignal.timeout(s))}catch{return"unknown"}l=await h(e,t)}return"hosted"===l&&a.set(e.scope,(a.get(e.scope)??new Set).add(u)),"refused"===l?"unknown":l}function l(e){const t=e.error?.trim();return t?`${e.status} - ${t}`:`${e.status}`}async function w({handler:e,session:t,context:a,currentSession:s,signerAddress:n,resolveHost:o,domain:i,hostName:r,guard:c,host:d,onHosted:p,activate:h,signal:u}){const w=()=>{if(u?.throwIfAborted(),t&&s?.()!==t)throw new Error("Space hosting session changed")};if(w(),t&&n&&(await n()).toLowerCase()!==t.address.toLowerCase())return;w();const f=a??(t&&{address:t.address,chainId:t.chainId,spaceId:t.spaceId,host:await(o?.())??r??""});if(!f)throw new Error("Space hosting requires a session context");w(),await c(f),w();const m=await e.confirmSpaceCreation(f);if(w(),!m)return;try{const e=await d(f,w,e=>({address:f.address,chainId:f.chainId,domain:i??"",issuedAt:(new Date).toISOString(),spaceId:f.spaceId,peerId:e}));if(!e.success)throw Object.assign(new Error(`Failed to create space ${f.spaceId}: ${l(e)}`),{cause:e})}catch(t){throw e.onSpaceCreationFailed?.(f,t instanceof Error?t:new Error(String(t))),t}w(),p(f),await new Promise(e=>setTimeout(e,100)),w();const g=await h(f);if(w(),!g.success){const t=Object.assign(new Error(`Failed to activate session after creating space: ${l(g)}`),{cause:g});throw e.onSpaceCreationFailed?.(f,t),t}e.onSpaceCreated?.(f)}function f(e,t,a,s){if(/[\r\u0085\u2028\u2029]/.test(e))throw new Error("Host SIWE contains an unsupported line separator");const n=e.split("\n");if(n.some(e=>e.startsWith("Expiration Time:")))throw new Error("Host SIWE already contains Expiration Time");const o=""===n[3]?4:5,i=o+4;if(!n[o]?.startsWith("URI: ")||!n[i]?.startsWith("Issued At: "))throw new Error("Host SIWE has no positional Issued At field");const r=new Date(t),c=r.getUTCDate();r.setUTCDate(1),r.setUTCFullYear(r.getUTCFullYear()+a);const d=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()+1,0)).getUTCDate();r.setUTCDate(Math.min(c,d));const p=void 0===s?r.getTime():Date.parse(s);if(!Number.isFinite(p)||p<=t.getTime())throw new Error("Host expiry must be a valid future timestamp");const h=new Date(Math.min(p,r.getTime())).toISOString();return n.splice(i+1,0,`Expiration Time: ${h}`),n.join("\n")}module.exports=t})();
|
package/dist/space-hosting.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t=new WeakMap,e="tinycloud.kv/list",a="tinycloud.kv/metadata",s="tinycloud.kv/get",n="tinycloud.space/info",i=t=>""===t||t.endsWith("/")||t.endsWith("/*")||t.endsWith("/**"),o=t=>t.endsWith("/**")?t.slice(0,-2):t.endsWith("/*")?t.slice(0,-1):"/"===t?"":t,r=t=>i(t)?`${o(t)}.tinycloud-space-probe`:t;async function c(t,e){try{const{spaceId:a}=t,s=await t.fetch(`${t.host}/invoke`,{method:"POST",headers:{...t.sign([{spaceId:a,service:e.service,path:e.path,action:e.action}]),...e.headers},body:e.body,signal:AbortSignal.timeout(5e3)});return s.ok?(s.body instanceof ReadableStream&&await s.body.cancel().catch(()=>{}),"hosted"):401===s.status||403===s.status?"refused":404===s.status?/space not found/i.test(await s.text())?"not-hosted":"hosted":"unknown"}catch{return"unknown"}}async function d(d){const h=function({spaceId:t,operations:c,covers:d}){const h=c.filter(e=>!e.caveats?.length&&d(e,{spaceId:t,service:e.service,path:e.path,action:e.action})),p=(e,a)=>h.filter(s=>d(s,{spaceId:t,service:e,path:s.path,action:a}));return[...p("kv",e).map(t=>({service:"kv",path:i(t.path)?o(t.path):t.path,action:e,headers:{"x-tinycloud-limit":"1"}})),...p("kv",a).map(t=>({service:"kv",path:r(t.path),action:a})),...p("space",n).map(()=>({service:"space",path:"",action:n,body:"{}"})),...p("kv",s).map(t=>({service:"kv",path:r(t.path),action:s}))].find(e=>h.some(a=>d(a,{spaceId:t,service:e.service,path:e.path,action:e.action})))}(d);if(!h)return"unknown";const p=`${d.host} ${d.spaceId.replace(/^(tinycloud:pkh:eip155:\d+:)(0x[0-9a-fA-F]{40})/,(t,e,a)=>e+a.toLowerCase())}`;if(t.get(d.scope)?.has(p))return"hosted";let u=await c(d,h);if("refused"===u){try{await d.activate(AbortSignal.timeout(5e3))}catch{return"unknown"}u=await c(d,h)}return"hosted"===u&&t.set(d.scope,(t.get(d.scope)??new Set).add(p)),"refused"===u?"unknown":u}function h(t){const e=t.error?.trim();return e?`${t.status} - ${e}`:`${t.status}`}async function p({handler:t,session:e,context:a,currentSession:s,signerAddress:n,resolveHost:i,domain:o,hostName:r,guard:c,host:d,onHosted:p,activate:u,signal:w}){const l=()=>{if(w?.throwIfAborted(),e&&s?.()!==e)throw new Error("Space hosting session changed")};if(l(),e&&n&&(await n()).toLowerCase()!==e.address.toLowerCase())return;l();const f=a??(e&&{address:e.address,chainId:e.chainId,spaceId:e.spaceId,host:await(i?.())??r??""});if(!f)throw new Error("Space hosting requires a session context");l(),await c(f),l();const m=await t.confirmSpaceCreation(f);if(l(),!m)return;try{const t=await d(f,l,t=>({address:f.address,chainId:f.chainId,domain:o??"",issuedAt:(new Date).toISOString(),spaceId:f.spaceId,peerId:t}));if(!t.success)throw Object.assign(new Error(`Failed to create space ${f.spaceId}: ${h(t)}`),{cause:t})}catch(e){throw t.onSpaceCreationFailed?.(f,e instanceof Error?e:new Error(String(e))),e}l(),p(f),await new Promise(t=>setTimeout(t,100)),l();const v=await u(f);if(l(),!v.success){const e=Object.assign(new Error(`Failed to activate session after creating space: ${h(v)}`),{cause:v});throw t.onSpaceCreationFailed?.(f,e),e}t.onSpaceCreated?.(f)}function u(t,e,a,s){if(/[\r\u0085\u2028\u2029]/.test(t))throw new Error("Host SIWE contains an unsupported line separator");const n=t.split("\n");if(n.some(t=>t.startsWith("Expiration Time:")))throw new Error("Host SIWE already contains Expiration Time");const i=""===n[3]?4:5,o=i+4;if(!n[i]?.startsWith("URI: ")||!n[o]?.startsWith("Issued At: "))throw new Error("Host SIWE has no positional Issued At field");const r=new Date(e),c=r.getUTCDate();r.setUTCDate(1),r.setUTCFullYear(r.getUTCFullYear()+a);const d=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()+1,0)).getUTCDate();r.setUTCDate(Math.min(c,d));const h=void 0===s?r.getTime():Date.parse(s);if(!Number.isFinite(h)||h<=e.getTime())throw new Error("Host expiry must be a valid future timestamp");const p=new Date(Math.min(h,r.getTime())).toISOString();return n.splice(o+1,0,`Expiration Time: ${p}`),n.join("\n")}export{d as askSpaceHosting,p as createPrimarySpace,u as withHostExpiry};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinycloud/web-sdk",
|
|
3
|
-
"version": "3.12.0-beta.
|
|
3
|
+
"version": "3.12.0-beta.12",
|
|
4
4
|
"description": "A set of tools and utilities to help you build your app with TinyCloud.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"@multiformats/multiaddr": "^13.0.1",
|
|
68
68
|
"@multiformats/multiaddr-to-uri": "^12.0.0",
|
|
69
69
|
"@noble/curves": "^1.9.7",
|
|
70
|
-
"@tinycloud/node-sdk": "3.12.0-beta.
|
|
70
|
+
"@tinycloud/node-sdk": "3.12.0-beta.12",
|
|
71
71
|
"@tinycloud/replica": "0.4.5-beta.4",
|
|
72
|
-
"@tinycloud/sdk-core": "3.12.0-beta.
|
|
72
|
+
"@tinycloud/sdk-core": "3.12.0-beta.12",
|
|
73
73
|
"@tinycloud/share-envelope": "1.5.0",
|
|
74
74
|
"@tinycloud/share-sdk": "1.4.4",
|
|
75
75
|
"@tinycloud/web-sdk-wasm": "1.7.7",
|