This commit is contained in:
girinb
2025-05-29 15:41:51 +09:00
parent a1bd4f87a1
commit 485098cd1a
5611 changed files with 881685 additions and 0 deletions

View File

@@ -0,0 +1,241 @@
import { CloudFunction, EventContext } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";
/**
* Registers a function to handle analytics events.
*
* @param analyticsEventType Name of the analytics event type to which
* this Cloud Function is scoped.
*
* @returns Analytics event builder interface.
*/
export declare function event(analyticsEventType: string): AnalyticsEventBuilder;
/**
* The Firebase Analytics event builder interface.
*
* Access via `functions.analytics.event()`.
*/
export declare class AnalyticsEventBuilder {
private triggerResource;
private options;
/** @hidden */
constructor(triggerResource: () => string, options: DeploymentOptions);
/**
* Event handler that fires every time a Firebase Analytics event occurs.
*
* @param handler Event handler that fires every time a Firebase Analytics event
* occurs.
*
* @returns A function that you can export and deploy.
*/
onLog(handler: (event: AnalyticsEvent, context: EventContext) => PromiseLike<any> | any): CloudFunction<AnalyticsEvent>;
}
/** Interface representing a Firebase Analytics event that was logged for a specific user. */
export declare class AnalyticsEvent {
/**
* The date on which the event.was logged.
* (`YYYYMMDD` format in the registered timezone of your app).
*/
reportingDate: string;
/** The name of the event. */
name: string;
/**
* A map of parameters and their values associated with the event.
*
* Note: Values in this map are cast to the most appropriate type. Due to
* the nature of JavaScript's number handling, this might entail a loss of
* precision in cases of very large integers.
*/
params: {
[key: string]: any;
};
/** UTC client time when the event happened. */
logTime: string;
/** UTC client time when the previous event happened. */
previousLogTime?: string;
/** Value parameter in USD. */
valueInUSD?: number;
/** User-related dimensions. */
user?: UserDimensions;
/** @hidden */
constructor(wireFormat: any);
}
/**
* Interface representing the user who triggered the events.
*/
export declare class UserDimensions {
/**
* The user ID set via the `setUserId` API.
* [Android](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.html#setUserId(java.lang.String))
* [iOS](https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#/c:objc(cs)FIRAnalytics(cm)setUserID)
*/
userId?: string;
/** The time (in UTC) at which the user first opened the app. */
firstOpenTime?: string;
/**
* A map of user properties set with the
* [`setUserProperty`](https://firebase.google.com/docs/analytics/android/properties) API.
*
* All values are [`UserPropertyValue`](providers_analytics_.userpropertyvalue) objects.
*/
userProperties: {
[key: string]: UserPropertyValue;
};
/** Device information. */
deviceInfo: DeviceInfo;
/** User's geographic information. */
geoInfo: GeoInfo;
/** App information. */
appInfo?: AppInfo;
/** Information regarding the bundle in which these events were uploaded. */
bundleInfo: ExportBundleInfo;
/** @hidden */
constructor(wireFormat: any);
}
/** Predefined or custom properties stored on the client side. */
export declare class UserPropertyValue {
/** The last set value of a user property. */
value: string;
/** UTC client time when the user property was last set. */
setTime: string;
/** @hidden */
constructor(wireFormat: any);
}
/**
* Interface representing the device that triggered these
* Firebase Analytics events.
*/
export interface DeviceInfo {
/**
* Device category.
*
* Examples: "tablet" or "mobile".
*/
deviceCategory?: string;
/**
* Device brand name.
*
* Examples: "Samsung", "HTC"
*/
mobileBrandName?: string;
/**
* Device model name in human-readable format.
*
* Example: "iPhone 7"
*/
mobileModelName?: string;
/**
* Device marketing name.
*
* Example: "Galaxy S4 Mini"
*/
mobileMarketingName?: string;
/**
* Device model, as read from the OS.
*
* Example: "iPhone9,1"
*/
deviceModel?: string;
/**
* Device OS version when data capture ended.
*
* Example: "4.4.2"
*/
platformVersion?: string;
/**
* Vendor specific device identifier. This is IDFV on iOS. Not used for Android.
*
* Example: '599F9C00-92DC-4B5C-9464-7971F01F8370'
*/
deviceId?: string;
/**
* The type of the [`resettable_device_id`](https://support.google.com/dfp_premium/answer/6238701?hl=en)
* is IDFA on iOS (when available) and AdId on Android.
*
* Example: "71683BF9-FA3B-4B0D-9535-A1F05188BAF3"
*/
resettableDeviceId?: string;
/**
* The user language in language-country format, where language is an ISO 639
* value and country is an ISO 3166 value.
*
* Examples: "en-us", "en-za", "zh-tw", "jp"
*/
userDefaultLanguage: string;
/**
* The time zone of the device when data was uploaded, as seconds skew from UTC.
* Use this to calculate the device's local time for
* [`EventContext.timestamp`](cloud_functions_eventcontext.html#timestamp).
*/
deviceTimeZoneOffsetSeconds: number;
/**
* The device's Limit Ad Tracking setting.
* When `true`, you cannot use `resettableDeviceId` for remarketing, demographics or influencing ads serving
* behaviour. However, you can use `resettableDeviceId` for conversion tracking and campaign attribution.
*/
limitedAdTracking: boolean;
}
/** Interface representing the geographic origin of the events. */
export interface GeoInfo {
/**
* The geographic continent.
*
* Example: "South America".
*/
continent?: string;
/**
* The geographic country.
*
* Example: "Brazil".
*/
country?: string;
/**
* The geographic region.
*
* Example: "State of Sao Paulo".
*/
region?: string;
/**
* The geographic city.
*
* Example: "Sao Paulo".
*/
city?: string;
}
/** Interface representing the application that triggered these events. */
export interface AppInfo {
/**
* The app's version name.
*
* Examples: "1.0", "4.3.1.1.213361", "2.3 (1824253)", "v1.8b22p6".
*/
appVersion?: string;
/**
* Unique ID for this instance of the app.
*
* Example: "71683BF9FA3B4B0D9535A1F05188BAF3".
*/
appInstanceId: string;
/**
* The identifier of the store that installed the app.
*
* Examples: "com.sec.android.app.samsungapps", "com.amazon.venezia", "com.nokia.nstore".
*/
appStore?: string;
/**
* The app platform.
*
* Examples: "ANDROID", "IOS".
*/
appPlatform: string;
/** Unique application identifier within an app store. */
appId?: string;
}
/** Interface representing the bundle these events were uploaded to. */
export declare class ExportBundleInfo {
/** Monotonically increasing index for each bundle set by the Analytics SDK. */
bundleSequenceId: number;
/** Timestamp offset (in milliseconds) between collection time and upload time. */
serverTimestampOffset: number;
/** @hidden */
constructor(wireFormat: any);
}

View File

