firebase-admin 4.1.2 → 4.2.1

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.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v4.1.2
1
+ /*! firebase-admin v4.2.1
2
2
  https://firebase.google.com/terms/ */
3
3
  "use strict";
4
4
  var firebase_namespace_1 = require("./firebase-namespace");
@@ -1,15 +1,18 @@
1
- /*! firebase-admin v4.1.2
1
+ /*! firebase-admin v4.2.1
2
2
  https://firebase.google.com/terms/ */
3
3
  "use strict";
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ var validator = require("./utils/validator");
5
6
  var deep_copy_1 = require("./utils/deep-copy");
6
7
  var credential_1 = require("./auth/credential");
8
+ var error_1 = require("./utils/error");
7
9
  /**
8
10
  * Internals of a FirebaseApp instance.
9
11
  */
10
12
  var FirebaseAppInternals = (function () {
11
13
  function FirebaseAppInternals(credential_) {
12
14
  this.credential_ = credential_;
15
+ this.isDeleted_ = false;
13
16
  this.tokenListeners_ = [];
14
17
  }
15
18
  /**
@@ -22,23 +25,37 @@ var FirebaseAppInternals = (function () {
22
25
  var _this = this;
23
26
  var expired = this.cachedToken_ && this.cachedToken_.expirationTime < Date.now();
24
27
  if (this.cachedTokenPromise_ && !forceRefresh && !expired) {
25
- return this.cachedTokenPromise_;
28
+ return this.cachedTokenPromise_
29
+ .catch(function (error) {
30
+ // Update the cached token promise to avoid caching errors. Set it to resolve with the
31
+ // cached token if we have one (and return that promise since the token has still not
32
+ // expired).
33
+ if (_this.cachedToken_) {
34
+ _this.cachedTokenPromise_ = Promise.resolve(_this.cachedToken_);
35
+ return _this.cachedTokenPromise_;
36
+ }
37
+ // Otherwise, set the cached token promise to null so that it will force a refresh next
38
+ // time getToken() is called.
39
+ _this.cachedTokenPromise_ = null;
40
+ // And re-throw the caught error.
41
+ throw error;
42
+ });
26
43
  }
27
44
  else {
45
+ // Clear the outstanding token refresh timeout. This is a noop if the timeout is undefined.
46
+ clearTimeout(this.tokenRefreshTimeout_);
28
47
  // this.credential_ may be an external class; resolving it in a promise helps us
29
48
  // protect against exceptions and upgrades the result to a promise in all cases.
30
49
  this.cachedTokenPromise_ = Promise.resolve(this.credential_.getAccessToken())
31
50
  .then(function (result) {
32
- if (result === null) {
33
- return null;
34
- }
35
51
  // Since the developer can provide the credential implementation, we want to weakly verify
36
52
  // the return type until the type is properly exported.
37
- if (typeof result !== 'object' ||
53
+ if (!validator.isNonNullObject(result) ||
38
54
  typeof result.expires_in !== 'number' ||
39
55
  typeof result.access_token !== 'string') {
40
- throw new Error("Invalid access token generated: " + JSON.stringify(result) + ". Valid access tokens must " +
41
- 'be an object with the "expires_in" (number) and "access_token" (string) properties.');
56
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, "Invalid access token generated: \"" + JSON.stringify(result) + "\". Valid access " +
57
+ 'tokens must be an object with the "expires_in" (number) and "access_token" ' +
58
+ '(string) properties.');
42
59
  }
43
60
  var token = {
44
61
  accessToken: result.access_token,
@@ -52,21 +69,33 @@ var FirebaseAppInternals = (function () {
52
69
  listener(token.accessToken);
53
70
  });
54
71
  }
72
+ // Establish a timeout to proactively refresh the token every minute starting at five
73
+ // minutes before it expires. Once a token refresh succeeds, no further retries are
74
+ // needed; if it fails, retry every minute until the token expires (resulting in a total
75
+ // of four retries: at 4, 3, 2, and 1 minutes).
76
+ var refreshTimeInSeconds = (result.expires_in - (5 * 60));
77
+ var numRetries = 4;
78
+ // In the rare cases the token is short-lived (that is, it expires in less than five
79
+ // minutes from when it was fetched), establish the timeout to refresh it after the
80
+ // current minute ends and update the number of retries that should be attempted before
81
+ // the token expires.
82
+ if (refreshTimeInSeconds <= 0) {
83
+ refreshTimeInSeconds = result.expires_in % 60;
84
+ numRetries = Math.floor(result.expires_in / 60) - 1;
85
+ }
86
+ // The token refresh timeout keeps the Node.js process alive, so only create it if this
87
+ // instance has not already been deleted.
88
+ if (numRetries && !_this.isDeleted_) {
89
+ _this.setTokenRefreshTimeout(refreshTimeInSeconds * 1000, numRetries);
90
+ }
55
91
  return token;
56
92
  })
57
93
  .catch(function (error) {
58
- // Update the cached token promise to avoid caching errors. Set it to resolve with the
59
- // cached token if we have one; otherwise, set it to null.
60
- if (_this.cachedToken_) {
61
- _this.cachedTokenPromise_ = Promise.resolve(_this.cachedToken_);
62
- }
63
- else {
64
- _this.cachedTokenPromise_ = null;
65
- }
66
- var errorMessage = 'Credential implementation provided to initializeApp() via the ' +
94
+ var errorMessage = (typeof error === 'string') ? error : error.message;
95
+ errorMessage = 'Credential implementation provided to initializeApp() via the ' +
67
96
  '"credential" property failed to fetch a valid Google OAuth2 access token with the ' +
68
- ("following error: \"" + error.message + "\".");
69
- if (error.message.indexOf('invalid_grant') !== -1) {
97
+ ("following error: \"" + errorMessage + "\".");
98
+ if (errorMessage.indexOf('invalid_grant') !== -1) {
70
99
  errorMessage += ' There are two likely causes: (1) your server time is not properly ' +
71
100
  'synced or (2) your certificate key file has been revoked. To solve (1), re-sync the ' +
72
101
  'time on your server. To solve (2), make sure the key ID for your key file is still ' +
@@ -74,7 +103,7 @@ var FirebaseAppInternals = (function () {
74
103
  'not, generate a new key file at ' +
75
104
  'https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk.';
76
105
  }
77
- throw new Error(errorMessage);
106
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, errorMessage);
78
107
  });
79
108
  return this.cachedTokenPromise_;
80
109
  }
@@ -98,6 +127,35 @@ var FirebaseAppInternals = (function () {
98
127
  FirebaseAppInternals.prototype.removeAuthTokenListener = function (listener) {
99
128
  this.tokenListeners_ = this.tokenListeners_.filter(function (other) { return other !== listener; });
100
129
  };
130
+ /**
131
+ * Deletes the FirebaseAppInternals instance.
132
+ */
133
+ FirebaseAppInternals.prototype.delete = function () {
134
+ this.isDeleted_ = true;
135
+ // Clear the token refresh timeout so it doesn't keep the Node.js process alive.
136
+ clearTimeout(this.tokenRefreshTimeout_);
137
+ };
138
+ /**
139
+ * Establishes timeout to refresh the Google OAuth2 access token used by the SDK.
140
+ *
141
+ * @param {number} delayInMilliseconds The delay to use for the timeout.
142
+ * @param {number} numRetries The number of times to retry fetching a new token if the prior fetch
143
+ * failed.
144
+ */
145
+ FirebaseAppInternals.prototype.setTokenRefreshTimeout = function (delayInMilliseconds, numRetries) {
146
+ var _this = this;
147
+ this.tokenRefreshTimeout_ = setTimeout(function () {
148
+ _this.getToken(/* forceRefresh */ true)
149
+ .catch(function (error) {
150
+ // Ignore the error since this might just be an intermittent failure. If we really cannot
151
+ // refresh the token, an error will be logged once the existing token expires and we try
152
+ // to fetch a fresh one.
153
+ if (numRetries > 0) {
154
+ _this.setTokenRefreshTimeout(60 * 1000, numRetries - 1);
155
+ }
156
+ });
157
+ }, delayInMilliseconds);
158
+ };
101
159
  return FirebaseAppInternals;
102
160
  }());
