create-rudder-app 0.4.0 → 0.5.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 (95) hide show
  1. package/dist/index.js +3 -5
  2. package/dist/index.js.map +1 -1
  3. package/dist/templates/app/service-provider.d.ts +1 -1
  4. package/dist/templates/app/service-provider.d.ts.map +1 -1
  5. package/dist/templates/app/service-provider.js +23 -2
  6. package/dist/templates/app/service-provider.js.map +1 -1
  7. package/dist/templates/configs/index.d.ts.map +1 -1
  8. package/dist/templates/configs/index.js +0 -4
  9. package/dist/templates/configs/index.js.map +1 -1
  10. package/dist/templates/demos/avatar.d.ts +3 -0
  11. package/dist/templates/demos/avatar.d.ts.map +1 -0
  12. package/dist/templates/demos/avatar.js +182 -0
  13. package/dist/templates/demos/avatar.js.map +1 -0
  14. package/dist/templates/demos/cache.d.ts +3 -0
  15. package/dist/templates/demos/cache.d.ts.map +1 -0
  16. package/dist/templates/demos/cache.js +99 -0
  17. package/dist/templates/demos/cache.js.map +1 -0
  18. package/dist/templates/demos/fibonacci.d.ts +7 -0
  19. package/dist/templates/demos/fibonacci.d.ts.map +1 -0
  20. package/dist/templates/demos/fibonacci.js +172 -0
  21. package/dist/templates/demos/fibonacci.js.map +1 -0
  22. package/dist/templates/demos/http.d.ts +3 -0
  23. package/dist/templates/demos/http.d.ts.map +1 -0
  24. package/dist/templates/demos/http.js +117 -0
  25. package/dist/templates/demos/http.js.map +1 -0
  26. package/dist/templates/demos/index-view.d.ts.map +1 -1
  27. package/dist/templates/demos/index-view.js +79 -2
  28. package/dist/templates/demos/index-view.js.map +1 -1
  29. package/dist/templates/demos/localization.d.ts +4 -0
  30. package/dist/templates/demos/localization.d.ts.map +1 -0
  31. package/dist/templates/demos/localization.js +130 -0
  32. package/dist/templates/demos/localization.js.map +1 -0
  33. package/dist/templates/demos/mail.d.ts +4 -0
  34. package/dist/templates/demos/mail.d.ts.map +1 -0
  35. package/dist/templates/demos/mail.js +127 -0
  36. package/dist/templates/demos/mail.js.map +1 -0
  37. package/dist/templates/demos/notifications.d.ts +4 -0
  38. package/dist/templates/demos/notifications.d.ts.map +1 -0
  39. package/dist/templates/demos/notifications.js +133 -0
  40. package/dist/templates/demos/notifications.js.map +1 -0
  41. package/dist/templates/demos/pennant.d.ts +8 -0
  42. package/dist/templates/demos/pennant.d.ts.map +1 -0
  43. package/dist/templates/demos/pennant.js +138 -0
  44. package/dist/templates/demos/pennant.js.map +1 -0
  45. package/dist/templates/demos/queue.d.ts +4 -0
  46. package/dist/templates/demos/queue.d.ts.map +1 -0
  47. package/dist/templates/demos/queue.js +107 -0
  48. package/dist/templates/demos/queue.js.map +1 -0
  49. package/dist/templates/demos/registry.d.ts.map +1 -1
  50. package/dist/templates/demos/registry.js +12 -1
  51. package/dist/templates/demos/registry.js.map +1 -1
  52. package/dist/templates/demos/rudder-socket.d.ts +2 -0
  53. package/dist/templates/demos/rudder-socket.d.ts.map +1 -0
  54. package/dist/templates/demos/{bk-socket.js → rudder-socket.js} +8 -8
  55. package/dist/templates/demos/rudder-socket.js.map +1 -0
  56. package/dist/templates/demos/sync.d.ts +2 -0
  57. package/dist/templates/demos/sync.d.ts.map +1 -0
  58. package/dist/templates/demos/{live.js → sync.js} +4 -4
  59. package/dist/templates/demos/sync.js.map +1 -0
  60. package/dist/templates/demos/system-info.d.ts +3 -0
  61. package/dist/templates/demos/system-info.d.ts.map +1 -0
  62. package/dist/templates/demos/system-info.js +142 -0
  63. package/dist/templates/demos/system-info.js.map +1 -0
  64. package/dist/templates/demos/todos.d.ts +6 -0
  65. package/dist/templates/demos/todos.d.ts.map +1 -0
  66. package/dist/templates/demos/todos.js +246 -0
  67. package/dist/templates/demos/todos.js.map +1 -0
  68. package/dist/templates/demos/ws.js +4 -4
  69. package/dist/templates/env.d.ts.map +1 -1
  70. package/dist/templates/env.js +0 -14
  71. package/dist/templates/env.js.map +1 -1
  72. package/dist/templates/package-json.d.ts.map +1 -1
  73. package/dist/templates/package-json.js +1 -3
  74. package/dist/templates/package-json.js.map +1 -1
  75. package/dist/templates/routes/api.d.ts.map +1 -1
  76. package/dist/templates/routes/api.js +48 -0
  77. package/dist/templates/routes/api.js.map +1 -1
  78. package/dist/templates/routes/web.d.ts.map +1 -1
  79. package/dist/templates/routes/web.js +49 -2
  80. package/dist/templates/routes/web.js.map +1 -1
  81. package/dist/templates.d.ts +2 -3
  82. package/dist/templates.d.ts.map +1 -1
  83. package/dist/templates.js +70 -10
  84. package/dist/templates.js.map +1 -1
  85. package/package.json +1 -1
  86. package/dist/templates/configs/cashier.d.ts +0 -2
  87. package/dist/templates/configs/cashier.d.ts.map +0 -1
  88. package/dist/templates/configs/cashier.js +0 -22
  89. package/dist/templates/configs/cashier.js.map +0 -1
  90. package/dist/templates/demos/bk-socket.d.ts +0 -2
  91. package/dist/templates/demos/bk-socket.d.ts.map +0 -1
  92. package/dist/templates/demos/bk-socket.js.map +0 -1
  93. package/dist/templates/demos/live.d.ts +0 -2
  94. package/dist/templates/demos/live.d.ts.map +0 -1
  95. package/dist/templates/demos/live.js.map +0 -1
