@sanity/sdk 3.0.0-rc.0 → 3.0.0-rc.2

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 (241) hide show
  1. package/README.md +12 -0
  2. package/dist/_exports/_internal.d.ts +163 -0
  3. package/dist/_exports/_internal.d.ts.map +1 -0
  4. package/dist/_exports/_internal.js +332 -0
  5. package/dist/_exports/_internal.js.map +1 -0
  6. package/dist/_exports/agent.d.ts +65 -0
  7. package/dist/_exports/agent.d.ts.map +1 -0
  8. package/dist/_exports/agent.js +71 -0
  9. package/dist/_exports/agent.js.map +1 -0
  10. package/dist/_exports/comlink.d.ts +118 -0
  11. package/dist/_exports/comlink.d.ts.map +1 -0
  12. package/dist/_exports/comlink.js +69 -0
  13. package/dist/_exports/comlink.js.map +1 -0
  14. package/dist/authStore-CtE9bLHW.js +754 -0
  15. package/dist/authStore-CtE9bLHW.js.map +1 -0
  16. package/dist/authStore-DKFX8fn7.d.ts +3179 -0
  17. package/dist/authStore-DKFX8fn7.d.ts.map +1 -0
  18. package/dist/clientStore-BtE2-q2i.js +90 -0
  19. package/dist/clientStore-BtE2-q2i.js.map +1 -0
  20. package/dist/createSanityInstance-DUI1bGIg.d.ts +278 -0
  21. package/dist/createSanityInstance-DUI1bGIg.d.ts.map +1 -0
  22. package/dist/createStateSourceAction-BOKtqFNm.js +300 -0
  23. package/dist/createStateSourceAction-BOKtqFNm.js.map +1 -0
  24. package/dist/getEnv-D5RGkQLu.js +8 -0
  25. package/dist/getEnv-D5RGkQLu.js.map +1 -0
  26. package/dist/getNodeState-CR3__B2D.js +67 -0
  27. package/dist/getNodeState-CR3__B2D.js.map +1 -0
  28. package/dist/index.d.ts +3 -2332
  29. package/dist/index.js +4171 -4332
  30. package/dist/index.js.map +1 -1
  31. package/dist/logger-DAtJb5RQ.js +173 -0
  32. package/dist/logger-DAtJb5RQ.js.map +1 -0
  33. package/dist/object-CxXlSVg7.js +83 -0
  34. package/dist/object-CxXlSVg7.js.map +1 -0
  35. package/dist/queryStore-DPf9sN3V.js +1346 -0
  36. package/dist/queryStore-DPf9sN3V.js.map +1 -0
  37. package/dist/rolldown-runtime-vyAXikos.js +9 -0
  38. package/dist/setCleanupTimeout-BiM6q1KF.js +31 -0
  39. package/dist/setCleanupTimeout-BiM6q1KF.js.map +1 -0
  40. package/dist/telemetryManager-Dq_qCkeI.js +127 -0
  41. package/dist/telemetryManager-Dq_qCkeI.js.map +1 -0
  42. package/dist/version-BChjsi4u.js +9 -0
  43. package/dist/version-BChjsi4u.js.map +1 -0
  44. package/package.json +47 -52
  45. package/src/_exports/_internal.ts +27 -0
  46. package/src/_exports/agent.ts +19 -0
  47. package/src/_exports/comlink.ts +16 -0
  48. package/src/_exports/index.ts +125 -64
  49. package/src/access/checkPermissions.test.ts +55 -0
  50. package/src/access/checkPermissions.ts +54 -0
  51. package/src/agent/agentActions.test.ts +16 -60
  52. package/src/agent/agentActions.ts +25 -38
  53. package/src/applications/applications.test-d.ts +88 -0
  54. package/src/applications/applications.test.ts +130 -0
  55. package/src/applications/applications.ts +367 -0
  56. package/src/auth/authLogger.ts +30 -0
  57. package/src/auth/authStore.test.ts +194 -13
  58. package/src/auth/authStore.ts +58 -26
  59. package/src/auth/getOrganizationVerificationState.test.ts +18 -17
  60. package/src/auth/getOrganizationVerificationState.ts +4 -4
  61. package/src/auth/handleAuthCallback.test.ts +35 -1
  62. package/src/auth/handleAuthCallback.ts +25 -6
  63. package/src/auth/logout.test.ts +75 -2
  64. package/src/auth/logout.ts +23 -4
  65. package/src/auth/refreshStampedToken.test.ts +219 -469
  66. package/src/auth/refreshStampedToken.ts +79 -195
  67. package/src/auth/studioAuth.ts +1 -1
  68. package/src/auth/studioModeAuth.ts +2 -1
  69. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +146 -13
  70. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +37 -6
  71. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +2 -0
  72. package/src/client/clientStore.test.ts +62 -37
  73. package/src/client/clientStore.ts +45 -75
  74. package/src/client/liveEvents.test.ts +151 -0
  75. package/src/client/liveEvents.ts +107 -0
  76. package/src/comlink/controller/actions/destroyController.test.ts +4 -1
  77. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +4 -1
  78. package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
  79. package/src/comlink/controller/actions/getOrCreateController.test.ts +4 -1
  80. package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
  81. package/src/comlink/controller/comlinkControllerStore.test.ts +4 -1
  82. package/src/comlink/node/actions/getOrCreateNode.test.ts +9 -3
  83. package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
  84. package/src/comlink/node/actions/releaseNode.test.ts +7 -4
  85. package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
  86. package/src/comlink/node/getNodeState.test.ts +1 -1
  87. package/src/comlink/node/getNodeState.ts +2 -1
  88. package/src/comments/addonDatasetStore.test.ts +215 -0
  89. package/src/comments/addonDatasetStore.ts +249 -0
  90. package/src/comments/buildCommentThreads.test.ts +83 -0
  91. package/src/comments/buildCommentThreads.ts +54 -0
  92. package/src/comments/commentActions.test.ts +540 -0
  93. package/src/comments/commentActions.ts +555 -0
  94. package/src/comments/commentFieldPath.test.ts +40 -0
  95. package/src/comments/commentFieldPath.ts +44 -0
  96. package/src/comments/commentsConstants.ts +80 -0
  97. package/src/comments/commentsStore.test.ts +419 -0
  98. package/src/comments/commentsStore.ts +483 -0
  99. package/src/comments/normalizeComment.test.ts +116 -0
  100. package/src/comments/normalizeComment.ts +45 -0
  101. package/src/comments/observeComments.test.ts +193 -0
  102. package/src/comments/observeComments.ts +113 -0
  103. package/src/comments/reducers.test.ts +277 -0
  104. package/src/comments/reducers.ts +316 -0
  105. package/src/comments/types.ts +249 -0
  106. package/src/comments/weakenReferences.test.ts +47 -0
  107. package/src/comments/weakenReferences.ts +29 -0
  108. package/src/config/__tests__/handles.test.ts +18 -12
  109. package/src/config/handles.ts +25 -7
  110. package/src/config/sanityConfig.ts +40 -82
  111. package/src/datasets/datasets.test.ts +2 -2
  112. package/src/datasets/datasets.ts +10 -4
  113. package/src/document/actions.test.ts +115 -33
  114. package/src/document/actions.ts +212 -15
  115. package/src/document/applyDocumentActions.test.ts +35 -13
  116. package/src/document/applyDocumentActions.ts +30 -9
  117. package/src/document/documentConstants.ts +15 -0
  118. package/src/document/documentStore.concurrency.test.ts +1306 -0
  119. package/src/document/documentStore.test.ts +753 -273
  120. package/src/document/documentStore.ts +197 -75
  121. package/src/document/events.test.ts +57 -2
  122. package/src/document/events.ts +82 -26
  123. package/src/document/listen.test.ts +56 -0
  124. package/src/document/listen.ts +74 -21
  125. package/src/document/listenerEventOperators.test.ts +311 -0
  126. package/src/document/listenerEventOperators.ts +217 -0
  127. package/src/document/patchOperations.test.ts +76 -2
  128. package/src/document/patchOperations.ts +60 -1
  129. package/src/document/permissions.test.ts +107 -60
  130. package/src/document/permissions.ts +44 -19
  131. package/src/document/processActions/create.ts +138 -0
  132. package/src/document/processActions/delete.ts +100 -0
  133. package/src/document/processActions/discard.ts +63 -0
  134. package/src/document/processActions/edit.ts +154 -0
  135. package/src/document/processActions/processActions.ts +218 -0
  136. package/src/document/processActions/publish.ts +120 -0
  137. package/src/document/processActions/releaseArchive.ts +77 -0
  138. package/src/document/processActions/releaseCreate.ts +59 -0
  139. package/src/document/processActions/releaseDelete.ts +65 -0
  140. package/src/document/processActions/releaseEdit.ts +37 -0
  141. package/src/document/processActions/releasePublish.ts +45 -0
  142. package/src/document/processActions/releaseSchedule.ts +87 -0
  143. package/src/document/processActions/releaseUtil.ts +31 -0
  144. package/src/document/processActions/shared.ts +308 -0
  145. package/src/document/processActions/unpublish.ts +85 -0
  146. package/src/document/processActions.test.ts +1129 -121
  147. package/src/document/reducers.test.ts +772 -64
  148. package/src/document/reducers.ts +205 -51
  149. package/src/document/resourceRules.test.ts +178 -0
  150. package/src/document/resourceRules.ts +117 -0
  151. package/src/document/sharedListener.test.ts +16 -14
  152. package/src/document/sharedListener.ts +24 -8
  153. package/src/document/util.test.ts +46 -0
  154. package/src/document/util.ts +50 -0
  155. package/src/favorites/favorites.test.ts +5 -6
  156. package/src/installations/installations.test-d.ts +73 -0
  157. package/src/installations/installations.test.ts +62 -0
  158. package/src/installations/installations.ts +206 -0
  159. package/src/organization/organization.test-d.ts +36 -0
  160. package/src/organization/organization.test.ts +138 -0
  161. package/src/organization/organization.ts +138 -0
  162. package/src/organizations/organizations.test-d.ts +56 -0
  163. package/src/organizations/organizations.test.ts +150 -0
  164. package/src/organizations/organizations.ts +107 -0
  165. package/src/presence/bifurTransport.test.ts +201 -9
  166. package/src/presence/bifurTransport.ts +98 -14
  167. package/src/presence/paths.test.ts +70 -0
  168. package/src/presence/paths.ts +41 -0
  169. package/src/presence/presenceStore.test.ts +915 -24
  170. package/src/presence/presenceStore.ts +576 -104
  171. package/src/presence/types.ts +175 -3
  172. package/src/preview/previewProjectionUtils.test.ts +9 -22
  173. package/src/preview/previewProjectionUtils.ts +7 -3
  174. package/src/preview/types.ts +0 -15
  175. package/src/project/project.test-d.ts +37 -0
  176. package/src/project/project.test.ts +157 -12
  177. package/src/project/project.ts +138 -25
  178. package/src/projection/getProjectionState.test.ts +18 -20
  179. package/src/projection/getProjectionState.ts +23 -3
  180. package/src/projection/projectionQuery.ts +5 -5
  181. package/src/projection/projectionStore.test.ts +1 -9
  182. package/src/projection/resolveProjection.test.ts +1 -2
  183. package/src/projection/resolveProjection.ts +16 -0
  184. package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
  185. package/src/projection/subscribeToStateAndFetchBatches.ts +32 -23
  186. package/src/projects/projects.test-d.ts +32 -0
  187. package/src/projects/projects.test.ts +108 -42
  188. package/src/projects/projects.ts +63 -27
  189. package/src/query/queryStore.test.ts +259 -123
  190. package/src/query/queryStore.ts +85 -69
  191. package/src/query/reducers.test.ts +0 -42
  192. package/src/query/reducers.ts +2 -18
  193. package/src/releases/getPerspectiveState.test.ts +17 -23
  194. package/src/releases/getPerspectiveState.ts +8 -20
  195. package/src/releases/observeReleases.test.ts +127 -0
  196. package/src/releases/observeReleases.ts +102 -0
  197. package/src/releases/releasesStore.test.ts +100 -53
  198. package/src/releases/releasesStore.ts +69 -44
  199. package/src/releases/utils/sortReleases.test.ts +38 -2
  200. package/src/releases/utils/sortReleases.ts +15 -10
  201. package/src/store/createActionBinder.test.ts +109 -90
  202. package/src/store/createActionBinder.ts +36 -28
  203. package/src/store/createSanityInstance.test.ts +15 -13
  204. package/src/store/createSanityInstance.ts +14 -2
  205. package/src/store/createStateSourceAction.test.ts +64 -2
  206. package/src/store/createStateSourceAction.ts +38 -43
  207. package/src/store/createStoreInstance.test.ts +4 -2
  208. package/src/store/fetcherStore.test-d.ts +121 -0
  209. package/src/store/fetcherStore.test.ts +299 -0
  210. package/src/store/fetcherStore.ts +801 -0
  211. package/src/telemetry/environment.test.ts +119 -0
  212. package/src/telemetry/environment.ts +92 -0
  213. package/src/telemetry/events.ts +42 -0
  214. package/src/telemetry/initTelemetry.test.ts +432 -0
  215. package/src/telemetry/initTelemetry.ts +218 -0
  216. package/src/telemetry/telemetryManager.test.ts +327 -0
  217. package/src/telemetry/telemetryManager.ts +199 -0
  218. package/src/users/reducers.test.ts +3 -1
  219. package/src/users/reducers.ts +5 -6
  220. package/src/users/types.ts +4 -4
  221. package/src/users/usersStore.test.ts +16 -12
  222. package/src/users/usersStore.ts +5 -1
  223. package/src/utils/buildQuery.test.ts +14 -0
  224. package/src/utils/buildQuery.ts +17 -0
  225. package/src/utils/createFetcherStore.test.ts +7 -5
  226. package/src/utils/createFetcherStore.ts +8 -5
  227. package/src/utils/getStagingApiHost.test.ts +21 -0
  228. package/src/utils/getStagingApiHost.ts +14 -0
  229. package/src/utils/ids.test.ts +1 -29
  230. package/src/utils/ids.ts +0 -10
  231. package/src/utils/includeShape.ts +36 -0
  232. package/src/utils/isImportError.test.ts +72 -0
  233. package/src/utils/isImportError.ts +34 -0
  234. package/src/utils/logger.test.ts +12 -0
  235. package/src/utils/logger.ts +8 -3
  236. package/src/utils/object.test.ts +95 -0
  237. package/src/utils/object.ts +142 -0
  238. package/src/utils/setCleanupTimeout.ts +37 -0
  239. package/src/document/processActions.ts +0 -707
  240. package/src/utils/defineIntent.test.ts +0 -477
  241. package/src/utils/defineIntent.ts +0 -244
