Skip to content

Commit aef6bc4

Browse files
authored
Allow project-management to auto-generate typings, separate internal vs external APIs (#971)
* Allow project-management to auto-generate typings, separate internal vs external APIs (#971)
1 parent 646d90f commit aef6bc4

File tree

11 files changed

+296
-26
lines changed

11 files changed

+296
-26
lines changed

gulpfile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ var paths = {
5252

5353
build: 'lib/',
5454

55-
curatedTypings: ['src/*.d.ts', '!src/instance-id.d.ts'],
55+
curatedTypings: [
56+
'src/*.d.ts',
57+
'!src/instance-id.d.ts',
58+
'!src/project-management.d.ts'
59+
],
5660
};
5761

5862
const TEMPORARY_TYPING_EXCLUDES = [
@@ -65,7 +69,6 @@ const TEMPORARY_TYPING_EXCLUDES = [
6569
'!lib/firestore/*.d.ts',
6670
'!lib/machine-learning/*.d.ts',
6771
'!lib/messaging/*.d.ts',
68-
'!lib/project-management/*.d.ts',
6972
'!lib/remote-config/*.d.ts',
7073
'!lib/security-rules/*.d.ts',
7174
'!lib/storage/*.d.ts',

src/project-management/android-app.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { FirebaseProjectManagementError } from '../utils/error';
1818
import * as validator from '../utils/validator';
19-
import { ProjectManagementRequestHandler, assertServerResponse } from './project-management-api-request';
19+
import { ProjectManagementRequestHandler, assertServerResponse } from './project-management-api-request-internal';
2020
import { AndroidAppMetadata, AppPlatform } from './app-metadata';
2121

2222
export class AndroidApp {
@@ -33,6 +33,11 @@ export class AndroidApp {
3333
this.resourceName = `projects/-/androidApps/${appId}`;
3434
}
3535

36+
/**
37+
* Retrieves metadata about this Android app.
38+
*
39+
* @return A promise that resolves to the retrieved metadata about this Android app.
40+
*/
3641
public getMetadata(): Promise<AndroidAppMetadata> {
3742
return this.requestHandler.getResource(this.resourceName)
3843
.then((responseData: any) => {
@@ -61,10 +66,23 @@ export class AndroidApp {
6166
});
6267
}
6368

69+
/**
70+
* Sets the optional user-assigned display name of the app.
71+
*
72+
* @param newDisplayName The new display name to set.
73+
*
74+
* @return A promise that resolves when the display name has been set.
75+
*/
6476
public setDisplayName(newDisplayName: string): Promise<void> {
6577
return this.requestHandler.setDisplayName(this.resourceName, newDisplayName);
6678
}
6779

80+
/**
81+
* Gets the list of SHA certificates associated with this Android app in Firebase.
82+
*
83+
* @return The list of SHA-1 and SHA-256 certificates associated with this Android app in
84+
* Firebase.
85+
*/
6886
public getShaCertificates(): Promise<ShaCertificate[]> {
6987
return this.requestHandler.getAndroidShaCertificates(this.resourceName)
7088
.then((responseData: any) => {
@@ -98,10 +116,26 @@ export class AndroidApp {
98116
});
99117
}
100118

119+
/**
120+
* Adds the given SHA certificate to this Android app.
121+
*
122+
* @param certificateToAdd The SHA certificate to add.
123+
*
124+
* @return A promise that resolves when the given certificate
125+
* has been added to the Android app.
126+
*/
101127
public addShaCertificate(certificateToAdd: ShaCertificate): Promise<void> {
102128
return this.requestHandler.addAndroidShaCertificate(this.resourceName, certificateToAdd);
103129
}
104130

131+
/**
132+
* Deletes the specified SHA certificate from this Android app.
133+
*
134+
* @param certificateToDelete The SHA certificate to delete.
135+
*
136+
* @return A promise that resolves when the specified
137+
* certificate has been removed from the Android app.
138+
*/
105139
public deleteShaCertificate(certificateToDelete: ShaCertificate): Promise<void> {
106140
if (!certificateToDelete.resourceName) {
107141
throw new FirebaseProjectManagementError(
@@ -113,8 +147,12 @@ export class AndroidApp {
113147
}
114148

115149
/**
116-
* @return {Promise<string>} A promise that resolves to a UTF-8 JSON string, typically intended to
117-
* be written to a JSON file.
150+
* Gets the configuration artifact associated with this app.
151+
*
152+
* @return A promise that resolves to the Android app's
153+
* Firebase config file, in UTF-8 string format. This string is typically
154+
* intended to be written to a JSON file that gets shipped with your Android
155+
* app.
118156
*/
119157
public getConfig(): Promise<string> {
120158
return this.requestHandler.getConfig(this.resourceName)
@@ -135,16 +173,38 @@ export class AndroidApp {
135173
}
136174
}
137175

176+
/**
177+
* A SHA-1 or SHA-256 certificate.
178+
*
179+
* Do not call this constructor directly. Instead, use
180+
* [`projectManagement.shaCertificate()`](admin.projectManagement.ProjectManagement#shaCertificate).
181+
*/
138182
export class ShaCertificate {
183+
/**
184+
* The SHA certificate type.
185+
*
186+
* @example
187+
* ```javascript
188+
* var certType = shaCertificate.certType;
189+
* ```
190+
*/
139191
public readonly certType: ('sha1' | 'sha256');
140192

141193
/**
142194
* Creates a ShaCertificate using the given hash. The ShaCertificate's type (eg. 'sha256') is
143195
* automatically determined from the hash itself.
144196
*
145197
* @param shaHash The sha256 or sha1 hash for this certificate.
198+
* @example
199+
* ```javascript
200+
* var shaHash = shaCertificate.shaHash;
201+
* ```
146202
* @param resourceName The Firebase resource name for this certificate. This does not need to be
147203
* set when creating a new certificate.
204+
* @example
205+
* ```javascript
206+
* var resourceName = shaCertificate.resourceName;
207+
* ```
148208
*/
149209
constructor(public readonly shaHash: string, public readonly resourceName?: string) {
150210
if (/^[a-fA-F0-9]{40}$/.test(shaHash)) {

src/project-management/app-metadata.ts

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,117 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* Platforms with which a Firebase App can be associated.
19+
*/
1720
export enum AppPlatform {
21+
22+
/**
23+
* Unknown state. This is only used for distinguishing unset values.
24+
*/
1825
PLATFORM_UNKNOWN = 'PLATFORM_UNKNOWN',
26+
27+
/**
28+
* The Firebase App is associated with iOS.
29+
*/
1930
IOS = 'IOS',
31+
32+
/**
33+
* The Firebase App is associated with Android.
34+
*/
2035
ANDROID = 'ANDROID',
2136
}
2237

38+
/**
39+
* Metadata about a Firebase app.
40+
*/
2341
export interface AppMetadata {
42+
43+
/**
44+
* The globally unique, Firebase-assigned identifier of the app.
45+
*
46+
* @example
47+
* ```javascript
48+
* var appId = appMetadata.appId;
49+
* ```
50+
*/
2451
appId: string;
52+
53+
/**
54+
* The optional user-assigned display name of the app.
55+
*
56+
* @example
57+
* ```javascript
58+
* var displayName = appMetadata.displayName;
59+
* ```
60+
*/
2561
displayName?: string;
62+
63+
/**
64+
* The development platform of the app. Supporting Android and iOS app platforms.
65+
*
66+
* @example
67+
* ```javascript
68+
* var platform = AppPlatform.ANDROID;
69+
* ```
70+
*/
2671
platform: AppPlatform;
72+
73+
/**
74+
* The globally unique, user-assigned ID of the parent project for the app.
75+
*
76+
* @example
77+
* ```javascript
78+
* var projectId = appMetadata.projectId;
79+
* ```
80+
*/
2781
projectId: string;
28-
resourceName: string;
29-
}
3082

31-
export interface AndroidAppMetadata extends AppMetadata {
32-
platform: AppPlatform.ANDROID;
33-
packageName: string;
83+
/**
84+
* The fully-qualified resource name that identifies this app.
85+
*
86+
* This is useful when manually constructing requests for Firebase's public API.
87+
*
88+
* @example
89+
* ```javascript
90+
* var resourceName = androidAppMetadata.resourceName;
91+
* ```
92+
*/
93+
resourceName: string;
3494
}
3595

96+
/**
97+
* Metadata about a Firebase iOS App.
98+
*/
3699
export interface IosAppMetadata extends AppMetadata {
37100
platform: AppPlatform.IOS;
101+
102+
/**
103+
* The canonical bundle ID of the iOS App as it would appear in the iOS App Store.
104+
*
105+
* @example
106+
* ```javascript
107+
* var bundleId = iosAppMetadata.bundleId;
108+
*```
109+
*/
38110
bundleId: string;
39111
}
112+
113+
/**
114+
* Metadata about a Firebase Android App.
115+
*/
116+
export interface AndroidAppMetadata extends AppMetadata {
117+
118+
platform: AppPlatform.ANDROID;
119+
120+
/**
121+
* The canonical package name of the Android App, as would appear in the Google Play Developer
122+
* Console.
123+
*
124+
* @example
125+
* ```javascript
126+
* var packageName = androidAppMetadata.packageName;
127+
* ```
128+
*/
129+
packageName: string;
130+
}

src/project-management/index.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*!
2+
* Copyright 2020 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { FirebaseApp } from '../firebase-app';
18+
import * as androidAppApi from './android-app';
19+
import * as appMetadataApi from './app-metadata';
20+
import * as iosAppApi from './ios-app';
21+
import * as projectManagementApi from './project-management';
22+
import * as firebaseAdmin from '../index';
23+
24+
export function projectManagement(app?: FirebaseApp): projectManagementApi.ProjectManagement {
25+
if (typeof(app) === 'undefined') {
26+
app = firebaseAdmin.app();
27+
}
28+
return app.projectManagement();
29+
}
30+
31+
/**
32+
* We must define a namespace to make the typings work correctly. Otherwise
33+
* `admin.projectManagement()` cannot be called like a function. Temporarily,
34+
* admin.projectManagement is used as the namespace name because we cannot barrel
35+
* re-export the contents from instance-id, and we want it to
36+
* match the namespacing in the re-export inside src/index.d.ts
37+
*/
38+
/* eslint-disable @typescript-eslint/no-namespace */
39+
export namespace admin.projectManagement {
40+
// See https://github.com/microsoft/TypeScript/issues/4336
41+
/* eslint-disable @typescript-eslint/no-unused-vars */
42+
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
43+
export import AndroidAppMetadata = appMetadataApi.AndroidAppMetadata
44+
export import AppMetadata = appMetadataApi.AppMetadata
45+
export import AppPlatform = appMetadataApi.AppPlatform
46+
export import IosAppMetadata = appMetadataApi.IosAppMetadata
47+
48+
// Allows for exposing classes as interfaces in typings
49+
/* eslint-disable @typescript-eslint/no-empty-interface */
50+
export interface AndroidApp extends androidAppApi.AndroidApp {}
51+
export interface IosApp extends iosAppApi.IosApp {}
52+
export interface ProjectManagement extends projectManagementApi.ProjectManagement {}
53+
export interface ShaCertificate extends androidAppApi.ShaCertificate {}
54+
}

src/project-management/ios-app.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { FirebaseProjectManagementError } from '../utils/error';
1818
import * as validator from '../utils/validator';
19-
import { ProjectManagementRequestHandler, assertServerResponse } from './project-management-api-request';
19+
import { ProjectManagementRequestHandler, assertServerResponse } from './project-management-api-request-internal';
2020
import { IosAppMetadata, AppPlatform } from './app-metadata';
2121

2222
export class IosApp {
@@ -33,6 +33,12 @@ export class IosApp {
3333
this.resourceName = `projects/-/iosApps/${appId}`;
3434
}
3535

36+
/**
37+
* Retrieves metadata about this iOS app.
38+
*
39+
* @return {!Promise<admin.projectManagement.IosAppMetadata>} A promise that
40+
* resolves to the retrieved metadata about this iOS app.
41+
*/
3642
public getMetadata(): Promise<IosAppMetadata> {
3743
return this.requestHandler.getResource(this.resourceName)
3844
.then((responseData: any) => {
@@ -61,13 +67,24 @@ export class IosApp {
6167
});
6268
}
6369

70+
/**
71+
* Sets the optional user-assigned display name of the app.
72+
*
73+
* @param newDisplayName The new display name to set.
74+
*
75+
* @return A promise that resolves when the display name has
76+
* been set.
77+
*/
6478
public setDisplayName(newDisplayName: string): Promise<void> {
6579
return this.requestHandler.setDisplayName(this.resourceName, newDisplayName);
6680
}
6781

6882
/**
69-
* @return {Promise<string>} A promise that resolves to a UTF-8 XML string, typically intended to
70-
* be written to a plist file.
83+
* Gets the configuration artifact associated with this app.
84+
*
85+
* @return A promise that resolves to the iOS app's Firebase
86+
* config file, in UTF-8 string format. This string is typically intended to
87+
* be written to a plist file that gets shipped with your iOS app.
7188
*/
7289
public getConfig(): Promise<string> {
7390
return this.requestHandler.getConfig(this.resourceName)

0 commit comments

Comments
 (0)