solid-logic 1.3.17-ec29db42 → 1.3.17-f02a2f1a

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 (117) hide show
  1. package/lib/acl/aclLogic.d.ts +3 -30
  2. package/lib/acl/aclLogic.d.ts.map +1 -1
  3. package/lib/acl/aclLogic.js +152 -119
  4. package/lib/acl/aclLogic.js.map +1 -1
  5. package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
  6. package/lib/authn/SolidAuthnLogic.js +2 -2
  7. package/lib/authn/SolidAuthnLogic.js.map +1 -1
  8. package/lib/chat/chatLogic.d.ts +3 -0
  9. package/lib/chat/chatLogic.d.ts.map +1 -0
  10. package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -86
  11. package/lib/chat/chatLogic.js.map +1 -0
  12. package/lib/inbox/inboxLogic.d.ts +3 -0
  13. package/lib/inbox/inboxLogic.d.ts.map +1 -0
  14. package/lib/inbox/{InboxLogic.js → inboxLogic.js} +58 -64
  15. package/lib/inbox/inboxLogic.js.map +1 -0
  16. package/lib/index.d.ts +6 -11
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +5 -25
  19. package/lib/index.js.map +1 -1
  20. package/lib/logic/CustomError.d.ts +4 -0
  21. package/lib/logic/CustomError.d.ts.map +1 -1
  22. package/lib/logic/CustomError.js +17 -1
  23. package/lib/logic/CustomError.js.map +1 -1
  24. package/lib/logic/SolidLogic.d.ts +4 -46
  25. package/lib/logic/SolidLogic.d.ts.map +1 -1
  26. package/lib/logic/SolidLogic.js +44 -273
  27. package/lib/logic/SolidLogic.js.map +1 -1
  28. package/lib/logic/solidLogicSingleton.d.ts +1 -2
  29. package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
  30. package/lib/logic/solidLogicSingleton.js +2 -2
  31. package/lib/logic/solidLogicSingleton.js.map +1 -1
  32. package/lib/profile/profileLogic.d.ts +3 -0
  33. package/lib/profile/profileLogic.d.ts.map +1 -0
  34. package/lib/profile/profileLogic.js +246 -0
  35. package/lib/profile/profileLogic.js.map +1 -0
  36. package/lib/typeIndex/typeIndexLogic.d.ts +2 -21
  37. package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
  38. package/lib/typeIndex/typeIndexLogic.js +304 -296
  39. package/lib/typeIndex/typeIndexLogic.js.map +1 -1
  40. package/lib/types.d.ts +82 -1
  41. package/lib/types.d.ts.map +1 -1
  42. package/lib/util/containerLogic.d.ts +11 -0
  43. package/lib/util/containerLogic.d.ts.map +1 -0
  44. package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +53 -44
  45. package/lib/util/containerLogic.js.map +1 -0
  46. package/lib/util/ns.d.ts +2 -0
  47. package/lib/util/ns.d.ts.map +1 -0
  48. package/lib/util/ns.js +34 -0
  49. package/lib/util/ns.js.map +1 -0
  50. package/lib/util/utilityLogic.d.ts +15 -0
  51. package/lib/util/utilityLogic.d.ts.map +1 -0
  52. package/lib/util/utilityLogic.js +272 -0
  53. package/lib/util/utilityLogic.js.map +1 -0
  54. package/lib/util/utils.d.ts +8 -0
  55. package/lib/util/utils.d.ts.map +1 -0
  56. package/lib/util/utils.js +48 -0
  57. package/lib/util/utils.js.map +1 -0
  58. package/package.json +3 -1
  59. package/src/acl/aclLogic.ts +137 -118
  60. package/src/authn/SolidAuthnLogic.ts +3 -2
  61. package/src/chat/chatLogic.ts +225 -0
  62. package/src/inbox/inboxLogic.ts +58 -0
  63. package/src/index.ts +11 -30
  64. package/src/logic/CustomError.ts +5 -1
  65. package/src/logic/SolidLogic.ts +42 -229
  66. package/src/logic/solidLogicSingleton.ts +3 -3
  67. package/src/profile/profileLogic.ts +126 -0
  68. package/src/typeIndex/typeIndexLogic.ts +175 -182
  69. package/src/types.ts +83 -4
  70. package/src/util/containerLogic.ts +54 -0
  71. package/src/util/ns.ts +5 -0
  72. package/src/util/utilityLogic.ts +155 -0
  73. package/src/util/utils.ts +52 -0
  74. package/test/aclLogic.test.ts +13 -4
  75. package/test/chatLogic.test.ts +70 -71
  76. package/test/container.test.ts +56 -0
  77. package/test/helpers/dataSetup.ts +134 -0
  78. package/test/helpers/setup.ts +4 -0
  79. package/test/inboxLogic.test.ts +39 -38
  80. package/test/logic.test.ts +10 -9
  81. package/test/profileLogic.test.ts +246 -0
  82. package/test/typeIndexLogic.test.ts +487 -30
  83. package/test/utilityLogic.test.ts +172 -126
  84. package/test/utils.test.ts +32 -0
  85. package/lib/chat/ChatLogic.d.ts +0 -26
  86. package/lib/chat/ChatLogic.d.ts.map +0 -1
  87. package/lib/chat/ChatLogic.js.map +0 -1
  88. package/lib/chat/determineChatContainer.d.ts +0 -3
  89. package/lib/chat/determineChatContainer.d.ts.map +0 -1
  90. package/lib/chat/determineChatContainer.js +0 -12
  91. package/lib/chat/determineChatContainer.js.map +0 -1
  92. package/lib/discovery/discoveryLogic.d.ts +0 -37
  93. package/lib/discovery/discoveryLogic.d.ts.map +0 -1
  94. package/lib/discovery/discoveryLogic.js +0 -507
  95. package/lib/discovery/discoveryLogic.js.map +0 -1
  96. package/lib/inbox/InboxLogic.d.ts +0 -18
  97. package/lib/inbox/InboxLogic.d.ts.map +0 -1
  98. package/lib/inbox/InboxLogic.js.map +0 -1
  99. package/lib/profile/ProfileLogic.d.ts +0 -13
  100. package/lib/profile/ProfileLogic.d.ts.map +0 -1
  101. package/lib/profile/ProfileLogic.js.map +0 -1
  102. package/lib/util/UtilityLogic.d.ts +0 -33
  103. package/lib/util/UtilityLogic.d.ts.map +0 -1
  104. package/lib/util/UtilityLogic.js +0 -240
  105. package/lib/util/UtilityLogic.js.map +0 -1
  106. package/lib/util/uri.d.ts +0 -3
  107. package/lib/util/uri.d.ts.map +0 -1
  108. package/lib/util/uri.js +0 -9
  109. package/lib/util/uri.js.map +0 -1
  110. package/src/chat/ChatLogic.ts +0 -244
  111. package/src/chat/determineChatContainer.ts +0 -14
  112. package/src/discovery/discoveryLogic.ts +0 -288
  113. package/src/inbox/InboxLogic.ts +0 -66
  114. package/src/profile/ProfileLogic.ts +0 -44
  115. package/src/util/UtilityLogic.ts +0 -161
  116. package/src/util/uri.ts +0 -5
  117. package/test/discoveryLogic.test.ts +0 -712
