feat: label the product page links with a fixed UTM per button (#525) #528
20 changed files with 445 additions and 61 deletions
|
|
@ -15,6 +15,7 @@
|
|||
- Guide d'utilisation : la procédure BMO de « Exporter un CSV depuis votre banque » est désormais confirmée sur un compte réel (2026-10-22). Le bouton s'appelle « Télécharger » sur le site français, sans l'ancien « ou Exporter », et les trois points qui n'ont pas pu être vérifiés (l'historique de la Mastercard, les prêts qui ne s'exportent pas, les colonnes des comptes de dépôt) sont marqués comme non vérifiés. La note dit désormais que la détection générique lit les exports BMO, des comptes de dépôt comme de la Mastercard, en retenant pour la Mastercard la date de la transaction plutôt que celle de l'inscription au relevé, et qu'un fichier dont les vingt premières lignes comptent plus d'entrées que de sorties sort inversé à l'aperçu jusqu'à « Inverser les signes » (#371).
|
||||
- L'écran de déverrouillage qui s'ouvre dans une fenêtre en édition Gratuite, depuis un profil verrouillé du sélecteur de profil ou depuis le bouton Répartition de la page Transactions, se ferme désormais avec Échap. Les lecteurs d'écran reconnaissent désormais la fenêtre du sélecteur de profil comme une boîte de dialogue, nommée d'après l'édition requise (par exemple « Fonctionnalité Base »), avec un bouton « Fermer », comme celle du bouton Répartition. Ces fenêtres, et la fenêtre « Gérer les profils », s'ouvrent désormais avec le focus sur leur bouton « Fermer », gardent Tab et Maj+Tab à l'intérieur et rendent le focus quand elles se ferment : au bouton du sélecteur de profil pour les fenêtres ouvertes depuis son menu, sinon au bouton qui les a ouvertes. La fenêtre « Gérer les profils » se ferme aussi avec Échap, sauf pendant l'enregistrement d'un profil ; les lecteurs d'écran la reconnaissent comme une boîte de dialogue nommée d'après son titre, avec un bouton « Fermer », et le bouton du sélecteur de profil dit désormais si sa liste est ouverte. Dans « Gérer les profils », le focus revient sur « Créer un profil » après « Annuler » ou après l'enregistrement des modifications d'un profil (#451, #494).
|
||||
- Rapports : les rapports s'ouvrent désormais sur « Cette année », du 1er janvier à aujourd'hui, avec son bouton allumé, au lieu de « Personnalisé » sur toute l'année civile, mois à venir compris ; le tableau de bord ne change pas. L'aide de la page Rapports dit désormais que Tendances montre vos revenus et dépenses mois par mois sur la période choisie, et sa carte Tendances affiche « Où vous allez, mois par mois », au lieu de « sur 12 mois » : Tendances suit le sélecteur de période. Sur les Comparables, dont le mois de référence suit la fin de la période, « Ce mois », « 3 mois », « 6 mois » et « 12 mois » finissent aujourd'hui comme « Cette année » : choisis juste après l'ouverture, ils ne déplacent plus le mois de référence vers le mois en cours ; la liste « Mois de référence » le fait toujours (#479).
|
||||
- Les liens vers la page produit ouverts depuis l'application portent une étiquette qui indique au site de quel bouton ils viennent, sans aucune donnée personnelle.
|
||||
|
||||
### Corrigé
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
- User guide: the BMO procedure of “Export a CSV from your bank” is now confirmed on a real account (2026-10-22). The button is named “Télécharger” on the French site, without the former “or Export”, and the three points that could not be checked (the Mastercard history, loans that cannot be exported, the columns of deposit accounts) are marked as not verified. The note now says that generic detection reads BMO exports, deposit accounts and Mastercard alike, keeping the transaction date rather than the posting date for the Mastercard, and that a file whose first twenty rows hold more inflows than outflows comes out reversed in the preview until “Flip the signs” (#371).
|
||||
- The unlock screen that opens in a window on the Free edition, from a locked profile of the profile switcher or from the Split button of the Transactions page, now closes with Escape. Screen readers now identify the profile switcher's window as a dialog, named after the edition it needs (such as “Base feature”), with a “Close” button, like the Split button's. These windows, and the “Manage Profiles” window, now open with the focus on their “Close” button, keep Tab and Shift+Tab inside them, and give the focus back when they close: to the profile switcher's button for the windows opened from its menu, otherwise to the button that opened them. The “Manage Profiles” window also closes with Escape, except while a profile is being saved; screen readers identify it as a dialog named after its title, with a “Close” button, and the profile switcher's button now tells whether its list is open. In “Manage Profiles”, the focus goes back to “Create Profile” after “Cancel” or after saving a profile's changes (#451, #494).
|
||||
- Reports: the reports now open on “This year”, from January 1st to today, with its button lit, instead of “Custom” over the whole calendar year, months to come included; the Dashboard does not change. The help of the Reports page now says that Trends shows your income and expenses month by month over the selected period, and its Trends card reads “Where you're heading, month by month”, instead of “over 12 months”: Trends follows the period selector. On Compare, whose reference month follows the end of the period, “This month”, “3 months”, “6 months” and “12 months” end today like “This year”: chosen right after opening, they no longer move the reference month to the current month; the “Reference month” list still does (#479).
|
||||
- Product page links opened from the app carry a label that tells the site which button they come from, with no personal data.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
### Privacy-first — NON NÉGOCIABLE
|
||||
- Zéro donnée envoyée vers un serveur tiers
|
||||
- Tout le traitement CSV et toutes les données financières restent en local
|
||||
- Aucune télémétrie, aucun analytics cloud
|
||||
- Aucune télémétrie, aucun analytics cloud ; les liens vers la page produit portent une étiquette UTM fixe par bouton, sans donnée de l'utilisateur (décision de Max du 2026-11-02, #525)
|
||||
|
||||
### Précision financière
|
||||
- Toujours valider les montants selon les règles de parsing configurables (gestion des virgules/points, espaces, symboles monétaires)
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ Chaque règle cite sa source. Elles valent quel que soit le niveau : une PR norm
|
|||
### Vie privée
|
||||
|
||||
- Aucune donnée financière ne quitte le poste : ni télémétrie, ni analytics, et le CSV comme la base restent locaux. Un appel réseau ajouté se justifie dans la PR : il n'envoie rien de financier ni aucun identifiant brut, et il passe derrière un consentement ou l'édition. — `CLAUDE.md` « Privacy-first — NON NÉGOCIABLE », [ADR 0009](docs/adr/0009-proxy-price-fetching-via-maximus-api.md), [ADR 0020](docs/adr/0020-identifiant-machine-derive.md)
|
||||
- Les liens vers la page produit (`purchaseUrl`, `src/shared/purchaseUrl.ts`) portent `utm_source=app`, `utm_medium=desktop`, `utm_campaign=simpl-resultat` et un `utm_content` fixé par le bouton (type `ProductPageLink` : `locked-module`, `license-card`, `update-locked`, `update-locked-download`), jamais une valeur tirée de l'utilisateur ou de l'installation (version, édition, module, clé, machine, état d'erreur) ; le guide intégré le dit (`docs.settings.tips[6]`). Ce n'est pas de la télémétrie : l'app n'envoie rien, le navigateur ouvre la page sur un clic. — décision de Max du 2026-11-02 (#525)
|
||||
- Les appels sortants partent tous du Rust (`reqwest`) : `auth_commands.rs` (compte), `license_commands.rs` (licence et activation), `balance_commands.rs` (`fetch_price`, qui porte le jeton d'activation) et `feedback_commands.rs`, plus l'endpoint du plugin d'updater. Le `connect-src` de `app.security.csp` (`api.`, `auth.` et `feedback.lacompagniemaximus.com`) ne borne que la webview : lire chaque URL, chaque en-tête et chaque corps envoyé. — `CLAUDE.md` « Privacy-first — NON NÉGOCIABLE », `src-tauri/tauri.conf.json`, `src-tauri/src/commands/`
|
||||
- Les cours passent par `maximus-api`, après un consentement explicite par profil, avec les seuls en-têtes `Authorization`, `Accept` et `User-Agent` : le fournisseur tiers ne voit jamais le poste. Ce consentement n'est vérifié que côté front (`PriceFetchControl.tsx`, `PriceFetchConsentToggle.tsx`) : `fetch_price` ne le revérifie pas. — [ADR 0009](docs/adr/0009-proxy-price-fetching-via-maximus-api.md), `src-tauri/src/commands/balance_commands.rs`
|
||||
- Seule l'activation envoie un identifiant de la machine, et seulement le dérivé (`HMAC-SHA256` de l'identifiant du système) ; un jeton émis avant la dérivation porte encore l'identifiant brut jusqu'à la réactivation. — [ADR 0020](docs/adr/0020-identifiant-machine-derive.md), § 2 et 5
|
||||
|
|
|
|||
|
|
@ -506,7 +506,7 @@ Révocation (#365) : `license.check`, dans le dossier de données, garde ce que
|
|||
|
||||
Identifiant machine (#350, [ADR 0020](adr/0020-identifiant-machine-derive.md)) : le serveur de licences ne reçoit plus l'identifiant du système (`machine_uid::get()` : `/etc/machine-id`, `MachineGuid`), que machine-id(5) tient pour confidentiel, mais `derive_machine_id`, soit `HMAC-SHA256` sous la clé fixe `com.simpl.resultat/license-machine-id/v1`, rendu en 64 caractères hexadécimaux. La clé et la formule sont figées, épinglées par deux vecteurs de référence ; un identifiant vide est refusé, jamais haché. `MachineIds` porte les deux formes de l'identifiant de cette machine, la dérivée et la brute, et la brute ne sert plus qu'à reconnaître ce qui date d'avant la dérivation : un jeton dont le claim la porte se lit toujours « Activée », et une ligne de la liste qui la porte est toujours marquée `is_this_machine`. Seule l'activation envoie un identifiant de cette machine (`activate_and_store_in`, qui dérive juste avant l'appel et exige que le jeton reçu porte le dérivé) ; la désactivation renvoie au serveur l'identifiant de la ligne choisie. `drop_token_of_deactivated_machine_in` supprime ensuite le jeton local s'il représentait la place libérée : toute ligne de cette machine l'emporte, sauf l'ancienne ligne brute quand le jeton vaut pour la ligne dérivée, restée active. `drop_token_of_unlisted_machine_in` (#367), appelée par `list_machines_in`, supprime le jeton quand la liste de la clé enregistrée ne nomme ce poste sous aucune des deux formes, si l'identifiant du système est lisible, si la liste est complète (`machines_from_verify` compte les lignes écartées, que l'affichage tolère toujours), si le jeton active ce poste et s'il n'a pas changé pendant la requête ; une erreur, une clé révoquée ou un 429 ne suppriment rien. Elle suppose que le serveur, s'il rehache un jour ses lignes brutes (maximus/maximus-api#82), produit exactement le dérivé ci-dessus, ce qu'un test épingle. Un identifiant du système illisible ne bloque ni la liste ni la désactivation, et se lit « non activée ». Plus aucune commande ne lit l'identifiant du système pour le remettre au webview ; la liste du serveur porte encore celui d'une ligne antérieure à la dérivation, jusqu'à la réactivation. La compatibilité avec l'identifiant brut a une condition de retrait, consignée dans l'ADR.
|
||||
|
||||
Le lien d'achat, `/{fr|en}/produits/simpl-resultat` (`src/shared/purchaseUrl.ts`), utilisé par la carte Licence, `PurchaseButton` et `DownloadLatestButton`, est un contrat avec le site : il est gravé dans des binaires qui ne se mettent plus à jour en édition gratuite (voir maximus/la-compagnie-maximus#153).
|
||||
Le lien d'achat, `/{fr|en}/produits/simpl-resultat` (`src/shared/purchaseUrl.ts`), utilisé par la carte Licence, `PurchaseButton` et `DownloadLatestButton`, est un contrat avec le site par son chemin : il est gravé dans des binaires qui ne se mettent plus à jour en édition gratuite (voir maximus/la-compagnie-maximus#153). Sa requête porte une étiquette UTM fixée par le bouton (`utm_content` : `locked-module`, `license-card`, `update-locked`, `update-locked-download`), jamais une valeur tirée de l'utilisateur (#525).
|
||||
|
||||
### `auth_commands.rs` — Compte Maximus / OAuth2 PKCE (5)
|
||||
|
||||
|
|
|
|||
|
|
@ -588,7 +588,7 @@ Configurez les préférences de l'application, vérifiez les mises à jour, acc
|
|||
- Vérification automatique des mises à jour avec installation en un clic
|
||||
- Journaux de l'application (logs) consultables avec filtres par niveau, copie et effacement
|
||||
- Historique des versions : les notes de la version installée s'affichent d'emblée, les autres versions sont repliées et se déplient d'un clic sur leur numéro, ou toutes ensemble avec « Tout déplier »
|
||||
- Envoi de feedback optionnel vers `feedback.lacompagniemaximus.com` (exception explicite au fonctionnement 100 % local — déclenche une demande de consentement avant le premier envoi)
|
||||
- Envoi de feedback optionnel vers `feedback.lacompagniemaximus.com` (sur demande ; une demande de consentement précède le premier envoi)
|
||||
- Export des données (transactions, catégories, ou les deux) en format JSON ou CSV
|
||||
- Import des données depuis un fichier exporté précédemment
|
||||
- Chiffrement AES-256-GCM optionnel pour les fichiers exportés
|
||||
|
|
@ -613,7 +613,7 @@ Configurez les préférences de l'application, vérifiez les mises à jour, acc
|
|||
- Exportez régulièrement pour garder une sauvegarde de vos données
|
||||
- Le guide d'utilisation peut être imprimé ou exporté en PDF via le bouton Imprimer
|
||||
- Les journaux persistent pendant la session — ils survivent à un rafraîchissement de la page
|
||||
- L'application ne contacte un serveur que pour les mises à jour, la connexion Maximus, le feedback, la licence (activation et vérification) et les cours du marché. Une seule requête part d'elle-même, au démarrage et à la saisie d'une clé : la vérification de la licence, au plus une fois par 24 heures pour une même clé et seulement si une clé est enregistrée. Aucune télémétrie
|
||||
- L'application ne contacte un serveur que pour les mises à jour, la connexion Maximus, le feedback, la licence (activation et vérification) et les cours du marché. Une seule requête part d'elle-même, au démarrage et à la saisie d'une clé : la vérification de la licence, au plus une fois par 24 heures pour une même clé et seulement si une clé est enregistrée. Aucune télémétrie. Les liens vers la page produit indiquent au site qu'ils viennent de l'application et de quel bouton, sans rien qui vous identifie.
|
||||
- En cas de problème, cliquez Envoyer un feedback et cochez « Inclure les derniers logs d'erreur » pour joindre les journaux récents automatiquement
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ function LicenseCardBody() {
|
|||
};
|
||||
|
||||
const handlePurchase = () => {
|
||||
void openUrl(purchaseUrl(i18n.language)).catch((e) =>
|
||||
void openUrl(purchaseUrl(i18n.language, "license-card")).catch((e) =>
|
||||
logError("Product page: openUrl failed", e),
|
||||
);
|
||||
};
|
||||
|
|
|
|||
97
src/components/settings/LicenseCard.wiring.test.ts
Normal file
97
src/components/settings/LicenseCard.wiring.test.ts
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// LicenseCard — the purchase button of the free edition and its label (#525).
|
||||
//
|
||||
// LicenseCard only renders LicenseCardBody under the key of the stored license
|
||||
// (#347); the body is not exported, so the test reads it from the element the
|
||||
// card returns (its `type`) and calls it with that element's props. The body
|
||||
// calls useState, so it runs under the shared harness (src/test/hookHarness.ts,
|
||||
// #409). The license context and the machine hook are replaced by fakes, as in
|
||||
// LicenseCard.render.test.tsx. The test clicks the purchase button through the
|
||||
// props of the rendered tree and reads the address handed to `openUrl`.
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import type { ReactElement, ReactNode } from "react";
|
||||
|
||||
vi.mock("react", async (orig) => (await import("../../test/hookHarness")).fakeReact(await orig()));
|
||||
vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
|
||||
|
||||
const ctx = vi.hoisted(() => ({
|
||||
openUrl: vi.fn((_url: string) => Promise.resolve()),
|
||||
/** The license context of the free edition: no key stored. */
|
||||
license: {
|
||||
status: "ready",
|
||||
edition: "free",
|
||||
features: [],
|
||||
info: null,
|
||||
error: null,
|
||||
validating: false,
|
||||
validationError: null,
|
||||
revoked: false,
|
||||
} as Record<string, unknown>,
|
||||
}));
|
||||
vi.mock("@tauri-apps/plugin-opener", () => ({ openUrl: (url: string) => ctx.openUrl(url) }));
|
||||
|
||||
vi.mock("../../contexts/LicenseContext", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../../contexts/LicenseContext")>()),
|
||||
useLicenseContext: () => ({ ...ctx.license, refresh: vi.fn(), submitKey: vi.fn() }),
|
||||
}));
|
||||
|
||||
vi.mock("../../hooks/useLicenseMachines", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../hooks/useLicenseMachines")>();
|
||||
const state = actual.initialLicenseMachinesState;
|
||||
return {
|
||||
...actual,
|
||||
useLicenseMachines: () => ({
|
||||
state,
|
||||
revoked: false,
|
||||
activate: vi.fn(),
|
||||
deactivate: vi.fn(),
|
||||
toggleList: vi.fn(),
|
||||
removeKey: vi.fn(),
|
||||
showEmptyState: actual.selectShowEmptyState(state),
|
||||
canDeactivate: actual.selectCanDeactivate(state),
|
||||
canActivate: actual.selectCanActivate(state, false),
|
||||
canRemoveKey: actual.selectCanRemoveKey(state),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
import { hookHarness } from "../../test/hookHarness";
|
||||
import { find, texts } from "../../test/elementTree";
|
||||
import LicenseCard from "./LicenseCard";
|
||||
|
||||
const harness = hookHarness();
|
||||
|
||||
/**
|
||||
* One render of the card's body: LicenseCardBody, read from the element that
|
||||
* LicenseCard returns. LicenseCard itself calls no hook of React: it is called
|
||||
* as a plain function, and only the body is mounted on the harness.
|
||||
*/
|
||||
function renderBody(): ReactNode {
|
||||
const card = LicenseCard() as ReactElement<Record<string, unknown>>;
|
||||
const Body = card.type as (props: Record<string, unknown>) => ReactNode;
|
||||
expect(Body).toBeTypeOf("function");
|
||||
expect(Body).not.toBe(LicenseCard);
|
||||
return harness.render(() => Body(card.props));
|
||||
}
|
||||
|
||||
/** The purchase button of the free edition: the one labelled « Buy Simpl'Result » (`license.purchase`). */
|
||||
function purchaseButton(tree: ReactNode) {
|
||||
const buttons = find(tree, (el) => el.type === "button" && texts(el).includes("t(license.purchase)"));
|
||||
expect(buttons).toHaveLength(1);
|
||||
return buttons[0];
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
harness.clear();
|
||||
ctx.openUrl.mockClear();
|
||||
});
|
||||
|
||||
describe("LicenseCard — the purchase button of the free edition (#525)", () => {
|
||||
it("opens the product page labelled license-card", () => {
|
||||
(purchaseButton(renderBody()).props.onClick as () => void)();
|
||||
expect(ctx.openUrl).toHaveBeenCalledTimes(1);
|
||||
const url = new URL(ctx.openUrl.mock.calls[0][0]);
|
||||
expect(`${url.origin}${url.pathname}`).toBe("https://lacompagniemaximus.com/fr/produits/simpl-resultat");
|
||||
expect(url.searchParams.get("utm_content")).toBe("license-card");
|
||||
});
|
||||
});
|
||||
|
|
@ -94,7 +94,10 @@ export default function UpdateCard() {
|
|||
</p>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<PurchaseButton className="inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm" />
|
||||
<PurchaseButton
|
||||
link="update-locked"
|
||||
className="inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm"
|
||||
/>
|
||||
<HaveKeyButton className="inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm" />
|
||||
</div>
|
||||
<DownloadLatestButton />
|
||||
|
|
|
|||
61
src/components/settings/UpdateCard.wiring.test.ts
Normal file
61
src/components/settings/UpdateCard.wiring.test.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// UpdateCard — the product page buttons of the free edition and their label (#525).
|
||||
//
|
||||
// The card calls useState, useCallback and useEffect, so it runs under the shared
|
||||
// harness (src/test/hookHarness.ts, #409) to be called as a plain function and
|
||||
// expose the props of the elements it renders. `useUpdater` is replaced, as in
|
||||
// UpsellCtas.render.test.tsx, by the state of the free edition: `notEntitled`.
|
||||
// No effect is run (`commit()`): the card's one effect only fetches release
|
||||
// notes for an available update. PurchaseButton and DownloadLatestButton stay
|
||||
// elements, never called: what they open with their label is proved by
|
||||
// UpsellCtas.render.test.tsx.
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
vi.mock("react", async (orig) => (await import("../../test/hookHarness")).fakeReact(await orig()));
|
||||
vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock());
|
||||
vi.mock("@tauri-apps/plugin-opener", () => ({ openUrl: vi.fn(() => Promise.resolve()) }));
|
||||
|
||||
vi.mock("../../contexts/LicenseContext", () => ({
|
||||
useLicenseContext: () => ({ revoked: false }),
|
||||
}));
|
||||
|
||||
vi.mock("../../hooks/useUpdater", () => ({
|
||||
useUpdater: () => ({
|
||||
state: { status: "notEntitled", version: null, body: null, progress: 0, contentLength: null, error: null },
|
||||
checkForUpdate: vi.fn(),
|
||||
downloadAndInstall: vi.fn(),
|
||||
installAndRestart: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
import { hookHarness } from "../../test/hookHarness";
|
||||
import { find, texts } from "../../test/elementTree";
|
||||
import UpdateCard from "./UpdateCard";
|
||||
import PurchaseButton from "../shared/PurchaseButton";
|
||||
import DownloadLatestButton from "../shared/DownloadLatestButton";
|
||||
import HaveKeyButton from "../shared/HaveKeyButton";
|
||||
|
||||
const harness = hookHarness();
|
||||
|
||||
/** One render of the mounted card. */
|
||||
const render = (): ReactNode => harness.render(() => UpdateCard());
|
||||
|
||||
beforeEach(() => harness.clear());
|
||||
|
||||
describe("UpdateCard — updates locked in the free edition (#346, #525)", () => {
|
||||
it("offers Get Base labelled update-locked and Download the latest version", () => {
|
||||
const tree = render();
|
||||
expect(texts(tree)).toContain("t(settings.updates.notEntitled)");
|
||||
|
||||
const purchase = find(tree, (el) => el.type === PurchaseButton);
|
||||
expect(purchase).toHaveLength(1);
|
||||
expect(purchase[0].props.link).toBe("update-locked");
|
||||
|
||||
const download = find(tree, (el) => el.type === DownloadLatestButton);
|
||||
expect(download).toHaveLength(1);
|
||||
// The download button has a label of its own, fixed inside it.
|
||||
expect(download[0].props).not.toHaveProperty("link");
|
||||
|
||||
expect(find(tree, (el) => el.type === HaveKeyButton)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
|
@ -15,9 +15,10 @@ interface DownloadLatestButtonProps {
|
|||
/**
|
||||
* "Download the latest version", shown in the free edition where automatic updates
|
||||
* are locked (issue #346). It opens the product page, which serves the latest
|
||||
* installers directly (la-compagnie-maximus#153). No update check runs here: the
|
||||
* free edition makes no network call for updates. A failure to open the browser
|
||||
* is logged, like PurchaseButton's.
|
||||
* installers directly (la-compagnie-maximus#153), always labelled
|
||||
* `update-locked-download` (#525): the update card and the error page share it. No
|
||||
* update check runs here: the free edition makes no network call for updates. A
|
||||
* failure to open the browser is logged, like PurchaseButton's.
|
||||
*/
|
||||
export default function DownloadLatestButton({
|
||||
className = DEFAULT_LAYOUT,
|
||||
|
|
@ -27,7 +28,7 @@ export default function DownloadLatestButton({
|
|||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
void openUrl(purchaseUrl(i18n.language)).catch((e) =>
|
||||
void openUrl(purchaseUrl(i18n.language, "update-locked-download")).catch((e) =>
|
||||
logError("Product page: openUrl failed", e),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ export default function ErrorPage({ error }: ErrorPageProps) {
|
|||
<p className="text-sm text-[var(--muted-foreground)]">
|
||||
{t("error.updateNotEntitled")}
|
||||
</p>
|
||||
<PurchaseButton />
|
||||
<PurchaseButton link="update-locked" />
|
||||
<DownloadLatestButton />
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
78
src/components/shared/ErrorPage.wiring.test.ts
Normal file
78
src/components/shared/ErrorPage.wiring.test.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// ErrorPage — the product page buttons of the free edition and their label (#525).
|
||||
//
|
||||
// A static render never shows them: they appear once the update check, run by a
|
||||
// click, learns that automatic updates are locked (#346). React's hooks come from
|
||||
// the shared harness (src/test/hookHarness.ts, #409): the page runs as a plain
|
||||
// function, its state survives from one call to the next as between two renders
|
||||
// of a mounted component, and the test clicks the update check through the props
|
||||
// of the rendered tree, awaits it, then renders again to read what it opened (the
|
||||
// harness does not re-render after a setter). No slot is preset, so the test does
|
||||
// not depend on the order of the page's hooks (docs/architecture.md, « Limites
|
||||
// connues »). PurchaseButton and DownloadLatestButton stay elements, never called:
|
||||
// what they open with their label is proved by UpsellCtas.render.test.tsx.
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
vi.mock("react", async (orig) => (await import("../../test/hookHarness")).fakeReact(await orig()));
|
||||
vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock());
|
||||
|
||||
const tauri = vi.hoisted(() => ({
|
||||
/** `check_entitlement` answers false: the free edition. */
|
||||
invoke: vi.fn(async (_command: string, _args?: unknown) => false as unknown),
|
||||
check: vi.fn(async () => null),
|
||||
}));
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke: tauri.invoke }));
|
||||
vi.mock("@tauri-apps/plugin-updater", () => ({ check: tauri.check }));
|
||||
vi.mock("@tauri-apps/plugin-opener", () => ({ openUrl: vi.fn(() => Promise.resolve()) }));
|
||||
|
||||
import { hookHarness } from "../../test/hookHarness";
|
||||
import { find, texts } from "../../test/elementTree";
|
||||
import ErrorPage from "./ErrorPage";
|
||||
import PurchaseButton from "./PurchaseButton";
|
||||
import DownloadLatestButton from "./DownloadLatestButton";
|
||||
|
||||
const harness = hookHarness();
|
||||
|
||||
/** One render of the mounted page. */
|
||||
const render = (): ReactNode => harness.render(() => ErrorPage({}));
|
||||
|
||||
/** The update check: the button labelled « Check for updates ». */
|
||||
function updateCheck(tree: ReactNode) {
|
||||
const buttons = find(tree, (el) => el.type === "button" && texts(el).includes("t(error.checkUpdate)"));
|
||||
expect(buttons).toHaveLength(1);
|
||||
return buttons[0];
|
||||
}
|
||||
|
||||
const purchases = (tree: ReactNode) => find(tree, (el) => el.type === PurchaseButton);
|
||||
const downloads = (tree: ReactNode) => find(tree, (el) => el.type === DownloadLatestButton);
|
||||
|
||||
beforeEach(() => {
|
||||
harness.clear();
|
||||
tauri.invoke.mockClear();
|
||||
tauri.check.mockClear();
|
||||
});
|
||||
|
||||
describe("ErrorPage — updates locked in the free edition (#346, #525)", () => {
|
||||
it("shows no product page button before the update check", () => {
|
||||
const tree = render();
|
||||
expect(purchases(tree)).toHaveLength(0);
|
||||
expect(downloads(tree)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("after the check, offers Get Base labelled update-locked and Download the latest version", async () => {
|
||||
await (updateCheck(render()).props.onClick as () => Promise<void>)();
|
||||
expect(tauri.invoke).toHaveBeenCalledWith("check_entitlement", { feature: "auto-update" });
|
||||
// The free edition makes no update check.
|
||||
expect(tauri.check).not.toHaveBeenCalled();
|
||||
|
||||
const opened = render();
|
||||
expect(texts(opened)).toContain("t(error.updateNotEntitled)");
|
||||
const purchase = purchases(opened);
|
||||
expect(purchase).toHaveLength(1);
|
||||
expect(purchase[0].props.link).toBe("update-locked");
|
||||
const download = downloads(opened);
|
||||
expect(download).toHaveLength(1);
|
||||
// The download button has a label of its own, fixed inside it.
|
||||
expect(download[0].props).not.toHaveProperty("link");
|
||||
});
|
||||
});
|
||||
|
|
@ -9,24 +9,31 @@ const COLOURS =
|
|||
"bg-[var(--primary)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity";
|
||||
|
||||
interface PurchaseButtonProps {
|
||||
/**
|
||||
* The screen the button sits on, sent as the `utm_content` of the product page
|
||||
* (#525): the locked screen of a module, or the update card and the error page of
|
||||
* the free edition. A fixed label of the caller, never a value of the user.
|
||||
*/
|
||||
link: "locked-module" | "update-locked";
|
||||
/** Replaces the default layout classes (width, padding, radius); colours stay fixed. */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* "Get Base": opens the localized product page in the system browser (issue #346).
|
||||
* Needs no router, so it also works on ErrorPage and in modals rendered outside
|
||||
* BrowserRouter. It never calls a modal host's onNavigate: the page opens in the
|
||||
* browser and the app stays where it was. A failure to open the browser is
|
||||
* logged, so it shows up in the in-app logs instead of vanishing.
|
||||
* "Get Base": opens the localized product page in the system browser (issue #346),
|
||||
* labelled with the caller's `link` (#525). Needs no router, so it also works on
|
||||
* ErrorPage and in modals rendered outside BrowserRouter. It never calls a modal
|
||||
* host's onNavigate: the page opens in the browser and the app stays where it was.
|
||||
* A failure to open the browser is logged, so it shows up in the in-app logs
|
||||
* instead of vanishing.
|
||||
*/
|
||||
export default function PurchaseButton({ className = DEFAULT_LAYOUT }: PurchaseButtonProps) {
|
||||
export default function PurchaseButton({ link, className = DEFAULT_LAYOUT }: PurchaseButtonProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
void openUrl(purchaseUrl(i18n.language)).catch((e) =>
|
||||
void openUrl(purchaseUrl(i18n.language, link)).catch((e) =>
|
||||
logError("Product page: openUrl failed", e),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ vi.mock("../../hooks/useUpdater", () => ({
|
|||
}));
|
||||
|
||||
import { find } from "../../test/elementTree";
|
||||
import type { ProductPageLink } from "../../shared/purchaseUrl";
|
||||
import UpsellGate from "./UpsellGate";
|
||||
import PurchaseButton from "./PurchaseButton";
|
||||
import DownloadLatestButton from "./DownloadLatestButton";
|
||||
|
|
@ -113,30 +114,75 @@ describe("UpsellGate wiring", () => {
|
|||
expect(purchase).toHaveLength(1);
|
||||
expect(purchase[0].props).not.toHaveProperty("onNavigate");
|
||||
});
|
||||
|
||||
it("labels Get Base with the locked screen of a module (#525)", () => {
|
||||
const tree = UpsellGate({ feature: "budget", requiredTier: "base" });
|
||||
const purchase = find(tree, (el) => el.type === PurchaseButton);
|
||||
expect(purchase).toHaveLength(1);
|
||||
expect(purchase[0].props.link).toBe("locked-module");
|
||||
});
|
||||
});
|
||||
|
||||
// Both buttons open the product page. A failure to open the browser must reach
|
||||
// the in-app logs, not vanish as an unhandled rejection.
|
||||
function productPageButtonTests(Button: (props: { className?: string }) => ReactNode) {
|
||||
it("opens the product page in the app language", () => {
|
||||
/** The address a button opened: the product page, then its UTM label (#525). */
|
||||
const productPage = (locale: "fr" | "en", link: ProductPageLink) =>
|
||||
`https://lacompagniemaximus.com/${locale}/produits/simpl-resultat` +
|
||||
`?utm_source=app&utm_medium=desktop&utm_campaign=simpl-resultat&utm_content=${link}`;
|
||||
|
||||
// Both buttons open the product page, labelled with their screen (#525). A
|
||||
// failure to open the browser must reach the in-app logs, not vanish as an
|
||||
// unhandled rejection.
|
||||
function productPageButtonTests(render: () => ReactNode, link: ProductPageLink) {
|
||||
it("opens the product page in the app language, with its label", () => {
|
||||
language = "en";
|
||||
const button = Button({}) as ReactElement<{ onClick: () => void }>;
|
||||
const button = render() as ReactElement<{ onClick: () => void }>;
|
||||
button.props.onClick();
|
||||
expect(openUrl).toHaveBeenCalledWith("https://lacompagniemaximus.com/en/produits/simpl-resultat");
|
||||
expect(openUrl).toHaveBeenCalledTimes(1);
|
||||
expect(openUrl).toHaveBeenCalledWith(productPage("en", link));
|
||||
});
|
||||
|
||||
it("logs a failure to open the browser", async () => {
|
||||
const failure = new Error("no browser");
|
||||
openUrl.mockRejectedValueOnce(failure);
|
||||
const button = Button({}) as ReactElement<{ onClick: () => void }>;
|
||||
const button = render() as ReactElement<{ onClick: () => void }>;
|
||||
button.props.onClick();
|
||||
await vi.waitFor(() => expect(logError).toHaveBeenCalledWith(expect.any(String), failure));
|
||||
});
|
||||
}
|
||||
|
||||
describe("PurchaseButton", () => productPageButtonTests(PurchaseButton));
|
||||
describe("PurchaseButton", () => {
|
||||
productPageButtonTests(() => PurchaseButton({ link: "update-locked" }), "update-locked");
|
||||
|
||||
describe("DownloadLatestButton", () => productPageButtonTests(DownloadLatestButton));
|
||||
it("opens the label its caller gives: the locked screen's is locked-module", () => {
|
||||
const button = PurchaseButton({ link: "locked-module" }) as ReactElement<{ onClick: () => void }>;
|
||||
button.props.onClick();
|
||||
expect(openUrl).toHaveBeenCalledWith(productPage("fr", "locked-module"));
|
||||
});
|
||||
|
||||
it("takes only its two labels, and needs one: checked by tsc, not by vitest", () => {
|
||||
// If `link` were widened (to ProductPageLink or to string) or made optional,
|
||||
// these directives would be unused and `npm run build` would fail.
|
||||
const typeChecks = () => [
|
||||
// @ts-expect-error the license card calls purchaseUrl itself
|
||||
PurchaseButton({ link: "license-card" }),
|
||||
// @ts-expect-error the download label belongs to DownloadLatestButton
|
||||
PurchaseButton({ link: "update-locked-download" }),
|
||||
// @ts-expect-error a label is required
|
||||
PurchaseButton({}),
|
||||
];
|
||||
expect(typeChecks).toBeTypeOf("function");
|
||||
});
|
||||
});
|
||||
|
||||
describe("DownloadLatestButton", () => {
|
||||
productPageButtonTests(() => DownloadLatestButton({}), "update-locked-download");
|
||||
|
||||
it("takes no label: it always opens update-locked-download (checked by tsc)", () => {
|
||||
const typeChecks = () =>
|
||||
// @ts-expect-error no link prop: the update card and the error page share one label
|
||||
DownloadLatestButton({ link: "update-locked" });
|
||||
expect(typeChecks).toBeTypeOf("function");
|
||||
});
|
||||
});
|
||||
|
||||
describe("UpdateCard in the free edition", () => {
|
||||
it("offers Get Base, I already have a key and Download the latest version", () => {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export default function UpsellGate({ feature, requiredTier, onNavigate }: Upsell
|
|||
|
||||
<div className="flex flex-col gap-3">
|
||||
{cta.purchasable ? (
|
||||
<PurchaseButton />
|
||||
<PurchaseButton link="locked-module" />
|
||||
) : (
|
||||
<div>
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -1343,7 +1343,7 @@
|
|||
"Data export (transactions, categories, or both) in JSON or CSV format",
|
||||
"Data import from a previously exported file",
|
||||
"Optional AES-256-GCM encryption for exported files",
|
||||
"Optional feedback submission to feedback.lacompagniemaximus.com (explicit exception to the 100% local operation — prompts for consent)",
|
||||
"Optional feedback submission to feedback.lacompagniemaximus.com (on request, after a consent prompt)",
|
||||
"Show the getting-started path again (Settings → Users) once it was hidden"
|
||||
],
|
||||
"steps": [
|
||||
|
|
@ -1364,7 +1364,7 @@
|
|||
"The user guide can be printed or exported to PDF via the Print button",
|
||||
"Logs persist for the session — they survive a page refresh",
|
||||
"If you encounter an issue, copy the logs and attach them to your report",
|
||||
"The app only contacts a server for updates, Maximus sign-in, feedback, the license (activation and check) and market prices. One request goes out on its own, at startup and when a key is entered: the license check, at most once every 24 hours for the same key and only when a key is stored. No telemetry"
|
||||
"The app only contacts a server for updates, Maximus sign-in, feedback, the license (activation and check) and market prices. One request goes out on its own, at startup and when a key is entered: the license check, at most once every 24 hours for the same key and only when a key is stored. No telemetry. Links to the product page tell the site they come from the app and from which button, with nothing that identifies you."
|
||||
]
|
||||
},
|
||||
"editions": {
|
||||
|
|
@ -1563,7 +1563,7 @@
|
|||
},
|
||||
"consent": {
|
||||
"title": "Feedback submission",
|
||||
"body": "Your feedback will be sent to feedback.lacompagniemaximus.com so we can improve the app. This requires an internet connection and is an exception to the app's 100% local operation.",
|
||||
"body": "Your feedback will be sent to feedback.lacompagniemaximus.com so we can improve the app. Sending it requires an internet connection; your accounting data stays on your computer.",
|
||||
"accept": "I agree"
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1343,7 +1343,7 @@
|
|||
"Export des données (transactions, catégories, ou les deux) en format JSON ou CSV",
|
||||
"Import des données depuis un fichier exporté précédemment",
|
||||
"Chiffrement AES-256-GCM optionnel pour les fichiers exportés",
|
||||
"Envoi de feedback optionnel vers feedback.lacompagniemaximus.com (exception explicite au fonctionnement 100% local — déclenche une demande de consentement)",
|
||||
"Envoi de feedback optionnel vers feedback.lacompagniemaximus.com (sur demande, après une demande de consentement)",
|
||||
"Réaffichage du parcours de démarrage (Paramètres → Utilisateurs) quand il a été masqué"
|
||||
],
|
||||
"steps": [
|
||||
|
|
@ -1364,7 +1364,7 @@
|
|||
"Le guide d'utilisation peut être imprimé ou exporté en PDF via le bouton Imprimer",
|
||||
"Les journaux persistent pendant la session — ils survivent à un rafraîchissement de la page",
|
||||
"En cas de problème, copiez les journaux et joignez-les à votre signalement",
|
||||
"L'application ne contacte un serveur que pour les mises à jour, la connexion Maximus, le feedback, la licence (activation et vérification) et les cours du marché. Une seule requête part d'elle-même, au démarrage et à la saisie d'une clé : la vérification de la licence, au plus une fois par 24 heures pour une même clé et seulement si une clé est enregistrée. Aucune télémétrie"
|
||||
"L'application ne contacte un serveur que pour les mises à jour, la connexion Maximus, le feedback, la licence (activation et vérification) et les cours du marché. Une seule requête part d'elle-même, au démarrage et à la saisie d'une clé : la vérification de la licence, au plus une fois par 24 heures pour une même clé et seulement si une clé est enregistrée. Aucune télémétrie. Les liens vers la page produit indiquent au site qu'ils viennent de l'application et de quel bouton, sans rien qui vous identifie."
|
||||
]
|
||||
},
|
||||
"editions": {
|
||||
|
|
@ -1563,7 +1563,7 @@
|
|||
},
|
||||
"consent": {
|
||||
"title": "Envoi de feedback",
|
||||
"body": "Votre feedback sera envoyé à feedback.lacompagniemaximus.com pour que nous puissions améliorer l'application. Cette opération nécessite une connexion Internet et constitue une exception au fonctionnement 100 % local de l'application.",
|
||||
"body": "Votre feedback sera envoyé à feedback.lacompagniemaximus.com pour que nous puissions améliorer l'application. Cet envoi nécessite une connexion Internet ; vos données comptables, elles, restent sur votre ordinateur.",
|
||||
"accept": "J'accepte"
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,37 +1,103 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { purchaseUrl } from "./purchaseUrl";
|
||||
import { purchaseUrl, type ProductPageLink } from "./purchaseUrl";
|
||||
|
||||
// The old constant pointed at /simpl-resultat, a path the site did not serve
|
||||
// when #270 was filed (307 to /fr/simpl-resultat, then 404). The site has
|
||||
// redirected it since la-compagnie-maximus#153; the app now links the
|
||||
// localized product page, /{locale}/produits/simpl-resultat, directly.
|
||||
describe("purchaseUrl", () => {
|
||||
it("opens the French product page when the app is in French", () => {
|
||||
expect(purchaseUrl("fr")).toBe(
|
||||
"https://lacompagniemaximus.com/fr/produits/simpl-resultat",
|
||||
);
|
||||
});
|
||||
//
|
||||
// The contract with the site is that path, compiled into every released
|
||||
// binary. Since #525 the URL also carries a query: a fixed UTM label set by
|
||||
// the button that opens the page, never a value taken from the user.
|
||||
|
||||
it("opens the English product page when the app is in English", () => {
|
||||
expect(purchaseUrl("en")).toBe(
|
||||
"https://lacompagniemaximus.com/en/produits/simpl-resultat",
|
||||
);
|
||||
const ORIGIN = "https://lacompagniemaximus.com";
|
||||
const pageOf = (locale: "fr" | "en") => `/${locale}/produits/simpl-resultat`;
|
||||
|
||||
/** The four labels, one per button (decision of Max, 2026-11-02). */
|
||||
const LINKS: readonly ProductPageLink[] = [
|
||||
"locked-module",
|
||||
"license-card",
|
||||
"update-locked",
|
||||
"update-locked-download",
|
||||
];
|
||||
|
||||
/** The app's languages and the page each one opens. */
|
||||
const LANGUAGES = [
|
||||
["fr", "fr"],
|
||||
["en", "en"],
|
||||
] as const;
|
||||
|
||||
/** The part of the URL the site's contract covers: origin and path, without the query. */
|
||||
const contractOf = (url: string) => {
|
||||
const parsed = new URL(url);
|
||||
return `${parsed.origin}${parsed.pathname}`;
|
||||
};
|
||||
|
||||
describe("purchaseUrl — the path of the contract", () => {
|
||||
it.each(LANGUAGES)("opens exactly the product page for %s, whatever the label", (language, locale) => {
|
||||
for (const link of LINKS) {
|
||||
const url = new URL(purchaseUrl(language, link));
|
||||
expect(url.origin).toBe(ORIGIN);
|
||||
expect(url.pathname).toBe(pageOf(locale));
|
||||
expect(url.hash).toBe("");
|
||||
expect(url.username).toBe("");
|
||||
expect(url.password).toBe("");
|
||||
}
|
||||
});
|
||||
|
||||
it("maps regional English variants to the English page", () => {
|
||||
expect(purchaseUrl("en-US")).toBe(
|
||||
"https://lacompagniemaximus.com/en/produits/simpl-resultat",
|
||||
);
|
||||
expect(purchaseUrl("EN")).toBe(
|
||||
"https://lacompagniemaximus.com/en/produits/simpl-resultat",
|
||||
);
|
||||
expect(contractOf(purchaseUrl("en-US", "locked-module"))).toBe(`${ORIGIN}${pageOf("en")}`);
|
||||
expect(contractOf(purchaseUrl("EN", "license-card"))).toBe(`${ORIGIN}${pageOf("en")}`);
|
||||
});
|
||||
|
||||
it("falls back to French for any other value", () => {
|
||||
for (const language of ["fr-CA", "de", "", "cimode"]) {
|
||||
expect(purchaseUrl(language)).toBe(
|
||||
"https://lacompagniemaximus.com/fr/produits/simpl-resultat",
|
||||
);
|
||||
expect(contractOf(purchaseUrl(language, "update-locked"))).toBe(`${ORIGIN}${pageOf("fr")}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("purchaseUrl — the UTM label (#525)", () => {
|
||||
it.each(LANGUAGES)("carries the four UTM keys and no other, in a fixed order (%s)", (language) => {
|
||||
for (const link of LINKS) {
|
||||
const { searchParams } = new URL(purchaseUrl(language, link));
|
||||
expect([...searchParams.keys()]).toEqual(["utm_source", "utm_medium", "utm_campaign", "utm_content"]);
|
||||
expect(Object.fromEntries(searchParams)).toEqual({
|
||||
utm_source: "app",
|
||||
utm_medium: "desktop",
|
||||
utm_campaign: "simpl-resultat",
|
||||
utm_content: link,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("sets utm_content to the label, for each of the four", () => {
|
||||
const contents = LINKS.map((link) => new URL(purchaseUrl("fr", link)).searchParams.get("utm_content"));
|
||||
expect(contents).toEqual(["locked-module", "license-card", "update-locked", "update-locked-download"]);
|
||||
});
|
||||
|
||||
it("writes the exact address the browser opens", () => {
|
||||
expect(purchaseUrl("fr", "locked-module")).toBe(
|
||||
"https://lacompagniemaximus.com/fr/produits/simpl-resultat" +
|
||||
"?utm_source=app&utm_medium=desktop&utm_campaign=simpl-resultat&utm_content=locked-module",
|
||||
);
|
||||
expect(purchaseUrl("en", "update-locked-download")).toBe(
|
||||
"https://lacompagniemaximus.com/en/produits/simpl-resultat" +
|
||||
"?utm_source=app&utm_medium=desktop&utm_campaign=simpl-resultat&utm_content=update-locked-download",
|
||||
);
|
||||
});
|
||||
|
||||
it("takes only the four labels: a free string does not compile", () => {
|
||||
// Checked by `tsc` (`npm run build`), not by vitest: if `link` were widened to
|
||||
// `string`, these directives would be unused and the build would fail. A value
|
||||
// of the user (an e-mail, a version, a key) cannot reach the URL.
|
||||
const typeChecks = () => {
|
||||
const fromTheUser: string = "user@example.com";
|
||||
// @ts-expect-error a label is one of the four constants of ProductPageLink
|
||||
purchaseUrl("fr", fromTheUser);
|
||||
// @ts-expect-error no URL without a label
|
||||
purchaseUrl("fr");
|
||||
};
|
||||
expect(typeChecks).toBeTypeOf("function");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,19 +1,41 @@
|
|||
// Product page on the vitrine, where Simpl'Résultat Base is sold.
|
||||
//
|
||||
// Contract with the site: this path is compiled into every released binary,
|
||||
// Contract with the site: the path is compiled into every released binary,
|
||||
// and an install without a key never updates past v0.15.0 (auto-update is
|
||||
// Base+), so a URL shipped here must keep answering for years. Renaming the
|
||||
// Base+), so a path shipped here must keep answering for years. Renaming the
|
||||
// page on the site requires a 308 redirect — see
|
||||
// maximus/la-compagnie-maximus#153, which also redirects the old
|
||||
// `/simpl-resultat` path baked into v0.14.0 and v0.15.0 (issue #270).
|
||||
//
|
||||
// The query is not part of that contract: it is a fixed UTM label set by the
|
||||
// button that opens the page (#525), so the site can tell a visit from the app
|
||||
// apart from a direct one. It never carries a value taken from the user or the
|
||||
// install (version, edition, module, key, machine, error state): `link` is one
|
||||
// of the four constants of `ProductPageLink`, written in the code of each button.
|
||||
const PRODUCT_PAGE = "https://lacompagniemaximus.com/{locale}/produits/simpl-resultat";
|
||||
|
||||
/** The button that opens the product page, sent as the `utm_content` of its URL (#525). */
|
||||
export type ProductPageLink =
|
||||
| "locked-module"
|
||||
| "license-card"
|
||||
| "update-locked"
|
||||
| "update-locked-download";
|
||||
|
||||
/**
|
||||
* Localized product page for the app language. `i18n.language` is `fr` or
|
||||
* `en` in practice; any English variant opens the English page, anything else
|
||||
* falls back to French (the app's default language).
|
||||
* Localized product page for the app language, labelled with the button that
|
||||
* opens it. `i18n.language` is `fr` or `en` in practice; any English variant
|
||||
* opens the English page, anything else falls back to French (the app's
|
||||
* default language). The query always holds these four keys, in this order:
|
||||
* `utm_source=app`, `utm_medium=desktop`, `utm_campaign=simpl-resultat`,
|
||||
* `utm_content=<link>`.
|
||||
*/
|
||||
export function purchaseUrl(language: string): string {
|
||||
export function purchaseUrl(language: string, link: ProductPageLink): string {
|
||||
const locale = language.toLowerCase().startsWith("en") ? "en" : "fr";
|
||||
return PRODUCT_PAGE.replace("{locale}", locale);
|
||||
const query = new URLSearchParams([
|
||||
["utm_source", "app"],
|
||||
["utm_medium", "desktop"],
|
||||
["utm_campaign", "simpl-resultat"],
|
||||
["utm_content", link],
|
||||
]);
|
||||
return `${PRODUCT_PAGE.replace("{locale}", locale)}?${query.toString()}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue