@sanity/sdk 3.4.0-rc.0 → 3.4.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.
Files changed (48) hide show
  1. package/dist/_exports/_internal.d.ts +3 -3
  2. package/dist/_exports/_internal.js +5 -5
  3. package/dist/_exports/agent.d.ts +1 -1
  4. package/dist/_exports/agent.js +1 -1
  5. package/dist/_exports/comlink.d.ts +1 -1
  6. package/dist/_exports/dashboard.d.ts +2 -2
  7. package/dist/_exports/dashboard.js +2 -2
  8. package/dist/{applications-903KQTrD.d.ts → applications-Bb-0Kgkc.d.ts} +6 -20
  9. package/dist/applications-Bb-0Kgkc.d.ts.map +1 -0
  10. package/dist/{clientStore-QDrJNTM4.js → clientStore-CD-USpIU.js} +11 -15
  11. package/dist/clientStore-CD-USpIU.js.map +1 -0
  12. package/dist/{createSanityInstance--Lrldto8.d.ts → createSanityInstance-BQIqyGLX.d.ts} +3 -6
  13. package/dist/createSanityInstance-BQIqyGLX.d.ts.map +1 -0
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +204 -211
  16. package/dist/index.js.map +1 -1
  17. package/dist/{topicStore-BJ54_X6H.js → topicStore-CPhGph6z.js} +53 -13
  18. package/dist/topicStore-CPhGph6z.js.map +1 -0
  19. package/dist/{topicStore-VQILEI1R.d.ts → topicStore-fPK2CfqH.d.ts} +91 -4
  20. package/dist/topicStore-fPK2CfqH.d.ts.map +1 -0
  21. package/dist/{version-CYqZgJX1.js → version-C7m7OAy9.js} +3 -3
  22. package/dist/{version-CYqZgJX1.js.map → version-C7m7OAy9.js.map} +1 -1
  23. package/package.json +6 -6
  24. package/src/_exports/dashboard.ts +6 -0
  25. package/src/auth/authStore.test.ts +0 -18
  26. package/src/auth/authStore.ts +1 -4
  27. package/src/auth/handleAuthCallback.test.ts +0 -33
  28. package/src/auth/handleAuthCallback.ts +1 -11
  29. package/src/auth/logout.test.ts +1 -9
  30. package/src/auth/logout.ts +1 -18
  31. package/src/auth/oauth/oauthActions.test.ts +1 -178
  32. package/src/auth/oauth/oauthActions.ts +46 -111
  33. package/src/auth/oauth/oauthAuth.test.ts +0 -23
  34. package/src/auth/oauth/oauthAuth.ts +8 -18
  35. package/src/config/authConfig.ts +2 -5
  36. package/src/dashboard/messageBus/bus.test.ts +118 -0
  37. package/src/dashboard/messageBus/bus.ts +81 -7
  38. package/src/dashboard/messageBus/topics.test.ts +20 -0
  39. package/src/dashboard/messageBus/topics.ts +74 -0
  40. package/src/document/documentConstants.ts +5 -2
  41. package/src/document/documentStore.test.ts +194 -0
  42. package/src/document/documentStore.ts +79 -39
  43. package/src/document/reducers.ts +2 -2
  44. package/dist/applications-903KQTrD.d.ts.map +0 -1
  45. package/dist/clientStore-QDrJNTM4.js.map +0 -1
  46. package/dist/createSanityInstance--Lrldto8.d.ts.map +0 -1
  47. package/dist/topicStore-BJ54_X6H.js.map +0 -1
  48. package/dist/topicStore-VQILEI1R.d.ts.map +0 -1
@@ -3,15 +3,30 @@ import { n as setCleanupTimeout } from "./setCleanupTimeout-BiM6q1KF.js";
3
3
  import { t as _defineProperty } from "./defineProperty-Bho9Ngsi.js";
4
4
  import { BehaviorSubject, ReplaySubject, Subject, concat, defer, filter, firstValueFrom, from, map, takeUntil } from "rxjs";
5
5
  import "@sanity/types";
6
- const stateTopic = (seed) => ({
6
+ /**
7
+ * The capabilities a host can provide.
8
+ *
9
+ * Reuses the Studio's rendering-context identifiers so an application can hide its own
10
+ * implementation of anything the host provides.
11
+ * @public
12
+ */
13
+ const capabilities = [
14
+ "globalUserMenu",
15
+ "favorites",
16
+ "history"
17
+ ], stateTopic = (seed) => ({
7
18
  kind: "state",
8
19
  seed
9
20
  }), dashboardEvent = {
10
21
  kind: "event",
11
22
  ownership: { type: "same_app" }
12
23
  }, DASHBOARD_TOPIC_MANIFEST = {
24
+ "applications.activity": dashboardEvent,
13
25
  "applications.base-path": stateTopic(void 0),
26
+ "applications.capabilities": stateTopic(void 0),
14
27
  "applications.config": stateTopic(void 0),
28
+ "applications.context": stateTopic(void 0),
29
+ "applications.context.update": dashboardEvent,
15
30
  "applications.foreground": stateTopic(void 0),
16
31
  "applications.list": stateTopic(void 0),
17
32
  "applications.status.update": dashboardEvent,
@@ -94,6 +109,16 @@ function createEventMessage(appId, moduleId, type, payload, pendingReply) {
94
109
  value
95
110
  });
96
111
  },
112
+ reject: (reason) => {
113
+ if (pendingReply.settled) {
114
+ console.warn(`[sanity-sdk:message-bus] reject ignored for "${type}": no waiting caller or already replied`);
115
+ return;
116
+ }
117
+ settleReply(pendingReply, {
118
+ ok: !1,
119
+ error: new MessageBusError("REFUSED", reason)
120
+ });
121
+ },
97
122
  get signal() {
98
123
  return pendingReply.responderSignal;
99
124
  }
@@ -152,18 +177,25 @@ function emit(registry, type, payload, options, appId, moduleId, connectionSigna
152
177
  }, appId, moduleId);
153
178
  }
154
179
  function emitState(registry, connection, type, value) {
180
+ connection.rejections.delete(type);
155
181
  let subject = resolveStateSubject(registry, connection, type);
156
182
  Object.is(subject.getValue(), value) || subject.next(value);
157
183
  }
