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,30 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2022 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';
type ExtensionsErrorCode = 'invalid-argument' | 'not-found' | 'forbidden' | 'internal-error' | 'unknown-error';
/**
* Firebase Extensions error code structure. This extends PrefixedFirebaseError.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
export declare class FirebaseExtensionsError extends PrefixedFirebaseError {
constructor(code: ExtensionsErrorCode, message: string);
}
export {};

View File

@@ -0,0 +1,105 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2022 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.FirebaseExtensionsError = exports.ExtensionsApiClient = void 0;
const api_request_1 = require("../utils/api-request");
const error_1 = require("../utils/error");
const validator = require("../utils/validator");
const utils = require("../utils");
const FIREBASE_FUNCTIONS_CONFIG_HEADERS = {
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`
};
const EXTENSIONS_API_VERSION = 'v1beta';
// Note - use getExtensionsApiUri() instead so that changing environments is consistent.
const EXTENSIONS_URL = 'https://firebaseextensions.googleapis.com';
/**
* Class that facilitates sending requests to the Firebase Extensions backend API.
*
* @internal
*/
class ExtensionsApiClient {
constructor(app) {
this.app = app;
if (!validator.isNonNullObject(app) || !('options' in app)) {
throw new error_1.FirebaseAppError('invalid-argument', 'First argument passed to getExtensions() must be a valid Firebase app instance.');
}
this.httpClient = new api_request_1.AuthorizedHttpClient(this.app);
}
async updateRuntimeData(projectId, instanceId, runtimeData) {
const url = this.getRuntimeDataUri(projectId, instanceId);
const request = {
method: 'PATCH',
url,
headers: FIREBASE_FUNCTIONS_CONFIG_HEADERS,
data: runtimeData,
};
try {
const res = await this.httpClient.send(request);
return res.data;
}
catch (err) {
throw this.toFirebaseError(err);
}
}
getExtensionsApiUri() {
return process.env['FIREBASE_EXT_URL'] ?? EXTENSIONS_URL;
}
getRuntimeDataUri(projectId, instanceId) {
return `${this.getExtensionsApiUri()}/${EXTENSIONS_API_VERSION}/projects/${projectId}/instances/${instanceId}/runtimeData`;
}
toFirebaseError(err) {
if (err instanceof error_1.PrefixedFirebaseError) {
return err;
}
const response = err.response;
if (!response?.isJson()) {
return new FirebaseExtensionsError('unknown-error', `Unexpected response with status: ${response.status} and body: ${response.text}`);
}
const error = response.data?.error;
const message = error?.message || `Unknown server error: ${response.text}`;
switch (error.code) {
case 403:
return new FirebaseExtensionsError('forbidden', message);
case 404:
return new FirebaseExtensionsError('not-found', message);
case 500:
return new FirebaseExtensionsError('internal-error', message);
}
return new FirebaseExtensionsError('unknown-error', message);
}
}
exports.ExtensionsApiClient = ExtensionsApiClient;
/**
* Firebase Extensions error code structure. This extends PrefixedFirebaseError.
*
* @param code - The error code.
* @param message - The error message.
* @constructor
*/
class FirebaseExtensionsError extends error_1.PrefixedFirebaseError {
constructor(code, message) {
super('Extensions', 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__ = FirebaseExtensionsError.prototype;
}
}
exports.FirebaseExtensionsError = FirebaseExtensionsError;

View File

@@ -0,0 +1,44 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2022 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.
*/
/**
* `SettableProcessingState` represents all the processing states that can be set
* on an Extension instance's runtime data.
*
* @remarks
* You can set the following states:
*
* - `NONE`: No relevant lifecycle event work has been done.
* Set this to clear out old statuses.
*
* - `PROCESSING_COMPLETE`: Lifecycle event work completed with no errors.
*
* - `PROCESSING_WARNING`: Lifecycle event work succeeded partially, or
* something happened that the user should be warned about.
*
* - `PROCESSING_FAILED`: Lifecycle event work failed completely, but the
* instance will still work correctly going forward.
*
* If the extension instance is in a broken state due to errors, instead call
* {@link Runtime.setFatalError}.
*
* The "processing" state gets set automatically when a lifecycle event handler
* starts; you can't set it explicitly.
* To report the ongoing status of an extension's function, use `console.log`
* or the Cloud Functions logger SDK.
*/
export type SettableProcessingState = 'NONE' | 'PROCESSING_COMPLETE' | 'PROCESSING_WARNING' | 'PROCESSING_FAILED';

View File

@@ -0,0 +1,19 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2022 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,73 @@
/*! firebase-admin v13.5.0 */
/*!
* @license
* Copyright 2022 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 { SettableProcessingState } from './extensions-api';
/**
* The Firebase `Extensions` service interface.
*/
export declare class Extensions {
readonly app: App;
private readonly client;
/**
* The runtime() method returns a new Runtime, which provides methods to modify an extension instance's runtime data.
*
* @remarks
* This method will throw an error if called outside an Extensions environment.
*
* @returns A new {@link Runtime} object.
*/
runtime(): Runtime;
}
/**
* Runtime provides methods to modify an extension instance's runtime data.
*/
export declare class Runtime {
private projectId;
private extensionInstanceId;
private readonly client;
/**
* Sets the processing state of an extension instance.
*
* @remarks
* Use this method to report the results of a lifecycle event handler.
*
* If the lifecycle event failed & the extension instance will no longer work
* correctly, use {@link Runtime.setFatalError} instead.
*
* To report the status of function calls other than lifecycle event handlers,
* use `console.log` or the Cloud Functions logger SDK.
*
* @param state - The state to set the instance to.
* @param detailMessage - A message explaining the results of the lifecycle function.
*/
setProcessingState(state: SettableProcessingState, detailMessage: string): Promise<void>;
/**
* Reports a fatal error while running a lifecycle event handler.
*
* @remarks
* Call this method when a lifecycle event handler fails in a way that makes
* the Instance inoperable.
* If the lifecycle event failed but the instance will still work as expected,
* call `setProcessingState` with the "PROCESSING_WARNING" or
* "PROCESSING_FAILED" state instead.
*
* @param errorMessage - A message explaining what went wrong and how to fix it.
*/
setFatalError(errorMessage: string): Promise<void>;
private getProjectId;
}

View File

@@ -0,0 +1,122 @@
/*! firebase-admin v13.5.0 */
"use strict";
/*!
* @license
* Copyright 2022 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.Runtime = exports.Extensions = void 0;
const extensions_api_client_internal_1 = require("./extensions-api-client-internal");
const validator = require("../utils/validator");
/**
* The Firebase `Extensions` service interface.
*/
class Extensions {
/**
* @param app - The app for this `Extensions` service.
* @constructor
* @internal
*/
constructor(app) {
this.app = app;
this.client = new extensions_api_client_internal_1.ExtensionsApiClient(app);
}
/**
* The runtime() method returns a new Runtime, which provides methods to modify an extension instance's runtime data.
*
* @remarks
* This method will throw an error if called outside an Extensions environment.
*
* @returns A new {@link Runtime} object.
*/
runtime() {
return new Runtime(this.client);
}
}
exports.Extensions = Extensions;
/**
* Runtime provides methods to modify an extension instance's runtime data.
*/
class Runtime {
/**
* @param client - The API client for this `Runtime` service.
* @constructor
* @internal
*/
constructor(client) {
this.projectId = this.getProjectId();
if (!validator.isNonEmptyString(process.env['EXT_INSTANCE_ID'])) {
throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'Runtime is only available from within a running Extension instance.');
}
this.extensionInstanceId = process.env['EXT_INSTANCE_ID'];
if (!validator.isNonNullObject(client) || !('updateRuntimeData' in client)) {
throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'Must provide a valid ExtensionsApiClient instance to create a new Runtime.');
}
this.client = client;
}
/**
* Sets the processing state of an extension instance.
*
* @remarks
* Use this method to report the results of a lifecycle event handler.
*
* If the lifecycle event failed & the extension instance will no longer work
* correctly, use {@link Runtime.setFatalError} instead.
*
* To report the status of function calls other than lifecycle event handlers,
* use `console.log` or the Cloud Functions logger SDK.
*
* @param state - The state to set the instance to.
* @param detailMessage - A message explaining the results of the lifecycle function.
*/
async setProcessingState(state, detailMessage) {
await this.client.updateRuntimeData(this.projectId, this.extensionInstanceId, {
processingState: {
state,
detailMessage,
},
});
}
/**
* Reports a fatal error while running a lifecycle event handler.
*
* @remarks
* Call this method when a lifecycle event handler fails in a way that makes
* the Instance inoperable.
* If the lifecycle event failed but the instance will still work as expected,
* call `setProcessingState` with the "PROCESSING_WARNING" or
* "PROCESSING_FAILED" state instead.
*
* @param errorMessage - A message explaining what went wrong and how to fix it.
*/
async setFatalError(errorMessage) {
if (!validator.isNonEmptyString(errorMessage)) {
throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'errorMessage must not be empty');
}
await this.client.updateRuntimeData(this.projectId, this.extensionInstanceId, {
fatalError: {
errorMessage,
},
});
}
getProjectId() {
const projectId = process.env['PROJECT_ID'];
if (!validator.isNonEmptyString(projectId)) {
throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'PROJECT_ID must not be undefined in Extensions runtime environment');
}
return projectId;
}
}
exports.Runtime = Runtime;

