@umituz/react-native-firebase 1.13.49 โ 1.13.51
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/cli-handlers.d.ts +27 -0
- package/dist/scripts/cli-handlers.d.ts.map +1 -0
- package/dist/scripts/cli-handlers.js +125 -0
- package/dist/scripts/cli-handlers.js.map +1 -0
- package/dist/scripts/cli-parser.d.ts +25 -0
- package/dist/scripts/cli-parser.d.ts.map +1 -0
- package/dist/scripts/cli-parser.js +101 -0
- package/dist/scripts/cli-parser.js.map +1 -0
- package/dist/scripts/cli.js +20 -155
- package/dist/scripts/cli.js.map +1 -1
- package/dist/scripts/firestore-operations.d.ts +18 -0
- package/dist/scripts/firestore-operations.d.ts.map +1 -0
- package/dist/scripts/firestore-operations.js +88 -0
- package/dist/scripts/firestore-operations.js.map +1 -0
- package/dist/scripts/firestore-queries.d.ts +27 -0
- package/dist/scripts/firestore-queries.d.ts.map +1 -0
- package/dist/scripts/firestore-queries.js +77 -0
- package/dist/scripts/firestore-queries.js.map +1 -0
- package/dist/scripts/firestore-seeding.d.ts +21 -0
- package/dist/scripts/firestore-seeding.d.ts.map +1 -0
- package/dist/scripts/firestore-seeding.js +67 -0
- package/dist/scripts/firestore-seeding.js.map +1 -0
- package/dist/scripts/firestore.d.ts +3 -48
- package/dist/scripts/firestore.d.ts.map +1 -1
- package/dist/scripts/firestore.js +16 -210
- package/dist/scripts/firestore.js.map +1 -1
- package/dist/scripts/user-commands.d.ts +33 -0
- package/dist/scripts/user-commands.d.ts.map +1 -0
- package/dist/scripts/user-commands.js +113 -0
- package/dist/scripts/user-commands.js.map +1 -0
- package/dist/scripts/user-formatters.d.ts +10 -0
- package/dist/scripts/user-formatters.d.ts.map +1 -0
- package/dist/scripts/user-formatters.js +55 -0
- package/dist/scripts/user-formatters.js.map +1 -0
- package/dist/scripts/user-queries.d.ts +42 -0
- package/dist/scripts/user-queries.d.ts.map +1 -0
- package/dist/scripts/user-queries.js +125 -0
- package/dist/scripts/user-queries.js.map +1 -0
- package/dist/scripts/user.d.ts +3 -67
- package/dist/scripts/user.d.ts.map +1 -1
- package/dist/scripts/user.js +15 -272
- package/dist/scripts/user.js.map +1 -1
- package/package.json +1 -1
- package/scripts/cli-handlers.ts +170 -0
- package/scripts/cli-parser.ts +82 -0
- package/scripts/cli.ts +27 -193
- package/scripts/firestore-operations.ts +111 -0
- package/scripts/firestore-queries.ts +97 -0
- package/scripts/firestore-seeding.ts +87 -0
- package/scripts/firestore.ts +20 -275
- package/scripts/user-commands.ts +104 -0
- package/scripts/user-formatters.ts +55 -0
- package/scripts/user-queries.ts +185 -0
- package/scripts/user.ts +19 -326
package/scripts/user.ts
CHANGED
|
@@ -3,329 +3,22 @@
|
|
|
3
3
|
* Read and manage user data including credits, subscriptions, transactions
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
includeTransactions = true,
|
|
26
|
-
creditsCollection = "user_credits",
|
|
27
|
-
} = options || {};
|
|
28
|
-
|
|
29
|
-
const result: UserData = {
|
|
30
|
-
userId,
|
|
31
|
-
exists: false,
|
|
32
|
-
profile: null,
|
|
33
|
-
credits: null,
|
|
34
|
-
subscriptions: [],
|
|
35
|
-
transactions: [],
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Get user profile
|
|
39
|
-
const userDoc = await db.collection("users").doc(userId).get();
|
|
40
|
-
if (userDoc.exists) {
|
|
41
|
-
result.exists = true;
|
|
42
|
-
result.profile = userDoc.data() as Record<string, unknown>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Get credits from root-level collection
|
|
46
|
-
if (includeCredits) {
|
|
47
|
-
const creditsDoc = await db.collection(creditsCollection).doc(userId).get();
|
|
48
|
-
if (creditsDoc.exists) {
|
|
49
|
-
result.credits = creditsDoc.data() as UserCredits;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Get subscriptions subcollection
|
|
54
|
-
if (includeSubscriptions) {
|
|
55
|
-
const subsSnapshot = await db
|
|
56
|
-
.collection("users")
|
|
57
|
-
.doc(userId)
|
|
58
|
-
.collection("subscriptions")
|
|
59
|
-
.get();
|
|
60
|
-
result.subscriptions = subsSnapshot.docs.map((doc) => ({
|
|
61
|
-
id: doc.id,
|
|
62
|
-
...doc.data(),
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Get transactions subcollection
|
|
67
|
-
if (includeTransactions) {
|
|
68
|
-
const txSnapshot = await db
|
|
69
|
-
.collection("users")
|
|
70
|
-
.doc(userId)
|
|
71
|
-
.collection("transactions")
|
|
72
|
-
.orderBy("createdAt", "desc")
|
|
73
|
-
.limit(50)
|
|
74
|
-
.get();
|
|
75
|
-
result.transactions = txSnapshot.docs.map((doc) => ({
|
|
76
|
-
id: doc.id,
|
|
77
|
-
...doc.data(),
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Initialize credits for a user
|
|
86
|
-
*/
|
|
87
|
-
export async function initializeUserCredits(
|
|
88
|
-
db: admin.firestore.Firestore,
|
|
89
|
-
userId: string,
|
|
90
|
-
config: CreditsConfig
|
|
91
|
-
): Promise<UserCredits> {
|
|
92
|
-
const { collectionName = "user_credits", textLimit = 0, imageLimit = 0 } = config;
|
|
93
|
-
|
|
94
|
-
const now = admin.firestore.FieldValue.serverTimestamp();
|
|
95
|
-
|
|
96
|
-
const credits: Omit<UserCredits, "createdAt" | "updatedAt"> & {
|
|
97
|
-
createdAt: admin.firestore.FieldValue;
|
|
98
|
-
updatedAt: admin.firestore.FieldValue;
|
|
99
|
-
} = {
|
|
100
|
-
text: textLimit,
|
|
101
|
-
image: imageLimit,
|
|
102
|
-
video: 0,
|
|
103
|
-
audio: 0,
|
|
104
|
-
createdAt: now,
|
|
105
|
-
updatedAt: now,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
await db.collection(collectionName).doc(userId).set(credits, { merge: true });
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
text: textLimit,
|
|
112
|
-
image: imageLimit,
|
|
113
|
-
video: 0,
|
|
114
|
-
audio: 0,
|
|
115
|
-
createdAt: new Date(),
|
|
116
|
-
updatedAt: new Date(),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Add credits to a user
|
|
122
|
-
*/
|
|
123
|
-
export async function addUserCredits(
|
|
124
|
-
db: admin.firestore.Firestore,
|
|
125
|
-
userId: string,
|
|
126
|
-
credits: { text?: number; image?: number; video?: number; audio?: number },
|
|
127
|
-
collectionName = "user_credits"
|
|
128
|
-
): Promise<void> {
|
|
129
|
-
const updates: Record<string, admin.firestore.FieldValue> = {
|
|
130
|
-
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
if (credits.text) {
|
|
134
|
-
updates.text = admin.firestore.FieldValue.increment(credits.text);
|
|
135
|
-
}
|
|
136
|
-
if (credits.image) {
|
|
137
|
-
updates.image = admin.firestore.FieldValue.increment(credits.image);
|
|
138
|
-
}
|
|
139
|
-
if (credits.video) {
|
|
140
|
-
updates.video = admin.firestore.FieldValue.increment(credits.video);
|
|
141
|
-
}
|
|
142
|
-
if (credits.audio) {
|
|
143
|
-
updates.audio = admin.firestore.FieldValue.increment(credits.audio);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await db.collection(collectionName).doc(userId).update(updates);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Set credits for a user (overwrite)
|
|
151
|
-
*/
|
|
152
|
-
export async function setUserCredits(
|
|
153
|
-
db: admin.firestore.Firestore,
|
|
154
|
-
userId: string,
|
|
155
|
-
credits: { text?: number; image?: number; video?: number; audio?: number },
|
|
156
|
-
collectionName = "user_credits"
|
|
157
|
-
): Promise<void> {
|
|
158
|
-
const updates: Record<string, unknown> = {
|
|
159
|
-
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
if (credits.text !== undefined) updates.text = credits.text;
|
|
163
|
-
if (credits.image !== undefined) updates.image = credits.image;
|
|
164
|
-
if (credits.video !== undefined) updates.video = credits.video;
|
|
165
|
-
if (credits.audio !== undefined) updates.audio = credits.audio;
|
|
166
|
-
|
|
167
|
-
await db.collection(collectionName).doc(userId).set(updates, { merge: true });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* List all users with their credit balances
|
|
172
|
-
*/
|
|
173
|
-
export async function listUsersWithCredits(
|
|
174
|
-
db: admin.firestore.Firestore,
|
|
175
|
-
options?: {
|
|
176
|
-
creditsCollection?: string;
|
|
177
|
-
limit?: number;
|
|
178
|
-
onlyWithCredits?: boolean;
|
|
179
|
-
}
|
|
180
|
-
): Promise<
|
|
181
|
-
Array<{
|
|
182
|
-
userId: string;
|
|
183
|
-
displayName?: string;
|
|
184
|
-
email?: string;
|
|
185
|
-
isAnonymous: boolean;
|
|
186
|
-
credits: UserCredits | null;
|
|
187
|
-
}>
|
|
188
|
-
> {
|
|
189
|
-
const { creditsCollection = "user_credits", limit = 100, onlyWithCredits = false } = options || {};
|
|
190
|
-
|
|
191
|
-
const usersSnapshot = await db.collection("users").limit(limit).get();
|
|
192
|
-
const result: Array<{
|
|
193
|
-
userId: string;
|
|
194
|
-
displayName?: string;
|
|
195
|
-
email?: string;
|
|
196
|
-
isAnonymous: boolean;
|
|
197
|
-
credits: UserCredits | null;
|
|
198
|
-
}> = [];
|
|
199
|
-
|
|
200
|
-
for (const userDoc of usersSnapshot.docs) {
|
|
201
|
-
const userData = userDoc.data();
|
|
202
|
-
const creditsDoc = await db.collection(creditsCollection).doc(userDoc.id).get();
|
|
203
|
-
const credits = creditsDoc.exists ? (creditsDoc.data() as UserCredits) : null;
|
|
204
|
-
|
|
205
|
-
if (onlyWithCredits && !credits) continue;
|
|
206
|
-
|
|
207
|
-
result.push({
|
|
208
|
-
userId: userDoc.id,
|
|
209
|
-
displayName: userData.displayName,
|
|
210
|
-
email: userData.email,
|
|
211
|
-
isAnonymous: userData.isAnonymous || false,
|
|
212
|
-
credits,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Delete user credits document
|
|
221
|
-
*/
|
|
222
|
-
export async function deleteUserCredits(
|
|
223
|
-
db: admin.firestore.Firestore,
|
|
224
|
-
userId: string,
|
|
225
|
-
collectionName = "user_credits"
|
|
226
|
-
): Promise<void> {
|
|
227
|
-
await db.collection(collectionName).doc(userId).delete();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get credits summary across all users
|
|
232
|
-
*/
|
|
233
|
-
export async function getCreditsSummary(
|
|
234
|
-
db: admin.firestore.Firestore,
|
|
235
|
-
collectionName = "user_credits"
|
|
236
|
-
): Promise<{
|
|
237
|
-
totalUsers: number;
|
|
238
|
-
totalText: number;
|
|
239
|
-
totalImage: number;
|
|
240
|
-
totalVideo: number;
|
|
241
|
-
totalAudio: number;
|
|
242
|
-
usersWithCredits: number;
|
|
243
|
-
usersWithZeroCredits: number;
|
|
244
|
-
}> {
|
|
245
|
-
const snapshot = await db.collection(collectionName).get();
|
|
246
|
-
|
|
247
|
-
let totalText = 0;
|
|
248
|
-
let totalImage = 0;
|
|
249
|
-
let totalVideo = 0;
|
|
250
|
-
let totalAudio = 0;
|
|
251
|
-
let usersWithCredits = 0;
|
|
252
|
-
let usersWithZeroCredits = 0;
|
|
253
|
-
|
|
254
|
-
snapshot.docs.forEach((doc) => {
|
|
255
|
-
const data = doc.data();
|
|
256
|
-
const text = data.text || 0;
|
|
257
|
-
const image = data.image || 0;
|
|
258
|
-
const video = data.video || 0;
|
|
259
|
-
const audio = data.audio || 0;
|
|
260
|
-
|
|
261
|
-
totalText += text;
|
|
262
|
-
totalImage += image;
|
|
263
|
-
totalVideo += video;
|
|
264
|
-
totalAudio += audio;
|
|
265
|
-
|
|
266
|
-
if (text > 0 || image > 0 || video > 0 || audio > 0) {
|
|
267
|
-
usersWithCredits++;
|
|
268
|
-
} else {
|
|
269
|
-
usersWithZeroCredits++;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
totalUsers: snapshot.docs.length,
|
|
275
|
-
totalText,
|
|
276
|
-
totalImage,
|
|
277
|
-
totalVideo,
|
|
278
|
-
totalAudio,
|
|
279
|
-
usersWithCredits,
|
|
280
|
-
usersWithZeroCredits,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Print user data in formatted way
|
|
286
|
-
*/
|
|
287
|
-
export function printUserData(data: UserData): void {
|
|
288
|
-
console.log("\n" + "โ".repeat(60));
|
|
289
|
-
console.log(`๐ค USER: ${data.userId}`);
|
|
290
|
-
console.log("โ".repeat(60));
|
|
291
|
-
|
|
292
|
-
console.log("\n๐ PROFILE:");
|
|
293
|
-
if (data.profile) {
|
|
294
|
-
console.log(JSON.stringify(data.profile, null, 2));
|
|
295
|
-
} else {
|
|
296
|
-
console.log(" โ Not found");
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
console.log("\n๐ฐ CREDITS:");
|
|
300
|
-
if (data.credits) {
|
|
301
|
-
console.log(` Text: ${data.credits.text || 0}`);
|
|
302
|
-
console.log(` Image: ${data.credits.image || 0}`);
|
|
303
|
-
console.log(` Video: ${data.credits.video || 0}`);
|
|
304
|
-
console.log(` Audio: ${data.credits.audio || 0}`);
|
|
305
|
-
} else {
|
|
306
|
-
console.log(" โ Not found");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
console.log("\n๐ SUBSCRIPTIONS:");
|
|
310
|
-
if (data.subscriptions.length > 0) {
|
|
311
|
-
data.subscriptions.forEach((sub) => {
|
|
312
|
-
console.log(` - ${sub.id}: ${JSON.stringify(sub)}`);
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
315
|
-
console.log(" โ None");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
console.log("\n๐งพ TRANSACTIONS:");
|
|
319
|
-
if (data.transactions.length > 0) {
|
|
320
|
-
data.transactions.slice(0, 5).forEach((tx) => {
|
|
321
|
-
console.log(` - ${tx.id}: ${JSON.stringify(tx)}`);
|
|
322
|
-
});
|
|
323
|
-
if (data.transactions.length > 5) {
|
|
324
|
-
console.log(` ... and ${data.transactions.length - 5} more`);
|
|
325
|
-
}
|
|
326
|
-
} else {
|
|
327
|
-
console.log(" โ None");
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
console.log("\n" + "โ".repeat(60) + "\n");
|
|
331
|
-
}
|
|
6
|
+
// Query functions
|
|
7
|
+
export {
|
|
8
|
+
getUserData,
|
|
9
|
+
listUsersWithCredits,
|
|
10
|
+
getCreditsSummary,
|
|
11
|
+
} from "./user-queries";
|
|
12
|
+
|
|
13
|
+
// Command functions
|
|
14
|
+
export {
|
|
15
|
+
initializeUserCredits,
|
|
16
|
+
addUserCredits,
|
|
17
|
+
setUserCredits,
|
|
18
|
+
deleteUserCredits,
|
|
19
|
+
} from "./user-commands";
|
|
20
|
+
|
|
21
|
+
// Formatter functions
|
|
22
|
+
export {
|
|
23
|
+
printUserData,
|
|
24
|
+
} from "./user-formatters";
|