initial commit

This commit is contained in:
2025-09-01 22:12:29 +02:00
parent b1873f9c1d
commit 02a54f61c0
5598 changed files with 903558 additions and 0 deletions

View File

@@ -0,0 +1,324 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseApp } from '../app/firebase-app';
import http = require('http');
import http2 = require('http2');
import { EventEmitter } from 'events';
/** Http method type definition. */
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';
/** API callback function type definition. */
export type ApiCallbackFunction = (data: object) => void;
/**
* Base configuration for constructing a new request.
*/
export interface BaseRequestConfig {
method: HttpMethod;
/** Target URL of the request. Should be a well-formed URL including protocol, hostname, port and path. */
url: string;
headers?: {
[key: string]: string;
};
data?: string | object | Buffer | null;
/** Connect and read timeout (in milliseconds) for the outgoing request. */
timeout?: number;
}
/**
* Configuration for constructing a new HTTP request.
*/
export interface HttpRequestConfig extends BaseRequestConfig {
httpAgent?: http.Agent;
}
/**
* Configuration for constructing a new HTTP/2 request.
*/
export interface Http2RequestConfig extends BaseRequestConfig {
http2SessionHandler: Http2SessionHandler;
}
type RequestConfig = HttpRequestConfig | Http2RequestConfig;
/**
* Represents an HTTP or HTTP/2 response received from a remote server.
*/
export interface RequestResponse {
readonly status: number;
readonly headers: any;
/** Response data as a raw string. */
readonly text?: string;
/** Response data as a parsed JSON object. */
readonly data?: any;
/** For multipart responses, the payloads of individual parts. */
readonly multipart?: Buffer[];
/**
* Indicates if the response content is JSON-formatted or not. If true, data field can be used
* to retrieve the content as a parsed JSON object.
*/
isJson(): boolean;
}
interface BaseLowLevelResponse {
status: number;
data?: string;
multipart?: Buffer[];
}
interface LowLevelHttpResponse extends BaseLowLevelResponse {
headers: http.IncomingHttpHeaders;
request: http.ClientRequest | null;
config: HttpRequestConfig;
}
type IncomingHttp2Headers = http2.IncomingHttpHeaders & http2.IncomingHttpStatusHeader;
interface LowLevelHttp2Response extends BaseLowLevelResponse {
headers: IncomingHttp2Headers;
request: http2.ClientHttp2Stream | null;
config: Http2RequestConfig;
}
type LowLevelResponse = LowLevelHttpResponse | LowLevelHttp2Response;
interface BaseLowLevelError extends Error {
code?: string;
}
interface LowLevelHttpError extends BaseLowLevelError {
config: HttpRequestConfig;
request?: http.ClientRequest;
response?: LowLevelHttpResponse;
}
interface LowLevelHttp2Error extends BaseLowLevelError {
config: Http2RequestConfig;
request?: http2.ClientHttp2Stream;
response?: LowLevelHttp2Response;
}
type LowLevelError = LowLevelHttpError | LowLevelHttp2Error;
export declare class RequestResponseError extends Error {
readonly response: RequestResponse;
constructor(response: RequestResponse);
}
/**
* Specifies how failing HTTP and HTTP/2 requests should be retried.
*/
export interface RetryConfig {
/** Maximum number of times to retry a given request. */
maxRetries: number;
/** Response status codes that should be retried. */
statusCodes?: number[];
/** Low-level I/O error codes that should be retried. */
ioErrorCodes?: string[];
/**
* The multiplier for exponential back off. The retry delay is calculated in seconds using the formula
* `(2^n) * backOffFactor`, where n is the number of retries performed so far. When the `backOffFactor` is set
* to 0, retries are not delayed. When the `backOffFactor` is 1, retry duration is doubled each iteration.
*/
backOffFactor?: number;
/** Maximum duration to wait before initiating a retry. */
maxDelayInMillis: number;
}
/**
* Default retry configuration for HTTP and HTTP/2 requests. Retries up to 4 times on connection reset and timeout
* errors as well as 503 errors. Exposed as a function to ensure that every `RequestClient` gets its own `RetryConfig`
* instance.
*/
export declare function defaultRetryConfig(): RetryConfig;
export declare class RequestClient {
protected readonly retry: RetryConfig;
constructor(retry?: RetryConfig | null);
protected createRequestResponse(resp: LowLevelResponse): RequestResponse;
protected waitForRetry(delayMillis: number): Promise<void>;
/**
* Checks if a failed request is eligible for a retry, and if so returns the duration to wait before initiating
* the retry.
*
* @param retryAttempts - Number of retries completed up to now.
* @param err - The last encountered error.
* @returns A 2-tuple where the 1st element is the duration to wait before another retry, and the
* 2nd element is a boolean indicating whether the request is eligible for a retry or not.
*/
protected getRetryDelayMillis(retryAttempts: number, err: LowLevelError): [number, boolean];
protected isRetryEligible(retryAttempts: number, err: LowLevelError): boolean;
/**???
* Parses the Retry-After header as a milliseconds value. Return value is negative if the Retry-After header
* contains an expired timestamp or otherwise malformed.
*/
protected parseRetryAfterIntoMillis(retryAfter: string): number;
protected backOffDelayMillis(retryAttempts: number): number;
}
export declare class HttpClient extends RequestClient {
constructor(retry?: RetryConfig | null);
/**
* Sends an HTTP request to a remote server. If the server responds with a successful response (2xx), the returned
* promise resolves with an `RequestResponse`. If the server responds with an error (3xx, 4xx, 5xx), the promise
* rejects with an `RequestResponseError`. In case of all other errors, the promise rejects with a `FirebaseAppError`.
* If a request fails due to a low-level network error, the client transparently retries the request once before
* rejecting the promise.
*
* If the request data is specified as an object, it will be serialized into a JSON string. The application/json
* content-type header will also be automatically set in this case. For all other payload types, the content-type
* header should be explicitly set by the caller. To send a JSON leaf value (e.g. "foo", 5), parse it into JSON,
* and pass as a string or a Buffer along with the appropriate content-type header.
*
* @param config - HTTP request to be sent.
* @returns A promise that resolves with the response details.
*/
send(config: HttpRequestConfig): Promise<RequestResponse>;
/**
* Sends an HTTP request. In the event of an error, retries the HTTP request according to the
* `RetryConfig` set on the `HttpClient`.
*
* @param config - HTTP request to be sent.
* @param retryAttempts - Number of retries performed up to now.
* @returns A promise that resolves with the response details.
*/
private sendWithRetry;
}
export declare class Http2Client extends RequestClient {
constructor(retry?: RetryConfig | null);
/**
* Sends an HTTP/2 request to a remote server. If the server responds with a successful response (2xx), the returned
* promise resolves with an `RequestResponse`. If the server responds with an error (3xx, 4xx, 5xx), the promise
* rejects with an `RequestResponseError`. In case of all other errors, the promise rejects with a `FirebaseAppError`.
* If a request fails due to a low-level network error, the client transparently retries the request once before
* rejecting the promise.
*
* If the request data is specified as an object, it will be serialized into a JSON string. The application/json
* content-type header will also be automatically set in this case. For all other payload types, the content-type
* header should be explicitly set by the caller. To send a JSON leaf value (e.g. "foo", 5), parse it into JSON,
* and pass as a string or a Buffer along with the appropriate content-type header.
*
* @param config - HTTP/2 request to be sent.
* @returns A promise that resolves with the response details.
*/
send(config: Http2RequestConfig): Promise<RequestResponse>;
/**
* Sends an HTTP/2 request. In the event of an error, retries the HTTP/2 request according to the
* `RetryConfig` set on the `Http2Client`.
*
* @param config - HTTP/2 request to be sent.
* @param retryAttempts - Number of retries performed up to now.
* @returns A promise that resolves with the response details.
*/
private sendWithRetry;
}
/**
* Parses a full HTTP or HTTP/2 response message containing both a header and a body.
*
* @param response - The HTTP or HTTP/2 response to be parsed.
* @param config - The request configuration that resulted in the HTTP or HTTP/2 response.
* @returns An object containing the response's parsed status, headers and the body.
*/
export declare function parseHttpResponse(response: string | Buffer, config: RequestConfig): RequestResponse;
export declare class AuthorizedHttpClient extends HttpClient {
private readonly app;
constructor(app: FirebaseApp);
send(request: HttpRequestConfig): Promise<RequestResponse>;
protected getToken(): Promise<string>;
}
export declare class AuthorizedHttp2Client extends Http2Client {
private readonly app;
constructor(app: FirebaseApp);
send(request: Http2RequestConfig): Promise<RequestResponse>;
protected getToken(): Promise<string>;
}
/**
* Class that defines all the settings for the backend API endpoint.
*
* @param endpoint - The Firebase Auth backend endpoint.
* @param httpMethod - The HTTP method for that endpoint.
* @constructor
*/
export declare class ApiSettings {
private endpoint;
private httpMethod;
private requestValidator;
private responseValidator;
constructor(endpoint: string, httpMethod?: HttpMethod);
/** @returns The backend API endpoint. */
getEndpoint(): string;
/** @returns The request HTTP method. */
getHttpMethod(): HttpMethod;
/**
* @param requestValidator - The request validator.
* @returns The current API settings instance.
*/
setRequestValidator(requestValidator: ApiCallbackFunction | null): ApiSettings;
/** @returns The request validator. */
getRequestValidator(): ApiCallbackFunction;
/**
* @param responseValidator - The response validator.
* @returns The current API settings instance.
*/
setResponseValidator(responseValidator: ApiCallbackFunction | null): ApiSettings;
/** @returns The response validator. */
getResponseValidator(): ApiCallbackFunction;
}
/**
* Class used for polling an endpoint with exponential backoff.
*
* Example usage:
* ```
* const poller = new ExponentialBackoffPoller();
* poller
* .poll(() => {
* return myRequestToPoll()
* .then((responseData: any) => {
* if (!isValid(responseData)) {
* // Continue polling.
* return null;
* }
*
* // Polling complete. Resolve promise with final response data.
* return responseData;
* });
* })
* .then((responseData: any) => {
* console.log(`Final response: ${responseData}`);
* });
* ```
*/
export declare class ExponentialBackoffPoller<T> extends EventEmitter {
private readonly initialPollingDelayMillis;
private readonly maxPollingDelayMillis;
private readonly masterTimeoutMillis;
private numTries;
private completed;
private masterTimer;
private repollTimer;
private pollCallback?;
private resolve;
private reject;
constructor(initialPollingDelayMillis?: number, maxPollingDelayMillis?: number, masterTimeoutMillis?: number);
/**
* Poll the provided callback with exponential backoff.
*
* @param callback - The callback to be called for each poll. If the
* callback resolves to a falsey value, polling will continue. Otherwise, the truthy
* resolution will be used to resolve the promise returned by this method.
* @returns A Promise which resolves to the truthy value returned by the provided
* callback when polling is complete.
*/
poll(callback: () => Promise<T>): Promise<T>;
private repoll;
private getPollingDelayMillis;
private markCompleted;
}
export declare class Http2SessionHandler {
private http2Session;
protected promise: Promise<void>;
protected resolve: () => void;
protected reject: (_: any) => void;
constructor(url: string);
createSession(url: string): http2.ClientHttp2Session;
invoke(): Promise<void>;
get session(): http2.ClientHttp2Session;
get isClosed(): boolean;
close(): void;
}
export {};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,128 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2021 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { App } from '../app';
import { ServiceAccountCredential } from '../app/credential-internal';
import { AuthorizedHttpClient } from './api-request';
import { Algorithm } from 'jsonwebtoken';
import { ErrorInfo } from '../utils/error';
/**
* CryptoSigner interface represents an object that can be used to sign JWTs.
*/
export interface CryptoSigner {
/**
* The name of the signing algorithm.
*/
readonly algorithm: Algorithm;
/**
* Cryptographically signs a buffer of data.
*
* @param buffer - The data to be signed.
* @returns A promise that resolves with the raw bytes of a signature.
*/
sign(buffer: Buffer): Promise<Buffer>;
/**
* Returns the ID of the service account used to sign tokens.
*
* @returns A promise that resolves with a service account ID.
*/
getAccountId(): Promise<string>;
}
/**
* A CryptoSigner implementation that uses an explicitly specified service account private key to
* sign data. Performs all operations locally, and does not make any RPC calls.
*/
export declare class ServiceAccountSigner implements CryptoSigner {
private readonly credential;
algorithm: Algorithm;
/**
* Creates a new CryptoSigner instance from the given service account credential.
*
* @param credential - A service account credential.
*/
constructor(credential: ServiceAccountCredential);
/**
* @inheritDoc
*/
sign(buffer: Buffer): Promise<Buffer>;
/**
* @inheritDoc
*/
getAccountId(): Promise<string>;
}
/**
* A CryptoSigner implementation that uses the remote IAM service to sign data. If initialized without
* a service account ID, attempts to discover a service account ID by consulting the local Metadata
* service. This will succeed in managed environments like Google Cloud Functions and App Engine.
*
* @see https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob
* @see https://cloud.google.com/compute/docs/storing-retrieving-metadata
*/
export declare class IAMSigner implements CryptoSigner {
algorithm: Algorithm;
private readonly httpClient;
private serviceAccountId?;
private app?;
constructor(httpClient: AuthorizedHttpClient, app?: App);
/**
* @inheritDoc
*/
sign(buffer: Buffer): Promise<Buffer>;
/**
* @inheritDoc
*/
getAccountId(): Promise<string>;
}
/**
* Creates a new CryptoSigner instance for the given app. If the app has been initialized with a
* service account credential, creates a ServiceAccountSigner.
*
* @param app - A FirebaseApp instance.
* @returns A CryptoSigner instance.
*/
export declare function cryptoSignerFromApp(app: App): CryptoSigner;
/**
* Defines extended error info type. This includes a code, message string, and error data.
*/
export interface ExtendedErrorInfo extends ErrorInfo {
cause?: Error;
}
/**
* CryptoSigner error code structure.
*
* @param errorInfo - The error information (code and message).
* @constructor
*/
export declare class CryptoSignerError extends Error {
private errorInfo;
constructor(errorInfo: ExtendedErrorInfo);
/** @returns The error code. */
get code(): string;
/** @returns The error message. */
get message(): string;
/** @returns The error data. */
get cause(): Error | undefined;
}
/**
* Crypto Signer error codes and their default messages.
*/
export declare class CryptoSignerErrorCode {
static INVALID_ARGUMENT: string;
static INTERNAL_ERROR: string;
static INVALID_CREDENTIAL: string;
static SERVER_ERROR: string;
}