@@ -0,0 +1,247 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExportBundleInfo = exports.UserPropertyValue = exports.UserDimensions = exports.AnalyticsEvent = exports.AnalyticsEventBuilder = exports._eventWithOptions = exports.event = exports.service = exports.provider = void 0;
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.provider = "google.analytics";
/** @internal */
exports.service = "app-measurement.com";
/**
* Registers a function to handle analytics events.
*
* @param analyticsEventType Name of the analytics event type to which
* this Cloud Function is scoped.
*
* @returns Analytics event builder interface.
*/
function event(analyticsEventType) {
return _eventWithOptions(analyticsEventType, {});
}
exports.event = event;
/** @internal */
function _eventWithOptions(analyticsEventType, options) {
return new AnalyticsEventBuilder(() => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
return "projects/" + process.env.GCLOUD_PROJECT + "/events/" + analyticsEventType;
}, options);
}
exports._eventWithOptions = _eventWithOptions;
/**
* The Firebase Analytics event builder interface.
*
* Access via `functions.analytics.event()`.
*/
class AnalyticsEventBuilder {
/** @hidden */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
/**
* Event handler that fires every time a Firebase Analytics event occurs.
*
* @param handler Event handler that fires every time a Firebase Analytics event
* occurs.
*
* @returns A function that you can export and deploy.
*/
onLog(handler) {
const dataConstructor = (raw) => {
return new AnalyticsEvent(raw.data);
};
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
eventType: "event.log",
service: exports.service,
legacyEventType: `providers/google.firebase.analytics/eventTypes/event.log`,
triggerResource: this.triggerResource,
dataConstructor,
options: this.options,
});
}
}
exports.AnalyticsEventBuilder = AnalyticsEventBuilder;
/** Interface representing a Firebase Analytics event that was logged for a specific user. */
class AnalyticsEvent {
/** @hidden */
constructor(wireFormat) {
this.params = {}; // In case of absent field, show empty (not absent) map.
if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
// If there's an eventDim, there'll always be exactly one.
const eventDim = wireFormat.eventDim[0];
copyField(eventDim, this, "name");
copyField(eventDim, this, "params", (p) => mapKeys(p, unwrapValue));
copyFieldTo(eventDim, this, "valueInUsd", "valueInUSD");
copyFieldTo(eventDim, this, "date", "reportingDate");
copyTimestampToString(eventDim, this, "timestampMicros", "logTime");
copyTimestampToString(eventDim, this, "previousTimestampMicros", "previousLogTime");
}
copyFieldTo(wireFormat, this, "userDim", "user", (dim) => new UserDimensions(dim));
}
}
exports.AnalyticsEvent = AnalyticsEvent;
/**
* Interface representing the user who triggered the events.
*/
class UserDimensions {
/** @hidden */
constructor(wireFormat) {
// These are interfaces or primitives, no transformation needed.
copyFields(wireFormat, this, ["userId", "deviceInfo", "geoInfo", "appInfo"]);
// The following fields do need transformations of some sort.
copyTimestampToString(wireFormat, this, "firstOpenTimestampMicros", "firstOpenTime");
this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
copyField(wireFormat, this, "userProperties", (r) => {
const entries = Object.entries(r).map(([k, v]) => [k, new UserPropertyValue(v)]);
return Object.fromEntries(entries);
});
copyField(wireFormat, this, "bundleInfo", (r) => new ExportBundleInfo(r));
// BUG(36000368) Remove when no longer necessary
/* tslint:disable:no-string-literal */
if (!this.userId && this.userProperties["user_id"]) {
this.userId = this.userProperties["user_id"].value;
}
/* tslint:enable:no-string-literal */
}
}
exports.UserDimensions = UserDimensions;
/** Predefined or custom properties stored on the client side. */
class UserPropertyValue {
/** @hidden */
constructor(wireFormat) {
copyField(wireFormat, this, "value", unwrapValueAsString);
copyTimestampToString(wireFormat, this, "setTimestampUsec", "setTime");
}
}
exports.UserPropertyValue = UserPropertyValue;
/** Interface representing the bundle these events were uploaded to. */
class ExportBundleInfo {
/** @hidden */
constructor(wireFormat) {
copyField(wireFormat, this, "bundleSequenceId");
copyTimestampToMillis(wireFormat, this, "serverTimestampOffsetMicros", "serverTimestampOffset");
}
}
exports.ExportBundleInfo = ExportBundleInfo;
/** @hidden */
function copyFieldTo(from, to, fromField, toField, transform) {
if (typeof from[fromField] === "undefined") {
return;
}
if (transform) {
to[toField] = transform(from[fromField]);
return;
}
to[toField] = from[fromField];
}
/** @hidden */
function copyField(from, to, field, transform = (from) => from) {
copyFieldTo(from, to, field, field, transform);
}
/** @hidden */
function copyFields(from, to, fields) {
for (const field of fields) {
copyField(from, to, field);
}
}
function mapKeys(obj, transform) {
const entries = Object.entries(obj).map(([k, v]) => [k, transform(v)]);
return Object.fromEntries(entries);
}
// The incoming payload will have fields like:
// {
// 'myInt': {
// 'intValue': '123'
// },
// 'myDouble': {
// 'doubleValue': 1.0
// },
// 'myFloat': {
// 'floatValue': 1.1
// },
// 'myString': {
// 'stringValue': 'hi!'
// }
// }
//
// The following method will remove these four types of 'xValue' fields, flattening them
// to just their values, as a string:
// {
// 'myInt': '123',
// 'myDouble': '1.0',
// 'myFloat': '1.1',
// 'myString': 'hi!'
// }
//
// Note that while 'intValue' will have a quoted payload, 'doubleValue' and 'floatValue' will not. This
// is due to the encoding library, which renders int64 values as strings to avoid loss of precision. This
// method always returns a string, similarly to avoid loss of precision, unlike the less-conservative
// 'unwrapValue' method just below.
/** @hidden */
function unwrapValueAsString(wrapped) {
const key = Object.keys(wrapped)[0];
return wrapped[key].toString();
}
// Ditto as the method above, but returning the values in the idiomatic JavaScript type (string for strings,
// number for numbers):
// {
// 'myInt': 123,
// 'myDouble': 1.0,
// 'myFloat': 1.1,
// 'myString': 'hi!'
// }
//
// The field names in the incoming xValue fields identify the type a value has, which for JavaScript's
// purposes can be divided into 'number' versus 'string'. This method will render all the numbers as
// JavaScript's 'number' type, since we prefer using idiomatic types. Note that this may lead to loss
// in precision for int64 fields, so use with care.
/** @hidden */
const xValueNumberFields = ["intValue", "floatValue", "doubleValue"];
/** @hidden */
function unwrapValue(wrapped) {
const key = Object.keys(wrapped)[0];
const value = unwrapValueAsString(wrapped);
return xValueNumberFields.includes(key) ? Number(value) : value;
}
// The JSON payload delivers timestamp fields as strings of timestamps denoted in microseconds.
// The JavaScript convention is to use numbers denoted in milliseconds. This method
// makes it easy to convert a field of one type into the other.
/** @hidden */
function copyTimestampToMillis(from, to, fromName, toName) {
if (from[fromName] !== undefined) {
to[toName] = Math.round(from[fromName] / 1000);
}
}
// The JSON payload delivers timestamp fields as strings of timestamps denoted in microseconds.
// In our SDK, we'd like to present timestamp as ISO-format strings. This method makes it easy
// to convert a field of one type into the other.
/** @hidden */
function copyTimestampToString(from, to, fromName, toName) {
if (from[fromName] !== undefined) {
to[toName] = new Date(from[fromName] / 1000).toISOString();
}
}

View File

@@ -0,0 +1,73 @@
import { AuthEventContext, AuthUserRecord, BeforeCreateResponse, BeforeEmailResponse, BeforeSignInResponse, BeforeSmsResponse, HttpsError, MaybeAsync, UserInfo, UserRecord, userRecordConstructor, UserRecordMetadata } from "../../common/providers/identity";
import { BlockingFunction, CloudFunction, EventContext } from "../cloud-functions";
export { UserRecord, UserInfo, UserRecordMetadata, userRecordConstructor };
export { HttpsError };
/**
* Options for Auth blocking function.
*/
export interface UserOptions {
/** Options to set configuration at the resource level for blocking functions. */
blockingOptions?: {
/** Pass the ID Token credential to the function. */
idToken?: boolean;
/** Pass the Access Token credential to the function. */
accessToken?: boolean;
/** Pass the Refresh Token credential to the function. */
refreshToken?: boolean;
};
}
/**
* Handles events related to Firebase Auth users events.
*
* @param userOptions - Resource level options
* @returns UserBuilder - Builder used to create functions for Firebase Auth user lifecycle events
*
* @public
*/
export declare function user(userOptions?: UserOptions): UserBuilder;
/**
* Builder used to create functions for Firebase Auth user lifecycle events.
* @public
*/
export declare class UserBuilder {
private triggerResource;
private options;
private userOptions?;
private static dataConstructor;
/**
* Responds to the creation of a Firebase Auth user.
*
* @param handler Event handler that responds to the creation of a Firebase Auth user.
*
* @public
*/
onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
/**
* Responds to the deletion of a Firebase Auth user.
*
* @param handler Event handler that responds to the deletion of a Firebase Auth user.
*
* @public
*/
onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
/**
* Blocks request to create a Firebase Auth user.
*
* @param handler Event handler that blocks creation of a Firebase Auth user.
*
* @public
*/
beforeCreate(handler: (user: AuthUserRecord, context: AuthEventContext) => MaybeAsync<BeforeCreateResponse | void>): BlockingFunction;
/**
* Blocks request to sign-in a Firebase Auth user.
*
* @param handler Event handler that blocks sign-in of a Firebase Auth user.
*
* @public
*/
beforeSignIn(handler: (user: AuthUserRecord, context: AuthEventContext) => MaybeAsync<BeforeSignInResponse | void>): BlockingFunction;
beforeEmail(handler: (context: AuthEventContext) => MaybeAsync<BeforeEmailResponse | void>): BlockingFunction;
beforeSms(handler: (context: AuthEventContext) => MaybeAsync<BeforeSmsResponse | void>): BlockingFunction;
private onOperation;
private beforeOperation;
}

View File

@@ -0,0 +1,174 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserBuilder = exports._userWithOptions = exports.user = exports.service = exports.provider = exports.HttpsError = exports.userRecordConstructor = exports.UserRecordMetadata = void 0;
const identity_1 = require("../../common/providers/identity");
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
Object.defineProperty(exports, "userRecordConstructor", { enumerable: true, get: function () { return identity_1.userRecordConstructor; } });
Object.defineProperty(exports, "UserRecordMetadata", { enumerable: true, get: function () { return identity_1.UserRecordMetadata; } });
const cloud_functions_1 = require("../cloud-functions");
const manifest_1 = require("../../runtime/manifest");
/** @internal */
exports.provider = "google.firebase.auth";
/** @internal */
exports.service = "firebaseauth.googleapis.com";
/**
* Handles events related to Firebase Auth users events.
*
* @param userOptions - Resource level options
* @returns UserBuilder - Builder used to create functions for Firebase Auth user lifecycle events
*
* @public
*/
function user(userOptions) {
return _userWithOptions({}, userOptions || {});
}
exports.user = user;
/** @internal */
function _userWithOptions(options, userOptions) {
return new UserBuilder(() => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
return "projects/" + process.env.GCLOUD_PROJECT;
}, options, userOptions);
}
exports._userWithOptions = _userWithOptions;
/**
* Builder used to create functions for Firebase Auth user lifecycle events.
* @public
*/
class UserBuilder {
static dataConstructor(raw) {
return (0, identity_1.userRecordConstructor)(raw.data);
}
/* @internal */
constructor(triggerResource, options, userOptions) {
this.triggerResource = triggerResource;
this.options = options;
this.userOptions = userOptions;
}
/**
* Responds to the creation of a Firebase Auth user.
*
* @param handler Event handler that responds to the creation of a Firebase Auth user.
*
* @public
*/
onCreate(handler) {
return this.onOperation(handler, "user.create");
}
/**
* Responds to the deletion of a Firebase Auth user.
*
* @param handler Event handler that responds to the deletion of a Firebase Auth user.
*
* @public
*/
onDelete(handler) {
return this.onOperation(handler, "user.delete");
}
/**
* Blocks request to create a Firebase Auth user.
*
* @param handler Event handler that blocks creation of a Firebase Auth user.
*
* @public
*/
beforeCreate(handler) {
return this.beforeOperation(handler, "beforeCreate");
}
/**
* Blocks request to sign-in a Firebase Auth user.
*
* @param handler Event handler that blocks sign-in of a Firebase Auth user.
*
* @public
*/
beforeSignIn(handler) {
return this.beforeOperation(handler, "beforeSignIn");
}
beforeEmail(handler) {
return this.beforeOperation(handler, "beforeSendEmail");
}
beforeSms(handler) {
return this.beforeOperation(handler, "beforeSendSms");
}
onOperation(handler, eventType) {
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
eventType,
service: exports.service,
triggerResource: this.triggerResource,
// eslint-disable-next-line @typescript-eslint/unbound-method
dataConstructor: UserBuilder.dataConstructor,
legacyEventType: `providers/firebase.auth/eventTypes/${eventType}`,
options: this.options,
});
}
beforeOperation(handler, eventType) {
var _a, _b, _c, _d, _e, _f;
const accessToken = ((_b = (_a = this.userOptions) === null || _a === void 0 ? void 0 : _a.blockingOptions) === null || _b === void 0 ? void 0 : _b.accessToken) || false;
const idToken = ((_d = (_c = this.userOptions) === null || _c === void 0 ? void 0 : _c.blockingOptions) === null || _d === void 0 ? void 0 : _d.idToken) || false;
const refreshToken = ((_f = (_e = this.userOptions) === null || _e === void 0 ? void 0 : _e.blockingOptions) === null || _f === void 0 ? void 0 : _f.refreshToken) || false;
const annotatedHandler = Object.assign(handler, { platform: "gcfv1" });
const func = (0, identity_1.wrapHandler)(eventType, annotatedHandler);
const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
func.__trigger = {
labels: {},
...(0, cloud_functions_1.optionsToTrigger)(this.options),
blockingTrigger: {
eventType: legacyEventType,
options: {
accessToken,
idToken,
refreshToken,
},
},
};
func.__endpoint = {
platform: "gcfv1",
labels: {},
...(0, manifest_1.initV1Endpoint)(this.options),
...(0, cloud_functions_1.optionsToEndpoint)(this.options),
blockingTrigger: {
eventType: legacyEventType,
options: {
accessToken,
idToken,
refreshToken,
},
},
};
func.__requiredAPIs = [
{
api: "identitytoolkit.googleapis.com",
reason: "Needed for auth blocking functions",
},
];
func.run = handler;
return func;
}
}
exports.UserBuilder = UserBuilder;

