@api-client/core 0.18.39 → 0.18.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { setupWorker } from '@jarrodek/amw';
1
+ import { setupWorker, } from '@jarrodek/amw';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
3
  import { ModelingMock } from '../mocking/ModelingMock.js';
4
4
  /**
@@ -56,6 +56,10 @@ import { ModelingMock } from '../mocking/ModelingMock.js';
56
56
  * // Stop and remove the Service Worker
57
57
  * await mocker.teardown();
58
58
  * ```
59
+ *
60
+ * @TODO: Add a in-memory state store so that mocks can maintain state across requests.
61
+ * This way, operations like create, update, delete can affect subsequent list/read calls
62
+ * and we can mimic the API behavior more closely.
59
63
  */
60
64
  export class SdkMock {
61
65
  options;
@@ -135,7 +139,7 @@ export class SdkMock {
135
139
  * Adds an intercept to mock the `organizations.list()` method.
136
140
  * @param options Optional response configuration
137
141
  */
138
- list: async (init) => {
142
+ list: async (init, options) => {
139
143
  const { mock } = this;
140
144
  // const respond = init?.response ?? {
141
145
  // status: 200,
@@ -155,13 +159,13 @@ export class SdkMock {
155
159
  methods: ['GET'],
156
160
  },
157
161
  respond,
158
- });
162
+ }, options);
159
163
  },
160
164
  /**
161
165
  * Adds an intercept to mock the `organizations.create()` method.
162
166
  * @param options Optional response configuration
163
167
  */
164
- create: async (init) => {
168
+ create: async (init, options) => {
165
169
  const { mock } = this;
166
170
  // const respond = init?.response ?? {
167
171
  // status: 200,
@@ -175,10 +179,10 @@ export class SdkMock {
175
179
  methods: ['POST'],
176
180
  },
177
181
  respond,
178
- });
182
+ }, options);
179
183
  },
180
184
  invitations: {
181
- list: async (init) => {
185
+ list: async (init, options) => {
182
186
  const { mock } = this;
183
187
  // const respond = init?.response ?? {
184
188
  // status: 200,
@@ -201,9 +205,9 @@ export class SdkMock {
201
205
  methods: ['GET'],
202
206
  },
203
207
  respond,
204
- });
208
+ }, options);
205
209
  },
206
- create: async (init) => {
210
+ create: async (init, options) => {
207
211
  const { mock } = this;
208
212
  // const respond = init?.response ?? {
209
213
  // status: 200,
@@ -217,9 +221,9 @@ export class SdkMock {
217
221
  methods: ['POST'],
218
222
  },
219
223
  respond,
220
- });
224
+ }, options);
221
225
  },
222
- findByToken: async (init) => {
226
+ findByToken: async (init, options) => {
223
227
  const { mock } = this;
224
228
  // const respond = init?.response ?? {
225
229
  // status: 200,
@@ -233,9 +237,9 @@ export class SdkMock {
233
237
  methods: ['GET'],
234
238
  },
235
239
  respond,
236
- });
240
+ }, options);
237
241
  },
238
- decline: async (init) => {
242
+ decline: async (init, options) => {
239
243
  const { mock } = this;
240
244
  // const respond = init?.response ?? {
241
245
  // status: 200,
@@ -249,9 +253,9 @@ export class SdkMock {
249
253
  methods: ['POST'],
250
254
  },
251
255
  respond,
252
- });
256
+ }, options);
253
257
  },
254
- delete: async (init) => {
258
+ delete: async (init, options) => {
255
259
  const { mock } = this;
256
260
  // const respond = init?.response ?? {
257
261
  // status: 200,
@@ -265,9 +269,9 @@ export class SdkMock {
265
269
  methods: ['DELETE'],
266
270
  },
267
271
  respond,
268
- });
272
+ }, options);
269
273
  },
270
- patch: async (init) => {
274
+ patch: async (init, options) => {
271
275
  const { mock } = this;
272
276
  // const respond = init?.response ?? {
273
277
  // status: 200,
@@ -281,9 +285,9 @@ export class SdkMock {
281
285
  methods: ['PATCH'],
282
286
  },
283
287
  respond,
284
- });
288
+ }, options);
285
289
  },