@@ -0,0 +1,272 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.createUtilityLogic = void 0;
63
+ var rdflib_1 = require("rdflib");
64
+ var CustomError_1 = require("../logic/CustomError");
65
+ var debug = __importStar(require("../util/debug"));
66
+ var utils_1 = require("./utils");
67
+ function createUtilityLogic(store, aclLogic, containerLogic) {
68
+ function recursiveDelete(url) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var aclDocUrl, containerMembers, e_1;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ _a.trys.push([0, 6, , 7]);
75
+ if (!containerLogic.isContainer(url)) return [3 /*break*/, 5];
76
+ return [4 /*yield*/, aclLogic.findAclDocUrl(url)];
77
+ case 1:
78
+ aclDocUrl = _a.sent();
79
+ return [4 /*yield*/, store.fetcher._fetch(aclDocUrl, { method: "DELETE" })];
80
+ case 2:
81
+ _a.sent();
82
+ return [4 /*yield*/, containerLogic.getContainerMembers(url)];
83
+ case 3:
84
+ containerMembers = _a.sent();
85
+ return [4 /*yield*/, Promise.all(containerMembers.map(function (url) { return recursiveDelete(url); }))];
86
+ case 4:
87
+ _a.sent();
88
+ _a.label = 5;
89
+ case 5: return [2 /*return*/, store.fetcher._fetch(url, { method: "DELETE" })];
90
+ case 6:
91
+ e_1 = _a.sent();
92
+ return [3 /*break*/, 7];
93
+ case 7: return [2 /*return*/];
94
+ }
95
+ });
96
+ });
97
+ }
98
+ /**
99
+ * Create a resource if it really does not exist
100
+ * Be absolutely sure something does not exist before creating a new empty file
101
+ * as otherwise existing could be deleted.
102
+ * @param doc {NamedNode} - The resource
103
+ */
104
+ function loadOrCreateIfNotExists(doc) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var response, err_1, err_2, msg, msg;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ _a.trys.push([0, 2, , 10]);
111
+ return [4 /*yield*/, store.fetcher.load(doc)];
112
+ case 1:
113
+ response = _a.sent();
114
+ return [3 /*break*/, 10];
115
+ case 2:
116
+ err_1 = _a.sent();
117
+ if (!(err_1.response.status === 404)) return [3 /*break*/, 8];
118
+ _a.label = 3;
119
+ case 3:
120
+ _a.trys.push([3, 5, , 6]);
121
+ return [4 /*yield*/, store.fetcher.webOperation('PUT', doc, { data: '', contentType: 'text/turtle' })];
122
+ case 4:
123
+ _a.sent();
124
+ return [3 /*break*/, 6];
125
+ case 5:
126
+ err_2 = _a.sent();
127
+ msg = 'createIfNotExists: PUT FAILED: ' + doc + ': ' + err_2;
128
+ throw new CustomError_1.WebOperationError(msg);
129
+ case 6: return [4 /*yield*/, store.fetcher.load(doc)];
130
+ case 7:
131
+ _a.sent();
132
+ return [3 /*break*/, 9];
133
+ case 8:
134
+ if (err_1.response.status === 401) {
135
+ throw new CustomError_1.UnauthorizedError();
136
+ }
137
+ if (err_1.response.status === 403) {
138
+ if ((0, utils_1.differentOrigin)(doc)) {
139
+ throw new CustomError_1.CrossOriginForbiddenError();
140
+ }
141
+ throw new CustomError_1.SameOriginForbiddenError();
142
+ }
143
+ msg = 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err_1;
144
+ throw new CustomError_1.FetchError(err_1.status, err_1.message + msg);
145
+ case 9: return [3 /*break*/, 10];
146
+ case 10: return [2 /*return*/, response];
147
+ }
148
+ });
149
+ });
150
+ }
151
+ /* Follow link from this doc to another thing, or else make a new link
152
+ **
153
+ ** @returns existing object, or creates it if non existent
154
+ */
155
+ function followOrCreateLink(subject, predicate, object, doc) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var result, msg, err_3, msg, err_4;
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0: return [4 /*yield*/, store.fetcher.load(doc)];
161
+ case 1:
162
+ _a.sent();
163
+ result = store.any(subject, predicate, null, doc);
164
+ if (result)
165
+ return [2 /*return*/, result];
166
+ if (!store.updater.editable(doc)) {
167
+ msg = "followOrCreateLink: cannot edit ".concat(doc.value);
168
+ debug.warn(msg);
169
+ throw new CustomError_1.NotEditableError(msg);
170
+ }
171
+ _a.label = 2;
172
+ case 2:
173
+ _a.trys.push([2, 4, , 5]);
174
+ return [4 /*yield*/, store.updater.update([], [(0, rdflib_1.st)(subject, predicate, object, doc)])];
175
+ case 3:
176
+ _a.sent();
177
+ return [3 /*break*/, 5];
178
+ case 4:
179
+ err_3 = _a.sent();
180
+ msg = "followOrCreateLink: Error making link in ".concat(doc, " to ").concat(object, ": ").concat(err_3);
181
+ debug.warn(msg);
182
+ throw new CustomError_1.WebOperationError(err_3);
183
+ case 5:
184
+ _a.trys.push([5, 7, , 8]);
185
+ return [4 /*yield*/, loadOrCreateIfNotExists(object)
186
+ // store.fetcher.webOperation('PUT', object, { data: '', contentType: 'text/turtle'})
187
+ ];
188
+ case 6:
189
+ _a.sent();
190
+ return [3 /*break*/, 8];
191
+ case 7:
192
+ err_4 = _a.sent();
193
+ debug.warn("followOrCreateLink: Error loading or saving new linked document: ".concat(object, ": ").concat(err_4));
194
+ throw err_4;
195
+ case 8: return [2 /*return*/, object];
196
+ }
197
+ });
198
+ });
199
+ }
200
+ // Copied from https://github.com/solidos/web-access-control-tests/blob/v3.0.0/test/surface/delete.test.ts#L5
201
+ function setSinglePeerAccess(options) {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ var str, aclDocUrl;
204
+ return __generator(this, function (_a) {
205
+ switch (_a.label) {
206
+ case 0:
207
+ str = [
208
+ '@prefix acl: <http://www.w3.org/ns/auth/acl#>.',
209
+ '',
210
+ "<#alice> a acl:Authorization;\n acl:agent <".concat(options.ownerWebId, ">;"),
211
+ " acl:accessTo <".concat(options.target, ">;"),
212
+ " acl:default <".concat(options.target, ">;"),
213
+ ' acl:mode acl:Read, acl:Write, acl:Control.',
214
+ ''
215
+ ].join('\n');
216
+ if (options.accessToModes) {
217
+ str += [
218
+ '<#bobAccessTo> a acl:Authorization;',
219
+ " acl:agent <".concat(options.peerWebId, ">;"),
220
+ " acl:accessTo <".concat(options.target, ">;"),
221
+ " acl:mode ".concat(options.accessToModes, "."),
222
+ ''
223
+ ].join('\n');
224
+ }
225
+ if (options.defaultModes) {
226
+ str += [
227
+ '<#bobDefault> a acl:Authorization;',
228
+ " acl:agent <".concat(options.peerWebId, ">;"),
229
+ " acl:default <".concat(options.target, ">;"),
230
+ " acl:mode ".concat(options.defaultModes, "."),
231
+ ''
232
+ ].join('\n');
233
+ }
234
+ return [4 /*yield*/, aclLogic.findAclDocUrl(options.target)];
235
+ case 1:
236
+ aclDocUrl = _a.sent();
237
+ return [2 /*return*/, store.fetcher._fetch(aclDocUrl, {
238
+ method: 'PUT',
239
+ body: str,
240
+ headers: [
241
+ ['Content-Type', 'text/turtle']
242
+ ]
243
+ })];
244
+ }
245
+ });
246
+ });
247
+ }
248
+ function createEmptyRdfDoc(doc, comment) {
249
+ return __awaiter(this, void 0, void 0, function () {
250
+ return __generator(this, function (_a) {
251
+ switch (_a.label) {
252
+ case 0: return [4 /*yield*/, store.fetcher.webOperation("PUT", doc.uri, {
253
+ data: "# ".concat(new Date(), " ").concat(comment, "\n "),
254
+ contentType: "text/turtle",
255
+ })];
256
+ case 1:
257
+ _a.sent();
258
+ return [2 /*return*/];
259
+ }
260
+ });
261
+ });
262
+ }
263
+ return {
264
+ recursiveDelete: recursiveDelete,
265
+ setSinglePeerAccess: setSinglePeerAccess,
266
+ createEmptyRdfDoc: createEmptyRdfDoc,
267
+ followOrCreateLink: followOrCreateLink,
268
+ loadOrCreateIfNotExists: loadOrCreateIfNotExists
269
+ };
270
+ }
271
+ exports.createUtilityLogic = createUtilityLogic;
272
+ //# sourceMappingURL=utilityLogic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilityLogic.js","sourceRoot":"","sources":["../../src/util/utilityLogic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAuC;AACvC,oDAA+J;AAC/J,mDAAuC;AACvC,iCAA0C;AAE1C,SAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,cAAc;IAEhE,SAAe,eAAe,CAAC,GAAW;;;;;;;6BAEhC,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,EAA/B,wBAA+B;wBACf,qBAAM,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,EAAA;;wBAA7C,SAAS,GAAG,SAAiC;wBACnD,qBAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,EA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AE,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;AApJD,gDAoJC"}
@@ -0,0 +1,8 @@
1
+ import { NamedNode } from "rdflib";
2
+ export declare function newThing(doc: NamedNode): NamedNode;
3
+ export declare function uniqueNodes(arr: NamedNode[]): NamedNode[];
4
+ export declare function getArchiveUrl(baseUrl: string, date: Date): string;
5
+ export declare function differentOrigin(doc: any): boolean;
6
+ export declare function suggestPreferencesFile(me: NamedNode): NamedNode;
7
+ export declare function determineChatContainer(invitee: NamedNode, podRoot: NamedNode): NamedNode;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAO,MAAM,QAAQ,CAAC;AAExC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAElD;AAED,wBAAgB,WAAW,CAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAM1D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,UAOxD;AAED,wBAAgB,eAAe,CAAC,GAAG,KAAA,GAAG,OAAO,CAO5C;AAED,wBAAgB,sBAAsB,CAAE,EAAE,EAAC,SAAS,aAMnD;AAED,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,SAAS,GACnB,SAAS,CAQX"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determineChatContainer = exports.suggestPreferencesFile = exports.differentOrigin = exports.getArchiveUrl = exports.uniqueNodes = exports.newThing = void 0;
4
+ var rdflib_1 = require("rdflib");
5
+ function newThing(doc) {
6
+ return (0, rdflib_1.sym)(doc.uri + "#" + "id" + ("" + Date.now()));
7
+ }
8
+ exports.newThing = newThing;
9
+ function uniqueNodes(arr) {
10
+ var uris = arr.map(function (x) { return x.uri; });
11
+ var set = new Set(uris);
12
+ var uris2 = Array.from(set);
13
+ var arr2 = uris2.map(function (u) { return new rdflib_1.NamedNode(u); });
14
+ return arr2; // Array.from(new Set(arr.map(x => x.uri))).map(u => sym(u))
15
+ }
16
+ exports.uniqueNodes = uniqueNodes;
17
+ function getArchiveUrl(baseUrl, date) {
18
+ var year = date.getUTCFullYear();
19
+ var month = ('0' + (date.getUTCMonth() + 1)).slice(-2);
20
+ var day = ('0' + (date.getUTCDate())).slice(-2);
21
+ var parts = baseUrl.split('/');
22
+ var filename = parts[parts.length - 1];
23
+ return new URL("./archive/".concat(year, "/").concat(month, "/").concat(day, "/").concat(filename), baseUrl).toString();
24
+ }
25
+ exports.getArchiveUrl = getArchiveUrl;
26
+ function differentOrigin(doc) {
27
+ if (!doc) {
28
+ return true;
29
+ }
30
+ return ("".concat(window.location.origin, "/") !== new URL(doc.value).origin);
31
+ }
32
+ exports.differentOrigin = differentOrigin;
33
+ function suggestPreferencesFile(me) {
34
+ var stripped = me.uri.replace('/profile/', '/').replace('/public/', '/');
35
+ // const stripped = me.uri.replace(\/[p|P]rofile/\g, '/').replace(\/[p|P]ublic/\g, '/')
36
+ var folderURI = stripped.split('/').slice(0, -1).join('/') + '/Settings/';
37
+ var fileURI = folderURI + 'Preferences.ttl';
38
+ return (0, rdflib_1.sym)(fileURI);
39
+ }
40
+ exports.suggestPreferencesFile = suggestPreferencesFile;
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
+ exports.determineChatContainer = determineChatContainer;
48
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AAExC,SAAgB,QAAQ,CAAC,GAAc;IACnC,OAAO,IAAA,YAAG,EAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACzD,CAAC;AAFD,4BAEC;AAED,SAAgB,WAAW,CAAE,GAAgB;IACzC,IAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,GAAG,EAAL,CAAK,CAAC,CAAA;IAChC,IAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;IACzB,IAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,IAAI,kBAAS,CAAC,CAAC,CAAC,EAAhB,CAAgB,CAAC,CAAA;IAC7C,OAAO,IAAI,CAAA,CAAC,4DAA4D;AAC5E,CAAC;AAND,kCAMC;AAED,SAAgB,aAAa,CAAC,OAAe,EAAE,IAAU;IACrD,IAAM,IAAI,GAAG,I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AC7C,OAAO,IAAA,YAAG,EAAC,OAAO,CAAC,CAAA;AACvB,CAAC;AAND,wDAMC;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;AAXD,wDAWC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-logic",
3
- "version": "1.3.17-ec29db42",
3
+ "version": "1.3.17-f02a2f1a",
4
4
  "description": "Core business logic of Solid OS",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -8,6 +8,7 @@
