Repository navigation
Expand file tree
/
Copy pathswagger.yaml
More file actions
7976 lines (7921 loc) · 257 KB
/
Copy pathswagger.yaml
File metadata and controls
7976 lines (7921 loc) · 257 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.0
info:
title: Navin Backend API
version: 1.0.0
license:
name: MIT
url: https://opensource.org/licenses/MIT
description: |
Navin Backend is the logistics / supply-chain HTTP API for shipment lifecycle management,
IoT telemetry ingest and anomaly detection, Stellar-backed settlements/payments, and
organization administration.
## Authentication
### JWT Bearer (`bearerAuth`)
Most protected endpoints require `Authorization: Bearer <JWT>`. Tokens are issued by
`/api/auth/login`, `/api/auth/signup`, `/api/auth/register/company`, or `/api/auth/refresh`. Claims include `userId`,
`role` (`SUPER_ADMIN` | `ADMIN` | `MANAGER` | `VIEWER` | `CUSTOMER`), optional
`organizationId` / `organizationType` (`ENTERPRISE` | `LOGISTICS`), and `jti` (used for
logout / revocation). Role permissions and frontend persona mapping are documented in
`docs/auth-model.md`.
### API key (`apiKeyAuth`)
Machine / IoT clients authenticate with the `x-api-key` header on selected webhook
endpoints (notably `POST /api/webhooks/iot`). API keys are managed under `/api/auth/api-keys`
by ADMIN / SUPER_ADMIN users.
### Stellar webhook signature (`stellarSignature`)
`POST /api/webhooks/stellar` requires an HMAC-SHA256 digest in `x-stellar-signature`,
computed over the raw body with `STELLAR_WEBHOOK_SECRET`.
## Response envelope
Successful JSON handlers use a standard envelope via `sendResponse`:
```json
{
"success": true,
"message": "...",
"data": { },
"meta": { }
}
```
`meta` is optional and holds pagination cursors / totals. A few endpoints intentionally
diverge (for example shipment CSV/JSON export and SSE event streams).
## Pagination
Use **cursor** pagination (`cursor`, `limit` → `meta.nextCursor`, `meta.hasMore`) for large
collections (telemetry, anomalies, payments/settlements, audit logs, users). Use **offset**
pagination (`page`, `limit` → `meta.page`, `meta.limit`, `meta.total`) for bounded admin
lists (shipments). Telemetry additionally accepts legacy `page` for dashboard clients, but
`cursor` and `page` must not be combined. Pagination fields always live in `meta`, never in
`data`. See `docs/PAGINATION.md`.
## Error handling
Errors return JSON with `success: false`, a human-readable `message`, `data: null`, and an
`error.code` string (plus optional `details` for validation failures). Common HTTP statuses
include 400 (validation / bad request), 401 (missing or invalid credentials), 403
(insufficient role), 404 (resource not found), and 409 (conflict such as duplicate email).
contact:
name: Navin Backend Maintainers
url: https://github.com/Navin-xmr/navin-backend
servers:
- url: http://localhost:3000
description: Local development server (default PORT=3000)
- url: https://{productionHost}
description: Production API host (placeholder — set productionHost to your deployed API base URL; no canonical production URL is published in this repository)
variables:
productionHost:
default: api.example.com
description: Replace with the real production API hostname when deploying
x-rate-limit:
standard:
limit: 100
window: 15 minutes
strict:
limit: 20
window: 15 minutes
login:
limit: 5
window: 15 minutes
paths:
/api/webhooks/iot:
post:
operationId: webhooks_post_webhooks_iot
tags:
- Webhooks
summary: IoT webhook — ingest telemetry into the anchoring pipeline
description: |
Receives telemetry from IoT sensors/gateways and kicks off the async ingestion pipeline:
1. **Normalize** — union payload → canonical fields (`normalizeIotWebhookBody`)
2. **Persist** — MongoDB telemetry with `anchorStatus=PENDING_ANCHOR` and `dataHash`
3. **Queue** — enqueue BullMQ job on `transaction_queue` (`anchor_telemetry`)
4. **Emit socket** — `location:update` to the shipment room
5. **Detect anomaly** (async `setImmediate` → `detectTelemetryAnomalies`) — org/shipment thresholds default to **maxTemp=25°C / maxHumidity=80% / minBatteryLevel=20%**; types `TEMPERATURE_BREACH` / `HUMIDITY_BREACH` / `SHOCK_EVENT` / `GPS_LOST` / `BATTERY_LOW` at severity `HIGH`
6. **Alert** — on detection, emit `anomaly:detected` and push to `alert_queue`
Returns **202 Accepted** as soon as the record is stored and the anchor job is queued.
Stellar anchoring is completed by `stellar.worker` consuming `transaction_queue`.
See `docs/telemetry-pipeline.md` for the full sequence diagram.
security:
- apiKeyAuth: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/IotWebhookBody'
examples:
normalizedShipmentPayload:
summary: Shipment-centric (normalized) payload
value:
shipmentId: '507f1f77bcf86cd799439011'
temperature: 22.5
humidity: 55
latitude: 12.34
longitude: 56.78
batteryLevel: 88
timestamp: '2026-01-15T12:30:00.000Z'
sensorCentricPayload:
summary: Sensor-centric payload (temp + location)
value:
sensorId: 'SENSOR-42'
temp: 22.5
humidity: 55
location:
lat: 12.34
lng: 56.78
batteryLevel: 88
timestamp: '2026-01-15T12:30:00.000Z'
responses:
'202':
description: >
Telemetry accepted and queued for Stellar anchoring.
Anomaly detection runs asynchronously after this response.
content:
application/json:
schema:
$ref: '#/components/schemas/IotWebhookAcceptedResponse'
example:
success: true
message: Telemetry received and queued for Stellar anchoring
data:
_id: t1
shipmentId: '507f1f77bcf86cd799439011'
sensorId: 'SENSOR-42'
temperature: 22.5
humidity: 55
latitude: 12.34
longitude: 56.78
batteryLevel: 88
timestamp: '2026-01-15T12:30:00.000Z'
dataHash: 'a1b2c3...'
anchorStatus: PENDING_ANCHOR
'400':
description: Invalid request payload (Zod validation failure or unresolvable shipmentId)
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Missing or invalid API key
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: No active shipment found for the given sensorId
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/webhooks/stellar:
post:
operationId: webhooks_post_webhooks_stellar
tags:
- Webhooks
summary: Stellar proof-of-delivery / settlement webhook
description: |
Receives Stellar settlement callbacks for proof-of-delivery and escrow events
(`release`, `escrow`, `failed`). This is the settlement side of the telemetry
pipeline — distinct from BullMQ `transaction_queue` hash anchoring.
Requires a valid HMAC-SHA256 signature in the `x-stellar-signature` header,
computed over the raw request body using `STELLAR_WEBHOOK_SECRET`.
On `release`, payment status becomes RELEASED and a `SETTLEMENT_COMPLETED`
ledger block may be written. See `docs/telemetry-pipeline.md`.
security:
- stellarSignature: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/StellarWebhookPayload'
example:
id: evt_01HXYZ
type: release
paymentId: '507f1f77bcf86cd799439022'
transactionHash: 'a1b2c3d4e5f6...'
amount: 1500
timestamp: '2026-01-15T13:00:00.000Z'
responses:
'200':
description: Stellar webhook received and processed successfully
content:
application/json:
schema:
$ref: '#/components/schemas/StellarWebhookResponse'
'400':
description: Invalid Stellar webhook payload or unknown event type
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Missing or invalid x-stellar-signature header
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/health:
get:
operationId: health_get_health
tags:
- Health
summary: Health check
description: Public health endpoint used by load balancers and uptime monitors.
security: []
responses:
'200':
description: Service health metadata
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: OK
data:
type: object
properties:
status:
type: string
example: active
uptime:
type: number
description: Process uptime in seconds
timestamp:
type: string
format: date-time
description: Current UTC timestamp
'400':
description: Invalid request (should not occur for this endpoint)
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications:
get:
operationId: notifications_get_notifications
tags: [Notifications]
summary: List notifications
description: >
Returns the authenticated user's notifications, newest first, with
offset pagination. Optionally filtered by type and full-text search.
security:
- bearerAuth: []
parameters:
- in: query
name: page
schema:
type: integer
minimum: 1
default: 1
description: Page number (1-based).
- in: query
name: limit
schema:
type: integer
minimum: 1
maximum: 100
default: 20
description: Notifications per page.
- in: query
name: type
schema:
type: string
enum: [shipments, settlements, system]
description: Filter by notification category.
- in: query
name: q
schema:
type: string
description: Search title/description text (case-insensitive substring).
responses:
'200':
description: Notifications retrieved successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Notifications retrieved successfully
data:
type: array
items:
$ref: '#/components/schemas/Notification'
meta:
type: object
properties:
page:
type: integer
limit:
type: integer
total:
type: integer
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications/unread-count:
get:
operationId: notifications_get_notifications_unread_count
tags: [Notifications]
summary: Get unread notifications count
description: Returns the number of unread notifications for the authenticated user.
security:
- bearerAuth: []
responses:
'200':
description: Unread count retrieved successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Unread count retrieved successfully
data:
type: object
properties:
count:
type: integer
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications/read-all:
post:
operationId: notifications_post_notifications_read_all
tags: [Notifications]
summary: Mark all notifications as read
description: Marks every unread notification of the authenticated user as read.
security:
- bearerAuth: []
responses:
'200':
description: Notifications marked as read
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: 3 notifications marked as read
data:
type: object
properties:
count:
type: integer
description: Number of notifications updated.
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications/{id}/read:
patch:
operationId: notifications_patch_notifications_id_read
tags: [Notifications]
summary: Mark a notification as read
description: Marks the specified notification as read. Only the owning user can update it.
security:
- bearerAuth: []
parameters:
- in: path
name: id
required: true
schema:
type: string
description: Notification ObjectId.
responses:
'200':
description: Notification marked as read
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Notification marked as read
data:
$ref: '#/components/schemas/Notification'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Notification not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications/{id}:
delete:
operationId: notifications_delete_notifications_id
tags: [Notifications]
summary: Delete a notification
description: Soft-deletes the specified notification. Only the owning user can delete it.
security:
- bearerAuth: []
parameters:
- in: path
name: id
required: true
schema:
type: string
description: Notification ObjectId.
responses:
'200':
description: Notification deleted successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Notification deleted successfully
data:
$ref: '#/components/schemas/Notification'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Notification not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications/preferences:
get:
operationId: notifications_get_notifications_preferences
tags: [Notifications]
summary: Get notification channel preferences
description: Returns all notification preferences for the authenticated user.
security:
- bearerAuth: []
responses:
'200':
description: Notification preferences retrieved successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Notification preferences retrieved successfully
data:
type: array
items:
$ref: '#/components/schemas/NotificationPreference'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
patch:
operationId: notifications_patch_notifications_preferences
tags: [Notifications]
summary: Update a notification preference
description: >
Creates or updates the preference for the given event/channel pair
(upsert). Only the enabled flag can be toggled per pair.
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [event, channel, enabled]
properties:
event:
type: string
enum:
[
shipment_created,
status_changed,
delivery_confirmed,
payment_received,
dispute_opened,
dispute_resolved,
]
channel:
type: string
enum: [email, sms]
enabled:
type: boolean
responses:
'200':
description: Notification preference updated successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Notification preference updated successfully
data:
$ref: '#/components/schemas/NotificationPreference'
'400':
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/notifications/phone/send-otp:
post:
operationId: notifications_post_notifications_phone_send_otp
tags: [Notifications]
summary: Send an SMS OTP to a phone number
description: >
Generates a 6-digit OTP, stores its hash in Redis (5-minute TTL) and
delivers it via Twilio (production) or logs it (dev/test). Rate limited
to 5 requests per 15 minutes per IP.
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [phone]
properties:
phone:
type: string
pattern: '^\+?[1-9]\d{9,14}$'
minLength: 10
maxLength: 15
description: Phone number in E.164-ish format (e.g. +15551234567).
responses:
'200':
description: OTP sent successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: OTP sent successfully
data:
type: string
nullable: true
example: null
'400':
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'429':
description: Too many OTP requests, please try again later.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
message:
type: string
retryAfter:
type: integer
data:
type: string
nullable: true
/api/notifications/phone/verify-otp:
post:
operationId: notifications_post_notifications_phone_verify_otp
tags: [Notifications]
summary: Verify an SMS OTP
description: >
Checks the submitted OTP against the stored hash, then marks the user's
phone as verified. Rate limited to 5 requests per 15 minutes per IP.
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [phone, otp]
properties:
phone:
type: string
pattern: '^\+?[1-9]\d{9,14}$'
minLength: 10
maxLength: 15
otp:
type: string
pattern: '^\d{6}$'
minLength: 6
maxLength: 6
description: The 6-digit code received via SMS.
responses:
'200':
description: Phone verified successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Phone verified successfully
data:
type: object
properties:
_id:
type: string
email:
type: string
name:
type: string
role:
type: string
phone:
type: string
nullable: true
phoneVerified:
type: boolean
organizationId:
type: string
nullable: true
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
'400':
description: Invalid or expired OTP
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'429':
description: Too many OTP requests, please try again later.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
message:
type: string
retryAfter:
type: integer
data:
type: string
nullable: true
/api/public/tracking/{trackingNumber}:
get:
operationId: public_tracking_get_public_tracking_trackingnumber
tags: [Public Tracking]
summary: Public shipment tracking by tracking number
description: |
Unauthenticated public tracking endpoint. Returns a safe subset of shipment
data suitable for public tracking pages. No authentication required.
Rate limited to prevent abuse.
x-implemented: true
x-required-role: none
security: []
parameters:
- in: path
name: trackingNumber
required: true
schema:
type: string
pattern: '^[A-Za-z0-9_-]+$'
maxLength: 64
description: Carrier tracking number (e.g., NVN-123456)
responses:
'200':
description: Shipment tracking information retrieved successfully
content:
application/json:
schema:
type: object
required: [success, message, data]
properties:
success:
type: boolean
example: true
message:
type: string
example: Shipment tracking retrieved
data:
$ref: '#/components/schemas/PublicTrackingResponse'
'404':
description: Shipment not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'400':
description: Invalid tracking number parameter
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'429':
description: Too many requests
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/events:
get:
operationId: events_get_events
summary: Real-time event stream (SSE)
description: |
Status: implemented (x-implemented: true). Listed in API-QA #398 for completeness.
Opens a Server-Sent Events stream for the authenticated user. Events are scoped
per user via Redis pub/sub channels and include shipment, settlement, anomaly,
and location updates. A heartbeat comment is sent every 30 seconds.
Authentication accepts either `Authorization: Bearer <token>` or `?token=<jwt>`
for EventSource clients that cannot set custom headers.
tags:
- Events
security:
- bearerAuth: []
parameters:
- in: query
name: token
required: false
schema:
type: string
description: JWT for EventSource clients that cannot send Authorization headers
responses:
'200':
description: SSE stream opened
content:
text/event-stream:
schema:
type: string
description: |
Stream of SSE messages. Event types: shipment:status, shipment:milestone,
settlement:status, notification:new, anomaly:detected, location:update.
examples:
shipmentStatus:
summary: Shipment status change
value: |
event: shipment:status
data: {"type":"shipment:status","shipmentId":"671000000000000000000001","newStatus":"IN_TRANSIT","timestamp":"2026-01-15T12:00:00.000Z"}
heartbeat:
summary: Keep-alive heartbeat (every 30s)
value: |
: heartbeat
'401':
description: Missing, invalid, or revoked JWT
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/auth/api-keys:
post:
operationId: api_keys_post_auth_api_keys
tags:
- API Keys
x-required-role: [ADMIN, SUPER_ADMIN]
summary: Create a new API key
description: Generates a new API key for machine-to-machine authentication. The raw API key is returned only once.
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- name
- organizationId
properties:
name:
type: string
description: Descriptive name for the API key
organizationId:
type: string
description: MongoDB ObjectId of the organization
shipmentId:
type: string
description: Optional MongoDB ObjectId of a specific shipment
responses:
'201':
description: API key created successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
data:
type: object
properties:
apiKey:
type: string
description: Raw API key (shown only once)
id:
type: string
name:
type: string
organizationId:
type: string
shipmentId:
type: string
createdAt:
type: string
format: date-time
'400':
description: Invalid request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/auth/sessions:
get:
operationId: auth_get_auth_sessions
summary: List active sessions
description: |
Returns all active session records for the authenticated user (one per device/login).
Sessions are ordered newest-first.
tags:
- Auth
security:
- bearerAuth: []
responses:
'200':
description: Session list retrieved successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Sessions retrieved
data:
type: array
items:
$ref: '#/components/schemas/Session'
'401':
description: Missing or invalid authorization token
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/auth/sessions/{jti}:
delete:
operationId: auth_delete_auth_sessions_jti
summary: Revoke a session
description: |
Blocklists the token identified by `jti` in Redis and removes the session record.
The token will be rejected immediately by `requireAuth` on subsequent requests.
- Returns **403** if the session belongs to a different user (cross-user revocation).
- Returns **404** if no session with that `jti` exists.
tags:
- Auth
security:
- bearerAuth: []
parameters:
- in: path
name: jti
required: true
schema:
type: string
description: The JWT ID (`jti` claim) of the session to revoke
responses:
'200':
description: Session revoked successfully
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Session revoked successfully
data:
type: string