solid-logic 3.1.1 → 4.0.0-3e8294e

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/README.md +129 -2
  2. package/dist/acl/aclLogic.d.ts +5 -0
  3. package/{lib → dist}/acl/aclLogic.d.ts.map +1 -1
  4. package/dist/acl/aclLogic.js +117 -0
  5. package/dist/acl/aclLogic.js.map +1 -0
  6. package/dist/authSession/authSession.js +3 -0
  7. package/dist/authSession/authSession.js.map +1 -0
  8. package/{lib → dist}/authn/SolidAuthnLogic.d.ts +3 -3
  9. package/{lib → dist}/authn/SolidAuthnLogic.d.ts.map +1 -1
  10. package/dist/authn/SolidAuthnLogic.js +109 -0
  11. package/dist/authn/SolidAuthnLogic.js.map +1 -0
  12. package/{lib → dist}/authn/authUtil.d.ts +1 -1
  13. package/dist/authn/authUtil.d.ts.map +1 -0
  14. package/dist/authn/authUtil.js +64 -0
  15. package/dist/authn/authUtil.js.map +1 -0
  16. package/{lib → dist}/chat/chatLogic.d.ts +1 -1
  17. package/{lib → dist}/chat/chatLogic.d.ts.map +1 -1
  18. package/dist/chat/chatLogic.js +157 -0
  19. package/dist/chat/chatLogic.js.map +1 -0
  20. package/{lib → dist}/inbox/inboxLogic.d.ts +1 -1
  21. package/{lib → dist}/inbox/inboxLogic.d.ts.map +1 -1
  22. package/dist/inbox/inboxLogic.js +51 -0
  23. package/dist/inbox/inboxLogic.js.map +1 -0
  24. package/{lib → dist}/index.d.ts +1 -1
  25. package/{lib → dist}/index.d.ts.map +1 -1
  26. package/dist/index.js +14 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/issuer/issuerLogic.js +37 -0
  29. package/dist/issuer/issuerLogic.js.map +1 -0
  30. package/{lib → dist}/logic/CustomError.d.ts.map +1 -1
  31. package/dist/logic/CustomError.js +27 -0
  32. package/dist/logic/CustomError.js.map +1 -0
  33. package/dist/logic/solidLogic.d.ts +6 -0
  34. package/{lib → dist}/logic/solidLogic.d.ts.map +1 -1
  35. package/dist/logic/solidLogic.js +64 -0
  36. package/dist/logic/solidLogic.js.map +1 -0
  37. package/dist/logic/solidLogicSingleton.d.ts +4 -0
  38. package/{lib → dist}/logic/solidLogicSingleton.d.ts.map +1 -1
  39. package/dist/logic/solidLogicSingleton.js +31 -0
  40. package/dist/logic/solidLogicSingleton.js.map +1 -0
  41. package/{lib → dist}/profile/profileLogic.d.ts +1 -1
  42. package/{lib → dist}/profile/profileLogic.d.ts.map +1 -1
  43. package/dist/profile/profileLogic.js +128 -0
  44. package/dist/profile/profileLogic.js.map +1 -0
  45. package/dist/solid-logic.esm.js +7356 -0
  46. package/dist/solid-logic.esm.js.map +1 -0
  47. package/dist/solid-logic.esm.min.js +32 -0
  48. package/dist/solid-logic.esm.min.js.map +1 -0
  49. package/dist/solid-logic.js +7415 -0
  50. package/dist/solid-logic.js.map +1 -0
  51. package/dist/solid-logic.min.js +32 -0
  52. package/dist/solid-logic.min.js.map +1 -0
  53. package/{lib → dist}/typeIndex/typeIndexLogic.d.ts.map +1 -1
  54. package/dist/typeIndex/typeIndexLogic.js +182 -0
  55. package/dist/typeIndex/typeIndexLogic.js.map +1 -0
  56. package/{lib → dist}/types.d.ts +2 -2
  57. package/{lib → dist}/types.d.ts.map +1 -1
  58. package/dist/types.js +2 -0
  59. package/{lib → dist}/util/containerLogic.d.ts +1 -1
  60. package/{lib → dist}/util/containerLogic.d.ts.map +1 -1
  61. package/{src/util/containerLogic.ts → dist/util/containerLogic.js} +15 -23
  62. package/dist/util/containerLogic.js.map +1 -0
  63. package/dist/util/debug.d.ts.map +1 -0
  64. package/dist/util/debug.js +13 -0
  65. package/dist/util/debug.js.map +1 -0
  66. package/dist/util/ns.js +5 -0
  67. package/dist/util/ns.js.map +1 -0
  68. package/{lib → dist}/util/utilityLogic.d.ts +1 -1
  69. package/{lib → dist}/util/utilityLogic.d.ts.map +1 -1
  70. package/dist/util/utilityLogic.js +144 -0
  71. package/dist/util/utilityLogic.js.map +1 -0
  72. package/{lib → dist}/util/utils.d.ts +1 -1
  73. package/{lib → dist}/util/utils.d.ts.map +1 -1
  74. package/dist/util/utils.js +39 -0
  75. package/dist/util/utils.js.map +1 -0
  76. package/dist/versionInfo.js +30 -0
  77. package/dist/versionInfo.js.map +1 -0
  78. package/package.json +51 -23
  79. package/eslint.config.js +0 -29
  80. package/jest.config.js +0 -10
  81. package/lib/acl/aclLogic.d.ts +0 -5
  82. package/lib/acl/aclLogic.js +0 -168
  83. package/lib/acl/aclLogic.js.map +0 -1
  84. package/lib/authSession/authSession.js +0 -6
  85. package/lib/authSession/authSession.js.map +0 -1
  86. package/lib/authn/SolidAuthnLogic.js +0 -193
  87. package/lib/authn/SolidAuthnLogic.js.map +0 -1
  88. package/lib/authn/authUtil.d.ts.map +0 -1
  89. package/lib/authn/authUtil.js +0 -105
  90. package/lib/authn/authUtil.js.map +0 -1
  91. package/lib/chat/chatLogic.js +0 -272
  92. package/lib/chat/chatLogic.js.map +0 -1
  93. package/lib/inbox/inboxLogic.js +0 -139
  94. package/lib/inbox/inboxLogic.js.map +0 -1
  95. package/lib/index.js +0 -31
  96. package/lib/index.js.map +0 -1
  97. package/lib/issuer/issuerLogic.js +0 -52
  98. package/lib/issuer/issuerLogic.js.map +0 -1
  99. package/lib/logic/CustomError.js +0 -89
  100. package/lib/logic/CustomError.js.map +0 -1
  101. package/lib/logic/solidLogic.d.ts +0 -6
  102. package/lib/logic/solidLogic.js +0 -102
  103. package/lib/logic/solidLogic.js.map +0 -1
  104. package/lib/logic/solidLogicSingleton.d.ts +0 -3
  105. package/lib/logic/solidLogicSingleton.js +0 -94
  106. package/lib/logic/solidLogicSingleton.js.map +0 -1
  107. package/lib/profile/profileLogic.js +0 -259
  108. package/lib/profile/profileLogic.js.map +0 -1
  109. package/lib/typeIndex/typeIndexLogic.js +0 -399
  110. package/lib/typeIndex/typeIndexLogic.js.map +0 -1
  111. package/lib/types.js +0 -3
  112. package/lib/util/containerLogic.js +0 -102
  113. package/lib/util/containerLogic.js.map +0 -1
  114. package/lib/util/debug.d.ts.map +0 -1
  115. package/lib/util/debug.js +0 -40
  116. package/lib/util/debug.js.map +0 -1
  117. package/lib/util/ns.js +0 -44
  118. package/lib/util/ns.js.map +0 -1
  119. package/lib/util/utilityLogic.js +0 -284
  120. package/lib/util/utilityLogic.js.map +0 -1
  121. package/lib/util/utils.js +0 -47
  122. package/lib/util/utils.js.map +0 -1
  123. package/src/acl/aclLogic.ts +0 -156
  124. package/src/authSession/authSession.ts +0 -7
  125. package/src/authn/SolidAuthnLogic.ts +0 -127
  126. package/src/authn/authUtil.ts +0 -70
  127. package/src/chat/chatLogic.ts +0 -226
  128. package/src/inbox/inboxLogic.ts +0 -59
  129. package/src/index.ts +0 -22
  130. package/src/issuer/issuerLogic.ts +0 -40
  131. package/src/logic/CustomError.ts +0 -29
  132. package/src/logic/solidLogic.ts +0 -76
  133. package/src/logic/solidLogicSingleton.ts +0 -20
  134. package/src/profile/profileLogic.ts +0 -125
  135. package/src/typeIndex/typeIndexLogic.ts +0 -198
  136. package/src/types.ts +0 -122
  137. package/src/util/debug.ts +0 -20
  138. package/src/util/ns.ts +0 -5
  139. package/src/util/utilityLogic.ts +0 -156
  140. package/src/util/utils.ts +0 -52
  141. package/test/aclLogic.test.ts +0 -24
  142. package/test/authUtil.test.ts +0 -23
  143. package/test/chatLogic.test.ts +0 -316
  144. package/test/container.test.ts +0 -58
  145. package/test/helpers/dataSetup.ts +0 -134
  146. package/test/helpers/setup.ts +0 -17
  147. package/test/inboxLogic.test.ts +0 -218
  148. package/test/logic.test.ts +0 -29
  149. package/test/profileLogic.test.ts +0 -246
  150. package/test/solidAuthLogic.test.ts +0 -49
  151. package/test/typeIndexLogic.test.ts +0 -255
  152. package/test/utilityLogic.test.ts +0 -179
  153. package/test/utils.test.ts +0 -32
  154. package/tsconfig.json +0 -75
  155. /package/{lib → dist}/authSession/authSession.d.ts +0 -0
  156. /package/{lib → dist}/authSession/authSession.d.ts.map +0 -0
  157. /package/{lib → dist}/issuer/issuerLogic.d.ts +0 -0
  158. /package/{lib → dist}/issuer/issuerLogic.d.ts.map +0 -0
  159. /package/{lib → dist}/logic/CustomError.d.ts +0 -0
  160. /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts +0 -0
  161. /package/{lib → dist}/types.js.map +0 -0
  162. /package/{lib → dist}/util/debug.d.ts +0 -0
  163. /package/{lib → dist}/util/ns.d.ts +0 -0
  164. /package/{lib → dist}/util/ns.d.ts.map +0 -0
