@panneau/data 3.0.119 → 3.0.130

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 (3) hide show
  1. package/es/index.js +135 -264
  2. package/lib/index.js +868 -342
  3. package/package.json +7 -6
package/es/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import { useUrlGenerator } from '@panneau/core/contexts';
2
1
  import PropTypes from 'prop-types';
3
2
  import React, { useState, useCallback, useEffect, useRef, useMemo, useContext } from 'react';
3
+ import { useUrlGenerator } from '@panneau/core/contexts';
4
4
  import _createClass from '@babel/runtime/helpers/createClass';
5
5
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
6
6
  import _callSuper from '@babel/runtime/helpers/callSuper';
7
7
  import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
8
8
  import _inherits from '@babel/runtime/helpers/inherits';
9
9
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
10
- import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
11
- import queryString from 'query-string';
10
+ import { getCSRFHeaders, getJSON, postJSON } from '@folklore/fetch';
12
11
  import { generatePath } from '@folklore/routes';
12
+ import queryString from 'query-string';
13
13
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
14
14
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
15
15
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
@@ -348,6 +348,131 @@ var useItems = function useItems(_ref) {
348
348
  };
349
349
  var useItems$1 = useItems;
350
350
 
351
+ var AccountApi = /*#__PURE__*/function () {
352
+ function AccountApi(api, opts) {
353
+ _classCallCheck(this, AccountApi);
354
+ this.api = api;
355
+ this.options = _objectSpread({
356
+ withCredentials: false
357
+ }, opts);
358
+ }
359
+ _createClass(AccountApi, [{
360
+ key: "update",
361
+ value: function update(data) {
362
+ var withCredentials = this.options.withCredentials;
363
+ return this.api.requestPost(this.api.route('account'), data, {
364
+ withSession: !withCredentials,
365
+ withCredentials: withCredentials
366
+ });
367
+ }
368
+ }, {
369
+ key: "updatePassword",
370
+ value: function updatePassword(data) {
371
+ var withCredentials = this.options.withCredentials;
372
+ return this.api.requestPost(this.api.route('account.password'), data, {
373
+ withSession: !withCredentials,
374
+ withCredentials: withCredentials
375
+ });
376
+ }
377
+ }, {
378
+ key: "updateTaxes",
379
+ value: function updateTaxes(data) {
380
+ var withCredentials = this.options.withCredentials;
381
+ return this.api.requestPost(this.api.route('account.taxes'), data, {
382
+ withSession: !withCredentials,
383
+ withCredentials: withCredentials
384
+ });
385
+ }
386
+ }, {
387
+ key: "delete",
388
+ value: function _delete(data) {
389
+ var withCredentials = this.options.withCredentials;
390
+ return this.api.requestPost(this.api.route('account.delete'), data, {
391
+ withSession: !withCredentials,
392
+ withCredentials: withCredentials
393
+ });
394
+ }
395
+ }]);
396
+ return AccountApi;
397
+ }();
398
+ var AccountApi$1 = AccountApi;
399
+
400
+ var AuthApi = /*#__PURE__*/function () {
401
+ function AuthApi(api, opts) {
402
+ _classCallCheck(this, AuthApi);
403
+ this.api = api;
404
+ this.options = _objectSpread({
405
+ withCredentials: true
406
+ }, opts);
407
+ }
408
+ _createClass(AuthApi, [{
409
+ key: "check",
410
+ value: function check() {
411
+ var withCredentials = this.options.withCredentials;
412
+ return this.api.requestGet(this.api.route('auth.check'), null, {
413
+ withSession: !withCredentials,
414
+ withCredentials: withCredentials
415
+ });
416
+ }
417
+ }, {
418
+ key: "login",
419
+ value: function login(email, password) {
420
+ var withCredentials = this.options.withCredentials;
421
+ return this.api.requestPost(this.api.route('auth.login'), {
422
+ email: email,
423
+ password: password
424
+ }, {
425
+ withSession: !withCredentials,
426
+ withCredentials: withCredentials
427
+ });
428
+ }
429
+ }, {
430
+ key: "register",
431
+ value: function register(data) {
432
+ var withCredentials = this.options.withCredentials;
433
+ return this.api.requestPost(this.api.route('auth.register'), data, {
434
+ withSession: !withCredentials,
435
+ withCredentials: withCredentials
436
+ });
437
+ }
438
+ }, {
439
+ key: "logout",
440
+ value: function logout() {
441
+ var url = this.api.getFullUrl(this.api.route('auth.logout'));
442
+ return fetch(url, {
443
+ method: 'POST',
444
+ headers: _objectSpread({}, getCSRFHeaders()),
445
+ credentials: 'include'
446
+ })["catch"](function (err) {
447
+ console.log('logout err', err); // eslint-disable-line
448
+ throw err;
449
+ });
450
+ }
451
+ }, {
452
+ key: "requestPassword",
453
+ value: function requestPassword(email) {
454
+ var withCredentials = this.options.withCredentials;
455
+ return this.api.requestPost(this.api.route('auth.password.email'), {
456
+ email: email
457
+ }, {
458
+ withSession: !withCredentials,
459
+ withCredentials: withCredentials
460
+ });
461
+ }
462
+ }, {
463
+ key: "resetPassword",
464
+ value: function resetPassword(data) {
465
+ var withCredentials = this.options.withCredentials;
466
+ return this.api.requestPost(this.api.route('auth.password.update'), data, {
467
+ withSession: !withCredentials,
468
+ withCredentials: withCredentials
469
+ });
470
+ }
471
+ }]);
472
+ return AuthApi;
473
+ }();
474
+ var AuthApi$1 = AuthApi;
475
+
351
476
  var Base = /*#__PURE__*/function () {
352
477
  function Base() {
353
478
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -465,137 +590,13 @@ var Base = /*#__PURE__*/function () {
465
590
  }();
466
591
  var Base$1 = Base;
467
592
 
468
- var AuthApi = /*#__PURE__*/function () {
469
- function AuthApi(api, opts) {
470
- _classCallCheck(this, AuthApi);
471
- this.api = api;
472
- this.options = _objectSpread({
473
- withCredentials: true
474
- }, opts);
475
- }
476
- _createClass(AuthApi, [{
477
- key: "check",
478
- value: function check() {
479
- var withCredentials = this.options.withCredentials;
480
- return this.api.requestGet(this.api.route('auth.check'), null, {
481
- withSession: !withCredentials,
482
- withCredentials: withCredentials
483
- });
484
- }
485
- }, {
486
- key: "login",
487
- value: function login(email, password) {
488
- var withCredentials = this.options.withCredentials;
489
- return this.api.requestPost(this.api.route('auth.login'), {
490
- email: email,
491
- password: password
492
- }, {
493
- withSession: !withCredentials,
494
- withCredentials: withCredentials
495
- });
496
- }
497
- }, {
498
- key: "register",
499
- value: function register(data) {
500
- var withCredentials = this.options.withCredentials;
501
- return this.api.requestPost(this.api.route('auth.register'), data, {
502
- withSession: !withCredentials,
503
- withCredentials: withCredentials
504
- });
505
- }
506
- }, {
507
- key: "logout",
508
- value: function logout() {
509
- var url = this.api.getFullUrl(this.api.route('auth.logout'));
510
- return fetch(url, {
511
- method: 'POST',
512
- headers: _objectSpread({}, getCSRFHeaders()),
513
- credentials: 'include'
514
- })["catch"](function (err) {
515
- console.log('logout err', err); // eslint-disable-line
516
- throw err;
517
- });
518
- }
519
- }, {
520
- key: "requestPassword",
521
- value: function requestPassword(email) {
522
- var withCredentials = this.options.withCredentials;
523
- return this.api.requestPost(this.api.route('auth.password.email'), {
524
- email: email
525
- }, {
526
- withSession: !withCredentials,
527
- withCredentials: withCredentials
528
- });
529
- }
530
- }, {
531
- key: "resetPassword",
532
- value: function resetPassword(data) {
533
- var withCredentials = this.options.withCredentials;
534
- return this.api.requestPost(this.api.route('auth.password.update'), data, {
535
- withSession: !withCredentials,
536
- withCredentials: withCredentials
537
- });
538
- }
539
- }]);
540
- return AuthApi;
541
- }();
542
- var AuthApi$1 = AuthApi;
543
-
544
- var AccountApi = /*#__PURE__*/function () {
545
- function AccountApi(api, opts) {
546
- _classCallCheck(this, AccountApi);
547
- this.api = api;
548
- this.options = _objectSpread({
549
- withCredentials: false
550
- }, opts);
551
- }
552
- _createClass(AccountApi, [{
553
- key: "update",
554
- value: function update(data) {
555
- var withCredentials = this.options.withCredentials;
556
- return this.api.requestPost(this.api.route('account'), data, {
557
- withSession: !withCredentials,
558
- withCredentials: withCredentials
559
- });
560
- }
561
- }, {
562
- key: "updatePassword",
563
- value: function updatePassword(data) {
564
- var withCredentials = this.options.withCredentials;
565
- return this.api.requestPost(this.api.route('account.password'), data, {
566
- withSession: !withCredentials,
567
- withCredentials: withCredentials
568
- });
569
- }
570
- }, {
571
- key: "updateTaxes",
572
- value: function updateTaxes(data) {
573
- var withCredentials = this.options.withCredentials;
574
- return this.api.requestPost(this.api.route('account.taxes'), data, {
575
- withSession: !withCredentials,
576
- withCredentials: withCredentials
577
- });
578
- }
579
- }, {
580
- key: "delete",
581
- value: function _delete(data) {
582
- var withCredentials = this.options.withCredentials;
583
- return this.api.requestPost(this.api.route('account.delete'), data, {
584
- withSession: !withCredentials,
585
- withCredentials: withCredentials
586
- });
587
- }
588
- }]);
589
- return AccountApi;
590
- }();
591
- var AccountApi$1 = AccountApi;
592
-
593
593
  var MediasApi = /*#__PURE__*/function (_Base) {
594
594
  _inherits(MediasApi, _Base);
595
595
  function MediasApi() {
596
596
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
597
597
  _classCallCheck(this, MediasApi);
598
- return _callSuper(this, MediasApi, [_objectSpread(_objectSpread({}, opts), {}, {
598
+ return _callSuper(this, MediasApi, [{
599
+ baseUrl: opts.baseUrl ? opts.baseUrl : null,
599
600
  routes: _objectSpread({
600
601
  index: 'medias',
601
602
  tags: 'medias/tags',
@@ -604,7 +605,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
604
605
  update: 'medias/:media',
605
606
  "delete": 'medias/:media'
606
607
  }, opts.routes || null)
607
- })]);
608
+ }]); // console.log('opts', opts);
608
609
  }
609
610
  _createClass(MediasApi, [{
610
611
  key: "find",
@@ -661,7 +662,6 @@ var MediasApi = /*#__PURE__*/function (_Base) {
661
662
  }]);
662
663
  return MediasApi;
663
664
  }(Base$1);
664
- var MediasApi$1 = MediasApi;
665
665
 
666
666
  var ResourcesApi = /*#__PURE__*/function () {
667
667
  function ResourcesApi(api) {
@@ -748,8 +748,10 @@ var Api = /*#__PURE__*/function (_Base) {
748
748
  _this.account = new AccountApi$1(_assertThisInitialized(_this), {
749
749
  withCredentials: true
750
750
  });
751
- _this.medias = new MediasApi$1(_assertThisInitialized(_this));
751
+ _this.medias = new MediasApi(opts);
752
752
  _this.resources = new ResourcesApi$1(_assertThisInitialized(_this));
753
+ // console.log('opts', opts);
754
+ // console.log('this', this);
753
755
  return _this;
754
756
  }
755
757
  return _createClass(Api);
@@ -793,137 +795,6 @@ var ApiProvider = function ApiProvider(_ref) {
793
795
  ApiProvider.propTypes = propTypes$1;
794
796
  ApiProvider.defaultProps = defaultProps$1;
795
797
 
796
- var _excluded$4 = ["items", "pageItems"];
797
- var useMedias = function useMedias() {
798
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
799
- var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
800
- var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
801
- var opts = arguments.length > 3 ? arguments[3] : undefined;
802
- var api = useApi();
803
- var getItems = useCallback(function () {
804
- var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
805
- return api.medias.get(query, requestedPage, count);
806
- }, [api, query, count]);
807
- var _useItems = useItems$1(_objectSpread({
808
- getPage: page !== null ? getItems : null,
809
- getItems: page === null ? getItems : null,
810
- page: page
811
- }, opts)),
812
- items = _useItems.items,
813
- pageItems = _useItems.pageItems,
814
- request = _objectWithoutProperties(_useItems, _excluded$4);
815
- // console.log('medias', items);
816
- return _objectSpread({
817
- medias: page !== null ? pageItems : items,
818
- allMedias: items
819
- }, request);
820
- };
821
- var useMedias$1 = useMedias;
822
-
823
- var useMediasRecent = function useMediasRecent(opts) {
824
- var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'media-gallery-recent-searches';
825
- var createSearch = useCallback(function (value) {
826
- if (window !== undefined && value) {
827
- var recent = window.localStorage.getItem(key) || null;
828
- var current = recent !== null ? JSON.parse(recent || '[]') : [];
829
- var encoded = JSON.stringify([value].concat(_toConsumableArray(current)));
830
- window.localStorage.setItem(key, encoded);
831
- return true;
832
- }
833
- return false;
834
- }, [key]);
835
- var getSearches = useCallback(function () {
836
- var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
837
- if (window !== undefined) {
838
- var recent = window.localStorage.getItem(key) || null;
839
- var current = recent !== null ? JSON.parse(recent || '[]') : [];
840
- return current.slice(0, count);
841
- }
842
- return [];
843
- }, [key]);
844
- return {
845
- createSearch: createSearch,
846
- getSearches: getSearches
847
- };
848
- };
849
- var useMediasRecent$1 = useMediasRecent;
850
-
851
- var _excluded$3 = ["data"];
852
- var useMedia = function useMedia(id, opts) {
853
- var api = useApi();
854
- var loader = useCallback(function () {
855
- return api.medias.find(id);
856
- }, [api, id]);
857
- var _useData = useData$1(loader, opts),
858
- data = _useData.data,
859
- request = _objectWithoutProperties(_useData, _excluded$3);
860
- return _objectSpread({
861
- story: data
862
- }, request);
863
- };
864
- var useMedia$1 = useMedia;
865
-
866
- var useMediaCreate = function useMediaCreate() {
867
- var _useState = useState(false),
868
- _useState2 = _slicedToArray(_useState, 2),
869
- creating = _useState2[0],
870
- setCreating = _useState2[1];
871
- var api = useApi();
872
- var create = useCallback(function (data) {
873
- setCreating(true);
874
- return api.medias.create(data).then(function (response) {
875
- setCreating(false);
876
- return response;
877
- });
878
- }, [api, setCreating]);
879
- return {
880
- create: create,
881
- creating: creating
882
- };
883
- };
884
- var useMediaCreate$1 = useMediaCreate;
885
-
886
- var _excluded$2 = ["items", "pageItems"];
887
- var useMediaTags = function useMediaTags() {
888
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
889
- var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
890
- var opts = arguments.length > 2 ? arguments[2] : undefined;
891
- var api = useApi();
892
- var getItems = useCallback(function () {
893
- return api.medias.getTags(query, count);
894
- }, [api, query, count]);
895
- var _useItems = useItems$1(_objectSpread({
896
- getItems: getItems
897
- }, opts)),
898
- items = _useItems.items;
899
- _useItems.pageItems;
900
- var request = _objectWithoutProperties(_useItems, _excluded$2);
901
- return _objectSpread({
902
- tags: items
903
- }, request);
904
- };
905
- var useMediaTags$1 = useMediaTags;
906
-
907
- var useMediaUpdate = function useMediaUpdate() {
908
- var _useState = useState(false),
909
- _useState2 = _slicedToArray(_useState, 2),
910
- updating = _useState2[0],
911
- setUpdating = _useState2[1];
912
- var api = useApi();
913
- var update = useCallback(function (id, data) {
914
- setUpdating(true);
915
- return api.medias.update(id, data).then(function (response) {
916
- setUpdating(false);
917
- return response;
918
- });
919
- }, [api, setUpdating]);
920
- return {
921
- update: update,
922
- updating: updating
923
- };
924
- };
925
- var useMediaUpdate$1 = useMediaUpdate;
926
-
927
798
  var useResourceDestroy = function useResourceDestroy(resource) {
928
799
  var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
929
800
  var _useState = useState(false),
@@ -1075,4 +946,4 @@ DataProvider.propTypes = propTypes;
1075
946
  DataProvider.defaultProps = defaultProps;
1076
947
  var DataProvider$1 = DataProvider;
1077
948
 
1078
- export { Api$1 as Api, ApiProvider, Base$1 as BaseApi, DataProvider$1 as DataProvider, useApi, useData$1 as useData, useItems$1 as useItems, useMedia$1 as useMedia, useMediaCreate$1 as useMediaCreate, useMediaTags$1 as useMediaTags, useMediaUpdate$1 as useMediaUpdate, useMedias$1 as useMedias, useMediasRecent$1 as useMediasRecentSearches, useResourceDestroy$1 as useResourceDestroy, useResourceItem$1 as useResourceItem, useResourceItems$1 as useResourceItems, useResourceCreate$1 as useResourceStore, useResourceUpdate$1 as useResourceUpdate };
949
+ export { Api$1 as Api, ApiProvider, Base$1 as BaseApi, DataProvider$1 as DataProvider, useApi, useData$1 as useData, useItems$1 as useItems, useResourceDestroy$1 as useResourceDestroy, useResourceItem$1 as useResourceItem, useResourceItems$1 as useResourceItems, useResourceCreate$1 as useResourceStore, useResourceUpdate$1 as useResourceUpdate };