firebase-admin 11.2.0 → 11.3.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 (204) 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 +1 -1
  6. package/lib/app/credential-internal.js +1 -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 +1 -1
  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 +1 -1
  29. package/lib/app-check/token-verifier.d.ts +1 -1
  30. package/lib/app-check/token-verifier.js +1 -1
  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 +1 -1
  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 +1 -1
  42. package/lib/auth/base-auth.js +1 -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/project-config-manager.d.ts +1 -1
  48. package/lib/auth/project-config-manager.js +1 -1
  49. package/lib/auth/project-config.d.ts +1 -1
  50. package/lib/auth/project-config.js +1 -1
  51. package/lib/auth/tenant-manager.d.ts +1 -1
  52. package/lib/auth/tenant-manager.js +1 -1
  53. package/lib/auth/tenant.d.ts +1 -1
  54. package/lib/auth/tenant.js +1 -1
  55. package/lib/auth/token-generator.d.ts +1 -1
  56. package/lib/auth/token-generator.js +1 -1
  57. package/lib/auth/token-verifier.d.ts +1 -1
  58. package/lib/auth/token-verifier.js +1 -1
  59. package/lib/auth/user-import-builder.d.ts +1 -1
  60. package/lib/auth/user-import-builder.js +1 -1
  61. package/lib/auth/user-record.d.ts +1 -1
  62. package/lib/auth/user-record.js +1 -1
  63. package/lib/credential/index.d.ts +1 -1
  64. package/lib/credential/index.js +1 -1
  65. package/lib/database/database-namespace.d.ts +1 -1
  66. package/lib/database/database-namespace.js +1 -1
  67. package/lib/database/database.d.ts +1 -1
  68. package/lib/database/database.js +1 -1
  69. package/lib/database/index.d.ts +1 -1
  70. package/lib/database/index.js +1 -1
  71. package/lib/default-namespace.d.ts +1 -1
  72. package/lib/default-namespace.js +1 -1
  73. package/lib/esm/extensions/index.js +5 -0
  74. package/lib/eventarc/cloudevent.d.ts +1 -1
  75. package/lib/eventarc/cloudevent.js +1 -1
  76. package/lib/eventarc/eventarc-client-internal.d.ts +1 -1
  77. package/lib/eventarc/eventarc-client-internal.js +1 -1
  78. package/lib/eventarc/eventarc-utils.d.ts +1 -1
  79. package/lib/eventarc/eventarc-utils.js +1 -1
  80. package/lib/eventarc/eventarc.d.ts +1 -1
  81. package/lib/eventarc/eventarc.js +1 -1
  82. package/lib/eventarc/index.d.ts +1 -1
  83. package/lib/eventarc/index.js +1 -1
  84. package/lib/extensions/extensions-api-client-internal.d.ts +30 -0
  85. package/lib/extensions/extensions-api-client-internal.js +105 -0
  86. package/lib/extensions/extensions-api.d.ts +44 -0
  87. package/lib/extensions/extensions-api.js +19 -0
  88. package/lib/extensions/extensions.d.ts +73 -0
  89. package/lib/extensions/extensions.js +122 -0
  90. package/lib/extensions/index.d.ts +53 -0
  91. package/lib/extensions/index.js +64 -0
  92. package/lib/firebase-namespace-api.d.ts +1 -1
  93. package/lib/firebase-namespace-api.js +1 -1
  94. package/lib/firestore/firestore-internal.d.ts +4 -4
  95. package/lib/firestore/firestore-internal.js +12 -6
  96. package/lib/firestore/firestore-namespace.d.ts +1 -1
  97. package/lib/firestore/firestore-namespace.js +1 -1
  98. package/lib/firestore/index.d.ts +17 -4
  99. package/lib/firestore/index.js +6 -33
  100. package/lib/functions/functions-api-client-internal.d.ts +1 -1
  101. package/lib/functions/functions-api-client-internal.js +1 -1
  102. package/lib/functions/functions-api.d.ts +1 -1
  103. package/lib/functions/functions-api.js +1 -1
  104. package/lib/functions/functions.d.ts +1 -1
  105. package/lib/functions/functions.js +1 -1
  106. package/lib/functions/index.d.ts +1 -1
  107. package/lib/functions/index.js +1 -1
  108. package/lib/index.d.ts +1 -1
  109. package/lib/index.js +1 -1
  110. package/lib/installations/index.d.ts +1 -1
  111. package/lib/installations/index.js +1 -1
  112. package/lib/installations/installations-namespace.d.ts +1 -1
  113. package/lib/installations/installations-namespace.js +1 -1
  114. package/lib/installations/installations-request-handler.d.ts +1 -1
  115. package/lib/installations/installations-request-handler.js +1 -1
  116. package/lib/installations/installations.d.ts +1 -1
  117. package/lib/installations/installations.js +1 -1
  118. package/lib/instance-id/index.d.ts +1 -1
  119. package/lib/instance-id/index.js +1 -1
  120. package/lib/instance-id/instance-id-namespace.d.ts +1 -1
  121. package/lib/instance-id/instance-id-namespace.js +1 -1
  122. package/lib/instance-id/instance-id.d.ts +1 -1
  123. package/lib/instance-id/instance-id.js +1 -1
  124. package/lib/machine-learning/index.d.ts +1 -1
  125. package/lib/machine-learning/index.js +1 -1
  126. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  127. package/lib/machine-learning/machine-learning-api-client.js +1 -1
  128. package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
  129. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  130. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  131. package/lib/machine-learning/machine-learning-utils.js +1 -1
  132. package/lib/machine-learning/machine-learning.d.ts +1 -1
  133. package/lib/machine-learning/machine-learning.js +1 -1
  134. package/lib/messaging/batch-request-internal.d.ts +1 -1
  135. package/lib/messaging/batch-request-internal.js +1 -1
  136. package/lib/messaging/index.d.ts +1 -1
  137. package/lib/messaging/index.js +1 -1
  138. package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
  139. package/lib/messaging/messaging-api-request-internal.js +2 -2
  140. package/lib/messaging/messaging-api.d.ts +1 -1
  141. package/lib/messaging/messaging-api.js +1 -1
  142. package/lib/messaging/messaging-errors-internal.d.ts +1 -1
  143. package/lib/messaging/messaging-errors-internal.js +1 -1
  144. package/lib/messaging/messaging-internal.d.ts +1 -1
  145. package/lib/messaging/messaging-internal.js +1 -1
  146. package/lib/messaging/messaging-namespace.d.ts +1 -1
  147. package/lib/messaging/messaging-namespace.js +1 -1
  148. package/lib/messaging/messaging.d.ts +1 -1
  149. package/lib/messaging/messaging.js +1 -1
  150. package/lib/project-management/android-app.d.ts +1 -1
  151. package/lib/project-management/android-app.js +1 -1
  152. package/lib/project-management/app-metadata.d.ts +1 -1
  153. package/lib/project-management/app-metadata.js +1 -1
  154. package/lib/project-management/index.d.ts +1 -1
  155. package/lib/project-management/index.js +1 -1
  156. package/lib/project-management/ios-app.d.ts +1 -1
  157. package/lib/project-management/ios-app.js +1 -1
  158. package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
  159. package/lib/project-management/project-management-api-request-internal.js +1 -1
  160. package/lib/project-management/project-management-namespace.d.ts +1 -1
  161. package/lib/project-management/project-management-namespace.js +1 -1
  162. package/lib/project-management/project-management.d.ts +1 -1
  163. package/lib/project-management/project-management.js +1 -1
  164. package/lib/remote-config/index.d.ts +1 -1
  165. package/lib/remote-config/index.js +1 -1
  166. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  167. package/lib/remote-config/remote-config-api-client-internal.js +1 -1
  168. package/lib/remote-config/remote-config-api.d.ts +1 -1
  169. package/lib/remote-config/remote-config-api.js +1 -1
  170. package/lib/remote-config/remote-config-namespace.d.ts +1 -1
  171. package/lib/remote-config/remote-config-namespace.js +1 -1
  172. package/lib/remote-config/remote-config.d.ts +1 -1
  173. package/lib/remote-config/remote-config.js +1 -1
  174. package/lib/security-rules/index.d.ts +1 -1
  175. package/lib/security-rules/index.js +1 -1
  176. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  177. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  178. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  179. package/lib/security-rules/security-rules-internal.js +1 -1
  180. package/lib/security-rules/security-rules-namespace.d.ts +1 -1
  181. package/lib/security-rules/security-rules-namespace.js +1 -1
  182. package/lib/security-rules/security-rules.d.ts +1 -1
  183. package/lib/security-rules/security-rules.js +1 -1
  184. package/lib/storage/index.d.ts +1 -1
  185. package/lib/storage/index.js +1 -1
  186. package/lib/storage/storage-namespace.d.ts +1 -1
  187. package/lib/storage/storage-namespace.js +1 -1
  188. package/lib/storage/storage.d.ts +1 -1
  189. package/lib/storage/storage.js +1 -1
  190. package/lib/utils/api-request.d.ts +1 -1
  191. package/lib/utils/api-request.js +1 -1
  192. package/lib/utils/crypto-signer.d.ts +1 -1
  193. package/lib/utils/crypto-signer.js +1 -1
  194. package/lib/utils/deep-copy.d.ts +1 -1
  195. package/lib/utils/deep-copy.js +1 -1
  196. package/lib/utils/error.d.ts +1 -1
  197. package/lib/utils/error.js +1 -1
  198. package/lib/utils/index.d.ts +1 -1
  199. package/lib/utils/index.js +1 -1
  200. package/lib/utils/jwt.d.ts +1 -1
  201. package/lib/utils/jwt.js +1 -1
  202. package/lib/utils/validator.d.ts +1 -1
  203. package/lib/utils/validator.js +1 -1
  204. package/package.json +10 -2
