Skip to content

Commit 8d16ac0

Browse files
authored
feat(auth): Modularized firebase-admin/auth API entrypoint (#1140)
* feat(auth): Modularized firebase-admin/auth API entrypoint * fix(auth): Rearranged imports/exports alphabetically * fix: Fixed indentation; Using trailing underscore for private members
1 parent d754b94 commit 8d16ac0

25 files changed

+2949
-3365
lines changed

etc/firebase-admin.api.md

Lines changed: 563 additions & 328 deletions
Large diffs are not rendered by default.

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ gulp.task('compile', function() {
8888
'lib/firebase-namespace-api.d.ts',
8989
'lib/core.d.ts',
9090
'lib/app/*.d.ts',
91+
'lib/auth/*.d.ts',
9192
'lib/instance-id/*.d.ts',
9293
'!lib/utils/index.d.ts',
9394
];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint:test": "eslint test/ --ext .ts",
2323
"apidocs": "node docgen/generate-docs.js --api node",
2424
"api-extractor": "api-extractor run",
25-
"api-extractor:local": "api-extractor run --local"
25+
"api-extractor:local": "npm run build && api-extractor run --local"
2626
},
2727
"nyc": {
2828
"extension": [

src/app/firebase-app.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,8 @@ export class FirebaseApp implements app.App {
277277
* @return The Auth service instance of this app.
278278
*/
279279
public auth(): Auth {
280-
return this.ensureService_('auth', () => {
281-
const authService: typeof Auth = require('../auth/auth').Auth;
282-
return new authService(this);
283-
});
280+
const fn = require('../auth/index').auth;
281+
return fn(this);
284282
}
285283

286284
/**

src/auth/action-code-settings-builder.ts

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,87 @@
1616

1717
import * as validator from '../utils/validator';
1818
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
19-
import { auth } from './index';
2019

21-
import ActionCodeSettings = auth.ActionCodeSettings;
20+
/**
21+
* This is the interface that defines the required continue/state URL with
22+
* optional Android and iOS bundle identifiers.
23+
*/
24+
export interface ActionCodeSettings {
25+
26+
/**
27+
* Defines the link continue/state URL, which has different meanings in
28+
* different contexts:
29+
* <ul>
30+
* <li>When the link is handled in the web action widgets, this is the deep
31+
* link in the `continueUrl` query parameter.</li>
32+
* <li>When the link is handled in the app directly, this is the `continueUrl`
33+
* query parameter in the deep link of the Dynamic Link.</li>
34+
* </ul>
35+
*/
36+
url: string;
37+
38+
/**
39+
* Whether to open the link via a mobile app or a browser.
40+
* The default is false. When set to true, the action code link is sent
41+
* as a Universal Link or Android App Link and is opened by the app if
42+
* installed. In the false case, the code is sent to the web widget first
43+
* and then redirects to the app if installed.
44+
*/
45+
handleCodeInApp?: boolean;
46+
47+
/**
48+
* Defines the iOS bundle ID. This will try to open the link in an iOS app if it
49+
* is installed.
50+
*/
51+
iOS?: {
52+
53+
/**
54+
* Defines the required iOS bundle ID of the app where the link should be
55+
* handled if the application is already installed on the device.
56+
*/
57+
bundleId: string;
58+
};
59+
60+
/**
61+
* Defines the Android package name. This will try to open the link in an
62+
* android app if it is installed. If `installApp` is passed, it specifies
63+
* whether to install the Android app if the device supports it and the app is
64+
* not already installed. If this field is provided without a `packageName`, an
65+
* error is thrown explaining that the `packageName` must be provided in
66+
* conjunction with this field. If `minimumVersion` is specified, and an older
67+
* version of the app is installed, the user is taken to the Play Store to
68+
* upgrade the app.
69+
*/
70+
android?: {
71+
72+
/**
73+
* Defines the required Android package name of the app where the link should be
74+
* handled if the Android app is installed.
75+
*/
76+
packageName: string;
77+
78+
/**
79+
* Whether to install the Android app if the device supports it and the app is
80+
* not already installed.
81+
*/
82+
installApp?: boolean;
83+
84+
/**
85+
* The Android minimum version if available. If the installed app is an older
86+
* version, the user is taken to the GOogle Play Store to upgrade the app.
87+
*/
88+
minimumVersion?: string;
89+
};
90+
91+
/**
92+
* Defines the dynamic link domain to use for the current link if it is to be
93+
* opened using Firebase Dynamic Links, as multiple dynamic link domains can be
94+
* configured per project. This field provides the ability to explicitly choose
95+
* configured per project. This fields provides the ability explicitly choose
96+
* one. If none is provided, the oldest domain is used by default.
97+
*/
98+
dynamicLinkDomain?: string;
99+
}
22100

23101
/** Defines the email action code server request. */
24102
interface EmailActionCodeRequest {
@@ -34,6 +112,8 @@ interface EmailActionCodeRequest {
34112
/**
35113
* Defines the ActionCodeSettings builder class used to convert the
36114
* ActionCodeSettings object to its corresponding server request.
115+
*
116+
* @internal
37117
*/
38118
export class ActionCodeSettingsBuilder {
39119
private continueUrl?: string;
@@ -70,7 +150,7 @@ export class ActionCodeSettingsBuilder {
70150
this.continueUrl = actionCodeSettings.url;
71151

72152
if (typeof actionCodeSettings.handleCodeInApp !== 'undefined' &&
73-
!validator.isBoolean(actionCodeSettings.handleCodeInApp)) {
153+
!validator.isBoolean(actionCodeSettings.handleCodeInApp)) {
74154
throw new FirebaseAuthError(
75155
AuthClientErrorCode.INVALID_ARGUMENT,
76156
'"ActionCodeSettings.handleCodeInApp" must be a boolean.',
@@ -79,14 +159,14 @@ export class ActionCodeSettingsBuilder {
79159
this.canHandleCodeInApp = actionCodeSettings.handleCodeInApp || false;
80160

81161
if (typeof actionCodeSettings.dynamicLinkDomain !== 'undefined' &&
82-
!validator.isNonEmptyString(actionCodeSettings.dynamicLinkDomain)) {
162+
!validator.isNonEmptyString(actionCodeSettings.dynamicLinkDomain)) {
83163
throw new FirebaseAuthError(
84164
AuthClientErrorCode.INVALID_DYNAMIC_LINK_DOMAIN,
85165
);
86166
}
87167
this.dynamicLinkDomain = actionCodeSettings.dynamicLinkDomain;
88168

89-
if (typeof actionCodeSettings.iOS !== 'undefined') {
169+
if (typeof actionCodeSettings.iOS !== 'undefined') {
90170
if (!validator.isNonNullObject(actionCodeSettings.iOS)) {
91171
throw new FirebaseAuthError(
92172
AuthClientErrorCode.INVALID_ARGUMENT,
@@ -105,7 +185,7 @@ export class ActionCodeSettingsBuilder {
105185
this.ibi = actionCodeSettings.iOS.bundleId;
106186
}
107187

108-
if (typeof actionCodeSettings.android !== 'undefined') {
188+
if (typeof actionCodeSettings.android !== 'undefined') {
109189
if (!validator.isNonNullObject(actionCodeSettings.android)) {
110190
throw new FirebaseAuthError(
111191
AuthClientErrorCode.INVALID_ARGUMENT,
@@ -121,13 +201,13 @@ export class ActionCodeSettingsBuilder {
121201
'"ActionCodeSettings.android.packageName" must be a valid non-empty string.',
122202
);
123203
} else if (typeof actionCodeSettings.android.minimumVersion !== 'undefined' &&
124-
!validator.isNonEmptyString(actionCodeSettings.android.minimumVersion)) {
204+
!validator.isNonEmptyString(actionCodeSettings.android.minimumVersion)) {
125205
throw new FirebaseAuthError(
126206
AuthClientErrorCode.INVALID_ARGUMENT,
127207
'"ActionCodeSettings.android.minimumVersion" must be a valid non-empty string.',
128208
);
129209
} else if (typeof actionCodeSettings.android.installApp !== 'undefined' &&
130-
!validator.isBoolean(actionCodeSettings.android.installApp)) {
210+
!validator.isBoolean(actionCodeSettings.android.installApp)) {
131211
throw new FirebaseAuthError(
132212
AuthClientErrorCode.INVALID_ARGUMENT,
133213
'"ActionCodeSettings.android.installApp" must be a valid boolean.',
@@ -146,7 +226,7 @@ export class ActionCodeSettingsBuilder {
146226
* @return {EmailActionCodeRequest} The constructed EmailActionCodeRequest request.
147227
*/
148228
public buildRequest(): EmailActionCodeRequest {
149-
const request: {[key: string]: any} = {
229+
const request: { [key: string]: any } = {
150230
continueUrl: this.continueUrl,
151231
canHandleCodeInApp: this.canHandleCodeInApp,
152232
dynamicLinkDomain: this.dynamicLinkDomain,

0 commit comments

Comments
 (0)