1
1
/*!
2
2
* @license
3
- * Copyright 2017 Google Inc.
3
+ * Copyright 2021 Google Inc.
4
4
*
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
16
16
*/
17
17
18
18
import { FirebaseApp } from '../firebase-app' ;
19
- import { FirebaseInstanceIdError , InstanceIdClientErrorCode } from '../utils/error' ;
19
+ import { FirebaseInstallationsError , InstallationsClientErrorCode } from '../utils/error' ;
20
20
import {
21
21
ApiSettings , AuthorizedHttpClient , HttpRequestConfig , HttpError ,
22
22
} from '../utils/api-request' ;
@@ -33,50 +33,50 @@ const FIREBASE_IID_TIMEOUT = 10000;
33
33
34
34
/** HTTP error codes raised by the backend server. */
35
35
const ERROR_CODES : { [ key : number ] : string } = {
36
- 400 : 'Malformed instance ID argument.' ,
36
+ 400 : 'Malformed installation ID argument.' ,
37
37
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.' ,
40
40
409 : 'Already deleted.' ,
41
41
429 : 'Request throttled out by the backend server.' ,
42
42
500 : 'Internal server error.' ,
43
43
503 : 'Backend servers are over capacity. Try again later.' ,
44
44
} ;
45
45
46
46
/**
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.
48
48
*/
49
- export class FirebaseInstanceIdRequestHandler {
49
+ export class FirebaseInstallationsRequestHandler {
50
50
51
51
private readonly host : string = FIREBASE_IID_HOST ;
52
52
private readonly timeout : number = FIREBASE_IID_TIMEOUT ;
53
53
private readonly httpClient : AuthorizedHttpClient ;
54
54
private path : string ;
55
55
56
56
/**
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.
58
58
*
59
59
* @constructor
60
60
*/
61
61
constructor ( private readonly app : FirebaseApp ) {
62
62
this . httpClient = new AuthorizedHttpClient ( app ) ;
63
63
}
64
64
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.' ,
70
70
) ) ;
71
71
}
72
- return this . invokeRequestHandler ( new ApiSettings ( instanceId , 'DELETE' ) ) ;
72
+ return this . invokeRequestHandler ( new ApiSettings ( fid , 'DELETE' ) ) ;
73
73
}
74
74
75
75
/**
76
76
* Invokes the request handler based on the API settings object passed.
77
77
*
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.
80
80
*/
81
81
private invokeRequestHandler ( apiSettings : ApiSettings ) : Promise < void > {
82
82
return this . getPathPrefix ( )
@@ -98,8 +98,8 @@ export class FirebaseInstanceIdRequestHandler {
98
98
response . data . error : response . text ;
99
99
const template : string = ERROR_CODES [ response . status ] ;
100
100
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 ) ;
103
103
}
104
104
// In case of timeouts and other network errors, the HttpClient returns a
105
105
// FirebaseError wrapped in the response. Simply throw it here.
@@ -116,9 +116,9 @@ export class FirebaseInstanceIdRequestHandler {
116
116
. then ( ( projectId ) => {
117
117
if ( ! validator . isNonEmptyString ( projectId ) ) {
118
118
// 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 '
122
122
+ 'SDK with service account credentials or set project ID as an app option. '
123
123
+ 'Alternatively set the GOOGLE_CLOUD_PROJECT environment variable.' ,
124
124
) ;
0 commit comments