@donotdev/firebase 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 (51) hide show
  1. package/LICENSE.md +242 -0
  2. package/README.md +386 -0
  3. package/dist/client/firestore.d.ts +147 -0
  4. package/dist/client/firestore.d.ts.map +1 -0
  5. package/dist/client/firestore.js +1 -0
  6. package/dist/client/functions.d.ts +28 -0
  7. package/dist/client/functions.d.ts.map +1 -0
  8. package/dist/client/functions.js +1 -0
  9. package/dist/client/index.d.ts +11 -0
  10. package/dist/client/index.d.ts.map +1 -0
  11. package/dist/client/index.js +1 -0
  12. package/dist/client/sdk.d.ts +968 -0
  13. package/dist/client/sdk.d.ts.map +1 -0
  14. package/dist/client/sdk.js +21 -0
  15. package/dist/index.d.ts +9 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/server/batch.d.ts +97 -0
  19. package/dist/server/batch.d.ts.map +1 -0
  20. package/dist/server/batch.js +1 -0
  21. package/dist/server/index.d.ts +15 -0
  22. package/dist/server/index.d.ts.map +1 -0
  23. package/dist/server/index.js +1 -0
  24. package/dist/server/init.d.ts +13 -0
  25. package/dist/server/init.d.ts.map +1 -0
  26. package/dist/server/init.js +2 -0
  27. package/dist/server/subscription.d.ts +117 -0
  28. package/dist/server/subscription.d.ts.map +1 -0
  29. package/dist/server/subscription.js +1 -0
  30. package/dist/server/uniqueness.d.ts +69 -0
  31. package/dist/server/uniqueness.d.ts.map +1 -0
  32. package/dist/server/uniqueness.js +1 -0
  33. package/dist/server/utils.d.ts +28 -0
  34. package/dist/server/utils.d.ts.map +1 -0
  35. package/dist/server/utils.js +1 -0
  36. package/dist/server/validation.d.ts +43 -0
  37. package/dist/server/validation.d.ts.map +1 -0
  38. package/dist/server/validation.js +1 -0
  39. package/dist/shared/index.d.ts +11 -0
  40. package/dist/shared/index.d.ts.map +1 -0
  41. package/dist/shared/index.js +1 -0
  42. package/dist/shared/transform.d.ts +96 -0
  43. package/dist/shared/transform.d.ts.map +1 -0
  44. package/dist/shared/transform.js +1 -0
  45. package/dist/shared/types.d.ts +37 -0
  46. package/dist/shared/types.d.ts.map +1 -0
  47. package/dist/shared/types.js +0 -0
  48. package/dist/shared/utils.d.ts +71 -0
  49. package/dist/shared/utils.d.ts.map +1 -0
  50. package/dist/shared/utils.js +1 -0
  51. package/package.json +50 -0
