@mx-space/api-client 0.0.5 → 0.3.1

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.
Files changed (170) hide show
  1. package/build/index.cjs.js +411 -53
  2. package/build/index.cjs.js.map +1 -1
  3. package/build/index.cjs.min.js +1 -1
  4. package/build/index.cjs.min.js.map +1 -1
  5. package/build/index.d.ts +463 -108
  6. package/build/index.esm.js +411 -53
  7. package/build/index.esm.js.map +1 -1
  8. package/build/index.esm.min.js +1 -1
  9. package/build/index.esm.min.js.map +1 -1
  10. package/build/index.umd.js +411 -53
  11. package/build/index.umd.js.map +1 -1
  12. package/build/index.umd.min.js +1 -1
  13. package/build/index.umd.min.js.map +1 -1
  14. package/esm/core/attachRequest.js +4 -0
  15. package/esm/core/attachRequest.js.map +1 -1
  16. package/esm/core/client.d.ts +2 -9
  17. package/esm/core/client.js +16 -2
  18. package/esm/core/client.js.map +1 -1
  19. package/esm/core/controllers/aggregate.d.ts +44 -0
  20. package/esm/core/controllers/aggregate.js +40 -0
  21. package/esm/core/controllers/aggregate.js.map +1 -0
  22. package/esm/core/controllers/all.d.ts +13 -2
  23. package/esm/core/controllers/all.js +38 -9
  24. package/esm/core/controllers/all.js.map +1 -1
  25. package/esm/core/controllers/base.d.ts +29 -0
  26. package/esm/core/controllers/base.js +25 -0
  27. package/esm/core/controllers/base.js.map +1 -0
  28. package/esm/core/controllers/category.d.ts +44 -0
  29. package/esm/core/controllers/category.js +66 -0
  30. package/esm/core/controllers/category.js.map +1 -0
  31. package/esm/core/controllers/index.d.ts +0 -2
  32. package/esm/core/controllers/index.js +0 -3
  33. package/esm/core/controllers/index.js.map +1 -1
  34. package/esm/core/controllers/link.d.ts +9 -0
  35. package/esm/core/controllers/link.js +10 -0
  36. package/esm/core/controllers/link.js.map +1 -0
  37. package/esm/core/controllers/project.d.ts +9 -0
  38. package/esm/core/controllers/project.js +10 -0
  39. package/esm/core/controllers/project.js.map +1 -0
  40. package/esm/core/controllers/recently.d.ts +33 -0
  41. package/esm/core/controllers/recently.js +32 -0
  42. package/esm/core/controllers/recently.js.map +1 -0
  43. package/esm/core/controllers/say.d.ts +22 -0
  44. package/esm/core/controllers/say.js +19 -0
  45. package/esm/core/controllers/say.js.map +1 -0
  46. package/esm/core/controllers/search.d.ts +58 -0
  47. package/esm/core/controllers/search.js +26 -0
  48. package/esm/core/controllers/search.js.map +1 -0
  49. package/esm/core/controllers/snippet.d.ts +18 -0
  50. package/esm/core/controllers/snippet.js +17 -0
  51. package/esm/core/controllers/snippet.js.map +1 -0
  52. package/esm/core/controllers/user.d.ts +28 -0
  53. package/esm/core/controllers/user.js +29 -0
  54. package/esm/core/controllers/user.js.map +1 -0
  55. package/esm/core/define.d.ts +19 -0
  56. package/esm/core/define.js +12 -0
  57. package/esm/core/define.js.map +1 -0
  58. package/esm/interfaces/options.d.ts +1 -0
  59. package/esm/interfaces/options.js +2 -0
  60. package/esm/interfaces/options.js.map +1 -0
  61. package/esm/interfaces/request.d.ts +9 -3
  62. package/esm/models/aggregate.d.ts +47 -0
  63. package/esm/models/aggregate.js +6 -0
  64. package/esm/models/aggregate.js.map +1 -0
  65. package/esm/models/category.d.ts +24 -0
  66. package/esm/models/category.js +6 -0
  67. package/esm/models/category.js.map +1 -0
  68. package/esm/models/link.d.ts +17 -0
  69. package/esm/models/link.js +11 -0
  70. package/esm/models/link.js.map +1 -0
  71. package/esm/models/project.d.ts +16 -0
  72. package/esm/models/project.js +2 -0
  73. package/esm/models/project.js.map +1 -0
  74. package/esm/models/recently.d.ts +5 -0
  75. package/esm/models/recently.js +2 -0
  76. package/esm/models/recently.js.map +1 -0
  77. package/esm/models/say.d.ts +6 -0
  78. package/esm/models/say.js +2 -0
  79. package/esm/models/say.js.map +1 -0
  80. package/esm/models/setting.d.ts +66 -0
  81. package/esm/models/setting.js +2 -0
  82. package/esm/models/setting.js.map +1 -0
  83. package/esm/models/snippet.d.ts +14 -0
  84. package/esm/models/snippet.js +7 -0
  85. package/esm/models/snippet.js.map +1 -0
  86. package/esm/models/user.d.ts +29 -0
  87. package/esm/models/user.js +2 -0
  88. package/esm/models/user.js.map +1 -0
  89. package/esm/utils/index.d.ts +4 -0
  90. package/esm/utils/index.js +38 -0
  91. package/esm/utils/index.js.map +1 -1
  92. package/lib/core/attachRequest.js +4 -0
  93. package/lib/core/attachRequest.js.map +1 -1
  94. package/lib/core/client.d.ts +2 -9
  95. package/lib/core/client.js +16 -2
  96. package/lib/core/client.js.map +1 -1
  97. package/lib/core/controllers/aggregate.d.ts +44 -0
  98. package/lib/core/controllers/aggregate.js +44 -0
  99. package/lib/core/controllers/aggregate.js.map +1 -0
  100. package/lib/core/controllers/all.d.ts +13 -2
  101. package/lib/core/controllers/all.js +52 -11
  102. package/lib/core/controllers/all.js.map +1 -1
  103. package/lib/core/controllers/base.d.ts +29 -0
  104. package/lib/core/controllers/base.js +29 -0
  105. package/lib/core/controllers/base.js.map +1 -0
  106. package/lib/core/controllers/category.d.ts +44 -0
  107. package/lib/core/controllers/category.js +70 -0
  108. package/lib/core/controllers/category.js.map +1 -0
  109. package/lib/core/controllers/index.d.ts +0 -2
  110. package/lib/core/controllers/index.js +0 -3
  111. package/lib/core/controllers/index.js.map +1 -1
  112. package/lib/core/controllers/link.d.ts +9 -0
  113. package/lib/core/controllers/link.js +14 -0
  114. package/lib/core/controllers/link.js.map +1 -0
  115. package/lib/core/controllers/project.d.ts +9 -0
  116. package/lib/core/controllers/project.js +14 -0
  117. package/lib/core/controllers/project.js.map +1 -0
  118. package/lib/core/controllers/recently.d.ts +33 -0
  119. package/lib/core/controllers/recently.js +36 -0
  120. package/lib/core/controllers/recently.js.map +1 -0
  121. package/lib/core/controllers/say.d.ts +22 -0
  122. package/lib/core/controllers/say.js +23 -0
  123. package/lib/core/controllers/say.js.map +1 -0
  124. package/lib/core/controllers/search.d.ts +58 -0
  125. package/lib/core/controllers/search.js +30 -0
  126. package/lib/core/controllers/search.js.map +1 -0
  127. package/lib/core/controllers/snippet.d.ts +18 -0
  128. package/lib/core/controllers/snippet.js +21 -0
  129. package/lib/core/controllers/snippet.js.map +1 -0
  130. package/lib/core/controllers/user.d.ts +28 -0
  131. package/lib/core/controllers/user.js +33 -0
  132. package/lib/core/controllers/user.js.map +1 -0
  133. package/lib/core/define.d.ts +19 -0
  134. package/lib/core/define.js +16 -0
  135. package/lib/core/define.js.map +1 -0
  136. package/lib/interfaces/options.d.ts +1 -0
  137. package/lib/interfaces/options.js +3 -0
  138. package/lib/interfaces/options.js.map +1 -0
  139. package/lib/interfaces/request.d.ts +9 -3
  140. package/lib/models/aggregate.d.ts +47 -0
  141. package/lib/models/aggregate.js +9 -0
  142. package/lib/models/aggregate.js.map +1 -0
  143. package/lib/models/category.d.ts +24 -0
  144. package/lib/models/category.js +9 -0
  145. package/lib/models/category.js.map +1 -0
  146. package/lib/models/link.d.ts +17 -0
  147. package/lib/models/link.js +14 -0
  148. package/lib/models/link.js.map +1 -0
  149. package/lib/models/project.d.ts +16 -0
  150. package/lib/models/project.js +3 -0
  151. package/lib/models/project.js.map +1 -0
  152. package/lib/models/recently.d.ts +5 -0
  153. package/lib/models/recently.js +3 -0
  154. package/lib/models/recently.js.map +1 -0
  155. package/lib/models/say.d.ts +6 -0
  156. package/lib/models/say.js +3 -0
  157. package/lib/models/say.js.map +1 -0
  158. package/lib/models/setting.d.ts +66 -0
  159. package/lib/models/setting.js +3 -0
  160. package/lib/models/setting.js.map +1 -0
  161. package/lib/models/snippet.d.ts +14 -0
  162. package/lib/models/snippet.js +10 -0
  163. package/lib/models/snippet.js.map +1 -0
  164. package/lib/models/user.d.ts +29 -0
  165. package/lib/models/user.js +3 -0
  166. package/lib/models/user.js.map +1 -0
  167. package/lib/utils/index.d.ts +4 -0
  168. package/lib/utils/index.js +42 -1
  169. package/lib/utils/index.js.map +1 -1
  170. package/package.json +11 -11
