@sanity/workbench 0.1.0-alpha.5 → 0.1.0-alpha.7

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 (43) hide show
  1. package/dist/{log.js → _chunks-es/index.js} +1 -1
  2. package/dist/_chunks-es/index.js.map +1 -0
  3. package/dist/_internal.d.ts +13 -6
  4. package/dist/_internal.js +21 -5
  5. package/dist/_internal.js.map +1 -1
  6. package/dist/core.d.ts +906 -0
  7. package/dist/core.js +642 -0
  8. package/dist/core.js.map +1 -0
  9. package/package.json +11 -5
  10. package/src/_exports/core.ts +1 -0
  11. package/src/_internal/index.ts +2 -1
  12. package/src/_internal/render.test.ts +56 -1
  13. package/src/_internal/render.ts +52 -28
  14. package/src/core/__tests__/__fixtures__.ts +248 -0
  15. package/src/core/applications/application-list.test.ts +222 -0
  16. package/src/core/applications/application-list.ts +103 -0
  17. package/src/core/applications/application.ts +78 -0
  18. package/src/core/applications/local-application.test.ts +93 -0
  19. package/src/core/applications/local-application.ts +52 -0
  20. package/src/core/canvases.test.ts +38 -0
  21. package/src/core/canvases.ts +81 -0
  22. package/src/core/config.ts +34 -0
  23. package/src/core/index.ts +12 -0
  24. package/src/core/media-libraries.test.ts +38 -0
  25. package/src/core/media-libraries.ts +83 -0
  26. package/src/core/organizations.test.ts +134 -0
  27. package/src/core/organizations.ts +115 -0
  28. package/src/core/projects.test.ts +248 -0
  29. package/src/core/projects.ts +114 -0
  30. package/src/core/shared/urls.test.ts +182 -0
  31. package/src/core/shared/urls.ts +128 -0
  32. package/src/core/user-applications/core-app.test.ts +151 -0
  33. package/src/core/user-applications/core-app.ts +57 -0
  34. package/src/core/user-applications/studio.test.ts +928 -0
  35. package/src/core/user-applications/studio.ts +656 -0
  36. package/src/core/user-applications/user-application.test.ts +126 -0
  37. package/src/core/user-applications/user-application.ts +76 -0
  38. package/src/vite-env.d.ts +8 -0
  39. package/dist/log.d.ts +0 -48
  40. package/dist/log.js.map +0 -1
  41. package/src/_exports/log.ts +0 -1
  42. /package/src/{log → core/log}/index.test.ts +0 -0
  43. /package/src/{log → core/log}/index.ts +0 -0
