Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fcm): Add HTTP2 support for sendEach() and sendEachForMulticast() #2550

Merged
merged 11 commits into from
Jul 23, 2024
2 changes: 2 additions & 0 deletions etc/firebase-admin.messaging.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export type Message = TokenMessage | TopicMessage | ConditionMessage;
// @public
export class Messaging {
get app(): App;
// @deprecated
enableLegacyHttpTransport(): void;
send(message: Message, dryRun?: boolean): Promise<string>;
// @deprecated
sendAll(messages: Message[], dryRun?: boolean): Promise<BatchResponse>;
Expand Down
6 changes: 3 additions & 3 deletions src/app-check/app-check-api-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { App } from '../app';
import { FirebaseApp } from '../app/firebase-app';
import {
HttpRequestConfig, HttpClient, HttpError, AuthorizedHttpClient, HttpResponse
HttpRequestConfig, HttpClient, RequestResponseError, AuthorizedHttpClient, RequestResponse
} from '../utils/api-request';
import { PrefixedFirebaseError } from '../utils/error';
import * as utils from '../utils/index';
Expand Down Expand Up @@ -157,7 +157,7 @@ export class AppCheckApiClient {
});
}

private toFirebaseError(err: HttpError): PrefixedFirebaseError {
private toFirebaseError(err: RequestResponseError): PrefixedFirebaseError {
if (err instanceof PrefixedFirebaseError) {
return err;
}
Expand All @@ -184,7 +184,7 @@ export class AppCheckApiClient {
* @param resp - API response object.
* @returns An AppCheckToken instance.
*/
private toAppCheckToken(resp: HttpResponse): AppCheckToken {
private toAppCheckToken(resp: RequestResponse): AppCheckToken {
const token = resp.data.token;
// `ttl` is a string with the suffix "s" preceded by the number of seconds,
// with nanoseconds expressed as fractional seconds.
Expand Down
4 changes: 2 additions & 2 deletions src/app-check/token-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
APP_CHECK_ERROR_CODE_MAPPING,
} from './app-check-api-client-internal';
import { AppCheckTokenOptions } from './app-check-api';
import { HttpError } from '../utils/api-request';
import { RequestResponseError } from '../utils/api-request';

const ONE_MINUTE_IN_SECONDS = 60;
const ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000;
Expand Down Expand Up @@ -147,7 +147,7 @@ export function appCheckErrorFromCryptoSignerError(err: Error): Error {
return err;
}
if (err.code === CryptoSignerErrorCode.SERVER_ERROR && validator.isNonNullObject(err.cause)) {
const httpError = err.cause as HttpError
const httpError = err.cause as RequestResponseError
const errorResponse = httpError.response.data;
if (errorResponse?.error) {
const status = errorResponse.error.status;
Expand Down
12 changes: 7 additions & 5 deletions src/app/credential-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import path = require('path');
import { Agent } from 'http';
import { Credential, GoogleOAuthAccessToken } from './credential';
import { AppErrorCodes, FirebaseAppError } from '../utils/error';
import { HttpClient, HttpRequestConfig, HttpError, HttpResponse } from '../utils/api-request';
import { HttpClient, HttpRequestConfig, RequestResponseError, RequestResponse } from '../utils/api-request';
import * as util from '../utils/validator';

const GOOGLE_TOKEN_AUDIENCE = 'https://accounts.google.com/o/oauth2/token';
Expand Down Expand Up @@ -232,7 +232,8 @@ export class ComputeEngineCredential implements Credential {
return this.projectId;
})
.catch((err) => {
const detail: string = (err instanceof HttpError) ? getDetailFromResponse(err.response) : err.message;
const detail: string =
(err instanceof RequestResponseError) ? getDetailFromResponse(err.response) : err.message;
throw new FirebaseAppError(
AppErrorCodes.INVALID_CREDENTIAL,
`Failed to determine project ID: ${detail}`);
Expand All @@ -251,7 +252,8 @@ export class ComputeEngineCredential implements Credential {
return this.accountId;
})
.catch((err) => {
const detail: string = (err instanceof HttpError) ? getDetailFromResponse(err.response) : err.message;
const detail: string =
(err instanceof RequestResponseError) ? getDetailFromResponse(err.response) : err.message;
throw new FirebaseAppError(
AppErrorCodes.INVALID_CREDENTIAL,
`Failed to determine service account email: ${detail}`);
Expand Down Expand Up @@ -553,7 +555,7 @@ function requestIDToken(client: HttpClient, request: HttpRequestConfig): Promise
* Constructs a human-readable error message from the given Error.
*/
function getErrorMessage(err: Error): string {
const detail: string = (err instanceof HttpError) ? getDetailFromResponse(err.response) : err.message;
const detail: string = (err instanceof RequestResponseError) ? getDetailFromResponse(err.response) : err.message;
return `Error fetching access token: ${detail}`;
}

Expand All @@ -562,7 +564,7 @@ function getErrorMessage(err: Error): string {
* the response is JSON-formatted, looks up the error and error_description fields sent by the
* Google Auth servers. Otherwise returns the entire response payload as the error detail.
*/
function getDetailFromResponse(response: HttpResponse): string {
function getDetailFromResponse(response: RequestResponse): string {
if (response.isJson() && response.data.error) {
const json = response.data;
let detail = json.error;
Expand Down
4 changes: 2 additions & 2 deletions src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { FirebaseApp } from '../app/firebase-app';
import { deepCopy, deepExtend } from '../utils/deep-copy';
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
import {
ApiSettings, AuthorizedHttpClient, HttpRequestConfig, HttpError,
ApiSettings, AuthorizedHttpClient, HttpRequestConfig, RequestResponseError,
} from '../utils/api-request';
import * as utils from '../utils/index';

Expand Down Expand Up @@ -1933,7 +1933,7 @@ export abstract class AbstractAuthRequestHandler {
return response.data;
})
.catch((err) => {
if (err instanceof HttpError) {
if (err instanceof RequestResponseError) {
const error = err.response.data;
const errorCode = AbstractAuthRequestHandler.getErrorCode(error);
if (!errorCode) {
Expand Down
4 changes: 2 additions & 2 deletions src/auth/token-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { AuthClientErrorCode, ErrorInfo, FirebaseAuthError } from '../utils/error';
import { HttpError } from '../utils/api-request';
import { RequestResponseError } from '../utils/api-request';
import { CryptoSigner, CryptoSignerError, CryptoSignerErrorCode } from '../utils/crypto-signer';

import * as validator from '../utils/validator';
Expand Down Expand Up @@ -213,7 +213,7 @@ export function handleCryptoSignerError(err: Error): Error {
}
if (err.code === CryptoSignerErrorCode.SERVER_ERROR && validator.isNonNullObject(err.cause)) {
const httpError = err.cause;
const errorResponse = (httpError as HttpError).response.data;
const errorResponse = (httpError as RequestResponseError).response.data;
if (validator.isNonNullObject(errorResponse) && errorResponse.error) {
const errorCode = errorResponse.error.status;
const description = 'Please refer to https://firebase.google.com/docs/auth/admin/create-custom-tokens ' +
Expand Down
6 changes: 3 additions & 3 deletions src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Database as DatabaseImpl } from '@firebase/database-compat/standalone';
import { App } from '../app';
import { FirebaseApp } from '../app/firebase-app';
import * as validator from '../utils/validator';
import { AuthorizedHttpClient, HttpRequestConfig, HttpError } from '../utils/api-request';
import { AuthorizedHttpClient, HttpRequestConfig, RequestResponseError } from '../utils/api-request';
import { getSdkVersion } from '../utils/index';

/**
Expand Down Expand Up @@ -292,7 +292,7 @@ class DatabaseRulesClient {
}

private handleError(err: Error): Error {
if (err instanceof HttpError) {
if (err instanceof RequestResponseError) {
return new FirebaseDatabaseError({
code: AppErrorCodes.INTERNAL_ERROR,
message: this.getErrorMessage(err),
Expand All @@ -301,7 +301,7 @@ class DatabaseRulesClient {
return err;
}

private getErrorMessage(err: HttpError): string {
private getErrorMessage(err: RequestResponseError): string {
const intro = 'Error while accessing security rules';
try {
const body: { error?: string } = err.response.data;
Expand Down
4 changes: 2 additions & 2 deletions src/eventarc/eventarc-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { FirebaseEventarcError, toCloudEventProtoFormat } from './eventarc-utils
import { App } from '../app';
import { Channel } from './eventarc';
import {
HttpRequestConfig, HttpClient, HttpError, AuthorizedHttpClient
HttpRequestConfig, HttpClient, RequestResponseError, AuthorizedHttpClient
} from '../utils/api-request';
import { FirebaseApp } from '../app/firebase-app';
import * as utils from '../utils';
Expand Down Expand Up @@ -117,7 +117,7 @@ export class EventarcApiClient {
});
}

private toFirebaseError(err: HttpError): PrefixedFirebaseError {
private toFirebaseError(err: RequestResponseError): PrefixedFirebaseError {
if (err instanceof PrefixedFirebaseError) {
return err;
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/extensions-api-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { App } from '../app';
import { FirebaseApp } from '../app/firebase-app';
import { AuthorizedHttpClient, HttpClient, HttpError, HttpRequestConfig } from '../utils/api-request';
import { AuthorizedHttpClient, HttpClient, RequestResponseError, HttpRequestConfig } from '../utils/api-request';
import { FirebaseAppError, PrefixedFirebaseError } from '../utils/error';
import * as validator from '../utils/validator';
import * as utils from '../utils';
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ExtensionsApiClient {
}/${EXTENSIONS_API_VERSION}/projects/${projectId}/instances/${instanceId}/runtimeData`;
}

private toFirebaseError(err: HttpError): PrefixedFirebaseError {
private toFirebaseError(err: RequestResponseError): PrefixedFirebaseError {
if (err instanceof PrefixedFirebaseError) {
return err;
}
Expand Down
8 changes: 4 additions & 4 deletions src/functions/functions-api-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { App } from '../app';
import { FirebaseApp } from '../app/firebase-app';
import {
HttpRequestConfig, HttpClient, HttpError, AuthorizedHttpClient
HttpRequestConfig, HttpClient, RequestResponseError, AuthorizedHttpClient
} from '../utils/api-request';
import { PrefixedFirebaseError } from '../utils/error';
import * as utils from '../utils/index';
Expand Down Expand Up @@ -99,7 +99,7 @@ export class FunctionsApiClient {
};
await this.httpClient.send(request);
} catch (err: unknown) {
if (err instanceof HttpError) {
if (err instanceof RequestResponseError) {
if (err.response.status === 404) {
// if no task with the provided ID exists, then ignore the delete.
return;
Expand Down Expand Up @@ -156,7 +156,7 @@ export class FunctionsApiClient {
};
await this.httpClient.send(request);
} catch (err: unknown) {
if (err instanceof HttpError) {
if (err instanceof RequestResponseError) {
if (err.response.status === 409) {
throw new FirebaseFunctionsError('task-already-exists', `A task with ID ${opts?.id} already exists`);
} else {
Expand Down Expand Up @@ -321,7 +321,7 @@ export class FunctionsApiClient {
return task;
}

private toFirebaseError(err: HttpError): PrefixedFirebaseError {
private toFirebaseError(err: RequestResponseError): PrefixedFirebaseError {
if (err instanceof PrefixedFirebaseError) {
return err;
}
Expand Down
4 changes: 2 additions & 2 deletions src/installations/installations-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { App } from '../app/index';
import { FirebaseApp } from '../app/firebase-app';
import { FirebaseInstallationsError, InstallationsClientErrorCode } from '../utils/error';
import {
ApiSettings, AuthorizedHttpClient, HttpRequestConfig, HttpError,
ApiSettings, AuthorizedHttpClient, HttpRequestConfig, RequestResponseError,
} from '../utils/api-request';

import * as utils from '../utils/index';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class FirebaseInstallationsRequestHandler {
// return nothing on success
})
.catch((err) => {
if (err instanceof HttpError) {
if (err instanceof RequestResponseError) {
const response = err.response;
const errorMessage: string = (response.isJson() && 'error' in response.data) ?
response.data.error : response.text;
Expand Down
4 changes: 2 additions & 2 deletions src/machine-learning/machine-learning-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { App } from '../app';
import { FirebaseApp } from '../app/firebase-app';
import {
HttpRequestConfig, HttpClient, HttpError, AuthorizedHttpClient, ExponentialBackoffPoller
HttpRequestConfig, HttpClient, RequestResponseError, AuthorizedHttpClient, ExponentialBackoffPoller
} from '../utils/api-request';
import { PrefixedFirebaseError } from '../utils/error';
import * as utils from '../utils/index';
Expand Down Expand Up @@ -369,7 +369,7 @@ export class MachineLearningApiClient {
});
}

private toFirebaseError(err: HttpError): PrefixedFirebaseError {
private toFirebaseError(err: RequestResponseError): PrefixedFirebaseError {
if (err instanceof PrefixedFirebaseError) {
return err;
}
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/batch-request-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {
HttpClient, HttpRequestConfig, HttpResponse, parseHttpResponse,
HttpClient, HttpRequestConfig, RequestResponse, parseHttpResponse,
} from '../utils/api-request';
import { FirebaseAppError, AppErrorCodes } from '../utils/error';

Expand Down Expand Up @@ -59,7 +59,7 @@ export class BatchRequestClient {
* @param requests - An array of sub requests to send.
* @returns A promise that resolves when the send operation is complete.
*/
public send(requests: SubRequest[]): Promise<HttpResponse[]> {
public send(requests: SubRequest[]): Promise<RequestResponse[]> {
requests = requests.map((req) => {
req.headers = Object.assign({}, this.commonHeaders, req.headers);
return req;
Expand Down
Loading
Loading