@@ -0,0 +1,71 @@
1
+ import { r as getClientState } from "../clientStore-BtE2-q2i.js";
2
+ import "@sanity/client";
3
+ import { from, switchMap } from "rxjs";
4
+ /**
5
+ * Generates a new document using the agent.
6
+ * @param instance - The Sanity instance.
7
+ * @param options - The options for the agent generate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
8
+ * @returns An Observable emitting the result of the agent generate action.
9
+ * @alpha
10
+ */
11
+ function agentGenerate(instance, options, resource) {
12
+ return getClientState(instance, {
13
+ apiVersion: "vX",
14
+ resource
15
+ }).observable.pipe(switchMap((client) => client.observable.agent.action.generate(options)));
16
+ }
17
+ /**
18
+ * Transforms a document using the agent.
19
+ * @param instance - The Sanity instance.
20
+ * @param options - The options for the agent transform action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
21
+ * @returns An Observable emitting the result of the agent transform action.
22
+ * @alpha
23
+ */
24
+ function agentTransform(instance, options, resource) {
25
+ return getClientState(instance, {
26
+ apiVersion: "vX",
27
+ resource
28
+ }).observable.pipe(switchMap((client) => client.observable.agent.action.transform(options)));
29
+ }
30
+ /**
31
+ * Translates a document using the agent.
32
+ * @param instance - The Sanity instance.
33
+ * @param options - The options for the agent translate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
34
+ * @returns An Observable emitting the result of the agent translate action.
35
+ * @alpha
36
+ */
37
+ function agentTranslate(instance, options, resource) {
38
+ return getClientState(instance, {
39
+ apiVersion: "vX",
40
+ resource
41
+ }).observable.pipe(switchMap((client) => client.observable.agent.action.translate(options)));
42
+ }
43
+ /**
44
+ * Prompts the agent using the same instruction template format as the other actions, but returns text or json instead of acting on a document.
45
+ * @param instance - The Sanity instance.
46
+ * @param options - The options for the agent prompt action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
47
+ * @returns An Observable emitting the result of the agent prompt action.
48
+ * @alpha
49
+ */
50
+ function agentPrompt(instance, options, resource) {
51
+ return getClientState(instance, {
52
+ apiVersion: "vX",
53
+ resource
54
+ }).observable.pipe(switchMap((client) => from(client.agent.action.prompt(options))));
55
+ }
56
+ /**
57
+ * Patches a document using the agent.
58
+ * @param instance - The Sanity instance.
59
+ * @param options - The options for the agent patch action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
60
+ * @returns An Observable emitting the result of the agent patch action.
61
+ * @alpha
62
+ */
63
+ function agentPatch(instance, options, resource) {
64
+ return getClientState(instance, {
65
+ apiVersion: "vX",
66
+ resource
67
+ }).observable.pipe(switchMap((client) => from(client.agent.action.patch(options))));
68
+ }
69
+ export { agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate };
70
+
71
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","names":[],"sources":["../../src/agent/agentActions.ts"],"sourcesContent":["import {type SanityClient} from '@sanity/client'\nimport {from, Observable, switchMap} from 'rxjs'\n\nimport {getClientState} from '../client/clientStore'\nimport {type DocumentResource} from '../config/sanityConfig'\nimport {type SanityInstance} from '../store/createSanityInstance'\n\nconst API_VERSION = 'vX'\n\n/** @alpha */\nexport type AgentGenerateOptions = Parameters<\n SanityClient['observable']['agent']['action']['generate']\n>[0]\n\n/** @alpha */\nexport type AgentTransformOptions = Parameters<\n SanityClient['observable']['agent']['action']['transform']\n>[0]\n\n/** @alpha */\nexport type AgentTranslateOptions = Parameters<\n SanityClient['observable']['agent']['action']['translate']\n>[0]\n\n/** @alpha */\nexport type AgentPromptOptions = Parameters<SanityClient['agent']['action']['prompt']>[0]\n\n/** @alpha */\nexport type AgentPatchOptions = Parameters<SanityClient['agent']['action']['patch']>[0]\n\n/** @alpha */\nexport type AgentGenerateResult = Awaited<\n ReturnType<SanityClient['observable']['agent']['action']['generate']>\n>\n\n/** @alpha */\nexport type AgentTransformResult = Awaited<\n ReturnType<SanityClient['observable']['agent']['action']['transform']>\n>\n\n/** @alpha */\nexport type AgentTranslateResult = Awaited<\n ReturnType<SanityClient['observable']['agent']['action']['translate']>\n>\n\n/** @alpha */\nexport type AgentPromptResult = Awaited<ReturnType<SanityClient['agent']['action']['prompt']>>\n\n/** @alpha */\nexport type AgentPatchResult = Awaited<ReturnType<SanityClient['agent']['action']['patch']>>\n\n/**\n * Generates a new document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent generate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent generate action.\n * @alpha\n */\nexport function agentGenerate(\n instance: SanityInstance,\n options: AgentGenerateOptions,\n resource?: DocumentResource,\n): AgentGenerateResult {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => client.observable.agent.action.generate(options)),\n )\n}\n\n/**\n * Transforms a document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent transform action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent transform action.\n * @alpha\n */\nexport function agentTransform(\n instance: SanityInstance,\n options: AgentTransformOptions,\n resource?: DocumentResource,\n): AgentTransformResult {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => client.observable.agent.action.transform(options)),\n )\n}\n\n/**\n * Translates a document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent translate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent translate action.\n * @alpha\n */\nexport function agentTranslate(\n instance: SanityInstance,\n options: AgentTranslateOptions,\n resource?: DocumentResource,\n): AgentTranslateResult {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => client.observable.agent.action.translate(options)),\n )\n}\n\n/**\n * Prompts the agent using the same instruction template format as the other actions, but returns text or json instead of acting on a document.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent prompt action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent prompt action.\n * @alpha\n */\nexport function agentPrompt(\n instance: SanityInstance,\n options: AgentPromptOptions,\n resource?: DocumentResource,\n): Observable<AgentPromptResult> {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => from(client.agent.action.prompt(options))),\n )\n}\n\n/**\n * Patches a document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent patch action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent patch action.\n * @alpha\n */\nexport function agentPatch(\n instance: SanityInstance,\n options: AgentPatchOptions,\n resource?: DocumentResource,\n): Observable<AgentPatchResult> {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => from(client.agent.action.patch(options))),\n )\n}\n"],"mappings":";;;;;;;;;;AA0DA,SAAgB,cACd,UACA,SACA,UACqB;CACrB,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,OAAO,WAAW,MAAM,OAAO,SAAS,OAAO,CAAC,CACxE;AACF;;;;;;;;AASA,SAAgB,eACd,UACA,SACA,UACsB;CACtB,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,OAAO,WAAW,MAAM,OAAO,UAAU,OAAO,CAAC,CACzE;AACF;;;;;;;;AASA,SAAgB,eACd,UACA,SACA,UACsB;CACtB,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,OAAO,WAAW,MAAM,OAAO,UAAU,OAAO,CAAC,CACzE;AACF;;;;;;;;AASA,SAAgB,YACd,UACA,SACA,UAC+B;CAC/B,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,KAAK,OAAO,MAAM,OAAO,OAAO,OAAO,CAAC,CAAC,CACjE;AACF;;;;;;;;AASA,SAAgB,WACd,UACA,SACA,UAC8B;CAC9B,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,KAAK,OAAO,MAAM,OAAO,MAAM,OAAO,CAAC,CAAC,CAChE;AACF"}
@@ -0,0 +1,118 @@
1
+ import { Ei as BoundStoreAction, Ti as StateSource } from "../authStore-DKFX8fn7.js";
2
+ import { ChannelInput, ChannelInstance, Controller, Message, Node, NodeInput, Status } from "@sanity/comlink";
3
+ /**
4
+ * Message sent from a containing app to an iframe
5
+ * @public
6
+ */
7
+ type FrameMessage = Message;
8
+ /**
9
+ * Message sent from an iframe to a containing app
10
+ * @public
11
+ */
12
+ type WindowMessage = Message;
13
+ /**
14
+ * Message from SDK (iframe) to Parent (dashboard) to request a new token
15
+ * @internal
16
+ */
17
+ type RequestNewTokenMessage = {
18
+ type: 'dashboard/v1/auth/tokens/create';
19
+ payload?: undefined;
20
+ };
21
+ /**
22
+ * Message from Parent (dashboard) to SDK (iframe) with the new token
23
+ * @internal
24
+ */
25
+ type NewTokenResponseMessage = {
26
+ type: 'dashboard/v1/auth/tokens/create';
27
+ payload: {
28
+ token: string | null;
29
+ error?: string;
30
+ };
31
+ };
32
+ /**
33
+ * Individual channel with its relevant options
34
+ * @public
35
+ */
36
+ interface ChannelEntry {
37
+ channel: ChannelInstance<FrameMessage, WindowMessage>;
38
+ options: ChannelInput;
39
+ refCount: number;
40
+ }
41
+ /**
42
+ * Internal state tracking comlink connections
43
+ * @public
44
+ */
45
+ interface ComlinkControllerState {
46
+ controller: Controller | null;
47
+ controllerOrigin: string | null;
48
+ channels: Map<string, ChannelEntry>;
49
+ }
50
+ /**
51
+ * Calls the destroy method on the controller and resets the controller state.
52
+ * @public
53
+ */
54
+ declare const destroyController: BoundStoreAction<ComlinkControllerState, [], void>;
55
+ /**
56
+ * Retrieve or create a channel to be used for communication between
57
+ * an application and the controller.
58
+ * @public
59
+ */
60
+ declare const getOrCreateChannel: BoundStoreAction<ComlinkControllerState, [options: ChannelInput], ChannelInstance<import("@sanity/comlink").Message, import("@sanity/comlink").Message>>;
61
+ /**
62
+ * Initializes or fetches a controller to handle communication
63
+ * between an application and iframes.
64
+ * @public
65
+ */
66
+ declare const getOrCreateController: BoundStoreAction<ComlinkControllerState, [targetOrigin: string], Controller>;
67
+ /**
68
+ * Signals to the store that the consumer has stopped using the channel
69
+ * @public
70
+ */
71
+ declare const releaseChannel: BoundStoreAction<ComlinkControllerState, [name: string], void>;
72
+ /**
73
+ * Individual node with its relevant options
74
+ * @public
75
+ */
76
+ interface NodeEntry {
77
+ node: Node<WindowMessage, FrameMessage>;
78
+ options: NodeInput;
79
+ status: Status;
80
+ statusUnsub?: () => void;
81
+ }
82
+ /**
83
+ * Internal state tracking comlink connections
84
+ * @public
85
+ */
86
+ interface ComlinkNodeState {
87
+ nodes: Map<string, NodeEntry>;
88
+ subscriptions: Map<string, Set<symbol>>;
89
+ }
90
+ /**
91
+ * Signals to the store that the consumer has stopped using the node
92
+ * @public
93
+ */
94
+ declare const releaseNode: BoundStoreAction<ComlinkNodeState, [name: string], void>;
95
+ /**
96
+ * Retrieve or create a node to be used for communication between
97
+ * an application and the controller -- specifically, a node should
98
+ * be created within a frame / window to communicate with the controller.
99
+ * @public
100
+ */
101
+ declare const getOrCreateNode: BoundStoreAction<ComlinkNodeState, [options: NodeInput], Node<import("@sanity/comlink").Message, import("@sanity/comlink").Message>>;
102
+ /**
103
+ * @public
104
+ */
105
+ interface NodeState {
106
+ node: Node<WindowMessage, FrameMessage>;
107
+ status: Status | undefined;
108
+ }
109
+ /**
110
+ * Provides a subscribable state source for a node by name
111
+ * @param instance - The Sanity instance to get the node state for
112
+ * @param nodeInput - The configuration for the node to get the state for
113
+ * @returns A subscribable state source for the node
114
+ * @public
115
+ */
116
+ declare const getNodeState: BoundStoreAction<ComlinkNodeState, [NodeInput], StateSource<NodeState | undefined>>;
117
+ export { type ComlinkControllerState, type ComlinkNodeState, type FrameMessage, type NewTokenResponseMessage, type NodeState, type RequestNewTokenMessage, type WindowMessage, destroyController, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, releaseChannel, releaseNode };
118
+ //# sourceMappingURL=comlink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comlink.d.ts","names":[],"sources":["../../src/comlink/types.ts","../../src/comlink/controller/comlinkControllerStore.ts","../../src/comlink/node/comlinkNodeStore.ts","../../src/comlink/node/getNodeState.ts"],"mappings":";;;;;;KAMY,eAAe;;;;;KAMf,gBAAgB;;;;;KAMhB;EACV;EACA;;;;;;KAOU;EACV;EACA;IAAU;IAAsB;;;;;;;UCfjB;EACf,SAAS,gBAAgB,cAAc;EAEvC,SAAS;EAET;;;;;;UAOe;EACf,YAAY;EACZ;EACA,UAAU,YAAY;;;;;;cAyBX,mBAAiB,iBAAA;;;;;;cAUjB,oBAAkB,iBAAA,yBAAA,SAAA,eAAA,0CAAA,mCAAA;;;;;;cAUlB,uBAAqB,iBAAA,yBAAA,uBAAA;;;;;cASrB,gBAAc,iBAAA,yBAAA;;;;;UCvEV;EACf,MAAM,KAAK,eAAe;EAE1B,SAAS;EAET,QAAQ;EACR;;;;;;UAOe;EACf,OAAO,YAAY;EAEnB,eAAe,YAAY;;;;;;cAuBhB,aAAW,iBAAA,mBAAA;;;;;;;cAQX,iBAAe,iBAAA,mBAAA,SAAA,YAAA,+BAAA,mCAAA;;;;UCvCX;EACf,MAAM,KAAK,eAAe;EAC1B,QAAQ;;;;;;;;;cAaG,cAAY,iBAAA,mBAAA,YAAA,YAAA"}
@@ -0,0 +1,69 @@
1
+ import { a as defineStore, i as bindActionGlobally } from "../createStateSourceAction-BOKtqFNm.js";
2
+ import { t as isDeepEqual } from "../object-CxXlSVg7.js";
3
+ import { n as getOrCreateNode, r as releaseNode, t as getNodeState } from "../getNodeState-CR3__B2D.js";
4
+ import { createController } from "@sanity/comlink";
5
+ /**
6
+ * Calls the destroy method on the controller and resets the controller state.
7
+ * @public
8
+ */
9
+ const destroyController$1 = ({ state }) => {
10
+ let { controller } = state.get();
11
+ controller && (controller.destroy(), state.set("destroyController", {
12
+ controller: null,
13
+ channels: /* @__PURE__ */ new Map()
14
+ }));
15
+ }, getOrCreateChannel$1 = ({ state }, options) => {
16
+ let controller = state.get().controller;
17
+ if (!controller) throw Error("Controller must be initialized before using or creating channels");
18
+ let channels = state.get().channels, existing = channels.get(options.name);
19
+ if (existing) {
20
+ if (!isDeepEqual(existing.options, options)) throw Error(`Channel "${options.name}" already exists with different options`);
21
+ return state.set("incrementChannelRefCount", { channels: new Map(channels).set(options.name, {
22
+ ...existing,
23
+ refCount: existing.refCount + 1
24
+ }) }), existing.channel.start(), existing.channel;
25
+ }
26
+ let channel = controller.createChannel(options);
27
+ return channel.start(), state.set("createChannel", { channels: new Map(channels).set(options.name, {
28
+ channel,
29
+ options,
30
+ refCount: 1
31
+ }) }), channel;
32
+ }, getOrCreateController$1 = ({ state, instance }, targetOrigin) => {
33
+ let { controller, controllerOrigin } = state.get();
34
+ if (controller && controllerOrigin === targetOrigin) return controller;
35
+ controller && destroyController$1({
36
+ state,
37
+ instance,
38
+ key: void 0
39
+ });
40
+ let newController = createController({ targetOrigin });
41
+ return state.set("initializeController", {
42
+ controllerOrigin: targetOrigin,
43
+ controller: newController
44
+ }), newController;
45
+ }, releaseChannel$1 = ({ state }, name) => {
46
+ let channels = state.get().channels, channelEntry = channels.get(name);
47
+ if (channelEntry) {
48
+ let newRefCount = channelEntry.refCount === 0 ? 0 : channelEntry.refCount - 1;
49
+ newRefCount === 0 ? (channelEntry.channel.stop(), channels.delete(name), state.set("releaseChannel", { channels: new Map(channels) })) : state.set("releaseChannel", { channels: new Map(channels).set(name, {
50
+ ...channelEntry,
51
+ refCount: newRefCount
52
+ }) });
53
+ }
54
+ }, comlinkControllerStore = defineStore({
55
+ name: "connectionStore",
56
+ getInitialState: () => ({
57
+ controller: null,
58
+ controllerOrigin: null,
59
+ channels: /* @__PURE__ */ new Map()
60
+ }),
61
+ initialize({ instance }) {
62
+ return () => {
63
+ destroyController(instance);
64
+ };
65
+ }
66
+ }), destroyController = bindActionGlobally(comlinkControllerStore, destroyController$1), getOrCreateChannel = bindActionGlobally(comlinkControllerStore, getOrCreateChannel$1), getOrCreateController = bindActionGlobally(comlinkControllerStore, getOrCreateController$1), releaseChannel = bindActionGlobally(comlinkControllerStore, releaseChannel$1);
67
+ export { destroyController, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, releaseChannel, releaseNode };
68
+
69
+ //# sourceMappingURL=comlink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comlink.js","names":["destroyController","getOrCreateChannel","getOrCreateController","releaseChannel","unboundDestroyController","unboundGetOrCreateChannel","unboundGetOrCreateController","unboundReleaseChannel"],"sources":["../../src/comlink/controller/actions/destroyController.ts","../../src/comlink/controller/actions/getOrCreateChannel.ts","../../src/comlink/controller/actions/getOrCreateController.ts","../../src/comlink/controller/actions/releaseChannel.ts","../../src/comlink/controller/comlinkControllerStore.ts"],"sourcesContent":["import {type StoreContext} from '../../../store/defineStore'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\n\n/**\n * Calls the destroy method on the controller and resets the controller state.\n * @public\n */\nexport const destroyController = ({state}: StoreContext<ComlinkControllerState>): void => {\n const {controller} = state.get()\n\n if (controller) {\n controller.destroy()\n state.set('destroyController', {\n controller: null,\n channels: new Map(),\n })\n }\n}\n","import {type ChannelInput, type ChannelInstance} from '@sanity/comlink'\n\nimport {type StoreContext} from '../../../store/defineStore'\nimport {isDeepEqual} from '../../../utils/object'\nimport {type FrameMessage, type WindowMessage} from '../../types'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\n\n/**\n * Retrieve or create a channel to be used for communication between\n * an application and the controller.\n * @public\n */\nexport const getOrCreateChannel = (\n {state}: StoreContext<ComlinkControllerState>,\n options: ChannelInput,\n): ChannelInstance<FrameMessage, WindowMessage> => {\n const controller = state.get().controller\n\n if (!controller) {\n throw new Error('Controller must be initialized before using or creating channels')\n }\n\n const channels = state.get().channels\n const existing = channels.get(options.name)\n\n // limit channels to one per name\n if (existing) {\n if (!isDeepEqual(existing.options, options)) {\n throw new Error(`Channel \"${options.name}\" already exists with different options`)\n }\n\n state.set('incrementChannelRefCount', {\n channels: new Map(channels).set(options.name, {\n ...existing,\n refCount: existing.refCount + 1,\n }),\n })\n existing.channel.start()\n return existing.channel\n }\n\n const channel = controller.createChannel(options)\n channel.start()\n state.set('createChannel', {\n channels: new Map(channels).set(options.name, {\n channel,\n options,\n refCount: 1,\n }),\n })\n\n return channel\n}\n","import {type Controller, createController} from '@sanity/comlink'\n\nimport {type StoreContext} from '../../../store/defineStore'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\nimport {destroyController} from './destroyController'\n\n/**\n * Initializes or fetches a controller to handle communication\n * between an application and iframes.\n * @public\n */\nexport const getOrCreateController = (\n {state, instance}: StoreContext<ComlinkControllerState>,\n targetOrigin: string,\n): Controller => {\n const {controller, controllerOrigin} = state.get()\n if (controller && controllerOrigin === targetOrigin) {\n return controller\n }\n\n // if the target origin has changed, we'll create a new controller,\n // but need to clean up first\n if (controller) {\n destroyController({state, instance, key: undefined})\n }\n\n const newController = createController({targetOrigin})\n state.set('initializeController', {\n controllerOrigin: targetOrigin,\n controller: newController,\n })\n\n return newController\n}\n","import {type StoreContext} from '../../../store/defineStore'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\n\n/**\n * Signals to the store that the consumer has stopped using the channel\n * @public\n */\nexport const releaseChannel = (\n {state}: StoreContext<ComlinkControllerState>,\n name: string,\n): void => {\n const channels = state.get().channels\n const channelEntry = channels.get(name)\n\n if (channelEntry) {\n const newRefCount = channelEntry.refCount === 0 ? 0 : channelEntry.refCount - 1\n\n if (newRefCount === 0) {\n channelEntry.channel.stop()\n channels.delete(name)\n state.set('releaseChannel', {channels: new Map(channels)})\n } else {\n state.set('releaseChannel', {\n channels: new Map(channels).set(name, {\n ...channelEntry,\n refCount: newRefCount,\n }),\n })\n }\n }\n}\n","import {type ChannelInput, type ChannelInstance, type Controller} from '@sanity/comlink'\n\nimport {bindActionGlobally} from '../../store/createActionBinder'\nimport {defineStore} from '../../store/defineStore'\nimport {type FrameMessage, type WindowMessage} from '../types'\nimport {destroyController as unboundDestroyController} from './actions/destroyController'\nimport {getOrCreateChannel as unboundGetOrCreateChannel} from './actions/getOrCreateChannel'\nimport {getOrCreateController as unboundGetOrCreateController} from './actions/getOrCreateController'\nimport {releaseChannel as unboundReleaseChannel} from './actions/releaseChannel'\n\n/**\n * Individual channel with its relevant options\n * @public\n */\nexport interface ChannelEntry {\n channel: ChannelInstance<FrameMessage, WindowMessage>\n // we store options to ensure that channels remain as unique / consistent as possible\n options: ChannelInput\n // we store refCount to ensure channels remain open only as long as they are in use\n refCount: number\n}\n\n/**\n * Internal state tracking comlink connections\n * @public\n */\nexport interface ComlinkControllerState {\n controller: Controller | null\n controllerOrigin: string | null\n channels: Map<string, ChannelEntry>\n}\n\nexport const comlinkControllerStore = defineStore<ComlinkControllerState>({\n name: 'connectionStore',\n getInitialState: () => {\n const initialState = {\n controller: null,\n controllerOrigin: null,\n channels: new Map(),\n }\n return initialState\n },\n initialize({instance}) {\n return () => {\n // destroying controller also destroys channels\n destroyController(instance)\n }\n },\n})\n\n/**\n * Calls the destroy method on the controller and resets the controller state.\n * @public\n */\nexport const destroyController = bindActionGlobally(\n comlinkControllerStore,\n unboundDestroyController,\n)\n\n/**\n * Retrieve or create a channel to be used for communication between\n * an application and the controller.\n * @public\n */\nexport const getOrCreateChannel = bindActionGlobally(\n comlinkControllerStore,\n unboundGetOrCreateChannel,\n)\n\n/**\n * Initializes or fetches a controller to handle communication\n * between an application and iframes.\n * @public\n */\nexport const getOrCreateController = bindActionGlobally(\n comlinkControllerStore,\n unboundGetOrCreateController,\n)\n\n/**\n * Signals to the store that the consumer has stopped using the channel\n * @public\n */\nexport const releaseChannel = bindActionGlobally(comlinkControllerStore, unboundReleaseChannel)\n"],"mappings":";;;;;;;;AAOA,MAAaA,uBAAqB,EAAC,YAAuD;CACxF,IAAM,EAAC,eAAc,MAAM,IAAI;CAE/B,AAAI,eACF,WAAW,QAAQ,GACnB,MAAM,IAAI,qBAAqB;EAC7B,YAAY;EACZ,0BAAU,IAAI,IAAI;CACpB,CAAC;AAEL,GCLaC,wBACX,EAAC,SACD,YACiD;CACjD,IAAM,aAAa,MAAM,IAAI,CAAC,CAAC;CAE/B,IAAI,CAAC,YACH,MAAU,MAAM,kEAAkE;CAGpF,IAAM,WAAW,MAAM,IAAI,CAAC,CAAC,UACvB,WAAW,SAAS,IAAI,QAAQ,IAAI;CAG1C,IAAI,UAAU;EACZ,IAAI,CAAC,YAAY,SAAS,SAAS,OAAO,GACxC,MAAU,MAAM,YAAY,QAAQ,KAAK,wCAAwC;EAUnF,OAPA,MAAM,IAAI,4BAA4B,EACpC,UAAU,IAAI,IAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,MAAM;GAC5C,GAAG;GACH,UAAU,SAAS,WAAW;EAChC,CAAC,EACH,CAAC,GACD,SAAS,QAAQ,MAAM,GAChB,SAAS;CAClB;CAEA,IAAM,UAAU,WAAW,cAAc,OAAO;CAUhD,OATA,QAAQ,MAAM,GACd,MAAM,IAAI,iBAAiB,EACzB,UAAU,IAAI,IAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,MAAM;EAC5C;EACA;EACA,UAAU;CACZ,CAAC,EACH,CAAC,GAEM;AACT,GCzCaC,2BACX,EAAC,OAAO,YACR,iBACe;CACf,IAAM,EAAC,YAAY,qBAAoB,MAAM,IAAI;CACjD,IAAI,cAAc,qBAAqB,cACrC,OAAO;CAKT,AAAI,cACF,oBAAkB;EAAC;EAAO;EAAU,KAAK,KAAA;CAAS,CAAC;CAGrD,IAAM,gBAAgB,iBAAiB,EAAC,aAAY,CAAC;CAMrD,OALA,MAAM,IAAI,wBAAwB;EAChC,kBAAkB;EAClB,YAAY;CACd,CAAC,GAEM;AACT,GC1BaC,oBACX,EAAC,SACD,SACS;CACT,IAAM,WAAW,MAAM,IAAI,CAAC,CAAC,UACvB,eAAe,SAAS,IAAI,IAAI;CAEtC,IAAI,cAAc;EAChB,IAAM,cAAc,aAAa,aAAa,IAAI,IAAI,aAAa,WAAW;EAE9E,AAAI,gBAAgB,KAClB,aAAa,QAAQ,KAAK,GAC1B,SAAS,OAAO,IAAI,GACpB,MAAM,IAAI,kBAAkB,EAAC,UAAU,IAAI,IAAI,QAAQ,EAAC,CAAC,KAEzD,MAAM,IAAI,kBAAkB,EAC1B,UAAU,IAAI,IAAI,QAAQ,CAAC,CAAC,IAAI,MAAM;GACpC,GAAG;GACH,UAAU;EACZ,CAAC,EACH,CAAC;CAEL;AACF,GCEa,yBAAyB,YAAoC;CACxE,MAAM;CACN,wBAMS;EAJL,YAAY;EACZ,kBAAkB;EAClB,0BAAU,IAAI,IAAI;CAEF;CAEpB,WAAW,EAAC,YAAW;EACrB,aAAa;GAEX,kBAAkB,QAAQ;EAC5B;CACF;AACF,CAAC,GAMY,oBAAoB,mBAC/B,wBACAC,mBACF,GAOa,qBAAqB,mBAChC,wBACAC,oBACF,GAOa,wBAAwB,mBACnC,wBACAC,uBACF,GAMa,iBAAiB,mBAAmB,wBAAwBC,gBAAqB"}