create-rudder-app 0.4.0 → 0.6.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 (96) 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 +16 -29
  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 +13 -0
  50. package/dist/templates/demos/registry.d.ts.map +1 -1
  51. package/dist/templates/demos/registry.js +120 -3
  52. package/dist/templates/demos/registry.js.map +1 -1
  53. package/dist/templates/demos/rudder-socket.d.ts +2 -0
  54. package/dist/templates/demos/rudder-socket.d.ts.map +1 -0
  55. package/dist/templates/demos/{bk-socket.js → rudder-socket.js} +8 -8
  56. package/dist/templates/demos/rudder-socket.js.map +1 -0
  57. package/dist/templates/demos/sync.d.ts +2 -0
  58. package/dist/templates/demos/sync.d.ts.map +1 -0
  59. package/dist/templates/demos/{live.js → sync.js} +4 -4
  60. package/dist/templates/demos/sync.js.map +1 -0
  61. package/dist/templates/demos/system-info.d.ts +3 -0
  62. package/dist/templates/demos/system-info.d.ts.map +1 -0
  63. package/dist/templates/demos/system-info.js +142 -0
  64. package/dist/templates/demos/system-info.js.map +1 -0
  65. package/dist/templates/demos/todos.d.ts +6 -0
  66. package/dist/templates/demos/todos.d.ts.map +1 -0
  67. package/dist/templates/demos/todos.js +246 -0
  68. package/dist/templates/demos/todos.js.map +1 -0
  69. package/dist/templates/demos/ws.js +4 -4
  70. package/dist/templates/env.d.ts.map +1 -1
  71. package/dist/templates/env.js +0 -14
  72. package/dist/templates/env.js.map +1 -1
  73. package/dist/templates/package-json.d.ts.map +1 -1
  74. package/dist/templates/package-json.js +1 -3
  75. package/dist/templates/package-json.js.map +1 -1
  76. package/dist/templates/routes/api.d.ts.map +1 -1
  77. package/dist/templates/routes/api.js +48 -0
  78. package/dist/templates/routes/api.js.map +1 -1
  79. package/dist/templates/routes/web.d.ts.map +1 -1
  80. package/dist/templates/routes/web.js +49 -2
  81. package/dist/templates/routes/web.js.map +1 -1
  82. package/dist/templates.d.ts +2 -3
  83. package/dist/templates.d.ts.map +1 -1
  84. package/dist/templates.js +70 -10
  85. package/dist/templates.js.map +1 -1
  86. package/package.json +5 -1
  87. package/dist/templates/configs/cashier.d.ts +0 -2
  88. package/dist/templates/configs/cashier.d.ts.map +0 -1
  89. package/dist/templates/configs/cashier.js +0 -22
  90. package/dist/templates/configs/cashier.js.map +0 -1
  91. package/dist/templates/demos/bk-socket.d.ts +0 -2
  92. package/dist/templates/demos/bk-socket.d.ts.map +0 -1
  93. package/dist/templates/demos/bk-socket.js.map +0 -1
  94. package/dist/templates/demos/live.d.ts +0 -2
  95. package/dist/templates/demos/live.d.ts.map +0 -1
  96. package/dist/templates/demos/live.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mail.js","sourceRoot":"","sources":["../../../src/templates/demos/mail.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,mEAAmE;AAEnE,MAAM,UAAU,aAAa;IAC3B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmFR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO;;;;;;;;;;;;;;;;CAgBR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO;;;;;;;;;;;;;;;;GAgBN,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function demosNotificationsView(): string;
