@dereekb/firebase-server 9.7.7 → 9.9.1

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +4 -5
  3. package/mailgun/package.json +42 -0
  4. package/mailgun/src/index.d.ts +1 -0
  5. package/mailgun/src/index.js +5 -0
  6. package/mailgun/src/index.js.map +1 -0
  7. package/mailgun/src/lib/auth.mailgun.d.ts +17 -0
  8. package/mailgun/src/lib/auth.mailgun.js +35 -0
  9. package/mailgun/src/lib/auth.mailgun.js.map +1 -0
  10. package/mailgun/src/lib/index.d.ts +1 -0
  11. package/mailgun/src/lib/index.js +5 -0
  12. package/mailgun/src/lib/index.js.map +1 -0
  13. package/package.json +12 -7
  14. package/src/lib/auth/auth.service.d.ts +103 -5
  15. package/src/lib/auth/auth.service.js +155 -1
  16. package/src/lib/auth/auth.service.js.map +1 -1
  17. package/src/lib/auth/auth.util.d.ts +8 -0
  18. package/src/lib/auth/auth.util.js +27 -0
  19. package/src/lib/auth/auth.util.js.map +1 -0
  20. package/src/lib/auth/index.d.ts +1 -0
  21. package/src/lib/auth/index.js +1 -0
  22. package/src/lib/auth/index.js.map +1 -1
  23. package/src/lib/env/env.service.d.ts +1 -1
  24. package/src/lib/env/env.service.js.map +1 -1
  25. package/src/lib/env/index.d.ts +0 -1
  26. package/src/lib/env/index.js +0 -1
  27. package/src/lib/env/index.js.map +1 -1
  28. package/src/lib/nest/app.d.ts +2 -2
  29. package/src/lib/nest/app.js +2 -1
  30. package/src/lib/nest/app.js.map +1 -1
  31. package/src/lib/nest/env/env.config.d.ts +3 -19
  32. package/src/lib/nest/env/env.nest.d.ts +7 -4
  33. package/src/lib/nest/env/env.nest.js +8 -10
  34. package/src/lib/nest/env/env.nest.js.map +1 -1
  35. package/src/lib/nest/env/env.service.d.ts +3 -8
  36. package/src/lib/nest/env/env.service.js +4 -19
  37. package/src/lib/nest/env/env.service.js.map +1 -1
  38. package/test/package.json +10 -10
  39. package/test/src/lib/firebase/firebase.admin.nest.d.ts +6 -5
  40. package/test/src/lib/firebase/firebase.admin.nest.js +6 -5
  41. package/test/src/lib/firebase/firebase.admin.nest.js.map +1 -1
  42. package/src/lib/env/env.d.ts +0 -4
  43. package/src/lib/env/env.js +0 -11
  44. package/src/lib/env/env.js.map +0 -1
  45. package/test/CHANGELOG.md +0 -549
  46. package/test/README.md +0 -11
