@umituz/react-native-firebase 1.13.36 → 1.13.38
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/dist/scripts/auth.d.ts +39 -0
- package/dist/scripts/auth.d.ts.map +1 -0
- package/dist/scripts/auth.js +114 -0
- package/dist/scripts/auth.js.map +1 -0
- package/dist/scripts/firestore.d.ts +53 -0
- package/dist/scripts/firestore.d.ts.map +1 -0
- package/dist/scripts/firestore.js +217 -0
- package/dist/scripts/firestore.js.map +1 -0
- package/dist/scripts/index.d.ts +25 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +68 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/init.d.ts +29 -0
- package/dist/scripts/init.d.ts.map +1 -0
- package/dist/scripts/init.js +91 -0
- package/dist/scripts/init.js.map +1 -0
- package/dist/scripts/storage.d.ts +31 -0
- package/dist/scripts/storage.d.ts.map +1 -0
- package/dist/scripts/storage.js +93 -0
- package/dist/scripts/storage.js.map +1 -0
- package/dist/scripts/types.d.ts +49 -0
- package/dist/scripts/types.d.ts.map +1 -0
- package/dist/scripts/types.js +7 -0
- package/dist/scripts/types.js.map +1 -0
- package/dist/scripts/utils.d.ts +45 -0
- package/dist/scripts/utils.d.ts.map +1 -0
- package/dist/scripts/utils.js +93 -0
- package/dist/scripts/utils.js.map +1 -0
- package/package.json +18 -2
- package/scripts/auth.ts +142 -0
- package/scripts/firestore.ts +280 -0
- package/scripts/index.ts +85 -0
- package/scripts/init.ts +61 -0
- package/scripts/storage.ts +119 -0
- package/scripts/types.ts +55 -0
- package/scripts/utils.ts +95 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin Auth Utilities
|
|
3
|
+
* Generic auth operations for admin scripts
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from "firebase-admin";
|
|
6
|
+
import type { UserInfo, CleanupResult } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* List all users from Firebase Auth
|
|
9
|
+
*/
|
|
10
|
+
export declare function listAllUsers(auth: admin.auth.Auth): Promise<UserInfo[]>;
|
|
11
|
+
/**
|
|
12
|
+
* List only authenticated users (with email/providers)
|
|
13
|
+
*/
|
|
14
|
+
export declare function listAuthenticatedUsers(auth: admin.auth.Auth): Promise<UserInfo[]>;
|
|
15
|
+
/**
|
|
16
|
+
* List only anonymous users
|
|
17
|
+
*/
|
|
18
|
+
export declare function listAnonymousUsers(auth: admin.auth.Auth): Promise<UserInfo[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Delete users by UIDs
|
|
21
|
+
*/
|
|
22
|
+
export declare function deleteUsers(auth: admin.auth.Auth, uids: string[], onProgress?: (deleted: number, total: number) => void): Promise<CleanupResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Cleanup anonymous users - delete all users without providers
|
|
25
|
+
*/
|
|
26
|
+
export declare function cleanupAnonymousUsers(auth: admin.auth.Auth, onProgress?: (deleted: number, total: number) => void): Promise<CleanupResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete all users from Firebase Auth
|
|
29
|
+
*/
|
|
30
|
+
export declare function deleteAllUsers(auth: admin.auth.Auth, onProgress?: (deleted: number, total: number) => void): Promise<CleanupResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Get user statistics
|
|
33
|
+
*/
|
|
34
|
+
export declare function getUserStats(auth: admin.auth.Auth): Promise<{
|
|
35
|
+
total: number;
|
|
36
|
+
anonymous: number;
|
|
37
|
+
authenticated: number;
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../scripts/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEv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0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin Auth Utilities
|
|
4
|
+
* Generic auth operations for admin scripts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.listAllUsers = listAllUsers;
|
|
8
|
+
exports.listAuthenticatedUsers = listAuthenticatedUsers;
|
|
9
|
+
exports.listAnonymousUsers = listAnonymousUsers;
|
|
10
|
+
exports.deleteUsers = deleteUsers;
|
|
11
|
+
exports.cleanupAnonymousUsers = cleanupAnonymousUsers;
|
|
12
|
+
exports.deleteAllUsers = deleteAllUsers;
|
|
13
|
+
exports.getUserStats = getUserStats;
|
|
14
|
+
/**
|
|
15
|
+
* List all users from Firebase Auth
|
|
16
|
+
*/
|
|
17
|
+
async function listAllUsers(auth) {
|
|
18
|
+
const users = [];
|
|
19
|
+
let nextPageToken;
|
|
20
|
+
do {
|
|
21
|
+
const result = await auth.listUsers(1000, nextPageToken);
|
|
22
|
+
result.users.forEach((user) => {
|
|
23
|
+
users.push({
|
|
24
|
+
uid: user.uid,
|
|
25
|
+
email: user.email,
|
|
26
|
+
displayName: user.displayName,
|
|
27
|
+
isAnonymous: !user.providerData || user.providerData.length === 0,
|
|
28
|
+
createdAt: user.metadata.creationTime
|
|
29
|
+
? new Date(user.metadata.creationTime)
|
|
30
|
+
: undefined,
|
|
31
|
+
providerCount: user.providerData?.length ?? 0,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
nextPageToken = result.pageToken;
|
|
35
|
+
} while (nextPageToken);
|
|
36
|
+
return users;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* List only authenticated users (with email/providers)
|
|
40
|
+
*/
|
|
41
|
+
async function listAuthenticatedUsers(auth) {
|
|
42
|
+
const allUsers = await listAllUsers(auth);
|
|
43
|
+
return allUsers.filter((user) => !user.isAnonymous && user.email);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* List only anonymous users
|
|
47
|
+
*/
|
|
48
|
+
async function listAnonymousUsers(auth) {
|
|
49
|
+
const allUsers = await listAllUsers(auth);
|
|
50
|
+
return allUsers.filter((user) => user.isAnonymous);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Delete users by UIDs
|
|
54
|
+
*/
|
|
55
|
+
async function deleteUsers(auth, uids, onProgress) {
|
|
56
|
+
const result = {
|
|
57
|
+
totalProcessed: uids.length,
|
|
58
|
+
deleted: 0,
|
|
59
|
+
preserved: 0,
|
|
60
|
+
errors: [],
|
|
61
|
+
};
|
|
62
|
+
for (const uid of uids) {
|
|
63
|
+
try {
|
|
64
|
+
await auth.deleteUser(uid);
|
|
65
|
+
result.deleted++;
|
|
66
|
+
onProgress?.(result.deleted, uids.length);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
result.errors.push(`Failed to delete ${uid}: ${error}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Cleanup anonymous users - delete all users without providers
|
|
76
|
+
*/
|
|
77
|
+
async function cleanupAnonymousUsers(auth, onProgress) {
|
|
78
|
+
const anonymousUsers = await listAnonymousUsers(auth);
|
|
79
|
+
const uids = anonymousUsers.map((u) => u.uid);
|
|
80
|
+
if (uids.length === 0) {
|
|
81
|
+
return {
|
|
82
|
+
totalProcessed: 0,
|
|
83
|
+
deleted: 0,
|
|
84
|
+
preserved: 0,
|
|
85
|
+
errors: [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const deleteResult = await deleteUsers(auth, uids, onProgress);
|
|
89
|
+
// Count preserved (authenticated) users
|
|
90
|
+
const authenticatedUsers = await listAuthenticatedUsers(auth);
|
|
91
|
+
deleteResult.preserved = authenticatedUsers.length;
|
|
92
|
+
return deleteResult;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Delete all users from Firebase Auth
|
|
96
|
+
*/
|
|
97
|
+
async function deleteAllUsers(auth, onProgress) {
|
|
98
|
+
const allUsers = await listAllUsers(auth);
|
|
99
|
+
const uids = allUsers.map((u) => u.uid);
|
|
100
|
+
return deleteUsers(auth, uids, onProgress);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get user statistics
|
|
104
|
+
*/
|
|
105
|
+
async function getUserStats(auth) {
|
|
106
|
+
const allUsers = await listAllUsers(auth);
|
|
107
|
+
const anonymous = allUsers.filter((u) => u.isAnonymous).length;
|
|
108
|
+
return {
|
|
109
|
+
total: allUsers.length,
|
|
110
|
+
anonymous,
|
|
111
|
+
authenticated: allUsers.length - anonymous,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../scripts/auth.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAQH,oCAwBC;AAKD,wDAKC;AAKD,gDAKC;AAKD,kCAuBC;AAKD,sDAuBC;AAKD,wCAOC;AAKD,oCAaC;AArID;;GAEG;AACI,KAAK,UAAU,YAAY,CAAC,IAAqB;IACtD,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,IAAI,aAAiC,CAAC;IAEtC,GAAG,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAEzD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC5B,KAAK,CAAC,IAAI,CAAC;gBACT,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,WAAW,EAAE,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC;gBACjE,SAAS,EAAE,IAAI,CAAC,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U,YAAY,CAAC,IAAqB;IAKtD,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;IAE/D,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,MAAM;QACtB,SAAS;QACT,aAAa,EAAE,QAAQ,CAAC,MAAM,GAAG,SAAS;KAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin Firestore Utilities
|
|
3
|
+
* Generic Firestore operations for admin scripts
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from "firebase-admin";
|
|
6
|
+
import type { CollectionInfo, BatchResult } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* List all root-level collections
|
|
9
|
+
*/
|
|
10
|
+
export declare function listCollections(db: admin.firestore.Firestore): Promise<CollectionInfo[]>;
|
|
11
|
+
/**
|
|
12
|
+
* List subcollections for a user document
|
|
13
|
+
*/
|
|
14
|
+
export declare function listUserSubcollections(db: admin.firestore.Firestore, userId: string): Promise<CollectionInfo[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Delete collection in batches
|
|
17
|
+
*/
|
|
18
|
+
export declare function deleteCollection(db: admin.firestore.Firestore, collectionPath: string, onProgress?: (deleted: number) => void): Promise<number>;
|
|
19
|
+
/**
|
|
20
|
+
* Delete user subcollection for all users
|
|
21
|
+
*/
|
|
22
|
+
export declare function deleteUserSubcollection(db: admin.firestore.Firestore, subcollectionName: string, onProgress?: (deleted: number) => void): Promise<number>;
|
|
23
|
+
/**
|
|
24
|
+
* Delete all Firestore data
|
|
25
|
+
*/
|
|
26
|
+
export declare function deleteAllData(db: admin.firestore.Firestore, onProgress?: (collection: string, deleted: number) => void): Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Seed documents in batches
|
|
29
|
+
*/
|
|
30
|
+
export declare function seedBatch(db: admin.firestore.Firestore, collectionPath: string, docs: Array<{
|
|
31
|
+
id: string;
|
|
32
|
+
data: Record<string, unknown>;
|
|
33
|
+
}>): Promise<BatchResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Seed user subcollection
|
|
36
|
+
*/
|
|
37
|
+
export declare function seedUserSubcollection(db: admin.firestore.Firestore, userId: string, subcollectionName: string, docs: Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
data: Record<string, unknown>;
|
|
40
|
+
}>): Promise<BatchResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Count documents in collection
|
|
43
|
+
*/
|
|
44
|
+
export declare function countDocuments(db: admin.firestore.Firestore, collectionPath: string): Promise<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Get user document count statistics
|
|
47
|
+
*/
|
|
48
|
+
export declare function getUserStats(db: admin.firestore.Firestore): Promise<{
|
|
49
|
+
total: number;
|
|
50
|
+
anonymous: number;
|
|
51
|
+
authenticated: number;
|
|
52
|
+
}>;
|
|
53
|
+
//# sourceMappingURL=firestore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../../scripts/firestore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3D;;GAEG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC,CAqB3B;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,EAAE,CAAC,CAc3B;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAC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AC,SAAS,EAC7B,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,OAAO,CAAC;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC,CAoBD"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin Firestore Utilities
|
|
4
|
+
* Generic Firestore operations for admin scripts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.listCollections = listCollections;
|
|
8
|
+
exports.listUserSubcollections = listUserSubcollections;
|
|
9
|
+
exports.deleteCollection = deleteCollection;
|
|
10
|
+
exports.deleteUserSubcollection = deleteUserSubcollection;
|
|
11
|
+
exports.deleteAllData = deleteAllData;
|
|
12
|
+
exports.seedBatch = seedBatch;
|
|
13
|
+
exports.seedUserSubcollection = seedUserSubcollection;
|
|
14
|
+
exports.countDocuments = countDocuments;
|
|
15
|
+
exports.getUserStats = getUserStats;
|
|
16
|
+
const BATCH_SIZE = 500;
|
|
17
|
+
/**
|
|
18
|
+
* List all root-level collections
|
|
19
|
+
*/
|
|
20
|
+
async function listCollections(db) {
|
|
21
|
+
const collections = await db.listCollections();
|
|
22
|
+
const result = [];
|
|
23
|
+
for (const collection of collections) {
|
|
24
|
+
const snapshot = await collection.limit(1000).get();
|
|
25
|
+
const info = {
|
|
26
|
+
name: collection.id,
|
|
27
|
+
documentCount: snapshot.docs.length,
|
|
28
|
+
sampleDocumentId: snapshot.docs[0]?.id,
|
|
29
|
+
};
|
|
30
|
+
if (!snapshot.empty) {
|
|
31
|
+
const subcollections = await snapshot.docs[0].ref.listCollections();
|
|
32
|
+
info.hasSubcollections = subcollections.length > 0;
|
|
33
|
+
}
|
|
34
|
+
result.push(info);
|
|
35
|
+
}
|
|
36
|
+
return result.sort((a, b) => b.documentCount - a.documentCount);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* List subcollections for a user document
|
|
40
|
+
*/
|
|
41
|
+
async function listUserSubcollections(db, userId) {
|
|
42
|
+
const userRef = db.collection("users").doc(userId);
|
|
43
|
+
const subcollections = await userRef.listCollections();
|
|
44
|
+
const result = [];
|
|
45
|
+
for (const subcollection of subcollections) {
|
|
46
|
+
const count = await subcollection.count().get();
|
|
47
|
+
result.push({
|
|
48
|
+
name: subcollection.id,
|
|
49
|
+
documentCount: count.data().count,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Delete collection in batches
|
|
56
|
+
*/
|
|
57
|
+
async function deleteCollection(db, collectionPath, onProgress) {
|
|
58
|
+
let totalDeleted = 0;
|
|
59
|
+
let hasMore = true;
|
|
60
|
+
while (hasMore) {
|
|
61
|
+
const snapshot = await db
|
|
62
|
+
.collection(collectionPath)
|
|
63
|
+
.orderBy("__name__")
|
|
64
|
+
.limit(BATCH_SIZE)
|
|
65
|
+
.get();
|
|
66
|
+
if (snapshot.empty) {
|
|
67
|
+
hasMore = false;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const batch = db.batch();
|
|
71
|
+
snapshot.docs.forEach((doc) => batch.delete(doc.ref));
|
|
72
|
+
await batch.commit();
|
|
73
|
+
totalDeleted += snapshot.docs.length;
|
|
74
|
+
onProgress?.(totalDeleted);
|
|
75
|
+
}
|
|
76
|
+
return totalDeleted;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Delete user subcollection for all users
|
|
80
|
+
*/
|
|
81
|
+
async function deleteUserSubcollection(db, subcollectionName, onProgress) {
|
|
82
|
+
let totalDeleted = 0;
|
|
83
|
+
const usersSnapshot = await db.collection("users").get();
|
|
84
|
+
for (const userDoc of usersSnapshot.docs) {
|
|
85
|
+
const subcollectionRef = userDoc.ref.collection(subcollectionName);
|
|
86
|
+
const subcollectionSnapshot = await subcollectionRef.get();
|
|
87
|
+
if (!subcollectionSnapshot.empty) {
|
|
88
|
+
const batch = db.batch();
|
|
89
|
+
subcollectionSnapshot.docs.forEach((doc) => batch.delete(doc.ref));
|
|
90
|
+
await batch.commit();
|
|
91
|
+
totalDeleted += subcollectionSnapshot.docs.length;
|
|
92
|
+
onProgress?.(totalDeleted);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return totalDeleted;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Delete all Firestore data
|
|
99
|
+
*/
|
|
100
|
+
async function deleteAllData(db, onProgress) {
|
|
101
|
+
let totalDeleted = 0;
|
|
102
|
+
const collections = await db.listCollections();
|
|
103
|
+
for (const collection of collections) {
|
|
104
|
+
const snapshot = await collection.get();
|
|
105
|
+
// Delete subcollections first for users collection
|
|
106
|
+
if (collection.id === "users") {
|
|
107
|
+
for (const doc of snapshot.docs) {
|
|
108
|
+
const subcollections = await doc.ref.listCollections();
|
|
109
|
+
for (const subcollection of subcollections) {
|
|
110
|
+
const subSnapshot = await subcollection.get();
|
|
111
|
+
if (!subSnapshot.empty) {
|
|
112
|
+
const batch = db.batch();
|
|
113
|
+
subSnapshot.docs.forEach((subDoc) => batch.delete(subDoc.ref));
|
|
114
|
+
await batch.commit();
|
|
115
|
+
totalDeleted += subSnapshot.docs.length;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Delete main collection documents
|
|
121
|
+
if (!snapshot.empty) {
|
|
122
|
+
const batch = db.batch();
|
|
123
|
+
snapshot.docs.forEach((doc) => batch.delete(doc.ref));
|
|
124
|
+
await batch.commit();
|
|
125
|
+
totalDeleted += snapshot.docs.length;
|
|
126
|
+
onProgress?.(collection.id, totalDeleted);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return totalDeleted;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Seed documents in batches
|
|
133
|
+
*/
|
|
134
|
+
async function seedBatch(db, collectionPath, docs) {
|
|
135
|
+
const result = {
|
|
136
|
+
success: true,
|
|
137
|
+
processed: 0,
|
|
138
|
+
errors: [],
|
|
139
|
+
};
|
|
140
|
+
for (let i = 0; i < docs.length; i += BATCH_SIZE) {
|
|
141
|
+
const batch = db.batch();
|
|
142
|
+
const slice = docs.slice(i, i + BATCH_SIZE);
|
|
143
|
+
for (const { id, data } of slice) {
|
|
144
|
+
const ref = db.collection(collectionPath).doc(id);
|
|
145
|
+
const clean = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
146
|
+
batch.set(ref, clean);
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
await batch.commit();
|
|
150
|
+
result.processed += slice.length;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
result.success = false;
|
|
154
|
+
result.errors.push(`Batch failed at index ${i}: ${error}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Seed user subcollection
|
|
161
|
+
*/
|
|
162
|
+
async function seedUserSubcollection(db, userId, subcollectionName, docs) {
|
|
163
|
+
const result = {
|
|
164
|
+
success: true,
|
|
165
|
+
processed: 0,
|
|
166
|
+
errors: [],
|
|
167
|
+
};
|
|
168
|
+
const batch = db.batch();
|
|
169
|
+
for (const { id, data } of docs) {
|
|
170
|
+
const ref = db
|
|
171
|
+
.collection("users")
|
|
172
|
+
.doc(userId)
|
|
173
|
+
.collection(subcollectionName)
|
|
174
|
+
.doc(id);
|
|
175
|
+
const clean = Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined));
|
|
176
|
+
batch.set(ref, clean);
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
await batch.commit();
|
|
180
|
+
result.processed = docs.length;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
result.success = false;
|
|
184
|
+
result.errors.push(`Failed to seed subcollection: ${error}`);
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Count documents in collection
|
|
190
|
+
*/
|
|
191
|
+
async function countDocuments(db, collectionPath) {
|
|
192
|
+
const count = await db.collection(collectionPath).count().get();
|
|
193
|
+
return count.data().count;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get user document count statistics
|
|
197
|
+
*/
|
|
198
|
+
async function getUserStats(db) {
|
|
199
|
+
const usersSnapshot = await db.collection("users").get();
|
|
200
|
+
let anonymous = 0;
|
|
201
|
+
let authenticated = 0;
|
|
202
|
+
usersSnapshot.docs.forEach((doc) => {
|
|
203
|
+
const data = doc.data();
|
|
204
|
+
if (data.isAnonymous) {
|
|
205
|
+
anonymous++;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
authenticated++;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
total: usersSnapshot.docs.length,
|
|
213
|
+
anonymous,
|
|
214
|
+
authenticated,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=firestore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.js","sourceRoot":"","sources":["../../scripts/firestore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAUH,0CAuBC;AAKD,wDAiBC;AAKD,4CA6BC;AAKD,0DAsBC;AAKD,sCAqCC;AAKD,8BAiCC;AAKD,sDAmCC;AAKD,wCAMC;AAKD,oCAwBC;AA/QD,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;GAEG;AACI,KAAK,UAAU,eAAe,CACnC,EAA6B;IAE7B,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,eAAe,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAqB,EAAE,CA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a,EAAE,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM;QAChC,SAAS;QACT,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin Scripts
|
|
3
|
+
*
|
|
4
|
+
* Generic utilities for Firebase Admin operations.
|
|
5
|
+
* Use these for CLI scripts, seeding, cleanup, and testing.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { initFirebaseAdmin, cleanupAnonymousUsers } from "@umituz/react-native-firebase/scripts";
|
|
9
|
+
*
|
|
10
|
+
* const app = initFirebaseAdmin({
|
|
11
|
+
* serviceAccountPath: "./service-account.json",
|
|
12
|
+
* projectId: "my-project",
|
|
13
|
+
* storageBucket: "my-project.appspot.com",
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const auth = getAuthAdmin(app);
|
|
17
|
+
* await cleanupAnonymousUsers(auth);
|
|
18
|
+
*/
|
|
19
|
+
export type { FirebaseAdminConfig, CollectionInfo, UserInfo, CleanupResult, BatchResult, StorageFileInfo, ResetSummary, } from "./types";
|
|
20
|
+
export { initFirebaseAdmin, getFirestoreAdmin, getAuthAdmin, getStorageAdmin, resetFirebaseAdmin, } from "./init";
|
|
21
|
+
export { listAllUsers, listAuthenticatedUsers, listAnonymousUsers, deleteUsers, cleanupAnonymousUsers, deleteAllUsers, getUserStats as getAuthUserStats, } from "./auth";
|
|
22
|
+
export { listCollections, listUserSubcollections, deleteCollection, deleteUserSubcollection, deleteAllData, seedBatch, seedUserSubcollection, countDocuments, getUserStats as getFirestoreUserStats, } from "./firestore";
|
|
23
|
+
export { listFiles, deleteAllFiles, deleteFilesByPrefix, getStorageStats, deleteUserFiles, } from "./storage";
|
|
24
|
+
export { randomId, randomDate, randomItem, randomNumber, randomBoolean, sleep, formatBytes, createConfirmationTimer, printSeparator, printHeader, } from "./utils";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../scripts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,kBAAkB,GACnB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,YAAY,IAAI,gBAAgB,GACjC,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,cAAc,EACd,YAAY,IAAI,qBAAqB,GACtC,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,eAAe,GAChB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,KAAK,EACL,WAAW,EACX,uBAAuB,EACvB,cAAc,EACd,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin Scripts
|
|
4
|
+
*
|
|
5
|
+
* Generic utilities for Firebase Admin operations.
|
|
6
|
+
* Use these for CLI scripts, seeding, cleanup, and testing.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { initFirebaseAdmin, cleanupAnonymousUsers } from "@umituz/react-native-firebase/scripts";
|
|
10
|
+
*
|
|
11
|
+
* const app = initFirebaseAdmin({
|
|
12
|
+
* serviceAccountPath: "./service-account.json",
|
|
13
|
+
* projectId: "my-project",
|
|
14
|
+
* storageBucket: "my-project.appspot.com",
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const auth = getAuthAdmin(app);
|
|
18
|
+
* await cleanupAnonymousUsers(auth);
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.printHeader = exports.printSeparator = exports.createConfirmationTimer = exports.formatBytes = exports.sleep = exports.randomBoolean = exports.randomNumber = exports.randomItem = exports.randomDate = exports.randomId = exports.deleteUserFiles = exports.getStorageStats = exports.deleteFilesByPrefix = exports.deleteAllFiles = exports.listFiles = exports.getFirestoreUserStats = exports.countDocuments = exports.seedUserSubcollection = exports.seedBatch = exports.deleteAllData = exports.deleteUserSubcollection = exports.deleteCollection = exports.listUserSubcollections = exports.listCollections = exports.getAuthUserStats = exports.deleteAllUsers = exports.cleanupAnonymousUsers = exports.deleteUsers = exports.listAnonymousUsers = exports.listAuthenticatedUsers = exports.listAllUsers = exports.resetFirebaseAdmin = exports.getStorageAdmin = exports.getAuthAdmin = exports.getFirestoreAdmin = exports.initFirebaseAdmin = void 0;
|
|
22
|
+
// Initialization
|
|
23
|
+
var init_1 = require("./init");
|
|
24
|
+
Object.defineProperty(exports, "initFirebaseAdmin", { enumerable: true, get: function () { return init_1.initFirebaseAdmin; } });
|
|
25
|
+
Object.defineProperty(exports, "getFirestoreAdmin", { enumerable: true, get: function () { return init_1.getFirestoreAdmin; } });
|
|
26
|
+
Object.defineProperty(exports, "getAuthAdmin", { enumerable: true, get: function () { return init_1.getAuthAdmin; } });
|
|
27
|
+
Object.defineProperty(exports, "getStorageAdmin", { enumerable: true, get: function () { return init_1.getStorageAdmin; } });
|
|
28
|
+
Object.defineProperty(exports, "resetFirebaseAdmin", { enumerable: true, get: function () { return init_1.resetFirebaseAdmin; } });
|
|
29
|
+
// Auth utilities
|
|
30
|
+
var auth_1 = require("./auth");
|
|
31
|
+
Object.defineProperty(exports, "listAllUsers", { enumerable: true, get: function () { return auth_1.listAllUsers; } });
|
|
32
|
+
Object.defineProperty(exports, "listAuthenticatedUsers", { enumerable: true, get: function () { return auth_1.listAuthenticatedUsers; } });
|
|
33
|
+
Object.defineProperty(exports, "listAnonymousUsers", { enumerable: true, get: function () { return auth_1.listAnonymousUsers; } });
|
|
34
|
+
Object.defineProperty(exports, "deleteUsers", { enumerable: true, get: function () { return auth_1.deleteUsers; } });
|
|
35
|
+
Object.defineProperty(exports, "cleanupAnonymousUsers", { enumerable: true, get: function () { return auth_1.cleanupAnonymousUsers; } });
|
|
36
|
+
Object.defineProperty(exports, "deleteAllUsers", { enumerable: true, get: function () { return auth_1.deleteAllUsers; } });
|
|
37
|
+
Object.defineProperty(exports, "getAuthUserStats", { enumerable: true, get: function () { return auth_1.getUserStats; } });
|
|
38
|
+
// Firestore utilities
|
|
39
|
+
var firestore_1 = require("./firestore");
|
|
40
|
+
Object.defineProperty(exports, "listCollections", { enumerable: true, get: function () { return firestore_1.listCollections; } });
|
|
41
|
+
Object.defineProperty(exports, "listUserSubcollections", { enumerable: true, get: function () { return firestore_1.listUserSubcollections; } });
|
|
42
|
+
Object.defineProperty(exports, "deleteCollection", { enumerable: true, get: function () { return firestore_1.deleteCollection; } });
|
|
43
|
+
Object.defineProperty(exports, "deleteUserSubcollection", { enumerable: true, get: function () { return firestore_1.deleteUserSubcollection; } });
|
|
44
|
+
Object.defineProperty(exports, "deleteAllData", { enumerable: true, get: function () { return firestore_1.deleteAllData; } });
|
|
45
|
+
Object.defineProperty(exports, "seedBatch", { enumerable: true, get: function () { return firestore_1.seedBatch; } });
|
|
46
|
+
Object.defineProperty(exports, "seedUserSubcollection", { enumerable: true, get: function () { return firestore_1.seedUserSubcollection; } });
|
|
47
|
+
Object.defineProperty(exports, "countDocuments", { enumerable: true, get: function () { return firestore_1.countDocuments; } });
|
|
48
|
+
Object.defineProperty(exports, "getFirestoreUserStats", { enumerable: true, get: function () { return firestore_1.getUserStats; } });
|
|
49
|
+
// Storage utilities
|
|
50
|
+
var storage_1 = require("./storage");
|
|
51
|
+
Object.defineProperty(exports, "listFiles", { enumerable: true, get: function () { return storage_1.listFiles; } });
|
|
52
|
+
Object.defineProperty(exports, "deleteAllFiles", { enumerable: true, get: function () { return storage_1.deleteAllFiles; } });
|
|
53
|
+
Object.defineProperty(exports, "deleteFilesByPrefix", { enumerable: true, get: function () { return storage_1.deleteFilesByPrefix; } });
|
|
54
|
+
Object.defineProperty(exports, "getStorageStats", { enumerable: true, get: function () { return storage_1.getStorageStats; } });
|
|
55
|
+
Object.defineProperty(exports, "deleteUserFiles", { enumerable: true, get: function () { return storage_1.deleteUserFiles; } });
|
|
56
|
+
// Utility functions
|
|
57
|
+
var utils_1 = require("./utils");
|
|
58
|
+
Object.defineProperty(exports, "randomId", { enumerable: true, get: function () { return utils_1.randomId; } });
|
|
59
|
+
Object.defineProperty(exports, "randomDate", { enumerable: true, get: function () { return utils_1.randomDate; } });
|
|
60
|
+
Object.defineProperty(exports, "randomItem", { enumerable: true, get: function () { return utils_1.randomItem; } });
|
|
61
|
+
Object.defineProperty(exports, "randomNumber", { enumerable: true, get: function () { return utils_1.randomNumber; } });
|
|
62
|
+
Object.defineProperty(exports, "randomBoolean", { enumerable: true, get: function () { return utils_1.randomBoolean; } });
|
|
63
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
|
|
64
|
+
Object.defineProperty(exports, "formatBytes", { enumerable: true, get: function () { return utils_1.formatBytes; } });
|
|
65
|
+
Object.defineProperty(exports, "createConfirmationTimer", { enumerable: true, get: function () { return utils_1.createConfirmationTimer; } });
|
|
66
|
+
Object.defineProperty(exports, "printSeparator", { enumerable: true, get: function () { return utils_1.printSeparator; } });
|
|
67
|
+
Object.defineProperty(exports, "printHeader", { enumerable: true, get: function () { return utils_1.printHeader; } });
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../scripts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAaH,iBAAiB;AACjB,+BAMgB;AALd,yGAAA,iBAAiB,OAAA;AACjB,yGAAA,iBAAiB,OAAA;AACjB,oGAAA,YAAY,OAAA;AACZ,uGAAA,eAAe,OAAA;AACf,0GAAA,kBAAkB,OAAA;AAGpB,iBAAiB;AACjB,+BAQgB;AAPd,oGAAA,YAAY,OAAA;AACZ,8GAAA,sBAAsB,OAAA;AACtB,0GAAA,kBAAkB,OAAA;AAClB,mGAAA,WAAW,OAAA;AACX,6GAAA,qBAAqB,OAAA;AACrB,sGAAA,cAAc,OAAA;AACd,wGAAA,YAAY,OAAoB;AAGlC,sBAAsB;AACtB,yCAUqB;AATnB,4GAAA,eAAe,OAAA;AACf,mHAAA,sBAAsB,OAAA;AACtB,6GAAA,gBAAgB,OAAA;AAChB,oHAAA,uBAAuB,OAAA;AACvB,0GAAA,aAAa,OAAA;AACb,sGAAA,SAAS,OAAA;AACT,kHAAA,qBAAqB,OAAA;AACrB,2GAAA,cAAc,OAAA;AACd,kHAAA,YAAY,OAAyB;AAGvC,oBAAoB;AACpB,qCAMmB;AALjB,oGAAA,SAAS,OAAA;AACT,yGAAA,cAAc,OAAA;AACd,8GAAA,mBAAmB,OAAA;AACnB,0GAAA,eAAe,OAAA;AACf,0GAAA,eAAe,OAAA;AAGjB,oBAAoB;AACpB,iCAWiB;AAVf,iGAAA,QAAQ,OAAA;AACR,mGAAA,UAAU,OAAA;AACV,mGAAA,UAAU,OAAA;AACV,qGAAA,YAAY,OAAA;AACZ,sGAAA,aAAa,OAAA;AACb,8FAAA,KAAK,OAAA;AACL,oGAAA,WAAW,OAAA;AACX,gHAAA,uBAAuB,OAAA;AACvB,uGAAA,cAAc,OAAA;AACd,oGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Admin Initialization
|
|
3
|
+
* Dynamic configuration - no hardcoded values
|
|
4
|
+
*/
|
|
5
|
+
import * as admin from "firebase-admin";
|
|
6
|
+
import type { FirebaseAdminConfig } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize Firebase Admin SDK with config
|
|
9
|
+
* @param config - Firebase Admin configuration
|
|
10
|
+
* @returns Initialized Firebase Admin app
|
|
11
|
+
*/
|
|
12
|
+
export declare function initFirebaseAdmin(config: FirebaseAdminConfig): admin.app.App;
|
|
13
|
+
/**
|
|
14
|
+
* Get Firestore instance
|
|
15
|
+
*/
|
|
16
|
+
export declare function getFirestoreAdmin(app: admin.app.App): admin.firestore.Firestore;
|
|
17
|
+
/**
|
|
18
|
+
* Get Auth instance
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAuthAdmin(app: admin.app.App): admin.auth.Auth;
|
|
21
|
+
/**
|
|
22
|
+
* Get Storage bucket
|
|
23
|
+
*/
|
|
24
|
+
export declare function getStorageAdmin(app: admin.app.App): admin.storage.Storage;
|
|
25
|
+
/**
|
|
26
|
+
* Reset initialized app (for testing)
|
|
27
|
+
*/
|
|
28
|
+
export declare function resetFirebaseAdmin(): void;
|
|
29
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../scripts/init.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAInD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAiB5E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAE/E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAEhE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAEzE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|