@@ -0,0 +1,172 @@
1
+ // Fibonacci demo — sequential vs worker-pool parallel via @rudderjs/concurrency.
2
+ export function demosFibonacciView() {
3
+ return `import { useState } from 'react'
4
+ import '@/index.css'
5
+
6
+ interface FibResponse {
7
+ n: number
8
+ count: number
9
+ result: number
10
+ sequentialMs: number
11
+ parallelMs: number
12
+ workers: number
13
+ }
14
+
15
+ export default function FibonacciDemo() {
16
+ const [n, setN ] = useState(36)
17
+ const [count, setCount ] = useState(4)
18
+ const [data, setData ] = useState<FibResponse | null>(null)
19
+ const [loading, setLoading] = useState(false)
20
+ const [error, setError ] = useState<string | null>(null)
21
+
22
+ async function run() {
23
+ setLoading(true); setError(null); setData(null)
24
+ try {
25
+ const res = await fetch(\`/api/fib?n=\${n}&count=\${count}\`)
26
+ const body = await res.json() as FibResponse | { message: string }
27
+ if (!res.ok) throw new Error((body as { message: string }).message ?? 'Failed')
28
+ setData(body as FibResponse)
29
+ } catch (e) {
30
+ setError((e as Error).message)
31
+ } finally {
32
+ setLoading(false)
33
+ }
34
+ }
35
+
36
+ return (
37
+ <div className="page">
38
+ <nav className="page-nav">
39
+ <div className="brand">
40
+ <span className="brand-dot" />
41
+ RudderJS
42
+ </div>
43
+ <div className="nav-right">
44
+ <a href="/demos" className="nav-link">Demos</a>
45
+ <a href="/" className="nav-link">Home</a>
46
+ </div>
47
+ </nav>
48
+
49
+ <section className="hero">
50
+ <h1 className="hero-title">Worker Threads</h1>
51
+ <p className="hero-lead">
52
+ Compute <code className="inline-code">fib(n)</code> N times — sequentially on the main thread, then
53
+ in parallel via <code className="inline-code">@rudderjs/concurrency</code>'s worker pool. Watch the
54
+ parallel cost stay flat as N grows (until you saturate workers).
55
+ </p>
56
+ </section>
57
+
58
+ <section className="feature-section">
59
+ <div className="form-card">
60
+ <div style={{ display: 'flex', gap: '1rem', marginBottom: '1rem' }}>
61
+ <div style={{ flex: 1 }}>
62
+ <p className="form-label">n (Fibonacci index)</p>
63
+ <input
64
+ className="form-input"
65
+ type="number"
66
+ min={20}
67
+ max={42}
68
+ value={n}
69
+ onChange={e => setN(Number(e.target.value))}
70
+ />
71
+ </div>
72
+ <div style={{ flex: 1 }}>
73
+ <p className="form-label">count (parallel calls)</p>
74
+ <input
75
+ className="form-input"
76
+ type="number"
77
+ min={1}
78
+ max={16}
79
+ value={count}
80
+ onChange={e => setCount(Number(e.target.value))}
81
+ />
82
+ </div>
83
+ </div>
84
+
85
+ <button
86
+ className="form-submit"
87
+ onClick={run}
88
+ disabled={loading}
89
+ style={{ marginBottom: '1rem' }}
90
+ >
91
+ {loading ? 'Computing…' : \`Run \${count} × fib(\${n})\`}
92
+ </button>
93
+
94
+ {error && (
95
+ <p className="form-error">{error}</p>
96
+ )}
97
+
98
+ {data && (
99
+ <>
100
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1rem', marginBottom: '0.75rem' }}>
101
+ <div style={{ padding: '0.75rem', borderRadius: '0.375rem', border: '1px solid var(--border, #e5e7eb)' }}>
102
+ <p className="form-label" style={{ marginBottom: '0.25rem' }}>Sequential (main thread)</p>
103
+ <p style={{ fontSize: '1.25rem', fontWeight: 600, margin: 0 }}>{data.sequentialMs}ms</p>
104
+ <p className="feature-desc" style={{ fontSize: '0.7rem', marginTop: '0.25rem' }}>
105
+ {data.count} × fib({data.n}) one after another, blocking the event loop
106
+ </p>
107
+ </div>
108
+ <div style={{ padding: '0.75rem', borderRadius: '0.375rem', border: '1px solid var(--border, #e5e7eb)' }}>
109
+ <p className="form-label" style={{ marginBottom: '0.25rem' }}>Parallel ({data.workers} workers)</p>
110
+ <p style={{ fontSize: '1.25rem', fontWeight: 600, margin: 0 }}>{data.parallelMs}ms</p>
111
+ <p className="feature-desc" style={{ fontSize: '0.7rem', marginTop: '0.25rem' }}>
112
+ same {data.count} tasks via <code>Concurrency.run([...])</code>
113
+ </p>
114
+ </div>
115
+ </div>
116
+
117
+ <p className="feature-desc" style={{ fontSize: '0.85rem' }}>
118
+ Result: <code>fib({data.n}) = {data.result.toLocaleString()}</code>
119
+ {' · '}
120
+ <strong>{Math.round((data.sequentialMs / Math.max(data.parallelMs, 1)) * 10) / 10}× faster</strong>
121
+ {' '}via worker pool
122
+ </p>
123
+ </>
124
+ )}
125
+ </div>
126
+ </section>
127
+ </div>
128
+ )
129
+ }
130
+ `;
131
+ }
132
+ /**
133
+ * Returns the inline lines that live in routes/api.ts to handle GET /api/fib.
134
+ * Inlined (not a separate Service) to keep the demo single-file readable.
135
+ */
136
+ export function demosFibonacciApiBlock() {
137
+ return `// GET /api/fib?n=36&count=4 — sequential vs worker-pool parallel via @rudderjs/concurrency.
138
+ router.get('/api/fib', async (req, res) => {
139
+ const n = Math.max(1, Math.min(42, Number((req.query as Record<string, string>)['n'] ?? 36)))
140
+ const count = Math.max(1, Math.min(16, Number((req.query as Record<string, string>)['count'] ?? 4)))
141
+
142
+ const { Concurrency } = await import('@rudderjs/concurrency')
143
+ const { cpus } = await import('node:os')
144
+
145
+ // The task body must be self-contained — closures don't capture variables across the
146
+ // worker boundary. Inline 'fib' and bind 'n' via a Function-style template.
147
+ const buildTask = (val: number): (() => number) => {
148
+ const src = \`
149
+ function fib(k) { return k < 2 ? k : fib(k - 1) + fib(k - 2) }
150
+ return fib(\${val})
151
+ \`
152
+ return new Function(src) as () => number
153
+ }
154
+
155
+ const seqStart = Date.now()
156
+ let result = 0
157
+ for (let i = 0; i < count; i++) result = buildTask(n)()
158
+ const sequentialMs = Date.now() - seqStart
159
+
160
+ const parStart = Date.now()
161
+ const tasks = Array.from({ length: count }, () => buildTask(n))
162
+ const results = await Concurrency.run(tasks)
163
+ const parallelMs = Date.now() - parStart
164
+ result = results[0] ?? result
165
+
166
+ res.json({
167
+ n, count, result, sequentialMs, parallelMs,
168
+ workers: Math.min(count, cpus().length),
169
+ })
170
+ })`;
171
+ }
172
+ //# sourceMappingURL=fibonacci.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fibonacci.js","sourceRoot":"","sources":["../../../src/templates/demos/fibonacci.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,MAAM,UAAU,kBAAkB;IAChC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+HR,CAAA;AACD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCN,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function demosHttpView(): string;
2
+ export declare function demosHttpApiBlock(): string;
3
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/http.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,IAAI,MAAM,CAyFtC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAwB1C"}
@@ -0,0 +1,117 @@
1
+ // HTTP client demo — fluent fetch with retry + timeout against a public API.
2
+ export function demosHttpView() {
3
+ return `import { useState } from 'react'
4
+ import '@/index.css'
5
+
6
+ interface HttpResponseShape {
7
+ status: number
8
+ ok: boolean
9
+ durationMs: number
10
+ url: string
11
+ body: unknown
12
+ }
13
+
14
+ const ENDPOINTS = [
15
+ { url: 'https://jsonplaceholder.typicode.com/todos/1', label: 'Todo (works)' },
16
+ { url: 'https://jsonplaceholder.typicode.com/users/1', label: 'User (works)' },
17
+ { url: 'https://httpstat.us/500?sleep=300', label: 'Force 500 (retries 3×)' },
18
+ ]
19
+
20
+ export default function HttpDemo() {
21
+ const [url, setUrl] = useState(ENDPOINTS[0]!.url)
22
+ const [data, setData] = useState<HttpResponseShape | null>(null)
23
+ const [loading, setLoading] = useState(false)
24
+ const [error, setError] = useState<string | null>(null)
25
+
26
+ async function fetchUrl() {
27
+ setLoading(true); setError(null)
28
+ try {
29
+ const res = await fetch('/api/http/fetch?url=' + encodeURIComponent(url))
30
+ const body = await res.json() as HttpResponseShape | { message: string }
31
+ if (!res.ok) throw new Error((body as { message: string }).message ?? 'Failed')
32
+ setData(body as HttpResponseShape)
33
+ } catch (e) {
34
+ setError((e as Error).message)
35
+ } finally {
36
+ setLoading(false)
37
+ }
38
+ }
39
+
40
+ return (
41
+ <div className="page">
42
+ <nav className="page-nav">
43
+ <div className="brand">
44
+ <span className="brand-dot" />
45
+ RudderJS
46
+ </div>
47
+ <div className="nav-right">
48
+ <a href="/demos" className="nav-link">Demos</a>
49
+ <a href="/" className="nav-link">Home</a>
50
+ </div>
51
+ </nav>
52
+
53
+ <section className="hero">
54
+ <h1 className="hero-title">HTTP client</h1>
55
+ <p className="hero-lead">
56
+ Server-side <code className="inline-code">Http.retry(3, 200).timeout(5000).get(url)</code>{' '}
57
+ against a public API. Pick a URL — the 500 endpoint exercises the retry path.
58
+ </p>
59
+ </section>
60
+
61
+ <section className="feature-section" style={{ maxWidth: '40rem', margin: '0 auto' }}>
62
+ <div className="form-card">
63
+ <label className="form-label" htmlFor="http-url">URL</label>
64
+ <select id="http-url" className="form-input" value={url} onChange={e => setUrl(e.target.value)} style={{ marginBottom: '0.75rem' }}>
65
+ {ENDPOINTS.map(e => (
66
+ <option key={e.url} value={e.url}>{e.label}</option>
67
+ ))}
68
+ </select>
69
+ <button className="form-submit" onClick={fetchUrl} disabled={loading}>
70
+ {loading ? 'Fetching…' : 'Fetch'}
71
+ </button>
72
+ {error && (
73
+ <p className="form-error" style={{ marginTop: '1rem' }}>{error}</p>
74
+ )}
75
+ {data && (
76
+ <div style={{ marginTop: '1rem' }}>
77
+ <p className="feature-desc">
78
+ <strong>{data.status}</strong> · {data.durationMs}ms · ok={String(data.ok)}
79
+ </p>
80
+ <pre style={{ marginTop: '0.5rem', padding: '0.75rem', borderRadius: '0.375rem', background: 'var(--muted, #f4f4f5)', fontSize: '0.7rem', whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}>
81
+ {JSON.stringify(data.body, null, 2).slice(0, 600)}
82
+ </pre>
83
+ </div>
84
+ )}
85
+ </div>
86
+ </section>
87
+ </div>
88
+ )
89
+ }
90
+ `;
91
+ }
92
+ export function demosHttpApiBlock() {
93
+ return `// GET /api/http/fetch?url=… — server-side HTTP with retry + timeout.
94
+ router.get('/api/http/fetch', async (req, res) => {
95
+ const url = (req.query as Record<string, string>)['url']
96
+ if (!url) return res.status(422).json({ message: 'url is required' })
97
+ if (!/^https?:\\/\\//.test(url)) return res.status(422).json({ message: 'url must be http(s)' })
98
+
99
+ const { Http } = await import('@rudderjs/http')
100
+ const t0 = Date.now()
101
+ try {
102
+ const response = await Http.retry(3, 200).timeout(5000).get(url)
103
+ let body: unknown = null
104
+ try { body = response.json() } catch { body = response.body.slice(0, 600) }
105
+ res.json({
106
+ status: response.status,
107
+ ok: response.ok(),
108
+ durationMs: Date.now() - t0,
109
+ url,
110
+ body,
111
+ })
112
+ } catch (e) {
113
+ res.status(502).json({ message: (e as Error).message ?? 'Request failed', durationMs: Date.now() - t0, url })
114
+ }
115
+ })`;
116
+ }
117
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/templates/demos/http.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,MAAM,UAAU,aAAa;IAC3B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO;;;;;;;;;;;;;;;;;;;;;;GAsBN,CAAA;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index-view.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/index-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAE7E,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAkE3D"}
1
+ {"version":3,"file":"index-view.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/index-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAE7E,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CA+I3D"}
@@ -8,6 +8,83 @@ export function demosIndexView(ctx) {
8
8
  pkgs: '@rudderjs/middleware · @rudderjs/core',
9
9
  show: shouldScaffoldDemo(ctx, 'contact'),
10
10
  },