View File

@@ -0,0 +1,210 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2021 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CryptoSignerErrorCode = exports.CryptoSignerError = exports.IAMSigner = exports.ServiceAccountSigner = void 0;
exports.cryptoSignerFromApp = cryptoSignerFromApp;
const credential_internal_1 = require("../app/credential-internal");
const api_request_1 = require("./api-request");
const utils = require("../utils/index");
const validator = require("../utils/validator");
const ALGORITHM_RS256 = 'RS256';
/**
* A CryptoSigner implementation that uses an explicitly specified service account private key to
* sign data. Performs all operations locally, and does not make any RPC calls.
*/
class ServiceAccountSigner {
/**
* Creates a new CryptoSigner instance from the given service account credential.
*
* @param credential - A service account credential.
*/
constructor(credential) {
this.credential = credential;
this.algorithm = ALGORITHM_RS256;
if (!credential) {
throw new CryptoSignerError({
code: CryptoSignerErrorCode.INVALID_CREDENTIAL,
message: 'INTERNAL ASSERT: Must provide a service account credential to initialize ServiceAccountSigner.',
});
}
}
/**
* @inheritDoc
*/
sign(buffer) {
const crypto = require('crypto'); // eslint-disable-line @typescript-eslint/no-var-requires
const sign = crypto.createSign('RSA-SHA256');
sign.update(buffer);
return Promise.resolve(sign.sign(this.credential.privateKey));
}
/**
* @inheritDoc
*/
getAccountId() {
return Promise.resolve(this.credential.clientEmail);
}
}
exports.ServiceAccountSigner = ServiceAccountSigner;
/**
* A CryptoSigner implementation that uses the remote IAM service to sign data. If initialized without
* a service account ID, attempts to discover a service account ID by consulting the local Metadata
* service. This will succeed in managed environments like Google Cloud Functions and App Engine.
*
* @see https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob
* @see https://cloud.google.com/compute/docs/storing-retrieving-metadata
*/
class IAMSigner {
constructor(httpClient, app) {
this.algorithm = ALGORITHM_RS256;
if (!httpClient) {
throw new CryptoSignerError({
code: CryptoSignerErrorCode.INVALID_ARGUMENT,
message: 'INTERNAL ASSERT: Must provide a HTTP client to initialize IAMSigner.',
});
}
if (app && (typeof app !== 'object' || app === null || !('options' in app))) {
throw new CryptoSignerError({
code: CryptoSignerErrorCode.INVALID_ARGUMENT,
message: 'INTERNAL ASSERT: Must provide a valid Firebase app instance.',
});
}
this.httpClient = httpClient;
this.app = app;
}
/**
* @inheritDoc
*/
sign(buffer) {
return this.getAccountId().then((serviceAccount) => {
const request = {
method: 'POST',
url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${serviceAccount}:signBlob`,
data: { payload: buffer.toString('base64') },
};
return this.httpClient.send(request);
}).then((response) => {
// Response from IAM is base64 encoded. Decode it into a buffer and return.
return Buffer.from(response.data.signedBlob, 'base64');
}).catch((err) => {
if (err instanceof api_request_1.RequestResponseError) {
throw new CryptoSignerError({
code: CryptoSignerErrorCode.SERVER_ERROR,
message: err.message,
cause: err
});
}
throw err;
});
}
/**
* @inheritDoc
*/
async getAccountId() {
if (validator.isNonEmptyString(this.serviceAccountId)) {
return this.serviceAccountId;
}
if (this.app) {
const accountId = await utils.findServiceAccountEmail(this.app);
if (accountId) {
this.serviceAccountId = accountId;
return accountId;
}
}
const request = {
method: 'GET',
url: 'http://metadata/computeMetadata/v1/instance/service-accounts/default/email',
headers: {
'Metadata-Flavor': 'Google',
},
};
const client = new api_request_1.HttpClient();
return client.send(request).then((response) => {
if (!response.text) {
throw new CryptoSignerError({
code: CryptoSignerErrorCode.INTERNAL_ERROR,
message: 'HTTP Response missing payload',
});
}
this.serviceAccountId = response.text;
return response.text;
}).catch((err) => {
throw new CryptoSignerError({
code: CryptoSignerErrorCode.INVALID_CREDENTIAL,
message: 'Failed to determine service account. Make sure to initialize ' +
'the SDK with a service account credential. Alternatively specify a service ' +
`account with iam.serviceAccounts.signBlob permission. Original error: ${err}`,
});
});
}
}
exports.IAMSigner = IAMSigner;
/**
* Creates a new CryptoSigner instance for the given app. If the app has been initialized with a
* service account credential, creates a ServiceAccountSigner.
*
* @param app - A FirebaseApp instance.
* @returns A CryptoSigner instance.
*/
function cryptoSignerFromApp(app) {
const credential = app.options.credential;
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
return new ServiceAccountSigner(credential);
}
return new IAMSigner(new api_request_1.AuthorizedHttpClient(app), app);
}
/**
* CryptoSigner error code structure.
*
* @param errorInfo - The error information (code and message).
* @constructor
*/
class CryptoSignerError extends Error {
constructor(errorInfo) {
super(errorInfo.message);
this.errorInfo = errorInfo;
/* tslint:disable:max-line-length */
// Set the prototype explicitly. See the following link for more details:
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
/* tslint:enable:max-line-length */
this.__proto__ = CryptoSignerError.prototype;
}
/** @returns The error code. */
get code() {
return this.errorInfo.code;
}
/** @returns The error message. */
get message() {
return this.errorInfo.message;
}
/** @returns The error data. */
get cause() {
return this.errorInfo.cause;
}
}
exports.CryptoSignerError = CryptoSignerError;
/**
* Crypto Signer error codes and their default messages.
*/
class CryptoSignerErrorCode {
}
exports.CryptoSignerErrorCode = CryptoSignerErrorCode;
CryptoSignerErrorCode.INVALID_ARGUMENT = 'invalid-argument';
CryptoSignerErrorCode.INTERNAL_ERROR = 'internal-error';
CryptoSignerErrorCode.INVALID_CREDENTIAL = 'invalid-credential';
CryptoSignerErrorCode.SERVER_ERROR = 'server-error';

View File

@@ -0,0 +1,40 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Returns a deep copy of an object or array.
*
* @param value - The object or array to deep copy.
* @returns A deep copy of the provided object or array.
*/
export declare function deepCopy<T>(value: T): T;
/**
* Copies properties from source to target (recursively allows extension of objects and arrays).
* Scalar values in the target are over-written. If target is undefined, an object of the
* appropriate type will be created (and returned).
*
* We recursively copy all child properties of plain objects in the source - so that namespace-like
* objects are merged.
*
* Note that the target can be a function, in which case the properties in the source object are
* copied onto it as static properties of the function.
*
* @param target - The value which is being extended.
* @param source - The value whose properties are extending the target.
* @returns The target value.
*/
export declare function deepExtend(target: any, source: any): any;

View File

@@ -0,0 +1,77 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepCopy = deepCopy;
exports.deepExtend = deepExtend;
/**
* Returns a deep copy of an object or array.
*
* @param value - The object or array to deep copy.
* @returns A deep copy of the provided object or array.
*/
function deepCopy(value) {
return deepExtend(undefined, value);
}
/**
* Copies properties from source to target (recursively allows extension of objects and arrays).
* Scalar values in the target are over-written. If target is undefined, an object of the
* appropriate type will be created (and returned).
*
* We recursively copy all child properties of plain objects in the source - so that namespace-like
* objects are merged.
*
* Note that the target can be a function, in which case the properties in the source object are
* copied onto it as static properties of the function.
*
* @param target - The value which is being extended.
* @param source - The value whose properties are extending the target.
* @returns The target value.
*/
function deepExtend(target, source) {
if (!(source instanceof Object)) {
return source;
}
switch (source.constructor) {
case Date: {
// Treat Dates like scalars; if the target date object had any child
// properties - they will be lost!
const dateValue = source;
return new Date(dateValue.getTime());
}
case Object:
if (target === undefined) {
target = {};
}
break;
case Array:
// Always copy the array source and overwrite the target.
target = [];
break;
default:
// Not a plain Object - treat it as a scalar.
return source;
}
for (const prop in source) {
if (!Object.prototype.hasOwnProperty.call(source, prop)) {
continue;
}
target[prop] = deepExtend(target[prop], source[prop]);
}
return target;
}

604
server/node_modules/firebase-admin/lib/utils/error.d.ts generated vendored Normal file
View File

@@ -0,0 +1,604 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseError as FirebaseErrorInterface } from '../app';
import { BatchResponse } from '../messaging/messaging-api';
/**
* Defines error info type. This includes a code and message string.
*/
export interface ErrorInfo {
code: string;
message: string;
}
/**
* Firebase error code structure. This extends Error.
*/
export declare class FirebaseError extends Error implements FirebaseErrorInterface {
private errorInfo;
/** @returns The error code. */
get code(): string;
/** @returns The error message. */
get message(): string;
/** @returns The object representation of the error. */
toJSON(): object;
}
/**
* A FirebaseError with a prefix in front of the error code.
*/
export declare class PrefixedFirebaseError extends FirebaseError {
private codePrefix;
/**
* Allows the error type to be checked without needing to know implementation details
* of the code prefixing.
*
* @param code - The non-prefixed error code to test against.
* @returns True if the code matches, false otherwise.
*/
hasCode(code: string): boolean;
}
/**
* Firebase App error code structure. This extends PrefixedFirebaseError.
*/
export declare class FirebaseAppError extends PrefixedFirebaseError {
}
/**
* Firebase Auth error code structure. This extends PrefixedFirebaseError.
*/
export declare class FirebaseAuthError extends PrefixedFirebaseError {
}
/**
* Firebase Database error code structure. This extends FirebaseError.
*/
export declare class FirebaseDatabaseError extends FirebaseError {
}
/**
* Firebase Firestore error code structure. This extends FirebaseError.
*/
export declare class FirebaseFirestoreError extends FirebaseError {
}
/**
* Firebase instance ID error code structure. This extends FirebaseError.
*/
export declare class FirebaseInstanceIdError extends FirebaseError {
}
/**
* Firebase Installations service error code structure. This extends `FirebaseError`.
*/
export declare class FirebaseInstallationsError extends FirebaseError {
}
/**
* Firebase Messaging error code structure. This extends PrefixedFirebaseError.
*/
export declare class FirebaseMessagingError extends PrefixedFirebaseError {
}
export declare class FirebaseMessagingSessionError extends FirebaseMessagingError {
pendingBatchResponse?: Promise<BatchResponse>;
/** @returns The object representation of the error. */
toJSON(): object;
}
/**
* Firebase project management error code structure. This extends PrefixedFirebaseError.
*/
export declare class FirebaseProjectManagementError extends PrefixedFirebaseError {
}
/**
* App client error codes and their default messages.
*/
export declare class AppErrorCodes {
static APP_DELETED: string;
static DUPLICATE_APP: string;
static INVALID_ARGUMENT: string;
static INTERNAL_ERROR: string;
static INVALID_APP_NAME: string;
static INVALID_APP_OPTIONS: string;
static INVALID_CREDENTIAL: string;
static NETWORK_ERROR: string;
static NETWORK_TIMEOUT: string;
static NO_APP: string;
static UNABLE_TO_PARSE_RESPONSE: string;
}
/**
* Auth client error codes and their default messages.
*/
export declare class AuthClientErrorCode {
static AUTH_BLOCKING_TOKEN_EXPIRED: {
code: string;
message: string;
};
static BILLING_NOT_ENABLED: {
code: string;
message: string;
};
static CLAIMS_TOO_LARGE: {
code: string;
message: string;
};
static CONFIGURATION_EXISTS: {
code: string;
message: string;
};
static CONFIGURATION_NOT_FOUND: {
code: string;
message: string;
};
static ID_TOKEN_EXPIRED: {
code: string;
message: string;
};
static INVALID_ARGUMENT: {
code: string;
message: string;
};
static INVALID_CONFIG: {
code: string;
message: string;
};
static EMAIL_ALREADY_EXISTS: {
code: string;
message: string;
};
static EMAIL_NOT_FOUND: {
code: string;
message: string;
};
static FORBIDDEN_CLAIM: {
code: string;
message: string;
};
static INVALID_ID_TOKEN: {
code: string;
message: string;
};
static ID_TOKEN_REVOKED: {
code: string;
message: string;
};
static INTERNAL_ERROR: {
code: string;
message: string;
};
static INVALID_CLAIMS: {
code: string;
message: string;
};
static INVALID_CONTINUE_URI: {
code: string;
message: string;
};
static INVALID_CREATION_TIME: {
code: string;
message: string;
};
static INVALID_CREDENTIAL: {
code: string;
message: string;
};
static INVALID_DISABLED_FIELD: {
code: string;
message: string;
};
static INVALID_DISPLAY_NAME: {
code: string;
message: string;
};
static INVALID_DYNAMIC_LINK_DOMAIN: {
code: string;
message: string;
};
static INVALID_HOSTING_LINK_DOMAIN: {
code: string;
message: string;
};
static INVALID_EMAIL_VERIFIED: {
code: string;
message: string;
};
static INVALID_EMAIL: {
code: string;
message: string;
};
static INVALID_NEW_EMAIL: {
code: string;
message: string;
};
static INVALID_ENROLLED_FACTORS: {
code: string;
message: string;
};
static INVALID_ENROLLMENT_TIME: {
code: string;
message: string;
};
static INVALID_HASH_ALGORITHM: {
code: string;
message: string;
};
static INVALID_HASH_BLOCK_SIZE: {
code: string;
message: string;
};
static INVALID_HASH_DERIVED_KEY_LENGTH: {
code: string;
message: string;
};
static INVALID_HASH_KEY: {
code: string;
message: string;
};
static INVALID_HASH_MEMORY_COST: {
code: string;
message: string;
};
static INVALID_HASH_PARALLELIZATION: {
code: string;
message: string;
};
static INVALID_HASH_ROUNDS: {
code: string;
message: string;
};
static INVALID_HASH_SALT_SEPARATOR: {
code: string;
message: string;
};
static INVALID_LAST_SIGN_IN_TIME: {
code: string;
message: string;
};
static INVALID_NAME: {
code: string;
message: string;
};
static INVALID_OAUTH_CLIENT_ID: {
code: string;
message: string;
};
static INVALID_PAGE_TOKEN: {
code: string;
message: string;
};
static INVALID_PASSWORD: {
code: string;
message: string;
};
static INVALID_PASSWORD_HASH: {
code: string;
message: string;
};
static INVALID_PASSWORD_SALT: {
code: string;
message: string;
};
static INVALID_PHONE_NUMBER: {
code: string;
message: string;
};
static INVALID_PHOTO_URL: {
code: string;
message: string;
};
static INVALID_PROJECT_ID: {
code: string;
message: string;
};
static INVALID_PROVIDER_DATA: {
code: string;
message: string;
};
static INVALID_PROVIDER_ID: {
code: string;
message: string;
};
static INVALID_PROVIDER_UID: {
code: string;
message: string;
};
static INVALID_OAUTH_RESPONSETYPE: {
code: string;
message: string;
};
static INVALID_SESSION_COOKIE_DURATION: {
code: string;
message: string;
};
static INVALID_TENANT_ID: {
code: string;
message: string;
};
static INVALID_TENANT_TYPE: {
code: string;
message: string;
};
static INVALID_TESTING_PHONE_NUMBER: {
code: string;
message: string;
};
static INVALID_UID: {
code: string;
message: string;
};
static INVALID_USER_IMPORT: {
code: string;
message: string;
};
static INVALID_TOKENS_VALID_AFTER_TIME: {
code: string;
message: string;
};
static MISMATCHING_TENANT_ID: {
code: string;
message: string;
};
static MISSING_ANDROID_PACKAGE_NAME: {
code: string;
message: string;
};
static MISSING_CONFIG: {
code: string;
message: string;
};
static MISSING_CONTINUE_URI: {
code: string;
message: string;
};
static MISSING_DISPLAY_NAME: {
code: string;
message: string;
};
static MISSING_EMAIL: {
code: string;
message: string;
};
static MISSING_IOS_BUNDLE_ID: {
code: string;
message: string;
};
static MISSING_ISSUER: {
code: string;
message: string;
};
static MISSING_HASH_ALGORITHM: {
code: string;
message: string;
};
static MISSING_OAUTH_CLIENT_ID: {
code: string;
message: string;
};
static MISSING_OAUTH_CLIENT_SECRET: {
code: string;
message: string;
};
static MISSING_PROVIDER_ID: {
code: string;
message: string;
};
static MISSING_SAML_RELYING_PARTY_CONFIG: {
code: string;
message: string;
};
static MAXIMUM_TEST_PHONE_NUMBER_EXCEEDED: {
code: string;
message: string;
};
static MAXIMUM_USER_COUNT_EXCEEDED: {
code: string;
message: string;
};
static MISSING_UID: {
code: string;
message: string;
};
static OPERATION_NOT_ALLOWED: {
code: string;
message: string;
};
static PHONE_NUMBER_ALREADY_EXISTS: {
code: string;
message: string;
};
static PROJECT_NOT_FOUND: {
code: string;
message: string;
};
static INSUFFICIENT_PERMISSION: {
code: string;
message: string;
};
static QUOTA_EXCEEDED: {
code: string;
message: string;
};
static SECOND_FACTOR_LIMIT_EXCEEDED: {
code: string;
message: string;
};
static SECOND_FACTOR_UID_ALREADY_EXISTS: {
code: string;
message: string;
};
static SESSION_COOKIE_EXPIRED: {
code: string;
message: string;
};
static SESSION_COOKIE_REVOKED: {
code: string;
message: string;
};
static TENANT_NOT_FOUND: {
code: string;
message: string;
};
static UID_ALREADY_EXISTS: {
code: string;
message: string;
};
static UNAUTHORIZED_DOMAIN: {
code: string;
message: string;
};
static UNSUPPORTED_FIRST_FACTOR: {
code: string;
message: string;
};
static UNSUPPORTED_SECOND_FACTOR: {
code: string;
message: string;
};
static UNSUPPORTED_TENANT_OPERATION: {
code: string;
message: string;
};
static UNVERIFIED_EMAIL: {
code: string;
message: string;
};
static USER_NOT_FOUND: {
code: string;
message: string;
};
static NOT_FOUND: {
code: string;
message: string;
};
static USER_DISABLED: {
code: string;
message: string;
};
static USER_NOT_DISABLED: {
code: string;
message: string;
};
static INVALID_RECAPTCHA_ACTION: {
code: string;
message: string;
};
static INVALID_RECAPTCHA_ENFORCEMENT_STATE: {
code: string;
message: string;
};
static RECAPTCHA_NOT_ENABLED: {
code: string;
message: string;
};
}
/**
* Messaging client error codes and their default messages.
*/
export declare class MessagingClientErrorCode {
static INVALID_ARGUMENT: {
code: string;
message: string;
};
static INVALID_RECIPIENT: {
code: string;
message: string;
};
static INVALID_PAYLOAD: {
code: string;
message: string;
};
static INVALID_DATA_PAYLOAD_KEY: {
code: string;
message: string;
};
static PAYLOAD_SIZE_LIMIT_EXCEEDED: {
code: string;
message: string;
};
static INVALID_OPTIONS: {
code: string;
message: string;
};
static INVALID_REGISTRATION_TOKEN: {
code: string;
message: string;
};
static REGISTRATION_TOKEN_NOT_REGISTERED: {
code: string;
message: string;
};
static MISMATCHED_CREDENTIAL: {
code: string;
message: string;
};
static INVALID_PACKAGE_NAME: {
code: string;
message: string;
};
static DEVICE_MESSAGE_RATE_EXCEEDED: {
code: string;
message: string;
};
static TOPICS_MESSAGE_RATE_EXCEEDED: {
code: string;
message: string;
};
static MESSAGE_RATE_EXCEEDED: {
code: string;
message: string;
};
static THIRD_PARTY_AUTH_ERROR: {
code: string;
message: string;
};
static TOO_MANY_TOPICS: {
code: string;
message: string;
};
static AUTHENTICATION_ERROR: {
code: string;
message: string;
};
static SERVER_UNAVAILABLE: {
code: string;
message: string;
};
static INTERNAL_ERROR: {
code: string;
message: string;
};
static UNKNOWN_ERROR: {
code: string;
message: string;
};
}
export declare class InstallationsClientErrorCode {
static INVALID_ARGUMENT: {
code: string;
message: string;
};
static INVALID_PROJECT_ID: {
code: string;
message: string;
};
static INVALID_INSTALLATION_ID: {
code: string;
message: string;
};
static API_ERROR: {
code: string;
message: string;
};
}
export declare class InstanceIdClientErrorCode extends InstallationsClientErrorCode {
static INVALID_INSTANCE_ID: {
code: string;
message: string;
};
}
export type ProjectManagementErrorCode = 'already-exists' | 'authentication-error' | 'internal-error' | 'invalid-argument' | 'invalid-project-id' | 'invalid-server-response' | 'not-found' | 'service-unavailable' | 'unknown-error';

1086
server/node_modules/firebase-admin/lib/utils/error.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

147
server/node_modules/firebase-admin/lib/utils/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,147 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { App } from '../app/index';
export declare function getSdkVersion(): string;
export declare function getMetricsHeader(): string;
/**
* Renames properties on an object given a mapping from old to new property names.
*
* For example, this can be used to map underscore_cased properties to camelCase.
*
* @param obj - The object whose properties to rename.
* @param keyMap - The mapping from old to new property names.
*/
export declare function renameProperties(obj: {
[key: string]: any;
}, keyMap: {
[key: string]: string;
}): void;
/**
* Defines a new read-only property directly on an object and returns the object.
*
* @param obj - The object on which to define the property.
* @param prop - The name of the property to be defined or modified.
* @param value - The value associated with the property.
*/
export declare function addReadonlyGetter(obj: object, prop: string, value: any): void;
/**
* Returns the Google Cloud project ID associated with a Firebase app, if it's explicitly
* specified in either the Firebase app options, credentials or the local environment.
* Otherwise returns null.
*
* @param app - A Firebase app to get the project ID from.
*
* @returns A project ID string or null.
*/
export declare function getExplicitProjectId(app: App): string | null;
/**
* Determines the Google Cloud project ID associated with a Firebase app. This method
* first checks if a project ID is explicitly specified in either the Firebase app options,
* credentials or the local environment in that order. If no explicit project ID is
* configured, but the SDK has been initialized with ComputeEngineCredentials, this
* method attempts to discover the project ID from the local metadata service.
*
* @param app - A Firebase app to get the project ID from.
*
* @returns A project ID string or null.
*/
export declare function findProjectId(app: App): Promise<string | null>;
/**
* Returns the service account email associated with a Firebase app, if it's explicitly
* specified in either the Firebase app options, credentials or the local environment.
* Otherwise returns null.
*
* @param app - A Firebase app to get the service account email from.
*
* @returns A service account email string or null.
*/
export declare function getExplicitServiceAccountEmail(app: App): string | null;
/**
* Determines the service account email associated with a Firebase app. This method first
* checks if a service account email is explicitly specified in either the Firebase app options,
* credentials or the local environment in that order. If no explicit service account email is
* configured, but the SDK has been initialized with ComputeEngineCredentials, this
* method attempts to discover the service account email from the local metadata service.
*
* @param app - A Firebase app to get the service account email from.
*
* @returns A service account email ID string or null.
*/
export declare function findServiceAccountEmail(app: App): Promise<string | null>;
/**
* Encodes data using web-safe-base64.
*
* @param data - The raw data byte input.
* @returns The base64-encoded result.
*/
export declare function toWebSafeBase64(data: Buffer): string;
/**
* Formats a string of form 'project/{projectId}/{api}' and replaces
* with corresponding arguments {projectId: '1234', api: 'resource'}
* and returns output: 'project/1234/resource'.
*
* @param str - The original string where the param need to be
* replaced.
* @param params - The optional parameters to replace in the
* string.
* @returns The resulting formatted string.
*/
export declare function formatString(str: string, params?: object): string;
/**
* Generates the update mask for the provided object.
* Note this will ignore the last key with value undefined.
*
* @param obj - The object to generate the update mask for.
* @param terminalPaths - The optional map of keys for maximum paths to traverse.
* Nested objects beyond that path will be ignored. This is useful for
* keys with variable object values.
* @param root - The path so far.
* @returns The computed update mask list.
*/
export declare function generateUpdateMask(obj: any, terminalPaths?: string[], root?: string): string[];
/**
* Transforms milliseconds to a protobuf Duration type string.
* Returns the duration in seconds with up to nine fractional
* digits, terminated by 's'. Example: "3 seconds 0 nano seconds as 3s,
* 3 seconds 1 nano seconds as 3.000000001s".
*
* @param milliseconds - The duration in milliseconds.
* @returns The resulting formatted string in seconds with up to nine fractional
* digits, terminated by 's'.
*/
export declare function transformMillisecondsToSecondsString(milliseconds: number): string;
/**
* Internal type to represent a resource name
*/
export type ParsedResource = {
projectId?: string;
locationId?: string;
resourceId: string;
};
/**
* Parses the top level resources of a given resource name.
* Supports both full and partial resources names, example:
* `locations/{location}/functions/{functionName}`,
* `projects/{project}/locations/{location}/functions/{functionName}`, or {functionName}
* Does not support deeply nested resource names.
*
* @param resourceName - The resource name string.
* @param resourceIdKey - The key of the resource name to be parsed.
* @returns A parsed resource name object.
*/
export declare function parseResourceName(resourceName: string, resourceIdKey: string): ParsedResource;

286
server/node_modules/firebase-admin/lib/utils/index.js generated vendored Normal file
View File

@@ -0,0 +1,286 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSdkVersion = getSdkVersion;
exports.getMetricsHeader = getMetricsHeader;
exports.renameProperties = renameProperties;
exports.addReadonlyGetter = addReadonlyGetter;
exports.getExplicitProjectId = getExplicitProjectId;
exports.findProjectId = findProjectId;
exports.getExplicitServiceAccountEmail = getExplicitServiceAccountEmail;
exports.findServiceAccountEmail = findServiceAccountEmail;
exports.toWebSafeBase64 = toWebSafeBase64;
exports.formatString = formatString;
exports.generateUpdateMask = generateUpdateMask;
exports.transformMillisecondsToSecondsString = transformMillisecondsToSecondsString;
exports.parseResourceName = parseResourceName;
const credential_internal_1 = require("../app/credential-internal");
const validator = require("./validator");
let sdkVersion;
// TODO: Move to firebase-admin/app as an internal member.
function getSdkVersion() {
if (!sdkVersion) {
const { version } = require('../../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires
sdkVersion = version;
}
return sdkVersion;
}
function getMetricsHeader() {
return `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`;
}
/**
* Renames properties on an object given a mapping from old to new property names.
*
* For example, this can be used to map underscore_cased properties to camelCase.
*
* @param obj - The object whose properties to rename.
* @param keyMap - The mapping from old to new property names.
*/
function renameProperties(obj, keyMap) {
Object.keys(keyMap).forEach((oldKey) => {
if (oldKey in obj) {
const newKey = keyMap[oldKey];
// The old key's value takes precedence over the new key's value.
obj[newKey] = obj[oldKey];
delete obj[oldKey];
}
});
}
/**
* Defines a new read-only property directly on an object and returns the object.
*
* @param obj - The object on which to define the property.
* @param prop - The name of the property to be defined or modified.
* @param value - The value associated with the property.
*/
function addReadonlyGetter(obj, prop, value) {
Object.defineProperty(obj, prop, {
value,
// Make this property read-only.
writable: false,
// Include this property during enumeration of obj's properties.
enumerable: true,
});
}
/**
* Returns the Google Cloud project ID associated with a Firebase app, if it's explicitly
* specified in either the Firebase app options, credentials or the local environment.
* Otherwise returns null.
*
* @param app - A Firebase app to get the project ID from.
*
* @returns A project ID string or null.
*/
function getExplicitProjectId(app) {
const options = app.options;
if (validator.isNonEmptyString(options.projectId)) {
return options.projectId;
}
const credential = app.options.credential;
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
return credential.projectId;
}
const projectId = process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT;
if (validator.isNonEmptyString(projectId)) {
return projectId;
}
return null;
}
/**
* Determines the Google Cloud project ID associated with a Firebase app. This method
* first checks if a project ID is explicitly specified in either the Firebase app options,
* credentials or the local environment in that order. If no explicit project ID is
* configured, but the SDK has been initialized with ComputeEngineCredentials, this
* method attempts to discover the project ID from the local metadata service.
*
* @param app - A Firebase app to get the project ID from.
*
* @returns A project ID string or null.
*/
function findProjectId(app) {
const projectId = getExplicitProjectId(app);
if (projectId) {
return Promise.resolve(projectId);
}
const credential = app.options.credential;
if (credential instanceof credential_internal_1.ApplicationDefaultCredential) {
return credential.getProjectId();
}
return Promise.resolve(null);
}
/**
* Returns the service account email associated with a Firebase app, if it's explicitly
* specified in either the Firebase app options, credentials or the local environment.
* Otherwise returns null.
*
* @param app - A Firebase app to get the service account email from.
*
* @returns A service account email string or null.
*/
function getExplicitServiceAccountEmail(app) {
const options = app.options;
if (validator.isNonEmptyString(options.serviceAccountId)) {
return options.serviceAccountId;
}
const credential = app.options.credential;
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
return credential.clientEmail;
}
return null;
}
/**
* Determines the service account email associated with a Firebase app. This method first
* checks if a service account email is explicitly specified in either the Firebase app options,
* credentials or the local environment in that order. If no explicit service account email is
* configured, but the SDK has been initialized with ComputeEngineCredentials, this
* method attempts to discover the service account email from the local metadata service.
*
* @param app - A Firebase app to get the service account email from.
*
* @returns A service account email ID string or null.
*/
function findServiceAccountEmail(app) {
const accountId = getExplicitServiceAccountEmail(app);
if (accountId) {
return Promise.resolve(accountId);
}
const credential = app.options.credential;
if (credential instanceof credential_internal_1.ApplicationDefaultCredential) {
return credential.getServiceAccountEmail();
}
return Promise.resolve(null);
}
/**
* Encodes data using web-safe-base64.
*
* @param data - The raw data byte input.
* @returns The base64-encoded result.
*/
function toWebSafeBase64(data) {
return data.toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
}
/**
* Formats a string of form 'project/{projectId}/{api}' and replaces
* with corresponding arguments {projectId: '1234', api: 'resource'}
* and returns output: 'project/1234/resource'.
*
* @param str - The original string where the param need to be
* replaced.
* @param params - The optional parameters to replace in the
* string.
* @returns The resulting formatted string.
*/
function formatString(str, params) {
let formatted = str;
Object.keys(params || {}).forEach((key) => {
formatted = formatted.replace(new RegExp('{' + key + '}', 'g'), params[key]);
});
return formatted;
}
/**
* Generates the update mask for the provided object.
* Note this will ignore the last key with value undefined.
*
* @param obj - The object to generate the update mask for.
* @param terminalPaths - The optional map of keys for maximum paths to traverse.
* Nested objects beyond that path will be ignored. This is useful for
* keys with variable object values.
* @param root - The path so far.
* @returns The computed update mask list.
*/
function generateUpdateMask(obj, terminalPaths = [], root = '') {
const updateMask = [];
if (!validator.isNonNullObject(obj)) {
return updateMask;
}
for (const key in obj) {
if (typeof obj[key] !== 'undefined') {
const nextPath = root ? `${root}.${key}` : key;
// We hit maximum path.
// Consider switching to Set<string> if the list grows too large.
if (terminalPaths.indexOf(nextPath) !== -1) {
// Add key and stop traversing this branch.
updateMask.push(key);
}
else {
const maskList = generateUpdateMask(obj[key], terminalPaths, nextPath);
if (maskList.length > 0) {
maskList.forEach((mask) => {
updateMask.push(`${key}.${mask}`);
});
}
else {
updateMask.push(key);
}
}
}
}
return updateMask;
}
/**
* Transforms milliseconds to a protobuf Duration type string.
* Returns the duration in seconds with up to nine fractional
* digits, terminated by 's'. Example: "3 seconds 0 nano seconds as 3s,
* 3 seconds 1 nano seconds as 3.000000001s".
*
* @param milliseconds - The duration in milliseconds.
* @returns The resulting formatted string in seconds with up to nine fractional
* digits, terminated by 's'.
*/
function transformMillisecondsToSecondsString(milliseconds) {
let duration;
const seconds = Math.floor(milliseconds / 1000);
const nanos = Math.floor((milliseconds - seconds * 1000) * 1000000);
if (nanos > 0) {
let nanoString = nanos.toString();
while (nanoString.length < 9) {
nanoString = '0' + nanoString;
}
duration = `${seconds}.${nanoString}s`;
}
else {
duration = `${seconds}s`;
}
return duration;
}
/**
* Parses the top level resources of a given resource name.
* Supports both full and partial resources names, example:
* `locations/{location}/functions/{functionName}`,
* `projects/{project}/locations/{location}/functions/{functionName}`, or {functionName}
* Does not support deeply nested resource names.
*
* @param resourceName - The resource name string.
* @param resourceIdKey - The key of the resource name to be parsed.
* @returns A parsed resource name object.
*/
function parseResourceName(resourceName, resourceIdKey) {
if (!resourceName.includes('/')) {
return { resourceId: resourceName };
}
const CHANNEL_NAME_REGEX = new RegExp(`^(projects/([^/]+)/)?locations/([^/]+)/${resourceIdKey}/([^/]+)$`);
const match = CHANNEL_NAME_REGEX.exec(resourceName);
if (match === null) {
throw new Error('Invalid resource name format.');
}
const projectId = match[2];
const locationId = match[3];
const resourceId = match[4];
return { projectId, locationId, resourceId };
}

130
server/node_modules/firebase-admin/lib/utils/jwt.d.ts generated vendored Normal file
View File

@@ -0,0 +1,130 @@
/*! firebase-admin v13.5.0 */
/*!
* Copyright 2021 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as jwt from 'jsonwebtoken';
import { Agent } from 'http';
export declare const ALGORITHM_RS256: jwt.Algorithm;
export type Dictionary = {
[key: string]: any;
};
export type DecodedToken = {
header: Dictionary;
payload: Dictionary;
};
export interface SignatureVerifier {
verify(token: string): Promise<void>;
}
interface KeyFetcher {
fetchPublicKeys(): Promise<{
[key: string]: string;
}>;
}
export declare class JwksFetcher implements KeyFetcher {
private publicKeys;
private publicKeysExpireAt;
private client;
constructor(jwksUrl: string, httpAgent?: Agent);
fetchPublicKeys(): Promise<{
[key: string]: string;
}>;
private shouldRefresh;
private refresh;
}
/**
* Class to fetch public keys from a client certificates URL.
*/
export declare class UrlKeyFetcher implements KeyFetcher {
private clientCertUrl;
private readonly httpAgent?;
private publicKeys;
private publicKeysExpireAt;
constructor(clientCertUrl: string, httpAgent?: Agent | undefined);
/**
* Fetches the public keys for the Google certs.
*
* @returns A promise fulfilled with public keys for the Google certs.
*/
fetchPublicKeys(): Promise<{
[key: string]: string;
}>;
/**
* Checks if the cached public keys need to be refreshed.
*
* @returns Whether the keys should be fetched from the client certs url or not.
*/
private shouldRefresh;
private refresh;
}
/**
* Class for verifying JWT signature with a public key.
*/
export declare class PublicKeySignatureVerifier implements SignatureVerifier {
private keyFetcher;
constructor(keyFetcher: KeyFetcher);
static withCertificateUrl(clientCertUrl: string, httpAgent?: Agent): PublicKeySignatureVerifier;
static withJwksUrl(jwksUrl: string, httpAgent?: Agent): PublicKeySignatureVerifier;
verify(token: string): Promise<void>;
private verifyWithoutKid;
private verifyWithAllKeys;
}
/**
* Class for verifying unsigned (emulator) JWTs.
*/
export declare class EmulatorSignatureVerifier implements SignatureVerifier {
verify(token: string): Promise<void>;
}
/**
* Verifies the signature of a JWT using the provided secret or a function to fetch
* the secret or public key.
*
* @param token - The JWT to be verified.
* @param secretOrPublicKey - The secret or a function to fetch the secret or public key.
* @param options - JWT verification options.
* @returns A Promise resolving for a token with a valid signature.
*/
export declare function verifyJwtSignature(token: string, secretOrPublicKey: jwt.Secret | jwt.GetPublicKeyOrSecret, options?: jwt.VerifyOptions): Promise<void>;
/**
* Decodes general purpose Firebase JWTs.
*
* @param jwtToken - JWT token to be decoded.
* @returns Decoded token containing the header and payload.
*/
export declare function decodeJwt(jwtToken: string): Promise<DecodedToken>;
/**
* Jwt error code structure.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
export declare class JwtError extends Error {
readonly code: JwtErrorCode;
readonly message: string;
constructor(code: JwtErrorCode, message: string);
}
/**
* JWT error codes.
*/
export declare enum JwtErrorCode {
INVALID_ARGUMENT = "invalid-argument",
INVALID_CREDENTIAL = "invalid-credential",
TOKEN_EXPIRED = "token-expired",
INVALID_SIGNATURE = "invalid-token",
NO_MATCHING_KID = "no-matching-kid-error",
NO_KID_IN_HEADER = "no-kid-error",
KEY_FETCH_ERROR = "key-fetch-error"
}
export {};

330
server/node_modules/firebase-admin/lib/utils/jwt.js generated vendored Normal file
View File

@@ -0,0 +1,330 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* Copyright 2021 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.JwtErrorCode = exports.JwtError = exports.EmulatorSignatureVerifier = exports.PublicKeySignatureVerifier = exports.UrlKeyFetcher = exports.JwksFetcher = exports.ALGORITHM_RS256 = void 0;
exports.verifyJwtSignature = verifyJwtSignature;
exports.decodeJwt = decodeJwt;
const validator = require("./validator");
const jwt = require("jsonwebtoken");
const jwks = require("jwks-rsa");
const api_request_1 = require("../utils/api-request");
exports.ALGORITHM_RS256 = 'RS256';
// `jsonwebtoken` converts errors from the `getKey` callback to its own `JsonWebTokenError` type
// and prefixes the error message with the following. Use the prefix to identify errors thrown
// from the key provider callback.
// https://github.com/auth0/node-jsonwebtoken/blob/d71e383862fc735991fd2e759181480f066bf138/verify.js#L96
const JWT_CALLBACK_ERROR_PREFIX = 'error in secret or public key callback: ';
const NO_MATCHING_KID_ERROR_MESSAGE = 'no-matching-kid-error';
const NO_KID_IN_HEADER_ERROR_MESSAGE = 'no-kid-in-header-error';
const HOUR_IN_SECONDS = 3600;
class JwksFetcher {
constructor(jwksUrl, httpAgent) {
this.publicKeysExpireAt = 0;
if (!validator.isURL(jwksUrl)) {
throw new Error('The provided JWKS URL is not a valid URL.');
}
this.client = jwks({
jwksUri: jwksUrl,
cache: false, // disable jwks-rsa LRU cache as the keys are always cached for 6 hours.
requestAgent: httpAgent,
});
}
fetchPublicKeys() {
if (this.shouldRefresh()) {
return this.refresh();
}
return Promise.resolve(this.publicKeys);
}
shouldRefresh() {
return !this.publicKeys || this.publicKeysExpireAt <= Date.now();
}
refresh() {
return this.client.getSigningKeys()
.then((signingKeys) => {
// reset expire at from previous set of keys.
this.publicKeysExpireAt = 0;
const newKeys = signingKeys.reduce((map, signingKey) => {
map[signingKey.kid] = signingKey.getPublicKey();
return map;
}, {});
this.publicKeysExpireAt = Date.now() + (HOUR_IN_SECONDS * 6 * 1000);
this.publicKeys = newKeys;
return newKeys;
}).catch((err) => {
throw new Error(`Error fetching Json Web Keys: ${err.message}`);
});
}
}
exports.JwksFetcher = JwksFetcher;
/**
* Class to fetch public keys from a client certificates URL.
*/
class UrlKeyFetcher {
constructor(clientCertUrl, httpAgent) {
this.clientCertUrl = clientCertUrl;
this.httpAgent = httpAgent;
this.publicKeysExpireAt = 0;
if (!validator.isURL(clientCertUrl)) {
throw new Error('The provided public client certificate URL is not a valid URL.');
}
}
/**
* Fetches the public keys for the Google certs.
*
* @returns A promise fulfilled with public keys for the Google certs.
*/
fetchPublicKeys() {
if (this.shouldRefresh()) {
return this.refresh();
}
return Promise.resolve(this.publicKeys);
}
/**
* Checks if the cached public keys need to be refreshed.
*
* @returns Whether the keys should be fetched from the client certs url or not.
*/
shouldRefresh() {
return !this.publicKeys || this.publicKeysExpireAt <= Date.now();
}
refresh() {
const client = new api_request_1.HttpClient();
const request = {
method: 'GET',
url: this.clientCertUrl,
httpAgent: this.httpAgent,
};
return client.send(request).then((resp) => {
if (!resp.isJson() || resp.data.error) {
// Treat all non-json messages and messages with an 'error' field as
// error responses.
throw new api_request_1.RequestResponseError(resp);
}
// reset expire at from previous set of keys.
this.publicKeysExpireAt = 0;
if (Object.prototype.hasOwnProperty.call(resp.headers, 'cache-control')) {
const cacheControlHeader = resp.headers['cache-control'];
const parts = cacheControlHeader.split(',');
parts.forEach((part) => {
const subParts = part.trim().split('=');
if (subParts[0] === 'max-age') {
const maxAge = +subParts[1];
this.publicKeysExpireAt = Date.now() + (maxAge * 1000);
}
});
}
this.publicKeys = resp.data;
return resp.data;
}).catch((err) => {
if (err instanceof api_request_1.RequestResponseError) {
let errorMessage = 'Error fetching public keys for Google certs: ';
const resp = err.response;
if (resp.isJson() && resp.data.error) {
errorMessage += `${resp.data.error}`;
if (resp.data.error_description) {
errorMessage += ' (' + resp.data.error_description + ')';
}
}
else {
errorMessage += `${resp.text}`;
}
throw new Error(errorMessage);
}
throw err;
});
}
}
exports.UrlKeyFetcher = UrlKeyFetcher;
/**
* Class for verifying JWT signature with a public key.
*/
class PublicKeySignatureVerifier {
constructor(keyFetcher) {
this.keyFetcher = keyFetcher;
if (!validator.isNonNullObject(keyFetcher)) {
throw new Error('The provided key fetcher is not an object or null.');
}
}
static withCertificateUrl(clientCertUrl, httpAgent) {
return new PublicKeySignatureVerifier(new UrlKeyFetcher(clientCertUrl, httpAgent));
}
static withJwksUrl(jwksUrl, httpAgent) {
return new PublicKeySignatureVerifier(new JwksFetcher(jwksUrl, httpAgent));
}
verify(token) {
if (!validator.isString(token)) {
return Promise.reject(new JwtError(JwtErrorCode.INVALID_ARGUMENT, 'The provided token must be a string.'));
}
return verifyJwtSignature(token, getKeyCallback(this.keyFetcher), { algorithms: [exports.ALGORITHM_RS256] })
.catch((error) => {
if (error.code === JwtErrorCode.NO_KID_IN_HEADER) {
// No kid in JWT header. Try with all the public keys.
return this.verifyWithoutKid(token);
}
throw error;
});
}
verifyWithoutKid(token) {
return this.keyFetcher.fetchPublicKeys()
.then(publicKeys => this.verifyWithAllKeys(token, publicKeys));
}
verifyWithAllKeys(token, keys) {
const promises = [];
Object.values(keys).forEach((key) => {
const result = verifyJwtSignature(token, key)
.then(() => true)
.catch((error) => {
if (error.code === JwtErrorCode.TOKEN_EXPIRED) {
throw error;
}
return false;
});
promises.push(result);
});
return Promise.all(promises)
.then((result) => {
if (result.every((r) => r === false)) {
throw new JwtError(JwtErrorCode.INVALID_SIGNATURE, 'Invalid token signature.');
}
});
}
}
exports.PublicKeySignatureVerifier = PublicKeySignatureVerifier;
/**
* Class for verifying unsigned (emulator) JWTs.
*/
class EmulatorSignatureVerifier {
verify(token) {
// Signature checks skipped for emulator; no need to fetch public keys.
return verifyJwtSignature(token, undefined, { algorithms: ['none'] });
}
}
exports.EmulatorSignatureVerifier = EmulatorSignatureVerifier;
/**
* Provides a callback to fetch public keys.
*
* @param fetcher - KeyFetcher to fetch the keys from.
* @returns A callback function that can be used to get keys in `jsonwebtoken`.
*/
function getKeyCallback(fetcher) {
return (header, callback) => {
if (!header.kid) {
callback(new Error(NO_KID_IN_HEADER_ERROR_MESSAGE));
}
const kid = header.kid || '';
fetcher.fetchPublicKeys().then((publicKeys) => {
if (!Object.prototype.hasOwnProperty.call(publicKeys, kid)) {
callback(new Error(NO_MATCHING_KID_ERROR_MESSAGE));
}
else {
callback(null, publicKeys[kid]);
}
})
.catch(error => {
callback(error);
});
};
}
/**
* Verifies the signature of a JWT using the provided secret or a function to fetch
* the secret or public key.
*
* @param token - The JWT to be verified.
* @param secretOrPublicKey - The secret or a function to fetch the secret or public key.
* @param options - JWT verification options.
* @returns A Promise resolving for a token with a valid signature.
*/
function verifyJwtSignature(token, secretOrPublicKey, options) {
if (!validator.isString(token)) {
return Promise.reject(new JwtError(JwtErrorCode.INVALID_ARGUMENT, 'The provided token must be a string.'));
}
return new Promise((resolve, reject) => {
jwt.verify(token, secretOrPublicKey, options, (error) => {
if (!error) {
return resolve();
}
if (error.name === 'TokenExpiredError') {
return reject(new JwtError(JwtErrorCode.TOKEN_EXPIRED, 'The provided token has expired. Get a fresh token from your ' +
'client app and try again.'));
}
else if (error.name === 'JsonWebTokenError') {
if (error.message && error.message.includes(JWT_CALLBACK_ERROR_PREFIX)) {
const message = error.message.split(JWT_CALLBACK_ERROR_PREFIX).pop() || 'Error fetching public keys.';
let code = JwtErrorCode.KEY_FETCH_ERROR;
if (message === NO_MATCHING_KID_ERROR_MESSAGE) {
code = JwtErrorCode.NO_MATCHING_KID;
}
else if (message === NO_KID_IN_HEADER_ERROR_MESSAGE) {
code = JwtErrorCode.NO_KID_IN_HEADER;
}
return reject(new JwtError(code, message));
}
}
return reject(new JwtError(JwtErrorCode.INVALID_SIGNATURE, error.message));
});
});
}
/**
* Decodes general purpose Firebase JWTs.
*
* @param jwtToken - JWT token to be decoded.
* @returns Decoded token containing the header and payload.
*/
function decodeJwt(jwtToken) {
if (!validator.isString(jwtToken)) {
return Promise.reject(new JwtError(JwtErrorCode.INVALID_ARGUMENT, 'The provided token must be a string.'));
}
const fullDecodedToken = jwt.decode(jwtToken, {
complete: true,
});
if (!fullDecodedToken) {
return Promise.reject(new JwtError(JwtErrorCode.INVALID_ARGUMENT, 'Decoding token failed.'));
}
const header = fullDecodedToken?.header;
const payload = fullDecodedToken?.payload;
return Promise.resolve({ header, payload });
}
/**
* Jwt error code structure.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
class JwtError extends Error {
constructor(code, message) {
super(message);
this.code = code;
this.message = message;
this.__proto__ = JwtError.prototype;
}
}
exports.JwtError = JwtError;
/**
* JWT error codes.
*/
var JwtErrorCode;
(function (JwtErrorCode) {
JwtErrorCode["INVALID_ARGUMENT"] = "invalid-argument";
JwtErrorCode["INVALID_CREDENTIAL"] = "invalid-credential";
JwtErrorCode["TOKEN_EXPIRED"] = "token-expired";
JwtErrorCode["INVALID_SIGNATURE"] = "invalid-token";
JwtErrorCode["NO_MATCHING_KID"] = "no-matching-kid-error";
JwtErrorCode["NO_KID_IN_HEADER"] = "no-kid-error";
JwtErrorCode["KEY_FETCH_ERROR"] = "key-fetch-error";
})(JwtErrorCode || (exports.JwtErrorCode = JwtErrorCode = {}));

View File

@@ -0,0 +1,151 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Validates that a value is a byte buffer.
*
* @param value - The value to validate.
* @returns Whether the value is byte buffer or not.
*/
export declare function isBuffer(value: any): value is Buffer;
/**
* Validates that a value is an array.
*
* @param value - The value to validate.
* @returns Whether the value is an array or not.
*/
export declare function isArray<T>(value: any): value is T[];
/**
* Validates that a value is a non-empty array.
*
* @param value - The value to validate.
* @returns Whether the value is a non-empty array or not.
*/
export declare function isNonEmptyArray<T>(value: any): value is T[];
/**
* Validates that a value is a boolean.
*
* @param value - The value to validate.
* @returns Whether the value is a boolean or not.
*/
export declare function isBoolean(value: any): boolean;
/**
* Validates that a value is a number.
*
* @param value - The value to validate.
* @returns Whether the value is a number or not.
*/
export declare function isNumber(value: any): boolean;
/**
* Validates that a value is a string.
*
* @param value - The value to validate.
* @returns Whether the value is a string or not.
*/
export declare function isString(value: any): value is string;
/**
* Validates that a value is a base64 string.
*
* @param value - The value to validate.
* @returns Whether the value is a base64 string or not.
*/
export declare function isBase64String(value: any): boolean;
/**
* Validates that a value is a non-empty string.
*
* @param value - The value to validate.
* @returns Whether the value is a non-empty string or not.
*/
export declare function isNonEmptyString(value: any): value is string;
/**
* Validates that a value is a nullable object.
*
* @param value - The value to validate.
* @returns Whether the value is an object or not.
*/
export declare function isObject(value: any): boolean;
/**
* Validates that a value is a non-null object.
*
* @param value - The value to validate.
* @returns Whether the value is a non-null object or not.
*/
export declare function isNonNullObject<T>(value: T | null | undefined): value is T;
/**
* Validates that a string is a valid Firebase Auth uid.
*
* @param uid - The string to validate.
* @returns Whether the string is a valid Firebase Auth uid.
*/
export declare function isUid(uid: any): boolean;
/**
* Validates that a string is a valid Firebase Auth password.
*
* @param password - The password string to validate.
* @returns Whether the string is a valid Firebase Auth password.
*/
export declare function isPassword(password: any): boolean;
/**
* Validates that a string is a valid email.
*
* @param email - The string to validate.
* @returns Whether the string is valid email or not.
*/
export declare function isEmail(email: any): boolean;
/**
* Validates that a string is a valid phone number.
*
* @param phoneNumber - The string to validate.
* @returns Whether the string is a valid phone number or not.
*/
export declare function isPhoneNumber(phoneNumber: any): boolean;
/**
* Validates that a string is a valid ISO date string.
*
* @param dateString - The string to validate.
* @returns Whether the string is a valid ISO date string.
*/
export declare function isISODateString(dateString: any): boolean;
/**
* Validates that a string is a valid UTC date string.
*
* @param dateString - The string to validate.
* @returns Whether the string is a valid UTC date string.
*/
export declare function isUTCDateString(dateString: any): boolean;
/**
* Validates that a string is a valid web URL.
*
* @param urlStr - The string to validate.
* @returns Whether the string is valid web URL or not.
*/
export declare function isURL(urlStr: any): boolean;
/**
* Validates that the provided topic is a valid FCM topic name.
*
* @param topic - The topic to validate.
* @returns Whether the provided topic is a valid FCM topic name.
*/
export declare function isTopic(topic: any): boolean;
/**
* Validates that the provided string can be used as a task ID
* for Cloud Tasks.
*
* @param taskId - the task ID to validate.
* @returns Whether the provided task ID is valid.
*/
export declare function isTaskId(taskId: any): boolean;

View File

@@ -0,0 +1,285 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBuffer = isBuffer;
exports.isArray = isArray;
exports.isNonEmptyArray = isNonEmptyArray;
exports.isBoolean = isBoolean;
exports.isNumber = isNumber;
exports.isString = isString;
exports.isBase64String = isBase64String;
exports.isNonEmptyString = isNonEmptyString;
exports.isObject = isObject;
exports.isNonNullObject = isNonNullObject;
exports.isUid = isUid;
exports.isPassword = isPassword;
exports.isEmail = isEmail;
exports.isPhoneNumber = isPhoneNumber;
exports.isISODateString = isISODateString;
exports.isUTCDateString = isUTCDateString;
exports.isURL = isURL;
exports.isTopic = isTopic;
exports.isTaskId = isTaskId;
const url = require("url");
/**
* Validates that a value is a byte buffer.
*
* @param value - The value to validate.
* @returns Whether the value is byte buffer or not.
*/
function isBuffer(value) {
return value instanceof Buffer;
}
/**
* Validates that a value is an array.
*
* @param value - The value to validate.
* @returns Whether the value is an array or not.
*/
function isArray(value) {
return Array.isArray(value);
}
/**
* Validates that a value is a non-empty array.
*
* @param value - The value to validate.
* @returns Whether the value is a non-empty array or not.
*/
function isNonEmptyArray(value) {
return isArray(value) && value.length !== 0;
}
/**
* Validates that a value is a boolean.
*
* @param value - The value to validate.
* @returns Whether the value is a boolean or not.
*/
function isBoolean(value) {
return typeof value === 'boolean';
}
/**
* Validates that a value is a number.
*
* @param value - The value to validate.
* @returns Whether the value is a number or not.
*/
function isNumber(value) {
return typeof value === 'number' && !isNaN(value);
}
/**
* Validates that a value is a string.
*
* @param value - The value to validate.
* @returns Whether the value is a string or not.
*/
function isString(value) {
return typeof value === 'string';
}
/**
* Validates that a value is a base64 string.
*
* @param value - The value to validate.
* @returns Whether the value is a base64 string or not.
*/
function isBase64String(value) {
if (!isString(value)) {
return false;
}
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
}
/**
* Validates that a value is a non-empty string.
*
* @param value - The value to validate.
* @returns Whether the value is a non-empty string or not.
*/
function isNonEmptyString(value) {
return isString(value) && value !== '';
}
/**
* Validates that a value is a nullable object.
*
* @param value - The value to validate.
* @returns Whether the value is an object or not.
*/
function isObject(value) {
return typeof value === 'object' && !isArray(value);
}
/**
* Validates that a value is a non-null object.
*
* @param value - The value to validate.
* @returns Whether the value is a non-null object or not.
*/
function isNonNullObject(value) {
return isObject(value) && value !== null;
}
/**
* Validates that a string is a valid Firebase Auth uid.
*
* @param uid - The string to validate.
* @returns Whether the string is a valid Firebase Auth uid.
*/
function isUid(uid) {
return typeof uid === 'string' && uid.length > 0 && uid.length <= 128;
}
/**
* Validates that a string is a valid Firebase Auth password.
*
* @param password - The password string to validate.
* @returns Whether the string is a valid Firebase Auth password.
*/
function isPassword(password) {
// A password must be a string of at least 6 characters.
return typeof password === 'string' && password.length >= 6;
}
/**
* Validates that a string is a valid email.
*
* @param email - The string to validate.
* @returns Whether the string is valid email or not.
*/
function isEmail(email) {
if (typeof email !== 'string') {
return false;
}
// There must at least one character before the @ symbol and another after.
const re = /^[^@]+@[^@]+$/;
return re.test(email);
}
/**
* Validates that a string is a valid phone number.
*
* @param phoneNumber - The string to validate.
* @returns Whether the string is a valid phone number or not.
*/
function isPhoneNumber(phoneNumber) {
if (typeof phoneNumber !== 'string') {
return false;
}
// Phone number validation is very lax here. Backend will enforce E.164
// spec compliance and will normalize accordingly.
// The phone number string must be non-empty and starts with a plus sign.
const re1 = /^\+/;
// The phone number string must contain at least one alphanumeric character.
const re2 = /[\da-zA-Z]+/;
return re1.test(phoneNumber) && re2.test(phoneNumber);
}
/**
* Validates that a string is a valid ISO date string.
*
* @param dateString - The string to validate.
* @returns Whether the string is a valid ISO date string.
*/
function isISODateString(dateString) {
try {
return isNonEmptyString(dateString) &&
(new Date(dateString).toISOString() === dateString);
}
catch (e) {
return false;
}
}
/**
* Validates that a string is a valid UTC date string.
*
* @param dateString - The string to validate.
* @returns Whether the string is a valid UTC date string.
*/
function isUTCDateString(dateString) {
try {
return isNonEmptyString(dateString) &&
(new Date(dateString).toUTCString() === dateString);
}
catch (e) {
return false;
}
}
/**
* Validates that a string is a valid web URL.
*
* @param urlStr - The string to validate.
* @returns Whether the string is valid web URL or not.
*/
function isURL(urlStr) {
if (typeof urlStr !== 'string') {
return false;
}
// Lookup illegal characters.
const re = /[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i;
if (re.test(urlStr)) {
return false;
}
try {
const uri = url.parse(urlStr);
const scheme = uri.protocol;
const slashes = uri.slashes;
const hostname = uri.hostname;
const pathname = uri.pathname;
if ((scheme !== 'http:' && scheme !== 'https:') || !slashes) {
return false;
}
// Validate hostname: Can contain letters, numbers, underscore and dashes separated by a dot.
// Each zone must not start with a hyphen or underscore.
if (!hostname || !/^[a-zA-Z0-9]+[\w-]*([.]?[a-zA-Z0-9]+[\w-]*)*$/.test(hostname)) {
return false;
}
// Allow for pathnames: (/chars+)*/?
// Where chars can be a combination of: a-z A-Z 0-9 - _ . ~ ! $ & ' ( ) * + , ; = : @ %
const pathnameRe = /^(\/[\w\-.~!$'()*+,;=:@%]+)*\/?$/;
// Validate pathname.
if (pathname &&
pathname !== '/' &&
!pathnameRe.test(pathname)) {
return false;
}
// Allow any query string and hash as long as no invalid character is used.
}
catch (e) {
return false;
}
return true;
}
/**
* Validates that the provided topic is a valid FCM topic name.
*
* @param topic - The topic to validate.
* @returns Whether the provided topic is a valid FCM topic name.
*/
function isTopic(topic) {
if (typeof topic !== 'string') {
return false;
}
const VALID_TOPIC_REGEX = /^(\/topics\/)?(private\/)?[a-zA-Z0-9-_.~%]+$/;
return VALID_TOPIC_REGEX.test(topic);
}
/**
* Validates that the provided string can be used as a task ID
* for Cloud Tasks.
*
* @param taskId - the task ID to validate.
* @returns Whether the provided task ID is valid.
*/
function isTaskId(taskId) {
if (typeof taskId !== 'string') {
return false;
}
const VALID_TASK_ID_REGEX = /^[A-Za-z0-9_-]+$/;
return VALID_TASK_ID_REGEX.test(taskId);
}