New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

sushidev/fairu-sdk

Laravel SDK for Fairu GraphQL API
2,930

Larablocks Analysis

sushidev/fairu-sdk works with Laravel 10 to 13 (latest release v1.4.0, Nov 4, 2026).

Recommendation checks

Solid choice

Solid choice: maintained and up to date, meets 2 of 4 checks; below the bar for Recommended on use.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Nov 4, 2026)
  • 2,373 downloads a month (needs 10,000)
  • 0 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Nov 4, 2026.
  • 8 releases in the last 12 months.
  • First released: Dec 30, 2025.
  • Monthly downloads: 2,373.
  • 2 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 27, 2026.

Install
composer require sushidev/fairu-sdk
Latest Version:v1.4.0
PHP:^8.2
Laravel:10 – 13
License:MIT
Last Updated:Nov 26, 2026
Links: GitHub  ·  Packagist
Maintainer: sushidev

Fairu SDK for Laravel

A comprehensive Laravel SDK for the Fairu GraphQL API with dynamic fragments, caching, and full type support.

Requirements

  • PHP 8.2+ (PHP 8.3+ for Laravel 13)
  • Laravel 10, 11, 12, or 13

Installation

composer require sushidev/fairu-sdk

The package will auto-register its service provider and facade.

Publish Configuration

php artisan vendor:publish --tag=fairu-config

Configuration

Add the following to your .env file:

FAIRU_URL=https://fairu.app
FAIRU_TOKEN=your-api-token

Full Configuration Options

// config/fairu.php
return [
    'base_url' => env('FAIRU_URL', 'https://fairu.app'),
    'token' => env('FAIRU_TOKEN'),
    'timeout' => 30,

    'retry' => [
        'times' => 3,
        'sleep' => 100,
    ],

    'cache' => [
        'enabled' => true,
        'store' => null, // null = default cache store
        'prefix' => 'fairu_',
        'ttl' => [
            'tenant' => 3600,
            'roles' => 3600,
            'assets' => 300,
            'default' => 600,
        ],
    ],
];

Current API and radio

$client->api() provides every query and mutation in the versioned schema (167 roots), alongside the existing resource helpers. Field/argument names are checked against the catalog and values remain GraphQL variables. Permissions and tenant isolation are enforced by Fairu.

$public = new \SushiDev\Fairu\FairuClient('https://fairu.app', null);
$station = $public->api()->publicStation($channelId);
$state = $public->api()->publicRadio($publicListeningToken);

// Trusted server only: requires a workspace token with channel permissions.
$client->api()->controlRadio($radioId, 'PAUSE', $currentRevision);
$client->api()->execute('updateFairuVideoChannelEpisode', [
    'channel' => $channelId, 'id' => $episodeId,
    'input' => ['title' => 'Episode', 'ad_clips' => null, 'ads_enabled' => false],
]);

Default catalog selections are intentionally bounded; pass a third selection string to execute() for additional fields. Nullable overrides and false are preserved. Configured retries apply only to transient query failures; forbidden requests and mutations are not replayed automatically.

The schema includes fairu-app #728; new radio operations require that backend release. tests/fixtures/schema-source.json records its provenance. Laravel 13 is tested with the latest stable framework resolution, while Laravel 12 remains in CI.

Test fixtures

tests/fixtures/api.json contains synthetic variables and responses for every operation. The contract tests use Guzzle's MockHandler, validate all generated documents and predefined fragments against the schema, and never contact production. Fixtures are test data, not a public fake-client mode.

Run composer schema:sync -- /path/to/schema.graphql /path/to/source-info.json to regenerate the catalog and fixtures offline. The metadata must include source_repository and a full source_commit; counts are derived automatically. Then run composer test. GraphQL validation is a development dependency only.

Important: UUIDs

All IDs in the Fairu API are UUIDs (Universally Unique Identifiers). This applies to all resources:

  • Assets
  • Folders
  • Galleries
  • Copyrights
  • Licenses
  • Users
  • Roles
  • Disks
  • Tenants

Example:

$assetId = '550e8400-e29b-41d4-a716-446655440000';
$asset = Fairu::assets()->find($assetId);

Basic Usage

Queries

use SushiDev\Fairu\Facades\Fairu;

// Health Check
$status = Fairu::health()->check();

// Get single asset
$asset = Fairu::assets()->find('uuid');
$asset = Fairu::assets()->findByPath('/images/logo.png');

