firebase-admin 10.1.0 → 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 +18 -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 +1 -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 +2 -2
  29. package/lib/app-check/token-verifier.d.ts +1 -1
  30. package/lib/app-check/token-verifier.js +2 -2
  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 +1 -1
  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 +26 -1
  42. package/lib/auth/base-auth.js +28 -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 +1 -1
  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 +1 -1
  53. package/lib/auth/token-verifier.d.ts +1 -1
  54. package/lib/auth/token-verifier.js +1 -1
  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 +1 -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 -1
  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 +5 -1
  186. package/lib/utils/error.js +7 -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 +22 -5
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  /*!
3
3
  * Copyright 2020 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2020 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  /*!
3
3
  * Copyright 2020 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2020 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  /*!
3
3
  * Copyright 2020 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.1.0 */
1
+ /*! firebase-admin v10.2.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -0,0 +1,5 @@
1
+ import mod from "../../eventarc/index.js";
2
+
3
+ export const Channel = mod.Channel;
4
+ export const Eventarc = mod.Eventarc;
5
+ export const getEventarc = mod.getEventarc;
@@ -0,0 +1,5 @@
1
+ import mod from "../../functions/index.js";
2
+
3
+ export const Functions = mod.Functions;
4
+ export const TaskQueue = mod.TaskQueue;
5
+ export const getFunctions = mod.getFunctions;
@@ -0,0 +1,84 @@
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
+ * A CloudEvent version.
20
+ */
21
+ export declare type CloudEventVersion = '1.0';
22
+ /**
23
+ * A CloudEvent describes event data.
24
+ *
25
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
26
+ */
27
+ export interface CloudEvent {
28
+ /**
29
+ * Identifier for the event. If not provided, it is auto-populated with a UUID.
30
+ *
31
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#id
32
+ */
33
+ id?: string;
34
+ /**
35
+ * Identifies the context in which an event happened. If not provided, the value of `EVENTARC_CLOUD_EVENT_SOURCE`
36
+ * environment variable is used and if that is not set, a validation error is thrown.
37
+ *
38
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#source-1
39
+ */
40
+ source?: string;
41
+ /**
42
+ * The version of the CloudEvents specification which the event uses. If not provided, is set to `1.0` --
43
+ * the only supported value.
44
+ *
45
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion
46
+ */
47
+ specversion?: CloudEventVersion;
48
+ /**
49
+ * Type of the event. Should be prefixed with a reverse-DNS name (`com.my-org.v1.something.happended`).
50
+ *
51
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#type
52
+ */
53
+ type: string;
54
+ /**
55
+ * Subject (context) of the event in the context of the event producer.
56
+ *
57
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
58
+ */
59
+ subject?: string;
60
+ /**
61
+ * MIME type of the data being sent with the event in the `data` field. Only `application/json` and `text/plain`
62
+ * are currently supported. If not specified, it is automatically inferred from the type of provided data.
63
+ *
64
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype
65
+ */
66
+ datacontenttype?: string;
67
+ /**
68
+ * Timestamp of the event. Must be in ISO time format. If not specified, current time (at the moment of publishing)
69
+ * is used.
70
+ *
71
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#time
72
+ */
73
+ time?: string;
74
+ /**
75
+ * Data payload of the event. Objects are stringified with JSON and strings are be passed along as-is.
76
+ */
77
+ data?: object | string;
78
+ /**
79
+ * Custom attributes/extensions. Must be strings. Added to the event as is.
80
+ *
81
+ * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes
82
+ */
83
+ [key: string]: any;
84
+ }
@@ -0,0 +1,19 @@
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 });
@@ -0,0 +1,18 @@
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
+ export {};
@@ -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
+ }