@digitalaidseattle/firebase 1.0.10 → 1.0.13
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/declarations/src/FirebaseAuthService.d.ts +12 -6
- package/dist/declarations/src/FirebaseStorageService.d.ts +9 -6
- package/dist/declarations/src/FirestoreService.d.ts +5 -3
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/digitalaidseattle-firebase.cjs.dev.js +177 -144
- package/dist/digitalaidseattle-firebase.cjs.prod.js +177 -144
- package/dist/digitalaidseattle-firebase.esm.js +181 -147
- package/package.json +3 -3
- package/dist/declarations/src/GeminiService.d.ts +0 -25
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* storageService.ts
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2024 Digital Aid Seattle
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import { AuthError, AuthService, OAuthResponse } from '@digitalaidseattle/core';
|
|
8
|
+
import { FirebaseApp } from 'firebase/app';
|
|
9
|
+
import { Auth } from 'firebase/auth';
|
|
10
|
+
export declare class FirebaseAuthService implements AuthService {
|
|
11
|
+
auth: Auth;
|
|
12
|
+
constructor(firebaseClient: FirebaseApp);
|
|
6
13
|
getProviders(): string[];
|
|
7
14
|
signInWith(provider: string): Promise<OAuthResponse>;
|
|
8
15
|
hasUser(): Promise<boolean>;
|
|
@@ -12,4 +19,3 @@ declare class FirebaseAuthService implements AuthService {
|
|
|
12
19
|
}>;
|
|
13
20
|
signInWithGoogle: () => Promise<any>;
|
|
14
21
|
}
|
|
15
|
-
export { FirebaseAuthService };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* FirebaseStorageService.ts
|
|
3
3
|
*
|
|
4
|
-
* @copyright
|
|
4
|
+
* @copyright 2026 Digital Aid Seattle
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
import { StorageService } from "@digitalaidseattle/core";
|
|
8
|
+
import { FirebaseApp } from "firebase/app";
|
|
9
|
+
import { FirebaseStorage } from "firebase/storage";
|
|
8
10
|
export declare class FirebaseStorageService implements StorageService {
|
|
9
|
-
storage:
|
|
11
|
+
storage: FirebaseStorage;
|
|
10
12
|
decoder: TextDecoder;
|
|
13
|
+
constructor(firebaseClient: FirebaseApp);
|
|
11
14
|
downloadFile: (filepath: string) => Promise<string>;
|
|
12
15
|
getUrlAsync(filepath: string): Promise<string>;
|
|
13
|
-
list(filepath?: string): Promise<any[]>;
|
|
14
16
|
getUrl(filepath: string): string;
|
|
15
|
-
upload(path: string, blob: any): Promise<any>;
|
|
16
17
|
downloadBlob(filepath: string): Promise<Blob | null>;
|
|
17
|
-
removeFile(
|
|
18
|
+
removeFile(path: string): Promise<void>;
|
|
19
|
+
list(filepath?: string): Promise<any[]>;
|
|
20
|
+
upload(path: string, file: any): Promise<any>;
|
|
18
21
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Entity, EntityService, Identifier, User } from "@digitalaidseattle/core";
|
|
2
|
+
import { Firestore } from "firebase/firestore";
|
|
3
|
+
import { FirebaseApp } from "firebase/app";
|
|
2
4
|
declare class FirestoreService<T extends Entity> implements EntityService<T> {
|
|
3
5
|
collectionName: string;
|
|
4
|
-
db:
|
|
5
|
-
constructor(collectionName: string);
|
|
6
|
+
db: Firestore;
|
|
7
|
+
constructor(collectionName: string, firebaseClient?: FirebaseApp);
|
|
6
8
|
getAll(count?: number, select?: string, mapper?: (json: any) => T): Promise<T[]>;
|
|
7
9
|
getById(id: string, select?: string, mapper?: (json: any) => T): Promise<T>;
|
|
8
10
|
batchInsert(entities: T[], select?: string, mapper?: (json: any) => T, user?: User): Promise<T[]>;
|
|
9
11
|
insert(entity: T, select?: string, mapper?: (json: any) => T, user?: User): Promise<T>;
|
|
10
12
|
update(entityId: Identifier, updatedFields: Partial<T>, select?: string, mapper?: (json: any) => T, user?: User): Promise<T>;
|
|
11
13
|
delete(entityId: Identifier): Promise<void>;
|
|
14
|
+
upsert(entity: T): Promise<T>;
|
|
12
15
|
}
|
|
13
16
|
export { FirestoreService };
|
|
14
|
-
export type { Entity };
|
|
@@ -12,37 +12,33 @@ var app = require('firebase/app');
|
|
|
12
12
|
var storage = require('firebase/storage');
|
|
13
13
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
14
14
|
var firestore = require('firebase/firestore');
|
|
15
|
-
var firebase = require('@digitalaidseattle/firebase');
|
|
16
|
-
var ai = require('firebase/ai');
|
|
17
15
|
|
|
18
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
17
|
|
|
20
18
|
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
19
|
|
|
22
|
-
var firebaseConfig = {
|
|
23
|
-
apiKey: undefined.VITE_FIREBASE_API_KEY,
|
|
24
|
-
authDomain: undefined.VITE_FIREBASE_AUTH_DOMAIN,
|
|
25
|
-
projectId: undefined.VITE_FIREBASE_PROJECT_ID,
|
|
26
|
-
storageBucket: undefined.VITE_FIREBASE_STORAGE_BUCKET,
|
|
27
|
-
messagingSenderId: undefined.VITE_FIREBASE_MESSAGING_SENDER_ID,
|
|
28
|
-
appId: undefined.VITE_FIREBASE_APP_ID,
|
|
29
|
-
measurementId: undefined.VITE_FIREBASE_MEASUREMENT_ID
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// Initialize Firebase
|
|
33
|
-
var firebaseClient = app.initializeApp(firebaseConfig);
|
|
34
|
-
|
|
35
20
|
var FirebaseAuthService = /*#__PURE__*/function () {
|
|
36
|
-
function FirebaseAuthService() {
|
|
21
|
+
function FirebaseAuthService(firebaseClient) {
|
|
37
22
|
var _this = this;
|
|
38
23
|
_classCallCheck(this, FirebaseAuthService);
|
|
39
|
-
_defineProperty(this, "currentUser", undefined);
|
|
40
|
-
_defineProperty(this, "auth", auth.getAuth(firebaseClient));
|
|
41
24
|
_defineProperty(this, "getUser", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
42
25
|
return _regeneratorRuntime__default["default"].wrap(function (_context) {
|
|
43
26
|
while (1) switch (_context.prev = _context.next) {
|
|
44
27
|
case 0:
|
|
45
|
-
return _context.abrupt("return",
|
|
28
|
+
return _context.abrupt("return", new Promise(function (resolve) {
|
|
29
|
+
var unsubscribe = auth.onAuthStateChanged(_this.auth, function (gUser) {
|
|
30
|
+
unsubscribe(); // stop listening after first call
|
|
31
|
+
var user = gUser ? {
|
|
32
|
+
email: gUser.email,
|
|
33
|
+
user_metadata: {
|
|
34
|
+
name: gUser.displayName,
|
|
35
|
+
avatar_url: gUser.photoURL,
|
|
36
|
+
email: gUser.email
|
|
37
|
+
}
|
|
38
|
+
} : null;
|
|
39
|
+
resolve(user);
|
|
40
|
+
});
|
|
41
|
+
}));
|
|
46
42
|
case 1:
|
|
47
43
|
case "end":
|
|
48
44
|
return _context.stop();
|
|
@@ -53,19 +49,20 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
53
49
|
return _regeneratorRuntime__default["default"].wrap(function (_context2) {
|
|
54
50
|
while (1) switch (_context2.prev = _context2.next) {
|
|
55
51
|
case 0:
|
|
56
|
-
|
|
57
|
-
_this.auth.signOut();
|
|
52
|
+
_context2.next = 1;
|
|
53
|
+
return _this.auth.signOut();
|
|
54
|
+
case 1:
|
|
58
55
|
return _context2.abrupt("return", {
|
|
59
56
|
error: null
|
|
60
57
|
});
|
|
61
|
-
case
|
|
58
|
+
case 2:
|
|
62
59
|
case "end":
|
|
63
60
|
return _context2.stop();
|
|
64
61
|
}
|
|
65
62
|
}, _callee2);
|
|
66
63
|
})));
|
|
67
64
|
_defineProperty(this, "signInWithGoogle", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
|
|
68
|
-
var provider,
|
|
65
|
+
var provider, _t;
|
|
69
66
|
return _regeneratorRuntime__default["default"].wrap(function (_context3) {
|
|
70
67
|
while (1) switch (_context3.prev = _context3.next) {
|
|
71
68
|
case 0:
|
|
@@ -74,15 +71,6 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
74
71
|
_context3.next = 1;
|
|
75
72
|
return auth.signInWithPopup(_this.auth, provider);
|
|
76
73
|
case 1:
|
|
77
|
-
resp = _context3.sent;
|
|
78
|
-
_this.currentUser = {
|
|
79
|
-
email: resp.user.email,
|
|
80
|
-
user_metadata: {
|
|
81
|
-
name: resp.user.displayName,
|
|
82
|
-
avatar_url: resp.user.photoURL,
|
|
83
|
-
email: resp.user.email
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
74
|
return _context3.abrupt("return", {
|
|
87
75
|
data: {
|
|
88
76
|
url: undefined.VITE_AUTH_DOMAIN
|
|
@@ -99,18 +87,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
99
87
|
}
|
|
100
88
|
}, _callee3, null, [[0, 2]]);
|
|
101
89
|
})));
|
|
102
|
-
this.auth.
|
|
103
|
-
if (user) {
|
|
104
|
-
_this.currentUser = {
|
|
105
|
-
email: user.email,
|
|
106
|
-
user_metadata: {
|
|
107
|
-
name: user.displayName,
|
|
108
|
-
avatar_url: user.photoURL,
|
|
109
|
-
email: user.email
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
90
|
+
this.auth = auth.getAuth(firebaseClient);
|
|
114
91
|
}
|
|
115
92
|
return _createClass(FirebaseAuthService, [{
|
|
116
93
|
key: "getProviders",
|
|
@@ -130,17 +107,34 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
130
107
|
}, {
|
|
131
108
|
key: "hasUser",
|
|
132
109
|
value: function hasUser() {
|
|
133
|
-
|
|
110
|
+
var _this2 = this;
|
|
111
|
+
return new Promise(function (resolve) {
|
|
112
|
+
var unsubscribe = auth.onAuthStateChanged(_this2.auth, function (user) {
|
|
113
|
+
unsubscribe(); // stop listening after first call
|
|
114
|
+
resolve(user ? true : false);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
134
117
|
}
|
|
135
118
|
}]);
|
|
136
119
|
}();
|
|
137
120
|
|
|
121
|
+
var firebaseConfig = {
|
|
122
|
+
apiKey: undefined.VITE_FIREBASE_API_KEY,
|
|
123
|
+
authDomain: undefined.VITE_FIREBASE_AUTH_DOMAIN,
|
|
124
|
+
projectId: undefined.VITE_FIREBASE_PROJECT_ID,
|
|
125
|
+
storageBucket: undefined.VITE_FIREBASE_STORAGE_BUCKET,
|
|
126
|
+
messagingSenderId: undefined.VITE_FIREBASE_MESSAGING_SENDER_ID,
|
|
127
|
+
appId: undefined.VITE_FIREBASE_APP_ID,
|
|
128
|
+
measurementId: undefined.VITE_FIREBASE_MEASUREMENT_ID
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Initialize Firebase
|
|
132
|
+
var firebaseClient = app.initializeApp(firebaseConfig);
|
|
133
|
+
|
|
138
134
|
var FirebaseStorageService = /*#__PURE__*/function () {
|
|
139
|
-
function FirebaseStorageService() {
|
|
135
|
+
function FirebaseStorageService(firebaseClient) {
|
|
140
136
|
var _this = this;
|
|
141
137
|
_classCallCheck(this, FirebaseStorageService);
|
|
142
|
-
_defineProperty(this, "storage", storage.getStorage(firebaseClient));
|
|
143
|
-
_defineProperty(this, "decoder", new TextDecoder("utf-8"));
|
|
144
138
|
_defineProperty(this, "downloadFile", /*#__PURE__*/function () {
|
|
145
139
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(filepath) {
|
|
146
140
|
var fileRef;
|
|
@@ -161,6 +155,8 @@ var FirebaseStorageService = /*#__PURE__*/function () {
|
|
|
161
155
|
return _ref.apply(this, arguments);
|
|
162
156
|
};
|
|
163
157
|
}());
|
|
158
|
+
this.storage = storage.getStorage(firebaseClient);
|
|
159
|
+
this.decoder = new TextDecoder("utf-8");
|
|
164
160
|
}
|
|
165
161
|
return _createClass(FirebaseStorageService, [{
|
|
166
162
|
key: "getUrlAsync",
|
|
@@ -192,40 +188,136 @@ var FirebaseStorageService = /*#__PURE__*/function () {
|
|
|
192
188
|
}
|
|
193
189
|
return getUrlAsync;
|
|
194
190
|
}()
|
|
195
|
-
}, {
|
|
196
|
-
key: "list",
|
|
197
|
-
value: function list(filepath) {
|
|
198
|
-
throw new Error("Method not implemented.");
|
|
199
|
-
}
|
|
200
191
|
}, {
|
|
201
192
|
key: "getUrl",
|
|
202
193
|
value: function getUrl(filepath) {
|
|
203
194
|
throw new Error("Method not supported.");
|
|
204
195
|
}
|
|
205
|
-
}, {
|
|
206
|
-
key: "upload",
|
|
207
|
-
value: function upload(path, blob) {
|
|
208
|
-
throw new Error("Method not implemented.");
|
|
209
|
-
}
|
|
210
196
|
}, {
|
|
211
197
|
key: "downloadBlob",
|
|
212
198
|
value: function downloadBlob(filepath) {
|
|
213
|
-
|
|
199
|
+
var fileRef = storage.ref(this.storage, filepath);
|
|
200
|
+
return storage.getBytes(fileRef).then(function (bytes) {
|
|
201
|
+
return new Blob([bytes]);
|
|
202
|
+
});
|
|
214
203
|
}
|
|
215
204
|
}, {
|
|
216
205
|
key: "removeFile",
|
|
217
|
-
value: function removeFile(
|
|
218
|
-
|
|
206
|
+
value: function removeFile(path) {
|
|
207
|
+
try {
|
|
208
|
+
var fileRef = storage.ref(this.storage, path);
|
|
209
|
+
return storage.deleteObject(fileRef);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (error.code === "storage/object-not-found") {
|
|
212
|
+
console.warn("File does not exist");
|
|
213
|
+
} else if (error.code === "storage/unauthorized") {
|
|
214
|
+
console.error("User not authorized to delete file");
|
|
215
|
+
} else {
|
|
216
|
+
console.error("Delete failed:", error);
|
|
217
|
+
}
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
219
220
|
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "list",
|
|
223
|
+
value: function () {
|
|
224
|
+
var _list = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(filepath) {
|
|
225
|
+
var folderRef, result, files;
|
|
226
|
+
return _regeneratorRuntime__default["default"].wrap(function (_context4) {
|
|
227
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
228
|
+
case 0:
|
|
229
|
+
if (filepath) {
|
|
230
|
+
_context4.next = 1;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
return _context4.abrupt("return", []);
|
|
234
|
+
case 1:
|
|
235
|
+
folderRef = storage.ref(this.storage, filepath);
|
|
236
|
+
_context4.next = 2;
|
|
237
|
+
return storage.listAll(folderRef);
|
|
238
|
+
case 2:
|
|
239
|
+
result = _context4.sent;
|
|
240
|
+
_context4.next = 3;
|
|
241
|
+
return Promise.all(result.items.map(/*#__PURE__*/function () {
|
|
242
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(item) {
|
|
243
|
+
var metadata;
|
|
244
|
+
return _regeneratorRuntime__default["default"].wrap(function (_context3) {
|
|
245
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
246
|
+
case 0:
|
|
247
|
+
_context3.next = 1;
|
|
248
|
+
return storage.getMetadata(item);
|
|
249
|
+
case 1:
|
|
250
|
+
metadata = _context3.sent;
|
|
251
|
+
return _context3.abrupt("return", {
|
|
252
|
+
name: item.name,
|
|
253
|
+
fullPath: item.fullPath,
|
|
254
|
+
type: metadata.contentType,
|
|
255
|
+
size: metadata.size,
|
|
256
|
+
updated: metadata.updated
|
|
257
|
+
});
|
|
258
|
+
case 2:
|
|
259
|
+
case "end":
|
|
260
|
+
return _context3.stop();
|
|
261
|
+
}
|
|
262
|
+
}, _callee3);
|
|
263
|
+
}));
|
|
264
|
+
return function (_x4) {
|
|
265
|
+
return _ref2.apply(this, arguments);
|
|
266
|
+
};
|
|
267
|
+
}()));
|
|
268
|
+
case 3:
|
|
269
|
+
files = _context4.sent;
|
|
270
|
+
return _context4.abrupt("return", files);
|
|
271
|
+
case 4:
|
|
272
|
+
case "end":
|
|
273
|
+
return _context4.stop();
|
|
274
|
+
}
|
|
275
|
+
}, _callee4, this);
|
|
276
|
+
}));
|
|
277
|
+
function list(_x3) {
|
|
278
|
+
return _list.apply(this, arguments);
|
|
279
|
+
}
|
|
280
|
+
return list;
|
|
281
|
+
}()
|
|
282
|
+
}, {
|
|
283
|
+
key: "upload",
|
|
284
|
+
value: function () {
|
|
285
|
+
var _upload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(path, file) {
|
|
286
|
+
var storageRef, snapshot, downloadUrl;
|
|
287
|
+
return _regeneratorRuntime__default["default"].wrap(function (_context5) {
|
|
288
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
289
|
+
case 0:
|
|
290
|
+
storageRef = storage.ref(this.storage, path); // Upload file
|
|
291
|
+
_context5.next = 1;
|
|
292
|
+
return storage.uploadBytes(storageRef, file, {
|
|
293
|
+
contentType: file === null || file === void 0 ? void 0 : file.type
|
|
294
|
+
});
|
|
295
|
+
case 1:
|
|
296
|
+
snapshot = _context5.sent;
|
|
297
|
+
_context5.next = 2;
|
|
298
|
+
return storage.getDownloadURL(snapshot.ref);
|
|
299
|
+
case 2:
|
|
300
|
+
downloadUrl = _context5.sent;
|
|
301
|
+
return _context5.abrupt("return", downloadUrl);
|
|
302
|
+
case 3:
|
|
303
|
+
case "end":
|
|
304
|
+
return _context5.stop();
|
|
305
|
+
}
|
|
306
|
+
}, _callee5, this);
|
|
307
|
+
}));
|
|
308
|
+
function upload(_x5, _x6) {
|
|
309
|
+
return _upload.apply(this, arguments);
|
|
310
|
+
}
|
|
311
|
+
return upload;
|
|
312
|
+
}()
|
|
220
313
|
}]);
|
|
221
314
|
}();
|
|
222
315
|
|
|
223
316
|
var FirestoreService = /*#__PURE__*/function () {
|
|
224
|
-
function FirestoreService(collectionName) {
|
|
317
|
+
function FirestoreService(collectionName, firebaseClient$1) {
|
|
225
318
|
_classCallCheck(this, FirestoreService);
|
|
226
|
-
_defineProperty(this, "collectionName", "player");
|
|
227
|
-
_defineProperty(this, "db", firestore.getFirestore(firebaseClient));
|
|
228
319
|
this.collectionName = collectionName;
|
|
320
|
+
this.db = firestore.getFirestore(firebaseClient$1 !== null && firebaseClient$1 !== void 0 ? firebaseClient$1 : firebaseClient);
|
|
229
321
|
}
|
|
230
322
|
|
|
231
323
|
// Get all documents from a collection
|
|
@@ -395,7 +487,6 @@ var FirestoreService = /*#__PURE__*/function () {
|
|
|
395
487
|
return _regeneratorRuntime__default["default"].wrap(function (_context6) {
|
|
396
488
|
while (1) switch (_context6.prev = _context6.next) {
|
|
397
489
|
case 0:
|
|
398
|
-
console.log('delete', entityId);
|
|
399
490
|
return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
|
|
400
491
|
case 1:
|
|
401
492
|
case "end":
|
|
@@ -408,90 +499,32 @@ var FirestoreService = /*#__PURE__*/function () {
|
|
|
408
499
|
}
|
|
409
500
|
return _delete;
|
|
410
501
|
}()
|
|
411
|
-
}]);
|
|
412
|
-
}();
|
|
413
|
-
|
|
414
|
-
var GeminiService = /*#__PURE__*/function () {
|
|
415
|
-
function GeminiService(modelType) {
|
|
416
|
-
_classCallCheck(this, GeminiService);
|
|
417
|
-
this.ai = ai.getAI(firebase.firebaseClient, {
|
|
418
|
-
backend: new ai.GoogleAIBackend()
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
return _createClass(GeminiService, [{
|
|
422
|
-
key: "getModels",
|
|
423
|
-
value: function getModels() {
|
|
424
|
-
return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
|
|
425
|
-
}
|
|
426
502
|
}, {
|
|
427
|
-
key: "
|
|
428
|
-
value: function
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
throw new Error("Failed to query AI: " + error.message);
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Wrap in an async function so you can use await
|
|
453
|
-
}, {
|
|
454
|
-
key: "generateParameterizedContent",
|
|
455
|
-
value: function generateParameterizedContent(model, prompt, schemaParams) {
|
|
456
|
-
// Provide a JSON schema object using a standard format.
|
|
457
|
-
// Later, pass this schema object into `responseSchema` in the generation config.
|
|
458
|
-
var schema = ai.Schema.object({
|
|
459
|
-
properties: {
|
|
460
|
-
characters: ai.Schema.array({
|
|
461
|
-
items: ai.Schema.object({
|
|
462
|
-
properties: Object.fromEntries(schemaParams.map(function (field) {
|
|
463
|
-
return [field, ai.Schema.string()];
|
|
464
|
-
}))
|
|
465
|
-
})
|
|
466
|
-
})
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// Create a `GenerativeModel` instance with a model that supports your use case
|
|
471
|
-
var jModel = ai.getGenerativeModel(this.ai, {
|
|
472
|
-
model: model,
|
|
473
|
-
// In the generation config, set the `responseMimeType` to `application/json`
|
|
474
|
-
// and pass the JSON schema object into `responseSchema`.
|
|
475
|
-
generationConfig: {
|
|
476
|
-
responseMimeType: "application/json",
|
|
477
|
-
responseSchema: schema
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// To generate text output, call generateContent with the text input
|
|
482
|
-
return jModel.generateContent(prompt).then(function (result) {
|
|
483
|
-
var content = result.response.text();
|
|
484
|
-
return JSON.parse(content).characters[0];
|
|
485
|
-
})["catch"](function (error) {
|
|
486
|
-
console.error("Error querying AI: ", error);
|
|
487
|
-
throw new Error("Failed to query AI: " + error.message);
|
|
488
|
-
});
|
|
489
|
-
}
|
|
503
|
+
key: "upsert",
|
|
504
|
+
value: function () {
|
|
505
|
+
var _upsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(entity) {
|
|
506
|
+
return _regeneratorRuntime__default["default"].wrap(function (_context7) {
|
|
507
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
508
|
+
case 0:
|
|
509
|
+
_context7.next = 1;
|
|
510
|
+
return firestore.setDoc(firestore.doc(this.db, this.collectionName, entity.id), entity);
|
|
511
|
+
case 1:
|
|
512
|
+
return _context7.abrupt("return", entity);
|
|
513
|
+
case 2:
|
|
514
|
+
case "end":
|
|
515
|
+
return _context7.stop();
|
|
516
|
+
}
|
|
517
|
+
}, _callee7, this);
|
|
518
|
+
}));
|
|
519
|
+
function upsert(_x19) {
|
|
520
|
+
return _upsert.apply(this, arguments);
|
|
521
|
+
}
|
|
522
|
+
return upsert;
|
|
523
|
+
}()
|
|
490
524
|
}]);
|
|
491
525
|
}();
|
|
492
526
|
|
|
493
527
|
exports.FirebaseAuthService = FirebaseAuthService;
|
|
494
528
|
exports.FirebaseStorageService = FirebaseStorageService;
|
|
495
529
|
exports.FirestoreService = FirestoreService;
|
|
496
|
-
exports.GeminiService = GeminiService;
|
|
497
530
|
exports.firebaseClient = firebaseClient;
|