Skip to content

Commit 757e413

Browse files
authored
[FDC] Relax project requirement in sdk:generate & Fixed GA metrics label ambiguity (#9337)
* label init from gen sdk * m * pull source into a parent object * m * relax project requirement in sdk:generate
1 parent 795975c commit 757e413

File tree

8 files changed

+36
-15
lines changed

8 files changed

+36
-15
lines changed

src/commands/dataconnect-sdk-generate.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as clc from "colorette";
33
import { Command } from "../command";
44
import { Options } from "../options";
55
import { DataConnectEmulator } from "../emulator/dataconnectEmulator";
6-
import { needProjectId } from "../projectUtils";
6+
import { getProjectId } from "../projectUtils";
77
import { loadAll } from "../dataconnect/load";
88
import { getProjectDefaultAccount } from "../auth";
99
import { logBullet, logLabeledSuccess, logWarning } from "../utils";
@@ -14,6 +14,7 @@ import * as dataconnectInit from "../init/features/dataconnect";
1414
import * as dataconnectSdkInit from "../init/features/dataconnect/sdk";
1515
import { FirebaseError } from "../error";
1616
import { postInitSaves } from "./init";
17+
import { EmulatorHub } from "../emulator/hub";
1718

1819
type GenerateOptions = Options & { watch?: boolean };
1920

@@ -24,7 +25,7 @@ export const command = new Command("dataconnect:sdk:generate")
2425
"watch for changes to your connector GQL files and regenerate your SDKs when updates occur",
2526
)
2627
.action(async (options: GenerateOptions) => {
27-
const projectId = needProjectId(options);
28+
const projectId = getProjectId(options);
2829

2930
let justRanInit = false;
3031
let config = options.config;
@@ -44,7 +45,11 @@ export const command = new Command("dataconnect:sdk:generate")
4445
}
4546
const setup: Setup = {
4647
config: config.src,
48+
projectId: projectId,
4749
rcfile: options.rc.data,
50+
featureInfo: {
51+
dataconnectSource: "gen_sdk_init",
52+
},
4853
instructions: [],
4954
};
5055
await dataconnectInit.askQuestions(setup);
@@ -67,7 +72,11 @@ export const command = new Command("dataconnect:sdk:generate")
6772
);
6873
const setup: Setup = {
6974
config: config.src,
75+
projectId: projectId,
7076
rcfile: options.rc.data,
77+
featureInfo: {
78+
dataconnectSource: "gen_sdk_init_sdk",
79+
},
7180
instructions: [],
7281
};
7382
await dataconnectSdkInit.askQuestions(setup);
@@ -79,8 +88,11 @@ export const command = new Command("dataconnect:sdk:generate")
7988
await generateSDKsInAll(options, serviceInfosWithSDKs, justRanInit);
8089
});
8190

