Skip to content

Commit 26fa539

Browse files
committed
remove api urls from --verbose flag
1 parent 3438d3a commit 26fa539

4 files changed

Lines changed: 60 additions & 82 deletions

File tree

src/commands/pull.ts

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
fetchCloudApp,
99
FirestoreClientError,
1010
type CloudApp,
11-
type FirestoreClientOptions,
1211
} from '../cloud/firestoreClient.js';
1312
import { collectAppFiles } from '../core/appCollector.js';
1413
import { ArtifactProps, type ArtifactProp } from '../core/artifacts.js';
@@ -18,7 +17,7 @@ import { getValidAuthSession } from '../auth/session.js';
1817
import { withSpinner } from '../lib/spinner.js';
1918
import { applyCloudStateToFs } from '../core/applyToFs.js';
2019
import { type RootManifest } from '../core/manifest.js';
21-
import { writeVerboseJson } from '../core/debugFiles.js';
20+
import { createFirestoreDebugOptions, writeVerboseJson } from '../core/debugFiles.js';
2221
import { computePullPlan, type PullSummary } from '../core/sync.js';
2322
import { applyCloudAssetsToFs, buildEnvConfigForCloudAssets } from '../core/pullAssets.js';
2423
import { ui } from '../core/ui.js';
@@ -164,45 +163,7 @@ export async function pullCommand(options: PullOptions = {}): Promise<void> {
164163
}
165164
const { idToken, userId } = session;
166165

167-
const debugEnabled = verbose;
168-
const firestoreOptions: FirestoreClientOptions | undefined = debugEnabled
169-
? {
170-
debug: (event) => {
171-
// eslint-disable-next-line no-console
172-
console.log(
173-
`[debug:firestore] ${event.kind}`,
174-
JSON.stringify(
175-
{
176-
...(event.kind === 'request' && {
177-
method: event.method,
178-
url: event.url,
179-
context: event.context,
180-
}),
181-
...(event.kind === 'response' && {
182-
method: event.method,
183-
url: event.url,
184-
status: event.status,
185-
context: event.context,
186-
}),
187-
...(event.kind === 'list_documents' && {
188-
collection: event.collection,
189-
parentPath: event.parentPath,
190-
count: event.count,
191-
}),
192-
...(event.kind === 'push_operation' && {
193-
appId: event.appId,
194-
operation: event.operation,
195-
artifactKind: event.artifactKind,
196-
documentId: event.documentId,
197-
}),
198-
},
199-
null,
200-
2
201-
)
202-
);
203-
},
204-
}
205-
: undefined;
166+
const firestoreOptions = verbose ? createFirestoreDebugOptions() : undefined;
206167

207168
const manifestPath = path.join(projectRoot, '.manifest.json');
208169
const readManifest = (): Promise<RootManifest> =>

src/commands/push.ts

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
fetchCloudApp,
88
submitCliPush,
99
FirestoreClientError,
10-
type FirestoreClientOptions,
1110
type CloudApp,
1211
} from '../cloud/firestoreClient.js';
1312
import { buildDocumentsFromParsed } from '../core/buildDocuments.js';
@@ -18,7 +17,7 @@ import { resolveVerboseFlag } from '../core/cliError.js';
1817
import { resolveAppContext } from '../config/projectConfig.js';
1918
import { getValidAuthSession } from '../auth/session.js';
2019
import { withSpinner } from '../lib/spinner.js';
21-
import { writeVerboseJson } from '../core/debugFiles.js';
20+
import { createFirestoreDebugOptions, writeVerboseJson } from '../core/debugFiles.js';
2221
import { computePushPlan, type PushSummary, type PushCounts } from '../core/sync.js';
2322
import { buildAndWriteManifest } from '../core/manifest.js';
2423
import { ui } from '../core/ui.js';
@@ -207,45 +206,7 @@ export async function pushCommand(options: PushOptions = {}): Promise<void> {
207206
}
208207
const { idToken, userId } = session;
209208

