@burdenoff/microfe-movethewheels 2026.1107.3 → 2026.1107.5
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/dist/components/ScenarioPlanningPanel.js +411 -0
- package/dist/generated/tracking-quality-operations.d.ts +1 -1
- package/dist/generated/wspace-types.d.ts +1028 -42
- package/dist/hooks/useScenarioPlanning.js +89 -0
- package/dist/movethewheels/components/ScenarioPlanningPanel.d.ts +4 -0
- package/dist/movethewheels/hooks/useCarrierIntegrations.d.ts +2 -0
- package/dist/movethewheels/hooks/useScenarioPlanning.d.ts +94 -0
- package/dist/movethewheels/utils/carrierIntegrations.d.ts +38 -4
- package/dist/node_modules/lucide-react/dist/esm/icons/git-compare.js +26 -0
- package/dist/pages/AnalyticsPage.js +80 -78
- package/dist/pages/IntegrationsPage.js +324 -129
- package/dist/utils/carrierIntegrations.js +62 -23
- package/package.json +1 -1
- package/src/generated/tracking-quality-operations.ts +1 -0
- package/src/generated/wspace-types.ts +1148 -42
- package/src/movethewheels/components/ScenarioPlanningPanel.tsx +539 -0
- package/src/movethewheels/hooks/useCarrierIntegrations.ts +2 -0
- package/src/movethewheels/hooks/useScenarioPlanning.ts +273 -0
- package/src/movethewheels/pages/AnalyticsPage.tsx +5 -0
- package/src/movethewheels/pages/IntegrationsPage.tsx +266 -44
- package/src/movethewheels/utils/carrierIntegrations.ts +76 -8
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* integration's URL, signed with HMAC-SHA256 over the raw body, and every
|
|
7
7
|
* accepted update becomes a tracking event on the matching shipment.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* read back from the service.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* A generic feed's signing secret is generated in the browser, shown exactly
|
|
10
|
+
* once and never read back from the service. A Samsara feed (BOFF-10703) uses
|
|
11
|
+
* the secret Samsara issues for its webhook, pasted here once. Named carrier
|
|
12
|
+
* networks (project44, FourKites, Descartes) are listed as not yet available:
|
|
13
|
+
* they need vendor agreements before an adapter can ship, and the service
|
|
14
|
+
* refuses them.
|
|
13
15
|
*/
|
|
14
16
|
import { useEffect, useRef, useState, type FormEvent } from 'react';
|
|
15
17
|
import {
|
|
@@ -63,23 +65,31 @@ import {
|
|
|
63
65
|
useCarrierIntegrations,
|
|
64
66
|
} from '../hooks/useCarrierIntegrations';
|
|
65
67
|
import {
|
|
68
|
+
DEFAULT_SAMSARA_SHIPMENT_KEY,
|
|
66
69
|
INTEGRATION_STATUSES,
|
|
67
70
|
MAX_UPDATES_PER_DELIVERY,
|
|
71
|
+
PLANNED_ELD_PROVIDERS,
|
|
68
72
|
ROADMAP_PROVIDERS,
|
|
73
|
+
SAMSARA_EVENT_TYPES,
|
|
74
|
+
SAMSARA_SIGNATURE_HEADERS,
|
|
69
75
|
SIGNATURE_HEADER,
|
|
70
76
|
TRACKING_EVENT_TYPES,
|
|
71
77
|
curlExample,
|
|
72
78
|
eventStatusTone,
|
|
73
79
|
examplePayload,
|
|
80
|
+
externalIdKeyError,
|
|
74
81
|
generateSigningSecret,
|
|
75
82
|
humanize,
|
|
76
83
|
integrationNameError,
|
|
77
84
|
integrationStatusTone,
|
|
85
|
+
providerLabel,
|
|
86
|
+
samsaraSecretError,
|
|
78
87
|
signingSecretError,
|
|
79
88
|
statusExplanation,
|
|
80
89
|
webhookUrl,
|
|
81
90
|
type CarrierIntegration,
|
|
82
91
|
type IntegrationStatus,
|
|
92
|
+
type SupportedProvider,
|
|
83
93
|
} from '../utils/carrierIntegrations';
|
|
84
94
|
import { formatDateTime } from '../utils/formatters';
|
|
85
95
|
|
|
@@ -173,23 +183,35 @@ function CreateIntegrationDialog({
|
|
|
173
183
|
}: {
|
|
174
184
|
open: boolean;
|
|
175
185
|
onOpenChange: (open: boolean) => void;
|
|
176
|
-
|
|
186
|
+
/** `secret` is set only when MoveTheWheels generated it and must reveal it once. */
|
|
187
|
+
onCreated: (integration: CarrierIntegration, secret: string | null) => void;
|
|
177
188
|
}) {
|
|
178
189
|
const actions = useCarrierIntegrationActions();
|
|
190
|
+
const [provider, setProvider] = useState<SupportedProvider>('GENERIC_WEBHOOK');
|
|
179
191
|
const [name, setName] = useState('');
|
|
180
192
|
const [secret, setSecret] = useState(() => generateSigningSecret());
|
|
193
|
+
const [samsaraSecret, setSamsaraSecret] = useState('');
|
|
194
|
+
const [shipmentKey, setShipmentKey] = useState('');
|
|
181
195
|
const [error, setError] = useState<string | null>(null);
|
|
182
196
|
const [isSaving, setIsSaving] = useState(false);
|
|
197
|
+
const isSamsara = provider === 'SAMSARA';
|
|
183
198
|
|
|
184
199
|
const reset = () => {
|
|
200
|
+
setProvider('GENERIC_WEBHOOK');
|
|
185
201
|
setName('');
|
|
186
202
|
setSecret(generateSigningSecret());
|
|
203
|
+
setSamsaraSecret('');
|
|
204
|
+
setShipmentKey('');
|
|
187
205
|
setError(null);
|
|
188
206
|
};
|
|
189
207
|
|
|
190
208
|
const submit = async (event: FormEvent) => {
|
|
191
209
|
event.preventDefault();
|
|
192
|
-
const problem =
|
|
210
|
+
const problem =
|
|
211
|
+
integrationNameError(name) ??
|
|
212
|
+
(isSamsara
|
|
213
|
+
? (samsaraSecretError(samsaraSecret) ?? externalIdKeyError(shipmentKey))
|
|
214
|
+
: signingSecretError(secret));
|
|
193
215
|
if (problem) {
|
|
194
216
|
setError(problem);
|
|
195
217
|
return;
|
|
@@ -197,12 +219,18 @@ function CreateIntegrationDialog({
|
|
|
197
219
|
setIsSaving(true);
|
|
198
220
|
setError(null);
|
|
199
221
|
try {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
222
|
+
const key = shipmentKey.trim();
|
|
223
|
+
const created = await actions.create(
|
|
224
|
+
isSamsara
|
|
225
|
+
? {
|
|
226
|
+
provider: 'SAMSARA',
|
|
227
|
+
name,
|
|
228
|
+
apiSecret: samsaraSecret.trim(),
|
|
229
|
+
...(key ? { config: { shipmentExternalIdKey: key } } : {}),
|
|
230
|
+
}
|
|
231
|
+
: { provider: 'GENERIC_WEBHOOK', name, apiSecret: secret }
|
|
232
|
+
);
|
|
233
|
+
onCreated(created, isSamsara ? null : secret);
|
|
206
234
|
reset();
|
|
207
235
|
onOpenChange(false);
|
|
208
236
|
} catch (createError) {
|
|
@@ -225,7 +253,7 @@ function CreateIntegrationDialog({
|
|
|
225
253
|
<ResponsiveDialogHeader>
|
|
226
254
|
<ResponsiveDialogTitle>Connect a tracking feed</ResponsiveDialogTitle>
|
|
227
255
|
<ResponsiveDialogDescription>
|
|
228
|
-
A signed webhook
|
|
256
|
+
A signed webhook from a carrier, ELD or GPS provider. Updates it sends become tracking
|
|
229
257
|
events on the matching shipments.
|
|
230
258
|
</ResponsiveDialogDescription>
|
|
231
259
|
</ResponsiveDialogHeader>
|
|
@@ -235,37 +263,87 @@ function CreateIntegrationDialog({
|
|
|
235
263
|
id="integration-name"
|
|
236
264
|
value={name}
|
|
237
265
|
maxLength={120}
|
|
238
|
-
placeholder=
|
|
266
|
+
placeholder={isSamsara ? 'e.g. Samsara fleet' : 'e.g. Fleet GPS feed'}
|
|
239
267
|
onChange={(event) => setName(event.target.value)}
|
|
240
268
|
autoFocus
|
|
241
269
|
/>
|
|
242
270
|
</div>
|
|
243
271
|
<div className="space-y-1.5">
|
|
244
|
-
<Label>Type</Label>
|
|
245
|
-
<
|
|
246
|
-
|
|
247
|
-
|
|
272
|
+
<Label htmlFor="integration-type">Type</Label>
|
|
273
|
+
<Select
|
|
274
|
+
value={provider}
|
|
275
|
+
onValueChange={(value) => {
|
|
276
|
+
setProvider(value as SupportedProvider);
|
|
277
|
+
setError(null);
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
280
|
+
<SelectTrigger id="integration-type" aria-label="Type">
|
|
281
|
+
<SelectValue />
|
|
282
|
+
</SelectTrigger>
|
|
283
|
+
<SelectContent>
|
|
284
|
+
<SelectItem value="GENERIC_WEBHOOK">
|
|
285
|
+
Signed webhook (any system that can send HTTPS POSTs)
|
|
286
|
+
</SelectItem>
|
|
287
|
+
<SelectItem value="SAMSARA">Samsara (ELD and telematics)</SelectItem>
|
|
288
|
+
</SelectContent>
|
|
289
|
+
</Select>
|
|
248
290
|
</div>
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
<
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
291
|
+
{isSamsara ? (
|
|
292
|
+
<>
|
|
293
|
+
<div className="space-y-1.5">
|
|
294
|
+
<Label htmlFor="samsara-secret">Samsara webhook secret key</Label>
|
|
295
|
+
<Input
|
|
296
|
+
id="samsara-secret"
|
|
297
|
+
type="password"
|
|
298
|
+
autoComplete="off"
|
|
299
|
+
spellCheck={false}
|
|
300
|
+
value={samsaraSecret}
|
|
301
|
+
placeholder="Paste from Samsara → Settings → Webhooks"
|
|
302
|
+
onChange={(event) => setSamsaraSecret(event.target.value)}
|
|
303
|
+
/>
|
|
304
|
+
<p className="text-xs text-text-secondary">
|
|
305
|
+
Create the webhook in Samsara first; its page shows this key. MoveTheWheels stores
|
|
306
|
+
it encrypted and never shows it again.
|
|
307
|
+
</p>
|
|
308
|
+
</div>
|
|
309
|
+
<div className="space-y-1.5">
|
|
310
|
+
<Label htmlFor="samsara-shipment-key">Shipment external ID key (optional)</Label>
|
|
311
|
+
<Input
|
|
312
|
+
id="samsara-shipment-key"
|
|
313
|
+
value={shipmentKey}
|
|
314
|
+
maxLength={64}
|
|
315
|
+
placeholder={DEFAULT_SAMSARA_SHIPMENT_KEY}
|
|
316
|
+
onChange={(event) => setShipmentKey(event.target.value)}
|
|
317
|
+
/>
|
|
318
|
+
<p className="text-xs text-text-secondary">
|
|
319
|
+
The external ID on a Samsara route or stop that holds the MoveTheWheels tracking
|
|
320
|
+
number. Leave blank to use{' '}
|
|
321
|
+
<code className="font-mono">{DEFAULT_SAMSARA_SHIPMENT_KEY}</code>.
|
|
322
|
+
</p>
|
|
323
|
+
</div>
|
|
324
|
+
</>
|
|
325
|
+
) : (
|
|
326
|
+
<div className="space-y-1.5">
|
|
327
|
+
<div className="flex items-center justify-between">
|
|
328
|
+
<Label>Signing secret</Label>
|
|
329
|
+
<Button
|
|
330
|
+
type="button"
|
|
331
|
+
size="sm"
|
|
332
|
+
variant="ghost"
|
|
333
|
+
onClick={() => setSecret(generateSigningSecret())}
|
|
334
|
+
>
|
|
335
|
+
<RefreshCw size={14} className="mr-1" />
|
|
336
|
+
Generate another
|
|
337
|
+
</Button>
|
|
338
|
+
</div>
|
|
339
|
+
<code className="block break-all rounded-lg bg-bg-sunken px-3 py-2 font-mono text-xs">
|
|
340
|
+
{secret}
|
|
341
|
+
</code>
|
|
342
|
+
<p className="text-xs text-text-secondary">
|
|
343
|
+
Generated in your browser. You can copy it on the next step.
|
|
344
|
+
</p>
|
|
261
345
|
</div>
|
|
262
|
-
|
|
263
|
-
{secret}
|
|
264
|
-
</code>
|
|
265
|
-
<p className="text-xs text-text-secondary">
|
|
266
|
-
Generated in your browser. You can copy it on the next step.
|
|
267
|
-
</p>
|
|
268
|
-
</div>
|
|
346
|
+
)}
|
|
269
347
|
<FormError message={error} />
|
|
270
348
|
<ResponsiveDialogFooter>
|
|
271
349
|
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
|
@@ -281,6 +359,119 @@ function CreateIntegrationDialog({
|
|
|
281
359
|
);
|
|
282
360
|
}
|
|
283
361
|
|
|
362
|
+
/** Samsara issues the secret, so rotating it means pasting the new one from Samsara. */
|
|
363
|
+
function ReplaceSamsaraSecretDialog({
|
|
364
|
+
integration,
|
|
365
|
+
onClose,
|
|
366
|
+
onReplace,
|
|
367
|
+
}: {
|
|
368
|
+
integration: CarrierIntegration | null;
|
|
369
|
+
onClose: () => void;
|
|
370
|
+
onReplace: (integration: CarrierIntegration, secret: string) => Promise<void>;
|
|
371
|
+
}) {
|
|
372
|
+
const [secret, setSecret] = useState('');
|
|
373
|
+
const [error, setError] = useState<string | null>(null);
|
|
374
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
375
|
+
const close = () => {
|
|
376
|
+
setSecret('');
|
|
377
|
+
setError(null);
|
|
378
|
+
onClose();
|
|
379
|
+
};
|
|
380
|
+
const submit = async (event: FormEvent) => {
|
|
381
|
+
event.preventDefault();
|
|
382
|
+
if (!integration) return;
|
|
383
|
+
const problem = samsaraSecretError(secret);
|
|
384
|
+
if (problem) {
|
|
385
|
+
setError(problem);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
setIsSaving(true);
|
|
389
|
+
setError(null);
|
|
390
|
+
try {
|
|
391
|
+
await onReplace(integration, secret.trim());
|
|
392
|
+
close();
|
|
393
|
+
} catch (replaceError) {
|
|
394
|
+
setError(errorMessage(replaceError, 'Could not replace the secret.'));
|
|
395
|
+
} finally {
|
|
396
|
+
setIsSaving(false);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
return (
|
|
400
|
+
<ResponsiveDialog open={integration !== null} onOpenChange={(open) => !open && close()}>
|
|
401
|
+
<ResponsiveDialogContent>
|
|
402
|
+
<form onSubmit={(event) => void submit(event)} className="space-y-4">
|
|
403
|
+
<ResponsiveDialogHeader>
|
|
404
|
+
<ResponsiveDialogTitle>
|
|
405
|
+
Replace the Samsara secret for {integration?.name}
|
|
406
|
+
</ResponsiveDialogTitle>
|
|
407
|
+
<ResponsiveDialogDescription>
|
|
408
|
+
Regenerate the secret on the webhook page in Samsara, then paste the new key here.
|
|
409
|
+
Deliveries signed with the old key are refused once you save.
|
|
410
|
+
</ResponsiveDialogDescription>
|
|
411
|
+
</ResponsiveDialogHeader>
|
|
412
|
+
<div className="space-y-1.5">
|
|
413
|
+
<Label htmlFor="samsara-new-secret">New Samsara webhook secret key</Label>
|
|
414
|
+
<Input
|
|
415
|
+
id="samsara-new-secret"
|
|
416
|
+
type="password"
|
|
417
|
+
autoComplete="off"
|
|
418
|
+
spellCheck={false}
|
|
419
|
+
value={secret}
|
|
420
|
+
onChange={(event) => setSecret(event.target.value)}
|
|
421
|
+
autoFocus
|
|
422
|
+
/>
|
|
423
|
+
</div>
|
|
424
|
+
<FormError message={error} />
|
|
425
|
+
<ResponsiveDialogFooter>
|
|
426
|
+
<Button type="button" variant="outline" onClick={close}>
|
|
427
|
+
Cancel
|
|
428
|
+
</Button>
|
|
429
|
+
<Button type="submit" disabled={isSaving}>
|
|
430
|
+
{isSaving ? 'Saving…' : 'Replace secret'}
|
|
431
|
+
</Button>
|
|
432
|
+
</ResponsiveDialogFooter>
|
|
433
|
+
</form>
|
|
434
|
+
</ResponsiveDialogContent>
|
|
435
|
+
</ResponsiveDialog>
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function SamsaraSetupInstructions({ url }: { url: string }) {
|
|
440
|
+
return (
|
|
441
|
+
<div className="space-y-3">
|
|
442
|
+
<p className="text-sm font-medium">How to connect Samsara</p>
|
|
443
|
+
<CopyField label="Webhook URL" value={url} />
|
|
444
|
+
<ol className="list-decimal space-y-1 pl-5 text-xs text-text-secondary">
|
|
445
|
+
<li>
|
|
446
|
+
In Samsara, open Settings → Developer → Webhooks, add a webhook with the URL above and
|
|
447
|
+
subscribe it to{' '}
|
|
448
|
+
{SAMSARA_EVENT_TYPES.map((event, index) => (
|
|
449
|
+
<span key={event.type}>
|
|
450
|
+
{index > 0 ? ', ' : ''}
|
|
451
|
+
<code className="font-mono">{event.type}</code>
|
|
452
|
+
</span>
|
|
453
|
+
))}
|
|
454
|
+
.
|
|
455
|
+
</li>
|
|
456
|
+
<li>
|
|
457
|
+
Route stop and geofence arrivals become Arrived events; departures become Departed events.
|
|
458
|
+
</li>
|
|
459
|
+
<li>
|
|
460
|
+
To match a shipment, put its MoveTheWheels tracking number in the route or stop external
|
|
461
|
+
ID under the key chosen when this feed was connected (default{' '}
|
|
462
|
+
<code className="font-mono">{DEFAULT_SAMSARA_SHIPMENT_KEY}</code>). Without one, the
|
|
463
|
+
Samsara vehicle name or licence plate is matched to a MoveTheWheels vehicle, and the event
|
|
464
|
+
goes to that vehicle's single in-progress route.
|
|
465
|
+
</li>
|
|
466
|
+
<li>
|
|
467
|
+
Samsara signs every delivery ({SAMSARA_SIGNATURE_HEADERS.join(' and ')}); deliveries with
|
|
468
|
+
a wrong signature or more than five minutes old are refused.
|
|
469
|
+
</li>
|
|
470
|
+
</ol>
|
|
471
|
+
</div>
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
284
475
|
function DeliveryLog({ integrationId, refreshKey }: { integrationId: string; refreshKey: number }) {
|
|
285
476
|
const { events, isLoading, error } = useCarrierIntegrationEvents(integrationId, refreshKey);
|
|
286
477
|
return (
|
|
@@ -388,7 +579,7 @@ function IntegrationCard({
|
|
|
388
579
|
</Badge>
|
|
389
580
|
</div>
|
|
390
581
|
<p className="text-xs text-text-secondary">
|
|
391
|
-
|
|
582
|
+
{providerLabel(integration.provider)} · {statusExplanation(integration.status)}
|
|
392
583
|
</p>
|
|
393
584
|
<p className="text-xs text-text-secondary">
|
|
394
585
|
Last accepted update:{' '}
|
|
@@ -419,7 +610,7 @@ function IntegrationCard({
|
|
|
419
610
|
</Button>
|
|
420
611
|
<Button size="sm" variant="outline" disabled={busy} onClick={onRotate}>
|
|
421
612
|
<KeyRound size={14} className="mr-1" />
|
|
422
|
-
Rotate secret
|
|
613
|
+
{integration.provider === 'SAMSARA' ? 'Replace secret' : 'Rotate secret'}
|
|
423
614
|
</Button>
|
|
424
615
|
<Button
|
|
425
616
|
size="sm"
|
|
@@ -443,7 +634,11 @@ function IntegrationCard({
|
|
|
443
634
|
</div>
|
|
444
635
|
{expanded ? (
|
|
445
636
|
<div className="mt-4 grid gap-6 border-t border-border-subtle pt-4 lg:grid-cols-2">
|
|
446
|
-
|
|
637
|
+
{integration.provider === 'SAMSARA' ? (
|
|
638
|
+
<SamsaraSetupInstructions url={url} />
|
|
639
|
+
) : (
|
|
640
|
+
<SetupInstructions url={url} />
|
|
641
|
+
)}
|
|
447
642
|
<DeliveryLog integrationId={integration.id} refreshKey={refreshKey} />
|
|
448
643
|
</div>
|
|
449
644
|
) : null}
|
|
@@ -472,6 +667,7 @@ function WorkspaceIntegrationsPage() {
|
|
|
472
667
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
473
668
|
const [expandedId, setExpandedId] = useState<string | null>(null);
|
|
474
669
|
const [createOpen, setCreateOpen] = useState(false);
|
|
670
|
+
const [replaceTarget, setReplaceTarget] = useState<CarrierIntegration | null>(null);
|
|
475
671
|
// Secrets waiting to be shown, oldest first. Each is shown once and cannot be
|
|
476
672
|
// read back, so concurrent rotations on different feeds queue instead of
|
|
477
673
|
// replacing an unacknowledged secret.
|
|
@@ -560,6 +756,13 @@ function WorkspaceIntegrationsPage() {
|
|
|
560
756
|
}
|
|
561
757
|
};
|
|
562
758
|
|
|
759
|
+
const replaceSamsaraSecret = async (integration: CarrierIntegration, secret: string) => {
|
|
760
|
+
await exclusive(integration.id, async () => {
|
|
761
|
+
await actions.update(integration.id, { apiSecret: secret });
|
|
762
|
+
done(`Replaced the Samsara secret for ${integration.name}.`);
|
|
763
|
+
});
|
|
764
|
+
};
|
|
765
|
+
|
|
563
766
|
const removeIntegration = async (integration: CarrierIntegration) => {
|
|
564
767
|
if (
|
|
565
768
|
!window.confirm(
|
|
@@ -682,7 +885,11 @@ function WorkspaceIntegrationsPage() {
|
|
|
682
885
|
onSetStatus={(next) =>
|
|
683
886
|
void exclusive(integration.id, () => setIntegrationStatus(integration, next))
|
|
684
887
|
}
|
|
685
|
-
onRotate={() =>
|
|
888
|
+
onRotate={() =>
|
|
889
|
+
integration.provider === 'SAMSARA'
|
|
890
|
+
? setReplaceTarget(integration)
|
|
891
|
+
: void exclusive(integration.id, () => rotateSecret(integration))
|
|
892
|
+
}
|
|
686
893
|
onDelete={() => void exclusive(integration.id, () => removeIntegration(integration))}
|
|
687
894
|
/>
|
|
688
895
|
))}
|
|
@@ -717,13 +924,23 @@ function WorkspaceIntegrationsPage() {
|
|
|
717
924
|
|
|
718
925
|
<Card>
|
|
719
926
|
<CardContent className="space-y-2 p-5">
|
|
720
|
-
<p className="text-sm font-medium">Carrier networks</p>
|
|
927
|
+
<p className="text-sm font-medium">Carrier and ELD networks</p>
|
|
721
928
|
<p className="text-sm text-text-secondary">
|
|
722
|
-
|
|
929
|
+
Samsara connects directly: choose it when you connect a feed. Direct connections to{' '}
|
|
930
|
+
{[
|
|
931
|
+
...ROADMAP_PROVIDERS.map((provider) => provider.label),
|
|
932
|
+
...PLANNED_ELD_PROVIDERS,
|
|
933
|
+
].join(', ')}{' '}
|
|
723
934
|
are not available yet. Until they are, any carrier or telematics system that can send
|
|
724
935
|
HTTPS webhooks connects through a signed feed above.
|
|
725
936
|
</p>
|
|
726
937
|
<div className="flex flex-wrap gap-2">
|
|
938
|
+
<Badge variant="default">Samsara · available</Badge>
|
|
939
|
+
{PLANNED_ELD_PROVIDERS.map((label) => (
|
|
940
|
+
<Badge key={label} variant="outline">
|
|
941
|
+
{label} · not available yet
|
|
942
|
+
</Badge>
|
|
943
|
+
))}
|
|
727
944
|
{ROADMAP_PROVIDERS.map((provider) => (
|
|
728
945
|
<Badge key={provider.id} variant="outline">
|
|
729
946
|
{provider.label} · not available yet
|
|
@@ -738,10 +955,15 @@ function WorkspaceIntegrationsPage() {
|
|
|
738
955
|
onOpenChange={setCreateOpen}
|
|
739
956
|
onCreated={(integration, secret) => {
|
|
740
957
|
setExpandedId(integration.id);
|
|
741
|
-
reveal(integration.name, secret);
|
|
958
|
+
if (secret) reveal(integration.name, secret);
|
|
742
959
|
done(`Connected ${integration.name}.`);
|
|
743
960
|
}}
|
|
744
961
|
/>
|
|
962
|
+
<ReplaceSamsaraSecretDialog
|
|
963
|
+
integration={replaceTarget}
|
|
964
|
+
onClose={() => setReplaceTarget(null)}
|
|
965
|
+
onReplace={replaceSamsaraSecret}
|
|
966
|
+
/>
|
|
745
967
|
<SecretRevealDialog
|
|
746
968
|
secret={revealed?.secret ?? null}
|
|
747
969
|
integrationName={revealed?.name ?? ''}
|
|
@@ -1,31 +1,99 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Carrier and telematics integrations (BOFF-4404).
|
|
2
|
+
* Carrier and telematics integrations (BOFF-4404, Samsara in BOFF-10703).
|
|
3
3
|
*
|
|
4
4
|
* A workspace connects an external carrier, ELD or GPS feed to MoveTheWheels
|
|
5
|
-
* as a signed webhook.
|
|
6
|
-
* request body using
|
|
7
|
-
*
|
|
5
|
+
* as a signed webhook. A generic feed is verified with HMAC-SHA256 over the
|
|
6
|
+
* raw request body using a secret generated here; a Samsara feed is verified
|
|
7
|
+
* with Samsara's own timestamped signature using the secret Samsara issues.
|
|
8
|
+
* Every accepted update becomes a tracking event on the matching shipment.
|
|
8
9
|
*
|
|
9
10
|
* This module holds the GraphQL documents and the pure helpers the page uses;
|
|
10
11
|
* the network calls live in `hooks/useCarrierIntegrations`.
|
|
11
12
|
*/
|
|
12
13
|
import { resolveGraphqlUrl } from './graphqlClient';
|
|
13
14
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Providers this page can connect. The service also ingests SHIPROCKET, which
|
|
17
|
+
* is set up from the Shiprocket carrier flow rather than here.
|
|
18
|
+
*/
|
|
19
|
+
export const SUPPORTED_PROVIDERS = ['GENERIC_WEBHOOK', 'SAMSARA'] as const;
|
|
16
20
|
export type SupportedProvider = (typeof SUPPORTED_PROVIDERS)[number];
|
|
17
21
|
|
|
18
|
-
/** Named networks
|
|
22
|
+
/** Named networks without an adapter yet; the service refuses the reserved ones. */
|
|
19
23
|
export const ROADMAP_PROVIDERS = [
|
|
20
24
|
{ id: 'PROJECT44', label: 'project44' },
|
|
21
25
|
{ id: 'FOURKITES', label: 'FourKites' },
|
|
22
26
|
{ id: 'DESCARTES', label: 'Descartes' },
|
|
23
27
|
] as const;
|
|
24
28
|
|
|
29
|
+
/** ELD networks planned after Samsara (BOFF-10703 follow-ups); not in the schema yet. */
|
|
30
|
+
export const PLANNED_ELD_PROVIDERS = ['Motive', 'Geotab'] as const;
|
|
31
|
+
|
|
25
32
|
export const INTEGRATION_STATUSES = ['ACTIVE', 'PAUSED', 'DISABLED'] as const;
|
|
26
33
|
export type IntegrationStatus = (typeof INTEGRATION_STATUSES)[number];
|
|
27
34
|
|
|
28
|
-
export type IntegrationProvider =
|
|
35
|
+
export type IntegrationProvider =
|
|
36
|
+
'GENERIC_WEBHOOK' | 'SAMSARA' | 'SHIPROCKET' | 'PROJECT44' | 'FOURKITES' | 'DESCARTES';
|
|
37
|
+
|
|
38
|
+
/** How each provider is named on the page. */
|
|
39
|
+
export function providerLabel(provider: IntegrationProvider): string {
|
|
40
|
+
switch (provider) {
|
|
41
|
+
case 'GENERIC_WEBHOOK':
|
|
42
|
+
return 'Signed webhook';
|
|
43
|
+
case 'SAMSARA':
|
|
44
|
+
return 'Samsara';
|
|
45
|
+
case 'SHIPROCKET':
|
|
46
|
+
return 'Shiprocket';
|
|
47
|
+
case 'PROJECT44':
|
|
48
|
+
return 'project44';
|
|
49
|
+
case 'FOURKITES':
|
|
50
|
+
return 'FourKites';
|
|
51
|
+
case 'DESCARTES':
|
|
52
|
+
return 'Descartes';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Samsara webhook event types the service turns into tracking events. */
|
|
57
|
+
export const SAMSARA_EVENT_TYPES = [
|
|
58
|
+
{ type: 'RouteStopArrival', becomes: 'ARRIVED' },
|
|
59
|
+
{ type: 'RouteStopDeparture', becomes: 'DEPARTED' },
|
|
60
|
+
{ type: 'GeofenceEntry', becomes: 'ARRIVED' },
|
|
61
|
+
{ type: 'GeofenceExit', becomes: 'DEPARTED' },
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
64
|
+
/** Route or stop external id key the service reads the shipment reference from by default. */
|
|
65
|
+
export const DEFAULT_SAMSARA_SHIPMENT_KEY = 'mtwShipment';
|
|
66
|
+
|
|
67
|
+
/** The service refuses Samsara secrets that decode to fewer bytes than this. */
|
|
68
|
+
export const MIN_SAMSARA_SECRET_BYTES = 16;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Returns an error message for an unusable Samsara webhook secret, or null.
|
|
72
|
+
* Samsara shows the secret Base64-encoded; it must be pasted exactly.
|
|
73
|
+
*/
|
|
74
|
+
export function samsaraSecretError(secret: string): string | null {
|
|
75
|
+
const trimmed = secret.trim();
|
|
76
|
+
const message = 'Paste the secret key exactly as Samsara shows it on the webhook page.';
|
|
77
|
+
if (!trimmed || trimmed.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(trimmed)) {
|
|
78
|
+
return message;
|
|
79
|
+
}
|
|
80
|
+
const padding = trimmed.endsWith('==') ? 2 : trimmed.endsWith('=') ? 1 : 0;
|
|
81
|
+
const bytes = (trimmed.length / 4) * 3 - padding;
|
|
82
|
+
return bytes < MIN_SAMSARA_SECRET_BYTES ? message : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Returns an error message for an unusable external id key, or null. */
|
|
86
|
+
export function externalIdKeyError(key: string): string | null {
|
|
87
|
+
const trimmed = key.trim();
|
|
88
|
+
if (!trimmed) return null;
|
|
89
|
+
if (trimmed.length > 64 || !/^[A-Za-z0-9_.-]+$/.test(trimmed)) {
|
|
90
|
+
return 'Use letters, numbers, dots, dashes or underscores (up to 64) for the external ID key.';
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Headers Samsara signs each delivery with; the workspace gateway forwards both. */
|
|
96
|
+
export const SAMSARA_SIGNATURE_HEADERS = ['X-Samsara-Signature', 'X-Samsara-Timestamp'] as const;
|
|
29
97
|
|
|
30
98
|
export type IntegrationEventStatus =
|
|
31
99
|
'RECEIVED' | 'ACCEPTED' | 'PARTIAL' | 'REJECTED' | 'DUPLICATE' | 'CONFLICT';
|