@start9labs/start-sdk 0.3.6-alpha.21 → 0.3.6-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/base/lib/Effects.d.ts +2 -2
  2. package/base/lib/actions/input/builder/inputSpec.d.ts +4 -3
  3. package/base/lib/actions/input/builder/inputSpec.js.map +1 -1
  4. package/base/lib/actions/input/builder/value.d.ts +4 -7
  5. package/base/lib/actions/input/builder/value.js.map +1 -1
  6. package/base/lib/actions/input/builder/variants.d.ts +1 -15
  7. package/base/lib/actions/input/builder/variants.js.map +1 -1
  8. package/base/lib/actions/setupActions.d.ts +3 -1
  9. package/base/lib/osBindings/BindInfo.d.ts +2 -2
  10. package/base/lib/osBindings/GitHash.d.ts +1 -0
  11. package/base/lib/osBindings/GitHash.js +4 -0
  12. package/base/lib/osBindings/GitHash.js.map +1 -0
  13. package/base/lib/osBindings/IpInfo.d.ts +1 -6
  14. package/base/lib/osBindings/Manifest.d.ts +2 -1
  15. package/base/lib/osBindings/NetInfo.d.ts +5 -0
  16. package/base/lib/osBindings/NetInfo.js +4 -0
  17. package/base/lib/osBindings/NetInfo.js.map +1 -0
  18. package/base/lib/osBindings/NetworkInterfaceInfo.d.ts +5 -0
  19. package/base/lib/osBindings/NetworkInterfaceInfo.js +3 -0
  20. package/base/lib/osBindings/NetworkInterfaceInfo.js.map +1 -0
  21. package/base/lib/osBindings/PackageVersionInfo.d.ts +2 -1
  22. package/base/lib/osBindings/ServerInfo.d.ts +5 -3
  23. package/base/lib/osBindings/index.d.ts +4 -1
  24. package/base/lib/types.d.ts +1 -1
  25. package/package/lib/StartSdk.d.ts +151 -91
  26. package/package/lib/StartSdk.js +136 -81
  27. package/package/lib/StartSdk.js.map +1 -1
  28. package/package/lib/backup/Backups.d.ts +0 -22
  29. package/package/lib/backup/Backups.js +0 -22
  30. package/package/lib/backup/Backups.js.map +1 -1
  31. package/package/lib/health/checkFns/checkPortListening.js +0 -1
  32. package/package/lib/health/checkFns/checkPortListening.js.map +1 -1
  33. package/package/lib/mainFn/CommandController.js.map +1 -1
  34. package/package/lib/manifest/setupManifest.d.ts +1 -2
  35. package/package/lib/manifest/setupManifest.js +0 -13
  36. package/package/lib/manifest/setupManifest.js.map +1 -1
  37. package/package/lib/store/setupExposeStore.js.map +1 -1
  38. package/package/lib/test/output.sdk.d.ts +1 -1
  39. package/package/lib/trigger/defaultTrigger.js.map +1 -1
  40. package/package/lib/util/SubContainer.js +0 -1
  41. package/package/lib/util/SubContainer.js.map +1 -1
  42. package/package/lib/util/fileHelper.d.ts +16 -9
  43. package/package/lib/util/fileHelper.js +16 -9
  44. package/package/lib/util/fileHelper.js.map +1 -1
  45. package/package.json +2 -2
@@ -13,7 +13,7 @@ import { checkPortListening } from "./health/checkFns/checkPortListening";
13
13
  import { List } from "../../base/lib/actions/input/builder/list";
14
14
  import { Install, InstallFn } from "./inits/setupInstall";
15
15
  import { SetupBackupsParams } from "./backup/setupBackups";
16
- import { Uninstall, UninstallFn } from "./inits/setupUninstall";
16
+ import { UninstallFn } from "./inits/setupUninstall";
17
17
  import { changeOnFirstSuccess, cooldownTrigger } from "./trigger";
18
18
  import { UpdateServiceInterfaces } from "../../base/lib/interfaces/setupInterfaces";