View File

@@ -0,0 +1,117 @@
import { Change } from "../../common/change";
import { ParamsOf } from "../../common/params";
import { DataSnapshot } from "../../common/providers/database";
import { CloudFunction, EventContext } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";
export { DataSnapshot };
/**
* Registers a function that triggers on events from a specific
* Firebase Realtime Database instance.
*
* @remarks
* Use this method together with `ref` to specify the instance on which to
* watch for database events. For example: `firebase.database.instance('my-app-db-2').ref('/foo/bar')`
*
* Note that `functions.database.ref` used without `instance` watches the
* *default* instance for events.
*
* @param instance The instance name of the database instance
* to watch for write events.
* @returns Firebase Realtime Database instance builder interface.
*/
export declare function instance(instance: string): InstanceBuilder;
/**
* Registers a function that triggers on Firebase Realtime Database write
* events.
*
* @remarks
* This method behaves very similarly to the method of the same name in the
* client and Admin Firebase SDKs. Any change to the Database that affects the
* data at or below the provided `path` will fire an event in Cloud Functions.
*
* There are three important differences between listening to a Realtime
* Database event in Cloud Functions and using the Realtime Database in the
* client and Admin SDKs:
*
* 1. Cloud Functions allows wildcards in the `path` name. Any `path` component
* in curly brackets (`{}`) is a wildcard that matches all strings. The value
* that matched a certain invocation of a Cloud Function is returned as part
* of the [`EventContext.params`](cloud_functions_eventcontext.html#params object. For
* example, `ref("messages/{messageId}")` matches changes at
* `/messages/message1` or `/messages/message2`, resulting in
* `event.params.messageId` being set to `"message1"` or `"message2"`,
* respectively.
*
* 2. Cloud Functions do not fire an event for data that already existed before
* the Cloud Function was deployed.
*
* 3. Cloud Function events have access to more information, including a
* snapshot of the previous event data and information about the user who
* triggered the Cloud Function.
*
* @param path The path within the Database to watch for write events.
* @returns Firebase Realtime Database builder interface.
*/
export declare function ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
/**
* The Firebase Realtime Database instance builder interface.
*
* Access via [`database.instance()`](providers_database_.html#instance).
*/
export declare class InstanceBuilder {
private instance;
private options;
constructor(instance: string, options: DeploymentOptions);
/**
* @returns Firebase Realtime Database reference builder interface.
*/
ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
}
/**
* The Firebase Realtime Database reference builder interface.
*
* Access via [`functions.database.ref()`](functions.database#.ref).
*/
export declare class RefBuilder<Ref extends string> {
private triggerResource;
private options;
constructor(triggerResource: () => string, options: DeploymentOptions);
/**
* Event handler that fires every time a Firebase Realtime Database write
* of any kind (creation, update, or delete) occurs.
*
* @param handler Event handler that runs every time a Firebase Realtime Database
* write occurs.
* @returns A function that you can export and deploy.
*/
onWrite(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
/**
* Event handler that fires every time data is updated in
* Firebase Realtime Database.
*
* @param handler Event handler which is run every time a Firebase Realtime Database
* write occurs.
* @returns A function which you can export and deploy.
*/
onUpdate(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;
/**
* Event handler that fires every time new data is created in
* Firebase Realtime Database.
*
* @param handler Event handler that runs every time new data is created in
* Firebase Realtime Database.
* @returns A function that you can export and deploy.
*/
onCreate(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
/**
* Event handler that fires every time data is deleted from
* Firebase Realtime Database.
*
* @param handler Event handler that runs every time data is deleted from
* Firebase Realtime Database.
* @returns A function that you can export and deploy.
*/
onDelete(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;
private onOperation;
private changeConstructor;
}

View File

@@ -0,0 +1,263 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractInstanceAndPath = exports.RefBuilder = exports._refWithOptions = exports.InstanceBuilder = exports._instanceWithOptions = exports.ref = exports.instance = exports.service = exports.provider = exports.DataSnapshot = void 0;
const app_1 = require("../../common/app");
const config_1 = require("../../common/config");
const database_1 = require("../../common/providers/database");
Object.defineProperty(exports, "DataSnapshot", { enumerable: true, get: function () { return database_1.DataSnapshot; } });
const path_1 = require("../../common/utilities/path");
const utils_1 = require("../../common/utilities/utils");
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.provider = "google.firebase.database";
/** @internal */
exports.service = "firebaseio.com";
const databaseURLRegex = new RegExp("^https://([^.]+).");
const emulatorDatabaseURLRegex = new RegExp("^http://.*ns=([^&]+)");
/**
* Registers a function that triggers on events from a specific
* Firebase Realtime Database instance.
*
* @remarks
* Use this method together with `ref` to specify the instance on which to
* watch for database events. For example: `firebase.database.instance('my-app-db-2').ref('/foo/bar')`
*
* Note that `functions.database.ref` used without `instance` watches the
* *default* instance for events.
*
* @param instance The instance name of the database instance
* to watch for write events.
* @returns Firebase Realtime Database instance builder interface.
*/
function instance(instance) {
return _instanceWithOptions(instance, {});
}
exports.instance = instance;
/**
* Registers a function that triggers on Firebase Realtime Database write
* events.
*
* @remarks
* This method behaves very similarly to the method of the same name in the
* client and Admin Firebase SDKs. Any change to the Database that affects the
* data at or below the provided `path` will fire an event in Cloud Functions.
*
* There are three important differences between listening to a Realtime
* Database event in Cloud Functions and using the Realtime Database in the
* client and Admin SDKs:
*
* 1. Cloud Functions allows wildcards in the `path` name. Any `path` component
* in curly brackets (`{}`) is a wildcard that matches all strings. The value
* that matched a certain invocation of a Cloud Function is returned as part
* of the [`EventContext.params`](cloud_functions_eventcontext.html#params object. For
* example, `ref("messages/{messageId}")` matches changes at
* `/messages/message1` or `/messages/message2`, resulting in
* `event.params.messageId` being set to `"message1"` or `"message2"`,
* respectively.
*
* 2. Cloud Functions do not fire an event for data that already existed before
* the Cloud Function was deployed.
*
* 3. Cloud Function events have access to more information, including a
* snapshot of the previous event data and information about the user who
* triggered the Cloud Function.
*
* @param path The path within the Database to watch for write events.
* @returns Firebase Realtime Database builder interface.
*/
function ref(path) {
return _refWithOptions(path, {});
}
exports.ref = ref;
/** @internal */
function _instanceWithOptions(instance, options) {
return new InstanceBuilder(instance, options);
}
exports._instanceWithOptions = _instanceWithOptions;
/**
* The Firebase Realtime Database instance builder interface.
*
* Access via [`database.instance()`](providers_database_.html#instance).
*/
class InstanceBuilder {
constructor(instance, options) {
this.instance = instance;
this.options = options;
}
/**
* @returns Firebase Realtime Database reference builder interface.
*/
ref(path) {
const normalized = (0, path_1.normalizePath)(path);
return new RefBuilder(() => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
}
}
exports.InstanceBuilder = InstanceBuilder;
/** @internal */
function _refWithOptions(path, options) {
const resourceGetter = () => {
const normalized = (0, path_1.normalizePath)(path);
const databaseURL = (0, config_1.firebaseConfig)().databaseURL;
if (!databaseURL) {
throw new Error("Missing expected firebase config value databaseURL, " +
"config is actually" +
JSON.stringify((0, config_1.firebaseConfig)()) +
"\n If you are unit testing, please set process.env.FIREBASE_CONFIG");
}
let instance;
const prodMatch = databaseURL.match(databaseURLRegex);
if (prodMatch) {
instance = prodMatch[1];
}
else {
const emulatorMatch = databaseURL.match(emulatorDatabaseURLRegex);
if (emulatorMatch) {
instance = emulatorMatch[1];
}
}
if (!instance) {
throw new Error("Invalid value for config firebase.databaseURL: " + databaseURL);
}
return `projects/_/instances/${instance}/refs/${normalized}`;
};
return new RefBuilder(resourceGetter, options);
}
exports._refWithOptions = _refWithOptions;
/**
* The Firebase Realtime Database reference builder interface.
*
* Access via [`functions.database.ref()`](functions.database#.ref).
*/
class RefBuilder {
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
this.changeConstructor = (raw) => {
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
const before = new database_1.DataSnapshot(raw.data.data, path, (0, app_1.getApp)(), dbInstance);
const after = new database_1.DataSnapshot((0, utils_1.applyChange)(raw.data.data, raw.data.delta), path, (0, app_1.getApp)(), dbInstance);
return {
before,
after,
};
};
}
/**
* Event handler that fires every time a Firebase Realtime Database write
* of any kind (creation, update, or delete) occurs.
*
* @param handler Event handler that runs every time a Firebase Realtime Database
* write occurs.
* @returns A function that you can export and deploy.
*/
onWrite(handler) {
return this.onOperation(handler, "ref.write", this.changeConstructor);
}
/**
* Event handler that fires every time data is updated in
* Firebase Realtime Database.
*
* @param handler Event handler which is run every time a Firebase Realtime Database
* write occurs.
* @returns A function which you can export and deploy.
*/
onUpdate(handler) {
return this.onOperation(handler, "ref.update", this.changeConstructor);
}
/**
* Event handler that fires every time new data is created in
* Firebase Realtime Database.
*
* @param handler Event handler that runs every time new data is created in
* Firebase Realtime Database.
* @returns A function that you can export and deploy.
*/
onCreate(handler) {
const dataConstructor = (raw) => {
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
return new database_1.DataSnapshot(raw.data.delta, path, (0, app_1.getApp)(), dbInstance);
};
return this.onOperation(handler, "ref.create", dataConstructor);
}
/**
* Event handler that fires every time data is deleted from
* Firebase Realtime Database.
*
* @param handler Event handler that runs every time data is deleted from
* Firebase Realtime Database.
* @returns A function that you can export and deploy.
*/
onDelete(handler) {
const dataConstructor = (raw) => {
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
return new database_1.DataSnapshot(raw.data.data, path, (0, app_1.getApp)(), dbInstance);
};
return this.onOperation(handler, "ref.delete", dataConstructor);
}
onOperation(handler, eventType, dataConstructor) {
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
service: exports.service,
eventType,
legacyEventType: `providers/${exports.provider}/eventTypes/${eventType}`,
triggerResource: this.triggerResource,
dataConstructor,
options: this.options,
});
}
}
exports.RefBuilder = RefBuilder;
const resourceRegex = /^projects\/([^/]+)\/instances\/([a-zA-Z0-9-]+)\/refs(\/.+)?/;
/**
* Utility function to extract database reference from resource string
*
* @param optional database domain override for the original of the source database.
* It defaults to `firebaseio.com`.
* Multi-region RTDB will be served from different domains.
* Since region is not part of the resource name, it is provided through context.
*
* @internal
*/
function extractInstanceAndPath(resource, domain = "firebaseio.com") {
const match = resource.match(new RegExp(resourceRegex));
if (!match) {
throw new Error(`Unexpected resource string for Firebase Realtime Database event: ${resource}. ` +
'Expected string in the format of "projects/_/instances/{firebaseioSubdomain}/refs/{ref=**}"');
}
const [, project, dbInstanceName, path] = match;
if (project !== "_") {
throw new Error(`Expect project to be '_' in a Firebase Realtime Database event`);
}
const emuHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
if (emuHost) {
const dbInstance = `http://${emuHost}/?ns=${dbInstanceName}`;
return [dbInstance, path];
}
else {
const dbInstance = "https://" + dbInstanceName + "." + domain;
return [dbInstance, path];
}
}
exports.extractInstanceAndPath = extractInstanceAndPath;

View File

@@ -0,0 +1,47 @@
import * as firestore from "firebase-admin/firestore";
import { Change } from "../../common/change";
import { ParamsOf } from "../../common/params";
import { CloudFunction, Event, EventContext } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";
export type DocumentSnapshot = firestore.DocumentSnapshot;
export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot;
/**
* Select the Firestore document to listen to for events.
* @param path Full database path to listen to. This includes the name of
* the collection that the document is a part of. For example, if the
* collection is named "users" and the document is named "Ada", then the
* path is "/users/Ada".
*/
export declare function document<Path extends string>(path: Path): DocumentBuilder<Path>;
export declare function namespace(namespace: string): NamespaceBuilder;
export declare function database(database: string): DatabaseBuilder;
export declare class DatabaseBuilder {
private database;
private options;
constructor(database: string, options: DeploymentOptions);
namespace(namespace: string): NamespaceBuilder;
document<Path extends string>(path: Path): DocumentBuilder<Path>;
}
export declare class NamespaceBuilder {
private database;
private options;
private namespace?;
constructor(database: string, options: DeploymentOptions, namespace?: string);
document<Path extends string>(path: Path): DocumentBuilder<Path>;
}
export declare function snapshotConstructor(event: Event): DocumentSnapshot;
export declare function beforeSnapshotConstructor(event: Event): DocumentSnapshot;
export declare class DocumentBuilder<Path extends string> {
private triggerResource;
private options;
constructor(triggerResource: () => string, options: DeploymentOptions);
/** Respond to all document writes (creates, updates, or deletes). */
onWrite(handler: (change: Change<DocumentSnapshot>, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<Change<DocumentSnapshot>>;
/** Respond only to document updates. */
onUpdate(handler: (change: Change<QueryDocumentSnapshot>, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<Change<QueryDocumentSnapshot>>;
/** Respond only to document creations. */
onCreate(handler: (snapshot: QueryDocumentSnapshot, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<QueryDocumentSnapshot>;
/** Respond only to document deletions. */
onDelete(handler: (snapshot: QueryDocumentSnapshot, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<QueryDocumentSnapshot>;
private onOperation;
}

View File

@@ -0,0 +1,150 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentBuilder = exports.beforeSnapshotConstructor = exports.snapshotConstructor = exports.NamespaceBuilder = exports.DatabaseBuilder = exports._documentWithOptions = exports._namespaceWithOptions = exports._databaseWithOptions = exports.database = exports.namespace = exports.document = exports.defaultDatabase = exports.service = exports.provider = void 0;
const path_1 = require("path");
const change_1 = require("../../common/change");
const firestore_1 = require("../../common/providers/firestore");
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.provider = "google.firestore";
/** @internal */
exports.service = "firestore.googleapis.com";
/** @internal */
exports.defaultDatabase = "(default)";
/**
* Select the Firestore document to listen to for events.
* @param path Full database path to listen to. This includes the name of
* the collection that the document is a part of. For example, if the
* collection is named "users" and the document is named "Ada", then the
* path is "/users/Ada".
*/
function document(path) {
return _documentWithOptions(path, {});
}
exports.document = document;
// Multiple namespaces are not yet supported by Firestore.
function namespace(namespace) {
return _namespaceWithOptions(namespace, {});
}
exports.namespace = namespace;
// Multiple databases are not yet supported by Firestore.
function database(database) {
return _databaseWithOptions(database, {});
}
exports.database = database;
/** @internal */
function _databaseWithOptions(database = exports.defaultDatabase, options) {
return new DatabaseBuilder(database, options);
}
exports._databaseWithOptions = _databaseWithOptions;
/** @internal */
function _namespaceWithOptions(namespace, options) {
return _databaseWithOptions(exports.defaultDatabase, options).namespace(namespace);
}
exports._namespaceWithOptions = _namespaceWithOptions;
/** @internal */
function _documentWithOptions(path, options) {
return _databaseWithOptions(exports.defaultDatabase, options).document(path);
}
exports._documentWithOptions = _documentWithOptions;
class DatabaseBuilder {
constructor(database, options) {
this.database = database;
this.options = options;
}
namespace(namespace) {
return new NamespaceBuilder(this.database, this.options, namespace);
}
document(path) {
return new NamespaceBuilder(this.database, this.options).document(path);
}
}
exports.DatabaseBuilder = DatabaseBuilder;
class NamespaceBuilder {
constructor(database, options, namespace) {
this.database = database;
this.options = options;
this.namespace = namespace;
}
document(path) {
return new DocumentBuilder(() => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
const database = path_1.posix.join("projects", process.env.GCLOUD_PROJECT, "databases", this.database);
return path_1.posix.join(database, this.namespace ? `documents@${this.namespace}` : "documents", path);
}, this.options);
}
}
exports.NamespaceBuilder = NamespaceBuilder;
function snapshotConstructor(event) {
var _a, _b, _c, _d;
return (0, firestore_1.createSnapshotFromJson)(event.data, event.context.resource.name, (_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.readTime, (_d = (_c = event === null || event === void 0 ? void 0 : event.data) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.updateTime);
}
exports.snapshotConstructor = snapshotConstructor;
// TODO remove this function when wire format changes to new format
function beforeSnapshotConstructor(event) {
var _a, _b;
return (0, firestore_1.createBeforeSnapshotFromJson)(event.data, event.context.resource.name, (_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.oldValue) === null || _b === void 0 ? void 0 : _b.readTime, undefined);
}
exports.beforeSnapshotConstructor = beforeSnapshotConstructor;
function changeConstructor(raw) {
return change_1.Change.fromObjects(beforeSnapshotConstructor(raw), snapshotConstructor(raw));
}
class DocumentBuilder {
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
// TODO what validation do we want to do here?
}
/** Respond to all document writes (creates, updates, or deletes). */
onWrite(handler) {
return this.onOperation(handler, "document.write", changeConstructor);
}
/** Respond only to document updates. */
onUpdate(handler) {
return this.onOperation(handler, "document.update", changeConstructor);
}
/** Respond only to document creations. */
onCreate(handler) {
return this.onOperation(handler, "document.create", snapshotConstructor);
}
/** Respond only to document deletions. */
onDelete(handler) {
return this.onOperation(handler, "document.delete", beforeSnapshotConstructor);
}
onOperation(handler, eventType, dataConstructor) {
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
eventType,
service: exports.service,
triggerResource: this.triggerResource,
legacyEventType: `providers/cloud.firestore/eventTypes/${eventType}`,
dataConstructor,
options: this.options,
});
}
}
exports.DocumentBuilder = DocumentBuilder;

View File

@@ -0,0 +1,15 @@
import * as express from "express";
import { CallableContext, FunctionsErrorCode, HttpsError, Request } from "../../common/providers/https";
import { HttpsFunction, Runnable } from "../cloud-functions";
export { Request, CallableContext, FunctionsErrorCode, HttpsError };
/**
* Handle HTTP requests.
* @param handler A function that takes a request and response object,
* same signature as an Express app.
*/
export declare function onRequest(handler: (req: Request, resp: express.Response) => void | Promise<void>): HttpsFunction;
/**
* Declares a callable method for clients to call using a Firebase SDK.
* @param handler A method that takes a data and context and returns a value.
*/
export declare function onCall(handler: (data: any, context: CallableContext) => any | Promise<any>): HttpsFunction & Runnable<any>;

View File

@@ -0,0 +1,99 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports._onCallWithOptions = exports._onRequestWithOptions = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
const encoding_1 = require("../../common/encoding");
const https_1 = require("../../common/providers/https");
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
const cloud_functions_1 = require("../cloud-functions");
const manifest_1 = require("../../runtime/manifest");
const onInit_1 = require("../../common/onInit");
const trace_1 = require("../../v2/trace");
/**
* Handle HTTP requests.
* @param handler A function that takes a request and response object,
* same signature as an Express app.
*/
function onRequest(handler) {
return _onRequestWithOptions(handler, {});
}
exports.onRequest = onRequest;
/**
* Declares a callable method for clients to call using a Firebase SDK.
* @param handler A method that takes a data and context and returns a value.
*/
function onCall(handler) {
return _onCallWithOptions(handler, {});
}
exports.onCall = onCall;
/** @internal */
function _onRequestWithOptions(handler, options) {
// lets us add __endpoint without altering handler:
const cloudFunction = (req, res) => {
return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(req, res);
};
cloudFunction.__trigger = {
...(0, cloud_functions_1.optionsToTrigger)(options),
httpsTrigger: {},
};
(0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, "invoker", "invoker", encoding_1.convertInvoker);
// TODO parse the options
cloudFunction.__endpoint = {
platform: "gcfv1",
...(0, manifest_1.initV1Endpoint)(options),
...(0, cloud_functions_1.optionsToEndpoint)(options),
httpsTrigger: {},
};
(0, encoding_1.convertIfPresent)(cloudFunction.__endpoint.httpsTrigger, options, "invoker", "invoker", encoding_1.convertInvoker);
return cloudFunction;
}
exports._onRequestWithOptions = _onRequestWithOptions;
/** @internal */
function _onCallWithOptions(handler, options) {
// fix the length of handler to make the call to handler consistent
// in the onCallHandler
const fixedLen = (data, context) => {
return (0, onInit_1.withInit)(handler)(data, context);
};
const func = (0, trace_1.wrapTraceContext)((0, https_1.onCallHandler)({
enforceAppCheck: options.enforceAppCheck,
consumeAppCheckToken: options.consumeAppCheckToken,
cors: { origin: true, methods: "POST" },
}, fixedLen, "gcfv1"));
func.__trigger = {
labels: {},
...(0, cloud_functions_1.optionsToTrigger)(options),
httpsTrigger: {},
};
func.__trigger.labels["deployment-callable"] = "true";
func.__endpoint = {
platform: "gcfv1",
labels: {},
...(0, manifest_1.initV1Endpoint)(options),
...(0, cloud_functions_1.optionsToEndpoint)(options),
callableTrigger: {},
};
func.run = fixedLen;
return func;
}
exports._onCallWithOptions = _onCallWithOptions;

View File

@@ -0,0 +1,93 @@
import { CloudFunction, EventContext } from "../cloud-functions";
import { DeploymentOptions, ScheduleRetryConfig } from "../function-configuration";
/**
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
* is sent to a specified topic.
*
* @param topic - The Pub/Sub topic to watch for message events.
* @returns Pub/Sub topic builder interface.
*/
export declare function topic(topic: string): TopicBuilder;
/**
* The Google Cloud Pub/Sub topic builder.
*
* Access via `functions.pubsub.topic()`.
*/
export declare class TopicBuilder {
private triggerResource;
private options;
/** @hidden */
constructor(triggerResource: () => string, options: DeploymentOptions);
/**
* Event handler that fires every time a Cloud Pub/Sub message is
* published.
*
* @param handler - Event handler that runs every time a Cloud Pub/Sub message
* is published.
* @returns A function that you can export and deploy.
*/
onPublish(handler: (message: Message, context: EventContext) => PromiseLike<any> | any): CloudFunction<Message>;
}
/**
* Registers a Cloud Function to run at specified times.
*
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
* @returns ScheduleBuilder interface.
*/
export declare function schedule(schedule: string): ScheduleBuilder;
/**
* The builder for scheduled functions, which are powered by
* Google Pub/Sub and Cloud Scheduler. Describes the Cloud Scheduler
* job that is deployed to trigger a scheduled function at the provided
* frequency. For more information, see
* [Schedule functions](/docs/functions/schedule-functions).
*
* Access via `functions.pubsub.schedule()`.
*/
export declare class ScheduleBuilder {
private triggerResource;
private options;
/** @hidden */
constructor(triggerResource: () => string, options: DeploymentOptions);
retryConfig(config: ScheduleRetryConfig): ScheduleBuilder;
timeZone(timeZone: string): ScheduleBuilder;
/**
* Event handler for scheduled functions. Triggered whenever the associated
* scheduler job sends a Pub/Sub message.
*
* @param handler - Handler that fires whenever the associated
* scheduler job sends a Pub/Sub message.
* @returns A function that you can export and deploy.
*/
onRun(handler: (context: EventContext) => PromiseLike<any> | any): CloudFunction<unknown>;
}
/**
* Interface representing a Google Cloud Pub/Sub message.
*
* @param data - Payload of a Pub/Sub message.
*/
export declare class Message {
/**
* The data payload of this message object as a base64-encoded string.
*/
readonly data: string;
/**
* User-defined attributes published with the message, if any.
*/
readonly attributes: {
[key: string]: string;
};
/** @hidden */
private _json;
constructor(data: any);
/**
* The JSON data payload of this message object, if any.
*/
get json(): any;
/**
* Returns a JSON-serializable representation of this object.
*
* @returns A JSON-serializable representation of this object.
*/
toJSON(): any;
}

View File

@@ -0,0 +1,186 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = exports.ScheduleBuilder = exports._scheduleWithOptions = exports.schedule = exports.TopicBuilder = exports._topicWithOptions = exports.topic = exports.service = exports.provider = void 0;
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.provider = "google.pubsub";
/** @internal */
exports.service = "pubsub.googleapis.com";
/**
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
* is sent to a specified topic.
*
* @param topic - The Pub/Sub topic to watch for message events.
* @returns Pub/Sub topic builder interface.
*/
function topic(topic) {
return _topicWithOptions(topic, {});
}
exports.topic = topic;
/** @internal */
function _topicWithOptions(topic, options) {
if (topic.indexOf("/") !== -1) {
throw new Error("Topic name may not have a /");
}
return new TopicBuilder(() => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
return `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`;
}, options);
}
exports._topicWithOptions = _topicWithOptions;
/**
* The Google Cloud Pub/Sub topic builder.
*
* Access via `functions.pubsub.topic()`.
*/
class TopicBuilder {
/** @hidden */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
/**
* Event handler that fires every time a Cloud Pub/Sub message is
* published.
*
* @param handler - Event handler that runs every time a Cloud Pub/Sub message
* is published.
* @returns A function that you can export and deploy.
*/
onPublish(handler) {
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
service: exports.service,
triggerResource: this.triggerResource,
eventType: "topic.publish",
dataConstructor: (raw) => new Message(raw.data),
options: this.options,
});
}
}
exports.TopicBuilder = TopicBuilder;
/**
* Registers a Cloud Function to run at specified times.
*
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
* @returns ScheduleBuilder interface.
*/
function schedule(schedule) {
return _scheduleWithOptions(schedule, {});
}
exports.schedule = schedule;
/** @internal */
function _scheduleWithOptions(schedule, options) {
const triggerResource = () => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
// The CLI will append the correct topic name based on region and function name
return `projects/${process.env.GCLOUD_PROJECT}/topics`;
};
return new ScheduleBuilder(triggerResource, {
...options,
schedule: { schedule },
});
}
exports._scheduleWithOptions = _scheduleWithOptions;
/**
* The builder for scheduled functions, which are powered by
* Google Pub/Sub and Cloud Scheduler. Describes the Cloud Scheduler
* job that is deployed to trigger a scheduled function at the provided
* frequency. For more information, see
* [Schedule functions](/docs/functions/schedule-functions).
*
* Access via `functions.pubsub.schedule()`.
*/
class ScheduleBuilder {
/** @hidden */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
retryConfig(config) {
this.options.schedule.retryConfig = config;
return this;
}
timeZone(timeZone) {
this.options.schedule.timeZone = timeZone;
return this;
}
/**
* Event handler for scheduled functions. Triggered whenever the associated
* scheduler job sends a Pub/Sub message.
*
* @param handler - Handler that fires whenever the associated
* scheduler job sends a Pub/Sub message.
* @returns A function that you can export and deploy.
*/
onRun(handler) {
const cloudFunction = (0, cloud_functions_1.makeCloudFunction)({
contextOnlyHandler: handler,
provider: exports.provider,
service: exports.service,
triggerResource: this.triggerResource,
eventType: "topic.publish",
options: this.options,
labels: { "deployment-scheduled": "true" },
});
return cloudFunction;
}
}
exports.ScheduleBuilder = ScheduleBuilder;
/**
* Interface representing a Google Cloud Pub/Sub message.
*
* @param data - Payload of a Pub/Sub message.
*/
class Message {
constructor(data) {
[this.data, this.attributes, this._json] = [data.data, data.attributes || {}, data.json];
}
/**
* The JSON data payload of this message object, if any.
*/
get json() {
if (typeof this._json === "undefined") {
this._json = JSON.parse(Buffer.from(this.data, "base64").toString("utf8"));
}
return this._json;
}
/**
* Returns a JSON-serializable representation of this object.
*
* @returns A JSON-serializable representation of this object.
*/
toJSON() {
return {
data: this.data,
attributes: this.attributes,
};
}
}
exports.Message = Message;

View File

@@ -0,0 +1,71 @@
import { CloudFunction, EventContext } from "../cloud-functions";
/**
* Registers a function that triggers on Firebase Remote Config template
* update events.
*
* @param handler A function that takes the updated Remote Config
* template version metadata as an argument.
*
* @returns A function that you can export and deploy.
*/
export declare function onUpdate(handler: (version: TemplateVersion, context: EventContext) => PromiseLike<any> | any): CloudFunction<TemplateVersion>;
/** Builder used to create Cloud Functions for Remote Config. */
export declare class UpdateBuilder {
private triggerResource;
private options;
/**
* Handle all updates (including rollbacks) that affect a Remote Config
* project.
* @param handler A function that takes the updated Remote Config template
* version metadata as an argument.
*/
onUpdate(handler: (version: TemplateVersion, context: EventContext) => PromiseLike<any> | any): CloudFunction<TemplateVersion>;
}
/**
* An interface representing a Remote Config template version metadata object
* emitted when a project is updated.
*/
export interface TemplateVersion {
/** The version number of the updated Remote Config template. */
versionNumber: number;
/** When the template was updated in format (ISO8601 timestamp). */
updateTime: string;
/**
* Metadata about the account that performed the update, of
* type [`RemoteConfigUser`](/docs/reference/remote-config/rest/v1/Version#remoteconfiguser).
*/
updateUser: RemoteConfigUser;
/** A description associated with this Remote Config template version. */
description: string;
/**
* The origin of the caller - either the Firebase console or the Remote Config
* REST API. See [`RemoteConfigUpdateOrigin`](/docs/reference/remote-config/rest/v1/Version#remoteconfigupdateorigin)
* for valid values.
*/
updateOrigin: string;
/**
* The type of update action that was performed, whether forced,
* incremental, or a rollback operation. See
* [`RemoteConfigUpdateType`](/docs/reference/remote-config/rest/v1/Version#remoteconfigupdatetype)
* for valid values.
*/
updateType: string;
/**
* The version number of the Remote Config template that this update rolled back to.
* Only applies if this update was a rollback.
*/
rollbackSource?: number;
}
/**
* An interface representing metadata for a Remote Config account
* that performed the update. Contains the same fields as
* [`RemoteConfigUser`](/docs/reference/remote-config/rest/v1/Version#remoteconfiguser).
*/
export interface RemoteConfigUser {
/** Name of the Remote Config account that performed the update. */
name?: string;
/** Email address of the Remote Config account that performed the update. */
email: string;
/** Image URL of the Remote Config account that performed the update. */
imageUrl?: string;
}

View File

@@ -0,0 +1,78 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2018 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateBuilder = exports._onUpdateWithOptions = exports.onUpdate = exports.service = exports.provider = void 0;
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.provider = "google.firebase.remoteconfig";
/** @internal */
exports.service = "firebaseremoteconfig.googleapis.com";
/**
* Registers a function that triggers on Firebase Remote Config template
* update events.
*
* @param handler A function that takes the updated Remote Config
* template version metadata as an argument.
*
* @returns A function that you can export and deploy.
*/
function onUpdate(handler) {
return _onUpdateWithOptions(handler, {});
}
exports.onUpdate = onUpdate;
/** @internal */
function _onUpdateWithOptions(handler, options) {
const triggerResource = () => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
return `projects/${process.env.GCLOUD_PROJECT}`;
};
return new UpdateBuilder(triggerResource, options).onUpdate(handler);
}
exports._onUpdateWithOptions = _onUpdateWithOptions;
/** Builder used to create Cloud Functions for Remote Config. */
class UpdateBuilder {
/** @internal */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
/**
* Handle all updates (including rollbacks) that affect a Remote Config
* project.
* @param handler A function that takes the updated Remote Config template
* version metadata as an argument.
*/
onUpdate(handler) {
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
service: exports.service,
triggerResource: this.triggerResource,
eventType: "update",
options: this.options,
});
}
}
exports.UpdateBuilder = UpdateBuilder;

View File

@@ -0,0 +1,220 @@
import { CloudFunction, EventContext } from "../cloud-functions";
/**
* Registers a Cloud Function scoped to a specific storage bucket.
*
* @param bucket Name of the bucket to which this Cloud Function is
* scoped.
*
* @returns Storage bucket builder interface.
*/
export declare function bucket(bucket?: string): BucketBuilder;
/**
* Registers a Cloud Function scoped to the default storage bucket for the
* project.
*
* @returns Storage object builder interface.
*/
export declare function object(): ObjectBuilder;
/**
* The Google Cloud Storage bucket builder interface.
*
* Access via `functions.storage.bucket()`.
*/
export declare class BucketBuilder {
private triggerResource;
private options;
/**
* Event handler which fires every time a Google Cloud Storage change occurs.
*
* @returns Storage object builder interface scoped to the specified storage
* bucket.
*/
object(): ObjectBuilder;
}
/**
* The Google Cloud Storage object builder interface.
*
* Access via `functions.storage.object()`.
*/
export declare class ObjectBuilder {
private triggerResource;
private options;
/**
* Event handler sent only when a bucket has enabled object versioning.
* This event indicates that the live version of an object has become an
* archived version, either because it was archived or because it was
* overwritten by the upload of an object of the same name.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* archival occurs.
*
* @returns A function which you can export and deploy.
*/
onArchive(handler: (object: ObjectMetadata, context: EventContext) => PromiseLike<any> | any): CloudFunction<ObjectMetadata>;
/**
* Event handler which fires every time a Google Cloud Storage deletion occurs.
*
* Sent when an object has been permanently deleted. This includes objects
* that are overwritten or are deleted as part of the bucket's lifecycle
* configuration. For buckets with object versioning enabled, this is not
* sent when an object is archived, even if archival occurs
* via the `storage.objects.delete` method.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* deletion occurs.
*
* @returns A function which you can export and deploy.
*/
onDelete(handler: (object: ObjectMetadata, context: EventContext) => PromiseLike<any> | any): CloudFunction<ObjectMetadata>;
/**
* Event handler which fires every time a Google Cloud Storage object
* creation occurs.
*
* Sent when a new object (or a new generation of an existing object)
* is successfully created in the bucket. This includes copying or rewriting
* an existing object. A failed upload does not trigger this event.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* object creation occurs.
*
* @returns A function which you can export and deploy.
*/
onFinalize(handler: (object: ObjectMetadata, context: EventContext) => PromiseLike<any> | any): CloudFunction<ObjectMetadata>;
/**
* Event handler which fires every time the metadata of an existing object
* changes.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* metadata update occurs.
*
* @returns A function which you can export and deploy.
*/
onMetadataUpdate(handler: (object: ObjectMetadata, context: EventContext) => PromiseLike<any> | any): CloudFunction<ObjectMetadata>;
/** @hidden */
private onOperation;
}
/** Interface representing a Google Google Cloud Storage object metadata object. */
export interface ObjectMetadata {
/** The kind of the object, which is always `storage#object`. */
kind: string;
/**
* The ID of the object, including the bucket name, object name, and
* generation number.
*/
id: string;
/** Storage bucket that contains the object. */
bucket: string;
/** Storage class of the object. */
storageClass: string;
/**
* The value of the `Content-Length` header, used to determine the length of
* the object data in bytes.
*/
size: string;
/** The creation time of the object in RFC 3339 format. */
timeCreated: string;
/**
* The modification time of the object metadata in RFC 3339 format.
*/
updated: string;
/** Link to access the object, assuming you have sufficient permissions. */
selfLink?: string;
/** The object's name. */
name?: string;
/**
* Generation version number that changes each time the object is
* overwritten.
*/
generation?: string;
/** The object's content type, also known as the MIME type. */
contentType?: string;
/**
* Meta-generation version number that changes each time the object's metadata
* is updated.
*/
metageneration?: string;
/**
* The deletion time of the object in RFC 3339 format. Returned
* only if this version of the object has been deleted.
*/
timeDeleted?: string;
timeStorageClassUpdated?: string;
/**
* MD5 hash for the object. All Google Cloud Storage objects
* have a CRC32C hash or MD5 hash.
*/
md5Hash?: string;
/** Media download link. */
mediaLink?: string;
/**
* Content-Encoding to indicate that an object is compressed
* (for example, with gzip compression) while maintaining its Content-Type.
*/
contentEncoding?: string;
/**
* The value of the `Content-Disposition` header, used to specify presentation
* information about the data being transmitted.
*/
contentDisposition?: string;
/** ISO 639-1 language code of the content. */
contentLanguage?: string;
/**
* The value of the `Cache-Control` header, used to determine whether Internet
* caches are allowed to cache public data for an object.
*/
cacheControl?: string;
/** User-provided metadata. */
metadata?: {
[key: string]: string;
};
acl?: [
{
kind?: string;
id?: string;
selfLink?: string;
bucket?: string;
object?: string;
generation?: string;
entity?: string;
role?: string;
email?: string;
entityId?: string;
domain?: string;
projectTeam?: {
projectNumber?: string;
team?: string;
};
etag?: string;
}
];
owner?: {
entity?: string;
entityId?: string;
};
/**
* The object's CRC32C hash. All Google Cloud Storage objects
* have a CRC32C hash or MD5 hash.
*/
crc32c?: string;
/**
* Specifies the number of originally uploaded objects from which
* a composite object was created.
*/
componentCount?: string;
etag?: string;
/**
* Customer-supplied encryption key.
*
* This object contains the following properties:
* * `encryptionAlgorithm` (`string|undefined`): The encryption algorithm that
* was used. Always contains the value `AES256`.
* * `keySha256` (`string|undefined`): An RFC 4648 base64-encoded string of the
* SHA256 hash of your encryption key. You can use this SHA256 hash to
* uniquely identify the AES-256 encryption key required to decrypt the
* object, which you must store securely.
*/
customerEncryption?: {
encryptionAlgorithm?: string;
keySha256?: string;
};
}

View File

@@ -0,0 +1,178 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2017 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectBuilder = exports.BucketBuilder = exports._objectWithOptions = exports._bucketWithOptions = exports.object = exports.bucket = exports.service = exports.provider = void 0;
const config_1 = require("../../common/config");
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.provider = "google.storage";
/** @internal */
exports.service = "storage.googleapis.com";
/**
* Registers a Cloud Function scoped to a specific storage bucket.
*
* @param bucket Name of the bucket to which this Cloud Function is
* scoped.
*
* @returns Storage bucket builder interface.
*/
function bucket(bucket) {
return _bucketWithOptions({}, bucket);
}
exports.bucket = bucket;
/**
* Registers a Cloud Function scoped to the default storage bucket for the
* project.
*
* @returns Storage object builder interface.
*/
function object() {
return _objectWithOptions({});
}
exports.object = object;
/** @internal */
function _bucketWithOptions(options, bucket) {
const resourceGetter = () => {
bucket = bucket || (0, config_1.firebaseConfig)().storageBucket;
if (!bucket) {
throw new Error("Missing bucket name. If you are unit testing, please provide a bucket name" +
" through `functions.storage.bucket(bucketName)`, or set process.env.FIREBASE_CONFIG.");
}
if (!/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucket)) {
throw new Error(`Invalid bucket name ${bucket}`);
}
return `projects/_/buckets/${bucket}`;
};
return new BucketBuilder(resourceGetter, options);
}
exports._bucketWithOptions = _bucketWithOptions;
/** @internal */
function _objectWithOptions(options) {
return _bucketWithOptions(options).object();
}
exports._objectWithOptions = _objectWithOptions;
/**
* The Google Cloud Storage bucket builder interface.
*
* Access via `functions.storage.bucket()`.
*/
class BucketBuilder {
/** @internal */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
/**
* Event handler which fires every time a Google Cloud Storage change occurs.
*
* @returns Storage object builder interface scoped to the specified storage
* bucket.
*/
object() {
return new ObjectBuilder(this.triggerResource, this.options);
}
}
exports.BucketBuilder = BucketBuilder;
/**
* The Google Cloud Storage object builder interface.
*
* Access via `functions.storage.object()`.
*/
class ObjectBuilder {
/** @internal */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
/**
* Event handler sent only when a bucket has enabled object versioning.
* This event indicates that the live version of an object has become an
* archived version, either because it was archived or because it was
* overwritten by the upload of an object of the same name.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* archival occurs.
*
* @returns A function which you can export and deploy.
*/
onArchive(handler) {
return this.onOperation(handler, "object.archive");
}
/**
* Event handler which fires every time a Google Cloud Storage deletion occurs.
*
* Sent when an object has been permanently deleted. This includes objects
* that are overwritten or are deleted as part of the bucket's lifecycle
* configuration. For buckets with object versioning enabled, this is not
* sent when an object is archived, even if archival occurs
* via the `storage.objects.delete` method.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* deletion occurs.
*
* @returns A function which you can export and deploy.
*/
onDelete(handler) {
return this.onOperation(handler, "object.delete");
}
/**
* Event handler which fires every time a Google Cloud Storage object
* creation occurs.
*
* Sent when a new object (or a new generation of an existing object)
* is successfully created in the bucket. This includes copying or rewriting
* an existing object. A failed upload does not trigger this event.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* object creation occurs.
*
* @returns A function which you can export and deploy.
*/
onFinalize(handler) {
return this.onOperation(handler, "object.finalize");
}
/**
* Event handler which fires every time the metadata of an existing object
* changes.
*
* @param handler Event handler which is run every time a Google Cloud Storage
* metadata update occurs.
*
* @returns A function which you can export and deploy.
*/
onMetadataUpdate(handler) {
return this.onOperation(handler, "object.metadataUpdate");
}
/** @hidden */
onOperation(handler, eventType) {
return (0, cloud_functions_1.makeCloudFunction)({
handler,
provider: exports.provider,
service: exports.service,
eventType,
triggerResource: this.triggerResource,
options: this.options,
});
}
}
exports.ObjectBuilder = ObjectBuilder;

