Skip to content

Commit 33e1848

Browse files
Merge master into release
2 parents 56aad27 + d87d3a8 commit 33e1848

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+461
-147
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/rules-unit-testing': patch
3+
---
4+
5+
Add Node ESM build to rules-unit-testing.

.changeset/rotten-tables-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/database": patch
3+
---
4+
5+
Fixed issue where `get()` saved results incorrectly for non-default queries.

.changeset/sharp-rules-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/analytics': patch
3+
---
4+
5+
Fix typo in GtagConfigParams

.changeset/tame-rice-peel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@firebase/app-check": patch
3+
"@firebase/database": patch
4+
"@firebase/util": patch
5+
---
6+
7+
Extract uuid function into @firebase/util

.github/workflows/e2e-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
env:
6262
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
6363
RELEASE_TRACKER_URL: ${{ secrets.RELEASE_TRACKER_URL }}
64+
VERSION_OR_TAG: ${{ github.event.client_payload.versionOrTag }}
6465
# run in root
6566
working-directory: '.'
6667
- name: Tests failed
@@ -69,5 +70,6 @@ jobs:
6970
env:
7071
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
7172
RELEASE_TRACKER_URL: ${{ secrets.RELEASE_TRACKER_URL }}
73+
VERSION_OR_TAG: ${{ github.event.client_payload.versionOrTag }}
7274
# run in root
7375
working-directory: '.'

