solid-ui 2.4.14-alpha → 2.4.14-bbf45639-aade069c

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 (257) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +0 -0
  3. package/lib/acl/access-controller.d.ts +0 -0
  4. package/lib/acl/access-controller.d.ts.map +0 -0
  5. package/lib/acl/access-controller.js +441 -334
  6. package/lib/acl/access-controller.js.map +1 -1
  7. package/lib/acl/access-groups.d.ts +1 -2
  8. package/lib/acl/access-groups.d.ts.map +1 -1
  9. package/lib/acl/access-groups.js +495 -347
  10. package/lib/acl/access-groups.js.map +1 -1
  11. package/lib/acl/acl-control.d.ts +0 -0
  12. package/lib/acl/acl-control.d.ts.map +0 -0
  13. package/lib/acl/acl-control.js +198 -168
  14. package/lib/acl/acl-control.js.map +1 -1
  15. package/lib/acl/acl.d.ts +1 -2
  16. package/lib/acl/acl.d.ts.map +1 -1
  17. package/lib/acl/acl.js +463 -444
  18. package/lib/acl/acl.js.map +1 -1
  19. package/lib/acl/add-agent-buttons.d.ts +0 -0
  20. package/lib/acl/add-agent-buttons.d.ts.map +0 -0
  21. package/lib/acl/add-agent-buttons.js +515 -318
  22. package/lib/acl/add-agent-buttons.js.map +1 -1
  23. package/lib/acl/index.d.ts +0 -0
  24. package/lib/acl/index.d.ts.map +0 -0
  25. package/lib/acl/index.js +35 -27
  26. package/lib/acl/index.js.map +1 -1
  27. package/lib/acl/styles.d.ts +0 -0
  28. package/lib/acl/styles.d.ts.map +0 -0
  29. package/lib/acl/styles.js +90 -84
  30. package/lib/acl/styles.js.map +1 -1
  31. package/lib/acl/types.d.ts +0 -0
  32. package/lib/acl/types.d.ts.map +0 -0
  33. package/lib/acl/types.js +4 -5
  34. package/lib/acl/types.js.map +1 -1
  35. package/lib/authn/authSession.d.ts +0 -0
  36. package/lib/authn/authSession.d.ts.map +0 -0
  37. package/lib/authn/authSession.js +21 -14
  38. package/lib/authn/authSession.js.map +1 -1
  39. package/lib/authn/authn.d.ts +0 -0
  40. package/lib/authn/authn.d.ts.map +0 -0
  41. package/lib/authn/authn.js +1935 -1391
  42. package/lib/authn/authn.js.map +1 -1
  43. package/lib/authn/config-default.js +0 -0
  44. package/lib/authn/config-default.js.map +0 -0
  45. package/lib/authn/index.d.ts +0 -0
  46. package/lib/authn/index.d.ts.map +0 -0
  47. package/lib/authn/index.js +37 -26
  48. package/lib/authn/index.js.map +1 -1
  49. package/lib/authn/signup.js +0 -0
  50. package/lib/authn/signup.js.map +0 -0
  51. package/lib/authn/types.d.ts +0 -0
  52. package/lib/authn/types.d.ts.map +0 -0
  53. package/lib/authn/types.js +4 -1
  54. package/lib/authn/types.js.map +1 -1
  55. package/lib/chat/bookmarks.js +0 -0
  56. package/lib/chat/bookmarks.js.map +0 -0
  57. package/lib/chat/dateFolder.js +0 -0
  58. package/lib/chat/dateFolder.js.map +0 -0
  59. package/lib/chat/infinite.js +0 -0
  60. package/lib/chat/infinite.js.map +0 -0
  61. package/lib/chat/message.js +0 -0
  62. package/lib/chat/message.js.map +0 -0
  63. package/lib/chat/messageTools.js +0 -0
  64. package/lib/chat/messageTools.js.map +0 -0
  65. package/lib/chat/thread.js +0 -0
  66. package/lib/chat/thread.js.map +0 -0
  67. package/lib/create/create.d.ts +0 -0
  68. package/lib/create/create.d.ts.map +0 -0
  69. package/lib/create/create.js +214 -209
  70. package/lib/create/create.js.map +1 -1
  71. package/lib/create/index.d.ts +0 -0
  72. package/lib/create/index.d.ts.map +0 -0
  73. package/lib/create/index.js +10 -4
  74. package/lib/create/index.js.map +1 -1
  75. package/lib/create/types.d.ts +0 -0
  76. package/lib/create/types.d.ts.map +0 -0
  77. package/lib/create/types.js +4 -1
  78. package/lib/create/types.js.map +1 -1
  79. package/lib/debug.d.ts +0 -0
  80. package/lib/debug.d.ts.map +0 -0
  81. package/lib/debug.js +28 -30
  82. package/lib/debug.js.map +1 -1
  83. package/lib/folders.js +0 -0
  84. package/lib/folders.js.map +0 -0
  85. package/lib/footer/index.d.ts +0 -0
  86. package/lib/footer/index.d.ts.map +0 -0
  87. package/lib/footer/index.js +126 -109
  88. package/lib/footer/index.js.map +1 -1
  89. package/lib/footer/styleMap.d.ts +0 -0
  90. package/lib/footer/styleMap.d.ts.map +0 -0
  91. package/lib/footer/styleMap.js +11 -7
  92. package/lib/footer/styleMap.js.map +1 -1
  93. package/lib/header/empty-profile.d.ts +0 -0
  94. package/lib/header/empty-profile.d.ts.map +0 -0
  95. package/lib/header/empty-profile.js +6 -2
  96. package/lib/header/empty-profile.js.map +1 -1
  97. package/lib/header/index.d.ts +0 -0
  98. package/lib/header/index.d.ts.map +0 -0
  99. package/lib/header/index.js +361 -285
  100. package/lib/header/index.js.map +1 -1
  101. package/lib/header/styleMap.d.ts +0 -0
  102. package/lib/header/styleMap.d.ts.map +0 -0
  103. package/lib/header/styleMap.js +132 -116
  104. package/lib/header/styleMap.js.map +1 -1
  105. package/lib/iconBase.d.ts +0 -0
  106. package/lib/iconBase.d.ts.map +0 -0
  107. package/lib/iconBase.js +30 -23
  108. package/lib/iconBase.js.map +1 -1
  109. package/lib/icons/solid_logo.d.ts +0 -0
  110. package/lib/icons/solid_logo.d.ts.map +0 -0
  111. package/lib/icons/solid_logo.js +0 -0
  112. package/lib/icons/solid_logo.js.map +1 -1
  113. package/lib/index.d.ts +1 -1
  114. package/lib/index.d.ts.map +1 -1
  115. package/lib/index.js +207 -103
  116. package/lib/index.js.map +1 -1
  117. package/lib/jss/index.d.ts +0 -0
  118. package/lib/jss/index.d.ts.map +0 -0
  119. package/lib/jss/index.js +30 -21
  120. package/lib/jss/index.js.map +1 -1
  121. package/lib/log.d.ts +0 -0
  122. package/lib/log.d.ts.map +0 -0
  123. package/lib/log.js +131 -83
  124. package/lib/log.js.map +1 -1
  125. package/lib/logic.d.ts +2 -2
  126. package/lib/logic.d.ts.map +1 -1
  127. package/lib/logic.js +73 -82
  128. package/lib/logic.js.map +1 -1
  129. package/lib/matrix/index.d.ts +0 -0
  130. package/lib/matrix/index.d.ts.map +0 -0
  131. package/lib/matrix/index.js +10 -4
  132. package/lib/matrix/index.js.map +1 -1
  133. package/lib/matrix/matrix.d.ts +0 -0
  134. package/lib/matrix/matrix.d.ts.map +0 -0
  135. package/lib/matrix/matrix.js +237 -210
  136. package/lib/matrix/matrix.js.map +1 -1
  137. package/lib/matrix/types.d.ts +0 -0
  138. package/lib/matrix/types.d.ts.map +0 -0
  139. package/lib/matrix/types.js +4 -1
  140. package/lib/matrix/types.js.map +1 -1
  141. package/lib/media/index.d.ts +0 -0
  142. package/lib/media/index.d.ts.map +0 -0
  143. package/lib/media/index.js +11 -5
  144. package/lib/media/index.js.map +1 -1
  145. package/lib/media/media-capture.d.ts +0 -0
  146. package/lib/media/media-capture.d.ts.map +0 -0
  147. package/lib/media/media-capture.js +181 -187
  148. package/lib/media/media-capture.js.map +1 -1
  149. package/lib/messageArea.js +0 -0
  150. package/lib/messageArea.js.map +0 -0
  151. package/lib/noun_Camera_1618446_000000.js +0 -0
  152. package/lib/noun_Camera_1618446_000000.js.map +0 -0
  153. package/lib/ns.js +0 -0
  154. package/lib/ns.js.map +0 -0
  155. package/lib/pad.d.ts +0 -0
  156. package/lib/pad.d.ts.map +0 -0
  157. package/lib/pad.js +954 -794
  158. package/lib/pad.js.map +1 -1
  159. package/lib/participation.d.ts +0 -0
  160. package/lib/participation.d.ts.map +0 -0
  161. package/lib/participation.js +199 -170
  162. package/lib/participation.js.map +1 -1
  163. package/lib/preferences.js +0 -0
  164. package/lib/preferences.js.map +0 -0
  165. package/lib/stories/decorators.js +0 -0
  166. package/lib/stories/decorators.js.map +0 -0
  167. package/lib/style.js +0 -0
  168. package/lib/style.js.map +0 -0
  169. package/lib/table.js +0 -0
  170. package/lib/table.js.map +0 -0
  171. package/lib/tabs.d.ts +0 -0
  172. package/lib/tabs.d.ts.map +0 -0
  173. package/lib/tabs.js +342 -235
  174. package/lib/tabs.js.map +1 -1
  175. package/lib/typings.d.js +0 -0
  176. package/lib/typings.d.js.map +0 -0
  177. package/lib/utils/headerFooterHelpers.d.ts +0 -0
  178. package/lib/utils/headerFooterHelpers.d.ts.map +0 -0
  179. package/lib/utils/headerFooterHelpers.js +155 -130
  180. package/lib/utils/headerFooterHelpers.js.map +1 -1
  181. package/lib/utils/index.js +0 -0
  182. package/lib/utils/index.js.map +0 -0
  183. package/lib/utils/label.d.ts +0 -0
  184. package/lib/utils/label.d.ts.map +0 -0
  185. package/lib/utils/label.js +113 -121
  186. package/lib/utils/label.js.map +1 -1
  187. package/lib/versionInfo.d.ts +0 -0
  188. package/lib/versionInfo.d.ts.map +0 -0
  189. package/lib/versionInfo.js +28 -23
  190. package/lib/versionInfo.js.map +1 -1
  191. package/lib/webpack-bundle.js +264 -175
  192. package/lib/webpack-bundle.js.map +1 -1
  193. package/lib/widgets/buttons/iconLinks.d.ts +0 -0
  194. package/lib/widgets/buttons/iconLinks.d.ts.map +0 -0
  195. package/lib/widgets/buttons/iconLinks.js +30 -19
  196. package/lib/widgets/buttons/iconLinks.js.map +1 -1
  197. package/lib/widgets/buttons.d.ts +0 -0
  198. package/lib/widgets/buttons.d.ts.map +0 -0
  199. package/lib/widgets/buttons.js +1113 -935
  200. package/lib/widgets/buttons.js.map +1 -1
  201. package/lib/widgets/dragAndDrop.js +0 -0
  202. package/lib/widgets/dragAndDrop.js.map +0 -0
  203. package/lib/widgets/error.d.ts +0 -0
  204. package/lib/widgets/error.d.ts.map +0 -0
  205. package/lib/widgets/error.js +24 -18
  206. package/lib/widgets/error.js.map +1 -1
  207. package/lib/widgets/forms/autocomplete/autocompleteBar.d.ts +0 -0
  208. package/lib/widgets/forms/autocomplete/autocompleteBar.d.ts.map +0 -0
  209. package/lib/widgets/forms/autocomplete/autocompleteBar.js +325 -234
  210. package/lib/widgets/forms/autocomplete/autocompleteBar.js.map +1 -1
  211. package/lib/widgets/forms/autocomplete/autocompleteField.d.ts +0 -0
  212. package/lib/widgets/forms/autocomplete/autocompleteField.d.ts.map +0 -0
  213. package/lib/widgets/forms/autocomplete/autocompleteField.js +280 -246
  214. package/lib/widgets/forms/autocomplete/autocompleteField.js.map +1 -1
  215. package/lib/widgets/forms/autocomplete/autocompletePicker.d.ts +0 -0
  216. package/lib/widgets/forms/autocomplete/autocompletePicker.d.ts.map +0 -0
  217. package/lib/widgets/forms/autocomplete/autocompletePicker.js +497 -317
  218. package/lib/widgets/forms/autocomplete/autocompletePicker.js.map +1 -1
  219. package/lib/widgets/forms/autocomplete/language.d.ts +0 -0
  220. package/lib/widgets/forms/autocomplete/language.d.ts.map +0 -0
  221. package/lib/widgets/forms/autocomplete/language.js +214 -159
  222. package/lib/widgets/forms/autocomplete/language.js.map +1 -1
  223. package/lib/widgets/forms/autocomplete/publicData.d.ts +0 -0
  224. package/lib/widgets/forms/autocomplete/publicData.d.ts.map +0 -0
  225. package/lib/widgets/forms/autocomplete/publicData.js +725 -485
  226. package/lib/widgets/forms/autocomplete/publicData.js.map +1 -1
  227. package/lib/widgets/forms/basic.d.ts +0 -0
  228. package/lib/widgets/forms/basic.d.ts.map +0 -0
  229. package/lib/widgets/forms/basic.js +239 -208
  230. package/lib/widgets/forms/basic.js.map +1 -1
  231. package/lib/widgets/forms/comment.d.ts +0 -0
  232. package/lib/widgets/forms/comment.d.ts.map +0 -0
  233. package/lib/widgets/forms/comment.js +48 -48
  234. package/lib/widgets/forms/comment.js.map +1 -1
  235. package/lib/widgets/forms/fieldFunction.d.ts +0 -0
  236. package/lib/widgets/forms/fieldFunction.d.ts.map +0 -0
  237. package/lib/widgets/forms/fieldFunction.js +50 -31
  238. package/lib/widgets/forms/fieldFunction.js.map +1 -1
  239. package/lib/widgets/forms/fieldParams.d.ts +0 -0
  240. package/lib/widgets/forms/fieldParams.d.ts.map +0 -0
  241. package/lib/widgets/forms/fieldParams.js +81 -102
  242. package/lib/widgets/forms/fieldParams.js.map +1 -1
  243. package/lib/widgets/forms/formStyle.d.ts +0 -0
  244. package/lib/widgets/forms/formStyle.d.ts.map +0 -0
  245. package/lib/widgets/forms/formStyle.js +50 -52
  246. package/lib/widgets/forms/formStyle.js.map +1 -1
  247. package/lib/widgets/forms.js +0 -0
  248. package/lib/widgets/forms.js.map +0 -0
  249. package/lib/widgets/index.js +0 -0
  250. package/lib/widgets/index.js.map +0 -0
  251. package/lib/widgets/peoplePicker.js +0 -0
  252. package/lib/widgets/peoplePicker.js.map +0 -0
  253. package/lib/widgets/widgetHelpers.d.ts +0 -0
  254. package/lib/widgets/widgetHelpers.d.ts.map +0 -0
  255. package/lib/widgets/widgetHelpers.js +30 -18
  256. package/lib/widgets/widgetHelpers.js.map +1 -1
  257. package/package.json +7 -7
@@ -1,73 +1,65 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
13
9
  });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- 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;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
58
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
59
- if (ar || !(i in from)) {
60
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
61
- ar[i] = from[i];
62
- }
63
- }
64
- return to.concat(ar || Array.prototype.slice.call(from));
65
- };
66
- var __importDefault = (this && this.__importDefault) || function (mod) {
67
- return (mod && mod.__esModule) ? mod : { "default": mod };
68
- };
69
- Object.defineProperty(exports, "__esModule", { value: true });
70
- exports.filterAvailablePanes = exports.getUserRoles = exports.newAppInstance = exports.selectWorkspace = exports.loginStatusBox = exports.checkUser = exports.renderSignInPopup = exports.offlineTestID = exports.setACLUserPublic = exports.registrationList = exports.registrationControl = exports.registerInTypeIndex = exports.findAppInstances = exports.loadTypeIndexes = exports.logInLoadPreferences = exports.logInLoadProfile = exports.logIn = exports.currentUser = exports.defaultTestUser = exports.saveUser = exports.findOriginOwner = exports.authSession = void 0;
10
+ exports.authSession = void 0;
11
+ exports.checkUser = checkUser;
12
+ exports.currentUser = currentUser;
13
+ exports.defaultTestUser = defaultTestUser;
14
+ exports.filterAvailablePanes = filterAvailablePanes;
15
+ exports.findAppInstances = findAppInstances;
16
+ exports.findOriginOwner = findOriginOwner;
17
+ exports.getUserRoles = getUserRoles;
18
+ exports.loadTypeIndexes = loadTypeIndexes;
19
+ exports.logIn = logIn;
20
+ exports.logInLoadPreferences = logInLoadPreferences;
21
+ exports.logInLoadProfile = logInLoadProfile;
22
+ exports.loginStatusBox = loginStatusBox;
23
+ exports.newAppInstance = newAppInstance;
24
+ exports.offlineTestID = offlineTestID;
25
+ exports.registerInTypeIndex = registerInTypeIndex;
26
+ exports.registrationControl = registrationControl;
27
+ exports.registrationList = registrationList;
28
+ exports.renderSignInPopup = renderSignInPopup;
29
+ exports.saveUser = saveUser;
30
+ exports.selectWorkspace = selectWorkspace;
31
+ exports.setACLUserPublic = setACLUserPublic;
32
+
33
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
34
+
35
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
36
+
37
+ var _rdflib = require("rdflib");
38
+
39
+ var _signup = require("./signup");
40
+
41
+ var widgets = _interopRequireWildcard(require("../widgets"));
42
+
43
+ var ns = _interopRequireWildcard(require("../ns.js"));
44
+
45
+ var utils = _interopRequireWildcard(require("../utils"));
46
+
47
+ var _log = require("../log");
48
+
49
+ var _authSession = _interopRequireDefault(require("./authSession"));
50
+
51
+ var debug = _interopRequireWildcard(require("../debug"));
52
+
53
+ var _style = require("../style");
54
+
55
+ var _logic = require("../logic");
56
+
57
+ var _solidLogic = require("solid-logic");
58
+
59
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
60
+
61
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
62
+
71
63
  /**
72
64
  * Signing in, signing up, profile and preferences reloading
73
65
  * Type index management
@@ -89,53 +81,38 @@ exports.filterAvailablePanes = exports.getUserRoles = exports.newAppInstance = e
89
81
  * * `statusArea` A DOM element (opt) progress stuff can be displayed, or error messages
90
82
  * @packageDocumentation
91
83
  */
92
- var rdflib_1 = require("rdflib");
93
- var signup_1 = require("./signup");
94
- var widgets = __importStar(require("../widgets"));
95
- var ns = __importStar(require("../ns.js"));
96
- var utils = __importStar(require("../utils"));
97
- var log_1 = require("../log");
98
- var authSession_1 = __importDefault(require("./authSession"));
99
- var debug = __importStar(require("../debug"));
100
- var style_1 = require("../style");
101
- var logic_1 = require("../logic");
102
- var solid_logic_1 = require("solid-logic");
84
+
103
85
  /* global confirm */
104
- exports.authSession = authSession_1.default;
105
- var DEFAULT_ISSUERS = [
106
- {
107
- name: 'Solid Community',
108
- uri: 'https://solidcommunity.net'
109
- },
110
- {
111
- name: 'Solid Web',
112
- uri: 'https://solidweb.org'
113
- },
114
- {
115
- name: 'Inrupt.net',
116
- uri: 'https://inrupt.net'
117
- },
118
- {
119
- name: 'pod.Inrupt.com',
120
- uri: 'https://broker.pod.inrupt.com'
121
- }
122
- ];
123
- // const userCheckSite = 'https://databox.me/'
86
+ var authSession = _authSession["default"];
87
+ exports.authSession = authSession;
88
+ var DEFAULT_ISSUERS = [{
89
+ name: 'Solid Community',
90
+ uri: 'https://solidcommunity.net'
91
+ }, {
92
+ name: 'Solid Web',
93
+ uri: 'https://solidweb.org'
94
+ }, {
95
+ name: 'Inrupt.net',
96
+ uri: 'https://inrupt.net'
97
+ }, {
98
+ name: 'pod.Inrupt.com',
99
+ uri: 'https://broker.pod.inrupt.com'
100
+ }]; // const userCheckSite = 'https://databox.me/'
101
+
124
102
  /**
125
103
  * Look for and load the User who has control over it
126
104
  */
