@sanity/client 7.19.0 → 7.21.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.
@@ -3425,7 +3425,8 @@ ${selectionOpts}`);
3425
3425
  */
3426
3426
  events({
3427
3427
  includeDrafts = false,
3428
- tag: _tag
3428
+ tag: _tag,
3429
+ waitFor
3429
3430
  } = {}) {
3430
3431
  const {
3431
3432
  projectId: projectId2,
@@ -3444,7 +3445,7 @@ ${selectionOpts}`);
3444
3445
  "The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
3445
3446
  );
3446
3447
  const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, false)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
3447
- tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
3448
+ tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true"), waitFor && url.searchParams.set("waitFor", waitFor);
3448
3449
  const esOptions = {};
3449
3450
  includeDrafts && withCredentials && (esOptions.withCredentials = true), (includeDrafts && token || configHeaders) && (esOptions.headers = {}, includeDrafts && token && (esOptions.headers.Authorization = `Bearer ${token}`), configHeaders && Object.assign(esOptions.headers, configHeaders));
3450
3451
  const key = `${url.href}::${JSON.stringify(esOptions)}`, existing = eventsCache.get(key);
@@ -3745,9 +3746,18 @@ ${selectionOpts}`);
3745
3746
  constructor(client, httpRequest) {
3746
3747
  this.#client = client, this.#httpRequest = httpRequest;
3747
3748
  }
3749
+ /**
3750
+ * Fetch a list of projects the authenticated user has access to.
3751
+ *
3752
+ * @param options - Options for the list request
3753
+ * - `includeMembers` - Whether to include members in the response (default: true)
3754
+ * - `includeFeatures` - Whether to include features in the response (default: true)
3755
+ * - `organizationId` - ID of the organization to fetch projects for
3756
+ * - `onlyExplicitMembership` - Whether to include only projects with explicit membership (default: false)
3757
+ */
3748
3758
  list(options) {
3749
3759
  const query = {}, uri = "/projects";
3750
- return options?.includeMembers === false && (query.includeMembers = "false"), options?.organizationId && (query.organizationId = options.organizationId), options?.onlyExplicitMembership === true && (query.onlyExplicitMembership = "true"), _request(this.#client, this.#httpRequest, { uri, query });
3760
+ return options?.includeMembers === false && (query.includeMembers = "false"), options?.includeFeatures === false && (query.includeFeatures = "false"), options?.organizationId && (query.organizationId = options.organizationId), options?.onlyExplicitMembership && (query.onlyExplicitMembership = "true"), _request(this.#client, this.#httpRequest, { uri, query });
3751
3761
  }
3752
3762
  /**
3753
3763
  * Fetch a project by project ID
@@ -3764,9 +3774,20 @@ ${selectionOpts}`);
3764
3774
  constructor(client, httpRequest) {
3765
3775
  this.#client = client, this.#httpRequest = httpRequest;
3766
3776
  }