2
+ export declare function demoNotification(): string;
3
+ export declare function demosNotificationsApiBlock(): string;
4
+ //# sourceMappingURL=notifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/notifications.ts"],"names":[],"mappings":"AAGA,wBAAgB,sBAAsB,IAAI,MAAM,CAgF/C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAiCzC;AAED,wBAAgB,0BAA0B,IAAI,MAAM,CAcnD"}
@@ -0,0 +1,133 @@
1
+ // Notifications demo — multi-channel notification (mail only by default;
2
+ // add 'database' to via() once @rudderjs/notification's Prisma model is in place).
3
+ export function demosNotificationsView() {
4
+ return `import { useState } from 'react'
5
+ import '@/index.css'
6
+
7
+ interface NotifyResponse {
8
+ ok: boolean
9
+ to: string
10
+ channels: string[]
11
+ }
12
+
13
+ export default function NotificationsDemo() {
14
+ const [to, setTo] = useState('user@example.com')
15
+ const [data, setData] = useState<NotifyResponse | null>(null)
16
+ const [loading, setLoading] = useState(false)
17
+ const [error, setError] = useState<string | null>(null)
18
+
19
+ async function notify() {
20
+ setLoading(true); setError(null)
21
+ try {
22
+ const res = await fetch('/api/notifications/send', {
23
+ method: 'POST',
24
+ headers: { 'Content-Type': 'application/json' },
25
+ body: JSON.stringify({ to }),
26
+ })
27
+ const body = await res.json() as NotifyResponse | { message: string }
28
+ if (!res.ok) throw new Error((body as { message: string }).message ?? 'Send failed')
29
+ setData(body as NotifyResponse)
30
+ } catch (e) {
31
+ setError((e as Error).message)
32
+ } finally {
33
+ setLoading(false)
34
+ }
35
+ }
36
+
37
+ return (
38
+ <div className="page">
39
+ <nav className="page-nav">
40
+ <div className="brand">
41
+ <span className="brand-dot" />
42
+ RudderJS
43
+ </div>
44
+ <div className="nav-right">
45
+ <a href="/demos" className="nav-link">Demos</a>
46
+ <a href="/" className="nav-link">Home</a>
47
+ </div>
48
+ </nav>
49
+
50
+ <section className="hero">
51
+ <h1 className="hero-title">Notifications</h1>
52
+ <p className="hero-lead">
53
+ Dispatches a <code className="inline-code">WelcomeNotification</code> via{' '}
54
+ <code className="inline-code">notify(notifiable, notification)</code>. The notification's{' '}
55
+ <code className="inline-code">via()</code> picks the channel(s); the mail channel routes
56
+ through the log driver, so output lands in the dev terminal.
57
+ </p>
58
+ </section>
59
+
60
+ <section className="feature-section" style={{ maxWidth: '32rem', margin: '0 auto' }}>
61
+ <div className="form-card">
62
+ <div style={{ marginBottom: '1rem' }}>
63
+ <label className="form-label" htmlFor="notify-to">Email</label>
64
+ <input id="notify-to" className="form-input" value={to} onChange={e => setTo(e.target.value)} />
65
+ </div>
66
+ <button className="form-submit" onClick={notify} disabled={loading}>
67
+ {loading ? 'Sending…' : 'Send notification'}
68
+ </button>
69
+ {error && (
70
+ <p className="form-error" style={{ marginTop: '1rem' }}>{error}</p>
71
+ )}
72
+ {data && (
73
+ <p className="form-success" style={{ marginTop: '1rem' }}>
74
+ Sent to <code>{data.to}</code> via <code>{data.channels.join(', ')}</code> — check the terminal.
75
+ </p>
76
+ )}
77
+ </div>
78
+ </section>
79
+ </div>
80
+ )
81
+ }
82
+ `;
83
+ }
84
+ export function demoNotification() {
85
+ return `import { Notification, type Notifiable } from '@rudderjs/notification'
86
+ import { Mailable } from '@rudderjs/mail'
87
+
88
+ class WelcomeMail extends Mailable {
89
+ constructor(private readonly notifiable: Notifiable) { super() }
90
+
91
+ build(): this {
92
+ return this
93
+ .subject(\`Welcome to RudderJS, \${this.notifiable.name ?? 'friend'}!\`)
94
+ .text(
95
+ \`Hi \${this.notifiable.name ?? 'there'},\\n\\n\` +
96
+ \`Your account is ready. Thanks for joining us.\\n\\n\` +
97
+ \`— The RudderJS Team\`,
98
+ )
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Demo notification — single mail channel by default. Add 'database' once
104
+ * the Notification Prisma model is migrated, or 'broadcast' once @rudderjs/broadcast
105
+ * is wired up.
106
+ */
107
+ export class WelcomeNotification extends Notification {
108
+ via(_notifiable: Notifiable): string[] {
109
+ return ['mail']
110
+ }
111
+
112
+ toMail(notifiable: Notifiable): WelcomeMail {
113
+ return new WelcomeMail(notifiable)
114
+ }
115
+ }
116
+ `;
117
+ }
118
+ export function demosNotificationsApiBlock() {
119
+ return `// POST /api/notifications/send — dispatches WelcomeNotification to the supplied email.
120
+ // On-demand notifiable: no DB record required.
121
+ router.post('/api/notifications/send', async (req, res) => {
122
+ const body = (req.body ?? {}) as { to?: string }
123
+ if (!body.to) return res.status(422).json({ message: 'Body must be { to }' })
124
+
125
+ const { notify, Notification } = await import('@rudderjs/notification')
126
+ const { WelcomeNotification } = await import('../app/Notifications/WelcomeNotification.ts')
127
+
128
+ const notification = new WelcomeNotification()
129
+ await notify(Notification.route('mail', body.to), notification)
130
+ res.json({ ok: true, to: body.to, channels: notification.via({ id: '0', email: body.to }) })
131
+ })`;
132
+ }
133
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications.js","sourceRoot":"","sources":["../../../src/templates/demos/notifications.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,mFAAmF;AAEnF,MAAM,UAAU,sBAAsB;IACpC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8ER,CAAA;AACD,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,OAAO;;;;;;;;;;;;GAYN,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function demosPennantView(): string;
2
+ export declare function demosPennantBetaView(): string;
3
+ /**
4
+ * Lines added to AppServiceProvider's boot() when the pennant demo is selected.
5
+ * Defines the four feature shapes shown in the demo (boolean, value, scoped, lottery).
6
+ */
7
+ export declare function pennantFeatureDefinitions(): string;
8
+ //# sourceMappingURL=pennant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pennant.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/pennant.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,IAAI,MAAM,CAqGzC;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAqB7C;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAKlD"}
@@ -0,0 +1,138 @@
1
+ // Pennant demo — feature flags resolved against the current user. Two routes:
2
+ // /demos/pennant (renders the four card shapes) and /demos/pennant/beta
3
+ // (guarded by FeatureMiddleware to demonstrate the 403 path).
4
+ export function demosPennantView() {
5
+ return `import '@/index.css'
6
+
7
+ interface PennantProps {
8
+ user: { id: string; name: string; email: string } | null
9
+ values: Record<string, unknown>
10
+ }
11
+
12
+ interface FeatureCardSpec {
13
+ name: string
14
+ shape: string
15
+ resolver: string
16
+ expected: string
17
+ }
18
+
19
+ const features: FeatureCardSpec[] = [
20
+ { name: 'dark-mode', shape: 'boolean', resolver: '() => true', expected: 'Always true.' },
21
+ { name: 'max-uploads', shape: 'value', resolver: '() => 10', expected: 'Returns the literal value, not a boolean.' },
22
+ { name: 'beta-dashboard', shape: 'scoped', resolver: '(scope) => scope !== null', expected: 'True for any signed-in user; false for anon.' },
23
+ { name: 'new-checkout', shape: 'lottery', resolver: '() => Lottery.odds(1, 4)', expected: '~25% chance per scope. Stable on subsequent checks.' },
24
+ ]
25
+
26
+ export default function PennantDemo({ user, values }: PennantProps) {
27
+ return (
28
+ <div className="page">
29
+ <nav className="page-nav">
30
+ <div className="brand">
31
+ <span className="brand-dot" />
32
+ RudderJS
33
+ </div>
34
+ <div className="nav-right">
35
+ <a href="/demos" className="nav-link">Demos</a>
36
+ <a href="/" className="nav-link">Home</a>
37
+ </div>
38
+ </nav>
39
+
40
+ <section className="hero">
41
+ <h1 className="hero-title">Feature flags</h1>
42
+ <p className="hero-lead">
43
+ Resolved against the current scope ({user
44
+ ? <><strong>{user.name}</strong> · {user.email}</>
45
+ : <em>guest</em>}). Definitions live in{' '}
46
+ <code className="inline-code">app/Providers/AppServiceProvider.ts</code>{' '}
47
+ and resolution happens here via{' '}
48
+ <code className="inline-code">Feature.values([...], scope)</code>.
49
+ </p>
50
+ {!user && (
51
+ <p className="hero-meta">
52
+ Sign in to see <code className="inline-code">beta-dashboard</code> flip to true.
53
+ </p>
54
+ )}
55
+ </section>
56
+
57
+ <section className="feature-section">
58
+ <div className="demo-card-grid">
59
+ {features.map(f => {
60
+ const resolved = values[f.name]
61
+ const display = JSON.stringify(resolved)
62
+ return (
63
+ <div key={f.name} className="demo-card">
64
+ <div className="demo-card-header">
65
+ <h2 className="flag-name">{f.name}</h2>
66
+ <p className="flag-shape">{f.shape}</p>
67
+ </div>
68
+ <div className="demo-card-body">
69
+ <div className="flag-section">
70
+ <div className="flag-section-label">resolver</div>
71
+ <code className="code-inline-block">{f.resolver}</code>
72
+ </div>
73
+ <div className="flag-section">
74
+ <div className="flag-section-label">expected</div>
75
+ <p className="demo-card-desc">{f.expected}</p>
76
+ </div>
77
+ <div className="flag-resolved">
78
+ <div className="flag-section-label">resolved value</div>
79
+ <code className="flag-resolved-value">{display}</code>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ )
84
+ })}
85
+ </div>
86
+
87
+ <div className="demo-card" style={{ marginTop: '1.5rem' }}>
88
+ <div className="demo-card-header">
89
+ <h2 className="demo-card-title">FeatureMiddleware</h2>
90
+ <p className="demo-card-desc">
91
+ <code className="inline-code">/demos/pennant/beta</code> is wrapped in{' '}
92
+ <code className="inline-code">FeatureMiddleware('beta-dashboard')</code>. The middleware reads{' '}
93
+ <code className="inline-code">req.user</code> as the scope; non-matching scopes get a 403.
94
+ </p>
95
+ </div>
96
+ <a href="/demos/pennant/beta" className="button-primary" style={{ display: 'inline-block', textDecoration: 'none' }}>
97
+ Open /demos/pennant/beta →
98
+ </a>
99
+ </div>
100
+ </section>
101
+ </div>
102
+ )
103
+ }
104
+ `;
105
+ }
106
+ export function demosPennantBetaView() {
107
+ return `import '@/index.css'
108
+
109
+ // Override the id-derived URL ('/demos/pennant-beta') so SPA nav matches the
110
+ // controller route, which is '/demos/pennant/beta' (a sub-path under pennant).
111
+ export const route = '/demos/pennant/beta'
112
+
113
+ export default function PennantBeta() {
114
+ return (
115
+ <div className="error-wrap">
116
+ <h1 className="heading-lg">Beta dashboard</h1>
117
+ <p className="muted" style={{ maxWidth: '32rem', textAlign: 'center' }}>
118
+ You only see this page if <code className="inline-code">beta-dashboard</code> is active for your scope.
119
+ The route is wrapped in <code className="inline-code">FeatureMiddleware('beta-dashboard')</code>;
120
+ unauthorized scopes get a 403 before this view ever renders.
121
+ </p>
122
+ <a href="/demos/pennant" className="error-link">← Back to /demos/pennant</a>
123
+ </div>
124
+ )
125
+ }
126
+ `;
127
+ }
128
+ /**
129
+ * Lines added to AppServiceProvider's boot() when the pennant demo is selected.
130
+ * Defines the four feature shapes shown in the demo (boolean, value, scoped, lottery).
131
+ */
132
+ export function pennantFeatureDefinitions() {
133
+ return `Feature.define('dark-mode', () => true)
134
+ Feature.define('max-uploads', () => 10)
135
+ Feature.define('beta-dashboard', (scope) => typeof scope === 'object' && scope !== null)
136
+ Feature.define('new-checkout', () => Lottery.odds(1, 4))`;
137
+ }
138
+ //# sourceMappingURL=pennant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pennant.js","sourceRoot":"","sources":["../../../src/templates/demos/pennant.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wEAAwE;AACxE,8DAA8D;AAE9D,MAAM,UAAU,gBAAgB;IAC9B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmGR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO;;;;;;;;;;;;;;;;;;;CAmBR,CAAA;AACD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO;;;+DAGsD,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function demosQueueView(): string;
2
+ export declare function exampleJob(): string;
3
+ export declare function demosQueueApiBlock(): string;
4
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/queue.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,IAAI,MAAM,CAqEvC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAyBnC;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAO3C"}
@@ -0,0 +1,107 @@
1
+ // Queue dispatch demo — Job class in app/Jobs/ + dispatch endpoint that
2
+ // enqueues it. Default driver is in-memory; the worker drains during dev.
3
+ export function demosQueueView() {
4
+ return `import { useState } from 'react'
5
+ import '@/index.css'
6
+
7
+ interface QueueResponse {
8
+ ok: boolean
9
+ queue: string
10
+ dispatchedAt: string
11
+ }
12
+
13
+ export default function QueueDemo() {
14
+ const [results, setResults] = useState<QueueResponse[]>([])
15
+ const [loading, setLoading] = useState(false)
16
+
17
+ async function dispatch() {
18
+ setLoading(true)
19
+ try {
20
+ const res = await fetch('/api/queue/dispatch', { method: 'POST' })
21
+ const data = await res.json() as QueueResponse
22
+ setResults(prev => [data, ...prev].slice(0, 10))
23
+ } finally {
24
+ setLoading(false)
25
+ }
26
+ }
27
+
28
+ return (
29
+ <div className="page">
30
+ <nav className="page-nav">
31
+ <div className="brand">
32
+ <span className="brand-dot" />
33
+ RudderJS
34
+ </div>
35
+ <div className="nav-right">
36
+ <a href="/demos" className="nav-link">Demos</a>
37
+ <a href="/" className="nav-link">Home</a>
38
+ </div>
39
+ </nav>
40
+
41
+ <section className="hero">
42
+ <h1 className="hero-title">Queue dispatch</h1>
43
+ <p className="hero-lead">
44
+ Click to dispatch <code className="inline-code">ExampleJob</code> via{' '}
45
+ <code className="inline-code">@rudderjs/queue</code>. The handler logs to the
46
+ server terminal — install <code className="inline-code">@rudderjs/horizon</code> to see
47
+ dispatched jobs in a UI.
48
+ </p>
49
+ </section>
50
+
51
+ <section className="feature-section" style={{ maxWidth: '32rem', margin: '0 auto' }}>
52
+ <div className="form-card">
53
+ <button className="form-submit" onClick={dispatch} disabled={loading} style={{ marginBottom: '1rem' }}>
54
+ {loading ? 'Dispatching…' : 'Dispatch ExampleJob'}
55
+ </button>
56
+ {results.length === 0 && (
57
+ <p className="feature-desc" style={{ fontSize: '0.75rem', textAlign: 'center' }}>
58
+ No dispatches yet.
59
+ </p>
60
+ )}
61
+ {results.map((r, i) => (
62
+ <p key={i} className="feature-desc" style={{ fontSize: '0.75rem', fontFamily: 'monospace', marginBottom: '0.25rem' }}>
63
+ · {r.dispatchedAt} · queue={r.queue}
64
+ </p>
65
+ ))}
66
+ </div>
67
+ </section>
68
+ </div>
69
+ )
70
+ }
71
+ `;
72
+ }
73
+ export function exampleJob() {
74
+ return `import { Job } from '@rudderjs/queue'
75
+
76
+ /**
77
+ * Example job for the queue demo. Logs to the server terminal when run
78
+ * by the worker. Replace with whatever async work the queue should handle
79
+ * (sending mail, generating reports, syncing third-party data, …).
80
+ */
81
+ export class ExampleJob extends Job {
82
+ static override queue = 'default'
83
+ static override retries = 3
84
+
85
+ constructor(private readonly payload: string = 'hello') {
86
+ super()
87
+ }
88
+
89
+ async handle(): Promise<void> {
90
+ console.log(\`[ExampleJob] handling: \${this.payload}\`)
91
+ }
92
+
93
+ failed(error: unknown): void {
94
+ console.error('[ExampleJob] failed after all retries:', error)
95
+ }
96
+ }
97
+ `;
98
+ }
99
+ export function demosQueueApiBlock() {
100
+ return `// POST /api/queue/dispatch — enqueue ExampleJob. Worker drains it during dev.
101
+ router.post('/api/queue/dispatch', async (_req, res) => {
102
+ const { ExampleJob } = await import('../app/Jobs/ExampleJob.ts')
103
+ await ExampleJob.dispatch('hello from /api/queue/dispatch').send()
104
+ res.json({ ok: true, queue: 'default', dispatchedAt: new Date().toISOString() })
105
+ })`;
106
+ }
107
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/templates/demos/queue.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,0EAA0E;AAE1E,MAAM,UAAU,cAAc;IAC5B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmER,CAAA;AACD,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO;;;;;;;;;;;;;;;;;;;;;;;CAuBR,CAAA;AACD,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO;;;;;GAKN,CAAA;AACH,CAAC"}
@@ -1,13 +1,26 @@
1
1
  import type { TemplateContext } from '../../templates.js';
