firebase-admin 9.12.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 (84) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +90 -0
  3. package/lib/app-check/app-check-api-client-internal.js +197 -0
  4. package/lib/app-check/app-check.js +79 -0
  5. package/lib/app-check/index.d.ts +160 -0
  6. package/lib/app-check/index.js +19 -0
  7. package/lib/app-check/token-generator.js +161 -0
  8. package/lib/app-check/token-verifier.js +152 -0
  9. package/lib/auth/action-code-settings-builder.js +118 -0
  10. package/lib/auth/auth-api-request.js +1856 -0
  11. package/lib/auth/auth-config.js +636 -0
  12. package/lib/auth/auth.js +836 -0
  13. package/lib/auth/identifier.js +40 -0
  14. package/lib/auth/index.d.ts +1927 -0
  15. package/lib/auth/index.js +18 -0
  16. package/lib/auth/tenant-manager.js +140 -0
  17. package/lib/auth/tenant.js +171 -0
  18. package/lib/auth/token-generator.js +200 -0
  19. package/lib/auth/token-verifier.js +259 -0
  20. package/lib/auth/user-import-builder.js +387 -0
  21. package/lib/auth/user-record.js +346 -0
  22. package/lib/credential/credential-internal.js +391 -0
  23. package/lib/credential/credential.js +44 -0
  24. package/lib/credential/index.d.ts +169 -0
  25. package/lib/credential/index.js +23 -0
  26. package/lib/database/database-internal.js +266 -0
  27. package/lib/database/index.d.ts +89 -0
  28. package/lib/database/index.js +31 -0
  29. package/lib/default-namespace.js +31 -0
  30. package/lib/firebase-app.js +349 -0
  31. package/lib/firebase-namespace-api.d.ts +243 -0
  32. package/lib/firebase-namespace-api.js +18 -0
  33. package/lib/firebase-namespace.d.ts +31 -0
  34. package/lib/firebase-namespace.js +417 -0
  35. package/lib/firestore/firestore-internal.js +105 -0
  36. package/lib/firestore/index.d.ts +50 -0
  37. package/lib/firestore/index.js +47 -0
  38. package/lib/index.d.ts +24 -0
  39. package/lib/index.js +27 -0
  40. package/lib/installations/index.d.ts +81 -0
  41. package/lib/installations/index.js +18 -0
  42. package/lib/installations/installations-request-handler.js +117 -0
  43. package/lib/installations/installations.js +62 -0
  44. package/lib/instance-id/index.d.ts +83 -0
  45. package/lib/instance-id/index.js +18 -0
  46. package/lib/instance-id/instance-id.js +87 -0
  47. package/lib/machine-learning/index.d.ts +249 -0
  48. package/lib/machine-learning/index.js +18 -0
  49. package/lib/machine-learning/machine-learning-api-client.js +304 -0
  50. package/lib/machine-learning/machine-learning-utils.js +62 -0
  51. package/lib/machine-learning/machine-learning.js +364 -0
  52. package/lib/messaging/batch-request-internal.js +129 -0
  53. package/lib/messaging/index.d.ts +1174 -0
  54. package/lib/messaging/index.js +18 -0
  55. package/lib/messaging/messaging-api-request-internal.js +128 -0
  56. package/lib/messaging/messaging-errors-internal.js +106 -0
  57. package/lib/messaging/messaging-internal.js +484 -0
  58. package/lib/messaging/messaging.js +846 -0
  59. package/lib/project-management/android-app.js +176 -0
  60. package/lib/project-management/index.d.ts +363 -0
  61. package/lib/project-management/index.js +41 -0
  62. package/lib/project-management/ios-app.js +88 -0
  63. package/lib/project-management/project-management-api-request-internal.js +273 -0
  64. package/lib/project-management/project-management.js +254 -0
  65. package/lib/remote-config/index.d.ts +369 -0
  66. package/lib/remote-config/index.js +18 -0
  67. package/lib/remote-config/remote-config-api-client-internal.js +407 -0
  68. package/lib/remote-config/remote-config.js +304 -0
  69. package/lib/security-rules/index.d.ts +216 -0
  70. package/lib/security-rules/index.js +18 -0
  71. package/lib/security-rules/security-rules-api-client-internal.js +237 -0
  72. package/lib/security-rules/security-rules-internal.js +41 -0
  73. package/lib/security-rules/security-rules.js +310 -0
  74. package/lib/storage/index.d.ts +60 -0
  75. package/lib/storage/index.js +18 -0
  76. package/lib/storage/storage.js +123 -0
  77. package/lib/utils/api-request.js +845 -0
  78. package/lib/utils/crypto-signer.js +237 -0
  79. package/lib/utils/deep-copy.js +78 -0
  80. package/lib/utils/error.js +1063 -0
  81. package/lib/utils/index.js +217 -0
  82. package/lib/utils/jwt.js +355 -0
  83. package/lib/utils/validator.js +271 -0
  84. package/package.json +122 -0
