Skip to content

Commit

Permalink
Merge master into release
Browse files Browse the repository at this point in the history
  • Loading branch information
google-oss-bot committed Jun 21, 2022
2 parents 56aad27 + d87d3a8 commit 33e1848
Show file tree
Hide file tree
Showing 61 changed files with 461 additions and 147 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-starfishes-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/rules-unit-testing': patch
---

Add Node ESM build to rules-unit-testing.
5 changes: 5 additions & 0 deletions .changeset/rotten-tables-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/database": patch
---

Fixed issue where `get()` saved results incorrectly for non-default queries.
5 changes: 5 additions & 0 deletions .changeset/sharp-rules-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/analytics': patch
---

Fix typo in GtagConfigParams
7 changes: 7 additions & 0 deletions .changeset/tame-rice-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@firebase/app-check": patch
"@firebase/database": patch
"@firebase/util": patch
---

Extract uuid function into @firebase/util
2 changes: 2 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
env:
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
RELEASE_TRACKER_URL: ${{ secrets.RELEASE_TRACKER_URL }}
VERSION_OR_TAG: ${{ github.event.client_payload.versionOrTag }}
# run in root
working-directory: '.'
- name: Tests failed
Expand All @@ -69,5 +70,6 @@ jobs:
env:
WEBHOOK_URL: ${{ secrets.JSCORE_CHAT_WEBHOOK_URL }}
RELEASE_TRACKER_URL: ${{ secrets.RELEASE_TRACKER_URL }}
VERSION_OR_TAG: ${{ github.event.client_payload.versionOrTag }}
# run in root
working-directory: '.'
9 changes: 5 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"type": "node",
"request": "launch",
"name": "RTDB Unit Tests (Node)",
"program": "${workspaceRoot}/packages/firebase/node_modules/.bin/_mocha",
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}/packages/database",
"args": [
"test/{,!(browser)/**/}*.test.ts",
"--file", "index.node.ts",
"--config", "../../config/mocharc.node.js"
"--file", "src/index.node.ts",
"--config", "../../config/mocharc.node.js",
],
"env": {
"TS_NODE_FILES":true,
"TS_NODE_CACHE": "NO",
"TS_NODE_COMPILER_OPTIONS" : "{\"module\":\"commonjs\"}"
},
Expand All @@ -30,7 +31,7 @@
"cwd": "${workspaceRoot}/packages/firestore",
"args": [
"--require", "babel-register.js",
"--require", "index.node.ts",
"--require", "src/index.node.ts",
"--timeout", "5000",
"test/{,!(browser|integration)/**/}*.test.ts",
"--exit"
Expand Down
2 changes: 1 addition & 1 deletion common/api-review/analytics.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export function getAnalytics(app?: FirebaseApp): Analytics;

// @public
export interface GtagConfigParams {
'allow_google_signals?': boolean;
// (undocumented)
[key: string]: unknown;
'allow_ad_personalization_signals'?: boolean;
'allow_google_signals'?: boolean;
'cookie_domain'?: string;
'cookie_expires'?: number;
'cookie_flags'?: string;
Expand Down
3 changes: 3 additions & 0 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ export interface Subscribe<T> {
// @public (undocumented)
export type Unsubscribe = () => void;

// @public
export const uuidv4: () => string;

// Warning: (ae-missing-release-tag) "validateArgCount" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down
11 changes: 7 additions & 4 deletions packages/analytics/src/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ async function attemptFetchDynamicConfigWithRetry(
logger.warn(
`Timed out fetching this Firebase app's measurement ID from the server.` +
` Falling back to the measurement ID ${measurementId}` +
` provided in the "measurementId" field in the local Firebase config. [${e.message}]`
` provided in the "measurementId" field in the local Firebase config. [${
(e as Error)?.message
}]`
);
return { appId, measurementId };
}
Expand All @@ -203,13 +205,14 @@ async function attemptFetchDynamicConfigWithRetry(

return response;
} catch (e) {
if (!isRetriableError(e)) {
const error = e as Error;
if (!isRetriableError(error)) {
retryData.deleteThrottleMetadata(appId);
if (measurementId) {
logger.warn(
`Failed to fetch this Firebase app's measurement ID from the server.` +
` Falling back to the measurement ID ${measurementId}` +
` provided in the "measurementId" field in the local Firebase config. [${e.message}]`
` provided in the "measurementId" field in the local Firebase config. [${error?.message}]`
);
return { appId, measurementId };
} else {
Expand All @@ -218,7 +221,7 @@ async function attemptFetchDynamicConfigWithRetry(
}

const backoffMillis =
Number(e.customData.httpStatus) === 503
Number(error?.customData?.httpStatus) === 503
? calculateBackoffMillis(
backoffCount,
retryData.intervalMillis,
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/src/initialize-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function validateIndexedDB(): Promise<boolean> {
} catch (e) {
logger.warn(
ERROR_FACTORY.create(AnalyticsError.INDEXEDDB_UNAVAILABLE, {
errorInfo: e
errorInfo: (e as Error)?.toString()
}).message
);
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface GtagConfigParams {
* If set to false, disables all advertising features with `gtag.js`.
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features }
*/
'allow_google_signals?': boolean;
'allow_google_signals'?: boolean;
/**
* If set to false, disables all advertising personalization with `gtag.js`.
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features }
Expand Down
3 changes: 1 addition & 2 deletions packages/app-check/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* limitations under the License.
*/

import { uuidv4 } from './util';
import { FirebaseApp } from '@firebase/app';
import { isIndexedDBAvailable } from '@firebase/util';
import { isIndexedDBAvailable, uuidv4 } from '@firebase/util';
import {
readDebugTokenFromIndexedDB,
readTokenFromIndexedDB,
Expand Down
11 changes: 0 additions & 11 deletions packages/app-check/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ export function ensureActivated(app: FirebaseApp): void {
}
}

/**
* Copied from https://stackoverflow.com/a/2117523
*/
export function uuidv4(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0,
v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

export function getDurationString(durationInMillis: number): string {
const totalSeconds = Math.round(durationInMillis / 1000);
const days = Math.floor(totalSeconds / (3600 * 24));
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-compat/src/user_credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function attachExtraErrorFields(auth: exp.Auth, e: FirebaseError): void {
// actually match the underlying type
const response = (e.customData as exp.TaggedWithTokenResponse | undefined)
?._tokenResponse as unknown as Record<string, string>;
if (e.code === 'auth/multi-factor-auth-required') {
if ((e as FirebaseError)?.code === 'auth/multi-factor-auth-required') {
const mfaErr = e as compat.MultiFactorError;
mfaErr.resolver = new MultiFactorResolver(
auth,
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import {
createSubscribe,
ErrorFactory,
FirebaseError,
getModularInstance,
Observer,
Subscribe
Expand Down Expand Up @@ -301,7 +302,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
try {
await _reloadWithoutSaving(user);
} catch (e) {
if (e.code !== `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
if ((e as FirebaseError)?.code !== `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
// Something's wrong with the user's token. Log them out and remove
// them from storage
return this.directlySetCurrentUser(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/core/user/id_token_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function _parseToken(token: string): ParsedToken | null {
}
return JSON.parse(decoded);
} catch (e) {
_logError('Caught error parsing JWT payload as JSON', e);
_logError('Caught error parsing JWT payload as JSON', (e as Error)?.toString());
return null;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/core/user/proactive_refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import { FirebaseError } from '@firebase/util';
import { UserInternal } from '../../model/user';
import { AuthErrorCode } from '../errors';

Expand Down Expand Up @@ -92,7 +93,7 @@ export class ProactiveRefresh {
await this.user.getIdToken(true);
} catch (e) {
// Only retry on network errors
if (e.code === `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
if ((e as FirebaseError)?.code === `auth/${AuthErrorCode.NETWORK_REQUEST_FAILED}`) {
this.schedule(/* wasError */ true);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/core/user/reauthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import { FirebaseError } from '@firebase/util';
import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error';
import { OperationType } from '../../model/enums';
import { UserInternal } from '../../model/user';
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function _reauthenticate(
return UserCredentialImpl._forOperation(user, operationType, response);
} catch (e) {
// Convert user deleted error into user mismatch
if (e?.code === `auth/${AuthErrorCode.USER_DELETED}`) {
if ((e as FirebaseError)?.code === `auth/${AuthErrorCode.USER_DELETED}`) {
_fail(auth, AuthErrorCode.USER_MISMATCH);
}
throw e;
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/mfa/mfa_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { UserInternal } from '../model/user';
import { MultiFactorAssertionImpl } from './mfa_assertion';
import { MultiFactorInfoImpl } from './mfa_info';
import { MultiFactorSessionImpl } from './mfa_session';
import { getModularInstance } from '@firebase/util';
import { FirebaseError, getModularInstance } from '@firebase/util';

export class MultiFactorUserImpl implements MultiFactorUser {
enrolledFactors: MultiFactorInfo[] = [];
Expand Down Expand Up @@ -94,7 +94,7 @@ export class MultiFactorUserImpl implements MultiFactorUser {
try {
await this.user.reload();
} catch (e) {
if (e.code !== `auth/${AuthErrorCode.TOKEN_EXPIRED}`) {
if ((e as FirebaseError)?.code !== `auth/${AuthErrorCode.TOKEN_EXPIRED}`) {
throw e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/platform_browser/providers/phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class PhoneAuthProvider {
* auth.currentUser,
* PhoneAuthProvider.credential(verificationId, code));
* } catch (e) {
* if (e.code === 'auth/account-exists-with-different-credential') {
* if ((e as FirebaseError)?.code === 'auth/account-exists-with-different-credential') {
* const cred = PhoneAuthProvider.credentialFromError(e);
* await linkWithCredential(auth.currentUser, cred);
* }
Expand Down
3 changes: 2 additions & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"@firebase/app": "0.7.26",
"rollup": "2.72.1",
"rollup-plugin-typescript2": "0.31.2",
"typescript": "4.2.2"
"typescript": "4.2.2",
"uuid": "^8.3.2"
},
"repository": {
"directory": "packages/database",
Expand Down
8 changes: 1 addition & 7 deletions packages/database/src/core/PersistentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ export class PersistentConnection extends ServerActions {
onComplete: (message: { [k: string]: unknown }) => {
const payload = message['d'] as string;
if (message['s'] === 'ok') {
this.onDataUpdate_(
request['p'],
payload,
/*isMerge*/ false,
/*tag*/ null
);
deferred.resolve(payload);
} else {
deferred.reject(payload);
Expand Down Expand Up @@ -265,7 +259,7 @@ export class PersistentConnection extends ServerActions {
);
assert(
!this.listens.get(pathString)!.has(queryId),
'listen() called twice for same path/queryId.'
`listen() called twice for same path/queryId.`
);
const listenSpec: ListenSpec = {
onComplete,
Expand Down
35 changes: 28 additions & 7 deletions packages/database/src/core/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import {
syncTreeApplyUserOverwrite,
syncTreeCalcCompleteEventCache,
syncTreeGetServerValue,
syncTreeRemoveEventRegistration
syncTreeRemoveEventRegistration,
syncTreeRegisterQuery
} from './SyncTree';
import { Indexable } from './util/misc';
import {
Expand Down Expand Up @@ -466,16 +467,36 @@ export function repoGetValue(repo: Repo, query: QueryContext): Promise<Node> {
}
return repo.server_.get(query).then(
payload => {
const node = nodeFromJSON(payload as string).withIndex(
const node = nodeFromJSON(payload).withIndex(
query._queryParams.getIndex()
);
const events = syncTreeApplyServerOverwrite(
// if this is a filtered query, then overwrite at path
if (query._queryParams.loadsAllData()) {
syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
} else {
// Simulate `syncTreeAddEventRegistration` without events/listener setup.
// We do this (along with the syncTreeRemoveEventRegistration` below) so that
// `repoGetValue` results have the same cache effects as initial listener(s)
// updates.
const tag = syncTreeRegisterQuery(repo.serverSyncTree_, query);
syncTreeApplyTaggedQueryOverwrite(
repo.serverSyncTree_,
query._path,
node,
tag
);
// Call `syncTreeRemoveEventRegistration` with a null event registration, since there is none.
// Note: The below code essentially unregisters the query and cleans up any views/syncpoints temporarily created above.
}
const cancels = syncTreeRemoveEventRegistration(
repo.serverSyncTree_,
query._path,
node
query,
null
);
eventQueueRaiseEventsAtPath(repo.eventQueue_, query._path, events);
return Promise.resolve(node);
if (cancels.length > 0) {
repoLog(repo, 'unexpected cancel events in repoGetValue');
}
return node;
},
err => {
repoLog(repo, 'get for query ' + stringify(query) + ' failed: ' + err);
Expand Down
Loading

0 comments on commit 33e1848

Please sign in to comment.