Skip to content

Commit 2f4628c

Browse files
committed
refactor(plapi): allow null active_domain and guard in deploy wizard
1 parent 1dc279f commit 2f4628c

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

packages/cli-core/src/commands/deploy/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,30 @@ describe("deploy", () => {
708708
});
709709
});
710710

711+
test("throws a CliError when createProductionInstance returns no active_domain", async () => {
712+
await linkedProject();
713+
mockIsAgent.mockReturnValue(false);
714+
mockConfirm.mockResolvedValueOnce(true).mockResolvedValueOnce(true);
715+
mockInput.mockResolvedValueOnce("example.com");
716+
mockCreateProductionInstance.mockResolvedValueOnce({
717+
instance_id: "ins_prod_mock",
718+
environment_type: "production" as const,
719+
active_domain: null,
720+
publishable_key: "pk_live_test",
721+
secret_key: "sk_live_test",
722+
cname_targets: [],
723+
});
724+
725+
let thrown: unknown;
726+
try {
727+
await runDeploy({});
728+
} catch (e) {
729+
thrown = e;
730+
}
731+
expect(thrown).toBeInstanceOf(CliError);
732+
expect((thrown as CliError).message).toContain("did not return a domain");
733+
});
734+
711735
test("Ctrl-C at the DNS handoff reports paused", async () => {
712736
await linkedProject();
713737
mockIsAgent.mockReturnValue(false);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isAgent } from "../../mode.ts";
22
import { isInsideGutter, log } from "../../lib/log.ts";
33
import { sleep } from "../../lib/sleep.ts";
44
import { bar, intro, outro, withSpinner } from "../../lib/spinner.ts";
5-
import { UserAbortError, isPromptExitError, throwUsageError } from "../../lib/errors.ts";
5+
import { CliError, UserAbortError, isPromptExitError, throwUsageError } from "../../lib/errors.ts";
66
import { resolveProfile, setProfile } from "../../lib/config.ts";
77
import {
88
createProductionInstance as apiCreateProductionInstance,
@@ -217,6 +217,14 @@ async function startNewDeploy(ctx: DeployContext): Promise<void> {
217217
}
218218
const production = productionOrExists;
219219
await persistProductionInstance(ctx, production.instance_id);
220+
221+
if (!production.active_domain) {
222+
throw new CliError(
223+
"Production instance was created but Clerk did not return a domain. " +
224+
"Run `clerk deploy` again to retry domain provisioning.",
225+
);
226+
}
227+
220228
log.blank();
221229

222230
const productionDomain = production.active_domain.name;

packages/cli-core/src/lib/plapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export type ListApplicationDomainsResponse = {
174174
export type ProductionInstanceResponse = {
175175
instance_id: string;
176176
environment_type: "production";
177-
active_domain: DomainSummary;
177+
active_domain: DomainSummary | null;
178178
secret_key?: string;
179179
publishable_key: string;
180180
cname_targets: CnameTarget[];

0 commit comments

Comments
 (0)