@sanity/cli-core 3.7.0 → 3.8.1
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.
- package/README.md +18 -0
- package/dist/SanityCommand.d.ts +2 -2
- package/dist/_exports/commandPolicy.d.ts +149 -0
- package/dist/_exports/commandPolicy.js +3 -0
- package/dist/_exports/commandPolicy.js.map +1 -0
- package/dist/_exports/index.d.ts +1 -1
- package/dist/_exports/schemas.d.ts +1 -1
- package/dist/_exports/types.d.ts +1 -1
- package/dist/commandPolicy.js +115 -0
- package/dist/commandPolicy.js.map +1 -0
- package/dist/config/cli/schemas.js +4 -1
- package/dist/config/cli/schemas.js.map +1 -1
- package/dist/loaders/studio/studioModuleEvaluator.js +5 -11
- package/dist/loaders/studio/studioModuleEvaluator.js.map +1 -1
- package/dist/{schemas-BUfBJffI.d.ts → schemas-DDpPtgia.d.ts} +2 -1
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -27,6 +27,24 @@ Browser environment mock. Note this depends on `jsdom` (~46 MB) and so has non-t
|
|
|
27
27
|
| -------------------------- | ---------------------------------------------- |
|
|
28
28
|
| `mockBrowserEnvironment()` | Set up a mocked browser environment via JSDOM. |
|
|
29
29
|
|
|
30
|
+
## `@sanity/cli-core/commandPolicy`
|
|
31
|
+
|
|
32
|
+
The contract for exposing commands to programmatic invocation sources, such as the remote MCP server.
|
|
33
|
+
|
|
34
|
+
| Export | Description |
|
|
35
|
+
| ------------------------------------------ | ------------------------------------------------------------------------------------ |
|
|
36
|
+
| `allow` | Policy stating every valid invocation of the command is safe. |
|
|
37
|
+
| `deny` | Policy stating no invocation is safe; the command behaves like an unknown one. |
|
|
38
|
+
| `conditionalDenyFlags(...names)` | Policy refusing the named flags, which are also hidden from rendered help. |
|
|
39
|
+
| `conditionalPolicy(options)` | `conditionalDenyFlags` plus an extra predicate on the parsed invocation. |
|
|
40
|
+
| `definePluginInvocationPolicies(policies)` | Type-checked identity helper for authoring a plugin's policy module. |
|
|
41
|
+
| `isCommandPolicySet(value)` | Whether a value is a usable policy table. Used by the host to verify plugin modules. |
|
|
42
|
+
| `isConditionalInvocationPolicy(policy)` | Type-guard narrowing a policy to its conditional form. |
|
|
43
|
+
| `CommandPolicy` | One command's policy: a `kind` and a `validate` predicate. |
|
|
44
|
+
| `CommandPolicySet` | A complete policy table, keyed by oclif command id. |
|
|
45
|
+
| `InvocationSource` | Where an invocation originates; selects the policy to enforce. |
|
|
46
|
+
| `PluginInvocationPolicies` | The policies a plugin declares, keyed by invocation source. |
|
|
47
|
+
|
|
30
48
|
## `@sanity/cli-core/config`
|
|
31
49
|
|
|
32
50
|
CLI, studio, and workspace configuration helpers.
|
package/dist/SanityCommand.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ declare abstract class SanityCommand<T extends typeof Command> extends Command i
|
|
|
35
35
|
*
|
|
36
36
|
* @deprecated use `getGlobalCliClient` function directly instead.
|
|
37
37
|
*/
|
|
38
|
-
protected getGlobalApiClient: (args: GlobalCliClientOptions) => Promise<import("
|
|
38
|
+
protected getGlobalApiClient: (args: GlobalCliClientOptions) => Promise<import("sanity").SanityClient>;
|
|
39
39
|
/**
|
|
40
40
|
* Get the project API client.
|
|
41
41
|
*
|
|
@@ -44,7 +44,7 @@ declare abstract class SanityCommand<T extends typeof Command> extends Command i
|
|
|
44
44
|
*
|
|
45
45
|
* @deprecated use `getProjectCliClient` function directly instead.
|
|
46
46
|
*/
|
|
47
|
-
protected getProjectApiClient: (args: ProjectCliClientOptions) => Promise<import("
|
|
47
|
+
protected getProjectApiClient: (args: ProjectCliClientOptions) => Promise<import("sanity").SanityClient>;
|
|
48
48
|
/**
|
|
49
49
|
* Helper for outputting to the console.
|
|
50
50
|
*
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { z } from "zod/mini";
|
|
2
|
+
/**
|
|
3
|
+
* The contract for exposing CLI commands to programmatic invocation sources,
|
|
4
|
+
* such as the remote MCP server.
|
|
5
|
+
*
|
|
6
|
+
* A command reaches a programmatic caller only when it satisfies both halves
|
|
7
|
+
* of this contract:
|
|
8
|
+
*
|
|
9
|
+
* 1. **Capability.** The command must be runnable in isolation, which means
|
|
10
|
+
* extending `SanityCommand` (see `@sanity/cli-core/SanityCommand`). That
|
|
11
|
+
* base class supplies `runInExecutionContext()` and routes output, token
|
|
12
|
+
* resolution, interactivity, and project discovery through the CLI
|
|
13
|
+
* execution context. A command extending oclif's `Command` directly cannot
|
|
14
|
+
* be invoked programmatically, no matter what policy it declares.
|
|
15
|
+
* 2. **Policy.** Something must state that the invocation is safe. For the
|
|
16
|
+
* `@sanity/cli` package's own commands that statement lives in the CLI. A
|
|
17
|
+
* plugin states it for its own commands by declaring a policy module (see
|
|
18
|
+
* {@link PluginInvocationPolicies}).
|
|
19
|
+
*
|
|
20
|
+
* Anything not covered by both halves is denied. The absence of a policy is
|
|
21
|
+
* never read as permission.
|
|
22
|
+
*/
|
|
23
|
+
/** The command invocation a conditional policy is evaluated against. */
|
|
24
|
+
declare const InvocationPolicySchema: z.ZodMiniFunction<z.ZodMiniTuple<[z.ZodMiniObject<{
|
|
25
|
+
args: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
26
|
+
flags: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
27
|
+
}, z.core.$strip>], null>, z.ZodMiniBoolean<boolean>>;
|
|
28
|
+
declare const CommandPolicyConditionalSchema: z.ZodMiniObject<{
|
|
29
|
+
deniedFlags: z.ZodMiniArray<z.ZodMiniString<string>>;
|
|
30
|
+
kind: z.ZodMiniLiteral<"conditional">;
|
|
31
|
+
validate: z.ZodMiniFunction<z.ZodMiniTuple<[z.ZodMiniObject<{
|
|
32
|
+
args: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
33
|
+
flags: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
34
|
+
}, z.core.$strip>], null>, z.ZodMiniBoolean<boolean>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
declare const CommandPolicySchema: z.ZodMiniUnion<readonly [z.ZodMiniObject<{
|
|
37
|
+
kind: z.ZodMiniEnum<{
|
|
38
|
+
allow: "allow";
|
|
39
|
+
deny: "deny";
|
|
40
|
+
}>;
|
|
41
|
+
validate: z.ZodMiniFunction<z.ZodMiniTuple<[z.ZodMiniObject<{
|
|
42
|
+
args: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
43
|
+
flags: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
44
|
+
}, z.core.$strip>], null>, z.ZodMiniBoolean<boolean>>;
|
|
45
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
46
|
+
deniedFlags: z.ZodMiniArray<z.ZodMiniString<string>>;
|
|
47
|
+
kind: z.ZodMiniLiteral<"conditional">;
|
|
48
|
+
validate: z.ZodMiniFunction<z.ZodMiniTuple<[z.ZodMiniObject<{
|
|
49
|
+
args: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
50
|
+
flags: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
51
|
+
}, z.core.$strip>], null>, z.ZodMiniBoolean<boolean>>;
|
|
52
|
+
}, z.core.$strip>]>;
|
|
53
|
+
declare const CommandPolicySetSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnion<readonly [z.ZodMiniObject<{
|
|
54
|
+
kind: z.ZodMiniEnum<{
|
|
55
|
+
allow: "allow";
|
|
56
|
+
deny: "deny";
|
|
57
|
+
}>;
|
|
58
|
+
validate: z.ZodMiniFunction<z.ZodMiniTuple<[z.ZodMiniObject<{
|
|
59
|
+
args: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
60
|
+
flags: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
61
|
+
}, z.core.$strip>], null>, z.ZodMiniBoolean<boolean>>;
|
|
62
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
63
|
+
deniedFlags: z.ZodMiniArray<z.ZodMiniString<string>>;
|
|
64
|
+
kind: z.ZodMiniLiteral<"conditional">;
|
|
65
|
+
validate: z.ZodMiniFunction<z.ZodMiniTuple<[z.ZodMiniObject<{
|
|
66
|
+
args: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
67
|
+
flags: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
68
|
+
}, z.core.$strip>], null>, z.ZodMiniBoolean<boolean>>;
|
|
69
|
+
}, z.core.$strip>]>>;
|
|
70
|
+
type InvocationPolicy = z.infer<typeof InvocationPolicySchema>;
|
|
71
|
+
type ConditionalInvocationPolicy = z.infer<typeof CommandPolicyConditionalSchema>;
|
|
72
|
+
type CommandPolicy = z.infer<typeof CommandPolicySchema>;
|
|
73
|
+
/** A complete policy table, keyed by oclif command id. */
|
|
74
|
+
type CommandPolicySet = z.infer<typeof CommandPolicySetSchema>;
|
|
75
|
+
/** Where an invocation originates; selects the policy to enforce. */
|
|
76
|
+
type InvocationSource = 'mcp';
|
|
77
|
+
/**
|
|
78
|
+
* The policies a plugin declares for the commands it contributes, keyed by
|
|
79
|
+
* invocation source. A source left out denies every command for that source.
|
|
80
|
+
*
|
|
81
|
+
* Declared by pointing at the module from the plugin's package.json:
|
|
82
|
+
*
|
|
83
|
+
* ```json
|
|
84
|
+
* {"sanity": {"invocationPolicies": "./dist/invocationPolicies.js"}}
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* The module must provide this table as a named `invocationPolicies` export.
|
|
88
|
+
* It is resolved once per plugin, so root help stays cheap, and it is code
|
|
89
|
+
* rather than JSON so conditional policies can inspect parsed invocations.
|
|
90
|
+
*
|
|
91
|
+
* Two limits apply, and neither is negotiable by the declaring plugin:
|
|
92
|
+
* entries for commands the plugin does not contribute are ignored, and a
|
|
93
|
+
* command the hosting CLI already governs keeps the CLI's own policy. A
|
|
94
|
+
* declaration is a request to expose surface, not a grant.
|
|
95
|
+
*/
|
|
96
|
+
type PluginInvocationPolicies = Partial<Record<InvocationSource, CommandPolicySet>>;
|
|
97
|
+
/** Every valid invocation of the command is safe. */
|
|
98
|
+
declare const allow: CommandPolicy;
|
|
99
|
+
/** No invocation of the command is safe. Behaves like an unknown command. */
|
|
100
|
+
declare const deny: CommandPolicy;
|
|
101
|
+
/**
|
|
102
|
+
* Conditional policies to deny flags. The flags are also hidden
|
|
103
|
+
* from rendered help, so hosts are never told about surface they cannot use.
|
|
104
|
+
*/
|
|
105
|
+
declare function conditionalDenyFlags(...names: string[]): ConditionalInvocationPolicy;
|
|
106
|
+
/**
|
|
107
|
+
* Conditional policy combining {@link conditionalDenyFlags} with an extra
|
|
108
|
+
* predicate on the parsed invocation, for conditions a flag name alone
|
|
109
|
+
* cannot express — e.g. flag values that would read from the host machine.
|
|
110
|
+
* `deniedFlags` are hidden from rendered help; the predicate is not
|
|
111
|
+
* expressible there, so flags it constrains stay advertised.
|
|
112
|
+
*/
|
|
113
|
+
declare function conditionalPolicy(options: {
|
|
114
|
+
deniedFlags?: string[];
|
|
115
|
+
validate: InvocationPolicy;
|
|
116
|
+
}): ConditionalInvocationPolicy;
|
|
117
|
+
/**
|
|
118
|
+
* Type-checked identity helper for authoring a plugin's policy module.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* import {allow, definePluginInvocationPolicies, deny} from '@sanity/cli-core/commandPolicy'
|
|
122
|
+
*
|
|
123
|
+
* export const invocationPolicies = definePluginInvocationPolicies({
|
|
124
|
+
* mcp: {
|
|
125
|
+
* 'widgets:list': allow,
|
|
126
|
+
* // Reads widget definitions from the local filesystem.
|
|
127
|
+
* 'widgets:push': deny,
|
|
128
|
+
* },
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare function definePluginInvocationPolicies(policies: PluginInvocationPolicies): PluginInvocationPolicies;
|
|
133
|
+
/**
|
|
134
|
+
* Identified by shape rather than by identity, because a plugin's policies are
|
|
135
|
+
* built against its own copy of this module.
|
|
136
|
+
*
|
|
137
|
+
* `deniedFlags` is checked as well as `kind`, so callers that read it off the
|
|
138
|
+
* narrowed type cannot be handed an object that only claims to be conditional.
|
|
139
|
+
*/
|
|
140
|
+
declare function isConditionalInvocationPolicy(policy: CommandPolicy): policy is ConditionalInvocationPolicy;
|
|
141
|
+
/**
|
|
142
|
+
* Whether an arbitrary value is a usable policy table. Plugin policy modules
|
|
143
|
+
* are third-party code loaded at runtime, so their shape is verified rather
|
|
144
|
+
* than trusted; anything that does not match is treated as no declaration at
|
|
145
|
+
* all, which denies the plugin's commands.
|
|
146
|
+
*/
|
|
147
|
+
declare function isCommandPolicySet(value: unknown): value is CommandPolicySet;
|
|
148
|
+
export { CommandPolicy, CommandPolicySet, InvocationSource, PluginInvocationPolicies, allow, conditionalDenyFlags, conditionalPolicy, definePluginInvocationPolicies, deny, isCommandPolicySet, isConditionalInvocationPolicy };
|
|
149
|
+
//# sourceMappingURL=commandPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/commandPolicy.ts"],"sourcesContent":["export * from '../commandPolicy.js'\n"],"names":[],"mappings":"AAAA,cAAc,sBAAqB"}
|
package/dist/_exports/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { a as isCi, i as isInteractive, n as normalizePath, o as importModule, r
|
|
|
18
18
|
import { a as getLocalPackageVersion, i as getLocalPackageDir, n as resolveLocalPackageFrom, r as resolveLocalPackagePath, t as resolveLocalPackage } from "../resolveLocalPackage-Dr-TNTyk.js";
|
|
19
19
|
import { n as ReadPackageJsonOptions, r as readPackageJson, t as PackageJson } from "../readPackageJson-Cr_lbjVR.js";
|
|
20
20
|
import { n as colorizeJson, t as getTimer } from "../timer-Dwu2TIgB.js";
|
|
21
|
-
import { i as studioManifestSchema, n as StudioManifest, r as coreAppManifestSchema, t as CoreAppManifest } from "../schemas-
|
|
21
|
+
import { i as studioManifestSchema, n as StudioManifest, r as coreAppManifestSchema, t as CoreAppManifest } from "../schemas-DDpPtgia.js";
|
|
22
22
|
import { WorkerOptions } from "node:worker_threads";
|
|
23
23
|
interface PromisifyWorkerOptions extends WorkerOptions {
|
|
24
24
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as cliConfigSchema, i as studioManifestSchema, n as StudioManifest, r as coreAppManifestSchema, t as CoreAppManifest } from "../schemas-
|
|
1
|
+
import { a as cliConfigSchema, i as studioManifestSchema, n as StudioManifest, r as coreAppManifestSchema, t as CoreAppManifest } from "../schemas-DDpPtgia.js";
|
|
2
2
|
export { type CoreAppManifest, type StudioManifest, cliConfigSchema, coreAppManifestSchema, studioManifestSchema };
|
package/dist/_exports/types.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { n as RequireProps, r as SanityOrgUser, t as Output } from "../types-CwJ
|
|
|
5
5
|
import { SanityCommandInterface } from "../SanityCommand.js";
|
|
6
6
|
import { t as ApplicationType } from "../workbenchApp-DVKwpTyU.js";
|
|
7
7
|
import { n as ReadPackageJsonOptions, t as PackageJson } from "../readPackageJson-Cr_lbjVR.js";
|
|
8
|
-
import { n as StudioManifest, t as CoreAppManifest } from "../schemas-
|
|
8
|
+
import { n as StudioManifest, t as CoreAppManifest } from "../schemas-DDpPtgia.js";
|
|
9
9
|
export type { ApplicationType, CLITelemetryStore, CliConfig, ConfigStore, ConsentInformation, CoreAppManifest, Output, PackageJson, ProjectRootResult, ReactCompilerConfig, ReadPackageJsonOptions, RequireProps, SanityCommandInterface, SanityOrgUser, StudioManifest, TelemetryUserProperties, TypeGenConfig, UserViteConfig };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { z } from 'zod/mini';
|
|
2
|
+
/**
|
|
3
|
+
* The contract for exposing CLI commands to programmatic invocation sources,
|
|
4
|
+
* such as the remote MCP server.
|
|
5
|
+
*
|
|
6
|
+
* A command reaches a programmatic caller only when it satisfies both halves
|
|
7
|
+
* of this contract:
|
|
8
|
+
*
|
|
9
|
+
* 1. **Capability.** The command must be runnable in isolation, which means
|
|
10
|
+
* extending `SanityCommand` (see `@sanity/cli-core/SanityCommand`). That
|
|
11
|
+
* base class supplies `runInExecutionContext()` and routes output, token
|
|
12
|
+
* resolution, interactivity, and project discovery through the CLI
|
|
13
|
+
* execution context. A command extending oclif's `Command` directly cannot
|
|
14
|
+
* be invoked programmatically, no matter what policy it declares.
|
|
15
|
+
* 2. **Policy.** Something must state that the invocation is safe. For the
|
|
16
|
+
* `@sanity/cli` package's own commands that statement lives in the CLI. A
|
|
17
|
+
* plugin states it for its own commands by declaring a policy module (see
|
|
18
|
+
* {@link PluginInvocationPolicies}).
|
|
19
|
+
*
|
|
20
|
+
* Anything not covered by both halves is denied. The absence of a policy is
|
|
21
|
+
* never read as permission.
|
|
22
|
+
*/ /** The command invocation a conditional policy is evaluated against. */ const InvocationPolicySchema = z.function({
|
|
23
|
+
input: [
|
|
24
|
+
z.object({
|
|
25
|
+
args: z.record(z.string(), z.unknown()),
|
|
26
|
+
flags: z.record(z.string(), z.unknown())
|
|
27
|
+
})
|
|
28
|
+
],
|
|
29
|
+
output: z.boolean()
|
|
30
|
+
});
|
|
31
|
+
// A conditional entry must carry the deniedFlags list for the help renderer
|
|
32
|
+
// to omit them from the advertised command surface.
|
|
33
|
+
const CommandPolicyConditionalSchema = z.object({
|
|
34
|
+
deniedFlags: z.array(z.string()),
|
|
35
|
+
kind: z.literal('conditional'),
|
|
36
|
+
validate: InvocationPolicySchema
|
|
37
|
+
});
|
|
38
|
+
const CommandPolicySchema = z.union([
|
|
39
|
+
z.object({
|
|
40
|
+
kind: z.enum([
|
|
41
|
+
'allow',
|
|
42
|
+
'deny'
|
|
43
|
+
]),
|
|
44
|
+
validate: InvocationPolicySchema
|
|
45
|
+
}),
|
|
46
|
+
CommandPolicyConditionalSchema
|
|
47
|
+
]);
|
|
48
|
+
const CommandPolicySetSchema = z.record(z.string(), CommandPolicySchema);
|
|
49
|
+
/** Every valid invocation of the command is safe. */ export const allow = {
|
|
50
|
+
kind: 'allow',
|
|
51
|
+
validate: ()=>true
|
|
52
|
+
};
|
|
53
|
+
/** No invocation of the command is safe. Behaves like an unknown command. */ export const deny = {
|
|
54
|
+
kind: 'deny',
|
|
55
|
+
validate: ()=>false
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Conditional policies to deny flags. The flags are also hidden
|
|
59
|
+
* from rendered help, so hosts are never told about surface they cannot use.
|
|
60
|
+
*/ export function conditionalDenyFlags(...names) {
|
|
61
|
+
return {
|
|
62
|
+
deniedFlags: names,
|
|
63
|
+
kind: 'conditional',
|
|
64
|
+
validate: ({ flags })=>names.every((name)=>flags[name] === undefined || flags[name] === false)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Conditional policy combining {@link conditionalDenyFlags} with an extra
|
|
69
|
+
* predicate on the parsed invocation, for conditions a flag name alone
|
|
70
|
+
* cannot express — e.g. flag values that would read from the host machine.
|
|
71
|
+
* `deniedFlags` are hidden from rendered help; the predicate is not
|
|
72
|
+
* expressible there, so flags it constrains stay advertised.
|
|
73
|
+
*/ export function conditionalPolicy(options) {
|
|
74
|
+
const denyFlags = conditionalDenyFlags(...options.deniedFlags ?? []);
|
|
75
|
+
return {
|
|
76
|
+
...denyFlags,
|
|
77
|
+
validate: (invocation)=>denyFlags.validate(invocation) && options.validate(invocation)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Type-checked identity helper for authoring a plugin's policy module.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* import {allow, definePluginInvocationPolicies, deny} from '@sanity/cli-core/commandPolicy'
|
|
85
|
+
*
|
|
86
|
+
* export const invocationPolicies = definePluginInvocationPolicies({
|
|
87
|
+
* mcp: {
|
|
88
|
+
* 'widgets:list': allow,
|
|
89
|
+
* // Reads widget definitions from the local filesystem.
|
|
90
|
+
* 'widgets:push': deny,
|
|
91
|
+
* },
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/ export function definePluginInvocationPolicies(policies) {
|
|
95
|
+
return policies;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Identified by shape rather than by identity, because a plugin's policies are
|
|
99
|
+
* built against its own copy of this module.
|
|
100
|
+
*
|
|
101
|
+
* `deniedFlags` is checked as well as `kind`, so callers that read it off the
|
|
102
|
+
* narrowed type cannot be handed an object that only claims to be conditional.
|
|
103
|
+
*/ export function isConditionalInvocationPolicy(policy) {
|
|
104
|
+
return CommandPolicyConditionalSchema.safeParse(policy).success;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether an arbitrary value is a usable policy table. Plugin policy modules
|
|
108
|
+
* are third-party code loaded at runtime, so their shape is verified rather
|
|
109
|
+
* than trusted; anything that does not match is treated as no declaration at
|
|
110
|
+
* all, which denies the plugin's commands.
|
|
111
|
+
*/ export function isCommandPolicySet(value) {
|
|
112
|
+
return CommandPolicySetSchema.safeParse(value).success;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=commandPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commandPolicy.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\n/**\n * The contract for exposing CLI commands to programmatic invocation sources,\n * such as the remote MCP server.\n *\n * A command reaches a programmatic caller only when it satisfies both halves\n * of this contract:\n *\n * 1. **Capability.** The command must be runnable in isolation, which means\n * extending `SanityCommand` (see `@sanity/cli-core/SanityCommand`). That\n * base class supplies `runInExecutionContext()` and routes output, token\n * resolution, interactivity, and project discovery through the CLI\n * execution context. A command extending oclif's `Command` directly cannot\n * be invoked programmatically, no matter what policy it declares.\n * 2. **Policy.** Something must state that the invocation is safe. For the\n * `@sanity/cli` package's own commands that statement lives in the CLI. A\n * plugin states it for its own commands by declaring a policy module (see\n * {@link PluginInvocationPolicies}).\n *\n * Anything not covered by both halves is denied. The absence of a policy is\n * never read as permission.\n */\n\n/** The command invocation a conditional policy is evaluated against. */\nconst InvocationPolicySchema = z.function({\n input: [\n z.object({\n args: z.record(z.string(), z.unknown()),\n flags: z.record(z.string(), z.unknown()),\n }),\n ],\n output: z.boolean(),\n})\n\n// A conditional entry must carry the deniedFlags list for the help renderer\n// to omit them from the advertised command surface.\nconst CommandPolicyConditionalSchema = z.object({\n deniedFlags: z.array(z.string()),\n kind: z.literal('conditional'),\n validate: InvocationPolicySchema,\n})\n\nconst CommandPolicySchema = z.union([\n z.object({\n kind: z.enum(['allow', 'deny']),\n validate: InvocationPolicySchema,\n }),\n CommandPolicyConditionalSchema,\n])\n\nconst CommandPolicySetSchema = z.record(z.string(), CommandPolicySchema)\n\ntype InvocationPolicy = z.infer<typeof InvocationPolicySchema>\n\ntype ConditionalInvocationPolicy = z.infer<typeof CommandPolicyConditionalSchema>\n\nexport type CommandPolicy = z.infer<typeof CommandPolicySchema>\n\n/** A complete policy table, keyed by oclif command id. */\nexport type CommandPolicySet = z.infer<typeof CommandPolicySetSchema>\n\n/** Where an invocation originates; selects the policy to enforce. */\nexport type InvocationSource = 'mcp'\n\n/**\n * The policies a plugin declares for the commands it contributes, keyed by\n * invocation source. A source left out denies every command for that source.\n *\n * Declared by pointing at the module from the plugin's package.json:\n *\n * ```json\n * {\"sanity\": {\"invocationPolicies\": \"./dist/invocationPolicies.js\"}}\n * ```\n *\n * The module must provide this table as a named `invocationPolicies` export.\n * It is resolved once per plugin, so root help stays cheap, and it is code\n * rather than JSON so conditional policies can inspect parsed invocations.\n *\n * Two limits apply, and neither is negotiable by the declaring plugin:\n * entries for commands the plugin does not contribute are ignored, and a\n * command the hosting CLI already governs keeps the CLI's own policy. A\n * declaration is a request to expose surface, not a grant.\n */\nexport type PluginInvocationPolicies = Partial<Record<InvocationSource, CommandPolicySet>>\n\n/** Every valid invocation of the command is safe. */\nexport const allow: CommandPolicy = {kind: 'allow', validate: () => true}\n\n/** No invocation of the command is safe. Behaves like an unknown command. */\nexport const deny: CommandPolicy = {kind: 'deny', validate: () => false}\n\n/**\n * Conditional policies to deny flags. The flags are also hidden\n * from rendered help, so hosts are never told about surface they cannot use.\n */\nexport function conditionalDenyFlags(...names: string[]): ConditionalInvocationPolicy {\n return {\n deniedFlags: names,\n kind: 'conditional',\n validate: ({flags}) =>\n names.every((name) => flags[name] === undefined || flags[name] === false),\n }\n}\n\n/**\n * Conditional policy combining {@link conditionalDenyFlags} with an extra\n * predicate on the parsed invocation, for conditions a flag name alone\n * cannot express — e.g. flag values that would read from the host machine.\n * `deniedFlags` are hidden from rendered help; the predicate is not\n * expressible there, so flags it constrains stay advertised.\n */\nexport function conditionalPolicy(options: {\n deniedFlags?: string[]\n validate: InvocationPolicy\n}): ConditionalInvocationPolicy {\n const denyFlags = conditionalDenyFlags(...(options.deniedFlags ?? []))\n return {\n ...denyFlags,\n validate: (invocation) => denyFlags.validate(invocation) && options.validate(invocation),\n }\n}\n\n/**\n * Type-checked identity helper for authoring a plugin's policy module.\n *\n * ```ts\n * import {allow, definePluginInvocationPolicies, deny} from '@sanity/cli-core/commandPolicy'\n *\n * export const invocationPolicies = definePluginInvocationPolicies({\n * mcp: {\n * 'widgets:list': allow,\n * // Reads widget definitions from the local filesystem.\n * 'widgets:push': deny,\n * },\n * })\n * ```\n */\nexport function definePluginInvocationPolicies(\n policies: PluginInvocationPolicies,\n): PluginInvocationPolicies {\n return policies\n}\n\n/**\n * Identified by shape rather than by identity, because a plugin's policies are\n * built against its own copy of this module.\n *\n * `deniedFlags` is checked as well as `kind`, so callers that read it off the\n * narrowed type cannot be handed an object that only claims to be conditional.\n */\nexport function isConditionalInvocationPolicy(\n policy: CommandPolicy,\n): policy is ConditionalInvocationPolicy {\n return CommandPolicyConditionalSchema.safeParse(policy).success\n}\n\n/**\n * Whether an arbitrary value is a usable policy table. Plugin policy modules\n * are third-party code loaded at runtime, so their shape is verified rather\n * than trusted; anything that does not match is treated as no declaration at\n * all, which denies the plugin's commands.\n */\nexport function isCommandPolicySet(value: unknown): value is CommandPolicySet {\n return CommandPolicySetSchema.safeParse(value).success\n}\n"],"names":["z","InvocationPolicySchema","function","input","object","args","record","string","unknown","flags","output","boolean","CommandPolicyConditionalSchema","deniedFlags","array","kind","literal","validate","CommandPolicySchema","union","enum","CommandPolicySetSchema","allow","deny","conditionalDenyFlags","names","every","name","undefined","conditionalPolicy","options","denyFlags","invocation","definePluginInvocationPolicies","policies","isConditionalInvocationPolicy","policy","safeParse","success","isCommandPolicySet","value"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B;;;;;;;;;;;;;;;;;;;;CAoBC,GAED,sEAAsE,GACtE,MAAMC,yBAAyBD,EAAEE,QAAQ,CAAC;IACxCC,OAAO;QACLH,EAAEI,MAAM,CAAC;YACPC,MAAML,EAAEM,MAAM,CAACN,EAAEO,MAAM,IAAIP,EAAEQ,OAAO;YACpCC,OAAOT,EAAEM,MAAM,CAACN,EAAEO,MAAM,IAAIP,EAAEQ,OAAO;QACvC;KACD;IACDE,QAAQV,EAAEW,OAAO;AACnB;AAEA,4EAA4E;AAC5E,oDAAoD;AACpD,MAAMC,iCAAiCZ,EAAEI,MAAM,CAAC;IAC9CS,aAAab,EAAEc,KAAK,CAACd,EAAEO,MAAM;IAC7BQ,MAAMf,EAAEgB,OAAO,CAAC;IAChBC,UAAUhB;AACZ;AAEA,MAAMiB,sBAAsBlB,EAAEmB,KAAK,CAAC;IAClCnB,EAAEI,MAAM,CAAC;QACPW,MAAMf,EAAEoB,IAAI,CAAC;YAAC;YAAS;SAAO;QAC9BH,UAAUhB;IACZ;IACAW;CACD;AAED,MAAMS,yBAAyBrB,EAAEM,MAAM,CAACN,EAAEO,MAAM,IAAIW;AAmCpD,mDAAmD,GACnD,OAAO,MAAMI,QAAuB;IAACP,MAAM;IAASE,UAAU,IAAM;AAAI,EAAC;AAEzE,2EAA2E,GAC3E,OAAO,MAAMM,OAAsB;IAACR,MAAM;IAAQE,UAAU,IAAM;AAAK,EAAC;AAExE;;;CAGC,GACD,OAAO,SAASO,qBAAqB,GAAGC,KAAe;IACrD,OAAO;QACLZ,aAAaY;QACbV,MAAM;QACNE,UAAU,CAAC,EAACR,KAAK,EAAC,GAChBgB,MAAMC,KAAK,CAAC,CAACC,OAASlB,KAAK,CAACkB,KAAK,KAAKC,aAAanB,KAAK,CAACkB,KAAK,KAAK;IACvE;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASE,kBAAkBC,OAGjC;IACC,MAAMC,YAAYP,wBAAyBM,QAAQjB,WAAW,IAAI,EAAE;IACpE,OAAO;QACL,GAAGkB,SAAS;QACZd,UAAU,CAACe,aAAeD,UAAUd,QAAQ,CAACe,eAAeF,QAAQb,QAAQ,CAACe;IAC/E;AACF;AAEA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,+BACdC,QAAkC;IAElC,OAAOA;AACT;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,8BACdC,MAAqB;IAErB,OAAOxB,+BAA+ByB,SAAS,CAACD,QAAQE,OAAO;AACjE;AAEA;;;;;CAKC,GACD,OAAO,SAASC,mBAAmBC,KAAc;IAC/C,OAAOnB,uBAAuBgB,SAAS,CAACG,OAAOF,OAAO;AACxD"}
|
|
@@ -18,7 +18,10 @@ import { APP_VISIBILITIES } from './types/cliConfig.js';
|
|
|
18
18
|
autoUpdates: z.optional(z.boolean()),
|
|
19
19
|
deployment: z.optional(z.object({
|
|
20
20
|
appId: z.optional(z.string()),
|
|
21
|
-
autoUpdates: z.optional(z.boolean())
|
|
21
|
+
autoUpdates: z.optional(z.boolean()),
|
|
22
|
+
studioHost: z.optional(z.never({
|
|
23
|
+
error: 'deployment.studioHost is not supported. Move studioHost to the top level of sanity.cli.ts, or pass --url <hostname> to sanity deploy.'
|
|
24
|
+
}))
|
|
22
25
|
})),
|
|
23
26
|
graphql: z.optional(z.array(z.object({
|
|
24
27
|
filterSuffix: z.optional(z.string()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/schemas.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {\n APP_VISIBILITIES,\n type CliConfig,\n type ReactCompilerConfig,\n type TypeGenConfig,\n} from './types/cliConfig.js'\nimport {type UserViteConfig} from './types/userViteConfig'\n\n/**\n * @public\n */\nexport const cliConfigSchema = z.object({\n api: z.optional(\n z.object({\n dataset: z.optional(z.string()),\n projectId: z.optional(z.string()),\n }),\n ),\n\n app: z.optional(\n z.object({\n entry: z.optional(z.string()),\n icon: z.optional(z.string()),\n id: z.optional(z.string()),\n organizationId: z.optional(z.string()),\n title: z.optional(z.string()),\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n }),\n ),\n\n autoUpdates: z.optional(z.boolean()),\n\n deployment: z.optional(\n z.object({\n appId: z.optional(z.string()),\n autoUpdates: z.optional(z.boolean()),\n }),\n ),\n\n graphql: z.optional(\n z.array(\n z.object({\n filterSuffix: z.optional(z.string()),\n generation: z.optional(z.enum(['gen1', 'gen2', 'gen3'])),\n id: z.optional(z.string()),\n nonNullDocumentFields: z.optional(z.boolean()),\n playground: z.optional(z.boolean()),\n source: z.optional(z.string()),\n tag: z.optional(z.string()),\n workspace: z.optional(z.string()),\n }),\n ),\n ),\n\n mediaLibrary: z.optional(\n z.object({\n aspectsPath: z.optional(z.string()),\n }),\n ),\n\n project: z.optional(\n z.object({\n basePath: z.optional(z.string()),\n }),\n ),\n\n reactCompiler: z.optional(z.custom<boolean | ReactCompilerConfig>()),\n\n reactStrictMode: z.optional(z.boolean()),\n\n schemaExtraction: z.optional(\n z.object({\n enabled: z.optional(z.boolean()),\n enforceRequiredFields: z.optional(z.boolean()),\n path: z.optional(z.string()),\n watchPatterns: z.optional(z.array(z.string())),\n workspace: z.optional(z.string()),\n }),\n ),\n\n server: z.optional(\n z.object({\n hostname: z.optional(z.string()),\n port: z.optional(z.number()),\n }),\n ),\n\n studioHost: z.optional(z.string()),\n\n unstable_bundledDev: z.optional(z.boolean()),\n\n vite: z.optional(z.custom<UserViteConfig>()),\n\n typegen: z.optional(z.custom<Partial<TypeGenConfig> & {enabled?: boolean}>()),\n}) satisfies z.core.$ZodType<CliConfig>\n"],"names":["z","APP_VISIBILITIES","cliConfigSchema","object","api","optional","dataset","string","projectId","app","entry","icon","id","organizationId","title","visibility","enum","autoUpdates","boolean","deployment","appId","graphql","array","filterSuffix","generation","nonNullDocumentFields","playground","source","tag","workspace","mediaLibrary","aspectsPath","project","basePath","reactCompiler","custom","reactStrictMode","schemaExtraction","enabled","enforceRequiredFields","path","watchPatterns","server","hostname","port","number","
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/schemas.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\nimport {\n APP_VISIBILITIES,\n type CliConfig,\n type ReactCompilerConfig,\n type TypeGenConfig,\n} from './types/cliConfig.js'\nimport {type UserViteConfig} from './types/userViteConfig'\n\n/**\n * @public\n */\nexport const cliConfigSchema = z.object({\n api: z.optional(\n z.object({\n dataset: z.optional(z.string()),\n projectId: z.optional(z.string()),\n }),\n ),\n\n app: z.optional(\n z.object({\n entry: z.optional(z.string()),\n icon: z.optional(z.string()),\n id: z.optional(z.string()),\n organizationId: z.optional(z.string()),\n title: z.optional(z.string()),\n visibility: z.optional(z.enum(APP_VISIBILITIES)),\n }),\n ),\n\n autoUpdates: z.optional(z.boolean()),\n\n deployment: z.optional(\n z.object({\n appId: z.optional(z.string()),\n autoUpdates: z.optional(z.boolean()),\n studioHost: z.optional(\n z.never({\n error:\n 'deployment.studioHost is not supported. Move studioHost to the top level of sanity.cli.ts, or pass --url <hostname> to sanity deploy.',\n }),\n ),\n }),\n ),\n\n graphql: z.optional(\n z.array(\n z.object({\n filterSuffix: z.optional(z.string()),\n generation: z.optional(z.enum(['gen1', 'gen2', 'gen3'])),\n id: z.optional(z.string()),\n nonNullDocumentFields: z.optional(z.boolean()),\n playground: z.optional(z.boolean()),\n source: z.optional(z.string()),\n tag: z.optional(z.string()),\n workspace: z.optional(z.string()),\n }),\n ),\n ),\n\n mediaLibrary: z.optional(\n z.object({\n aspectsPath: z.optional(z.string()),\n }),\n ),\n\n project: z.optional(\n z.object({\n basePath: z.optional(z.string()),\n }),\n ),\n\n reactCompiler: z.optional(z.custom<boolean | ReactCompilerConfig>()),\n\n reactStrictMode: z.optional(z.boolean()),\n\n schemaExtraction: z.optional(\n z.object({\n enabled: z.optional(z.boolean()),\n enforceRequiredFields: z.optional(z.boolean()),\n path: z.optional(z.string()),\n watchPatterns: z.optional(z.array(z.string())),\n workspace: z.optional(z.string()),\n }),\n ),\n\n server: z.optional(\n z.object({\n hostname: z.optional(z.string()),\n port: z.optional(z.number()),\n }),\n ),\n\n studioHost: z.optional(z.string()),\n\n unstable_bundledDev: z.optional(z.boolean()),\n\n vite: z.optional(z.custom<UserViteConfig>()),\n\n typegen: z.optional(z.custom<Partial<TypeGenConfig> & {enabled?: boolean}>()),\n}) satisfies z.core.$ZodType<CliConfig>\n"],"names":["z","APP_VISIBILITIES","cliConfigSchema","object","api","optional","dataset","string","projectId","app","entry","icon","id","organizationId","title","visibility","enum","autoUpdates","boolean","deployment","appId","studioHost","never","error","graphql","array","filterSuffix","generation","nonNullDocumentFields","playground","source","tag","workspace","mediaLibrary","aspectsPath","project","basePath","reactCompiler","custom","reactStrictMode","schemaExtraction","enabled","enforceRequiredFields","path","watchPatterns","server","hostname","port","number","unstable_bundledDev","vite","typegen"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B,SACEC,gBAAgB,QAIX,uBAAsB;AAG7B;;CAEC,GACD,OAAO,MAAMC,kBAAkBF,EAAEG,MAAM,CAAC;IACtCC,KAAKJ,EAAEK,QAAQ,CACbL,EAAEG,MAAM,CAAC;QACPG,SAASN,EAAEK,QAAQ,CAACL,EAAEO,MAAM;QAC5BC,WAAWR,EAAEK,QAAQ,CAACL,EAAEO,MAAM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AAM,CAAC;QACP+B,aAAalC,EAAEK,QAAQ,CAACL,EAAEO,MAAM;IAClC;IAGF4B,SAASnC,EAAEK,QAAQ,CACjBL,EAAEG,MAAM,CAAC;QACPiC,UAAUpC,EAAEK,QAAQ,CAACL,EAAEO,MAAM;IAC/B;IAGF8B,eAAerC,EAAEK,QAAQ,CAACL,EAAEsC,MAAM;IAElCC,iBAAiBvC,EAAEK,QAAQ,CAACL,EAAEkB,OAAO;IAErCsB,kBAAkBxC,EAAEK,QAAQ,CAC1BL,EAAEG,MAAM,CAAC;QACPsC,SAASzC,EAAEK,QAAQ,CAACL,EAAEkB,OAAO;QAC7BwB,uBAAuB1C,EAAEK,QAAQ,CAACL,EAAEkB,OAAO;QAC3CyB,MAAM3C,EAAEK,QAAQ,CAACL,EAAEO,MAAM;QACzBqC,eAAe5C,EAAEK,QAAQ,CAACL,EAAEyB,KAAK,CAACzB,EAAEO,MAAM;QAC1CyB,WAAWhC,EAAEK,QAAQ,CAACL,EAAEO,MAAM;IAChC;IAGFsC,QAAQ7C,EAAEK,QAAQ,CAChBL,EAAEG,MAAM,CAAC;QACP2C,UAAU9C,EAAEK,QAAQ,CAACL,EAAEO,MAAM;QAC7BwC,MAAM/C,EAAEK,QAAQ,CAACL,EAAEgD,MAAM;IAC3B;IAGF3B,YAAYrB,EAAEK,QAAQ,CAACL,EAAEO,MAAM;IAE/B0C,qBAAqBjD,EAAEK,QAAQ,CAACL,EAAEkB,OAAO;IAEzCgC,MAAMlD,EAAEK,QAAQ,CAACL,EAAEsC,MAAM;IAEzBa,SAASnD,EAAEK,QAAQ,CAACL,EAAEsC,MAAM;AAC9B,GAAuC"}
|
|
@@ -2,9 +2,6 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
4
|
import { ESModulesEvaluator, ssrModuleExportsKey } from 'vite/module-runner';
|
|
5
|
-
function isCommonJsCode(code) {
|
|
6
|
-
return /\bmodule\.exports\b/.test(code) || /\bexports\.[a-zA-Z_$]/.test(code) || /(?:^|[;\n])\s*exports\s=/.test(code) || /(?:^|\n|\s)require\s*\(/.test(code);
|
|
7
|
-
}
|
|
8
5
|
function isPrimitive(value) {
|
|
9
6
|
return !value || typeof value !== 'object' && typeof value !== 'function';
|
|
10
7
|
}
|
|
@@ -41,9 +38,6 @@ function exportAll(exports, sourceModule) {
|
|
|
41
38
|
return this.esmEvaluator.runExternalModule(filepath);
|
|
42
39
|
}
|
|
43
40
|
runInlinedModule(context, code, module) {
|
|
44
|
-
if (!isCommonJsCode(code)) {
|
|
45
|
-
return this.esmEvaluator.runInlinedModule(context, code, module);
|
|
46
|
-
}
|
|
47
41
|
return this.runCommonJsModule(context, code, module);
|
|
48
42
|
}
|
|
49
43
|
async runCommonJsModule(context, code, module) {
|
|
@@ -61,7 +55,9 @@ function exportAll(exports, sourceModule) {
|
|
|
61
55
|
},
|
|
62
56
|
getPrototypeOf: ()=>Object.prototype,
|
|
63
57
|
set: (_, property, value)=>{
|
|
64
|
-
|
|
58
|
+
// Keep the module default when CommonJS aliases it back to `module.exports`.
|
|
59
|
+
if (property === 'default' && cjsExports !== value) {
|
|
60
|
+
exportAll(exports, value);
|
|
65
61
|
exports.default = value;
|
|
66
62
|
return true;
|
|
67
63
|
}
|
|
@@ -72,7 +68,7 @@ function exportAll(exports, sourceModule) {
|
|
|
72
68
|
defineExport(exports, String(property), ()=>{});
|
|
73
69
|
return true;
|
|
74
70
|
}
|
|
75
|
-
if (!isPrimitive(exports.default)
|
|
71
|
+
if (!isPrimitive(exports.default)) {
|
|
76
72
|
;
|
|
77
73
|
exports.default[String(property)] = value;
|
|
78
74
|
}
|
|
@@ -104,11 +100,9 @@ function exportAll(exports, sourceModule) {
|
|
|
104
100
|
if (normalizedCode[0] === '#') {
|
|
105
101
|
normalizedCode = normalizedCode.replace(/^#!.*/, (line)=>' '.repeat(line.length));
|
|
106
102
|
}
|
|
107
|
-
// Use AsyncFunction (same as ESModulesEvaluator) so the shared `startOffset`
|
|
108
|
-
// ModuleRunner applies to inlined sourcemaps matches this wrapper's padding.
|
|
109
103
|
const AsyncFunction = (async function() {}).constructor;
|
|
110
104
|
const parameterNames = Object.keys(cjsContext);
|
|
111
|
-
const runner = new AsyncFunction(...parameterNames, `"use strict"
|
|
105
|
+
const runner = new AsyncFunction(...parameterNames, `"use strict";{\n${normalizedCode}\n}`);
|
|
112
106
|
await runner(...parameterNames.map((name)=>cjsContext[name]));
|
|
113
107
|
}
|
|
114
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loaders/studio/studioModuleEvaluator.ts"],"sourcesContent":["import {createRequire} from 'node:module'\nimport {dirname} from 'node:path'\nimport {fileURLToPath, pathToFileURL} from 'node:url'\n\nimport {\n ESModulesEvaluator,\n type EvaluatedModuleNode,\n type ModuleEvaluator,\n type ModuleRunnerContext,\n ssrModuleExportsKey,\n} from 'vite/module-runner'\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/studioModuleEvaluator.ts"],"sourcesContent":["import {createRequire} from 'node:module'\nimport {dirname} from 'node:path'\nimport {fileURLToPath, pathToFileURL} from 'node:url'\n\nimport {\n ESModulesEvaluator,\n type EvaluatedModuleNode,\n type ModuleEvaluator,\n type ModuleRunnerContext,\n ssrModuleExportsKey,\n} from 'vite/module-runner'\n\nfunction isPrimitive(value: unknown): boolean {\n return !value || (typeof value !== 'object' && typeof value !== 'function')\n}\n\nfunction defineExport(exports: Record<string, unknown>, key: string, getter: () => unknown) {\n Object.defineProperty(exports, key, {\n configurable: true,\n enumerable: true,\n get: getter,\n })\n}\n\nfunction exportAll(exports: Record<string, unknown>, sourceModule: unknown) {\n if (exports === sourceModule) return\n if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) {\n return\n }\n\n for (const key in sourceModule as Record<string, unknown>) {\n if (key !== 'default' && !(key in exports)) {\n try {\n defineExport(exports, key, () => (sourceModule as Record<string, unknown>)[key])\n } catch {\n // ignore non-configurable exports\n }\n }\n }\n}\n\n/**\n * Module evaluator that can execute raw CommonJS modules in addition to\n * Vite's SSR-transformed ESM. Matches vite-node's CJS execution behavior,\n * which ModuleRunner's default ESModulesEvaluator does not support.\n */\nexport class StudioModuleEvaluator implements ModuleEvaluator {\n private readonly esmEvaluator = new ESModulesEvaluator()\n readonly startOffset = this.esmEvaluator.startOffset\n\n runExternalModule(filepath: string): Promise<unknown> {\n return this.esmEvaluator.runExternalModule(filepath)\n }\n\n runInlinedModule(\n context: ModuleRunnerContext,\n code: string,\n module: Readonly<EvaluatedModuleNode>,\n ): Promise<void> {\n return this.runCommonJsModule(context, code, module)\n }\n\n private async runCommonJsModule(\n context: ModuleRunnerContext,\n code: string,\n module: Readonly<EvaluatedModuleNode>,\n ): Promise<void> {\n const modulePath = module.file || module.id\n const href = pathToFileURL(modulePath).href\n const __filename = fileURLToPath(href)\n const __dirname = dirname(__filename)\n\n const exports = context[ssrModuleExportsKey]\n const moduleNotDefined = Symbol('not defined')\n let moduleExports: unknown = moduleNotDefined\n\n const cjsExports = new Proxy(exports, {\n get: (target, property, receiver) => {\n if (Reflect.has(target, property)) return Reflect.get(target, property, receiver)\n return Reflect.get(Object.prototype, property, receiver)\n },\n getPrototypeOf: () => Object.prototype,\n set: (_, property, value) => {\n // Keep the module default when CommonJS aliases it back to `module.exports`.\n if (property === 'default' && cjsExports !== value) {\n exportAll(exports, value)\n exports.default = value\n return true\n }\n if (!Reflect.has(exports, 'default')) {\n exports.default = {}\n }\n if (moduleExports !== moduleNotDefined && isPrimitive(moduleExports)) {\n defineExport(exports, String(property), () => {})\n return true\n }\n if (!isPrimitive(exports.default)) {\n ;(exports.default as Record<string, unknown>)[String(property)] = value\n }\n if (property !== 'default') {\n defineExport(exports, String(property), () => value)\n }\n return true\n },\n })\n\n const moduleProxy = {\n get exports() {\n return cjsExports\n },\n set exports(value: unknown) {\n exportAll(exports, value)\n exports.default = value\n moduleExports = value\n },\n }\n\n const cjsContext: Record<string, unknown> = {\n ...context,\n __dirname,\n __filename,\n exports: cjsExports,\n module: moduleProxy,\n require: createRequire(href),\n }\n\n let normalizedCode = code\n if (normalizedCode[0] === '#') {\n normalizedCode = normalizedCode.replace(/^#!.*/, (line) => ' '.repeat(line.length))\n }\n\n const AsyncFunction = async function () {}.constructor as new (\n ...args: string[]\n ) => (...args: unknown[]) => Promise<unknown>\n const parameterNames = Object.keys(cjsContext)\n const runner = new AsyncFunction(...parameterNames, `\"use strict\";{\\n${normalizedCode}\\n}`)\n await runner(...parameterNames.map((name) => cjsContext[name]))\n }\n}\n"],"names":["createRequire","dirname","fileURLToPath","pathToFileURL","ESModulesEvaluator","ssrModuleExportsKey","isPrimitive","value","defineExport","exports","key","getter","Object","defineProperty","configurable","enumerable","get","exportAll","sourceModule","Array","isArray","Promise","StudioModuleEvaluator","esmEvaluator","startOffset","runExternalModule","filepath","runInlinedModule","context","code","module","runCommonJsModule","modulePath","file","id","href","__filename","__dirname","moduleNotDefined","Symbol","moduleExports","cjsExports","Proxy","target","property","receiver","Reflect","has","prototype","getPrototypeOf","set","_","default","String","moduleProxy","cjsContext","require","normalizedCode","replace","line","repeat","length","AsyncFunction","parameterNames","keys","runner","map","name"],"mappings":"AAAA,SAAQA,aAAa,QAAO,cAAa;AACzC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,EAAEC,aAAa,QAAO,WAAU;AAErD,SACEC,kBAAkB,EAIlBC,mBAAmB,QACd,qBAAoB;AAE3B,SAASC,YAAYC,KAAc;IACjC,OAAO,CAACA,SAAU,OAAOA,UAAU,YAAY,OAAOA,UAAU;AAClE;AAEA,SAASC,aAAaC,OAAgC,EAAEC,GAAW,EAAEC,MAAqB;IACxFC,OAAOC,cAAc,CAACJ,SAASC,KAAK;QAClCI,cAAc;QACdC,YAAY;QACZC,KAAKL;IACP;AACF;AAEA,SAASM,UAAUR,OAAgC,EAAES,YAAqB;IACxE,IA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AG,CAAC;QAC1F,MAAMQ,UAAUF,eAAeG,GAAG,CAAC,CAACC,OAASZ,UAAU,CAACY,KAAK;IAC/D;AACF"}
|
|
@@ -24,6 +24,7 @@ declare const cliConfigSchema: z.ZodMiniObject<{
|
|
|
24
24
|
deployment: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
25
25
|
appId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
26
26
|
autoUpdates: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
27
|
+
studioHost: z.ZodMiniOptional<z.ZodMiniNever>;
|
|
27
28
|
}, z.core.$strip>>;
|
|
28
29
|
graphql: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
29
30
|
filterSuffix: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
@@ -103,4 +104,4 @@ type CoreAppManifest = z.infer<typeof coreAppManifestSchema>;
|
|
|
103
104
|
declare const studioManifestSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
104
105
|
type StudioManifest = z.infer<typeof studioManifestSchema>;
|
|
105
106
|
export { cliConfigSchema as a, studioManifestSchema as i, StudioManifest as n, coreAppManifestSchema as r, CoreAppManifest as t };
|
|
106
|
-
//# sourceMappingURL=schemas-
|
|
107
|
+
//# sourceMappingURL=schemas-DDpPtgia.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"source": "./src/_exports/browser.ts",
|
|
42
42
|
"default": "./dist/_exports/browser.js"
|
|
43
43
|
},
|
|
44
|
+
"./commandPolicy": {
|
|
45
|
+
"source": "./src/_exports/commandPolicy.ts",
|
|
46
|
+
"default": "./dist/_exports/commandPolicy.js"
|
|
47
|
+
},
|
|
44
48
|
"./config": {
|
|
45
49
|
"source": "./src/_exports/config.ts",
|
|
46
50
|
"default": "./dist/_exports/config.js"
|
|
@@ -117,20 +121,20 @@
|
|
|
117
121
|
"dependencies": {
|
|
118
122
|
"@inquirer/prompts": "^8.5.2",
|
|
119
123
|
"@oclif/core": "^4.11.14",
|
|
120
|
-
"@sanity/client": "^8.
|
|
124
|
+
"@sanity/client": "^8.6.2",
|
|
121
125
|
"boxen": "^8.0.1",
|
|
122
126
|
"empathic": "^2.0.1",
|
|
123
|
-
"get-it": "^9.5.
|
|
127
|
+
"get-it": "^9.5.4",
|
|
124
128
|
"get-tsconfig": "^4.14.3",
|
|
125
129
|
"import-meta-resolve": "^4.2.0",
|
|
126
130
|
"jiti": "^2.7.0",
|
|
127
131
|
"jsdom": "^29.1.1",
|
|
128
132
|
"json-lexer": "^1.2.0",
|
|
129
133
|
"log-symbols": "^7.0.1",
|
|
130
|
-
"obug": "^
|
|
134
|
+
"obug": "^3.0.0",
|
|
131
135
|
"ora": "^9.0.0",
|
|
132
136
|
"rxjs": "^7.8.2",
|
|
133
|
-
"vite": "^8.
|
|
137
|
+
"vite": "^8.3.0",
|
|
134
138
|
"wrap-ansi": "^9.0.2",
|
|
135
139
|
"zod": "^4.5.2"
|
|
136
140
|
},
|
|
@@ -149,7 +153,7 @@
|
|
|
149
153
|
"eslint": "^10.7.0",
|
|
150
154
|
"oxc-transform-react": "^0.147.0",
|
|
151
155
|
"publint": "^0.3.21",
|
|
152
|
-
"sanity": "^6.
|
|
156
|
+
"sanity": "^6.15.0",
|
|
153
157
|
"typescript": "^6.0.3",
|
|
154
158
|
"vitest": "^4.1.11"
|
|
155
159
|
},
|