Files
windmill/typescript-client/build.sh
T
Diego Imbert 7e1c1fa3a4 feat(apps): use the windmill-client SDK from raw app frontend code (#10377)
* feat(apps): use the windmill-client SDK from raw app frontend code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): bound the raw app SDK token to deployed runnables

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): deny dependency jobs and survive a failed SDK mint

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): confine the SDK token's users scope to the viewer's identity

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* docs: describe the full raw-app SDK sentinel narrowing

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): deny workflow-as-code replay for raw app SDK tokens

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): deny preview-flow restart replay for raw app SDK tokens

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): re-prompt when an app widens its SDK scopes mid-consent

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* feat(apps): support the frontend SDK in sandboxed raw apps

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): hand the sandboxed SDK token over only once per loaded document

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): bind the sandboxed SDK handoff to the document we loaded

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): use an unguessable nonce for the sandboxed SDK handoff

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): reply to the sandboxed SDK handshake over its own port

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): answer the raw app handshake only over a transferred port

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): set frontend_sdk_scopes in the S3-gated policy literals

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* docs: describe the sandboxed wrapper's credential as it now works

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* ui nit

* feat(apps): make the frontend SDK work in the raw app editor preview

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): guard the preview token mint and drop superseded responses

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): refuse job tokens on every raw app SDK mint path

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* docs: correct the mint caller list and the preview retry rationale

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): apply the consent response's render mode before rendering

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): restart the viewer when a redeploy changes the render mode

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): restart on every render-mode change, not just the first

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): clear the preview's SDK credential when scopes go away

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): remove window.process in the preview instead of blanking it

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* docs: cut the raw app SDK comments down to the invariant

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* refactor(apps): use randomUUID for the raw app handshake nonce

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): re-read the render mode before rendering without a token

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* fix(apps): make the raw app handshake nonce unguessable again

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* chore: pin the EE ref to a commit that builds against this OSS tree

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Gmsk9kAG7p9t2Qy6ADRJz

* refactor(apps): authenticate the raw app preview by session instead of a token

The editor preview is same-origin and unsandboxed, so app code there already
holds the editing user's session cookie. Minting a scoped bearer for it added
an endpoint and a portable 12h credential without containing anything.

Inject only BASE_URL and WM_WORKSPACE: `windmill-client` falls back to
credentialed same-origin requests when it finds no token, so the SDK runs as
the editing user. Drops POST /apps/preview_sdk_token and the mint/race
handling in the editor.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* fix(sdk): send credentials only outside the browser

The API answers `Access-Control-Allow-Origin: *` and never sets
`allow_credentials`, so a credentialed cross-origin request fails before the
bearer is read — which is what a sandboxed raw app issues. Keying this on the
browser rather than on `WM_TOKEN` leaves non-browser callers byte-identical,
and browsers keep sending cookies same-origin through fetch's own default.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* remove windmill-client from templates

* fix(sdk): drop credentials only for raw app bundles

A sandboxed raw app calls the API from an opaque origin, and the API answers
`Access-Control-Allow-Origin: *`, which a credentialed request can never pair
with. Gate on WM_RAW_APP, set by the two places that build a raw app's
`window.process.env`, so every other windmill-client consumer is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* feat(apps): make frontend SDK access sandbox-only

An unsandboxed bundle runs same-origin with the viewer's full session, so a
consent prompt there implies a boundary that does not exist and the token adds
nothing it could not already do. Advertise scopes and mint only when isolation
is on; turning the toggle off clears the declared scopes with it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* Revert "refactor(apps): authenticate the raw app preview by session instead of a token"

This reverts commit 81905e455b, restoring POST /apps/preview_sdk_token.

Session auth gave the preview the editing user's full permissions and worked
regardless of policy, so an app that would 403 for a viewer — or that declares
no scopes at all — ran fine in the preview and broke only once deployed. The
preview now takes the same credential as a deployed app, gated the same way:
sandbox off or no scopes means no env at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* docs(apps): state the sandbox-only SDK contract in the public schema

The Policy and EmbedTokenResponse descriptions still promised a token to any
raw app with non-empty scopes, and said raw apps skip tokens entirely. Point
authors at adding windmill-client themselves too, since the starter templates
no longer carry it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* fix(apps): drop the preview token before minting its replacement

A mint is asynchronous, so clearing the env only on the empty-scope path left
the running preview — and any build fed meanwhile — holding scopes the policy
had just removed, or a token for the workspace just left, for as long as the
request took.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* fix(apps): restart the preview realm when its credential changes

