solid-logic 6.0.0 → 6.0.1-1

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.
Files changed (164) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs.js +1 -1
  2. package/dist/acl/accessControlSubjects.cjs.js +2 -0
  3. package/dist/acl/accessControlSubjects.cjs.js.map +1 -0
  4. package/dist/acl/accessControlSubjects.d.ts +8 -0
  5. package/dist/acl/accessControlSubjects.d.ts.map +1 -0
  6. package/dist/acl/accessControlSubjects.esm.js +75 -0
  7. package/dist/acl/accessControlSubjects.esm.js.map +1 -0
  8. package/dist/acl/aclLogic.cjs.js +1 -1
  9. package/dist/acl/aclLogic.cjs.js.map +1 -1
  10. package/dist/acl/aclLogic.d.ts +10 -0
  11. package/dist/acl/aclLogic.d.ts.map +1 -0
  12. package/dist/acl/aclLogic.esm.js +128 -26
  13. package/dist/acl/aclLogic.esm.js.map +1 -1
  14. package/dist/authSession/authSession.cjs.js.map +1 -1
  15. package/dist/authSession/authSession.d.ts +42 -0
  16. package/dist/authSession/authSession.d.ts.map +1 -0
  17. package/dist/authSession/authSession.esm.js.map +1 -1
  18. package/dist/authSession/events.cjs.js.map +1 -1
  19. package/dist/authSession/events.d.ts +25 -0
  20. package/dist/authSession/events.d.ts.map +1 -0
  21. package/dist/authSession/events.esm.js.map +1 -1
  22. package/dist/authSession/flagAuthorizationOnTransitions.cjs.js +1 -1
  23. package/dist/authSession/flagAuthorizationOnTransitions.cjs.js.map +1 -1
  24. package/dist/authSession/flagAuthorizationOnTransitions.d.ts +76 -0
  25. package/dist/authSession/flagAuthorizationOnTransitions.d.ts.map +1 -0
  26. package/dist/authSession/flagAuthorizationOnTransitions.esm.js +1 -1
  27. package/dist/authSession/flagAuthorizationOnTransitions.esm.js.map +1 -1
  28. package/dist/authSession/identityState.cjs.js +1 -1
  29. package/dist/authSession/identityState.cjs.js.map +1 -1
  30. package/dist/authSession/identityState.d.ts +199 -0
  31. package/dist/authSession/identityState.d.ts.map +1 -0
  32. package/dist/authSession/identityState.esm.js +1 -1
  33. package/dist/authSession/identityState.esm.js.map +1 -1
  34. package/dist/authSession/issuer.d.ts +8 -0
  35. package/dist/authSession/issuer.d.ts.map +1 -0
  36. package/dist/authSession/session.cjs.js +1 -1
  37. package/dist/authSession/session.cjs.js.map +1 -1
  38. package/dist/authSession/session.d.ts +45 -0
  39. package/dist/authSession/session.d.ts.map +1 -0
  40. package/dist/authSession/session.esm.js +1 -1
  41. package/dist/authSession/session.esm.js.map +1 -1
  42. package/dist/authn/SolidAuthnLogic.cjs.js.map +1 -1
  43. package/dist/authn/SolidAuthnLogic.d.ts +61 -0
  44. package/dist/authn/SolidAuthnLogic.d.ts.map +1 -0
  45. package/dist/authn/SolidAuthnLogic.esm.js.map +1 -1
  46. package/dist/authn/authUtil.cjs.js.map +1 -1
  47. package/dist/authn/authUtil.d.ts +17 -0
  48. package/dist/authn/authUtil.d.ts.map +1 -0
  49. package/dist/authn/serverLogout.d.ts +6 -0
  50. package/dist/authn/serverLogout.d.ts.map +1 -0
  51. package/dist/chat/chatLogic.cjs.js +1 -1
  52. package/dist/chat/chatLogic.cjs.js.map +1 -1
  53. package/dist/chat/chatLogic.d.ts +3 -0
  54. package/dist/chat/chatLogic.d.ts.map +1 -0
  55. package/dist/chat/chatLogic.esm.js +5 -5
  56. package/dist/chat/chatLogic.esm.js.map +1 -1
  57. package/dist/directory/catalogDirectory.cjs.js +2 -0
  58. package/dist/directory/catalogDirectory.cjs.js.map +1 -0
  59. package/dist/directory/catalogDirectory.d.ts +5 -0
  60. package/dist/directory/catalogDirectory.d.ts.map +1 -0
  61. package/dist/directory/catalogDirectory.esm.js +54 -0
  62. package/dist/directory/catalogDirectory.esm.js.map +1 -0
  63. package/dist/directory/contactsDirectory.cjs.js +2 -0
  64. package/dist/directory/contactsDirectory.cjs.js.map +1 -0
  65. package/dist/directory/contactsDirectory.d.ts +7 -0
  66. package/dist/directory/contactsDirectory.d.ts.map +1 -0
  67. package/dist/directory/contactsDirectory.esm.js +91 -0
  68. package/dist/directory/contactsDirectory.esm.js.map +1 -0
  69. package/dist/directory/directoryHelpers.cjs.js +2 -0
  70. package/dist/directory/directoryHelpers.cjs.js.map +1 -0
  71. package/dist/directory/directoryHelpers.d.ts +18 -0
  72. package/dist/directory/directoryHelpers.d.ts.map +1 -0
  73. package/dist/directory/directoryHelpers.esm.js +89 -0
  74. package/dist/directory/directoryHelpers.esm.js.map +1 -0
  75. package/dist/directory/directoryLogic.cjs.js +2 -0
  76. package/dist/directory/directoryLogic.cjs.js.map +1 -0
  77. package/dist/directory/directoryLogic.d.ts +6 -0
  78. package/dist/directory/directoryLogic.d.ts.map +1 -0
  79. package/dist/directory/directoryLogic.esm.js +41 -0
  80. package/dist/directory/directoryLogic.esm.js.map +1 -0
  81. package/dist/directory/friendsDirectory.cjs.js +2 -0
  82. package/dist/directory/friendsDirectory.cjs.js.map +1 -0
  83. package/dist/directory/friendsDirectory.d.ts +6 -0
  84. package/dist/directory/friendsDirectory.d.ts.map +1 -0
  85. package/dist/directory/friendsDirectory.esm.js +58 -0
  86. package/dist/directory/friendsDirectory.esm.js.map +1 -0
  87. package/dist/inbox/inboxLogic.d.ts +3 -0
  88. package/dist/inbox/inboxLogic.d.ts.map +1 -0
  89. package/dist/index.cjs.js +1 -1
  90. package/dist/index.cjs.js.map +1 -1
  91. package/dist/index.d.ts +19 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.esm.js +10 -9
  94. package/dist/index.esm.js.map +1 -1
  95. package/dist/issuer/issuerLogic.d.ts +8 -0
  96. package/dist/issuer/issuerLogic.d.ts.map +1 -0
  97. package/dist/logic/CustomError.cjs.js.map +1 -1
  98. package/dist/logic/CustomError.d.ts +21 -0
  99. package/dist/logic/CustomError.d.ts.map +1 -0
  100. package/dist/logic/CustomError.esm.js.map +1 -1
  101. package/dist/logic/solidLogic.cjs.js +1 -1
  102. package/dist/logic/solidLogic.cjs.js.map +1 -1
  103. package/dist/logic/solidLogic.d.ts +6 -0
  104. package/dist/logic/solidLogic.d.ts.map +1 -0
  105. package/dist/logic/solidLogic.esm.js +29 -27
  106. package/dist/logic/solidLogic.esm.js.map +1 -1
  107. package/dist/logic/solidLogicSingleton.cjs.js +1 -1
  108. package/dist/logic/solidLogicSingleton.cjs.js.map +1 -1
  109. package/dist/logic/solidLogicSingleton.d.ts +4 -0
  110. package/dist/logic/solidLogicSingleton.d.ts.map +1 -0
  111. package/dist/logic/solidLogicSingleton.esm.js +2 -1
  112. package/dist/logic/solidLogicSingleton.esm.js.map +1 -1
  113. package/dist/profile/profileAclDocuments.d.ts +2 -0
  114. package/dist/profile/profileAclDocuments.d.ts.map +1 -0
  115. package/dist/profile/profileDocuments.d.ts +2 -0
  116. package/dist/profile/profileDocuments.d.ts.map +1 -0
  117. package/dist/profile/profileLogic.cjs.js.map +1 -1
  118. package/dist/profile/profileLogic.d.ts +3 -0
  119. package/dist/profile/profileLogic.d.ts.map +1 -0
  120. package/dist/profile/profileLogic.esm.js +2 -1
  121. package/dist/profile/profileLogic.esm.js.map +1 -1
  122. package/dist/resource/resourceHttp.d.ts +5 -0
  123. package/dist/resource/resourceHttp.d.ts.map +1 -0
  124. package/dist/resource/resourceLogic.cjs.js +1 -1
  125. package/dist/resource/resourceLogic.cjs.js.map +1 -1
  126. package/dist/resource/resourceLogic.d.ts +4 -0
  127. package/dist/resource/resourceLogic.d.ts.map +1 -0
  128. package/dist/resource/resourceLogic.esm.js +36 -26
  129. package/dist/resource/resourceLogic.esm.js.map +1 -1
  130. package/dist/resource/resourceMetadata.d.ts +5 -0
  131. package/dist/resource/resourceMetadata.d.ts.map +1 -0
  132. package/dist/typeIndex/typeIndexAclDocuments.d.ts +2 -0
  133. package/dist/typeIndex/typeIndexAclDocuments.d.ts.map +1 -0
  134. package/dist/typeIndex/typeIndexDocuments.d.ts +3 -0
  135. package/dist/typeIndex/typeIndexDocuments.d.ts.map +1 -0
  136. package/dist/typeIndex/typeIndexLogic.cjs.js.map +1 -1
  137. package/dist/typeIndex/typeIndexLogic.d.ts +3 -0
  138. package/dist/typeIndex/typeIndexLogic.d.ts.map +1 -0
  139. package/dist/typeIndex/typeIndexLogic.esm.js +10 -5
  140. package/dist/typeIndex/typeIndexLogic.esm.js.map +1 -1
  141. package/dist/types.d.ts +192 -0
  142. package/dist/types.d.ts.map +1 -0
  143. package/dist/util/containerLogic.cjs.js.map +1 -1
  144. package/dist/util/containerLogic.d.ts +12 -0
  145. package/dist/util/containerLogic.d.ts.map +1 -0
  146. package/dist/util/containerLogic.esm.js.map +1 -1
  147. package/dist/util/debug.d.ts +5 -0
  148. package/dist/util/debug.d.ts.map +1 -0
  149. package/dist/util/ns.cjs.js.map +1 -1
  150. package/dist/util/ns.d.ts +2 -0
  151. package/dist/util/ns.d.ts.map +1 -0
  152. package/dist/util/utilityLogic.cjs.js +1 -1
  153. package/dist/util/utilityLogic.cjs.js.map +1 -1
  154. package/dist/util/utilityLogic.d.ts +16 -0
  155. package/dist/util/utilityLogic.d.ts.map +1 -0
  156. package/dist/util/utilityLogic.esm.js +6 -2
  157. package/dist/util/utilityLogic.esm.js.map +1 -1
  158. package/dist/util/utils.cjs.js +1 -1
  159. package/dist/util/utils.cjs.js.map +1 -1
  160. package/dist/util/utils.d.ts +8 -0
  161. package/dist/util/utils.d.ts.map +1 -0
  162. package/dist/util/utils.esm.js +5 -3
  163. package/dist/util/utils.esm.js.map +1 -1
  164. package/package.json +6 -4
