@prmichaelsen/firebase-admin-sdk-v8 2.0.5 → 2.0.7
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.
- package/EXAMPLES.md +8 -6
- package/README.md +7 -4
- package/dist/index.d.mts +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +5 -1
- package/dist/index.mjs +5 -1
- package/package.json +1 -1
package/EXAMPLES.md
CHANGED
|
@@ -50,16 +50,18 @@ await setDocument('users', 'user123', {
|
|
|
50
50
|
import { addDocument } from 'firebase-admin-sdk-v8';
|
|
51
51
|
|
|
52
52
|
// Auto-generate document ID
|
|
53
|
-
const
|
|
53
|
+
const docRef = await addDocument('posts', {
|
|
54
54
|
title: 'Hello World',
|
|
55
55
|
content: 'This is my first post',
|
|
56
56
|
createdAt: new Date(),
|
|
57
57
|
});
|
|
58
|
+
console.log('Created document:', docRef.id);
|
|
58
59
|
|
|
59
60
|
// Or specify custom ID
|
|
60
|
-
const
|
|
61
|
+
const customDocRef = await addDocument('posts', {
|
|
61
62
|
title: 'Custom ID Post',
|
|
62
63
|
}, 'my-custom-id');
|
|
64
|
+
console.log('Created document:', customDocRef.id); // 'my-custom-id'
|
|
63
65
|
```
|
|
64
66
|
|
|
65
67
|
### Get Document
|
|
@@ -426,7 +428,7 @@ await setDocument('users', 'user123', {
|
|
|
426
428
|
import { addDocument, FieldValue } from 'firebase-admin-sdk-v8';
|
|
427
429
|
|
|
428
430
|
async function registerUser(email: string, name: string) {
|
|
429
|
-
const
|
|
431
|
+
const docRef = await addDocument('users', {
|
|
430
432
|
email,
|
|
431
433
|
name,
|
|
432
434
|
createdAt: FieldValue.serverTimestamp(),
|
|
@@ -435,7 +437,7 @@ async function registerUser(email: string, name: string) {
|
|
|
435
437
|
roles: ['user'],
|
|
436
438
|
});
|
|
437
439
|
|
|
438
|
-
return
|
|
440
|
+
return docRef.id;
|
|
439
441
|
}
|
|
440
442
|
```
|
|
441
443
|
|
|
@@ -458,7 +460,7 @@ async function trackUserLogin(userId: string) {
|
|
|
458
460
|
import { addDocument, updateDocument, FieldValue } from 'firebase-admin-sdk-v8';
|
|
459
461
|
|
|
460
462
|
async function createPost(title: string, content: string, tags: string[]) {
|
|
461
|
-
const
|
|
463
|
+
const docRef = await addDocument('posts', {
|
|
462
464
|
title,
|
|
463
465
|
content,
|
|
464
466
|
tags,
|
|
@@ -468,7 +470,7 @@ async function createPost(title: string, content: string, tags: string[]) {
|
|
|
468
470
|
updatedAt: FieldValue.serverTimestamp(),
|
|
469
471
|
});
|
|
470
472
|
|
|
471
|
-
return
|
|
473
|
+
return docRef.id;
|
|
472
474
|
}
|
|
473
475
|
|
|
474
476
|
async function addTagToPost(postId: string, tag: string) {
|
package/README.md
CHANGED
|
@@ -169,13 +169,16 @@ await setDocument('users', 'user123', { age: 31, city: 'NYC' }, {
|
|
|
169
169
|
});
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
#### `addDocument(collectionPath, data, documentId?): Promise<
|
|
172
|
+
#### `addDocument(collectionPath, data, documentId?): Promise<DocumentReference>`
|
|
173
173
|
|
|
174
|
-
Add a document with auto-generated or custom ID.
|
|
174
|
+
Add a document with auto-generated or custom ID. Returns a DocumentReference with `id` and `path` properties.
|
|
175
175
|
|
|
176
176
|
```typescript
|
|
177
|
-
const
|
|
178
|
-
|
|
177
|
+
const docRef = await addDocument('posts', { title: 'Hello' });
|
|
178
|
+
console.log('Created:', docRef.id); // Auto-generated ID
|
|
179
|
+
|
|
180
|
+
const customDocRef = await addDocument('posts', { title: 'Hi' }, 'custom-id');
|
|
181
|
+
console.log('Created:', customDocRef.id); // 'custom-id'
|
|
179
182
|
```
|
|
180
183
|
|
|
181
184
|
#### `getDocument(collectionPath, documentId): Promise<DataObject | null>`
|
package/dist/index.d.mts
CHANGED
|
@@ -91,6 +91,15 @@ interface FirestoreDocument {
|
|
|
91
91
|
* Generic data object
|
|
92
92
|
*/
|
|
93
93
|
type DataObject = Record<string, any>;
|
|
94
|
+
/**
|
|
95
|
+
* Document reference (simplified version for REST API)
|
|
96
|
+
*/
|
|
97
|
+
interface DocumentReference {
|
|
98
|
+
/** Document ID */
|
|
99
|
+
id: string;
|
|
100
|
+
/** Collection path */
|
|
101
|
+
path: string;
|
|
102
|
+
}
|
|
94
103
|
/**
|
|
95
104
|
* Set options for document writes
|
|
96
105
|
*/
|
|
@@ -311,19 +320,20 @@ declare function setDocument(collectionPath: string, documentId: string, data: D
|
|
|
311
320
|
* @param {string} collectionPath - Collection path (e.g., 'users' or 'users/uid/posts')
|
|
312
321
|
* @param {DataObject} data - Document data
|
|
313
322
|
* @param {string} [documentId] - Optional document ID (auto-generated if not provided)
|
|
314
|
-
* @returns {Promise<
|
|
323
|
+
* @returns {Promise<DocumentReference>} Document reference with id and path
|
|
315
324
|
* @throws {Error} If the operation fails
|
|
316
325
|
*
|
|
317
326
|
* @example
|
|
318
327
|
* ```typescript
|
|
319
|
-
* const
|
|
328
|
+
* const docRef = await addDocument('users', {
|
|
320
329
|
* name: 'John Doe',
|
|
321
330
|
* email: 'john@example.com',
|
|
322
331
|
* createdAt: new Date()
|
|
323
332
|
* });
|
|
333
|
+
* console.log('Created document:', docRef.id);
|
|
324
334
|
* ```
|
|
325
335
|
*/
|
|
326
|
-
declare function addDocument(collectionPath: string, data: DataObject, documentId?: string): Promise<
|
|
336
|
+
declare function addDocument(collectionPath: string, data: DataObject, documentId?: string): Promise<DocumentReference>;
|
|
327
337
|
/**
|
|
328
338
|
* Get a document from Firestore
|
|
329
339
|
*
|
|
@@ -512,4 +522,4 @@ declare function getAdminAccessToken(): Promise<string>;
|
|
|
512
522
|
*/
|
|
513
523
|
declare function clearTokenCache(): void;
|
|
514
524
|
|
|
515
|
-
export { type BatchWrite, type BatchWriteResult, type DataObject, type DecodedIdToken, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FirestoreDocument, type FirestoreValue, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type TokenResponse, type UpdateOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, deleteDocument, getAdminAccessToken, getAuth, getConfig, getDocument, getProjectId, getServiceAccount, getUserFromToken, initializeApp, queryDocuments, setDocument, updateDocument, verifyIdToken };
|
|
525
|
+
export { type BatchWrite, type BatchWriteResult, type DataObject, type DecodedIdToken, type DocumentReference, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FirestoreDocument, type FirestoreValue, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type TokenResponse, type UpdateOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, deleteDocument, getAdminAccessToken, getAuth, getConfig, getDocument, getProjectId, getServiceAccount, getUserFromToken, initializeApp, queryDocuments, setDocument, updateDocument, verifyIdToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,15 @@ interface FirestoreDocument {
|
|
|
91
91
|
* Generic data object
|
|
92
92
|
*/
|
|
93
93
|
type DataObject = Record<string, any>;
|
|
94
|
+
/**
|
|
95
|
+
* Document reference (simplified version for REST API)
|
|
96
|
+
*/
|
|
97
|
+
interface DocumentReference {
|
|
98
|
+
/** Document ID */
|
|
99
|
+
id: string;
|
|
100
|
+
/** Collection path */
|
|
101
|
+
path: string;
|
|
102
|
+
}
|
|
94
103
|
/**
|
|
95
104
|
* Set options for document writes
|
|
96
105
|
*/
|
|
@@ -311,19 +320,20 @@ declare function setDocument(collectionPath: string, documentId: string, data: D
|
|
|
311
320
|
* @param {string} collectionPath - Collection path (e.g., 'users' or 'users/uid/posts')
|
|
312
321
|
* @param {DataObject} data - Document data
|
|
313
322
|
* @param {string} [documentId] - Optional document ID (auto-generated if not provided)
|
|
314
|
-
* @returns {Promise<
|
|
323
|
+
* @returns {Promise<DocumentReference>} Document reference with id and path
|
|
315
324
|
* @throws {Error} If the operation fails
|
|
316
325
|
*
|
|
317
326
|
* @example
|
|
318
327
|
* ```typescript
|
|
319
|
-
* const
|
|
328
|
+
* const docRef = await addDocument('users', {
|
|
320
329
|
* name: 'John Doe',
|
|
321
330
|
* email: 'john@example.com',
|
|
322
331
|
* createdAt: new Date()
|
|
323
332
|
* });
|
|
333
|
+
* console.log('Created document:', docRef.id);
|
|
324
334
|
* ```
|
|
325
335
|
*/
|
|
326
|
-
declare function addDocument(collectionPath: string, data: DataObject, documentId?: string): Promise<
|
|
336
|
+
declare function addDocument(collectionPath: string, data: DataObject, documentId?: string): Promise<DocumentReference>;
|
|
327
337
|
/**
|
|
328
338
|
* Get a document from Firestore
|
|
329
339
|
*
|
|
@@ -512,4 +522,4 @@ declare function getAdminAccessToken(): Promise<string>;
|
|
|
512
522
|
*/
|
|
513
523
|
declare function clearTokenCache(): void;
|
|
514
524
|
|
|
515
|
-
export { type BatchWrite, type BatchWriteResult, type DataObject, type DecodedIdToken, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FirestoreDocument, type FirestoreValue, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type TokenResponse, type UpdateOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, deleteDocument, getAdminAccessToken, getAuth, getConfig, getDocument, getProjectId, getServiceAccount, getUserFromToken, initializeApp, queryDocuments, setDocument, updateDocument, verifyIdToken };
|
|
525
|
+
export { type BatchWrite, type BatchWriteResult, type DataObject, type DecodedIdToken, type DocumentReference, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FirestoreDocument, type FirestoreValue, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type TokenResponse, type UpdateOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, deleteDocument, getAdminAccessToken, getAuth, getConfig, getDocument, getProjectId, getServiceAccount, getUserFromToken, initializeApp, queryDocuments, setDocument, updateDocument, verifyIdToken };
|
package/dist/index.js
CHANGED
|
@@ -722,7 +722,11 @@ async function addDocument(collectionPath, data, documentId) {
|
|
|
722
722
|
throw new Error(`Failed to add document: ${errorText}`);
|
|
723
723
|
}
|
|
724
724
|
const result = await response.json();
|
|
725
|
-
|
|
725
|
+
const docId = result.name.split("/").pop();
|
|
726
|
+
return {
|
|
727
|
+
id: docId,
|
|
728
|
+
path: `${collectionPath}/${docId}`
|
|
729
|
+
};
|
|
726
730
|
}
|
|
727
731
|
async function getDocument(collectionPath, documentId) {
|
|
728
732
|
const accessToken = await getAdminAccessToken();
|
package/dist/index.mjs
CHANGED
|
@@ -679,7 +679,11 @@ async function addDocument(collectionPath, data, documentId) {
|
|
|
679
679
|
throw new Error(`Failed to add document: ${errorText}`);
|
|
680
680
|
}
|
|
681
681
|
const result = await response.json();
|
|
682
|
-
|
|
682
|
+
const docId = result.name.split("/").pop();
|
|
683
|
+
return {
|
|
684
|
+
id: docId,
|
|
685
|
+
path: `${collectionPath}/${docId}`
|
|
686
|
+
};
|
|
683
687
|
}
|
|
684
688
|
async function getDocument(collectionPath, documentId) {
|
|
685
689
|
const accessToken = await getAdminAccessToken();
|
package/package.json
CHANGED