windmill-cli 1.804.0 → 1.805.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/esm/main.js +299 -229
  2. package/package.json +1 -1
package/esm/main.js CHANGED
@@ -16766,7 +16766,7 @@ var init_OpenAPI = __esm(() => {
16766
16766
  PASSWORD: undefined,
16767
16767
  TOKEN: getEnv3("WM_TOKEN"),
16768
16768
  USERNAME: undefined,
16769
- VERSION: "1.804.0",
16769
+ VERSION: "1.805.0",
16770
16770
  WITH_CREDENTIALS: true,
16771
16771
  interceptors: {
16772
16772
  request: new Interceptors,
@@ -19971,7 +19971,7 @@ var init_auth = __esm(async () => {
19971
19971
  });
19972
19972
 
19973
19973
  // src/core/constants.ts
19974
- var WM_FORK_PREFIX = "wm-fork", VERSION = "1.804.0";
19974
+ var WM_FORK_PREFIX = "wm-fork", VERSION = "1.805.0";
19975
19975
 
19976
19976
  // src/utils/git.ts
19977
19977
  import { execSync, spawnSync } from "node:child_process";
@@ -20709,7 +20709,7 @@ function getGitRepoRoot() {
20709
20709
  return null;
20710
20710
  }
20711
20711
  }
20712
- function findWmillYaml() {
20712
+ function locateWmillYaml() {
20713
20713
  const startDir = resolve5(process.cwd());
20714
20714
  const isInGitRepo = isGitRepository();
20715
20715
  const gitRoot = isInGitRepo ? getGitRepoRoot() : null;
@@ -20730,6 +20730,11 @@ function findWmillYaml() {
20730
20730
  }
20731
20731
  currentDir = parentDir;
20732
20732
  }
20733
+ return foundPath;
20734
+ }
20735
+ function findWmillYaml() {
20736
+ const startDir = resolve5(process.cwd());
20737
+ const foundPath = locateWmillYaml();
20733
20738
  if (!GLOBAL_CONFIG_OPT.noCdToRoot && foundPath && resolve5(dirname6(foundPath)) !== resolve5(startDir)) {
20734
20739
  const configDir = dirname6(foundPath);
20735
20740
  const relativePath = relative4(startDir, foundPath);
@@ -20742,6 +20747,24 @@ function findWmillYaml() {
20742
20747
  function getWmillYamlPath() {
20743
20748
  return findWmillYaml();
20744
20749
  }
20750
+ async function peekWorkspaceEntry(workspaceName) {
20751
+ if (RESERVED_WORKSPACE_KEYS.has(workspaceName)) {
20752
+ return;
20753
+ }
20754
+ const wmillYamlPath = locateWmillYaml();
20755
+ if (!wmillYamlPath) {
20756
+ return;
20757
+ }
20758
+ try {
20759
+ const conf = await yamlParseFile(wmillYamlPath);
20760
+ const workspaces = conf?.workspaces ?? conf?.gitBranches ?? conf?.environments ?? conf?.git_branches;
20761
+ const entry = workspaces?.[workspaceName];
20762
+ return typeof entry === "object" && entry !== null ? entry : undefined;
20763
+ } catch (e) {
20764
+ debug(`Failed to parse ${wmillYamlPath} for workspace lookup: ${e}`);
20765
+ return;
20766
+ }
20767
+ }
20745
20768
  async function readConfigFile(opts) {
20746
20769
  const warnIfMissing = opts?.warnIfMissing ?? true;
20747
20770
  try {
@@ -20965,6 +20988,48 @@ async function getEffectiveSettings(config, promotion, skipBranchValidation, sup
20965
20988
  }
20966
20989
  return effective;
20967
20990
  }
20991
+ function resolveWsNameFromBranch(opts, branchName) {
20992
+ const match = findWorkspaceByGitBranch(opts.workspaces, branchName);
20993
+ return match ? match[0] : branchName;
20994
+ }
20995
+ function resolveWsNameForConfigFromFlags(opts) {
20996
+ if (opts.branch) {
20997
+ return resolveWsNameFromBranch(opts, opts.branch);
20998
+ }
20999
+ if (opts.workspace) {
21000
+ const validKeys = getWorkspaceNames(opts.workspaces);
21001
+ if (validKeys.includes(opts.workspace)) {
21002
+ return opts.workspace;
21003
+ }
21004
+ }
21005
+ return;
21006
+ }
21007
+ function inferWsNameFromProfile(opts, profile) {
21008
+ if (!opts.workspaces)
21009
+ return;
21010
+ for (const name of getWorkspaceNames(opts.workspaces)) {
21011
+ const entry = opts.workspaces[name];
21012
+ if (!entry?.baseUrl)
21013
+ continue;
21014
+ try {
21015
+ const entryUrl = new URL(entry.baseUrl).toString();
21016
+ const profileUrl = new URL(profile.remote).toString();
21017
+ const entryWsId = entry.workspaceId ?? name;
21018
+ if (entryUrl === profileUrl && entryWsId === profile.workspaceId) {
21019
+ return name;
21020
+ }
21021
+ } catch {
21022
+ continue;
21023
+ }
21024
+ }
21025
+ return;
21026
+ }
21027
+ async function readEffectiveSyncBehavior(opts, profile) {
21028
+ const config = await readConfigFile({ warnIfMissing: false });
21029
+ const named = resolveWsNameForConfigFromFlags({ ...config, ...opts });
21030
+ const effective = await getEffectiveSettings(config, undefined, false, true, named ?? (profile ? inferWsNameFromProfile(config, profile) : undefined));
21031
+ return effective.syncBehavior;
21032
+ }
20968
21033
  function findWorkspaceByGitBranch(workspaces, branchName) {
20969
21034
  if (!workspaces)
20970
21035
  return;
@@ -23661,6 +23726,7 @@ async function tryResolveWorkspace(opts) {
23661
23726
  if (opts.workspace) {
23662
23727
  const config = await readConfigFile({ warnIfMissing: false });
23663
23728
  const wsEntry = config.workspaces?.[opts.workspace];
23729
+ let configuredTarget;
23664
23730
  if (wsEntry?.baseUrl) {
23665
23731
  const workspaceId = getEffectiveWorkspaceId(opts.workspace, wsEntry);
23666
23732
  let normalizedBaseUrl;
@@ -23672,6 +23738,7 @@ async function tryResolveWorkspace(opts) {
23672
23738
  error: colors.red.underline(`Invalid baseUrl in workspace '${opts.workspace}' configuration: ${wsEntry.baseUrl}`)
23673
23739
  };
23674
23740
  }
23741
+ configuredTarget = { workspaceId, baseUrl: normalizedBaseUrl };
23675
23742
  const allProfs = await allWorkspaces(opts.configDir);
23676
23743
  const matching = allProfs.filter((w) => w.remote === normalizedBaseUrl && w.workspaceId === workspaceId);
23677
23744
  if (matching.length >= 1) {
@@ -23694,6 +23761,12 @@ async function tryResolveWorkspace(opts) {
23694
23761
  error: colors.red.underline(`Workspace '${opts.workspace}' not found in wmill.yaml config or local profiles.`)
23695
23762
  };
23696
23763
  }
23764
+ if (configuredTarget && (e.workspaceId !== configuredTarget.workspaceId || e.remote !== configuredTarget.baseUrl)) {
23765
+ warnStderr(colors.yellow(`⚠️ Falling back to the local profile named '${opts.workspace}' (${e.workspaceId} on ${e.remote}), which does NOT match wmill.yaml:
23766
+ ` + ` wmill.yaml maps workspace '${opts.workspace}' to ${configuredTarget.workspaceId} on ${configuredTarget.baseUrl}, but no profile targets it.
23767
+ ` + ` Run: wmill workspace add <profile-name> ${configuredTarget.workspaceId} ${configuredTarget.baseUrl}`));
23768
+ }
23769
+ infoStderr(`Using local profile '${e.name}' → ${e.workspaceId} on ${e.remote}`);
23697
23770
  opts.__secret_workspace = e;
23698
23771
  return { isError: false, value: e };
23699
23772
  }
@@ -23813,6 +23886,7 @@ async function resolveWorkspace(opts, workspaceNameOverride) {
23813
23886
  infoStderr(colors.red(`Invalid base URL: ${opts.baseUrl}`));
23814
23887
  return process.exit(-1);
23815
23888
  }
23889
+ let resolved;
23816
23890
  if (opts.workspace) {
23817
23891
  let existingWorkspace = await getWorkspaceByName(opts.workspace, opts.configDir);
23818
23892
  if (!existingWorkspace) {
@@ -23828,18 +23902,28 @@ async function resolveWorkspace(opts, workspaceNameOverride) {
23828
23902
  infoStderr(colors.red(`Base URL mismatch: --base-url is ${normalizedBaseUrl} but workspace profile "${opts.workspace}" uses ${existingWorkspace.remote}`));
23829
23903
  return process.exit(-1);
23830
23904
  }
23831
- return {
23905
+ resolved = {
23832
23906
  ...existingWorkspace,
23833
23907
  token: opts.token
23834
23908
  };
23835
23909
  }
23836
23910
  }
23837
- return {
23911
+ resolved ??= {
23838
23912
  remote: normalizedBaseUrl,
23839
23913
  workspaceId: opts.workspace,
23840
23914
  name: opts.workspace,
23841
23915
  token: opts.token
23842
23916
  };
23917
+ const yamlEntry = await peekWorkspaceEntry(opts.workspace);
23918
+ const yamlWorkspaceId = yamlEntry?.workspaceId;
23919
+ if (yamlWorkspaceId && yamlWorkspaceId !== resolved.workspaceId) {
23920
+ warnStderr(colors.yellow(`⚠️ --base-url is set, so wmill.yaml is not consulted: workspace id '${resolved.workspaceId}' is sent to the API.
23921
+ wmill.yaml maps workspace '${opts.workspace}' to workspace id '${yamlWorkspaceId}'${yamlEntry.baseUrl ? ` on ${yamlEntry.baseUrl}` : ""}.
23922
+ Use '--workspace ${yamlWorkspaceId}', or drop --base-url/--token to resolve through wmill.yaml.`));
23923
+ }
23924
+ infoStderr(`Using workspace id '${resolved.workspaceId}' on ${normalizedBaseUrl} (--base-url given` + (resolved.name !== resolved.workspaceId ? `, profile '${resolved.name}')` : ")"));
23925
+ opts.__secret_workspace = resolved;
23926
+ return resolved;
23843
23927
  } else {
23844
23928
  infoStderr(colors.red("If you specify a base URL with --base-url, you must also specify a workspace (--workspace) and token (--token)."));
23845
23929
  return process.exit(-1);
@@ -45156,7 +45240,10 @@ async function downloadZip(workspace, plainSecrets, skipVariables, skipResources
45156
45240
  return process.exit(1);
45157
45241
  }
45158
45242
  if (zipResponse.status === 404 || body.includes("no rows returned")) {
45159
- info(colors.red(`Workspace '${workspace.workspaceId}' not found on ${workspace.remote}. Please check your --workspace and try again.`));
45243
+ info(colors.red(`Workspace id '${workspace.workspaceId}' not found on ${workspace.remote}` + (workspace.name !== workspace.workspaceId ? ` (resolved from profile '${workspace.name}')` : "") + `.
45244
+ ` + `Note this is the workspace *id* sent to the API, which is not necessarily what you passed to --workspace:
45245
+ ` + ` - check 'wmill workspace list' (the 'workspace id' column)
45246
+ ` + ` - check the 'workspaces' block of wmill.yaml ('workspaceId' overrides the workspace name)`));
45160
45247
  } else {
45161
45248
  info(colors.red(`Failed to request tarball from API: ${zipResponse.status} ${zipResponse.statusText}`));
45162
45249
  if (body)
@@ -56286,7 +56373,7 @@ var init_openflow = __esm(() => {
56286
56373
  openflow_default = {
56287
56374
  openapi: "3.0.3",
56288
56375
  info: {
56289
- version: "1.804.0",
56376
+ version: "1.805.0",
56290
56377
  title: "OpenFlow Spec",
56291
56378
  contact: {
56292
56379
  name: "Ruben Fiszel",
@@ -60033,6 +60120,163 @@ var init_src = __esm(() => {
60033
60120
  init_validation();
60034
60121
  });
60035
60122
 
60123
+ // src/core/permissioned_as.ts
60124
+ async function buildPermissionedAsContext(workspace, syncBehavior) {
60125
+ if (parseSyncBehavior(syncBehavior) < 1) {
60126
+ return;
60127
+ }
60128
+ const user = await whoami({ workspace });
60129
+ const userIsAdminOrDeployer = user.is_admin || (user.groups ?? []).includes("wm_deployers");
60130
+ debug(`permissioned_as: user=${user.email}, is_admin=${user.is_admin}, groups=${JSON.stringify(user.groups)}, isAdminOrDeployer=${userIsAdminOrDeployer}`);
60131
+ return {
60132
+ userCache: new Map,
60133
+ userIsAdminOrDeployer,
60134
+ userEmail: user.email
60135
+ };
60136
+ }
60137
+ async function ensureUserCache(workspace, cache) {
60138
+ if (cache.size > 0)
60139
+ return;
60140
+ const users = await listUsers({ workspace });
60141
+ for (const user of users) {
60142
+ cache.set(user.username, { username: user.username, email: user.email });
60143
+ cache.set(user.email, { username: user.username, email: user.email });
60144
+ }
60145
+ }
60146
+ async function lookupUsernameByEmail(workspace, email, cache) {
60147
+ await ensureUserCache(workspace, cache);
60148
+ const entry = cache.get(email);
60149
+ if (!entry) {
60150
+ throw new Error(`Could not find username for email '${email}' in workspace. ` + `Make sure the user exists in the workspace.`);
60151
+ }
60152
+ return entry.username;
60153
+ }
60154
+ function contentHasOnBehalfOf(content, typeStr) {
60155
+ if (typeStr === "script") {
60156
+ return !!content.match(/has_on_behalf_of:\s*(true)/) || !!content.match(/on_behalf_of_email:\s*["']?([^\s"']+)["']?/);
60157
+ }
60158
+ if (typeStr === "flow") {
60159
+ return !!content.match(/has_on_behalf_of:\s*(true)/);
60160
+ }
60161
+ return false;
60162
+ }
60163
+ async function preCheckPermissionedAs(changes, userEmail, userIsAdminOrDeployer, acceptOverride, isInteractive) {
60164
+ if (userIsAdminOrDeployer)
60165
+ return;
60166
+ const wouldChangeItems = [];
60167
+ for (const change of changes) {
60168
+ let typeStr;
60169
+ try {
60170
+ typeStr = getTypeStrFromPath(change.path);
60171
+ } catch {
60172
+ continue;
60173
+ }
60174
+ if (change.name === "added") {
60175
+ const content = change.content;
60176
+ if (!content)
60177
+ continue;
60178
+ const isScriptMeta = typeStr === "script" && (change.path.endsWith(".script.yaml") || change.path.endsWith(".script.json"));
60179
+ const isFlowMeta = typeStr === "flow" && (change.path.endsWith("flow.yaml") || change.path.endsWith("flow.json"));
60180
+ if ((isScriptMeta || isFlowMeta) && contentHasOnBehalfOf(content, typeStr)) {
60181
+ const label = typeStr === "script" ? "(script owner)" : "(flow owner)";
60182
+ wouldChangeItems.push({ path: change.path, currentOwner: label });
60183
+ } else if (typeStr === "app") {
60184
+ wouldChangeItems.push({
60185
+ path: change.path,
60186
+ currentOwner: "(app policy owner)"
60187
+ });
60188
+ }
60189
+ continue;
60190
+ }
60191
+ if (change.name !== "edited")
60192
+ continue;
60193
+ const beforeContent = change.before;
60194
+ if (!beforeContent)
60195
+ continue;
60196
+ let currentOwner;
60197
+ if (typeStr === "script") {
60198
+ if (change.path.endsWith(".script.yaml") || change.path.endsWith(".script.json")) {
60199
+ const hasOboMatch = beforeContent.match(/has_on_behalf_of:\s*(true)/);
60200
+ if (hasOboMatch) {
60201
+ currentOwner = "(script owner)";
60202
+ } else {
60203
+ const emailMatch = beforeContent.match(/on_behalf_of_email:\s*["']?([^\s"']+)["']?/);
60204
+ if (emailMatch) {
60205
+ currentOwner = emailMatch[1];
60206
+ }
60207
+ }
60208
+ }
60209
+ } else if (typeStr === "flow") {
60210
+ if (change.path.endsWith("flow.yaml") || change.path.endsWith("flow.json")) {
60211
+ const hasOboMatch = beforeContent.match(/has_on_behalf_of:\s*(true)/);
60212
+ if (hasOboMatch) {
60213
+ wouldChangeItems.push({
60214
+ path: change.path,
60215
+ currentOwner: "(flow owner)"
60216
+ });
60217
+ }
60218
+ }
60219
+ continue;
60220
+ } else if (typeStr === "app") {
60221
+ wouldChangeItems.push({
60222
+ path: change.path,
60223
+ currentOwner: "(app policy owner)"
60224
+ });
60225
+ continue;
60226
+ } else if (typeStr === "schedule") {
60227
+ const match = beforeContent.match(/email:\s*["']?([^\s"']+)["']?/);
60228
+ if (match) {
60229
+ currentOwner = match[1];
60230
+ }
60231
+ } else if (typeStr.endsWith("_trigger")) {
60232
+ wouldChangeItems.push({
60233
+ path: change.path,
60234
+ currentOwner: "(trigger owner)"
60235
+ });
60236
+ continue;
60237
+ }
60238
+ if (currentOwner && currentOwner !== userEmail) {
60239
+ wouldChangeItems.push({ path: change.path, currentOwner });
60240
+ }
60241
+ }
60242
+ if (wouldChangeItems.length === 0)
60243
+ return;
60244
+ const itemList = wouldChangeItems.map((item) => ` - ${item.path} (current owner: ${item.currentOwner})`).join(`
60245
+ `);
60246
+ const message = `You are not an admin or member of 'wm_deployers'. The following ${wouldChangeItems.length} item(s) ` + `will have their permissioned_as/email changed to your user (${userEmail}):
60247
+ ${itemList}`;
60248
+ if (acceptOverride) {
60249
+ warn(colors.yellow(`Warning: ${message}`));
60250
+ return;
60251
+ }
60252
+ if (isInteractive) {
60253
+ warn(colors.yellow(message));
60254
+ const proceed = await Confirm.prompt({
60255
+ message: "Do you want to proceed? (use --accept-overriding-permissioned-as-with-self to skip this prompt)",
60256
+ default: false
60257
+ });
60258
+ if (!proceed) {
60259
+ info("Push cancelled.");
60260
+ process.exit(0);
60261
+ }
60262
+ } else {
60263
+ error(colors.red(`${message}
60264
+
60265
+ Use --accept-overriding-permissioned-as-with-self to proceed anyway.`));
60266
+ process.exit(1);
60267
+ }
60268
+ }
60269
+ var init_permissioned_as = __esm(async () => {
60270
+ init_services_gen();
60271
+ init_log();
60272
+ init_colors2();
60273
+ await __promiseAll([
60274
+ init_confirm(),
60275
+ init_types(),
60276
+ init_conf()
60277
+ ]);
60278
+ });
60279
+
60036
60280
  // src/core/extra_perms.ts
60037
60281
  function normalize5(value, source) {
60038
60282
  const perms = {};
@@ -62009,7 +62253,7 @@ async function push2(opts, filePath) {
62009
62253
  }
62010
62254
  } catch {}
62011
62255
  const codebases = await listSyncCodebases(opts);
62012
- await handleFile(filePath, workspace, [], opts.message, opts, await getRawWorkspaceDependencies(true), codebases);
62256
+ await handleFile(filePath, workspace, [], opts.message, opts, await getRawWorkspaceDependencies(true), codebases, await buildPermissionedAsContext(workspace.workspaceId, await readEffectiveSyncBehavior(opts, workspace)));
62013
62257
  info(colors.bold.underline.green(`Script ${filePath} pushed`));
62014
62258
  }
62015
62259
  async function findResourceFile(path) {
@@ -63104,6 +63348,7 @@ var init_script = __esm(async () => {
63104
63348
  await __promiseAll([
63105
63349
  init_auth(),
63106
63350
  init_context(),
63351
+ init_permissioned_as(),
63107
63352
  init_confirm(),
63108
63353
  init_utils(),
63109
63354
  init_specific_items(),
@@ -63867,149 +64112,6 @@ var init_shared_ui = __esm(async () => {
63867
64112
  await init_utils();
63868
64113
  });
63869
64114
 
63870
- // src/core/permissioned_as.ts
63871
- async function ensureUserCache(workspace, cache) {
63872
- if (cache.size > 0)
63873
- return;
63874
- const users = await listUsers({ workspace });
63875
- for (const user of users) {
63876
- cache.set(user.username, { username: user.username, email: user.email });
63877
- cache.set(user.email, { username: user.username, email: user.email });
63878
- }
63879
- }
63880
- async function lookupUsernameByEmail(workspace, email, cache) {
63881
- await ensureUserCache(workspace, cache);
63882
- const entry = cache.get(email);
63883
- if (!entry) {
63884
- throw new Error(`Could not find username for email '${email}' in workspace. ` + `Make sure the user exists in the workspace.`);
63885
- }
63886
- return entry.username;
63887
- }
63888
- function contentHasOnBehalfOf(content, typeStr) {
63889
- if (typeStr === "script") {
63890
- return !!content.match(/has_on_behalf_of:\s*(true)/) || !!content.match(/on_behalf_of_email:\s*["']?([^\s"']+)["']?/);
63891
- }
63892
- if (typeStr === "flow") {
63893
- return !!content.match(/has_on_behalf_of:\s*(true)/);
63894
- }
63895
- return false;
63896
- }
63897
- async function preCheckPermissionedAs(changes, userEmail, userIsAdminOrDeployer, acceptOverride, isInteractive) {
63898
- if (userIsAdminOrDeployer)
63899
- return;
63900
- const wouldChangeItems = [];
63901
- for (const change of changes) {
63902
- let typeStr;
63903
- try {
63904
- typeStr = getTypeStrFromPath(change.path);
63905
- } catch {
63906
- continue;
63907
- }
63908
- if (change.name === "added") {
63909
- const content = change.content;
63910
- if (!content)
63911
- continue;
63912
- const isScriptMeta = typeStr === "script" && (change.path.endsWith(".script.yaml") || change.path.endsWith(".script.json"));
63913
- const isFlowMeta = typeStr === "flow" && (change.path.endsWith("flow.yaml") || change.path.endsWith("flow.json"));
63914
- if ((isScriptMeta || isFlowMeta) && contentHasOnBehalfOf(content, typeStr)) {
63915
- const label = typeStr === "script" ? "(script owner)" : "(flow owner)";
63916
- wouldChangeItems.push({ path: change.path, currentOwner: label });
63917
- } else if (typeStr === "app") {
63918
- wouldChangeItems.push({
63919
- path: change.path,
63920
- currentOwner: "(app policy owner)"
63921
- });
63922
- }
63923
- continue;
63924
- }
63925
- if (change.name !== "edited")
63926
- continue;
63927
- const beforeContent = change.before;
63928
- if (!beforeContent)
63929
- continue;
63930
- let currentOwner;
63931
- if (typeStr === "script") {
63932
- if (change.path.endsWith(".script.yaml") || change.path.endsWith(".script.json")) {
63933
- const hasOboMatch = beforeContent.match(/has_on_behalf_of:\s*(true)/);
63934
- if (hasOboMatch) {
63935
- currentOwner = "(script owner)";
63936
- } else {
63937
- const emailMatch = beforeContent.match(/on_behalf_of_email:\s*["']?([^\s"']+)["']?/);
63938
- if (emailMatch) {
63939
- currentOwner = emailMatch[1];
63940
- }
63941
- }
63942
- }
63943
- } else if (typeStr === "flow") {
63944
- if (change.path.endsWith("flow.yaml") || change.path.endsWith("flow.json")) {
63945
- const hasOboMatch = beforeContent.match(/has_on_behalf_of:\s*(true)/);
63946
- if (hasOboMatch) {
63947
- wouldChangeItems.push({
63948
- path: change.path,
63949
- currentOwner: "(flow owner)"
63950
- });
63951
- }
63952
- }
63953
- continue;
63954
- } else if (typeStr === "app") {
63955
- wouldChangeItems.push({
63956
- path: change.path,
63957
- currentOwner: "(app policy owner)"
63958
- });
63959
- continue;
63960
- } else if (typeStr === "schedule") {
63961
- const match = beforeContent.match(/email:\s*["']?([^\s"']+)["']?/);
63962
- if (match) {
63963
- currentOwner = match[1];
63964
- }
63965
- } else if (typeStr.endsWith("_trigger")) {
63966
- wouldChangeItems.push({
63967
- path: change.path,
63968
- currentOwner: "(trigger owner)"
63969
- });
63970
- continue;
63971
- }
63972
- if (currentOwner && currentOwner !== userEmail) {
63973
- wouldChangeItems.push({ path: change.path, currentOwner });
63974
- }
63975
- }
63976
- if (wouldChangeItems.length === 0)
63977
- return;
63978
- const itemList = wouldChangeItems.map((item) => ` - ${item.path} (current owner: ${item.currentOwner})`).join(`
63979
- `);
63980
- const message = `You are not an admin or member of 'wm_deployers'. The following ${wouldChangeItems.length} item(s) ` + `will have their permissioned_as/email changed to your user (${userEmail}):
63981
- ${itemList}`;
63982
- if (acceptOverride) {
63983
- warn(colors.yellow(`Warning: ${message}`));
63984
- return;
63985
- }
63986
- if (isInteractive) {
63987
- warn(colors.yellow(message));
63988
- const proceed = await Confirm.prompt({
63989
- message: "Do you want to proceed? (use --accept-overriding-permissioned-as-with-self to skip this prompt)",
63990
- default: false
63991
- });
63992
- if (!proceed) {
63993
- info("Push cancelled.");
63994
- process.exit(0);
63995
- }
63996
- } else {
63997
- error(colors.red(`${message}
63998
-
63999
- Use --accept-overriding-permissioned-as-with-self to proceed anyway.`));
64000
- process.exit(1);
64001
- }
64002
- }
64003
- var init_permissioned_as = __esm(async () => {
64004
- init_services_gen();
64005
- init_log();
64006
- init_colors2();
64007
- await __promiseAll([
64008
- init_confirm(),
64009
- init_types()
64010
- ]);
64011
- });
64012
-
64013
64115
  // src/commands/resource/resource.ts
64014
64116
  import { mkdir as mkdir4, stat as stat6, writeFile as writeFile6, readdir as readdir3 } from "node:fs/promises";
64015
64117
  import nodePath from "node:path";
@@ -64654,22 +64756,6 @@ function computeWsSpecificFlagOnlyPushes(localMap, localSpecificItems, serverIte
64654
64756
  }
64655
64757
  return out;
64656
64758
  }
64657
- function resolveWsNameFromBranch(opts, branchName) {
64658
- const match = findWorkspaceByGitBranch(opts.workspaces, branchName);
64659
- return match ? match[0] : branchName;
64660
- }
64661
- function resolveWsNameForConfigFromFlags(opts) {
64662
- if (opts.branch) {
64663
- return resolveWsNameFromBranch(opts, opts.branch);
64664
- }
64665
- if (opts.workspace) {
64666
- const validKeys = getWorkspaceNames(opts.workspaces);
64667
- if (validKeys.includes(opts.workspace)) {
64668
- return opts.workspace;
64669
- }
64670
- }
64671
- return;
64672
- }
64673
64759
  function warnWorkspaceOverride(opts, wsNameForConfig) {
64674
64760
  if (!wsNameForConfig || !opts.workspaces)
64675
64761
  return;
@@ -64695,27 +64781,6 @@ function warnWorkspaceOverride(opts, wsNameForConfig) {
64695
64781
  function resolveWsNameForFiles(_opts, wsName) {
64696
64782
  return wsName;
64697
64783
  }
64698
- function inferWsNameFromProfile(opts, profile) {
64699
- if (!opts.workspaces)
64700
- return;
64701
- const wsNames = Object.keys(opts.workspaces).filter((k) => k !== "commonSpecificItems");
64702
- for (const name of wsNames) {
64703
- const entry = opts.workspaces[name];
64704
- if (!entry?.baseUrl)
64705
- continue;
64706
- try {
64707
- const entryUrl = new URL(entry.baseUrl).toString();
64708
- const profileUrl = new URL(profile.remote).toString();
64709
- const entryWsId = entry.workspaceId ?? name;
64710
- if (entryUrl === profileUrl && entryWsId === profile.workspaceId) {
64711
- return name;
64712
- }
64713
- } catch {
64714
- continue;
64715
- }
64716
- }
64717
- return;
64718
- }
64719
64784
  function mergeCliWithEffectiveOptions(cliOpts, effectiveOpts) {
64720
64785
  return Object.assign({}, effectiveOpts, cliOpts);
64721
64786
  }
@@ -67491,17 +67556,9 @@ Run 'wmill folder add-missing' to create them locally, then push again.`;
67491
67556
  ⚠ ${syncPushDestructiveWarning(opts.keepDeleted)}`));
67492
67557
  return;
67493
67558
  }
67494
- let permissionedAsContext = undefined;
67495
- if (parseSyncBehavior(opts.syncBehavior) >= 1) {
67496
- const user = await whoami({ workspace: workspace.workspaceId });
67497
- const userIsAdminOrDeployer = user.is_admin || (user.groups ?? []).includes("wm_deployers");
67498
- debug(`permissioned_as: user=${user.email}, is_admin=${user.is_admin}, groups=${JSON.stringify(user.groups)}, isAdminOrDeployer=${userIsAdminOrDeployer}`);
67499
- permissionedAsContext = {
67500
- userCache: new Map,
67501
- userIsAdminOrDeployer,
67502
- userEmail: user.email
67503
- };
67504
- await preCheckPermissionedAs(changes.filter((c) => c.name !== "ws_specific_flag"), user.email, userIsAdminOrDeployer, opts.acceptOverridingPermissionedAsWithSelf ?? false, !!process.stdin.isTTY);
67559
+ const permissionedAsContext = await buildPermissionedAsContext(workspace.workspaceId, opts.syncBehavior);
67560
+ if (permissionedAsContext) {
67561
+ await preCheckPermissionedAs(changes.filter((c) => c.name !== "ws_specific_flag"), permissionedAsContext.userEmail, permissionedAsContext.userIsAdminOrDeployer, opts.acceptOverridingPermissionedAsWithSelf ?? false, !!process.stdin.isTTY);
67505
67562
  } else if (folderDefaultAnnotations && folderDefaultAnnotations.size > 0) {
67506
67563
  warn(colors.yellow(`This workspace has folder default_permissioned_as rules that affect ${folderDefaultAnnotations.size} item(s) being pushed, but syncBehavior is not set in wmill.yaml. Add 'syncBehavior: v1' to enable ownership preservation on update and on_behalf_of stripping on pull.`));
67507
67564
  }
@@ -72981,7 +73038,7 @@ async function push5(opts, filePath, remotePath) {
72981
73038
  await pushRawApp(workspace.workspaceId, remotePath, absoluteFilePath, undefined, merged.defaultTs);
72982
73039
  info(colors.bold.underline.green("Raw app pushed"));
72983
73040
  } else {
72984
- await pushApp(workspace.workspaceId, remotePath, absoluteFilePath);
73041
+ await pushApp(workspace.workspaceId, remotePath, absoluteFilePath, undefined, await buildPermissionedAsContext(workspace.workspaceId, await readEffectiveSyncBehavior(opts, workspace)));
72985
73042
  info(colors.bold.underline.green("App pushed"));
72986
73043
  }
72987
73044
  }
@@ -73006,7 +73063,8 @@ var init_app = __esm(async () => {
73006
73063
  init_lint2(),
73007
73064
  init_bundle_command(),
73008
73065
  init_new(),
73009
- init_generate_agents()
73066
+ init_generate_agents(),
73067
+ init_permissioned_as()
73010
73068
  ]);
73011
73069
  alreadySynced2 = [];
73012
73070
  APP_FOLDER_SUFFIXES = ["__raw_app", ".raw_app", "__app", ".app"];
@@ -73361,30 +73419,31 @@ async function pushVariable(workspace, remotePath, variable, localVariable, plai
73361
73419
  } catch {
73362
73420
  debug(`Variable ${remotePath} does not exist on remote`);
73363
73421
  }
73422
+ const { extra_perms: localPerms, ...localVariableBody } = localVariable;
73364
73423
  if (variable) {
73365
- if (isSuperset(localVariable, variable)) {
73424
+ if (isSuperset(localVariableBody, variable)) {
73366
73425
  debug(`Variable ${remotePath} is up-to-date`);
73367
- return;
73368
- }
73369
- debug(`Variable ${remotePath} is not up-to-date, updating`);
73370
- let nextIsSecret = undefined;
73371
- if (localVariable.is_secret !== variable.is_secret) {
73372
- if (localVariable.is_secret) {
73373
- nextIsSecret = true;
73374
- } else if (allowSecretDowngrade) {
73375
- nextIsSecret = false;
73426
+ } else {
73427
+ debug(`Variable ${remotePath} is not up-to-date, updating`);
73428
+ let nextIsSecret = undefined;
73429
+ if (localVariableBody.is_secret !== variable.is_secret) {
73430
+ if (localVariableBody.is_secret) {
73431
+ nextIsSecret = true;
73432
+ } else if (allowSecretDowngrade) {
73433
+ nextIsSecret = false;
73434
+ }
73376
73435
  }
73436
+ await updateVariable({
73437
+ workspace,
73438
+ path: remotePath.replaceAll(SEP16, "/"),
73439
+ alreadyEncrypted: !plainSecrets,
73440
+ requestBody: {
73441
+ ...localVariableBody,
73442
+ is_secret: nextIsSecret,
73443
+ ...wsSpecific !== undefined ? { ws_specific: wsSpecific } : {}
73444
+ }
73445
+ });
73377
73446
  }
73378
- await updateVariable({
73379
- workspace,
73380
- path: remotePath.replaceAll(SEP16, "/"),
73381
- alreadyEncrypted: !plainSecrets,
73382
- requestBody: {
73383
- ...localVariable,
73384
- is_secret: nextIsSecret,
73385
- ...wsSpecific !== undefined ? { ws_specific: wsSpecific } : {}
73386
- }
73387
- });
73388
73447
  } else {
73389
73448
  info(colors.yellow.bold(`Creating new variable ${remotePath}...`));
73390
73449
  await createVariable({
@@ -73392,11 +73451,12 @@ async function pushVariable(workspace, remotePath, variable, localVariable, plai
73392
73451
  alreadyEncrypted: !plainSecrets,
73393
73452
  requestBody: {
73394
73453
  path: remotePath.replaceAll(SEP16, "/"),
73395
- ...localVariable,
73454
+ ...localVariableBody,
73396
73455
  ...wsSpecific !== undefined ? { ws_specific: wsSpecific } : {}
73397
73456
  }
73398
73457
  });
73399
73458
  }
73459
+ await applyExtraPermsDiff(workspace, "variable", remotePath.replaceAll(SEP16, "/"), localPerms, variable?.extra_perms);
73400
73460
  }
73401
73461
  async function push7(opts, filePath, remotePath) {
73402
73462
  const workspace = await resolveWorkspace(opts);
@@ -73482,6 +73542,7 @@ var init_variable = __esm(async () => {
73482
73542
  init_colors2();
73483
73543
  init_log();
73484
73544
  init_services_gen();
73545
+ init_extra_perms();
73485
73546
  await __promiseAll([
73486
73547
  init_auth(),
73487
73548
  init_context(),
@@ -73496,7 +73557,7 @@ var init_variable = __esm(async () => {
73496
73557
  // src/commands/schedule/schedule.ts
73497
73558
  import { mkdir as mkdir12, stat as stat13, writeFile as writeFile14 } from "node:fs/promises";
73498
73559
  import { dirname as dirname18 } from "node:path";
73499
- import { sep as SEP17 } from "node:path";
73560
+ import { sep as SEP17, resolve as pathResolve2 } from "node:path";
73500
73561
  async function list9(opts) {
73501
73562
  if (opts.json)
73502
73563
  setSilent(true);
@@ -73689,8 +73750,10 @@ async function disable(opts, path) {
73689
73750
  info(colors.yellow(`Schedule ${path} disabled.`));
73690
73751
  }
73691
73752
  async function push8(opts, filePath, remotePath) {
73753
+ filePath = pathResolve2(filePath);
73692
73754
  const workspace = await resolveWorkspace(opts);
73693
73755
  await requireLogin(opts);
73756
+ const syncBehavior = await readEffectiveSyncBehavior(opts, workspace);
73694
73757
  if (!validatePath(remotePath)) {
73695
73758
  return;
73696
73759
  }
@@ -73699,7 +73762,7 @@ async function push8(opts, filePath, remotePath) {
73699
73762
  throw new Error("file path must refer to a file.");
73700
73763
  }
73701
73764
  console.log(colors.bold.yellow("Pushing schedule..."));
73702
- await pushSchedule(workspace.workspaceId, remotePath, undefined, parseFromFile(filePath));
73765
+ await pushSchedule(workspace.workspaceId, remotePath, undefined, parseFromFile(filePath), await buildPermissionedAsContext(workspace.workspaceId, syncBehavior));
73703
73766
  console.log(colors.bold.underline.green("Schedule pushed"));
73704
73767
  }
73705
73768
  var import_yaml29, command17, schedule_default2;
@@ -75317,7 +75380,7 @@ var init_dependencies = __esm(async () => {
75317
75380
  // src/commands/trigger/trigger.ts
75318
75381
  import { mkdir as mkdir14, stat as stat15, writeFile as writeFile18 } from "node:fs/promises";
75319
75382
  import { dirname as dirname19 } from "node:path";
75320
- import { sep as SEP18 } from "node:path";
75383
+ import { sep as SEP18, resolve as pathResolve3 } from "node:path";
75321
75384
  async function getTrigger(triggerType, workspace, path) {
75322
75385
  const triggerFunctions = {
75323
75386
  http: getHttpTrigger,
@@ -75663,8 +75726,10 @@ async function extractTriggerKindFromPath(filePath) {
75663
75726
  return triggerMatch ? triggerMatch[1] : undefined;
75664
75727
  }
75665
75728
  async function push10(opts, filePath, remotePath) {
75729
+ filePath = pathResolve3(filePath);
75666
75730
  const workspace = await resolveWorkspace(opts);
75667
75731
  await requireLogin(opts);
75732
+ const syncBehavior = await readEffectiveSyncBehavior(opts, workspace);
75668
75733
  if (!validatePath(remotePath)) {
75669
75734
  return;
75670
75735
  }
@@ -75677,7 +75742,7 @@ async function push10(opts, filePath, remotePath) {
75677
75742
  if (!checkIfValidTrigger(triggerKind)) {
75678
75743
  throw new Error("Invalid trigger kind: " + triggerKind);
75679
75744
  }
75680
- await pushTrigger(triggerKind, workspace.workspaceId, remotePath, undefined, parseFromFile(filePath));
75745
+ await pushTrigger(triggerKind, workspace.workspaceId, remotePath, undefined, parseFromFile(filePath), await buildPermissionedAsContext(workspace.workspaceId, syncBehavior));
75681
75746
  console.log(colors.bold.underline.green("Trigger pushed"));
75682
75747
  }
75683
75748
  var import_yaml36, triggerTemplates, TRIGGER_SKIP_FIELDS, command21, trigger_default;
@@ -75692,7 +75757,9 @@ var init_trigger = __esm(async () => {
75692
75757
  init_types(),
75693
75758
  init_specific_items(),
75694
75759
  init_auth(),
75695
- init_context()
75760
+ init_context(),
75761
+ init_permissioned_as(),
75762
+ init_conf()
75696
75763
  ]);
75697
75764
  import_yaml36 = __toESM(require_dist(), 1);
75698
75765
  triggerTemplates = {
@@ -76254,7 +76321,7 @@ var init_local_path_scripts = __esm(async () => {
76254
76321
  });
76255
76322
 
76256
76323
  // src/commands/flow/flow.ts
76257
- import { dirname as dirname20, sep as SEP20 } from "node:path";
76324
+ import { dirname as dirname20, sep as SEP20, resolve as pathResolve4 } from "node:path";
76258
76325
  import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
76259
76326
  function normalizeOptionalString(value) {
76260
76327
  return typeof value === "string" && value.trim() === "" ? undefined : value ?? undefined;
@@ -76420,9 +76487,11 @@ async function push11(opts, filePath, remotePath) {
76420
76487
  if (!validatePath(remotePath)) {
76421
76488
  return;
76422
76489
  }
76490
+ filePath = pathResolve4(filePath);
76423
76491
  const workspace = await resolveWorkspace(opts);
76424
76492
  await requireLogin(opts);
76425
- await pushFlow(workspace.workspaceId, remotePath, filePath, opts.message);
76493
+ const syncBehavior = await readEffectiveSyncBehavior(opts, workspace);
76494
+ await pushFlow(workspace.workspaceId, remotePath, filePath, opts.message, await buildPermissionedAsContext(workspace.workspaceId, syncBehavior));
76426
76495
  info(colors.bold.underline.green("Flow pushed"));
76427
76496
  }
76428
76497
  async function list12(opts) {
@@ -77019,6 +77088,7 @@ var init_flow = __esm(async () => {
77019
77088
  init_script(),
77020
77089
  init_conf(),
77021
77090
  init_sync(),
77091
+ init_permissioned_as(),
77022
77092
  init_flow_metadata(),
77023
77093
  init_script(),
77024
77094
  init_codebase(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windmill-cli",
3
- "version": "1.804.0",
3
+ "version": "1.805.0",
4
4
  "description": "CLI for Windmill",
5
5
  "license": "Apache 2.0",
6
6
  "type": "module",