@@ -0,0 +1,105 @@
1
+ /*! firebase-admin v11.3.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.FirebaseExtensionsError = exports.ExtensionsApiClient = void 0;
21
+ const api_request_1 = require("../utils/api-request");
22
+ const error_1 = require("../utils/error");
23
+ const validator = require("../utils/validator");
24
+ const utils = require("../utils");
25
+ const FIREBASE_FUNCTIONS_CONFIG_HEADERS = {
26
+ 'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`
27
+ };
28
+ const EXTENSIONS_API_VERSION = 'v1beta';
29
+ // Note - use getExtensionsApiUri() instead so that changing environments is consistent.
30
+ const EXTENSIONS_URL = 'https://firebaseextensions.googleapis.com';
31
+ /**
32
+ * Class that facilitates sending requests to the Firebase Extensions backend API.
33
+ *
34
+ * @internal
35
+ */
36
+ class ExtensionsApiClient {
37
+ constructor(app) {
38
+ this.app = app;
39
+ if (!validator.isNonNullObject(app) || !('options' in app)) {
40
+ throw new error_1.FirebaseAppError('invalid-argument', 'First argument passed to getExtensions() must be a valid Firebase app instance.');
41
+ }
42
+ this.httpClient = new api_request_1.AuthorizedHttpClient(this.app);
43
+ }
44
+ async updateRuntimeData(projectId, instanceId, runtimeData) {
45
+ const url = this.getRuntimeDataUri(projectId, instanceId);
46
+ const request = {
47
+ method: 'PATCH',
48
+ url,
49
+ headers: FIREBASE_FUNCTIONS_CONFIG_HEADERS,
50
+ data: runtimeData,
51
+ };
52
+ try {
53
+ const res = await this.httpClient.send(request);
54
+ return res.data;
55
+ }
56
+ catch (err) {
57
+ throw this.toFirebaseError(err);
58
+ }
59
+ }
60
+ getExtensionsApiUri() {
61
+ return process.env['FIREBASE_EXT_URL'] ?? EXTENSIONS_URL;
62
+ }
63
+ getRuntimeDataUri(projectId, instanceId) {
64
+ return `${this.getExtensionsApiUri()}/${EXTENSIONS_API_VERSION}/projects/${projectId}/instances/${instanceId}/runtimeData`;
65
+ }
66
+ toFirebaseError(err) {
67
+ if (err instanceof error_1.PrefixedFirebaseError) {
68
+ return err;
69
+ }
70
+ const response = err.response;
71
+ if (!response?.isJson()) {
72
+ return new FirebaseExtensionsError('unknown-error', `Unexpected response with status: ${response.status} and body: ${response.text}`);
73
+ }
74
+ const error = response.data?.error;
75
+ const message = error?.message || `Unknown server error: ${response.text}`;
76
+ switch (error.code) {
77
+ case 403:
78
+ return new FirebaseExtensionsError('forbidden', message);
79
+ case 404:
80
+ return new FirebaseExtensionsError('not-found', message);
81
+ case 500:
82
+ return new FirebaseExtensionsError('internal-error', message);
83
+ }
84
+ return new FirebaseExtensionsError('unknown-error', message);
85
+ }
86
+ }
87
+ exports.ExtensionsApiClient = ExtensionsApiClient;
88
+ /**
89
+ * Firebase Extensions error code structure. This extends PrefixedFirebaseError.
90
+ *
91
+ * @param code - The error code.
92
+ * @param message - The error message.
93
+ * @constructor
94
+ */
95
+ class FirebaseExtensionsError extends error_1.PrefixedFirebaseError {
96
+ constructor(code, message) {
97
+ super('Extensions', code, message);
98
+ /* tslint:disable:max-line-length */
99
+ // Set the prototype explicitly. See the following link for more details:
100
+ // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
101
+ /* tslint:enable:max-line-length */
102
+ this.__proto__ = FirebaseExtensionsError.prototype;
103
+ }
104
+ }
105
+ exports.FirebaseExtensionsError = FirebaseExtensionsError;
@@ -0,0 +1,44 @@
1
+ /*! firebase-admin v11.3.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
+ * `SettableProcessingState` represents all the processing states that can be set
20
+ * on an Extension instance's runtime data.
21
+ *
22
+ * @remarks
23
+ * You can set the following states:
24
+ *
25
+ * - `NONE`: No relevant lifecycle event work has been done.
26
+ * Set this to clear out old statuses.
27
+ *
28
+ * - `PROCESSING_COMPLETE`: Lifecycle event work completed with no errors.
29
+ *
30
+ * - `PROCESSING_WARNING`: Lifecycle event work succeeded partially, or
31
+ * something happened that the user should be warned about.
32
+ *
33
+ * - `PROCESSING_FAILED`: Lifecycle event work failed completely, but the
34
+ * instance will still work correctly going forward.
35
+ *
36
+ * If the extension instance is in a broken state due to errors, instead call
37
+ * {@link Runtime.setFatalError}.
38
+ *
39
+ * The "processing" state gets set automatically when a lifecycle event handler
40
+ * starts; you can't set it explicitly.
41
+ * To report the ongoing status of an extension's function, use `console.log`
42
+ * or the Cloud Functions logger SDK.
43
+ */
44
+ export declare type SettableProcessingState = 'NONE' | 'PROCESSING_COMPLETE' | 'PROCESSING_WARNING' | 'PROCESSING_FAILED';
@@ -0,0 +1,19 @@
1
+ /*! firebase-admin v11.3.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,73 @@
1
+ /*! firebase-admin v11.3.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 { SettableProcessingState } from './extensions-api';
20
+ /**
21
+ * The Firebase `Extensions` service interface.
22
+ */
23
+ export declare class Extensions {
24
+ readonly app: App;
25
+ private readonly client;
26
+ /**
27
+ * The runtime() method returns a new Runtime, which provides methods to modify an extension instance's runtime data.
28
+ *
29
+ * @remarks
30
+ * This method will throw an error if called outside an Extensions environment.
31
+ *
32
+ * @returns A new {@link Runtime} object.
33
+ */
34
+ runtime(): Runtime;
35
+ }
36
+ /**
37
+ * Runtime provides methods to modify an extension instance's runtime data.
38
+ */
39
+ export declare class Runtime {
40
+ private projectId;
41
+ private extensionInstanceId;
42
+ private readonly client;
43
+ /**
44
+ * Sets the processing state of an extension instance.
45
+ *
46
+ * @remarks
47
+ * Use this method to report the results of a lifecycle event handler.
48
+ *
49
+ * If the lifecycle event failed & the extension instance will no longer work
50
+ * correctly, use {@link Runtime.setFatalError} instead.
51
+ *
52
+ * To report the status of function calls other than lifecycle event handlers,
53
+ * use `console.log` or the Cloud Functions logger SDK.
54
+ *
55
+ * @param state - The state to set the instance to.
56
+ * @param detailMessage - A message explaining the results of the lifecycle function.
57
+ */
58
+ setProcessingState(state: SettableProcessingState, detailMessage: string): Promise<void>;
59
+ /**
60
+ * Reports a fatal error while running a lifecycle event handler.
61
+ *
62
+ * @remarks
63
+ * Call this method when a lifecycle event handler fails in a way that makes
64
+ * the Instance inoperable.
65
+ * If the lifecycle event failed but the instance will still work as expected,
66
+ * call `setProcessingState` with the "PROCESSING_WARNING" or
67
+ * "PROCESSING_FAILED" state instead.
68
+ *
69
+ * @param errorMessage - A message explaining what went wrong and how to fix it.
70
+ */
71
+ setFatalError(errorMessage: string): Promise<void>;
72
+ private getProjectId;
73
+ }
@@ -0,0 +1,122 @@
1
+ /*! firebase-admin v11.3.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.Runtime = exports.Extensions = void 0;
21
+ const extensions_api_client_internal_1 = require("./extensions-api-client-internal");
22
+ const validator = require("../utils/validator");
23
+ /**
24
+ * The Firebase `Extensions` service interface.
25
+ */
26
+ class Extensions {
27
+ /**
28
+ * @param app - The app for this `Extensions` service.
29
+ * @constructor
30
+ * @internal
31
+ */
32
+ constructor(app) {
33
+ this.app = app;
34
+ this.client = new extensions_api_client_internal_1.ExtensionsApiClient(app);
35
+ }
36
+ /**
37
+ * The runtime() method returns a new Runtime, which provides methods to modify an extension instance's runtime data.
38
+ *
39
+ * @remarks
40
+ * This method will throw an error if called outside an Extensions environment.
41
+ *
42
+ * @returns A new {@link Runtime} object.
43
+ */
44
+ runtime() {
45
+ return new Runtime(this.client);
46
+ }
47
+ }
48
+ exports.Extensions = Extensions;
49
+ /**
50
+ * Runtime provides methods to modify an extension instance's runtime data.
51
+ */
52
+ class Runtime {
53
+ /**
54
+ * @param client - The API client for this `Runtime` service.
55
+ * @constructor
56
+ * @internal
57
+ */
58
+ constructor(client) {
59
+ this.projectId = this.getProjectId();
60
+ if (!validator.isNonEmptyString(process.env['EXT_INSTANCE_ID'])) {
61
+ throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'Runtime is only available from within a running Extension instance.');
62
+ }
63
+ this.extensionInstanceId = process.env['EXT_INSTANCE_ID'];
64
+ if (!validator.isNonNullObject(client) || !('updateRuntimeData' in client)) {
65
+ throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'Must provide a valid ExtensionsApiClient instance to create a new Runtime.');
66
+ }
67
+ this.client = client;
68
+ }
69
+ /**
70
+ * Sets the processing state of an extension instance.
71
+ *
72
+ * @remarks
73
+ * Use this method to report the results of a lifecycle event handler.
74
+ *
75
+ * If the lifecycle event failed & the extension instance will no longer work
76
+ * correctly, use {@link Runtime.setFatalError} instead.
77
+ *
78
+ * To report the status of function calls other than lifecycle event handlers,
79
+ * use `console.log` or the Cloud Functions logger SDK.
80
+ *
81
+ * @param state - The state to set the instance to.
82
+ * @param detailMessage - A message explaining the results of the lifecycle function.
83
+ */
84
+ async setProcessingState(state, detailMessage) {
85
+ await this.client.updateRuntimeData(this.projectId, this.extensionInstanceId, {
86
+ processingState: {
87
+ state,
88
+ detailMessage,
89
+ },
90
+ });
91
+ }
92
+ /**
93
+ * Reports a fatal error while running a lifecycle event handler.
94
+ *
95
+ * @remarks
96
+ * Call this method when a lifecycle event handler fails in a way that makes
97
+ * the Instance inoperable.
98
+ * If the lifecycle event failed but the instance will still work as expected,
99
+ * call `setProcessingState` with the "PROCESSING_WARNING" or
100
+ * "PROCESSING_FAILED" state instead.
101
+ *
102
+ * @param errorMessage - A message explaining what went wrong and how to fix it.
103
+ */
104
+ async setFatalError(errorMessage) {
105
+ if (!validator.isNonEmptyString(errorMessage)) {
106
+ throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'errorMessage must not be empty');
107
+ }
108
+ await this.client.updateRuntimeData(this.projectId, this.extensionInstanceId, {
109
+ fatalError: {
110
+ errorMessage,
111
+ },
112
+ });
113
+ }
114
+ getProjectId() {
115
+ const projectId = process.env['PROJECT_ID'];
116
+ if (!validator.isNonEmptyString(projectId)) {
117
+ throw new extensions_api_client_internal_1.FirebaseExtensionsError('invalid-argument', 'PROJECT_ID must not be undefined in Extensions runtime environment');
118
+ }
119
+ return projectId;
120
+ }
121
+ }
122
+ exports.Runtime = Runtime;
@@ -0,0 +1,53 @@
1
+ /*! firebase-admin v11.3.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2021 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 Extensions service.
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ import { App } from '../app';
24
+ import { Extensions } from './extensions';
25
+ export { Extensions, Runtime } from './extensions';
26
+ export { SettableProcessingState } from './extensions-api';
27
+ /**
28
+ * Gets the {@link Extensions} service for the default app
29
+ * or a given app.
30
+ *
31
+ * `getExtensions()` can be called with no arguments to access the default
32
+ * app's `Extensions` service or as `getExtensions(app)` to access the
33
+ * `Extensions` service associated with a specific app.
34
+ *
35
+ * @example
36
+ * ```javascript
37
+ * // Get the `Extensions` service for the default app
38
+ * const defaultExtensions = getExtensions();
39
+ * ```
40
+ *
41
+ * @example
42
+ * ```javascript
43
+ * // Get the `Extensions` service for a given app
44
+ * const otherExtensions = getExtensions(otherApp);
45
+ * ```
46
+ *
47
+ * @param app - Optional app for which to return the `Extensions` service.
48
+ * If not provided, the default `Extensions` service is returned.
49
+ *
50
+ * @returns The default `Extensions` service if no app is provided, or the `Extensions`
51
+ * service associated with the provided app.
52
+ */
53
+ export declare function getExtensions(app?: App): Extensions;
@@ -0,0 +1,64 @@
1
+ /*! firebase-admin v11.3.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 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.getExtensions = exports.Runtime = exports.Extensions = void 0;
21
+ /**
22
+ * Firebase Extensions service.
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ const app_1 = require("../app");
27
+ const extensions_1 = require("./extensions");
28
+ var extensions_2 = require("./extensions");
29
+ Object.defineProperty(exports, "Extensions", { enumerable: true, get: function () { return extensions_2.Extensions; } });
30
+ Object.defineProperty(exports, "Runtime", { enumerable: true, get: function () { return extensions_2.Runtime; } });
31
+ /**
32
+ * Gets the {@link Extensions} service for the default app
33
+ * or a given app.
34
+ *
35
+ * `getExtensions()` can be called with no arguments to access the default
36
+ * app's `Extensions` service or as `getExtensions(app)` to access the
37
+ * `Extensions` service associated with a specific app.
38
+ *
39
+ * @example
40
+ * ```javascript
41
+ * // Get the `Extensions` service for the default app
42
+ * const defaultExtensions = getExtensions();
43
+ * ```
44
+ *
45
+ * @example
46
+ * ```javascript
47
+ * // Get the `Extensions` service for a given app
48
+ * const otherExtensions = getExtensions(otherApp);
49
+ * ```
50
+ *
51
+ * @param app - Optional app for which to return the `Extensions` service.
52
+ * If not provided, the default `Extensions` service is returned.
53
+ *
54
+ * @returns The default `Extensions` service if no app is provided, or the `Extensions`
55
+ * service associated with the provided app.
56
+ */
57
+ function getExtensions(app) {
58
+ if (typeof app === 'undefined') {
59
+ app = (0, app_1.getApp)();
60
+ }
61
+ const firebaseApp = app;
62
+ return firebaseApp.getOrInitService('extensions', (app) => new extensions_1.Extensions(app));
63
+ }
64
+ exports.getExtensions = getExtensions;
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
@@ -18,15 +18,15 @@
18
18
  import { Firestore, Settings } from '@google-cloud/firestore';
