diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d3e59..ed5145a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to the Rust Apify API client are documented here. The format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to [Semantic Versioning](https://semver.org/). +## [0.19.0] - 2026-11-27 + +### Fixed +- `StoreCollectionClient::iterate` with a non-empty `search` fetches the single page the API + returns and stops, instead of repeating the same Actors. + +### Changed +- Documented the Store search, `limit`, `category`, and `sort_by` semantics on `StoreListOptions` + and in the docs, and deprecated `StoreListOptions::sort_by`, which the API ignores. +- `ActorVersionCollectionClient::create` and `ActorVersionClient::update` use the `Long` timeout + tier by default, since a version can carry its source files. + ## [0.18.0] - 2026-11-20 ### Added diff --git a/Cargo.toml b/Cargo.toml index 8f39189..e6cb32b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "apify-client" -version = "0.18.0" +version = "0.19.0" authors = ["Apify Technologies "] description = "Rust client for the Apify API (https://apify.com)." license = "Apache-2.0" diff --git a/README.md b/README.md index 806784f..1ef751e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ It provides a resource-oriented, async interface that follows the ```toml [dependencies] -apify-client = "0.18" +apify-client = "0.19" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } serde_json = "1" # for the `serde_json::Value` responses used in the Quick start ``` @@ -49,7 +49,7 @@ instead, disable the default features and name `rustls`. The `"zstd"` entry keep so drop it if you do not need it: ```toml -apify-client = { version = "0.18", default-features = false, features = ["rustls", "zstd"] } +apify-client = { version = "0.19", default-features = false, features = ["rustls", "zstd"] } ``` The `rustls` feature requires `rustls-webpki` 0.103.16 or newer and `webpki-roots` 1.0.10 or diff --git a/docs/README.md b/docs/README.md index 515f1ee..e75fb3c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -31,7 +31,7 @@ Add the crate and an async runtime: ```toml [dependencies] -apify-client = "0.18" +apify-client = "0.19" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } ``` diff --git a/docs/actors.md b/docs/actors.md index 75ec001..d7e0f6b 100644 --- a/docs/actors.md +++ b/docs/actors.md @@ -407,4 +407,5 @@ when it is `None`. Creating a version needs `versionNumber` and `sourceType` in the body, and so does every item of the `versions` array in an Actor create or update body. The writable source types are `SOURCE_FILES`, `GIT_REPO`, `TARBALL` and `GITHUB_GIST`; `SOURCE_CODE` can be read but not sent. -Updating a version needs no required field. +Updating a version needs no required field. `create` and `update` use the `Long` timeout tier by +default, since a version can carry its source files; set another one with `with_timeout`. diff --git a/docs/misc.md b/docs/misc.md index 5f7b1b1..8b1a71e 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -10,10 +10,19 @@ | `iterate(options)` | `StoreListOptions` | `StoreActorIterator` | Lazy, page-fetching iterator. | `StoreListOptions`: `offset`, `limit`, `search`, `sort_by`, `category`, `username`, -`pricing_model`, `include_unrunnable_actors`, `allows_agentic_users`, `response_format`. +`pricing_model`, `include_unrunnable_actors`, `allows_agentic_users`, `response_format`, +`include_input_schema`. `limit` means a single page's size for `list`, but a cap on the *total* number of items yielded for `iterate` (see below). +With a non-empty `search`, the API ranks the results by relevance and returns a single page of at +most 100 items: `offset` is ignored, a larger `limit` is reduced to 100, and there is no second +page. Without it, a page has at most 1000 items, or 10 with `include_input_schema`. `sort_by` is +deprecated: the API accepts it and ignores it, so sort the results on the client if you need a +different order. `category` takes one or more category IDs separated by commas, such as +`AI_AND_ML`; an Actor must match all of them, and an unknown category makes the API answer with a +`400` error. + `StoreActorIterator` is a type alias for `ListIterator` (the shared iterator returned by every collection's `iterate`), re-exported at the crate root alongside `ListIterator` itself. Its `next()` is `async` and fallible — it returns @@ -50,6 +59,10 @@ while let Some(actor) = iter.next().await? { # } ``` +With a non-empty `search`, the API returns a single page and ignores `offset`, so the iterator +fetches that one page of at most 100 Actors and stops; `with_chunk_size` has no effect then. An +empty `search` is the same as none. + `ActorStoreListItem` (from `apify_client::models`) is the element type yielded by both `list` and the iterator. Its fields: diff --git a/src/clients/actor_version.rs b/src/clients/actor_version.rs index 80a9ad8..1a9ef3f 100644 --- a/src/clients/actor_version.rs +++ b/src/clients/actor_version.rs @@ -32,8 +32,11 @@ impl ActorVersionClient { } /// Updates the version with the given fields. + /// + /// The request uses the `Long` timeout tier by default, since the version can carry its + /// source files. Set another one with [`with_timeout`](Self::with_timeout). pub async fn update(&self, new_fields: &T) -> ApifyClientResult { - update_resource(&self.ctx, None, new_fields, Timeout::Short).await + update_resource(&self.ctx, None, new_fields, Timeout::Long).await } /// Deletes the version. diff --git a/src/clients/actor_version_collection.rs b/src/clients/actor_version_collection.rs index 42efa26..7f8782f 100644 --- a/src/clients/actor_version_collection.rs +++ b/src/clients/actor_version_collection.rs @@ -41,7 +41,10 @@ impl ActorVersionCollectionClient { } /// Creates a new Actor version. + /// + /// The request uses the `Long` timeout tier by default, since the version can carry its + /// source files. Set another one with [`with_timeout`](Self::with_timeout). pub async fn create(&self, version: &T) -> ApifyClientResult { - create_resource(&self.ctx, &QueryParams::new(), version, Timeout::Short).await + create_resource(&self.ctx, &QueryParams::new(), version, Timeout::Long).await } } diff --git a/src/clients/pagination.rs b/src/clients/pagination.rs index 6a52bf5..e39c2a5 100644 --- a/src/clients/pagination.rs +++ b/src/clients/pagination.rs @@ -30,7 +30,8 @@ type PageFetcher = Box) -> PageFuture + Send + Syn /// Collections whose listing does not fit this shape build their iterator directly instead: /// the run listing takes a separate `filter` argument, dataset items use `list_items::`, and /// the listings that are not paginated (an Actor's versions and a version's env vars) use -/// `single_page_iterator!`. +/// `single_page_iterator!`. The Store listing uses this macro, except for a non-empty search, +/// which returns one page and ignores `offset`, so it uses `single_page_iterator!` as well. macro_rules! list_iterator { ($self:expr, $options:expr, $list:ident) => {{ let client = $self.clone(); @@ -52,9 +53,12 @@ macro_rules! list_iterator { } pub(crate) use list_iterator; -/// Generates the body of the `iterate()` method of a collection whose endpoint is not -/// offset-paginated: it has a no-argument `list()` method and returns every item in one response. -/// The resulting [`ListIterator`] calls `list` exactly once and then completes. +/// Generates the body of the `iterate()` method of a collection that is read in a single request. +/// Without more arguments, the endpoint is not offset-paginated and the collection has a +/// no-argument `list()` method. With `options` and a list method name, it calls `$list(options)` +/// once with the options as given (no `offset` or `limit` override), for a request that ignores +/// `offset`, such as a Store search. The resulting [`ListIterator`] calls `list` exactly once and +/// then completes. macro_rules! single_page_iterator { ($self:expr) => {{ let client = $self.clone(); @@ -65,6 +69,17 @@ macro_rules! single_page_iterator { }, )) }}; + ($self:expr, $options:expr, $list:ident) => {{ + let client = $self.clone(); + let options = $options; + $crate::clients::pagination::ListIterator::new_single_page(Box::new( + move |_offset, _page_limit| { + let client = client.clone(); + let options = options.clone(); + Box::pin(async move { client.$list(options).await }) + }, + )) + }}; } pub(crate) use single_page_iterator; @@ -124,8 +139,9 @@ pub struct ListIterator { remaining: Option, /// Page size to request per fetch; `None` = let the API choose its default page size. chunk_size: Option, - /// When `true`, the underlying endpoint is not offset-paginated: the first fetch returns the - /// whole result set, so the iterator stops after it rather than requesting a second page. + /// When `true`, the underlying endpoint is not offset-paginated, or ignores `offset` for the + /// request (a Store search): the first fetch returns the only page, so the iterator stops + /// after it rather than requesting a second page. single_page: bool, /// Set once the listing has been fully consumed. exhausted: bool, @@ -148,9 +164,10 @@ impl ListIterator { } /// Builds an iterator over an endpoint that is **not** offset-paginated (it returns every - /// item in one response, e.g. an Actor version's environment variables). `fetch` is called - /// exactly once; the iterator does not attempt a second page, so it does not depend on the - /// endpoint reporting a page `limit` and cannot refetch the same items. + /// item in one response, e.g. an Actor version's environment variables) or that ignores + /// `offset` for the request at hand (a Store search). `fetch` is called exactly once; the + /// iterator does not attempt a second page, so it does not depend on the endpoint reporting a + /// page `limit` and cannot refetch the same items. pub(crate) fn new_single_page(fetch: PageFetcher) -> Self { Self { single_page: true, @@ -222,7 +239,7 @@ impl ListIterator { // Only a page that scanned nothing, or the caller's cap, ends the walk, which costs one // extra request at the end. if self.single_page { - // Non-paginated endpoint: everything came back in one response. + // Single-page listing: the first fetch is the only page. self.exhausted = true; } else if scanned == 0 { self.exhausted = true; diff --git a/src/clients/store_collection.rs b/src/clients/store_collection.rs index 13d3d9f..9b9815c 100644 --- a/src/clients/store_collection.rs +++ b/src/clients/store_collection.rs @@ -1,7 +1,7 @@ //! Client for browsing the Apify Store (`/v2/store`). use crate::clients::base::{list_resource, ResourceContext}; -use crate::clients::pagination::{list_iterator, ListIterator}; +use crate::clients::pagination::{list_iterator, single_page_iterator, ListIterator}; use crate::common::{PaginationList, QueryParams}; use crate::error::ApifyClientResult; use crate::http_client::HttpClient; @@ -18,26 +18,38 @@ pub type StoreActorIterator = ListIterator; /// Options for searching the Apify Store. #[derive(Debug, Default, Clone)] pub struct StoreListOptions { - /// Number of items to skip. + /// Number of items to skip. The API ignores it when a non-empty `search` is used. pub offset: Option, - /// Item limit. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a - /// single page's size (the maximum items that one call returns); for + /// Item limit. The default and the maximum are 1000. When a non-empty `search` is used, + /// they are 100, and a larger value is reduced to 100. With `include_input_schema`, they are + /// 10. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a single + /// page's size (the maximum items that one call returns); for /// [`StoreCollectionClient::iterate`] it is a cap on the *total* number of items yielded across /// all pages. See each method's docs. pub limit: Option, - /// Full-text search query. + /// Search query. With a non-empty query, the API ranks the results by relevance and returns a + /// single page of at most 100 items: `offset` is ignored and there is no second page. To + /// narrow the results, use `category`, `username`, or `pricing_model`. pub search: Option, - /// Sort key (e.g. `popularity`, `newest`). + /// Deprecated and ignored by the API, which accepts it for backward compatibility. Results + /// are ordered by relevance when a non-empty `search` is used, and by Store position + /// otherwise. Sort the results on the client if you need a different order. + #[deprecated(note = "the API ignores `sortBy`: sort the results on the client")] pub sort_by: Option, - /// Filter by category. + /// Filter by category. Accepts one or more category IDs separated by commas, case-insensitive + /// (for example `AI_AND_ML`). An Actor must match all of the listed categories. An unknown + /// category makes the API answer with a `400` error. pub category: Option, /// Filter by owner username. pub username: Option, /// Filter by pricing model: `FREE`, `PRICE_PER_DATASET_ITEM` or `PAY_PER_EVENT`. pub pricing_model: Option, - /// Include Actors that the current user cannot run (e.g. needing a missing integration). + /// By default, results exclude Actors that are not safe to run automatically, such as Actors + /// from developers who have not passed KYC or full-permission Actors without a large user + /// base. Set to `true` to bypass this safety filtering and include all Actors. pub include_unrunnable_actors: Option, - /// Filter to Actors that allow agentic (x402/Skyfire) users. + /// If `true`, returns only Actors that allow agentic users. If `false`, returns only Actors + /// that do not allow agentic users. pub allows_agentic_users: Option, /// Response format requested from the API (`full` or `agent`, the API default is `full`). pub response_format: Option, @@ -83,10 +95,19 @@ impl StoreCollectionClient { /// [`list`](Self::list) where `limit` is a single page's size. Set the per-page fetch size /// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see /// [`ListIterator`] for details. + /// + /// With a non-empty `options.search`, the API returns a single page of at most 100 Actors and + /// ignores `offset`, so the iterator fetches that one page and stops. `with_chunk_size` has no + /// effect then, and `options.limit` is sent as given. pub fn iterate(&self, options: StoreListOptions) -> StoreActorIterator { - list_iterator!(self, options, list) + // The API treats an empty search as no search and pages through the Store as usual. + match options.search.as_deref() { + Some(search) if !search.is_empty() => single_page_iterator!(self, options, list), + _ => list_iterator!(self, options, list), + } } + #[allow(deprecated)] // `sort_by` is deprecated, but it is still sent as the caller set it. fn build_params(&self, options: &StoreListOptions) -> QueryParams { let mut params = QueryParams::new(); params diff --git a/tests/store.rs b/tests/store.rs index 549fa0e..600d168 100644 --- a/tests/store.rs +++ b/tests/store.rs @@ -58,3 +58,39 @@ async fn list_store_with_input_schema() { assert!(!page.items.is_empty(), "the Store lists Actors"); assert!(page.items.len() <= 3); } + +/// Simple GET: the deprecated `sort_by` is accepted by the Store endpoint, which ignores it, so +/// the order of the result is not asserted. +#[tokio::test(flavor = "multi_thread")] +#[allow(deprecated)] // The test covers the deprecated option. +async fn list_store_accepts_the_deprecated_sort_by() { + let client = require_client!(); + let page = client + .store() + .list(StoreListOptions { + limit: Some(10), + sort_by: Some("popularity".to_string()), + ..Default::default() + }) + .await + .expect("listing the store with the deprecated sort_by should succeed"); + assert!(!page.items.is_empty(), "the Store lists Actors"); +} + +/// Convenience: iterating a search fetches its single page and ends, without repeating Actors. +#[tokio::test(flavor = "multi_thread")] +async fn iterate_store_search_ends_with_unique_actors() { + let client = require_client!(); + let mut iter = client.store().iterate(StoreListOptions { + search: Some("web scraper".to_string()), + ..Default::default() + }); + let mut ids = std::collections::HashSet::new(); + let mut seen = 0; + while let Some(actor) = iter.next().await.expect("iterate the store search") { + seen += 1; + assert!(ids.insert(actor.id), "an Actor was yielded twice"); + } + assert!(seen > 0, "the search yields at least one Actor"); + assert!(seen <= 100, "a search returns at most 100 Actors"); +} diff --git a/tests/unit_http.rs b/tests/unit_http.rs index c8e05b4..dcf607d 100644 --- a/tests/unit_http.rs +++ b/tests/unit_http.rs @@ -10,7 +10,7 @@ use std::time::Duration; use apify_client::{ ActorCallOptions, ActorStartOptions, ApifyClient, ApifyClientError, LastRunOptions, - LogRedirect, RequestCompression, TaskStartOptions, WaitForResources, + LogRedirect, RequestCompression, StoreListOptions, TaskStartOptions, WaitForResources, }; use common::mock_backend::{client_with, MockBackend, MockOutcome}; use futures_util::StreamExt; @@ -1699,6 +1699,71 @@ async fn iterate_steps_by_the_count_the_api_reports_when_it_exceeds_the_items_re assert!(urls[2].contains("offset=6"), "{urls:?}"); } +/// With `search` the API returns one page and ignores `offset`, so the iterator stops after it +/// instead of requesting the same Actors again. +#[tokio::test] +async fn iterating_a_store_search_fetches_a_single_page() { + let backend = MockBackend::new(vec![MockOutcome::Status( + 200, + br#"{"data":{"total":2,"count":2,"items":[{"id":"a"},{"id":"b"}]}}"#.to_vec(), + )]); + let client = client_with(backend.clone(), 0); + + let actors = client + .store() + .iterate(StoreListOptions { + search: Some("scraper".to_string()), + limit: Some(10), + ..Default::default() + }) + .collect_all() + .await + .expect("ok"); + + let ids: Vec<&str> = actors.iter().map(|actor| actor.id.as_str()).collect(); + assert_eq!(ids, ["a", "b"]); + let urls = backend.urls(); + assert_eq!(urls.len(), 1, "{urls:?}"); + assert!(urls[0].contains("search=scraper"), "{urls:?}"); + assert!(urls[0].contains("limit=10"), "{urls:?}"); +} + +/// The API treats an empty `search` as no search and pages through the Store, so the iterator +/// keeps paging instead of stopping after the first page. +#[tokio::test] +async fn iterating_an_empty_store_search_pages_normally() { + let backend = MockBackend::new(vec![ + MockOutcome::Status( + 200, + br#"{"data":{"total":4,"count":2,"items":[{"id":"a"},{"id":"b"}]}}"#.to_vec(), + ), + MockOutcome::Status( + 200, + br#"{"data":{"total":4,"count":2,"items":[{"id":"c"},{"id":"d"}]}}"#.to_vec(), + ), + MockOutcome::Status( + 200, + br#"{"data":{"total":4,"count":0,"items":[]}}"#.to_vec(), + ), + ]); + let client = client_with(backend.clone(), 0); + + let actors = client + .store() + .iterate(StoreListOptions { + search: Some(String::new()), + ..Default::default() + }) + .with_chunk_size(2) + .collect_all() + .await + .expect("ok"); + + assert_eq!(actors.len(), 4); + let urls = backend.urls(); + assert!(urls[1].contains("offset=2"), "{urls:?}"); +} + /// A streaming call retries an error status until the response starts, like a buffered call. #[tokio::test] async fn a_stream_is_retried_on_an_error_status_until_the_response_starts() { diff --git a/tests/unit_timeouts.rs b/tests/unit_timeouts.rs index bc4d442..b385906 100644 --- a/tests/unit_timeouts.rs +++ b/tests/unit_timeouts.rs @@ -56,6 +56,32 @@ async fn listing_uses_the_medium_tier() { assert_eq!(backend.last_timeout(), Duration::from_secs(30)); } +#[tokio::test] +async fn creating_and_updating_an_actor_version_use_the_long_tier() { + let backend = MockBackend::new(vec![ + ok_data(json!({ "versionNumber": "0.1" })), + ok_data(json!({ "versionNumber": "0.1" })), + ]); + let client = client_with(backend.clone(), 0); + let body = json!({ "versionNumber": "0.1", "sourceType": "SOURCE_FILES" }); + client + .actor("a") + .versions() + .create(&body) + .await + .expect("create version"); + client + .actor("a") + .version("0.1") + .update(&body) + .await + .expect("update version"); + assert_eq!( + backend.timeouts(), + vec![Duration::from_secs(360), Duration::from_secs(360)] + ); +} + #[tokio::test] async fn dataset_items_use_the_long_tier() { let backend = MockBackend::new(vec![MockOutcome::Status(200, b"[]".to_vec())]);