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,127 @@
1
+ // Mail send demo — defines a Mailable and posts to /api/mail/send.
2
+ // Default driver is `log`, so the email lands in the dev terminal.
3
+ export function demosMailView() {
4
+ return `import { useState } from 'react'
5
+ import '@/index.css'
6
+
7
+ interface MailResponse {
8
+ ok: boolean
9
+ to: string
10
+ subject: string
11
+ driver: string
12
+ }
13
+
14
+ export default function MailDemo() {
15
+ const [to, setTo] = useState('user@example.com')
16
+ const [subject, setSubject] = useState('Hello from RudderJS')
17
+ const [data, setData] = useState<MailResponse | null>(null)
18
+ const [loading, setLoading] = useState(false)
19
+ const [error, setError] = useState<string | null>(null)
20
+
21
+ async function send() {
22
+ setLoading(true); setError(null)
23
+ try {
24
+ const res = await fetch('/api/mail/send', {
25
+ method: 'POST',
26
+ headers: { 'Content-Type': 'application/json' },
27
+ body: JSON.stringify({ to, subject }),
28
+ })
29
+ const body = await res.json() as MailResponse | { message: string }
30
+ if (!res.ok) throw new Error((body as { message: string }).message ?? 'Send failed')
31
+ setData(body as MailResponse)
32
+ } catch (e) {
33
+ setError((e as Error).message)
34
+ } finally {
35
+ setLoading(false)
36
+ }
37
+ }
38
+
39
+ return (
40
+ <div className="page">
41
+ <nav className="page-nav">
42
+ <div className="brand">
43
+ <span className="brand-dot" />
44
+ RudderJS
45
+ </div>
46
+ <div className="nav-right">
47
+ <a href="/demos" className="nav-link">Demos</a>
48
+ <a href="/" className="nav-link">Home</a>
49
+ </div>
50
+ </nav>
51
+
52
+ <section className="hero">
53
+ <h1 className="hero-title">Mail send</h1>
54
+ <p className="hero-lead">
55
+ Sends a <code className="inline-code">DemoMail</code> via{' '}
56
+ <code className="inline-code">@rudderjs/mail</code>. Default driver is{' '}
57
+ <code className="inline-code">log</code> — check the dev server terminal for output.
58
+ </p>
59
+ </section>
60
+
61
+ <section className="feature-section" style={{ maxWidth: '32rem', margin: '0 auto' }}>
62
+ <div className="form-card">
63
+ <div style={{ marginBottom: '1rem' }}>
64
+ <label className="form-label" htmlFor="mail-to">To</label>
65
+ <input id="mail-to" className="form-input" value={to} onChange={e => setTo(e.target.value)} />
66
+ </div>
67
+ <div style={{ marginBottom: '1rem' }}>
68
+ <label className="form-label" htmlFor="mail-subject">Subject</label>
69
+ <input id="mail-subject" className="form-input" value={subject} onChange={e => setSubject(e.target.value)} />
70
+ </div>
71
+ <button className="form-submit" onClick={send} disabled={loading}>
72
+ {loading ? 'Sending…' : 'Send mail'}
73
+ </button>
74
+ {error && (
75
+ <p className="form-error" style={{ marginTop: '1rem' }}>{error}</p>
76
+ )}
77
+ {data && (
78
+ <p className="form-success" style={{ marginTop: '1rem' }}>
79
+ Sent to <code>{data.to}</code> via <code>{data.driver}</code> driver — check the terminal.
80
+ </p>
81
+ )}
82
+ </div>
83
+ </section>
84
+ </div>
85
+ )
86
+ }
87
+ `;
88
+ }
89
+ export function demoMailable() {
90
+ return `import { Mailable } from '@rudderjs/mail'
91
+
92
+ /**
93
+ * Demo mailable — built dynamically from the to/subject the user enters.
94
+ * Replace with whatever copy your real templates need (HTML + text).
95
+ */
96
+ export class DemoMail extends Mailable {
97
+ constructor(private readonly heading: string) { super() }
98
+
99
+ build(): this {
100
+ return this
101
+ .subject(this.heading)
102
+ .html(\`<h1>\${this.heading}</h1><p>Sent from the RudderJS mail demo.</p>\`)
103
+ .text(\`\${this.heading}\\n\\nSent from the RudderJS mail demo.\`)
104
+ }
105
+ }
106
+ `;
107
+ }
108
+ export function demosMailApiBlock() {
109
+ return `// POST /api/mail/send — sends a DemoMail to the user-supplied address.
110
+ router.post('/api/mail/send', async (req, res) => {
111
+ const body = (req.body ?? {}) as { to?: string; subject?: string }
112
+ if (!body.to || !body.subject) {
113
+ return res.status(422).json({ message: 'Body must be { to, subject }' })
114
+ }
115
+ const { Mail } = await import('@rudderjs/mail')
116
+ const { DemoMail } = await import('../app/Mail/DemoMail.ts')
117
+ const { config } = await import('@rudderjs/core')
118
+ await Mail.to(body.to).send(new DemoMail(body.subject))
119
+ res.json({
120
+ ok: true,
121
+ to: body.to,
122
+ subject: body.subject,
123
+ driver: config<string>('mail.default', 'log'),
124
+ })
125
+ })`;
126
+ }
127
+ //# sourceMappingURL=mail.js.map
@@ -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 +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,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,CAezC,CAAA;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC,EAC3B,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,GACpC,QAAQ,EAAE,CAMZ"}
@@ -1,7 +1,18 @@
1
1
  export const DEMOS = [
2
2
  { value: 'contact', label: 'Contact form', hint: 'CSRF + Zod validation' },
3
+ { value: 'cache', label: 'Cache counter', hint: 'Cache.get + Cache.set round-trip' },
4
+ { value: 'todos', label: 'Todos CRUD', hint: 'requires ORM', requiresOrm: true },
5
+ { value: 'queue', label: 'Queue dispatch', hint: 'requires Queue', requires: ['queue'] },
6
+ { value: 'mail', label: 'Mail send', hint: 'requires Mail', requires: ['mail'] },
7
+ { value: 'notifications', label: 'Notifications', hint: 'requires Notifications + Mail', requires: ['notifications', 'mail'] },
8
+ { value: 'localization', label: 'Localization', hint: 'requires Localization', requires: ['localization'] },
9
+ { value: 'http', label: 'HTTP client', hint: 'requires HTTP', requires: ['http'] },
10
+ { value: 'avatar', label: 'Avatar resize', hint: 'requires Storage + Image', requires: ['storage', 'image'] },
11
+ { value: 'fibonacci', label: 'Worker threads', hint: 'requires Concurrency', requires: ['concurrency'] },
12
+ { value: 'system-info', label: 'System info', hint: 'requires Process', requires: ['process'] },
13
+ { value: 'pennant', label: 'Feature flags', hint: 'requires Pennant + Auth', requires: ['pennant', 'auth'] },
3
14
  { value: 'ws', label: 'WebSocket chat', hint: 'requires WebSocket / Broadcast', requires: ['broadcast'] },
4
- { value: 'live', label: 'Yjs collaboration', hint: 'requires Sync', requires: ['sync'] },
15
+ { value: 'sync', label: 'Yjs collaboration', hint: 'requires Sync', requires: ['sync'] },
5
16
  ];
