Skip to content

Commit 2b45bcc

Browse files
committed
Change prepare to auth prepare for consistency.
1 parent eb4d3ca commit 2b45bcc

7 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/cliCommands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ export function registerCommands(program: Command, deps: CliDependencies): void
737737
}
738738
});
739739

740-
program
740+
authCommand
741741
.command('prepare')
742742
.description(
743743
"Store a service's credentials from a JSON payload (e.g. an OAuth client id/secret)."
@@ -749,12 +749,12 @@ export function registerCommands(program: Command, deps: CliDependencies): void
749749
)
750750
.addHelpText(
751751
'after',
752-
`\nExample:\n $ latchkey prepare google-gmail '{"clientId":"<id>","clientSecret":"<secret>"}'`
752+
`\nExample:\n $ latchkey auth prepare google-gmail '{"clientId":"<id>","clientSecret":"<secret>"}'`
753753
)
754754
.action(async (serviceName: string, json: string) => {
755755
if (deps.config.gatewayUrl !== null) {
756756
await forwardToGateway(deps, {
757-
command: 'prepare',
757+
command: 'auth prepare',
758758
params: { serviceName, json },
759759
});
760760
deps.log(`Done`);
@@ -766,7 +766,7 @@ export function registerCommands(program: Command, deps: CliDependencies): void
766766
deps.config.credentialStorePath,
767767
encryptedStorage
768768
);
769-
const result = prepareService(deps.registry, apiCredentialStore, serviceName, json);
769+
prepareService(deps.registry, apiCredentialStore, serviceName, json);
770770
deps.log(`Done`);
771771
} catch (error) {
772772
if (

src/gateway/latchkeyEndpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const AuthBrowserPrepareRequestSchema = z.object({
7575
});
7676

7777
const PrepareRequestSchema = z.object({
78-
command: z.literal('prepare'),
78+
command: z.literal('auth prepare'),
7979
params: serviceNameParams.extend({
8080
json: z.string(),
8181
}),
@@ -175,7 +175,7 @@ async function dispatch(
175175
parsed.params.serviceName
176176
);
177177

178-
case 'prepare':
178+
case 'auth prepare':
179179
return prepareService(
180180
deps.registry,
181181
apiCredentialStore,

src/services/core/base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ export class LoginFailedError extends Error {
4040
}
4141

4242
/**
43-
* Thrown when `latchkey prepare` is run for a service that does not declare a
43+
* Thrown when `latchkey auth prepare` is run for a service that does not declare a
4444
* prepare schema (the base default — services opt in by setting one).
4545
*/
4646
export class PrepareNotSupportedError extends Error {
4747
constructor(serviceName: string) {
4848
super(
49-
`Service '${serviceName}' does not support 'latchkey prepare'. ` +
49+
`Service '${serviceName}' does not support 'latchkey auth prepare'. ` +
5050
`Use 'latchkey services info ${serviceName}' to see how to authenticate.`
5151
);
5252
this.name = 'PrepareNotSupportedError';
5353
}
5454
}
5555

5656
/**
57-
* Thrown when the JSON passed to `latchkey prepare` is malformed or does not
57+
* Thrown when the JSON passed to `latchkey auth prepare` is malformed or does not
5858
* match the service's prepare schema. The whole command is rejected and
5959
* nothing is stored.
6060
*/
@@ -180,7 +180,7 @@ export abstract class Service {
180180
}
181181

182182
/**
183-
* Build credentials from a parsed JSON payload for `latchkey prepare`.
183+
* Build credentials from a parsed JSON payload for `latchkey auth prepare`.
184184
*
185185
* Optional, like `getSession`/`refreshCredentials`: services opt in by
186186
* implementing it (typically via `buildPreparedCredentials` with a Zod

src/services/google/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ class GoogleServiceSession extends BrowserFollowupServiceSession {
824824
}
825825

826826
/**
827-
* JSON accepted by `latchkey prepare <google-service>`: the OAuth client
827+
* JSON accepted by `latchkey auth prepare <google-service>`: the OAuth client
828828
* credentials to use for that service. `.strict()` rejects unknown keys so
829829
* typos are reported instead of silently ignored.
830830
*/
@@ -851,7 +851,7 @@ export abstract class GoogleService extends Service {
851851

852852
/**
853853
* Google services accept an official OAuth client's id/secret via
854-
* `latchkey prepare`, stored as token-less OAuth credentials until login.
854+
* `latchkey auth prepare`, stored as token-less OAuth credentials until login.
855855
*/
856856
override prepareFromJson(parsedJson: unknown): ApiCredentials {
857857
return buildPreparedCredentials(

src/sharedOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export interface PrepareServiceResult {
265265

266266
/**
267267
* Store credentials for a service from a validated JSON payload
268-
* (`latchkey prepare <service> <json>`). The whole operation is rejected — and
268+
* (`latchkey auth prepare <service> <json>`). The whole operation is rejected — and
269269
* nothing is stored — if the JSON is malformed, fails the service's schema, or
270270
* the service does not support prepare.
271271
*/

tests/cli.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,11 +1205,11 @@ describe('CLI commands with dependency injection', () => {
12051205
});
12061206

12071207
await runCommand(
1208-
['prepare', 'google-gmail', '{"clientId":"cid","clientSecret":"csecret"}'],
1208+
['auth', 'prepare', 'google-gmail', '{"clientId":"cid","clientSecret":"csecret"}'],
12091209
deps
12101210
);
12111211

1212-
expect(logs).toContain('Prepared google-gmail.');
1212+
expect(logs).toContain('Done');
12131213
const storedData = JSON.parse(readSecureFile(storePath) ?? '{}') as Record<string, unknown>;
12141214
expect(storedData['google-gmail']).toEqual({
12151215
objectType: 'oauth',
@@ -1221,15 +1221,15 @@ describe('CLI commands with dependency injection', () => {
12211221
it('returns an error for an unknown service', async () => {
12221222
const deps = createMockDependencies();
12231223

1224-
await runCommand(['prepare', 'unknown-service', '{}'], deps);
1224+
await runCommand(['auth', 'prepare', 'unknown-service', '{}'], deps);
12251225

12261226
expect(exitCode).toBe(1);
12271227
});
12281228

12291229
it('returns an error for a service that does not support prepare', async () => {
12301230
const deps = createMockDependencies();
12311231

1232-
await runCommand(['prepare', 'slack', '{"clientId":"a","clientSecret":"b"}'], deps);
1232+
await runCommand(['auth', 'prepare', 'slack', '{"clientId":"a","clientSecret":"b"}'], deps);
12331233

12341234
expect(exitCode).toBe(1);
12351235
});
@@ -1242,7 +1242,7 @@ describe('CLI commands with dependency injection', () => {
12421242
registry: new ServiceRegistry([GOOGLE_GMAIL]),
12431243
});
12441244

1245-
await runCommand(['prepare', 'google-gmail', '{not valid'], deps);
1245+
await runCommand(['auth', 'prepare', 'google-gmail', '{not valid'], deps);
12461246

12471247
expect(exitCode).toBe(1);
12481248
const storedData = JSON.parse(readSecureFile(storePath) ?? '{}') as Record<string, unknown>;
@@ -1257,7 +1257,7 @@ describe('CLI commands with dependency injection', () => {
12571257
registry: new ServiceRegistry([GOOGLE_GMAIL]),
12581258
});
12591259

1260-
await runCommand(['prepare', 'google-gmail', '{"clientId":"only-id"}'], deps);
1260+
await runCommand(['auth', 'prepare', 'google-gmail', '{"clientId":"only-id"}'], deps);
12611261

12621262
expect(exitCode).toBe(1);
12631263
const storedData = JSON.parse(readSecureFile(storePath) ?? '{}') as Record<string, unknown>;
@@ -2539,21 +2539,21 @@ describe('CLI commands with dependency injection', () => {
25392539
});
25402540

25412541
await runCommand(
2542-
['prepare', 'google-gmail', '{"clientId":"cid","clientSecret":"csecret"}'],
2542+
['auth', 'prepare', 'google-gmail', '{"clientId":"cid","clientSecret":"csecret"}'],
25432543
deps
25442544
);
25452545

25462546
expect(fetchMock).toHaveBeenCalledTimes(1);
25472547
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
25482548
expect(url).toBe(`${GATEWAY_URL}/latchkey`);
25492549
expect(JSON.parse(init.body as string) as unknown).toEqual({
2550-
command: 'prepare',
2550+
command: 'auth prepare',
25512551
params: {
25522552
serviceName: 'google-gmail',
25532553
json: '{"clientId":"cid","clientSecret":"csecret"}',
25542554
},
25552555
});
2556-
expect(logs).toContain('Prepared google-gmail.');
2556+
expect(logs).toContain('Done');
25572557
});
25582558

25592559
it.each([
@@ -2562,7 +2562,7 @@ describe('CLI commands with dependency injection', () => {
25622562
['auth list', ['auth', 'list']],
25632563
['auth browser', ['auth', 'browser', 'slack']],
25642564
['auth browser-prepare', ['auth', 'browser-prepare', 'slack']],
2565-
['prepare', ['prepare', 'foo', '{}']],
2565+
['auth prepare', ['auth', 'prepare', 'foo', '{}']],
25662566
])('reports gateway errors on stderr (not stdout) for `%s`', async (_name, argv) => {
25672567
makeFetchMock(
25682568
new Response(JSON.stringify({ error: 'Unknown service: foo.' }), { status: 400 })

tests/latchkeyEndpoint.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,23 @@ describe('LatchkeyRequestSchema', () => {
9494

9595
it('should validate prepare with serviceName and json', () => {
9696
const result = LatchkeyRequestSchema.safeParse({
97-
command: 'prepare',
97+
command: 'auth prepare',
9898
params: { serviceName: 'google-gmail', json: '{"clientId":"a","clientSecret":"b"}' },
9999
});
100100
expect(result.success).toBe(true);
101101
});
102102

103103
it('should reject prepare without json', () => {
104104
const result = LatchkeyRequestSchema.safeParse({
105-
command: 'prepare',
105+
command: 'auth prepare',
106106
params: { serviceName: 'google-gmail' },
107107
});
108108
expect(result.success).toBe(false);
109109
});
110110

111111
it('should reject prepare without serviceName', () => {
112112
const result = LatchkeyRequestSchema.safeParse({
113-
command: 'prepare',
113+
command: 'auth prepare',
114114
params: { json: '{}' },
115115
});
116116
expect(result.success).toBe(false);
@@ -348,7 +348,7 @@ describe('/latchkey/ endpoint', () => {
348348
it('stores OAuth client credentials for a Google service', async () => {
349349
gateway = await createTestGateway({}, { registry: new ServiceRegistry([GOOGLE_GMAIL]) });
350350
const response = await postLatchkey({
351-
command: 'prepare',
351+
command: 'auth prepare',
352352
params: {
353353
serviceName: 'google-gmail',
354354
json: '{"clientId":"cid","clientSecret":"csecret"}',
@@ -365,7 +365,7 @@ describe('/latchkey/ endpoint', () => {
365365
it('returns 400 when the service does not support prepare', async () => {
366366
gateway = await createTestGateway();
367367
const response = await postLatchkey({
368-
command: 'prepare',
368+
command: 'auth prepare',
369369
params: { serviceName: 'slack', json: '{"clientId":"a","clientSecret":"b"}' },
370370
});
371371

@@ -377,7 +377,7 @@ describe('/latchkey/ endpoint', () => {
377377
it('returns 400 for malformed prepare JSON', async () => {
378378
gateway = await createTestGateway({}, { registry: new ServiceRegistry([GOOGLE_GMAIL]) });
379379
const response = await postLatchkey({
380-
command: 'prepare',
380+
command: 'auth prepare',
381381
params: { serviceName: 'google-gmail', json: '{not valid' },
382382
});
383383

0 commit comments

Comments
 (0)