@@ -0,0 +1,21 @@
1
+ declare class CustomError extends Error {
2
+ constructor(message?: string);
3
+ }
4
+ export declare class UnauthorizedError extends CustomError {
5
+ }
6
+ export declare class CrossOriginForbiddenError extends CustomError {
7
+ }
8
+ export declare class SameOriginForbiddenError extends CustomError {
9
+ }
10
+ export declare class NotFoundError extends CustomError {
11
+ }
12
+ export declare class NotEditableError extends CustomError {
13
+ }
14
+ export declare class WebOperationError extends CustomError {
15
+ }
16
+ export declare class FetchError extends CustomError {
17
+ status: number;
18
+ constructor(status: number, message?: string);
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=CustomError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomError.d.ts","sourceRoot":"","sources":["../../src/logic/CustomError.ts"],"names":[],"mappings":"AAAA,cAAM,WAAY,SAAQ,KAAK;gBACf,OAAO,CAAC,EAAE,MAAM;CAM/B;AAED,qBAAa,iBAAkB,SAAQ,WAAW;CAAG;AAErD,qBAAa,yBAA0B,SAAQ,WAAW;CAAG;AAE7D,qBAAa,wBAAyB,SAAQ,WAAW;CAAG;AAE5D,qBAAa,aAAc,SAAQ,WAAW;CAAG;AAEjD,qBAAa,gBAAiB,SAAQ,WAAW;CAAI;AAErD,qBAAa,iBAAkB,SAAQ,WAAW;CAAG;AAErD,qBAAa,UAAW,SAAQ,WAAW;IACvC,MAAM,EAAE,MAAM,CAAA;gBAEF,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAI/C"}
@@ -1 +1 @@
1
- {"version":3,"file":"CustomError.esm.js","names":[],"sources":["../../src/logic/CustomError.ts"],"sourcesContent":["class CustomError extends Error {\n constructor(message?: string) {\n super(message)\n // see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html\n Object.setPrototypeOf(this, new.target.prototype) // restore prototype chain\n this.name = new.target.name // stack traces display correctly now\n }\n}\n\nexport class UnauthorizedError extends CustomError {}\n\nexport class CrossOriginForbiddenError extends CustomError {}\n\nexport class SameOriginForbiddenError extends CustomError {}\n\nexport class NotFoundError extends CustomError {}\n\nexport class NotEditableError extends CustomError { }\n\nexport class WebOperationError extends CustomError {}\n\nexport class FetchError extends CustomError {\n status: number\n\n constructor(status: number, message?: string) {\n super(message)\n this.status = status\n }\n}"],"mappings":";AAAA,IAAM,IAAN,cAA0B,MAAM;CAC5B,YAAY,GAAkB;EAI1B,AAHA,MAAM,CAAO,GAEb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS,GAChD,KAAK,OAAO,IAAI,OAAO;CAC3B;AACJ,GAEa,IAAb,cAAuC,EAAY,CAAC,GAEvC,IAAb,cAA+C,EAAY,CAAC,GAE/C,IAAb,cAA8C,EAAY,CAAC,GAE9C,IAAb,cAAmC,EAAY,CAAC,GAEnC,IAAb,cAAsC,EAAY,CAAE,GAEvC,IAAb,cAAuC,EAAY,CAAC,GAEvC,IAAb,cAAgC,EAAY;CAGxC,YAAY,GAAgB,GAAkB;EAE1C,AADA,MAAM,CAAO,GACb,KAAK,SAAS;CAClB;AACJ"}
1
+ {"version":3,"file":"CustomError.esm.js","names":[],"sources":["../../src/logic/CustomError.ts"],"sourcesContent":["class CustomError extends Error {\n constructor(message?: string) {\n super(message)\n // see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html\n Object.setPrototypeOf(this, new.target.prototype) // restore prototype chain\n this.name = new.target.name // stack traces display correctly now\n }\n}\n\nexport class UnauthorizedError extends CustomError {}\n\nexport class CrossOriginForbiddenError extends CustomError {}\n\nexport class SameOriginForbiddenError extends CustomError {}\n\nexport class NotFoundError extends CustomError {}\n\nexport class NotEditableError extends CustomError { }\n\nexport class WebOperationError extends CustomError {}\n\nexport class FetchError extends CustomError {\n status: number\n\n constructor(status: number, message?: string) {\n super(message)\n this.status = status\n }\n}"],"mappings":";AAAA,IAAM,IAAN,cAA0B,MAAM;CAC5B,YAAY,GAAkB;EAI1B,AAHA,MAAM,CAAO,GAEb,OAAO,eAAe,MAAM,WAAW,SAAS,GAChD,KAAK,OAAO,WAAW;CAC3B;AACJ,GAEa,IAAb,cAAuC,EAAY,CAAC,GAEvC,IAAb,cAA+C,EAAY,CAAC,GAE/C,IAAb,cAA8C,EAAY,CAAC,GAE9C,IAAb,cAAmC,EAAY,CAAC,GAEnC,IAAb,cAAsC,EAAY,CAAE,GAEvC,IAAb,cAAuC,EAAY,CAAC,GAEvC,IAAb,cAAgC,EAAY;CAGxC,YAAY,GAAgB,GAAkB;EAE1C,AADA,MAAM,CAAO,GACb,KAAK,SAAS;CAClB;AACJ"}
@@ -1,2 +1,2 @@
1
- const e=require("../_virtual/_rolldown/runtime.cjs.js"),t=require("../util/debug.cjs.js"),n=require("../acl/aclLogic.cjs.js"),r=require("../authn/SolidAuthnLogic.cjs.js"),i=require("../authSession/flagAuthorizationOnTransitions.cjs.js"),a=require("../chat/chatLogic.cjs.js"),o=require("../inbox/inboxLogic.cjs.js"),s=require("../resource/resourceLogic.cjs.js"),c=require("../util/containerLogic.cjs.js"),l=require("../profile/profileLogic.cjs.js"),u=require("../typeIndex/typeIndexLogic.cjs.js"),d=require("../util/utilityLogic.cjs.js");let f=require("rdflib");f=e.__toESM(f);function p(e,p){t.log(`SolidLogic: Unique instance created. There should only be one of these.`);let m=f.graph();f.fetcher(m,{fetch:e.fetch}),m.updater=new f.UpdateManager(m),m.features=[];let h=i.flagAuthorizationOnSessionTransitions(m,p),g=new r.SolidAuthnLogic(p),_=g.dispose?.bind(g);g.dispose=()=>{h(),_?.()};let v=n.createAclLogic(m),y=c.createContainerLogic(m),b=d.createUtilityLogic(m,v,y),x=l.createProfileLogic(m,g,b),S=a.createChatLogic(m,x),C=o.createInboxLogic(m,x,b,y,v),w=u.createTypeIndexLogic(m,g,x,b),T=s.createResourceLogic(m,v,y,w);t.log(`SolidAuthnLogic initialized`);function E(e){return m.fetcher.load(e)}function D(e,t=[]){return new Promise((n,r)=>{m.updater.update(e,t,function(e,t,i){t?n():r(Error(i))})})}function O(){m.statements.slice().forEach(m.remove.bind(m))}return{store:m,authn:g,acl:v,resource:T,inbox:C,chat:S,profile:x,typeIndex:w,load:E,updatePromise:D,clearStore:O}}exports.createSolidLogic=p;
1
+ const e=require("../_virtual/_rolldown/runtime.cjs.js"),t=require("../util/debug.cjs.js"),n=require("../acl/aclLogic.cjs.js"),r=require("../authn/SolidAuthnLogic.cjs.js"),i=require("../authSession/flagAuthorizationOnTransitions.cjs.js"),a=require("../chat/chatLogic.cjs.js"),o=require("../inbox/inboxLogic.cjs.js"),s=require("../resource/resourceLogic.cjs.js"),c=require("../util/containerLogic.cjs.js"),l=require("../profile/profileLogic.cjs.js"),u=require("../typeIndex/typeIndexLogic.cjs.js"),d=require("../directory/directoryLogic.cjs.js"),f=require("../util/utilityLogic.cjs.js");let p=require("rdflib");p=e.__toESM(p);function m(e,m){t.log(`SolidLogic: Unique instance created. There should only be one of these.`);let h=p.graph();p.fetcher(h,{fetch:e.fetch}),h.updater=new p.UpdateManager(h),h.features=[];let g=i.flagAuthorizationOnSessionTransitions(h,m),_=new r.SolidAuthnLogic(m),v=_.dispose?.bind(_);_.dispose=()=>{g(),v?.()};let y=n.createAclLogic(h),b=c.createContainerLogic(h),x=f.createUtilityLogic(h,y,b),S=l.createProfileLogic(h,_,x),C=a.createChatLogic(h,S),w=o.createInboxLogic(h,S,x,b,y),T=u.createTypeIndexLogic(h,_,S,x),E=d.createDirectoryLogic(h,_,T),D=s.createResourceLogic(h,y,b,T);t.log(`SolidAuthnLogic initialized`);function O(e){return h.fetcher.load(e)}function k(e,t=[]){return new Promise((n,r)=>{h.updater.update(e,t,function(e,t,i){t?n():r(Error(i))})})}function A(){h.statements.slice().forEach(h.remove.bind(h))}return{store:h,authn:_,acl:y,resource:D,inbox:w,chat:C,profile:S,typeIndex:T,directory:E,load:O,updatePromise:k,clearStore:A}}exports.createSolidLogic=m;
2
2
  //# sourceMappingURL=solidLogic.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"solidLogic.cjs.js","names":[],"sources":["../../src/logic/solidLogic.ts"],"sourcesContent":["import * as rdf from 'rdflib'\nimport { LiveStore, NamedNode, Statement } from 'rdflib'\nimport { createAclLogic } from '../acl/aclLogic'\nimport { SolidAuthnLogic } from '../authn/SolidAuthnLogic'\nimport type { SessionWithLegacyEvents } from '../authSession/authSession'\nimport { flagAuthorizationOnSessionTransitions } from '../authSession/flagAuthorizationOnTransitions'\nimport { createChatLogic } from '../chat/chatLogic'\nimport { createInboxLogic } from '../inbox/inboxLogic'\nimport { createResourceLogic } from '../resource/resourceLogic'\nimport { createProfileLogic } from '../profile/profileLogic'\nimport { createTypeIndexLogic } from '../typeIndex/typeIndexLogic'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { createUtilityLogic } from '../util/utilityLogic'\nimport type { AuthnLogic, SolidLogic } from '../types'\nimport * as debug from '../util/debug'\n/*\n** It is important to distinquish `fetch`, a function provided by the browser\n** and `Fetcher`, a helper object for the rdflib Store which turns it\n** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is\n** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,\n*/\nexport function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: SessionWithLegacyEvents): SolidLogic {\n\n debug.log('SolidLogic: Unique instance created. There should only be one of these.')\n const store: LiveStore = rdf.graph() as LiveStore\n rdf.fetcher(store, {fetch: specialFetch.fetch}) // Attach a web I/O module, store.fetcher\n store.updater = new rdf.UpdateManager(store) // Add real-time live updates store.updater\n store.features = [] // disable automatic node merging on store load\n // Whose credentials a request would carry changed: mark every recorded\n // response out-of-date so editability answers \"unknown\" instead of the\n // previous identity's access. Decision points repair with\n // ensureDocumentAuthorization() (see flagAuthorizationOnTransitions.ts).\n const unsubscribeAuthorization = flagAuthorizationOnSessionTransitions(store, session)\n\n const authn: AuthnLogic = new SolidAuthnLogic(session)\n\n // The subscription is released with the auth logic: both belong to this\n // instance's lifetime, so replacing a SolidLogic instance does not leave\n // the old store subscribed to the session.\n const disposeAuthn = authn.dispose?.bind(authn)\n authn.dispose = (): void => {\n unsubscribeAuthorization()\n disposeAuthn?.()\n }\n \n const acl = createAclLogic(store)\n const containerLogic = createContainerLogic(store)\n const utilityLogic = createUtilityLogic(store, acl, containerLogic)\n const profile = createProfileLogic(store, authn, utilityLogic)\n const chat = createChatLogic(store, profile)\n const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl)\n const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic)\n const resource = createResourceLogic(store, acl, containerLogic, typeIndex)\n debug.log('SolidAuthnLogic initialized')\n\n function load(doc: NamedNode | NamedNode[] | string) {\n return store.fetcher.load(doc)\n }\n\n // @@@@ use the one in rdflib.js when it is available and delete this\n function updatePromise(\n del: Array<Statement>,\n ins: Array<Statement> = []\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n store.updater.update(del, ins, function (_uri, ok, errorBody) {\n if (!ok) {\n reject(new Error(errorBody))\n } else {\n resolve()\n }\n }) // callback\n }) // promise\n }\n\n function clearStore() {\n store.statements.slice().forEach(store.remove.bind(store))\n }\n\n return {\n store,\n authn,\n acl,\n resource,\n inbox,\n chat,\n profile,\n typeIndex,\n load,\n updatePromise,\n clearStore\n }\n}\n"],"mappings":"gkBAqBA,SAAgB,EAAiB,EAA8D,EAA8C,CAEzI,EAAA,IAAU,0EAA0E,EACpF,IAAM,EAAmB,EAAI,MAAM,EACnC,EAAI,QAAQ,EAAO,CAAC,MAAO,EAAa,KAAK,CAAC,EAC9C,EAAM,QAAU,IAAI,EAAI,cAAc,CAAK,EAC3C,EAAM,SAAW,CAAC,EAKlB,IAAM,EAA2B,EAAA,sCAAsC,EAAO,CAAO,EAE/E,EAAoB,IAAI,EAAA,gBAAgB,CAAO,EAK/C,EAAe,EAAM,SAAS,KAAK,CAAK,EAC9C,EAAM,YAAsB,CAC1B,EAAyB,EACzB,IAAe,CACjB,EAEA,IAAM,EAAM,EAAA,eAAe,CAAK,EAC1B,EAAiB,EAAA,qBAAqB,CAAK,EAC3C,EAAe,EAAA,mBAAmB,EAAO,EAAK,CAAc,EAC5D,EAAU,EAAA,mBAAmB,EAAO,EAAO,CAAY,EACvD,EAAO,EAAA,gBAAgB,EAAO,CAAO,EACrC,EAAQ,EAAA,iBAAiB,EAAO,EAAS,EAAc,EAAgB,CAAG,EAC1E,EAAY,EAAA,qBAAqB,EAAO,EAAO,EAAS,CAAY,EACpE,EAAW,EAAA,oBAAoB,EAAO,EAAK,EAAgB,CAAS,EAC1E,EAAA,IAAU,6BAA6B,EAEvC,SAAS,EAAK,EAAuC,CACjD,OAAO,EAAM,QAAQ,KAAK,CAAG,CACjC,CAGA,SAAS,EACL,EACA,EAAwB,CAAC,EACZ,CACb,OAAO,IAAI,SAAS,EAAS,IAAW,CACxC,EAAM,QAAQ,OAAO,EAAK,EAAK,SAAU,EAAM,EAAI,EAAW,CACrD,EAGL,EAAQ,EAFR,EAAW,MAAM,CAAS,CAAC,CAI/B,CAAC,CACD,CAAC,CACL,CAEA,SAAS,GAAa,CAClB,EAAM,WAAW,MAAM,CAAC,CAAC,QAAQ,EAAM,OAAO,KAAK,CAAK,CAAC,CAC7D,CAEA,MAAO,CACH,QACA,QACA,MACA,WACA,QACA,OACA,UACA,YACA,OACA,gBACA,YACJ,CACJ"}
1
+ {"version":3,"file":"solidLogic.cjs.js","names":[],"sources":["../../src/logic/solidLogic.ts"],"sourcesContent":["import * as rdf from 'rdflib'\nimport { LiveStore, NamedNode, Statement } from 'rdflib'\nimport { createAclLogic } from '../acl/aclLogic'\nimport { SolidAuthnLogic } from '../authn/SolidAuthnLogic'\nimport type { SessionWithLegacyEvents } from '../authSession/authSession'\nimport { flagAuthorizationOnSessionTransitions } from '../authSession/flagAuthorizationOnTransitions'\nimport { createChatLogic } from '../chat/chatLogic'\nimport { createInboxLogic } from '../inbox/inboxLogic'\nimport { createResourceLogic } from '../resource/resourceLogic'\nimport { createProfileLogic } from '../profile/profileLogic'\nimport { createTypeIndexLogic } from '../typeIndex/typeIndexLogic'\nimport { createDirectoryLogic } from '../directory/directoryLogic'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { createUtilityLogic } from '../util/utilityLogic'\nimport type { AuthnLogic, SolidLogic } from '../types'\nimport * as debug from '../util/debug'\n/*\n** It is important to distinquish `fetch`, a function provided by the browser\n** and `Fetcher`, a helper object for the rdflib Store which turns it\n** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is\n** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,\n*/\nexport function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: SessionWithLegacyEvents): SolidLogic {\n\n debug.log('SolidLogic: Unique instance created. There should only be one of these.')\n const store: LiveStore = rdf.graph() as LiveStore\n rdf.fetcher(store, {fetch: specialFetch.fetch}) // Attach a web I/O module, store.fetcher\n store.updater = new rdf.UpdateManager(store) // Add real-time live updates store.updater\n store.features = [] // disable automatic node merging on store load\n // Whose credentials a request would carry changed: mark every recorded\n // response out-of-date so editability answers \"unknown\" instead of the\n // previous identity's access. Decision points repair with\n // ensureDocumentAuthorization() (see flagAuthorizationOnTransitions.ts).\n const unsubscribeAuthorization = flagAuthorizationOnSessionTransitions(store, session)\n\n const authn: AuthnLogic = new SolidAuthnLogic(session)\n\n // The subscription is released with the auth logic: both belong to this\n // instance's lifetime, so replacing a SolidLogic instance does not leave\n // the old store subscribed to the session.\n const disposeAuthn = authn.dispose?.bind(authn)\n authn.dispose = (): void => {\n unsubscribeAuthorization()\n disposeAuthn?.()\n }\n \n const acl = createAclLogic(store)\n const containerLogic = createContainerLogic(store)\n const utilityLogic = createUtilityLogic(store, acl, containerLogic)\n const profile = createProfileLogic(store, authn, utilityLogic)\n const chat = createChatLogic(store, profile)\n const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl)\n const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic)\n const directory = createDirectoryLogic(store, authn, typeIndex)\n const resource = createResourceLogic(store, acl, containerLogic, typeIndex)\n debug.log('SolidAuthnLogic initialized')\n\n function load(doc: NamedNode | NamedNode[] | string) {\n return store.fetcher.load(doc)\n }\n\n // @@@@ use the one in rdflib.js when it is available and delete this\n function updatePromise(\n del: Array<Statement>,\n ins: Array<Statement> = []\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n store.updater.update(del, ins, function (_uri, ok, errorBody) {\n if (!ok) {\n reject(new Error(errorBody))\n } else {\n resolve()\n }\n }) // callback\n }) // promise\n }\n\n function clearStore() {\n store.statements.slice().forEach(store.remove.bind(store))\n }\n\n return {\n store,\n authn,\n acl,\n resource,\n inbox,\n ch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,CAAC,QAAQ,EAAM,OAAO,KAAK,CAAK,CAAC,CAC7D,CAEA,MAAO,CACH,QACA,QACA,MACA,WACA,QACA,OACA,UACA,YACA,YACA,OACA,gBACA,YACJ,CACJ"}
@@ -0,0 +1,6 @@
1
+ import type { SessionWithLegacyEvents } from '../authSession/authSession';
2
+ import type { SolidLogic } from '../types';
3
+ export declare function createSolidLogic(specialFetch: {
4
+ fetch: (url: any, requestInit: any) => any;
5
+ }, session: SessionWithLegacyEvents): SolidLogic;
6
+ //# sourceMappingURL=solidLogic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solidLogic.d.ts","sourceRoot":"","sources":["../../src/logic/solidLogic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAUzE,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,UAAU,CAAA;AAQtD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE;IAAE,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,KAAK,GAAG,CAAA;CAAE,EAAE,OAAO,EAAE,uBAAuB,GAAG,UAAU,CAyE3I"}
@@ -8,47 +8,49 @@ import { createResourceLogic as o } from "../resource/resourceLogic.esm.js";
8
8
  import { createContainerLogic as s } from "../util/containerLogic.esm.js";
9
9
  import { createProfileLogic as c } from "../profile/profileLogic.esm.js";
10
10
  import { createTypeIndexLogic as l } from "../typeIndex/typeIndexLogic.esm.js";
11
- import { createUtilityLogic as u } from "../util/utilityLogic.esm.js";
12
- import * as d from "rdflib";
11
+ import { createDirectoryLogic as u } from "../directory/directoryLogic.esm.js";
12
+ import { createUtilityLogic as d } from "../util/utilityLogic.esm.js";
13
+ import * as f from "rdflib";
13
14
  //#region src/logic/solidLogic.ts
14
- function f(f, p) {
15
+ function p(p, m) {
15
16
  e("SolidLogic: Unique instance created. There should only be one of these.");
16
- let m = d.graph();
17
- d.fetcher(m, { fetch: f.fetch }), m.updater = new d.UpdateManager(m), m.features = [];
18
- let h = r(m, p), g = new n(p), _ = g.dispose?.bind(g);
19
- g.dispose = () => {
20
- h(), _?.();
17
+ let h = f.graph();
18
+ f.fetcher(h, { fetch: p.fetch }), h.updater = new f.UpdateManager(h), h.features = [];
19
+ let g = r(h, m), _ = new n(m), v = _.dispose?.bind(_);
20
+ _.dispose = () => {
21
+ g(), v?.();
21
22
  };
22
- let v = t(m), y = s(m), b = u(m, v, y), x = c(m, g, b), S = i(m, x), C = a(m, x, b, y, v), w = l(m, g, x, b), T = o(m, v, y, w);
23
+ let y = t(h), b = s(h), x = d(h, y, b), S = c(h, _, x), C = i(h, S), w = a(h, S, x, b, y), T = l(h, _, S, x), E = u(h, _, T), D = o(h, y, b, T);
23
24
  e("SolidAuthnLogic initialized");
24
- function E(e) {
25
- return m.fetcher.load(e);
25
+ function O(e) {
26
+ return h.fetcher.load(e);
26
27
  }
27
- function D(e, t = []) {
28
+ function k(e, t = []) {
28
29
  return new Promise((n, r) => {
29
- m.updater.update(e, t, function(e, t, i) {
30
+ h.updater.update(e, t, function(e, t, i) {
30
31
  t ? n() : r(Error(i));
31
32
  });
32
33
  });
33
34
  }
34
- function O() {
35
- m.statements.slice().forEach(m.remove.bind(m));
35
+ function A() {
36
+ h.statements.slice().forEach(h.remove.bind(h));
36
37
  }
37
38
  return {
38
- store: m,
39
- authn: g,
40
- acl: v,
41
- resource: T,
42
- inbox: C,
43
- chat: S,
44
- profile: x,
45
- typeIndex: w,
46
- load: E,
47
- updatePromise: D,
48
- clearStore: O
39
+ store: h,
40
+ authn: _,
41
+ acl: y,
42
+ resource: D,
43
+ inbox: w,
44
+ chat: C,
45
+ profile: S,
46
+ typeIndex: T,
47
+ directory: E,
48
+ load: O,
49
+ updatePromise: k,
50
+ clearStore: A
49
51
  };
50
52
  }
51
53
  //#endregion
52
- export { f as createSolidLogic };
54
+ export { p as createSolidLogic };
53
55
 
54
56
  //# sourceMappingURL=solidLogic.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"solidLogic.esm.js","names":[],"sources":["../../src/logic/solidLogic.ts"],"sourcesContent":["import * as rdf from 'rdflib'\nimport { LiveStore, NamedNode, Statement } from 'rdflib'\nimport { createAclLogic } from '../acl/aclLogic'\nimport { SolidAuthnLogic } from '../authn/SolidAuthnLogic'\nimport type { SessionWithLegacyEvents } from '../authSession/authSession'\nimport { flagAuthorizationOnSessionTransitions } from '../authSession/flagAuthorizationOnTransitions'\nimport { createChatLogic } from '../chat/chatLogic'\nimport { createInboxLogic } from '../inbox/inboxLogic'\nimport { createResourceLogic } from '../resource/resourceLogic'\nimport { createProfileLogic } from '../profile/profileLogic'\nimport { createTypeIndexLogic } from '../typeIndex/typeIndexLogic'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { createUtilityLogic } from '../util/utilityLogic'\nimport type { AuthnLogic, SolidLogic } from '../types'\nimport * as debug from '../util/debug'\n/*\n** It is important to distinquish `fetch`, a function provided by the browser\n** and `Fetcher`, a helper object for the rdflib Store which turns it\n** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is\n** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,\n*/\nexport function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: SessionWithLegacyEvents): SolidLogic {\n\n debug.log('SolidLogic: Unique instance created. There should only be one of these.')\n const store: LiveStore = rdf.graph() as LiveStore\n rdf.fetcher(store, {fetch: specialFetch.fetch}) // Attach a web I/O module, store.fetcher\n store.updater = new rdf.UpdateManager(store) // Add real-time live updates store.updater\n store.features = [] // disable automatic node merging on store load\n // Whose credentials a request would carry changed: mark every recorded\n // response out-of-date so editability answers \"unknown\" instead of the\n // previous identity's access. Decision points repair with\n // ensureDocumentAuthorization() (see flagAuthorizationOnTransitions.ts).\n const unsubscribeAuthorization = flagAuthorizationOnSessionTransitions(store, session)\n\n const authn: AuthnLogic = new SolidAuthnLogic(session)\n\n // The subscription is released with the auth logic: both belong to this\n // instance's lifetime, so replacing a SolidLogic instance does not leave\n // the old store subscribed to the session.\n const disposeAuthn = authn.dispose?.bind(authn)\n authn.dispose = (): void => {\n unsubscribeAuthorization()\n disposeAuthn?.()\n }\n \n const acl = createAclLogic(store)\n const containerLogic = createContainerLogic(store)\n const utilityLogic = createUtilityLogic(store, acl, containerLogic)\n const profile = createProfileLogic(store, authn, utilityLogic)\n const chat = createChatLogic(store, profile)\n const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl)\n const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic)\n const resource = createResourceLogic(store, acl, containerLogic, typeIndex)\n debug.log('SolidAuthnLogic initialized')\n\n function load(doc: NamedNode | NamedNode[] | string) {\n return store.fetcher.load(doc)\n }\n\n // @@@@ use the one in rdflib.js when it is available and delete this\n function updatePromise(\n del: Array<Statement>,\n ins: Array<Statement> = []\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n store.updater.update(del, ins, function (_uri, ok, errorBody) {\n if (!ok) {\n reject(new Error(errorBody))\n } else {\n resolve()\n }\n }) // callback\n }) // promise\n }\n\n function clearStore() {\n store.statements.slice().forEach(store.remove.bind(store))\n }\n\n return {\n store,\n authn,\n acl,\n resource,\n inbox,\n chat,\n profile,\n typeIndex,\n load,\n updatePromise,\n clearStore\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAqBA,SAAgB,EAAiB,GAA8D,GAA8C;CAEzI,EAAU,0EAA0E;CACpF,IAAM,IAAmB,EAAI,MAAM;CAGnC,AAFA,EAAI,QAAQ,GAAO,EAAC,OAAO,EAAa,MAAK,CAAC,GAC9C,EAAM,UAAU,IAAI,EAAI,cAAc,CAAK,GAC3C,EAAM,WAAW,CAAC;CAKlB,IAAM,IAA2B,EAAsC,GAAO,CAAO,GAE/E,IAAoB,IAAI,EAAgB,CAAO,GAK/C,IAAe,EAAM,SAAS,KAAK,CAAK;CAC9C,EAAM,gBAAsB;EAE1B,AADA,EAAyB,GACzB,IAAe;CACjB;CAEA,IAAM,IAAM,EAAe,CAAK,GAC1B,IAAiB,EAAqB,CAAK,GAC3C,IAAe,EAAmB,GAAO,GAAK,CAAc,GAC5D,IAAU,EAAmB,GAAO,GAAO,CAAY,GACvD,IAAO,EAAgB,GAAO,CAAO,GACrC,IAAQ,EAAiB,GAAO,GAAS,GAAc,GAAgB,CAAG,GAC1E,IAAY,EAAqB,GAAO,GAAO,GAAS,CAAY,GACpE,IAAW,EAAoB,GAAO,GAAK,GAAgB,CAAS;CAC1E,EAAU,6BAA6B;CAEvC,SAAS,EAAK,GAAuC;EACjD,OAAO,EAAM,QAAQ,KAAK,CAAG;CACjC;CAGA,SAAS,EACL,GACA,IAAwB,CAAC,GACZ;EACb,OAAO,IAAI,SAAS,GAAS,MAAW;GACxC,EAAM,QAAQ,OAAO,GAAK,GAAK,SAAU,GAAM,GAAI,GAAW;IAC1D,AAAK,IAGL,EAAQ,IAFR,EAAW,MAAM,CAAS,CAAC;GAI/B,CAAC;EACD,CAAC;CACL;CAEA,SAAS,IAAa;EAClB,EAAM,WAAW,MAAM,CAAC,CAAC,QAAQ,EAAM,OAAO,KAAK,CAAK,CAAC;CAC7D;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
1
+ {"version":3,"file":"solidLogic.esm.js","names":[],"sources":["../../src/logic/solidLogic.ts"],"sourcesContent":["import * as rdf from 'rdflib'\nimport { LiveStore, NamedNode, Statement } from 'rdflib'\nimport { createAclLogic } from '../acl/aclLogic'\nimport { SolidAuthnLogic } from '../authn/SolidAuthnLogic'\nimport type { SessionWithLegacyEvents } from '../authSession/authSession'\nimport { flagAuthorizationOnSessionTransitions } from '../authSession/flagAuthorizationOnTransitions'\nimport { createChatLogic } from '../chat/chatLogic'\nimport { createInboxLogic } from '../inbox/inboxLogic'\nimport { createResourceLogic } from '../resource/resourceLogic'\nimport { createProfileLogic } from '../profile/profileLogic'\nimport { createTypeIndexLogic } from '../typeIndex/typeIndexLogic'\nimport { createDirectoryLogic } from '../directory/directoryLogic'\nimport { createContainerLogic } from '../util/containerLogic'\nimport { createUtilityLogic } from '../util/utilityLogic'\nimport type { AuthnLogic, SolidLogic } from '../types'\nimport * as debug from '../util/debug'\n/*\n** It is important to distinquish `fetch`, a function provided by the browser\n** and `Fetcher`, a helper object for the rdflib Store which turns it\n** into a `ConnectedStore` or a `LiveStore`. A Fetcher object is\n** available at store.fetcher, and `fetch` function at `store.fetcher._fetch`,\n*/\nexport function createSolidLogic(specialFetch: { fetch: (url: any, requestInit: any) => any }, session: SessionWithLegacyEvents): SolidLogic {\n\n debug.log('SolidLogic: Unique instance created. There should only be one of these.')\n const store: LiveStore = rdf.graph() as LiveStore\n rdf.fetcher(store, {fetch: specialFetch.fetch}) // Attach a web I/O module, store.fetcher\n store.updater = new rdf.UpdateManager(store) // Add real-time live updates store.updater\n store.features = [] // disable automatic node merging on store load\n // Whose credentials a request would carry changed: mark every recorded\n // response out-of-date so editability answers \"unknown\" instead of the\n // previous identity's access. Decision points repair with\n // ensureDocumentAuthorization() (see flagAuthorizationOnTransitions.ts).\n const unsubscribeAuthorization = flagAuthorizationOnSessionTransitions(store, session)\n\n const authn: AuthnLogic = new SolidAuthnLogic(session)\n\n // The subscription is released with the auth logic: both belong to this\n // instance's lifetime, so replacing a SolidLogic instance does not leave\n // the old store subscribed to the session.\n const disposeAuthn = authn.dispose?.bind(authn)\n authn.dispose = (): void => {\n unsubscribeAuthorization()\n disposeAuthn?.()\n }\n \n const acl = createAclLogic(store)\n const containerLogic = createContainerLogic(store)\n const utilityLogic = createUtilityLogic(store, acl, containerLogic)\n const profile = createProfileLogic(store, authn, utilityLogic)\n const chat = createChatLogic(store, profile)\n const inbox = createInboxLogic(store, profile, utilityLogic, containerLogic, acl)\n const typeIndex = createTypeIndexLogic(store, authn, profile, utilityLogic)\n const directory = createDirectoryLogic(store, authn, typeIndex)\n const resource = createResourceLogic(store, acl, containerLogic, typeIndex)\n debug.log('SolidAuthnLogic initialized')\n\n function load(doc: NamedNode | NamedNode[] | string) {\n return store.fetcher.load(doc)\n }\n\n // @@@@ use the one in rdflib.js when it is available and delete this\n function updatePromise(\n del: Array<Statement>,\n ins: Array<Statement> = []\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n store.updater.update(del, ins, function (_uri, ok, errorBody) {\n if (!ok) {\n reject(new Error(errorBody))\n } else {\n resolve()\n }\n }) // callback\n }) // promise\n }\n\n function clearStore() {\n store.statements.slice().forEach(store.remove.bind(store))\n }\n\n return {\n store,\n authn,\n acl,\n resource,\n inbox,\n chat,\n profile,\n typeIndex,\n directory,\n load,\n updatePromise,\n clearStore\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,EAAiB,GAA8D,GAA8C;CAEzI,EAAU,0EAA0E;CACpF,IAAM,IAAmB,EAAI,MAAM;CAGnC,AAFA,EAAI,QAAQ,GAAO,EAAC,OAAO,EAAa,MAAK,CAAC,GAC9C,EAAM,UAAU,IAAI,EAAI,cAAc,CAAK,GAC3C,EAAM,WAAW,CAAC;CAKlB,IAAM,IAA2B,EAAsC,GAAO,CAAO,GAE/E,IAAoB,IAAI,EAAgB,CAAO,GAK/C,IAAe,EAAM,SAAS,KAAK,CAAK;CAC9C,EAAM,gBAAsB;EAE1B,AADA,EAAyB,GACzB,IAAe;CACjB;CAEA,IAAM,IAAM,EAAe,CAAK,GAC1B,IAAiB,EAAqB,CAAK,GAC3C,IAAe,EAAmB,GAAO,GAAK,CAAc,GAC5D,IAAU,EAAmB,GAAO,GAAO,CAAY,GACvD,IAAO,EAAgB,GAAO,CAAO,GACrC,IAAQ,EAAiB,GAAO,GAAS,GAAc,GAAgB,CAAG,GAC1E,IAAY,EAAqB,GAAO,GAAO,GAAS,CAAY,GACpE,IAAY,EAAqB,GAAO,GAAO,CAAS,GACxD,IAAW,EAAoB,GAAO,GAAK,GAAgB,CAAS;CAC1E,EAAU,6BAA6B;CAEvC,SAAS,EAAK,GAAuC;EACjD,OAAO,EAAM,QAAQ,KAAK,CAAG;CACjC;CAGA,SAAS,EACL,GACA,IAAwB,CAAC,GACZ;EACb,OAAO,IAAI,SAAS,GAAS,MAAW;GACxC,EAAM,QAAQ,OAAO,GAAK,GAAK,SAAU,GAAM,GAAI,GAAW;IAC1D,AAAK,IAGL,EAAQ,IAFR,EAAW,MAAM,CAAS,CAAC;GAI/B,CAAC;EACD,CAAC;CACL;CAEA,SAAS,IAAa;EAClB,EAAM,WAAW,MAAM,CAAC,CAAC,QAAQ,EAAM,OAAO,KAAK,CAAK,CAAC;CAC7D;CAEA,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ"}
@@ -1,2 +1,2 @@
1
- const e=require("../util/debug.cjs.js"),t=require("../authSession/identityState.cjs.js"),n=require("../authSession/authSession.cjs.js"),r=require("./solidLogic.cjs.js");var i=async(e,r)=>{let i=r&&r.credentials&&r.credentials==`omit`,a=n.authSession;if(!t.sessionExplicitlyInactive(a)&&(a?.info?.webId||a?.webId)&&!i){let t=typeof a.fetch==`function`?a.fetch.bind(a):typeof a.authFetch==`function`?a.authFetch.bind(a):null;return t?t(e,r):window.fetch(e,r)}else return window.fetch(e,r)},a=Symbol.for(`solid-logic-singleton`),o=typeof window<`u`?window:global;function s(){return o[a]?e.log(`SolidLogic: Using existing global singleton instance.`):(e.log(`SolidLogic: Creating new global singleton instance.`),o[a]=r.createSolidLogic({fetch:i},n.authSession),e.log(`Unique quadstore initialized.`)),o[a]}var c=s();exports.solidLogicSingleton=c;
1
+ const e=require("../util/debug.cjs.js"),t=require("../authSession/identityState.cjs.js"),n=require("../authSession/authSession.cjs.js"),r=require("./solidLogic.cjs.js");var i=async(e,r)=>{let i=r&&r.credentials&&r.credentials==`omit`,a=n.authSession;if(!t.sessionExplicitlyInactive(a)&&(a?.info?.webId||a?.webId)&&!i){let t=typeof a.fetch==`function`?a.fetch.bind(a):typeof a.authFetch==`function`?a.authFetch.bind(a):null;return t?t(e,r):window.fetch(e,r)}return window.fetch(e,r)},a=Symbol.for(`solid-logic-singleton`),o=typeof window<`u`?window:global;function s(){return o[a]?e.log(`SolidLogic: Using existing global singleton instance.`):(e.log(`SolidLogic: Creating new global singleton instance.`),o[a]=r.createSolidLogic({fetch:i},n.authSession),e.log(`Unique quadstore initialized.`)),o[a]}var c=s();exports.solidLogicSingleton=c;
2
2
  //# sourceMappingURL=solidLogicSingleton.cjs.js.map
@@ -1 +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 { sessionExplicitlyInactive } from '../authSession/identityState'\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 // A session that explicitly reports itself inactive must not keep\n // identifying the last user: with a retained WebID, choosing the\n // authenticated fetch would send the previous identity's credentials.\n const sessionWebId = sessionExplicitlyInactive(sessionAny)\n ? undefined\n : (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":"yKAMA,IAAM,EAAS,MAAO,EAAK,IAAgB,CACvC,IAAM,EAAY,GAAe,EAAY,aAAe,EAAY,aAAe,OACjF,EAAa,EAAA,YAOnB,GAHqB,GAAA,0BAA0B,CAAU,IAElD,GAAY,MAAM,OAAS,GAAY,QAC1B,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"}
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 { sessionExplicitlyInactive } from '../authSession/identityState'\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 // A session that explicitly reports itself inactive must not keep\n // identifying the last user: with a retained WebID, choosing the\n // authenticated fetch would send the previous identity's credentials.\n const sessionWebId = sessionExplicitlyInactive(sessionAny)\n ? undefined\n : (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":"yKAMA,IAAM,EAAS,MAAO,EAAK,IAAgB,CACvC,IAAM,EAAY,GAAe,EAAY,aAAe,EAAY,aAAe,OACjF,EAAa,EAAA,YAOnB,GAHqB,GAAA,0BAA0B,CAAU,IAElD,GAAY,MAAM,OAAS,GAAY,QAC1B,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,CACI,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,4 @@
1
+ import { SolidLogic } from '../types';
2
+ declare const solidLogicSingleton: SolidLogic;
3
+ export { solidLogicSingleton };
4
+ //# sourceMappingURL=solidLogicSingleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solidLogicSingleton.d.ts","sourceRoot":"","sources":["../../src/logic/solidLogicSingleton.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AA8CrC,QAAA,MAAM,mBAAmB,YAAyB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
@@ -8,7 +8,8 @@ var i = async (e, r) => {
8
8
  if (!t(a) && (a?.info?.webId || a?.webId) && !i) {
9
9
  let t = typeof a.fetch == "function" ? a.fetch.bind(a) : typeof a.authFetch == "function" ? a.authFetch.bind(a) : null;
10
10
  return t ? t(e, r) : window.fetch(e, r);
11
- } else return window.fetch(e, r);
11
+ }
12
+ return window.fetch(e, r);
12
13
  }, a = Symbol.for("solid-logic-singleton"), o = typeof window < "u" ? window : global;
13
14
  function s() {
14
15
  return o[a] ? e("SolidLogic: Using existing global singleton instance.") : (e("SolidLogic: Creating new global singleton instance."), o[a] = r({ fetch: i }, n), e("Unique quadstore initialized.")), o[a];
@@ -1 +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 { sessionExplicitlyInactive } from '../authSession/identityState'\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 // A session that explicitly reports itself inactive must not keep\n // identifying the last user: with a retained WebID, choosing the\n // authenticated fetch would send the previous identity's credentials.\n const sessionWebId = sessionExplicitlyInactive(sessionAny)\n ? undefined\n : (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":";;;;;AAMA,IAAM,IAAS,OAAO,GAAK,MAAgB;CACvC,IAAM,IAAY,KAAe,EAAY,eAAe,EAAY,eAAe,QACjF,IAAa;CAOnB,IAHqB,GAA0B,CAAU,MAElD,GAAY,MAAM,SAAS,GAAY,UAC1B,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"}
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 { sessionExplicitlyInactive } from '../authSession/identityState'\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 // A session that explicitly reports itself inactive must not keep\n // identifying the last user: with a retained WebID, choosing the\n // authenticated fetch would send the previous identity's credentials.\n const sessionWebId = sessionExplicitlyInactive(sessionAny)\n ? undefined\n : (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":";;;;;AAMA,IAAM,IAAS,OAAO,GAAK,MAAgB;CACvC,IAAM,IAAY,KAAe,EAAY,eAAe,EAAY,eAAe,QACjF,IAAa;CAOnB,IAHqB,GAA0B,CAAU,MAElD,GAAY,MAAM,SAAS,GAAY,UAC1B,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;CACI,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,2 @@
1
+ export declare function ownerOnlyContainerAclDocument(webId: string): string;
2
+ //# sourceMappingURL=profileAclDocuments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profileAclDocuments.d.ts","sourceRoot":"","sources":["../../src/profile/profileAclDocuments.ts"],"names":[],"mappings":"AAAA,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWnE"}
@@ -0,0 +1,2 @@
1
+ export declare function preferencesFileDocument(): string;
2
+ //# sourceMappingURL=profileDocuments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profileDocuments.d.ts","sourceRoot":"","sources":["../../src/profile/profileDocuments.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,IAAI,MAAM,CAShD"}
@@ -1 +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,EAAA,EAAA,IAAA,CAAW,EAAS,CAAQ,CAChC,CAEA,SAAS,EAAgB,EAAmB,CACxC,GAAI,GAAK,UAAU,SAAW,IAAK,MAAO,GAC1C,IAAM,EAAO,GAAG,GAAK,SAAW,GAAO,K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GAAG,IAAM,GAC1C,EAAwB,OAAO,EAAK,GAAG,CAE/C,CACJ,CAEA,eAAe,EAAa,EAAqC,CAC7D,GAAI,CAAC,EACD,MAAU,MAAM,6BAA6B,EAEjD,GAAI,CACA,MAAM,EAAM,QAAQ,KAAK,EAAK,IAAI,CAAC,CACvC,OAAS,EAAK,CACV,MAAU,MAAM,kCAAkC,EAAK,IAAI,GAAK,CACpE,CACA,OAAO,EAAK,IAAI,CACpB,CAEA,eAAe,GAA6B,CACxC,IAAM,EAAK,EAAM,YAAY,EAC7B,GAAI,IAAO,KACP,MAAU,MAAM,wCAAwC,EAG5D,OADA,MAAM,EAAM,QAAQ,KAAK,EAAG,IAAI,CAAC,EAC1B,CACX,CAEA,SAAS,EAAW,EAA4B,CAC5C,IAAM,EAAU,EAAY,CAAI,EAChC,GAAI,CAAC,EACD,MAAU,MAAM,0BAA0B,EAE9C,OAAO,CACX,CAEA,eAAe,EAAa,EAAqC,CAC7D,MAAM,EAAM,QAAQ,KAAK,CAAI,EAC7B,IAAM,EAAY,EAAM,IAAI,EAAM,EAAG,IAAI,OAAO,EAAG,IAAA,GAAW,EAAK,IAAI,CAAC,EACxE,GAAI,CAAC,EACD,MAAU,MAAM,4BAA4B,EAEhD,OAAO,CACX,CAEA,SAAS,EAAY,EAAe,CAChC,OAAO,EAAM,IAAI,EAAI,EAAG,MAAM,SAAS,EAAG,IAAA,GAAW,EAAG,IAAI,CAAC,CACjE,CAEA,MAAO,CACH,SACA,aACA,eACA,cACA,kBACA,cACA,yBACJ,CACJ"}
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,EAAO,EAAA,IAAA,CAAI,EAAS,CAAQ,CAChC,CAEA,SAAS,EAAgB,EAAmB,CACxC,GAAI,GAAK,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EACzC,GAAI,CACA,OAAO,MAAM,CACjB,QAAU,CACF,EAAwB,IAAI,EAAK,GAAG,IAAM,GAC1C,EAAwB,OAAO,EAAK,GAAG,CAE/C,CACJ,CAEA,eAAe,EAAa,EAAqC,CAC7D,GAAI,CAAC,EACD,MAAU,MAAM,6BAA6B,EAEjD,GAAI,CACA,MAAM,EAAM,QAAQ,KAAK,EAAK,IAAI,CAAC,CACvC,OAAS,EAAK,CACV,MAAU,MAAM,kCAAkC,EAAK,IAAI,GAAK,CACpE,CACA,OAAO,EAAK,IAAI,CACpB,CAEA,eAAe,GAA6B,CACxC,IAAM,EAAK,EAAM,YAAY,EAC7B,GAAI,IAAO,KACP,MAAU,MAAM,wCAAwC,EAG5D,OADA,MAAM,EAAM,QAAQ,KAAK,EAAG,IAAI,CAAC,EAC1B,CACX,CAEA,SAAS,EAAW,EAA4B,CAC5C,IAAM,EAAU,EAAY,CAAI,EAChC,GAAI,CAAC,EACD,MAAU,MAAM,0BAA0B,EAE9C,OAAO,CACX,CAEA,eAAe,EAAa,EAAqC,CAC7D,MAAM,EAAM,QAAQ,KAAK,CAAI,EAC7B,IAAM,EAAY,EAAM,IAAI,EAAM,EAAG,IAAI,OAAO,EAAG,IAAA,GAAW,EAAK,IAAI,CAAC,EACxE,GAAI,CAAC,EACD,MAAU,MAAM,4BAA4B,EAEhD,OAAO,CACX,CAEA,SAAS,EAAY,EAAe,CAChC,OAAO,EAAM,IAAI,EAAI,EAAG,MAAM,SAAS,EAAG,IAAA,GAAW,EAAG,IAAI,CAAC,CACjE,CAEA,MAAO,CACH,SACA,aACA,eACA,cACA,kBACA,cACA,yBACJ,CACJ"}
@@ -0,0 +1,3 @@
1
+ import { ProfileLogic } from '../types';
2
+ export declare function createProfileLogic(store: any, authn: any, utilityLogic: any): ProfileLogic;
3
+ //# sourceMappingURL=profileLogic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profileLogic.d.ts","sourceRoot":"","sources":["../../src/profile/profileLogic.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,wBAAgB,kBAAkB,CAAC,KAAK,KAAA,EAAE,KAAK,KAAA,EAAE,YAAY,KAAA,GAAG,YAAY,CA6U3E"}
@@ -122,7 +122,8 @@ function b(b, x, S) {
122
122
  try {
123
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
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;
125
+ let r = `User ${t} has no pointer in profile to preferences file.`;
126
+ throw e(r), n instanceof s || n instanceof u || n instanceof l || n instanceof a || n instanceof c || n instanceof o, n;
126
127
  }
127
128
  try {
128
129
  await b.fetcher.load(d);
@@ -1 +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"],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7D,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"}
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,CAA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EA,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,5 @@
1
+ export declare function assertSuccessfulHttpResponse(response: Response, method: string, options?: {
2
+ allowNotFound?: boolean;
3
+ }): void;
4
+ export declare function isMissingError(error: any): boolean;
5
+ //# sourceMappingURL=resourceHttp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceHttp.d.ts","sourceRoot":"","sources":["../../src/resource/resourceHttp.ts"],"names":[],"mappings":"AAQA,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAO,QASzH;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAIlD"}
@@ -1,2 +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;
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(e){let t=typeof e==`string`?e:e.value;try{let e=new URL(t);return e.hash===`#me`&&/\/profile\/card\.ttl$/.test(e.pathname)}catch{return!1}}function p(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=a.anyValue(i,e.ns.httph(`wac-allow`))||a.anyValue(i,e.ns.httph(`WAC-Allow`)),f=r.readWacAccessInfo(d);s||=f.canEdit,c||=f.isPublic;let p=a.anyValue(i,e.ns.httph(`etag`))||void 0;l===void 0&&(l=p),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 m(e){let t=await a.fetcher.webOperation(`HEAD`,e.uri);return n.assertSuccessfulHttpResponse(t,`HEAD`),p(e,t)}async function h(t){let n=a.any(t,e.ns.ldp(`contains`))||t.dir();if(!n||n.termType!==`NamedNode`)return!1;try{return(await m(n)).access.canEdit}catch{return!1}}async function g(e){return h(e)}async function _(e){return m(e)}async function v(e){let t;try{t=await m(e)}catch{t={contentType:void 0,access:{canEdit:!1,isPublic:!1},aclUri:void 0,eTag:void 0,modified:void 0}}let n=await g(e),r={canEdit:t.access?.canEdit??!1,isPublic:t.access?.isPublic??!1,canDelete:n};return{...t,access:r}}async function y(e,t){if(t)try{await c.deleteTypeIndexRegistrationForResource(e,t)}catch{}}async function b(t,r={}){let o=t.dir();if(u(t)){let e=await s.getContainerMembers(t);await Promise.all(e.map(e=>b((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 y(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 x(e,t){await b(e,{deleteTypeIndexes:!0,user:t})}return{recursiveDelete:b,deleteResourceAndTypeIndexIfExists:x,fetchMetadata:_,fetchMetadataWithDelete:v,createContainer:l,isContainer:u,getContainerMemberCount:d,isWebId:f}}exports.createResourceLogic=a;
2
2
  //# sourceMappingURL=resourceLogic.cjs.js.map