index.ts 181 KB
Newer Older
Stefan Probst's avatar
Stefan Probst committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * SSHOC Marketplace API
 *
 * Social Sciences and Humanities Open Cloud Marketplace
 *
 * License: Apache 2.0
 * Version: 0.1.1
 */

/* eslint-disable @typescript-eslint/no-namespace */

import type {
  UseMutationOptions,
  UseMutationResult,
  UseQueryOptions,
  UseQueryResult,
} from 'react-query'
Stefan Probst's avatar
Stefan Probst committed
18
import { useMutation, useQuery } from 'react-query'
Stefan Probst's avatar
Stefan Probst committed
19
20
21
22
23
24

export type ActorRoleDto = {
  code?: string
  label?: string
}

Stefan Probst's avatar
Stefan Probst committed
25
export type ActorRoleCore = {
26
  code?: string
Stefan Probst's avatar
Stefan Probst committed
27
28
  label: string
  ord?: number /* int32 */
29
30
}

Stefan Probst's avatar
Stefan Probst committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export type ActorDto = {
  id?: number /* int64 */
  name?: string
  externalIds?: Array<ActorExternalIdDto>
  website?: string
  email?: string
  affiliations?: Array<ActorDto>
}

export type ActorExternalIdDto = {
  identifierService?: ActorSourceDto
  identifier?: string
}

Stefan Probst's avatar
Stefan Probst committed
45
export type ActorSourceDto = {
Stefan Probst's avatar
Stefan Probst committed
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
  code?: string
  label?: string
}

export type ConceptBasicDto = {
  code?: string
  vocabulary?: VocabularyBasicDto
  label?: string
  notation?: string
  definition?: string
  uri?: string
}

export type ItemBasicDto = {
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
}

export type ItemContributorDto = {
  actor?: ActorDto
  role?: ActorRoleDto
}

export type ItemExternalIdDto = {
  identifierService?: ItemSourceDto
  identifier?: string
}

83
84
85
86
87
export type ItemMediaDto = {
  metadata?: MediaDetails
  caption?: string
}

Stefan Probst's avatar
Stefan Probst committed
88
89
90
91
92
93
94
95
96
97
export type ItemRelationDto = {
  code?: string
  label?: string
}

export type ItemSourceDto = {
  code?: string
  label?: string
}

98
99
100
101
export type ItemThumbnailId = {
  mediaId?: string /* uuid */
}

Stefan Probst's avatar
Stefan Probst committed
102
103
104
105
106
107
108
109
110
111
112
113
export type LicenseDto = {
  code?: string
  label?: string
  types?: Array<LicenseTypeDto>
  accessibleAt?: string
}

export type LicenseTypeDto = {
  code?: string
  label?: string
}

114
115
116
117
118
119
120
121
122
123
124
export type MediaDetails = {
  mediaId?: string /* uuid */
  category?: 'image' | 'video' | 'object' | 'thumbnail'
  location?: MediaLocation
  filename?: string
  mimeType?: string
  hasThumbnail?: boolean
}

export type MediaLocation = {
  sourceUrl?: string /* url */
Stefan Probst's avatar
Stefan Probst committed
125
126
127
128
129
130
131
132
133
}

export type PropertyDto = {
  id?: number /* int64 */
  type?: PropertyTypeDto
  value?: string
  concept?: ConceptBasicDto
}

Stefan Probst's avatar
Stefan Probst committed
134
135
136
137
138
139
140
141
142
143
export type PropertyTypeDto = {
  code?: string
  label?: string
  type?: 'concept' | 'string' | 'url' | 'int' | 'float' | 'date'
  groupName?: string
  hidden?: boolean
  ord?: number /* int32 */
  allowedVocabularies?: Array<VocabularyBasicDto>
}

Stefan Probst's avatar
Stefan Probst committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
export type RelatedItemDto = {
  id?: number /* int64 */
  persistentId?: string
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  description?: string
  relation?: ItemRelationDto
}

