Skip to content

feat(auth): Modularized firebase-admin/auth API entrypoint #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
891 changes: 563 additions & 328 deletions etc/firebase-admin.api.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ gulp.task('compile', function() {
'lib/firebase-namespace-api.d.ts',
'lib/core.d.ts',
'lib/app/*.d.ts',
'lib/auth/*.d.ts',
'lib/instance-id/*.d.ts',
'!lib/utils/index.d.ts',
];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"lint:test": "eslint test/ --ext .ts",
"apidocs": "node docgen/generate-docs.js --api node",
"api-extractor": "api-extractor run",
"api-extractor:local": "api-extractor run --local"
"api-extractor:local": "npm run build && api-extractor run --local"
},
"nyc": {
"extension": [
Expand Down
6 changes: 2 additions & 4 deletions src/app/firebase-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,8 @@ export class FirebaseApp implements app.App {
* @return The Auth service instance of this app.
*/
public auth(): Auth {
return this.ensureService_('auth', () => {
const authService: typeof Auth = require('../auth/auth').Auth;
return new authService(this);
});
const fn = require('../auth/index').auth;
return fn(this);
}

/**
Expand Down
98 changes: 89 additions & 9 deletions src/auth/action-code-settings-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,87 @@

import * as validator from '../utils/validator';
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
import { auth } from './index';

import ActionCodeSettings = auth.ActionCodeSettings;
/**
* This is the interface that defines the required continue/state URL with
* optional Android and iOS bundle identifiers.
*/
export interface ActionCodeSettings {

/**
* Defines the link continue/state URL, which has different meanings in
* different contexts:
* <ul>
* <li>When the link is handled in the web action widgets, this is the deep
* link in the `continueUrl` query parameter.</li>
* <li>When the link is handled in the app directly, this is the `continueUrl`
* query parameter in the deep link of the Dynamic Link.</li>
* </ul>
*/
url: string;

/**
* Whether to open the link via a mobile app or a browser.
* The default is false. When set to true, the action code link is sent
* as a Universal Link or Android App Link and is opened by the app if
* installed. In the false case, the code is sent to the web widget first
* and then redirects to the app if installed.
*/
handleCodeInApp?: boolean;

/**
* Defines the iOS bundle ID. This will try to open the link in an iOS app if it
* is installed.
*/
iOS?: {

/**
* Defines the required iOS bundle ID of the app where the link should be
* handled if the application is already installed on the device.
*/
bundleId: string;
};

/**
* Defines the Android package name. This will try to open the link in an
* android app if it is installed. If `installApp` is passed, it specifies
* whether to install the Android app if the device supports it and the app is
* not already installed. If this field is provided without a `packageName`, an
* error is thrown explaining that the `packageName` must be provided in
* conjunction with this field. If `minimumVersion` is specified, and an older
* version of the app is installed, the user is taken to the Play Store to
* upgrade the app.
*/
android?: {

/**
* Defines the required Android package name of the app where the link should be
* handled if the Android app is installed.
*/
packageName: string;

/**
* Whether to install the Android app if the device supports it and the app is
* not already installed.
*/
installApp?: boolean;

/**
* The Android minimum version if available. If the installed app is an older
* version, the user is taken to the GOogle Play Store to upgrade the app.
*/
minimumVersion?: string;
};

/**
* Defines the dynamic link domain to use for the current link if it is to be
* opened using Firebase Dynamic Links, as multiple dynamic link domains can be
* configured per project. This field provides the ability to explicitly choose
* configured per project. This fields provides the ability explicitly choose
* one. If none is provided, the oldest domain is used by default.
*/
dynamicLinkDomain?: string;
}

/** Defines the email action code server request. */
interface EmailActionCodeRequest {
Expand All @@ -34,6 +112,8 @@ interface EmailActionCodeRequest {
/**
* Defines the ActionCodeSettings builder class used to convert the
* ActionCodeSettings object to its corresponding server request.
*
* @internal
*/
export class ActionCodeSettingsBuilder {
private continueUrl?: string;
Expand Down Expand Up @@ -70,7 +150,7 @@ export class ActionCodeSettingsBuilder {
this.continueUrl = actionCodeSettings.url;

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

if (typeof actionCodeSettings.dynamicLinkDomain !== 'undefined' &&
!validator.isNonEmptyString(actionCodeSettings.dynamicLinkDomain)) {
!validator.isNonEmptyString(actionCodeSettings.dynamicLinkDomain)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_DYNAMIC_LINK_DOMAIN,
);
}
this.dynamicLinkDomain = actionCodeSettings.dynamicLinkDomain;

if (typeof actionCodeSettings.iOS !== 'undefined') {
if (typeof actionCodeSettings.iOS !== 'undefined') {
if (!validator.isNonNullObject(actionCodeSettings.iOS)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT,
Expand All @@ -105,7 +185,7 @@ export class ActionCodeSettingsBuilder {
this.ibi = actionCodeSettings.iOS.bundleId;
}

if (typeof actionCodeSettings.android !== 'undefined') {
if (typeof actionCodeSettings.android !== 'undefined') {
if (!validator.isNonNullObject(actionCodeSettings.android)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT,
Expand All @@ -121,13 +201,13 @@ export class ActionCodeSettingsBuilder {
'"ActionCodeSettings.android.packageName" must be a valid non-empty string.',
);
} else if (typeof actionCodeSettings.android.minimumVersion !== 'undefined' &&
!validator.isNonEmptyString(actionCodeSettings.android.minimumVersion)) {
!validator.isNonEmptyString(actionCodeSettings.android.minimumVersion)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT,
'"ActionCodeSettings.android.minimumVersion" must be a valid non-empty string.',
);
} else if (typeof actionCodeSettings.android.installApp !== 'undefined' &&
!validator.isBoolean(actionCodeSettings.android.installApp)) {
!validator.isBoolean(actionCodeSettings.android.installApp)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT,
'"ActionCodeSettings.android.installApp" must be a valid boolean.',
Expand All @@ -146,7 +226,7 @@ export class ActionCodeSettingsBuilder {
* @return {EmailActionCodeRequest} The constructed EmailActionCodeRequest request.
*/
public buildRequest(): EmailActionCodeRequest {
const request: {[key: string]: any} = {
const request: { [key: string]: any } = {
continueUrl: this.continueUrl,
canHandleCodeInApp: this.canHandleCodeInApp,
dynamicLinkDomain: this.dynamicLinkDomain,
Expand Down
Loading