nuxt-telegram-mini-app 0.0.1

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 (40) hide show
  1. package/.env.example +2 -0
  2. package/.vscode/settings.json +55 -0
  3. package/.vscode/tailwind.json +55 -0
  4. package/CONTRIBUTING.md +406 -0
  5. package/LICENSE +21 -0
  6. package/README.md +640 -0
  7. package/app/app.vue +87 -0
  8. package/app/assets/css/main.css +53 -0
  9. package/app/assets/css/tailwind.css +3 -0
  10. package/app/components/ErrorBoundary.vue +81 -0
  11. package/app/components/Hero.vue +61 -0
  12. package/app/components/tg/Button.vue +128 -0
  13. package/app/components/tg/Cell.vue +91 -0
  14. package/app/components/tg/Content.vue +42 -0
  15. package/app/components/tg/Nav.vue +107 -0
  16. package/app/components/tg/Section.vue +50 -0
  17. package/app/composables/telegram.ts +342 -0
  18. package/app/error.vue +161 -0
  19. package/app/pages/components.vue +279 -0
  20. package/app/pages/functions.vue +107 -0
  21. package/app/pages/index.vue +211 -0
  22. package/app/pages/utilities.vue +402 -0
  23. package/app/types/telegram-webapp.ts +160 -0
  24. package/app/utils/color.ts +37 -0
  25. package/eslint.config.mjs +6 -0
  26. package/nuxt.config.ts +55 -0
  27. package/package.json +46 -0
  28. package/public/_redirects +2 -0
  29. package/public/favicon.ico +0 -0
  30. package/public/img/hero-user.svg +8 -0
  31. package/public/img/nuxt-logo.svg +11 -0
  32. package/public/robots.txt +2 -0
  33. package/server/api/verify-telegram-data.post.ts +150 -0
  34. package/tailwind.config.ts +39 -0
  35. package/tests/components.spec.ts +311 -0
  36. package/tests/pages.spec.ts +426 -0
  37. package/tests/telegram.spec.ts +105 -0
  38. package/tests/utils.spec.ts +47 -0
  39. package/tsconfig.json +18 -0
  40. package/vitest.config.ts +24 -0