@@ -364,6 +364,44 @@ var camelcaseKeys = (input, options) => {
364
364
 
365
365
  const isPlainObject = (obj) => typeof obj === 'object' &&
366
366
  Object.prototype.toString.call(obj) === '[object Object]';
367
+ const sortOrderToNumber = (order) => {
368
+ return ({
369
+ asc: 1,
370
+ desc: -1,
371
+ }[order] || 1);
372
+ };
373
+ const destructureData = (payload) => {
374
+ if (typeof payload !== 'object') {
375
+ return payload;
376
+ }
377
+ if (payload === null) {
378
+ return payload;
379
+ }
380
+ const data = payload.data;
381
+ const dataIsPlainObject = Object.prototype.toString.call(data) === '[object Object]';
382
+ if (dataIsPlainObject && Object.keys(payload).length === 1) {
383
+ const d = Object.assign({}, data);
384
+ // attach raw onto new data
385
+ attachRawFromOneToAnthor(payload, d);
386
+ return d;
387
+ }
388
+ return payload;
389
+ };
390
+ const attachRawFromOneToAnthor = (from, to) => {
391
+ if (!from) {
392
+ return;
393
+ }
394
+ from.$raw &&
395
+ Object.defineProperty(to, '$raw', {
396
+ value: Object.assign({}, from.$raw),
397
+ enumerable: false,
398
+ });
399
+ from.$request &&
400
+ Object.defineProperty(to, '$request', {
401
+ value: Object.assign({}, from.$request),
402
+ enumerable: false,
403
+ });
404
+ };
367
405
 
368
406
  function attachRequestMethod(target) {
369
407
  Object.defineProperty(target, '$$get', {
@@ -390,11 +428,200 @@ function handleSearchParams(obj) {
390
428
  }
391
429
  const search = new URLSearchParams();
392
430
  Object.entries(obj).forEach(([k, v]) => {
431
+ if (typeof v === 'undefined' ||
432
+ Object.prototype.toString.call(v) === '[object Null]') {
433
+ return;
434
+ }
393
435
  search.set(k, v);
394
436
  });
395
437
  return search.toString();
396
438
  }
397
439
 
440
+ class AggregateController {
441
+ constructor(client) {
442
+ this.client = client;
443
+ this.base = 'aggregate';
444
+ this.name = 'aggregate';
445
+ }
446
+ get proxy() {
447
+ return this.client.proxy(this.base);
448
+ }
449
+ /**
450
+ * 获取聚合数据
451
+ */
452
+ getAggregateData() {
453
+ return this.proxy.get();
454
+ }
455
+ /**
456
+ * 获取最新发布的内容
457
+ */
458
+ getTop(size = 5) {
459
+ return this.proxy.top.get({ params: { size } });
460
+ }
461
+ getTimeline(options) {
462
+ const { sort, type, year } = options || {};
463
+ return this.proxy.timeline.get({
464
+ params: {
465
+ sort: sort && sortOrderToNumber(sort),
466
+ type,
467
+ year,
468
+ },
469
+ });
470
+ }
471
+ /**
472
+ * 获取聚合数据统计
473
+ */
474
+ getStat() {
475
+ return this.proxy.stat.get();
476
+ }
477
+ }
478
+
479
+ var CategoryType;
480
+ (function (CategoryType) {
481
+ CategoryType[CategoryType["Category"] = 0] = "Category";
482
+ CategoryType[CategoryType["Tag"] = 1] = "Tag";
483
+ })(CategoryType || (CategoryType = {}));
484
+
485
+ class CategoryController {
486
+ constructor(client) {
487
+ this.client = client;
488
+ this.name = 'category';
489
+ this.base = 'categories';
490
+ }
491
+ get proxy() {
492
+ return this.client.proxy(this.base);
493
+ }
494
+ getAllCategories() {
495
+ return this.proxy.get({
496
+ params: {
497
+ type: CategoryType.Category,
498
+ },
499
+ });
500
+ }
501
+ getAllTags() {
502
+ return this.proxy.get({
503
+ params: {
504
+ type: CategoryType.Tag,
505
+ },
506
+ });
507
+ }
508
+ async getCategoryDetail(ids) {
509
+ if (typeof ids === 'string') {
510
+ const data = await this.proxy.get({
511
+ params: {
512
+ ids: ids,
513
+ },
514
+ });
515
+ const result = Object.values(data.entries)[0];
516
+ attachRawFromOneToAnthor(data, result);
517
+ return result;
518
+ }
519
+ else if (Array.isArray(ids)) {
520
+ const data = await this.proxy.get({
521
+ params: {
522
+ ids: ids.join(','),
523
+ },
524
+ });
525
+ const entries = data === null || data === void 0 ? void 0 : data.entries;
526
+ if (!entries) {
527
+ throw new RequestError('data structure error', 500, data.$request.path, data);
528
+ }
529
+ const map = new Map(Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]));
530
+ attachRawFromOneToAnthor(data, map);
531
+ return map;
532
+ }
533
+ }
534
+ async getCategoryByIdOrSlug(idOrSlug) {
535
+ const res = await this.proxy(idOrSlug).get();
536
+ return destructureData(res);
537
+ }
538
+ async getTagByName(name) {
539
+ const res = await this.proxy(name).get({
540
+ params: {
541
+ tag: 1,
542
+ },
543
+ });
544
+ return res;
545
+ }
546
+ }
547
+
548
+ class CommentController {
549
+ constructor(client) {
550
+ this.client = client;
551
+ this.base = 'comments';
552
+ this.name = 'comment';
553
+ }
554
+ get proxy() {
555
+ return this.client.proxy(this.base);
556
+ }
557
+ /**
558
+ * 根据 comment id 获取评论, 包括子评论
559
+ */
560
+ getById(id) {
561
+ return this.proxy(id).get();
562
+ }
563
+ /**
564
+ * 获取文章的评论列表
565
+ * @param refId 文章 Id
566
+ */
567
+ getByRefId(refId, pagination = {}) {
568
+ const { page, size } = pagination;
569
+ return this.proxy.ref(refId).get({
570
+ params: { page: page || 1, size: size || 10 },
571
+ });
572
+ }
573
+ /**
574
+ * 评论
575
+ */
576
+ comment(refId, data) {
577
+ return this.proxy(refId).post({
578
+ data,
579
+ });
580
+ }
581
+ /**
582
+ * 回复评论
583
+ */
584
+ reply(commentId, data) {
585
+ return this.proxy.reply(commentId).post({
586
+ data,
587
+ });
588
+ }
589
+ }
590
+
591
+ class BaseCrudController {
592
+ constructor(client) {
593
+ this.client = client;
594
+ }
595
+ get proxy() {
596
+ return this.client.proxy(this.base);
597
+ }
598
+ getById(id) {
599
+ return this.proxy(id).get();
600
+ }
601
+ getAll() {
602
+ return this.proxy.all.get();
603
+ }
604
+ /**
605
+ * 带分页的查询
606
+ * @param page
607
+ * @param perPage
608
+ */
609
+ getAllPaginated(page, perPage) {
610
+ return this.proxy.get({
611
+ params: { page, size: perPage },
612
+ });
613
+ }
614
+ }
615
+
616
+ class LinkController extends BaseCrudController {
617
+ constructor(client) {
618
+ super(client);
619
+ this.client = client;
620
+ this.name = 'link';
621
+ this.base = 'links';
622
+ }
623
+ }
624
+
398
625
  class NoteController {
399
626
  constructor(client) {
400
627
  this.client = client;
@@ -449,6 +676,39 @@ class NoteController {
449
676
  }
450
677
  }
451
678
 
679
+ class PageController {
680
+ constructor(client) {
681
+ this.client = client;
682
+ this.base = 'pages';
683
+ this.name = 'page';
684
+ }
685
+ get proxy() {
686
+ return this.client.proxy(this.base);
687
+ }
688
+ /**
689
+ * 页面列表
690
+ */
691
+ getList(page = 1, perPage = 10) {
692
+ return this.proxy.get({
693
+ params: { page, size: perPage },
694
+ });
695
+ }
696
+ /**
697
+ * 页面详情
698
+ */
699
+ getById(id) {
700
+ return this.proxy(id).get();
701
+ }
702
+ /**
703
+ * 根据路径获取页面
704
+ * @param slug 路径
705
+ * @returns
706
+ */
707
+ getBySlug(slug) {
708
+ return this.proxy.slug(slug).get({});
709
+ }
710
+ }
711
+
452
712
  class PostController {
453
713
  constructor(client) {
454
714
  this.client = client;
@@ -491,94 +751,179 @@ class PostController {
491
751
  }
492
752
  }
493
753
 
494
- class CommentController {
754
+ class ProjectController extends BaseCrudController {
495
755
  constructor(client) {
756
+ super(client);
496
757
  this.client = client;
497
- this.base = 'comments';
498
- this.name = 'comment';
758
+ this.base = 'projects';
759
+ this.name = 'project';
760
+ }
761
+ }
762
+
763
+ class RecentlyController {
764
+ constructor(client) {
765
+ this.client = client;
766
+ this.base = 'recently';
767
+ this.name = 'recently';
499
768
  }
500
769
  get proxy() {
501
770
  return this.client.proxy(this.base);
502
771
  }
503
772
  /**
504
- * 根据 comment id 获取评论, 包括子评论
773
+ * 获取最新一条
505
774
  */
506
- getById(id) {
507
- return this.proxy(id).get();
775
+ getLatestOne() {
776
+ return this.proxy.latest.get();
508
777
  }
509
- /**
510
- * 获取文章的评论列表
511
- * @param refId 文章 Id
512
- */
513
- getByRefId(refId, pagination = {}) {
514
- const { page, size } = pagination;
515
- return this.proxy.ref(refId).get({
516
- params: { page: page || 1, size: size || 10 },
517
- });
778
+ getAll() {
779
+ return this.proxy.all.get();
518
780
  }
519
- /**
520
- * 评论
521
- */
522
- comment(refId, data) {
523
- return this.proxy(refId).post({
524
- data,
781
+ getList(before, after, size) {
782
+ if (!before && !after) {
783
+ throw new Error('you can only choose `before` or `after`');
784
+ }
785
+ return this.proxy.get({
786
+ params: {
787
+ before,
788
+ after,
789
+ size,
790
+ },
525
791
  });
526
792
  }
793
+ }
794
+
795
+ class SayController extends BaseCrudController {
796
+ constructor(client) {
797
+ super(client);
798
+ this.client = client;
799
+ this.base = 'says';
800
+ this.name = 'say';
801
+ }
802
+ get proxy() {
803
+ return this.client.proxy(this.base);
804
+ }
527
805
  /**
528
- * 回复评论
806
+ * 获取随机一条
529
807
  */
530
- reply(commentId, data) {
531
- return this.proxy.reply(commentId).post({
532
- data,
533
- });
808
+ getRandom() {
809
+ return this.proxy.random.get();
534
810
  }
535
811
  }
536
812
 
537
- class PageController {
813
+ class SearchController {
538
814
  constructor(client) {
539
815
  this.client = client;
540
- this.base = 'pages';
541
- this.name = 'page';
816
+ this.base = 'search';
817
+ this.name = 'search';
542
818
  }
543
819
  get proxy() {
544
820
  return this.client.proxy(this.base);
545
821
  }
546
- /**
547
- * 页面列表
548
- */
549
- getList(page = 1, perPage = 10) {
550
- return this.proxy.get({
551
- params: { page, size: perPage },
822
+ search(type, keyword, options = {}) {
823
+ return this.proxy(type).get({
824
+ params: Object.assign({ keyword }, options),
552
825
  });
553
826
  }
554
827
  /**
555
- * 页面详情
828
+ * 从 algolya 搜索
829
+ * https://www.algolia.com/doc/api-reference/api-methods/search/
830
+ * @param keyword
831
+ * @param options
832
+ * @returns
556
833
  */
834
+ searchByAlgolia(keyword, options) {
835
+ return this.proxy('algolia').get({ params: Object.assign({ keyword }, options) });
836
+ }
837
+ }
838
+
839
+ class SnippetController {
840
+ constructor(client) {
841
+ this.client = client;
842
+ this.base = 'snippets';
843
+ this.name = 'snippet';
844
+ }
845
+ get proxy() {
846
+ return this.client.proxy(this.base);
847
+ }
557
848
  getById(id) {
558
849
  return this.proxy(id).get();
559
850
  }
560
- /**
561
- * 根据路径获取页面
562
- * @param slug 路径
563
- * @returns
564
- */
565
- getBySlug(slug) {
566
- return this.proxy.slug(slug).get({});
851
+ getByReferenceAndName(reference, name) {
852
+ return this.proxy(reference)(name).get();
853
+ }
854
+ }
855
+
856
+ class UserController {
857
+ constructor(client) {
858
+ this.client = client;
859
+ this.base = 'master';
860
+ this.name = 'user';
861
+ }
862
+ get proxy() {
863
+ return this.client.proxy(this.base);
864
+ }
865
+ getMasterInfo() {
866
+ return this.proxy.get();
867
+ }
868
+ login(username, password) {
869
+ return this.proxy.login.post({
870
+ data: {
871
+ username,
872
+ password,
873
+ },
874
+ });
875
+ }
876
+ checkTokenValid(token) {
877
+ return this.proxy.check_logged.get({
878
+ params: {
879
+ token,
880
+ },
881
+ });
567
882
  }
568
883
  }
569
884
 
570
885
  const allControllers = [
886
+ AggregateController,
887
+ CategoryController,
888
+ CommentController,
889
+ LinkController,
571
890
  NoteController,
572
- PostController,
573
891
  PageController,
574
- CommentController,
892
+ PostController,
893
+ ProjectController,
894
+ RecentlyController,
895
+ SayController,
896
+ SearchController,
897
+ SnippetController,
898
+ UserController,
899
+ ];
900
+ const allContollerNames = [
901
+ 'aggregate',
902
+ 'category',
903
+ 'comment',
904
+ 'link',
905
+ 'note',
906
+ 'page',
907
+ 'post',
908
+ 'project',
909
+ 'recently',
910
+ 'say',
911
+ 'search',
912
+ 'snippet',
913
+ 'user',
575
914
  ];
576
- // export const allClientName = allClients.map((c) =>
577
- // c.name.replace('Client', '').toLowerCase(),
578
- // )
579
- // Why not code like before
580
- // In order to tree shake unnecessary client
581
- const allContollerNames = ['note', 'post', 'page', 'comment'];
915
+
916
+ class HTTPControllerDefine {
917
+ get master() {
918
+ return this.user;
919
+ }
920
+ get friend() {
921
+ return this.link;
922
+ }
923
+ get shorthand() {
924
+ return this.recently;
925
+ }
926
+ }
582
927
 
583
928
  class RequestError extends Error {
584
929
  constructor(message, status, path, raw) {
@@ -589,8 +934,10 @@ class RequestError extends Error {
589
934
  }
590
935
  }
591
936
 
592
- class HTTPClient {
937
+ class HTTPClient extends HTTPControllerDefine {
938
+ // define all clients
593
939
  constructor(_endpoint, _instance) {
940
+ super();
594
941
  this._endpoint = _endpoint;
595
942
  this._instance = _instance;
596
943
  this._endpoint = _endpoint
@@ -692,13 +1039,24 @@ class HTTPClient {
692
1039
  const transform = Array.isArray(data) || isPlainObject(data)
693
1040
  ? camelcaseKeys(data, { deep: true })
694
1041
  : data;
695
- Object.defineProperty(transform, 'raw', {
1042
+ Object.defineProperty(transform, '$raw', {
696
1043
  get() {
697
1044
  return res;
698
1045
  },
699
1046
  enumerable: false,
700
1047
  configurable: false,
701
1048
  });
1049
+ // attach request config onto response
1050
+ Object.defineProperty(transform, '$request', {
1051
+ get() {
1052
+ return {
1053
+ url,
1054
+ method: name,
1055
+ options,
1056
+ };
1057
+ },
1058
+ enumerable: false,
1059
+ });
702
1060
  return transform;
703
1061
  };
704
1062
  }