@causa/workspace-google 0.1.1 → 0.3.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 +66 -0
- package/dist/functions/google-firebase-storage-merge-rules.js +1 -2
- package/dist/functions/google-firestore-merge-rules.js +1 -2
- 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 +73 -0
- package/dist/functions/google-services-enable.js +1 -2
- 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 +18 -1
- package/dist/functions/project-get-artefact-destination-cloud-functions.d.ts +11 -0
- package/dist/functions/project-get-artefact-destination-cloud-functions.js +18 -0
- package/dist/functions/project-get-artefact-destination-cloud-run.d.ts +10 -0
- package/dist/functions/project-get-artefact-destination-cloud-run.js +17 -0
- package/dist/functions/project-push-artefact-cloud-functions.d.ts +11 -0
- package/dist/functions/project-push-artefact-cloud-functions.js +31 -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 +7 -0
- package/dist/services/index.js +7 -0
- package/dist/services/storage.d.ts +33 -0
- package/dist/services/storage.errors.d.ts +8 -0
- package/dist/services/storage.errors.js +11 -0
- package/dist/services/storage.js +36 -0
- package/package.json +22 -8
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStart, EmulatorStartResult } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStart} for the Pub/Sub emulator.
|
|
5
|
+
* This first starts the Pub/Sub emulator, and then creates the topics defined in the workspace (if the workspace is
|
|
6
|
+
* configured with Pub/Sub as its event broker).
|
|
7
|
+
*/
|
|
8
|
+
export declare class EmulatorStartForPubSub extends EmulatorStart {
|
|
9
|
+
_call(context: WorkspaceContext): Promise<EmulatorStartResult>;
|
|
10
|
+
_supports(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Starts the Pub/Sub emulator and creates the topics defined in the workspace.
|
|
13
|
+
*
|
|
14
|
+
* @param context The {@link WorkspaceContext}.
|
|
15
|
+
* @returns The configuration for the emulator and the local Pub/Sub topics.
|
|
16
|
+
*/
|
|
17
|
+
private startPubSub;
|
|
18
|
+
/**
|
|
19
|
+
* Starts the Pub/Sub emulator.
|
|
20
|
+
*
|
|
21
|
+
* @param context The {@link WorkspaceContext}.
|
|
22
|
+
* @returns The configuration for the Pub/Sub emulator.
|
|
23
|
+
*/
|
|
24
|
+
private startPubSubEmulator;
|
|
25
|
+
/**
|
|
26
|
+
* Creates the Pub/Sub topics corresponding to the event topics defined in the workspace.
|
|
27
|
+
* This is only performed if Pub/Sub is defined as the broker for the workspace.
|
|
28
|
+
*
|
|
29
|
+
* @param context The {@link WorkspaceContext}.
|
|
30
|
+
* @returns The configuration listing the local Pub/Sub topics.
|
|
31
|
+
*/
|
|
32
|
+
private createTopicsIfNeeded;
|
|
33
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { EmulatorStart, EventTopicList, } from '@causa/workspace-core';
|
|
2
|
+
import { PubSub } from '@google-cloud/pubsub';
|
|
3
|
+
import { getLocalGcpProject } from '../configurations/utils.js';
|
|
4
|
+
import { PUBSUB_EMULATOR_NAME, PUBSUB_PORT, formatPubSubTopicAsEnvironmentVariable, getPubSubContainerName, } from '../emulators/index.js';
|
|
5
|
+
import { GcloudEmulatorService } from '../index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Implements {@link EmulatorStart} for the Pub/Sub emulator.
|
|
8
|
+
* This first starts the Pub/Sub emulator, and then creates the topics defined in the workspace (if the workspace is
|
|
9
|
+
* configured with Pub/Sub as its event broker).
|
|
10
|
+
*/
|
|
11
|
+
export class EmulatorStartForPubSub extends EmulatorStart {
|
|
12
|
+
async _call(context) {
|
|
13
|
+
const configuration = await this.startPubSub(context);
|
|
14
|
+
return { name: PUBSUB_EMULATOR_NAME, configuration };
|
|
15
|
+
}
|
|
16
|
+
_supports() {
|
|
17
|
+
return this.name === undefined || this.name === PUBSUB_EMULATOR_NAME;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Starts the Pub/Sub emulator and creates the topics defined in the workspace.
|
|
21
|
+
*
|
|
22
|
+
* @param context The {@link WorkspaceContext}.
|
|
23
|
+
* @returns The configuration for the emulator and the local Pub/Sub topics.
|
|
24
|
+
*/
|
|
25
|
+
async startPubSub(context) {
|
|
26
|
+
if (this.dryRun) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
const emulatorConf = await this.startPubSubEmulator(context);
|
|
30
|
+
const topicsConf = await this.createTopicsIfNeeded(context);
|
|
31
|
+
context.logger.info('📫 Successfully initialized Pub/Sub emulator.');
|
|
32
|
+
return { ...emulatorConf, ...topicsConf };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Starts the Pub/Sub emulator.
|
|
36
|
+
*
|
|
37
|
+
* @param context The {@link WorkspaceContext}.
|
|
38
|
+
* @returns The configuration for the Pub/Sub emulator.
|
|
39
|
+
*/
|
|
40
|
+
async startPubSubEmulator(context) {
|
|
41
|
+
context.logger.info('📫 Starting Pub/Sub emulator.');
|
|
42
|
+
const gcpProject = getLocalGcpProject(context);
|
|
43
|
+
const containerName = getPubSubContainerName(context);
|
|
44
|
+
const gcloudEmulatorService = context.service(GcloudEmulatorService);
|
|
45
|
+
await gcloudEmulatorService.start('pubsub', containerName, [{ host: '127.0.0.1', local: PUBSUB_PORT, container: PUBSUB_PORT }], {
|
|
46
|
+
availabilityEndpoint: `http://127.0.0.1:${PUBSUB_PORT}/v1/projects/${gcpProject}/topics`,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
PUBSUB_EMULATOR_HOST: `127.0.0.1:${PUBSUB_PORT}`,
|
|
50
|
+
GOOGLE_CLOUD_PROJECT: gcloudEmulatorService.localGcpProject,
|
|
51
|
+
GCP_PROJECT: gcloudEmulatorService.localGcpProject,
|
|
52
|
+
GCLOUD_PROJECT: gcloudEmulatorService.localGcpProject,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates the Pub/Sub topics corresponding to the event topics defined in the workspace.
|
|
57
|
+
* This is only performed if Pub/Sub is defined as the broker for the workspace.
|
|
58
|
+
*
|
|
59
|
+
* @param context The {@link WorkspaceContext}.
|
|
60
|
+
* @returns The configuration listing the local Pub/Sub topics.
|
|
61
|
+
*/
|
|
62
|
+
async createTopicsIfNeeded(context) {
|
|
63
|
+
if (context.get('events.broker') !== 'google.pubSub') {
|
|
64
|
+
context.logger.warn('📫️ Pub/Sub is not set as the event broker. Skipping event topics setup.');
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
const topics = await context.call(EventTopicList, {});
|
|
68
|
+
const gcpProject = getLocalGcpProject(context);
|
|
69
|
+
const pubSub = new PubSub({
|
|
70
|
+
projectId: gcpProject,
|
|
71
|
+
apiEndpoint: `127.0.0.1:${PUBSUB_PORT}`,
|
|
72
|
+
});
|
|
73
|
+
const envVars = await Promise.all(topics.map(async ({ id }) => {
|
|
74
|
+
context.logger.info(`📫 Creating Pub/Sub emulator topic '${id}'.`);
|
|
75
|
+
const [topic] = await pubSub.topic(id).create();
|
|
76
|
+
return {
|
|
77
|
+
envVar: formatPubSubTopicAsEnvironmentVariable(id),
|
|
78
|
+
pubSubTopic: topic.name,
|
|
79
|
+
};
|
|
80
|
+
}));
|
|
81
|
+
return envVars.reduce((vars, { envVar, pubSubTopic }) => {
|
|
82
|
+
vars[envVar] = pubSubTopic;
|
|
83
|
+
return vars;
|
|
84
|
+
}, {});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStart, EmulatorStartResult } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStart} for the Spanner emulator.
|
|
5
|
+
* This starts the emulator, creates a local instance, and creates the databases using the DDLs found in the workspace.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EmulatorStartForSpanner extends EmulatorStart {
|
|
8
|
+
_call(context: WorkspaceContext): Promise<EmulatorStartResult>;
|
|
9
|
+
_supports(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Starts the Spanner emulator, and creates the instance and databases within it.
|
|
12
|
+
*
|
|
13
|
+
* @param context The {@link WorkspaceContext}.
|
|
14
|
+
* @returns The configuration for the emulator, instance and databases.
|
|
15
|
+
*/
|
|
16
|
+
private startSpanner;
|
|
17
|
+
/**
|
|
18
|
+
* Starts the Spanner emulator.
|
|
19
|
+
* The emulator is defined in a separate Docker image, not part of the `gcloud` CLI emulators.
|
|
20
|
+
*
|
|
21
|
+
* @param context The {@link WorkspaceContext}.
|
|
22
|
+
* @returns The configuration for the Spanner emulator.
|
|
23
|
+
*/
|
|
24
|
+
private startSpannerEmulator;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a local instance within the Spanner emulator.
|
|
27
|
+
*
|
|
28
|
+
* @param context The {@link WorkspaceContext}.
|
|
29
|
+
* @returns The created Spanner {@link Instance} and the corresponding client configuration.
|
|
30
|
+
*/
|
|
31
|
+
private createInstance;
|
|
32
|
+
/**
|
|
33
|
+
* Creates the Spanner databases within the given instance, along with their DDL statements found in the workspace.
|
|
34
|
+
*
|
|
35
|
+
* @param instance The Spanner {@link Instance} in which the databases should be created.
|
|
36
|
+
* @param context The {@link WorkspaceContext}.
|
|
37
|
+
* @returns The configuration for the created databases.
|
|
38
|
+
*/
|
|
39
|
+
private createDatabases;
|
|
40
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { DockerEmulatorService, EmulatorStart, } from '@causa/workspace-core';
|
|
2
|
+
import { Spanner } from '@google-cloud/spanner';
|
|
3
|
+
import { grpc } from 'google-gax';
|
|
4
|
+
import { getLocalGcpProject, } from '../configurations/index.js';
|
|
5
|
+
import { SPANNER_EMULATOR_NAME, SPANNER_GRPC_PORT, SPANNER_HTTP_PORT, SPANNER_IMAGE, getSpannerContainerName, } from '../emulators/index.js';
|
|
6
|
+
import { GoogleSpannerListDatabases } from './google-spanner-list-databases.js';
|
|
7
|
+
/**
|
|
8
|
+
* Implements {@link EmulatorStart} for the Spanner emulator.
|
|
9
|
+
* This starts the emulator, creates a local instance, and creates the databases using the DDLs found in the workspace.
|
|
10
|
+
*/
|
|
11
|
+
export class EmulatorStartForSpanner extends EmulatorStart {
|
|
12
|
+
async _call(context) {
|
|
13
|
+
const configuration = await this.startSpanner(context);
|
|
14
|
+
return { name: SPANNER_EMULATOR_NAME, configuration };
|
|
15
|
+
}
|
|
16
|
+
_supports() {
|
|
17
|
+
return this.name === undefined || this.name === SPANNER_EMULATOR_NAME;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Starts the Spanner emulator, and creates the instance and databases within it.
|
|
21
|
+
*
|
|
22
|
+
* @param context The {@link WorkspaceContext}.
|
|
23
|
+
* @returns The configuration for the emulator, instance and databases.
|
|
24
|
+
*/
|
|
25
|
+
async startSpanner(context) {
|
|
26
|
+
if (this.dryRun) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
const emulatorConf = await this.startSpannerEmulator(context);
|
|
30
|
+
const { instance, instanceConf } = await this.createInstance(context);
|
|
31
|
+
const databaseConf = await this.createDatabases(instance, context);
|
|
32
|
+
context.logger.info('🗃️ Successfully initialized Spanner emulator.');
|
|
33
|
+
return { ...emulatorConf, ...instanceConf, ...databaseConf };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Starts the Spanner emulator.
|
|
37
|
+
* The emulator is defined in a separate Docker image, not part of the `gcloud` CLI emulators.
|
|
38
|
+
*
|
|
39
|
+
* @param context The {@link WorkspaceContext}.
|
|
40
|
+
* @returns The configuration for the Spanner emulator.
|
|
41
|
+
*/
|
|
42
|
+
async startSpannerEmulator(context) {
|
|
43
|
+
context.logger.info('🗃️ Starting Spanner emulator.');
|
|
44
|
+
const gcpProject = getLocalGcpProject(context);
|
|
45
|
+
const containerName = getSpannerContainerName(context);
|
|
46
|
+
const imageVersion = context
|
|
47
|
+
.asConfiguration()
|
|
48
|
+
.get('google.spanner.emulator.version') ?? 'latest';
|
|
49
|
+
const dockerEmulatorService = context.service(DockerEmulatorService);
|
|
50
|
+
await dockerEmulatorService.start(`${SPANNER_IMAGE}:${imageVersion}`, containerName, [SPANNER_GRPC_PORT, SPANNER_HTTP_PORT].map((p) => ({
|
|
51
|
+
host: '127.0.0.1',
|
|
52
|
+
local: p,
|
|
53
|
+
container: p,
|
|
54
|
+
})));
|
|
55
|
+
await dockerEmulatorService.waitForAvailability(containerName, `http://127.0.0.1:${SPANNER_HTTP_PORT}/v1/projects/${gcpProject}/instances`);
|
|
56
|
+
return {
|
|
57
|
+
SPANNER_EMULATOR_HOST: `127.0.0.1:${SPANNER_GRPC_PORT}`,
|
|
58
|
+
GOOGLE_CLOUD_PROJECT: gcpProject,
|
|
59
|
+
GCP_PROJECT: gcpProject,
|
|
60
|
+
GCLOUD_PROJECT: gcpProject,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a local instance within the Spanner emulator.
|
|
65
|
+
*
|
|
66
|
+
* @param context The {@link WorkspaceContext}.
|
|
67
|
+
* @returns The created Spanner {@link Instance} and the corresponding client configuration.
|
|
68
|
+
*/
|
|
69
|
+
async createInstance(context) {
|
|
70
|
+
const instanceName = context
|
|
71
|
+
.asConfiguration()
|
|
72
|
+
.get('google.spanner.emulator.instanceName') ?? 'local';
|
|
73
|
+
context.logger.info(`🗃️ Creating Spanner emulator instance '${instanceName}'.`);
|
|
74
|
+
const spanner = new Spanner({
|
|
75
|
+
servicePath: '127.0.0.1',
|
|
76
|
+
port: SPANNER_GRPC_PORT,
|
|
77
|
+
projectId: getLocalGcpProject(context),
|
|
78
|
+
sslCreds: grpc.credentials.createInsecure(),
|
|
79
|
+
});
|
|
80
|
+
const [instance, operation] = await spanner.createInstance(instanceName, {
|
|
81
|
+
config: 'emulator-config',
|
|
82
|
+
displayName: instanceName,
|
|
83
|
+
processingUnits: 100,
|
|
84
|
+
});
|
|
85
|
+
await operation.promise();
|
|
86
|
+
return { instance, instanceConf: { SPANNER_INSTANCE: instanceName } };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Creates the Spanner databases within the given instance, along with their DDL statements found in the workspace.
|
|
90
|
+
*
|
|
91
|
+
* @param instance The Spanner {@link Instance} in which the databases should be created.
|
|
92
|
+
* @param context The {@link WorkspaceContext}.
|
|
93
|
+
* @returns The configuration for the created databases.
|
|
94
|
+
*/
|
|
95
|
+
async createDatabases(instance, context) {
|
|
96
|
+
const databases = await context.call(GoogleSpannerListDatabases, {});
|
|
97
|
+
await Promise.all(databases.map(async (database) => {
|
|
98
|
+
context.logger.info(`🗃️ Creating Spanner emulator database '${database.id}'.`);
|
|
99
|
+
// Discarding `DROP TABLE` statements as the emulator does not seem to handle them properly.
|
|
100
|
+
const ddls = database.ddls.filter((statement) => !statement.toUpperCase().startsWith('DROP TABLE'));
|
|
101
|
+
const [_, operation] = await instance.createDatabase(database.id, {
|
|
102
|
+
schema: ddls,
|
|
103
|
+
});
|
|
104
|
+
await operation.promise();
|
|
105
|
+
}));
|
|
106
|
+
return databases.length === 0
|
|
107
|
+
? {}
|
|
108
|
+
: {
|
|
109
|
+
SPANNER_DATABASE: databases.map((database) => database.id).join('|'),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStop } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Firebase Storage emulator.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmulatorStopForFirebaseStorage extends EmulatorStop {
|
|
7
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
8
|
+
_supports(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
+
import { FIREBASE_STORAGE_EMULATOR_NAME, getFirebaseStorageContainerName, } from '../emulators/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Firebase Storage emulator.
|
|
5
|
+
*/
|
|
6
|
+
export class EmulatorStopForFirebaseStorage extends EmulatorStop {
|
|
7
|
+
async _call(context) {
|
|
8
|
+
const containerName = getFirebaseStorageContainerName(context);
|
|
9
|
+
context.logger.info('️🍱 Stopping Firebase Storage emulator.');
|
|
10
|
+
await context.service(DockerEmulatorService).stop(containerName);
|
|
11
|
+
context.logger.info('️🍱 Successfully stopped Firebase Storage emulator.');
|
|
12
|
+
return FIREBASE_STORAGE_EMULATOR_NAME;
|
|
13
|
+
}
|
|
14
|
+
_supports() {
|
|
15
|
+
return (this.name === undefined || this.name === FIREBASE_STORAGE_EMULATOR_NAME);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStop } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Firestore emulator.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmulatorStopForFirestore extends EmulatorStop {
|
|
7
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
8
|
+
_supports(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
+
import { FIRESTORE_EMULATOR_NAME, getFirestoreContainerName, } from '../emulators/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Firestore emulator.
|
|
5
|
+
*/
|
|
6
|
+
export class EmulatorStopForFirestore extends EmulatorStop {
|
|
7
|
+
async _call(context) {
|
|
8
|
+
const containerName = getFirestoreContainerName(context);
|
|
9
|
+
context.logger.info('️🗃️ Stopping Firestore emulator.');
|
|
10
|
+
await context.service(DockerEmulatorService).stop(containerName);
|
|
11
|
+
context.logger.info('️🗃️ Successfully stopped Firestore emulator.');
|
|
12
|
+
return FIRESTORE_EMULATOR_NAME;
|
|
13
|
+
}
|
|
14
|
+
_supports() {
|
|
15
|
+
return this.name === undefined || this.name === FIRESTORE_EMULATOR_NAME;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStop } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Identity Platform emulator.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmulatorStopForIdentityPlatform extends EmulatorStop {
|
|
7
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
8
|
+
_supports(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
+
import { IDENTITY_PLATFORM_EMULATOR_NAME, getIdentityPlatformContainerName, } from '../emulators/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Identity Platform emulator.
|
|
5
|
+
*/
|
|
6
|
+
export class EmulatorStopForIdentityPlatform extends EmulatorStop {
|
|
7
|
+
async _call(context) {
|
|
8
|
+
const containerName = getIdentityPlatformContainerName(context);
|
|
9
|
+
context.logger.info('️🛂 Stopping Identity Platform emulator.');
|
|
10
|
+
await context.service(DockerEmulatorService).stop(containerName);
|
|
11
|
+
context.logger.info('🛂 Successfully stopped Identity Platform emulator.');
|
|
12
|
+
return IDENTITY_PLATFORM_EMULATOR_NAME;
|
|
13
|
+
}
|
|
14
|
+
_supports() {
|
|
15
|
+
return (this.name === undefined || this.name === IDENTITY_PLATFORM_EMULATOR_NAME);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStop } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Pub/Sub emulator.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmulatorStopForPubSub extends EmulatorStop {
|
|
7
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
8
|
+
_supports(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
+
import { PUBSUB_EMULATOR_NAME, getPubSubContainerName, } from '../emulators/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Pub/Sub emulator.
|
|
5
|
+
*/
|
|
6
|
+
export class EmulatorStopForPubSub extends EmulatorStop {
|
|
7
|
+
async _call(context) {
|
|
8
|
+
const containerName = getPubSubContainerName(context);
|
|
9
|
+
context.logger.info('️📫 Stopping Pub/Sub emulator.');
|
|
10
|
+
await context.service(DockerEmulatorService).stop(containerName);
|
|
11
|
+
context.logger.info('📫 Successfully stopped Pub/Sub emulator.');
|
|
12
|
+
return PUBSUB_EMULATOR_NAME;
|
|
13
|
+
}
|
|
14
|
+
_supports() {
|
|
15
|
+
return this.name === undefined || this.name === PUBSUB_EMULATOR_NAME;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EmulatorStop } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Spanner emulator.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmulatorStopForSpanner extends EmulatorStop {
|
|
7
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
8
|
+
_supports(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
+
import { SPANNER_EMULATOR_NAME, getSpannerContainerName, } from '../emulators/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EmulatorStop} for the Spanner emulator.
|
|
5
|
+
*/
|
|
6
|
+
export class EmulatorStopForSpanner extends EmulatorStop {
|
|
7
|
+
async _call(context) {
|
|
8
|
+
const containerName = getSpannerContainerName(context);
|
|
9
|
+
context.logger.info('️️🗃️ Stopping Spanner emulator.');
|
|
10
|
+
await context.service(DockerEmulatorService).stop(containerName);
|
|
11
|
+
context.logger.info('️🗃️ Successfully stopped Spanner emulator.');
|
|
12
|
+
return SPANNER_EMULATOR_NAME;
|
|
13
|
+
}
|
|
14
|
+
_supports() {
|
|
15
|
+
return this.name === undefined || this.name === SPANNER_EMULATOR_NAME;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a new AppCheck token.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GoogleAppCheckGenerateToken extends WorkspaceFunction<Promise<string>> {
|
|
6
|
+
/**
|
|
7
|
+
* The ID of the Firebase app for which the token will be generated.
|
|
8
|
+
* If `undefined`, a Firebase app ID will be found in the configuration or using the API.
|
|
9
|
+
*/
|
|
10
|
+
readonly app?: string;
|
|
11
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
12
|
+
_supports(): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { CliCommand, CliOption } from '@causa/cli';
|
|
11
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
12
|
+
import { AllowMissing } from '@causa/workspace/validation';
|
|
13
|
+
import { IsString } from 'class-validator';
|
|
14
|
+
import { getAppCheck } from 'firebase-admin/app-check';
|
|
15
|
+
import { appCheckCommandDefinition } from '../cli/index.js';
|
|
16
|
+
import { FirebaseAppService } from '../services/index.js';
|
|
17
|
+
/**
|
|
18
|
+
* The time to live of generated tokens, in seconds.
|
|
19
|
+
*/
|
|
20
|
+
const TOKEN_TTL = 3600;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a new AppCheck token.
|
|
23
|
+
*/
|
|
24
|
+
export let GoogleAppCheckGenerateToken = class GoogleAppCheckGenerateToken extends WorkspaceFunction {
|
|
25
|
+
/**
|
|
26
|
+
* The ID of the Firebase app for which the token will be generated.
|
|
27
|
+
* If `undefined`, a Firebase app ID will be found in the configuration or using the API.
|
|
28
|
+
*/
|
|
29
|
+
app;
|
|
30
|
+
async _call(context) {
|
|
31
|
+
const firebaseAppService = context.service(FirebaseAppService);
|
|
32
|
+
const app = await firebaseAppService.getAdminAppForAdminServiceAccount();
|
|
33
|
+
const appId = this.app ?? (await firebaseAppService.getAppId());
|
|
34
|
+
context.logger.info(`🛂 Generating AppCheck token for Firebase application '${appId}'.`);
|
|
35
|
+
const appCheck = getAppCheck(app);
|
|
36
|
+
const { token } = await appCheck.createToken(appId, {
|
|
37
|
+
ttlMillis: TOKEN_TTL * 1000,
|
|
38
|
+
});
|
|
39
|
+
return token;
|
|
40
|
+
}
|
|
41
|
+
_supports() {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
__decorate([
|
|
46
|
+
CliOption({
|
|
47
|
+
flags: '-a, --app <app>',
|
|
48
|
+
description: 'The ID of the Firebase app for which the token will be generated.',
|
|
49
|
+
}),
|
|
50
|
+
IsString(),
|
|
51
|
+
AllowMissing(),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], GoogleAppCheckGenerateToken.prototype, "app", void 0);
|
|
54
|
+
GoogleAppCheckGenerateToken = __decorate([
|
|
55
|
+
CliCommand({
|
|
56
|
+
parent: appCheckCommandDefinition,
|
|
57
|
+
name: 'genToken',
|
|
58
|
+
description: `Generates an AppCheck token.
|
|
59
|
+
This token can be used to mock a call from a verified device.
|
|
60
|
+
If the Firebase app ID is not specified, it will:
|
|
61
|
+
- Be fetched from the 'google.firebase.appId' configuration.
|
|
62
|
+
- If not present in the configuration, will be automatically looked up from the API.`,
|
|
63
|
+
summary: 'Generates an AppCheck token.',
|
|
64
|
+
outputFn: (token) => console.log(token),
|
|
65
|
+
})
|
|
66
|
+
], GoogleAppCheckGenerateToken);
|
|
@@ -27,7 +27,7 @@ const DEFAULT_FIREBASE_STORAGE_SECURITY_RULE_FILE = 'storage.rules';
|
|
|
27
27
|
* Returns a configuration with `google.firebaseStorage.securityRuleFile` set, such that the function can be used as a
|
|
28
28
|
* processor.
|
|
29
29
|
*/
|
|
30
|
-
let GoogleFirebaseStorageMergeRules = class GoogleFirebaseStorageMergeRules extends WorkspaceFunction {
|
|
30
|
+
export let GoogleFirebaseStorageMergeRules = class GoogleFirebaseStorageMergeRules extends WorkspaceFunction {
|
|
31
31
|
tearDown;
|
|
32
32
|
async _call(context) {
|
|
33
33
|
if (this.tearDown) {
|
|
@@ -69,4 +69,3 @@ Input files are looked for in the workspace using the globs defined in google.fi
|
|
|
69
69
|
outputFn: ({ securityRuleFile }) => console.log(securityRuleFile),
|
|
70
70
|
})
|
|
71
71
|
], GoogleFirebaseStorageMergeRules);
|
|
72
|
-
export { GoogleFirebaseStorageMergeRules };
|
|
@@ -27,7 +27,7 @@ const DEFAULT_FIRESTORE_SECURITY_RULE_FILE = 'firestore.rules';
|
|
|
27
27
|
* Returns a configuration with `google.firestore.securityRuleFile` set, such that the function can be used as a
|
|
28
28
|
* processor.
|
|
29
29
|
*/
|
|
30
|
-
let GoogleFirestoreMergeRules = class GoogleFirestoreMergeRules extends WorkspaceFunction {
|
|
30
|
+
export let GoogleFirestoreMergeRules = class GoogleFirestoreMergeRules extends WorkspaceFunction {
|
|
31
31
|
tearDown;
|
|
32
32
|
async _call(context) {
|
|
33
33
|
if (this.tearDown) {
|
|
@@ -69,4 +69,3 @@ Input files are looked for in the workspace using the globs defined in google.fi
|
|
|
69
69
|
outputFn: ({ securityRuleFile }) => console.log(securityRuleFile),
|
|
70
70
|
})
|
|
71
71
|
], GoogleFirestoreMergeRules);
|
|
72
|
-
export { GoogleFirestoreMergeRules };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a custom token that can be used to sign in to Identity Platform as a given user.
|
|
4
|
+
* Optionally, custom claims can be set in the token.
|
|
5
|
+
* They will be included in the ID token returned by Identity Platform when signing in.
|
|
6
|
+
* If `google.firebase.adminServiceAccount` is set, the service account will be used to sign the token. Otherwise, an
|
|
7
|
+
* attempt will be made to find a valid service account in the `google.project`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GoogleIdentityPlatformGenerateCustomToken extends WorkspaceFunction<Promise<string>> {
|
|
10
|
+
/**
|
|
11
|
+
* The ID of the user for which the custom token should be generated.
|
|
12
|
+
*/
|
|
13
|
+
readonly user: string;
|
|
14
|
+
/**
|
|
15
|
+
* A dictionary of custom claims to add to the token.
|
|
16
|
+
*/
|
|
17
|
+
readonly claims?: Record<string, any>;
|
|
18
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
19
|
+
_supports(): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { WorkspaceFunction } from '@causa/workspace';
|
|
11
|
+
import { AllowMissing } from '@causa/workspace/validation';
|
|
12
|
+
import { IsObject, IsString } from 'class-validator';
|
|
13
|
+
import { getAuth } from 'firebase-admin/auth';
|
|
14
|
+
import { FirebaseAppService } from '../index.js';
|
|
15
|
+
/**
|
|
16
|
+
* Generates a custom token that can be used to sign in to Identity Platform as a given user.
|
|
17
|
+
* Optionally, custom claims can be set in the token.
|
|
18
|
+
* They will be included in the ID token returned by Identity Platform when signing in.
|
|
19
|
+
* If `google.firebase.adminServiceAccount` is set, the service account will be used to sign the token. Otherwise, an
|
|
20
|
+
* attempt will be made to find a valid service account in the `google.project`.
|
|
21
|
+
*/
|
|
22
|
+
export class GoogleIdentityPlatformGenerateCustomToken extends WorkspaceFunction {
|
|
23
|
+
/**
|
|
24
|
+
* The ID of the user for which the custom token should be generated.
|
|
25
|
+
*/
|
|
26
|
+
user;
|
|
27
|
+
/**
|
|
28
|
+
* A dictionary of custom claims to add to the token.
|
|
29
|
+
*/
|
|
30
|
+
claims;
|
|
31
|
+
async _call(context) {
|
|
32
|
+
const adminApp = await context
|
|
33
|
+
.service(FirebaseAppService)
|
|
34
|
+
.getAdminAppForAdminServiceAccount();
|
|
35
|
+
return await getAuth(adminApp).createCustomToken(this.user, this.claims);
|
|
36
|
+
}
|
|
37
|
+
_supports() {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
__decorate([
|
|
42
|
+
IsString(),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], GoogleIdentityPlatformGenerateCustomToken.prototype, "user", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
IsObject(),
|
|
47
|
+
AllowMissing(),
|
|
48
|
+
__metadata("design:type", Object)
|
|
49
|
+
], GoogleIdentityPlatformGenerateCustomToken.prototype, "claims", void 0);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
|
|
2
|
+
/**
|
|
3
|
+
* Generates an ID token for an Identity Platform end user.
|
|
4
|
+
* For this function to succeed, the `google.project` should be set, which usually means setting the environment in the
|
|
5
|
+
* context. Also `google.firebase` children can be used to configure (and speed up) how tokens are generated.
|
|
6
|
+
*/
|
|
7
|
+
export declare class GoogleIdentityPlatformGenerateToken extends WorkspaceFunction<Promise<string>> {
|
|
8
|
+
/**
|
|
9
|
+
* The ID of the user for which the token will be generated.
|
|
10
|
+
*/
|
|
11
|
+
readonly user: string;
|
|
12
|
+
/**
|
|
13
|
+
* A dictionary of custom claims that will be added to the generated JWT.
|
|
14
|
+
*/
|
|
15
|
+
readonly claims?: Record<string, any>;
|
|
16
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
17
|
+
_supports(): boolean;
|
|
18
|
+
}
|