Compare commits

...

5 Commits

4 changed files with 55 additions and 11 deletions

View File

@ -1,3 +1,10 @@
# [0.2.0-develop.26](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.2.0-develop.25...v0.2.0-develop.26) (2023-07-18)
### Features
* add support for loading and saving portal lists ([4fe84e8](https://git.lumeweb.com/LumeWeb/libweb/commit/4fe84e8ab47d7fadeca685e51182e67f91d4c10f))
# [0.2.0-develop.25](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.2.0-develop.24...v0.2.0-develop.25) (2023-07-18)
# [0.2.0-develop.24](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.2.0-develop.23...v0.2.0-develop.24) (2023-07-18)

12
npm-shrinkwrap.json generated
View File

@ -1,15 +1,15 @@
{
"name": "@lumeweb/libweb",
"version": "0.2.0-develop.25",
"version": "0.2.0-develop.26",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lumeweb/libweb",
"version": "0.2.0-develop.25",
"version": "0.2.0-develop.26",
"dependencies": {
"@lumeweb/community-portals": "^0.1.0-develop.6",
"@lumeweb/libportal": "^0.2.0-develop.15",
"@lumeweb/libportal": "^0.2.0-develop.16",
"@lumeweb/node-library-preset": "0.2.7",
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1"
@ -1676,9 +1676,9 @@
}
},
"node_modules/@lumeweb/libportal": {
"version": "0.2.0-develop.15",
"resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.15.tgz",
"integrity": "sha512-2N/U2+eO28eLmRGSzY4YOipl1NK8oNtqJ36Udy1eBnorejqMtq9t86srIKpZAsGkTGZiNDp3LXiR92a4c3ImYw==",
"version": "0.2.0-develop.16",
"resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.16.tgz",
"integrity": "sha512-wyzza/ttvU6I1gIs4tnYSkcT6s7MIBnUdJSNAbe6k6NsQ1w4bhBVJhEKbBru/lAEASO/PAhHGBwaOCv20rZZfA==",
"dependencies": {
"@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git",
"@noble/curves": "^1.1.0",

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/libweb",
"version": "0.2.0-develop.25",
"version": "0.2.0-develop.26",
"main": "lib/index.js",
"type": "module",
"repository": {
@ -22,7 +22,7 @@
},
"dependencies": {
"@lumeweb/community-portals": "^0.1.0-develop.6",
"@lumeweb/libportal": "^0.2.0-develop.15",
"@lumeweb/libportal": "^0.2.0-develop.16",
"@lumeweb/node-library-preset": "0.2.7",
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1"

View File

@ -13,12 +13,23 @@ let ACTIVE_PORTALS = new Set<Client>();
type PortalSessionsStore = { [id: string]: string };
const PORTAL_ID = Symbol.for("PORTAL_ID");
const PORTAL_NAME = Symbol.for("PORTAL_NAME");
export function maybeInitDefaultPortals(): ErrTuple {
if (!activePortalMasterKey) {
return [null, "activePortalMasterKey not set"];
}
for (const portal of DEFAULT_PORTAL_LIST) {
let portalsToLoad = DEFAULT_PORTAL_LIST;
const savedPortals = loadSavedPortals();
if (savedPortals) {
portalsToLoad = savedPortals;
}
for (const portal of portalsToLoad) {
addActivePortal(initPortal(portal));
}
@ -66,12 +77,17 @@ export function initPortal(portal: Portal): Client {
}
}
return new Client({
const client = new Client({
email: generatePortalEmail(portal),
portalUrl: portal.url,
privateKey: generatePortalKeyPair(portal).privateKey,
jwt: jwt as string,
});
client[PORTAL_ID] = portal.id;
client[PORTAL_NAME] = portal.name;
return client;
}
export function getPortalSessions() {
@ -79,7 +95,7 @@ export function getPortalSessions() {
return undefined;
}
let portalSessionsData = globalThis.localStorage.getItem("portals");
let portalSessionsData = globalThis.localStorage.getItem("portal_sessions");
let portalSessions: PortalSessionsStore = {};
if (portalSessions) {
portalSessions = JSON.parse(
@ -95,3 +111,24 @@ export function getPortalSessions() {
export function setActivePortals(portals: Client[]) {
ACTIVE_PORTALS = new Set<Client>(portals);
}
export function savePortals() {
const portals = [...ACTIVE_PORTALS.values()].map((item) => {
return {
id: item[PORTAL_ID],
name: item[PORTAL_NAME],
url: item.portalUrl,
} as Portal;
});
window.localStorage.setItem("portals", JSON.stringify(portals));
}
export function loadSavedPortals(): Portal[] | null {
let portals = window.localStorage.getItem("portals");
if (!portals) {
return null;
}
return JSON.parse(portals);
}