8
8
  "clean": "rm -rf lib",
9
9
  "lint": "eslint ./src",
10
10
  "test": "jest",
11
+ "test-debug": "node --inspect-brk ./node_modules/.bin/jest -i --env jest-environment-node-debug",
11
12
  "preversion": "npm test",
12
13
  "postversion": "git push --follow-tags",
13
14
  "ignore:prepublishOnly": "npm run build",
@@ -35,6 +36,7 @@
35
36
  "@typescript-eslint/parser": "^5.19.0",
36
37
  "eslint": "^8.13.0",
37
38
  "jest": "^27.5.1",
39
+ "jest-environment-node-debug": "^2.0.0",
38
40
  "jest-fetch-mock": "^3.0.3",
39
41
  "typescript": "^4.6.3"
40
42
  },
@@ -1,137 +1,156 @@
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
- */
1
+ import { graph, NamedNode, Namespace, serialize, sym } from "rdflib"
2
+ import { AclLogic } from "../types";
3
+ import { ns as namespace } from '../util/ns'
14
4
 
15
- import { graph, NamedNode, Namespace, serialize } from "rdflib"
16
- import solidNamespace from 'solid-namespace'
17
- import * as $rdf from 'rdflib'
18
- import { solidLogicSingleton } from "../logic/solidLogicSingleton"
19
- import { ACL_LINK } from "../util/UtilityLogic"
20
5
 
