@ramme-io/create-app 3.1.0 → 3.3.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.
Files changed (33) hide show
  1. package/index.js +98 -12
  2. package/package.json +4 -4
  3. package/template/.env.example +6 -0
  4. package/template/CHANGELOG.md +175 -0
  5. package/template/gitignore +6 -0
  6. package/template/index.html +4 -2
  7. package/template/package.json +3 -2
  8. package/template/public/rocket.svg +18 -0
  9. package/template/src/components/AddItemsModal.tsx +0 -1
  10. package/template/src/components/AppFooter.tsx +2 -1
  11. package/template/src/components/AppHeader.tsx +2 -1
  12. package/template/src/components/PageTitleUpdater.tsx +8 -4
  13. package/template/src/components/ProtectedAppShell.tsx +11 -6
  14. package/template/src/components/SettingsModal.tsx +1 -1
  15. package/template/src/config/app.config.ts +36 -0
  16. package/template/src/config/app.manifest.ts +5 -4
  17. package/template/src/features/about/pages/AboutPage.tsx +0 -2
  18. package/template/src/features/config/AppConfigContext.tsx +24 -9
  19. package/template/src/pages/SettingsPage.tsx +0 -2
  20. package/template/src/templates/dashboard/DashboardLayout.tsx +2 -1
  21. package/template/src/tests/smoke.test.tsx +0 -1
  22. package/template-device/AGENTS.md +20 -0
  23. package/template-device/CHANGELOG.md +26 -0
  24. package/template-device/README.md +41 -0
  25. package/template-device/apps/hello.json +10 -0
  26. package/template-device/apps/probe.json +26 -0
  27. package/template-device/gitignore +5 -0
  28. package/template-device/package.json +17 -0
  29. package/template-device/page.html +86 -0
  30. package/template-device/server.mjs +242 -0
  31. package/template-device/server.test.mjs +117 -0
  32. package/template/public/orange.png +0 -0
  33. package/template/src/assets/orange.png +0 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * This server answers a board the way ramme.io does.
