instance-id.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*! firebase-admin v12.1.1 */
  2. "use strict";
  3. /*!
  4. * Copyright 2020 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.InstanceId = void 0;
  20. const installations_1 = require("../installations");
  21. const error_1 = require("../utils/error");
  22. const validator = require("../utils/validator");
  23. /**
  24. * The `InstanceId` service enables deleting the Firebase instance IDs
  25. * associated with Firebase client app instances.
  26. *
  27. * @deprecated Use {@link firebase-admin.installations#Installations} instead.
  28. */
  29. class InstanceId {
  30. /**
  31. * @param app - The app for this InstanceId service.
  32. * @constructor
  33. * @internal
  34. */
  35. constructor(app) {
  36. if (!validator.isNonNullObject(app) || !('options' in app)) {
  37. throw new error_1.FirebaseInstanceIdError(error_1.InstanceIdClientErrorCode.INVALID_ARGUMENT, 'First argument passed to instanceId() must be a valid Firebase app instance.');
  38. }
  39. this.app_ = app;
  40. }
  41. /**
  42. * Deletes the specified instance ID and the associated data from Firebase.
  43. *
  44. * Note that Google Analytics for Firebase uses its own form of Instance ID to
  45. * keep track of analytics data. Therefore deleting a Firebase Instance ID does
  46. * not delete Analytics data. See
  47. * {@link https://firebase.google.com/support/privacy/manage-iids#delete_an_instance_id |
  48. * Delete an Instance ID}
  49. * for more information.
  50. *
  51. * @param instanceId - The instance ID to be deleted.
  52. *
  53. * @returns A promise fulfilled when the instance ID is deleted.
  54. */
  55. deleteInstanceId(instanceId) {
  56. return (0, installations_1.getInstallations)(this.app).deleteInstallation(instanceId)
  57. .catch((err) => {
  58. if (err instanceof error_1.FirebaseInstallationsError) {
  59. let code = err.code.replace('installations/', '');
  60. if (code === error_1.InstallationsClientErrorCode.INVALID_INSTALLATION_ID.code) {
  61. code = error_1.InstanceIdClientErrorCode.INVALID_INSTANCE_ID.code;
  62. }
  63. throw new error_1.FirebaseInstanceIdError({ code, message: err.message });
  64. }
  65. throw err;
  66. });
  67. }
  68. /**
  69. * Returns the app associated with this InstanceId instance.
  70. *
  71. * @returns The app associated with this InstanceId instance.
  72. */
  73. get app() {
  74. return this.app_;
  75. }
  76. }
  77. exports.InstanceId = InstanceId;