@ercioko/meblotex-api 0.2.2 → 0.2.4

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 (181) hide show
  1. package/dist/api/Api.d.ts +33 -0
  2. package/dist/api/Api.js +152 -0
  3. package/dist/api/Endpoint.d.ts +13 -0
  4. package/dist/api/Endpoint.js +126 -0
  5. package/dist/api/createApi.d.ts +53 -0
  6. package/dist/api/createApi.js +82 -0
  7. package/dist/api/error.d.ts +15 -0
  8. package/dist/api/error.js +18 -0
  9. package/{src/api/index.ts → dist/api/index.d.ts} +0 -1
  10. package/dist/api/index.js +34 -0
  11. package/dist/api/status.d.ts +3 -0
  12. package/dist/api/status.js +6 -0
  13. package/dist/api/utils/getAlert.d.ts +6 -0
  14. package/dist/api/utils/getAlert.js +65 -0
  15. package/dist/api/utils/index.js +8 -0
  16. package/dist/app_types.d.ts +607 -0
  17. package/dist/app_types.js +75 -0
  18. package/dist/components/ApiHostProvider.d.ts +7 -0
  19. package/dist/components/ApiHostProvider.js +35 -0
  20. package/dist/components/StatusTag.d.ts +11 -0
  21. package/dist/components/StatusTag.js +86 -0
  22. package/dist/components/Table/DataTableWrapper.d.ts +3 -0
  23. package/dist/components/Table/DataTableWrapper.js +44 -0
  24. package/dist/components/Table/FloatingActions.d.ts +14 -0
  25. package/dist/components/Table/FloatingActions.js +32 -0
  26. package/dist/components/Table/Spinner.d.ts +2 -0
  27. package/dist/components/Table/Spinner.js +26 -0
  28. package/dist/components/Table/Table.d.ts +28 -0
  29. package/dist/components/Table/Table.js +330 -0
  30. package/dist/components/Table/addIndexToObject.d.ts +3 -0
  31. package/dist/components/Table/addIndexToObject.js +17 -0
  32. package/dist/components/Table/areProvidedColumnsDifferent.d.ts +2 -0
  33. package/dist/components/Table/areProvidedColumnsDifferent.js +16 -0
  34. package/dist/components/Table/hooks/useFetchPage.d.ts +18 -0
  35. package/dist/components/Table/hooks/useFetchPage.js +123 -0
  36. package/dist/components/Table/hooks/useGetCellRenderer.d.ts +25 -0
  37. package/dist/components/Table/hooks/useGetCellRenderer.js +166 -0
  38. package/dist/components/Table/hooks/useGetColumnsWithCheckbox.d.ts +5 -0
  39. package/dist/components/Table/hooks/useGetColumnsWithCheckbox.js +53 -0
  40. package/dist/components/Table/hooks/useGetDeleteRow.d.ts +9 -0
  41. package/dist/components/Table/hooks/useGetDeleteRow.js +74 -0
  42. package/dist/components/Table/hooks/useGetResizeColumn.d.ts +8 -0
  43. package/dist/components/Table/hooks/useGetResizeColumn.js +28 -0
  44. package/dist/components/Table/hooks/useGetRowCheckbox.d.ts +5 -0
  45. package/dist/components/Table/hooks/useGetRowCheckbox.js +54 -0
  46. package/dist/components/Table/hooks/useLoadDataSource.d.ts +10 -0
  47. package/dist/components/Table/hooks/useLoadDataSource.js +20 -0
  48. package/dist/components/Table/hooks/usePageSize.d.ts +5 -0
  49. package/dist/components/Table/hooks/usePageSize.js +16 -0
  50. package/dist/components/Table/hooks/useRenderRowActions.d.ts +6 -0
  51. package/dist/components/Table/hooks/useRenderRowActions.js +51 -0
  52. package/dist/components/Table/hooks/useResizeColumns.d.ts +9 -0
  53. package/dist/components/Table/hooks/useResizeColumns.js +60 -0
  54. package/dist/components/Table/index.d.ts +1 -0
  55. package/dist/components/Table/index.js +8 -0
  56. package/dist/components/Table/providers/OrderProvider.d.ts +9 -0
  57. package/dist/components/Table/providers/OrderProvider.js +17 -0
  58. package/dist/components/Table/styles.d.ts +6 -0
  59. package/dist/components/Table/styles.js +37 -0
  60. package/dist/components/index.js +26 -0
  61. package/dist/config.d.ts +6 -0
  62. package/dist/config.js +8 -0
  63. package/dist/db_types.d.ts +208 -0
  64. package/dist/db_types.js +2 -0
  65. package/dist/hooks/index.js +10 -0
  66. package/dist/hooks/useApi.d.ts +2 -0
  67. package/dist/hooks/useApi.js +42 -0
  68. package/dist/hooks/useEndpoint.d.ts +2 -0
  69. package/dist/hooks/useEndpoint.js +34 -0
  70. package/dist/index.js +19 -0
  71. package/dist/lib/index.js +18 -0
  72. package/dist/lib/jednostkaNazwa.d.ts +6 -0
  73. package/dist/lib/jednostkaNazwa.js +9 -0
  74. package/dist/lib/typDokumentuNazwa.d.ts +6 -0
  75. package/dist/lib/typDokumentuNazwa.js +11 -0
  76. package/dist/src/api/Api.js +316 -0
  77. package/dist/src/api/Endpoint.js +365 -0
  78. package/dist/src/api/createApi.js +51 -0
  79. package/dist/src/api/error.js +15 -0
  80. package/dist/src/api/index.js +5 -0
  81. package/dist/src/api/status.js +3 -0
  82. package/dist/src/api/utils/getAlert.js +63 -0
  83. package/dist/src/api/utils/index.js +1 -0
  84. package/dist/src/app_types.js +72 -0
  85. package/dist/src/components/ApiHostProvider.js +11 -0
  86. package/dist/src/components/StatusTag.js +153 -0
  87. package/dist/src/components/Table/DataTableWrapper.js +115 -0
  88. package/dist/src/components/Table/FloatingActions.js +60 -0
  89. package/dist/src/components/Table/Spinner.js +40 -0
  90. package/dist/src/components/Table/Summary.js +16 -0
  91. package/dist/src/components/Table/Table.js +498 -0
  92. package/dist/src/components/Table/addIndexToObject.js +57 -0
  93. package/dist/src/components/Table/areProvidedColumnsDifferent.js +19 -0
  94. package/dist/src/components/Table/clicked.js +12 -0
  95. package/dist/src/components/Table/displayActions.js +11 -0
  96. package/dist/src/components/Table/hooks/useFetchPage.js +254 -0
  97. package/dist/src/components/Table/hooks/useGetCellRenderer.js +231 -0
  98. package/dist/src/components/Table/hooks/useGetColumnsWithCheckbox.js +33 -0
  99. package/dist/src/components/Table/hooks/useGetDeleteRow.js +181 -0
  100. package/dist/src/components/Table/hooks/useGetResizeColumn.js +72 -0
  101. package/dist/src/components/Table/hooks/useGetRowCheckbox.js +55 -0
  102. package/dist/src/components/Table/hooks/useLoadDataSource.js +16 -0
  103. package/dist/src/components/Table/hooks/usePageSize.js +15 -0
  104. package/dist/src/components/Table/hooks/useRenderRowActions.js +50 -0
  105. package/dist/src/components/Table/hooks/useResizeColumns.js +70 -0
  106. package/dist/src/components/Table/index.js +1 -0
  107. package/dist/src/components/Table/providers/OrderProvider.js +65 -0
  108. package/dist/src/components/Table/styles.js +66 -0
  109. package/dist/src/components/index.js +4 -0
  110. package/dist/src/config.js +6 -0
  111. package/dist/src/db_types.js +1 -0
  112. package/dist/src/hooks/index.js +2 -0
  113. package/dist/src/hooks/useApi.js +84 -0
  114. package/dist/src/hooks/useEndpoint.js +60 -0
  115. package/dist/src/index.js +3 -0
  116. package/dist/src/lib/index.js +2 -0
  117. package/dist/src/lib/jednostkaNazwa.js +6 -0
  118. package/dist/src/lib/typDokumentuNazwa.js +16 -0
  119. package/dist/src/utils/Query.js +73 -0
  120. package/dist/src/utils/getWZNumber.js +4 -0
  121. package/dist/src/utils/getZamowienieDokumentNumber.js +4 -0
  122. package/{src/utils/index.ts → dist/src/utils/index.js} +2 -2
  123. package/dist/utils/Query.d.ts +6 -0
  124. package/dist/utils/Query.js +33 -0
  125. package/dist/utils/getWZNumber.d.ts +2 -0
  126. package/dist/utils/getWZNumber.js +10 -0
  127. package/dist/utils/getZamowienieDokumentNumber.d.ts +2 -0
  128. package/dist/utils/getZamowienieDokumentNumber.js +8 -0
  129. package/dist/utils/index.d.ts +3 -0
  130. package/dist/utils/index.js +12 -0
  131. package/package.json +3 -2
  132. package/.eslintrc +0 -6
  133. package/.nvmrc +0 -1
  134. package/.prettierrc +0 -11
  135. package/src/api/Api.ts +0 -140
  136. package/src/api/Endpoint.ts +0 -76
  137. package/src/api/createApi.ts +0 -116
  138. package/src/api/error.ts +0 -17
  139. package/src/api/status.ts +0 -3
  140. package/src/api/utils/getAlert.ts +0 -75
  141. package/src/app_types.ts +0 -695
  142. package/src/components/ApiHostProvider.tsx +0 -13
  143. package/src/components/StatusTag.tsx +0 -83
  144. package/src/components/Table/DataTableWrapper.tsx +0 -28
  145. package/src/components/Table/FloatingActions.tsx +0 -152
  146. package/src/components/Table/Spinner.tsx +0 -35
  147. package/src/components/Table/Summary.tsx +0 -18
  148. package/src/components/Table/Table.tsx +0 -474
  149. package/src/components/Table/addIndexToObject.ts +0 -6
  150. package/src/components/Table/areProvidedColumnsDifferent.ts +0 -26
  151. package/src/components/Table/clicked.js +0 -12
  152. package/src/components/Table/displayActions.tsx +0 -19
  153. package/src/components/Table/hooks/useFetchPage.tsx +0 -83
  154. package/src/components/Table/hooks/useGetCellRenderer.tsx +0 -197
  155. package/src/components/Table/hooks/useGetColumnsWithCheckbox.tsx +0 -34
  156. package/src/components/Table/hooks/useGetDeleteRow.tsx +0 -37
  157. package/src/components/Table/hooks/useGetResizeColumn.ts +0 -33
  158. package/src/components/Table/hooks/useGetRowCheckbox.tsx +0 -25
  159. package/src/components/Table/hooks/useLoadDataSource.ts +0 -24
  160. package/src/components/Table/hooks/usePageSize.tsx +0 -20
  161. package/src/components/Table/hooks/useRenderRowActions.tsx +0 -45
  162. package/src/components/Table/hooks/useResizeColumns.ts +0 -61
  163. package/src/components/Table/index.ts +0 -1
  164. package/src/components/Table/providers/OrderProvider.tsx +0 -20
  165. package/src/components/Table/styles.ts +0 -208
  166. package/src/config.ts +0 -7
  167. package/src/db_types.ts +0 -220
  168. package/src/hooks/useApi.ts +0 -43
  169. package/src/hooks/useEndpoint.ts +0 -35
  170. package/src/lib/jednostkaNazwa.ts +0 -6
  171. package/src/lib/typDokumentuNazwa.ts +0 -8
  172. package/src/utils/Query.ts +0 -30
  173. package/src/utils/getWZNumber.ts +0 -13
  174. package/src/utils/getZamowienieDokumentNumber.ts +0 -11
  175. package/tsconfig.json +0 -25
  176. package/tsconfig.tsbuildinfo +0 -1
  177. /package/{src/api/utils/index.ts → dist/api/utils/index.d.ts} +0 -0
  178. /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
  179. /package/{src/hooks/index.ts → dist/hooks/index.d.ts} +0 -0
  180. /package/{src/index.ts → dist/index.d.ts} +0 -0
  181. /package/{src/lib/index.ts → dist/lib/index.d.ts} +0 -0