158
- function query(source, type, options, connectionSignal, resetSignal) {
184
+ function query(source, type, options, connectionSignal, resetSignal, connection) {
185
+ let rejection = () => new MessageBusError("REFUSED", connection.rejections.get(type));
186
+ if (connection.rejections.has(type)) return Promise.reject(rejection());
159
187
  let current = source.getCurrent();
160
188
  if (current !== void 0) return Promise.resolve(current);
161
189
  let signal = scopeSignal(options?.signal, resetSignal, connectionSignal);
162
190
  if (signal.aborted) return Promise.reject(new MessageBusError("ABORTED"));
163
191
  let timeoutMs = options?.timeout === void 0 ? DEFAULT_TIMEOUT_MS : options.timeout;
164
192
  return new Promise((resolve, reject) => {
165
- let timer = timeoutMs === null ? void 0 : setTimeout(() => reject(new MessageBusError("TIMEOUT", `query("${type}") timed out`)), timeoutMs), clear = () => {
166
- timer !== void 0 && clearTimeout(timer);
193
+ let timer = timeoutMs === null ? void 0 : setTimeout(() => {
194
+ clear(), signal?.removeEventListener("abort", onAbort), reject(new MessageBusError("TIMEOUT", `query("${type}") timed out`));
195
+ }, timeoutMs), rejectedSub = connection.rejected$.subscribe((rejectedType) => {
196
+ rejectedType === type && (clear(), signal?.removeEventListener("abort", onAbort), reject(rejection()));
197
+ }), clear = () => {
198
+ timer !== void 0 && clearTimeout(timer), rejectedSub.unsubscribe();
167
199
  }, onAbort = () => {
168
200
  clear(), reject(new MessageBusError("ABORTED"));
169
201
  };
@@ -291,6 +323,7 @@ function migrateEventMessage(message, payload, reply) {
291
323
  payload: payload(message.payload),
292
324
  meta: message.meta,
293
325
  reply: (value) => message.reply(reply(value)),
326
+ reject: (reason) => message.reject(reason),
294
327
  get signal() {
295
328
  return message.signal;
296
329
  }
@@ -300,11 +333,12 @@ function migrateEventReply(result, project) {
300
333
  let projected;
301
334
  return createLazyReply(() => projected ??= Promise.resolve(result).then(project));
302
335
  }
303
- function createRejectedConnection(connectionError) {
336
+ function createRejectedConnection(appId, connectionError) {
304
337
  let throwConnectionError = () => {
305
338
  throw connectionError();
306
339
  };
307
340
  return {
341
+ appId,
308
342
  emit: throwConnectionError,
309
343
  query: () => Promise.reject(connectionError()),
310
344
  subscribe: throwConnectionError,
@@ -318,13 +352,13 @@ function createRejectedConnection(connectionError) {
318
352
  function connectApplicationToMessageBus(installedMessageBus, config) {
319
353
  config.appId || throwMissingAppId();
320
354
  let { appId } = config, installedProtocol = installedMessageBus[MESSAGE_BUS_PROTOCOL_KEY];
321
- if (installedProtocol !== 1) return console.error(`[sanity-sdk:message-bus] protocol mismatch for "${appId}": installed ${String(installedProtocol)}, this copy speaks 1`), createRejectedConnection(() => new MessageBusError("PROTOCOL_MISMATCH", `installed message bus speaks protocol ${String(installedProtocol)}, this copy speaks 1`));
355
+ if (installedProtocol !== 1) return console.error(`[sanity-sdk:message-bus] protocol mismatch for "${appId}": installed ${String(installedProtocol)}, this copy speaks 1`), createRejectedConnection(appId, () => new MessageBusError("PROTOCOL_MISMATCH", `installed message bus speaks protocol ${String(installedProtocol)}, this copy speaks 1`));
322
356
  let registry = installedMessageBus[MESSAGE_BUS_REGISTRY_KEY];
323
- if (!registry) return console.error(`[sanity-sdk:message-bus] incompatible message bus for "${appId}"`), createRejectedConnection(() => new MessageBusError("PROTOCOL_MISMATCH", "installed message bus does not expose a compatible registry"));
357
+ if (!registry) return console.error(`[sanity-sdk:message-bus] incompatible message bus for "${appId}"`), createRejectedConnection(appId, () => new MessageBusError("PROTOCOL_MISMATCH", "installed message bus does not expose a compatible registry"));
324
358
  try {
325
359
  mergeTopicManifest(registry, DASHBOARD_TOPIC_MANIFEST);
326
360
  } catch (error) {
327
- return console.error(`[sanity-sdk:message-bus] topic manifest conflict for "${appId}"`, { error }), createRejectedConnection(() => error);
361
+ return console.error(`[sanity-sdk:message-bus] topic manifest conflict for "${appId}"`, { error }), createRejectedConnection(appId, () => error);
328
362
  }
329
363
  return createConnection(registry, config);
330
364
  }
@@ -339,6 +373,9 @@ function createClient(registry, record, compatibility) {
339
373
  return;
340
374
  }
341
375
  emitState(registry, record, type, compatibility.toInstalledEmission(type, value));
376
+ },
377
+ reject: (type, message) => {
378
+ record.abort.signal.aborted || (record.rejections.set(type, message), record.rejected$.next(type));
342
379
  }
343
380
  };
344
381
  }
@@ -356,6 +393,8 @@ function createConnection(registry, config) {
356
393
  appId,
357
394
  moduleId,
358
395
  stateSubjects: /* @__PURE__ */ new Map(),
396
+ rejections: /* @__PURE__ */ new Map(),
397
+ rejected$: new Subject(),
359
398
  abort: connectionAbort
360
399
  }, compatibility = createTopicCompatibility(registry.migrations, config.migrations ?? bundledMigrations()), isState = (type) => isStateTopic(registry, type), applicationStreams = /* @__PURE__ */ new Map(), streamGeneration = registry.generation, cachedStream = (type, create) => {
361
400
  streamGeneration !== registry.generation && (applicationStreams.clear(), streamGeneration = registry.generation);
@@ -364,8 +403,9 @@ function createConnection(registry, config) {
364
403
  }, stateSource = (type) => cachedStream(type, () => createStateSource(resolveStateSubject(registry, record, type), (value) => compatibility.toApplicationStateValue(type, value), connectionAborted$)), eventStream = (type) => cachedStream(type, () => resolveEventSubject(registry, type).pipe(map((message) => compatibility.toApplicationEventPayload(type, message.payload)), takeUntil(connectionAborted$))), throwIfDisconnected = () => {
365
404
  if (connectionSignal.aborted) throw new MessageBusError("ABORTED");
366
405
  }, connection = {
406
+ appId,
367
407
  emit: (type, payload, options) => (throwIfDisconnected(), migrateEventReply(emit(registry, type, compatibility.toInstalledEmission(type, payload), options, appId, moduleId, connectionSignal), (value) => compatibility.toApplicationEventReply(type, value))),
368
- query: (type, options) => connectionSignal.aborted ? Promise.reject(new MessageBusError("ABORTED")) : query(stateSource(type), type, options, connectionSignal, registry.resetAbort.signal),
408
+ query: (type, options) => connectionSignal.aborted ? Promise.reject(new MessageBusError("ABORTED")) : query(stateSource(type), type, options, connectionSignal, registry.resetAbort.signal, record),
369
409
  subscribe: (type, handler, options) => {
370
410
  if (throwIfDisconnected(), isState(type)) {
371
411
  let source = stateSource(type);
@@ -380,7 +420,7 @@ function createConnection(registry, config) {
380
420
  if (!connectionSignal.aborted) {
381
421
  connectionAbort.abort();
382
422
  for (let subject of record.stateSubjects.values()) subject.complete();
383
- record.stateSubjects.clear(), registry.connections.delete(record);
423
+ record.stateSubjects.clear(), record.rejected$.complete(), registry.connections.delete(record);
384
424
  }
385
425
  }
386
426
  };
@@ -392,7 +432,7 @@ function reset(registry) {
392
432
  registry.resetAbort.abort();
393
433
  for (let connection of registry.connections) {
394
434
  for (let subject of connection.stateSubjects.values()) subject.complete();
395
- connection.stateSubjects.clear();
435
+ connection.stateSubjects.clear(), connection.rejections.clear();
396
436
  }
397
437
  for (let subject of registry.eventSubjects.values()) subject.complete();
398
438
  registry.topics.clear(), registry.eventSubjects.clear(), registry.responderCounts.clear(), registry.resetAbort = new AbortController(), registry.generation += 1, mergeTopicManifest(registry, DASHBOARD_TOPIC_MANIFEST);
@@ -562,6 +602,6 @@ const updateEntry = (topic, update) => (state) => {
562
602
  subscribers: entry.subscribers + 1
563
603
  }))), pending;
564
604
  });
565
- export { isDashboardEnvironment as a, connectMessageBus as c, getDashboardMessageBus as i, installMessageBus as l, getTopicState as n, requireDashboardMessageBus as o, resolveTopic as r, MessageBusError as s, TopicError as t, resetMessageBus as u };
605
+ export { isDashboardEnvironment as a, connectMessageBus as c, capabilities as d, getDashboardMessageBus as i, installMessageBus as l, getTopicState as n, requireDashboardMessageBus as o, resolveTopic as r, MessageBusError as s, TopicError as t, resetMessageBus as u };
566
606
 
567
- //# sourceMappingURL=topicStore-BJ54_X6H.js.map
607
+ //# sourceMappingURL=topicStore-CPhGph6z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topicStore-CPhGph6z.js","names":["bindActionByInstance"],"sources":["../src/dashboard/messageBus/topics.ts","../src/dashboard/messageBus/bus.ts","../src/dashboard/messageBus/store.ts","../src/dashboard/messageBus/topicStore.ts"],"sourcesContent":["import {type CurrentUser} from '@sanity/types'\n\nimport {type Application, type ApplicationInclude} from '../../applications/applications'\nimport {type OrganizationBase} from '../../organization/organization'\n\n/**\n * Identifies a module federation expose and the manifest that serves it.\n * @public\n */\nexport interface RemoteModuleRef {\n readonly entry: string\n readonly moduleId: string\n readonly version: string\n}\n\n/**\n * Application types that can receive configuration modules.\n *\n * The dashboard supplies this value over the message bus, so any string is accepted; known\n * types are listed for autocomplete. `& {}` keeps the literal from collapsing into `string`.\n * @public\n */\nexport type ApplicationConfigAppType = 'media-library' | (string & {})\n\n/**\n * Identifies a configuration module for an application or application type.\n * @public\n */\nexport interface ApplicationConfig extends RemoteModuleRef {\n readonly appId?: Application['id']\n readonly appType: ApplicationConfigAppType\n}\n\n/**\n * The capabilities a host can provide.\n *\n * Reuses the Studio's rendering-context identifiers so an application can hide its own\n * implementation of anything the host provides.\n * @public\n */\nexport const capabilities = ['globalUserMenu', 'favorites', 'history'] as const\n\n/**\n * A capability a host can provide.\n * @public\n */\nexport type Capability = (typeof capabilities)[number]\n\n/**\n * The capabilities the host provides. A missing key means the host does not provide it.\n * @public\n */\nexport type CapabilityRecord = Partial<Record<Capability, boolean>>\n\n/**\n * A document a user viewed, edited, created, or deleted in an application.\n * @public\n */\nexport interface DocumentActivity {\n readonly kind: 'document'\n readonly eventType: 'viewed' | 'edited' | 'created' | 'deleted'\n readonly document: {\n readonly id: string\n readonly type: string\n readonly resource: {\n readonly id: string\n readonly type: 'dataset' | 'media-library' | 'canvas'\n /** Schema collection the document belongs to; the workspace name for studios. */\n readonly schemaName?: string\n }\n }\n}\n\n/**\n * Activity an application reports to the host. Discriminated on `kind`.\n * @public\n */\nexport type ApplicationActivity = DocumentActivity\n\n/**\n * A label rendered for an application interface; `null` clears it.\n * @internal\n */\nexport type ApplicationStatus = {label: string | null}\n\n/**\n * Updates the status rendered for an application interface.\n * @internal\n */\nexport type ApplicationStatusUpdate = {\n /** The application interface name. */\n name: string\n /** The status to render. */\n value: ApplicationStatus\n}\n\n/**\n * What an application is currently showing: the Comlink agent resource context, made generic.\n * @public\n */\nexport interface ApplicationContext {\n /** The resource the application is working in. Types follow `@sanity/client`'s resource config. */\n readonly resource: {\n readonly id: string\n readonly type: 'dataset' | 'media-library' | 'canvas'\n }\n /** The open document, or `null` when none is open. */\n readonly document: {readonly id: string} | null\n}\n\n/**\n * Declares a topic that stores and replays its current value.\n * @public\n */\nexport type StateTopicDef<T> = {kind: 'state'; value: T}\n\n/**\n * Declares a topic that delivers events and an optional reply.\n * @public\n */\nexport type EventTopicDef<P, R = never> = {\n kind: 'event'\n payload: P\n reply?: R\n}\n\n/**\n * Represents a successful topic value or a failed topic operation.\n * @public\n */\nexport type TopicResult<T> = {ok: true; value: T} | {ok: false}\n\n/**\n * Identifies a dashboard application and a route within it.\n * @public\n */\nexport type NavigationTarget = {\n /** The application ID, or `null` for dashboard-level routes. */\n appId: Application['id'] | null\n /** The route path, including its query string and fragment. */\n path: string\n}\n\n/**\n * Describes the current dashboard location and an active navigation.\n * @public\n */\nexport type NavigationLocation = NavigationTarget & {\n /** The active navigation, or `null` when navigation is idle. */\n transition: {\n /** Whether the navigation pushes or replaces browser history. */\n navigationType: 'push' | 'replace'\n /** The requested destination. */\n to: NavigationTarget\n } | null\n}\n\n/**\n * Declares the topics provided by the dashboard.\n * @public\n */\nexport interface DashboardTopics {\n /** Reports user activity in an application, e.g. for the recents feed. Fire-and-forget. */\n 'applications.activity': EventTopicDef<ApplicationActivity>\n /**\n * The base path for an application.\n *\n * An unknown application returns `{ok: false}`.\n */\n 'applications.base-path': StateTopicDef<TopicResult<string>>\n /** The capabilities the host provides. A missing key means the host does not provide it. */\n 'applications.capabilities': StateTopicDef<CapabilityRecord>\n /** The available application configuration modules. */\n 'applications.config': StateTopicDef<ApplicationConfig[] | null>\n /** The foreground application's context, or `null` when it has published none. */\n 'applications.context': StateTopicDef<\n (ApplicationContext & {readonly appId: Application['id']}) | null\n >\n /** Publishes the sending application's context. `null` clears it. Fire-and-forget. */\n 'applications.context.update': EventTopicDef<ApplicationContext | null>\n /** The foreground application ID, or `null` on dashboard-level routes. */\n 'applications.foreground': StateTopicDef<Application['id'] | null>\n /** The dashboard applications available to the current user. */\n 'applications.list': StateTopicDef<TopicResult<Application<ApplicationInclude>[]> | null>\n 'applications.status.update': EventTopicDef<ApplicationStatusUpdate>\n /**\n * The session token for the reading connection, or `null` while signed out. The host\n * writes it to each connection separately, so one application never sees another's token.\n */\n 'auth.token': StateTopicDef<string | null>\n /** Requests a dashboard session token. */\n 'auth.token.refresh': EventTopicDef<void, string>\n /** The current dashboard location and active navigation. */\n 'navigation.location': StateTopicDef<NavigationLocation | null>\n /**\n * Requests navigation and replies when the location commits.\n *\n * `ok: false` reasons:\n * - `not-navigable`: the URL cannot be handled by a dashboard application\n * - `interrupted`: another navigation superseded the request\n * - `failed`: the router rejected or did not commit the request\n */\n 'navigation.location.update': EventTopicDef<\n {\n url: string\n history?: 'push' | 'replace'\n },\n {ok: true} | {ok: false; reason: 'not-navigable' | 'interrupted' | 'failed'}\n >\n /** The current organization, or `null` without an active organization. */\n 'organizations.current': StateTopicDef<Pick<OrganizationBase, 'id' | 'name' | 'slug'> | null>\n /** The open panel, its application, display mode, and optional width in pixels. */\n 'panels.mode': StateTopicDef<TopicResult<\n | {appId: string; name: string; mode: 'aside'; size?: number}\n | {appId: string; name: string; mode: 'full'}\n | null\n > | null>\n /** Opens, updates, resizes, or closes an application's panel. */\n 'panels.mode.set': EventTopicDef<\n {name: string; mode: 'aside' | 'full'} | {name: string; size: number} | null\n >\n /** The resolved dashboard color scheme. */\n 'preferences.color-scheme': StateTopicDef<'light' | 'dark'>\n /** Whether the dashboard dock is pinned open. */\n 'preferences.dock-locked': StateTopicDef<boolean>\n /** The signed-in user, or `null` while signed out. */\n 'users.current': StateTopicDef<CurrentUser | null>\n}\n\n/**\n * Declares every topic available through the message bus.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- Declaration merging extends the SDK manifest.\nexport interface Topics extends DashboardTopics {}\n\n/**\n * Hides provisional topics from the public message bus methods.\n * @internal\n */\nexport type MessageBusTopics = Omit<Topics, 'applications.status.update'>\n\n/**\n * Every declared topic name.\n * @public\n */\nexport type TopicName<TTopics = Topics> = keyof TTopics\n\ntype StateTopicsOf<T> = {\n [K in keyof T]: T[K] extends {kind: 'state'} ? K : never\n}[keyof T]\n\n/**\n * Names of state topics exposed by message bus methods.\n * @public\n */\nexport type StateTopic<TTopics = MessageBusTopics> = StateTopicsOf<TTopics>\n\ntype TopicOwnership = {readonly type: 'same_app'} | {readonly type: 'any_app'}\n\n// State is only ever written by the host, one connection at a time, so it carries no ownership.\ntype TopicManifestEntry<T> = T extends {kind: 'state'; value: infer V}\n ? {readonly kind: 'state'; readonly seed: V | undefined}\n : {readonly kind: 'event'; readonly ownership: TopicOwnership}\n\n// The value a connection's copy of the topic starts with; `undefined` means unpublished.\nconst stateTopic = <const V>(seed: V) => ({kind: 'state', seed}) as const\n\n// `same_app` restricts responding to the application that installed the bus.\nconst dashboardEvent = {kind: 'event', ownership: {type: 'same_app'}} as const\n\ntype DashboardTopicManifest = {\n readonly [K in keyof DashboardTopics]: TopicManifestEntry<DashboardTopics[K]>\n}\n\n/**\n * Defines the runtime kind, ownership, and initial value of dashboard topics.\n * @internal\n */\nexport const DASHBOARD_TOPIC_MANIFEST: DashboardTopicManifest = {\n 'applications.activity': dashboardEvent,\n 'applications.base-path': stateTopic(undefined),\n 'applications.capabilities': stateTopic(undefined),\n 'applications.config': stateTopic(undefined),\n 'applications.context': stateTopic(undefined),\n 'applications.context.update': dashboardEvent,\n 'applications.foreground': stateTopic(undefined),\n 'applications.list': stateTopic(undefined),\n 'applications.status.update': dashboardEvent,\n 'auth.token': stateTopic(undefined),\n 'auth.token.refresh': dashboardEvent,\n 'navigation.location': stateTopic(undefined),\n 'navigation.location.update': dashboardEvent,\n 'organizations.current': stateTopic(undefined),\n 'panels.mode': stateTopic({ok: true, value: null}),\n 'panels.mode.set': dashboardEvent,\n 'preferences.color-scheme': stateTopic(undefined),\n 'preferences.dock-locked': stateTopic(undefined),\n 'users.current': stateTopic(undefined),\n}\n\n/**\n * Defines the runtime manifest accepted from any message bus version.\n * @internal\n */\nexport type TopicManifest = Readonly<\n Record<\n string,\n | {readonly kind: 'state'; readonly seed: unknown}\n | {readonly kind: 'event'; readonly ownership: TopicOwnership}\n >\n>\n\n/**\n * Names of event topics exposed by message bus methods.\n * @public\n */\nexport type EventTopic<TTopics = MessageBusTopics> = {\n [K in keyof TTopics]: TTopics[K] extends {kind: 'event'} ? K : never\n}[keyof TTopics]\n\n/**\n * The value type of a state topic.\n * @public\n */\nexport type ValueOf<K extends StateTopic<TTopics>, TTopics = Topics> =\n TTopics[K] extends StateTopicDef<infer T> ? T : never\n\n/**\n * The payload type of an event topic.\n * @public\n */\nexport type PayloadOf<K extends EventTopic<TTopics>, TTopics = Topics> =\n TTopics[K] extends EventTopicDef<infer P, infer _R> ? P : never\n\n/**\n * The reply type of an event topic (`never` if it declares none).\n * @public\n */\nexport type ReplyOf<K extends EventTopic<TTopics>, TTopics = Topics> =\n TTopics[K] extends EventTopicDef<infer _P, infer R> ? R : never\n\n/**\n * Converts a topic value between 2 adjacent versions.\n * @internal\n */\nexport interface TopicMigration {\n /** The older version. */\n readonly from: number\n /** The newer version. */\n readonly to: number\n /** Converts an older state value or event payload to the newer version. */\n up(older: unknown): unknown\n /** Converts a newer state value or event payload to the older version. */\n down(newer: unknown): unknown\n /** Converts event replies between these versions. */\n readonly reply?: {\n /** Converts an older reply to the newer version. */\n up(older: unknown): unknown\n /** Converts a newer reply to the older version. */\n down(newer: unknown): unknown\n }\n}\n\n/**\n * Defines the bundled migration chain for each topic.\n * @internal\n */\nexport const topicMigrations: Partial<Record<TopicName, readonly TopicMigration[]>> = {}\n","/* eslint-disable no-console -- The bus can initialize before the SDK logger exists. */\nimport {\n BehaviorSubject,\n concat,\n defer,\n filter,\n firstValueFrom,\n from,\n map,\n type Observable,\n ReplaySubject,\n Subject,\n type Subscription,\n takeUntil,\n} from 'rxjs'\n\nimport {type Application} from '../../applications/applications'\nimport {\n DASHBOARD_TOPIC_MANIFEST,\n type EventTopic,\n type MessageBusTopics,\n type PayloadOf,\n type ReplyOf,\n type StateTopic,\n type TopicManifest,\n type TopicMigration,\n topicMigrations,\n type TopicName,\n type Topics,\n type ValueOf,\n} from './topics'\n\n/**\n * A message bus protocol error code.\n * @public\n */\nexport type MessageBusErrorCode =\n | 'NO_RESPONDER'\n | 'TIMEOUT'\n | 'ABORTED'\n | 'HANDLER_THREW'\n | 'PROTOCOL_MISMATCH'\n | 'OWNERSHIP_MISMATCH'\n | 'MISSING_APP_ID'\n | 'REFUSED'\n\n/**\n * An error raised by the message bus protocol.\n * @public\n */\nexport class MessageBusError extends Error {\n /** The machine-readable protocol error code. */\n readonly code: MessageBusErrorCode\n\n /** Creates a message bus protocol error. */\n constructor(code: MessageBusErrorCode, message?: string, options?: {cause?: unknown}) {\n super(message ?? code, options)\n this.name = 'MessageBusError'\n this.code = code\n }\n}\n\n/**\n * Metadata that travels with each message bus event.\n * @public\n */\nexport interface MessageBusMeta {\n /** The application that produced the message. */\n appId: Application['id']\n /**\n * The federation module id of the connection that sent the message (e.g.\n * `favorites/views/list/panel`). Absent from older copies and when the host\n * supplied none, so readers normalise with `message.meta.moduleId ?? message.meta.appId`.\n */\n moduleId?: string\n /** The Unix timestamp in milliseconds when the message was produced. */\n timestamp: number\n}\n\n/**\n * A message delivered to an event topic responder.\n * @public\n */\nexport interface MessageBusMessage<T, R = never, K extends PropertyKey = TopicName> {\n /** The topic that carries the message. */\n type: K\n /** The event payload. */\n payload: T\n /** The message provenance. */\n meta: MessageBusMeta\n /** Replies to an awaiting sender. */\n reply(value: R): void\n /**\n * Refuses the message: the sender's awaited `emit()` rejects with a\n * {@link MessageBusError} whose `code` is `'REFUSED'`. Ignored, with a warning,\n * once the reply has already settled.\n */\n reject(message?: string): void\n /** Aborts when the sender stops waiting for a reply. */\n readonly signal: AbortSignal\n}\n\n/**\n * An observable state topic with access to its current and first values.\n * @public\n */\nexport interface MessageBusStateSource<T> extends Observable<T> {\n /** Returns the current value, or `undefined` before the first value is published. */\n getCurrent(): T | undefined\n /** Resolves with the first published value. */\n readonly firstValue: Promise<T>\n}\n\n/**\n * Options for aborting a message bus operation.\n * @public\n */\nexport interface MessageBusAbortOptions {\n /** Aborts the operation when signaled. */\n signal?: AbortSignal\n}\n\n/**\n * Options for reading a state topic.\n * @public\n */\nexport interface MessageBusQueryOptions extends MessageBusAbortOptions {\n /** Wait timeout in milliseconds. Defaults to 5 seconds; `null` disables it. */\n timeout?: number | null\n}\n\n/**\n * Options for emitting an event topic.\n * @public\n */\nexport interface MessageBusEmitOptions extends MessageBusAbortOptions {\n /** Reply timeout in milliseconds. Defaults to 5 seconds; `null` disables it. */\n timeout?: number | null\n}\n\n/**\n * A lazily awaited event reply.\n * @public\n */\nexport interface MessageBusEmitResult<R> extends PromiseLike<R> {\n /** Handles a rejected event reply. */\n catch<T = never>(onRejected?: (reason: unknown) => T | PromiseLike<T>): Promise<R | T>\n /** Runs after the event reply settles. */\n finally(onFinally?: () => void): Promise<R>\n}\n\n/**\n * Sends events and reads typed state and event topics.\n *\n * @remarks\n * State topics are written by the host to each connection separately through\n * {@link MessageBusClient.emit}; a connection only ever reads its own values.\n * @public\n */\nexport interface MessageBus<TTopics = MessageBusTopics> {\n /** Emits an event topic and provides its reply when awaited. */\n emit<K extends EventTopic<TTopics>>(\n type: K,\n ...rest: PayloadOf<K, TTopics> extends void\n ? [payload?: void, options?: MessageBusEmitOptions]\n : [payload: PayloadOf<K, TTopics>, options?: MessageBusEmitOptions]\n ): MessageBusEmitResult<ReplyOf<K, TTopics>>\n /** Reads the current or next value of a state topic. */\n query<K extends StateTopic<TTopics>>(\n type: K,\n options?: MessageBusQueryOptions,\n ): Promise<ValueOf<K, TTopics>>\n /** Runs a responder for each event until its signal aborts. */\n subscribe<K extends EventTopic<TTopics>>(\n type: K,\n handler: (message: MessageBusMessage<PayloadOf<K, TTopics>, ReplyOf<K, TTopics>, K>) => void,\n options?: MessageBusAbortOptions,\n ): void\n /** Runs a handler for each state value until its signal aborts. */\n subscribe<K extends StateTopic<TTopics>>(\n type: K,\n handler: (value: ValueOf<K, TTopics>) => void,\n options?: MessageBusAbortOptions,\n ): void\n /** Returns a state topic as a `MessageBusStateSource`. */\n subscribe<K extends StateTopic<TTopics>>(type: K): MessageBusStateSource<ValueOf<K, TTopics>>\n /** Returns an event topic as an observable of its payloads. */\n subscribe<K extends EventTopic<TTopics>>(type: K): Observable<PayloadOf<K, TTopics>>\n}\n\n/**\n * A message bus connection that can be torn down independently of its siblings.\n * @public\n */\nexport interface MessageBusConnection<TTopics = MessageBusTopics> extends MessageBus<TTopics> {\n /** The application this connection belongs to. */\n readonly appId: Application['id']\n /**\n * Tears down this connection: pending requests reject `ABORTED`, subscriptions\n * complete, and later `emit`, `query`, and `subscribe` calls fail with `ABORTED`.\n * Siblings and the shared bus are untouched.\n */\n disconnect(): void\n}\n\n/**\n * The host's handle to one connection: who it is, when it closes, and where to write its state.\n * @public\n */\nexport interface MessageBusClient {\n /** The application the connection belongs to. */\n readonly appId: Application['id']\n /** The federation module id of the connection. Equals `appId` when the host supplied none. */\n readonly moduleId: string\n /** Aborts when the connection disconnects. Drop per-client state here. */\n readonly closed: AbortSignal\n /** Writes a state value to this connection only. Ignored once the connection has closed. */\n emit<K extends StateTopic>(type: K, value: ValueOf<K>): void\n /**\n * Rejects a state topic for this connection: its pending and later {@link MessageBus.query}\n * calls reject with a {@link MessageBusError} whose `code` is `'REFUSED'`, until the host next\n * writes a value with {@link MessageBusClient.emit}, which clears the rejection.\n *\n * @remarks\n * A rejected promise cannot be un-rejected and an errored subject cannot resume, so the\n * rejection is tracked per connection alongside the topic's subject rather than by erroring\n * it: `query` consults it before awaiting, and {@link MessageBus.subscribe} and the topic's\n * {@link MessageBusStateSource} stay silent (they never error) until a value is written.\n * Ignored once the connection has closed, the same as {@link MessageBusClient.emit}.\n */\n reject<K extends StateTopic>(type: K, message?: string): void\n}\n\n/**\n * The host's connection to the bus.\n *\n * @remarks\n * State reaches an application only through {@link MessageBusClient.emit}. There is no\n * broadcast: sending the same value to everyone is a loop over `connections`, and giving a\n * new connection the current values is done when it appears there, as an SSE server writes\n * a snapshot to each new client.\n * @public\n */\nexport interface MessageBusHost<TTopics = MessageBusTopics> extends MessageBusConnection<TTopics> {\n /**\n * Every open connection other than this one first, then each new one as it joins. The same\n * {@link MessageBusClient} object is handed out for a connection across subscriptions, so it\n * can be kept in a `Set`. A connection stays listed until it calls `disconnect()`; the SDK\n * does that when the owning `SanityInstance` is disposed.\n */\n readonly connections: Observable<MessageBusClient>\n}\n\nconst MESSAGE_BUS_KEY = Symbol.for('sanity.os.bus')\nconst MESSAGE_BUS_PROTOCOL_KEY = Symbol.for('sanity.os.protocol')\nconst MESSAGE_BUS_REGISTRY_KEY = Symbol.for('sanity.os.registry')\nconst MESSAGE_BUS_PENDING_REPLY_KEY = Symbol.for('sanity.os.request')\n\nconst MESSAGE_BUS_PROTOCOL = 1\n\nconst DEFAULT_TIMEOUT_MS = 5000\n\n// Distinguishes an unpublished topic from a published `undefined` value.\nconst NO_VALUE = Symbol.for('sanity.os.no-value')\n\ntype ReplyOutcome =\n | {readonly ok: true; readonly value: unknown}\n | {readonly ok: false; readonly error: unknown}\n\n// Defers Promise creation until the reply is awaited to preserve fire-and-forget emission.\ninterface PendingReply {\n readonly responderAbort: AbortController\n readonly responderSignal: AbortSignal\n settled: boolean\n outcomeBeforeAwait?: ReplyOutcome\n settlePromise?: (outcome: ReplyOutcome) => void\n replyPromise?: Promise<unknown>\n}\n\n// One connection: its identity, its own copy of every state topic, and its lifetime.\ninterface ConnectionRecord {\n readonly appId: string\n readonly moduleId: string\n readonly stateSubjects: Map<string, BehaviorSubject<unknown>>\n // Topics the host has rejected for this connection, with the reason, until the next write.\n readonly rejections: Map<string, string | undefined>\n // Fires the rejected topic name so pending queries on that topic can reject at once.\n readonly rejected$: Subject<string>\n readonly abort: AbortController\n}\n\ninterface MessageBusRegistry {\n readonly appId: string\n readonly topics: Map<string, TopicManifest[string]>\n readonly connections: Set<ConnectionRecord>\n readonly connected$: Subject<ConnectionRecord>\n readonly eventSubjects: Map<string, Subject<MessageBusMessage<unknown, unknown>>>\n readonly responderCounts: Map<string, number>\n readonly migrations: ReadonlyMap<string, readonly TopicMigration[]>\n resetAbort: AbortController\n generation: number\n}\n\ntype InternalMessageBus = MessageBus & {\n [MESSAGE_BUS_REGISTRY_KEY]: MessageBusRegistry\n [MESSAGE_BUS_PROTOCOL_KEY]: number\n}\n\n// A connection's box for a state topic, created on first use from the topic's manifest seed.\nfunction resolveStateSubject(\n registry: MessageBusRegistry,\n connection: ConnectionRecord,\n type: string,\n): BehaviorSubject<unknown> {\n // Callers gate on the connection's lifetime; this keeps a slipped call from recreating a\n // box on a closed connection that nothing would ever complete.\n if (connection.abort.signal.aborted) throw new MessageBusError('ABORTED')\n let subject = connection.stateSubjects.get(type)\n if (!subject) {\n const topic = registry.topics.get(type)\n if (!topic) {\n console.warn(`[sanity-sdk:message-bus] state topic \"${type}\" is not declared`)\n }\n const seed = topic?.kind === 'state' ? topic.seed : undefined\n subject = new BehaviorSubject<unknown>(seed === undefined ? NO_VALUE : seed)\n connection.stateSubjects.set(type, subject)\n }\n return subject\n}\n\nfunction toStateSource(\n values: Observable<unknown>,\n getCurrent: () => unknown,\n): MessageBusStateSource<unknown> {\n const source = values as MessageBusStateSource<unknown>\n source.getCurrent = getCurrent\n // Unread sources must not create promises that reject when reset completes them.\n let firstValue: Promise<unknown> | undefined\n Object.defineProperty(source, 'firstValue', {\n get: () => (firstValue ??= firstValueFrom(values)),\n })\n return source\n}\n\nfunction assertCompatibleTopicManifest(\n registry: MessageBusRegistry,\n manifest: TopicManifest,\n): void {\n for (const [type, entry] of Object.entries(manifest)) {\n const existing = registry.topics.get(type)\n if (existing && existing.kind !== entry.kind) {\n throw new MessageBusError(\n 'PROTOCOL_MISMATCH',\n `topic \"${type}\" is declared \"${entry.kind}\" but the installed bus knows it as \"${existing.kind}\"`,\n )\n }\n if (\n existing?.kind === 'event' &&\n entry.kind === 'event' &&\n existing.ownership.type !== entry.ownership.type\n ) {\n throw new MessageBusError('OWNERSHIP_MISMATCH', `topic \"${type}\" has conflicting ownership`)\n }\n }\n}\n\nfunction mergeTopicManifest(registry: MessageBusRegistry, manifest: TopicManifest): void {\n assertCompatibleTopicManifest(registry, manifest)\n for (const [type, entry] of Object.entries(manifest)) registry.topics.set(type, entry)\n}\n\nfunction resolveEventSubject(\n registry: MessageBusRegistry,\n type: string,\n): Subject<MessageBusMessage<unknown, unknown>> {\n let subject = registry.eventSubjects.get(type)\n if (!subject) {\n subject = new Subject<MessageBusMessage<unknown, unknown>>()\n registry.eventSubjects.set(type, subject)\n }\n return subject\n}\n\nfunction settleReply(reply: PendingReply, outcome: ReplyOutcome): void {\n if (reply.settled) return\n reply.settled = true\n if (reply.settlePromise) reply.settlePromise(outcome)\n else reply.outcomeBeforeAwait = outcome\n}\n\nfunction createEventMessage(\n appId: string,\n moduleId: string,\n type: string,\n payload: unknown,\n pendingReply: PendingReply,\n): MessageBusMessage<unknown, unknown> {\n const message: MessageBusMessage<unknown, unknown> & {\n [MESSAGE_BUS_PENDING_REPLY_KEY]?: PendingReply\n } = {\n type: type as TopicName,\n payload,\n meta: {appId, moduleId, timestamp: Date.now()},\n reply: (value) => {\n if (pendingReply.settled) {\n console.warn(\n `[sanity-sdk:message-bus] reply ignored for \"${type}\": no waiting caller or already replied`,\n )\n return\n }\n settleReply(pendingReply, {ok: true, value})\n },\n reject: (reason) => {\n if (pendingReply.settled) {\n console.warn(\n `[sanity-sdk:message-bus] reject ignored for \"${type}\": no waiting caller or already replied`,\n )\n return\n }\n settleReply(pendingReply, {ok: false, error: new MessageBusError('REFUSED', reason)})\n },\n get signal() {\n return pendingReply.responderSignal\n },\n }\n\n message[MESSAGE_BUS_PENDING_REPLY_KEY] = pendingReply\n return message\n}\n\nfunction createReplyPromise(\n pendingReply: PendingReply,\n options: MessageBusEmitOptions & {hadResponderAtEmission: boolean},\n): Promise<unknown> {\n return new Promise<unknown>((resolve, reject) => {\n const settlePromise = (outcome: ReplyOutcome) =>\n outcome.ok ? resolve(outcome.value) : reject(outcome.error)\n\n if (pendingReply.outcomeBeforeAwait) {\n pendingReply.responderAbort.abort()\n settlePromise(pendingReply.outcomeBeforeAwait)\n return\n }\n if (!options.hadResponderAtEmission) {\n reject(new MessageBusError('NO_RESPONDER'))\n return\n }\n\n const timeoutMs = options.timeout === undefined ? DEFAULT_TIMEOUT_MS : options.timeout\n let timer: ReturnType<typeof setTimeout> | undefined\n const onAbort = () =>\n settleReply(pendingReply, {ok: false, error: new MessageBusError('ABORTED')})\n\n pendingReply.settlePromise = (outcome) => {\n if (timer !== undefined) clearTimeout(timer)\n options.signal?.removeEventListener('abort', onAbort)\n pendingReply.responderAbort.abort()\n settlePromise(outcome)\n }\n\n if (timeoutMs !== null) {\n timer = setTimeout(\n () => settleReply(pendingReply, {ok: false, error: new MessageBusError('TIMEOUT')}),\n timeoutMs,\n )\n }\n if (options.signal) {\n if (options.signal.aborted) onAbort()\n else options.signal.addEventListener('abort', onAbort, {once: true})\n }\n })\n}\n\nfunction createLazyReply<R>(awaitReply: () => Promise<R>): MessageBusEmitResult<R> {\n return {\n // oxlint-disable-next-line unicorn/no-thenable -- awaiting arms reply failure handling; fire-and-forget does not.\n then: (onFulfilled, onRejected) => awaitReply().then(onFulfilled, onRejected),\n catch: (onRejected) => awaitReply().then(undefined, onRejected),\n finally: (onFinally) => awaitReply().finally(onFinally),\n }\n}\n\nfunction emitEvent(\n registry: MessageBusRegistry,\n type: string,\n payload: unknown,\n options: MessageBusEmitOptions | undefined,\n appId: string,\n moduleId: string,\n): MessageBusEmitResult<unknown> {\n const hadResponderAtEmission = (registry.responderCounts.get(type) ?? 0) > 0\n const responderAbort = new AbortController()\n const pendingReply: PendingReply = {\n responderAbort,\n responderSignal: scopeSignal(options?.signal, responderAbort.signal),\n settled: false,\n }\n\n resolveEventSubject(registry, type).next(\n createEventMessage(appId, moduleId, type, payload, pendingReply),\n )\n\n const awaitReply = () =>\n (pendingReply.replyPromise ??= createReplyPromise(pendingReply, {\n ...options,\n hadResponderAtEmission,\n }))\n return createLazyReply(awaitReply)\n}\n\nconst isStateTopic = (registry: MessageBusRegistry, type: string): boolean =>\n registry.topics.get(type)?.kind === 'state'\n\nconst canRespond = (\n registry: MessageBusRegistry,\n ownership: {readonly type: 'same_app' | 'any_app'},\n appId: string,\n): boolean => ownership.type === 'any_app' || appId === registry.appId\n\nfunction emit(\n registry: MessageBusRegistry,\n type: string,\n payload: unknown,\n options: MessageBusEmitOptions | undefined,\n appId: string,\n moduleId: string,\n connectionSignal: AbortSignal,\n): MessageBusEmitResult<unknown> {\n if (isStateTopic(registry, type)) {\n throw new MessageBusError(\n 'OWNERSHIP_MISMATCH',\n `Cannot emit state topic \"${type}\" from app \"${appId}\". The host writes state to each connection through its client handle. Read it with query() or subscribe().`,\n )\n }\n return emitEvent(\n registry,\n type,\n payload,\n {\n ...options,\n signal: scopeSignal(options?.signal, registry.resetAbort.signal, connectionSignal),\n },\n appId,\n moduleId,\n )\n}\n\nfunction emitState(\n registry: MessageBusRegistry,\n connection: ConnectionRecord,\n type: string,\n value: unknown,\n): void {\n // A written value clears any rejection so later queries resolve normally.\n connection.rejections.delete(type)\n const subject = resolveStateSubject(registry, connection, type)\n if (!Object.is(subject.getValue(), value)) subject.next(value)\n}\n\nfunction query(\n source: MessageBusStateSource<unknown>,\n type: string,\n options: MessageBusQueryOptions | undefined,\n connectionSignal: AbortSignal,\n resetSignal: AbortSignal,\n connection: ConnectionRecord,\n): Promise<unknown> {\n const rejection = () => new MessageBusError('REFUSED', connection.rejections.get(type))\n // A rejection outranks any earlier value: it is cleared only when the host writes a new one.\n if (connection.rejections.has(type)) return Promise.reject(rejection())\n const current = source.getCurrent()\n if (current !== undefined) return Promise.resolve(current)\n\n const signal = scopeSignal(options?.signal, resetSignal, connectionSignal)\n if (signal.aborted) return Promise.reject(new MessageBusError('ABORTED'))\n const timeoutMs = options?.timeout === undefined ? DEFAULT_TIMEOUT_MS : options.timeout\n return new Promise((resolve, reject) => {\n const timer =\n timeoutMs === null\n ? undefined\n : setTimeout(() => {\n clear()\n signal?.removeEventListener('abort', onAbort)\n reject(new MessageBusError('TIMEOUT', `query(\"${type}\") timed out`))\n }, timeoutMs)\n // A rejection that arrives while waiting rejects the pending query at once.\n const rejectedSub = connection.rejected$.subscribe((rejectedType) => {\n if (rejectedType !== type) return\n clear()\n signal?.removeEventListener('abort', onAbort)\n reject(rejection())\n })\n const clear = () => {\n if (timer !== undefined) clearTimeout(timer)\n rejectedSub.unsubscribe()\n }\n const onAbort = () => {\n clear()\n reject(new MessageBusError('ABORTED'))\n }\n signal?.addEventListener('abort', onAbort, {once: true})\n void source.firstValue.then(\n (value) => {\n clear()\n signal?.removeEventListener('abort', onAbort)\n resolve(value)\n },\n (error) => {\n clear()\n signal?.removeEventListener('abort', onAbort)\n reject(error)\n },\n )\n })\n}\n\nfunction unsubscribeOnAbort(subscription: Subscription, signal: AbortSignal | undefined): void {\n if (!signal) return\n if (signal.aborted) {\n subscription.unsubscribe()\n return\n }\n signal.addEventListener('abort', () => subscription.unsubscribe(), {\n once: true,\n })\n}\n\nfunction scopeSignal(signal: AbortSignal | undefined, ...lifecycles: AbortSignal[]): AbortSignal {\n return signal ? AbortSignal.any([signal, ...lifecycles]) : AbortSignal.any(lifecycles)\n}\n\nfunction invokeResponder(\n handler: (message: MessageBusMessage<unknown, unknown>) => unknown,\n message: MessageBusMessage<unknown, unknown> & {\n [MESSAGE_BUS_PENDING_REPLY_KEY]?: PendingReply\n },\n): void {\n const pendingReply = message[MESSAGE_BUS_PENDING_REPLY_KEY]\n const fail = (error: unknown) => {\n if (pendingReply) {\n settleReply(pendingReply, {\n ok: false,\n error: new MessageBusError('HANDLER_THREW', undefined, {\n cause: error,\n }),\n })\n }\n }\n try {\n const result = handler(message)\n if (result instanceof Promise) result.catch(fail)\n } catch (error) {\n fail(error)\n }\n}\n\nfunction respond(\n registry: MessageBusRegistry,\n type: string,\n handler: (message: MessageBusMessage<unknown, unknown>) => unknown,\n options: MessageBusAbortOptions | undefined,\n appId: string,\n connectionSignal: AbortSignal,\n): void {\n const topic = registry.topics.get(type)\n if (topic?.kind === 'event' && !canRespond(registry, topic.ownership, appId)) {\n throw new MessageBusError(\n 'OWNERSHIP_MISMATCH',\n `Cannot register a handler for event topic \"${type}\" from app \"${appId}\". Only the app that owns this topic can respond to it. Other apps can send it with emit().`,\n )\n }\n\n registry.responderCounts.set(type, (registry.responderCounts.get(type) ?? 0) + 1)\n const subscription = resolveEventSubject(registry, type).subscribe((message) =>\n invokeResponder(handler, message),\n )\n subscription.add(() => {\n const count = registry.responderCounts.get(type) ?? 0\n if (count > 0) registry.responderCounts.set(type, count - 1)\n })\n unsubscribeOnAbort(\n subscription,\n scopeSignal(options?.signal, registry.resetAbort.signal, connectionSignal),\n )\n}\n\nconst bundledMigrations = () => new Map(Object.entries(topicMigrations))\n\n/**\n * Creates an isolated message bus without installing it globally and returns the host's\n * connection to it.\n * @internal\n */\nexport function createIsolatedMessageBus(\n appId: string,\n config: {\n migrations?: ReadonlyMap<string, readonly TopicMigration[]>\n } = {},\n): MessageBusHost<Topics> {\n if (!appId) throwMissingAppId()\n\n const registry: MessageBusRegistry = {\n appId,\n topics: new Map(),\n connections: new Set(),\n connected$: new Subject(),\n eventSubjects: new Map(),\n responderCounts: new Map(),\n migrations: config.migrations ?? bundledMigrations(),\n resetAbort: new AbortController(),\n generation: 0,\n }\n\n mergeTopicManifest(registry, DASHBOARD_TOPIC_MANIFEST)\n\n return createConnection(registry, {\n appId,\n migrations: config.migrations,\n }) as MessageBusHost<Topics>\n}\n\ntype TopicVersionAdapter = {\n toInstalled: (type: string, value: unknown) => unknown\n toApplication: (type: string, value: unknown) => unknown\n}\n\ntype TopicCompatibility = {\n toInstalledEmission: TopicVersionAdapter['toInstalled']\n toApplicationStateValue: TopicVersionAdapter['toApplication']\n toApplicationEventPayload: TopicVersionAdapter['toApplication']\n toInstalledEventReply: TopicVersionAdapter['toInstalled']\n toApplicationEventReply: TopicVersionAdapter['toApplication']\n}\n\ntype TopicMigrationTransform = Pick<TopicMigration, 'up' | 'down'>\n\nconst identityMigration: TopicMigrationTransform = {\n up: (value) => value,\n down: (value) => value,\n}\n\nfunction effectiveTopicVersions(\n migrations: ReadonlyMap<string, readonly TopicMigration[]>,\n): Map<string, number> {\n const versions = new Map<string, number>()\n for (const [topic, steps] of migrations) {\n let version = 1\n for (const step of steps) if (step.to > version) version = step.to\n versions.set(topic, version)\n }\n return versions\n}\n\nfunction migrationTransformAt(\n steps: readonly TopicMigration[] | undefined,\n version: number,\n select: (step: TopicMigration) => TopicMigrationTransform | undefined,\n): TopicMigrationTransform {\n const step = steps?.find((candidate) => candidate.from === version)\n return (step ? select(step) : undefined) ?? identityMigration\n}\n\nfunction migrateVersionedValue(\n steps: readonly TopicMigration[] | undefined,\n value: unknown,\n from: number,\n to: number,\n select: (step: TopicMigration) => TopicMigrationTransform | undefined,\n): unknown {\n if (from === to) return value\n\n let current = value\n if (from < to) {\n for (let version = from; version < to; version++) {\n current = migrationTransformAt(steps, version, select).up(current)\n }\n } else {\n for (let version = from; version > to; version--) {\n current = migrationTransformAt(steps, version - 1, select).down(current)\n }\n }\n return current\n}\n\nfunction createTopicCompatibility(\n installedMigrations: ReadonlyMap<string, readonly TopicMigration[]>,\n applicationMigrations: ReadonlyMap<string, readonly TopicMigration[]>,\n): TopicCompatibility {\n const installedVersions = effectiveTopicVersions(installedMigrations)\n const applicationVersions = effectiveTopicVersions(applicationMigrations)\n const applicationVersion = (type: string) => applicationVersions.get(type) ?? 1\n const installedVersion = (type: string) => installedVersions.get(type) ?? 1\n const migrationChainFor = (type: string) =>\n (applicationVersion(type) > installedVersion(type)\n ? applicationMigrations\n : installedMigrations\n ).get(type)\n const createVersionAdapter = (\n select: (step: TopicMigration) => TopicMigrationTransform | undefined,\n ): TopicVersionAdapter => ({\n toInstalled: (type, value) =>\n migrateVersionedValue(\n migrationChainFor(type),\n value,\n applicationVersion(type),\n installedVersion(type),\n select,\n ),\n toApplication: (type, value) =>\n migrateVersionedValue(\n migrationChainFor(type),\n value,\n installedVersion(type),\n applicationVersion(type),\n select,\n ),\n })\n\n const stateValueAndEventPayload = createVersionAdapter((step) => step)\n const eventReply = createVersionAdapter((step) => step.reply)\n return {\n toInstalledEmission: stateValueAndEventPayload.toInstalled,\n toApplicationStateValue: stateValueAndEventPayload.toApplication,\n toApplicationEventPayload: stateValueAndEventPayload.toApplication,\n toInstalledEventReply: eventReply.toInstalled,\n toApplicationEventReply: eventReply.toApplication,\n }\n}\n\n// Cache projections by input reference to keep state snapshots stable.\nfunction projectCurrent(input: () => unknown, project: (value: unknown) => unknown): () => unknown {\n let lastInput: unknown\n let lastOutput: unknown\n let cached = false\n return () => {\n const current = input()\n if (current === undefined) return undefined\n if (!cached || current !== lastInput) {\n lastInput = current\n lastOutput = project(current)\n cached = true\n }\n return lastOutput\n }\n}\n\n// The connection's view of one of its state boxes, in the connection's topic version.\nfunction createStateSource(\n subject: BehaviorSubject<unknown>,\n project: (value: unknown) => unknown,\n completeOn: Observable<unknown>,\n): MessageBusStateSource<unknown> {\n const getCurrent = () => {\n const current = subject.getValue()\n return current === NO_VALUE ? undefined : current\n }\n return toStateSource(\n subject.pipe(\n filter((value) => value !== NO_VALUE),\n map(project),\n takeUntil(completeOn),\n ),\n projectCurrent(getCurrent, project),\n )\n}\n\nfunction migrateEventMessage(\n message: MessageBusMessage<unknown, unknown>,\n payload: (value: unknown) => unknown,\n reply: (value: unknown) => unknown,\n): MessageBusMessage<unknown, unknown> {\n return {\n type: message.type,\n payload: payload(message.payload),\n meta: message.meta,\n reply: (value) => message.reply(reply(value)),\n reject: (reason) => message.reject(reason),\n get signal() {\n return message.signal\n },\n }\n}\n\nfunction migrateEventReply(\n result: MessageBusEmitResult<unknown>,\n project: (value: unknown) => unknown,\n): MessageBusEmitResult<unknown> {\n let projected: Promise<unknown> | undefined\n return createLazyReply(() => (projected ??= Promise.resolve(result).then(project)))\n}\n\nfunction createRejectedConnection(\n appId: string,\n connectionError: () => unknown,\n): MessageBusConnection {\n const throwConnectionError = (): never => {\n throw connectionError()\n }\n return {\n appId,\n emit: throwConnectionError,\n // `query` is typed as a Promise, so it must reject rather than throw synchronously.\n query: () => Promise.reject(connectionError()),\n subscribe: throwConnectionError,\n disconnect: () => {},\n } as unknown as MessageBusConnection\n}\n\n/**\n * Options for connecting an application to an isolated message bus.\n * @internal\n */\nexport interface ConnectApplicationToMessageBusOptions {\n /** The application ID stamped on emitted messages. */\n appId: string\n /** The federation module id stamped on emitted messages. Defaults to `appId`. */\n moduleId?: string\n /** The topic migrations supported by the application. */\n migrations?: ReadonlyMap<string, readonly TopicMigration[]>\n}\n\n/**\n * Connects an application to an isolated message bus.\n * @internal\n */\nexport function connectApplicationToMessageBus(\n installedMessageBus: MessageBus,\n config: ConnectApplicationToMessageBusOptions,\n): MessageBusConnection<Topics> {\n if (!config.appId) throwMissingAppId()\n\n const {appId} = config\n const installedProtocol = (installedMessageBus as Partial<InternalMessageBus>)[\n MESSAGE_BUS_PROTOCOL_KEY\n ]\n if (installedProtocol !== MESSAGE_BUS_PROTOCOL) {\n console.error(\n `[sanity-sdk:message-bus] protocol mismatch for \"${appId}\": installed ${String(installedProtocol)}, this copy speaks ${MESSAGE_BUS_PROTOCOL}`,\n )\n return createRejectedConnection(\n appId,\n () =>\n new MessageBusError(\n 'PROTOCOL_MISMATCH',\n `installed message bus speaks protocol ${String(installedProtocol)}, this copy speaks ${MESSAGE_BUS_PROTOCOL}`,\n ),\n )\n }\n\n const registry = (installedMessageBus as Partial<InternalMessageBus>)[MESSAGE_BUS_REGISTRY_KEY]\n if (!registry) {\n console.error(`[sanity-sdk:message-bus] incompatible message bus for \"${appId}\"`)\n return createRejectedConnection(\n appId,\n () =>\n new MessageBusError(\n 'PROTOCOL_MISMATCH',\n 'installed message bus does not expose a compatible registry',\n ),\n )\n }\n\n try {\n mergeTopicManifest(registry, DASHBOARD_TOPIC_MANIFEST)\n } catch (error) {\n console.error(`[sanity-sdk:message-bus] topic manifest conflict for \"${appId}\"`, {error})\n return createRejectedConnection(appId, () => error)\n }\n\n return createConnection(registry, config) as MessageBusConnection<Topics>\n}\n\n// Hands the host the same client object for a connection across `connections` subscriptions.\nfunction createClient(\n registry: MessageBusRegistry,\n record: ConnectionRecord,\n compatibility: TopicCompatibility,\n): MessageBusClient {\n return {\n appId: record.appId,\n moduleId: record.moduleId,\n closed: record.abort.signal,\n emit: (type: string, value: unknown) => {\n if (record.abort.signal.aborted) {\n console.warn(\n `[sanity-sdk:message-bus] \"${type}\" not written: connection \"${record.moduleId}\" has closed`,\n )\n return\n }\n emitState(registry, record, type, compatibility.toInstalledEmission(type, value))\n },\n reject: (type: string, message?: string) => {\n if (record.abort.signal.aborted) return\n record.rejections.set(type, message)\n record.rejected$.next(type)\n },\n } as MessageBusClient\n}\n\n// Open connections other than the host's own first, then each new one; one client object per\n// connection so the host can keep them in a Set. Completes when the host connection disconnects.\nfunction createConnectionsSource(\n registry: MessageBusRegistry,\n self: ConnectionRecord,\n compatibility: TopicCompatibility,\n completeOn: Observable<unknown>,\n): Observable<MessageBusClient> {\n const clients = new WeakMap<ConnectionRecord, MessageBusClient>()\n const clientFor = (record: ConnectionRecord) => {\n let client = clients.get(record)\n if (!client) {\n client = createClient(registry, record, compatibility)\n clients.set(record, client)\n }\n return client\n }\n return defer(() => concat(from([...registry.connections]), registry.connected$)).pipe(\n filter((record) => record !== self),\n map(clientFor),\n takeUntil(completeOn),\n )\n}\n\nfunction createConnection(\n registry: MessageBusRegistry,\n config: ConnectApplicationToMessageBusOptions,\n): MessageBusConnection {\n const {appId} = config\n const moduleId = config.moduleId ?? appId\n // Each connection owns its lifetime; disconnect() aborts it without touching siblings.\n const connectionAbort = new AbortController()\n const connectionSignal = connectionAbort.signal\n // ReplaySubject, not fromEvent: `abort` fires once, so a cold listener attached by a\n // stream subscribed after disconnect() would never see it and never complete. Replaying\n // the notification lets those late subscribers complete immediately.\n const connectionAborted$ = new ReplaySubject<void>(1)\n connectionSignal.addEventListener('abort', () => connectionAborted$.next(), {once: true})\n\n const record: ConnectionRecord = {\n appId,\n moduleId,\n stateSubjects: new Map(),\n rejections: new Map(),\n rejected$: new Subject<string>(),\n abort: connectionAbort,\n }\n\n const compatibility = createTopicCompatibility(\n registry.migrations,\n config.migrations ?? bundledMigrations(),\n )\n const isState = (type: string) => isStateTopic(registry, type)\n\n // Reuse topic streams because React external-store snapshots require stable references.\n const applicationStreams = new Map<string, MessageBusStateSource<unknown> | Observable<unknown>>()\n let streamGeneration = registry.generation\n const cachedStream = <T extends MessageBusStateSource<unknown> | Observable<unknown>>(\n type: string,\n create: () => T,\n ): T => {\n if (streamGeneration !== registry.generation) {\n applicationStreams.clear()\n streamGeneration = registry.generation\n }\n let stream = applicationStreams.get(type)\n if (!stream) {\n stream = create()\n applicationStreams.set(type, stream)\n }\n return stream as T\n }\n const stateSource = (type: string) =>\n cachedStream(type, () =>\n createStateSource(\n resolveStateSubject(registry, record, type),\n (value) => compatibility.toApplicationStateValue(type, value),\n connectionAborted$,\n ),\n )\n const eventStream = (type: string) =>\n cachedStream(type, () =>\n resolveEventSubject(registry, type).pipe(\n map((message) => compatibility.toApplicationEventPayload(type, message.payload)),\n takeUntil(connectionAborted$),\n ),\n )\n\n // A disconnected connection must not reach siblings, so its operations fail before touching\n // the shared registry rather than only tearing down pending requests and subscriptions.\n const throwIfDisconnected = () => {\n if (connectionSignal.aborted) throw new MessageBusError('ABORTED')\n }\n\n const connection = {\n appId,\n emit: (type: string, payload: unknown, options?: MessageBusEmitOptions) => {\n throwIfDisconnected()\n return migrateEventReply(\n emit(\n registry,\n type,\n compatibility.toInstalledEmission(type, payload),\n options,\n appId,\n moduleId,\n connectionSignal,\n ),\n (value) => compatibility.toApplicationEventReply(type, value),\n )\n },\n query: (type: string, options?: MessageBusQueryOptions) => {\n if (connectionSignal.aborted) return Promise.reject(new MessageBusError('ABORTED'))\n return query(\n stateSource(type),\n type,\n options,\n connectionSignal,\n registry.resetAbort.signal,\n record,\n )\n },\n subscribe: (\n type: string,\n handler?: (arg: never) => void,\n options?: MessageBusAbortOptions,\n ): MessageBusStateSource<unknown> | Observable<unknown> | undefined => {\n throwIfDisconnected()\n if (isState(type)) {\n const source = stateSource(type)\n if (!handler) return source\n unsubscribeOnAbort(\n source.subscribe(handler as (value: unknown) => void),\n scopeSignal(options?.signal, registry.resetAbort.signal, connectionSignal),\n )\n return undefined\n }\n if (!handler) return eventStream(type)\n respond(\n registry,\n type,\n (message) =>\n (handler as (message: MessageBusMessage<unknown, unknown>) => void)(\n migrateEventMessage(\n message,\n (value) => compatibility.toApplicationEventPayload(type, value),\n (value) => compatibility.toInstalledEventReply(type, value),\n ),\n ),\n options,\n appId,\n connectionSignal,\n )\n return undefined\n },\n disconnect: () => {\n if (connectionSignal.aborted) return\n connectionAbort.abort()\n for (const subject of record.stateSubjects.values()) subject.complete()\n record.stateSubjects.clear()\n record.rejected$.complete()\n registry.connections.delete(record)\n },\n }\n\n if (appId === registry.appId) {\n Object.assign(connection, {\n connections: createConnectionsSource(registry, record, compatibility, connectionAborted$),\n })\n }\n\n const instance = connection as unknown as InternalMessageBus\n instance[MESSAGE_BUS_REGISTRY_KEY] = registry\n instance[MESSAGE_BUS_PROTOCOL_KEY] = MESSAGE_BUS_PROTOCOL\n\n // Announce last: a host subscriber may write to the new client synchronously.\n registry.connections.add(record)\n registry.connected$.next(record)\n return instance as unknown as MessageBusConnection\n}\n\nfunction reset(registry: MessageBusRegistry): void {\n registry.resetAbort.abort()\n for (const connection of registry.connections) {\n for (const subject of connection.stateSubjects.values()) subject.complete()\n connection.stateSubjects.clear()\n connection.rejections.clear()\n }\n for (const subject of registry.eventSubjects.values()) subject.complete()\n\n registry.topics.clear()\n registry.eventSubjects.clear()\n registry.responderCounts.clear()\n registry.resetAbort = new AbortController()\n registry.generation += 1\n mergeTopicManifest(registry, DASHBOARD_TOPIC_MANIFEST)\n}\n\ndeclare const __SANITY_APP_ID__: string | undefined\n\nfunction throwMissingAppId(): never {\n throw new MessageBusError(\n 'MISSING_APP_ID',\n 'Cannot initialize the message bus without an app ID. Build the application with the Sanity CLI or pass an app ID when connecting.',\n )\n}\n\nconst resolveAppId = (appId?: string): string | undefined =>\n appId ?? (typeof __SANITY_APP_ID__ === 'string' ? __SANITY_APP_ID__ : undefined)\n\nfunction getInstalledMessageBus(): MessageBus | undefined {\n const bus = (globalThis as {[MESSAGE_BUS_KEY]?: unknown})[MESSAGE_BUS_KEY]\n return typeof bus === 'object' && bus !== null && MESSAGE_BUS_REGISTRY_KEY in bus\n ? (bus as unknown as MessageBus)\n : undefined\n}\n\n/**\n * Returns whether a message bus registry is installed.\n * @internal\n */\nexport function isMessageBusInstalled(): boolean {\n return getInstalledMessageBus() !== undefined\n}\n\n/**\n * Options for connecting to an installed message bus.\n * @public\n */\nexport interface ConnectMessageBusOptions {\n /** The application ID. Defaults to the ID embedded by the Sanity CLI. */\n appId?: string\n /** The federation module id stamped on emitted messages. Defaults to `appId`. */\n moduleId?: string\n}\n\n/**\n * Connects to the installed message bus, or returns `undefined` when no compatible connection exists.\n * @public\n */\nexport function connectMessageBus(\n options: ConnectMessageBusOptions = {},\n): MessageBusConnection | undefined {\n const installedMessageBus = getInstalledMessageBus()\n if (!installedMessageBus) return undefined\n\n const appId = resolveAppId(options.appId)\n if (!appId) {\n console.warn(\n '[sanity-sdk:message-bus] cannot connect without an app ID; build with the Sanity CLI or pass appId',\n )\n return undefined\n }\n\n const connection = connectApplicationToMessageBus(installedMessageBus, {\n appId,\n moduleId: options.moduleId,\n })\n return MESSAGE_BUS_REGISTRY_KEY in connection ? connection : undefined\n}\n\n/**\n * Resets the installed message bus for test isolation.\n * @internal\n */\nexport function resetMessageBus(): void {\n const installedMessageBus = getInstalledMessageBus()\n if (!installedMessageBus) return\n reset((installedMessageBus as InternalMessageBus)[MESSAGE_BUS_REGISTRY_KEY])\n}\n\n/**\n * Options for installing the shared message bus. The host is the whole app, so it carries\n * no `moduleId`.\n * @internal\n */\nexport interface InstallMessageBusOptions {\n /** The application ID. Defaults to the ID embedded by the Sanity CLI. */\n appId?: string\n}\n\n/**\n * Installs the shared message bus and returns the host's connection, or connects to its\n * existing installation. Only the host calls this; another app's ID is rejected because the\n * connection it would get has no `connections`.\n * @internal\n */\nexport function installMessageBus(options: InstallMessageBusOptions = {}): MessageBusHost<Topics> {\n const appId = resolveAppId(options.appId) ?? throwMissingAppId()\n const installedMessageBus = getInstalledMessageBus()\n if (installedMessageBus) {\n const installedAppId = (installedMessageBus as InternalMessageBus)[MESSAGE_BUS_REGISTRY_KEY]\n .appId\n if (installedAppId !== appId) {\n throw new MessageBusError(\n 'OWNERSHIP_MISMATCH',\n `Cannot install the message bus as \"${appId}\": it is already installed by \"${installedAppId}\". Applications connect with connectMessageBus().`,\n )\n }\n return connectApplicationToMessageBus(installedMessageBus, {\n appId,\n }) as MessageBusHost<Topics>\n }\n\n const globals = globalThis as {[MESSAGE_BUS_KEY]?: MessageBus}\n if (globals[MESSAGE_BUS_KEY]) {\n // A foreign value already occupies the bus symbol (e.g. an older Workbench bus); overwriting it disconnects that bus.\n console.error(\n '[sanity-sdk:message-bus] overwriting an incompatible message bus already installed',\n )\n }\n const host = createIsolatedMessageBus(appId)\n globals[MESSAGE_BUS_KEY] = host\n return host\n}\n\n/**\n * Declares state topics that are not in the bundled manifest, with the seed a new\n * connection's box starts from.\n * @internal\n */\nexport function registerStateTopics(\n target: MessageBus,\n topics: Partial<{[K in StateTopic]: ValueOf<K> | undefined}>,\n): void {\n const registry = (target as InternalMessageBus)[MESSAGE_BUS_REGISTRY_KEY]\n const manifest: TopicManifest = Object.fromEntries(\n Object.entries(topics).map(([name, seed]) => [name, {kind: 'state', seed}]),\n )\n mergeTopicManifest(registry, manifest)\n}\n","import {createActionBinder} from '../../store/createActionBinder'\nimport {type SanityInstance} from '../../store/createSanityInstance'\nimport {defineStore} from '../../store/defineStore'\nimport {connectMessageBus, isMessageBusInstalled, type MessageBusConnection} from './bus'\n\ninterface DashboardMessageBusState {\n connection?: MessageBusConnection\n}\n\nconst bindActionByInstance = createActionBinder<{name: string}, [moduleId?: string]>(\n (instance) => ({name: instance.instanceId}),\n)\n\nconst dashboardMessageBusStore = defineStore<DashboardMessageBusState>({\n name: 'dashboardMessageBus',\n getInitialState: () => ({}),\n // Runs when the instance is disposed, tearing down this window's connection.\n initialize:\n ({state}) =>\n () =>\n state.get().connection?.disconnect(),\n})\n\n/**\n * Returns the message bus connection for this instance, connecting on first call.\n *\n * @remarks\n * One connection is made per {@link SanityInstance}, carrying that window's\n * module identity. The first caller wins; later callers get the cached\n * connection. When no host bus is installed it returns `undefined` without\n * caching, so a later call retries once a host installs the bus.\n * @internal\n */\nexport const getDashboardMessageBus = bindActionByInstance(\n dashboardMessageBusStore,\n ({state}, moduleId?: string): MessageBusConnection | undefined => {\n const current = state.get().connection\n if (current) return current\n if (!isMessageBusInstalled()) return undefined\n const connection = connectMessageBus({moduleId})\n if (!connection) return undefined\n state.set('connect', {connection})\n return connection\n },\n)\n\n/**\n * Returns the instance's message bus connection, or throws when no dashboard host has\n * installed a bus. `action` names what the caller was about to do, e.g. `read topic \"x\"`.\n * @internal\n */\nexport function requireDashboardMessageBus(\n instance: SanityInstance,\n action: string,\n): MessageBusConnection {\n const messageBus = getDashboardMessageBus(instance)\n if (!messageBus) {\n throw new Error(`Cannot ${action} without an installed dashboard message bus`)\n }\n return messageBus\n}\n\n/**\n * Returns whether a dashboard host has installed a message bus.\n *\n * @remarks\n * Answers \"does a host own this session\", not \"has this instance connected yet\". Callers\n * such as the login redirect run before {@link getDashboardMessageBus} has been called for\n * the instance, so this must not depend on the connection state.\n * @internal\n */\nexport function isDashboardEnvironment(): boolean {\n return isMessageBusInstalled()\n}\n","import {createActionBinder} from '../../store/createActionBinder'\nimport {type SanityInstance} from '../../store/createSanityInstance'\nimport {createStateSourceAction} from '../../store/createStateSourceAction'\nimport {defineStore} from '../../store/defineStore'\nimport {setCleanupTimeout} from '../../utils/setCleanupTimeout'\nimport {type MessageBus, type MessageBusStateSource} from './bus'\nimport {requireDashboardMessageBus} from './store'\nimport {type StateTopic, type ValueOf} from './topics'\n\n/**\n * An error raised when a dashboard state topic reports failure.\n * @public\n */\nexport class TopicError extends Error {\n /** The topic that failed. */\n readonly topic: StateTopic\n\n /** Creates an error for a failed topic. */\n constructor(topic: StateTopic) {\n super(`Topic \"${topic}\" failed`)\n this.name = 'TopicError'\n this.topic = topic\n }\n}\n\n/**\n * The value of a state topic, with `TopicResult` wrappers unwrapped to their success value.\n * @public\n */\nexport type TopicData<K extends StateTopic> =\n ValueOf<K> extends infer Value\n ? Value extends {ok: true; value: infer Success}\n ? Success\n : Value extends {ok: false}\n ? never\n : Value\n : never\n\n// Mirrors the `TopicResult` shape declared in the topic manifest; no plain-value topic has an `ok` field.\nfunction isTopicResult(value: unknown): value is {ok: boolean; value?: unknown} {\n return (\n typeof value === 'object' && value !== null && 'ok' in value && typeof value.ok === 'boolean'\n )\n}\n\nfunction unwrapTopicResult(topic: StateTopic, value: unknown): unknown {\n if (!isTopicResult(value)) return value\n if (!value.ok) throw new TopicError(topic)\n return value.value\n}\n\ninterface TopicEntry {\n /** Why the first-value query failed. Dropped with the entry when its last subscriber leaves. */\n error?: unknown\n /** The in-flight first-value query, shared by every suspended render of the topic. */\n pending?: Promise<void>\n subscribers: number\n}\n\ninterface DashboardTopicsState {\n topics: {[topic: string]: TopicEntry}\n}\n\n// Matches the query store: a suspended component re-renders after its promise settles before\n// the temporary subscriber is released, so it still sees the recorded failure.\nconst TOPIC_STATE_CLEAR_DELAY = 1000\n\nconst bindActionByInstance = createActionBinder<{name: string}, [topic: StateTopic]>(\n (instance) => ({name: instance.instanceId}),\n)\n\n// The bus is the source of truth for topic values (it already keeps one replaying source per\n// topic). This store only tracks what the bus cannot: read failures and who is still reading.\nconst dashboardTopicsStore = defineStore<DashboardTopicsState>({\n name: 'dashboardTopics',\n getInitialState: () => ({topics: {}}),\n})\n\nconst getMessageBus = (instance: SanityInstance, topic: StateTopic): MessageBus =>\n requireDashboardMessageBus(instance, `read topic \"${topic}\"`)\n\nfunction getSource(instance: SanityInstance, topic: StateTopic): MessageBusStateSource<unknown> {\n return getMessageBus(instance, topic).subscribe(topic)\n}\n\n// An entry lives as long as it has subscribers. Dropping it with the last one is what gives a\n// later mount a fresh deadline instead of a stale failure.\nconst updateEntry =\n (topic: string, update: (entry: TopicEntry) => TopicEntry) =>\n (state: DashboardTopicsState): DashboardTopicsState => {\n const {[topic]: entry = {subscribers: 0}, ...rest} = state.topics\n const next = update(entry)\n return {topics: next.subscribers > 0 ? {...rest, [topic]: next} : rest}\n }\n\nconst addSubscriber = (topic: string) =>\n updateEntry(topic, (entry) => ({...entry, subscribers: entry.subscribers + 1}))\n\nconst removeSubscriber = (topic: string) =>\n updateEntry(topic, (entry) => ({...entry, subscribers: entry.subscribers - 1}))\n\n/**\n * A state source for a dashboard state topic, with `TopicResult` wrappers unwrapped.\n *\n * @remarks\n * Returns `undefined` until the topic publishes; use {@link resolveTopic} to wait for that\n * first value. While the topic is still unpublished, reading throws the failure that\n * {@link resolveTopic} recorded. A published value takes precedence over a recorded failure,\n * and a {@link TopicError} is thrown when the topic itself reports failure. A thrown failure\n * ends the subscription, so a reader recovers by subscribing again.\n * @internal\n */\nexport const getTopicState = bindActionByInstance(\n dashboardTopicsStore,\n createStateSourceAction({\n selector: ({state, instance}, topic: StateTopic) => {\n const current = getSource(instance, topic).getCurrent()\n // A recorded failure only describes the wait for a first value; a published value wins.\n const entry = state.topics[topic]\n if (current === undefined && entry?.error) throw entry.error\n return unwrapTopicResult(topic, current)\n },\n onSubscribe: ({state, instance}, topic: StateTopic) => {\n state.set('addSubscriber', addSubscriber(topic))\n // Each publish writes a fresh state object so the selector re-runs against the bus.\n const subscription = getSource(instance, topic).subscribe(() =>\n state.set(\n 'publish',\n updateEntry(topic, (entry) => ({...entry})),\n ),\n )\n return () => {\n subscription.unsubscribe()\n setCleanupTimeout(\n () => state.set('removeSubscriber', removeSubscriber(topic)),\n TOPIC_STATE_CLEAR_DELAY,\n )\n }\n },\n }),\n)\n\n/**\n * Resolves once a dashboard state topic has published, or records the failure for\n * {@link getTopicState} to throw. Repeated calls for a pending topic share one query.\n *\n * @remarks\n * Holds a temporary subscriber while the query is in flight so a failure recorded after the\n * reading component has gone is dropped with it, rather than thrown at the next mount.\n * @internal\n */\nexport const resolveTopic = bindActionByInstance(\n dashboardTopicsStore,\n ({state, instance}, topic: StateTopic): Promise<void> => {\n const existing = state.get().topics[topic]?.pending\n if (existing) return existing\n\n const release = () =>\n setCleanupTimeout(\n () => state.set('removeSubscriber', removeSubscriber(topic)),\n TOPIC_STATE_CLEAR_DELAY,\n )\n const pending = getMessageBus(instance, topic)\n .query(topic)\n .then(\n () =>\n state.set(\n 'resolved',\n updateEntry(topic, ({pending: _pending, ...entry}) => entry),\n ),\n (error: unknown) =>\n state.set(\n 'failed',\n updateEntry(topic, ({pending: _pending, ...entry}) => ({...entry, error})),\n ),\n )\n pending.then(release, release)\n state.set(\n 'query',\n updateEntry(topic, (entry) => ({...entry, pending, subscribers: entry.subscribers + 1})),\n )\n return pending\n },\n)\n"],"mappings":";;;;;;;;;;;;AAwCA,MAAa,eAAe;CAAC;CAAkB;CAAa;AAAS,GAkO/D,cAAuB,UAAa;CAAC,MAAM;CAAS;AAAI,IAGxD,iBAAiB;CAAC,MAAM;CAAS,WAAW,EAAC,MAAM,WAAU;AAAC,GAUvD,2BAAmD;CAC9D,yBAAyB;CACzB,0BAA0B,WAAW,KAAA,CAAS;CAC9C,6BAA6B,WAAW,KAAA,CAAS;CACjD,uBAAuB,WAAW,KAAA,CAAS;CAC3C,wBAAwB,WAAW,KAAA,CAAS;CAC5C,+BAA+B;CAC/B,2BAA2B,WAAW,KAAA,CAAS;CAC/C,qBAAqB,WAAW,KAAA,CAAS;CACzC,8BAA8B;CAC9B,cAAc,WAAW,KAAA,CAAS;CAClC,sBAAsB;CACtB,uBAAuB,WAAW,KAAA,CAAS;CAC3C,8BAA8B;CAC9B,yBAAyB,WAAW,KAAA,CAAS;CAC7C,eAAe,WAAW;EAAC,IAAI;EAAM,OAAO;CAAI,CAAC;CACjD,mBAAmB;CACnB,4BAA4B,WAAW,KAAA,CAAS;CAChD,2BAA2B,WAAW,KAAA,CAAS;CAC/C,iBAAiB,WAAW,KAAA,CAAS;AACvC,GAqEa,kBAAyE,CAAC;;;;;AC9TvF,IAAa,kBAAb,cAAqC,MAAM;;CAKzC,YAAY,MAA2B,SAAkB,SAA6B;EAGpF,AAFA,MAAM,WAAW,MAAM,OAAO,GAJvB,gBAAA,MAAA,QAAA,KAAA,CAAA,GAKP,KAAK,OAAO,mBACZ,KAAK,OAAO;CACd;AACF;AAiMA,MAAM,kBAAkB,OAAO,IAAI,eAAe,GAC5C,2BAA2B,OAAO,IAAI,oBAAoB,GAC1D,2BAA2B,OAAO,IAAI,oBAAoB,GAC1D,g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,YAAY,QAAQ,WAAW,EAAC,GAAG,MAAK,EAAE,CAC5C,CACF;EACA,aAAa;GAEX,AADA,aAAa,YAAY,GACzB,wBACQ,MAAM,IAAI,oBAAoB,iBAAiB,KAAK,CAAC,GAC3D,uBACF;EACF;CACF;AACF,CAAC,CACH,GAWa,eAAe,qBAC1B,uBACC,EAAC,OAAO,YAAW,UAAqC;CACvD,IAAM,WAAW,MAAM,IAAI,CAAC,CAAC,OAAO,MAAM,EAAE;CAC5C,IAAI,UAAU,OAAO;CAErB,IAAM,gBACJ,wBACQ,MAAM,IAAI,oBAAoB,iBAAiB,KAAK,CAAC,GAC3D,uBACF,GACI,UAAU,cAAc,UAAU,KAAK,CAAC,CAC3C,MAAM,KAAK,CAAC,CACZ,WAEG,MAAM,IACJ,YACA,YAAY,QAAQ,EAAC,SAAS,UAAU,GAAG,YAAW,KAAK,CAC7D,IACD,UACC,MAAM,IACJ,UACA,YAAY,QAAQ,EAAC,SAAS,UAAU,GAAG,aAAY;EAAC,GAAG;EAAO;CAAK,EAAE,CAC3E,CACJ;CAMF,OALA,QAAQ,KAAK,SAAS,OAAO,GAC7B,MAAM,IACJ,SACA,YAAY,QAAQ,WAAW;EAAC,GAAG;EAAO;EAAS,aAAa,MAAM,cAAc;CAAC,EAAE,CACzF,GACO;AACT,CACF"}
@@ -1,4 +1,4 @@
1
- import { Bi as BoundStoreAction, a as ApplicationInclude, t as Application, zi as StateSource, zt as OrganizationBase } from "./applications-903KQTrD.js";
1
+ import { Bi as BoundStoreAction, a as ApplicationInclude, t as Application, zi as StateSource, zt as OrganizationBase } from "./applications-Bb-0Kgkc.js";
2
2
  import { Observable } from "rxjs";
3
3
  import { CurrentUser } from "@sanity/types";
4
4
  /**
@@ -26,6 +26,47 @@ interface ApplicationConfig extends RemoteModuleRef {
26
26
  readonly appId?: Application['id'];
27
27
  readonly appType: ApplicationConfigAppType;
28
28
  }
29
+ /**
30
+ * The capabilities a host can provide.
31
+ *
32
+ * Reuses the Studio's rendering-context identifiers so an application can hide its own
33
+ * implementation of anything the host provides.
34
+ * @public
35
+ */
36
+ declare const capabilities: readonly ["globalUserMenu", "favorites", "history"];
37
+ /**
38
+ * A capability a host can provide.
39
+ * @public
40
+ */
41
+ type Capability = (typeof capabilities)[number];
42
+ /**
43
+ * The capabilities the host provides. A missing key means the host does not provide it.
44
+ * @public
45
+ */
46
+ type CapabilityRecord = Partial<Record<Capability, boolean>>;
47
+ /**
48
+ * A document a user viewed, edited, created, or deleted in an application.
49
+ * @public
50
+ */
51
+ interface DocumentActivity {
52
+ readonly kind: 'document';
53
+ readonly eventType: 'viewed' | 'edited' | 'created' | 'deleted';
54
+ readonly document: {
55
+ readonly id: string;
56
+ readonly type: string;
57
+ readonly resource: {
58
+ readonly id: string;
59
+ readonly type: 'dataset' | 'media-library' | 'canvas';
60
+ /** Schema collection the document belongs to; the workspace name for studios. */
61
+ readonly schemaName?: string;
62
+ };
63
+ };
64
+ }
65
+ /**
66
+ * Activity an application reports to the host. Discriminated on `kind`.
67
+ * @public
68
+ */
69
+ type ApplicationActivity = DocumentActivity;
29
70
  /**
30
71
  * A label rendered for an application interface; `null` clears it.
31
72
  * @internal
@@ -43,6 +84,21 @@ type ApplicationStatusUpdate = {
43
84
  /** The status to render. */
44
85
  value: ApplicationStatus;
45
86
  };
87
+ /**
88
+ * What an application is currently showing: the Comlink agent resource context, made generic.
89
+ * @public
90
+ */
91
+ interface ApplicationContext {
92
+ /** The resource the application is working in. Types follow `@sanity/client`'s resource config. */
93
+ readonly resource: {
94
+ readonly id: string;
95
+ readonly type: 'dataset' | 'media-library' | 'canvas';
96
+ };
97
+ /** The open document, or `null` when none is open. */
98
+ readonly document: {
99
+ readonly id: string;
100
+ } | null;
101
+ }
46
102
  /**
47
103
  * Declares a topic that stores and replays its current value.
48
104
  * @public
@@ -98,14 +154,24 @@ type NavigationLocation = NavigationTarget & {
98
154
  * @public
99
155
  */
100
156
  interface DashboardTopics {
157
+ /** Reports user activity in an application, e.g. for the recents feed. Fire-and-forget. */
158
+ 'applications.activity': EventTopicDef<ApplicationActivity>;
101
159
  /**
102
160
  * The base path for an application.
103
161
  *
104
162
  * An unknown application returns `{ok: false}`.
105
163
  */
106
164
  'applications.base-path': StateTopicDef<TopicResult<string>>;
165
+ /** The capabilities the host provides. A missing key means the host does not provide it. */
166
+ 'applications.capabilities': StateTopicDef<CapabilityRecord>;
107
167
  /** The available application configuration modules. */
108
168
  'applications.config': StateTopicDef<ApplicationConfig[] | null>;
169
+ /** The foreground application's context, or `null` when it has published none. */
170
+ 'applications.context': StateTopicDef<(ApplicationContext & {
171
+ readonly appId: Application['id'];
172
+ }) | null>;
173
+ /** Publishes the sending application's context. `null` clears it. Fire-and-forget. */
174
+ 'applications.context.update': EventTopicDef<ApplicationContext | null>;
109
175
  /** The foreground application ID, or `null` on dashboard-level routes. */
110
176
  'applications.foreground': StateTopicDef<Application['id'] | null>;
111
177
  /** The dashboard applications available to the current user. */
@@ -214,7 +280,7 @@ type ReplyOf<K extends EventTopic<TTopics>, TTopics = Topics> = TTopics[K] exten
214
280
  * A message bus protocol error code.
215
281
  * @public
216
282
  */
217
- type MessageBusErrorCode = 'NO_RESPONDER' | 'TIMEOUT' | 'ABORTED' | 'HANDLER_THREW' | 'PROTOCOL_MISMATCH' | 'OWNERSHIP_MISMATCH' | 'MISSING_APP_ID';
283
+ type MessageBusErrorCode = 'NO_RESPONDER' | 'TIMEOUT' | 'ABORTED' | 'HANDLER_THREW' | 'PROTOCOL_MISMATCH' | 'OWNERSHIP_MISMATCH' | 'MISSING_APP_ID' | 'REFUSED';
218
284
  /**
219
285
  * An error raised by the message bus protocol.
220
286
  * @public
@@ -256,6 +322,12 @@ interface MessageBusMessage<T, R = never, K extends PropertyKey = TopicName> {
256
322
  meta: MessageBusMeta;
257
323
  /** Replies to an awaiting sender. */
258
324
  reply(value: R): void;
325
+ /**
326
+ * Refuses the message: the sender's awaited `emit()` rejects with a
327
+ * {@link MessageBusError} whose `code` is `'REFUSED'`. Ignored, with a warning,
328
+ * once the reply has already settled.
329
+ */
330
+ reject(message?: string): void;
259
331
  /** Aborts when the sender stops waiting for a reply. */
260
332
  readonly signal: AbortSignal;
261
333
  }
@@ -330,6 +402,8 @@ interface MessageBus<TTopics = MessageBusTopics> {
330
402
  * @public
331
403
  */
332
404
  interface MessageBusConnection<TTopics = MessageBusTopics> extends MessageBus<TTopics> {
405
+ /** The application this connection belongs to. */
406
+ readonly appId: Application['id'];
333
407
  /**
334
408
  * Tears down this connection: pending requests reject `ABORTED`, subscriptions
335
409
  * complete, and later `emit`, `query`, and `subscribe` calls fail with `ABORTED`.
@@ -350,6 +424,19 @@ interface MessageBusClient {
350
424
  readonly closed: AbortSignal;
351
425
  /** Writes a state value to this connection only. Ignored once the connection has closed. */
352
426
  emit<K extends StateTopic>(type: K, value: ValueOf<K>): void;
427
+ /**
428
+ * Rejects a state topic for this connection: its pending and later {@link MessageBus.query}
429
+ * calls reject with a {@link MessageBusError} whose `code` is `'REFUSED'`, until the host next
430
+ * writes a value with {@link MessageBusClient.emit}, which clears the rejection.
431
+ *
432
+ * @remarks
433
+ * A rejected promise cannot be un-rejected and an errored subject cannot resume, so the
434
+ * rejection is tracked per connection alongside the topic's subject rather than by erroring
435
+ * it: `query` consults it before awaiting, and {@link MessageBus.subscribe} and the topic's
436
+ * {@link MessageBusStateSource} stay silent (they never error) until a value is written.
437
+ * Ignored once the connection has closed, the same as {@link MessageBusClient.emit}.
438
+ */
439
+ reject<K extends StateTopic>(type: K, message?: string): void;
353
440
  }
354
441
  /**
355
442
  * The host's connection to the bus.
@@ -460,5 +547,5 @@ declare const getTopicState: BoundStoreAction<DashboardTopicsState, [topic: Stat
460
547
  * @internal
461
548
  */
462
549
  declare const resolveTopic: BoundStoreAction<DashboardTopicsState, [topic: StateTopic], Promise<void>>;
463
- export { MessageBusTopics as A, Topics as B, ApplicationConfig as C, DashboardTopics as D, ApplicationStatusUpdate as E, ReplyOf as F, StateTopic as I, StateTopicDef as L, NavigationTarget as M, PayloadOf as N, EventTopic as O, RemoteModuleRef as P, TopicName as R, resetMessageBus as S, ApplicationStatus as T, ValueOf as V, MessageBusMeta as _, ConnectMessageBusOptions as a, connectMessageBus as b, MessageBusAbortOptions as c, MessageBusEmitOptions as d, MessageBusEmitResult as f, MessageBusMessage as g, MessageBusHost as h, resolveTopic as i, NavigationLocation as j, EventTopicDef as k, MessageBusClient as l, MessageBusErrorCode as m, TopicError as n, InstallMessageBusOptions as o, MessageBusError as p, getTopicState as r, MessageBus as s, TopicData as t, MessageBusConnection as u, MessageBusQueryOptions as v, ApplicationConfigAppType as w, installMessageBus as x, MessageBusStateSource as y, TopicResult as z };
464
- //# sourceMappingURL=topicStore-VQILEI1R.d.ts.map
550
+ export { CapabilityRecord as A, ReplyOf as B, ApplicationActivity as C, ApplicationStatus as D, ApplicationContext as E, MessageBusTopics as F, Topics as G, StateTopicDef as H, NavigationLocation as I, ValueOf as K, NavigationTarget as L, DocumentActivity as M, EventTopic as N, ApplicationStatusUpdate as O, EventTopicDef as P, PayloadOf as R, resetMessageBus as S, ApplicationConfigAppType as T, TopicName as U, StateTopic as V, TopicResult as W, MessageBusMeta as _, ConnectMessageBusOptions as a, connectMessageBus as b, MessageBusAbortOptions as c, MessageBusEmitOptions as d, MessageBusEmitResult as f, MessageBusMessage as g, MessageBusHost as h, resolveTopic as i, DashboardTopics as j, Capability as k, MessageBusClient as l, MessageBusErrorCode as m, TopicError as n, InstallMessageBusOptions as o, MessageBusError as p, capabilities as q, getTopicState as r, MessageBus as s, TopicData as t, MessageBusConnection as u, MessageBusQueryOptions as v, ApplicationConfig as w, installMessageBus as x, MessageBusStateSource as y, RemoteModuleRef as z };
551
+ //# sourceMappingURL=topicStore-fPK2CfqH.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topicStore-fPK2CfqH.d.ts","names":[],"sources":["../src/dashboard/messageBus/topics.ts","../src/dashboard/messageBus/bus.ts","../src/dashboard/messageBus/topicStore.ts"],"mappings":";;;;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AkB,UAAU,GAAG,UAAU,QAAQ,GAAG,UAAU,aACjF,UAAU;;EAGZ,UAAU,UAAU,WAAW,UAC7B,MAAM,GACN,UAAU,OAAO,QAAQ,GAAG,mBAC5B,UAAU;;EAGZ,UAAU,UAAU,WAAW,UAAU,MAAM,IAAI,sBAAsB,QAAQ,GAAG;;EAEpF,UAAU,UAAU,WAAW,UAAU,MAAM,IAAI,WAAW,UAAU,GAAG;;;;;;UAO5D,qBAAqB,UAAU,0BAA0B,WAAW;;WAE1E,OAAO;;;;;;EAMhB;;;;;;UAOe;;WAEN,OAAO;;WAEP;;WAEA,QAAQ;;EAEjB,KAAK,UAAU,YAAY,MAAM,GAAG,OAAO,QAAQ;;;;;;;;;;;;;EAanD,OAAO,UAAU,YAAY,MAAM,GAAG;;;;;;;;;;;;UAavB,eAAe,UAAU,0BAA0B,qBAAqB;;;;;;;WAO9E,aAAa,WAAW;;;;;;UAk9BlB;;EAEf;;EAEA;;;;;;iBAOc,kBACd,UAAS,2BACR;;;;;iBAuBa;;;;;;UAWC;;EAEf;;;;;;;;iBASc,kBAAkB,UAAS,2BAAgC,eAAe;;;;;cCzvC7E,mBAAmB;;WAErB,OAAO;;EAGJ,YAAA,OAAO;;;;;;KAWT,UAAU,UAAU,cAC9B,QAAQ,kBAAiB,SACrB;EAAe;EAAU,aAAa;IACpC,UACA;EAAe;YAEb;UAgBA;;EAER;;EAEA,UAAU;EACV;;UAGQ;EACR;KAAU,gBAAgB;;;;;;;;;;;;;;cAoDf,eAAa,iBAAA,uBAAA,OAAA,aAAA;;;;;;;;;;cAuCb,cAAY,iBAAA,uBAAA,OAAA,aAAA"}
@@ -1,4 +1,4 @@
1
- import { n as getClient, r as getClientState } from "./clientStore-QDrJNTM4.js";
1
+ import { n as getClient, r as getClientState } from "./clientStore-CD-USpIU.js";
2
2
  import { c as isReleasePerspective, i as bindActionGlobally, n as bindActionByResource, o as defineStore, s as getEnv, t as createStateSourceAction, u as isDatasetResource } from "./createStateSourceAction-DdAhEfnZ.js";
3
3
  import { r as omitProperty } from "./object-CxXlSVg7.js";
4
4
  import { n as setCleanupTimeout, t as setCleanupInterval } from "./setCleanupTimeout-BiM6q1KF.js";
@@ -1372,7 +1372,7 @@ const _resolveQuery = bindActionByResource(queryStore, ({ state, instance }, { s
1372
1372
  }, QUERY_STATE_CLEAR_DELAY);
1373
1373
  };
1374
1374
  return promise.then(releaseSubscriber, releaseSubscriber), promise;
1375
- }), CORE_SDK_VERSION = getEnv("PKG_VERSION") || "3.4.0-rc.0-development";
1375
+ }), CORE_SDK_VERSION = getEnv("PKG_VERSION") || "3.4.0-development";
1376
1376
  export { clearPendingTransaction as A, assertDatasetResource as B, getCommentsState as C, toCommentsKeyParts as D, resolveComments as E, rollbackCommentUpdate as F, defineMutation as G, provisionAddonDataset as H, setCommentCreateError as I, randomId as K, setPendingTransaction as L, receiveComment as M, removeCommentById as N, addComment as O, restoreComments as P, normalizeComment as R, getCommentsOptionsKey as S, resolveCommentThreads as T, COMMENTS_API_VERSION as U, getAddonDatasetState as V, defineFetcher as W, updateLastLoadMoreRequest as _, resolveQuery as a, commentsStore as b, getAllReleasesState as c, getUsersKey as d, initializeRequest as f, setUsersError as g, setUsersData as h, parseQueryKey as i, getCommentsKey as j, applyCommentUpdate as k, addSubscription as l, removeSubscription as m, getQueryKey as n, getPerspectiveState as o, parseUsersKey as p, randomUuid as q, getQueryState as r, getActiveReleasesState as s, CORE_SDK_VERSION as t, cancelRequest as u, PROJECT_API_VERSION as v, parseCommentsOptionsKey as w, getCommentThreadsState as x, USERS_STATE_CLEAR_DELAY as y, toCommentFieldPath as z };
1377
1377
 
1378
- //# sourceMappingURL=version-CYqZgJX1.js.map
1378
+ //# sourceMappingURL=version-C7m7OAy9.js.map