210-
const debugEnabled = verbose;
211-
const firestoreOptions: FirestoreClientOptions | undefined = debugEnabled
212-
? {
213-
debug: (event) => {
214-
// eslint-disable-next-line no-console
215-
console.log(
216-
`[debug:firestore] ${event.kind}`,
217-
JSON.stringify(
218-
{
219-
...(event.kind === 'request' && {
220-
method: event.method,
221-
url: event.url,
222-
context: event.context,
223-
}),
224-
...(event.kind === 'response' && {
225-
method: event.method,
226-
url: event.url,
227-
status: event.status,
228-
context: event.context,
229-
}),
230-
...(event.kind === 'list_documents' && {
231-
collection: event.collection,
232-
parentPath: event.parentPath,
233-
count: event.count,
234-
}),
235-
...(event.kind === 'push_operation' && {
236-
appId: event.appId,
237-
operation: event.operation,
238-
artifactKind: event.artifactKind,
239-
documentId: event.documentId,
240-
}),
241-
},
242-
null,
243-
2
244-
)
245-
);
246-
},
247-
}
248-
: undefined;
209+
const firestoreOptions = verbose ? createFirestoreDebugOptions() : undefined;
249210

250211
const [access, dataWithLang, cloudAppResult] = await withSpinner(
251212
'Preparing app for push...',

src/core/debugFiles.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import fs from 'fs/promises';
22
import path from 'path';
33

4+
import type { FirestoreClientOptions, FirestoreDebugEvent } from '../cloud/firestoreClient.js';
5+
6+
export function createFirestoreDebugOptions(): FirestoreClientOptions {
7+
return { debug: logFirestoreDebugEvent };
8+
}
9+
10+
function logFirestoreDebugEvent(event: FirestoreDebugEvent): void {
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12+
const { kind, url: _omit, ...payload } = event as FirestoreDebugEvent & { url: never };
13+
// eslint-disable-next-line no-console
14+
console.log(`[debug:firestore] ${kind}`, JSON.stringify(payload, null, 2));
15+
}
16+
417
interface WriteVerboseJsonOptions {
518
verbose: boolean;
619
truncateLargeContent?: boolean;

tests/core/debugFiles.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, it, expect, vi, afterEach } from 'vitest';
2+
3+
import { createFirestoreDebugOptions } from '../../src/core/debugFiles.js';
4+
5+
describe('createFirestoreDebugOptions', () => {
6+
afterEach(() => {
7+
vi.restoreAllMocks();
8+
});
9+
10+
it('logs firestore debug events without api urls', () => {
11+
const lines: string[] = [];
12+
vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
13+
lines.push(args.map(String).join(' '));
14+
});
15+
16+
const { debug } = createFirestoreDebugOptions();
17+
debug?.({
18+
kind: 'request',
19+
method: 'GET',
20+
url: 'https://firestore.googleapis.com/v1/projects/p/databases/(default)/documents/apps/app1/artifacts?pageToken=secret',
21+
context: 'listCollectionDocuments',
22+
});
23+
debug?.({
24+
kind: 'response',
25+
method: 'GET',
26+
url: 'https://firestore.googleapis.com/v1/projects/p/databases/(default)/documents/apps/app1/artifacts',
27+
status: 200,
28+
context: 'listCollectionDocuments',
29+
});
30+
debug?.({
31+
kind: 'list_documents',
32+
collection: 'artifacts',
33+
parentPath: 'apps/app1',
34+
count: 97,
35+
});
36+
37+
const output = lines.join('\n');
38+
expect(output).toContain('listCollectionDocuments');
39+
expect(output).toContain('"count": 97');
40+
expect(output).not.toContain('firestore.googleapis.com');
41+
expect(output).not.toContain('pageToken');
42+
});
43+
});

0 commit comments

Comments
 (0)