.vscode/launch.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
"type": "node",
99
"request": "launch",
1010
"name": "RTDB Unit Tests (Node)",
11-
"program": "${workspaceRoot}/packages/firebase/node_modules/.bin/_mocha",
11+
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
1212
"cwd": "${workspaceRoot}/packages/database",
1313
"args": [
1414
"test/{,!(browser)/**/}*.test.ts",
15-
"--file", "index.node.ts",
16-
"--config", "../../config/mocharc.node.js"
15+
"--file", "src/index.node.ts",
16+
"--config", "../../config/mocharc.node.js",
1717
],
1818
"env": {
19+
"TS_NODE_FILES":true,
1920
"TS_NODE_CACHE": "NO",
2021
"TS_NODE_COMPILER_OPTIONS" : "{\"module\":\"commonjs\"}"
2122
},
@@ -30,7 +31,7 @@
3031
"cwd": "${workspaceRoot}/packages/firestore",
3132
"args": [
3233
"--require", "babel-register.js",
33-
"--require", "index.node.ts",
34+
"--require", "src/index.node.ts",
3435
"--timeout", "5000",
3536
"test/{,!(browser|integration)/**/}*.test.ts",
3637
"--exit"

common/api-review/analytics.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ export function getAnalytics(app?: FirebaseApp): Analytics;
121121

122122
// @public
123123
export interface GtagConfigParams {
124-
'allow_google_signals?': boolean;
125124
// (undocumented)
126125
[key: string]: unknown;
127126
'allow_ad_personalization_signals'?: boolean;
127+
'allow_google_signals'?: boolean;
128128
'cookie_domain'?: string;
129129
'cookie_expires'?: number;
130130
'cookie_flags'?: string;

common/api-review/util.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ export interface Subscribe<T> {
422422
// @public (undocumented)
423423
export type Unsubscribe = () => void;
424424

425+
// @public
426+
export const uuidv4: () => string;
427+
425428
// Warning: (ae-missing-release-tag) "validateArgCount" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
426429
//
427430
// @public

packages/analytics/src/get-config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ async function attemptFetchDynamicConfigWithRetry(
188188
logger.warn(
189189
`Timed out fetching this Firebase app's measurement ID from the server.` +
190190
` Falling back to the measurement ID ${measurementId}` +
191-
` provided in the "measurementId" field in the local Firebase config. [${e.message}]`
191+
` provided in the "measurementId" field in the local Firebase config. [${
192+
(e as Error)?.message
193+
}]`
192194
);
193195
return { appId, measurementId };
194196
}
@@ -203,13 +205,14 @@ async function attemptFetchDynamicConfigWithRetry(
203205

204206
return response;
205207
} catch (e) {
206-
if (!isRetriableError(e)) {
208+
const error = e as Error;
209+
if (!isRetriableError(error)) {
207210
retryData.deleteThrottleMetadata(appId);
208211
if (measurementId) {
209212
logger.warn(
210213
`Failed to fetch this Firebase app's measurement ID from the server.` +
211214
` Falling back to the measurement ID ${measurementId}` +
212-
` provided in the "measurementId" field in the local Firebase config. [${e.message}]`
215+
` provided in the "measurementId" field in the local Firebase config. [${error?.message}]`
213216
);
214217
return { appId, measurementId };
215218
} else {
@@ -218,7 +221,7 @@ async function attemptFetchDynamicConfigWithRetry(
218221
}
219222

220223
const backoffMillis =
221-
Number(e.customData.httpStatus) === 503
224+
Number(error?.customData?.httpStatus) === 503
222225
? calculateBackoffMillis(
223226
backoffCount,
224227
retryData.intervalMillis,

packages/analytics/src/initialize-analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function validateIndexedDB(): Promise<boolean> {
4343
} catch (e) {
4444
logger.warn(
4545
ERROR_FACTORY.create(AnalyticsError.INDEXEDDB_UNAVAILABLE, {
46-
errorInfo: e
46+
errorInfo: (e as Error)?.toString()
4747
}).message
4848
);
4949
return false;

packages/analytics/src/public-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface GtagConfigParams {
7070
* If set to false, disables all advertising features with `gtag.js`.
7171
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features }
7272
*/
73-
'allow_google_signals?': boolean;
73+
'allow_google_signals'?: boolean;
7474
/**
7575
* If set to false, disables all advertising personalization with `gtag.js`.
7676
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features }

packages/app-check/src/storage.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { uuidv4 } from './util';
1918
import { FirebaseApp } from '@firebase/app';
20-
import { isIndexedDBAvailable } from '@firebase/util';
19+
import { isIndexedDBAvailable, uuidv4 } from '@firebase/util';
2120
import {
2221
readDebugTokenFromIndexedDB,
2322
readTokenFromIndexedDB,

packages/app-check/src/util.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ export function ensureActivated(app: FirebaseApp): void {
3737
}
3838
}
3939

40-
/**
41-
* Copied from https://stackoverflow.com/a/2117523
42-
*/
43-
export function uuidv4(): string {
44-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
45-
const r = (Math.random() * 16) | 0,
46-
v = c === 'x' ? r : (r & 0x3) | 0x8;
47-
return v.toString(16);
48-
});
49-
}
50-
5140
export function getDurationString(durationInMillis: number): string {
5241
const totalSeconds = Math.round(durationInMillis / 1000);
5342
const days = Math.floor(totalSeconds / (3600 * 24));

packages/auth-compat/src/user_credential.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function attachExtraErrorFields(auth: exp.Auth, e: FirebaseError): void {
3333
// actually match the underlying type
3434
const response = (e.customData as exp.TaggedWithTokenResponse | undefined)
3535
?._tokenResponse as unknown as Record<string, string>;
36-
if (e.code === 'auth/multi-factor-auth-required') {
36+
if ((e as FirebaseError)?.code === 'auth/multi-factor-auth-required') {
3737
const mfaErr = e as compat.MultiFactorError;
3838
mfaErr.resolver = new MultiFactorResolver(
3939
auth,

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
import {
3636
createSubscribe,
3737
ErrorFactory,
38+
FirebaseError,
3839
getModularInstance,
3940
Observer,
4041
Subscribe
@@ -301,7 +302,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
301302
try {
302303
await _reloadWithoutSaving(user);
303304
} catch (e) {
304-
if (e.code !== `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
305+
if ((e as FirebaseError)?.code !== `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
305306
// Something's wrong with the user's token. Log them out and remove
306307
// them from storage
307308
return this.directlySetCurrentUser(null);

packages/auth/src/core/user/id_token_result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function _parseToken(token: string): ParsedToken | null {
110110
}
111111
return JSON.parse(decoded);
112112
} catch (e) {
113-
_logError('Caught error parsing JWT payload as JSON', e);
113+
_logError('Caught error parsing JWT payload as JSON', (e as Error)?.toString());
114114
return null;
115115
}
116116
}

packages/auth/src/core/user/proactive_refresh.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { FirebaseError } from '@firebase/util';
1819
import { UserInternal } from '../../model/user';
1920
import { AuthErrorCode } from '../errors';
2021

@@ -92,7 +93,7 @@ export class ProactiveRefresh {
9293
await this.user.getIdToken(true);
9394
} catch (e) {
9495
// Only retry on network errors
95-
if (e.code === `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
96+
if ((e as FirebaseError)?.code === `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
9697
this.schedule(/* wasError */ true);
9798
}
9899

packages/auth/src/core/user/reauthenticate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { FirebaseError } from '@firebase/util';
1819
import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error';
1920
import { OperationType } from '../../model/enums';
2021
import { UserInternal } from '../../model/user';
@@ -54,7 +55,7 @@ export async function _reauthenticate(
5455
return UserCredentialImpl._forOperation(user, operationType, response);
5556
} catch (e) {
5657
// Convert user deleted error into user mismatch
57-
if (e?.code === `auth/${AuthErrorCode.USER_DELETED}`) {
58+
if ((e as FirebaseError)?.code === `auth/${AuthErrorCode.USER_DELETED}`) {
5859
_fail(auth, AuthErrorCode.USER_MISMATCH);
5960
}
6061
throw e;

packages/auth/src/mfa/mfa_user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { UserInternal } from '../model/user';
2929
import { MultiFactorAssertionImpl } from './mfa_assertion';
3030
import { MultiFactorInfoImpl } from './mfa_info';
3131
import { MultiFactorSessionImpl } from './mfa_session';
32-
import { getModularInstance } from '@firebase/util';
32+
import { FirebaseError, getModularInstance } from '@firebase/util';
3333

3434
export class MultiFactorUserImpl implements MultiFactorUser {
3535
enrolledFactors: MultiFactorInfo[] = [];
@@ -94,7 +94,7 @@ export class MultiFactorUserImpl implements MultiFactorUser {
9494
try {
9595
await this.user.reload();
9696
} catch (e) {
97-
if (e.code !== `auth/${AuthErrorCode.TOKEN_EXPIRED}`) {
97+
if ((e as FirebaseError)?.code !== `auth/${AuthErrorCode.TOKEN_EXPIRED}`) {
9898
throw e;
9999
}
100100
}

packages/auth/src/platform_browser/providers/phone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class PhoneAuthProvider {
179179
* auth.currentUser,
180180
* PhoneAuthProvider.credential(verificationId, code));
181181
* } catch (e) {
182-
* if (e.code === 'auth/account-exists-with-different-credential') {
182+
* if ((e as FirebaseError)?.code === 'auth/account-exists-with-different-credential') {
183183
* const cred = PhoneAuthProvider.credentialFromError(e);
184184
* await linkWithCredential(auth.currentUser, cred);
185185
* }

packages/database/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"@firebase/app": "0.7.26",
5757
"rollup": "2.72.1",
5858
"rollup-plugin-typescript2": "0.31.2",
59-
"typescript": "4.2.2"
59+
"typescript": "4.2.2",
60+
"uuid": "^8.3.2"
6061
},
6162
"repository": {
6263
"directory": "packages/database",

packages/database/src/core/PersistentConnection.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,6 @@ export class PersistentConnection extends ServerActions {
206206
onComplete: (message: { [k: string]: unknown }) => {
207207
const payload = message['d'] as string;
208208
if (message['s'] === 'ok') {
209-
this.onDataUpdate_(
210-
request['p'],
211-
payload,
212-
/*isMerge*/ false,
213-
/*tag*/ null
214-
);
215209
deferred.resolve(payload);
216210
} else {
217211
deferred.reject(payload);
@@ -265,7 +259,7 @@ export class PersistentConnection extends ServerActions {
265259
);
266260
assert(
267261
!this.listens.get(pathString)!.has(queryId),
268-
'listen() called twice for same path/queryId.'
262+
`listen() called twice for same path/queryId.`
269263
);
270264
const listenSpec: ListenSpec = {
271265
onComplete,

packages/database/src/core/Repo.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ import {
6060
syncTreeApplyUserOverwrite,
6161
syncTreeCalcCompleteEventCache,
6262
syncTreeGetServerValue,
63-
syncTreeRemoveEventRegistration
63+
syncTreeRemoveEventRegistration,
64+
syncTreeRegisterQuery
6465
} from './SyncTree';
6566
import { Indexable } from './util/misc';
6667
import {
@@ -466,16 +467,36 @@ export function repoGetValue(repo: Repo, query: QueryContext): Promise<Node> {
466467
}
467468
return repo.server_.get(query).then(
468469
payload => {
469-
const node = nodeFromJSON(payload as string).withIndex(
470+
const node = nodeFromJSON(payload).withIndex(
470471
query._queryParams.getIndex()
471472
);
472-
const events = syncTreeApplyServerOverwrite(
473+
// if this is a filtered query, then overwrite at path
474+
if (query._queryParams.loadsAllData()) {
475+
syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
476+
} else {
477+
// Simulate `syncTreeAddEventRegistration` without events/listener setup.
478+
// We do this (along with the syncTreeRemoveEventRegistration` below) so that
479+
// `repoGetValue` results have the same cache effects as initial listener(s)
480+
// updates.
481+
const tag = syncTreeRegisterQuery(repo.serverSyncTree_, query);
482+
syncTreeApplyTaggedQueryOverwrite(
483+
repo.serverSyncTree_,
484+
query._path,
485+
node,
486+
tag
487+
);
488+
// Call `syncTreeRemoveEventRegistration` with a null event registration, since there is none.
489+
// Note: The below code essentially unregisters the query and cleans up any views/syncpoints temporarily created above.
490+
}
491+
const cancels = syncTreeRemoveEventRegistration(
473492
repo.serverSyncTree_,
474-
query._path,
475-
node
493+
query,
494+
null
476495
);
477-
eventQueueRaiseEventsAtPath(repo.eventQueue_, query._path, events);
478-
return Promise.resolve(node);
496+
if (cancels.length > 0) {
497+
repoLog(repo, 'unexpected cancel events in repoGetValue');
498+
}
499+
return node;
479500
},
480501
err => {
481502
repoLog(repo, 'get for query ' + stringify(query) + ' failed: ' + err);

0 commit comments

Comments
 (0)