firebase-admin 10.0.1 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/lib/app/core.d.ts +1 -1
  2. package/lib/app/core.js +1 -1
  3. package/lib/app/credential-factory.d.ts +1 -1
  4. package/lib/app/credential-factory.js +1 -1
  5. package/lib/app/credential-internal.d.ts +3 -1
  6. package/lib/app/credential-internal.js +19 -1
  7. package/lib/app/credential.d.ts +1 -1
  8. package/lib/app/credential.js +1 -1
  9. package/lib/app/firebase-app.d.ts +1 -1
  10. package/lib/app/firebase-app.js +4 -1
  11. package/lib/app/firebase-namespace.d.ts +1 -1
  12. package/lib/app/firebase-namespace.js +1 -1
  13. package/lib/app/index.d.ts +1 -1
  14. package/lib/app/index.js +1 -1
  15. package/lib/app/lifecycle.d.ts +1 -1
  16. package/lib/app/lifecycle.js +1 -1
  17. package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
  18. package/lib/app-check/app-check-api-client-internal.js +3 -3
  19. package/lib/app-check/app-check-api.d.ts +1 -1
  20. package/lib/app-check/app-check-api.js +1 -1
  21. package/lib/app-check/app-check-namespace.d.ts +1 -1
  22. package/lib/app-check/app-check-namespace.js +1 -1
  23. package/lib/app-check/app-check.d.ts +1 -1
  24. package/lib/app-check/app-check.js +1 -1
  25. package/lib/app-check/index.d.ts +1 -1
  26. package/lib/app-check/index.js +1 -1
  27. package/lib/app-check/token-generator.d.ts +1 -1
  28. package/lib/app-check/token-generator.js +3 -5
  29. package/lib/app-check/token-verifier.d.ts +1 -1
  30. package/lib/app-check/token-verifier.js +2 -3
  31. package/lib/auth/action-code-settings-builder.d.ts +1 -1
  32. package/lib/auth/action-code-settings-builder.js +1 -1
  33. package/lib/auth/auth-api-request.d.ts +1 -1
  34. package/lib/auth/auth-api-request.js +24 -4
  35. package/lib/auth/auth-config.d.ts +1 -1
  36. package/lib/auth/auth-config.js +1 -1
  37. package/lib/auth/auth-namespace.d.ts +4 -2
  38. package/lib/auth/auth-namespace.js +1 -1
  39. package/lib/auth/auth.d.ts +1 -1
  40. package/lib/auth/auth.js +1 -1
  41. package/lib/auth/base-auth.d.ts +29 -2
  42. package/lib/auth/base-auth.js +38 -1
  43. package/lib/auth/identifier.d.ts +1 -1
  44. package/lib/auth/identifier.js +1 -1
  45. package/lib/auth/index.d.ts +2 -2
  46. package/lib/auth/index.js +1 -1
  47. package/lib/auth/tenant-manager.d.ts +1 -1
  48. package/lib/auth/tenant-manager.js +1 -1
  49. package/lib/auth/tenant.d.ts +1 -1
  50. package/lib/auth/tenant.js +1 -1
  51. package/lib/auth/token-generator.d.ts +1 -1
  52. package/lib/auth/token-generator.js +2 -2
  53. package/lib/auth/token-verifier.d.ts +70 -1
  54. package/lib/auth/token-verifier.js +54 -7
  55. package/lib/auth/user-import-builder.d.ts +1 -1
  56. package/lib/auth/user-import-builder.js +1 -1
  57. package/lib/auth/user-record.d.ts +1 -1
  58. package/lib/auth/user-record.js +1 -1
  59. package/lib/credential/index.d.ts +1 -1
  60. package/lib/credential/index.js +1 -1
  61. package/lib/database/database-namespace.d.ts +1 -1
  62. package/lib/database/database-namespace.js +1 -1
  63. package/lib/database/database.d.ts +1 -1
  64. package/lib/database/database.js +1 -1
  65. package/lib/database/index.d.ts +1 -1
  66. package/lib/database/index.js +2 -1
  67. package/lib/default-namespace.d.ts +1 -1
  68. package/lib/default-namespace.js +1 -1
  69. package/lib/esm/eventarc/index.js +5 -0
  70. package/lib/esm/functions/index.js +5 -0
  71. package/lib/eventarc/cloudevent.d.ts +84 -0
  72. package/lib/eventarc/cloudevent.js +19 -0
  73. package/lib/eventarc/eventarc-client-internal.d.ts +18 -0
  74. package/lib/eventarc/eventarc-client-internal.js +205 -0
  75. package/lib/eventarc/eventarc-utils.d.ts +31 -0
  76. package/lib/eventarc/eventarc-utils.js +141 -0
  77. package/lib/eventarc/eventarc.d.ts +107 -0
  78. package/lib/eventarc/eventarc.js +139 -0
  79. package/lib/eventarc/index.d.ts +53 -0
  80. package/lib/eventarc/index.js +64 -0
  81. package/lib/firebase-namespace-api.d.ts +1 -1
  82. package/lib/firebase-namespace-api.js +1 -1
  83. package/lib/firestore/firestore-internal.d.ts +1 -1
  84. package/lib/firestore/firestore-internal.js +1 -1
  85. package/lib/firestore/firestore-namespace.d.ts +1 -1
  86. package/lib/firestore/firestore-namespace.js +1 -1
  87. package/lib/firestore/index.d.ts +1 -1
  88. package/lib/firestore/index.js +1 -1
  89. package/lib/functions/functions-api-client-internal.d.ts +32 -0
  90. package/lib/functions/functions-api-client-internal.js +279 -0
  91. package/lib/functions/functions-api.d.ts +67 -0
  92. package/lib/functions/functions-api.js +19 -0
  93. package/lib/functions/functions.d.ts +63 -0
  94. package/lib/functions/functions.js +99 -0
  95. package/lib/functions/index.d.ts +53 -0
  96. package/lib/functions/index.js +64 -0
  97. package/lib/index.d.ts +1 -1
  98. package/lib/index.js +1 -1
  99. package/lib/installations/index.d.ts +1 -1
  100. package/lib/installations/index.js +1 -1
  101. package/lib/installations/installations-namespace.d.ts +1 -1
  102. package/lib/installations/installations-namespace.js +1 -1
  103. package/lib/installations/installations-request-handler.d.ts +1 -1
  104. package/lib/installations/installations-request-handler.js +1 -1
  105. package/lib/installations/installations.d.ts +1 -1
  106. package/lib/installations/installations.js +1 -1
  107. package/lib/instance-id/index.d.ts +1 -1
  108. package/lib/instance-id/index.js +1 -1
  109. package/lib/instance-id/instance-id-namespace.d.ts +1 -1
  110. package/lib/instance-id/instance-id-namespace.js +1 -1
  111. package/lib/instance-id/instance-id.d.ts +1 -1
  112. package/lib/instance-id/instance-id.js +1 -1
  113. package/lib/machine-learning/index.d.ts +1 -1
  114. package/lib/machine-learning/index.js +1 -1
  115. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  116. package/lib/machine-learning/machine-learning-api-client.js +1 -1
  117. package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
  118. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  119. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  120. package/lib/machine-learning/machine-learning-utils.js +1 -1
  121. package/lib/machine-learning/machine-learning.d.ts +1 -1
  122. package/lib/machine-learning/machine-learning.js +1 -1
  123. package/lib/messaging/batch-request-internal.d.ts +1 -1
  124. package/lib/messaging/batch-request-internal.js +1 -1
  125. package/lib/messaging/index.d.ts +1 -1
  126. package/lib/messaging/index.js +1 -1
  127. package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
  128. package/lib/messaging/messaging-api-request-internal.js +1 -1
  129. package/lib/messaging/messaging-api.d.ts +1 -1
  130. package/lib/messaging/messaging-api.js +1 -1
  131. package/lib/messaging/messaging-errors-internal.d.ts +1 -1
  132. package/lib/messaging/messaging-errors-internal.js +1 -1
  133. package/lib/messaging/messaging-internal.d.ts +1 -1
  134. package/lib/messaging/messaging-internal.js +1 -1
  135. package/lib/messaging/messaging-namespace.d.ts +1 -1
  136. package/lib/messaging/messaging-namespace.js +1 -1
  137. package/lib/messaging/messaging.d.ts +1 -1
  138. package/lib/messaging/messaging.js +1 -2
  139. package/lib/project-management/android-app.d.ts +1 -1
  140. package/lib/project-management/android-app.js +1 -1
  141. package/lib/project-management/app-metadata.d.ts +1 -1
  142. package/lib/project-management/app-metadata.js +1 -1
  143. package/lib/project-management/index.d.ts +1 -1
  144. package/lib/project-management/index.js +1 -1
  145. package/lib/project-management/ios-app.d.ts +1 -1
  146. package/lib/project-management/ios-app.js +1 -1
  147. package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
  148. package/lib/project-management/project-management-api-request-internal.js +1 -1
  149. package/lib/project-management/project-management-namespace.d.ts +1 -1
  150. package/lib/project-management/project-management-namespace.js +1 -1
  151. package/lib/project-management/project-management.d.ts +1 -1
  152. package/lib/project-management/project-management.js +1 -1
  153. package/lib/remote-config/index.d.ts +1 -1
  154. package/lib/remote-config/index.js +1 -1
  155. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  156. package/lib/remote-config/remote-config-api-client-internal.js +1 -1
  157. package/lib/remote-config/remote-config-api.d.ts +1 -1
  158. package/lib/remote-config/remote-config-api.js +1 -1
  159. package/lib/remote-config/remote-config-namespace.d.ts +1 -1
  160. package/lib/remote-config/remote-config-namespace.js +1 -1
  161. package/lib/remote-config/remote-config.d.ts +1 -1
  162. package/lib/remote-config/remote-config.js +1 -1
  163. package/lib/security-rules/index.d.ts +1 -1
  164. package/lib/security-rules/index.js +1 -1
  165. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  166. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  167. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  168. package/lib/security-rules/security-rules-internal.js +1 -1
  169. package/lib/security-rules/security-rules-namespace.d.ts +1 -1
  170. package/lib/security-rules/security-rules-namespace.js +1 -1
  171. package/lib/security-rules/security-rules.d.ts +1 -1
  172. package/lib/security-rules/security-rules.js +1 -1
  173. package/lib/storage/index.d.ts +1 -1
  174. package/lib/storage/index.js +1 -1
  175. package/lib/storage/storage-namespace.d.ts +1 -1
  176. package/lib/storage/storage-namespace.js +1 -1
  177. package/lib/storage/storage.d.ts +1 -1
  178. package/lib/storage/storage.js +1 -1
  179. package/lib/utils/api-request.d.ts +1 -1
  180. package/lib/utils/api-request.js +1 -1
  181. package/lib/utils/crypto-signer.d.ts +1 -1
  182. package/lib/utils/crypto-signer.js +1 -1
  183. package/lib/utils/deep-copy.d.ts +1 -1
  184. package/lib/utils/deep-copy.js +1 -1
  185. package/lib/utils/error.d.ts +9 -1
  186. package/lib/utils/error.js +11 -1
  187. package/lib/utils/index.d.ts +43 -1
  188. package/lib/utils/index.js +72 -2
  189. package/lib/utils/jwt.d.ts +1 -1
  190. package/lib/utils/jwt.js +1 -1
  191. package/lib/utils/validator.d.ts +1 -1
  192. package/lib/utils/validator.js +1 -1
  193. package/package.json +32 -15
