@dereekb/firebase-server 13.12.3 → 13.12.5

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/index.cjs.js CHANGED
@@ -265,6 +265,12 @@ function _type_of$7(obj) {
265
265
  *
266
266
  * @param input - The value to check.
267
267
  * @returns `true` if the input is a Firebase {@link HttpsError}.
268
+ *
269
+ * @dbxUtil
270
+ * @dbxUtilCategory firebase-error
271
+ * @dbxUtilKind function
272
+ * @dbxUtilTags firebase, https, error, type-guard, server, callable
273
+ * @dbxUtilRelated is-firebase-error, firebase-server-error-info
268
274
  */ function isFirebaseHttpsError(input) {
269
275
  return (typeof input === "undefined" ? "undefined" : _type_of$7(input)) === 'object' && input != null && 'code' in input && 'httpErrorCode' in input && 'toJSON' in input;
270
276
  }
@@ -273,6 +279,12 @@ function _type_of$7(obj) {
273
279
  *
274
280
  * @param input - The value to check.
275
281
  * @returns `true` if the input is a Firebase Admin {@link admin.FirebaseError}.
282
+ *
283
+ * @dbxUtil
284
+ * @dbxUtilCategory firebase-error
285
+ * @dbxUtilKind function
286
+ * @dbxUtilTags firebase, admin, error, type-guard, server
287
+ * @dbxUtilRelated is-firebase-https-error, firebase-server-error-info
276
288
  */ function isFirebaseError(input) {
277
289
  return (typeof input === "undefined" ? "undefined" : _type_of$7(input)) === 'object' && input != null && 'code' in input && 'message' in input && 'toJSON' in input;
278
290
  }
@@ -285,6 +297,12 @@ function _type_of$7(obj) {
285
297
  * @param e - The caught error to analyze.
286
298
  * @returns Structured {@link FirebaseServerErrorInfo} with classified error details.
287
299
  *
300
+ * @dbxUtil
301
+ * @dbxUtilCategory firebase-error
302
+ * @dbxUtilKind function
303
+ * @dbxUtilTags firebase, error, decode, analyze, https, admin, server, classify, server-error
304
+ * @dbxUtilRelated firebase-server-error-info-code-pair, firebase-server-error-info-server-error-pair, firebase-server-error-info-server-error-code-pair, is-firebase-https-error, is-firebase-error
305
+ *
288
306
  * @example
289
307
  * ```typescript
290
308
  * try {
@@ -331,6 +349,12 @@ function _type_of$7(obj) {
331
349
  *
332
350
  * @param e - The caught error to analyze.
333
351
  * @returns A tuple of the Firebase error code (if present) and the full error info.
352
+ *
353
+ * @dbxUtil
354
+ * @dbxUtilCategory firebase-error
355
+ * @dbxUtilKind function
356
+ * @dbxUtilTags firebase, error, code, pair, tuple, pattern-match, decode
357
+ * @dbxUtilRelated firebase-server-error-info, firebase-server-error-info-server-error-pair, firebase-server-error-info-server-error-code-pair
334
358
  */ function firebaseServerErrorInfoCodePair(e) {
335
359
  var info = firebaseServerErrorInfo(e);
336
360
  return [
@@ -343,6 +367,12 @@ function _type_of$7(obj) {
343
367
  *
344
368
  * @param e - The caught error to analyze.
345
369
  * @returns A tuple of the server error (if present) and the full error info.
370
+ *
371
+ * @dbxUtil
372
+ * @dbxUtilCategory firebase-error
373
+ * @dbxUtilKind function
374
+ * @dbxUtilTags firebase, error, server-error, pair, tuple, pattern-match, decode, details
375
+ * @dbxUtilRelated firebase-server-error-info, firebase-server-error-info-code-pair, firebase-server-error-info-server-error-code-pair
346
376
  */ function firebaseServerErrorInfoServerErrorPair(e) {
347
377
  var info = firebaseServerErrorInfo(e);
348
378
  return [
@@ -355,6 +385,12 @@ function _type_of$7(obj) {
355
385
  *
356
386
  * @param e - The caught error to analyze.
357
387
  * @returns A tuple of the server error code (if present) and the full error info.
388
+ *
389
+ * @dbxUtil
390
+ * @dbxUtilCategory firebase-error
391
+ * @dbxUtilKind function
392
+ * @dbxUtilTags firebase, error, server-error, code, string-code, pair, tuple, pattern-match, decode
393
+ * @dbxUtilRelated firebase-server-error-info, firebase-server-error-info-code-pair, firebase-server-error-info-server-error-pair
358
394
  */ function firebaseServerErrorInfoServerErrorCodePair(e) {
359
395
  var info = firebaseServerErrorInfo(e);
360
396
  return [
@@ -369,6 +405,12 @@ function _type_of$7(obj) {
369
405
  *
370
406
  * @param e - The caught error.
371
407
  * @param handleFirebaseErrorFn - Handler that receives the typed {@link admin.FirebaseError}.
408
+ *
409
+ * @dbxUtil
410
+ * @dbxUtilCategory firebase-error
411
+ * @dbxUtilKind function
412
+ * @dbxUtilTags firebase, admin, error, handler, catch, conditional, rethrow
413
+ * @dbxUtilRelated is-firebase-error, firebase-server-error-info
372
414
  */ function handleFirebaseError(e, handleFirebaseErrorFn) {
373
415
  var firebaseError = e.code ? e : undefined;
374
416
  if (firebaseError) {
@@ -1256,15 +1298,6 @@ function _ts_generator$g(thisArg, body) {
1256
1298
  this.updateClaims(passwordClaimsData)
1257
1299
  ];
1258
1300
  case 1:
1259
- _state.sent();
1260
- // update the user
1261
- return [
1262
- 4,
1263
- this.updateUser({
1264
- password: password
1265
- })
1266
- ];
1267
- case 2:
1268
1301
  _state.sent();
1269
1302
  return [
1270
1303
  2,
@@ -1346,11 +1379,43 @@ function _ts_generator$g(thisArg, body) {
1346
1379
  key: "updateUser",
1347
1380
  value: function updateUser(template) {
1348
1381
  return _async_to_generator$g(function() {
1382
+ var e, firebaseError, errorCode, email, phoneNumber;
1349
1383
  return _ts_generator$g(this, function(_state) {
1350
- return [
1351
- 2,
1352
- this.service.auth.updateUser(this.uid, template)
1353
- ];
1384
+ switch(_state.label){
1385
+ case 0:
1386
+ _state.trys.push([
1387
+ 0,
1388
+ 2,
1389
+ ,
1390
+ 3
1391
+ ]);
1392
+ return [
1393
+ 4,
1394
+ this.service.auth.updateUser(this.uid, template)
1395
+ ];
1396
+ case 1:
1397
+ return [
1398
+ 2,
1399
+ _state.sent()
1400
+ ];
1401
+ case 2:
1402
+ e = _state.sent();
1403
+ firebaseError = e;
1404
+ errorCode = firebaseError.code;
1405
+ email = template.email, phoneNumber = template.phoneNumber;
1406
+ if (errorCode === firebase.FIREBASE_AUTH_PHONE_NUMBER_ALREADY_EXISTS_ERROR && phoneNumber) {
1407
+ throw new FirebaseServerAuthUserExistsError(errorCode, 'phone', phoneNumber);
1408
+ } else if (errorCode === firebase.FIREBASE_AUTH_EMAIL_ALREADY_EXISTS_ERROR && email) {
1409
+ throw new FirebaseServerAuthUserExistsError(errorCode, 'email', email);
1410
+ } else if (errorCode === firebase.FIREBASE_AUTH_INVALID_PHONE_NUMBER_ERROR && phoneNumber) {
1411
+ throw new FirebaseServerAuthUserBadInputError(errorCode, phoneNumber);
1412
+ }
1413
+ throw e;
1414
+ case 3:
1415
+ return [
1416
+ 2
1417
+ ];
1418
+ }
1354
1419
  });
1355
1420
  }).call(this);
1356
1421
  }
@@ -2123,6 +2188,50 @@ function _ts_generator$g(thisArg, body) {
2123
2188
  ]);
2124
2189
  return NoSetupContentFirebaseServerNewUserService;
2125
2190
  }(AbstractFirebaseServerNewUserService);
2191
+ /**
2192
+ * Builds the composite oob code from a raw reset code (the numeric value stored in
2193
+ * {@link FirebaseServerAuthResetUserPasswordClaims.resetPassword}) and the target user's uid.
2194
+ *
2195
+ * @param uid - The target user's UID.
2196
+ * @param code - The raw reset code from the user's claims.
2197
+ *
2198
+ * @example
2199
+ * ```typescript
2200
+ * const oobCode = encodeFirebaseServerUserPasswordResetOobCode(user.uid, claims.resetPassword);
2201
+ * // e.g. '482910-abcDEF123'
2202
+ * ```
2203
+ */ function encodeFirebaseServerUserPasswordResetOobCode(uid, code) {
2204
+ return "".concat(code, "-").concat(uid);
2205
+ }
2206
+ /**
2207
+ * Decodes a composite oob code back into its `{ uid, code }` parts. Returns `undefined`
2208
+ * when the token is malformed (missing separator, non-numeric code, empty uid).
2209
+ *
2210
+ * @param token - The composite oob token, typically received from the password-reset email.
2211
+ *
2212
+ * @example
2213
+ * ```typescript
2214
+ * const decoded = decodeFirebaseServerUserPasswordResetOobCode('482910-abcDEF123');
2215
+ * // decoded = { uid: 'abcDEF123', code: '482910' }
2216
+ * ```
2217
+ */ function decodeFirebaseServerUserPasswordResetOobCode(token) {
2218
+ var result;
2219
+ if (typeof token === 'string') {
2220
+ var dashIndex = token.indexOf('-');
2221
+ if (dashIndex > 0 && dashIndex < token.length - 1) {
2222
+ var code = token.slice(0, dashIndex);
2223
+ var uid = token.slice(dashIndex + 1);
2224
+ // Code must be purely digits (matches DEFAULT_FIREBASE_PASSWORD_NUMBER_GENERATOR output).
2225
+ if (/^\d+$/.test(code)) {
2226
+ result = {
2227
+ uid: uid,
2228
+ code: code
2229
+ };
2230
+ }
2231
+ }
2232
+ }
2233
+ return result;
2234
+ }
2126
2235
  /**
2127
2236
  * Default throttle duration (60 seconds) between reset content re-sends to prevent spam while
2128
2237
  * remaining responsive for legitimate users who didn't receive the first email.
@@ -2171,7 +2280,7 @@ function _ts_generator$g(thisArg, body) {
2171
2280
  key: "beginPasswordReset",
2172
2281
  value: function beginPasswordReset(input) {
2173
2282
  return _async_to_generator$g(function() {
2174
- var uid, email, sendResetContent, sendResetDetailsOnce, sendResetIgnoreThrottle, sendResetThrowErrors, data, sendDetailsInTestEnvironment, resolvedUid, userRecord, userContext, claims;
2283
+ var uid, email, sendResetContent, sendResetDetailsOnce, sendResetIgnoreThrottle, sendResetThrowErrors, data, sendDetailsInTestEnvironment, resolvedUid, userRecord, userContext, claims, oobCode;
2175
2284
  return _ts_generator$g(this, function(_state) {
2176
2285
  switch(_state.label){
2177
2286
  case 0:
@@ -2232,9 +2341,13 @@ function _ts_generator$g(thisArg, body) {
2232
2341
  _state.sent();
2233
2342
  _state.label = 7;
2234
2343
  case 7:
2344
+ oobCode = encodeFirebaseServerUserPasswordResetOobCode(resolvedUid, claims.resetPassword);
2235
2345
  return [
2236
2346
  2,
2237
- claims
2347
+ {
2348
+ claims: claims,
2349
+ oobCode: oobCode
2350
+ }
2238
2351
  ];
2239
2352
  }
2240
2353
  });
@@ -2380,6 +2493,7 @@ function _ts_generator$g(thisArg, body) {
2380
2493
  resetCommunicationAt: claims.resetCommunicationAt,
2381
2494
  resetExpiresAt: claims.resetExpiresAt
2382
2495
  },
2496
+ oobCode: encodeFirebaseServerUserPasswordResetOobCode(userContext.uid, claims.resetPassword),
2383
2497
  data: config === null || config === void 0 ? void 0 : config.data,
2384
2498
  sendDetailsInTestEnvironment: config === null || config === void 0 ? void 0 : config.sendDetailsInTestEnvironment
2385
2499
  };
@@ -2422,30 +2536,56 @@ function _ts_generator$g(thisArg, body) {
2422
2536
  },
2423
2537
  {
2424
2538
  key: "completePasswordReset",
2425
- value: function completePasswordReset(uid, input) {
2539
+ value: function completePasswordReset(input) {
2426
2540
  return _async_to_generator$g(function() {
2427
- var userContext, claims, storedCode, expiresAt, storedBuf, inputBuf;
2541
+ var decoded, userContext, claims, storedCode, expiresAt, storedBuf, inputBuf;
2428
2542
  return _ts_generator$g(this, function(_state) {
2429
2543
  switch(_state.label){
2430
2544
  case 0:
2431
- userContext = this.authService.userContext(uid);
2545
+ // Decode the composite token. A malformed token is treated identically to every other
2546
+ // failure mode below — the caller cannot distinguish between "bad encoding", "unknown uid",
2547
+ // "no active reset", "expired", or "wrong code".
2548
+ decoded = decodeFirebaseServerUserPasswordResetOobCode(input.oobCode);
2549
+ if (!decoded) {
2550
+ throw new FirebaseServerAuthPasswordResetInvalidCodeError();
2551
+ }
2552
+ userContext = this.authService.userContext(decoded.uid);
2553
+ _state.label = 1;
2554
+ case 1:
2555
+ _state.trys.push([
2556
+ 1,
2557
+ 3,
2558
+ ,
2559
+ 4
2560
+ ]);
2432
2561
  return [
2433
2562
  4,
2434
2563
  userContext.loadResetPasswordClaims()
2435
2564
  ];
2436
- case 1:
2565
+ case 2:
2437
2566
  claims = _state.sent();
2567
+ return [
2568
+ 3,
2569
+ 4
2570
+ ];
2571
+ case 3:
2572
+ _state.sent();
2573
+ claims = undefined;
2574
+ return [
2575
+ 3,
2576
+ 4
2577
+ ];
2578
+ case 4:
2438
2579
  storedCode = claims === null || claims === void 0 ? void 0 : claims.resetPassword;
2439
2580
  expiresAt = claims === null || claims === void 0 ? void 0 : claims.resetExpiresAt;
2440
2581
  // Reject if no active reset OR the stored code is missing/wrong length OR the code is expired.
2441
- // All failure cases throw the same opaque error so callers cannot distinguish them.
2442
- if (!storedCode || !expiresAt || storedCode.length !== input.resetPassword.length || new Date(expiresAt).getTime() <= Date.now()) {
2582
+ if (!storedCode || !expiresAt || storedCode.length !== decoded.code.length || new Date(expiresAt).getTime() <= Date.now()) {
2443
2583
  throw new FirebaseServerAuthPasswordResetInvalidCodeError();
2444
2584
  }
2445
2585
  // Constant-time comparison to avoid leaking timing information about how many leading
2446
2586
  // characters of the provided code matched. Lengths are equal per the guard above.
2447
2587
  storedBuf = Buffer.from(storedCode);
2448
- inputBuf = Buffer.from(input.resetPassword);
2588
+ inputBuf = Buffer.from(decoded.code);
2449
2589
  if (!node_crypto.timingSafeEqual(storedBuf, inputBuf)) {
2450
2590
  throw new FirebaseServerAuthPasswordResetInvalidCodeError();
2451
2591
  }
@@ -12998,12 +13138,14 @@ exports.catchAndThrowPasswordResetServerErrors = catchAndThrowPasswordResetServe
12998
13138
  exports.cloudEventHandlerWithNestContextFactory = cloudEventHandlerWithNestContextFactory;
12999
13139
  exports.collectionRefForPath = collectionRefForPath;
13000
13140
  exports.createModelUnknownModelTypeError = createModelUnknownModelTypeError;
13141
+ exports.decodeFirebaseServerUserPasswordResetOobCode = decodeFirebaseServerUserPasswordResetOobCode;
13001
13142
  exports.defaultFirebaseServerActionsTransformFactoryLogErrorFunction = defaultFirebaseServerActionsTransformFactoryLogErrorFunction;
13002
13143
  exports.defaultProvideFirebaseServerStorageServiceSimple = defaultProvideFirebaseServerStorageServiceSimple;
13003
13144
  exports.deleteModelUnknownModelTypeError = deleteModelUnknownModelTypeError;
13004
13145
  exports.developmentUnknownSpecifierError = developmentUnknownSpecifierError;
13005
13146
  exports.docRefForPath = docRefForPath;
13006
13147
  exports.documentModelNotAvailableError = documentModelNotAvailableError;
13148
+ exports.encodeFirebaseServerUserPasswordResetOobCode = encodeFirebaseServerUserPasswordResetOobCode;
13007
13149
  exports.executeOnCallQuery = executeOnCallQuery;
13008
13150
  exports.firebaseAuthTokenFromDecodedIdToken = firebaseAuthTokenFromDecodedIdToken;
13009
13151
  exports.firebaseServerActionsContext = firebaseServerActionsContext;