export type SourceBasicDto = {
  id?: number /* int64 */
  label?: string
  url?: string
  urlTemplate?: string
}

Stefan Probst's avatar
Stefan Probst committed
166
export type ToolDto = {
Stefan Probst's avatar
Stefan Probst committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
  description?: string
  licenses?: Array<LicenseDto>
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  externalIds?: Array<ItemExternalIdDto>
  accessibleAt?: Array<string>
  source?: SourceBasicDto
  sourceItemId?: string
  relatedItems?: Array<RelatedItemDto>
187
188
  media?: Array<ItemMediaDto>
  thumbnail?: ItemThumbnailId
Stefan Probst's avatar
Stefan Probst committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  informationContributor?: UserDto
  lastInfoUpdate?: string
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  olderVersions?: Array<ItemBasicDto>
  newerVersions?: Array<ItemBasicDto>
}

export type UserDto = {
  id?: number /* int64 */
  username?: string
  displayName?: string
206
  status?: 'during-registration' | 'enabled' | 'locked'
Stefan Probst's avatar
Stefan Probst committed
207
208
209
210
211
  registrationDate?: string
  role?: 'contributor' | 'system-contributor' | 'moderator' | 'administrator'
  email?: string
}

Stefan Probst's avatar
Stefan Probst committed
212
213
export type VocabularyBasicDto = {
  code?: string
Stefan Probst's avatar
Stefan Probst committed
214
  label?: string
Stefan Probst's avatar
Stefan Probst committed
215
  accessibleAt?: string
Stefan Probst's avatar
Stefan Probst committed
216
217
}

Stefan Probst's avatar
Stefan Probst committed
218
export type PaginatedTools = {
219
220
221
222
223
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
Stefan Probst's avatar
Stefan Probst committed
224
225
226
227
228
  tools?: Array<ToolDto>
}

export type ActorId = {
  id?: number /* int64 */
229
230
}

Stefan Probst's avatar
Stefan Probst committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
export type ActorRoleId = {
  code?: string
}

export type ConceptId = {
  code?: string
  vocabulary?: VocabularyId
  uri?: string
}

export type ItemContributorId = {
  actor?: ActorId
  role?: ActorRoleId
}

export type ItemExternalIdCore = {
247
  serviceIdentifier: ItemExternalIdId
Stefan Probst's avatar
Stefan Probst committed
248
249
250
  identifier: string
}

251
252
253
254
255
256
257
258
259
export type ItemExternalIdId = {
  code?: string
}

export type ItemMediaCore = {
  mediaId?: string /* uuid */
  caption?: string
}

Stefan Probst's avatar
Stefan Probst committed
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
export type ItemRelationId = {
  code?: string
}

export type LicenseId = {
  code?: string
}

export type PropertyCore = {
  type?: PropertyTypeId
  value?: string
  concept?: ConceptId
}

export type PropertyTypeId = {
  code?: string
}

export type RelatedItemCore = {
279
  persistentId?: string
Stefan Probst's avatar
Stefan Probst committed
280
281
282
283
284
285
286
  relation?: ItemRelationId
}

export type SourceId = {
  id?: number /* int64 */
}

Stefan Probst's avatar
Stefan Probst committed
287
export type ToolCore = {
Stefan Probst's avatar
Stefan Probst committed
288
289
290
291
292
293
294
295
  label?: string
  version?: string
  description?: string
  licenses?: Array<LicenseId>
  contributors?: Array<ItemContributorId>
  externalIds?: Array<ItemExternalIdCore>
  properties?: Array<PropertyCore>
  relatedItems?: Array<RelatedItemCore>
296
297
  media?: Array<ItemMediaCore>
  thumbnail?: ItemThumbnailId
Stefan Probst's avatar
Stefan Probst committed
298
299
300
301
302
  accessibleAt?: Array<string>
  source?: SourceId
  sourceItemId?: string
}

Stefan Probst's avatar
Stefan Probst committed
303
304
export type VocabularyId = {
  code?: string
305
306
}