105
+
127
106
  function findOriginOwner(doc) {
128
- var uri = (typeof doc === 'string') ? doc : doc.uri;
129
- var i = uri.indexOf('://');
130
- if (i < 0)
131
- return false;
132
- var j = uri.indexOf('/', i + 3);
133
- if (j < 0)
134
- return false;
135
- var origin = uri.slice(0, j + 1); // @@ TBC
136
- return origin;
107
+ var uri = typeof doc === 'string' ? doc : doc.uri;
108
+ var i = uri.indexOf('://');
109
+ if (i < 0) return false;
110
+ var j = uri.indexOf('/', i + 3);
111
+ if (j < 0) return false;
112
+ var origin = uri.slice(0, j + 1); // @@ TBC
113
+
114
+ return origin;
137
115
  }
138
- exports.findOriginOwner = findOriginOwner;
139
116
  /**
140
117
  * Saves `webId` in `context.me`
141
118
  * @param webId
@@ -143,110 +120,136 @@ exports.findOriginOwner = findOriginOwner;
143
120
  *
144
121
  * @returns Returns the WebID, after setting it
145
122
  */
123
+
124
+
146
125
  function saveUser(webId, context) {
147
- // @@ TODO Remove the need for having context as output argument
148
- var webIdUri;
149
- if (webId) {
150
- webIdUri = (typeof webId === 'string') ? webId : webId.uri;
151
- var me = (0, rdflib_1.namedNode)(webIdUri);
152
- if (context) {
153
- context.me = me;
154
- }
155
- return me;
126
+ // @@ TODO Remove the need for having context as output argument
127
+ var webIdUri;
128
+
129
+ if (webId) {
130
+ webIdUri = typeof webId === 'string' ? webId : webId.uri;
131
+ var me = (0, _rdflib.namedNode)(webIdUri);
132
+
133
+ if (context) {
134
+ context.me = me;
156
135
  }
157
- return null;
136
+
137
+ return me;
138
+ }
139
+
140
+ return null;
158
141
  }
159
- exports.saveUser = saveUser;
160
142
  /**
161
143
  * Wrapper around [[offlineTestID]]
162
144
  * @returns {NamedNode|null}
163
145
  */
146
+
147
+
164
148
  function defaultTestUser() {
165
- // Check for offline override
166
- var offlineId = offlineTestID();
167
- if (offlineId) {
168
- return offlineId;
169
- }
170
- return null;
149
+ // Check for offline override
150
+ var offlineId = offlineTestID();
151
+
152
+ if (offlineId) {
153
+ return offlineId;
154
+ }
155
+
156
+ return null;
171
157
  }
172
- exports.defaultTestUser = defaultTestUser;
173
158
  /**
174
159
  * find a user or app's context as set in window.SolidAppContext
175
160
  * @return {any} - an appContext object
176
161
  */
162
+
163
+
177
164
  function appContext() {
178
- var SolidAppContext = window.SolidAppContext;
179
- SolidAppContext || (SolidAppContext = {});
180
- SolidAppContext.viewingNoAuthPage = false;
181
- if (SolidAppContext.noAuth && window.document) {
182
- var currentPage = window.document.location.href;
183
- if (currentPage.startsWith(SolidAppContext.noAuth)) {
184
- SolidAppContext.viewingNoAuthPage = true;
185
- var params = new URLSearchParams(window.document.location.search);
186
- if (params) {
187
- var viewedPage = SolidAppContext.viewedPage = params.get('uri') || null;
188
- if (viewedPage) {
189
- viewedPage = decodeURI(viewedPage);
190
- if (!viewedPage.startsWith(SolidAppContext.noAuth)) {
191
- var ary = viewedPage.split(/\//);
192
- SolidAppContext.idp = ary[0] + '//' + ary[2];
193
- SolidAppContext.viewingNoAuthPage = false;
194
- }
195
- }
196
- }
165
+ var _window = window,
166
+ SolidAppContext = _window.SolidAppContext;
167
+ SolidAppContext || (SolidAppContext = {});
168
+ SolidAppContext.viewingNoAuthPage = false;
169
+
170
+ if (SolidAppContext.noAuth && window.document) {
171
+ var currentPage = window.document.location.href;
172
+
173
+ if (currentPage.startsWith(SolidAppContext.noAuth)) {
174
+ SolidAppContext.viewingNoAuthPage = true;
175
+ var params = new URLSearchParams(window.document.location.search);
176
+
177
+ if (params) {
178
+ var viewedPage = SolidAppContext.viewedPage = params.get('uri') || null;
179
+
180
+ if (viewedPage) {
181
+ viewedPage = decodeURI(viewedPage);
182
+
183
+ if (!viewedPage.startsWith(SolidAppContext.noAuth)) {
184
+ var ary = viewedPage.split(/\//);
185
+ SolidAppContext.idp = ary[0] + '//' + ary[2];
186
+ SolidAppContext.viewingNoAuthPage = false;
187
+ }
197
188
  }
189
+ }
198
190
  }
199
- return SolidAppContext;
191
+ }
192
+
193
+ return SolidAppContext;
200
194
  }
201
195
  /**
202
196
  * Checks synchronously whether user is logged in
203
197
  *
204
198
  * @returns Named Node or null
205
199
  */
200
+
201
+
206
202
  function currentUser() {
207
- var app = appContext();
208
- if (app.viewingNoAuthPage) {
209
- return (0, rdflib_1.sym)(app.webId);
210
- }
211
- if (exports.authSession.info.webId && exports.authSession.info.isLoggedIn) {
212
- return (0, rdflib_1.sym)(exports.authSession.info.webId);
213
- }
214
- return offlineTestID(); // null unless testing
215
- // JSON.parse(localStorage['solid-auth-client']).session.webId
203
+ var app = appContext();
204
+
205
+ if (app.viewingNoAuthPage) {
206
+ return (0, _rdflib.sym)(app.webId);
207
+ }
208
+
209
+ if (authSession.info.webId && authSession.info.isLoggedIn) {
210
+ return (0, _rdflib.sym)(authSession.info.webId);
211
+ }
212
+
213
+ return offlineTestID(); // null unless testing
214
+ // JSON.parse(localStorage['solid-auth-client']).session.webId
216
215
  }
217
- exports.currentUser = currentUser;
218
216
  /**
219
217
  * Resolves with the logged in user's WebID
220
218
  *
221
219
  * @param context
222
220
  */
221
+
222
+
223
223
  function logIn(context) {
224
- var app = appContext();
225
- var me = app.viewingNoAuthPage ? (0, rdflib_1.sym)(app.webId) : defaultTestUser(); // me is a NamedNode or null
226
- if (me) {
227
- context.me = me;
228
- return Promise.resolve(context);
229
- }
230
- return new Promise(function (resolve) {
231
- checkUser().then(function (webId) {
232
- // Already logged in?
233
- if (webId) {
234
- context.me = (0, rdflib_1.sym)(webId);
235
- debug.log("logIn: Already logged in as ".concat(context.me));
236
- return resolve(context);
237
- }
238
- if (!context.div || !context.dom) {
239
- return resolve(context);
240
- }
241
- var box = loginStatusBox(context.dom, function (webIdUri) {
242
- saveUser(webIdUri, context);
243
- resolve(context); // always pass growing context
244
- });
245
- context.div.appendChild(box);
246
- });
224
+ var app = appContext();
225
+ var me = app.viewingNoAuthPage ? (0, _rdflib.sym)(app.webId) : defaultTestUser(); // me is a NamedNode or null
226
+
227
+ if (me) {
228
+ context.me = me;
229
+ return Promise.resolve(context);
230
+ }
231
+
232
+ return new Promise(function (resolve) {
233
+ checkUser().then(function (webId) {
234
+ // Already logged in?
235
+ if (webId) {
236
+ context.me = (0, _rdflib.sym)(webId);
237
+ debug.log("logIn: Already logged in as ".concat(context.me));
238
+ return resolve(context);
239
+ }
240
+
241
+ if (!context.div || !context.dom) {
242
+ return resolve(context);
243
+ }
244
+
245
+ var box = loginStatusBox(context.dom, function (webIdUri) {
246
+ saveUser(webIdUri, context);
247
+ resolve(context); // always pass growing context
248
+ });
249
+ context.div.appendChild(box);
247
250
  });
251
+ });
248
252
  }
249
- exports.logIn = logIn;
250
253
  /**
251
254
  * Logs the user in and loads their WebID profile document into the store
252
255
  *
@@ -254,42 +257,11 @@ exports.logIn = logIn;
254
257
  *
255
258
  * @returns Resolves with the context after login / fetch
256
259
  */
257
- function logInLoadProfile(context) {
258
- return __awaiter(this, void 0, void 0, function () {
259
- var loggedInContext, _a, err_1;
260
- return __generator(this, function (_b) {
261
- switch (_b.label) {
262
- case 0:
263
- // console.log('Solid UI logInLoadProfile')
264
- if (context.publicProfile) {
265
- return [2 /*return*/, context];
266
- } // already done
267
- _b.label = 1;
268
- case 1:
269
- _b.trys.push([1, 4, , 5]);
270
- return [4 /*yield*/, logIn(context)];
271
- case 2:
272
- loggedInContext = _b.sent();
273
- if (!loggedInContext.me) {
274
- throw new Error('Could not log in');
275
- }
276
- _a = context;
277
- return [4 /*yield*/, logic_1.solidLogicSingleton.loadProfile(loggedInContext.me)];
278
- case 3:
279
- _a.publicProfile = _b.sent();
280
- return [3 /*break*/, 5];
281
- case 4:
282
- err_1 = _b.sent();
283
- if (context.div && context.dom) {
284
- context.div.appendChild(widgets.errorMessageBlock(context.dom, err_1.message));
285
- }
286
- throw new Error("Can't log in: ".concat(err_1));
287
- case 5: return [2 /*return*/, context];
288
- }
289
- });
290
- });
260
+
261
+
262
+ function logInLoadProfile(_x2) {
263
+ return _logInLoadProfile.apply(this, arguments);
291
264
  }
292
- exports.logInLoadProfile = logInLoadProfile;
293
265
  /**
294
266
  * Loads preference file
295
267
  * Do this after having done log in and load profile
@@ -298,144 +270,321 @@ exports.logInLoadProfile = logInLoadProfile;
298
270
  *
299
271
  * @param context
300
272
  */
301
- function logInLoadPreferences(context) {
302
- return __awaiter(this, void 0, void 0, function () {
303
- function complain(message) {
304
- message = "logInLoadPreferences: ".concat(message);
305
- if (statusArea) {
306
- // statusArea.innerHTML = ''
307
- statusArea.appendChild(widgets.errorMessageBlock(context.dom, message));
273
+
274
+
275
+ function _logInLoadProfile() {
276
+ _logInLoadProfile = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(context) {
277
+ var loggedInContext;
278
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
279
+ while (1) {
280
+ switch (_context4.prev = _context4.next) {
281
+ case 0:
282
+ if (!context.publicProfile) {
283
+ _context4.next = 2;
284
+ break;
308
285
  }
309
- debug.log(message);
310
- // reject(new Error(message))
311
- }
312
- var statusArea, progressDisplay, preferencesFile, err_2, m2;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0:
316
- // console.log('Solid UI logInLoadPreferences')
317
- if (context.preferencesFile)
318
- return [2 /*return*/, Promise.resolve(context)]; // already done
319
- statusArea = context.statusArea || context.div || null;
320
- _a.label = 1;
321
- case 1:
322
- _a.trys.push([1, 4, , 5]);
323
- return [4 /*yield*/, logInLoadProfile(context)
324
- // console.log('back in Solid UI after logInLoadProfile', context)
325
- ];
326
- case 2:
327
- context = _a.sent();
328
- return [4 /*yield*/, logic_1.solidLogicSingleton.loadPreferences(context.me)];
329
- case 3:
330
- preferencesFile = _a.sent();
331
- if (progressDisplay) {
332
- progressDisplay.parentNode.removeChild(progressDisplay);
333
- }
334
- context.preferencesFile = preferencesFile;
335
- return [3 /*break*/, 5];
336
- case 4:
337
- err_2 = _a.sent();
338
- m2 = void 0;
339
- if (err_2 instanceof solid_logic_1.UnauthorizedError) {
340
- m2 = 'Ooops - you are not authenticated (properly logged in) to for me to read your preference file. Try loggin out and logging in?';
341
- (0, log_1.alert)(m2);
342
- }
343
- else if (err_2 instanceof solid_logic_1.CrossOriginForbiddenError) {
344
- m2 = "Unauthorized: Assuming preference file blocked for origin ".concat(window.location.origin);
345
- context.preferencesFileError = m2;
346
- return [2 /*return*/, context];
347
- }
348
- else if (err_2 instanceof solid_logic_1.SameOriginForbiddenError) {
349
- m2 = 'You are not authorized to read your preference file. This may be because you are using an untrusted web app.';
350
- debug.warn(m2);
351
- }
352
- else if (err_2 instanceof solid_logic_1.NotFoundError) {
353
- if (confirm("You do not currently have a preference file. OK for me to create an empty one? ".concat(err_2.preferencesFile || ''))) {
354
- // @@@ code me ... weird to have a name of the file but no file
355
- (0, log_1.alert)("Sorry; I am not prepared to do this. Please create an empty file at ".concat(err_2.preferencesFile || '(?)'));
356
- complain(new Error('Sorry; no code yet to create a preference file at '));
357
- }
358
- else {
359
- throw (new Error("User declined to create a preference file at ".concat(err_2.preferencesFile || '(?)')));
360
- }
361
- }
362
- else if (err_2 instanceof solid_logic_1.FetchError) {
363
- m2 = "Strange: Error ".concat(err_2.status, " trying to read your preference file.").concat(err_2.message);
364
- (0, log_1.alert)(m2);
365
- }
366
- else {
367
- throw new Error("(via loadPrefs) ".concat(err_2));
368
- }
369
- return [3 /*break*/, 5];
370
- case 5: return [2 /*return*/, context];
286
+
287
+ return _context4.abrupt("return", context);
288
+
289
+ case 2:
290
+ _context4.prev = 2;
291
+ _context4.next = 5;
292
+ return logIn(context);
293
+
294
+ case 5:
295
+ loggedInContext = _context4.sent;
296
+
297
+ if (loggedInContext.me) {
298
+ _context4.next = 8;
299
+ break;
371
300
  }
372
- });
373
- });
301
+
302
+ throw new Error('Could not log in');
303
+
304
+ case 8:
305
+ _context4.next = 10;
306
+ return _logic.solidLogicSingleton.loadProfile(loggedInContext.me);
307
+
308
+ case 10:
309
+ context.publicProfile = _context4.sent;
310
+ _context4.next = 17;
311
+ break;
312
+
313
+ case 13:
314
+ _context4.prev = 13;
315
+ _context4.t0 = _context4["catch"](2);
316
+
317
+ if (context.div && context.dom) {
318
+ context.div.appendChild(widgets.errorMessageBlock(context.dom, _context4.t0.message));
319
+ }
320
+
321
+ throw new Error("Can't log in: ".concat(_context4.t0));
322
+
323
+ case 17:
324
+ return _context4.abrupt("return", context);
325
+
326
+ case 18:
327
+ case "end":
328
+ return _context4.stop();
329
+ }
330
+ }
331
+ }, _callee4, null, [[2, 13]]);
332
+ }));
333
+ return _logInLoadProfile.apply(this, arguments);
334
+ }
335
+
336
+ function logInLoadPreferences(_x3) {
337
+ return _logInLoadPreferences.apply(this, arguments);
374
338
  }
375
- exports.logInLoadPreferences = logInLoadPreferences;
376
339
  /**
377
340
  * Resolves with the same context, outputting
378
341
  * output: index.public, index.private
379
342
  *
380
343
  * @see https://github.com/solid/solid/blob/main/proposals/data-discovery.md#discoverability
381
344
  */
382
- function loadIndex(context, isPublic) {
383
- return __awaiter(this, void 0, void 0, function () {
384
- var indexes;
385
- var _this = this;
386
- return __generator(this, function (_a) {
387
- switch (_a.label) {
388
- case 0: return [4 /*yield*/, logic_1.solidLogicSingleton.loadIndexes(context.me, (isPublic ? context.publicProfile || null : null), (isPublic ? null : context.preferencesFile || null), function (err) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
389
- return [2 /*return*/, widgets.complain(context, err.message)];
390
- }); }); })];
391
- case 1:
392
- indexes = _a.sent();
393
- context.index = context.index || {};
394
- context.index.private = indexes.private || context.index.private;
395
- context.index.public = indexes.public || context.index.public;
396
- return [2 /*return*/, context];
345
+
346
+
347
+ function _logInLoadPreferences() {
348
+ _logInLoadPreferences = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(context) {
349
+ var statusArea, progressDisplay, complain, preferencesFile, m2;
350
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
351
+ while (1) {
352
+ switch (_context5.prev = _context5.next) {
353
+ case 0:
354
+ complain = function _complain(message) {
355
+ message = "logInLoadPreferences: ".concat(message);
356
+
357
+ if (statusArea) {
358
+ // statusArea.innerHTML = ''
359
+ statusArea.appendChild(widgets.errorMessageBlock(context.dom, message));
360
+ }
361
+
362
+ debug.log(message); // reject(new Error(message))
363
+ };
364
+
365
+ if (!context.preferencesFile) {
366
+ _context5.next = 3;
367
+ break;
397
368
  }
398
- });
399
- });
400
- }
401
- function loadTypeIndexes(context) {
402
- return __awaiter(this, void 0, void 0, function () {
403
- var indexes;
404
- var _this = this;
405
- return __generator(this, function (_a) {
406
- switch (_a.label) {
407
- case 0: return [4 /*yield*/, logic_1.solidLogicSingleton.loadIndexes(context.me, context.publicProfile || null, context.preferencesFile || null, function (err) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
408
- return [2 /*return*/, widgets.complain(context, err.message)];
409
- }); }); })];
410
- case 1:
411
- indexes = _a.sent();
412
- context.index = context.index || {};
413
- context.index.private = indexes.private || context.index.private;
414
- context.index.public = indexes.public || context.index.public;
415
- return [2 /*return*/, context];
369
+
370
+ return _context5.abrupt("return", Promise.resolve(context));
371
+
372
+ case 3:
373
+ // already done
374
+ statusArea = context.statusArea || context.div || null;
375
+ _context5.prev = 4;
376
+ _context5.next = 7;
377
+ return logInLoadProfile(context);
378
+
379
+ case 7:
380
+ context = _context5.sent;
381
+ _context5.next = 10;
382
+ return _logic.solidLogicSingleton.loadPreferences(context.me);
383
+
384
+ case 10:
385
+ preferencesFile = _context5.sent;
386
+
387
+ if (progressDisplay) {
388
+ progressDisplay.parentNode.removeChild(progressDisplay);
416
389
  }
417
- });
418
- });
390
+
391
+ context.preferencesFile = preferencesFile;
392
+ _context5.next = 48;
393
+ break;
394
+
395
+ case 15:
396
+ _context5.prev = 15;
397
+ _context5.t0 = _context5["catch"](4);
398
+
399
+ if (!(_context5.t0 instanceof _solidLogic.UnauthorizedError)) {
400
+ _context5.next = 22;
401
+ break;
402
+ }
403
+
404
+ m2 = 'Ooops - you are not authenticated (properly logged in) to for me to read your preference file. Try loggin out and logging in?';
405
+ (0, _log.alert)(m2);
406
+ _context5.next = 48;
407
+ break;
408
+
409
+ case 22:
410
+ if (!(_context5.t0 instanceof _solidLogic.CrossOriginForbiddenError)) {
411
+ _context5.next = 28;
412
+ break;
413
+ }
414
+
415
+ m2 = "Unauthorized: Assuming preference file blocked for origin ".concat(window.location.origin);
416
+ context.preferencesFileError = m2;
417
+ return _context5.abrupt("return", context);
418
+
419
+ case 28:
420
+ if (!(_context5.t0 instanceof _solidLogic.SameOriginForbiddenError)) {
421
+ _context5.next = 33;
422
+ break;
423
+ }
424
+
425
+ m2 = 'You are not authorized to read your preference file. This may be because you are using an untrusted web app.';
426
+ debug.warn(m2);
427
+ _context5.next = 48;
428
+ break;
429
+
430
+ case 33:
431
+ if (!(_context5.t0 instanceof _solidLogic.NotFoundError)) {
432
+ _context5.next = 42;
433
+ break;
434
+ }
435
+
436
+ if (!confirm("You do not currently have a preference file. OK for me to create an empty one? ".concat(_context5.t0.preferencesFile || ''))) {
437
+ _context5.next = 39;
438
+ break;
439
+ }
440
+
441
+ // @@@ code me ... weird to have a name of the file but no file
442
+ (0, _log.alert)("Sorry; I am not prepared to do this. Please create an empty file at ".concat(_context5.t0.preferencesFile || '(?)'));
443
+ complain(new Error('Sorry; no code yet to create a preference file at '));
444
+ _context5.next = 40;
445
+ break;
446
+
447
+ case 39:
448
+ throw new Error("User declined to create a preference file at ".concat(_context5.t0.preferencesFile || '(?)'));
449
+
450
+ case 40:
451
+ _context5.next = 48;
452
+ break;
453
+
454
+ case 42:
455
+ if (!(_context5.t0 instanceof _solidLogic.FetchError)) {
456
+ _context5.next = 47;
457
+ break;
458
+ }
459
+
460
+ m2 = "Strange: Error ".concat(_context5.t0.status, " trying to read your preference file.").concat(_context5.t0.message);
461
+ (0, _log.alert)(m2);
462
+ _context5.next = 48;
463
+ break;
464
+
465
+ case 47:
466
+ throw new Error("(via loadPrefs) ".concat(_context5.t0));
467
+
468
+ case 48:
469
+ return _context5.abrupt("return", context);
470
+
471
+ case 49:
472
+ case "end":
473
+ return _context5.stop();
474
+ }
475
+ }
476
+ }, _callee5, null, [[4, 15]]);
477
+ }));
478
+ return _logInLoadPreferences.apply(this, arguments);
479
+ }
480
+
481
+ function loadIndex(_x4, _x5) {
482
+ return _loadIndex.apply(this, arguments);
483
+ }
484
+
485
+ function _loadIndex() {
486
+ _loadIndex = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(context, isPublic) {
487
+ var indexes;
488
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
489
+ while (1) {
490
+ switch (_context7.prev = _context7.next) {
491
+ case 0:
492
+ _context7.next = 2;
493
+ return _logic.solidLogicSingleton.loadIndexes(context.me, isPublic ? context.publicProfile || null : null, isPublic ? null : context.preferencesFile || null, /*#__PURE__*/function () {
494
+ var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(err) {
495
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
496
+ while (1) {
497
+ switch (_context6.prev = _context6.next) {
498
+ case 0:
499
+ return _context6.abrupt("return", widgets.complain(context, err.message));
500
+
501
+ case 1:
502
+ case "end":
503
+ return _context6.stop();
504
+ }
505
+ }
506
+ }, _callee6);
507
+ }));
508
+
509
+ return function (_x21) {
510
+ return _ref4.apply(this, arguments);
511
+ };
512
+ }());
513
+
514
+ case 2:
515
+ indexes = _context7.sent;
516
+ context.index = context.index || {};
517
+ context.index["private"] = indexes["private"] || context.index["private"];
518
+ context.index["public"] = indexes["public"] || context.index["public"];
519
+ return _context7.abrupt("return", context);
520
+
521
+ case 7:
522
+ case "end":
523
+ return _context7.stop();
524
+ }
525
+ }
526
+ }, _callee7);
527
+ }));
528
+ return _loadIndex.apply(this, arguments);
529
+ }
530
+
531
+ function loadTypeIndexes(_x6) {
532
+ return _loadTypeIndexes.apply(this, arguments);
419
533
  }