286
- resend: async (init) => {
290
+ resend: async (init, options) => {
287
291
  const { mock } = this;
288
292
  // const respond = init?.response ?? {
289
293
  // status: 200,
@@ -297,11 +301,11 @@ export class SdkMock {
297
301
  methods: ['PUT'],
298
302
  },
299
303
  respond,
300
- });
304
+ }, options);
301
305
  },
302
306
  },
303
307
  users: {
304
- list: async (init) => {
308
+ list: async (init, options) => {
305
309
  const { mock } = this;
306
310
  // const respond = init?.response ?? {
307
311
  // status: 200,
@@ -324,9 +328,9 @@ export class SdkMock {
324
328
  methods: ['GET'],
325
329
  },
326
330
  respond,
327
- });
331
+ }, options);
328
332
  },
329
- read: async (init) => {
333
+ read: async (init, options) => {
330
334
  const { mock } = this;
331
335
  // const respond = init?.response ?? {
332
336
  // status: 200,
@@ -340,9 +344,9 @@ export class SdkMock {
340
344
  methods: ['GET'],
341
345
  },
342
346
  respond,
343
- });
347
+ }, options);
344
348
  },
345
- readBatch: async (init) => {
349
+ readBatch: async (init, options) => {
346
350
  const { mock } = this;
347
351
  const path = RouteBuilder.organizationUserBatch(':oid');
348
352
  const respond = init?.response ?? {
@@ -359,9 +363,9 @@ export class SdkMock {
359
363
  methods: ['POST'],
360
364
  },
361
365
  respond,
362
- });
366
+ }, options);
363
367
  },
364
- activate: async (init) => {
368
+ activate: async (init, options) => {
365
369
  const { mock } = this;
366
370
  // const respond = init?.response ?? {
367
371
  // status: 200,
@@ -375,9 +379,9 @@ export class SdkMock {
375
379
  methods: ['POST'],
376
380
  },
377
381
  respond,
378
- });
382
+ }, options);
379
383
  },
380
- deactivate: async (init) => {
384
+ deactivate: async (init, options) => {
381
385
  const { mock } = this;
382
386
  // const respond = init?.response ?? {
383
387
  // status: 200,
@@ -391,9 +395,9 @@ export class SdkMock {
391
395
  methods: ['POST'],
392
396
  },
393
397
  respond,
394
- });
398
+ }, options);
395
399
  },
396
- delete: async (init) => {
400
+ delete: async (init, options) => {
397
401
  const { mock } = this;
398
402
  // const respond = init?.response ?? {
399
403
  // status: 204,
@@ -405,7 +409,7 @@ export class SdkMock {
405
409
  methods: ['DELETE'],
406
410
  },
407
411
  respond,
408
- });
412
+ }, options);
409
413
  },
410
414
  },
411
415
  };
@@ -417,7 +421,7 @@ export class SdkMock {
417
421
  * Mocks the `groups.list()` method.
418
422
  * @param options Optional response customization.
419
423
  */
420
- list: async (init) => {
424
+ list: async (init, options) => {
421
425
  const { mock } = this;
422
426
  // const respond = init?.response ?? {
423
427
  // status: 200,
@@ -440,13 +444,13 @@ export class SdkMock {
440
444
  methods: ['GET'],
441
445
  },
442
446
  respond,
443
- });
447
+ }, options);
444
448
  },
445
449
  /**
446
450
  * Mocks the `groups.create()` method.
447
451
  * @param options Optional response customization.
448
452
  */
449
- create: async (init) => {
453
+ create: async (init, options) => {
450
454
  const { mock } = this;
451
455
  // const respond = init?.response ?? {
452
456
  // status: 201,
@@ -460,13 +464,13 @@ export class SdkMock {
460
464
  methods: ['POST'],
461
465
  },
462
466
  respond,
463
- });
467
+ }, options);
464
468
  },
465
469
  /**
466
470
  * Mocks the `groups.update()` method.
467
471
  * @param options Optional response customization.
468
472
  */
