create-react-native-airborne 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 (78) hide show
  1. package/README.md +24 -0
  2. package/package.json +21 -0
  3. package/src/index.mjs +103 -0
  4. package/template/.agents/skills/convex-best-practices/SKILL.md +333 -0
  5. package/template/.agents/skills/convex-file-storage/SKILL.md +466 -0
  6. package/template/.agents/skills/convex-security-audit/SKILL.md +538 -0
  7. package/template/.agents/skills/convex-security-check/SKILL.md +377 -0
  8. package/template/.github/workflows/ci.yml +130 -0
  9. package/template/.prettierignore +8 -0
  10. package/template/.prettierrc.json +6 -0
  11. package/template/AGENTS.md +156 -0
  12. package/template/Justfile +48 -0
  13. package/template/README.md +94 -0
  14. package/template/client/.env.example +3 -0
  15. package/template/client/.vscode/extensions.json +1 -0
  16. package/template/client/.vscode/settings.json +7 -0
  17. package/template/client/README.md +33 -0
  18. package/template/client/app/(app)/_layout.tsx +34 -0
  19. package/template/client/app/(app)/index.tsx +66 -0
  20. package/template/client/app/(app)/push.tsx +75 -0
  21. package/template/client/app/(app)/settings.tsx +36 -0
  22. package/template/client/app/(auth)/_layout.tsx +22 -0
  23. package/template/client/app/(auth)/sign-in.tsx +358 -0
  24. package/template/client/app/(auth)/sign-up.tsx +237 -0
  25. package/template/client/app/_layout.tsx +30 -0
  26. package/template/client/app/index.tsx +127 -0
  27. package/template/client/app.config.ts +30 -0
  28. package/template/client/assets/images/android-icon-background.png +0 -0
  29. package/template/client/assets/images/android-icon-foreground.png +0 -0
  30. package/template/client/assets/images/android-icon-monochrome.png +0 -0
  31. package/template/client/assets/images/favicon.png +0 -0
  32. package/template/client/assets/images/icon.png +0 -0
  33. package/template/client/assets/images/partial-react-logo.png +0 -0
  34. package/template/client/assets/images/react-logo.png +0 -0
  35. package/template/client/assets/images/react-logo@2x.png +0 -0
  36. package/template/client/assets/images/react-logo@3x.png +0 -0
  37. package/template/client/assets/images/splash-icon.png +0 -0
  38. package/template/client/eslint.config.js +10 -0
  39. package/template/client/global.css +2 -0
  40. package/template/client/metro.config.js +9 -0
  41. package/template/client/package.json +51 -0
  42. package/template/client/src/components/auth-shell.tsx +63 -0
  43. package/template/client/src/components/form-input.tsx +62 -0
  44. package/template/client/src/components/primary-button.tsx +37 -0
  45. package/template/client/src/components/screen.tsx +17 -0
  46. package/template/client/src/components/sign-out-button.tsx +32 -0
  47. package/template/client/src/hooks/use-theme-sync.ts +11 -0
  48. package/template/client/src/lib/convex.ts +6 -0
  49. package/template/client/src/lib/env-schema.ts +13 -0
  50. package/template/client/src/lib/env.test.ts +24 -0
  51. package/template/client/src/lib/env.ts +19 -0
  52. package/template/client/src/lib/notifications.ts +47 -0
  53. package/template/client/src/store/preferences-store.ts +42 -0
  54. package/template/client/src/types/theme.ts +1 -0
  55. package/template/client/tsconfig.json +18 -0
  56. package/template/client/uniwind-types.d.ts +10 -0
  57. package/template/client/vitest.config.ts +7 -0
  58. package/template/package.json +22 -0
  59. package/template/server/.env.example +8 -0
  60. package/template/server/README.md +31 -0
  61. package/template/server/convex/_generated/api.d.ts +55 -0
  62. package/template/server/convex/_generated/api.js +23 -0
  63. package/template/server/convex/_generated/dataModel.d.ts +60 -0
  64. package/template/server/convex/_generated/server.d.ts +143 -0
  65. package/template/server/convex/_generated/server.js +93 -0
  66. package/template/server/convex/auth.config.ts +11 -0
  67. package/template/server/convex/env.ts +18 -0
  68. package/template/server/convex/lib.ts +12 -0
  69. package/template/server/convex/push.ts +148 -0
  70. package/template/server/convex/schema.ts +22 -0
  71. package/template/server/convex/users.ts +54 -0
  72. package/template/server/convex.json +3 -0
  73. package/template/server/eslint.config.js +51 -0
  74. package/template/server/package.json +29 -0
  75. package/template/server/tests/convex.test.ts +52 -0
  76. package/template/server/tests/import-meta.d.ts +3 -0
  77. package/template/server/tsconfig.json +15 -0
  78. package/template/server/vitest.config.ts +13 -0
