@ofidj/generator-fidj 1.0.5 → 1.0.7

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.
@@ -2,10 +2,12 @@ import {agreementMarkup, bindAgreement, acceptedAgreement, signInErrorMessage} f
2
2
  import { FidjNodeService, FidjOidcClient } from "@ofidj/node";
3
3
  import config from "../app.config.json";
4
4
  import "./style.css";
5
+ import { showVersionBadge } from "./version";
5
6
 
6
7
  const sdk = new FidjNodeService();
7
8
  const oidc = config.oidcIssuer ? new FidjOidcClient({issuer: config.oidcIssuer, clientId: config.appId, redirectUri: window.location.origin + window.location.pathname, apiEndpoint: config.apiEndpoint, storage: sessionStorage}) : null;
8
9
  const root = document.querySelector<HTMLDivElement>("#app")!;
10
+ showVersionBadge(config.releaseVersion);
9
11
  const appPath = `/me/apps/${encodeURIComponent(config.appId)}`;
10
12
  let signedIn = false;
11
13
  let emailVerified = false;
@@ -1,6 +1,7 @@
1
1
  import {agreementMarkup, bindAgreement, acceptedAgreement, signInErrorMessage} from "./service-agreement";
2
2
  import { FidjNodeService } from "@ofidj/node";
3
3
  import "./style.css";
4
+ import { showVersionBadge } from "./version";
4
5
 
5
6
  type Session = { username: string; roles: string[] };
6
7
  type Note = { id: string; title: string; body: string; createdAt: string };
@@ -10,6 +11,7 @@ type Settings = {
10
11
  apiEndpoint: string;
11
12
  dashboardUrl: string;
12
13
  localDemo: boolean;
14
+ releaseVersion: string;
13
15
  };
14
16
  const root = document.querySelector<HTMLDivElement>("#app")!;
15
17
  const sdk = new FidjNodeService();