Stefan Probst's avatar
Stefan Probst committed
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
export type CheckedCount = {
  count?: number /* int64 */
  checked?: boolean
}

export type LabeledCheckedCount = {
  count?: number /* int64 */
  checked?: boolean
  label?: string
}

export type PaginatedSearchItems = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  q?: string
  order?: Array<'score' | 'label' | 'modified-on'>
  items?: Array<SearchItem>
  categories?: Record<string, LabeledCheckedCount>
  facets?: Record<string, Record<string, CheckedCount>>
}

export type SearchItem = {
  id?: number /* int64 */
  persistentId?: string
  label?: string
  description?: string
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  owner?: string
}

export type CountedPropertyType = {
  code?: string
  label?: string
  count?: number /* int64 */
  checked?: boolean
}

export type PaginatedSearchConcepts = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  q?: string
  concepts?: Array<SearchConcept>
  types?: Record<string, CountedPropertyType>
}

export type SearchConcept = {
  code?: string
  vocabulary?: VocabularyId
  label?: string
  notation?: string
  definition?: string
  uri?: string
  types?: Array<PropertyTypeId>
}

export type SuggestedSearchPhrases = {
  phrase?: string
  suggestions?: Array<string>
}

Stefan Probst's avatar
Stefan Probst committed
388
389
390
391
392
export type OAuthRegistrationData = {
  id?: number /* int64 */
  displayName?: string
  email?: string
  acceptedRegulations?: boolean
Stefan Probst's avatar
Stefan Probst committed
393
394
}

Stefan Probst's avatar
Stefan Probst committed
395
396
397
398
399
400
401
402
export type ImplicitGrantTokenData = {
  token?: string
  registration?: boolean
}

export type OAuthRegistrationDto = {
  id?: number /* int64 */
  displayName?: string
Stefan Probst's avatar
Stefan Probst committed
403
404
405
  email?: string
}

Stefan Probst's avatar
Stefan Probst committed
406
export type TrainingMaterialDto = {
Stefan Probst's avatar
Stefan Probst committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
  description?: string
  licenses?: Array<LicenseDto>
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  externalIds?: Array<ItemExternalIdDto>
  accessibleAt?: Array<string>
  source?: SourceBasicDto
  sourceItemId?: string
  relatedItems?: Array<RelatedItemDto>
427
428
  media?: Array<ItemMediaDto>
  thumbnail?: ItemThumbnailId
Stefan Probst's avatar
Stefan Probst committed
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
  informationContributor?: UserDto
  lastInfoUpdate?: string
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  olderVersions?: Array<ItemBasicDto>
  newerVersions?: Array<ItemBasicDto>
  dateCreated?: string
  dateLastUpdated?: string
}

Stefan Probst's avatar
Stefan Probst committed
444
export type TrainingMaterialCore = {
Stefan Probst's avatar
Stefan Probst committed
445
446
447
448
449
450
451
452
  label?: string
  version?: string
  description?: string
  licenses?: Array<LicenseId>
  contributors?: Array<ItemContributorId>
  externalIds?: Array<ItemExternalIdCore>
  properties?: Array<PropertyCore>
  relatedItems?: Array<RelatedItemCore>
453
454
  media?: Array<ItemMediaCore>
  thumbnail?: ItemThumbnailId
Stefan Probst's avatar
Stefan Probst committed
455
456
457
458
459
460
461
  accessibleAt?: Array<string>
  source?: SourceId
  sourceItemId?: string
  dateCreated?: string
  dateLastUpdated?: string
}

Stefan Probst's avatar
Stefan Probst committed
462
export type PaginatedTrainingMaterials = {
463
464
465
466
467
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
Stefan Probst's avatar
Stefan Probst committed
468
  trainingMaterials?: Array<TrainingMaterialDto>
Stefan Probst's avatar
Stefan Probst committed
469
470
}

Stefan Probst's avatar
Stefan Probst committed
471
472
473
474
export type ItemSourceCore = {
  code?: string
  label: string
  ord?: number /* int32 */
Stefan Probst's avatar
Stefan Probst committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
}

