firebase-admin 10.2.0 → 11.0.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/README.md +1 -1
- 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 +7 -1
- package/lib/app/credential-internal.js +120 -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 +62 -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 +19 -1
- package/lib/functions/functions-api-client-internal.js +83 -103
- 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 +3 -1
- package/lib/security-rules/security-rules-api-client-internal.js +118 -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 +83 -92
- 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 +25 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2019 Google Inc.
|
|
@@ -15,27 +15,12 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
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
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
19
|
exports.FirebaseSecurityRulesError = void 0;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return _super.call(this, 'security-rules', code, message) || this;
|
|
20
|
+
const error_1 = require("../utils/error");
|
|
21
|
+
class FirebaseSecurityRulesError extends error_1.PrefixedFirebaseError {
|
|
22
|
+
constructor(code, message) {
|
|
23
|
+
super('security-rules', code, message);
|
|
38
24
|
}
|
|
39
|
-
|
|
40
|
-
}(error_1.PrefixedFirebaseError));
|
|
25
|
+
}
|
|
41
26
|
exports.FirebaseSecurityRulesError = FirebaseSecurityRulesError;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2019 Google Inc.
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.SecurityRules = exports.Ruleset = exports.RulesetMetadataList = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const validator = require("../utils/validator");
|
|
21
|
+
const security_rules_api_client_internal_1 = require("./security-rules-api-client-internal");
|
|
22
|
+
const security_rules_internal_1 = require("./security-rules-internal");
|
|
23
23
|
/**
|
|
24
24
|
* A page of ruleset metadata.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
class RulesetMetadataList {
|
|
27
27
|
/**
|
|
28
28
|
* @internal
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
constructor(response) {
|
|
31
31
|
if (!validator.isNonNullObject(response) || !validator.isArray(response.rulesets)) {
|
|
32
|
-
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument',
|
|
32
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', `Invalid ListRulesets response: ${JSON.stringify(response)}`);
|
|
33
33
|
}
|
|
34
|
-
this.rulesets = response.rulesets.map(
|
|
34
|
+
this.rulesets = response.rulesets.map((rs) => {
|
|
35
35
|
return {
|
|
36
36
|
name: stripProjectIdPrefix(rs.name),
|
|
37
37
|
createTime: new Date(rs.createTime).toUTCString(),
|
|
@@ -41,40 +41,38 @@ var RulesetMetadataList = /** @class */ (function () {
|
|
|
41
41
|
this.nextPageToken = response.nextPageToken;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
}());
|
|
44
|
+
}
|
|
46
45
|
exports.RulesetMetadataList = RulesetMetadataList;
|
|
47
46
|
/**
|
|
48
47
|
* A set of Firebase security rules.
|
|
49
48
|
*/
|
|
50
|
-
|
|
49
|
+
class Ruleset {
|
|
51
50
|
/**
|
|
52
51
|
* @internal
|
|
53
52
|
*/
|
|
54
|
-
|
|
53
|
+
constructor(ruleset) {
|
|
55
54
|
if (!validator.isNonNullObject(ruleset) ||
|
|
56
55
|
!validator.isNonEmptyString(ruleset.name) ||
|
|
57
56
|
!validator.isNonEmptyString(ruleset.createTime) ||
|
|
58
57
|
!validator.isNonNullObject(ruleset.source)) {
|
|
59
|
-
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument',
|
|
58
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', `Invalid Ruleset response: ${JSON.stringify(ruleset)}`);
|
|
60
59
|
}
|
|
61
60
|
this.name = stripProjectIdPrefix(ruleset.name);
|
|
62
61
|
this.createTime = new Date(ruleset.createTime).toUTCString();
|
|
63
62
|
this.source = ruleset.source.files || [];
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
}());
|
|
64
|
+
}
|
|
67
65
|
exports.Ruleset = Ruleset;
|
|
68
66
|
/**
|
|
69
67
|
* The Firebase `SecurityRules` service interface.
|
|
70
68
|
*/
|
|
71
|
-
|
|
69
|
+
class SecurityRules {
|
|
72
70
|
/**
|
|
73
71
|
* @param app - The app for this SecurityRules service.
|
|
74
72
|
* @constructor
|
|
75
73
|
* @internal
|
|
76
74
|
*/
|
|
77
|
-
|
|
75
|
+
constructor(app) {
|
|
78
76
|
this.app = app;
|
|
79
77
|
this.client = new security_rules_api_client_internal_1.SecurityRulesApiClient(app);
|
|
80
78
|
}
|
|
@@ -88,12 +86,12 @@ var SecurityRules = /** @class */ (function () {
|
|
|
88
86
|
* @param name - Name of the `Ruleset` to retrieve.
|
|
89
87
|
* @returns A promise that fulfills with the specified `Ruleset`.
|
|
90
88
|
*/
|
|
91
|
-
|
|
89
|
+
getRuleset(name) {
|
|
92
90
|
return this.client.getRuleset(name)
|
|
93
|
-
.then(
|
|
91
|
+
.then((rulesetResponse) => {
|
|
94
92
|
return new Ruleset(rulesetResponse);
|
|
95
93
|
});
|
|
96
|
-
}
|
|
94
|
+
}
|
|
97
95
|
/**
|
|
98
96
|
* Gets the {@link Ruleset} currently applied to
|
|
99
97
|
* Cloud Firestore. Rejects with a `not-found` error if no ruleset is applied
|
|
@@ -101,9 +99,9 @@ var SecurityRules = /** @class */ (function () {
|
|
|
101
99
|
*
|
|
102
100
|
* @returns A promise that fulfills with the Firestore ruleset.
|
|
103
101
|
*/
|
|
104
|
-
|
|
102
|
+
getFirestoreRuleset() {
|
|
105
103
|
return this.getRulesetForRelease(SecurityRules.CLOUD_FIRESTORE);
|
|
106
|
-
}
|
|
104
|
+
}
|
|
107
105
|
/**
|
|
108
106
|
* Creates a new {@link Ruleset} from the given
|
|
109
107
|
* source, and applies it to Cloud Firestore.
|
|
@@ -111,20 +109,19 @@ var SecurityRules = /** @class */ (function () {
|
|
|
111
109
|
* @param source - Rules source to apply.
|
|
112
110
|
* @returns A promise that fulfills when the ruleset is created and released.
|
|
113
111
|
*/
|
|
114
|
-
|
|
115
|
-
var _this = this;
|
|
112
|
+
releaseFirestoreRulesetFromSource(source) {
|
|
116
113
|
return Promise.resolve()
|
|
117
|
-
.then(
|
|
118
|
-
|
|
119
|
-
return
|
|
114
|
+
.then(() => {
|
|
115
|
+
const rulesFile = this.createRulesFileFromSource('firestore.rules', source);
|
|
116
|
+
return this.createRuleset(rulesFile);
|
|
120
117
|
})
|
|
121
|
-
.then(
|
|
122
|
-
return
|
|
123
|
-
.then(
|
|
118
|
+
.then((ruleset) => {
|
|
119
|
+
return this.releaseFirestoreRuleset(ruleset)
|
|
120
|
+
.then(() => {
|
|
124
121
|
return ruleset;
|
|
125
122
|
});
|
|
126
123
|
});
|
|
127
|
-
}
|
|
124
|
+
}
|
|
128
125
|
/**
|
|
129
126
|
* Applies the specified {@link Ruleset} ruleset
|
|
130
127
|
* to Cloud Firestore.
|
|
@@ -133,9 +130,9 @@ var SecurityRules = /** @class */ (function () {
|
|
|
133
130
|
* containing the name.
|
|
134
131
|
* @returns A promise that fulfills when the ruleset is released.
|
|
135
132
|
*/
|
|
136
|
-
|
|
133
|
+
releaseFirestoreRuleset(ruleset) {
|
|
137
134
|
return this.releaseRuleset(ruleset, SecurityRules.CLOUD_FIRESTORE);
|
|
138
|
-
}
|
|
135
|
+
}
|
|
139
136
|
/**
|
|
140
137
|
* Gets the {@link Ruleset} currently applied to a
|
|
141
138
|
* Cloud Storage bucket. Rejects with a `not-found` error if no ruleset is applied
|
|
@@ -146,16 +143,15 @@ var SecurityRules = /** @class */ (function () {
|
|
|
146
143
|
* `AppOptions`.
|
|
147
144
|
* @returns A promise that fulfills with the Cloud Storage ruleset.
|
|
148
145
|
*/
|
|
149
|
-
|
|
150
|
-
var _this = this;
|
|
146
|
+
getStorageRuleset(bucket) {
|
|
151
147
|
return Promise.resolve()
|
|
152
|
-
.then(
|
|
153
|
-
return
|
|
148
|
+
.then(() => {
|
|
149
|
+
return this.getBucketName(bucket);
|
|
154
150
|
})
|
|
155
|
-
.then(
|
|
156
|
-
return
|
|
151
|
+
.then((bucketName) => {
|
|
152
|
+
return this.getRulesetForRelease(`${SecurityRules.FIREBASE_STORAGE}/${bucketName}`);
|
|
157
153
|
});
|
|
158
|
-
}
|
|
154
|
+
}
|
|
159
155
|
/**
|
|
160
156
|
* Creates a new {@link Ruleset} from the given
|
|
161
157
|
* source, and applies it to a Cloud Storage bucket.
|
|
@@ -166,23 +162,22 @@ var SecurityRules = /** @class */ (function () {
|
|
|
166
162
|
* {@link firebase-admin.app#AppOptions}.
|
|
167
163
|
* @returns A promise that fulfills when the ruleset is created and released.
|
|
168
164
|
*/
|
|
169
|
-
|
|
170
|
-
var _this = this;
|
|
165
|
+
releaseStorageRulesetFromSource(source, bucket) {
|
|
171
166
|
return Promise.resolve()
|
|
172
|
-
.then(
|
|
167
|
+
.then(() => {
|
|
173
168
|
// Bucket name is not required until the last step. But since there's a createRuleset step
|
|
174
169
|
// before then, make sure to run this check and fail early if the bucket name is invalid.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return
|
|
170
|
+
this.getBucketName(bucket);
|
|
171
|
+
const rulesFile = this.createRulesFileFromSource('storage.rules', source);
|
|
172
|
+
return this.createRuleset(rulesFile);
|
|
178
173
|
})
|
|
179
|
-
.then(
|
|
180
|
-
return
|
|
181
|
-
.then(
|
|
174
|
+
.then((ruleset) => {
|
|
175
|
+
return this.releaseStorageRuleset(ruleset, bucket)
|
|
176
|
+
.then(() => {
|
|
182
177
|
return ruleset;
|
|
183
178
|
});
|
|
184
179
|
});
|
|
185
|
-
}
|
|
180
|
+
}
|
|
186
181
|
/**
|
|
187
182
|
* Applies the specified {@link Ruleset} ruleset
|
|
188
183
|
* to a Cloud Storage bucket.
|
|
@@ -194,16 +189,15 @@ var SecurityRules = /** @class */ (function () {
|
|
|
194
189
|
* {@link firebase-admin.app#AppOptions}.
|
|
195
190
|
* @returns A promise that fulfills when the ruleset is released.
|
|
196
191
|
*/
|
|
197
|
-
|
|
198
|
-
var _this = this;
|
|
192
|
+
releaseStorageRuleset(ruleset, bucket) {
|
|
199
193
|
return Promise.resolve()
|
|
200
|
-
.then(
|
|
201
|
-
return
|
|
194
|
+
.then(() => {
|
|
195
|
+
return this.getBucketName(bucket);
|
|
202
196
|
})
|
|
203
|
-
.then(
|
|
204
|
-
return
|
|
197
|
+
.then((bucketName) => {
|
|
198
|
+
return this.releaseRuleset(ruleset, `${SecurityRules.FIREBASE_STORAGE}/${bucketName}`);
|
|
205
199
|
});
|
|
206
|
-
}
|
|
200
|
+
}
|
|
207
201
|
/**
|
|
208
202
|
* Creates a {@link RulesFile} with the given name
|
|
209
203
|
* and source. Throws an error if any of the arguments are invalid. This is a local
|
|
@@ -221,11 +215,11 @@ var SecurityRules = /** @class */ (function () {
|
|
|
221
215
|
* @param source - Contents of the rules file.
|
|
222
216
|
* @returns A new rules file instance.
|
|
223
217
|
*/
|
|
224
|
-
|
|
218
|
+
createRulesFileFromSource(name, source) {
|
|
225
219
|
if (!validator.isNonEmptyString(name)) {
|
|
226
220
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Name must be a non-empty string.');
|
|
227
221
|
}
|
|
228
|
-
|
|
222
|
+
let content;
|
|
229
223
|
if (validator.isNonEmptyString(source)) {
|
|
230
224
|
content = source;
|
|
231
225
|
}
|
|
@@ -236,27 +230,27 @@ var SecurityRules = /** @class */ (function () {
|
|
|
236
230
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Source must be a non-empty string or a Buffer.');
|
|
237
231
|
}
|
|
238
232
|
return {
|
|
239
|
-
name
|
|
240
|
-
content
|
|
233
|
+
name,
|
|
234
|
+
content,
|
|
241
235
|
};
|
|
242
|
-
}
|
|
236
|
+
}
|
|
243
237
|
/**
|
|
244
238
|
* Creates a new {@link Ruleset} from the given {@link RulesFile}.
|
|
245
239
|
*
|
|
246
240
|
* @param file - Rules file to include in the new `Ruleset`.
|
|
247
241
|
* @returns A promise that fulfills with the newly created `Ruleset`.
|
|
248
242
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
243
|
+
createRuleset(file) {
|
|
244
|
+
const ruleset = {
|
|
251
245
|
source: {
|
|
252
246
|
files: [file],
|
|
253
247
|
},
|
|
254
248
|
};
|
|
255
249
|
return this.client.createRuleset(ruleset)
|
|
256
|
-
.then(
|
|
250
|
+
.then((rulesetResponse) => {
|
|
257
251
|
return new Ruleset(rulesetResponse);
|
|
258
252
|
});
|
|
259
|
-
}
|
|
253
|
+
}
|
|
260
254
|
/**
|
|
261
255
|
* Deletes the {@link Ruleset} identified by the given
|
|
262
256
|
* name. The input name should be the short name string without the project ID
|
|
@@ -267,9 +261,9 @@ var SecurityRules = /** @class */ (function () {
|
|
|
267
261
|
* @param name - Name of the `Ruleset` to delete.
|
|
268
262
|
* @returns A promise that fulfills when the `Ruleset` is deleted.
|
|
269
263
|
*/
|
|
270
|
-
|
|
264
|
+
deleteRuleset(name) {
|
|
271
265
|
return this.client.deleteRuleset(name);
|
|
272
|
-
}
|
|
266
|
+
}
|
|
273
267
|
/**
|
|
274
268
|
* Retrieves a page of ruleset metadata.
|
|
275
269
|
*
|
|
@@ -279,50 +273,47 @@ var SecurityRules = /** @class */ (function () {
|
|
|
279
273
|
* starting without any offset.
|
|
280
274
|
* @returns A promise that fulfills with a page of rulesets.
|
|
281
275
|
*/
|
|
282
|
-
|
|
283
|
-
if (pageSize === void 0) { pageSize = 100; }
|
|
276
|
+
listRulesetMetadata(pageSize = 100, nextPageToken) {
|
|
284
277
|
return this.client.listRulesets(pageSize, nextPageToken)
|
|
285
|
-
.then(
|
|
278
|
+
.then((response) => {
|
|
286
279
|
return new RulesetMetadataList(response);
|
|
287
280
|
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
var _this = this;
|
|
281
|
+
}
|
|
282
|
+
getRulesetForRelease(releaseName) {
|
|
291
283
|
return this.client.getRelease(releaseName)
|
|
292
|
-
.then(
|
|
293
|
-
|
|
284
|
+
.then((release) => {
|
|
285
|
+
const rulesetName = release.rulesetName;
|
|
294
286
|
if (!validator.isNonEmptyString(rulesetName)) {
|
|
295
|
-
throw new security_rules_internal_1.FirebaseSecurityRulesError('not-found',
|
|
287
|
+
throw new security_rules_internal_1.FirebaseSecurityRulesError('not-found', `Ruleset name not found for ${releaseName}.`);
|
|
296
288
|
}
|
|
297
|
-
return
|
|
289
|
+
return this.getRuleset(stripProjectIdPrefix(rulesetName));
|
|
298
290
|
});
|
|
299
|
-
}
|
|
300
|
-
|
|
291
|
+
}
|
|
292
|
+
releaseRuleset(ruleset, releaseName) {
|
|
301
293
|
if (!validator.isNonEmptyString(ruleset) &&
|
|
302
294
|
(!validator.isNonNullObject(ruleset) || !validator.isNonEmptyString(ruleset.name))) {
|
|
303
|
-
|
|
295
|
+
const err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'ruleset must be a non-empty name or a RulesetMetadata object.');
|
|
304
296
|
return Promise.reject(err);
|
|
305
297
|
}
|
|
306
|
-
|
|
307
|
-
return this.client.
|
|
308
|
-
.then(
|
|
298
|
+
const rulesetName = validator.isString(ruleset) ? ruleset : ruleset.name;
|
|
299
|
+
return this.client.updateOrCreateRelease(releaseName, rulesetName)
|
|
300
|
+
.then(() => {
|
|
309
301
|
return;
|
|
310
302
|
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
303
|
+
}
|
|
304
|
+
getBucketName(bucket) {
|
|
305
|
+
const bucketName = (typeof bucket !== 'undefined') ? bucket : this.app.options.storageBucket;
|
|
314
306
|
if (!validator.isNonEmptyString(bucketName)) {
|
|
315
307
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Bucket name not specified or invalid. Specify a default bucket name via the ' +
|
|
316
308
|
'storageBucket option when initializing the app, or specify the bucket name ' +
|
|
317
309
|
'explicitly when calling the rules API.');
|
|
318
310
|
}
|
|
319
311
|
return bucketName;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
SecurityRules.FIREBASE_STORAGE = 'firebase.storage';
|
|
323
|
-
return SecurityRules;
|
|
324
|
-
}());
|
|
312
|
+
}
|
|
313
|
+
}
|
|
325
314
|
exports.SecurityRules = SecurityRules;
|
|
315
|
+
SecurityRules.CLOUD_FIRESTORE = 'cloud.firestore';
|
|
316
|
+
SecurityRules.FIREBASE_STORAGE = 'firebase.storage';
|
|
326
317
|
function stripProjectIdPrefix(name) {
|
|
327
318
|
return name.split('/').pop();
|
|
328
319
|
}
|
package/lib/storage/index.d.ts
CHANGED
package/lib/storage/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getStorage = void 0;
|
|
19
|
+
exports.getStorage = exports.Storage = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Cloud Storage for Firebase.
|
|
22
22
|
*
|
|
23
23
|
* @packageDocumentation
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const app_1 = require("../app");
|
|
26
|
+
const storage_1 = require("./storage");
|
|
27
27
|
var storage_2 = require("./storage");
|
|
28
28
|
Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return storage_2.Storage; } });
|
|
29
29
|
/**
|
|
@@ -47,9 +47,9 @@ Object.defineProperty(exports, "Storage", { enumerable: true, get: function () {
|
|
|
47
47
|
*/
|
|
48
48
|
function getStorage(app) {
|
|
49
49
|
if (typeof app === 'undefined') {
|
|
50
|
-
app = app_1.getApp();
|
|
50
|
+
app = (0, app_1.getApp)();
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
return firebaseApp.getOrInitService('storage',
|
|
52
|
+
const firebaseApp = app;
|
|
53
|
+
return firebaseApp.getOrInitService('storage', (app) => new storage_1.Storage(app));
|
|
54
54
|
}
|
|
55
55
|
exports.getStorage = getStorage;
|
package/lib/storage/storage.d.ts
CHANGED
package/lib/storage/storage.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.Storage = void 0;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const error_1 = require("../utils/error");
|
|
22
|
+
const credential_internal_1 = require("../app/credential-internal");
|
|
23
|
+
const utils = require("../utils/index");
|
|
24
|
+
const validator = require("../utils/validator");
|
|
25
25
|
/**
|
|
26
26
|
* The default `Storage` service if no
|
|
27
27
|
* app is provided or the `Storage` service associated with the provided
|
|
28
28
|
* app.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
class Storage {
|
|
31
31
|
/**
|
|
32
32
|
* @param app - The app for this Storage service.
|
|
33
33
|
* @constructor
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
constructor(app) {
|
|
37
37
|
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
38
38
|
throw new error_1.FirebaseError({
|
|
39
39
|
code: 'storage/invalid-argument',
|
|
@@ -41,16 +41,16 @@ var Storage = /** @class */ (function () {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
if (!process.env.STORAGE_EMULATOR_HOST && process.env.FIREBASE_STORAGE_EMULATOR_HOST) {
|
|
44
|
-
|
|
44
|
+
const firebaseStorageEmulatorHost = process.env.FIREBASE_STORAGE_EMULATOR_HOST;
|
|
45
45
|
if (firebaseStorageEmulatorHost.match(/https?:\/\//)) {
|
|
46
46
|
throw new error_1.FirebaseError({
|
|
47
47
|
code: 'storage/invalid-emulator-host',
|
|
48
48
|
message: 'FIREBASE_STORAGE_EMULATOR_HOST should not contain a protocol (http or https).',
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
process.env.STORAGE_EMULATOR_HOST =
|
|
51
|
+
process.env.STORAGE_EMULATOR_HOST = `http://${process.env.FIREBASE_STORAGE_EMULATOR_HOST}`;
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
let storage;
|
|
54
54
|
try {
|
|
55
55
|
storage = require('@google-cloud/storage').Storage;
|
|
56
56
|
}
|
|
@@ -59,11 +59,11 @@ var Storage = /** @class */ (function () {
|
|
|
59
59
|
code: 'storage/missing-dependencies',
|
|
60
60
|
message: 'Failed to import the Cloud Storage client library for Node.js. '
|
|
61
61
|
+ 'Make sure to install the "@google-cloud/storage" npm package. '
|
|
62
|
-
+
|
|
62
|
+
+ `Original error: ${err}`,
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const projectId = utils.getExplicitProjectId(app);
|
|
66
|
+
const credential = app.options.credential;
|
|
67
67
|
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
|
|
68
68
|
this.storageClient = new storage({
|
|
69
69
|
// When the SDK is initialized with ServiceAccountCredentials an explicit projectId is
|
|
@@ -75,7 +75,7 @@ var Storage = /** @class */ (function () {
|
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
else if (credential_internal_1.isApplicationDefault(app.options.credential)) {
|
|
78
|
+
else if ((0, credential_internal_1.isApplicationDefault)(app.options.credential)) {
|
|
79
79
|
// Try to use the Google application default credentials.
|
|
80
80
|
this.storageClient = new storage();
|
|
81
81
|
}
|
|
@@ -97,8 +97,8 @@ var Storage = /** @class */ (function () {
|
|
|
97
97
|
* @returns A {@link https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket | Bucket}
|
|
98
98
|
* instance as defined in the `@google-cloud/storage` package.
|
|
99
99
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
bucket(name) {
|
|
101
|
+
const bucketName = (typeof name !== 'undefined')
|
|
102
102
|
? name : this.appInternal.options.storageBucket;
|
|
103
103
|
if (validator.isNonEmptyString(bucketName)) {
|
|
104
104
|
return this.storageClient.bucket(bucketName);
|
|
@@ -109,18 +109,13 @@ var Storage = /** @class */ (function () {
|
|
|
109
109
|
'storageBucket option when initializing the app, or specify the bucket name ' +
|
|
110
110
|
'explicitly when calling the getBucket() method.',
|
|
111
111
|
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
enumerable: false,
|
|
122
|
-
configurable: true
|
|
123
|
-
});
|
|
124
|
-
return Storage;
|
|
125
|
-
}());
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Optional app whose `Storage` service to
|
|
115
|
+
* return. If not provided, the default `Storage` service will be returned.
|
|
116
|
+
*/
|
|
117
|
+
get app() {
|
|
118
|
+
return this.appInternal;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
126
121
|
exports.Storage = Storage;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
/*!
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2017 Google Inc.
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
/// <reference types="node" />
|
|
19
|
+
/// <reference types="node" />
|
|
20
|
+
/// <reference types="node" />
|
|
19
21
|
import { FirebaseApp } from '../app/firebase-app';
|
|
20
22
|
import http = require('http');
|
|
21
23
|
import { EventEmitter } from 'events';
|