@fleetbase/fleetops-engine 0.6.20 → 0.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/components/custom-entity/form.hbs +14 -14
- package/addon/components/device/details.hbs +92 -43
- package/addon/components/device/form.hbs +108 -60
- package/addon/components/device/form.js +36 -8
- package/addon/components/device/panel-header.hbs +32 -0
- package/addon/components/device/panel-header.js +3 -0
- package/addon/components/driver/form.hbs +1 -1
- package/addon/components/driver/form.js +49 -47
- package/addon/components/entity/form.hbs +7 -5
- package/addon/components/layout/fleet-ops-sidebar.js +12 -12
- package/addon/components/map/drawer/device-event-listing.hbs +58 -0
- package/addon/components/map/drawer/device-event-listing.js +181 -0
- package/addon/components/map/drawer/position-listing.hbs +84 -0
- package/addon/components/map/drawer/position-listing.js +289 -0
- package/addon/components/map/drawer.js +2 -0
- package/addon/components/map/leaflet-live-map.hbs +7 -2
- package/addon/components/order/details/payload.hbs +6 -4
- package/addon/components/order/details/payload.js +2 -0
- package/addon/components/order-config-manager/custom-fields.js +1 -1
- package/addon/components/positions-replay.hbs +333 -0
- package/addon/components/positions-replay.js +372 -0
- package/addon/components/sensor/details.hbs +64 -38
- package/addon/components/sensor/form.hbs +112 -63
- package/addon/components/sensor/form.js +36 -24
- package/addon/components/sensor/panel-header.hbs +32 -0
- package/addon/components/sensor/panel-header.js +3 -0
- package/addon/components/telematic/details.hbs +40 -16
- package/addon/components/telematic/form.hbs +63 -64
- package/addon/components/telematic/form.js +73 -4
- package/addon/components/vehicle/card.hbs +1 -1
- package/addon/controllers/analytics/reports/index/edit.js +1 -1
- package/addon/controllers/connectivity/devices/index/details.js +22 -1
- package/addon/controllers/connectivity/devices/index/edit.js +66 -1
- package/addon/controllers/connectivity/devices/index.js +51 -9
- package/addon/controllers/connectivity/events/index.js +65 -16
- package/addon/controllers/connectivity/sensors/index/details.js +22 -1
- package/addon/controllers/connectivity/sensors/index/edit.js +66 -1
- package/addon/controllers/connectivity/sensors/index.js +66 -6
- package/addon/controllers/connectivity/telematics/index/details.js +22 -1
- package/addon/controllers/connectivity/telematics/index/edit.js +66 -1
- package/addon/controllers/connectivity/telematics/index.js +20 -11
- package/addon/controllers/management/fleets/index/details.js +26 -21
- package/addon/controllers/management/fleets/index/edit.js +9 -6
- package/addon/controllers/management/vehicles/index/details.js +21 -13
- package/addon/controllers/settings/custom-fields.js +6 -0
- package/addon/helpers/get-fleet-ops-option-label.js +11 -0
- package/addon/routes/connectivity/devices/index/details.js +27 -1
- package/addon/routes/connectivity/devices/index/edit.js +27 -1
- package/addon/routes/connectivity/sensors/index/details.js +27 -1
- package/addon/routes/connectivity/sensors/index/edit.js +27 -1
- package/addon/routes/connectivity/telematics/index/details.js +27 -1
- package/addon/routes/connectivity/telematics/index/edit.js +27 -1
- package/addon/routes/management/vehicles/index/details/positions.js +3 -0
- package/addon/routes.js +1 -0
- package/addon/services/movement-tracker.js +81 -30
- package/addon/styles/fleetops-engine.css +157 -0
- package/addon/templates/connectivity/devices/index/details/index.hbs +2 -2
- package/addon/templates/connectivity/devices/index/details.hbs +15 -2
- package/addon/templates/connectivity/devices/index/edit.hbs +1 -1
- package/addon/templates/connectivity/events/index.hbs +1 -1
- package/addon/templates/connectivity/sensors/index/details/index.hbs +2 -2
- package/addon/templates/connectivity/sensors/index/details.hbs +15 -2
- package/addon/templates/connectivity/sensors/index/edit.hbs +1 -1
- package/addon/templates/connectivity/telematics/index/details/index.hbs +2 -2
- package/addon/templates/connectivity/telematics/index/details.hbs +14 -2
- package/addon/templates/connectivity/telematics/index/edit.hbs +1 -1
- package/addon/templates/management/vehicles/index/details/positions.hbs +1 -0
- package/addon/utils/fleet-ops-options.js +95 -0
- package/app/components/device/panel-header.js +1 -0
- package/app/components/map/drawer/device-event-listing.js +1 -0
- package/app/components/map/drawer/position-listing.js +1 -0
- package/app/components/positions-replay.js +1 -0
- package/app/components/sensor/panel-header.js +1 -0
- package/app/helpers/get-fleet-ops-option-label.js +1 -0
- package/app/routes/management/vehicles/index/details/positions.js +1 -0
- package/app/templates/management/vehicles/index/details/positions.js +1 -0
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +4 -4
- package/server/config/telematics.php +111 -0
- package/server/migrations/2025_10_27_000001_add_telematics_integration_fields.php +70 -0
- package/server/migrations/2025_10_27_171322_fix_device_column_names.php +107 -0
- package/server/migrations/2025_10_27_203023_add_company_uuid_to_device_events_table.php +28 -0
- package/server/src/Console/Commands/ReplayVehicleLocations.php +225 -0
- package/server/src/Contracts/TelematicProviderDescriptor.php +72 -0
- package/server/src/Contracts/TelematicProviderInterface.php +119 -0
- package/server/src/Exceptions/TelematicProviderException.php +14 -0
- package/server/src/Exceptions/TelematicRateLimitExceededException.php +12 -0
- package/server/src/Http/Controllers/Api/v1/DriverController.php +24 -14
- package/server/src/Http/Controllers/Api/v1/VehicleController.php +27 -7
- package/server/src/Http/Controllers/Internal/v1/DeviceController.php +22 -0
- package/server/src/Http/Controllers/Internal/v1/PositionController.php +240 -0
- package/server/src/Http/Controllers/Internal/v1/SensorController.php +11 -0
- package/server/src/Http/Controllers/Internal/v1/TelematicController.php +141 -0
- package/server/src/Http/Controllers/Internal/v1/TelematicWebhookController.php +170 -0
- package/server/src/Http/Filter/DeviceEventFilter.php +68 -0
- package/server/src/Http/Filter/PositionFilter.php +35 -0
- package/server/src/Http/Resources/v1/Position.php +44 -0
- package/server/src/Jobs/ReplayPositions.php +64 -0
- package/server/src/Jobs/SendPositionReplay.php +65 -0
- package/server/src/Jobs/SyncTelematicDevicesJob.php +106 -0
- package/server/src/Jobs/TestTelematicConnectionJob.php +102 -0
- package/server/src/Models/Device.php +72 -10
- package/server/src/Models/DeviceEvent.php +7 -0
- package/server/src/Models/Driver.php +28 -1
- package/server/src/Models/Payload.php +0 -1
- package/server/src/Models/Place.php +4 -1
- package/server/src/Models/Position.php +17 -17
- package/server/src/Models/Sensor.php +78 -13
- package/server/src/Models/Telematic.php +116 -6
- package/server/src/Models/Vehicle.php +8 -11
- package/server/src/Providers/FleetOpsServiceProvider.php +2 -0
- package/server/src/Support/Telematics/Providers/AbstractProvider.php +151 -0
- package/server/src/Support/Telematics/Providers/FlespiProvider.php +182 -0
- package/server/src/Support/Telematics/Providers/GeotabProvider.php +181 -0
- package/server/src/Support/Telematics/Providers/SamsaraProvider.php +177 -0
- package/server/src/Support/Telematics/TelematicProviderRegistry.php +147 -0
- package/server/src/Support/Telematics/TelematicService.php +223 -0
- package/server/src/Support/Utils.php +1 -1
- package/server/src/routes.php +12 -1
|
@@ -7,6 +7,8 @@ use Fleetbase\Models\Model;
|
|
|
7
7
|
use Fleetbase\Traits\HasApiModelBehavior;
|
|
8
8
|
use Fleetbase\Traits\HasUuid;
|
|
9
9
|
use Fleetbase\Traits\TracksApiCredential;
|
|
10
|
+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
11
|
+
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
10
12
|
|
|
11
13
|
class Position extends Model
|
|
12
14
|
{
|
|
@@ -48,7 +50,7 @@ class Position extends Model
|
|
|
48
50
|
*
|
|
49
51
|
* @var array
|
|
50
52
|
*/
|
|
51
|
-
protected $appends = [];
|
|
53
|
+
protected $appends = ['latitude', 'longitude'];
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Get filter parameters for this model.
|
|
@@ -85,35 +87,33 @@ class Position extends Model
|
|
|
85
87
|
*/
|
|
86
88
|
protected static $logName = 'position';
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
90
|
-
*/
|
|
91
|
-
public function company()
|
|
90
|
+
public function company(): BelongsTo
|
|
92
91
|
{
|
|
93
92
|
return $this->belongsTo(\Fleetbase\Models\Company::class);
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
98
|
-
*/
|
|
99
|
-
public function order()
|
|
95
|
+
public function order(): BelongsTo
|
|
100
96
|
{
|
|
101
97
|
return $this->belongsTo(Order::class);
|
|
102
98
|
}
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
106
|
-
*/
|
|
107
|
-
public function destination()
|
|
100
|
+
public function destination(): BelongsTo
|
|
108
101
|
{
|
|
109
102
|
return $this->belongsTo(Place::class);
|
|
110
103
|
}
|
|
111
104
|
|
|
112
|
-
|
|
113
|
-
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
114
|
-
*/
|
|
115
|
-
public function subject()
|
|
105
|
+
public function subject(): MorphTo
|
|
116
106
|
{
|
|
117
107
|
return $this->morphTo(__FUNCTION__, 'subject_type', 'subject_uuid')->withoutGlobalScopes();
|
|
118
108
|
}
|
|
109
|
+
|
|
110
|
+
public function getLongitudeAttribute(): float
|
|
111
|
+
{
|
|
112
|
+
return $this->coordinates?->getLng() ?? 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public function getLatitudeAttribute(): float
|
|
116
|
+
{
|
|
117
|
+
return $this->coordinates?->getLat() ?? 0;
|
|
118
|
+
}
|
|
119
119
|
}
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Models;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\FleetOps\Casts\Point;
|
|
7
|
+
use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait;
|
|
8
|
+
use Fleetbase\LaravelMysqlSpatial\Types\Point as SpatialPoint;
|
|
6
9
|
use Fleetbase\Models\Alert;
|
|
10
|
+
use Fleetbase\Models\File;
|
|
7
11
|
use Fleetbase\Models\Model;
|
|
8
12
|
use Fleetbase\Models\User;
|
|
9
13
|
use Fleetbase\Traits\HasApiModelBehavior;
|
|
@@ -16,6 +20,8 @@ use Fleetbase\Traits\TracksApiCredential;
|
|
|
16
20
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
17
21
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
18
22
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
23
|
+
use Illuminate\Support\Arr;
|
|
24
|
+
use Illuminate\Support\Str;
|
|
19
25
|
use Spatie\Activitylog\LogOptions;
|
|
20
26
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
21
27
|
use Spatie\Sluggable\HasSlug;
|
|
@@ -39,6 +45,7 @@ class Sensor extends Model
|
|
|
39
45
|
use HasMetaAttributes;
|
|
40
46
|
use Searchable;
|
|
41
47
|
use HasCustomFields;
|
|
48
|
+
use SpatialTrait;
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
51
|
* The database table used by the model.
|
|
@@ -77,8 +84,16 @@ class Sensor extends Model
|
|
|
77
84
|
'company_uuid',
|
|
78
85
|
'device_uuid',
|
|
79
86
|
'warranty_uuid',
|
|
87
|
+
'telematic_uuid',
|
|
88
|
+
'photo_uuid',
|
|
80
89
|
'name',
|
|
81
|
-
'
|
|
90
|
+
'type',
|
|
91
|
+
'internal_id',
|
|
92
|
+
'imei',
|
|
93
|
+
'imsi',
|
|
94
|
+
'firmware_version',
|
|
95
|
+
'serial_number',
|
|
96
|
+
'last_position',
|
|
82
97
|
'unit',
|
|
83
98
|
'min_threshold',
|
|
84
99
|
'max_threshold',
|
|
@@ -100,12 +115,9 @@ class Sensor extends Model
|
|
|
100
115
|
* @var array
|
|
101
116
|
*/
|
|
102
117
|
protected $appends = [
|
|
103
|
-
'device_name',
|
|
104
|
-
'warranty_name',
|
|
105
|
-
'attached_to_name',
|
|
106
118
|
'is_active',
|
|
107
119
|
'threshold_status',
|
|
108
|
-
'
|
|
120
|
+
'photo_url',
|
|
109
121
|
];
|
|
110
122
|
|
|
111
123
|
/**
|
|
@@ -113,7 +125,14 @@ class Sensor extends Model
|
|
|
113
125
|
*
|
|
114
126
|
* @var array
|
|
115
127
|
*/
|
|
116
|
-
protected $hidden = [
|
|
128
|
+
protected $hidden = [];
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The attributes that are spatial columns.
|
|
132
|
+
*
|
|
133
|
+
* @var array
|
|
134
|
+
*/
|
|
135
|
+
protected $spatialFields = ['last_position'];
|
|
117
136
|
|
|
118
137
|
/**
|
|
119
138
|
* The attributes that should be cast to native types.
|
|
@@ -121,13 +140,14 @@ class Sensor extends Model
|
|
|
121
140
|
* @var array
|
|
122
141
|
*/
|
|
123
142
|
protected $casts = [
|
|
124
|
-
'min_threshold'
|
|
125
|
-
'max_threshold'
|
|
126
|
-
'threshold_inclusive'
|
|
127
|
-
'last_reading_at'
|
|
128
|
-
'report_frequency_sec'
|
|
129
|
-
'
|
|
130
|
-
'
|
|
143
|
+
'min_threshold' => 'float',
|
|
144
|
+
'max_threshold' => 'float',
|
|
145
|
+
'threshold_inclusive' => 'boolean',
|
|
146
|
+
'last_reading_at' => 'datetime',
|
|
147
|
+
'report_frequency_sec' => 'integer',
|
|
148
|
+
'last_position' => Point::class,
|
|
149
|
+
'calibration' => Json::class,
|
|
150
|
+
'meta' => Json::class,
|
|
131
151
|
];
|
|
132
152
|
|
|
133
153
|
/**
|
|
@@ -169,6 +189,11 @@ class Sensor extends Model
|
|
|
169
189
|
return LogOptions::defaults()->logAll();
|
|
170
190
|
}
|
|
171
191
|
|
|
192
|
+
public function telematic(): BelongsTo
|
|
193
|
+
{
|
|
194
|
+
return $this->belongsTo(Telematic::class, 'telematic_uuid', 'uuid');
|
|
195
|
+
}
|
|
196
|
+
|
|
172
197
|
public function device(): BelongsTo
|
|
173
198
|
{
|
|
174
199
|
return $this->belongsTo(Device::class, 'device_uuid', 'uuid');
|
|
@@ -194,12 +219,27 @@ class Sensor extends Model
|
|
|
194
219
|
return $this->morphTo();
|
|
195
220
|
}
|
|
196
221
|
|
|
222
|
+
public function photo(): BelongsTo
|
|
223
|
+
{
|
|
224
|
+
return $this->belongsTo(File::class);
|
|
225
|
+
}
|
|
226
|
+
|
|
197
227
|
public function alerts(): HasMany
|
|
198
228
|
{
|
|
199
229
|
return $this->hasMany(Alert::class, 'subject_uuid', 'uuid')
|
|
200
230
|
->where('subject_type', static::class);
|
|
201
231
|
}
|
|
202
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Get photo URL attribute.
|
|
235
|
+
*
|
|
236
|
+
* @return string
|
|
237
|
+
*/
|
|
238
|
+
public function getPhotoUrlAttribute()
|
|
239
|
+
{
|
|
240
|
+
return data_get($this, 'photo.url', 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/image-file-icon.png');
|
|
241
|
+
}
|
|
242
|
+
|
|
203
243
|
/**
|
|
204
244
|
* Get the device name.
|
|
205
245
|
*/
|
|
@@ -507,4 +547,29 @@ class Sensor extends Model
|
|
|
507
547
|
],
|
|
508
548
|
];
|
|
509
549
|
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Creates a new position for the vehicle.
|
|
553
|
+
*/
|
|
554
|
+
public function createPosition(array $attributes = [], Model|string|null $destination = null): ?Position
|
|
555
|
+
{
|
|
556
|
+
if (!isset($attributes['coordinates']) && isset($attributes['location'])) {
|
|
557
|
+
$attributes['coordinates'] = $attributes['location'];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (!isset($attributes['coordinates']) && isset($attributes['latitude']) && isset($attributes['longitude'])) {
|
|
561
|
+
$attributes['coordinates'] = new SpatialPoint($attributes['latitude'], $attributes['longitude']);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// handle destination if set
|
|
565
|
+
$destinationUuid = Str::isUuid($destination) ? $destination : data_get($destination, 'uuid');
|
|
566
|
+
|
|
567
|
+
return Position::create([
|
|
568
|
+
...Arr::only($attributes, ['coordinates', 'heading', 'bearing', 'speed', 'altitude', 'order_uuid']),
|
|
569
|
+
'subject_uuid' => $this->uuid,
|
|
570
|
+
'subject_type' => $this->getMorphClass(),
|
|
571
|
+
'company_uuid' => $this->company_uuid,
|
|
572
|
+
'destination_uuid' => $destinationUuid,
|
|
573
|
+
]);
|
|
574
|
+
}
|
|
510
575
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Models;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\FleetOps\Support\Telematics\TelematicProviderRegistry;
|
|
6
7
|
use Fleetbase\Models\Model;
|
|
7
8
|
use Fleetbase\Models\User;
|
|
8
9
|
use Fleetbase\Traits\HasApiModelBehavior;
|
|
@@ -85,8 +86,8 @@ class Telematic extends Model
|
|
|
85
86
|
'last_seen_at',
|
|
86
87
|
'last_metrics',
|
|
87
88
|
'config',
|
|
89
|
+
'credentials',
|
|
88
90
|
'meta',
|
|
89
|
-
'slug',
|
|
90
91
|
];
|
|
91
92
|
|
|
92
93
|
/**
|
|
@@ -94,7 +95,7 @@ class Telematic extends Model
|
|
|
94
95
|
*
|
|
95
96
|
* @var array
|
|
96
97
|
*/
|
|
97
|
-
protected $appends = ['warranty_name', 'is_online', 'signal_strength', 'last_location'];
|
|
98
|
+
protected $appends = ['warranty_name', 'is_online', 'signal_strength', 'last_location', 'provider_descriptor'];
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* The attributes excluded from the model's JSON form.
|
|
@@ -109,10 +110,97 @@ class Telematic extends Model
|
|
|
109
110
|
* @var array
|
|
110
111
|
*/
|
|
111
112
|
protected $casts = [
|
|
112
|
-
'last_seen_at'
|
|
113
|
-
'last_metrics'
|
|
114
|
-
'config'
|
|
115
|
-
'
|
|
113
|
+
'last_seen_at' => 'datetime',
|
|
114
|
+
'last_metrics' => Json::class,
|
|
115
|
+
'config' => Json::class,
|
|
116
|
+
'credentials' => Json::class,
|
|
117
|
+
'meta' => Json::class,
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Telematic statuses.
|
|
122
|
+
*
|
|
123
|
+
* @var array
|
|
124
|
+
*/
|
|
125
|
+
public static $statuses = [
|
|
126
|
+
[
|
|
127
|
+
'key' => 'initialized',
|
|
128
|
+
'label' => 'Initialized',
|
|
129
|
+
'description' => 'Provider entry has been created but not yet configured.',
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
'key' => 'configured',
|
|
133
|
+
'label' => 'Configured',
|
|
134
|
+
'description' => 'Provider credentials and settings are valid but connection not yet tested.',
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
'key' => 'connecting',
|
|
138
|
+
'label' => 'Connecting',
|
|
139
|
+
'description' => 'Attempting to establish a connection with provider API.',
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
'key' => 'connected',
|
|
143
|
+
'label' => 'Connected',
|
|
144
|
+
'description' => 'Successfully authenticated and connected to provider API.',
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
'key' => 'synchronizing',
|
|
148
|
+
'label' => 'Synchronizing',
|
|
149
|
+
'description' => 'Currently syncing data (devices, vehicles, positions, etc.) from provider.',
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
'key' => 'active',
|
|
153
|
+
'label' => 'Active',
|
|
154
|
+
'description' => 'Integration is healthy and data syncs are occurring normally.',
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
'key' => 'degraded',
|
|
158
|
+
'label' => 'Degraded',
|
|
159
|
+
'description' => 'Integration partially working; intermittent errors or missing data.',
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
'key' => 'disconnected',
|
|
163
|
+
'label' => 'Disconnected',
|
|
164
|
+
'description' => 'Connection lost or failed authentication.',
|
|
165
|
+
],
|
|
166
|
+
[
|
|
167
|
+
'key' => 'error',
|
|
168
|
+
'label' => 'Error',
|
|
169
|
+
'description' => 'Provider integration encountered a fatal issue.',
|
|
170
|
+
],
|
|
171
|
+
[
|
|
172
|
+
'key' => 'disabled',
|
|
173
|
+
'label' => 'Disabled',
|
|
174
|
+
'description' => 'Manually disabled by the user.',
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
'key' => 'archived',
|
|
178
|
+
'label' => 'Archived',
|
|
179
|
+
'description' => 'Deprecated or replaced integration, kept for record.',
|
|
180
|
+
],
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Telematic health statuses.
|
|
185
|
+
*
|
|
186
|
+
* @var array
|
|
187
|
+
*/
|
|
188
|
+
public static $healthStates = [
|
|
189
|
+
[
|
|
190
|
+
'key' => 'healthy',
|
|
191
|
+
'label' => 'Healthy',
|
|
192
|
+
'description' => 'Integration tested and stable.',
|
|
193
|
+
],
|
|
194
|
+
[
|
|
195
|
+
'key' => 'warning',
|
|
196
|
+
'label' => 'Warning',
|
|
197
|
+
'description' => 'Minor issues detected (e.g., slow response, nearing quota).',
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
'key' => 'critical',
|
|
201
|
+
'label' => 'Critical',
|
|
202
|
+
'description' => 'Persistent failure or no data received in X hours.',
|
|
203
|
+
],
|
|
116
204
|
];
|
|
117
205
|
|
|
118
206
|
/**
|
|
@@ -169,6 +257,20 @@ class Telematic extends Model
|
|
|
169
257
|
return $this->hasMany(Asset::class, 'telematic_uuid', 'uuid');
|
|
170
258
|
}
|
|
171
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Get the provider config.
|
|
262
|
+
*/
|
|
263
|
+
public function getProviderDescriptorAttribute(): array
|
|
264
|
+
{
|
|
265
|
+
$registry = app(TelematicProviderRegistry::class);
|
|
266
|
+
$provider = $registry->findByKey($this->provider);
|
|
267
|
+
if ($provider) {
|
|
268
|
+
return $provider->toArray();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
|
|
172
274
|
/**
|
|
173
275
|
* Get the warranty name.
|
|
174
276
|
*/
|
|
@@ -333,4 +435,12 @@ class Telematic extends Model
|
|
|
333
435
|
|
|
334
436
|
return true;
|
|
335
437
|
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Sets a default status if none input.
|
|
441
|
+
*/
|
|
442
|
+
public function setStatusAttribute(?string $status = null): void
|
|
443
|
+
{
|
|
444
|
+
$this->attributes['status'] = $status ?? 'initialized';
|
|
445
|
+
}
|
|
336
446
|
}
|
|
@@ -536,10 +536,7 @@ class Vehicle extends Model
|
|
|
536
536
|
}
|
|
537
537
|
|
|
538
538
|
/**
|
|
539
|
-
* Creates a new position for the vehicle
|
|
540
|
-
*
|
|
541
|
-
* @param array $attributes
|
|
542
|
-
* @return Position|null
|
|
539
|
+
* Creates a new position for the vehicle.
|
|
543
540
|
*/
|
|
544
541
|
public function createPosition(array $attributes = [], Model|string|null $destination = null): ?Position
|
|
545
542
|
{
|
|
@@ -555,11 +552,11 @@ class Vehicle extends Model
|
|
|
555
552
|
$destinationUuid = Str::isUuid($destination) ? $destination : data_get($destination, 'uuid');
|
|
556
553
|
|
|
557
554
|
return Position::create([
|
|
558
|
-
...Arr::only($attributes, ['coordinates', 'heading', 'bearing', 'speed', 'altitude']),
|
|
559
|
-
'subject_uuid'
|
|
560
|
-
'subject_type'
|
|
561
|
-
'company_uuid'
|
|
562
|
-
'destination_uuid' => $destinationUuid
|
|
555
|
+
...Arr::only($attributes, ['coordinates', 'heading', 'bearing', 'speed', 'altitude', 'order_uuid']),
|
|
556
|
+
'subject_uuid' => $this->uuid,
|
|
557
|
+
'subject_type' => $this->getMorphClass(),
|
|
558
|
+
'company_uuid' => $this->company_uuid,
|
|
559
|
+
'destination_uuid' => $destinationUuid,
|
|
563
560
|
]);
|
|
564
561
|
}
|
|
565
562
|
|
|
@@ -760,8 +757,8 @@ class Vehicle extends Model
|
|
|
760
757
|
*/
|
|
761
758
|
public function setVinDatas(array $newVinData = []): array
|
|
762
759
|
{
|
|
763
|
-
$vinData
|
|
764
|
-
$vinData
|
|
760
|
+
$vinData = is_array($this->vin_data) ? $this->vin_data : (array) $this->vin_data;
|
|
761
|
+
$vinData = array_merge($vinData, $newVinData);
|
|
765
762
|
$this->vin_data = $vinData;
|
|
766
763
|
|
|
767
764
|
return $vinData;
|
|
@@ -59,6 +59,7 @@ class FleetOpsServiceProvider extends CoreServiceProvider
|
|
|
59
59
|
\Fleetbase\FleetOps\Console\Commands\DebugOrderTracker::class,
|
|
60
60
|
\Fleetbase\FleetOps\Console\Commands\PurgeUnpurchasedServiceQuotes::class,
|
|
61
61
|
\Fleetbase\FleetOps\Console\Commands\SendDriverNotification::class,
|
|
62
|
+
\Fleetbase\FleetOps\Console\Commands\ReplayVehicleLocations::class,
|
|
62
63
|
];
|
|
63
64
|
|
|
64
65
|
/**
|
|
@@ -103,6 +104,7 @@ class FleetOpsServiceProvider extends CoreServiceProvider
|
|
|
103
104
|
$this->loadMigrationsFrom(__DIR__ . '/../../migrations');
|
|
104
105
|
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'fleetops');
|
|
105
106
|
$this->mergeConfigFrom(__DIR__ . '/../../config/fleetops.php', 'fleetops');
|
|
107
|
+
$this->mergeConfigFrom(__DIR__ . '/../../config/telematics.php', 'telematics');
|
|
106
108
|
$this->mergeConfigFrom(__DIR__ . '/../../config/api.php', 'api');
|
|
107
109
|
$this->mergeConfigFrom(__DIR__ . '/../../config/cache.stores.php', 'cache.stores');
|
|
108
110
|
$this->mergeConfigFrom(__DIR__ . '/../../config/geocoder.php', 'geocoder');
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Support\Telematics\Providers;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Contracts\TelematicProviderInterface;
|
|
6
|
+
use Fleetbase\FleetOps\Exceptions\TelematicRateLimitExceededException;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Telematic;
|
|
8
|
+
use Illuminate\Support\Facades\Cache;
|
|
9
|
+
use Illuminate\Support\Facades\Crypt;
|
|
10
|
+
use Illuminate\Support\Facades\Http;
|
|
11
|
+
use Illuminate\Support\Facades\Log;
|
|
12
|
+
use Illuminate\Support\Str;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class AbstractProvider.
|
|
16
|
+
*
|
|
17
|
+
* Base implementation for all telematics providers.
|
|
18
|
+
* Provides common functionality for HTTP requests, rate limiting,
|
|
19
|
+
* and credential management.
|
|
20
|
+
*/
|
|
21
|
+
abstract class AbstractProvider implements TelematicProviderInterface
|
|
22
|
+
{
|
|
23
|
+
protected Telematic $telematic;
|
|
24
|
+
protected array $credentials = [];
|
|
25
|
+
protected array $headers = [];
|
|
26
|
+
protected string $baseUrl = '';
|
|
27
|
+
protected int $requestsPerMinute = 60;
|
|
28
|
+
protected int $burstSize = 10;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Connect to the provider.
|
|
32
|
+
*/
|
|
33
|
+
public function connect(Telematic $telematic): void
|
|
34
|
+
{
|
|
35
|
+
$this->telematic = $telematic;
|
|
36
|
+
$this->credentials = json_decode(Crypt::decryptString($telematic->credentials), true);
|
|
37
|
+
$this->prepareAuthentication();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Prepare authentication headers/tokens.
|
|
42
|
+
* Override this in provider implementations.
|
|
43
|
+
*/
|
|
44
|
+
abstract protected function prepareAuthentication(): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Make an HTTP request to the provider API.
|
|
48
|
+
*
|
|
49
|
+
* @throws TelematicRateLimitExceededException
|
|
50
|
+
*/
|
|
51
|
+
protected function request(string $method, string $endpoint, array $data = []): array
|
|
52
|
+
{
|
|
53
|
+
$this->checkRateLimit();
|
|
54
|
+
|
|
55
|
+
$url = $this->baseUrl . $endpoint;
|
|
56
|
+
$correlationId = Str::uuid()->toString();
|
|
57
|
+
|
|
58
|
+
Log::info('Provider API request', [
|
|
59
|
+
'correlation_id' => $correlationId,
|
|
60
|
+
'provider' => class_basename($this),
|
|
61
|
+
'method' => $method,
|
|
62
|
+
'url' => $url,
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
$response = Http::withHeaders($this->headers)
|
|
66
|
+
->timeout(30)
|
|
67
|
+
->{strtolower($method)}($url, $data);
|
|
68
|
+
|
|
69
|
+
$this->recordRequest();
|
|
70
|
+
|
|
71
|
+
if ($response->failed()) {
|
|
72
|
+
Log::error('Provider API request failed', [
|
|
73
|
+
'correlation_id' => $correlationId,
|
|
74
|
+
'status' => $response->status(),
|
|
75
|
+
'body' => $response->body(),
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
throw new \Exception('API request failed: ' . $response->body());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return $response->json();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check rate limit using token bucket algorithm.
|
|
86
|
+
*
|
|
87
|
+
* @throws TelematicRateLimitExceededException
|
|
88
|
+
*/
|
|
89
|
+
protected function checkRateLimit(): void
|
|
90
|
+
{
|
|
91
|
+
$key = 'rate_limit:' . class_basename($this) . ':' . $this->telematic->uuid;
|
|
92
|
+
$tokens = Cache::get($key, $this->burstSize);
|
|
93
|
+
|
|
94
|
+
if ($tokens <= 0) {
|
|
95
|
+
throw new TelematicRateLimitExceededException('Rate limit exceeded for provider');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Cache::put($key, $tokens - 1, 60);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Record a request for metrics.
|
|
103
|
+
*/
|
|
104
|
+
protected function recordRequest(): void
|
|
105
|
+
{
|
|
106
|
+
$key = 'rate_limit:' . class_basename($this) . ':' . $this->telematic->uuid;
|
|
107
|
+
$tokens = Cache::get($key, 0);
|
|
108
|
+
|
|
109
|
+
// Refill tokens gradually
|
|
110
|
+
if ($tokens < $this->burstSize) {
|
|
111
|
+
Cache::put($key, min($tokens + 1, $this->burstSize), 60);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public function supportsWebhooks(): bool
|
|
116
|
+
{
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public function supportsDiscovery(): bool
|
|
121
|
+
{
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public function getRateLimits(): array
|
|
126
|
+
{
|
|
127
|
+
return [
|
|
128
|
+
'requests_per_minute' => $this->requestsPerMinute,
|
|
129
|
+
'burst_size' => $this->burstSize,
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public function validateWebhookSignature(string $payload, string $signature, array $credentials): bool
|
|
134
|
+
{
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public function processWebhook(array $payload, array $headers = []): array
|
|
139
|
+
{
|
|
140
|
+
return [
|
|
141
|
+
'devices' => [],
|
|
142
|
+
'events' => [],
|
|
143
|
+
'sensors' => [],
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public function getCredentialSchema(): array
|
|
148
|
+
{
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
}
|