firebase-admin 4.2.0 → 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.
- package/lib/auth/auth-api-request.js +2 -2
- package/lib/auth/auth.js +1 -1
- package/lib/auth/credential.js +1 -1
- package/lib/auth/register-auth.js +1 -1
- package/lib/auth/token-generator.js +1 -1
- package/lib/auth/user-record.js +1 -1
- package/lib/database/database.js +1 -1
- package/lib/default-namespace.js +1 -1
- package/lib/firebase-app.js +68 -10
- package/lib/firebase-namespace.js +2 -2
- package/lib/firebase-service.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/messaging/messaging-api-request.js +2 -2
- package/lib/messaging/messaging.js +1 -1
- package/lib/messaging/register-messaging.js +1 -1
- package/lib/utils/api-request.js +1 -1
- package/lib/utils/deep-copy.js +1 -1
- package/lib/utils/error.js +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/validator.js +1 -1
- package/npm-shrinkwrap.json +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin v4.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 });
|
|
@@ -16,7 +16,7 @@ var FIREBASE_AUTH_PATH = '/identitytoolkit/v3/relyingparty/';
|
|
|
16
16
|
/** Firebase Auth request header. */
|
|
17
17
|
var FIREBASE_AUTH_HEADER = {
|
|
18
18
|
'Content-Type': 'application/json',
|
|
19
|
-
'X-Client-Version': 'Node/Admin/4.2.
|
|
19
|
+
'X-Client-Version': 'Node/Admin/4.2.1',
|
|
20
20
|
};
|
|
21
21
|
/** Firebase Auth request timeout duration in milliseconds. */
|
|
22
22
|
var FIREBASE_AUTH_TIMEOUT = 10000;
|
package/lib/auth/auth.js
CHANGED
package/lib/auth/credential.js
CHANGED
package/lib/auth/user-record.js
CHANGED
package/lib/database/database.js
CHANGED
package/lib/default-namespace.js
CHANGED
package/lib/firebase-app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin v4.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 });
|
|
@@ -12,6 +12,7 @@ var error_1 = require("./utils/error");
|
|
|
12
12
|
var FirebaseAppInternals = (function () {
|
|
13
13
|
function FirebaseAppInternals(credential_) {
|
|
14
14
|
this.credential_ = credential_;
|
|
15
|
+
this.isDeleted_ = false;
|
|
15
16
|
this.tokenListeners_ = [];
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
@@ -24,9 +25,25 @@ var FirebaseAppInternals = (function () {
|
|
|
24
25
|
var _this = this;
|
|
25
26
|
var expired = this.cachedToken_ && this.cachedToken_.expirationTime < Date.now();
|
|
26
27
|
if (this.cachedTokenPromise_ && !forceRefresh && !expired) {
|
|
27
|
-
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
|
+
});
|
|
28
43
|
}
|
|
29
44
|
else {
|
|
45
|
+
// Clear the outstanding token refresh timeout. This is a noop if the timeout is undefined.
|
|
46
|
+
clearTimeout(this.tokenRefreshTimeout_);
|
|
30
47
|
// this.credential_ may be an external class; resolving it in a promise helps us
|
|
31
48
|
// protect against exceptions and upgrades the result to a promise in all cases.
|
|
32
49
|
this.cachedTokenPromise_ = Promise.resolve(this.credential_.getAccessToken())
|
|
@@ -52,17 +69,28 @@ 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
94
|
var errorMessage = (typeof error === 'string') ? error : error.message;
|
|
67
95
|
errorMessage = 'Credential implementation provided to initializeApp() via the ' +
|
|
68
96
|
'"credential" property failed to fetch a valid Google OAuth2 access token with the ' +
|
|
@@ -99,6 +127,35 @@ var FirebaseAppInternals = (function () {
|
|
|
99
127
|
FirebaseAppInternals.prototype.removeAuthTokenListener = function (listener) {
|
|
100
128
|
this.tokenListeners_ = this.tokenListeners_.filter(function (other) { return other !== listener; });
|
|
101
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
|
+
};
|
|
102
159
|
return FirebaseAppInternals;
|
|
103
160
|
}());
|
|
104
161
|
exports.FirebaseAppInternals = FirebaseAppInternals;
|
|
@@ -214,6 +271,7 @@ var FirebaseApp = (function () {
|
|
|
214
271
|
var _this = this;
|
|
215
272
|
this.checkDestroyed_();
|
|
216
273
|
this.firebaseInternals_.removeApp(this.name_);
|
|
274
|
+
this.INTERNAL.delete();
|
|
217
275
|
return Promise.all(Object.keys(this.services_).map(function (serviceName) {
|
|
218
276
|
return _this.services_[serviceName].INTERNAL.delete();
|
|
219
277
|
})).then(function () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin v4.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 });
|
|
@@ -201,7 +201,7 @@ var FirebaseNamespace = (function () {
|
|
|
201
201
|
this.__esModule = true;
|
|
202
202
|
/* tslint:enable:variable-name */
|
|
203
203
|
this.credential = firebaseCredential;
|
|
204
|
-
this.SDK_VERSION = '4.2.
|
|
204
|
+
this.SDK_VERSION = '4.2.1';
|
|
205
205
|
/* tslint:disable */
|
|
206
206
|
// TODO(jwenger): Database is the only consumer of firebase.Promise. We should update it to use
|
|
207
207
|
// use the native Promise and then remove this.
|
package/lib/firebase-service.js
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin v4.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 });
|
|
@@ -12,7 +12,7 @@ var FIREBASE_MESSAGING_TIMEOUT = 10000;
|
|
|
12
12
|
var FIREBASE_MESSAGING_HTTP_METHOD = 'POST';
|
|
13
13
|
var FIREBASE_MESSAGING_HEADERS = {
|
|
14
14
|
'Content-Type': 'application/json',
|
|
15
|
-
'Sdk-Version': 'Node/Admin/4.2.
|
|
15
|
+
'Sdk-Version': 'Node/Admin/4.2.1',
|
|
16
16
|
access_token_auth: 'true',
|
|
17
17
|
};
|
|
18
18
|
/**
|
package/lib/utils/api-request.js
CHANGED
package/lib/utils/deep-copy.js
CHANGED
package/lib/utils/error.js
CHANGED
package/lib/utils/index.js
CHANGED
package/lib/utils/validator.js
CHANGED
package/npm-shrinkwrap.json
CHANGED
package/package.json
CHANGED