@@ -0,0 +1,151 @@
1
+ import type { ApplicationResource as ProtocolApplicationResource } from "@sanity/message-protocol";
2
+ import { afterEach, describe, expect, expectTypeOf, it, vi } from "vitest";
3
+
4
+ import { APPLICATION_DATA } from "../__tests__/__fixtures__";
5
+ import { CoreAppApplication } from "./core-app";
6
+
7
+ const setup = () => new CoreAppApplication(APPLICATION_DATA);
8
+
9
+ describe("CoreAppApplication", () => {
10
+ afterEach(() => {
11
+ vi.unstubAllEnvs();
12
+ });
13
+ it("should have a type of coreApp", () => {
14
+ const application = setup();
15
+ expect(application.type).toBe("coreApp");
16
+ });
17
+
18
+ it("should have a href of <application>/<id>", () => {
19
+ const application = setup();
20
+ expect(application.href).toBe("/application/v27rvqtlp3lmdvcln6ey3lro");
21
+ });
22
+
23
+ it("should have a name of the application title", () => {
24
+ const application = setup();
25
+ expect(application.title).toBe("sdk-movie-list");
26
+ });
27
+
28
+ it("should have a updatedAt property", () => {
29
+ const application = setup();
30
+ expect(application.updatedAt).toBe("2025-03-27T19:00:32.792Z");
31
+ });
32
+
33
+ it("should have an activeDeployment property", () => {
34
+ const application = setup();
35
+ expect(application.activeDeployment).toMatchInlineSnapshot(`
36
+ {
37
+ "createdAt": "2025-03-27T19:07:21.038Z",
38
+ "deployedAt": "2025-03-27T19:07:21.082Z",
39
+ "deployedBy": "gwXueEBci",
40
+ "id": "dv3kz3fsl4aqha3parc8k391",
41
+ "isActiveDeployment": true,
42
+ "isAutoUpdating": false,
43
+ "manifest": null,
44
+ "size": 528292,
45
+ "updatedAt": "2025-03-27T19:07:21.082Z",
46
+ "userApplicationId": "v27rvqtlp3lmdvcln6ey3lro",
47
+ "version": "3.81.0",
48
+ }
49
+ `);
50
+ });
51
+
52
+ it("should implement the toProtocolResource method", () => {
53
+ vi.stubEnv("VITE_SANITY_ENV", "staging");
54
+ vi.stubEnv("VITE_SANITY_DOMAIN", "sanity.work");
55
+ const application = setup();
56
+ expect(application.toProtocolResource()).toMatchInlineSnapshot(`
57
+ {
58
+ "activeDeployment": {
59
+ "createdAt": "2025-03-27T19:07:21.038Z",
60
+ "deployedAt": "2025-03-27T19:07:21.082Z",
61
+ "deployedBy": "gwXueEBci",
62
+ "id": "dv3kz3fsl4aqha3parc8k391",
63
+ "isActiveDeployment": true,
64
+ "isAutoUpdating": false,
65
+ "manifest": null,
66
+ "size": 528292,
67
+ "updatedAt": "2025-03-27T19:07:21.082Z",
68
+ "userApplicationId": "v27rvqtlp3lmdvcln6ey3lro",
69
+ "version": "3.81.0",
70
+ },
71
+ "appHost": "x7apsmr6fxvc",
72
+ "createdAt": "2025-03-27T19:00:32.792Z",
73
+ "dashboardStatus": "default",
74
+ "id": "v27rvqtlp3lmdvcln6ey3lro",
75
+ "organizationId": "oSyH1iET5",
76
+ "projectId": null,
77
+ "title": "sdk-movie-list",
78
+ "type": "application",
79
+ "updatedAt": "2025-03-27T19:00:32.792Z",
80
+ "url": "https://x7apsmr6fxvc.studio.sanity.work/",
81
+ "urlType": "internal",
82
+ }
83
+ `);
84
+
85
+ expectTypeOf(
86
+ application.toProtocolResource(),
87
+ ).toEqualTypeOf<ProtocolApplicationResource>();
88
+ });
89
+
90
+ it("should return undefined for subtitle", () => {
91
+ const application = setup();
92
+ expect(application.subtitle).toBeUndefined();
93
+ });
94
+
95
+ describe("get", () => {
96
+ it("should throw when accessing a non-existent attribute", () => {
97
+ const application = setup();
98
+ expect(() =>
99
+ // @ts-expect-error - testing invalid attribute
100
+ application.get("nonExistent"),
101
+ ).toThrow(
102
+ "Attribute nonExistent does not exist on application v27rvqtlp3lmdvcln6ey3lro",
103
+ );
104
+ });
105
+ });
106
+
107
+ describe("manifest functionality", () => {
108
+ it("should use manifest from application when present", () => {
109
+ const applicationWithManifest = {
110
+ ...APPLICATION_DATA,
111
+ activeDeployment: {
112
+ ...APPLICATION_DATA.activeDeployment,
113
+ manifest: {
114
+ version: "1.0.0",
115
+ icon: "<svg>test-icon</svg>",
116
+ title: "Manifest Title",
117
+ },
118
+ },
119
+ };
120
+ const application = new CoreAppApplication(applicationWithManifest);
121
+ expect(application.title).toBe("Manifest Title");
122
+ });
123
+
124
+ it("should use manifest from activeDeployment when application manifest is not present", () => {
125
+ const applicationWithDeploymentManifest = {
126
+ ...APPLICATION_DATA,
127
+ activeDeployment: {
128
+ ...APPLICATION_DATA.activeDeployment,
129
+ manifest: {
130
+ version: "1.0.0",
131
+ icon: "<svg>deployment-icon</svg>",
132
+ title: "Deployment Title",
133
+ },
134
+ },
135
+ };
136
+ const application = new CoreAppApplication(
137
+ applicationWithDeploymentManifest,
138
+ );
139
+ expect(application.title).toBe("Deployment Title");
140
+ });
141
+
142
+ it("should allow you to get attributes from the application", () => {
143
+ const application = setup();
144
+
145
+ expect(application.get("title")).toBe("sdk-movie-list");
146
+ expect(application.get("urlType")).toBe("internal");
147
+ expect(application.get("appHost")).toBe("x7apsmr6fxvc");
148
+ expectTypeOf(application.get("appHost")).toEqualTypeOf<string>();
149
+ });
150
+ });
151
+ });
@@ -0,0 +1,57 @@
1
+ import type {
2
+ ApplicationResource as ProtocolApplicationResource,
3
+ CoreApplication,
4
+ } from "@sanity/message-protocol";
5
+
6
+ import { UserApplication } from "./user-application";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export class CoreAppApplication extends UserApplication<
12
+ CoreApplication,
13
+ "coreApp",
14
+ ProtocolApplicationResource
15
+ > {
16
+ readonly activeDeployment: CoreApplication["activeDeployment"];
17
+
18
+ constructor(application: CoreApplication) {
19
+ super(application, "coreApp");
20
+
21
+ this.activeDeployment = application.activeDeployment;
22
+ }
23
+
24
+ get href() {
25
+ return `/application/${this.application.id}`;
26
+ }
27
+
28
+ get title() {
29
+ return this.activeDeployment?.manifest?.title ?? this.application.title;
30
+ }
31
+
32
+ get subtitle() {
33
+ return undefined;
34
+ }
35
+
36
+ get updatedAt() {
37
+ return this.application.updatedAt;
38
+ }
39
+
40
+ get<TKey extends keyof CoreApplication>(attr: TKey): CoreApplication[TKey] {
41
+ if (!(attr in this.application)) {
42
+ throw new Error(
43
+ `Attribute ${attr.toString()} does not exist on application ${this.application.id}`,
44
+ );
45
+ }
46
+
47
+ return this.application[attr];
48
+ }
49
+
50
+ toProtocolResource(): ProtocolApplicationResource {
51
+ return {
52
+ ...this.application,
53
+ type: "application",
54
+ url: this.url.toString(),
55
+ } satisfies ProtocolApplicationResource;
56
+ }
57
+ }