2
2
  export interface DemoSpec {
3
+ /** Stable id used in URLs, file names, and the prompt multiselect. */
3
4
  value: string;
5
+ /** Short label shown in the @clack/prompts multiselect. */
4
6
  label: string;
7
+ /** Single-line hint shown next to the label in the prompt. */
5
8
  hint?: string;
9
+ /** Card title shown on /demos. Falls back to `label` when omitted. */
10
+ title?: string;
11
+ /** Long description shown on the /demos card in the scaffolded app + playground. */
12
+ description: string;
13
+ /** Packages this demo exercises — rendered under each /demos card. */
14
+ packages: ReadonlyArray<string>;
6
15
  /** Package keys that must all be selected for this demo to scaffold. */
7
16
  requires?: ReadonlyArray<keyof TemplateContext['packages']>;
8
17
  /** True if this demo requires a database/ORM. */
9
18
  requiresOrm?: boolean;
10
19
  }
20
+ /** Card title used on /demos — falls back to `label` when not overridden. */
21
+ export declare function demoTitle(spec: DemoSpec): string;
11
22
  export declare const DEMOS: ReadonlyArray<DemoSpec>;
12
23
  export declare function availableDemos(orm: TemplateContext['orm'], packages: TemplateContext['packages']): DemoSpec[];
