h1v3 0.3.0 → 0.6.0
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.
- package/.vscode/settings.json +3 -0
- package/dist/browser/client/auth.js +128 -0
- package/dist/browser/client/bus.js +1 -0
- package/dist/browser/{web-ui → client}/components/login.js +11 -2
- package/dist/browser/client/components/notification.html.js +25 -0
- package/dist/browser/client/components/notification.js +27 -0
- package/{src/client/web-ui → dist/browser/client}/components/partials/wa-utils.js +1 -0
- package/dist/browser/client/context.js +98 -0
- package/dist/browser/{event-store/modular.js → client/event-store.js} +21 -14
- package/{src/client/web → dist/browser/client}/events.js +5 -1
- package/dist/browser/{web/system.js → client/firebase.js} +1 -7
- package/dist/browser/client/id.js +37 -0
- package/dist/browser/client/logger.js +60 -0
- package/dist/browser/client/notifications.js +50 -0
- package/{src/client/web-ui → dist/browser/client}/system.js +10 -4
- package/dist/browser/client/team/invites.js +119 -0
- package/dist/browser/client/team/team.js +143 -0
- package/dist/browser/client/team/user.js +62 -0
- package/package.json +2 -7
- package/src/client/context.js +58 -0
- package/src/client/index.js +2 -2
- package/src/client/node.js +29 -1
- package/src/commands/generate-rules.js +56 -26
- package/src/commands/vendor.js +90 -21
- package/src/configuration.js +106 -0
- package/src/event-store/{initialise.js → configuration.js} +15 -4
- package/src/event-store/projections.js +40 -11
- package/src/exec-eventstore.js +52 -10
- package/src/index.js +20 -4
- package/src/load-configuration.js +17 -3
- package/src/membership/index.js +5 -2
- package/src/membership/team-details/events.js +5 -0
- package/src/membership/team-details/projections/current.js +9 -0
- package/src/membership/team-details/store.js +30 -0
- package/src/membership/team-details/verify-store-paths.js +8 -0
- package/src/membership/team-membership/events.js +17 -0
- package/src/membership/team-membership/projections/_shared.js +55 -0
- package/src/membership/team-membership/projections/details.js +105 -0
- package/src/membership/team-membership/projections/inviteToEmail.js +25 -0
- package/src/membership/team-membership/projections/members.js +68 -0
- package/src/membership/team-membership/store.js +56 -0
- package/src/membership/user-profile/events.js +6 -0
- package/src/membership/user-profile/projections/current.js +9 -0
- package/src/membership/user-profile/store.js +28 -0
- package/src/membership/user-teams/events.js +5 -0
- package/src/membership/user-teams/projections/current.js +21 -0
- package/src/membership/user-teams/store.js +27 -0
- package/src/membership/userInvites/events.js +12 -0
- package/src/membership/userInvites/projections/pending.js +45 -0
- package/src/membership/userInvites/store.js +46 -0
- package/src/paths.js +5 -0
- package/src/rules.js +153 -0
- package/src/schema.js +91 -1
- package/src/system/main.js +1 -1
- package/dist/browser/web/events.js +0 -7
- package/dist/browser/web/login.js +0 -48
- package/dist/browser/web-ui/components/notification.html.js +0 -12
- package/dist/browser/web-ui/components/notification.js +0 -25
- package/dist/browser/web-ui/components/partials/wa-utils.js +0 -17
- package/dist/browser/web-ui/errors.js +0 -23
- package/dist/browser/web-ui/system.js +0 -20
- package/scripts/dist-client.js +0 -31
- package/src/client/modular.js +0 -82
- package/src/client/web/login.js +0 -48
- package/src/client/web/system.js +0 -67
- package/src/client/web-ui/components/login.html.js +0 -44
- package/src/client/web-ui/components/login.js +0 -74
- package/src/client/web-ui/components/notification.html.js +0 -12
- package/src/client/web-ui/components/notification.js +0 -25
- package/src/client/web-ui/errors.js +0 -23
- package/src/membership/membership-store.js +0 -88
- package/src/membership/user-profile-store.js +0 -39
- /package/dist/browser/{web-ui → client}/components/login.html.js +0 -0
package/src/schema.js
CHANGED
|
@@ -63,4 +63,94 @@ export function filterBySchema(schema, obj) {
|
|
|
63
63
|
}
|
|
64
64
|
return result;
|
|
65
65
|
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function patchViewWithSchema({ view, payload, schema }) {
|
|
69
|
+
|
|
70
|
+
if (!payload || typeof payload !== "object") return view;
|
|
71
|
+
view = Object.assign(view, filterBySchema(schema, payload));
|
|
72
|
+
if (payload?.unset)
|
|
73
|
+
payload.unset.forEach(path => {
|
|
74
|
+
|
|
75
|
+
if (schemaAllowsPath(schema, path))
|
|
76
|
+
deleteByPath(view, path);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
else
|
|
80
|
+
console.warn("Unset path not allowed by schema", path);
|
|
81
|
+
|
|
82
|
+
});
|
|
83
|
+
return view;
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Validate an object against the schema
|
|
88
|
+
// Options:
|
|
89
|
+
// - allowUnknownKeys (default false): reject keys not in schema
|
|
90
|
+
// - requireAllKeys (default false): every schema key must be present
|
|
91
|
+
export function checkSchema(schema, obj, { allowUnknownKeys = false, requireAllKeys = false } = {}) {
|
|
92
|
+
const errors = [];
|
|
93
|
+
|
|
94
|
+
function isPlainObject(v) {
|
|
95
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function checkAtPath(s, o, path) {
|
|
99
|
+
if (!isPlainObject(o)) {
|
|
100
|
+
errors.push(`${path || '(root)'}: expected object, got ${o === null ? 'null' : typeof o}`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Unknown keys?
|
|
105
|
+
if (!allowUnknownKeys) {
|
|
106
|
+
for (const k of Object.keys(o)) {
|
|
107
|
+
if (!(k in s)) {
|
|
108
|
+
const p = path ? `${path}.${k}` : k;
|
|
109
|
+
errors.push(`${p}: key not allowed by schema`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const k of Object.keys(s)) {
|
|
115
|
+
const expected = s[k];
|
|
116
|
+
const value = o[k];
|
|
117
|
+
const p = path ? `${path}.${k}` : k;
|
|
118
|
+
|
|
119
|
+
// Required check
|
|
120
|
+
if (typeof value === 'undefined') {
|
|
121
|
+
if (requireAllKeys) errors.push(`Missing: ${p}`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Type checks
|
|
126
|
+
if (expected === String) {
|
|
127
|
+
if (typeof value !== 'string') errors.push(`${p}: expected string, got ${typeof value}`);
|
|
128
|
+
} else if (expected === Number) {
|
|
129
|
+
if (typeof value !== 'number' || Number.isNaN(value)) errors.push(`${p}: expected number, got ${value}`);
|
|
130
|
+
} else if (expected === Boolean) {
|
|
131
|
+
if (typeof value !== 'boolean') errors.push(`${p}: expected boolean, got ${typeof value}`);
|
|
132
|
+
} else if (expected === Array) {
|
|
133
|
+
if (!Array.isArray(value)) errors.push(`${p}: expected array, got ${typeof value}`);
|
|
134
|
+
} else if (isPlainObject(expected)) {
|
|
135
|
+
if (!isPlainObject(value)) {
|
|
136
|
+
errors.push(`${p}: expected object, got ${value === null ? 'null' : typeof value}`);
|
|
137
|
+
} else {
|
|
138
|
+
checkAtPath(expected, value, p);
|
|
139
|
+
}
|
|
140
|
+
} else if (typeof expected === 'function') {
|
|
141
|
+
if (!(value instanceof expected)) {
|
|
142
|
+
errors.push(`${p}: expected instance of ${expected.name || 'Function'}, got ${value?.constructor?.name || typeof value}`);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
errors.push(`${p}: invalid schema entry (${String(expected)})`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!isPlainObject(schema)) {
|
|
151
|
+
return { valid: false, errors: ['(schema): schema must be a plain object'] };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
checkAtPath(schema, obj, '');
|
|
155
|
+
return { valid: errors.length === 0, errors };
|
|
156
|
+
}
|
package/src/system/main.js
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const EVENT_ERROR_OCCURRED = "h1v3:error-occurred";
|
|
2
|
-
|
|
3
|
-
export const EVENT_SIGN_OUT_REQUESTED = "h1v3:sign-out-requested";
|
|
4
|
-
|
|
5
|
-
export const EVENT_EMAIL_AUTH_REQUESTED = "h1v3:email-auth-requested";
|
|
6
|
-
|
|
7
|
-
export const EVENT_GOOGLE_AUTH_REQUESTED = "h1v3:google-auth-requested";
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { EVENT_EMAIL_AUTH_REQUESTED, EVENT_GOOGLE_AUTH_REQUESTED, EVENT_SIGN_OUT_REQUESTED } from "./events.js";
|
|
2
|
-
|
|
3
|
-
export function registerLoginHandlers(bus, {
|
|
4
|
-
authentication: {
|
|
5
|
-
auth,
|
|
6
|
-
GoogleAuthProvider,
|
|
7
|
-
signInWithPopup,
|
|
8
|
-
signInWithEmailAndPassword,
|
|
9
|
-
signOut
|
|
10
|
-
}
|
|
11
|
-
}) {
|
|
12
|
-
|
|
13
|
-
const googleAuth = new GoogleAuthProvider();
|
|
14
|
-
|
|
15
|
-
bus.addEventListener(EVENT_GOOGLE_AUTH_REQUESTED, () => {
|
|
16
|
-
|
|
17
|
-
signInWithPopup(auth, googleAuth);
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
bus.addEventListener(EVENT_EMAIL_AUTH_REQUESTED, async (e) => {
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
|
|
25
|
-
await signInWithEmailAndPassword(auth, e.detail?.email, e.detail?.password);
|
|
26
|
-
|
|
27
|
-
} catch (err) {
|
|
28
|
-
|
|
29
|
-
switch (err?.code) {
|
|
30
|
-
case "auth/wrong-password":
|
|
31
|
-
alert("Wrong password");
|
|
32
|
-
break;
|
|
33
|
-
default:
|
|
34
|
-
alert(err?.code || err?.message);
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
bus.addEventListener(EVENT_SIGN_OUT_REQUESTED, () => {
|
|
43
|
-
|
|
44
|
-
signOut(auth);
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { html } from "../system.js";
|
|
2
|
-
|
|
3
|
-
export const errorNotification = ({ message }) => html`
|
|
4
|
-
|
|
5
|
-
<wa-callout variant="danger" style="opacity: 1; margin: 0.5rem; zoom: 0.8;" role="alert">
|
|
6
|
-
|
|
7
|
-
<wa-icon slot="icon" name="circle-exclamation"></wa-icon>
|
|
8
|
-
<strong>${message}</strong>
|
|
9
|
-
|
|
10
|
-
</wa-callout>
|
|
11
|
-
|
|
12
|
-
`;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { LitElement } from "../system.js";
|
|
2
|
-
import { errorNotification } from "./notification.html.js";
|
|
3
|
-
import { styled } from "./partials/wa-utils.js";
|
|
4
|
-
|
|
5
|
-
class Notification extends LitElement {
|
|
6
|
-
|
|
7
|
-
static get properties() {
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
|
|
11
|
-
err: { type: Object }
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
render() {
|
|
18
|
-
|
|
19
|
-
if (this.err)
|
|
20
|
-
return styled(errorNotification(this.err));
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
customElements.define("h1v3-notification", Notification);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { html, waDist } from "../../system.js";
|
|
2
|
-
|
|
3
|
-
export const styled = (...children) => html`
|
|
4
|
-
<link rel="stylesheet" href="${waDist}/styles/webawesome.css" />
|
|
5
|
-
<link rel="stylesheet" href="${waDist}/styles/themes/premium.css" />
|
|
6
|
-
<div class="wa-cloak">
|
|
7
|
-
${children}
|
|
8
|
-
</div>
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
export const dialog = (title, ...children) => html`
|
|
12
|
-
<wa-dialog label="${title}" light-dismiss class="dialog-light-dismiss">
|
|
13
|
-
|
|
14
|
-
${children}
|
|
15
|
-
|
|
16
|
-
</wa-dialog>
|
|
17
|
-
`;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { EVENT_ERROR_OCCURRED } from "../web/events.js";
|
|
2
|
-
|
|
3
|
-
const container = document.createElement("ASIDE");
|
|
4
|
-
container.style.position = "fixed";
|
|
5
|
-
container.style.top = "0px";
|
|
6
|
-
container.style.right = "0px";
|
|
7
|
-
container.style.maxWidth = "40rem";
|
|
8
|
-
container.style.zIndex = 9999;
|
|
9
|
-
|
|
10
|
-
document.body.appendChild(container);
|
|
11
|
-
|
|
12
|
-
document.addEventListener(EVENT_ERROR_OCCURRED, ({ detail: { err } }) => {
|
|
13
|
-
|
|
14
|
-
if (err) {
|
|
15
|
-
|
|
16
|
-
const notification = document.createElement("h1v3-notification");
|
|
17
|
-
container.appendChild(notification);
|
|
18
|
-
notification.err = err;
|
|
19
|
-
setTimeout(() => notification.remove(), 5000);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export * from "../web/system.js";
|
|
2
|
-
|
|
3
|
-
export const waDist = "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist";
|
|
4
|
-
|
|
5
|
-
// vendor: webawesome
|
|
6
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/button/button.js";
|
|
7
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/input/input.js";
|
|
8
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/card/card.js";
|
|
9
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/divider/divider.js";
|
|
10
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/icon/icon.js";
|
|
11
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/dialog/dialog.js";
|
|
12
|
-
import "/vendor/@shoelace-style/webawesome-pro@3.0.0-beta.6/dist/components/callout/callout.js";
|
|
13
|
-
|
|
14
|
-
// vendor: lit
|
|
15
|
-
export { html, LitElement } from "/vendor/lit@3.3.1/dist/lit-core.min.js";
|
|
16
|
-
|
|
17
|
-
// h1v3
|
|
18
|
-
import "./errors.js";
|
|
19
|
-
import "./components/notification.js";
|
|
20
|
-
import "./components/login.js";
|
package/scripts/dist-client.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
|
|
7
|
-
const src = join(__dirname, "..", "src", "client");
|
|
8
|
-
const dist = join(__dirname, "..", "dist", "browser");
|
|
9
|
-
|
|
10
|
-
await fs.rm(dist, { recursive: true, force: true });
|
|
11
|
-
async function distribute(subPath, path) {
|
|
12
|
-
|
|
13
|
-
const subDist = join(dist, subPath);
|
|
14
|
-
await fs.mkdir(subDist, { recursive: true });
|
|
15
|
-
await fs.cp(
|
|
16
|
-
join(src, path),
|
|
17
|
-
join(subDist, path),
|
|
18
|
-
{ recursive: true, force: true }
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const publishList = [
|
|
24
|
-
["event-store", "modular.js"],
|
|
25
|
-
["", "web/"],
|
|
26
|
-
["", "web-ui/"]
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
await Promise.all(publishList.map(kv => distribute(...kv)));
|
|
30
|
-
|
|
31
|
-
console.log("Published", publishList.map(x => x.map(y => y || ".").reverse().join(" > ")).join(", "));
|
package/src/client/modular.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
function newEventId(eventType) {
|
|
2
|
-
|
|
3
|
-
return `${Date.now()}-${Math.random().toString().substring(2)}-${eventType}`;
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function eventStore(firebase, path) {
|
|
8
|
-
|
|
9
|
-
const { db, ref, onValue, get, set } = firebase;
|
|
10
|
-
for (const required of ["db", "ref", "onValue", "get", "set"])
|
|
11
|
-
if (!firebase[required]) throw new Error(`Missing required firebase.${required}`);
|
|
12
|
-
|
|
13
|
-
const eventsPath = `${path}/events`;
|
|
14
|
-
const projectionsPath = `${path}/projections`;
|
|
15
|
-
|
|
16
|
-
const subscriptions = {};
|
|
17
|
-
|
|
18
|
-
async function unsubscribe(name) {
|
|
19
|
-
|
|
20
|
-
const unsubscribe = subscriptions[name];
|
|
21
|
-
if (unsubscribe) {
|
|
22
|
-
|
|
23
|
-
console.log("Unsubscribing from", name);
|
|
24
|
-
await unsubscribe();
|
|
25
|
-
delete subscriptions[name];
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function unsubscribeAll() {
|
|
32
|
-
|
|
33
|
-
while(Object.keys(subscriptions).length) {
|
|
34
|
-
|
|
35
|
-
await Promise.all(
|
|
36
|
-
Object.keys(subscriptions).map(unsubscribe)
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
|
|
45
|
-
async record(eventType, payload) {
|
|
46
|
-
|
|
47
|
-
const eid = newEventId(eventType);
|
|
48
|
-
const data = { type: eventType, payload };
|
|
49
|
-
await set(ref(db, `${eventsPath}/${eid}`), data);
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
async getProjection(name) {
|
|
54
|
-
|
|
55
|
-
const snap = await get(ref(db, `${projectionsPath}/${name}`));
|
|
56
|
-
return snap.val();
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
onProjectionValue(name, callback) {
|
|
61
|
-
|
|
62
|
-
const query = ref(db, `${projectionsPath}/${name}`);
|
|
63
|
-
console.log("Subscribing to", query.toString());
|
|
64
|
-
subscriptions[name] = onValue(query, callback);
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
async offProjection(name) {
|
|
69
|
-
|
|
70
|
-
await unsubscribe(name);
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
async dispose() {
|
|
75
|
-
|
|
76
|
-
await unsubscribeAll();
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
}
|
package/src/client/web/login.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { EVENT_EMAIL_AUTH_REQUESTED, EVENT_GOOGLE_AUTH_REQUESTED, EVENT_SIGN_OUT_REQUESTED } from "./events.js";
|
|
2
|
-
|
|
3
|
-
export function registerLoginHandlers(bus, {
|
|
4
|
-
authentication: {
|
|
5
|
-
auth,
|
|
6
|
-
GoogleAuthProvider,
|
|
7
|
-
signInWithPopup,
|
|
8
|
-
signInWithEmailAndPassword,
|
|
9
|
-
signOut
|
|
10
|
-
}
|
|
11
|
-
}) {
|
|
12
|
-
|
|
13
|
-
const googleAuth = new GoogleAuthProvider();
|
|
14
|
-
|
|
15
|
-
bus.addEventListener(EVENT_GOOGLE_AUTH_REQUESTED, () => {
|
|
16
|
-
|
|
17
|
-
signInWithPopup(auth, googleAuth);
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
bus.addEventListener(EVENT_EMAIL_AUTH_REQUESTED, async (e) => {
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
|
|
25
|
-
await signInWithEmailAndPassword(auth, e.detail?.email, e.detail?.password);
|
|
26
|
-
|
|
27
|
-
} catch (err) {
|
|
28
|
-
|
|
29
|
-
switch (err?.code) {
|
|
30
|
-
case "auth/wrong-password":
|
|
31
|
-
alert("Wrong password");
|
|
32
|
-
break;
|
|
33
|
-
default:
|
|
34
|
-
alert(err?.code || err?.message);
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
bus.addEventListener(EVENT_SIGN_OUT_REQUESTED, () => {
|
|
43
|
-
|
|
44
|
-
signOut(auth);
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
}
|
package/src/client/web/system.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// vendor: firebase
|
|
2
|
-
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.3.0/firebase-app.js";
|
|
3
|
-
import {
|
|
4
|
-
connectAuthEmulator,
|
|
5
|
-
getAuth,
|
|
6
|
-
onAuthStateChanged,
|
|
7
|
-
signInWithPopup,
|
|
8
|
-
signInWithEmailAndPassword,
|
|
9
|
-
signOut,
|
|
10
|
-
GoogleAuthProvider
|
|
11
|
-
} from "https://www.gstatic.com/firebasejs/12.3.0/firebase-auth.js";
|
|
12
|
-
import {
|
|
13
|
-
child,
|
|
14
|
-
connectDatabaseEmulator,
|
|
15
|
-
get,
|
|
16
|
-
getDatabase,
|
|
17
|
-
off,
|
|
18
|
-
onValue,
|
|
19
|
-
ref,
|
|
20
|
-
set,
|
|
21
|
-
update,
|
|
22
|
-
} from "https://www.gstatic.com/firebasejs/12.3.0/firebase-database.js";
|
|
23
|
-
|
|
24
|
-
// init firebase
|
|
25
|
-
import firebaseConfig from "/firebase.config.js";
|
|
26
|
-
const app = initializeApp(firebaseConfig);
|
|
27
|
-
const auth = getAuth(app);
|
|
28
|
-
const db = getDatabase(app);
|
|
29
|
-
|
|
30
|
-
// firebase emulator support
|
|
31
|
-
const useEmulator = location?.hostname === "localhost" || location?.hostname === "127.0.0.1";
|
|
32
|
-
if (useEmulator) {
|
|
33
|
-
|
|
34
|
-
const resp = await fetch("http://127.0.0.1:4400/emulators");
|
|
35
|
-
const emulators = await resp.json();
|
|
36
|
-
connectAuthEmulator(auth, `http://${emulators.auth.host}:${emulators.auth.port}`);
|
|
37
|
-
connectDatabaseEmulator(db, emulators.database.host, emulators.database.port);
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// controlled export of firebase
|
|
42
|
-
export const firebase = {
|
|
43
|
-
authentication: {
|
|
44
|
-
auth,
|
|
45
|
-
onAuthStateChanged,
|
|
46
|
-
signInWithEmailAndPassword,
|
|
47
|
-
signInWithPopup,
|
|
48
|
-
signOut,
|
|
49
|
-
GoogleAuthProvider
|
|
50
|
-
},
|
|
51
|
-
database: {
|
|
52
|
-
child,
|
|
53
|
-
db,
|
|
54
|
-
ref,
|
|
55
|
-
get,
|
|
56
|
-
set,
|
|
57
|
-
update,
|
|
58
|
-
onValue,
|
|
59
|
-
off
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const bus = document;
|
|
64
|
-
|
|
65
|
-
// h1v3
|
|
66
|
-
import { registerLoginHandlers } from "./login.js";
|
|
67
|
-
registerLoginHandlers(bus, firebase);
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { html } from "../system.js";
|
|
2
|
-
import { dialog } from "./partials/wa-utils.js";
|
|
3
|
-
|
|
4
|
-
export const loginButton = () => html`<wa-button class="open-login">Login</wa-button>`;
|
|
5
|
-
|
|
6
|
-
export const loginDialog = () => dialog("Login", html`
|
|
7
|
-
<div class="wa-stack">
|
|
8
|
-
|
|
9
|
-
<wa-input label="Email" type="email"></wa-input>
|
|
10
|
-
<wa-input label="Password" type="password"></wa-input>
|
|
11
|
-
<a href="#">Having trouble signing in?</a>
|
|
12
|
-
<wa-button class="login-with-email">Sign in</wa-button>
|
|
13
|
-
<wa-divider></wa-divider>
|
|
14
|
-
<p>Or sign in with:</p>
|
|
15
|
-
<div class="wa-grid" style="--min-column-size: 12ch;">
|
|
16
|
-
|
|
17
|
-
<wa-button appearance="outlined" class="login-with-google">
|
|
18
|
-
|
|
19
|
-
<wa-icon slot="start" name="google" family="brands"></wa-icon>
|
|
20
|
-
Google
|
|
21
|
-
|
|
22
|
-
</wa-button>
|
|
23
|
-
<wa-button appearance="outlined" disabled>
|
|
24
|
-
|
|
25
|
-
<wa-icon slot="start" name="apple" family="brands"></wa-icon>
|
|
26
|
-
Apple ID
|
|
27
|
-
|
|
28
|
-
</wa-button>
|
|
29
|
-
<wa-button appearance="outlined" disabled>
|
|
30
|
-
|
|
31
|
-
<wa-icon slot="start" name="facebook" family="brands"></wa-icon>
|
|
32
|
-
Facebook
|
|
33
|
-
|
|
34
|
-
</wa-button>
|
|
35
|
-
|
|
36
|
-
</div>
|
|
37
|
-
<p>Don't have an account? <a href="#">Create one</a></p>
|
|
38
|
-
|
|
39
|
-
</div>
|
|
40
|
-
`);
|
|
41
|
-
|
|
42
|
-
export const signOutButton = () => html`<wa-button class="sign-out">Sign out</wa-button>`;
|
|
43
|
-
|
|
44
|
-
export const hello = ({ displayName, email }) => html`<strong>${displayName}</strong> (${email}) `;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { LitElement, html, bus } from "../system.js";
|
|
2
|
-
import { styled } from "./partials/wa-utils.js";
|
|
3
|
-
import { hello, loginButton, loginDialog, signOutButton } from './login.html.js';
|
|
4
|
-
import { EVENT_EMAIL_AUTH_REQUESTED, EVENT_GOOGLE_AUTH_REQUESTED, EVENT_SIGN_OUT_REQUESTED } from "../../web/events.js";
|
|
5
|
-
|
|
6
|
-
class Login extends LitElement {
|
|
7
|
-
|
|
8
|
-
static get properties() {
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
|
|
12
|
-
currentUser: { type: Object }
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
createRenderRoot() {
|
|
19
|
-
|
|
20
|
-
const root = super.createRenderRoot();
|
|
21
|
-
root.addEventListener("click", e => this.handleClick(e));
|
|
22
|
-
return root;
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
handleClick(e) {
|
|
27
|
-
|
|
28
|
-
switch(e.target.className) {
|
|
29
|
-
|
|
30
|
-
case "open-login":
|
|
31
|
-
this.shadowRoot.querySelector("wa-dialog").open = true;
|
|
32
|
-
break;
|
|
33
|
-
case "login-with-google":
|
|
34
|
-
bus.dispatchEvent(new CustomEvent(EVENT_GOOGLE_AUTH_REQUESTED));
|
|
35
|
-
break;
|
|
36
|
-
case "login-with-email":
|
|
37
|
-
const inputLogin = this.shadowRoot.querySelector("wa-input[type=email]");
|
|
38
|
-
const inputPassword = this.shadowRoot.querySelector("wa-input[type=password]");
|
|
39
|
-
bus.dispatchEvent(new CustomEvent(EVENT_EMAIL_AUTH_REQUESTED, { detail: { email: inputLogin.value, password: inputPassword.value }}));
|
|
40
|
-
break;
|
|
41
|
-
case "sign-out":
|
|
42
|
-
bus.dispatchEvent(new CustomEvent(EVENT_SIGN_OUT_REQUESTED));
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
render() {
|
|
49
|
-
|
|
50
|
-
if (this.currentUser === undefined) {
|
|
51
|
-
|
|
52
|
-
return html`Initialising...`;
|
|
53
|
-
|
|
54
|
-
} else if(this.currentUser === null) {
|
|
55
|
-
|
|
56
|
-
return styled(
|
|
57
|
-
loginDialog(),
|
|
58
|
-
loginButton()
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
} else {
|
|
62
|
-
|
|
63
|
-
return styled(
|
|
64
|
-
hello(this.currentUser),
|
|
65
|
-
signOutButton()
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
customElements.define('h1v3-login', Login);
|
|
74
|
-
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { html } from "../system.js";
|
|
2
|
-
|
|
3
|
-
export const errorNotification = ({ message }) => html`
|
|
4
|
-
|
|
5
|
-
<wa-callout variant="danger" style="opacity: 1; margin: 0.5rem; zoom: 0.8;" role="alert">
|
|
6
|
-
|
|
7
|
-
<wa-icon slot="icon" name="circle-exclamation"></wa-icon>
|
|
8
|
-
<strong>${message}</strong>
|
|
9
|
-
|
|
10
|
-
</wa-callout>
|
|
11
|
-
|
|
12
|
-
`;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { LitElement } from "../system.js";
|
|
2
|
-
import { errorNotification } from "./notification.html.js";
|
|
3
|
-
import { styled } from "./partials/wa-utils.js";
|
|
4
|
-
|
|
5
|
-
class Notification extends LitElement {
|
|
6
|
-
|
|
7
|
-
static get properties() {
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
|
|
11
|
-
err: { type: Object }
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
render() {
|
|
18
|
-
|
|
19
|
-
if (this.err)
|
|
20
|
-
return styled(errorNotification(this.err));
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
customElements.define("h1v3-notification", Notification);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { EVENT_ERROR_OCCURRED } from "../web/events.js";
|
|
2
|
-
|
|
3
|
-
const container = document.createElement("ASIDE");
|
|
4
|
-
container.style.position = "fixed";
|
|
5
|
-
container.style.top = "0px";
|
|
6
|
-
container.style.right = "0px";
|
|
7
|
-
container.style.maxWidth = "40rem";
|
|
8
|
-
container.style.zIndex = 9999;
|
|
9
|
-
|
|
10
|
-
document.body.appendChild(container);
|
|
11
|
-
|
|
12
|
-
document.addEventListener(EVENT_ERROR_OCCURRED, ({ detail: { err } }) => {
|
|
13
|
-
|
|
14
|
-
if (err) {
|
|
15
|
-
|
|
16
|
-
const notification = document.createElement("h1v3-notification");
|
|
17
|
-
container.appendChild(notification);
|
|
18
|
-
notification.err = err;
|
|
19
|
-
setTimeout(() => notification.remove(), 5000);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
});
|