// Get multiple assets
$assets = Fairu::assets()->findMany(['uuid-1', 'uuid-2']);

// Search assets
$results = Fairu::assets()->search('logo', page: 1, perPage: 20);

// List assets in folder
$assets = Fairu::assets()->all(folderId: 'folder-uuid', page: 1, perPage: 20);

// Get folder content (folders + assets)
$content = Fairu::folders()->content('folder-uuid');
$content->folders; // Array of Folder objects
$content->assets;  // Array of Asset objects

// Get tenant info
$tenant = Fairu::tenant()->get();

// List sub-tenants of the current tenant
$subTenants = Fairu::tenant()->subTenants();
foreach ($subTenants as $subTenant) {
    $subTenant->getId();
    $subTenant->getName();
    $subTenant->getParentId();
    $subTenant->isSubTenant(); // true
}

// List galleries
$galleries = Fairu::galleries()->all(['tenant-uuid'], from: '2024-01-01');

// Other queries
$copyrights = Fairu::copyrights()->all();
$licenses = Fairu::licenses()->all();
$workflows = Fairu::workflows()->all();
$users = Fairu::users()->all();
$roles = Fairu::roles()->all();
$disks = Fairu::disks()->all();

Mutations

use SushiDev\Fairu\Facades\Fairu;
use SushiDev\Fairu\DTOs\FileDTO;
use SushiDev\Fairu\DTOs\FolderDTO;
use SushiDev\Fairu\DTOs\GalleryDTO;
use SushiDev\Fairu\Enums\UploadType;

// Upload a file
$uploadLink = Fairu::uploads()->createLink(
    filename: 'photo.jpg',
    type: UploadType::STANDARD,
    folderId: 'folder-uuid',
    alt: 'Photo description'
);
// Use $uploadLink->getUrl() to upload your file via PUT request

// Update asset metadata
$asset = Fairu::assetMutations()->update(
    FileDTO::make()
        ->id('asset-uuid')
        ->alt('New alt text')
        ->description('Updated description')
        ->copyrightIds(['copyright-uuid'])
);

// Visible watermark: true on, false off, null inherits, uncalled leaves it alone
Fairu::assetMutations()->update(FileDTO::make()->id('asset-uuid')->watermark(true));
Fairu::folderMutations()->update(FolderDTO::make()->id('folder-uuid')->watermark(null));

// Set it for many assets at once (at most 2000); returns the number updated
$count = Fairu::assetMutations()->setWatermark(['asset-uuid-1', 'asset-uuid-2'], false);

// Delete asset
Fairu::assetMutations()->delete('asset-uuid');

// Move asset to another folder
Fairu::assetMutations()->move('asset-uuid', 'new-folder-uuid');

// Create folder
$folder = Fairu::folderMutations()->create(
    FolderDTO::make()
        ->name('New Folder')
        ->parent('parent-uuid')
);

// Create gallery
$gallery = Fairu::galleryMutations()->create(
    GalleryDTO::make()
        ->name('Event 2024')
        ->folderId('folder-uuid')
        ->date(now())
        ->location('Berlin')
);

// Create a sub-tenant of the current tenant.
// The returned API key is only shown once - store it securely.
$result = Fairu::tenantMutations()->createSubTenant('Client Workspace');
$subTenantId = $result->getId();
$apiKey = $result->getApiKey();
$createdAt = $result->getCreatedAt();

// Detach a sub-tenant, making it a fully independent tenant
$detached = Fairu::tenantMutations()->detachSubTenant($subTenantId);

Fragments

Fragments allow you to customize which fields are returned from the API.

Predefined Fragments

Each resource type has three predefined variants: minimal, default, and full.

use SushiDev\Fairu\Facades\Fairu;

// Use predefined fragments
$asset = Fairu::assets()->find('uuid', Fairu::fragments()->asset('minimal'));
$asset = Fairu::assets()->find('uuid', Fairu::fragments()->asset('full'));

Custom Fragments with FragmentBuilder

use SushiDev\Fairu\Fragments\FragmentBuilder;

// Build custom fragment
$fragment = FragmentBuilder::for('FairuAsset')
    ->select(['id', 'name', 'mime', 'url', 'width', 'height', 'blurhash'])
    ->with('copyrights', fn($f) => $f->select(['id', 'name', 'email']))
    ->with('licenses', fn($f) => $f->select(['id', 'name', 'type', 'start', 'end']))
    ->build();

