firebase-admin 9.100.0-alpha.0 → 10.0.2

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 (188) hide show
  1. package/README.md +7 -3
  2. package/lib/app/core.d.ts +15 -22
  3. package/lib/app/core.js +1 -1
  4. package/lib/app/credential-factory.d.ts +17 -33
  5. package/lib/app/credential-factory.js +17 -33
  6. package/lib/app/credential-internal.d.ts +10 -9
  7. package/lib/app/credential-internal.js +15 -13
  8. package/lib/app/credential.d.ts +3 -9
  9. package/lib/app/credential.js +1 -1
  10. package/lib/app/firebase-app.d.ts +6 -30
  11. package/lib/app/firebase-app.js +72 -216
  12. package/lib/app/firebase-namespace.d.ts +28 -34
  13. package/lib/app/firebase-namespace.js +119 -99
  14. package/lib/app/index.d.ts +6 -1
  15. package/lib/app/index.js +1 -1
  16. package/lib/app/lifecycle.d.ts +24 -3
  17. package/lib/app/lifecycle.js +119 -25
  18. package/lib/app-check/app-check-api-client-internal.d.ts +32 -0
  19. package/lib/app-check/app-check-api-client-internal.js +197 -0
  20. package/lib/app-check/app-check-api.d.ts +95 -0
  21. package/lib/app-check/app-check-api.js +19 -0
  22. package/lib/app-check/app-check-namespace.d.ts +65 -0
  23. package/lib/app-check/app-check-namespace.js +18 -0
  24. package/lib/app-check/app-check.d.ts +49 -0
  25. package/lib/app-check/app-check.js +82 -0
  26. package/lib/app-check/index.d.ts +53 -0
  27. package/lib/app-check/index.js +63 -0
  28. package/lib/app-check/token-generator.d.ts +25 -0
  29. package/lib/app-check/token-generator.js +159 -0
  30. package/lib/app-check/token-verifier.d.ts +17 -0
  31. package/lib/app-check/token-verifier.js +151 -0
  32. package/lib/auth/action-code-settings-builder.d.ts +1 -1
  33. package/lib/auth/action-code-settings-builder.js +2 -2
  34. package/lib/auth/auth-api-request.d.ts +28 -32
  35. package/lib/auth/auth-api-request.js +167 -125
  36. package/lib/auth/auth-config.d.ts +123 -21
  37. package/lib/auth/auth-config.js +85 -34
  38. package/lib/auth/auth-namespace.d.ts +157 -4
  39. package/lib/auth/auth-namespace.js +1 -1
  40. package/lib/auth/auth.d.ts +5 -3
  41. package/lib/auth/auth.js +6 -4
  42. package/lib/auth/base-auth.d.ts +134 -116
  43. package/lib/auth/base-auth.js +213 -143
  44. package/lib/auth/identifier.d.ts +5 -5
  45. package/lib/auth/identifier.js +1 -1
  46. package/lib/auth/index.d.ts +10 -5
  47. package/lib/auth/index.js +9 -4
  48. package/lib/auth/tenant-manager.d.ts +19 -19
  49. package/lib/auth/tenant-manager.js +21 -25
  50. package/lib/auth/tenant.d.ts +14 -5
  51. package/lib/auth/tenant.js +19 -11
  52. package/lib/auth/token-generator.d.ts +7 -108
  53. package/lib/auth/token-generator.js +52 -145
  54. package/lib/auth/token-verifier.d.ts +3 -4
  55. package/lib/auth/token-verifier.js +96 -145
  56. package/lib/auth/user-import-builder.d.ts +11 -11
  57. package/lib/auth/user-import-builder.js +9 -9
  58. package/lib/auth/user-record.d.ts +23 -15
  59. package/lib/auth/user-record.js +30 -20
  60. package/lib/credential/index.d.ts +18 -35
  61. package/lib/credential/index.js +17 -33
  62. package/lib/database/database-namespace.d.ts +39 -10
  63. package/lib/database/database-namespace.js +1 -1
  64. package/lib/database/database.d.ts +16 -6
  65. package/lib/database/database.js +61 -6
  66. package/lib/database/index.d.ts +19 -18
  67. package/lib/database/index.js +21 -23
  68. package/lib/default-namespace.d.ts +7 -1
  69. package/lib/default-namespace.js +4 -4
  70. package/lib/esm/app/index.js +10 -0
  71. package/lib/esm/app-check/index.js +4 -0
  72. package/lib/esm/auth/index.js +14 -0
  73. package/lib/esm/database/index.js +6 -0
  74. package/lib/esm/firestore/index.js +24 -0
  75. package/lib/esm/installations/index.js +4 -0
  76. package/lib/esm/instance-id/index.js +4 -0
  77. package/lib/esm/machine-learning/index.js +5 -0
  78. package/lib/esm/messaging/index.js +4 -0
  79. package/lib/esm/package.json +1 -0
  80. package/lib/esm/project-management/index.js +8 -0
  81. package/lib/esm/remote-config/index.js +4 -0
  82. package/lib/esm/security-rules/index.js +6 -0
  83. package/lib/esm/storage/index.js +4 -0
  84. package/lib/firebase-namespace-api.d.ts +12 -6
  85. package/lib/firebase-namespace-api.js +5 -1
  86. package/lib/firestore/firestore-internal.d.ts +2 -2
  87. package/lib/firestore/firestore-internal.js +2 -2
  88. package/lib/firestore/firestore-namespace.d.ts +6 -1
  89. package/lib/firestore/firestore-namespace.js +2 -1
  90. package/lib/firestore/index.d.ts +36 -4
  91. package/lib/firestore/index.js +29 -1
  92. package/lib/index.d.ts +1 -1
  93. package/lib/index.js +1 -1
  94. package/lib/installations/index.d.ts +52 -0
  95. package/lib/installations/index.js +62 -0
  96. package/lib/installations/installations-namespace.d.ts +55 -0
  97. package/lib/installations/installations-namespace.js +18 -0
  98. package/lib/{instance-id/instance-id-request-internal.d.ts → installations/installations-request-handler.d.ts} +8 -8
  99. package/lib/{instance-id/instance-id-request-internal.js → installations/installations-request-handler.js} +23 -23
  100. package/lib/installations/installations.d.ts +38 -0
  101. package/lib/installations/installations.js +63 -0
  102. package/lib/instance-id/index.d.ts +20 -9
  103. package/lib/instance-id/index.js +20 -9
  104. package/lib/instance-id/instance-id-namespace.d.ts +9 -8
  105. package/lib/instance-id/instance-id-namespace.js +1 -1
  106. package/lib/instance-id/instance-id.d.ts +8 -6
  107. package/lib/instance-id/instance-id.js +20 -11
  108. package/lib/machine-learning/index.d.ts +29 -27
  109. package/lib/machine-learning/index.js +29 -27
  110. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  111. package/lib/machine-learning/machine-learning-api-client.js +4 -4
  112. package/lib/machine-learning/machine-learning-namespace.d.ts +33 -8
  113. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  114. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  115. package/lib/machine-learning/machine-learning-utils.js +1 -1
  116. package/lib/machine-learning/machine-learning.d.ts +19 -19
  117. package/lib/machine-learning/machine-learning.js +20 -20
  118. package/lib/messaging/batch-request-internal.d.ts +3 -3
  119. package/lib/messaging/batch-request-internal.js +9 -9
  120. package/lib/messaging/index.d.ts +11 -9
  121. package/lib/messaging/index.js +11 -9
  122. package/lib/messaging/messaging-api-request-internal.d.ts +8 -8
  123. package/lib/messaging/messaging-api-request-internal.js +8 -8
  124. package/lib/messaging/messaging-api.d.ts +79 -75
  125. package/lib/messaging/messaging-api.js +1 -1
  126. package/lib/messaging/messaging-errors-internal.d.ts +5 -5
  127. package/lib/messaging/messaging-errors-internal.js +7 -7
  128. package/lib/messaging/messaging-internal.d.ts +1 -1
  129. package/lib/messaging/messaging-internal.js +6 -31
  130. package/lib/messaging/messaging-namespace.d.ts +105 -8
  131. package/lib/messaging/messaging-namespace.js +1 -1
  132. package/lib/messaging/messaging.d.ts +70 -86
  133. package/lib/messaging/messaging.js +76 -89
  134. package/lib/project-management/android-app.d.ts +11 -12
  135. package/lib/project-management/android-app.js +13 -14
  136. package/lib/project-management/app-metadata.d.ts +1 -1
  137. package/lib/project-management/app-metadata.js +1 -1
  138. package/lib/project-management/index.d.ts +11 -9
  139. package/lib/project-management/index.js +11 -9
  140. package/lib/project-management/ios-app.d.ts +6 -7
  141. package/lib/project-management/ios-app.js +6 -7
  142. package/lib/project-management/project-management-api-request-internal.d.ts +1 -80
  143. package/lib/project-management/project-management-api-request-internal.js +14 -14
  144. package/lib/project-management/project-management-namespace.d.ts +31 -9
  145. package/lib/project-management/project-management-namespace.js +1 -1
  146. package/lib/project-management/project-management.d.ts +18 -21
  147. package/lib/project-management/project-management.js +19 -22
  148. package/lib/remote-config/index.d.ts +12 -10
  149. package/lib/remote-config/index.js +11 -9
  150. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  151. package/lib/remote-config/remote-config-api-client-internal.js +2 -2
  152. package/lib/remote-config/remote-config-api.d.ts +12 -2
  153. package/lib/remote-config/remote-config-api.js +1 -1
  154. package/lib/remote-config/remote-config-namespace.d.ts +50 -9
  155. package/lib/remote-config/remote-config-namespace.js +1 -1
  156. package/lib/remote-config/remote-config.d.ts +19 -21
  157. package/lib/remote-config/remote-config.js +25 -25
  158. package/lib/security-rules/index.d.ts +12 -10
  159. package/lib/security-rules/index.js +12 -10
  160. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  161. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  162. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  163. package/lib/security-rules/security-rules-internal.js +1 -1
  164. package/lib/security-rules/security-rules-namespace.d.ts +43 -28
  165. package/lib/security-rules/security-rules-namespace.js +1 -1
  166. package/lib/security-rules/security-rules.d.ts +39 -42
  167. package/lib/security-rules/security-rules.js +38 -39
  168. package/lib/storage/index.d.ts +9 -7
  169. package/lib/storage/index.js +9 -7
  170. package/lib/storage/storage-namespace.d.ts +7 -6
  171. package/lib/storage/storage-namespace.js +1 -1
  172. package/lib/storage/storage.d.ts +3 -3
  173. package/lib/storage/storage.js +14 -4
  174. package/lib/utils/api-request.d.ts +24 -24
  175. package/lib/utils/api-request.js +25 -25
  176. package/lib/utils/crypto-signer.d.ts +128 -0
  177. package/lib/utils/crypto-signer.js +237 -0
  178. package/lib/utils/deep-copy.d.ts +6 -6
  179. package/lib/utils/deep-copy.js +6 -6
  180. package/lib/utils/error.d.ts +69 -36
  181. package/lib/utils/error.js +98 -43
  182. package/lib/utils/index.d.ts +30 -19
  183. package/lib/utils/index.js +47 -20
  184. package/lib/utils/jwt.d.ts +131 -0
  185. package/lib/utils/jwt.js +355 -0
  186. package/lib/utils/validator.d.ts +37 -37
  187. package/lib/utils/validator.js +37 -37
  188. package/package.json +126 -53
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -17,129 +17,53 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.FirebaseNamespace = exports.FirebaseNamespaceInternals = exports.FIREBASE_CONFIG_VAR = void 0;
21
- var fs = require("fs");
22
- var error_1 = require("../utils/error");
23
- var firebase_app_1 = require("./firebase-app");
20
+ exports.defaultNamespace = exports.FirebaseNamespace = exports.FirebaseNamespaceInternals = void 0;
21
+ var lifecycle_1 = require("./lifecycle");
24
22
  var credential_factory_1 = require("./credential-factory");