package/LICENSE.md ADDED
@@ -0,0 +1,242 @@
1
+ # DoNotDev Framework License Agreement
2
+
3
+ **Version 1.0 – Effective Date: May 5, 2025**
4
+
5
+ Copyright © 2025 Ambroise Park Consulting. All rights reserved.
6
+
7
+ ---
8
+
9
+ ## 1. DEFINITIONS
10
+
11
+ **1.1 "Framework"** means the DoNotDev commercial software packages (excluding @donotdev/cli and @donotdev/components, which are free), including all compiled JavaScript files, TypeScript definition files, and associated documentation.
12
+
13
+ **1.2 "License Key"** means the unique alphanumeric key provided to you upon purchase, required to suppress watermarks and unlock full Framework functionality.
14
+
15
+ **1.3 "Developer License"** means a license granted to an individual developer, permitting use of the Framework subject to the terms herein.
16
+
17
+ **1.4 "Project Deployment License"** means a license required for each Client Project delivered by a Developer.
18
+
19
+ **1.5 "Client Project"** means any software application or website built using the Framework and delivered to a third party who compensated you (directly or indirectly) for its development. This includes:
20
+ - Code handoff (repository transfer, zip file delivery, etc.)
21
+ - Hosted applications where the client has access to source code (repository access, cPanel, FTP, etc.)
22
+ - Hosted applications operated on behalf of a paying client, regardless of code access
23
+
24
+ **1.6 "Internal Use"** means software applications built using the Framework for your own use or your employer's internal use, including SaaS products you own and operate where end-users have no access to Framework code.
25
+
26
+ ---
27
+
28
+ ## 2. LICENSE GRANT
29
+
30
+ **2.1 Developer License**
31
+
32
+ Subject to payment of applicable fees and compliance with this Agreement, Ambroise Park Consulting grants you a non-exclusive, non-transferable, perpetual license to:
33
+
34
+ (a) Install Framework packages from npm
35
+ (b) Use the Framework to develop software applications
36
+ (c) Deploy applications for Internal Use without additional fees
37
+ (d) Incorporate the Framework into applications as compiled/minified code
38
+
39
+ **2.2 Project Deployment License**
40
+
41
+ For each Client Project, you must obtain a Project Deployment License prior to delivery. Each Project Deployment License grants you the right to deliver one Client Project containing the Framework.
42
+
43
+ **2.3 Multi-Developer Projects**
44
+
45
+ When multiple developers collaborate on a project:
46
+ - Each developer must hold a Developer License with their own License Key
47
+ - Only one Project Deployment License is required per Client Project (regardless of team size)
48
+
49
+ ---
50
+
51
+ ## 3. LICENSE KEY REQUIREMENT
52
+
53
+ **3.1 License Key Activation**
54
+
55
+ Upon purchasing a Developer License or Project Deployment License, you will receive a License Key. You must configure your applications with this key:
56
+
57
+ ```javascript
58
+ // Environment variable (recommended)
59
+ DONOTDEV_LICENSE_KEY=your-license-key-here
60
+
61
+ // Or in code
62
+ globalThis.__DONOTDEV_LICENSE_KEY__ = 'your-license-key-here';
63
+ ```
64
+
65
+ **3.2 Watermark Enforcement**
66
+
67
+ Applications running without a valid License Key will display a watermark:
68
+ - "⚠️ Unlicensed DoNotDev Framework - Visit donotdev.com"
69
+ - Console warnings in development mode
70
+
71
+ **3.3 License Key Types**
72
+
73
+ - **Developer License Key:** For Internal Use and development
74
+ - **Project Deployment License Key:** For Client Project deployment (suppresses watermark in production)
75
+
76
+ **3.4 Key Management**
77
+
78
+ - Do not commit License Keys to public repositories
79
+ - Use environment variables or secure secret management for production deployments
80
+ - Each developer uses their own Developer License Key for development
81
+ - Project Deployment Keys are provisioned per client project
82
+
83
+ ---
84
+
85
+ ## 4. PERMITTED USES
86
+
87
+ You may:
88
+
89
+ (a) Build unlimited applications for Internal Use with a Developer License
90
+ (b) Develop SaaS products you own and operate (no Project Deployment License required if clients cannot access Framework code)
91
+ (c) Create internal tools for your organization
92
+ (d) Build applications that include the Framework as compiled dependencies
93
+ (e) Open-source applications built on top of the Framework (provided end-users obtain their own licenses to suppress watermarks)
94
+
95
+ ---
96
+
97
+ ## 5. RESTRICTIONS
98
+
99
+ You may not:
100
+
101
+ (a) Redistribute Framework packages independently of your applications
102
+ (b) Share, publish, or transfer your License Key to unlicensed parties
103
+ (c) Decompile, reverse engineer, or attempt to extract source code from minified files
104
+ (d) Remove or obscure copyright notices or watermarks from Framework code
105
+ (e) Sublicense, resell, or transfer your Developer License to another individual
106
+ (f) Deliver Client Projects without obtaining a Project Deployment License
107
+ (g) Modify Framework code to bypass license validation or watermark enforcement
108
+ (h) Create derivative frameworks intended for redistribution
109
+ (i) Use a single Project Deployment License for multiple client projects
110
+
111
+ ---
112
+
113
+ ## 6. LICENSE TYPES & FEES
114
+
115
+ **6.1 Developer License**
116
+ - **Scope:** Per individual developer
117
+ - **Term:** Perpetual (lifetime access)
118
+ - **Fee:** Set forth in purchase agreement or donotdev.com pricing
119
+ - **Entitlements:** Unlimited Internal Use projects; Client Projects require additional Project Deployment Licenses
120
+ - **License Key:** One Developer License Key provided
121
+
122
+ **6.2 Project Deployment License**
123
+ - **Scope:** Per Client Project delivered
124
+ - **Term:** Perpetual for the specific project
125
+ - **Fee:** Set forth in purchase agreement or donotdev.com pricing
126
+ - **Purchaser:** Typically purchased by the developer/agency; client payment arrangements are permitted
127
+ - **License Key:** One Project Deployment Key provided per project
128
+
129
+ **6.3 Volume Licensing**
130
+
131
+ Organizations requiring multiple Developer Licenses may contact Ambroise Park Consulting for volume pricing and enterprise key management.
132
+
133
+ ---
134
+
135
+ ## 7. PAYMENT & VERIFICATION
136
+
137
+ **7.1 Payment**
138
+
139
+ All fees must be paid in full before License Key issuance. Payment terms and pricing are specified at donotdev.com or in separate purchase agreements.
140
+
141
+ **7.2 Compliance Verification**
142
+
143
+ Ambroise Park Consulting may request reasonable verification of Project Deployment License compliance. You agree to cooperate with such verification requests in good faith.
144
+
145
+ **7.3 Enforcement**
146
+
147
+ License compliance is primarily honor-based. Watermarks serve as technical reminders. Ambroise Park Consulting reserves the right to audit usage and pursue legal remedies for material breaches.
148
+
149
+ ---
150
+
151
+ ## 8. TERM & TERMINATION
152
+
153
+ **8.1 Perpetual Term**
154
+
155
+ Developer Licenses and Project Deployment Licenses are perpetual and do not expire, subject to Section 8.2.
156
+
157
+ **8.2 Termination for Breach**
158
+
159
+ Ambroise Park Consulting may terminate your license(s) and revoke your License Key(s) if you:
160
+ - Breach any material term of this Agreement
161
+ - Fail to pay applicable fees
162
+ - Engage in unauthorized redistribution or License Key sharing
163
+ - Attempt to bypass license validation mechanisms
164
+
165
+ **8.3 Effect of Termination**
166
+
167
+ Upon termination:
168
+ - Your License Key(s) will be revoked and watermarks will reappear
169
+ - Your right to use the Framework ceases
170
+ - Previously deployed applications may continue to function but will display watermarks
171
+ - You must cease distribution of any Client Projects in development
172
+ - You must remove the Framework from any ongoing projects
173
+
174
+ **8.4 Survival**
175
+
176
+ Sections 5 (Restrictions), 9 (Warranty Disclaimer), 10 (Limitation of Liability), and 11 (General Provisions) survive termination.
177
+
178
+ ---
179
+
180
+ ## 9. WARRANTY DISCLAIMER
181
+
182
+ THE FRAMEWORK IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
183
+
184
+ Ambroise Park Consulting does not warrant that the Framework will be error-free, uninterrupted, or meet your specific requirements.
185
+
186
+ ---
187
+
188
+ ## 10. LIMITATION OF LIABILITY
189
+
190
+ TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL AMBROISE PARK CONSULTING BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES (INCLUDING LOSS OF PROFITS, DATA, OR BUSINESS OPPORTUNITIES) ARISING OUT OF OR RELATED TO THIS AGREEMENT OR USE OF THE FRAMEWORK, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
191
+
192
+ Ambroise Park Consulting's total cumulative liability under this Agreement shall not exceed the fees you paid for the specific license giving rise to the claim.
193
+
194
+ ---
195
+
196
+ ## 11. GENERAL PROVISIONS
197
+
198
+ **11.1 Governing Law**
199
+
200
+ This Agreement is governed by the laws of Quebec, Canada, without regard to conflict of law principles. Any disputes arising under this Agreement shall be resolved exclusively in the courts of Quebec, Canada.
201
+
202
+ **11.2 Severability**
203
+
204
+ If any provision of this Agreement is found unenforceable, the remaining provisions continue in full force and effect.
205
+
206
+ **11.3 Assignment**
207
+
208
+ You may not assign or transfer this Agreement or any licenses granted hereunder without prior written consent of Ambroise Park Consulting. Ambroise Park Consulting may assign this Agreement without restriction.
209
+
210
+ **11.4 Entire Agreement**
211
+
212
+ This Agreement, together with any applicable purchase agreements or order forms, constitutes the entire agreement between you and Ambroise Park Consulting regarding the Framework and supersedes all prior agreements and understandings.
213
+
214
+ **11.5 Amendments**
215
+
216
+ Ambroise Park Consulting may update this Agreement from time to time. Updates apply to licenses purchased after the effective date of the update. Existing licenses remain governed by the version in effect at the time of purchase unless you opt-in to updated terms.
217
+
218
+ **11.6 Export Compliance**
219
+
220
+ You agree to comply with all applicable export and import laws and regulations in your use of the Framework.
221
+
222
+ **11.7 Force Majeure**
223
+
224
+ Neither party is liable for failure to perform due to causes beyond reasonable control, including but not limited to acts of God, war, strikes, or third-party service outages.
225
+
226
+ **11.8 No Support Obligation**
227
+
228
+ Ambroise Park Consulting has no obligation to provide support, updates, or maintenance. Any support provided is at sole discretion and may be discontinued without notice.
229
+
230
+ **11.9 Contact**
231
+
232
+ Questions about licensing or compliance:
233
+
234
+ **Email:** mooti.web.app@gmail.com
235
+ **Website:** donotdev.com
236
+
237
+ ---
238
+
239
+ **END OF LICENSE AGREEMENT**
240
+
241
+ **DoNotDev Framework License v2.0**
242
+ Ambroise Park Consulting – 2025
package/README.md ADDED
@@ -0,0 +1,386 @@
1
+ # @donotdev/firebase
2
+
3
+ Firebase utilities for DoNotDev applications. This package provides a clean separation between client-safe and server-only Firebase functions.
4
+
5
+ ## Structure
6
+
7
+ This package is split into two main parts:
8
+
9
+ ### Client-Safe Exports (Default)
10
+
11
+ Import from the main package for client-safe functions:
12
+
13
+ ```typescript
14
+ import { initFirebase, getAuth } from '@donotdev/firebase';
15
+ import { getFirestore } from '@donotdev/firebase/server';
16
+ ```
17
+
18
+ **Available modules:**
19
+
20
+ - `auth.ts` - Authentication utilities
21
+ - `init.ts` - Firebase initialization
22
+ - `transform.ts` - Data transformation utilities
23
+ - `utils.ts` - Client-safe utility functions
24
+ - `validation.ts` - Client-safe validation functions
25
+ - `uniqueness.ts` - Uniqueness validation (client-safe functions only)
26
+
27
+ ### Server-Only Exports
28
+
29
+ Import from the server subpath for server-only functions:
30
+
31
+ ```typescript
32
+ import { batchWrite, getActiveSubscription } from '@donotdev/firebase/server';
33
+ ```
34
+
35
+ **Available modules:**
36
+
37
+ - `batch.ts` - Batch operations (create, update, delete)
38
+ - `subscription.ts` - Subscription management
39
+ - `server/utils.ts` - Server-only utilities
40
+ - `validation.ts` - Server-only validation functions
41
+ - `uniqueness.ts` - Server-only uniqueness functions
42
+
43
+ ## Features
44
+
45
+ - **Data Transformation**: Convert between Firestore and application formats
46
+ - **Uniqueness Validation**: Enforce field uniqueness constraints
47
+ - **Schema Validation**: Validate documents against schemas
48
+ - **Batch Operations**: Efficiently handle multiple document operations
49
+ - **Authentication**: Type-safe auth utilities with standard error handling
50
+ - **Initialization**: Simple configuration with environment variable support
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ bun add @donotdev/firebase
56
+ ```
57
+
58
+ ## Usage Examples
59
+
60
+ ### Client-Side (Browser/SSR)
61
+
62
+ ```typescript
63
+ import { initFirebase, getAuth } from '@donotdev/firebase';
64
+
65
+ // Initialize Firebase
66
+ const { app, auth } = initFirebase();
67
+
68
+ // Use client SDK
69
+ const user = auth?.currentUser;
70
+ ```
71
+
72
+ ### Server-Side (API Routes, Server Actions)
73
+
74
+ ```typescript
75
+ import { batchWrite, getActiveSubscription } from '@donotdev/firebase/server';
76
+
77
+ // Batch operations
78
+ const result = await batchWrite('users', users, 'create');
79
+
80
+ // Subscription management
81
+ const subscription = await getActiveSubscription(userId);
82
+ ```
83
+
84
+ ### Data Transformation
85
+
86
+ ```typescript
87
+ import {
88
+ transformFirestoreData,
89
+ prepareForFirestore,
90
+ } from '@donotdev/firebase';
91
+
92
+ // Convert Firestore Timestamps to ISO strings
93
+ const appData = transformFirestoreData(firestoreData);
94
+
95
+ // Convert ISO strings to Firestore Timestamps
96
+ const firestoreData = prepareForFirestore(appData);
97
+ ```
98
+
99
+ ### Schema Validation
100
+
101
+ ```typescript
102
+ import { enhanceSchema, validateCreate } from '@donotdev/firebase';
103
+ import * as v from 'valibot';
104
+
105
+ // Create a schema with uniqueness constraints
106
+ const userSchema = enhanceSchema(
107
+ v.object({
108
+ email: z.string().email(),
109
+ username: z.string().min(3),
110
+ createdAt: z.string().datetime(),
111
+ }),
112
+ {
113
+ collection: 'users',
114
+ uniqueFields: [
115
+ { field: 'email', errorMessage: 'Email is already in use' },
116
+ { field: 'username', errorMessage: 'Username is taken' },
117
+ ],
118
+ }
119
+ );
120
+
121
+ // Validate a document before saving
122
+ try {
123
+ await validateCreate(userSchema, userData);
124
+ // Document is valid, proceed with saving
125
+ } catch (error) {
126
+ // Handle validation errors
127
+ console.error('Validation failed:', error);
128
+ }
129
+ ```
130
+
131
+ ### Batch Operations
132
+
133
+ ```typescript
134
+ import { batchCreate, batchUpdate, batchDelete } from '@donotdev/firebase';
135
+
136
+ // Create multiple documents
137
+ const createResult = await batchCreate('products', products);
138
+ console.log(
139
+ `Created ${createResult.successes} products with ${createResult.failures} failures`
140
+ );
141
+
142
+ // Update multiple documents
143
+ const updateResult = await batchUpdate('products', updatedProducts);
144
+
145
+ // Delete multiple documents
146
+ const deleteResult = await batchDelete('products', productIds, {
147
+ idField: 'id',
148
+ });
149
+ ```
150
+
151
+ ### Authentication
152
+
153
+ The Firebase SDK automatically handles `authDomain` configuration using a dynamic approach:
154
+
155
+ - **Client-Side (CSR)**: Uses `window.location.hostname` for same-origin authentication
156
+ - **Server-Side (SSR)**: Uses `APP_URL` environment variable hostname
157
+ - **Localhost**: Falls back to `${projectId}.firebaseapp.com` for Firebase infrastructure
158
+
159
+ No manual `authDomain` configuration required - the SDK handles this automatically.
160
+
161
+ ```typescript
162
+ import {
163
+ signInWithEmail,
164
+ signInWithGoogle,
165
+ getCurrentUser,
166
+ signOut,
167
+ getIdToken,
168
+ } from '@donotdev/firebase';
169
+
170
+ // Sign in with email/password
171
+ const user = await signInWithEmail('user@example.com', 'password');
172
+
173
+ // Sign in with Google
174
+ const user = await signInWithGoogle();
175
+
176
+ // Get current user
177
+ const currentUser = getCurrentUser();
178
+
179
+ // Get authentication token
180
+ const token = await getIdToken();
181
+
182
+ // Sign out
183
+ await signOut();
184
+ ```
185
+
186
+ ### Initialization
187
+
188
+ ```typescript
189
+ import { initFirebase } from '@donotdev/firebase';
190
+
191
+ // Initialize Firebase from environment variables
192
+ const { app, auth, firestore } = initFirebase();
193
+
194
+ // Or with custom configuration
195
+ const { app, auth, firestore } = initFirebase({
196
+ apiKey: 'your-api-key',
197
+ authDomain: 'your-project.firebaseapp.com',
198
+ projectId: 'your-project-id',
199
+ // ...other config
200
+ });
201
+
202
+ // Use emulators for development
203
+ const { app, auth, firestore } = initFirebase(undefined, true);
204
+ ```
205
+
206
+ ## Key Benefits
207
+
208
+ 1. **No Client Bundling Issues**: Server-only functions are never bundled in client builds
209
+ 2. **Clear Separation**: Easy to understand what's safe for client vs server
210
+ 3. **Type Safety**: Full TypeScript support for both client and server functions
211
+ 4. **Framework Agnostic**: Works with Next.js, Vite, and other frameworks
212
+
213
+ ## Migration Guide
214
+
215
+ If you were previously importing server functions from the main package:
216
+
217
+ **Before:**
218
+
219
+ ```typescript
220
+ import { batchWrite } from '@donotdev/firebase';
221
+ ```
222
+
223
+ **After:**
224
+
225
+ ```typescript
226
+ import { batchWrite } from '@donotdev/firebase/server';
227
+ ```
228
+
229
+ ## Environment Variables
230
+
231
+ Required for client initialization:
232
+
233
+ - `VITE_FIREBASE_API_KEY`
234
+ - `VITE_FIREBASE_PROJECT_ID`
235
+
236
+ Optional:
237
+
238
+ - `VITE_FIREBASE_STORAGE_BUCKET`
239
+ - `VITE_FIREBASE_MESSAGING_SENDER_ID`
240
+ - `VITE_FIREBASE_APP_ID`
241
+ - `VITE_FIREBASE_MEASUREMENT_ID`
242
+
243
+ ## Demo Mode
244
+
245
+ The package includes a demo mode that activates when Firebase configuration is missing. This allows development without Firebase setup.
246
+
247
+ ```typescript
248
+ import { isFirebaseDemoMode } from '@donotdev/firebase';
249
+
250
+ if (isFirebaseDemoMode()) {
251
+ console.log('Running in demo mode');
252
+ }
253
+ ```
254
+
255
+ ## Integration with DoNotDev
256
+
257
+ This package integrates seamlessly with other DoNotDev packages:
258
+
259
+ - Use with `@donotdev/schemas` for complete entity validation
260
+ - Pair with `@donotdev/hooks` for type-safe data access
261
+ - Works with `@donotdev/auth` for comprehensive authentication
262
+
263
+ ## Core Modules
264
+
265
+ ### transform.ts
266
+
267
+ Data transformation utilities for converting between Firestore and application formats.
268
+
269
+ - `transformFirestoreData`: Converts Timestamps to ISO strings
270
+ - `prepareForFirestore`: Converts ISO strings to Timestamps
271
+ - `toTimestamp`: Converts Date or ISO string to Firestore Timestamp
272
+ - `toISOString`: Converts DateValue to ISO string
273
+ - `createFirestorePartialUpdate`: Creates a diff for partial updates
274
+
275
+ ### validation.ts
276
+
277
+ Document validation against schemas with uniqueness constraints.
278
+
279
+ - `validateFirestoreDocument`: Validates document against schema and checks uniqueness
280
+ - `validateCreate`: Validates document for creation
281
+ - `validateUpdate`: Validates document for update
282
+ - `enhanceSchema`: Adds Firestore metadata to schema
283
+
284
+ ### uniqueness.ts
285
+
286
+ Uniqueness constraint validation to ensure field values are unique.
287
+
288
+ - `validateUniqueness`: Validates uniqueness constraints for a document
289
+ - `createFirestoreValidator`: Server-side validator for uniqueness
290
+ - `createFirestoreClientValidator`: Client-side validator for uniqueness
291
+
292
+ ### batch.ts
293
+
294
+ Utilities for batch operations with automatic chunking.
295
+
296
+ - `batchWrite`: Generic batch write operation
297
+ - `batchCreate`: Creates multiple documents
298
+ - `batchUpdate`: Updates multiple documents
299
+ - `batchDelete`: Deletes multiple documents
300
+ - `bulkGet`: Fetches multiple documents by ID
301
+
302
+ ### auth.ts
303
+
304
+ Authentication utilities for client-side operations.
305
+
306
+ - `signInWithEmail`: Signs in with email and password
307
+ - `signInWithGoogle`: Signs in with Google
308
+ - `resetPassword`: Sends password reset email
309
+ - `getCurrentUser`: Gets current authenticated user
310
+ - `getIdToken`: Gets authentication token
311
+ - `signOut`: Signs out current user
312
+ - `isCurrentUserAdmin`: Checks if current user has admin role
313
+
314
+ ### utils.ts
315
+
316
+ Core utilities for Firebase operations.
317
+
318
+ - `handleFirebaseError`: Standardizes Firebase errors
319
+ - `generateId`: Generates unique IDs for documents
320
+ - `executeFirebaseOperation`: Executes operation with retry support
321
+
322
+ ### init.ts
323
+
324
+ Initialization utilities for Firebase in different environments.
325
+
326
+ - `initFirebase`: Initializes Firebase from environment variables or config
327
+ - `initAdminApp`: Initializes Firebase Admin SDK
328
+
329
+ ## Best Practices
330
+
331
+ 1. Always transform data when crossing the Firebase boundary:
332
+
333
+ ```typescript
334
+ // Before saving to Firestore
335
+ const firestoreData = prepareForFirestore(appData);
336
+
337
+ // After fetching from Firestore
338
+ const appData = transformFirestoreData(firestoreData);
339
+ ```
340
+
341
+ 2. Use batch operations for multiple documents:
342
+
343
+ ```typescript
344
+ // Instead of multiple individual writes
345
+ await batchCreate('products', newProducts);
346
+ ```
347
+
348
+ 3. Handle errors consistently:
349
+
350
+ ```typescript
351
+ try {
352
+ // Firebase operation
353
+ } catch (error) {
354
+ throw handleFirebaseError(error, 'Operation name');
355
+ }
356
+ ```
357
+
358
+ 4. Enforce uniqueness constraints:
359
+
360
+ ```typescript
361
+ const schema = enhanceSchema(productSchema, {
362
+ collection: 'products',
363
+ uniqueFields: [{ field: 'sku', errorMessage: 'SKU already exists' }],
364
+ });
365
+ ```
366
+
367
+ 5. For server environments, initialize validator early:
368
+
369
+ ```typescript
370
+ import { createFirestoreValidator } from '@donotdev/firebase/server';
371
+
372
+ async function initializeApp() {
373
+ // Set up validator once at app startup
374
+ await createFirestoreValidator();
375
+ }
376
+ ```
377
+
378
+ ## 📄 License & Ownership
379
+
380
+ All rights reserved.
381
+ The DoNotDev framework and its premium features are the exclusive property of **Ambroise Park Consulting**.
382
+
383
+ - Premium features require an active paid subscription.
384
+ - Redistribution, reverse-engineering, or commercial reuse is strictly prohibited without written authorization.
385
+
386
+ © Ambroise Park Consulting – 2025