11/*!
22 * @license
3- * Copyright 2017 Google Inc.
3+ * Copyright 2021 Google Inc.
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
1616 */
1717
1818import { FirebaseApp } from '../firebase-app' ;
19- import { FirebaseInstanceIdError , InstanceIdClientErrorCode } from '../utils/error' ;
19+ import { FirebaseInstallationsError , InstallationsClientErrorCode } from '../utils/error' ;
2020import {
2121 ApiSettings , AuthorizedHttpClient , HttpRequestConfig , HttpError ,
2222} from '../utils/api-request' ;
@@ -33,50 +33,50 @@ const FIREBASE_IID_TIMEOUT = 10000;
3333
3434/** HTTP error codes raised by the backend server. */
3535const ERROR_CODES : { [ key : number ] : string } = {
36- 400 : 'Malformed instance ID argument.' ,
36+ 400 : 'Malformed installation ID argument.' ,
3737 401 : 'Request not authorized.' ,
38- 403 : 'Project does not match instance ID or the client does not have sufficient privileges.' ,
39- 404 : 'Failed to find the instance ID.' ,
38+ 403 : 'Project does not match installation ID or the client does not have sufficient privileges.' ,
39+ 404 : 'Failed to find the installation ID.' ,
4040 409 : 'Already deleted.' ,
4141 429 : 'Request throttled out by the backend server.' ,
4242 500 : 'Internal server error.' ,
4343 503 : 'Backend servers are over capacity. Try again later.' ,
4444} ;
4545
4646/**
47- * Class that provides mechanism to send requests to the Firebase Instance ID backend endpoints.
47+ * Class that provides mechanism to send requests to the FIS backend endpoints.
4848 */
49- export class FirebaseInstanceIdRequestHandler {
49+ export class FirebaseInstallationsRequestHandler {
5050
5151 private readonly host : string = FIREBASE_IID_HOST ;
5252 private readonly timeout : number = FIREBASE_IID_TIMEOUT ;
5353 private readonly httpClient : AuthorizedHttpClient ;
5454 private path : string ;
5555
5656 /**
57- * @param { FirebaseApp } app The app used to fetch access tokens to sign API requests.
57+ * @param app The app used to fetch access tokens to sign API requests.
5858 *
5959 * @constructor
6060 */
6161 constructor ( private readonly app : FirebaseApp ) {
6262 this . httpClient = new AuthorizedHttpClient ( app ) ;
6363 }
6464
65- public deleteInstanceId ( instanceId : string ) : Promise < void > {
66- if ( ! validator . isNonEmptyString ( instanceId ) ) {
67- return Promise . reject ( new FirebaseInstanceIdError (
68- InstanceIdClientErrorCode . INVALID_INSTANCE_ID ,
69- 'Instance ID must be a non-empty string.' ,
65+ public deleteInstallation ( fid : string ) : Promise < void > {
66+ if ( ! validator . isNonEmptyString ( fid ) ) {
67+ return Promise . reject ( new FirebaseInstallationsError (
68+ InstallationsClientErrorCode . INVALID_INSTALLATION_ID ,
69+ 'Installation ID must be a non-empty string.' ,
7070 ) ) ;
7171 }
72- return this . invokeRequestHandler ( new ApiSettings ( instanceId , 'DELETE' ) ) ;
72+ return this . invokeRequestHandler ( new ApiSettings ( fid , 'DELETE' ) ) ;
7373 }
7474
7575 /**
7676 * Invokes the request handler based on the API settings object passed.
7777 *
78- * @param { ApiSettings } apiSettings The API endpoint settings to apply to request and response.
79- * @return { Promise<void> } A promise that resolves when the request is complete.
78+ * @param apiSettings The API endpoint settings to apply to request and response.
79+ * @return A promise that resolves when the request is complete.
8080 */
8181 private invokeRequestHandler ( apiSettings : ApiSettings ) : Promise < void > {
8282 return this . getPathPrefix ( )
@@ -98,8 +98,8 @@ export class FirebaseInstanceIdRequestHandler {
9898 response . data . error : response . text ;
9999 const template : string = ERROR_CODES [ response . status ] ;
100100 const message : string = template ?
101- `Instance ID "${ apiSettings . getEndpoint ( ) } ": ${ template } ` : errorMessage ;
102- throw new FirebaseInstanceIdError ( InstanceIdClientErrorCode . API_ERROR , message ) ;
101+ `Installation ID "${ apiSettings . getEndpoint ( ) } ": ${ template } ` : errorMessage ;
102+ throw new FirebaseInstallationsError ( InstallationsClientErrorCode . API_ERROR , message ) ;
103103 }
104104 // In case of timeouts and other network errors, the HttpClient returns a
105105 // FirebaseError wrapped in the response. Simply throw it here.
@@ -116,9 +116,9 @@ export class FirebaseInstanceIdRequestHandler {
116116 . then ( ( projectId ) => {
117117 if ( ! validator . isNonEmptyString ( projectId ) ) {
118118 // Assert for an explicit projct ID (either via AppOptions or the cert itself).
119- throw new FirebaseInstanceIdError (
120- InstanceIdClientErrorCode . INVALID_PROJECT_ID ,
121- 'Failed to determine project ID for InstanceId . Initialize the '
119+ throw new FirebaseInstallationsError (
120+ InstallationsClientErrorCode . INVALID_PROJECT_ID ,
121+ 'Failed to determine project ID for Installations . Initialize the '
122122 + 'SDK with service account credentials or set project ID as an app option. '
123123 + 'Alternatively set the GOOGLE_CLOUD_PROJECT environment variable.' ,
124124 ) ;
0 commit comments