diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 64f9ff4..427b8ec 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.8.0" + ".": "2.9.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 74e73bc..97db86d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-155e4761d62255841349c0f8a01b0a9c463ea1d1f2d6c4fd8d1a75c8bef6f226.yml -openapi_spec_hash: ab91f77e7c9d992400cbc7fc8a9e76c1 -config_hash: bff282047fafdad771fb7ec685f56944 +configured_endpoints: 40 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a0dda03bbb600917cfb9add468cc4c8c84351a8dbbf61644dbc353263ca1748f.yml +openapi_spec_hash: c24264f32a46d9317aac5af9d6a396f7 +config_hash: 920678668dd2da6f8966fbf1b8fde4e2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b6d2c..7f203b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 2.9.0 (2026-08-07) + +Full Changelog: [v2.8.0...v2.9.0](https://github.com/context-dot-dev/context-php-sdk/compare/v2.8.0...v2.9.0) + +### Features + +* **api:** api update ([ff6e987](https://github.com/context-dot-dev/context-php-sdk/commit/ff6e9870b85a7e2c9b6f88928ae9fd3ab0af5d4b)) +* **api:** api update ([1b83bad](https://github.com/context-dot-dev/context-php-sdk/commit/1b83bad5cc2fec1d3659f6109fc6b7ce30446add)) +* **api:** api update ([5932741](https://github.com/context-dot-dev/context-php-sdk/commit/5932741da1376f8eba94cb6736f356efc8d9e455)) +* **api:** api update ([985cbbd](https://github.com/context-dot-dev/context-php-sdk/commit/985cbbd5032c78418d6235faf14641dfe3782cb4)) +* **api:** api update ([dd60dca](https://github.com/context-dot-dev/context-php-sdk/commit/dd60dca30260506e86c70a674f10e9892788109b)) +* **api:** api update ([841bd43](https://github.com/context-dot-dev/context-php-sdk/commit/841bd435edb55d3539afb1162993ac28c427fcd0)) +* **api:** api update ([3797497](https://github.com/context-dot-dev/context-php-sdk/commit/3797497dd171a1b3b6ca8260ea34c0e6bccda217)) +* **api:** manual updates ([7de1574](https://github.com/context-dot-dev/context-php-sdk/commit/7de1574a2177b6842269fdd4f453f4e5829557fb)) + ## 2.8.0 (2026-08-05) Full Changelog: [v2.7.0...v2.8.0](https://github.com/context-dot-dev/context-php-sdk/compare/v2.7.0...v2.8.0) diff --git a/README.md b/README.md index 3f9ffb2..8272f7d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The REST API documentation can be found on [docs.context.dev](https://docs.conte ``` -composer require "context-dev/context-dev-php 2.8.0" +composer require "context-dev/context-dev-php 2.9.0" ``` diff --git a/src/Batch/BatchDeleteResponse.php b/src/Batch/BatchDeleteResponse.php new file mode 100644 index 0000000..d7f89aa --- /dev/null +++ b/src/Batch/BatchDeleteResponse.php @@ -0,0 +1,104 @@ + */ + use SdkModel; + + /** + * ID of the deleted batch. + */ + #[Optional] + public ?string $id; + + /** + * Always true on success. + */ + #[Optional] + public ?bool $deleted; + + /** + * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + */ + #[Optional('key_metadata')] + public ?KeyMetadata $keyMetadata; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param KeyMetadata|KeyMetadataShape|null $keyMetadata + */ + public static function with( + ?string $id = null, + ?bool $deleted = null, + KeyMetadata|array|null $keyMetadata = null, + ): self { + $self = new self; + + null !== $id && $self['id'] = $id; + null !== $deleted && $self['deleted'] = $deleted; + null !== $keyMetadata && $self['keyMetadata'] = $keyMetadata; + + return $self; + } + + /** + * ID of the deleted batch. + */ + public function withID(string $id): self + { + $self = clone $this; + $self['id'] = $id; + + return $self; + } + + /** + * Always true on success. + */ + public function withDeleted(bool $deleted): self + { + $self = clone $this; + $self['deleted'] = $deleted; + + return $self; + } + + /** + * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + * + * @param KeyMetadata|KeyMetadataShape $keyMetadata + */ + public function withKeyMetadata(KeyMetadata|array $keyMetadata): self + { + $self = clone $this; + $self['keyMetadata'] = $keyMetadata; + + return $self; + } +} diff --git a/src/Batch/BatchDeleteResponse/KeyMetadata.php b/src/Batch/BatchDeleteResponse/KeyMetadata.php new file mode 100644 index 0000000..4766458 --- /dev/null +++ b/src/Batch/BatchDeleteResponse/KeyMetadata.php @@ -0,0 +1,92 @@ + */ + use SdkModel; + + /** + * The number of credits consumed by this request. + */ + #[Required('credits_consumed')] + public int $creditsConsumed; + + /** + * The number of credits remaining for your organization after this request. + */ + #[Required('credits_remaining')] + public int $creditsRemaining; + + /** + * `new KeyMetadata()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * KeyMetadata::with(creditsConsumed: ..., creditsRemaining: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new KeyMetadata)->withCreditsConsumed(...)->withCreditsRemaining(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + int $creditsConsumed, + int $creditsRemaining + ): self { + $self = new self; + + $self['creditsConsumed'] = $creditsConsumed; + $self['creditsRemaining'] = $creditsRemaining; + + return $self; + } + + /** + * The number of credits consumed by this request. + */ + public function withCreditsConsumed(int $creditsConsumed): self + { + $self = clone $this; + $self['creditsConsumed'] = $creditsConsumed; + + return $self; + } + + /** + * The number of credits remaining for your organization after this request. + */ + public function withCreditsRemaining(int $creditsRemaining): self + { + $self = clone $this; + $self['creditsRemaining'] = $creditsRemaining; + + return $self; + } +} diff --git a/src/Batch/BatchGetResponse/Credits.php b/src/Batch/BatchGetResponse/Credits.php index a498842..39696c6 100644 --- a/src/Batch/BatchGetResponse/Credits.php +++ b/src/Batch/BatchGetResponse/Credits.php @@ -11,7 +11,9 @@ /** * What this batch has done to your credit balance. * - * @phpstan-type CreditsShape = array{net: int, refunded: int, reserved: int} + * @phpstan-type CreditsShape = array{ + * net: int, ocrCharged: int, refunded: int, reserved: int + * } */ final class Credits implements BaseModel { @@ -19,11 +21,17 @@ final class Credits implements BaseModel use SdkModel; /** - * `reserved` minus `refunded` — what the batch has cost so far. Equal to `reserved` until the batch settles. + * `reserved` minus `refunded` plus `ocr_charged` — what the batch has cost so far. Equal to `reserved` until the batch settles. */ #[Required] public int $net; + /** + * Credits charged for PDF pages recovered by OCR (pdf.ocr=true), 1 per recovered page, on top of `reserved`. Stays 0 until the batch settles. + */ + #[Required('ocr_charged')] + public int $ocrCharged; + /** * Credits returned for pages that did not succeed. Stays 0 until the batch reaches a final status, then settles in one movement. */ @@ -41,13 +49,17 @@ final class Credits implements BaseModel * * To enforce required parameters use * ``` - * Credits::with(net: ..., refunded: ..., reserved: ...) + * Credits::with(net: ..., ocrCharged: ..., refunded: ..., reserved: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new Credits)->withNet(...)->withRefunded(...)->withReserved(...) + * (new Credits) + * ->withNet(...) + * ->withOcrCharged(...) + * ->withRefunded(...) + * ->withReserved(...) * ``` */ public function __construct() @@ -60,11 +72,16 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. */ - public static function with(int $net, int $refunded, int $reserved): self - { + public static function with( + int $net, + int $ocrCharged, + int $refunded, + int $reserved + ): self { $self = new self; $self['net'] = $net; + $self['ocrCharged'] = $ocrCharged; $self['refunded'] = $refunded; $self['reserved'] = $reserved; @@ -72,7 +89,7 @@ public static function with(int $net, int $refunded, int $reserved): self } /** - * `reserved` minus `refunded` — what the batch has cost so far. Equal to `reserved` until the batch settles. + * `reserved` minus `refunded` plus `ocr_charged` — what the batch has cost so far. Equal to `reserved` until the batch settles. */ public function withNet(int $net): self { @@ -82,6 +99,17 @@ public function withNet(int $net): self return $self; } + /** + * Credits charged for PDF pages recovered by OCR (pdf.ocr=true), 1 per recovered page, on top of `reserved`. Stays 0 until the batch settles. + */ + public function withOcrCharged(int $ocrCharged): self + { + $self = clone $this; + $self['ocrCharged'] = $ocrCharged; + + return $self; + } + /** * Credits returned for pages that did not succeed. Stays 0 until the batch reaches a final status, then settles in one movement. */ diff --git a/src/Batch/BatchGetResultsResponse/Data/ScrapedPage.php b/src/Batch/BatchGetResultsResponse/Data/ScrapedPage.php index aafb7cf..d5c7edd 100644 --- a/src/Batch/BatchGetResultsResponse/Data/ScrapedPage.php +++ b/src/Batch/BatchGetResultsResponse/Data/ScrapedPage.php @@ -25,6 +25,7 @@ * itemID?: string|null, * markdown?: string|null, * meta?: array|null, + * ocrPages?: int|null, * } */ final class ScrapedPage implements BaseModel @@ -90,6 +91,12 @@ final class ScrapedPage implements BaseModel #[Optional(map: 'mixed')] public ?array $meta; + /** + * PDF pages of this document recovered by OCR (pdf.ocr=true). Each recovered page bills 1 credit on top of the page base credit; absent when no OCR ran. + */ + #[Optional('ocr_pages')] + public ?int $ocrPages; + /** * `new ScrapedPage()` is missing required properties by the API. * @@ -130,6 +137,7 @@ public static function with( ?string $itemID = null, ?string $markdown = null, ?array $meta = null, + ?int $ocrPages = null, ): self { $self = new self; @@ -142,6 +150,7 @@ public static function with( null !== $itemID && $self['itemID'] = $itemID; null !== $markdown && $self['markdown'] = $markdown; null !== $meta && $self['meta'] = $meta; + null !== $ocrPages && $self['ocrPages'] = $ocrPages; return $self; } @@ -250,4 +259,15 @@ public function withMeta(array $meta): self return $self; } + + /** + * PDF pages of this document recovered by OCR (pdf.ocr=true). Each recovered page bills 1 credit on top of the page base credit; absent when no OCR ran. + */ + public function withOcrPages(int $ocrPages): self + { + $self = clone $this; + $self['ocrPages'] = $ocrPages; + + return $self; + } } diff --git a/src/Batch/BatchListResponse/Data/Credits.php b/src/Batch/BatchListResponse/Data/Credits.php index cfb610d..37c7deb 100644 --- a/src/Batch/BatchListResponse/Data/Credits.php +++ b/src/Batch/BatchListResponse/Data/Credits.php @@ -11,7 +11,9 @@ /** * What this batch has done to your credit balance. * - * @phpstan-type CreditsShape = array{net: int, refunded: int, reserved: int} + * @phpstan-type CreditsShape = array{ + * net: int, ocrCharged: int, refunded: int, reserved: int + * } */ final class Credits implements BaseModel { @@ -19,11 +21,17 @@ final class Credits implements BaseModel use SdkModel; /** - * `reserved` minus `refunded` — what the batch has cost so far. Equal to `reserved` until the batch settles. + * `reserved` minus `refunded` plus `ocr_charged` — what the batch has cost so far. Equal to `reserved` until the batch settles. */ #[Required] public int $net; + /** + * Credits charged for PDF pages recovered by OCR (pdf.ocr=true), 1 per recovered page, on top of `reserved`. Stays 0 until the batch settles. + */ + #[Required('ocr_charged')] + public int $ocrCharged; + /** * Credits returned for pages that did not succeed. Stays 0 until the batch reaches a final status, then settles in one movement. */ @@ -41,13 +49,17 @@ final class Credits implements BaseModel * * To enforce required parameters use * ``` - * Credits::with(net: ..., refunded: ..., reserved: ...) + * Credits::with(net: ..., ocrCharged: ..., refunded: ..., reserved: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new Credits)->withNet(...)->withRefunded(...)->withReserved(...) + * (new Credits) + * ->withNet(...) + * ->withOcrCharged(...) + * ->withRefunded(...) + * ->withReserved(...) * ``` */ public function __construct() @@ -60,11 +72,16 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. */ - public static function with(int $net, int $refunded, int $reserved): self - { + public static function with( + int $net, + int $ocrCharged, + int $refunded, + int $reserved + ): self { $self = new self; $self['net'] = $net; + $self['ocrCharged'] = $ocrCharged; $self['refunded'] = $refunded; $self['reserved'] = $reserved; @@ -72,7 +89,7 @@ public static function with(int $net, int $refunded, int $reserved): self } /** - * `reserved` minus `refunded` — what the batch has cost so far. Equal to `reserved` until the batch settles. + * `reserved` minus `refunded` plus `ocr_charged` — what the batch has cost so far. Equal to `reserved` until the batch settles. */ public function withNet(int $net): self { @@ -82,6 +99,17 @@ public function withNet(int $net): self return $self; } + /** + * Credits charged for PDF pages recovered by OCR (pdf.ocr=true), 1 per recovered page, on top of `reserved`. Stays 0 until the batch settles. + */ + public function withOcrCharged(int $ocrCharged): self + { + $self = clone $this; + $self['ocrCharged'] = $ocrCharged; + + return $self; + } + /** * Credits returned for pages that did not succeed. Stays 0 until the batch reaches a final status, then settles in one movement. */ diff --git a/src/Batch/BatchSubmitParams.php b/src/Batch/BatchSubmitParams.php index c1a94b3..f231ee4 100644 --- a/src/Batch/BatchSubmitParams.php +++ b/src/Batch/BatchSubmitParams.php @@ -4,7 +4,9 @@ namespace ContextDev\Batch; -use ContextDev\Batch\BatchSubmitParams\Identifiers; +use ContextDev\Batch\BatchSubmitParams\Input; +use ContextDev\Batch\BatchSubmitParams\Input\Crawl; +use ContextDev\Batch\BatchSubmitParams\Input\Scrape; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; use ContextDev\Core\Concerns\SdkModel; @@ -12,16 +14,18 @@ use ContextDev\Core\Contracts\BaseModel; /** - * Retrieve and normalize a person profile from identifiers. + * Scrape 25K URLs or crawl large websites asynchronously. * * @see ContextDev\Services\BatchService::submit() * - * @phpstan-import-type IdentifiersShape from \ContextDev\Batch\BatchSubmitParams\Identifiers + * @phpstan-import-type InputVariants from \ContextDev\Batch\BatchSubmitParams\Input + * @phpstan-import-type InputShape from \ContextDev\Batch\BatchSubmitParams\Input * * @phpstan-type BatchSubmitParamsShape = array{ - * identifiers: Identifiers|IdentifiersShape, + * input: InputShape, * tags?: list|null, - * timeoutMs?: int|null, + * webhookURL?: string|null, + * idempotencyKey?: string|null, * } */ final class BatchSubmitParams implements BaseModel @@ -31,13 +35,15 @@ final class BatchSubmitParams implements BaseModel use SdkParams; /** - * Known identifiers for the person. At least one identifier is required. + * Choose a URL list or a site crawl. + * + * @var InputVariants $input */ - #[Required] - public Identifiers $identifiers; + #[Required(union: Input::class)] + public Scrape|Crawl $input; /** - * Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. + * Tags stored on the batch. Filter the batch list by them later. * * @var list|null $tags */ @@ -45,23 +51,29 @@ final class BatchSubmitParams implements BaseModel public ?array $tags; /** - * Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + * URL notified when the batch finishes. + */ + #[Optional('webhookUrl')] + public ?string $webhookURL; + + /** + * Any string unique to this submission. Retries with the same key return the original batch. */ - #[Optional('timeoutMS')] - public ?int $timeoutMs; + #[Optional] + public ?string $idempotencyKey; /** * `new BatchSubmitParams()` is missing required properties by the API. * * To enforce required parameters use * ``` - * BatchSubmitParams::with(identifiers: ...) + * BatchSubmitParams::with(input: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new BatchSubmitParams)->withIdentifiers(...) + * (new BatchSubmitParams)->withInput(...) * ``` */ public function __construct() @@ -74,39 +86,41 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Identifiers|IdentifiersShape $identifiers + * @param InputShape $input * @param list|null $tags */ public static function with( - Identifiers|array $identifiers, + Scrape|array|Crawl $input, ?array $tags = null, - ?int $timeoutMs = null + ?string $webhookURL = null, + ?string $idempotencyKey = null, ): self { $self = new self; - $self['identifiers'] = $identifiers; + $self['input'] = $input; null !== $tags && $self['tags'] = $tags; - null !== $timeoutMs && $self['timeoutMs'] = $timeoutMs; + null !== $webhookURL && $self['webhookURL'] = $webhookURL; + null !== $idempotencyKey && $self['idempotencyKey'] = $idempotencyKey; return $self; } /** - * Known identifiers for the person. At least one identifier is required. + * Choose a URL list or a site crawl. * - * @param Identifiers|IdentifiersShape $identifiers + * @param InputShape $input */ - public function withIdentifiers(Identifiers|array $identifiers): self + public function withInput(Scrape|array|Crawl $input): self { $self = clone $this; - $self['identifiers'] = $identifiers; + $self['input'] = $input; return $self; } /** - * Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. + * Tags stored on the batch. Filter the batch list by them later. * * @param list $tags */ @@ -119,12 +133,23 @@ public function withTags(array $tags): self } /** - * Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + * URL notified when the batch finishes. + */ + public function withWebhookURL(string $webhookURL): self + { + $self = clone $this; + $self['webhookURL'] = $webhookURL; + + return $self; + } + + /** + * Any string unique to this submission. Retries with the same key return the original batch. */ - public function withTimeoutMs(int $timeoutMs): self + public function withIdempotencyKey(string $idempotencyKey): self { $self = clone $this; - $self['timeoutMs'] = $timeoutMs; + $self['idempotencyKey'] = $idempotencyKey; return $self; } diff --git a/src/Batch/BatchSubmitParams/Identifiers.php b/src/Batch/BatchSubmitParams/Identifiers.php deleted file mode 100644 index 5ceb6cb..0000000 --- a/src/Batch/BatchSubmitParams/Identifiers.php +++ /dev/null @@ -1,56 +0,0 @@ - */ - use SdkModel; - - /** - * LinkedIn profile URL, e.g. https://www.linkedin.com/in/yahia-bakour/. - */ - #[Optional('linkedinUrl')] - public ?string $linkedinURL; - - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - */ - public static function with(?string $linkedinURL = null): self - { - $self = new self; - - null !== $linkedinURL && $self['linkedinURL'] = $linkedinURL; - - return $self; - } - - /** - * LinkedIn profile URL, e.g. https://www.linkedin.com/in/yahia-bakour/. - */ - public function withLinkedinURL(string $linkedinURL): self - { - $self = clone $this; - $self['linkedinURL'] = $linkedinURL; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitParams/Input.php b/src/Batch/BatchSubmitParams/Input.php new file mode 100644 index 0000000..995acfc --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input.php @@ -0,0 +1,38 @@ +|array + */ + public static function variants(): array + { + return ['scrape' => Scrape::class, 'crawl' => Crawl::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl.php b/src/Batch/BatchSubmitParams/Input/Crawl.php new file mode 100644 index 0000000..f785a5c --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl.php @@ -0,0 +1,103 @@ + */ + use SdkModel; + + /** + * Discover and scrape pages from `data.source`. + * + * @var 'crawl' $mode + */ + #[Required] + public string $mode = 'crawl'; + + /** + * Crawl source and output format. + * + * @var DataVariants $data + */ + #[Required(union: Data::class)] + public Markdown|HTML $data; + + /** + * `new Crawl()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Crawl::with(data: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Crawl)->withData(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param DataShape $data + */ + public static function with(Markdown|array|HTML $data): self + { + $self = new self; + + $self['data'] = $data; + + return $self; + } + + /** + * Crawl source and output format. + * + * @param DataShape $data + */ + public function withData(Markdown|array|HTML $data): self + { + $self = clone $this; + $self['data'] = $data; + + return $self; + } + + /** + * Discover and scrape pages from `data.source`. + * + * @param 'crawl' $mode + */ + public function withMode(string $mode): self + { + $self = clone $this; + $self['mode'] = $mode; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data.php new file mode 100644 index 0000000..2e5d21f --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data.php @@ -0,0 +1,38 @@ +|array + */ + public static function variants(): array + { + return ['markdown' => Markdown::class, 'html' => HTML::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML.php new file mode 100644 index 0000000..73d2736 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML.php @@ -0,0 +1,132 @@ + */ + use SdkModel; + + /** + * Return page content as HTML. + * + * @var 'html' $format + */ + #[Required] + public string $format = 'html'; + + /** + * How to find pages to crawl. + * + * @var SourceVariants $source + */ + #[Required(union: Source::class)] + public StartURL|Sitemap $source; + + /** + * Options for HTML output. + */ + #[Optional] + public ?Options $options; + + /** + * `new HTML()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * HTML::with(source: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new HTML)->withSource(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param SourceShape $source + * @param Options|OptionsShape|null $options + */ + public static function with( + StartURL|array|Sitemap $source, + Options|array|null $options = null + ): self { + $self = new self; + + $self['source'] = $source; + + null !== $options && $self['options'] = $options; + + return $self; + } + + /** + * Return page content as HTML. + * + * @param 'html' $format + */ + public function withFormat(string $format): self + { + $self = clone $this; + $self['format'] = $format; + + return $self; + } + + /** + * How to find pages to crawl. + * + * @param SourceShape $source + */ + public function withSource(StartURL|array|Sitemap $source): self + { + $self = clone $this; + $self['source'] = $source; + + return $self; + } + + /** + * Options for HTML output. + * + * @param Options|OptionsShape $options + */ + public function withOptions(Options|array $options): self + { + $self = clone $this; + $self['options'] = $options; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options.php new file mode 100644 index 0000000..823d3a2 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options.php @@ -0,0 +1,222 @@ +, + * excludeSelectors?: list|null, + * includeSelectors?: list|null, + * maxAgeMs?: int|null, + * pdf?: null|Pdf|PdfShape, + * settleAnimations?: bool|null, + * useMainContentOnly?: bool|null, + * waitForMs?: int|null, + * } + */ +final class Options implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @var list|null $excludeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $excludeSelectors; + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @var list|null $includeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $includeSelectors; + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + #[Optional(nullable: true)] + public ?int $maxAgeMs; + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + */ + #[Optional] + public ?Pdf $pdf; + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + #[Optional] + public ?bool $settleAnimations; + + /** + * Return the main content without navigation or footers. + */ + #[Optional] + public ?bool $useMainContentOnly; + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + #[Optional] + public ?int $waitForMs; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Country|value-of|null $country + * @param list|null $excludeSelectors + * @param list|null $includeSelectors + * @param Pdf|PdfShape|null $pdf + */ + public static function with( + Country|string|null $country = null, + ?array $excludeSelectors = null, + ?array $includeSelectors = null, + ?int $maxAgeMs = null, + Pdf|array|null $pdf = null, + ?bool $settleAnimations = null, + ?bool $useMainContentOnly = null, + ?int $waitForMs = null, + ): self { + $self = new self; + + null !== $country && $self['country'] = $country; + null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; + null !== $includeSelectors && $self['includeSelectors'] = $includeSelectors; + null !== $maxAgeMs && $self['maxAgeMs'] = $maxAgeMs; + null !== $pdf && $self['pdf'] = $pdf; + null !== $settleAnimations && $self['settleAnimations'] = $settleAnimations; + null !== $useMainContentOnly && $self['useMainContentOnly'] = $useMainContentOnly; + null !== $waitForMs && $self['waitForMs'] = $waitForMs; + + return $self; + } + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @param list|null $excludeSelectors + */ + public function withExcludeSelectors(?array $excludeSelectors): self + { + $self = clone $this; + $self['excludeSelectors'] = $excludeSelectors; + + return $self; + } + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @param list|null $includeSelectors + */ + public function withIncludeSelectors(?array $includeSelectors): self + { + $self = clone $this; + $self['includeSelectors'] = $includeSelectors; + + return $self; + } + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + public function withMaxAgeMs(?int $maxAgeMs): self + { + $self = clone $this; + $self['maxAgeMs'] = $maxAgeMs; + + return $self; + } + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + * + * @param Pdf|PdfShape $pdf + */ + public function withPdf(Pdf|array $pdf): self + { + $self = clone $this; + $self['pdf'] = $pdf; + + return $self; + } + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + public function withSettleAnimations(bool $settleAnimations): self + { + $self = clone $this; + $self['settleAnimations'] = $settleAnimations; + + return $self; + } + + /** + * Return the main content without navigation or footers. + */ + public function withUseMainContentOnly(bool $useMainContentOnly): self + { + $self = clone $this; + $self['useMainContentOnly'] = $useMainContentOnly; + + return $self; + } + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + public function withWaitForMs(int $waitForMs): self + { + $self = clone $this; + $self['waitForMs'] = $waitForMs; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Country.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Country.php new file mode 100644 index 0000000..30da436 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Country.php @@ -0,0 +1,419 @@ + */ + use SdkModel; + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + #[Optional] + public ?int $end; + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @var OcrVariants|null $ocr + */ + #[Optional(union: Ocr::class)] + public bool|string|null $ocr; + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @var ShouldParseVariants|null $shouldParse + */ + #[Optional(union: ShouldParse::class)] + public bool|string|null $shouldParse; + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + #[Optional] + public ?int $start; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param OcrShape|null $ocr + * @param ShouldParseShape|null $shouldParse + */ + public static function with( + ?int $end = null, + bool|UnionMember1|string|null $ocr = null, + bool|ShouldParse\UnionMember1|string|null $shouldParse = null, + ?int $start = null, + ): self { + $self = new self; + + null !== $end && $self['end'] = $end; + null !== $ocr && $self['ocr'] = $ocr; + null !== $shouldParse && $self['shouldParse'] = $shouldParse; + null !== $start && $self['start'] = $start; + + return $self; + } + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + public function withEnd(int $end): self + { + $self = clone $this; + $self['end'] = $end; + + return $self; + } + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @param OcrShape $ocr + */ + public function withOcr(bool|UnionMember1|string $ocr): self + { + $self = clone $this; + $self['ocr'] = $ocr; + + return $self; + } + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @param ShouldParseShape $shouldParse + */ + public function withShouldParse( + bool|ShouldParse\UnionMember1|string $shouldParse, + ): self { + $self = clone $this; + $self['shouldParse'] = $shouldParse; + + return $self; + } + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + public function withStart(int $start): self + { + $self = clone $this; + $self['start'] = $start; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/Ocr.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/Ocr.php new file mode 100644 index 0000000..f6b7285 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/Ocr.php @@ -0,0 +1,29 @@ + + * @phpstan-type OcrShape = OcrVariants + */ +final class Ocr implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/Ocr/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/Ocr/UnionMember1.php new file mode 100644 index 0000000..8fa3635 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/Ocr/UnionMember1.php @@ -0,0 +1,12 @@ + + * @phpstan-type ShouldParseShape = ShouldParseVariants + */ +final class ShouldParse implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/ShouldParse/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/ShouldParse/UnionMember1.php new file mode 100644 index 0000000..7150ad6 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Options/Pdf/ShouldParse/UnionMember1.php @@ -0,0 +1,12 @@ +|array + */ + public static function variants(): array + { + return ['start_url' => StartURL::class, 'sitemap' => Sitemap::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/Sitemap.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/Sitemap.php new file mode 100644 index 0000000..88b7b48 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/Sitemap.php @@ -0,0 +1,122 @@ + */ + use SdkModel; + + /** + * Scrape the URLs in the domain's sitemap. + * + * @var 'sitemap' $type + */ + #[Required] + public string $type = 'sitemap'; + + /** + * Domain whose sitemap lists the pages to scrape. A full URL is reduced to its domain. + */ + #[Required] + public string $domain; + + /** + * Limits and filters for the sitemap URLs. A sitemap batch scrapes exactly those URLs and never follows links off them, so there is no crawl depth here. + */ + #[Optional] + public ?Controls $controls; + + /** + * `new Sitemap()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Sitemap::with(domain: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Sitemap)->withDomain(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Controls|ControlsShape|null $controls + */ + public static function with( + string $domain, + Controls|array|null $controls = null + ): self { + $self = new self; + + $self['domain'] = $domain; + + null !== $controls && $self['controls'] = $controls; + + return $self; + } + + /** + * Domain whose sitemap lists the pages to scrape. A full URL is reduced to its domain. + */ + public function withDomain(string $domain): self + { + $self = clone $this; + $self['domain'] = $domain; + + return $self; + } + + /** + * Scrape the URLs in the domain's sitemap. + * + * @param 'sitemap' $type + */ + public function withType(string $type): self + { + $self = clone $this; + $self['type'] = $type; + + return $self; + } + + /** + * Limits and filters for the sitemap URLs. A sitemap batch scrapes exactly those URLs and never follows links off them, so there is no crawl depth here. + * + * @param Controls|ControlsShape $controls + */ + public function withControls(Controls|array $controls): self + { + $self = clone $this; + $self['controls'] = $controls; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/Sitemap/Controls.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/Sitemap/Controls.php new file mode 100644 index 0000000..1868bf7 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/Sitemap/Controls.php @@ -0,0 +1,74 @@ + */ + use SdkModel; + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + #[Optional('maxUrls')] + public ?int $maxURLs; + + /** + * RE2 pattern; only sitemap URLs matching it are scraped. + */ + #[Optional] + public ?string $regex; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(?int $maxURLs = null, ?string $regex = null): self + { + $self = new self; + + null !== $maxURLs && $self['maxURLs'] = $maxURLs; + null !== $regex && $self['regex'] = $regex; + + return $self; + } + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + public function withMaxURLs(int $maxURLs): self + { + $self = clone $this; + $self['maxURLs'] = $maxURLs; + + return $self; + } + + /** + * RE2 pattern; only sitemap URLs matching it are scraped. + */ + public function withRegex(string $regex): self + { + $self = clone $this; + $self['regex'] = $regex; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/StartURL.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/StartURL.php new file mode 100644 index 0000000..944bb15 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/StartURL.php @@ -0,0 +1,122 @@ + */ + use SdkModel; + + /** + * Start from one page. + * + * @var 'start_url' $type + */ + #[Required] + public string $type = 'start_url'; + + /** + * Page where crawling begins. A URL without a scheme is read as https://. + */ + #[Required] + public string $url; + + /** + * Limits and filters for page discovery. + */ + #[Optional] + public ?Controls $controls; + + /** + * `new StartURL()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * StartURL::with(url: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new StartURL)->withURL(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Controls|ControlsShape|null $controls + */ + public static function with( + string $url, + Controls|array|null $controls = null + ): self { + $self = new self; + + $self['url'] = $url; + + null !== $controls && $self['controls'] = $controls; + + return $self; + } + + /** + * Start from one page. + * + * @param 'start_url' $type + */ + public function withType(string $type): self + { + $self = clone $this; + $self['type'] = $type; + + return $self; + } + + /** + * Page where crawling begins. A URL without a scheme is read as https://. + */ + public function withURL(string $url): self + { + $self = clone $this; + $self['url'] = $url; + + return $self; + } + + /** + * Limits and filters for page discovery. + * + * @param Controls|ControlsShape $controls + */ + public function withControls(Controls|array $controls): self + { + $self = clone $this; + $self['controls'] = $controls; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/StartURL/Controls.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/StartURL/Controls.php new file mode 100644 index 0000000..29fe8f0 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/HTML/Source/StartURL/Controls.php @@ -0,0 +1,119 @@ + */ + use SdkModel; + + /** + * Follow links to subdomains. + */ + #[Optional] + public ?bool $followSubdomains; + + /** + * Maximum link depth. Source pages are depth 0. No limit when omitted. + */ + #[Optional] + public ?int $maxDepth; + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + #[Optional('maxUrls')] + public ?int $maxURLs; + + /** + * RE2 pattern for URLs to include. The `start_url` itself is always included. + */ + #[Optional] + public ?string $regex; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?bool $followSubdomains = null, + ?int $maxDepth = null, + ?int $maxURLs = null, + ?string $regex = null, + ): self { + $self = new self; + + null !== $followSubdomains && $self['followSubdomains'] = $followSubdomains; + null !== $maxDepth && $self['maxDepth'] = $maxDepth; + null !== $maxURLs && $self['maxURLs'] = $maxURLs; + null !== $regex && $self['regex'] = $regex; + + return $self; + } + + /** + * Follow links to subdomains. + */ + public function withFollowSubdomains(bool $followSubdomains): self + { + $self = clone $this; + $self['followSubdomains'] = $followSubdomains; + + return $self; + } + + /** + * Maximum link depth. Source pages are depth 0. No limit when omitted. + */ + public function withMaxDepth(int $maxDepth): self + { + $self = clone $this; + $self['maxDepth'] = $maxDepth; + + return $self; + } + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + public function withMaxURLs(int $maxURLs): self + { + $self = clone $this; + $self['maxURLs'] = $maxURLs; + + return $self; + } + + /** + * RE2 pattern for URLs to include. The `start_url` itself is always included. + */ + public function withRegex(string $regex): self + { + $self = clone $this; + $self['regex'] = $regex; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown.php new file mode 100644 index 0000000..3fcbde0 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown.php @@ -0,0 +1,132 @@ + */ + use SdkModel; + + /** + * Return page content as Markdown. + * + * @var 'markdown' $format + */ + #[Required] + public string $format = 'markdown'; + + /** + * How to find pages to crawl. + * + * @var SourceVariants $source + */ + #[Required(union: Source::class)] + public StartURL|Sitemap $source; + + /** + * Options for Markdown output. + */ + #[Optional] + public ?Options $options; + + /** + * `new Markdown()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Markdown::with(source: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Markdown)->withSource(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param SourceShape $source + * @param Options|OptionsShape|null $options + */ + public static function with( + StartURL|array|Sitemap $source, + Options|array|null $options = null + ): self { + $self = new self; + + $self['source'] = $source; + + null !== $options && $self['options'] = $options; + + return $self; + } + + /** + * Return page content as Markdown. + * + * @param 'markdown' $format + */ + public function withFormat(string $format): self + { + $self = clone $this; + $self['format'] = $format; + + return $self; + } + + /** + * How to find pages to crawl. + * + * @param SourceShape $source + */ + public function withSource(StartURL|array|Sitemap $source): self + { + $self = clone $this; + $self['source'] = $source; + + return $self; + } + + /** + * Options for Markdown output. + * + * @param Options|OptionsShape $options + */ + public function withOptions(Options|array $options): self + { + $self = clone $this; + $self['options'] = $options; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options.php new file mode 100644 index 0000000..20e33f6 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options.php @@ -0,0 +1,282 @@ +, + * excludeSelectors?: list|null, + * includeImages?: bool|null, + * includeLinks?: bool|null, + * includeSelectors?: list|null, + * maxAgeMs?: int|null, + * pdf?: null|Pdf|PdfShape, + * settleAnimations?: bool|null, + * shortenBase64Images?: bool|null, + * useMainContentOnly?: bool|null, + * waitForMs?: int|null, + * } + */ +final class Options implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @var list|null $excludeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $excludeSelectors; + + /** + * Include image references in the Markdown. + */ + #[Optional] + public ?bool $includeImages; + + /** + * Include links in the Markdown. + */ + #[Optional] + public ?bool $includeLinks; + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @var list|null $includeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $includeSelectors; + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + #[Optional(nullable: true)] + public ?int $maxAgeMs; + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + */ + #[Optional] + public ?Pdf $pdf; + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + #[Optional] + public ?bool $settleAnimations; + + /** + * Shorten inline base64 image data. + */ + #[Optional] + public ?bool $shortenBase64Images; + + /** + * Return the main content without navigation or footers. + */ + #[Optional] + public ?bool $useMainContentOnly; + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + #[Optional] + public ?int $waitForMs; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Country|value-of|null $country + * @param list|null $excludeSelectors + * @param list|null $includeSelectors + * @param Pdf|PdfShape|null $pdf + */ + public static function with( + Country|string|null $country = null, + ?array $excludeSelectors = null, + ?bool $includeImages = null, + ?bool $includeLinks = null, + ?array $includeSelectors = null, + ?int $maxAgeMs = null, + Pdf|array|null $pdf = null, + ?bool $settleAnimations = null, + ?bool $shortenBase64Images = null, + ?bool $useMainContentOnly = null, + ?int $waitForMs = null, + ): self { + $self = new self; + + null !== $country && $self['country'] = $country; + null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; + null !== $includeImages && $self['includeImages'] = $includeImages; + null !== $includeLinks && $self['includeLinks'] = $includeLinks; + null !== $includeSelectors && $self['includeSelectors'] = $includeSelectors; + null !== $maxAgeMs && $self['maxAgeMs'] = $maxAgeMs; + null !== $pdf && $self['pdf'] = $pdf; + null !== $settleAnimations && $self['settleAnimations'] = $settleAnimations; + null !== $shortenBase64Images && $self['shortenBase64Images'] = $shortenBase64Images; + null !== $useMainContentOnly && $self['useMainContentOnly'] = $useMainContentOnly; + null !== $waitForMs && $self['waitForMs'] = $waitForMs; + + return $self; + } + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @param list|null $excludeSelectors + */ + public function withExcludeSelectors(?array $excludeSelectors): self + { + $self = clone $this; + $self['excludeSelectors'] = $excludeSelectors; + + return $self; + } + + /** + * Include image references in the Markdown. + */ + public function withIncludeImages(bool $includeImages): self + { + $self = clone $this; + $self['includeImages'] = $includeImages; + + return $self; + } + + /** + * Include links in the Markdown. + */ + public function withIncludeLinks(bool $includeLinks): self + { + $self = clone $this; + $self['includeLinks'] = $includeLinks; + + return $self; + } + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @param list|null $includeSelectors + */ + public function withIncludeSelectors(?array $includeSelectors): self + { + $self = clone $this; + $self['includeSelectors'] = $includeSelectors; + + return $self; + } + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + public function withMaxAgeMs(?int $maxAgeMs): self + { + $self = clone $this; + $self['maxAgeMs'] = $maxAgeMs; + + return $self; + } + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + * + * @param Pdf|PdfShape $pdf + */ + public function withPdf(Pdf|array $pdf): self + { + $self = clone $this; + $self['pdf'] = $pdf; + + return $self; + } + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + public function withSettleAnimations(bool $settleAnimations): self + { + $self = clone $this; + $self['settleAnimations'] = $settleAnimations; + + return $self; + } + + /** + * Shorten inline base64 image data. + */ + public function withShortenBase64Images(bool $shortenBase64Images): self + { + $self = clone $this; + $self['shortenBase64Images'] = $shortenBase64Images; + + return $self; + } + + /** + * Return the main content without navigation or footers. + */ + public function withUseMainContentOnly(bool $useMainContentOnly): self + { + $self = clone $this; + $self['useMainContentOnly'] = $useMainContentOnly; + + return $self; + } + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + public function withWaitForMs(int $waitForMs): self + { + $self = clone $this; + $self['waitForMs'] = $waitForMs; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Country.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Country.php new file mode 100644 index 0000000..f16f355 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Country.php @@ -0,0 +1,419 @@ + */ + use SdkModel; + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + #[Optional] + public ?int $end; + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @var OcrVariants|null $ocr + */ + #[Optional(union: Ocr::class)] + public bool|string|null $ocr; + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @var ShouldParseVariants|null $shouldParse + */ + #[Optional(union: ShouldParse::class)] + public bool|string|null $shouldParse; + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + #[Optional] + public ?int $start; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param OcrShape|null $ocr + * @param ShouldParseShape|null $shouldParse + */ + public static function with( + ?int $end = null, + bool|UnionMember1|string|null $ocr = null, + bool|ShouldParse\UnionMember1|string|null $shouldParse = null, + ?int $start = null, + ): self { + $self = new self; + + null !== $end && $self['end'] = $end; + null !== $ocr && $self['ocr'] = $ocr; + null !== $shouldParse && $self['shouldParse'] = $shouldParse; + null !== $start && $self['start'] = $start; + + return $self; + } + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + public function withEnd(int $end): self + { + $self = clone $this; + $self['end'] = $end; + + return $self; + } + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @param OcrShape $ocr + */ + public function withOcr(bool|UnionMember1|string $ocr): self + { + $self = clone $this; + $self['ocr'] = $ocr; + + return $self; + } + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @param ShouldParseShape $shouldParse + */ + public function withShouldParse( + bool|ShouldParse\UnionMember1|string $shouldParse, + ): self { + $self = clone $this; + $self['shouldParse'] = $shouldParse; + + return $self; + } + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + public function withStart(int $start): self + { + $self = clone $this; + $self['start'] = $start; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/Ocr.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/Ocr.php new file mode 100644 index 0000000..5ec1a5c --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/Ocr.php @@ -0,0 +1,29 @@ + + * @phpstan-type OcrShape = OcrVariants + */ +final class Ocr implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/Ocr/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/Ocr/UnionMember1.php new file mode 100644 index 0000000..eeaff6f --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/Ocr/UnionMember1.php @@ -0,0 +1,12 @@ + + * @phpstan-type ShouldParseShape = ShouldParseVariants + */ +final class ShouldParse implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/ShouldParse/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/ShouldParse/UnionMember1.php new file mode 100644 index 0000000..c33e42d --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Options/Pdf/ShouldParse/UnionMember1.php @@ -0,0 +1,12 @@ +|array + */ + public static function variants(): array + { + return ['start_url' => StartURL::class, 'sitemap' => Sitemap::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/Sitemap.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/Sitemap.php new file mode 100644 index 0000000..d7c860a --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/Sitemap.php @@ -0,0 +1,122 @@ + */ + use SdkModel; + + /** + * Scrape the URLs in the domain's sitemap. + * + * @var 'sitemap' $type + */ + #[Required] + public string $type = 'sitemap'; + + /** + * Domain whose sitemap lists the pages to scrape. A full URL is reduced to its domain. + */ + #[Required] + public string $domain; + + /** + * Limits and filters for the sitemap URLs. A sitemap batch scrapes exactly those URLs and never follows links off them, so there is no crawl depth here. + */ + #[Optional] + public ?Controls $controls; + + /** + * `new Sitemap()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Sitemap::with(domain: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Sitemap)->withDomain(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Controls|ControlsShape|null $controls + */ + public static function with( + string $domain, + Controls|array|null $controls = null + ): self { + $self = new self; + + $self['domain'] = $domain; + + null !== $controls && $self['controls'] = $controls; + + return $self; + } + + /** + * Domain whose sitemap lists the pages to scrape. A full URL is reduced to its domain. + */ + public function withDomain(string $domain): self + { + $self = clone $this; + $self['domain'] = $domain; + + return $self; + } + + /** + * Scrape the URLs in the domain's sitemap. + * + * @param 'sitemap' $type + */ + public function withType(string $type): self + { + $self = clone $this; + $self['type'] = $type; + + return $self; + } + + /** + * Limits and filters for the sitemap URLs. A sitemap batch scrapes exactly those URLs and never follows links off them, so there is no crawl depth here. + * + * @param Controls|ControlsShape $controls + */ + public function withControls(Controls|array $controls): self + { + $self = clone $this; + $self['controls'] = $controls; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/Sitemap/Controls.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/Sitemap/Controls.php new file mode 100644 index 0000000..0b3de54 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/Sitemap/Controls.php @@ -0,0 +1,74 @@ + */ + use SdkModel; + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + #[Optional('maxUrls')] + public ?int $maxURLs; + + /** + * RE2 pattern; only sitemap URLs matching it are scraped. + */ + #[Optional] + public ?string $regex; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(?int $maxURLs = null, ?string $regex = null): self + { + $self = new self; + + null !== $maxURLs && $self['maxURLs'] = $maxURLs; + null !== $regex && $self['regex'] = $regex; + + return $self; + } + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + public function withMaxURLs(int $maxURLs): self + { + $self = clone $this; + $self['maxURLs'] = $maxURLs; + + return $self; + } + + /** + * RE2 pattern; only sitemap URLs matching it are scraped. + */ + public function withRegex(string $regex): self + { + $self = clone $this; + $self['regex'] = $regex; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/StartURL.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/StartURL.php new file mode 100644 index 0000000..7af4bc4 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/StartURL.php @@ -0,0 +1,122 @@ + */ + use SdkModel; + + /** + * Start from one page. + * + * @var 'start_url' $type + */ + #[Required] + public string $type = 'start_url'; + + /** + * Page where crawling begins. A URL without a scheme is read as https://. + */ + #[Required] + public string $url; + + /** + * Limits and filters for page discovery. + */ + #[Optional] + public ?Controls $controls; + + /** + * `new StartURL()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * StartURL::with(url: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new StartURL)->withURL(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Controls|ControlsShape|null $controls + */ + public static function with( + string $url, + Controls|array|null $controls = null + ): self { + $self = new self; + + $self['url'] = $url; + + null !== $controls && $self['controls'] = $controls; + + return $self; + } + + /** + * Start from one page. + * + * @param 'start_url' $type + */ + public function withType(string $type): self + { + $self = clone $this; + $self['type'] = $type; + + return $self; + } + + /** + * Page where crawling begins. A URL without a scheme is read as https://. + */ + public function withURL(string $url): self + { + $self = clone $this; + $self['url'] = $url; + + return $self; + } + + /** + * Limits and filters for page discovery. + * + * @param Controls|ControlsShape $controls + */ + public function withControls(Controls|array $controls): self + { + $self = clone $this; + $self['controls'] = $controls; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/StartURL/Controls.php b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/StartURL/Controls.php new file mode 100644 index 0000000..44880f7 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Crawl/Data/Markdown/Source/StartURL/Controls.php @@ -0,0 +1,119 @@ + */ + use SdkModel; + + /** + * Follow links to subdomains. + */ + #[Optional] + public ?bool $followSubdomains; + + /** + * Maximum link depth. Source pages are depth 0. No limit when omitted. + */ + #[Optional] + public ?int $maxDepth; + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + #[Optional('maxUrls')] + public ?int $maxURLs; + + /** + * RE2 pattern for URLs to include. The `start_url` itself is always included. + */ + #[Optional] + public ?string $regex; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?bool $followSubdomains = null, + ?int $maxDepth = null, + ?int $maxURLs = null, + ?string $regex = null, + ): self { + $self = new self; + + null !== $followSubdomains && $self['followSubdomains'] = $followSubdomains; + null !== $maxDepth && $self['maxDepth'] = $maxDepth; + null !== $maxURLs && $self['maxURLs'] = $maxURLs; + null !== $regex && $self['regex'] = $regex; + + return $self; + } + + /** + * Follow links to subdomains. + */ + public function withFollowSubdomains(bool $followSubdomains): self + { + $self = clone $this; + $self['followSubdomains'] = $followSubdomains; + + return $self; + } + + /** + * Maximum link depth. Source pages are depth 0. No limit when omitted. + */ + public function withMaxDepth(int $maxDepth): self + { + $self = clone $this; + $self['maxDepth'] = $maxDepth; + + return $self; + } + + /** + * Maximum pages to fetch. Unused reserved credits are refunded. Maximum 25000. + */ + public function withMaxURLs(int $maxURLs): self + { + $self = clone $this; + $self['maxURLs'] = $maxURLs; + + return $self; + } + + /** + * RE2 pattern for URLs to include. The `start_url` itself is always included. + */ + public function withRegex(string $regex): self + { + $self = clone $this; + $self['regex'] = $regex; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape.php b/src/Batch/BatchSubmitParams/Input/Scrape.php new file mode 100644 index 0000000..1842547 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape.php @@ -0,0 +1,103 @@ + */ + use SdkModel; + + /** + * Scrape the pages in `data.urls`. + * + * @var 'scrape' $mode + */ + #[Required] + public string $mode = 'scrape'; + + /** + * Pages to scrape and their output format. + * + * @var DataVariants $data + */ + #[Required(union: Data::class)] + public Markdown|HTML $data; + + /** + * `new Scrape()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Scrape::with(data: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Scrape)->withData(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param DataShape $data + */ + public static function with(Markdown|array|HTML $data): self + { + $self = new self; + + $self['data'] = $data; + + return $self; + } + + /** + * Pages to scrape and their output format. + * + * @param DataShape $data + */ + public function withData(Markdown|array|HTML $data): self + { + $self = clone $this; + $self['data'] = $data; + + return $self; + } + + /** + * Scrape the pages in `data.urls`. + * + * @param 'scrape' $mode + */ + public function withMode(string $mode): self + { + $self = clone $this; + $self['mode'] = $mode; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data.php new file mode 100644 index 0000000..37e5c05 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data.php @@ -0,0 +1,38 @@ +|array + */ + public static function variants(): array + { + return ['markdown' => Markdown::class, 'html' => HTML::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML.php new file mode 100644 index 0000000..cf0ae5c --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML.php @@ -0,0 +1,129 @@ +, options?: null|Options|OptionsShape + * } + */ +final class HTML implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Return page content as HTML. + * + * @var 'html' $format + */ + #[Required] + public string $format = 'html'; + + /** + * Pages to scrape. Maximum 25000. + * + * @var list $urls + */ + #[Required(list: URL::class)] + public array $urls; + + /** + * Options for HTML output. + */ + #[Optional] + public ?Options $options; + + /** + * `new HTML()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * HTML::with(urls: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new HTML)->withURLs(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param list $urls + * @param Options|OptionsShape|null $options + */ + public static function with( + array $urls, + Options|array|null $options = null + ): self { + $self = new self; + + $self['urls'] = $urls; + + null !== $options && $self['options'] = $options; + + return $self; + } + + /** + * Return page content as HTML. + * + * @param 'html' $format + */ + public function withFormat(string $format): self + { + $self = clone $this; + $self['format'] = $format; + + return $self; + } + + /** + * Pages to scrape. Maximum 25000. + * + * @param list $urls + */ + public function withURLs(array $urls): self + { + $self = clone $this; + $self['urls'] = $urls; + + return $self; + } + + /** + * Options for HTML output. + * + * @param Options|OptionsShape $options + */ + public function withOptions(Options|array $options): self + { + $self = clone $this; + $self['options'] = $options; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options.php new file mode 100644 index 0000000..83d4ac3 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options.php @@ -0,0 +1,222 @@ +, + * excludeSelectors?: list|null, + * includeSelectors?: list|null, + * maxAgeMs?: int|null, + * pdf?: null|Pdf|PdfShape, + * settleAnimations?: bool|null, + * useMainContentOnly?: bool|null, + * waitForMs?: int|null, + * } + */ +final class Options implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @var list|null $excludeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $excludeSelectors; + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @var list|null $includeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $includeSelectors; + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + #[Optional(nullable: true)] + public ?int $maxAgeMs; + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + */ + #[Optional] + public ?Pdf $pdf; + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + #[Optional] + public ?bool $settleAnimations; + + /** + * Return the main content without navigation or footers. + */ + #[Optional] + public ?bool $useMainContentOnly; + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + #[Optional] + public ?int $waitForMs; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Country|value-of|null $country + * @param list|null $excludeSelectors + * @param list|null $includeSelectors + * @param Pdf|PdfShape|null $pdf + */ + public static function with( + Country|string|null $country = null, + ?array $excludeSelectors = null, + ?array $includeSelectors = null, + ?int $maxAgeMs = null, + Pdf|array|null $pdf = null, + ?bool $settleAnimations = null, + ?bool $useMainContentOnly = null, + ?int $waitForMs = null, + ): self { + $self = new self; + + null !== $country && $self['country'] = $country; + null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; + null !== $includeSelectors && $self['includeSelectors'] = $includeSelectors; + null !== $maxAgeMs && $self['maxAgeMs'] = $maxAgeMs; + null !== $pdf && $self['pdf'] = $pdf; + null !== $settleAnimations && $self['settleAnimations'] = $settleAnimations; + null !== $useMainContentOnly && $self['useMainContentOnly'] = $useMainContentOnly; + null !== $waitForMs && $self['waitForMs'] = $waitForMs; + + return $self; + } + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @param list|null $excludeSelectors + */ + public function withExcludeSelectors(?array $excludeSelectors): self + { + $self = clone $this; + $self['excludeSelectors'] = $excludeSelectors; + + return $self; + } + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @param list|null $includeSelectors + */ + public function withIncludeSelectors(?array $includeSelectors): self + { + $self = clone $this; + $self['includeSelectors'] = $includeSelectors; + + return $self; + } + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + public function withMaxAgeMs(?int $maxAgeMs): self + { + $self = clone $this; + $self['maxAgeMs'] = $maxAgeMs; + + return $self; + } + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + * + * @param Pdf|PdfShape $pdf + */ + public function withPdf(Pdf|array $pdf): self + { + $self = clone $this; + $self['pdf'] = $pdf; + + return $self; + } + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + public function withSettleAnimations(bool $settleAnimations): self + { + $self = clone $this; + $self['settleAnimations'] = $settleAnimations; + + return $self; + } + + /** + * Return the main content without navigation or footers. + */ + public function withUseMainContentOnly(bool $useMainContentOnly): self + { + $self = clone $this; + $self['useMainContentOnly'] = $useMainContentOnly; + + return $self; + } + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + public function withWaitForMs(int $waitForMs): self + { + $self = clone $this; + $self['waitForMs'] = $waitForMs; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Country.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Country.php new file mode 100644 index 0000000..733da41 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Country.php @@ -0,0 +1,419 @@ + */ + use SdkModel; + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + #[Optional] + public ?int $end; + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @var OcrVariants|null $ocr + */ + #[Optional(union: Ocr::class)] + public bool|string|null $ocr; + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @var ShouldParseVariants|null $shouldParse + */ + #[Optional(union: ShouldParse::class)] + public bool|string|null $shouldParse; + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + #[Optional] + public ?int $start; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param OcrShape|null $ocr + * @param ShouldParseShape|null $shouldParse + */ + public static function with( + ?int $end = null, + bool|UnionMember1|string|null $ocr = null, + bool|ShouldParse\UnionMember1|string|null $shouldParse = null, + ?int $start = null, + ): self { + $self = new self; + + null !== $end && $self['end'] = $end; + null !== $ocr && $self['ocr'] = $ocr; + null !== $shouldParse && $self['shouldParse'] = $shouldParse; + null !== $start && $self['start'] = $start; + + return $self; + } + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + public function withEnd(int $end): self + { + $self = clone $this; + $self['end'] = $end; + + return $self; + } + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @param OcrShape $ocr + */ + public function withOcr(bool|UnionMember1|string $ocr): self + { + $self = clone $this; + $self['ocr'] = $ocr; + + return $self; + } + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @param ShouldParseShape $shouldParse + */ + public function withShouldParse( + bool|ShouldParse\UnionMember1|string $shouldParse, + ): self { + $self = clone $this; + $self['shouldParse'] = $shouldParse; + + return $self; + } + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + public function withStart(int $start): self + { + $self = clone $this; + $self['start'] = $start; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/Ocr.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/Ocr.php new file mode 100644 index 0000000..71e7691 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/Ocr.php @@ -0,0 +1,29 @@ + + * @phpstan-type OcrShape = OcrVariants + */ +final class Ocr implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/Ocr/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/Ocr/UnionMember1.php new file mode 100644 index 0000000..afe8fda --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/Ocr/UnionMember1.php @@ -0,0 +1,12 @@ + + * @phpstan-type ShouldParseShape = ShouldParseVariants + */ +final class ShouldParse implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/ShouldParse/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/ShouldParse/UnionMember1.php new file mode 100644 index 0000000..53f4ef0 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/HTML/Options/Pdf/ShouldParse/UnionMember1.php @@ -0,0 +1,12 @@ +|null + * } + */ +final class URL implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Page URL to scrape. + */ + #[Required] + public string $url; + + /** + * Your ID for this page, returned with its result. The same URL can use different IDs. + */ + #[Optional('itemId')] + public ?string $itemID; + + /** + * Custom JSON returned unchanged with this page result. + * + * @var array|null $meta + */ + #[Optional(map: 'mixed')] + public ?array $meta; + + /** + * `new URL()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * URL::with(url: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new URL)->withURL(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param array|null $meta + */ + public static function with( + string $url, + ?string $itemID = null, + ?array $meta = null + ): self { + $self = new self; + + $self['url'] = $url; + + null !== $itemID && $self['itemID'] = $itemID; + null !== $meta && $self['meta'] = $meta; + + return $self; + } + + /** + * Page URL to scrape. + */ + public function withURL(string $url): self + { + $self = clone $this; + $self['url'] = $url; + + return $self; + } + + /** + * Your ID for this page, returned with its result. The same URL can use different IDs. + */ + public function withItemID(string $itemID): self + { + $self = clone $this; + $self['itemID'] = $itemID; + + return $self; + } + + /** + * Custom JSON returned unchanged with this page result. + * + * @param array $meta + */ + public function withMeta(array $meta): self + { + $self = clone $this; + $self['meta'] = $meta; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown.php new file mode 100644 index 0000000..be4ccda --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown.php @@ -0,0 +1,131 @@ +, + * options?: null|Options|OptionsShape, + * } + */ +final class Markdown implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Return page content as Markdown. + * + * @var 'markdown' $format + */ + #[Required] + public string $format = 'markdown'; + + /** + * Pages to scrape. Maximum 25000. + * + * @var list $urls + */ + #[Required(list: URL::class)] + public array $urls; + + /** + * Options for Markdown output. + */ + #[Optional] + public ?Options $options; + + /** + * `new Markdown()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Markdown::with(urls: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Markdown)->withURLs(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param list $urls + * @param Options|OptionsShape|null $options + */ + public static function with( + array $urls, + Options|array|null $options = null + ): self { + $self = new self; + + $self['urls'] = $urls; + + null !== $options && $self['options'] = $options; + + return $self; + } + + /** + * Return page content as Markdown. + * + * @param 'markdown' $format + */ + public function withFormat(string $format): self + { + $self = clone $this; + $self['format'] = $format; + + return $self; + } + + /** + * Pages to scrape. Maximum 25000. + * + * @param list $urls + */ + public function withURLs(array $urls): self + { + $self = clone $this; + $self['urls'] = $urls; + + return $self; + } + + /** + * Options for Markdown output. + * + * @param Options|OptionsShape $options + */ + public function withOptions(Options|array $options): self + { + $self = clone $this; + $self['options'] = $options; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options.php new file mode 100644 index 0000000..b734ecf --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options.php @@ -0,0 +1,282 @@ +, + * excludeSelectors?: list|null, + * includeImages?: bool|null, + * includeLinks?: bool|null, + * includeSelectors?: list|null, + * maxAgeMs?: int|null, + * pdf?: null|Pdf|PdfShape, + * settleAnimations?: bool|null, + * shortenBase64Images?: bool|null, + * useMainContentOnly?: bool|null, + * waitForMs?: int|null, + * } + */ +final class Options implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @var list|null $excludeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $excludeSelectors; + + /** + * Include image references in the Markdown. + */ + #[Optional] + public ?bool $includeImages; + + /** + * Include links in the Markdown. + */ + #[Optional] + public ?bool $includeLinks; + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @var list|null $includeSelectors + */ + #[Optional(list: 'string', nullable: true)] + public ?array $includeSelectors; + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + #[Optional(nullable: true)] + public ?int $maxAgeMs; + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + */ + #[Optional] + public ?Pdf $pdf; + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + #[Optional] + public ?bool $settleAnimations; + + /** + * Shorten inline base64 image data. + */ + #[Optional] + public ?bool $shortenBase64Images; + + /** + * Return the main content without navigation or footers. + */ + #[Optional] + public ?bool $useMainContentOnly; + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + #[Optional] + public ?int $waitForMs; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Country|value-of|null $country + * @param list|null $excludeSelectors + * @param list|null $includeSelectors + * @param Pdf|PdfShape|null $pdf + */ + public static function with( + Country|string|null $country = null, + ?array $excludeSelectors = null, + ?bool $includeImages = null, + ?bool $includeLinks = null, + ?array $includeSelectors = null, + ?int $maxAgeMs = null, + Pdf|array|null $pdf = null, + ?bool $settleAnimations = null, + ?bool $shortenBase64Images = null, + ?bool $useMainContentOnly = null, + ?int $waitForMs = null, + ): self { + $self = new self; + + null !== $country && $self['country'] = $country; + null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; + null !== $includeImages && $self['includeImages'] = $includeImages; + null !== $includeLinks && $self['includeLinks'] = $includeLinks; + null !== $includeSelectors && $self['includeSelectors'] = $includeSelectors; + null !== $maxAgeMs && $self['maxAgeMs'] = $maxAgeMs; + null !== $pdf && $self['pdf'] = $pdf; + null !== $settleAnimations && $self['settleAnimations'] = $settleAnimations; + null !== $shortenBase64Images && $self['shortenBase64Images'] = $shortenBase64Images; + null !== $useMainContentOnly && $self['useMainContentOnly'] = $useMainContentOnly; + null !== $waitForMs && $self['waitForMs'] = $waitForMs; + + return $self; + } + + /** + * Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2). + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + + /** + * Remove elements matching these CSS selectors. Applied after `includeSelectors`, so an element matching both is removed. + * + * @param list|null $excludeSelectors + */ + public function withExcludeSelectors(?array $excludeSelectors): self + { + $self = clone $this; + $self['excludeSelectors'] = $excludeSelectors; + + return $self; + } + + /** + * Include image references in the Markdown. + */ + public function withIncludeImages(bool $includeImages): self + { + $self = clone $this; + $self['includeImages'] = $includeImages; + + return $self; + } + + /** + * Include links in the Markdown. + */ + public function withIncludeLinks(bool $includeLinks): self + { + $self = clone $this; + $self['includeLinks'] = $includeLinks; + + return $self; + } + + /** + * Keep only the subtrees matching these CSS selectors. Filtered pages are always fetched fresh, ignoring `maxAgeMs`. + * + * @param list|null $includeSelectors + */ + public function withIncludeSelectors(?array $includeSelectors): self + { + $self = clone $this; + $self['includeSelectors'] = $includeSelectors; + + return $self; + } + + /** + * Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + */ + public function withMaxAgeMs(?int $maxAgeMs): self + { + $self = clone $this; + $self['maxAgeMs'] = $maxAgeMs; + + return $self; + } + + /** + * PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range. + * + * @param Pdf|PdfShape $pdf + */ + public function withPdf(Pdf|array $pdf): self + { + $self = clone $this; + $self['pdf'] = $pdf; + + return $self; + } + + /** + * Wait briefly for CSS and transition animations to settle before extraction, on pages that render in a browser. + */ + public function withSettleAnimations(bool $settleAnimations): self + { + $self = clone $this; + $self['settleAnimations'] = $settleAnimations; + + return $self; + } + + /** + * Shorten inline base64 image data. + */ + public function withShortenBase64Images(bool $shortenBase64Images): self + { + $self = clone $this; + $self['shortenBase64Images'] = $shortenBase64Images; + + return $self; + } + + /** + * Return the main content without navigation or footers. + */ + public function withUseMainContentOnly(bool $useMainContentOnly): self + { + $self = clone $this; + $self['useMainContentOnly'] = $useMainContentOnly; + + return $self; + } + + /** + * How long to wait after initial page load, in milliseconds. `0` waits 500 ms. + */ + public function withWaitForMs(int $waitForMs): self + { + $self = clone $this; + $self['waitForMs'] = $waitForMs; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Country.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Country.php new file mode 100644 index 0000000..9afbe12 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Country.php @@ -0,0 +1,419 @@ + */ + use SdkModel; + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + #[Optional] + public ?int $end; + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @var OcrVariants|null $ocr + */ + #[Optional(union: Ocr::class)] + public bool|string|null $ocr; + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @var ShouldParseVariants|null $shouldParse + */ + #[Optional(union: ShouldParse::class)] + public bool|string|null $shouldParse; + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + #[Optional] + public ?int $start; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param OcrShape|null $ocr + * @param ShouldParseShape|null $shouldParse + */ + public static function with( + ?int $end = null, + bool|UnionMember1|string|null $ocr = null, + bool|ShouldParse\UnionMember1|string|null $shouldParse = null, + ?int $start = null, + ): self { + $self = new self; + + null !== $end && $self['end'] = $end; + null !== $ocr && $self['ocr'] = $ocr; + null !== $shouldParse && $self['shouldParse'] = $shouldParse; + null !== $start && $self['start'] = $start; + + return $self; + } + + /** + * Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided. + */ + public function withEnd(int $end): self + { + $self = clone $this; + $self['end'] = $end; + + return $self; + } + + /** + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. + * + * @param OcrShape $ocr + */ + public function withOcr(bool|UnionMember1|string $ocr): self + { + $self = clone $this; + $self['ocr'] = $ocr; + + return $self; + } + + /** + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. + * + * @param ShouldParseShape $shouldParse + */ + public function withShouldParse( + bool|ShouldParse\UnionMember1|string $shouldParse, + ): self { + $self = clone $this; + $self['shouldParse'] = $shouldParse; + + return $self; + } + + /** + * First 1-based PDF page to parse. When omitted, parsing starts at the first page. + */ + public function withStart(int $start): self + { + $self = clone $this; + $self['start'] = $start; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/Ocr.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/Ocr.php new file mode 100644 index 0000000..ace72dc --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/Ocr.php @@ -0,0 +1,29 @@ + + * @phpstan-type OcrShape = OcrVariants + */ +final class Ocr implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/Ocr/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/Ocr/UnionMember1.php new file mode 100644 index 0000000..b1c5bb8 --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/Ocr/UnionMember1.php @@ -0,0 +1,12 @@ + + * @phpstan-type ShouldParseShape = ShouldParseVariants + */ +final class ShouldParse implements ConverterSource +{ + use SdkUnion; + + /** + * @return list|array + */ + public static function variants(): array + { + return ['bool', UnionMember1::class]; + } +} diff --git a/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/ShouldParse/UnionMember1.php b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/ShouldParse/UnionMember1.php new file mode 100644 index 0000000..d212a3f --- /dev/null +++ b/src/Batch/BatchSubmitParams/Input/Scrape/Data/Markdown/Options/Pdf/ShouldParse/UnionMember1.php @@ -0,0 +1,12 @@ +|null + * } + */ +final class URL implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Page URL to scrape. + */ + #[Required] + public string $url; + + /** + * Your ID for this page, returned with its result. The same URL can use different IDs. + */ + #[Optional('itemId')] + public ?string $itemID; + + /** + * Custom JSON returned unchanged with this page result. + * + * @var array|null $meta + */ + #[Optional(map: 'mixed')] + public ?array $meta; + + /** + * `new URL()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * URL::with(url: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new URL)->withURL(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param array|null $meta + */ + public static function with( + string $url, + ?string $itemID = null, + ?array $meta = null + ): self { + $self = new self; + + $self['url'] = $url; + + null !== $itemID && $self['itemID'] = $itemID; + null !== $meta && $self['meta'] = $meta; + + return $self; + } + + /** + * Page URL to scrape. + */ + public function withURL(string $url): self + { + $self = clone $this; + $self['url'] = $url; + + return $self; + } + + /** + * Your ID for this page, returned with its result. The same URL can use different IDs. + */ + public function withItemID(string $itemID): self + { + $self = clone $this; + $self['itemID'] = $itemID; + + return $self; + } + + /** + * Custom JSON returned unchanged with this page result. + * + * @param array $meta + */ + public function withMeta(array $meta): self + { + $self = clone $this; + $self['meta'] = $meta; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitResponse.php b/src/Batch/BatchSubmitResponse.php index dd7d5a6..0082a4a 100644 --- a/src/Batch/BatchSubmitResponse.php +++ b/src/Batch/BatchSubmitResponse.php @@ -4,10 +4,11 @@ namespace ContextDev\Batch; -use ContextDev\Batch\BatchSubmitResponse\Code; +use ContextDev\Batch\BatchSubmitResponse\Credits; +use ContextDev\Batch\BatchSubmitResponse\Format; +use ContextDev\Batch\BatchSubmitResponse\InvalidURL; use ContextDev\Batch\BatchSubmitResponse\KeyMetadata; -use ContextDev\Batch\BatchSubmitResponse\Metadata; -use ContextDev\Batch\BatchSubmitResponse\Person; +use ContextDev\Batch\BatchSubmitResponse\Mode; use ContextDev\Batch\BatchSubmitResponse\Status; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; @@ -15,16 +16,25 @@ use ContextDev\Core\Contracts\BaseModel; /** - * @phpstan-import-type MetadataShape from \ContextDev\Batch\BatchSubmitResponse\Metadata - * @phpstan-import-type PersonShape from \ContextDev\Batch\BatchSubmitResponse\Person + * @phpstan-import-type CrawlControlsShape from \ContextDev\Batch\CrawlControls + * @phpstan-import-type CreditsShape from \ContextDev\Batch\BatchSubmitResponse\Credits + * @phpstan-import-type IntakeShape from \ContextDev\Batch\Intake + * @phpstan-import-type InvalidURLShape from \ContextDev\Batch\BatchSubmitResponse\InvalidURL * @phpstan-import-type KeyMetadataShape from \ContextDev\Batch\BatchSubmitResponse\KeyMetadata * * @phpstan-type BatchSubmitResponseShape = array{ - * code: Code|value-of, - * metadata: Metadata|MetadataShape, - * person: Person|PersonShape, + * id: string, + * crawl: null|CrawlControls|CrawlControlsShape, + * createdAt: string, + * credits: Credits|CreditsShape, + * format: Format|value-of, + * input: Intake|IntakeShape, + * invalidURLs: list, + * mode: Mode|value-of, * status: Status|value-of, + * tags: list, * keyMetadata?: null|KeyMetadata|KeyMetadataShape, + * webhookSecret?: string|null, * } */ final class BatchSubmitResponse implements BaseModel @@ -33,27 +43,61 @@ final class BatchSubmitResponse implements BaseModel use SdkModel; /** - * HTTP status code. - * - * @var value-of $code + * Batch ID. Poll GET /batch/{batch_id} with it. */ - #[Required(enum: Code::class)] - public int $code; + #[Required] + public string $id; /** - * Additional response details. + * The crawl controls as submitted, so the limits requested can be compared against what the crawl reached. */ #[Required] - public Metadata $metadata; + public ?CrawlControls $crawl; + + /** + * When the batch was created. + */ + #[Required('created_at')] + public string $createdAt; + + /** + * What accepting this batch cost. + */ + #[Required] + public Credits $credits; + + /** + * What each page will be returned as. + * + * @var value-of $format + */ + #[Required(enum: Format::class)] + public string $format; /** - * Retrieved person profile. + * What submission took in, and what it charged for. */ #[Required] - public Person $person; + public Intake $input; + + /** + * Rejected URLs, up to 100. These are not charged. + * + * @var list $invalidURLs + */ + #[Required('invalid_urls', list: InvalidURL::class)] + public array $invalidURLs; /** - * Response status. + * How pages will be selected. + * + * @var value-of $mode + */ + #[Required(enum: Mode::class)] + public string $mode; + + /** + * Always `queued`. An accepted batch has not started yet. * * @var value-of $status */ @@ -61,27 +105,58 @@ final class BatchSubmitResponse implements BaseModel public string $status; /** - * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + * Tags stored on the batch. + * + * @var list $tags + */ + #[Required(list: 'string')] + public array $tags; + + /** + * API key usage for this request. */ #[Optional('key_metadata')] public ?KeyMetadata $keyMetadata; + /** + * Signing secret for the completion webhook, returned only here and never again. Store it now; it is not repeated by GET /batch/{batch_id}. + */ + #[Optional('webhook_secret')] + public ?string $webhookSecret; + /** * `new BatchSubmitResponse()` is missing required properties by the API. * * To enforce required parameters use * ``` - * BatchSubmitResponse::with(code: ..., metadata: ..., person: ..., status: ...) + * BatchSubmitResponse::with( + * id: ..., + * crawl: ..., + * createdAt: ..., + * credits: ..., + * format: ..., + * input: ..., + * invalidURLs: ..., + * mode: ..., + * status: ..., + * tags: ..., + * ) * ``` * * Otherwise ensure the following setters are called * * ``` * (new BatchSubmitResponse) - * ->withCode(...) - * ->withMetadata(...) - * ->withPerson(...) + * ->withID(...) + * ->withCrawl(...) + * ->withCreatedAt(...) + * ->withCredits(...) + * ->withFormat(...) + * ->withInput(...) + * ->withInvalidURLs(...) + * ->withMode(...) * ->withStatus(...) + * ->withTags(...) * ``` */ public function __construct() @@ -94,72 +169,151 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * - * @param Code|value-of $code - * @param Metadata|MetadataShape $metadata - * @param Person|PersonShape $person + * @param CrawlControls|CrawlControlsShape|null $crawl + * @param Credits|CreditsShape $credits + * @param Format|value-of $format + * @param Intake|IntakeShape $input + * @param list $invalidURLs + * @param Mode|value-of $mode * @param Status|value-of $status + * @param list $tags * @param KeyMetadata|KeyMetadataShape|null $keyMetadata */ public static function with( - Code|int $code, - Metadata|array $metadata, - Person|array $person, + string $id, + CrawlControls|array|null $crawl, + string $createdAt, + Credits|array $credits, + Format|string $format, + Intake|array $input, + array $invalidURLs, + Mode|string $mode, Status|string $status, + array $tags, KeyMetadata|array|null $keyMetadata = null, + ?string $webhookSecret = null, ): self { $self = new self; - $self['code'] = $code; - $self['metadata'] = $metadata; - $self['person'] = $person; + $self['id'] = $id; + $self['crawl'] = $crawl; + $self['createdAt'] = $createdAt; + $self['credits'] = $credits; + $self['format'] = $format; + $self['input'] = $input; + $self['invalidURLs'] = $invalidURLs; + $self['mode'] = $mode; $self['status'] = $status; + $self['tags'] = $tags; null !== $keyMetadata && $self['keyMetadata'] = $keyMetadata; + null !== $webhookSecret && $self['webhookSecret'] = $webhookSecret; + + return $self; + } + + /** + * Batch ID. Poll GET /batch/{batch_id} with it. + */ + public function withID(string $id): self + { + $self = clone $this; + $self['id'] = $id; + + return $self; + } + + /** + * The crawl controls as submitted, so the limits requested can be compared against what the crawl reached. + * + * @param CrawlControls|CrawlControlsShape|null $crawl + */ + public function withCrawl(CrawlControls|array|null $crawl): self + { + $self = clone $this; + $self['crawl'] = $crawl; + + return $self; + } + + /** + * When the batch was created. + */ + public function withCreatedAt(string $createdAt): self + { + $self = clone $this; + $self['createdAt'] = $createdAt; + + return $self; + } + + /** + * What accepting this batch cost. + * + * @param Credits|CreditsShape $credits + */ + public function withCredits(Credits|array $credits): self + { + $self = clone $this; + $self['credits'] = $credits; + + return $self; + } + + /** + * What each page will be returned as. + * + * @param Format|value-of $format + */ + public function withFormat(Format|string $format): self + { + $self = clone $this; + $self['format'] = $format; return $self; } /** - * HTTP status code. + * What submission took in, and what it charged for. * - * @param Code|value-of $code + * @param Intake|IntakeShape $input */ - public function withCode(Code|int $code): self + public function withInput(Intake|array $input): self { $self = clone $this; - $self['code'] = $code; + $self['input'] = $input; return $self; } /** - * Additional response details. + * Rejected URLs, up to 100. These are not charged. * - * @param Metadata|MetadataShape $metadata + * @param list $invalidURLs */ - public function withMetadata(Metadata|array $metadata): self + public function withInvalidURLs(array $invalidURLs): self { $self = clone $this; - $self['metadata'] = $metadata; + $self['invalidURLs'] = $invalidURLs; return $self; } /** - * Retrieved person profile. + * How pages will be selected. * - * @param Person|PersonShape $person + * @param Mode|value-of $mode */ - public function withPerson(Person|array $person): self + public function withMode(Mode|string $mode): self { $self = clone $this; - $self['person'] = $person; + $self['mode'] = $mode; return $self; } /** - * Response status. + * Always `queued`. An accepted batch has not started yet. * * @param Status|value-of $status */ @@ -172,7 +326,20 @@ public function withStatus(Status|string $status): self } /** - * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + * Tags stored on the batch. + * + * @param list $tags + */ + public function withTags(array $tags): self + { + $self = clone $this; + $self['tags'] = $tags; + + return $self; + } + + /** + * API key usage for this request. * * @param KeyMetadata|KeyMetadataShape $keyMetadata */ @@ -183,4 +350,15 @@ public function withKeyMetadata(KeyMetadata|array $keyMetadata): self return $self; } + + /** + * Signing secret for the completion webhook, returned only here and never again. Store it now; it is not repeated by GET /batch/{batch_id}. + */ + public function withWebhookSecret(string $webhookSecret): self + { + $self = clone $this; + $self['webhookSecret'] = $webhookSecret; + + return $self; + } } diff --git a/src/Batch/BatchSubmitResponse/Code.php b/src/Batch/BatchSubmitResponse/Code.php deleted file mode 100644 index 5fa2c30..0000000 --- a/src/Batch/BatchSubmitResponse/Code.php +++ /dev/null @@ -1,13 +0,0 @@ - */ + use SdkModel; + + /** + * Credits just debited from your balance. Whatever the batch does not spend is refunded when it settles. + */ + #[Required] + public int $reserved; + + /** + * `new Credits()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Credits::with(reserved: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Credits)->withReserved(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(int $reserved): self + { + $self = new self; + + $self['reserved'] = $reserved; + + return $self; + } + + /** + * Credits just debited from your balance. Whatever the batch does not spend is refunded when it settles. + */ + public function withReserved(int $reserved): self + { + $self = clone $this; + $self['reserved'] = $reserved; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitResponse/Format.php b/src/Batch/BatchSubmitResponse/Format.php new file mode 100644 index 0000000..863387f --- /dev/null +++ b/src/Batch/BatchSubmitResponse/Format.php @@ -0,0 +1,15 @@ + */ + use SdkModel; + + /** + * Why it was rejected. + */ + #[Required] + public string $reason; + + /** + * Rejected URL. + */ + #[Required] + public string $url; + + /** + * `new InvalidURL()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * InvalidURL::with(reason: ..., url: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new InvalidURL)->withReason(...)->withURL(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(string $reason, string $url): self + { + $self = new self; + + $self['reason'] = $reason; + $self['url'] = $url; + + return $self; + } + + /** + * Why it was rejected. + */ + public function withReason(string $reason): self + { + $self = clone $this; + $self['reason'] = $reason; + + return $self; + } + + /** + * Rejected URL. + */ + public function withURL(string $url): self + { + $self = clone $this; + $self['url'] = $url; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitResponse/KeyMetadata.php b/src/Batch/BatchSubmitResponse/KeyMetadata.php index 1647397..d02f348 100644 --- a/src/Batch/BatchSubmitResponse/KeyMetadata.php +++ b/src/Batch/BatchSubmitResponse/KeyMetadata.php @@ -9,7 +9,7 @@ use ContextDev\Core\Contracts\BaseModel; /** - * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + * API key usage for this request. * * @phpstan-type KeyMetadataShape = array{ * creditsConsumed: int, creditsRemaining: int diff --git a/src/Batch/BatchSubmitResponse/Metadata.php b/src/Batch/BatchSubmitResponse/Metadata.php deleted file mode 100644 index b0fcfa2..0000000 --- a/src/Batch/BatchSubmitResponse/Metadata.php +++ /dev/null @@ -1,188 +0,0 @@ ->, - * sourcesSucceeded: list>, - * urlsAnalyzed: list, - * personalWebsiteURL?: string|null, - * } - */ -final class Metadata implements BaseModel -{ - /** @use SdkModel */ - use SdkModel; - - /** - * Identifiers returned for the person. - */ - #[Required] - public Identifiers $identifiers; - - /** - * Source categories checked. - * - * @var list> $sourcesAttempted - */ - #[Required(list: SourcesAttempted::class)] - public array $sourcesAttempted; - - /** - * Source categories with data. - * - * @var list> $sourcesSucceeded - */ - #[Required(list: SourcesSucceeded::class)] - public array $sourcesSucceeded; - - /** - * URLs reviewed for this profile. - * - * @var list $urlsAnalyzed - */ - #[Required(list: 'string')] - public array $urlsAnalyzed; - - /** - * Personal website URL, when found. - */ - #[Optional('personalWebsiteUrl')] - public ?string $personalWebsiteURL; - - /** - * `new Metadata()` is missing required properties by the API. - * - * To enforce required parameters use - * ``` - * Metadata::with( - * identifiers: ..., - * sourcesAttempted: ..., - * sourcesSucceeded: ..., - * urlsAnalyzed: ..., - * ) - * ``` - * - * Otherwise ensure the following setters are called - * - * ``` - * (new Metadata) - * ->withIdentifiers(...) - * ->withSourcesAttempted(...) - * ->withSourcesSucceeded(...) - * ->withURLsAnalyzed(...) - * ``` - */ - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - * - * @param Identifiers|IdentifiersShape $identifiers - * @param list> $sourcesAttempted - * @param list> $sourcesSucceeded - * @param list $urlsAnalyzed - */ - public static function with( - Identifiers|array $identifiers, - array $sourcesAttempted, - array $sourcesSucceeded, - array $urlsAnalyzed, - ?string $personalWebsiteURL = null, - ): self { - $self = new self; - - $self['identifiers'] = $identifiers; - $self['sourcesAttempted'] = $sourcesAttempted; - $self['sourcesSucceeded'] = $sourcesSucceeded; - $self['urlsAnalyzed'] = $urlsAnalyzed; - - null !== $personalWebsiteURL && $self['personalWebsiteURL'] = $personalWebsiteURL; - - return $self; - } - - /** - * Identifiers returned for the person. - * - * @param Identifiers|IdentifiersShape $identifiers - */ - public function withIdentifiers(Identifiers|array $identifiers): self - { - $self = clone $this; - $self['identifiers'] = $identifiers; - - return $self; - } - - /** - * Source categories checked. - * - * @param list> $sourcesAttempted - */ - public function withSourcesAttempted(array $sourcesAttempted): self - { - $self = clone $this; - $self['sourcesAttempted'] = $sourcesAttempted; - - return $self; - } - - /** - * Source categories with data. - * - * @param list> $sourcesSucceeded - */ - public function withSourcesSucceeded(array $sourcesSucceeded): self - { - $self = clone $this; - $self['sourcesSucceeded'] = $sourcesSucceeded; - - return $self; - } - - /** - * URLs reviewed for this profile. - * - * @param list $urlsAnalyzed - */ - public function withURLsAnalyzed(array $urlsAnalyzed): self - { - $self = clone $this; - $self['urlsAnalyzed'] = $urlsAnalyzed; - - return $self; - } - - /** - * Personal website URL, when found. - */ - public function withPersonalWebsiteURL(string $personalWebsiteURL): self - { - $self = clone $this; - $self['personalWebsiteURL'] = $personalWebsiteURL; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Metadata/Identifiers.php b/src/Batch/BatchSubmitResponse/Metadata/Identifiers.php deleted file mode 100644 index 21ffd4d..0000000 --- a/src/Batch/BatchSubmitResponse/Metadata/Identifiers.php +++ /dev/null @@ -1,56 +0,0 @@ - */ - use SdkModel; - - /** - * LinkedIn profile URL. - */ - #[Optional('linkedinUrl')] - public ?string $linkedinURL; - - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - */ - public static function with(?string $linkedinURL = null): self - { - $self = new self; - - null !== $linkedinURL && $self['linkedinURL'] = $linkedinURL; - - return $self; - } - - /** - * LinkedIn profile URL. - */ - public function withLinkedinURL(string $linkedinURL): self - { - $self = clone $this; - $self['linkedinURL'] = $linkedinURL; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Metadata/SourcesAttempted.php b/src/Batch/BatchSubmitResponse/Metadata/SourcesAttempted.php deleted file mode 100644 index 9b09592..0000000 --- a/src/Batch/BatchSubmitResponse/Metadata/SourcesAttempted.php +++ /dev/null @@ -1,18 +0,0 @@ -, - * experience: list, - * profile: Profile|ProfileShape, - * skills: list, - * } - */ -final class Person implements BaseModel -{ - /** @use SdkModel */ - use SdkModel; - - /** - * Education history. - * - * @var list $education - */ - #[Required(list: Education::class)] - public array $education; - - /** - * Work history. - * - * @var list $experience - */ - #[Required(list: Experience::class)] - public array $experience; - - /** - * Core profile details. - */ - #[Required] - public Profile $profile; - - /** - * Listed skills. - * - * @var list $skills - */ - #[Required(list: Skill::class)] - public array $skills; - - /** - * `new Person()` is missing required properties by the API. - * - * To enforce required parameters use - * ``` - * Person::with(education: ..., experience: ..., profile: ..., skills: ...) - * ``` - * - * Otherwise ensure the following setters are called - * - * ``` - * (new Person) - * ->withEducation(...) - * ->withExperience(...) - * ->withProfile(...) - * ->withSkills(...) - * ``` - */ - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - * - * @param list $education - * @param list $experience - * @param Profile|ProfileShape $profile - * @param list $skills - */ - public static function with( - array $education, - array $experience, - Profile|array $profile, - array $skills - ): self { - $self = new self; - - $self['education'] = $education; - $self['experience'] = $experience; - $self['profile'] = $profile; - $self['skills'] = $skills; - - return $self; - } - - /** - * Education history. - * - * @param list $education - */ - public function withEducation(array $education): self - { - $self = clone $this; - $self['education'] = $education; - - return $self; - } - - /** - * Work history. - * - * @param list $experience - */ - public function withExperience(array $experience): self - { - $self = clone $this; - $self['experience'] = $experience; - - return $self; - } - - /** - * Core profile details. - * - * @param Profile|ProfileShape $profile - */ - public function withProfile(Profile|array $profile): self - { - $self = clone $this; - $self['profile'] = $profile; - - return $self; - } - - /** - * Listed skills. - * - * @param list $skills - */ - public function withSkills(array $skills): self - { - $self = clone $this; - $self['skills'] = $skills; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Person/Education/Dates.php b/src/Batch/BatchSubmitResponse/Person/Education/Dates.php deleted file mode 100644 index 64de539..0000000 --- a/src/Batch/BatchSubmitResponse/Person/Education/Dates.php +++ /dev/null @@ -1,111 +0,0 @@ - */ - use SdkModel; - - /** - * End date, when known. - */ - #[Optional] - public ?EndDate $endDate; - - /** - * Whether the entry is current. - */ - #[Optional] - public ?bool $isCurrent; - - /** - * Start date, when known. - */ - #[Optional] - public ?StartDate $startDate; - - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - * - * @param EndDate|EndDateShape|null $endDate - * @param StartDate|StartDateShape|null $startDate - */ - public static function with( - EndDate|array|null $endDate = null, - ?bool $isCurrent = null, - StartDate|array|null $startDate = null, - ): self { - $self = new self; - - null !== $endDate && $self['endDate'] = $endDate; - null !== $isCurrent && $self['isCurrent'] = $isCurrent; - null !== $startDate && $self['startDate'] = $startDate; - - return $self; - } - - /** - * End date, when known. - * - * @param EndDate|EndDateShape $endDate - */ - public function withEndDate(EndDate|array $endDate): self - { - $self = clone $this; - $self['endDate'] = $endDate; - - return $self; - } - - /** - * Whether the entry is current. - */ - public function withIsCurrent(bool $isCurrent): self - { - $self = clone $this; - $self['isCurrent'] = $isCurrent; - - return $self; - } - - /** - * Start date, when known. - * - * @param StartDate|StartDateShape $startDate - */ - public function withStartDate(StartDate|array $startDate): self - { - $self = clone $this; - $self['startDate'] = $startDate; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Person/Experience.php b/src/Batch/BatchSubmitResponse/Person/Experience.php deleted file mode 100644 index b1a0e49..0000000 --- a/src/Batch/BatchSubmitResponse/Person/Experience.php +++ /dev/null @@ -1,145 +0,0 @@ - */ - use SdkModel; - - /** - * Company or organization name. - */ - #[Required] - public Company $company; - - /** - * Role or job title. - */ - #[Required] - public string $title; - - /** - * Role dates. - */ - #[Optional] - public ?Dates $dates; - - /** - * Role description. - */ - #[Optional] - public ?string $description; - - /** - * `new Experience()` is missing required properties by the API. - * - * To enforce required parameters use - * ``` - * Experience::with(company: ..., title: ...) - * ``` - * - * Otherwise ensure the following setters are called - * - * ``` - * (new Experience)->withCompany(...)->withTitle(...) - * ``` - */ - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - * - * @param Company|CompanyShape $company - * @param Dates|DatesShape|null $dates - */ - public static function with( - Company|array $company, - string $title, - Dates|array|null $dates = null, - ?string $description = null, - ): self { - $self = new self; - - $self['company'] = $company; - $self['title'] = $title; - - null !== $dates && $self['dates'] = $dates; - null !== $description && $self['description'] = $description; - - return $self; - } - - /** - * Company or organization name. - * - * @param Company|CompanyShape $company - */ - public function withCompany(Company|array $company): self - { - $self = clone $this; - $self['company'] = $company; - - return $self; - } - - /** - * Role or job title. - */ - public function withTitle(string $title): self - { - $self = clone $this; - $self['title'] = $title; - - return $self; - } - - /** - * Role dates. - * - * @param Dates|DatesShape $dates - */ - public function withDates(Dates|array $dates): self - { - $self = clone $this; - $self['dates'] = $dates; - - return $self; - } - - /** - * Role description. - */ - public function withDescription(string $description): self - { - $self = clone $this; - $self['description'] = $description; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Person/Experience/Company.php b/src/Batch/BatchSubmitResponse/Person/Experience/Company.php deleted file mode 100644 index 400e046..0000000 --- a/src/Batch/BatchSubmitResponse/Person/Experience/Company.php +++ /dev/null @@ -1,92 +0,0 @@ - */ - use SdkModel; - - /** - * Display name. - */ - #[Required] - public string $display; - - /** - * Standardized name, when available. - */ - #[Optional] - public ?string $normalized; - - /** - * `new Company()` is missing required properties by the API. - * - * To enforce required parameters use - * ``` - * Company::with(display: ...) - * ``` - * - * Otherwise ensure the following setters are called - * - * ``` - * (new Company)->withDisplay(...) - * ``` - */ - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - */ - public static function with( - string $display, - ?string $normalized = null - ): self { - $self = new self; - - $self['display'] = $display; - - null !== $normalized && $self['normalized'] = $normalized; - - return $self; - } - - /** - * Display name. - */ - public function withDisplay(string $display): self - { - $self = clone $this; - $self['display'] = $display; - - return $self; - } - - /** - * Standardized name, when available. - */ - public function withNormalized(string $normalized): self - { - $self = clone $this; - $self['normalized'] = $normalized; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Person/Experience/Dates.php b/src/Batch/BatchSubmitResponse/Person/Experience/Dates.php deleted file mode 100644 index 3480d50..0000000 --- a/src/Batch/BatchSubmitResponse/Person/Experience/Dates.php +++ /dev/null @@ -1,111 +0,0 @@ - */ - use SdkModel; - - /** - * End date, when known. - */ - #[Optional] - public ?EndDate $endDate; - - /** - * Whether the entry is current. - */ - #[Optional] - public ?bool $isCurrent; - - /** - * Start date, when known. - */ - #[Optional] - public ?StartDate $startDate; - - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - * - * @param EndDate|EndDateShape|null $endDate - * @param StartDate|StartDateShape|null $startDate - */ - public static function with( - EndDate|array|null $endDate = null, - ?bool $isCurrent = null, - StartDate|array|null $startDate = null, - ): self { - $self = new self; - - null !== $endDate && $self['endDate'] = $endDate; - null !== $isCurrent && $self['isCurrent'] = $isCurrent; - null !== $startDate && $self['startDate'] = $startDate; - - return $self; - } - - /** - * End date, when known. - * - * @param EndDate|EndDateShape $endDate - */ - public function withEndDate(EndDate|array $endDate): self - { - $self = clone $this; - $self['endDate'] = $endDate; - - return $self; - } - - /** - * Whether the entry is current. - */ - public function withIsCurrent(bool $isCurrent): self - { - $self = clone $this; - $self['isCurrent'] = $isCurrent; - - return $self; - } - - /** - * Start date, when known. - * - * @param StartDate|StartDateShape $startDate - */ - public function withStartDate(StartDate|array $startDate): self - { - $self = clone $this; - $self['startDate'] = $startDate; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Person/Profile.php b/src/Batch/BatchSubmitResponse/Person/Profile.php deleted file mode 100644 index fb6274e..0000000 --- a/src/Batch/BatchSubmitResponse/Person/Profile.php +++ /dev/null @@ -1,139 +0,0 @@ - */ - use SdkModel; - - /** - * Person's full name. - */ - #[Optional] - public ?string $fullName; - - /** - * Short professional headline. - */ - #[Optional] - public ?string $headline; - - /** - * Person's listed location. - */ - #[Optional] - public ?string $location; - - /** - * Profile image URL. - */ - #[Optional('profilePictureUrl')] - public ?string $profilePictureURL; - - /** - * Brief profile summary. - */ - #[Optional] - public ?string $summary; - - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - */ - public static function with( - ?string $fullName = null, - ?string $headline = null, - ?string $location = null, - ?string $profilePictureURL = null, - ?string $summary = null, - ): self { - $self = new self; - - null !== $fullName && $self['fullName'] = $fullName; - null !== $headline && $self['headline'] = $headline; - null !== $location && $self['location'] = $location; - null !== $profilePictureURL && $self['profilePictureURL'] = $profilePictureURL; - null !== $summary && $self['summary'] = $summary; - - return $self; - } - - /** - * Person's full name. - */ - public function withFullName(string $fullName): self - { - $self = clone $this; - $self['fullName'] = $fullName; - - return $self; - } - - /** - * Short professional headline. - */ - public function withHeadline(string $headline): self - { - $self = clone $this; - $self['headline'] = $headline; - - return $self; - } - - /** - * Person's listed location. - */ - public function withLocation(string $location): self - { - $self = clone $this; - $self['location'] = $location; - - return $self; - } - - /** - * Profile image URL. - */ - public function withProfilePictureURL(string $profilePictureURL): self - { - $self = clone $this; - $self['profilePictureURL'] = $profilePictureURL; - - return $self; - } - - /** - * Brief profile summary. - */ - public function withSummary(string $summary): self - { - $self = clone $this; - $self['summary'] = $summary; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Person/Skill.php b/src/Batch/BatchSubmitResponse/Person/Skill.php deleted file mode 100644 index b5e9c82..0000000 --- a/src/Batch/BatchSubmitResponse/Person/Skill.php +++ /dev/null @@ -1,111 +0,0 @@ - */ - use SdkModel; - - /** - * Skill name. - */ - #[Required] - public string $name; - - /** - * Standardized skill name, when available. - */ - #[Optional] - public ?string $normalized; - - /** - * Skill proficiency, when available. - */ - #[Optional] - public ?string $proficiency; - - /** - * `new Skill()` is missing required properties by the API. - * - * To enforce required parameters use - * ``` - * Skill::with(name: ...) - * ``` - * - * Otherwise ensure the following setters are called - * - * ``` - * (new Skill)->withName(...) - * ``` - */ - public function __construct() - { - $this->initialize(); - } - - /** - * Construct an instance from the required parameters. - * - * You must use named parameters to construct any parameters with a default value. - */ - public static function with( - string $name, - ?string $normalized = null, - ?string $proficiency = null - ): self { - $self = new self; - - $self['name'] = $name; - - null !== $normalized && $self['normalized'] = $normalized; - null !== $proficiency && $self['proficiency'] = $proficiency; - - return $self; - } - - /** - * Skill name. - */ - public function withName(string $name): self - { - $self = clone $this; - $self['name'] = $name; - - return $self; - } - - /** - * Standardized skill name, when available. - */ - public function withNormalized(string $normalized): self - { - $self = clone $this; - $self['normalized'] = $normalized; - - return $self; - } - - /** - * Skill proficiency, when available. - */ - public function withProficiency(string $proficiency): self - { - $self = clone $this; - $self['proficiency'] = $proficiency; - - return $self; - } -} diff --git a/src/Batch/BatchSubmitResponse/Status.php b/src/Batch/BatchSubmitResponse/Status.php index e71e05d..8247e87 100644 --- a/src/Batch/BatchSubmitResponse/Status.php +++ b/src/Batch/BatchSubmitResponse/Status.php @@ -5,9 +5,9 @@ namespace ContextDev\Batch\BatchSubmitResponse; /** - * Response status. + * Always `queued`. An accepted batch has not started yet. */ enum Status: string { - case OK = 'ok'; + case QUEUED = 'queued'; } diff --git a/src/Batch/CrawlControls.php b/src/Batch/CrawlControls.php index ba5e8c9..6852de2 100644 --- a/src/Batch/CrawlControls.php +++ b/src/Batch/CrawlControls.php @@ -4,8 +4,8 @@ namespace ContextDev\Batch; -use ContextDev\Batch\CrawlControls\Source\UnionMember0; -use ContextDev\Batch\CrawlControls\Source\UnionMember1; +use ContextDev\Batch\CrawlControls\Source\Sitemap; +use ContextDev\Batch\CrawlControls\Source\StartURL; use ContextDev\Core\Attributes\Required; use ContextDev\Core\Concerns\SdkModel; use ContextDev\Core\Contracts\BaseModel; @@ -53,7 +53,7 @@ final class CrawlControls implements BaseModel * @var SourceVariants $source */ #[Required] - public UnionMember0|UnionMember1 $source; + public StartURL|Sitemap $source; /** * RE2 pattern URLs had to match to be crawled. Null when the crawl set none. @@ -102,7 +102,7 @@ public static function with( bool $followSubdomains, ?int $maxDepth, int $maxPages, - UnionMember0|array|UnionMember1 $source, + StartURL|array|Sitemap $source, ?string $urlPattern, ): self { $self = new self; @@ -154,7 +154,7 @@ public function withMaxPages(int $maxPages): self * * @param SourceShape $source */ - public function withSource(UnionMember0|array|UnionMember1 $source): self + public function withSource(StartURL|array|Sitemap $source): self { $self = clone $this; $self['source'] = $source; diff --git a/src/Batch/CrawlControls/Source.php b/src/Batch/CrawlControls/Source.php index 83d9e9d..1ddf36f 100644 --- a/src/Batch/CrawlControls/Source.php +++ b/src/Batch/CrawlControls/Source.php @@ -4,8 +4,8 @@ namespace ContextDev\Batch\CrawlControls; -use ContextDev\Batch\CrawlControls\Source\UnionMember0; -use ContextDev\Batch\CrawlControls\Source\UnionMember1; +use ContextDev\Batch\CrawlControls\Source\Sitemap; +use ContextDev\Batch\CrawlControls\Source\StartURL; use ContextDev\Core\Concerns\SdkUnion; use ContextDev\Core\Conversion\Contracts\Converter; use ContextDev\Core\Conversion\Contracts\ConverterSource; @@ -13,11 +13,11 @@ /** * Where the crawl started. * - * @phpstan-import-type UnionMember0Shape from \ContextDev\Batch\CrawlControls\Source\UnionMember0 - * @phpstan-import-type UnionMember1Shape from \ContextDev\Batch\CrawlControls\Source\UnionMember1 + * @phpstan-import-type StartURLShape from \ContextDev\Batch\CrawlControls\Source\StartURL + * @phpstan-import-type SitemapShape from \ContextDev\Batch\CrawlControls\Source\Sitemap * - * @phpstan-type SourceVariants = UnionMember0|UnionMember1 - * @phpstan-type SourceShape = SourceVariants|UnionMember0Shape|UnionMember1Shape + * @phpstan-type SourceVariants = StartURL|Sitemap + * @phpstan-type SourceShape = SourceVariants|StartURLShape|SitemapShape */ final class Source implements ConverterSource { @@ -28,6 +28,6 @@ final class Source implements ConverterSource */ public static function variants(): array { - return [UnionMember0::class, UnionMember1::class]; + return [StartURL::class, Sitemap::class]; } } diff --git a/src/Batch/CrawlControls/Source/UnionMember1.php b/src/Batch/CrawlControls/Source/Sitemap.php similarity index 77% rename from src/Batch/CrawlControls/Source/UnionMember1.php rename to src/Batch/CrawlControls/Source/Sitemap.php index 7d10636..a1c30de 100644 --- a/src/Batch/CrawlControls/Source/UnionMember1.php +++ b/src/Batch/CrawlControls/Source/Sitemap.php @@ -4,19 +4,19 @@ namespace ContextDev\Batch\CrawlControls\Source; -use ContextDev\Batch\CrawlControls\Source\UnionMember1\Type; +use ContextDev\Batch\CrawlControls\Source\Sitemap\Type; use ContextDev\Core\Attributes\Required; use ContextDev\Core\Concerns\SdkModel; use ContextDev\Core\Contracts\BaseModel; /** - * @phpstan-type UnionMember1Shape = array{ - * domain: string, type: Type|value-of - * } + * The crawl scraped the pages listed in the domain's sitemap. + * + * @phpstan-type SitemapShape = array{domain: string, type: Type|value-of} */ -final class UnionMember1 implements BaseModel +final class Sitemap implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @@ -30,17 +30,17 @@ final class UnionMember1 implements BaseModel public string $type; /** - * `new UnionMember1()` is missing required properties by the API. + * `new Sitemap()` is missing required properties by the API. * * To enforce required parameters use * ``` - * UnionMember1::with(domain: ..., type: ...) + * Sitemap::with(domain: ..., type: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new UnionMember1)->withDomain(...)->withType(...) + * (new Sitemap)->withDomain(...)->withType(...) * ``` */ public function __construct() diff --git a/src/Batch/CrawlControls/Source/UnionMember1/Type.php b/src/Batch/CrawlControls/Source/Sitemap/Type.php similarity index 58% rename from src/Batch/CrawlControls/Source/UnionMember1/Type.php rename to src/Batch/CrawlControls/Source/Sitemap/Type.php index 5514933..edde8e6 100644 --- a/src/Batch/CrawlControls/Source/UnionMember1/Type.php +++ b/src/Batch/CrawlControls/Source/Sitemap/Type.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\CrawlControls\Source\UnionMember1; +namespace ContextDev\Batch\CrawlControls\Source\Sitemap; enum Type: string { diff --git a/src/Batch/CrawlControls/Source/UnionMember0.php b/src/Batch/CrawlControls/Source/StartURL.php similarity index 77% rename from src/Batch/CrawlControls/Source/UnionMember0.php rename to src/Batch/CrawlControls/Source/StartURL.php index 80e86a2..bd79a13 100644 --- a/src/Batch/CrawlControls/Source/UnionMember0.php +++ b/src/Batch/CrawlControls/Source/StartURL.php @@ -4,17 +4,19 @@ namespace ContextDev\Batch\CrawlControls\Source; -use ContextDev\Batch\CrawlControls\Source\UnionMember0\Type; +use ContextDev\Batch\CrawlControls\Source\StartURL\Type; use ContextDev\Core\Attributes\Required; use ContextDev\Core\Concerns\SdkModel; use ContextDev\Core\Contracts\BaseModel; /** - * @phpstan-type UnionMember0Shape = array{type: Type|value-of, url: string} + * The crawl discovered pages by following links from one URL. + * + * @phpstan-type StartURLShape = array{type: Type|value-of, url: string} */ -final class UnionMember0 implements BaseModel +final class StartURL implements BaseModel { - /** @use SdkModel */ + /** @use SdkModel */ use SdkModel; /** @var value-of $type */ @@ -28,17 +30,17 @@ final class UnionMember0 implements BaseModel public string $url; /** - * `new UnionMember0()` is missing required properties by the API. + * `new StartURL()` is missing required properties by the API. * * To enforce required parameters use * ``` - * UnionMember0::with(type: ..., url: ...) + * StartURL::with(type: ..., url: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new UnionMember0)->withType(...)->withURL(...) + * (new StartURL)->withType(...)->withURL(...) * ``` */ public function __construct() diff --git a/src/Batch/CrawlControls/Source/UnionMember0/Type.php b/src/Batch/CrawlControls/Source/StartURL/Type.php similarity index 59% rename from src/Batch/CrawlControls/Source/UnionMember0/Type.php rename to src/Batch/CrawlControls/Source/StartURL/Type.php index f8fa57a..ea4ecba 100644 --- a/src/Batch/CrawlControls/Source/UnionMember0/Type.php +++ b/src/Batch/CrawlControls/Source/StartURL/Type.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\CrawlControls\Source\UnionMember0; +namespace ContextDev\Batch\CrawlControls\Source\StartURL; enum Type: string { diff --git a/src/Brand/BrandGetResponse/Brand.php b/src/Brand/BrandGetResponse/Brand.php index 23527d6..a540ecf 100644 --- a/src/Brand/BrandGetResponse/Brand.php +++ b/src/Brand/BrandGetResponse/Brand.php @@ -7,6 +7,7 @@ use ContextDev\Brand\BrandGetResponse\Brand\Address; use ContextDev\Brand\BrandGetResponse\Brand\Backdrop; use ContextDev\Brand\BrandGetResponse\Brand\Color; +use ContextDev\Brand\BrandGetResponse\Brand\Employees; use ContextDev\Brand\BrandGetResponse\Brand\Industries; use ContextDev\Brand\BrandGetResponse\Brand\Links; use ContextDev\Brand\BrandGetResponse\Brand\Logo; @@ -23,6 +24,7 @@ * @phpstan-import-type AddressShape from \ContextDev\Brand\BrandGetResponse\Brand\Address * @phpstan-import-type BackdropShape from \ContextDev\Brand\BrandGetResponse\Brand\Backdrop * @phpstan-import-type ColorShape from \ContextDev\Brand\BrandGetResponse\Brand\Color + * @phpstan-import-type EmployeesShape from \ContextDev\Brand\BrandGetResponse\Brand\Employees * @phpstan-import-type IndustriesShape from \ContextDev\Brand\BrandGetResponse\Brand\Industries * @phpstan-import-type LinksShape from \ContextDev\Brand\BrandGetResponse\Brand\Links * @phpstan-import-type LogoShape from \ContextDev\Brand\BrandGetResponse\Brand\Logo @@ -36,6 +38,7 @@ * description?: string|null, * domain?: string|null, * email?: string|null, + * employees?: null|Employees|EmployeesShape, * industries?: null|Industries|IndustriesShape, * isNsfw?: bool|null, * links?: null|Links|LinksShape, @@ -93,6 +96,12 @@ final class Brand implements BaseModel #[Optional] public ?string $email; + /** + * Employee headcount information for the brand (will be null if unknown). + */ + #[Optional] + public ?Employees $employees; + /** * Industry classification information for the brand. */ @@ -172,6 +181,7 @@ public function __construct() * @param Address|AddressShape|null $address * @param list|null $backdrops * @param list|null $colors + * @param Employees|EmployeesShape|null $employees * @param Industries|IndustriesShape|null $industries * @param Links|LinksShape|null $links * @param list|null $logos @@ -186,6 +196,7 @@ public static function with( ?string $description = null, ?string $domain = null, ?string $email = null, + Employees|array|null $employees = null, Industries|array|null $industries = null, ?bool $isNsfw = null, Links|array|null $links = null, @@ -205,6 +216,7 @@ public static function with( null !== $description && $self['description'] = $description; null !== $domain && $self['domain'] = $domain; null !== $email && $self['email'] = $email; + null !== $employees && $self['employees'] = $employees; null !== $industries && $self['industries'] = $industries; null !== $isNsfw && $self['isNsfw'] = $isNsfw; null !== $links && $self['links'] = $links; @@ -291,6 +303,19 @@ public function withEmail(string $email): self return $self; } + /** + * Employee headcount information for the brand (will be null if unknown). + * + * @param Employees|EmployeesShape $employees + */ + public function withEmployees(Employees|array $employees): self + { + $self = clone $this; + $self['employees'] = $employees; + + return $self; + } + /** * Industry classification information for the brand. * diff --git a/src/Brand/BrandGetResponse/Brand/Employees.php b/src/Brand/BrandGetResponse/Brand/Employees.php new file mode 100644 index 0000000..e9eba50 --- /dev/null +++ b/src/Brand/BrandGetResponse/Brand/Employees.php @@ -0,0 +1,85 @@ + + * } + */ +final class Employees implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** + * Exact employee count when a precise headcount is known. + */ + #[Optional] + public ?int $exact; + + /** + * Employee count range for the brand (e.g. '11 to 50'). + * + * @var value-of|null $range + */ + #[Optional(enum: Range::class)] + public ?string $range; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Range|value-of|null $range + */ + public static function with( + ?int $exact = null, + Range|string|null $range = null + ): self { + $self = new self; + + null !== $exact && $self['exact'] = $exact; + null !== $range && $self['range'] = $range; + + return $self; + } + + /** + * Exact employee count when a precise headcount is known. + */ + public function withExact(int $exact): self + { + $self = clone $this; + $self['exact'] = $exact; + + return $self; + } + + /** + * Employee count range for the brand (e.g. '11 to 50'). + * + * @param Range|value-of $range + */ + public function withRange(Range|string $range): self + { + $self = clone $this; + $self['range'] = $range; + + return $self; + } +} diff --git a/src/Brand/BrandGetResponse/Brand/Employees/Range.php b/src/Brand/BrandGetResponse/Brand/Employees/Range.php new file mode 100644 index 0000000..ef6a6f2 --- /dev/null +++ b/src/Brand/BrandGetResponse/Brand/Employees/Range.php @@ -0,0 +1,27 @@ + $results */ @@ -80,7 +80,7 @@ public static function with( } /** - * Up to 10 matching brands, most popular first. Empty when nothing matches. + * Up to 10 matching brands, name matches first, then domain matches, most popular first within each group. Empty when nothing matches. * * @param list $results */ diff --git a/src/Client.php b/src/Client.php index 2258fbc..facfd9f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,6 +13,7 @@ use ContextDev\Services\IndustryService; use ContextDev\Services\MonitorsService; use ContextDev\Services\ParseService; +use ContextDev\Services\PeopleService; use ContextDev\Services\UtilityService; use ContextDev\Services\WebService; use Http\Discovery\Psr17FactoryDiscovery; @@ -66,6 +67,11 @@ class Client extends BaseClient */ public BatchService $batch; + /** + * @api + */ + public PeopleService $people; + /** * @param RequestOpts|null $requestOptions */ @@ -132,6 +138,7 @@ public function __construct( $this->utility = new UtilityService($this); $this->monitors = new MonitorsService($this); $this->batch = new BatchService($this); + $this->people = new PeopleService($this); } /** @return array */ diff --git a/src/Parse/ParseHandleParams.php b/src/Parse/ParseHandleParams.php index 7e18b75..4c7b150 100644 --- a/src/Parse/ParseHandleParams.php +++ b/src/Parse/ParseHandleParams.php @@ -85,7 +85,7 @@ final class ParseHandleParams implements BaseModel public bool|string|null $includeLinks; /** - * When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback. + * When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @var OcrVariants|null $ocr */ @@ -231,7 +231,7 @@ public function withIncludeLinks( } /** - * When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback. + * When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @param OcrShape $ocr */ diff --git a/src/Parse/ParseHandleParams/Ocr.php b/src/Parse/ParseHandleParams/Ocr.php index 2455988..6f68b5e 100644 --- a/src/Parse/ParseHandleParams/Ocr.php +++ b/src/Parse/ParseHandleParams/Ocr.php @@ -10,7 +10,7 @@ use ContextDev\Parse\ParseHandleParams\Ocr\UnionMember1; /** - * When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback. + * When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @phpstan-type OcrVariants = bool|value-of * @phpstan-type OcrShape = OcrVariants diff --git a/src/People/PersonEnrichParams.php b/src/People/PersonEnrichParams.php new file mode 100644 index 0000000..637e578 --- /dev/null +++ b/src/People/PersonEnrichParams.php @@ -0,0 +1,204 @@ +|null, + * email?: string|null, + * location?: null|Location|LocationShape, + * name?: null|Name|NameShape, + * socialURLs?: list|null, + * tags?: list|null, + * timeoutMs?: int|null, + * } + */ +final class PersonEnrichParams implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + use SdkParams; + + #[Optional] + public ?Company $company; + + /** @var list|null $education */ + #[Optional(list: Education::class)] + public ?array $education; + + #[Optional] + public ?string $email; + + #[Optional] + public ?Location $location; + + #[Optional] + public ?Name $name; + + /** @var list|null $socialURLs */ + #[Optional('social_urls', list: 'string')] + public ?array $socialURLs; + + /** + * Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. + * + * @var list|null $tags + */ + #[Optional(list: 'string')] + public ?array $tags; + + /** + * Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + */ + #[Optional('timeoutMS')] + public ?int $timeoutMs; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Company|CompanyShape|null $company + * @param list|null $education + * @param Location|LocationShape|null $location + * @param Name|NameShape|null $name + * @param list|null $socialURLs + * @param list|null $tags + */ + public static function with( + Company|array|null $company = null, + ?array $education = null, + ?string $email = null, + Location|array|null $location = null, + Name|array|null $name = null, + ?array $socialURLs = null, + ?array $tags = null, + ?int $timeoutMs = null, + ): self { + $self = new self; + + null !== $company && $self['company'] = $company; + null !== $education && $self['education'] = $education; + null !== $email && $self['email'] = $email; + null !== $location && $self['location'] = $location; + null !== $name && $self['name'] = $name; + null !== $socialURLs && $self['socialURLs'] = $socialURLs; + null !== $tags && $self['tags'] = $tags; + null !== $timeoutMs && $self['timeoutMs'] = $timeoutMs; + + return $self; + } + + /** + * @param Company|CompanyShape $company + */ + public function withCompany(Company|array $company): self + { + $self = clone $this; + $self['company'] = $company; + + return $self; + } + + /** + * @param list $education + */ + public function withEducation(array $education): self + { + $self = clone $this; + $self['education'] = $education; + + return $self; + } + + public function withEmail(string $email): self + { + $self = clone $this; + $self['email'] = $email; + + return $self; + } + + /** + * @param Location|LocationShape $location + */ + public function withLocation(Location|array $location): self + { + $self = clone $this; + $self['location'] = $location; + + return $self; + } + + /** + * @param Name|NameShape $name + */ + public function withName(Name|array $name): self + { + $self = clone $this; + $self['name'] = $name; + + return $self; + } + + /** + * @param list $socialURLs + */ + public function withSocialURLs(array $socialURLs): self + { + $self = clone $this; + $self['socialURLs'] = $socialURLs; + + return $self; + } + + /** + * Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. + * + * @param list $tags + */ + public function withTags(array $tags): self + { + $self = clone $this; + $self['tags'] = $tags; + + return $self; + } + + /** + * Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + */ + public function withTimeoutMs(int $timeoutMs): self + { + $self = clone $this; + $self['timeoutMs'] = $timeoutMs; + + return $self; + } +} diff --git a/src/People/PersonEnrichParams/Company.php b/src/People/PersonEnrichParams/Company.php new file mode 100644 index 0000000..3f57a08 --- /dev/null +++ b/src/People/PersonEnrichParams/Company.php @@ -0,0 +1,62 @@ + */ + use SdkModel; + + #[Optional] + public ?string $domain; + + #[Optional] + public ?string $name; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?string $domain = null, + ?string $name = null + ): self { + $self = new self; + + null !== $domain && $self['domain'] = $domain; + null !== $name && $self['name'] = $name; + + return $self; + } + + public function withDomain(string $domain): self + { + $self = clone $this; + $self['domain'] = $domain; + + return $self; + } + + public function withName(string $name): self + { + $self = clone $this; + $self['name'] = $name; + + return $self; + } +} diff --git a/src/People/PersonEnrichParams/Education.php b/src/People/PersonEnrichParams/Education.php new file mode 100644 index 0000000..a1e2683 --- /dev/null +++ b/src/People/PersonEnrichParams/Education.php @@ -0,0 +1,101 @@ + */ + use SdkModel; + + #[Optional] + public ?string $degree; + + #[Optional('field_of_study')] + public ?string $fieldOfStudy; + + #[Optional('graduation_year')] + public ?int $graduationYear; + + #[Optional] + public ?Institution $institution; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Institution|InstitutionShape|null $institution + */ + public static function with( + ?string $degree = null, + ?string $fieldOfStudy = null, + ?int $graduationYear = null, + Institution|array|null $institution = null, + ): self { + $self = new self; + + null !== $degree && $self['degree'] = $degree; + null !== $fieldOfStudy && $self['fieldOfStudy'] = $fieldOfStudy; + null !== $graduationYear && $self['graduationYear'] = $graduationYear; + null !== $institution && $self['institution'] = $institution; + + return $self; + } + + public function withDegree(string $degree): self + { + $self = clone $this; + $self['degree'] = $degree; + + return $self; + } + + public function withFieldOfStudy(string $fieldOfStudy): self + { + $self = clone $this; + $self['fieldOfStudy'] = $fieldOfStudy; + + return $self; + } + + public function withGraduationYear(int $graduationYear): self + { + $self = clone $this; + $self['graduationYear'] = $graduationYear; + + return $self; + } + + /** + * @param Institution|InstitutionShape $institution + */ + public function withInstitution(Institution|array $institution): self + { + $self = clone $this; + $self['institution'] = $institution; + + return $self; + } +} diff --git a/src/People/PersonEnrichParams/Education/Institution.php b/src/People/PersonEnrichParams/Education/Institution.php new file mode 100644 index 0000000..aaae682 --- /dev/null +++ b/src/People/PersonEnrichParams/Education/Institution.php @@ -0,0 +1,62 @@ + */ + use SdkModel; + + #[Optional] + public ?string $domain; + + #[Optional] + public ?string $name; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?string $domain = null, + ?string $name = null + ): self { + $self = new self; + + null !== $domain && $self['domain'] = $domain; + null !== $name && $self['name'] = $name; + + return $self; + } + + public function withDomain(string $domain): self + { + $self = clone $this; + $self['domain'] = $domain; + + return $self; + } + + public function withName(string $name): self + { + $self = clone $this; + $self['name'] = $name; + + return $self; + } +} diff --git a/src/People/PersonEnrichParams/Location.php b/src/People/PersonEnrichParams/Location.php new file mode 100644 index 0000000..c45ef6e --- /dev/null +++ b/src/People/PersonEnrichParams/Location.php @@ -0,0 +1,77 @@ + */ + use SdkModel; + + #[Optional] + public ?string $city; + + #[Optional] + public ?string $country; + + #[Optional] + public ?string $region; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?string $city = null, + ?string $country = null, + ?string $region = null + ): self { + $self = new self; + + null !== $city && $self['city'] = $city; + null !== $country && $self['country'] = $country; + null !== $region && $self['region'] = $region; + + return $self; + } + + public function withCity(string $city): self + { + $self = clone $this; + $self['city'] = $city; + + return $self; + } + + public function withCountry(string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + + public function withRegion(string $region): self + { + $self = clone $this; + $self['region'] = $region; + + return $self; + } +} diff --git a/src/People/PersonEnrichParams/Name.php b/src/People/PersonEnrichParams/Name.php new file mode 100644 index 0000000..df93ca2 --- /dev/null +++ b/src/People/PersonEnrichParams/Name.php @@ -0,0 +1,60 @@ + */ + use SdkModel; + + #[Optional] + public ?string $first; + + #[Optional] + public ?string $last; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(?string $first = null, ?string $last = null): self + { + $self = new self; + + null !== $first && $self['first'] = $first; + null !== $last && $self['last'] = $last; + + return $self; + } + + public function withFirst(string $first): self + { + $self = clone $this; + $self['first'] = $first; + + return $self; + } + + public function withLast(string $last): self + { + $self = clone $this; + $self['last'] = $last; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse.php b/src/People/PersonEnrichResponse.php new file mode 100644 index 0000000..7d9db40 --- /dev/null +++ b/src/People/PersonEnrichResponse.php @@ -0,0 +1,110 @@ + */ + use SdkModel; + + /** + * The highest-scoring person candidate. + * + * @var MatchVariants $match + */ + #[Required(union: Match_::class)] + public PersonEnrichmentCandidateMatch|PersonEnrichmentNotFoundMatch $match; + + /** + * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + */ + #[Optional('key_metadata')] + public ?KeyMetadata $keyMetadata; + + /** + * `new PersonEnrichResponse()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * PersonEnrichResponse::with(match: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new PersonEnrichResponse)->withMatch(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param MatchShape $match + * @param KeyMetadata|KeyMetadataShape|null $keyMetadata + */ + public static function with( + PersonEnrichmentCandidateMatch|array|PersonEnrichmentNotFoundMatch $match, + KeyMetadata|array|null $keyMetadata = null, + ): self { + $self = new self; + + $self['match'] = $match; + + null !== $keyMetadata && $self['keyMetadata'] = $keyMetadata; + + return $self; + } + + /** + * The highest-scoring person candidate. + * + * @param MatchShape $match + */ + public function withMatch( + PersonEnrichmentCandidateMatch|array|PersonEnrichmentNotFoundMatch $match + ): self { + $self = clone $this; + $self['match'] = $match; + + return $self; + } + + /** + * Metadata about the API key used for the request. Included in every response whenever a valid API key is provided, even when the response status is not 200. + * + * @param KeyMetadata|KeyMetadataShape $keyMetadata + */ + public function withKeyMetadata(KeyMetadata|array $keyMetadata): self + { + $self = clone $this; + $self['keyMetadata'] = $keyMetadata; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/KeyMetadata.php b/src/People/PersonEnrichResponse/KeyMetadata.php new file mode 100644 index 0000000..e86d446 --- /dev/null +++ b/src/People/PersonEnrichResponse/KeyMetadata.php @@ -0,0 +1,92 @@ + */ + use SdkModel; + + /** + * The number of credits consumed by this request. + */ + #[Required('credits_consumed')] + public int $creditsConsumed; + + /** + * The number of credits remaining for your organization after this request. + */ + #[Required('credits_remaining')] + public int $creditsRemaining; + + /** + * `new KeyMetadata()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * KeyMetadata::with(creditsConsumed: ..., creditsRemaining: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new KeyMetadata)->withCreditsConsumed(...)->withCreditsRemaining(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + int $creditsConsumed, + int $creditsRemaining + ): self { + $self = new self; + + $self['creditsConsumed'] = $creditsConsumed; + $self['creditsRemaining'] = $creditsRemaining; + + return $self; + } + + /** + * The number of credits consumed by this request. + */ + public function withCreditsConsumed(int $creditsConsumed): self + { + $self = clone $this; + $self['creditsConsumed'] = $creditsConsumed; + + return $self; + } + + /** + * The number of credits remaining for your organization after this request. + */ + public function withCreditsRemaining(int $creditsRemaining): self + { + $self = clone $this; + $self['creditsRemaining'] = $creditsRemaining; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_.php b/src/People/PersonEnrichResponse/Match_.php new file mode 100644 index 0000000..9fa31be --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_.php @@ -0,0 +1,41 @@ +|array + */ + public static function variants(): array + { + return [ + 'candidate' => PersonEnrichmentCandidateMatch::class, + 'not_found' => PersonEnrichmentNotFoundMatch::class, + ]; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch.php new file mode 100644 index 0000000..0bb6018 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch.php @@ -0,0 +1,101 @@ + */ + use SdkModel; + + /** @var 'candidate' $status */ + #[Required] + public string $status = 'candidate'; + + #[Required] + public Person $person; + + #[Required] + public int $score; + + /** + * `new PersonEnrichmentCandidateMatch()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * PersonEnrichmentCandidateMatch::with(person: ..., score: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new PersonEnrichmentCandidateMatch)->withPerson(...)->withScore(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Person|PersonShape $person + */ + public static function with(Person|array $person, int $score): self + { + $self = new self; + + $self['person'] = $person; + $self['score'] = $score; + + return $self; + } + + /** + * @param Person|PersonShape $person + */ + public function withPerson(Person|array $person): self + { + $self = clone $this; + $self['person'] = $person; + + return $self; + } + + public function withScore(int $score): self + { + $self = clone $this; + $self['score'] = $score; + + return $self; + } + + /** + * @param 'candidate' $status + */ + public function withStatus(string $status): self + { + $self = clone $this; + $self['status'] = $status; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person.php new file mode 100644 index 0000000..eff3845 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person.php @@ -0,0 +1,267 @@ +, + * experience: list, + * skills: list, + * socialURLs: list, + * websiteURLs: list, + * avatarURL?: string|null, + * bio?: string|null, + * currentRole?: null|CurrentRole|CurrentRoleShape, + * email?: string|null, + * location?: null|Location|LocationShape, + * name?: null|Name|NameShape, + * } + */ +final class Person implements BaseModel +{ + /** @use SdkModel */ + use SdkModel; + + /** @var list $education */ + #[Required(list: Education::class)] + public array $education; + + /** @var list $experience */ + #[Required(list: Experience::class)] + public array $experience; + + /** @var list $skills */ + #[Required(list: 'string')] + public array $skills; + + /** @var list $socialURLs */ + #[Required('social_urls', list: 'string')] + public array $socialURLs; + + /** @var list $websiteURLs */ + #[Required('website_urls', list: 'string')] + public array $websiteURLs; + + #[Optional('avatar_url')] + public ?string $avatarURL; + + #[Optional] + public ?string $bio; + + #[Optional('current_role')] + public ?CurrentRole $currentRole; + + #[Optional] + public ?string $email; + + #[Optional] + public ?Location $location; + + #[Optional] + public ?Name $name; + + /** + * `new Person()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Person::with( + * education: ..., + * experience: ..., + * skills: ..., + * socialURLs: ..., + * websiteURLs: ..., + * ) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Person) + * ->withEducation(...) + * ->withExperience(...) + * ->withSkills(...) + * ->withSocialURLs(...) + * ->withWebsiteURLs(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param list $education + * @param list $experience + * @param list $skills + * @param list $socialURLs + * @param list $websiteURLs + * @param CurrentRole|CurrentRoleShape|null $currentRole + * @param Location|LocationShape|null $location + * @param Name|NameShape|null $name + */ + public static function with( + array $education, + array $experience, + array $skills, + array $socialURLs, + array $websiteURLs, + ?string $avatarURL = null, + ?string $bio = null, + CurrentRole|array|null $currentRole = null, + ?string $email = null, + Location|array|null $location = null, + Name|array|null $name = null, + ): self { + $self = new self; + + $self['education'] = $education; + $self['experience'] = $experience; + $self['skills'] = $skills; + $self['socialURLs'] = $socialURLs; + $self['websiteURLs'] = $websiteURLs; + + null !== $avatarURL && $self['avatarURL'] = $avatarURL; + null !== $bio && $self['bio'] = $bio; + null !== $currentRole && $self['currentRole'] = $currentRole; + null !== $email && $self['email'] = $email; + null !== $location && $self['location'] = $location; + null !== $name && $self['name'] = $name; + + return $self; + } + + /** + * @param list $education + */ + public function withEducation(array $education): self + { + $self = clone $this; + $self['education'] = $education; + + return $self; + } + + /** + * @param list $experience + */ + public function withExperience(array $experience): self + { + $self = clone $this; + $self['experience'] = $experience; + + return $self; + } + + /** + * @param list $skills + */ + public function withSkills(array $skills): self + { + $self = clone $this; + $self['skills'] = $skills; + + return $self; + } + + /** + * @param list $socialURLs + */ + public function withSocialURLs(array $socialURLs): self + { + $self = clone $this; + $self['socialURLs'] = $socialURLs; + + return $self; + } + + /** + * @param list $websiteURLs + */ + public function withWebsiteURLs(array $websiteURLs): self + { + $self = clone $this; + $self['websiteURLs'] = $websiteURLs; + + return $self; + } + + public function withAvatarURL(string $avatarURL): self + { + $self = clone $this; + $self['avatarURL'] = $avatarURL; + + return $self; + } + + public function withBio(string $bio): self + { + $self = clone $this; + $self['bio'] = $bio; + + return $self; + } + + /** + * @param CurrentRole|CurrentRoleShape $currentRole + */ + public function withCurrentRole(CurrentRole|array $currentRole): self + { + $self = clone $this; + $self['currentRole'] = $currentRole; + + return $self; + } + + public function withEmail(string $email): self + { + $self = clone $this; + $self['email'] = $email; + + return $self; + } + + /** + * @param Location|LocationShape $location + */ + public function withLocation(Location|array $location): self + { + $self = clone $this; + $self['location'] = $location; + + return $self; + } + + /** + * @param Name|NameShape $name + */ + public function withName(Name|array $name): self + { + $self = clone $this; + $self['name'] = $name; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole.php new file mode 100644 index 0000000..58005ce --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole.php @@ -0,0 +1,171 @@ + */ + use SdkModel; + + #[Required] + public Organization $organization; + + #[Required] + public string $title; + + #[Optional] + public ?string $description; + + #[Optional('end_date')] + public ?EndDate $endDate; + + #[Optional('is_current')] + public ?bool $isCurrent; + + #[Optional] + public ?string $location; + + #[Optional('start_date')] + public ?StartDate $startDate; + + /** + * `new CurrentRole()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * CurrentRole::with(organization: ..., title: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new CurrentRole)->withOrganization(...)->withTitle(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Organization|OrganizationShape $organization + * @param EndDate|EndDateShape|null $endDate + * @param StartDate|StartDateShape|null $startDate + */ + public static function with( + Organization|array $organization, + string $title, + ?string $description = null, + EndDate|array|null $endDate = null, + ?bool $isCurrent = null, + ?string $location = null, + StartDate|array|null $startDate = null, + ): self { + $self = new self; + + $self['organization'] = $organization; + $self['title'] = $title; + + null !== $description && $self['description'] = $description; + null !== $endDate && $self['endDate'] = $endDate; + null !== $isCurrent && $self['isCurrent'] = $isCurrent; + null !== $location && $self['location'] = $location; + null !== $startDate && $self['startDate'] = $startDate; + + return $self; + } + + /** + * @param Organization|OrganizationShape $organization + */ + public function withOrganization(Organization|array $organization): self + { + $self = clone $this; + $self['organization'] = $organization; + + return $self; + } + + public function withTitle(string $title): self + { + $self = clone $this; + $self['title'] = $title; + + return $self; + } + + public function withDescription(string $description): self + { + $self = clone $this; + $self['description'] = $description; + + return $self; + } + + /** + * @param EndDate|EndDateShape $endDate + */ + public function withEndDate(EndDate|array $endDate): self + { + $self = clone $this; + $self['endDate'] = $endDate; + + return $self; + } + + public function withIsCurrent(bool $isCurrent): self + { + $self = clone $this; + $self['isCurrent'] = $isCurrent; + + return $self; + } + + public function withLocation(string $location): self + { + $self = clone $this; + $self['location'] = $location; + + return $self; + } + + /** + * @param StartDate|StartDateShape $startDate + */ + public function withStartDate(StartDate|array $startDate): self + { + $self = clone $this; + $self['startDate'] = $startDate; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitResponse/Person/Education/Dates/EndDate.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/EndDate.php similarity index 83% rename from src/Batch/BatchSubmitResponse/Person/Education/Dates/EndDate.php rename to src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/EndDate.php index 6abd73f..9016819 100644 --- a/src/Batch/BatchSubmitResponse/Person/Education/Dates/EndDate.php +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/EndDate.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\BatchSubmitResponse\Person\Education\Dates; +namespace ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\CurrentRole; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; @@ -10,8 +10,6 @@ use ContextDev\Core\Contracts\BaseModel; /** - * End date, when known. - * * @phpstan-type EndDateShape = array{year: int, day?: int|null, month?: int|null} */ final class EndDate implements BaseModel @@ -19,21 +17,12 @@ final class EndDate implements BaseModel /** @use SdkModel */ use SdkModel; - /** - * Year value. - */ #[Required] public int $year; - /** - * Day value, when known. - */ #[Optional] public ?int $day; - /** - * Month value, when known. - */ #[Optional] public ?int $month; @@ -76,9 +65,6 @@ public static function with( return $self; } - /** - * Year value. - */ public function withYear(int $year): self { $self = clone $this; @@ -87,9 +73,6 @@ public function withYear(int $year): self return $self; } - /** - * Day value, when known. - */ public function withDay(int $day): self { $self = clone $this; @@ -98,9 +81,6 @@ public function withDay(int $day): self return $self; } - /** - * Month value, when known. - */ public function withMonth(int $month): self { $self = clone $this; diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/Organization.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/Organization.php new file mode 100644 index 0000000..4cb9738 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/Organization.php @@ -0,0 +1,76 @@ + */ + use SdkModel; + + #[Required] + public string $name; + + #[Optional] + public ?string $domain; + + /** + * `new Organization()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Organization::with(name: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Organization)->withName(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(string $name, ?string $domain = null): self + { + $self = new self; + + $self['name'] = $name; + + null !== $domain && $self['domain'] = $domain; + + return $self; + } + + public function withName(string $name): self + { + $self = clone $this; + $self['name'] = $name; + + return $self; + } + + public function withDomain(string $domain): self + { + $self = clone $this; + $self['domain'] = $domain; + + return $self; + } +} diff --git a/src/Batch/BatchSubmitResponse/Person/Education/Dates/StartDate.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/StartDate.php similarity index 83% rename from src/Batch/BatchSubmitResponse/Person/Education/Dates/StartDate.php rename to src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/StartDate.php index 356edb2..f9d07d4 100644 --- a/src/Batch/BatchSubmitResponse/Person/Education/Dates/StartDate.php +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/CurrentRole/StartDate.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\BatchSubmitResponse\Person\Education\Dates; +namespace ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\CurrentRole; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; @@ -10,8 +10,6 @@ use ContextDev\Core\Contracts\BaseModel; /** - * Start date, when known. - * * @phpstan-type StartDateShape = array{ * year: int, day?: int|null, month?: int|null * } @@ -21,21 +19,12 @@ final class StartDate implements BaseModel /** @use SdkModel */ use SdkModel; - /** - * Year value. - */ #[Required] public int $year; - /** - * Day value, when known. - */ #[Optional] public ?int $day; - /** - * Month value, when known. - */ #[Optional] public ?int $month; @@ -78,9 +67,6 @@ public static function with( return $self; } - /** - * Year value. - */ public function withYear(int $year): self { $self = clone $this; @@ -89,9 +75,6 @@ public function withYear(int $year): self return $self; } - /** - * Day value, when known. - */ public function withDay(int $day): self { $self = clone $this; @@ -100,9 +83,6 @@ public function withDay(int $day): self return $self; } - /** - * Month value, when known. - */ public function withMonth(int $month): self { $self = clone $this; diff --git a/src/Batch/BatchSubmitResponse/Person/Education.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education.php similarity index 54% rename from src/Batch/BatchSubmitResponse/Person/Education.php rename to src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education.php index d6d858d..da1996c 100644 --- a/src/Batch/BatchSubmitResponse/Person/Education.php +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education.php @@ -2,25 +2,28 @@ declare(strict_types=1); -namespace ContextDev\Batch\BatchSubmitResponse\Person; +namespace ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person; -use ContextDev\Batch\BatchSubmitResponse\Person\Education\Dates; -use ContextDev\Batch\BatchSubmitResponse\Person\Education\Institution; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; use ContextDev\Core\Concerns\SdkModel; use ContextDev\Core\Contracts\BaseModel; +use ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education\EndDate; +use ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education\Institution; +use ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education\StartDate; /** - * @phpstan-import-type InstitutionShape from \ContextDev\Batch\BatchSubmitResponse\Person\Education\Institution - * @phpstan-import-type DatesShape from \ContextDev\Batch\BatchSubmitResponse\Person\Education\Dates + * @phpstan-import-type InstitutionShape from \ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education\Institution + * @phpstan-import-type EndDateShape from \ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education\EndDate + * @phpstan-import-type StartDateShape from \ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education\StartDate * * @phpstan-type EducationShape = array{ * institution: Institution|InstitutionShape, - * dates?: null|Dates|DatesShape, + * degree?: string|null, * description?: string|null, + * endDate?: null|EndDate|EndDateShape, * fieldOfStudy?: string|null, - * qualification?: string|null, + * startDate?: null|StartDate|StartDateShape, * } */ final class Education implements BaseModel @@ -28,35 +31,23 @@ final class Education implements BaseModel /** @use SdkModel */ use SdkModel; - /** - * School or institution name. - */ #[Required] public Institution $institution; - /** - * Education dates. - */ #[Optional] - public ?Dates $dates; + public ?string $degree; - /** - * Additional education details. - */ #[Optional] public ?string $description; - /** - * Area of study. - */ - #[Optional] + #[Optional('end_date')] + public ?EndDate $endDate; + + #[Optional('field_of_study')] public ?string $fieldOfStudy; - /** - * Degree, certificate, or credential. - */ - #[Optional] - public ?string $qualification; + #[Optional('start_date')] + public ?StartDate $startDate; /** * `new Education()` is missing required properties by the API. @@ -83,30 +74,31 @@ public function __construct() * You must use named parameters to construct any parameters with a default value. * * @param Institution|InstitutionShape $institution - * @param Dates|DatesShape|null $dates + * @param EndDate|EndDateShape|null $endDate + * @param StartDate|StartDateShape|null $startDate */ public static function with( Institution|array $institution, - Dates|array|null $dates = null, + ?string $degree = null, ?string $description = null, + EndDate|array|null $endDate = null, ?string $fieldOfStudy = null, - ?string $qualification = null, + StartDate|array|null $startDate = null, ): self { $self = new self; $self['institution'] = $institution; - null !== $dates && $self['dates'] = $dates; + null !== $degree && $self['degree'] = $degree; null !== $description && $self['description'] = $description; + null !== $endDate && $self['endDate'] = $endDate; null !== $fieldOfStudy && $self['fieldOfStudy'] = $fieldOfStudy; - null !== $qualification && $self['qualification'] = $qualification; + null !== $startDate && $self['startDate'] = $startDate; return $self; } /** - * School or institution name. - * * @param Institution|InstitutionShape $institution */ public function withInstitution(Institution|array $institution): self @@ -117,22 +109,14 @@ public function withInstitution(Institution|array $institution): self return $self; } - /** - * Education dates. - * - * @param Dates|DatesShape $dates - */ - public function withDates(Dates|array $dates): self + public function withDegree(string $degree): self { $self = clone $this; - $self['dates'] = $dates; + $self['degree'] = $degree; return $self; } - /** - * Additional education details. - */ public function withDescription(string $description): self { $self = clone $this; @@ -142,8 +126,16 @@ public function withDescription(string $description): self } /** - * Area of study. + * @param EndDate|EndDateShape $endDate */ + public function withEndDate(EndDate|array $endDate): self + { + $self = clone $this; + $self['endDate'] = $endDate; + + return $self; + } + public function withFieldOfStudy(string $fieldOfStudy): self { $self = clone $this; @@ -153,12 +145,12 @@ public function withFieldOfStudy(string $fieldOfStudy): self } /** - * Degree, certificate, or credential. + * @param StartDate|StartDateShape $startDate */ - public function withQualification(string $qualification): self + public function withStartDate(StartDate|array $startDate): self { $self = clone $this; - $self['qualification'] = $qualification; + $self['startDate'] = $startDate; return $self; } diff --git a/src/Batch/BatchSubmitResponse/Person/Experience/Dates/EndDate.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/EndDate.php similarity index 83% rename from src/Batch/BatchSubmitResponse/Person/Experience/Dates/EndDate.php rename to src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/EndDate.php index 9723146..499e245 100644 --- a/src/Batch/BatchSubmitResponse/Person/Experience/Dates/EndDate.php +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/EndDate.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\BatchSubmitResponse\Person\Experience\Dates; +namespace ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; @@ -10,8 +10,6 @@ use ContextDev\Core\Contracts\BaseModel; /** - * End date, when known. - * * @phpstan-type EndDateShape = array{year: int, day?: int|null, month?: int|null} */ final class EndDate implements BaseModel @@ -19,21 +17,12 @@ final class EndDate implements BaseModel /** @use SdkModel */ use SdkModel; - /** - * Year value. - */ #[Required] public int $year; - /** - * Day value, when known. - */ #[Optional] public ?int $day; - /** - * Month value, when known. - */ #[Optional] public ?int $month; @@ -76,9 +65,6 @@ public static function with( return $self; } - /** - * Year value. - */ public function withYear(int $year): self { $self = clone $this; @@ -87,9 +73,6 @@ public function withYear(int $year): self return $self; } - /** - * Day value, when known. - */ public function withDay(int $day): self { $self = clone $this; @@ -98,9 +81,6 @@ public function withDay(int $day): self return $self; } - /** - * Month value, when known. - */ public function withMonth(int $month): self { $self = clone $this; diff --git a/src/Batch/BatchSubmitResponse/Person/Education/Institution.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/Institution.php similarity index 52% rename from src/Batch/BatchSubmitResponse/Person/Education/Institution.php rename to src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/Institution.php index 55d16cf..06d4594 100644 --- a/src/Batch/BatchSubmitResponse/Person/Education/Institution.php +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/Institution.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\BatchSubmitResponse\Person\Education; +namespace ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; @@ -10,41 +10,31 @@ use ContextDev\Core\Contracts\BaseModel; /** - * School or institution name. - * - * @phpstan-type InstitutionShape = array{ - * display: string, normalized?: string|null - * } + * @phpstan-type InstitutionShape = array{name: string, domain?: string|null} */ final class Institution implements BaseModel { /** @use SdkModel */ use SdkModel; - /** - * Display name. - */ #[Required] - public string $display; + public string $name; - /** - * Standardized name, when available. - */ #[Optional] - public ?string $normalized; + public ?string $domain; /** * `new Institution()` is missing required properties by the API. * * To enforce required parameters use * ``` - * Institution::with(display: ...) + * Institution::with(name: ...) * ``` * * Otherwise ensure the following setters are called * * ``` - * (new Institution)->withDisplay(...) + * (new Institution)->withName(...) * ``` */ public function __construct() @@ -57,37 +47,29 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. */ - public static function with( - string $display, - ?string $normalized = null - ): self { + public static function with(string $name, ?string $domain = null): self + { $self = new self; - $self['display'] = $display; + $self['name'] = $name; - null !== $normalized && $self['normalized'] = $normalized; + null !== $domain && $self['domain'] = $domain; return $self; } - /** - * Display name. - */ - public function withDisplay(string $display): self + public function withName(string $name): self { $self = clone $this; - $self['display'] = $display; + $self['name'] = $name; return $self; } - /** - * Standardized name, when available. - */ - public function withNormalized(string $normalized): self + public function withDomain(string $domain): self { $self = clone $this; - $self['normalized'] = $normalized; + $self['domain'] = $domain; return $self; } diff --git a/src/Batch/BatchSubmitResponse/Person/Experience/Dates/StartDate.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/StartDate.php similarity index 83% rename from src/Batch/BatchSubmitResponse/Person/Experience/Dates/StartDate.php rename to src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/StartDate.php index a8a241d..b639ff2 100644 --- a/src/Batch/BatchSubmitResponse/Person/Experience/Dates/StartDate.php +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Education/StartDate.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace ContextDev\Batch\BatchSubmitResponse\Person\Experience\Dates; +namespace ContextDev\People\PersonEnrichResponse\Match_\PersonEnrichmentCandidateMatch\Person\Education; use ContextDev\Core\Attributes\Optional; use ContextDev\Core\Attributes\Required; @@ -10,8 +10,6 @@ use ContextDev\Core\Contracts\BaseModel; /** - * Start date, when known. - * * @phpstan-type StartDateShape = array{ * year: int, day?: int|null, month?: int|null * } @@ -21,21 +19,12 @@ final class StartDate implements BaseModel /** @use SdkModel */ use SdkModel; - /** - * Year value. - */ #[Required] public int $year; - /** - * Day value, when known. - */ #[Optional] public ?int $day; - /** - * Month value, when known. - */ #[Optional] public ?int $month; @@ -78,9 +67,6 @@ public static function with( return $self; } - /** - * Year value. - */ public function withYear(int $year): self { $self = clone $this; @@ -89,9 +75,6 @@ public function withYear(int $year): self return $self; } - /** - * Day value, when known. - */ public function withDay(int $day): self { $self = clone $this; @@ -100,9 +83,6 @@ public function withDay(int $day): self return $self; } - /** - * Month value, when known. - */ public function withMonth(int $month): self { $self = clone $this; diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience.php new file mode 100644 index 0000000..8ec6b85 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience.php @@ -0,0 +1,171 @@ + */ + use SdkModel; + + #[Required] + public Organization $organization; + + #[Required] + public string $title; + + #[Optional] + public ?string $description; + + #[Optional('end_date')] + public ?EndDate $endDate; + + #[Optional('is_current')] + public ?bool $isCurrent; + + #[Optional] + public ?string $location; + + #[Optional('start_date')] + public ?StartDate $startDate; + + /** + * `new Experience()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Experience::with(organization: ..., title: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Experience)->withOrganization(...)->withTitle(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param Organization|OrganizationShape $organization + * @param EndDate|EndDateShape|null $endDate + * @param StartDate|StartDateShape|null $startDate + */ + public static function with( + Organization|array $organization, + string $title, + ?string $description = null, + EndDate|array|null $endDate = null, + ?bool $isCurrent = null, + ?string $location = null, + StartDate|array|null $startDate = null, + ): self { + $self = new self; + + $self['organization'] = $organization; + $self['title'] = $title; + + null !== $description && $self['description'] = $description; + null !== $endDate && $self['endDate'] = $endDate; + null !== $isCurrent && $self['isCurrent'] = $isCurrent; + null !== $location && $self['location'] = $location; + null !== $startDate && $self['startDate'] = $startDate; + + return $self; + } + + /** + * @param Organization|OrganizationShape $organization + */ + public function withOrganization(Organization|array $organization): self + { + $self = clone $this; + $self['organization'] = $organization; + + return $self; + } + + public function withTitle(string $title): self + { + $self = clone $this; + $self['title'] = $title; + + return $self; + } + + public function withDescription(string $description): self + { + $self = clone $this; + $self['description'] = $description; + + return $self; + } + + /** + * @param EndDate|EndDateShape $endDate + */ + public function withEndDate(EndDate|array $endDate): self + { + $self = clone $this; + $self['endDate'] = $endDate; + + return $self; + } + + public function withIsCurrent(bool $isCurrent): self + { + $self = clone $this; + $self['isCurrent'] = $isCurrent; + + return $self; + } + + public function withLocation(string $location): self + { + $self = clone $this; + $self['location'] = $location; + + return $self; + } + + /** + * @param StartDate|StartDateShape $startDate + */ + public function withStartDate(StartDate|array $startDate): self + { + $self = clone $this; + $self['startDate'] = $startDate; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/EndDate.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/EndDate.php new file mode 100644 index 0000000..2b28b48 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/EndDate.php @@ -0,0 +1,91 @@ + */ + use SdkModel; + + #[Required] + public int $year; + + #[Optional] + public ?int $day; + + #[Optional] + public ?int $month; + + /** + * `new EndDate()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * EndDate::with(year: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new EndDate)->withYear(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + int $year, + ?int $day = null, + ?int $month = null + ): self { + $self = new self; + + $self['year'] = $year; + + null !== $day && $self['day'] = $day; + null !== $month && $self['month'] = $month; + + return $self; + } + + public function withYear(int $year): self + { + $self = clone $this; + $self['year'] = $year; + + return $self; + } + + public function withDay(int $day): self + { + $self = clone $this; + $self['day'] = $day; + + return $self; + } + + public function withMonth(int $month): self + { + $self = clone $this; + $self['month'] = $month; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/Organization.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/Organization.php new file mode 100644 index 0000000..e73034f --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/Organization.php @@ -0,0 +1,76 @@ + */ + use SdkModel; + + #[Required] + public string $name; + + #[Optional] + public ?string $domain; + + /** + * `new Organization()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * Organization::with(name: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new Organization)->withName(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with(string $name, ?string $domain = null): self + { + $self = new self; + + $self['name'] = $name; + + null !== $domain && $self['domain'] = $domain; + + return $self; + } + + public function withName(string $name): self + { + $self = clone $this; + $self['name'] = $name; + + return $self; + } + + public function withDomain(string $domain): self + { + $self = clone $this; + $self['domain'] = $domain; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/StartDate.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/StartDate.php new file mode 100644 index 0000000..db6ac57 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Experience/StartDate.php @@ -0,0 +1,93 @@ + */ + use SdkModel; + + #[Required] + public int $year; + + #[Optional] + public ?int $day; + + #[Optional] + public ?int $month; + + /** + * `new StartDate()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * StartDate::with(year: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new StartDate)->withYear(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + int $year, + ?int $day = null, + ?int $month = null + ): self { + $self = new self; + + $self['year'] = $year; + + null !== $day && $self['day'] = $day; + null !== $month && $self['month'] = $month; + + return $self; + } + + public function withYear(int $year): self + { + $self = clone $this; + $self['year'] = $year; + + return $self; + } + + public function withDay(int $day): self + { + $self = clone $this; + $self['day'] = $day; + + return $self; + } + + public function withMonth(int $month): self + { + $self = clone $this; + $self['month'] = $month; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Location.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Location.php new file mode 100644 index 0000000..f237b48 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Location.php @@ -0,0 +1,107 @@ + */ + use SdkModel; + + #[Optional] + public ?string $city; + + #[Optional] + public ?string $country; + + #[Optional('country_code')] + public ?string $countryCode; + + #[Optional] + public ?string $display; + + #[Optional] + public ?string $region; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?string $city = null, + ?string $country = null, + ?string $countryCode = null, + ?string $display = null, + ?string $region = null, + ): self { + $self = new self; + + null !== $city && $self['city'] = $city; + null !== $country && $self['country'] = $country; + null !== $countryCode && $self['countryCode'] = $countryCode; + null !== $display && $self['display'] = $display; + null !== $region && $self['region'] = $region; + + return $self; + } + + public function withCity(string $city): self + { + $self = clone $this; + $self['city'] = $city; + + return $self; + } + + public function withCountry(string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + + public function withCountryCode(string $countryCode): self + { + $self = clone $this; + $self['countryCode'] = $countryCode; + + return $self; + } + + public function withDisplay(string $display): self + { + $self = clone $this; + $self['display'] = $display; + + return $self; + } + + public function withRegion(string $region): self + { + $self = clone $this; + $self['region'] = $region; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Name.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Name.php new file mode 100644 index 0000000..5b552b0 --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentCandidateMatch/Person/Name.php @@ -0,0 +1,77 @@ + */ + use SdkModel; + + #[Optional] + public ?string $first; + + #[Optional] + public ?string $full; + + #[Optional] + public ?string $last; + + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + */ + public static function with( + ?string $first = null, + ?string $full = null, + ?string $last = null + ): self { + $self = new self; + + null !== $first && $self['first'] = $first; + null !== $full && $self['full'] = $full; + null !== $last && $self['last'] = $last; + + return $self; + } + + public function withFirst(string $first): self + { + $self = clone $this; + $self['first'] = $first; + + return $self; + } + + public function withFull(string $full): self + { + $self = clone $this; + $self['full'] = $full; + + return $self; + } + + public function withLast(string $last): self + { + $self = clone $this; + $self['last'] = $last; + + return $self; + } +} diff --git a/src/People/PersonEnrichResponse/Match_/PersonEnrichmentNotFoundMatch.php b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentNotFoundMatch.php new file mode 100644 index 0000000..720b91a --- /dev/null +++ b/src/People/PersonEnrichResponse/Match_/PersonEnrichmentNotFoundMatch.php @@ -0,0 +1,104 @@ + */ + use SdkModel; + + /** @var 'not_found' $status */ + #[Required] + public string $status = 'not_found'; + + /** @var null|null $person */ + #[Required] + public null $person; + + /** @var null|null $score */ + #[Required] + public null $score; + + /** + * `new PersonEnrichmentNotFoundMatch()` is missing required properties by the API. + * + * To enforce required parameters use + * ``` + * PersonEnrichmentNotFoundMatch::with(person: ..., score: ...) + * ``` + * + * Otherwise ensure the following setters are called + * + * ``` + * (new PersonEnrichmentNotFoundMatch)->withPerson(...)->withScore(...) + * ``` + */ + public function __construct() + { + $this->initialize(); + } + + /** + * Construct an instance from the required parameters. + * + * You must use named parameters to construct any parameters with a default value. + * + * @param null|null $person + * @param null|null $score + */ + public static function with(null $person, null $score): self + { + $self = new self; + + $self['person'] = $person; + $self['score'] = $score; + + return $self; + } + + /** + * @param null|null $person + */ + public function withPerson(null $person): self + { + $self = clone $this; + $self['person'] = $person; + + return $self; + } + + /** + * @param null|null $score + */ + public function withScore(null $score): self + { + $self = clone $this; + $self['score'] = $score; + + return $self; + } + + /** + * @param 'not_found' $status + */ + public function withStatus(string $status): self + { + $self = clone $this; + $self['status'] = $status; + + return $self; + } +} diff --git a/src/ServiceContracts/BatchContract.php b/src/ServiceContracts/BatchContract.php index dd2416b..60b8484 100644 --- a/src/ServiceContracts/BatchContract.php +++ b/src/ServiceContracts/BatchContract.php @@ -5,18 +5,20 @@ namespace ContextDev\ServiceContracts; use ContextDev\Batch\BatchCancelResponse; +use ContextDev\Batch\BatchDeleteResponse; use ContextDev\Batch\BatchGetResponse; use ContextDev\Batch\BatchGetResultsResponse; use ContextDev\Batch\BatchListParams\SearchType; use ContextDev\Batch\BatchListParams\Status; use ContextDev\Batch\BatchListResponse; -use ContextDev\Batch\BatchSubmitParams\Identifiers; +use ContextDev\Batch\BatchSubmitParams\Input\Crawl; +use ContextDev\Batch\BatchSubmitParams\Input\Scrape; use ContextDev\Batch\BatchSubmitResponse; use ContextDev\Core\Exceptions\APIException; use ContextDev\RequestOptions; /** - * @phpstan-import-type IdentifiersShape from \ContextDev\Batch\BatchSubmitParams\Identifiers + * @phpstan-import-type InputShape from \ContextDev\Batch\BatchSubmitParams\Input * @phpstan-import-type RequestOpts from \ContextDev\RequestOptions */ interface BatchContract @@ -57,6 +59,19 @@ public function list( RequestOptions|array|null $requestOptions = null, ): BatchListResponse; + /** + * @api + * + * @param string $batchID ID of the batch to retrieve or cancel + * @param RequestOpts|null $requestOptions + * + * @throws APIException + */ + public function delete( + string $batchID, + RequestOptions|array|null $requestOptions = null + ): BatchDeleteResponse; + /** * @api * @@ -90,17 +105,19 @@ public function getResults( /** * @api * - * @param Identifiers|IdentifiersShape $identifiers Known identifiers for the person. At least one identifier is required. - * @param list $tags Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. - * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + * @param InputShape $input body param: Choose a URL list or a site crawl + * @param list $tags Body param: Tags stored on the batch. Filter the batch list by them later. + * @param string $webhookURL body param: URL notified when the batch finishes + * @param string $idempotencyKey Header param: Any string unique to this submission. Retries with the same key return the original batch. * @param RequestOpts|null $requestOptions * * @throws APIException */ public function submit( - Identifiers|array $identifiers, + Scrape|array|Crawl $input, ?array $tags = null, - ?int $timeoutMs = null, + ?string $webhookURL = null, + ?string $idempotencyKey = null, RequestOptions|array|null $requestOptions = null, ): BatchSubmitResponse; } diff --git a/src/ServiceContracts/BatchRawContract.php b/src/ServiceContracts/BatchRawContract.php index 39e7673..435e884 100644 --- a/src/ServiceContracts/BatchRawContract.php +++ b/src/ServiceContracts/BatchRawContract.php @@ -5,6 +5,7 @@ namespace ContextDev\ServiceContracts; use ContextDev\Batch\BatchCancelResponse; +use ContextDev\Batch\BatchDeleteResponse; use ContextDev\Batch\BatchGetResponse; use ContextDev\Batch\BatchGetResultsParams; use ContextDev\Batch\BatchGetResultsResponse; @@ -51,6 +52,21 @@ public function list( RequestOptions|array|null $requestOptions = null, ): BaseResponse; + /** + * @api + * + * @param string $batchID ID of the batch to retrieve or cancel + * @param RequestOpts|null $requestOptions + * + * @return BaseResponse + * + * @throws APIException + */ + public function delete( + string $batchID, + RequestOptions|array|null $requestOptions = null + ): BaseResponse; + /** * @api * diff --git a/src/ServiceContracts/ParseContract.php b/src/ServiceContracts/ParseContract.php index c724b43..77448f0 100644 --- a/src/ServiceContracts/ParseContract.php +++ b/src/ServiceContracts/ParseContract.php @@ -32,7 +32,7 @@ interface ParseContract * @param Extension|value-of $extension query param: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md, py, rtf, jpg, png, or txt * @param IncludeImagesShape $includeImages Query param: Include image references in Markdown output * @param IncludeLinksShape $includeLinks Query param: Preserve hyperlinks in Markdown output - * @param OcrShape $ocr Query param: When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback. + * @param OcrShape $ocr Query param: When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * @param Pdf|PdfShape $pdf Query param: PDF page-range options as a JSON object, e.g. {"start": 2, "end": 5}. * @param ShortenBase64ImagesShape $shortenBase64Images Query param: Shorten base64-encoded image data in the Markdown output * @param list $tags Query param: Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters. diff --git a/src/ServiceContracts/PeopleContract.php b/src/ServiceContracts/PeopleContract.php new file mode 100644 index 0000000..68d1b1f --- /dev/null +++ b/src/ServiceContracts/PeopleContract.php @@ -0,0 +1,49 @@ + $education + * @param Location|LocationShape $location + * @param Name|NameShape $name + * @param list $socialURLs + * @param list $tags Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. + * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + * @param RequestOpts|null $requestOptions + * + * @throws APIException + */ + public function enrich( + Company|array|null $company = null, + ?array $education = null, + ?string $email = null, + Location|array|null $location = null, + Name|array|null $name = null, + ?array $socialURLs = null, + ?array $tags = null, + ?int $timeoutMs = null, + RequestOptions|array|null $requestOptions = null, + ): PersonEnrichResponse; +} diff --git a/src/ServiceContracts/PeopleRawContract.php b/src/ServiceContracts/PeopleRawContract.php new file mode 100644 index 0000000..15b65a5 --- /dev/null +++ b/src/ServiceContracts/PeopleRawContract.php @@ -0,0 +1,32 @@ +|PersonEnrichParams $params + * @param RequestOpts|null $requestOptions + * + * @return BaseResponse + * + * @throws APIException + */ + public function enrich( + array|PersonEnrichParams $params, + RequestOptions|array|null $requestOptions = null, + ): BaseResponse; +} diff --git a/src/ServiceContracts/WebContract.php b/src/ServiceContracts/WebContract.php index 575855f..beefa33 100644 --- a/src/ServiceContracts/WebContract.php +++ b/src/ServiceContracts/WebContract.php @@ -411,6 +411,7 @@ public function webScrapeMd( * @param string $domain Domain to build a sitemap for * @param array $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache. * @param int $maxLinks Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000. + * @param string $search Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1. * @param string $sitemapURL Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps. * @param list $tags Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters. * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). @@ -424,6 +425,7 @@ public function webScrapeSitemap( string $domain, ?array $headers = null, int $maxLinks = 10000, + ?string $search = null, ?string $sitemapURL = null, ?array $tags = null, ?int $timeoutMs = null, diff --git a/src/Services/BatchRawService.php b/src/Services/BatchRawService.php index c2088aa..d3f4c6d 100644 --- a/src/Services/BatchRawService.php +++ b/src/Services/BatchRawService.php @@ -5,6 +5,7 @@ namespace ContextDev\Services; use ContextDev\Batch\BatchCancelResponse; +use ContextDev\Batch\BatchDeleteResponse; use ContextDev\Batch\BatchGetResponse; use ContextDev\Batch\BatchGetResultsParams; use ContextDev\Batch\BatchGetResultsResponse; @@ -13,7 +14,6 @@ use ContextDev\Batch\BatchListParams\Status; use ContextDev\Batch\BatchListResponse; use ContextDev\Batch\BatchSubmitParams; -use ContextDev\Batch\BatchSubmitParams\Identifiers; use ContextDev\Batch\BatchSubmitResponse; use ContextDev\Client; use ContextDev\Core\Contracts\BaseResponse; @@ -23,7 +23,9 @@ use ContextDev\ServiceContracts\BatchRawContract; /** - * @phpstan-import-type IdentifiersShape from \ContextDev\Batch\BatchSubmitParams\Identifiers + * Scrape many pages or crawl a site asynchronously. + * + * @phpstan-import-type InputShape from \ContextDev\Batch\BatchSubmitParams\Input * @phpstan-import-type RequestOpts from \ContextDev\RequestOptions */ final class BatchRawService implements BatchRawContract @@ -100,6 +102,31 @@ public function list( ); } + /** + * @api + * + * Permanently delete a finished batch and its stored results. Active batches must settle first. + * + * @param string $batchID ID of the batch to retrieve or cancel + * @param RequestOpts|null $requestOptions + * + * @return BaseResponse + * + * @throws APIException + */ + public function delete( + string $batchID, + RequestOptions|array|null $requestOptions = null + ): BaseResponse { + // @phpstan-ignore-next-line return.type + return $this->client->request( + method: 'delete', + path: ['batch/%1$s', $batchID], + options: $requestOptions, + convert: BatchDeleteResponse::class, + ); + } + /** * @api * @@ -161,12 +188,13 @@ public function getResults( /** * @api * - * Retrieve and normalize a person profile from identifiers. + * Scrape 25K URLs or crawl large websites asynchronously. * * @param array{ - * identifiers: Identifiers|IdentifiersShape, + * input: InputShape, * tags?: list, - * timeoutMs?: int, + * webhookURL?: string, + * idempotencyKey?: string, * }|BatchSubmitParams $params * @param RequestOpts|null $requestOptions * @@ -182,12 +210,20 @@ public function submit( $params, $requestOptions, ); + $header_params = ['idempotencyKey' => 'Idempotency-Key']; // @phpstan-ignore-next-line return.type return $this->client->request( method: 'post', - path: 'people/retrieve', - body: (object) $parsed, + path: 'batch/submit', + headers: Util::array_transform_keys( + array_intersect_key($parsed, array_flip(array_keys($header_params))), + $header_params, + ), + body: (object) array_diff_key( + $parsed, + array_flip(array_keys($header_params)) + ), options: $options, convert: BatchSubmitResponse::class, ); diff --git a/src/Services/BatchService.php b/src/Services/BatchService.php index 4e6cbe6..6d56fd9 100644 --- a/src/Services/BatchService.php +++ b/src/Services/BatchService.php @@ -5,12 +5,14 @@ namespace ContextDev\Services; use ContextDev\Batch\BatchCancelResponse; +use ContextDev\Batch\BatchDeleteResponse; use ContextDev\Batch\BatchGetResponse; use ContextDev\Batch\BatchGetResultsResponse; use ContextDev\Batch\BatchListParams\SearchType; use ContextDev\Batch\BatchListParams\Status; use ContextDev\Batch\BatchListResponse; -use ContextDev\Batch\BatchSubmitParams\Identifiers; +use ContextDev\Batch\BatchSubmitParams\Input\Crawl; +use ContextDev\Batch\BatchSubmitParams\Input\Scrape; use ContextDev\Batch\BatchSubmitResponse; use ContextDev\Client; use ContextDev\Core\Exceptions\APIException; @@ -19,7 +21,9 @@ use ContextDev\ServiceContracts\BatchContract; /** - * @phpstan-import-type IdentifiersShape from \ContextDev\Batch\BatchSubmitParams\Identifiers + * Scrape many pages or crawl a site asynchronously. + * + * @phpstan-import-type InputShape from \ContextDev\Batch\BatchSubmitParams\Input * @phpstan-import-type RequestOpts from \ContextDev\RequestOptions */ final class BatchService implements BatchContract @@ -98,6 +102,26 @@ public function list( return $response->parse(); } + /** + * @api + * + * Permanently delete a finished batch and its stored results. Active batches must settle first. + * + * @param string $batchID ID of the batch to retrieve or cancel + * @param RequestOpts|null $requestOptions + * + * @throws APIException + */ + public function delete( + string $batchID, + RequestOptions|array|null $requestOptions = null + ): BatchDeleteResponse { + // @phpstan-ignore-next-line argument.type + $response = $this->raw->delete($batchID, requestOptions: $requestOptions); + + return $response->parse(); + } + /** * @api * @@ -147,26 +171,29 @@ public function getResults( /** * @api * - * Retrieve and normalize a person profile from identifiers. + * Scrape 25K URLs or crawl large websites asynchronously. * - * @param Identifiers|IdentifiersShape $identifiers Known identifiers for the person. At least one identifier is required. - * @param list $tags Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. - * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + * @param InputShape $input body param: Choose a URL list or a site crawl + * @param list $tags Body param: Tags stored on the batch. Filter the batch list by them later. + * @param string $webhookURL body param: URL notified when the batch finishes + * @param string $idempotencyKey Header param: Any string unique to this submission. Retries with the same key return the original batch. * @param RequestOpts|null $requestOptions * * @throws APIException */ public function submit( - Identifiers|array $identifiers, + Scrape|array|Crawl $input, ?array $tags = null, - ?int $timeoutMs = null, + ?string $webhookURL = null, + ?string $idempotencyKey = null, RequestOptions|array|null $requestOptions = null, ): BatchSubmitResponse { $params = Util::removeNulls( [ - 'identifiers' => $identifiers, + 'input' => $input, 'tags' => $tags, - 'timeoutMs' => $timeoutMs, + 'webhookURL' => $webhookURL, + 'idempotencyKey' => $idempotencyKey, ], ); diff --git a/src/Services/BrandRawService.php b/src/Services/BrandRawService.php index fdb05fd..46c7292 100644 --- a/src/Services/BrandRawService.php +++ b/src/Services/BrandRawService.php @@ -123,7 +123,7 @@ public function retrieveSimplified( /** * @api * - * Search brands by name or domain and get back up to 10 lightweight matches (domain, name, logo), most popular first: by Tranco rank, then market cap for brands outside the Tranco list, with text relevance breaking ties. Matching is prefix-based with no typo tolerance, so it is suited to autocomplete. Only brands already in the Context.dev index are returned — use /brand/retrieve to fetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit per request on the Free and Starter plans. + * Search brands by name or domain and get back up to 10 lightweight matches (domain, name, logo). Name matches rank ahead of domain matches; within each group the most popular brands come first: by Tranco rank, then market cap for brands outside the Tranco list, with text relevance breaking ties. Matching is prefix-based with no typo tolerance, so it is suited to autocomplete. Only brands already in the Context.dev index are returned — use /brand/retrieve to fetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit per request on the Free and Starter plans. * * @param array{query: string, tags?: list}|BrandSearchParams $params * @param RequestOpts|null $requestOptions diff --git a/src/Services/BrandService.php b/src/Services/BrandService.php index fc9c8ee..d9d72a4 100644 --- a/src/Services/BrandService.php +++ b/src/Services/BrandService.php @@ -154,7 +154,7 @@ public function retrieveSimplified( /** * @api * - * Search brands by name or domain and get back up to 10 lightweight matches (domain, name, logo), most popular first: by Tranco rank, then market cap for brands outside the Tranco list, with text relevance breaking ties. Matching is prefix-based with no typo tolerance, so it is suited to autocomplete. Only brands already in the Context.dev index are returned — use /brand/retrieve to fetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit per request on the Free and Starter plans. + * Search brands by name or domain and get back up to 10 lightweight matches (domain, name, logo). Name matches rank ahead of domain matches; within each group the most popular brands come first: by Tranco rank, then market cap for brands outside the Tranco list, with text relevance breaking ties. Matching is prefix-based with no typo tolerance, so it is suited to autocomplete. Only brands already in the Context.dev index are returned — use /brand/retrieve to fetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit per request on the Free and Starter plans. * * @param string $query Search term, matched against brand names and domains by prefix (e.g. 'nike', 'nike.com', 'nik'). * @param list $tags Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters. diff --git a/src/Services/ParseService.php b/src/Services/ParseService.php index 8d6df77..545b7b7 100644 --- a/src/Services/ParseService.php +++ b/src/Services/ParseService.php @@ -50,7 +50,7 @@ public function __construct(private Client $client) * @param Extension|value-of $extension query param: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md, py, rtf, jpg, png, or txt * @param IncludeImagesShape $includeImages Query param: Include image references in Markdown output * @param IncludeLinksShape $includeLinks Query param: Preserve hyperlinks in Markdown output - * @param OcrShape $ocr Query param: When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback. + * @param OcrShape $ocr Query param: When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * @param Pdf|PdfShape $pdf Query param: PDF page-range options as a JSON object, e.g. {"start": 2, "end": 5}. * @param ShortenBase64ImagesShape $shortenBase64Images Query param: Shorten base64-encoded image data in the Markdown output * @param list $tags Query param: Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters. diff --git a/src/Services/PeopleRawService.php b/src/Services/PeopleRawService.php new file mode 100644 index 0000000..14b280f --- /dev/null +++ b/src/Services/PeopleRawService.php @@ -0,0 +1,73 @@ +, + * email?: string, + * location?: Location|LocationShape, + * name?: Name|NameShape, + * socialURLs?: list, + * tags?: list, + * timeoutMs?: int, + * }|PersonEnrichParams $params + * @param RequestOpts|null $requestOptions + * + * @return BaseResponse + * + * @throws APIException + */ + public function enrich( + array|PersonEnrichParams $params, + RequestOptions|array|null $requestOptions = null, + ): BaseResponse { + [$parsed, $options] = PersonEnrichParams::parseRequest( + $params, + $requestOptions, + ); + + // @phpstan-ignore-next-line return.type + return $this->client->request( + method: 'post', + path: 'people/enrich', + body: (object) $parsed, + options: $options, + convert: PersonEnrichResponse::class, + ); + } +} diff --git a/src/Services/PeopleService.php b/src/Services/PeopleService.php new file mode 100644 index 0000000..9051917 --- /dev/null +++ b/src/Services/PeopleService.php @@ -0,0 +1,85 @@ +raw = new PeopleRawService($client); + } + + /** + * @api + * + * Finds and normalizes the best available person candidate from additive identity clues, then assigns an identity match score from 0 to 100. Available on all paid plans. Successful requests cost 20 credits. Disposable and free email addresses (like gmail.com, yahoo.com) will throw a 422 error. + * + * @param Company|CompanyShape $company + * @param list $education + * @param Location|LocationShape $location + * @param Name|NameShape $name + * @param list $socialURLs + * @param list $tags Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. + * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). + * @param RequestOpts|null $requestOptions + * + * @throws APIException + */ + public function enrich( + Company|array|null $company = null, + ?array $education = null, + ?string $email = null, + Location|array|null $location = null, + Name|array|null $name = null, + ?array $socialURLs = null, + ?array $tags = null, + ?int $timeoutMs = null, + RequestOptions|array|null $requestOptions = null, + ): PersonEnrichResponse { + $params = Util::removeNulls( + [ + 'company' => $company, + 'education' => $education, + 'email' => $email, + 'location' => $location, + 'name' => $name, + 'socialURLs' => $socialURLs, + 'tags' => $tags, + 'timeoutMs' => $timeoutMs, + ], + ); + + // @phpstan-ignore-next-line argument.type + $response = $this->raw->enrich(params: $params, requestOptions: $requestOptions); + + return $response->parse(); + } +} diff --git a/src/Services/WebRawService.php b/src/Services/WebRawService.php index 3a1a7f4..953b50d 100644 --- a/src/Services/WebRawService.php +++ b/src/Services/WebRawService.php @@ -473,6 +473,10 @@ public function webScrapeImages( * * Scrapes the given URL into LLM usable Markdown. Inspect key_metadata on JSON responses from a recognized API key; use error_code to distinguish stable failure categories. * + * ### YouTube + * + * YouTube URLs return the video or channel itself rather than the surrounding player and navigation chrome. A URL addressing a single video (`/watch`, `youtu.be`, `/shorts`, `/embed`, `/live`) returns its title, channel, duration, view count, keywords, full description, and the transcript when the video has captions that can be retrieved; videos without captions return everything except the transcript. A channel URL (`/channel/UC…`, `/@handle`, `/c/…`, `/user/…`) returns its name, handle, subscriber count, video count, and full description. When `includeImages=true`, video responses also include the thumbnail and channel responses include the avatar. Costs the same as any other scrape. + * * ### Billing & errors * * | HTTP status | Billed? | Meaning | @@ -482,6 +486,7 @@ public function webScrapeImages( * | 401 / 403 | No | Invalid/disabled key, insufficient permissions, or credits exhausted; inspect error_code | * | 404 | No | Target page returned or fingerprinted as not found | * | 408 | No | Request timed out | + * | 413 | No | Target content exceeds the maximum supported size (20 MB) | * | 415 | No | Unsupported content type | * | 429 | No | Per-minute rate limit exceeded; honor Retry-After | * | 500 | No | Internal error | @@ -534,12 +539,13 @@ public function webScrapeMd( /** * @api * - * Crawl an entire website's sitemap and return all discovered page URLs. + * Crawl an entire website's sitemap and return all discovered page URLs. Pass `search` to have the crawled sitemap filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1. * * @param array{ * domain: string, * headers?: array, * maxLinks?: int, + * search?: string, * sitemapURL?: string, * tags?: list, * timeoutMs?: int, diff --git a/src/Services/WebService.php b/src/Services/WebService.php index 30d0899..27e6e7e 100644 --- a/src/Services/WebService.php +++ b/src/Services/WebService.php @@ -584,6 +584,10 @@ public function webScrapeImages( * * Scrapes the given URL into LLM usable Markdown. Inspect key_metadata on JSON responses from a recognized API key; use error_code to distinguish stable failure categories. * + * ### YouTube + * + * YouTube URLs return the video or channel itself rather than the surrounding player and navigation chrome. A URL addressing a single video (`/watch`, `youtu.be`, `/shorts`, `/embed`, `/live`) returns its title, channel, duration, view count, keywords, full description, and the transcript when the video has captions that can be retrieved; videos without captions return everything except the transcript. A channel URL (`/channel/UC…`, `/@handle`, `/c/…`, `/user/…`) returns its name, handle, subscriber count, video count, and full description. When `includeImages=true`, video responses also include the thumbnail and channel responses include the avatar. Costs the same as any other scrape. + * * ### Billing & errors * * | HTTP status | Billed? | Meaning | @@ -593,6 +597,7 @@ public function webScrapeImages( * | 401 / 403 | No | Invalid/disabled key, insufficient permissions, or credits exhausted; inspect error_code | * | 404 | No | Target page returned or fingerprinted as not found | * | 408 | No | Request timed out | + * | 413 | No | Target content exceeds the maximum supported size (20 MB) | * | 415 | No | Unsupported content type | * | 429 | No | Per-minute rate limit exceeded; honor Retry-After | * | 500 | No | Internal error | @@ -674,11 +679,12 @@ public function webScrapeMd( /** * @api * - * Crawl an entire website's sitemap and return all discovered page URLs. + * Crawl an entire website's sitemap and return all discovered page URLs. Pass `search` to have the crawled sitemap filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1. * * @param string $domain Domain to build a sitemap for * @param array $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache. * @param int $maxLinks Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000. + * @param string $search Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1. * @param string $sitemapURL Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps. * @param list $tags Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters. * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). @@ -692,6 +698,7 @@ public function webScrapeSitemap( string $domain, ?array $headers = null, int $maxLinks = 10000, + ?string $search = null, ?string $sitemapURL = null, ?array $tags = null, ?int $timeoutMs = null, @@ -704,6 +711,7 @@ public function webScrapeSitemap( 'domain' => $domain, 'headers' => $headers, 'maxLinks' => $maxLinks, + 'search' => $search, 'sitemapURL' => $sitemapURL, 'tags' => $tags, 'timeoutMs' => $timeoutMs, diff --git a/src/Version.php b/src/Version.php index 9050d10..fc11686 100644 --- a/src/Version.php +++ b/src/Version.php @@ -5,5 +5,5 @@ namespace ContextDev; // x-release-please-start-version -const VERSION = '2.8.0'; +const VERSION = '2.9.0'; // x-release-please-end diff --git a/src/Web/WebSearchResponse/Result/Markdown/Code.php b/src/Web/WebSearchResponse/Result/Markdown/Code.php index 38dfcb4..688183f 100644 --- a/src/Web/WebSearchResponse/Result/Markdown/Code.php +++ b/src/Web/WebSearchResponse/Result/Markdown/Code.php @@ -15,6 +15,8 @@ enum Code: string case TIMEOUT = 'TIMEOUT'; + case CONTENT_TOO_LARGE = 'CONTENT_TOO_LARGE'; + case WEBSITE_ACCESS_ERROR = 'WEBSITE_ACCESS_ERROR'; case ERROR = 'ERROR'; diff --git a/src/Web/WebWebCrawlMdParams/Pdf.php b/src/Web/WebWebCrawlMdParams/Pdf.php index d412e2e..443d177 100644 --- a/src/Web/WebWebCrawlMdParams/Pdf.php +++ b/src/Web/WebWebCrawlMdParams/Pdf.php @@ -27,7 +27,7 @@ final class Pdf implements BaseModel public ?int $end; /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. */ #[Optional] public ?bool $ocr; @@ -82,7 +82,7 @@ public function withEnd(int $end): self } /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. */ public function withOcr(bool $ocr): self { diff --git a/src/Web/WebWebScrapeHTMLParams/Pdf.php b/src/Web/WebWebScrapeHTMLParams/Pdf.php index 4bea0c5..0523390 100644 --- a/src/Web/WebWebScrapeHTMLParams/Pdf.php +++ b/src/Web/WebWebScrapeHTMLParams/Pdf.php @@ -38,7 +38,7 @@ final class Pdf implements BaseModel public ?int $end; /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @var OcrVariants|null $ocr */ @@ -46,7 +46,7 @@ final class Pdf implements BaseModel public bool|string|null $ocr; /** - * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned. + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. * * @var ShouldParseVariants|null $shouldParse */ @@ -100,7 +100,7 @@ public function withEnd(int $end): self } /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @param OcrShape $ocr */ @@ -113,7 +113,7 @@ public function withOcr(bool|UnionMember1|string $ocr): self } /** - * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned. + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. * * @param ShouldParseShape $shouldParse */ diff --git a/src/Web/WebWebScrapeHTMLParams/Pdf/Ocr.php b/src/Web/WebWebScrapeHTMLParams/Pdf/Ocr.php index 43dc659..074bc18 100644 --- a/src/Web/WebWebScrapeHTMLParams/Pdf/Ocr.php +++ b/src/Web/WebWebScrapeHTMLParams/Pdf/Ocr.php @@ -10,7 +10,7 @@ use ContextDev\Web\WebWebScrapeHTMLParams\Pdf\Ocr\UnionMember1; /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @phpstan-type OcrVariants = bool|value-of * @phpstan-type OcrShape = OcrVariants diff --git a/src/Web/WebWebScrapeHTMLParams/Pdf/ShouldParse.php b/src/Web/WebWebScrapeHTMLParams/Pdf/ShouldParse.php index 22883a0..ea0a236 100644 --- a/src/Web/WebWebScrapeHTMLParams/Pdf/ShouldParse.php +++ b/src/Web/WebWebScrapeHTMLParams/Pdf/ShouldParse.php @@ -10,7 +10,7 @@ use ContextDev\Web\WebWebScrapeHTMLParams\Pdf\ShouldParse\UnionMember1; /** - * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned. + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. * * @phpstan-type ShouldParseVariants = bool|value-of * @phpstan-type ShouldParseShape = ShouldParseVariants diff --git a/src/Web/WebWebScrapeMdParams.php b/src/Web/WebWebScrapeMdParams.php index 8c65497..99db851 100644 --- a/src/Web/WebWebScrapeMdParams.php +++ b/src/Web/WebWebScrapeMdParams.php @@ -24,6 +24,10 @@ /** * Scrapes the given URL into LLM usable Markdown. Inspect key_metadata on JSON responses from a recognized API key; use error_code to distinguish stable failure categories. * + * ### YouTube + * + * YouTube URLs return the video or channel itself rather than the surrounding player and navigation chrome. A URL addressing a single video (`/watch`, `youtu.be`, `/shorts`, `/embed`, `/live`) returns its title, channel, duration, view count, keywords, full description, and the transcript when the video has captions that can be retrieved; videos without captions return everything except the transcript. A channel URL (`/channel/UC…`, `/@handle`, `/c/…`, `/user/…`) returns its name, handle, subscriber count, video count, and full description. When `includeImages=true`, video responses also include the thumbnail and channel responses include the avatar. Costs the same as any other scrape. + * * ### Billing & errors * * | HTTP status | Billed? | Meaning | @@ -33,6 +37,7 @@ * | 401 / 403 | No | Invalid/disabled key, insufficient permissions, or credits exhausted; inspect error_code | * | 404 | No | Target page returned or fingerprinted as not found | * | 408 | No | Request timed out | + * | 413 | No | Target content exceeds the maximum supported size (20 MB) | * | 415 | No | Unsupported content type | * | 429 | No | Per-minute rate limit exceeded; honor Retry-After | * | 500 | No | Internal error | diff --git a/src/Web/WebWebScrapeMdParams/Pdf.php b/src/Web/WebWebScrapeMdParams/Pdf.php index 701103d..a712278 100644 --- a/src/Web/WebWebScrapeMdParams/Pdf.php +++ b/src/Web/WebWebScrapeMdParams/Pdf.php @@ -38,7 +38,7 @@ final class Pdf implements BaseModel public ?int $end; /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @var OcrVariants|null $ocr */ @@ -46,7 +46,7 @@ final class Pdf implements BaseModel public bool|string|null $ocr; /** - * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned. + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. * * @var ShouldParseVariants|null $shouldParse */ @@ -100,7 +100,7 @@ public function withEnd(int $end): self } /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @param OcrShape $ocr */ @@ -113,7 +113,7 @@ public function withOcr(bool|UnionMember1|string $ocr): self } /** - * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned. + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. * * @param ShouldParseShape $shouldParse */ diff --git a/src/Web/WebWebScrapeMdParams/Pdf/Ocr.php b/src/Web/WebWebScrapeMdParams/Pdf/Ocr.php index b7b34fa..d88785e 100644 --- a/src/Web/WebWebScrapeMdParams/Pdf/Ocr.php +++ b/src/Web/WebWebScrapeMdParams/Pdf/Ocr.php @@ -10,7 +10,7 @@ use ContextDev\Web\WebWebScrapeMdParams\Pdf\Ocr\UnionMember1; /** - * When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback. + * When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs. * * @phpstan-type OcrVariants = bool|value-of * @phpstan-type OcrShape = OcrVariants diff --git a/src/Web/WebWebScrapeMdParams/Pdf/ShouldParse.php b/src/Web/WebWebScrapeMdParams/Pdf/ShouldParse.php index 0e05273..1d63915 100644 --- a/src/Web/WebWebScrapeMdParams/Pdf/ShouldParse.php +++ b/src/Web/WebWebScrapeMdParams/Pdf/ShouldParse.php @@ -10,7 +10,7 @@ use ContextDev\Web\WebWebScrapeMdParams\Pdf\ShouldParse\UnionMember1; /** - * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned. + * When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned. * * @phpstan-type ShouldParseVariants = bool|value-of * @phpstan-type ShouldParseShape = ShouldParseVariants diff --git a/src/Web/WebWebScrapeSitemapParams.php b/src/Web/WebWebScrapeSitemapParams.php index 05d8790..0ce7273 100644 --- a/src/Web/WebWebScrapeSitemapParams.php +++ b/src/Web/WebWebScrapeSitemapParams.php @@ -12,7 +12,7 @@ use ContextDev\Web\WebWebScrapeSitemapParams\Zdr; /** - * Crawl an entire website's sitemap and return all discovered page URLs. + * Crawl an entire website's sitemap and return all discovered page URLs. Pass `search` to have the crawled sitemap filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1. * * @see ContextDev\Services\WebService::webScrapeSitemap() * @@ -20,6 +20,7 @@ * domain: string, * headers?: array|null, * maxLinks?: int|null, + * search?: string|null, * sitemapURL?: string|null, * tags?: list|null, * timeoutMs?: int|null, @@ -53,6 +54,12 @@ final class WebWebScrapeSitemapParams implements BaseModel #[Optional] public ?int $maxLinks; + /** + * Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1. + */ + #[Optional] + public ?string $search; + /** * Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps. */ @@ -119,6 +126,7 @@ public static function with( string $domain, ?array $headers = null, ?int $maxLinks = null, + ?string $search = null, ?string $sitemapURL = null, ?array $tags = null, ?int $timeoutMs = null, @@ -131,6 +139,7 @@ public static function with( null !== $headers && $self['headers'] = $headers; null !== $maxLinks && $self['maxLinks'] = $maxLinks; + null !== $search && $self['search'] = $search; null !== $sitemapURL && $self['sitemapURL'] = $sitemapURL; null !== $tags && $self['tags'] = $tags; null !== $timeoutMs && $self['timeoutMs'] = $timeoutMs; @@ -175,6 +184,17 @@ public function withMaxLinks(int $maxLinks): self return $self; } + /** + * Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1. + */ + public function withSearch(string $search): self + { + $self = clone $this; + $self['search'] = $search; + + return $self; + } + /** * Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps. */ diff --git a/src/Web/WebWebScrapeSitemapResponse.php b/src/Web/WebWebScrapeSitemapResponse.php index 4d606f4..ea97f61 100644 --- a/src/Web/WebWebScrapeSitemapResponse.php +++ b/src/Web/WebWebScrapeSitemapResponse.php @@ -47,7 +47,7 @@ final class WebWebScrapeSitemapResponse implements BaseModel public bool $success; /** - * Array of discovered page URLs from the sitemap (max 500). + * Discovered page URLs from the sitemap, up to `maxLinks`. When `search` is set these are only the matching pages, most relevant first. * * @var list $urls */ @@ -149,7 +149,7 @@ public function withSuccess(bool $success): self } /** - * Array of discovered page URLs from the sitemap (max 500). + * Discovered page URLs from the sitemap, up to `maxLinks`. When `search` is set these are only the matching pages, most relevant first. * * @param list $urls */ diff --git a/tests/Services/BatchTest.php b/tests/Services/BatchTest.php index 1da9404..e215546 100644 --- a/tests/Services/BatchTest.php +++ b/tests/Services/BatchTest.php @@ -3,6 +3,7 @@ namespace Tests\Services; use ContextDev\Batch\BatchCancelResponse; +use ContextDev\Batch\BatchDeleteResponse; use ContextDev\Batch\BatchGetResponse; use ContextDev\Batch\BatchGetResultsResponse; use ContextDev\Batch\BatchListResponse; @@ -58,6 +59,19 @@ public function testList(): void $this->assertInstanceOf(BatchListResponse::class, $result); } + #[Test] + public function testDelete(): void + { + if (UnsupportedMockTests::$skip) { + $this->markTestSkipped('Mock server tests are disabled'); + } + + $result = $this->client->batch->delete('batch_9f2c8a'); + + // @phpstan-ignore-next-line method.alreadyNarrowedType + $this->assertInstanceOf(BatchDeleteResponse::class, $result); + } + #[Test] public function testCancel(): void { @@ -91,7 +105,18 @@ public function testSubmit(): void $this->markTestSkipped('Mock server tests are disabled'); } - $result = $this->client->batch->submit(identifiers: []); + $result = $this->client->batch->submit( + input: [ + 'data' => [ + 'format' => 'markdown', + 'urls' => [ + ['url' => 'https://example.com/products/anvil'], + ['url' => 'https://example.com/products/hammer'], + ], + ], + 'mode' => 'scrape', + ], + ); // @phpstan-ignore-next-line method.alreadyNarrowedType $this->assertInstanceOf(BatchSubmitResponse::class, $result); @@ -105,11 +130,42 @@ public function testSubmitWithOptionalParams(): void } $result = $this->client->batch->submit( - identifiers: [ - 'linkedinURL' => 'https://www.linkedin.com/in/yahia-bakour/', + input: [ + 'data' => [ + 'format' => 'markdown', + 'urls' => [ + [ + 'url' => 'https://example.com/products/anvil', + 'itemID' => 'sku-1', + 'meta' => ['category' => 'bar'], + ], + [ + 'url' => 'https://example.com/products/hammer', + 'itemID' => 'sku-2', + 'meta' => ['foo' => 'bar'], + ], + ], + 'options' => [ + 'country' => 'de', + 'excludeSelectors' => ['x'], + 'includeImages' => true, + 'includeLinks' => true, + 'includeSelectors' => ['x'], + 'maxAgeMs' => 0, + 'pdf' => [ + 'end' => 1, 'ocr' => 'true', 'shouldParse' => 'true', 'start' => 1, + ], + 'settleAnimations' => true, + 'shortenBase64Images' => true, + 'useMainContentOnly' => true, + 'waitForMs' => 0, + ], + ], + 'mode' => 'scrape', ], - tags: ['production', 'team-alpha'], - timeoutMs: 1000, + tags: ['docs', 'competitor'], + webhookURL: 'webhookUrl', + idempotencyKey: 'Idempotency-Key', ); // @phpstan-ignore-next-line method.alreadyNarrowedType diff --git a/tests/Services/PeopleTest.php b/tests/Services/PeopleTest.php new file mode 100644 index 0000000..42724a9 --- /dev/null +++ b/tests/Services/PeopleTest.php @@ -0,0 +1,43 @@ +client = $client; + } + + #[Test] + public function testEnrich(): void + { + if (UnsupportedMockTests::$skip) { + $this->markTestSkipped('Mock server tests are disabled'); + } + + $result = $this->client->people->enrich(); + + // @phpstan-ignore-next-line method.alreadyNarrowedType + $this->assertInstanceOf(PersonEnrichResponse::class, $result); + } +} diff --git a/tests/Services/WebTest.php b/tests/Services/WebTest.php index c0febb0..eb41d56 100644 --- a/tests/Services/WebTest.php +++ b/tests/Services/WebTest.php @@ -411,6 +411,7 @@ public function testWebScrapeSitemapWithOptionalParams(): void domain: 'xxx', headers: ['foo' => 'J!'], maxLinks: 1, + search: 'help center and troubleshooting articles', sitemapURL: 'https://example.com', tags: ['production', 'team-alpha'], timeoutMs: 1,