420
- exports.loadTypeIndexes = loadTypeIndexes;
421
534
  /**
422
535
  * Resolves with the same context, outputting
423
536
  * @see https://github.com/solid/solid/blob/main/proposals/data-discovery.md#discoverability
424
537
  */
425
- function ensureTypeIndexes(context) {
426
- return __awaiter(this, void 0, void 0, function () {
427
- return __generator(this, function (_a) {
428
- switch (_a.label) {
429
- case 0: return [4 /*yield*/, ensureOneTypeIndex(context, true)];
430
- case 1:
431
- _a.sent();
432
- return [4 /*yield*/, ensureOneTypeIndex(context, false)];
433
- case 2:
434
- _a.sent();
435
- return [2 /*return*/, context];
436
- }
437
- });
438
- });
538
+
539
+
540
+ function _loadTypeIndexes() {
541
+ _loadTypeIndexes = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(context) {
542
+ var indexes;
543
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
544
+ while (1) {
545
+ switch (_context9.prev = _context9.next) {
546
+ case 0:
547
+ _context9.next = 2;
548
+ return _logic.solidLogicSingleton.loadIndexes(context.me, context.publicProfile || null, context.preferencesFile || null, /*#__PURE__*/function () {
549
+ var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(err) {
550
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
551
+ while (1) {
552
+ switch (_context8.prev = _context8.next) {
553
+ case 0:
554
+ return _context8.abrupt("return", widgets.complain(context, err.message));
555
+
556
+ case 1:
557
+ case "end":
558
+ return _context8.stop();
559
+ }
560
+ }
561
+ }, _callee8);
562
+ }));
563
+
564
+ return function (_x22) {
565
+ return _ref5.apply(this, arguments);
566
+ };
567
+ }());
568
+
569
+ case 2:
570
+ indexes = _context9.sent;
571
+ context.index = context.index || {};
572
+ context.index["private"] = indexes["private"] || context.index["private"];
573
+ context.index["public"] = indexes["public"] || context.index["public"];
574
+ return _context9.abrupt("return", context);
575
+
576
+ case 7:
577
+ case "end":
578
+ return _context9.stop();
579
+ }
580
+ }
581
+ }, _callee9);
582
+ }));
583
+ return _loadTypeIndexes.apply(this, arguments);
584
+ }
585
+
586
+ function ensureTypeIndexes(_x7) {
587
+ return _ensureTypeIndexes.apply(this, arguments);
439
588
  }
440
589
  /**
441
590
  * Load or create ONE type index
@@ -445,112 +594,36 @@ function ensureTypeIndexes(context) {
445
594
  * Adds its output to the context
446
595
  * @see https://github.com/solid/solid/blob/main/proposals/data-discovery.md#discoverability
447
596
  */
448
- function ensureOneTypeIndex(context, isPublic) {
449
- return __awaiter(this, void 0, void 0, function () {
450
- function makeIndexIfNecessary(context, isPublic) {
451
- return __awaiter(this, void 0, void 0, function () {
452
- function putIndex(newIndex) {
453
- return __awaiter(this, void 0, void 0, function () {
454
- var e_1, msg;
455
- return __generator(this, function (_a) {
456
- switch (_a.label) {
457
- case 0:
458
- _a.trys.push([0, 2, , 3]);
459
- return [4 /*yield*/, logic_1.solidLogicSingleton.createEmptyRdfDoc(newIndex, 'Blank initial Type index')];
460
- case 1:
461
- _a.sent();
462
- return [2 /*return*/, context];
463
- case 2:
464
- e_1 = _a.sent();
465
- msg = "Error creating new index ".concat(e_1);
466
- widgets.complain(context, msg);
467
- return [3 /*break*/, 3];
468
- case 3: return [2 /*return*/];
469
- }
470
- });
471
- });
472
- } // putIndex
473
- var relevant, visibility, newIndex, addMe, err_3, msg, ixs, err_4;
474
- return __generator(this, function (_a) {
475
- switch (_a.label) {
476
- case 0:
477
- relevant = isPublic ? context.publicProfile : context.preferencesFile;
478
- visibility = isPublic ? 'public' : 'private';
479
- context.index = context.index || {};
480
- context.index[visibility] = context.index[visibility] || [];
481
- if (!(context.index[visibility].length === 0)) return [3 /*break*/, 6];
482
- newIndex = (0, rdflib_1.sym)("".concat(relevant.dir().uri + visibility, "TypeIndex.ttl"));
483
- debug.log("Linking to new fresh type index ".concat(newIndex));
484
- if (!confirm("OK to create a new empty index file at ".concat(newIndex, ", overwriting anything that is now there?"))) {
485
- throw new Error('cancelled by user');
486
- }
487
- debug.log("Linking to new fresh type index ".concat(newIndex));
488
- addMe = [
489
- (0, rdflib_1.st)(context.me, ns.solid("".concat(visibility, "TypeIndex")), newIndex, relevant)
490
- ];
491
- _a.label = 1;
492
- case 1:
493
- _a.trys.push([1, 3, , 4]);
494
- return [4 /*yield*/, logic_1.solidLogicSingleton.updatePromise([], addMe)];
495
- case 2:
496
- _a.sent();
497
- return [3 /*break*/, 4];
498
- case 3:
499
- err_3 = _a.sent();
500
- msg = "Error saving type index link saving back ".concat(newIndex, ": ").concat(err_3);
501
- widgets.complain(context, msg);
502
- return [2 /*return*/, context];
503
- case 4:
504
- debug.log("Creating new fresh type index file".concat(newIndex));
505
- return [4 /*yield*/, putIndex(newIndex)];
506
- case 5:
507
- _a.sent();
508
- context.index[visibility].push(newIndex); // @@ wait
509
- return [3 /*break*/, 10];
510
- case 6:
511
- ixs = context.index[visibility];
512
- _a.label = 7;
513
- case 7:
514
- _a.trys.push([7, 9, , 10]);
515
- return [4 /*yield*/, logic_1.solidLogicSingleton.load(ixs)];
516
- case 8:
517
- _a.sent();
518
- return [3 /*break*/, 10];
519
- case 9:
520
- err_4 = _a.sent();
521
- widgets.complain(context, "ensureOneTypeIndex: loading indexes ".concat(err_4));
522
- return [3 /*break*/, 10];
523
- case 10: return [2 /*return*/];
524
- }
525
- });
526
- });
527
- } // makeIndexIfNecessary
528
- var error_1;
529
- return __generator(this, function (_a) {
530
- switch (_a.label) {
531
- case 0:
532
- _a.trys.push([0, 2, , 4]);
533
- return [4 /*yield*/, loadIndex(context, isPublic)];
534
- case 1:
535
- _a.sent();
536
- if (context.index) {
537
- debug.log("ensureOneTypeIndex: Type index exists already ".concat(isPublic
538
- ? context.index.public[0]
539
- : context.index.private[0]));
540
- }
541
- return [2 /*return*/, context];
542
- case 2:
543
- error_1 = _a.sent();
544
- return [4 /*yield*/, makeIndexIfNecessary(context, isPublic)
545
- // widgets.complain(context, 'calling loadIndex:' + error)
546
- ];
547
- case 3:
548
- _a.sent();
549
- return [3 /*break*/, 4];
550
- case 4: return [2 /*return*/];
551
- }
552
- });
553
- });
597
+
598
+
599
+ function _ensureTypeIndexes() {
600
+ _ensureTypeIndexes = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(context) {
601
+ return _regenerator["default"].wrap(function _callee10$(_context10) {
602
+ while (1) {
603
+ switch (_context10.prev = _context10.next) {
604
+ case 0:
605
+ _context10.next = 2;
606
+ return ensureOneTypeIndex(context, true);
607
+
608
+ case 2:
609
+ _context10.next = 4;
610
+ return ensureOneTypeIndex(context, false);
611
+
612
+ case 4:
613
+ return _context10.abrupt("return", context);
614
+
615
+ case 5:
616
+ case "end":
617
+ return _context10.stop();
618
+ }
619
+ }
620
+ }, _callee10);
621
+ }));
622
+ return _ensureTypeIndexes.apply(this, arguments);
623
+ }
624
+
625
+ function ensureOneTypeIndex(_x8, _x9) {
626
+ return _ensureOneTypeIndex.apply(this, arguments);
554
627
  }
555
628
  /**
556
629
  * Returns promise of context with arrays of symbols
@@ -558,283 +631,519 @@ function ensureOneTypeIndex(context, isPublic) {
558
631
  * 2016-12-11 change to include forClass arc a la
559
632
  * https://github.com/solid/solid/blob/main/proposals/data-discovery.md
560
633
  */
561
- function findAppInstances(context, theClass, isPublic) {
562
- return __awaiter(this, void 0, void 0, function () {
563
- function unique(arr) {
564
- return Array.from(new Set(arr));
565
- }
566
- var err_5, visibility, err_6, index, thisIndex, registrations, instances, containers, err_7, e, i, cont, _a, _b, _c;
567
- return __generator(this, function (_d) {
568
- switch (_d.label) {
569
- case 0:
570
- if (!(isPublic === undefined)) return [3 /*break*/, 3];
571
- // Then both public and private
572
- // console.log('finding public app instance')
573
- return [4 /*yield*/, findAppInstances(context, theClass, true)
574
- // console.log('finding private app instance')
575
- ];
576
- case 1:
577
- // Then both public and private
578
- // console.log('finding public app instance')
579
- _d.sent();
580
- // console.log('finding private app instance')
581
- return [4 /*yield*/, findAppInstances(context, theClass, false)
582
- // console.log('found public & private app instance', context)
583
- ];
584
- case 2:
585
- // console.log('finding private app instance')
586
- _d.sent();
587
- // console.log('found public & private app instance', context)
588
- return [2 /*return*/, context];
589
- case 3:
590
- _d.trys.push([3, 5, , 6]);
591
- // console.log('calling logInLoad', isPublic)
592
- return [4 /*yield*/, (isPublic
593
- ? logInLoadProfile(context)
594
- : logInLoadPreferences(context))
595
- // console.log('called logInLoad', isPublic)
596
- ];
597
- case 4:
598
- // console.log('calling logInLoad', isPublic)
599
- _d.sent();
600
- return [3 /*break*/, 6];
601
- case 5:
602
- err_5 = _d.sent();
603
- widgets.complain(context, "loadIndex: login and load problem ".concat(err_5));
604
- return [3 /*break*/, 6];
605
- case 6:
606
- visibility = isPublic ? 'public' : 'private';
607
- _d.label = 7;
608
- case 7:
609
- _d.trys.push([7, 9, , 10]);
610
- return [4 /*yield*/, loadIndex(context, isPublic)];
611
- case 8:
612
- _d.sent();
613
- return [3 /*break*/, 10];
614
- case 9:
615
- err_6 = _d.sent();
616
- return [3 /*break*/, 10];
617
- case 10:
618
- index = context.index;
619
- thisIndex = index[visibility];
620
- registrations = thisIndex
621
- .map(function (ix) { return logic_1.solidLogicSingleton.store.each(undefined, ns.solid('forClass'), theClass, ix); })
622
- .reduce(function (acc, curr) { return acc.concat(curr); }, []);
623
- instances = registrations
624
- .map(function (reg) { return logic_1.solidLogicSingleton.store.each(reg, ns.solid('instance')); })
625
- .reduce(function (acc, curr) { return acc.concat(curr); }, []);
626
- containers = registrations
627
- .map(function (reg) { return logic_1.solidLogicSingleton.store.each(reg, ns.solid('instanceContainer')); })
628
- .reduce(function (acc, curr) { return acc.concat(curr); }, []);
629
- context.instances = context.instances || [];
630
- context.instances = unique(context.instances.concat(instances));
631
- context.containers = context.containers || [];
632
- context.containers = unique(context.containers.concat(containers));
633
- if (!containers.length) {
634
- return [2 /*return*/, context];
634
+
635
+
636
+ function _ensureOneTypeIndex() {
637
+ _ensureOneTypeIndex = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(context, isPublic) {
638
+ var makeIndexIfNecessary, _makeIndexIfNecessary;
639
+
640
+ return _regenerator["default"].wrap(function _callee13$(_context13) {
641
+ while (1) {
642
+ switch (_context13.prev = _context13.next) {
643
+ case 0:
644
+ _makeIndexIfNecessary = function _makeIndexIfNecessary3() {
645
+ _makeIndexIfNecessary = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(context, isPublic) {
646
+ var relevant, visibility, putIndex, _putIndex, newIndex, addMe, msg, ixs;
647
+
648
+ return _regenerator["default"].wrap(function _callee12$(_context12) {
649
+ while (1) {
650
+ switch (_context12.prev = _context12.next) {
651
+ case 0:
652
+ _putIndex = function _putIndex3() {
653
+ _putIndex = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(newIndex) {
654
+ var _msg;
655
+
656
+ return _regenerator["default"].wrap(function _callee11$(_context11) {
657
+ while (1) {
658
+ switch (_context11.prev = _context11.next) {
659
+ case 0:
660
+ _context11.prev = 0;
661
+ _context11.next = 3;
662
+ return _logic.solidLogicSingleton.createEmptyRdfDoc(newIndex, 'Blank initial Type index');
663
+
664
+ case 3:
665
+ return _context11.abrupt("return", context);
666
+
667
+ case 6:
668
+ _context11.prev = 6;
669
+ _context11.t0 = _context11["catch"](0);
670
+ _msg = "Error creating new index ".concat(_context11.t0);
671
+ widgets.complain(context, _msg);
672
+
673
+ case 10:
674
+ case "end":
675
+ return _context11.stop();
676
+ }
677
+ }
678
+ }, _callee11, null, [[0, 6]]);
679
+ }));
680
+ return _putIndex.apply(this, arguments);
681
+ };
682
+
683
+ putIndex = function _putIndex2(_x25) {
684
+ return _putIndex.apply(this, arguments);
685
+ };
686
+
687
+ relevant = isPublic ? context.publicProfile : context.preferencesFile;
688
+ visibility = isPublic ? 'public' : 'private';
689
+ // putIndex
690
+ context.index = context.index || {};
691
+ context.index[visibility] = context.index[visibility] || [];
692
+
693
+ if (!(context.index[visibility].length === 0)) {
694
+ _context12.next = 29;
695
+ break;
696
+ }
697
+
698
+ newIndex = (0, _rdflib.sym)("".concat(relevant.dir().uri + visibility, "TypeIndex.ttl"));
699
+ debug.log("Linking to new fresh type index ".concat(newIndex));
700
+
701
+ if (confirm("OK to create a new empty index file at ".concat(newIndex, ", overwriting anything that is now there?"))) {
702
+ _context12.next = 11;
703
+ break;
704
+ }
705
+
706
+ throw new Error('cancelled by user');
707
+
708
+ case 11:
709
+ debug.log("Linking to new fresh type index ".concat(newIndex));
710
+ addMe = [(0, _rdflib.st)(context.me, ns.solid("".concat(visibility, "TypeIndex")), newIndex, relevant)];
711
+ _context12.prev = 13;
712
+ _context12.next = 16;
713
+ return _logic.solidLogicSingleton.updatePromise([], addMe);
714
+
715
+ case 16:
716
+ _context12.next = 23;
717
+ break;
718
+
719
+ case 18:
720
+ _context12.prev = 18;
721
+ _context12.t0 = _context12["catch"](13);
722
+ msg = "Error saving type index link saving back ".concat(newIndex, ": ").concat(_context12.t0);
723
+ widgets.complain(context, msg);
724
+ return _context12.abrupt("return", context);
725
+
726
+ case 23:
727
+ debug.log("Creating new fresh type index file".concat(newIndex));
728
+ _context12.next = 26;
729
+ return putIndex(newIndex);
730
+
731
+ case 26:
732
+ context.index[visibility].push(newIndex); // @@ wait
733
+
734
+ _context12.next = 38;
735
+ break;
736
+
737
+ case 29:
738
+ // officially exists
739
+ ixs = context.index[visibility];
740
+ _context12.prev = 30;
741
+ _context12.next = 33;
742
+ return _logic.solidLogicSingleton.load(ixs);
743
+
744
+ case 33:
745
+ _context12.next = 38;
746
+ break;
747
+
748
+ case 35:
749
+ _context12.prev = 35;
750
+ _context12.t1 = _context12["catch"](30);
751
+ widgets.complain(context, "ensureOneTypeIndex: loading indexes ".concat(_context12.t1));
752
+
753
+ case 38:
754
+ case "end":
755
+ return _context12.stop();
635
756
  }
636
- _d.label = 11;
637
- case 11:
638
- _d.trys.push([11, 13, , 14]);
639
- return [4 /*yield*/, logic_1.solidLogicSingleton.load(containers)];
640
- case 12:
641
- _d.sent();
642
- return [3 /*break*/, 14];
643
- case 13:
644
- err_7 = _d.sent();
645
- e = new Error("[FAI] Unable to load containers".concat(err_7));
646
- debug.log(e); // complain
647
- widgets.complain(context, "Error looking for ".concat(utils.label(theClass), ": ").concat(err_7));
648
- return [3 /*break*/, 14];
649
- case 14:
650
- i = 0;
651
- _d.label = 15;
652
- case 15:
653
- if (!(i < containers.length)) return [3 /*break*/, 18];
654
- cont = containers[i];
655
- _a = context;
656
- _c = (_b = context.instances).concat;
657
- return [4 /*yield*/, logic_1.solidLogicSingleton.getContainerMembers(cont.value)];
658
- case 16:
659
- _a.instances = _c.apply(_b, [(_d.sent()).map(function (uri) { return logic_1.solidLogicSingleton.store.sym(uri); }) // @@ warning: uses strings not NN
660
- ]);
661
- _d.label = 17;
662
- case 17:
663
- i++;
664
- return [3 /*break*/, 15];
665
- case 18: return [2 /*return*/, context];
757
+ }
758
+ }, _callee12, null, [[13, 18], [30, 35]]);
759
+ }));
760
+ return _makeIndexIfNecessary.apply(this, arguments);
761
+ };
762
+
763
+ makeIndexIfNecessary = function _makeIndexIfNecessary2(_x23, _x24) {
764
+ return _makeIndexIfNecessary.apply(this, arguments);
765
+ };
766
+
767
+ _context13.prev = 2;
768
+ _context13.next = 5;
769
+ return loadIndex(context, isPublic);
770
+
771
+ case 5:
772
+ if (context.index) {
773
+ debug.log("ensureOneTypeIndex: Type index exists already ".concat(isPublic ? context.index["public"][0] : context.index["private"][0]));
666
774
  }
667
- });
668
- });
775
+
776
+ return _context13.abrupt("return", context);
777
+
778
+ case 9:
779
+ _context13.prev = 9;
780
+ _context13.t0 = _context13["catch"](2);
781
+ _context13.next = 13;
782
+ return makeIndexIfNecessary(context, isPublic);
783
+
784
+ case 13:
785
+ case "end":
786
+ return _context13.stop();
787
+ }
788
+ }
789
+ }, _callee13, null, [[2, 9]]);
790
+ }));
791
+ return _ensureOneTypeIndex.apply(this, arguments);
792
+ }
793
+
794
+ function findAppInstances(_x10, _x11, _x12) {
795
+ return _findAppInstances.apply(this, arguments);
669
796
  }