Re-feeding the build resets the preview's DOM but keeps its JavaScript realm,
so the previous bundle's timers, listeners and pending callbacks went on using
the client they imported — and the token it captured at module load — after the
policy dropped it. Reload both shells instead; each replays the build on its
way back, so only the new realm survives.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* fix(apps): start the preview once per credential change

Restarting the realm made its shell replay the build immediately, so a delayed
mint ran the app once tokenless and again tokenful — mount-time side effects
twice per scope or workspace change. Hold the build back until the mint
settles: the shell comes back blank and whichever finishes last starts the app.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* fix(apps): wait for the detached preview shell before replaying

Its reload was only initiated, never awaited — unlike the inline iframe it had
no readiness flag — so a mint settling first posted the build to the retiring
document, which then ran alongside the replacement shell's own replay. Track
readiness from both paths that announce it: `load` for a freshly opened window,
`appPreviewReady` for a reload.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPCW1WB5QeYrgJmgwcywNA

* chore: update ee-repo-ref to 99e143fa1e2e6c33b3525366a5afe48f7a4f020e

This commit updates the EE repository reference after PR #688 was merged in windmill-ee-private.

Previous ee-repo-ref: 609e197fbc08f1ce83dd86f816748cc19d213f77

New ee-repo-ref: 99e143fa1e2e6c33b3525366a5afe48f7a4f020e

Automated by sync-ee-ref workflow.

* nit better description

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2026-08-03 19:31:57 +00:00

