codicent-app-sdk 0.3.47 → 0.3.49

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.
@@ -1 +1 @@
1
- {"version":3,"file":"FileThumbnail.d.ts","sourceRoot":"","sources":["../../../src/components/FileThumbnail.tsx"],"names":[],"mappings":"AA6EA,UAAU,kBAAkB;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsCtD,CAAC"}
1
+ {"version":3,"file":"FileThumbnail.d.ts","sourceRoot":"","sources":["../../../src/components/FileThumbnail.tsx"],"names":[],"mappings":"AA6EA,UAAU,kBAAkB;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA2CtD,CAAC"}
@@ -1 +1 @@
1
- "use strict";var e=require("react/jsx-runtime"),o=require("../node_modules/@griffel/react/makeStyles.esm.js"),t=require("../node_modules/@fluentui/react-button/lib/components/Button/Button.js"),i=require("../node_modules/@fluentui/react-image/lib/components/Image/Image.js"),r=require("../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js"),n=require("../node_modules/@fluentui/tokens/lib/tokens.js"),l=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js");const s=o.makeStyles({thumbnail:{width:"64px",height:"64px",borderRadius:n.tokens.borderRadiusMedium,backgroundColor:n.tokens.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:n.tokens.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:n.tokens.colorNeutralForegroundInverted,padding:"4px",fontSize:n.tokens.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:n.tokens.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:n.tokens.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:n.tokens.colorNeutralBackground1Hover}}});exports.FileThumbnail=({file:o,getImageUrl:n,onClick:a,onDelete:u,thumbnailSize:c})=>{const d=s();return e.jsxs("div",{className:d.thumbnail,onClick:a,title:o.filename,children:[u&&e.jsx(t.Button,{className:d.deleteButton,icon:e.jsx(l.DismissRegular,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),o.contentType&&o.contentType.startsWith("image")?e.jsx(i.Image,{className:d.image,src:`${n(o.id,c||200)}&width=${c}`,alt:o.filename}):e.jsx(r.DocumentData32Regular,{className:d.fileIcon}),e.jsx("div",{className:d.fileName,children:o.filename})]})};
1
+ "use strict";var e=require("react/jsx-runtime"),o=require("../node_modules/@griffel/react/makeStyles.esm.js"),t=require("../node_modules/@fluentui/react-button/lib/components/Button/Button.js"),i=require("../node_modules/@fluentui/react-image/lib/components/Image/Image.js"),r=require("../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js"),n=require("../node_modules/@fluentui/tokens/lib/tokens.js"),l=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js");const s=o.makeStyles({thumbnail:{width:"64px",height:"64px",borderRadius:n.tokens.borderRadiusMedium,backgroundColor:n.tokens.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:n.tokens.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:n.tokens.colorNeutralForegroundInverted,padding:"4px",fontSize:n.tokens.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:n.tokens.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:n.tokens.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:n.tokens.colorNeutralBackground1Hover}}});exports.FileThumbnail=({file:o,getImageUrl:n,onClick:a,onDelete:u,thumbnailSize:c=64})=>{const d=s();return e.jsxs("div",{className:d.thumbnail,style:{width:`${c}px`,height:`${c}px`},onClick:a,title:o.filename,children:[u&&e.jsx(t.Button,{className:d.deleteButton,icon:e.jsx(l.DismissRegular,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),o.contentType&&o.contentType.startsWith("image")?e.jsx(i.Image,{className:d.image,src:`${n(o.id,c||200)}&width=${c}`,alt:o.filename}):e.jsx(r.DocumentData32Regular,{className:d.fileIcon}),e.jsx("div",{className:d.fileName,children:o.filename})]})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C,KAAK,EAAE,MAAM,KAAK,IAAI,oBAErG,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../_virtual/index.js"),e=require("../config/index.js");class i extends t.distExports.StateMachine{constructor(t,e){super(),this.context={isAuthenticated:void 0,hasAccess:!1,error:null,errorType:void 0,apps:[],hasApps:!1,appsLoaded:!1},this.currentStateName="",this.resetContext(),this.service=t,this.onStateChange=e,this.allStates=this.initializeStateMachine()}resetContext(){this.context={isAuthenticated:!1,isRegistered:void 0,hasValidPurchase:void 0,hasAccess:!1,selectedApp:localStorage.getItem("selectedApp")||void 0,error:null,errorType:void 0,accessToken:void 0,nickname:void 0,apps:[],hasApps:!1,appsLoaded:!1},e.getConfigValue("APP_PREFIX")&&this.context.selectedApp&&!this.context.selectedApp.startsWith(e.getConfigValue("APP_PREFIX"))?this.context.selectedApp=void 0:this.context.selectedApp}update(){super.update()}handlePurchase(){window.location.href="./#/purchase"}initializeStateMachine(){const i=new t.distExports.State,n=new t.distExports.State({entering:()=>{this.context.selectedApp&&!this.service.codicent&&(this.service.codicent=this.context.selectedApp)}}),s=new t.distExports.State,o=new t.distExports.State,r=new t.distExports.State({entering:()=>{this.service.findUsername().then((t=>{t?this.service.nicknameExists(t).then((e=>{e?this.updateContext({error:"Användarnamnet finns redan.",errorType:"UsernameExists"}):this.service.registerUser(t,this.context.user.email,this.context.user.sub,this.context.accessToken).then((()=>{this.service.setToken(this.context.accessToken),this.updateContext({nickname:t,isRegistered:!0})})).catch((t=>{console.warn("Failed to register account",t),this.updateContext({error:"Ett fel uppstod vid registrering. Försök igen senare.",errorType:"ErrorRegistering"})}))})).catch((t=>{console.warn("Failed to check username",t),this.updateContext({error:"Ett fel uppstod vid kontroll av användarnamn.",errorType:"ErrorCheckingUsername"})})):this.updateContext({error:"Användarnamn kunde inte hittas.",errorType:"NoUsernameFound"})})).catch((t=>{console.warn("Failed to find username",t),this.updateContext({error:"Ett fel uppstod vid sökning av användarnamn.",errorType:"ErrorFindingUsername"})}))}}),a=new t.distExports.State,c=new t.distExports.State({entering:()=>{this.checkPurchase()}}),d=new t.distExports.State({entering:()=>{this.handlePurchase()}}),h=new t.distExports.State({entering:()=>{this.getApps()}}),p=new t.distExports.State,l=new t.distExports.State,g=new t.distExports.State({}),x=new t.distExports.State,u=new t.distExports.State({entering:()=>{this.context.nickname&&(localStorage.setItem("nickname",this.context.nickname),this.service.getUserInfo(this.context.nickname).then((t=>{const e=t?.name||t?.nickname||"";this.updateContext({name:e})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorLoadingUser"}))))}}),A=new t.distExports.State({entering:()=>{localStorage.removeItem("selectedApp"),localStorage.removeItem("nickname"),localStorage.removeItem("codicent"),sessionStorage.clear(),this.updateContext({isAuthenticated:!1,isRegistered:void 0,apps:[],hasApps:!1,selectedApp:void 0,accessToken:void 0,user:void 0}),setTimeout((()=>{this.current=this.allStates.initial}),1e3)}}),T=new t.distExports.State({entering:()=>{this.service.createApp().then((t=>{t?(this.service.codicent=t,this.updateContext({selectedApp:t,apps:[...this.context.apps||[],{id:t,title:t,logo:""}]})):this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})})).catch((t=>{console.warn("Error creating app",t),this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})}))}}),C=new t.distExports.State({entering:()=>{this.service.loginUser(this.context.user.sub,this.context.accessToken).then((t=>{null===t?this.updateContext({isRegistered:!1}):""===t?this.updateContext({isRegistered:!1,error:"Kunde inte logga in hos Codicent.",errorType:"CodicentLoginFailed"}):(this.service.setToken(this.context.accessToken),this.service.getNickname().then((t=>{t?this.updateContext({isRegistered:!0,nickname:t}):this.updateContext({error:"Kunde inte hitta användarnamn.",errorType:"ErrorFindingUsername"})})).catch((()=>{this.updateContext({error:"Fel vid hämtning av användarnamn.",errorType:"ErrorFindingUsername"})})))})).catch((()=>{this.updateContext({isRegistered:!1,error:"Fel vid inloggning hos Codicent.",errorType:"CodicentLoginError"})}))}}),E=new t.distExports.State({entering:()=>{this.service.setToken(e.getConfigValue("ANONYMOUS_TOKEN")),this.service.codicent=e.getConfigValue("ANONYMOUS_CODICENT")||e.getConfigValue("APP_NAME")||""}});i.addTransition(n,{condition:()=>!0}),n.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),n.addTransition(x,{condition:()=>Boolean(this.context.error)}),n.addTransition(E,{condition:()=>!0===this.context.isAnonymous&&!!e.getConfigValue("ANONYMOUS_TOKEN")}),n.addTransition(s,{condition:()=>!1===this.context.isAuthenticated}),s.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),s.addTransition(x,{condition:()=>!!this.context.error}),o.addTransition(C,{}),C.addTransition(r,{condition:()=>!1===this.context.isRegistered}),C.addTransition(a,{condition:()=>!0===this.context.isRegistered}),C.addTransition(x,{condition:()=>!!this.context.error}),a.addTransition(u,{condition:()=>!!this.context.nickname}),a.addTransition(x,{condition:()=>!this.context.nickname,action:()=>this.updateContext({error:"Missing nickname after registration",errorType:"ErrorLoadingUser"})}),c.addTransition(d,{condition:()=>!1===this.context.hasValidPurchase}),c.addTransition(h,{condition:()=>!0===this.context.hasValidPurchase}),h.addTransition(x,{condition:()=>!!this.context.error,action:()=>console.log("getting apps -> error")}),h.addTransition(p,{condition:()=>!!e.getConfigValue("APP_NAME")&&this.context.hasApps}),h.addTransition(T,{condition:()=>!e.getConfigValue("APP_NAME")&&this.context.appsLoaded&&0===this.context.apps.length,action:()=>this.updateContext({selectedApp:void 0})}),h.addTransition(p,{condition:()=>!e.getConfigValue("APP_NAME")&&this.context.hasApps&&this.context.apps.length>0}),T.addTransition(p,{condition:()=>!!this.context.selectedApp}),T.addTransition(x,{condition:()=>!!this.context.error}),p.addTransition(g,{condition:()=>!e.getConfigValue("APP_NAME")&&this.context.apps.some((t=>t.id===this.context.selectedApp)),action:()=>{this.service.codicent=this.context.selectedApp||"",localStorage.setItem("selectedApp",this.context.selectedApp||"")}}),p.addTransition(g,{condition:()=>!e.getConfigValue("APP_NAME")&&!this.context.selectedApp,action:()=>{const t=this.context.apps[0].id;this.service.codicent=t,localStorage.setItem("selectedApp",t),this.updateContext({selectedApp:t})}}),p.addTransition(g,{condition:()=>this.context.apps.some((t=>t.id===e.getConfigValue("APP_NAME"))),action:()=>{this.service.codicent=e.getConfigValue("APP_NAME"),this.updateContext({selectedApp:e.getConfigValue("APP_NAME")})}}),p.addTransition(l,{condition:()=>!this.context.apps.some((t=>t.id===this.context.selectedApp||t.id===e.getConfigValue("APP_NAME"))),action:()=>console.log("checking access -> no access",this.context.apps,this.context.selectedApp,e.getConfigValue("APP_NAME"))}),g.addTransition(u,{condition:()=>!!localStorage.getItem("selectedApp")&&localStorage.getItem("selectedApp")!==this.context.selectedApp,action:()=>{this.service.codicent=localStorage.getItem("selectedApp")||"",this.updateContext({selectedApp:localStorage.getItem("selectedApp")||void 0})}}),r.addTransition(a,{condition:()=>!0===this.context.isRegistered}),r.addTransition(x,{condition:()=>!!this.context.error}),d.addTransition(c,{condition:()=>void 0===this.context.hasValidPurchase,action:()=>{window.history.replaceState({},document.title,window.location.pathname),this.checkPurchase()}}),[n,h,c,C,r].forEach((t=>{t.addTransition(x,{condition:()=>this.context.error?.includes("network")||this.context.error?.includes("connectivity")||!1}),t.addTransition(x,{condition:()=>!!this.context.error})})),[o,a,g,l].forEach((t=>{t.addTransition(A,{condition:()=>!1===this.context.isAuthenticated})})),a.addTransition(u,{condition:()=>!this.context.user&&!!this.context.nickname}),u.addTransition(c,{condition:()=>!!this.context.name&&e.getConfigValue("SUBSCRIPTION_NEEDED")}),u.addTransition(h,{condition:()=>!!this.context.name&&!e.getConfigValue("SUBSCRIPTION_NEEDED")}),x.addTransition(c,{condition:()=>!this.context.error&&"ErrorCheckingPurchase"!==this.context.errorType}),x.addTransition(h,{condition:()=>!this.context.error&&"ErrorGettingApps"!==this.context.errorType}),x.addTransition(p,{condition:()=>!this.context.error&&"ErrorCheckingAccess"!==this.context.errorType}),x.addTransition(u,{condition:()=>!this.context.error&&"ErrorLoadingUser"!==this.context.errorType}),x.addTransition(T,{condition:()=>!this.context.error&&"ErrorCreatingApp"!==this.context.errorType}),x.addTransition(C,{condition:()=>!this.context.error&&"CodicentLoginFailed"!==this.context.errorType}),A.addTransition(i,{condition:()=>!this.context.isAuthenticated&&!this.context.accessToken});const S={initial:i,authenticating:n,notAuthenticated:s,authenticated:o,checkingCodicentAccess:C,registering:r,registered:a,checkingPurchase:c,needsPurchase:d,gettingApps:h,creatingApp:T,checkingAccess:p,noAccess:l,error:x,loadingUser:u,loggingOut:A,hasAccess:g,anonymous:E};return this.states.push(...Object.values(S)),S}get error(){return this.context.error}checkPurchase(){this.service.checkSubscriptionStatus().then((t=>this.updateContext({hasValidPurchase:"active"===t}))).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorCheckingPurchase"})))}getApps(){this.service.getApps().then((t=>{if(null===t)throw new Error("Failed to fetch apps.");e.getConfigValue("APP_PREFIX")&&(t=t.filter((t=>t.id.startsWith(e.getConfigValue("APP_PREFIX"))))),this.updateContext({apps:t,hasApps:!0,appsLoaded:!0}),this.context.selectedApp&&!t.some((t=>t.id===this.context.selectedApp))&&this.updateContext({selectedApp:void 0})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorGettingApps"})))}setUser(t){this.context.user=t}getContext(){return{...this.context}}updateContext(t){this.context={...this.context,...t}}getCurrentStateName(){const t=Object.entries(this.allStates).find((([t,e])=>e===this.current));return t?t[0]:""}logout(){localStorage.clear(),sessionStorage.clear(),this.resetContext()}setSelectedApp(t){localStorage.setItem("selectedApp",t),this.update()}isBusy(){return this.current===this.allStates.gettingApps||this.current===this.allStates.checkingPurchase||this.current===this.allStates.checkingAccess||this.current===this.allStates.checkingCodicentAccess||this.current===this.allStates.registering||this.current===this.allStates.loadingUser||this.current===this.allStates.creatingApp||this.current===this.allStates.loggingOut}}exports.AppStateMachine=i,exports.createAppStateMachine=(t,e)=>new i(t,e),exports.default=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../_virtual/index.js"),e=require("../config/index.js");class i extends t.distExports.StateMachine{constructor(t,e){super(),this.context={isAuthenticated:void 0,hasAccess:!1,error:null,errorType:void 0,apps:[],hasApps:!1,appsLoaded:!1},this.currentStateName="",this.resetContext(),this.service=t,this.onStateChange=e,this.allStates=this.initializeStateMachine()}resetContext(){this.context={isAuthenticated:!1,isRegistered:void 0,hasValidPurchase:void 0,hasAccess:!1,selectedApp:localStorage.getItem("selectedApp")||void 0,error:null,errorType:void 0,accessToken:void 0,nickname:void 0,apps:[],hasApps:!1,appsLoaded:!1},e.getConfigValue("APP_PREFIX")&&this.context.selectedApp&&!this.context.selectedApp.startsWith(e.getConfigValue("APP_PREFIX"))?this.context.selectedApp=void 0:this.context.selectedApp}update(){super.update()}handlePurchase(){window.location.href="./#/purchase"}initializeStateMachine(){const i=new t.distExports.State,n=new t.distExports.State({entering:()=>{this.context.selectedApp&&!this.service.codicent&&(this.service.codicent=this.context.selectedApp)}}),s=new t.distExports.State,o=new t.distExports.State,r=new t.distExports.State({entering:()=>{this.service.findUsername().then((t=>{t?this.service.nicknameExists(t).then((e=>{e?this.updateContext({error:"Användarnamnet finns redan.",errorType:"UsernameExists"}):this.service.registerUser(t,this.context.user.email,this.context.user.sub,this.context.accessToken).then((()=>{this.service.setToken(this.context.accessToken),this.updateContext({nickname:t,isRegistered:!0})})).catch((t=>{console.warn("Failed to register account",t),this.updateContext({error:"Ett fel uppstod vid registrering. Försök igen senare.",errorType:"ErrorRegistering"})}))})).catch((t=>{console.warn("Failed to check username",t),this.updateContext({error:"Ett fel uppstod vid kontroll av användarnamn.",errorType:"ErrorCheckingUsername"})})):this.updateContext({error:"Användarnamn kunde inte hittas.",errorType:"NoUsernameFound"})})).catch((t=>{console.warn("Failed to find username",t),this.updateContext({error:"Ett fel uppstod vid sökning av användarnamn.",errorType:"ErrorFindingUsername"})}))}}),a=new t.distExports.State,c=new t.distExports.State({entering:()=>{this.checkPurchase()}}),d=new t.distExports.State({entering:()=>{this.handlePurchase()}}),h=new t.distExports.State({entering:()=>{this.getApps()}}),p=new t.distExports.State,l=new t.distExports.State,g=new t.distExports.State({}),x=new t.distExports.State,u=new t.distExports.State({entering:()=>{this.context.nickname&&(localStorage.setItem("nickname",this.context.nickname),this.service.getUserInfo(this.context.nickname).then((t=>{const e=t?.name||t?.nickname||"";this.updateContext({name:e})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorLoadingUser"}))))}}),A=new t.distExports.State({entering:()=>{localStorage.removeItem("selectedApp"),localStorage.removeItem("nickname"),localStorage.removeItem("codicent"),sessionStorage.clear(),this.updateContext({isAuthenticated:!1,isRegistered:void 0,apps:[],hasApps:!1,selectedApp:void 0,accessToken:void 0,user:void 0}),setTimeout((()=>{this.current=this.allStates.initial}),1e3)}}),T=new t.distExports.State({entering:()=>{this.service.createApp().then((t=>{t?(this.service.codicent=t,this.updateContext({selectedApp:t,apps:[...this.context.apps||[],{id:t,title:t,logo:""}]})):this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})})).catch((t=>{console.warn("Error creating app",t),this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})}))}}),C=new t.distExports.State({entering:()=>{this.service.loginUser(this.context.user.sub,this.context.accessToken).then((t=>{null===t?this.updateContext({isRegistered:!1}):""===t?this.updateContext({isRegistered:!1,error:"Kunde inte logga in hos Codicent.",errorType:"CodicentLoginFailed"}):(this.service.setToken(this.context.accessToken),this.service.getNickname().then((t=>{t?this.updateContext({isRegistered:!0,nickname:t}):this.updateContext({error:"Kunde inte hitta användarnamn.",errorType:"ErrorFindingUsername"})})).catch((()=>{this.updateContext({error:"Fel vid hämtning av användarnamn.",errorType:"ErrorFindingUsername"})})))})).catch((()=>{this.updateContext({isRegistered:!1,error:"Fel vid inloggning hos Codicent.",errorType:"CodicentLoginError"})}))}}),E=new t.distExports.State({entering:()=>{this.service.setToken(e.getConfigValue("ANONYMOUS_TOKEN")),this.service.codicent=e.getConfigValue("ANONYMOUS_CODICENT")||e.getConfigValue("APP_NAME")||""}});i.addTransition(n,{condition:()=>!0}),n.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),n.addTransition(x,{condition:()=>Boolean(this.context.error)}),n.addTransition(E,{condition:()=>!0===this.context.isAnonymous&&!!e.getConfigValue("ANONYMOUS_TOKEN")}),n.addTransition(s,{condition:()=>!1===this.context.isAuthenticated}),s.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),s.addTransition(x,{condition:()=>!!this.context.error}),o.addTransition(C,{}),C.addTransition(r,{condition:()=>!1===this.context.isRegistered}),C.addTransition(a,{condition:()=>!0===this.context.isRegistered}),C.addTransition(x,{condition:()=>!!this.context.error}),a.addTransition(u,{condition:()=>!!this.context.nickname}),a.addTransition(x,{condition:()=>!this.context.nickname,action:()=>this.updateContext({error:"Missing nickname after registration",errorType:"ErrorLoadingUser"})}),c.addTransition(d,{condition:()=>!1===this.context.hasValidPurchase}),c.addTransition(h,{condition:()=>!0===this.context.hasValidPurchase}),h.addTransition(x,{condition:()=>!!this.context.error,action:()=>console.log("getting apps -> error")}),h.addTransition(p,{condition:()=>!!e.getConfigValue("APP_NAME")&&this.context.hasApps}),h.addTransition(T,{condition:()=>!e.getConfigValue("APP_NAME")&&this.context.appsLoaded&&0===this.context.apps.length,action:()=>this.updateContext({selectedApp:void 0})}),h.addTransition(p,{condition:()=>!e.getConfigValue("APP_NAME")&&this.context.hasApps&&this.context.apps.length>0}),T.addTransition(p,{condition:()=>!!this.context.selectedApp}),T.addTransition(x,{condition:()=>!!this.context.error}),p.addTransition(g,{condition:()=>!e.getConfigValue("APP_NAME")&&this.context.apps.some((t=>t.id===this.context.selectedApp)),action:()=>{this.service.codicent=this.context.selectedApp||"",localStorage.setItem("selectedApp",this.context.selectedApp||"")}}),p.addTransition(g,{condition:()=>!e.getConfigValue("APP_NAME")&&!this.context.selectedApp,action:()=>{const t=this.context.apps[0].id;this.context.selectedApp!==t&&(this.service.codicent=t,localStorage.setItem("selectedApp",t),this.updateContext({selectedApp:t}))}}),p.addTransition(g,{condition:()=>this.context.apps.some((t=>t.id===e.getConfigValue("APP_NAME"))),action:()=>{const t=e.getConfigValue("APP_NAME");this.context.selectedApp!==t&&(this.service.codicent=t,this.updateContext({selectedApp:t}))}}),p.addTransition(l,{condition:()=>!this.context.apps.some((t=>t.id===this.context.selectedApp||t.id===e.getConfigValue("APP_NAME"))),action:()=>console.log("checking access -> no access",this.context.apps,this.context.selectedApp,e.getConfigValue("APP_NAME"))}),g.addTransition(u,{condition:()=>!!localStorage.getItem("selectedApp")&&localStorage.getItem("selectedApp")!==this.context.selectedApp,action:()=>{this.service.codicent=localStorage.getItem("selectedApp")||"",this.updateContext({selectedApp:localStorage.getItem("selectedApp")||void 0})}}),r.addTransition(a,{condition:()=>!0===this.context.isRegistered}),r.addTransition(x,{condition:()=>!!this.context.error}),d.addTransition(c,{condition:()=>void 0===this.context.hasValidPurchase,action:()=>{window.history.replaceState({},document.title,window.location.pathname),this.checkPurchase()}}),[n,h,c,C,r].forEach((t=>{t.addTransition(x,{condition:()=>this.context.error?.includes("network")||this.context.error?.includes("connectivity")||!1}),t.addTransition(x,{condition:()=>!!this.context.error})})),[o,a,g,l].forEach((t=>{t.addTransition(A,{condition:()=>!1===this.context.isAuthenticated})})),a.addTransition(u,{condition:()=>!this.context.user&&!!this.context.nickname}),u.addTransition(c,{condition:()=>!!this.context.name&&e.getConfigValue("SUBSCRIPTION_NEEDED")}),u.addTransition(h,{condition:()=>!!this.context.name&&!e.getConfigValue("SUBSCRIPTION_NEEDED")}),x.addTransition(c,{condition:()=>!this.context.error&&"ErrorCheckingPurchase"!==this.context.errorType}),x.addTransition(h,{condition:()=>!this.context.error&&"ErrorGettingApps"!==this.context.errorType}),x.addTransition(p,{condition:()=>!this.context.error&&"ErrorCheckingAccess"!==this.context.errorType}),x.addTransition(u,{condition:()=>!this.context.error&&"ErrorLoadingUser"!==this.context.errorType}),x.addTransition(T,{condition:()=>!this.context.error&&"ErrorCreatingApp"!==this.context.errorType}),x.addTransition(C,{condition:()=>!this.context.error&&"CodicentLoginFailed"!==this.context.errorType}),A.addTransition(i,{condition:()=>!this.context.isAuthenticated&&!this.context.accessToken});const S={initial:i,authenticating:n,notAuthenticated:s,authenticated:o,checkingCodicentAccess:C,registering:r,registered:a,checkingPurchase:c,needsPurchase:d,gettingApps:h,creatingApp:T,checkingAccess:p,noAccess:l,error:x,loadingUser:u,loggingOut:A,hasAccess:g,anonymous:E};return this.states.push(...Object.values(S)),S}get error(){return this.context.error}checkPurchase(){this.service.checkSubscriptionStatus().then((t=>this.updateContext({hasValidPurchase:"active"===t}))).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorCheckingPurchase"})))}getApps(){this.service.getApps().then((t=>{if(null===t)throw new Error("Failed to fetch apps.");e.getConfigValue("APP_PREFIX")&&(t=t.filter((t=>t.id.startsWith(e.getConfigValue("APP_PREFIX"))))),this.updateContext({apps:t,hasApps:!0,appsLoaded:!0}),this.context.selectedApp&&!t.some((t=>t.id===this.context.selectedApp))&&this.updateContext({selectedApp:void 0})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorGettingApps"})))}setUser(t){this.context.user=t}getContext(){return{...this.context}}updateContext(t){this.context={...this.context,...t}}getCurrentStateName(){const t=Object.entries(this.allStates).find((([t,e])=>e===this.current));return t?t[0]:""}logout(){localStorage.clear(),sessionStorage.clear(),this.resetContext()}setSelectedApp(t){localStorage.setItem("selectedApp",t),this.update()}isBusy(){return this.current===this.allStates.gettingApps||this.current===this.allStates.checkingPurchase||this.current===this.allStates.checkingAccess||this.current===this.allStates.checkingCodicentAccess||this.current===this.allStates.registering||this.current===this.allStates.loadingUser||this.current===this.allStates.creatingApp||this.current===this.allStates.loggingOut}}exports.AppStateMachine=i,exports.createAppStateMachine=(t,e)=>new i(t,e),exports.default=i;
@@ -1 +1 @@
1
- {"version":3,"file":"FileThumbnail.d.ts","sourceRoot":"","sources":["../../../src/components/FileThumbnail.tsx"],"names":[],"mappings":"AA6EA,UAAU,kBAAkB;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsCtD,CAAC"}
1
+ {"version":3,"file":"FileThumbnail.d.ts","sourceRoot":"","sources":["../../../src/components/FileThumbnail.tsx"],"names":[],"mappings":"AA6EA,UAAU,kBAAkB;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA2CtD,CAAC"}
@@ -1 +1 @@
1
- import{jsxs as e,jsx as o}from"react/jsx-runtime";import{makeStyles as t}from"../node_modules/@griffel/react/makeStyles.esm.js";import{Button as i}from"../node_modules/@fluentui/react-button/lib/components/Button/Button.js";import{Image as r}from"../node_modules/@fluentui/react-image/lib/components/Image/Image.js";import{DocumentData32Regular as n}from"../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js";import{tokens as l}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{DismissRegular as a}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js";const s=t({thumbnail:{width:"64px",height:"64px",borderRadius:l.borderRadiusMedium,backgroundColor:l.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:l.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:l.colorNeutralForegroundInverted,padding:"4px",fontSize:l.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:l.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:l.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:l.colorNeutralBackground1Hover}}}),c=({file:t,getImageUrl:l,onClick:c,onDelete:u,thumbnailSize:d})=>{const m=s();return e("div",{className:m.thumbnail,onClick:c,title:t.filename,children:[u&&o(i,{className:m.deleteButton,icon:o(a,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),t.contentType&&t.contentType.startsWith("image")?o(r,{className:m.image,src:`${l(t.id,d||200)}&width=${d}`,alt:t.filename}):o(n,{className:m.fileIcon}),o("div",{className:m.fileName,children:t.filename})]})};export{c as FileThumbnail};
1
+ import{jsxs as e,jsx as o}from"react/jsx-runtime";import{makeStyles as t}from"../node_modules/@griffel/react/makeStyles.esm.js";import{Button as i}from"../node_modules/@fluentui/react-button/lib/components/Button/Button.js";import{Image as r}from"../node_modules/@fluentui/react-image/lib/components/Image/Image.js";import{DocumentData32Regular as n}from"../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js";import{tokens as l}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{DismissRegular as a}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js";const s=t({thumbnail:{width:"64px",height:"64px",borderRadius:l.borderRadiusMedium,backgroundColor:l.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:l.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:l.colorNeutralForegroundInverted,padding:"4px",fontSize:l.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:l.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:l.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:l.colorNeutralBackground1Hover}}}),c=({file:t,getImageUrl:l,onClick:c,onDelete:d,thumbnailSize:u=64})=>{const m=s();return e("div",{className:m.thumbnail,style:{width:`${u}px`,height:`${u}px`},onClick:c,title:t.filename,children:[d&&o(i,{className:m.deleteButton,icon:o(a,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),d?.()},title:"Ta bort"}),t.contentType&&t.contentType.startsWith("image")?o(r,{className:m.image,src:`${l(t.id,u||200)}&width=${u}`,alt:t.filename}):o(n,{className:m.fileIcon}),o("div",{className:m.fileName,children:t.filename})]})};export{c as FileThumbnail};
@@ -1 +1 @@
1
- {"version":3,"file":"appState.d.ts","sourceRoot":"","sources":["../../../src/utils/appState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM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KAAK,CAAC;IACb,SAAS,EAAE,KAAK,CAAC;IACjB,WAAW,EAAE,KAAK,CAAC;IACnB,UAAU,EAAE,KAAK,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC;IACnB,sBAAsB,EAAE,KAAK,CAAC;IAC9B,SAAS,EAAE,KAAK,CAAC;CAClB;AAED,qBAAa,eAAgB,SAAQ,YAAY;IACxC,OAAO,EAAE,YAAY,CAQ1B;IACK,gBAAgB,EAAE,MAAM,CAAM;IACrC,aAAa,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACrD,SAAgB,OAAO,EAAE,eAAe,CAAC;IAClC,SAAS,EAAE,kBAAkB,CAAC;gBAEzB,OAAO,EAAE,eAAe,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAQ7E,OAAO,CAAC,YAAY;IA6Bb,MAAM;IAIb,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,sBAAsB;IAqd9B,IAAI,KAAK,kBAER;IAED,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,OAAO;IAiBR,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAI5C,UAAU,IAAI,QAAQ,CAAC,YAAY,CAAC;IAIpC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC;IAI5C,mBAAmB;IAKnB,MAAM;IASN,cAAc,CAAC,KAAK,EAAE,MAAM;IAK5B,MAAM;CAad;AAGD,eAAO,MAAM,qBAAqB,YAAa,eAAe,iBAAiB,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,oBAErG,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1 +1 @@
1
- import{d as t}from"../_virtual/index.js";import{getConfigValue as e}from"../config/index.js";class i extends t.StateMachine{constructor(t,e){super(),this.context={isAuthenticated:void 0,hasAccess:!1,error:null,errorType:void 0,apps:[],hasApps:!1,appsLoaded:!1},this.currentStateName="",this.resetContext(),this.service=t,this.onStateChange=e,this.allStates=this.initializeStateMachine()}resetContext(){this.context={isAuthenticated:!1,isRegistered:void 0,hasValidPurchase:void 0,hasAccess:!1,selectedApp:localStorage.getItem("selectedApp")||void 0,error:null,errorType:void 0,accessToken:void 0,nickname:void 0,apps:[],hasApps:!1,appsLoaded:!1},e("APP_PREFIX")&&this.context.selectedApp&&!this.context.selectedApp.startsWith(e("APP_PREFIX"))?this.context.selectedApp=void 0:this.context.selectedApp}update(){super.update()}handlePurchase(){window.location.href="./#/purchase"}initializeStateMachine(){const i=new t.State,n=new t.State({entering:()=>{this.context.selectedApp&&!this.service.codicent&&(this.service.codicent=this.context.selectedApp)}}),s=new t.State,o=new t.State,r=new t.State({entering:()=>{this.service.findUsername().then((t=>{t?this.service.nicknameExists(t).then((e=>{e?this.updateContext({error:"Användarnamnet finns redan.",errorType:"UsernameExists"}):this.service.registerUser(t,this.context.user.email,this.context.user.sub,this.context.accessToken).then((()=>{this.service.setToken(this.context.accessToken),this.updateContext({nickname:t,isRegistered:!0})})).catch((t=>{console.warn("Failed to register account",t),this.updateContext({error:"Ett fel uppstod vid registrering. Försök igen senare.",errorType:"ErrorRegistering"})}))})).catch((t=>{console.warn("Failed to check username",t),this.updateContext({error:"Ett fel uppstod vid kontroll av användarnamn.",errorType:"ErrorCheckingUsername"})})):this.updateContext({error:"Användarnamn kunde inte hittas.",errorType:"NoUsernameFound"})})).catch((t=>{console.warn("Failed to find username",t),this.updateContext({error:"Ett fel uppstod vid sökning av användarnamn.",errorType:"ErrorFindingUsername"})}))}}),a=new t.State,c=new t.State({entering:()=>{this.checkPurchase()}}),d=new t.State({entering:()=>{this.handlePurchase()}}),h=new t.State({entering:()=>{this.getApps()}}),p=new t.State,l=new t.State,g=new t.State({}),x=new t.State,u=new t.State({entering:()=>{this.context.nickname&&(localStorage.setItem("nickname",this.context.nickname),this.service.getUserInfo(this.context.nickname).then((t=>{const e=t?.name||t?.nickname||"";this.updateContext({name:e})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorLoadingUser"}))))}}),A=new t.State({entering:()=>{localStorage.removeItem("selectedApp"),localStorage.removeItem("nickname"),localStorage.removeItem("codicent"),sessionStorage.clear(),this.updateContext({isAuthenticated:!1,isRegistered:void 0,apps:[],hasApps:!1,selectedApp:void 0,accessToken:void 0,user:void 0}),setTimeout((()=>{this.current=this.allStates.initial}),1e3)}}),T=new t.State({entering:()=>{this.service.createApp().then((t=>{t?(this.service.codicent=t,this.updateContext({selectedApp:t,apps:[...this.context.apps||[],{id:t,title:t,logo:""}]})):this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})})).catch((t=>{console.warn("Error creating app",t),this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})}))}}),m=new t.State({entering:()=>{this.service.loginUser(this.context.user.sub,this.context.accessToken).then((t=>{null===t?this.updateContext({isRegistered:!1}):""===t?this.updateContext({isRegistered:!1,error:"Kunde inte logga in hos Codicent.",errorType:"CodicentLoginFailed"}):(this.service.setToken(this.context.accessToken),this.service.getNickname().then((t=>{t?this.updateContext({isRegistered:!0,nickname:t}):this.updateContext({error:"Kunde inte hitta användarnamn.",errorType:"ErrorFindingUsername"})})).catch((()=>{this.updateContext({error:"Fel vid hämtning av användarnamn.",errorType:"ErrorFindingUsername"})})))})).catch((()=>{this.updateContext({isRegistered:!1,error:"Fel vid inloggning hos Codicent.",errorType:"CodicentLoginError"})}))}}),S=new t.State({entering:()=>{this.service.setToken(e("ANONYMOUS_TOKEN")),this.service.codicent=e("ANONYMOUS_CODICENT")||e("APP_NAME")||""}});i.addTransition(n,{condition:()=>!0}),n.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),n.addTransition(x,{condition:()=>Boolean(this.context.error)}),n.addTransition(S,{condition:()=>!0===this.context.isAnonymous&&!!e("ANONYMOUS_TOKEN")}),n.addTransition(s,{condition:()=>!1===this.context.isAuthenticated}),s.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),s.addTransition(x,{condition:()=>!!this.context.error}),o.addTransition(m,{}),m.addTransition(r,{condition:()=>!1===this.context.isRegistered}),m.addTransition(a,{condition:()=>!0===this.context.isRegistered}),m.addTransition(x,{condition:()=>!!this.context.error}),a.addTransition(u,{condition:()=>!!this.context.nickname}),a.addTransition(x,{condition:()=>!this.context.nickname,action:()=>this.updateContext({error:"Missing nickname after registration",errorType:"ErrorLoadingUser"})}),c.addTransition(d,{condition:()=>!1===this.context.hasValidPurchase}),c.addTransition(h,{condition:()=>!0===this.context.hasValidPurchase}),h.addTransition(x,{condition:()=>!!this.context.error,action:()=>console.log("getting apps -> error")}),h.addTransition(p,{condition:()=>!!e("APP_NAME")&&this.context.hasApps}),h.addTransition(T,{condition:()=>!e("APP_NAME")&&this.context.appsLoaded&&0===this.context.apps.length,action:()=>this.updateContext({selectedApp:void 0})}),h.addTransition(p,{condition:()=>!e("APP_NAME")&&this.context.hasApps&&this.context.apps.length>0}),T.addTransition(p,{condition:()=>!!this.context.selectedApp}),T.addTransition(x,{condition:()=>!!this.context.error}),p.addTransition(g,{condition:()=>!e("APP_NAME")&&this.context.apps.some((t=>t.id===this.context.selectedApp)),action:()=>{this.service.codicent=this.context.selectedApp||"",localStorage.setItem("selectedApp",this.context.selectedApp||"")}}),p.addTransition(g,{condition:()=>!e("APP_NAME")&&!this.context.selectedApp,action:()=>{const t=this.context.apps[0].id;this.service.codicent=t,localStorage.setItem("selectedApp",t),this.updateContext({selectedApp:t})}}),p.addTransition(g,{condition:()=>this.context.apps.some((t=>t.id===e("APP_NAME"))),action:()=>{this.service.codicent=e("APP_NAME"),this.updateContext({selectedApp:e("APP_NAME")})}}),p.addTransition(l,{condition:()=>!this.context.apps.some((t=>t.id===this.context.selectedApp||t.id===e("APP_NAME"))),action:()=>console.log("checking access -> no access",this.context.apps,this.context.selectedApp,e("APP_NAME"))}),g.addTransition(u,{condition:()=>!!localStorage.getItem("selectedApp")&&localStorage.getItem("selectedApp")!==this.context.selectedApp,action:()=>{this.service.codicent=localStorage.getItem("selectedApp")||"",this.updateContext({selectedApp:localStorage.getItem("selectedApp")||void 0})}}),r.addTransition(a,{condition:()=>!0===this.context.isRegistered}),r.addTransition(x,{condition:()=>!!this.context.error}),d.addTransition(c,{condition:()=>void 0===this.context.hasValidPurchase,action:()=>{window.history.replaceState({},document.title,window.location.pathname),this.checkPurchase()}}),[n,h,c,m,r].forEach((t=>{t.addTransition(x,{condition:()=>this.context.error?.includes("network")||this.context.error?.includes("connectivity")||!1}),t.addTransition(x,{condition:()=>!!this.context.error})})),[o,a,g,l].forEach((t=>{t.addTransition(A,{condition:()=>!1===this.context.isAuthenticated})})),a.addTransition(u,{condition:()=>!this.context.user&&!!this.context.nickname}),u.addTransition(c,{condition:()=>!!this.context.name&&e("SUBSCRIPTION_NEEDED")}),u.addTransition(h,{condition:()=>!!this.context.name&&!e("SUBSCRIPTION_NEEDED")}),x.addTransition(c,{condition:()=>!this.context.error&&"ErrorCheckingPurchase"!==this.context.errorType}),x.addTransition(h,{condition:()=>!this.context.error&&"ErrorGettingApps"!==this.context.errorType}),x.addTransition(p,{condition:()=>!this.context.error&&"ErrorCheckingAccess"!==this.context.errorType}),x.addTransition(u,{condition:()=>!this.context.error&&"ErrorLoadingUser"!==this.context.errorType}),x.addTransition(T,{condition:()=>!this.context.error&&"ErrorCreatingApp"!==this.context.errorType}),x.addTransition(m,{condition:()=>!this.context.error&&"CodicentLoginFailed"!==this.context.errorType}),A.addTransition(i,{condition:()=>!this.context.isAuthenticated&&!this.context.accessToken});const v={initial:i,authenticating:n,notAuthenticated:s,authenticated:o,checkingCodicentAccess:m,registering:r,registered:a,checkingPurchase:c,needsPurchase:d,gettingApps:h,creatingApp:T,checkingAccess:p,noAccess:l,error:x,loadingUser:u,loggingOut:A,hasAccess:g,anonymous:S};return this.states.push(...Object.values(v)),v}get error(){return this.context.error}checkPurchase(){this.service.checkSubscriptionStatus().then((t=>this.updateContext({hasValidPurchase:"active"===t}))).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorCheckingPurchase"})))}getApps(){this.service.getApps().then((t=>{if(null===t)throw new Error("Failed to fetch apps.");e("APP_PREFIX")&&(t=t.filter((t=>t.id.startsWith(e("APP_PREFIX"))))),this.updateContext({apps:t,hasApps:!0,appsLoaded:!0}),this.context.selectedApp&&!t.some((t=>t.id===this.context.selectedApp))&&this.updateContext({selectedApp:void 0})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorGettingApps"})))}setUser(t){this.context.user=t}getContext(){return{...this.context}}updateContext(t){this.context={...this.context,...t}}getCurrentStateName(){const t=Object.entries(this.allStates).find((([t,e])=>e===this.current));return t?t[0]:""}logout(){localStorage.clear(),sessionStorage.clear(),this.resetContext()}setSelectedApp(t){localStorage.setItem("selectedApp",t),this.update()}isBusy(){return this.current===this.allStates.gettingApps||this.current===this.allStates.checkingPurchase||this.current===this.allStates.checkingAccess||this.current===this.allStates.checkingCodicentAccess||this.current===this.allStates.registering||this.current===this.allStates.loadingUser||this.current===this.allStates.creatingApp||this.current===this.allStates.loggingOut}}const n=(t,e)=>new i(t,e);export{i as AppStateMachine,n as createAppStateMachine,i as default};
1
+ import{d as t}from"../_virtual/index.js";import{getConfigValue as e}from"../config/index.js";class i extends t.StateMachine{constructor(t,e){super(),this.context={isAuthenticated:void 0,hasAccess:!1,error:null,errorType:void 0,apps:[],hasApps:!1,appsLoaded:!1},this.currentStateName="",this.resetContext(),this.service=t,this.onStateChange=e,this.allStates=this.initializeStateMachine()}resetContext(){this.context={isAuthenticated:!1,isRegistered:void 0,hasValidPurchase:void 0,hasAccess:!1,selectedApp:localStorage.getItem("selectedApp")||void 0,error:null,errorType:void 0,accessToken:void 0,nickname:void 0,apps:[],hasApps:!1,appsLoaded:!1},e("APP_PREFIX")&&this.context.selectedApp&&!this.context.selectedApp.startsWith(e("APP_PREFIX"))?this.context.selectedApp=void 0:this.context.selectedApp}update(){super.update()}handlePurchase(){window.location.href="./#/purchase"}initializeStateMachine(){const i=new t.State,n=new t.State({entering:()=>{this.context.selectedApp&&!this.service.codicent&&(this.service.codicent=this.context.selectedApp)}}),s=new t.State,o=new t.State,r=new t.State({entering:()=>{this.service.findUsername().then((t=>{t?this.service.nicknameExists(t).then((e=>{e?this.updateContext({error:"Användarnamnet finns redan.",errorType:"UsernameExists"}):this.service.registerUser(t,this.context.user.email,this.context.user.sub,this.context.accessToken).then((()=>{this.service.setToken(this.context.accessToken),this.updateContext({nickname:t,isRegistered:!0})})).catch((t=>{console.warn("Failed to register account",t),this.updateContext({error:"Ett fel uppstod vid registrering. Försök igen senare.",errorType:"ErrorRegistering"})}))})).catch((t=>{console.warn("Failed to check username",t),this.updateContext({error:"Ett fel uppstod vid kontroll av användarnamn.",errorType:"ErrorCheckingUsername"})})):this.updateContext({error:"Användarnamn kunde inte hittas.",errorType:"NoUsernameFound"})})).catch((t=>{console.warn("Failed to find username",t),this.updateContext({error:"Ett fel uppstod vid sökning av användarnamn.",errorType:"ErrorFindingUsername"})}))}}),a=new t.State,c=new t.State({entering:()=>{this.checkPurchase()}}),d=new t.State({entering:()=>{this.handlePurchase()}}),h=new t.State({entering:()=>{this.getApps()}}),p=new t.State,l=new t.State,g=new t.State({}),x=new t.State,u=new t.State({entering:()=>{this.context.nickname&&(localStorage.setItem("nickname",this.context.nickname),this.service.getUserInfo(this.context.nickname).then((t=>{const e=t?.name||t?.nickname||"";this.updateContext({name:e})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorLoadingUser"}))))}}),A=new t.State({entering:()=>{localStorage.removeItem("selectedApp"),localStorage.removeItem("nickname"),localStorage.removeItem("codicent"),sessionStorage.clear(),this.updateContext({isAuthenticated:!1,isRegistered:void 0,apps:[],hasApps:!1,selectedApp:void 0,accessToken:void 0,user:void 0}),setTimeout((()=>{this.current=this.allStates.initial}),1e3)}}),T=new t.State({entering:()=>{this.service.createApp().then((t=>{t?(this.service.codicent=t,this.updateContext({selectedApp:t,apps:[...this.context.apps||[],{id:t,title:t,logo:""}]})):this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})})).catch((t=>{console.warn("Error creating app",t),this.updateContext({error:"Misslyckades att skapa din app. Försök igen senare.",errorType:"ErrorCreatingApp"})}))}}),m=new t.State({entering:()=>{this.service.loginUser(this.context.user.sub,this.context.accessToken).then((t=>{null===t?this.updateContext({isRegistered:!1}):""===t?this.updateContext({isRegistered:!1,error:"Kunde inte logga in hos Codicent.",errorType:"CodicentLoginFailed"}):(this.service.setToken(this.context.accessToken),this.service.getNickname().then((t=>{t?this.updateContext({isRegistered:!0,nickname:t}):this.updateContext({error:"Kunde inte hitta användarnamn.",errorType:"ErrorFindingUsername"})})).catch((()=>{this.updateContext({error:"Fel vid hämtning av användarnamn.",errorType:"ErrorFindingUsername"})})))})).catch((()=>{this.updateContext({isRegistered:!1,error:"Fel vid inloggning hos Codicent.",errorType:"CodicentLoginError"})}))}}),S=new t.State({entering:()=>{this.service.setToken(e("ANONYMOUS_TOKEN")),this.service.codicent=e("ANONYMOUS_CODICENT")||e("APP_NAME")||""}});i.addTransition(n,{condition:()=>!0}),n.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),n.addTransition(x,{condition:()=>Boolean(this.context.error)}),n.addTransition(S,{condition:()=>!0===this.context.isAnonymous&&!!e("ANONYMOUS_TOKEN")}),n.addTransition(s,{condition:()=>!1===this.context.isAuthenticated}),s.addTransition(o,{condition:()=>!0===this.context.isAuthenticated}),s.addTransition(x,{condition:()=>!!this.context.error}),o.addTransition(m,{}),m.addTransition(r,{condition:()=>!1===this.context.isRegistered}),m.addTransition(a,{condition:()=>!0===this.context.isRegistered}),m.addTransition(x,{condition:()=>!!this.context.error}),a.addTransition(u,{condition:()=>!!this.context.nickname}),a.addTransition(x,{condition:()=>!this.context.nickname,action:()=>this.updateContext({error:"Missing nickname after registration",errorType:"ErrorLoadingUser"})}),c.addTransition(d,{condition:()=>!1===this.context.hasValidPurchase}),c.addTransition(h,{condition:()=>!0===this.context.hasValidPurchase}),h.addTransition(x,{condition:()=>!!this.context.error,action:()=>console.log("getting apps -> error")}),h.addTransition(p,{condition:()=>!!e("APP_NAME")&&this.context.hasApps}),h.addTransition(T,{condition:()=>!e("APP_NAME")&&this.context.appsLoaded&&0===this.context.apps.length,action:()=>this.updateContext({selectedApp:void 0})}),h.addTransition(p,{condition:()=>!e("APP_NAME")&&this.context.hasApps&&this.context.apps.length>0}),T.addTransition(p,{condition:()=>!!this.context.selectedApp}),T.addTransition(x,{condition:()=>!!this.context.error}),p.addTransition(g,{condition:()=>!e("APP_NAME")&&this.context.apps.some((t=>t.id===this.context.selectedApp)),action:()=>{this.service.codicent=this.context.selectedApp||"",localStorage.setItem("selectedApp",this.context.selectedApp||"")}}),p.addTransition(g,{condition:()=>!e("APP_NAME")&&!this.context.selectedApp,action:()=>{const t=this.context.apps[0].id;this.context.selectedApp!==t&&(this.service.codicent=t,localStorage.setItem("selectedApp",t),this.updateContext({selectedApp:t}))}}),p.addTransition(g,{condition:()=>this.context.apps.some((t=>t.id===e("APP_NAME"))),action:()=>{const t=e("APP_NAME");this.context.selectedApp!==t&&(this.service.codicent=t,this.updateContext({selectedApp:t}))}}),p.addTransition(l,{condition:()=>!this.context.apps.some((t=>t.id===this.context.selectedApp||t.id===e("APP_NAME"))),action:()=>console.log("checking access -> no access",this.context.apps,this.context.selectedApp,e("APP_NAME"))}),g.addTransition(u,{condition:()=>!!localStorage.getItem("selectedApp")&&localStorage.getItem("selectedApp")!==this.context.selectedApp,action:()=>{this.service.codicent=localStorage.getItem("selectedApp")||"",this.updateContext({selectedApp:localStorage.getItem("selectedApp")||void 0})}}),r.addTransition(a,{condition:()=>!0===this.context.isRegistered}),r.addTransition(x,{condition:()=>!!this.context.error}),d.addTransition(c,{condition:()=>void 0===this.context.hasValidPurchase,action:()=>{window.history.replaceState({},document.title,window.location.pathname),this.checkPurchase()}}),[n,h,c,m,r].forEach((t=>{t.addTransition(x,{condition:()=>this.context.error?.includes("network")||this.context.error?.includes("connectivity")||!1}),t.addTransition(x,{condition:()=>!!this.context.error})})),[o,a,g,l].forEach((t=>{t.addTransition(A,{condition:()=>!1===this.context.isAuthenticated})})),a.addTransition(u,{condition:()=>!this.context.user&&!!this.context.nickname}),u.addTransition(c,{condition:()=>!!this.context.name&&e("SUBSCRIPTION_NEEDED")}),u.addTransition(h,{condition:()=>!!this.context.name&&!e("SUBSCRIPTION_NEEDED")}),x.addTransition(c,{condition:()=>!this.context.error&&"ErrorCheckingPurchase"!==this.context.errorType}),x.addTransition(h,{condition:()=>!this.context.error&&"ErrorGettingApps"!==this.context.errorType}),x.addTransition(p,{condition:()=>!this.context.error&&"ErrorCheckingAccess"!==this.context.errorType}),x.addTransition(u,{condition:()=>!this.context.error&&"ErrorLoadingUser"!==this.context.errorType}),x.addTransition(T,{condition:()=>!this.context.error&&"ErrorCreatingApp"!==this.context.errorType}),x.addTransition(m,{condition:()=>!this.context.error&&"CodicentLoginFailed"!==this.context.errorType}),A.addTransition(i,{condition:()=>!this.context.isAuthenticated&&!this.context.accessToken});const v={initial:i,authenticating:n,notAuthenticated:s,authenticated:o,checkingCodicentAccess:m,registering:r,registered:a,checkingPurchase:c,needsPurchase:d,gettingApps:h,creatingApp:T,checkingAccess:p,noAccess:l,error:x,loadingUser:u,loggingOut:A,hasAccess:g,anonymous:S};return this.states.push(...Object.values(v)),v}get error(){return this.context.error}checkPurchase(){this.service.checkSubscriptionStatus().then((t=>this.updateContext({hasValidPurchase:"active"===t}))).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorCheckingPurchase"})))}getApps(){this.service.getApps().then((t=>{if(null===t)throw new Error("Failed to fetch apps.");e("APP_PREFIX")&&(t=t.filter((t=>t.id.startsWith(e("APP_PREFIX"))))),this.updateContext({apps:t,hasApps:!0,appsLoaded:!0}),this.context.selectedApp&&!t.some((t=>t.id===this.context.selectedApp))&&this.updateContext({selectedApp:void 0})})).catch((t=>this.updateContext({error:t.toString(),errorType:"ErrorGettingApps"})))}setUser(t){this.context.user=t}getContext(){return{...this.context}}updateContext(t){this.context={...this.context,...t}}getCurrentStateName(){const t=Object.entries(this.allStates).find((([t,e])=>e===this.current));return t?t[0]:""}logout(){localStorage.clear(),sessionStorage.clear(),this.resetContext()}setSelectedApp(t){localStorage.setItem("selectedApp",t),this.update()}isBusy(){return this.current===this.allStates.gettingApps||this.current===this.allStates.checkingPurchase||this.current===this.allStates.checkingAccess||this.current===this.allStates.checkingCodicentAccess||this.current===this.allStates.registering||this.current===this.allStates.loadingUser||this.current===this.allStates.creatingApp||this.current===this.allStates.loggingOut}}const n=(t,e)=>new i(t,e);export{i as AppStateMachine,n as createAppStateMachine,i as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codicent-app-sdk",
3
- "version": "0.3.47",
3
+ "version": "0.3.49",
4
4
  "description": "SDK for building AI-powered applications with Codicent",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",