$asset = Fairu::assets()->find('uuid', $fragment);

// With arguments (e.g., for URL parameters)
$fragment = FragmentBuilder::for('FairuAsset')
    ->select(['id', 'name'])
    ->withArguments('url', ['width' => 800, 'height' => 600, 'quality' => 80], [])
    ->build();

Register Custom Fragments

// In a service provider
Fairu::fragments()->register('my_asset_card',
    FragmentBuilder::for('FairuAsset')
        ->select(['id', 'name', 'url', 'blurhash', 'width', 'height'])
        ->build()
);

// Use it later
$asset = Fairu::assets()->find('uuid', Fairu::fragments()->get('my_asset_card'));

Caching

The SDK supports Laravel's cache system for API responses.

// Enable caching for a query (uses config TTL)
$tenant = Fairu::tenant()->cached()->get();

// Custom TTL (in seconds)
$roles = Fairu::roles()->cached(ttl: 3600)->all();

// Force fresh data (bypass cache)
$tenant = Fairu::tenant()->fresh()->get();

// Clear cached data
Fairu::tenant()->forget('cache-key');

DTOs (Data Transfer Objects)

All input types have fluent DTOs for type-safe data handling.

use SushiDev\Fairu\DTOs\FileDTO;
use SushiDev\Fairu\DTOs\FolderDTO;
use SushiDev\Fairu\DTOs\CopyrightDTO;
use SushiDev\Fairu\DTOs\LicenseDTO;
use SushiDev\Fairu\DTOs\GalleryDTO;
use SushiDev\Fairu\DTOs\DiskDTO;
use SushiDev\Fairu\DTOs\DiskCredentialsDTO;
use SushiDev\Fairu\Enums\DiskType;
use SushiDev\Fairu\Enums\LicenseType;

// File DTO
$file = FileDTO::make()
    ->id('uuid')
    ->name('photo.jpg')
    ->alt('Description')
    ->caption('Caption text')
    ->description('Full description')
    ->focalPoint('50-50')
    ->copyrightIds(['cr-1', 'cr-2'])
    ->licenseIds(['lic-1']);

// Copyright DTO
$copyright = CopyrightDTO::make()
    ->name('John Doe Photography')
    ->email('john@example.com')
    ->phone('+1234567890')
    ->website('https://johndoe.com')
    ->active(true);

// License DTO
$license = LicenseDTO::make()
    ->name('Annual License')
    ->type(LicenseType::PERIOD)
    ->copyrightId('copyright-uuid')
    ->start(now())
    ->end(now()->addYear())
    ->days(365);

// Disk DTO with credentials
$credentials = DiskCredentialsDTO::make()
    ->key('aws-access-key')
    ->secret('aws-secret')
    ->bucket('my-bucket')
    ->region('eu-west-1');

$disk = DiskDTO::make()
    ->name('S3 Backup')
    ->type(DiskType::S3)
    ->folderId('folder-uuid')
    ->credentials($credentials)
    ->active(true);

Response Objects

All API responses are wrapped in typed response objects.

$asset = Fairu::assets()->find('uuid');

// Access properties
$asset->id;
$asset->name;
$asset->mime;
$asset->url;
$asset->width;
$asset->height;
$asset->blurhash;

// Helper methods
$asset->isImage();      // true for image/* mime types
$asset->isVideo();      // true for video/* mime types
$asset->isPdf();        // true for application/pdf
$asset->getAspectRatio(); // width/height ratio

// Nested relations
$asset->getCopyrights(); // Array of Copyright objects
$asset->getLicenses();   // Array of License objects

// Array access
$asset['name'];
$asset['url'];

// JSON serialization
json_encode($asset);

Paginated Lists

$results = Fairu::assets()->search('logo');

// Access items
$results->items();       // Array of Asset objects
$results->first();       // First item
$results->last();        // Last item
$results->isEmpty();     // Check if empty
$results->count();       // Items on current page

// Pagination info
$results->total();       // Total items across all pages
$results->currentPage(); // Current page number
$results->lastPage();    // Last page number
$results->perPage();     // Items per page
$results->hasMorePages(); // Has more pages?

// Iteration
foreach ($results as $asset) {
    echo $asset->name;
}

// Collection-like methods
$ids = $results->pluck('id');
$filtered = $results->filter(fn($a) => $a->isImage());
$mapped = $results->map(fn($a) => $a->name);