469
- update: async (init) => {
473
+ update: async (init, options) => {
470
474
  const { mock } = this;
471
475
  // const respond = init?.response ?? {
472
476
  // status: 200,
@@ -480,13 +484,13 @@ export class SdkMock {
480
484
  methods: ['PATCH'],
481
485
  },
482
486
  respond,
483
- });
487
+ }, options);
484
488
  },
485
489
  /**
486
490
  * Mocks the `groups.delete()` method.
487
491
  * @param options Optional response customization.
488
492
  */
489
- delete: async (init) => {
493
+ delete: async (init, options) => {
490
494
  const { mock } = this;
491
495
  // const respond = init?.response ?? {
492
496
  // status: 204,
@@ -498,12 +502,12 @@ export class SdkMock {
498
502
  methods: ['DELETE'],
499
503
  },
500
504
  respond,
501
- });
505
+ }, options);
502
506
  },
503
507
  /**
504
508
  * Mocks the `groups.addUsers()` method.
505
509
  */
506
- addUsers: async (init) => {
510
+ addUsers: async (init, options) => {
507
511
  const { mock } = this;
508
512
  // const respond = init?.response ?? {
509
513
  // status: 200,
@@ -517,12 +521,12 @@ export class SdkMock {
517
521
  methods: ['POST'],
518
522
  },
519
523
  respond,
520
- });
524
+ }, options);
521
525
  },
522
526
  /**
523
527
  * Mocks the `groups.removeUsers()` method.
524
528
  */
525
- removeUsers: async (init) => {
529
+ removeUsers: async (init, options) => {
526
530
  const { mock } = this;
527
531
  // const respond = init?.response ?? {
528
532
  // status: 200,
@@ -536,7 +540,7 @@ export class SdkMock {
536
540
  methods: ['DELETE'],
537
541
  },
538
542
  respond,
539
- });
543
+ }, options);
540
544
  },
541
545
  };
542
546
  /**
@@ -547,7 +551,7 @@ export class SdkMock {
547
551
  * Mocks the `user.me()` method.
548
552
  * @param options Optional response customization.
549
553
  */
550
- me: async (init) => {
554
+ me: async (init, options) => {
551
555
  const { mock } = this;
552
556
  // const respond = init?.response ?? {
553
557
  // status: 200,
@@ -561,7 +565,7 @@ export class SdkMock {
561
565
  methods: ['GET'],
562
566
  },
563
567
  respond,
564
- });
568
+ }, options);
565
569
  },
566
570
  };
567
571
  /**
@@ -571,7 +575,7 @@ export class SdkMock {
571
575
  /**
572
576
  * Mocks the `file.list()` method.
573
577
  */
574
- list: async (init) => {
578
+ list: async (init, options) => {
575
579
  const { mock } = this;
576
580
  // const respond = init?.response ?? {
577
581
  // status: 200,
@@ -594,12 +598,12 @@ export class SdkMock {
594
598
  methods: ['GET'],
595
599
  },
596
600
  respond,
597
- });
601
+ }, options);
598
602
  },
599
603
  /**
600
604
  * Mocks the `file.createMeta()` method.
601
605
  */
602
- createMeta: async (init) => {
606
+ createMeta: async (init, options) => {
603
607
  const { mock } = this;
604
608
  // const respond = init?.response ?? {
605
609
  // status: 201,
@@ -613,12 +617,12 @@ export class SdkMock {
613
617
  methods: ['POST'],
614
618
  },
615
619
  respond,
616
- });
620
+ }, options);
617
621
  },
618
622
  /**
619
623
  * Mocks the `file.createMedia()` method.
620
624
  */
621
- createMedia: async (init) => {
625
+ createMedia: async (init, options) => {
622
626
  const { mock } = this;
623
627
  // const respond = init?.response ?? {
624
628
  // status: 200,
@@ -630,22 +634,22 @@ export class SdkMock {
630
634
  methods: ['PUT'],
631
635
  },
632
636
  respond,
633
- });
637
+ }, options);
634
638
  },
635
639
  /**
636
640
  * Mocks the `file.create()` method.
637
641
  */
