Skip to content

Commit 52441e2

Browse files
authored
Merge pull request #30 from fleetbase/fix/extensions-list-install-count-order
fix: Use withCount('installs') to sort public extensions by install count
2 parents 3e6ba69 + 1430a7c commit 52441e2

File tree

5 files changed

+104
-7
lines changed

5 files changed

+104
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fleetbase/registry-bridge",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Internal Bridge between Fleetbase API and Extensions Registry",
55
"keywords": [
66
"fleetbase-extension",

extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Registry Bridge",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Internal Bridge between Fleetbase API and Extensions Registry",
55
"repository": "https://github.com/fleetbase/registry-bridge",
66
"license": "AGPL-3.0-or-later",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fleetbase/registry-bridge-engine",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Internal Bridge between Fleetbase API and Extensions Registry",
55
"fleetbase": {
66
"route": "extensions"

server/src/Http/Controllers/Internal/v1/RegistryExtensionController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Fleetbase\RegistryBridge\Http\Controllers\RegistryBridgeController;
99
use Fleetbase\RegistryBridge\Http\Requests\CreateRegistryExtensionRequest;
1010
use Fleetbase\RegistryBridge\Http\Requests\RegistryExtensionActionRequest;
11+
use Fleetbase\RegistryBridge\Http\Resources\PublicRegistryExtension;
1112
use Fleetbase\RegistryBridge\Models\RegistryExtension;
1213
use Fleetbase\RegistryBridge\Support\Utils;
1314
use Illuminate\Http\Request;
@@ -41,14 +42,15 @@ public function listPublicExtensions(Request $request)
4142

4243
$extensions = \Illuminate\Support\Facades\Cache::remember($cacheKey, $cacheTtl, function () {
4344
return RegistryExtension::where('status', 'published')
44-
->with(['author', 'category', 'currentBundle'])
45-
->orderBy('install_count', 'desc')
45+
->with(['company', 'category', 'currentBundle'])
46+
->withCount('installs')
47+
->orderBy('installs_count', 'desc')
4648
->get();
4749
});
4850

49-
$this->resource::wrap('registryExtensions');
51+
PublicRegistryExtension::withoutWrapping();
5052

51-
return $this->resource::collection($extensions);
53+
return PublicRegistryExtension::collection($extensions);
5254
}
5355

5456
/**
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)