View File

@@ -0,0 +1,61 @@
import * as express from "express";
import { Request } from "../../common/providers/https";
import { RateLimits, RetryConfig, TaskContext } from "../../common/providers/tasks";
import { ManifestEndpoint, ManifestRequiredAPI } from "../../runtime/manifest";
export { RetryConfig, RateLimits, TaskContext };
/**
* Options for configuring the task queue to listen to.
*/
export interface TaskQueueOptions {
/** How a task should be retried in the event of a non-2xx return. */
retryConfig?: RetryConfig;
/** How congestion control should be applied to the function. */
rateLimits?: RateLimits;
/**
* Who can enqueue tasks for this function.
* If left unspecified, only service accounts which have
* `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
* will have permissions.
*/
invoker?: "private" | string | string[];
}
/**
* A handler for tasks.
*/
export interface TaskQueueFunction {
(req: Request, res: express.Response): Promise<void>;
/** @alpha */
__trigger: unknown;
/** @alpha */
__endpoint: ManifestEndpoint;
/** @alpha */
__requiredAPIs?: ManifestRequiredAPI[];
/**
* The callback passed to the `TaskQueueFunction` constructor.
* @param data - The body enqueued into a task queue.
* @param context - The request context of the enqueued task
* @returns Any return value. Google Cloud Functions will await any promise
* before shutting down your function. Resolved return values
* are only used for unit testing purposes.
*/
run(data: any, context: TaskContext): void | Promise<void>;
}
/**
* Builder for creating a `TaskQueueFunction`.
*/
export declare class TaskQueueBuilder {
private readonly tqOpts?;
private readonly depOpts?;
/**
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
* @param handler - A callback to handle task requests.
* @returns A function you can export and deploy.
*/
onDispatch(handler: (data: any, context: TaskContext) => void | Promise<void>): TaskQueueFunction;
}
/**
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
* @param options - Configuration for the Task Queue that feeds into this function.
* Omitting options will configure a Task Queue with default settings.
*/
export declare function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder;