@@ -0,0 +1,417 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2017 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.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';
35
+ /**
36
+ * Internals of a FirebaseNamespace instance.
37
+ */
38
+ var FirebaseNamespaceInternals = /** @class */ (function () {
39
+ function FirebaseNamespaceInternals(firebase_) {
40
+ this.firebase_ = firebase_;
41
+ this.apps_ = {};
42
+ }
43
+ /**
44
+ * Initializes the App instance.
45
+ *
46
+ * @param options Optional options for the App instance. If none present will try to initialize
47
+ * from the FIREBASE_CONFIG environment variable. If the environment variable contains a string
48
+ * that starts with '{' it will be parsed as JSON, otherwise it will be assumed to be pointing
49
+ * to a file.
50
+ * @param appName Optional name of the FirebaseApp instance.
51
+ *
52
+ * @return A new App instance.
53
+ */
54
+ 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;
80
+ };
81
+ /**
82
+ * Returns the App instance with the provided name (or the default App instance
83
+ * if no name is provided).
84
+ *
85
+ * @param appName Optional name of the FirebaseApp instance to return.
86
+ * @return The App instance which has the provided name.
87
+ */
88
+ 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];
100
+ };
101
+ Object.defineProperty(FirebaseNamespaceInternals.prototype, "apps", {
102
+ /*
103
+ * Returns an array of all the non-deleted App instances.
104
+ */
105
+ 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]; });
109
+ },
110
+ enumerable: false,
111
+ configurable: true
112
+ });
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
+ return FirebaseNamespaceInternals;
144
+ }());
145
+ exports.FirebaseNamespaceInternals = FirebaseNamespaceInternals;
146
+ var firebaseCredential = {
147
+ cert: credential_1.cert, refreshToken: credential_1.refreshToken, applicationDefault: credential_1.applicationDefault
148
+ };
149
+ /**
150
+ * Global Firebase context object.
151
+ */
152
+ var FirebaseNamespace = /** @class */ (function () {
153
+ /* tslint:enable */
154
+ function FirebaseNamespace() {
155
+ // Hack to prevent Babel from modifying the object returned as the default admin namespace.
156
+ /* tslint:disable:variable-name */
157
+ this.__esModule = true;
158
+ /* tslint:enable:variable-name */
159
+ this.credential = firebaseCredential;
160
+ this.SDK_VERSION = index_1.getSdkVersion();
161
+ /* tslint:disable */
162
+ // TODO(jwenger): Database is the only consumer of firebase.Promise. We should update it to use
163
+ // use the native Promise and then remove this.
164
+ this.Promise = Promise;
165
+ this.INTERNAL = new FirebaseNamespaceInternals(this);
166
+ }
167
+ Object.defineProperty(FirebaseNamespace.prototype, "auth", {
168
+ /**
169
+ * Gets the `Auth` service namespace. The returned namespace can be used to get the
170
+ * `Auth` service for the default app or an explicitly specified app.
171
+ */
172
+ get: function () {
173
+ var _this = this;
174
+ var fn = function (app) {
175
+ return _this.ensureApp(app).auth();
176
+ };
177
+ var auth = require('./auth/auth').Auth;
178
+ return Object.assign(fn, { Auth: auth });
179
+ },
180
+ enumerable: false,
181
+ configurable: true
182
+ });
183
+ Object.defineProperty(FirebaseNamespace.prototype, "database", {
184
+ /**
185
+ * Gets the `Database` service namespace. The returned namespace can be used to get the
186
+ * `Database` service for the default app or an explicitly specified app.
187
+ */
188
+ get: function () {
189
+ var _this = this;
190
+ var fn = function (app) {
191
+ return _this.ensureApp(app).database();
192
+ };
193
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
194
+ return Object.assign(fn, require('@firebase/database-compat/standalone'));
195
+ },
196
+ enumerable: false,
197
+ configurable: true
198
+ });
199
+ Object.defineProperty(FirebaseNamespace.prototype, "messaging", {
200
+ /**
201
+ * Gets the `Messaging` service namespace. The returned namespace can be used to get the
202
+ * `Messaging` service for the default app or an explicitly specified app.
203
+ */
204
+ get: function () {
205
+ var _this = this;
206
+ var fn = function (app) {
207
+ return _this.ensureApp(app).messaging();
208
+ };
209
+ var messaging = require('./messaging/messaging').Messaging;
210
+ return Object.assign(fn, { Messaging: messaging });
211
+ },
212
+ enumerable: false,
213
+ configurable: true
214
+ });
215
+ Object.defineProperty(FirebaseNamespace.prototype, "storage", {
216
+ /**
217
+ * Gets the `Storage` service namespace. The returned namespace can be used to get the
218
+ * `Storage` service for the default app or an explicitly specified app.
219
+ */
220
+ get: function () {
221
+ var _this = this;
222
+ var fn = function (app) {
223
+ return _this.ensureApp(app).storage();
224
+ };
225
+ var storage = require('./storage/storage').Storage;
226
+ return Object.assign(fn, { Storage: storage });
227
+ },
228
+ enumerable: false,
229
+ configurable: true
230
+ });
231
+ Object.defineProperty(FirebaseNamespace.prototype, "firestore", {
232
+ /**
233
+ * Gets the `Firestore` service namespace. The returned namespace can be used to get the
234
+ * `Firestore` service for the default app or an explicitly specified app.
235
+ */
236
+ get: function () {
237
+ var _this = this;
238
+ var fn = function (app) {
239
+ return _this.ensureApp(app).firestore();
240
+ };
241
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
242
+ var firestore = require('@google-cloud/firestore');
243
+ fn = Object.assign(fn, firestore.Firestore);
244
+ // `v1beta1` and `v1` are lazy-loaded in the Firestore SDK. We use the same trick here
245
+ // to avoid triggering this lazy-loading upon initialization.
246
+ Object.defineProperty(fn, 'v1beta1', {
247
+ get: function () {
248
+ return firestore.v1beta1;
249
+ },
250
+ });
251
+ Object.defineProperty(fn, 'v1', {
252
+ get: function () {
253
+ return firestore.v1;
254
+ },
255
+ });
256
+ return fn;
257
+ },
258
+ enumerable: false,
259
+ configurable: true
260
+ });
261
+ Object.defineProperty(FirebaseNamespace.prototype, "machineLearning", {
262
+ /**
263
+ * Gets the `MachineLearning` service namespace. The returned namespace can be
264
+ * used to get the `MachineLearning` service for the default app or an
265
+ * explicityly specified app.
266
+ */
267
+ get: function () {
268
+ var _this = this;
269
+ var fn = function (app) {
270
+ return _this.ensureApp(app).machineLearning();
271
+ };
272
+ var machineLearning = require('./machine-learning/machine-learning').MachineLearning;
273
+ return Object.assign(fn, { MachineLearning: machineLearning });
274
+ },
275
+ enumerable: false,
276
+ configurable: true
277
+ });
278
+ Object.defineProperty(FirebaseNamespace.prototype, "installations", {
279
+ /**
280
+ * Gets the `Installations` service namespace. The returned namespace can be used to get the
281
+ * `Installations` service for the default app or an explicitly specified app.
282
+ */
283
+ get: function () {
284
+ var _this = this;
285
+ var fn = function (app) {
286
+ return _this.ensureApp(app).installations();
287
+ };
288
+ var installations = require('./installations/installations').Installations;
289
+ return Object.assign(fn, { Installations: installations });
290
+ },
291
+ enumerable: false,
292
+ configurable: true
293
+ });
294
+ Object.defineProperty(FirebaseNamespace.prototype, "instanceId", {
295
+ /**
296
+ * Gets the `InstanceId` service namespace. The returned namespace can be used to get the
297
+ * `Instance` service for the default app or an explicitly specified app.
298
+ */
299
+ get: function () {
300
+ var _this = this;
301
+ var fn = function (app) {
302
+ return _this.ensureApp(app).instanceId();
303
+ };
304
+ var instanceId = require('./instance-id/instance-id').InstanceId;
305
+ return Object.assign(fn, { InstanceId: instanceId });
306
+ },
307
+ enumerable: false,
308
+ configurable: true
309
+ });
310
+ Object.defineProperty(FirebaseNamespace.prototype, "projectManagement", {
311
+ /**
312
+ * Gets the `ProjectManagement` service namespace. The returned namespace can be used to get the
313
+ * `ProjectManagement` service for the default app or an explicitly specified app.
314
+ */
315
+ get: function () {
316
+ var _this = this;
317
+ var fn = function (app) {
318
+ return _this.ensureApp(app).projectManagement();
319
+ };
320
+ var projectManagement = require('./project-management/project-management').ProjectManagement;
321
+ return Object.assign(fn, { ProjectManagement: projectManagement });
322
+ },
323
+ enumerable: false,
324
+ configurable: true
325
+ });
326
+ Object.defineProperty(FirebaseNamespace.prototype, "securityRules", {
327
+ /**
328
+ * Gets the `SecurityRules` service namespace. The returned namespace can be used to get the
329
+ * `SecurityRules` service for the default app or an explicitly specified app.
330
+ */
331
+ get: function () {
332
+ var _this = this;
333
+ var fn = function (app) {
334
+ return _this.ensureApp(app).securityRules();
335
+ };
336
+ var securityRules = require('./security-rules/security-rules').SecurityRules;
337
+ return Object.assign(fn, { SecurityRules: securityRules });
338
+ },
339
+ enumerable: false,
340
+ configurable: true
341
+ });
342
+ Object.defineProperty(FirebaseNamespace.prototype, "remoteConfig", {
343
+ /**
344
+ * Gets the `RemoteConfig` service namespace. The returned namespace can be used to get the
345
+ * `RemoteConfig` service for the default app or an explicitly specified app.
346
+ */
347
+ get: function () {
348
+ var _this = this;
349
+ var fn = function (app) {
350
+ return _this.ensureApp(app).remoteConfig();
351
+ };
352
+ var remoteConfig = require('./remote-config/remote-config').RemoteConfig;
353
+ return Object.assign(fn, { RemoteConfig: remoteConfig });
354
+ },
355
+ enumerable: false,
356
+ configurable: true
357
+ });
358
+ Object.defineProperty(FirebaseNamespace.prototype, "appCheck", {
359
+ /**
360
+ * Gets the `AppCheck` service namespace. The returned namespace can be used to get the
361
+ * `AppCheck` service for the default app or an explicitly specified app.
362
+ */
363
+ get: function () {
364
+ var _this = this;
365
+ var fn = function (app) {
366
+ return _this.ensureApp(app).appCheck();
367
+ };
368
+ var appCheck = require('./app-check/app-check').AppCheck;
369
+ return Object.assign(fn, { AppCheck: appCheck });
370
+ },
371
+ enumerable: false,
372
+ configurable: true
373
+ });
374
+ // TODO: Change the return types to app.App in the following methods.
375
+ /**
376
+ * Initializes the FirebaseApp instance.
377
+ *
378
+ * @param options Optional options for the FirebaseApp instance.
379
+ * If none present will try to initialize from the FIREBASE_CONFIG environment variable.
380
+ * If the environment variable contains a string that starts with '{' it will be parsed as JSON,
381
+ * otherwise it will be assumed to be pointing to a file.
382
+ * @param appName Optional name of the FirebaseApp instance.
383
+ *
384
+ * @return A new FirebaseApp instance.
385
+ */
386
+ FirebaseNamespace.prototype.initializeApp = function (options, appName) {
387
+ return this.INTERNAL.initializeApp(options, appName);
388
+ };
389
+ /**
390
+ * Returns the FirebaseApp instance with the provided name (or the default FirebaseApp instance
391
+ * if no name is provided).
392
+ *
393
+ * @param appName Optional name of the FirebaseApp instance to return.
394
+ * @return The FirebaseApp instance which has the provided name.
395
+ */
396
+ FirebaseNamespace.prototype.app = function (appName) {
397
+ return this.INTERNAL.app(appName);
398
+ };
399
+ Object.defineProperty(FirebaseNamespace.prototype, "apps", {
400
+ /*
401
+ * Returns an array of all the non-deleted FirebaseApp instances.
402
+ */
403
+ get: function () {
404
+ return this.INTERNAL.apps;
405
+ },
406
+ enumerable: false,
407
+ configurable: true
408
+ });
409
+ FirebaseNamespace.prototype.ensureApp = function (app) {
410
+ if (typeof app === 'undefined') {
411
+ app = this.app();
412
+ }
413
+ return app;
414
+ };
415
+ return FirebaseNamespace;
416
+ }());
417
+ exports.FirebaseNamespace = FirebaseNamespace;
@@ -0,0 +1,105 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2017 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.getFirestoreOptions = exports.FirestoreService = void 0;
21
+ var error_1 = require("../utils/error");
22
+ var credential_internal_1 = require("../credential/credential-internal");
23
+ var validator = require("../utils/validator");
24
+ var utils = require("../utils/index");
25
+ var FirestoreService = /** @class */ (function () {
26
+ function FirestoreService(app) {
27
+ this.firestoreClient = initFirestore(app);
28
+ this.appInternal = app;
29
+ }
30
+ Object.defineProperty(FirestoreService.prototype, "app", {
31
+ /**
32
+ * Returns the app associated with this Storage instance.
33
+ *
34
+ * @return {FirebaseApp} The app associated with this Storage instance.
35
+ */
36
+ get: function () {
37
+ return this.appInternal;
38
+ },
39
+ enumerable: false,
40
+ configurable: true
41
+ });
42
+ Object.defineProperty(FirestoreService.prototype, "client", {
43
+ get: function () {
44
+ return this.firestoreClient;
45
+ },
46
+ enumerable: false,
47
+ configurable: true
48
+ });
49
+ return FirestoreService;
50
+ }());
51
+ exports.FirestoreService = FirestoreService;
52
+ function getFirestoreOptions(app) {
53
+ if (!validator.isNonNullObject(app) || !('options' in app)) {
54
+ throw new error_1.FirebaseFirestoreError({
55
+ code: 'invalid-argument',
56
+ message: 'First argument passed to admin.firestore() must be a valid Firebase app instance.',
57
+ });
58
+ }
59
+ var projectId = utils.getExplicitProjectId(app);
60
+ var credential = app.options.credential;
61
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
62
+ var firebaseVersion = require('../../package.json').version;
63
+ if (credential instanceof credential_internal_1.ServiceAccountCredential) {
64
+ return {
65
+ credentials: {
66
+ private_key: credential.privateKey,
67
+ client_email: credential.clientEmail,
68
+ },
69
+ // When the SDK is initialized with ServiceAccountCredentials an explicit projectId is
70
+ // guaranteed to be available.
71
+ projectId: projectId,
72
+ firebaseVersion: firebaseVersion,
73
+ };
74
+ }
75
+ else if (credential_internal_1.isApplicationDefault(app.options.credential)) {
76
+ // Try to use the Google application default credentials.
77
+ // If an explicit project ID is not available, let Firestore client discover one from the
78
+ // environment. This prevents the users from having to set GOOGLE_CLOUD_PROJECT in GCP runtimes.
79
+ return validator.isNonEmptyString(projectId) ? { projectId: projectId, firebaseVersion: firebaseVersion } : { firebaseVersion: firebaseVersion };
80
+ }
81
+ throw new error_1.FirebaseFirestoreError({
82
+ code: 'invalid-credential',
83
+ message: 'Failed to initialize Google Cloud Firestore client with the available credentials. ' +
84
+ 'Must initialize the SDK with a certificate credential or application default credentials ' +
85
+ 'to use Cloud Firestore API.',
86
+ });
87
+ }
88
+ exports.getFirestoreOptions = getFirestoreOptions;
89
+ function initFirestore(app) {
90
+ var options = getFirestoreOptions(app);
91
+ var firestoreDatabase;
92
+ try {
93
+ // Lazy-load the Firestore implementation here, which in turns loads gRPC.
94
+ firestoreDatabase = require('@google-cloud/firestore').Firestore;
95
+ }
96
+ catch (err) {
97
+ throw new error_1.FirebaseFirestoreError({
98
+ code: 'missing-dependencies',
99
+ message: 'Failed to import the Cloud Firestore client library for Node.js. '
100
+ + 'Make sure to install the "@google-cloud/firestore" npm package. '
101
+ + ("Original error: " + err),
102
+ });
103
+ }
104
+ return new firestoreDatabase(options);
105
+ }
@@ -0,0 +1,50 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ /*!
3
+ * Copyright 2020 Google Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { app } from '../firebase-namespace-api';
18
+ import * as _firestore from '@google-cloud/firestore';
19
+ export declare function firestore(app?: app.App): _firestore.Firestore;
20
+ export declare namespace firestore {
21
+ export import v1beta1 = _firestore.v1beta1;
22
+ export import v1 = _firestore.v1;
23
+ export import BulkWriter = _firestore.BulkWriter;
24
+ export import BulkWriterOptions = _firestore.BulkWriterOptions;
25
+ export import CollectionGroup = _firestore.CollectionGroup;
26
+ export import CollectionReference = _firestore.CollectionReference;
27
+ export import DocumentChangeType = _firestore.DocumentChangeType;
28
+ export import DocumentData = _firestore.DocumentData;
29
+ export import DocumentReference = _firestore.DocumentReference;
30
+ export import DocumentSnapshot = _firestore.DocumentSnapshot;
31
+ export import FieldPath = _firestore.FieldPath;
32
+ export import FieldValue = _firestore.FieldValue;
33
+ export import Firestore = _firestore.Firestore;
34
+ export import FirestoreDataConverter = _firestore.FirestoreDataConverter;
35
+ export import GeoPoint = _firestore.GeoPoint;
36
+ export import GrpcStatus = _firestore.GrpcStatus;
37
+ export import Precondition = _firestore.Precondition;
38
+ export import Query = _firestore.Query;
39
+ export import QueryDocumentSnapshot = _firestore.QueryDocumentSnapshot;
40
+ export import QueryPartition = _firestore.QueryPartition;
41
+ export import QuerySnapshot = _firestore.QuerySnapshot;
42
+ export import ReadOptions = _firestore.ReadOptions;
43
+ export import Settings = _firestore.Settings;
44
+ export import Timestamp = _firestore.Timestamp;
45
+ export import Transaction = _firestore.Transaction;
46
+ export import UpdateData = _firestore.UpdateData;
47
+ export import WriteBatch = _firestore.WriteBatch;
48
+ export import WriteResult = _firestore.WriteResult;
49
+ export import setLogFunction = _firestore.setLogFunction;
50
+ }
@@ -0,0 +1,47 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * Copyright 2020 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
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.firestore = void 0;
20
+ var _firestore = require("@google-cloud/firestore");
21
+ /* eslint-disable @typescript-eslint/no-namespace */
22
+ var firestore;
23
+ (function (firestore) {
24
+ /* eslint-disable @typescript-eslint/no-unused-vars */
25
+ // See https://github.com/typescript-eslint/typescript-eslint/issues/363
26
+ firestore.v1beta1 = _firestore.v1beta1;
27
+ firestore.v1 = _firestore.v1;
28
+ firestore.BulkWriter = _firestore.BulkWriter;
29
+ firestore.CollectionGroup = _firestore.CollectionGroup;
30
+ firestore.CollectionReference = _firestore.CollectionReference;
31
+ firestore.DocumentReference = _firestore.DocumentReference;
32
+ firestore.DocumentSnapshot = _firestore.DocumentSnapshot;
33
+ firestore.FieldPath = _firestore.FieldPath;
34
+ firestore.FieldValue = _firestore.FieldValue;
35
+ firestore.Firestore = _firestore.Firestore;
36
+ firestore.GeoPoint = _firestore.GeoPoint;
37
+ firestore.GrpcStatus = _firestore.GrpcStatus;
38
+ firestore.Query = _firestore.Query;
39
+ firestore.QueryDocumentSnapshot = _firestore.QueryDocumentSnapshot;
40
+ firestore.QueryPartition = _firestore.QueryPartition;
41
+ firestore.QuerySnapshot = _firestore.QuerySnapshot;
42
+ firestore.Timestamp = _firestore.Timestamp;
43
+ firestore.Transaction = _firestore.Transaction;
44
+ firestore.WriteBatch = _firestore.WriteBatch;
45
+ firestore.WriteResult = _firestore.WriteResult;
46
+ firestore.setLogFunction = _firestore.setLogFunction;
47
+ })(firestore = exports.firestore || (exports.firestore = {}));
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2017 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
+ import * as admin from './firebase-namespace';
20
+
21
+ declare module 'firebase-admin' {
22
+ }
23
+
24
+ export = admin;
package/lib/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2017 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var firebase = require("./default-namespace");
20
+ // Only Node.js has a process variable that is of [[Class]] process
21
+ var processGlobal = typeof process !== 'undefined' ? process : 0;
22
+ if (Object.prototype.toString.call(processGlobal) !== '[object process]') {
23
+ var message = "\n======== WARNING! ========\n\nfirebase-admin appears to have been installed in an unsupported environment.\nThis package should only be used in server-side or backend Node.js environments,\nand should not be used in web browsers or other client-side environments.\n\nUse the Firebase JS SDK for client-side Firebase integrations:\n\nhttps://firebase.google.com/docs/web/setup\n";
24
+ // tslint:disable-next-line:no-console
25
+ console.error(message);
26
+ }
27
+ module.exports = firebase;