|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Fleetbase\RegistryBridge\Http\Resources; |
| 4 | + |
| 5 | +use Fleetbase\Http\Resources\FleetbaseResource; |
| 6 | + |
| 7 | +class PublicRegistryExtension extends FleetbaseResource |
| 8 | +{ |
| 9 | + /** |
| 10 | + * Transform the resource into an array. |
| 11 | + * |
| 12 | + * Only exposes fields that are safe for public consumption. |
| 13 | + * No UUIDs, no Stripe data, no internal IDs, no bundle file relationships, |
| 14 | + * no purchase/install relationships, no sensitive company data. |
| 15 | + * |
| 16 | + * @param \Illuminate\Http\Request $request |
| 17 | + * |
| 18 | + * @return array |
| 19 | + */ |
| 20 | + public function toArray($request) |
| 21 | + { |
| 22 | + return [ |
| 23 | + // Core identity (public_id only, no uuid) |
| 24 | + 'id' => $this->public_id, |
| 25 | + 'slug' => $this->slug, |
| 26 | + 'name' => $this->name, |
| 27 | + 'subtitle' => $this->subtitle, |
| 28 | + 'description' => $this->description, |
| 29 | + 'promotional_text' => $this->promotional_text, |
| 30 | + 'fa_icon' => $this->fa_icon, |
| 31 | + 'icon_url' => $this->icon_url, |
| 32 | + 'tags' => $this->tags ?? [], |
| 33 | + 'languages' => $this->languages ?? [], |
| 34 | + 'primary_language' => $this->primary_language, |
| 35 | + 'version' => $this->version, |
| 36 | + 'status' => $this->status, |
| 37 | + |
| 38 | + // URLs |
| 39 | + 'website_url' => $this->website_url, |
| 40 | + 'repo_url' => $this->repo_url, |
| 41 | + 'support_url' => $this->support_url, |
| 42 | + 'privacy_policy_url' => $this->privacy_policy_url, |
| 43 | + 'tos_url' => $this->tos_url, |
| 44 | + 'copyright' => $this->copyright, |
| 45 | + |
| 46 | + // Pricing (public-safe fields only, no Stripe IDs) |
| 47 | + 'payment_required' => $this->payment_required, |
| 48 | + 'price' => $this->price, |
| 49 | + 'sale_price' => $this->sale_price, |
| 50 | + 'on_sale' => $this->on_sale, |
| 51 | + 'currency' => $this->currency, |
| 52 | + 'subscription_required' => $this->subscription_required, |
| 53 | + |
| 54 | + // Flags |
| 55 | + 'core_extension' => $this->core_extension, |
| 56 | + 'self_managed' => $this->self_managed, |
| 57 | + |
| 58 | + // Stats |
| 59 | + 'installs_count' => $this->installs_count ?? 0, |
| 60 | + |
| 61 | + // Timestamps |
| 62 | + 'published_at' => $this->published_at, |
| 63 | + 'created_at' => $this->created_at, |
| 64 | + 'updated_at' => $this->updated_at, |
| 65 | + |
| 66 | + // Publisher (minimal safe fields only) |
| 67 | + 'publisher' => $this->when($this->relationLoaded('company') && $this->company, [ |
| 68 | + 'name' => data_get($this, 'company.name'), |
| 69 | + 'slug' => data_get($this, 'company.slug'), |
| 70 | + 'type' => data_get($this, 'company.type'), |
| 71 | + 'website_url' => data_get($this, 'company.website_url'), |
| 72 | + 'description' => data_get($this, 'company.description'), |
| 73 | + ]), |
| 74 | + |
| 75 | + // Category (safe fields only, no UUIDs) |
| 76 | + 'category' => $this->when($this->relationLoaded('category') && $this->category, [ |
| 77 | + 'id' => data_get($this, 'category.public_id'), |
| 78 | + 'name' => data_get($this, 'category.name'), |
| 79 | + 'slug' => data_get($this, 'category.slug'), |
| 80 | + 'description' => data_get($this, 'category.description'), |
| 81 | + 'icon' => data_get($this, 'category.icon'), |
| 82 | + 'icon_color' => data_get($this, 'category.icon_color'), |
| 83 | + 'tags' => data_get($this, 'category.tags', []), |
| 84 | + ]), |
| 85 | + |
| 86 | + // Current bundle (status, version, meta, bundle_number only - no file relationships, no UUIDs) |
| 87 | + 'current_bundle' => $this->when($this->relationLoaded('currentBundle') && $this->currentBundle, [ |
| 88 | + 'bundle_number' => data_get($this, 'currentBundle.bundle_number'), |
| 89 | + 'version' => data_get($this, 'currentBundle.version'), |
| 90 | + 'status' => data_get($this, 'currentBundle.status'), |
| 91 | + 'meta' => data_get($this, 'currentBundle.meta'), |
| 92 | + ]), |
| 93 | + ]; |
| 94 | + } |
| 95 | +} |
0 commit comments