103
161
  exports.FirebaseAppInternals = FirebaseAppInternals;
@@ -142,7 +200,7 @@ var FirebaseApp = (function () {
142
200
  }
143
201
  }
144
202
  if (typeof errorMessage !== 'undefined') {
145
- throw new Error("Invalid Firebase app options passed as the first argument to initializeApp() for the " +
203
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_OPTIONS, "Invalid Firebase app options passed as the first argument to initializeApp() for the " +
146
204
  ("app named \"" + this.name_ + "\". " + errorMessage));
147
205
  }
148
206
  // TODO(jwenger): NEXT MAJOR RELEASE - remove "serviceAccount" property deprecation warning and
@@ -160,24 +218,6 @@ var FirebaseApp = (function () {
160
218
  _this[serviceName] = _this.getService_.bind(_this, serviceName);
161
219
  });
162
220
  this.INTERNAL = new FirebaseAppInternals(this.options_.credential);
163
- // Asynchronously ensure the provided credential can generate OAuth access tokens. We explicitly
164
- // call this here to provide the developer with an error as soon as possible and so that each
165
- // individual service doesn't have to worry about logging this class of error. Because getToken()
166
- // caches tokens, there is no real performance penalty for calling this here.
167
- // b/35366344: We only do this if the credential has a non-null certificate to ensure we do not
168
- // do this check for things like Application Default Credentials on Cloud Functions, which
169
- // often results in ECONNTIMEOUT errors.
170
- if (typeof this.options_.credential.getCertificate === 'function') {
171
- var certificate = this.options_.credential.getCertificate();
172
- if (certificate) {
173
- this.INTERNAL.getToken()
174
- .catch(function (error) {
175
- /* tslint:disable:no-console */
176
- console.error(error);
177
- /* tslint:enable:no-console */
178
- });
179
- }
180
- }
181
221
  }