25
- var credential_internal_1 = require("./credential-internal");
26
- var validator = require("../utils/validator");
27
23
  var index_1 = require("../utils/index");
28
- var DEFAULT_APP_NAME = '[DEFAULT]';
29
- /**
30
- * Constant holding the environment variable name with the default config.
31
- * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
32
- * otherwise it will be assumed to be pointing to a file.
33
- */
34
- exports.FIREBASE_CONFIG_VAR = 'FIREBASE_CONFIG';
35
24
  /**
36
25
  * Internals of a FirebaseNamespace instance.
37
26
  */
38
27
  var FirebaseNamespaceInternals = /** @class */ (function () {
39
- function FirebaseNamespaceInternals(firebase_) {
40
- this.firebase_ = firebase_;
41
- this.apps_ = {};
28
+ function FirebaseNamespaceInternals(appStore) {
29
+ this.appStore = appStore;
42
30
  }
43
31
  /**
44
32
  * Initializes the App instance.
45
33
  *
46
- * @param options Optional options for the App instance. If none present will try to initialize
34
+ * @param options - Optional options for the App instance. If none present will try to initialize
47
35
  * from the FIREBASE_CONFIG environment variable. If the environment variable contains a string
48
36
  * that starts with '{' it will be parsed as JSON, otherwise it will be assumed to be pointing
49
37
  * to a file.
50
- * @param appName Optional name of the FirebaseApp instance.
38
+ * @param appName - Optional name of the FirebaseApp instance.
51
39
  *
52
- * @return A new App instance.
40
+ * @returns A new App instance.
53
41
  */
54
42
  FirebaseNamespaceInternals.prototype.initializeApp = function (options, appName) {
55
- if (appName === void 0) { appName = DEFAULT_APP_NAME; }
56
- if (typeof options === 'undefined') {
57
- options = this.loadOptionsFromEnvVar();
58
- options.credential = credential_internal_1.getApplicationDefault();
59
- }
60
- if (typeof appName !== 'string' || appName === '') {
61
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, "Invalid Firebase app name \"" + appName + "\" provided. App name must be a non-empty string.");
62
- }
63
- else if (appName in this.apps_) {
64
- if (appName === DEFAULT_APP_NAME) {
65
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, 'The default Firebase app already exists. This means you called initializeApp() ' +
66
- 'more than once without providing an app name as the second argument. In most cases ' +
67
- 'you only need to call initializeApp() once. But if you do want to initialize ' +
68
- 'multiple apps, pass a second argument to initializeApp() to give each app a unique ' +
69
- 'name.');
70
- }
71
- else {
72
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, "Firebase app named \"" + appName + "\" already exists. This means you called initializeApp() " +
73
- 'more than once with the same app name as the second argument. Make sure you provide a ' +
74
- 'unique name every time you call initializeApp().');
75
- }
76
- }
77
- var app = new firebase_app_1.FirebaseApp(options, appName, this);
78
- this.apps_[appName] = app;
79
- return app;
43
+ var app = this.appStore.initializeApp(options, appName);
44
+ return extendApp(app);
80
45
  };
