@dereekb/firebase-server 10.1.30 → 11.0.0
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/CHANGELOG.md +18 -0
- package/mailgun/package.json +1 -1
- package/mailgun/src/lib/auth.mailgun.js +23 -17
- package/mailgun/src/lib/auth.mailgun.js.map +1 -1
- package/package.json +7 -1
- package/src/lib/auth/auth.service.js +196 -225
- package/src/lib/auth/auth.service.js.map +1 -1
- package/src/lib/auth/auth.util.js +10 -13
- package/src/lib/auth/auth.util.js.map +1 -1
- package/src/lib/firestore/driver.accessor.batch.js +8 -4
- package/src/lib/firestore/driver.accessor.batch.js.map +1 -1
- package/src/lib/firestore/driver.accessor.default.js +3 -2
- package/src/lib/firestore/driver.accessor.default.js.map +1 -1
- package/src/lib/firestore/driver.accessor.js +4 -5
- package/src/lib/firestore/driver.accessor.js.map +1 -1
- package/src/lib/firestore/driver.accessor.transaction.js +7 -3
- package/src/lib/firestore/driver.accessor.transaction.js.map +1 -1
- package/src/lib/firestore/driver.query.js +5 -2
- package/src/lib/firestore/driver.query.js.map +1 -1
- package/src/lib/firestore/increment.js +1 -1
- package/src/lib/firestore/increment.js.map +1 -1
- package/src/lib/function/assert.js +18 -25
- package/src/lib/function/assert.js.map +1 -1
- package/src/lib/function/context.js +1 -2
- package/src/lib/function/context.js.map +1 -1
- package/src/lib/function/error.auth.js +1 -1
- package/src/lib/function/error.auth.js.map +1 -1
- package/src/lib/function/error.js +60 -10
- package/src/lib/function/error.js.map +1 -1
- package/src/lib/nest/app.js +7 -8
- package/src/lib/nest/app.js.map +1 -1
- package/src/lib/nest/auth/auth.module.js +4 -2
- package/src/lib/nest/auth/auth.module.js.map +1 -1
- package/src/lib/nest/auth/auth.util.js +1 -2
- package/src/lib/nest/auth/auth.util.js.map +1 -1
- package/src/lib/nest/development/development.app.function.js +5 -4
- package/src/lib/nest/development/development.app.function.js.map +1 -1
- package/src/lib/nest/development/development.function.js +5 -1
- package/src/lib/nest/development/development.function.js.map +1 -1
- package/src/lib/nest/development/development.schedule.function.js +3 -4
- package/src/lib/nest/development/development.schedule.function.js.map +1 -1
- package/src/lib/nest/firestore/firestore.module.js +3 -4
- package/src/lib/nest/firestore/firestore.module.js.map +1 -1
- package/src/lib/nest/function/context.js +3 -1
- package/src/lib/nest/function/context.js.map +1 -1
- package/src/lib/nest/function/nest.js +8 -2
- package/src/lib/nest/function/nest.js.map +1 -1
- package/src/lib/nest/function/v1/call.js +5 -2
- package/src/lib/nest/function/v1/call.js.map +1 -1
- package/src/lib/nest/function/v1/event.js +10 -3
- package/src/lib/nest/function/v1/event.js.map +1 -1
- package/src/lib/nest/function/v2/blocking.js +4 -1
- package/src/lib/nest/function/v2/blocking.js.map +1 -1
- package/src/lib/nest/function/v2/call.js +4 -1
- package/src/lib/nest/function/v2/call.js.map +1 -1
- package/src/lib/nest/function/v2/event.js +4 -1
- package/src/lib/nest/function/v2/event.js.map +1 -1
- package/src/lib/nest/function/v2/taskqueue.js +5 -2
- package/src/lib/nest/function/v2/taskqueue.js.map +1 -1
- package/src/lib/nest/middleware/appcheck.decorator.js +2 -3
- package/src/lib/nest/middleware/appcheck.decorator.js.map +1 -1
- package/src/lib/nest/middleware/appcheck.middleware.js +24 -30
- package/src/lib/nest/middleware/appcheck.middleware.js.map +1 -1
- package/src/lib/nest/middleware/appcheck.module.js +1 -3
- package/src/lib/nest/middleware/appcheck.module.js.map +1 -1
- package/src/lib/nest/middleware/webhook.js +1 -3
- package/src/lib/nest/middleware/webhook.js.map +1 -1
- package/src/lib/nest/model/call.model.function.js +1 -2
- package/src/lib/nest/model/call.model.function.js.map +1 -1
- package/src/lib/nest/model/create.model.function.js +6 -3
- package/src/lib/nest/model/create.model.function.js.map +1 -1
- package/src/lib/nest/model/delete.model.function.js +6 -3
- package/src/lib/nest/model/delete.model.function.js.map +1 -1
- package/src/lib/nest/model/permission.error.js +4 -6
- package/src/lib/nest/model/permission.error.js.map +1 -1
- package/src/lib/nest/model/read.model.function.js +6 -3
- package/src/lib/nest/model/read.model.function.js.map +1 -1
- package/src/lib/nest/model/specifier.function.js +3 -4
- package/src/lib/nest/model/specifier.function.js.map +1 -1
- package/src/lib/nest/model/update.model.function.js +6 -3
- package/src/lib/nest/model/update.model.function.js.map +1 -1
- package/src/lib/nest/nest.provider.js +25 -31
- package/src/lib/nest/nest.provider.js.map +1 -1
- package/src/lib/nest/storage/storage.module.js +4 -2
- package/src/lib/nest/storage/storage.module.js.map +1 -1
- package/src/lib/storage/driver.accessor.js +32 -26
- package/src/lib/storage/driver.accessor.js.map +1 -1
- package/src/lib/storage/storage.service.js +1 -0
- package/src/lib/storage/storage.service.js.map +1 -1
- package/test/package.json +1 -1
- package/test/src/lib/firebase/firebase.admin.auth.js +55 -49
- package/test/src/lib/firebase/firebase.admin.auth.js.map +1 -1
- package/test/src/lib/firebase/firebase.admin.collection.js +9 -7
- package/test/src/lib/firebase/firebase.admin.collection.js.map +1 -1
- package/test/src/lib/firebase/firebase.admin.function.js +11 -9
- package/test/src/lib/firebase/firebase.admin.function.js.map +1 -1
- package/test/src/lib/firebase/firebase.admin.js +19 -16
- package/test/src/lib/firebase/firebase.admin.js.map +1 -1
- package/test/src/lib/firebase/firebase.admin.nest.function.js +5 -1
- package/test/src/lib/firebase/firebase.admin.nest.function.js.map +1 -1
- package/test/src/lib/firebase/firebase.admin.nest.js +11 -12
- package/test/src/lib/firebase/firebase.admin.nest.js.map +1 -1
- package/test/src/lib/firebase/firebase.admin.test.server.js +5 -6
- package/test/src/lib/firebase/firebase.admin.test.server.js.map +1 -1
- package/test/src/lib/firebase/firebase.function.js +4 -1
- package/test/src/lib/firebase/firebase.function.js.map +1 -1
- package/test/src/lib/firebase/firebase.js +1 -2
- package/test/src/lib/firebase/firebase.js.map +1 -1
- package/test/src/lib/firestore/firestore.js +7 -9
- package/test/src/lib/firestore/firestore.js.map +1 -1
- package/test/src/lib/storage/storage.js +6 -8
- package/test/src/lib/storage/storage.js.map +1 -1
- package/zoho/package.json +6 -0
- package/zoho/src/index.d.ts +1 -0
- package/zoho/src/index.js +5 -0
- package/zoho/src/index.js.map +1 -0
- package/zoho/src/lib/index.d.ts +2 -0
- package/zoho/src/lib/index.js +6 -0
- package/zoho/src/lib/index.js.map +1 -0
- package/zoho/src/lib/zoho.accounts.firebase.d.ts +8 -0
- package/zoho/src/lib/zoho.accounts.firebase.js +62 -0
- package/zoho/src/lib/zoho.accounts.firebase.js.map +1 -0
- package/zoho/src/lib/zoho.accounts.firebase.system.d.ts +32 -0
- package/zoho/src/lib/zoho.accounts.firebase.system.js +44 -0
- package/zoho/src/lib/zoho.accounts.firebase.system.js.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [11.0.0](https://github.com/dereekb/dbx-components/compare/v10.2.0-dev...v11.0.0) (2024-11-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Code Refactoring
|
|
9
|
+
|
|
10
|
+
* revisited some todos ([4902b4b](https://github.com/dereekb/dbx-components/commit/4902b4bcffde7174c37b72d84fd4473e3b975769))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* all breaking changes are documented in VERSION_MIGRATION.md
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# [10.2.0](https://github.com/dereekb/dbx-components/compare/v10.1.30-dev...v10.2.0) (2024-11-07)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
5
23
|
## [10.1.30](https://github.com/dereekb/dbx-components/compare/v10.1.29-dev...v10.1.30) (2024-10-23)
|
|
6
24
|
|
|
7
25
|
|
package/mailgun/package.json
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractMailgunContentFirebaseServerNewUserService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const firebase_server_1 = require("@dereekb/firebase-server");
|
|
6
5
|
/**
|
|
7
6
|
* Abstract FirebaseServerNewUserService implementation that sends an email to a template on Mailgun.
|
|
8
7
|
*/
|
|
9
8
|
class AbstractMailgunContentFirebaseServerNewUserService extends firebase_server_1.AbstractFirebaseServerNewUserService {
|
|
9
|
+
mailgunService;
|
|
10
10
|
constructor(authService, mailgunService) {
|
|
11
11
|
super(authService);
|
|
12
12
|
this.mailgunService = mailgunService;
|
|
13
13
|
}
|
|
14
|
-
sendSetupContentToUser(user) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
async sendSetupContentToUser(user) {
|
|
15
|
+
const userRecord = await user.userContext.loadRecord();
|
|
16
|
+
const { setupPassword } = user.claims;
|
|
17
|
+
const { uid, displayName, email } = userRecord;
|
|
18
|
+
if (!email) {
|
|
19
|
+
throw new Error(`Email is not present/available for the user record "${userRecord.uid}"`);
|
|
20
|
+
}
|
|
21
|
+
const baseRequest = await this.buildNewUserMailgunContentRequest(user);
|
|
22
|
+
const baseRequestTo = baseRequest.to;
|
|
23
|
+
await this.mailgunService.sendTemplateEmail({
|
|
24
|
+
...baseRequest,
|
|
25
|
+
to: {
|
|
26
|
+
name: baseRequestTo?.name,
|
|
27
|
+
email,
|
|
28
|
+
userVariables: {
|
|
29
|
+
setupPassword,
|
|
30
|
+
...baseRequestTo?.userVariables,
|
|
31
|
+
displayName,
|
|
32
|
+
uid
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
sendTestEmails: baseRequest.sendTestEmails || user.sendDetailsInTestEnvironment || undefined
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.mailgun.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/mailgun/src/lib/auth.mailgun.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.mailgun.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/mailgun/src/lib/auth.mailgun.ts"],"names":[],"mappings":";;;AACA,8DAAgO;AAWhO;;GAEG;AACH,MAAsB,kDAA0N,SAAQ,sDAA6C;IAChO;IAAnE,YAAY,WAA4C,EAAW,cAA8B;QAC/F,KAAK,CAAC,WAAW,CAAC,CAAC;QAD8C,mBAAc,GAAd,cAAc,CAAgB;IAEjG,CAAC;IAES,KAAK,CAAC,sBAAsB,CAAC,IAAiD;QACtF,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;QACvD,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACtC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC;QAE/C,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,uDAAuD,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC;SAC3F;QAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC;QACvE,MAAM,aAAa,GAAG,WAAW,CAAC,EAAE,CAAC;QAErC,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC;YAC1C,GAAG,WAAW;YACd,EAAE,EAAE;gBACF,IAAI,EAAE,aAAa,EAAE,IAAI;gBACzB,KAAK;gBACL,aAAa,EAAE;oBACb,aAAa;oBACb,GAAG,aAAa,EAAE,aAAa;oBAC/B,WAAW;oBACX,GAAG;iBACJ;aACF;YACD,cAAc,EAAE,WAAW,CAAC,cAAc,IAAI,IAAI,CAAC,4BAA4B,IAAI,SAAS;SAC7F,CAAC,CAAC;IACL,CAAC;CAGF;AAlCD,gHAkCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
"main": "./mailgun/src/index.js",
|
|
20
20
|
"require": "./mailgun/src/index.js",
|
|
21
21
|
"default": "./mailgun/src/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./zoho": {
|
|
24
|
+
"types": "./zoho/src/index.d.ts",
|
|
25
|
+
"main": "./zoho/src/index.js",
|
|
26
|
+
"require": "./zoho/src/index.js",
|
|
27
|
+
"default": "./zoho/src/index.js"
|
|
22
28
|
}
|
|
23
29
|
},
|
|
24
30
|
"main": "./src/index.js",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractFirebaseServerAuthService = exports.FirebaseServerAuthService = exports.NoSetupContentFirebaseServerNewUserService = exports.AbstractFirebaseServerNewUserService = exports.userContextFromUid = exports.DEFAULT_SETUP_COM_THROTTLE_TIME = exports.AbstractFirebaseServerAuthContext = exports.AbstractFirebaseServerAuthUserContext = exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const firebase_1 = require("@dereekb/firebase");
|
|
6
5
|
const util_1 = require("@dereekb/util");
|
|
7
6
|
const context_1 = require("../function/context");
|
|
@@ -10,15 +9,15 @@ const date_1 = require("@dereekb/date");
|
|
|
10
9
|
const auth_util_1 = require("./auth.util");
|
|
11
10
|
exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR = (0, util_1.randomNumberFactory)({ min: 100000, max: 1000000, round: 'floor' }); // 6 digits
|
|
12
11
|
class AbstractFirebaseServerAuthUserContext {
|
|
12
|
+
service;
|
|
13
|
+
uid;
|
|
14
|
+
_loadRecord = (0, util_1.cachedGetter)(() => this.service.auth.getUser(this.uid));
|
|
13
15
|
constructor(service, uid) {
|
|
14
16
|
this.service = service;
|
|
15
17
|
this.uid = uid;
|
|
16
|
-
this._loadRecord = (0, util_1.cachedGetter)(() => this.service.auth.getUser(this.uid));
|
|
17
18
|
}
|
|
18
|
-
exists() {
|
|
19
|
-
return
|
|
20
|
-
return (0, auth_util_1.getAuthUserOrUndefined)(this._loadRecord()).then((x) => Boolean(x));
|
|
21
|
-
});
|
|
19
|
+
async exists() {
|
|
20
|
+
return (0, auth_util_1.getAuthUserOrUndefined)(this._loadRecord()).then((x) => Boolean(x));
|
|
22
21
|
}
|
|
23
22
|
loadRecord() {
|
|
24
23
|
return this._loadRecord();
|
|
@@ -29,74 +28,60 @@ class AbstractFirebaseServerAuthUserContext {
|
|
|
29
28
|
_generateResetPasswordKey() {
|
|
30
29
|
return String((0, exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR)());
|
|
31
30
|
}
|
|
32
|
-
beginResetPassword() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
else {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
31
|
+
async beginResetPassword() {
|
|
32
|
+
const password = this._generateResetPasswordKey();
|
|
33
|
+
const passwordClaimsData = {
|
|
34
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_RESET_PASSWORD_KEY]: password,
|
|
35
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_RESET_LAST_COM_DATE_KEY]: (0, date_1.toISODateString)(new Date())
|
|
36
|
+
};
|
|
37
|
+
// set the claims
|
|
38
|
+
await this.updateClaims(passwordClaimsData);
|
|
39
|
+
// update the user
|
|
40
|
+
await this.updateUser({ password });
|
|
41
|
+
return passwordClaimsData;
|
|
42
|
+
}
|
|
43
|
+
async loadResetPasswordClaims() {
|
|
44
|
+
const claims = await this.loadClaims();
|
|
45
|
+
if (claims.resetPassword != null) {
|
|
46
|
+
return claims;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
56
51
|
}
|
|
57
52
|
/**
|
|
58
53
|
* Sets the user's password.
|
|
59
54
|
*/
|
|
60
|
-
setPassword(password) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_RESET_LAST_COM_DATE_KEY]: null
|
|
67
|
-
});
|
|
68
|
-
return record;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
updateUser(template) {
|
|
72
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return this.service.auth.updateUser(this.uid, template);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
loadRoles() {
|
|
77
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const claims = yield this.loadClaims();
|
|
79
|
-
return this.service.readRoles(claims);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
addRoles(roles) {
|
|
83
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
const claims = this._claimsForRolesChange(roles);
|
|
85
|
-
return this.updateClaims(claims);
|
|
55
|
+
async setPassword(password) {
|
|
56
|
+
const record = await this.updateUser({ password });
|
|
57
|
+
// clear password reset claims
|
|
58
|
+
await this.updateClaims({
|
|
59
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_RESET_PASSWORD_KEY]: null,
|
|
60
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_RESET_LAST_COM_DATE_KEY]: null
|
|
86
61
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
62
|
+
return record;
|
|
63
|
+
}
|
|
64
|
+
async updateUser(template) {
|
|
65
|
+
return this.service.auth.updateUser(this.uid, template);
|
|
66
|
+
}
|
|
67
|
+
async loadRoles() {
|
|
68
|
+
const claims = await this.loadClaims();
|
|
69
|
+
return this.service.readRoles(claims);
|
|
70
|
+
}
|
|
71
|
+
async addRoles(roles) {
|
|
72
|
+
const claims = this._claimsForRolesChange(roles);
|
|
73
|
+
return this.updateClaims(claims);
|
|
74
|
+
}
|
|
75
|
+
async removeRoles(roles) {
|
|
76
|
+
const baseClaims = this._claimsForRolesChange(roles);
|
|
77
|
+
const claims = {};
|
|
78
|
+
(0, util_1.forEachKeyValue)(baseClaims, {
|
|
79
|
+
forEach: ([key]) => {
|
|
80
|
+
claims[key] = null; // set null on every key
|
|
81
|
+
},
|
|
82
|
+
filter: util_1.KeyValueTypleValueFilter.NONE // don't skip any key/value
|
|
99
83
|
});
|
|
84
|
+
return this.updateClaims(claims);
|
|
100
85
|
}
|
|
101
86
|
/**
|
|
102
87
|
* Sets the claims using the input roles and roles set.
|
|
@@ -109,32 +94,34 @@ class AbstractFirebaseServerAuthUserContext {
|
|
|
109
94
|
* @param claimsToRetain
|
|
110
95
|
* @returns
|
|
111
96
|
*/
|
|
112
|
-
setRoles(roles, claimsToRetain) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
97
|
+
async setRoles(roles, claimsToRetain) {
|
|
98
|
+
const claims = {
|
|
99
|
+
...claimsToRetain,
|
|
100
|
+
...this._claimsForRolesChange(Array.from(roles))
|
|
101
|
+
};
|
|
102
|
+
return this.setClaims(claims);
|
|
117
103
|
}
|
|
118
104
|
_claimsForRolesChange(roles) {
|
|
119
105
|
// filter null/undefined since the claims will contain null values for claims that are not related.
|
|
120
106
|
return (0, util_1.filterNullAndUndefinedValues)(this.service.claimsForRoles((0, util_1.asSet)(roles)));
|
|
121
107
|
}
|
|
122
108
|
loadClaims() {
|
|
123
|
-
return this.loadRecord().then((x) =>
|
|
124
|
-
}
|
|
125
|
-
updateClaims(claims) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
109
|
+
return this.loadRecord().then((x) => (x.customClaims ?? {}));
|
|
110
|
+
}
|
|
111
|
+
async updateClaims(claims) {
|
|
112
|
+
const currentClaims = await this.loadClaims();
|
|
113
|
+
let newClaims;
|
|
114
|
+
if (currentClaims) {
|
|
115
|
+
newClaims = {
|
|
116
|
+
...currentClaims,
|
|
117
|
+
...(0, util_1.filterUndefinedValues)(claims, false)
|
|
118
|
+
};
|
|
119
|
+
newClaims = (0, util_1.filterNullAndUndefinedValues)(newClaims);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
newClaims = claims;
|
|
123
|
+
}
|
|
124
|
+
return this.setClaims(newClaims);
|
|
138
125
|
}
|
|
139
126
|
clearClaims() {
|
|
140
127
|
return this.setClaims(null);
|
|
@@ -147,13 +134,15 @@ class AbstractFirebaseServerAuthUserContext {
|
|
|
147
134
|
}
|
|
148
135
|
exports.AbstractFirebaseServerAuthUserContext = AbstractFirebaseServerAuthUserContext;
|
|
149
136
|
class AbstractFirebaseServerAuthContext {
|
|
137
|
+
service;
|
|
138
|
+
context;
|
|
139
|
+
_authRoles = (0, util_1.cachedGetter)(() => this.service.readRoles(this.claims));
|
|
140
|
+
_isAdmin = (0, util_1.cachedGetter)(() => this.service.isAdminInRoles(this._authRoles()));
|
|
141
|
+
_hasSignedTos = (0, util_1.cachedGetter)(() => this.service.hasSignedTosInRoles(this._authRoles()));
|
|
142
|
+
_userContext = (0, util_1.cachedGetter)(() => this.service.userContext(this.context.auth.uid));
|
|
150
143
|
constructor(service, context) {
|
|
151
144
|
this.service = service;
|
|
152
145
|
this.context = context;
|
|
153
|
-
this._authRoles = (0, util_1.cachedGetter)(() => this.service.readRoles(this.claims));
|
|
154
|
-
this._isAdmin = (0, util_1.cachedGetter)(() => this.service.isAdminInRoles(this._authRoles()));
|
|
155
|
-
this._hasSignedTos = (0, util_1.cachedGetter)(() => this.service.hasSignedTosInRoles(this._authRoles()));
|
|
156
|
-
this._userContext = (0, util_1.cachedGetter)(() => this.service.userContext(this.context.auth.uid));
|
|
157
146
|
}
|
|
158
147
|
get userContext() {
|
|
159
148
|
return this._userContext();
|
|
@@ -189,112 +178,101 @@ function userContextFromUid(authService, userContextOrUid) {
|
|
|
189
178
|
}
|
|
190
179
|
exports.userContextFromUid = userContextFromUid;
|
|
191
180
|
class AbstractFirebaseServerNewUserService {
|
|
181
|
+
authService;
|
|
182
|
+
setupThrottleTime = exports.DEFAULT_SETUP_COM_THROTTLE_TIME;
|
|
192
183
|
constructor(authService) {
|
|
193
184
|
this.authService = authService;
|
|
194
|
-
this.setupThrottleTime = exports.DEFAULT_SETUP_COM_THROTTLE_TIME;
|
|
195
|
-
}
|
|
196
|
-
initializeNewUser(input) {
|
|
197
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
const { uid, email, phone, sendSetupContent, sendSetupContentIfUserExists, data, sendDetailsInTestEnvironment } = input;
|
|
199
|
-
let userRecordPromise;
|
|
200
|
-
if (uid) {
|
|
201
|
-
userRecordPromise = this.authService.auth.getUser(uid);
|
|
202
|
-
}
|
|
203
|
-
else if (email) {
|
|
204
|
-
userRecordPromise = this.authService.auth.getUserByEmail(email);
|
|
205
|
-
}
|
|
206
|
-
else if (phone) {
|
|
207
|
-
userRecordPromise = this.authService.auth.getUserByPhoneNumber(phone);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
throw new Error('email or phone is required to initialize a new user.');
|
|
211
|
-
}
|
|
212
|
-
let userRecord = yield (0, auth_util_1.getAuthUserOrUndefined)(userRecordPromise);
|
|
213
|
-
let userRecordId;
|
|
214
|
-
let createdUser = false;
|
|
215
|
-
if (!userRecord) {
|
|
216
|
-
const createResult = yield this.createNewUser(input);
|
|
217
|
-
// add the setup password to the user's credentials
|
|
218
|
-
const userContext = this.authService.userContext(createResult.user.uid);
|
|
219
|
-
yield this.addNewUserSetupClaims(userContext, createResult.password);
|
|
220
|
-
createdUser = true;
|
|
221
|
-
userRecordId = userContext.uid;
|
|
222
|
-
userRecord = yield userContext.loadRecord();
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
userRecordId = userRecord.uid;
|
|
226
|
-
}
|
|
227
|
-
// send content if necessary
|
|
228
|
-
if ((createdUser && sendSetupContent === true) || sendSetupContentIfUserExists) {
|
|
229
|
-
const sentEmail = yield this.sendSetupContent(userRecordId, { data, sendDetailsInTestEnvironment });
|
|
230
|
-
// reload the user record
|
|
231
|
-
if (sentEmail) {
|
|
232
|
-
const userContext = this.authService.userContext(userRecordId);
|
|
233
|
-
userRecord = yield userContext.loadRecord();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return userRecord;
|
|
237
|
-
});
|
|
238
185
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
186
|
+
async initializeNewUser(input) {
|
|
187
|
+
const { uid, email, phone, sendSetupContent, sendSetupContentIfUserExists, data, sendDetailsInTestEnvironment } = input;
|
|
188
|
+
let userRecordPromise;
|
|
189
|
+
if (uid) {
|
|
190
|
+
userRecordPromise = this.authService.auth.getUser(uid);
|
|
191
|
+
}
|
|
192
|
+
else if (email) {
|
|
193
|
+
userRecordPromise = this.authService.auth.getUserByEmail(email);
|
|
194
|
+
}
|
|
195
|
+
else if (phone) {
|
|
196
|
+
userRecordPromise = this.authService.auth.getUserByPhoneNumber(phone);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
throw new Error('email or phone is required to initialize a new user.');
|
|
200
|
+
}
|
|
201
|
+
let userRecord = await (0, auth_util_1.getAuthUserOrUndefined)(userRecordPromise);
|
|
202
|
+
let userRecordId;
|
|
203
|
+
let createdUser = false;
|
|
204
|
+
if (!userRecord) {
|
|
205
|
+
const createResult = await this.createNewUser(input);
|
|
206
|
+
// add the setup password to the user's credentials
|
|
207
|
+
const userContext = this.authService.userContext(createResult.user.uid);
|
|
208
|
+
await this.addNewUserSetupClaims(userContext, createResult.password);
|
|
209
|
+
createdUser = true;
|
|
210
|
+
userRecordId = userContext.uid;
|
|
211
|
+
userRecord = await userContext.loadRecord();
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
userRecordId = userRecord.uid;
|
|
215
|
+
}
|
|
216
|
+
// send content if necessary
|
|
217
|
+
if ((createdUser && sendSetupContent === true) || sendSetupContentIfUserExists) {
|
|
218
|
+
const sentEmail = await this.sendSetupContent(userRecordId, { data, sendDetailsInTestEnvironment });
|
|
219
|
+
// reload the user record
|
|
220
|
+
if (sentEmail) {
|
|
221
|
+
const userContext = this.authService.userContext(userRecordId);
|
|
222
|
+
userRecord = await userContext.loadRecord();
|
|
260
223
|
}
|
|
261
|
-
|
|
262
|
-
|
|
224
|
+
}
|
|
225
|
+
return userRecord;
|
|
263
226
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (userExists) {
|
|
270
|
-
details = yield this.loadSetupDetailsForUserContext(userContext, config);
|
|
271
|
-
}
|
|
272
|
-
return details;
|
|
227
|
+
async addNewUserSetupClaims(userContextOrUid, setupPassword) {
|
|
228
|
+
const password = setupPassword ?? this.generateRandomSetupPassword();
|
|
229
|
+
const userContext = userContextFromUid(this.authService, userContextOrUid);
|
|
230
|
+
await userContext.updateClaims({
|
|
231
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY]: password
|
|
273
232
|
});
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
},
|
|
286
|
-
data: config === null || config === void 0 ? void 0 : config.data,
|
|
287
|
-
sendDetailsInTestEnvironment: config === null || config === void 0 ? void 0 : config.sendDetailsInTestEnvironment
|
|
288
|
-
};
|
|
233
|
+
return userContext;
|
|
234
|
+
}
|
|
235
|
+
async sendSetupContent(userContextOrUid, config) {
|
|
236
|
+
const setupDetails = await this.loadSetupDetails(userContextOrUid, config);
|
|
237
|
+
let sentContent = false;
|
|
238
|
+
if (setupDetails) {
|
|
239
|
+
const { setupCommunicationAt } = setupDetails.claims;
|
|
240
|
+
if (!setupCommunicationAt || (0, date_1.timeHasExpired)(new Date(setupCommunicationAt), this.setupThrottleTime)) {
|
|
241
|
+
await this.sendSetupContentToUser(setupDetails);
|
|
242
|
+
await this.updateSetupContentSentTime(setupDetails);
|
|
243
|
+
sentContent = true;
|
|
289
244
|
}
|
|
290
|
-
|
|
291
|
-
|
|
245
|
+
}
|
|
246
|
+
return sentContent;
|
|
247
|
+
}
|
|
248
|
+
async loadSetupDetails(userContextOrUid, config) {
|
|
249
|
+
const userContext = userContextFromUid(this.authService, userContextOrUid);
|
|
250
|
+
const userExists = await userContext.exists();
|
|
251
|
+
let details;
|
|
252
|
+
if (userExists) {
|
|
253
|
+
details = await this.loadSetupDetailsForUserContext(userContext, config);
|
|
254
|
+
}
|
|
255
|
+
return details;
|
|
256
|
+
}
|
|
257
|
+
async loadSetupDetailsForUserContext(userContext, config) {
|
|
258
|
+
let details;
|
|
259
|
+
const { setupPassword, setupCommunicationAt } = await userContext.loadClaims();
|
|
260
|
+
if (setupPassword) {
|
|
261
|
+
details = {
|
|
262
|
+
userContext,
|
|
263
|
+
claims: {
|
|
264
|
+
setupPassword,
|
|
265
|
+
setupCommunicationAt
|
|
266
|
+
},
|
|
267
|
+
data: config?.data,
|
|
268
|
+
sendDetailsInTestEnvironment: config?.sendDetailsInTestEnvironment
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return details;
|
|
292
272
|
}
|
|
293
|
-
updateSetupContentSentTime(details) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
setupCommunicationAt: (0, date_1.toISODateString)(new Date())
|
|
297
|
-
});
|
|
273
|
+
async updateSetupContentSentTime(details) {
|
|
274
|
+
await details.userContext.updateClaims({
|
|
275
|
+
setupCommunicationAt: (0, date_1.toISODateString)(new Date())
|
|
298
276
|
});
|
|
299
277
|
}
|
|
300
278
|
/**
|
|
@@ -304,51 +282,43 @@ class AbstractFirebaseServerNewUserService {
|
|
|
304
282
|
*
|
|
305
283
|
* @param uid
|
|
306
284
|
*/
|
|
307
|
-
markUserSetupAsComplete(uid) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
email,
|
|
325
|
-
phoneNumber,
|
|
326
|
-
password
|
|
327
|
-
});
|
|
328
|
-
return {
|
|
329
|
-
user,
|
|
330
|
-
password
|
|
331
|
-
};
|
|
285
|
+
async markUserSetupAsComplete(uid) {
|
|
286
|
+
const userContext = this.authService.userContext(uid);
|
|
287
|
+
const userExists = await userContext.exists();
|
|
288
|
+
if (userExists) {
|
|
289
|
+
await this.updateClaimsToClearUser(userContext);
|
|
290
|
+
}
|
|
291
|
+
return userExists;
|
|
292
|
+
}
|
|
293
|
+
async createNewUser(input) {
|
|
294
|
+
const { uid, displayName, email, phone: phoneNumber, setupPassword: inputPassword } = input;
|
|
295
|
+
const password = inputPassword ?? this.generateRandomSetupPassword();
|
|
296
|
+
const user = await this.authService.auth.createUser({
|
|
297
|
+
uid,
|
|
298
|
+
displayName,
|
|
299
|
+
email,
|
|
300
|
+
phoneNumber,
|
|
301
|
+
password
|
|
332
302
|
});
|
|
303
|
+
return {
|
|
304
|
+
user,
|
|
305
|
+
password
|
|
306
|
+
};
|
|
333
307
|
}
|
|
334
308
|
generateRandomSetupPassword() {
|
|
335
309
|
return `${(0, exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR)()}`;
|
|
336
310
|
}
|
|
337
|
-
updateClaimsToClearUser(userContext) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_LAST_COM_DATE_KEY]: null
|
|
342
|
-
});
|
|
311
|
+
async updateClaimsToClearUser(userContext) {
|
|
312
|
+
await userContext.updateClaims({
|
|
313
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY]: null,
|
|
314
|
+
[firebase_1.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_LAST_COM_DATE_KEY]: null
|
|
343
315
|
});
|
|
344
316
|
}
|
|
345
317
|
}
|
|
346
318
|
exports.AbstractFirebaseServerNewUserService = AbstractFirebaseServerNewUserService;
|
|
347
319
|
class NoSetupContentFirebaseServerNewUserService extends AbstractFirebaseServerNewUserService {
|
|
348
|
-
sendSetupContentToUser(user) {
|
|
349
|
-
|
|
350
|
-
// send nothing.
|
|
351
|
-
});
|
|
320
|
+
async sendSetupContentToUser(user) {
|
|
321
|
+
// send nothing.
|
|
352
322
|
}
|
|
353
323
|
}
|
|
354
324
|
exports.NoSetupContentFirebaseServerNewUserService = NoSetupContentFirebaseServerNewUserService;
|
|
@@ -362,6 +332,7 @@ exports.FirebaseServerAuthService = FirebaseServerAuthService;
|
|
|
362
332
|
* Abstract FirebaseServerAuthService implementation.
|
|
363
333
|
*/
|
|
364
334
|
class AbstractFirebaseServerAuthService {
|
|
335
|
+
auth;
|
|
365
336
|
constructor(auth) {
|
|
366
337
|
this.auth = auth;
|
|
367
338
|
}
|