Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/free-breads-pick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion .claude/rules/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ const config = await withApiContext(

## API error classes

`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.
`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.
2 changes: 1 addition & 1 deletion packages/cli-core/src/commands/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAuthToken } from "../../lib/plapi.ts";
import { getBapiBaseUrl, getPlapiBaseUrl } from "../../lib/environment.ts";
import { normalizeBapiPath, resolveBapiSecretKey } from "../../lib/bapi-command.ts";
import { type ApiResponse } from "../../lib/fetch.ts";
import { bapiRequest } from "./bapi.ts";
import { bapiRequest } from "../../lib/bapi.ts";
import { fapiRequest } from "../../lib/fapi.ts";
import { resolveFapiHost } from "./fapi.ts";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/commands/users/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mock.module("../../lib/bapi-command.ts", () => ({
}));

const mockBapiRequest = mock();
mock.module("../../commands/api/bapi.ts", () => ({
mock.module("../../lib/bapi.ts", () => ({
bapiRequest: (...args: unknown[]) => mockBapiRequest(...args),
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/commands/users/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
redactUsersDisplayPayload,
} from "../../lib/users.ts";
import { isAgent, isHuman } from "../../mode.ts";
import { bapiRequest } from "../api/bapi.ts";
import { bapiRequest } from "../../lib/bapi.ts";
import { withSpinner, intro, outro, pausedOutro } from "../../lib/spinner.ts";
import { handleUsersBapiError, printUsersMutationResult } from "./output.ts";
import { registerUsersAction } from "./registry.ts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test, expect, describe, beforeEach, mock } from "bun:test";
const mockBapiRequest = mock();
const mockSearch = mock();

mock.module("../../api/bapi.ts", () => ({
mock.module("../../../lib/bapi.ts", () => ({
bapiRequest: (...args: unknown[]) => mockBapiRequest(...args),
}));
mock.module("../../../lib/listage.ts", () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { search, Separator } from "../../../lib/listage.ts";
import { bapiRequest } from "../../api/bapi.ts";
import { bapiRequest } from "../../../lib/bapi.ts";

export type PickUserOptions = {
secretKey: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/commands/users/lifecycle-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { log } from "../../lib/log.ts";
import { confirm } from "../../lib/prompts.ts";
import { withSpinner } from "../../lib/spinner.ts";
import { isHuman } from "../../mode.ts";
import { bapiRequest } from "../api/bapi.ts";
import { bapiRequest } from "../../lib/bapi.ts";
import { handleUsersBapiError, printUsersMutationSuccess } from "./output.ts";

export type UserLifecycleOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/commands/users/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { popPrefix, pushPrefix } from "../../lib/log.ts";
import { useCaptureLog } from "../../test/lib/stubs.ts";

const mockBapiRequest = mock();
mock.module("../../commands/api/bapi.ts", () => ({
mock.module("../../lib/bapi.ts", () => ({
bapiRequest: (...args: unknown[]) => mockBapiRequest(...args),
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/commands/users/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CliError, ERROR_CODE, UserAbortError, isPromptExitError } from "../../l
import { isInsideGutter, log } from "../../lib/log.ts";
import { isAgent, isHuman } from "../../mode.ts";
import { withSpinner, intro, outro, pausedOutro } from "../../lib/spinner.ts";
import { bapiRequest } from "../api/bapi.ts";
import { bapiRequest } from "../../lib/bapi.ts";
import { resolveUsersInstanceContext } from "./interactive/instance-context.ts";
import { registerUsersAction } from "./registry.ts";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
import { stubFetch } from "../../test/lib/stubs.ts";
import { stubFetch } from "../test/lib/stubs.ts";
import { bapiRequest } from "./bapi.ts";
import { BapiError } from "../../lib/errors.ts";
import { BapiError } from "./errors.ts";

describe("bapi", () => {
const originalFetch = globalThis.fetch;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Backend API (BAPI) client.
* Thin HTTP wrapper for Clerk's Backend API endpoints.
* Thin HTTP wrapper for Clerk's Backend API endpoints. Sibling to lib/fapi.ts.
*/

import { getBapiBaseUrl } from "../../lib/environment.ts";
import { normalizeBapiPath } from "../../lib/bapi-command.ts";
import { BapiError } from "../../lib/errors.ts";
import { loggedFetch, type ApiResponse } from "../../lib/fetch.ts";
import { getBapiBaseUrl } from "./environment.ts";
import { normalizeBapiPath } from "./bapi-command.ts";
import { BapiError } from "./errors.ts";
import { loggedFetch, type ApiResponse } from "./fetch.ts";

export async function bapiRequest(options: {
method: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class FapiError extends ApiError {
/**
* Error from the Clerk Backend API (BAPI).
*
* Thrown by `src/commands/api/bapi.ts` when a Backend API request fails.
* Thrown by `src/lib/bapi.ts` when a Backend API request fails.
* Displayed as "Backend API request failed" in the global error handler.
* Unlike {@link PlapiError}, `headers` is always present (required).
*
Expand Down