UNPKG

3.66 kBTypeScriptView Raw
1/*! firebase-admin v12.0.0 */
2/*!
3 * @license
4 * Copyright 2022 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18import { App } from '../app';
19import { CloudEvent } from './cloudevent';
20/**
21 * Channel options interface.
22 */
23export interface ChannelOptions {
24 /**
25 * An array of allowed event types. If specified, publishing events of
26 * unknown types is a no op. When not provided, no event filtering is
27 * performed.
28 */
29 allowedEventTypes?: string[] | string | undefined;
30}
31/**
32 * Eventarc service bound to the provided app.
33 */
34export declare class Eventarc {
35 private readonly appInternal;
36 /**
37 * The {@link firebase-admin.app#App} associated with the current Eventarc service
38 * instance.
39 *
40 * @example
41 * ```javascript
42 * var app = eventarc.app;
43 * ```
44 */
45 get app(): App;
46 /**
47 * Creates a reference to the Eventarc channel using the provided channel resource name.
48 * The channel resource name can be either:
49 *
50 * - A fully qualified channel resource name:
51 * `projects/{project}/locations/{location}/channels/{channel-id}`
52 *
53 * - A partial resource name with location and channel ID, in which case
54 * the runtime project ID of the function is used:
55 * `locations/{location}/channels/{channel-id}`
56 *
57 * - A partial channel ID, in which case the runtime project ID of the
58 * function and `us-central1` as location is used:
59 * `{channel-id}`
60 *
61 * @param name - Channel resource name.
62 * @param options - (optional) additional channel options
63 * @returns An Eventarc channel reference for publishing events.
64 */
65 channel(name: string, options?: ChannelOptions): Channel;
66 /**
67 * Create a reference to the default Firebase channel:
68 * `locations/us-central1/channels/firebase`
69 *
70 * @param options - (optional) additional channel options
71 * @returns Eventarc channel reference for publishing events.
72 */
73 channel(options?: ChannelOptions): Channel;
74}
75/**
76 * Eventarc Channel.
77 */
78export declare class Channel {
79 private readonly eventarcInternal;
80 private nameInternal;
81 /**
82 * List of event types allowed by this channel for publishing. Other event types are ignored.
83 */
84 readonly allowedEventTypes?: string[];
85 private readonly client;
86 /**
87 * The {@link firebase-admin.eventarc#Eventarc} service instance associated with the current `Channel`.
88 *
89 * @example
90 * ```javascript
91 * var app = channel.eventarc;
92 * ```
93 */
94 get eventarc(): Eventarc;
95 /**
96 * The channel name as provided during channel creation. If it was not specifed, the default channel name is returned
97 * ('locations/us-central1/channels/firebase').
98 */
99 get name(): string;
100 /**
101 * Publishes provided events to this channel. If channel was created with `allowedEventTypes` and event type is not
102 * on that list, the event is ignored.
103 *
104 * @param events - CloudEvent to publish to the channel.
105 */
106 publish(events: CloudEvent | CloudEvent[]): Promise<void>;
107}