solid-logic 1.3.13-0e650512 → 1.3.13-ef4be651

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 (120) hide show
  1. package/.github/workflows/ci.yml +18 -19
  2. package/jest.config.js +1 -4
  3. package/jest.setup.ts +2 -0
  4. package/lib/authn/NoAuthnLogic.d.ts +9 -0
  5. package/lib/authn/NoAuthnLogic.d.ts.map +1 -0
  6. package/lib/authn/NoAuthnLogic.js +17 -0
  7. package/lib/authn/NoAuthnLogic.js.map +1 -0
  8. package/lib/authn/SolidAuthnLogic.d.ts +6 -26
  9. package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
  10. package/lib/authn/SolidAuthnLogic.js +5 -161
  11. package/lib/authn/SolidAuthnLogic.js.map +1 -1
  12. package/lib/authn/index.d.ts +5 -0
  13. package/lib/authn/index.d.ts.map +1 -0
  14. package/lib/{types.js → authn/index.js} +1 -1
  15. package/lib/authn/index.js.map +1 -0
  16. package/lib/chat/ChatLogic.d.ts +2 -2
  17. package/lib/chat/ChatLogic.d.ts.map +1 -1
  18. package/lib/chat/ChatLogic.js +1 -1
  19. package/lib/chat/ChatLogic.js.map +1 -1
  20. package/lib/chat/integration.test.d.ts +2 -0
  21. package/lib/chat/integration.test.d.ts.map +1 -0
  22. package/lib/chat/integration.test.js +318 -0
  23. package/lib/chat/integration.test.js.map +1 -0
  24. package/lib/{util/debug.d.ts → debug.d.ts} +0 -0
  25. package/lib/debug.d.ts.map +1 -0
  26. package/lib/{util/debug.js → debug.js} +0 -0
  27. package/lib/debug.js.map +1 -0
  28. package/lib/inbox/InboxLogic.d.ts +2 -2
  29. package/lib/inbox/InboxLogic.d.ts.map +1 -1
  30. package/lib/inbox/InboxLogic.js.map +1 -1
  31. package/lib/inbox/unit.test.d.ts +2 -0
  32. package/lib/inbox/unit.test.d.ts.map +1 -0
  33. package/lib/inbox/unit.test.js +264 -0
  34. package/lib/inbox/unit.test.js.map +1 -0
  35. package/lib/index.d.ts +67 -9
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +384 -31
  38. package/lib/index.js.map +1 -1
  39. package/lib/profile/ProfileLogic.d.ts +3 -2
  40. package/lib/profile/ProfileLogic.d.ts.map +1 -1
  41. package/lib/profile/ProfileLogic.js.map +1 -1
  42. package/lib/{util/uri.d.ts → uri.d.ts} +0 -0
  43. package/lib/uri.d.ts.map +1 -0
  44. package/lib/{util/uri.js → uri.js} +0 -0
  45. package/lib/uri.js.map +1 -0
  46. package/lib/util/UtilityLogic.d.ts +2 -2
  47. package/lib/util/UtilityLogic.d.ts.map +1 -1
  48. package/lib/util/UtilityLogic.js.map +1 -1
  49. package/lib/util/unit.test.d.ts +2 -0
  50. package/lib/util/unit.test.d.ts.map +1 -0
  51. package/lib/util/unit.test.js +200 -0
  52. package/lib/util/unit.test.js.map +1 -0
  53. package/package.json +1 -3
  54. package/src/authn/NoAuthnLogic.ts +16 -0
  55. package/src/authn/SolidAuthnLogic.ts +10 -112
  56. package/src/authn/index.ts +5 -0
  57. package/src/chat/ChatLogic.ts +3 -3
  58. package/{test/chatLogic.test.ts → src/chat/integration.test.ts} +5 -4
  59. package/src/{util/debug.ts → debug.ts} +0 -0
  60. package/src/inbox/InboxLogic.ts +14 -2
  61. package/{test/inboxLogic.test.ts → src/inbox/unit.test.ts} +6 -5
  62. package/src/index.ts +308 -18
  63. package/src/profile/ProfileLogic.ts +3 -2
  64. package/src/{util/uri.ts → uri.ts} +0 -0
  65. package/src/util/UtilityLogic.ts +14 -2
  66. package/{test/utilityLogic.test.ts → src/util/unit.test.ts} +4 -3
  67. package/lib/acl/aclLogic.d.ts +0 -32
  68. package/lib/acl/aclLogic.d.ts.map +0 -1
  69. package/lib/acl/aclLogic.js +0 -132
  70. package/lib/acl/aclLogic.js.map +0 -1
  71. package/lib/authSession/authSession.d.ts +0 -4
  72. package/lib/authSession/authSession.d.ts.map +0 -1
  73. package/lib/authSession/authSession.js +0 -18
  74. package/lib/authSession/authSession.js.map +0 -1
  75. package/lib/authn/authUtil.d.ts +0 -17
  76. package/lib/authn/authUtil.d.ts.map +0 -1
  77. package/lib/authn/authUtil.js +0 -88
  78. package/lib/authn/authUtil.js.map +0 -1
  79. package/lib/issuer/issuerLogic.d.ts +0 -8
  80. package/lib/issuer/issuerLogic.d.ts.map +0 -1
  81. package/lib/issuer/issuerLogic.js +0 -53
  82. package/lib/issuer/issuerLogic.js.map +0 -1
  83. package/lib/logic/CustomError.d.ts +0 -17
  84. package/lib/logic/CustomError.d.ts.map +0 -1
  85. package/lib/logic/CustomError.js +0 -73
  86. package/lib/logic/CustomError.js.map +0 -1
  87. package/lib/logic/SolidLogic.d.ts +0 -49
  88. package/lib/logic/SolidLogic.d.ts.map +0 -1
  89. package/lib/logic/SolidLogic.js +0 -316
  90. package/lib/logic/SolidLogic.js.map +0 -1
  91. package/lib/logic/solidLogicSingleton.d.ts +0 -8
  92. package/lib/logic/solidLogicSingleton.d.ts.map +0 -1
  93. package/lib/logic/solidLogicSingleton.js +0 -88
  94. package/lib/logic/solidLogicSingleton.js.map +0 -1
  95. package/lib/typeIndex/typeIndexLogic.d.ts +0 -22
  96. package/lib/typeIndex/typeIndexLogic.d.ts.map +0 -1
  97. package/lib/typeIndex/typeIndexLogic.js +0 -302
  98. package/lib/typeIndex/typeIndexLogic.js.map +0 -1
  99. package/lib/types.d.ts +0 -29
  100. package/lib/types.d.ts.map +0 -1
  101. package/lib/types.js.map +0 -1
  102. package/lib/util/debug.d.ts.map +0 -1
  103. package/lib/util/debug.js.map +0 -1
  104. package/lib/util/uri.d.ts.map +0 -1
  105. package/lib/util/uri.js.map +0 -1
  106. package/src/acl/aclLogic.ts +0 -137
  107. package/src/authSession/authSession.ts +0 -22
  108. package/src/authn/authUtil.ts +0 -67
  109. package/src/issuer/issuerLogic.ts +0 -40
  110. package/src/logic/CustomError.ts +0 -25
  111. package/src/logic/SolidLogic.ts +0 -264
  112. package/src/logic/solidLogicSingleton.ts +0 -24
  113. package/src/typeIndex/typeIndexLogic.ts +0 -170
  114. package/src/types.ts +0 -41
  115. package/test/aclLogic.test.ts +0 -15
  116. package/test/authUtil.test.ts +0 -19
  117. package/test/helpers/setup.ts +0 -13
  118. package/test/logic.test.ts +0 -28
  119. package/test/solidAuthLogic.test.ts +0 -45
  120. package/test/typeIndexLogic.test.ts +0 -26