81
46
  /**
82
47
  * Returns the App instance with the provided name (or the default App instance
83
48
  * if no name is provided).
84
49
  *
85
- * @param appName Optional name of the FirebaseApp instance to return.
86
- * @return The App instance which has the provided name.
50
+ * @param appName - Optional name of the FirebaseApp instance to return.
51
+ * @returns The App instance which has the provided name.
87
52
  */
88
53
  FirebaseNamespaceInternals.prototype.app = function (appName) {
89
- if (appName === void 0) { appName = DEFAULT_APP_NAME; }
90
- if (typeof appName !== 'string' || appName === '') {
91
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, "Invalid Firebase app name \"" + appName + "\" provided. App name must be a non-empty string.");
92
- }
93
- else if (!(appName in this.apps_)) {
94
- var errorMessage = (appName === DEFAULT_APP_NAME)
95
- ? 'The default Firebase app does not exist. ' : "Firebase app named \"" + appName + "\" does not exist. ";
96
- errorMessage += 'Make sure you call initializeApp() before using any of the Firebase services.';
97
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.NO_APP, errorMessage);
98
- }
99
- return this.apps_[appName];
54
+ var app = this.appStore.getApp(appName);
55
+ return extendApp(app);
100
56
  };
101
57
  Object.defineProperty(FirebaseNamespaceInternals.prototype, "apps", {
102
58
  /*
103
59
  * Returns an array of all the non-deleted App instances.
104
60
  */
105
61
  get: function () {
106
- var _this = this;
107
- // Return a copy so the caller cannot mutate the array
108
- return Object.keys(this.apps_).map(function (appName) { return _this.apps_[appName]; });
62
+ return this.appStore.getApps().map(function (app) { return extendApp(app); });
109
63
  },
110
64
  enumerable: false,
111
65
  configurable: true
112
66
  });
