@causa/workspace-google 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/firebase-auth.json +12 -0
- package/dist/assets/firebase-storage.json +15 -0
- package/dist/cli/google-app-check.d.ts +5 -0
- package/dist/cli/google-app-check.js +9 -0
- package/dist/cli/google-identity-platform.d.ts +5 -0
- package/dist/cli/google-identity-platform.js +9 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/configurations/google.d.ts +15 -8
- package/dist/configurations/index.d.ts +1 -0
- package/dist/configurations/index.js +1 -1
- package/dist/configurations/utils.d.ts +10 -0
- package/dist/configurations/utils.js +17 -0
- package/dist/emulators/firebase-storage.d.ts +20 -0
- package/dist/emulators/firebase-storage.js +27 -0
- package/dist/emulators/firestore.d.ts +20 -0
- package/dist/emulators/firestore.js +27 -0
- package/dist/emulators/identity-platform.d.ts +16 -0
- package/dist/emulators/identity-platform.js +23 -0
- package/dist/emulators/index.d.ts +5 -0
- package/dist/emulators/index.js +5 -0
- package/dist/emulators/pubsub.d.ts +25 -0
- package/dist/emulators/pubsub.js +35 -0
- package/dist/emulators/spanner.d.ts +24 -0
- package/dist/emulators/spanner.js +31 -0
- package/dist/functions/emulator-start-firebase-storage.d.ts +17 -0
- package/dist/functions/emulator-start-firebase-storage.js +64 -0
- package/dist/functions/emulator-start-firestore.d.ts +17 -0
- package/dist/functions/emulator-start-firestore.js +58 -0
- package/dist/functions/emulator-start-identity-platform.d.ts +16 -0
- package/dist/functions/emulator-start-identity-platform.js +49 -0
- package/dist/functions/emulator-start-pubsub.d.ts +33 -0
- package/dist/functions/emulator-start-pubsub.js +86 -0
- package/dist/functions/emulator-start-spanner.d.ts +40 -0
- package/dist/functions/emulator-start-spanner.js +112 -0
- package/dist/functions/emulator-stop-firebase-storage.d.ts +9 -0
- package/dist/functions/emulator-stop-firebase-storage.js +17 -0
- package/dist/functions/emulator-stop-firestore.d.ts +9 -0
- package/dist/functions/emulator-stop-firestore.js +17 -0
- package/dist/functions/emulator-stop-identity-platform.d.ts +9 -0
- package/dist/functions/emulator-stop-identity-platform.js +17 -0
- package/dist/functions/emulator-stop-pubsub.d.ts +9 -0
- package/dist/functions/emulator-stop-pubsub.js +17 -0
- package/dist/functions/emulator-stop-spanner.d.ts +9 -0
- package/dist/functions/emulator-stop-spanner.js +17 -0
- package/dist/functions/google-app-check-generate-token.d.ts +13 -0
- package/dist/functions/google-app-check-generate-token.js +67 -0
- package/dist/functions/google-identity-platform-generate-custom-token.d.ts +20 -0
- package/dist/functions/google-identity-platform-generate-custom-token.js +49 -0
- package/dist/functions/google-identity-platform-generate-token.d.ts +18 -0
- package/dist/functions/google-identity-platform-generate-token.js +74 -0
- package/dist/functions/google-spanner-list-databases.d.ts +33 -0
- package/dist/functions/google-spanner-list-databases.js +66 -0
- package/dist/functions/index.js +16 -1
- package/dist/functions/project-get-artefact-destination-service-container.d.ts +10 -0
- package/dist/functions/project-get-artefact-destination-service-container.js +17 -0
- package/dist/services/firebase-app.d.ts +151 -0
- package/dist/services/firebase-app.errors.d.ts +26 -0
- package/dist/services/firebase-app.errors.js +35 -0
- package/dist/services/firebase-app.js +286 -0
- package/dist/services/firebase-emulator.d.ts +35 -0
- package/dist/services/firebase-emulator.js +65 -0
- package/dist/services/gcloud-emulator.d.ts +55 -0
- package/dist/services/gcloud-emulator.js +66 -0
- package/dist/services/google-apis.d.ts +34 -0
- package/dist/services/google-apis.js +48 -0
- package/dist/services/google-apis.types.d.ts +226 -0
- package/dist/services/google-apis.types.js +4 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.js +5 -0
- package/package.json +19 -6
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { CliArgument, CliCommand, CliOption } from '@causa/cli';
|
|
11
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
12
|
+
import { AllowMissing } from '@causa/workspace/validation';
|
|
13
|
+
import { Transform } from 'class-transformer';
|
|
14
|
+
import { IsObject, IsString } from 'class-validator';
|
|
15
|
+
import { getAuth, signInWithCustomToken } from 'firebase/auth';
|
|
16
|
+
import { identityPlatformCommandDefinition } from '../cli/index.js';
|
|
17
|
+
import { FirebaseAppService } from '../services/index.js';
|
|
18
|
+
import { GoogleIdentityPlatformGenerateCustomToken } from './google-identity-platform-generate-custom-token.js';
|
|
19
|
+
/**
|
|
20
|
+
* Generates an ID token for an Identity Platform end user.
|
|
21
|
+
* For this function to succeed, the `google.project` should be set, which usually means setting the environment in the
|
|
22
|
+
* context. Also `google.firebase` children can be used to configure (and speed up) how tokens are generated.
|
|
23
|
+
*/
|
|
24
|
+
let GoogleIdentityPlatformGenerateToken = class GoogleIdentityPlatformGenerateToken extends WorkspaceFunction {
|
|
25
|
+
/**
|
|
26
|
+
* The ID of the user for which the token will be generated.
|
|
27
|
+
*/
|
|
28
|
+
user;
|
|
29
|
+
/**
|
|
30
|
+
* A dictionary of custom claims that will be added to the generated JWT.
|
|
31
|
+
*/
|
|
32
|
+
claims;
|
|
33
|
+
async _call(context) {
|
|
34
|
+
context.logger.info(`🛂 Signing in user '${this.user}' with a custom token.`);
|
|
35
|
+
const customToken = await context.call(GoogleIdentityPlatformGenerateCustomToken, { user: this.user, claims: this.claims });
|
|
36
|
+
const app = await context.service(FirebaseAppService).getApp();
|
|
37
|
+
const auth = getAuth(app);
|
|
38
|
+
const credentials = await signInWithCustomToken(auth, customToken);
|
|
39
|
+
return await credentials.user.getIdToken();
|
|
40
|
+
}
|
|
41
|
+
_supports() {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__decorate([
|
|
46
|
+
CliArgument({
|
|
47
|
+
name: '<user>',
|
|
48
|
+
position: 0,
|
|
49
|
+
description: 'The ID of the user for which the token will be generated.',
|
|
50
|
+
}),
|
|
51
|
+
IsString(),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], GoogleIdentityPlatformGenerateToken.prototype, "user", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
CliOption({
|
|
56
|
+
flags: '-c, --claims <claims>',
|
|
57
|
+
description: 'A JSON string containing custom claims that will be added to the token.',
|
|
58
|
+
}),
|
|
59
|
+
IsObject(),
|
|
60
|
+
AllowMissing(),
|
|
61
|
+
Transform(({ value }) => typeof value === 'string' ? JSON.parse(value) : value),
|
|
62
|
+
__metadata("design:type", Object)
|
|
63
|
+
], GoogleIdentityPlatformGenerateToken.prototype, "claims", void 0);
|
|
64
|
+
GoogleIdentityPlatformGenerateToken = __decorate([
|
|
65
|
+
CliCommand({
|
|
66
|
+
parent: identityPlatformCommandDefinition,
|
|
67
|
+
name: 'genToken',
|
|
68
|
+
description: `Generates an ID token that can be used to access Firebase services as an end user.
|
|
69
|
+
Optional custom claims can be included in the signed token.`,
|
|
70
|
+
summary: 'Generates an ID token that can be used to access Firebase services as a client.',
|
|
71
|
+
outputFn: (token) => console.log(token),
|
|
72
|
+
})
|
|
73
|
+
], GoogleIdentityPlatformGenerateToken);
|
|
74
|
+
export { GoogleIdentityPlatformGenerateToken };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
|
|
2
|
+
/**
|
|
3
|
+
* The definition of a Spanner database with its DDL statements.
|
|
4
|
+
*/
|
|
5
|
+
export type SpannerDatabase = {
|
|
6
|
+
/**
|
|
7
|
+
* The ID / name of the database.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* The paths (relative to the workspace root) containing DDL statements for this database.
|
|
12
|
+
*/
|
|
13
|
+
ddlFiles: string[];
|
|
14
|
+
/**
|
|
15
|
+
* The DDL statements for the database.
|
|
16
|
+
*/
|
|
17
|
+
ddls: string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A function that lists Spanner databases defined in the workspace, and returns their corresponding DDLs.
|
|
21
|
+
*/
|
|
22
|
+
export declare class GoogleSpannerListDatabases extends WorkspaceFunction<Promise<SpannerDatabase[]>> {
|
|
23
|
+
_call(context: WorkspaceContext): Promise<SpannerDatabase[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Parses a SQL file containing Spanner DDL statements.
|
|
26
|
+
* End-of-the-line comments are removed, and statements are split using semicolons.
|
|
27
|
+
*
|
|
28
|
+
* @param path The path to the SQL file containing DDL statements.
|
|
29
|
+
* @returns The list of DDL statements.
|
|
30
|
+
*/
|
|
31
|
+
private parseDdlFile;
|
|
32
|
+
_supports(): boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WorkspaceFunction, listFilesAndFormat, } from '@causa/workspace';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
/**
|
|
4
|
+
* The default format used to infer the ID / name of the database from the format parts.
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_DDL_DATABASE_ID_FORMAT = '${ database }';
|
|
7
|
+
/**
|
|
8
|
+
* The default glob pattern used to find DDL statements in the workspace.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_DDL_GLOBS = ['domains/*/spanner/*.sql'];
|
|
11
|
+
/**
|
|
12
|
+
* The default regular expression used to extract format parts from DDL file paths.
|
|
13
|
+
*/
|
|
14
|
+
const DEFAULT_DDL_REGULAR_EXPRESSION = 'domains/(?<database>[\\w-]+)\\/spanner\\/[\\w-]+\\.sql';
|
|
15
|
+
/**
|
|
16
|
+
* A function that lists Spanner databases defined in the workspace, and returns their corresponding DDLs.
|
|
17
|
+
*/
|
|
18
|
+
export class GoogleSpannerListDatabases extends WorkspaceFunction {
|
|
19
|
+
async _call(context) {
|
|
20
|
+
const googleConf = context.asConfiguration();
|
|
21
|
+
const format = googleConf.get('google.spanner.ddls.format') ??
|
|
22
|
+
DEFAULT_DDL_DATABASE_ID_FORMAT;
|
|
23
|
+
const globs = googleConf.get('google.spanner.ddls.globs') ?? DEFAULT_DDL_GLOBS;
|
|
24
|
+
const regExp = googleConf.get('google.spanner.ddls.regularExpression') ??
|
|
25
|
+
DEFAULT_DDL_REGULAR_EXPRESSION;
|
|
26
|
+
context.logger.debug('🗃️ Listing Spanner databases and DDL files.');
|
|
27
|
+
const filesAndFormats = await listFilesAndFormat(globs, regExp, format, context.rootPath, {
|
|
28
|
+
nonMatchingPathHandler: (path) => context.logger.warn(`📂 Path '${path}' matches the Spanner DDL globs but did not match the regular expression. It will be ignored.`),
|
|
29
|
+
});
|
|
30
|
+
const databaseDdlFiles = filesAndFormats.reduce((files, { rendered, filePath }) => {
|
|
31
|
+
(files[rendered] ?? (files[rendered] = [])).push(filePath);
|
|
32
|
+
return files;
|
|
33
|
+
}, {});
|
|
34
|
+
return await Promise.all(Object.entries(databaseDdlFiles).map(async ([id, ddlFiles]) => {
|
|
35
|
+
ddlFiles.sort();
|
|
36
|
+
const ddlsInFiles = await Promise.all(ddlFiles.map((ddlFile) => this.parseDdlFile(ddlFile)));
|
|
37
|
+
const ddls = ddlsInFiles.flatMap((ddls) => ddls);
|
|
38
|
+
context.logger.debug(`🗃️ Found Spanner database '${id}' with ${ddlFiles.length} DDL file(s) and ${ddls.length} statement(s).`);
|
|
39
|
+
return { id, ddlFiles, ddls };
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parses a SQL file containing Spanner DDL statements.
|
|
44
|
+
* End-of-the-line comments are removed, and statements are split using semicolons.
|
|
45
|
+
*
|
|
46
|
+
* @param path The path to the SQL file containing DDL statements.
|
|
47
|
+
* @returns The list of DDL statements.
|
|
48
|
+
*/
|
|
49
|
+
async parseDdlFile(path) {
|
|
50
|
+
const rawFile = (await readFile(path)).toString();
|
|
51
|
+
return (rawFile
|
|
52
|
+
// Removing comments using the `-- My comment until the end of the line` syntax.
|
|
53
|
+
.replace(/--.*$/gm, '')
|
|
54
|
+
// Trimming lines for readability in logs, and joining them to easily split into statements.
|
|
55
|
+
.split('\n')
|
|
56
|
+
.map((statement) => statement.trim())
|
|
57
|
+
.join(' ')
|
|
58
|
+
// Splitting the SQL statements.
|
|
59
|
+
.split(';')
|
|
60
|
+
// Trimming for readability in logs.
|
|
61
|
+
.map((statement) => statement.trim()));
|
|
62
|
+
}
|
|
63
|
+
_supports() {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/functions/index.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
import { EmulatorStartForFirebaseStorage } from './emulator-start-firebase-storage.js';
|
|
2
|
+
import { EmulatorStartForFirestore } from './emulator-start-firestore.js';
|
|
3
|
+
import { EmulatorStartForIdentityPlatform } from './emulator-start-identity-platform.js';
|
|
4
|
+
import { EmulatorStartForPubSub } from './emulator-start-pubsub.js';
|
|
5
|
+
import { EmulatorStartForSpanner } from './emulator-start-spanner.js';
|
|
6
|
+
import { EmulatorStopForFirebaseStorage } from './emulator-stop-firebase-storage.js';
|
|
7
|
+
import { EmulatorStopForFirestore } from './emulator-stop-firestore.js';
|
|
8
|
+
import { EmulatorStopForIdentityPlatform } from './emulator-stop-identity-platform.js';
|
|
9
|
+
import { EmulatorStopForPubSub } from './emulator-stop-pubsub.js';
|
|
10
|
+
import { EmulatorStopForSpanner } from './emulator-stop-spanner.js';
|
|
11
|
+
import { GoogleAppCheckGenerateToken } from './google-app-check-generate-token.js';
|
|
1
12
|
import { GoogleFirebaseStorageMergeRules } from './google-firebase-storage-merge-rules.js';
|
|
2
13
|
import { GoogleFirestoreMergeRules } from './google-firestore-merge-rules.js';
|
|
14
|
+
import { GoogleIdentityPlatformGenerateCustomToken } from './google-identity-platform-generate-custom-token.js';
|
|
15
|
+
import { GoogleIdentityPlatformGenerateToken } from './google-identity-platform-generate-token.js';
|
|
3
16
|
import { GoogleServicesEnable } from './google-services-enable.js';
|
|
17
|
+
import { GoogleSpannerListDatabases } from './google-spanner-list-databases.js';
|
|
18
|
+
import { ProjectGetArtefactDestinationForServiceContainer } from './project-get-artefact-destination-service-container.js';
|
|
4
19
|
import { SecretFetchForGoogleSecretManager } from './secret-fetch-secret-manager.js';
|
|
5
20
|
export function registerFunctions(context) {
|
|
6
|
-
context.registerFunctionImplementations(GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleServicesEnable, SecretFetchForGoogleSecretManager);
|
|
21
|
+
context.registerFunctionImplementations(EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GoogleServicesEnable, GoogleSpannerListDatabases, ProjectGetArtefactDestinationForServiceContainer, SecretFetchForGoogleSecretManager);
|
|
7
22
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { ProjectGetArtefactDestination } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements the {@link ProjectGetArtefactDestination} function for Cloud Run services.
|
|
5
|
+
* The destination Docker repository is expected to be defined in `google.cloudRun.dockerRepository`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ProjectGetArtefactDestinationForServiceContainer extends ProjectGetArtefactDestination {
|
|
8
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
9
|
+
_supports(context: WorkspaceContext): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProjectGetArtefactDestination, } from '@causa/workspace-core';
|
|
2
|
+
/**
|
|
3
|
+
* Implements the {@link ProjectGetArtefactDestination} function for Cloud Run services.
|
|
4
|
+
* The destination Docker repository is expected to be defined in `google.cloudRun.dockerRepository`.
|
|
5
|
+
*/
|
|
6
|
+
export class ProjectGetArtefactDestinationForServiceContainer extends ProjectGetArtefactDestination {
|
|
7
|
+
async _call(context) {
|
|
8
|
+
const projectName = context.getOrThrow('project.name');
|
|
9
|
+
const dockerRepository = context.getOrThrow('google.cloudRun.dockerRepository');
|
|
10
|
+
return `${dockerRepository}/${projectName}:${this.tag}`;
|
|
11
|
+
}
|
|
12
|
+
_supports(context) {
|
|
13
|
+
const conf = context.asConfiguration();
|
|
14
|
+
return (conf.get('project.type') === 'serviceContainer' &&
|
|
15
|
+
conf.get('serviceContainer.platform') === 'google.cloudRun');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { App as FirebaseAdminApp } from 'firebase-admin/app';
|
|
3
|
+
import { FirebaseApp } from 'firebase/app';
|
|
4
|
+
/**
|
|
5
|
+
* The types (platforms) of Firebase apps.
|
|
6
|
+
* Apps are split by type and cannot be listed globally.
|
|
7
|
+
*/
|
|
8
|
+
declare const FIREBASE_APP_TYPES: readonly ["androidApps", "iosApps", "webApps"];
|
|
9
|
+
/**
|
|
10
|
+
* The type (platform) of a Firebase app.
|
|
11
|
+
*/
|
|
12
|
+
export type FirebaseAppType = (typeof FIREBASE_APP_TYPES)[number];
|
|
13
|
+
/**
|
|
14
|
+
* A service exposing generic Firebase functionalities based on the workspace configuration.
|
|
15
|
+
*/
|
|
16
|
+
export declare class FirebaseAppService {
|
|
17
|
+
/**
|
|
18
|
+
* The GCP project ID read from the {@link WorkspaceContext} configuration.
|
|
19
|
+
*/
|
|
20
|
+
readonly projectId: string;
|
|
21
|
+
/**
|
|
22
|
+
* The Firebase auth domain, read from the configuration or inferred from the GCP project ID.
|
|
23
|
+
*/
|
|
24
|
+
readonly authDomain: string;
|
|
25
|
+
/**
|
|
26
|
+
* The logger to use.
|
|
27
|
+
*/
|
|
28
|
+
private readonly logger;
|
|
29
|
+
/**
|
|
30
|
+
* The Firebase API key set in the configuration.
|
|
31
|
+
* This could be `undefined`, in which case {@link FirebaseAppService.findApiKey} will be called.
|
|
32
|
+
*/
|
|
33
|
+
private readonly confApiKey;
|
|
34
|
+
/**
|
|
35
|
+
* The Firebase admin service account for the GCP project, read from the configuration.
|
|
36
|
+
* This could be `undefined`, in which case {@link FirebaseAppService.findAdminServiceAccount} will be called.
|
|
37
|
+
*/
|
|
38
|
+
private readonly confAdminServiceAccount;
|
|
39
|
+
/**
|
|
40
|
+
* The Firebase app ID, read from the configuration.
|
|
41
|
+
* This could be `undefined`, in which case {@link FirebaseAppService.getAnyAppId} will be called.
|
|
42
|
+
*/
|
|
43
|
+
private readonly confAppId;
|
|
44
|
+
/**
|
|
45
|
+
* The {@link GoogleApisService} used to make calls to IAM when listing service accounts.
|
|
46
|
+
*/
|
|
47
|
+
private readonly googleApisService;
|
|
48
|
+
constructor(context: WorkspaceContext);
|
|
49
|
+
/**
|
|
50
|
+
* The promise resolving to the Firebase API key, in the case it wasn't set in the configuration.
|
|
51
|
+
*/
|
|
52
|
+
private apiKeyPromise;
|
|
53
|
+
/**
|
|
54
|
+
* Finds a Firebase API key for the configured GCP project by listing them using the API keys API.
|
|
55
|
+
* The method used to find the correct API key is a hack, relying on the display name of the key.
|
|
56
|
+
* This is why it is preferable for the API key to be set manually in the configuration.
|
|
57
|
+
*
|
|
58
|
+
* @returns A Firebase API key for the configured GCP project.
|
|
59
|
+
*/
|
|
60
|
+
private findApiKey;
|
|
61
|
+
/**
|
|
62
|
+
* Returns either the Firebase API key set in the configuration, or one found using the Google APIs.
|
|
63
|
+
*
|
|
64
|
+
* @returns The Firebase API key.
|
|
65
|
+
*/
|
|
66
|
+
getApiKey(): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* The singleton {@link FirebaseApp} created by {@link FirebaseAppService.getApp}.
|
|
69
|
+
*/
|
|
70
|
+
private app;
|
|
71
|
+
/**
|
|
72
|
+
* Initializes and returns a {@link FirebaseApp} for the configured GCP project.
|
|
73
|
+
*
|
|
74
|
+
* @returns The {@link FirebaseApp}.
|
|
75
|
+
*/
|
|
76
|
+
getApp(): Promise<FirebaseApp>;
|
|
77
|
+
/**
|
|
78
|
+
* The promise resolving to the email of the Firebase-owned service account, in case it wasn't set in the
|
|
79
|
+
* configuration.
|
|
80
|
+
*/
|
|
81
|
+
private adminServiceAccountPromise;
|
|
82
|
+
/**
|
|
83
|
+
* Looks for the automatically-created Firebase admin service account by listing service accounts in the configured
|
|
84
|
+
* GCP project.
|
|
85
|
+
* This is a hack which uses the inferred format of the service account name used by Firebase. It is preferred to
|
|
86
|
+
* manually set the `google.firebase.adminServiceAccount` configuration.
|
|
87
|
+
*
|
|
88
|
+
* @returns The email of the Firebase admin service account.
|
|
89
|
+
*/
|
|
90
|
+
private findAdminServiceAccount;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the email for the Firebase admin service account, either from the configuration or by listing service
|
|
93
|
+
* accounts using Google APIs.
|
|
94
|
+
*
|
|
95
|
+
* @returns The email for the Firebase admin service account.
|
|
96
|
+
*/
|
|
97
|
+
getAdminServiceAccount(): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* The singleton {@link FirebaseAdminApp}, created by {@link FirebaseAppService.getAdminAppForAdminServiceAccount}.
|
|
100
|
+
*/
|
|
101
|
+
private adminAppForAdminServiceAccount;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a Firebase admin app configured to authenticate as the Firebase admin service account.
|
|
104
|
+
* Using a service account rather than end user credentials ensures access to all functionalities (e.g. token
|
|
105
|
+
* signing), which are otherwise unavailable to end users.
|
|
106
|
+
*
|
|
107
|
+
* @returns The Firebase admin app.
|
|
108
|
+
*/
|
|
109
|
+
getAdminAppForAdminServiceAccount(): Promise<FirebaseAdminApp>;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a {@link Credential} object that can be used when initializing a Firebase admin app.
|
|
112
|
+
* The returned object generates access tokens for the given service account. The application default credentials (or
|
|
113
|
+
* any other default authentication method) should provide authorization to sign tokens in the GCP project for this to
|
|
114
|
+
* work.
|
|
115
|
+
*
|
|
116
|
+
* @param serviceAccountId The ID / email of the service account to impersonate.
|
|
117
|
+
* @returns The {@link Credential} to use with the Firebase admin app.
|
|
118
|
+
*/
|
|
119
|
+
private makeAdminCredential;
|
|
120
|
+
/**
|
|
121
|
+
* Looks for a Firebase app ID using the API and returns the first one found.
|
|
122
|
+
* This could be the ID of an Android, iOS, or web app.
|
|
123
|
+
* If no app can be found, an error is returned.
|
|
124
|
+
*
|
|
125
|
+
* @param options Options when listing the existing apps.
|
|
126
|
+
* @returns The first found Firebase app ID.
|
|
127
|
+
*/
|
|
128
|
+
getAnyAppId(options?: {
|
|
129
|
+
appTypes?: FirebaseAppType[];
|
|
130
|
+
}): Promise<string>;
|
|
131
|
+
/**
|
|
132
|
+
* Fetches the first Firebase app of a given type and returns its ID.
|
|
133
|
+
*
|
|
134
|
+
* @param client The Firebase API client to use.
|
|
135
|
+
* @param appType The type of Firebase app to list.
|
|
136
|
+
* @returns The ID of the first app, or `null` if none could be found.
|
|
137
|
+
*/
|
|
138
|
+
private getFirstApp;
|
|
139
|
+
/**
|
|
140
|
+
* The promise resolving to one of the Firebase App IDs available in the GCP project.
|
|
141
|
+
* Only set if {@link FirebaseAppService.confAppId} is not set.
|
|
142
|
+
*/
|
|
143
|
+
private appIdPromise;
|
|
144
|
+
/**
|
|
145
|
+
* Returns the Firebase App ID, either from the configuration or by listing apps using Google APIs.
|
|
146
|
+
*
|
|
147
|
+
* @returns The Firebase App ID.
|
|
148
|
+
*/
|
|
149
|
+
getAppId(): Promise<string>;
|
|
150
|
+
}
|
|
151
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for errors in the FirebaseApp service.
|
|
3
|
+
*/
|
|
4
|
+
export declare class FirebaseAppServiceError extends Error {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* An error thrown when the Firebase admin service account cannot be found in the configured GCP project.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FirebaseAdminServiceAccountNotFoundError extends FirebaseAppServiceError {
|
|
10
|
+
readonly projectId: string;
|
|
11
|
+
constructor(projectId: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An error thrown when a Firebase API key cannot be found in the configured GCP project.
|
|
15
|
+
*/
|
|
16
|
+
export declare class FirebaseApiKeyNotFoundError extends FirebaseAppServiceError {
|
|
17
|
+
readonly projectId: string;
|
|
18
|
+
constructor(projectId: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An error thrown when no Firebase app can be found in the given GCP project.
|
|
22
|
+
*/
|
|
23
|
+
export declare class NoFirebaseAppFoundError extends FirebaseAppServiceError {
|
|
24
|
+
readonly projectId: string;
|
|
25
|
+
constructor(projectId: string);
|
|
26
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for errors in the FirebaseApp service.
|
|
3
|
+
*/
|
|
4
|
+
export class FirebaseAppServiceError extends Error {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* An error thrown when the Firebase admin service account cannot be found in the configured GCP project.
|
|
8
|
+
*/
|
|
9
|
+
export class FirebaseAdminServiceAccountNotFoundError extends FirebaseAppServiceError {
|
|
10
|
+
projectId;
|
|
11
|
+
constructor(projectId) {
|
|
12
|
+
super(`Unable to find the service account for Firebase admin from the list of accounts in project '${projectId}'.`);
|
|
13
|
+
this.projectId = projectId;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An error thrown when a Firebase API key cannot be found in the configured GCP project.
|
|
18
|
+
*/
|
|
19
|
+
export class FirebaseApiKeyNotFoundError extends FirebaseAppServiceError {
|
|
20
|
+
projectId;
|
|
21
|
+
constructor(projectId) {
|
|
22
|
+
super(`Unable to find a Firebase API key from the keys listed in project '${projectId}'.`);
|
|
23
|
+
this.projectId = projectId;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* An error thrown when no Firebase app can be found in the given GCP project.
|
|
28
|
+
*/
|
|
29
|
+
export class NoFirebaseAppFoundError extends FirebaseAppServiceError {
|
|
30
|
+
projectId;
|
|
31
|
+
constructor(projectId) {
|
|
32
|
+
super(`Unable to find a single Firebase app in project '${projectId}' using the API.`);
|
|
33
|
+
this.projectId = projectId;
|
|
34
|
+
}
|
|
35
|
+
}
|