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
7 changes: 7 additions & 0 deletions .changeset/preview-secret-per-preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": minor
---

Use Preview deployment PATCH APIs for Preview secret commands

Wrangler now updates Worker Preview secrets by patching the named Preview's latest deployment instead of patching the Worker's Previews settings. This keeps secret changes scoped to one Preview, avoids affecting production or other Previews, and creates a new Preview deployment that goes live at 100% immediately. `wrangler preview secret list` now reads from the named Preview's latest deployment and prints secret names with values masked. `wrangler preview secret bulk` now deletes a secret when its value is `null`, matching `wrangler secret bulk`.
27 changes: 26 additions & 1 deletion packages/deploy-helpers/src/preview/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export async function getPreviewDeployment(
accountId: string,
workerName: string,
previewIdentifier: string,
deploymentIdentifier: string
deploymentIdentifier = "latest"
): Promise<DeploymentResource> {
return fetchResult<DeploymentResource>(
config,
Expand Down Expand Up @@ -266,6 +266,31 @@ export async function createPreviewDeployment(
);
}

export async function patchPreviewDeployment(
config: Config,
accountId: string,
workerName: string,
previewIdentifier: string,
env: Record<string, Binding | null>,
annotations?: {
"workers/message"?: string;
"workers/tag"?: string;
},
deploymentIdentifier = "latest"
): Promise<DeploymentResource> {
return fetchResult<DeploymentResource>(
config,
`/accounts/${accountId}/workers/workers/${workerName}/previews/${encodeURIComponent(
previewIdentifier
)}/deployments/${encodeURIComponent(deploymentIdentifier)}`,
{
method: "PATCH",
headers: { "Content-Type": "application/merge-patch+json" },
body: JSON.stringify({ env, annotations }),
}
);
}

export async function getWorkerPreviewDefaults(
config: Config,
accountId: string,
Expand Down
Loading