638
- create: async (init) => {
639
- await this.file.createMeta(init);
642
+ create: async (init, options) => {
643
+ await this.file.createMeta(init, options);
640
644
  // When SDK's file.create() is called, it responds with
641
645
  // what the result of file.createMeta() would be.
642
646
  // Because of that, we don't need to configure the media request.
643
- await this.file.createMedia();
647
+ await this.file.createMedia(undefined, options);
644
648
  },
645
649
  /**
646
650
  * Mocks the `file.createFolder()` method.
647
651
  */
648
- createFolder: async (init) => {
652
+ createFolder: async (init, options) => {
649
653
  const { mock } = this;
650
654
  // const respond = init?.response ?? {
651
655
  // status: 201,
@@ -659,12 +663,12 @@ export class SdkMock {
659
663
  methods: ['POST'],
660
664
  },
661
665
  respond,
662
- });
666
+ }, options);
663
667
  },
664
668
  /**
665
669
  * Mocks the `file.read()` method.
666
670
  */
667
- read: async (init) => {
671
+ read: async (init, options) => {
668
672
  const { mock } = this;
669
673
  // const respond = init?.response ?? {
670
674
  // status: 200,
@@ -678,12 +682,12 @@ export class SdkMock {
678
682
  methods: ['GET'],
679
683
  },
680
684
  respond,
681
- });
685
+ }, options);
682
686
  },
683
687
  /**
684
688
  * Mocks the `file.readMedia()` method.
685
689
  */
686
- readMedia: async (init) => {
690
+ readMedia: async (init, options) => {
687
691
  const { mock } = this;
688
692
  // const respond = init?.response ?? {
689
693
  // status: 200,
@@ -703,12 +707,12 @@ export class SdkMock {
703
707
  methods: ['GET'],
704
708
  },
705
709
  respond,
706
- });
710
+ }, options);
707
711
  },
708
712
  /**
709
713
  * Mocks the `file.readBulk()` method.
710
714
  */
711
- readBulk: async (init) => {
715
+ readBulk: async (init, options) => {
712
716
  const { mock } = this;
713
717
  // const respond = init?.response ?? {
714
718
  // status: 200,
@@ -729,12 +733,12 @@ export class SdkMock {
729
733
  methods: ['POST'],
730
734
  },
731
735
  respond,
732
- });
736
+ }, options);
733
737
  },
734
738
  /**
735
739
  * Mocks the `file.patch()` method.
736
740
  */
737
- patch: async (init) => {
741
+ patch: async (init, options) => {
738
742
  const { mock } = this;
739
743
  // const respond = init?.response ?? {
740
744
  // status: 200,
@@ -748,12 +752,12 @@ export class SdkMock {
748
752
  methods: ['PATCH'],
749
753
  },
750
754
  respond,
751
- });
755
+ }, options);
752
756
  },
753
757
  /**
754
758
  * Mocks the `file.patchMedia()` method.
755
759
  */
756
- patchMedia: async (init) => {
760
+ patchMedia: async (init, options) => {
757
761
  const { mock } = this;
758
762
  // const respond = init?.response ?? {
759
763
  // status: 200,
@@ -767,12 +771,12 @@ export class SdkMock {
767
771
  methods: ['PATCH'],
768
772
  },
769
773
  respond,
770
- });
774
+ }, options);
771
775
  },
772
776
  /**
773
777
  * Mocks the `file.delete()` method.
774
778
  */
775
- delete: async (init) => {
779
+ delete: async (init, options) => {
776
780
  const { mock } = this;
777
781
  // const respond = init?.response ?? {
778
782
  // status: 204,
@@ -784,12 +788,12 @@ export class SdkMock {
784
788
  methods: ['DELETE'],
785
789
  },
786
790
  respond,
787
- });
791
+ }, options);
788
792
  },
789
793
  /**
790
794
  * Mocks the `file.deleteBulk()` method.
791
795
  */
792
- deleteBulk: async (init) => {
796
+ deleteBulk: async (init, options) => {
793
797
  const { mock } = this;
794
798
  // const respond = init?.response ?? {
795
799
  // status: 204,
@@ -801,12 +805,12 @@ export class SdkMock {
801
805
  methods: ['DELETE'],
802
806
  },
803
807
  respond,
804
- });
808
+ }, options);
805
809
  },
806
810
  /**
807
811
  * Mocks the `file.patchUsers()` method.
808
812
  */
