firebase-admin 9.12.0 → 10.0.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 (189) hide show
  1. package/README.md +7 -3
  2. package/lib/app/core.d.ts +188 -0
  3. package/lib/app/core.js +19 -0
  4. package/lib/app/credential-factory.d.ts +123 -0
  5. package/lib/app/credential-factory.js +150 -0
  6. package/lib/app/credential-internal.d.ts +90 -0
  7. package/lib/{credential → app}/credential-internal.js +15 -13
  8. package/lib/app/credential.d.ts +45 -0
  9. package/lib/app/credential.js +19 -0
  10. package/lib/app/firebase-app.d.ts +51 -0
  11. package/lib/{firebase-app.js → app/firebase-app.js} +26 -156
  12. package/lib/app/firebase-namespace.d.ts +163 -0
  13. package/lib/{firebase-namespace.js → app/firebase-namespace.js} +99 -111
  14. package/lib/app/index.d.ts +27 -0
  15. package/lib/app/index.js +31 -0
  16. package/lib/app/lifecycle.d.ts +60 -0
  17. package/lib/app/lifecycle.js +165 -0
  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 +10 -10
  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 +13 -10
  26. package/lib/app-check/index.d.ts +19 -126
  27. package/lib/app-check/index.js +45 -1
  28. package/lib/app-check/token-generator.d.ts +25 -0
  29. package/lib/app-check/token-generator.js +9 -9
  30. package/lib/app-check/token-verifier.d.ts +17 -0
  31. package/lib/app-check/token-verifier.js +6 -6
  32. package/lib/auth/action-code-settings-builder.d.ts +87 -0
  33. package/lib/auth/action-code-settings-builder.js +4 -2
  34. package/lib/auth/auth-api-request.d.ts +174 -0
  35. package/lib/auth/auth-api-request.js +197 -124
  36. package/lib/auth/auth-config.d.ts +575 -0
  37. package/lib/auth/auth-config.js +43 -34
  38. package/lib/auth/auth-namespace.d.ts +255 -0
  39. package/lib/auth/auth-namespace.js +18 -0
  40. package/lib/auth/auth.d.ts +40 -0
  41. package/lib/auth/auth.js +12 -772
  42. package/lib/auth/base-auth.d.ts +613 -0
  43. package/lib/auth/base-auth.js +951 -0
  44. package/lib/auth/identifier.d.ts +57 -0
  45. package/lib/auth/identifier.js +1 -1
  46. package/lib/auth/index.d.ts +25 -1897
  47. package/lib/auth/index.js +54 -1
  48. package/lib/auth/tenant-manager.d.ts +146 -0
  49. package/lib/auth/tenant-manager.js +151 -39
  50. package/lib/auth/tenant.d.ts +130 -0
  51. package/lib/auth/tenant.js +62 -16
  52. package/lib/auth/token-generator.d.ts +44 -0
  53. package/lib/auth/token-generator.js +11 -9
  54. package/lib/auth/token-verifier.d.ts +150 -0
  55. package/lib/auth/token-verifier.js +27 -15
  56. package/lib/auth/user-import-builder.d.ts +322 -0
  57. package/lib/auth/user-import-builder.js +9 -9
  58. package/lib/auth/user-record.d.ts +265 -0
  59. package/lib/auth/user-record.js +80 -45
  60. package/lib/credential/index.d.ts +24 -66
  61. package/lib/credential/index.js +101 -1
  62. package/lib/database/database-namespace.d.ts +95 -0
  63. package/lib/database/database-namespace.js +23 -0
  64. package/lib/database/database.d.ts +66 -0
  65. package/lib/database/{database-internal.js → database.js} +16 -9
  66. package/lib/database/index.d.ts +55 -54
  67. package/lib/database/index.js +84 -13
  68. package/lib/{firebase-namespace.d.ts → default-namespace.d.ts} +7 -14
  69. package/lib/default-namespace.js +4 -5
  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 +23 -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 +34 -186
  85. package/lib/firebase-namespace-api.js +37 -2
  86. package/lib/firestore/firestore-internal.d.ts +32 -0
  87. package/lib/firestore/firestore-internal.js +3 -3
  88. package/lib/firestore/firestore-namespace.d.ts +50 -0
  89. package/lib/firestore/firestore-namespace.js +47 -0
  90. package/lib/firestore/index.d.ts +37 -35
  91. package/lib/firestore/index.js +61 -30
  92. package/lib/index.d.ts +2 -2
  93. package/lib/index.js +1 -1
  94. package/lib/installations/index.d.ts +34 -63
  95. package/lib/installations/index.js +45 -1
  96. package/lib/installations/installations-namespace.d.ts +55 -0
  97. package/lib/installations/installations-namespace.js +18 -0
  98. package/lib/installations/installations-request-handler.d.ts +43 -0
  99. package/lib/installations/installations-request-handler.js +4 -4
  100. package/lib/installations/installations.d.ts +38 -0
  101. package/lib/installations/installations.js +6 -5
  102. package/lib/instance-id/index.d.ts +23 -45
  103. package/lib/instance-id/index.js +54 -1
  104. package/lib/instance-id/instance-id-namespace.d.ts +38 -0
  105. package/lib/instance-id/instance-id-namespace.js +3 -0
  106. package/lib/instance-id/instance-id.d.ts +47 -0
  107. package/lib/instance-id/instance-id.js +14 -19
  108. package/lib/machine-learning/index.d.ts +19 -216
  109. package/lib/machine-learning/index.js +46 -1
  110. package/lib/machine-learning/machine-learning-api-client.d.ts +102 -0
  111. package/lib/machine-learning/machine-learning-api-client.js +6 -6
  112. package/lib/machine-learning/machine-learning-namespace.d.ts +85 -0
  113. package/lib/machine-learning/machine-learning-namespace.js +18 -0
  114. package/lib/machine-learning/machine-learning-utils.d.ts +22 -0
  115. package/lib/machine-learning/machine-learning-utils.js +1 -1
  116. package/lib/machine-learning/machine-learning.d.ts +181 -0
  117. package/lib/machine-learning/machine-learning.js +72 -37
  118. package/lib/messaging/batch-request-internal.d.ts +55 -0
  119. package/lib/messaging/batch-request-internal.js +9 -9
  120. package/lib/messaging/index.d.ts +18 -1140
  121. package/lib/messaging/index.js +45 -1
  122. package/lib/messaging/messaging-api-request-internal.d.ts +50 -0
  123. package/lib/messaging/messaging-api-request-internal.js +8 -8
  124. package/lib/messaging/messaging-api.d.ts +980 -0
  125. package/lib/messaging/messaging-api.js +19 -0
  126. package/lib/messaging/messaging-errors-internal.d.ts +31 -0
  127. package/lib/messaging/messaging-errors-internal.js +7 -7
  128. package/lib/messaging/messaging-internal.d.ts +27 -0
  129. package/lib/messaging/messaging-internal.js +2 -2
  130. package/lib/messaging/messaging-namespace.d.ts +181 -0
  131. package/lib/messaging/messaging-namespace.js +18 -0
  132. package/lib/messaging/messaging.d.ts +269 -0
  133. package/lib/messaging/messaging.js +83 -91
  134. package/lib/project-management/android-app.d.ts +110 -0
  135. package/lib/project-management/android-app.js +24 -15
  136. package/lib/project-management/app-metadata.d.ts +85 -0
  137. package/lib/project-management/app-metadata.js +37 -0
  138. package/lib/project-management/index.d.ts +21 -331
  139. package/lib/project-management/index.js +51 -24
  140. package/lib/project-management/ios-app.d.ts +66 -0
  141. package/lib/project-management/ios-app.js +15 -8
  142. package/lib/project-management/project-management-api-request-internal.d.ts +17 -0
  143. package/lib/project-management/project-management-api-request-internal.js +15 -15
  144. package/lib/project-management/project-management-namespace.d.ts +82 -0
  145. package/lib/project-management/project-management-namespace.js +18 -0
  146. package/lib/project-management/project-management.d.ts +115 -0
  147. package/lib/project-management/project-management.js +22 -25
  148. package/lib/remote-config/index.d.ts +19 -336
  149. package/lib/remote-config/index.js +45 -1
  150. package/lib/remote-config/remote-config-api-client-internal.d.ts +28 -0
  151. package/lib/remote-config/remote-config-api-client-internal.js +3 -3
  152. package/lib/remote-config/remote-config-api.d.ts +258 -0
  153. package/lib/remote-config/remote-config-api.js +18 -0
  154. package/lib/remote-config/remote-config-namespace.d.ts +105 -0
  155. package/lib/remote-config/remote-config-namespace.js +18 -0
  156. package/lib/remote-config/remote-config.d.ts +94 -0
  157. package/lib/remote-config/remote-config.js +27 -26
  158. package/lib/security-rules/index.d.ts +18 -184
  159. package/lib/security-rules/index.js +46 -1
  160. package/lib/security-rules/security-rules-api-client-internal.d.ts +73 -0
  161. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  162. package/lib/security-rules/security-rules-internal.d.ts +21 -0
  163. package/lib/security-rules/security-rules-internal.js +1 -1
  164. package/lib/security-rules/security-rules-namespace.d.ts +69 -0
  165. package/lib/security-rules/security-rules-namespace.js +18 -0
  166. package/lib/security-rules/security-rules.d.ts +196 -0
  167. package/lib/security-rules/security-rules.js +73 -55
  168. package/lib/storage/index.d.ts +16 -32
  169. package/lib/storage/index.js +38 -1
  170. package/lib/storage/storage-namespace.d.ts +45 -0
  171. package/lib/storage/storage-namespace.js +18 -0
  172. package/lib/storage/storage.d.ts +42 -0
  173. package/lib/storage/storage.js +9 -6
  174. package/lib/utils/api-request.d.ts +230 -0
  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 +9 -9
  178. package/lib/utils/deep-copy.d.ts +40 -0
  179. package/lib/utils/deep-copy.js +6 -6
  180. package/lib/utils/error.d.ts +650 -0
  181. package/lib/utils/error.js +34 -34
  182. package/lib/utils/index.d.ts +105 -0
  183. package/lib/utils/index.js +22 -21
  184. package/lib/utils/jwt.d.ts +131 -0
  185. package/lib/utils/jwt.js +11 -11
  186. package/lib/utils/validator.d.ts +144 -0
  187. package/lib/utils/validator.js +37 -37
  188. package/package.json +110 -8
  189. package/lib/credential/credential.js +0 -44
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.12.0 */
1
+ /*! firebase-admin v10.0.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -17,141 +17,65 @@
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");
24
- var credential_1 = require("./credential/credential");
25
- var credential_internal_1 = require("./credential/credential-internal");
26
- var validator = require("./utils/validator");
27
- 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';
20
+ exports.defaultNamespace = exports.FirebaseNamespace = exports.FirebaseNamespaceInternals = void 0;
21
+ var lifecycle_1 = require("./lifecycle");
22
+ var credential_factory_1 = require("./credential-factory");
23
+ var index_1 = require("../utils/index");
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;
146
70
  var firebaseCredential = {
147
- cert: credential_1.cert, refreshToken: credential_1.refreshToken, applicationDefault: credential_1.applicationDefault
71
+ cert: credential_factory_1.cert, refreshToken: credential_factory_1.refreshToken, applicationDefault: credential_factory_1.applicationDefault
148
72
  };
149
73
  /**
150
74
  * Global Firebase context object.
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
  /**
@@ -174,7 +98,7 @@ var FirebaseNamespace = /** @class */ (function () {
174
98
  var fn = function (app) {
175
99
  return _this.ensureApp(app).auth();
176
100
  };
177
- var auth = require('./auth/auth').Auth;
101
+ var auth = require('../auth/auth').Auth;
178
102
  return Object.assign(fn, { Auth: auth });
179
103
  },
180
104
  enumerable: false,
@@ -206,7 +130,7 @@ var FirebaseNamespace = /** @class */ (function () {
206
130
  var fn = function (app) {
207
131
  return _this.ensureApp(app).messaging();
208
132
  };
209
- var messaging = require('./messaging/messaging').Messaging;
133
+ var messaging = require('../messaging/messaging').Messaging;
210
134
  return Object.assign(fn, { Messaging: messaging });
211
135
  },
212
136
  enumerable: false,
@@ -222,7 +146,7 @@ var FirebaseNamespace = /** @class */ (function () {
222
146
  var fn = function (app) {
223
147
  return _this.ensureApp(app).storage();
224
148
  };
225
- var storage = require('./storage/storage').Storage;
149
+ var storage = require('../storage/storage').Storage;
226
150
  return Object.assign(fn, { Storage: storage });
227
151
  },
228
152
  enumerable: false,
@@ -269,7 +193,7 @@ var FirebaseNamespace = /** @class */ (function () {
269
193
  var fn = function (app) {
270
194
  return _this.ensureApp(app).machineLearning();
271
195
  };
272
- var machineLearning = require('./machine-learning/machine-learning').MachineLearning;
196
+ var machineLearning = require('../machine-learning/machine-learning').MachineLearning;
273
197
  return Object.assign(fn, { MachineLearning: machineLearning });
274
198
  },
275
199
  enumerable: false,
@@ -285,7 +209,7 @@ var FirebaseNamespace = /** @class */ (function () {
285
209
  var fn = function (app) {
286
210
  return _this.ensureApp(app).installations();
287
211
  };
288
- var installations = require('./installations/installations').Installations;
212
+ var installations = require('../installations/installations').Installations;
289
213
  return Object.assign(fn, { Installations: installations });
290
214
  },
291
215
  enumerable: false,
@@ -301,7 +225,7 @@ var FirebaseNamespace = /** @class */ (function () {
301
225
  var fn = function (app) {
302
226
  return _this.ensureApp(app).instanceId();
303
227
  };
304
- var instanceId = require('./instance-id/instance-id').InstanceId;
228
+ var instanceId = require('../instance-id/instance-id').InstanceId;
305
229
  return Object.assign(fn, { InstanceId: instanceId });
306
230
  },
307
231
  enumerable: false,
@@ -317,7 +241,7 @@ var FirebaseNamespace = /** @class */ (function () {
317
241
  var fn = function (app) {
318
242
  return _this.ensureApp(app).projectManagement();
319
243
  };
320
- var projectManagement = require('./project-management/project-management').ProjectManagement;
244
+ var projectManagement = require('../project-management/project-management').ProjectManagement;
321
245
  return Object.assign(fn, { ProjectManagement: projectManagement });
322
246
  },
323
247
  enumerable: false,
@@ -333,7 +257,7 @@ var FirebaseNamespace = /** @class */ (function () {
333
257
  var fn = function (app) {
334
258
  return _this.ensureApp(app).securityRules();
335
259
  };
336
- var securityRules = require('./security-rules/security-rules').SecurityRules;
260
+ var securityRules = require('../security-rules/security-rules').SecurityRules;
337
261
  return Object.assign(fn, { SecurityRules: securityRules });
338
262
  },
339
263
  enumerable: false,
@@ -349,7 +273,7 @@ var FirebaseNamespace = /** @class */ (function () {
349
273
  var fn = function (app) {
350
274
  return _this.ensureApp(app).remoteConfig();
351
275
  };
352
- var remoteConfig = require('./remote-config/remote-config').RemoteConfig;
276
+ var remoteConfig = require('../remote-config/remote-config').RemoteConfig;
353
277
  return Object.assign(fn, { RemoteConfig: remoteConfig });
354
278
  },
355
279
  enumerable: false,
@@ -365,7 +289,7 @@ var FirebaseNamespace = /** @class */ (function () {
365
289
  var fn = function (app) {
366
290
  return _this.ensureApp(app).appCheck();
367
291
  };
368
- var appCheck = require('./app-check/app-check').AppCheck;
292
+ var appCheck = require('../app-check/app-check').AppCheck;
369
293
  return Object.assign(fn, { AppCheck: appCheck });
370
294
  },
371
295
  enumerable: false,
@@ -375,13 +299,13 @@ var FirebaseNamespace = /** @class */ (function () {
375
299
  /**
376
300
  * Initializes the FirebaseApp instance.
377
301
  *
378
- * @param options Optional options for the FirebaseApp instance.
302
+ * @param options - Optional options for the FirebaseApp instance.
379
303
  * If none present will try to initialize from the FIREBASE_CONFIG environment variable.
380
304
  * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
381
305
  * otherwise it will be assumed to be pointing to a file.
382
- * @param appName Optional name of the FirebaseApp instance.
306
+ * @param appName - Optional name of the FirebaseApp instance.
383
307
  *
384
- * @return A new FirebaseApp instance.
308
+ * @returns A new FirebaseApp instance.
385
309
  */
386
310
  FirebaseNamespace.prototype.initializeApp = function (options, appName) {
387
311
  return this.INTERNAL.initializeApp(options, appName);
@@ -390,8 +314,8 @@ var FirebaseNamespace = /** @class */ (function () {
390
314
  * Returns the FirebaseApp instance with the provided name (or the default FirebaseApp instance
391
315
  * if no name is provided).
392
316
  *
393
- * @param appName Optional name of the FirebaseApp instance to return.
394
- * @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.
395
319
  */
396
320
  FirebaseNamespace.prototype.app = function (appName) {
397
321
  return this.INTERNAL.app(appName);
@@ -415,3 +339,67 @@ var FirebaseNamespace = /** @class */ (function () {
415
339
  return FirebaseNamespace;
416
340
  }());
417
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
+ }
@@ -0,0 +1,27 @@
1
+ /*! firebase-admin v10.0.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 App and SDK initialization.
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ export { App, AppOptions, FirebaseArrayIndexError, FirebaseError } from './core';
24
+ export { initializeApp, getApp, getApps, deleteApp } from './lifecycle';
25
+ export { Credential, ServiceAccount, GoogleOAuthAccessToken } from './credential';
26
+ export { applicationDefault, cert, refreshToken } from './credential-factory';
27
+ export declare const SDK_VERSION: string;
@@ -0,0 +1,31 @@
1
+ /*! firebase-admin v10.0.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.SDK_VERSION = void 0;
21
+ var utils_1 = require("../utils");
22
+ var lifecycle_1 = require("./lifecycle");
23
+ Object.defineProperty(exports, "initializeApp", { enumerable: true, get: function () { return lifecycle_1.initializeApp; } });
24
+ Object.defineProperty(exports, "getApp", { enumerable: true, get: function () { return lifecycle_1.getApp; } });
25
+ Object.defineProperty(exports, "getApps", { enumerable: true, get: function () { return lifecycle_1.getApps; } });
26
+ Object.defineProperty(exports, "deleteApp", { enumerable: true, get: function () { return lifecycle_1.deleteApp; } });
27
+ var credential_factory_1 = require("./credential-factory");
28
+ Object.defineProperty(exports, "applicationDefault", { enumerable: true, get: function () { return credential_factory_1.applicationDefault; } });
29
+ Object.defineProperty(exports, "cert", { enumerable: true, get: function () { return credential_factory_1.cert; } });
30
+ Object.defineProperty(exports, "refreshToken", { enumerable: true, get: function () { return credential_factory_1.refreshToken; } });
31
+ exports.SDK_VERSION = utils_1.getSdkVersion();
@@ -0,0 +1,60 @@
1
+ /*! firebase-admin v10.0.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
+ import { App, AppOptions } from './core';
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;
36
+ export declare function getApps(): App[];
37
+ /**
38
+ * Renders this given `App` unusable and frees the resources of
39
+ * all associated services (though it does *not* clean up any backend
40
+ * resources). When running the SDK locally, this method
41
+ * must be called to ensure graceful termination of the process.
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * deleteApp(app)
46
+ * .then(function() {
47
+ * console.log("App deleted successfully");
48
+ * })
49
+ * .catch(function(error) {
50
+ * console.log("Error deleting app:", error);
51
+ * });
52
+ * ```
53
+ */
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";
@@ -0,0 +1,165 @@
1
+ /*! firebase-admin v10.0.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.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");
23
+ var error_1 = require("../utils/error");
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);
108
+ }
109
+ exports.initializeApp = initializeApp;
110
+ function getApp(appName) {
111
+ if (appName === void 0) { appName = DEFAULT_APP_NAME; }
112
+ return exports.defaultAppStore.getApp(appName);
113
+ }
114
+ exports.getApp = getApp;
115
+ function getApps() {
116
+ return exports.defaultAppStore.getApps();
117
+ }
118
+ exports.getApps = getApps;
119
+ /**
120
+ * Renders this given `App` unusable and frees the resources of
121
+ * all associated services (though it does *not* clean up any backend
122
+ * resources). When running the SDK locally, this method
123
+ * must be called to ensure graceful termination of the process.
124
+ *
125
+ * @example
126
+ * ```javascript
127
+ * deleteApp(app)
128
+ * .then(function() {
129
+ * console.log("App deleted successfully");
130
+ * })
131
+ * .catch(function(error) {
132
+ * console.log("Error deleting app:", error);
133
+ * });
134
+ * ```
135
+ */
136
+ function deleteApp(app) {
137
+ return exports.defaultAppStore.deleteApp(app);
138
+ }
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
+ }