package/src/index.ts CHANGED
@@ -1,18 +1,308 @@
1
- export {
2
- setACLUserPublic,
3
- genACLText
4
- } from './acl/aclLogic'
5
- export {
6
- ensureTypeIndexes,
7
- loadTypeIndexes,
8
- registerInTypeIndex,
9
- loadIndex
10
- } from './typeIndex/typeIndexLogic'
11
- export { default as authSession } from './authSession/authSession'
12
- export { SolidLogic } from "./logic/SolidLogic"
13
- export { offlineTestID, appContext } from './authn/authUtil'
14
- export { ACL_LINK } from './util/UtilityLogic'
15
- export { getSuggestedIssuers } from './issuer/issuerLogic'
16
- export { AppDetails, SolidNamespace, AuthenticationContext } from './types'
17
- export { solidLogicSingleton, authn, store, chat, profile } from './logic/solidLogicSingleton'
18
- export { UnauthorizedError, CrossOriginForbiddenError, SameOriginForbiddenError, NotFoundError, FetchError } from './logic/CustomError'
1
+ import { Session } from "@inrupt/solid-client-authn-browser";
2
+ import * as rdf from "rdflib";
3
+ import { Fetcher, NamedNode, Statement, Store, UpdateManager } from "rdflib";
4
+ import solidNamespace from "solid-namespace";
5
+ import { AuthnLogic } from "./authn";
6
+ import { NoAuthnLogic } from "./authn/NoAuthnLogic";
7
+ import { SolidAuthnLogic } from "./authn/SolidAuthnLogic";
8
+
9
+ import { ChatLogic } from "./chat/ChatLogic";
10
+ import * as debug from "./debug";
11
+ import { ProfileLogic } from "./profile/ProfileLogic";
12
+ import { UtilityLogic } from "./util/UtilityLogic";
13
+ import { ConnectedStore, LiveStore } from 'rdflib'
14
+
15
+ export { ACL_LINK } from './util/UtilityLogic';
16
+
17
+ const ns: SolidNamespace = solidNamespace(rdf);
18
+
19
+ /* interface ConnectedStore extends Store {
20
+ fetcher: Fetcher;
21
+ }
22
+
23
+ export interface LiveStore extends ConnectedStore {
24
+ updater: UpdateManager;
25
+ } */
26
+
27
+ export interface SolidNamespace {
28
+ [key: string]: (term: string) => NamedNode;
29
+ }
30
+
31
+ export class SolidLogic {
32
+ cache: {
33
+ profileDocument: {
34
+ [WebID: string]: NamedNode;
35
+ };
36
+ preferencesFile: {
37
+ [WebID: string]: NamedNode;
38
+ };
39
+ };
40
+
41
+ store: LiveStore;
42
+ me: string | undefined;
43
+ fetcher: { fetch: (url: string, options?: any) => any };
44
+
45
+ chat: ChatLogic;
46
+ profile: ProfileLogic;
47
+ authn: AuthnLogic;
48
+ util: UtilityLogic;
49
+
50
+ constructor(fetcher: { fetch: (url: any, requestInit: any) => any }, solidAuthSession: Session) {
51
+ this.store = rdf.graph() as LiveStore; // Make a Quad store
52
+ rdf.fetcher(this.store, fetcher); // Attach a web I/O module, store.fetcher
53
+ this.store.updater = new rdf.UpdateManager(this.store); // Add real-time live updates store.updater
54
+ this.cache = {
55
+ profileDocument: {},
56
+ preferencesFile: {},
57
+ };
58
+ this.fetcher = fetcher;
59
+ if (solidAuthSession) {
60
+ this.authn = new SolidAuthnLogic(solidAuthSession);
61
+ } else {
62
+ this.authn = new NoAuthnLogic();
63
+ }
64
+ this.profile = new ProfileLogic(this.store, ns, this.authn);
65
+ this.chat = new ChatLogic(this.store, ns, this.profile);
66
+ this.util = new UtilityLogic(this.store, ns, this.fetcher);
67
+ }
68
+
69
+ findAclDocUrl(url: string) {
70
+ return this.util.findAclDocUrl(url);
71
+ }
72
+
73
+ loadDoc(doc: NamedNode): Promise<void> {
74
+ return this.util.loadDoc(doc);
75
+ }
76
+
77
+ async loadProfile(me: NamedNode): Promise<NamedNode> {
78
+ // console.log('loadProfile', me)
79
+ if (this.cache.profileDocument[me.value]) {
80
+ return this.cache.profileDocument[me.value];
81
+ }
82
+ let profileDocument;
83
+ try {
84
+ profileDocument = me.doc();
85
+ await this.loadDoc(profileDocument);
86
+ return profileDocument;
87
+ } catch (err) {
88
+ const message = `Logged in but cannot load profile ${profileDocument} : ${err}`;
89
+ throw new Error(message);
90
+ }
91
+ }
92
+
93
+ async loadPreferences(me: NamedNode): Promise<NamedNode> {
94
+ // console.log('loadPreferences', me)
95
+ if (this.cache.preferencesFile[me.value]) {
96
+ return this.cache.preferencesFile[me.value];
97
+ }
98
+ const preferencesFile = this.store.any(me, ns.space("preferencesFile"));
99
+
100
+ // console.log('this.store.any()', this.store.any())
101
+ /**
102
+ * Are we working cross-origin?
103
+ * Returns True if we are in a webapp at an origin, and the file origin is different
104
+ */
105
+ function differentOrigin(): boolean {
106
+ if (!preferencesFile) {
107
+ return true;
108
+ }
109
+ return (
110
+ `${window.location.origin}/` !== new URL(preferencesFile.value).origin
111
+ );
112
+ }
113
+
114
+ if (!preferencesFile) {
115
+ throw new Error(
116
+ `Can't find a preference file pointer in profile ${me.doc()}`
117
+ );
118
+ }
119
+
120
+ if (!this.store.fetcher) {
121
+ throw new Error("Cannot load doc, have no fetcher");
122
+ }
123
+ // //// Load preference file
124
+ try {
125
+ await this.store.fetcher.load(preferencesFile as NamedNode, {
126
+ withCredentials: true,
127
+ });
128
+ } catch (err) {
129
+ // Really important to look at why
130
+ const status = err.status;
131
+ debug.log(`HTTP status ${status} for preference file ${preferencesFile}`);
132
+ if (status === 401) {
133
+ throw new UnauthorizedError();
134
+ }
135
+ if (status === 403) {
136
+ if (differentOrigin()) {
137
+ throw new CrossOriginForbiddenError();
138
+ }
139
+ throw new SameOriginForbiddenError();
140
+ }
141
+ if (status === 404) {
142
+ throw new NotFoundError(preferencesFile.value);
143
+ }
144
+ throw new FetchError(err.status, err.message);
145
+ }
146
+ return preferencesFile as NamedNode;
147
+ }
148
+
149
+ getTypeIndex(
150
+ me: NamedNode | string,
151
+ preferencesFile: NamedNode | string,
152
+ isPublic: boolean
153
+ ): NamedNode[] {
154
+ // console.log('getTypeIndex', this.store.each(me, undefined, undefined, preferencesFile), isPublic, preferencesFile)
155
+ return this.store.each(
156
+ me as NamedNode,
157
+ isPublic ? ns.solid("publicTypeIndex") : ns.solid("privateTypeIndex"),
158
+ undefined,
159
+ preferencesFile as NamedNode
160
+ ) as NamedNode[];
161
+ }
162
+
163
+ getRegistrations(instance, theClass) {
164
+ return this.store
165
+ .each(undefined, ns.solid("instance"), instance)
166
+ .filter((r) => {
167
+ return this.store.holds(r, ns.solid("forClass"), theClass);
168
+ });
169
+ }
170
+
171
+ load(doc: NamedNode | NamedNode[] | string) {
172
+ if (!this.store.fetcher) {
173
+ throw new Error("Cannot load doc(s), have no fetcher");
174
+ }
175
+ return this.store.fetcher.load(doc);
176
+ }
177
+
178
+ async loadIndexes(
179
+ me: NamedNode | string,
180
+ publicProfile: NamedNode | string | null,
181
+ preferencesFile: NamedNode | string | null,
182
+ onWarning = async (_err: Error) => {
183
+ return undefined;
184
+ }
185
+ ): Promise<{
186
+ private: any;
187
+ public: any;
188
+ }> {
189
+ let privateIndexes: any[] = [];
190
+ let publicIndexes: any[] = [];
191
+ if (publicProfile) {
192
+ publicIndexes = this.getTypeIndex(me, publicProfile, true);
193
+ try {
194
+ await this.load(publicIndexes as NamedNode[]);
195
+ } catch (err) {
196
+ onWarning(new Error(`loadIndex: loading public type index(es) ${err}`));
197
+ }
198
+ }
199
+ if (preferencesFile) {
200
+ privateIndexes = this.getTypeIndex(me, preferencesFile, false);
201
+ // console.log({ privateIndexes })
202
+ if (privateIndexes.length === 0) {
203
+ await onWarning(
204
+ new Error(
205
+ `Your preference file ${preferencesFile} does not point to a private type index.`
206
+ )
207
+ );
208
+ } else {
209
+ try {
210
+ await this.load(privateIndexes);
211
+ } catch (err) {
212
+ onWarning(
213
+ new Error(`loadIndex: loading private type index(es) ${err}`)
214
+ );
215
+ }
216
+ }
217
+ // } else {
218
+ // debug.log(
219
+ // 'We know your preference file is not available, so we are not bothering with private type indexes.'
220
+ // )
221
+ }
222
+
223
+ return {
224
+ private: privateIndexes,
225
+ public: publicIndexes,
226
+ };
227
+ }
228
+
229
+ async createEmptyRdfDoc(doc: NamedNode, comment: string) {
230
+ if (!this.store.fetcher) {
231
+ throw new Error("Cannot create empty rdf doc, have no fetcher");
232
+ }
233
+ await this.store.fetcher.webOperation("PUT", doc.uri, {
234
+ data: `# ${new Date()} ${comment}
235
+ `,
236
+ contentType: "text/turtle",
237
+ });
238
+ }
239
+
240
+ // @@@@ use the one in rdflib.js when it is available and delete this
241
+ updatePromise(
242
+ del: Array<Statement>,
243
+ ins: Array<Statement> = []
244
+ ): Promise<void> {
245
+ return new Promise((resolve, reject) => {
246
+ if (!this.store.updater) {
247
+ throw new Error("Cannot updatePromise, have no updater");
248
+ }
249
+ this.store.updater.update(del, ins, function (_uri, ok, errorBody) {
250
+ if (!ok) {
251
+ reject(new Error(errorBody));
252
+ } else {
253
+ resolve();
254
+ }
255
+ }); // callback
256
+ }); // promise
257
+ }
258
+
259
+ isContainer(url: string) {
260
+ return this.util.isContainer(url);
261
+ }
262
+
263
+ getContainerElements(containerNode: NamedNode): NamedNode[] {
264
+ return this.util.getContainerElements(containerNode);
265
+ }
266
+
267
+ getContainerMembers(containerUrl: string): Promise<string[]> {
268
+ return this.util.getContainerMembers(containerUrl);
269
+ }
270
+
271
+ async recursiveDelete(url: string) {
272
+ return this.util.recursiveDelete(url);
273
+ }
274
+
275
+ clearStore() {
276
+ return this.util.clearStore();
277
+ }
278
+
279
+ async fetch(url: string, options?: any) {
280
+ return this.fetcher.fetch(url, options);
281
+ }
282
+ }
283
+
284
+ class CustomError extends Error {
285
+ constructor(message?: string) {
286
+ super(message);
287
+ // see: typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html
288
+ Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
289
+ this.name = new.target.name; // stack traces display correctly now
290
+ }
291
+ }
292
+
293
+ export class UnauthorizedError extends CustomError {}
294
+
295
+ export class CrossOriginForbiddenError extends CustomError {}
296
+
297
+ export class SameOriginForbiddenError extends CustomError {}
298
+
299
+ export class NotFoundError extends CustomError {}
300
+
301
+ export class FetchError extends CustomError {
302
+ status: number;
303
+
304
+ constructor(status: number, message?: string) {
305
+ super(message);
306
+ this.status = status;
307
+ }
308
+ }
@@ -1,5 +1,6 @@
1
- import { NamedNode, LiveStore } from "rdflib";
2
- import { AuthnLogic, SolidNamespace } from "../types";
1
+ import { LiveStore, NamedNode } from "rdflib";
2
+ import { AuthnLogic } from "../authn";
3
+ import { SolidNamespace } from "../index";
3
4
 