182
222
  /**
183
223
  * Firebase services available off of a FirebaseApp instance. These are monkey-patched via
@@ -186,15 +226,15 @@ var FirebaseApp = (function () {
186
226
  */
187
227
  /* istanbul ignore next */
188
228
  FirebaseApp.prototype.auth = function () {
189
- throw new Error('INTERNAL ASSERT FAILED: Firebase auth() service has not been registered.');
229
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Firebase auth() service has not been registered.');
190
230
  };
191
231
  /* istanbul ignore next */
192
232
  FirebaseApp.prototype.database = function () {
193
- throw new Error('INTERNAL ASSERT FAILED: Firebase database() service has not been registered.');
233
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Firebase database() service has not been registered.');
194
234
  };
195
235
  /* istanbul ignore next */
196
236
  FirebaseApp.prototype.messaging = function () {
197
- throw new Error('INTERNAL ASSERT FAILED: Firebase messaging() service has not been registered.');
237
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Firebase messaging() service has not been registered.');
198
238
  };
199
239
  Object.defineProperty(FirebaseApp.prototype, "name", {
200
240
  /**
@@ -231,6 +271,7 @@ var FirebaseApp = (function () {
231
271
  var _this = this;
232
272
  this.checkDestroyed_();
233
273
  this.firebaseInternals_.removeApp(this.name_);
274
+ this.INTERNAL.delete();
234
275
  return Promise.all(Object.keys(this.services_).map(function (serviceName) {
235
276
  return _this.services_[serviceName].INTERNAL.delete();
236
277
  })).then(function () {
@@ -263,7 +304,7 @@ var FirebaseApp = (function () {
263
304
  */
264
305
  FirebaseApp.prototype.checkDestroyed_ = function () {
265
306
  if (this.isDeleted_) {
266
- throw new Error("Firebase app named \"" + this.name_ + "\" has already been deleted.");
307
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.APP_DELETED, "Firebase app named \"" + this.name_ + "\" has already been deleted.");
267
308
  }
268
309
  };
269
310
  return FirebaseApp;
@@ -1,8 +1,9 @@
1
- /*! firebase-admin v4.1.2
1
+ /*! firebase-admin v4.2.1
2
2
  https://firebase.google.com/terms/ */
3
3
  "use strict";
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  var deep_copy_1 = require("./utils/deep-copy");
6
+ var error_1 = require("./utils/error");
6
7
  var firebase_app_1 = require("./firebase-app");
7
8
  var credential_1 = require("./auth/credential");
8
9
  var DEFAULT_APP_NAME = '[DEFAULT]';
@@ -30,18 +31,18 @@ var FirebaseNamespaceInternals = (function () {
30
31
  FirebaseNamespaceInternals.prototype.initializeApp = function (options, appName) {
31
32
  if (appName === void 0) { appName = DEFAULT_APP_NAME; }
32
33
  if (typeof appName !== 'string' || appName === '') {
33
- throw new Error("Illegal Firebase app name \"" + appName + "\" provided. App name must be a non-empty string.");
34
+ 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.");
34
35
  }
35
36
  else if (appName in this.apps_) {
36
37
  if (appName === DEFAULT_APP_NAME) {
37
- throw new Error('The default Firebase app already exists. This means you called initializeApp() ' +
38
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, 'The default Firebase app already exists. This means you called initializeApp() ' +
38
39
  'more than once without providing an app name as the second argument. In most cases ' +
39
40
  'you only need to call initializeApp() once. But if you do want to initialize ' +
40
41
  'multiple apps, pass a second argument to initializeApp() to give each app a unique ' +
41
42
  'name.');
42
43
  }
43
44
  else {
44
- throw new Error("Firebase app named \"" + appName + "\" already exists. This means you called initializeApp() " +
45
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.DUPLICATE_APP, "Firebase app named \"" + appName + "\" already exists. This means you called initializeApp() " +
45
46
  'more than once with the same app name as the second argument. Make sure you provide a ' +
46
47
  'unique name every time you call initializeApp().');
47
48
  }
@@ -61,7 +62,7 @@ var FirebaseNamespaceInternals = (function () {
61
62
  FirebaseNamespaceInternals.prototype.app = function (appName) {
62
63
  if (appName === void 0) { appName = DEFAULT_APP_NAME; }
63
64
  if (typeof appName !== 'string' || appName === '') {
64
- throw new Error("Illegal Firebase app name \"" + appName + "\" provided. App name must be a non-empty string.");
65
+ 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.");
65
66
  }
66
67
  else if (!(appName in this.apps_)) {
67
68
  var errorMessage = void 0;
@@ -72,7 +73,7 @@ var FirebaseNamespaceInternals = (function () {
72
73
  errorMessage = "Firebase app named \"" + appName + "\" does not exist. ";
73
74
  }
74
75
  errorMessage += 'Make sure you call initializeApp() before using any of the Firebase services.';
75
- throw new Error(errorMessage);
76
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.NO_APP, errorMessage);
76
77
  }
77
78
  return this.apps_[appName];
78
79
  };
@@ -97,7 +98,7 @@ var FirebaseNamespaceInternals = (function () {
97
98
  */
98
99
  FirebaseNamespaceInternals.prototype.removeApp = function (appName) {
99
100
  if (typeof appName === 'undefined') {
100
- throw new Error("No Firebase app name provided. App name must be a non-empty string.");
101
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_APP_NAME, "No Firebase app name provided. App name must be a non-empty string.");
101
102
  }
102
103
  var appToRemove = this.app(appName);
103
104
  this.callAppHooks_(appToRemove, 'delete');
@@ -114,14 +115,18 @@ var FirebaseNamespaceInternals = (function () {
114
115
  */
115
116
  FirebaseNamespaceInternals.prototype.registerService = function (serviceName, createService, serviceProperties, appHook) {
116
117
  var _this = this;
118
+ var errorMessage;
117
119
  if (typeof serviceName === 'undefined') {
118
- throw new Error("No service name provided. Service name must be a non-empty string.");
120
+ errorMessage = "No service name provided. Service name must be a non-empty string.";
119
121
  }
120
122
  else if (typeof serviceName !== 'string' || serviceName === '') {
121
- throw new Error("Illegal service name \"" + serviceName + "\" provided. Service name must be a non-empty string.");
123
+ errorMessage = "Invalid service name \"" + serviceName + "\" provided. Service name must be a non-empty string.";
122
124
  }
123
125
  else if (serviceName in this.serviceFactories) {
124
- throw new Error("Firebase service named \"" + serviceName + "\" has already been registered.");
126
+ errorMessage = "Firebase service named \"" + serviceName + "\" has already been registered.";
127
+ }
128
+ if (typeof errorMessage !== 'undefined') {
129
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, "INTERNAL ASSERT FAILED: " + errorMessage);
125
130
  }
126
131
  this.serviceFactories[serviceName] = createService;
127
132
  if (appHook) {
@@ -196,7 +201,7 @@ var FirebaseNamespace = (function () {
196
201
  this.__esModule = true;
197
202
  /* tslint:enable:variable-name */
198
203
  this.credential = firebaseCredential;
199
- this.SDK_VERSION = '4.1.2';
204
+ this.SDK_VERSION = '4.2.1';
200
205
  /* tslint:disable */
201
206
  // TODO(jwenger): Database is the only consumer of firebase.Promise. We should update it to use
202
207
  // use the native Promise and then remove this.
@@ -210,15 +215,15 @@ var FirebaseNamespace = (function () {
210
215
  */
211
216
  /* istanbul ignore next */
212
217
  FirebaseNamespace.prototype.auth = function () {
213
- throw new Error('INTERNAL ASSERT FAILED: Firebase auth() service has not been registered.');
218
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Firebase auth() service has not been registered.');
214
219
  };
215
220
  /* istanbul ignore next */
216
221
  FirebaseNamespace.prototype.database = function () {
217
- throw new Error('INTERNAL ASSERT FAILED: Firebase database() service has not been registered.');
222
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Firebase database() service has not been registered.');
218
223
  };
219
224
  /* istanbul ignore next */
220
225
  FirebaseNamespace.prototype.messaging = function () {
221
- throw new Error('INTERNAL ASSERT FAILED: Firebase messaging() service has not been registered.');
226
+ throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Firebase messaging() service has not been registered.');
222
227
  };
223
228
  /**
224
229
  * Initializes the FirebaseApp instance.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v4.1.2
1
+ /*! firebase-admin v4.2.1
2
2
  https://firebase.google.com/terms/ */
3
3
  "use strict";
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v4.1.2
1
+ /*! firebase-admin v4.2.1
2
2
  https://firebase.google.com/terms/ */
3
3
  declare namespace admin {
4
4
  interface FirebaseError {
@@ -9,21 +9,9 @@ declare namespace admin {
9
9
  toJSON(): Object;
10
10
  }
11
11
 
12
- class Promise<T> extends Promise_Instance<T> {
13
- static all(values: admin.Promise<any>[]): admin.Promise<any[]>;
14
- static reject(error: Error): admin.Promise<any>;
15
- static resolve<T>(value?: T): admin.Promise<T>;
16
- }
17
-
18
- class Promise_Instance<T> implements admin.Thenable<any> {
19
- constructor(resolver: (a?: (a: T) => undefined, b?: (a: Error) => undefined) => any);
20
- catch(onReject?: (a: Error) => any): admin.Thenable<any>;
21
- then(onResolve?: (a: T) => any, onReject?: (a: Error) => any): admin.Promise<any>;
22
- }
23
-
24
- interface Thenable<T> {
25
- catch(onReject?: (a: Error) => any): admin.Thenable<any>;
26
- then(onResolve?: (a: T) => any, onReject?: (a: Error) => any): admin.Thenable<any>;
12
+ type FirebaseArrayIndexError = {
13
+ index: number;
14
+ error: FirebaseError;
27
15
  }
28
16
 
29
17
  interface ServiceAccount {
@@ -63,7 +51,7 @@ declare namespace admin.app {
63
51
  auth(): admin.auth.Auth;
64
52
  database(): admin.database.Database;
65
53
  messaging(): admin.messaging.Messaging;
66
- delete(): admin.Promise<undefined>;
54
+ delete(): Promise<void>;
67
55
  }
68
56
  }
69
57
 
@@ -99,27 +87,39 @@ declare namespace admin.auth {
99
87
  }
100
88
 
101
89
  interface DecodedIdToken {
102
- uid: string;
90
+ aud: string;
91
+ auth_time: number;
92
+ exp: number;
93
+ firebase: {
94
+ identities: {
95
+ [key: string]: any;
96
+ };
97
+ sign_in_provider: string;
98
+ [key: string]: any;
99
+ };
100
+ iat: number;
101
+ iss: string;
103
102
  sub: string;
104
- [other: string]: any;
103
+ uid: string;
104
+ [key: string]: any;
105
105
  }
106
106
 
107
107
  interface Auth {
108
108
  app: admin.app.App;
109
109
 
110
- createCustomToken(uid: string, developerClaims?: Object): admin.Promise<string>;
111
- createUser(properties: Object): admin.Promise<admin.auth.UserRecord>;
112
- deleteUser(uid: string): admin.Promise<undefined>;
113
- getUser(uid: string): admin.Promise<admin.auth.UserRecord>;
114
- getUserByEmail(email: string): admin.Promise<admin.auth.UserRecord>;
115
- updateUser(uid: string, properties: Object): admin.Promise<admin.auth.UserRecord>;
116
- verifyIdToken(idToken: string): admin.Promise<DecodedIdToken>;
110
+ createCustomToken(uid: string, developerClaims?: Object): Promise<string>;
111
+ createUser(properties: Object): Promise<admin.auth.UserRecord>;
112
+ deleteUser(uid: string): Promise<void>;
113
+ getUser(uid: string): Promise<admin.auth.UserRecord>;
114
+ getUserByEmail(email: string): Promise<admin.auth.UserRecord>;
115
+ updateUser(uid: string, properties: Object): Promise<admin.auth.UserRecord>;
116
+ verifyIdToken(idToken: string): Promise<admin.auth.DecodedIdToken>;
117
117
  }
118
118
  }
119
119
 
120
120
  declare namespace admin.credential {
121
121
  interface Credential {
122
- getAccessToken(): admin.Promise<admin.GoogleOAuthAccessToken>;
122
+ getAccessToken(): Promise<admin.GoogleOAuthAccessToken>;
123
123
  }
124
124
 
125
125
  function applicationDefault(): admin.credential.Credential;
@@ -131,8 +131,8 @@ declare namespace admin.database {
131
131
  interface Database {
132
132
  app: admin.app.App;
133
133
 
134
- goOffline(): undefined;
135
- goOnline(): undefined;
134
+ goOffline(): void;
135
+ goOnline(): void;
136
136
  ref(path?: string): admin.database.Reference;
137
137
  refFromURL(url: string): admin.database.Reference;
138
138
  }
@@ -154,17 +154,18 @@ declare namespace admin.database {
154
154
  }
155
155
 
156
156
  interface OnDisconnect {
157
- cancel(onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
158
- remove(onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
159
- set(value: any, onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
157
+ cancel(onComplete?: (a: Error|null) => any): Promise<void>;
158
+ remove(onComplete?: (a: Error|null) => any): Promise<void>;
159
+ set(value: any, onComplete?: (a: Error|null) => any): Promise<void>;
160
160
  setWithPriority(
161
161
  value: any,
162
162
  priority: number|string|null,
163
163
  onComplete?: (a: Error|null) => any
164
- ): admin.Promise<undefined>;
165
- update(values: Object, onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
164
+ ): Promise<void>;
165
+ update(values: Object, onComplete?: (a: Error|null) => any): Promise<void>;
166
166
  }
167
167
 
168
+ type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
168
169
  interface Query {
169
170
  ref: admin.database.Reference;
170
171
 
@@ -174,22 +175,22 @@ declare namespace admin.database {
174
175
  limitToFirst(limit: number): admin.database.Query;
175
176
  limitToLast(limit: number): admin.database.Query;
176
177
  off(
177
- eventType?: string,
178
+ eventType?: admin.database.EventType,
178
179
  callback?: (a: admin.database.DataSnapshot, b?: string|null) => any,
179
180
  context?: Object|null
180
- ): undefined;
181
+ ): void;
181
182
  on(
182
- eventType: string,
183
+ eventType: admin.database.EventType,
183
184
  callback: (a: admin.database.DataSnapshot|null, b?: string) => any,
184
185
  cancelCallbackOrContext?: Object|null,
185
186
  context?: Object|null
186
187
  ): (a: admin.database.DataSnapshot|null, b?: string) => any;
187
188
  once(
188
- eventType: string,
189
+ eventType: admin.database.EventType,
189
190
  successCallback?: (a: admin.database.DataSnapshot, b?: string) => any,
190
191
  failureCallbackOrContext?: Object|null,
191
192
  context?: Object|null
192
- ): admin.Promise<any>;
193
+ ): Promise<any>;
193
194
  orderByChild(path: string): admin.database.Query;
194
195
  orderByKey(): admin.database.Query;
195
196
  orderByPriority(): admin.database.Query;
@@ -207,28 +208,28 @@ declare namespace admin.database {
207
208
  child(path: string): admin.database.Reference;
208
209
  onDisconnect(): admin.database.OnDisconnect;
209
210
  push(value?: any, onComplete?: (a: Error|null) => any): admin.database.ThenableReference;
210
- remove(onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
211
- set(value: any, onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
211
+ remove(onComplete?: (a: Error|null) => any): Promise<void>;
212
+ set(value: any, onComplete?: (a: Error|null) => any): Promise<void>;
212
213
  setPriority(
213
214
  priority: string|number|null,
214
215
  onComplete: (a: Error|null) => any
215
- ): admin.Promise<undefined>;
216
+ ): Promise<void>;
216
217
  setWithPriority(
217
218
  newVal: any, newPriority: string|number|null,
218
219
  onComplete?: (a: Error|null) => any
219
- ): admin.Promise<undefined>;
220
+ ): Promise<void>;
220
221
  transaction(
221
222
  transactionUpdate: (a: any) => any,
222
223
  onComplete?: (a: Error|null, b: boolean, c: admin.database.DataSnapshot|null) => any,
223
224
  applyLocally?: boolean
224
- ): admin.Promise<{
225
+ ): Promise<{
225
226
  committed: boolean,
226
227
  snapshot: admin.database.DataSnapshot|null
227
228
  }>;
228
- update(values: Object, onComplete?: (a: Error|null) => any): admin.Promise<undefined>;
229
+ update(values: Object, onComplete?: (a: Error|null) => any): Promise<void>;
229
230
  }
230
231
 
231
- interface ThenableReference extends admin.database.Reference, admin.Thenable<any> {}
232
+ interface ThenableReference extends admin.database.Reference, Promise<any> {}
232
233
 
233
234
  function enableLogging(logger?: boolean|((message: string) => any), persistent?: boolean): any;
234
235
  }
@@ -255,7 +256,7 @@ declare namespace admin.messaging {
255
256
  clickAction?: string;
256
257
  titleLocKey?: string;
257
258
  titleLocArgs?: string;
258
- [other: string]: string;
259
+ [key: string]: string | undefined;
259
260
  };
260
261
 
261
262
  type MessagingPayload = {
@@ -271,7 +272,7 @@ declare namespace admin.messaging {
271
272
  mutableContent?: boolean;
272
273
  contentAvailable?: boolean;
273
274
  restrictedPackageName?: string;
274
- [other: string]: any;
275
+ [key: string]: any | undefined;
275
276
  };
276
277
 
277
278
  type MessagingDeviceResult = {
@@ -302,6 +303,12 @@ declare namespace admin.messaging {
302
303
  messageId: number;
303
304
  };
304
305
 
306
+ type MessagingTopicManagementResponse = {
307
+ failureCount: number;
308
+ successCount: number;
309
+ errors: admin.FirebaseArrayIndexError[];
310
+ };
311
+
305
312
  interface Messaging {
306
313
  app: admin.app.App;
307
314
 
@@ -309,27 +316,43 @@ declare namespace admin.messaging {
309
316
  registrationToken: string,
310
317
  payload: admin.messaging.MessagingPayload,
311
318
  options?: admin.messaging.MessagingOptions
312
- ): admin.Promise<admin.messaging.MessagingDevicesResponse>;
319
+ ): Promise<admin.messaging.MessagingDevicesResponse>;
313
320
  sendToDevice(
314
321
  registrationTokens: string[],
315
322
  payload: admin.messaging.MessagingPayload,
316
323
  options?: admin.messaging.MessagingOptions
317
- ): admin.Promise<admin.messaging.MessagingDevicesResponse>;
324
+ ): Promise<admin.messaging.MessagingDevicesResponse>;
318
325
  sendToDeviceGroup(
319
326
  notificationKey: string,
320
327
  payload: admin.messaging.MessagingPayload,
321
328
  options?: admin.messaging.MessagingOptions
322
- ): admin.Promise<admin.messaging.MessagingDeviceGroupResponse>;
329
+ ): Promise<admin.messaging.MessagingDeviceGroupResponse>;
323
330
  sendToTopic(
324
331
  topic: string,
325
332
  payload: admin.messaging.MessagingPayload,
326
333
  options?: admin.messaging.MessagingOptions
327
- ): admin.Promise<admin.messaging.MessagingTopicResponse>;
334
+ ): Promise<admin.messaging.MessagingTopicResponse>;
328
335
  sendToCondition(
329
336
  condition: string,
330
337
  payload: admin.messaging.MessagingPayload,
331
338
  options?: admin.messaging.MessagingOptions
332
- ): admin.Promise<admin.messaging.MessagingConditionResponse>;
339
+ ): Promise<admin.messaging.MessagingConditionResponse>;
340
+ subscribeToTopic(
341
+ registrationToken: string,
342
+ topic: string
343
+ ): Promise<admin.messaging.MessagingTopicManagementResponse>;
344
+ subscribeToTopic(
345
+ registrationTokens: string[],
346
+ topic: string
347
+ ): Promise<admin.messaging.MessagingTopicManagementResponse>;
348
+ unsubscribeFromTopic(
349
+ registrationToken: string,
350
+ topic: string
351
+ ): Promise<admin.messaging.MessagingTopicManagementResponse>;
352
+ unsubscribeFromTopic(
353
+ registrationTokens: string[],
354
+ topic: string
355
+ ): Promise<admin.messaging.MessagingTopicManagementResponse>;
333
356
  }
334
357
  }
335
358
 
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v4.1.2
1
+ /*! firebase-admin v4.2.1
2
2
  https://firebase.google.com/terms/ */
3
3
  "use strict";
4
4
  var firebase = require("./default-namespace");