ios-app.js 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*! firebase-admin v12.1.1 */
  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.IosApp = void 0;
  20. const error_1 = require("../utils/error");
  21. const validator = require("../utils/validator");
  22. const project_management_api_request_internal_1 = require("./project-management-api-request-internal");
  23. const 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. */
  29. class IosApp {
  30. /**
  31. * @internal
  32. */
  33. constructor(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. getMetadata() {
  48. return this.requestHandler.getResource(this.resourceName)
  49. .then((responseData) => {
  50. (0, project_management_api_request_internal_1.assertServerResponse)(validator.isNonNullObject(responseData), responseData, 'getMetadata()\'s responseData must be a non-null object.');
  51. const requiredFieldsList = ['name', 'appId', 'projectId', 'bundleId'];
  52. requiredFieldsList.forEach((requiredField) => {
  53. (0, project_management_api_request_internal_1.assertServerResponse)(validator.isNonEmptyString(responseData[requiredField]), responseData, `getMetadata()'s responseData.${requiredField} must be a non-empty string.`);
  54. });
  55. const 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. setDisplayName(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. getConfig() {
  85. return this.requestHandler.getConfig(this.resourceName)
  86. .then((responseData) => {
  87. (0, project_management_api_request_internal_1.assertServerResponse)(validator.isNonNullObject(responseData), responseData, 'getConfig()\'s responseData must be a non-null object.');
  88. const base64ConfigFileContents = responseData.configFileContents;
  89. (0, 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. }
  94. exports.IosApp = IosApp;