export type DatasetDto = {
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
  description?: string
  licenses?: Array<LicenseDto>
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  externalIds?: Array<ItemExternalIdDto>
  accessibleAt?: Array<string>
  source?: SourceBasicDto
  sourceItemId?: string
  relatedItems?: Array<RelatedItemDto>
498
499
  media?: Array<ItemMediaDto>
  thumbnail?: ItemThumbnailId
Stefan Probst's avatar
Stefan Probst committed
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
  informationContributor?: UserDto
  lastInfoUpdate?: string
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  olderVersions?: Array<ItemBasicDto>
  newerVersions?: Array<ItemBasicDto>
  dateCreated?: string
  dateLastUpdated?: string
}

export type PaginatedDatasets = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  datasets?: Array<DatasetDto>
}

export type DatasetCore = {
  label?: string
  version?: string
  description?: string
  licenses?: Array<LicenseId>
  contributors?: Array<ItemContributorId>
  externalIds?: Array<ItemExternalIdCore>
  properties?: Array<PropertyCore>
  relatedItems?: Array<RelatedItemCore>
533
534
  media?: Array<ItemMediaCore>
  thumbnail?: ItemThumbnailId
Stefan Probst's avatar
Stefan Probst committed
535
536
537
538
539
540
541
  accessibleAt?: Array<string>
  source?: SourceId
  sourceItemId?: string
  dateCreated?: string
  dateLastUpdated?: string
}

Stefan Probst's avatar
Stefan Probst committed
542
543
544
545
546
547
548
549
export type PaginatedActors = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  actors?: Array<ActorDto>
}
Stefan Probst's avatar
Stefan Probst committed
550

Stefan Probst's avatar
Stefan Probst committed
551
552
553
554
555
556
557
export type ActorCore = {
  name?: string
  externalIds?: Array<ActorExternalIdCore>
  website?: string
  email?: string
  affiliations?: Array<ActorId>
}
Stefan Probst's avatar
Stefan Probst committed
558

Stefan Probst's avatar
Stefan Probst committed
559
560
561
562
export type ActorExternalIdCore = {
  serviceIdentifier: ActorSourceId
  identifier: string
}
Stefan Probst's avatar
Stefan Probst committed
563

Stefan Probst's avatar
Stefan Probst committed
564
565
export type ActorSourceId = {
  code?: string
Stefan Probst's avatar
Stefan Probst committed
566
567
}

Stefan Probst's avatar
Stefan Probst committed
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
export type ActorSourceCore = {
  code?: string
  label: string
  ord?: number /* int32 */
}

export type PaginatedVocabularies = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  vocabularies?: Array<VocabularyBasicDto>
}

export type ConceptDto = {
  code?: string
  vocabulary?: VocabularyBasicDto
  label?: string
  notation?: string
  definition?: string
  uri?: string
  relatedConcepts?: Array<RelatedConceptDto>
}

export type ConceptRelationDto = {
  code?: string
  label?: string
}

export type PaginatedConcepts = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  concepts?: Array<ConceptDto>
}

export type RelatedConceptDto = {
  code?: string
  vocabulary?: VocabularyBasicDto
  label?: string
  notation?: string
  definition?: string
  uri?: string
  relation?: ConceptRelationDto
}

export type VocabularyDto = {
  code?: string
  label?: string
  accessibleAt?: string
  description?: string
  conceptResults?: PaginatedConcepts
}

export type PaginatedPropertyTypes = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  propertyTypes?: Array<PropertyTypeDto>
}

export type PropertyTypeCore = {
  code?: string
  label?: string
  type?: 'concept' | 'string' | 'url' | 'int' | 'float' | 'date'
  groupName?: string
  hidden?: boolean
  ord?: number /* int32 */
  allowedVocabularies?: Array<string>
}

export type PropertyTypeReorder = {
  code: string
  ord?: number /* int32 */
}

export type PropertyTypesReordering = {
  shifts: Array<PropertyTypeReorder>
}

