dev testing

This commit is contained in:
2026-03-23 15:29:13 -04:00
parent 28dae0dc60
commit d772b7ec9c
5664 changed files with 863006 additions and 73 deletions

View File

@@ -0,0 +1,32 @@
/*! firebase-admin v12.7.0 */
/*!
* @license
* Copyright 2024 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 { PrefixedFirebaseError } from '../utils/error';
export declare const DATA_CONNECT_ERROR_CODE_MAPPING: {
[key: string]: DataConnectErrorCode;
};
export type DataConnectErrorCode = 'aborted' | 'invalid-argument' | 'invalid-credential' | 'internal-error' | 'permission-denied' | 'unauthenticated' | 'not-found' | 'unknown-error' | 'query-error';
/**
* Firebase Data Connect error code structure. This extends PrefixedFirebaseError.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
export declare class FirebaseDataConnectError extends PrefixedFirebaseError {
constructor(code: DataConnectErrorCode, message: string);
}

View File

@@ -0,0 +1,182 @@
/*! firebase-admin v12.7.0 */
"use strict";
/*!
* @license
* Copyright 2024 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.FirebaseDataConnectError = exports.DATA_CONNECT_ERROR_CODE_MAPPING = exports.DataConnectApiClient = void 0;
const api_request_1 = require("../utils/api-request");
const error_1 = require("../utils/error");
const utils = require("../utils/index");
const validator = require("../utils/validator");
// Data Connect backend constants
const DATA_CONNECT_HOST = 'https://firebasedataconnect.googleapis.com';
const DATA_CONNECT_API_URL_FORMAT = '{host}/v1alpha/projects/{projectId}/locations/{locationId}/services/{serviceId}:{endpointId}';
const EXECUTE_GRAPH_QL_ENDPOINT = 'executeGraphql';
const EXECUTE_GRAPH_QL_READ_ENDPOINT = 'executeGraphqlRead';
const DATA_CONNECT_CONFIG_HEADERS = {
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`
};
/**
* Class that facilitates sending requests to the Firebase Data Connect backend API.
*
* @internal
*/
class DataConnectApiClient {
constructor(connectorConfig, app) {
this.connectorConfig = connectorConfig;
this.app = app;
if (!validator.isNonNullObject(app) || !('options' in app)) {
throw new FirebaseDataConnectError(exports.DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT, 'First argument passed to getDataConnect() must be a valid Firebase app instance.');
}
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
}
/**
* Execute arbitrary GraphQL, including both read and write queries
*
* @param query - The GraphQL string to be executed.
* @param options - GraphQL Options
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
*/
async executeGraphql(query, options) {
return this.executeGraphqlHelper(query, EXECUTE_GRAPH_QL_ENDPOINT, options);
}
/**
* Execute arbitrary read-only GraphQL queries
*
* @param query - The GraphQL (read-only) string to be executed.
* @param options - GraphQL Options
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
* @throws FirebaseDataConnectError
*/
async executeGraphqlRead(query, options) {
return this.executeGraphqlHelper(query, EXECUTE_GRAPH_QL_READ_ENDPOINT, options);
}
async executeGraphqlHelper(query, endpoint, options) {
if (!validator.isNonEmptyString(query)) {
throw new FirebaseDataConnectError(exports.DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT, '`query` must be a non-empty string.');
}
if (typeof options !== 'undefined') {
if (!validator.isNonNullObject(options)) {
throw new FirebaseDataConnectError(exports.DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT, 'GraphqlOptions must be a non-null object');
}
}
const host = (process.env.DATA_CONNECT_EMULATOR_HOST || DATA_CONNECT_HOST);
const data = {
query,
...(options?.variables && { variables: options?.variables }),
...(options?.operationName && { operationName: options?.operationName }),
};
return this.getUrl(host, this.connectorConfig.location, this.connectorConfig.serviceId, endpoint)
.then(async (url) => {
const request = {
method: 'POST',
url,
headers: DATA_CONNECT_CONFIG_HEADERS,
data,
};
const resp = await this.httpClient.send(request);
if (resp.data.errors && validator.isNonEmptyArray(resp.data.errors)) {
const allMessages = resp.data.errors.map((error) => error.message).join(' ');
throw new FirebaseDataConnectError(exports.DATA_CONNECT_ERROR_CODE_MAPPING.QUERY_ERROR, allMessages);
}
return Promise.resolve({
data: resp.data.data,
});
})
.then((resp) => {
return resp;
})
.catch((err) => {
throw this.toFirebaseError(err);
});
}
async getUrl(host, locationId, serviceId, endpointId) {
return this.getProjectId()
.then((projectId) => {
const urlParams = {
host,
projectId,
locationId,
serviceId,
endpointId
};
const baseUrl = utils.formatString(DATA_CONNECT_API_URL_FORMAT, urlParams);
return utils.formatString(baseUrl);
});
}
getProjectId() {
if (this.projectId) {
return Promise.resolve(this.projectId);
}
return utils.findProjectId(this.app)
.then((projectId) => {
if (!validator.isNonEmptyString(projectId)) {
throw new FirebaseDataConnectError(exports.DATA_CONNECT_ERROR_CODE_MAPPING.UNKNOWN, 'Failed to determine project ID. Initialize the '
+ 'SDK with service account credentials or set project ID as an app option. '
+ 'Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.');
}
this.projectId = projectId;
return projectId;
});
}
toFirebaseError(err) {
if (err instanceof error_1.PrefixedFirebaseError) {
return err;
}
const response = err.response;
if (!response.isJson()) {
return new FirebaseDataConnectError(exports.DATA_CONNECT_ERROR_CODE_MAPPING.UNKNOWN, `Unexpected response with status: ${response.status} and body: ${response.text}`);
}
const error = response.data.error || {};
let code = exports.DATA_CONNECT_ERROR_CODE_MAPPING.UNKNOWN;
if (error.status && error.status in exports.DATA_CONNECT_ERROR_CODE_MAPPING) {
code = exports.DATA_CONNECT_ERROR_CODE_MAPPING[error.status];
}
const message = error.message || `Unknown server error: ${response.text}`;
return new FirebaseDataConnectError(code, message);
}
}
exports.DataConnectApiClient = DataConnectApiClient;
exports.DATA_CONNECT_ERROR_CODE_MAPPING = {
ABORTED: 'aborted',
INVALID_ARGUMENT: 'invalid-argument',
INVALID_CREDENTIAL: 'invalid-credential',
INTERNAL: 'internal-error',
PERMISSION_DENIED: 'permission-denied',
UNAUTHENTICATED: 'unauthenticated',
NOT_FOUND: 'not-found',
UNKNOWN: 'unknown-error',
QUERY_ERROR: 'query-error',
};
/**
* Firebase Data Connect error code structure. This extends PrefixedFirebaseError.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
class FirebaseDataConnectError extends error_1.PrefixedFirebaseError {
constructor(code, message) {
super('data-connect', code, message);
/* 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__ = FirebaseDataConnectError.prototype;
}
}
exports.FirebaseDataConnectError = FirebaseDataConnectError;

View File

@@ -0,0 +1,52 @@
/*! firebase-admin v12.7.0 */
/*!
* @license
* Copyright 2024 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.
*/
/**
* Interface representing a Data Connect connector configuration.
*/
export interface ConnectorConfig {
/**
* Location ID of the Data Connect service.
*/
location: string;
/**
* Service ID of the Data Connect service.
*/
serviceId: string;
}
/**
* Interface representing GraphQL response.
*/
export interface ExecuteGraphqlResponse<GraphqlResponse> {
/**
* Data payload of the GraphQL response.
*/
data: GraphqlResponse;
}
/**
* Interface representing GraphQL options.
*/
export interface GraphqlOptions<Variables> {
/**
* Values for GraphQL variables provided in this query or mutation.
*/
variables?: Variables;
/**
* The name of the GraphQL operation. Required only if `query` contains multiple operations.
*/
operationName?: string;
}

