Skip to content

Commit 9ae9985

Browse files
HavenDVclaude
andcommitted
refactor: adopt AutoSDK-generated helpers (issues #332-#337 closed)
All six AutoSDK generator improvements filed yesterday shipped in autosdk.cli 0.30.2-dev.59. Switching to the generated runtime lets us delete five hand-written shim files (~250 LOC) while gaining additional typed exception variants, idempotency-key on every mutating op, and RFC-5988 Link-header pagination — none of which we had hand-rolled. generate.sh — added flags: --generate-http-exception-hierarchy (issue #332) --generate-idempotency-helpers --idempotency-header-name x-idempotency-key (issue #333) --generate-retry-handler (issue #335) --generate-pageable-helpers (issue #334 — AutoSDKPager.NextUrlAsync + EnsureSameOrigin) --generate-multipart-upload-helpers (issue #336 — AutoSDKUploadFile) Deleted (now redundant with generated equivalents): FirecrawlExceptions.cs → AuthenticationException / PaymentRequiredException / RateLimitException (with RetryAfter) / ServerException now generated, plus more (AuthorizationException 403, NotFoundException 404, RequestTimeoutException 408, ConflictException 409, ValidationException 422). FirecrawlClient.Exceptions.cs → ApiException.Create() routes every error response to the typed subclass automatically; no ProcessResponse partial wiring needed. FirecrawlExceptionMapper.cs → ApiException.TryParseRetryAfter is now a public static helper inside the generated ApiException type. IdempotencyKeyExtensions.cs → every POST/PATCH/DELETE op now takes a string? idempotencyKey parameter directly. PaginationHelper.cs → AutoSDKPager.EnsureSameOrigin replaces it; pagination helpers now delegate to it. Refactored: V2/ParseFile.cs → thin compatibility shim around AutoSDKUploadFile.From{Bytes,Path,Stream}. Drops the duplicated MIME-type table — now uses AutoSDKMimeTypeGuesser which covers more types (audio/video/archives). V2/V2Client.cs → ParseAsync accepts AutoSDKUploadFile + uses ToHttpContent("file"); error path uses ApiException.Create for typed exceptions; monitor PaginateAsync uses AutoSDKPager.EnsureSameOrigin. CrawlClient.Paginate.cs → uses AutoSDKPager.EnsureSameOrigin + raises typed exceptions via ApiException.Create. ScrapingClient.PaginateBatch.cs → same. Filed AutoSDK #349 for a generator XML-doc bug in AutoSDKUploadFile.g.cs (cref uses C# keyword 'byte' instead of 'Byte', causing CS1584/CS1658/CS0419 under GenerateDocumentationFile=true). Worked around with CS1584/CS1658/CS0419 in <NoWarn>. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cbabfd0 commit 9ae9985

63 files changed

Lines changed: 2145 additions & 1030 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/libs/Firecrawl/CrawlClient.Paginate.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Net.Http;
2+
13
namespace Firecrawl;
24

35
public partial class CrawlingClient
@@ -7,12 +9,14 @@ public partial class CrawlingClient
79
/// every page of <see cref="CrawlStatusResponseObj.Data"/> into the first
810
/// response and clearing <see cref="CrawlStatusResponseObj.Next"/> when
911
/// done. The supplied <paramref name="response"/> is mutated and returned.
12+
///
13+
/// <para>
14+
/// Same-origin validation against <see cref="HttpClient.BaseAddress"/> is
15+
/// enforced via <see cref="AutoSDKPager.EnsureSameOrigin"/> — Firecrawl's
16+
/// <c>next</c> pointers are absolute URLs and a hostile server returning a
17+
/// foreign URL would otherwise harvest the <c>Authorization</c> header.
18+
/// </para>
1019
/// </summary>
11-
/// <remarks>
12-
/// Firecrawl's <c>next</c> pointers are absolute URLs; we refuse to
13-
/// forward the <c>Authorization</c> header across origins to avoid leaking
14-
/// the API key.
15-
/// </remarks>
1620
public async Task<CrawlStatusResponseObj> PaginateAsync(
1721
CrawlStatusResponseObj response,
1822
CancellationToken cancellationToken = default)
@@ -25,10 +29,25 @@ public async Task<CrawlStatusResponseObj> PaginateAsync(
2529
while (!string.IsNullOrEmpty(next))
2630
{
2731
cancellationToken.ThrowIfCancellationRequested();
32+
AutoSDKPager.EnsureSameOrigin(next, HttpClient.BaseAddress);
33+
34+
using var request = new HttpRequestMessage(HttpMethod.Get, next);
35+
if (HttpClient.DefaultRequestHeaders.Authorization is { } auth)
36+
{
37+
request.Headers.Authorization = auth;
38+
}
39+
40+
using var http = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
41+
if (!http.IsSuccessStatusCode)
42+
{
43+
throw ApiException.Create(http.StatusCode, http.ReasonPhrase ?? http.StatusCode.ToString());
44+
}
2845

29-
var content = await PaginationHelper
30-
.FetchNextPageJsonAsync(HttpClient, next, cancellationToken)
31-
.ConfigureAwait(false);
46+
var content = await http.Content.ReadAsStringAsync(
47+
#if NET5_0_OR_GREATER
48+
cancellationToken
49+
#endif
50+
).ConfigureAwait(false);
3251

3352
var page = CrawlStatusResponseObj.FromJson(content, JsonSerializerContext)
3453
?? throw new InvalidOperationException("Pagination response deserialization returned null.");

src/libs/Firecrawl/Firecrawl.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
CA2000 — StringContent/ByteArrayContent ownership transferred to MultipartFormDataContent.
2323
CA2227 — DTO collection setters required for System.Text.Json source-gen round-trip.
2424
-->
25-
<NoWarn>$(NoWarn);CS1591;CA1032;CA1056;CA1308;CA1819;CA1822;CA2000;CA2227</NoWarn>
25+
<NoWarn>$(NoWarn);CS1591;CS1584;CS1658;CS0419;CA1032;CA1056;CA1308;CA1819;CA1822;CA2000;CA2227</NoWarn>
2626
</PropertyGroup>
2727

2828
</Project>

src/libs/Firecrawl/FirecrawlClient.Exceptions.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/libs/Firecrawl/FirecrawlExceptionMapper.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/libs/Firecrawl/FirecrawlExceptions.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)