@causa/workspace-google 0.4.0 → 0.5.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.
Files changed (108) hide show
  1. package/README.md +6 -0
  2. package/dist/backfilling/bigquery.d.ts +53 -0
  3. package/dist/backfilling/bigquery.js +99 -0
  4. package/dist/backfilling/index.d.ts +2 -0
  5. package/dist/backfilling/index.js +2 -0
  6. package/dist/backfilling/pubsub.d.ts +34 -0
  7. package/dist/backfilling/pubsub.js +63 -0
  8. package/dist/configurations/google.d.ts +9 -0
  9. package/dist/functions/emulator/index.d.ts +10 -0
  10. package/dist/functions/emulator/index.js +10 -0
  11. package/dist/functions/{emulator-start-firebase-storage.js → emulator/start-firebase-storage.js} +4 -4
  12. package/dist/functions/{emulator-start-firestore.js → emulator/start-firestore.js} +3 -3
  13. package/dist/functions/{emulator-start-identity-platform.js → emulator/start-identity-platform.js} +3 -3
  14. package/dist/functions/{emulator-start-pubsub.js → emulator/start-pubsub.js} +3 -3
  15. package/dist/functions/{emulator-start-spanner.js → emulator/start-spanner.js} +3 -3
  16. package/dist/functions/{emulator-stop-firebase-storage.js → emulator/stop-firebase-storage.js} +1 -1
  17. package/dist/functions/{emulator-stop-firestore.js → emulator/stop-firestore.js} +1 -1
  18. package/dist/functions/{emulator-stop-identity-platform.js → emulator/stop-identity-platform.js} +1 -1
  19. package/dist/functions/{emulator-stop-pubsub.js → emulator/stop-pubsub.js} +1 -1
  20. package/dist/functions/{emulator-stop-spanner.js → emulator/stop-spanner.js} +1 -1
  21. package/dist/functions/event-topic/broker-create-topic-pubsub.d.ts +11 -0
  22. package/dist/functions/event-topic/broker-create-topic-pubsub.js +27 -0
  23. package/dist/functions/event-topic/broker-create-trigger-cloud-run.d.ts +11 -0
  24. package/dist/functions/event-topic/broker-create-trigger-cloud-run.js +38 -0
  25. package/dist/functions/event-topic/broker-delete-topic-pubsub.d.ts +10 -0
  26. package/dist/functions/event-topic/broker-delete-topic-pubsub.js +26 -0
  27. package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.d.ts +11 -0
  28. package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.js +29 -0
  29. package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.d.ts +10 -0
  30. package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.js +31 -0
  31. package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.d.ts +11 -0
  32. package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.js +28 -0
  33. package/dist/functions/event-topic/broker-get-topic-id-pubsub.d.ts +10 -0
  34. package/dist/functions/event-topic/broker-get-topic-id-pubsub.js +16 -0
  35. package/dist/functions/event-topic/broker-publish-events-google.d.ts +17 -0
  36. package/dist/functions/event-topic/broker-publish-events-google.js +45 -0
  37. package/dist/functions/event-topic/index.d.ts +8 -0
  38. package/dist/functions/event-topic/index.js +8 -0
  39. package/dist/functions/{google-app-check-generate-token.js → google-app-check/generate-token.js} +2 -2
  40. package/dist/functions/google-app-check/index.d.ts +1 -0
  41. package/dist/functions/google-app-check/index.js +1 -0
  42. package/dist/functions/google-firebase-storage/index.d.ts +1 -0
  43. package/dist/functions/google-firebase-storage/index.js +1 -0
  44. package/dist/functions/{google-firebase-storage-merge-rules.d.ts → google-firebase-storage/merge-rules.d.ts} +1 -1
  45. package/dist/functions/{google-firebase-storage-merge-rules.js → google-firebase-storage/merge-rules.js} +2 -2
  46. package/dist/functions/google-firestore/index.d.ts +1 -0
  47. package/dist/functions/google-firestore/index.js +1 -0
  48. package/dist/functions/{google-firestore-merge-rules.d.ts → google-firestore/merge-rules.d.ts} +1 -1
  49. package/dist/functions/{google-firestore-merge-rules.js → google-firestore/merge-rules.js} +2 -2
  50. package/dist/functions/{google-identity-platform-generate-custom-token.js → google-identity-platform/generate-custom-token.js} +1 -1
  51. package/dist/functions/{google-identity-platform-generate-token.js → google-identity-platform/generate-token.js} +3 -3
  52. package/dist/functions/google-identity-platform/index.d.ts +2 -0
  53. package/dist/functions/google-identity-platform/index.js +2 -0
  54. package/dist/functions/google-pubsub/index.d.ts +1 -0
  55. package/dist/functions/google-pubsub/index.js +1 -0
  56. package/dist/functions/{google-services-enable.d.ts → google-services/enable.d.ts} +1 -1
  57. package/dist/functions/{google-services-enable.js → google-services/enable.js} +1 -1
  58. package/dist/functions/google-services/index.d.ts +1 -0
  59. package/dist/functions/google-services/index.js +1 -0
  60. package/dist/functions/google-spanner/index.d.ts +2 -0
  61. package/dist/functions/google-spanner/index.js +2 -0
  62. package/dist/functions/{google-spanner-write-databases.js → google-spanner/write-databases.js} +1 -1
  63. package/dist/functions/index.js +12 -24
  64. package/dist/functions/project/index.d.ts +3 -0
  65. package/dist/functions/project/index.js +3 -0
  66. package/dist/functions/{project-push-artefact-cloud-functions.js → project/push-artefact-cloud-functions.js} +1 -1
  67. package/dist/functions/{secret-fetch-secret-manager.js → secret/fetch-secret-manager.js} +1 -1
  68. package/dist/functions/secret/index.d.ts +1 -0
  69. package/dist/functions/secret/index.js +1 -0
  70. package/dist/services/bigquery.d.ts +16 -0
  71. package/dist/services/bigquery.js +19 -0
  72. package/dist/services/cloud-run-pubsub-trigger.d.ts +101 -0
  73. package/dist/services/cloud-run-pubsub-trigger.js +177 -0
  74. package/dist/services/cloud-run.d.ts +35 -0
  75. package/dist/services/cloud-run.js +72 -0
  76. package/dist/services/iam.d.ts +43 -0
  77. package/dist/services/iam.js +65 -0
  78. package/dist/services/index.d.ts +6 -0
  79. package/dist/services/index.js +6 -0
  80. package/dist/services/pubsub.d.ts +41 -0
  81. package/dist/services/pubsub.js +62 -0
  82. package/dist/services/resource-manager.d.ts +18 -0
  83. package/dist/services/resource-manager.js +35 -0
  84. package/package.json +16 -12
  85. /package/dist/functions/{emulator-start-firebase-storage.d.ts → emulator/start-firebase-storage.d.ts} +0 -0
  86. /package/dist/functions/{emulator-start-firestore.d.ts → emulator/start-firestore.d.ts} +0 -0
  87. /package/dist/functions/{emulator-start-identity-platform.d.ts → emulator/start-identity-platform.d.ts} +0 -0
  88. /package/dist/functions/{emulator-start-pubsub.d.ts → emulator/start-pubsub.d.ts} +0 -0
  89. /package/dist/functions/{emulator-start-spanner.d.ts → emulator/start-spanner.d.ts} +0 -0
  90. /package/dist/functions/{emulator-stop-firebase-storage.d.ts → emulator/stop-firebase-storage.d.ts} +0 -0
  91. /package/dist/functions/{emulator-stop-firestore.d.ts → emulator/stop-firestore.d.ts} +0 -0
  92. /package/dist/functions/{emulator-stop-identity-platform.d.ts → emulator/stop-identity-platform.d.ts} +0 -0
  93. /package/dist/functions/{emulator-stop-pubsub.d.ts → emulator/stop-pubsub.d.ts} +0 -0
  94. /package/dist/functions/{emulator-stop-spanner.d.ts → emulator/stop-spanner.d.ts} +0 -0
  95. /package/dist/functions/{google-app-check-generate-token.d.ts → google-app-check/generate-token.d.ts} +0 -0
  96. /package/dist/functions/{google-identity-platform-generate-custom-token.d.ts → google-identity-platform/generate-custom-token.d.ts} +0 -0
  97. /package/dist/functions/{google-identity-platform-generate-token.d.ts → google-identity-platform/generate-token.d.ts} +0 -0
  98. /package/dist/functions/{google-pubsub-write-topics.d.ts → google-pubsub/write-topics.d.ts} +0 -0
  99. /package/dist/functions/{google-pubsub-write-topics.js → google-pubsub/write-topics.js} +0 -0
  100. /package/dist/functions/{google-spanner-list-databases.d.ts → google-spanner/list-databases.d.ts} +0 -0
  101. /package/dist/functions/{google-spanner-list-databases.js → google-spanner/list-databases.js} +0 -0
  102. /package/dist/functions/{google-spanner-write-databases.d.ts → google-spanner/write-databases.d.ts} +0 -0
  103. /package/dist/functions/{project-get-artefact-destination-cloud-functions.d.ts → project/get-artefact-destination-cloud-functions.d.ts} +0 -0
  104. /package/dist/functions/{project-get-artefact-destination-cloud-functions.js → project/get-artefact-destination-cloud-functions.js} +0 -0
  105. /package/dist/functions/{project-get-artefact-destination-cloud-run.d.ts → project/get-artefact-destination-cloud-run.d.ts} +0 -0
  106. /package/dist/functions/{project-get-artefact-destination-cloud-run.js → project/get-artefact-destination-cloud-run.js} +0 -0
  107. /package/dist/functions/{project-push-artefact-cloud-functions.d.ts → project/push-artefact-cloud-functions.d.ts} +0 -0
  108. /package/dist/functions/{secret-fetch-secret-manager.d.ts → secret/fetch-secret-manager.d.ts} +0 -0