6
17
  export function availableDemos(orm, packages) {
7
18
  return DEMOS.filter(d => {
@@ -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,EAAE,IAAI,EAAO,KAAK,EAAE,gBAAgB,EAAK,IAAI,EAAE,gCAAgC,EAAE,QAAQ,EAAE,CAAC,WAAW,CAAC,EAAE;IACjH,EAAE,KAAK,EAAE,MAAM,EAAK,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,EAAmB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE;CAC7G,CAAA;AAED,MAAM,UAAU,cAAc,CAC5B,GAA2B,EAC3B,QAAqC;IAErC,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"}
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,EAAQ,KAAK,EAAE,cAAc,EAAO,IAAI,EAAE,uBAAuB,EAAE;IACrF,EAAE,KAAK,EAAE,OAAO,EAAU,KAAK,EAAE,eAAe,EAAM,IAAI,EAAE,kCAAkC,EAAE;IAChG,EAAE,KAAK,EAAE,OAAO,EAAU,KAAK,EAAE,YAAY,EAAS,IAAI,EAAE,cAAc,EAAoB,WAAW,EAAE,IAAI,EAAE;IACjH,EAAE,KAAK,EAAE,OAAO,EAAU,KAAK,EAAE,gBAAgB,EAAK,IAAI,EAAE,gBAAgB,EAAkB,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE;IACnH,EAAE,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,WAAW,EAAU,IAAI,EAAE,eAAe,EAAmB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE;IAClH,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,EAAM,IAAI,EAAE,+BAA+B,EAAG,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,CAAC,EAAE;IACnI,EAAE,KAAK,EAAE,cAAc,EAAG,KAAK,EAAE,cAAc,EAAO,IAAI,EAAE,uBAAuB,EAAW,QAAQ,EAAE,CAAC,cAAc,CAAC,EAAE;IAC1H,EAAE,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,aAAa,EAAQ,IAAI,EAAE,eAAe,EAAmB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE;IAClH,EAAE,KAAK,EAAE,QAAQ,EAAS,KAAK,EAAE,eAAe,EAAM,IAAI,EAAE,0BAA0B,EAAQ,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE;IAC9H,EAAE,KAAK,EAAE,WAAW,EAAM,KAAK,EAAE,gBAAgB,EAAK,IAAI,EAAE,sBAAsB,EAAY,QAAQ,EAAE,CAAC,aAAa,CAAC,EAAE;IACzH,EAAE,KAAK,EAAE,aAAa,EAAI,KAAK,EAAE,aAAa,EAAQ,IAAI,EAAE,kBAAkB,EAAgB,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE;IACrH,EAAE,KAAK,EAAE,SAAS,EAAQ,KAAK,EAAE,eAAe,EAAM,IAAI,EAAE,yBAAyB,EAAS,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE;IAC7H,EAAE,KAAK,EAAE,IAAI,EAAa,KAAK,EAAE,gBAAgB,EAAK,IAAI,EAAE,gCAAgC,EAAE,QAAQ,EAAE,CAAC,WAAW,CAAC,EAAE;IACvH,EAAE,KAAK,EAAE,MAAM,EAAW,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,EAAmB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE;CACnH,CAAA;AAED,MAAM,UAAU,cAAc,CAC5B,GAA2B,EAC3B,QAAqC;IAErC,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"}
@@ -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"}
@@ -1,5 +1,5 @@
1
- export function bkSocketSource() {
2
- return `// BKSocket — RudderJS WebSocket client
1
+ export function rudderSocketSource() {
2
+ return `// RudderSocket — RudderJS WebSocket client
3
3
  //
4
4
  // Multiplexes channels and presence rooms over a single WebSocket connection.
5
5
  // Mirrors the API expected by @rudderjs/broadcast on the server.
@@ -10,7 +10,7 @@ class Channel {
10
10
  private listeners = new Map<string, Set<Listener>>()
11
11
 
12
12
  constructor(
13
- private readonly socket: BKSocket,
13
+ private readonly socket: RudderSocket,
14
14
  public readonly name: string,
15
15
  ) {}
16
16
 
@@ -25,19 +25,19 @@ class Channel {
25
25
  return this
26
26
  }
27
27
 
28
- /** @internal — invoked by BKSocket on incoming messages */
28
+ /** @internal — invoked by RudderSocket on incoming messages */
29
29
  receive(event: string, data: unknown) {
30
30
  this.listeners.get(event)?.forEach(fn => fn(data))
31
31
  }
32
32
 
33
- /** @internal — invoked by BKSocket to (re)subscribe after connect */
33
+ /** @internal — invoked by RudderSocket to (re)subscribe after connect */
34
34
  subscribe() {
35
35
  this.socket.send({ type: 'subscribe', channel: this.name })
36
36
  }
37
37
  }
38
38
 
39
39
  class Presence extends Channel {
40
- constructor(socket: BKSocket, name: string, private readonly token: string) {
40
+ constructor(socket: RudderSocket, name: string, private readonly token: string) {
41
41
  super(socket, name)
42
42
  }
43
43
 
@@ -46,7 +46,7 @@ class Presence extends Channel {
46
46
  }
47
47
  }
48
48
 
49
- export class BKSocket {
49
+ export class RudderSocket {
50
50
  private ws?: WebSocket
51
51
  private readonly channels = new Map<string, Channel>()
52
52
  private reconnectTimer?: ReturnType<typeof setTimeout>
@@ -92,4 +92,4 @@ export class BKSocket {
92
92
  }
93
93
  `;
94
94
  }
95
- //# sourceMappingURL=bk-socket.js.map
95
+ //# sourceMappingURL=rudder-socket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rudder-socket.js","sourceRoot":"","sources":["../../../src/templates/demos/rudder-socket.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB;IAChC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2FR,CAAA;AACD,CAAC"}