@3plus/redux-api 1.0.2

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,82 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ## [0.12.0](https://github.com/lexich/redux-api/compare/v0.11.2...v0.12.0) (2020-02-25)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * potential security vulnerabilities in dependencies ([5a37929](https://github.com/lexich/redux-api/commit/5a379290d78798ca39b4eb7792f9a0cd0d6ab0b8))
11
+
12
+ <a name="0.11.2"></a>
13
+ ## [0.11.2](https://github.com/lexich/redux-api/compare/v0.11.1...v0.11.2) (2017-12-29)
14
+
15
+
16
+
17
+ <a name="0.11.1"></a>
18
+ ## [0.11.1](https://github.com/lexich/redux-api/compare/v0.11.0...v0.11.1) (2017-10-02)
19
+
20
+
21
+
22
+ <a name="0.11.0"></a>
23
+ # [0.11.0](https://github.com/lexich/redux-api/compare/v0.10.8...v0.11.0) (2017-07-31)
24
+
25
+
26
+
27
+ <a name="0.10.8"></a>
28
+ ## [0.10.8](https://github.com/lexich/redux-api/compare/v0.10.7...v0.10.8) (2017-07-14)
29
+
30
+
31
+
32
+ <a name="0.10.7"></a>
33
+ ## [0.10.7](https://github.com/lexich/redux-api/compare/v0.10.6...v0.10.7) (2017-07-10)
34
+
35
+
36
+
37
+ <a name="0.10.6"></a>
38
+ ## [0.10.6](https://github.com/lexich/redux-api/compare/v0.10.5...v0.10.6) (2017-06-12)
39
+
40
+
41
+
42
+ <a name="0.10.5"></a>
43
+ ## [0.10.5](https://github.com/lexich/redux-api/compare/v0.10.4...v0.10.5) (2017-05-18)
44
+
45
+
46
+
47
+ <a name="0.10.4"></a>
48
+ ## [0.10.4](https://github.com/lexich/redux-api/compare/v0.10.3...v0.10.4) (2017-04-28)
49
+
50
+
51
+
52
+ <a name="0.10.3"></a>
53
+ ## [0.10.3](https://github.com/lexich/redux-api/compare/v0.10.2...v0.10.3) (2017-03-30)
54
+
55
+
56
+
57
+ <a name="0.10.2"></a>
58
+ ## [0.10.2](https://github.com/lexich/redux-api/compare/v0.9.18...v0.10.2) (2017-03-29)
59
+ Add support cache [option](https://github.com/lexich/redux-api/blob/master/docs/DOCS.md#cache)
60
+
61
+ <a name="0.9.18"></a>
62
+ ## [0.9.18](https://github.com/lexich/redux-api/compare/v0.9.17...v0.9.18) (2017-03-06)
63
+
64
+
65
+
66
+ <a name="0.9.17"></a>
67
+ ## [0.9.17](https://github.com/lexich/redux-api/compare/0.9.16...v0.9.17) (2017-01-19)
68
+
69
+
70
+
71
+ <a name="0.9.15"></a>
72
+ ## [0.9.15](https://github.com/lexich/redux-api/compare/v0.9.13...v0.9.15) (2016-11-16)
73
+
74
+
75
+
76
+ <a name="0.9.13"></a>
77
+ ## [0.9.13](https://github.com/lexich/redux-api/compare/v0.9.12...v0.9.13) (2016-10-24)
78
+
79
+
80
+
81
+ <a name="0.9.12"></a>
82
+ ## [0.9.12](https://github.com/lexich/redux-api/compare/0.9.11...v0.9.12) (2016-10-24)
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2016 Efremov Alex
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ ### Redux-api
2
+ Flux REST API for redux infrastructure
3
+
4
+ ## Introduction
5
+ `redux-api` solves the problem of writing clients to communicate with backends. It generates [actions](http://redux.js.org/docs/basics/Actions.html) and [reducers](http://redux.js.org/docs/basics/Reducers.html) for making AJAX calls to API endpoints. You don't need to write a lot of [boilerplate code](http://redux.js.org/docs/advanced/ExampleRedditAPI.html) if you use `redux` and want to exchange data with server.
6
+
7
+ Inspired by [Redux-rest](https://github.com/Kvoti/redux-rest) and is intended to be used with [Redux](https://github.com/gaearon/redux).
8
+
9
+
10
+ ## Documentation
11
+ See [DOCS.md](docs/DOCS.md) for API documentation.
12
+ ## Use cases
13
+ * [AuthorizationJWT.md](docs/AuthorizationJWT.md) - example of JWT Authorization
14
+ * [Scoping.md](docs/Scoping.md) - use scoping or using multiple redux-api instance without naming intersections.
15
+
16
+ ## Install
17
+ With npm:
18
+ ```sh
19
+ npm install @3plus/redux-api --save
20
+ ```
21
+
22
+ =======
23
+ ## Remote calls
24
+
25
+ `redux-api` doesn't bind you to a technology to make AJAX calls. It uses configurable `adapters` - a pretty simple function which receives 2 arguments: `endpoint` and `options`, and returns a Promise as result. The default adapter uses [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), and has an implementation like this:
26
+ ```js
27
+ function adapterFetch(url, options) {
28
+ return fetch(url, options);
29
+ }
30
+ ```
31
+
32
+ However, you are not tied to using isomorphic-fetch. For instance, if you prefer to use jQuery, you can use the following adapter:
33
+ ```js
34
+ function adapterJquery(url, options) {
35
+ return new Promise((success, error)=> {
36
+ $.ajax({ ...options, url, success, error });
37
+ });
38
+ }
39
+ ```
40
+ This implementation allows you to make any request and process any response.
41
+
42
+ And of course you have to set up adapter to your `redux-api` instance before using.
43
+ ```
44
+ reduxApi(....).use("fetch", adapterFetch)
45
+ ```
46
+
47
+ =======
48
+
49
+ ### Example
50
+ rest.js
51
+ ```js
52
+ import "isomorphic-fetch";
53
+ import reduxApi, {transformers} from "@3plus/redux-api";
54
+ import adapterFetch from "@3plus/redux-api/lib/adapters/fetch";
55
+ export default reduxApi({
56
+ // simple endpoint description
57
+ entry: `/api/v1/entry/:id`,
58
+ // complex endpoint description
59
+ regions: {
60
+ url: `/api/v1/regions`,
61
+ // reimplement default `transformers.object`
62
+ transformer: transformers.array,
63
+ // base endpoint options `fetch(url, options)`
64
+ options: {
65
+ headers: {
66
+ "Accept": "application/json"
67
+ }
68
+ }
69
+ }
70
+ }).use("fetch", adapterFetch(fetch));
71
+ ```
72
+
73
+ index.jsx
74
+ ```js
75
+ import React, {PropTypes} from "react";
76
+ import { createStore, applyMiddleware, combineReducers } from "redux";
77
+ import thunk from "redux-thunk";
78
+ import { Provider, connect } from "react-redux";
79
+ import rest from "./rest"; //our redux-rest object
80
+
81
+ const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
82
+ const reducer = combineReducers(rest.reducers);
83
+ const store = createStoreWithMiddleware(reducer);
84
+
85
+ function select(state) {
86
+ return { entry: state.entry, regions: state.regions };
87
+ }
88
+
89
+ class Application {
90
+ static propTypes = {
91
+ entry: PropTypes.shape({
92
+ loading: PropTypes.bool.isRequired,
93
+ data: PropTypes.shape({
94
+ text: PropTypes.string
95
+ }).isRequired
96
+ }).isRequired,
97
+ regions: PropTypes.shape({
98
+ loading: PropTypes.bool.isRequired,
99
+ data: PropTypes.array.isRequired
100
+ }).isRequired,
101
+ dispatch: PropTypes.func.isRequired
102
+ };
103
+ componentDidMount() {
104
+ const {dispatch} = this.props;
105
+ // fetch `/api/v1/regions
106
+ dispatch(rest.actions.regions.sync());
107
+ //specify id for GET: /api/v1/entry/1
108
+ dispatch(rest.actions.entry({id: 1}));
109
+ }
110
+ render() {
111
+ const {entry, regions} = this.props;
112
+ const Regions = regions.data.map((item)=> <p>{ item.name }</p>)
113
+ return (
114
+ <div>
115
+ Loading regions: { regions.loading }
116
+ <Regions/>
117
+ Loading entry: {entry.loading}
118
+ <div>{{ entry.data.text }}</div>
119
+ </div>
120
+ );
121
+ }
122
+ }
123
+
124
+ const SmartComponent = connect(select)(Application);
125
+
126
+ React.render(
127
+ <Provider store={store}>
128
+ <SmartComponent />
129
+ </Provider>,
130
+ document.getElementById("content")
131
+ );
132
+ ```
package/lib/PubSub.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
9
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
10
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ var PubSub = exports["default"] = /*#__PURE__*/function () {
14
+ function PubSub() {
15
+ _classCallCheck(this, PubSub);
16
+ this.container = [];
17
+ }
18
+ return _createClass(PubSub, [{
19
+ key: "push",
20
+ value: function push(cb) {
21
+ cb instanceof Function && this.container.push(cb);
22
+ }
23
+ }, {
24
+ key: "resolve",
25
+ value: function resolve(data) {
26
+ var container = this.container;
27
+ this.container = [];
28
+ container.forEach(function (cb) {
29
+ return cb(null, data);
30
+ });
31
+ }
32
+ }, {
33
+ key: "reject",
34
+ value: function reject(err) {
35
+ var container = this.container;
36
+ this.container = [];
37
+ container.forEach(function (cb) {
38
+ return cb(err);
39
+ });
40
+ }
41
+ }]);
42
+ }();
43
+ module.exports = exports.default;
44
+ //# sourceMappingURL=PubSub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PubSub.js","names":["Object","defineProperty","exports","value","_typeof","o","Symbol","iterator","constructor","prototype","_classCallCheck","a","n","TypeError","_defineProperties","e","r","t","length","enumerable","configurable","writable","_toPropertyKey","key","_createClass","i","_toPrimitive","toPrimitive","call","String","Number","PubSub","container","push","cb","Function","resolve","data","forEach","reject","err","module","default"],"sources":["../src/PubSub.js"],"sourcesContent":["\"use strict\";\n\nexport default class PubSub {\n constructor() {\n this.container = [];\n }\n\n push(cb) {\n cb instanceof Function && this.container.push(cb);\n }\n\n resolve(data) {\n const container = this.container;\n this.container = [];\n container.forEach(cb => cb(null, data));\n }\n\n reject(err) {\n const container = this.container;\n this.container = [];\n container.forEach(cb => cb(err));\n }\n}\n"],"mappings":"AAAA,YAAY;;AAACA,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,KAAA;AAAA;AAAAD,OAAA;AAAA,SAAAE,QAAAC,CAAA,sCAAAD,OAAA,wBAAAE,MAAA,uBAAAA,MAAA,CAAAC,QAAA,aAAAF,CAAA,kBAAAA,CAAA,gBAAAA,CAAA,WAAAA,CAAA,yBAAAC,MAAA,IAAAD,CAAA,CAAAG,WAAA,KAAAF,MAAA,IAAAD,CAAA,KAAAC,MAAA,CAAAG,SAAA,qBAAAJ,CAAA,KAAAD,OAAA,CAAAC,CAA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