View File

@@ -0,0 +1,85 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2022 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.taskQueue = exports.TaskQueueBuilder = void 0;
const encoding_1 = require("../../common/encoding");
const tasks_1 = require("../../common/providers/tasks");
const manifest_1 = require("../../runtime/manifest");
const cloud_functions_1 = require("../cloud-functions");
/**
* Builder for creating a `TaskQueueFunction`.
*/
class TaskQueueBuilder {
/** @internal */
constructor(tqOpts, depOpts) {
this.tqOpts = tqOpts;
this.depOpts = depOpts;
}
/**
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
* @param handler - A callback to handle task requests.
* @returns A function you can export and deploy.
*/
onDispatch(handler) {
var _a, _b;
// onEnqueueHandler sniffs the function length of the passed-in callback
// and the user could have only tried to listen to data. Wrap their handler
// in another handler to avoid accidentally triggering the v2 API
const fixedLen = (data, context) => handler(data, context);
const func = (0, tasks_1.onDispatchHandler)(fixedLen);
func.__trigger = {
...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
taskQueueTrigger: {},
};
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "retryConfig");
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "rateLimits");
(0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "invoker", "invoker", encoding_1.convertInvoker);
func.__endpoint = {
platform: "gcfv1",
...(0, manifest_1.initV1Endpoint)(this.depOpts),
...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
taskQueueTrigger: (0, manifest_1.initTaskQueueTrigger)(this.depOpts),
};
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger.retryConfig, ((_a = this.tqOpts) === null || _a === void 0 ? void 0 : _a.retryConfig) || {}, "maxAttempts", "maxBackoffSeconds", "maxDoublings", "maxRetrySeconds", "minBackoffSeconds");
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger.rateLimits, ((_b = this.tqOpts) === null || _b === void 0 ? void 0 : _b.rateLimits) || {}, "maxConcurrentDispatches", "maxDispatchesPerSecond");
(0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, "invoker", "invoker", encoding_1.convertInvoker);
func.__requiredAPIs = [
{
api: "cloudtasks.googleapis.com",
reason: "Needed for task queue functions",
},
];
func.run = handler;
return func;
}
}
exports.TaskQueueBuilder = TaskQueueBuilder;
/**
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
* @param options - Configuration for the Task Queue that feeds into this function.
* Omitting options will configure a Task Queue with default settings.
*/
function taskQueue(options) {
return new TaskQueueBuilder(options);
}
exports.taskQueue = taskQueue;

