Skip to content

Commit ae4e22f

Browse files
committed
refactor(api): move bapiRequest into lib/bapi.ts
Mirror the fapiRequest relocation: the BAPI passthrough wrapper now lives in lib/bapi.ts as a sibling to lib/fapi.ts, so both API clients sit in the leaf layer instead of one being a command module. Updates all importers and the relocated bapi test; no behavior change. Claude-Session: https://claude.ai/code/session_01QnfBw9qY7u19BvUWyfQGC6
1 parent efa6d41 commit ae4e22f

13 files changed

Lines changed: 19 additions & 17 deletions

File tree

.changeset/free-breads-pick.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.claude/rules/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ const config = await withApiContext(
6161

6262
## API error classes
6363

64-
`BapiError` and `PlapiError` (both extend `ApiError`) are thrown by the API helpers in `src/commands/api/bapi.ts` and `src/lib/plapi.ts` respectively. Don't construct these in commands — they're thrown automatically by the fetch wrappers. Use `withApiContext` to add context when calling those helpers.
64+
`BapiError` and `PlapiError` (both extend `ApiError`) are thrown by the API helpers in `src/lib/bapi.ts` and `src/lib/plapi.ts` respectively. Don't construct these in commands — they're thrown automatically by the fetch wrappers. Use `withApiContext` to add context when calling those helpers.

packages/cli-core/src/commands/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getAuthToken } from "../../lib/plapi.ts";
33
import { getBapiBaseUrl, getPlapiBaseUrl } from "../../lib/environment.ts";
44
import { normalizeBapiPath, resolveBapiSecretKey } from "../../lib/bapi-command.ts";
55
import { type ApiResponse } from "../../lib/fetch.ts";
6-
import { bapiRequest } from "./bapi.ts";
6+
import { bapiRequest } from "../../lib/bapi.ts";
77
import { fapiRequest } from "../../lib/fapi.ts";
88
import { resolveFapiHost } from "./fapi.ts";
99
import {

packages/cli-core/src/commands/users/create.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mock.module("../../lib/bapi-command.ts", () => ({
1010
}));
1111

1212
const mockBapiRequest = mock();
13-
mock.module("../../commands/api/bapi.ts", () => ({
13+
mock.module("../../lib/bapi.ts", () => ({
1414
bapiRequest: (...args: unknown[]) => mockBapiRequest(...args),
1515
}));
1616

packages/cli-core/src/commands/users/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
redactUsersDisplayPayload,
1010
} from "../../lib/users.ts";
1111
import { isAgent, isHuman } from "../../mode.ts";
12-
import { bapiRequest } from "../api/bapi.ts";
12+
import { bapiRequest } from "../../lib/bapi.ts";
1313
import { withSpinner, intro, outro, pausedOutro } from "../../lib/spinner.ts";
1414
import { handleUsersBapiError, printUsersMutationResult } from "./output.ts";
1515
import { registerUsersAction } from "./registry.ts";

packages/cli-core/src/commands/users/interactive/pick-user.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { test, expect, describe, beforeEach, mock } from "bun:test";
33
const mockBapiRequest = mock();
44
const mockSearch = mock();
55

6-
mock.module("../../api/bapi.ts", () => ({
6+
mock.module("../../../lib/bapi.ts", () => ({
77
bapiRequest: (...args: unknown[]) => mockBapiRequest(...args),
88
}));
99
mock.module("../../../lib/listage.ts", () => ({

packages/cli-core/src/commands/users/interactive/pick-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { search, Separator } from "../../../lib/listage.ts";
2-
import { bapiRequest } from "../../api/bapi.ts";
2+
import { bapiRequest } from "../../../lib/bapi.ts";
33

44
export type PickUserOptions = {
55
secretKey: string;

packages/cli-core/src/commands/users/lifecycle-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { log } from "../../lib/log.ts";
99
import { confirm } from "../../lib/prompts.ts";
1010
import { withSpinner } from "../../lib/spinner.ts";
1111
import { isHuman } from "../../mode.ts";
12-
import { bapiRequest } from "../api/bapi.ts";
12+
import { bapiRequest } from "../../lib/bapi.ts";
1313
import { handleUsersBapiError, printUsersMutationSuccess } from "./output.ts";
1414

1515
export type UserLifecycleOptions = {

packages/cli-core/src/commands/users/list.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { popPrefix, pushPrefix } from "../../lib/log.ts";
44
import { useCaptureLog } from "../../test/lib/stubs.ts";
55

66
const mockBapiRequest = mock();
7-
mock.module("../../commands/api/bapi.ts", () => ({
7+
mock.module("../../lib/bapi.ts", () => ({
88
bapiRequest: (...args: unknown[]) => mockBapiRequest(...args),
99
}));
1010

packages/cli-core/src/commands/users/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CliError, ERROR_CODE, UserAbortError, isPromptExitError } from "../../l
44
import { isInsideGutter, log } from "../../lib/log.ts";
55
import { isAgent, isHuman } from "../../mode.ts";
66
import { withSpinner, intro, outro, pausedOutro } from "../../lib/spinner.ts";
7-
import { bapiRequest } from "../api/bapi.ts";
7+
import { bapiRequest } from "../../lib/bapi.ts";
88
import { resolveUsersInstanceContext } from "./interactive/instance-context.ts";
99
import { registerUsersAction } from "./registry.ts";
1010

0 commit comments

Comments
 (0)