firebase-admin 10.3.0 → 11.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.
- package/README.md +1 -2
- package/lib/app/core.d.ts +1 -1
- package/lib/app/core.js +1 -1
- package/lib/app/credential-factory.d.ts +1 -1
- package/lib/app/credential-factory.js +8 -8
- package/lib/app/credential-internal.d.ts +1 -1
- package/lib/app/credential-internal.js +97 -106
- package/lib/app/credential.d.ts +1 -1
- package/lib/app/credential.js +1 -1
- package/lib/app/firebase-app.d.ts +1 -1
- package/lib/app/firebase-app.js +76 -91
- package/lib/app/firebase-namespace.d.ts +1 -1
- package/lib/app/firebase-namespace.js +209 -279
- package/lib/app/index.d.ts +1 -1
- package/lib/app/index.js +4 -4
- package/lib/app/lifecycle.d.ts +1 -1
- package/lib/app/lifecycle.js +37 -43
- package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
- package/lib/app-check/app-check-api-client-internal.js +54 -73
- package/lib/app-check/app-check-api.d.ts +1 -1
- package/lib/app-check/app-check-api.js +1 -1
- package/lib/app-check/app-check-namespace.d.ts +1 -1
- package/lib/app-check/app-check-namespace.js +1 -1
- package/lib/app-check/app-check.d.ts +1 -1
- package/lib/app-check/app-check.js +17 -19
- package/lib/app-check/index.d.ts +1 -1
- package/lib/app-check/index.js +7 -7
- package/lib/app-check/token-generator.d.ts +1 -1
- package/lib/app-check/token-generator.js +47 -52
- package/lib/app-check/token-verifier.d.ts +1 -1
- package/lib/app-check/token-verifier.js +46 -50
- package/lib/auth/action-code-settings-builder.d.ts +1 -1
- package/lib/auth/action-code-settings-builder.js +10 -11
- package/lib/auth/auth-api-request.d.ts +1 -1
- package/lib/auth/auth-api-request.js +346 -393
- package/lib/auth/auth-config.d.ts +1 -1
- package/lib/auth/auth-config.js +95 -106
- package/lib/auth/auth-namespace.d.ts +1 -1
- package/lib/auth/auth-namespace.js +1 -1
- package/lib/auth/auth.d.ts +1 -1
- package/lib/auth/auth.js +20 -40
- package/lib/auth/base-auth.d.ts +1 -1
- package/lib/auth/base-auth.js +137 -144
- package/lib/auth/identifier.d.ts +1 -1
- package/lib/auth/identifier.js +2 -2
- package/lib/auth/index.d.ts +1 -1
- package/lib/auth/index.js +7 -7
- package/lib/auth/tenant-manager.d.ts +1 -1
- package/lib/auth/tenant-manager.js +49 -71
- package/lib/auth/tenant.d.ts +1 -1
- package/lib/auth/tenant.js +44 -55
- package/lib/auth/token-generator.d.ts +1 -1
- package/lib/auth/token-generator.js +49 -53
- package/lib/auth/token-verifier.d.ts +1 -1
- package/lib/auth/token-verifier.js +83 -91
- package/lib/auth/user-import-builder.d.ts +1 -1
- package/lib/auth/user-import-builder.js +70 -73
- package/lib/auth/user-record.d.ts +1 -1
- package/lib/auth/user-record.js +61 -84
- package/lib/credential/index.d.ts +1 -1
- package/lib/credential/index.js +2 -2
- package/lib/database/database-namespace.d.ts +1 -1
- package/lib/database/database-namespace.js +1 -1
- package/lib/database/database.d.ts +1 -1
- package/lib/database/database.js +92 -108
- package/lib/database/index.d.ts +1 -1
- package/lib/database/index.js +10 -10
- package/lib/default-namespace.d.ts +1 -1
- package/lib/default-namespace.js +2 -2
- package/lib/eventarc/cloudevent.d.ts +1 -1
- package/lib/eventarc/cloudevent.js +1 -1
- package/lib/eventarc/eventarc-client-internal.d.ts +1 -1
- package/lib/eventarc/eventarc-client-internal.js +63 -129
- package/lib/eventarc/eventarc-utils.d.ts +1 -1
- package/lib/eventarc/eventarc-utils.js +16 -32
- package/lib/eventarc/eventarc.d.ts +1 -1
- package/lib/eventarc/eventarc.js +51 -65
- package/lib/eventarc/index.d.ts +1 -1
- package/lib/eventarc/index.js +7 -7
- package/lib/firebase-namespace-api.d.ts +1 -1
- package/lib/firebase-namespace-api.js +8 -3
- package/lib/firestore/firestore-internal.d.ts +1 -1
- package/lib/firestore/firestore-internal.js +28 -37
- package/lib/firestore/firestore-namespace.d.ts +9 -1
- package/lib/firestore/firestore-namespace.js +2 -2
- package/lib/firestore/index.d.ts +2 -2
- package/lib/firestore/index.js +7 -7
- package/lib/functions/functions-api-client-internal.d.ts +1 -1
- package/lib/functions/functions-api-client-internal.js +71 -93
- package/lib/functions/functions-api.d.ts +1 -1
- package/lib/functions/functions-api.js +1 -1
- package/lib/functions/functions.d.ts +1 -1
- package/lib/functions/functions.js +13 -15
- package/lib/functions/index.d.ts +1 -1
- package/lib/functions/index.js +7 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +14 -4
- package/lib/installations/index.d.ts +1 -1
- package/lib/installations/index.js +6 -6
- package/lib/installations/installations-namespace.d.ts +1 -1
- package/lib/installations/installations-namespace.js +1 -1
- package/lib/installations/installations-request-handler.d.ts +1 -1
- package/lib/installations/installations-request-handler.js +33 -36
- package/lib/installations/installations.d.ts +1 -1
- package/lib/installations/installations.js +17 -22
- package/lib/instance-id/index.d.ts +1 -1
- package/lib/instance-id/index.js +6 -6
- package/lib/instance-id/instance-id-namespace.d.ts +1 -1
- package/lib/instance-id/instance-id-namespace.js +1 -1
- package/lib/instance-id/instance-id.d.ts +1 -1
- package/lib/instance-id/instance-id.js +21 -26
- package/lib/machine-learning/index.d.ts +1 -1
- package/lib/machine-learning/index.js +7 -7
- package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
- package/lib/machine-learning/machine-learning-api-client.js +110 -124
- package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
- package/lib/machine-learning/machine-learning-namespace.js +1 -1
- package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
- package/lib/machine-learning/machine-learning-utils.js +9 -24
- package/lib/machine-learning/machine-learning.d.ts +1 -1
- package/lib/machine-learning/machine-learning.js +146 -207
- package/lib/messaging/batch-request-internal.d.ts +1 -1
- package/lib/messaging/batch-request-internal.js +33 -35
- package/lib/messaging/index.d.ts +1 -1
- package/lib/messaging/index.js +7 -7
- package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
- package/lib/messaging/messaging-api-request-internal.js +38 -40
- package/lib/messaging/messaging-api.d.ts +1 -1
- package/lib/messaging/messaging-api.js +1 -1
- package/lib/messaging/messaging-errors-internal.d.ts +1 -1
- package/lib/messaging/messaging-errors-internal.js +12 -13
- package/lib/messaging/messaging-internal.d.ts +1 -1
- package/lib/messaging/messaging-internal.js +51 -51
- package/lib/messaging/messaging-namespace.d.ts +1 -1
- package/lib/messaging/messaging-namespace.js +1 -1
- package/lib/messaging/messaging.d.ts +1 -1
- package/lib/messaging/messaging.js +184 -208
- package/lib/project-management/android-app.d.ts +1 -1
- package/lib/project-management/android-app.js +41 -43
- package/lib/project-management/app-metadata.d.ts +1 -1
- package/lib/project-management/app-metadata.js +1 -1
- package/lib/project-management/index.d.ts +1 -1
- package/lib/project-management/index.js +7 -7
- package/lib/project-management/ios-app.d.ts +1 -1
- package/lib/project-management/ios-app.js +25 -26
- package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
- package/lib/project-management/project-management-api-request-internal.js +84 -89
- package/lib/project-management/project-management-namespace.d.ts +1 -1
- package/lib/project-management/project-management-namespace.js +1 -1
- package/lib/project-management/project-management.d.ts +1 -1
- package/lib/project-management/project-management.js +80 -87
- package/lib/remote-config/index.d.ts +1 -1
- package/lib/remote-config/index.js +7 -7
- package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
- package/lib/remote-config/remote-config-api-client-internal.js +116 -154
- package/lib/remote-config/remote-config-api.d.ts +1 -1
- package/lib/remote-config/remote-config-api.js +1 -1
- package/lib/remote-config/remote-config-namespace.d.ts +1 -1
- package/lib/remote-config/remote-config-namespace.js +1 -1
- package/lib/remote-config/remote-config.d.ts +1 -1
- package/lib/remote-config/remote-config.js +51 -59
- package/lib/security-rules/index.d.ts +1 -1
- package/lib/security-rules/index.js +7 -7
- package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-api-client-internal.js +95 -107
- package/lib/security-rules/security-rules-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-internal.js +6 -21
- package/lib/security-rules/security-rules-namespace.d.ts +1 -1
- package/lib/security-rules/security-rules-namespace.js +1 -1
- package/lib/security-rules/security-rules.d.ts +1 -1
- package/lib/security-rules/security-rules.js +82 -91
- package/lib/storage/index.d.ts +1 -1
- package/lib/storage/index.js +7 -7
- package/lib/storage/storage-namespace.d.ts +1 -1
- package/lib/storage/storage-namespace.js +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +25 -30
- package/lib/utils/api-request.d.ts +3 -1
- package/lib/utils/api-request.js +278 -356
- package/lib/utils/crypto-signer.d.ts +1 -1
- package/lib/utils/crypto-signer.js +58 -93
- package/lib/utils/deep-copy.d.ts +1 -1
- package/lib/utils/deep-copy.js +3 -3
- package/lib/utils/error.d.ts +1 -1
- package/lib/utils/error.js +611 -681
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +38 -43
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/jwt.js +97 -123
- package/lib/utils/validator.d.ts +1 -1
- package/lib/utils/validator.js +13 -13
- package/package.json +5 -5
package/lib/database/database.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.DatabaseService = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const url_1 = require("url");
|
|
21
|
+
const path = require("path");
|
|
22
|
+
const error_1 = require("../utils/error");
|
|
23
|
+
const validator = require("../utils/validator");
|
|
24
|
+
const api_request_1 = require("../utils/api-request");
|
|
25
|
+
const index_1 = require("../utils/index");
|
|
26
|
+
const TOKEN_REFRESH_THRESHOLD_MILLIS = 5 * 60 * 1000;
|
|
27
|
+
class DatabaseService {
|
|
28
|
+
constructor(app) {
|
|
29
29
|
this.databases = {};
|
|
30
30
|
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
31
31
|
throw new error_1.FirebaseDatabaseError({
|
|
@@ -35,66 +35,56 @@ var DatabaseService = /** @class */ (function () {
|
|
|
35
35
|
}
|
|
36
36
|
this.appInternal = app;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
enumerable: false,
|
|
43
|
-
configurable: true
|
|
44
|
-
});
|
|
38
|
+
get firebaseApp() {
|
|
39
|
+
return this.app;
|
|
40
|
+
}
|
|
45
41
|
/**
|
|
46
42
|
* @internal
|
|
47
43
|
*/
|
|
48
|
-
|
|
49
|
-
var _this = this;
|
|
44
|
+
delete() {
|
|
50
45
|
if (this.tokenListener) {
|
|
51
46
|
this.firebaseApp.INTERNAL.removeAuthTokenListener(this.tokenListener);
|
|
52
47
|
clearTimeout(this.tokenRefreshTimeout);
|
|
53
48
|
}
|
|
54
|
-
|
|
55
|
-
for (
|
|
56
|
-
|
|
57
|
-
var db = this.databases[dbUrl];
|
|
49
|
+
const promises = [];
|
|
50
|
+
for (const dbUrl of Object.keys(this.databases)) {
|
|
51
|
+
const db = this.databases[dbUrl];
|
|
58
52
|
promises.push(db.INTERNAL.delete());
|
|
59
53
|
}
|
|
60
|
-
return Promise.all(promises).then(
|
|
61
|
-
|
|
54
|
+
return Promise.all(promises).then(() => {
|
|
55
|
+
this.databases = {};
|
|
62
56
|
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
configurable: true
|
|
75
|
-
});
|
|
76
|
-
DatabaseService.prototype.getDatabase = function (url) {
|
|
77
|
-
var dbUrl = this.ensureUrl(url);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the app associated with this DatabaseService instance.
|
|
60
|
+
*
|
|
61
|
+
* @returns The app associated with this DatabaseService instance.
|
|
62
|
+
*/
|
|
63
|
+
get app() {
|
|
64
|
+
return this.appInternal;
|
|
65
|
+
}
|
|
66
|
+
getDatabase(url) {
|
|
67
|
+
const dbUrl = this.ensureUrl(url);
|
|
78
68
|
if (!validator.isNonEmptyString(dbUrl)) {
|
|
79
69
|
throw new error_1.FirebaseDatabaseError({
|
|
80
70
|
code: 'invalid-argument',
|
|
81
71
|
message: 'Database URL must be a valid, non-empty URL string.',
|
|
82
72
|
});
|
|
83
73
|
}
|
|
84
|
-
|
|
74
|
+
let db = this.databases[dbUrl];
|
|
85
75
|
if (typeof db === 'undefined') {
|
|
86
76
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
87
|
-
|
|
88
|
-
db = rtdb.initStandalone(this.appInternal, dbUrl, index_1.getSdkVersion()).instance;
|
|
89
|
-
|
|
90
|
-
db.getRules =
|
|
91
|
-
return
|
|
77
|
+
const rtdb = require('@firebase/database-compat/standalone');
|
|
78
|
+
db = rtdb.initStandalone(this.appInternal, dbUrl, (0, index_1.getSdkVersion)()).instance;
|
|
79
|
+
const rulesClient = new DatabaseRulesClient(this.app, dbUrl);
|
|
80
|
+
db.getRules = () => {
|
|
81
|
+
return rulesClient.getRules();
|
|
92
82
|
};
|
|
93
|
-
db.getRulesJSON =
|
|
94
|
-
return
|
|
83
|
+
db.getRulesJSON = () => {
|
|
84
|
+
return rulesClient.getRulesJSON();
|
|
95
85
|
};
|
|
96
|
-
db.setRules =
|
|
97
|
-
return
|
|
86
|
+
db.setRules = (source) => {
|
|
87
|
+
return rulesClient.setRules(source);
|
|
98
88
|
};
|
|
99
89
|
this.databases[dbUrl] = db;
|
|
100
90
|
}
|
|
@@ -103,32 +93,31 @@ var DatabaseService = /** @class */ (function () {
|
|
|
103
93
|
this.firebaseApp.INTERNAL.addAuthTokenListener(this.tokenListener);
|
|
104
94
|
}
|
|
105
95
|
return db;
|
|
106
|
-
}
|
|
96
|
+
}
|
|
107
97
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
onTokenChange(_) {
|
|
99
|
+
const token = this.firebaseApp.INTERNAL.getCachedToken();
|
|
110
100
|
if (token) {
|
|
111
|
-
|
|
101
|
+
const delayMillis = token.expirationTime - TOKEN_REFRESH_THRESHOLD_MILLIS - Date.now();
|
|
112
102
|
// If the new token is set to expire soon (unlikely), do nothing. Somebody will eventually
|
|
113
103
|
// notice and refresh the token, at which point this callback will fire again.
|
|
114
104
|
if (delayMillis > 0) {
|
|
115
105
|
this.scheduleTokenRefresh(delayMillis);
|
|
116
106
|
}
|
|
117
107
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
var _this = this;
|
|
108
|
+
}
|
|
109
|
+
scheduleTokenRefresh(delayMillis) {
|
|
121
110
|
clearTimeout(this.tokenRefreshTimeout);
|
|
122
|
-
this.tokenRefreshTimeout = setTimeout(
|
|
123
|
-
|
|
124
|
-
.catch(
|
|
111
|
+
this.tokenRefreshTimeout = setTimeout(() => {
|
|
112
|
+
this.firebaseApp.INTERNAL.getToken(/*forceRefresh=*/ true)
|
|
113
|
+
.catch(() => {
|
|
125
114
|
// Ignore the error since this might just be an intermittent failure. If we really cannot
|
|
126
115
|
// refresh the token, an error will be logged once the existing token expires and we try
|
|
127
116
|
// to fetch a fresh one.
|
|
128
117
|
});
|
|
129
118
|
}, delayMillis);
|
|
130
|
-
}
|
|
131
|
-
|
|
119
|
+
}
|
|
120
|
+
ensureUrl(url) {
|
|
132
121
|
if (typeof url !== 'undefined') {
|
|
133
122
|
return url;
|
|
134
123
|
}
|
|
@@ -139,21 +128,20 @@ var DatabaseService = /** @class */ (function () {
|
|
|
139
128
|
code: 'invalid-argument',
|
|
140
129
|
message: 'Can\'t determine Firebase Database URL.',
|
|
141
130
|
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
145
133
|
exports.DatabaseService = DatabaseService;
|
|
146
|
-
|
|
134
|
+
const RULES_URL_PATH = '.settings/rules.json';
|
|
147
135
|
/**
|
|
148
136
|
* A helper client for managing RTDB security rules.
|
|
149
137
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
138
|
+
class DatabaseRulesClient {
|
|
139
|
+
constructor(app, dbUrl) {
|
|
140
|
+
let parsedUrl = new url_1.URL(dbUrl);
|
|
141
|
+
const emulatorHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
|
|
154
142
|
if (emulatorHost) {
|
|
155
|
-
|
|
156
|
-
parsedUrl = new url_1.URL(
|
|
143
|
+
const namespace = extractNamespace(parsedUrl);
|
|
144
|
+
parsedUrl = new url_1.URL(`http://${emulatorHost}?ns=${namespace}`);
|
|
157
145
|
}
|
|
158
146
|
parsedUrl.pathname = path.join(parsedUrl.pathname, RULES_URL_PATH);
|
|
159
147
|
this.dbUrl = parsedUrl.toString();
|
|
@@ -165,44 +153,42 @@ var DatabaseRulesClient = /** @class */ (function () {
|
|
|
165
153
|
*
|
|
166
154
|
* @returns A promise fulfilled with the rules as a raw string.
|
|
167
155
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
var req = {
|
|
156
|
+
getRules() {
|
|
157
|
+
const req = {
|
|
171
158
|
method: 'GET',
|
|
172
159
|
url: this.dbUrl,
|
|
173
160
|
};
|
|
174
161
|
return this.httpClient.send(req)
|
|
175
|
-
.then(
|
|
162
|
+
.then((resp) => {
|
|
176
163
|
if (!resp.text) {
|
|
177
164
|
throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INTERNAL_ERROR, 'HTTP response missing data.');
|
|
178
165
|
}
|
|
179
166
|
return resp.text;
|
|
180
167
|
})
|
|
181
|
-
.catch(
|
|
182
|
-
throw
|
|
168
|
+
.catch((err) => {
|
|
169
|
+
throw this.handleError(err);
|
|
183
170
|
});
|
|
184
|
-
}
|
|
171
|
+
}
|
|
185
172
|
/**
|
|
186
173
|
* Gets the currently applied security rules as a parsed JSON object. Any comments in
|
|
187
174
|
* the original source are stripped away.
|
|
188
175
|
*
|
|
189
176
|
* @returns {Promise<object>} A promise fulfilled with the parsed rules source.
|
|
190
177
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
var req = {
|
|
178
|
+
getRulesJSON() {
|
|
179
|
+
const req = {
|
|
194
180
|
method: 'GET',
|
|
195
181
|
url: this.dbUrl,
|
|
196
182
|
data: { format: 'strict' },
|
|
197
183
|
};
|
|
198
184
|
return this.httpClient.send(req)
|
|
199
|
-
.then(
|
|
185
|
+
.then((resp) => {
|
|
200
186
|
return resp.data;
|
|
201
187
|
})
|
|
202
|
-
.catch(
|
|
203
|
-
throw
|
|
188
|
+
.catch((err) => {
|
|
189
|
+
throw this.handleError(err);
|
|
204
190
|
});
|
|
205
|
-
}
|
|
191
|
+
}
|
|
206
192
|
/**
|
|
207
193
|
* Sets the specified rules on the Firebase Database instance. If the rules source is
|
|
208
194
|
* specified as a string or a Buffer, it may include comments.
|
|
@@ -211,18 +197,17 @@ var DatabaseRulesClient = /** @class */ (function () {
|
|
|
211
197
|
* or empty.
|
|
212
198
|
* @returns {Promise<void>} Resolves when the rules are set on the Database.
|
|
213
199
|
*/
|
|
214
|
-
|
|
215
|
-
var _this = this;
|
|
200
|
+
setRules(source) {
|
|
216
201
|
if (!validator.isNonEmptyString(source) &&
|
|
217
202
|
!validator.isBuffer(source) &&
|
|
218
203
|
!validator.isNonNullObject(source)) {
|
|
219
|
-
|
|
204
|
+
const error = new error_1.FirebaseDatabaseError({
|
|
220
205
|
code: 'invalid-argument',
|
|
221
206
|
message: 'Source must be a non-empty string, Buffer or an object.',
|
|
222
207
|
});
|
|
223
208
|
return Promise.reject(error);
|
|
224
209
|
}
|
|
225
|
-
|
|
210
|
+
const req = {
|
|
226
211
|
method: 'PUT',
|
|
227
212
|
url: this.dbUrl,
|
|
228
213
|
data: source,
|
|
@@ -231,14 +216,14 @@ var DatabaseRulesClient = /** @class */ (function () {
|
|
|
231
216
|
},
|
|
232
217
|
};
|
|
233
218
|
return this.httpClient.send(req)
|
|
234
|
-
.then(
|
|
219
|
+
.then(() => {
|
|
235
220
|
return;
|
|
236
221
|
})
|
|
237
|
-
.catch(
|
|
238
|
-
throw
|
|
222
|
+
.catch((err) => {
|
|
223
|
+
throw this.handleError(err);
|
|
239
224
|
});
|
|
240
|
-
}
|
|
241
|
-
|
|
225
|
+
}
|
|
226
|
+
handleError(err) {
|
|
242
227
|
if (err instanceof api_request_1.HttpError) {
|
|
243
228
|
return new error_1.FirebaseDatabaseError({
|
|
244
229
|
code: error_1.AppErrorCodes.INTERNAL_ERROR,
|
|
@@ -246,28 +231,27 @@ var DatabaseRulesClient = /** @class */ (function () {
|
|
|
246
231
|
});
|
|
247
232
|
}
|
|
248
233
|
return err;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
234
|
+
}
|
|
235
|
+
getErrorMessage(err) {
|
|
236
|
+
const intro = 'Error while accessing security rules';
|
|
252
237
|
try {
|
|
253
|
-
|
|
238
|
+
const body = err.response.data;
|
|
254
239
|
if (body && body.error) {
|
|
255
|
-
return intro
|
|
240
|
+
return `${intro}: ${body.error.trim()}`;
|
|
256
241
|
}
|
|
257
242
|
}
|
|
258
|
-
catch
|
|
243
|
+
catch {
|
|
259
244
|
// Ignore parsing errors
|
|
260
245
|
}
|
|
261
|
-
return intro
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
}());
|
|
246
|
+
return `${intro}: ${err.response.text}`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
265
249
|
function extractNamespace(parsedUrl) {
|
|
266
|
-
|
|
250
|
+
const ns = parsedUrl.searchParams.get('ns');
|
|
267
251
|
if (ns) {
|
|
268
252
|
return ns;
|
|
269
253
|
}
|
|
270
|
-
|
|
271
|
-
|
|
254
|
+
const hostname = parsedUrl.hostname;
|
|
255
|
+
const dotIndex = hostname.indexOf('.');
|
|
272
256
|
return hostname.substring(0, dotIndex).toLowerCase();
|
|
273
257
|
}
|
package/lib/database/index.d.ts
CHANGED
package/lib/database/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.getDatabaseWithUrl = exports.getDatabase = exports.ServerValue = exports.enableLogging = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const standalone_1 = require("@firebase/database-compat/standalone");
|
|
21
|
+
const app_1 = require("../app");
|
|
22
|
+
const database_1 = require("./database");
|
|
23
23
|
// TODO: Remove the following any-cast once the typins in @firebase/database-types are fixed.
|
|
24
24
|
/**
|
|
25
25
|
* {@link https://firebase.google.com/docs/reference/js/firebase.database#enablelogging | enableLogging}
|
|
@@ -59,7 +59,7 @@ exports.ServerValue = standalone_1.ServerValue;
|
|
|
59
59
|
* is provided or the `Database` service associated with the provided app.
|
|
60
60
|
*/
|
|
61
61
|
function getDatabase(app) {
|
|
62
|
-
return getDatabaseInstance({ app
|
|
62
|
+
return getDatabaseInstance({ app });
|
|
63
63
|
}
|
|
64
64
|
exports.getDatabase = getDatabase;
|
|
65
65
|
/**
|
|
@@ -89,15 +89,15 @@ exports.getDatabase = getDatabase;
|
|
|
89
89
|
* is provided or the `Database` service associated with the provided app.
|
|
90
90
|
*/
|
|
91
91
|
function getDatabaseWithUrl(url, app) {
|
|
92
|
-
return getDatabaseInstance({ url
|
|
92
|
+
return getDatabaseInstance({ url, app });
|
|
93
93
|
}
|
|
94
94
|
exports.getDatabaseWithUrl = getDatabaseWithUrl;
|
|
95
95
|
function getDatabaseInstance(options) {
|
|
96
|
-
|
|
96
|
+
let { app } = options;
|
|
97
97
|
if (typeof app === 'undefined') {
|
|
98
|
-
app = app_1.getApp();
|
|
98
|
+
app = (0, app_1.getApp)();
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const firebaseApp = app;
|
|
101
|
+
const dbService = firebaseApp.getOrInitService('database', (app) => new database_1.DatabaseService(app));
|
|
102
102
|
return dbService.getDatabase(options.url);
|
|
103
103
|
}
|
package/lib/default-namespace.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
const firebase_namespace_1 = require("./app/firebase-namespace");
|
|
20
20
|
// Inject a circular default export to allow users to use both:
|
|
21
21
|
//
|
|
22
22
|
// import firebaseAdmin from 'firebase-admin';
|