@@ -0,0 +1,205 @@
1
+ /*! firebase-admin v10.2.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2022 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
+ return new (P || (P = Promise))(function (resolve, reject) {
22
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ };
28
+ var __generator = (this && this.__generator) || function (thisArg, body) {
29
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
30
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
31
+ function verb(n) { return function (v) { return step([n, v]); }; }
32
+ function step(op) {
33
+ if (f) throw new TypeError("Generator is already executing.");
34
+ while (_) try {
35
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
36
+ if (y = 0, t) op = [op[0] & 2, t.value];
37
+ switch (op[0]) {
38
+ case 0: case 1: t = op; break;
39
+ case 4: _.label++; return { value: op[1], done: false };
40
+ case 5: _.label++; y = op[1]; op = [0]; continue;
41
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
42
+ default:
43
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
44
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
45
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
46
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
47
+ if (t[2]) _.ops.pop();
48
+ _.trys.pop(); continue;
49
+ }
50
+ op = body.call(thisArg, _);
51
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
52
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
53
+ }
54
+ };
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.EventarcApiClient = void 0;
57
+ var validator = require("../utils/validator");
58
+ var eventarc_utils_1 = require("./eventarc-utils");
59
+ var api_request_1 = require("../utils/api-request");
60
+ var utils = require("../utils");
61
+ var error_1 = require("../utils/error");
62
+ var EVENTARC_API = 'https://eventarcpublishing.googleapis.com/v1';
63
+ var FIREBASE_VERSION_HEADER = {
64
+ 'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion(),
65
+ };
66
+ var CHANNEL_NAME_REGEX = /^(projects\/([^/]+)\/)?locations\/([^/]+)\/channels\/([^/]+)$/;
67
+ var DEFAULT_CHANNEL_REGION = 'us-central1';
68
+ /**
69
+ * Class that facilitates sending requests to the Eventarc backend API.
70
+ *
71
+ * @internal
72
+ */
73
+ var EventarcApiClient = /** @class */ (function () {
74
+ function EventarcApiClient(app, channel) {
75
+ this.app = app;
76
+ this.channel = channel;
77
+ if (!validator.isNonNullObject(app) || !('options' in app)) {
78
+ throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Channel() must be a valid Eventarc service instance.');
79
+ }
80
+ this.httpClient = new api_request_1.AuthorizedHttpClient(app);
81
+ this.resolvedChannelName = this.resolveChannelName(channel.name);
82
+ }
83
+ EventarcApiClient.prototype.getProjectId = function () {
84
+ var _this = this;
85
+ if (this.projectId) {
86
+ return Promise.resolve(this.projectId);
87
+ }
88
+ return utils.findProjectId(this.app)
89
+ .then(function (projectId) {
90
+ if (!validator.isNonEmptyString(projectId)) {
91
+ throw new eventarc_utils_1.FirebaseEventarcError('unknown-error', 'Failed to determine project ID. Initialize the '
92
+ + 'SDK with service account credentials or set project ID as an app option. '
93
+ + 'Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.');
94
+ }
95
+ _this.projectId = projectId;
96
+ return projectId;
97
+ });
98
+ };
99
+ /**
100
+ * Publishes provided events to this channel. If channel was created with `allowedEventsTypes` and event type
101
+ * is not on that list, the event is ignored.
102
+ *
103
+ * The following CloudEvent fields are auto-populated if not set:
104
+ * * specversion - `1.0`
105
+ * * id - uuidv4()
106
+ * * source - populated with `process.env.EVENTARC_CLOUD_EVENT_SOURCE` and
107
+ * if not set an error is thrown.
108
+ *
109
+ * @param events - CloudEvent to publish to the channel.
110
+ */
111
+ EventarcApiClient.prototype.publish = function (events) {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var _a;
114
+ var _this = this;
115
+ return __generator(this, function (_b) {
116
+ switch (_b.label) {
117
+ case 0:
118
+ if (!Array.isArray(events)) {
119
+ events = [events];
120
+ }
121
+ _a = this.publishToEventarcApi;
122
+ return [4 /*yield*/, this.resolvedChannelName];
123
+ case 1: return [2 /*return*/, _a.apply(this, [_b.sent(),
124
+ events
125
+ .filter(function (e) { return typeof _this.channel.allowedEventTypes === 'undefined' ||
126
+ _this.channel.allowedEventTypes.includes(e.type); })
127
+ .map(eventarc_utils_1.toCloudEventProtoFormat)])];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ EventarcApiClient.prototype.publishToEventarcApi = function (channel, events) {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ var request;
135
+ return __generator(this, function (_a) {
136
+ if (events.length === 0) {
137
+ return [2 /*return*/];
138
+ }
139
+ request = {
140
+ method: 'POST',
141
+ url: this.getEventarcHost() + "/" + channel + ":publishEvents",
142
+ data: JSON.stringify({ events: events }),
143
+ };
144
+ return [2 /*return*/, this.sendRequest(request)];
145
+ });
146
+ });
147
+ };
148
+ EventarcApiClient.prototype.sendRequest = function (request) {
149
+ var _this = this;
150
+ request.headers = FIREBASE_VERSION_HEADER;
151
+ return this.httpClient.send(request)
152
+ .then(function () { return undefined; })
153
+ .catch(function (err) {
154
+ throw _this.toFirebaseError(err);
155
+ });
156
+ };
157
+ EventarcApiClient.prototype.toFirebaseError = function (err) {
158
+ if (err instanceof error_1.PrefixedFirebaseError) {
159
+ return err;
160
+ }
161
+ var response = err.response;
162
+ return new eventarc_utils_1.FirebaseEventarcError('unknown-error', "Unexpected response with status: " + response.status + " and body: " + response.text);
163
+ };
164
+ EventarcApiClient.prototype.resolveChannelName = function (name) {
165
+ if (!name.includes('/')) {
166
+ var location = DEFAULT_CHANNEL_REGION;
167
+ var channelId = name;
168
+ return this.resolveChannelNameProjectId(location, channelId);
169
+ }
170
+ else {
171
+ var match = CHANNEL_NAME_REGEX.exec(name);
172
+ if (match === null || match.length < 4) {
173
+ throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'Invalid channel name format.');
174
+ }
175
+ var projectId = match[2];
176
+ var location = match[3];
177
+ var channelId = match[4];
178
+ if (validator.isNonEmptyString(projectId)) {
179
+ return Promise.resolve("projects/" + projectId + "/locations/" + location + "/channels/" + channelId);
180
+ }
181
+ else {
182
+ return this.resolveChannelNameProjectId(location, channelId);
183
+ }
184
+ }
185
+ };
186
+ EventarcApiClient.prototype.resolveChannelNameProjectId = function (location, channelId) {
187
+ return __awaiter(this, void 0, void 0, function () {
188
+ var projectId;
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, this.getProjectId()];
192
+ case 1:
193
+ projectId = _a.sent();
194
+ return [2 /*return*/, "projects/" + projectId + "/locations/" + location + "/channels/" + channelId];
195
+ }
196
+ });
197
+ });
198
+ };
199
+ EventarcApiClient.prototype.getEventarcHost = function () {
200
+ var _a;
201
+ return (_a = process.env.CLOUD_EVENTARC_EMULATOR_HOST) !== null && _a !== void 0 ? _a : EVENTARC_API;
202
+ };
203
+ return EventarcApiClient;
204
+ }());
205
+ exports.EventarcApiClient = EventarcApiClient;
@@ -0,0 +1,31 @@
1
+ /*! firebase-admin v10.2.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
+ */
18
+ import { PrefixedFirebaseError } from '../utils/error';
19
+ import { CloudEvent } from './cloudevent';
20
+ export declare type EventarcErrorCode = 'unknown-error' | 'invalid-argument';
21
+ /**
22
+ * Firebase Eventarc error code structure. This extends PrefixedFirebaseError.
23
+ *
24
+ * @param code - The error code.
25
+ * @param message - The error message.
26
+ * @constructor
27
+ */
28
+ export declare class FirebaseEventarcError extends PrefixedFirebaseError {
29
+ constructor(code: EventarcErrorCode, message: string);
30
+ }
31
+ export declare function toCloudEventProtoFormat(ce: CloudEvent): any;
@@ -0,0 +1,141 @@
1
+ /*! firebase-admin v10.2.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2022 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __extends = (this && this.__extends) || (function () {
20
+ var extendStatics = function (d, b) {
21
+ extendStatics = Object.setPrototypeOf ||
22
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
24
+ return extendStatics(d, b);
25
+ };
26
+ return function (d, b) {
27
+ extendStatics(d, b);
28
+ function __() { this.constructor = d; }
29
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
+ };
31
+ })();
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.toCloudEventProtoFormat = exports.FirebaseEventarcError = void 0;
34
+ var error_1 = require("../utils/error");
35
+ var uuid_1 = require("uuid");
36
+ var validator = require("../utils/validator");
37
+ // List of CloudEvent properties that are handled "by hand" and should be skipped by
38
+ // automatic attribute copy.
39
+ var TOP_LEVEL_CE_ATTRS = ['id', 'type', 'specversion', 'source', 'data', 'time', 'datacontenttype', 'subject'];
40
+ /**
41
+ * Firebase Eventarc error code structure. This extends PrefixedFirebaseError.
42
+ *
43
+ * @param code - The error code.
44
+ * @param message - The error message.
45
+ * @constructor
46
+ */
47
+ var FirebaseEventarcError = /** @class */ (function (_super) {
48
+ __extends(FirebaseEventarcError, _super);
49
+ function FirebaseEventarcError(code, message) {
50
+ return _super.call(this, 'eventarc', code, message) || this;
51
+ }
52
+ return FirebaseEventarcError;
53
+ }(error_1.PrefixedFirebaseError));
54
+ exports.FirebaseEventarcError = FirebaseEventarcError;
55
+ function toCloudEventProtoFormat(ce) {
56
+ var _a, _b, _c;
57
+ var source = (_a = ce.source) !== null && _a !== void 0 ? _a : process.env.EVENTARC_CLOUD_EVENT_SOURCE;
58
+ if (typeof source === 'undefined' || !validator.isNonEmptyString(source)) {
59
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'source' is required.");
60
+ }
61
+ if (!validator.isNonEmptyString(ce.type)) {
62
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'type' is required.");
63
+ }
64
+ var out = {
65
+ '@type': 'type.googleapis.com/io.cloudevents.v1.CloudEvent',
66
+ 'id': (_b = ce.id) !== null && _b !== void 0 ? _b : uuid_1.v4(),
67
+ 'type': ce.type,
68
+ 'specVersion': (_c = ce.specversion) !== null && _c !== void 0 ? _c : '1.0',
69
+ 'source': source
70
+ };
71
+ if (typeof ce.time !== 'undefined') {
72
+ if (!validator.isISODateString(ce.time)) {
73
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'tyme' must be in ISO date format.");
74
+ }
75
+ setAttribute(out, 'time', {
76
+ 'ceTimestamp': ce.time
77
+ });
78
+ }
79
+ else {
80
+ setAttribute(out, 'time', {
81
+ 'ceTimestamp': new Date().toISOString()
82
+ });
83
+ }
84
+ if (typeof ce.datacontenttype !== 'undefined') {
85
+ if (!validator.isNonEmptyString(ce.datacontenttype)) {
86
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'datacontenttype' if specified must be non-empty string.");
87
+ }
88
+ setAttribute(out, 'datacontenttype', {
89
+ 'ceString': ce.datacontenttype
90
+ });
91
+ }
92
+ if (ce.subject) {
93
+ if (!validator.isNonEmptyString(ce.subject)) {
94
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'subject' if specified must be non-empty string.");
95
+ }
96
+ setAttribute(out, 'subject', {
97
+ 'ceString': ce.subject
98
+ });
99
+ }
100
+ if (typeof ce.data === 'undefined') {
101
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'data' is required.");
102
+ }
103
+ if (validator.isObject(ce.data)) {
104
+ out['textData'] = JSON.stringify(ce.data);
105
+ if (!ce.datacontenttype) {
106
+ setAttribute(out, 'datacontenttype', {
107
+ 'ceString': 'application/json'
108
+ });
109
+ }
110
+ }
111
+ else if (validator.isNonEmptyString(ce.data)) {
112
+ out['textData'] = ce.data;
113
+ if (!ce.datacontenttype) {
114
+ setAttribute(out, 'datacontenttype', {
115
+ 'ceString': 'text/plain'
116
+ });
117
+ }
118
+ }
119
+ else {
120
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent 'data' must be string or an object (which are converted to JSON), got '" + typeof ce.data + "'.");
121
+ }
122
+ for (var attr in ce) {
123
+ if (TOP_LEVEL_CE_ATTRS.includes(attr)) {
124
+ continue;
125
+ }
126
+ if (!validator.isNonEmptyString(ce[attr])) {
127
+ throw new FirebaseEventarcError('invalid-argument', "CloudEvent extension attributes ('" + attr + "') must be string.");
128
+ }
129
+ setAttribute(out, attr, {
130
+ 'ceString': ce[attr]
131
+ });
132
+ }
133
+ return out;
134
+ }
135
+ exports.toCloudEventProtoFormat = toCloudEventProtoFormat;
136
+ function setAttribute(event, attr, value) {
137
+ if (!Object.prototype.hasOwnProperty.call(event, 'attributes')) {
138
+ event.attributes = {};
139
+ }
140
+ event['attributes'][attr] = value;
141
+ }
@@ -0,0 +1,107 @@
1
+ /*! firebase-admin v10.2.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
+ */
18
+ import { App } from '../app';
19
+ import { CloudEvent } from './cloudevent';
20
+ /**
21
+ * Channel options interface.
22
+ */
23
+ export 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
+ */
34
+ export 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
+ */
78
+ export 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
+ }
@@ -0,0 +1,139 @@
1
+ /*! firebase-admin v10.2.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2022 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.Channel = exports.Eventarc = void 0;
21
+ var validator = require("../utils/validator");
22
+ var eventarc_utils_1 = require("./eventarc-utils");
23
+ var eventarc_client_internal_1 = require("./eventarc-client-internal");
24
+ /**
25
+ * Eventarc service bound to the provided app.
26
+ */
27
+ var Eventarc = /** @class */ (function () {
28
+ /**
29
+ * @internal
30
+ */
31
+ function Eventarc(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
+ Object.defineProperty(Eventarc.prototype, "app", {
38
+ /**
39
+ * The {@link firebase-admin.app#App} associated with the current Eventarc service
40
+ * instance.
41
+ *
42
+ * @example
43
+ * ```javascript
44
+ * var app = eventarc.app;
45
+ * ```
46
+ */
47
+ get: function () {
48
+ return this.appInternal;
49
+ },
50
+ enumerable: false,
51
+ configurable: true
52
+ });
53
+ Eventarc.prototype.channel = function (nameOrOptions, options) {
54
+ var channel;
55
+ var opts;
56
+ if (validator.isNonEmptyString(nameOrOptions)) {
57
+ channel = nameOrOptions;
58
+ }
59
+ else {
60
+ channel = 'locations/us-central1/channels/firebase';
61
+ }
62
+ if (validator.isNonNullObject(nameOrOptions)) {
63
+ opts = nameOrOptions;
64
+ }
65
+ else {
66
+ opts = options;
67
+ }
68
+ var allowedEventTypes = undefined;
69
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.allowedEventTypes) === 'string') {
70
+ allowedEventTypes = opts.allowedEventTypes.split(',');
71
+ }
72
+ else if (validator.isArray(opts === null || opts === void 0 ? void 0 : opts.allowedEventTypes)) {
73
+ allowedEventTypes = opts === null || opts === void 0 ? void 0 : opts.allowedEventTypes;
74
+ }
75
+ else if (typeof (opts === null || opts === void 0 ? void 0 : opts.allowedEventTypes) !== 'undefined') {
76
+ throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'AllowedEventTypes must be either an array of strings or a comma separated string.');
77
+ }
78
+ return new Channel(this, channel, allowedEventTypes);
79
+ };
80
+ return Eventarc;
81
+ }());
82
+ exports.Eventarc = Eventarc;
83
+ /**
84
+ * Eventarc Channel.
85
+ */
86
+ var Channel = /** @class */ (function () {
87
+ /**
88
+ * @internal
89
+ */
90
+ function Channel(eventarc, name, allowedEventTypes) {
91
+ if (!validator.isNonNullObject(eventarc)) {
92
+ throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'First argument passed to Channel() must be a valid Eventarc service instance.');
93
+ }
94
+ if (!validator.isNonEmptyString(name)) {
95
+ throw new eventarc_utils_1.FirebaseEventarcError('invalid-argument', 'name is required.');
96
+ }
97
+ this.nameInternal = name;
98
+ this.eventarcInternal = eventarc;
99
+ this.allowedEventTypes = allowedEventTypes;
100
+ this.client = new eventarc_client_internal_1.EventarcApiClient(eventarc.app, this);
101
+ }
102
+ Object.defineProperty(Channel.prototype, "eventarc", {
103
+ /**
104
+ * The {@link firebase-admin.eventarc#Eventarc} service instance associated with the current `Channel`.
105
+ *
106
+ * @example
107
+ * ```javascript
108
+ * var app = channel.eventarc;
109
+ * ```
110
+ */
111
+ get: function () {
112
+ return this.eventarcInternal;
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Object.defineProperty(Channel.prototype, "name", {
118
+ /**
119
+ * The channel name as provided during channel creation. If it was not specifed, the default channel name is returned
120
+ * ('locations/us-central1/channels/firebase').
121
+ */
122
+ get: function () {
123
+ return this.nameInternal;
124
+ },
125
+ enumerable: false,
126
+ configurable: true
127
+ });
128
+ /**
129
+ * Publishes provided events to this channel. If channel was created with `allowedEventTypes` and event type is not
130
+ * on that list, the event is ignored.
131
+ *
132
+ * @param events - CloudEvent to publish to the channel.
133
+ */
134
+ Channel.prototype.publish = function (events) {
135
+ return this.client.publish(events);
136
+ };
137
+ return Channel;
138
+ }());
139
+ exports.Channel = Channel;
@@ -0,0 +1,53 @@
1
+ /*! firebase-admin v10.2.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
+ */
18
+ /**
19
+ * Firebase Eventarc.
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ import { App } from '../app';
24
+ import { Eventarc } from './eventarc';
25
+ export { CloudEvent, CloudEventVersion } from './cloudevent';
26
+ export { Eventarc, Channel, ChannelOptions } from './eventarc';
27
+ /**
28
+ * Gets the {@link Eventarc} service for the default app or a given app.
29
+ *
30
+ * `getEventarc()` can be called with no arguments to access the default
31
+ * app's `Eventarc` service or as `getEventarc(app)` to access the
32
+ * `Eventarc` service associated with specific app.
33
+ *
34
+ * @example
35
+ * ```javascript
36
+ * // Get the Eventarc service for the default app
37
+ * const defaultEventarc = getEventarc();
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```javascript
42
+ * // Get the Eventarc service for a given app
43
+ * const otherEventarc = getEventarc(otherApp);
44
+ * ```
45
+ *
46
+ * @param app - Optional app whose `Eventarc` service will be returned.
47
+ * If not provided, the default `Eventarc` service will be returned.
48
+ *
49
+ * @returns The default `Eventarc` service if no
50
+ * app is provided or the `Eventarc` service associated with the provided
51
+ * app.
52
+ */
53
+ export declare function getEventarc(app?: App): Eventarc;