View File

@@ -0,0 +1,184 @@
import { CloudFunction, EventContext } from "../cloud-functions";
/** Handle events related to Test Lab test matrices. */
export declare function testMatrix(): TestMatrixBuilder;
/** Builder used to create Cloud Functions for Test Lab test matrices events. */
export declare class TestMatrixBuilder {
private triggerResource;
private options;
/** Handle a TestMatrix that reached a final test state. */
onComplete(handler: (testMatrix: TestMatrix, context: EventContext) => PromiseLike<any> | any): CloudFunction<TestMatrix>;
}
/** TestMatrix captures details about a test run. */
export declare class TestMatrix {
/** Unique id set by the service. */
testMatrixId: string;
/** When this test matrix was initially created (ISO8601 timestamp). */
createTime: string;
/** Indicates the current progress of the test matrix */
state: TestState;
/**
* The overall outcome of the test matrix run. Only set when the test matrix
* state is FINISHED.
*/
outcomeSummary?: OutcomeSummary;
/** For 'INVALID' matrices only, describes why the matrix is invalid. */
invalidMatrixDetails?: InvalidMatrixDetails;
/** Where the results for the matrix are located. */
resultStorage: ResultStorage;
/** Information about the client which invoked the test. */
clientInfo: ClientInfo;
}
/** Information about the client which invoked the test. */
export declare class ClientInfo {
/** Client name, e.g. 'gcloud'. */
name: string;
/** Map of detailed information about the client which invoked the test. */
details: {
[key: string]: string;
};
}
/** Locations where the test results are stored. */
export declare class ResultStorage {
/** A storage location within Google Cloud Storage (GCS) for the test artifacts. */
gcsPath?: string;
/** Id of the ToolResults History containing these results. */
toolResultsHistoryId?: string;
/**
* Id of the ToolResults execution that the detailed TestMatrix results are
* written to.
*/
toolResultsExecutionId?: string;
/** URL to test results in Firebase Console. */
resultsUrl?: string;
}
/**
* The detailed reason that a Matrix was deemed INVALID.
*
* @remarks
* Possible values:
*
* - `DETAILS_UNAVAILABLE`: The matrix is INVALID, but there are no further details available.
*
* - `MALFORMED_APK`: The input app APK could not be parsed.
*
* - `MALFORMED_TEST_APK`: The input test APK could not be parsed.
*
* - `NO_MANIFEST`: The AndroidManifest.xml could not be found.
*
* - `NO_PACKAGE_NAME`: The APK manifest does not declare a package name.
*
* - `INVALID_PACKAGE_NAME`: The APK application ID is invalid.
*
* - `TEST_SAME_AS_APP`: The test package and app package are the same.
*
* - `NO_INSTRUMENTATION`: The test apk does not declare an instrumentation.
*
* - `NO_SIGNATURE`: The input app apk does not have a signature.
*
* - `INSTRUMENTATION_ORCHESTRATOR_INCOMPATIBLE`: The test runner class specified by
* user or in the test APK`s manifest file is not compatible with Android Test Orchestrator.
*
* - `NO_TEST_RUNNER_CLASS`: The test APK does not contain the test runner class
* specified by user or in the manifest file.
*
* - `NO_LAUNCHER_ACTIVITY`: A main launcher activity could not be found.
*
* - `FORBIDDEN_PERMISSIONS`: The app declares one or more permissions that are
* not allowed.
*
* - `INVALID_ROBO_DIRECTIVES`: There is a conflict in the provided
* robo_directives.
*
* - `INVALID_RESOURCE_NAME`: There is at least one invalid resource name in the
* provided robo directives.
*
* - `INVALID_DIRECTIVE_ACTION`: Invalid definition of action in the robo
* directives, e.g. a click or ignore action includes an input text field.
*
* - `TEST_LOOP_INTENT_FILTER_NOT_FOUND`: There is no test loop intent filter,
* or the one that is given is not formatted correctly.
*
* - `SCENARIO_LABEL_NOT_DECLARED`: The request contains a scenario label that
* was not declared in the manifest.
*
* - `SCENARIO_LABEL_MALFORMED`: There was an error when parsing a label value.
*
* - `SCENARIO_NOT_DECLARED`: The request contains a scenario number that was
* not declared in the manifest.
*
* - `DEVICE_ADMIN_RECEIVER`: Device administrator applications are not allowed.
*
* - `MALFORMED_XC_TEST_ZIP`: The zipped XCTest was malformed. The zip did not ]
* contain a single .xctestrun file and the contents of the
* DerivedData/Build/Products directory.
*
* - `BUILT_FOR_IOS_SIMULATOR`: The zipped XCTest was built for the iOS
* simulator rather than for a physical device.
*
* - `NO_TESTS_IN_XC_TEST_ZIP`: The .xctestrun file did not specify any test
* targets.
*
* - `USE_DESTINATION_ARTIFACTS`: One or more of the test targets defined in the
* .xctestrun file specifies "UseDestinationArtifacts", which is disallowed.
*
* - `TEST_NOT_APP_HOSTED`: XC tests which run on physical devices must have
* "IsAppHostedTestBundle" == "true" in the xctestrun file.
*
* - `PLIST_CANNOT_BE_PARSED`: An Info.plist file in the XCTest zip could not be
* parsed.
*
* - `NO_CODE_APK`: APK contains no code.
*
* - `INVALID_INPUT_APK`: Either the provided input APK path was malformed, the
* APK file does not exist, or the user does not have permission to access the
* APK file.
*
* - `INVALID_APK_PREVIEW_SDK`: APK is built for a preview SDK which is
* unsupported.
*/
export type InvalidMatrixDetails = "DETAILS_UNAVAILABLE" | "MALFORMED_APK" | "MALFORMED_TEST_APK" | "NO_MANIFEST" | "NO_PACKAGE_NAME" | "INVALID_PACKAGE_NAME" | "TEST_SAME_AS_APP" | "NO_INSTRUMENTATION" | "NO_SIGNATURE" | "INSTRUMENTATION_ORCHESTRATOR_INCOMPATIBLE" | "NO_TEST_RUNNER_CLASS" | "NO_LAUNCHER_ACTIVITY" | "FORBIDDEN_PERMISSIONS" | "INVALID_ROBO_DIRECTIVES" | "INVALID_RESOURCE_NAME" | "INVALID_DIRECTIVE_ACTION" | "TEST_LOOP_INTENT_FILTER_NOT_FOUND" | "SCENARIO_LABEL_NOT_DECLARED" | "SCENARIO_LABEL_MALFORMED" | "SCENARIO_NOT_DECLARED" | "DEVICE_ADMIN_RECEIVER" | "MALFORMED_XC_TEST_ZIP" | "BUILT_FOR_IOS_SIMULATOR" | "NO_TESTS_IN_XC_TEST_ZIP" | "USE_DESTINATION_ARTIFACTS" | "TEST_NOT_APP_HOSTED" | "PLIST_CANNOT_BE_PARSED" | "NO_CODE_APK" | "INVALID_INPUT_APK" | "INVALID_APK_PREVIEW_SDK";
/**
* The state (i.e. progress) of a TestMatrix.
*
* @remarks
* Possible values:
*
* - `VALIDATING`: The matrix is being validated.
*
* - `PENDING`: The matrix is waiting for resources to become available.
*
* - `FINISHED`: The matrix has terminated normally. This means that the matrix
* level processing completed normally, but individual executions may be in an
* ERROR state.
*
* - `ERROR`: The matrix has stopped because it encountered an infrastructure
* failure.
*
* - `INVALID`: The matrix was not run because the provided inputs are not
* valid. E.g. the input file is not of the expected type, or is
* malformed/corrupt.
*/
export type TestState = "VALIDATING" | "PENDING" | "FINISHED" | "ERROR" | "INVALID";
/**
* Outcome summary for a finished TestMatrix.
*
* @remarks
* Possible values:
*
* - `SUCCESS`: The test matrix run was successful, for instance:
* - All the test cases passed.
* - Robo did not detect a crash of the application under test.
*
* - `FAILURE`: The test run failed, for instance:
* - One or more test cases failed.
* - A test timed out.
* - The application under test crashed.
*
* - `INCONCLUSIVE`: Something unexpected happened. The run should still be
* considered unsuccessful but this is likely a transient problem and
* re-running the test might be successful.
*
* - `SKIPPED`: All tests were skipped, for instance:
* - All device configurations were incompatible.
*/
export type OutcomeSummary = "SUCCESS" | "FAILURE" | "INCONCLUSIVE" | "SKIPPED";