233 lines
6.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eou pipefail
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
rm -rf "${script_dirpath}/src"
npx --yes @hey-api/openapi-ts@0.43.0 --input "${script_dirpath}/../backend/windmill-api/openapi.yaml" --output "${script_dirpath}/src" --useOptions --schemas false
cat <<EOF - src/core/OpenAPI.ts > temp_file && mv temp_file src/core/OpenAPI.ts
const getEnv = (key: string) => {
if (typeof window === "undefined") {
// \`typeof\` first: where \`process\` is undeclared entirely (web worker), even
// \`process?.env\` throws a ReferenceError.
if (typeof process !== "undefined") {
return process?.env?.[key];
}
return globalThis?.process?.env?.[key];
}
// browser
return window?.process?.env?.[key];
};
const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000";
const baseUrlApi = (baseUrl ?? '') + "/api";
EOF
# Windmill's raw app wrapper sets WM_RAW_APP: such a bundle may call the API
# cross-origin (sandboxed apps run on an opaque origin), and the API answers
# `Access-Control-Allow-Origin: *`, which a credentialed request can never pair
# with. Every other consumer keeps credentials on.
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: !getEnv("WM_RAW_APP")/g' src/core/OpenAPI.ts
sed -i '' 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' src/core/OpenAPI.ts
sed -i '' "s/BASE: '\/api'/BASE: baseUrlApi/g" src/core/OpenAPI.ts
else
sed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: !getEnv("WM_RAW_APP")/g' src/core/OpenAPI.ts
sed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' src/core/OpenAPI.ts
sed -i "s/BASE: '\/api'/BASE: baseUrlApi/g" src/core/OpenAPI.ts
fi
cp "${script_dirpath}/client.ts" "${script_dirpath}/src/"
cp "${script_dirpath}/wacError.ts" "${script_dirpath}/src/"
cp "${script_dirpath}/s3Types.ts" "${script_dirpath}/src/"
cp "${script_dirpath}/sqlUtils.ts" "${script_dirpath}/src/"
echo "" >> "${script_dirpath}/src/index.ts"
echo 'export type { DenoS3LightClientSettings } from "./s3Types";' >> "${script_dirpath}/src/index.ts"
echo "" >> "${script_dirpath}/src/index.ts"
echo 'export { type Base64, setClient, getVariable, setVariable, getResource, setResource, getResumeUrls, setState, setProgress, getProgress, getState, getIdToken, denoS3LightClientSettings, loadS3FileStream, loadS3File, writeS3File, deleteS3File, signS3Objects, signS3Object, getPresignedS3PublicUrls, getPresignedS3PublicUrl, task, taskScript, taskFlow, workflow, step, sleep, parallel, waitForApproval, getApprovalUrls, type TaskOptions, type Jsonified, type JsonifiedFn, WorkflowCtx, _workflowCtx, setWorkflowCtx, StepSuspend, runScript, runScriptAsync, runScriptByPath, runScriptByHash, runScriptByPathAsync, runScriptByHashAsync, runFlow, runFlowAsync, waitJob, getRootJobId, setFlowUserState, getFlowUserState, usernameToEmail, requestInteractiveSlackApproval, type Sql, requestInteractiveTeamsApproval, appendToResultStream, streamResult, datatable, ducklake, upsertPartition, appendPartition, type DucklakeMaterializeOptions, type SqlStatement, type DatatableSqlTemplateFunction, type SqlTemplateFunction, type S3Object, type S3ObjectRecord, type S3ObjectURI, commitKafkaOffsets } from "./client";' >> "${script_dirpath}/src/index.ts"
# Build default export by combining client utilities + services
# This preserves backward compatibility for `import wmill from "windmill-client"`
# while enabling tree-shaking for named imports
cat >> "${script_dirpath}/src/index.ts" << 'INDEXEOF'
import {
setClient,
getVariable,
setVariable,
getResource,
setResource,
getResumeUrls,
setState,
setProgress,
getProgress,
getState,
getIdToken,
denoS3LightClientSettings,
loadS3FileStream,
loadS3File,
writeS3File,
deleteS3File,
signS3Objects,
signS3Object,
getPresignedS3PublicUrls,
getPresignedS3PublicUrl,
task,
taskScript,
taskFlow,
workflow,
step,
sleep,
parallel,
waitForApproval,
getApprovalUrls,
WorkflowCtx,
_workflowCtx,
setWorkflowCtx,
StepSuspend,
runScript,
runScriptAsync,
runScriptByPath,
runScriptByHash,
runScriptByPathAsync,
runScriptByHashAsync,
runFlow,
runFlowAsync,
waitJob,
getRootJobId,
setFlowUserState,
getFlowUserState,
usernameToEmail,
requestInteractiveSlackApproval,
requestInteractiveTeamsApproval,
appendToResultStream,
streamResult,
datatable,
ducklake,
upsertPartition,
appendPartition,
SHARED_FOLDER,
getWorkspace,
getStatePath,
getInternalState,
setInternalState,
getResumeEndpoints,
getResult,
getResultMaybe,
resolveDefaultResource,
databaseUrlFromResource,
base64ToUint8Array,
uint8ArrayToBase64,
parseS3Object,
commitKafkaOffsets,
} from "./client";
import {
AdminService,
AuditService,
FlowService,
GranularAclService,
GroupService,
JobService,
ResourceService,
VariableService,
ScriptService,
ScheduleService,
SettingsService,
UserService,
WorkspaceService,
TeamsService,
} from "./services.gen";
const wmill = {
// Client utilities
setClient,
getVariable,
setVariable,
getResource,
setResource,
getResumeUrls,
setState,
setProgress,
getProgress,
getState,
getIdToken,
denoS3LightClientSettings,
loadS3FileStream,
loadS3File,
writeS3File,
deleteS3File,
signS3Objects,
signS3Object,
getPresignedS3PublicUrls,
getPresignedS3PublicUrl,
task,
taskScript,
taskFlow,
workflow,
step,
sleep,
parallel,
waitForApproval,
getApprovalUrls,
WorkflowCtx,
_workflowCtx,
setWorkflowCtx,
StepSuspend,
runScript,
runScriptAsync,
runScriptByPath,
runScriptByHash,
runScriptByPathAsync,
runScriptByHashAsync,
runFlow,
runFlowAsync,
waitJob,
getRootJobId,
setFlowUserState,
getFlowUserState,
usernameToEmail,
requestInteractiveSlackApproval,
requestInteractiveTeamsApproval,
appendToResultStream,
streamResult,
datatable,
ducklake,
upsertPartition,
appendPartition,
SHARED_FOLDER,
getWorkspace,
getStatePath,
getInternalState,
setInternalState,
getResumeEndpoints,
getResult,
getResultMaybe,
resolveDefaultResource,
databaseUrlFromResource,
base64ToUint8Array,
uint8ArrayToBase64,
parseS3Object,
commitKafkaOffsets,
// Services
AdminService,
AuditService,
FlowService,
GranularAclService,
GroupService,
JobService,
ResourceService,
VariableService,
ScriptService,
ScheduleService,
SettingsService,
UserService,
WorkspaceService,
TeamsService,
};
export default wmill;
INDEXEOF