19
19
  import { MultiHost, Scheme } from "../../base/lib/interfaces/Host";
@@ -84,69 +84,112 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
84
84
  stderr: string | Buffer;
85
85
  }>;
86
86
  /**
87
- * TODO: rewrite this
88
- * @description Use this function to create a static Action, including optional form input.
87
+ * @description Use this class to create an Action. By convention, each Action should receive its own file.
89
88
  *
90
- * By convention, each Action should receive its own file.
91
- *
92
- * @param id
93
- * @param metaData
94
- * @param fn
95
- * @returns
96
- * @example
97
- * In this example, we create an Action that prints a name to the console. We present a user
98
- * with a form for optionally entering a temp name. If no temp name is provided, we use the name
99
- * from the underlying `inputSpec.yaml` file. If no name is there, we use "Unknown". Then, we return
100
- * a message to the user informing them what happened.
101
- *
102
- * ```
103
- import { sdk } from '../sdk'
104
- const { InputSpec, Value } = sdk
105
- import { yamlFile } from '../file-models/inputSpec.yml'
106
-
107
- const input = InputSpec.of({
108
- nameToPrint: Value.text({
109
- name: 'Temp Name',
110
- description: 'If no name is provided, the name from inputSpec will be used',
111
- required: false,
112
- }),
113
- })
114
-
115
- export const nameToLog = sdk.createAction(
116
- // id
117
- 'nameToLogs',
118
-
119
- // metadata
120
- {
121
- name: 'Name to Logs',
122
- description: 'Prints "Hello [Name]" to the service logs.',
123
- warning: null,
124
- disabled: false,
125
- input,
126
- allowedStatuses: 'onlyRunning',
127
- group: null,
128
- },
129
-
130
- // the execution function
131
- async ({ effects, input }) => {
132
- const name =
133
- input.nameToPrint || (await yamlFile.read(effects))?.name || 'Unknown'
134
-
135
- console.info(`Hello ${name}`)
136
-
137
- return {
138
- version: '0',
139
- message: `"Hello ${name}" has been written to the service logs. Open your logs to view it.`,
140
- value: name,
141
- copyable: true,
142
- qr: false,
143
- }
144
- },
145
- )
146
- * ```
147
89
  */