View File

@@ -0,0 +1,108 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2019 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResultStorage = exports.ClientInfo = exports.TestMatrix = exports.TestMatrixBuilder = exports._testMatrixWithOpts = exports.testMatrix = exports.TEST_MATRIX_COMPLETE_EVENT_TYPE = exports.SERVICE = exports.PROVIDER = void 0;
const cloud_functions_1 = require("../cloud-functions");
/** @internal */
exports.PROVIDER = "google.testing";
/** @internal */
exports.SERVICE = "testing.googleapis.com";
/** @internal */
exports.TEST_MATRIX_COMPLETE_EVENT_TYPE = "testMatrix.complete";
/** Handle events related to Test Lab test matrices. */
function testMatrix() {
return _testMatrixWithOpts({});
}
exports.testMatrix = testMatrix;
/** @internal */
function _testMatrixWithOpts(opts) {
return new TestMatrixBuilder(() => {
if (!process.env.GCLOUD_PROJECT) {
throw new Error("process.env.GCLOUD_PROJECT is not set.");
}
return "projects/" + process.env.GCLOUD_PROJECT + "/testMatrices/{matrix}";
}, opts);
}
exports._testMatrixWithOpts = _testMatrixWithOpts;
/** Builder used to create Cloud Functions for Test Lab test matrices events. */
class TestMatrixBuilder {
/** @internal */
constructor(triggerResource, options) {
this.triggerResource = triggerResource;
this.options = options;
}
/** Handle a TestMatrix that reached a final test state. */
onComplete(handler) {
const dataConstructor = (raw) => {
return new TestMatrix(raw.data);
};
return (0, cloud_functions_1.makeCloudFunction)({
provider: exports.PROVIDER,
eventType: exports.TEST_MATRIX_COMPLETE_EVENT_TYPE,
triggerResource: this.triggerResource,
service: exports.SERVICE,
dataConstructor,
handler,
options: this.options,
});
}
}
exports.TestMatrixBuilder = TestMatrixBuilder;
/** TestMatrix captures details about a test run. */
class TestMatrix {
/** @internal */
constructor(data) {
this.testMatrixId = data.testMatrixId;
this.createTime = data.timestamp;
this.state = data.state;
this.outcomeSummary = data.outcomeSummary;
this.invalidMatrixDetails = data.invalidMatrixDetails;
this.resultStorage = new ResultStorage(data.resultStorage);
this.clientInfo = new ClientInfo(data.clientInfo);
}
}
exports.TestMatrix = TestMatrix;
/** Information about the client which invoked the test. */
class ClientInfo {
/** @internal */
constructor(data) {
this.name = (data === null || data === void 0 ? void 0 : data.name) || "";
this.details = {};
for (const detail of (data === null || data === void 0 ? void 0 : data.clientInfoDetails) || []) {
this.details[detail.key] = detail.value || "";
}
}
}
exports.ClientInfo = ClientInfo;
/** Locations where the test results are stored. */
class ResultStorage {
/** @internal */
constructor(data) {
var _a, _b, _c;
this.gcsPath = (_a = data === null || data === void 0 ? void 0 : data.googleCloudStorage) === null || _a === void 0 ? void 0 : _a.gcsPath;
this.toolResultsHistoryId = (_b = data === null || data === void 0 ? void 0 : data.toolResultsHistory) === null || _b === void 0 ? void 0 : _b.historyId;
this.toolResultsExecutionId = (_c = data === null || data === void 0 ? void 0 : data.toolResultsExecution) === null || _c === void 0 ? void 0 : _c.executionId;
this.resultsUrl = data === null || data === void 0 ? void 0 : data.resultsUrl;
}
}
exports.ResultStorage = ResultStorage;