@@ -248,6 +250,7 @@ function render() {
248
250
  async function start() {
249
251
  try {
250
252
  settings = await (await fetch("/api/config")).json();
253
+ showVersionBadge(settings.releaseVersion);
251
254
  await sdk.init(settings.appId, {
252
255
  apiEndpoint: settings.apiEndpoint,
253
256
  prod: !settings.localDemo,
@@ -1,5 +1,5 @@
1
1
  export function agreementMarkup() {
2
- return `<div class="signin-agreement"><label class="agreement-choice"><input id="service-agreement" type="checkbox" aria-required="true" disabled><span id="agreement-label">I accept the service agreement for this app.</span></label><button type="button" id="read-agreement" disabled>Read service agreement</button><p id="agreement-status" class="fineprint" role="status">Loading service agreement…</p></div><dialog id="agreement-dialog" aria-labelledby="agreement-heading"><h2 id="agreement-heading">Service agreement</h2><p id="agreement-version"></p><p id="agreement-text"></p><button type="button" id="close-agreement">Close agreement</button></dialog>`;
2
+ return `<div class="signin-agreement"><label class="agreement-choice"><input id="service-agreement" type="checkbox" aria-required="true" disabled><span id="agreement-label">I accept the service agreement for this app.</span></label><button type="button" id="read-agreement" disabled>Read service agreement</button><p id="agreement-status" class="fineprint" role="status">Loading service agreement…</p><button type="button" id="retry-agreement" hidden>Retry</button></div><dialog id="agreement-dialog" aria-labelledby="agreement-heading"><h2 id="agreement-heading">Service agreement</h2><p id="agreement-version"></p><p id="agreement-text"></p><button type="button" id="close-agreement">Close agreement</button></dialog>`;
3
3
  }
4
4
 
5
5
  export function acceptedAgreement(form: HTMLFormElement) {
@@ -24,6 +24,7 @@ export async function bindAgreement(form: HTMLFormElement | null, title: string,
24
24
  const read = form.querySelector<HTMLButtonElement>("#read-agreement")!;
25
25
  const dialog = form.querySelector<HTMLDialogElement>("#agreement-dialog")!;
26
26
  const status = form.querySelector<HTMLElement>("#agreement-status")!;
27
+ const retry = form.querySelector<HTMLButtonElement>("#retry-agreement")!;
27
28
  const submitButtons = form.querySelectorAll<HTMLButtonElement>('button[type="submit"]');
28
29
  const update = () => submitButtons.forEach(button => { button.disabled = checkbox.disabled; });
29
30
  form.querySelector("#agreement-label")!.textContent = `I accept the service agreement for ${title}.`;
@@ -31,21 +32,31 @@ export async function bindAgreement(form: HTMLFormElement | null, title: string,
31
32
  checkbox.addEventListener("change", update);
32
33
  read.addEventListener("click", () => dialog.showModal());
33
34
  form.querySelector("#close-agreement")!.addEventListener("click", () => dialog.close());
34
- try {
35
- const response = await fetch(`${endpoint}/apps/${encodeURIComponent(appId)}`, {signal: AbortSignal.timeout(10000)});
36
- if (!response.ok) throw new Error("Agreement unavailable");
37
- const agreement = (await response.json()).app?.agreement;
38
- if (!agreement || typeof agreement.version !== "string" || !agreement.version || typeof agreement.text !== "string" || !agreement.text) throw new Error("Agreement unavailable");
39
- if (!form.isConnected) return;
40
- checkbox.dataset.version = agreement.version;
41
- checkbox.disabled = false;
42
- checkbox.checked = checked;
43
- read.disabled = false;
44
- dialog.querySelector("#agreement-version")!.textContent = `Version ${agreement.version}`;
45
- dialog.querySelector("#agreement-text")!.textContent = agreement.text;
46
- status.textContent = "Required to sign in. Optional data choices stay separate.";
47
- update();
48
- } catch {
49
- if (form.isConnected) status.textContent = "The service agreement could not be loaded. Reload this page to try again.";
50
- }
35
+ const load = async () => {
36
+ retry.hidden = true;
37
+ status.textContent = "Loading service agreement…";
38
+ try {
39
+ const response = await fetch(`${endpoint}/apps/${encodeURIComponent(appId)}`, {signal: AbortSignal.timeout(10000)});
40
+ if (!response.ok) throw new Error(response.status === 404 ? "missing" : "unreachable");
41
+ const agreement = (await response.json()).app?.agreement;
42
+ if (!agreement || typeof agreement.version !== "string" || !agreement.version || typeof agreement.text !== "string" || !agreement.text) throw new Error("missing");
43
+ if (!form.isConnected) return;
44
+ checkbox.dataset.version = agreement.version;
45
+ checkbox.disabled = false;
46
+ checkbox.checked = checked;
47
+ read.disabled = false;
48
+ dialog.querySelector("#agreement-version")!.textContent = `Version ${agreement.version}`;
49
+ dialog.querySelector("#agreement-text")!.textContent = agreement.text;
50
+ status.textContent = "Required to sign in. Optional data choices stay separate.";
51
+ update();
52
+ } catch (error) {
53
+ if (!form.isConnected) return;
54
+ status.textContent = error instanceof Error && error.message === "missing"
55
+ ? "This app has no service agreement available."
56
+ : "We cannot reach Fidj right now. Try again.";
57
+ retry.hidden = false;
58
+ }
59
+ };
60
+ retry.addEventListener("click", load);
61
+ await load();
51
62
  }
@@ -419,6 +419,21 @@ footer {
419
419
  border-top: 1px solid var(--fidj-line-soft);
420
420
  padding: 28px 0 10px;
421
421
  }
422
+ .fidj-version {
423
+ position: fixed;
424
+ right: 10px;
425
+ bottom: 8px;
426
+ z-index: 1000;
427
+ padding: 4px 7px;
428
+ border: 1px solid var(--fidj-line-soft);
429
+ border-radius: var(--fidj-radius);
430
+ background: var(--fidj-paper);
431
+ color: var(--fidj-text-faint);
432
+ font-family: var(--fidj-font-mono);
433
+ font-size: 10px;
434
+ line-height: 1;
435
+ opacity: 0.9;
436
+ }
422
437
 
423
438
  @media (max-width: 760px) {
424
439
  main {
@@ -0,0 +1,8 @@
1
+ export function showVersionBadge(version: string): void {
2
+ if (!/^\d{2}\.\d{2}\.\d{2}$/.test(version || "")) return;
3
+ const badge = document.createElement("div");
4
+ badge.className = "fidj-version";
5
+ badge.setAttribute("aria-label", `App version ${version}`);
6
+ badge.textContent = `v${version}`;
7
+ document.body.append(badge);
8
+ }
package/lib/scaffold.cjs CHANGED
@@ -136,6 +136,7 @@ function scaffold(destination, options) {
136
136
  apiEndpoint: localApi,
137
137
  dashboardUrl: options.local ? "http://localhost:4200" : "https://fidj.ovh",
138
138
  title,
139
+ releaseVersion: new Date().toISOString().slice(2, 10).replaceAll("-", "."),
139
140
  localDemo: Boolean(options.local),
140
141
  allowAnonymous: anonymous === true || anonymous === "true",
141
142
  welcome: options.welcome || title,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ofidj/generator-fidj",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Generate a TypeScript app with Fidj sign-in, live server-side roles and per-app privacy.",
5
5
  "homepage": "https://fidj.ovh",
6
6
  "bugs": {