809
- patchUsers: async (init) => {
813
+ patchUsers: async (init, options) => {
810
814
  const { mock } = this;
811
815
  // const respond = init?.response ?? {
812
816
  // status: 200,
@@ -820,24 +824,24 @@ export class SdkMock {
820
824
  methods: ['PATCH'],
821
825
  },
822
826
  respond,
823
- });
827
+ }, options);
824
828
  },
825
829
  /**
826
830
  * Mocks the `file.addUser()` method.
827
831
  */
828
- addUser: async (init) => {
829
- await this.file.patchUsers(init);
832
+ addUser: async (init, options) => {
833
+ await this.file.patchUsers(init, options);
830
834
  },
831
835
  /**
832
836
  * Mocks the `file.removeUser()` method.
833
837
  */
834
- removeUser: async (init) => {
835
- await this.file.patchUsers(init);
838
+ removeUser: async (init, options) => {
839
+ await this.file.patchUsers(init, options);
836
840
  },
837
841
  /**
838
842
  * Mocks the `file.listUsers()` method.
839
843
  */
840
- listUsers: async (init) => {
844
+ listUsers: async (init, options) => {
841
845
  const { mock } = this;
842
846
  // const respond = init?.response ?? {
843
847
  // status: 200,
@@ -860,12 +864,12 @@ export class SdkMock {
860
864
  methods: ['GET'],
861
865
  },
862
866
  respond,
863
- });
867
+ }, options);
864
868
  },
865
869
  /**
866
870
  * Mocks the `file.breadcrumbs()` method.
867
871
  */
868
- breadcrumbs: async (init) => {
872
+ breadcrumbs: async (init, options) => {
869
873
  const { mock } = this;
870
874
  // const respond = init?.response ?? {
871
875
  // status: 200,
@@ -888,14 +892,14 @@ export class SdkMock {
888
892
  methods: ['GET'],
889
893
  },
890
894
  respond,
891
- });
895
+ }, options);
892
896
  },
893
897
  };
894
898
  /**
895
899
  * Shared API mocks.
896
900
  */
897
901
  shared = {
898
- list: async (init) => {
902
+ list: async (init, options) => {
899
903
  const { mock } = this;
900
904
  // const respond = init?.response ?? {
901
905
  // status: 200,
@@ -918,14 +922,14 @@ export class SdkMock {
918
922
  methods: ['GET'],
919
923
  },
920
924
  respond,
921
- });
925
+ }, options);
922
926
  },
923
927
  };
924
928
  /**
925
929
  * Trash API mocks.
926
930
  */
927
931
  trash = {
928
- list: async (init) => {
932
+ list: async (init, options) => {
929
933
  const { mock } = this;
930
934
  // const respond = init?.response ?? {
931
935
  // status: 200,
@@ -948,9 +952,9 @@ export class SdkMock {
948
952
  methods: ['GET'],
949
953
  },
950
954
  respond,
951
- });
955
+ }, options);
952
956
  },
953
- delete: async (init) => {
957
+ delete: async (init, options) => {
954
958
  const { mock } = this;
955
959
  // const respond = init?.response ?? {
956
960
  // status: 204,
@@ -962,9 +966,9 @@ export class SdkMock {
962
966
  methods: ['DELETE'],
963
967
  },
964
968
  respond,
965
- });
969
+ }, options);
966
970
  },
967
- restore: async (init) => {
971
+ restore: async (init, options) => {
968
972
  const { mock } = this;
969
973
  // const respond = init?.response ?? {
970
974
  // status: 204,
@@ -976,9 +980,9 @@ export class SdkMock {
976
980
  methods: ['POST'],
977
981
  },
978
982
  respond,
979
- });
983
+ }, options);
980
984
  },
981
- empty: async (init) => {
985
+ empty: async (init, options) => {
982
986
  const { mock } = this;
983
987
  // const respond = init?.response ?? {
984
988
  // status: 204,
@@ -990,7 +994,7 @@ export class SdkMock {
990
994
  methods: ['DELETE'],
991
995
  },
992
996
  respond,
993
- });
997
+ }, options);
994
998
  },
995
999
  };
996
1000
  }