670
- exports.findAppInstances = findAppInstances;
671
797
  /**
672
798
  * Register a new app in a type index
673
799
  */
674
- function registerInTypeIndex(context, instance, theClass, isPublic) {
675
- return __awaiter(this, void 0, void 0, function () {
676
- var indexes, index, registration, ins, e_2;
677
- return __generator(this, function (_a) {
678
- switch (_a.label) {
679
- case 0: return [4 /*yield*/, ensureOneTypeIndex(context, isPublic)];
680
- case 1:
681
- _a.sent();
682
- if (!context.index) {
683
- throw new Error('registerInTypeIndex: No type index found');
684
- }
685
- indexes = isPublic ? context.index.public : context.index.private;
686
- if (!indexes.length) {
687
- throw new Error('registerInTypeIndex: What no type index?');
688
- }
689
- index = indexes[0];
690
- registration = widgets.newThing(index);
691
- ins = [
692
- // See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
693
- (0, rdflib_1.st)(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index),
694
- (0, rdflib_1.st)(registration, ns.solid('forClass'), theClass, index),
695
- (0, rdflib_1.st)(registration, ns.solid('instance'), instance, index)
696
- ];
697
- _a.label = 2;
698
- case 2:
699
- _a.trys.push([2, 4, , 5]);
700
- return [4 /*yield*/, logic_1.solidLogicSingleton.updatePromise([], ins)];
701
- case 3:
702
- _a.sent();
703
- return [3 /*break*/, 5];
704
- case 4:
705
- e_2 = _a.sent();
706
- debug.log(e_2);
707
- (0, log_1.alert)(e_2);
708
- return [3 /*break*/, 5];
709
- case 5: return [2 /*return*/, context];
800
+
801
+
802
+ function _findAppInstances() {
803
+ _findAppInstances = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(context, theClass, isPublic) {
804
+ var visibility, index, thisIndex, registrations, instances, containers, unique, e, i, cont;
805
+ return _regenerator["default"].wrap(function _callee14$(_context14) {
806
+ while (1) {
807
+ switch (_context14.prev = _context14.next) {
808
+ case 0:
809
+ unique = function _unique(arr) {
810
+ return Array.from(new Set(arr));
811
+ };
812
+
813
+ if (!(isPublic === undefined)) {
814
+ _context14.next = 7;
815
+ break;
710
816
  }
711
- });
712
- });
817
+
818
+ _context14.next = 4;
819
+ return findAppInstances(context, theClass, true);
820
+
821
+ case 4:
822
+ _context14.next = 6;
823
+ return findAppInstances(context, theClass, false);
824
+
825
+ case 6:
826
+ return _context14.abrupt("return", context);
827
+
828
+ case 7:
829
+ _context14.prev = 7;
830
+ _context14.next = 10;
831
+ return isPublic ? logInLoadProfile(context) : logInLoadPreferences(context);
832
+
833
+ case 10:
834
+ _context14.next = 15;
835
+ break;
836
+
837
+ case 12:
838
+ _context14.prev = 12;
839
+ _context14.t0 = _context14["catch"](7);
840
+ widgets.complain(context, "loadIndex: login and load problem ".concat(_context14.t0));
841
+
842
+ case 15:
843
+ // console.log('awaited LogInLoad!', context)
844
+ visibility = isPublic ? 'public' : 'private';
845
+ _context14.prev = 16;
846
+ _context14.next = 19;
847
+ return loadIndex(context, isPublic);
848
+
849
+ case 19:
850
+ _context14.next = 23;
851
+ break;
852
+
853
+ case 21:
854
+ _context14.prev = 21;
855
+ _context14.t1 = _context14["catch"](16);
856
+
857
+ case 23:
858
+ index = context.index;
859
+ thisIndex = index[visibility];
860
+ registrations = thisIndex.map(function (ix) {
861
+ return _logic.solidLogicSingleton.store.each(undefined, ns.solid('forClass'), theClass, ix);
862
+ }).reduce(function (acc, curr) {
863
+ return acc.concat(curr);
864
+ }, []);
865
+ instances = registrations.map(function (reg) {
866
+ return _logic.solidLogicSingleton.store.each(reg, ns.solid('instance'));
867
+ }).reduce(function (acc, curr) {
868
+ return acc.concat(curr);
869
+ }, []);
870
+ containers = registrations.map(function (reg) {
871
+ return _logic.solidLogicSingleton.store.each(reg, ns.solid('instanceContainer'));
872
+ }).reduce(function (acc, curr) {
873
+ return acc.concat(curr);
874
+ }, []);
875
+ context.instances = context.instances || [];
876
+ context.instances = unique(context.instances.concat(instances));
877
+ context.containers = context.containers || [];
878
+ context.containers = unique(context.containers.concat(containers));
879
+
880
+ if (containers.length) {
881
+ _context14.next = 34;
882
+ break;
883
+ }
884
+
885
+ return _context14.abrupt("return", context);
886
+
887
+ case 34:
888
+ _context14.prev = 34;
889
+ _context14.next = 37;
890
+ return _logic.solidLogicSingleton.load(containers);
891
+
892
+ case 37:
893
+ _context14.next = 44;
894
+ break;
895
+
896
+ case 39:
897
+ _context14.prev = 39;
898
+ _context14.t2 = _context14["catch"](34);
899
+ e = new Error("[FAI] Unable to load containers".concat(_context14.t2));
900
+ debug.log(e); // complain
901
+
902
+ widgets.complain(context, "Error looking for ".concat(utils.label(theClass), ": ").concat(_context14.t2)); // but then ignore it
903
+ // throw new Error(e)
904
+
905
+ case 44:
906
+ i = 0;
907
+
908
+ case 45:
909
+ if (!(i < containers.length)) {
910
+ _context14.next = 55;
911
+ break;
912
+ }
913
+
914
+ cont = containers[i];
915
+ _context14.t3 = context.instances;
916
+ _context14.next = 50;
917
+ return _logic.solidLogicSingleton.getContainerMembers(cont.value);
918
+
919
+ case 50:
920
+ _context14.t4 = _context14.sent.map(function (uri) {
921
+ return _logic.solidLogicSingleton.store.sym(uri);
922
+ });
923
+ context.instances = _context14.t3.concat.call(_context14.t3, _context14.t4);
924
+
925
+ case 52:
926
+ i++;
927
+ _context14.next = 45;
928
+ break;
929
+
930
+ case 55:
931
+ return _context14.abrupt("return", context);
932
+
933
+ case 56:
934
+ case "end":
935
+ return _context14.stop();
936
+ }
937
+ }
938
+ }, _callee14, null, [[7, 12], [16, 21], [34, 39]]);
939
+ }));
940
+ return _findAppInstances.apply(this, arguments);
941
+ }
942
+
943
+ function registerInTypeIndex(_x13, _x14, _x15, _x16) {
944
+ return _registerInTypeIndex.apply(this, arguments);
713
945
  }
714
- exports.registerInTypeIndex = registerInTypeIndex;
715
946
  /**
716
947
  * UI to control registration of instance
717
948
  */
