@sanity/sdk 0.0.0-alpha.18 → 0.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -489,7 +489,7 @@ export {CurrentUser}
489
489
  declare interface DashboardContext {
490
490
  mode?: string
491
491
  env?: string
492
- orgId?: string | object
492
+ orgId?: string
493
493
  }
494
494
 
495
495
  declare class DateTime {
@@ -946,6 +946,15 @@ export declare const getCurrentUserState: ResourceAction<
946
946
  StateSource<CurrentUser | null>
947
947
  >
948
948
 
949
+ /**
950
+ * @public
951
+ */
952
+ export declare const getDashboardOrganizationId: ResourceAction<
953
+ AuthStoreState,
954
+ [],
955
+ StateSource<string | undefined>
956
+ >
957
+
949
958
  /** @public */
950
959
  export declare const getDatasetsState: ResourceAction<
951
960
  FetcherStoreState<[], DatasetsResponse>,
@@ -1619,7 +1628,7 @@ declare interface ProjectionStoreState<TValue extends object = object> extends L
1619
1628
  * @beta
1620
1629
  */
1621
1630
  export declare interface ProjectionValuePending<TValue extends object> {
1622
- results: TValue | null
1631
+ data: TValue | null
1623
1632
  isPending: boolean
1624
1633
  }
1625
1634
 
@@ -2099,7 +2108,7 @@ declare interface ValueNode<P = any> {
2099
2108
  * @public
2100
2109
  */
2101
2110
  export declare type ValuePending<T> = {
2102
- results: T | null
2111
+ data: T | null
2103
2112
  isPending: boolean
2104
2113
  }
2105
2114
 
package/dist/index.js CHANGED
@@ -291,7 +291,10 @@ const authStore = {
291
291
  ), getLoginUrlsState = createStateSourceAction(
292
292
  authStore,
293
293
  ({ providers }) => providers ?? null
294
- ), getAuthState = createStateSourceAction(authStore, ({ authState }) => authState), fetchLoginUrls = createAction(authStore, ({ state }) => {
294
+ ), getAuthState = createStateSourceAction(authStore, ({ authState }) => authState), getDashboardOrganizationId = createStateSourceAction(
295
+ authStore,
296
+ ({ dashboardContext }) => dashboardContext?.orgId
297
+ ), fetchLoginUrls = createAction(authStore, ({ state }) => {
295
298
  const { callbackUrl, clientFactory, apiHost, customProviders } = state.get().options, client = clientFactory({
296
299
  apiVersion: DEFAULT_API_VERSION$1,
297
300
  requestTagPrefix: REQUEST_TAG_PREFIX,
@@ -4230,8 +4233,8 @@ function getPreviewProjection() {
4230
4233
  _updatedAt
4231
4234
  }`;
4232
4235
  }
4233
- const PREVIEW_TAG = "preview", STABLE_EMPTY_PREVIEW = { results: null, isPending: !1 }, STABLE_ERROR_PREVIEW = {
4234
- results: {
4236
+ const PREVIEW_TAG = "preview", STABLE_EMPTY_PREVIEW = { data: null, isPending: !1 }, STABLE_ERROR_PREVIEW = {
4237
+ data: {
4235
4238
  title: "Preview Error",
4236
4239
  ...!!getEnv("DEV") && { subtitle: "Check the console for more details" }
4237
4240
  },
@@ -4286,7 +4289,7 @@ function processPreviewQuery({
4286
4289
  ...draftResult?._updatedAt && { lastEditedDraftAt: draftResult._updatedAt },
4287
4290
  ...publishedResult?._updatedAt && { lastEditedPublishedAt: publishedResult._updatedAt }
4288
4291
  };
4289
- return [id, { results: { ...preview, status }, isPending: !1 }];
4292
+ return [id, { data: { ...preview, status }, isPending: !1 }];
4290
4293
  } catch (e3) {
4291
4294
  return console.warn(e3), [id, STABLE_ERROR_PREVIEW];
4292
4295
  }
@@ -4322,8 +4325,8 @@ const BATCH_DEBOUNCE_TIME$1 = 50, subscribeToStateAndFetchBatches$1 = createInte
4322
4325
  const newIds = [...currIds].filter((element) => !prevIds.has(element));
4323
4326
  state.set("updatingPending", (prev) => {
4324
4327
  const pendingValues = newIds.reduce((acc, id) => {
4325
- const prevValue = prev.values[id], value = prevValue?.results ? prevValue.results : null;
4326
- return acc[id] = { results: value, isPending: !0 }, acc;
4328
+ const prevValue = prev.values[id], value = prevValue?.data ? prevValue.data : null;
4329
+ return acc[id] = { data: value, isPending: !0 }, acc;
4327
4330
  }, {});
4328
4331
  return { values: { ...prev.values, ...pendingValues } };
4329
4332
  });
@@ -4403,10 +4406,10 @@ const BATCH_DEBOUNCE_TIME$1 = 50, subscribeToStateAndFetchBatches$1 = createInte
4403
4406
  const unsubscribe = previewState.subscribe(subscriber);
4404
4407
  return () => {
4405
4408
  unsubscribe(), state.set("removeSubscription", (prev) => {
4406
- const documentSubscriptions = omit(prev.subscriptions[documentId], subscriptionId), hasSubscribers = !!Object.keys(documentSubscriptions).length, prevValue = prev.values[documentId], previewValue = prevValue?.results ? prevValue.results : null;
4409
+ const documentSubscriptions = omit(prev.subscriptions[documentId], subscriptionId), hasSubscribers = !!Object.keys(documentSubscriptions).length, prevValue = prev.values[documentId], previewValue = prevValue?.data ? prevValue.data : null;
4407
4410
  return {
4408
4411
  subscriptions: hasSubscribers ? { ...prev.subscriptions, [documentId]: documentSubscriptions } : omit(prev.subscriptions, documentId),
4409
- values: hasSubscribers ? prev.values : { ...prev.values, [documentId]: { results: previewValue, isPending: !1 } }
4412
+ values: hasSubscribers ? prev.values : { ...prev.values, [documentId]: { data: previewValue, isPending: !1 } }
4410
4413
  };
4411
4414
  });
4412
4415
  };
@@ -4417,7 +4420,7 @@ const BATCH_DEBOUNCE_TIME$1 = 50, subscribeToStateAndFetchBatches$1 = createInte
4417
4420
  return new Promise((resolve) => {
4418
4421
  const unsubscribe = subscribe(() => {
4419
4422
  const current = getCurrent();
4420
- current?.results && (resolve(current), unsubscribe());
4423
+ current?.data && (resolve(current), unsubscribe());
4421
4424
  });
4422
4425
  });
4423
4426
  }), project = createFetcherStore({
@@ -4427,7 +4430,7 @@ const BATCH_DEBOUNCE_TIME$1 = 50, subscribeToStateAndFetchBatches$1 = createInte
4427
4430
  switchMap((client) => client.observable.projects.getById(projectId))
4428
4431
  )
4429
4432
  }), getProjectState = project.getState, resolveProject = project.resolveState, PROJECTION_TAG = "sdk.projection", STABLE_EMPTY_PROJECTION = {
4430
- results: null,
4433
+ data: null,
4431
4434
  isPending: !1
4432
4435
  };
4433
4436
  function validateProjection(projection) {
@@ -4463,12 +4466,12 @@ function processProjectionQuery({ ids, results }) {
4463
4466
  return Object.fromEntries(
4464
4467
  Array.from(ids).map((id) => {
4465
4468
  const publishedId = getPublishedId(id), draftId = getDraftId(id), draftResult = resultMap[draftId], publishedResult = resultMap[publishedId], projectionResult = draftResult?.result ?? publishedResult?.result;
4466
- if (!projectionResult) return [id, { results: null, isPending: !1 }];
4469
+ if (!projectionResult) return [id, { data: null, isPending: !1 }];
4467
4470
  const status = {
4468
4471
  ...draftResult?._updatedAt && { lastEditedDraftAt: draftResult._updatedAt },
4469
4472
  ...publishedResult?._updatedAt && { lastEditedPublishedAt: publishedResult._updatedAt }
4470
4473
  };
4471
- return [id, { results: { ...projectionResult, status }, isPending: !1 }];
4474
+ return [id, { data: { ...projectionResult, status }, isPending: !1 }];
4472
4475
  })
4473
4476
  );
4474
4477
  }
@@ -4494,8 +4497,8 @@ const BATCH_DEBOUNCE_TIME = 50, subscribeToStateAndFetchBatches = createInternal
4494
4497
  const newIds = [...currIds].filter((element) => !prevIds.has(element));
4495
4498
  state.set("updatingPending", (prev) => {
4496
4499
  const pendingValues = newIds.reduce((acc, id) => {
4497
- const prevValue = prev.values[id], value = prevValue?.results ? prevValue.results : null;
4498
- return acc[id] = { results: value, isPending: !0 }, acc;
4500
+ const prevValue = prev.values[id], value = prevValue?.data ? prevValue.data : null;
4501
+ return acc[id] = { data: value, isPending: !0 }, acc;
4499
4502
  }, {});
4500
4503
  return { values: { ...prev.values, ...pendingValues } };
4501
4504
  });
@@ -4580,10 +4583,10 @@ const _getProjectionState = createAction(projectionStore, ({ state }) => functio
4580
4583
  const unsubscribe = projectionState.subscribe(subscriber);
4581
4584
  return () => {
4582
4585
  unsubscribe(), state.set("removeSubscription", (prev) => {
4583
- const documentSubscriptions = omit(prev.subscriptions[documentId], subscriptionId), hasSubscribers = !!Object.keys(documentSubscriptions).length, prevValue = prev.values[documentId], projectionValue = prevValue?.results ? prevValue.results : null;
4586
+ const documentSubscriptions = omit(prev.subscriptions[documentId], subscriptionId), hasSubscribers = !!Object.keys(documentSubscriptions).length, prevValue = prev.values[documentId], projectionValue = prevValue?.data ? prevValue.data : null;
4584
4587
  return {
4585
4588
  subscriptions: hasSubscribers ? { ...prev.subscriptions, [documentId]: documentSubscriptions } : omit(prev.subscriptions, documentId),
4586
- values: hasSubscribers ? prev.values : { ...prev.values, [documentId]: { results: projectionValue, isPending: !1 } }
4589
+ values: hasSubscribers ? prev.values : { ...prev.values, [documentId]: { data: projectionValue, isPending: !1 } }
4587
4590
  };
4588
4591
  });
4589
4592
  };
@@ -4594,7 +4597,7 @@ const _getProjectionState = createAction(projectionStore, ({ state }) => functio
4594
4597
  return new Promise((resolve) => {
4595
4598
  const unsubscribe = subscribe(() => {
4596
4599
  const current = getCurrent();
4597
- current?.results && (resolve(current), unsubscribe());
4600
+ current?.data && (resolve(current), unsubscribe());
4598
4601
  });
4599
4602
  });
4600
4603
  }), projects = createFetcherStore({
@@ -4844,7 +4847,7 @@ const API_VERSION = "vX", usersStore = {
4844
4847
  resolveUsers,
4845
4848
  setOptions
4846
4849
  });
4847
- var version = "0.0.0-alpha.18";
4850
+ var version = "0.0.0-alpha.19";
4848
4851
  const CORE_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
4849
4852
  export {
4850
4853
  AuthStateType,
@@ -4862,6 +4865,7 @@ export {
4862
4865
  getClient,
4863
4866
  getClientState,
4864
4867
  getCurrentUserState,
4868
+ getDashboardOrganizationId,
4865
4869
  getDatasetsState,
4866
4870
  getDocumentState,
4867
4871
  getDocumentSyncStatus,