View File

@@ -0,0 +1,19 @@
/*! firebase-admin v12.7.0 */
"use strict";
/*!
* @license
* Copyright 2024 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 });

View File

@@ -0,0 +1,59 @@
/*! firebase-admin v12.7.0 */
/*!
* @license
* Copyright 2024 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 { ConnectorConfig, ExecuteGraphqlResponse, GraphqlOptions } from './data-connect-api';
export declare class DataConnectService {
private readonly appInternal;
private dataConnectInstances;
constructor(app: App);
getDataConnect(connectorConfig: ConnectorConfig): DataConnect;
/**
* Returns the app associated with this `DataConnectService` instance.
*
* @returns The app associated with this `DataConnectService` instance.
*/
get app(): App;
}
/**
* The Firebase `DataConnect` service interface.
*/
export declare class DataConnect {
readonly connectorConfig: ConnectorConfig;
readonly app: App;
private readonly client;
/**
* Execute an arbitrary GraphQL query or mutation
*
* @param query - The GraphQL query or mutation.
* @param options - Optional {@link GraphqlOptions} when executing a GraphQL query or mutation.
*
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
* @beta
*/
executeGraphql<GraphqlResponse, Variables>(query: string, options?: GraphqlOptions<Variables>): Promise<ExecuteGraphqlResponse<GraphqlResponse>>;
/**
* Execute an arbitrary read-only GraphQL query
*
* @param query - The GraphQL read-only query.
* @param options - Optional {@link GraphqlOptions} when executing a read-only GraphQL query.
*
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
* @beta
*/
executeGraphqlRead<GraphqlResponse, Variables>(query: string, options?: GraphqlOptions<Variables>): Promise<ExecuteGraphqlResponse<GraphqlResponse>>;
}