949
+
950
+
951
+ function _registerInTypeIndex() {
952
+ _registerInTypeIndex = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(context, instance, theClass, isPublic) {
953
+ var indexes, index, registration, ins;
954
+ return _regenerator["default"].wrap(function _callee15$(_context15) {
955
+ while (1) {
956
+ switch (_context15.prev = _context15.next) {
957
+ case 0:
958
+ _context15.next = 2;
959
+ return ensureOneTypeIndex(context, isPublic);
960
+
961
+ case 2:
962
+ if (context.index) {
963
+ _context15.next = 4;
964
+ break;
965
+ }
966
+
967
+ throw new Error('registerInTypeIndex: No type index found');
968
+
969
+ case 4:
970
+ indexes = isPublic ? context.index["public"] : context.index["private"];
971
+
972
+ if (indexes.length) {
973
+ _context15.next = 7;
974
+ break;
975
+ }
976
+
977
+ throw new Error('registerInTypeIndex: What no type index?');
978
+
979
+ case 7:
980
+ index = indexes[0];
981
+ registration = widgets.newThing(index);
982
+ ins = [// See https://github.com/solid/solid/blob/main/proposals/data-discovery.md
983
+ (0, _rdflib.st)(registration, ns.rdf('type'), ns.solid('TypeRegistration'), index), (0, _rdflib.st)(registration, ns.solid('forClass'), theClass, index), (0, _rdflib.st)(registration, ns.solid('instance'), instance, index)];
984
+ _context15.prev = 10;
985
+ _context15.next = 13;
986
+ return _logic.solidLogicSingleton.updatePromise([], ins);
987
+
988
+ case 13:
989
+ _context15.next = 19;
990
+ break;
991
+
992
+ case 15:
993
+ _context15.prev = 15;
994
+ _context15.t0 = _context15["catch"](10);
995
+ debug.log(_context15.t0);
996
+ (0, _log.alert)(_context15.t0);
997
+
998
+ case 19:
999
+ return _context15.abrupt("return", context);
1000
+
1001
+ case 20:
1002
+ case "end":
1003
+ return _context15.stop();
1004
+ }
1005
+ }
1006
+ }, _callee15, null, [[10, 15]]);
1007
+ }));
1008
+ return _registerInTypeIndex.apply(this, arguments);
1009
+ }
1010
+
718
1011
  function registrationControl(context, instance, theClass) {
719
- var dom = context.dom;
720
- if (!dom || !context.div) {
721
- return Promise.resolve();
1012
+ var dom = context.dom;
1013
+
1014
+ if (!dom || !context.div) {
1015
+ return Promise.resolve();
1016
+ }
1017
+
1018
+ var box = dom.createElement('div');
1019
+ context.div.appendChild(box);
1020
+ return ensureTypeIndexes(context).then(function () {
1021
+ box.innerHTML = '<table><tbody><tr></tr><tr></tr></tbody></table>'; // tbody will be inserted anyway
1022
+
1023
+ box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;');
1024
+ var tbody = box.children[0].children[0];
1025
+ var form = new _rdflib.BlankNode(); // @@ say for now
1026
+
1027
+ var registrationStatements = function registrationStatements(index) {
1028
+ var registrations = _logic.solidLogicSingleton.getRegistrations(instance, theClass);
1029
+
1030
+ var reg = registrations.length ? registrations[0] : widgets.newThing(index);
1031
+ return [(0, _rdflib.st)(reg, ns.solid('instance'), instance, index), (0, _rdflib.st)(reg, ns.solid('forClass'), theClass, index)];
1032
+ };
1033
+
1034
+ var index, statements;
1035
+
1036
+ if (context.index && context.index["public"] && context.index["public"].length > 0) {
1037
+ index = context.index["public"][0];
1038
+ statements = registrationStatements(index);
1039
+ tbody.children[0].appendChild(widgets.buildCheckBoxForm(context.dom, _logic.solidLogicSingleton.store, "Public link to this ".concat(context.noun), null, statements, form, index));
722
1040
  }
723
- var box = dom.createElement('div');
724
- context.div.appendChild(box);
725
- return ensureTypeIndexes(context)
726
- .then(function () {
727
- box.innerHTML = '<table><tbody><tr></tr><tr></tr></tbody></table>'; // tbody will be inserted anyway
728
- box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid gray 0.05em;');
729
- var tbody = box.children[0].children[0];
730
- var form = new rdflib_1.BlankNode(); // @@ say for now
731
- var registrationStatements = function (index) {
732
- var registrations = logic_1.solidLogicSingleton.getRegistrations(instance, theClass);
733
- var reg = registrations.length
734
- ? registrations[0]
735
- : widgets.newThing(index);
736
- return [
737
- (0, rdflib_1.st)(reg, ns.solid('instance'), instance, index),
738
- (0, rdflib_1.st)(reg, ns.solid('forClass'), theClass, index)
739
- ];
740
- };
741
- var index, statements;
742
- if (context.index && context.index.public && context.index.public.length > 0) {
743
- index = context.index.public[0];
744
- statements = registrationStatements(index);
745
- tbody.children[0].appendChild(widgets.buildCheckBoxForm(context.dom, logic_1.solidLogicSingleton.store, "Public link to this ".concat(context.noun), null, statements, form, index));
746
- }
747
- if (context.index && context.index.private && context.index.private.length > 0) {
748
- index = context.index.private[0];
749
- statements = registrationStatements(index);
750
- tbody.children[1].appendChild(widgets.buildCheckBoxForm(context.dom, logic_1.solidLogicSingleton.store, "Personal note of this ".concat(context.noun), null, statements, form, index));
751
- }
752
- return context;
753
- }, function (e) {
754
- var msg;
755
- if (context.div && context.preferencesFileError) {
756
- msg = '(Preferences not available)';
757
- context.div.appendChild(dom.createElement('p')).textContent = msg;
758
- }
759
- else if (context.div) {
760
- msg = "registrationControl: Type indexes not available: ".concat(e);
761
- context.div.appendChild(widgets.errorMessageBlock(context.dom, e));
762
- }
763
- debug.log(msg);
764
- })
765
- .catch(function (e) {
766
- var msg = "registrationControl: Error making panel: ".concat(e);
767
- if (context.div) {
768
- context.div.appendChild(widgets.errorMessageBlock(context.dom, e));
769
- }
770
- debug.log(msg);
771
- });
1041
+
1042
+ if (context.index && context.index["private"] && context.index["private"].length > 0) {
1043
+ index = context.index["private"][0];
1044
+ statements = registrationStatements(index);
1045
+ tbody.children[1].appendChild(widgets.buildCheckBoxForm(context.dom, _logic.solidLogicSingleton.store, "Personal note of this ".concat(context.noun), null, statements, form, index));
1046
+ }
1047
+
1048
+ return context;
1049
+ }, function (e) {
1050
+ var msg;
1051
+
1052
+ if (context.div && context.preferencesFileError) {
1053
+ msg = '(Preferences not available)';
1054
+ context.div.appendChild(dom.createElement('p')).textContent = msg;
1055
+ } else if (context.div) {
1056
+ msg = "registrationControl: Type indexes not available: ".concat(e);
1057
+ context.div.appendChild(widgets.errorMessageBlock(context.dom, e));
1058
+ }
1059
+
1060
+ debug.log(msg);
1061
+ })["catch"](function (e) {
1062
+ var msg = "registrationControl: Error making panel: ".concat(e);
1063
+
1064
+ if (context.div) {
1065
+ context.div.appendChild(widgets.errorMessageBlock(context.dom, e));
1066
+ }
1067
+
1068
+ debug.log(msg);
1069
+ });
772
1070
  }
773
- exports.registrationControl = registrationControl;
774
1071
  /**
775
1072
  * UI to List at all registered things
776
1073
  */
1074
+
1075
+
777
1076
  function registrationList(context, options) {
778
- var dom = context.dom;
779
- var div = context.div;
780
- var box = dom.createElement('div');
781
- div.appendChild(box);
782
- return ensureTypeIndexes(context).then(function (_indexes) {
783
- box.innerHTML = '<table><tbody></tbody></table>'; // tbody will be inserted anyway
784
- box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;');
785
- var table = box.firstChild;
786
- var ix = [];
787
- var sts = [];
788
- var vs = ['private', 'public'];
789
- vs.forEach(function (visibility) {
790
- if (context.index && options[visibility]) {
791
- ix = ix.concat(context.index[visibility][0]);
792
- sts = sts.concat(logic_1.solidLogicSingleton.store.statementsMatching(undefined, ns.solid('instance'), undefined, context.index[visibility][0]));
793
- }
794
- });
795
- var _loop_1 = function (i) {
796
- var statement = sts[i];
797
- if (options.type) { // now check terms:forClass
798
- if (!logic_1.solidLogicSingleton.store.holds(statement.subject, ns.solid('forClass'), options.type, statement.why)) {
799
- return "continue";
800
- }
801
- }
802
- // const cla = statement.subject
803
- var inst = statement.object;
804
- table.appendChild(widgets.personTR(dom, ns.solid('instance'), inst, {
805
- deleteFunction: function (_x) {
806
- if (!logic_1.solidLogicSingleton.store.updater) {
807
- throw new Error('Cannot delete this, store has no updater');
808
- }
809
- logic_1.solidLogicSingleton.store.updater.update([statement], [], function (uri, ok, errorBody) {
810
- if (ok) {
811
- debug.log("Removed from index: ".concat(statement.subject));
812
- }
813
- else {
814
- debug.log("Error: Cannot delete ".concat(statement, ": ").concat(errorBody));
815
- }
816
- });
817
- }
818
- }));
819
- };
820
- for (var i = 0; i < sts.length; i++) {
821
- _loop_1(i);
822
- } // registrationList
823
- /*
824
- //const containers = solidLogicSingleton.store.each(theClass, ns.solid('instanceContainer'));
825
- if (containers.length) {
826
- fetcher.load(containers).then(function(xhrs){
827
- for (const i=0; i<containers.length; i++) {
828
- const cont = containers[i];
829
- instances = instances.concat(solidLogicSingleton.store.each(cont, ns.ldp('contains')));
830
- }
831
- });
832
- }
833
- */
834
- return context;
1077
+ var dom = context.dom;
1078
+ var div = context.div;
1079
+ var box = dom.createElement('div');
1080
+ div.appendChild(box);
1081
+ return ensureTypeIndexes(context).then(function (_indexes) {
1082
+ box.innerHTML = '<table><tbody></tbody></table>'; // tbody will be inserted anyway
1083
+
1084
+ box.setAttribute('style', 'font-size: 120%; text-align: right; padding: 1em; border: solid #eee 0.5em;');
1085
+ var table = box.firstChild;
1086
+ var ix = [];
1087
+ var sts = [];
1088
+ var vs = ['private', 'public'];
1089
+ vs.forEach(function (visibility) {
1090
+ if (context.index && options[visibility]) {
1091
+ ix = ix.concat(context.index[visibility][0]);
1092
+ sts = sts.concat(_logic.solidLogicSingleton.store.statementsMatching(undefined, ns.solid('instance'), undefined, context.index[visibility][0]));
1093
+ }
835
1094
  });
1095
+
1096
+ var _loop = function _loop(i) {
1097
+ var statement = sts[i];
1098
+
1099
+ if (options.type) {
1100
+ // now check terms:forClass
1101
+ if (!_logic.solidLogicSingleton.store.holds(statement.subject, ns.solid('forClass'), options.type, statement.why)) {
1102
+ return "continue"; // skip irrelevant ones
1103
+ }
1104
+ } // const cla = statement.subject
1105
+
1106
+
1107
+ var inst = statement.object;
1108
+ table.appendChild(widgets.personTR(dom, ns.solid('instance'), inst, {
1109
+ deleteFunction: function deleteFunction(_x) {
1110
+ if (!_logic.solidLogicSingleton.store.updater) {
1111
+ throw new Error('Cannot delete this, store has no updater');
1112
+ }
1113
+
1114
+ _logic.solidLogicSingleton.store.updater.update([statement], [], function (uri, ok, errorBody) {
1115
+ if (ok) {
1116
+ debug.log("Removed from index: ".concat(statement.subject));
1117
+ } else {
1118
+ debug.log("Error: Cannot delete ".concat(statement, ": ").concat(errorBody));
1119
+ }
1120
+ });
1121
+ }
1122
+ }));
1123
+ };
1124
+
1125
+ for (var i = 0; i < sts.length; i++) {
1126
+ var _ret = _loop(i);
1127
+
1128
+ if (_ret === "continue") continue;
1129
+ } // registrationList
1130
+
1131
+ /*
1132
+ //const containers = solidLogicSingleton.store.each(theClass, ns.solid('instanceContainer'));
1133
+ if (containers.length) {
1134
+ fetcher.load(containers).then(function(xhrs){
1135
+ for (const i=0; i<containers.length; i++) {
1136
+ const cont = containers[i];
1137
+ instances = instances.concat(solidLogicSingleton.store.each(cont, ns.ldp('contains')));
1138
+ }
1139
+ });
1140
+ }
1141
+ */
1142
+
1143
+
1144
+ return context;
1145
+ });
836
1146
  }
837
- exports.registrationList = registrationList;
838
1147
  /**
839
1148
  * Simple Access Control
840
1149
  *
@@ -848,55 +1157,64 @@ exports.registrationList = registrationList;
848
1157
  *
849
1158
  * @returns Resolves with aclDoc uri on successful write
850
1159
  */
1160
+
1161
+
851
1162
  function setACLUserPublic(docURI, me, options) {
852
- var aclDoc = logic_1.solidLogicSingleton.store.any(logic_1.solidLogicSingleton.store.sym(docURI), solid_logic_1.ACL_LINK);
853
- return Promise.resolve()
854
- .then(function () {
855
- if (aclDoc) {
856
- return aclDoc;
857
- }
858
- return fetchACLRel(docURI).catch(function (err) {
859
- throw new Error("Error fetching rel=ACL header for ".concat(docURI, ": ").concat(err));
860
- });
861
- })
862
- .then(function (aclDoc) {
863
- var aclText = genACLText(docURI, me, aclDoc.uri, options);
864
- if (!logic_1.solidLogicSingleton.store.fetcher) {
865
- throw new Error('Cannot PUT this, store has no fetcher');
866
- }
867
- return logic_1.solidLogicSingleton.store.fetcher
868
- .webOperation('PUT', aclDoc.uri, {
869
- data: aclText,
870
- contentType: 'text/turtle'
871
- })
872
- .then(function (result) {
873
- if (!result.ok) {
874
- throw new Error('Error writing ACL text: ' + result.error);
875
- }
876
- return aclDoc;
877
- });
1163
+ var aclDoc = _logic.solidLogicSingleton.store.any(_logic.solidLogicSingleton.store.sym(docURI), _solidLogic.ACL_LINK);
1164
+
1165
+ return Promise.resolve().then(function () {
1166
+ if (aclDoc) {
1167
+ return aclDoc;
1168
+ }
1169
+
1170
+ return fetchACLRel(docURI)["catch"](function (err) {
1171
+ throw new Error("Error fetching rel=ACL header for ".concat(docURI, ": ").concat(err));
878
1172
  });
1173
+ }).then(function (aclDoc) {
1174
+ var aclText = genACLText(docURI, me, aclDoc.uri, options);
1175
+
1176
+ if (!_logic.solidLogicSingleton.store.fetcher) {
1177
+ throw new Error('Cannot PUT this, store has no fetcher');
1178
+ }
1179
+
1180
+ return _logic.solidLogicSingleton.store.fetcher.webOperation('PUT', aclDoc.uri, {
1181
+ data: aclText,
1182
+ contentType: 'text/turtle'
1183
+ }).then(function (result) {
1184
+ if (!result.ok) {
1185
+ throw new Error('Error writing ACL text: ' + result.error);
1186
+ }
1187
+
1188
+ return aclDoc;
1189
+ });
1190
+ });
879
1191
  }
880
- exports.setACLUserPublic = setACLUserPublic;
881
1192
  /**
882
1193
  * @param docURI
883
1194
  * @returns
884
1195
  */
1196
+
1197
+
885
1198
  function fetchACLRel(docURI) {
886
- var fetcher = logic_1.solidLogicSingleton.store.fetcher;
887
- if (!fetcher) {
888
- throw new Error('Cannot fetch ACL rel, store has no fetcher');
1199
+ var fetcher = _logic.solidLogicSingleton.store.fetcher;
1200
+
1201
+ if (!fetcher) {
1202
+ throw new Error('Cannot fetch ACL rel, store has no fetcher');
1203
+ }
1204
+
1205
+ return fetcher.load(docURI).then(function (result) {
1206
+ if (!result.ok) {
1207
+ throw new Error('fetchACLRel: While loading:' + result.error);
889
1208
  }
890
- return fetcher.load(docURI).then(function (result) {
891
- if (!result.ok) {
892
- throw new Error('fetchACLRel: While loading:' + result.error);
893
- }
894
- var aclDoc = logic_1.solidLogicSingleton.store.any(logic_1.solidLogicSingleton.store.sym(docURI), solid_logic_1.ACL_LINK);
895
- if (!aclDoc) {
896
- throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI);
897
- }
898
- return aclDoc;
899
- });
1209
+
1210
+ var aclDoc = _logic.solidLogicSingleton.store.any(_logic.solidLogicSingleton.store.sym(docURI), _solidLogic.ACL_LINK);
1211
+
1212
+ if (!aclDoc) {
1213
+ throw new Error('fetchACLRel: No Link rel=ACL header for ' + docURI);
1214
+ }
1215
+
1216
+ return aclDoc;
1217
+ });
900
1218
  }
901
1219
  /**
902
1220
  * @param docURI
@@ -906,66 +1224,75 @@ function fetchACLRel(docURI) {
906
1224
  *
907
1225
  * @returns Serialized ACL
908
1226
  */
909
- function genACLText(docURI, me, aclURI, options) {
910
- if (options === void 0) { options = {}; }
911
- var optPublic = options.public || [];
912
- var g = (0, rdflib_1.graph)();
913
- var auth = (0, rdflib_1.Namespace)('http://www.w3.org/ns/auth/acl#');
914
- var a = g.sym("".concat(aclURI, "#a1"));
915
- var acl = g.sym(aclURI);
916
- var doc = g.sym(docURI);
1227
+
1228
+
1229
+ function genACLText(docURI, me, aclURI) {
1230
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1231
+ var optPublic = options["public"] || [];
1232
+ var g = (0, _rdflib.graph)();
1233
+ var auth = (0, _rdflib.Namespace)('http://www.w3.org/ns/auth/acl#');
1234
+ var a = g.sym("".concat(aclURI, "#a1"));
1235
+ var acl = g.sym(aclURI);
1236
+ var doc = g.sym(docURI);
1237
+ g.add(a, ns.rdf('type'), auth('Authorization'), acl);
1238
+ g.add(a, auth('accessTo'), doc, acl);
1239
+
1240
+ if (options.defaultForNew) {
1241
+ g.add(a, auth('default'), doc, acl);
1242
+ }
1243
+
1244
+ g.add(a, auth('agent'), me, acl);
1245
+ g.add(a, auth('mode'), auth('Read'), acl);
1246
+ g.add(a, auth('mode'), auth('Write'), acl);
1247
+ g.add(a, auth('mode'), auth('Control'), acl);
1248
+
1249
+ if (optPublic.length) {
1250
+ a = g.sym("".concat(aclURI, "#a2"));
917
1251
  g.add(a, ns.rdf('type'), auth('Authorization'), acl);
918
1252
  g.add(a, auth('accessTo'), doc, acl);
919
- if (options.defaultForNew) {
920
- g.add(a, auth('default'), doc, acl);
921
- }
922
- g.add(a, auth('agent'), me, acl);
923
- g.add(a, auth('mode'), auth('Read'), acl);
924
- g.add(a, auth('mode'), auth('Write'), acl);
925
- g.add(a, auth('mode'), auth('Control'), acl);
926
- if (optPublic.length) {
927
- a = g.sym("".concat(aclURI, "#a2"));
928
- g.add(a, ns.rdf('type'), auth('Authorization'), acl);
929
- g.add(a, auth('accessTo'), doc, acl);
930
- g.add(a, auth('agentClass'), ns.foaf('Agent'), acl);
931
- for (var p = 0; p < optPublic.length; p++) {
932
- g.add(a, auth('mode'), auth(optPublic[p]), acl); // Like 'Read' etc
933
- }
1253
+ g.add(a, auth('agentClass'), ns.foaf('Agent'), acl);
1254
+
1255
+ for (var p = 0; p < optPublic.length; p++) {
1256
+ g.add(a, auth('mode'), auth(optPublic[p]), acl); // Like 'Read' etc
934
1257
  }
935
- return (0, rdflib_1.serialize)(acl, g, aclURI);
1258
+ }
1259
+
1260
+ return (0, _rdflib.serialize)(acl, g, aclURI);
936
1261
  }
937
1262
  /**
938
1263
  * Returns `sym($SolidTestEnvironment.username)` if
939
1264
  * `$SolidTestEnvironment.username` is defined as a global
940
1265
  * @returns {NamedNode|null}
941
1266
  */
1267
+
1268
+
942
1269
  function offlineTestID() {
943
- var $SolidTestEnvironment = window.$SolidTestEnvironment;
944
- if (typeof $SolidTestEnvironment !== 'undefined' &&
945
- $SolidTestEnvironment.username) {
946
- // Test setup
947
- debug.log('Assuming the user is ' + $SolidTestEnvironment.username);
948
- return (0, rdflib_1.sym)($SolidTestEnvironment.username);
949
- }
950
- if (typeof document !== 'undefined' &&
951
- document.location &&
952
- ('' + document.location).slice(0, 16) === 'http://localhost') {
953
- var div = document.getElementById('appTarget');
954
- if (!div)
955
- return null;
956
- var id = div.getAttribute('testID');
957
- if (!id)
958
- return null;
959
- /* me = solidLogicSingleton.store.any(subject, ns.acl('owner')); // when testing on plane with no WebID
960
- */
961
- debug.log('Assuming user is ' + id);
962
- return (0, rdflib_1.sym)(id);
963
- }
964
- return null;
1270
+ var _window2 = window,
1271
+ $SolidTestEnvironment = _window2.$SolidTestEnvironment;
1272
+
1273
+ if (typeof $SolidTestEnvironment !== 'undefined' && $SolidTestEnvironment.username) {
1274
+ // Test setup
1275
+ debug.log('Assuming the user is ' + $SolidTestEnvironment.username);
1276
+ return (0, _rdflib.sym)($SolidTestEnvironment.username);
1277
+ }
1278
+
1279
+ if (typeof document !== 'undefined' && document.location && ('' + document.location).slice(0, 16) === 'http://localhost') {
1280
+ var div = document.getElementById('appTarget');
1281
+ if (!div) return null;
1282
+ var id = div.getAttribute('testID');
1283
+ if (!id) return null;
1284
+ /* me = solidLogicSingleton.store.any(subject, ns.acl('owner')); // when testing on plane with no WebID
1285
+ */
1286
+
1287
+ debug.log('Assuming user is ' + id);
1288
+ return (0, _rdflib.sym)(id);
1289
+ }
1290
+
1291
+ return null;
965
1292
  }
966
- exports.offlineTestID = offlineTestID;
1293
+
967
1294
  function getDefaultSignInButtonStyle() {
968
- return 'padding: 1em; border-radius:0.5em; font-size: 100%;';
1295
+ return 'padding: 1em; border-radius:0.5em; font-size: 100%;';
969
1296
  }
970
1297
  /**
971
1298
  * Bootstrapping identity
@@ -976,210 +1303,252 @@ function getDefaultSignInButtonStyle() {
976
1303
  *
977
1304
  * @returns
978
1305
  */
979
- function signInOrSignUpBox(dom, setUserCallback, options) {
980
- if (options === void 0) { options = {}; }
981
- options = options || {};
982
- var signInButtonStyle = options.buttonStyle || getDefaultSignInButtonStyle();
983
- // @@ TODO Remove the need to cast HTML element to any
984
- var box = dom.createElement('div');
985
- var magicClassName = 'SolidSignInOrSignUpBox';
986
- debug.log('widgets.signInOrSignUpBox');
987
- box.setUserCallback = setUserCallback;
988
- box.setAttribute('class', magicClassName);
989
- box.style = 'display:flex;'; // @@ fix all typecasts like this
990
- // Sign in button with PopUP
991
- var signInPopUpButton = dom.createElement('input'); // multi
992
- box.appendChild(signInPopUpButton);
993
- signInPopUpButton.setAttribute('type', 'button');
994
- signInPopUpButton.setAttribute('value', 'Log in');
995
- signInPopUpButton.setAttribute('style', "".concat(signInButtonStyle, "background-color: #eef;"));
996
- exports.authSession.onLogin(function () {
997
- var sessionInfo = exports.authSession.info;
998
- if (sessionInfo && sessionInfo.isLoggedIn) {
999
- var webIdURI = sessionInfo.webId;
1000
- // setUserCallback(webIdURI)
1001
- var divs = dom.getElementsByClassName(magicClassName);
1002
- debug.log("Logged in, ".concat(divs.length, " panels to be serviced"));
1003
- // At the same time, satisfy all the other login boxes
1004
- for (var i = 0; i < divs.length; i++) {
1005
- var div = divs[i];
1006
- // @@ TODO Remove the need to manipulate HTML elements
1007
- if (div.setUserCallback) {
1008
- try {
1009
- div.setUserCallback(webIdURI);
1010
- var parent_1 = div.parentNode;
1011
- if (parent_1) {
1012
- parent_1.removeChild(div);
1013
- }
1014
- }
1015
- catch (e) {
1016
- debug.log("## Error satisfying login box: ".concat(e));
1017
- div.appendChild(widgets.errorMessageBlock(dom, e));
1018
- }
1019
- }
1306
+
1307
+
1308
+ function signInOrSignUpBox(dom, setUserCallback) {
1309
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1310
+ options = options || {};
1311
+ var signInButtonStyle = options.buttonStyle || getDefaultSignInButtonStyle(); // @@ TODO Remove the need to cast HTML element to any
1312
+
1313
+ var box = dom.createElement('div');
1314
+ var magicClassName = 'SolidSignInOrSignUpBox';
1315
+ debug.log('widgets.signInOrSignUpBox');
1316
+ box.setUserCallback = setUserCallback;
1317
+ box.setAttribute('class', magicClassName);
1318
+ box.style = 'display:flex;'; // @@ fix all typecasts like this
1319
+ // Sign in button with PopUP
1320
+
1321
+ var signInPopUpButton = dom.createElement('input'); // multi
1322
+
1323
+ box.appendChild(signInPopUpButton);
1324
+ signInPopUpButton.setAttribute('type', 'button');
1325
+ signInPopUpButton.setAttribute('value', 'Log in');
1326
+ signInPopUpButton.setAttribute('style', "".concat(signInButtonStyle, "background-color: #eef;"));
1327
+ authSession.onLogin(function () {
1328
+ var sessionInfo = authSession.info;
1329
+
1330
+ if (sessionInfo && sessionInfo.isLoggedIn) {
1331
+ var webIdURI = sessionInfo.webId; // setUserCallback(webIdURI)
1332
+
1333
+ var divs = dom.getElementsByClassName(magicClassName);
1334
+ debug.log("Logged in, ".concat(divs.length, " panels to be serviced")); // At the same time, satisfy all the other login boxes
1335
+
1336
+ for (var i = 0; i < divs.length; i++) {
1337
+ var div = divs[i]; // @@ TODO Remove the need to manipulate HTML elements
1338
+
1339
+ if (div.setUserCallback) {
1340
+ try {
1341
+ div.setUserCallback(webIdURI);
1342
+ var parent = div.parentNode;
1343
+
1344
+ if (parent) {
1345
+ parent.removeChild(div);
1020
1346
  }
1347
+ } catch (e) {
1348
+ debug.log("## Error satisfying login box: ".concat(e));
1349
+ div.appendChild(widgets.errorMessageBlock(dom, e));
1350
+ }
1021
1351
  }
1352
+ }
1353
+ }
1354
+ });
1355
+ signInPopUpButton.addEventListener('click', function () {
1356
+ var offline = offlineTestID();
1357
+ if (offline) return setUserCallback(offline.uri);
1358
+ renderSignInPopup(dom);
1359
+ }, false); // Sign up button
1360
+
1361
+ var signupButton = dom.createElement('input');
1362
+ box.appendChild(signupButton);
1363
+ signupButton.setAttribute('type', 'button');
1364
+ signupButton.setAttribute('value', 'Sign Up for Solid');
1365
+ signupButton.setAttribute('style', "".concat(signInButtonStyle, "background-color: #efe;"));
1366
+ signupButton.addEventListener('click', function (_event) {
1367
+ var signupMgr = new _signup.Signup();
1368
+ signupMgr.signup().then(function (uri) {
1369
+ debug.log('signInOrSignUpBox signed up ' + uri);
1370
+ setUserCallback(uri);
1022
1371
  });
1023
- signInPopUpButton.addEventListener('click', function () {
1024
- var offline = offlineTestID();
1025
- if (offline)
1026
- return setUserCallback(offline.uri);
1027
- renderSignInPopup(dom);
1028
- }, false);
1029
- // Sign up button
1030
- var signupButton = dom.createElement('input');
1031
- box.appendChild(signupButton);
1032
- signupButton.setAttribute('type', 'button');
1033
- signupButton.setAttribute('value', 'Sign Up for Solid');
1034
- signupButton.setAttribute('style', "".concat(signInButtonStyle, "background-color: #efe;"));
1035
- signupButton.addEventListener('click', function (_event) {
1036
- var signupMgr = new signup_1.Signup();
1037
- signupMgr.signup().then(function (uri) {
1038
- debug.log('signInOrSignUpBox signed up ' + uri);
1039
- setUserCallback(uri);
1040
- });
1041
- }, false);
1042
- return box;
1372
+ }, false);
1373
+ return box;
1043
1374
  }
1375
+
1044
1376
  function renderSignInPopup(dom) {
1045
- var _this = this;
1046
- /**
1047
- * Issuer Menu
1048
- */
1049
- var issuerPopup = dom.createElement('div');
1050
- issuerPopup.setAttribute('style', 'position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; align-items: center;');
1051
- dom.body.appendChild(issuerPopup);
1052
- var issuerPopupBox = dom.createElement('div');
1053
- issuerPopupBox.setAttribute('style', "\n background-color: white;\n box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n -webkit-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n -moz-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n -o-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n border-radius: 4px;\n min-width: 400px;\n padding: 10px;\n ");
1054
- issuerPopup.appendChild(issuerPopupBox);
1055
- var issuerPopupBoxTopMenu = dom.createElement('div');
1056
- issuerPopupBoxTopMenu.setAttribute('style', "\n border-bottom: 1px solid #DDD;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n ");
1057
- issuerPopupBox.appendChild(issuerPopupBoxTopMenu);
1058
- var issuerPopupBoxLabel = dom.createElement('label');
1059
- issuerPopupBoxLabel.setAttribute('style', 'margin-right: 5px; font-weight: 800');
1060
- issuerPopupBoxLabel.innerText = 'Select an identity provider';
1061
- var issuerPopupBoxCloseButton = dom.createElement('button');
1062
- issuerPopupBoxCloseButton.innerHTML = '<img src="https://solid.github.io/solid-ui/src/icons/noun_1180156.svg" style="width: 2em; height: 2em;" title="Cancel">';
1063
- issuerPopupBoxCloseButton.setAttribute('style', 'background-color: transparent; border: none;');
1064
- issuerPopupBoxCloseButton.addEventListener('click', function () {
1065
- issuerPopup.remove();
1066
- });
1067
- issuerPopupBoxTopMenu.appendChild(issuerPopupBoxLabel);
1068
- issuerPopupBoxTopMenu.appendChild(issuerPopupBoxCloseButton);
1069
- var loginToIssuer = function (issuerUri) { return __awaiter(_this, void 0, void 0, function () {
1070
- var preLoginRedirectHash, err_8;
1071
- return __generator(this, function (_a) {
1072
- switch (_a.label) {
1073
- case 0:
1074
- _a.trys.push([0, 2, , 3]);
1075
- preLoginRedirectHash = new URL(window.location.href).hash;
1076
- if (preLoginRedirectHash) {
1077
- window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash);
1078
- }
1079
- window.localStorage.setItem('loginIssuer', issuerUri);
1080
- // Login
1081
- return [4 /*yield*/, exports.authSession.login({
1082
- redirectUrl: window.location.href,
1083
- oidcIssuer: issuerUri
1084
- })];
1085
- case 1:
1086
- // Login
1087
- _a.sent();
1088
- return [3 /*break*/, 3];
1089
- case 2:
1090
- err_8 = _a.sent();
1091
- (0, log_1.alert)(err_8.message);
1092
- return [3 /*break*/, 3];
1093
- case 3: return [2 /*return*/];
1094
- }
1095
- });
1096
- }); };
1097
- /**
1098
- * Text-based idp selection
1099
- */
1100
- var issuerTextContainer = dom.createElement('div');
1101
- issuerTextContainer.setAttribute('style', "\n border-bottom: 1px solid #DDD;\n display: flex;\n flex-direction: column;\n padding-top: 10px;\n ");
1102
- var issuerTextInputContainer = dom.createElement('div');
1103
- issuerTextInputContainer.setAttribute('style', "\n display: flex;\n flex-direction: row;\n ");
1104
- var issuerTextLabel = dom.createElement('label');
1105
- issuerTextLabel.innerText = 'Enter the URL of your identity provider:';
1106
- issuerTextLabel.setAttribute('style', 'color: #888');
1107
- var issuerTextInput = dom.createElement('input');
1108
- issuerTextInput.setAttribute('type', 'text');
1109
- issuerTextInput.setAttribute('style', 'margin-left: 0 !important; flex: 1; margin-right: 5px !important');
1110
- issuerTextInput.setAttribute('placeholder', 'https://example.com');
1111
- issuerTextInput.value = localStorage.getItem('loginIssuer') || '';
1112
- var issuerTextGoButton = dom.createElement('button');
1113
- issuerTextGoButton.innerText = 'Go';
1114
- issuerTextGoButton.setAttribute('style', 'margin-top: 12px; margin-bottom: 12px;');
1115
- issuerTextGoButton.addEventListener('click', function () {
1116
- loginToIssuer(issuerTextInput.value);
1117
- });
1118
- issuerTextContainer.appendChild(issuerTextLabel);
1119
- issuerTextInputContainer.appendChild(issuerTextInput);
1120
- issuerTextInputContainer.appendChild(issuerTextGoButton);
1121
- issuerTextContainer.appendChild(issuerTextInputContainer);
1122
- issuerPopupBox.appendChild(issuerTextContainer);
1123
- /**
1124
- * Button-based idp selection
1125
- */
1126
- var issuerButtonContainer = dom.createElement('div');
1127
- issuerButtonContainer.setAttribute('style', "\n display: flex;\n flex-direction: column;\n padding-top: 10px;\n ");
1128
- var issuerBottonLabel = dom.createElement('label');
1129
- issuerBottonLabel.innerText = 'Or pick an identity provider from the list below:';
1130
- issuerBottonLabel.setAttribute('style', 'color: #888');
1131
- issuerButtonContainer.appendChild(issuerBottonLabel);
1132
- getSuggestedIssuers().forEach(function (issuerInfo) {
1133
- var issuerButton = dom.createElement('button');
1134
- issuerButton.innerText = issuerInfo.name;
1135
- issuerButton.setAttribute('style', 'height: 38px; margin-top: 10px');
1136
- issuerButton.addEventListener('click', function () {
1137
- loginToIssuer(issuerInfo.uri);
1138
- });
1139
- issuerButtonContainer.appendChild(issuerButton);
1377
+ /**
1378
+ * Issuer Menu
1379
+ */
1380
+ var issuerPopup = dom.createElement('div');
1381
+ issuerPopup.setAttribute('style', 'position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; align-items: center;');
1382
+ dom.body.appendChild(issuerPopup);
1383
+ var issuerPopupBox = dom.createElement('div');
1384
+ issuerPopupBox.setAttribute('style', "\n background-color: white;\n box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n -webkit-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n -moz-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n -o-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);\n border-radius: 4px;\n min-width: 400px;\n padding: 10px;\n ");
1385
+ issuerPopup.appendChild(issuerPopupBox);
1386
+ var issuerPopupBoxTopMenu = dom.createElement('div');
1387
+ issuerPopupBoxTopMenu.setAttribute('style', "\n border-bottom: 1px solid #DDD;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n ");
1388
+ issuerPopupBox.appendChild(issuerPopupBoxTopMenu);
1389
+ var issuerPopupBoxLabel = dom.createElement('label');
1390
+ issuerPopupBoxLabel.setAttribute('style', 'margin-right: 5px; font-weight: 800');
1391
+ issuerPopupBoxLabel.innerText = 'Select an identity provider';
1392
+ var issuerPopupBoxCloseButton = dom.createElement('button');
1393
+ issuerPopupBoxCloseButton.innerHTML = '<img src="https://solid.github.io/solid-ui/src/icons/noun_1180156.svg" style="width: 2em; height: 2em;" title="Cancel">';
1394
+ issuerPopupBoxCloseButton.setAttribute('style', 'background-color: transparent; border: none;');
1395
+ issuerPopupBoxCloseButton.addEventListener('click', function () {
1396
+ issuerPopup.remove();
1397
+ });
1398
+ issuerPopupBoxTopMenu.appendChild(issuerPopupBoxLabel);
1399
+ issuerPopupBoxTopMenu.appendChild(issuerPopupBoxCloseButton);
1400
+
1401
+ var loginToIssuer = /*#__PURE__*/function () {
1402
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(issuerUri) {
1403
+ var preLoginRedirectHash;
1404
+ return _regenerator["default"].wrap(function _callee$(_context) {
1405
+ while (1) {
1406
+ switch (_context.prev = _context.next) {
1407
+ case 0:
1408
+ _context.prev = 0;
1409
+ // Save hash
1410
+ preLoginRedirectHash = new URL(window.location.href).hash;
1411
+
1412
+ if (preLoginRedirectHash) {
1413
+ window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash);
1414
+ }
1415
+
1416
+ window.localStorage.setItem('loginIssuer', issuerUri); // Login
1417
+
1418
+ _context.next = 6;
1419
+ return authSession.login({
1420
+ redirectUrl: window.location.href,
1421
+ oidcIssuer: issuerUri
1422
+ });
1423
+
1424
+ case 6:
1425
+ _context.next = 11;
1426
+ break;
1427
+
1428
+ case 8:
1429
+ _context.prev = 8;
1430
+ _context.t0 = _context["catch"](0);
1431
+ (0, _log.alert)(_context.t0.message);
1432
+
1433
+ case 11:
1434
+ case "end":
1435
+ return _context.stop();
1436
+ }
1437
+ }
1438
+ }, _callee, null, [[0, 8]]);
1439
+ }));
1440
+
1441
+ return function loginToIssuer(_x17) {
1442
+ return _ref.apply(this, arguments);
1443
+ };
1444
+ }();
1445
+ /**
1446
+ * Text-based idp selection
1447
+ */
1448
+
1449
+
1450
+ var issuerTextContainer = dom.createElement('div');
1451
+ issuerTextContainer.setAttribute('style', "\n border-bottom: 1px solid #DDD;\n display: flex;\n flex-direction: column;\n padding-top: 10px;\n ");
1452
+ var issuerTextInputContainer = dom.createElement('div');
1453
+ issuerTextInputContainer.setAttribute('style', "\n display: flex;\n flex-direction: row;\n ");
1454
+ var issuerTextLabel = dom.createElement('label');
1455
+ issuerTextLabel.innerText = 'Enter the URL of your identity provider:';
1456
+ issuerTextLabel.setAttribute('style', 'color: #888');
1457
+ var issuerTextInput = dom.createElement('input');
1458
+ issuerTextInput.setAttribute('type', 'text');
1459
+ issuerTextInput.setAttribute('style', 'margin-left: 0 !important; flex: 1; margin-right: 5px !important');
1460
+ issuerTextInput.setAttribute('placeholder', 'https://example.com');
1461
+ issuerTextInput.value = localStorage.getItem('loginIssuer') || '';
1462
+ var issuerTextGoButton = dom.createElement('button');
1463
+ issuerTextGoButton.innerText = 'Go';
1464
+ issuerTextGoButton.setAttribute('style', 'margin-top: 12px; margin-bottom: 12px;');
1465
+ issuerTextGoButton.addEventListener('click', function () {
1466
+ loginToIssuer(issuerTextInput.value);
1467
+ });
1468
+ issuerTextContainer.appendChild(issuerTextLabel);
1469
+ issuerTextInputContainer.appendChild(issuerTextInput);
1470
+ issuerTextInputContainer.appendChild(issuerTextGoButton);
1471
+ issuerTextContainer.appendChild(issuerTextInputContainer);
1472
+ issuerPopupBox.appendChild(issuerTextContainer);
1473
+ /**
1474
+ * Button-based idp selection
1475
+ */
1476
+
1477
+ var issuerButtonContainer = dom.createElement('div');
1478
+ issuerButtonContainer.setAttribute('style', "\n display: flex;\n flex-direction: column;\n padding-top: 10px;\n ");
1479
+ var issuerBottonLabel = dom.createElement('label');
1480
+ issuerBottonLabel.innerText = 'Or pick an identity provider from the list below:';
1481
+ issuerBottonLabel.setAttribute('style', 'color: #888');
1482
+ issuerButtonContainer.appendChild(issuerBottonLabel);
1483
+ getSuggestedIssuers().forEach(function (issuerInfo) {
1484
+ var issuerButton = dom.createElement('button');
1485
+ issuerButton.innerText = issuerInfo.name;
1486
+ issuerButton.setAttribute('style', 'height: 38px; margin-top: 10px');
1487
+ issuerButton.addEventListener('click', function () {
1488
+ loginToIssuer(issuerInfo.uri);
1140
1489
  });
1141
- issuerPopupBox.appendChild(issuerButtonContainer);
1490
+ issuerButtonContainer.appendChild(issuerButton);
1491
+ });
1492
+ issuerPopupBox.appendChild(issuerButtonContainer);
1142
1493
  }
1143
- exports.renderSignInPopup = renderSignInPopup;
1144
1494
  /**
1145
1495
  * @returns - A list of suggested OIDC issuers
1146
1496
  */
1497
+
1498
+
1147
1499
  function getSuggestedIssuers() {
1148
- // Suggest a default list of OIDC issuers
1149
- var issuers = __spreadArray([], DEFAULT_ISSUERS, true);
1150
- // Suggest the current host if not already included
1151
- var _a = new URL(location.href), host = _a.host, origin = _a.origin;
1152
- var hosts = issuers.map(function (_a) {
1153
- var uri = _a.uri;
1154
- return new URL(uri).host;
1500
+ // Suggest a default list of OIDC issuers
1501
+ var issuers = [].concat(DEFAULT_ISSUERS); // Suggest the current host if not already included
1502
+
1503
+ var _URL = new URL(location.href),
1504
+ host = _URL.host,
1505
+ origin = _URL.origin;
1506
+
1507
+ var hosts = issuers.map(function (_ref2) {
1508
+ var uri = _ref2.uri;
1509
+ return new URL(uri).host;
1510
+ });
1511
+
1512
+ if (!hosts.includes(host) && !hosts.some(function (existing) {
1513
+ return isSubdomainOf(host, existing);
1514
+ })) {
1515
+ issuers.unshift({
1516
+ name: host,
1517
+ uri: origin
1155
1518
  });
1156
- if (!hosts.includes(host) && !hosts.some(function (existing) { return isSubdomainOf(host, existing); })) {
1157
- issuers.unshift({ name: host, uri: origin });
1158
- }
1159
- return issuers;
1519
+ }
1520
+
1521
+ return issuers;
1160
1522
  }
1523
+
1161
1524
  function isSubdomainOf(subdomain, domain) {
1162
- var dot = subdomain.length - domain.length - 1;
1163
- return dot > 0 && subdomain[dot] === '.' && subdomain.endsWith(domain);
1525
+ var dot = subdomain.length - domain.length - 1;
1526
+ return dot > 0 && subdomain[dot] === '.' && subdomain.endsWith(domain);
1164
1527
  }
1165
1528
  /**
1166
1529
  * @returns {Promise<string|null>} Resolves with WebID URI or null
1167
1530
  */
1531
+
1532
+
1168
1533
  function webIdFromSession(session) {
1169
- var webId = (session === null || session === void 0 ? void 0 : session.webId) && session.isLoggedIn ? session.webId : null;
1170
- if (webId) {
1171
- saveUser(webId);
1172
- }
1173
- return webId;
1534
+ var webId = session !== null && session !== void 0 && session.webId && session.isLoggedIn ? session.webId : null;
1535
+
1536
+ if (webId) {
1537
+ saveUser(webId);
1538
+ }
1539
+
1540
+ return webId;
1174
1541
  }
1175
1542
  /**
1176
1543
  * @returns {Promise<string|null>} Resolves with WebID URI or null
1177
1544
  */
1545
+
1178
1546
  /*
1179
1547
  function checkCurrentUser () {
1180
1548
  return checkUser()
1181
1549
  }
1182
1550
  */
1551
+
1183
1552
  /**
1184
1553
  * Retrieves currently logged in webId from either
1185
1554
  * defaultTestUser or SolidAuth
@@ -1187,68 +1556,11 @@ function checkCurrentUser () {
1187
1556
  *
1188
1557
  * @returns Resolves with webId uri, if no callback provided
1189
1558
  */
1190
- function checkUser(setUserCallback) {
1191
- return __awaiter(this, void 0, void 0, function () {
1192
- var preLoginRedirectHash, postLoginRedirectHash, curUrl, me, webId;
1193
- return __generator(this, function (_a) {
1194
- switch (_a.label) {
1195
- case 0:
1196
- preLoginRedirectHash = new URL(window.location.href).hash;
1197
- if (preLoginRedirectHash) {
1198
- window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash);
1199
- }
1200
- exports.authSession.onSessionRestore(function (url) {
1201
- if (document.location.toString() !== url)
1202
- history.replaceState(null, '', url);
1203
- });
1204
- /**
1205
- * Handle a successful authentication redirect
1206
- */
1207
- return [4 /*yield*/, exports.authSession
1208
- .handleIncomingRedirect({
1209
- restorePreviousSession: true,
1210
- url: window.location.href
1211
- })
1212
- // Check to see if a hash was stored in local storage
1213
- ];
1214
- case 1:
1215
- /**
1216
- * Handle a successful authentication redirect
1217
- */
1218
- _a.sent();
1219
- postLoginRedirectHash = window.localStorage.getItem('preLoginRedirectHash');
1220
- if (postLoginRedirectHash) {
1221
- curUrl = new URL(window.location.href);
1222
- if (curUrl.hash !== postLoginRedirectHash) {
1223
- if (history.pushState) {
1224
- // console.log('Setting window.location.has using pushState')
1225
- history.pushState(null, document.title, postLoginRedirectHash);
1226
- }
1227
- else {
1228
- // console.warn('Setting window.location.has using location.hash')
1229
- location.hash = postLoginRedirectHash;
1230
- }
1231
- curUrl.hash = postLoginRedirectHash;
1232
- }
1233
- // See https://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document
1234
- // indow.location.href = curUrl.toString()// @@ See https://developer.mozilla.org/en-US/docs/Web/API/Window/location
1235
- window.localStorage.setItem('preLoginRedirectHash', '');
1236
- }
1237
- me = defaultTestUser();
1238
- if (me) {
1239
- return [2 /*return*/, Promise.resolve(setUserCallback ? setUserCallback(me) : me)];
1240
- }
1241
- webId = webIdFromSession(exports.authSession.info);
1242
- me = saveUser(webId);
1243
- if (me) {
1244
- debug.log("(Logged in as ".concat(me, " by authentication)"));
1245
- }
1246
- return [2 /*return*/, Promise.resolve(setUserCallback ? setUserCallback(me) : me)];
1247
- }
1248
- });
1249
- });
1559
+
1560
+
1561
+ function checkUser(_x18) {
1562
+ return _checkUser.apply(this, arguments);
1250
1563
  }
1251
- exports.checkUser = checkUser;
1252
1564
  /**
1253
1565
  * Login status box
1254
1566
  *
@@ -1259,135 +1571,259 @@ exports.checkUser = checkUser;
1259
1571
  *
1260
1572
  * @returns
1261
1573
  */
1262
- function loginStatusBox(dom, listener, options) {
1263
- if (listener === void 0) { listener = null; }
1264
- if (options === void 0) { options = {}; }
1265
- // 20190630
1266
- var me = defaultTestUser();
1267
- // @@ TODO Remove the need to cast HTML element to any
1268
- var box = dom.createElement('div');
1269
- function setIt(newidURI) {
1270
- if (!newidURI) {
1271
- return;
1272
- }
1273
- var uri = newidURI.uri || newidURI;
1274
- // UI.preferences.set('me', uri)
1275
- me = (0, rdflib_1.sym)(uri);
1276
- box.refresh();
1277
- if (listener)
1278
- listener(me.uri);
1279
- }
1280
- function logoutButtonHandler(_event) {
1281
- // UI.preferences.set('me', '')
1282
- exports.authSession.logout().then(function () {
1283
- var message = "Your WebID was ".concat(me, ". It has been forgotten.");
1284
- me = null;
1285
- try {
1286
- (0, log_1.alert)(message);
1287
- }
1288
- catch (e) {
1289
- window.alert(message);
1574
+
1575
+
1576
+ function _checkUser() {
1577
+ _checkUser = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(setUserCallback) {
1578
+ var preLoginRedirectHash, postLoginRedirectHash, curUrl, me, webId;
1579
+ return _regenerator["default"].wrap(function _callee16$(_context16) {
1580
+ while (1) {
1581
+ switch (_context16.prev = _context16.next) {
1582
+ case 0:
1583
+ // Save hash for "restorePreviousSession"
1584
+ preLoginRedirectHash = new URL(window.location.href).hash;
1585
+
1586
+ if (preLoginRedirectHash) {
1587
+ window.localStorage.setItem('preLoginRedirectHash', preLoginRedirectHash);
1290
1588
  }
1291
- box.refresh();
1292
- if (listener)
1293
- listener(null);
1294
- }, function (err) {
1295
- (0, log_1.alert)('Fail to log out:' + err);
1296
- });
1297
- }
1298
- function logoutButton(me, options) {
1299
- var signInButtonStyle = options.buttonStyle || getDefaultSignInButtonStyle();
1300
- var logoutLabel = 'WebID logout';
1301
- if (me) {
1302
- var nick = logic_1.solidLogicSingleton.store.any(me, ns.foaf('nick')) ||
1303
- logic_1.solidLogicSingleton.store.any(me, ns.foaf('name'));
1304
- if (nick) {
1305
- logoutLabel = 'Logout ' + nick.value;
1589
+
1590
+ authSession.onSessionRestore(function (url) {
1591
+ if (document.location.toString() !== url) history.replaceState(null, '', url);
1592
+ });
1593
+ /**
1594
+ * Handle a successful authentication redirect
1595
+ */
1596
+
1597
+ _context16.next = 5;
1598
+ return authSession.handleIncomingRedirect({
1599
+ restorePreviousSession: true,
1600
+ url: window.location.href
1601
+ });
1602
+
1603
+ case 5:
1604
+ // Check to see if a hash was stored in local storage
1605
+ postLoginRedirectHash = window.localStorage.getItem('preLoginRedirectHash');
1606
+
1607
+ if (postLoginRedirectHash) {
1608
+ curUrl = new URL(window.location.href);
1609
+
1610
+ if (curUrl.hash !== postLoginRedirectHash) {
1611
+ if (history.pushState) {
1612
+ // console.log('Setting window.location.has using pushState')
1613
+ history.pushState(null, document.title, postLoginRedirectHash);
1614
+ } else {
1615
+ // console.warn('Setting window.location.has using location.hash')
1616
+ location.hash = postLoginRedirectHash;
1617
+ }
1618
+
1619
+ curUrl.hash = postLoginRedirectHash;
1620
+ } // See https://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document
1621
+ // indow.location.href = curUrl.toString()// @@ See https://developer.mozilla.org/en-US/docs/Web/API/Window/location
1622
+
1623
+
1624
+ window.localStorage.setItem('preLoginRedirectHash', '');
1625
+ } // Check to see if already logged in / have the WebID
1626
+
1627
+
1628
+ me = defaultTestUser();
1629
+
1630
+ if (!me) {
1631
+ _context16.next = 10;
1632
+ break;
1306
1633
  }
1307
- }
1308
- var signOutButton = dom.createElement('input');
1309
- // signOutButton.className = 'WebIDCancelButton'
1310
- signOutButton.setAttribute('type', 'button');
1311
- signOutButton.setAttribute('value', logoutLabel);
1312
- signOutButton.setAttribute('style', "".concat(signInButtonStyle, "background-color: #eee;"));
1313
- signOutButton.addEventListener('click', logoutButtonHandler, false);
1314
- return signOutButton;
1315
- }
1316
- box.refresh = function () {
1317
- var sessionInfo = exports.authSession.info;
1318
- if (sessionInfo && sessionInfo.webId && sessionInfo.isLoggedIn) {
1319
- me = (0, rdflib_1.sym)(sessionInfo.webId);
1320
- }
1321
- else {
1322
- me = null;
1323
- }
1324
- if ((me && box.me !== me.uri) || (!me && box.me)) {
1325
- widgets.clearElement(box);
1634
+
1635
+ return _context16.abrupt("return", Promise.resolve(setUserCallback ? setUserCallback(me) : me));
1636
+
1637
+ case 10:
1638
+ // doc = solidLogicSingleton.store.any(doc, ns.link('userMirror')) || doc
1639
+ webId = webIdFromSession(authSession.info);
1640
+ me = saveUser(webId);
1641
+
1326
1642
  if (me) {
1327
- box.appendChild(logoutButton(me, options));
1328
- }
1329
- else {
1330
- box.appendChild(signInOrSignUpBox(dom, setIt, options));
1643
+ debug.log("(Logged in as ".concat(me, " by authentication)"));
1331
1644
  }
1645
+
1646
+ return _context16.abrupt("return", Promise.resolve(setUserCallback ? setUserCallback(me) : me));
1647
+
1648
+ case 14:
1649
+ case "end":
1650
+ return _context16.stop();
1332
1651
  }
1333
- box.me = me ? me.uri : null;
1334
- };
1335
- function trackSession() {
1336
- var sessionInfo = exports.authSession.info;
1337
- if (sessionInfo && sessionInfo.webId && sessionInfo.isLoggedIn) {
1338
- me = (0, rdflib_1.sym)(sessionInfo.webId);
1339
- }
1340
- else {
1341
- me = null;
1342
- }
1343
- box.refresh();
1652
+ }
1653
+ }, _callee16);
1654
+ }));
1655
+ return _checkUser.apply(this, arguments);
1656
+ }
1657
+
1658
+ function loginStatusBox(dom) {
1659
+ var listener = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1660
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1661
+ // 20190630
1662
+ var me = defaultTestUser(); // @@ TODO Remove the need to cast HTML element to any
1663
+
1664
+ var box = dom.createElement('div');
1665
+
1666
+ function setIt(newidURI) {
1667
+ if (!newidURI) {
1668
+ return;
1344
1669
  }
1345
- trackSession();
1346
- exports.authSession.onLogin(trackSession);
1347
- exports.authSession.onLogout(trackSession);
1348
- box.me = '99999'; // Force refresh
1670
+
1671
+ var uri = newidURI.uri || newidURI; // UI.preferences.set('me', uri)
1672
+
1673
+ me = (0, _rdflib.sym)(uri);
1349
1674
  box.refresh();
1350
- return box;
1351
- }
1352
- exports.loginStatusBox = loginStatusBox;
1353
- exports.authSession.onLogout(function () { return __awaiter(void 0, void 0, void 0, function () {
1354
- var issuer, wellKnownUri, wellKnownResult, openidConfiguration, err_9;
1355
- return __generator(this, function (_a) {
1356
- switch (_a.label) {
1357
- case 0:
1358
- issuer = window.localStorage.getItem('loginIssuer');
1359
- if (!issuer) return [3 /*break*/, 7];
1360
- _a.label = 1;
1361
- case 1:
1362
- _a.trys.push([1, 6, , 7]);
1363
- wellKnownUri = new URL(issuer);
1364
- wellKnownUri.pathname = '/.well-known/openid-configuration';
1365
- return [4 /*yield*/, fetch(wellKnownUri.toString())];
1366
- case 2:
1367
- wellKnownResult = _a.sent();
1368
- if (!(wellKnownResult.status === 200)) return [3 /*break*/, 5];
1369
- return [4 /*yield*/, wellKnownResult.json()];
1370
- case 3:
1371
- openidConfiguration = _a.sent();
1372
- if (!(openidConfiguration && openidConfiguration.end_session_endpoint)) return [3 /*break*/, 5];
1373
- return [4 /*yield*/, fetch(openidConfiguration.end_session_endpoint, { credentials: 'include' })];
1374
- case 4:
1375
- _a.sent();
1376
- _a.label = 5;
1377
- case 5: return [3 /*break*/, 7];
1378
- case 6:
1379
- err_9 = _a.sent();
1380
- return [3 /*break*/, 7];
1381
- case 7:
1382
- window.location.reload();
1383
- return [2 /*return*/];
1384
- }
1675
+ if (listener) listener(me.uri);
1676
+ }
1677
+
1678
+ function logoutButtonHandler(_event) {
1679
+ // UI.preferences.set('me', '')
1680
+ authSession.logout().then(function () {
1681
+ var message = "Your WebID was ".concat(me, ". It has been forgotten.");
1682
+ me = null;
1683
+
1684
+ try {
1685
+ (0, _log.alert)(message);
1686
+ } catch (e) {
1687
+ window.alert(message);
1688
+ }
1689
+
1690
+ box.refresh();
1691
+ if (listener) listener(null);
1692
+ }, function (err) {
1693
+ (0, _log.alert)('Fail to log out:' + err);
1385
1694
  });
1386
- }); });
1695
+ }
1696
+
1697
+ function logoutButton(me, options) {
1698
+ var signInButtonStyle = options.buttonStyle || getDefaultSignInButtonStyle();
1699
+ var logoutLabel = 'WebID logout';
1700
+
1701
+ if (me) {
1702
+ var nick = _logic.solidLogicSingleton.store.any(me, ns.foaf('nick')) || _logic.solidLogicSingleton.store.any(me, ns.foaf('name'));
1703
+
1704
+ if (nick) {
1705
+ logoutLabel = 'Logout ' + nick.value;
1706
+ }
1707
+ }
1708
+
1709
+ var signOutButton = dom.createElement('input'); // signOutButton.className = 'WebIDCancelButton'
1710
+
1711
+ signOutButton.setAttribute('type', 'button');
1712
+ signOutButton.setAttribute('value', logoutLabel);
1713
+ signOutButton.setAttribute('style', "".concat(signInButtonStyle, "background-color: #eee;"));
1714
+ signOutButton.addEventListener('click', logoutButtonHandler, false);
1715
+ return signOutButton;
1716
+ }
1717
+
1718
+ box.refresh = function () {
1719
+ var sessionInfo = authSession.info;
1720
+
1721
+ if (sessionInfo && sessionInfo.webId && sessionInfo.isLoggedIn) {
1722
+ me = (0, _rdflib.sym)(sessionInfo.webId);
1723
+ } else {
1724
+ me = null;
1725
+ }
1726
+
1727
+ if (me && box.me !== me.uri || !me && box.me) {
1728
+ widgets.clearElement(box);
1729
+
1730
+ if (me) {
1731
+ box.appendChild(logoutButton(me, options));
1732
+ } else {
1733
+ box.appendChild(signInOrSignUpBox(dom, setIt, options));
1734
+ }
1735
+ }
1736
+
1737
+ box.me = me ? me.uri : null;
1738
+ };
1739
+
1740
+ function trackSession() {
1741
+ var sessionInfo = authSession.info;
1742
+
1743
+ if (sessionInfo && sessionInfo.webId && sessionInfo.isLoggedIn) {
1744
+ me = (0, _rdflib.sym)(sessionInfo.webId);
1745
+ } else {
1746
+ me = null;
1747
+ }
1748
+
1749
+ box.refresh();
1750
+ }
1751
+
1752
+ trackSession();
1753
+ authSession.onLogin(trackSession);
1754
+ authSession.onLogout(trackSession);
1755
+ box.me = '99999'; // Force refresh
1756
+
1757
+ box.refresh();
1758
+ return box;
1759
+ }
1760
+
1761
+ authSession.onLogout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
1762
+ var issuer, wellKnownUri, wellKnownResult, openidConfiguration;
1763
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
1764
+ while (1) {
1765
+ switch (_context2.prev = _context2.next) {
1766
+ case 0:
1767
+ issuer = window.localStorage.getItem('loginIssuer');
1768
+
1769
+ if (!issuer) {
1770
+ _context2.next = 19;
1771
+ break;
1772
+ }
1773
+
1774
+ _context2.prev = 2;
1775
+ wellKnownUri = new URL(issuer);
1776
+ wellKnownUri.pathname = '/.well-known/openid-configuration';
1777
+ _context2.next = 7;
1778
+ return fetch(wellKnownUri.toString());
1779
+
1780
+ case 7:
1781
+ wellKnownResult = _context2.sent;
1782
+
1783
+ if (!(wellKnownResult.status === 200)) {
1784
+ _context2.next = 15;
1785
+ break;
1786
+ }
1787
+
1788
+ _context2.next = 11;
1789
+ return wellKnownResult.json();
1790
+
1791
+ case 11:
1792
+ openidConfiguration = _context2.sent;
1793
+
1794
+ if (!(openidConfiguration && openidConfiguration.end_session_endpoint)) {
1795
+ _context2.next = 15;
1796
+ break;
1797
+ }
1798
+
1799
+ _context2.next = 15;
1800
+ return fetch(openidConfiguration.end_session_endpoint, {
1801
+ credentials: 'include'
1802
+ });
1803
+
1804
+ case 15:
1805
+ _context2.next = 19;
1806
+ break;
1807
+
1808
+ case 17:
1809
+ _context2.prev = 17;
1810
+ _context2.t0 = _context2["catch"](2);
1811
+
1812
+ case 19:
1813
+ window.location.reload();
1814
+
1815
+ case 20:
1816
+ case "end":
1817
+ return _context2.stop();
1818
+ }
1819
+ }
1820
+ }, _callee2, null, [[2, 17]]);
1821
+ })));
1387
1822
  /**
1388
1823
  * Workspace selection etc
1389
1824
  * See https://github.com/solid/userguide/issues/16
1390
1825
  */
1826
+
1391
1827
  /**
1392
1828
  * Returns a UI object which, if it selects a workspace,
1393
1829
  * will callback(workspace, newBase).
@@ -1406,209 +1842,266 @@ exports.authSession.onLogout(function () { return __awaiter(void 0, void 0, void
1406
1842
  * @param appDetails
1407
1843
  * @param callbackWS
1408
1844
  */
1845
+
1409
1846
  function selectWorkspace(dom, appDetails, callbackWS) {
1410
- var noun = appDetails.noun;
1411
- var appPathSegment = appDetails.appPathSegment;
1412
- var me = defaultTestUser();
1413
- var box = dom.createElement('div');
1414
- var context = { me: me, dom: dom, div: box };
1415
- function say(s, background) {
1416
- box.appendChild(widgets.errorMessageBlock(dom, s, background));
1847
+ var noun = appDetails.noun;
1848
+ var appPathSegment = appDetails.appPathSegment;
1849
+ var me = defaultTestUser();
1850
+ var box = dom.createElement('div');
1851
+ var context = {
1852
+ me: me,
1853
+ dom: dom,
1854
+ div: box
1855
+ };
1856
+
1857
+ function say(s, background) {
1858
+ box.appendChild(widgets.errorMessageBlock(dom, s, background));
1859
+ }
1860
+
1861
+ function figureOutBase(ws) {
1862
+ var newBaseNode = _logic.solidLogicSingleton.store.any(ws, ns.space('uriPrefix'));
1863
+
1864
+ var newBaseString;
1865
+
1866
+ if (!newBaseNode) {
1867
+ newBaseString = ws.uri.split('#')[0];
1868
+ } else {
1869
+ newBaseString = newBaseNode.value;
1417
1870
  }
1418
- function figureOutBase(ws) {
1419
- var newBaseNode = logic_1.solidLogicSingleton.store.any(ws, ns.space('uriPrefix'));
1420
- var newBaseString;
1421
- if (!newBaseNode) {
1422
- newBaseString = ws.uri.split('#')[0];
1423
- }
1424
- else {
1425
- newBaseString = newBaseNode.value;
1426
- }
1427
- if (newBaseString.slice(-1) !== '/') {
1428
- debug.log("".concat(appPathSegment, ": No / at end of uriPrefix ").concat(newBaseString)); // @@ paramater?
1429
- newBaseString = "".concat(newBaseString, "/");
1430
- }
1431
- var now = new Date();
1432
- newBaseString += "".concat(appPathSegment, "/id").concat(now.getTime(), "/"); // unique id
1433
- return newBaseString;
1871
+
1872
+ if (newBaseString.slice(-1) !== '/') {
1873
+ debug.log("".concat(appPathSegment, ": No / at end of uriPrefix ").concat(newBaseString)); // @@ paramater?
1874
+
1875
+ newBaseString = "".concat(newBaseString, "/");
1434
1876
  }
1435
- function displayOptions(context) {
1436
- // console.log('displayOptions!', context)
1437
- function makeNewWorkspace(_event) {
1438
- return __awaiter(this, void 0, void 0, function () {
1439
- var row, cell, newBase, _a, newWs, newData;
1440
- return __generator(this, function (_b) {
1441
- switch (_b.label) {
1442
- case 0:
1443
- row = table.appendChild(dom.createElement('tr'));
1444
- cell = row.appendChild(dom.createElement('td'));
1445
- cell.setAttribute('colspan', '3');
1446
- cell.style.padding = '0.5em';
1447
- _a = encodeURI;
1448
- return [4 /*yield*/, widgets.askName(dom, logic_1.solidLogicSingleton.store, cell, ns.solid('URL'), ns.space('Workspace'), 'Workspace')];
1449
- case 1:
1450
- newBase = _a.apply(void 0, [_b.sent()]);
1451
- newWs = widgets.newThing(context.preferencesFile);
1452
- newData = [(0, rdflib_1.st)(context.me, ns.space('workspace'), newWs, context.preferencesFile),
1453
- // eslint-disable-next-line camelcase
1454
- (0, rdflib_1.st)(newWs, ns.space('uriPrefix'), newBase, context.preferencesFile)];
1455
- if (!logic_1.solidLogicSingleton.store.updater) {
1456
- throw new Error('store has no updater');
1457
- }
1458
- return [4 /*yield*/, logic_1.solidLogicSingleton.store.updater.update([], newData)
1459
- // @@ now refresh list of workspaces
1460
- ];
1461
- case 2:
1462
- _b.sent();
1463
- return [2 /*return*/];
1464
- }
1465
- });
1466
- });
1467
- }
1468
- // const status = ''
1469
- var id = context.me;
1470
- var preferencesFile = context.preferencesFile;
1471
- var newBase = null;
1472
- // A workspace specifically defined in the private preference file:
1473
- var w = logic_1.solidLogicSingleton.store.each(id, ns.space('workspace'), undefined, preferencesFile); // Only trust preference file here
1474
- // A workspace in a storage in the public profile:
1475
- var storages = logic_1.solidLogicSingleton.store.each(id, ns.space('storage')); // @@ No provenance requirement at the moment
1476
- if (w.length === 0 && storages) {
1477
- say("You don't seem to have any workspaces. You have ".concat(storages.length, " storage spaces."), 'white');
1478
- storages.map(function (s) {
1479
- w = w.concat(logic_1.solidLogicSingleton.store.each(s, ns.ldp('contains')));
1480
- return w;
1481
- }).filter(function (file) {
1482
- return (file.id) ? ['public', 'private'].includes(file.id().toLowerCase()) : '';
1483
- });
1484
- }
1485
- if (w.length === 1) {
1486
- say("Workspace used: ".concat(w[0].uri), 'white'); // @@ allow user to see URI
1487
- newBase = figureOutBase(w[0]);
1488
- // callbackWS(w[0], newBase)
1489
- // } else if (w.length === 0) {
1490
- }
1491
- // Prompt for ws selection or creation
1492
- // say( w.length + " workspaces for " + id + "Choose one.");
1493
- var table = dom.createElement('table');
1494
- table.setAttribute('style', 'border-collapse:separate; border-spacing: 0.5em;');
1495
- // const popup = window.open(undefined, '_blank', { height: 300, width:400 }, false)
1496
- box.appendChild(table);
1497
- // Add a field for directly adding the URI yourself
1498
- // const hr = box.appendChild(dom.createElement('hr')) // @@
1499
- box.appendChild(dom.createElement('hr')); // @@
1500
- var p = box.appendChild(dom.createElement('p'));
1501
- p.style = style_1.commentStyle;
1502
- p.textContent = "Where would you like to store the data for the ".concat(noun, "?\n Give the URL of the folder where you would like the data stored.\n It can be anywhere in solid world - this URI is just an idea.");
1503
- // @@ TODO Remove the need to cast baseField to any
1504
- var baseField = box.appendChild(dom.createElement('input'));
1505
- baseField.setAttribute('type', 'text');
1506
- baseField.style = style_1.textInputStyle;
1507
- baseField.size = 80; // really a string
1508
- baseField.label = 'base URL';
1509
- baseField.autocomplete = 'on';
1510
- if (newBase) {
1511
- // set to default
1512
- baseField.value = newBase;
1513
- }
1514
- context.baseField = baseField;
1515
- box.appendChild(dom.createElement('br')); // @@
1516
- var button = box.appendChild(dom.createElement('button'));
1517
- button.style = style_1.buttonStyle;
1518
- button.textContent = "Start new ".concat(noun, " at this URI");
1519
- button.addEventListener('click', function (_event) {
1520
- var newBase = baseField.value.replace(' ', '%20'); // do not re-encode in general, as % encodings may exist
1521
- if (newBase.slice(-1) !== '/') {
1522
- newBase += '/';
1523
- }
1524
- callbackWS(null, newBase);
1525
- });
1526
- // Now go set up the table of spaces
1527
- // const row = 0
1528
- w = w.filter(function (x) {
1529
- return !logic_1.solidLogicSingleton.store.holds(x, ns.rdf('type'), // Ignore master workspaces
1530
- ns.space('MasterWorkspace'));
1531
- });
1532
- var col1, col2, col3, tr, ws, style, comment;
1533
- var cellStyle = 'height: 3em; margin: 1em; padding: 1em white; border-radius: 0.3em;';
1534
- var deselectedStyle = "".concat(cellStyle, "border: 0px;");
1535
- // const selectedStyle = cellStyle + 'border: 1px solid black;'
1536
- for (var i = 0; i < w.length; i++) {
1537
- ws = w[i];
1538
- tr = dom.createElement('tr');
1539
- if (i === 0) {
1540
- col1 = dom.createElement('td');
1541
- col1.setAttribute('rowspan', "".concat(w.length));
1542
- col1.textContent = 'Choose a workspace for this:';
1543
- col1.setAttribute('style', 'vertical-align:middle;');
1544
- tr.appendChild(col1);
1545
- }
1546
- col2 = dom.createElement('td');
1547
- style = logic_1.solidLogicSingleton.store.anyValue(ws, ns.ui('style'));
1548
- if (!style) {
1549
- // Otherwise make up arbitrary colour
1550
- var hash = function (x) {
1551
- return x.split('').reduce(function (a, b) {
1552
- a = (a << 5) - a + b.charCodeAt(0);
1553
- return a & a;
1554
- }, 0);
1555
- };
1556
- var bgcolor = "#".concat(((hash(ws.uri) & 0xffffff) | 0xc0c0c0).toString(16)); // c0c0c0 forces pale
1557
- style = "color: black ; background-color: ".concat(bgcolor, ";");
1558
- }
1559
- col2.setAttribute('style', deselectedStyle + style);
1560
- tr.target = ws.uri;
1561
- var label = logic_1.solidLogicSingleton.store.any(ws, ns.rdfs('label'));
1562
- if (!label) {
1563
- label = ws.uri.split('/').slice(-1)[0] || ws.uri.split('/').slice(-2)[0];
1564
- }
1565
- col2.textContent = label || '???';
1566
- tr.appendChild(col2);
1567
- if (i === 0) {
1568
- col3 = dom.createElement('td');
1569
- col3.setAttribute('rowspan', "".concat(w.length, "1"));
1570
- // col3.textContent = '@@@@@ remove';
1571
- col3.setAttribute('style', 'width:50%;');
1572
- tr.appendChild(col3);
1877
+
1878
+ var now = new Date();
1879
+ newBaseString += "".concat(appPathSegment, "/id").concat(now.getTime(), "/"); // unique id
1880
+
1881
+ return newBaseString;
1882
+ }
1883
+
1884
+ function displayOptions(context) {
1885
+ // console.log('displayOptions!', context)
1886
+ function makeNewWorkspace(_x19) {
1887
+ return _makeNewWorkspace.apply(this, arguments);
1888
+ } // const status = ''
1889
+
1890
+
1891
+ function _makeNewWorkspace() {
1892
+ _makeNewWorkspace = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(_event) {
1893
+ var row, cell, newBase, newWs, newData;
1894
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
1895
+ while (1) {
1896
+ switch (_context3.prev = _context3.next) {
1897
+ case 0:
1898
+ row = table.appendChild(dom.createElement('tr'));
1899
+ cell = row.appendChild(dom.createElement('td'));
1900
+ cell.setAttribute('colspan', '3');
1901
+ cell.style.padding = '0.5em';
1902
+ _context3.t0 = encodeURI;
1903
+ _context3.next = 7;
1904
+ return widgets.askName(dom, _logic.solidLogicSingleton.store, cell, ns.solid('URL'), ns.space('Workspace'), 'Workspace');
1905
+
1906
+ case 7:
1907
+ _context3.t1 = _context3.sent;
1908
+ newBase = (0, _context3.t0)(_context3.t1);
1909
+ newWs = widgets.newThing(context.preferencesFile);
1910
+ newData = [(0, _rdflib.st)(context.me, ns.space('workspace'), newWs, context.preferencesFile), // eslint-disable-next-line camelcase
1911
+ (0, _rdflib.st)(newWs, ns.space('uriPrefix'), newBase, context.preferencesFile)];
1912
+
1913
+ if (_logic.solidLogicSingleton.store.updater) {
1914
+ _context3.next = 13;
1915
+ break;
1916
+ }
1917
+
1918
+ throw new Error('store has no updater');
1919
+
1920
+ case 13:
1921
+ _context3.next = 15;
1922
+ return _logic.solidLogicSingleton.store.updater.update([], newData);
1923
+
1924
+ case 15:
1925
+ case "end":
1926
+ return _context3.stop();
1573
1927
  }
1574
- table.appendChild(tr);
1575
- comment = logic_1.solidLogicSingleton.store.any(ws, ns.rdfs('comment'));
1576
- comment = comment ? comment.value : 'Use this workspace';
1577
- col2.addEventListener('click', function (_event) {
1578
- col3.textContent = comment ? comment.value : '';
1579
- col3.setAttribute('style', deselectedStyle + style);
1580
- var button = dom.createElement('button');
1581
- button.textContent = 'Continue';
1582
- // button.setAttribute('style', style);
1583
- var newBase = figureOutBase(ws);
1584
- baseField.value = newBase; // show user proposed URI
1585
- button.addEventListener('click', function (_event) {
1586
- button.disabled = true;
1587
- callbackWS(ws, newBase);
1588
- button.textContent = '---->';
1589
- }, true); // capture vs bubble
1590
- col3.appendChild(button);
1591
- }, true); // capture vs bubble
1592
- }
1593
- // last line with "Make new workspace"
1594
- var trLast = dom.createElement('tr');
1595
- col2 = dom.createElement('td');
1596
- col2.setAttribute('style', cellStyle);
1597
- col2.textContent = '+ Make a new workspace';
1598
- col2.addEventListener('click', makeNewWorkspace);
1599
- trLast.appendChild(col2);
1600
- table.appendChild(trLast);
1601
- } // displayOptions
1602
- // console.log('kicking off async operation')
1603
- logInLoadPreferences(context) // kick off async operation
1604
- .then(displayOptions)
1605
- .catch(function (err) {
1606
- // console.log("err from async op")
1607
- box.appendChild(widgets.errorMessageBlock(context.dom, err));
1928
+ }
1929
+ }, _callee3);
1930
+ }));
1931
+ return _makeNewWorkspace.apply(this, arguments);
1932
+ }
1933
+
1934
+ var id = context.me;
1935
+ var preferencesFile = context.preferencesFile;
1936
+ var newBase = null; // A workspace specifically defined in the private preference file:
1937
+
1938
+ var w = _logic.solidLogicSingleton.store.each(id, ns.space('workspace'), undefined, preferencesFile); // Only trust preference file here
1939
+ // A workspace in a storage in the public profile:
1940
+
1941
+
1942
+ var storages = _logic.solidLogicSingleton.store.each(id, ns.space('storage')); // @@ No provenance requirement at the moment
1943
+
1944
+
1945
+ if (w.length === 0 && storages) {
1946
+ say("You don't seem to have any workspaces. You have ".concat(storages.length, " storage spaces."), 'white');
1947
+ storages.map(function (s) {
1948
+ w = w.concat(_logic.solidLogicSingleton.store.each(s, ns.ldp('contains')));
1949
+ return w;
1950
+ }).filter(function (file) {
1951
+ return file.id ? ['public', 'private'].includes(file.id().toLowerCase()) : '';
1952
+ });
1953
+ }
1954
+
1955
+ if (w.length === 1) {
1956
+ say("Workspace used: ".concat(w[0].uri), 'white'); // @@ allow user to see URI
1957
+
1958
+ newBase = figureOutBase(w[0]); // callbackWS(w[0], newBase)
1959
+ // } else if (w.length === 0) {
1960
+ } // Prompt for ws selection or creation
1961
+ // say( w.length + " workspaces for " + id + "Choose one.");
1962
+
1963
+
1964
+ var table = dom.createElement('table');
1965
+ table.setAttribute('style', 'border-collapse:separate; border-spacing: 0.5em;'); // const popup = window.open(undefined, '_blank', { height: 300, width:400 }, false)
1966
+
1967
+ box.appendChild(table); // Add a field for directly adding the URI yourself
1968
+ // const hr = box.appendChild(dom.createElement('hr')) // @@
1969
+
1970
+ box.appendChild(dom.createElement('hr')); // @@
1971
+
1972
+ var p = box.appendChild(dom.createElement('p'));
1973
+ p.style = _style.commentStyle;
1974
+ p.textContent = "Where would you like to store the data for the ".concat(noun, "?\n Give the URL of the folder where you would like the data stored.\n It can be anywhere in solid world - this URI is just an idea."); // @@ TODO Remove the need to cast baseField to any
1975
+
1976
+ var baseField = box.appendChild(dom.createElement('input'));
1977
+ baseField.setAttribute('type', 'text');
1978
+ baseField.style = _style.textInputStyle;
1979
+ baseField.size = 80; // really a string
1980
+
1981
+ baseField.label = 'base URL';
1982
+ baseField.autocomplete = 'on';
1983
+
1984
+ if (newBase) {
1985
+ // set to default
1986
+ baseField.value = newBase;
1987
+ }
1988
+
1989
+ context.baseField = baseField;
1990
+ box.appendChild(dom.createElement('br')); // @@
1991
+
1992
+ var button = box.appendChild(dom.createElement('button'));
1993
+ button.style = _style.buttonStyle;
1994
+ button.textContent = "Start new ".concat(noun, " at this URI");
1995
+ button.addEventListener('click', function (_event) {
1996
+ var newBase = baseField.value.replace(' ', '%20'); // do not re-encode in general, as % encodings may exist
1997
+
1998
+ if (newBase.slice(-1) !== '/') {
1999
+ newBase += '/';
2000
+ }
2001
+
2002
+ callbackWS(null, newBase);
2003
+ }); // Now go set up the table of spaces
2004
+ // const row = 0
2005
+
2006
+ w = w.filter(function (x) {
2007
+ return !_logic.solidLogicSingleton.store.holds(x, ns.rdf('type'), // Ignore master workspaces
2008
+ ns.space('MasterWorkspace'));
1608
2009
  });
1609
- return box; // return the box element, while login proceeds
2010
+ var col1, col2, col3, tr, ws, style, comment;
2011
+ var cellStyle = 'height: 3em; margin: 1em; padding: 1em white; border-radius: 0.3em;';
2012
+ var deselectedStyle = "".concat(cellStyle, "border: 0px;"); // const selectedStyle = cellStyle + 'border: 1px solid black;'
2013
+
2014
+ for (var i = 0; i < w.length; i++) {
2015
+ ws = w[i];
2016
+ tr = dom.createElement('tr');
2017
+
2018
+ if (i === 0) {
2019
+ col1 = dom.createElement('td');
2020
+ col1.setAttribute('rowspan', "".concat(w.length));
2021
+ col1.textContent = 'Choose a workspace for this:';
2022
+ col1.setAttribute('style', 'vertical-align:middle;');
2023
+ tr.appendChild(col1);
2024
+ }
2025
+
2026
+ col2 = dom.createElement('td');
2027
+ style = _logic.solidLogicSingleton.store.anyValue(ws, ns.ui('style'));
2028
+
2029
+ if (!style) {
2030
+ // Otherwise make up arbitrary colour
2031
+ var hash = function hash(x) {
2032
+ return x.split('').reduce(function (a, b) {
2033
+ a = (a << 5) - a + b.charCodeAt(0);
2034
+ return a & a;
2035
+ }, 0);
2036
+ };
2037
+
2038
+ var bgcolor = "#".concat((hash(ws.uri) & 0xffffff | 0xc0c0c0).toString(16)); // c0c0c0 forces pale
2039
+
2040
+ style = "color: black ; background-color: ".concat(bgcolor, ";");
2041
+ }
2042
+
2043
+ col2.setAttribute('style', deselectedStyle + style);
2044
+ tr.target = ws.uri;
2045
+
2046
+ var label = _logic.solidLogicSingleton.store.any(ws, ns.rdfs('label'));
2047
+
2048
+ if (!label) {
2049
+ label = ws.uri.split('/').slice(-1)[0] || ws.uri.split('/').slice(-2)[0];
2050
+ }
2051
+
2052
+ col2.textContent = label || '???';
2053
+ tr.appendChild(col2);
2054
+
2055
+ if (i === 0) {
2056
+ col3 = dom.createElement('td');
2057
+ col3.setAttribute('rowspan', "".concat(w.length, "1")); // col3.textContent = '@@@@@ remove';
2058
+
2059
+ col3.setAttribute('style', 'width:50%;');
2060
+ tr.appendChild(col3);
2061
+ }
2062
+
2063
+ table.appendChild(tr);
2064
+ comment = _logic.solidLogicSingleton.store.any(ws, ns.rdfs('comment'));
2065
+ comment = comment ? comment.value : 'Use this workspace';
2066
+ col2.addEventListener('click', function (_event) {
2067
+ col3.textContent = comment ? comment.value : '';
2068
+ col3.setAttribute('style', deselectedStyle + style);
2069
+ var button = dom.createElement('button');
2070
+ button.textContent = 'Continue'; // button.setAttribute('style', style);
2071
+
2072
+ var newBase = figureOutBase(ws);
2073
+ baseField.value = newBase; // show user proposed URI
2074
+
2075
+ button.addEventListener('click', function (_event) {
2076
+ button.disabled = true;
2077
+ callbackWS(ws, newBase);
2078
+ button.textContent = '---->';
2079
+ }, true); // capture vs bubble
2080
+
2081
+ col3.appendChild(button);
2082
+ }, true); // capture vs bubble
2083
+ } // last line with "Make new workspace"
2084
+
2085
+
2086
+ var trLast = dom.createElement('tr');
2087
+ col2 = dom.createElement('td');
2088
+ col2.setAttribute('style', cellStyle);
2089
+ col2.textContent = '+ Make a new workspace';
2090
+ col2.addEventListener('click', makeNewWorkspace);
2091
+ trLast.appendChild(col2);
2092
+ table.appendChild(trLast);
2093
+ } // displayOptions
2094
+ // console.log('kicking off async operation')
2095
+
2096
+
2097
+ logInLoadPreferences(context) // kick off async operation
2098
+ .then(displayOptions)["catch"](function (err) {
2099
+ // console.log("err from async op")
2100
+ box.appendChild(widgets.errorMessageBlock(context.dom, err));
2101
+ });
2102
+ return box; // return the box element, while login proceeds
1610
2103
  } // selectWorkspace
1611
- exports.selectWorkspace = selectWorkspace;
2104
+
1612
2105
  /**
1613
2106
  * Creates a new instance of an app.
1614
2107
  *
@@ -1625,70 +2118,121 @@ exports.selectWorkspace = selectWorkspace;
1625
2118
  *
1626
2119
  * @returns A div with a button in it for making a new app instance
1627
2120
  */
2121
+
2122
+
1628
2123
  function newAppInstance(dom, appDetails, callback) {
1629
- var gotWS = function (ws, base) {
1630
- // log.debug("newAppInstance: Selected workspace = " + (ws? ws.uri : 'none'))
1631
- callback(ws, base);
1632
- };
1633
- var div = dom.createElement('div');
1634
- var b = dom.createElement('button');
1635
- b.setAttribute('type', 'button');
1636
- div.appendChild(b);
1637
- b.innerHTML = "Make new ".concat(appDetails.noun);
1638
- b.addEventListener('click', function (_event) {
1639
- div.appendChild(selectWorkspace(dom, appDetails, gotWS));
1640
- }, false);
1641
- div.appendChild(b);
1642
- return div;
2124
+ var gotWS = function gotWS(ws, base) {
2125
+ // log.debug("newAppInstance: Selected workspace = " + (ws? ws.uri : 'none'))
2126
+ callback(ws, base);
2127
+ };
2128
+
2129
+ var div = dom.createElement('div');
2130
+ var b = dom.createElement('button');
2131
+ b.setAttribute('type', 'button');
2132
+ div.appendChild(b);
2133
+ b.innerHTML = "Make new ".concat(appDetails.noun);
2134
+ b.addEventListener('click', function (_event) {
2135
+ div.appendChild(selectWorkspace(dom, appDetails, gotWS));
2136
+ }, false);
2137
+ div.appendChild(b);
2138
+ return div;
1643
2139
  }
1644
- exports.newAppInstance = newAppInstance;
1645
2140
  /**
1646
2141
  * Retrieves whether the currently logged in user is a power user
1647
2142
  * and/or a developer
1648
2143
  */
2144
+
2145
+
1649
2146
  function getUserRoles() {
1650
- return __awaiter(this, void 0, void 0, function () {
1651
- var _a, me, preferencesFile, preferencesFileError, error_2;
1652
- return __generator(this, function (_b) {
1653
- switch (_b.label) {
1654
- case 0:
1655
- _b.trys.push([0, 2, , 3]);
1656
- return [4 /*yield*/, logInLoadPreferences({})];
1657
- case 1:
1658
- _a = _b.sent(), me = _a.me, preferencesFile = _a.preferencesFile, preferencesFileError = _a.preferencesFileError;
1659
- if (!preferencesFile || preferencesFileError) {
1660
- throw new Error(preferencesFileError);
1661
- }
1662
- return [2 /*return*/, logic_1.solidLogicSingleton.store.each(me, ns.rdf('type'), null, preferencesFile.doc())];
1663
- case 2:
1664
- error_2 = _b.sent();
1665
- debug.warn('Unable to fetch your preferences - this was the error: ', error_2);
1666
- return [3 /*break*/, 3];
1667
- case 3: return [2 /*return*/, []];
1668
- }
1669
- });
1670
- });
2147
+ return _getUserRoles.apply(this, arguments);
1671
2148
  }
1672
- exports.getUserRoles = getUserRoles;
1673
2149
  /**
1674
2150
  * Filters which panes should be available, based on the result of [[getUserRoles]]
1675
2151
  */
1676
- function filterAvailablePanes(panes) {
1677
- return __awaiter(this, void 0, void 0, function () {
1678
- var userRoles;
1679
- return __generator(this, function (_a) {
1680
- switch (_a.label) {
1681
- case 0: return [4 /*yield*/, getUserRoles()];
1682
- case 1:
1683
- userRoles = _a.sent();
1684
- return [2 /*return*/, panes.filter(function (pane) { return isMatchingAudience(pane, userRoles); })];
2152
+
2153
+
2154
+ function _getUserRoles() {
2155
+ _getUserRoles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17() {
2156
+ var _yield$logInLoadPrefe, me, preferencesFile, preferencesFileError;
2157
+
2158
+ return _regenerator["default"].wrap(function _callee17$(_context17) {
2159
+ while (1) {
2160
+ switch (_context17.prev = _context17.next) {
2161
+ case 0:
2162
+ _context17.prev = 0;
2163
+ _context17.next = 3;
2164
+ return logInLoadPreferences({});
2165
+
2166
+ case 3:
2167
+ _yield$logInLoadPrefe = _context17.sent;
2168
+ me = _yield$logInLoadPrefe.me;
2169
+ preferencesFile = _yield$logInLoadPrefe.preferencesFile;
2170
+ preferencesFileError = _yield$logInLoadPrefe.preferencesFileError;
2171
+
2172
+ if (!(!preferencesFile || preferencesFileError)) {
2173
+ _context17.next = 9;
2174
+ break;
1685
2175
  }
1686
- });
1687
- });
2176
+
2177
+ throw new Error(preferencesFileError);
2178
+
2179
+ case 9:
2180
+ return _context17.abrupt("return", _logic.solidLogicSingleton.store.each(me, ns.rdf('type'), null, preferencesFile.doc()));
2181
+
2182
+ case 12:
2183
+ _context17.prev = 12;
2184
+ _context17.t0 = _context17["catch"](0);
2185
+ debug.warn('Unable to fetch your preferences - this was the error: ', _context17.t0);
2186
+
2187
+ case 15:
2188
+ return _context17.abrupt("return", []);
2189
+
2190
+ case 16:
2191
+ case "end":
2192
+ return _context17.stop();
2193
+ }
2194
+ }
2195
+ }, _callee17, null, [[0, 12]]);
2196
+ }));
2197
+ return _getUserRoles.apply(this, arguments);
1688
2198
  }
1689
- exports.filterAvailablePanes = filterAvailablePanes;
2199
+
2200
+ function filterAvailablePanes(_x20) {
2201
+ return _filterAvailablePanes.apply(this, arguments);
2202
+ }
2203
+
2204
+ function _filterAvailablePanes() {
2205
+ _filterAvailablePanes = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18(panes) {
2206
+ var userRoles;
2207
+ return _regenerator["default"].wrap(function _callee18$(_context18) {
2208
+ while (1) {
2209
+ switch (_context18.prev = _context18.next) {
2210
+ case 0:
2211
+ _context18.next = 2;
2212
+ return getUserRoles();
2213
+
2214
+ case 2:
2215
+ userRoles = _context18.sent;
2216
+ return _context18.abrupt("return", panes.filter(function (pane) {
2217
+ return isMatchingAudience(pane, userRoles);
2218
+ }));
2219
+
2220
+ case 4:
2221
+ case "end":
2222
+ return _context18.stop();
2223
+ }
2224
+ }
2225
+ }, _callee18);
2226
+ }));
2227
+ return _filterAvailablePanes.apply(this, arguments);
2228
+ }
2229
+
1690
2230
  function isMatchingAudience(pane, userRoles) {
1691
- var audience = pane.audience || [];
1692
- return audience.reduce(function (isMatch, audienceRole) { return isMatch && !!userRoles.find(function (role) { return role.equals(audienceRole); }); }, true);
2231
+ var audience = pane.audience || [];
2232
+ return audience.reduce(function (isMatch, audienceRole) {
2233
+ return isMatch && !!userRoles.find(function (role) {
2234
+ return role.equals(audienceRole);
2235
+ });
2236
+ }, true);
1693
2237
  }
1694
2238
  //# sourceMappingURL=authn.js.map