82-
async function loadAllWithSDKs(projectId: string, config: Config): Promise<ServiceInfo[]> {
83-
const serviceInfos = await loadAll(projectId, config);
91+
async function loadAllWithSDKs(
92+
projectId: string | undefined,
93+
config: Config,
94+
): Promise<ServiceInfo[]> {
95+
const serviceInfos = await loadAll(projectId || EmulatorHub.MISSING_PROJECT_PLACEHOLDER, config);
8496
return serviceInfos.filter((serviceInfo) =>
8597
serviceInfo.connectorInfo.some((c) => {
8698
return (

src/dataconnect/provisionCloudSql.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { checkFreeTrialInstanceUsed, freeTrialTermsLink } from "./freeTrial";
88
import { promiseWithSpinner } from "../utils";
99
import { trackGA4 } from "../track";
1010
import * as utils from "../utils";
11+
import { Source } from "../init/features/dataconnect";
1112

1213
const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
1314

@@ -24,7 +25,7 @@ export async function setupCloudSql(args: {
2425
instanceId: string;
2526
databaseId: string;
2627
requireGoogleMlIntegration: boolean;
27-
source: "mcp_init" | "init" | "init_sdk" | "deploy";
28+
source: Source;
2829
dryRun?: boolean;
2930
}): Promise<void> {
3031
const { projectId, instanceId, requireGoogleMlIntegration, dryRun } = args;

src/init/features/dataconnect/index.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ function mockConfig(data: Record<string, any> = {}): Config {
247247
}
248248
function mockRequiredInfo(info: Partial<init.RequiredInfo> = {}): init.RequiredInfo {
249249
return {
250-
source: "init",
251250
flow: "test",
252251
appDescription: "",
253252
serviceId: "test-service",

src/init/features/dataconnect/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ const QUERIES_TEMPLATE = readTemplateSync("init/dataconnect/queries.gql");
5050
const MUTATIONS_TEMPLATE = readTemplateSync("init/dataconnect/mutations.gql");
5151
const SEED_DATA_TEMPLATE = readTemplateSync("init/dataconnect/seed_data.gql");
5252

53+
export type Source =
54+
| "mcp_init"
55+
| "init"
56+
| "init_sdk"
57+
| "gen_sdk_init"
58+
| "gen_sdk_init_sdk"
59+
| "deploy";
60+
5361
export interface RequiredInfo {
5462
// The GA analytics metric to track how developers go through `init dataconnect`.
55-
source: "mcp_init" | "init" | "init_sdk";
5663
flow: string;
5764
appDescription: string;
5865
serviceId: string;
@@ -100,7 +107,6 @@ const templateServiceInfo: ServiceGQL = {
100107
// logic should live here, and _no_ actuation logic should live here.
101108
export async function askQuestions(setup: Setup): Promise<void> {
102109
const info: RequiredInfo = {
103-
source: "init",
104110
flow: "",
105111
appDescription: "",
106112
serviceId: "",
@@ -177,10 +183,10 @@ export async function actuate(setup: Setup, config: Config, options: any): Promi
177183
void trackGA4(
178184
"dataconnect_init",
179185
{
180-
source: info.source,
186+
source: setup.featureInfo?.dataconnectSource || "init",
181187
flow: info.flow.substring(1), // Trim the leading `_`
182188
project_status: setup.projectId
183-
? setup.isBillingEnabled
189+
? (await isBillingEnabled(setup))
184190
? info.shouldProvisionCSQL
185191
? "blaze_provisioned_csql"
186192
: "blaze"
@@ -199,7 +205,7 @@ export async function actuate(setup: Setup, config: Config, options: any): Promi
199205
https://console.firebase.google.com/project/${setup.projectId!}/dataconnect/locations/${info.locationId}/services/${info.serviceId}/schema`,
200206
);
201207
}
202-
if (!setup.isBillingEnabled) {
208+
if (!(await isBillingEnabled(setup))) {
203209
setup.instructions.push(upgradeInstructions(setup.projectId || "your-firebase-project"));
204210
}
205211
setup.instructions.push(
@@ -230,7 +236,7 @@ async function actuateWithInfo(
230236
instanceId: info.cloudSqlInstanceId,
231237
databaseId: info.cloudSqlDatabase,
232238
requireGoogleMlIntegration: false,
233-
source: info.source,
239+
source: setup.featureInfo?.dataconnectSource || "init",
234240
});
235241
}
236242

src/init/features/dataconnect/sdk.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { getGlobalDefaultAccount } from "../../../auth";
3434
import { createFlutterApp, createNextApp, createReactApp } from "./create_app";
3535
import { trackGA4 } from "../../../track";
3636
import { dirExistsSync, listFiles } from "../../../fsutils";
37+
import { isBillingEnabled } from "../../../gcp/cloudbilling";
3738

3839
export const FDC_APP_FOLDER = "FDC_APP_FOLDER";
3940
export const FDC_SDK_FRAMEWORKS_ENV = "FDC_SDK_FRAMEWORKS";
@@ -170,9 +171,9 @@ export async function actuate(setup: Setup, config: Config) {
170171
void trackGA4(
171172
"dataconnect_init",
172173
{
173-
flow: "cli_sdk",
174+
source: setup.featureInfo?.dataconnectSource || "cli_sdk",
174175
project_status: setup.projectId
175-
? setup.isBillingEnabled
176+
? (await isBillingEnabled(setup))
176177
? "blaze"
177178
: "spark"
178179
: "missing",

src/init/features/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export { initGitHub as hostingGithub } from "./hosting/github";
2525
export {
2626
askQuestions as dataconnectAskQuestions,
2727
RequiredInfo as DataconnectInfo,
28+
Source as DataconnectSource,
2829
actuate as dataconnectActuate,
2930
} from "./dataconnect";
3031
export {

src/init/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface SetupInfo {
3636
firestore?: features.FirestoreInfo;
3737
dataconnect?: features.DataconnectInfo;
3838
dataconnectSdk?: features.DataconnectSdkInfo;
39+
dataconnectSource?: features.DataconnectSource;
3940
storage?: features.StorageInfo;
4041
apptesting?: features.ApptestingInfo;
4142
ailogic?: features.AiLogicInfo;

src/mcp/tools/core/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ export const init = tool(
182182
if (err) return err;
183183
}
184184
featuresList.push("dataconnect");
185+
featureInfo.dataconnectSource = "mcp_init";
185186
featureInfo.dataconnect = {
186-
source: "mcp_init",
187187
flow: "",
188188
appDescription: features.dataconnect.app_description || "",
189189
serviceId: features.dataconnect.service_id || "",

0 commit comments

Comments
 (0)