113
- /*
114
- * Removes the specified App instance.
115
- */
116
- FirebaseNamespaceInternals.prototype.removeApp = function (appName) {
117
- if (typeof appName === 'undefined') {
118
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, 'No Firebase app name provided. App name must be a non-empty string.');
119
- }
120
- var appToRemove = this.app(appName);
121
- delete this.apps_[appToRemove.name];
122
- };
123
- /**
124
- * Parse the file pointed to by the FIREBASE_CONFIG_VAR, if it exists.
125
- * Or if the FIREBASE_CONFIG_ENV contains a valid JSON object, parse it directly.
126
- * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
127
- * otherwise it will be assumed to be pointing to a file.
128
- */
129
- FirebaseNamespaceInternals.prototype.loadOptionsFromEnvVar = function () {
130
- var config = process.env[exports.FIREBASE_CONFIG_VAR];
131
- if (!validator.isNonEmptyString(config)) {
132
- return {};
133
- }
134
- try {
135
- var contents = config.startsWith('{') ? config : fs.readFileSync(config, 'utf8');
136
- return JSON.parse(contents);
137
- }
138
- catch (error) {
139
- // Throw a nicely formed error message if the file contents cannot be parsed
140
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, 'Failed to parse app options file: ' + error);
141
- }
142
- };
143
67
  return FirebaseNamespaceInternals;
