firebase-admin 9.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +90 -0
- package/lib/app-check/app-check-api-client-internal.js +197 -0
- package/lib/app-check/app-check.js +79 -0
- package/lib/app-check/index.d.ts +160 -0
- package/lib/app-check/index.js +19 -0
- package/lib/app-check/token-generator.js +161 -0
- package/lib/app-check/token-verifier.js +152 -0
- package/lib/auth/action-code-settings-builder.js +118 -0
- package/lib/auth/auth-api-request.js +1856 -0
- package/lib/auth/auth-config.js +636 -0
- package/lib/auth/auth.js +836 -0
- package/lib/auth/identifier.js +40 -0
- package/lib/auth/index.d.ts +1927 -0
- package/lib/auth/index.js +18 -0
- package/lib/auth/tenant-manager.js +140 -0
- package/lib/auth/tenant.js +171 -0
- package/lib/auth/token-generator.js +200 -0
- package/lib/auth/token-verifier.js +259 -0
- package/lib/auth/user-import-builder.js +387 -0
- package/lib/auth/user-record.js +346 -0
- package/lib/credential/credential-internal.js +391 -0
- package/lib/credential/credential.js +44 -0
- package/lib/credential/index.d.ts +169 -0
- package/lib/credential/index.js +23 -0
- package/lib/database/database-internal.js +266 -0
- package/lib/database/index.d.ts +89 -0
- package/lib/database/index.js +31 -0
- package/lib/default-namespace.js +31 -0
- package/lib/firebase-app.js +349 -0
- package/lib/firebase-namespace-api.d.ts +243 -0
- package/lib/firebase-namespace-api.js +18 -0
- package/lib/firebase-namespace.d.ts +31 -0
- package/lib/firebase-namespace.js +417 -0
- package/lib/firestore/firestore-internal.js +105 -0
- package/lib/firestore/index.d.ts +50 -0
- package/lib/firestore/index.js +47 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +27 -0
- package/lib/installations/index.d.ts +81 -0
- package/lib/installations/index.js +18 -0
- package/lib/installations/installations-request-handler.js +117 -0
- package/lib/installations/installations.js +62 -0
- package/lib/instance-id/index.d.ts +83 -0
- package/lib/instance-id/index.js +18 -0
- package/lib/instance-id/instance-id.js +87 -0
- package/lib/machine-learning/index.d.ts +249 -0
- package/lib/machine-learning/index.js +18 -0
- package/lib/machine-learning/machine-learning-api-client.js +304 -0
- package/lib/machine-learning/machine-learning-utils.js +62 -0
- package/lib/machine-learning/machine-learning.js +364 -0
- package/lib/messaging/batch-request-internal.js +129 -0
- package/lib/messaging/index.d.ts +1174 -0
- package/lib/messaging/index.js +18 -0
- package/lib/messaging/messaging-api-request-internal.js +128 -0
- package/lib/messaging/messaging-errors-internal.js +106 -0
- package/lib/messaging/messaging-internal.js +484 -0
- package/lib/messaging/messaging.js +846 -0
- package/lib/project-management/android-app.js +176 -0
- package/lib/project-management/index.d.ts +363 -0
- package/lib/project-management/index.js +41 -0
- package/lib/project-management/ios-app.js +88 -0
- package/lib/project-management/project-management-api-request-internal.js +273 -0
- package/lib/project-management/project-management.js +254 -0
- package/lib/remote-config/index.d.ts +369 -0
- package/lib/remote-config/index.js +18 -0
- package/lib/remote-config/remote-config-api-client-internal.js +407 -0
- package/lib/remote-config/remote-config.js +304 -0
- package/lib/security-rules/index.d.ts +216 -0
- package/lib/security-rules/index.js +18 -0
- package/lib/security-rules/security-rules-api-client-internal.js +237 -0
- package/lib/security-rules/security-rules-internal.js +41 -0
- package/lib/security-rules/security-rules.js +310 -0
- package/lib/storage/index.d.ts +60 -0
- package/lib/storage/index.js +18 -0
- package/lib/storage/storage.js +123 -0
- package/lib/utils/api-request.js +845 -0
- package/lib/utils/crypto-signer.js +237 -0
- package/lib/utils/deep-copy.js +78 -0
- package/lib/utils/error.js +1063 -0
- package/lib/utils/index.js +217 -0
- package/lib/utils/jwt.js +355 -0
- package/lib/utils/validator.js +271 -0
- package/package.json +122 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2018 Google Inc.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ProjectManagementRequestHandler = exports.assertServerResponse = void 0;
|
|
20
|
+
var api_request_1 = require("../utils/api-request");
|
|
21
|
+
var error_1 = require("../utils/error");
|
|
22
|
+
var validator = require("../utils/validator");
|
|
23
|
+
var index_1 = require("../utils/index");
|
|
24
|
+
/** Project management backend host and port. */
|
|
25
|
+
var PROJECT_MANAGEMENT_HOST_AND_PORT = 'firebase.googleapis.com:443';
|
|
26
|
+
/** Project management backend path. */
|
|
27
|
+
var PROJECT_MANAGEMENT_PATH = '/v1/';
|
|
28
|
+
/** Project management beta backend path. */
|
|
29
|
+
var PROJECT_MANAGEMENT_BETA_PATH = '/v1beta1/';
|
|
30
|
+
/** Project management request header. */
|
|
31
|
+
var PROJECT_MANAGEMENT_HEADERS = {
|
|
32
|
+
'X-Client-Version': "Node/Admin/" + index_1.getSdkVersion(),
|
|
33
|
+
};
|
|
34
|
+
/** Project management request timeout duration in milliseconds. */
|
|
35
|
+
var PROJECT_MANAGEMENT_TIMEOUT_MILLIS = 10000;
|
|
36
|
+
var LIST_APPS_MAX_PAGE_SIZE = 100;
|
|
37
|
+
var CERT_TYPE_API_MAP = {
|
|
38
|
+
sha1: 'SHA_1',
|
|
39
|
+
sha256: 'SHA_256',
|
|
40
|
+
};
|
|
41
|
+
function assertServerResponse(condition, responseData, message) {
|
|
42
|
+
if (!condition) {
|
|
43
|
+
throw new error_1.FirebaseProjectManagementError('invalid-server-response', message + " Response data: " + JSON.stringify(responseData, null, 2));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.assertServerResponse = assertServerResponse;
|
|
47
|
+
/**
|
|
48
|
+
* Class that provides mechanism to send requests to the Firebase project management backend
|
|
49
|
+
* endpoints.
|
|
50
|
+
*
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
var ProjectManagementRequestHandler = /** @class */ (function () {
|
|
54
|
+
/**
|
|
55
|
+
* @param {FirebaseApp} app The app used to fetch access tokens to sign API requests.
|
|
56
|
+
* @constructor
|
|
57
|
+
*/
|
|
58
|
+
function ProjectManagementRequestHandler(app) {
|
|
59
|
+
this.baseUrl = "https://" + PROJECT_MANAGEMENT_HOST_AND_PORT + PROJECT_MANAGEMENT_PATH;
|
|
60
|
+
this.baseBetaUrl = "https://" + PROJECT_MANAGEMENT_HOST_AND_PORT + PROJECT_MANAGEMENT_BETA_PATH;
|
|
61
|
+
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
62
|
+
}
|
|
63
|
+
ProjectManagementRequestHandler.wrapAndRethrowHttpError = function (errStatusCode, errText) {
|
|
64
|
+
var errorCode;
|
|
65
|
+
var errorMessage;
|
|
66
|
+
switch (errStatusCode) {
|
|
67
|
+
case 400:
|
|
68
|
+
errorCode = 'invalid-argument';
|
|
69
|
+
errorMessage = 'Invalid argument provided.';
|
|
70
|
+
break;
|
|
71
|
+
case 401:
|
|
72
|
+
case 403:
|
|
73
|
+
errorCode = 'authentication-error';
|
|
74
|
+
errorMessage = 'An error occurred when trying to authenticate. Make sure the credential '
|
|
75
|
+
+ 'used to authenticate this SDK has the proper permissions. See '
|
|
76
|
+
+ 'https://firebase.google.com/docs/admin/setup for setup instructions.';
|
|
77
|
+
break;
|
|
78
|
+
case 404:
|
|
79
|
+
errorCode = 'not-found';
|
|
80
|
+
errorMessage = 'The specified entity could not be found.';
|
|
81
|
+
break;
|
|
82
|
+
case 409:
|
|
83
|
+
errorCode = 'already-exists';
|
|
84
|
+
errorMessage = 'The specified entity already exists.';
|
|
85
|
+
break;
|
|
86
|
+
case 500:
|
|
87
|
+
errorCode = 'internal-error';
|
|
88
|
+
errorMessage = 'An internal error has occurred. Please retry the request.';
|
|
89
|
+
break;
|
|
90
|
+
case 503:
|
|
91
|
+
errorCode = 'service-unavailable';
|
|
92
|
+
errorMessage = 'The server could not process the request in time. See the error '
|
|
93
|
+
+ 'documentation for more details.';
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
errorCode = 'unknown-error';
|
|
97
|
+
errorMessage = 'An unknown server error was returned.';
|
|
98
|
+
}
|
|
99
|
+
if (!errText) {
|
|
100
|
+
errText = '<missing>';
|
|
101
|
+
}
|
|
102
|
+
throw new error_1.FirebaseProjectManagementError(errorCode, errorMessage + " Status code: " + errStatusCode + ". Raw server response: \"" + errText + "\".");
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} parentResourceName Fully-qualified resource name of the project whose Android
|
|
106
|
+
* apps you want to list.
|
|
107
|
+
*/
|
|
108
|
+
ProjectManagementRequestHandler.prototype.listAndroidApps = function (parentResourceName) {
|
|
109
|
+
return this.invokeRequestHandler('GET', parentResourceName + "/androidApps?page_size=" + LIST_APPS_MAX_PAGE_SIZE,
|
|
110
|
+
/* requestData */ null, 'v1beta1');
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} parentResourceName Fully-qualified resource name of the project whose iOS apps
|
|
114
|
+
* you want to list.
|
|
115
|
+
*/
|
|
116
|
+
ProjectManagementRequestHandler.prototype.listIosApps = function (parentResourceName) {
|
|
117
|
+
return this.invokeRequestHandler('GET', parentResourceName + "/iosApps?page_size=" + LIST_APPS_MAX_PAGE_SIZE,
|
|
118
|
+
/* requestData */ null, 'v1beta1');
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* @param {string} parentResourceName Fully-qualified resource name of the project whose iOS apps
|
|
122
|
+
* you want to list.
|
|
123
|
+
*/
|
|
124
|
+
ProjectManagementRequestHandler.prototype.listAppMetadata = function (parentResourceName) {
|
|
125
|
+
return this.invokeRequestHandler('GET', parentResourceName + ":searchApps?page_size=" + LIST_APPS_MAX_PAGE_SIZE,
|
|
126
|
+
/* requestData */ null, 'v1beta1');
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} parentResourceName Fully-qualified resource name of the project that you want
|
|
130
|
+
* to create the Android app within.
|
|
131
|
+
*/
|
|
132
|
+
ProjectManagementRequestHandler.prototype.createAndroidApp = function (parentResourceName, packageName, displayName) {
|
|
133
|
+
var _this = this;
|
|
134
|
+
var requestData = {
|
|
135
|
+
packageName: packageName,
|
|
136
|
+
};
|
|
137
|
+
if (validator.isNonEmptyString(displayName)) {
|
|
138
|
+
requestData.displayName = displayName;
|
|
139
|
+
}
|
|
140
|
+
return this
|
|
141
|
+
.invokeRequestHandler('POST', parentResourceName + "/androidApps", requestData, 'v1beta1')
|
|
142
|
+
.then(function (responseData) {
|
|
143
|
+
assertServerResponse(validator.isNonNullObject(responseData), responseData, 'createAndroidApp\'s responseData must be a non-null object.');
|
|
144
|
+
assertServerResponse(validator.isNonEmptyString(responseData.name), responseData, 'createAndroidApp\'s responseData.name must be a non-empty string.');
|
|
145
|
+
return _this.pollRemoteOperationWithExponentialBackoff(responseData.name);
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* @param {string} parentResourceName Fully-qualified resource name of the project that you want
|
|
150
|
+
* to create the iOS app within.
|
|
151
|
+
*/
|
|
152
|
+
ProjectManagementRequestHandler.prototype.createIosApp = function (parentResourceName, bundleId, displayName) {
|
|
153
|
+
var _this = this;
|
|
154
|
+
var requestData = {
|
|
155
|
+
bundleId: bundleId,
|
|
156
|
+
};
|
|
157
|
+
if (validator.isNonEmptyString(displayName)) {
|
|
158
|
+
requestData.displayName = displayName;
|
|
159
|
+
}
|
|
160
|
+
return this
|
|
161
|
+
.invokeRequestHandler('POST', parentResourceName + "/iosApps", requestData, 'v1beta1')
|
|
162
|
+
.then(function (responseData) {
|
|
163
|
+
assertServerResponse(validator.isNonNullObject(responseData), responseData, 'createIosApp\'s responseData must be a non-null object.');
|
|
164
|
+
assertServerResponse(validator.isNonEmptyString(responseData.name), responseData, 'createIosApp\'s responseData.name must be a non-empty string.');
|
|
165
|
+
return _this.pollRemoteOperationWithExponentialBackoff(responseData.name);
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* @param {string} resourceName Fully-qualified resource name of the entity whose display name you
|
|
170
|
+
* want to set.
|
|
171
|
+
*/
|
|
172
|
+
ProjectManagementRequestHandler.prototype.setDisplayName = function (resourceName, newDisplayName) {
|
|
173
|
+
var requestData = {
|
|
174
|
+
displayName: newDisplayName,
|
|
175
|
+
};
|
|
176
|
+
return this
|
|
177
|
+
.invokeRequestHandler('PATCH', resourceName + "?update_mask=display_name", requestData, 'v1beta1')
|
|
178
|
+
.then(function () { return undefined; });
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* @param {string} parentResourceName Fully-qualified resource name of the Android app whose SHA
|
|
182
|
+
* certificates you want to get.
|
|
183
|
+
*/
|
|
184
|
+
ProjectManagementRequestHandler.prototype.getAndroidShaCertificates = function (parentResourceName) {
|
|
185
|
+
return this.invokeRequestHandler('GET', parentResourceName + "/sha", /* requestData */ null, 'v1beta1');
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* @param {string} parentResourceName Fully-qualified resource name of the Android app that you
|
|
189
|
+
* want to add the given SHA certificate to.
|
|
190
|
+
*/
|
|
191
|
+
ProjectManagementRequestHandler.prototype.addAndroidShaCertificate = function (parentResourceName, certificate) {
|
|
192
|
+
var requestData = {
|
|
193
|
+
shaHash: certificate.shaHash,
|
|
194
|
+
certType: CERT_TYPE_API_MAP[certificate.certType],
|
|
195
|
+
};
|
|
196
|
+
return this
|
|
197
|
+
.invokeRequestHandler('POST', parentResourceName + "/sha", requestData, 'v1beta1')
|
|
198
|
+
.then(function () { return undefined; });
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* @param {string} parentResourceName Fully-qualified resource name of the app whose config you
|
|
202
|
+
* want to get.
|
|
203
|
+
*/
|
|
204
|
+
ProjectManagementRequestHandler.prototype.getConfig = function (parentResourceName) {
|
|
205
|
+
return this.invokeRequestHandler('GET', parentResourceName + "/config", /* requestData */ null, 'v1beta1');
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* @param {string} parentResourceName Fully-qualified resource name of the entity that you want to
|
|
209
|
+
* get.
|
|
210
|
+
*/
|
|
211
|
+
ProjectManagementRequestHandler.prototype.getResource = function (parentResourceName) {
|
|
212
|
+
return this.invokeRequestHandler('GET', parentResourceName, /* requestData */ null, 'v1beta1');
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* @param {string} resourceName Fully-qualified resource name of the entity that you want to
|
|
216
|
+
* delete.
|
|
217
|
+
*/
|
|
218
|
+
ProjectManagementRequestHandler.prototype.deleteResource = function (resourceName) {
|
|
219
|
+
return this
|
|
220
|
+
.invokeRequestHandler('DELETE', resourceName, /* requestData */ null, 'v1beta1')
|
|
221
|
+
.then(function () { return undefined; });
|
|
222
|
+
};
|
|
223
|
+
ProjectManagementRequestHandler.prototype.pollRemoteOperationWithExponentialBackoff = function (operationResourceName) {
|
|
224
|
+
var _this = this;
|
|
225
|
+
var poller = new api_request_1.ExponentialBackoffPoller();
|
|
226
|
+
return poller.poll(function () {
|
|
227
|
+
return _this.invokeRequestHandler('GET', operationResourceName, /* requestData */ null)
|
|
228
|
+
.then(function (responseData) {
|
|
229
|
+
if (responseData.error) {
|
|
230
|
+
var errStatusCode = responseData.error.code || 500;
|
|
231
|
+
var errText = responseData.error.message || JSON.stringify(responseData.error);
|
|
232
|
+
ProjectManagementRequestHandler.wrapAndRethrowHttpError(errStatusCode, errText);
|
|
233
|
+
}
|
|
234
|
+
if (!responseData.done) {
|
|
235
|
+
// Continue polling.
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
// Polling complete. Resolve with operation response JSON.
|
|
239
|
+
return responseData.response;
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Invokes the request handler with the provided request data.
|
|
245
|
+
*/
|
|
246
|
+
ProjectManagementRequestHandler.prototype.invokeRequestHandler = function (method, path, requestData, apiVersion) {
|
|
247
|
+
if (apiVersion === void 0) { apiVersion = 'v1'; }
|
|
248
|
+
var baseUrlToUse = (apiVersion === 'v1') ? this.baseUrl : this.baseBetaUrl;
|
|
249
|
+
var request = {
|
|
250
|
+
method: method,
|
|
251
|
+
url: "" + baseUrlToUse + path,
|
|
252
|
+
headers: PROJECT_MANAGEMENT_HEADERS,
|
|
253
|
+
data: requestData,
|
|
254
|
+
timeout: PROJECT_MANAGEMENT_TIMEOUT_MILLIS,
|
|
255
|
+
};
|
|
256
|
+
return this.httpClient.send(request)
|
|
257
|
+
.then(function (response) {
|
|
258
|
+
// Send non-JSON responses to the catch() below, where they will be treated as errors.
|
|
259
|
+
if (!response.isJson()) {
|
|
260
|
+
throw new api_request_1.HttpError(response);
|
|
261
|
+
}
|
|
262
|
+
return response.data;
|
|
263
|
+
})
|
|
264
|
+
.catch(function (err) {
|
|
265
|
+
if (err instanceof api_request_1.HttpError) {
|
|
266
|
+
ProjectManagementRequestHandler.wrapAndRethrowHttpError(err.response.status, err.response.text);
|
|
267
|
+
}
|
|
268
|
+
throw err;
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
return ProjectManagementRequestHandler;
|
|
272
|
+
}());
|
|
273
|
+
exports.ProjectManagementRequestHandler = ProjectManagementRequestHandler;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2018 Google Inc.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ProjectManagement = void 0;
|
|
20
|
+
var error_1 = require("../utils/error");
|
|
21
|
+
var utils = require("../utils/index");
|
|
22
|
+
var validator = require("../utils/validator");
|
|
23
|
+
var android_app_1 = require("./android-app");
|
|
24
|
+
var ios_app_1 = require("./ios-app");
|
|
25
|
+
var project_management_api_request_internal_1 = require("./project-management-api-request-internal");
|
|
26
|
+
var index_1 = require("./index");
|
|
27
|
+
var AppPlatform = index_1.projectManagement.AppPlatform;
|
|
28
|
+
/**
|
|
29
|
+
* The Firebase ProjectManagement service interface.
|
|
30
|
+
*
|
|
31
|
+
* Do not call this constructor directly. Instead, use
|
|
32
|
+
* [`admin.projectManagement()`](projectManagement#projectManagement).
|
|
33
|
+
*/
|
|
34
|
+
var ProjectManagement = /** @class */ (function () {
|
|
35
|
+
/**
|
|
36
|
+
* @param {object} app The app for this ProjectManagement service.
|
|
37
|
+
* @constructor
|
|
38
|
+
*/
|
|
39
|
+
function ProjectManagement(app) {
|
|
40
|
+
this.app = app;
|
|
41
|
+
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
42
|
+
throw new error_1.FirebaseProjectManagementError('invalid-argument', 'First argument passed to admin.projectManagement() must be a valid Firebase app '
|
|
43
|
+
+ 'instance.');
|
|
44
|
+
}
|
|
45
|
+
this.requestHandler = new project_management_api_request_internal_1.ProjectManagementRequestHandler(app);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Lists up to 100 Firebase Android apps associated with this Firebase project.
|
|
49
|
+
*
|
|
50
|
+
* @return The list of Android apps.
|
|
51
|
+
*/
|
|
52
|
+
ProjectManagement.prototype.listAndroidApps = function () {
|
|
53
|
+
return this.listPlatformApps('android', 'listAndroidApps()');
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Lists up to 100 Firebase iOS apps associated with this Firebase project.
|
|
57
|
+
*
|
|
58
|
+
* @return The list of iOS apps.
|
|
59
|
+
*/
|
|
60
|
+
ProjectManagement.prototype.listIosApps = function () {
|
|
61
|
+
return this.listPlatformApps('ios', 'listIosApps()');
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Creates an `AndroidApp` object, referencing the specified Android app within
|
|
65
|
+
* this Firebase project.
|
|
66
|
+
*
|
|
67
|
+
* This method does not perform an RPC.
|
|
68
|
+
*
|
|
69
|
+
* @param appId The `appId` of the Android app to reference.
|
|
70
|
+
*
|
|
71
|
+
* @return An `AndroidApp` object that references the specified Firebase Android app.
|
|
72
|
+
*/
|
|
73
|
+
ProjectManagement.prototype.androidApp = function (appId) {
|
|
74
|
+
return new android_app_1.AndroidApp(appId, this.requestHandler);
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Creates an `iOSApp` object, referencing the specified iOS app within
|
|
78
|
+
* this Firebase project.
|
|
79
|
+
*
|
|
80
|
+
* This method does not perform an RPC.
|
|
81
|
+
*
|
|
82
|
+
* @param appId The `appId` of the iOS app to reference.
|
|
83
|
+
*
|
|
84
|
+
* @return An `iOSApp` object that references the specified Firebase iOS app.
|
|
85
|
+
*/
|
|
86
|
+
ProjectManagement.prototype.iosApp = function (appId) {
|
|
87
|
+
return new ios_app_1.IosApp(appId, this.requestHandler);
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Creates a `ShaCertificate` object.
|
|
91
|
+
*
|
|
92
|
+
* This method does not perform an RPC.
|
|
93
|
+
*
|
|
94
|
+
* @param shaHash The SHA-1 or SHA-256 hash for this certificate.
|
|
95
|
+
*
|
|
96
|
+
* @return A `ShaCertificate` object contains the specified SHA hash.
|
|
97
|
+
*/
|
|
98
|
+
ProjectManagement.prototype.shaCertificate = function (shaHash) {
|
|
99
|
+
return new android_app_1.ShaCertificate(shaHash);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new Firebase Android app associated with this Firebase project.
|
|
103
|
+
*
|
|
104
|
+
* @param packageName The canonical package name of the Android App,
|
|
105
|
+
* as would appear in the Google Play Developer Console.
|
|
106
|
+
* @param displayName An optional user-assigned display name for this
|
|
107
|
+
* new app.
|
|
108
|
+
*
|
|
109
|
+
* @return A promise that resolves to the newly created Android app.
|
|
110
|
+
*/
|
|
111
|
+
ProjectManagement.prototype.createAndroidApp = function (packageName, displayName) {
|
|
112
|
+
var _this = this;
|
|
113
|
+
return this.getResourceName()
|
|
114
|
+
.then(function (resourceName) {
|
|
115
|
+
return _this.requestHandler.createAndroidApp(resourceName, packageName, displayName);
|
|
116
|
+
})
|
|
117
|
+
.then(function (responseData) {
|
|
118
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonNullObject(responseData), responseData, 'createAndroidApp()\'s responseData must be a non-null object.');
|
|
119
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonEmptyString(responseData.appId), responseData, '"responseData.appId" field must be present in createAndroidApp()\'s response data.');
|
|
120
|
+
return new android_app_1.AndroidApp(responseData.appId, _this.requestHandler);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new Firebase iOS app associated with this Firebase project.
|
|
125
|
+
*
|
|
126
|
+
* @param bundleId The iOS app bundle ID to use for this new app.
|
|
127
|
+
* @param displayName An optional user-assigned display name for this
|
|
128
|
+
* new app.
|
|
129
|
+
*
|
|
130
|
+
* @return A promise that resolves to the newly created iOS app.
|
|
131
|
+
*/
|
|
132
|
+
ProjectManagement.prototype.createIosApp = function (bundleId, displayName) {
|
|
133
|
+
var _this = this;
|
|
134
|
+
return this.getResourceName()
|
|
135
|
+
.then(function (resourceName) {
|
|
136
|
+
return _this.requestHandler.createIosApp(resourceName, bundleId, displayName);
|
|
137
|
+
})
|
|
138
|
+
.then(function (responseData) {
|
|
139
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonNullObject(responseData), responseData, 'createIosApp()\'s responseData must be a non-null object.');
|
|
140
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonEmptyString(responseData.appId), responseData, '"responseData.appId" field must be present in createIosApp()\'s response data.');
|
|
141
|
+
return new ios_app_1.IosApp(responseData.appId, _this.requestHandler);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Lists up to 100 Firebase apps associated with this Firebase project.
|
|
146
|
+
*
|
|
147
|
+
* @return A promise that resolves to the metadata list of the apps.
|
|
148
|
+
*/
|
|
149
|
+
ProjectManagement.prototype.listAppMetadata = function () {
|
|
150
|
+
var _this = this;
|
|
151
|
+
return this.getResourceName()
|
|
152
|
+
.then(function (resourceName) {
|
|
153
|
+
return _this.requestHandler.listAppMetadata(resourceName);
|
|
154
|
+
})
|
|
155
|
+
.then(function (responseData) {
|
|
156
|
+
return _this.getProjectId()
|
|
157
|
+
.then(function (projectId) {
|
|
158
|
+
return _this.transformResponseToAppMetadata(responseData, projectId);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Update the display name of this Firebase project.
|
|
164
|
+
*
|
|
165
|
+
* @param newDisplayName The new display name to be updated.
|
|
166
|
+
*
|
|
167
|
+
* @return A promise that resolves when the project display name has been updated.
|
|
168
|
+
*/
|
|
169
|
+
ProjectManagement.prototype.setDisplayName = function (newDisplayName) {
|
|
170
|
+
var _this = this;
|
|
171
|
+
return this.getResourceName()
|
|
172
|
+
.then(function (resourceName) {
|
|
173
|
+
return _this.requestHandler.setDisplayName(resourceName, newDisplayName);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
ProjectManagement.prototype.transformResponseToAppMetadata = function (responseData, projectId) {
|
|
177
|
+
this.assertListAppsResponseData(responseData, 'listAppMetadata()');
|
|
178
|
+
if (!responseData.apps) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
return responseData.apps.map(function (appJson) {
|
|
182
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonEmptyString(appJson.appId), responseData, '"apps[].appId" field must be present in the listAppMetadata() response data.');
|
|
183
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonEmptyString(appJson.platform), responseData, '"apps[].platform" field must be present in the listAppMetadata() response data.');
|
|
184
|
+
var metadata = {
|
|
185
|
+
appId: appJson.appId,
|
|
186
|
+
platform: AppPlatform[appJson.platform] || AppPlatform.PLATFORM_UNKNOWN,
|
|
187
|
+
projectId: projectId,
|
|
188
|
+
resourceName: appJson.name,
|
|
189
|
+
};
|
|
190
|
+
if (appJson.displayName) {
|
|
191
|
+
metadata.displayName = appJson.displayName;
|
|
192
|
+
}
|
|
193
|
+
return metadata;
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
ProjectManagement.prototype.getResourceName = function () {
|
|
197
|
+
return this.getProjectId()
|
|
198
|
+
.then(function (projectId) {
|
|
199
|
+
return "projects/" + projectId;
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
ProjectManagement.prototype.getProjectId = function () {
|
|
203
|
+
var _this = this;
|
|
204
|
+
if (this.projectId) {
|
|
205
|
+
return Promise.resolve(this.projectId);
|
|
206
|
+
}
|
|
207
|
+
return utils.findProjectId(this.app)
|
|
208
|
+
.then(function (projectId) {
|
|
209
|
+
// Assert that a specific project ID was provided within the app.
|
|
210
|
+
if (!validator.isNonEmptyString(projectId)) {
|
|
211
|
+
throw new error_1.FirebaseProjectManagementError('invalid-project-id', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
|
212
|
+
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
|
213
|
+
+ 'environment variable.');
|
|
214
|
+
}
|
|
215
|
+
_this.projectId = projectId;
|
|
216
|
+
return _this.projectId;
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Lists up to 100 Firebase apps for a specified platform, associated with this Firebase project.
|
|
221
|
+
*/
|
|
222
|
+
ProjectManagement.prototype.listPlatformApps = function (platform, callerName) {
|
|
223
|
+
var _this = this;
|
|
224
|
+
return this.getResourceName()
|
|
225
|
+
.then(function (resourceName) {
|
|
226
|
+
return (platform === 'android') ?
|
|
227
|
+
_this.requestHandler.listAndroidApps(resourceName)
|
|
228
|
+
: _this.requestHandler.listIosApps(resourceName);
|
|
229
|
+
})
|
|
230
|
+
.then(function (responseData) {
|
|
231
|
+
_this.assertListAppsResponseData(responseData, callerName);
|
|
232
|
+
if (!responseData.apps) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
return responseData.apps.map(function (appJson) {
|
|
236
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonEmptyString(appJson.appId), responseData, "\"apps[].appId\" field must be present in the " + callerName + " response data.");
|
|
237
|
+
if (platform === 'android') {
|
|
238
|
+
return new android_app_1.AndroidApp(appJson.appId, _this.requestHandler);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
return new ios_app_1.IosApp(appJson.appId, _this.requestHandler);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
ProjectManagement.prototype.assertListAppsResponseData = function (responseData, callerName) {
|
|
247
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isNonNullObject(responseData), responseData, callerName + "'s responseData must be a non-null object.");
|
|
248
|
+
if (responseData.apps) {
|
|
249
|
+
project_management_api_request_internal_1.assertServerResponse(validator.isArray(responseData.apps), responseData, "\"apps\" field must be present in the " + callerName + " response data.");
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return ProjectManagement;
|
|
253
|
+
}());
|
|
254
|
+
exports.ProjectManagement = ProjectManagement;
|