148
90
  Action: {
91
+ /**
92
+ * @description Use this function to create an action that accepts form input
93
+ * @param id - a unique ID for this action
94
+ * @param metadata - information describing the action and its availability
95
+ * @param inputSpec - define the form input using the InputSpec and Value classes
96
+ * @param prefillFn - optionally fetch data from the file system to pre-fill the input form. Must returns a deep partial of the input spec
97
+ * @param executionFn - execute the action. Optionally return data for the user to view. Must be in the structure of an ActionResult, version "1"
98
+ * @example
99
+ * In this example, we create an action for a user to provide their name.
100
+ * We prefill the input form with their existing name from the service's yaml file.
101
+ * The new name is saved to the yaml file, and we return nothing to the user, which
102
+ * means they will receive a generic success message.
103
+ *
104
+ * ```
105
+ import { sdk } from '../sdk'
106
+ import { yamlFile } from '../file-models/config.yml'
107
+
108
+ const { InputSpec, Value } = sdk
109
+
110
+ export const inputSpec = InputSpec.of({
111
+ name: Value.text({
112
+ name: 'Name',
113
+ description:
114
+ 'When you launch the Hello World UI, it will display "Hello [Name]"',
115
+ required: true,
116
+ default: 'World',
117
+ }),
118
+ })
119
+
120
+ export const setName = sdk.Action.withInput(
121
+ // id
122
+ 'set-name',
123
+
124
+ // metadata
125
+ async ({ effects }) => ({
126
+ name: 'Set Name',
127
+ description: 'Set your name so Hello World can say hello to you',
128
+ warning: null,
129
+ allowedStatuses: 'any',
130
+ group: null,
131
+ visibility: 'enabled',
132
+ }),
133
+
134
+ // form input specification
135
+ inputSpec,
136
+
137
+ // optionally pre-fill the input form
138
+ async ({ effects }) => {
139
+ const name = await yamlFile.read.const(effects)?.name
140
+ return { name }
141
+ },
142
+
143
+ // the execution function
144
+ async ({ effects, input }) => yamlFile.merge(input)
145
+ )
146
+ * ```
147
+ */
149
148
  withInput: <Id extends string, InputSpecType extends Record<string, any> | InputSpec<any, never> | InputSpec<any, any>, Type extends ExtractInputSpecType<InputSpecType> = ExtractInputSpecType<InputSpecType>>(id: Id, metadata: MaybeFn<Omit<T.ActionMetadata, "hasInput">>, inputSpec: InputSpecType, getInput: GetInput<Type>, run: Run<Type>) => Action<Id, unknown, InputSpecType>;
149
+ /**
150
+ * @description Use this function to create an action that does not accept form input
151
+ * @param id - a unique ID for this action
152
+ * @param metadata - information describing the action and its availability
153
+ * @param executionFn - execute the action. Optionally return data for the user to view. Must be in the structure of an ActionResult, version "1"
154
+ * @example
155
+ * In this example, we create an action that returns a secret phrase for the user to see.
156
+ *
157
+ * ```
158
+ import { sdk } from '../sdk'
159
+
160
+ export const showSecretPhrase = sdk.Action.withoutInput(
161
+ // id
162
+ 'show-secret-phrase',
163
+
164
+ // metadata
165
+ async ({ effects }) => ({
166
+ name: 'Show Secret Phrase',
167
+ description: 'Reveal the secret phrase for Hello World',
168
+ warning: null,
169
+ allowedStatuses: 'any',
170
+ group: null,
171
+ visibility: 'enabled',
172
+ }),
173
+
174
+ // the execution function
175
+ async ({ effects }) => ({
176
+ version: '1',
177
+ title: 'Secret Phrase',
178
+ message:
179
+ 'Below is your secret phrase. Use it to gain access to extraordinary places',
180
+ result: {
181
+ type: 'single',
182
+ value: await sdk.store
183
+ .getOwn(effects, sdk.StorePath.secretPhrase)
184
+ .const(),
185
+ copyable: true,
186
+ qr: true,
187
+ masked: true,
188
+ },
189
+ }),
190
+ )
191
+ * ```
192
+ */
150
193
  withoutInput: <Id_1 extends string>(id: Id_1, metadata: MaybeFn<Omit<T.ActionMetadata, "hasInput">>, run: Run<{}>) => Action<Id_1, unknown, {}>;
151
194
  };
152
195
  inputSpecConstants: {
@@ -202,9 +245,9 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
202
245
  id: string;
203
246
  /** The human readable description. */
204
247
  description: string;
205
- /** Not available until StartOS v0.4.0. If true, forces the user to select one URL (i.e. .onion, .local, or IP address) as the primary URL. This is needed by some services to function properly. */
248
+ /** No effect until StartOS v0.4.0. If true, forces the user to select one URL (i.e. .onion, .local, or IP address) as the primary URL. This is needed by some services to function properly. */
206
249
  hasPrimary: boolean;
207
- /** Affects how the interface appears to the user. One of: 'ui', 'api', 'p2p'. */
250
+ /** Affects how the interface appears to the user. One of: 'ui', 'api', 'p2p'. If 'ui', the user will see a "Launch UI" button */
208
251
  type: ServiceInterfaceType;
209
252
  /** (optional) prepends the provided username to all URLs. */
210
253
  username: null | string;
@@ -266,15 +309,22 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
266
309
  * In this example, we back up the entire "main" volume and nothing else.
267
310
  *
268
311
  * ```
269
- export const { createBackup, restoreBackup } = sdk.setupBackups(sdk.Backups.addVolume('main'))
312
+ import { sdk } from './sdk'
313
+
314
+ export const { createBackup, restoreBackup } = sdk.setupBackups(
315
+ async ({ effects }) => sdk.Backups.volumes('main'),
316
+ )
270
317
  * ```
271
318
  * @example
272
- * In this example, we back up the "main" and the "other" volume, but exclude hypothetical directory "excludedDir" from the "other".
319
+ * In this example, we back up the "main" volume, but exclude hypothetical directory "excludedDir".
273
320
  *
274
321
  * ```
275
- export const { createBackup, restoreBackup } = sdk.setupBackups(sdk.Backups
276
- .addVolume('main')
277
- .addVolume('other', { exclude: ['path/to/excludedDir'] })
322
+ import { sdk } from './sdk'
323
+
324
+ export const { createBackup, restoreBackup } = sdk.setupBackups(async () =>
325
+ sdk.Backups.volumes('main').setOptions({
326
+ exclude: ['excludedDir'],
327
+ }),
278
328
  )
279
329
  * ```
280
330
  */
@@ -284,37 +334,36 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
284
334
  };