package/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [9.9.1](https://github.com/dereekb/dbx-components/compare/v9.9.0-dev...v9.9.1) (2022-09-18)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * fixed dependencies for release ([7c57c7e](https://github.com/dereekb/dbx-components/commit/7c57c7ef5df664b8df2641fb3b50b82b3fb2c650))
11
+
12
+
13
+
14
+ # [9.9.0](https://github.com/dereekb/dbx-components/compare/v9.8.0-dev...v9.9.0) (2022-09-17)
15
+
16
+
17
+ ### Features
18
+
19
+ * mailgun ([#16](https://github.com/dereekb/dbx-components/issues/16)) ([9c7d4cc](https://github.com/dereekb/dbx-components/commit/9c7d4cc997e86b664ff7e2bc6e04392e650b7910))
20
+
21
+
22
+
23
+ # [9.8.0](https://github.com/dereekb/dbx-components/compare/v9.7.7-dev...v9.8.0) (2022-09-15)
24
+
25
+
26
+ ### Features
27
+
28
+ * added FirebaseServerNewUserService ([10d64dc](https://github.com/dereekb/dbx-components/commit/10d64dc137e533a62d7449709a93056741a840e4))
29
+
30
+
31
+
5
32
  ## [9.7.7](https://github.com/dereekb/dbx-components/compare/v9.7.6-dev...v9.7.7) (2022-09-12)
6
33
 
7
34
 
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # firebase-server
1
+ @dereekb/firebase-server
2
+ =======
2
3
 
3
- This library was generated with [Nx](https://nx.dev).
4
+ The sources for this package are in the main [@dereekb/dbx-components](https://github.com/dereekb/dbx-components) repo. Please file issues and pull requests against that repo.
4
5
 
5
- ## Running unit tests
6
-
7
- Run `nx test firebase-server` to execute the unit tests via [Jest](https://jestjs.io).
6
+ License: MIT
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@dereekb/firebase-server/mailgun",
3
+ "version": "9.9.1",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "typings": "./src/index.d.ts",
7
+ "dependencies": {},
8
+ "peerDependencies": {
9
+ "@dereekb/nestjs/mailgun": "9.9.1",
10
+ "@nestjs/common": "^9.0.0",
11
+ "mailgun.js": "^8.0.0",
12
+ "form-data": "4.0.0",
13
+ "@dereekb/util": "9.9.1",
14
+ "lodash.isequal": "^4.5.0",
15
+ "make-error": "^1.3.0",
16
+ "ts-essentials": "^9.1.2",
17
+ "extra-set": "^2.2.11",
18
+ "@dereekb/nestjs": "9.9.1",
19
+ "@nestjs/config": "^2.0.1",
20
+ "@dereekb/firebase-server": "9.9.1",
21
+ "jsonwebtoken": "^8.0.0",
22
+ "@dereekb/firebase": "9.9.1",
23
+ "rxjs": "^7.5.0",
24
+ "firebase": "^9.9.2",
25
+ "@dereekb/rxjs": "9.9.1",
26
+ "ms": "^3.0.0-canary.1",
27
+ "@dereekb/model": "9.9.1",
28
+ "class-transformer": "^0.5.1",
29
+ "class-validator": "^0.13.2",
30
+ "@dereekb/date": "9.9.1",
31
+ "date-fns": "^2.29.0",
32
+ "date-fns-tz": "^1.3.0",
33
+ "rrule": "git+https://git@github.com/dereekb/rrule#2b13b1ea881059ba2ecfec380e12ef244ef54570",
34
+ "@vvo/tzdb": "^6.56.0",
35
+ "firebase-functions": "^3.22.0",
36
+ "firebase-admin": "^11.0.0",
37
+ "@google-cloud/firestore": "^5.0.2",
38
+ "@nestjs/core": "^9.0.0",
39
+ "@nestjs/platform-express": "^9.0.0",
40
+ "tslib": "^2.0.0"
41
+ }
42
+ }
@@ -0,0 +1 @@
1
+ export * from './lib';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/firebase-server/mailgun/src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB"}
@@ -0,0 +1,17 @@
1
+ import { MailgunService, MailgunTemplateEmailRequest } from '@dereekb/nestjs/mailgun';
2
+ import { AbstractFirebaseServerNewUserService, FirebaseServerAuthNewUserSetupDetails, FirebaseServerAuthService, FirebaseServerAuthUserContext } from '@dereekb/firebase-server';
3
+ /**
4
+ * MailgunTemplateEmailRequest for AbstractMailgunContentFirebaseServerNewUserService.
5
+ *
6
+ * Omits the "to" input since it gets configured by the input.
7
+ */
8
+ export declare type NewUserMailgunContentRequest = Omit<MailgunTemplateEmailRequest, 'to'>;
9
+ /**
10
+ * Abstract FirebaseServerNewUserService implementation that sends an email to a template on Mailgun.
11
+ */
12
+ export declare abstract class AbstractMailgunContentFirebaseServerNewUserService<U extends FirebaseServerAuthUserContext = FirebaseServerAuthUserContext> extends AbstractFirebaseServerNewUserService<U> {
13
+ readonly mailgunService: MailgunService;
14
+ constructor(authService: FirebaseServerAuthService<U>, mailgunService: MailgunService);
15
+ protected sendSetupContentToUser(user: FirebaseServerAuthNewUserSetupDetails<U>): Promise<void>;
16
+ protected abstract buildNewUserMailgunContentRequest(user: FirebaseServerAuthNewUserSetupDetails<U>): Promise<NewUserMailgunContentRequest>;
17
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractMailgunContentFirebaseServerNewUserService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const firebase_server_1 = require("@dereekb/firebase-server");
6
+ /**
7
+ * Abstract FirebaseServerNewUserService implementation that sends an email to a template on Mailgun.
8
+ */
9
+ class AbstractMailgunContentFirebaseServerNewUserService extends firebase_server_1.AbstractFirebaseServerNewUserService {
10
+ constructor(authService, mailgunService) {
11
+ super(authService);
12
+ this.mailgunService = mailgunService;
13
+ }
14
+ sendSetupContentToUser(user) {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ const userRecord = yield user.userContext.loadRecord();
17
+ const { setupPassword } = user.claims;
18
+ const { uid, displayName, email } = userRecord;
19
+ if (!email) {
20
+ throw new Error(`Email is not present/available for the user record "${userRecord.uid}"`);
21
+ }
22
+ const baseRequest = yield this.buildNewUserMailgunContentRequest(user);
23
+ yield this.mailgunService.sendTemplateEmail(Object.assign(Object.assign({}, baseRequest), { to: {
24
+ email,
25
+ userVariables: {
26
+ uid,
27
+ displayName,
28
+ setupPassword
29
+ }
30
+ } }));
31
+ });
32
+ }
33
+ }
34
+ exports.AbstractMailgunContentFirebaseServerNewUserService = AbstractMailgunContentFirebaseServerNewUserService;
35
+ //# sourceMappingURL=auth.mailgun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.mailgun.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/mailgun/src/lib/auth.mailgun.ts"],"names":[],"mappings":";;;;AACA,8DAAiL;AASjL;;GAEG;AACH,MAAsB,kDAA4H,SAAQ,sDAAuC;IAC/L,YAAY,WAAyC,EAAW,cAA8B;QAC5F,KAAK,CAAC,WAAW,CAAC,CAAC;QAD2C,mBAAc,GAAd,cAAc,CAAgB;IAE9F,CAAC;IAEe,sBAAsB,CAAC,IAA8C;;YACnF,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;YACvD,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;YACtC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC;YAE/C,IAAI,CAAC,KAAK,EAAE;gBACV,MAAM,IAAI,KAAK,CAAC,uDAAuD,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC;aAC3F;YAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC;YACvE,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,iCACtC,WAAW,KACd,EAAE,EAAE;oBACF,KAAK;oBACL,aAAa,EAAE;wBACb,GAAG;wBACH,WAAW;wBACX,aAAa;qBACd;iBACF,IACD,CAAC;QACL,CAAC;KAAA;CAGF;AA7BD,gHA6BC"}
@@ -0,0 +1 @@
1
+ export * from './auth.mailgun';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./auth.mailgun"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/mailgun/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B"}
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server",
3
- "version": "9.7.7",
3
+ "version": "9.9.1",
4
4
  "devDependencies": {
5
5
  "firebase-functions-test": "2.0.2"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "jsonwebtoken": "^8.0.0",
9
- "@dereekb/firebase": "9.7.7",
9
+ "@dereekb/firebase": "9.9.1",
10
10
  "rxjs": "^7.5.0",
11
11
  "firebase": "^9.9.2",
12
- "@dereekb/util": "9.7.7",
12
+ "@dereekb/util": "9.9.1",
13
13
  "lodash.isequal": "^4.5.0",
14
14
  "make-error": "^1.3.0",
15
15
  "ts-essentials": "^9.1.2",
16
16
  "extra-set": "^2.2.11",
17
- "@dereekb/rxjs": "9.7.7",
17
+ "@dereekb/rxjs": "9.9.1",
18
18
  "ms": "^3.0.0-canary.1",
19
- "@dereekb/model": "9.7.7",
19
+ "@dereekb/model": "9.9.1",
20
20
  "class-transformer": "^0.5.1",
21
21
  "class-validator": "^0.13.2",
22
- "@dereekb/date": "9.7.7",
22
+ "@dereekb/date": "9.9.1",
23
23
  "date-fns": "^2.29.0",
24
24
  "date-fns-tz": "^1.3.0",
25
25
  "rrule": "git+https://git@github.com/dereekb/rrule#2b13b1ea881059ba2ecfec380e12ef244ef54570",
@@ -30,7 +30,7 @@
30
30
  "@nestjs/common": "^9.0.0",
31
31
  "@nestjs/core": "^9.0.0",
32
32
  "@nestjs/platform-express": "^9.0.0",
33
- "@dereekb/nestjs": "9.7.7",
33
+ "@dereekb/nestjs": "9.9.1",
34
34
  "@nestjs/config": "^2.0.1",
35
35
  "tslib": "^2.0.0"
36
36
  },
@@ -44,6 +44,11 @@
44
44
  "main": "./test/index.js",
45
45
  "types": "./test/index.d.ts",
46
46
  "default": "./test/index.js"
47
+ },
48
+ "./mailgun": {
49
+ "main": "./mailgun/index.js",
50
+ "types": "./mailgun/index.d.ts",
51
+ "default": "./mailgun/index.js"
47
52
  }
48
53
  },
49
54
  "main": "./src/index.js",
@@ -1,7 +1,7 @@
1
1
  import * as functions from 'firebase-functions';
2
2
  import * as admin from 'firebase-admin';
3
3
  import { FirebaseAuthContextInfo, FirebaseAuthUserId } from '@dereekb/firebase';
4
- import { AuthClaims, AuthRoleSet, ArrayOrValue, AuthRole, AuthClaimsUpdate, AuthClaimsObject, Maybe } from '@dereekb/util';
4
+ import { ISO8601DateString, Milliseconds, AuthClaims, AuthRoleSet, ArrayOrValue, AuthRole, AuthClaimsUpdate, AuthClaimsObject, Maybe, EmailAddress, E164PhoneNumber, PasswordString } from '@dereekb/util';
5
5
  import { CallableContextWithAuthData } from '../function/context';
6
6
  import { AuthDataRef } from './auth.context';
7
7
  export interface FirebaseServerAuthUserIdentifierContext {
@@ -11,6 +11,10 @@ export interface FirebaseServerAuthUserIdentifierContext {
11
11
  readonly uid: FirebaseAuthUserId;
12
12
  }
13
13
  export interface FirebaseServerAuthUserContext extends FirebaseServerAuthUserIdentifierContext {
14
+ /**
15
+ * Returns true if the user exists.
16
+ */
17
+ exists(): Promise<boolean>;
14
18
  /**
15
19
  * Loads the record of the user.
16
20
  */
@@ -48,13 +52,13 @@ export interface FirebaseServerAuthUserContext extends FirebaseServerAuthUserIde
48
52
  *
49
53
  * @param claims
50
54
  */
51
- updateClaims(claims: AuthClaimsUpdate): Promise<void>;
55
+ updateClaims<T extends AuthClaimsObject = AuthClaimsObject>(claims: AuthClaimsUpdate<T>): Promise<void>;
52
56
  /**
53
57
  * Sets the claims for a user. All previous claims are cleared.
54
58
  *
55
59
  * @param claims
56
60
  */
57
- setClaims(claims: AuthClaimsUpdate): Promise<void>;
61
+ setClaims<T extends AuthClaimsObject = AuthClaimsObject>(claims: AuthClaimsUpdate<T>): Promise<void>;
58
62
  /**
59
63
  * Clears all claims for the user.
60
64
  *
@@ -67,6 +71,7 @@ export declare abstract class AbstractFirebaseServerAuthUserContext<S extends Fi
67
71
  readonly uid: FirebaseAuthUserId;
68
72
  private readonly _loadRecord;
69
73
  constructor(service: S, uid: FirebaseAuthUserId);
74
+ exists(): Promise<boolean>;
70
75
  loadRecord(): Promise<admin.auth.UserRecord>;
71
76
  loadRoles(): Promise<AuthRoleSet>;
72
77
  addRoles(roles: ArrayOrValue<AuthRole>): Promise<void>;
@@ -78,9 +83,9 @@ export declare abstract class AbstractFirebaseServerAuthUserContext<S extends Fi
78
83
  [x: symbol]: null;
79
84
  }>;
80
85
  loadClaims<T extends AuthClaimsObject = AuthClaimsObject>(): Promise<AuthClaims<T>>;
81
- updateClaims(claims: AuthClaimsUpdate): Promise<void>;
86
+ updateClaims<T extends AuthClaimsObject = AuthClaimsObject>(claims: AuthClaimsUpdate<T>): Promise<void>;
82
87
  clearClaims(): Promise<void>;
83
- setClaims(claims: AuthClaimsUpdate | null): Promise<void>;
88
+ setClaims<T extends AuthClaimsObject = AuthClaimsObject>(claims: AuthClaimsUpdate<T> | null): Promise<void>;
84
89
  }
85
90
  export interface FirebaseServerAuthContext<U extends FirebaseServerAuthUserContext = FirebaseServerAuthUserContext> extends FirebaseServerAuthUserIdentifierContext {
86
91
  /**
@@ -128,6 +133,94 @@ export declare abstract class AbstractFirebaseServerAuthContext<C extends Fireba
128
133
  get claims(): AuthClaims;
129
134
  get uid(): string;
130
135
  }
136
+ export declare const FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY = "setupPassword";
137
+ export declare const FIREBASE_SERVER_AUTH_CLAIMS_SETUP_LAST_COM_DATE_KEY = "setupCommunicationAt";
138
+ /**
139
+ * Password used for completing setup.
140
+ */
141
+ export declare type FirebaseServerAuthSetupPassword = PasswordString;
142
+ export interface FirebaseServerAuthNewUserClaims extends AuthClaimsObject {
143
+ /**
144
+ * Setup password time
145
+ */
146
+ setupPassword: FirebaseServerAuthSetupPassword;
147
+ /**
148
+ * Last setup communication time.
149
+ */
150
+ setupCommunicationAt: ISO8601DateString;
151
+ }
152
+ export interface FirebaseServerAuthInitializeNewUser {
153
+ /**
154
+ * Specific user identifier to use.
155
+ */
156
+ readonly uid?: FirebaseAuthUserId;
157
+ /**
158
+ * User's display name
159
+ */
160
+ readonly displayName?: string;
161
+ /**
162
+ * Email for the new user, if applicable.
163
+ */
164
+ readonly email?: EmailAddress;
165
+ /**
166
+ * Phone for the new user, if applicable.
167
+ */
168
+ readonly phone?: E164PhoneNumber;
169
+ /**
170
+ * Password to set on the user if not created yet.
171
+ *
172
+ * This is a setup password and should not be the user's permenant/final password.
173
+ */
174
+ readonly setupPassword?: FirebaseServerAuthSetupPassword;
175
+ /**
176
+ * Whether or not to send a setup email. Is true by default.
177
+ */
178
+ readonly sendSetupContent?: boolean;
179
+ }
180
+ export interface FirebaseServerAuthCreateNewUserResult {
181
+ readonly user: admin.auth.UserRecord;
182
+ readonly password: FirebaseServerAuthSetupPassword;
183
+ }
184
+ export interface FirebaseServerAuthNewUserSetupDetails<U extends FirebaseServerAuthUserContext = FirebaseServerAuthUserContext> {
185
+ readonly userContext: U;
186
+ readonly claims: FirebaseServerAuthNewUserClaims;
187
+ }
188
+ export interface FirebaseServerNewUserService {
189
+ initializeNewUser(input: FirebaseServerAuthInitializeNewUser): Promise<admin.auth.UserRecord>;
190
+ sendSetupContent(uid: FirebaseAuthUserId): Promise<boolean>;
191
+ markUserSetupAsComplete(uid: FirebaseAuthUserId): Promise<boolean>;
192
+ }
193
+ export declare const DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR: import("@dereekb/util").RandomNumberFactory;
194
+ export declare const DEFAULT_SETUP_COM_THROTTLE_TIME: number;
195
+ export declare abstract class AbstractFirebaseServerNewUserService<U extends FirebaseServerAuthUserContext = FirebaseServerAuthUserContext, C extends FirebaseServerAuthContext = FirebaseServerAuthContext> implements FirebaseServerNewUserService {
196
+ readonly authService: FirebaseServerAuthService<U, C>;
197
+ protected setupThrottleTime: Milliseconds;
198
+ constructor(authService: FirebaseServerAuthService<U, C>);
199
+ initializeNewUser(input: FirebaseServerAuthInitializeNewUser): Promise<admin.auth.UserRecord>;
200
+ /**
201
+ * Sends the setup content to the user. Returns true if content was sent or was already recently sent.
202
+ *
203
+ * @param uid
204
+ */
205
+ sendSetupContent(uid: FirebaseAuthUserId): Promise<boolean>;
206
+ loadSetupDetails(uid: FirebaseAuthUserId): Promise<Maybe<FirebaseServerAuthNewUserSetupDetails<U>>>;
207
+ protected updateSetupContentSentTime(details: FirebaseServerAuthNewUserSetupDetails<U>): Promise<void>;
208
+ /**
209
+ * Update a user's claims to clear any setup-related content.
210
+ *
211
+ * Returns true if a user was updated.
212
+ *
213
+ * @param uid
214
+ */
215
+ markUserSetupAsComplete(uid: FirebaseAuthUserId): Promise<boolean>;
216
+ protected createNewUser(input: FirebaseServerAuthInitializeNewUser): Promise<FirebaseServerAuthCreateNewUserResult>;
217
+ protected generateRandomSetupPassword(): FirebaseServerAuthSetupPassword;
218
+ protected abstract sendSetupContentToUser(user: FirebaseServerAuthNewUserSetupDetails<U>): Promise<void>;
219
+ protected updateClaimsToClearUser(userContext: U): Promise<void>;
220
+ }
221
+ export declare class NoSetupContentFirebaseServerNewUserService<U extends FirebaseServerAuthUserContext = FirebaseServerAuthUserContext> extends AbstractFirebaseServerNewUserService<U> {
222
+ protected sendSetupContentToUser(user: FirebaseServerAuthNewUserSetupDetails<U>): Promise<void>;
223
+ }
131
224
  /**
132
225
  * Reference to a FirebaseServerAuthService
133
226
  */
@@ -199,6 +292,10 @@ export declare abstract class FirebaseServerAuthService<U extends FirebaseServer
199
292
  * @param context
200
293
  */
201
294
  abstract authContextInfo(context: AuthDataRef): Maybe<FirebaseAuthContextInfo>;
295
+ /**
296
+ * Returns the new user service to create a new user programmatically.
297
+ */
298
+ abstract newUser(): FirebaseServerNewUserService;
202
299
  }
203
300
  /**
204
301
  * Abstract FirebaseServerAuthService implementation.
@@ -215,5 +312,6 @@ export declare abstract class AbstractFirebaseServerAuthService<U extends Fireba
215
312
  hasSignedTosInRoles(roles: AuthRoleSet): boolean;
216
313
  abstract readRoles(claims: AuthClaims): AuthRoleSet;
217
314
  abstract claimsForRoles(roles: AuthRoleSet): AuthClaimsUpdate;
315
+ newUser(): FirebaseServerNewUserService;
218
316
  authContextInfo(context: AuthDataRef): Maybe<FirebaseAuthContextInfo>;
219
317
  }
@@ -1,16 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractFirebaseServerAuthService = exports.FirebaseServerAuthService = exports.AbstractFirebaseServerAuthContext = exports.AbstractFirebaseServerAuthUserContext = void 0;
3
+ exports.AbstractFirebaseServerAuthService = exports.FirebaseServerAuthService = exports.NoSetupContentFirebaseServerNewUserService = exports.AbstractFirebaseServerNewUserService = exports.DEFAULT_SETUP_COM_THROTTLE_TIME = exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR = exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_LAST_COM_DATE_KEY = exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY = exports.AbstractFirebaseServerAuthContext = exports.AbstractFirebaseServerAuthUserContext = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const util_1 = require("@dereekb/util");
6
6
  const context_1 = require("../function/context");
7
7
  const auth_context_1 = require("./auth.context");
8
+ const date_1 = require("@dereekb/date");
9
+ const auth_util_1 = require("./auth.util");
8
10
  class AbstractFirebaseServerAuthUserContext {
9
11
  constructor(service, uid) {
10
12
  this.service = service;
11
13
  this.uid = uid;
12
14
  this._loadRecord = (0, util_1.cachedGetter)(() => this.service.auth.getUser(this.uid));
13
15
  }
16
+ exists() {
17
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
+ return (0, auth_util_1.getAuthUserOrUndefined)(this._loadRecord()).then((x) => Boolean(x));
19
+ });
20
+ }
14
21
  loadRecord() {
15
22
  return this._loadRecord();
16
23
  }
@@ -109,6 +116,150 @@ class AbstractFirebaseServerAuthContext {
109
116
  }
110
117
  }
111
118
  exports.AbstractFirebaseServerAuthContext = AbstractFirebaseServerAuthContext;
119
+ // MARK: New Account Initialization
120
+ exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY = 'setupPassword';
121
+ exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_LAST_COM_DATE_KEY = 'setupCommunicationAt';
122
+ exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR = (0, util_1.randomNumberFactory)({ min: 100000, max: 1000000 - 1 });
123
+ exports.DEFAULT_SETUP_COM_THROTTLE_TIME = (0, date_1.hoursToMs)(1);
124
+ class AbstractFirebaseServerNewUserService {
125
+ constructor(authService) {
126
+ this.authService = authService;
127
+ this.setupThrottleTime = exports.DEFAULT_SETUP_COM_THROTTLE_TIME;
128
+ }
129
+ initializeNewUser(input) {
130
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
131
+ const { uid, displayName, email, phone, sendSetupContent: sendSetupEmail } = input;
132
+ let userRecordPromise;
133
+ if (uid) {
134
+ userRecordPromise = this.authService.auth.getUser(uid);
135
+ }
136
+ else if (email) {
137
+ userRecordPromise = this.authService.auth.getUserByEmail(email);
138
+ }
139
+ else if (phone) {
140
+ userRecordPromise = this.authService.auth.getUserByPhoneNumber(phone);
141
+ }
142
+ else {
143
+ throw new Error('email or phone is required to initialize a new user.');
144
+ }
145
+ let userRecord = yield (0, auth_util_1.getAuthUserOrUndefined)(userRecordPromise);
146
+ if (!userRecord) {
147
+ const createResult = yield this.createNewUser(input);
148
+ // add the setup password to the user's credentials
149
+ const userContext = this.authService.userContext(createResult.user.uid);
150
+ yield userContext.updateClaims({
151
+ [exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY]: createResult.password
152
+ });
153
+ if (sendSetupEmail !== false) {
154
+ yield this.sendSetupContent(createResult.user.uid);
155
+ }
156
+ // return the new record
157
+ userRecord = yield userContext.loadRecord();
158
+ }
159
+ return userRecord;
160
+ });
161
+ }
162
+ /**
163
+ * Sends the setup content to the user. Returns true if content was sent or was already recently sent.
164
+ *
165
+ * @param uid
166
+ */
167
+ sendSetupContent(uid) {
168
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
169
+ const setupDetails = yield this.loadSetupDetails(uid);
170
+ if (setupDetails) {
171
+ const { setupCommunicationAt } = setupDetails.claims;
172
+ if (!setupCommunicationAt || (0, date_1.timeHasExpired)(new Date(setupCommunicationAt), this.setupThrottleTime)) {
173
+ yield this.sendSetupContentToUser(setupDetails);
174
+ yield this.updateSetupContentSentTime(setupDetails);
175
+ }
176
+ }
177
+ return false;
178
+ });
179
+ }
180
+ loadSetupDetails(uid) {
181
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
182
+ const userContext = this.authService.userContext(uid);
183
+ const userExists = yield userContext.exists();
184
+ let details;
185
+ if (userExists) {
186
+ const { setupPassword, setupCommunicationAt } = yield userContext.loadClaims();
187
+ if (setupPassword) {
188
+ details = {
189
+ userContext,
190
+ claims: {
191
+ setupPassword,
192
+ setupCommunicationAt
193
+ }
194
+ };
195
+ }
196
+ }
197
+ return details;
198
+ });
199
+ }
200
+ updateSetupContentSentTime(details) {
201
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
202
+ yield details.userContext.updateClaims({
203
+ setupCommunicationAt: (0, date_1.toISODateString)(new Date())
204
+ });
205
+ });
206
+ }
207
+ /**
208
+ * Update a user's claims to clear any setup-related content.
209
+ *
210
+ * Returns true if a user was updated.
211
+ *
212
+ * @param uid
213
+ */
214
+ markUserSetupAsComplete(uid) {
215
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
216
+ const userContext = this.authService.userContext(uid);
217
+ const userExists = yield userContext.exists();
218
+ if (userExists) {
219
+ yield this.updateClaimsToClearUser(userContext);
220
+ }
221
+ return userExists;
222
+ });
223
+ }
224
+ createNewUser(input) {
225
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
226
+ const { uid, displayName, email, phone: phoneNumber, setupPassword: inputPassword } = input;
227
+ const password = inputPassword !== null && inputPassword !== void 0 ? inputPassword : this.generateRandomSetupPassword();
228
+ const user = yield this.authService.auth.createUser({
229
+ uid,
230
+ displayName,
231
+ email,
232
+ phoneNumber,
233
+ password
234
+ });
235
+ return {
236
+ user,
237
+ password
238
+ };
239
+ });
240
+ }
241
+ generateRandomSetupPassword() {
242
+ const x = (0, exports.DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR)();
243
+ return `${x}`;
244
+ }
245
+ updateClaimsToClearUser(userContext) {
246
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
247
+ yield userContext.updateClaims({
248
+ [exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY]: null,
249
+ [exports.FIREBASE_SERVER_AUTH_CLAIMS_SETUP_LAST_COM_DATE_KEY]: null
250
+ });
251
+ });
252
+ }
253
+ }
254
+ exports.AbstractFirebaseServerNewUserService = AbstractFirebaseServerNewUserService;
255
+ class NoSetupContentFirebaseServerNewUserService extends AbstractFirebaseServerNewUserService {
256
+ sendSetupContentToUser(user) {
257
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
258
+ // send nothing.
259
+ });
260
+ }
261
+ }
262
+ exports.NoSetupContentFirebaseServerNewUserService = NoSetupContentFirebaseServerNewUserService;
112
263
  /**
113
264
  * FirebaseServer auth service that provides accessors to auth-related components.
114
265
  */
