@sanity/runtime-cli 4.0.0 → 4.1.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.
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/4.0.0 linux-x64 node-v22.14.0
23
+ @sanity/runtime-cli/4.1.0 linux-x64 node-v22.14.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -64,7 +64,7 @@ EXAMPLES
64
64
  $ sanity-run blueprints add function
65
65
  ```
66
66
 
67
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/add.ts)_
67
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/add.ts)_
68
68
 
69
69
  ## `sanity-run blueprints config`
70
70
 
@@ -86,7 +86,7 @@ EXAMPLES
86
86
  $ sanity-run blueprints config --edit
87
87
  ```
88
88
 
89
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/config.ts)_
89
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/config.ts)_
90
90
 
91
91
  ## `sanity-run blueprints deploy`
92
92
 
@@ -106,7 +106,7 @@ EXAMPLES
106
106
  $ sanity-run blueprints deploy
107
107
  ```
108
108
 
109
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/deploy.ts)_
109
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/deploy.ts)_
110
110
 
111
111
  ## `sanity-run blueprints destroy`
112
112
 
@@ -129,7 +129,7 @@ EXAMPLES
129
129
  $ sanity-run blueprints destroy --id ST-a1b2c3
130
130
  ```
131
131
 
132
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/destroy.ts)_
132
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/destroy.ts)_
133
133
 
134
134
  ## `sanity-run blueprints info`
135
135
 
@@ -151,7 +151,7 @@ EXAMPLES
151
151
  $ sanity-run blueprints info --id ST-a1b2c3
152
152
  ```
153
153
 
154
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/info.ts)_
154
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/info.ts)_
155
155
 
156
156
  ## `sanity-run blueprints init`
157
157
 
@@ -168,7 +168,7 @@ EXAMPLES
168
168
  $ sanity-run blueprints init
169
169
  ```
170
170
 
171
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/init.ts)_
171
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/init.ts)_
172
172
 
173
173
  ## `sanity-run blueprints logs`
174
174
 
@@ -190,7 +190,7 @@ EXAMPLES
190
190
  $ sanity-run blueprints logs --watch
191
191
  ```
192
192
 
193
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/logs.ts)_
193
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/logs.ts)_
194
194
 
195
195
  ## `sanity-run blueprints plan`
196
196
 
@@ -207,7 +207,7 @@ EXAMPLES
207
207
  $ sanity-run blueprints plan
208
208
  ```
209
209
 
210
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/plan.ts)_
210
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/plan.ts)_
211
211
 
212
212
  ## `sanity-run blueprints stacks`
213
213
 
@@ -229,7 +229,7 @@ EXAMPLES
229
229
  $ sanity-run blueprints stacks --projectId a1b2c3
230
230
  ```
231
231
 
232
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/blueprints/stacks.ts)_
232
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/blueprints/stacks.ts)_
233
233
 
234
234
  ## `sanity-run functions dev`
235
235
 
@@ -249,7 +249,7 @@ EXAMPLES
249
249
  $ sanity-run functions dev --port 8974
250
250
  ```
251
251
 
252
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/functions/dev.ts)_
252
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/functions/dev.ts)_
253
253
 
254
254
  ## `sanity-run functions env add NAME KEY VALUE`
255
255
 
@@ -271,7 +271,7 @@ EXAMPLES
271
271
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
272
272
  ```
273
273
 
274
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/functions/env/add.ts)_
274
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/functions/env/add.ts)_
275
275
 
276
276
  ## `sanity-run functions env remove NAME KEY`
277
277
 
@@ -292,7 +292,7 @@ EXAMPLES
292
292
  $ sanity-run functions env remove MyFunction API_URL
293
293
  ```
294
294
 
295
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/functions/env/remove.ts)_
295
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/functions/env/remove.ts)_
296
296
 
297
297
  ## `sanity-run functions invoke NAME`
298
298
 
@@ -318,7 +318,7 @@ EXAMPLES
318
318
  $ sanity-run functions invoke <name> --file 'payload.json'
319
319
  ```
320
320
 
321
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/functions/invoke.ts)_
321
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/functions/invoke.ts)_
322
322
 
323
323
  ## `sanity-run functions logs NAME`
324
324
 
@@ -350,7 +350,7 @@ EXAMPLES
350
350
  $ sanity-run functions logs <name> --delete
351
351
  ```
352
352
 
353
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/functions/logs.ts)_
353
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/functions/logs.ts)_
354
354
 
355
355
  ## `sanity-run functions test NAME`
356
356
 
