@plitzi/plitzi-sdk 0.37.6 → 0.37.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @plitzi/plitzi-sdk
2
2
 
3
+ ## 0.37.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 4d10e0a: ## CDNs with several buckets
8
+
9
+ A CDN is the customer's own storage account — S3 or R2, which they run and pay for — and now holds any number of
10
+ buckets, each with its own configuration: its name at the provider, its region, `public` (served at its domain) or
11
+ `private` (no domain, read only by the platform with the CDN's credential).
12
+
13
+ - `Cdn` carries `buckets: CdnBucket[]`; `domain`, `visibility`, `bucketName` and `region` moved from the CDN to its
14
+ buckets. `Resource.bucketIdentifier` names the bucket a file is in.
15
+ - `SpaceAddCdn(name, provider, endpoint, buckets)` creates the account with its buckets; `SpaceUpdateCdn` changes the
16
+ account only. New `SpaceAddCdnBucket`, `SpaceUpdateCdnBucket` and `SpaceRemoveCdnBucket`.
17
+ - `SpaceResources`, `SpaceAddResource`, `SpaceRemoveResource` and `SpaceMoveResource` take `bucketIdentifier`.
18
+ - Server code — functions and runtime — goes in the space's oldest private bucket. A bucket that keeps code a version
19
+ runs can be neither made public, pointed at another bucket nor removed, and neither can its CDN.
20
+ - Builder: Resources shows each CDN with its buckets — add, edit and remove buckets, upload and browse per bucket; the
21
+ account (name, provider, endpoint, credential) is edited apart. Saving an element as a template picks a public
22
+ bucket (`elementAsTemplate({ cdnIdentifier, bucketIdentifier }, …)`).
23
+ - CLI: `plitzi upload plugin --bucket <identifier>` (with `--cdn` to narrow); only public buckets are offered, a private
24
+ one is refused.
25
+
26
+ - Updated dependencies [4d10e0a]
27
+ - @plitzi/sdk-auth@0.37.7
28
+ - @plitzi/sdk-dev-tools@0.37.7
29
+ - @plitzi/sdk-elements@0.37.7
30
+ - @plitzi/sdk-event-bridge@0.37.7
31
+ - @plitzi/sdk-interactions@0.37.7
32
+ - @plitzi/sdk-navigation@0.37.7
33
+ - @plitzi/sdk-plugins@0.37.7
34
+ - @plitzi/sdk-schema@0.37.7
35
+ - @plitzi/sdk-shared@0.37.7
36
+ - @plitzi/sdk-style@0.37.7
37
+ - @plitzi/sdk-variables@0.37.7
38
+
3
39
  ## 0.37.6
4
40
 
5
41
  ### Patch Changes
@@ -55,7 +55,7 @@ return e.createElement(e.Fragment,null,f.map(t=>/* @__PURE__ */e.createElement("
55
55
  return e.createElement(Kk,{...c,"aria-current":C,className:k,ref:u,style:A,to:o,viewTransition:s},"function"==typeof l?l(T):l)});Jk.displayName="NavLink";var Xk=e.forwardRef(({discover:t="render",fetcherKey:n,navigate:r,reloadDocument:a,replace:i,state:o,method:s=Ek,action:l,onSubmit:c,relative:u,preventScrollReset:d,viewTransition:p,defaultShouldRevalidate:f,...h},m)=>{let{useTransitions:g}=e.useContext(rk),y=function(){let{router:t}=Zk("useSubmit"),{basename:n}=e.useContext(rk),r=kk("useRouteId"),a=t.fetch,i=t.navigate;return e.useCallback(async(e,t={})=>{let{action:o,method:s,encType:l,formData:c,body:u}=function(e,t){let n,r,a,i,o;if(_k(s=e)&&"form"===s.tagName.toLowerCase()){let o=e.getAttribute("action");r=o?_w(o,t):null,n=e.getAttribute("method")||Ek,a=Mk(e.getAttribute("enctype"))||Ik,i=new FormData(e)}else if(function(e){return _k(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return _k(e)&&"input"===e.tagName.toLowerCase()}(e)&&("submit"===e.type||"image"===e.type)){let o=e.form;if(null==o)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let s=e.getAttribute("formaction")||o.getAttribute("action");if(r=s?_w(s,t):null,n=e.getAttribute("formmethod")||o.getAttribute("method")||Ek,a=Mk(e.getAttribute("formenctype"))||Mk(o.getAttribute("enctype"))||Ik,i=new FormData(o,e),!function(){if(null===Nk)try{new FormData(document.createElement("form"),0),Nk=!1}catch(tI){Nk=!0}return Nk}()){let{name:t,type:n,value:r}=e;if("image"===n){let e=t?`${t}.`:"";i.append(`${e}x`,"0"),i.append(`${e}y`,"0")}else t&&i.append(t,r)}}else{if(_k(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n=Ek,r=null,a=Ik,o=e}var s;return i&&"text/plain"===a&&(o=i,i=void 0),{action:r,method:n.toLowerCase(),encType:a,formData:i,body:o}}(e,n);if(!1===t.navigate){let e=t.fetcherKey||ex();await a(e,r,t.action||o,{defaultShouldRevalidate:t.defaultShouldRevalidate,preventScrollReset:t.preventScrollReset,formData:c,body:u,formMethod:t.method||s,formEncType:t.encType||l,flushSync:t.flushSync})}else await i(t.action||o,{defaultShouldRevalidate:t.defaultShouldRevalidate,preventScrollReset:t.preventScrollReset,formData:c,body:u,formMethod:t.method||s,formEncType:t.encType||l,replace:t.replace,state:t.state,fromRouteId:r,flushSync:t.flushSync,viewTransition:t.viewTransition})},[a,i,n,r])}(),b=function(t,{relative:n}={}){let{basename:r}=e.useContext(rk),a=e.useContext(ik);sw(a,"useFormAction must be used inside a RouteContext");let[i]=a.matches.slice(-1),o={...fk(t||".",{relative:n})},s=ck();if(null==t){o.search=s.search;let e=new URLSearchParams(o.search),t=e.getAll("index");if(t.some(e=>""===e)){e.delete("index"),t.filter(e=>e).forEach(t=>e.append("index",t));let n=e.toString();o.search=n?`?${n}`:""}}return t&&"."!==t||!i.route.index||(o.search=o.search?o.search.replace(/^\?/,"?index&"):"?index"),"/"!==r&&(o.pathname="/"===o.pathname?r:Dw([r,o.pathname])),dw(o)}(l,{relative:u}),v="get"===s.toLowerCase()?"get":"post",w="string"==typeof l&&rw.test(l);/* @__PURE__ */
56
56
  return e.createElement("form",{ref:m,method:v,action:b,onSubmit:a?c:t=>{if(c&&c(t),t.defaultPrevented)return;t.preventDefault();let a=t.nativeEvent.submitter,l=a?.getAttribute("formmethod")||s,h=()=>y(a||t.currentTarget,{fetcherKey:n,method:l,navigate:r,replace:i,state:o,relative:u,preventScrollReset:d,viewTransition:p,defaultShouldRevalidate:f});g&&!1!==r?e.startTransition(()=>h()):h()},...h,"data-discover":w||"render"!==t?void 0:"true"})});function Zk(t){let n=e.useContext(Zw);return sw(n,function(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}(t)),n}Xk.displayName="Form";var Qk=0,ex=()=>`__${String(++Qk)}__`;function tx({basename:t,children:n,location:r="/"}){"string"==typeof r&&(r=pw(r));let a={pathname:r.pathname||"/",search:r.search||"",hash:r.hash||"",state:null!=r.state?r.state:null,key:r.key||"default",mask:void 0},i={createHref:nx,encodeLocation:rx,push(e){throw new Error(`You cannot use navigator.push() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${JSON.stringify(e)})\` somewhere in your app.`)},replace(e){throw new Error(`You cannot use navigator.replace() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${JSON.stringify(e)}, { replace: true })\` somewhere in your app.`)},go(e){throw new Error(`You cannot use navigator.go() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${e})\` somewhere in your app.`)},back(){throw new Error("You cannot use navigator.back() on the server because it is a stateless environment.")},forward(){throw new Error("You cannot use navigator.forward() on the server because it is a stateless environment.")}};/* @__PURE__ */
57
57
  return e.createElement(Ak,{basename:t,children:n,location:a,navigationType:"POP",navigator:i,static:!0,useTransitions:!1})}function nx(e){return"string"==typeof e?e:dw(e)}function rx(e){let t="string"==typeof e?e:dw(e);t=t.replace(/ $/,"%20");let n=rw.test(t)?new URL(t):new URL(t,"http://localhost");return{pathname:n.pathname,search:n.search,hash:n.hash}}var ax,ix=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],ox=()=>{const e=new URLSearchParams(window.location.search),t={};for(const n of ix){const r=e.get(n);r&&(t[n.slice(4)]=r)}return Object.keys(t).length>0?t:void 0},sx=()=>"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,lx=e=>{ax=e},cx=(e,t)=>{ax?.track(e,t)},ux=({analytics:e})=>{const t=ck(),n=x(!0===e?.firstViewCounted);return g(()=>{if(!e?.endpoint||!e.key)return;const t=((e,t=20,n=5e3)=>{const r=[],a=`${e.endpoint.replace(/\/+$/,"")}/batch?k=${encodeURIComponent(e.key)}`;let i;const o=()=>{0!==r.length&&(e=>{const t=JSON.stringify({events:e});"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon&&navigator.sendBeacon(a,t)||fetch(a,{method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:t,keepalive:!0,mode:"no-cors"}).catch(()=>{})})(r.splice(0,r.length))},s=e=>{r.push(e),r.length>=t&&o()},l=()=>({path:window.location.pathname,title:document.title||void 0});return"undefined"!=typeof window&&(i=setInterval(o,n),document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState&&o()}),window.addEventListener("pagehide",o)),{trackRender:()=>{s({id:sx(),type:"render",ts:Date.now(),page:l(),ref:{referrer:document.referrer||void 0,utm:ox()}})},track:(e,t)=>{s({id:sx(),type:"interaction",ts:Date.now(),page:l(),name:e,props:t})},flush:o,stop:()=>{i&&(clearInterval(i),i=void 0),o()}}})(e);return lx(t),()=>{lx(void 0),t.stop()}},[e]),g(()=>{n.current?n.current=!1:ax?.trackRender()},[t.pathname,t.search]),null},dx=l({});dx.displayName="AuthContext";var px=({server:e,routerLocation:t})=>{let n=k(()=>typeof window<"u"?window.location:Jn(e,"location",{pathname:"/"}),[e]),r=k(()=>{if(!t)return n;let{origin:e,host:r,hostname:a,protocol:i,href:o}=n,{pathname:s,search:l}=t;return{origin:e,host:r,hostname:a,protocol:i,pathname:s,search:l,hash:"",href:e?`${e}${s}${l}`:o}},[n,t]),a=k(()=>function(e){!e&&typeof window<"u"&&(e=window.location.search);let t={};if(!e||0===e.length)return t;let n=e.replace("?","").split("&");for(let r=0;r<n.length;r++){let e=n[r].split("="),a=decodeURIComponent(e[0]),i=decodeURIComponent(e[1]);void 0===t[a]?t[a]=decodeURIComponent(i):"string"==typeof t[a]?t[a]=[t[a],decodeURIComponent(i)]:t[a].push(decodeURIComponent(i))}return t}(r.search),[r.search]),i=k(()=>r.hostname?r.hostname:"localhost",[r.hostname]),o=r.origin||"";return k(()=>({queryParams:a,hostname:i,origin:o,location:r}),[a,i,o,r])},fx=({children:e,currentPageId:t})=>{const{server:n}=f(nc),r=At(),{renderMode:a,previewMode:i,environment:o}=K(),[[s,l,c]]=Ot(["schema.pageFolders","pageDefinitions","schema.variables"]),u=n.ssr?.renderResult,d="widget"!==a?ck():void 0,{queryParams:p,hostname:m,origin:y,location:b}=px({server:n,routerLocation:d}),v=x(l);v.current=l;const w=x(s);w.current=s;const{authenticated:S}=f(dx),T="widget"!==a?pk():void 0,C=x(T);g(()=>{C.current=T},[T]);const A=k(()=>Ec(l,s,S,n.basePath,i),[l,s,S,n.basePath,i]),{action:E,pageId:N="",pathMatch:O}=k(()=>"widget"===a?{action:{type:"normal",path:""},pageId:t}:Ic(A,b.pathname,S),[A,b.pathname,S,a,t]),M=t||N;g(()=>{Ml.info("navigation",/* @__PURE__ */_("span",{children:["Navigated to page"," ",
58
- /* @__PURE__ */I("b",{children:Jn(l,`${M}.attributes.name`,M||"Unknown")})]}),{status:E.type,elementId:M})},[E.type,M,l]);const P=h(e=>((e,t,n)=>{let r=e[n];if(!r)return n;let{slug:a,default:i}=r.attributes;return"string"==typeof a?Cc(e,t,n,!0):i?"/":`/${n}`})(v.current,w.current,e),[]),L=h((e,t=!1)=>{if(t&&"undefined"!=typeof window)return void(window.location.href=e);const n=P(e);if(!r.get("rsc.enabled"))return void C.current?.(n);const a=()=>C.current?.(n);Promise.race([Mc(r,void 0,void 0,n),new Promise(e=>setTimeout(e,1500))]).then(a,a)},[P,r]),D=k(()=>{const e=A.find(e=>e.pageId===M&&!e.isRaw);return e?{..._c(e.path).reduce((e,t)=>({...e,[t]:""}),{}),...Jn(O,"params",{})}:Jn(O,"params",{})},[A,O,M]),z=jl(D),R=jl(p),j=k(()=>new URLSearchParams(b.search),[b.search]),$=y?`${y}${b.pathname}${b.search}`:"";if(Mt(["navigation.urlSearchParams","navigation.routeParams","navigation.queryParams","navigation.hostname","navigation.origin","navigation.href","navigation.currentPageId","navigation.navigate"],[j,z,R,m,y,$,M,L],{raw:!0}),"notFound"===E.type)return u&&(u.status=404),"Not Found";if("accessDenied"===E.type)return u&&(u.status=403),"Access Denied";if("redirect"===E.type){const e=_l(c,{queryParams:p,routeParams:z,hostname:m,environment:o}),t=E.path?String(On(E.path,{variables:e},!1,!0)):"";if(t&&kc(t)){const e=new URL(t);return e.searchParams.has("redirect")||e.searchParams.set("redirect",(e=>e.href?e.href:`${e.protocol||"https:"}//${e.host||e.hostname}${e.pathname}${e.search}`)(b)),u?(u.redirect=e.toString(),null):(window.location.assign(e.toString()),null)}return u?(u.redirect=E.path??"",null):/* @__PURE__ */I(Ck,{to:E.path??"",replace:!0})}return e},hx=(e,{src:t,type:n,isMain:r},a=!1)=>{let i,o=`${e}/${t}`,s=btoa(o);return i="style"===n&&o.endsWith(".css")?{type:"link",id:s,params:{href:o,rel:"stylesheet",type:"text/css"},isMain:r}:{type:"script",id:s,params:{src:o,type:"text/javascript"},isMain:r},a&&delete i.isMain,i},mx=(e,t)=>{try{let{resource:n,settings:r,type:a}=e,{definition:{name:i="Plitzi's Demo Plugin",owner:o="Plitzi",verified:s=!1,license:l="MIT",website:c="https://plitzi.com",backgroundColor:u="#4422ee",icon:d="https://cdn.plitzi.com/resources/img/favicon.svg"},assets:p,assetsSettings:f,pluginSchema:h}=t;return Object.values(Jn(t,"pluginSchema",{})).reduce((e,m)=>{let{definition:g,builder:y,defaultStyle:b,attributes:v}=m,w=[];return g.type===a&&(w=Object.keys(rr(h,[a]))),{...e,[g.type]:{attributes:v,builder:y,defaultStyle:b,definition:g,market:{owner:o,verified:s,license:l,website:c,backgroundColor:u,icon:d,category:i},resource:n,isMain:g.type===a,manifest:t,type:a,settings:r,assetsSettings:Object.values(f).filter(({src:e})=>!!e&&[".css",".js",".mjs",".cjs"].some(t=>e.endsWith(t))).map(e=>hx(n,e,!0)),assets:Object.values(p).filter(({src:e})=>!!e&&[".css",".js",".mjs",".cjs"].some(t=>e.endsWith(t))).map(e=>hx(n,e)),subPlugins:w}}},{})}catch{return{}}},gx=async(e=[])=>{let t={};if(!Array.isArray(e))return t;let n=await(async e=>{if(!Array.isArray(e)||0===e.length)return{};let t=e.map(e=>(async e=>{try{let t=await fetch(e,{headers:{Accept:"application/json"}});return t.ok?await t.json():void 0}catch{return}})(e));return(await Promise.allSettled(t)).reduce((e,t)=>"fulfilled"===t.status&&t.value?{...e,[Jn(t.value,"root","")]:t.value}:e,{})})(e.filter(e=>e.resource).reduce((e,t)=>[...e,`${t.resource}/plugin-manifest.json`],[]));return e.forEach(e=>{let{type:r}=e,a=Jn(n,r);t={...t,...mx(e,a)}}),t},yx=class extends Error{failure;statusCode;constructor(e,t,n){super(e),this.name="GraphqlRequestError",this.failure=t,this.statusCode=n}},bx=e=>"object"==typeof e&&null!==e,vx=({children:e,server:t,revision:n,webKey:r="",webId:a,userKey:i="",instanceId:o,offlineMode:s=!1,offlineData:l,offlineDataType:c="json"})=>{const{environment:u,debugMode:d}=K(),p=Lt(),m=s&&!!l&&!!l.schema,y=k(()=>((e,t)=>({request:async(n,r)=>{let a;try{a=await fetch(e,{method:"POST",headers:{accept:"application/graphql-response+json, application/json;q=0.9","content-type":"application/json","sdk-version":"0.37.6",authorization:t?`Bearer ${t}`:""},body:JSON.stringify({query:n,variables:r})})}catch(tI){throw new yx(tI instanceof Error?tI.message:"Network request failed","network")}const i=(e=>{try{return JSON.parse(e)}catch{return}})(await a.text());if(!a.ok){const t=Hr(a.status,i);throw t&&Br({reason:t,url:e}),new yx(`Response not successful: Received status code ${a.status}`,"http",a.status)}const o=(e=>{const t=bx(e)?e.errors:void 0;return Array.isArray(t)?t.map(e=>bx(e)&&"string"==typeof e.message?e.message:"Unknown error"):[]})(i);if(o.length)throw new yx(o.join("\n"),"graphql",a.status);if(!bx(i)||!bx(i.data))throw new yx("The server answered without data","graphql",a.status);return i.data}}))(t.serverUrl,r),[t.serverUrl,r]),[b,v]=S(!(s&&l)),[w,x]=S(void 0),{components:T}=f(_r),[C,A]=S(()=>m&&"json"===c?{...l,plugins:{},segments:{}}:{plugins:{},segments:{}}),E=h(async(e,t)=>{try{return{success:!0,result:await y.request(ic[e],{environment:u,...t})}}catch(tI){return{success:!1,result:void 0,error:tI instanceof Error?tI:String(tI)}}},[y,u]),N=h(async(e,t,n=!0)=>{const r=ac[e];if(!r)return{success:!1,result:void 0,error:"Mutation Not Found"};try{return{success:!0,result:await y.request(r,n?{environment:u,...t}:t)}}catch(tI){return{success:!1,result:void 0,error:tI instanceof Error?tI:String(tI)}}},[y,u]),O=async()=>{let e=n;"number"==typeof n&&0!==n||(e=void 0);const t=await E("Init",{environment:u,revision:e});if(t.error)return v(!1),void x((e=>e instanceof yx?401===e.statusCode?"Access not authorized":"network"===e.failure?"Service not available":e.message:"string"==typeof e?e:e.message)(t.error));if(t.success&&t.result){const{Space:e}=Qn(t.result);if(!e)return x(/* @__PURE__ */_("span",{children:["Space not found, publish to ",
58
+ /* @__PURE__ */I("b",{children:Jn(l,`${M}.attributes.name`,M||"Unknown")})]}),{status:E.type,elementId:M})},[E.type,M,l]);const P=h(e=>((e,t,n)=>{let r=e[n];if(!r)return n;let{slug:a,default:i}=r.attributes;return"string"==typeof a?Cc(e,t,n,!0):i?"/":`/${n}`})(v.current,w.current,e),[]),L=h((e,t=!1)=>{if(t&&"undefined"!=typeof window)return void(window.location.href=e);const n=P(e);if(!r.get("rsc.enabled"))return void C.current?.(n);const a=()=>C.current?.(n);Promise.race([Mc(r,void 0,void 0,n),new Promise(e=>setTimeout(e,1500))]).then(a,a)},[P,r]),D=k(()=>{const e=A.find(e=>e.pageId===M&&!e.isRaw);return e?{..._c(e.path).reduce((e,t)=>({...e,[t]:""}),{}),...Jn(O,"params",{})}:Jn(O,"params",{})},[A,O,M]),z=jl(D),R=jl(p),j=k(()=>new URLSearchParams(b.search),[b.search]),$=y?`${y}${b.pathname}${b.search}`:"";if(Mt(["navigation.urlSearchParams","navigation.routeParams","navigation.queryParams","navigation.hostname","navigation.origin","navigation.href","navigation.currentPageId","navigation.navigate"],[j,z,R,m,y,$,M,L],{raw:!0}),"notFound"===E.type)return u&&(u.status=404),"Not Found";if("accessDenied"===E.type)return u&&(u.status=403),"Access Denied";if("redirect"===E.type){const e=_l(c,{queryParams:p,routeParams:z,hostname:m,environment:o}),t=E.path?String(On(E.path,{variables:e},!1,!0)):"";if(t&&kc(t)){const e=new URL(t);return e.searchParams.has("redirect")||e.searchParams.set("redirect",(e=>e.href?e.href:`${e.protocol||"https:"}//${e.host||e.hostname}${e.pathname}${e.search}`)(b)),u?(u.redirect=e.toString(),null):(window.location.assign(e.toString()),null)}return u?(u.redirect=E.path??"",null):/* @__PURE__ */I(Ck,{to:E.path??"",replace:!0})}return e},hx=(e,{src:t,type:n,isMain:r},a=!1)=>{let i,o=`${e}/${t}`,s=btoa(o);return i="style"===n&&o.endsWith(".css")?{type:"link",id:s,params:{href:o,rel:"stylesheet",type:"text/css"},isMain:r}:{type:"script",id:s,params:{src:o,type:"text/javascript"},isMain:r},a&&delete i.isMain,i},mx=(e,t)=>{try{let{resource:n,settings:r,type:a}=e,{definition:{name:i="Plitzi's Demo Plugin",owner:o="Plitzi",verified:s=!1,license:l="MIT",website:c="https://plitzi.com",backgroundColor:u="#4422ee",icon:d="https://cdn.plitzi.com/resources/img/favicon.svg"},assets:p,assetsSettings:f,pluginSchema:h}=t;return Object.values(Jn(t,"pluginSchema",{})).reduce((e,m)=>{let{definition:g,builder:y,defaultStyle:b,attributes:v}=m,w=[];return g.type===a&&(w=Object.keys(rr(h,[a]))),{...e,[g.type]:{attributes:v,builder:y,defaultStyle:b,definition:g,market:{owner:o,verified:s,license:l,website:c,backgroundColor:u,icon:d,category:i},resource:n,isMain:g.type===a,manifest:t,type:a,settings:r,assetsSettings:Object.values(f).filter(({src:e})=>!!e&&[".css",".js",".mjs",".cjs"].some(t=>e.endsWith(t))).map(e=>hx(n,e,!0)),assets:Object.values(p).filter(({src:e})=>!!e&&[".css",".js",".mjs",".cjs"].some(t=>e.endsWith(t))).map(e=>hx(n,e)),subPlugins:w}}},{})}catch{return{}}},gx=async(e=[])=>{let t={};if(!Array.isArray(e))return t;let n=await(async e=>{if(!Array.isArray(e)||0===e.length)return{};let t=e.map(e=>(async e=>{try{let t=await fetch(e,{headers:{Accept:"application/json"}});return t.ok?await t.json():void 0}catch{return}})(e));return(await Promise.allSettled(t)).reduce((e,t)=>"fulfilled"===t.status&&t.value?{...e,[Jn(t.value,"root","")]:t.value}:e,{})})(e.filter(e=>e.resource).reduce((e,t)=>[...e,`${t.resource}/plugin-manifest.json`],[]));return e.forEach(e=>{let{type:r}=e,a=Jn(n,r);t={...t,...mx(e,a)}}),t},yx=class extends Error{failure;statusCode;constructor(e,t,n){super(e),this.name="GraphqlRequestError",this.failure=t,this.statusCode=n}},bx=e=>"object"==typeof e&&null!==e,vx=({children:e,server:t,revision:n,webKey:r="",webId:a,userKey:i="",instanceId:o,offlineMode:s=!1,offlineData:l,offlineDataType:c="json"})=>{const{environment:u,debugMode:d}=K(),p=Lt(),m=s&&!!l&&!!l.schema,y=k(()=>((e,t)=>({request:async(n,r)=>{let a;try{a=await fetch(e,{method:"POST",headers:{accept:"application/graphql-response+json, application/json;q=0.9","content-type":"application/json","sdk-version":"0.37.7",authorization:t?`Bearer ${t}`:""},body:JSON.stringify({query:n,variables:r})})}catch(tI){throw new yx(tI instanceof Error?tI.message:"Network request failed","network")}const i=(e=>{try{return JSON.parse(e)}catch{return}})(await a.text());if(!a.ok){const t=Hr(a.status,i);throw t&&Br({reason:t,url:e}),new yx(`Response not successful: Received status code ${a.status}`,"http",a.status)}const o=(e=>{const t=bx(e)?e.errors:void 0;return Array.isArray(t)?t.map(e=>bx(e)&&"string"==typeof e.message?e.message:"Unknown error"):[]})(i);if(o.length)throw new yx(o.join("\n"),"graphql",a.status);if(!bx(i)||!bx(i.data))throw new yx("The server answered without data","graphql",a.status);return i.data}}))(t.serverUrl,r),[t.serverUrl,r]),[b,v]=S(!(s&&l)),[w,x]=S(void 0),{components:T}=f(_r),[C,A]=S(()=>m&&"json"===c?{...l,plugins:{},segments:{}}:{plugins:{},segments:{}}),E=h(async(e,t)=>{try{return{success:!0,result:await y.request(ic[e],{environment:u,...t})}}catch(tI){return{success:!1,result:void 0,error:tI instanceof Error?tI:String(tI)}}},[y,u]),N=h(async(e,t,n=!0)=>{const r=ac[e];if(!r)return{success:!1,result:void 0,error:"Mutation Not Found"};try{return{success:!0,result:await y.request(r,n?{environment:u,...t}:t)}}catch(tI){return{success:!1,result:void 0,error:tI instanceof Error?tI:String(tI)}}},[y,u]),O=async()=>{let e=n;"number"==typeof n&&0!==n||(e=void 0);const t=await E("Init",{environment:u,revision:e});if(t.error)return v(!1),void x((e=>e instanceof yx?401===e.statusCode?"Access not authorized":"network"===e.failure?"Service not available":e.message:"string"==typeof e?e:e.message)(t.error));if(t.success&&t.result){const{Space:e}=Qn(t.result);if(!e)return x(/* @__PURE__ */_("span",{children:["Space not found, publish to ",
59
59
  /* @__PURE__ */I("b",{children:u})," environment"]})),void v(!1);let n={};e.plugins.length>0&&(n=await gx(e.plugins.filter(e=>!T.current[e.type]))),p("render.overQuota",e.render?.overQuota??!1),A({schema:{...Ql,...e.schema,flat:e.schema.flat.reduce((e,t)=>({...e,[t.id]:t}),{})},plugins:n,style:e.style,segments:e.segments?.map(e=>({...e,schema:{...Jn(e,"schema"),flat:Jn(e,"schema.flat",[]).reduce((e,t)=>({...e,[t.id]:t}),{})}})).reduce((e,t)=>({...e,[t.identifier]:t}),{})??{}})}v(!1)};g(()=>{s&&l?m&&(async()=>{let e={};l?.plugins&&l.plugins.length>0&&(e=await gx(l.plugins.filter(e=>!T.current[e.type]))),A(t=>({...t,plugins:e})),v(!1)})():(v(e=>e||!0),O())},[m,s&&c,r,u,d]);const M=k(()=>({query:E,mutate:N,webKey:r,webId:a,server:t,environment:u,instanceId:o,userKey:i}),[E,N,r,a,t,u,o,i]);return w?/* @__PURE__ */I("div",{children:w}):b?null:/* @__PURE__ */I(nc,{value:M,children:/* @__PURE__ */I(rc,{value:C,children:e})})},wx=l({assets:{}});wx.displayName="PluginsContext";var kx=({children:e,plugins:t,sdkStylePath:n="./plitzi-sdk.css"})=>{const{renderMode:r}=K(),[a,i]=S({}),o=f(rc),s=k(()=>t||o.plugins,[t,o]),{components:l}=f(_r),c=h((e,t,n="")=>t?Jn(s,`${e}.settings.${t}`,n):Jn(s,`${e}.settings`,{}),[s]),u=h((e=[])=>{const t=e.reduce((e,t)=>{let n="";return n="script"===t.type?t.params.src:t.params.href,n?(n=btoa(n),{...e,[n]:{...t,key:n}}):e},{});0!==Object.keys(t).length&&i(e=>({...e,...t}))},[]),d=h((e=[])=>{const t=e.filter(e=>!function(e){return null==e||"number"!=typeof e&&"boolean"!=typeof e&&"function"!=typeof e&&"symbol"!=typeof e&&("string"==typeof e||Array.isArray(e)?0===e.length:e instanceof Map||e instanceof Set?0===e.size:"object"==typeof e&&0===Object.keys(e).length)}(e)).map(e=>btoa(e));i(e=>rr(e,t))},[]),p=k(()=>(e=>Object.values(e).reduce((e,t)=>({...e,...Jn(t,"assets",[]).filter(e=>"link"===e.type).reduce((e,t)=>({...e,[btoa(t.id)]:t}),{})}),{}))(s),[s]),m=k(()=>Object.keys(l.current).filter(e=>"local-custom"===l.current[e].origin).reduce((e,t)=>({...e,...Jn(l,`${t}.assets`,[]).reduce((e,n,r)=>({...e,[`${t}-${r}`]:{type:"link",id:`${t}-${r}`,params:n}}),{})}),{}),[l.current]),g=k(()=>{const e={};return"iframe"!==r&&"shadow"!==r||(e["static-99"]={type:"link",id:"static-99",params:{type:"text/css",href:n,rel:"stylesheet"}}),{...e,...m,...p,...a}},[m,p,a,r,n]),y=k(()=>({assets:g,getSettings:c,plugins:s,registerCustomAssets:u,unregisterCustomAssets:d}),[g,c,s,u,d]),b=k(()=>Object.values({...p,...a}).map((e,t)=>/* @__PURE__ */I(e.type,{...e.params},t)),[p,a]);/* @__PURE__ */
60
60
  return _(E,{children:[/* @__PURE__ */I(Ud,{children:("raw"===r||"widget"===r)&&b}),/* @__PURE__ */I(wx,{value:y,children:e})]})},xx=({children:e,schema:t})=>{const n=f(rc),r=k(()=>({...Ql,...t||n.schema}),[t,n.schema]);Mt("schema",r);const a=k(()=>Zn(Jn(r,"flat",{}),Jn(r,"pages",[])),[r.pages]);return Mt("pageDefinitions",a),e},Sx=l({});Sx.displayName="ContainerRootContext";var Tx=({className:e="",children:t,...n})=>{let r=x(null),a=h(()=>r.current instanceof HTMLElement?r.current.getRootNode():void 0,[r]),i=h(()=>a()instanceof ShadowRoot,[a]),o=k(()=>({getHost:a,rootRef:r,isRootShadow:i}),[a,r,i]);/* @__PURE__ */
61
61
  return I("div",{...n,ref:r,className:e,children:/* @__PURE__ */I(Sx,{value:o,children:t})})},Cx=l({});Cx.displayName="InteractionsContext";var Ax=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/,Ex=/^rgba?\(\s*(\d{1,3}%?\s*,\s*){2,3}\d{1,3}%?\s*\)$/,Ix=/^hsla?\(\s*\d{1,3}(deg|rad|turn)?\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%(\s*,\s*(0|0?\.\d+|1))?\s*\)$/,_x=/* @__PURE__ */new Set(["black","white","red","green","blue","yellow","cyan","magenta","orange","purple","brown","pink","gray","lime","teal","navy","silver","maroon","olive","aqua","fuchsia"]),Nx=({children:e,contentDidMount:t,contentDidDismount:n})=>(g(()=>(t?.(),()=>{n?.()}),[]),e),Ox=({ref:e,className:t="",ssrMode:r=!1,id:a="",css:i="",style:o,zoom:s=1,assets:l,viewport:c="width=device-width, initial-scale=1",children:u,contentDidMount:d,contentDidDismount:p,contentDidUpdate:f,onLoad:m})=>{t=ns("ContainerFrame",{className:t,componentKey:"root"});let y=x(null);v(e,()=>y.current,[y]);let[b,w]=S(!1),[k,T]=S(null),C=h((e,t,n)=>{let r=[...t.childNodes],a=n.getElementById("customStyle");Object.values(e).forEach(e=>{let i=n.createElement(e.type);e.id&&i.setAttribute("data-id",e.id),Object.keys(e.params).forEach(t=>{("link"===e.type||"script"===e.type)&&i.setAttribute(t,e.params[t])}),r.find(t=>"link"===e.type&&t.href===i.href||"script"===e.type&&t.src===i.src)||(t.insertBefore(i,a),r.push(i))})},[]),A=h((e,t)=>{let{head:n}=e,r=n.querySelectorAll('*:not([asset-static="true"])');Object.values(r).forEach(e=>{n.removeChild(e)}),t&&C(t,n,e)},[C]),[O]=S(()=>(e=>{if(!e)return"";let t=[];return Object.values(e).forEach(e=>{t.push(`<${e.type} ${Object.keys(e.params).map(t=>`${t}="${e.params[t]}"`).join(" ")}>`)}),t.join("")})(l)),M=h(()=>d?.(),[d]);g(()=>{b&&k&&A(k,l)},[b,l,k,A]);let P=h(()=>{let e=y.current&&k,t=y.current?.contentDocument===k;!e||t?b||(m?.(y.current),w(!0),T(y.current?.contentDocument)):T(y.current?.contentDocument)},[b,k,m]);return g(()=>{k&&(k.body.style.zoom=1===s?"":`${s}`)},[k,s]),/* @__PURE__ */_("iframe",{ref:y,className:t,title:"#",srcDoc:`<!DOCTYPE html><html><head>${O}</head><body></body></html>`,id:a,onLoad:P,style:o,children:[b&&k&&N(/* @__PURE__ */_(E,{children:[
@@ -147,4 +147,4 @@ return I(Tx,{className:U(e,t&&"system"!==r&&r),children:n})},fI=/* @__PURE__ */$
147
147
  return I(_r,{value:p,children:n})},xI=e=>({apiServer:"https://api.plitzi.com",ssrServer:"https://ssr.plitzi.com",serverUrl:"https://server.plitzi.com",websocketServer:"wss://server.plitzi.com",subscriptionServer:"wss://server.plitzi.com/subscriptions",...e}),SI={Button:ss,ContentEditable:op,Input:hs,Heading:lp,ContainerResizable:Xd,ContainerCollapsable:Kd,Text:nw,Markdown:Zv,ContainerTabs:ap},TI=({className:e="min-h-screen",children:t,webKey:r="",server:i,renderMode:o=Y.renderMode,routing:s="browser",debugMode:l=!1,themeScope:c="document",theme:d,state:p,...f})=>{const m=k(()=>function(e){if(!e)return 0;let t={};try{let n=e.split(".")[1],r=typeof window<"u"?window.atob(n):Buffer.from(n,"base64").toString();t=JSON.parse(r)}catch{return 0}return Jn(t,"data.spaceId",0)}(r),[r]),y=x(p).current,b=k(()=>({segments:{},runtime:{sources:{},state:y??{}},render:Y}),[y]),v=k(()=>(e=>{let t=e?.split(":")[1];return t?`plitzi_debug_${t}`:"plitzi_debug"})("undefined"==typeof window?void 0:window.location.host),[]),[w,T]=S(()=>(e=>{if("undefined"==typeof document)return!0;for(const t of document.cookie.split(";")){const n=t.indexOf("=");if(-1!==n&&t.slice(0,n).trim()===e)return"false"!==decodeURIComponent(t.slice(n+1).trim())}return!0})(v)),C=l&&w,A=k(()=>xI(i),[i]);g(()=>{},[]);const E=h(()=>{const e=!w;((e,t)=>{"undefined"!=typeof document&&(document.cookie=`${e}=${JSON.stringify(t)}; path=/; max-age=31536000; samesite=lax`)})(v,e),T(e)},[v,w]);(({authorized:e,onToggle:t})=>{const n=h(e=>{var n;e.shiftKey&&"F12"===e.key?t():!e.shiftKey||!e.altKey||"KeyD"!==e.code||(n=e.target)instanceof HTMLElement&&(n.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(n.tagName))||(e.preventDefault(),t())},[t]);g(()=>{if(e)return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,n])})({authorized:l,onToggle:E}),g(()=>{},[l,w,v]),g(()=>{if(C)return window.plitziTracing={lastCommitId:Mu.lastCommitId,commitsSince:Mu.commitsSince},()=>{delete window.plitziTracing}},[C]),g(()=>{f.isHydrating&&Mu.setHydrated()},[f.isHydrating]);const _=k(()=>{const e={};return n.forEach(t,t=>{if(!u(t))return;if(t.type!==vA)return;const{renderType:n,component:r,assets:a=[],...i}=t.props;if(!n||!r)return;const o=r;o.type=n,o.assets=a,o.extraProps=i,e[n]=o}),e},[t]);"undefined"==typeof window&&A.requestUrl;const N="widget"===o?a:"undefined"==typeof window?tx:"memory"===s?Tk:Yk,O="widget"===o?{}:{..."memory"===s&&"undefined"!=typeof window?{}:{basename:Jn(A,"basePath","/"),location:"undefined"==typeof window?A.requestUrl??"":void 0}};/* @__PURE__ */
148
148
  return I(kt,{value:b,middlewares:[fe(Pl("sdk")),Gc(m),...C?[()=>({onChange:e=>Mu.recordStoreChange(e)}),ue({shouldRecord:e=>!e?.startsWith("runtime.elements")&&!e?.startsWith("rsc")&&!e?.startsWith("theme")})]:[]],children:/* @__PURE__ */I(dI,{scope:c,theme:d,children:/* @__PURE__ */I(tw,{components:SI,children:/* @__PURE__ */I(pI,{scoped:"container"===c,className:U("plitzi-sdk flex",e,{"sdk-debug-mode":C}),children:/* @__PURE__ */I(Fd,{children:/* @__PURE__ */I(N,{...O,children:/* @__PURE__ */I(kI,{localCustomComponents:_,localComponents:AI,children:/* @__PURE__ */I(uI,{server:A,webKey:r,renderMode:o,debugMode:C,webId:m,...f})})})})})})})})},CI=Lu(({ref:e,className:t,spaceKey:n,environment:r="main"})=>{const{settings:{previewMode:a},contexts:{NetworkContext:i}}=zl(),{server:o}=f(i);/* @__PURE__ */
149
149
  return I(sd,{ref:e,className:U("plitzi-component__plitzi-sdk",t,{"with__plitzi-sdk":!a}),children:n&&/* @__PURE__ */I(TI,{webKey:n,environment:r,renderMode:"widget",server:o,className:"h-full w-full"})})}),AI={plitziSdk:Object.assign(CI,{type:"plitziSdk",content:{attributes:{spaceId:"",spaceKey:"",environment:"main"},definition:{label:"Plitzi Sdk",type:"plitziSdk",bindings:{},styleSelectors:{base:""},initialState:{visibility:!0}},builder:{canDelete:!0,canSelect:!0,canDragDrop:!0,canMove:!0,canTemplate:!0,itemsAllowed:[],itemsNotAllowed:[]},market:{category:"advanced",owner:"Plitzi",verified:!0,license:"MIT",website:"https://plitzi.com",backgroundColor:"#4422ee",icon:/* @__PURE__ */I(q,{})},defaultStyle:{name:"Plitzi Sdk",displayMode:"desktop",style:{base:{default:{}}}},settings:{}}})};Promise.resolve({ });function EI(e,t={},n={},r=!1,a=!1){const{actionRuns:i,styleCacheInDocument:o,...s}=(e=>{if(e.analytics||e.offlineMode||!e.webKey)return e;const{apiServer:t}=xI(e.server);return t?{...e,analytics:{endpoint:`${t.replace(/\/+$/,"")}/v1/collect`,key:e.webKey}}:e})(t),l="undefined"!=typeof document?document.getElementById(e):void 0,c=o?((e,t)=>{const{offlineData:n}=e;if(!n||!t)return e;const r=(e=>{let t=e.querySelector('style[data-id="plitzi-runtime-style"]')?.textContent??"",n=t.indexOf(Jl),r=t.indexOf(Xl,n);if(!(n<0||r<0))return t.slice(n+22,r)})(t);return void 0===r?e:{...e,offlineData:{...n,style:{...n.style,cache:r}}}})(s,l):s,u=c.debugMode??r;u&&i?.length&&it(i);const d=({isHydrating:e=!1})=>{const[t,r]=S(!e);g(()=>r(!0),[]);const a=Object.keys(n).filter(e=>t||!n[e].clientOnly);u||(()=>{if(typeof window>"u")return;let e=()=>{},t=window.__REACT_DEVTOOLS_GLOBAL_HOOK__;"object"==typeof t&&Object.keys(t).forEach(n=>{let r=t[n];t[n]="function"==typeof r?e:null})})();const i=h(e=>{oI=e},[]),o=h(e=>{sI=e},[]);/* @__PURE__ */
150
- return I(TI,{...c,debugMode:u,isHydrating:e,onInitStateManager:i,onInitEventBridge:o,children:a.filter(e=>!!n[e].component).map(e=>/* @__PURE__ */I(TA.Plugin,{renderType:e,component:n[e].component,...n[e].props},e))})};if(!l)return;const p=a?A(l,/* @__PURE__ */I(d,{isHydrating:!0})):C(l);return a||p.render(/* @__PURE__ */I(d,{})),{unmount:()=>p.unmount()}}var II=({debugMode:e=!1,isHydrating:t=!1,children:n,webKey:r="",environment:a="main",renderMode:i=Y.renderMode,...o})=>/* @__PURE__ */I(TI,{...o,isHydrating:t,renderMode:i,debugMode:e,webKey:r,environment:a,children:n});II.Plugin=TA.Plugin;var _I=zl,NI="0.37.6",OI=()=>oI,MI=()=>sI;export{Ze as A,ir as C,_r as ComponentContext,kI as ComponentProvider,lt as D,ht as E,vI as JsxManager,le as M,U as N,rt as O,Rl as PlitziServiceProvider,Bx as PluginManager,Mr as PluginRemote,eC as ReplicaProvider,sd as RootElement,Ar as S,Et as T,xi as _,wx as a,ri as b,ip as c,Mu as d,II as default,uu as f,ls as g,MI as getEventBridge,OI as getStateManager,ms as h,vT as i,Ie as j,Xe as k,Qd as l,Nl as m,QA as n,Vg as o,wc as p,eE as r,EI as render,qg as s,AI as sdkComponents,oE as t,cx as track,Jd as u,FT as useChannel,Du as useElement,_I as usePlitziServiceContext,hT as useRscData,Pc as useRscRefresh,Ot as useStore,ii as v,NI as version,Jn as w,Lu as withElement,Nr as x,ai as y};
150
+ return I(TI,{...c,debugMode:u,isHydrating:e,onInitStateManager:i,onInitEventBridge:o,children:a.filter(e=>!!n[e].component).map(e=>/* @__PURE__ */I(TA.Plugin,{renderType:e,component:n[e].component,...n[e].props},e))})};if(!l)return;const p=a?A(l,/* @__PURE__ */I(d,{isHydrating:!0})):C(l);return a||p.render(/* @__PURE__ */I(d,{})),{unmount:()=>p.unmount()}}var II=({debugMode:e=!1,isHydrating:t=!1,children:n,webKey:r="",environment:a="main",renderMode:i=Y.renderMode,...o})=>/* @__PURE__ */I(TI,{...o,isHydrating:t,renderMode:i,debugMode:e,webKey:r,environment:a,children:n});II.Plugin=TA.Plugin;var _I=zl,NI="0.37.7",OI=()=>oI,MI=()=>sI;export{Ze as A,ir as C,_r as ComponentContext,kI as ComponentProvider,lt as D,ht as E,vI as JsxManager,le as M,U as N,rt as O,Rl as PlitziServiceProvider,Bx as PluginManager,Mr as PluginRemote,eC as ReplicaProvider,sd as RootElement,Ar as S,Et as T,xi as _,wx as a,ri as b,ip as c,Mu as d,II as default,uu as f,ls as g,MI as getEventBridge,OI as getStateManager,ms as h,vT as i,Ie as j,Xe as k,Qd as l,Nl as m,QA as n,Vg as o,wc as p,eE as r,EI as render,qg as s,AI as sdkComponents,oE as t,cx as track,Jd as u,FT as useChannel,Du as useElement,_I as usePlitziServiceContext,hT as useRscData,Pc as useRscRefresh,Ot as useStore,ii as v,NI as version,Jn as w,Lu as withElement,Nr as x,ai as y};
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/plitzi-sdk",
3
- "version": "0.37.6",
3
+ "version": "0.37.7",
4
4
  "homepage": "./",
5
5
  "license": "AGPL-3.0",
6
6
  "files": [
@@ -32,17 +32,17 @@
32
32
  "@fortawesome/fontawesome-free": "^7.3.1",
33
33
  "@plitzi/nexus": "^1.3.1",
34
34
  "@plitzi/plitzi-ui": "^1.6.24",
35
- "@plitzi/sdk-auth": "0.37.6",
36
- "@plitzi/sdk-dev-tools": "0.37.6",
37
- "@plitzi/sdk-elements": "0.37.6",
38
- "@plitzi/sdk-event-bridge": "0.37.6",
39
- "@plitzi/sdk-interactions": "0.37.6",
40
- "@plitzi/sdk-navigation": "0.37.6",
41
- "@plitzi/sdk-plugins": "0.37.6",
42
- "@plitzi/sdk-schema": "0.37.6",
43
- "@plitzi/sdk-shared": "0.37.6",
44
- "@plitzi/sdk-style": "0.37.6",
45
- "@plitzi/sdk-variables": "0.37.6",
35
+ "@plitzi/sdk-auth": "0.37.7",
36
+ "@plitzi/sdk-dev-tools": "0.37.7",
37
+ "@plitzi/sdk-elements": "0.37.7",
38
+ "@plitzi/sdk-event-bridge": "0.37.7",
39
+ "@plitzi/sdk-interactions": "0.37.7",
40
+ "@plitzi/sdk-navigation": "0.37.7",
41
+ "@plitzi/sdk-plugins": "0.37.7",
42
+ "@plitzi/sdk-schema": "0.37.7",
43
+ "@plitzi/sdk-shared": "0.37.7",
44
+ "@plitzi/sdk-style": "0.37.7",
45
+ "@plitzi/sdk-variables": "0.37.7",
46
46
  "clsx": "^2.1.1",
47
47
  "immer": "^11.1.18",
48
48
  "react-router-dom": "^7.18.4"