create-mana 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +28 -2
- package/bin/create-mana.mjs +5 -0
- package/kits/auth/files/src/api/auth.ts +100 -0
- package/kits/auth/files/src/api/profile.ts +48 -0
- package/kits/auth/files/src/api/types.ts +28 -0
- package/kits/auth/files/src/components/AppLayout.mana +31 -0
- package/kits/auth/files/src/components/VerifyBanner.mana +47 -0
- package/kits/auth/files/src/router/routes.ts +31 -0
- package/kits/auth/files/src/shared/events.ts +11 -0
- package/kits/auth/files/src/stores/session.ts +99 -0
- package/kits/auth/files/src/views/ForgotPassword.mana +83 -0
- package/kits/auth/files/src/views/Home.mana +15 -0
- package/kits/auth/files/src/views/Profile.mana +172 -0
- package/kits/auth/files/src/views/Register.mana +86 -0
- package/kits/auth/files/src/views/ResetPassword.mana +90 -0
- package/kits/auth/files/src/views/SignIn.mana +84 -0
- package/kits/auth/files/src/views/VerifyEmail.mana +78 -0
- package/kits/auth/files/tests/auth.test.mjs +93 -0
- package/kits/auth/files/tests/home.test.mjs +38 -0
- package/kits/auth/files/tests/profile.test.mjs +68 -0
- package/kits/auth/files/tests/support/users.mjs +2 -0
- package/kits/auth/kit.json +80 -0
- package/kits/base/files/README.md +39 -0
- package/kits/base/kit.json +7 -0
- package/kits/organisations/files/src/api/auth.ts +124 -0
- package/kits/organisations/files/src/api/members.ts +243 -0
- package/kits/organisations/files/src/api/notifications.ts +63 -0
- package/kits/organisations/files/src/api/organisations.ts +41 -0
- package/kits/organisations/files/src/api/scope.ts +98 -0
- package/kits/organisations/files/src/api/types.ts +72 -0
- package/kits/organisations/files/src/assets/styles/organisations.css +46 -0
- package/kits/organisations/files/src/components/AppLayout.mana +90 -0
- package/kits/organisations/files/src/components/NotificationBell.mana +35 -0
- package/kits/organisations/files/src/components/NotificationList.mana +112 -0
- package/kits/organisations/files/src/components/OrganisationSwitcher.mana +171 -0
- package/kits/organisations/files/src/composables/notifications.ts +28 -0
- package/kits/organisations/files/src/router/routes.ts +43 -0
- package/kits/organisations/files/src/shared/roles.ts +10 -0
- package/kits/organisations/files/src/stores/notifications.ts +41 -0
- package/kits/organisations/files/src/stores/session.ts +158 -0
- package/kits/organisations/files/src/utilities/format.ts +15 -0
- package/kits/organisations/files/src/views/Forbidden.mana +28 -0
- package/kits/organisations/files/src/views/Home.mana +15 -0
- package/kits/organisations/files/src/views/Invite.mana +156 -0
- package/kits/organisations/files/src/views/InviteMember.mana +99 -0
- package/kits/organisations/files/src/views/Members.mana +218 -0
- package/kits/organisations/files/src/views/NoOrganisation.mana +184 -0
- package/kits/organisations/files/src/views/Notifications.mana +30 -0
- package/kits/organisations/files/src/views/OrganisationForm.mana +76 -0
- package/kits/organisations/files/src/views/OrganisationSettings.mana +62 -0
- package/kits/organisations/files/src/views/Profile.mana +213 -0
- package/kits/organisations/files/src/views/Register.mana +113 -0
- package/kits/organisations/files/tests/auth.test.mjs +82 -0
- package/kits/organisations/files/tests/home.test.mjs +43 -0
- package/kits/organisations/files/tests/members.test.mjs +89 -0
- package/kits/organisations/files/tests/notifications.test.mjs +49 -0
- package/kits/organisations/files/tests/organisations.test.mjs +70 -0
- package/kits/organisations/files/tests/profile.test.mjs +79 -0
- package/kits/organisations/files/tests/support/users.mjs +3 -0
- package/kits/organisations/kit.json +51 -0
- package/lib/compose.mjs +209 -0
- package/lib/new.mjs +161 -0
- package/lib/prompts.mjs +182 -0
- package/package.json +36 -4
- package/template/.nvmrc +1 -0
- package/template/README.md +23 -0
- package/template/_gitignore +25 -0
- package/template/index.html +17 -0
- package/template/package.json +22 -0
- package/template/public/favicon.svg +1 -0
- package/template/public/icons.svg +24 -0
- package/template/src/App.mana +15 -0
- package/template/src/api/ApiError.ts +17 -0
- package/template/src/api/client.ts +116 -0
- package/template/src/assets/styles/main.css +158 -0
- package/template/src/components/AppLogo.mana +20 -0
- package/template/src/components/Button.mana +25 -0
- package/template/src/components/ConfirmHost.mana +43 -0
- package/template/src/components/TextField.mana +60 -0
- package/template/src/components/ToastHost.mana +40 -0
- package/template/src/composables/media.ts +19 -0
- package/template/src/composables/unsaved.ts +29 -0
- package/template/src/main.ts +25 -0
- package/template/src/router/index.ts +14 -0
- package/template/src/router/routes.ts +11 -0
- package/template/src/stores/confirm.ts +45 -0
- package/template/src/stores/toasts.ts +64 -0
- package/template/src/utilities/query.ts +40 -0
- package/template/src/utilities/timers.ts +12 -0
- package/template/src/views/Home.mana +12 -0
- package/template/src/views/NotFound.mana +13 -0
- package/template/tests/home.test.mjs +29 -0
- package/template/tests/support/api.mjs +44 -0
- package/template/tests/support/check.mjs +15 -0
- package/template/tests/support/dom.mjs +45 -0
- package/template/tests/support/paths.mjs +54 -0
- package/template/tests/support/settle.mjs +15 -0
- package/template/tsconfig.json +35 -0
- package/template/vite.config.ts +29 -0
- package/versions.json +3 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The bare starter: the home page at /, and the page for an address with no page, shown through the real router and root component.
|
|
2
|
+
import { check } from "./support/check.mjs";
|
|
3
|
+
import { settle } from "./support/settle.mjs";
|
|
4
|
+
import { useDom } from "./support/dom.mjs";
|
|
5
|
+
import { useFakeApi } from "./support/api.mjs";
|
|
6
|
+
|
|
7
|
+
useDom('<main id="app"></main>', { url: "http://app.test/" });
|
|
8
|
+
useFakeApi();
|
|
9
|
+
|
|
10
|
+
const { createApp, createEvents, createStores } = await import("@mana-js/mana");
|
|
11
|
+
const { default: App } = await import("@/App.mana");
|
|
12
|
+
const { default: router } = await import("@/router");
|
|
13
|
+
|
|
14
|
+
createApp(App).use(createStores()).use(createEvents()).use(router).mount("#app");
|
|
15
|
+
await router.isReady();
|
|
16
|
+
await settle();
|
|
17
|
+
|
|
18
|
+
const root = document.getElementById("app");
|
|
19
|
+
const text = selector => root.querySelector(selector)?.textContent.replace(/\s+/g, " ").trim() ?? null;
|
|
20
|
+
|
|
21
|
+
check("the home page: its heading", text("h1") == "Mana Starter" && /src\/views\/Home\.mana/.test(text("main") ?? ""));
|
|
22
|
+
|
|
23
|
+
await router.push("/nowhere/at/all");
|
|
24
|
+
await settle();
|
|
25
|
+
check("an address with no page: not found, with the way back", text("h1") == "Page not found" && root.querySelector("a[href='/']") !== null);
|
|
26
|
+
|
|
27
|
+
await router.push("/");
|
|
28
|
+
await settle();
|
|
29
|
+
check("…and back at the home page", text("h1") == "Mana Starter");
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The API, faked for a suite: `fetch` answers the routes a suite gives, after a moment, so suites stay fast and need no server. `api.post("/api/login", body => ({ status: 200, json: {…} }))`; a route not
|
|
3
|
+
* given is a 404. What was asked is in `calls`. As the real API does, it answers GET /api/csrf-cookie by setting the XSRF-TOKEN cookie, and refuses with 419 what changes something without that
|
|
4
|
+
* token. The real API is checked by its own tests. While an answer is on its way it's counted as pending, so settle() waits for it too.
|
|
5
|
+
*/
|
|
6
|
+
export const pending = { count: 0 };
|
|
7
|
+
|
|
8
|
+
export function useFakeApi({ delay = 5 } = {}) {
|
|
9
|
+
const routes = new Map();
|
|
10
|
+
const calls = [];
|
|
11
|
+
const route = method => (path, answer) => routes.set(`${method} ${path}`, answer);
|
|
12
|
+
|
|
13
|
+
globalThis.fetch = async (input, init = {}) => {
|
|
14
|
+
const url = new URL(String(input), "http://app.test");
|
|
15
|
+
const method = (init.method ?? "GET").toUpperCase();
|
|
16
|
+
const body = typeof init.body == "string" ? JSON.parse(init.body) : undefined;
|
|
17
|
+
const sent = new Headers(init.headers).get("x-xsrf-token");
|
|
18
|
+
|
|
19
|
+
calls.push({ method, path: url.pathname + url.search, body });
|
|
20
|
+
pending.count++;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
24
|
+
|
|
25
|
+
if(method == "GET" && url.pathname == "/api/csrf-cookie") {
|
|
26
|
+
document.cookie = "XSRF-TOKEN=token-1; path=/";
|
|
27
|
+
|
|
28
|
+
return new Response(null, { status: 204 });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if(!["GET", "HEAD", "OPTIONS"].includes(method) && sent !== "token-1")
|
|
32
|
+
return new Response(JSON.stringify({ message: "CSRF token mismatch." }), { status: 419, headers: { "content-type": "application/json" } });
|
|
33
|
+
|
|
34
|
+
const answer = routes.get(`${method} ${url.pathname}`);
|
|
35
|
+
const { status = 200, json } = answer ? await answer(body, url) : { status: 404, json: { message: "Not Found" } };
|
|
36
|
+
|
|
37
|
+
return new Response(status == 204 || json === undefined ? null : JSON.stringify(json), { status, headers: json === undefined ? {} : { "content-type": "application/json" } });
|
|
38
|
+
} finally {
|
|
39
|
+
pending.count--;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return { calls, get: route("GET"), post: route("POST"), put: route("PUT"), patch: route("PATCH"), delete: route("DELETE") };
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A suite's checks: each is a node:test test, named by its label, that
|
|
3
|
+
* passes when the check held, and otherwise fails with its detail (what was
|
|
4
|
+
* found instead) and where in the suite it is. Whether it held is worked out
|
|
5
|
+
* when check() is called, so a suite reads top to bottom, each step's checks
|
|
6
|
+
* right after it.
|
|
7
|
+
*/
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { test } from "node:test";
|
|
10
|
+
|
|
11
|
+
export function check(label, ok, detail = "") {
|
|
12
|
+
const where = new Error().stack?.split("\n")[2]?.trim() ?? "";
|
|
13
|
+
|
|
14
|
+
test(label, () => assert.ok(ok, `${detail === "" ? "It didn't hold" : String(detail)}\n ${where}`));
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A DOM for a suite: a jsdom window made from the suite's own markup and
|
|
3
|
+
* options (a URL, for the router), with what Mana and the app reach for put on
|
|
4
|
+
* globalThis, as a browser has it. Each test file runs in its own process, so
|
|
5
|
+
* each gets a fresh one. jsdom has no PointerEvent; MouseEvent stands in. It
|
|
6
|
+
* lays nothing out, so it has no ResizeObserver either; one that never reports
|
|
7
|
+
* stands in. A
|
|
8
|
+
* page with no URL has no sessionStorage (jsdom refuses it), as before.
|
|
9
|
+
*/
|
|
10
|
+
import { JSDOM } from "jsdom";
|
|
11
|
+
|
|
12
|
+
export function useDom(html = "", options = {}) {
|
|
13
|
+
const { window } = new JSDOM(html, options);
|
|
14
|
+
|
|
15
|
+
Object.assign(globalThis, {
|
|
16
|
+
window,
|
|
17
|
+
document: window.document,
|
|
18
|
+
AbortController: window.AbortController,
|
|
19
|
+
Blob: window.Blob,
|
|
20
|
+
CSSStyleDeclaration: window.CSSStyleDeclaration,
|
|
21
|
+
Element: window.Element,
|
|
22
|
+
Event: window.Event,
|
|
23
|
+
FocusEvent: window.FocusEvent,
|
|
24
|
+
HTMLButtonElement: window.HTMLButtonElement,
|
|
25
|
+
HTMLDialogElement: window.HTMLDialogElement,
|
|
26
|
+
HTMLElement: window.HTMLElement,
|
|
27
|
+
HTMLInputElement: window.HTMLInputElement,
|
|
28
|
+
HTMLSelectElement: window.HTMLSelectElement,
|
|
29
|
+
HTMLTextAreaElement: window.HTMLTextAreaElement,
|
|
30
|
+
HTMLUnknownElement: window.HTMLUnknownElement,
|
|
31
|
+
KeyboardEvent: window.KeyboardEvent,
|
|
32
|
+
MouseEvent: window.MouseEvent,
|
|
33
|
+
MutationObserver: window.MutationObserver,
|
|
34
|
+
Node: window.Node,
|
|
35
|
+
PointerEvent: window.MouseEvent,
|
|
36
|
+
PopStateEvent: window.PopStateEvent,
|
|
37
|
+
ResizeObserver: class { observe() {} unobserve() {} disconnect() {} },
|
|
38
|
+
SVGElement: window.SVGElement
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if(options.url)
|
|
42
|
+
globalThis.sessionStorage = window.sessionStorage;
|
|
43
|
+
|
|
44
|
+
return window;
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* the app's `@/` paths for Node, as Vite's alias resolves them: `@/api/stub`
|
|
3
|
+
* is src/api/stub.ts, `@/router` is src/router/index.ts, and a path with its
|
|
4
|
+
* extension is that file (`@/components/Button.mana`). And `.mana` files,
|
|
5
|
+
* compiled as Vite's plugin compiles them: the file's module, its script's
|
|
6
|
+
* TypeScript, and its styles, empty here, since jsdom applies no CSS. Loaded
|
|
7
|
+
* before the suites with `node --import`.
|
|
8
|
+
*/
|
|
9
|
+
import { compile, componentModule, filePart, partSource } from "@mana-js/mana/compiler";
|
|
10
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
+
import { registerHooks } from "node:module";
|
|
12
|
+
import { relative } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
const root = fileURLToPath(new URL("../../", import.meta.url));
|
|
16
|
+
const source = new URL("../../src/", import.meta.url);
|
|
17
|
+
|
|
18
|
+
registerHooks({
|
|
19
|
+
resolve(specifier, context, nextResolve) {
|
|
20
|
+
if(!specifier.startsWith("@/"))
|
|
21
|
+
return nextResolve(specifier, context);
|
|
22
|
+
|
|
23
|
+
if(/\.\w+$/.test(specifier))
|
|
24
|
+
return nextResolve(new URL(specifier.slice(2), source).href, context);
|
|
25
|
+
|
|
26
|
+
const file = new URL(`${specifier.slice(2)}.ts`, source);
|
|
27
|
+
|
|
28
|
+
return nextResolve(existsSync(file) ? file.href : new URL(`${specifier.slice(2)}/index.ts`, source).href, context);
|
|
29
|
+
},
|
|
30
|
+
load(url, context, nextLoad) {
|
|
31
|
+
const address = new URL(url);
|
|
32
|
+
|
|
33
|
+
if(address.protocol != "file:" || !address.pathname.endsWith(".mana"))
|
|
34
|
+
return nextLoad(url, context);
|
|
35
|
+
|
|
36
|
+
const path = fileURLToPath(address);
|
|
37
|
+
const compiled = compile(readFileSync(path, "utf8"), { file: relative(root, path) });
|
|
38
|
+
const part = filePart(address.search.slice(1));
|
|
39
|
+
|
|
40
|
+
if(!part) {
|
|
41
|
+
return {
|
|
42
|
+
format: "module",
|
|
43
|
+
source: componentModule(compiled),
|
|
44
|
+
shortCircuit: true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
format: part.type == "script" && compiled.lang == "ts" ? "module-typescript" : "module",
|
|
50
|
+
source: part.type == "style" ? "" : partSource(compiled, part) ?? "",
|
|
51
|
+
shortCircuit: true,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Waits until the app has settled: no answer from the faked API on its way, and still none a moment later (an answer often sets off the next request), so the page shows what came back. Exact however
|
|
3
|
+
* busy the machine is, where a fixed wait is a guess. Gives up after `timeout` ms without failing: the next check then fails, saying what it found.
|
|
4
|
+
*/
|
|
5
|
+
import { pending } from "./api.mjs";
|
|
6
|
+
|
|
7
|
+
export async function settle(timeout = 5000) {
|
|
8
|
+
const end = Date.now() + timeout;
|
|
9
|
+
let quiet = 0;
|
|
10
|
+
|
|
11
|
+
while(quiet < 2 && Date.now() < end) {
|
|
12
|
+
await new Promise(resolve => setTimeout(resolve, 5));
|
|
13
|
+
quiet = pending.count == 0 ? quiet + 1 : 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2023",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2023",
|
|
7
|
+
"DOM"
|
|
8
|
+
],
|
|
9
|
+
"types": [
|
|
10
|
+
"vite/client",
|
|
11
|
+
"@mana-js/mana/client"
|
|
12
|
+
],
|
|
13
|
+
"paths": {
|
|
14
|
+
"@/*": [
|
|
15
|
+
"./src/*"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"allowArbitraryExtensions": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
/* Bundler mode */
|
|
21
|
+
"moduleResolution": "bundler",
|
|
22
|
+
"allowImportingTsExtensions": true,
|
|
23
|
+
"verbatimModuleSyntax": true,
|
|
24
|
+
"moduleDetection": "force",
|
|
25
|
+
"noEmit": true,
|
|
26
|
+
/* Linting */
|
|
27
|
+
"noUnusedLocals": true,
|
|
28
|
+
"noUnusedParameters": true,
|
|
29
|
+
"erasableSyntaxOnly": true,
|
|
30
|
+
"noFallthroughCasesInSwitch": true
|
|
31
|
+
},
|
|
32
|
+
"include": [
|
|
33
|
+
"src"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fileURLToPath, URL } from "node:url";
|
|
2
|
+
|
|
3
|
+
import { mana } from "@mana-js/mana/vite";
|
|
4
|
+
import { defineConfig } from "vite";
|
|
5
|
+
|
|
6
|
+
// The API, which `/api/…` is passed on to while developing and previewing: on port 3000 (the Coven starter's) unless API_URL says where. In production, one host serves both.
|
|
7
|
+
const api = process.env["API_URL"] ?? "http://localhost:3000";
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [
|
|
11
|
+
mana(),
|
|
12
|
+
],
|
|
13
|
+
server: {
|
|
14
|
+
port: 5173,
|
|
15
|
+
proxy: {
|
|
16
|
+
"/api": api,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
preview: {
|
|
20
|
+
proxy: {
|
|
21
|
+
"/api": api,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
resolve: {
|
|
25
|
+
alias: {
|
|
26
|
+
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
package/versions.json
ADDED