144
68
  }());
145
69
  exports.FirebaseNamespaceInternals = FirebaseNamespaceInternals;
@@ -151,7 +75,7 @@ var firebaseCredential = {
151
75
  */
152
76
  var FirebaseNamespace = /** @class */ (function () {
153
77
  /* tslint:enable */
154
- function FirebaseNamespace() {
78
+ function FirebaseNamespace(appStore) {
155
79
  // Hack to prevent Babel from modifying the object returned as the default admin namespace.
156
80
  /* tslint:disable:variable-name */
157
81
  this.__esModule = true;
@@ -162,7 +86,7 @@ var FirebaseNamespace = /** @class */ (function () {
162
86
  // TODO(jwenger): Database is the only consumer of firebase.Promise. We should update it to use
163
87
  // use the native Promise and then remove this.
164
88
  this.Promise = Promise;
165
- this.INTERNAL = new FirebaseNamespaceInternals(this);
89
+ this.INTERNAL = new FirebaseNamespaceInternals(appStore !== null && appStore !== void 0 ? appStore : new lifecycle_1.AppStore());
166
90
  }
167
91
  Object.defineProperty(FirebaseNamespace.prototype, "auth", {
168
92
  /**
@@ -191,7 +115,7 @@ var FirebaseNamespace = /** @class */ (function () {
191
115
  return _this.ensureApp(app).database();
192
116
  };
193
117
  // eslint-disable-next-line @typescript-eslint/no-var-requires
194
- return Object.assign(fn, require('@firebase/database'));
118
+ return Object.assign(fn, require('@firebase/database-compat/standalone'));
195
119
  },
196
120
  enumerable: false,
197
121
  configurable: true
@@ -275,6 +199,22 @@ var FirebaseNamespace = /** @class */ (function () {
275
199
  enumerable: false,
276
200
  configurable: true
277
201
  });
202
+ Object.defineProperty(FirebaseNamespace.prototype, "installations", {
203
+ /**
204
+ * Gets the `Installations` service namespace. The returned namespace can be used to get the
205
+ * `Installations` service for the default app or an explicitly specified app.
206
+ */
207
+ get: function () {
208
+ var _this = this;
209
+ var fn = function (app) {
210
+ return _this.ensureApp(app).installations();
211
+ };
212
+ var installations = require('../installations/installations').Installations;
213
+ return Object.assign(fn, { Installations: installations });
214
+ },
215
+ enumerable: false,
216
+ configurable: true
217
+ });
278
218
  Object.defineProperty(FirebaseNamespace.prototype, "instanceId", {
279
219
  /**
280
220
  * Gets the `InstanceId` service namespace. The returned namespace can be used to get the
@@ -339,17 +279,33 @@ var FirebaseNamespace = /** @class */ (function () {
339
279
  enumerable: false,
340
280
  configurable: true
341
281
  });
282
+ Object.defineProperty(FirebaseNamespace.prototype, "appCheck", {
283
+ /**
284
+ * Gets the `AppCheck` service namespace. The returned namespace can be used to get the
285
+ * `AppCheck` service for the default app or an explicitly specified app.
286
+ */
287
+ get: function () {
288
+ var _this = this;
289
+ var fn = function (app) {
290
+ return _this.ensureApp(app).appCheck();
291
+ };
292
+ var appCheck = require('../app-check/app-check').AppCheck;
293
+ return Object.assign(fn, { AppCheck: appCheck });
294
+ },
295
+ enumerable: false,
296
+ configurable: true
297
+ });
342
298
  // TODO: Change the return types to app.App in the following methods.
343
299
  /**
344
300
  * Initializes the FirebaseApp instance.
345
301
  *
346
- * @param options Optional options for the FirebaseApp instance.
302
+ * @param options - Optional options for the FirebaseApp instance.
347
303
  * If none present will try to initialize from the FIREBASE_CONFIG environment variable.
348
304
  * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
349
305
  * otherwise it will be assumed to be pointing to a file.
350
- * @param appName Optional name of the FirebaseApp instance.
306
+ * @param appName - Optional name of the FirebaseApp instance.
351
307
  *
352
- * @return A new FirebaseApp instance.
308
+ * @returns A new FirebaseApp instance.
353
309
  */
354
310
  FirebaseNamespace.prototype.initializeApp = function (options, appName) {
355
311
  return this.INTERNAL.initializeApp(options, appName);
@@ -358,8 +314,8 @@ var FirebaseNamespace = /** @class */ (function () {
358
314
  * Returns the FirebaseApp instance with the provided name (or the default FirebaseApp instance
359
315
  * if no name is provided).
360
316
  *
361
- * @param appName Optional name of the FirebaseApp instance to return.
362
- * @return The FirebaseApp instance which has the provided name.
317
+ * @param appName - Optional name of the FirebaseApp instance to return.
318
+ * @returns The FirebaseApp instance which has the provided name.
363
319
  */
364
320
  FirebaseNamespace.prototype.app = function (appName) {
365
321
  return this.INTERNAL.app(appName);
@@ -383,3 +339,67 @@ var FirebaseNamespace = /** @class */ (function () {
383
339
  return FirebaseNamespace;
384
340
  }());
385
341
  exports.FirebaseNamespace = FirebaseNamespace;
342
+ /**
343
+ * In order to maintain backward compatibility, we instantiate a default namespace instance in
344
+ * this module, and delegate all app lifecycle operations to it. In a future implementation where
345
+ * the old admin namespace is no longer supported, we should remove this.
346
+ *
347
+ * @internal
348
+ */
349
+ exports.defaultNamespace = new FirebaseNamespace(lifecycle_1.defaultAppStore);
350
+ function extendApp(app) {
351
+ var result = app;
352
+ if (result.__extended) {
353
+ return result;
354
+ }
355
+ result.auth = function () {
356
+ var fn = require('../auth/index').getAuth;
357
+ return fn(app);
358
+ };
359
+ result.appCheck = function () {
360
+ var fn = require('../app-check/index').getAppCheck;
361
+ return fn(app);
362
+ };
363
+ result.database = function (url) {
364
+ var fn = require('../database/index').getDatabaseWithUrl;
365
+ return fn(url, app);
366
+ };
367
+ result.messaging = function () {
368
+ var fn = require('../messaging/index').getMessaging;
369
+ return fn(app);
370
+ };
371
+ result.storage = function () {
372
+ var fn = require('../storage/index').getStorage;
373
+ return fn(app);
374
+ };
375
+ result.firestore = function () {
376
+ var fn = require('../firestore/index').getFirestore;
377
+ return fn(app);
378
+ };
379
+ result.instanceId = function () {
380
+ var fn = require('../instance-id/index').getInstanceId;
381
+ return fn(app);
382
+ };
383
+ result.installations = function () {
384
+ var fn = require('../installations/index').getInstallations;
385
+ return fn(app);
386
+ };
387
+ result.machineLearning = function () {
388
+ var fn = require('../machine-learning/index').getMachineLearning;
389
+ return fn(app);
390
+ };
391
+ result.projectManagement = function () {
392
+ var fn = require('../project-management/index').getProjectManagement;
393
+ return fn(app);
394
+ };
395
+ result.securityRules = function () {
396
+ var fn = require('../security-rules/index').getSecurityRules;
397
+ return fn(app);
398
+ };
399
+ result.remoteConfig = function () {
400
+ var fn = require('../remote-config/index').getRemoteConfig;
401
+ return fn(app);
402
+ };
403
+ result.__extended = true;
404
+ return result;
405
+ }
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -15,6 +15,11 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
+ /**
19
+ * Firebase App and SDK initialization.
20
+ *
21
+ * @packageDocumentation
22
+ */
18
23
  export { App, AppOptions, FirebaseArrayIndexError, FirebaseError } from './core';
19
24
  export { initializeApp, getApp, getApps, deleteApp } from './lifecycle';
20
25
  export { Credential, ServiceAccount, GoogleOAuthAccessToken } from './credential';
package/lib/app/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2021 Google Inc.
@@ -16,8 +16,23 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import { App, AppOptions } from './core';
19
- export declare function initializeApp(options?: AppOptions, name?: string): App;
20
- export declare function getApp(name?: string): App;
19
+ export declare class AppStore {
20
+ private readonly appStore;
21
+ initializeApp(options?: AppOptions, appName?: string): App;
22
+ getApp(appName?: string): App;
23
+ getApps(): App[];
24
+ deleteApp(app: App): Promise<void>;
25
+ clearAllApps(): Promise<void>;
26
+ /**
27
+ * Removes the specified App instance from the store. This is currently called by the
28
+ * {@link FirebaseApp.delete} method. Can be removed once the app deletion is handled
29
+ * entirely by the {@link deleteApp} top-level function.
30
+ */
31
+ removeApp(appName: string): void;
32
+ }
33
+ export declare const defaultAppStore: AppStore;
34
+ export declare function initializeApp(options?: AppOptions, appName?: string): App;
35
+ export declare function getApp(appName?: string): App;
21
36
  export declare function getApps(): App[];
22
37
  /**
23
38
  * Renders this given `App` unusable and frees the resources of
@@ -37,3 +52,9 @@ export declare function getApps(): App[];
37
52
  * ```
38
53
  */
39
54
  export declare function deleteApp(app: App): Promise<void>;
55
+ /**
56
+ * Constant holding the environment variable name with the default config.
57
+ * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
58
+ * otherwise it will be assumed to be pointing to a file.
59
+ */
60
+ export declare const FIREBASE_CONFIG_VAR = "FIREBASE_CONFIG";
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -17,28 +17,103 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.deleteApp = exports.getApps = exports.getApp = exports.initializeApp = exports.defaultNamespace = void 0;
20
+ exports.FIREBASE_CONFIG_VAR = exports.deleteApp = exports.getApps = exports.getApp = exports.initializeApp = exports.defaultAppStore = exports.AppStore = void 0;
21
+ var fs = require("fs");
22
+ var validator = require("../utils/validator");
21
23
  var error_1 = require("../utils/error");
22
- var firebase_namespace_1 = require("./firebase-namespace");
23
- /**
24
- * In order to maintain backward compatibility, we instantiate a default namespace instance in
25
- * this module, and delegate all app lifecycle operations to it. In a future implementation where
26
- * the old admin namespace is no longer supported, we should remove this, and implement app
27
- * lifecycle management in this module itself.
28
- *
29
- * @internal
30
- */
31
- exports.defaultNamespace = new firebase_namespace_1.FirebaseNamespace();
32
- function initializeApp(options, name) {
33
- return exports.defaultNamespace.initializeApp(options, name);
24
+ var credential_internal_1 = require("./credential-internal");
25
+ var firebase_app_1 = require("./firebase-app");
26
+ var DEFAULT_APP_NAME = '[DEFAULT]';
27
+ var AppStore = /** @class */ (function () {
28
+ function AppStore() {
29
+ this.appStore = new Map();
30
+ }
31
+ AppStore.prototype.initializeApp = function (options, appName) {
32
+ if (appName === void 0) { appName = DEFAULT_APP_NAME; }
33
+ if (typeof options === 'undefined') {
34
+ options = loadOptionsFromEnvVar();
35
+ options.credential = credential_internal_1.getApplicationDefault();
36
+ }
37
+ if (typeof appName !== 'string' || appName === '') {
38
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, "Invalid Firebase app name \"" + appName + "\" provided. App name must be a non-empty string.");
39
+ }
40
+ else if (this.appStore.has(appName)) {
41
+ if (appName === DEFAULT_APP_NAME) {
42
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, 'The default Firebase app already exists. This means you called initializeApp() ' +
43
+ 'more than once without providing an app name as the second argument. In most cases ' +
44
+ 'you only need to call initializeApp() once. But if you do want to initialize ' +
45
+ 'multiple apps, pass a second argument to initializeApp() to give each app a unique ' +
46
+ 'name.');
47
+ }
48
+ else {
49
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, "Firebase app named \"" + appName + "\" already exists. This means you called initializeApp() " +
50
+ 'more than once with the same app name as the second argument. Make sure you provide a ' +
51
+ 'unique name every time you call initializeApp().');
52
+ }
53
+ }
54
+ var app = new firebase_app_1.FirebaseApp(options, appName, this);
55
+ this.appStore.set(app.name, app);
56
+ return app;
57
+ };
58
+ AppStore.prototype.getApp = function (appName) {
59
+ if (appName === void 0) { appName = DEFAULT_APP_NAME; }
60
+ if (typeof appName !== 'string' || appName === '') {
61
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, "Invalid Firebase app name \"" + appName + "\" provided. App name must be a non-empty string.");
62
+ }
63
+ else if (!this.appStore.has(appName)) {
64
+ var errorMessage = (appName === DEFAULT_APP_NAME)
65
+ ? 'The default Firebase app does not exist. ' : "Firebase app named \"" + appName + "\" does not exist. ";
66
+ errorMessage += 'Make sure you call initializeApp() before using any of the Firebase services.';
67
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.NO_APP, errorMessage);
68
+ }
69
+ return this.appStore.get(appName);
70
+ };
71
+ AppStore.prototype.getApps = function () {
72
+ // Return a copy so the caller cannot mutate the array
73
+ return Array.from(this.appStore.values());
74
+ };
75
+ AppStore.prototype.deleteApp = function (app) {
76
+ if (typeof app !== 'object' || app === null || !('options' in app)) {
77
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_ARGUMENT, 'Invalid app argument.');
78
+ }
79
+ // Make sure the given app already exists.
80
+ var existingApp = getApp(app.name);
81
+ // Delegate delete operation to the App instance itself. That will also remove the App
82
+ // instance from the AppStore.
83
+ return existingApp.delete();
84
+ };
85
+ AppStore.prototype.clearAllApps = function () {
86
+ var _this = this;
87
+ var promises = [];
88
+ this.getApps().forEach(function (app) {
89
+ promises.push(_this.deleteApp(app));
90
+ });
91
+ return Promise.all(promises).then();
92
+ };
93
+ /**
94
+ * Removes the specified App instance from the store. This is currently called by the
95
+ * {@link FirebaseApp.delete} method. Can be removed once the app deletion is handled
96
+ * entirely by the {@link deleteApp} top-level function.
97
+ */
98
+ AppStore.prototype.removeApp = function (appName) {
99
+ this.appStore.delete(appName);
100
+ };
101
+ return AppStore;
102
+ }());
103
+ exports.AppStore = AppStore;
104
+ exports.defaultAppStore = new AppStore();
105
+ function initializeApp(options, appName) {
106
+ if (appName === void 0) { appName = DEFAULT_APP_NAME; }
107
+ return exports.defaultAppStore.initializeApp(options, appName);
34
108
  }
35
109
  exports.initializeApp = initializeApp;
36
- function getApp(name) {
37
- return exports.defaultNamespace.app(name);
110
+ function getApp(appName) {
111
+ if (appName === void 0) { appName = DEFAULT_APP_NAME; }
112
+ return exports.defaultAppStore.getApp(appName);
38
113
  }
39
114
  exports.getApp = getApp;
40
115
  function getApps() {
41
- return exports.defaultNamespace.apps;
116
+ return exports.defaultAppStore.getApps();
42
117
  }
43
118
  exports.getApps = getApps;
44
119
  /**
@@ -59,13 +134,32 @@ exports.getApps = getApps;
59
134
  * ```
60
135
  */
61
136
  function deleteApp(app) {
62
- if (typeof app !== 'object' || app === null || !('options' in app)) {
63
- throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_ARGUMENT, 'Invalid app argument.');
64
- }
65
- // Make sure the given app already exists.
66
- var existingApp = getApp(app.name);
67
- // Delegate delete operation to the App instance itself for now. This will tear down any
68
- // local app state, and also remove it from the global map.
69
- return existingApp.delete();
137
+ return exports.defaultAppStore.deleteApp(app);
70
138
  }
71
139
  exports.deleteApp = deleteApp;
140
+ /**
141
+ * Constant holding the environment variable name with the default config.
142
+ * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
143
+ * otherwise it will be assumed to be pointing to a file.
144
+ */
145
+ exports.FIREBASE_CONFIG_VAR = 'FIREBASE_CONFIG';
146
+ /**
147
+ * Parse the file pointed to by the FIREBASE_CONFIG_VAR, if it exists.
148
+ * Or if the FIREBASE_CONFIG_ENV contains a valid JSON object, parse it directly.
149
+ * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
150
+ * otherwise it will be assumed to be pointing to a file.
151
+ */
152
+ function loadOptionsFromEnvVar() {
153
+ var config = process.env[exports.FIREBASE_CONFIG_VAR];
154
+ if (!validator.isNonEmptyString(config)) {
155
+ return {};
156
+ }
157
+ try {
158
+ var contents = config.startsWith('{') ? config : fs.readFileSync(config, 'utf8');
159
+ return JSON.parse(contents);
160
+ }
161
+ catch (error) {
162
+ // Throw a nicely formed error message if the file contents cannot be parsed
163
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, 'Failed to parse app options file: ' + error);
164
+ }
165
+ }
@@ -0,0 +1,32 @@
1
+ /*! firebase-admin v10.0.2 */
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
+ import { PrefixedFirebaseError } from '../utils/error';
19
+ export declare const APP_CHECK_ERROR_CODE_MAPPING: {
20
+ [key: string]: AppCheckErrorCode;
21
+ };
22
+ export declare type AppCheckErrorCode = 'aborted' | 'invalid-argument' | 'invalid-credential' | 'internal-error' | 'permission-denied' | 'unauthenticated' | 'not-found' | 'app-check-token-expired' | 'unknown-error';
23
+ /**
24
+ * Firebase App Check error code structure. This extends PrefixedFirebaseError.
25
+ *
26
+ * @param code - The error code.
27
+ * @param message - The error message.
28
+ * @constructor
29
+ */
30
+ export declare class FirebaseAppCheckError extends PrefixedFirebaseError {
31
+ constructor(code: AppCheckErrorCode, message: string);
32
+ }