@sanity/workbench 0.1.0-alpha.12 → 0.1.0-alpha.14

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/dist/system.js ADDED
@@ -0,0 +1,528 @@
1
+ import { getAuthState, logout, AuthStateType, getClient, createSanityInstance } from "@sanity/sdk";
2
+ import { fromObservable, fromPromise, setup, assign, fromCallback, sendTo, raise } from "xstate";
3
+ import "./_chunks-es/studio.js";
4
+ import { logger } from "./_chunks-es/index.js";
5
+ import { createSessionId, createBatchedStore } from "@sanity/telemetry";
6
+ const authStateLogic = fromObservable(
7
+ ({ input }) => getAuthState(input.instance).observable
8
+ ), logoutActorLogic = fromPromise(async ({ input }) => {
9
+ await logout(input.instance);
10
+ }), authLogic = setup({
11
+ types: {
12
+ input: {},
13
+ context: {},
14
+ events: {},
15
+ tags: {}
16
+ },
17
+ actors: {
18
+ authState: authStateLogic,
19
+ logoutActor: logoutActorLogic
20
+ },
21
+ delays: {
22
+ authTimeout: 3e4
23
+ },
24
+ guards: {
25
+ isLoggedInComplete: (_, params) => params.state?.type === AuthStateType.LOGGED_IN && !!params.state.token && params.state.currentUser !== null,
26
+ isAuthState: (_, params) => params.state?.type === params.type
27
+ },
28
+ actions: {
29
+ setLoggedIn: assign({
30
+ token: (_, params) => params.token,
31
+ currentUser: (_, params) => params.currentUser,
32
+ error: () => null
33
+ }),
34
+ clearAuth: assign({
35
+ token: () => null,
36
+ currentUser: () => null,
37
+ error: () => null
38
+ }),
39
+ setError: assign({
40
+ token: () => null,
41
+ currentUser: () => null,
42
+ error: (_, params) => params.error
43
+ })
44
+ }
45
+ }).createMachine({
46
+ id: "auth",
47
+ initial: "init",
48
+ context: ({ input }) => ({
49
+ instance: input.instance,
50
+ token: null,
51
+ currentUser: null,
52
+ error: null
53
+ }),
54
+ invoke: {
55
+ src: "authState",
56
+ input: ({ context }) => ({ instance: context.instance }),
57
+ onSnapshot: [
58
+ {
59
+ guard: {
60
+ type: "isLoggedInComplete",
61
+ params: ({ event }) => ({
62
+ state: event.snapshot.context
63
+ })
64
+ },
65
+ actions: [
66
+ {
67
+ type: "setLoggedIn",
68
+ params: ({ event }) => {
69
+ const state = event.snapshot.context;
70
+ return {
71
+ token: state.token,
72
+ currentUser: state.currentUser
73
+ };
74
+ }
75
+ }
76
+ ],
77
+ target: `.${AuthStateType.LOGGED_IN}`
78
+ },
79
+ {
80
+ guard: {
81
+ type: "isAuthState",
82
+ params: ({ event }) => ({
83
+ state: event.snapshot.context,
84
+ type: AuthStateType.LOGGING_IN
85
+ })
86
+ },
87
+ actions: [{ type: "clearAuth" }],
88
+ target: `.${AuthStateType.LOGGING_IN}`
89
+ },
90
+ {
91
+ guard: {
92
+ type: "isAuthState",
93
+ params: ({ event }) => ({
94
+ state: event.snapshot.context,
95
+ type: AuthStateType.ERROR
96
+ })
97
+ },
98
+ actions: [
99
+ {
100
+ type: "setError",
101
+ params: ({ event }) => ({
102
+ error: event.snapshot.context?.type === AuthStateType.ERROR ? event.snapshot.context.error : null
103
+ })
104
+ }
105
+ ],
106
+ target: `.${AuthStateType.ERROR}`
107
+ },
108
+ {
109
+ guard: {
110
+ type: "isAuthState",
111
+ params: ({ event }) => ({
112
+ state: event.snapshot.context,
113
+ type: AuthStateType.LOGGED_OUT
114
+ })
115
+ },
116
+ actions: [{ type: "clearAuth" }],
117
+ target: `.${AuthStateType.LOGGED_OUT}`
118
+ }
119
+ ]
120
+ },
121
+ states: {
122
+ init: {
123
+ tags: ["authenticating"],
124
+ after: {
125
+ authTimeout: {
126
+ actions: [
127
+ {
128
+ type: "setError",
129
+ params: () => ({
130
+ error: new Error("Authentication timed out")
131
+ })
132
+ }
133
+ ],
134
+ target: AuthStateType.ERROR
135
+ }
136
+ }
137
+ },
138
+ [AuthStateType.LOGGING_IN]: {
139
+ tags: ["authenticating"],
140
+ after: {
141
+ authTimeout: {
142
+ actions: [
143
+ {
144
+ type: "setError",
145
+ params: () => ({
146
+ error: new Error("Authentication timed out")
147
+ })
148
+ }
149
+ ],
150
+ target: AuthStateType.ERROR
151
+ }
152
+ }
153
+ },
154
+ [AuthStateType.LOGGED_IN]: {
155
+ tags: ["authenticated"],
156
+ on: {
157
+ "auth.logout": { target: "logging-out" }
158
+ }
159
+ },
160
+ "logging-out": {
161
+ invoke: {
162
+ src: "logoutActor",
163
+ input: ({ context }) => ({ instance: context.instance }),
164
+ onDone: {
165
+ target: AuthStateType.LOGGED_OUT
166
+ },
167
+ onError: {
168
+ actions: [
169
+ {
170
+ type: "setError",
171
+ params: ({ event }) => ({ error: event.error })
172
+ }
173
+ ],
174
+ target: AuthStateType.ERROR
175
+ }
176
+ }
177
+ },
178
+ [AuthStateType.LOGGED_OUT]: {},
179
+ [AuthStateType.ERROR]: { tags: ["error"] }
180
+ }
181
+ }), actorPath = (ref) => {
182
+ const segments = [];
183
+ let current = ref;
184
+ for (; current; )
185
+ segments.unshift(current.id ?? current.sessionId), current = current._parent;
186
+ return segments.join(":");
187
+ }, inspect = (event) => {
188
+ const ref = event.actorRef, log = logger.child(actorPath(ref));
189
+ switch (event.type) {
190
+ case "@xstate.snapshot": {
191
+ log.debug("snapshot", event.snapshot);
192
+ break;
193
+ }
194
+ case "@xstate.event":
195
+ log.debug("event", event.event);
196
+ break;
197
+ case "@xstate.action":
198
+ log.debug("action", event.action);
199
+ break;
200
+ }
201
+ }, DEFAULT_PREFERRED_COLOR_SCHEME = "system", DEFAULT_OS_COLOR_SCHEME = "light", resolveColorScheme = (preferred, osColorScheme) => preferred === "system" ? osColorScheme : preferred, adapterBridgeLogic = fromCallback(({ input: adapter, sendBack, receive }) => {
202
+ if (!adapter) return;
203
+ const unsubscribePreferredColorScheme = adapter.subscribePreferredColorScheme(
204
+ (next) => {
205
+ sendBack({
206
+ type: "preferredColorScheme.set",
207
+ preferredColorScheme: next ?? "system"
208
+ });
209
+ }
210
+ ), unsubscribeOs = adapter.subscribeOsColorScheme((next) => {
211
+ sendBack({ type: "osColorScheme.set", osColorScheme: next });
212
+ });
213
+ return receive((event) => {
214
+ adapter.getPreferredColorScheme() !== event.preferredColorScheme && adapter.persistPreferredColorScheme(event.preferredColorScheme);
215
+ }), () => {
216
+ unsubscribePreferredColorScheme(), unsubscribeOs();
217
+ };
218
+ }), systemPreferencesLogic = setup({
219
+ types: {
220
+ input: {},
221
+ context: {},
222
+ events: {}
223
+ },
224
+ actors: {
225
+ adapterBridge: adapterBridgeLogic
226
+ },
227
+ actions: {
228
+ setPreferredColorScheme: assign({
229
+ preferredColorScheme: (_, params) => params.preferredColorScheme,
230
+ colorScheme: ({ context }, params) => resolveColorScheme(params.preferredColorScheme, context.osColorScheme)
231
+ }),
232
+ setOsColorScheme: assign({
233
+ osColorScheme: (_, params) => params.osColorScheme,
234
+ colorScheme: ({ context }, params) => resolveColorScheme(context.preferredColorScheme, params.osColorScheme)
235
+ })
236
+ }
237
+ }).createMachine({
238
+ id: "system-preferences",
239
+ initial: "ready",
240
+ context: ({ input }) => {
241
+ const adapter = input.adapter, preferredColorScheme = adapter?.getPreferredColorScheme() ?? DEFAULT_PREFERRED_COLOR_SCHEME, osColorScheme = adapter?.getOsColorScheme() ?? DEFAULT_OS_COLOR_SCHEME;
242
+ return {
243
+ adapter,
244
+ preferredColorScheme,
245
+ osColorScheme,
246
+ colorScheme: resolveColorScheme(preferredColorScheme, osColorScheme)
247
+ };
248
+ },
249
+ invoke: {
250
+ id: "adapter",
251
+ src: "adapterBridge",
252
+ input: ({ context }) => context.adapter
253
+ },
254
+ states: {
255
+ ready: {
256
+ on: {
257
+ "preferredColorScheme.set": {
258
+ actions: [
259
+ {
260
+ type: "setPreferredColorScheme",
261
+ params: ({ event }) => ({
262
+ preferredColorScheme: event.preferredColorScheme
263
+ })
264
+ },
265
+ // Forward to the adapter bridge so it can persist the user's
266
+ // choice. The bridge guards against redundant writes, so
267
+ // round-tripping a `preferredColorScheme.set` it sourced itself
268
+ // (e.g. from a `storage` event in another tab) is a no-op.
269
+ sendTo("adapter", ({ event }) => event)
270
+ ]
271
+ },
272
+ "osColorScheme.set": {
273
+ actions: [
274
+ {
275
+ type: "setOsColorScheme",
276
+ params: ({ event }) => ({
277
+ osColorScheme: event.osColorScheme
278
+ })
279
+ }
280
+ ]
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }), TELEMETRY_API_VERSION = "2024-11-12", FLUSH_INTERVAL_MS = 3e4, checkConsentLogic = fromPromise(async ({ input, signal }) => {
286
+ try {
287
+ return await getClient(input.instance, {
288
+ apiVersion: TELEMETRY_API_VERSION
289
+ }).request({
290
+ uri: "/intake/telemetry-status",
291
+ tag: "telemetry-consent",
292
+ signal
293
+ });
294
+ } catch {
295
+ return { status: "undetermined" };
296
+ }
297
+ }), telemetryLogic = setup({
298
+ types: {
299
+ input: {},
300
+ context: {},
301
+ events: {}
302
+ },
303
+ actors: {
304
+ checkConsent: checkConsentLogic
305
+ },
306
+ guards: {
307
+ isConsentGranted: (_, params) => params.status === "granted"
308
+ },
309
+ actions: {
310
+ createStore: assign({
311
+ store: ({ context }) => {
312
+ const sessionId = createSessionId(), client = getClient(context.instance, {
313
+ apiVersion: TELEMETRY_API_VERSION
314
+ }), store = createBatchedStore(sessionId, {
315
+ flushInterval: FLUSH_INTERVAL_MS,
316
+ resolveConsent: () => client.request({
317
+ uri: "/intake/telemetry-status",
318
+ tag: "telemetry-consent"
319
+ }),
320
+ sendEvents: (batch) => client.request({
321
+ uri: "/intake/batch",
322
+ method: "POST",
323
+ body: { batch },
324
+ tag: "telemetry.batch"
325
+ }),
326
+ sendBeacon: (batch) => typeof navigator > "u" ? !1 : navigator.sendBeacon(
327
+ client.getUrl("/intake/batch"),
328
+ JSON.stringify({ batch })
329
+ )
330
+ });
331
+ return store.logger.updateUserProperties(context.userProperties), store;
332
+ }
333
+ }),
334
+ teardownStore: ({ context }) => {
335
+ context.store?.end();
336
+ }
337
+ }
338
+ }).createMachine({
339
+ id: "telemetry",
340
+ initial: "idle",
341
+ context: ({ input }) => ({
342
+ instance: input.instance,
343
+ store: null,
344
+ userProperties: {
345
+ version: input.version,
346
+ organizationId: input.organizationId,
347
+ environment: input.environment,
348
+ userAgent: input.userAgent
349
+ }
350
+ }),
351
+ states: {
352
+ idle: {
353
+ on: {
354
+ "telemetry.start": {
355
+ target: "checkingConsent"
356
+ }
357
+ }
358
+ },
359
+ checkingConsent: {
360
+ invoke: {
361
+ src: "checkConsent",
362
+ input: ({ context }) => ({
363
+ instance: context.instance
364
+ }),
365
+ onDone: [
366
+ {
367
+ guard: {
368
+ type: "isConsentGranted",
369
+ params: ({ event }) => ({
370
+ status: event.output.status
371
+ })
372
+ },
373
+ actions: [{ type: "createStore" }],
374
+ target: "active"
375
+ },
376
+ {
377
+ target: "denied"
378
+ }
379
+ ]
380
+ }
381
+ },
382
+ active: {
383
+ tags: ["telemetry-resolved"],
384
+ exit: [{ type: "teardownStore" }],
385
+ on: {
386
+ "telemetry.stop": { target: "stopped" }
387
+ }
388
+ },
389
+ stopped: {
390
+ type: "final"
391
+ },
392
+ denied: {
393
+ tags: ["telemetry-resolved"]
394
+ }
395
+ }
396
+ }), os = setup({
397
+ types: {
398
+ input: {},
399
+ context: {},
400
+ events: {},
401
+ // https://github.com/statelyai/xstate/issues/5515
402
+ children: {}
403
+ },
404
+ actors: {
405
+ auth: authLogic,
406
+ telemetry: telemetryLogic,
407
+ systemPreferences: systemPreferencesLogic
408
+ },
409
+ guards: {
410
+ hasTag: (_, params) => params.hasTag
411
+ },
412
+ actions: {
413
+ raiseAuthReady: raise({ type: "boot.auth.ready" }),
414
+ raiseAuthFailed: raise({ type: "boot.auth.failed" }),
415
+ raiseTelemetryReady: raise({
416
+ type: "boot.telemetry.ready"
417
+ }),
418
+ startTelemetry: sendTo("telemetry", {
419
+ type: "telemetry.start"
420
+ })
421
+ }
422
+ }).createMachine({
423
+ id: "os",
424
+ context: ({ input }) => ({
425
+ instance: createSanityInstance(),
426
+ userProperties: {
427
+ version: input.version,
428
+ organizationId: input.organizationId,
429
+ environment: input.environment,
430
+ userAgent: input.userAgent
431
+ },
432
+ systemPreferencesAdapter: input.systemPreferencesAdapter
433
+ }),
434
+ initial: "booting",
435
+ invoke: [
436
+ {
437
+ id: "auth",
438
+ systemId: "auth",
439
+ src: "auth",
440
+ input: ({ context }) => ({ instance: context.instance }),
441
+ onSnapshot: [
442
+ {
443
+ guard: {
444
+ type: "hasTag",
445
+ params: ({ event }) => ({
446
+ hasTag: event.snapshot.hasTag("authenticated")
447
+ })
448
+ },
449
+ actions: [{ type: "raiseAuthReady" }]
450
+ },
451
+ {
452
+ guard: {
453
+ type: "hasTag",
454
+ params: ({ event }) => ({
455
+ hasTag: event.snapshot.hasTag("error")
456
+ })
457
+ },
458
+ actions: [{ type: "raiseAuthFailed" }]
459
+ }
460
+ ]
461
+ },
462
+ {
463
+ id: "telemetry",
464
+ systemId: "telemetry",
465
+ src: "telemetry",
466
+ input: ({ context }) => ({
467
+ instance: context.instance,
468
+ ...context.userProperties
469
+ }),
470
+ onSnapshot: [
471
+ {
472
+ guard: {
473
+ type: "hasTag",
474
+ params: ({ event }) => ({
475
+ hasTag: event.snapshot.hasTag("telemetry-resolved")
476
+ })
477
+ },
478
+ actions: [{ type: "raiseTelemetryReady" }]
479
+ }
480
+ ]
481
+ },
482
+ {
483
+ id: "system-preferences",
484
+ systemId: "system-preferences",
485
+ src: "systemPreferences",
486
+ input: ({ context }) => ({ adapter: context.systemPreferencesAdapter })
487
+ }
488
+ ],
489
+ states: {
490
+ booting: {
491
+ initial: "auth",
492
+ states: {
493
+ auth: {
494
+ on: {
495
+ "boot.auth.ready": {
496
+ target: "telemetry",
497
+ actions: [{ type: "startTelemetry" }]
498
+ },
499
+ "boot.auth.failed": { target: "error" }
500
+ }
501
+ },
502
+ telemetry: {
503
+ on: {
504
+ "boot.telemetry.ready": { target: "done" }
505
+ }
506
+ },
507
+ error: {},
508
+ done: { type: "final" }
509
+ },
510
+ onDone: { target: "running" }
511
+ },
512
+ running: {
513
+ type: "parallel"
514
+ }
515
+ }
516
+ });
517
+ function createOSOptions(input) {
518
+ return {
519
+ id: "os",
520
+ input,
521
+ inspect
522
+ };
523
+ }
524
+ export {
525
+ createOSOptions,
526
+ os
527
+ };
528
+ //# sourceMappingURL=system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.js","sources":["../src/system/auth.machine.ts","../src/system/inspect.ts","../src/system/system-preferences.machine.ts","../src/system/telemetry.machine.ts","../src/system/root.machine.ts"],"sourcesContent":["import {\n type AuthState,\n AuthStateType,\n type CurrentUser,\n getAuthState,\n type LoggedInAuthState,\n logout,\n type SanityInstance,\n} from \"@sanity/sdk\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport type { OSBaseInput } from \"./root.machine\";\n\n/**\n * @internal\n */\nexport interface AuthInput extends OSBaseInput {}\n\nconst authStateLogic = fromObservable<AuthState, AuthInput>(\n ({ input }) => getAuthState(input.instance).observable,\n);\n\n/**\n * @internal\n */\nexport interface LogoutInput extends OSBaseInput {}\n\nconst logoutActorLogic = fromPromise<void, LogoutInput>(async ({ input }) => {\n await logout(input.instance);\n});\n\ntype AuthContext = {\n instance: SanityInstance;\n token: string | null;\n currentUser: CurrentUser | null;\n error: unknown;\n};\n\ntype AuthEvent = { type: \"auth.logout\" };\n\nexport const authLogic = setup({\n types: {\n input: {} as AuthInput,\n context: {} as AuthContext,\n events: {} as AuthEvent,\n tags: {} as \"authenticating\" | \"authenticated\" | \"error\",\n },\n actors: {\n authState: authStateLogic,\n logoutActor: logoutActorLogic,\n },\n delays: {\n authTimeout: 30_000,\n },\n guards: {\n isLoggedInComplete: (_, params: { state: AuthState | undefined }) =>\n params.state?.type === AuthStateType.LOGGED_IN &&\n Boolean((params.state as LoggedInAuthState).token) &&\n (params.state as LoggedInAuthState).currentUser !== null,\n isAuthState: (\n _,\n params: { state: AuthState | undefined; type: AuthStateType },\n ) => params.state?.type === params.type,\n },\n actions: {\n setLoggedIn: assign({\n token: (_, params: { token: string; currentUser: CurrentUser }) =>\n params.token,\n currentUser: (_, params: { token: string; currentUser: CurrentUser }) =>\n params.currentUser,\n error: () => null,\n }),\n clearAuth: assign({\n token: () => null,\n currentUser: () => null,\n error: () => null,\n }),\n setError: assign({\n token: () => null,\n currentUser: () => null,\n error: (_, params: { error: unknown }) => params.error,\n }),\n },\n}).createMachine({\n id: \"auth\",\n initial: \"init\",\n context: ({ input }) => ({\n instance: input.instance,\n token: null,\n currentUser: null,\n error: null,\n }),\n invoke: {\n src: \"authState\",\n input: ({ context }) => ({ instance: context.instance }),\n onSnapshot: [\n {\n guard: {\n type: \"isLoggedInComplete\",\n params: ({ event }) => ({\n state: event.snapshot.context,\n }),\n },\n actions: [\n {\n type: \"setLoggedIn\",\n params: ({ event }) => {\n const state = event.snapshot.context as LoggedInAuthState;\n return {\n token: state.token,\n currentUser: state.currentUser!,\n };\n },\n },\n ],\n target: `.${AuthStateType.LOGGED_IN}`,\n },\n {\n guard: {\n type: \"isAuthState\",\n params: ({ event }) => ({\n state: event.snapshot.context,\n type: AuthStateType.LOGGING_IN,\n }),\n },\n actions: [{ type: \"clearAuth\" }],\n target: `.${AuthStateType.LOGGING_IN}`,\n },\n {\n guard: {\n type: \"isAuthState\",\n params: ({ event }) => ({\n state: event.snapshot.context,\n type: AuthStateType.ERROR,\n }),\n },\n actions: [\n {\n type: \"setError\",\n params: ({ event }) => ({\n error:\n event.snapshot.context?.type === AuthStateType.ERROR\n ? event.snapshot.context.error\n : null,\n }),\n },\n ],\n target: `.${AuthStateType.ERROR}`,\n },\n {\n guard: {\n type: \"isAuthState\",\n params: ({ event }) => ({\n state: event.snapshot.context,\n type: AuthStateType.LOGGED_OUT,\n }),\n },\n actions: [{ type: \"clearAuth\" }],\n target: `.${AuthStateType.LOGGED_OUT}`,\n },\n ],\n },\n states: {\n init: {\n tags: [\"authenticating\"],\n after: {\n authTimeout: {\n actions: [\n {\n type: \"setError\",\n params: () => ({\n error: new Error(\"Authentication timed out\"),\n }),\n },\n ],\n target: AuthStateType.ERROR,\n },\n },\n },\n [AuthStateType.LOGGING_IN]: {\n tags: [\"authenticating\"],\n after: {\n authTimeout: {\n actions: [\n {\n type: \"setError\",\n params: () => ({\n error: new Error(\"Authentication timed out\"),\n }),\n },\n ],\n target: AuthStateType.ERROR,\n },\n },\n },\n [AuthStateType.LOGGED_IN]: {\n tags: [\"authenticated\"],\n on: {\n \"auth.logout\": { target: \"logging-out\" },\n },\n },\n [\"logging-out\"]: {\n invoke: {\n src: \"logoutActor\",\n input: ({ context }) => ({ instance: context.instance }),\n onDone: {\n target: AuthStateType.LOGGED_OUT,\n },\n onError: {\n actions: [\n {\n type: \"setError\",\n params: ({ event }) => ({ error: event.error }),\n },\n ],\n target: AuthStateType.ERROR,\n },\n },\n },\n [AuthStateType.LOGGED_OUT]: {},\n [AuthStateType.ERROR]: { tags: [\"error\"] },\n },\n});\n","import { type ActorRefLike, type InspectionEvent } from \"xstate\";\n\nimport { logger } from \"../core\";\n\n// Mirrors @statelyai/inspect's ActorRefLikeWithData — the inspect\n// callback receives full Actor instances at runtime, but the type is\n// narrowed for @xstate/store compat.\ntype ActorRefWithAncestry = ActorRefLike & {\n id?: string;\n _parent?: ActorRefWithAncestry;\n};\n\nconst actorPath = (ref: ActorRefWithAncestry): string => {\n const segments: string[] = [];\n let current: ActorRefWithAncestry | undefined = ref;\n while (current) {\n segments.unshift(current.id ?? current.sessionId);\n current = current._parent;\n }\n return segments.join(\":\");\n};\n\n/** @internal exported for testing */\nexport const inspect = (event: InspectionEvent): void => {\n const ref = event.actorRef as ActorRefWithAncestry;\n const log = logger.child(actorPath(ref));\n\n switch (event.type) {\n case \"@xstate.snapshot\": {\n log.debug(\"snapshot\", event.snapshot);\n break;\n }\n case \"@xstate.event\":\n log.debug(\"event\", event.event);\n break;\n case \"@xstate.action\":\n log.debug(\"action\", event.action);\n break;\n }\n};\n","import { assign, fromCallback, sendTo, setup } from \"xstate\";\n\ntype ColorScheme = \"light\" | \"dark\";\n\ntype ColorSchemePreference = \"system\" | ColorScheme;\n\n/**\n * The system-preferences machine's context. Consumers read fields directly\n * (e.g. via `useSelector`) rather than going through a resolver utility —\n * the action handlers keep `colorScheme` in sync with `preferredColorScheme`\n * and `osColorScheme`.\n *\n * Note: `colorScheme` is intentionally stored as derived state in context so\n * consumers can read the resolved value directly without a utility. The\n * action handlers below are the single source of truth for the resolution.\n * @public\n */\nexport type SystemPreferencesContext = {\n /** User's color scheme choice; `system` defers to the OS preference. */\n preferredColorScheme: ColorSchemePreference;\n /** Last reported OS color scheme. Used to resolve `colorScheme` when the\n * preference is `system`. */\n osColorScheme: ColorScheme;\n /** Resolved color scheme — what the UI should render. Recomputed by the\n * action handlers whenever an input changes. */\n colorScheme: ColorScheme;\n};\n\nconst DEFAULT_PREFERRED_COLOR_SCHEME: ColorSchemePreference = \"system\";\nconst DEFAULT_OS_COLOR_SCHEME: ColorScheme = \"light\";\n\n/**\n * Events the system-preferences machine accepts. Both originate from the\n * host's adapter — `preferredColorScheme.set` is also forwarded back to it\n * so it can persist the user's choice.\n * @public\n */\nexport type SystemPreferencesEvent =\n | {\n type: \"preferredColorScheme.set\";\n preferredColorScheme: ColorSchemePreference;\n }\n | {\n type: \"osColorScheme.set\";\n osColorScheme: ColorScheme;\n };\n\n/**\n * Adapter interface the host implements to give the system-preferences\n * machine access to the user's environment (OS color scheme, persistent\n * storage, cross-context change notifications).\n *\n * The package owns all orchestration — synchronous seeding, idempotent\n * persistence, mapping cleared storage to `\"system\"`. The host's\n * implementation is pure DOM/storage glue: read, write, subscribe.\n * @public\n */\nexport type SystemPreferencesAdapter = {\n /** Read the user's stored preference. `null` means \"no preference set\"\n * (the machine treats this as `\"system\"`). */\n getPreferredColorScheme: () => ColorSchemePreference | null;\n /** Write the user's preference to persistent storage. */\n persistPreferredColorScheme: (value: ColorSchemePreference) => void;\n /** Subscribe to cross-context preference changes (e.g. another tab\n * writing to the shared storage). The callback receives the new stored\n * value (or `null` if it was cleared). Returns an unsubscribe function. */\n subscribePreferredColorScheme: (\n callback: (next: ColorSchemePreference | null) => void,\n ) => () => void;\n /** Read the current OS-detected color scheme. */\n getOsColorScheme: () => ColorScheme;\n /** Subscribe to OS color-scheme changes (e.g. user flipping dark mode).\n * Returns an unsubscribe function. */\n subscribeOsColorScheme: (callback: (next: ColorScheme) => void) => () => void;\n};\n\nconst resolveColorScheme = (\n preferred: ColorSchemePreference,\n osColorScheme: ColorScheme,\n): ColorScheme => (preferred === \"system\" ? osColorScheme : preferred);\n\n// Internal bridge actor — subscribes to the host's adapter for runtime\n// changes and persists user-driven preference changes when the parent\n// forwards them. No-op if the host didn't pass an adapter (SSR, tests).\ntype AdapterBridgeReceiveEvent = Extract<\n SystemPreferencesEvent,\n { type: \"preferredColorScheme.set\" }\n>;\n\nconst adapterBridgeLogic = fromCallback<\n AdapterBridgeReceiveEvent,\n SystemPreferencesAdapter | undefined,\n SystemPreferencesEvent\n>(({ input: adapter, sendBack, receive }) => {\n if (!adapter) return;\n\n const unsubscribePreferredColorScheme = adapter.subscribePreferredColorScheme(\n (next) => {\n // Falls back to `\"system\"` so an external clear (another tab deleting\n // the key) resets the preference rather than silently keeping the\n // previous value.\n sendBack({\n type: \"preferredColorScheme.set\",\n preferredColorScheme: next ?? \"system\",\n });\n },\n );\n\n const unsubscribeOs = adapter.subscribeOsColorScheme((next) => {\n sendBack({ type: \"osColorScheme.set\", osColorScheme: next });\n });\n\n receive((event) => {\n // Idempotent: skip writes that match the current stored value so a\n // `preferredColorScheme.set` originating from cross-context change\n // doesn't loop back into another write.\n if (adapter.getPreferredColorScheme() === event.preferredColorScheme)\n return;\n\n adapter.persistPreferredColorScheme(event.preferredColorScheme);\n });\n\n return () => {\n unsubscribePreferredColorScheme();\n unsubscribeOs();\n };\n});\n\n/**\n * @internal\n */\nexport const systemPreferencesLogic = setup({\n types: {\n input: {} as { adapter?: SystemPreferencesAdapter },\n context: {} as SystemPreferencesContext & {\n adapter: SystemPreferencesAdapter | undefined;\n },\n events: {} as SystemPreferencesEvent,\n },\n actors: {\n adapterBridge: adapterBridgeLogic,\n },\n actions: {\n setPreferredColorScheme: assign({\n preferredColorScheme: (\n _,\n params: { preferredColorScheme: ColorSchemePreference },\n ) => params.preferredColorScheme,\n colorScheme: (\n { context },\n params: { preferredColorScheme: ColorSchemePreference },\n ) =>\n resolveColorScheme(params.preferredColorScheme, context.osColorScheme),\n }),\n setOsColorScheme: assign({\n osColorScheme: (_, params: { osColorScheme: ColorScheme }) =>\n params.osColorScheme,\n colorScheme: ({ context }, params: { osColorScheme: ColorScheme }) =>\n resolveColorScheme(context.preferredColorScheme, params.osColorScheme),\n }),\n },\n}).createMachine({\n id: \"system-preferences\",\n initial: \"ready\",\n context: ({ input }) => {\n const adapter = input.adapter;\n const preferredColorScheme =\n adapter?.getPreferredColorScheme() ?? DEFAULT_PREFERRED_COLOR_SCHEME;\n const osColorScheme =\n adapter?.getOsColorScheme() ?? DEFAULT_OS_COLOR_SCHEME;\n\n return {\n adapter,\n preferredColorScheme,\n osColorScheme,\n colorScheme: resolveColorScheme(preferredColorScheme, osColorScheme),\n };\n },\n invoke: {\n id: \"adapter\",\n src: \"adapterBridge\",\n input: ({ context }) => context.adapter,\n },\n states: {\n ready: {\n on: {\n \"preferredColorScheme.set\": {\n actions: [\n {\n type: \"setPreferredColorScheme\",\n params: ({ event }) => ({\n preferredColorScheme: event.preferredColorScheme,\n }),\n },\n // Forward to the adapter bridge so it can persist the user's\n // choice. The bridge guards against redundant writes, so\n // round-tripping a `preferredColorScheme.set` it sourced itself\n // (e.g. from a `storage` event in another tab) is a no-op.\n sendTo(\"adapter\", ({ event }) => event),\n ],\n },\n \"osColorScheme.set\": {\n actions: [\n {\n type: \"setOsColorScheme\",\n params: ({ event }) => ({\n osColorScheme: event.osColorScheme,\n }),\n },\n ],\n },\n },\n },\n },\n});\n","import { getClient, type SanityInstance } from \"@sanity/sdk\";\nimport {\n type ConsentStatus,\n createBatchedStore,\n createSessionId,\n type TelemetryEvent,\n type TelemetryStore,\n} from \"@sanity/telemetry\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport type { OSBaseInput } from \"./root.machine\";\n\n/**\n * @public\n */\nexport type WorkbenchUserProperties = {\n version: string;\n organizationId: string;\n environment: string;\n userAgent: string;\n};\n\n/**\n * @internal\n */\nexport interface TelemetryInput extends OSBaseInput, WorkbenchUserProperties {}\n\n/**\n * TODO: this shouldn't be unique to the telemetry machine,\n * remove this and set it globally with a single client actor.\n */\nconst TELEMETRY_API_VERSION = \"2024-11-12\";\n/**\n * 30 seconds, in milliseconds, is the default flush interval\n * for the telemetry store.\n */\nconst FLUSH_INTERVAL_MS = 30_000;\n\ntype ConsentResult = { status: ConsentStatus };\n\nconst checkConsentLogic = fromPromise<\n ConsentResult,\n { instance: SanityInstance }\n>(async ({ input, signal }) => {\n try {\n const client = getClient(input.instance, {\n apiVersion: TELEMETRY_API_VERSION,\n });\n return await client.request<ConsentResult>({\n uri: \"/intake/telemetry-status\",\n tag: \"telemetry-consent\",\n signal,\n });\n } catch {\n return { status: \"undetermined\" } satisfies ConsentResult;\n }\n});\n\ntype TelemetryContext = {\n instance: SanityInstance;\n store: TelemetryStore<WorkbenchUserProperties> | null;\n userProperties: WorkbenchUserProperties;\n};\n\ntype TelemetryMachineEvent =\n | { type: \"telemetry.start\" }\n | { type: \"telemetry.stop\" };\n\nexport const telemetryLogic = setup({\n types: {\n input: {} as TelemetryInput,\n context: {} as TelemetryContext,\n events: {} as TelemetryMachineEvent,\n },\n actors: {\n checkConsent: checkConsentLogic,\n },\n guards: {\n isConsentGranted: (_, params: { status: ConsentStatus }) =>\n params.status === \"granted\",\n },\n actions: {\n createStore: assign({\n store: ({ context }) => {\n const sessionId = createSessionId();\n const client = getClient(context.instance, {\n apiVersion: TELEMETRY_API_VERSION,\n });\n const store = createBatchedStore<WorkbenchUserProperties>(sessionId, {\n flushInterval: FLUSH_INTERVAL_MS,\n resolveConsent: () =>\n client.request<{ status: ConsentStatus }>({\n uri: \"/intake/telemetry-status\",\n tag: \"telemetry-consent\",\n }),\n sendEvents: (batch: TelemetryEvent[]) =>\n client.request({\n uri: \"/intake/batch\",\n method: \"POST\",\n body: { batch },\n tag: \"telemetry.batch\",\n }),\n sendBeacon: (batch: TelemetryEvent[]) => {\n if (typeof navigator === \"undefined\") {\n return false;\n }\n return navigator.sendBeacon(\n client.getUrl(\"/intake/batch\"),\n JSON.stringify({ batch }),\n );\n },\n });\n store.logger.updateUserProperties(context.userProperties);\n return store;\n },\n }),\n teardownStore: ({ context }) => {\n context.store?.end();\n },\n },\n}).createMachine({\n id: \"telemetry\",\n initial: \"idle\",\n context: ({ input }) => ({\n instance: input.instance,\n store: null,\n userProperties: {\n version: input.version,\n organizationId: input.organizationId,\n environment: input.environment,\n userAgent: input.userAgent,\n },\n }),\n states: {\n idle: {\n on: {\n \"telemetry.start\": {\n target: \"checkingConsent\",\n },\n },\n },\n checkingConsent: {\n invoke: {\n src: \"checkConsent\",\n input: ({ context }) => ({\n instance: context.instance,\n }),\n onDone: [\n {\n guard: {\n type: \"isConsentGranted\",\n params: ({ event }) => ({\n status: event.output.status,\n }),\n },\n actions: [{ type: \"createStore\" }],\n target: \"active\",\n },\n {\n target: \"denied\",\n },\n ],\n },\n },\n active: {\n tags: [\"telemetry-resolved\"],\n exit: [{ type: \"teardownStore\" }],\n on: {\n \"telemetry.stop\": { target: \"stopped\" },\n },\n },\n stopped: {\n type: \"final\",\n },\n denied: {\n tags: [\"telemetry-resolved\"],\n },\n },\n});\n","import { createSanityInstance, type SanityInstance } from \"@sanity/sdk\";\nimport { raise, sendTo, setup, type ActorOptions } from \"xstate\";\n\nimport { authLogic } from \"./auth.machine\";\nimport { inspect } from \"./inspect\";\nimport {\n type SystemPreferencesAdapter,\n systemPreferencesLogic,\n} from \"./system-preferences.machine\";\nimport {\n telemetryLogic,\n type WorkbenchUserProperties,\n} from \"./telemetry.machine\";\n\ntype OSInput = WorkbenchUserProperties & {\n systemPreferencesAdapter?: SystemPreferencesAdapter;\n};\n\ntype OSContext = {\n instance: SanityInstance;\n userProperties: WorkbenchUserProperties;\n systemPreferencesAdapter: SystemPreferencesAdapter | undefined;\n};\n\n/**\n * The base inputs for the OS machine.\n * @internal\n */\nexport interface OSBaseInput extends Pick<OSContext, \"instance\"> {}\n\n/**\n * The sanity OS machine, responsible for managing the global state of the OS.\n * @public\n * @example\n * ```ts\n * import { os, createOSOptions } from \"@sanity/workbench/system\";\n * import { useActor } from \"@xstate/react\";\n *\n * const [state, send] = useActor(os, createOSOptions({\n * version: \"1.0.0\",\n * organizationId: \"...\",\n * environment: \"production\",\n * userAgent: navigator.userAgent,\n * }));\n * ```\n */\nexport const os = setup({\n types: {\n input: {} as OSInput,\n context: {} as OSContext,\n events: {} as\n | { type: \"boot.auth.ready\" }\n | { type: \"boot.auth.failed\" }\n | { type: \"boot.telemetry.ready\" },\n // https://github.com/statelyai/xstate/issues/5515\n children: {} as {\n auth: \"auth\";\n telemetry: \"telemetry\";\n \"system-preferences\": \"systemPreferences\";\n },\n },\n actors: {\n auth: authLogic,\n telemetry: telemetryLogic,\n systemPreferences: systemPreferencesLogic,\n },\n guards: {\n hasTag: (_, params: { hasTag: boolean }) => params.hasTag,\n },\n actions: {\n raiseAuthReady: raise({ type: \"boot.auth.ready\" }),\n raiseAuthFailed: raise({ type: \"boot.auth.failed\" }),\n raiseTelemetryReady: raise({\n type: \"boot.telemetry.ready\",\n }),\n startTelemetry: sendTo(\"telemetry\", {\n type: \"telemetry.start\",\n }),\n },\n}).createMachine({\n id: \"os\",\n context: ({ input }) => ({\n instance: createSanityInstance(),\n userProperties: {\n version: input.version,\n organizationId: input.organizationId,\n environment: input.environment,\n userAgent: input.userAgent,\n },\n systemPreferencesAdapter: input.systemPreferencesAdapter,\n }),\n initial: \"booting\",\n invoke: [\n {\n id: \"auth\",\n systemId: \"auth\",\n src: \"auth\",\n input: ({ context }) => ({ instance: context.instance }),\n onSnapshot: [\n {\n guard: {\n type: \"hasTag\",\n params: ({ event }) => ({\n hasTag: event.snapshot.hasTag(\"authenticated\"),\n }),\n },\n actions: [{ type: \"raiseAuthReady\" }],\n },\n {\n guard: {\n type: \"hasTag\",\n params: ({ event }) => ({\n hasTag: event.snapshot.hasTag(\"error\"),\n }),\n },\n actions: [{ type: \"raiseAuthFailed\" }],\n },\n ],\n },\n {\n id: \"telemetry\",\n systemId: \"telemetry\",\n src: \"telemetry\",\n input: ({ context }) => ({\n instance: context.instance,\n ...context.userProperties,\n }),\n onSnapshot: [\n {\n guard: {\n type: \"hasTag\",\n params: ({ event }) => ({\n hasTag: event.snapshot.hasTag(\"telemetry-resolved\"),\n }),\n },\n actions: [{ type: \"raiseTelemetryReady\" }],\n },\n ],\n },\n {\n id: \"system-preferences\",\n systemId: \"system-preferences\",\n src: \"systemPreferences\",\n input: ({ context }) => ({ adapter: context.systemPreferencesAdapter }),\n },\n ],\n states: {\n booting: {\n initial: \"auth\",\n states: {\n auth: {\n on: {\n \"boot.auth.ready\": {\n target: \"telemetry\",\n actions: [{ type: \"startTelemetry\" }],\n },\n \"boot.auth.failed\": { target: \"error\" },\n },\n },\n telemetry: {\n on: {\n \"boot.telemetry.ready\": { target: \"done\" },\n },\n },\n error: {},\n done: { type: \"final\" },\n },\n onDone: { target: \"running\" },\n },\n running: {\n type: \"parallel\",\n },\n },\n});\n\n/**\n * Creates a set of default options for the OS machine. Forwards the workbench\n * user properties to the machine's input and wires the structured-logging\n * `inspect` callback. Browser-specific concerns (color-scheme seeding,\n * persistence) live in the {@link SystemPreferencesAdapter} the host passes\n * via `systemPreferencesAdapter`.\n * @public\n */\nexport function createOSOptions(input: OSInput) {\n return {\n id: \"os\",\n input,\n inspect,\n } satisfies ActorOptions<typeof os>;\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,iBAAiB;AAAA,EACrB,CAAC,EAAE,MAAA,MAAY,aAAa,MAAM,QAAQ,EAAE;AAC9C,GAOM,mBAAmB,YAA+B,OAAO,EAAE,YAAY;AAC3E,QAAM,OAAO,MAAM,QAAQ;AAC7B,CAAC,GA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AAA,QACxC;AAAA,QAEF,WAAW;AAAA,UACT,IAAI;AAAA,YACF,wBAAwB,EAAE,QAAQ,OAAA;AAAA,UAAO;AAAA,QAC3C;AAAA,QAEF,OAAO,CAAA;AAAA,QACP,MAAM,EAAE,MAAM,QAAA;AAAA,MAAQ;AAAA,MAExB,QAAQ,EAAE,QAAQ,UAAA;AAAA,IAAU;AAAA,IAE9B,SAAS;AAAA,MACP,MAAM;AAAA,IAAA;AAAA,EACR;AAEJ,CAAC;AAUM,SAAS,gBAAgB,OAAgB;AAC9C,SAAO;AAAA,IACL,IAAI;AAAA,IACJ;AAAA,IACA;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/workbench",
3
- "version": "0.1.0-alpha.12",
3
+ "version": "0.1.0-alpha.14",
4
4
  "description": "Workbench component for the Sanity Content Operating System",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/sanity-io/workbench/packages/@sanity/workbench#readme",
@@ -34,23 +34,34 @@
34
34
  "development": "./src/_exports/core.ts",
35
35
  "default": "./dist/core.js"
36
36
  },
37
+ "./system": {
38
+ "source": "./src/_exports/system.ts",
39
+ "development": "./src/_exports/system.ts",
40
+ "default": "./dist/system.js"
41
+ },
37
42
  "./package.json": "./package.json"
38
43
  },
39
44
  "dependencies": {
40
45
  "@sanity/message-protocol": "^0.23.0",
46
+ "@sanity/telemetry": "^1.1.0",
41
47
  "rxjs": "^7.8.2",
42
48
  "semver": "^7.7.4",
49
+ "xstate": "^5.31.0",
43
50
  "zod": "^4.3.6",
44
51
  "@sanity/federation": "0.1.0-alpha.7"
45
52
  },
46
53
  "devDependencies": {
47
54
  "@sanity/pkg-utils": "^9.2.3",
55
+ "@sanity/sdk": "https://pkg.pr.new/sanity-io/sdk/@sanity/sdk@fbc9e08",
48
56
  "@types/semver": "^7.7.1",
49
57
  "typescript": "^6.0.2",
50
58
  "vite": "^7.3.1",
51
59
  "@repo/oxc-config": "0.0.0",
52
60
  "@repo/tsconfig": "0.0.1"
53
61
  },
62
+ "peerDependencies": {
63
+ "@sanity/sdk": "^2.9.0"
64
+ },
54
65
  "browserslist": "extends @sanity/browserslist-config",
55
66
  "engines": {
56
67
  "node": ">=20.19.1 <22 || >=22.12"
@@ -0,0 +1 @@
1
+ export * from "../system";