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.
- package/LICENSE +201 -0
- package/README.md +90 -0
- package/lib/app-check/app-check-api-client-internal.js +197 -0
- package/lib/app-check/app-check.js +79 -0
- package/lib/app-check/index.d.ts +160 -0
- package/lib/app-check/index.js +19 -0
- package/lib/app-check/token-generator.js +161 -0
- package/lib/app-check/token-verifier.js +152 -0
- package/lib/auth/action-code-settings-builder.js +118 -0
- package/lib/auth/auth-api-request.js +1856 -0
- package/lib/auth/auth-config.js +636 -0
- package/lib/auth/auth.js +836 -0
- package/lib/auth/identifier.js +40 -0
- package/lib/auth/index.d.ts +1927 -0
- package/lib/auth/index.js +18 -0
- package/lib/auth/tenant-manager.js +140 -0
- package/lib/auth/tenant.js +171 -0
- package/lib/auth/token-generator.js +200 -0
- package/lib/auth/token-verifier.js +259 -0
- package/lib/auth/user-import-builder.js +387 -0
- package/lib/auth/user-record.js +346 -0
- package/lib/credential/credential-internal.js +391 -0
- package/lib/credential/credential.js +44 -0
- package/lib/credential/index.d.ts +169 -0
- package/lib/credential/index.js +23 -0
- package/lib/database/database-internal.js +266 -0
- package/lib/database/index.d.ts +89 -0
- package/lib/database/index.js +31 -0
- package/lib/default-namespace.js +31 -0
- package/lib/firebase-app.js +349 -0
- package/lib/firebase-namespace-api.d.ts +243 -0
- package/lib/firebase-namespace-api.js +18 -0
- package/lib/firebase-namespace.d.ts +31 -0
- package/lib/firebase-namespace.js +417 -0
- package/lib/firestore/firestore-internal.js +105 -0
- package/lib/firestore/index.d.ts +50 -0
- package/lib/firestore/index.js +47 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +27 -0
- package/lib/installations/index.d.ts +81 -0
- package/lib/installations/index.js +18 -0
- package/lib/installations/installations-request-handler.js +117 -0
- package/lib/installations/installations.js +62 -0
- package/lib/instance-id/index.d.ts +83 -0
- package/lib/instance-id/index.js +18 -0
- package/lib/instance-id/instance-id.js +87 -0
- package/lib/machine-learning/index.d.ts +249 -0
- package/lib/machine-learning/index.js +18 -0
- package/lib/machine-learning/machine-learning-api-client.js +304 -0
- package/lib/machine-learning/machine-learning-utils.js +62 -0
- package/lib/machine-learning/machine-learning.js +364 -0
- package/lib/messaging/batch-request-internal.js +129 -0
- package/lib/messaging/index.d.ts +1174 -0
- package/lib/messaging/index.js +18 -0
- package/lib/messaging/messaging-api-request-internal.js +128 -0
- package/lib/messaging/messaging-errors-internal.js +106 -0
- package/lib/messaging/messaging-internal.js +484 -0
- package/lib/messaging/messaging.js +846 -0
- package/lib/project-management/android-app.js +176 -0
- package/lib/project-management/index.d.ts +363 -0
- package/lib/project-management/index.js +41 -0
- package/lib/project-management/ios-app.js +88 -0
- package/lib/project-management/project-management-api-request-internal.js +273 -0
- package/lib/project-management/project-management.js +254 -0
- package/lib/remote-config/index.d.ts +369 -0
- package/lib/remote-config/index.js +18 -0
- package/lib/remote-config/remote-config-api-client-internal.js +407 -0
- package/lib/remote-config/remote-config.js +304 -0
- package/lib/security-rules/index.d.ts +216 -0
- package/lib/security-rules/index.js +18 -0
- package/lib/security-rules/security-rules-api-client-internal.js +237 -0
- package/lib/security-rules/security-rules-internal.js +41 -0
- package/lib/security-rules/security-rules.js +310 -0
- package/lib/storage/index.d.ts +60 -0
- package/lib/storage/index.js +18 -0
- package/lib/storage/storage.js +123 -0
- package/lib/utils/api-request.js +845 -0
- package/lib/utils/crypto-signer.js +237 -0
- package/lib/utils/deep-copy.js +78 -0
- package/lib/utils/error.js +1063 -0
- package/lib/utils/index.js +217 -0
- package/lib/utils/jwt.js +355 -0
- package/lib/utils/validator.js +271 -0
- package/package.json +122 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2019 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.SecurityRulesApiClient = void 0;
|
|
20
|
+
var api_request_1 = require("../utils/api-request");
|
|
21
|
+
var error_1 = require("../utils/error");
|
|
22
|
+
var security_rules_internal_1 = require("./security-rules-internal");
|
|
23
|
+
var utils = require("../utils/index");
|
|
24
|
+
var validator = require("../utils/validator");
|
|
25
|
+
var RULES_V1_API = 'https://firebaserules.googleapis.com/v1';
|
|
26
|
+
var FIREBASE_VERSION_HEADER = {
|
|
27
|
+
'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion(),
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Class that facilitates sending requests to the Firebase security rules backend API.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
var SecurityRulesApiClient = /** @class */ (function () {
|
|
35
|
+
function SecurityRulesApiClient(app) {
|
|
36
|
+
this.app = app;
|
|
37
|
+
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
38
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'First argument passed to admin.securityRules() must be a valid Firebase app '
|
|
39
|
+
+ 'instance.');
|
|
40
|
+
}
|
|
41
|
+
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
42
|
+
}
|
|
43
|
+
SecurityRulesApiClient.prototype.getRuleset = function (name) {
|
|
44
|
+
var _this = this;
|
|
45
|
+
return Promise.resolve()
|
|
46
|
+
.then(function () {
|
|
47
|
+
return _this.getRulesetName(name);
|
|
48
|
+
})
|
|
49
|
+
.then(function (rulesetName) {
|
|
50
|
+
return _this.getResource(rulesetName);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
SecurityRulesApiClient.prototype.createRuleset = function (ruleset) {
|
|
54
|
+
var _this = this;
|
|
55
|
+
if (!validator.isNonNullObject(ruleset) ||
|
|
56
|
+
!validator.isNonNullObject(ruleset.source) ||
|
|
57
|
+
!validator.isNonEmptyArray(ruleset.source.files)) {
|
|
58
|
+
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Invalid rules content.');
|
|
59
|
+
return Promise.reject(err);
|
|
60
|
+
}
|
|
61
|
+
for (var _i = 0, _a = ruleset.source.files; _i < _a.length; _i++) {
|
|
62
|
+
var rf = _a[_i];
|
|
63
|
+
if (!validator.isNonNullObject(rf) ||
|
|
64
|
+
!validator.isNonEmptyString(rf.name) ||
|
|
65
|
+
!validator.isNonEmptyString(rf.content)) {
|
|
66
|
+
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', "Invalid rules file argument: " + JSON.stringify(rf));
|
|
67
|
+
return Promise.reject(err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return this.getUrl()
|
|
71
|
+
.then(function (url) {
|
|
72
|
+
var request = {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
url: url + "/rulesets",
|
|
75
|
+
data: ruleset,
|
|
76
|
+
};
|
|
77
|
+
return _this.sendRequest(request);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
SecurityRulesApiClient.prototype.deleteRuleset = function (name) {
|
|
81
|
+
var _this = this;
|
|
82
|
+
return this.getUrl()
|
|
83
|
+
.then(function (url) {
|
|
84
|
+
var rulesetName = _this.getRulesetName(name);
|
|
85
|
+
var request = {
|
|
86
|
+
method: 'DELETE',
|
|
87
|
+
url: url + "/" + rulesetName,
|
|
88
|
+
};
|
|
89
|
+
return _this.sendRequest(request);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
SecurityRulesApiClient.prototype.listRulesets = function (pageSize, pageToken) {
|
|
93
|
+
var _this = this;
|
|
94
|
+
if (pageSize === void 0) { pageSize = 100; }
|
|
95
|
+
if (!validator.isNumber(pageSize)) {
|
|
96
|
+
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Invalid page size.');
|
|
97
|
+
return Promise.reject(err);
|
|
98
|
+
}
|
|
99
|
+
if (pageSize < 1 || pageSize > 100) {
|
|
100
|
+
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Page size must be between 1 and 100.');
|
|
101
|
+
return Promise.reject(err);
|
|
102
|
+
}
|
|
103
|
+
if (typeof pageToken !== 'undefined' && !validator.isNonEmptyString(pageToken)) {
|
|
104
|
+
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Next page token must be a non-empty string.');
|
|
105
|
+
return Promise.reject(err);
|
|
106
|
+
}
|
|
107
|
+
var data = {
|
|
108
|
+
pageSize: pageSize,
|
|
109
|
+
pageToken: pageToken,
|
|
110
|
+
};
|
|
111
|
+
if (!pageToken) {
|
|
112
|
+
delete data.pageToken;
|
|
113
|
+
}
|
|
114
|
+
return this.getUrl()
|
|
115
|
+
.then(function (url) {
|
|
116
|
+
var request = {
|
|
117
|
+
method: 'GET',
|
|
118
|
+
url: url + "/rulesets",
|
|
119
|
+
data: data,
|
|
120
|
+
};
|
|
121
|
+
return _this.sendRequest(request);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
SecurityRulesApiClient.prototype.getRelease = function (name) {
|
|
125
|
+
return this.getResource("releases/" + name);
|
|
126
|
+
};
|
|
127
|
+
SecurityRulesApiClient.prototype.updateRelease = function (name, rulesetName) {
|
|
128
|
+
var _this = this;
|
|
129
|
+
return this.getUrl()
|
|
130
|
+
.then(function (url) {
|
|
131
|
+
return _this.getReleaseDescription(name, rulesetName)
|
|
132
|
+
.then(function (release) {
|
|
133
|
+
var request = {
|
|
134
|
+
method: 'PATCH',
|
|
135
|
+
url: url + "/releases/" + name,
|
|
136
|
+
data: { release: release },
|
|
137
|
+
};
|
|
138
|
+
return _this.sendRequest(request);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
SecurityRulesApiClient.prototype.getUrl = function () {
|
|
143
|
+
return this.getProjectIdPrefix()
|
|
144
|
+
.then(function (projectIdPrefix) {
|
|
145
|
+
return RULES_V1_API + "/" + projectIdPrefix;
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
SecurityRulesApiClient.prototype.getProjectIdPrefix = function () {
|
|
149
|
+
var _this = this;
|
|
150
|
+
if (this.projectIdPrefix) {
|
|
151
|
+
return Promise.resolve(this.projectIdPrefix);
|
|
152
|
+
}
|
|
153
|
+
return utils.findProjectId(this.app)
|
|
154
|
+
.then(function (projectId) {
|
|
155
|
+
if (!validator.isNonEmptyString(projectId)) {
|
|
156
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
|
157
|
+
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
|
158
|
+
+ 'environment variable.');
|
|
159
|
+
}
|
|
160
|
+
_this.projectIdPrefix = "projects/" + projectId;
|
|
161
|
+
return _this.projectIdPrefix;
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Gets the specified resource from the rules API. Resource names must be the short names without project
|
|
166
|
+
* ID prefix (e.g. `rulesets/ruleset-name`).
|
|
167
|
+
*
|
|
168
|
+
* @param {string} name Full qualified name of the resource to get.
|
|
169
|
+
* @returns {Promise<T>} A promise that fulfills with the resource.
|
|
170
|
+
*/
|
|
171
|
+
SecurityRulesApiClient.prototype.getResource = function (name) {
|
|
172
|
+
var _this = this;
|
|
173
|
+
return this.getUrl()
|
|
174
|
+
.then(function (url) {
|
|
175
|
+
var request = {
|
|
176
|
+
method: 'GET',
|
|
177
|
+
url: url + "/" + name,
|
|
178
|
+
};
|
|
179
|
+
return _this.sendRequest(request);
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
SecurityRulesApiClient.prototype.getReleaseDescription = function (name, rulesetName) {
|
|
183
|
+
var _this = this;
|
|
184
|
+
return this.getProjectIdPrefix()
|
|
185
|
+
.then(function (projectIdPrefix) {
|
|
186
|
+
return {
|
|
187
|
+
name: projectIdPrefix + "/releases/" + name,
|
|
188
|
+
rulesetName: projectIdPrefix + "/" + _this.getRulesetName(rulesetName),
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
SecurityRulesApiClient.prototype.getRulesetName = function (name) {
|
|
193
|
+
if (!validator.isNonEmptyString(name)) {
|
|
194
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Ruleset name must be a non-empty string.');
|
|
195
|
+
}
|
|
196
|
+
if (name.indexOf('/') !== -1) {
|
|
197
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Ruleset name must not contain any "/" characters.');
|
|
198
|
+
}
|
|
199
|
+
return "rulesets/" + name;
|
|
200
|
+
};
|
|
201
|
+
SecurityRulesApiClient.prototype.sendRequest = function (request) {
|
|
202
|
+
var _this = this;
|
|
203
|
+
request.headers = FIREBASE_VERSION_HEADER;
|
|
204
|
+
return this.httpClient.send(request)
|
|
205
|
+
.then(function (resp) {
|
|
206
|
+
return resp.data;
|
|
207
|
+
})
|
|
208
|
+
.catch(function (err) {
|
|
209
|
+
throw _this.toFirebaseError(err);
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
SecurityRulesApiClient.prototype.toFirebaseError = function (err) {
|
|
213
|
+
if (err instanceof error_1.PrefixedFirebaseError) {
|
|
214
|
+
return err;
|
|
215
|
+
}
|
|
216
|
+
var response = err.response;
|
|
217
|
+
if (!response.isJson()) {
|
|
218
|
+
return new security_rules_internal_1.FirebaseSecurityRulesError('unknown-error', "Unexpected response with status: " + response.status + " and body: " + response.text);
|
|
219
|
+
}
|
|
220
|
+
var error = response.data.error || {};
|
|
221
|
+
var code = 'unknown-error';
|
|
222
|
+
if (error.status && error.status in ERROR_CODE_MAPPING) {
|
|
223
|
+
code = ERROR_CODE_MAPPING[error.status];
|
|
224
|
+
}
|
|
225
|
+
var message = error.message || "Unknown server error: " + response.text;
|
|
226
|
+
return new security_rules_internal_1.FirebaseSecurityRulesError(code, message);
|
|
227
|
+
};
|
|
228
|
+
return SecurityRulesApiClient;
|
|
229
|
+
}());
|
|
230
|
+
exports.SecurityRulesApiClient = SecurityRulesApiClient;
|
|
231
|
+
var ERROR_CODE_MAPPING = {
|
|
232
|
+
INVALID_ARGUMENT: 'invalid-argument',
|
|
233
|
+
NOT_FOUND: 'not-found',
|
|
234
|
+
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
|
235
|
+
UNAUTHENTICATED: 'authentication-error',
|
|
236
|
+
UNKNOWN: 'unknown-error',
|
|
237
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2019 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
|
+
var __extends = (this && this.__extends) || (function () {
|
|
19
|
+
var extendStatics = function (d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
return function (d, b) {
|
|
26
|
+
extendStatics(d, b);
|
|
27
|
+
function __() { this.constructor = d; }
|
|
28
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
29
|
+
};
|
|
30
|
+
})();
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.FirebaseSecurityRulesError = void 0;
|
|
33
|
+
var error_1 = require("../utils/error");
|
|
34
|
+
var FirebaseSecurityRulesError = /** @class */ (function (_super) {
|
|
35
|
+
__extends(FirebaseSecurityRulesError, _super);
|
|
36
|
+
function FirebaseSecurityRulesError(code, message) {
|
|
37
|
+
return _super.call(this, 'security-rules', code, message) || this;
|
|
38
|
+
}
|
|
39
|
+
return FirebaseSecurityRulesError;
|
|
40
|
+
}(error_1.PrefixedFirebaseError));
|
|
41
|
+
exports.FirebaseSecurityRulesError = FirebaseSecurityRulesError;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2019 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.SecurityRules = exports.Ruleset = void 0;
|
|
20
|
+
var validator = require("../utils/validator");
|
|
21
|
+
var security_rules_api_client_internal_1 = require("./security-rules-api-client-internal");
|
|
22
|
+
var security_rules_internal_1 = require("./security-rules-internal");
|
|
23
|
+
var RulesetMetadataListImpl = /** @class */ (function () {
|
|
24
|
+
function RulesetMetadataListImpl(response) {
|
|
25
|
+
if (!validator.isNonNullObject(response) || !validator.isArray(response.rulesets)) {
|
|
26
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', "Invalid ListRulesets response: " + JSON.stringify(response));
|
|
27
|
+
}
|
|
28
|
+
this.rulesets = response.rulesets.map(function (rs) {
|
|
29
|
+
return {
|
|
30
|
+
name: stripProjectIdPrefix(rs.name),
|
|
31
|
+
createTime: new Date(rs.createTime).toUTCString(),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
if (response.nextPageToken) {
|
|
35
|
+
this.nextPageToken = response.nextPageToken;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return RulesetMetadataListImpl;
|
|
39
|
+
}());
|
|
40
|
+
/**
|
|
41
|
+
* Represents a set of Firebase security rules.
|
|
42
|
+
*/
|
|
43
|
+
var Ruleset = /** @class */ (function () {
|
|
44
|
+
function Ruleset(ruleset) {
|
|
45
|
+
if (!validator.isNonNullObject(ruleset) ||
|
|
46
|
+
!validator.isNonEmptyString(ruleset.name) ||
|
|
47
|
+
!validator.isNonEmptyString(ruleset.createTime) ||
|
|
48
|
+
!validator.isNonNullObject(ruleset.source)) {
|
|
49
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', "Invalid Ruleset response: " + JSON.stringify(ruleset));
|
|
50
|
+
}
|
|
51
|
+
this.name = stripProjectIdPrefix(ruleset.name);
|
|
52
|
+
this.createTime = new Date(ruleset.createTime).toUTCString();
|
|
53
|
+
this.source = ruleset.source.files || [];
|
|
54
|
+
}
|
|
55
|
+
return Ruleset;
|
|
56
|
+
}());
|
|
57
|
+
exports.Ruleset = Ruleset;
|
|
58
|
+
/**
|
|
59
|
+
* The Firebase `SecurityRules` service interface.
|
|
60
|
+
*
|
|
61
|
+
* Do not call this constructor directly. Instead, use
|
|
62
|
+
* [`admin.securityRules()`](securityRules#securityRules).
|
|
63
|
+
*/
|
|
64
|
+
var SecurityRules = /** @class */ (function () {
|
|
65
|
+
/**
|
|
66
|
+
* @param {object} app The app for this SecurityRules service.
|
|
67
|
+
* @constructor
|
|
68
|
+
*/
|
|
69
|
+
function SecurityRules(app) {
|
|
70
|
+
this.app = app;
|
|
71
|
+
this.client = new security_rules_api_client_internal_1.SecurityRulesApiClient(app);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets the Ruleset identified by the given name. The input name should be the short name string without
|
|
75
|
+
* the project ID prefix. For example, to retrieve the `projects/project-id/rulesets/my-ruleset`, pass the
|
|
76
|
+
* short name "my-ruleset". Rejects with a `not-found` error if the specified Ruleset cannot be found.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} name Name of the Ruleset to retrieve.
|
|
79
|
+
* @returns {Promise<Ruleset>} A promise that fulfills with the specified Ruleset.
|
|
80
|
+
*/
|
|
81
|
+
SecurityRules.prototype.getRuleset = function (name) {
|
|
82
|
+
return this.client.getRuleset(name)
|
|
83
|
+
.then(function (rulesetResponse) {
|
|
84
|
+
return new Ruleset(rulesetResponse);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Gets the Ruleset currently applied to Cloud Firestore. Rejects with a `not-found` error if no Ruleset is
|
|
89
|
+
* applied on Firestore.
|
|
90
|
+
*
|
|
91
|
+
* @returns {Promise<Ruleset>} A promise that fulfills with the Firestore Ruleset.
|
|
92
|
+
*/
|
|
93
|
+
SecurityRules.prototype.getFirestoreRuleset = function () {
|
|
94
|
+
return this.getRulesetForRelease(SecurityRules.CLOUD_FIRESTORE);
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new ruleset from the given source, and applies it to Cloud Firestore.
|
|
98
|
+
*
|
|
99
|
+
* @param {string|Buffer} source Rules source to apply.
|
|
100
|
+
* @returns {Promise<Ruleset>} A promise that fulfills when the ruleset is created and released.
|
|
101
|
+
*/
|
|
102
|
+
SecurityRules.prototype.releaseFirestoreRulesetFromSource = function (source) {
|
|
103
|
+
var _this = this;
|
|
104
|
+
return Promise.resolve()
|
|
105
|
+
.then(function () {
|
|
106
|
+
var rulesFile = _this.createRulesFileFromSource('firestore.rules', source);
|
|
107
|
+
return _this.createRuleset(rulesFile);
|
|
108
|
+
})
|
|
109
|
+
.then(function (ruleset) {
|
|
110
|
+
return _this.releaseFirestoreRuleset(ruleset)
|
|
111
|
+
.then(function () {
|
|
112
|
+
return ruleset;
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Makes the specified ruleset the currently applied ruleset for Cloud Firestore.
|
|
118
|
+
*
|
|
119
|
+
* @param {string|RulesetMetadata} ruleset Name of the ruleset to apply or a RulesetMetadata object containing
|
|
120
|
+
* the name.
|
|
121
|
+
* @returns {Promise<void>} A promise that fulfills when the ruleset is released.
|
|
122
|
+
*/
|
|
123
|
+
SecurityRules.prototype.releaseFirestoreRuleset = function (ruleset) {
|
|
124
|
+
return this.releaseRuleset(ruleset, SecurityRules.CLOUD_FIRESTORE);
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Gets the Ruleset currently applied to a Cloud Storage bucket. Rejects with a `not-found` error if no Ruleset is
|
|
128
|
+
* applied on the bucket.
|
|
129
|
+
*
|
|
130
|
+
* @param {string=} bucket Optional name of the Cloud Storage bucket to be retrieved. If not specified,
|
|
131
|
+
* retrieves the ruleset applied on the default bucket configured via `AppOptions`.
|
|
132
|
+
* @returns {Promise<Ruleset>} A promise that fulfills with the Cloud Storage Ruleset.
|
|
133
|
+
*/
|
|
134
|
+
SecurityRules.prototype.getStorageRuleset = function (bucket) {
|
|
135
|
+
var _this = this;
|
|
136
|
+
return Promise.resolve()
|
|
137
|
+
.then(function () {
|
|
138
|
+
return _this.getBucketName(bucket);
|
|
139
|
+
})
|
|
140
|
+
.then(function (bucketName) {
|
|
141
|
+
return _this.getRulesetForRelease(SecurityRules.FIREBASE_STORAGE + "/" + bucketName);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Creates a new ruleset from the given source, and applies it to a Cloud Storage bucket.
|
|
146
|
+
*
|
|
147
|
+
* @param {string|Buffer} source Rules source to apply.
|
|
148
|
+
* @param {string=} bucket Optional name of the Cloud Storage bucket to apply the rules on. If not specified,
|
|
149
|
+
* applies the ruleset on the default bucket configured via `AppOptions`.
|
|
150
|
+
* @returns {Promise<Ruleset>} A promise that fulfills when the ruleset is created and released.
|
|
151
|
+
*/
|
|
152
|
+
SecurityRules.prototype.releaseStorageRulesetFromSource = function (source, bucket) {
|
|
153
|
+
var _this = this;
|
|
154
|
+
return Promise.resolve()
|
|
155
|
+
.then(function () {
|
|
156
|
+
// Bucket name is not required until the last step. But since there's a createRuleset step
|
|
157
|
+
// before then, make sure to run this check and fail early if the bucket name is invalid.
|
|
158
|
+
_this.getBucketName(bucket);
|
|
159
|
+
var rulesFile = _this.createRulesFileFromSource('storage.rules', source);
|
|
160
|
+
return _this.createRuleset(rulesFile);
|
|
161
|
+
})
|
|
162
|
+
.then(function (ruleset) {
|
|
163
|
+
return _this.releaseStorageRuleset(ruleset, bucket)
|
|
164
|
+
.then(function () {
|
|
165
|
+
return ruleset;
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Makes the specified ruleset the currently applied ruleset for a Cloud Storage bucket.
|
|
171
|
+
*
|
|
172
|
+
* @param {string|RulesetMetadata} ruleset Name of the ruleset to apply or a RulesetMetadata object containing
|
|
173
|
+
* the name.
|
|
174
|
+
* @param {string=} bucket Optional name of the Cloud Storage bucket to apply the rules on. If not specified,
|
|
175
|
+
* applies the ruleset on the default bucket configured via `AppOptions`.
|
|
176
|
+
* @returns {Promise<void>} A promise that fulfills when the ruleset is released.
|
|
177
|
+
*/
|
|
178
|
+
SecurityRules.prototype.releaseStorageRuleset = function (ruleset, bucket) {
|
|
179
|
+
var _this = this;
|
|
180
|
+
return Promise.resolve()
|
|
181
|
+
.then(function () {
|
|
182
|
+
return _this.getBucketName(bucket);
|
|
183
|
+
})
|
|
184
|
+
.then(function (bucketName) {
|
|
185
|
+
return _this.releaseRuleset(ruleset, SecurityRules.FIREBASE_STORAGE + "/" + bucketName);
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Creates a {@link securityRules.RulesFile `RuleFile`} with the given name
|
|
190
|
+
* and source. Throws an error if any of the arguments are invalid. This is a local
|
|
191
|
+
* operation, and does not involve any network API calls.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```javascript
|
|
195
|
+
* const source = '// Some rules source';
|
|
196
|
+
* const rulesFile = admin.securityRules().createRulesFileFromSource(
|
|
197
|
+
* 'firestore.rules', source);
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @param name Name to assign to the rules file. This is usually a short file name that
|
|
201
|
+
* helps identify the file in a ruleset.
|
|
202
|
+
* @param source Contents of the rules file.
|
|
203
|
+
* @return A new rules file instance.
|
|
204
|
+
*/
|
|
205
|
+
SecurityRules.prototype.createRulesFileFromSource = function (name, source) {
|
|
206
|
+
if (!validator.isNonEmptyString(name)) {
|
|
207
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Name must be a non-empty string.');
|
|
208
|
+
}
|
|
209
|
+
var content;
|
|
210
|
+
if (validator.isNonEmptyString(source)) {
|
|
211
|
+
content = source;
|
|
212
|
+
}
|
|
213
|
+
else if (validator.isBuffer(source)) {
|
|
214
|
+
content = source.toString('utf-8');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Source must be a non-empty string or a Buffer.');
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
name: name,
|
|
221
|
+
content: content,
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Creates a new {@link securityRules.Ruleset `Ruleset`} from the given
|
|
226
|
+
* {@link securityRules.RulesFile `RuleFile`}.
|
|
227
|
+
*
|
|
228
|
+
* @param file Rules file to include in the new `Ruleset`.
|
|
229
|
+
* @returns A promise that fulfills with the newly created `Ruleset`.
|
|
230
|
+
*/
|
|
231
|
+
SecurityRules.prototype.createRuleset = function (file) {
|
|
232
|
+
var ruleset = {
|
|
233
|
+
source: {
|
|
234
|
+
files: [file],
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
return this.client.createRuleset(ruleset)
|
|
238
|
+
.then(function (rulesetResponse) {
|
|
239
|
+
return new Ruleset(rulesetResponse);
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Deletes the {@link securityRules.Ruleset `Ruleset`} identified by the given
|
|
244
|
+
* name. The input name should be the short name string without the project ID
|
|
245
|
+
* prefix. For example, to delete the `projects/project-id/rulesets/my-ruleset`,
|
|
246
|
+
* pass the short name "my-ruleset". Rejects with a `not-found` error if the
|
|
247
|
+
* specified `Ruleset` cannot be found.
|
|
248
|
+
*
|
|
249
|
+
* @param name Name of the `Ruleset` to delete.
|
|
250
|
+
* @return A promise that fulfills when the `Ruleset` is deleted.
|
|
251
|
+
*/
|
|
252
|
+
SecurityRules.prototype.deleteRuleset = function (name) {
|
|
253
|
+
return this.client.deleteRuleset(name);
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Retrieves a page of ruleset metadata.
|
|
257
|
+
*
|
|
258
|
+
* @param pageSize The page size, 100 if undefined. This is also the maximum allowed
|
|
259
|
+
* limit.
|
|
260
|
+
* @param nextPageToken The next page token. If not specified, returns rulesets
|
|
261
|
+
* starting without any offset.
|
|
262
|
+
* @return A promise that fulfills with a page of rulesets.
|
|
263
|
+
*/
|
|
264
|
+
SecurityRules.prototype.listRulesetMetadata = function (pageSize, nextPageToken) {
|
|
265
|
+
if (pageSize === void 0) { pageSize = 100; }
|
|
266
|
+
return this.client.listRulesets(pageSize, nextPageToken)
|
|
267
|
+
.then(function (response) {
|
|
268
|
+
return new RulesetMetadataListImpl(response);
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
SecurityRules.prototype.getRulesetForRelease = function (releaseName) {
|
|
272
|
+
var _this = this;
|
|
273
|
+
return this.client.getRelease(releaseName)
|
|
274
|
+
.then(function (release) {
|
|
275
|
+
var rulesetName = release.rulesetName;
|
|
276
|
+
if (!validator.isNonEmptyString(rulesetName)) {
|
|
277
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('not-found', "Ruleset name not found for " + releaseName + ".");
|
|
278
|
+
}
|
|
279
|
+
return _this.getRuleset(stripProjectIdPrefix(rulesetName));
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
SecurityRules.prototype.releaseRuleset = function (ruleset, releaseName) {
|
|
283
|
+
if (!validator.isNonEmptyString(ruleset) &&
|
|
284
|
+
(!validator.isNonNullObject(ruleset) || !validator.isNonEmptyString(ruleset.name))) {
|
|
285
|
+
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'ruleset must be a non-empty name or a RulesetMetadata object.');
|
|
286
|
+
return Promise.reject(err);
|
|
287
|
+
}
|
|
288
|
+
var rulesetName = validator.isString(ruleset) ? ruleset : ruleset.name;
|
|
289
|
+
return this.client.updateRelease(releaseName, rulesetName)
|
|
290
|
+
.then(function () {
|
|
291
|
+
return;
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
SecurityRules.prototype.getBucketName = function (bucket) {
|
|
295
|
+
var bucketName = (typeof bucket !== 'undefined') ? bucket : this.app.options.storageBucket;
|
|
296
|
+
if (!validator.isNonEmptyString(bucketName)) {
|
|
297
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Bucket name not specified or invalid. Specify a default bucket name via the ' +
|
|
298
|
+
'storageBucket option when initializing the app, or specify the bucket name ' +
|
|
299
|
+
'explicitly when calling the rules API.');
|
|
300
|
+
}
|
|
301
|
+
return bucketName;
|
|
302
|
+
};
|
|
303
|
+
SecurityRules.CLOUD_FIRESTORE = 'cloud.firestore';
|
|
304
|
+
SecurityRules.FIREBASE_STORAGE = 'firebase.storage';
|
|
305
|
+
return SecurityRules;
|
|
306
|
+
}());
|
|
307
|
+
exports.SecurityRules = SecurityRules;
|
|
308
|
+
function stripProjectIdPrefix(name) {
|
|
309
|
+
return name.split('/').pop();
|
|
310
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { Bucket } from '@google-cloud/storage';
|
|
18
|
+
import { app } from '../firebase-namespace-api';
|
|
19
|
+
/**
|
|
20
|
+
* Gets the {@link storage.Storage `Storage`} service for the
|
|
21
|
+
* default app or a given app.
|
|
22
|
+
*
|
|
23
|
+
* `admin.storage()` can be called with no arguments to access the default
|
|
24
|
+
* app's {@link storage.Storage `Storage`} service or as
|
|
25
|
+
* `admin.storage(app)` to access the
|
|
26
|
+
* {@link storage.Storage `Storage`} service associated with a
|
|
27
|
+
* specific app.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```javascript
|
|
31
|
+
* // Get the Storage service for the default app
|
|
32
|
+
* var defaultStorage = admin.storage();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```javascript
|
|
37
|
+
* // Get the Storage service for a given app
|
|
38
|
+
* var otherStorage = admin.storage(otherApp);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function storage(app?: app.App): storage.Storage;
|
|
42
|
+
export declare namespace storage {
|
|
43
|
+
/**
|
|
44
|
+
* The default `Storage` service if no
|
|
45
|
+
* app is provided or the `Storage` service associated with the provided
|
|
46
|
+
* app.
|
|
47
|
+
*/
|
|
48
|
+
interface Storage {
|
|
49
|
+
/**
|
|
50
|
+
* Optional app whose `Storage` service to
|
|
51
|
+
* return. If not provided, the default `Storage` service will be returned.
|
|
52
|
+
*/
|
|
53
|
+
app: app.App;
|
|
54
|
+
/**
|
|
55
|
+
* @returns A [Bucket](https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket)
|
|
56
|
+
* instance as defined in the `@google-cloud/storage` package.
|
|
57
|
+
*/
|
|
58
|
+
bucket(name?: string): Bucket;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 });
|