-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinq.openapi.json
More file actions
3191 lines (3191 loc) · 90.7 KB
/
Copy pathlinq.openapi.json
File metadata and controls
3191 lines (3191 loc) · 90.7 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.1.0",
"info": {
"title": "linq",
"version": "0.1.0",
"summary": "Self-hosted URL shortener and dynamic-link service.",
"description": "Three things share one port: the REST API under `/api`, the Client UI's\nstatic export under `/home`, and the redirect on every other path.\n\n**Authentication.** Every `/api/v1/*` route needs an API key, sent as\n`Authorization: Bearer <key>` or `X-Api-Key: <key>`. A key is the principal:\nnobody logs in, and there are no user accounts. A key whose `expires_at` has\npassed fails with 401.\n\n**Roles** are ordered `viewer < author < manager < admin`. Each operation\nbelow states the minimum it needs.\n\n**Errors** all share one envelope, documented on the `Error` schema.\n\n**Lists** all share one envelope — `{ data, total, limit, offset }` — where\n`total` counts every row matching the filters, not just the page.\n\n---\n\nWritten by hand from `apps/server/src/http/`, which stays the source of\ntruth; the zod schemas in `packages/shared/src/` are what the server\nactually validates against, and the constraints here mirror them.\n"
},
"servers": [
{
"url": "http://localhost:3000",
"description": "Local development"
},
{
"url": "https://{host}",
"description": "A deployed instance",
"variables": {
"host": {
"default": "links.example.com"
}
}
}
],
"security": [
{
"bearerAuth": []
},
{
"apiKeyAuth": []
}
],
"tags": [
{
"name": "Health",
"description": "Unauthenticated liveness."
},
{
"name": "Identity",
"description": "Who the calling key belongs to."
},
{
"name": "Domains",
"description": "The hosts links live on."
},
{
"name": "Links",
"description": "Short links, their rules and their reports."
},
{
"name": "Analytics",
"description": "Visits, and the reports rolled up from them."
},
{
"name": "QR codes",
"description": "Styled QR codes for a short link. Always attached to exactly one link."
},
{
"name": "Keys",
"description": "Keys are the principals. Minting one is how access is granted; revoking it is how access is removed."
},
{
"name": "Redirect",
"description": "What the public actually hits."
}
],
"paths": {
"/api/health": {
"get": {
"tags": [
"Health"
],
"operationId": "getHealth",
"summary": "Liveness and version",
"description": "The only route under `/api` that needs no key.",
"security": [],
"responses": {
"200": {
"description": "The server is up.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"status",
"version"
],
"properties": {
"status": {
"type": "string",
"const": "ok"
},
"version": {
"type": "string",
"examples": [
"0.1.0"
]
}
}
}
}
}
}
}
}
},
"/api/v1/me": {
"get": {
"tags": [
"Identity"
],
"operationId": "getMe",
"summary": "The calling key's identity",
"description": "The calling key. There is no user behind it: a key carries its own name and role, and this is what the Client UI gates its menus on.\n",
"responses": {
"200": {
"description": "The calling key.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiKey"
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
}
}
}
},
"/api/v1/domains": {
"get": {
"tags": [
"Domains"
],
"operationId": "listDomains",
"summary": "List domains",
"description": "Ordered by host. Every role may read.",
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
}
],
"responses": {
"200": {
"description": "A page of domains.",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/Page"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Domain"
}
}
}
}
]
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
}
}
},
"post": {
"tags": [
"Domains"
],
"operationId": "createDomain",
"summary": "Create a domain",
"description": "Requires: **admin**.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DomainCreate"
}
}
}
},
"responses": {
"201": {
"description": "The created domain.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Domain"
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"409": {
"description": "The host already exists.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/api/v1/domains/{id}": {
"parameters": [
{
"$ref": "#/components/parameters/Id"
}
],
"get": {
"tags": [
"Domains"
],
"operationId": "getDomain",
"summary": "Read a domain",
"responses": {
"200": {
"description": "The domain.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Domain"
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
}
},
"patch": {
"tags": [
"Domains"
],
"operationId": "updateDomain",
"summary": "Update a domain",
"description": "Requires: **admin**. `host` is immutable and is not accepted.\n\nArchiving is refused while any **active** link points at the domain.\n",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DomainPatch"
}
}
}
},
"responses": {
"200": {
"description": "The updated domain.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Domain"
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"409": {
"description": "The domain still has active links.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
},
"delete": {
"tags": [
"Domains"
],
"operationId": "archiveDomain",
"summary": "Archive a domain",
"description": "Requires: **admin**. `DELETE` archives; it never destroys. An archived\ndomain returns an untracked 404 for everything. See `docs/adr/0002`.\n",
"responses": {
"200": {
"description": "The archived domain.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Domain"
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"409": {
"description": "The domain still has active links.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/api/v1/domains/{id}/purge": {
"parameters": [
{
"$ref": "#/components/parameters/Id"
}
],
"delete": {
"tags": [
"Domains"
],
"operationId": "purgeDomain",
"summary": "Destroy an archived domain",
"description": "Requires: **admin**. Irreversible, and refused unless the domain is\nalready archived — archiving and purging are always two deliberate\nsteps. Refused while **any** link row still points at the domain,\narchived ones included.\n\nThis is the one operation in linq that loses analytics history: a\ndomain's visits and rollups go with it.\n",
"responses": {
"204": {
"description": "Destroyed."
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"409": {
"description": "Not archived yet, or links still point at it.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/api/v1/links": {
"get": {
"tags": [
"Links"
],
"operationId": "listLinks",
"summary": "List links",
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
},
{
"name": "search",
"in": "query",
"description": "Substring match, case-insensitive, over slug, name and destination.",
"schema": {
"type": "string",
"minLength": 1,
"maxLength": 200
}
},
{
"name": "tags",
"in": "query",
"description": "Comma-separated. A link matches when it carries **any** of them.",
"schema": {
"type": "string",
"examples": [
"launch,press"
]
}
},
{
"name": "domain_id",
"in": "query",
"schema": {
"type": "string",
"format": "uuid"
}
},
{
"name": "status",
"in": "query",
"schema": {
"type": "string",
"enum": [
"active",
"archived",
"all"
],
"default": "active"
}
},
{
"name": "sort",
"in": "query",
"schema": {
"type": "string",
"enum": [
"created_at",
"updated_at",
"visits"
],
"default": "created_at"
}
},
{
"name": "order",
"in": "query",
"schema": {
"type": "string",
"enum": [
"asc",
"desc"
],
"default": "desc"
}
},
{
"name": "expiry",
"in": "query",
"description": "Filters on expires_at against the current time. `live` includes links that never expire.",
"schema": {
"type": "string",
"enum": [
"any",
"live",
"expired"
],
"default": "any"
}
}
],
"responses": {
"200": {
"description": "A page of links.",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/Page"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Link"
}
}
}
}
]
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
}
}
},
"post": {
"tags": [
"Links"
],
"operationId": "createLink",
"summary": "Create a link",
"description": "Requires: **editor**.\n\nOmit `slug` for a generated one. A custom slug that is taken on that\ndomain — including by an archived link — is a 409.\n",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkCreate"
}
}
}
},
"responses": {
"201": {
"description": "The created link.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Link"
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"description": "The domain does not exist.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"409": {
"description": "The slug is taken, the domain is archived, or no free slug could be allocated.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/api/v1/links/count": {
"get": {
"tags": [
"Links"
],
"operationId": "countLinks",
"summary": "Count links",
"description": "Just the `total` a page from `GET /links` would also carry, for a caller — such as the sidebar's link/archive badges — that never needed the rows or the joins that build them. Takes only `status`; every other list filter is out of scope here.",
"parameters": [
{
"name": "status",
"in": "query",
"schema": {
"type": "string",
"enum": [
"active",
"archived",
"all"
],
"default": "active"
}
}
],
"responses": {
"200": {
"description": "The count.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"total"
],
"properties": {
"total": {
"type": "integer",
"minimum": 0
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
}
}
}
},
"/api/v1/links/purge": {
"delete": {
"tags": [
"Links"
],
"operationId": "purgeArchivedLinks",
"summary": "Destroy every archived link",
"description": "Requires: **admin**. Bulk analogue of `DELETE /links/{id}/purge`: destroys every currently archived link in one call — \"Empty archive\" — instead of a client-side loop calling the single-link route once per row. Takes no filter: purging always means every archived link, the same invariant the single-link route already enforces one row at a time. Its rules go with each link (`ON DELETE CASCADE`). Irreversible.\n",
"responses": {
"200": {
"description": "How many links were destroyed.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"purged"
],
"properties": {
"purged": {
"type": "integer",
"minimum": 0
}
}
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
}
}
}
},
"/api/v1/links/{id}": {
"parameters": [
{
"$ref": "#/components/parameters/Id"
}
],
"get": {
"tags": [
"Links"
],
"operationId": "getLink",
"summary": "Read a link",
"responses": {
"200": {
"description": "The link.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Link"
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
}
},
"patch": {
"tags": [
"Links"
],
"operationId": "updateLink",
"summary": "Update a link",
"description": "Requires: **editor**, except a `status` change (archiving or restoring), which requires **admin**.\n\n`slug` and `domain_id` are immutable, and the body is strict, so sending\neither is a 400 rather than a silently ignored field.\n",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkPatch"
}
}
}
},
"responses": {
"200": {
"description": "The updated link.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Link"
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
}
},
"delete": {
"tags": [
"Links"
],
"operationId": "archiveLink",
"summary": "Archive a link",
"description": "Requires: **admin**.\n\n`DELETE` archives; it never destroys. An archived link stops\nredirecting — its slug becomes an orphan visit — but keeps its row, its\nvisits and its reservation on that slug. Reversible by\n`PATCH { \"status\": \"active\" }` (also admin only). See `docs/adr/0002` and\n`docs/adr/0016`.\n",
"responses": {
"200": {
"description": "The archived link.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Link"
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
}
}
},
"/api/v1/links/{id}/purge": {
"parameters": [
{
"$ref": "#/components/parameters/Id"
}
],
"delete": {
"tags": [
"Links"
],
"operationId": "purgeLink",
"summary": "Destroy an archived link",
"description": "Requires: **admin**. Irreversible, and refused unless the link is\nalready archived.\n\nIts rules go with it. Its visits survive as **orphan visits**, and its\nrollups are merged into the orphan scope — history is kept, attribution\nis not. Unlike archiving, this **releases the slug** for anyone to claim\non that domain.\n",
"responses": {
"204": {
"description": "Destroyed."
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
},
"409": {
"description": "The link is not archived yet.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/api/v1/links/{id}/rules": {
"parameters": [
{
"$ref": "#/components/parameters/Id"
}
],
"get": {
"tags": [
"Links"
],
"operationId": "getLinkRules",
"summary": "Read a link's rules",
"description": "In `position` order, which is the order they are evaluated in.",
"responses": {
"200": {
"description": "The rules, lowest position first.",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Rule"
}
}
}
}
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
}
},
"put": {
"tags": [
"Links"
],
"operationId": "replaceLinkRules",
"summary": "Replace a link's rules",
"description": "Requires: **editor**.\n\nReplaces the whole ordered set in one transaction; the server owns\n`position` and assigns it from the array order. Send `[]` to remove\nevery rule.\n",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "array",
"maxItems": 50,
"items": {
"$ref": "#/components/schemas/RuleInput"
}
}
}
}
},
"responses": {
"200": {
"description": "The stored rules, in their new order.",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Rule"
}
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
}
}
},
"/api/v1/qr-codes": {
"get": {
"tags": [
"QR codes"
],
"operationId": "listQrCodes",
"summary": "List QR codes",
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
},
{
"name": "link_id",
"in": "query",
"schema": {
"type": "string",
"format": "uuid"
}
},
{
"name": "search",
"in": "query",
"description": "Substring match, case-insensitive, over the QR code's own name and its link's name and slug.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "A page of QR codes.",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/Page"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/QrCode"
}
}
}
}
]
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
}
}
},
"post": {
"tags": [
"QR codes"
],
"operationId": "createQrCode",
"summary": "Create a QR code",
"description": "Requires: **editor**. A QR code is always attached to a link — `link_id` is required — and the link must be active: an archived link's short URL does not resolve, so a code for one would be born dead.\n",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/QrCodeCreate"
}
}
}
},
"responses": {
"201": {
"description": "The created QR code.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/QrCode"
}
}
}
},
"400": {
"$ref": "#/components/responses/ValidationFailed"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"description": "The link does not exist.",
"content": {