@sanity/cli-core 3.15.0 → 3.16.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.
@@ -0,0 +1,13 @@
1
+ /** @public */
2
+ interface ImageFile {
3
+ contentType: string;
4
+ image: Buffer;
5
+ }
6
+ /**
7
+ * Read an image file to upload, such as an organization's logo. Throws an error a user can act on
8
+ * when the file is missing, isn't a supported image type, or is over 5 MB.
9
+ * @public
10
+ */
11
+ declare function readImageFile(filePath: string): Promise<ImageFile>;
12
+ export { type ImageFile, readImageFile };
13
+ //# sourceMappingURL=images.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { readImageFile } from '../util/readImageFile.js';
2
+
3
+ //# sourceMappingURL=images.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/_exports/images.ts"],"sourcesContent":["export {type ImageFile, readImageFile} from '../util/readImageFile.js'\n"],"names":["readImageFile"],"mappings":"AAAA,SAAwBA,aAAa,QAAO,2BAA0B"}
@@ -1,4 +1,4 @@
1
- import { mkdirSync } from 'node:fs';
1
+ import { chmodSync, mkdirSync, statSync } from 'node:fs';
2
2
  import { dirname, join as joinPath } from 'node:path';
3
3
  import { z } from 'zod/mini';
4
4
  import { debug } from '../../_exports/debug.js';
@@ -59,6 +59,15 @@ export const _internals = {
59
59
  setCachedTokenInfo(tokenInfo);
60
60
  return tokenInfo;
61
61
  }
62
+ // The config file holds the CLI auth token, so keep it readable by its owner only
63
+ const CONFIG_DIR_OPTIONS = {
64
+ mode: 0o700,
65
+ recursive: true
66
+ };
67
+ const CONFIG_WRITE_OPTIONS = {
68
+ mode: 0o600,
69
+ pretty: true
70
+ };
62
71
  const cliUserConfigSchema = {
63
72
  authToken: z.optional(z.string())
64
73
  };
@@ -78,23 +87,17 @@ const cliUserConfigSchema = {
78
87
  throw new Error(`Invalid value for config property "${prop}": ${message}`);
79
88
  }
80
89
  const configPath = getCliUserConfigPath();
81
- mkdirSync(dirname(configPath), {
82
- recursive: true
83
- });
90
+ mkdirSync(dirname(configPath), CONFIG_DIR_OPTIONS);
84
91
  // When value is undefined, explicitly delete the key rather than relying
85
92
  // on JSON.stringify silently dropping undefined values.
86
93
  if (value === undefined) {
87
94
  const { [prop]: _, ...rest } = config;
88
- writeJsonFileSync(configPath, rest, {
89
- pretty: true
90
- });
95
+ writeJsonFileSync(configPath, rest, CONFIG_WRITE_OPTIONS);
91
96
  } else {
92
97
  writeJsonFileSync(configPath, {
93
98
  ...config,
94
99
  [prop]: value
95
- }, {
96
- pretty: true
97
- });
100
+ }, CONFIG_WRITE_OPTIONS);
98
101
  }
99
102
  // Invalidate the in-process token cache so subsequent getCliToken() calls
100
103
  // pick up the new value from disk.
@@ -140,15 +143,11 @@ const cliUserConfigSchema = {
140
143
  set (key, value) {
141
144
  const config = readConfig();
142
145
  const configPath = getCliUserConfigPath();
143
- mkdirSync(dirname(configPath), {
144
- recursive: true
145
- });
146
+ mkdirSync(dirname(configPath), CONFIG_DIR_OPTIONS);
146
147
  writeJsonFileSync(configPath, {
147
148
  ...config,
148
149
  [key]: value
149
- }, {
150
- pretty: true
151
- });
150
+ }, CONFIG_WRITE_OPTIONS);
152
151
  if (key === 'authToken') clearCliTokenCache();
153
152
  },
154
153
  // No mkdirSync needed: if readConfig() succeeded the directory already exists.
@@ -156,9 +155,7 @@ const cliUserConfigSchema = {
156
155
  const config = readConfig();
157
156
  if (!(key in config)) return;
158
157
  const { [key]: _, ...rest } = config;
159
- writeJsonFileSync(getCliUserConfigPath(), rest, {
160
- pretty: true
161
- });
158
+ writeJsonFileSync(getCliUserConfigPath(), rest, CONFIG_WRITE_OPTIONS);
162
159
  if (key === 'authToken') clearCliTokenCache();
163
160
  }
164
161
  };
