solid-logic 5.0.0 → 6.0.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.
- package/README.md +3 -4
- package/dist/_virtual/_rolldown/runtime.cjs.js +1 -0
- package/dist/acl/aclLogic.cjs.js +2 -0
- package/dist/acl/aclLogic.cjs.js.map +1 -0
- package/dist/acl/aclLogic.esm.js +56 -0
- package/dist/acl/aclLogic.esm.js.map +1 -0
- package/dist/authSession/authSession.cjs.js +2 -0
- package/dist/authSession/authSession.cjs.js.map +1 -0
- package/dist/authSession/authSession.esm.js +22 -0
- package/dist/authSession/authSession.esm.js.map +1 -0
- package/dist/authSession/events.cjs.js +2 -0
- package/dist/authSession/events.cjs.js.map +1 -0
- package/dist/authSession/events.esm.js +19 -0
- package/dist/authSession/events.esm.js.map +1 -0
- package/dist/authSession/issuer.cjs.js +2 -0
- package/dist/authSession/issuer.cjs.js.map +1 -0
- package/dist/authSession/issuer.esm.js +18 -0
- package/dist/authSession/issuer.esm.js.map +1 -0
- package/dist/authSession/session.cjs.js +2 -0
- package/dist/authSession/session.cjs.js.map +1 -0
- package/dist/authSession/session.esm.js +102 -0
- package/dist/authSession/session.esm.js.map +1 -0
- package/dist/authn/SolidAuthnLogic.cjs.js +2 -0
- package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -0
- package/dist/authn/SolidAuthnLogic.esm.js +116 -0
- package/dist/authn/SolidAuthnLogic.esm.js.map +1 -0
- package/dist/authn/authUtil.cjs.js +2 -0
- package/dist/authn/authUtil.cjs.js.map +1 -0
- package/dist/authn/authUtil.esm.js +33 -0
- package/dist/authn/authUtil.esm.js.map +1 -0
- package/dist/authn/serverLogout.cjs.js +2 -0
- package/dist/authn/serverLogout.cjs.js.map +1 -0
- package/dist/authn/serverLogout.esm.js +25 -0
- package/dist/authn/serverLogout.esm.js.map +1 -0
- package/dist/chat/chatLogic.cjs.js +21 -0
- package/dist/chat/chatLogic.cjs.js.map +1 -0
- package/dist/chat/chatLogic.esm.js +116 -0
- package/dist/chat/chatLogic.esm.js.map +1 -0
- package/dist/inbox/inboxLogic.cjs.js +2 -0
- package/dist/inbox/inboxLogic.cjs.js.map +1 -0
- package/dist/inbox/inboxLogic.esm.js +37 -0
- package/dist/inbox/inboxLogic.esm.js.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +13 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/issuer/issuerLogic.cjs.js +2 -0
- package/dist/issuer/issuerLogic.cjs.js.map +1 -0
- package/dist/issuer/issuerLogic.esm.js +30 -0
- package/dist/issuer/issuerLogic.esm.js.map +1 -0
- package/dist/logic/CustomError.cjs.js +2 -0
- package/dist/logic/CustomError.cjs.js.map +1 -0
- package/dist/logic/CustomError.esm.js +14 -0
- package/dist/logic/CustomError.esm.js.map +1 -0
- package/dist/logic/solidLogic.cjs.js +2 -0
- package/dist/logic/solidLogic.cjs.js.map +1 -0
- package/dist/logic/solidLogic.esm.js +49 -0
- package/dist/logic/solidLogic.esm.js.map +1 -0
- package/dist/logic/solidLogicSingleton.cjs.js +2 -0
- package/dist/logic/solidLogicSingleton.cjs.js.map +1 -0
- package/dist/logic/solidLogicSingleton.esm.js +19 -0
- package/dist/logic/solidLogicSingleton.esm.js.map +1 -0
- package/dist/profile/profileAclDocuments.cjs.js +3 -0
- package/dist/profile/profileAclDocuments.cjs.js.map +1 -0
- package/dist/profile/profileAclDocuments.esm.js +17 -0
- package/dist/profile/profileAclDocuments.esm.js.map +1 -0
- package/dist/profile/profileDocuments.cjs.js +3 -0
- package/dist/profile/profileDocuments.cjs.js.map +1 -0
- package/dist/profile/profileDocuments.esm.js +15 -0
- package/dist/profile/profileDocuments.esm.js.map +1 -0
- package/dist/profile/profileLogic.cjs.js +2 -0
- package/dist/profile/profileLogic.cjs.js.map +1 -0
- package/dist/profile/profileLogic.esm.js +184 -0
- package/dist/profile/profileLogic.esm.js.map +1 -0
- package/dist/resource/resourceHttp.cjs.js +2 -0
- package/dist/resource/resourceHttp.cjs.js.map +1 -0
- package/dist/resource/resourceHttp.esm.js +21 -0
- package/dist/resource/resourceHttp.esm.js.map +1 -0
- package/dist/resource/resourceLogic.cjs.js +2 -0
- package/dist/resource/resourceLogic.cjs.js.map +1 -0
- package/dist/resource/resourceLogic.esm.js +130 -0
- package/dist/resource/resourceLogic.esm.js.map +1 -0
- package/dist/resource/resourceMetadata.cjs.js +2 -0
- package/dist/resource/resourceMetadata.cjs.js.map +1 -0
- package/dist/resource/resourceMetadata.esm.js +28 -0
- package/dist/resource/resourceMetadata.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.cjs.js +3 -0
- package/dist/typeIndex/typeIndexAclDocuments.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexAclDocuments.esm.js +35 -0
- package/dist/typeIndex/typeIndexAclDocuments.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.cjs.js +4 -0
- package/dist/typeIndex/typeIndexDocuments.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexDocuments.esm.js +21 -0
- package/dist/typeIndex/typeIndexDocuments.esm.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js +2 -0
- package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -0
- package/dist/typeIndex/typeIndexLogic.esm.js +210 -0
- package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -0
- package/dist/util/containerLogic.cjs.js +2 -0
- package/dist/util/containerLogic.cjs.js.map +1 -0
- package/dist/util/containerLogic.esm.js +42 -0
- package/dist/util/containerLogic.esm.js.map +1 -0
- package/dist/util/debug.cjs.js +2 -0
- package/dist/util/debug.cjs.js.map +1 -0
- package/dist/util/debug.esm.js +11 -0
- package/dist/util/debug.esm.js.map +1 -0
- package/dist/util/ns.cjs.js +2 -0
- package/dist/util/ns.cjs.js.map +1 -0
- package/dist/util/ns.esm.js +8 -0
- package/dist/util/ns.esm.js.map +1 -0
- package/dist/util/utilityLogic.cjs.js +6 -0
- package/dist/util/utilityLogic.cjs.js.map +1 -0
- package/dist/util/utilityLogic.esm.js +135 -0
- package/dist/util/utilityLogic.esm.js.map +1 -0
- package/dist/util/utils.cjs.js +2 -0
- package/dist/util/utils.cjs.js.map +1 -0
- package/dist/util/utils.esm.js +22 -0
- package/dist/util/utils.esm.js.map +1 -0
- package/package.json +27 -33
- package/dist/2729812e0bfc062ee77a.js +0 -1
- package/dist/a9c30b64ceaae48b72f0.js +0 -2045
- package/dist/acl/aclLogic.d.ts +0 -5
- package/dist/acl/aclLogic.d.ts.map +0 -1
- package/dist/authSession/authSession.d.ts +0 -42
- package/dist/authSession/authSession.d.ts.map +0 -1
- package/dist/authSession/events.d.ts +0 -24
- package/dist/authSession/events.d.ts.map +0 -1
- package/dist/authSession/issuer.d.ts +0 -8
- package/dist/authSession/issuer.d.ts.map +0 -1
- package/dist/authSession/session.d.ts +0 -45
- package/dist/authSession/session.d.ts.map +0 -1
- package/dist/authn/SolidAuthnLogic.d.ts +0 -42
- package/dist/authn/SolidAuthnLogic.d.ts.map +0 -1
- package/dist/authn/authUtil.d.ts +0 -17
- package/dist/authn/authUtil.d.ts.map +0 -1
- package/dist/authn/serverLogout.d.ts +0 -6
- package/dist/authn/serverLogout.d.ts.map +0 -1
- package/dist/chat/chatLogic.d.ts +0 -3
- package/dist/chat/chatLogic.d.ts.map +0 -1
- package/dist/inbox/inboxLogic.d.ts +0 -3
- package/dist/inbox/inboxLogic.d.ts.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/issuer/issuerLogic.d.ts +0 -8
- package/dist/issuer/issuerLogic.d.ts.map +0 -1
- package/dist/logic/CustomError.d.ts +0 -21
- package/dist/logic/CustomError.d.ts.map +0 -1
- package/dist/logic/solidLogic.d.ts +0 -6
- package/dist/logic/solidLogic.d.ts.map +0 -1
- package/dist/logic/solidLogicSingleton.d.ts +0 -4
- package/dist/logic/solidLogicSingleton.d.ts.map +0 -1
- package/dist/profile/profileAclDocuments.d.ts +0 -2
- package/dist/profile/profileAclDocuments.d.ts.map +0 -1
- package/dist/profile/profileDocuments.d.ts +0 -2
- package/dist/profile/profileDocuments.d.ts.map +0 -1
- package/dist/profile/profileLogic.d.ts +0 -3
- package/dist/profile/profileLogic.d.ts.map +0 -1
- package/dist/solid-logic.esm.js +0 -2358
- package/dist/solid-logic.esm.js.map +0 -1
- package/dist/solid-logic.esm.min.js +0 -2
- package/dist/solid-logic.esm.min.js.map +0 -1
- package/dist/solid-logic.js +0 -7548
- package/dist/solid-logic.js.map +0 -1
- package/dist/solid-logic.min.js +0 -2
- package/dist/solid-logic.min.js.map +0 -1
- package/dist/typeIndex/typeIndexAclDocuments.d.ts +0 -2
- package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +0 -1
- package/dist/typeIndex/typeIndexDocuments.d.ts +0 -3
- package/dist/typeIndex/typeIndexDocuments.d.ts.map +0 -1
- package/dist/typeIndex/typeIndexLogic.d.ts +0 -3
- package/dist/typeIndex/typeIndexLogic.d.ts.map +0 -1
- package/dist/types.d.ts +0 -113
- package/dist/types.d.ts.map +0 -1
- package/dist/util/containerLogic.d.ts +0 -11
- package/dist/util/containerLogic.d.ts.map +0 -1
- package/dist/util/debug.d.ts +0 -5
- package/dist/util/debug.d.ts.map +0 -1
- package/dist/util/ns.d.ts +0 -2
- package/dist/util/ns.d.ts.map +0 -1
- package/dist/util/utilityLogic.d.ts +0 -17
- package/dist/util/utilityLogic.d.ts.map +0 -1
- package/dist/util/utils.d.ts +0 -8
- package/dist/util/utils.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solidLogicSingleton.cjs.js","names":[],"sources":["../../src/logic/solidLogicSingleton.ts"],"sourcesContent":["import * as debug from '../util/debug'\nimport { authSession } from '../authSession/authSession'\nimport { createSolidLogic } from './solidLogic'\nimport { SolidLogic } from '../types'\n\nconst _fetch = async (url, requestInit) => {\n const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'\n const sessionAny = authSession as any\n const sessionWebId = sessionAny?.info?.webId || sessionAny?.webId\n if (sessionWebId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114\n // In fact fetch should respect credentials omit itself\n const authenticatedFetch = (typeof sessionAny.fetch === 'function')\n ? sessionAny.fetch.bind(sessionAny)\n : (typeof sessionAny.authFetch === 'function' ? sessionAny.authFetch.bind(sessionAny) : null)\n if (authenticatedFetch) {\n return authenticatedFetch(url, requestInit)\n }\n return window.fetch(url, requestInit)\n } else {\n return window.fetch(url, requestInit)\n }\n}\n\n// Global singleton pattern to ensure unique store across library versions\nconst SINGLETON_SYMBOL = Symbol.for('solid-logic-singleton')\n\n// Type the global object properly with the singleton\ninterface GlobalWithSingleton {\n [SINGLETON_SYMBOL]?: SolidLogic\n}\n\nconst globalTarget = (typeof window !== 'undefined' ? window : global) as GlobalWithSingleton\n\nfunction getOrCreateSingleton(): SolidLogic {\n if (!globalTarget[SINGLETON_SYMBOL]) {\n debug.log('SolidLogic: Creating new global singleton instance.')\n globalTarget[SINGLETON_SYMBOL] = createSolidLogic({ fetch: _fetch }, authSession)\n debug.log('Unique quadstore initialized.')\n } else {\n debug.log('SolidLogic: Using existing global singleton instance.')\n }\n return globalTarget[SINGLETON_SYMBOL]!\n}\n//this const makes solidLogicSingleton global accessible in mashlib\nconst solidLogicSingleton = getOrCreateSingleton()\n\nexport { solidLogicSingleton }"],"mappings":"wHAKA,IAAM,EAAS,MAAO,EAAK,IAAgB,CACvC,IAAM,EAAY,GAAe,EAAY,aAAe,EAAY,aAAe,OACjF,EAAa,EAAA,YAEnB,IADqB,GAAY,MAAM,OAAS,GAAY,QACxC,CAAC,EAAW,CAE5B,IAAM,EAAsB,OAAO,EAAW,OAAU,WAClD,EAAW,MAAM,KAAK,CAAU,EAC/B,OAAO,EAAW,WAAc,WAAa,EAAW,UAAU,KAAK,CAAU,EAAI,KAI5F,OAHI,EACO,EAAmB,EAAK,CAAW,EAEvC,OAAO,MAAM,EAAK,CAAW,CACxC,MACI,OAAO,OAAO,MAAM,EAAK,CAAW,CAE5C,EAGM,EAAmB,OAAO,IAAI,uBAAuB,EAOrD,EAAgB,OAAO,OAAW,IAAc,OAAS,OAE/D,SAAS,GAAmC,CAQxC,OAPK,EAAa,GAKd,EAAA,IAAU,uDAAuD,GAJjE,EAAA,IAAU,qDAAqD,EAC/D,EAAa,GAAoB,EAAA,iBAAiB,CAAE,MAAO,CAAO,EAAG,EAAA,WAAW,EAChF,EAAA,IAAU,+BAA+B,GAItC,EAAa,EACxB,CAEA,IAAM,EAAsB,EAAqB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { log as e } from "../util/debug.esm.js";
|
|
2
|
+
import { authSession as t } from "../authSession/authSession.esm.js";
|
|
3
|
+
import { createSolidLogic as n } from "./solidLogic.esm.js";
|
|
4
|
+
//#region src/logic/solidLogicSingleton.ts
|
|
5
|
+
var r = async (e, n) => {
|
|
6
|
+
let r = n && n.credentials && n.credentials == "omit", i = t;
|
|
7
|
+
if ((i?.info?.webId || i?.webId) && !r) {
|
|
8
|
+
let t = typeof i.fetch == "function" ? i.fetch.bind(i) : typeof i.authFetch == "function" ? i.authFetch.bind(i) : null;
|
|
9
|
+
return t ? t(e, n) : window.fetch(e, n);
|
|
10
|
+
} else return window.fetch(e, n);
|
|
11
|
+
}, i = Symbol.for("solid-logic-singleton"), a = typeof window < "u" ? window : global;
|
|
12
|
+
function o() {
|
|
13
|
+
return a[i] ? e("SolidLogic: Using existing global singleton instance.") : (e("SolidLogic: Creating new global singleton instance."), a[i] = n({ fetch: r }, t), e("Unique quadstore initialized.")), a[i];
|
|
14
|
+
}
|
|
15
|
+
var s = o();
|
|
16
|
+
//#endregion
|
|
17
|
+
export { s as solidLogicSingleton };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=solidLogicSingleton.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solidLogicSingleton.esm.js","names":[],"sources":["../../src/logic/solidLogicSingleton.ts"],"sourcesContent":["import * as debug from '../util/debug'\nimport { authSession } from '../authSession/authSession'\nimport { createSolidLogic } from './solidLogic'\nimport { SolidLogic } from '../types'\n\nconst _fetch = async (url, requestInit) => {\n const omitCreds = requestInit && requestInit.credentials && requestInit.credentials == 'omit'\n const sessionAny = authSession as any\n const sessionWebId = sessionAny?.info?.webId || sessionAny?.webId\n if (sessionWebId && !omitCreds) { // see https://github.com/solidos/solidos/issues/114\n // In fact fetch should respect credentials omit itself\n const authenticatedFetch = (typeof sessionAny.fetch === 'function')\n ? sessionAny.fetch.bind(sessionAny)\n : (typeof sessionAny.authFetch === 'function' ? sessionAny.authFetch.bind(sessionAny) : null)\n if (authenticatedFetch) {\n return authenticatedFetch(url, requestInit)\n }\n return window.fetch(url, requestInit)\n } else {\n return window.fetch(url, requestInit)\n }\n}\n\n// Global singleton pattern to ensure unique store across library versions\nconst SINGLETON_SYMBOL = Symbol.for('solid-logic-singleton')\n\n// Type the global object properly with the singleton\ninterface GlobalWithSingleton {\n [SINGLETON_SYMBOL]?: SolidLogic\n}\n\nconst globalTarget = (typeof window !== 'undefined' ? window : global) as GlobalWithSingleton\n\nfunction getOrCreateSingleton(): SolidLogic {\n if (!globalTarget[SINGLETON_SYMBOL]) {\n debug.log('SolidLogic: Creating new global singleton instance.')\n globalTarget[SINGLETON_SYMBOL] = createSolidLogic({ fetch: _fetch }, authSession)\n debug.log('Unique quadstore initialized.')\n } else {\n debug.log('SolidLogic: Using existing global singleton instance.')\n }\n return globalTarget[SINGLETON_SYMBOL]!\n}\n//this const makes solidLogicSingleton global accessible in mashlib\nconst solidLogicSingleton = getOrCreateSingleton()\n\nexport { solidLogicSingleton }"],"mappings":";;;;AAKA,IAAM,IAAS,OAAO,GAAK,MAAgB;CACvC,IAAM,IAAY,KAAe,EAAY,eAAe,EAAY,eAAe,QACjF,IAAa;CAEnB,KADqB,GAAY,MAAM,SAAS,GAAY,UACxC,CAAC,GAAW;EAE5B,IAAM,IAAsB,OAAO,EAAW,SAAU,aAClD,EAAW,MAAM,KAAK,CAAU,IAC/B,OAAO,EAAW,aAAc,aAAa,EAAW,UAAU,KAAK,CAAU,IAAI;EAI5F,OAHI,IACO,EAAmB,GAAK,CAAW,IAEvC,OAAO,MAAM,GAAK,CAAW;CACxC,OACI,OAAO,OAAO,MAAM,GAAK,CAAW;AAE5C,GAGM,IAAmB,OAAO,IAAI,uBAAuB,GAOrD,IAAgB,OAAO,SAAW,MAAc,SAAS;AAE/D,SAAS,IAAmC;CAQxC,OAPK,EAAa,KAKd,EAAU,uDAAuD,KAJjE,EAAU,qDAAqD,GAC/D,EAAa,KAAoB,EAAiB,EAAE,OAAO,EAAO,GAAG,CAAW,GAChF,EAAU,+BAA+B,IAItC,EAAa;AACxB;AAEA,IAAM,IAAsB,EAAqB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function e(e){return[`@prefix acl: <http://www.w3.org/ns/auth/acl#>.`,``,`<#owner>`,`a acl:Authorization;`,`acl:agent <${e}>;`,`acl:accessTo <./>;`,`acl:default <./>;`,`acl:mode acl:Read, acl:Write, acl:Control.`].join(`
|
|
2
|
+
`)}exports.ownerOnlyContainerAclDocument=e;
|
|
3
|
+
//# sourceMappingURL=profileAclDocuments.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileAclDocuments.cjs.js","names":[],"sources":["../../src/profile/profileAclDocuments.ts"],"sourcesContent":["export function ownerOnlyContainerAclDocument(webId: string): string {\n return [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#owner>',\n 'a acl:Authorization;',\n `acl:agent <${webId}>;`,\n 'acl:accessTo <./>;',\n 'acl:default <./>;',\n 'acl:mode acl:Read, acl:Write, acl:Control.'\n ].join('\\n')\n}\n"],"mappings":"AAAA,SAAgB,EAA8B,EAAuB,CACjE,MAAO,CACH,iDACA,GACA,WACA,uBACA,cAAc,EAAM,IACpB,qBACA,oBACA,4CACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/profile/profileAclDocuments.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return [
|
|
4
|
+
"@prefix acl: <http://www.w3.org/ns/auth/acl#>.",
|
|
5
|
+
"",
|
|
6
|
+
"<#owner>",
|
|
7
|
+
"a acl:Authorization;",
|
|
8
|
+
`acl:agent <${e}>;`,
|
|
9
|
+
"acl:accessTo <./>;",
|
|
10
|
+
"acl:default <./>;",
|
|
11
|
+
"acl:mode acl:Read, acl:Write, acl:Control."
|
|
12
|
+
].join("\n");
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { e as ownerOnlyContainerAclDocument };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=profileAclDocuments.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileAclDocuments.esm.js","names":[],"sources":["../../src/profile/profileAclDocuments.ts"],"sourcesContent":["export function ownerOnlyContainerAclDocument(webId: string): string {\n return [\n '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',\n '',\n '<#owner>',\n 'a acl:Authorization;',\n `acl:agent <${webId}>;`,\n 'acl:accessTo <./>;',\n 'acl:default <./>;',\n 'acl:mode acl:Read, acl:Write, acl:Control.'\n ].join('\\n')\n}\n"],"mappings":";AAAA,SAAgB,EAA8B,GAAuB;CACjE,OAAO;EACH;EACA;EACA;EACA;EACA,cAAc,EAAM;EACpB;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function e(){return[`@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(`
|
|
2
|
+
`)}exports.preferencesFileDocument=e;
|
|
3
|
+
//# sourceMappingURL=profileDocuments.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileDocuments.cjs.js","names":[],"sources":["../../src/profile/profileDocuments.ts"],"sourcesContent":["export function preferencesFileDocument(): string {\n return [\n '@prefix dct: <http://purl.org/dc/terms/>.',\n '@prefix pim: <http://www.w3.org/ns/pim/space#>.',\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a pim:ConfigurationFile ;',\n ' dct:title \"Preferences file\".'\n ].join('\\n')\n}\n"],"mappings":"AAAA,SAAgB,GAAkC,CAC9C,MAAO,CACH,4CACA,kDACA,sDACA,KACA,gCACA,mCACJ,CAAC,CAAC,KAAK;CAAI,CACf"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/profile/profileDocuments.ts
|
|
2
|
+
function e() {
|
|
3
|
+
return [
|
|
4
|
+
"@prefix dct: <http://purl.org/dc/terms/>.",
|
|
5
|
+
"@prefix pim: <http://www.w3.org/ns/pim/space#>.",
|
|
6
|
+
"@prefix solid: <http://www.w3.org/ns/solid/terms#>.",
|
|
7
|
+
"<>",
|
|
8
|
+
" a pim:ConfigurationFile ;",
|
|
9
|
+
" dct:title \"Preferences file\"."
|
|
10
|
+
].join("\n");
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { e as preferencesFileDocument };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=profileDocuments.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileDocuments.esm.js","names":[],"sources":["../../src/profile/profileDocuments.ts"],"sourcesContent":["export function preferencesFileDocument(): string {\n return [\n '@prefix dct: <http://purl.org/dc/terms/>.',\n '@prefix pim: <http://www.w3.org/ns/pim/space#>.',\n '@prefix solid: <http://www.w3.org/ns/solid/terms#>.',\n '<>',\n ' a pim:ConfigurationFile ;',\n ' dct:title \"Preferences file\".'\n ].join('\\n')\n}\n"],"mappings":";AAAA,SAAgB,IAAkC;CAC9C,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC,CAAC,KAAK,IAAI;AACf"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../util/debug.cjs.js"),t=require("../util/ns.cjs.js"),n=require("../acl/aclLogic.cjs.js"),r=require("../util/utils.cjs.js"),i=require("../logic/CustomError.cjs.js"),a=require("../typeIndex/typeIndexDocuments.cjs.js"),o=require("../typeIndex/typeIndexAclDocuments.cjs.js"),s=require("./profileDocuments.cjs.js"),c=require("./profileAclDocuments.cjs.js"),l=require("../util/containerLogic.cjs.js");let u=require("rdflib");function d(d,f,p){let m=t.ns,h=l.createContainerLogic(d),g=new Map,_=new Map;function v(e){return!!e&&(e.startsWith(`https://`)||e.startsWith(`http://`))}function y(e){let t=e.doc(),n=t.dir();if(n?.uri&&v(n.uri))return n.uri;let r=t.uri;if(!r||!v(r))return null;let i=r.split(`#`)[0],a=i.lastIndexOf(`/`);return a===-1?null:i.slice(0,a+1)}function b(e,t){let n=y(e);if(!n)throw Error(`Cannot derive directory for preferences file ${e.uri}`);return(0,u.sym)(n+t)}function x(e){if(e?.response?.status===404)return!0;let t=`${e?.message||e||``}`;return t.includes(`404`)||t.includes(`Not Found`)}async function S(e){let t=(0,u.sym)(e);try{await d.fetcher.load(t);return}catch(e){if(!x(e))throw e}await h.createContainer(e)}async function C(e,t){let r=y(t);if(!r)throw Error(`Cannot derive settings directory from ${t.uri}`);await S(r);let i=(0,u.sym)(r),a;try{await d.fetcher.load(i),a=d.any(i,n.ACL_LINK)?.value}catch(e){if(!x(e))throw e}a||=`${r}.acl`;let o=(0,u.sym)(a);try{await d.fetcher.load(o);return}catch(e){if(!x(e))throw e}await d.fetcher.webOperation(`PUT`,o.uri,{data:c.ownerOnlyContainerAclDocument(e.uri),contentType:`text/turtle`})}async function w(e,t,r=!1){if(!await p.loadOrCreateWithContentOnCreate(t,a.publicTypeIndexDocument())&&!r)return;let i;try{await d.fetcher.load(t),i=d.any(t,n.ACL_LINK)?.value}catch(e){if(!x(e))throw e}i||=`${t.uri}.acl`;let s=(0,u.sym)(i);try{await d.fetcher.webOperation(`PUT`,s.uri,{data:o.publicTypeIndexAclDocument(e.uri,t.uri),contentType:`text/turtle`,headers:{"If-None-Match":`*`}})}catch(e){if((e?.response?.status??e?.status)!==412)throw e}}async function T(e){await p.loadOrCreateWithContentOnCreate(e,a.privateTypeIndexDocument())}async function E(e,t){let n=t.doc(),r=e.doc();await d.fetcher.load(n);let i=d.any(e,m.solid(`publicTypeIndex`),null,r),o=d.any(e,m.solid(`publicTypeIndex`),null,n),s=i||o||b(t,`publicTypeIndex.ttl`),c=d.any(e,m.solid(`privateTypeIndex`),null,n)||b(t,`privateTypeIndex.ttl`),l=!i;l&&await p.followOrCreateLinkWithContentOnCreate(e,m.solid(`publicTypeIndex`),s,r,a.publicTypeIndexDocument());let f=[];d.holds(n,m.rdf(`type`),m.space(`ConfigurationFile`),n)||f.push((0,u.st)(n,m.rdf(`type`),m.space(`ConfigurationFile`),n)),d.holds(n,m.dct(`title`),void 0,n)||f.push((0,u.st)(n,m.dct(`title`),(0,u.literal)(`Preferences file`),n)),d.holds(e,m.solid(`publicTypeIndex`),s,n)||f.push((0,u.st)(e,m.solid(`publicTypeIndex`),s,n)),d.holds(e,m.solid(`privateTypeIndex`),c,n)||f.push((0,u.st)(e,m.solid(`privateTypeIndex`),c,n)),f.length>0&&(await d.updater.update([],f),await d.fetcher.load(n)),await w(e,s,l),await T(c)}async function D(e){try{return!!await p.loadOrCreateWithContentOnCreate(e,s.preferencesFileDocument())}catch(t){throw t.response?.status===401?new i.UnauthorizedError:t.response?.status===403?r.differentOrigin(e)?new i.CrossOriginForbiddenError:new i.SameOriginForbiddenError:t}}async function O(e){try{return await k(e)}catch{return}}async function k(t){let n=_.get(t.uri);if(n)return n;let a=g.get(t.uri);if(a)return a;let o=(async()=>{await A(t);let n=r.suggestPreferencesFile(t),a;try{a=d.any(t,m.space(`preferencesFile`),null,t.doc())||await p.followOrCreateLink(t,m.space(`preferencesFile`),n,t.doc()),await C(t,a),await D(a),await E(t,a)}catch(n){let r=`User ${t} has no pointer in profile to preferences file.`;throw e.warn(r),n instanceof i.NotEditableError||n instanceof i.WebOperationError||n instanceof i.UnauthorizedError||n instanceof i.CrossOriginForbiddenError||n instanceof i.SameOriginForbiddenError||n instanceof i.FetchError,n}try{await d.fetcher.load(a)}catch(n){let o=`Unable to load preference of user ${t}: ${n}`;if(n.response?.status===404)return await C(t,a),await D(a),await E(t,a),await d.fetcher.load(a),a;throw e.warn(o),n.response.status===401?new i.UnauthorizedError:n.response.status===403?r.differentOrigin(a)?new i.CrossOriginForbiddenError:new i.SameOriginForbiddenError:Error(o)}return _.set(t.uri,a),a})();g.set(t.uri,o);try{return await o}finally{g.get(t.uri)===o&&g.delete(t.uri)}}async function A(e){if(!e)throw Error(`loadProfile: no user given.`);try{await d.fetcher.load(e.doc())}catch(t){throw Error(`Unable to load profile of user ${e}: ${t}`)}return e.doc()}async function j(){let e=f.currentUser();if(e===null)throw Error(`Current user not found! Not logged in?`);return await d.fetcher.load(e.doc()),e}function M(e){let t=P(e);if(!t)throw Error(`User pod root not found!`);return t}async function N(e){await d.fetcher.load(e);let t=d.any(e,m.ldp(`inbox`),void 0,e.doc());if(!t)throw Error(`User main inbox not found!`);return t}function P(e){return d.any(e,m.space(`storage`),void 0,e.doc())}return{loadMe:j,getPodRoot:M,getMainInbox:N,findStorage:P,loadPreferences:k,loadProfile:A,silencedLoadPreferences:O}}exports.createProfileLogic=d;
|
|
2
|
+
//# sourceMappingURL=profileLogic.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileLogic.cjs.js","names":[],"sources":["../../src/profile/profileLogic.ts"],"sourcesContent":["import { literal, NamedNode, st, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from '../typeIndex/typeIndexDocuments'\nimport { publicTypeIndexAclDocument } from '../typeIndex/typeIndexAclDocuments'\nimport { preferencesFileDocument } from './profileDocuments'\nimport { ownerOnlyContainerAclDocument } from './profileAclDocuments'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { differentOrigin, suggestPreferencesFile } from '../util/utils'\nimport { ProfileLogic } from '../types'\n\nexport function createProfileLogic(store, authn, utilityLogic): ProfileLogic {\n const ns = namespace\n const containerLogic = createContainerLogic(store)\n const loadPreferencesInFlight = new Map<string, Promise<NamedNode>>()\n const cachedPreferencesFileByWebId = new Map<string, NamedNode>()\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) return null\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) return null\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestTypeIndexInPreferences(preferencesFile: NamedNode, filename: string): NamedNode {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`Cannot derive directory for preferences file ${preferencesFile.uri}`)\n return sym(dirUri + filename)\n }\n\n function isNotFoundError(err: any): boolean {\n if (err?.response?.status === 404) return true\n const text = `${err?.message || err || ''}`\n return text.includes('404') || text.includes('Not Found')\n }\n\n async function ensureContainerExists(containerUri: string): Promise<void> {\n const containerNode = sym(containerUri)\n try {\n await store.fetcher.load(containerNode)\n return\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n await containerLogic.createContainer(containerUri)\n }\n\n async function ensureOwnerOnlyAclForSettings(user: NamedNode, preferencesFile: NamedNode): Promise<void> {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`Cannot derive settings directory from ${preferencesFile.uri}`)\n await ensureContainerExists(dirUri)\n\n const containerNode = sym(dirUri)\n let aclDocUri: string | undefined\n try {\n await store.fetcher.load(containerNode)\n aclDocUri = store.any(containerNode, ACL_LINK)?.value\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n if (!aclDocUri) {\n // Fallback for servers/tests where rel=acl is not exposed in mocked headers.\n aclDocUri = `${dirUri}.acl`\n }\n const aclDoc = sym(aclDocUri)\n try {\n await store.fetcher.load(aclDoc)\n return\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n\n await store.fetcher.webOperation('PUT', aclDoc.uri, {\n data: ownerOnlyContainerAclDocument(user.uri),\n contentType: 'text/turtle'\n })\n }\n\n async function ensurePublicTypeIndexAclOnCreate(user: NamedNode, publicTypeIndex: NamedNode, ensureAcl = false): Promise<void> {\n const created = await utilityLogic.loadOrCreateWithContentOnCreate(publicTypeIndex, publicTypeIndexDocument())\n if (!created && !ensureAcl) return\n\n let aclDocUri: string | undefined\n try {\n await store.fetcher.load(publicTypeIndex)\n aclDocUri = store.any(publicTypeIndex, ACL_LINK)?.value\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n if (!aclDocUri) {\n aclDocUri = `${publicTypeIndex.uri}.acl`\n }\n\n const aclDoc = sym(aclDocUri)\n try {\n await store.fetcher.webOperation('PUT', aclDoc.uri, {\n data: publicTypeIndexAclDocument(user.uri, publicTypeIndex.uri),\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 412) throw err\n }\n }\n\n async function ensurePrivateTypeIndexOnCreate(privateTypeIndex: NamedNode): Promise<void> {\n await utilityLogic.loadOrCreateWithContentOnCreate(privateTypeIndex, privateTypeIndexDocument())\n }\n\n async function initializePreferencesDefaults(user: NamedNode, preferencesFile: NamedNode): Promise<void> {\n const preferencesDoc = preferencesFile.doc() as NamedNode\n const profileDoc = user.doc() as NamedNode\n await store.fetcher.load(preferencesDoc)\n\n const profilePublicTypeIndex =\n (store.any(user, ns.solid('publicTypeIndex'), null, profileDoc) as NamedNode | null)\n const preferencesPublicTypeIndex =\n (store.any(user, ns.solid('publicTypeIndex'), null, preferencesDoc) as NamedNode | null)\n const publicTypeIndex =\n profilePublicTypeIndex ||\n preferencesPublicTypeIndex ||\n suggestTypeIndexInPreferences(preferencesFile, 'publicTypeIndex.ttl')\n const privateTypeIndex =\n (store.any(user, ns.solid('privateTypeIndex'), null, preferencesDoc) as NamedNode | null) ||\n suggestTypeIndexInPreferences(preferencesFile, 'privateTypeIndex.ttl')\n\n // Keep discovery consistent with typeIndexLogic, which resolves publicTypeIndex from the profile doc.\n const createdProfilePublicTypeIndexLink = !profilePublicTypeIndex\n if (createdProfilePublicTypeIndexLink) {\n await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n publicTypeIndex,\n profileDoc,\n publicTypeIndexDocument()\n )\n }\n\n const toInsert: any[] = []\n if (!store.holds(preferencesDoc, ns.rdf('type'), ns.space('ConfigurationFile'), preferencesDoc)) {\n toInsert.push(st(preferencesDoc, ns.rdf('type'), ns.space('ConfigurationFile'), preferencesDoc))\n }\n if (!store.holds(preferencesDoc, ns.dct('title'), undefined, preferencesDoc)) {\n toInsert.push(st(preferencesDoc, ns.dct('title'), literal('Preferences file'), preferencesDoc))\n }\n if (!store.holds(user, ns.solid('publicTypeIndex'), publicTypeIndex, preferencesDoc)) {\n toInsert.push(st(user, ns.solid('publicTypeIndex'), publicTypeIndex, preferencesDoc))\n }\n if (!store.holds(user, ns.solid('privateTypeIndex'), privateTypeIndex, preferencesDoc)) {\n toInsert.push(st(user, ns.solid('privateTypeIndex'), privateTypeIndex, preferencesDoc))\n }\n\n if (toInsert.length > 0) {\n await store.updater.update([], toInsert)\n await store.fetcher.load(preferencesDoc)\n }\n\n await ensurePublicTypeIndexAclOnCreate(user, publicTypeIndex, createdProfilePublicTypeIndexLink)\n await ensurePrivateTypeIndexOnCreate(privateTypeIndex)\n }\n\n async function ensurePreferencesDocExists(preferencesFile: NamedNode): Promise<boolean> {\n try {\n const created = await utilityLogic.loadOrCreateWithContentOnCreate(preferencesFile, preferencesFileDocument())\n if (created) {\n return true\n }\n return false\n } catch (err) {\n if (err.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err.response?.status === 403) {\n if (differentOrigin(preferencesFile)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n throw err\n }\n }\n\n /**\n * loads the preference without throwing errors - if it can create it it does so.\n * remark: it still throws error if it cannot load profile.\n * @param user\n * @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it\n */\n async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {\n try {\n return await loadPreferences(user)\n } catch (err) {\n return undefined\n }\n }\n\n /**\n * loads the preference without returning different errors if it cannot create or load it.\n * remark: it also throws error if it cannot load profile.\n * @param user\n * @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it\n */\n async function loadPreferences (user: NamedNode): Promise <NamedNode> {\n const cachedPreferencesFile = cachedPreferencesFileByWebId.get(user.uri)\n if (cachedPreferencesFile) {\n return cachedPreferencesFile\n }\n\n const inFlight = loadPreferencesInFlight.get(user.uri)\n if (inFlight) {\n return inFlight\n }\n\n const run = (async (): Promise<NamedNode> => {\n await loadProfile(user)\n\n const possiblePreferencesFile = suggestPreferencesFile(user)\n let preferencesFile\n try {\n const existingPreferencesFile = store.any(user, ns.space('preferencesFile'), null, user.doc()) as NamedNode | null\n if (existingPreferencesFile) {\n preferencesFile = existingPreferencesFile\n } else {\n preferencesFile = await utilityLogic.followOrCreateLink(user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())\n }\n\n await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)\n await ensurePreferencesDocExists(preferencesFile as NamedNode)\n await initializePreferencesDefaults(user, preferencesFile as NamedNode)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n // we are listing the possible errors\n if (err instanceof NotEditableError) { throw err }\n if (err instanceof WebOperationError) { throw err }\n if (err instanceof UnauthorizedError) { throw err }\n if (err instanceof CrossOriginForbiddenError) { throw err }\n if (err instanceof SameOriginForbiddenError) { throw err }\n if (err instanceof FetchError) { throw err }\n throw err\n }\n\n try {\n await store.fetcher.load(preferencesFile as NamedNode)\n } catch (err) { // Maybe a permission problem or origin problem\n const msg = `Unable to load preference of user ${user}: ${err}`\n if (err.response?.status === 404) {\n // Self-heal when a stale profile pointer references a missing preferences file.\n await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)\n await ensurePreferencesDocExists(preferencesFile as NamedNode)\n await initializePreferencesDefaults(user, preferencesFile as NamedNode)\n await store.fetcher.load(preferencesFile as NamedNode)\n return preferencesFile as NamedNode\n }\n debug.warn(msg)\n if (err.response.status === 401) {\n throw new UnauthorizedError()\n }\n if (err.response.status === 403) {\n if (differentOrigin(preferencesFile)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n /*if (err.response.status === 404) {\n throw new NotFoundError();\n }*/\n throw new Error(msg)\n }\n cachedPreferencesFileByWebId.set(user.uri, preferencesFile as NamedNode)\n return preferencesFile as NamedNode\n })()\n\n loadPreferencesInFlight.set(user.uri, run)\n try {\n return await run\n } finally {\n if (loadPreferencesInFlight.get(user.uri) === run) {\n loadPreferencesInFlight.delete(user.uri)\n }\n }\n }\n\n async function loadProfile (user: NamedNode):Promise <NamedNode> {\n if (!user) {\n throw new Error('loadProfile: no user given.')\n }\n try {\n await store.fetcher.load(user.doc())\n } catch (err) {\n throw new Error(`Unable to load profile of user ${user}: ${err}`)\n }\n return user.doc()\n }\n\n async function loadMe(): Promise<NamedNode> {\n const me = authn.currentUser()\n if (me === null) {\n throw new Error('Current user not found! Not logged in?')\n }\n await store.fetcher.load(me.doc())\n return me\n }\n\n function getPodRoot(user: NamedNode): NamedNode {\n const podRoot = findStorage(user)\n if (!podRoot) {\n throw new Error('User pod root not found!')\n }\n return podRoot as NamedNode\n }\n\n async function getMainInbox(user: NamedNode): Promise<NamedNode> {\n await store.fetcher.load(user)\n const mainInbox = store.any(user, ns.ldp('inbox'), undefined, user.doc())\n if (!mainInbox) {\n throw new Error('User main inbox not found!')\n }\n return mainInbox as NamedNode\n }\n\n function findStorage(me: NamedNode) {\n return store.any(me, ns.space('storage'), undefined, me.doc())\n }\n\n return {\n loadMe,\n getPodRoot,\n getMainInbox,\n findStorage,\n loadPreferences,\n loadProfile,\n silencedLoadPreferences\n }\n}\n"],"mappings":"qbAaA,SAAgB,EAAmB,EAAO,EAAO,EAA4B,CACzE,IAAM,EAAK,EAAA,GACL,EAAiB,EAAA,qBAAqB,CAAK,EAC3C,EAA0B,IAAI,IAC9B,EAA+B,IAAI,IAEzC,SAAS,EAAkB,EAAyC,CAChE,MAAO,CAAC,CAAC,IAAQ,EAAI,WAAW,UAAU,GAAK,EAAI,WAAW,SAAS,EAC3E,CAEA,SAAS,EAAU,EAAgC,CAC/C,IAAM,EAAM,EAAK,IAAI,EACf,EAAM,EAAI,IAAI,EACpB,GAAI,GAAK,KAAO,EAAkB,EAAI,GAAG,EAAG,OAAO,EAAI,IACvD,IAAM,EAAS,EAAI,IACnB,GAAI,CAAC,GAAU,CAAC,EAAkB,CAAM,EAAG,OAAO,KAClD,IAAM,EAAkB,EAAO,MAAM,GAAG,CAAC,CAAC,GACpC,EAAY,EAAgB,YAAY,GAAG,EAEjD,OADI,IAAc,GAAW,KACtB,EAAgB,MAAM,EAAG,EAAY,CAAC,CACjD,CAEA,SAAS,EAA8B,EAA4B,EAA6B,CAC5F,IAAM,EAAS,EAAU,CAAe,EACxC,GAAI,CAAC,EAAQ,MAAU,MAAM,gDAAgD,EAAgB,KAAK,EAClG,OAAA,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L_LINK as n } from "../acl/aclLogic.esm.js";
|
|
4
|
+
import { differentOrigin as r, suggestPreferencesFile as i } from "../util/utils.esm.js";
|
|
5
|
+
import { CrossOriginForbiddenError as a, FetchError as o, NotEditableError as s, SameOriginForbiddenError as c, UnauthorizedError as l, WebOperationError as u } from "../logic/CustomError.esm.js";
|
|
6
|
+
import { privateTypeIndexDocument as d, publicTypeIndexDocument as f } from "../typeIndex/typeIndexDocuments.esm.js";
|
|
7
|
+
import { publicTypeIndexAclDocument as p } from "../typeIndex/typeIndexAclDocuments.esm.js";
|
|
8
|
+
import { preferencesFileDocument as m } from "./profileDocuments.esm.js";
|
|
9
|
+
import { ownerOnlyContainerAclDocument as h } from "./profileAclDocuments.esm.js";
|
|
10
|
+
import { createContainerLogic as g } from "../util/containerLogic.esm.js";
|
|
11
|
+
import { literal as _, st as v, sym as y } from "rdflib";
|
|
12
|
+
//#region src/profile/profileLogic.ts
|
|
13
|
+
function b(b, x, S) {
|
|
14
|
+
let C = t, w = g(b), T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map();
|
|
15
|
+
function D(e) {
|
|
16
|
+
return !!e && (e.startsWith("https://") || e.startsWith("http://"));
|
|
17
|
+
}
|
|
18
|
+
function O(e) {
|
|
19
|
+
let t = e.doc(), n = t.dir();
|
|
20
|
+
if (n?.uri && D(n.uri)) return n.uri;
|
|
21
|
+
let r = t.uri;
|
|
22
|
+
if (!r || !D(r)) return null;
|
|
23
|
+
let i = r.split("#")[0], a = i.lastIndexOf("/");
|
|
24
|
+
return a === -1 ? null : i.slice(0, a + 1);
|
|
25
|
+
}
|
|
26
|
+
function k(e, t) {
|
|
27
|
+
let n = O(e);
|
|
28
|
+
if (!n) throw Error(`Cannot derive directory for preferences file ${e.uri}`);
|
|
29
|
+
return y(n + t);
|
|
30
|
+
}
|
|
31
|
+
function A(e) {
|
|
32
|
+
if (e?.response?.status === 404) return !0;
|
|
33
|
+
let t = `${e?.message || e || ""}`;
|
|
34
|
+
return t.includes("404") || t.includes("Not Found");
|
|
35
|
+
}
|
|
36
|
+
async function j(e) {
|
|
37
|
+
let t = y(e);
|
|
38
|
+
try {
|
|
39
|
+
await b.fetcher.load(t);
|
|
40
|
+
return;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (!A(e)) throw e;
|
|
43
|
+
}
|
|
44
|
+
await w.createContainer(e);
|
|
45
|
+
}
|
|
46
|
+
async function M(e, t) {
|
|
47
|
+
let r = O(t);
|
|
48
|
+
if (!r) throw Error(`Cannot derive settings directory from ${t.uri}`);
|
|
49
|
+
await j(r);
|
|
50
|
+
let i = y(r), a;
|
|
51
|
+
try {
|
|
52
|
+
await b.fetcher.load(i), a = b.any(i, n)?.value;
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (!A(e)) throw e;
|
|
55
|
+
}
|
|
56
|
+
a ||= `${r}.acl`;
|
|
57
|
+
let o = y(a);
|
|
58
|
+
try {
|
|
59
|
+
await b.fetcher.load(o);
|
|
60
|
+
return;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (!A(e)) throw e;
|
|
63
|
+
}
|
|
64
|
+
await b.fetcher.webOperation("PUT", o.uri, {
|
|
65
|
+
data: h(e.uri),
|
|
66
|
+
contentType: "text/turtle"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function N(e, t, r = !1) {
|
|
70
|
+
if (!await S.loadOrCreateWithContentOnCreate(t, f()) && !r) return;
|
|
71
|
+
let i;
|
|
72
|
+
try {
|
|
73
|
+
await b.fetcher.load(t), i = b.any(t, n)?.value;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (!A(e)) throw e;
|
|
76
|
+
}
|
|
77
|
+
i ||= `${t.uri}.acl`;
|
|
78
|
+
let a = y(i);
|
|
79
|
+
try {
|
|
80
|
+
await b.fetcher.webOperation("PUT", a.uri, {
|
|
81
|
+
data: p(e.uri, t.uri),
|
|
82
|
+
contentType: "text/turtle",
|
|
83
|
+
headers: { "If-None-Match": "*" }
|
|
84
|
+
});
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if ((e?.response?.status ?? e?.status) !== 412) throw e;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function P(e) {
|
|
90
|
+
await S.loadOrCreateWithContentOnCreate(e, d());
|
|
91
|
+
}
|
|
92
|
+
async function F(e, t) {
|
|
93
|
+
let n = t.doc(), r = e.doc();
|
|
94
|
+
await b.fetcher.load(n);
|
|
95
|
+
let i = b.any(e, C.solid("publicTypeIndex"), null, r), a = b.any(e, C.solid("publicTypeIndex"), null, n), o = i || a || k(t, "publicTypeIndex.ttl"), s = b.any(e, C.solid("privateTypeIndex"), null, n) || k(t, "privateTypeIndex.ttl"), c = !i;
|
|
96
|
+
c && await S.followOrCreateLinkWithContentOnCreate(e, C.solid("publicTypeIndex"), o, r, f());
|
|
97
|
+
let l = [];
|
|
98
|
+
b.holds(n, C.rdf("type"), C.space("ConfigurationFile"), n) || l.push(v(n, C.rdf("type"), C.space("ConfigurationFile"), n)), b.holds(n, C.dct("title"), void 0, n) || l.push(v(n, C.dct("title"), _("Preferences file"), n)), b.holds(e, C.solid("publicTypeIndex"), o, n) || l.push(v(e, C.solid("publicTypeIndex"), o, n)), b.holds(e, C.solid("privateTypeIndex"), s, n) || l.push(v(e, C.solid("privateTypeIndex"), s, n)), l.length > 0 && (await b.updater.update([], l), await b.fetcher.load(n)), await N(e, o, c), await P(s);
|
|
99
|
+
}
|
|
100
|
+
async function I(e) {
|
|
101
|
+
try {
|
|
102
|
+
return !!await S.loadOrCreateWithContentOnCreate(e, m());
|
|
103
|
+
} catch (t) {
|
|
104
|
+
throw t.response?.status === 401 ? new l() : t.response?.status === 403 ? r(e) ? new a() : new c() : t;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function L(e) {
|
|
108
|
+
try {
|
|
109
|
+
return await R(e);
|
|
110
|
+
} catch {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function R(t) {
|
|
115
|
+
let n = E.get(t.uri);
|
|
116
|
+
if (n) return n;
|
|
117
|
+
let d = T.get(t.uri);
|
|
118
|
+
if (d) return d;
|
|
119
|
+
let f = (async () => {
|
|
120
|
+
await z(t);
|
|
121
|
+
let n = i(t), d;
|
|
122
|
+
try {
|
|
123
|
+
d = b.any(t, C.space("preferencesFile"), null, t.doc()) || await S.followOrCreateLink(t, C.space("preferencesFile"), n, t.doc()), await M(t, d), await I(d), await F(t, d);
|
|
124
|
+
} catch (n) {
|
|
125
|
+
throw e(`User ${t} has no pointer in profile to preferences file.`), n instanceof s || n instanceof u || n instanceof l || n instanceof a || n instanceof c || n instanceof o, n;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
await b.fetcher.load(d);
|
|
129
|
+
} catch (n) {
|
|
130
|
+
let i = `Unable to load preference of user ${t}: ${n}`;
|
|
131
|
+
if (n.response?.status === 404) return await M(t, d), await I(d), await F(t, d), await b.fetcher.load(d), d;
|
|
132
|
+
throw e(i), n.response.status === 401 ? new l() : n.response.status === 403 ? r(d) ? new a() : new c() : Error(i);
|
|
133
|
+
}
|
|
134
|
+
return E.set(t.uri, d), d;
|
|
135
|
+
})();
|
|
136
|
+
T.set(t.uri, f);
|
|
137
|
+
try {
|
|
138
|
+
return await f;
|
|
139
|
+
} finally {
|
|
140
|
+
T.get(t.uri) === f && T.delete(t.uri);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function z(e) {
|
|
144
|
+
if (!e) throw Error("loadProfile: no user given.");
|
|
145
|
+
try {
|
|
146
|
+
await b.fetcher.load(e.doc());
|
|
147
|
+
} catch (t) {
|
|
148
|
+
throw Error(`Unable to load profile of user ${e}: ${t}`);
|
|
149
|
+
}
|
|
150
|
+
return e.doc();
|
|
151
|
+
}
|
|
152
|
+
async function B() {
|
|
153
|
+
let e = x.currentUser();
|
|
154
|
+
if (e === null) throw Error("Current user not found! Not logged in?");
|
|
155
|
+
return await b.fetcher.load(e.doc()), e;
|
|
156
|
+
}
|
|
157
|
+
function V(e) {
|
|
158
|
+
let t = U(e);
|
|
159
|
+
if (!t) throw Error("User pod root not found!");
|
|
160
|
+
return t;
|
|
161
|
+
}
|
|
162
|
+
async function H(e) {
|
|
163
|
+
await b.fetcher.load(e);
|
|
164
|
+
let t = b.any(e, C.ldp("inbox"), void 0, e.doc());
|
|
165
|
+
if (!t) throw Error("User main inbox not found!");
|
|
166
|
+
return t;
|
|
167
|
+
}
|
|
168
|
+
function U(e) {
|
|
169
|
+
return b.any(e, C.space("storage"), void 0, e.doc());
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
loadMe: B,
|
|
173
|
+
getPodRoot: V,
|
|
174
|
+
getMainInbox: H,
|
|
175
|
+
findStorage: U,
|
|
176
|
+
loadPreferences: R,
|
|
177
|
+
loadProfile: z,
|
|
178
|
+
silencedLoadPreferences: L
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
export { b as createProfileLogic };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=profileLogic.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileLogic.esm.js","names":[],"sources":["../../src/profile/profileLogic.ts"],"sourcesContent":["import { literal, NamedNode, st, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { CrossOriginForbiddenError, FetchError, NotEditableError, SameOriginForbiddenError, UnauthorizedError, WebOperationError } from '../logic/CustomError'\nimport * as debug from '../util/debug'\nimport { ns as namespace } from '../util/ns'\nimport { privateTypeIndexDocument, publicTypeIndexDocument } from '../typeIndex/typeIndexDocuments'\nimport { publicTypeIndexAclDocument } from '../typeIndex/typeIndexAclDocuments'\nimport { preferencesFileDocument } from './profileDocuments'\nimport { ownerOnlyContainerAclDocument } from './profileAclDocuments'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { differentOrigin, suggestPreferencesFile } from '../util/utils'\nimport { ProfileLogic } from '../types'\n\nexport function createProfileLogic(store, authn, utilityLogic): ProfileLogic {\n const ns = namespace\n const containerLogic = createContainerLogic(store)\n const loadPreferencesInFlight = new Map<string, Promise<NamedNode>>()\n const cachedPreferencesFileByWebId = new Map<string, NamedNode>()\n\n function isAbsoluteHttpUri(uri: string | null | undefined): boolean {\n return !!uri && (uri.startsWith('https://') || uri.startsWith('http://'))\n }\n\n function docDirUri(node: NamedNode): string | null {\n const doc = node.doc()\n const dir = doc.dir()\n if (dir?.uri && isAbsoluteHttpUri(dir.uri)) return dir.uri\n const docUri = doc.uri\n if (!docUri || !isAbsoluteHttpUri(docUri)) return null\n const withoutFragment = docUri.split('#')[0]\n const lastSlash = withoutFragment.lastIndexOf('/')\n if (lastSlash === -1) return null\n return withoutFragment.slice(0, lastSlash + 1)\n }\n\n function suggestTypeIndexInPreferences(preferencesFile: NamedNode, filename: string): NamedNode {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`Cannot derive directory for preferences file ${preferencesFile.uri}`)\n return sym(dirUri + filename)\n }\n\n function isNotFoundError(err: any): boolean {\n if (err?.response?.status === 404) return true\n const text = `${err?.message || err || ''}`\n return text.includes('404') || text.includes('Not Found')\n }\n\n async function ensureContainerExists(containerUri: string): Promise<void> {\n const containerNode = sym(containerUri)\n try {\n await store.fetcher.load(containerNode)\n return\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n await containerLogic.createContainer(containerUri)\n }\n\n async function ensureOwnerOnlyAclForSettings(user: NamedNode, preferencesFile: NamedNode): Promise<void> {\n const dirUri = docDirUri(preferencesFile)\n if (!dirUri) throw new Error(`Cannot derive settings directory from ${preferencesFile.uri}`)\n await ensureContainerExists(dirUri)\n\n const containerNode = sym(dirUri)\n let aclDocUri: string | undefined\n try {\n await store.fetcher.load(containerNode)\n aclDocUri = store.any(containerNode, ACL_LINK)?.value\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n if (!aclDocUri) {\n // Fallback for servers/tests where rel=acl is not exposed in mocked headers.\n aclDocUri = `${dirUri}.acl`\n }\n const aclDoc = sym(aclDocUri)\n try {\n await store.fetcher.load(aclDoc)\n return\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n\n await store.fetcher.webOperation('PUT', aclDoc.uri, {\n data: ownerOnlyContainerAclDocument(user.uri),\n contentType: 'text/turtle'\n })\n }\n\n async function ensurePublicTypeIndexAclOnCreate(user: NamedNode, publicTypeIndex: NamedNode, ensureAcl = false): Promise<void> {\n const created = await utilityLogic.loadOrCreateWithContentOnCreate(publicTypeIndex, publicTypeIndexDocument())\n if (!created && !ensureAcl) return\n\n let aclDocUri: string | undefined\n try {\n await store.fetcher.load(publicTypeIndex)\n aclDocUri = store.any(publicTypeIndex, ACL_LINK)?.value\n } catch (err) {\n if (!isNotFoundError(err)) throw err\n }\n if (!aclDocUri) {\n aclDocUri = `${publicTypeIndex.uri}.acl`\n }\n\n const aclDoc = sym(aclDocUri)\n try {\n await store.fetcher.webOperation('PUT', aclDoc.uri, {\n data: publicTypeIndexAclDocument(user.uri, publicTypeIndex.uri),\n contentType: 'text/turtle',\n headers: { 'If-None-Match': '*' }\n })\n } catch (err: any) {\n const status = err?.response?.status ?? err?.status\n if (status !== 412) throw err\n }\n }\n\n async function ensurePrivateTypeIndexOnCreate(privateTypeIndex: NamedNode): Promise<void> {\n await utilityLogic.loadOrCreateWithContentOnCreate(privateTypeIndex, privateTypeIndexDocument())\n }\n\n async function initializePreferencesDefaults(user: NamedNode, preferencesFile: NamedNode): Promise<void> {\n const preferencesDoc = preferencesFile.doc() as NamedNode\n const profileDoc = user.doc() as NamedNode\n await store.fetcher.load(preferencesDoc)\n\n const profilePublicTypeIndex =\n (store.any(user, ns.solid('publicTypeIndex'), null, profileDoc) as NamedNode | null)\n const preferencesPublicTypeIndex =\n (store.any(user, ns.solid('publicTypeIndex'), null, preferencesDoc) as NamedNode | null)\n const publicTypeIndex =\n profilePublicTypeIndex ||\n preferencesPublicTypeIndex ||\n suggestTypeIndexInPreferences(preferencesFile, 'publicTypeIndex.ttl')\n const privateTypeIndex =\n (store.any(user, ns.solid('privateTypeIndex'), null, preferencesDoc) as NamedNode | null) ||\n suggestTypeIndexInPreferences(preferencesFile, 'privateTypeIndex.ttl')\n\n // Keep discovery consistent with typeIndexLogic, which resolves publicTypeIndex from the profile doc.\n const createdProfilePublicTypeIndexLink = !profilePublicTypeIndex\n if (createdProfilePublicTypeIndexLink) {\n await utilityLogic.followOrCreateLinkWithContentOnCreate(\n user,\n ns.solid('publicTypeIndex') as NamedNode,\n publicTypeIndex,\n profileDoc,\n publicTypeIndexDocument()\n )\n }\n\n const toInsert: any[] = []\n if (!store.holds(preferencesDoc, ns.rdf('type'), ns.space('ConfigurationFile'), preferencesDoc)) {\n toInsert.push(st(preferencesDoc, ns.rdf('type'), ns.space('ConfigurationFile'), preferencesDoc))\n }\n if (!store.holds(preferencesDoc, ns.dct('title'), undefined, preferencesDoc)) {\n toInsert.push(st(preferencesDoc, ns.dct('title'), literal('Preferences file'), preferencesDoc))\n }\n if (!store.holds(user, ns.solid('publicTypeIndex'), publicTypeIndex, preferencesDoc)) {\n toInsert.push(st(user, ns.solid('publicTypeIndex'), publicTypeIndex, preferencesDoc))\n }\n if (!store.holds(user, ns.solid('privateTypeIndex'), privateTypeIndex, preferencesDoc)) {\n toInsert.push(st(user, ns.solid('privateTypeIndex'), privateTypeIndex, preferencesDoc))\n }\n\n if (toInsert.length > 0) {\n await store.updater.update([], toInsert)\n await store.fetcher.load(preferencesDoc)\n }\n\n await ensurePublicTypeIndexAclOnCreate(user, publicTypeIndex, createdProfilePublicTypeIndexLink)\n await ensurePrivateTypeIndexOnCreate(privateTypeIndex)\n }\n\n async function ensurePreferencesDocExists(preferencesFile: NamedNode): Promise<boolean> {\n try {\n const created = await utilityLogic.loadOrCreateWithContentOnCreate(preferencesFile, preferencesFileDocument())\n if (created) {\n return true\n }\n return false\n } catch (err) {\n if (err.response?.status === 401) {\n throw new UnauthorizedError()\n }\n if (err.response?.status === 403) {\n if (differentOrigin(preferencesFile)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n throw err\n }\n }\n\n /**\n * loads the preference without throwing errors - if it can create it it does so.\n * remark: it still throws error if it cannot load profile.\n * @param user\n * @returns undefined if preferenceFile cannot be returned or NamedNode if it can find it or create it\n */\n async function silencedLoadPreferences(user: NamedNode): Promise <NamedNode | undefined> {\n try {\n return await loadPreferences(user)\n } catch (err) {\n return undefined\n }\n }\n\n /**\n * loads the preference without returning different errors if it cannot create or load it.\n * remark: it also throws error if it cannot load profile.\n * @param user\n * @returns undefined if preferenceFile cannot be an Error or NamedNode if it can find it or create it\n */\n async function loadPreferences (user: NamedNode): Promise <NamedNode> {\n const cachedPreferencesFile = cachedPreferencesFileByWebId.get(user.uri)\n if (cachedPreferencesFile) {\n return cachedPreferencesFile\n }\n\n const inFlight = loadPreferencesInFlight.get(user.uri)\n if (inFlight) {\n return inFlight\n }\n\n const run = (async (): Promise<NamedNode> => {\n await loadProfile(user)\n\n const possiblePreferencesFile = suggestPreferencesFile(user)\n let preferencesFile\n try {\n const existingPreferencesFile = store.any(user, ns.space('preferencesFile'), null, user.doc()) as NamedNode | null\n if (existingPreferencesFile) {\n preferencesFile = existingPreferencesFile\n } else {\n preferencesFile = await utilityLogic.followOrCreateLink(user, ns.space('preferencesFile') as NamedNode, possiblePreferencesFile, user.doc())\n }\n\n await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)\n await ensurePreferencesDocExists(preferencesFile as NamedNode)\n await initializePreferencesDefaults(user, preferencesFile as NamedNode)\n } catch (err) {\n const message = `User ${user} has no pointer in profile to preferences file.`\n debug.warn(message)\n // we are listing the possible errors\n if (err instanceof NotEditableError) { throw err }\n if (err instanceof WebOperationError) { throw err }\n if (err instanceof UnauthorizedError) { throw err }\n if (err instanceof CrossOriginForbiddenError) { throw err }\n if (err instanceof SameOriginForbiddenError) { throw err }\n if (err instanceof FetchError) { throw err }\n throw err\n }\n\n try {\n await store.fetcher.load(preferencesFile as NamedNode)\n } catch (err) { // Maybe a permission problem or origin problem\n const msg = `Unable to load preference of user ${user}: ${err}`\n if (err.response?.status === 404) {\n // Self-heal when a stale profile pointer references a missing preferences file.\n await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)\n await ensurePreferencesDocExists(preferencesFile as NamedNode)\n await initializePreferencesDefaults(user, preferencesFile as NamedNode)\n await store.fetcher.load(preferencesFile as NamedNode)\n return preferencesFile as NamedNode\n }\n debug.warn(msg)\n if (err.response.status === 401) {\n throw new UnauthorizedError()\n }\n if (err.response.status === 403) {\n if (differentOrigin(preferencesFile)) {\n throw new CrossOriginForbiddenError()\n }\n throw new SameOriginForbiddenError()\n }\n /*if (err.response.status === 404) {\n throw new NotFoundError();\n }*/\n throw new Error(msg)\n }\n cachedPreferencesFileByWebId.set(user.uri, preferencesFile as NamedNode)\n return preferencesFile as NamedNode\n })()\n\n loadPreferencesInFlight.set(user.uri, run)\n try {\n return await run\n } finally {\n if (loadPreferencesInFlight.get(user.uri) === run) {\n loadPreferencesInFlight.delete(user.uri)\n }\n }\n }\n\n async function loadProfile (user: NamedNode):Promise <NamedNode> {\n if (!user) {\n throw new Error('loadProfile: no user given.')\n }\n try {\n await store.fetcher.load(user.doc())\n } catch (err) {\n throw new Error(`Unable to load profile of user ${user}: ${err}`)\n }\n return user.doc()\n }\n\n async function loadMe(): Promise<NamedNode> {\n const me = authn.currentUser()\n if (me === null) {\n throw new Error('Current user not found! Not logged in?')\n }\n await store.fetcher.load(me.doc())\n return me\n }\n\n function getPodRoot(user: NamedNode): NamedNode {\n const podRoot = findStorage(user)\n if (!podRoot) {\n throw new Error('User pod root not found!')\n }\n return podRoot as NamedNode\n }\n\n async function getMainInbox(user: NamedNode): Promise<NamedNode> {\n await store.fetcher.load(user)\n const mainInbox = store.any(user, ns.ldp('inbox'), undefined, user.doc())\n if (!mainInbox) {\n throw new Error('User main inbox not found!')\n }\n return mainInbox as NamedNode\n }\n\n function findStorage(me: NamedNode) {\n return store.any(me, ns.space('storage'), undefined, me.doc())\n }\n\n return {\n loadMe,\n getPodRoot,\n getMainInbox,\n findStorage,\n loadPreferences,\n loadProfile,\n silencedLoadPreferences\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,EAAmB,GAAO,GAAO,GAA4B;CACzE,IAAM,IAAK,GACL,IAAiB,EAAqB,CAAK,GAC3C,oBAA0B,IAAI,IAAgC,GAC9D,oBAA+B,IAAI,IAAuB;CAEhE,SAAS,EAAkB,GAAyC;EAChE,OAAO,CAAC,CAAC,MAAQ,EAAI,WAAW,UAAU,KAAK,EAAI,WAAW,SAAS;CAC3E;CAEA,SAAS,EAAU,GAAgC;EAC/C,IAAM,IAAM,EAAK,IAAI,GACf,IAAM,EAAI,IAAI;EACpB,IAAI,GAAK,OAAO,EAAkB,EAAI,GAAG,GAAG,OAAO,EAAI;EACvD,IAAM,IAAS,EAAI;EACnB,IAAI,CAAC,KAAU,CAAC,EAAkB,CAAM,GAAG,OAAO;EAClD,IAAM,IAAkB,EAAO,MAAM,GAAG,CAAC,CAAC,IACpC,IAAY,EAAgB,YAAY,GAAG;EAEjD,OADI,MAAc,KAAW,OACtB,EAAgB,MAAM,GAAG,IAAY,CAAC;CACjD;CAEA,SAAS,EAA8B,GAA4B,GAA6B;EAC5F,IAAM,IAAS,EAAU,CAAe;EACxC,IAAI,CAAC,GAAQ,MAAU,MAAM,gDAAgD,EAAgB,KAAK;EAClG,OAAO,EAAI,IAAS,CAAQ;CAChC;CAEA,SAAS,EAAgB,GAAmB;EACxC,IAAI,GAAK,UAAU,WAAW,KAAK,OAAO;EAC1C,IAAM,IAAO,GAAG,GAAK,WAAW,KAAO;EACvC,OAAO,EAAK,SAAS,KAAK,KAAK,EAAK,SAAS,WAAW;CAC5D;CAEA,eAAe,EAAsB,GAAqC;EACtE,IAAM,IAAgB,EAAI,CAAY;EACtC,IAAI;GACA,MAAM,EAAM,QAAQ,KAAK,CAAa;GACtC;EACJ,SAAS,GAAK;GACV,IAA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EAC5C,IAAM,IAAU,EAAY,CAAI;EAChC,IAAI,CAAC,GACD,MAAU,MAAM,0BAA0B;EAE9C,OAAO;CACX;CAEA,eAAe,EAAa,GAAqC;EAC7D,MAAM,EAAM,QAAQ,KAAK,CAAI;EAC7B,IAAM,IAAY,EAAM,IAAI,GAAM,EAAG,IAAI,OAAO,GAAG,KAAA,GAAW,EAAK,IAAI,CAAC;EACxE,IAAI,CAAC,GACD,MAAU,MAAM,4BAA4B;EAEhD,OAAO;CACX;CAEA,SAAS,EAAY,GAAe;EAChC,OAAO,EAAM,IAAI,GAAI,EAAG,MAAM,SAAS,GAAG,KAAA,GAAW,EAAG,IAAI,CAAC;CACjE;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){return e?.status??e?.response?.status}function t(e){return e===404||e===410}function n(e,n,r={}){if(e.ok||r.allowNotFound&&t(e.status))return;let i=e.status===412?`Error: File changed by someone else`:`HTTP error on ${n}! Status: ${e.status}`;throw Error(i)}function r(n){if(t(e(n)))return!0;let r=`${n?.message||n||``}`;return r.includes(`404`)||r.includes(`Not Found`)}exports.assertSuccessfulHttpResponse=n,exports.isMissingError=r;
|
|
2
|
+
//# sourceMappingURL=resourceHttp.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceHttp.cjs.js","names":[],"sources":["../../src/resource/resourceHttp.ts"],"sourcesContent":["function getHttpStatus(value: { status?: number, response?: { status?: number } } | null | undefined) {\n return value?.status ?? value?.response?.status\n}\n\nfunction isMissingStatus(status: number | undefined) {\n return status === 404 || status === 410\n}\n\nexport function assertSuccessfulHttpResponse(response: Response, method: string, options: { allowNotFound?: boolean } = {}) {\n if (response.ok) return\n\n if (options.allowNotFound && isMissingStatus(response.status)) return\n\n const message = response.status === 412\n ? 'Error: File changed by someone else'\n : `HTTP error on ${method}! Status: ${response.status}`\n throw new Error(message)\n}\n\nexport function isMissingError(error: any): boolean {\n if (isMissingStatus(getHttpStatus(error))) return true\n const text = `${error?.message || error || ''}`\n return text.includes('404') || text.includes('Not Found')\n}\n"],"mappings":"AAAA,SAAS,EAAc,EAA+E,CACpG,OAAO,GAAO,QAAU,GAAO,UAAU,MAC3C,CAEA,SAAS,EAAgB,EAA4B,CACnD,OAAO,IAAW,KAAO,IAAW,GACtC,CAEA,SAAgB,EAA6B,EAAoB,EAAgB,EAAuC,CAAC,EAAG,CAG1H,GAFI,EAAS,IAET,EAAQ,eAAiB,EAAgB,EAAS,MAAM,EAAG,OAE/D,IAAM,EAAU,EAAS,SAAW,IAChC,sCACA,iBAAiB,EAAO,YAAY,EAAS,SACjD,MAAU,MAAM,CAAO,CACzB,CAEA,SAAgB,EAAe,EAAqB,CAClD,GAAI,EAAgB,EAAc,CAAK,CAAC,EAAG,MAAO,GAClD,IAAM,EAAO,GAAG,GAAO,SAAW,GAAS,KAC3C,OAAO,EAAK,SAAS,KAAK,GAAK,EAAK,SAAS,WAAW,CAC1D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/resource/resourceHttp.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e?.status ?? e?.response?.status;
|
|
4
|
+
}
|
|
5
|
+
function t(e) {
|
|
6
|
+
return e === 404 || e === 410;
|
|
7
|
+
}
|
|
8
|
+
function n(e, n, r = {}) {
|
|
9
|
+
if (e.ok || r.allowNotFound && t(e.status)) return;
|
|
10
|
+
let i = e.status === 412 ? "Error: File changed by someone else" : `HTTP error on ${n}! Status: ${e.status}`;
|
|
11
|
+
throw Error(i);
|
|
12
|
+
}
|
|
13
|
+
function r(n) {
|
|
14
|
+
if (t(e(n))) return !0;
|
|
15
|
+
let r = `${n?.message || n || ""}`;
|
|
16
|
+
return r.includes("404") || r.includes("Not Found");
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { n as assertSuccessfulHttpResponse, r as isMissingError };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=resourceHttp.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceHttp.esm.js","names":[],"sources":["../../src/resource/resourceHttp.ts"],"sourcesContent":["function getHttpStatus(value: { status?: number, response?: { status?: number } } | null | undefined) {\n return value?.status ?? value?.response?.status\n}\n\nfunction isMissingStatus(status: number | undefined) {\n return status === 404 || status === 410\n}\n\nexport function assertSuccessfulHttpResponse(response: Response, method: string, options: { allowNotFound?: boolean } = {}) {\n if (response.ok) return\n\n if (options.allowNotFound && isMissingStatus(response.status)) return\n\n const message = response.status === 412\n ? 'Error: File changed by someone else'\n : `HTTP error on ${method}! Status: ${response.status}`\n throw new Error(message)\n}\n\nexport function isMissingError(error: any): boolean {\n if (isMissingStatus(getHttpStatus(error))) return true\n const text = `${error?.message || error || ''}`\n return text.includes('404') || text.includes('Not Found')\n}\n"],"mappings":";AAAA,SAAS,EAAc,GAA+E;CACpG,OAAO,GAAO,UAAU,GAAO,UAAU;AAC3C;AAEA,SAAS,EAAgB,GAA4B;CACnD,OAAO,MAAW,OAAO,MAAW;AACtC;AAEA,SAAgB,EAA6B,GAAoB,GAAgB,IAAuC,CAAC,GAAG;CAG1H,IAFI,EAAS,MAET,EAAQ,iBAAiB,EAAgB,EAAS,MAAM,GAAG;CAE/D,IAAM,IAAU,EAAS,WAAW,MAChC,wCACA,iBAAiB,EAAO,YAAY,EAAS;CACjD,MAAU,MAAM,CAAO;AACzB;AAEA,SAAgB,EAAe,GAAqB;CAClD,IAAI,EAAgB,EAAc,CAAK,CAAC,GAAG,OAAO;CAClD,IAAM,IAAO,GAAG,GAAO,WAAW,KAAS;CAC3C,OAAO,EAAK,SAAS,KAAK,KAAK,EAAK,SAAS,WAAW;AAC1D"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../util/ns.cjs.js"),t=require("../acl/aclLogic.cjs.js"),n=require("./resourceHttp.cjs.js"),r=require("./resourceMetadata.cjs.js");let i=require("rdflib");function a(a,o,s,c){function l(e){return s.createContainer(e)}function u(e){return s.isContainer(e)}function d(e){return s.getContainerMemberCount(e)}function f(n,i){let o,s=!1,c=!1,l,u;if(i.headers){o=i.headers.get(`content-type`)?.split(`;`)[0]??void 0;let t=r.readWacAccessInfo(i.headers.get(`wac-allow`));s=t.canEdit,c=t.isPublic,l=i.headers.get(`etag`)??void 0,u=a.anyValue(n,e.ns.dct(`modified`))||a.anyValue(n,e.ns.dc(`modified`))||void 0}(!i.headers||!i.headers.get(`content-type`))&&(!i.headers||!i.headers.get(`wac-allow`)||!i.headers.get(`etag`))&&a.each(null,a.sym(`http://www.w3.org/2007/ont/link#requestedURI`),n).map(t=>{let i=a.any(t,a.sym(`http://www.w3.org/2007/ont/link#response`));if(i&&i.termType===`NamedNode`){let t=a.anyValue(i,e.ns.httph(`content-type`))||void 0;o===void 0&&(o=t);let d=r.readWacAccessInfo(a.anyValue(i,e.ns.httph(`wac-allow`))||a.anyValue(i,e.ns.httph(`WAC-Allow`)));s||=d.canEdit,c||=d.isPublic;let f=a.anyValue(i,e.ns.httph(`etag`))||void 0;l===void 0&&(l=f),u=a.anyValue(n,e.ns.dct(`modified`))||a.anyValue(n,e.ns.dc(`modified`))||void 0}});let d=a.any(n,t.ACL_LINK)?.value||void 0;return{contentType:o,access:{canEdit:s,isPublic:c},aclUri:d,eTag:l,modified:u}}async function p(e){let t=await a.fetcher.webOperation(`HEAD`,e.uri);return n.assertSuccessfulHttpResponse(t,`HEAD`),f(e,t)}async function m(t){let n=a.any(t,e.ns.ldp(`contains`))||t.dir();if(!n||n.termType!==`NamedNode`)return!1;try{return(await p(n)).access.canEdit}catch{return!1}}async function h(e){return m(e)}async function g(e){return p(e)}async function _(e){let t;try{t=await p(e)}catch{t={contentType:void 0,access:{canEdit:!1,isPublic:!1},aclUri:void 0,eTag:void 0,modified:void 0}}let n=await h(e),r={canEdit:t.access?.canEdit??!1,isPublic:t.access?.isPublic??!1,canDelete:n};return{...t,access:r}}async function v(e,t){if(t)try{await c.deleteTypeIndexRegistrationForResource(e,t)}catch{}}async function y(t,r={}){let o=t.dir();if(u(t)){let e=await s.getContainerMembers(t);await Promise.all(e.map(e=>y((0,i.sym)(e),r)))}let c;try{c=await a.fetcher._fetch(t.value,{method:`DELETE`}),n.assertSuccessfulHttpResponse(c,`DELETE`,{allowNotFound:!0})}catch(e){if(!n.isMissingError(e))throw e}return r.deleteTypeIndexes&&await v(t,r.user),o&&a.removeMatches(o,e.ns.ldp(`contains`),t,o.doc()),a.removeDocument(t),a.fetcher.unload(t.doc()),c}async function b(e,t){await y(e,{deleteTypeIndexes:!0,user:t})}return{recursiveDelete:y,deleteResourceAndTypeIndexIfExists:b,fetchMetadata:g,fetchMetadataWithDelete:_,createContainer:l,isContainer:u,getContainerMemberCount:d}}exports.createResourceLogic=a;
|
|
2
|
+
//# sourceMappingURL=resourceLogic.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceLogic.cjs.js","names":[],"sources":["../../src/resource/resourceLogic.ts"],"sourcesContent":["import { NamedNode, sym } from 'rdflib'\nimport { ACL_LINK } from '../acl/aclLogic'\nimport { ns } from '../util/ns'\nimport { assertSuccessfulHttpResponse, isMissingError } from './resourceHttp'\nimport { readWacAccessInfo } from './resourceMetadata'\nimport { type AclLogic, type ResourceAccess, type ResourceAccessWithDelete, type ResourceDeleteOptions, type ResourceLogic, type ResourceMetadata, type ResourceMetadataWithDelete, type TypeIndexLogic } from '../types'\n\nexport function createResourceLogic(store, aclLogic: AclLogic, containerLogic, typeIndexLogic: TypeIndexLogic): ResourceLogic {\n function createContainer(url: string) {\n return containerLogic.createContainer(url)\n }\n\n function isContainer(resourceNode: NamedNode) {\n return containerLogic.isContainer(resourceNode)\n }\n\n function getContainerMemberCount(resourceNode: NamedNode) {\n return containerLogic.getContainerMemberCount(resourceNode)\n }\n\n function readMetadata(subject: NamedNode, response: Response): ResourceMetadata {\n let contentType: string | undefined\n let canEdit = false\n let isPublic = false\n let eTag: string | undefined\n let modified: string | undefined\n\n if (response.headers) {\n const contentTypeHeader = response.headers.get('content-type')\n contentType = contentTypeHeader?.split(';')[0] ?? undefined\n\n const accessFlags = readWacAccessInfo(response.headers.get('wac-allow'))\n canEdit = accessFlags.canEdit\n isPublic = accessFlags.isPublic\n eTag = response.headers.get('etag') ?? undefined\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n\n if ((!response.headers || !response.headers.get('content-type')) && (!response.headers || !response.headers.get('wac-allow') || !response.headers.get('etag'))) {\n const reqs = store.each(\n null,\n store.sym('http://www.w3.org/2007/ont/link#requestedURI'),\n subject\n )\n reqs.map((req: any) => {\n const responseNode = store.any(\n req as any,\n store.sym('http://www.w3.org/2007/ont/link#response')\n )\n if (responseNode && responseNode.termType === 'NamedNode') {\n const responseContentType = store.anyValue(responseNode as any, ns.httph('content-type')) || undefined\n if (contentType === undefined) {\n contentType = responseContentType\n }\n const wacAllow = (store.anyValue(responseNode as any, ns.httph('wac-allow')) as string | undefined) ||\n (store.anyValue(responseNode as any, ns.httph('WAC-Allow')) as string | undefined)\n const accessFlags = readWacAccessInfo(wacAllow)\n canEdit = canEdit || accessFlags.canEdit\n isPublic = isPublic || accessFlags.isPublic\n const responseETag = store.anyValue(responseNode as any, ns.httph('etag')) || undefined\n if (eTag === undefined) {\n eTag = responseETag\n }\n modified = store.anyValue(subject as any, ns.dct('modified')) || store.anyValue(subject as any, ns.dc('modified')) || undefined\n }\n })\n }\n\n const aclUri = store.any(subject, ACL_LINK)?.value || undefined\n const access: ResourceAccess = { canEdit, isPublic }\n return { contentType, access, aclUri, eTag, modified }\n }\n\n async function fetchHeadMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n const response = await store.fetcher.webOperation('HEAD', subject.uri)\n assertSuccessfulHttpResponse(response, 'HEAD')\n return readMetadata(subject, response)\n }\n\n async function userCanWriteToContainingContainer(resourceNode: NamedNode): Promise<boolean> {\n const containerNode = store.any(resourceNode, ns.ldp('contains')) || resourceNode.dir()\n if (!containerNode || containerNode.termType !== 'NamedNode') {\n return false\n }\n\n try {\n const containerMetadata = await fetchHeadMetadata(containerNode as NamedNode)\n return containerMetadata.access.canEdit\n } catch (_error) {\n return false\n }\n }\n\n async function userCanDeleteResource(resourceNode: NamedNode): Promise<boolean> {\n return userCanWriteToContainingContainer(resourceNode)\n }\n\n async function fetchMetadata(subject: NamedNode): Promise<ResourceMetadata> {\n return fetchHeadMetadata(subject)\n }\n\n async function fetchMetadataWithDelete(subject: NamedNode): Promise<ResourceMetadataWithDelete> {\n let resourceMetadata: ResourceMetadata\n\n try {\n resourceMetadata = await fetchHeadMetadata(subject)\n } catch (_error) {\n resourceMetadata = {\n contentType: undefined,\n access: { canEdit: false, isPublic: false },\n aclUri: undefined,\n eTag: undefined,\n modified: undefined\n }\n }\n\n const canDelete = await userCanDeleteResource(subject)\n const access: ResourceAccessWithDelete = {\n canEdit: resourceMetadata.access?.canEdit ?? false,\n isPublic: resourceMetadata.access?.isPublic ?? false,\n canDelete\n }\n return { ...resourceMetadata, access }\n }\n\n async function deleteTypeIndexesForResource(resourceNode: NamedNode, user?: NamedNode | null) {\n if (!user) return\n\n try {\n await typeIndexLogic.deleteTypeIndexRegistrationForResource(resourceNode, user)\n } catch (_error) {\n // Keep resource deletion best-effort even if type-index cleanup fails.\n }\n }\n\n async function recursiveDelete(resourceNode: NamedNode, options: ResourceDeleteOptions = {}) {\n const resourceParent = resourceNode.dir()\n\n if (isContainer(resourceNode)) {\n const containerMembers = await containerLogic.getContainerMembers(resourceNode)\n await Promise.all(containerMembers.map((url) => recursiveDelete(sym(url), options)))\n }\n\n let deleted\n try {\n deleted = await store.fetcher._fetch(resourceNode.value, { method: 'DELETE' })\n assertSuccessfulHttpResponse(deleted, 'DELETE', { allowNotFound: true })\n } catch (error) {\n if (!isMissingError(error)) {\n throw error\n }\n }\n\n if (options.deleteTypeIndexes) {\n await deleteTypeIndexesForResource(resourceNode, options.user)\n }\n\n if (resourceParent) {\n store.removeMatches(resourceParent, ns.ldp('contains'), resourceNode, resourceParent.doc())\n }\n\n store.removeDocument(resourceNode)\n store.fetcher.unload(resourceNode.doc())\n return deleted\n }\n\n async function deleteResourceAndTypeIndexIfExists(resourceNode: NamedNode, user?: NamedNode | null) {\n await recursiveDelete(resourceNode, { deleteTypeIndexes: true, user })\n }\n\n return {\n recursiveDelete,\n deleteResourceAndTypeIndexIfExists,\n fetchMetadata,\n fetchMetadataWithDelete,\n createContainer,\n isContainer,\n getContainerMemberCount\n }\n}\n"],"mappings":"2KAOA,SAAgB,EAAoB,EAAO,EAAoB,EAAgB,EAA+C,CAC5H,SAAS,EAAgB,EAAa,CACpC,OAAO,EAAe,gBAAgB,CAAG,CAC3C,CAEA,SAAS,EAAY,EAAyB,CAC5C,OAAO,EAAe,YAAY,CAAY,CAChD,CAEA,SAAS,EAAwB,EAAyB,CACxD,OAAO,EAAe,wBAAwB,CAAY,CAC5D,CAEA,SAAS,EAAa,EAAoB,EAAsC,CAC9E,IAAI,EACA,EAAU,GACV,EAAW,GACX,EACA,EAEJ,GAAI,EAAS,QAAS,CAEpB,EAD0B,EAAS,QAAQ,IAAI,cACjC,CAAA,EAAmB,MAAM,GAAG,CAAC,CAAC,IAAM,IAAA,GAElD,IAAM,EAAc,EAAA,kBAAkB,EAAS,QAAQ,IAAI,WAAW,CAAC,EACvE,EAAU,EAAY,QACtB,EAAW,EAAY,SACvB,EAAO,EAAS,QAAQ,IAAI,MAAM,GAAK,IAAA,GACvC,EAAW,EAAM,SAAS,EAAgB,EAAA,GAAG,IAAI,UAAU,CAAC,GAAK,EAAM,SAAS,EAAgB,EAAA,GAAG,GAAG,UAAU,CAAC,GAAK,IAAA,EACxH,EAEK,CAAC,EAAS,SAAW,CAAC,EAAS,QAAQ,IAAI,cAAc,KAAO,CAAC,EAAS,SAAW,CAAC,EAAS,QAAQ,IAAI,WAAW,GAAK,CAAC,EAAS,QAAQ,IAAI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,MAAM,EAA6B,EAAc,EAAQ,IAAI,EAG3D,GACF,EAAM,cAAc,EAAgB,EAAA,GAAG,IAAI,UAAU,EAAG,EAAc,EAAe,IAAI,CAAC,EAG5F,EAAM,eAAe,CAAY,EACjC,EAAM,QAAQ,OAAO,EAAa,IAAI,CAAC,EAChC,CACT,CAEA,eAAe,EAAmC,EAAyB,EAAyB,CAClG,MAAM,EAAgB,EAAc,CAAE,kBAAmB,GAAM,MAAK,CAAC,CACvE,CAEA,MAAO,CACL,kBACA,qCACA,gBACA,0BACA,kBACA,cACA,yBACF,CACF"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ns as e } from "../util/ns.esm.js";
|
|
2
|
+
import { ACL_LINK as t } from "../acl/aclLogic.esm.js";
|
|
3
|
+
import { assertSuccessfulHttpResponse as n, isMissingError as r } from "./resourceHttp.esm.js";
|
|
4
|
+
import { readWacAccessInfo as i } from "./resourceMetadata.esm.js";
|
|
5
|
+
import { sym as a } from "rdflib";
|
|
6
|
+
//#region src/resource/resourceLogic.ts
|
|
7
|
+
function o(o, s, c, l) {
|
|
8
|
+
function u(e) {
|
|
9
|
+
return c.createContainer(e);
|
|
10
|
+
}
|
|
11
|
+
function d(e) {
|
|
12
|
+
return c.isContainer(e);
|
|
13
|
+
}
|
|
14
|
+
function f(e) {
|
|
15
|
+
return c.getContainerMemberCount(e);
|
|
16
|
+
}
|
|
17
|
+
function p(n, r) {
|
|
18
|
+
let a, s = !1, c = !1, l, u;
|
|
19
|
+
if (r.headers) {
|
|
20
|
+
a = r.headers.get("content-type")?.split(";")[0] ?? void 0;
|
|
21
|
+
let t = i(r.headers.get("wac-allow"));
|
|
22
|
+
s = t.canEdit, c = t.isPublic, l = r.headers.get("etag") ?? void 0, u = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
|
|
23
|
+
}
|
|
24
|
+
(!r.headers || !r.headers.get("content-type")) && (!r.headers || !r.headers.get("wac-allow") || !r.headers.get("etag")) && o.each(null, o.sym("http://www.w3.org/2007/ont/link#requestedURI"), n).map((t) => {
|
|
25
|
+
let r = o.any(t, o.sym("http://www.w3.org/2007/ont/link#response"));
|
|
26
|
+
if (r && r.termType === "NamedNode") {
|
|
27
|
+
let t = o.anyValue(r, e.httph("content-type")) || void 0;
|
|
28
|
+
a === void 0 && (a = t);
|
|
29
|
+
let d = i(o.anyValue(r, e.httph("wac-allow")) || o.anyValue(r, e.httph("WAC-Allow")));
|
|
30
|
+
s ||= d.canEdit, c ||= d.isPublic;
|
|
31
|
+
let f = o.anyValue(r, e.httph("etag")) || void 0;
|
|
32
|
+
l === void 0 && (l = f), u = o.anyValue(n, e.dct("modified")) || o.anyValue(n, e.dc("modified")) || void 0;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
let d = o.any(n, t)?.value || void 0;
|
|
36
|
+
return {
|
|
37
|
+
contentType: a,
|
|
38
|
+
access: {
|
|
39
|
+
canEdit: s,
|
|
40
|
+
isPublic: c
|
|
41
|
+
},
|
|
42
|
+
aclUri: d,
|
|
43
|
+
eTag: l,
|
|
44
|
+
modified: u
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function m(e) {
|
|
48
|
+
let t = await o.fetcher.webOperation("HEAD", e.uri);
|
|
49
|
+
return n(t, "HEAD"), p(e, t);
|
|
50
|
+
}
|
|
51
|
+
async function h(t) {
|
|
52
|
+
let n = o.any(t, e.ldp("contains")) || t.dir();
|
|
53
|
+
if (!n || n.termType !== "NamedNode") return !1;
|
|
54
|
+
try {
|
|
55
|
+
return (await m(n)).access.canEdit;
|
|
56
|
+
} catch {
|
|
57
|
+
return !1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function g(e) {
|
|
61
|
+
return h(e);
|
|
62
|
+
}
|
|
63
|
+
async function _(e) {
|
|
64
|
+
return m(e);
|
|
65
|
+
}
|
|
66
|
+
async function v(e) {
|
|
67
|
+
let t;
|
|
68
|
+
try {
|
|
69
|
+
t = await m(e);
|
|
70
|
+
} catch {
|
|
71
|
+
t = {
|
|
72
|
+
contentType: void 0,
|
|
73
|
+
access: {
|
|
74
|
+
canEdit: !1,
|
|
75
|
+
isPublic: !1
|
|
76
|
+
},
|
|
77
|
+
aclUri: void 0,
|
|
78
|
+
eTag: void 0,
|
|
79
|
+
modified: void 0
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
let n = await g(e), r = {
|
|
83
|
+
canEdit: t.access?.canEdit ?? !1,
|
|
84
|
+
isPublic: t.access?.isPublic ?? !1,
|
|
85
|
+
canDelete: n
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
...t,
|
|
89
|
+
access: r
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function y(e, t) {
|
|
93
|
+
if (t) try {
|
|
94
|
+
await l.deleteTypeIndexRegistrationForResource(e, t);
|
|
95
|
+
} catch {}
|
|
96
|
+
}
|
|
97
|
+
async function b(t, i = {}) {
|
|
98
|
+
let s = t.dir();
|
|
99
|
+
if (d(t)) {
|
|
100
|
+
let e = await c.getContainerMembers(t);
|
|
101
|
+
await Promise.all(e.map((e) => b(a(e), i)));
|
|
102
|
+
}
|
|
103
|
+
let l;
|
|
104
|
+
try {
|
|
105
|
+
l = await o.fetcher._fetch(t.value, { method: "DELETE" }), n(l, "DELETE", { allowNotFound: !0 });
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (!r(e)) throw e;
|
|
108
|
+
}
|
|
109
|
+
return i.deleteTypeIndexes && await y(t, i.user), s && o.removeMatches(s, e.ldp("contains"), t, s.doc()), o.removeDocument(t), o.fetcher.unload(t.doc()), l;
|
|
110
|
+
}
|
|
111
|
+
async function x(e, t) {
|
|
112
|
+
await b(e, {
|
|
113
|
+
deleteTypeIndexes: !0,
|
|
114
|
+
user: t
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
recursiveDelete: b,
|
|
119
|
+
deleteResourceAndTypeIndexIfExists: x,
|
|
120
|
+
fetchMetadata: _,
|
|
121
|
+
fetchMetadataWithDelete: v,
|
|
122
|
+
createContainer: u,
|
|
123
|
+
isContainer: d,
|
|
124
|
+
getContainerMemberCount: f
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export { o as createResourceLogic };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=resourceLogic.esm.js.map
|