@@ -138,6 +289,9 @@ class AbstractFirebaseServerAuthService {
138
289
  hasSignedTosInRoles(roles) {
139
290
  return roles.has(util_1.AUTH_TOS_SIGNED_ROLE);
140
291
  }
292
+ newUser() {
293
+ return new NoSetupContentFirebaseServerNewUserService(this);
294
+ }
141
295
  authContextInfo(context) {
142
296
  const { auth } = context;
143
297
  let result;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/src/lib/auth/auth.service.ts"],"names":[],"mappings":";;;;AAGA,wCAAkS;AAClS,iDAA+F;AAC/F,iDAAkF;AAsElF,MAAsB,qCAAqC;IAGzD,YAAqB,OAAU,EAAW,GAAuB;QAA5C,YAAO,GAAP,OAAO,CAAG;QAAW,QAAG,GAAH,GAAG,CAAoB;QAFhD,gBAAW,GAAG,IAAA,mBAAY,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAEnB,CAAC;IAErE,UAAU;QACR,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAEK,SAAS;;YACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;KAAA;IAEK,QAAQ,CAAC,KAA6B;;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;KAAA;IAEK,WAAW,CAAC,KAA6B;;YAC7C,MAAM,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C;IACzC,CAAC;IAMD,eAAe,CAAC,OAAoB;QAClC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QACzB,IAAI,MAAsC,CAAC;QAE3C,IAAI,IAAI,EAAE;YACR,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAA8B,CAAC,CAAC,CAAC;YACvF,MAAM,SAAS,GAAG,GAAkD,EAAE,CAAC,IAAI,CAAC,KAAiC,CAAC;YAE9G,MAAM,GAAG;gBACP,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;gBAC5C,SAAS;gBACT,YAAY,EAAE,MAAM;gBACpB,KAAK,EAAE,IAAA,kDAAmC,EAAC,IAAI,CAAC,KAAK,CAAC;aACvD,CAAC;SACH;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAnDD,8EAmDC"}
1
+ {"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/src/lib/auth/auth.service.ts"],"names":[],"mappings":";;;;AAGA,wCAAuY;AACvY,iDAA+F;AAC/F,iDAAkF;AAClF,wCAA2E;AAC3E,2CAAqD;AA2ErD,MAAsB,qCAAqC;IAGzD,YAAqB,OAAU,EAAW,GAAuB;QAA5C,YAAO,GAAP,OAAO,CAAG;QAAW,QAAG,GAAH,GAAG,CAAoB;QAFhD,gBAAW,GAAG,IAAA,mBAAY,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAEnB,CAAC;IAE/D,MAAM;;YACV,OAAO,IAAA,kCAAsB,EAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC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I,CAAC,GAAG;gBACb,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;gBAC5C,SAAS;gBACT,YAAY,EAAE,MAAM;gBACpB,KAAK,EAAE,IAAA,kDAAmC,EAAC,IAAI,CAAC,KAAK,CAAC;aACvD,CAAC;SACH;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAvDD,8EAuDC"}
@@ -0,0 +1,8 @@
1
+ import { Maybe } from '@dereekb/util';
2
+ import * as admin from 'firebase-admin';
3
+ /**
4
+ * Awaits the load result from the input promise. If it encounters a FIREBASE_AUTH_USER_NOT_FOUND_ERROR, then returns undefined. Throws the error otherwise.
5
+ * @param promise
6
+ * @returns
7
+ */
8
+ export declare function getAuthUserOrUndefined(promise: Promise<admin.auth.UserRecord>): Promise<Maybe<admin.auth.UserRecord>>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAuthUserOrUndefined = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const firebase_1 = require("@dereekb/firebase");
6
+ /**
7
+ * Awaits the load result from the input promise. If it encounters a FIREBASE_AUTH_USER_NOT_FOUND_ERROR, then returns undefined. Throws the error otherwise.
8
+ * @param promise
9
+ * @returns
10
+ */
11
+ function getAuthUserOrUndefined(promise) {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ try {
14
+ return yield promise;
15
+ }
16
+ catch (error) {
17
+ if ((error === null || error === void 0 ? void 0 : error.code) === firebase_1.FIREBASE_AUTH_USER_NOT_FOUND_ERROR) {
18
+ return undefined;
19
+ }
20
+ else {
21
+ throw error;
22
+ }
23
+ }
24
+ });
25
+ }
26
+ exports.getAuthUserOrUndefined = getAuthUserOrUndefined;
27
+ //# sourceMappingURL=auth.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.util.js","sourceRoot":"","sources":["../../../../../../packages/firebase-server/src/lib/auth/auth.util.ts"],"names":[],"mappings":";;;;AAAA,gDAA0F;AAI1F;;;;GAIG;AACH,SAAsB,sBAAsB,CAAC,OAAuC;;QAClF,IAAI;YACF,OAAO,MAAM,OAAO,CAAC;SACtB;QAAC,OAAO,KAAc,EAAE;YACvB,IAAI,CAAC,KAA2B,aAA3B,KAAK,uBAAL,KAAK,CAAwB,IAAI,MAAK,6CAAkC,EAAE;gBAC7E,OAAO,SAAS,CAAC;aAClB;iBAAM;gBACL,MAAM,KAAK,CAAC;aACb;SACF;IACH,CAAC;CAAA;AAVD,wDAUC"}