@umituz/react-native-firebase 1.13.44 → 1.13.46
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.d.ts +24 -0
- package/dist/scripts/cli.d.ts.map +1 -0
- package/dist/scripts/cli.js +267 -0
- package/dist/scripts/cli.js.map +1 -0
- package/dist/scripts/index.d.ts +2 -1
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +11 -1
- package/dist/scripts/index.js.map +1 -1
- package/dist/scripts/types.d.ts +26 -0
- package/dist/scripts/types.d.ts.map +1 -1
- package/dist/scripts/user.d.ts +72 -0
- package/dist/scripts/user.d.ts.map +1 -0
- package/dist/scripts/user.js +279 -0
- package/dist/scripts/user.js.map +1 -0
- package/package.json +1 -1
- package/scripts/cli.ts +286 -0
- package/scripts/index.ts +15 -0
- package/scripts/types.ts +29 -0
- package/scripts/user.ts +331 -0
- package/src/firestore/infrastructure/config/FirestoreClient.ts +13 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin User Utilities
|
|
4
|
+
* Read and manage user data including credits, subscriptions, transactions
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.getUserData = getUserData;
|
|
41
|
+
exports.initializeUserCredits = initializeUserCredits;
|
|
42
|
+
exports.addUserCredits = addUserCredits;
|
|
43
|
+
exports.setUserCredits = setUserCredits;
|
|
44
|
+
exports.listUsersWithCredits = listUsersWithCredits;
|
|
45
|
+
exports.deleteUserCredits = deleteUserCredits;
|
|
46
|
+
exports.getCreditsSummary = getCreditsSummary;
|
|
47
|
+
exports.printUserData = printUserData;
|
|
48
|
+
const admin = __importStar(require("firebase-admin"));
|
|
49
|
+
/**
|
|
50
|
+
* Get complete user data including profile and all related collections
|
|
51
|
+
*/
|
|
52
|
+
async function getUserData(db, userId, options) {
|
|
53
|
+
const { includeCredits = true, includeSubscriptions = true, includeTransactions = true, creditsCollection = "user_credits", } = options || {};
|
|
54
|
+
const result = {
|
|
55
|
+
userId,
|
|
56
|
+
exists: false,
|
|
57
|
+
profile: null,
|
|
58
|
+
credits: null,
|
|
59
|
+
subscriptions: [],
|
|
60
|
+
transactions: [],
|
|
61
|
+
};
|
|
62
|
+
// Get user profile
|
|
63
|
+
const userDoc = await db.collection("users").doc(userId).get();
|
|
64
|
+
if (userDoc.exists) {
|
|
65
|
+
result.exists = true;
|
|
66
|
+
result.profile = userDoc.data();
|
|
67
|
+
}
|
|
68
|
+
// Get credits from root-level collection
|
|
69
|
+
if (includeCredits) {
|
|
70
|
+
const creditsDoc = await db.collection(creditsCollection).doc(userId).get();
|
|
71
|
+
if (creditsDoc.exists) {
|
|
72
|
+
result.credits = creditsDoc.data();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Get subscriptions subcollection
|
|
76
|
+
if (includeSubscriptions) {
|
|
77
|
+
const subsSnapshot = await db
|
|
78
|
+
.collection("users")
|
|
79
|
+
.doc(userId)
|
|
80
|
+
.collection("subscriptions")
|
|
81
|
+
.get();
|
|
82
|
+
result.subscriptions = subsSnapshot.docs.map((doc) => ({
|
|
83
|
+
id: doc.id,
|
|
84
|
+
...doc.data(),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
// Get transactions subcollection
|
|
88
|
+
if (includeTransactions) {
|
|
89
|
+
const txSnapshot = await db
|
|
90
|
+
.collection("users")
|
|
91
|
+
.doc(userId)
|
|
92
|
+
.collection("transactions")
|
|
93
|
+
.orderBy("createdAt", "desc")
|
|
94
|
+
.limit(50)
|
|
95
|
+
.get();
|
|
96
|
+
result.transactions = txSnapshot.docs.map((doc) => ({
|
|
97
|
+
id: doc.id,
|
|
98
|
+
...doc.data(),
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Initialize credits for a user
|
|
105
|
+
*/
|
|
106
|
+
async function initializeUserCredits(db, userId, config) {
|
|
107
|
+
const { collectionName = "user_credits", textLimit = 0, imageLimit = 0 } = config;
|
|
108
|
+
const now = admin.firestore.FieldValue.serverTimestamp();
|
|
109
|
+
const credits = {
|
|
110
|
+
text: textLimit,
|
|
111
|
+
image: imageLimit,
|
|
112
|
+
video: 0,
|
|
113
|
+
audio: 0,
|
|
114
|
+
createdAt: now,
|
|
115
|
+
updatedAt: now,
|
|
116
|
+
};
|
|
117
|
+
await db.collection(collectionName).doc(userId).set(credits, { merge: true });
|
|
118
|
+
return {
|
|
119
|
+
text: textLimit,
|
|
120
|
+
image: imageLimit,
|
|
121
|
+
video: 0,
|
|
122
|
+
audio: 0,
|
|
123
|
+
createdAt: new Date(),
|
|
124
|
+
updatedAt: new Date(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Add credits to a user
|
|
129
|
+
*/
|
|
130
|
+
async function addUserCredits(db, userId, credits, collectionName = "user_credits") {
|
|
131
|
+
const updates = {
|
|
132
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
133
|
+
};
|
|
134
|
+
if (credits.text) {
|
|
135
|
+
updates.text = admin.firestore.FieldValue.increment(credits.text);
|
|
136
|
+
}
|
|
137
|
+
if (credits.image) {
|
|
138
|
+
updates.image = admin.firestore.FieldValue.increment(credits.image);
|
|
139
|
+
}
|
|
140
|
+
if (credits.video) {
|
|
141
|
+
updates.video = admin.firestore.FieldValue.increment(credits.video);
|
|
142
|
+
}
|
|
143
|
+
if (credits.audio) {
|
|
144
|
+
updates.audio = admin.firestore.FieldValue.increment(credits.audio);
|
|
145
|
+
}
|
|
146
|
+
await db.collection(collectionName).doc(userId).update(updates);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Set credits for a user (overwrite)
|
|
150
|
+
*/
|
|
151
|
+
async function setUserCredits(db, userId, credits, collectionName = "user_credits") {
|
|
152
|
+
const updates = {
|
|
153
|
+
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
154
|
+
};
|
|
155
|
+
if (credits.text !== undefined)
|
|
156
|
+
updates.text = credits.text;
|
|
157
|
+
if (credits.image !== undefined)
|
|
158
|
+
updates.image = credits.image;
|
|
159
|
+
if (credits.video !== undefined)
|
|
160
|
+
updates.video = credits.video;
|
|
161
|
+
if (credits.audio !== undefined)
|
|
162
|
+
updates.audio = credits.audio;
|
|
163
|
+
await db.collection(collectionName).doc(userId).set(updates, { merge: true });
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* List all users with their credit balances
|
|
167
|
+
*/
|
|
168
|
+
async function listUsersWithCredits(db, options) {
|
|
169
|
+
const { creditsCollection = "user_credits", limit = 100, onlyWithCredits = false } = options || {};
|
|
170
|
+
const usersSnapshot = await db.collection("users").limit(limit).get();
|
|
171
|
+
const result = [];
|
|
172
|
+
for (const userDoc of usersSnapshot.docs) {
|
|
173
|
+
const userData = userDoc.data();
|
|
174
|
+
const creditsDoc = await db.collection(creditsCollection).doc(userDoc.id).get();
|
|
175
|
+
const credits = creditsDoc.exists ? creditsDoc.data() : null;
|
|
176
|
+
if (onlyWithCredits && !credits)
|
|
177
|
+
continue;
|
|
178
|
+
result.push({
|
|
179
|
+
userId: userDoc.id,
|
|
180
|
+
displayName: userData.displayName,
|
|
181
|
+
email: userData.email,
|
|
182
|
+
isAnonymous: userData.isAnonymous || false,
|
|
183
|
+
credits,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Delete user credits document
|
|
190
|
+
*/
|
|
191
|
+
async function deleteUserCredits(db, userId, collectionName = "user_credits") {
|
|
192
|
+
await db.collection(collectionName).doc(userId).delete();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get credits summary across all users
|
|
196
|
+
*/
|
|
197
|
+
async function getCreditsSummary(db, collectionName = "user_credits") {
|
|
198
|
+
const snapshot = await db.collection(collectionName).get();
|
|
199
|
+
let totalText = 0;
|
|
200
|
+
let totalImage = 0;
|
|
201
|
+
let totalVideo = 0;
|
|
202
|
+
let totalAudio = 0;
|
|
203
|
+
let usersWithCredits = 0;
|
|
204
|
+
let usersWithZeroCredits = 0;
|
|
205
|
+
snapshot.docs.forEach((doc) => {
|
|
206
|
+
const data = doc.data();
|
|
207
|
+
const text = data.text || 0;
|
|
208
|
+
const image = data.image || 0;
|
|
209
|
+
const video = data.video || 0;
|
|
210
|
+
const audio = data.audio || 0;
|
|
211
|
+
totalText += text;
|
|
212
|
+
totalImage += image;
|
|
213
|
+
totalVideo += video;
|
|
214
|
+
totalAudio += audio;
|
|
215
|
+
if (text > 0 || image > 0 || video > 0 || audio > 0) {
|
|
216
|
+
usersWithCredits++;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
usersWithZeroCredits++;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return {
|
|
223
|
+
totalUsers: snapshot.docs.length,
|
|
224
|
+
totalText,
|
|
225
|
+
totalImage,
|
|
226
|
+
totalVideo,
|
|
227
|
+
totalAudio,
|
|
228
|
+
usersWithCredits,
|
|
229
|
+
usersWithZeroCredits,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Print user data in formatted way
|
|
234
|
+
*/
|
|
235
|
+
function printUserData(data) {
|
|
236
|
+
console.log("\n" + "═".repeat(60));
|
|
237
|
+
console.log(`👤 USER: ${data.userId}`);
|
|
238
|
+
console.log("═".repeat(60));
|
|
239
|
+
console.log("\n📋 PROFILE:");
|
|
240
|
+
if (data.profile) {
|
|
241
|
+
console.log(JSON.stringify(data.profile, null, 2));
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
console.log(" ❌ Not found");
|
|
245
|
+
}
|
|
246
|
+
console.log("\n💰 CREDITS:");
|
|
247
|
+
if (data.credits) {
|
|
248
|
+
console.log(` Text: ${data.credits.text || 0}`);
|
|
249
|
+
console.log(` Image: ${data.credits.image || 0}`);
|
|
250
|
+
console.log(` Video: ${data.credits.video || 0}`);
|
|
251
|
+
console.log(` Audio: ${data.credits.audio || 0}`);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
console.log(" ❌ Not found");
|
|
255
|
+
}
|
|
256
|
+
console.log("\n🔔 SUBSCRIPTIONS:");
|
|
257
|
+
if (data.subscriptions.length > 0) {
|
|
258
|
+
data.subscriptions.forEach((sub) => {
|
|
259
|
+
console.log(` - ${sub.id}: ${JSON.stringify(sub)}`);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
console.log(" ❌ None");
|
|
264
|
+
}
|
|
265
|
+
console.log("\n🧾 TRANSACTIONS:");
|
|
266
|
+
if (data.transactions.length > 0) {
|
|
267
|
+
data.transactions.slice(0, 5).forEach((tx) => {
|
|
268
|
+
console.log(` - ${tx.id}: ${JSON.stringify(tx)}`);
|
|
269
|
+
});
|
|
270
|
+
if (data.transactions.length > 5) {
|
|
271
|
+
console.log(` ... and ${data.transactions.length - 5} more`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
console.log(" ❌ None");
|
|
276
|
+
}
|
|
277
|
+
console.log("\n" + "═".repeat(60) + "\n");
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../scripts/user.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,kCAsEC;AAKD,sDA+BC;AAKD,wCAwBC;AAKD,wCAgBC;AAKD,oDA4CC;AAKD,8CAMC;AAKD,8CAiDC;AAKD,sCA4CC;AArUD,sDAAwC;AAGxC;;GAEG;AACI,KAAK,UAAU,WAAW,CAC/B,EAA6B,EAC7B,MAAc,EACd,OAKC;IAED,MAAM,EACJ,cAAc,GAAG,IAAI,EACrB,oBAAoB,GAAG,IAAI,EAC3B,mBAAmB,GAAG,IAAI,EAC1B,iBAAiB,GAAG,cAAc,GACnC,GAAG,OAAO,IAAI,EAAE,CAAC;IAElB,MAAM,MAAM,GAAa;QACvB,MAAM;QACN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CAAC,aAAa,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.46",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/scripts/cli.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Admin CLI
|
|
4
|
+
* Unified CLI for Firebase Admin operations
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* npx ts-node -r tsconfig-paths/register node_modules/@umituz/react-native-firebase/scripts/cli.ts <command> [options]
|
|
8
|
+
*
|
|
9
|
+
* Commands:
|
|
10
|
+
* read-user <userId> Read user data
|
|
11
|
+
* init-credits <userId> Initialize credits for user
|
|
12
|
+
* set-credits <userId> <text> <image> Set credits for user
|
|
13
|
+
* list-users List all users with credits
|
|
14
|
+
* credits-summary Get credits summary
|
|
15
|
+
*
|
|
16
|
+
* Options:
|
|
17
|
+
* --service-account <path> Path to service account JSON (default: ./firebase-service-account.json)
|
|
18
|
+
* --project-id <id> Firebase project ID
|
|
19
|
+
* --credits-collection <name> Credits collection name (default: user_credits)
|
|
20
|
+
* --text-limit <n> Default text credit limit (default: 100)
|
|
21
|
+
* --image-limit <n> Default image credit limit (default: 100)
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import * as path from "path";
|
|
25
|
+
import * as fs from "fs";
|
|
26
|
+
import {
|
|
27
|
+
initFirebaseAdmin,
|
|
28
|
+
getFirestoreAdmin,
|
|
29
|
+
resetFirebaseAdmin,
|
|
30
|
+
} from "./init";
|
|
31
|
+
import {
|
|
32
|
+
getUserData,
|
|
33
|
+
initializeUserCredits,
|
|
34
|
+
setUserCredits,
|
|
35
|
+
listUsersWithCredits,
|
|
36
|
+
getCreditsSummary,
|
|
37
|
+
printUserData,
|
|
38
|
+
} from "./user";
|
|
39
|
+
import { printHeader, printSeparator } from "./utils";
|
|
40
|
+
|
|
41
|
+
interface CLIOptions {
|
|
42
|
+
serviceAccountPath: string;
|
|
43
|
+
projectId?: string;
|
|
44
|
+
creditsCollection: string;
|
|
45
|
+
textLimit: number;
|
|
46
|
+
imageLimit: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseArgs(): { command: string; args: string[]; options: CLIOptions } {
|
|
50
|
+
const args = process.argv.slice(2);
|
|
51
|
+
const command = args[0] || "help";
|
|
52
|
+
const commandArgs: string[] = [];
|
|
53
|
+
const options: CLIOptions = {
|
|
54
|
+
serviceAccountPath: "./firebase-service-account.json",
|
|
55
|
+
creditsCollection: "user_credits",
|
|
56
|
+
textLimit: 100,
|
|
57
|
+
imageLimit: 100,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
let i = 1;
|
|
61
|
+
while (i < args.length) {
|
|
62
|
+
const arg = args[i];
|
|
63
|
+
if (arg.startsWith("--")) {
|
|
64
|
+
const key = arg.slice(2);
|
|
65
|
+
const value = args[++i];
|
|
66
|
+
switch (key) {
|
|
67
|
+
case "service-account":
|
|
68
|
+
options.serviceAccountPath = value;
|
|
69
|
+
break;
|
|
70
|
+
case "project-id":
|
|
71
|
+
options.projectId = value;
|
|
72
|
+
break;
|
|
73
|
+
case "credits-collection":
|
|
74
|
+
options.creditsCollection = value;
|
|
75
|
+
break;
|
|
76
|
+
case "text-limit":
|
|
77
|
+
options.textLimit = parseInt(value) || 100;
|
|
78
|
+
break;
|
|
79
|
+
case "image-limit":
|
|
80
|
+
options.imageLimit = parseInt(value) || 100;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
commandArgs.push(arg);
|
|
85
|
+
}
|
|
86
|
+
i++;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { command, args: commandArgs, options };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getProjectId(options: CLIOptions): string {
|
|
93
|
+
if (options.projectId) return options.projectId;
|
|
94
|
+
|
|
95
|
+
const saPath = path.resolve(process.cwd(), options.serviceAccountPath);
|
|
96
|
+
if (fs.existsSync(saPath)) {
|
|
97
|
+
const sa = JSON.parse(fs.readFileSync(saPath, "utf8"));
|
|
98
|
+
return sa.project_id;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
throw new Error("Project ID not found. Use --project-id or ensure service account file exists.");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function main() {
|
|
105
|
+
const { command, args, options } = parseArgs();
|
|
106
|
+
|
|
107
|
+
if (command === "help") {
|
|
108
|
+
console.log(`
|
|
109
|
+
Firebase Admin CLI
|
|
110
|
+
|
|
111
|
+
Commands:
|
|
112
|
+
read-user <userId> Read user data including credits
|
|
113
|
+
init-credits <userId> Initialize credits for a user
|
|
114
|
+
set-credits <userId> <text> <image> Set credits for a user
|
|
115
|
+
list-users [--limit N] List all users with credits
|
|
116
|
+
credits-summary Get credits summary
|
|
117
|
+
|
|
118
|
+
Options:
|
|
119
|
+
--service-account <path> Path to service account JSON
|
|
120
|
+
--project-id <id> Firebase project ID
|
|
121
|
+
--credits-collection <name> Credits collection (default: user_credits)
|
|
122
|
+
--text-limit <n> Default text limit (default: 100)
|
|
123
|
+
--image-limit <n> Default image limit (default: 100)
|
|
124
|
+
|
|
125
|
+
Examples:
|
|
126
|
+
npx ts-node cli.ts read-user abc123
|
|
127
|
+
npx ts-node cli.ts init-credits abc123 --text-limit 1000 --image-limit 100
|
|
128
|
+
npx ts-node cli.ts set-credits abc123 500 50
|
|
129
|
+
npx ts-node cli.ts list-users --limit 50
|
|
130
|
+
npx ts-node cli.ts credits-summary
|
|
131
|
+
`);
|
|
132
|
+
process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const projectId = getProjectId(options);
|
|
137
|
+
const saPath = path.resolve(process.cwd(), options.serviceAccountPath);
|
|
138
|
+
|
|
139
|
+
const app = initFirebaseAdmin({
|
|
140
|
+
serviceAccountPath: saPath,
|
|
141
|
+
projectId,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const db = getFirestoreAdmin(app);
|
|
145
|
+
|
|
146
|
+
switch (command) {
|
|
147
|
+
case "read-user": {
|
|
148
|
+
const userId = args[0];
|
|
149
|
+
if (!userId) {
|
|
150
|
+
console.error("❌ Error: userId is required");
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
printHeader(`📖 READ USER: ${userId}`);
|
|
155
|
+
const userData = await getUserData(db, userId, {
|
|
156
|
+
creditsCollection: options.creditsCollection,
|
|
157
|
+
});
|
|
158
|
+
printUserData(userData);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
case "init-credits": {
|
|
163
|
+
const userId = args[0];
|
|
164
|
+
if (!userId) {
|
|
165
|
+
console.error("❌ Error: userId is required");
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
printHeader(`💰 INIT CREDITS: ${userId}`);
|
|
170
|
+
console.log(`Collection: ${options.creditsCollection}`);
|
|
171
|
+
console.log(`Limits: Text=${options.textLimit}, Image=${options.imageLimit}\n`);
|
|
172
|
+
|
|
173
|
+
const existing = await getUserData(db, userId, {
|
|
174
|
+
creditsCollection: options.creditsCollection,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (existing.credits) {
|
|
178
|
+
console.log("⚠️ Credits already exist:");
|
|
179
|
+
console.log(` Text: ${existing.credits.text}`);
|
|
180
|
+
console.log(` Image: ${existing.credits.image}`);
|
|
181
|
+
console.log("\n Use 'set-credits' to overwrite.");
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const credits = await initializeUserCredits(db, userId, {
|
|
186
|
+
collectionName: options.creditsCollection,
|
|
187
|
+
textLimit: options.textLimit,
|
|
188
|
+
imageLimit: options.imageLimit,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
console.log("✅ Credits initialized:");
|
|
192
|
+
console.log(` Text: ${credits.text}`);
|
|
193
|
+
console.log(` Image: ${credits.image}`);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
case "set-credits": {
|
|
198
|
+
const userId = args[0];
|
|
199
|
+
const text = parseInt(args[1]);
|
|
200
|
+
const image = parseInt(args[2]);
|
|
201
|
+
|
|
202
|
+
if (!userId || isNaN(text) || isNaN(image)) {
|
|
203
|
+
console.error("❌ Error: Usage: set-credits <userId> <text> <image>");
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
printHeader(`💰 SET CREDITS: ${userId}`);
|
|
208
|
+
console.log(`Setting: Text=${text}, Image=${image}\n`);
|
|
209
|
+
|
|
210
|
+
await setUserCredits(db, userId, { text, image }, options.creditsCollection);
|
|
211
|
+
|
|
212
|
+
console.log("✅ Credits set successfully!");
|
|
213
|
+
|
|
214
|
+
const updated = await getUserData(db, userId, {
|
|
215
|
+
creditsCollection: options.creditsCollection,
|
|
216
|
+
});
|
|
217
|
+
printUserData(updated);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
case "list-users": {
|
|
222
|
+
const limit = parseInt(args[0]) || 100;
|
|
223
|
+
|
|
224
|
+
printHeader("👥 USERS WITH CREDITS");
|
|
225
|
+
const users = await listUsersWithCredits(db, {
|
|
226
|
+
creditsCollection: options.creditsCollection,
|
|
227
|
+
limit,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
console.log(`Found ${users.length} users:\n`);
|
|
231
|
+
printSeparator("-", 80);
|
|
232
|
+
console.log(
|
|
233
|
+
"ID".padEnd(30) +
|
|
234
|
+
"Name".padEnd(20) +
|
|
235
|
+
"Text".padEnd(10) +
|
|
236
|
+
"Image".padEnd(10) +
|
|
237
|
+
"Anon"
|
|
238
|
+
);
|
|
239
|
+
printSeparator("-", 80);
|
|
240
|
+
|
|
241
|
+
users.forEach((u) => {
|
|
242
|
+
const text = u.credits?.text ?? "-";
|
|
243
|
+
const image = u.credits?.image ?? "-";
|
|
244
|
+
console.log(
|
|
245
|
+
u.userId.substring(0, 28).padEnd(30) +
|
|
246
|
+
(u.displayName || "-").substring(0, 18).padEnd(20) +
|
|
247
|
+
String(text).padEnd(10) +
|
|
248
|
+
String(image).padEnd(10) +
|
|
249
|
+
(u.isAnonymous ? "Yes" : "No")
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
printSeparator("-", 80);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
case "credits-summary": {
|
|
257
|
+
printHeader("📊 CREDITS SUMMARY");
|
|
258
|
+
const summary = await getCreditsSummary(db, options.creditsCollection);
|
|
259
|
+
|
|
260
|
+
console.log(`Total Users: ${summary.totalUsers}`);
|
|
261
|
+
console.log(`With Credits: ${summary.usersWithCredits}`);
|
|
262
|
+
console.log(`Zero Credits: ${summary.usersWithZeroCredits}`);
|
|
263
|
+
console.log();
|
|
264
|
+
console.log("Total Credits Across All Users:");
|
|
265
|
+
console.log(` Text: ${summary.totalText}`);
|
|
266
|
+
console.log(` Image: ${summary.totalImage}`);
|
|
267
|
+
console.log(` Video: ${summary.totalVideo}`);
|
|
268
|
+
console.log(` Audio: ${summary.totalAudio}`);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
default:
|
|
273
|
+
console.error(`❌ Unknown command: ${command}`);
|
|
274
|
+
console.log("Run with 'help' for available commands.");
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
resetFirebaseAdmin();
|
|
279
|
+
process.exit(0);
|
|
280
|
+
} catch (error) {
|
|
281
|
+
console.error("❌ Error:", error instanceof Error ? error.message : error);
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
main();
|
package/scripts/index.ts
CHANGED
|
@@ -26,6 +26,9 @@ export type {
|
|
|
26
26
|
BatchResult,
|
|
27
27
|
StorageFileInfo,
|
|
28
28
|
ResetSummary,
|
|
29
|
+
UserCredits,
|
|
30
|
+
UserData,
|
|
31
|
+
CreditsConfig,
|
|
29
32
|
} from "./types";
|
|
30
33
|
|
|
31
34
|
// Initialization
|
|
@@ -83,3 +86,15 @@ export {
|
|
|
83
86
|
printSeparator,
|
|
84
87
|
printHeader,
|
|
85
88
|
} from "./utils";
|
|
89
|
+
|
|
90
|
+
// User utilities
|
|
91
|
+
export {
|
|
92
|
+
getUserData,
|
|
93
|
+
initializeUserCredits,
|
|
94
|
+
addUserCredits,
|
|
95
|
+
setUserCredits,
|
|
96
|
+
listUsersWithCredits,
|
|
97
|
+
deleteUserCredits,
|
|
98
|
+
getCreditsSummary,
|
|
99
|
+
printUserData,
|
|
100
|
+
} from "./user";
|
package/scripts/types.ts
CHANGED
|
@@ -53,3 +53,32 @@ export interface ResetSummary {
|
|
|
53
53
|
firestoreDocsDeleted: number;
|
|
54
54
|
storageFilesDeleted: number;
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
/** User credits data */
|
|
58
|
+
export interface UserCredits {
|
|
59
|
+
text: number;
|
|
60
|
+
image: number;
|
|
61
|
+
video: number;
|
|
62
|
+
audio: number;
|
|
63
|
+
createdAt?: Date;
|
|
64
|
+
updatedAt?: Date;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Complete user data including all related collections */
|
|
68
|
+
export interface UserData {
|
|
69
|
+
userId: string;
|
|
70
|
+
exists: boolean;
|
|
71
|
+
profile: Record<string, unknown> | null;
|
|
72
|
+
credits: UserCredits | null;
|
|
73
|
+
subscriptions: Array<Record<string, unknown>>;
|
|
74
|
+
transactions: Array<Record<string, unknown>>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Credits initialization config */
|
|
78
|
+
export interface CreditsConfig {
|
|
79
|
+
collectionName?: string;
|
|
80
|
+
textLimit?: number;
|
|
81
|
+
imageLimit?: number;
|
|
82
|
+
videoLimit?: number;
|
|
83
|
+
audioLimit?: number;
|
|
84
|
+
}
|