package/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ # Telegram Bot Configuration
2
+ BOT_TOKEN=your_telegram_bot_token_here
@@ -0,0 +1,55 @@
1
+ {
2
+ // Disable the default formatter, use eslint instead
3
+ "prettier.enable": false,
4
+ "editor.formatOnSave": false,
5
+
6
+ // Auto fix
7
+ "editor.codeActionsOnSave": {
8
+ "source.fixAll.eslint": "explicit",
9
+ "source.organizeImports": "never"
10
+ },
11
+
12
+ // Silent the stylistic rules in you IDE, but still auto fix them
13
+ "eslint.rules.customizations": [
14
+ { "rule": "style/*", "severity": "off", "fixable": true },
15
+ { "rule": "format/*", "severity": "off", "fixable": true },
16
+ { "rule": "*-indent", "severity": "off", "fixable": true },
17
+ { "rule": "*-spacing", "severity": "off", "fixable": true },
18
+ { "rule": "*-spaces", "severity": "off", "fixable": true },
19
+ { "rule": "*-order", "severity": "off", "fixable": true },
20
+ { "rule": "*-dangle", "severity": "off", "fixable": true },
21
+ { "rule": "*-newline", "severity": "off", "fixable": true },
22
+ { "rule": "*quotes", "severity": "off", "fixable": true },
23
+ { "rule": "*semi", "severity": "off", "fixable": true }
24
+ ],
25
+
26
+ // Enable eslint for all supported languages
27
+ "eslint.validate": [
28
+ "javascript",
29
+ "javascriptreact",
30
+ "typescript",
31
+ "typescriptreact",
32
+ "vue",
33
+ "html",
34
+ "markdown",
35
+ "json",
36
+ "jsonc",
37
+ "yaml",
38
+ "toml",
39
+ "xml",
40
+ "gql",
41
+
42
+ "graphql",
43
+ "astro",
44
+ "svelte",
45
+ "css",
46
+ "less",
47
+ "scss",
48
+ "pcss",
49
+ "postcss"
50
+ ],
51
+
52
+ // Unknown at rule @apply (unknownAtRules) fix
53
+ // https://github.com/tailwindlabs/tailwindcss/discussions/5258
54
+ "css.customData": [".vscode/tailwind.json"]
55
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "version": 1.1,
3
+ "atDirectives": [
4
+ {
5
+ "name": "@tailwind",
6
+ "description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.",
7
+ "references": [
8
+ {
9
+ "name": "Tailwind Documentation",
10
+ "url": "https://tailwindcss.com/docs/functions-and-directives#tailwind"
11
+ }
12
+ ]
13
+ },
14
+ {
15
+ "name": "@apply",
16
+ "description": "Use the `@apply` directive to inline any existing utility classes into your own custom CSS. This is useful when you find a common utility pattern in your HTML that you’d like to extract to a new component.",
17
+ "references": [
18
+ {
19
+ "name": "Tailwind Documentation",
20
+ "url": "https://tailwindcss.com/docs/functions-and-directives#apply"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "name": "@responsive",
26
+ "description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n .alert {\n background-color: #E53E3E;\n }\n}\n```\n",
27
+ "references": [
28
+ {
29
+ "name": "Tailwind Documentation",
30
+ "url": "https://tailwindcss.com/docs/functions-and-directives#responsive"
31
+ }
32
+ ]
33
+ },
34
+ {
35
+ "name": "@screen",
36
+ "description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n /* ... */\n}\n```\n…gets transformed into this:\n```css\n@media (min-width: 640px) {\n /* ... */\n}\n```\n",
37
+ "references": [
38
+ {
39
+ "name": "Tailwind Documentation",
40
+ "url": "https://tailwindcss.com/docs/functions-and-directives#screen"
41
+ }
42
+ ]
43
+ },
44
+ {
45
+ "name": "@variants",
46
+ "description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n .btn-brand {\n background-color: #3182CE;\n }\n}\n```\n",
47
+ "references": [
48
+ {
49
+ "name": "Tailwind Documentation",
50
+ "url": "https://tailwindcss.com/docs/functions-and-directives#variants"
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,406 @@
1
+ # Contributing Guide
2
+
3
+ Thank you for your interest in contributing to the Nuxt Telegram Mini App Template! This guide will help you understand the project structure and development workflow.
4
+
5
+ ## 🏗️ Project Architecture
6
+
7
+ ### Directory Structure Overview
8
+
9
+ ```
10
+ root/
11
+ ├── app/ # Main application code (Nuxt srcDir)
12
+ │ ├── assets/ # Static assets and stylesheets
13
+ │ │ └── css/
14
+ │ │ ├── main.css # Global CSS with Telegram theme variables
15
+ │ │ └── tailwind.css # Tailwind CSS imports
16
+ │ ├── components/ # Reusable Vue components
17
+ │ │ ├── ErrorBoundary.vue # Error boundary component
18
+ │ │ ├── Hero.vue # Page hero component
19
+ │ │ └── tg/ # Telegram-specific components
20
+ │ │ ├── Button.vue # Telegram button component
21
+ │ │ ├── Cell.vue # List cell component
22
+ │ │ ├── Content.vue # Main content wrapper
23
+ │ │ ├── Nav.vue # Bottom navigation
24
+ │ │ └── Section.vue # Content sections
25
+ │ ├── composables/ # Vue composables for reusable logic
26
+ │ │ └── telegram.ts # Telegram WebApp SDK integration
27
+ │ ├── pages/ # File-based routing pages
28
+ │ │ ├── index.vue # Home page with main demo
29
+ │ │ ├── components.vue # Components showcase page
30
+ │ │ ├── utilities.vue # Utilities and tools demo
31
+ │ │ └── functions.vue # Functions page example
32
+ │ ├── types/ # TypeScript type definitions
33
+ │ │ └── telegram-webapp.ts # Telegram WebApp types
34
+ │ └── utils/ # Utility functions
35
+ │ └── color.ts # Color conversion utilities
36
+ ├── server/ # Nuxt server API
37
+ │ └── api/
38
+ │ └── verify-telegram-data.post.ts # Telegram data verification
39
+ ├── public/ # Static public assets
40
+ │ ├── _redirects # Netlify redirects
41
+ │ ├── robots.txt # SEO robots file
42
+ │ └── img/ # Images
43
+ ├── tests/ # Test files
44
+ │ ├── telegram.spec.ts # Telegram composables tests
45
+ │ ├── components.spec.ts # Component unit tests
46
+ │ └── pages.spec.ts # Page integration tests
47
+ ├── nuxt.config.ts # Nuxt configuration
48
+ ├── tailwind.config.ts # Tailwind CSS configuration
49
+ ├── vitest.config.ts # Vitest testing configuration
50
+ └── netlify.toml # Netlify deployment configuration
51
+ ```
52
+
53
+ ## 🧩 Component Architecture
54
+
55
+ ### Telegram Components (`app/components/tg/`)
56
+
57
+ All Telegram-specific components follow a consistent API pattern:
58
+
59
+ #### TgButton
60
+ - **Purpose**: Telegram-styled buttons with haptic feedback
61
+ - **Props**: `title`, `status`, `haptic`, `disabled`, `loading`, `shareUrl`
62
+ - **Events**: `click`
63
+ - **Usage**: Interactive buttons throughout the app
64
+
65
+ #### TgCell
66
+ - **Purpose**: List item cells with consistent styling
67
+ - **Props**: `title`, `subtitle`, `description`, `icon`, `to`, `border`
68
+ - **Events**: `click`
69
+ - **Usage**: Navigation items, settings, content lists
70
+
71
+ #### TgSection
72
+ - **Purpose**: Content grouping with proper spacing
73
+ - **Props**: `title`, `inset`
74
+ - **Usage**: Organizing content into logical sections
75
+
76
+ #### TgContent
77
+ - **Purpose**: Main content wrapper with safe areas
78
+ - **Usage**: Primary content container for all pages
79
+
80
+ #### TgNav
81
+ - **Purpose**: Bottom navigation bar
82
+ - **Props**: `modelValue`, `items`
83
+ - **Events**: `select`, `update:modelValue`
84
+ - **Usage**: App navigation
85
+
86
+ ### Design Principles
87
+
88
+ 1. **Telegram Native Feel**: All components match Telegram's design language
89
+ 2. **Accessibility**: Proper ARIA labels and keyboard navigation
90
+ 3. **Responsive**: Works on all device sizes
91
+ 4. **Theme Aware**: Automatically adapts to Telegram's theme
92
+ 5. **Type Safe**: Full TypeScript support
93
+
94
+ ## 🔧 Telegram SDK Integration
95
+
96
+ ### Composables Architecture
97
+
98
+ The `app/composables/telegram.ts` file provides Vue composables for all Telegram WebApp features:
99
+
100
+ #### Core Composables
101
+
102
+ ```typescript
103
+ // Main WebApp instance
104
+ useTelegramWebApp()
105
+
106
+ // Navigation
107
+ useBackButton()
108
+ useMainButton()
109
+
110
+ // User interaction
111
+ useHapticFeedback()
112
+
113
+ // Data access
114
+ useInitData()
115
+ useThemeParams()
116
+
117
+ // App control
118
+ useMiniApp()
119
+ useViewport()
120
+ ```
121
+
122
+ #### Usage Pattern
123
+
124
+ ```vue
125
+ <script setup lang="ts">
126
+ import { useMainButton, useHapticFeedback } from '~/composables/telegram'
127
+
128
+ const main = useMainButton()
129
+ const haptic = useHapticFeedback()
130
+
131
+ onMounted(() => {
132
+ // Configure main button
133
+ main.mount()
134
+ main.setParams({
135
+ is_visible: true,
136
+ is_active: true,
137
+ text: 'My Action'
138
+ })
139
+
140
+ // Handle click
141
+ const off = main.onClick(() => {
142
+ haptic.impactOccurred('medium')
143
+ // Your action here
144
+ })
145
+
146
+ // Cleanup
147
+ onBeforeUnmount(() => off?.())
148
+ })
149
+ </script>
150
+ ```
151
+
152
+ ## 🎨 Styling System
153
+
154
+ ### Tailwind Integration
155
+
156
+ The project uses Tailwind CSS with custom Telegram theme integration:
157
+
158
+ #### Theme Variables
159
+
160
+ ```css
161
+ /* app/assets/css/main.css */
162
+ :root {
163
+ --tg-theme-bg-color: #ffffff;
164
+ --tg-theme-text-color: #000000;
165
+ --tg-theme-hint-color: #999999;
166
+ /* ... more theme variables */
167
+ }
168
+ ```
169
+
170
+ #### Custom Tailwind Classes
171
+
172
+ ```css
173
+ /* Telegram-specific utilities */
174
+ .bg-tg-bg { @apply bg-[var(--tg-theme-bg-color)]; }
175
+ .text-tg { @apply text-[var(--tg-theme-text-color)]; }
176
+ .text-hint { @apply text-[var(--tg-theme-hint-color)]; }
177
+ ```
178
+
179
+ #### Component Styling Patterns
180
+
181
+ 1. Use Telegram theme variables for colors
182
+ 2. Follow mobile-first responsive design
183
+ 3. Ensure proper touch targets (44px minimum)
184
+ 4. Use consistent spacing scale
185
+
186
+ ## 📱 Page Structure
187
+
188
+ ### Standard Page Template
189
+
190
+ ```vue
191
+ <template>
192
+ <TgContent>
193
+ <Hero
194
+ title="Page Title"
195
+ subtitle="Page description"
196
+ image-src="/img/hero-image.svg"
197
+ />
198
+
199
+ <TgSection title="Section Title" inset>
200
+ <!-- Section content -->
201
+ </TgSection>
202
+
203
+ <div class="h-2" /> <!-- Bottom spacing -->
204
+ </TgContent>
205
+
206
+ <TgNav v-model="activeTab" :items="navItems" @select="onSelectTab" />
207
+ </template>
208
+
209
+ <script setup lang="ts">
210
+ import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
211
+ import { useRouter } from 'vue-router'
212
+ import { useMainButton } from '~/composables/telegram'
213
+
214
+ const router = useRouter()
215
+ const main = useMainButton()
216
+
217
+ // Navigation setup
218
+ const activeTab = ref('current-page')
219
+ const navItems = [
220
+ { key: 'home', label: 'Home', icon: 'i-heroicons-home-20-solid', to: '/' },
221
+ // ... other nav items
222
+ ]
223
+
224
+ function onSelectTab(item: NavItem) {
225
+ if (item.to) router.push(item.to)
226
+ }
227
+
228
+ // Main button setup
229
+ onMounted(() => {
230
+ main.mount()
231
+ main.setParams({ is_visible: true, text: 'Action' })
232
+
233
+ const off = main.onClick(() => {
234
+ // Action handler
235
+ })
236
+
237
+ onBeforeUnmount(() => off?.())
238
+ })
239
+ </script>
240
+ ```
241
+
242
+ ## 🧪 Testing Strategy
243
+
244
+ ### Test Structure
245
+
246
+ 1. **Unit Tests** (`*.spec.ts`): Individual component and function testing
247
+ 2. **Integration Tests**: Page-level functionality testing
248
+ 3. **E2E Tests**: Full user journey testing (to be implemented)
249
+
250
+ ### Testing Utilities
251
+
252
+ - **Vitest**: Fast unit test runner
253
+ - **Vue Test Utils**: Vue component testing
254
+ - **Happy DOM**: Lightweight DOM implementation
255
+ - **Mock System**: Comprehensive Telegram API mocking
256
+
257
+ ### Writing Tests
258
+
259
+ ```typescript
260
+ // Component test example
261
+ import { mount } from '@vue/test-utils'
262
+
263
+ describe('TgButton', () => {
264
+ it('renders with correct props', () => {
265
+ const wrapper = mount(TgButton, {
266
+ props: { title: 'Test Button', status: 'primary' }
267
+ })
268
+
269
+ expect(wrapper.text()).toBe('Test Button')
270
+ expect(wrapper.classes()).toContain('tg-button--primary')
271
+ })
272
+ })
273
+ ```
274
+
275
+ ## 🚀 Development Workflow
276
+
277
+ ### Getting Started
278
+
279
+ 1. **Clone and install**:
280
+ ```bash
281
+ git clone <your-repo>
282
+ cd nuxt-telegram-mini-app
283
+ npm install
284
+ ```
285
+
286
+ 2. **Start development**:
287
+ ```bash
288
+ npm run dev
289
+ ```
290
+
291
+ 3. **Run tests**:
292
+ ```bash
293
+ npm run test
294
+ npm run test:watch
295
+ ```
296
+
297
+ ### Adding New Features
298
+
299
+ #### 1. Adding a New Page
300
+
301
+ 1. Create `app/pages/new-page.vue`
302
+ 2. Follow the standard page template
303
+ 3. Add to navigation items in other pages
304
+ 4. Write integration tests
305
+
306
+ #### 2. Adding a New Component
307
+
308
+ 1. Create component in appropriate directory
309
+ 2. Follow TypeScript prop definitions
310
+ 3. Add proper styling with Tailwind
311
+ 4. Write unit tests
312
+ 5. Document props and usage
313
+
314
+ #### 3. Adding Telegram Features
315
+
316
+ 1. Extend composables in `app/composables/telegram.ts`
317
+ 2. Follow existing patterns for error handling
318
+ 3. Add TypeScript types if needed
319
+ 4. Test with actual Telegram WebApp
320
+ 5. Add mock implementations for tests
321
+
322
+ ### Code Style Guidelines
323
+
324
+ 1. **TypeScript**: Use strict typing, avoid `any`
325
+ 2. **Vue 3**: Use Composition API with `<script setup>`
326
+ 3. **Formatting**: Use ESLint
327
+ 4. **Naming**: Use descriptive names, follow Vue conventions
328
+ 5. **Comments**: Document complex logic and Telegram-specific behavior
329
+
330
+ ### Git Workflow
331
+
332
+ 1. **Branch naming**: `feature/description`, `fix/description`, `docs/description`
333
+ 2. **Commits**: Use conventional commits format
334
+ 3. **PRs**: Include description, screenshots for UI changes
335
+ 4. **Reviews**: All changes require review for template updates
336
+
337
+ ## 📦 Deployment
338
+
339
+ ### Netlify Deployment
340
+
341
+ The template is configured for zero-config Netlify deployment:
342
+
343
+ 1. **Build settings** are in `netlify.toml`
344
+ 2. **Functions** are in `netlify/functions/`
345
+ 3. **Redirects** are in `public/_redirects`
346
+
347
+ ### Manual Deployment
348
+
349
+ 1. Build the project: `npm run generate`
350
+ 2. Deploy the `dist` folder to your hosting provider
351
+ 3. Configure redirects for SPA routing
352
+
353
+ ### Environment Variables
354
+
355
+ - `ENV`: Set to `production` for production builds
356
+ - Add others as needed for your specific implementation
357
+
358
+ ## 🤝 Contributing Process
359
+
360
+ 1. **Fork** the repository
361
+ 2. **Create** a feature branch from `main`
362
+ 3. **Make** your changes following the guidelines
363
+ 4. **Test** your changes thoroughly
364
+ 5. **Update** documentation if needed
365
+ 6. **Submit** a pull request with clear description
366
+
367
+ ### Pull Request Template
368
+
369
+ ```markdown
370
+ ## Description
371
+ Brief description of changes
372
+
373
+ ## Type of Change
374
+ - [ ] Bug fix
375
+ - [ ] New feature
376
+ - [ ] Documentation update
377
+ - [ ] Refactoring
378
+
379
+ ## Testing
380
+ - [ ] Unit tests pass
381
+ - [ ] Manual testing completed
382
+ - [ ] Telegram WebApp tested (if applicable)
383
+
384
+ ## Screenshots
385
+ Include screenshots for UI changes
386
+ ```
387
+
388
+ ## 🆘 Troubleshooting
389
+
390
+ ### Common Issues
391
+
392
+ 1. **TypeScript Errors**: Check import paths and type definitions
393
+ 2. **Telegram SDK**: Ensure you're testing in actual Telegram context
394
+ 3. **Styling Issues**: Verify Tailwind classes and theme variables
395
+ 4. **Build Errors**: Check Node.js version and dependencies
396
+
397
+ ### Getting Help
398
+
399
+ - Check existing issues on GitHub
400
+ - Read Telegram Mini Apps documentation
401
+ - Ask questions in GitHub Discussions
402
+ - Review test files for usage examples
403
+
404
+ ---
405
+
406
+ **Happy coding! 🚀**
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Patrick Tobias
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.