4
5
  export class ProfileLogic {
5
6
  store: LiveStore;
File without changes
@@ -1,10 +1,22 @@
1
- import { NamedNode, Statement, sym, LiveStore } from "rdflib";
2
- import { SolidNamespace } from "../types";
1
+ import { LiveStore, NamedNode, Node, st, term, sym, Statement } from "rdflib";
2
+ import { SolidNamespace } from "../index";
3
+ import { ProfileLogic } from "../profile/ProfileLogic";
4
+ import { newThing } from "../uri";
3
5
 
4
6
  export const ACL_LINK = sym(
5
7
  "http://www.iana.org/assignments/link-relations/acl"
6
8
  );
7
9
 
10
+ interface NewPaneOptions {
11
+ me?: NamedNode;
12
+ newInstance?: NamedNode;
13
+ newBase: string;
14
+ }
15
+
16
+ interface CreatedPaneOptions {
17
+ newInstance: NamedNode;
18
+ }
19
+
8
20
  /**
9
21
  * Utility-related logic
10
22
  */
@@ -1,12 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { UtilityLogic } from "../src/util/UtilityLogic";
2
+ import { UtilityLogic } from "./UtilityLogic";
3
3
  import solidNamespace from "solid-namespace";
4
+
4
5
  import * as rdf from "rdflib";
6
+ import { ProfileLogic } from "../profile/ProfileLogic";
5
7
  import fetchMock from "jest-fetch-mock";
6
8
  import { UpdateManager } from "rdflib";
7
- import { SolidNamespace } from "../src/types";
8
9
 
9
- const ns: SolidNamespace = solidNamespace(rdf);
10
+ const ns = solidNamespace(rdf);
10
11
 
11
12
  const alice = rdf.sym("https://alice.example/profile/card#me");
12
13
  const bob = rdf.sym("https://bob.example/profile/card#me");
@@ -1,32 +0,0 @@
1
- /**
2
- * Simple Access Control
3
- *
4
- * This function sets up a simple default ACL for a resource, with
5
- * RWC for the owner, and a specified access (default none) for the public.
6
- * In all cases owner has read write control.
7
- * Parameter lists modes allowed to public
8
- *
9
- * @param options
10
- * @param options.public eg ['Read', 'Write']
11
- *
12
- * @returns Resolves with aclDoc uri on successful write
13
- */
14
- import { NamedNode } from "rdflib";
15
- export declare const ns: any;
16
- export declare function setACLUserPublic(docURI: string, me: NamedNode, options: {
17
- defaultForNew?: boolean;
18
- public?: [];
19
- }): Promise<NamedNode>;
20
- /**
21
- * @param docURI
22
- * @param me
23
- * @param aclURI
24
- * @param options
25
- *
26
- * @returns Serialized ACL
27
- */
28
- export declare function genACLText(docURI: string, me: NamedNode, aclURI: string, options?: {
29
- defaultForNew?: boolean;
30
- public?: [];
31
- }): string | undefined;
32
- //# sourceMappingURL=aclLogic.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aclLogic.d.ts","sourceRoot":"","sources":["../../src/acl/aclLogic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAS,SAAS,EAAwB,MAAM,QAAQ,CAAA;AAM/D,eAAO,MAAM,EAAE,KAAuB,CAAA;AAEtC,wBAAgB,gBAAgB,CAChC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,SAAS,EACb,OAAO,EAAE;IACL,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,EAAE,CAAA;CACd,GACE,OAAO,CAAC,SAAS,CAAC,CAkCpB;AA8BD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAC1B,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IACL,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,EAAE,CAAA;CACT,GACH,MAAM,GAAG,SAAS,CA2BpB"}
@@ -1,132 +0,0 @@
1
- "use strict";
2
- /**
3
- * Simple Access Control
4
- *
5
- * This function sets up a simple default ACL for a resource, with
6
- * RWC for the owner, and a specified access (default none) for the public.
7
- * In all cases owner has read write control.
8
- * Parameter lists modes allowed to public
9
- *
10
- * @param options
11
- * @param options.public eg ['Read', 'Write']
12
- *
13
- * @returns Resolves with aclDoc uri on successful write
14
- */
15
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
18
- }) : (function(o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- }));
22
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
- Object.defineProperty(o, "default", { enumerable: true, value: v });
24
- }) : function(o, v) {
25
- o["default"] = v;
26
- });
27
- var __importStar = (this && this.__importStar) || function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.genACLText = exports.setACLUserPublic = exports.ns = void 0;
39
- var rdflib_1 = require("rdflib");
40
- var solid_namespace_1 = __importDefault(require("solid-namespace"));
41
- var $rdf = __importStar(require("rdflib"));
42
- var solidLogicSingleton_1 = require("../logic/solidLogicSingleton");
43
- var UtilityLogic_1 = require("../util/UtilityLogic");
44
- exports.ns = (0, solid_namespace_1.default)($rdf);
45
- function setACLUserPublic(docURI, me, options) {
46
- var aclDoc = solidLogicSingleton_1.solidLogicSingleton.store.any(solidLogicSingleton_1.solidLogicSingleton.store.sym(docURI), UtilityLogic_1.ACL_LINK);
47
- return Promise.resolve()
48
- .then(function () {
49
- if (aclDoc) {
50
- return aclDoc;
51
- }
52
- return fetchACLRel(docURI).catch(function (err) {
53
- throw new Error("Error fetching rel=ACL header for ".concat(docURI, ": ").concat(err));
54
- });
55
- })
56
- .then(function (aclDoc) {
57
- var aclText = genACLText(docURI, me, aclDoc.uri, options);
58
- if (!solidLogicSingleton_1.solidLogicSingleton.store.fetcher) {
59
- throw new Error('Cannot PUT this, store has no fetcher');
60
- }
61
- return solidLogicSingleton_1.solidLogicSingleton.store.fetcher
62
- .webOperation('PUT', aclDoc.uri, {
63
- data: aclText,
64
- contentType: 'text/turtle'
65
- })
66
- .then(function (result) {
67
- if (!result.ok) {
68
- throw new Error('Error writing ACL text: ' + result.error);
69
- }
70
- return aclDoc;
71
- });
72
- });
73
- }
74
- exports.setACLUserPublic = setACLUserPublic;
75
- /**
76
- * @param docURI
77
- * @returns
78
- */
79
- function fetchACLRel(docURI) {
80
- var fetcher = solidLogicSingleton_1.solidLogicSingleton.store.fetcher;
81
- if (!fetcher) {
82
- throw new Error('Cannot fetch ACL rel, store has no fetcher');
83
- }
84
- return fetcher.load(docURI).then(function (result) {
85
- if (!result.ok) {
86
- throw new Error('fetchACLRel: While loading:' + result.error);
87
- }
88
- var aclDoc = solidLogicSingleton_1.solidLogicSingleton.store.any(solidLogicSingleton_1.solidLogicSingleton.store.sym(docURI), UtilityLogic_1.ACL_LINK);
89
- if (!aclDoc) {
90
- throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI);
91
- }
92
- return aclDoc;
93
- });
94
- }
95
- /**
96
- * @param docURI
97
- * @param me
98
- * @param aclURI
99
- * @param options
100
- *
101
- * @returns Serialized ACL
102
- */
103
- function genACLText(docURI, me, aclURI, options) {
104
- if (options === void 0) { options = {}; }
105
- var optPublic = options.public || [];
106
- var g = (0, rdflib_1.graph)();
107
- var auth = (0, rdflib_1.Namespace)('http://www.w3.org/ns/auth/acl#');
108
- var a = g.sym("".concat(aclURI, "#a1"));
109
- var acl = g.sym(aclURI);
110
- var doc = g.sym(docURI);
111
- g.add(a, exports.ns.rdf('type'), auth('Authorization'), acl);
112
- g.add(a, auth('accessTo'), doc, acl);
113
- if (options.defaultForNew) {
114
- g.add(a, auth('default'), doc, acl);
115
- }
116
- g.add(a, auth('agent'), me, acl);
117
- g.add(a, auth('mode'), auth('Read'), acl);
118
- g.add(a, auth('mode'), auth('Write'), acl);
119
- g.add(a, auth('mode'), auth('Control'), acl);
120
- if (optPublic.length) {
121
- a = g.sym("".concat(aclURI, "#a2"));
122
- g.add(a, exports.ns.rdf('type'), auth('Authorization'), acl);
123
- g.add(a, auth('accessTo'), doc, acl);
124
- g.add(a, auth('agentClass'), exports.ns.foaf('Agent'), acl);
125
- for (var p = 0; p < optPublic.length; p++) {
126
- g.add(a, auth('mode'), auth(optPublic[p]), acl); // Like 'Read' etc
127
- }
128
- }
129
- return (0, rdflib_1.serialize)(acl, g, aclURI);
130
- }
131
- exports.genACLText = genACLText;
132
- //# sourceMappingURL=aclLogic.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aclLogic.js","sourceRoot":"","sources":["../../src/acl/aclLogic.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iCAA+D;AAC/D,oEAA4C;AAC5C,2CAA8B;AAC9B,oEAAkE;AAClE,qDAA+C;AAElC,QAAA,EAAE,GAAG,IAAA,yBAAc,EAAC,IAAI,CAAC,CAAA;AAEtC,SAAgB,gBAAgB,CAChC,MAAc,EACd,EAAa,EACb,OAGC;IAED,IAAM,MAAM,GAAG,yCAAmB,CAAC,KAAK,CAAC,GAAG,CACxC,yCAAmB,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EACrC,uBAAQ,CACX,CAAA;IAED,OAAO,OAAO,CAAC,OAAO,EAAE;SACnB,IAAI,CAAC;QACN,IAAI,MAAM,EAAE;YACR,OAAO,MAAmB,CAAA;SAC7B;QAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC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- declare let authSession: Session;
3
- export default authSession;
4
- //# sourceMappingURL=authSession.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authSession.d.ts","sourceRoot":"","sources":["../../src/authSession/authSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAER,MAAM,oCAAoC,CAAA;AAE3C,QAAA,IAAI,WAAW,EAAE,OAAO,CAAA;AAgBxB,eAAe,WAAW,CAAA"}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var solid_client_authn_browser_1 = require("@inrupt/solid-client-authn-browser");
4
- var authSession;
5
- // @ts-ignore
6
- if (!window.authSession) {
7
- authSession = new solid_client_authn_browser_1.Session({
8
- clientAuthentication: (0, solid_client_authn_browser_1.getClientAuthenticationWithDependencies)({})
9
- }, 'mySession');
10
- // @ts-ignore
11
- window.authSession = authSession;
12
- }
13
- else {
14
- // @ts-ignore
15
- authSession = window.authSession;
16
- }
17
- exports.default = authSession;
18
- //# sourceMappingURL=authSession.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authSession.js","sourceRoot":"","sources":["../../src/authSession/authSession.ts"],"names":[],"mappings":";;AAAA,iFAG2C;AAE3C,IAAI,WAAoB,CAAA;AACxB,aAAa;AACb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;IACvB,WAAW,GAAG,IAAI,oCAAO,CACvB;QACE,oBAAoB,EAAE,IAAA,oEAAuC,EAAC,EAAE,CAAC;KAClE,EACD,WAAW,CACZ,CAAA;IACD,aAAa;IACb,MAAM,CAAC,WAAW,GAAG,WAAW,CAAA;CACjC;KAAM;IACL,aAAa;IACb,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;CACjC;AAED,kBAAe,WAAW,CAAA"}
@@ -1,17 +0,0 @@
1
- import { NamedNode } from "rdflib";
2
- /**
3
- * find a user or app's context as set in window.SolidAppContext
4
- * this is a const, not a function, because we have problems to jest mock it otherwise
5
- * see: https://github.com/facebook/jest/issues/936#issuecomment-545080082 for more
6
- * @return {any} - an appContext object
7
- */
8
- export declare const appContext: () => any;
9
- /**
10
- * Returns `sym($SolidTestEnvironment.username)` if
11
- * `$SolidTestEnvironment.username` is defined as a global
12
- * or
13
- * returns testID defined in the HTML page
14
- * @returns {NamedNode|null}
15
- */
16
- export declare function offlineTestID(): NamedNode | null;
17
- //# sourceMappingURL=authUtil.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authUtil.d.ts","sourceRoot":"","sources":["../../src/authn/authUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAO,MAAM,QAAQ,CAAA;AAGvC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAM,GAuB5B,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAK,SAAS,GAAG,IAAI,CAyBjD"}