21
- export const ns = solidNamespace($rdf)
6
+ export const ACL_LINK = sym(
7
+ "http://www.iana.org/assignments/link-relations/acl"
8
+ );
22
9
 
23
- export function setACLUserPublic (
24
- docURI: string,
25
- me: NamedNode,
26
- options: {
27
- defaultForNew?: boolean,
28
- public?: []
29
- }
30
- ): Promise<NamedNode> {
31
- const aclDoc = solidLogicSingleton.store.any(
32
- solidLogicSingleton.store.sym(docURI),
33
- ACL_LINK
34
- )
10
+ export function createAclLogic(store): AclLogic {
35
11
 
36
- return Promise.resolve()
37
- .then(() => {
38
- if (aclDoc) {
39
- return aclDoc as NamedNode
12
+ const ns = namespace
13
+
14
+ async function findAclDocUrl(url: string) {
15
+ const doc = store.sym(url);
16
+ await store.fetcher.load(doc);
17
+ const docNode = store.any(doc, ACL_LINK);
18
+ if (!docNode) {
19
+ throw new Error(`No ACL link discovered for ${url}`);
20
+ }
21
+ return docNode.value;
40
22
  }
41
-
42
- return fetchACLRel(docURI).catch(err => {
43
- throw new Error(`Error fetching rel=ACL header for ${docURI}: ${err}`)
44
- })
45
- })
46
- .then(aclDoc => {
47
- const aclText = genACLText(docURI, me, aclDoc.uri, options)
48
- if (!solidLogicSingleton.store.fetcher) {
49
- throw new Error('Cannot PUT this, store has no fetcher')
23
+ /**
24
+ * Simple Access Control
25
+ *
26
+ * This function sets up a simple default ACL for a resource, with
27
+ * RWC for the owner, and a specified access (default none) for the public.
28
+ * In all cases owner has read write control.
29
+ * Parameter lists modes allowed to public
30
+ *
31
+ * @param options
32
+ * @param options.public eg ['Read', 'Write']
33
+ *
34
+ * @returns Resolves with aclDoc uri on successful write
35
+ */
36
+ function setACLUserPublic (
37
+ docURI: string,
38
+ me: NamedNode,
39
+ options: {
40
+ defaultForNew?: boolean,
41
+ public?: []
50
42
  }
51
- return solidLogicSingleton.store.fetcher
52
- .webOperation('PUT', aclDoc.uri, {
53
- data: aclText,
54
- contentType: 'text/turtle'
55
- })
56
- .then(result => {
57
- if (!result.ok) {
58
- throw new Error('Error writing ACL text: ' + result.error)
43
+ ): Promise<NamedNode> {
44
+ const aclDoc = store.any(
45
+ store.sym(docURI),
46
+ ACL_LINK
47
+ )
48
+
49
+ return Promise.resolve()
50
+ .then(() => {
51
+ if (aclDoc) {
52
+ return aclDoc as NamedNode
59
53
  }
60
54
 
61
- return aclDoc
55
+ return fetchACLRel(docURI).catch(err => {
56
+ throw new Error(`Error fetching rel=ACL header for ${docURI}: ${err}`)
57
+ })
62
58
  })
63
- })
64
- }
59
+ .then(aclDoc => {
60
+ const aclText = genACLText(docURI, me, aclDoc.uri, options)
61
+ if (!store.fetcher) {
62
+ throw new Error('Cannot PUT this, store has no fetcher')
63
+ }
64
+ return store.fetcher
65
+ .webOperation('PUT', aclDoc.uri, {
66
+ data: aclText,
67
+ contentType: 'text/turtle'
68
+ })
69
+ .then(result => {
70
+ if (!result.ok) {
71
+ throw new Error('Error writing ACL text: ' + result.error)
72
+ }
65
73
 
66
- /**
67
- * @param docURI
68
- * @returns
69
- */
70
- function fetchACLRel (docURI: string): Promise<NamedNode> {
71
- const fetcher = solidLogicSingleton.store.fetcher
72
- if (!fetcher) {
73
- throw new Error('Cannot fetch ACL rel, store has no fetcher')
74
+ return aclDoc
75
+ })
76
+ })
74
77
  }
75
78
 
76
- return fetcher.load(docURI).then(result => {
77
- if (!result.ok) {
78
- throw new Error('fetchACLRel: While loading:' + (result as any).error)
79
+ /**
80
+ * @param docURI
81
+ * @returns
82
+ */
83
+ function fetchACLRel (docURI: string): Promise<NamedNode> {
84
+ const fetcher = store.fetcher
85
+ if (!fetcher) {
86
+ throw new Error('Cannot fetch ACL rel, store has no fetcher')
79
87
  }
80
88
 
81
- const aclDoc = solidLogicSingleton.store.any(
82
- solidLogicSingleton.store.sym(docURI),
83
- ACL_LINK
84
- )
89
+ return fetcher.load(docURI).then(result => {
90
+ if (!result.ok) {
91
+ throw new Error('fetchACLRel: While loading:' + (result as any).error)
92
+ }
85
93
 
86
- if (!aclDoc) {
87
- throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI)
88
- }
94
+ const aclDoc = store.any(
95
+ store.sym(docURI),
96
+ ACL_LINK
97
+ )
89
98
 
90
- return aclDoc as NamedNode
91
- })
92
- }
99
+ if (!aclDoc) {
100
+ throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI)
101
+ }
102
+
103
+ return aclDoc as NamedNode
104
+ })
105
+ }
93
106
 
94
- /**
95
- * @param docURI
96
- * @param me
97
- * @param aclURI
98
- * @param options
99
- *
100
- * @returns Serialized ACL
101
- */
102
- export function genACLText (
103
- docURI: string,
104
- me: NamedNode,
105
- aclURI: string,
106
- options: {
107
- defaultForNew?: boolean,
108
- public?: []
109
- } = {}
110
- ): string | undefined {
111
- const optPublic = options.public || []
112
- const g = graph()
113
- const auth = Namespace('http://www.w3.org/ns/auth/acl#')
114
- let a = g.sym(`${aclURI}#a1`)
115
- const acl = g.sym(aclURI)
116
- const doc = g.sym(docURI)
117
- g.add(a, ns.rdf('type'), auth('Authorization'), acl)
118
- g.add(a, auth('accessTo'), doc, acl)
119
- if (options.defaultForNew) {
120
- g.add(a, auth('default'), doc, acl)
121
- }
122
- g.add(a, auth('agent'), me, acl)
123
- g.add(a, auth('mode'), auth('Read'), acl)
124
- g.add(a, auth('mode'), auth('Write'), acl)
125
- g.add(a, auth('mode'), auth('Control'), acl)
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)
126
139
 
127
- if (optPublic.length) {
128
- a = g.sym(`${aclURI}#a2`)
129
- g.add(a, ns.rdf('type'), auth('Authorization'), acl)
130
- g.add(a, auth('accessTo'), doc, acl)
131
- g.add(a, auth('agentClass'), ns.foaf('Agent'), acl)
132
- for (let p = 0; p < optPublic.length; p++) {
133
- g.add(a, auth('mode'), auth(optPublic[p]), acl) // Like 'Read' etc
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
134
155
  }
135
- }
136
- return serialize(acl, g, aclURI)
137
- }
156
+ }