mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-04 22:59:41 +00:00
Requests with the user's token threw a bare ResourceException with a message like "… for resource [Anikeen\Id\Resources\Order]" and no error code, while app requests threw ApiException. Both throw ApiException now: status (also getCode()), Anikeen ID's error code and message, isNotFound(), isConflict(), isTemporary(). Failed lists throw CollectionException, now a subclass of ApiException. A request without a response (connection refused, timeout) throws ApiException with status 0 instead of a Guzzle exception. ApiException extends ResourceException, so existing catch blocks keep working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3.7 KiB
3.7 KiB
CLAUDE.md
Guidance for Claude Code (and other contributors) working in this repository.
What this is
anikeen/id is the public PHP client for the Anikeen ID API, shipped as a Laravel package
(Laravel 11–13, PHP 8.2+). It covers OAuth/Socialite login, an API token guard, and the billing
API (subscriptions, orders, checkout sessions, shipments, invoices, webhooks). This is a public
repo published on Packagist: never commit secrets, internal hostnames or customer data.
Commands
composer install
composer test # vendor/bin/phpunit
vendor/bin/phpunit --filter AppSubscriptionsTest
composer docs # regenerate README.md from README.stub
CI (.github/workflows/tests.yml) runs PHPUnit on PHP 8.3 and 8.4.
Layout
src/Id/AnikeenId.php– the API client (singleton, facadeAnikeenId). Readsconfig('services.anikeen.*');mode=stagingswitches to the staging base URL unlessbase_urlis set.request()wraps Guzzle and returns aResult.src/Id/Billable.php– trait for the app's user model; composes theConcerns/Manages*traits. Its API caches are declared properties on purpose (undeclared ones would be treated as Eloquent attributes and breaksave()). Add a new cache property there when a concern caches.src/Id/Concerns/– one trait per API area. Traits onAnikeenIdact as the app/client; traits onBillableact for one user.src/Id/Resources/–BaseResource(single object) andBaseCollection(lists, built via::builder()). Failed requests throwApiException::fromResult()(CollectionExceptionfor lists), no response::unreachable(),confirmation_requiredaConfirmationRequiredException. All extendResourceException.src/Id/Resources/App*– "app" variants that use the app's own client-credentials token (AnikeenId::asApp(),Support/AppRequest) instead of the user's token, for trusted apps. They must not send any request until a method is called.src/Id/Auth/,Providers/AnikeenIdServiceProvider.php,Http/Middleware/– theanikeenguard driver and user provider, JWT validation (Helpers/JwtParser.phpwith the bundledoauth-public*.key), scope middleware.src/Id/Webhooks/– signature verification (Webhook::constructEvent) andEventTypeconstants.src/Support/Query.php– query-string builder.generator/generate-docs.php– reflects the public methods ofAnikeenIdandBillabletraits into the README.
Conventions
- README: edit
README.stub, neverREADME.mddirectly, then runcomposer docs. The<!-- GENERATED-DOCS -->marker is replaced with the method reference. Commit both files. - New endpoints: add a method to the matching
Concerns/Manages*trait (or a resource class), document request attributes with anarray{…}PHPDoc shape and a short description per key, and add an example toREADME.stubwhen it is a new feature. - Tests: extend
Anikeen\Id\Tests\TestCase(Orchestra Testbench). No live API: queue responses with$this->respond($status, $body)(GuzzleMockHandler) and assert the sent requests via$this->sent/$this->sentJson($i)– method, path,Authorizationheader and JSON body. The app token is faked asapp-token. - Compatibility: this is a library used by several apps. Keep public method signatures backwards compatible; add optional parameters instead of changing existing ones.
- Code, comments, docs and commit messages in English. Commit subjects are short, imperative,
sentence case (e.g. "Ship orders: shipments with delivery notes"). Work happens on feature
branches merged via PR into
main.