@@ -177,8 +174,10 @@ function assertCanAccessHostUserConfig() {
177
174
  * @returns The whole CLI configuration.
178
175
  * @internal
179
176
  */ function readConfig() {
177
+ const configPath = getCliUserConfigPath();
178
+ restrictConfigFilePermissions(configPath);
180
179
  try {
181
- const config = readJsonFileSync(getCliUserConfigPath());
180
+ const config = readJsonFileSync(configPath);
182
181
  if (!config || typeof config !== 'object' || Array.isArray(config)) {
183
182
  throw new Error('Invalid config file - expected an object');
184
183
  }
@@ -188,6 +187,25 @@ function assertCanAccessHostUserConfig() {
188
187
  return {};
189
188
  }
190
189
  }
190
+ /**
191
+ * Remove group and other access from an existing config file. CLI versions from
192
+ * 6.0.0 created it with the default umask mode (usually 0644), exposing the auth
193
+ * token to other local users. Only touches files owned by the current user, and
194
+ * never adds permissions.
195
+ *
196
+ * @param configPath - Path to the CLI configuration file
197
+ */ function restrictConfigFilePermissions(configPath) {
198
+ // No POSIX permissions to fix on Windows
199
+ if (typeof process.getuid !== 'function') return;
200
+ try {
201
+ const { mode, uid } = statSync(configPath);
202
+ if (uid !== process.getuid() || (mode & 0o077) === 0) return;
203
+ chmodSync(configPath, mode & 0o700);
204
+ debug('Restricted permissions of %s to owner only', configPath);
205
+ } catch (err) {
206
+ debug('Could not restrict permissions of CLI config file: %s', err instanceof Error ? err.message : `${err}`);
207
+ }
208
+ }
191
209
  /**
192
210
  * Get the file system location for the CLI user configuration file.
193
211
  * Takes into account the active environment (staging vs production).
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/cli/cliUserConfig.ts"],"sourcesContent":["import {mkdirSync} from 'node:fs'\nimport {dirname, join as joinPath} from 'node:path'\n\nimport {z} from 'zod/mini'\n\nimport {debug} from '../../_exports/debug.js'\nimport {getCliExecutionContext} from '../../executionContext.js'\nimport {getSanityConfigDir} from '../../util/getSanityConfigDir.js'\nimport {readJsonFileSync} from '../../util/readJsonFileSync.js'\nimport {writeJsonFileSync} from '../../util/writeJsonFileSync.js'\nimport {\n clearCliTokenCache,\n type CliTokenInfo,\n getCachedTokenInfo,\n setCachedTokenInfo,\n} from './cliTokenCache.js'\nimport {type ConfigStore} from './types/cliConfig.js'\n\n// Re-export so existing consumers don't break\nexport {clearCliTokenCache} from './cliTokenCache.js'\nexport {type CliTokenInfo} from './cliTokenCache.js'\n\n// Only used for testing\nexport const _internals = {\n getCliUserConfig,\n}\n\n/**\n * Get the CLI authentication token selected for the current invocation.\n *\n * @returns A promise that resolves to a CLI token, or undefined if no token is found\n * @internal\n */\nexport async function getCliToken(): Promise<string | undefined> {\n return (await getCliTokenInfo())?.token\n}\n\n/**\n * Get the CLI authentication token and where it was resolved from.\n *\n * @returns A promise that resolves to the token and its source, or undefined if no token is found\n * @internal\n */\nexport async function getCliTokenInfo(): Promise<CliTokenInfo | undefined> {\n // A per-invocation execution context token (e.g. per-request from an MCP\n // server) takes precedence and must bypass the process-wide cache entirely:\n // reading the cache would leak another invocation's token, and writing it\n // would leak this one's.\n const context = getCliExecutionContext()\n if (context) {\n return context.token === undefined\n ? undefined\n : {source: 'CLI execution context', token: context.token}\n }\n\n const cachedTokenInfo = getCachedTokenInfo()\n if (cachedTokenInfo !== undefined) {\n return cachedTokenInfo\n }\n\n const token = process.env.SANITY_AUTH_TOKEN\n if (token) {\n const tokenInfo = {\n source: 'SANITY_AUTH_TOKEN environment variable',\n token: token.trim(),\n }\n setCachedTokenInfo(tokenInfo)\n return tokenInfo\n }\n\n const configToken = _internals.getCliUserConfig('authToken')\n const tokenInfo =\n configToken === undefined ? undefined : {source: getCliUserConfigPath(), token: configToken}\n setCachedTokenInfo(tokenInfo)\n return tokenInfo\n}\nconst cliUserConfigSchema = {\n authToken: z.optional(z.string()),\n}\n\n/**\n * Set the config value for the given property.\n * Validates that the passed value adheres to the defined CLI config schema.\n *\n * @param prop - The property to set the value for\n * @param value - The value to set\n * @internal\n */\nexport function setCliUserConfig(prop: 'authToken', value: string | undefined): void {\n assertCanAccessHostUserConfig()\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(value)\n if (!result.success) {\n const message = result.error.issues\n .map(({message, path}) => `[${path.join('.')}] ${message}`)\n .join('\\n')\n\n throw new Error(`Invalid value for config property \"${prop}\": ${message}`)\n }\n\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n\n // When value is undefined, explicitly delete the key rather than relying\n // on JSON.stringify silently dropping undefined values.\n if (value === undefined) {\n const {[prop]: _, ...rest} = config\n writeJsonFileSync(configPath, rest, {pretty: true})\n } else {\n writeJsonFileSync(configPath, {...config, [prop]: value}, {pretty: true})\n }\n\n // Invalidate the in-process token cache so subsequent getCliToken() calls\n // pick up the new value from disk.\n clearCliTokenCache()\n}\n\n/**\n * Get the config value for the given property\n *\n * @param prop - The property to get the value for\n * @returns The value of the given property\n */\nexport function getCliUserConfig(prop: 'authToken'): string | undefined {\n assertCanAccessHostUserConfig()\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(config[prop])\n if (!result.success) {\n debug('Ignoring invalid stored value for \"%s\", returning undefined', prop)\n return undefined\n }\n\n return result.data\n}\n\n/**\n * Get a key-value store backed by the CLI user configuration file\n * (`~/.config/sanity/config.json`).\n *\n * Each call to `get`, `set`, or `delete` performs a full synchronous\n * read-modify-write cycle. This is intentional: sync I/O prevents\n * intra-process race conditions that occurred with the previous async\n * (configstore-backed) implementation.\n *\n * Note: there is no file-level locking, so concurrent writes from\n * separate CLI processes could still conflict. In practice this is\n * unlikely since CLI config writes are rare and user-initiated.\n *\n * @returns A {@link ConfigStore} for the CLI config file\n * @public\n */\nexport function getUserConfig(): ConfigStore {\n assertCanAccessHostUserConfig()\n return {\n get(key: string): unknown {\n const config = readConfig()\n return config[key]\n },\n\n set(key: string, value: unknown): void {\n const config = readConfig()\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n writeJsonFileSync(configPath, {...config, [key]: value}, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n\n // No mkdirSync needed: if readConfig() succeeded the directory already exists.\n delete(key: string): void {\n const config = readConfig()\n if (!(key in config)) return\n const {[key]: _, ...rest} = config\n writeJsonFileSync(getCliUserConfigPath(), rest, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n }\n}\n\nfunction assertCanAccessHostUserConfig(): void {\n if (getCliExecutionContext()) {\n throw new Error('Host CLI user configuration is unavailable during programmatic invocations')\n }\n}\n\n/**\n * Read the whole configuration from file system. If the file does not exist,\n * is corrupt, or otherwise unreadable, an empty object is returned. This is\n * intentional: the config only holds recoverable data (auth tokens, telemetry\n * consent) so silently resetting is preferable to blocking the user.\n *\n * @returns The whole CLI configuration.\n * @internal\n */\nfunction readConfig(): Record<string, unknown> {\n try {\n const config = readJsonFileSync(getCliUserConfigPath())\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new Error('Invalid config file - expected an object')\n }\n return config\n } catch (err: unknown) {\n debug('Failed to read CLI config file: %s', err instanceof Error ? err.message : `${err}`)\n return {}\n }\n}\n\n/**\n * Get the file system location for the CLI user configuration file.\n * Takes into account the active environment (staging vs production).\n * The file is located in the user's home directory under the `.config` directory.\n *\n * @returns The path to the CLI configuration file.\n * @internal\n */\nfunction getCliUserConfigPath() {\n return process.env.SANITY_CLI_CONFIG_PATH || joinPath(getSanityConfigDir(), 'config.json')\n}\n"],"names":["mkdirSync","dirname","join","joinPath","z","debug","getCliExecutionContext","getSanityConfigDir","readJsonFileSync","writeJsonFileSync","clearCliTokenCache","getCachedTokenInfo","setCachedTokenInfo","_internals","getCliUserConfig","getCliToken","getCliTokenInfo","token","context","undefined","source","cachedTokenInfo","process","env","SANITY_AUTH_TOKEN","tokenInfo","trim","configToken","getCliUserConfigPath","cliUserConfigSchema","authToken","optional","string","setCliUserConfig","prop","value","assertCanAccessHostUserConfig","config","readConfig","result","safeParse","success","message","error","issues","map","path","Error","configPath","recursive","_","rest","pretty","data","getUserConfig","get","key","set","delete","Array","isArray","err","SANITY_CLI_CONFIG_PATH"],"mappings":"AAAA,SAAQA,SAAS,QAAO,UAAS;AACjC,SAAQC,OAAO,EAAEC,QAAQC,QAAQ,QAAO,YAAW;AAEnD,SAAQC,CAAC,QAAO,WAAU;AAE1B,SAAQC,KAAK,QAAO,0BAAyB;AAC7C,SAAQC,sBAAsB,QAAO,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+C,aAAa;gBAACC,WAAW;YAAI;YAC/CxC,kBAAkBuC,YAAY;gBAAC,GAAGX,MAAM;gBAAE,CAACmB,IAAI,EAAErB;YAAK,GAAG;gBAACiB,QAAQ;YAAI;YACtE,IAAII,QAAQ,aAAa9C;QAC3B;QAEA,+EAA+E;QAC/EgD,QAAOF,GAAW;YAChB,MAAMnB,SAASC;YACf,IAAI,CAAEkB,CAAAA,OAAOnB,MAAK,GAAI;YACtB,MAAM,EAAC,CAACmB,IAAI,EAAEN,CAAC,EAAE,GAAGC,MAAK,GAAGd;YAC5B5B,kBAAkBmB,wBAAwBuB,MAAM;gBAACC,QAAQ;YAAI;YAC7D,IAAII,QAAQ,aAAa9C;QAC3B;IACF;AACF;AAEA,SAAS0B;IACP,IAAI9B,0BAA0B;QAC5B,MAAM,IAAIyC,MAAM;IAClB;AACF;AAEA;;;;;;;;CAQC,GACD,SAAST;IACP,IAAI;QACF,MAAMD,SAAS7B,iBAAiBoB;QAChC,IAAI,CAACS,UAAU,OAAOA,WAAW,YAAYsB,MAAMC,OAAO,CAACvB,SAAS;YAClE,MAAM,IAAIU,MAAM;QAClB;QACA,OAAOV;IACT,EAAE,OAAOwB,KAAc;QACrBxD,MAAM,sCAAsCwD,eAAed,QAAQc,IAAInB,OAAO,GAAG,GAAGmB,KAAK;QACzF,OAAO,CAAC;IACV;AACF;AAEA;;;;;;;CAOC,GACD,SAASjC;IACP,OAAON,QAAQC,GAAG,CAACuC,sBAAsB,IAAI3D,SAASI,sBAAsB;AAC9E"}
1
+ {"version":3,"sources":["../../../src/config/cli/cliUserConfig.ts"],"sourcesContent":["import {chmodSync, mkdirSync, statSync} from 'node:fs'\nimport {dirname, join as joinPath} from 'node:path'\n\nimport {z} from 'zod/mini'\n\nimport {debug} from '../../_exports/debug.js'\nimport {getCliExecutionContext} from '../../executionContext.js'\nimport {getSanityConfigDir} from '../../util/getSanityConfigDir.js'\nimport {readJsonFileSync} from '../../util/readJsonFileSync.js'\nimport {writeJsonFileSync} from '../../util/writeJsonFileSync.js'\nimport {\n clearCliTokenCache,\n type CliTokenInfo,\n getCachedTokenInfo,\n setCachedTokenInfo,\n} from './cliTokenCache.js'\nimport {type ConfigStore} from './types/cliConfig.js'\n\n// Re-export so existing consumers don't break\nexport {clearCliTokenCache} from './cliTokenCache.js'\nexport {type CliTokenInfo} from './cliTokenCache.js'\n\n// Only used for testing\nexport const _internals = {\n getCliUserConfig,\n}\n\n/**\n * Get the CLI authentication token selected for the current invocation.\n *\n * @returns A promise that resolves to a CLI token, or undefined if no token is found\n * @internal\n */\nexport async function getCliToken(): Promise<string | undefined> {\n return (await getCliTokenInfo())?.token\n}\n\n/**\n * Get the CLI authentication token and where it was resolved from.\n *\n * @returns A promise that resolves to the token and its source, or undefined if no token is found\n * @internal\n */\nexport async function getCliTokenInfo(): Promise<CliTokenInfo | undefined> {\n // A per-invocation execution context token (e.g. per-request from an MCP\n // server) takes precedence and must bypass the process-wide cache entirely:\n // reading the cache would leak another invocation's token, and writing it\n // would leak this one's.\n const context = getCliExecutionContext()\n if (context) {\n return context.token === undefined\n ? undefined\n : {source: 'CLI execution context', token: context.token}\n }\n\n const cachedTokenInfo = getCachedTokenInfo()\n if (cachedTokenInfo !== undefined) {\n return cachedTokenInfo\n }\n\n const token = process.env.SANITY_AUTH_TOKEN\n if (token) {\n const tokenInfo = {\n source: 'SANITY_AUTH_TOKEN environment variable',\n token: token.trim(),\n }\n setCachedTokenInfo(tokenInfo)\n return tokenInfo\n }\n\n const configToken = _internals.getCliUserConfig('authToken')\n const tokenInfo =\n configToken === undefined ? undefined : {source: getCliUserConfigPath(), token: configToken}\n setCachedTokenInfo(tokenInfo)\n return tokenInfo\n}\n\n// The config file holds the CLI auth token, so keep it readable by its owner only\nconst CONFIG_DIR_OPTIONS = {mode: 0o700, recursive: true}\nconst CONFIG_WRITE_OPTIONS = {mode: 0o600, pretty: true}\n\nconst cliUserConfigSchema = {\n authToken: z.optional(z.string()),\n}\n\n/**\n * Set the config value for the given property.\n * Validates that the passed value adheres to the defined CLI config schema.\n *\n * @param prop - The property to set the value for\n * @param value - The value to set\n * @internal\n */\nexport function setCliUserConfig(prop: 'authToken', value: string | undefined): void {\n assertCanAccessHostUserConfig()\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(value)\n if (!result.success) {\n const message = result.error.issues\n .map(({message, path}) => `[${path.join('.')}] ${message}`)\n .join('\\n')\n\n throw new Error(`Invalid value for config property \"${prop}\": ${message}`)\n }\n\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), CONFIG_DIR_OPTIONS)\n\n // When value is undefined, explicitly delete the key rather than relying\n // on JSON.stringify silently dropping undefined values.\n if (value === undefined) {\n const {[prop]: _, ...rest} = config\n writeJsonFileSync(configPath, rest, CONFIG_WRITE_OPTIONS)\n } else {\n writeJsonFileSync(configPath, {...config, [prop]: value}, CONFIG_WRITE_OPTIONS)\n }\n\n // Invalidate the in-process token cache so subsequent getCliToken() calls\n // pick up the new value from disk.\n clearCliTokenCache()\n}\n\n/**\n * Get the config value for the given property\n *\n * @param prop - The property to get the value for\n * @returns The value of the given property\n */\nexport function getCliUserConfig(prop: 'authToken'): string | undefined {\n assertCanAccessHostUserConfig()\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(config[prop])\n if (!result.success) {\n debug('Ignoring invalid stored value for \"%s\", returning undefined', prop)\n return undefined\n }\n\n return result.data\n}\n\n/**\n * Get a key-value store backed by the CLI user configuration file\n * (`~/.config/sanity/config.json`).\n *\n * Each call to `get`, `set`, or `delete` performs a full synchronous\n * read-modify-write cycle. This is intentional: sync I/O prevents\n * intra-process race conditions that occurred with the previous async\n * (configstore-backed) implementation.\n *\n * Note: there is no file-level locking, so concurrent writes from\n * separate CLI processes could still conflict. In practice this is\n * unlikely since CLI config writes are rare and user-initiated.\n *\n * @returns A {@link ConfigStore} for the CLI config file\n * @public\n */\nexport function getUserConfig(): ConfigStore {\n assertCanAccessHostUserConfig()\n return {\n get(key: string): unknown {\n const config = readConfig()\n return config[key]\n },\n\n set(key: string, value: unknown): void {\n const config = readConfig()\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), CONFIG_DIR_OPTIONS)\n writeJsonFileSync(configPath, {...config, [key]: value}, CONFIG_WRITE_OPTIONS)\n if (key === 'authToken') clearCliTokenCache()\n },\n\n // No mkdirSync needed: if readConfig() succeeded the directory already exists.\n delete(key: string): void {\n const config = readConfig()\n if (!(key in config)) return\n const {[key]: _, ...rest} = config\n writeJsonFileSync(getCliUserConfigPath(), rest, CONFIG_WRITE_OPTIONS)\n if (key === 'authToken') clearCliTokenCache()\n },\n }\n}\n\nfunction assertCanAccessHostUserConfig(): void {\n if (getCliExecutionContext()) {\n throw new Error('Host CLI user configuration is unavailable during programmatic invocations')\n }\n}\n\n/**\n * Read the whole configuration from file system. If the file does not exist,\n * is corrupt, or otherwise unreadable, an empty object is returned. This is\n * intentional: the config only holds recoverable data (auth tokens, telemetry\n * consent) so silently resetting is preferable to blocking the user.\n *\n * @returns The whole CLI configuration.\n * @internal\n */\nfunction readConfig(): Record<string, unknown> {\n const configPath = getCliUserConfigPath()\n restrictConfigFilePermissions(configPath)\n try {\n const config = readJsonFileSync(configPath)\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new Error('Invalid config file - expected an object')\n }\n return config\n } catch (err: unknown) {\n debug('Failed to read CLI config file: %s', err instanceof Error ? err.message : `${err}`)\n return {}\n }\n}\n\n/**\n * Remove group and other access from an existing config file. CLI versions from\n * 6.0.0 created it with the default umask mode (usually 0644), exposing the auth\n * token to other local users. Only touches files owned by the current user, and\n * never adds permissions.\n *\n * @param configPath - Path to the CLI configuration file\n */\nfunction restrictConfigFilePermissions(configPath: string): void {\n // No POSIX permissions to fix on Windows\n if (typeof process.getuid !== 'function') return\n\n try {\n const {mode, uid} = statSync(configPath)\n if (uid !== process.getuid() || (mode & 0o077) === 0) return\n\n chmodSync(configPath, mode & 0o700)\n debug('Restricted permissions of %s to owner only', configPath)\n } catch (err: unknown) {\n debug(\n 'Could not restrict permissions of CLI config file: %s',\n err instanceof Error ? err.message : `${err}`,\n )\n }\n}\n\n/**\n * Get the file system location for the CLI user configuration file.\n * Takes into account the active environment (staging vs production).\n * The file is located in the user's home directory under the `.config` directory.\n *\n * @returns The path to the CLI configuration file.\n * @internal\n */\nfunction getCliUserConfigPath() {\n return process.env.SANITY_CLI_CONFIG_PATH || joinPath(getSanityConfigDir(), 'config.json')\n}\n"],"names":["chmodSync","mkdirSync","statSync","dirname","join","joinPath","z","debug","getCliExecutionContext","getSanityConfigDir","readJsonFileSync","writeJsonFileSync","clearCliTokenCache","getCachedTokenInfo","setCachedTokenInfo","_internals","getCliUserConfig","getCliToken","getCliTokenInfo","token","context","undefined","source","cachedTokenInfo","process","env","SANITY_AUTH_TOKEN","tokenInfo","trim","configToken","getCliUserConfigPath","CONFIG_DIR_OPTIONS","mode","recursive","CONFIG_WRITE_OPTIONS","pretty","cliUserConfigSchema","authToken","optional","string","setCliUserConfig","prop","value","assertCanAccessHostUserConfig","config","readConfig","result","safeParse","success","message","error","issues","map","path","Error","configPath","_","rest","data","getUserConfig","get","key","set","delete","restrictConfigFilePermissions","Array","isArray","err","getuid","uid","SANITY_CLI_CONFIG_PATH"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,SAAS,EAAEC,QAAQ,QAAO,UAAS;AACtD,SAAQC,OAAO,EAAEC,QAAQC,QAAQ,QAAO,YAAW;AAEnD,SAAQC,CAAC,QAAO,WAAU;AAE1B,SAAQC,KAAK,QAAO,0BAAyB;AAC7C,SAAQC,sBAAsB,QAAO,4BAA2B;AAChE,SAAQC,kBAAkB,QAAO,mCAAkC;AACnE,SAAQC,gBAAgB,QAAO,iCAAgC;AAC/D,SAAQC,iBAAiB,QAAO,kCAAiC;AACjE,SACEC,kBAAkB,EAElBC,kBAAkB,EAClBC,kBAAkB,QACb,qBAAoB;AAG3B,8CAA8C;AAC9C,SAAQF,kBAAkB,QAAO,qBAAoB;AAGrD,wB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Workspaces');
50
50
  // Imported lazily: rxjs and `@sanity/client` are only needed here, but this
51
51
  // module is reachable from the `@sanity/cli-core` barrel that every command loads.
52
52
  const [{ firstValueFrom, of }, { getEmptyAuth }] = await Promise.all([
53
- // eslint-disable-next-line no-restricted-syntax -- package import, not a file path
53
+ // eslint-disable-next-line eslint-js/no-restricted-syntax -- package import, not a file path
54
54
  import('rxjs'),
55
- // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path
55
+ // eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path
56
56
  import('../../util/getEmptyAuth.js')
57
57
  ]);
58
58
  const emptyAuth = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\nconst debug = subdebug('worker:getStudioWorkspaces')\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n debug('Finding studio config path %s', configPath)\n const mod = await doImport(configPath)\n // Named exports like `projectId` can make the module itself look like a config\n const config = 'default' in mod && isStudioConfig(mod.default) ? mod.default : mod\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n const workDir = dirname(configPath)\n debug('Work dir %s', workDir)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n // Imported lazily: rxjs and `@sanity/client` are only needed here, but this\n // module is reachable from the `@sanity/cli-core` barrel that every command loads.\n const [{firstValueFrom, of}, {getEmptyAuth}] = await Promise.all([\n // eslint-disable-next-line no-restricted-syntax -- package import, not a file path\n import('rxjs'),\n // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path\n import('../../util/getEmptyAuth.js'),\n ])\n const emptyAuth = {state: of(getEmptyAuth())}\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: emptyAuth,\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","subdebug","doImport","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","mod","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","firstValueFrom","of","getEmptyAuth","Promise","all","emptyAuth","state","unauthedWorkspaces","map","workspace","auth"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAIhD,SAAQC,QAAQ,QAAO,0BAAyB;AAChD,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD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,CAAA;YAC3D,GAAGA,SAAS;YACZC,MAAML;QACR,CAAA;IAEArB,MAAM,0BAA0BuB;IAEhC,OAAOP,eAAeN,cAAca;AACtC"}
1
+ {"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\nconst debug = subdebug('worker:getStudioWorkspaces')\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n debug('Finding studio config path %s', configPath)\n const mod = await doImport(configPath)\n // Named exports like `projectId` can make the module itself look like a config\n const config = 'default' in mod && isStudioConfig(mod.default) ? mod.default : mod\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n const workDir = dirname(configPath)\n debug('Work dir %s', workDir)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n // Imported lazily: rxjs and `@sanity/client` are only needed here, but this\n // module is reachable from the `@sanity/cli-core` barrel that every command loads.\n const [{firstValueFrom, of}, {getEmptyAuth}] = await Promise.all([\n // eslint-disable-next-line eslint-js/no-restricted-syntax -- package import, not a file path\n import('rxjs'),\n // eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path\n import('../../util/getEmptyAuth.js'),\n ])\n const emptyAuth = {state: of(getEmptyAuth())}\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: emptyAuth,\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","subdebug","doImport","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","mod","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","firstValueFrom","of","getEmptyAuth","Promise","all","emptyAuth","state","unauthedWorkspaces","map","workspace","auth"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAIhD,SAAQC,QAAQ,QAAO,0BAAyB;AAChD,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQL,SAAS;AAEvB;;;;;;;;CAQC,GACD,OAAO,eAAeM,oBAAoBC,UAAkB;IAC1D,IAAIR,cAAc;QAChB,MAAM,IAAIS,MAAM;IAClB;IACA,MAAMC,cAAc,AAAC,CAAA,MAAMZ,KAAKU,WAAU,EAAGE,WAAW;IACxD,IAAIA,aAAa;QACfF,aAAa,MAAMJ,qBAAqBI;IAC1C;IACAF,MAAM,iCAAiCE;IACvC,MAAMG,MAAM,MAAMT,SAASM;IAC3B,+EAA+E;IAC/E,MAAMI,SAAS,aAAaD,OAAON,eAAeM,IAAIE,OAAO,IAAIF,IAAIE,OAAO,GAAGF;IAE/EL,MAAM,sBAAsBM;IAC5B,IAAI,CAACP,eAAeO,SAAS;QAC3BN,MAAM,wCAAwCE;QAC9C,MAAM,IAAIM,UAAU,CAAC,iCAAiC,EAAEN,WAAW,CAAC,CAAC;IACvE;IAEA,MAAMO,UAAUhB,QAAQS;IACxBF,MAAM,eAAeS;IACrB,MAAM,EAACC,aAAa,EAAC,GAAG,MAAMb,oBAA6C,UAAUY;IACrF,IAAI,OAAOC,kBAAkB,YAAY;QACvC,MAAM,IAAIF,UAAU;IACtB;IAEA,kFAAkF;IAClF,mFAAmF;IACnF,MAAMG,gBAAgBC,MAAMC,OAAO,CAACP,UAChCA,SACA;QAAC;YAAC,GAAGA,MAAM;YAAEQ,UAAUR,OAAOQ,QAAQ,IAAI;YAAKC,MAAMT,OAAOS,IAAI,IAAI;QAAS;KAAE;IAEnF,4EAA4E;IAC5E,mFAAmF;IACnF,MAAM,CAAC,EAACC,cAAc,EAAEC,EAAE,EAAC,EAAE,EAACC,YAAY,EAAC,CAAC,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAC/D,6FAA6F;QAC7F,MAAM,CAAC;QACP,0GAA0G;QAC1G,MAAM,CAAC;KACR;IACD,MAAMC,YAAY;QAACC,OAAOL,GAAGC;IAAe;IAE5C,MAAMK,qBAAqBZ,cAAca,GAAG,CAAC,CAACC,YAAe,CAAA;YAC3D,GAAGA,SAAS;YACZC,MAAML;QACR,CAAA;IAEArB,MAAM,0BAA0BuB;IAEhC,OAAOP,eAAeN,cAAca;AACtC"}
@@ -9,8 +9,8 @@ import { pathToFileURL } from 'node:url';
9
9
  // Absolute paths in windows are not valid URLs and are not supported by import().
10
10
  // We need to convert the path to a file URL.
11
11
  // See: https://github.com/nodejs/node/issues/31710
12
- const url = /^file:\/\//.test(source) ? source : pathToFileURL(source).href;
13
- // eslint-disable-next-line no-restricted-syntax
12
+ const url = source.startsWith('file://') ? source : pathToFileURL(source).href;
13
+ // eslint-disable-next-line eslint-js/no-restricted-syntax
14
14
  return import(/* @vite-ignore */ url);
15
15
  }
16
16
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n const url = /^file:\\/\\//.test(source) ? source : pathToFileURL(source).href\n // eslint-disable-next-line no-restricted-syntax\n return import(\n /* @vite-ignore */\n url\n )\n}\n"],"names":["pathToFileURL","doImport","source","url","test","href"],"mappings":"AAAA,gDAAgD;AAChD,SAAQA,aAAa,QAAO,WAAU;AAEtC;;;;;CAKC,GACD,OAAO,SAASC,SAASC,MAAc;IACrC,kFAAkF;IAClF,6CAA6C;IAC7C,mDAAmD;IACnD,MAAMC,MAAM,aAAaC,IAAI,CAACF,UAAUA,SAASF,cAAcE,QAAQG,IAAI;IAC3E,gDAAgD;IAChD,OAAO,MAAM,CACX,gBAAgB,GAChBF;AAEJ"}
1
+ {"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n const url = source.startsWith('file://') ? source : pathToFileURL(source).href\n // eslint-disable-next-line eslint-js/no-restricted-syntax\n return import(\n /* @vite-ignore */\n url\n )\n}\n"],"names":["pathToFileURL","doImport","source","url","startsWith","href"],"mappings":"AAAA,gDAAgD;AAChD,SAAQA,aAAa,QAAO,WAAU;AAEtC;;;;;CAKC,GACD,OAAO,SAASC,SAASC,MAAc;IACrC,kFAAkF;IAClF,6CAA6C;IAC7C,mDAAmD;IACnD,MAAMC,MAAMD,OAAOE,UAAU,CAAC,aAAaF,SAASF,cAAcE,QAAQG,IAAI;IAC9E,0DAA0D;IAC1D,OAAO,MAAM,CACX,gBAAgB,GAChBF;AAEJ"}
@@ -18,7 +18,7 @@
18
18
  // even if Node provides them, so realm identity stays consistent.
19
19
  // Imported lazily: `stubs.js` pulls in JSDOM (~600 modules), and this module
20
20
  // is reachable from the `@sanity/cli-core` barrel that every command loads.
21
- // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path
21
+ // eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path
22
22
  const { getBrowserStubs } = await import('./stubs.js');
23
23
  const stubs = getBrowserStubs();
24
24
  const mockedGlobalThis = globalThis;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/util/environment/setupBrowserStubs.ts"],"sourcesContent":["/**\n * Sets up browser globals (window, document, etc.) in the global scope.\n *\n * This is used by both mockBrowserEnvironment (for child processes) and\n * studioWorkerLoader (for worker threads) to provide a browser-like environment.\n *\n * @returns A cleanup function that removes the injected globals\n * @internal\n */\nexport async function setupBrowserStubs(): Promise<() => void> {\n // Guard against double-registering\n if (globalThis.window && '__mockedBySanity' in globalThis.window) {\n return () => {\n /* intentional noop - already mocked */\n }\n }\n\n // Inject browser stubs into global scope. `getBrowserStubs()` has already\n // decided what to inject — including a small set of keys (e.g.\n // `localStorage`/`sessionStorage`/`Storage`) that we want to take from JSDOM\n // even if Node provides them, so realm identity stays consistent.\n // Imported lazily: `stubs.js` pulls in JSDOM (~600 modules), and this module\n // is reachable from the `@sanity/cli-core` barrel that every command loads.\n // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path\n const {getBrowserStubs} = await import('./stubs.js')\n const stubs = getBrowserStubs()\n const mockedGlobalThis: Record<string, unknown> = globalThis\n const stubbedKeys: string[] = []\n const originalDescriptors = new Map<string, PropertyDescriptor>()\n\n for (const key of Object.keys(stubs)) {\n // Snapshot via descriptor to avoid triggering getters (e.g. Node 26's\n // `localStorage` getter logs an ExperimentalWarning on read).\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, key)\n if (descriptor) {\n originalDescriptors.set(key, descriptor)\n // Assignment would throw for getter-only accessors (e.g. Node 26's\n // `localStorage`/`sessionStorage`), so replace the property outright.\n Object.defineProperty(globalThis, key, {\n configurable: true,\n enumerable: descriptor.enumerable,\n value: stubs[key],\n writable: true,\n })\n } else {\n mockedGlobalThis[key] = stubs[key]\n }\n stubbedKeys.push(key)\n }\n\n // Add marker to window to detect double-mocking\n if (globalThis.window) {\n ;(globalThis.window as unknown as Record<string, unknown>).__mockedBySanity = true\n }\n\n // Return cleanup function\n return () => {\n // Remove marker before deleting window\n if (globalThis.window) {\n delete (globalThis.window as unknown as Record<string, unknown>).__mockedBySanity\n }\n\n for (const key of stubbedKeys) {\n const descriptor = originalDescriptors.get(key)\n if (descriptor) {\n Object.defineProperty(globalThis, key, descriptor)\n } else {\n delete mockedGlobalThis[key]\n }\n }\n }\n}\n"],"names":["setupBrowserStubs","globalThis","window","getBrowserStubs","stubs","mockedGlobalThis","stubbedKeys","originalDescriptors","Map","key","Object","keys","descriptor","getOwnPropertyDescriptor","set","defineProperty","configurable","enumerable","value","writable","push","__mockedBySanity","get"],"mappings":"AAAA;;;;;;;;CAQC,GACD,OAAO,eAAeA;IACpB,mCAAmC;IACnC,IAAIC,WAAWC,MAAM,IAAI,sBAAsBD,WAAWC,MAAM,EAAE;QAChE,OAAO;QACL,qCAAqC,GACvC;IACF;IAEA,0EAA0E;IAC1E,+DAA+D;IAC/D,6EAA6E;IAC7E,kEAAkE;IAClE,6EAA6E;IAC7E,4EAA4E;IAC5E,gGAAgG;IAChG,MAAM,EAACC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC;IACvC,MAAMC,QAAQD;IACd,MAAME,mBAA4CJ;IAClD,MAAMK,cAAwB,EAAE;IAChC,MAAMC,sBAAsB,IAAIC;IAEhC,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACP,OAAQ;QACpC,sEAAsE;QACtE,8DAA8D;QAC9D,MAAMQ,aAAaF,OAAOG,wBAAwB,CAACZ,YAAYQ;QAC/D,IAAIG,YAAY;YACdL,oBAAoBO,GAAG,CAACL,KAAKG;YAC7B,mEAAmE;YACnE,sEAAsE;YACtEF,OAAOK,cAAc,CAACd,YAAYQ,KAAK;gBACrCO,cAAc;gBACdC,YAAYL,WAAWK,UAAU;gBACjCC,OAAOd,KAAK,CAACK,IAAI;gBACjBU,UAAU;YACZ;QACF,OAAO;YACLd,gBAAgB,CAACI,IAAI,GAAGL,KAAK,CAACK,IAAI;QACpC;QACAH,YAAYc,IAAI,CAACX;IACnB;IAEA,gDAAgD;IAChD,IAAIR,WAAWC,MAAM,EAAE;;QACnBD,WAAWC,MAAM,CAAwCmB,gBAAgB,GAAG;IAChF;IAEA,0BAA0B;IAC1B,OAAO;QACL,uCAAuC;QACvC,IAAIpB,WAAWC,MAAM,EAAE;YACrB,OAAO,AAACD,WAAWC,MAAM,CAAwCmB,gBAAgB;QACnF;QAEA,KAAK,MAAMZ,OAAOH,YAAa;YAC7B,MAAMM,aAAaL,oBAAoBe,GAAG,CAACb;YAC3C,IAAIG,YAAY;gBACdF,OAAOK,cAAc,CAACd,YAAYQ,KAAKG;YACzC,OAAO;gBACL,OAAOP,gBAAgB,CAACI,IAAI;YAC9B;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/util/environment/setupBrowserStubs.ts"],"sourcesContent":["/**\n * Sets up browser globals (window, document, etc.) in the global scope.\n *\n * This is used by both mockBrowserEnvironment (for child processes) and\n * studioWorkerLoader (for worker threads) to provide a browser-like environment.\n *\n * @returns A cleanup function that removes the injected globals\n * @internal\n */\nexport async function setupBrowserStubs(): Promise<() => void> {\n // Guard against double-registering\n if (globalThis.window && '__mockedBySanity' in globalThis.window) {\n return () => {\n /* intentional noop - already mocked */\n }\n }\n\n // Inject browser stubs into global scope. `getBrowserStubs()` has already\n // decided what to inject — including a small set of keys (e.g.\n // `localStorage`/`sessionStorage`/`Storage`) that we want to take from JSDOM\n // even if Node provides them, so realm identity stays consistent.\n // Imported lazily: `stubs.js` pulls in JSDOM (~600 modules), and this module\n // is reachable from the `@sanity/cli-core` barrel that every command loads.\n // eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path\n const {getBrowserStubs} = await import('./stubs.js')\n const stubs = getBrowserStubs()\n const mockedGlobalThis: Record<string, unknown> = globalThis\n const stubbedKeys: string[] = []\n const originalDescriptors = new Map<string, PropertyDescriptor>()\n\n for (const key of Object.keys(stubs)) {\n // Snapshot via descriptor to avoid triggering getters (e.g. Node 26's\n // `localStorage` getter logs an ExperimentalWarning on read).\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, key)\n if (descriptor) {\n originalDescriptors.set(key, descriptor)\n // Assignment would throw for getter-only accessors (e.g. Node 26's\n // `localStorage`/`sessionStorage`), so replace the property outright.\n Object.defineProperty(globalThis, key, {\n configurable: true,\n enumerable: descriptor.enumerable,\n value: stubs[key],\n writable: true,\n })\n } else {\n mockedGlobalThis[key] = stubs[key]\n }\n stubbedKeys.push(key)\n }\n\n // Add marker to window to detect double-mocking\n if (globalThis.window) {\n ;(globalThis.window as unknown as Record<string, unknown>).__mockedBySanity = true\n }\n\n // Return cleanup function\n return () => {\n // Remove marker before deleting window\n if (globalThis.window) {\n delete (globalThis.window as unknown as Record<string, unknown>).__mockedBySanity\n }\n\n for (const key of stubbedKeys) {\n const descriptor = originalDescriptors.get(key)\n if (descriptor) {\n Object.defineProperty(globalThis, key, descriptor)\n } else {\n delete mockedGlobalThis[key]\n }\n }\n }\n}\n"],"names":["setupBrowserStubs","globalThis","window","getBrowserStubs","stubs","mockedGlobalThis","stubbedKeys","originalDescriptors","Map","key","Object","keys","descriptor","getOwnPropertyDescriptor","set","defineProperty","configurable","enumerable","value","writable","push","__mockedBySanity","get"],"mappings":"AAAA;;;;;;;;CAQC,GACD,OAAO,eAAeA;IACpB,mCAAmC;IACnC,IAAIC,WAAWC,MAAM,IAAI,sBAAsBD,WAAWC,MAAM,EAAE;QAChE,OAAO;QACL,qCAAqC,GACvC;IACF;IAEA,0EAA0E;IAC1E,+DAA+D;IAC/D,6EAA6E;IAC7E,kEAAkE;IAClE,6EAA6E;IAC7E,4EAA4E;IAC5E,0GAA0G;IAC1G,MAAM,EAACC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC;IACvC,MAAMC,QAAQD;IACd,MAAME,mBAA4CJ;IAClD,MAAMK,cAAwB,EAAE;IAChC,MAAMC,sBAAsB,IAAIC;IAEhC,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACP,OAAQ;QACpC,sEAAsE;QACtE,8DAA8D;QAC9D,MAAMQ,aAAaF,OAAOG,wBAAwB,CAACZ,YAAYQ;QAC/D,IAAIG,YAAY;YACdL,oBAAoBO,GAAG,CAACL,KAAKG;YAC7B,mEAAmE;YACnE,sEAAsE;YACtEF,OAAOK,cAAc,CAACd,YAAYQ,KAAK;gBACrCO,cAAc;gBACdC,YAAYL,WAAWK,UAAU;gBACjCC,OAAOd,KAAK,CAACK,IAAI;gBACjBU,UAAU;YACZ;QACF,OAAO;YACLd,gBAAgB,CAACI,IAAI,GAAGL,KAAK,CAACK,IAAI;QACpC;QACAH,YAAYc,IAAI,CAACX;IACnB;IAEA,gDAAgD;IAChD,IAAIR,WAAWC,MAAM,EAAE;;QACnBD,WAAWC,MAAM,CAAwCmB,gBAAgB,GAAG;IAChF;IAEA,0BAA0B;IAC1B,OAAO;QACL,uCAAuC;QACvC,IAAIpB,WAAWC,MAAM,EAAE;YACrB,OAAO,AAACD,WAAWC,MAAM,CAAwCmB,gBAAgB;QACnF;QAEA,KAAK,MAAMZ,OAAOH,YAAa;YAC7B,MAAMM,aAAaL,oBAAoBe,GAAG,CAACb;YAC3C,IAAIG,YAAY;gBACdF,OAAOK,cAAc,CAACd,YAAYQ,KAAKG;YACzC,OAAO;gBACL,OAAOP,gBAAgB,CAACI,IAAI;YAC9B;QACF;IACF;AACF"}
@@ -0,0 +1,50 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import { extname } from 'node:path';
3
+ // The image formats Sanity accepts for uploaded images, such as organization logos. Uploads need
4
+ // an image Content-Type, and the CLI has no other source for one.
5
+ const IMAGE_CONTENT_TYPES = {
6
+ '.avif': 'image/avif',
7
+ '.bmp': 'image/bmp',
8
+ '.gif': 'image/gif',
9
+ '.heic': 'image/heic',
10
+ '.heif': 'image/heif',
11
+ '.jpeg': 'image/jpeg',
12
+ '.jpg': 'image/jpeg',
13
+ '.png': 'image/png',
14
+ '.svg': 'image/svg+xml',
15
+ '.tif': 'image/tiff',
16
+ '.tiff': 'image/tiff',
17
+ '.webp': 'image/webp'
18
+ };
19
+ // Matches the upload limit, so a large file fails here instead of after uploading it.
20
+ const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
21
+ /**
22
+ * Read an image file to upload, such as an organization's logo. Throws an error a user can act on
23
+ * when the file is missing, isn't a supported image type, or is over 5 MB.
24
+ * @public
25
+ */ export async function readImageFile(filePath) {
26
+ const contentType = IMAGE_CONTENT_TYPES[extname(filePath).toLowerCase()];
27
+ if (!contentType) {
28
+ throw new Error(`"${filePath}" isn't a supported image type. Use a PNG, JPEG, GIF, WebP, SVG, BMP, TIFF, HEIF or AVIF file.`);
29
+ }
30
+ let stats;
31
+ try {
32
+ stats = await stat(filePath);
33
+ } catch (error) {
34
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
35
+ throw new Error(`Couldn't find "${filePath}". Check the path and try again.`, {
36
+ cause: error
37
+ });
38
+ }
39
+ throw error;
40
+ }
41
+ if (stats.size > MAX_IMAGE_BYTES) {
42
+ throw new Error(`"${filePath}" is larger than 5 MB, the upload limit. Use a smaller image.`);
43
+ }
44
+ return {
45
+ contentType,
46
+ image: await readFile(filePath)
47
+ };
48
+ }
49
+
50
+ //# sourceMappingURL=readImageFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/readImageFile.ts"],"sourcesContent":["import {type Stats} from 'node:fs'\nimport {readFile, stat} from 'node:fs/promises'\nimport {extname} from 'node:path'\n\n// The image formats Sanity accepts for uploaded images, such as organization logos. Uploads need\n// an image Content-Type, and the CLI has no other source for one.\nconst IMAGE_CONTENT_TYPES: Record<string, string> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.heic': 'image/heic',\n '.heif': 'image/heif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.tif': 'image/tiff',\n '.tiff': 'image/tiff',\n '.webp': 'image/webp',\n}\n\n// Matches the upload limit, so a large file fails here instead of after uploading it.\nconst MAX_IMAGE_BYTES = 5 * 1024 * 1024\n\n/** @public */\nexport interface ImageFile {\n contentType: string\n image: Buffer\n}\n\n/**\n * Read an image file to upload, such as an organization's logo. Throws an error a user can act on\n * when the file is missing, isn't a supported image type, or is over 5 MB.\n * @public\n */\nexport async function readImageFile(filePath: string): Promise<ImageFile> {\n const contentType = IMAGE_CONTENT_TYPES[extname(filePath).toLowerCase()]\n if (!contentType) {\n throw new Error(\n `\"${filePath}\" isn't a supported image type. Use a PNG, JPEG, GIF, WebP, SVG, BMP, TIFF, HEIF or AVIF file.`,\n )\n }\n\n let stats: Stats\n try {\n stats = await stat(filePath)\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {\n throw new Error(`Couldn't find \"${filePath}\". Check the path and try again.`, {cause: error})\n }\n throw error\n }\n\n if (stats.size > MAX_IMAGE_BYTES) {\n throw new Error(`\"${filePath}\" is larger than 5 MB, the upload limit. Use a smaller image.`)\n }\n\n return {contentType, image: await readFile(filePath)}\n}\n"],"names":["readFile","stat","extname","IMAGE_CONTENT_TYPES","MAX_IMAGE_BYTES","readImageFile","filePath","contentType","toLowerCase","Error","stats","error","code","cause","size","image"],"mappings":"AACA,SAAQA,QAAQ,EAAEC,IAAI,QAAO,mBAAkB;AAC/C,SAAQC,OAAO,QAAO,YAAW;AAEjC,iGAAiG;AACjG,kEAAkE;AAClE,MAAMC,sBAA8C;IAClD,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;AACX;AAEA,sFAAsF;AACtF,MAAMC,kBAAkB,IAAI,OAAO;AAQnC;;;;CAIC,GACD,OAAO,eAAeC,cAAcC,QAAgB;IAClD,MAAMC,cAAcJ,mBAAmB,CAACD,QAAQI,UAAUE,WAAW,GAAG;IACxE,IAAI,CAACD,aAAa;QAChB,MAAM,IAAIE,MACR,CAAC,CAAC,EAAEH,SAAS,8FAA8F,CAAC;IAEhH;IAEA,IAAII;IACJ,IAAI;QACFA,QAAQ,MAAMT,KAAKK;IACrB,EAAE,OAAOK,OAAO;QACd,IAAIA,iBAAiBF,SAAS,UAAUE,SAASA,MAAMC,IAAI,KAAK,UAAU;YACxE,MAAM,IAAIH,MAAM,CAAC,eAAe,EAAEH,SAAS,gCAAgC,CAAC,EAAE;gBAACO,OAAOF;YAAK;QAC7F;QACA,MAAMA;IACR;IAEA,IAAID,MAAMI,IAAI,GAAGV,iBAAiB;QAChC,MAAM,IAAIK,MAAM,CAAC,CAAC,EAAEH,SAAS,6DAA6D,CAAC;IAC7F;IAEA,OAAO;QAACC;QAAaQ,OAAO,MAAMf,SAASM;IAAS;AACtD"}
@@ -1,14 +1,20 @@
1
- import { writeFileSync } from 'node:fs';
1
+ import { chmodSync, writeFileSync } from 'node:fs';
2
2
  /**
3
3
  * Serialize the given `data` as JSON and write it synchronously to the given path.
4
4
  *
5
5
  * @param filePath - Path to JSON file to write
6
+ * @param options - `mode` sets the file mode, both for new files and for files that already exist
6
7
  * @internal
7
8
  */ export function writeJsonFileSync(filePath, data, options = {}) {
8
- const { pretty = false } = options;
9
+ const { mode, pretty = false } = options;
9
10
  try {
10
11
  const stringified = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
11
- writeFileSync(filePath, `${stringified}\n`, 'utf8');
12
+ writeFileSync(filePath, `${stringified}\n`, mode === undefined ? 'utf8' : {
13
+ encoding: 'utf8',
14
+ mode
15
+ });
16
+ // `writeFileSync` only applies `mode` when it creates the file
17
+ if (mode !== undefined) chmodSync(filePath, mode);
12
18
  } catch (err) {
13
19
  throw new Error(`Failed to write "${filePath}"`, {
14
20
  cause: err
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/writeJsonFileSync.ts"],"sourcesContent":["import {writeFileSync} from 'node:fs'\n\n/**\n * Serialize the given `data` as JSON and write it synchronously to the given path.\n *\n * @param filePath - Path to JSON file to write\n * @internal\n */\nexport function writeJsonFileSync(\n filePath: string,\n data: unknown,\n options: {pretty?: boolean} = {},\n): void {\n const {pretty = false} = options\n try {\n const stringified = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data)\n writeFileSync(filePath, `${stringified}\\n`, 'utf8')\n } catch (err: unknown) {\n throw new Error(`Failed to write \"${filePath}\"`, {cause: err})\n }\n}\n"],"names":["writeFileSync","writeJsonFileSync","filePath","data","options","pretty","stringified","JSON","stringify","err","Error","cause"],"mappings":"AAAA,SAAQA,aAAa,QAAO,UAAS;AAErC;;;;;CAKC,GACD,OAAO,SAASC,kBACdC,QAAgB,EAChBC,IAAa,EACbC,UAA8B,CAAC,CAAC;IAEhC,MAAM,EAACC,SAAS,KAAK,EAAC,GAAGD;IACzB,IAAI;QACF,MAAME,cAAcD,SAASE,KAAKC,SAAS,CAACL,MAAM,MAAM,KAAKI,KAAKC,SAAS,CAACL;QAC5EH,cAAcE,UAAU,GAAGI,YAAY,EAAE,CAAC,EAAE;IAC9C,EAAE,OAAOG,KAAc;QACrB,MAAM,IAAIC,MAAM,CAAC,iBAAiB,EAAER,SAAS,CAAC,CAAC,EAAE;YAACS,OAAOF;QAAG;IAC9D;AACF"}
1
+ {"version":3,"sources":["../../src/util/writeJsonFileSync.ts"],"sourcesContent":["import {chmodSync, writeFileSync} from 'node:fs'\n\n/**\n * Serialize the given `data` as JSON and write it synchronously to the given path.\n *\n * @param filePath - Path to JSON file to write\n * @param options - `mode` sets the file mode, both for new files and for files that already exist\n * @internal\n */\nexport function writeJsonFileSync(\n filePath: string,\n data: unknown,\n options: {mode?: number; pretty?: boolean} = {},\n): void {\n const {mode, pretty = false} = options\n try {\n const stringified = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data)\n writeFileSync(\n filePath,\n `${stringified}\\n`,\n mode === undefined ? 'utf8' : {encoding: 'utf8', mode},\n )\n // `writeFileSync` only applies `mode` when it creates the file\n if (mode !== undefined) chmodSync(filePath, mode)\n } catch (err: unknown) {\n throw new Error(`Failed to write \"${filePath}\"`, {cause: err})\n }\n}\n"],"names":["chmodSync","writeFileSync","writeJsonFileSync","filePath","data","options","mode","pretty","stringified","JSON","stringify","undefined","encoding","err","Error","cause"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,aAAa,QAAO,UAAS;AAEhD;;;;;;CAMC,GACD,OAAO,SAASC,kBACdC,QAAgB,EAChBC,IAAa,EACbC,UAA6C,CAAC,CAAC;IAE/C,MAAM,EAACC,IAAI,EAAEC,SAAS,KAAK,EAAC,GAAGF;IAC/B,IAAI;QACF,MAAMG,cAAcD,SAASE,KAAKC,SAAS,CAACN,MAAM,MAAM,KAAKK,KAAKC,SAAS,CAACN;QAC5EH,cACEE,UACA,GAAGK,YAAY,EAAE,CAAC,EAClBF,SAASK,YAAY,SAAS;YAACC,UAAU;YAAQN;QAAI;QAEvD,+DAA+D;QAC/D,IAAIA,SAASK,WAAWX,UAAUG,UAAUG;IAC9C,EAAE,OAAOO,KAAc;QACrB,MAAM,IAAIC,MAAM,CAAC,iBAAiB,EAAEX,SAAS,CAAC,CAAC,EAAE;YAACY,OAAOF;QAAG;IAC9D;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-core",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "description": "Sanity CLI core package",
5
5
  "keywords": [
6
6
  "cli",
@@ -61,6 +61,10 @@
61
61
  "source": "./src/_exports/errors.ts",
62
62
  "default": "./dist/_exports/errors.js"
63
63
  },
64
+ "./images": {
65
+ "source": "./src/_exports/images.ts",
66
+ "default": "./dist/_exports/images.js"
67
+ },
64
68
  "./executionContext": {
65
69
  "source": "./src/executionContext.ts",
66
70
  "default": "./dist/executionContext.js"
@@ -121,11 +125,11 @@
121
125
  "dependencies": {
122
126
  "@inquirer/core": "^12.0.6",
123
127
  "@inquirer/prompts": "^8.7.5",
124
- "@oclif/core": "^4.11.14",
125
- "@sanity/client": "^8.15.0",
128
+ "@oclif/core": "^4.14.0",
129
+ "@sanity/client": "^8.17.0",
126
130
  "boxen": "^8.0.1",
127
- "empathic": "^2.0.1",
128
- "get-it": "^9.5.4",
131
+ "empathic": "^2.1.0",
132
+ "get-it": "^9.7.0",
129
133
  "get-tsconfig": "^4.14.3",
130
134
  "import-meta-resolve": "^4.2.0",
131
135
  "jiti": "^2.7.0",
@@ -140,10 +144,9 @@
140
144
  "zod": "^4.6.7"
141
145
  },
142
146
  "devDependencies": {
143
- "@eslint/compat": "^2.1.0",
147
+ "@repo/oxc-config": "0.0.0",
144
148
  "@repo/package.config": "0.0.1",
145
149
  "@repo/tsconfig": "3.70.0",
146
- "@sanity/eslint-config-cli": "1.1.3",
147
150
  "@sanity/pkg-utils": "^12.3.4",
148
151
  "@sanity/telemetry": "^1.1.0",
149
152
  "@swc/cli": "^0.8.2",
@@ -151,12 +154,12 @@
151
154
  "@types/jsdom": "^28.0.3",
152
155
  "@types/node": "^22.20.5",
153
156
  "babel-plugin-react-compiler": "^1.0.0",
154
- "eslint": "^10.7.0",
155
157
  "oxc-transform-react": "^0.158.0",
156
- "publint": "^0.3.21",
157
- "sanity": "^6.22.0",
158
+ "oxlint": "^1.94.0",
159
+ "publint": "^0.3.25",
160
+ "sanity": "^6.24.0",
158
161
  "typescript": "^6.0.3",
159
- "vitest": "^5.1.0"
162
+ "vitest": "^5.1.1"
160
163
  },
161
164
  "peerDependencies": {
162
165
  "babel-plugin-react-compiler": "*",
@@ -177,12 +180,12 @@
177
180
  "build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
178
181
  "build:types": "pkg-utils build --emitDeclarationOnly",
179
182
  "check:types": "tsc --noEmit",
180
- "lint": "eslint .",
181
183
  "publint": "publint",
182
184
  "test": "vitest run",
183
185
  "posttest": "pnpm run lint",
184
186
  "test:coverage": "vitest run --coverage",
185
187
  "test:watch": "vitest",
186
- "watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src"
188
+ "watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src",
189
+ "lint": "oxlint -c oxlint.config.ts"
187
190
  }
188
191
  }