24
+ /** Default href for a demo card — `/demos/<value>`. */
25
+ export declare function demoHref(spec: Pick<DemoSpec, 'value'>): string;
13
26
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEzD,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAS,MAAM,CAAA;IACpB,KAAK,EAAS,MAAM,CAAA;IACpB,IAAI,CAAC,EAAS,MAAM,CAAA;IACpB,wEAAwE;IACxE,QAAQ,CAAC,EAAK,aAAa,CAAC,MAAM,eAAe,CAAC,UAAU,CAAC,CAAC,CAAA;IAC9D,iDAAiD;IACjD,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,eAAO,MAAM,KAAK,EAAE,aAAa,CAAC,QAAQ,CAIzC,CAAA;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC,EAC3B,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,GACpC,QAAQ,EAAE,CAMZ"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEzD,MAAM,WAAW,QAAQ;IACvB,sEAAsE;IACtE,KAAK,EAAS,MAAM,CAAA;IACpB,2DAA2D;IAC3D,KAAK,EAAS,MAAM,CAAA;IACpB,8DAA8D;IAC9D,IAAI,CAAC,EAAS,MAAM,CAAA;IACpB,sEAAsE;IACtE,KAAK,CAAC,EAAQ,MAAM,CAAA;IACpB,oFAAoF;IACpF,WAAW,EAAG,MAAM,CAAA;IACpB,sEAAsE;IACtE,QAAQ,EAAM,aAAa,CAAC,MAAM,CAAC,CAAA;IACnC,wEAAwE;IACxE,QAAQ,CAAC,EAAK,aAAa,CAAC,MAAM,eAAe,CAAC,UAAU,CAAC,CAAC,CAAA;IAC9D,iDAAiD;IACjD,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEhD;AAED,eAAO,MAAM,KAAK,EAAE,aAAa,CAAC,QAAQ,CAiHzC,CAAA;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC,EAC3B,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,GACpC,QAAQ,EAAE,CAMZ;AAED,uDAAuD;AACvD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,MAAM,CAE9D"}
@@ -1,7 +1,120 @@
1
+ /** Card title used on /demos — falls back to `label` when not overridden. */
2
+ export function demoTitle(spec) {
3
+ return spec.title ?? spec.label;
4
+ }
1
5
  export const DEMOS = [
2
- { value: 'contact', label: 'Contact form', hint: 'CSRF + Zod validation' },
3
- { value: 'ws', label: 'WebSocket chat', hint: 'requires WebSocket / Broadcast', requires: ['broadcast'] },
4
- { value: 'live', label: 'Yjs collaboration', hint: 'requires Sync', requires: ['sync'] },
6
+ {
7
+ value: 'contact',
8
+ label: 'Contact form',
9
+ hint: 'CSRF + Zod validation',
10
+ description: 'CSRF-protected form with Zod validation. Demonstrates getCsrfToken() and FormRequest-style error handling.',
11
+ packages: ['@rudderjs/middleware', '@rudderjs/core'],
12
+ },
13
+ {
14
+ value: 'cache',
15
+ label: 'Cache counter',
16
+ hint: 'Cache.get + Cache.set round-trip',
17
+ description: 'Click "Bump" to read the current value via Cache.get, increment it, and write it back via Cache.set. Default driver is in-memory.',
18
+ packages: ['@rudderjs/cache'],
19
+ },
20
+ {
21
+ value: 'todos',
22
+ label: 'Todos CRUD',
23
+ title: 'Todos',
24
+ hint: 'requires ORM',
25
+ description: 'ORM + interactive UI. Controller loads initial data, the view hydrates and POSTs to /api/todos/* for live updates.',
26
+ packages: ['@rudderjs/orm', '@rudderjs/router'],
27
+ requiresOrm: true,
28
+ },
29
+ {
30
+ value: 'queue',
31
+ label: 'Queue dispatch',
32
+ hint: 'requires Queue',
33
+ description: 'Dispatch ExampleJob via @rudderjs/queue. The handler logs to the server terminal — install @rudderjs/horizon for a UI.',
34
+ packages: ['@rudderjs/queue'],
35
+ requires: ['queue'],
36
+ },
37
+ {
38
+ value: 'mail',
39
+ label: 'Mail send',
40
+ hint: 'requires Mail',
41
+ description: 'Send a DemoMail via @rudderjs/mail. Default driver is log — output lands in the dev server terminal.',
42
+ packages: ['@rudderjs/mail'],
43
+ requires: ['mail'],
44
+ },
45
+ {
46
+ value: 'notifications',
47
+ label: 'Notifications',
48
+ hint: 'requires Notifications + Mail',
49
+ description: "Dispatch a WelcomeNotification via notify(). The notification's via() picks the channel(s); mail routes through the log driver.",
50
+ packages: ['@rudderjs/notification', '@rudderjs/mail'],
51
+ requires: ['notifications', 'mail'],
52
+ },
53
+ {
54
+ value: 'localization',
55
+ label: 'Localization',
56
+ hint: 'requires Localization',
57
+ description: 'Locale switcher resolves the same keys server-side via trans(). Strings live in lang/<locale>/messages.json.',
58
+ packages: ['@rudderjs/localization'],
59
+ requires: ['localization'],
60
+ },
61
+ {
62
+ value: 'http',
63
+ label: 'HTTP client',
64
+ hint: 'requires HTTP',
65
+ description: 'Server-side Http.retry(3, 200).timeout(5000).get(url) against a public API. The 500 endpoint exercises the retry path.',
66
+ packages: ['@rudderjs/http'],
67
+ requires: ['http'],
68
+ },
69
+ {
70
+ value: 'avatar',
71
+ label: 'Avatar resize',
72
+ hint: 'requires Storage + Image',
73
+ description: 'Upload an image — server resizes it to 256×256 WebP via @rudderjs/image and saves to public storage. Side-by-side compare.',
74
+ packages: ['@rudderjs/image', '@rudderjs/storage'],
75
+ requires: ['storage', 'image'],
76
+ },
77
+ {
78
+ value: 'fibonacci',
79
+ label: 'Worker threads',
80
+ hint: 'requires Concurrency',
81
+ description: 'Compute fib(n) sequentially on the main thread vs across @rudderjs/concurrency worker pool. Watch the parallel cost stay flat as you crank N.',
82
+ packages: ['@rudderjs/concurrency'],
83
+ requires: ['concurrency'],
84
+ },
85
+ {
86
+ value: 'system-info',
87
+ label: 'System info',
88
+ hint: 'requires Process',
89
+ description: 'Three shell commands (git, node, uptime) executed via @rudderjs/process. Compares sequential vs parallel cost using Process.pool().',
90
+ packages: ['@rudderjs/process'],
91
+ requires: ['process'],
92
+ },
93
+ {
94
+ value: 'pennant',
95
+ label: 'Feature flags',
96
+ hint: 'requires Pennant + Auth',
97
+ description: 'Boolean, value, scoped, and Lottery features resolved against the current user. Sub-route guarded by FeatureMiddleware to demonstrate 403 blocking.',
98
+ packages: ['@rudderjs/pennant'],
99
+ requires: ['pennant', 'auth'],
100
+ },
101
+ {
102
+ value: 'ws',
103
+ label: 'WebSocket chat',
104
+ hint: 'requires WebSocket / Broadcast',
105
+ description: 'Real-time chat + presence using @rudderjs/broadcast — multi-channel pub/sub over a single WebSocket connection.',
106
+ packages: ['@rudderjs/broadcast'],
107
+ requires: ['broadcast'],
108
+ },
109
+ {
110
+ value: 'sync',
111
+ label: 'Yjs collaboration',
112
+ title: 'Collaborative editor',
113
+ hint: 'requires Sync',
114
+ description: 'Yjs CRDT live document with awareness cursors. Open in two tabs to see real-time sync over @rudderjs/sync.',
115
+ packages: ['@rudderjs/sync'],
116
+ requires: ['sync'],
117
+ },
5
118
  ];
6
119
  export function availableDemos(orm, packages) {
7
120
  return DEMOS.filter(d => {
@@ -12,4 +125,8 @@ export function availableDemos(orm, packages) {
12
125
  return true;
13
126
  });
14
127
  }
128
+ /** Default href for a demo card — `/demos/<value>`. */
129
+ export function demoHref(spec) {
130
+ return `/demos/${spec.value}`;
131
+ }
15
132
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/templates/demos/registry.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,KAAK,GAA4B;IAC5C,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAO,IAAI,EAAE,uBAAuB,EAAE;IAC/E,EAAE,KAAK,EA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ErC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QACtB,IAAI,CAAC,CAAC,WAAW,IAAI,GAAG,KAAK,KAAK;YAAE,OAAO,KAAK,CAAA;QAChD,IAAI,CAAC,CAAC,QAAQ;YAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QACzD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,QAAQ,CAAC,IAA6B;IACpD,OAAO,UAAU,IAAI,CAAC,KAAK,EAAE,CAAA;AAC/B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function rudderSocketSource(): string;
2
+ //# sourceMappingURL=rudder-socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rudder-socket.d.ts","sourceRoot":"","sources":["../../../src/templates/demos/rudder-socket.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,IAAI,MAAM,CA6F3C"}