285
335
  /**
286
336
  * @description Use this function to set dependency information.
287
- *
288
- * The function executes on service install, update, and inputSpec save. "input" will be of type `Input` for inputSpec save. It will be `null` for install and update.
289
337
  * @example
290
- * In this example, we create a static dependency on Hello World >=1.0.0:0, where Hello World must be running and passing its "webui" health check.
338
+ * In this example, we create a perpetual dependency on Hello World >=1.0.0:0, where Hello World must be running and passing its "primary" health check.
291
339
  *
292
340
  * ```
293
341
  export const setDependencies = sdk.setupDependencies(
294
342
  async ({ effects, input }) => {
295
343
  return {
296
- 'hello-world': sdk.Dependency.of({
297
- type: 'running',
298
- versionRange: VersionRange.parse('>=1.0.0:0'),
299
- healthChecks: ['webui'],
300
- }),
344
+ 'hello-world': {
345
+ kind: 'running',
346
+ versionRange: '>=1.0.0',
347
+ healthChecks: ['primary'],
348
+ },
301
349
  }
302
350
  },
303
351
  )
304
352
  * ```
305
353
  * @example
306
- * In this example, we create a conditional dependency on Hello World based on a hypothetical "needsWorld" boolean in the store.
354
+ * In this example, we create a conditional dependency on Hello World based on a hypothetical "needsWorld" boolean in our Store.
355
+ * Using .const() ensures that if the "needsWorld" boolean changes, setupDependencies will re-run.
307
356
  *
308
357
  * ```
309
358
  export const setDependencies = sdk.setupDependencies(
310
359
  async ({ effects }) => {
311
360
  if (sdk.store.getOwn(sdk.StorePath.needsWorld).const()) {
312
361
  return {
313
- 'hello-world': sdk.Dependency.of({
314
- type: 'running',
315
- versionRange: VersionRange.parse('>=1.0.0:0'),
316
- healthChecks: ['webui'],
317
- }),
362
+ 'hello-world': {
363
+ kind: 'running',
364
+ versionRange: '>=1.0.0',
365
+ healthChecks: ['primary'],
366
+ },
318
367
  }
319
368
  }
320
369
  return {}
@@ -327,7 +376,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
327
376
  }) => Promise<T.CurrentDependenciesResult<Manifest>>) => (options: {
328
377
  effects: Effects;
329
378
  }) => Promise<null>;
330
- setupInit: (versions: VersionGraph<string>, install: Install<Manifest, Store>, uninstall: Uninstall<Manifest, Store>, setServiceInterfaces: UpdateServiceInterfaces<any>, setDependencies: (options: {
379
+ setupInit: (versions: VersionGraph<string>, install: Install<Manifest, Store>, uninstall: import("./inits/setupUninstall").Uninstall<Manifest, Store>, setServiceInterfaces: UpdateServiceInterfaces<any>, setDependencies: (options: {
331
380
  effects: Effects;
332
381
  }) => Promise<void | null | undefined>, actions: Actions<Store, any>, exposedStore: T.ExposedStorePaths) => {
333
382
  packageInit: T.ExpectedExports.packageInit;
@@ -437,7 +486,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
437
486
  /**
438
487
  * Use this function to execute arbitrary logic *once*, on uninstall only. Most services will not use this.
439
488
  */