19
19
  import { App } from '../app';
20
20
  export declare class FirestoreService {
21
- private appInternal;
22
- private firestoreClient;
21
+ private readonly appInternal;
22
+ private readonly databases;
23
23
  constructor(app: App);
24
+ getDatabase(databaseId: string): Firestore;
24
25
  /**
25
26
  * Returns the app associated with this Storage instance.
26
27
  *
27
28
  * @returns The app associated with this Storage instance.
28
29
  */
29
30
  get app(): App;
30
- get client(): Firestore;
31
31
  }
32
32
  export declare function getFirestoreOptions(app: App): Settings;
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -24,9 +24,17 @@ const validator = require("../utils/validator");
24
24
  const utils = require("../utils/index");
25
25
  class FirestoreService {
26
26
  constructor(app) {
27
- this.firestoreClient = initFirestore(app);
27
+ this.databases = new Map();
28
28
  this.appInternal = app;
29
29
  }
30
+ getDatabase(databaseId) {
31
+ let database = this.databases.get(databaseId);
32
+ if (database === undefined) {
33
+ database = initFirestore(this.app, databaseId);
34
+ this.databases.set(databaseId, database);
35
+ }
36
+ return database;
37
+ }
30
38
  /**
31
39
  * Returns the app associated with this Storage instance.
32
40
  *
@@ -35,9 +43,6 @@ class FirestoreService {
35
43
  get app() {
36
44
  return this.appInternal;
37
45
  }
38
- get client() {
39
- return this.firestoreClient;
40
- }
41
46
  }
42
47
  exports.FirestoreService = FirestoreService;
43
48
  function getFirestoreOptions(app) {
@@ -77,8 +82,9 @@ function getFirestoreOptions(app) {
77
82
  });
78
83
  }
79
84
  exports.getFirestoreOptions = getFirestoreOptions;
80
- function initFirestore(app) {
85
+ function initFirestore(app, databaseId) {
81
86
  const options = getFirestoreOptions(app);
87
+ options.databaseId = databaseId;
82
88
  let firestoreDatabase;
83
89
  try {
84
90
  // Lazy-load the Firestore implementation here, which in turns loads gRPC.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v11.2.0 */
1
+ /*! firebase-admin v11.3.0 */
2
2
  /*!
3
3
  * Copyright 2020 Google Inc.
4
4
  *
@@ -21,10 +21,10 @@
21
21
  */
22
22
  import { Firestore } from '@google-cloud/firestore';
23
23
  import { App } from '../app';
24
- export { AddPrefixToKeys, BulkWriter, BulkWriterOptions, BundleBuilder, ChildUpdateFields, CollectionGroup, CollectionReference, DocumentChange, DocumentChangeType, DocumentData, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreDataConverter, GeoPoint, GrpcStatus, NestedUpdateFields, OrderByDirection, PartialWithFieldValue, Precondition, Primitive, Query, QueryDocumentSnapshot, QueryPartition, QuerySnapshot, ReadOptions, ReadOnlyTransactionOptions, Settings, SetOptions, Timestamp, Transaction, UpdateData, UnionToIntersection, WhereFilterOp, WithFieldValue, WriteBatch, WriteResult, v1, setLogFunction, } from '@google-cloud/firestore';
24
+ export { AddPrefixToKeys, BulkWriter, BulkWriterOptions, BundleBuilder, ChildUpdateFields, CollectionGroup, CollectionReference, DocumentChange, DocumentChangeType, DocumentData, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreDataConverter, GeoPoint, GrpcStatus, NestedUpdateFields, OrderByDirection, PartialWithFieldValue, Precondition, Primitive, Query, QueryDocumentSnapshot, QueryPartition, QuerySnapshot, ReadOptions, ReadOnlyTransactionOptions, ReadWriteTransactionOptions, Settings, SetOptions, Timestamp, Transaction, UpdateData, UnionToIntersection, WhereFilterOp, WithFieldValue, WriteBatch, WriteResult, v1, setLogFunction, } from '@google-cloud/firestore';
25
25
  /**
26
26
  * Gets the {@link https://googleapis.dev/nodejs/firestore/latest/Firestore.html | Firestore}
27
- * service for the default app or a given app.
27
+ * service for the default app.
28
28
  *
29
29
  * `getFirestore()` can be called with no arguments to access the default
30
30
  * app's `Firestore` service or as `getFirestore(app)` to access the
@@ -35,6 +35,19 @@ export { AddPrefixToKeys, BulkWriter, BulkWriterOptions, BundleBuilder, ChildUpd
35
35
  * // Get the Firestore service for the default app
36
36
  * const defaultFirestore = getFirestore();
37
37
  * ```
38
+
39
+ * @returns The default {@link https://googleapis.dev/nodejs/firestore/latest/Firestore.html | Firestore}
40
+ * service if no app is provided or the `Firestore` service associated with the
41
+ * provided app.
42
+ */
43
+ export declare function getFirestore(): Firestore;
44
+ /**
45
+ * Gets the {@link https://googleapis.dev/nodejs/firestore/latest/Firestore.html | Firestore}
46
+ * service for the given app.
47
+ *
48
+ * `getFirestore()` can be called with no arguments to access the default
49
+ * app's `Firestore` service or as `getFirestore(app)` to access the
50
+ * `Firestore` service associated with a specific app.
38
51
  *
39
52
  * @example
40
53
  * ```javascript
@@ -49,4 +62,4 @@ export { AddPrefixToKeys, BulkWriter, BulkWriterOptions, BundleBuilder, ChildUpd
49
62
  * service if no app is provided or the `Firestore` service associated with the
50
63
  * provided app.
51
64
  */
52
- export declare function getFirestore(app?: App): Firestore;
65
+ export declare function getFirestore(app: App): Firestore;