( events: EventDescriptor[], projectId: string, instanceId: string, )
| 45 | * @return The instance events config or undefined if the user doesn't want events |
| 46 | */ |
| 47 | export async function askForEventsConfig( |
| 48 | events: EventDescriptor[], |
| 49 | projectId: string, |
| 50 | instanceId: string, |
| 51 | ): Promise<InstanceEventsConfig | undefined> { |
| 52 | logger.info( |
| 53 | `\n${clc.bold("Enable Events")}: ${await marked( |
| 54 | "If you enable events, you can write custom event handlers ([https://firebase.google.com/docs/extensions/install-extensions#eventarc](https://firebase.google.com/docs/extensions/install-extensions#eventarc)) that respond to these events.\n\nYou can always enable or disable events later. Events will be emitted via Eventarc. Fees apply ([https://cloud.google.com/eventarc/pricing](https://cloud.google.com/eventarc/pricing)).", |
| 55 | )}`, |
| 56 | ); |
| 57 | if (!(await askShouldCollectEventsConfig())) { |
| 58 | return undefined; |
| 59 | } |
| 60 | let existingInstance: ExtensionInstance | undefined; |
| 61 | try { |
| 62 | existingInstance = instanceId |
| 63 | ? await extensionsApi.getInstance(projectId, instanceId) |
| 64 | : undefined; |
| 65 | } catch { |
| 66 | /* If instance was not found, then this is an instance ID for a new instance. Don't preselect any values when displaying prompts to the user. */ |
| 67 | } |
| 68 | const preselectedTypes = existingInstance?.config.allowedEventTypes ?? []; |
| 69 | const oldLocation = existingInstance?.config.eventarcChannel?.split("/")[3]; |
| 70 | const location = await askForEventArcLocation(oldLocation); |
| 71 | const channel = getEventArcChannel(projectId, location); |
| 72 | const allowedEventTypes = await askForAllowedEventTypes(events, preselectedTypes); |
| 73 | return { channel, allowedEventTypes }; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Creates an EventArc channel resource name |
nothing calls this directly
no test coverage detected
searching dependent graphs…