firebase-admin 10.1.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 -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 +3 -1
- package/lib/app/credential-internal.js +103 -95
- 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 +355 -382
- 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 +26 -1
- package/lib/auth/base-auth.js +162 -142
- 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/esm/eventarc/index.js +5 -0
- package/lib/esm/functions/index.js +5 -0
- package/lib/eventarc/cloudevent.d.ts +84 -0
- package/lib/eventarc/cloudevent.js +19 -0
- package/lib/eventarc/eventarc-client-internal.d.ts +18 -0
- package/lib/eventarc/eventarc-client-internal.js +139 -0
- package/lib/eventarc/eventarc-utils.d.ts +31 -0
- package/lib/eventarc/eventarc-utils.js +125 -0
- package/lib/eventarc/eventarc.d.ts +107 -0
- package/lib/eventarc/eventarc.js +125 -0
- package/lib/eventarc/index.d.ts +53 -0
- package/lib/eventarc/index.js +64 -0
- 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 +32 -0
- package/lib/functions/functions-api-client-internal.js +257 -0
- package/lib/functions/functions-api.d.ts +67 -0
- package/lib/functions/functions-api.js +19 -0
- package/lib/functions/functions.d.ts +63 -0
- package/lib/functions/functions.js +97 -0
- package/lib/functions/index.d.ts +53 -0
- package/lib/functions/index.js +64 -0
- 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 +5 -1
- package/lib/utils/error.js +613 -677
- package/lib/utils/index.d.ts +43 -1
- package/lib/utils/index.js +99 -34
- 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 +43 -11
|
@@ -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,18 +17,18 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.RemoteConfig = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const validator = require("../utils/validator");
|
|
21
|
+
const remote_config_api_client_internal_1 = require("./remote-config-api-client-internal");
|
|
22
22
|
/**
|
|
23
23
|
* The Firebase `RemoteConfig` service interface.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
class RemoteConfig {
|
|
26
26
|
/**
|
|
27
27
|
* @param app - The app for this RemoteConfig service.
|
|
28
28
|
* @constructor
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
constructor(app) {
|
|
32
32
|
this.app = app;
|
|
33
33
|
this.client = new remote_config_api_client_internal_1.RemoteConfigApiClient(app);
|
|
34
34
|
}
|
|
@@ -37,12 +37,12 @@ var RemoteConfig = /** @class */ (function () {
|
|
|
37
37
|
*
|
|
38
38
|
* @returns A promise that fulfills with a `RemoteConfigTemplate`.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
getTemplate() {
|
|
41
41
|
return this.client.getTemplate()
|
|
42
|
-
.then(
|
|
42
|
+
.then((templateResponse) => {
|
|
43
43
|
return new RemoteConfigTemplateImpl(templateResponse);
|
|
44
44
|
});
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
46
|
/**
|
|
47
47
|
* Gets the requested version of the {@link RemoteConfigTemplate} of the project.
|
|
48
48
|
*
|
|
@@ -50,24 +50,24 @@ var RemoteConfig = /** @class */ (function () {
|
|
|
50
50
|
*
|
|
51
51
|
* @returns A promise that fulfills with a `RemoteConfigTemplate`.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
getTemplateAtVersion(versionNumber) {
|
|
54
54
|
return this.client.getTemplateAtVersion(versionNumber)
|
|
55
|
-
.then(
|
|
55
|
+
.then((templateResponse) => {
|
|
56
56
|
return new RemoteConfigTemplateImpl(templateResponse);
|
|
57
57
|
});
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
59
|
/**
|
|
60
60
|
* Validates a {@link RemoteConfigTemplate}.
|
|
61
61
|
*
|
|
62
62
|
* @param template - The Remote Config template to be validated.
|
|
63
63
|
* @returns A promise that fulfills with the validated `RemoteConfigTemplate`.
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
validateTemplate(template) {
|
|
66
66
|
return this.client.validateTemplate(template)
|
|
67
|
-
.then(
|
|
67
|
+
.then((templateResponse) => {
|
|
68
68
|
return new RemoteConfigTemplateImpl(templateResponse);
|
|
69
69
|
});
|
|
70
|
-
}
|
|
70
|
+
}
|
|
71
71
|
/**
|
|
72
72
|
* Publishes a Remote Config template.
|
|
73
73
|
*
|
|
@@ -82,12 +82,12 @@ var RemoteConfig = /** @class */ (function () {
|
|
|
82
82
|
*
|
|
83
83
|
* @returns A Promise that fulfills with the published `RemoteConfigTemplate`.
|
|
84
84
|
*/
|
|
85
|
-
|
|
85
|
+
publishTemplate(template, options) {
|
|
86
86
|
return this.client.publishTemplate(template, options)
|
|
87
|
-
.then(
|
|
87
|
+
.then((templateResponse) => {
|
|
88
88
|
return new RemoteConfigTemplateImpl(templateResponse);
|
|
89
89
|
});
|
|
90
|
-
}
|
|
90
|
+
}
|
|
91
91
|
/**
|
|
92
92
|
* Rolls back a project's published Remote Config template to the specified version.
|
|
93
93
|
* A rollback is equivalent to getting a previously published Remote Config
|
|
@@ -100,12 +100,12 @@ var RemoteConfig = /** @class */ (function () {
|
|
|
100
100
|
* template that is being fetched by clients) are also deleted if they are more than 90 days old.
|
|
101
101
|
* @returns A promise that fulfills with the published `RemoteConfigTemplate`.
|
|
102
102
|
*/
|
|
103
|
-
|
|
103
|
+
rollback(versionNumber) {
|
|
104
104
|
return this.client.rollback(versionNumber)
|
|
105
|
-
.then(
|
|
105
|
+
.then((templateResponse) => {
|
|
106
106
|
return new RemoteConfigTemplateImpl(templateResponse);
|
|
107
107
|
});
|
|
108
|
-
}
|
|
108
|
+
}
|
|
109
109
|
/**
|
|
110
110
|
* Gets a list of Remote Config template versions that have been published, sorted in reverse
|
|
111
111
|
* chronological order. Only the last 300 versions are stored.
|
|
@@ -115,16 +115,15 @@ var RemoteConfig = /** @class */ (function () {
|
|
|
115
115
|
* @param options - Optional options object for getting a list of versions.
|
|
116
116
|
* @returns A promise that fulfills with a `ListVersionsResult`.
|
|
117
117
|
*/
|
|
118
|
-
|
|
118
|
+
listVersions(options) {
|
|
119
119
|
return this.client.listVersions(options)
|
|
120
|
-
.then(
|
|
121
|
-
var _a, _b;
|
|
120
|
+
.then((listVersionsResponse) => {
|
|
122
121
|
return {
|
|
123
|
-
versions:
|
|
122
|
+
versions: listVersionsResponse.versions?.map(version => new VersionImpl(version)) ?? [],
|
|
124
123
|
nextPageToken: listVersionsResponse.nextPageToken,
|
|
125
124
|
};
|
|
126
125
|
});
|
|
127
|
-
}
|
|
126
|
+
}
|
|
128
127
|
/**
|
|
129
128
|
* Creates and returns a new Remote Config template from a JSON string.
|
|
130
129
|
*
|
|
@@ -132,30 +131,29 @@ var RemoteConfig = /** @class */ (function () {
|
|
|
132
131
|
*
|
|
133
132
|
* @returns A new template instance.
|
|
134
133
|
*/
|
|
135
|
-
|
|
134
|
+
createTemplateFromJSON(json) {
|
|
136
135
|
if (!validator.isNonEmptyString(json)) {
|
|
137
136
|
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'JSON string must be a valid non-empty string');
|
|
138
137
|
}
|
|
139
|
-
|
|
138
|
+
let template;
|
|
140
139
|
try {
|
|
141
140
|
template = JSON.parse(json);
|
|
142
141
|
}
|
|
143
142
|
catch (e) {
|
|
144
|
-
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument',
|
|
143
|
+
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', `Failed to parse the JSON string: ${json}. ` + e);
|
|
145
144
|
}
|
|
146
145
|
return new RemoteConfigTemplateImpl(template);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
}());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
150
148
|
exports.RemoteConfig = RemoteConfig;
|
|
151
149
|
/**
|
|
152
150
|
* Remote Config template internal implementation.
|
|
153
151
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
class RemoteConfigTemplateImpl {
|
|
153
|
+
constructor(config) {
|
|
156
154
|
if (!validator.isNonNullObject(config) ||
|
|
157
155
|
!validator.isNonEmptyString(config.etag)) {
|
|
158
|
-
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument',
|
|
156
|
+
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', `Invalid Remote Config template: ${JSON.stringify(config)}`);
|
|
159
157
|
}
|
|
160
158
|
this.etagInternal = config.etag;
|
|
161
159
|
if (typeof config.parameters !== 'undefined') {
|
|
@@ -189,24 +187,20 @@ var RemoteConfigTemplateImpl = /** @class */ (function () {
|
|
|
189
187
|
this.version = new VersionImpl(config.version);
|
|
190
188
|
}
|
|
191
189
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
},
|
|
201
|
-
enumerable: false,
|
|
202
|
-
configurable: true
|
|
203
|
-
});
|
|
190
|
+
/**
|
|
191
|
+
* Gets the ETag of the template.
|
|
192
|
+
*
|
|
193
|
+
* @returns The ETag of the Remote Config template.
|
|
194
|
+
*/
|
|
195
|
+
get etag() {
|
|
196
|
+
return this.etagInternal;
|
|
197
|
+
}
|
|
204
198
|
/**
|
|
205
199
|
* Returns a JSON-serializable representation of this object.
|
|
206
200
|
*
|
|
207
201
|
* @returns A JSON-serializable representation of this object.
|
|
208
202
|
*/
|
|
209
|
-
|
|
203
|
+
toJSON() {
|
|
210
204
|
return {
|
|
211
205
|
conditions: this.conditions,
|
|
212
206
|
parameters: this.parameters,
|
|
@@ -214,16 +208,15 @@ var RemoteConfigTemplateImpl = /** @class */ (function () {
|
|
|
214
208
|
etag: this.etag,
|
|
215
209
|
version: this.version,
|
|
216
210
|
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
}());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
220
213
|
/**
|
|
221
214
|
* Remote Config Version internal implementation.
|
|
222
215
|
*/
|
|
223
|
-
|
|
224
|
-
|
|
216
|
+
class VersionImpl {
|
|
217
|
+
constructor(version) {
|
|
225
218
|
if (!validator.isNonNullObject(version)) {
|
|
226
|
-
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument',
|
|
219
|
+
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', `Invalid Remote Config version instance: ${JSON.stringify(version)}`);
|
|
227
220
|
}
|
|
228
221
|
if (typeof version.versionNumber !== 'undefined') {
|
|
229
222
|
if (!validator.isNonEmptyString(version.versionNumber) &&
|
|
@@ -284,7 +277,7 @@ var VersionImpl = /** @class */ (function () {
|
|
|
284
277
|
/**
|
|
285
278
|
* @returns A JSON-serializable representation of this object.
|
|
286
279
|
*/
|
|
287
|
-
|
|
280
|
+
toJSON() {
|
|
288
281
|
return {
|
|
289
282
|
versionNumber: this.versionNumber,
|
|
290
283
|
updateOrigin: this.updateOrigin,
|
|
@@ -295,11 +288,10 @@ var VersionImpl = /** @class */ (function () {
|
|
|
295
288
|
isLegacy: this.isLegacy,
|
|
296
289
|
updateTime: this.updateTime,
|
|
297
290
|
};
|
|
298
|
-
}
|
|
299
|
-
|
|
291
|
+
}
|
|
292
|
+
isValidTimestamp(timestamp) {
|
|
300
293
|
// This validation fails for timestamps earlier than January 1, 1970 and considers strings
|
|
301
294
|
// such as "1.2" as valid timestamps.
|
|
302
295
|
return validator.isNonEmptyString(timestamp) && (new Date(timestamp)).getTime() > 0;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
}());
|
|
296
|
+
}
|
|
297
|
+
}
|
|
@@ -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.
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getSecurityRules = void 0;
|
|
19
|
+
exports.getSecurityRules = exports.SecurityRules = exports.RulesetMetadataList = exports.Ruleset = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Security Rules for Cloud Firestore and Cloud Storage.
|
|
22
22
|
*
|
|
23
23
|
* @packageDocumentation
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const app_1 = require("../app");
|
|
26
|
+
const security_rules_1 = require("./security-rules");
|
|
27
27
|
var security_rules_2 = require("./security-rules");
|
|
28
28
|
Object.defineProperty(exports, "Ruleset", { enumerable: true, get: function () { return security_rules_2.Ruleset; } });
|
|
29
29
|
Object.defineProperty(exports, "RulesetMetadataList", { enumerable: true, get: function () { return security_rules_2.RulesetMetadataList; } });
|
|
@@ -55,9 +55,9 @@ Object.defineProperty(exports, "SecurityRules", { enumerable: true, get: functio
|
|
|
55
55
|
*/
|
|
56
56
|
function getSecurityRules(app) {
|
|
57
57
|
if (typeof app === 'undefined') {
|
|
58
|
-
app = app_1.getApp();
|
|
58
|
+
app = (0, app_1.getApp)();
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
return firebaseApp.getOrInitService('securityRules',
|
|
60
|
+
const firebaseApp = app;
|
|
61
|
+
return firebaseApp.getOrInitService('securityRules', (app) => new security_rules_1.SecurityRules(app));
|
|
62
62
|
}
|
|
63
63
|
exports.getSecurityRules = getSecurityRules;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2019 Google Inc.
|
|
@@ -17,22 +17,22 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.SecurityRulesApiClient = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'X-Firebase-Client':
|
|
20
|
+
const api_request_1 = require("../utils/api-request");
|
|
21
|
+
const error_1 = require("../utils/error");
|
|
22
|
+
const security_rules_internal_1 = require("./security-rules-internal");
|
|
23
|
+
const utils = require("../utils/index");
|
|
24
|
+
const validator = require("../utils/validator");
|
|
25
|
+
const RULES_V1_API = 'https://firebaserules.googleapis.com/v1';
|
|
26
|
+
const FIREBASE_VERSION_HEADER = {
|
|
27
|
+
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Class that facilitates sending requests to the Firebase security rules backend API.
|
|
31
31
|
*
|
|
32
32
|
* @private
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
class SecurityRulesApiClient {
|
|
35
|
+
constructor(app) {
|
|
36
36
|
this.app = app;
|
|
37
37
|
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
38
38
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'First argument passed to admin.securityRules() must be a valid Firebase app '
|
|
@@ -40,127 +40,119 @@ var SecurityRulesApiClient = /** @class */ (function () {
|
|
|
40
40
|
}
|
|
41
41
|
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
var _this = this;
|
|
43
|
+
getRuleset(name) {
|
|
45
44
|
return Promise.resolve()
|
|
46
|
-
.then(
|
|
47
|
-
return
|
|
45
|
+
.then(() => {
|
|
46
|
+
return this.getRulesetName(name);
|
|
48
47
|
})
|
|
49
|
-
.then(
|
|
50
|
-
return
|
|
48
|
+
.then((rulesetName) => {
|
|
49
|
+
return this.getResource(rulesetName);
|
|
51
50
|
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var _this = this;
|
|
51
|
+
}
|
|
52
|
+
createRuleset(ruleset) {
|
|
55
53
|
if (!validator.isNonNullObject(ruleset) ||
|
|
56
54
|
!validator.isNonNullObject(ruleset.source) ||
|
|
57
55
|
!validator.isNonEmptyArray(ruleset.source.files)) {
|
|
58
|
-
|
|
56
|
+
const err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Invalid rules content.');
|
|
59
57
|
return Promise.reject(err);
|
|
60
58
|
}
|
|
61
|
-
for (
|
|
62
|
-
var rf = _a[_i];
|
|
59
|
+
for (const rf of ruleset.source.files) {
|
|
63
60
|
if (!validator.isNonNullObject(rf) ||
|
|
64
61
|
!validator.isNonEmptyString(rf.name) ||
|
|
65
62
|
!validator.isNonEmptyString(rf.content)) {
|
|
66
|
-
|
|
63
|
+
const err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', `Invalid rules file argument: ${JSON.stringify(rf)}`);
|
|
67
64
|
return Promise.reject(err);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
return this.getUrl()
|
|
71
|
-
.then(
|
|
72
|
-
|
|
68
|
+
.then((url) => {
|
|
69
|
+
const request = {
|
|
73
70
|
method: 'POST',
|
|
74
|
-
url: url
|
|
71
|
+
url: `${url}/rulesets`,
|
|
75
72
|
data: ruleset,
|
|
76
73
|
};
|
|
77
|
-
return
|
|
74
|
+
return this.sendRequest(request);
|
|
78
75
|
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var _this = this;
|
|
76
|
+
}
|
|
77
|
+
deleteRuleset(name) {
|
|
82
78
|
return this.getUrl()
|
|
83
|
-
.then(
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
.then((url) => {
|
|
80
|
+
const rulesetName = this.getRulesetName(name);
|
|
81
|
+
const request = {
|
|
86
82
|
method: 'DELETE',
|
|
87
|
-
url: url
|
|
83
|
+
url: `${url}/${rulesetName}`,
|
|
88
84
|
};
|
|
89
|
-
return
|
|
85
|
+
return this.sendRequest(request);
|
|
90
86
|
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
var _this = this;
|
|
94
|
-
if (pageSize === void 0) { pageSize = 100; }
|
|
87
|
+
}
|
|
88
|
+
listRulesets(pageSize = 100, pageToken) {
|
|
95
89
|
if (!validator.isNumber(pageSize)) {
|
|
96
|
-
|
|
90
|
+
const err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Invalid page size.');
|
|
97
91
|
return Promise.reject(err);
|
|
98
92
|
}
|
|
99
93
|
if (pageSize < 1 || pageSize > 100) {
|
|
100
|
-
|
|
94
|
+
const err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Page size must be between 1 and 100.');
|
|
101
95
|
return Promise.reject(err);
|
|
102
96
|
}
|
|
103
97
|
if (typeof pageToken !== 'undefined' && !validator.isNonEmptyString(pageToken)) {
|
|
104
|
-
|
|
98
|
+
const err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Next page token must be a non-empty string.');
|
|
105
99
|
return Promise.reject(err);
|
|
106
100
|
}
|
|
107
|
-
|
|
108
|
-
pageSize
|
|
109
|
-
pageToken
|
|
101
|
+
const data = {
|
|
102
|
+
pageSize,
|
|
103
|
+
pageToken,
|
|
110
104
|
};
|
|
111
105
|
if (!pageToken) {
|
|
112
106
|
delete data.pageToken;
|
|
113
107
|
}
|
|
114
108
|
return this.getUrl()
|
|
115
|
-
.then(
|
|
116
|
-
|
|
109
|
+
.then((url) => {
|
|
110
|
+
const request = {
|
|
117
111
|
method: 'GET',
|
|
118
|
-
url: url
|
|
119
|
-
data
|
|
112
|
+
url: `${url}/rulesets`,
|
|
113
|
+
data,
|
|
120
114
|
};
|
|
121
|
-
return
|
|
115
|
+
return this.sendRequest(request);
|
|
122
116
|
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return this.getResource(
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
var _this = this;
|
|
117
|
+
}
|
|
118
|
+
getRelease(name) {
|
|
119
|
+
return this.getResource(`releases/${name}`);
|
|
120
|
+
}
|
|
121
|
+
updateRelease(name, rulesetName) {
|
|
129
122
|
return this.getUrl()
|
|
130
|
-
.then(
|
|
131
|
-
return
|
|
132
|
-
.then(
|
|
133
|
-
|
|
123
|
+
.then((url) => {
|
|
124
|
+
return this.getReleaseDescription(name, rulesetName)
|
|
125
|
+
.then((release) => {
|
|
126
|
+
const request = {
|
|
134
127
|
method: 'PATCH',
|
|
135
|
-
url: url
|
|
136
|
-
data: { release
|
|
128
|
+
url: `${url}/releases/${name}`,
|
|
129
|
+
data: { release },
|
|
137
130
|
};
|
|
138
|
-
return
|
|
131
|
+
return this.sendRequest(request);
|
|
139
132
|
});
|
|
140
133
|
});
|
|
141
|
-
}
|
|
142
|
-
|
|
134
|
+
}
|
|
135
|
+
getUrl() {
|
|
143
136
|
return this.getProjectIdPrefix()
|
|
144
|
-
.then(
|
|
145
|
-
return RULES_V1_API
|
|
137
|
+
.then((projectIdPrefix) => {
|
|
138
|
+
return `${RULES_V1_API}/${projectIdPrefix}`;
|
|
146
139
|
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
var _this = this;
|
|
140
|
+
}
|
|
141
|
+
getProjectIdPrefix() {
|
|
150
142
|
if (this.projectIdPrefix) {
|
|
151
143
|
return Promise.resolve(this.projectIdPrefix);
|
|
152
144
|
}
|
|
153
145
|
return utils.findProjectId(this.app)
|
|
154
|
-
.then(
|
|
146
|
+
.then((projectId) => {
|
|
155
147
|
if (!validator.isNonEmptyString(projectId)) {
|
|
156
148
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
|
157
149
|
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
|
158
150
|
+ 'environment variable.');
|
|
159
151
|
}
|
|
160
|
-
|
|
161
|
-
return
|
|
152
|
+
this.projectIdPrefix = `projects/${projectId}`;
|
|
153
|
+
return this.projectIdPrefix;
|
|
162
154
|
});
|
|
163
|
-
}
|
|
155
|
+
}
|
|
164
156
|
/**
|
|
165
157
|
* Gets the specified resource from the rules API. Resource names must be the short names without project
|
|
166
158
|
* ID prefix (e.g. `rulesets/ruleset-name`).
|
|
@@ -168,67 +160,63 @@ var SecurityRulesApiClient = /** @class */ (function () {
|
|
|
168
160
|
* @param {string} name Full qualified name of the resource to get.
|
|
169
161
|
* @returns {Promise<T>} A promise that fulfills with the resource.
|
|
170
162
|
*/
|
|
171
|
-
|
|
172
|
-
var _this = this;
|
|
163
|
+
getResource(name) {
|
|
173
164
|
return this.getUrl()
|
|
174
|
-
.then(
|
|
175
|
-
|
|
165
|
+
.then((url) => {
|
|
166
|
+
const request = {
|
|
176
167
|
method: 'GET',
|
|
177
|
-
url: url
|
|
168
|
+
url: `${url}/${name}`,
|
|
178
169
|
};
|
|
179
|
-
return
|
|
170
|
+
return this.sendRequest(request);
|
|
180
171
|
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
var _this = this;
|
|
172
|
+
}
|
|
173
|
+
getReleaseDescription(name, rulesetName) {
|
|
184
174
|
return this.getProjectIdPrefix()
|
|
185
|
-
.then(
|
|
175
|
+
.then((projectIdPrefix) => {
|
|
186
176
|
return {
|
|
187
|
-
name: projectIdPrefix
|
|
188
|
-
rulesetName: projectIdPrefix
|
|
177
|
+
name: `${projectIdPrefix}/releases/${name}`,
|
|
178
|
+
rulesetName: `${projectIdPrefix}/${this.getRulesetName(rulesetName)}`,
|
|
189
179
|
};
|
|
190
180
|
});
|
|
191
|
-
}
|
|
192
|
-
|
|
181
|
+
}
|
|
182
|
+
getRulesetName(name) {
|
|
193
183
|
if (!validator.isNonEmptyString(name)) {
|
|
194
184
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Ruleset name must be a non-empty string.');
|
|
195
185
|
}
|
|
196
186
|
if (name.indexOf('/') !== -1) {
|
|
197
187
|
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Ruleset name must not contain any "/" characters.');
|
|
198
188
|
}
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
var _this = this;
|
|
189
|
+
return `rulesets/${name}`;
|
|
190
|
+
}
|
|
191
|
+
sendRequest(request) {
|
|
203
192
|
request.headers = FIREBASE_VERSION_HEADER;
|
|
204
193
|
return this.httpClient.send(request)
|
|
205
|
-
.then(
|
|
194
|
+
.then((resp) => {
|
|
206
195
|
return resp.data;
|
|
207
196
|
})
|
|
208
|
-
.catch(
|
|
209
|
-
throw
|
|
197
|
+
.catch((err) => {
|
|
198
|
+
throw this.toFirebaseError(err);
|
|
210
199
|
});
|
|
211
|
-
}
|
|
212
|
-
|
|
200
|
+
}
|
|
201
|
+
toFirebaseError(err) {
|
|
213
202
|
if (err instanceof error_1.PrefixedFirebaseError) {
|
|
214
203
|
return err;
|
|
215
204
|
}
|
|
216
|
-
|
|
205
|
+
const response = err.response;
|
|
217
206
|
if (!response.isJson()) {
|
|
218
|
-
return new security_rules_internal_1.FirebaseSecurityRulesError('unknown-error',
|
|
207
|
+
return new security_rules_internal_1.FirebaseSecurityRulesError('unknown-error', `Unexpected response with status: ${response.status} and body: ${response.text}`);
|
|
219
208
|
}
|
|
220
|
-
|
|
221
|
-
|
|
209
|
+
const error = response.data.error || {};
|
|
210
|
+
let code = 'unknown-error';
|
|
222
211
|
if (error.status && error.status in ERROR_CODE_MAPPING) {
|
|
223
212
|
code = ERROR_CODE_MAPPING[error.status];
|
|
224
213
|
}
|
|
225
|
-
|
|
214
|
+
const message = error.message || `Unknown server error: ${response.text}`;
|
|
226
215
|
return new security_rules_internal_1.FirebaseSecurityRulesError(code, message);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
}());
|
|
216
|
+
}
|
|
217
|
+
}
|
|
230
218
|
exports.SecurityRulesApiClient = SecurityRulesApiClient;
|
|
231
|
-
|
|
219
|
+
const ERROR_CODE_MAPPING = {
|
|
232
220
|
INVALID_ARGUMENT: 'invalid-argument',
|
|
233
221
|
NOT_FOUND: 'not-found',
|
|
234
222
|
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
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;
|