View File

@@ -0,0 +1,53 @@
/*! 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.
*/
/**
* Firebase Extensions service.
*
* @packageDocumentation
*/
import { App } from '../app';
import { Extensions } from './extensions';
export { Extensions, Runtime } from './extensions';
export { SettableProcessingState } from './extensions-api';
/**
* Gets the {@link Extensions} service for the default app
* or a given app.
*
* `getExtensions()` can be called with no arguments to access the default
* app's `Extensions` service or as `getExtensions(app)` to access the
* `Extensions` service associated with a specific app.
*
* @example
* ```javascript
* // Get the `Extensions` service for the default app
* const defaultExtensions = getExtensions();
* ```
*
* @example
* ```javascript
* // Get the `Extensions` service for a given app
* const otherExtensions = getExtensions(otherApp);
* ```
*
* @param app - Optional app for which to return the `Extensions` service.
* If not provided, the default `Extensions` service is returned.
*
* @returns The default `Extensions` service if no app is provided, or the `Extensions`
* service associated with the provided app.
*/
export declare function getExtensions(app?: App): Extensions;

View File

@@ -0,0 +1,64 @@
/*! 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.Runtime = exports.Extensions = void 0;
exports.getExtensions = getExtensions;
/**
* Firebase Extensions service.
*
* @packageDocumentation
*/
const app_1 = require("../app");
const extensions_1 = require("./extensions");
var extensions_2 = require("./extensions");
Object.defineProperty(exports, "Extensions", { enumerable: true, get: function () { return extensions_2.Extensions; } });
Object.defineProperty(exports, "Runtime", { enumerable: true, get: function () { return extensions_2.Runtime; } });
/**
* Gets the {@link Extensions} service for the default app
* or a given app.
*
* `getExtensions()` can be called with no arguments to access the default
* app's `Extensions` service or as `getExtensions(app)` to access the
* `Extensions` service associated with a specific app.
*
* @example
* ```javascript
* // Get the `Extensions` service for the default app
* const defaultExtensions = getExtensions();
* ```
*
* @example
* ```javascript
* // Get the `Extensions` service for a given app
* const otherExtensions = getExtensions(otherApp);
* ```
*
* @param app - Optional app for which to return the `Extensions` service.
* If not provided, the default `Extensions` service is returned.
*
* @returns The default `Extensions` service if no app is provided, or the `Extensions`
* service associated with the provided app.
*/
function getExtensions(app) {
if (typeof app === 'undefined') {
app = (0, app_1.getApp)();
}
const firebaseApp = app;
return firebaseApp.getOrInitService('extensions', (app) => new extensions_1.Extensions(app));
}