-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathopenapi.yaml
More file actions
5958 lines (5774 loc) · 177 KB
/
Copy pathopenapi.yaml
File metadata and controls
5958 lines (5774 loc) · 177 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.3
info:
title: AidLink Backend API
version: 1.0.0
description: |
Production-grade REST API for AidLink — a blockchain-powered humanitarian aid platform built on Soroban/Stellar.
## Authentication
All protected endpoints require a Bearer JWT in the `Authorization` header:
```
Authorization: Bearer <access_token>
```
Tokens are obtained via `POST /api/v1/auth/login` or `POST /api/v1/auth/wallet`.
Access tokens expire in 15 minutes; use `POST /api/v1/auth/refresh` with the refresh token.
## Rate Limits
Rate limit headers are returned on every response (`RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`).
| Scope | Limit |
|---|---|
| Global API | 100 req / 15 min per IP |
| Auth endpoints | 5 req / 15 min per IP |
| Donation creation | 10 req / min per user |
| Campaign creation | 3 req / hour per user |
| Distribution creation | 5 req / min per user |
| Search | 30 req / min per user |
| Analytics | 20 req / min per user |
| Notifications | 10 req / min per user |
| Fraud reports | 5 req / hour per user |
## Roles
| Role | Description |
|---|---|
| ADMIN | Full platform access |
| ORGANIZATION | Manages campaigns and distributions |
| DONOR | Creates donations |
| BENEFICIARY | Receives distributions, submits KYC |
| VERIFIER | Reviews KYC and beneficiary data |
| AUDITOR | Read-only audit access |
## Errors
All errors follow a consistent envelope:
```json
{ "success": false, "error": "Human-readable message", "details": [...] }
```
contact:
name: AidLink Team
email: dev@aidlink.org
license:
name: MIT
servers:
- url: http://localhost:3000
description: Local development
- url: https://api-staging.aidlink.org
description: Staging
- url: https://api.aidlink.org
description: Production
tags:
- name: Authentication
description: Register, login, wallet auth, token refresh, session management
- name: Campaigns
description: Campaign lifecycle — create, update, fund-track, milestone and beneficiary assignment
- name: Donations
description: Donor contributions and blockchain confirmation
- name: Beneficiaries
description: Beneficiary profiles, KYC submissions and review
- name: Distributions
description: Fund disbursement to beneficiaries with proof tracking
- name: Notifications
description: In-app and push notification management
- name: Admin
description: Platform administration — users, audit logs, moderation, system health
- name: Organizations
description: NGO/organization profiles, bank accounts and verification workflow
- name: Analytics
description: Campaign, donor, organization and platform-wide metrics
- name: Search
description: Full-text and filtered search across entities
- name: Upload
description: File upload — profile pictures, KYC documents, campaign images, distribution proofs
- name: Moderation
description: Fraud reports, campaign suspensions and appeals
# ---------------------------------------------------------------------------
# COMPONENTS
# ---------------------------------------------------------------------------
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
description: JWT access token obtained from /auth/login or /auth/wallet
schemas:
# ── Generic wrappers ────────────────────────────────────────────────────
SuccessResponse:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: Operation completed successfully
data:
type: object
PaginatedMeta:
type: object
properties:
page:
type: integer
example: 1
limit:
type: integer
example: 20
total:
type: integer
example: 142
pages:
type: integer
example: 8
ErrorResponse:
type: object
required: [success, error]
properties:
success:
type: boolean
example: false
error:
type: string
example: Validation failed
details:
type: array
items:
type: object
properties:
field:
type: string
message:
type: string
# ── Enums ──────────────────────────────────────────────────────────────
Role:
type: string
enum: [ADMIN, ORGANIZATION, DONOR, BENEFICIARY, VERIFIER, AUDITOR]
UserStatus:
type: string
enum: [ACTIVE, SUSPENDED, PENDING_VERIFICATION, REJECTED, DELETED]
CampaignStatus:
type: string
enum: [DRAFT, ACTIVE, PAUSED, COMPLETED, CANCELLED, SUSPENDED, PENDING_REVIEW]
DonationStatus:
type: string
enum: [PENDING, CONFIRMED, FAILED, REFUNDED]
BeneficiaryStatus:
type: string
enum: [PENDING, VERIFIED, REJECTED, SUSPENDED, ACTIVE]
DistributionStatus:
type: string
enum: [PENDING, IN_PROGRESS, COMPLETED, FAILED, CANCELLED]
DistributionMethod:
type: string
enum: [CASH, BANK_TRANSFER, MOBILE_MONEY, CRYPTO, VOUCHER, IN_KIND]
KYCStatus:
type: string
enum: [PENDING, UNDER_REVIEW, APPROVED, REJECTED, EXPIRED]
NotificationType:
type: string
enum:
- DONATION_RECEIVED
- CAMPAIGN_UPDATE
- DISTRIBUTION_SENT
- KYC_APPROVED
- KYC_REJECTED
- SYSTEM_ALERT
- SECURITY_ALERT
- CAMPAIGN_SUSPENDED
- CAMPAIGN_REINSTATED
- APPEAL_UPDATE
AppealStatus:
type: string
enum: [OPEN, UNDER_REVIEW, APPROVED, DENIED]
FraudReportType:
type: string
enum: [SCAM, MISINFORMATION, INAPPROPRIATE_CONTENT, IMPERSONATION, DUPLICATE, OTHER]
OrganizationStatus:
type: string
enum: [PENDING, APPROVED, SUSPENDED, REJECTED]
OrganizationVerificationStatus:
type: string
enum: [UNVERIFIED, PENDING_VERIFICATION, VERIFIED, REJECTED, SUSPENDED, MORE_INFO_REQUESTED]
# ── Core models ────────────────────────────────────────────────────────
User:
type: object
properties:
id:
type: string
example: clx1a2b3c4d5e6f7g8h9
email:
type: string
format: email
example: donor@example.com
username:
type: string
example: john_donor
walletAddress:
type: string
example: GBKZRTIOAHMXIJKUQPMKLF6JYLXV2PJHFGXZQ4LQXSWM5YIZD3HMGKQ
role:
$ref: '#/components/schemas/Role'
status:
$ref: '#/components/schemas/UserStatus'
emailVerified:
type: boolean
lastLogin:
type: string
format: date-time
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
Session:
type: object
properties:
accessToken:
type: string
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
refreshToken:
type: string
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
expiresIn:
type: integer
description: Seconds until access token expires
example: 900
user:
$ref: '#/components/schemas/User'
Organization:
type: object
properties:
id:
type: string
example: clx2org0001
userId:
type: string
name:
type: string
example: Hope Foundation
email:
type: string
format: email
country:
type: string
example: Kenya
description:
type: string
website:
type: string
format: uri
logo:
type: string
format: uri
registrationNumber:
type: string
taxId:
type: string
status:
$ref: '#/components/schemas/OrganizationStatus'
verificationStatus:
$ref: '#/components/schemas/OrganizationVerificationStatus'
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
BankAccount:
type: object
properties:
id:
type: string
example: clxbank001
organizationId:
type: string
bankName:
type: string
example: Equity Bank Kenya
accountHolderName:
type: string
example: Hope Foundation
accountNumber:
type: string
example: "1234567890"
routingNumber:
type: string
iban:
type: string
accountType:
type: string
example: CHECKING
currency:
type: string
example: USD
country:
type: string
verificationStatus:
type: string
enum: [UNVERIFIED, PENDING_VERIFICATION, VERIFIED, REJECTED, ARCHIVED]
isPrimary:
type: boolean
createdAt:
type: string
format: date-time
Campaign:
type: object
properties:
id:
type: string
example: clxcamp001
organizationId:
type: string
userId:
type: string
title:
type: string
example: Clean Water for Northern Kenya
description:
type: string
imageUrl:
type: string
format: uri
targetAmount:
type: string
description: Decimal string to preserve precision
example: "50000.00"
currentAmount:
type: string
example: "12500.00"
startDate:
type: string
format: date-time
endDate:
type: string
format: date-time
status:
$ref: '#/components/schemas/CampaignStatus'
blockchainTxHash:
type: string
contractAddress:
type: string
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
CampaignStats:
type: object
properties:
campaignId:
type: string
example: clxcamp001
totalDonated:
type: string
example: "12500.00"
description: Sum of all confirmed donations
totalMatched:
type: string
example: "3750.00"
description: Quadratic matching funds added
combinedRaised:
type: string
example: "16250.00"
description: totalDonated + totalMatched
donationCount:
type: integer
example: 47
beneficiaryCount:
type: integer
example: 12
distributionCount:
type: integer
example: 8
percentFunded:
type: number
format: float
example: 32.5
Milestone:
type: object
properties:
id:
type: string
campaignId:
type: string
title:
type: string
example: Drill first borehole
description:
type: string
targetAmount:
type: string
example: "10000.00"
achieved:
type: boolean
achievedAt:
type: string
format: date-time
order:
type: integer
example: 1
createdAt:
type: string
format: date-time
Donation:
type: object
properties:
id:
type: string
example: clxdon001
campaignId:
type: string
userId:
type: string
amount:
type: string
example: "250.00"
currency:
type: string
example: XLM
status:
$ref: '#/components/schemas/DonationStatus'
blockchainTxHash:
type: string
example: a3f8c2d1e4b5...
fromWallet:
type: string
toWallet:
type: string
memo:
type: string
isAnonymous:
type: boolean
donorMessage:
type: string
matchedFunds:
type: string
description: Quadratic match amount added to this donation
example: "75.00"
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
Beneficiary:
type: object
properties:
id:
type: string
example: clxben001
userId:
type: string
firstName:
type: string
example: Amina
lastName:
type: string
example: Hassan
dateOfBirth:
type: string
format: date-time
gender:
type: string
example: FEMALE
nationality:
type: string
example: Kenyan
idDocumentType:
type: string
example: NATIONAL_ID
idDocumentNumber:
type: string
phoneNumber:
type: string
address:
type: string
city:
type: string
example: Nairobi
country:
type: string
example: Kenya
familySize:
type: integer
example: 4
status:
$ref: '#/components/schemas/BeneficiaryStatus'
riskScore:
type: integer
example: 15
createdAt:
type: string
format: date-time
KYCSubmission:
type: object
properties:
id:
type: string
userId:
type: string
beneficiaryId:
type: string
submissionType:
type: string
example: INDIVIDUAL
status:
$ref: '#/components/schemas/KYCStatus'
documentType:
type: string
example: NATIONAL_ID
documentUrl:
type: string
format: uri
selfieUrl:
type: string
format: uri
reviewNotes:
type: string
reviewedAt:
type: string
format: date-time
fraudScore:
type: integer
example: 5
createdAt:
type: string
format: date-time
Distribution:
type: object
properties:
id:
type: string
example: clxdist001
campaignId:
type: string
beneficiaryId:
type: string
amount:
type: string
example: "500.00"
currency:
type: string
example: XLM
method:
$ref: '#/components/schemas/DistributionMethod'
status:
$ref: '#/components/schemas/DistributionStatus'
blockchainTxHash:
type: string
proofDocumentUrl:
type: string
format: uri
notes:
type: string
distributedAt:
type: string
format: date-time
createdAt:
type: string
format: date-time
Notification:
type: object
properties:
id:
type: string
userId:
type: string
type:
$ref: '#/components/schemas/NotificationType'
title:
type: string
example: Donation Received
message:
type: string
example: Your campaign received a donation of 250 XLM
status:
type: string
enum: [UNREAD, READ, ARCHIVED]
metadata:
type: object
readAt:
type: string
format: date-time
createdAt:
type: string
format: date-time
Suspension:
type: object
properties:
id:
type: string
campaignId:
type: string
source:
type: string
enum: [AUTO, ADMIN]
reasonCode:
type: string
enum: [LOW_VERIFICATION, FRAUD_REPORTS, POLICY_VIOLATION, MANUAL_REVIEW, OTHER]
reasonText:
type: string
active:
type: boolean
liftedAt:
type: string
format: date-time
liftNotes:
type: string
createdAt:
type: string
format: date-time
Appeal:
type: object
properties:
id:
type: string
suspensionId:
type: string
campaignId:
type: string
message:
type: string
attachments:
type: array
items:
type: string
format: uri
status:
$ref: '#/components/schemas/AppealStatus'
adminNotes:
type: string
resolvedAt:
type: string
format: date-time
createdAt:
type: string
format: date-time
AuditLog:
type: object
properties:
id:
type: string
userId:
type: string
action:
type: string
example: DONATION_MADE
entityType:
type: string
example: Donation
entityId:
type: string
changes:
type: object
ipAddress:
type: string
createdAt:
type: string
format: date-time
BlockchainTransaction:
type: object
properties:
id:
type: string
txHash:
type: string
example: a3f8c2d1e4b567890abcdef1234567890abcdef1234567890abcdef1234567890
type:
type: string
enum: [DONATION, DISTRIBUTION, CONTRACT_DEPLOYMENT, CONTRACT_CALL, FEE_PAYMENT]
fromAddress:
type: string
example: GBKZRTIOAHMXIJKUQPMKLF6JYLXV2PJHFGXZQ4LQXSWM5YIZD3HMGKQ
toAddress:
type: string
example: GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGKZM9OSGLPQOAKXQ5XRGT
amount:
type: string
example: "250.00"
currency:
type: string
example: XLM
contractAddress:
type: string
functionName:
type: string
example: donate
parameters:
type: object
status:
type: string
enum: [PENDING, CONFIRMED, FAILED]
blockNumber:
type: string
description: Stellar ledger sequence number
example: "50234891"
timestamp:
type: string
format: date-time
indexed:
type: boolean
# ── Reusable parameters ──────────────────────────────────────────────────
parameters:
PageParam:
name: page
in: query
description: Page number (1-based)
schema:
type: integer
default: 1
minimum: 1
LimitParam:
name: limit
in: query
description: Results per page
schema:
type: integer
default: 20
minimum: 1
maximum: 100
SortParam:
name: sort
in: query
description: "Sort field, prefix with - for descending (e.g. -createdAt)"
schema:
type: string
# ── Reusable responses ───────────────────────────────────────────────────
responses:
Unauthorized:
description: Missing or invalid JWT
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Authentication token required
Forbidden:
description: Authenticated but insufficient role
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Insufficient permissions
NotFound:
description: Resource not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Resource not found
ValidationError:
description: Request body failed schema validation
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Validation failed
details:
- field: amount
message: Amount must be positive
RateLimited:
description: Rate limit exceeded
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Too many requests, please try again later
InternalError:
description: Unexpected server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Internal server error
# ---------------------------------------------------------------------------
# PATHS
# ---------------------------------------------------------------------------
paths:
# ==========================================================================
# AUTH
# ==========================================================================
/api/v1/auth/register:
post:
tags: [Authentication]
summary: Register a new user
description: |
Creates a new user account. The account starts in `PENDING_VERIFICATION` status.
**Rate limit:** 5 requests / 15 min per IP.
operationId: register
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [email, password]
properties:
email:
type: string
format: email
example: donor@example.com
password:
type: string
format: password
minLength: 8
example: "SecurePass123!"
username:
type: string
example: john_donor
role:
$ref: '#/components/schemas/Role'
example:
email: donor@example.com
password: "SecurePass123!"
username: john_donor
role: DONOR
responses:
"201":
description: User registered successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
example:
success: true
message: User registered successfully
data:
id: clx1a2b3c4d5e6f7g8h9
email: donor@example.com
username: john_donor
role: DONOR
status: PENDING_VERIFICATION
createdAt: "2024-03-15T10:30:00Z"
"400":
$ref: '#/components/responses/ValidationError'
"409":
description: Email already registered
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Email already in use
"429":
$ref: '#/components/responses/RateLimited'
/api/v1/auth/login:
post:
tags: [Authentication]
summary: Login with email and password
description: |
Authenticates a user and returns JWT access + refresh tokens.
**Rate limit:** 5 requests / 15 min per IP.
operationId: login
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [email, password]
properties:
email:
type: string
format: email
password:
type: string
format: password
example:
email: donor@example.com
password: "SecurePass123!"
responses:
"200":
description: Login successful
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
example:
success: true
message: Login successful
data:
accessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbHgxYTJiM2M0ZDVlNmY3ZzhoOSIsInJvbGUiOiJET05PUiIsImlhdCI6MTcxMDQ5NjIwMCwiZXhwIjoxNzEwNDk3MTAwfQ.sig
refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.refresh.sig
expiresIn: 900
user:
id: clx1a2b3c4d5e6f7g8h9
email: donor@example.com
role: DONOR
status: ACTIVE
"400":
$ref: '#/components/responses/ValidationError'
"401":
description: Invalid credentials
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
success: false
error: Invalid email or password
"429":
$ref: '#/components/responses/RateLimited'
/api/v1/auth/wallet:
post:
tags: [Authentication]
summary: Authenticate with a Stellar wallet
description: |
Verifies a signed message from a Stellar wallet address and returns JWT tokens.
The client must sign the `message` string with the wallet private key and pass the hex signature.
**Rate limit:** 5 requests / 15 min per IP.
operationId: walletAuth
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [walletAddress, signature, message]
properties:
walletAddress:
type: string
example: GBKZRTIOAHMXIJKUQPMKLF6JYLXV2PJHFGXZQ4LQXSWM5YIZD3HMGKQ
signature:
type: string
description: Ed25519 signature of `message` in hex
example: a3f8c2d1e4b567890abcdef...
message:
type: string
description: Nonce/challenge string that was signed
example: "AidLink authentication nonce: 1710496200"