Enums

All GraphQL enums are available as PHP 8.1 backed enums.

use SushiDev\Fairu\Enums\UploadType;
use SushiDev\Fairu\Enums\SortingDirection;
use SushiDev\Fairu\Enums\LicenseType;
use SushiDev\Fairu\Enums\WorkflowStatus;
use SushiDev\Fairu\Enums\WorkflowType;
use SushiDev\Fairu\Enums\UserStatus;
use SushiDev\Fairu\Enums\DiskType;
use SushiDev\Fairu\Enums\WebhookType;
use SushiDev\Fairu\Enums\CustomDomainStatus;
use SushiDev\Fairu\Enums\GallerySortingField;
use SushiDev\Fairu\Enums\VideoVersions;
use SushiDev\Fairu\Enums\DmcaStatus;
use SushiDev\Fairu\Enums\UploadShareLinkExpiration;
use SushiDev\Fairu\Enums\PdfSignatureRequestStatus;

// Usage
$type = UploadType::STANDARD;
$direction = SortingDirection::DESC;

// From string
$status = WorkflowStatus::from('PROCESSING');
$status = WorkflowStatus::tryFrom('INVALID'); // null

Error Handling

use SushiDev\Fairu\Exceptions\FairuException;
use SushiDev\Fairu\Exceptions\AuthenticationException;
use SushiDev\Fairu\Exceptions\GraphQLException;

try {
    $asset = Fairu::assets()->find('uuid');
} catch (AuthenticationException $e) {
    // Invalid or missing token (401)
} catch (GraphQLException $e) {
    // GraphQL errors
    $errors = $e->getGraphQLErrors();
    $first = $e->getFirstError();

    if ($e->hasValidationErrors()) {
        $validation = $e->getValidationErrors();
    }
} catch (FairuException $e) {
    // General API errors
}

Events

The SDK dispatches events for debugging and logging.

use SushiDev\Fairu\Events\QueryExecuted;
use SushiDev\Fairu\Events\MutationExecuted;

// In EventServiceProvider
protected $listen = [
    QueryExecuted::class => [
        LogQueryListener::class,
    ],
    MutationExecuted::class => [
        LogMutationListener::class,
    ],
];

// Listener
class LogQueryListener
{
    public function handle(QueryExecuted $event)
    {
        Log::debug('Fairu Query', [
            'query' => $event->query,
            'variables' => $event->variables,
            'response' => $event->response,
        ]);
    }
}

Multipart Uploads

For large files, use multipart uploads.

// Initialize multipart upload
$init = Fairu::uploads()->initMultipart(
    filename: 'large-video.mp4',
    folderId: 'folder-uuid',
    fileSize: 104857600, // 100MB
    contentType: 'video/mp4'
);

$fileId = $init->getId();
$uploadId = $init->getUploadId();

// Get upload URL for each part
$parts = [];
for ($i = 1; $i <= $totalParts; $i++) {
    $partInfo = Fairu::uploads()->getMultipartPartUrl($fileId, $uploadId, $i);

    // Upload part to $partInfo['url'] via PUT
    // Collect ETag from response
    $parts[] = [
        'partNumber' => $i,
        'etag' => $etag,
    ];
}

// Complete upload
$result = Fairu::uploads()->completeMultipart($fileId, $uploadId, $parts);

// Or abort if needed
Fairu::uploads()->abortMultipart($fileId, $uploadId);

File Proxy

The File Proxy provides image transformation and optimized file delivery.

Configuration

FAIRU_FILE_PROXY_URL=https://files.fairu.app

Basic Usage

use SushiDev\Fairu\Facades\Fairu;

// Generate a URL for an asset
$url = Fairu::fileProxy()->url('asset-uuid', 'image.jpg')->toUrl();

// From an Asset object
$asset = Fairu::assets()->find('asset-uuid');
$url = Fairu::fileProxy()->fromAsset($asset)->toUrl();

Image Transformations

use SushiDev\Fairu\Facades\Fairu;
use SushiDev\Fairu\Enums\FileProxyFit;
use SushiDev\Fairu\Enums\FileProxyFormat;

// Resize image
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->width(800)
    ->height(600)
    ->toUrl();

// Set dimensions with aspect ratio
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->dimensions(1200, 800)
    ->toUrl();

// Change format and quality
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->format(FileProxyFormat::WEBP)
    ->quality(85)
    ->toUrl();