@@ -383,7 +383,7 @@ EXAMPLES
383
383
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
384
384
  ```
385
385
 
386
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.0.0/src/commands/functions/test.ts)_
386
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.1.0/src/commands/functions/test.ts)_
387
387
 
388
388
  ## `sanity-run help [COMMAND]`
389
389
 
@@ -51,9 +51,11 @@ export default class Test extends Command {
51
51
  file: flags.file,
52
52
  timeout: flags.timeout,
53
53
  }, {
54
- apiVersion: flags.api,
55
- dataset: flags.dataset,
56
- projectId: flags.project,
54
+ clientOptions: {
55
+ apiVersion: flags.api,
56
+ dataset: flags.dataset,
57
+ projectId: flags.project,
58
+ },
57
59
  });
58
60
  if (!error) {
59
61
  this.log('Logs:');
@@ -21,9 +21,11 @@ class PayloadPanel extends ApiBaseElement {
21
21
  const payloadText = this.api.store.payload.state.doc.text.join('') || '{}'
22
22
  const event = JSON.parse(payloadText)
23
23
  const context = {
24
- apiVersion: this.apiVersion.value,
25
- dataset: this.api.store.selectedDataset,
26
- projectId: this.api.store.selectedProject,
24
+ clientOptions: {
25
+ apiVersion: this.apiVersion.value,
26
+ dataset: this.api.store.selectedDataset,
27
+ projectId: this.api.store.selectedProject,
28
+ },
27
29
  }
28
30
  this.api.invoke({context, event})
29
31
  }
@@ -13,30 +13,6 @@ export function getFunctionSource(src) {
13
13
  return src
14
14
  }
15
15
 
16
- async function enhanceContext(context = {}) {
17
- const {apiHost, apiVersion, dataset, projectId, token} = context
18
- const enhancedContext = {...context}
19
-
20
- try {
21
- if (apiHost && apiVersion && dataset && projectId && token) {
22
- // @ts-ignore
23
- const {createClient} = await import('@sanity/client')
24
- const client = createClient({
25
- projectId,
26
- dataset,
27
- useCdn: true,
28
- apiHost,
29
- apiVersion,
30
- token,
31
- })
32
- enhancedContext.client = client
33
- }
34
- } catch {
35
- // ignore as user hasn't provided the @sanity/client
36
- }
37
- return enhancedContext
38
- }
39
-
40
16
  // Start when payload data arrives from parent process
41
17
  process.on('message', async (data) => {
42
18
  let jsonData = null
@@ -48,7 +24,6 @@ process.on('message', async (data) => {
48
24
  }
49
25
  const {srcPath, payload} = jsonData
50
26
  const {context, ...event} = payload
51
- const enhancedContext = await enhanceContext(context)
52
27
  let logs = ''
53
28
  let json = null
54
29
 
@@ -67,7 +42,7 @@ process.on('message', async (data) => {
67
42
  }
68
43
 
69
44
  if (handler && typeof handler === 'function') {
70
- json = await handler({context: enhancedContext, event})
45
+ json = await handler({context, event})
71
46
  }
72
47
 
73
48
  // revert changes to stdout
@@ -1,2 +1,3 @@
1
1
  import type { InvocationResponse, InvokeContextOptions } from './types.js';
2
+ export declare function sanitizeLogs(logs: string): string;
2
3
  export default function invoke(srcPath: string, data: null | object, context: InvokeContextOptions, timeout?: number): Promise<InvocationResponse>;
@@ -5,6 +5,9 @@ import config from '../config.js';
5
5
  function getChildProcessWrapperPath() {
6
6
  return new URL('./child-process-wrapper.js', import.meta.url).pathname;
7
7
  }
8
+ export function sanitizeLogs(logs) {
9
+ return logs.replace(/[a-zA-Z0-9]{75}/g, '*'.repeat(10));
10
+ }
8
11
  export default async function invoke(srcPath, data, context, timeout = 5) {
9
12
  return new Promise((resolve, reject) => {
10
13
  let child;
@@ -18,7 +21,7 @@ export default async function invoke(srcPath, data, context, timeout = 5) {
18
21
  child.on('message', (data) => {
19
22
  const { json, logs } = JSON.parse(data.toString());
20
23
  shutdown();
21
- resolve({ json, logs, error: '' });
24
+ resolve({ json, logs: sanitizeLogs(logs), error: '' });
22
25
  });
23
26
  child.on('error', (error) => {
24
27
  reject(new Error(`encountered error ${error.message}`));
@@ -40,9 +43,12 @@ export default async function invoke(srcPath, data, context, timeout = 5) {
40
43
  const payload = {
41
44
  ...data,
42
45
  context: {
43
- apiHost: config.apiUrl,
44
- token: config.token,
45
46
  ...context,
47
+ clientOptions: {
48
+ ...context.clientOptions,
49
+ apiHost: config.apiUrl,
50
+ token: config.token,
51
+ },
46
52
  },
47
53
  };
48
54
  child.send(JSON.stringify({ srcPath, payload }, null, 2));
@@ -104,9 +104,11 @@ export interface InvokePayloadOptions {
104
104
  }
105
105
  /** @internal */
106
106
  export interface InvokeContextOptions {
107
- apiVersion?: string;
108
- dataset?: string;
109
- projectId?: string;
107
+ clientOptions: {
108
+ apiVersion?: string;
109
+ dataset?: string;
110
+ projectId?: string;
111
+ };
110
112
  }
111
113
  /** @internal */
112
114
  export interface InvocationResponse {
@@ -608,5 +608,5 @@
608
608
  ]
609
609
  }
610
610
  },
611
- "version": "4.0.0"
611
+ "version": "4.1.0"
612
612
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "Sanity's Runtime CLI for Blueprints and Functions",
4
- "version": "4.0.0",
4
+ "version": "4.1.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",