export type PaginatedSources = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  sources?: Array<SourceDto>
}

export type SourceDto = {
  id?: number /* int64 */
  label?: string
  url?: string
  urlTemplate?: string
  lastHarvestedDate?: string
}

export type SourceCore = {
  label?: string
  url?: string
  urlTemplate?: string
}

export type PaginatedLicenses = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  licenses?: Array<LicenseDto>
}

export type StepDto = {
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
  description?: string
  licenses?: Array<LicenseDto>
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  externalIds?: Array<ItemExternalIdDto>
  accessibleAt?: Array<string>
  source?: SourceBasicDto
  sourceItemId?: string
  relatedItems?: Array<RelatedItemDto>
  media?: Array<ItemMediaDto>
  thumbnail?: ItemThumbnailId
  informationContributor?: UserDto
  lastInfoUpdate?: string
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  olderVersions?: Array<ItemBasicDto>
  newerVersions?: Array<ItemBasicDto>
  composedOf?: Array<StepDto>
}

export type StepCore = {
  label?: string
  version?: string
  description?: string
  licenses?: Array<LicenseId>
  contributors?: Array<ItemContributorId>
  externalIds?: Array<ItemExternalIdCore>
  properties?: Array<PropertyCore>
  relatedItems?: Array<RelatedItemCore>
  media?: Array<ItemMediaCore>
  thumbnail?: ItemThumbnailId
  accessibleAt?: Array<string>
  source?: SourceId
  sourceItemId?: string
  stepNo?: number /* int32 */
}

export type PaginatedWorkflows = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  workflows?: Array<WorkflowDto>
}

export type WorkflowDto = {
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
  description?: string
  licenses?: Array<LicenseDto>
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  externalIds?: Array<ItemExternalIdDto>
  accessibleAt?: Array<string>
  source?: SourceBasicDto
  sourceItemId?: string
  relatedItems?: Array<RelatedItemDto>
  media?: Array<ItemMediaDto>
  thumbnail?: ItemThumbnailId
  informationContributor?: UserDto
  lastInfoUpdate?: string
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  olderVersions?: Array<ItemBasicDto>
  newerVersions?: Array<ItemBasicDto>
  composedOf?: Array<StepDto>
}

export type WorkflowCore = {
  label?: string
  version?: string
  description?: string
  licenses?: Array<LicenseId>
  contributors?: Array<ItemContributorId>
  externalIds?: Array<ItemExternalIdCore>
  properties?: Array<PropertyCore>
  relatedItems?: Array<RelatedItemCore>
  media?: Array<ItemMediaCore>
  thumbnail?: ItemThumbnailId
  accessibleAt?: Array<string>
  source?: SourceId
  sourceItemId?: string
}

export type MediaSourceDto = {
  code?: string
  serviceUrl?: string
  mediaCategory?: 'image' | 'video' | 'object' | 'thumbnail'
}

export type MediaSourceCore = {
  code?: string
  serviceUrl?: string
  mediaCategory?: 'image' | 'video' | 'object' | 'thumbnail'
  ord?: number /* int32 */
}

export type Resource = {
  url?: string /* url */
  readable?: boolean
  filename?: string
  description?: string
  uri?: string /* uri */
  open?: boolean
  file?: string /* binary */
  inputStream?: {}
}

export type MediaUploadInfo = {
  mediaId?: string /* uuid */
  filename?: string
  mimeType?: string
  nextChunkNo?: number /* int32 */
}

export type LoginData = {
  username?: string
  password?: string
}

export type PaginatedUsers = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  users?: Array<UserDto>
}

export type ItemRelatedItemDto = {
  subject?: ItemBasicDto
  object?: ItemBasicDto
  relation?: ItemRelationDto
}

export type ItemCommentDto = {
  id?: number /* int64 */
  body?: string
  creator?: UserDto
  dateCreated?: string
  dateLastUpdated?: string
}

export type ItemCommentCore = {
  body?: string
}