// Shorthand format methods
$url = Fairu::fileProxy()->url('asset-uuid', 'photo.jpg')->webp()->toUrl();
$url = Fairu::fileProxy()->url('asset-uuid', 'photo.jpg')->jpg()->toUrl();
$url = Fairu::fileProxy()->url('asset-uuid', 'photo.jpg')->png()->toUrl();

// Fit modes
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->dimensions(400, 400)
    ->cover()  // Scale and crop to fill (default)
    ->toUrl();

$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->dimensions(400, 400)
    ->contain()  // Maintain aspect ratio within dimensions
    ->toUrl();

// Focal point for smart cropping
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->dimensions(400, 400)
    ->focal(50, 30)  // x=50%, y=30%
    ->toUrl();

// With zoom level
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'photo.jpg')
    ->focal(50, 50, 2.0)  // x, y, zoom
    ->toUrl();

Video Features

use SushiDev\Fairu\Enums\VideoVersions;

// Extract video frame at timestamp
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'video.mp4')
    ->timestamp('00:00:05.000')
    ->toUrl();

// Video quality version
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'video.mp4')
    ->videoVersion(VideoVersions::HIGH)
    ->toUrl();

// HLS streaming URL
$hlsUrl = Fairu::fileProxy()->hlsUrl('tenant-uuid', 'asset-uuid');

Other Options

// Raw file download (no processing)
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'document.eps')
    ->raw()
    ->toUrl();

// Process SVG to raster
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'logo.svg')
    ->processSvg()
    ->width(200)
    ->toUrl();

// Signed URLs for restricted content
$url = Fairu::fileProxy()
    ->url('asset-uuid', 'file.jpg')
    ->signature($hmacSignature, $signatureDate)
    ->toUrl();

Skipping the visible watermark

If the tenant uses the visible watermark (logo overlay), server-rendered URLs can skip it with withoutWatermark(). Pass the tenant's watermark key (fwm_..., shown in the Fairu tenant settings). The SDK appends wm=0 and a signature (wms) over the final query when the URL is built, so call order does not matter. Removing wm=0/wms or changing any parameter of the URL brings the watermark back.

$url = Fairu::fileProxy()
    ->url('asset-uuid', 'hero.jpg')
    ->width(1600)
    ->withoutWatermark(config('services.fairu.watermark_key'))
    ->toUrl();
// https://files.fairu.app/asset-uuid/hero.jpg?width=1600&wm=0&wms=...

Keep the key server-side; never build these URLs in the browser. An invalid key throws an InvalidArgumentException.

Utility Methods

// Check if file exists
$exists = Fairu::fileProxy()->exists('asset-uuid');

// Get image dimensions
$meta = Fairu::fileProxy()->meta('asset-uuid');
// Returns: ['width' => 1920, 'height' => 1080]

// Health check
$healthy = Fairu::fileProxy()->health();

Available Parameters

Parameter Range Description
width 1-6000 Output width in pixels
height 1-6000 Output height in pixels
quality 1-100 JPEG/WebP quality (default: 95)
format jpg, png, webp Output format (default: webp)
fit cover, contain Resize mode (default: cover)
focal x-y-zoom Smart crop focal point
wm / wms 0 + signature Skip the visible watermark (set via withoutWatermark())

Testing

composer test

License

MIT License. See LICENSE for details.

Schema refreshes are staged and validated before publishing artifacts. A failed refresh preserves the previous consistent snapshot. Identical query/mutation field names use qualified keys (query.field / mutation.field) instead of overwriting each other. Default provisioning selections retain one-time credentials; public channel reads include effective episode advertising plans.

Queued podcast imports can be read through fairuPodcastImport(id:) with channel-read permission in the same workspace; other-workspace and missing IDs both return null. Total-file-size results use a numeric scalar that supports sums beyond the GraphQL 32-bit integer range. Both depend on the matching #728 backend release.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

431,187,642 4,660

Version History

Version Released PHP Laravel License
v1.4.0 ^8.2 ^10.0|^11.0|^12.0|^13.0 MIT
v1.3.0 ^8.2 ^10.0|^11.0|^12.0|^13.0 MIT
v1.2.0 ^8.2 ^10.0|^11.0|^12.0 MIT
v1.1.3 ^8.2 ^10.0|^11.0|^12.0 MIT
v1.1.2 ^8.2 ^10.0|^11.0|^12.0 MIT