@@ -1,284 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
- Object.defineProperty(exports, "__esModule", { value: true });
72
- exports.createUtilityLogic = createUtilityLogic;
73
- var rdflib_1 = require("rdflib");
74
- var CustomError_1 = require("../logic/CustomError");
75
- var debug = __importStar(require("../util/debug"));
76
- var utils_1 = require("./utils");
77
- function createUtilityLogic(store, aclLogic, containerLogic) {
78
- function recursiveDelete(containerNode) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var aclDocUrl, containerMembers, nodeToStringHere, e_1;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0:
84
- _a.trys.push([0, 6, , 7]);
85
- if (!containerLogic.isContainer(containerNode)) return [3 /*break*/, 5];
86
- return [4 /*yield*/, aclLogic.findAclDocUrl(containerNode)];
87
- case 1:
88
- aclDocUrl = _a.sent();
89
- return [4 /*yield*/, store.fetcher._fetch(aclDocUrl, { method: "DELETE" })];
90
- case 2:
91
- _a.sent();
92
- return [4 /*yield*/, containerLogic.getContainerMembers(containerNode)];
93
- case 3:
94
- containerMembers = _a.sent();
95
- return [4 /*yield*/, Promise.all(containerMembers.map(function (url) { return recursiveDelete(url); }))];
96
- case 4:
97
- _a.sent();
98
- _a.label = 5;
99
- case 5:
100
- nodeToStringHere = containerNode.value;
101
- return [2 /*return*/, store.fetcher._fetch(nodeToStringHere, { method: "DELETE" })];
102
- case 6:
103
- e_1 = _a.sent();
104
- debug.log("Please manually remove ".concat(containerNode.value, " from your system."), e_1);
105
- return [3 /*break*/, 7];
106
- case 7: return [2 /*return*/];
107
- }
108
- });
109
- });
110
- }
111
- /**
112
- * Create a resource if it really does not exist
113
- * Be absolutely sure something does not exist before creating a new empty file
114
- * as otherwise existing could be deleted.
115
- * @param doc {NamedNode} - The resource
116
- */
117
- function loadOrCreateIfNotExists(doc) {
118
- return __awaiter(this, void 0, void 0, function () {
119
- var response, err_1, err_2, msg, msg;
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0:
123
- _a.trys.push([0, 2, , 10]);
124
- return [4 /*yield*/, store.fetcher.load(doc)];
125
- case 1:
126
- response = _a.sent();
127
- return [3 /*break*/, 10];
128
- case 2:
129
- err_1 = _a.sent();
130
- if (!(err_1.response.status === 404)) return [3 /*break*/, 8];
131
- _a.label = 3;
132
- case 3:
133
- _a.trys.push([3, 5, , 6]);
134
- return [4 /*yield*/, store.fetcher.webOperation('PUT', doc, { data: '', contentType: 'text/turtle' })];
135
- case 4:
136
- _a.sent();
137
- return [3 /*break*/, 6];
138
- case 5:
139
- err_2 = _a.sent();
140
- msg = 'createIfNotExists: PUT FAILED: ' + doc + ': ' + err_2;
141
- throw new CustomError_1.WebOperationError(msg);
142
- case 6: return [4 /*yield*/, store.fetcher.load(doc)];
143
- case 7:
144
- _a.sent();
145
- return [3 /*break*/, 9];
146
- case 8:
147
- if (err_1.response.status === 401) {
148
- throw new CustomError_1.UnauthorizedError();
149
- }
150
- if (err_1.response.status === 403) {
151
- if ((0, utils_1.differentOrigin)(doc)) {
152
- throw new CustomError_1.CrossOriginForbiddenError();
153
- }
154
- throw new CustomError_1.SameOriginForbiddenError();
155
- }
156
- msg = 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err_1;
157
- throw new CustomError_1.FetchError(err_1.status, err_1.message + msg);
158
- case 9: return [3 /*break*/, 10];
159
- case 10: return [2 /*return*/, response];
160
- }
161
- });
162
- });
163
- }
164
- /* Follow link from this doc to another thing, or else make a new link
165
- **
166
- ** @returns existing object, or creates it if non existent
167
- */
168
- function followOrCreateLink(subject, predicate, object, doc) {
169
- return __awaiter(this, void 0, void 0, function () {
170
- var result, msg, err_3, msg, err_4;
171
- return __generator(this, function (_a) {
172
- switch (_a.label) {
173
- case 0: return [4 /*yield*/, store.fetcher.load(doc)];
174
- case 1:
175
- _a.sent();
176
- result = store.any(subject, predicate, null, doc);
177
- if (result)
178
- return [2 /*return*/, result];
179
- if (!store.updater.editable(doc)) {
180
- msg = "followOrCreateLink: cannot edit ".concat(doc.value);
181
- debug.warn(msg);
182
- throw new CustomError_1.NotEditableError(msg);
183
- }
184
- _a.label = 2;
185
- case 2:
186
- _a.trys.push([2, 4, , 5]);
187
- return [4 /*yield*/, store.updater.update([], [(0, rdflib_1.st)(subject, predicate, object, doc)])];
188
- case 3:
189
- _a.sent();
190
- return [3 /*break*/, 5];
191
- case 4:
192
- err_3 = _a.sent();
193
- msg = "followOrCreateLink: Error making link in ".concat(doc, " to ").concat(object, ": ").concat(err_3);
194
- debug.warn(msg);
195
- throw new CustomError_1.WebOperationError(err_3);
196
- case 5:
197
- _a.trys.push([5, 7, , 8]);
198
- return [4 /*yield*/, loadOrCreateIfNotExists(object)
199
- // store.fetcher.webOperation('PUT', object, { data: '', contentType: 'text/turtle'})
200
- ];
201
- case 6:
202
- _a.sent();
203
- return [3 /*break*/, 8];
204
- case 7:
205
- err_4 = _a.sent();
206
- debug.warn("followOrCreateLink: Error loading or saving new linked document: ".concat(object, ": ").concat(err_4));
207
- throw err_4;
208
- case 8: return [2 /*return*/, object];
209
- }
210
- });
211
- });
212
- }
213
- // Copied from https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5
214
- function setSinglePeerAccess(options) {
215
- return __awaiter(this, void 0, void 0, function () {
216
- var str, aclDocUrl;
217
- return __generator(this, function (_a) {
218
- switch (_a.label) {
219
- case 0:
220
- str = [
221
- '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',
222
- '',
223
- "<#alice> a acl:Authorization;\n acl:agent <".concat(options.ownerWebId, ">;"),
224
- " acl:accessTo <".concat(options.target, ">;"),
225
- " acl:default <".concat(options.target, ">;"),
226
- ' acl:mode acl:Read, acl:Write, acl:Control.',
227
- ''
228
- ].join('\n');
229
- if (options.accessToModes) {
230
- str += [
231
- '<#bobAccessTo> a acl:Authorization;',
232
- " acl:agent <".concat(options.peerWebId, ">;"),
233
- " acl:accessTo <".concat(options.target, ">;"),
234
- " acl:mode ".concat(options.accessToModes, "."),
235
- ''
236
- ].join('\n');
237
- }
238
- if (options.defaultModes) {
239
- str += [
240
- '<#bobDefault> a acl:Authorization;',
241
- " acl:agent <".concat(options.peerWebId, ">;"),
242
- " acl:default <".concat(options.target, ">;"),
243
- " acl:mode ".concat(options.defaultModes, "."),
244
- ''
245
- ].join('\n');
246
- }
247
- return [4 /*yield*/, aclLogic.findAclDocUrl((0, rdflib_1.sym)(options.target))];
248
- case 1:
249
- aclDocUrl = _a.sent();
250
- return [2 /*return*/, store.fetcher._fetch(aclDocUrl, {
251
- method: 'PUT',
252
- body: str,
253
- headers: [
254
- ['Content-Type', 'text/turtle']
255
- ]
256
- })];
257
- }
258
- });
259
- });
260
- }
261
- function createEmptyRdfDoc(doc, comment) {
262
- return __awaiter(this, void 0, void 0, function () {
263
- return __generator(this, function (_a) {
264
- switch (_a.label) {
265
- case 0: return [4 /*yield*/, store.fetcher.webOperation("PUT", doc.uri, {
266
- data: "# ".concat(new Date(), " ").concat(comment, "\n "),
267
- contentType: "text/turtle",
268
- })];
269
- case 1:
270
- _a.sent();
271
- return [2 /*return*/];
272
- }
273
- });
274
- });
275
- }
276
- return {
277
- recursiveDelete: recursiveDelete,
278
- setSinglePeerAccess: setSinglePeerAccess,
279
- createEmptyRdfDoc: createEmptyRdfDoc,
280
- followOrCreateLink: followOrCreateLink,
281
- loadOrCreateIfNotExists: loadOrCreateIfNotExists
282
- };
283
- }
284
- //# sourceMappingURL=utilityLogic.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilityLogic.js","sourceRoot":"","sources":["../../src/util/utilityLogic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,gDAqJC;AA1JD,iCAA4C;AAC5C,oDAA+J;AAC/J,mDAAuC;AACvC,iCAA0C;AAE1C,SAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,cAAc;IAEhE,SAAe,eAAe,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AAI,CAAC,CAAA;wBACd,CAAC;wBACD,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;4BACzB,GAAG,IAAI;gCACL,oCAAoC;gCACpC,uBAAgB,OAAO,CAAC,SAAS,OAAI;gCACrC,yBAAkB,OAAO,CAAC,MAAM,OAAI;gCACpC,qBAAc,OAAO,CAAC,YAAY,MAAG;gCACrC,EAAE;6BACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;wBACd,CAAC;wBACiB,qBAAM,QAAQ,CAAC,aAAa,CAAC,IAAA,YAAG,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAA;;wBAA7D,SAAS,GAAG,SAAiD;wBACnE,sBAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gCACrC,MAAM,EAAE,KAAK;gCACb,IAAI,EAAE,GAAG;gCACT,OAAO,EAAE;oCACP,CAAC,cAAc,EAAE,aAAa,CAAC;iCAChC;6BACF,CAAC,EAAC;;;;KACJ;IAED,SAAe,iBAAiB,CAAC,GAAc,EAAE,OAAe;;;;4BAC9D,qBAAM,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE;4BAC/C,IAAI,EAAE,YAAK,IAAI,IAAI,EAAE,cAAI,OAAO,SACnC;4BACG,WAAW,EAAE,aAAa;yBAC3B,CAAC,EAAA;;wBAJF,SAIE,CAAC;;;;;KACJ;IAED,OAAO;QACL,eAAe,iBAAA;QACf,mBAAmB,qBAAA;QACnB,iBAAiB,mBAAA;QACjB,kBAAkB,oBAAA;QAClB,uBAAuB,yBAAA;KACxB,CAAA;AACH,CAAC"}
package/lib/util/utils.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newThing = newThing;
4
- exports.uniqueNodes = uniqueNodes;
5
- exports.getArchiveUrl = getArchiveUrl;
6
- exports.differentOrigin = differentOrigin;
7
- exports.suggestPreferencesFile = suggestPreferencesFile;
8
- exports.determineChatContainer = determineChatContainer;
9
- var rdflib_1 = require("rdflib");
10
- function newThing(doc) {
11
- return (0, rdflib_1.sym)(doc.uri + "#" + "id" + ("" + Date.now()));
12
- }
13
- function uniqueNodes(arr) {
14
- var uris = arr.map(function (x) { return x.uri; });
15
- var set = new Set(uris);
16
- var uris2 = Array.from(set);
17
- var arr2 = uris2.map(function (u) { return new rdflib_1.NamedNode(u); });
18
- return arr2; // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))
19
- }
20
- function getArchiveUrl(baseUrl, date) {
21
- var year = date.getUTCFullYear();
22
- var month = ('0' + (date.getUTCMonth() + 1)).slice(-2);
23
- var day = ('0' + (date.getUTCDate())).slice(-2);
24
- var parts = baseUrl.split('/');
25
- var filename = parts[parts.length - 1];
26
- return new URL("./archive/".concat(year, "/").concat(month, "/").concat(day, "/").concat(filename), baseUrl).toString();
27
- }
28
- function differentOrigin(doc) {
29
- if (!doc) {
30
- return true;
31
- }
32
- return ("".concat(window.location.origin, "/") !== new URL(doc.value).origin);
33
- }
34
- function suggestPreferencesFile(me) {
35
- var stripped = me.uri.replace('/profile/', '/').replace('/public/', '/');
36
- // const stripped = me.uri.replace(\/[p|P]rofile/\g, '/').replace(\/[p|P]ublic/\g, '/')
37
- var folderURI = stripped.split('/').slice(0, -1).join('/') + '/Settings/';
38
- var fileURI = folderURI + 'Preferences.ttl';
39
- return (0, rdflib_1.sym)(fileURI);
40
- }
41
- function determineChatContainer(invitee, podRoot) {
42
- // Create chat
43
- // See https://gitter.im/solid/chat-app?at=5f3c800f855be416a23ae74a
44
- var chatContainerStr = new URL("IndividualChats/".concat(new URL(invitee.value).host, "/"), podRoot.value).toString();
45
- return new rdflib_1.NamedNode(chatContainerStr);
46
- }
47
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":";;AAEA,4BAEC;AAED,kCAMC;AAED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AC,oBAAa,IAAI,cAAI,KAAK,cAAI,GAAG,cAAI,QAAQ,CAAE,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AACxF,CAAC;AAED,SAAgB,eAAe,CAAC,GAAG;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,CACH,UAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,MAAG,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAC7D,CAAC;AACN,CAAC;AAED,SAAgB,sBAAsB,CAAE,EAAY;IAChD,IAAM,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAC1E,uFAAuF;IACvF,IAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,YAAY,CAAA;IAC1E,IAAM,OAAO,GAAG,SAAS,GAAG,iBAAiB,CAAA;IAC7C,OAAO,IAAA,YAAG,EAAC,OAAO,CAAC,CAAA;AACvB,CAAC;AAED,SAAgB,sBAAsB,CAClC,OAAkB,EAClB,OAAkB;IAElB,cAAc;IACd,mEAAmE;IACnE,IAAM,gBAAgB,GAAG,IAAI,GAAG,CAC5B,0BAAmB,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,MAAG,EACjD,OAAO,CAAC,KAAK,CAChB,CAAC,QAAQ,EAAE,CAAC;IACb,OAAO,IAAI,kBAAS,CAAC,gBAAgB,CAAC,CAAC;AAC3C,CAAC"}
@@ -1,156 +0,0 @@
1
- import { graph, NamedNode, Namespace, serialize, sym } from "rdflib"
2
- import { AclLogic } from "../types";
3
- import { ns as namespace } from '../util/ns'
4
-
5
-
6
- export const ACL_LINK = sym(
7
- "http://www.iana.org/assignments/link-relations/acl"
8
- );
9
-
10
- export function createAclLogic(store): AclLogic {
11
-
12
- const ns = namespace
13
-
14
- async function findAclDocUrl(url: NamedNode) {
15
- await store.fetcher.load(url);
16
- const docNode = store.any(url, ACL_LINK);
17
- if (!docNode) {
18
- throw new Error(`No ACL link discovered for ${url}`);
19
- }
20
- return docNode.value;
21
- }
22
- /**
23
- * Simple Access Control
24
- *
25
- * This function sets up a simple default ACL for a resource, with
26
- * RWC for the owner, and a specified access (default none) for the public.
27
- * In all cases owner has read write control.
28
- * Parameter lists modes allowed to public
29
- *
30
- * @param options
31
- * @param options.public eg ['Read', 'Write']
32
- *
33
- * @returns Resolves with aclDoc uri on successful write
34
- */
35
- function setACLUserPublic (
36
- docURI: string,
37
- me: NamedNode,
38
- options: {
39
- defaultForNew?: boolean,
40
- public?: []
41
- }
42
- ): Promise<NamedNode> {
43
- const aclDoc = store.any(
44
- store.sym(docURI),
45
- ACL_LINK
46
- )
47
-
48
- return Promise.resolve()
49
- .then(() => {
50
- if (aclDoc) {
51
- return aclDoc as NamedNode
52
- }
53
-
54
- return fetchACLRel(docURI).catch(err => {
55
- throw new Error(`Error fetching rel=ACL header for ${docURI}: ${err}`)
56
- })
57
- })
58
- .then(aclDoc => {
59
- const aclText = genACLText(docURI, me, aclDoc.uri, options)
60
- if (!store.fetcher) {
61
- throw new Error('Cannot PUT this, store has no fetcher')
62
- }
63
- return store.fetcher
64
- .webOperation('PUT', aclDoc.uri, {
65
- data: aclText,
66
- contentType: 'text/turtle'
67
- })
68
- .then(result => {
69
- if (!result.ok) {
70
- throw new Error('Error writing ACL text: ' + result.error)
71
- }
72
-
73
- return aclDoc
74
- })
75
- })
76
- }
77
-
78
- /**
79
- * @param docURI
80
- * @returns
81
- */
82
- function fetchACLRel (docURI: string): Promise<NamedNode> {
83
- const fetcher = store.fetcher
84
- if (!fetcher) {
85
- throw new Error('Cannot fetch ACL rel, store has no fetcher')
86
- }
87
-
88
- return fetcher.load(docURI).then(result => {
89
- if (!result.ok) {
90
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- throw new Error('fetchACLRel: While loading:' + (result as any).error)
92
- }
93
-
94
- const aclDoc = store.any(
95
- store.sym(docURI),
96
- ACL_LINK
97
- )
98
-
99
- if (!aclDoc) {
100
- throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI)
101
- }
102
-
103
- return aclDoc as NamedNode
104
- })
105
- }
106
-
107
- /**
108
- * @param docURI
109
- * @param me
110
- * @param aclURI
111
- * @param options
112
- *
113
- * @returns Serialized ACL
114
- */
115
- function genACLText (
116
- docURI: string,
117
- me: NamedNode,
118
- aclURI: string,
119
- options: {
120
- defaultForNew?: boolean,
121
- public?: []
122
- } = {}
123
- ): string | undefined {
124
- const optPublic = options.public || []
125
- const g = graph()
126
- const auth = Namespace('http://www.w3.org/ns/auth/acl#')
127
- let a = g.sym(`${aclURI}#a1`)
128
- const acl = g.sym(aclURI)
129
- const doc = g.sym(docURI)
130
- g.add(a, ns.rdf('type'), auth('Authorization'), acl)
131
- g.add(a, auth('accessTo'), doc, acl)
132
- if (options.defaultForNew) {
133
- g.add(a, auth('default'), doc, acl)
134
- }
135
- g.add(a, auth('agent'), me, acl)
136
- g.add(a, auth('mode'), auth('Read'), acl)
137
- g.add(a, auth('mode'), auth('Write'), acl)
138
- g.add(a, auth('mode'), auth('Control'), acl)
139
-
140
- if (optPublic.length) {
141
- a = g.sym(`${aclURI}#a2`)
142
- g.add(a, ns.rdf('type'), auth('Authorization'), acl)
143
- g.add(a, auth('accessTo'), doc, acl)
144
- g.add(a, auth('agentClass'), ns.foaf('Agent'), acl)
145
- for (let p = 0; p < optPublic.length; p++) {
146
- g.add(a, auth('mode'), auth(optPublic[p]), acl) // Like 'Read' etc
147
- }
148
- }
149
- return serialize(acl, g, aclURI)
150
- }
151
- return {
152
- findAclDocUrl,
153
- setACLUserPublic,
154
- genACLText
155
- }
156
- }
@@ -1,7 +0,0 @@
1
- import {
2
- Session,
3
- } from '@inrupt/solid-client-authn-browser'
4
-
5
- export const authSession = new Session()
6
-
7
-
@@ -1,127 +0,0 @@
1
- import { namedNode, NamedNode, sym } from "rdflib";
2
- import { appContext, offlineTestID } from "./authUtil";
3
- import * as debug from '../util/debug'
4
- import { EVENTS, Session } from "@inrupt/solid-client-authn-browser";
5
- import { AuthenticationContext, AuthnLogic } from "../types";
6
-
7
- export class SolidAuthnLogic implements AuthnLogic {
8
- private session: Session;
9
-
10
- constructor(solidAuthSession: Session) {
11
- this.session = solidAuthSession;
12
- }
13
-
14
- // we created authSession getter because we want to access it as authn.authSession externally
15
- get authSession():Session { return this.session }
16
-
17
- currentUser(): NamedNode | null {
18
- const app = appContext()
19
- if (app.viewingNoAuthPage) {
20
- return sym(app.webId)
21
- }
22
- if (this && this.session && this.session.info && this.session.info.webId && this.session.info.isLoggedIn) {
23
- return sym(this.session.info.webId)
24
- }
25
- return offlineTestID() // null unless testing
26
- }
27
-
28
- /**
29
- * Retrieves currently logged in webId from either
30
- * defaultTestUser or SolidAuth
31
- * Also activates a session after login
32
- * @param [setUserCallback] Optional callback
33
- * @returns Resolves with webId uri, if no callback provided
34
- */
35
- async checkUser<T> (
36
- setUserCallback?: (me: NamedNode | null) => T
37
- ): Promise<NamedNode | T | null> {
38
- // Save hash for "restorePreviousSession"
39
- const preLoginRedirectHash = new URL(window.location.href).hash
40
- if (preLoginRedirectHash) {
41
- window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash)
42
- }
43
- this.session.events.on(EVENTS.SESSION_RESTORED, (url) => {
44
- debug.log(`Session restored to ${url}`)
45
- if (document.location.toString() !== url) history.replaceState(null, '', url)
46
- })
47
-
48
- /**
49
- * Handle a successful authentication redirect
50
- */
51
- const redirectUrl = new URL(window.location.href)
52
- redirectUrl.hash = ''
53
- await this.session
54
- .handleIncomingRedirect({
55
- restorePreviousSession: true,
56
- url: redirectUrl.href
57
- })
58
-
59
- // Check to see if a hash was stored in local storage
60
- const postLoginRedirectHash = window.localStorage.getItem('preLoginRedirectHash')
61
- if (postLoginRedirectHash) {
62
- const curUrl = new URL(window.location.href)
63
- if (curUrl.hash !== postLoginRedirectHash) {
64
- if (history.pushState) {
65
- // debug.log('Setting window.location.has using pushState')
66
- history.pushState(null, document.title, postLoginRedirectHash)
67
- } else {
68
- // debug.warn('Setting window.location.has using location.hash')
69
- location.hash = postLoginRedirectHash
70
- }
71
- curUrl.hash = postLoginRedirectHash
72
- }
73
- // See https://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document
74
- // window.location.href = curUrl.toString()// @@ See https://developer.mozilla.org/en-US/docs/Web/API/Window/location
75
- window.localStorage.setItem('preLoginRedirectHash', '')
76
- }
77
-
78
- // Check to see if already logged in / have the WebID
79
- let me = offlineTestID()
80
- if (me) {
81
- return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
82
- }
83
-
84
- const webId = this.webIdFromSession(this.session.info)
85
- if (webId) {
86
- me = this.saveUser(webId)
87
- }
88
-
89
- if (me) {
90
- debug.log(`(Logged in as ${me} by authentication)`)
91
- }
92
-
93
- return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
94
- }
95
-
96
- /**
97
- * Saves `webId` in `context.me`
98
- * @param webId
99
- * @param context
100
- *
101
- * @returns Returns the WebID, after setting it
102
- */
103
- saveUser (
104
- webId: NamedNode | string | null,
105
- context?: AuthenticationContext
106
- ): NamedNode | null {
107
- let webIdUri: string
108
- if (webId) {
109
- webIdUri = (typeof webId === 'string') ? webId : webId.uri
110
- const me = namedNode(webIdUri)
111
- if (context) {
112
- context.me = me
113
- }
114
- return me
115
- }
116
- return null
117
- }
118
-
119
- /**
120
- * @returns {Promise<string|null>} Resolves with WebID URI or null
121
- */
122
- webIdFromSession (session?: { webId?: string, isLoggedIn: boolean }): string | null {
123
- const webId = session?.webId && session.isLoggedIn ? session.webId : null
124
- return webId
125
- }
126
-
127
- }