UNPKG

4.36 kBJavaScriptView Raw
1/*! firebase-admin v10.0.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 */
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.IosApp = void 0;
20var error_1 = require("../utils/error");
21var validator = require("../utils/validator");
22var project_management_api_request_internal_1 = require("./project-management-api-request-internal");
23var app_metadata_1 = require("./app-metadata");
24/**
25 * A reference to a Firebase iOS app.
26 *
27 * Do not call this constructor directly. Instead, use {@link ProjectManagement.iosApp}.
28 */
29var IosApp = /** @class */ (function () {
30 /**
31 * @internal
32 */
33 function IosApp(appId, requestHandler) {
34 this.appId = appId;
35 this.requestHandler = requestHandler;
36 if (!validator.isNonEmptyString(appId)) {
37 throw new error_1.FirebaseProjectManagementError('invalid-argument', 'appId must be a non-empty string.');
38 }
39 this.resourceName = "projects/-/iosApps/" + appId;
40 }
41 /**
42 * Retrieves metadata about this iOS app.
43 *
44 * @returns A promise that
45 * resolves to the retrieved metadata about this iOS app.
46 */
47 IosApp.prototype.getMetadata = function () {
48 return this.requestHandler.getResource(this.resourceName)
49 .then(function (responseData) {
50 project_management_api_request_internal_1.assertServerResponse(validator.isNonNullObject(responseData), responseData, 'getMetadata()\'s responseData must be a non-null object.');
51 var requiredFieldsList = ['name', 'appId', 'projectId', 'bundleId'];
52 requiredFieldsList.forEach(function (requiredField) {
53 project_management_api_request_internal_1.assertServerResponse(validator.isNonEmptyString(responseData[requiredField]), responseData, "getMetadata()'s responseData." + requiredField + " must be a non-empty string.");
54 });
55 var metadata = {
56 platform: app_metadata_1.AppPlatform.IOS,
57 resourceName: responseData.name,
58 appId: responseData.appId,
59 displayName: responseData.displayName || null,
60 projectId: responseData.projectId,
61 bundleId: responseData.bundleId,
62 };
63 return metadata;
64 });
65 };
66 /**
67 * Sets the optional user-assigned display name of the app.
68 *
69 * @param newDisplayName - The new display name to set.
70 *
71 * @returns A promise that resolves when the display name has
72 * been set.
73 */
74 IosApp.prototype.setDisplayName = function (newDisplayName) {
75 return this.requestHandler.setDisplayName(this.resourceName, newDisplayName);
76 };
77 /**
78 * Gets the configuration artifact associated with this app.
79 *
80 * @returns A promise that resolves to the iOS app's Firebase
81 * config file, in UTF-8 string format. This string is typically intended to
82 * be written to a plist file that gets shipped with your iOS app.
83 */
84 IosApp.prototype.getConfig = function () {
85 return this.requestHandler.getConfig(this.resourceName)
86 .then(function (responseData) {
87 project_management_api_request_internal_1.assertServerResponse(validator.isNonNullObject(responseData), responseData, 'getConfig()\'s responseData must be a non-null object.');
88 var base64ConfigFileContents = responseData.configFileContents;
89 project_management_api_request_internal_1.assertServerResponse(validator.isBase64String(base64ConfigFileContents), responseData, 'getConfig()\'s responseData.configFileContents must be a base64 string.');
90 return Buffer.from(base64ConfigFileContents, 'base64').toString('utf8');
91 });
92 };
93 return IosApp;
94}());
95exports.IosApp = IosApp;