440
- setupUninstall: (fn: UninstallFn<Manifest, Store>) => Uninstall<Manifest, Store>;
489
+ setupUninstall: (fn: UninstallFn<Manifest, Store>) => import("./inits/setupUninstall").Uninstall<Manifest, Store>;
441
490
  trigger: {
442
491
  defaultTrigger: import("./trigger").Trigger;
443
492
  cooldownTrigger: typeof cooldownTrigger;
@@ -472,7 +521,8 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
472
521
  name: 'Name',
473
522
  description:
474
523
  'When you launch the Hello World UI, it will display "Hello [Name]"',
475
- required: { default: 'World' },
524
+ required: true,
525
+ default: 'World'
476
526
  }),
477
527
  makePublic: Value.toggle({
478
528
  name: 'Make Public',
@@ -519,6 +569,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
519
569
  label: Value.text({
520
570
  name: 'Label',
521
571
  required: false,
572
+ default: null,
522
573
  })
523
574
  })
524
575
  displayAs: 'label',
@@ -536,11 +587,13 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
536
587
  spec: InputSpec.of({
537
588
  label: Value.text({
538
589
  name: 'Label',
539
- required: { default: null },
590
+ required: true,
591
+ default: null,
540
592
  })
541
593
  pubkey: Value.text({
542
594
  name: 'Pubkey',
543
- required: { default: null },
595
+ required: true,
596
+ default: null,
544
597
  })
545
598
  })
546
599
  displayAs: 'label',
@@ -553,11 +606,13 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
553
606
  spec: InputSpec.of({
554
607
  label: Value.text({
555
608
  name: 'Label',
556
- required: { default: null },
609
+ required: true,
610
+ default: null,
557
611
  })
558
612
  pubkey: Value.text({
559
613
  name: 'Pubkey',
560
- required: { default: null },
614
+ required: true,
615
+ default: null,
561
616
  })
562
617
  })
563
618
  displayAs: 'label',
@@ -617,6 +672,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
617
672
  // required
618
673
  name: 'Text Example',
619
674
  required: false,
675
+ default: null,
620
676
 
621
677
  // optional
622
678
  description: null,
@@ -641,6 +697,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
641
697
  // required
642
698
  name: 'Textarea Example',
643
699
  required: false,
700
+ default: null,
644
701
 
645
702
  // optional
646
703
  description: null,
@@ -661,6 +718,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
661
718
  // required
662
719
  name: 'Number Example',
663
720
  required: false,
721
+ default: null,
664
722
  integer: true,
665
723
 
666
724
  // optional
@@ -684,6 +742,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
684
742
  // required
685
743
  name: 'Color Example',
686
744
  required: false,
745
+ default: null,
687
746
 
688
747
  // optional
689
748
  description: null,
@@ -701,6 +760,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
701
760
  // required
702
761
  name: 'Datetime Example',
703
762
  required: false,
763
+ default: null,
704
764
 
705
765
  // optional
706
766
  description: null,
@@ -720,7 +780,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
720
780
  selectExample: Value.select({
721
781
  // required
722
782
  name: 'Select Example',
723
- required: false,
783
+ default: 'radio1',
724
784
  values: {
725
785
  radio1: 'Radio 1',
726
786
  radio2: 'Radio 2',
@@ -785,7 +845,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
785
845
  {
786
846
  // required
787
847
  name: 'Union Example',
788
- required: false,
848
+ default: 'option1',
789
849
 
790
850
  // optional
791
851
  description: null,
@@ -1144,7 +1204,7 @@ export declare class StartSdk<Manifest extends T.SDKManifest, Store> {
1144
1204
  packageId?: string | undefined;
1145
1205
  hostId: string;
1146
1206
  internalPort: number;
1147
- }) => Promise<T.LanInfo>;
1207
+ }) => Promise<T.NetInfo>;
1148
1208
  clearBindings: (effects: Effects, options: {
1149
1209
  except: {
1150
1210
  id: string;