@@ -0,0 +1,73 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ function encode(data) {
48
+ return data ? Object.entries(data).filter(function(param) {
49
+ var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
50
+ return k !== undefined && v !== undefined;
51
+ }).map(function(param) {
52
+ var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
53
+ return (Array.isArray(v) ? v : [
54
+ v
55
+ ]).map(function(e) {
56
+ return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(e));
57
+ }).join('&');
58
+ }).join('&') : '';
59
+ }
60
+ var Query = {
61
+ decode: function(query) {
62
+ if (!query) return {};
63
+ var q = {};
64
+ var pairs = query.replace(/\?/g, '').split('&');
65
+ pairs.forEach(function(pair) {
66
+ var p = pair.split('=');
67
+ q[decodeURIComponent(p[0])] = decodeURIComponent(p[1] || '');
68
+ });
69
+ return q;
70
+ },
71
+ encode: encode
72
+ };
73
+ export default Query;
@@ -0,0 +1,4 @@
1
+ export var getWZNumber = function(param) {
2
+ var numer = param.numer, numer_idx = param.numer_idx;
3
+ return "WZ ".concat(numer_idx.toString().slice(0, 4), "/").concat(numer_idx.toString().slice(4), "/").concat(numer.toString().padStart(4, '0'), "/M");
4
+ };
@@ -0,0 +1,4 @@
1
+ export var getZamowienieDokumentNumber = function(row) {
2
+ var _row_numer_idx, _row_numer_idx1, _row_numer;
3
+ return "".concat(row === null || row === void 0 ? void 0 : row.typ_dokumentu, "/").concat(row === null || row === void 0 ? void 0 : (_row_numer_idx = row.numer_idx) === null || _row_numer_idx === void 0 ? void 0 : _row_numer_idx.toString().slice(0, 4), "/").concat(row === null || row === void 0 ? void 0 : (_row_numer_idx1 = row.numer_idx) === null || _row_numer_idx1 === void 0 ? void 0 : _row_numer_idx1.toString().slice(4), "/").concat(row === null || row === void 0 ? void 0 : (_row_numer = row.numer) === null || _row_numer === void 0 ? void 0 : _row_numer.toString().padStart(4, '0'), "/M");
4
+ };
@@ -1,3 +1,3 @@
1
1
  export { default as Query } from "./Query";