View File

@@ -0,0 +1,87 @@
/*! firebase-admin v12.7.0 */
"use strict";
/*!
* @license
* Copyright 2024 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.DataConnect = exports.DataConnectService = void 0;
const data_connect_api_client_internal_1 = require("./data-connect-api-client-internal");
class DataConnectService {
constructor(app) {
this.dataConnectInstances = new Map();
this.appInternal = app;
}
getDataConnect(connectorConfig) {
const id = `${connectorConfig.location}-${connectorConfig.serviceId}`;
const dc = this.dataConnectInstances.get(id);
if (typeof dc !== 'undefined') {
return dc;
}
const newInstance = new DataConnect(connectorConfig, this.appInternal);
this.dataConnectInstances.set(id, newInstance);
return newInstance;
}
/**
* Returns the app associated with this `DataConnectService` instance.
*
* @returns The app associated with this `DataConnectService` instance.
*/
get app() {
return this.appInternal;
}
}
exports.DataConnectService = DataConnectService;
/**
* The Firebase `DataConnect` service interface.
*/
class DataConnect {
/**
* @param connectorConfig - The connector configuration.
* @param app - The app for this `DataConnect` service.
* @constructor
* @internal
*/
constructor(connectorConfig, app) {
this.connectorConfig = connectorConfig;
this.app = app;
this.client = new data_connect_api_client_internal_1.DataConnectApiClient(connectorConfig, app);
}
/**
* Execute an arbitrary GraphQL query or mutation
*
* @param query - The GraphQL query or mutation.
* @param options - Optional {@link GraphqlOptions} when executing a GraphQL query or mutation.
*
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
* @beta
*/
executeGraphql(query, options) {
return this.client.executeGraphql(query, options);
}
/**
* Execute an arbitrary read-only GraphQL query
*
* @param query - The GraphQL read-only query.
* @param options - Optional {@link GraphqlOptions} when executing a read-only GraphQL query.
*
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
* @beta
*/
executeGraphqlRead(query, options) {
return this.client.executeGraphqlRead(query, options);
}
}
exports.DataConnect = DataConnect;

