@gameslate/sdk 0.3.16 → 0.3.19

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,20 @@
1
+ import { z } from 'zod';
2
+ import { type PluginManifest } from './plugin-manifest.js';
3
+ export declare const PluginPermissionSchema: z.ZodObject<{
4
+ /** stable across versions: an update is compared key by key */
5
+ key: z.ZodString;
6
+ label: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ label: string;
9
+ key: string;
10
+ }, {
11
+ label: string;
12
+ key: string;
13
+ }>;
14
+ export type PluginPermission = z.infer<typeof PluginPermissionSchema>;
15
+ export declare function pluginPermissions(manifest: PluginManifest): PluginPermission[];
16
+ /** The permissions `next` asks for that `current` didn't have. */
17
+ export declare function addedPermissions(current: readonly PluginPermission[], next: readonly PluginPermission[]): PluginPermission[];
18
+ /** -1, 0 or 1 as version `a` (major.minor.patch) is older than, the same as or newer than `b`.
19
+ * Throws on any other form: a guess would install the wrong version or none. */
20
+ export declare function compareVersions(a: string, b: string): number;
@@ -0,0 +1,58 @@
1
+ import { z } from 'zod';
2
+ import { PluginVersionSchema } from './plugin-manifest.js';
3
+ /*
4
+ * What a plugin may do, in the player's words, derived from its manifest (docs/plugin-architecture.md,
5
+ * "Capabilities"): read the memory of each game it names, read the folders it offers for building
6
+ * maps, fetch each file it declares from the web. The cog shows these before an install, and an
7
+ * update that adds one waits for the player's consent. No plugin code runs outside the sandbox,
8
+ * so no permission names that.
9
+ */
10
+ export const PluginPermissionSchema = z.object({
11
+ /** stable across versions: an update is compared key by key */
12
+ key: z.string(),
13
+ label: z.string(),
14
+ });
15
+ export function pluginPermissions(manifest) {
16
+ const memory = manifest.games.map(g => ({
17
+ key: `memory:${g.id}`,
18
+ label: `Read ${g.title}'s memory while it runs`,
19
+ }));
20
+ /* the offered folders are read only by asset code */
21
+ const folders = manifest.assets
22
+ ? [...new Set(manifest.games.flatMap(g => g.inputs.flatMap(i => i.folders)))].map(f => ({
23
+ key: `files:${f}`,
24
+ label: `Read your game files in ${f} to build maps`,
25
+ }))
26
+ : [];
27
+ /* keyed by URL and hash: pointing a download at other bytes asks again */
28
+ const downloads = new Map(manifest.games.flatMap(g => g.downloads.map(d => [
29
+ `download:${d.url}#${d.sha256}`,
30
+ `Downloads ${downloadPlace(d.url)} to build maps`,
31
+ ])));
32
+ return [...memory, ...folders, ...[...downloads].map(([key, label]) => ({ key, label }))];
33
+ }
34
+ /* host and path, as the player reads a link ("example.com/a/b.tar.gz") */
35
+ function downloadPlace(url) {
36
+ const u = new URL(url);
37
+ return `${u.host}${u.pathname}${u.search}`;
38
+ }
39
+ /** The permissions `next` asks for that `current` didn't have. */
40
+ export function addedPermissions(current, next) {
41
+ const had = new Set(current.map(p => p.key));
42
+ return next.filter(p => !had.has(p.key));
43
+ }
44
+ /** -1, 0 or 1 as version `a` (major.minor.patch) is older than, the same as or newer than `b`.
45
+ * Throws on any other form: a guess would install the wrong version or none. */
46
+ export function compareVersions(a, b) {
47
+ const pa = versionParts(a);
48
+ const pb = versionParts(b);
49
+ for (let i = 0; i < 3; i++) {
50
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
51
+ if (d !== 0)
52
+ return Math.sign(d);
53
+ }
54
+ return 0;
55
+ }
56
+ function versionParts(version) {
57
+ return PluginVersionSchema.parse(version).split('.').map(Number);
58
+ }
@@ -1,10 +1,179 @@
1
1
  import { z } from 'zod';
