initial commit
This commit is contained in:
84
server/node_modules/firebase-admin/lib/eventarc/cloudevent.d.ts
generated
vendored
Normal file
84
server/node_modules/firebase-admin/lib/eventarc/cloudevent.d.ts
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* A CloudEvent version.
|
||||
*/
|
||||
export type CloudEventVersion = '1.0';
|
||||
/**
|
||||
* A CloudEvent describes event data.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
|
||||
*/
|
||||
export interface CloudEvent {
|
||||
/**
|
||||
* Identifier for the event. If not provided, it is auto-populated with a UUID.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#id
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* Identifies the context in which an event happened. If not provided, the value of `EVENTARC_CLOUD_EVENT_SOURCE`
|
||||
* environment variable is used and if that is not set, a validation error is thrown.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#source-1
|
||||
*/
|
||||
source?: string;
|
||||
/**
|
||||
* The version of the CloudEvents specification which the event uses. If not provided, is set to `1.0` --
|
||||
* the only supported value.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion
|
||||
*/
|
||||
specversion?: CloudEventVersion;
|
||||
/**
|
||||
* Type of the event. Should be prefixed with a reverse-DNS name (`com.my-org.v1.something.happended`).
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#type
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* Subject (context) of the event in the context of the event producer.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
|
||||
*/
|
||||
subject?: string;
|
||||
/**
|
||||
* MIME type of the data being sent with the event in the `data` field. Only `application/json` and `text/plain`
|
||||
* are currently supported. If not specified, it is automatically inferred from the type of provided data.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype
|
||||
*/
|
||||
datacontenttype?: string;
|
||||
/**
|
||||
* Timestamp of the event. Must be in ISO time format. If not specified, current time (at the moment of publishing)
|
||||
* is used.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#time
|
||||
*/
|
||||
time?: string;
|
||||
/**
|
||||
* Data payload of the event. Objects are stringified with JSON and strings are be passed along as-is.
|
||||
*/
|
||||
data?: object | string;
|
||||
/**
|
||||
* Custom attributes/extensions. Must be strings. Added to the event as is.
|
||||
*
|
||||
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes
|
||||
*/
|
||||
[key: string]: any;
|
||||
}
|
||||
19
server/node_modules/firebase-admin/lib/eventarc/cloudevent.js
generated
vendored
Normal file
19
server/node_modules/firebase-admin/lib/eventarc/cloudevent.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
18
server/node_modules/firebase-admin/lib/eventarc/eventarc-client-internal.d.ts
generated
vendored
Normal file
18
server/node_modules/firebase-admin/lib/eventarc/eventarc-client-internal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export {};
|
||||
139
server/node_modules/firebase-admin/lib/eventarc/eventarc-client-internal.js
generated
vendored
Normal file
139
server/node_modules/firebase-admin/lib/eventarc/eventarc-client-internal.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EventarcApiClient = void 0;
|
||||
const validator = require("../utils/validator");
|
||||
const eventarc_utils_1 = require("./eventarc-utils");
|
||||
const api_request_1 = require("../utils/api-request");
|
||||
const utils = require("../utils");
|
||||
const error_1 = require("../utils/error");
|
||||
const EVENTARC_API = 'https://eventarcpublishing.googleapis.com/v1';
|
||||
const FIREBASE_VERSION_HEADER = {
|
||||
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
|
||||
};
|
||||
const CHANNEL_NAME_REGEX = /^(projects\/([^/]+)\/)?locations\/([^/]+)\/channels\/([^/]+)$/;
|
||||
const DEFAULT_CHANNEL_REGION = 'us-central1';
|
||||
/**
|
||||
* Class that facilitates sending requests to the Eventarc backend API.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class EventarcApiClient {
|
||||
constructor(app, channel) {
|
||||
this.app = app;
|
||||
this.channel = channel;
|
||||
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Channel() must be a valid Eventarc service instance.');
|
||||
}
|
||||
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
||||
this.resolvedChannelName = this.resolveChannelName(channel.name);
|
||||
}
|
||||
getProjectId() {
|
||||
if (this.projectId) {
|
||||
return Promise.resolve(this.projectId);
|
||||
}
|
||||
return utils.findProjectId(this.app)
|
||||
.then((projectId) => {
|
||||
if (!validator.isNonEmptyString(projectId)) {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('unknown-error', 'Failed to determine project ID. Initialize the '
|
||||
+ 'SDK with service account credentials or set project ID as an app option. '
|
||||
+ 'Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.');
|
||||
}
|
||||
this.projectId = projectId;
|
||||
return projectId;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Publishes provided events to this channel. If channel was created with `allowedEventsTypes` and event type
|
||||
* is not on that list, the event is ignored.
|
||||
*
|
||||
* The following CloudEvent fields are auto-populated if not set:
|
||||
* * specversion - `1.0`
|
||||
* * id - uuidv4()
|
||||
* * source - populated with `process.env.EVENTARC_CLOUD_EVENT_SOURCE` and
|
||||
* if not set an error is thrown.
|
||||
*
|
||||
* @param events - CloudEvent to publish to the channel.
|
||||
*/
|
||||
async publish(events) {
|
||||
if (!Array.isArray(events)) {
|
||||
events = [events];
|
||||
}
|
||||
return this.publishToEventarcApi(await this.resolvedChannelName, events
|
||||
.filter(e => typeof this.channel.allowedEventTypes === 'undefined' ||
|
||||
this.channel.allowedEventTypes.includes(e.type))
|
||||
.map(eventarc_utils_1.toCloudEventProtoFormat));
|
||||
}
|
||||
async publishToEventarcApi(channel, events) {
|
||||
if (events.length === 0) {
|
||||
return;
|
||||
}
|
||||
const request = {
|
||||
method: 'POST',
|
||||
url: `${this.getEventarcHost()}/${channel}:publishEvents`,
|
||||
data: JSON.stringify({ events }),
|
||||
};
|
||||
return this.sendRequest(request);
|
||||
}
|
||||
sendRequest(request) {
|
||||
request.headers = FIREBASE_VERSION_HEADER;
|
||||
return this.httpClient.send(request)
|
||||
.then(() => undefined)
|
||||
.catch((err) => {
|
||||
throw this.toFirebaseError(err);
|
||||
});
|
||||
}
|
||||
toFirebaseError(err) {
|
||||
if (err instanceof error_1.PrefixedFirebaseError) {
|
||||
return err;
|
||||
}
|
||||
const response = err.response;
|
||||
return new eventarc_utils_1.FirebaseEventarcError('unknown-error', `Unexpected response with status: ${response.status} and body: ${response.text}`);
|
||||
}
|
||||
resolveChannelName(name) {
|
||||
if (!name.includes('/')) {
|
||||
const location = DEFAULT_CHANNEL_REGION;
|
||||
const channelId = name;
|
||||
return this.resolveChannelNameProjectId(location, channelId);
|
||||
}
|
||||
else {
|
||||
const match = CHANNEL_NAME_REGEX.exec(name);
|
||||
if (match === null || match.length < 4) {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'Invalid channel name format.');
|
||||
}
|
||||
const projectId = match[2];
|
||||
const location = match[3];
|
||||
const channelId = match[4];
|
||||
if (validator.isNonEmptyString(projectId)) {
|
||||
return Promise.resolve(`projects/${projectId}/locations/${location}/channels/${channelId}`);
|
||||
}
|
||||
else {
|
||||
return this.resolveChannelNameProjectId(location, channelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
async resolveChannelNameProjectId(location, channelId) {
|
||||
const projectId = await this.getProjectId();
|
||||
return `projects/${projectId}/locations/${location}/channels/${channelId}`;
|
||||
}
|
||||
getEventarcHost() {
|
||||
return process.env.CLOUD_EVENTARC_EMULATOR_HOST ?? EVENTARC_API;
|
||||
}
|
||||
}
|
||||
exports.EventarcApiClient = EventarcApiClient;
|
||||
31
server/node_modules/firebase-admin/lib/eventarc/eventarc-utils.d.ts
generated
vendored
Normal file
31
server/node_modules/firebase-admin/lib/eventarc/eventarc-utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PrefixedFirebaseError } from '../utils/error';
|
||||
import { CloudEvent } from './cloudevent';
|
||||
export type EventarcErrorCode = 'unknown-error' | 'invalid-argument';
|
||||
/**
|
||||
* Firebase Eventarc error code structure. This extends PrefixedFirebaseError.
|
||||
*
|
||||
* @param code - The error code.
|
||||
* @param message - The error message.
|
||||
* @constructor
|
||||
*/
|
||||
export declare class FirebaseEventarcError extends PrefixedFirebaseError {
|
||||
constructor(code: EventarcErrorCode, message: string);
|
||||
}
|
||||
export declare function toCloudEventProtoFormat(ce: CloudEvent): any;
|
||||
125
server/node_modules/firebase-admin/lib/eventarc/eventarc-utils.js
generated
vendored
Normal file
125
server/node_modules/firebase-admin/lib/eventarc/eventarc-utils.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FirebaseEventarcError = void 0;
|
||||
exports.toCloudEventProtoFormat = toCloudEventProtoFormat;
|
||||
const error_1 = require("../utils/error");
|
||||
const uuid_1 = require("uuid");
|
||||
const validator = require("../utils/validator");
|
||||
// List of CloudEvent properties that are handled "by hand" and should be skipped by
|
||||
// automatic attribute copy.
|
||||
const TOP_LEVEL_CE_ATTRS = ['id', 'type', 'specversion', 'source', 'data', 'time', 'datacontenttype', 'subject'];
|
||||
/**
|
||||
* Firebase Eventarc error code structure. This extends PrefixedFirebaseError.
|
||||
*
|
||||
* @param code - The error code.
|
||||
* @param message - The error message.
|
||||
* @constructor
|
||||
*/
|
||||
class FirebaseEventarcError extends error_1.PrefixedFirebaseError {
|
||||
constructor(code, message) {
|
||||
super('eventarc', code, message);
|
||||
}
|
||||
}
|
||||
exports.FirebaseEventarcError = FirebaseEventarcError;
|
||||
function toCloudEventProtoFormat(ce) {
|
||||
const source = ce.source ?? process.env.EVENTARC_CLOUD_EVENT_SOURCE;
|
||||
if (typeof source === 'undefined' || !validator.isNonEmptyString(source)) {
|
||||
throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'source' is required.");
|
||||
}
|
||||
if (!validator.isNonEmptyString(ce.type)) {
|
||||
throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'type' is required.");
|
||||
}
|
||||
const out = {
|
||||
'@type': 'type.googleapis.com/io.cloudevents.v1.CloudEvent',
|
||||
'id': ce.id ?? (0, uuid_1.v4)(),
|
||||
'type': ce.type,
|
||||
'specVersion': ce.specversion ?? '1.0',
|
||||
'source': source
|
||||
};
|
||||
if (typeof ce.time !== 'undefined') {
|
||||
if (!validator.isISODateString(ce.time)) {
|
||||
throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'tyme' must be in ISO date format.");
|
||||
}
|
||||
setAttribute(out, 'time', {
|
||||
'ceTimestamp': ce.time
|
||||
});
|
||||
}
|
||||
else {
|
||||
setAttribute(out, 'time', {
|
||||
'ceTimestamp': new Date().toISOString()
|
||||
});
|
||||
}
|
||||
if (typeof ce.datacontenttype !== 'undefined') {
|
||||
if (!validator.isNonEmptyString(ce.datacontenttype)) {
|
||||
throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'datacontenttype' if specified must be non-empty string.");
|
||||
}
|
||||
setAttribute(out, 'datacontenttype', {
|
||||
'ceString': ce.datacontenttype
|
||||
});
|
||||
}
|
||||
if (ce.subject) {
|
||||
if (!validator.isNonEmptyString(ce.subject)) {
|
||||
throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'subject' if specified must be non-empty string.");
|
||||
}
|
||||
setAttribute(out, 'subject', {
|
||||
'ceString': ce.subject
|
||||
});
|
||||
}
|
||||
if (typeof ce.data === 'undefined') {
|
||||
throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'data' is required.");
|
||||
}
|
||||
if (validator.isObject(ce.data)) {
|
||||
out['textData'] = JSON.stringify(ce.data);
|
||||
if (!ce.datacontenttype) {
|
||||
setAttribute(out, 'datacontenttype', {
|
||||
'ceString': 'application/json'
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (validator.isNonEmptyString(ce.data)) {
|
||||
out['textData'] = ce.data;
|
||||
if (!ce.datacontenttype) {
|
||||
setAttribute(out, 'datacontenttype', {
|
||||
'ceString': 'text/plain'
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new FirebaseEventarcError('invalid-argument', `CloudEvent 'data' must be string or an object (which are converted to JSON), got '${typeof ce.data}'.`);
|
||||
}
|
||||
for (const attr in ce) {
|
||||
if (TOP_LEVEL_CE_ATTRS.includes(attr)) {
|
||||
continue;
|
||||
}
|
||||
if (!validator.isNonEmptyString(ce[attr])) {
|
||||
throw new FirebaseEventarcError('invalid-argument', `CloudEvent extension attributes ('${attr}') must be string.`);
|
||||
}
|
||||
setAttribute(out, attr, {
|
||||
'ceString': ce[attr]
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function setAttribute(event, attr, value) {
|
||||
if (!Object.prototype.hasOwnProperty.call(event, 'attributes')) {
|
||||
event.attributes = {};
|
||||
}
|
||||
event['attributes'][attr] = value;
|
||||
}
|
||||
107
server/node_modules/firebase-admin/lib/eventarc/eventarc.d.ts
generated
vendored
Normal file
107
server/node_modules/firebase-admin/lib/eventarc/eventarc.d.ts
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { CloudEvent } from './cloudevent';
|
||||
/**
|
||||
* Channel options interface.
|
||||
*/
|
||||
export interface ChannelOptions {
|
||||
/**
|
||||
* An array of allowed event types. If specified, publishing events of
|
||||
* unknown types is a no op. When not provided, no event filtering is
|
||||
* performed.
|
||||
*/
|
||||
allowedEventTypes?: string[] | string | undefined;
|
||||
}
|
||||
/**
|
||||
* Eventarc service bound to the provided app.
|
||||
*/
|
||||
export declare class Eventarc {
|
||||
private readonly appInternal;
|
||||
/**
|
||||
* The {@link firebase-admin.app#App} associated with the current Eventarc service
|
||||
* instance.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* var app = eventarc.app;
|
||||
* ```
|
||||
*/
|
||||
get app(): App;
|
||||
/**
|
||||
* Creates a reference to the Eventarc channel using the provided channel resource name.
|
||||
* The channel resource name can be either:
|
||||
*
|
||||
* - A fully qualified channel resource name:
|
||||
* `projects/{project}/locations/{location}/channels/{channel-id}`
|
||||
*
|
||||
* - A partial resource name with location and channel ID, in which case
|
||||
* the runtime project ID of the function is used:
|
||||
* `locations/{location}/channels/{channel-id}`
|
||||
*
|
||||
* - A partial channel ID, in which case the runtime project ID of the
|
||||
* function and `us-central1` as location is used:
|
||||
* `{channel-id}`
|
||||
*
|
||||
* @param name - Channel resource name.
|
||||
* @param options - (optional) additional channel options
|
||||
* @returns An Eventarc channel reference for publishing events.
|
||||
*/
|
||||
channel(name: string, options?: ChannelOptions): Channel;
|
||||
/**
|
||||
* Create a reference to the default Firebase channel:
|
||||
* `locations/us-central1/channels/firebase`
|
||||
*
|
||||
* @param options - (optional) additional channel options
|
||||
* @returns Eventarc channel reference for publishing events.
|
||||
*/
|
||||
channel(options?: ChannelOptions): Channel;
|
||||
}
|
||||
/**
|
||||
* Eventarc Channel.
|
||||
*/
|
||||
export declare class Channel {
|
||||
private readonly eventarcInternal;
|
||||
private nameInternal;
|
||||
/**
|
||||
* List of event types allowed by this channel for publishing. Other event types are ignored.
|
||||
*/
|
||||
readonly allowedEventTypes?: string[];
|
||||
private readonly client;
|
||||
/**
|
||||
* The {@link firebase-admin.eventarc#Eventarc} service instance associated with the current `Channel`.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* var app = channel.eventarc;
|
||||
* ```
|
||||
*/
|
||||
get eventarc(): Eventarc;
|
||||
/**
|
||||
* The channel name as provided during channel creation. If it was not specifed, the default channel name is returned
|
||||
* ('locations/us-central1/channels/firebase').
|
||||
*/
|
||||
get name(): string;
|
||||
/**
|
||||
* Publishes provided events to this channel. If channel was created with `allowedEventTypes` and event type is not
|
||||
* on that list, the event is ignored.
|
||||
*
|
||||
* @param events - CloudEvent to publish to the channel.
|
||||
*/
|
||||
publish(events: CloudEvent | CloudEvent[]): Promise<void>;
|
||||
}
|
||||
125
server/node_modules/firebase-admin/lib/eventarc/eventarc.js
generated
vendored
Normal file
125
server/node_modules/firebase-admin/lib/eventarc/eventarc.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Channel = exports.Eventarc = void 0;
|
||||
const validator = require("../utils/validator");
|
||||
const eventarc_utils_1 = require("./eventarc-utils");
|
||||
const eventarc_client_internal_1 = require("./eventarc-client-internal");
|
||||
/**
|
||||
* Eventarc service bound to the provided app.
|
||||
*/
|
||||
class Eventarc {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(app) {
|
||||
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Eventarc() must be a valid Firebase app instance.');
|
||||
}
|
||||
this.appInternal = app;
|
||||
}
|
||||
/**
|
||||
* The {@link firebase-admin.app#App} associated with the current Eventarc service
|
||||
* instance.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* var app = eventarc.app;
|
||||
* ```
|
||||
*/
|
||||
get app() {
|
||||
return this.appInternal;
|
||||
}
|
||||
channel(nameOrOptions, options) {
|
||||
let channel;
|
||||
let opts;
|
||||
if (validator.isNonEmptyString(nameOrOptions)) {
|
||||
channel = nameOrOptions;
|
||||
}
|
||||
else {
|
||||
channel = 'locations/us-central1/channels/firebase';
|
||||
}
|
||||
if (validator.isNonNullObject(nameOrOptions)) {
|
||||
opts = nameOrOptions;
|
||||
}
|
||||
else {
|
||||
opts = options;
|
||||
}
|
||||
let allowedEventTypes = undefined;
|
||||
if (typeof opts?.allowedEventTypes === 'string') {
|
||||
allowedEventTypes = opts.allowedEventTypes.split(',');
|
||||
}
|
||||
else if (validator.isArray(opts?.allowedEventTypes)) {
|
||||
allowedEventTypes = opts?.allowedEventTypes;
|
||||
}
|
||||
else if (typeof opts?.allowedEventTypes !== 'undefined') {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'AllowedEventTypes must be either an array of strings or a comma separated string.');
|
||||
}
|
||||
return new Channel(this, channel, allowedEventTypes);
|
||||
}
|
||||
}
|
||||
exports.Eventarc = Eventarc;
|
||||
/**
|
||||
* Eventarc Channel.
|
||||
*/
|
||||
class Channel {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(eventarc, name, allowedEventTypes) {
|
||||
if (!validator.isNonNullObject(eventarc)) {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Channel() must be a valid Eventarc service instance.');
|
||||
}
|
||||
if (!validator.isNonEmptyString(name)) {
|
||||
throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'name is required.');
|
||||
}
|
||||
this.nameInternal = name;
|
||||
this.eventarcInternal = eventarc;
|
||||
this.allowedEventTypes = allowedEventTypes;
|
||||
this.client = new eventarc_client_internal_1.EventarcApiClient(eventarc.app, this);
|
||||
}
|
||||
/**
|
||||
* The {@link firebase-admin.eventarc#Eventarc} service instance associated with the current `Channel`.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* var app = channel.eventarc;
|
||||
* ```
|
||||
*/
|
||||
get eventarc() {
|
||||
return this.eventarcInternal;
|
||||
}
|
||||
/**
|
||||
* The channel name as provided during channel creation. If it was not specifed, the default channel name is returned
|
||||
* ('locations/us-central1/channels/firebase').
|
||||
*/
|
||||
get name() {
|
||||
return this.nameInternal;
|
||||
}
|
||||
/**
|
||||
* Publishes provided events to this channel. If channel was created with `allowedEventTypes` and event type is not
|
||||
* on that list, the event is ignored.
|
||||
*
|
||||
* @param events - CloudEvent to publish to the channel.
|
||||
*/
|
||||
publish(events) {
|
||||
return this.client.publish(events);
|
||||
}
|
||||
}
|
||||
exports.Channel = Channel;
|
||||
53
server/node_modules/firebase-admin/lib/eventarc/index.d.ts
generated
vendored
Normal file
53
server/node_modules/firebase-admin/lib/eventarc/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Firebase Eventarc.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { Eventarc } from './eventarc';
|
||||
export { CloudEvent, CloudEventVersion } from './cloudevent';
|
||||
export { Eventarc, Channel, ChannelOptions } from './eventarc';
|
||||
/**
|
||||
* Gets the {@link Eventarc} service for the default app or a given app.
|
||||
*
|
||||
* `getEventarc()` can be called with no arguments to access the default
|
||||
* app's `Eventarc` service or as `getEventarc(app)` to access the
|
||||
* `Eventarc` service associated with specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Eventarc service for the default app
|
||||
* const defaultEventarc = getEventarc();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Eventarc service for a given app
|
||||
* const otherEventarc = getEventarc(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app whose `Eventarc` service will be returned.
|
||||
* If not provided, the default `Eventarc` service will be returned.
|
||||
*
|
||||
* @returns The default `Eventarc` service if no
|
||||
* app is provided or the `Eventarc` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
export declare function getEventarc(app?: App): Eventarc;
|
||||
64
server/node_modules/firebase-admin/lib/eventarc/index.js
generated
vendored
Normal file
64
server/node_modules/firebase-admin/lib/eventarc/index.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Channel = exports.Eventarc = void 0;
|
||||
exports.getEventarc = getEventarc;
|
||||
/**
|
||||
* Firebase Eventarc.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
const app_1 = require("../app");
|
||||
const eventarc_1 = require("./eventarc");
|
||||
var eventarc_2 = require("./eventarc");
|
||||
Object.defineProperty(exports, "Eventarc", { enumerable: true, get: function () { return eventarc_2.Eventarc; } });
|
||||
Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return eventarc_2.Channel; } });
|
||||
/**
|
||||
* Gets the {@link Eventarc} service for the default app or a given app.
|
||||
*
|
||||
* `getEventarc()` can be called with no arguments to access the default
|
||||
* app's `Eventarc` service or as `getEventarc(app)` to access the
|
||||
* `Eventarc` service associated with specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Eventarc service for the default app
|
||||
* const defaultEventarc = getEventarc();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Eventarc service for a given app
|
||||
* const otherEventarc = getEventarc(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app whose `Eventarc` service will be returned.
|
||||
* If not provided, the default `Eventarc` service will be returned.
|
||||
*
|
||||
* @returns The default `Eventarc` service if no
|
||||
* app is provided or the `Eventarc` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
function getEventarc(app) {
|
||||
if (typeof app === 'undefined') {
|
||||
app = (0, app_1.getApp)();
|
||||
}
|
||||
const firebaseApp = app;
|
||||
return firebaseApp.getOrInitService('eventarc', (app) => new eventarc_1.Eventarc(app));
|
||||
}
|
||||
Reference in New Issue
Block a user