@thzero/library_server_firebase 0.18.16 → 0.18.19
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/README.md +15 -15
- package/auth/index.js +225 -225
- package/license.md +8 -8
- package/messaging/index.js +31 -31
- package/openSource.js +31 -31
- package/package.json +33 -33
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-

|
|
2
|
-

|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
|
|
5
|
-
# library_server_firebase
|
|
6
|
-
|
|
7
|
-
## Requirements
|
|
8
|
-
|
|
9
|
-
### NodeJs
|
|
10
|
-
|
|
11
|
-
[NodeJs](https://nodejs.org) version 18+
|
|
12
|
-
|
|
13
|
-
### Installation
|
|
14
|
-
|
|
15
|
-
[](https://npmjs.org/package/@thzero/library_server_firebase)
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
# library_server_firebase
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
### NodeJs
|
|
10
|
+
|
|
11
|
+
[NodeJs](https://nodejs.org) version 18+
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
[](https://npmjs.org/package/@thzero/library_server_firebase)
|
package/auth/index.js
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import { Mutex as asyncMutex } from 'async-mutex';
|
|
5
|
-
|
|
6
|
-
import admin from 'firebase-admin';
|
|
7
|
-
|
|
8
|
-
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
9
|
-
|
|
10
|
-
import LibraryMomentUtility from '@thzero/library_common/utility/moment.js';
|
|
11
|
-
|
|
12
|
-
import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
|
|
13
|
-
|
|
14
|
-
import Service from '@thzero/library_server/service/index.js';
|
|
15
|
-
|
|
16
|
-
import TokenExpiredError from '@thzero/library_server/errors/tokenExpired.js';
|
|
17
|
-
|
|
18
|
-
class FirebaseAuthAdminService extends Service {
|
|
19
|
-
constructor() {
|
|
20
|
-
super();
|
|
21
|
-
|
|
22
|
-
this._cacheTokens = new Map();
|
|
23
|
-
this._cacheTokensTtlDefault = 5 * 60 * 1000;
|
|
24
|
-
this._mutexCache = new asyncMutex();
|
|
25
|
-
|
|
26
|
-
this._serviceUsers = null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async init(injector) {
|
|
30
|
-
await super.init(injector);
|
|
31
|
-
|
|
32
|
-
let serviceAccount = process.env.SERVICE_ACCOUNT_KEY;
|
|
33
|
-
if (serviceAccount)
|
|
34
|
-
serviceAccount = JSON.parse(serviceAccount);
|
|
35
|
-
if (!serviceAccount)
|
|
36
|
-
serviceAccount = this._initConfig();
|
|
37
|
-
admin.initializeApp({
|
|
38
|
-
credential: admin.credential.cert(serviceAccount),
|
|
39
|
-
databaseURL: serviceAccount.database_url
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
this._serviceUsers = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async deleteUser(correlationId, uid) {
|
|
46
|
-
try {
|
|
47
|
-
if (String.isNullOrEmpty(uid))
|
|
48
|
-
return null;
|
|
49
|
-
|
|
50
|
-
const user = await admin.auth().getUser(uid);
|
|
51
|
-
if (!user)
|
|
52
|
-
return null;
|
|
53
|
-
|
|
54
|
-
const results = await admin.auth().deleteUser(uid);
|
|
55
|
-
if (!results)
|
|
56
|
-
return this._error('FirebaseAuthAdminService', 'deleteUser', 'Unable to delete user.', null, null, null, correlationId);
|
|
57
|
-
|
|
58
|
-
return this._success(correlationId);
|
|
59
|
-
}
|
|
60
|
-
catch(err) {
|
|
61
|
-
if (err.code && err.code === 'auth/user-not-found') {
|
|
62
|
-
this._logger.warn('FirebaseAuthAdminService', 'deleteUser', 'user not found', err, correlationId);
|
|
63
|
-
return this._error('FirebaseAuthAdminService', 'deleteUser', 'user-not-found', err, correlationId);
|
|
64
|
-
}
|
|
65
|
-
this._logger.exception('FirebaseAuthAdminService', 'deleteUser', err, correlationId);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return this._error('FirebaseAuthAdminService', 'deleteUser', null, null, null, correlationId);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async getUser(correlationId, uid) {
|
|
72
|
-
try {
|
|
73
|
-
if (String.isNullOrEmpty(uid))
|
|
74
|
-
return null;
|
|
75
|
-
|
|
76
|
-
const user = await admin.auth().getUser(uid);
|
|
77
|
-
if (!user)
|
|
78
|
-
return null;
|
|
79
|
-
|
|
80
|
-
return this._convert(user);
|
|
81
|
-
}
|
|
82
|
-
catch(err) {
|
|
83
|
-
this._logger.exception('FirebaseAuthAdminService', 'getUser', err, correlationId);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return null
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async setClaims(correlationId, uid, claims, replace) {
|
|
90
|
-
try {
|
|
91
|
-
this._enforceNotEmpty('FirebaseAuthAdminService', 'deleteUser', uid, 'uid', correlationId);
|
|
92
|
-
|
|
93
|
-
// Lookup the user associated with the specified uid.
|
|
94
|
-
const user = await admin.auth().getUser(uid);
|
|
95
|
-
if (!user)
|
|
96
|
-
return this._error('FirebaseAuthAdminService', 'deleteUser', 'Unable to get user', null, null, null, correlationId);
|
|
97
|
-
|
|
98
|
-
let updatedClaims = claims ? { ...claims } : null;
|
|
99
|
-
if (!replace) {
|
|
100
|
-
const customClaims = user.customClaims;
|
|
101
|
-
// merge new claims into existing
|
|
102
|
-
updatedClaims = { ...customClaims, ...claims };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// The new custom claims will propagate to the user's ID token the
|
|
106
|
-
// next time a new one is issued.
|
|
107
|
-
await admin.auth().setCustomUserClaims(uid, updatedClaims);
|
|
108
|
-
|
|
109
|
-
return this._success(correlationId);
|
|
110
|
-
}
|
|
111
|
-
catch(err) {
|
|
112
|
-
this._logger.exception('FirebaseAuthAdminService', 'setClaims', err, correlationId);
|
|
113
|
-
return this._error('FirebaseAuthAdminService', 'setClaims', err, null, null, null, correlationId);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async verifyToken(correlationId, token) {
|
|
118
|
-
try {
|
|
119
|
-
const results = {
|
|
120
|
-
user: null,
|
|
121
|
-
claims: null,
|
|
122
|
-
success: false
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (String.isNullOrEmpty(token))
|
|
126
|
-
return results;
|
|
127
|
-
|
|
128
|
-
if (this._cacheTokens.has(token)) {
|
|
129
|
-
// https://firebase.google.com/docs/auth/admin/manage-sessions
|
|
130
|
-
// firebase tokens are valid for an hour
|
|
131
|
-
// buffering...
|
|
132
|
-
const release = await this._mutexCache.acquire();
|
|
133
|
-
try {
|
|
134
|
-
if (this._cacheTokens.has(token)) {
|
|
135
|
-
const data = this._cacheTokens.get(token);
|
|
136
|
-
if (data) {
|
|
137
|
-
const now = LibraryMomentUtility.getTimestamp();
|
|
138
|
-
const delta = now - data.time;
|
|
139
|
-
if (delta <= this._cacheTokensTtlDefault)
|
|
140
|
-
return data.results;
|
|
141
|
-
|
|
142
|
-
this._cacheTokens.delete(token);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
finally {
|
|
147
|
-
release();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const decodedToken = await admin.auth().verifyIdToken(token);
|
|
152
|
-
if (!decodedToken)
|
|
153
|
-
return results;
|
|
154
|
-
|
|
155
|
-
this._logger.debug('FirebaseAuthAdminService', 'verifyToken', 'decodedToken', decodedToken, correlationId);
|
|
156
|
-
|
|
157
|
-
const uid = decodedToken.uid;
|
|
158
|
-
if (!uid)
|
|
159
|
-
return results;
|
|
160
|
-
|
|
161
|
-
// Getting user from database, which has the claims already, plus plan, etc.
|
|
162
|
-
// Lookup the user associated with the specified uid.
|
|
163
|
-
// const user = await admin.auth().getUser(uid);
|
|
164
|
-
// const claims = user.customClaims;
|
|
165
|
-
|
|
166
|
-
const userResponse = await this._serviceUsers.fetchByExternalId(correlationId, uid);
|
|
167
|
-
if (this._hasFailed(userResponse) || (this._hasSucceeded(userResponse) && !userResponse.results)) {
|
|
168
|
-
const userUpdateResponse = this._serviceUsers.update(correlationId, {
|
|
169
|
-
id: uid
|
|
170
|
-
});
|
|
171
|
-
if (this._hasFailed(userUpdateResponse) || (this._hasSucceeded(userUpdateResponse) && !userUpdateResponse.results))
|
|
172
|
-
return results;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
results.user = userResponse.results;
|
|
176
|
-
|
|
177
|
-
results.claims = userResponse.results.claims;
|
|
178
|
-
const configAuth = this._config.get('auth');
|
|
179
|
-
if (configAuth.claims && configAuth.claims.useDefault && !results.claims)
|
|
180
|
-
results.claims = [ this._defaultClaims() ];
|
|
181
|
-
|
|
182
|
-
this._cacheTokens.set(token, { time: LibraryMomentUtility.getTimestamp(), results: results });
|
|
183
|
-
results.success = true;
|
|
184
|
-
return results;
|
|
185
|
-
}
|
|
186
|
-
catch(err) {
|
|
187
|
-
this._logger.exception('FirebaseAuthAdminService', 'verifyToken', err, correlationId);
|
|
188
|
-
if (err.code === "auth/id-token-expired")
|
|
189
|
-
throw new TokenExpiredError();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
_convert(requestedUser) {
|
|
196
|
-
if (!requestedUser)
|
|
197
|
-
return null;
|
|
198
|
-
|
|
199
|
-
const user = {};
|
|
200
|
-
user.id = requestedUser.uid;
|
|
201
|
-
user.name = requestedUser.displayName;
|
|
202
|
-
user.picture = requestedUser.photoURL;
|
|
203
|
-
user.email = requestedUser.email;
|
|
204
|
-
return user;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
_defaultClaims() {
|
|
208
|
-
throw new NotImplementedError();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
_initConfig() {
|
|
212
|
-
const filePath = path.join(process.cwd(), 'config', 'serviceAccountKey.json');
|
|
213
|
-
const file = fs.readFileSync(filePath, 'utf8');
|
|
214
|
-
if (String.isNullOrEmpty(file))
|
|
215
|
-
throw Error('Invalid serviceAccountKey.json configuration file for Firebase; expected in the <app root>/config folder.');
|
|
216
|
-
|
|
217
|
-
const config = JSON.parse(file);
|
|
218
|
-
if (!config)
|
|
219
|
-
throw Error('Invalid serviceAccountKey.json file for Firebase config.');
|
|
220
|
-
|
|
221
|
-
return config;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export default FirebaseAuthAdminService;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import { Mutex as asyncMutex } from 'async-mutex';
|
|
5
|
+
|
|
6
|
+
import admin from 'firebase-admin';
|
|
7
|
+
|
|
8
|
+
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
9
|
+
|
|
10
|
+
import LibraryMomentUtility from '@thzero/library_common/utility/moment.js';
|
|
11
|
+
|
|
12
|
+
import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
|
|
13
|
+
|
|
14
|
+
import Service from '@thzero/library_server/service/index.js';
|
|
15
|
+
|
|
16
|
+
import TokenExpiredError from '@thzero/library_server/errors/tokenExpired.js';
|
|
17
|
+
|
|
18
|
+
class FirebaseAuthAdminService extends Service {
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
this._cacheTokens = new Map();
|
|
23
|
+
this._cacheTokensTtlDefault = 5 * 60 * 1000;
|
|
24
|
+
this._mutexCache = new asyncMutex();
|
|
25
|
+
|
|
26
|
+
this._serviceUsers = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async init(injector) {
|
|
30
|
+
await super.init(injector);
|
|
31
|
+
|
|
32
|
+
let serviceAccount = process.env.SERVICE_ACCOUNT_KEY;
|
|
33
|
+
if (serviceAccount)
|
|
34
|
+
serviceAccount = JSON.parse(serviceAccount);
|
|
35
|
+
if (!serviceAccount)
|
|
36
|
+
serviceAccount = this._initConfig();
|
|
37
|
+
admin.initializeApp({
|
|
38
|
+
credential: admin.credential.cert(serviceAccount),
|
|
39
|
+
databaseURL: serviceAccount.database_url
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this._serviceUsers = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async deleteUser(correlationId, uid) {
|
|
46
|
+
try {
|
|
47
|
+
if (String.isNullOrEmpty(uid))
|
|
48
|
+
return null;
|
|
49
|
+
|
|
50
|
+
const user = await admin.auth().getUser(uid);
|
|
51
|
+
if (!user)
|
|
52
|
+
return null;
|
|
53
|
+
|
|
54
|
+
const results = await admin.auth().deleteUser(uid);
|
|
55
|
+
if (!results)
|
|
56
|
+
return this._error('FirebaseAuthAdminService', 'deleteUser', 'Unable to delete user.', null, null, null, correlationId);
|
|
57
|
+
|
|
58
|
+
return this._success(correlationId);
|
|
59
|
+
}
|
|
60
|
+
catch(err) {
|
|
61
|
+
if (err.code && err.code === 'auth/user-not-found') {
|
|
62
|
+
this._logger.warn('FirebaseAuthAdminService', 'deleteUser', 'user not found', err, correlationId);
|
|
63
|
+
return this._error('FirebaseAuthAdminService', 'deleteUser', 'user-not-found', err, correlationId);
|
|
64
|
+
}
|
|
65
|
+
this._logger.exception('FirebaseAuthAdminService', 'deleteUser', err, correlationId);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return this._error('FirebaseAuthAdminService', 'deleteUser', null, null, null, correlationId);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getUser(correlationId, uid) {
|
|
72
|
+
try {
|
|
73
|
+
if (String.isNullOrEmpty(uid))
|
|
74
|
+
return null;
|
|
75
|
+
|
|
76
|
+
const user = await admin.auth().getUser(uid);
|
|
77
|
+
if (!user)
|
|
78
|
+
return null;
|
|
79
|
+
|
|
80
|
+
return this._convert(user);
|
|
81
|
+
}
|
|
82
|
+
catch(err) {
|
|
83
|
+
this._logger.exception('FirebaseAuthAdminService', 'getUser', err, correlationId);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async setClaims(correlationId, uid, claims, replace) {
|
|
90
|
+
try {
|
|
91
|
+
this._enforceNotEmpty('FirebaseAuthAdminService', 'deleteUser', uid, 'uid', correlationId);
|
|
92
|
+
|
|
93
|
+
// Lookup the user associated with the specified uid.
|
|
94
|
+
const user = await admin.auth().getUser(uid);
|
|
95
|
+
if (!user)
|
|
96
|
+
return this._error('FirebaseAuthAdminService', 'deleteUser', 'Unable to get user', null, null, null, correlationId);
|
|
97
|
+
|
|
98
|
+
let updatedClaims = claims ? { ...claims } : null;
|
|
99
|
+
if (!replace) {
|
|
100
|
+
const customClaims = user.customClaims;
|
|
101
|
+
// merge new claims into existing
|
|
102
|
+
updatedClaims = { ...customClaims, ...claims };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The new custom claims will propagate to the user's ID token the
|
|
106
|
+
// next time a new one is issued.
|
|
107
|
+
await admin.auth().setCustomUserClaims(uid, updatedClaims);
|
|
108
|
+
|
|
109
|
+
return this._success(correlationId);
|
|
110
|
+
}
|
|
111
|
+
catch(err) {
|
|
112
|
+
this._logger.exception('FirebaseAuthAdminService', 'setClaims', err, correlationId);
|
|
113
|
+
return this._error('FirebaseAuthAdminService', 'setClaims', err, null, null, null, correlationId);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async verifyToken(correlationId, token) {
|
|
118
|
+
try {
|
|
119
|
+
const results = {
|
|
120
|
+
user: null,
|
|
121
|
+
claims: null,
|
|
122
|
+
success: false
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (String.isNullOrEmpty(token))
|
|
126
|
+
return results;
|
|
127
|
+
|
|
128
|
+
if (this._cacheTokens.has(token)) {
|
|
129
|
+
// https://firebase.google.com/docs/auth/admin/manage-sessions
|
|
130
|
+
// firebase tokens are valid for an hour
|
|
131
|
+
// buffering...
|
|
132
|
+
const release = await this._mutexCache.acquire();
|
|
133
|
+
try {
|
|
134
|
+
if (this._cacheTokens.has(token)) {
|
|
135
|
+
const data = this._cacheTokens.get(token);
|
|
136
|
+
if (data) {
|
|
137
|
+
const now = LibraryMomentUtility.getTimestamp();
|
|
138
|
+
const delta = now - data.time;
|
|
139
|
+
if (delta <= this._cacheTokensTtlDefault)
|
|
140
|
+
return data.results;
|
|
141
|
+
|
|
142
|
+
this._cacheTokens.delete(token);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
release();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const decodedToken = await admin.auth().verifyIdToken(token);
|
|
152
|
+
if (!decodedToken)
|
|
153
|
+
return results;
|
|
154
|
+
|
|
155
|
+
this._logger.debug('FirebaseAuthAdminService', 'verifyToken', 'decodedToken', decodedToken, correlationId);
|
|
156
|
+
|
|
157
|
+
const uid = decodedToken.uid;
|
|
158
|
+
if (!uid)
|
|
159
|
+
return results;
|
|
160
|
+
|
|
161
|
+
// Getting user from database, which has the claims already, plus plan, etc.
|
|
162
|
+
// Lookup the user associated with the specified uid.
|
|
163
|
+
// const user = await admin.auth().getUser(uid);
|
|
164
|
+
// const claims = user.customClaims;
|
|
165
|
+
|
|
166
|
+
const userResponse = await this._serviceUsers.fetchByExternalId(correlationId, uid);
|
|
167
|
+
if (this._hasFailed(userResponse) || (this._hasSucceeded(userResponse) && !userResponse.results)) {
|
|
168
|
+
const userUpdateResponse = this._serviceUsers.update(correlationId, {
|
|
169
|
+
id: uid
|
|
170
|
+
});
|
|
171
|
+
if (this._hasFailed(userUpdateResponse) || (this._hasSucceeded(userUpdateResponse) && !userUpdateResponse.results))
|
|
172
|
+
return results;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
results.user = userResponse.results;
|
|
176
|
+
|
|
177
|
+
results.claims = userResponse.results.claims;
|
|
178
|
+
const configAuth = this._config.get('auth');
|
|
179
|
+
if (configAuth.claims && configAuth.claims.useDefault && !results.claims)
|
|
180
|
+
results.claims = [ this._defaultClaims() ];
|
|
181
|
+
|
|
182
|
+
this._cacheTokens.set(token, { time: LibraryMomentUtility.getTimestamp(), results: results });
|
|
183
|
+
results.success = true;
|
|
184
|
+
return results;
|
|
185
|
+
}
|
|
186
|
+
catch(err) {
|
|
187
|
+
this._logger.exception('FirebaseAuthAdminService', 'verifyToken', err, correlationId);
|
|
188
|
+
if (err.code === "auth/id-token-expired")
|
|
189
|
+
throw new TokenExpiredError();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_convert(requestedUser) {
|
|
196
|
+
if (!requestedUser)
|
|
197
|
+
return null;
|
|
198
|
+
|
|
199
|
+
const user = {};
|
|
200
|
+
user.id = requestedUser.uid;
|
|
201
|
+
user.name = requestedUser.displayName;
|
|
202
|
+
user.picture = requestedUser.photoURL;
|
|
203
|
+
user.email = requestedUser.email;
|
|
204
|
+
return user;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
_defaultClaims() {
|
|
208
|
+
throw new NotImplementedError();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
_initConfig() {
|
|
212
|
+
const filePath = path.join(process.cwd(), 'config', 'serviceAccountKey.json');
|
|
213
|
+
const file = fs.readFileSync(filePath, 'utf8');
|
|
214
|
+
if (String.isNullOrEmpty(file))
|
|
215
|
+
throw Error('Invalid serviceAccountKey.json configuration file for Firebase; expected in the <app root>/config folder.');
|
|
216
|
+
|
|
217
|
+
const config = JSON.parse(file);
|
|
218
|
+
if (!config)
|
|
219
|
+
throw Error('Invalid serviceAccountKey.json file for Firebase config.');
|
|
220
|
+
|
|
221
|
+
return config;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export default FirebaseAuthAdminService;
|
package/license.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020-
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2026 thZero.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/messaging/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import admin from 'firebase-admin';
|
|
2
|
-
|
|
3
|
-
import Service from '@thzero/library_server/service/index.js';
|
|
4
|
-
|
|
5
|
-
class FirebaseMessagingService extends Service {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
|
|
9
|
-
this.registrationToken = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async setMessage(correlationId, data) {
|
|
13
|
-
try {
|
|
14
|
-
var message = {
|
|
15
|
-
data: data,
|
|
16
|
-
token: this.registrationToken
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// Send a message to the device corresponding to the provided registration token.
|
|
20
|
-
const response = await admin.messaging().send(message);
|
|
21
|
-
this._logger.debug('FirebaseMessagingService', 'setMessage', 'Successfully sent message', response, correlationId);
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
this._logger.exception('FirebaseMessagingService', 'setMessage', err, correlationId);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return null
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default FirebaseMessagingService;
|
|
1
|
+
import admin from 'firebase-admin';
|
|
2
|
+
|
|
3
|
+
import Service from '@thzero/library_server/service/index.js';
|
|
4
|
+
|
|
5
|
+
class FirebaseMessagingService extends Service {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this.registrationToken = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async setMessage(correlationId, data) {
|
|
13
|
+
try {
|
|
14
|
+
var message = {
|
|
15
|
+
data: data,
|
|
16
|
+
token: this.registrationToken
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Send a message to the device corresponding to the provided registration token.
|
|
20
|
+
const response = await admin.messaging().send(message);
|
|
21
|
+
this._logger.debug('FirebaseMessagingService', 'setMessage', 'Successfully sent message', response, correlationId);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
this._logger.exception('FirebaseMessagingService', 'setMessage', err, correlationId);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default FirebaseMessagingService;
|
package/openSource.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export default () => {
|
|
2
|
-
return [
|
|
3
|
-
{
|
|
4
|
-
category: 'server',
|
|
5
|
-
name: '@thzero/library_common',
|
|
6
|
-
url: 'https://github.com/thzero/library_common',
|
|
7
|
-
licenseName: 'MIT',
|
|
8
|
-
licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
category: 'server',
|
|
12
|
-
name: '@thzero/library_common_service',
|
|
13
|
-
url: 'https://github.com/thzero/library_common_service',
|
|
14
|
-
licenseName: 'MIT',
|
|
15
|
-
licenseUrl: 'https://github.com/thzero/library_common_service/blob/master/license.md'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
category: 'server',
|
|
19
|
-
name: '@thzero/library_service',
|
|
20
|
-
url: 'https://github.com/thzero/library_service',
|
|
21
|
-
licenseName: 'MIT',
|
|
22
|
-
licenseUrl: 'https://github.com/thzero/library_service/blob/master/license.md'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
category: 'server',
|
|
26
|
-
name: '@thzero/library_server_firebase',
|
|
27
|
-
url: 'https://github.com/thzero/library_server_firebase',
|
|
28
|
-
licenseName: 'MIT',
|
|
29
|
-
licenseUrl: 'https://github.com/thzero/library_server_firebase/blob/master/license.md'
|
|
30
|
-
}
|
|
31
|
-
];
|
|
1
|
+
export default () => {
|
|
2
|
+
return [
|
|
3
|
+
{
|
|
4
|
+
category: 'server',
|
|
5
|
+
name: '@thzero/library_common',
|
|
6
|
+
url: 'https://github.com/thzero/library_common',
|
|
7
|
+
licenseName: 'MIT',
|
|
8
|
+
licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
category: 'server',
|
|
12
|
+
name: '@thzero/library_common_service',
|
|
13
|
+
url: 'https://github.com/thzero/library_common_service',
|
|
14
|
+
licenseName: 'MIT',
|
|
15
|
+
licenseUrl: 'https://github.com/thzero/library_common_service/blob/master/license.md'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
category: 'server',
|
|
19
|
+
name: '@thzero/library_service',
|
|
20
|
+
url: 'https://github.com/thzero/library_service',
|
|
21
|
+
licenseName: 'MIT',
|
|
22
|
+
licenseUrl: 'https://github.com/thzero/library_service/blob/master/license.md'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
category: 'server',
|
|
26
|
+
name: '@thzero/library_server_firebase',
|
|
27
|
+
url: 'https://github.com/thzero/library_server_firebase',
|
|
28
|
+
licenseName: 'MIT',
|
|
29
|
+
licenseUrl: 'https://github.com/thzero/library_server_firebase/blob/master/license.md'
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
32
|
}
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@thzero/library_server_firebase",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.18.
|
|
5
|
-
"version_major": 0,
|
|
6
|
-
"version_minor": 18,
|
|
7
|
-
"version_patch":
|
|
8
|
-
"version_date": "
|
|
9
|
-
"author": "thZero",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/thzero/library_server_firebase.git"
|
|
14
|
-
},
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/thzero/library_server_firebase/issues"
|
|
17
|
-
},
|
|
18
|
-
"homepage": "https://github.com/thzero/library_server_firebase#readme",
|
|
19
|
-
"engines": {
|
|
20
|
-
"node": ">=12.8.3"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"cli-update": "library-cli --updateversion --pi",
|
|
24
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"firebase-admin": "^13.
|
|
28
|
-
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"@thzero/library_common": "^0.18",
|
|
31
|
-
"@thzero/library_common_service": "^0.18",
|
|
32
|
-
"@thzero/library_server": "^0.18"
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@thzero/library_server_firebase",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.18.19",
|
|
5
|
+
"version_major": 0,
|
|
6
|
+
"version_minor": 18,
|
|
7
|
+
"version_patch": 19,
|
|
8
|
+
"version_date": "02/06/2026",
|
|
9
|
+
"author": "thZero",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/thzero/library_server_firebase.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/thzero/library_server_firebase/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/thzero/library_server_firebase#readme",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=12.8.3"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"cli-update": "library-cli --updateversion --pi",
|
|
24
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"firebase-admin": "^13.6.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@thzero/library_common": "^0.18",
|
|
31
|
+
"@thzero/library_common_service": "^0.18",
|
|
32
|
+
"@thzero/library_server": "^0.18"
|
|
33
|
+
}
|
|
34
34
|
}
|