11
+ {
12
+ title: 'Todos',
13
+ desc: 'ORM + interactive UI. Controller loads initial data, the view hydrates and POSTs to /api/todos/* for live updates.',
14
+ href: '/demos/todos',
15
+ pkgs: '@rudderjs/orm · @rudderjs/router',
16
+ show: shouldScaffoldDemo(ctx, 'todos'),
17
+ },
18
+ {
19
+ title: 'Avatar resize',
20
+ desc: 'Upload an image — server resizes it to 256×256 WebP via @rudderjs/image and saves to public storage. Side-by-side compare.',
21
+ href: '/demos/avatar',
22
+ pkgs: '@rudderjs/image · @rudderjs/storage',
23
+ show: shouldScaffoldDemo(ctx, 'avatar'),
24
+ },
25
+ {
26
+ title: 'System info',
27
+ desc: 'Three shell commands (git, node, uptime) executed via @rudderjs/process. Compares sequential vs parallel cost using Process.pool().',
28
+ href: '/demos/system-info',
29
+ pkgs: '@rudderjs/process',
30
+ show: shouldScaffoldDemo(ctx, 'system-info'),
31
+ },
32
+ {
33
+ title: 'Worker threads',
34
+ desc: 'Compute fib(n) sequentially on the main thread vs across @rudderjs/concurrency worker pool. Watch the parallel cost stay flat as you crank N.',
35
+ href: '/demos/fibonacci',
36
+ pkgs: '@rudderjs/concurrency',
37
+ show: shouldScaffoldDemo(ctx, 'fibonacci'),
38
+ },
39
+ {
40
+ title: 'Feature flags',
41
+ desc: 'Boolean, value, scoped, and Lottery features resolved against the current user. Sub-route guarded by FeatureMiddleware to demonstrate 403 blocking.',
42
+ href: '/demos/pennant',
43
+ pkgs: '@rudderjs/pennant',
44
+ show: shouldScaffoldDemo(ctx, 'pennant'),
45
+ },
46
+ {
47
+ title: 'Cache counter',
48
+ desc: 'Persistent view counter via Cache.get + Cache.set. Demonstrates the Cache facade with the in-memory driver.',
49
+ href: '/demos/cache',
50
+ pkgs: '@rudderjs/cache',
51
+ show: shouldScaffoldDemo(ctx, 'cache'),
52
+ },
53
+ {
54
+ title: 'Queue dispatch',
55
+ desc: 'Click to enqueue ExampleJob via @rudderjs/queue. The handler logs to the server terminal.',
56
+ href: '/demos/queue',
57
+ pkgs: '@rudderjs/queue',
58
+ show: shouldScaffoldDemo(ctx, 'queue'),
59
+ },
60
+ {
61
+ title: 'Mail send',
62
+ desc: 'Send a Mailable via Mail.to(...).send(). Default driver is "log" — output appears in the dev terminal.',
63
+ href: '/demos/mail',
64
+ pkgs: '@rudderjs/mail',
65
+ show: shouldScaffoldDemo(ctx, 'mail'),
66
+ },
67
+ {
68
+ title: 'Notifications',
69
+ desc: 'Multi-channel notification via notify(notifiable, notification). Mail channel uses the log driver.',
70
+ href: '/demos/notifications',
71
+ pkgs: '@rudderjs/notification · @rudderjs/mail',
72
+ show: shouldScaffoldDemo(ctx, 'notifications'),
73
+ },
74
+ {
75
+ title: 'Localization',
76
+ desc: 'Pick a locale to fetch the same keys via trans() server-side. Strings live in lang/<locale>/messages.json.',
77
+ href: '/demos/localization',
78
+ pkgs: '@rudderjs/localization',
79
+ show: shouldScaffoldDemo(ctx, 'localization'),
80
+ },
81
+ {
82
+ title: 'HTTP client',
83
+ desc: 'Server-side Http.retry(3, 200).timeout(5000).get(url) against a public API. The 500 endpoint exercises retry.',
84
+ href: '/demos/http',
85
+ pkgs: '@rudderjs/http',
86
+ show: shouldScaffoldDemo(ctx, 'http'),
87
+ },
11
88
  {
12
89
  title: 'WebSocket chat',
13
90
  desc: 'Real-time chat + presence using @rudderjs/broadcast — multi-channel pub/sub over a single WebSocket connection.',
@@ -18,9 +95,9 @@ export function demosIndexView(ctx) {
18
95
  {
19
96
  title: 'Collaborative editor',
20
97
  desc: 'Yjs CRDT live document with awareness cursors. Open in two tabs to see real-time sync over @rudderjs/sync.',
21
- href: '/demos/live',
98
+ href: '/demos/sync',
22
99
  pkgs: '@rudderjs/sync',
23
- show: shouldScaffoldDemo(ctx, 'live'),
100
+ show: shouldScaffoldDemo(ctx, 'sync'),
24
101
  },
25
102
  ].filter(c => c.show);
26
103
  const cardsJsx = cards.map(c => ` <a key="${c.href}" href="${c.href}" className="feature-card">
@@ -1 +1 @@
1
- {"version":3,"file":"index-view.js","sourceRoot":"","sources":["../../../src/templates/demos/index-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAwB,MAAM,oBAAoB,CAAA;AAE7E,MAAM,UAAU,cAAc,CAAC,GAAoB;IACjD,MAAM,KA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,CAAC,IAAI,WAAW,CAAC,CAAC,IAAI;0CAClC,CAAC,CAAC,KAAK;wCACT,CAAC,CAAC,IAAI;qFACuC,CAAC,CAAC,IAAI;aAC9E,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEvB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BP,QAAQ;;;;;;CAMT,CAAA;AACD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function demosLocalizationView(): string;
2
+ export declare function demosLocalizationApiBlock(): string;
3
+ export declare function langMessages(locale: 'en' | 'es' | 'ar'): string;
4
+ //# sourceMappingURL=localization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/localization.ts"],"names":[],"mappings":"AAIA,wBAAgB,qBAAqB,IAAI,MAAM,CAkF9C;AAED,wBAAgB,yBAAyB,IAAI,MAAM,CAkBlD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAuB/D"}
@@ -0,0 +1,130 @@
1
+ // Localization demo — language switcher hits /api/i18n?locale=…
2
+ // The route uses runWithLocale + setLocale + trans() to render strings.
3
+ // Lang files at lang/<locale>/messages.json.
4
+ export function demosLocalizationView() {
5
+ return `import { useEffect, useState } from 'react'
6
+ import '@/index.css'
7
+
8
+ interface I18nResponse {
9
+ locale: string
10
+ greeting: string
11
+ items: string
12
+ welcome: string
13
+ }
14
+
15
+ const LOCALES = [
16
+ { code: 'en', label: 'English' },
17
+ { code: 'es', label: 'Español' },
18
+ { code: 'ar', label: 'العربية' },
19
+ ]
20
+
21
+ export default function LocalizationDemo() {
22
+ const [locale, setLocale] = useState('en')
23
+ const [data, setData] = useState<I18nResponse | null>(null)
24
+
25
+ async function load(loc: string) {
26
+ const res = await fetch(\`/api/i18n?locale=\${loc}\`)
27
+ setData(await res.json() as I18nResponse)
28
+ }
29
+
30
+ useEffect(() => { load(locale) }, [locale])
31
+
32
+ return (
33
+ <div className="page">
34
+ <nav className="page-nav">
35
+ <div className="brand">
36
+ <span className="brand-dot" />
37
+ RudderJS
38
+ </div>
39
+ <div className="nav-right">
40
+ <a href="/demos" className="nav-link">Demos</a>
41
+ <a href="/" className="nav-link">Home</a>
42
+ </div>
43
+ </nav>
44
+
45
+ <section className="hero">
46
+ <h1 className="hero-title">Localization</h1>
47
+ <p className="hero-lead">
48
+ Pick a locale to fetch the same keys via{' '}
49
+ <code className="inline-code">trans()</code> on the server. Strings live in{' '}
50
+ <code className="inline-code">lang/&lt;locale&gt;/messages.json</code>.
51
+ </p>
52
+ </section>
53
+
54
+ <section className="feature-section" style={{ maxWidth: '32rem', margin: '0 auto' }}>
55
+ <div className="form-card">
56
+ <div style={{ marginBottom: '1rem' }}>
57
+ <label className="form-label" htmlFor="locale">Locale</label>
58
+ <select
59
+ id="locale"
60
+ className="form-input"
61
+ value={locale}
62
+ onChange={e => setLocale(e.target.value)}
63
+ >
64
+ {LOCALES.map(l => (
65
+ <option key={l.code} value={l.code}>{l.label} ({l.code})</option>
66
+ ))}
67
+ </select>
68
+ </div>
69
+
70
+ {data && (
71
+ <div style={{ display: 'grid', gap: '0.5rem' }}>
72
+ <p className="feature-desc"><strong>welcome:</strong> {data.welcome}</p>
73
+ <p className="feature-desc"><strong>greeting:</strong> {data.greeting}</p>
74
+ <p className="feature-desc"><strong>items (3):</strong> {data.items}</p>
75
+ <p className="feature-desc" style={{ fontSize: '0.7rem', opacity: 0.7 }}>
76
+ resolved server-side with locale = <code>{data.locale}</code>
77
+ </p>
78
+ </div>
79
+ )}
80
+ </div>
81
+ </section>
82
+ </div>
83
+ )
84
+ }
85
+ `;
86
+ }
87
+ export function demosLocalizationApiBlock() {
88
+ return `// GET /api/i18n?locale=… — resolves the same keys in the requested locale.
89
+ router.get('/api/i18n', async (req, res) => {
90
+ const { runWithLocale, setLocale, getLocale, trans } = await import('@rudderjs/localization')
91
+ const requested = (req.query as Record<string, string>)['locale'] ?? 'en'
92
+
93
+ const payload = await runWithLocale(requested, async () => {
94
+ setLocale(requested)
95
+ return {
96
+ locale: getLocale(),
97
+ welcome: await trans('messages.welcome'),
98
+ greeting: await trans('messages.greeting', { name: 'World' }),
99
+ items: await trans('messages.items', 3),
100
+ }
101
+ })
102
+
103
+ res.json(payload)
104
+ })`;
105
+ }
106
+ export function langMessages(locale) {
107
+ if (locale === 'es') {
108
+ return `{
109
+ "welcome": "¡Bienvenido a RudderJS!",
110
+ "greeting": "Hola, :name!",
111
+ "items": "{0} sin elementos|{1} un elemento|{n} :count elementos"
112
+ }
113
+ `;
114
+ }
115
+ if (locale === 'ar') {
116
+ return `{
117
+ "welcome": "مرحباً بك في RudderJS!",
118
+ "greeting": "مرحباً، :name!",
119
+ "items": "{0} لا توجد عناصر|{1} عنصر واحد|{n} :count عناصر"
120
+ }
121
+ `;
122
+ }
123
+ return `{
124
+ "welcome": "Welcome to RudderJS!",
125
+ "greeting": "Hello, :name!",
126
+ "items": "{0} no items|{1} one item|{n} :count items"
127
+ }
128
+ `;
129
+ }
130
+ //# sourceMappingURL=localization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localization.js","sourceRoot":"","sources":["../../../src/templates/demos/localization.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,wEAAwE;AACxE,6CAA6C;AAE7C,MAAM,UAAU,qBAAqB;IACnC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgFR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO;;;;;;;;;;;;;;;;GAgBN,CAAA;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAA0B;IACrD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO;;;;;CAKV,CAAA;IACC,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO;;;;;CAKV,CAAA;IACC,CAAC;IACD,OAAO;;;;;CAKR,CAAA;AACD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function demosMailView(): string;
2
+ export declare function demoMailable(): string;
3
+ export declare function demosMailApiBlock(): string;
4
+ //# sourceMappingURL=mail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/mail.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,IAAI,MAAM,CAqFtC;AAED,wBAAgB,YAAY,IAAI,MAAM,CAkBrC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAkB1C"}