1 |
|
2 | "use strict";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | Object.defineProperty(exports, "__esModule", { value: true });
|
20 | exports.Channel = exports.Eventarc = void 0;
|
21 | const validator = require("../utils/validator");
|
22 | const eventarc_utils_1 = require("./eventarc-utils");
|
23 | const eventarc_client_internal_1 = require("./eventarc-client-internal");
|
24 |
|
25 |
|
26 |
|
27 | class Eventarc {
|
28 | |
29 |
|
30 |
|
31 | constructor(app) {
|
32 | if (!validator.isNonNullObject(app) || !('options' in app)) {
|
33 | throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Eventarc() must be a valid Firebase app instance.');
|
34 | }
|
35 | this.appInternal = app;
|
36 | }
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | get app() {
|
47 | return this.appInternal;
|
48 | }
|
49 | channel(nameOrOptions, options) {
|
50 | let channel;
|
51 | let opts;
|
52 | if (validator.isNonEmptyString(nameOrOptions)) {
|
53 | channel = nameOrOptions;
|
54 | }
|
55 | else {
|
56 | channel = 'locations/us-central1/channels/firebase';
|
57 | }
|
58 | if (validator.isNonNullObject(nameOrOptions)) {
|
59 | opts = nameOrOptions;
|
60 | }
|
61 | else {
|
62 | opts = options;
|
63 | }
|
64 | let allowedEventTypes = undefined;
|
65 | if (typeof opts?.allowedEventTypes === 'string') {
|
66 | allowedEventTypes = opts.allowedEventTypes.split(',');
|
67 | }
|
68 | else if (validator.isArray(opts?.allowedEventTypes)) {
|
69 | allowedEventTypes = opts?.allowedEventTypes;
|
70 | }
|
71 | else if (typeof opts?.allowedEventTypes !== 'undefined') {
|
72 | throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'AllowedEventTypes must be either an array of strings or a comma separated string.');
|
73 | }
|
74 | return new Channel(this, channel, allowedEventTypes);
|
75 | }
|
76 | }
|
77 | exports.Eventarc = Eventarc;
|
78 |
|
79 |
|
80 |
|
81 | class Channel {
|
82 | |
83 |
|
84 |
|
85 | constructor(eventarc, name, allowedEventTypes) {
|
86 | if (!validator.isNonNullObject(eventarc)) {
|
87 | throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Channel() must be a valid Eventarc service instance.');
|
88 | }
|
89 | if (!validator.isNonEmptyString(name)) {
|
90 | throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'name is required.');
|
91 | }
|
92 | this.nameInternal = name;
|
93 | this.eventarcInternal = eventarc;
|
94 | this.allowedEventTypes = allowedEventTypes;
|
95 | this.client = new eventarc_client_internal_1.EventarcApiClient(eventarc.app, this);
|
96 | }
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | get eventarc() {
|
106 | return this.eventarcInternal;
|
107 | }
|
108 | |
109 |
|
110 |
|
111 |
|
112 | get name() {
|
113 | return this.nameInternal;
|
114 | }
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | publish(events) {
|
122 | return this.client.publish(events);
|
123 | }
|
124 | }
|
125 | exports.Channel = Channel;
|