@@ -0,0 +1,466 @@
1
+ ---
2
+ name: Convex File Storage
3
+ description: Complete file handling including upload flows, serving files via URL, storing generated files from actions, deletion, and accessing file metadata from system tables
4
+ version: 1.0.0
5
+ author: Convex
6
+ tags: [convex, file-storage, uploads, images, files]
7
+ ---
8
+
9
+ # Convex File Storage
10
+
11
+ Handle file uploads, storage, serving, and management in Convex applications with proper patterns for images, documents, and generated files.
12
+
13
+ ## Documentation Sources
14
+
15
+ Before implementing, do not assume; fetch the latest documentation:
16
+
17
+ - Primary: https://docs.convex.dev/file-storage
18
+ - Upload Files: https://docs.convex.dev/file-storage/upload-files
19
+ - Serve Files: https://docs.convex.dev/file-storage/serve-files
20
+ - For broader context: https://docs.convex.dev/llms.txt
21
+
22
+ ## Instructions
23
+
24
+ ### File Storage Overview
25
+
26
+ Convex provides built-in file storage with:
27
+ - Automatic URL generation for serving files
28
+ - Support for any file type (images, PDFs, videos, etc.)
29
+ - File metadata via the `_storage` system table
30
+ - Integration with mutations and actions
31
+
32
+ ### Generating Upload URLs
33
+
34
+ ```typescript
35
+ // convex/files.ts
36
+ import { mutation } from "./_generated/server";
37
+ import { v } from "convex/values";
38
+
39
+ export const generateUploadUrl = mutation({
40
+ args: {},
41
+ returns: v.string(),
42
+ handler: async (ctx) => {
43
+ return await ctx.storage.generateUploadUrl();
44
+ },
45
+ });
46
+ ```
47
+
48
+ ### Client-Side Upload
49
+
50
+ ```typescript
51
+ // React component
52
+ import { useMutation } from "convex/react";
53
+ import { api } from "../convex/_generated/api";
54
+ import { useState } from "react";
55
+
56
+ function FileUploader() {
57
+ const generateUploadUrl = useMutation(api.files.generateUploadUrl);
58
+ const saveFile = useMutation(api.files.saveFile);
59
+ const [uploading, setUploading] = useState(false);
60
+
61
+ const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
62
+ const file = e.target.files?.[0];
63
+ if (!file) return;
64
+
65
+ setUploading(true);
66
+ try {
67
+ // Step 1: Get upload URL
68
+ const uploadUrl = await generateUploadUrl();
69
+
70
+ // Step 2: Upload file to storage
71
+ const result = await fetch(uploadUrl, {
72
+ method: "POST",
73
+ headers: { "Content-Type": file.type },
74
+ body: file,
75
+ });
76
+
77
+ const { storageId } = await result.json();
78
+
79
+ // Step 3: Save file reference to database
80
+ await saveFile({
81
+ storageId,
82
+ fileName: file.name,
83
+ fileType: file.type,
84
+ fileSize: file.size,
85
+ });
86
+ } finally {
87
+ setUploading(false);
88
+ }
89
+ };
90
+
91
+ return (
92
+ <div>
93
+ <input
94
+ type="file"
95
+ onChange={handleUpload}
96
+ disabled={uploading}
97
+ />
98
+ {uploading && <p>Uploading...</p>}
99
+ </div>
100
+ );
101
+ }
102
+ ```
103
+
104
+ ### Saving File References
105
+
106
+ ```typescript
107
+ // convex/files.ts
108
+ import { mutation, query } from "./_generated/server";
109
+ import { v } from "convex/values";
110
+
111
+ export const saveFile = mutation({
112
+ args: {
113
+ storageId: v.id("_storage"),
114
+ fileName: v.string(),
115
+ fileType: v.string(),
116
+ fileSize: v.number(),
117
+ },
118
+ returns: v.id("files"),
119
+ handler: async (ctx, args) => {
120
+ return await ctx.db.insert("files", {
121
+ storageId: args.storageId,
122
+ fileName: args.fileName,
123
+ fileType: args.fileType,
124
+ fileSize: args.fileSize,
125
+ uploadedAt: Date.now(),
126
+ });
127
+ },
128
+ });
129
+ ```
130
+
131
+ ### Serving Files via URL
132
+
133
+ ```typescript
134
+ // convex/files.ts
135
+ export const getFileUrl = query({
136
+ args: { storageId: v.id("_storage") },
137
+ returns: v.union(v.string(), v.null()),
138
+ handler: async (ctx, args) => {
139
+ return await ctx.storage.getUrl(args.storageId);
140
+ },
141
+ });
142
+
143
+ // Get file with URL
144
+ export const getFile = query({
145
+ args: { fileId: v.id("files") },
146
+ returns: v.union(
147
+ v.object({
148
+ _id: v.id("files"),
149
+ fileName: v.string(),
150
+ fileType: v.string(),
151
+ fileSize: v.number(),
152
+ url: v.union(v.string(), v.null()),
153
+ }),
154
+ v.null()
155
+ ),
156
+ handler: async (ctx, args) => {
157
+ const file = await ctx.db.get(args.fileId);
158
+ if (!file) return null;
159
+
160
+ const url = await ctx.storage.getUrl(file.storageId);
161
+
162
+ return {
163
+ _id: file._id,
164
+ fileName: file.fileName,
165
+ fileType: file.fileType,
166
+ fileSize: file.fileSize,
167
+ url,
168
+ };
169
+ },
170
+ });
171
+ ```
172
+
173
+ ### Displaying Files in React
174
+
175
+ ```typescript
176
+ import { useQuery } from "convex/react";
177
+ import { api } from "../convex/_generated/api";
178
+
179
+ function FileDisplay({ fileId }: { fileId: Id<"files"> }) {
180
+ const file = useQuery(api.files.getFile, { fileId });
181
+
182
+ if (!file) return <div>Loading...</div>;
183
+ if (!file.url) return <div>File not found</div>;
184
+
185
+ // Handle different file types
186
+ if (file.fileType.startsWith("image/")) {
187
+ return <img src={file.url} alt={file.fileName} />;
188
+ }
189
+
190
+ if (file.fileType === "application/pdf") {
191
+ return (
192
+ <iframe
193
+ src={file.url}
194
+ title={file.fileName}
195
+ width="100%"
196
+ height="600px"
197
+ />
198
+ );
199
+ }
200
+
201
+ return (
202
+ <a href={file.url} download={file.fileName}>
203
+ Download {file.fileName}
204
+ </a>
205
+ );
206
+ }
207
+ ```
208
+
209
+ ### Storing Generated Files from Actions
210
+
211
+ ```typescript
212
+ // convex/generate.ts
213
+ "use node";
214
+
215
+ import { action } from "./_generated/server";
216
+ import { v } from "convex/values";
217
+ import { api } from "./_generated/api";
218
+
219
+ export const generatePDF = action({
220
+ args: { content: v.string() },
221
+ returns: v.id("_storage"),
222
+ handler: async (ctx, args) => {
223
+ // Generate PDF (example using a library)
224
+ const pdfBuffer = await generatePDFFromContent(args.content);
225
+
226
+ // Convert to Blob
227
+ const blob = new Blob([pdfBuffer], { type: "application/pdf" });
228
+
229
+ // Store in Convex
230
+ const storageId = await ctx.storage.store(blob);
231
+
232
+ return storageId;
233
+ },
234
+ });
235
+
236
+ // Generate and save image
237
+ export const generateImage = action({
238
+ args: { prompt: v.string() },
239
+ returns: v.id("_storage"),
240
+ handler: async (ctx, args) => {
241
+ // Call external API to generate image
242
+ const response = await fetch("https://api.example.com/generate", {
243
+ method: "POST",
244
+ body: JSON.stringify({ prompt: args.prompt }),
245
+ });
246
+
247
+ const imageBuffer = await response.arrayBuffer();
248
+ const blob = new Blob([imageBuffer], { type: "image/png" });
249
+
250
+ return await ctx.storage.store(blob);
251
+ },
252
+ });
253
+ ```
254
+
255
+ ### Accessing File Metadata
256
+
257
+ ```typescript
258
+ // convex/files.ts
259
+ import { query } from "./_generated/server";
260
+ import { v } from "convex/values";
261
+ import { Id } from "./_generated/dataModel";
262
+
263
+ type FileMetadata = {
264
+ _id: Id<"_storage">;
265
+ _creationTime: number;
266
+ contentType?: string;
267
+ sha256: string;
268
+ size: number;
269
+ };
270
+
271
+ export const getFileMetadata = query({
272
+ args: { storageId: v.id("_storage") },
273
+ returns: v.union(
274
+ v.object({
275
+ _id: v.id("_storage"),
276
+ _creationTime: v.number(),
277
+ contentType: v.optional(v.string()),
278
+ sha256: v.string(),
279
+ size: v.number(),
280
+ }),
281
+ v.null()
282
+ ),
283
+ handler: async (ctx, args) => {
284
+ const metadata = await ctx.db.system.get(args.storageId);
285
+ return metadata as FileMetadata | null;
286
+ },
287
+ });
288
+ ```
289
+
290
+ ### Deleting Files
291
+
292
+ ```typescript
293
+ // convex/files.ts
294
+ import { mutation } from "./_generated/server";
295
+ import { v } from "convex/values";
296
+
297
+ export const deleteFile = mutation({
298
+ args: { fileId: v.id("files") },
299
+ returns: v.null(),
300
+ handler: async (ctx, args) => {
301
+ const file = await ctx.db.get(args.fileId);
302
+ if (!file) return null;
303
+
304
+ // Delete from storage
305
+ await ctx.storage.delete(file.storageId);
306
+
307
+ // Delete database record
308
+ await ctx.db.delete(args.fileId);
309
+
310
+ return null;
311
+ },
312
+ });
313
+ ```
314
+
315
+ ### Image Upload with Preview
316
+
317
+ ```typescript
318
+ import { useMutation } from "convex/react";
319
+ import { api } from "../convex/_generated/api";
320
+ import { useState, useRef } from "react";
321
+
322
+ function ImageUploader({ onUpload }: { onUpload: (id: Id<"files">) => void }) {
323
+ const generateUploadUrl = useMutation(api.files.generateUploadUrl);
324
+ const saveFile = useMutation(api.files.saveFile);
325
+ const [preview, setPreview] = useState<string | null>(null);
326
+ const [uploading, setUploading] = useState(false);
327
+ const inputRef = useRef<HTMLInputElement>(null);
328
+
329
+ const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
330
+ const file = e.target.files?.[0];
331
+ if (!file) return;
332
+
333
+ // Validate file type
334
+ if (!file.type.startsWith("image/")) {
335
+ alert("Please select an image file");
336
+ return;
337
+ }
338
+
339
+ // Validate file size (max 10MB)
340
+ if (file.size > 10 * 1024 * 1024) {
341
+ alert("File size must be less than 10MB");
342
+ return;
343
+ }
344
+
345
+ // Show preview
346
+ const reader = new FileReader();
347
+ reader.onload = (e) => setPreview(e.target?.result as string);
348
+ reader.readAsDataURL(file);
349
+
350
+ // Upload
351
+ setUploading(true);
352
+ try {
353
+ const uploadUrl = await generateUploadUrl();
354
+ const result = await fetch(uploadUrl, {
355
+ method: "POST",
356
+ headers: { "Content-Type": file.type },
357
+ body: file,
358
+ });
359
+
360
+ const { storageId } = await result.json();
361
+ const fileId = await saveFile({
362
+ storageId,
363
+ fileName: file.name,
364
+ fileType: file.type,
365
+ fileSize: file.size,
366
+ });
367
+
368
+ onUpload(fileId);
369
+ } finally {
370
+ setUploading(false);
371
+ }
372
+ };
373
+
374
+ return (
375
+ <div>
376
+ <input
377
+ ref={inputRef}
378
+ type="file"
379
+ accept="image/*"
380
+ onChange={handleFileSelect}
381
+ style={{ display: "none" }}
382
+ />
383
+
384
+ <button
385
+ onClick={() => inputRef.current?.click()}
386
+ disabled={uploading}
387
+ >
388
+ {uploading ? "Uploading..." : "Select Image"}
389
+ </button>
390
+
391
+ {preview && (
392
+ <img
393
+ src={preview}
394
+ alt="Preview"
395
+ style={{ maxWidth: 200, marginTop: 10 }}
396
+ />
397
+ )}
398
+ </div>
399
+ );
400
+ }
401
+ ```
402
+
403
+ ## Examples
404
+
405
+ ### Schema for File Storage
406
+
407
+ ```typescript
408
+ // convex/schema.ts
409
+ import { defineSchema, defineTable } from "convex/server";
410
+ import { v } from "convex/values";
411
+
412
+ export default defineSchema({
413
+ files: defineTable({
414
+ storageId: v.id("_storage"),
415
+ fileName: v.string(),
416
+ fileType: v.string(),
417
+ fileSize: v.number(),
418
+ uploadedBy: v.id("users"),
419
+ uploadedAt: v.number(),
420
+ })
421
+ .index("by_user", ["uploadedBy"])
422
+ .index("by_type", ["fileType"]),
423
+
424
+ // User avatars
425
+ users: defineTable({
426
+ name: v.string(),
427
+ email: v.string(),
428
+ avatarStorageId: v.optional(v.id("_storage")),
429
+ }),
430
+
431
+ // Posts with images
432
+ posts: defineTable({
433
+ authorId: v.id("users"),
434
+ content: v.string(),
435
+ imageStorageIds: v.array(v.id("_storage")),
436
+ createdAt: v.number(),
437
+ }).index("by_author", ["authorId"]),
438
+ });
439
+ ```
440
+
441
+ ## Best Practices
442
+
443
+ - Never run `npx convex deploy` unless explicitly instructed
444
+ - Never run any git commands unless explicitly instructed
445
+ - Validate file types and sizes on the client before uploading
446
+ - Store file metadata (name, type, size) in your own table
447
+ - Use the `_storage` system table only for Convex metadata
448
+ - Delete storage files when deleting database references
449
+ - Use appropriate Content-Type headers when uploading
450
+ - Consider image optimization for large images
451
+
452
+ ## Common Pitfalls
453
+
454
+ 1. **Not setting Content-Type header** - Files may not serve correctly
455
+ 2. **Forgetting to delete storage** - Orphaned files waste storage
456
+ 3. **Not validating file types** - Security risk for malicious uploads
457
+ 4. **Large file uploads without progress** - Poor UX for users
458
+ 5. **Using deprecated getMetadata** - Use ctx.db.system.get instead
459
+
460
+ ## References
461
+
462
+ - Convex Documentation: https://docs.convex.dev/
463
+ - Convex LLMs.txt: https://docs.convex.dev/llms.txt
464
+ - File Storage: https://docs.convex.dev/file-storage
465
+ - Upload Files: https://docs.convex.dev/file-storage/upload-files
466
+ - Serve Files: https://docs.convex.dev/file-storage/serve-files