diff --git a/PRIVACY.md b/PRIVACY.md index 378d162..a9c4ba9 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -22,26 +22,43 @@ You choose, before you start: - **Kept:** the letter's text, when each character was typed, and numbers sampled four times a second: heart rate, a breathing value and (if you - allow it) a smile score. Six seconds of the pulse wave for the seal. + allow it) a smile score. Six seconds of the pulse wave for the seal. The + names you type in "To" and "From", and the date you sealed it (the day + only, no time of day). - **Never kept:** video, photos, frames or anything that shows your face. - Words you delete are dropped unless you chose to share them. + Words you delete are dropped unless you chose to share them. If you turn + "Show where I smiled" off, smiles are not requested from the SDK at all. ## Where it goes -- **While you write**, nothing is saved to disk. The letter exists only in - the app's memory. +- **While you write**, Heartwritten saves nothing to disk. The letter exists + only in the app's memory. Nothing is recorded until you type the first + character. - **The SmartSpectra SDK** measures on your computer. Presage's documentation says all metric computation runs on-device and the SDK calls Presage's service only to check the API key, so it needs a network connection while measuring. Presage says its telemetry does not include frames or vitals. Telemetry is off in Heartwritten unless you turn it on; if you do, Presage receives - session summaries and device details linked to your API key. + session summaries and device details linked to your API key. The SDK is + Presage's own code, so what it sends is Presage's statement, not something + Heartwritten can enforce. Heartwritten's own code makes no network requests. - **When you seal it**, the letter is packed into a token that lives in the link (after the `#`, which browsers don't send to servers) or in an HTML file you - save. Heartwritten has no server and no account. Nobody has the letter until - you send the link or file to them. -- **The reader page** can't send anything: its Content Security Policy blocks - every network request, and it loads nothing from anywhere else. + save. Heartwritten has no backend, no database and no account. Nobody has + the letter until you send the link or file to them. +- **The reader page** is one static HTML file. When someone opens a link, their + browser fetches that page from wherever it is hosted (by default + heartwritten.vercel.app), and the host sees what any website sees: an IP + address, a browser and a time. It does not see the letter, because the + letter is in the `#` part of the link. Once loaded, the page can't send + anything: its Content Security Policy blocks scripts from making network + requests, it loads nothing from anywhere else, and it sets no cookies and + uses no browser storage. A letter saved as a file opens with no network at + all. +- **The app itself** is built on Electron (Chromium). On Windows and Linux, + Chromium may download a spelling dictionary the first time you type; the + spell check itself runs on your computer. On macOS it uses the system's own + spell checker. ## How long it lasts, and deleting it diff --git a/README.md b/README.md index 74ed4cb..a29358a 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,9 @@ rushed, the ink warming where your heart sped up, the page rising and falling with your breath, a soft glow where you smiled. At the end they see where your heart was quickest and where it was steadiest. -Nothing goes to a server. A sealed letter lives inside its link (in the part -after `#`, which browsers never send) or inside a single HTML file. +The letter never goes to a server. A sealed letter lives inside its link (in +the part after `#`, which browsers never send) or inside a single HTML file. +There is no account and no database. ## Try it @@ -26,19 +27,27 @@ npm run start:sim ``` `start:sim` runs the whole app with simulated signals, so you can try it with -no key. Letters written this way are marked as samples, everywhere. +no key and no camera. Letters written this way are marked as samples, +everywhere. The first start downloads the Electron runtime (about 100 MB), so +give it a minute. + +`npm test` runs the tests and needs no key either. To read the real thing: 1. Get an API key from [physiology.presagetech.com](https://physiology.presagetech.com). 2. Put it in a file called `.smartspectra-key` in this folder (it's git-ignored), or set `SMARTSPECTRA_API_KEY` in your shell. -3. Check the SDK and key work: `npm run smoke` +3. Check the SDK loads and the key is found: `npm run smoke`. It says where it + found the key and never prints it. Presage checks the key itself when a + measurement starts, so to test that too, pass a short video of a face: + `npm run smoke -- path/to/face-clip.mp4` 4. Write a letter: `npm start` The SDK ships native libraries for macOS on Apple silicon, Linux (x64 and arm64) -and Windows x64. Measurement runs on your computer; the SDK needs a network connection -only so Presage can check the key. +and Windows x64. Heartwritten has been run on macOS on Apple silicon only. +Measurement runs on your computer. Presage's documentation says the SDK needs a +network connection only so Presage can check the key. To see a finished letter without the app, open the sample at https://heartwritten.vercel.app/sample, or run `npm run sample` and open @@ -63,8 +72,10 @@ by default. To host your own, deploy `dist/reader` anywhere static (a ``` or set `HEARTWRITTEN_READER_URL`. The reader has a Content Security Policy of -`default-src 'none'; connect-src 'none'`, so it can't send anything anywhere, -and the letter in the `#` part of the link never reaches the host's logs. +`default-src 'none'; connect-src 'none'`, so once it has loaded it can't send +anything anywhere. Whoever hosts the page sees an ordinary page request (an IP +address and a browser), as any website does, but the letter in the `#` part of +the link never reaches the host or its logs. ## How it responds to human signals @@ -87,12 +98,14 @@ read, what is kept and where it goes. See [PRIVACY.md](PRIVACY.md) for the full data handling, including the SDK's telemetry, which is off unless you turn it on. Heartwritten is for feeling, not medicine. Heart rate and breathing are camera -estimates. It makes no diagnosis and gives no health advice. +estimates. It makes no diagnosis, gives no health advice and isn't for +monitoring anyone. ## How it's built ``` app/main.cjs Electron main: window, camera permission, SDK IPC, key lookup +scripts/ Build, the sample letter, and the SDK load check (`npm run smoke`) src/writer/ The writing desk (consent → write → seal) sdk-source.js SmartSpectra renderer SDK, events decoded into metrics src/reader/ The reader, built into one self-contained HTML file @@ -108,7 +121,7 @@ src/shared/ test/ node --test: the core, plus the built pages in jsdom ``` -`npm test` builds everything and runs 25 tests, including the reader replaying +`npm test` builds everything and runs 28 tests, including the reader replaying a full letter and the writer going from consent to a sealed letter in simulated mode. diff --git a/docs/demo-script.md b/docs/demo-script.md index ae4efbb..c33d935 100644 --- a/docs/demo-script.md +++ b/docs/demo-script.md @@ -1,5 +1,8 @@ # Demo video script (about 90 seconds) +The shot-by-shot version, with capture settings and DEV's embed rules, is in +[shot-list.md](shot-list.md). + Record on your Mac with a real key, good light on your face and the room quiet. Screen-record the app, with a small picture-in-picture of your face only for shot 2. Write a short, real letter to someone (about 4 sentences) with one @@ -8,7 +11,7 @@ moment that actually moves you, and one line that makes you smile. | # | Time | On screen | Voice-over | | --- | --- | --- | --- | | 1 | 0:00–0:08 | A typed message on a phone, then a scanned handwritten letter with a crossed-out word | "Handwritten letters told you how they felt to write. Typed ones don't." | -| 2 | 0:08–0:18 | Heartwritten consent screen; tick agree; camera on; live heart trace and bpm settle | "Heartwritten reads your heartbeat, breathing and smiles through the webcam, with Presage SmartSpectra. Nothing is saved, and nothing goes to a server." | +| 2 | 0:08–0:18 | Heartwritten consent screen; tick agree; camera on; live heart trace and bpm settle | "Heartwritten reads your heartbeat, breathing and smiles through the webcam, with Presage SmartSpectra. Nothing is saved while you write, and the letter never goes to a server." | | 3 | 0:18–0:40 | Write the letter. Let the bpm visibly change at the emotional line. Smile once. Pause for a few seconds before the last line. | (Quiet. Let the typing and the live heart carry it.) | | 4 | 0:40–0:48 | Press **Seal it with my heartbeat**; the wax seal presses in | "You seal it with your own pulse wave. No two seals are the same." | | 5 | 0:48–1:15 | Open the link in a browser as the recipient. Tap the seal, it cracks. The letter writes itself: ink warming at the emotional line, the margin heart beating, a glow on the smiling words, "paused 9 seconds" in the margin | "They watch it written again, at your pace. The ink warms where your heart sped up. The page breathes with you." | diff --git a/docs/dev-post.md b/docs/dev-post.md index 70f7aed..b31e46c 100644 --- a/docs/dev-post.md +++ b/docs/dev-post.md @@ -1,6 +1,7 @@ --- title: "Heartwritten: letters that carry the heartbeat you wrote them with" -tags: presagechallenge, devchallenge, electron, javascript +published: false +tags: devchallenge, presagechallenge, electron, javascript --- *This is a submission for the [Presage SmartSpectra SDK Challenge](https://dev.to/challenges/presage-2026-11-04).* @@ -9,7 +10,7 @@ tags: presagechallenge, devchallenge, electron, javascript A handwritten letter used to tell you things the words didn't: where the pen pressed harder, where the writer stopped, the line they crossed out. Typed messages lost all of that. -**Heartwritten** brings it back with the one signal that never lies about how a sentence felt to write: your heartbeat. +**Heartwritten** brings some of it back with a signal you can't easily edit: your heartbeat while you wrote. You write a letter on your laptop. While you type, SmartSpectra reads your pulse, breathing and smiles through the webcam, and each word takes the ink of the heartbeat that wrote it. When you're done you seal it with a wax seal pressed from six seconds of your own pulse wave, so no two seals are alike. @@ -25,19 +26,24 @@ The person you send it to taps the seal, it cracks, and they watch your letter b At the end, a card shows where your heart was quickest and where it was steadiest, with the sentences. -There's no server and no account. A sealed letter lives entirely inside its link (in the part after `#`, which browsers never send anywhere) or in a single HTML file you can attach to an email. +There's no backend, no database and no account. A sealed letter lives entirely inside its link (in the part after `#`, which browsers never send anywhere) or in a single HTML file you can attach to an email. ## Demo - + +{% embed DEMO_VIDEO_LINK_GOES_HERE %} - +The video shows the live SmartSpectra signals (pulse trace, heart rate, breathing and smiles) while a real letter is written, then the same letter being opened. + +Open a sample letter in your browser: [heartwritten.vercel.app/sample](https://heartwritten.vercel.app/sample). That sample's heartbeat is simulated and labelled as such; the video shows a real one. ## Code - +{% github ubmids/heartwritten %} + +Repo: [github.com/ubmids/heartwritten](https://github.com/ubmids/heartwritten) (MIT). -Setup is in the README: `npm install`, add your SmartSpectra key, `npm start`. `npm run start:sim` runs the whole thing with simulated signals if you want to try it without a key. +Setup is in the README: `npm install`, put your SmartSpectra key in `.smartspectra-key`, then `npm start`. `npm run start:sim` runs the whole thing with simulated signals if you want to try it without a key or a camera, and `npm test` runs the 28 tests. ## How It Responds to Human Signals @@ -45,7 +51,7 @@ Every signal changes something you can see or hold in the finished letter. None | SmartSpectra signal | What it becomes | | --- | --- | -| `cardio.pulseRate` (stable readings only) | The colour of each character's ink, measured against *your own* median for that letter, so a calm writer and an anxious one both get a full range. It also sets the beat of the margin heart, and finds the quickest and steadiest sentences. | +| `cardio.pulseRate` (stable readings only) | The colour of each character's ink, measured against *your own* median for that letter, so a writer with a slow heart and one with a quick heart both get a full range. It also sets the beat of the margin heart, and finds the quickest and steadiest sentences. | | `cardio.arterialPressureTrace` | The wax seal. Six seconds of the pulse wave, wrapped into a ring around your initial. | | `breathing.upperTrace`, `breathing.rate` | The page breathing during replay. | | `face.expression` (happy) | The glow on words you wrote smiling. Optional, and it's the only face metric I request. | @@ -55,27 +61,33 @@ A few things I cared about: - **The signal follows the writing, not the clock.** Typing is recorded as timed edits and vitals at 4 Hz, and the replay lines them up, so the ink colour of a word is your heart rate *when you typed that word*. - **Only trustworthy readings count.** Pulse values that SmartSpectra doesn't mark stable are ignored, and old readings go stale after six seconds rather than painting the rest of the letter. -- **Relative, not clinical.** The ink compares you to yourself in that letter. It never says a number is good or bad. +- **Relative, never a verdict.** The ink compares you to yourself in that letter. It never says a number is good or bad, and it doesn't name a feeling. It shows where your heart was quicker or steadier and leaves the meaning to the two of you. - **Graceful degradation.** If a key isn't allowed expressions, the app drops smiles and keeps going. If you stop the camera halfway, the rest of the letter simply carries no heartbeat. -Under the hood it's an Electron app following Presage's quickstart pattern (main process binds the SDK IPC, the renderer runs `SmartSpectraSDK` with the camera), plus a reader page built into one self-contained HTML file. The letter is packed into a compact, deflated, URL-safe token, so a full page of writing with its heartbeat fits in a link of a few thousand characters. The repo has 25 tests, including the reader replaying a whole letter and the writer going from consent to a sealed letter. +Under the hood it's an Electron app following Presage's quickstart pattern (main process binds the SDK IPC, the renderer runs `SmartSpectraSDK` with the camera), plus a reader page built into one self-contained HTML file. The letter is packed into a compact, deflated, URL-safe token, so a full page of writing with its heartbeat fits in a link of a few thousand characters. It all happens live: the pulse trace, heart rate and breathing update on screen as you write, and each word is inked the moment you type it. The repo has 28 tests, including the reader replaying a whole letter and the writer going from consent to a sealed letter. ## Prize Categories -Most Creative or Delightful Use. +I'm entering both. + +**Most Creative or Delightful Use.** The idea came from old letters, where you can see the pen press harder or stop. I wanted a typed letter to carry something like that. So the heartbeat isn't shown as a chart. It becomes the ink, the wax seal and the pace of the page, and the person reading watches the letter being written again by the heart that wrote it. + +**Best Thoughtful Real-World Use.** The need is ordinary: people who are far apart, writing something that matters, with nothing but flat text to send. It's for anyone writing to someone they care about. To keep it usable, the reader needs nothing but a link (no app, no account, works on a phone), the writer gets plain-language hints about light and distance, and the app keeps working if a signal drops. Consent comes before the camera, the letter keeps numbers and never video, and there is no backend to trust (details below). ## Consent and Data Handling -- **Consent first.** The app opens on a consent screen. The camera stays off until you confirm you're the only person on camera and agree. A red dot shows while it's on, and you can stop it at any time. -- **What's read:** heart rate, pulse wave, breathing and smiles, estimated by SmartSpectra from your face. Measurement runs on your computer; per Presage's docs, the SDK contacts Presage's service only to check the API key. -- **What's kept:** the text, when each character was typed, and numbers sampled four times a second. Never video, photos or frames. Words you delete are dropped unless you choose to share them. -- **Storage:** nothing is saved while you write. A sealed letter exists only in the link or file you choose to send. Heartwritten has no server, no database and no account. -- **Sharing:** only with whoever you send the link or file to. The reader page has a Content Security Policy that blocks every network request, so opening a letter sends nothing anywhere, and the `#` part of a link never reaches the host. -- **Retention and deletion:** a letter lasts as long as its link or file. Delete those and it's gone. Closing the writer forgets an unsent letter. -- **SDK telemetry:** off by default (`enableTelemetry: false`). You can turn it on in the consent screen; Presage says its telemetry contains session summaries and device details linked to the key, never frames or vitals. -- **AI:** none. All the physiology comes from SmartSpectra. -- **Not medical:** camera estimates for feeling, not medicine. No diagnosis, no health advice, and not for monitoring anyone. +- **Consent first.** The app opens on a consent screen that says what is read, what is kept and where it goes. The camera stays off until you confirm you're the only person on camera and agree. A red dot shows while it's on, and **Stop camera** turns it off at any time. Heartwritten is for writing with your own face on camera, never for watching someone else. +- **What's read:** heart rate, pulse wave, breathing and smiles, estimated by SmartSpectra from your face. Measurement runs on your computer. Per Presage's docs, the SDK contacts Presage's service only to check the API key. +- **What's kept:** the text, the names you put in To and From, the date, when each character was typed, and numbers sampled four times a second. Never video, photos or frames. Words you delete are dropped unless you choose to share them, and if you turn smiles off they aren't requested from the SDK at all. +- **Storage:** nothing is saved while you write. A sealed letter exists only in the link or file you choose to send. Heartwritten has no backend, no database and no account. +- **Sharing:** only with whoever you send the link or file to. The reader is one static page. Its host sees an ordinary page request, as any website does, but never the letter, because the letter sits in the `#` part of the link. Once loaded, the page's Content Security Policy stops it sending anything anywhere. It sets no cookies and uses no browser storage. +- **Retention and deletion:** a letter lasts as long as its link or file. Delete those and it's gone, though anyone you sent it to keeps their copy, as with any letter. Closing the writer forgets an unsent letter. +- **SDK telemetry:** off by default (`enableTelemetry: false`). You can turn it on in the consent screen. Presage says its telemetry contains session summaries and device details linked to the key, never frames or vitals. +- **AI services:** none. All the physiology comes from SmartSpectra. +- **Not medical:** these are camera estimates, for feeling, not medicine. Heartwritten makes no diagnosis, gives no health advice, supports no medical decision and isn't for monitoring anyone. The full write-up is in [PRIVACY.md](https://github.com/ubmids/heartwritten/blob/main/PRIVACY.md). - + + + diff --git a/docs/shot-list.md b/docs/shot-list.md new file mode 100644 index 0000000..4746cc2 --- /dev/null +++ b/docs/shot-list.md @@ -0,0 +1,75 @@ +# Demo video shot list (target 80 seconds, hard limits 60 to 90) + +This is the cut-down, shot-by-shot version of [demo-script.md](demo-script.md). +The script is the story. This is what to capture and in what order. + +## Before you record + +- Real key in `.smartspectra-key`, then `npm start` (not `start:sim`). The + "Simulated heartbeat" pill must not be on screen in any shot. +- Light on your face from the front, nothing bright behind you. Wait for the + hint to stop asking for light or distance and for the bpm to show a number. +- Quiet room. Notifications off (Focus mode). Hide the Dock and menu bar extras. +- App window at its default size. Record the screen at 1920 by 1080, 30 fps. +- Decide the letter beforehand: about four sentences, to a real person, with + one line that matters to you and one that makes you smile. Fill "To" and + "From" with first names only. +- Never show the key, the `.smartspectra-key` file, a terminal with the + environment printed, or anyone else's face. +- Two sources: + - **SCREEN**: the screen recording of the app, then the browser. + - **CAM**: your face. The app's own camera tile (top left of the writing + desk, with the red dot) is enough. A separate picture-in-picture of you is + optional and belongs in shot 2 only. + +## Shots + +| # | Time | Length | Source | What is on screen | Action | Voice-over or caption | +| --- | --- | --- | --- | --- | --- | --- | +| 1 | 0:00 to 0:06 | 6 s | SCREEN | A plain typed chat message, then cut to the Heartwritten front page (heartwritten.vercel.app) with the ink specimen | Still, slow push in | "Handwritten letters told you how they felt to write. Typed ones don't." | +| 2 | 0:06 to 0:18 | 12 s | SCREEN + CAM | The consent screen. Open "What the camera reads, and where it goes" for a beat. Tick "I'm the only person on camera, and I agree to this". Press **Turn on the camera**. The camera tile, red dot, pulse trace and bpm appear and settle | Move the pointer slowly. Hold two seconds on the live trace once the bpm shows | "Heartwritten asks first. Then it reads your pulse, breathing and smiles through the webcam, with the Presage SmartSpectra SDK. The measurement runs on this laptop." | +| 3 | 0:18 to 0:38 | 20 s | SCREEN (camera tile visible) | Typing the letter. The words take their ink as they are typed. The bpm number and the trace move at the line that matters. The "smiling" mark lights once. A real pause of a few seconds before the last line | Type at your real pace. Speed this shot up to 2x in the edit if it runs long, but leave the pause at real speed | No voice. Typing sound only. Caption: "Live from the camera. Ink follows the heart rate." | +| 4 | 0:38 to 0:46 | 8 s | SCREEN | Press **Seal it with my heartbeat**. The wax seal appears, with "Sealed." and the private link | Hold on the seal for two seconds, then press **Copy link** | "You seal it with six seconds of your own pulse wave. No two seals are alike." | +| 5 | 0:46 to 1:08 | 22 s | SCREEN (browser, no camera) | Paste the link into a browser. The envelope with the seal. Press the seal, it breaks. The letter writes itself: ink warming at the line that mattered, the margin heart beating with its number, the glow on the smiling words, "paused ... seconds" in the margin | Leave it on "Their pace" for the line that matters, then press **Faster** | "They watch it written again, at your pace. The ink warms where your heart sped up, and the page moves with your breathing." | +| 6 | 1:08 to 1:16 | 8 s | SCREEN | Press **Show all**. The heartline under the signature and the closing card: "Quickest at", "Steadiest at" | Slow scroll to the card, hold | "At the end, where your heart was quickest, and where it was steadiest." | +| 7 | 1:16 to 1:20 | 4 s | SCREEN | Back to the envelope view with the line "This letter lives only in its link." | Still | "No server, no account, no video kept. Heartwritten." | + +Total: 80 seconds. If you need to cut to 60, drop shot 1 to 3 seconds, shot 3 +to 14 seconds (at 2x) and shot 5 to 16 seconds. + +## What the judges need to see + +The challenge page says judges check SmartSpectra use from the repo and the +demo video, and the template asks for a video "showing the live Presage +signal(s)". So these must be visible: + +1. The consent tick before the camera turns on (shot 2). +2. The live trace and bpm number changing while you are on camera (shots 2 + and 3). Keep the camera tile in frame so it is plain the signal is live. +3. The signal changing the result: ink colour, seal, breathing page, smile + glow (shots 3 to 6). + +## Words to avoid in voice-over and captions + +Say "heart rate", "pulse", "breathing", "camera estimates". Do not say that +it measures stress, anxiety, health, mood or emotion, and do not call any +number good, bad, normal or high. The challenge rules do not allow diagnosis +or treatment claims. + +## Getting it onto DEV + +Checked on 12 November 2026 against DEV's editor guide and the challenge page: + +- DEV's editor guide describes no direct video upload for posts, and states no + video size or length limit. Video goes in as an embed. +- `{% embed URL %}` supports YouTube, Vimeo, Loom, Mux and Twitch for video. + Example: `{% embed https://www.youtube.com/watch?v=VIDEO_ID %}` +- The challenge page gives no maximum video length and no required host. It + only says to embed or link a demo video. +- Images: the only stated limit is for GIFs, 200 megapixels per frame. The + cover image is best at 1000 by 420. +- At most four tags per post. + +Suggested export: MP4 (H.264), 1920 by 1080, 30 fps, uploaded to YouTube as +Public or Unlisted (not Private, or the embed will not play for judges). +Then replace the placeholder in [dev-post.md](dev-post.md) with the link. diff --git a/scripts/find-key.mjs b/scripts/find-key.mjs new file mode 100644 index 0000000..2e6ebe3 --- /dev/null +++ b/scripts/find-key.mjs @@ -0,0 +1,19 @@ +// find-key.mjs: where the SmartSpectra key comes from, for the scripts. +// Same order as the app (app/main.cjs): the environment first, then the +// git-ignored .smartspectra-key file in the project folder. The key is +// returned to the caller and never printed. +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const ROOT = fileURLToPath(new URL('../', import.meta.url)); + +export function findKey({ env = process.env, root = ROOT } = {}) { + const fromEnv = (env.SMARTSPECTRA_API_KEY || '').trim(); + if (fromEnv) return { key: fromEnv, source: 'SMARTSPECTRA_API_KEY' }; + try { + const fromFile = readFileSync(join(root, '.smartspectra-key'), 'utf8').trim(); + if (fromFile) return { key: fromFile, source: '.smartspectra-key' }; + } catch { /* no key file */ } + return { key: '', source: '' }; +} diff --git a/scripts/sdk-smoke.mjs b/scripts/sdk-smoke.mjs index 7e05114..549a7ef 100644 --- a/scripts/sdk-smoke.mjs +++ b/scripts/sdk-smoke.mjs @@ -1,13 +1,16 @@ // sdk-smoke.mjs // Headless check that the SmartSpectra SDK loads and that Heartwritten reads -// its packets. With a key and a short face video it runs a real measurement: +// its packets. With a key (in .smartspectra-key or SMARTSPECTRA_API_KEY) and +// a short face video it runs a real measurement: // -// SMARTSPECTRA_API_KEY=... npm run smoke -- path/to/face-clip.mp4 +// npm run smoke -- path/to/face-clip.mp4 // -// Without a key it only checks that the native runtime loads. +// Without a clip it only checks that the native runtime loads and says +// whether a key was found. The key itself is never printed. import { createRequire } from 'node:module'; import { VitalsTracker } from '../src/shared/vitals.js'; +import { findKey } from './find-key.mjs'; const require = createRequire(import.meta.url); const ss = require('@smartspectra/node-sdk'); @@ -21,10 +24,12 @@ try { console.log(`Camera discovery unavailable here (${e.message})`); } -const key = process.env.SMARTSPECTRA_API_KEY; +const { key, source } = findKey(); const clip = process.argv[2]; +console.log(key ? `Key found in ${source} (not shown).` : 'No key found. Put one in .smartspectra-key or set SMARTSPECTRA_API_KEY.'); if (!key || !clip) { - console.log('No key or clip given: load check passed. Pass both to run a real measurement.'); + console.log('Load check passed. The key is checked by Presage when a measurement starts:'); + console.log('run `npm run smoke -- path/to/face-clip.mp4` with a key, or just `npm start`.'); process.exit(0); } diff --git a/test/setup.test.js b/test/setup.test.js new file mode 100644 index 0000000..bd49fe7 --- /dev/null +++ b/test/setup.test.js @@ -0,0 +1,42 @@ +// Checks of the promises the README and PRIVACY.md make about the key and +// about SDK telemetry. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { mkdtemp, writeFile, readFile, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { findKey } from '../scripts/find-key.mjs'; + +const read = (p) => readFile(new URL(`../${p}`, import.meta.url), 'utf8'); + +test('the key is found in the environment first, then in .smartspectra-key', async () => { + const dir = await mkdtemp(join(tmpdir(), 'hw-key-')); + try { + assert.deepEqual(findKey({ env: {}, root: dir }), { key: '', source: '' }); + await writeFile(join(dir, '.smartspectra-key'), ' file-key\n'); + assert.deepEqual(findKey({ env: {}, root: dir }), { key: 'file-key', source: '.smartspectra-key' }); + assert.deepEqual(findKey({ env: { SMARTSPECTRA_API_KEY: ' env-key ' }, root: dir }), + { key: 'env-key', source: 'SMARTSPECTRA_API_KEY' }); + await writeFile(join(dir, '.smartspectra-key'), '\n'); + assert.equal(findKey({ env: {}, root: dir }).key, '', 'an empty key file counts as no key'); + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); + +test('the key file is git-ignored', async () => { + const lines = (await read('.gitignore')).split('\n').map((l) => l.trim()); + assert.ok(lines.includes('.smartspectra-key')); +}); + +test('SDK telemetry is off unless the writer ticks the box', async () => { + const html = await read('src/writer/index.html'); + const box = html.match(/]*id="opt-telemetry"[^>]*>/); + assert.ok(box, 'the telemetry choice is on the consent screen'); + assert.doesNotMatch(box[0], /\bchecked\b/, 'and it starts unticked'); + assert.match(await read('src/writer/sdk-source.js'), /telemetry = false/); + assert.match(await read('src/writer/sdk-source.js'), /enableTelemetry: this\.telemetry/); + const smoke = await read('scripts/sdk-smoke.mjs'); + assert.match(smoke, /enableTelemetry: false/); + assert.doesNotMatch(smoke, /enableTelemetry: true/); +});