diff --git a/.github/release-notes/v1.0.0.md b/.github/release-notes/v1.0.0.md new file mode 100644 index 0000000..566a291 --- /dev/null +++ b/.github/release-notes/v1.0.0.md @@ -0,0 +1,33 @@ +## moderation-api/sdk-php 1.0.0 + +The first stable version of the PHP SDK. Read the breaking changes before you upgrade. + +```bash +composer require moderation-api/sdk-php:^1.0 +``` + +### PHP-specific changes + +- Requires PHP 8.2 or later (was 8.1). +- The namespace is `ModerationApi` (was `ModerationAPI`). Create the client with `ModerationApi\ModerationApi::builder()->setSecurity($key)->build()`. +- Requests are typed objects, for example `new Operations\SubmitContentRequest(content: new Operations\TextRequest(text: '...'))`, and responses carry the result in `->object`. +- Verify webhooks with `ModerationApi\WebhookSignature::constructEvent($payload, $signature)`. +### What's new + +- **Covers the whole API**, including the management API (`projects`, `channels`), wordlists and the review queue. +- **Automatic pagination.** List methods return an iterator that fetches the next page for you. +- **Clear errors.** One error class per HTTP status (`BadRequestError`, `NotFoundError`, `RateLimitError`, ...). Every error has a specific `code` (for example `invalid_api_key`, `quota_exceeded` or `author_not_found`), a `request_id` and a `doc_url`. See [Errors](https://docs.moderationapi.com/api-reference/errors). +- **Retries** with exponential backoff on `429` and `5xx`, and timeouts per client or per request. +- **Webhook verification** that reads the secret from `MODAPI_WEBHOOK_SECRET`. + +### Breaking changes + +The SDK is now generated from our OpenAPI spec with a new generator. Most calls keep their names, but check these: + +- **List responses** are `{ data, pagination }` instead of a plain array or a resource-specific shape, and list methods take `page` and `pageSize`. +- **Errors** have a new body: `code` is the specific error code, not the HTTP category. The old `data` field is gone. +- **Renamed:** `account.list` is now `account.retrieve`, and `actions.execute.execute` is now `actions.execute`. +- **Removed:** `actions.execute.executeByID` (use `actions.execute` with `actionId` or `actionKey`), `auth.*`, and `content.stream` (see [Real-time voice](https://docs.moderationapi.com/content-moderation/real-time-voice)). +- **Organization keys** work only with `projects` and `channels`; project keys work with everything else. Use one client per key. See the README. + +The license is unchanged: Apache-2.0. diff --git a/.github/workflows/publish-packagist.yml b/.github/workflows/publish-packagist.yml index 10817ee..c702ced 100644 --- a/.github/workflows/publish-packagist.yml +++ b/.github/workflows/publish-packagist.yml @@ -1,19 +1,50 @@ # Maintained in moderation-api/sdk-generator (custom/php). Edits here are overwritten. -# Packagist reads the version from the release tag. +# Every push to main whose package version has no release tag yet publishes +# that version and creates the GitHub release (notes: .github/release-notes/vX.Y.Z.md +# if present, otherwise generated from the merged pull requests). +# Packagist reads the version from the tag, so the release comes first. name: Publish Packagist on: - release: - types: [published] + push: + branches: [main] workflow_dispatch: +concurrency: release + permissions: - contents: read + contents: write jobs: publish: runs-on: ubuntu-latest steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Read the version + run: | + echo "VERSION=$(sed -n 's/^ version: //p' .speakeasy/gen.yaml | head -n 1)" >> "$GITHUB_ENV" + - name: Check for an unreleased version + id: version + run: | + echo "VERSION=${VERSION}" >> "$GITHUB_ENV" + if git ls-remote --exit-code --tags origin "refs/tags/v${VERSION}" >/dev/null; then + echo "v${VERSION} is already released." + echo "release=false" >> "$GITHUB_OUTPUT" + else + echo "release=true" >> "$GITHUB_OUTPUT" + fi + - name: Create the GitHub release + if: steps.version.outputs.release == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + notes=".github/release-notes/v${VERSION}.md" + if [ -f "$notes" ]; then + gh release create "v${VERSION}" --target "$GITHUB_SHA" --title "v${VERSION}" --notes-file "$notes" + else + gh release create "v${VERSION}" --target "$GITHUB_SHA" --title "v${VERSION}" --generate-notes + fi - name: Tell Packagist to update + if: steps.version.outputs.release == 'true' run: |- curl --fail-with-body -X POST -H 'Content-Type: application/json' "https://packagist.org/api/update-package?username=${PACKAGIST_USERNAME}&apiToken=${PACKAGIST_SAFE_KEY}" -d '{"repository":"https://github.com/moderation-api/sdk-php"}' env: diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 4a65012..6e03ad3 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,7 +1,7 @@ lockVersion: 2.0.0 id: 0199302d-9d48-4081-a021-a66e7a11ce41 management: - docChecksum: 3320e8867e978fb3c091936a85b4b990 + docChecksum: 9e61a5512adcd4b1e0a74112ed775731 docVersion: 1.1.0 speakeasyVersion: internal generationVersion: internal