3777
+ /**
3778
+ * Fetch a list of projects the authenticated user has access to.
3779
+ *
3780
+ * @param options - Options for the list request
3781
+ * - `includeMembers` - Whether to include members in the response (default: true)
3782
+ * - `includeFeatures` - Whether to include features in the response (default: true)
3783
+ * - `organizationId` - ID of the organization to fetch projects for
3784
+ * - `onlyExplicitMembership` - Whether to include only projects with explicit membership (default: false)
3785
+ */
3767
3786
  list(options) {
3768
3787
  const query = {}, uri = "/projects";
3769
- return options?.includeMembers === false && (query.includeMembers = "false"), options?.organizationId && (query.organizationId = options.organizationId), options?.onlyExplicitMembership === true && (query.onlyExplicitMembership = "true"), lastValueFrom(_request(this.#client, this.#httpRequest, { uri, query }));
3788
+ return options?.includeMembers === false && (query.includeMembers = "false"), options?.includeFeatures === false && (query.includeFeatures = "false"), options?.organizationId && (query.organizationId = options.organizationId), options?.onlyExplicitMembership && (query.onlyExplicitMembership = "true"), lastValueFrom(
3789
+ _request(this.#client, this.#httpRequest, { uri, query })
3790
+ );
3770
3791
  }
3771
3792
  /**
3772
3793
  * Fetch a project by project ID
@@ -4322,13 +4343,22 @@ ${selectionOpts}`);
4322
4343
  * Private properties
4323
4344
  */
4324
4345
  #clientConfig;
4346
+ #originalHttpRequest;
4325
4347
  #httpRequest;
4326
4348
  /**
4327
4349
  * Instance properties
4328
4350
  */
4329
4351
  listen = _listen;
4330
4352
  constructor(httpRequest, config = defaultConfig) {
4331
- this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = {
4353
+ this.config(config), this.#originalHttpRequest = httpRequest;
4354
+ const requestHandler = config._requestHandler;
4355
+ this.#httpRequest = requestHandler ? /* @__PURE__ */ (() => {
4356
+ let bareClient;
4357
+ return (options, requester2) => {
4358
+ const opts = options;
4359
+ return bareClient || (bareClient = new SanityClient(httpRequest, { ...config, _requestHandler: void 0 })), requestHandler(opts, (o) => httpRequest(o, requester2), bareClient);
4360
+ };
4361
+ })() : httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = {
4332
4362
  video: new ObservableMediaLibraryVideoClient(this, this.#httpRequest)
4333
4363
  }, this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.agent = {
4334
4364
  action: new ObservableAgentsActionClient(this, this.#httpRequest)
@@ -4338,7 +4368,7 @@ ${selectionOpts}`);
4338
4368
  * Clone the client - returns a new instance
4339
4369
  */
4340
4370
  clone() {
4341
- return new ObservableSanityClient(this.#httpRequest, this.config());
4371
+ return new ObservableSanityClient(this.#originalHttpRequest, this.config());
4342
4372
  }
4343
4373
  config(newConfig) {
4344
4374
  if (newConfig === void 0)
@@ -4356,7 +4386,7 @@ ${selectionOpts}`);
4356
4386
  */
4357
4387
  withConfig(newConfig) {
4358
4388
  const thisConfig = this.config();
4359
- return new ObservableSanityClient(this.#httpRequest, {
4389
+ return new ObservableSanityClient(this.#originalHttpRequest, {
4360
4390
  ...thisConfig,
4361
4391
  ...newConfig,
4362
4392
  stega: {
@@ -4586,13 +4616,22 @@ ${selectionOpts}`);
4586
4616
  * Private properties
4587
4617
  */
4588
4618
  #clientConfig;
4619
+ #originalHttpRequest;
4589
4620
  #httpRequest;
4590
4621
  /**
4591
4622
  * Instance properties
4592
4623
  */
4593
4624
  listen = _listen;
4594
4625
  constructor(httpRequest, config = defaultConfig) {
4595
- this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = {
4626
+ this.config(config), this.#originalHttpRequest = httpRequest;
4627
+ const requestHandler = config._requestHandler;
4628
+ this.#httpRequest = requestHandler ? /* @__PURE__ */ (() => {
4629
+ let bareClient;
4630
+ return (options, requester2) => {
4631
+ const opts = options;
4632
+ return bareClient || (bareClient = new SanityClient(httpRequest, { ...config, _requestHandler: void 0 })), requestHandler(opts, (o) => httpRequest(o, requester2), bareClient);
4633
+ };
4634
+ })() : httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.mediaLibrary = {
4596
4635
  video: new MediaLibraryVideoClient(this, this.#httpRequest)
4597
4636
  }, this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.agent = {
4598
4637
  action: new AgentActionsClient(this, this.#httpRequest)
@@ -4602,7 +4641,7 @@ ${selectionOpts}`);
4602
4641
  * Clone the client - returns a new instance
4603
4642
  */
4604
4643
  clone() {
4605
- return new SanityClient(this.#httpRequest, this.config());
4644
+ return new SanityClient(this.#originalHttpRequest, this.config());
4606
4645
  }
4607
4646
  config(newConfig) {
4608
4647
  if (newConfig === void 0)
@@ -4620,7 +4659,7 @@ ${selectionOpts}`);
4620
4659
  */
4621
4660
  withConfig(newConfig) {
4622
4661
  const thisConfig = this.config();
4623
- return new SanityClient(this.#httpRequest, {
4662
+ return new SanityClient(this.#originalHttpRequest, {
4624
4663
  ...thisConfig,
4625
4664
  ...newConfig,
4626
4665
  stega: {