solid-logic 4.0.8-test.0 → 5.0.0

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,2 +1,2 @@
1
- import{Session as t}from"@uvdsl/solid-oidc-client-browser";import*as e from"@uvdsl/solid-oidc-client-browser/core";import*as n from"rdflib";var o={386(t){const e={acl:"http://www.w3.org/ns/auth/acl#",arg:"http://www.w3.org/ns/pim/arg#",as:"https://www.w3.org/ns/activitystreams#",bookmark:"http://www.w3.org/2002/01/bookmark#",cal:"http://www.w3.org/2002/12/cal/ical#",cco:"http://www.ontologyrepository.com/CommonCoreOntologies/",cert:"http://www.w3.org/ns/auth/cert#",contact:"http://www.w3.org/2000/10/swap/pim/contact#",dc:"http://purl.org/dc/elements/1.1/",dct:"http://purl.org/dc/terms/",doap:"http://usefulinc.com/ns/doap#",foaf:"http://xmlns.com/foaf/0.1/",geo:"http://www.w3.org/2003/01/geo/wgs84_pos#",gpx:"http://www.w3.org/ns/pim/gpx#",gr:"http://purl.org/goodrelations/v1#",http:"http://www.w3.org/2007/ont/http#",httph:"http://www.w3.org/2007/ont/httph#",icalTZ:"http://www.w3.org/2002/12/cal/icaltzd#",ldp:"http://www.w3.org/ns/ldp#",link:"http://www.w3.org/2007/ont/link#",log:"http://www.w3.org/2000/10/swap/log#",meeting:"http://www.w3.org/ns/pim/meeting#",mo:"http://purl.org/ontology/mo/",org:"http://www.w3.org/ns/org#",owl:"http://www.w3.org/2002/07/owl#",pad:"http://www.w3.org/ns/pim/pad#",patch:"http://www.w3.org/ns/pim/patch#",prov:"http://www.w3.org/ns/prov#",pto:"http://www.productontology.org/id/",qu:"http://www.w3.org/2000/10/swap/pim/qif#",trip:"http://www.w3.org/ns/pim/trip#",rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",rss:"http://purl.org/rss/1.0/",sched:"http://www.w3.org/ns/pim/schedule#",schema:"http://schema.org/",sioc:"http://rdfs.org/sioc/ns#",skos:"http://www.w3.org/2004/02/skos/core#",solid:"http://www.w3.org/ns/solid/terms#",space:"http://www.w3.org/ns/pim/space#",stat:"http://www.w3.org/ns/posix/stat#",tab:"http://www.w3.org/2007/ont/link#",tabont:"http://www.w3.org/2007/ont/link#",ui:"http://www.w3.org/ns/ui#",vann:"http://purl.org/vocab/vann/",vcard:"http://www.w3.org/2006/vcard/ns#",wf:"http://www.w3.org/2005/01/wf/flow#",xsd:"http://www.w3.org/2001/XMLSchema#"};t.exports=function(t={namedNode:t=>t}){const n={};for(const o in e){const r=e[o];n[o]=function(e=""){return t.namedNode(r+e)}}return n}}},r={};function i(t){var e=r[t];if(void 0!==e)return e.exports;var n=r[t]={exports:{}};return o[t](n,n.exports,i),n.exports}function a(...t){console.log(...t)}function s(...t){console.warn(...t)}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const c=e;class l{constructor(){this.map=new Map}shouldPreserveExistingRefreshToken(t,e){return"refresh_token"===t&&(null==e||""===e)&&this.map.has(t)}async init(){return this}async setItem(t,e){this.shouldPreserveExistingRefreshToken(t,e)||this.map.set(t,e)}async getItem(t){return this.map.has(t)?this.map.get(t):null}async deleteItem(t){this.map.delete(t)}async clear(){this.map.clear()}close(){}}class d{constructor(){this.db=null,this.dbName="soidc",this.storeName="session",this.dbVersion=1}async shouldPreserveExistingRefreshToken(t,e){if("refresh_token"!==t||null!=e&&""!==e)return!1;const n=await this.getItem(t);return null!=n&&""!==n}async init(){if(this.db)return this;if("undefined"==typeof indexedDB)throw new Error("IndexedDB is not available in this environment");return await new Promise((t,e)=>{const n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=()=>e(n.error),n.onsuccess=()=>{this.db=n.result,t()},n.onupgradeneeded=()=>{const t=n.result;t.objectStoreNames.contains(this.storeName)||t.createObjectStore(this.storeName)}}),this}async setItem(t,e){await this.init(),await this.shouldPreserveExistingRefreshToken(t,e)||await this.withStore("readwrite",n=>n.put(e,t))}async getItem(t){return await this.init(),this.withStore("readonly",e=>e.get(t))}async deleteItem(t){await this.init(),await this.withStore("readwrite",e=>e.delete(t))}async clear(){await this.init(),await this.withStore("readwrite",t=>t.clear())}close(){this.db&&(this.db.close(),this.db=null)}withStore(t,e){return new Promise((n,o)=>{if(!this.db)return void o(new Error("Session database not initialized"));const r=this.db.transaction(this.storeName,t),i=r.objectStore(this.storeName),a=e(i);let s=null;r.onerror=()=>{var t;return o(null!==(t=r.error)&&void 0!==t?t:a.error)},r.onabort=()=>{var t,e;return o(null!==(e=null!==(t=r.error)&&void 0!==t?t:a.error)&&void 0!==e?e:new Error("IndexedDB transaction aborted"))},r.oncomplete=()=>n(s),a.onerror=()=>o(a.error),a.onsuccess=()=>{var t;s=null!==(t=a.result)&&void 0!==t?t:null}})}}const u=function(){var t,e,n;const o=c,r=null!==(n=null!==(t=o.SessionCore)&&void 0!==t?t:null===(e=o.default)||void 0===e?void 0:e.SessionCore)&&void 0!==n?n:o.default;return"function"!=typeof r?null:r}();const w=function(){if("undefined"!=typeof window&&(()=>{const t=window.location.hostname;return"localhost"===t||"127.0.0.1"===t||t.endsWith(".localhost")})())return u?new u(void 0,{database:new d}):new t;try{return new t}catch(e){console.warn("solid-logic: falling back to non-worker auth session:",e);try{return u?new u(void 0,{database:new d}):new t}catch(e){return console.warn("solid-logic: IndexedDB unavailable, using in-memory session database:",e),u?new u(void 0,{database:new l}):new t}}}();async function h(t){const e=await async function(t){try{const e=new URL(t),n=new URL("/.well-known/openid-configuration",e.origin),o=await fetch(n.toString(),{credentials:"include"});if(!o.ok)return null;const r=await o.json();return"string"==typeof(null==r?void 0:r.issuer)&&r.issuer?r.issuer.replace(/\/$/,""):null}catch(t){return null}}(t);return e||t}var f;const p=w,g="function"==typeof p.login?p.login.bind(w):void 0;if(g){const t=async(t,e)=>{var n,o,r,i;if(t&&"object"==typeof t&&!Array.isArray(t)){const e=null!==(o=null!==(n=t.oidcIssuer)&&void 0!==n?n:t.idp)&&void 0!==o?o:t.issuer,a=null!==(i=null!==(r=t.redirectUrl)&&void 0!==r?r:t.redirect_uri)&&void 0!==i?i:t.redirectUri;if("string"==typeof e&&"string"==typeof a)return g(await h(e),a)}return g("string"==typeof t?await h(t):t,e)};p.login=t}const y=new class{constructor(){this.listeners=new Map}on(t,e){this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e)}off(t,e){var n;null===(n=this.listeners.get(t))||void 0===n||n.delete(e)}emit(t,...e){var n;null===(n=this.listeners.get(t))||void 0===n||n.forEach(t=>t(...e))}};let v=null!==(f=w.isActive)&&void 0!==f?f:Boolean(w.webId);"function"==typeof w.addEventListener&&w.addEventListener("sessionStateChange",()=>{var t;const e=null!==(t=w.isActive)&&void 0!==t?t:Boolean(w.webId);v&&!e&&y.emit("logout"),v=e});const m=Object.assign(w,{events:y}),b=n;var x=i(386);const I=i.n(x)()(b),C=(0,b.sym)("http://www.iana.org/assignments/link-relations/acl");function T(t){const e=I;function n(t,n,o,r={}){const i=r.public||[],a=(0,b.graph)(),s=(0,b.Namespace)("http://www.w3.org/ns/auth/acl#");let c=a.sym(`${o}#a1`);const l=a.sym(o),d=a.sym(t);if(a.add(c,e.rdf("type"),s("Authorization"),l),a.add(c,s("accessTo"),d,l),r.defaultForNew&&a.add(c,s("default"),d,l),a.add(c,s("agent"),n,l),a.add(c,s("mode"),s("Read"),l),a.add(c,s("mode"),s("Write"),l),a.add(c,s("mode"),s("Control"),l),i.length){c=a.sym(`${o}#a2`),a.add(c,e.rdf("type"),s("Authorization"),l),a.add(c,s("accessTo"),d,l),a.add(c,s("agentClass"),e.foaf("Agent"),l);for(let t=0;t<i.length;t++)a.add(c,s("mode"),s(i[t]),l)}return(0,b.serialize)(l,a,o)}return{findAclDocUrl:async function(e){await t.fetcher.load(e);const n=t.any(e,C);if(!n)throw new Error(`No ACL link discovered for ${e}`);return n.value},setACLUserPublic:function(e,o,r){const i=t.any(t.sym(e),C);return Promise.resolve().then(()=>i||function(e){const n=t.fetcher;if(!n)throw new Error("Cannot fetch ACL rel, store has no fetcher");return n.load(e).then(n=>{if(!n.ok)throw new Error("fetchACLRel: While loading:"+n.error);const o=t.any(t.sym(e),C);if(!o)throw new Error("fetchACLRel: No Link rel=ACL header for "+e);return o})}(e).catch(t=>{throw new Error(`Error fetching rel=ACL header for ${e}: ${t}`)})).then(i=>{const a=n(e,o,i.uri,r);if(!t.fetcher)throw new Error("Cannot PUT this, store has no fetcher");return t.fetcher.webOperation("PUT",i.uri,{data:a,contentType:"text/turtle"}).then(t=>{if(!t.ok)throw new Error("Error writing ACL text: "+t.error);return i})})},genACLText:n}}const $=()=>{let{SolidAppContext:t}=window;if(t||(t={}),t.viewingNoAuthPage=!1,t.noAuth&&window.document){if(window.document.location.href.startsWith(t.noAuth)){t.viewingNoAuthPage=!0;const e=new URLSearchParams(window.document.location.search);if(e){let n=t.viewedPage=e.get("uri")||null;if(n&&(n=decodeURI(n),!n.startsWith(t.noAuth))){const e=n.split(/\//);t.idp=e[0]+"//"+e[2],t.viewingNoAuthPage=!1}}}}return t};function U(){const{$SolidTestEnvironment:t}=window;if(void 0!==t&&t.username)return a("Assuming the user is "+t.username),(0,b.sym)(t.username);if("undefined"!=typeof document&&document.location&&"http://localhost"===(""+document.location).slice(0,16)){const t=document.getElementById("appTarget");if(!t)return null;const e=t.getAttribute("testID");return e?(a("Assuming user is "+e),(0,b.sym)(e)):null}return null}class k{constructor(t){this.checkUserInFlight=null,this.sessionRestoreHookAttached=!1,this.fallbackWebId=null,this.session=t}get authSession(){return this.session}currentUser(){var t,e;const n=$();if(n.viewingNoAuthPage)return(0,b.sym)(n.webId);const o=this.session,r=null===(t=null==o?void 0:o.info)||void 0===t?void 0:t.webId,i=null==o?void 0:o.webId,a=r||i||this.fallbackWebId,s=null===(e=null==o?void 0:o.info)||void 0===e?void 0:e.isLoggedIn,c=null==o?void 0:o.isActive,l=!0===s||!0===c||null==s&&null==c&&Boolean(a)||Boolean(this.fallbackWebId);return this&&this.session&&a&&l?(0,b.sym)(a):U()}async checkUser(t){var e;const n=new URL(window.location.href).hash;n&&window.localStorage.setItem("preLoginRedirectHash",n);const o=this.session;this.sessionRestoreHookAttached||"function"!=typeof(null===(e=null==o?void 0:o.events)||void 0===e?void 0:e.on)||(o.events.on("sessionRestore",t=>{a(`Session restored to ${t}`),document.location.toString()!==t&&history.replaceState(null,"",t)}),this.sessionRestoreHookAttached=!0),this.checkUserInFlight||(this.checkUserInFlight=this.resolveCurrentUser());const r=this.checkUserInFlight;let i;try{i=await r}finally{this.checkUserInFlight===r&&(this.checkUserInFlight=null)}return Promise.resolve(t?t(i):i)}async resolveCurrentUser(){var t,e,n,o,r,i;const s=this.session,c=new URL(window.location.href);if(c.hash="","function"==typeof(null==s?void 0:s.handleIncomingRedirect))await s.handleIncomingRedirect({restorePreviousSession:!0,url:c.href});else{if("function"==typeof(null==s?void 0:s.restore)){const o=null!==(t=null==s?void 0:s.isActive)&&void 0!==t?t:Boolean(null==s?void 0:s.webId);try{await s.restore()}catch(t){const e=t instanceof Error?t.message:String(t);if(!/no session to restore/i.test(e))throw t;a("No previous session to restore")}const r=null!==(e=null==s?void 0:s.isActive)&&void 0!==e?e:Boolean(null==s?void 0:s.webId);!o&&r&&(null===(n=s.events)||void 0===n||n.emit("sessionRestore",window.location.href))}if("function"==typeof(null==s?void 0:s.handleRedirectFromLogin)){const t=null!==(o=null==s?void 0:s.isActive)&&void 0!==o?o:Boolean(null==s?void 0:s.webId);await s.handleRedirectFromLogin();const e=null!==(r=null==s?void 0:s.isActive)&&void 0!==r?r:Boolean(null==s?void 0:s.webId);!t&&e&&(null===(i=s.events)||void 0===i||i.emit("login"))}}const l=window.localStorage.getItem("preLoginRedirectHash");if(l){const t=new URL(window.location.href);t.hash!==l&&(history.pushState?history.pushState(null,document.title,l):location.hash=l,t.hash=l),window.localStorage.setItem("preLoginRedirectHash","")}let d=U();if(d)return d;let u=this.webIdFromSession(null==s?void 0:s.info,s);return u||(u=await this.probeNssCookieBackedWebId()),this.fallbackWebId=u||null,u&&(d=this.saveUser(u)),d&&a(`(Logged in as ${d} by authentication)`),d}async probeNssCookieBackedWebId(){if("undefined"==typeof window)return null;const{hostname:t,port:e,protocol:n}=window.location,o=".localhost";if(!t.endsWith(o))return null;const r=t.slice(0,-10);if(!r||"localhost"===r||r.includes("."))return null;try{if(403!==(await fetch("/account/password/change",{credentials:"include",redirect:"manual",cache:"no-store"})).status)return null;return`${`${n}//${t}${e?`:${e}`:""}`}/profile/card#me`}catch(t){return null}}saveUser(t,e){let n;if(t){n="string"==typeof t?t:t.uri;const o=(0,b.namedNode)(n);return e&&(e.me=o),o}return null}webIdFromSession(t,e){const n=(null==t?void 0:t.webId)||(null==e?void 0:e.webId);if(!n)return null;const o=null==t?void 0:t.isLoggedIn,r=null==e?void 0:e.isLoggedIn,i=null==e?void 0:e.isActive;return!0===o||!0===r||!0===i?n:!1===o&&!1===r&&!1===i?null:n}}function E(t){return(0,b.sym)(t.uri+"#id"+Date.now())}function L(t){return!t||`${window.location.origin}/`!==new URL(t.value).origin}const A="index.ttl#this";function P(t,e){const n=I;async function o(e,n,o){await t.fetcher.load(e);const r=t.any(e,new b.NamedNode("http://www.iana.org/assignments/link-relations/acl"));if(!r)throw new Error("Chat ACL doc not found!");const i=`\n @prefix acl: <http://www.w3.org/ns/auth/acl#>.\n <#owner>\n a acl:Authorization;\n acl:agent <${n.value}>;\n acl:accessTo <.>;\n acl:default <.>;\n acl:mode\n acl:Read, acl:Write, acl:Control.\n <#invitee>\n a acl:Authorization;\n acl:agent <${o.value}>;\n acl:accessTo <.>;\n acl:default <.>;\n acl:mode\n acl:Read, acl:Append.\n `;await t.fetcher.webOperation("PUT",r.value,{data:i,contentType:"text/turtle"})}async function r(e,o){const r=t.any(o,n.solid("privateTypeIndex"));if(!r)throw new Error("Private type index not found!");await t.fetcher.load(r);const i=E(r),a=[(0,b.st)(i,n.rdf("type"),n.solid("TypeRegistration"),r.doc()),(0,b.st)(i,n.solid("forClass"),n.meeting("LongChat"),r.doc()),(0,b.st)(i,n.solid("instance"),e,r.doc())];await new Promise((e,n)=>{t.updater.update([],a,function(t,o,r){o?e(null):n(new Error(r))})})}async function i(n){const o=await e.loadMe(),r=function(t,e){const n=new URL(`IndividualChats/${new URL(t.value).host}/`,e.value).toString();return new b.NamedNode(n)}(n,await e.getPodRoot(o));let i=!0;try{await t.fetcher.load(new b.NamedNode(r.value+"index.ttl#this"))}catch(t){i=!1}return{me:o,chatContainer:r,exists:i}}async function a(t,e){return(await s({me:e,newBase:t.value})).newInstance}function s(e){const o=t,r=o.updater;if(e.me&&!e.me.uri)throw new Error("chat mintNew: Invalid userid "+e.me);const i=e.newInstance=e.newInstance||o.sym(e.newBase+A),a=i.doc();return o.add(i,n.rdf("type"),n.meeting("LongChat"),a),o.add(i,n.dc("title"),"Chat channel",a),o.add(i,n.dc("created"),(0,b.term)(new Date(Date.now())),a),e.me&&o.add(i,n.dc("author"),e.me,a),new Promise(function(t,n){null==r||r.put(a,o.statementsMatching(void 0,void 0,void 0,a),"text/turtle",function(o,r,a){r?t({...e,newInstance:i}):n(new Error("FAILED to save new chat channel at: "+o+" : "+a))})})}async function c(e,o){var r;await t.fetcher.load(e.doc());const i=t.any(e,n.ldp("inbox"),void 0,e.doc());if(!i)throw new Error(`Invitee inbox not found! ${e.value}`);const a=`\n <> a <http://www.w3.org/ns/pim/meeting#LongChatInvite> ;\n ${n.rdf("seeAlso")} <${o.value}> .\n `,s=await(null===(r=t.fetcher)||void 0===r?void 0:r.webOperation("POST",i.value,{data:a,contentType:"text/turtle"}));if(!(null==s?void 0:s.headers.get("location")))throw new Error(`Invite sending returned a ${null==s?void 0:s.status}`)}return{setAcl:o,addToPrivateTypeIndex:r,findChat:i,createChatThing:a,getChat:async function(t,e=!0){const{me:n,chatContainer:s,exists:l}=await i(t);if(l)return new b.NamedNode(s.value+A);if(e){const e=await a(s,n);return await c(t,e),await o(s,n,t),await r(e,n),e}return null},sendInvite:c,mintNew:s}}function S(t,e,n,o,r){return{createInboxFor:async function(t,r){const i=await e.loadMe(),a=`${(await e.getPodRoot(i)).value}p2p-inboxes/${encodeURIComponent(r)}/`;return await o.createContainer(a),await n.setSinglePeerAccess({ownerWebId:i.value,peerWebId:t,accessToModes:"acl:Append",target:a}),a},getNewMessages:async function(t){t||(t=await e.loadMe());const n=await e.getMainInbox(t);return(await o.getContainerMembers(n)).filter(t=>!o.isContainer(t))},markAsRead:async function(e,n){const o=await t.fetcher._fetch(e);if(200!==o.status)throw new Error(`Not OK! ${e}`);const r=function(t,e){const n=e.getUTCFullYear(),o=("0"+(e.getUTCMonth()+1)).slice(-2),r=("0"+e.getUTCDate()).slice(-2),i=t.split("/"),a=i[i.length-1];return new URL(`./archive/${n}/${o}/${r}/${a}`,t).toString()}(e,n),i={method:"PUT",body:await o.text(),headers:[["Content-Type",o.headers.get("Content-Type")||"application/octet-stream"]]};"2"===(await t.fetcher._fetch(r,i)).status.toString()[0]&&await t.fetcher._fetch(e,{method:"DELETE"})}}}class R extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=new.target.name}}class N extends R{}class O extends R{}class W extends R{}class M extends R{}class F extends R{}class D extends R{}class j extends R{constructor(t,e){super(e),this.status=t}}function B(){return["@prefix solid: <http://www.w3.org/ns/solid/terms#>.","<>"," a solid:TypeIndex ;"," a solid:ListedDocument."].join("\n")}function _(){return["@prefix solid: <http://www.w3.org/ns/solid/terms#>.","<>"," a solid:TypeIndex ;"," a solid:UnlistedDocument."].join("\n")}function z(t,e){const n=new URL(e).pathname.split("/").pop()||"publicTypeIndex.ttl";return["# ACL resource for the Public Type Index","","@prefix acl: <http://www.w3.org/ns/auth/acl#>.","@prefix foaf: <http://xmlns.com/foaf/0.1/>.","","<#owner>"," a acl:Authorization;",""," acl:agent",` <${t}>;`,"",` acl:accessTo <./${n}>;`,""," acl:mode"," acl:Read, acl:Write, acl:Control.","","# Public-readable","<#public>"," a acl:Authorization;",""," acl:agentClass foaf:Agent;","",` acl:accessTo <./${n}>;`,""," acl:mode acl:Read."].join("\n")}function H(t){function e(e){return t.statementsMatching(e,(0,b.sym)("http://www.w3.org/ns/ldp#contains"),void 0).map(t=>t.object)}function n(t){const e=t.value;return"/"===e.charAt(e.length-1)}return{isContainer:n,createContainer:async function(e){if(!n((0,b.sym)(e)))throw new Error(`Not a container URL ${e}`);const o=await t.fetcher._fetch(e,{method:"PUT",headers:{"Content-Type":"text/turtle","If-None-Match":"*",Link:'<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"'},body:" "});if(409!==o.status&&"2"!==o.status.toString()[0])throw new Error(`Not OK: got ${o.status} response while creating container at ${e}`)},getContainerElements:e,getContainerMembers:async function(n){return await t.fetcher.load(n),e(n)}}}function q(t,e,n){const o=I,r=H(t),i=new Map,a=new Map;function c(t){return!!t&&(t.startsWith("https://")||t.startsWith("http://"))}function l(t){const e=t.doc(),n=e.dir();if((null==n?void 0:n.uri)&&c(n.uri))return n.uri;const o=e.uri;if(!o||!c(o))return null;const r=o.split("#")[0],i=r.lastIndexOf("/");return-1===i?null:r.slice(0,i+1)}function d(t,e){const n=l(t);if(!n)throw new Error(`Cannot derive directory for preferences file ${t.uri}`);return(0,b.sym)(n+e)}function u(t){var e;if(404===(null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.status))return!0;const n=`${(null==t?void 0:t.message)||t||""}`;return n.includes("404")||n.includes("Not Found")}async function w(e,n){var o;const i=l(n);if(!i)throw new Error(`Cannot derive settings directory from ${n.uri}`);await async function(e){const n=(0,b.sym)(e);try{return void await t.fetcher.load(n)}catch(t){if(!u(t))throw t}await r.createContainer(e)}(i);const a=(0,b.sym)(i);let s;try{await t.fetcher.load(a),s=null===(o=t.any(a,C))||void 0===o?void 0:o.value}catch(t){if(!u(t))throw t}s||(s=`${i}.acl`);const c=(0,b.sym)(s);try{return void await t.fetcher.load(c)}catch(t){if(!u(t))throw t}var d;await t.fetcher.webOperation("PUT",c.uri,{data:(d=e.uri,["@prefix acl: <http://www.w3.org/ns/auth/acl#>.","","<#owner>","a acl:Authorization;",`acl:agent <${d}>;`,"acl:accessTo <./>;","acl:default <./>;","acl:mode acl:Read, acl:Write, acl:Control."].join("\n")),contentType:"text/turtle"})}async function h(e,r){const i=r.doc(),a=e.doc();await t.fetcher.load(i);const s=t.any(e,o.solid("publicTypeIndex"),null,a),c=t.any(e,o.solid("publicTypeIndex"),null,i),l=s||c||d(r,"publicTypeIndex.ttl"),w=t.any(e,o.solid("privateTypeIndex"),null,i)||d(r,"privateTypeIndex.ttl"),h=!s;h&&await n.followOrCreateLinkWithContentOnCreate(e,o.solid("publicTypeIndex"),l,a,B());const f=[];t.holds(i,o.rdf("type"),o.space("ConfigurationFile"),i)||f.push((0,b.st)(i,o.rdf("type"),o.space("ConfigurationFile"),i)),t.holds(i,o.dct("title"),void 0,i)||f.push((0,b.st)(i,o.dct("title"),(0,b.literal)("Preferences file"),i)),t.holds(e,o.solid("publicTypeIndex"),l,i)||f.push((0,b.st)(e,o.solid("publicTypeIndex"),l,i)),t.holds(e,o.solid("privateTypeIndex"),w,i)||f.push((0,b.st)(e,o.solid("privateTypeIndex"),w,i)),f.length>0&&(await t.updater.update([],f),await t.fetcher.load(i)),await async function(e,o,r=!1){var i,a,s;if(!await n.loadOrCreateWithContentOnCreate(o,B())&&!r)return;let c;try{await t.fetcher.load(o),c=null===(i=t.any(o,C))||void 0===i?void 0:i.value}catch(t){if(!u(t))throw t}c||(c=`${o.uri}.acl`);const l=(0,b.sym)(c);try{await t.fetcher.webOperation("PUT",l.uri,{data:z(e.uri,o.uri),contentType:"text/turtle",headers:{"If-None-Match":"*"}})}catch(t){if(412!==(null!==(s=null===(a=null==t?void 0:t.response)||void 0===a?void 0:a.status)&&void 0!==s?s:null==t?void 0:t.status))throw t}}(e,l,h),await async function(t){await n.loadOrCreateWithContentOnCreate(t,_())}(w)}async function f(t){var e,o;try{return!!await n.loadOrCreateWithContentOnCreate(t,["@prefix dct: <http://purl.org/dc/terms/>.","@prefix pim: <http://www.w3.org/ns/pim/space#>.","@prefix solid: <http://www.w3.org/ns/solid/terms#>.","<>"," a pim:ConfigurationFile ;",' dct:title "Preferences file".'].join("\n"))}catch(n){if(401===(null===(e=n.response)||void 0===e?void 0:e.status))throw new N;if(403===(null===(o=n.response)||void 0===o?void 0:o.status)){if(L(t))throw new O;throw new W}throw n}}async function p(e){const r=a.get(e.uri);if(r)return r;const c=i.get(e.uri);if(c)return c;const l=(async()=>{var r;await g(e);const i=function(t){const e=t.uri.replace("/profile/","/").replace("/public/","/").split("/").slice(0,-1).join("/")+"/settings/prefs.ttl";return(0,b.sym)(e)}(e);let c;try{const r=t.any(e,o.space("preferencesFile"),null,e.doc());c=r||await n.followOrCreateLink(e,o.space("preferencesFile"),i,e.doc()),await w(e,c),await f(c),await h(e,c)}catch(t){if(s(`User ${e} has no pointer in profile to preferences file.`),t instanceof F)throw t;if(t instanceof D)throw t;if(t instanceof N)throw t;if(t instanceof O)throw t;if(t instanceof W)throw t;if(t instanceof j)throw t;throw t}try{await t.fetcher.load(c)}catch(n){const o=`Unable to load preference of user ${e}: ${n}`;if(404===(null===(r=n.response)||void 0===r?void 0:r.status))return await w(e,c),await f(c),await h(e,c),await t.fetcher.load(c),c;if(s(o),401===n.response.status)throw new N;if(403===n.response.status){if(L(c))throw new O;throw new W}throw new Error(o)}return a.set(e.uri,c),c})();i.set(e.uri,l);try{return await l}finally{i.get(e.uri)===l&&i.delete(e.uri)}}async function g(e){if(!e)throw new Error("loadProfile: no user given.");try{await t.fetcher.load(e.doc())}catch(t){throw new Error(`Unable to load profile of user ${e}: ${t}`)}return e.doc()}function y(e){return t.any(e,o.space("storage"),void 0,e.doc())}return{loadMe:async function(){const n=e.currentUser();if(null===n)throw new Error("Current user not found! Not logged in?");return await t.fetcher.load(n.doc()),n},getPodRoot:function(t){const e=y(t);if(!e)throw new Error("User pod root not found!");return e},getMainInbox:async function(e){await t.fetcher.load(e);const n=t.any(e,o.ldp("inbox"),void 0,e.doc());if(!n)throw new Error("User main inbox not found!");return n},findStorage:y,loadPreferences:p,loadProfile:g,silencedLoadPreferences:async function(t){try{return await p(t)}catch(t){return}}}}function K(t,e,n,o){const r=I;function i(t){return!!t&&(t.startsWith("https://")||t.startsWith("http://"))}async function c(e){if(!e)throw new Error("loadTypeIndexesFor: No user given");const i=await n.loadProfile(e);let a,c=null;try{c=h(e)}catch(t){s(`User ${e} has no usable profile document directory for publicTypeIndex.`)}try{const n=t.any(e,r.solid("publicTypeIndex"),void 0,i);a=n||(c?await o.followOrCreateLinkWithContentOnCreate(e,r.solid("publicTypeIndex"),c,i,B()):null)}catch(t){s(`User ${e} has no pointer in profile to publicTypeIndex file: ${t}`)}const l=a?[{label:"public",index:a,agent:e}]:[];let d,u;try{d=await n.silencedLoadPreferences(e)}catch(t){d=null}if(d){let n,a=null;try{a=f(d)}catch(t){s(`User ${e} has no usable preferences document directory for privateTypeIndex.`)}try{const s=t.any(e,r.solid("privateTypeIndex"),void 0,i);n=s||(a?await o.followOrCreateLinkWithContentOnCreate(e,r.solid("privateTypeIndex"),a,d,_()):null)}catch(t){s(`User ${e} has no pointer in preference file to privateTypeIndex file: ${t}`)}u=n?[{label:"private",index:n,agent:e}]:[]}else u=[];const w=l.concat(u);if(0===w.length)return w;const p=w.map(t=>t.index);try{await t.fetcher.load(p)}catch(t){s("Problems loading type index: ",t)}return w}async function l(e){let o;try{o=await n.silencedLoadPreferences(e)}catch(t){s(`User ${e} has no pointer in profile to preferences file.`)}if(o){const n=t.each(e,r.solid("community"),void 0,o).concat(t.each(e,r.solid("community"),void 0,e.doc()));let a=[];for(const t of n)if("NamedNode"===t.termType&&i(t.uri))try{a=a.concat(await c(t))}catch(e){s(`Skipping community type indexes for ${t.uri}: ${e}`)}else s(`Skipping malformed community node for ${e}: ${t}`);return a}return[]}async function d(t){return(await c(t)).concat(await l(t))}async function u(t,e){const n=await d(e);let o=[];for(const e of n){const n=await p(e,t);o=o.concat(n)}return o}function w(t){const e=t.doc(),n=e.dir();if((null==n?void 0:n.uri)&&i(n.uri))return n.uri;const o=e.uri;if(!o||!i(o))return a(`docDirUri: missing or non-http(s) doc uri for ${null==t?void 0:t.uri}`),null;const r=o.split("#")[0],s=r.lastIndexOf("/");return-1===s?(a(`docDirUri: no slash in doc uri ${o}`),null):r.slice(0,s+1)}function h(t){const e=w(t);if(!e)throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${t.uri}`);return(0,b.sym)(e+"publicTypeIndex.ttl")}function f(t){const e=w(t);if(!e)throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${t.uri}`);return(0,b.sym)(e+"privateTypeIndex.ttl")}async function p(e,n){const o=e.index,i=[],a=t.statementsMatching(null,r.solid("instance"),null,o).concat(t.statementsMatching(null,r.solid("instanceContainer"),null,o)).map(t=>t.subject);for(const s of a){const a=t.any(s,r.solid("forClass"),null,o);if(!n||a.sameTerm(n)){const n=t.each(s,r.solid("instance"),null,o);for(const t of n)i.push({instance:t,type:a,scope:e});const c=t.each(s,r.solid("instanceContainer"),null,o);for(const n of c)await t.fetcher.load(n),i.push({instance:(0,b.sym)(n.value),type:a,scope:e})}}return i}return{registerInTypeIndex:async function(e,n,o){const i=E(n),a=[(0,b.st)(i,r.rdf("type"),r.solid("TypeRegistration"),n),(0,b.st)(i,r.solid("forClass"),o,n),(0,b.st)(i,r.solid("instance"),e,n)];try{await t.updater.update([],a)}catch(t){const o=`Unable to register ${e} in index ${n}: ${t}`;return console.warn(o),null}return i},getRegistrations:function(e,n){return t.each(void 0,r.solid("instance"),e).filter(e=>t.holds(e,r.solid("forClass"),n))},loadTypeIndexesFor:c,loadCommunityTypeIndexes:l,loadAllTypeIndexes:d,getScopedAppInstances:u,getAppInstances:async function(t){const n=e.currentUser();if(!n)throw new Error("getAppInstances: Must be logged in to find apps.");return(await u(t,n)).map(t=>t.instance)},suggestPublicTypeIndex:h,suggestPrivateTypeIndex:f,deleteTypeIndexRegistration:async function(e){const n=t.the(null,r.solid("instance"),e.instance,e.scope.index);if(!n)throw new Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);const o=t.statementsMatching(n,null,null,e.scope.index);await t.updater.update(o,[])},getScopedAppsFromIndex:p}}function V(t,e){a("SolidLogic: Unique instance created. There should only be one of these.");const n=b.graph();b.fetcher(n,{fetch:t.fetch}),n.updater=new b.UpdateManager(n),n.features=[];const o=new k(e),r=T(n),i=H(n),c=function(t,e,n){async function o(e){var n,o,r,i,a;try{return await t.fetcher.load(e)}catch(s){if(404===(null===(n=null==s?void 0:s.response)||void 0===n?void 0:n.status)){try{await t.fetcher.webOperation("PUT",e.uri,{data:"",contentType:"text/turtle",headers:{"If-None-Match":"*"}})}catch(t){if(412!==(null!==(r=null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status)&&void 0!==r?r:null==t?void 0:t.status))throw new D(`createIfNotExists: PUT FAILED: ${e}: ${t}`)}return await t.fetcher.load(e)}if(401===(null===(i=null==s?void 0:s.response)||void 0===i?void 0:i.status))throw new N;if(403===(null===(a=null==s?void 0:s.response)||void 0===a?void 0:a.status)){if(L(e))throw new O;throw new W}const c=`createIfNotExists doc load error: ${e}: ${s}`;throw new j(null==s?void 0:s.status,`${(null==s?void 0:s.message)||""}${c}`)}}async function r(e,n){var o,r,i,a;try{return await t.fetcher.load(e),!1}catch(t){if(404!==(null!==(r=null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status)&&void 0!==r?r:null==t?void 0:t.status))throw t}try{return await t.fetcher.webOperation("PUT",e.uri,{data:n,contentType:"text/turtle",headers:{"If-None-Match":"*"}}),!0}catch(t){if(412===(null!==(a=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.status)&&void 0!==a?a:null==t?void 0:t.status))return!1;throw t}}return{recursiveDelete:async function o(r){try{if(n.isContainer(r)){const i=await e.findAclDocUrl(r);await t.fetcher._fetch(i,{method:"DELETE"});const a=await n.getContainerMembers(r);await Promise.all(a.map(t=>o(t)))}return t.fetcher._fetch(r.value,{method:"DELETE"})}catch(t){a(`Please manually remove ${r.value} from your system.`,t)}},setSinglePeerAccess:async function(n){let o=["@prefix acl: <http://www.w3.org/ns/auth/acl#>.","","<#alice> a acl:Authorization;\n acl:agent <"+n.ownerWebId+">;",` acl:accessTo <${n.target}>;`,` acl:default <${n.target}>;`," acl:mode acl:Read, acl:Write, acl:Control.",""].join("\n");n.accessToModes&&(o+=["<#bobAccessTo> a acl:Authorization;",` acl:agent <${n.peerWebId}>;`,` acl:accessTo <${n.target}>;`,` acl:mode ${n.accessToModes}.`,""].join("\n")),n.defaultModes&&(o+=["<#bobDefault> a acl:Authorization;",` acl:agent <${n.peerWebId}>;`,` acl:default <${n.target}>;`,` acl:mode ${n.defaultModes}.`,""].join("\n"));const r=await e.findAclDocUrl((0,b.sym)(n.target));return t.fetcher._fetch(r,{method:"PUT",body:o,headers:[["Content-Type","text/turtle"]]})},createEmptyRdfDoc:async function(e,n){await t.fetcher.webOperation("PUT",e.uri,{data:`# ${new Date} ${n}\n`,contentType:"text/turtle"})},followOrCreateLink:async function(e,n,r,i){await t.fetcher.load(i);const a=t.any(e,n,null,i);if(a)return a;if(!t.updater.editable(i)){const t=`followOrCreateLink: cannot edit ${i.value}`;throw s(t),new F(t)}try{await t.updater.update([],[(0,b.st)(e,n,r,i)])}catch(t){throw s(`followOrCreateLink: Error making link in ${i} to ${r}: ${t}`),new D(t)}try{await o(r)}catch(t){throw s(`followOrCreateLink: Error loading or saving new linked document: ${r}: ${t}`),t}return r},followOrCreateLinkWithContentOnCreate:async function(e,n,o,i,a){await t.fetcher.load(i);const c=t.any(e,n,null,i);if(c)return c;if(!t.updater.editable(i)){const t=`followOrCreateLinkWithContentOnCreate: cannot edit ${i.value}`;throw s(t),new F(t)}try{await t.updater.update([],[(0,b.st)(e,n,o,i)])}catch(t){const e=`followOrCreateLinkWithContentOnCreate: Error making link in ${i} to ${o}: ${t}`;throw s(e),new D(e)}try{await r(o,a)}catch(t){throw s(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${o}: ${t}`),t}return o},loadOrCreateIfNotExists:o,loadOrCreateWithContentOnCreate:r}}(n,r,i),l=q(n,o,c),d=P(n,l),u=S(n,l,c,i),w=K(n,o,l,c);return a("SolidAuthnLogic initialized"),{store:n,authn:o,acl:r,inbox:u,chat:d,profile:l,typeIndex:w,load:function(t){return n.fetcher.load(t)},updatePromise:function(t,e=[]){return new Promise((o,r)=>{n.updater.update(t,e,function(t,e,n){e?o():r(new Error(n))})})},clearStore:function(){n.statements.slice().forEach(n.remove.bind(n))}}}const X=async(t,e)=>{var n;const o=e&&e.credentials&&"omit"==e.credentials,r=m;if(((null===(n=null==r?void 0:r.info)||void 0===n?void 0:n.webId)||(null==r?void 0:r.webId))&&!o){const n="function"==typeof r.fetch?r.fetch.bind(r):"function"==typeof r.authFetch?r.authFetch.bind(r):null;return n?n(t,e):window.fetch(t,e)}return window.fetch(t,e)},Y=Symbol.for("solid-logic-singleton"),Z="undefined"!=typeof window?window:i.g;const G=(Z[Y]?a("SolidLogic: Using existing global singleton instance."):(a("SolidLogic: Creating new global singleton instance."),Z[Y]=V({fetch:X},m),a("Unique quadstore initialized.")),Z[Y]);async function J(t={}){if("undefined"==typeof window)return!1;const e=t.issuer||"",n=t.postLogoutRedirectPath||"/";try{if(e){const t=new URL(e);t.pathname="/.well-known/openid-configuration";const n=await fetch(t.toString(),{credentials:"include"});if(200===n.status){const t=await n.json();t&&t.end_session_endpoint&&await fetch(t.end_session_endpoint,{credentials:"include"})}}}catch(t){}try{const t=await fetch("/.well-known/solid/logout",{credentials:"include"});if(t.ok||t.redirected)return window.location.assign(n),!0}catch(t){}return!1}const Q=[{name:"Solid Community",uri:"https://solidcommunity.net"},{name:"Solid Web",uri:"https://solidweb.org"},{name:"Solid Web ME",uri:"https://solidweb.me"},{name:"Inrupt.com",uri:"https://login.inrupt.com"}];function tt(){const t=[...Q],{host:e,origin:n}=new URL(location.href);return t.map(({uri:t})=>new URL(t).host).includes(e)||t.unshift({name:e,uri:n}),t}const et=G.authn,nt=G.authn.authSession,ot=G.store;export{C as ACL_LINK,O as CrossOriginForbiddenError,j as FetchError,F as NotEditableError,M as NotFoundError,W as SameOriginForbiddenError,N as UnauthorizedError,D as WebOperationError,$ as appContext,nt as authSession,et as authn,K as createTypeIndexLogic,tt as getSuggestedIssuers,U as offlineTestID,J as performServerSideLogout,G as solidLogicSingleton,ot as store};
1
+ import{Session as t}from"@uvdsl/solid-oidc-client-browser";import*as e from"@uvdsl/solid-oidc-client-browser/core";import*as n from"rdflib";var o={386(t){const e={acl:"http://www.w3.org/ns/auth/acl#",arg:"http://www.w3.org/ns/pim/arg#",as:"https://www.w3.org/ns/activitystreams#",bookmark:"http://www.w3.org/2002/01/bookmark#",cal:"http://www.w3.org/2002/12/cal/ical#",cco:"http://www.ontologyrepository.com/CommonCoreOntologies/",cert:"http://www.w3.org/ns/auth/cert#",contact:"http://www.w3.org/2000/10/swap/pim/contact#",dc:"http://purl.org/dc/elements/1.1/",dct:"http://purl.org/dc/terms/",doap:"http://usefulinc.com/ns/doap#",foaf:"http://xmlns.com/foaf/0.1/",geo:"http://www.w3.org/2003/01/geo/wgs84_pos#",gpx:"http://www.w3.org/ns/pim/gpx#",gr:"http://purl.org/goodrelations/v1#",http:"http://www.w3.org/2007/ont/http#",httph:"http://www.w3.org/2007/ont/httph#",icalTZ:"http://www.w3.org/2002/12/cal/icaltzd#",ldp:"http://www.w3.org/ns/ldp#",link:"http://www.w3.org/2007/ont/link#",log:"http://www.w3.org/2000/10/swap/log#",meeting:"http://www.w3.org/ns/pim/meeting#",mo:"http://purl.org/ontology/mo/",org:"http://www.w3.org/ns/org#",owl:"http://www.w3.org/2002/07/owl#",pad:"http://www.w3.org/ns/pim/pad#",patch:"http://www.w3.org/ns/pim/patch#",prov:"http://www.w3.org/ns/prov#",pto:"http://www.productontology.org/id/",qu:"http://www.w3.org/2000/10/swap/pim/qif#",trip:"http://www.w3.org/ns/pim/trip#",rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",rss:"http://purl.org/rss/1.0/",sched:"http://www.w3.org/ns/pim/schedule#",schema:"http://schema.org/",sioc:"http://rdfs.org/sioc/ns#",skos:"http://www.w3.org/2004/02/skos/core#",solid:"http://www.w3.org/ns/solid/terms#",space:"http://www.w3.org/ns/pim/space#",stat:"http://www.w3.org/ns/posix/stat#",tab:"http://www.w3.org/2007/ont/link#",tabont:"http://www.w3.org/2007/ont/link#",ui:"http://www.w3.org/ns/ui#",vann:"http://purl.org/vocab/vann/",vcard:"http://www.w3.org/2006/vcard/ns#",wf:"http://www.w3.org/2005/01/wf/flow#",xsd:"http://www.w3.org/2001/XMLSchema#"};t.exports=function(t={namedNode:t=>t}){const n={};for(const o in e){const r=e[o];n[o]=function(e=""){return t.namedNode(r+e)}}return n}}},r={};function i(t){var e=r[t];if(void 0!==e)return e.exports;var n=r[t]={exports:{}};return o[t](n,n.exports,i),n.exports}function a(...t){console.log(...t)}function s(...t){console.warn(...t)}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const c=e;class l{constructor(){this.map=new Map}shouldPreserveExistingRefreshToken(t,e){return"refresh_token"===t&&(null==e||""===e)&&this.map.has(t)}async init(){return this}async setItem(t,e){this.shouldPreserveExistingRefreshToken(t,e)||this.map.set(t,e)}async getItem(t){return this.map.has(t)?this.map.get(t):null}async deleteItem(t){this.map.delete(t)}async clear(){this.map.clear()}close(){}}class d{constructor(){this.db=null,this.dbName="soidc",this.storeName="session",this.dbVersion=1}async shouldPreserveExistingRefreshToken(t,e){if("refresh_token"!==t||null!=e&&""!==e)return!1;const n=await this.getItem(t);return null!=n&&""!==n}async init(){if(this.db)return this;if("undefined"==typeof indexedDB)throw new Error("IndexedDB is not available in this environment");return await new Promise((t,e)=>{const n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=()=>e(n.error),n.onsuccess=()=>{this.db=n.result,t()},n.onupgradeneeded=()=>{const t=n.result;t.objectStoreNames.contains(this.storeName)||t.createObjectStore(this.storeName)}}),this}async setItem(t,e){await this.init(),await this.shouldPreserveExistingRefreshToken(t,e)||await this.withStore("readwrite",n=>n.put(e,t))}async getItem(t){return await this.init(),this.withStore("readonly",e=>e.get(t))}async deleteItem(t){await this.init(),await this.withStore("readwrite",e=>e.delete(t))}async clear(){await this.init(),await this.withStore("readwrite",t=>t.clear())}close(){this.db&&(this.db.close(),this.db=null)}withStore(t,e){return new Promise((n,o)=>{if(!this.db)return void o(new Error("Session database not initialized"));const r=this.db.transaction(this.storeName,t),i=r.objectStore(this.storeName),a=e(i);let s=null;r.onerror=()=>{var t;return o(null!==(t=r.error)&&void 0!==t?t:a.error)},r.onabort=()=>{var t,e;return o(null!==(e=null!==(t=r.error)&&void 0!==t?t:a.error)&&void 0!==e?e:new Error("IndexedDB transaction aborted"))},r.oncomplete=()=>n(s),a.onerror=()=>o(a.error),a.onsuccess=()=>{var t;s=null!==(t=a.result)&&void 0!==t?t:null}})}}const u=function(){var t,e,n;const o=c,r=null!==(n=null!==(t=o.SessionCore)&&void 0!==t?t:null===(e=o.default)||void 0===e?void 0:e.SessionCore)&&void 0!==n?n:o.default;return"function"!=typeof r?null:r}();const w=function(){if("undefined"!=typeof window&&(()=>{const t=window.location.hostname;return"localhost"===t||"127.0.0.1"===t||t.endsWith(".localhost")})())return u?new u(void 0,{database:new d}):new t;try{return new t}catch(e){console.warn("solid-logic: falling back to non-worker auth session:",e);try{return u?new u(void 0,{database:new d}):new t}catch(e){return console.warn("solid-logic: IndexedDB unavailable, using in-memory session database:",e),u?new u(void 0,{database:new l}):new t}}}();async function h(t){const e=await async function(t){try{const e=new URL(t),n=new URL("/.well-known/openid-configuration",e.origin),o=await fetch(n.toString(),{credentials:"include"});if(!o.ok)return null;const r=await o.json();return"string"==typeof(null==r?void 0:r.issuer)&&r.issuer?r.issuer.replace(/\/$/,""):null}catch(t){return null}}(t);return e||t}var f;const p=w,g="function"==typeof p.login?p.login.bind(w):void 0;if(g){const t=async(t,e)=>{var n,o,r,i;if(t&&"object"==typeof t&&!Array.isArray(t)){const e=null!==(o=null!==(n=t.oidcIssuer)&&void 0!==n?n:t.idp)&&void 0!==o?o:t.issuer,a=null!==(i=null!==(r=t.redirectUrl)&&void 0!==r?r:t.redirect_uri)&&void 0!==i?i:t.redirectUri;if("string"==typeof e&&"string"==typeof a)return g(await h(e),a)}return g("string"==typeof t?await h(t):t,e)};p.login=t}const y=new class{constructor(){this.listeners=new Map}on(t,e){this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e)}off(t,e){var n;null===(n=this.listeners.get(t))||void 0===n||n.delete(e)}emit(t,...e){var n;null===(n=this.listeners.get(t))||void 0===n||n.forEach(t=>t(...e))}};let v=null!==(f=w.isActive)&&void 0!==f?f:Boolean(w.webId);"function"==typeof w.addEventListener&&w.addEventListener("sessionStateChange",()=>{var t;const e=null!==(t=w.isActive)&&void 0!==t?t:Boolean(w.webId);v&&!e&&y.emit("logout"),v=e});const m=Object.assign(w,{events:y});Object.defineProperty(m,"info",{enumerable:!0,configurable:!0,get(){const t=w,e=!0===t.isActive||Boolean(t.webId);return{webId:t.webId,isLoggedIn:e}}});const b=n;var I=i(386);const x=i.n(I)()(b),C=(0,b.sym)("http://www.iana.org/assignments/link-relations/acl");function T(t){const e=x;function n(t,n,o,r={}){const i=r.public||[],a=(0,b.graph)(),s=(0,b.Namespace)("http://www.w3.org/ns/auth/acl#");let c=a.sym(`${o}#a1`);const l=a.sym(o),d=a.sym(t);if(a.add(c,e.rdf("type"),s("Authorization"),l),a.add(c,s("accessTo"),d,l),r.defaultForNew&&a.add(c,s("default"),d,l),a.add(c,s("agent"),n,l),a.add(c,s("mode"),s("Read"),l),a.add(c,s("mode"),s("Write"),l),a.add(c,s("mode"),s("Control"),l),i.length){c=a.sym(`${o}#a2`),a.add(c,e.rdf("type"),s("Authorization"),l),a.add(c,s("accessTo"),d,l),a.add(c,s("agentClass"),e.foaf("Agent"),l);for(let t=0;t<i.length;t++)a.add(c,s("mode"),s(i[t]),l)}return(0,b.serialize)(l,a,o)}return{findAclDocUrl:async function(e){await t.fetcher.load(e);const n=t.any(e,C);if(!n)throw new Error(`No ACL link discovered for ${e}`);return n.value},setACLUserPublic:function(e,o,r){const i=t.any(t.sym(e),C);return Promise.resolve().then(()=>i||function(e){const n=t.fetcher;if(!n)throw new Error("Cannot fetch ACL rel, store has no fetcher");return n.load(e).then(n=>{if(!n.ok)throw new Error("fetchACLRel: While loading:"+n.error);const o=t.any(t.sym(e),C);if(!o)throw new Error("fetchACLRel: No Link rel=ACL header for "+e);return o})}(e).catch(t=>{throw new Error(`Error fetching rel=ACL header for ${e}: ${t}`)})).then(i=>{const a=n(e,o,i.uri,r);if(!t.fetcher)throw new Error("Cannot PUT this, store has no fetcher");return t.fetcher.webOperation("PUT",i.uri,{data:a,contentType:"text/turtle"}).then(t=>{if(!t.ok)throw new Error("Error writing ACL text: "+t.error);return i})})},genACLText:n}}const $=()=>{let{SolidAppContext:t}=window;if(t||(t={}),t.viewingNoAuthPage=!1,t.noAuth&&window.document){if(window.document.location.href.startsWith(t.noAuth)){t.viewingNoAuthPage=!0;const e=new URLSearchParams(window.document.location.search);if(e){let n=t.viewedPage=e.get("uri")||null;if(n&&(n=decodeURI(n),!n.startsWith(t.noAuth))){const e=n.split(/\//);t.idp=e[0]+"//"+e[2],t.viewingNoAuthPage=!1}}}}return t};function L(){const{$SolidTestEnvironment:t}=window;if(void 0!==t&&t.username)return a("Assuming the user is "+t.username),(0,b.sym)(t.username);if("undefined"!=typeof document&&document.location&&"http://localhost"===(""+document.location).slice(0,16)){const t=document.getElementById("appTarget");if(!t)return null;const e=t.getAttribute("testID");return e?(a("Assuming user is "+e),(0,b.sym)(e)):null}return null}class U{constructor(t){this.checkUserInFlight=null,this.sessionRestoreHookAttached=!1,this.fallbackWebId=null,this.session=t}get authSession(){return this.session}currentUser(){var t,e;const n=$();if(n.viewingNoAuthPage)return(0,b.sym)(n.webId);const o=this.session,r=null===(t=null==o?void 0:o.info)||void 0===t?void 0:t.webId,i=null==o?void 0:o.webId,a=r||i||this.fallbackWebId,s=null===(e=null==o?void 0:o.info)||void 0===e?void 0:e.isLoggedIn,c=null==o?void 0:o.isActive,l=!0===s||!0===c||null==s&&null==c&&Boolean(a)||Boolean(this.fallbackWebId);return this&&this.session&&a&&l?(0,b.sym)(a):L()}async checkUser(t){var e;const n=new URL(window.location.href).hash;n&&window.localStorage.setItem("preLoginRedirectHash",n);const o=this.session;this.sessionRestoreHookAttached||"function"!=typeof(null===(e=null==o?void 0:o.events)||void 0===e?void 0:e.on)||(o.events.on("sessionRestore",t=>{a(`Session restored to ${t}`),document.location.toString()!==t&&history.replaceState(null,"",t)}),this.sessionRestoreHookAttached=!0),this.checkUserInFlight||(this.checkUserInFlight=this.resolveCurrentUser());const r=this.checkUserInFlight;let i;try{i=await r}finally{this.checkUserInFlight===r&&(this.checkUserInFlight=null)}return Promise.resolve(t?t(i):i)}async resolveCurrentUser(){var t,e,n,o,r,i;const s=this.session,c=new URL(window.location.href);if(c.hash="","function"==typeof(null==s?void 0:s.handleIncomingRedirect))await s.handleIncomingRedirect({restorePreviousSession:!0,url:c.href});else{if("function"==typeof(null==s?void 0:s.restore)){const o=null!==(t=null==s?void 0:s.isActive)&&void 0!==t?t:Boolean(null==s?void 0:s.webId);try{await s.restore()}catch(t){const e=t instanceof Error?t.message:String(t);if(!/no session to restore/i.test(e))throw t;a("No previous session to restore")}const r=null!==(e=null==s?void 0:s.isActive)&&void 0!==e?e:Boolean(null==s?void 0:s.webId);!o&&r&&(null===(n=s.events)||void 0===n||n.emit("sessionRestore",window.location.href))}if("function"==typeof(null==s?void 0:s.handleRedirectFromLogin)){const t=null!==(o=null==s?void 0:s.isActive)&&void 0!==o?o:Boolean(null==s?void 0:s.webId);await s.handleRedirectFromLogin();const e=null!==(r=null==s?void 0:s.isActive)&&void 0!==r?r:Boolean(null==s?void 0:s.webId);!t&&e&&(null===(i=s.events)||void 0===i||i.emit("login"))}}const l=window.localStorage.getItem("preLoginRedirectHash");if(l){const t=new URL(window.location.href);t.hash!==l&&(history.pushState?history.pushState(null,document.title,l):location.hash=l,t.hash=l),window.localStorage.setItem("preLoginRedirectHash","")}let d=L();if(d)return d;let u=this.webIdFromSession(null==s?void 0:s.info,s);return u||(u=await this.probeNssCookieBackedWebId()),this.fallbackWebId=u||null,u&&(d=this.saveUser(u)),d&&a(`(Logged in as ${d} by authentication)`),d}async probeNssCookieBackedWebId(){if("undefined"==typeof window)return null;const{hostname:t,port:e,protocol:n}=window.location,o=".localhost";if(!t.endsWith(o))return null;const r=t.slice(0,-10);if(!r||"localhost"===r||r.includes("."))return null;try{if(403!==(await fetch("/account/password/change",{credentials:"include",redirect:"manual",cache:"no-store"})).status)return null;return`${`${n}//${t}${e?`:${e}`:""}`}/profile/card#me`}catch(t){return null}}saveUser(t,e){let n;if(t){n="string"==typeof t?t:t.uri;const o=(0,b.namedNode)(n);return e&&(e.me=o),o}return null}webIdFromSession(t,e){const n=(null==t?void 0:t.webId)||(null==e?void 0:e.webId);if(!n)return null;const o=null==t?void 0:t.isLoggedIn,r=null==e?void 0:e.isLoggedIn,i=null==e?void 0:e.isActive;return!0===o||!0===r||!0===i?n:!1===o&&!1===r&&!1===i?null:n}}function k(t){return(0,b.sym)(t.uri+"#id"+Date.now())}function E(t){return!t||`${window.location.origin}/`!==new URL(t.value).origin}const A="index.ttl#this";function P(t,e){const n=x;async function o(e,n,o){await t.fetcher.load(e);const r=t.any(e,new b.NamedNode("http://www.iana.org/assignments/link-relations/acl"));if(!r)throw new Error("Chat ACL doc not found!");const i=`\n @prefix acl: <http://www.w3.org/ns/auth/acl#>.\n <#owner>\n a acl:Authorization;\n acl:agent <${n.value}>;\n acl:accessTo <.>;\n acl:default <.>;\n acl:mode\n acl:Read, acl:Write, acl:Control.\n <#invitee>\n a acl:Authorization;\n acl:agent <${o.value}>;\n acl:accessTo <.>;\n acl:default <.>;\n acl:mode\n acl:Read, acl:Append.\n `;await t.fetcher.webOperation("PUT",r.value,{data:i,contentType:"text/turtle"})}async function r(e,o){const r=t.any(o,n.solid("privateTypeIndex"));if(!r)throw new Error("Private type index not found!");await t.fetcher.load(r);const i=k(r),a=[(0,b.st)(i,n.rdf("type"),n.solid("TypeRegistration"),r.doc()),(0,b.st)(i,n.solid("forClass"),n.meeting("LongChat"),r.doc()),(0,b.st)(i,n.solid("instance"),e,r.doc())];await new Promise((e,n)=>{t.updater.update([],a,function(t,o,r){o?e(null):n(new Error(r))})})}async function i(n){const o=await e.loadMe(),r=function(t,e){const n=new URL(`IndividualChats/${new URL(t.value).host}/`,e.value).toString();return new b.NamedNode(n)}(n,await e.getPodRoot(o));let i=!0;try{await t.fetcher.load(new b.NamedNode(r.value+"index.ttl#this"))}catch(t){i=!1}return{me:o,chatContainer:r,exists:i}}async function a(t,e){return(await s({me:e,newBase:t.value})).newInstance}function s(e){const o=t,r=o.updater;if(e.me&&!e.me.uri)throw new Error("chat mintNew: Invalid userid "+e.me);const i=e.newInstance=e.newInstance||o.sym(e.newBase+A),a=i.doc();return o.add(i,n.rdf("type"),n.meeting("LongChat"),a),o.add(i,n.dc("title"),"Chat channel",a),o.add(i,n.dc("created"),(0,b.term)(new Date(Date.now())),a),e.me&&o.add(i,n.dc("author"),e.me,a),new Promise(function(t,n){null==r||r.put(a,o.statementsMatching(void 0,void 0,void 0,a),"text/turtle",function(o,r,a){r?t({...e,newInstance:i}):n(new Error("FAILED to save new chat channel at: "+o+" : "+a))})})}async function c(e,o){var r;await t.fetcher.load(e.doc());const i=t.any(e,n.ldp("inbox"),void 0,e.doc());if(!i)throw new Error(`Invitee inbox not found! ${e.value}`);const a=`\n <> a <http://www.w3.org/ns/pim/meeting#LongChatInvite> ;\n ${n.rdf("seeAlso")} <${o.value}> .\n `,s=await(null===(r=t.fetcher)||void 0===r?void 0:r.webOperation("POST",i.value,{data:a,contentType:"text/turtle"}));if(!(null==s?void 0:s.headers.get("location")))throw new Error(`Invite sending returned a ${null==s?void 0:s.status}`)}return{setAcl:o,addToPrivateTypeIndex:r,findChat:i,createChatThing:a,getChat:async function(t,e=!0){const{me:n,chatContainer:s,exists:l}=await i(t);if(l)return new b.NamedNode(s.value+A);if(e){const e=await a(s,n);return await c(t,e),await o(s,n,t),await r(e,n),e}return null},sendInvite:c,mintNew:s}}function S(t,e,n,o,r){return{createInboxFor:async function(t,r){const i=await e.loadMe(),a=`${(await e.getPodRoot(i)).value}p2p-inboxes/${encodeURIComponent(r)}/`;return await o.createContainer(a),await n.setSinglePeerAccess({ownerWebId:i.value,peerWebId:t,accessToModes:"acl:Append",target:a}),a},getNewMessages:async function(t){t||(t=await e.loadMe());const n=await e.getMainInbox(t);return(await o.getContainerMembers(n)).filter(t=>!o.isContainer(t))},markAsRead:async function(e,n){const o=await t.fetcher._fetch(e);if(200!==o.status)throw new Error(`Not OK! ${e}`);const r=function(t,e){const n=e.getUTCFullYear(),o=("0"+(e.getUTCMonth()+1)).slice(-2),r=("0"+e.getUTCDate()).slice(-2),i=t.split("/"),a=i[i.length-1];return new URL(`./archive/${n}/${o}/${r}/${a}`,t).toString()}(e,n),i={method:"PUT",body:await o.text(),headers:[["Content-Type",o.headers.get("Content-Type")||"application/octet-stream"]]};"2"===(await t.fetcher._fetch(r,i)).status.toString()[0]&&await t.fetcher._fetch(e,{method:"DELETE"})}}}class R extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=new.target.name}}class O extends R{}class N extends R{}class W extends R{}class M extends R{}class F extends R{}class D extends R{}class j extends R{constructor(t,e){super(e),this.status=t}}function B(){return["@prefix solid: <http://www.w3.org/ns/solid/terms#>.","<>"," a solid:TypeIndex ;"," a solid:ListedDocument."].join("\n")}function _(){return["@prefix solid: <http://www.w3.org/ns/solid/terms#>.","<>"," a solid:TypeIndex ;"," a solid:UnlistedDocument."].join("\n")}function z(t,e){const n=new URL(e).pathname.split("/").pop()||"publicTypeIndex.ttl";return["# ACL resource for the Public Type Index","","@prefix acl: <http://www.w3.org/ns/auth/acl#>.","@prefix foaf: <http://xmlns.com/foaf/0.1/>.","","<#owner>"," a acl:Authorization;",""," acl:agent",` <${t}>;`,"",` acl:accessTo <./${n}>;`,""," acl:mode"," acl:Read, acl:Write, acl:Control.","","# Public-readable","<#public>"," a acl:Authorization;",""," acl:agentClass foaf:Agent;","",` acl:accessTo <./${n}>;`,""," acl:mode acl:Read."].join("\n")}function H(t){function e(e){return t.statementsMatching(e,(0,b.sym)("http://www.w3.org/ns/ldp#contains"),void 0).map(t=>t.object)}function n(t){const e=t.value;return"/"===e.charAt(e.length-1)}return{isContainer:n,createContainer:async function(e){if(!n((0,b.sym)(e)))throw new Error(`Not a container URL ${e}`);const o=await t.fetcher._fetch(e,{method:"PUT",headers:{"Content-Type":"text/turtle","If-None-Match":"*",Link:'<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"'},body:" "});if(409!==o.status&&"2"!==o.status.toString()[0])throw new Error(`Not OK: got ${o.status} response while creating container at ${e}`)},getContainerElements:e,getContainerMembers:async function(n){return await t.fetcher.load(n),e(n)}}}function q(t,e,n){const o=x,r=H(t),i=new Map,a=new Map;function c(t){return!!t&&(t.startsWith("https://")||t.startsWith("http://"))}function l(t){const e=t.doc(),n=e.dir();if((null==n?void 0:n.uri)&&c(n.uri))return n.uri;const o=e.uri;if(!o||!c(o))return null;const r=o.split("#")[0],i=r.lastIndexOf("/");return-1===i?null:r.slice(0,i+1)}function d(t,e){const n=l(t);if(!n)throw new Error(`Cannot derive directory for preferences file ${t.uri}`);return(0,b.sym)(n+e)}function u(t){var e;if(404===(null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.status))return!0;const n=`${(null==t?void 0:t.message)||t||""}`;return n.includes("404")||n.includes("Not Found")}async function w(e,n){var o;const i=l(n);if(!i)throw new Error(`Cannot derive settings directory from ${n.uri}`);await async function(e){const n=(0,b.sym)(e);try{return void await t.fetcher.load(n)}catch(t){if(!u(t))throw t}await r.createContainer(e)}(i);const a=(0,b.sym)(i);let s;try{await t.fetcher.load(a),s=null===(o=t.any(a,C))||void 0===o?void 0:o.value}catch(t){if(!u(t))throw t}s||(s=`${i}.acl`);const c=(0,b.sym)(s);try{return void await t.fetcher.load(c)}catch(t){if(!u(t))throw t}var d;await t.fetcher.webOperation("PUT",c.uri,{data:(d=e.uri,["@prefix acl: <http://www.w3.org/ns/auth/acl#>.","","<#owner>","a acl:Authorization;",`acl:agent <${d}>;`,"acl:accessTo <./>;","acl:default <./>;","acl:mode acl:Read, acl:Write, acl:Control."].join("\n")),contentType:"text/turtle"})}async function h(e,r){const i=r.doc(),a=e.doc();await t.fetcher.load(i);const s=t.any(e,o.solid("publicTypeIndex"),null,a),c=t.any(e,o.solid("publicTypeIndex"),null,i),l=s||c||d(r,"publicTypeIndex.ttl"),w=t.any(e,o.solid("privateTypeIndex"),null,i)||d(r,"privateTypeIndex.ttl"),h=!s;h&&await n.followOrCreateLinkWithContentOnCreate(e,o.solid("publicTypeIndex"),l,a,B());const f=[];t.holds(i,o.rdf("type"),o.space("ConfigurationFile"),i)||f.push((0,b.st)(i,o.rdf("type"),o.space("ConfigurationFile"),i)),t.holds(i,o.dct("title"),void 0,i)||f.push((0,b.st)(i,o.dct("title"),(0,b.literal)("Preferences file"),i)),t.holds(e,o.solid("publicTypeIndex"),l,i)||f.push((0,b.st)(e,o.solid("publicTypeIndex"),l,i)),t.holds(e,o.solid("privateTypeIndex"),w,i)||f.push((0,b.st)(e,o.solid("privateTypeIndex"),w,i)),f.length>0&&(await t.updater.update([],f),await t.fetcher.load(i)),await async function(e,o,r=!1){var i,a,s;if(!await n.loadOrCreateWithContentOnCreate(o,B())&&!r)return;let c;try{await t.fetcher.load(o),c=null===(i=t.any(o,C))||void 0===i?void 0:i.value}catch(t){if(!u(t))throw t}c||(c=`${o.uri}.acl`);const l=(0,b.sym)(c);try{await t.fetcher.webOperation("PUT",l.uri,{data:z(e.uri,o.uri),contentType:"text/turtle",headers:{"If-None-Match":"*"}})}catch(t){if(412!==(null!==(s=null===(a=null==t?void 0:t.response)||void 0===a?void 0:a.status)&&void 0!==s?s:null==t?void 0:t.status))throw t}}(e,l,h),await async function(t){await n.loadOrCreateWithContentOnCreate(t,_())}(w)}async function f(t){var e,o;try{return!!await n.loadOrCreateWithContentOnCreate(t,["@prefix dct: <http://purl.org/dc/terms/>.","@prefix pim: <http://www.w3.org/ns/pim/space#>.","@prefix solid: <http://www.w3.org/ns/solid/terms#>.","<>"," a pim:ConfigurationFile ;",' dct:title "Preferences file".'].join("\n"))}catch(n){if(401===(null===(e=n.response)||void 0===e?void 0:e.status))throw new O;if(403===(null===(o=n.response)||void 0===o?void 0:o.status)){if(E(t))throw new N;throw new W}throw n}}async function p(e){const r=a.get(e.uri);if(r)return r;const c=i.get(e.uri);if(c)return c;const l=(async()=>{var r;await g(e);const i=function(t){const e=t.uri.replace("/profile/","/").replace("/public/","/").split("/").slice(0,-1).join("/")+"/settings/prefs.ttl";return(0,b.sym)(e)}(e);let c;try{const r=t.any(e,o.space("preferencesFile"),null,e.doc());c=r||await n.followOrCreateLink(e,o.space("preferencesFile"),i,e.doc()),await w(e,c),await f(c),await h(e,c)}catch(t){if(s(`User ${e} has no pointer in profile to preferences file.`),t instanceof F)throw t;if(t instanceof D)throw t;if(t instanceof O)throw t;if(t instanceof N)throw t;if(t instanceof W)throw t;if(t instanceof j)throw t;throw t}try{await t.fetcher.load(c)}catch(n){const o=`Unable to load preference of user ${e}: ${n}`;if(404===(null===(r=n.response)||void 0===r?void 0:r.status))return await w(e,c),await f(c),await h(e,c),await t.fetcher.load(c),c;if(s(o),401===n.response.status)throw new O;if(403===n.response.status){if(E(c))throw new N;throw new W}throw new Error(o)}return a.set(e.uri,c),c})();i.set(e.uri,l);try{return await l}finally{i.get(e.uri)===l&&i.delete(e.uri)}}async function g(e){if(!e)throw new Error("loadProfile: no user given.");try{await t.fetcher.load(e.doc())}catch(t){throw new Error(`Unable to load profile of user ${e}: ${t}`)}return e.doc()}function y(e){return t.any(e,o.space("storage"),void 0,e.doc())}return{loadMe:async function(){const n=e.currentUser();if(null===n)throw new Error("Current user not found! Not logged in?");return await t.fetcher.load(n.doc()),n},getPodRoot:function(t){const e=y(t);if(!e)throw new Error("User pod root not found!");return e},getMainInbox:async function(e){await t.fetcher.load(e);const n=t.any(e,o.ldp("inbox"),void 0,e.doc());if(!n)throw new Error("User main inbox not found!");return n},findStorage:y,loadPreferences:p,loadProfile:g,silencedLoadPreferences:async function(t){try{return await p(t)}catch(t){return}}}}function K(t,e,n,o){const r=x;function i(t){return!!t&&(t.startsWith("https://")||t.startsWith("http://"))}async function c(e){if(!e)throw new Error("loadTypeIndexesFor: No user given");const i=await n.loadProfile(e);let a,c=null;try{c=h(e)}catch(t){s(`User ${e} has no usable profile document directory for publicTypeIndex.`)}try{const n=t.any(e,r.solid("publicTypeIndex"),void 0,i);a=n||(c?await o.followOrCreateLinkWithContentOnCreate(e,r.solid("publicTypeIndex"),c,i,B()):null)}catch(t){s(`User ${e} has no pointer in profile to publicTypeIndex file: ${t}`)}const l=a?[{label:"public",index:a,agent:e}]:[];let d,u;try{d=await n.silencedLoadPreferences(e)}catch(t){d=null}if(d){let n,a=null;try{a=f(d)}catch(t){s(`User ${e} has no usable preferences document directory for privateTypeIndex.`)}try{const s=t.any(e,r.solid("privateTypeIndex"),void 0,i);n=s||(a?await o.followOrCreateLinkWithContentOnCreate(e,r.solid("privateTypeIndex"),a,d,_()):null)}catch(t){s(`User ${e} has no pointer in preference file to privateTypeIndex file: ${t}`)}u=n?[{label:"private",index:n,agent:e}]:[]}else u=[];const w=l.concat(u);if(0===w.length)return w;const p=w.map(t=>t.index);try{await t.fetcher.load(p)}catch(t){s("Problems loading type index: ",t)}return w}async function l(e){let o;try{o=await n.silencedLoadPreferences(e)}catch(t){s(`User ${e} has no pointer in profile to preferences file.`)}if(o){const n=t.each(e,r.solid("community"),void 0,o).concat(t.each(e,r.solid("community"),void 0,e.doc()));let a=[];for(const t of n)if("NamedNode"===t.termType&&i(t.uri))try{a=a.concat(await c(t))}catch(e){s(`Skipping community type indexes for ${t.uri}: ${e}`)}else s(`Skipping malformed community node for ${e}: ${t}`);return a}return[]}async function d(t){return(await c(t)).concat(await l(t))}async function u(t,e){const n=await d(e);let o=[];for(const e of n){const n=await p(e,t);o=o.concat(n)}return o}function w(t){const e=t.doc(),n=e.dir();if((null==n?void 0:n.uri)&&i(n.uri))return n.uri;const o=e.uri;if(!o||!i(o))return a(`docDirUri: missing or non-http(s) doc uri for ${null==t?void 0:t.uri}`),null;const r=o.split("#")[0],s=r.lastIndexOf("/");return-1===s?(a(`docDirUri: no slash in doc uri ${o}`),null):r.slice(0,s+1)}function h(t){const e=w(t);if(!e)throw new Error(`suggestPublicTypeIndex: Cannot derive directory for ${t.uri}`);return(0,b.sym)(e+"publicTypeIndex.ttl")}function f(t){const e=w(t);if(!e)throw new Error(`suggestPrivateTypeIndex: Cannot derive directory for ${t.uri}`);return(0,b.sym)(e+"privateTypeIndex.ttl")}async function p(e,n){const o=e.index,i=[],a=t.statementsMatching(null,r.solid("instance"),null,o).concat(t.statementsMatching(null,r.solid("instanceContainer"),null,o)).map(t=>t.subject);for(const s of a){const a=t.any(s,r.solid("forClass"),null,o);if(!n||a.sameTerm(n)){const n=t.each(s,r.solid("instance"),null,o);for(const t of n)i.push({instance:t,type:a,scope:e});const c=t.each(s,r.solid("instanceContainer"),null,o);for(const n of c)await t.fetcher.load(n),i.push({instance:(0,b.sym)(n.value),type:a,scope:e})}}return i}return{registerInTypeIndex:async function(e,n,o){const i=k(n),a=[(0,b.st)(i,r.rdf("type"),r.solid("TypeRegistration"),n),(0,b.st)(i,r.solid("forClass"),o,n),(0,b.st)(i,r.solid("instance"),e,n)];try{await t.updater.update([],a)}catch(t){const o=`Unable to register ${e} in index ${n}: ${t}`;return console.warn(o),null}return i},getRegistrations:function(e,n){return t.each(void 0,r.solid("instance"),e).filter(e=>t.holds(e,r.solid("forClass"),n))},loadTypeIndexesFor:c,loadCommunityTypeIndexes:l,loadAllTypeIndexes:d,getScopedAppInstances:u,getAppInstances:async function(t){const n=e.currentUser();if(!n)throw new Error("getAppInstances: Must be logged in to find apps.");return(await u(t,n)).map(t=>t.instance)},suggestPublicTypeIndex:h,suggestPrivateTypeIndex:f,deleteTypeIndexRegistration:async function(e){const n=t.the(null,r.solid("instance"),e.instance,e.scope.index);if(!n)throw new Error(`deleteTypeIndexRegistration: No registration found for ${e.instance}`);const o=t.statementsMatching(n,null,null,e.scope.index);await t.updater.update(o,[])},getScopedAppsFromIndex:p}}function V(t,e){a("SolidLogic: Unique instance created. There should only be one of these.");const n=b.graph();b.fetcher(n,{fetch:t.fetch}),n.updater=new b.UpdateManager(n),n.features=[];const o=new U(e),r=T(n),i=H(n),c=function(t,e,n){async function o(e){var n,o,r,i,a;try{return await t.fetcher.load(e)}catch(s){if(404===(null===(n=null==s?void 0:s.response)||void 0===n?void 0:n.status)){try{await t.fetcher.webOperation("PUT",e.uri,{data:"",contentType:"text/turtle",headers:{"If-None-Match":"*"}})}catch(t){if(412!==(null!==(r=null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status)&&void 0!==r?r:null==t?void 0:t.status))throw new D(`createIfNotExists: PUT FAILED: ${e}: ${t}`)}return await t.fetcher.load(e)}if(401===(null===(i=null==s?void 0:s.response)||void 0===i?void 0:i.status))throw new O;if(403===(null===(a=null==s?void 0:s.response)||void 0===a?void 0:a.status)){if(E(e))throw new N;throw new W}const c=`createIfNotExists doc load error: ${e}: ${s}`;throw new j(null==s?void 0:s.status,`${(null==s?void 0:s.message)||""}${c}`)}}async function r(e,n){var o,r,i,a;try{return await t.fetcher.load(e),!1}catch(t){if(404!==(null!==(r=null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status)&&void 0!==r?r:null==t?void 0:t.status))throw t}try{return await t.fetcher.webOperation("PUT",e.uri,{data:n,contentType:"text/turtle",headers:{"If-None-Match":"*"}}),!0}catch(t){if(412===(null!==(a=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.status)&&void 0!==a?a:null==t?void 0:t.status))return!1;throw t}}return{recursiveDelete:async function o(r){try{if(n.isContainer(r)){const i=await e.findAclDocUrl(r);await t.fetcher._fetch(i,{method:"DELETE"});const a=await n.getContainerMembers(r);await Promise.all(a.map(t=>o(t)))}return t.fetcher._fetch(r.value,{method:"DELETE"})}catch(t){a(`Please manually remove ${r.value} from your system.`,t)}},setSinglePeerAccess:async function(n){let o=["@prefix acl: <http://www.w3.org/ns/auth/acl#>.","","<#alice> a acl:Authorization;\n acl:agent <"+n.ownerWebId+">;",` acl:accessTo <${n.target}>;`,` acl:default <${n.target}>;`," acl:mode acl:Read, acl:Write, acl:Control.",""].join("\n");n.accessToModes&&(o+=["<#bobAccessTo> a acl:Authorization;",` acl:agent <${n.peerWebId}>;`,` acl:accessTo <${n.target}>;`,` acl:mode ${n.accessToModes}.`,""].join("\n")),n.defaultModes&&(o+=["<#bobDefault> a acl:Authorization;",` acl:agent <${n.peerWebId}>;`,` acl:default <${n.target}>;`,` acl:mode ${n.defaultModes}.`,""].join("\n"));const r=await e.findAclDocUrl((0,b.sym)(n.target));return t.fetcher._fetch(r,{method:"PUT",body:o,headers:[["Content-Type","text/turtle"]]})},createEmptyRdfDoc:async function(e,n){await t.fetcher.webOperation("PUT",e.uri,{data:`# ${new Date} ${n}\n`,contentType:"text/turtle"})},followOrCreateLink:async function(e,n,r,i){await t.fetcher.load(i);const a=t.any(e,n,null,i);if(a)return a;if(!t.updater.editable(i)){const t=`followOrCreateLink: cannot edit ${i.value}`;throw s(t),new F(t)}try{await t.updater.update([],[(0,b.st)(e,n,r,i)])}catch(t){throw s(`followOrCreateLink: Error making link in ${i} to ${r}: ${t}`),new D(t)}try{await o(r)}catch(t){throw s(`followOrCreateLink: Error loading or saving new linked document: ${r}: ${t}`),t}return r},followOrCreateLinkWithContentOnCreate:async function(e,n,o,i,a){await t.fetcher.load(i);const c=t.any(e,n,null,i);if(c)return c;if(!t.updater.editable(i)){const t=`followOrCreateLinkWithContentOnCreate: cannot edit ${i.value}`;throw s(t),new F(t)}try{await t.updater.update([],[(0,b.st)(e,n,o,i)])}catch(t){const e=`followOrCreateLinkWithContentOnCreate: Error making link in ${i} to ${o}: ${t}`;throw s(e),new D(e)}try{await r(o,a)}catch(t){throw s(`followOrCreateLinkWithContentOnCreate: Error loading or saving new linked document: ${o}: ${t}`),t}return o},loadOrCreateIfNotExists:o,loadOrCreateWithContentOnCreate:r}}(n,r,i),l=q(n,o,c),d=P(n,l),u=S(n,l,c,i),w=K(n,o,l,c);return a("SolidAuthnLogic initialized"),{store:n,authn:o,acl:r,inbox:u,chat:d,profile:l,typeIndex:w,load:function(t){return n.fetcher.load(t)},updatePromise:function(t,e=[]){return new Promise((o,r)=>{n.updater.update(t,e,function(t,e,n){e?o():r(new Error(n))})})},clearStore:function(){n.statements.slice().forEach(n.remove.bind(n))}}}const X=async(t,e)=>{var n;const o=e&&e.credentials&&"omit"==e.credentials,r=m;if(((null===(n=null==r?void 0:r.info)||void 0===n?void 0:n.webId)||(null==r?void 0:r.webId))&&!o){const n="function"==typeof r.fetch?r.fetch.bind(r):"function"==typeof r.authFetch?r.authFetch.bind(r):null;return n?n(t,e):window.fetch(t,e)}return window.fetch(t,e)},Y=Symbol.for("solid-logic-singleton"),Z="undefined"!=typeof window?window:i.g;const G=(Z[Y]?a("SolidLogic: Using existing global singleton instance."):(a("SolidLogic: Creating new global singleton instance."),Z[Y]=V({fetch:X},m),a("Unique quadstore initialized.")),Z[Y]);async function J(t={}){if("undefined"==typeof window)return!1;const e=t.issuer||"",n=t.postLogoutRedirectPath||"/";try{if(e){const t=new URL(e);t.pathname="/.well-known/openid-configuration";const n=await fetch(t.toString(),{credentials:"include"});if(200===n.status){const t=await n.json();t&&t.end_session_endpoint&&await fetch(t.end_session_endpoint,{credentials:"include"})}}}catch(t){}try{const t=await fetch("/.well-known/solid/logout",{credentials:"include"});if(t.ok||t.redirected)return window.location.assign(n),!0}catch(t){}return!1}const Q=[{name:"Solid Community",uri:"https://solidcommunity.net"},{name:"Solid Web",uri:"https://solidweb.org"},{name:"Solid Web ME",uri:"https://solidweb.me"},{name:"Inrupt.com",uri:"https://login.inrupt.com"}];function tt(){const t=[...Q],{host:e,origin:n}=new URL(location.href);return t.map(({uri:t})=>new URL(t).host).includes(e)||t.unshift({name:e,uri:n}),t}const et=G.authn,nt=G.authn.authSession,ot=G.store;export{C as ACL_LINK,N as CrossOriginForbiddenError,j as FetchError,F as NotEditableError,M as NotFoundError,W as SameOriginForbiddenError,O as UnauthorizedError,D as WebOperationError,$ as appContext,nt as authSession,et as authn,K as createTypeIndexLogic,tt as getSuggestedIssuers,L as offlineTestID,J as performServerSideLogout,G as solidLogicSingleton,ot as store};
2
2
  //# sourceMappingURL=solid-logic.esm.min.js.map