View File

@@ -0,0 +1,61 @@
/*! firebase-admin v12.7.0 */
/*!
* @license
* Copyright 2024 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.
*/
/**
* Firebase Data Connect service.
*
* @packageDocumentation
*/
import { App } from '../app';
import { DataConnect } from './data-connect';
import { ConnectorConfig } from './data-connect-api';
export { GraphqlOptions, ExecuteGraphqlResponse, ConnectorConfig, } from './data-connect-api';
export { DataConnect, } from './data-connect';
/**
* Gets the {@link DataConnect} service with the provided connector configuration
* for the default app or a given app.
*
* `getDataConnect(connectorConfig)` can be called with no app argument to access the default
* app's `DataConnect` service or as `getDataConnect(connectorConfig, app)` to access the
* `DataConnect` service associated with a specific app.
*
* @example
* ```javascript
* const connectorConfig: ConnectorConfig = {
* location: 'us-west2',
* serviceId: 'my-service',
* };
*
* // Get the `DataConnect` service for the default app
* const defaultDataConnect = getDataConnect(connectorConfig);
* ```
*
* @example
* ```javascript
* // Get the `DataConnect` service for a given app
* const otherDataConnect = getDataConnect(connectorConfig, otherApp);
* ```
*
* @param connectorConfig - Connector configuration for the `DataConnect` service.
*
* @param app - Optional app for which to return the `DataConnect` service.
* If not provided, the default `DataConnect` service is returned.
*
* @returns The default `DataConnect` service with the provided connector configuration
* if no app is provided, or the `DataConnect` service associated with the provided app.
*/
export declare function getDataConnect(connectorConfig: ConnectorConfig, app?: App): DataConnect;

View File

@@ -0,0 +1,71 @@
/*! firebase-admin v12.7.0 */
"use strict";
/*!
* @license
* Copyright 2024 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.getDataConnect = exports.DataConnect = void 0;
/**
* Firebase Data Connect service.
*
* @packageDocumentation
*/
const app_1 = require("../app");
const data_connect_1 = require("./data-connect");
var data_connect_2 = require("./data-connect");
Object.defineProperty(exports, "DataConnect", { enumerable: true, get: function () { return data_connect_2.DataConnect; } });
/**
* Gets the {@link DataConnect} service with the provided connector configuration
* for the default app or a given app.
*
* `getDataConnect(connectorConfig)` can be called with no app argument to access the default
* app's `DataConnect` service or as `getDataConnect(connectorConfig, app)` to access the
* `DataConnect` service associated with a specific app.
*
* @example
* ```javascript
* const connectorConfig: ConnectorConfig = {
* location: 'us-west2',
* serviceId: 'my-service',
* };
*
* // Get the `DataConnect` service for the default app
* const defaultDataConnect = getDataConnect(connectorConfig);
* ```
*
* @example
* ```javascript
* // Get the `DataConnect` service for a given app
* const otherDataConnect = getDataConnect(connectorConfig, otherApp);
* ```
*
* @param connectorConfig - Connector configuration for the `DataConnect` service.
*
* @param app - Optional app for which to return the `DataConnect` service.
* If not provided, the default `DataConnect` service is returned.
*
* @returns The default `DataConnect` service with the provided connector configuration
* if no app is provided, or the `DataConnect` service associated with the provided app.
*/
function getDataConnect(connectorConfig, app) {
if (typeof app === 'undefined') {
app = (0, app_1.getApp)();
}
const firebaseApp = app;
const dataConnectService = firebaseApp.getOrInitService('dataConnect', (app) => new data_connect_1.DataConnectService(app));
return dataConnectService.getDataConnect(connectorConfig);
}
exports.getDataConnect = getDataConnect;