@ercioko/meblotex-api 0.1.1 → 0.1.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/dist/api/Api.d.ts +1 -1
- package/dist/api/Api.js +2 -9
- package/dist/api/Endpoint.d.ts +1 -1
- package/dist/api/Endpoint.js +2 -2
- package/dist/components/ApiHostProvider.d.ts +7 -0
- package/dist/components/ApiHostProvider.js +35 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/config.d.ts +0 -3
- package/dist/config.js +0 -4
- package/dist/hooks/useApi.js +3 -1
- package/dist/src/api/Api.js +2 -3
- package/dist/src/api/Endpoint.js +2 -2
- package/dist/src/components/ApiHostProvider.js +11 -0
- package/dist/src/components/index.js +1 -0
- package/dist/src/config.js +0 -4
- package/dist/src/hooks/useApi.js +3 -1
- package/package.json +1 -1
package/dist/api/Api.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export default class Api {
|
|
|
23
23
|
host: string;
|
|
24
24
|
namespace: string;
|
|
25
25
|
endpoint: string;
|
|
26
|
-
constructor(endpoint: string);
|
|
26
|
+
constructor(endpoint: string, host: string);
|
|
27
27
|
get<DataType>(opts?: RequestOptions<DataType extends any[] ? DataType[0] : DataType>): Promise<any>;
|
|
28
28
|
post<T, ResponseType>(data?: T, opts?: RequestOptions): Promise<ResponseType>;
|
|
29
29
|
put(id: number, data: RequestData, opts?: RequestOptions): Promise<ApiResponse>;
|
package/dist/api/Api.js
CHANGED
|
@@ -35,11 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var config_1 = __importDefault(require("../config"));
|
|
43
39
|
var utils_1 = require("../utils");
|
|
44
40
|
function handleResponse(res) {
|
|
45
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -68,11 +64,8 @@ function handleResponse(res) {
|
|
|
68
64
|
});
|
|
69
65
|
}
|
|
70
66
|
var Api = /** @class */ (function () {
|
|
71
|
-
function Api(endpoint) {
|
|
72
|
-
this.host =
|
|
73
|
-
(typeof window !== 'undefined' &&
|
|
74
|
-
window.localStorage.getItem('apiHost')) ||
|
|
75
|
-
config_1.default.api.host;
|
|
67
|
+
function Api(endpoint, host) {
|
|
68
|
+
this.host = host;
|
|
76
69
|
this.namespace = '';
|
|
77
70
|
this.endpoint = endpoint;
|
|
78
71
|
}
|
package/dist/api/Endpoint.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ type CallbackFunction<T> = (reason: unknown) => any;
|
|
|
3
3
|
export default class Endpoint<GetResponseElement> extends Api {
|
|
4
4
|
endpoint: string;
|
|
5
5
|
errorCallback?: CallbackFunction<any>;
|
|
6
|
-
constructor(endpoint: string, errorCallback?: (reason: unknown) => ApiResponse<any>);
|
|
6
|
+
constructor(endpoint: string, host?: string, errorCallback?: (reason: unknown) => ApiResponse<any>);
|
|
7
7
|
get<DataType = GetResponseElement>(opts?: RequestOptions<DataType extends any[] ? DataType[0] : DataType>): Promise<DataType extends any[] ? ApiResponse<DataType> : DataType>;
|
|
8
8
|
post<T = RequestData, ResponseType = T>(data?: T, opts?: RequestOptions): Promise<ResponseType>;
|
|
9
9
|
put(id: number, data: RequestData, opts?: RequestOptions): Promise<ApiResponse>;
|
package/dist/api/Endpoint.js
CHANGED
|
@@ -57,8 +57,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
57
57
|
var Api_1 = __importDefault(require("./Api"));
|
|
58
58
|
var Endpoint = /** @class */ (function (_super) {
|
|
59
59
|
__extends(Endpoint, _super);
|
|
60
|
-
function Endpoint(endpoint, errorCallback) {
|
|
61
|
-
var _this = _super.call(this, endpoint) || this;
|
|
60
|
+
function Endpoint(endpoint, host, errorCallback) {
|
|
61
|
+
var _this = _super.call(this, host, endpoint) || this;
|
|
62
62
|
_this.endpoint = endpoint;
|
|
63
63
|
_this.errorCallback = errorCallback;
|
|
64
64
|
return _this;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.useApiHost = exports.ApiHostProvider = void 0;
|
|
27
|
+
var react_1 = __importStar(require("react"));
|
|
28
|
+
var ApiHostContext = (0, react_1.createContext)('/api');
|
|
29
|
+
var ApiHostProvider = function (_a) {
|
|
30
|
+
var children = _a.children, host = _a.host;
|
|
31
|
+
return (react_1.default.createElement(ApiHostContext.Provider, { value: host }, children));
|
|
32
|
+
};
|
|
33
|
+
exports.ApiHostProvider = ApiHostProvider;
|
|
34
|
+
var useApiHost = function () { return (0, react_1.useContext)(ApiHostContext); };
|
|
35
|
+
exports.useApiHost = useApiHost;
|
package/dist/components/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.StatusTag = exports.Table = void 0;
|
|
21
|
+
__exportStar(require("./ApiHostProvider"), exports);
|
|
21
22
|
__exportStar(require("./Table"), exports);
|
|
22
23
|
var Table_1 = require("./Table");
|
|
23
24
|
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return __importDefault(Table_1).default; } });
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var nextHost = process.env.NEXT_PUBLIC_HOST;
|
|
4
3
|
var config = {
|
|
5
|
-
api: {
|
|
6
|
-
host: process.env.API_HOST || nextHost && "".concat(nextHost, "/api") || 'http://localhost:8443',
|
|
7
|
-
},
|
|
8
4
|
ROW_SIZE: 24,
|
|
9
5
|
ROW_SIZE_MOBILE: 48,
|
|
10
6
|
MOBILE_BREAKPOINT: 375,
|
package/dist/hooks/useApi.js
CHANGED
|
@@ -6,14 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
var react_1 = require("react");
|
|
7
7
|
var createApi_1 = require("../api/createApi");
|
|
8
8
|
var Endpoint_1 = __importDefault(require("../api/Endpoint"));
|
|
9
|
+
var components_1 = require("../components");
|
|
9
10
|
function useApi(onUnauthorized) {
|
|
10
11
|
if (onUnauthorized === void 0) { onUnauthorized = function () { }; }
|
|
12
|
+
var host = (0, components_1.useApiHost)();
|
|
11
13
|
var api = (0, react_1.useMemo)(function () {
|
|
12
14
|
return Object.fromEntries(Object.entries((0, createApi_1.createApi)()).map(function (_a) {
|
|
13
15
|
var key = _a[0], endpoint = _a[1].endpoint;
|
|
14
16
|
return [
|
|
15
17
|
key,
|
|
16
|
-
new Endpoint_1.default(endpoint, errorCallback),
|
|
18
|
+
new Endpoint_1.default(endpoint, host, errorCallback),
|
|
17
19
|
];
|
|
18
20
|
}));
|
|
19
21
|
}, []);
|
package/dist/src/api/Api.js
CHANGED
|
@@ -154,7 +154,6 @@ function _ts_generator(thisArg, body) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
import config from '../config';
|
|
158
157
|
import { Query } from '../utils';
|
|
159
158
|
function handleResponse(res) {
|
|
160
159
|
return _handleResponse.apply(this, arguments);
|
|
@@ -195,12 +194,12 @@ function _handleResponse() {
|
|
|
195
194
|
}
|
|
196
195
|
var Api = /*#__PURE__*/ function() {
|
|
197
196
|
"use strict";
|
|
198
|
-
function Api(endpoint) {
|
|
197
|
+
function Api(endpoint, host) {
|
|
199
198
|
_class_call_check(this, Api);
|
|
200
199
|
_define_property(this, "host", void 0);
|
|
201
200
|
_define_property(this, "namespace", void 0);
|
|
202
201
|
_define_property(this, "endpoint", void 0);
|
|
203
|
-
this.host =
|
|
202
|
+
this.host = host;
|
|
204
203
|
this.namespace = '';
|
|
205
204
|
this.endpoint = endpoint;
|
|
206
205
|
}
|
package/dist/src/api/Endpoint.js
CHANGED
|
@@ -248,10 +248,10 @@ var Endpoint = /*#__PURE__*/ function(Api) {
|
|
|
248
248
|
"use strict";
|
|
249
249
|
_inherits(Endpoint, Api);
|
|
250
250
|
var _super = _create_super(Endpoint);
|
|
251
|
-
function Endpoint(endpoint, errorCallback) {
|
|
251
|
+
function Endpoint(endpoint, host, errorCallback) {
|
|
252
252
|
_class_call_check(this, Endpoint);
|
|
253
253
|
var _this;
|
|
254
|
-
_this = _super.call(this, endpoint);
|
|
254
|
+
_this = _super.call(this, host, endpoint);
|
|
255
255
|
_define_property(_assert_this_initialized(_this), "endpoint", void 0);
|
|
256
256
|
_define_property(_assert_this_initialized(_this), "errorCallback", void 0);
|
|
257
257
|
_this.endpoint = endpoint;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
var ApiHostContext = /*#__PURE__*/ createContext('/api');
|
|
3
|
+
export var ApiHostProvider = function(param) {
|
|
4
|
+
var children = param.children, host = param.host;
|
|
5
|
+
return /*#__PURE__*/ React.createElement(ApiHostContext.Provider, {
|
|
6
|
+
value: host
|
|
7
|
+
}, children);
|
|
8
|
+
};
|
|
9
|
+
export var useApiHost = function() {
|
|
10
|
+
return useContext(ApiHostContext);
|
|
11
|
+
};
|
package/dist/src/config.js
CHANGED
package/dist/src/hooks/useApi.js
CHANGED
|
@@ -47,14 +47,16 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
47
47
|
import { useCallback, useMemo } from 'react';
|
|
48
48
|
import { createApi } from '../api/createApi';
|
|
49
49
|
import Endpoint from '../api/Endpoint';
|
|
50
|
+
import { useApiHost } from '../components';
|
|
50
51
|
export default function useApi() {
|
|
51
52
|
var onUnauthorized = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function() {};
|
|
53
|
+
var host = useApiHost();
|
|
52
54
|
var api = useMemo(function() {
|
|
53
55
|
return Object.fromEntries(Object.entries(createApi()).map(function(param) {
|
|
54
56
|
var _param = _sliced_to_array(param, 2), key = _param[0], endpoint = _param[1].endpoint;
|
|
55
57
|
return [
|
|
56
58
|
key,
|
|
57
|
-
new Endpoint(endpoint, errorCallback)
|
|
59
|
+
new Endpoint(endpoint, host, errorCallback)
|
|
58
60
|
];
|
|
59
61
|
}));
|
|
60
62
|
}, []);
|