3
+ *
4
+ * A board cannot tell which server it is talking to, and must not need to:
5
+ * the same firmware runs against both. So these hold the server to the
6
+ * protocol in @ramme-io/shared — the same schemas ramme.io's own routes are
7
+ * checked against — rather than to what this file happens to return. If you
8
+ * change server.mjs, keep these passing and a board will keep working.
9
+ */
10
+ import { describe, it, expect, beforeEach } from 'vitest';
11
+ import { mkdtempSync, readFileSync, readdirSync } from 'node:fs';
12
+ import { tmpdir } from 'node:os';
13
+ import { join } from 'node:path';
14
+ import { AppDocumentSchema, DEVICE_PROTOCOL, DevicePollReplySchema } from '@ramme-io/shared';
15
+ import { createHandler } from './server.mjs';
16
+
17
+ const ID = 'A7K2M9QP';
18
+ const CODE = '4821';
19
+ const HELLO = JSON.parse(readFileSync(new URL('./apps/hello.json', import.meta.url), 'utf8'));
20
+
21
+ let handle;
22
+ let file;
23
+ let clock;
24
+
25
+ beforeEach(() => {
26
+ file = join(mkdtempSync(join(tmpdir(), 'ramme-home-')), 'data.json');
27
+ clock = 1_800_000_000_000;
28
+ handle = createHandler({ file, now: () => clock });
29
+ });
30
+
31
+ const call = (method, url, body, headers = {}) => {
32
+ const out = handle({ method, url, body, headers });
33
+ return { ...out, json: out.body ? JSON.parse(out.body) : undefined };
34
+ };
35
+ const register = () =>
36
+ call('POST', DEVICE_PROTOCOL.register.path, { deviceId: ID, code: CODE, version: '2026-10-30+afe8999', board: 'freenove-esp32s3-2.8' });
37
+ const poll = since => call('GET', `${DEVICE_PROTOCOL.poll.path}?id=${ID}&since=${since}&v=2026-10-30%2Bafe8999&sh=1&rot=2`);
38
+ const send = (body, headers) => call('POST', '/api/device/send', { deviceId: ID, document: HELLO, ...body }, headers);
39
+
40
+ describe('a board', () => {
41
+ it('registers', () => {
42
+ expect(register().status).toBe(200);
43
+ expect(call('POST', DEVICE_PROTOCOL.register.path, { deviceId: 'nope' }).status).toBe(400);
44
+ });
45
+
46
+ it('hears 204 before anything is sent, then the app, then 304', () => {
47
+ register();
48
+ const none = poll(0);
49
+ expect(none.status).toBe(204);
50
+ expect(none.body).toBeUndefined();
51
+ expect(send({ code: CODE }).status).toBe(200);
52
+ const first = poll(0);
53
+ expect(first.status).toBe(200);
54
+ expect(DevicePollReplySchema.safeParse(first.json).success).toBe(true);
55
+ expect(first.json).toMatchObject({ revision: 1, document: { id: 'hello-home' } });
56
+ const current = poll(1);
57
+ expect(current.status).toBe(304);
58
+ expect(current.body).toBeUndefined();
59
+ });
60
+
61
+ it('reports readings, which come back as Signals', () => {
62
+ register();
63
+ const r = call('POST', `${DEVICE_PROTOCOL.report.path}?id=${ID}`, { readings: [{ key: 'temperature', value: 21.5, unit: '°C' }] });
64
+ expect(r).toMatchObject({ status: 202, json: { received: 1 } });
65
+ const parts = call('GET', `/api/device/vitals?id=${ID}`).json;
66
+ expect(parts.readings[0]).toMatchObject({ id: `${ID}:temperature`, source: 'http', value: 21.5, timestamp: clock });
67
+ });
68
+
69
+ it('gets only photos an app on it names', () => {
70
+ register();
71
+ const hash = 'a'.repeat(64);
72
+ expect(call('GET', `${DEVICE_PROTOCOL.photo.path}?id=${ID}&hash=${hash}`).status).toBe(404);
73
+ expect(call('GET', `${DEVICE_PROTOCOL.photo.path}?id=${ID}&hash=nope`).status).toBe(400);
74
+ });
75
+ });
76
+
77
+ describe('sending', () => {
78
+ it('needs the code on the screen, or the token', () => {
79
+ register();
80
+ expect(send({ code: '0000' }).status).toBe(403);
81
+ expect(send({}).status).toBe(403);
82
+ const { token } = JSON.parse(readFileSync(file, 'utf8'));
83
+ expect(send({}, { authorization: `Bearer ${token}` }).status).toBe(200);
84
+ });
85
+
86
+ it('refuses an app a board could not draw', () => {
87
+ register();
88
+ const r = send({ code: CODE, document: { ...HELLO, blocks: [] } });
89
+ expect(r).toMatchObject({ status: 400, json: { error: 'BAD_DOCUMENT' } });
90
+ });
91
+
92
+ it('survives a restart', () => {
93
+ register();
94
+ send({ code: CODE });
95
+ handle = createHandler({ file, now: () => clock });
96
+ expect(poll(0).json.revision).toBe(1);
97
+ });
98
+ });
99
+
100
+ describe('the devkit', () => {
101
+ it('lists boards without their codes', () => {
102
+ register();
103
+ const { devices } = call('GET', '/api/device/list').json;
104
+ expect(devices).toEqual([expect.objectContaining({ deviceId: ID, lastSeenAt: clock })]);
105
+ expect(JSON.stringify(devices)).not.toContain(CODE);
106
+ });
107
+ });
108
+
109
+ describe('the example apps', () => {
110
+ for (const name of readdirSync(new URL('./apps/', import.meta.url))) {
111
+ it(`${name} is an app a board can draw`, () => {
112
+ const doc = JSON.parse(readFileSync(new URL(`./apps/${name}`, import.meta.url), 'utf8'));
113
+ const parsed = AppDocumentSchema.safeParse(doc);
114
+ expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true);
115
+ });
116
+ }
117
+ });
Binary file
Binary file