2
- export { getZamowienieDokumentNumber } from './getZamowienieDokumentNumber'
3
- export { getWZNumber } from './getWZNumber'
2
+ export { getZamowienieDokumentNumber } from './getZamowienieDokumentNumber';
3
+ export { getWZNumber } from './getWZNumber';
@@ -0,0 +1,6 @@
1
+ declare function encode<T = Record<string, unknown>>(data: T): string;
2
+ declare const Query: {
3
+ decode: (query: string) => Record<string, unknown>;
4
+ encode: typeof encode;
5
+ };
6
+ export default Query;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function encode(data) {
4
+ return data
5
+ ? Object.entries(data)
6
+ .filter(function (_a) {
7
+ var k = _a[0], v = _a[1];
8
+ return k !== undefined && v !== undefined;
9
+ })
10
+ .map(function (_a) {
11
+ var k = _a[0], v = _a[1];
12
+ return (Array.isArray(v) ? v : [v])
13
+ .map(function (e) { return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(e)); })
14
+ .join('&');
15
+ })
16
+ .join('&')
17
+ : '';
18
+ }
19
+ var Query = {
20
+ decode: function (query) {
21
+ if (!query)
22
+ return {};
23
+ var q = {};
24
+ var pairs = query.replace(/\?/g, '').split('&');
25
+ pairs.forEach(function (pair) {
26
+ var p = pair.split('=');
27
+ q[decodeURIComponent(p[0])] = decodeURIComponent(p[1] || '');
28
+ });
29
+ return q;
30
+ },
31
+ encode: encode,
32
+ };
33
+ exports.default = Query;
@@ -0,0 +1,2 @@
1
+ import { ZamowienieDokumentMagazynAttributes } from '../db_types';
2
+ export declare const getWZNumber: ({ numer, numer_idx, }: Pick<ZamowienieDokumentMagazynAttributes, "numer_idx" | "numer">) => string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWZNumber = void 0;
4
+ var getWZNumber = function (_a) {
5
+ var numer = _a.numer, numer_idx = _a.numer_idx;
6
+ return "WZ ".concat(numer_idx.toString().slice(0, 4), "/").concat(numer_idx
7
+ .toString()
8
+ .slice(4), "/").concat(numer.toString().padStart(4, '0'), "/M");
9
+ };
10
+ exports.getWZNumber = getWZNumber;
@@ -0,0 +1,2 @@
1
+ import { ZamowienieDokument } from '../app_types';
2
+ export declare const getZamowienieDokumentNumber: (row: Pick<ZamowienieDokument, "typ_dokumentu" | "numer_idx" | "numer">) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getZamowienieDokumentNumber = void 0;
4
+ var getZamowienieDokumentNumber = function (row) {
5
+ var _a, _b, _c;
6
+ return "".concat(row === null || row === void 0 ? void 0 : row.typ_dokumentu, "/").concat((_a = row === null || row === void 0 ? void 0 : row.numer_idx) === null || _a === void 0 ? void 0 : _a.toString().slice(0, 4), "/").concat((_b = row === null || row === void 0 ? void 0 : row.numer_idx) === null || _b === void 0 ? void 0 : _b.toString().slice(4), "/").concat((_c = row === null || row === void 0 ? void 0 : row.numer) === null || _c === void 0 ? void 0 : _c.toString().padStart(4, '0'), "/M");
7
+ };
8
+ exports.getZamowienieDokumentNumber = getZamowienieDokumentNumber;
@@ -0,0 +1,3 @@
1
+ export { default as Query } from "./Query";
2
+ export { getZamowienieDokumentNumber } from './getZamowienieDokumentNumber';
3
+ export { getWZNumber } from './getWZNumber';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getWZNumber = exports.getZamowienieDokumentNumber = exports.Query = void 0;
7
+ var Query_1 = require("./Query");
8
+ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return __importDefault(Query_1).default; } });
9
+ var getZamowienieDokumentNumber_1 = require("./getZamowienieDokumentNumber");
10
+ Object.defineProperty(exports, "getZamowienieDokumentNumber", { enumerable: true, get: function () { return getZamowienieDokumentNumber_1.getZamowienieDokumentNumber; } });
11
+ var getWZNumber_1 = require("./getWZNumber");
12
+ Object.defineProperty(exports, "getWZNumber", { enumerable: true, get: function () { return getWZNumber_1.getWZNumber; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercioko/meblotex-api",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Shared modules for Meblotex app",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "url": "https://github.com/erykdziedzic/meblotex-api/issues"
24
24
  },
25
25
  "homepage": "https://github.com/erykdziedzic/meblotex-api#readme",
26
+ "files": ["./dist"],
26
27
  "peerDependencies": {
27
28
  "react": "^18.3.1",
28
29
  "react-dom": "^18.3.1",
@@ -45,5 +46,5 @@
45
46
  "prettier": "^3.3.3",
46
47
  "typescript": "^5.5.4"
47
48
  },
48
- "keywords": [ ]
49
+ "keywords": []
49
50
  }
package/.eslintrc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": [
3
- "eslint:recommended",
4
- "prettier"
5
- ]
6
- }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- v20.11.1
package/.prettierrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "singleQuote": true,
3
- "trailingComma": "es5",
4
- "semi": true,
5
- "tabWidth": 2,
6
- "bracketSpacing": true,
7
- "jsxBracketSameLine": false,
8
- "proseWrap": "never",
9
- "printWidth": 80,
10
- "arrowParens": "always"
11
- }
package/src/api/Api.ts DELETED
@@ -1,140 +0,0 @@
1
- import config from '../config';
2
- import { DataRow, Order } from '../app_types';
3
- import { Query } from '../utils';
4
- import { createApi } from './createApi';
5
-
6
- async function handleResponse(res: Response) {
7
- if (res.status === 204) return {};
8
- if (res.status.toString().startsWith('2')) return res.json();
9
-
10
- const { ok, url, headers, status, statusText } = res;
11
- const text = await res.text();
12
- throw new Error(
13
- JSON.stringify({
14
- ok,
15
- url,
16
- headers,
17
- status,
18
- statusText,
19
- text,
20
- })
21
- );
22
- }
23
-
24
- type QueryType<T> = {
25
- page?: number;
26
- records?: number;
27
- fields?: (keyof T)[];
28
- order?: Order[];
29
- } & Record<string, unknown>;
30
-
31
- export type RequestOptions<T> = {
32
- token?: string;
33
- id?: number | string;
34
- noId?: boolean;
35
- query?: QueryType<T>;
36
- };
37
-
38
- export type RequestData = Record<string, unknown>;
39
-
40
- export type ApiResponse<RowType = DataRow> = {
41
- [key in keyof ReturnType<typeof createApi>]: RowType;
42
- } & {
43
- total: number;
44
- };
45
-
46
- export default class Api {
47
- host: string;
48
-
49
- namespace: string;
50
-
51
- endpoint: string;
52
-
53
- private endpointUrl: string;
54
-
55
- constructor(endpoint: string, host?: string) {
56
- this.host = host;
57
- this.namespace = '';
58
- this.endpoint = endpoint;
59
- this.endpointUrl = `${this.host}${this.namespace}/${this.endpoint}`;
60
- }
61
-
62
- async get<DataType>(
63
- opts: RequestOptions<DataType extends any[] ? DataType[0] : DataType> = {}
64
- ): Promise<any> {
65
- const headers = new Headers();
66
- if (opts.token) headers.append('Authorization', `Bearer ${opts.token}`);
67
-
68
- const options: { credentials: RequestCredentials; headers: Headers } = {
69
- credentials: 'include',
70
- headers,
71
- };
72
-
73
- const url = `${this.endpointUrl}/${opts.id || ''}${this.getQuery(
74
- opts.query
75
- )}`;
76
-
77
- return fetch(url, options).then(handleResponse);
78
- }
79
-
80
- async post<T, ResponseType>(
81
- data?: T,
82
- opts: RequestOptions<T> = {}
83
- ): Promise<ResponseType> {
84
- const headers = new Headers();
85
- const body = JSON.stringify(data);
86
- headers.append('Content-Type', 'application/json');
87
- if (opts.token) headers.append('Authorization', `Bearer ${opts.token}`);
88
-
89
- const url = `${this.endpointUrl}${this.getQuery(opts.query)}`;
90
-
91
- return fetch(url, {
92
- method: 'POST',
93
- body,
94
- headers,
95
- credentials: 'include',
96
- }).then(handleResponse);
97
- }
98
-
99
- async put(
100
- id: number,
101
- data: RequestData,
102
- opts: RequestOptions<{}> = {}
103
- ): Promise<ApiResponse> {
104
- const body = JSON.stringify(data);
105
- const headers = new Headers();
106
- headers.append('Content-Type', 'application/json');
107
- if (opts.token) headers.append('Authorization', `Bearer ${opts.token}`);
108
-
109
- const url = `${this.endpointUrl}${opts.noId ? '' : '/'}${
110
- id || ''
111
- }${this.getQuery(opts.query)}`;
112
-
113
- return fetch(url, {
114
- method: 'PUT',
115
- body,
116
- headers,
117
- credentials: 'include',
118
- }).then(handleResponse);
119
- }
120
-
121
- async delete(
122
- id: number,
123
- opts: RequestOptions<{}> = {}
124
- ): Promise<ApiResponse> {
125
- const headers = new Headers();
126
- if (opts.token) headers.append('Authorization', `Bearer ${opts.token}`);
127
-
128
- const url = `${this.endpointUrl}/${id}${this.getQuery(opts.query)}`;
129
-
130
- return fetch(url, {
131
- headers,
132
- method: 'DELETE',
133
- credentials: 'include',
134
- }).then(handleResponse);
135
- }
136
-
137
- private getQuery<T>(query?: QueryType<T>) {
138
- return query ? `?${new URLSearchParams(Query.encode(query)).toString()}` : '';
139
- }
140
- }
@@ -1,76 +0,0 @@
1
- /* eslint-disable prefer-reflect */
2
- import { DataRow } from '../app_types';
3
- import Api, { ApiResponse, RequestData, RequestOptions } from './Api';
4
-
5
- type CallbackFunction<T> = (reason: unknown) => any;
6
-
7
- export default class Endpoint<GetResponseElement> extends Api {
8
- endpoint: string;
9
-
10
- errorCallback?: CallbackFunction<any>;
11
-
12
- constructor(
13
- endpoint: string,
14
- host: string = '',
15
- errorCallback?: (reason: unknown) => ApiResponse<any>
16
- ) {
17
- super(endpoint, host);
18
- this.endpoint = endpoint;
19
- this.errorCallback = errorCallback;
20
- }
21
-
22
- async get<DataType = GetResponseElement>(
23
- opts?: RequestOptions<DataType extends any[] ? DataType[0] : DataType>
24
- ): Promise<DataType extends any[] ? ApiResponse<DataType> : DataType> {
25
- return super.get<DataType>(opts).catch(this.errorCallback);
26
- }
27
-
28
- async post<T = RequestData, ResponseType = T>(
29
- data?: T,
30
- opts?: RequestOptions<T>
31
- ): Promise<ResponseType> {
32
- return super.post<T, ResponseType>(data, opts);
33
- }
34
-
35
- async put(
36
- id: number,
37
- data: RequestData,
38
- opts?: RequestOptions<{}>
39
- ): Promise<ApiResponse> {
40
- return super.put(id, data, opts);
41
- }
42
-
43
- async delete(id: number, opts?: RequestOptions<{}>): Promise<ApiResponse> {
44
- return super.delete(id, opts);
45
- }
46
-
47
- toJSON(proto: Record<string, unknown>): Record<string, unknown> {
48
- const jsoned: Record<string, unknown> = {};
49
- const toConvert = proto || this;
50
- Object.getOwnPropertyNames(toConvert).forEach((prop) => {
51
- const val = toConvert[prop];
52
- // don't include those
53
- if (prop === 'toJSON' || prop === 'constructor') {
54
- return;
55
- }
56
- if (typeof val === 'function') {
57
- jsoned[prop] = val.bind(jsoned);
58
- return;
59
- }
60
- jsoned[prop] = val;
61
- });
62
-
63
- const inherited = Object.getPrototypeOf(toConvert);
64
- if (inherited !== null) {
65
- Object.keys(this.toJSON(inherited)).forEach((key) => {
66
- if (!!jsoned[key] || key === 'constructor' || key === 'toJSON') return;
67
- if (typeof inherited[key] === 'function') {
68
- jsoned[key] = inherited[key].bind(jsoned);
69
- return;
70
- }
71
- jsoned[key] = inherited[key];
72
- });
73
- }
74
- return jsoned;
75
- }
76
- }
@@ -1,116 +0,0 @@
1
- import {
2
- Bufor,
3
- BuforInfoResponse,
4
- Klient,
5
- KlientKategoria,
6
- KlientRabat,
7
- KlientZamowienie,
8
- LoginResponse,
9
- NoweZamowienieAtrybutKonfigResponse,
10
- RownanieZmienna,
11
- RownanieZmiennaKategoria,
12
- Wplata,
13
- WplataZamowienieDokument,
14
- ZaliczkaZamowienieDokument,
15
- Zamowienie,
16
- ZamowienieInfoResponse,
17
- ZamowienieNowyDokumentElement,
18
- ZamowienieNowyDokumentRequest,
19
- } from '../app_types';
20
- import {
21
- ZamowienieDokumentAttributes,
22
- ZamowienieDokumentElementAttributes,
23
- ZamowienieDokumentMagazynAttributes,
24
- } from '../db_types';
25
- import Endpoint from './Endpoint';
26
- import * as error from './error';
27
- import * as hooks from '../hooks';
28
- import * as status from './status';
29
- import * as utils from './utils';
30
-
31
- export { status, error, utils, hooks };
32
-
33
- export const createApi = (host: string) => ({
34
- atrybut_konfig: new Endpoint('atrybut_konfig', host),
35
- bufor: new Endpoint<Bufor>('bufor', host),
36
- bufor_element: new Endpoint('bufor_element', host),
37
- bufor_element_atrybut: new Endpoint('bufor_element_atrybut', host),
38
- buforinfo: new Endpoint<BuforInfoResponse>('buforinfo', host),
39
- cecha_wartosc: new Endpoint('cecha_wartosc', host),
40
- get_set_param_number: new Endpoint('get_set_param_number', host),
41
- klient: new Endpoint<Klient>('klient', host),
42
- klient_kategoria: new Endpoint<KlientKategoria>('klient_kategoria', host),
43
- klient_rabat: new Endpoint<KlientRabat[]>('klient_rabat', host),
44
- klient_zamowienie: new Endpoint<KlientZamowienie>('klient_zamowienie', host),
45
- login: new Endpoint<LoginResponse>('auth/login', host),
46
- logout: new Endpoint('auth/logout', host),
47
- web_login: new Endpoint('web_auth/login', host),
48
- web_logout: new Endpoint('web_auth/logout', host),
49
- nowe_zamowienie_cecha_wartosc: new Endpoint(
50
- 'nowe_zamowienie/cecha_wartosc',
51
- host
52
- ),
53
- nowe_zamowienie_towar: new Endpoint('nowe_zamowienie/towar', host),
54
- nowe_zamowienie_towar_atrybut: new Endpoint(
55
- 'nowe_zamowienie/towar_atrybut',
56
- host
57
- ),
58
- nowe_zamowienie_towar_atrybut2: new Endpoint(
59
- 'nowe_zamowienie/towar_atrybut2',
60
- host
61
- ),
62
- nowe_zamowienie_towar_kategoria: new Endpoint(
63
- 'nowe_zamowienie/towar_kategoria',
64
- host
65
- ),
66
- nowe_zamowienie_towar_cecha_wartosc_pre: new Endpoint(
67
- 'nowe_zamowienie/towar_cecha_wartosc_pre',
68
- host
69
- ),
70
- nowe_zamowienie_atrybut_konfig: new Endpoint<{
71
- atrybut_konfig: NoweZamowienieAtrybutKonfigResponse[];
72
- }>('nowe_zamowienie/atrybut_konfig', host),
73
- rownanie: new Endpoint('rownanie', host),
74
- rownanie_zmienna: new Endpoint<RownanieZmienna>('rownanie_zmienna', host),
75
- rownanie_zmienna_kategoria: new Endpoint<RownanieZmiennaKategoria>(
76
- 'rownanie_zmienna_kategoria',
77
- host
78
- ),
79
- rownanie_js: new Endpoint('rownanie/js', host),
80
- towar: new Endpoint('towar', host),
81
- towar_atrybut: new Endpoint('towar_atrybut', host),
82
- towar_kategoria: new Endpoint('towar_kategoria', host),
83
- towar_cecha_wartosc_pre: new Endpoint('towar_cecha_wartosc_pre', host),
84
- wplata: new Endpoint<Wplata>('wplata', host),
85
- wplata_zamowienie_dokument: new Endpoint<WplataZamowienieDokument[]>(
86
- 'wplata_zamowienie_dokument',
87
- host
88
- ),
89
- zamowienie: new Endpoint<Zamowienie>('zamowienie', host),
90
- zamowienie_dokument: new Endpoint<ZamowienieDokumentAttributes>(
91
- 'zamowienie_dokument',
92
- host
93
- ),
94
- zamowienieinfo: new Endpoint<ZamowienieInfoResponse>('zamowienieinfo', host),
95
- zaliczka_zamowienie_dokument: new Endpoint<ZaliczkaZamowienieDokument[]>(
96
- 'zaliczka_zamowienie_dokument',
97
- host
98
- ),
99
- zamowienie_nowy_dokument_element: new Endpoint<
100
- ZamowienieNowyDokumentElement[]
101
- >('zamowienie_nowy_dokument_element', host),
102
- zamowienie_nowy_dokument: new Endpoint<ZamowienieNowyDokumentRequest>(
103
- 'zamowienie_nowy_dokument',
104
- host
105
- ),
106
- zamowienie_dokument_element:
107
- new Endpoint<ZamowienieDokumentElementAttributes>(
108
- 'zamowienie_dokument_element',
109
- host
110
- ),
111
- zamowienie_dokument_magazyn:
112
- new Endpoint<ZamowienieDokumentMagazynAttributes>(
113
- 'zamowienie_dokument_magazyn',
114
- host
115
- ),
116
- });
package/src/api/error.ts DELETED
@@ -1,17 +0,0 @@
1
- export const NOT_FOUND = 'not_found';
2
- export const INVALID_DATA = 'invalid_data';
3
- export const INVALID_REQUEST = 'invalid_request';
4
- export const UNAUTHORIZED = 'unauthorized';
5
- export const ALREADY_EXISTS = 'already_exists';
6
-
7
- export const FAILED_TO_FETCH = 'Failed to fetch';
8
-
9
- export const field = {
10
- NEW_PASSWORD: 'new_password',
11
- OLD_PASSWORD: 'old_password',
12
- EMAIL: 'email',
13
- LAST_NAME: 'surname',
14
- FIRST_NAME: 'name',
15
- COMPANY: 'company_name',
16
- PHONE: 'phone_number',
17
- };
package/src/api/status.ts DELETED
@@ -1,3 +0,0 @@
1
- export const OK = 'ok';
2
- export const INVALID_PASSWORD = 'invalid_password';
3
- export const ALREADY_LOGGED_IN = 'already_logged_in';
@@ -1,75 +0,0 @@
1
- import {
2
- FAILED_TO_FETCH,
3
- INVALID_DATA,
4
- INVALID_REQUEST,
5
- UNAUTHORIZED,
6
- field,
7
- } from "../error";
8
- import { ALREADY_LOGGED_IN, INVALID_PASSWORD, OK } from "../status";
9
-
10
- const severity = {
11
- SUCCESS: "success",
12
- ERROR: "error",
13
- WARNING: "warning",
14
- INFO: "info",
15
- };
16
-
17
- type Alert = {
18
- severity: string;
19
- message: string;
20
- };
21
-
22
- const createAlert = (severity: string, message: string): Alert => ({
23
- severity,
24
- message,
25
- });
26
-
27
- export default function getAlert(status: string): Alert {
28
- try {
29
- const error = JSON.parse(status);
30
- switch (error.error) {
31
- case INVALID_DATA:
32
- switch (error.field) {
33
- case field.EMAIL:
34
- return createAlert(severity.ERROR, "Błędny email");
35
- case field.FIRST_NAME:
36
- return createAlert(severity.ERROR, "Błędne imię");
37
- case field.LAST_NAME:
38
- return createAlert(severity.ERROR, "Błędne nazwisko");
39
- case field.PHONE:
40
- return createAlert(severity.ERROR, "Błędny numer telefonu");
41
- case field.COMPANY:
42
- return createAlert(severity.ERROR, "Błędna nazwa firmy");
43
- default:
44
- return createAlert(severity.ERROR, error.error);
45
- }
46
- default:
47
- return createAlert(severity.ERROR, error.error);
48
- }
49
- } catch (e) {
50
- switch (status) {
51
- case OK:
52
- return createAlert(severity.SUCCESS, "Sukces!");
53
- case INVALID_PASSWORD:
54
- return createAlert(severity.ERROR, "Błędne hasło lub email!");
55
- case ALREADY_LOGGED_IN:
56
- return createAlert(severity.ERROR, "Jesteś już zalogowany!");
57
- case FAILED_TO_FETCH:
58
- return createAlert(severity.ERROR, "Wystąpił błąd!");
59
- case INVALID_REQUEST:
60
- return createAlert(severity.ERROR, "Błąd zapytania!");
61
- case UNAUTHORIZED:
62
- return createAlert(severity.ERROR, "Błąd autoryzacji!");
63
- case field.NEW_PASSWORD:
64
- return createAlert(severity.ERROR, "Nowe hasło jest zbyt słabe!");
65
- case field.OLD_PASSWORD:
66
- return createAlert(severity.ERROR, "Stare hasło jest nieprawidłowe!");
67
- case "name_empty":
68
- return createAlert(severity.ERROR, "Nazwa jest pusta!");
69
- case "name_taken":
70
- return createAlert(severity.ERROR, "Nazwa jest zajęta!");
71
- default:
72
- return createAlert(severity.ERROR, status);
73
- }
74
- }
75
- }