dbp/relay-sublibrary-bundle
Installation:
composer require dbp/relay-sublibrary-bundle
Publish the bundle configuration:
php artisan vendor:publish --provider="Dbp\RelaySublibraryBundle\RelaySublibraryBundle" --tag="config"
Configuration:
config/relay-sublibrary.php to define:
alma_api_key (shared ALMA API key)sub_orgs (array of sub-organization IDs/keys)default_sub_org (fallback sub-org for unauthenticated requests).env with:
RELAY_SUBLIBRARY_ALMA_API_KEY=your_key_here
First Use Case: Fetch a sub-org’s holdings via a controller:
use Dbp\RelaySublibraryBundle\Service\AlmaService;
public function getHoldings(AlmaService $almaService, string $subOrgKey) {
$holdings = $almaService->getHoldings($subOrgKey);
return response()->json($holdings);
}
Sub-Organization Isolation:
{subOrgKey} (e.g., /api/{subOrgKey}/holdings).
Use middleware to inject the sub-org context:
// app/Http/Middleware/SubOrgMiddleware.php
public function handle($request, Closure $next) {
$subOrgKey = $request->route('subOrgKey');
app('relay-sublibrary')->setCurrentSubOrg($subOrgKey);
return $next($request);
}
AlmaService to delegate ALMA API calls with auto-scoping:
$service->createBook($subOrgKey, $bookData);
API Integration:
config/relay-sublibrary.php to throttle requests per sub-org:
'rate_limits' => [
'holdings' => ['max' => 100, 'period' => 'minute'],
],
Dbp\RelaySublibraryBundle\Exception\AlmaException for custom responses:
try {
$service->updateBudget($subOrgKey, $data);
} catch (AlmaException $e) {
return response()->json(['error' => $e->getSubOrgMessage()], 400);
}
Frontend Sync:
// app/GraphQL/Mutations/CreateBook.php
public function resolve($root, array $args) {
return app('relay-sublibrary')->createBook($args['subOrgKey'], $args['input']);
}
AppServiceProvider:
$this->app->bind(AlmaService::class, function ($app) {
return new AlmaService($app['config']['relay-sublibrary']);
});
// app/Listeners/LogSubOrgActivity.php
public function handle(SubOrgChanged $event) {
Log::info("Switched to sub-org: {$event->subOrgKey}");
}
API Key Leaks:
alma_api_key in config or logs..env and validate keys via middleware:
// app/Http/Middleware/ValidateAlmaKey.php
public function handle($request, Closure $next) {
if (empty(config('relay-sublibrary.alma_api_key'))) {
throw new \RuntimeException('ALMA API key not configured.');
}
return $next($request);
}
Sub-Org Mismatches:
subOrgKey="org1" but backend processes as org2.SubOrgMiddleware log:
Log::debug("Current sub-org: " . app('relay-sublibrary')->getCurrentSubOrg());
Rate Limiting:
rate_limits per sub-org dynamically:
$service->setRateLimit($subOrgKey, ['max' => 200, 'period' => 'hour']);
config/relay-sublibrary.php:
'debug' => env('APP_DEBUG', false),
Dbp\RelaySublibraryBundle\Service\AlmaHttpClient to inspect raw ALMA responses:
$client = app(AlmaHttpClient::class);
$client->setDebug(true); // Logs requests/responses to storage/logs/alma_debug.log
Custom ALMA Endpoints:
AlmaService to add methods for unsupported ALMA API calls:
// app/Services/ExtendedAlmaService.php
public function customAlmaCall($subOrgKey, $endpoint, $data) {
return $this->httpClient->post(
"https://api.alma.exlibrisgroup.com/{$endpoint}",
$this->preparePayload($subOrgKey, $data)
);
}
Sub-Org Validation:
SubOrgValidator to enforce custom rules (e.g., budget caps):
// app/Services/CustomSubOrgValidator.php
public function validate($subOrgKey, $action) {
if ($action === 'update_budget' && $this->isOverBudget($subOrgKey)) {
throw new \InvalidArgumentException("Budget exceeded for {$subOrgKey}.");
}
return parent::validate($subOrgKey, $action);
}
Webhook Integration:
// app/Listeners/SyncAlmaWebhook.php
public function handle(AlmaWebhookReceived $event) {
$subOrgKey = $event->payload['sub_org_key'];
$this->syncHoldings($subOrgKey);
}
How can I help you explore Laravel packages today?