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 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.getRemoteConfig = void 0;
|
|
19
|
+
exports.getRemoteConfig = exports.RemoteConfig = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Firebase Remote Config.
|
|
22
22
|
*
|
|
23
23
|
* @packageDocumentation
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const app_1 = require("../app");
|
|
26
|
+
const remote_config_1 = require("./remote-config");
|
|
27
27
|
var remote_config_2 = require("./remote-config");
|
|
28
28
|
Object.defineProperty(exports, "RemoteConfig", { enumerable: true, get: function () { return remote_config_2.RemoteConfig; } });
|
|
29
29
|
/**
|
|
@@ -54,9 +54,9 @@ Object.defineProperty(exports, "RemoteConfig", { enumerable: true, get: function
|
|
|
54
54
|
*/
|
|
55
55
|
function getRemoteConfig(app) {
|
|
56
56
|
if (typeof app === 'undefined') {
|
|
57
|
-
app = app_1.getApp();
|
|
57
|
+
app = (0, app_1.getApp)();
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
return firebaseApp.getOrInitService('remoteConfig',
|
|
59
|
+
const firebaseApp = app;
|
|
60
|
+
return firebaseApp.getOrInitService('remoteConfig', (app) => new remote_config_1.RemoteConfig(app));
|
|
61
61
|
}
|
|
62
62
|
exports.getRemoteConfig = getRemoteConfig;
|
|
@@ -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.
|
|
@@ -15,41 +15,17 @@
|
|
|
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
|
-
var __assign = (this && this.__assign) || function () {
|
|
32
|
-
__assign = Object.assign || function(t) {
|
|
33
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
|
-
s = arguments[i];
|
|
35
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
36
|
-
t[p] = s[p];
|
|
37
|
-
}
|
|
38
|
-
return t;
|
|
39
|
-
};
|
|
40
|
-
return __assign.apply(this, arguments);
|
|
41
|
-
};
|
|
42
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
19
|
exports.FirebaseRemoteConfigError = exports.RemoteConfigApiClient = void 0;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
20
|
+
const api_request_1 = require("../utils/api-request");
|
|
21
|
+
const error_1 = require("../utils/error");
|
|
22
|
+
const utils = require("../utils/index");
|
|
23
|
+
const validator = require("../utils/validator");
|
|
24
|
+
const deep_copy_1 = require("../utils/deep-copy");
|
|
49
25
|
// Remote Config backend constants
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'X-Firebase-Client':
|
|
26
|
+
const FIREBASE_REMOTE_CONFIG_V1_API = 'https://firebaseremoteconfig.googleapis.com/v1';
|
|
27
|
+
const FIREBASE_REMOTE_CONFIG_HEADERS = {
|
|
28
|
+
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
|
|
53
29
|
// There is a known issue in which the ETag is not properly returned in cases where the request
|
|
54
30
|
// does not specify a compression type. Currently, it is required to include the header
|
|
55
31
|
// `Accept-Encoding: gzip` or equivalent in all requests.
|
|
@@ -61,138 +37,131 @@ var FIREBASE_REMOTE_CONFIG_HEADERS = {
|
|
|
61
37
|
*
|
|
62
38
|
* @internal
|
|
63
39
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
class RemoteConfigApiClient {
|
|
41
|
+
constructor(app) {
|
|
66
42
|
this.app = app;
|
|
67
43
|
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
68
44
|
throw new FirebaseRemoteConfigError('invalid-argument', 'First argument passed to admin.remoteConfig() must be a valid Firebase app instance.');
|
|
69
45
|
}
|
|
70
46
|
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
71
47
|
}
|
|
72
|
-
|
|
73
|
-
var _this = this;
|
|
48
|
+
getTemplate() {
|
|
74
49
|
return this.getUrl()
|
|
75
|
-
.then(
|
|
76
|
-
|
|
50
|
+
.then((url) => {
|
|
51
|
+
const request = {
|
|
77
52
|
method: 'GET',
|
|
78
|
-
url: url
|
|
53
|
+
url: `${url}/remoteConfig`,
|
|
79
54
|
headers: FIREBASE_REMOTE_CONFIG_HEADERS
|
|
80
55
|
};
|
|
81
|
-
return
|
|
56
|
+
return this.httpClient.send(request);
|
|
82
57
|
})
|
|
83
|
-
.then(
|
|
84
|
-
return
|
|
58
|
+
.then((resp) => {
|
|
59
|
+
return this.toRemoteConfigTemplate(resp);
|
|
85
60
|
})
|
|
86
|
-
.catch(
|
|
87
|
-
throw
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
throw this.toFirebaseError(err);
|
|
88
63
|
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var data = { versionNumber: this.validateVersionNumber(versionNumber) };
|
|
64
|
+
}
|
|
65
|
+
getTemplateAtVersion(versionNumber) {
|
|
66
|
+
const data = { versionNumber: this.validateVersionNumber(versionNumber) };
|
|
93
67
|
return this.getUrl()
|
|
94
|
-
.then(
|
|
95
|
-
|
|
68
|
+
.then((url) => {
|
|
69
|
+
const request = {
|
|
96
70
|
method: 'GET',
|
|
97
|
-
url: url
|
|
71
|
+
url: `${url}/remoteConfig`,
|
|
98
72
|
headers: FIREBASE_REMOTE_CONFIG_HEADERS,
|
|
99
|
-
data
|
|
73
|
+
data
|
|
100
74
|
};
|
|
101
|
-
return
|
|
75
|
+
return this.httpClient.send(request);
|
|
102
76
|
})
|
|
103
|
-
.then(
|
|
104
|
-
return
|
|
77
|
+
.then((resp) => {
|
|
78
|
+
return this.toRemoteConfigTemplate(resp);
|
|
105
79
|
})
|
|
106
|
-
.catch(
|
|
107
|
-
throw
|
|
80
|
+
.catch((err) => {
|
|
81
|
+
throw this.toFirebaseError(err);
|
|
108
82
|
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
var _this = this;
|
|
83
|
+
}
|
|
84
|
+
validateTemplate(template) {
|
|
112
85
|
template = this.validateInputRemoteConfigTemplate(template);
|
|
113
86
|
return this.sendPutRequest(template, template.etag, true)
|
|
114
|
-
.then(
|
|
87
|
+
.then((resp) => {
|
|
115
88
|
// validating a template returns an etag with the suffix -0 means that your update
|
|
116
89
|
// was successfully validated. We set the etag back to the original etag of the template
|
|
117
90
|
// to allow future operations.
|
|
118
|
-
|
|
119
|
-
return
|
|
91
|
+
this.validateEtag(resp.headers['etag']);
|
|
92
|
+
return this.toRemoteConfigTemplate(resp, template.etag);
|
|
120
93
|
})
|
|
121
|
-
.catch(
|
|
122
|
-
throw
|
|
94
|
+
.catch((err) => {
|
|
95
|
+
throw this.toFirebaseError(err);
|
|
123
96
|
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
var _this = this;
|
|
97
|
+
}
|
|
98
|
+
publishTemplate(template, options) {
|
|
127
99
|
template = this.validateInputRemoteConfigTemplate(template);
|
|
128
|
-
|
|
100
|
+
let ifMatch = template.etag;
|
|
129
101
|
if (options && options.force == true) {
|
|
130
102
|
// setting `If-Match: *` forces the Remote Config template to be updated
|
|
131
103
|
// and circumvent the ETag, and the protection from that it provides.
|
|
132
104
|
ifMatch = '*';
|
|
133
105
|
}
|
|
134
106
|
return this.sendPutRequest(template, ifMatch)
|
|
135
|
-
.then(
|
|
136
|
-
return
|
|
107
|
+
.then((resp) => {
|
|
108
|
+
return this.toRemoteConfigTemplate(resp);
|
|
137
109
|
})
|
|
138
|
-
.catch(
|
|
139
|
-
throw
|
|
110
|
+
.catch((err) => {
|
|
111
|
+
throw this.toFirebaseError(err);
|
|
140
112
|
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
var data = { versionNumber: this.validateVersionNumber(versionNumber) };
|
|
113
|
+
}
|
|
114
|
+
rollback(versionNumber) {
|
|
115
|
+
const data = { versionNumber: this.validateVersionNumber(versionNumber) };
|
|
145
116
|
return this.getUrl()
|
|
146
|
-
.then(
|
|
147
|
-
|
|
117
|
+
.then((url) => {
|
|
118
|
+
const request = {
|
|
148
119
|
method: 'POST',
|
|
149
|
-
url: url
|
|
120
|
+
url: `${url}/remoteConfig:rollback`,
|
|
150
121
|
headers: FIREBASE_REMOTE_CONFIG_HEADERS,
|
|
151
|
-
data
|
|
122
|
+
data
|
|
152
123
|
};
|
|
153
|
-
return
|
|
124
|
+
return this.httpClient.send(request);
|
|
154
125
|
})
|
|
155
|
-
.then(
|
|
156
|
-
return
|
|
126
|
+
.then((resp) => {
|
|
127
|
+
return this.toRemoteConfigTemplate(resp);
|
|
157
128
|
})
|
|
158
|
-
.catch(
|
|
159
|
-
throw
|
|
129
|
+
.catch((err) => {
|
|
130
|
+
throw this.toFirebaseError(err);
|
|
160
131
|
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var _this = this;
|
|
132
|
+
}
|
|
133
|
+
listVersions(options) {
|
|
164
134
|
if (typeof options !== 'undefined') {
|
|
165
135
|
options = this.validateListVersionsOptions(options);
|
|
166
136
|
}
|
|
167
137
|
return this.getUrl()
|
|
168
|
-
.then(
|
|
169
|
-
|
|
138
|
+
.then((url) => {
|
|
139
|
+
const request = {
|
|
170
140
|
method: 'GET',
|
|
171
|
-
url: url
|
|
141
|
+
url: `${url}/remoteConfig:listVersions`,
|
|
172
142
|
headers: FIREBASE_REMOTE_CONFIG_HEADERS,
|
|
173
143
|
data: options
|
|
174
144
|
};
|
|
175
|
-
return
|
|
145
|
+
return this.httpClient.send(request);
|
|
176
146
|
})
|
|
177
|
-
.then(
|
|
147
|
+
.then((resp) => {
|
|
178
148
|
return resp.data;
|
|
179
149
|
})
|
|
180
|
-
.catch(
|
|
181
|
-
throw
|
|
150
|
+
.catch((err) => {
|
|
151
|
+
throw this.toFirebaseError(err);
|
|
182
152
|
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
var path = 'remoteConfig';
|
|
153
|
+
}
|
|
154
|
+
sendPutRequest(template, etag, validateOnly) {
|
|
155
|
+
let path = 'remoteConfig';
|
|
187
156
|
if (validateOnly) {
|
|
188
157
|
path += '?validate_only=true';
|
|
189
158
|
}
|
|
190
159
|
return this.getUrl()
|
|
191
|
-
.then(
|
|
192
|
-
|
|
160
|
+
.then((url) => {
|
|
161
|
+
const request = {
|
|
193
162
|
method: 'PUT',
|
|
194
|
-
url: url
|
|
195
|
-
headers:
|
|
163
|
+
url: `${url}/${path}`,
|
|
164
|
+
headers: { ...FIREBASE_REMOTE_CONFIG_HEADERS, 'If-Match': etag },
|
|
196
165
|
data: {
|
|
197
166
|
conditions: template.conditions,
|
|
198
167
|
parameters: template.parameters,
|
|
@@ -200,47 +169,46 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
200
169
|
version: template.version,
|
|
201
170
|
}
|
|
202
171
|
};
|
|
203
|
-
return
|
|
172
|
+
return this.httpClient.send(request);
|
|
204
173
|
});
|
|
205
|
-
}
|
|
206
|
-
|
|
174
|
+
}
|
|
175
|
+
getUrl() {
|
|
207
176
|
return this.getProjectIdPrefix()
|
|
208
|
-
.then(
|
|
209
|
-
return FIREBASE_REMOTE_CONFIG_V1_API
|
|
177
|
+
.then((projectIdPrefix) => {
|
|
178
|
+
return `${FIREBASE_REMOTE_CONFIG_V1_API}/${projectIdPrefix}`;
|
|
210
179
|
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
var _this = this;
|
|
180
|
+
}
|
|
181
|
+
getProjectIdPrefix() {
|
|
214
182
|
if (this.projectIdPrefix) {
|
|
215
183
|
return Promise.resolve(this.projectIdPrefix);
|
|
216
184
|
}
|
|
217
185
|
return utils.findProjectId(this.app)
|
|
218
|
-
.then(
|
|
186
|
+
.then((projectId) => {
|
|
219
187
|
if (!validator.isNonEmptyString(projectId)) {
|
|
220
188
|
throw new FirebaseRemoteConfigError('unknown-error', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
|
221
189
|
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
|
222
190
|
+ 'environment variable.');
|
|
223
191
|
}
|
|
224
|
-
|
|
225
|
-
return
|
|
192
|
+
this.projectIdPrefix = `projects/${projectId}`;
|
|
193
|
+
return this.projectIdPrefix;
|
|
226
194
|
});
|
|
227
|
-
}
|
|
228
|
-
|
|
195
|
+
}
|
|
196
|
+
toFirebaseError(err) {
|
|
229
197
|
if (err instanceof error_1.PrefixedFirebaseError) {
|
|
230
198
|
return err;
|
|
231
199
|
}
|
|
232
|
-
|
|
200
|
+
const response = err.response;
|
|
233
201
|
if (!response.isJson()) {
|
|
234
|
-
return new FirebaseRemoteConfigError('unknown-error',
|
|
202
|
+
return new FirebaseRemoteConfigError('unknown-error', `Unexpected response with status: ${response.status} and body: ${response.text}`);
|
|
235
203
|
}
|
|
236
|
-
|
|
237
|
-
|
|
204
|
+
const error = response.data.error || {};
|
|
205
|
+
let code = 'unknown-error';
|
|
238
206
|
if (error.status && error.status in ERROR_CODE_MAPPING) {
|
|
239
207
|
code = ERROR_CODE_MAPPING[error.status];
|
|
240
208
|
}
|
|
241
|
-
|
|
209
|
+
const message = error.message || `Unknown server error: ${response.text}`;
|
|
242
210
|
return new FirebaseRemoteConfigError(code, message);
|
|
243
|
-
}
|
|
211
|
+
}
|
|
244
212
|
/**
|
|
245
213
|
* Creates a RemoteConfigTemplate from the API response.
|
|
246
214
|
* If provided, customEtag is used instead of the etag returned in the API response.
|
|
@@ -248,17 +216,17 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
248
216
|
* @param {HttpResponse} resp API response object.
|
|
249
217
|
* @param {string} customEtag A custom etag to replace the etag fom the API response (Optional).
|
|
250
218
|
*/
|
|
251
|
-
|
|
252
|
-
|
|
219
|
+
toRemoteConfigTemplate(resp, customEtag) {
|
|
220
|
+
const etag = (typeof customEtag == 'undefined') ? resp.headers['etag'] : customEtag;
|
|
253
221
|
this.validateEtag(etag);
|
|
254
222
|
return {
|
|
255
223
|
conditions: resp.data.conditions,
|
|
256
224
|
parameters: resp.data.parameters,
|
|
257
225
|
parameterGroups: resp.data.parameterGroups,
|
|
258
|
-
etag
|
|
226
|
+
etag,
|
|
259
227
|
version: resp.data.version,
|
|
260
228
|
};
|
|
261
|
-
}
|
|
229
|
+
}
|
|
262
230
|
/**
|
|
263
231
|
* Checks if the given RemoteConfigTemplate object is valid.
|
|
264
232
|
* The object must have valid parameters, parameter groups, conditions, and an etag.
|
|
@@ -268,10 +236,10 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
268
236
|
*
|
|
269
237
|
* @returns {RemoteConfigTemplate} The validated RemoteConfigTemplate object.
|
|
270
238
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
239
|
+
validateInputRemoteConfigTemplate(template) {
|
|
240
|
+
const templateCopy = (0, deep_copy_1.deepCopy)(template);
|
|
273
241
|
if (!validator.isNonNullObject(templateCopy)) {
|
|
274
|
-
throw new FirebaseRemoteConfigError('invalid-argument',
|
|
242
|
+
throw new FirebaseRemoteConfigError('invalid-argument', `Invalid Remote Config template: ${JSON.stringify(templateCopy)}`);
|
|
275
243
|
}
|
|
276
244
|
if (!validator.isNonEmptyString(templateCopy.etag)) {
|
|
277
245
|
throw new FirebaseRemoteConfigError('invalid-argument', 'ETag must be a non-empty string.');
|
|
@@ -290,7 +258,7 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
290
258
|
templateCopy.version = { description: templateCopy.version.description };
|
|
291
259
|
}
|
|
292
260
|
return templateCopy;
|
|
293
|
-
}
|
|
261
|
+
}
|
|
294
262
|
/**
|
|
295
263
|
* Checks if a given version number is valid.
|
|
296
264
|
* A version number must be an integer or a string in int64 format.
|
|
@@ -300,22 +268,21 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
300
268
|
*
|
|
301
269
|
* @returns {string} The validated version number as a string.
|
|
302
270
|
*/
|
|
303
|
-
|
|
304
|
-
if (propertyName === void 0) { propertyName = 'versionNumber'; }
|
|
271
|
+
validateVersionNumber(versionNumber, propertyName = 'versionNumber') {
|
|
305
272
|
if (!validator.isNonEmptyString(versionNumber) &&
|
|
306
273
|
!validator.isNumber(versionNumber)) {
|
|
307
|
-
throw new FirebaseRemoteConfigError('invalid-argument', propertyName
|
|
274
|
+
throw new FirebaseRemoteConfigError('invalid-argument', `${propertyName} must be a non-empty string in int64 format or a number`);
|
|
308
275
|
}
|
|
309
276
|
if (!Number.isInteger(Number(versionNumber))) {
|
|
310
|
-
throw new FirebaseRemoteConfigError('invalid-argument', propertyName
|
|
277
|
+
throw new FirebaseRemoteConfigError('invalid-argument', `${propertyName} must be an integer or a string in int64 format`);
|
|
311
278
|
}
|
|
312
279
|
return versionNumber.toString();
|
|
313
|
-
}
|
|
314
|
-
|
|
280
|
+
}
|
|
281
|
+
validateEtag(etag) {
|
|
315
282
|
if (!validator.isNonEmptyString(etag)) {
|
|
316
283
|
throw new FirebaseRemoteConfigError('invalid-argument', 'ETag header is not present in the server response.');
|
|
317
284
|
}
|
|
318
|
-
}
|
|
285
|
+
}
|
|
319
286
|
/**
|
|
320
287
|
* Checks if a given `ListVersionsOptions` object is valid. If successful, creates a copy of the
|
|
321
288
|
* options object and convert `startTime` and `endTime` to RFC3339 UTC "Zulu" format, if present.
|
|
@@ -325,8 +292,8 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
325
292
|
* @returns {ListVersionsOptions} A copy of the provided options object with timestamps converted
|
|
326
293
|
* to UTC Zulu format.
|
|
327
294
|
*/
|
|
328
|
-
|
|
329
|
-
|
|
295
|
+
validateListVersionsOptions(options) {
|
|
296
|
+
const optionsCopy = (0, deep_copy_1.deepCopy)(options);
|
|
330
297
|
if (!validator.isNonNullObject(optionsCopy)) {
|
|
331
298
|
throw new FirebaseRemoteConfigError('invalid-argument', 'ListVersionsOptions must be a non-null object.');
|
|
332
299
|
}
|
|
@@ -369,15 +336,12 @@ var RemoteConfigApiClient = /** @class */ (function () {
|
|
|
369
336
|
}
|
|
370
337
|
}
|
|
371
338
|
// Remove undefined fields from optionsCopy
|
|
372
|
-
Object.keys(optionsCopy).forEach(
|
|
373
|
-
return (typeof optionsCopy[key] === 'undefined') && delete optionsCopy[key];
|
|
374
|
-
});
|
|
339
|
+
Object.keys(optionsCopy).forEach(key => (typeof optionsCopy[key] === 'undefined') && delete optionsCopy[key]);
|
|
375
340
|
return optionsCopy;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
}());
|
|
341
|
+
}
|
|
342
|
+
}
|
|
379
343
|
exports.RemoteConfigApiClient = RemoteConfigApiClient;
|
|
380
|
-
|
|
344
|
+
const ERROR_CODE_MAPPING = {
|
|
381
345
|
ABORTED: 'aborted',
|
|
382
346
|
ALREADY_EXISTS: 'already-exists',
|
|
383
347
|
INVALID_ARGUMENT: 'invalid-argument',
|
|
@@ -397,11 +361,9 @@ var ERROR_CODE_MAPPING = {
|
|
|
397
361
|
* @param {string} message The error message.
|
|
398
362
|
* @constructor
|
|
399
363
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return _super.call(this, 'remote-config', code, message) || this;
|
|
364
|
+
class FirebaseRemoteConfigError extends error_1.PrefixedFirebaseError {
|
|
365
|
+
constructor(code, message) {
|
|
366
|
+
super('remote-config', code, message);
|
|
404
367
|
}
|
|
405
|
-
|
|
406
|
-
}(error_1.PrefixedFirebaseError));
|
|
368
|
+
}
|
|
407
369
|
exports.FirebaseRemoteConfigError = FirebaseRemoteConfigError;
|