2
+ /** A plugin the player added by URL; a preset (built with the core) has none. */
3
+ export declare const InstalledInfoSchema: z.ZodObject<{
4
+ /** the manifest or zip URL it was added from */
5
+ url: z.ZodString;
6
+ /** false for a plain zip: there is no manifest to check for updates */
7
+ updates: z.ZodBoolean;
8
+ autoUpdate: z.ZodBoolean;
9
+ /** the version kept for a rollback */
10
+ previous: z.ZodNullable<z.ZodString>;
11
+ /** a newer version found at the URL, not installed yet */
12
+ update: z.ZodNullable<z.ZodObject<{
13
+ version: z.ZodString;
14
+ /** its zip's sha256: confirming sends it back, so only this version installs */
15
+ sha256: z.ZodString;
16
+ /** permissions it asks for that this version doesn't have: it waits for consent */
17
+ wants: z.ZodArray<z.ZodObject<{
18
+ key: z.ZodString;
19
+ label: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ label: string;
22
+ key: string;
23
+ }, {
24
+ label: string;
25
+ key: string;
26
+ }>, "many">;
27
+ /** it installs itself (auto-update on, nothing new asked, not rolled back from, not
28
+ * failed before) */
29
+ automatic: z.ZodBoolean;
30
+ /** it will install itself once no game from this plugin is running */
31
+ waitingForGame: z.ZodBoolean;
32
+ }, "strip", z.ZodTypeAny, {
33
+ sha256: string;
34
+ version: string;
35
+ wants: {
36
+ label: string;
37
+ key: string;
38
+ }[];
39
+ automatic: boolean;
40
+ waitingForGame: boolean;
41
+ }, {
42
+ sha256: string;
43
+ version: string;
44
+ wants: {
45
+ label: string;
46
+ key: string;
47
+ }[];
48
+ automatic: boolean;
49
+ waitingForGame: boolean;
50
+ }>>;
51
+ /** why the last update check or automatic update failed */
52
+ checkError: z.ZodNullable<z.ZodString>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ url: string;
55
+ updates: boolean;
56
+ autoUpdate: boolean;
57
+ previous: string | null;
58
+ update: {
59
+ sha256: string;
60
+ version: string;
61
+ wants: {
62
+ label: string;
63
+ key: string;
64
+ }[];
65
+ automatic: boolean;
66
+ waitingForGame: boolean;
67
+ } | null;
68
+ checkError: string | null;
69
+ }, {
70
+ url: string;
71
+ updates: boolean;
72
+ autoUpdate: boolean;
73
+ previous: string | null;
74
+ update: {
75
+ sha256: string;
76
+ version: string;
77
+ wants: {
78
+ label: string;
79
+ key: string;
80
+ }[];
81
+ automatic: boolean;
82
+ waitingForGame: boolean;
83
+ } | null;
84
+ checkError: string | null;
85
+ }>;
86
+ export type InstalledInfo = z.infer<typeof InstalledInfoSchema>;
2
87
  export declare const PluginViewSchema: z.ZodObject<{
3
88
  id: z.ZodString;
4
89
  name: z.ZodString;
5
90
  version: z.ZodString;
6
91
  /** built and tested with another core version */
7
92
  untested: z.ZodBoolean;
93
+ /** null: a preset, which can be hidden but not removed */
94
+ installed: z.ZodNullable<z.ZodObject<{
95
+ /** the manifest or zip URL it was added from */
96
+ url: z.ZodString;
97
+ /** false for a plain zip: there is no manifest to check for updates */
98
+ updates: z.ZodBoolean;
99
+ autoUpdate: z.ZodBoolean;
100
+ /** the version kept for a rollback */
101
+ previous: z.ZodNullable<z.ZodString>;
102
+ /** a newer version found at the URL, not installed yet */
103
+ update: z.ZodNullable<z.ZodObject<{
104
+ version: z.ZodString;
105
+ /** its zip's sha256: confirming sends it back, so only this version installs */
106
+ sha256: z.ZodString;
107
+ /** permissions it asks for that this version doesn't have: it waits for consent */
108
+ wants: z.ZodArray<z.ZodObject<{
109
+ key: z.ZodString;
110
+ label: z.ZodString;
111
+ }, "strip", z.ZodTypeAny, {
112
+ label: string;
113
+ key: string;
114
+ }, {
115
+ label: string;
116
+ key: string;
117
+ }>, "many">;
118
+ /** it installs itself (auto-update on, nothing new asked, not rolled back from, not
119
+ * failed before) */
120
+ automatic: z.ZodBoolean;
121
+ /** it will install itself once no game from this plugin is running */
122
+ waitingForGame: z.ZodBoolean;
123
+ }, "strip", z.ZodTypeAny, {
124
+ sha256: string;
125
+ version: string;
126
+ wants: {
127
+ label: string;
128
+ key: string;
129
+ }[];
130
+ automatic: boolean;
131
+ waitingForGame: boolean;
132
+ }, {
133
+ sha256: string;
134
+ version: string;
135
+ wants: {
136
+ label: string;
137
+ key: string;
138
+ }[];
139
+ automatic: boolean;
140
+ waitingForGame: boolean;
141
+ }>>;
142
+ /** why the last update check or automatic update failed */
143
+ checkError: z.ZodNullable<z.ZodString>;
144
+ }, "strip", z.ZodTypeAny, {
145
+ url: string;
146
+ updates: boolean;
147
+ autoUpdate: boolean;
148
+ previous: string | null;
149
+ update: {
150
+ sha256: string;
151
+ version: string;
152
+ wants: {
153
+ label: string;
154
+ key: string;
155
+ }[];
156
+ automatic: boolean;
157
+ waitingForGame: boolean;
158
+ } | null;
159
+ checkError: string | null;
160
+ }, {
161
+ url: string;
162
+ updates: boolean;
163
+ autoUpdate: boolean;
164
+ previous: string | null;
165
+ update: {
166
+ sha256: string;
167
+ version: string;
168
+ wants: {
169
+ label: string;
170
+ key: string;
171
+ }[];
172
+ automatic: boolean;
173
+ waitingForGame: boolean;
174
+ } | null;
175
+ checkError: string | null;
176
+ }>>;
8
177
  features: z.ZodObject<{
9
178
  live: z.ZodObject<{
10
179
  available: z.ZodBoolean;
@@ -77,6 +246,7 @@ export declare const PluginViewSchema: z.ZodObject<{
77
246
  }, "strip", z.ZodTypeAny, {
78
247
  id: string;
79
248
  name: string;
249
+ version: string;
80
250
  games: {
81
251
  id: string;
82
252
  title: string;
@@ -85,8 +255,24 @@ export declare const PluginViewSchema: z.ZodObject<{
85
255
  folder: string;
86
256
  }[];
87
257
  }[];
88
- version: string;
89
258
  untested: boolean;
259
+ installed: {
260
+ url: string;
261
+ updates: boolean;
262
+ autoUpdate: boolean;
263
+ previous: string | null;
264
+ update: {
265
+ sha256: string;
266
+ version: string;
267
+ wants: {
268
+ label: string;
269
+ key: string;
270
+ }[];
271
+ automatic: boolean;
272
+ waitingForGame: boolean;
273
+ } | null;
274
+ checkError: string | null;
275
+ } | null;
90
276
  features: {
91
277
  assets: {
92
278
  available: boolean;
@@ -100,6 +286,7 @@ export declare const PluginViewSchema: z.ZodObject<{
100
286
  }, {
101
287
  id: string;
102
288
  name: string;
289
+ version: string;
103
290
  games: {
104
291
  id: string;
105
292
  title: string;
@@ -108,8 +295,24 @@ export declare const PluginViewSchema: z.ZodObject<{
108
295
  folder: string;
109
296
  }[];
110
297
  }[];
111
- version: string;
112
298
  untested: boolean;
299
+ installed: {
300
+ url: string;
301
+ updates: boolean;
302
+ autoUpdate: boolean;
303
+ previous: string | null;
304
+ update: {
305
+ sha256: string;
306
+ version: string;
307
+ wants: {
308
+ label: string;
309
+ key: string;
310
+ }[];
311
+ automatic: boolean;
312
+ waitingForGame: boolean;
313
+ } | null;
314
+ checkError: string | null;
315
+ } | null;
113
316
  features: {
114
317
  assets: {
115
318
  available: boolean;
@@ -195,6 +398,90 @@ export declare const PluginsResponseSchema: z.ZodObject<{
195
398
  version: z.ZodString;
196
399
  /** built and tested with another core version */
197
400
  untested: z.ZodBoolean;
401
+ /** null: a preset, which can be hidden but not removed */
402
+ installed: z.ZodNullable<z.ZodObject<{
403
+ /** the manifest or zip URL it was added from */
404
+ url: z.ZodString;
405
+ /** false for a plain zip: there is no manifest to check for updates */
406
+ updates: z.ZodBoolean;
407
+ autoUpdate: z.ZodBoolean;
408
+ /** the version kept for a rollback */
409
+ previous: z.ZodNullable<z.ZodString>;
410
+ /** a newer version found at the URL, not installed yet */
411
+ update: z.ZodNullable<z.ZodObject<{
412
+ version: z.ZodString;
413
+ /** its zip's sha256: confirming sends it back, so only this version installs */
414
+ sha256: z.ZodString;
415
+ /** permissions it asks for that this version doesn't have: it waits for consent */
416
+ wants: z.ZodArray<z.ZodObject<{
417
+ key: z.ZodString;
418
+ label: z.ZodString;
419
+ }, "strip", z.ZodTypeAny, {
420
+ label: string;
421
+ key: string;
422
+ }, {
423
+ label: string;
424
+ key: string;
425
+ }>, "many">;
426
+ /** it installs itself (auto-update on, nothing new asked, not rolled back from, not
427
+ * failed before) */
428
+ automatic: z.ZodBoolean;
429
+ /** it will install itself once no game from this plugin is running */
430
+ waitingForGame: z.ZodBoolean;
431
+ }, "strip", z.ZodTypeAny, {
432
+ sha256: string;
433
+ version: string;
434
+ wants: {
435
+ label: string;
436
+ key: string;
437
+ }[];
438
+ automatic: boolean;
439
+ waitingForGame: boolean;
440
+ }, {
441
+ sha256: string;
442
+ version: string;
443
+ wants: {
444
+ label: string;
445
+ key: string;
446
+ }[];
447
+ automatic: boolean;
448
+ waitingForGame: boolean;
449
+ }>>;
450
+ /** why the last update check or automatic update failed */
451
+ checkError: z.ZodNullable<z.ZodString>;
452
+ }, "strip", z.ZodTypeAny, {
453
+ url: string;
454
+ updates: boolean;
455
+ autoUpdate: boolean;
456
+ previous: string | null;
457
+ update: {
458
+ sha256: string;
459
+ version: string;
460
+ wants: {
461
+ label: string;
462
+ key: string;
463
+ }[];
464
+ automatic: boolean;
465
+ waitingForGame: boolean;
466
+ } | null;
467
+ checkError: string | null;
468
+ }, {
469
+ url: string;
470
+ updates: boolean;
471
+ autoUpdate: boolean;
472
+ previous: string | null;
473
+ update: {
474
+ sha256: string;
475
+ version: string;
476
+ wants: {
477
+ label: string;
478
+ key: string;
479
+ }[];
480
+ automatic: boolean;
481
+ waitingForGame: boolean;
482
+ } | null;
483
+ checkError: string | null;
484
+ }>>;
198
485
  features: z.ZodObject<{
199
486
  live: z.ZodObject<{
200
487
  available: z.ZodBoolean;
@@ -267,6 +554,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
267
554
  }, "strip", z.ZodTypeAny, {
268
555
  id: string;
269
556
  name: string;
557
+ version: string;
270
558
  games: {
271
559
  id: string;
272
560
  title: string;
@@ -275,8 +563,24 @@ export declare const PluginsResponseSchema: z.ZodObject<{
275
563
  folder: string;
276
564
  }[];
277
565
  }[];
278
- version: string;
279
566
  untested: boolean;
567
+ installed: {
568
+ url: string;
569
+ updates: boolean;
570
+ autoUpdate: boolean;
571
+ previous: string | null;
572
+ update: {
573
+ sha256: string;
574
+ version: string;
575
+ wants: {
576
+ label: string;
577
+ key: string;
578
+ }[];
579
+ automatic: boolean;
580
+ waitingForGame: boolean;
581
+ } | null;
582
+ checkError: string | null;
583
+ } | null;
280
584
  features: {
281
585
  assets: {
282
586
  available: boolean;
@@ -290,6 +594,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
290
594
  }, {
291
595
  id: string;
292
596
  name: string;
597
+ version: string;
293
598
  games: {
294
599
  id: string;
295
600
  title: string;
@@ -298,8 +603,24 @@ export declare const PluginsResponseSchema: z.ZodObject<{
298
603
  folder: string;
299
604
  }[];
300
605
  }[];
301
- version: string;
302
606
  untested: boolean;
607
+ installed: {
608
+ url: string;
609
+ updates: boolean;
610
+ autoUpdate: boolean;
611
+ previous: string | null;
612
+ update: {
613
+ sha256: string;
614
+ version: string;
615
+ wants: {
616
+ label: string;
617
+ key: string;
618
+ }[];
619
+ automatic: boolean;
620
+ waitingForGame: boolean;
621
+ } | null;
622
+ checkError: string | null;
623
+ } | null;
303
624
  features: {
304
625
  assets: {
305
626
  available: boolean;
@@ -375,10 +696,33 @@ export declare const PluginsResponseSchema: z.ZodObject<{
375
696
  error?: string | undefined;
376
697
  building?: string[] | undefined;
377
698
  }>>;
699
+ /** presets the player hid: not loaded, offered to show again */
700
+ hidden: z.ZodArray<z.ZodObject<{
701
+ id: z.ZodString;
702
+ name: z.ZodString;
703
+ version: z.ZodString;
704
+ }, "strip", z.ZodTypeAny, {
705
+ id: string;
706
+ name: string;
707
+ version: string;
708
+ }, {
709
+ id: string;
710
+ name: string;
711
+ version: string;
712
+ }>, "many">;
713
+ /** why plugins can't be added, updated or removed right now (the daemon's install record is
714
+ * damaged), or null */
715
+ installError: z.ZodNullable<z.ZodString>;
378
716
  }, "strip", z.ZodTypeAny, {
717
+ hidden: {
718
+ id: string;
719
+ name: string;
720
+ version: string;
721
+ }[];
379
722
  plugins: {
380
723
  id: string;
381
724
  name: string;
725
+ version: string;
382
726
  games: {
383
727
  id: string;
384
728
  title: string;
@@ -387,8 +731,24 @@ export declare const PluginsResponseSchema: z.ZodObject<{
387
731
  folder: string;
388
732
  }[];
389
733
  }[];
390
- version: string;
391
734
  untested: boolean;
735
+ installed: {
736
+ url: string;
737
+ updates: boolean;
738
+ autoUpdate: boolean;
739
+ previous: string | null;
740
+ update: {
741
+ sha256: string;
742
+ version: string;
743
+ wants: {
744
+ label: string;
745
+ key: string;
746
+ }[];
747
+ automatic: boolean;
748
+ waitingForGame: boolean;
749
+ } | null;
750
+ checkError: string | null;
751
+ } | null;
392
752
  features: {
393
753
  assets: {
394
754
  available: boolean;
@@ -419,10 +779,17 @@ export declare const PluginsResponseSchema: z.ZodObject<{
419
779
  error?: string | undefined;
420
780
  building?: string[] | undefined;
421
781
  } | null;
782
+ installError: string | null;
422
783
  }, {
784
+ hidden: {
785
+ id: string;
786
+ name: string;
787
+ version: string;
788
+ }[];
423
789
  plugins: {
424
790
  id: string;
425
791
  name: string;
792
+ version: string;
426
793
  games: {
427
794
  id: string;
428
795
  title: string;
@@ -431,8 +798,24 @@ export declare const PluginsResponseSchema: z.ZodObject<{
431
798
  folder: string;
432
799
  }[];
433
800
  }[];
434
- version: string;
435
801
  untested: boolean;
802
+ installed: {
803
+ url: string;
804
+ updates: boolean;
805
+ autoUpdate: boolean;
806
+ previous: string | null;
807
+ update: {
808
+ sha256: string;
809
+ version: string;
810
+ wants: {
811
+ label: string;
812
+ key: string;
813
+ }[];
814
+ automatic: boolean;
815
+ waitingForGame: boolean;
816
+ } | null;
817
+ checkError: string | null;
818
+ } | null;
436
819
  features: {
437
820
  assets: {
438
821
  available: boolean;
@@ -463,5 +846,92 @@ export declare const PluginsResponseSchema: z.ZodObject<{
463
846
  error?: string | undefined;
464
847
  building?: string[] | undefined;
465
848
  } | null;
849
+ installError: string | null;
466
850
  }>;
467
851
  export type PluginsResponse = z.infer<typeof PluginsResponseSchema>;
852
+ /** What a URL holds, shown for the player to confirm before anything is installed. */
853
+ export declare const PluginPreviewSchema: z.ZodObject<{
854
+ url: z.ZodString;
855
+ /** a published manifest (updates are checked), or a plain zip (no update checks) */
856
+ kind: z.ZodEnum<["manifest", "zip"]>;
857
+ id: z.ZodString;
858
+ name: z.ZodString;
859
+ version: z.ZodString;
860
+ games: z.ZodArray<z.ZodObject<{
861
+ id: z.ZodString;
862
+ title: z.ZodString;
863
+ }, "strip", z.ZodTypeAny, {
864
+ id: string;
865
+ title: string;
866
+ }, {
867
+ id: string;
868
+ title: string;
869
+ }>, "many">;
870
+ permissions: z.ZodArray<z.ZodObject<{
871
+ key: z.ZodString;
872
+ label: z.ZodString;
873
+ }, "strip", z.ZodTypeAny, {
874
+ label: string;
875
+ key: string;
876
+ }, {
877
+ label: string;
878
+ key: string;
879
+ }>, "many">;
880
+ /** the zip's sha256: the install refuses any other */
881
+ sha256: z.ZodString;
882
+ /** where that hash came from: the manifest, a `.zip.sha256` beside the zip, or only this
883
+ * download */
884
+ checksum: z.ZodEnum<["manifest", "sidecar", "none"]>;
885
+ /** the version of this plugin already here, if any */
886
+ replaces: z.ZodNullable<z.ZodObject<{
887
+ version: z.ZodString;
888
+ preset: z.ZodBoolean;
889
+ }, "strip", z.ZodTypeAny, {
890
+ version: string;
891
+ preset: boolean;
892
+ }, {
893
+ version: string;
894
+ preset: boolean;
895
+ }>>;
896
+ }, "strip", z.ZodTypeAny, {
897
+ id: string;
898
+ kind: "manifest" | "zip";
899
+ name: string;
900
+ url: string;
901
+ sha256: string;
902
+ version: string;
903
+ games: {
904
+ id: string;
905
+ title: string;
906
+ }[];
907
+ permissions: {
908
+ label: string;
909
+ key: string;
910
+ }[];
911
+ checksum: "none" | "manifest" | "sidecar";
912
+ replaces: {
913
+ version: string;
914
+ preset: boolean;
915
+ } | null;
916
+ }, {
917
+ id: string;
918
+ kind: "manifest" | "zip";
919
+ name: string;
920
+ url: string;
921
+ sha256: string;
922
+ version: string;
923
+ games: {
924
+ id: string;
925
+ title: string;
926
+ }[];
927
+ permissions: {
928
+ label: string;
929
+ key: string;
930
+ }[];
931
+ checksum: "none" | "manifest" | "sidecar";
932
+ replaces: {
933
+ version: string;
934
+ preset: boolean;
935
+ } | null;
936
+ }>;
937
+ export type PluginPreview = z.infer<typeof PluginPreviewSchema>;