@@ -0,0 +1,31 @@
1
+ import { EventTopicBrokerDeleteTriggerResource, } from '@causa/workspace-core';
2
+ import { status } from '@grpc/grpc-js';
3
+ import { PubSubService } from '../../services/index.js';
4
+ /**
5
+ * Implements {@link EventTopicBrokerDeleteTriggerResource} for Pub/Sub subscriptions.
6
+ * Pub/Sub subscriptions are for example used when creating Cloud Run triggers.
7
+ */
8
+ export class EventTopicBrokerDeleteTriggerResourceForPubSubSubscription extends EventTopicBrokerDeleteTriggerResource {
9
+ async _call(context) {
10
+ context.logger.info(`📫 Deleting Pub/Sub subscription '${this.id}'.`);
11
+ try {
12
+ await context
13
+ .service(PubSubService)
14
+ .pubSub.subscription(this.id)
15
+ .delete();
16
+ }
17
+ catch (error) {
18
+ if (error.code === status.NOT_FOUND) {
19
+ context.logger.warn(`⚠️ Pub/Sub subscription '${this.id}' does not exist. It might have already been deleted.`);
20
+ }
21
+ else {
22
+ throw error;
23
+ }
24
+ }
25
+ }
26
+ _supports(context) {
27
+ return (this.id.match(/^projects\/[\w-]+\/subscriptions\/[\w-]+$/) != null &&
28
+ context.asConfiguration().get('events.broker') ===
29
+ 'google.pubSub');
30
+ }
31
+ }
@@ -0,0 +1,11 @@
1
+ import { WorkspaceContext } from '@causa/workspace';
2
+ import { EventTopicBrokerDeleteTriggerResource } from '@causa/workspace-core';
3
+ /**
4
+ * Implements {@link EventTopicBrokerDeleteTriggerResource} for GCP service accounts.
5
+ * Service accounts are used by Pub/Sub push subscriptions to authenticate requests when pushing messages (e.g. to Cloud
6
+ * Run services).
7
+ */
8
+ export declare class EventTopicBrokerDeleteTriggerResourceForServiceAccount extends EventTopicBrokerDeleteTriggerResource {
9
+ _call(context: WorkspaceContext): Promise<void>;
10
+ _supports(context: WorkspaceContext): boolean;
11
+ }
@@ -0,0 +1,28 @@
1
+ import { EventTopicBrokerDeleteTriggerResource, } from '@causa/workspace-core';
2
+ import { IamService } from '../../services/index.js';
3
+ /**
4
+ * Implements {@link EventTopicBrokerDeleteTriggerResource} for GCP service accounts.
5
+ * Service accounts are used by Pub/Sub push subscriptions to authenticate requests when pushing messages (e.g. to Cloud
6
+ * Run services).
7
+ */
8
+ export class EventTopicBrokerDeleteTriggerResourceForServiceAccount extends EventTopicBrokerDeleteTriggerResource {
9
+ async _call(context) {
10
+ context.logger.info(`🛂 Deleting Pub/Sub backfilling service account '${this.id}'.`);
11
+ try {
12
+ await context.service(IamService).deleteServiceAccount(this.id);
13
+ }
14
+ catch (error) {
15
+ if (error.code === 404) {
16
+ context.logger.warn(`⚠️ Pub/Sub backfilling service account '${this.id}' does not exist. It might have already been deleted.`);
17
+ }
18
+ else {
19
+ throw error;
20
+ }
21
+ }
22
+ }
23
+ _supports(context) {
24
+ return (this.id.match(/^projects\/[\w-]+\/serviceAccounts\/[^/]+$/) != null &&
25
+ context.asConfiguration().get('events.broker') ===
26
+ 'google.pubSub');
27
+ }
28
+ }
@@ -0,0 +1,10 @@
1
+ import { WorkspaceContext } from '@causa/workspace';
2
+ import { EventTopicBrokerGetTopicId } from '@causa/workspace-core';
3
+ /**
4
+ * Implements {@link EventTopicBrokerGetTopicId} for Pub/Sub.
5
+ * The returned topic ID is a full Pub/Sub topic ID, e.g. `projects/<projectId>/topics/<topicId>`.
6
+ */
7
+ export declare class EventTopicBrokerGetTopicIdForPubSub extends EventTopicBrokerGetTopicId {
8
+ _call(context: WorkspaceContext): Promise<string>;
9
+ _supports(context: WorkspaceContext): boolean;
10
+ }
@@ -0,0 +1,16 @@
1
+ import { EventTopicBrokerGetTopicId, } from '@causa/workspace-core';
2
+ /**
3
+ * Implements {@link EventTopicBrokerGetTopicId} for Pub/Sub.
4
+ * The returned topic ID is a full Pub/Sub topic ID, e.g. `projects/<projectId>/topics/<topicId>`.
5
+ */
6
+ export class EventTopicBrokerGetTopicIdForPubSub extends EventTopicBrokerGetTopicId {
7
+ async _call(context) {
8
+ const googleConf = context.asConfiguration();
9
+ const projectId = googleConf.getOrThrow('google.project');
10
+ return `projects/${projectId}/topics/${this.eventTopic}`;
11
+ }
12
+ _supports(context) {
13
+ return (context.asConfiguration().get('events.broker') ===
14
+ 'google.pubSub');
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ import { WorkspaceContext } from '@causa/workspace';
2
+ import { EventTopicBrokerPublishEvents } from '@causa/workspace-core';
3
+ /**
4
+ * Implements {@link EventTopicBrokerPublishEvents} for a Google / GCP stack.
5
+ * The supported message broker is Pub/Sub.
6
+ */
7
+ export declare class EventTopicBrokerPublishEventsForGoogle extends EventTopicBrokerPublishEvents {
8
+ /**
9
+ * Tries to create a {@link BackfillEventsSource} from the provided `source` and `filter`.
10
+ *
11
+ * @param context The {@link WorkspaceContext}.
12
+ * @returns The {@link BackfillEventsSource} to use for backfilling.
13
+ */
14
+ private createSource;
15
+ _call(context: WorkspaceContext): Promise<void>;
16
+ _supports(context: WorkspaceContext): boolean;
17
+ }
@@ -0,0 +1,45 @@
1
+ import { EventTopicBrokerPublishEvents, JsonFilesEventSource, } from '@causa/workspace-core';
2
+ import { BigQueryEventsSource, PubSubBackfillEventPublisher, } from '../../backfilling/index.js';
3
+ /**
4
+ * Implements {@link EventTopicBrokerPublishEvents} for a Google / GCP stack.
5
+ * The supported message broker is Pub/Sub.
6
+ */
7
+ export class EventTopicBrokerPublishEventsForGoogle extends EventTopicBrokerPublishEvents {
8
+ /**
9
+ * Tries to create a {@link BackfillEventsSource} from the provided `source` and `filter`.
10
+ *
11
+ * @param context The {@link WorkspaceContext}.
12
+ * @returns The {@link BackfillEventsSource} to use for backfilling.
13
+ */
14
+ async createSource(context) {
15
+ if (!this.source) {
16
+ const googleConf = context.asConfiguration();
17
+ const projectId = googleConf.getOrThrow('google.project');
18
+ const rawEventsDatasetId = googleConf.get('google.pubSub.bigQueryStorage.rawEventsDatasetId');
19
+ if (!rawEventsDatasetId) {
20
+ throw new Error('Cannot use the default event source because BigQuery storage is not configured.');
21
+ }
22
+ const tableName = this.eventTopic.replace(/[-\.]/g, '_');
23
+ const tableId = `${projectId}.${rawEventsDatasetId}.${tableName}`;
24
+ return new BigQueryEventsSource(context, tableId);
25
+ }
26
+ const bqSource = await BigQueryEventsSource.fromSourceAndFilter(context, this.source, this.filter);
27
+ if (bqSource) {
28
+ return bqSource;
29
+ }
30
+ const jsonFilesSource = await JsonFilesEventSource.fromSourceAndFilter(context, this.source, this.filter);
31
+ if (jsonFilesSource) {
32
+ return jsonFilesSource;
33
+ }
34
+ throw new Error(`The event source '${this.source}' is not supported.`);
35
+ }
36
+ async _call(context) {
37
+ const source = await this.createSource(context);
38
+ const publisher = new PubSubBackfillEventPublisher(context, this.topicId);
39
+ await publisher.publishFromSource(source);
40
+ }
41
+ _supports(context) {
42
+ return (context.asConfiguration().get('events.broker') ===
43
+ 'google.pubSub');
44
+ }
45
+ }
@@ -0,0 +1,8 @@
1
+ export { EventTopicBrokerCreateTopicForPubSub } from './broker-create-topic-pubsub.js';
2
+ export { EventTopicBrokerCreateTriggerForCloudRun } from './broker-create-trigger-cloud-run.js';
3
+ export { EventTopicBrokerDeleteTopicForPubSub } from './broker-delete-topic-pubsub.js';
4
+ export { EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole } from './broker-delete-trigger-resource-cloud-run-invoker-role.js';
5
+ export { EventTopicBrokerDeleteTriggerResourceForPubSubSubscription } from './broker-delete-trigger-resource-pubsub-subscription.js';
6
+ export { EventTopicBrokerDeleteTriggerResourceForServiceAccount } from './broker-delete-trigger-resource-service-account.js';
7
+ export { EventTopicBrokerGetTopicIdForPubSub } from './broker-get-topic-id-pubsub.js';
8
+ export { EventTopicBrokerPublishEventsForGoogle } from './broker-publish-events-google.js';
@@ -0,0 +1,8 @@
1
+ export { EventTopicBrokerCreateTopicForPubSub } from './broker-create-topic-pubsub.js';
2
+ export { EventTopicBrokerCreateTriggerForCloudRun } from './broker-create-trigger-cloud-run.js';
3
+ export { EventTopicBrokerDeleteTopicForPubSub } from './broker-delete-topic-pubsub.js';
4
+ export { EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole } from './broker-delete-trigger-resource-cloud-run-invoker-role.js';
5
+ export { EventTopicBrokerDeleteTriggerResourceForPubSubSubscription } from './broker-delete-trigger-resource-pubsub-subscription.js';
6
+ export { EventTopicBrokerDeleteTriggerResourceForServiceAccount } from './broker-delete-trigger-resource-service-account.js';
7
+ export { EventTopicBrokerGetTopicIdForPubSub } from './broker-get-topic-id-pubsub.js';
8
+ export { EventTopicBrokerPublishEventsForGoogle } from './broker-publish-events-google.js';
@@ -12,8 +12,8 @@ import { WorkspaceFunction } from '@causa/workspace';
12
12
  import { AllowMissing } from '@causa/workspace/validation';
13
13
  import { IsString } from 'class-validator';
14
14
  import { getAppCheck } from 'firebase-admin/app-check';
15
- import { appCheckCommandDefinition } from '../cli/index.js';
16
- import { FirebaseAppService } from '../services/index.js';
15
+ import { appCheckCommandDefinition } from '../../cli/index.js';
16
+ import { FirebaseAppService } from '../../services/index.js';
17
17
  /**
18
18
  * The time to live of generated tokens, in seconds.
19
19
  */
@@ -0,0 +1 @@
1
+ export { GoogleAppCheckGenerateToken } from './generate-token.js';
@@ -0,0 +1 @@
1
+ export { GoogleAppCheckGenerateToken } from './generate-token.js';
@@ -0,0 +1 @@
1
+ export { GoogleFirebaseStorageMergeRules } from './merge-rules.js';
@@ -0,0 +1 @@
1
+ export { GoogleFirebaseStorageMergeRules } from './merge-rules.js';
@@ -1,6 +1,6 @@
1
1
  import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
2
2
  import { InfrastructureProcessor } from '@causa/workspace-core';
3
- import { GoogleConfiguration } from '../configurations/index.js';
3
+ import { GoogleConfiguration } from '../../configurations/index.js';
4
4
  /**
5
5
  * The return value of {@link GoogleFirebaseStorageMergeRules}.
6
6
  */
@@ -11,8 +11,8 @@ import { CliCommand } from '@causa/cli';
11
11
  import { WorkspaceFunction } from '@causa/workspace';
12
12
  import { AllowMissing } from '@causa/workspace/validation';
13
13
  import { IsBoolean } from 'class-validator';
14
- import { firebaseStorageCommandDefinition } from '../cli/index.js';
15
- import { mergeFirebaseRulesFiles } from '../firebase/index.js';
14
+ import { firebaseStorageCommandDefinition } from '../../cli/index.js';
15
+ import { mergeFirebaseRulesFiles } from '../../firebase/index.js';
16
16
  /**
17
17
  * The default location where the security rules file for Firebase Storage will be written.
18
18
  */
@@ -0,0 +1 @@
1
+ export { GoogleFirestoreMergeRules } from './merge-rules.js';
@@ -0,0 +1 @@
1
+ export { GoogleFirestoreMergeRules } from './merge-rules.js';
@@ -1,6 +1,6 @@
1
1
  import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
2
2
  import { InfrastructureProcessor } from '@causa/workspace-core';
3
- import { GoogleConfiguration } from '../configurations/index.js';
3
+ import { GoogleConfiguration } from '../../configurations/index.js';
4
4
  /**
5
5
  * The return value of {@link GoogleFirestoreMergeRules}.
6
6
  */
@@ -11,8 +11,8 @@ import { CliCommand } from '@causa/cli';
11
11
  import { WorkspaceFunction } from '@causa/workspace';
12
12
  import { AllowMissing } from '@causa/workspace/validation';
13
13
  import { IsBoolean } from 'class-validator';
14
- import { firestoreCommandDefinition } from '../cli/index.js';
15
- import { mergeFirebaseRulesFiles } from '../firebase/index.js';
14
+ import { firestoreCommandDefinition } from '../../cli/index.js';
15
+ import { mergeFirebaseRulesFiles } from '../../firebase/index.js';
16
16
  /**
17
17
  * The default location where the security rules file for Firestore will be written.
18
18
  */
@@ -11,7 +11,7 @@ import { WorkspaceFunction } from '@causa/workspace';
11
11
  import { AllowMissing } from '@causa/workspace/validation';
12
12
  import { IsObject, IsString } from 'class-validator';
13
13
  import { getAuth } from 'firebase-admin/auth';
14
- import { FirebaseAppService } from '../index.js';
14
+ import { FirebaseAppService } from '../../services/index.js';
15
15
  /**
16
16
  * Generates a custom token that can be used to sign in to Identity Platform as a given user.
17
17
  * Optionally, custom claims can be set in the token.
@@ -13,9 +13,9 @@ import { AllowMissing } from '@causa/workspace/validation';
13
13
  import { Transform } from 'class-transformer';
14
14
  import { IsObject, IsString } from 'class-validator';
15
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';
16
+ import { identityPlatformCommandDefinition } from '../../cli/index.js';
17
+ import { FirebaseAppService } from '../../services/index.js';
18
+ import { GoogleIdentityPlatformGenerateCustomToken } from './generate-custom-token.js';
19
19
  /**
20
20
  * Generates an ID token for an Identity Platform end user.
21
21
  * For this function to succeed, the `google.project` should be set, which usually means setting the environment in the
@@ -0,0 +1,2 @@
1
+ export { GoogleIdentityPlatformGenerateCustomToken } from './generate-custom-token.js';
2
+ export { GoogleIdentityPlatformGenerateToken } from './generate-token.js';
@@ -0,0 +1,2 @@
1
+ export { GoogleIdentityPlatformGenerateCustomToken } from './generate-custom-token.js';
2
+ export { GoogleIdentityPlatformGenerateToken } from './generate-token.js';
@@ -0,0 +1 @@
1
+ export { GooglePubSubWriteTopics } from './write-topics.js';
@@ -0,0 +1 @@
1
+ export { GooglePubSubWriteTopics } from './write-topics.js';
@@ -1,6 +1,6 @@
1
1
  import { WorkspaceContext, WorkspaceFunction } from '@causa/workspace';
2
2
  import { InfrastructureProcessor } from '@causa/workspace-core';
3
- import { GoogleConfiguration } from '../configurations/index.js';
3
+ import { GoogleConfiguration } from '../../configurations/index.js';
4
4
  /**
5
5
  * The return value of {@link GoogleServicesEnable}.
6
6
  */
@@ -12,7 +12,7 @@ import { WorkspaceFunction } from '@causa/workspace';
12
12
  import { AllowMissing } from '@causa/workspace/validation';
13
13
  import { ServiceUsageClient } from '@google-cloud/service-usage';
14
14
  import { IsBoolean } from 'class-validator';
15
- import { googleCommandDefinition } from '../cli/index.js';
15
+ import { googleCommandDefinition } from '../../cli/index.js';
16
16
  /**
17
17
  * The maximum number of GCP services that can be enabled at the same time.
18
18
  */
@@ -0,0 +1 @@
1
+ export { GoogleServicesEnable } from './enable.js';
@@ -0,0 +1 @@
1
+ export { GoogleServicesEnable } from './enable.js';
@@ -0,0 +1,2 @@
1
+ export { GoogleSpannerListDatabases } from './list-databases.js';
2
+ export { GoogleSpannerWriteDatabases } from './write-databases.js';
@@ -0,0 +1,2 @@
1
+ export { GoogleSpannerListDatabases } from './list-databases.js';
2
+ export { GoogleSpannerWriteDatabases } from './write-databases.js';
@@ -13,7 +13,7 @@ import { AllowMissing } from '@causa/workspace/validation';
13
13
  import { IsBoolean } from 'class-validator';
14
14
  import { mkdir, rm, writeFile } from 'fs/promises';
15
15
  import { join } from 'path';
16
- import { GoogleSpannerListDatabases } from './google-spanner-list-databases.js';
16
+ import { GoogleSpannerListDatabases } from './list-databases.js';
17
17
  /**
18
18
  * The default directory where Spanner database configurations are written, relative to the workspace root.
19
19
  */
@@ -1,26 +1,14 @@
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';
12
- import { GoogleFirebaseStorageMergeRules } from './google-firebase-storage-merge-rules.js';
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';
16
- import { GooglePubSubWriteTopics } from './google-pubsub-write-topics.js';
17
- import { GoogleServicesEnable } from './google-services-enable.js';
18
- import { GoogleSpannerListDatabases } from './google-spanner-list-databases.js';
19
- import { GoogleSpannerWriteDatabases } from './google-spanner-write-databases.js';
20
- import { ProjectGetArtefactDestinationForCloudFunctions } from './project-get-artefact-destination-cloud-functions.js';
21
- import { ProjectGetArtefactDestinationForCloudRun } from './project-get-artefact-destination-cloud-run.js';
22
- import { ProjectPushArtefactForCloudFunctions } from './project-push-artefact-cloud-functions.js';
23
- import { SecretFetchForGoogleSecretManager } from './secret-fetch-secret-manager.js';
1
+ import { EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, } from './emulator/index.js';
2
+ import { EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, } from './event-topic/index.js';
3
+ import { GoogleAppCheckGenerateToken } from './google-app-check/index.js';
4
+ import { GoogleFirebaseStorageMergeRules } from './google-firebase-storage/index.js';
5
+ import { GoogleFirestoreMergeRules } from './google-firestore/index.js';
6
+ import { GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, } from './google-identity-platform/index.js';
7
+ import { GooglePubSubWriteTopics } from './google-pubsub/index.js';
8
+ import { GoogleServicesEnable } from './google-services/index.js';
9
+ import { GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, } from './google-spanner/index.js';
10
+ import { ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, } from './project/index.js';
11
+ import { SecretFetchForGoogleSecretManager } from './secret/index.js';
24
12
  export function registerFunctions(context) {
25
- context.registerFunctionImplementations(EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GooglePubSubWriteTopics, GoogleServicesEnable, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, SecretFetchForGoogleSecretManager);
13
+ context.registerFunctionImplementations(EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GooglePubSubWriteTopics, GoogleServicesEnable, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, SecretFetchForGoogleSecretManager);
26
14
  }
@@ -0,0 +1,3 @@
1
+ export { ProjectGetArtefactDestinationForCloudFunctions } from './get-artefact-destination-cloud-functions.js';
2
+ export { ProjectGetArtefactDestinationForCloudRun } from './get-artefact-destination-cloud-run.js';
3
+ export { ProjectPushArtefactForCloudFunctions } from './push-artefact-cloud-functions.js';
@@ -0,0 +1,3 @@
1
+ export { ProjectGetArtefactDestinationForCloudFunctions } from './get-artefact-destination-cloud-functions.js';
2
+ export { ProjectGetArtefactDestinationForCloudRun } from './get-artefact-destination-cloud-run.js';
3
+ export { ProjectPushArtefactForCloudFunctions } from './push-artefact-cloud-functions.js';
@@ -1,6 +1,6 @@
1
1
  import { ArtefactAlreadyExistsError, ProjectPushArtefact, } from '@causa/workspace-core';
2
2
  import { rm } from 'fs/promises';
3
- import { CloudStorageService } from '../services/index.js';
3
+ import { CloudStorageService } from '../../services/index.js';
4
4
  /**
5
5
  * Implements the {@link ProjectPushArtefact} function for Cloud Functions projects.
6
6
  * This copies the local archive of the Cloud Functions project to the Google Cloud Storage URI set in
@@ -1,5 +1,5 @@
1
1
  import { InvalidSecretDefinitionError, SecretFetch, } from '@causa/workspace';
2
- import { GoogleSecretManagerService } from '../services/index.js';
2
+ import { GoogleSecretManagerService } from '../../services/index.js';
3
3
  /**
4
4
  * The regular expression used to match the (Secret Manager) secret ID/name, and possibly its version and project.
5
5
  * [projects/<projectId>/secrets]<secretName>[/versions/<version>]
@@ -0,0 +1 @@
1
+ export { SecretFetchForGoogleSecretManager } from './fetch-secret-manager.js';
@@ -0,0 +1 @@
1
+ export { SecretFetchForGoogleSecretManager } from './fetch-secret-manager.js';
@@ -0,0 +1,16 @@
1
+ import { WorkspaceContext } from '@causa/workspace';
2
+ import { BigQuery } from '@google-cloud/bigquery';
3
+ /**
4
+ * A service that provides access to BigQuery.
5
+ */
6
+ export declare class BigQueryService {
7
+ /**
8
+ * The BigQuery client configured with the GCP project ID.
9
+ */
10
+ readonly bigQuery: BigQuery;
11
+ /**
12
+ * The GCP project ID.
13
+ */
14
+ readonly projectId: string;
15
+ constructor(context: WorkspaceContext);
16
+ }
@@ -0,0 +1,19 @@
1
+ import { BigQuery } from '@google-cloud/bigquery';
2
+ /**
3
+ * A service that provides access to BigQuery.
4
+ */
5
+ export class BigQueryService {
6
+ /**
7
+ * The BigQuery client configured with the GCP project ID.
8
+ */
9
+ bigQuery;
10
+ /**
11
+ * The GCP project ID.
12
+ */
13
+ projectId;
14
+ constructor(context) {
15
+ const googleConf = context.asConfiguration();
16
+ this.projectId = googleConf.getOrThrow('google.project');
17
+ this.bigQuery = new BigQuery({ projectId: this.projectId });
18
+ }
19
+ }
@@ -0,0 +1,101 @@
1
+ import { WorkspaceContext } from '@causa/workspace';
2
+ /**
3
+ * A service that manages (creates) Pub/Sub triggers pointing to Cloud Run services.
4
+ * This is used for backfilling operations. The reason it is a service is to persist temporary service accounts and IAM
5
+ * grants, such that they can be reused within the same backfilling operation.
6
+ */
7
+ export declare class CloudRunPubSubTriggerService {
8
+ /**
9
+ * The service managing Cloud Run resources.
10
+ */
11
+ private readonly cloudRunService;
12
+ /**
13
+ * The service managing Pub/Sub resources.
14
+ */
15
+ private readonly pubSubService;
16
+ /**
17
+ * The service managing IAM permissions.
18
+ */
19
+ private readonly iamService;
20
+ /**
21
+ * A set of IAM bindings that have already been created.
22
+ * This is used to avoid creating the same bindings multiple times within a single backfill operation.
23
+ * An IAM binding allows the service account used by Pub/Sub for a single backfill operation to invoke a Cloud Run
24
+ * service. The format of strings in this set is the one used to reference bindings during deletion as well, i.e.
25
+ * `projects/<projectId>/locations/<location>/services/<name>/invokerBindings/<serviceAccountEmail>`.
26
+ */
27
+ private readonly invokerBindingIds;
28
+ /**
29
+ * A map of backfill IDs to promises resolving to the service account email used by Pub/Sub to invoke Cloud Run
30
+ * services for the backfill.
31
+ */
32
+ private readonly backfillInvokerServiceAccounts;
33
+ /**
34
+ * The logger used by this service.
35
+ */
36
+ private readonly logger;
37
+ /**
38
+ * The ID of the GCP project in which resources should be created.
39
+ */
40
+ readonly projectId: string;
41
+ constructor(context: WorkspaceContext);
42
+ /**
43
+ * Creates a service account that should be used by Pub/Sub to invoke Cloud Run services for a given backfill
44
+ * operation.
45
+ *
46
+ * @param backfillId The ID of the backfilling operation.
47
+ * @returns The service account email that should be used by Pub/Sub when pushing messages to Cloud Run services,
48
+ * along with the corresponding resource ID that should be deleted as part of the backfill cleaning.
49
+ */
50
+ private createBackfillInvokerServiceAccount;
51
+ /**
52
+ * Gets or creates a service account that should be used by Pub/Sub to invoke Cloud Run services for a given backfill
53
+ * operation.
54
+ *
55
+ * @param backfillId The ID of the backfilling operation.
56
+ * @returns The service account email that should be used by Pub/Sub when pushing messages to Cloud Run services.
57
+ * If `resourceId` is not `null`, it should be added to the list of resources to delete as part of the backfill
58
+ * cleaning.
59
+ */
60
+ private getBackfillInvokerServiceAccount;
61
+ /**
62
+ * Grants the invoker role to a service account for a given Cloud Run service.
63
+ * This is used to allow Pub/Sub to invoke the Cloud Run service.
64
+ * If a resource ID string is returned, it should be added to the list of resources to delete as part of the backfill
65
+ * cleaning.
66
+ *
67
+ * @param serviceId The ID of the Cloud Run service.
68
+ * @param pubSubServiceAccount The service account email for which the invoker role should be granted.
69
+ * @returns The resource ID of the IAM binding that was created, or `null` if the binding already existed.
70
+ */
71
+ private grantPubSubInvokerRole;
72
+ /**
73
+ * Creates a Pub/Sub subscription that will push messages to a Cloud Run service.
74
+ *
75
+ * @param backfillId The ID of the backfilling operation.
76
+ * @param topicId The ID of the Pub/Sub topic to subscribe to.
77
+ * @param serviceId The ID of the Cloud Run service to invoke.
78
+ * @param path The HTTP endpoint of the Cloud Run service to invoke.
79
+ * @param serviceAccountEmail The service account email that should be used by Pub/Sub when pushing messages to the
80
+ * Cloud Run service.
81
+ * @returns The ID of the Pub/Sub subscription that was created. It should be added to the list of resources to delete
82
+ * as part of the backfill cleaning.
83
+ */
84
+ private createSubscription;
85
+ /**
86
+ * Creates a Pub/Sub trigger (push subscription) pointing to a Cloud Run service.
87
+ * This requires several resources, such as:
88
+ * - A service account that should be used by Pub/Sub to invoke Cloud Run services for the backfill.
89
+ * - An IAM binding allowing the service account to invoke the Cloud Run service.
90
+ * - A Pub/Sub subscription that will push messages to the Cloud Run service.
91
+ * The IDs of these resources are returned, and should be deleted as part of the backfill cleaning.
92
+ *
93
+ * @param backfillId The ID of the backfilling operation.
94
+ * @param topicId The ID of the Pub/Sub topic to subscribe to.
95
+ * @param serviceId The ID of the Cloud Run service to invoke.
96
+ * @param path The HTTP endpoint of the Cloud Run service to invoke.
97
+ * @returns The IDs of the resources that were created. They should be added to the list of resources to delete as
98
+ * part of the backfill cleaning.
99
+ */
100
+ create(backfillId: string, topicId: string, serviceId: string, path: string): Promise<string[]>;
101
+ }