export type PublicationDto = {
  id?: number /* int64 */
  category?:
    | 'tool-or-service'
    | 'training-material'
    | 'publication'
    | 'dataset'
    | 'workflow'
    | 'step'
  label?: string
  version?: string
  persistentId?: string
  description?: string
  licenses?: Array<LicenseDto>
  contributors?: Array<ItemContributorDto>
  properties?: Array<PropertyDto>
  externalIds?: Array<ItemExternalIdDto>
  accessibleAt?: Array<string>
  source?: SourceBasicDto
  sourceItemId?: string
  relatedItems?: Array<RelatedItemDto>
  media?: Array<ItemMediaDto>
  thumbnail?: ItemThumbnailId
  informationContributor?: UserDto
  lastInfoUpdate?: string
  status?:
    | 'draft'
    | 'ingested'
    | 'suggested'
    | 'approved'
    | 'disapproved'
    | 'deprecated'
  olderVersions?: Array<ItemBasicDto>
  newerVersions?: Array<ItemBasicDto>
  dateCreated?: string
  dateLastUpdated?: string
}

export type PaginatedPublications = {
  hits?: number /* int64 */
  count?: number /* int32 */
  page?: number /* int32 */
  perpage?: number /* int32 */
  pages?: number /* int32 */
  publications?: Array<PublicationDto>
}

export type PublicationCore = {
  label?: string
  version?: string
  description?: string
  licenses?: Array<LicenseId>
  contributors?: Array<ItemContributorId>
  externalIds?: Array<ItemExternalIdCore>
  properties?: Array<PropertyCore>
  relatedItems?: Array<RelatedItemCore>
  media?: Array<ItemMediaCore>
  thumbnail?: ItemThumbnailId
  accessibleAt?: Array<string>
  source?: SourceId
  sourceItemId?: string
  dateCreated?: string
  dateLastUpdated?: string
}

Stefan Probst's avatar
Stefan Probst committed
929
930
const defaultBaseUrl =
  process.env.SSHOC_API_BASE_URL ?? process.env.NEXT_PUBLIC_SSHOC_API_BASE_URL
Stefan Probst's avatar
Stefan Probst committed
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953

export { defaultBaseUrl as baseUrl }

export class HttpError extends Error {
  response: Response
  statusCode: number

  constructor(response: Response, message?: string) {
    super((message ?? response.statusText) || 'Unexpected HTTP error.')
    this.name = 'HttpError'
    this.response = response
    this.statusCode = response.status
  }
}

function createUrl(
  path: string,
  baseUrl = defaultBaseUrl,
  query: Record<string, unknown> = {},
) {
  const url = new URL(path, baseUrl)
  Object.entries(query).forEach(([key, value]) => {
    if (Array.isArray(value)) {
Stefan Probst's avatar
Stefan Probst committed
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
      value.forEach((v) => {
        if (v != null) {
          url.searchParams.append(key, String(v))
        }
      })
    } else if (value != null) {
      url.searchParams.set(key, String(value))
    }
  })
  return url.toString()
}

type RequestOptions<T> = {
  hooks?: {
    request?: (request: Request) => Request
    response?: (response: Response) => Promise<T>
  }
  token?: string
}
export async function request<T = unknown>({
  path,
  baseUrl,
  query,
  options,
  hooks = {},
  token,
  returnType = 'json',
}: {
  path: string
  baseUrl?: string
  query?: Record<string, unknown>
  options?: RequestInit
  hooks?: RequestOptions<T>['hooks']
  token?: RequestOptions<T>['token']
  returnType?: 'json'
}): Promise<T> {
  const url = createUrl(path, baseUrl, query)
  const req = new Request(url, options)
  const request = typeof hooks.request === 'function' ? hooks.request(req) : req
  if (token !== undefined && token.length > 0) {
    request.headers.set('Authorization', token)
  }
  const response = await fetch(request)
  if (!response.ok) {
    let message
    if (response.headers.get('content-type') === 'application/json') {
      const data = await response.json()
For faster browsing, not all history is shown. View entire blame