@ercioko/meblotex-api 0.2.0 → 0.2.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.
- package/.eslintrc +6 -0
- package/.nvmrc +1 -0
- package/.prettierrc +11 -0
- package/package.json +5 -16
- package/src/api/Api.ts +140 -0
- package/src/api/Endpoint.ts +76 -0
- package/src/api/createApi.ts +116 -0
- package/src/api/error.ts +17 -0
- package/{dist/api/index.d.ts → src/api/index.ts} +1 -0
- package/src/api/status.ts +3 -0
- package/src/api/utils/getAlert.ts +75 -0
- package/src/app_types.ts +695 -0
- package/src/components/ApiHostProvider.tsx +13 -0
- package/src/components/StatusTag.tsx +83 -0
- package/src/components/Table/DataTableWrapper.tsx +28 -0
- package/src/components/Table/FloatingActions.tsx +152 -0
- package/src/components/Table/Spinner.tsx +35 -0
- package/src/components/Table/Summary.tsx +18 -0
- package/src/components/Table/Table.tsx +474 -0
- package/src/components/Table/addIndexToObject.ts +6 -0
- package/src/components/Table/areProvidedColumnsDifferent.ts +26 -0
- package/src/components/Table/clicked.js +12 -0
- package/src/components/Table/displayActions.tsx +19 -0
- package/src/components/Table/hooks/useFetchPage.tsx +83 -0
- package/src/components/Table/hooks/useGetCellRenderer.tsx +197 -0
- package/src/components/Table/hooks/useGetColumnsWithCheckbox.tsx +34 -0
- package/src/components/Table/hooks/useGetDeleteRow.tsx +37 -0
- package/src/components/Table/hooks/useGetResizeColumn.ts +33 -0
- package/src/components/Table/hooks/useGetRowCheckbox.tsx +25 -0
- package/src/components/Table/hooks/useLoadDataSource.ts +24 -0
- package/src/components/Table/hooks/usePageSize.tsx +20 -0
- package/src/components/Table/hooks/useRenderRowActions.tsx +45 -0
- package/src/components/Table/hooks/useResizeColumns.ts +61 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/Table/providers/OrderProvider.tsx +20 -0
- package/src/components/Table/styles.ts +208 -0
- package/src/config.ts +7 -0
- package/src/db_types.ts +220 -0
- package/src/hooks/useApi.ts +43 -0
- package/src/hooks/useEndpoint.ts +35 -0
- package/src/lib/jednostkaNazwa.ts +6 -0
- package/src/lib/typDokumentuNazwa.ts +8 -0
- package/src/utils/Query.ts +30 -0
- package/src/utils/getWZNumber.ts +13 -0
- package/src/utils/getZamowienieDokumentNumber.ts +11 -0
- package/{dist/src/utils/index.js → src/utils/index.ts} +2 -2
- package/tsconfig.json +25 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/api/Api.d.ts +0 -33
- package/dist/api/Api.js +0 -152
- package/dist/api/Endpoint.d.ts +0 -13
- package/dist/api/Endpoint.js +0 -126
- package/dist/api/createApi.d.ts +0 -52
- package/dist/api/createApi.js +0 -81
- package/dist/api/error.d.ts +0 -15
- package/dist/api/error.js +0 -18
- package/dist/api/index.js +0 -34
- package/dist/api/status.d.ts +0 -3
- package/dist/api/status.js +0 -6
- package/dist/api/utils/getAlert.d.ts +0 -6
- package/dist/api/utils/getAlert.js +0 -65
- package/dist/api/utils/index.js +0 -8
- package/dist/app_types.d.ts +0 -607
- package/dist/app_types.js +0 -75
- package/dist/components/ApiHostProvider.d.ts +0 -7
- package/dist/components/ApiHostProvider.js +0 -35
- package/dist/components/StatusTag.d.ts +0 -11
- package/dist/components/StatusTag.js +0 -86
- package/dist/components/Table/DataTableWrapper.d.ts +0 -3
- package/dist/components/Table/DataTableWrapper.js +0 -44
- package/dist/components/Table/FloatingActions.d.ts +0 -14
- package/dist/components/Table/FloatingActions.js +0 -32
- package/dist/components/Table/Spinner.d.ts +0 -2
- package/dist/components/Table/Spinner.js +0 -26
- package/dist/components/Table/Summary.js +0 -16
- package/dist/components/Table/Table.d.ts +0 -28
- package/dist/components/Table/Table.js +0 -330
- package/dist/components/Table/addIndexToObject.d.ts +0 -3
- package/dist/components/Table/addIndexToObject.js +0 -17
- package/dist/components/Table/areProvidedColumnsDifferent.d.ts +0 -2
- package/dist/components/Table/areProvidedColumnsDifferent.js +0 -16
- package/dist/components/Table/clicked.js +0 -11
- package/dist/components/Table/displayActions.js +0 -11
- package/dist/components/Table/hooks/useFetchPage.d.ts +0 -18
- package/dist/components/Table/hooks/useFetchPage.js +0 -123
- package/dist/components/Table/hooks/useGetCellRenderer.d.ts +0 -25
- package/dist/components/Table/hooks/useGetCellRenderer.js +0 -166
- package/dist/components/Table/hooks/useGetColumnsWithCheckbox.d.ts +0 -5
- package/dist/components/Table/hooks/useGetColumnsWithCheckbox.js +0 -53
- package/dist/components/Table/hooks/useGetDeleteRow.d.ts +0 -9
- package/dist/components/Table/hooks/useGetDeleteRow.js +0 -74
- package/dist/components/Table/hooks/useGetResizeColumn.d.ts +0 -8
- package/dist/components/Table/hooks/useGetResizeColumn.js +0 -28
- package/dist/components/Table/hooks/useGetRowCheckbox.d.ts +0 -5
- package/dist/components/Table/hooks/useGetRowCheckbox.js +0 -54
- package/dist/components/Table/hooks/useLoadDataSource.d.ts +0 -10
- package/dist/components/Table/hooks/useLoadDataSource.js +0 -20
- package/dist/components/Table/hooks/usePageSize.d.ts +0 -5
- package/dist/components/Table/hooks/usePageSize.js +0 -16
- package/dist/components/Table/hooks/useRenderRowActions.d.ts +0 -6
- package/dist/components/Table/hooks/useRenderRowActions.js +0 -51
- package/dist/components/Table/hooks/useResizeColumns.d.ts +0 -9
- package/dist/components/Table/hooks/useResizeColumns.js +0 -60
- package/dist/components/Table/index.d.ts +0 -1
- package/dist/components/Table/index.js +0 -8
- package/dist/components/Table/providers/OrderProvider.d.ts +0 -9
- package/dist/components/Table/providers/OrderProvider.js +0 -17
- package/dist/components/Table/styles.d.ts +0 -6
- package/dist/components/Table/styles.js +0 -37
- package/dist/components/index.js +0 -26
- package/dist/config.d.ts +0 -6
- package/dist/config.js +0 -8
- package/dist/db_types.d.ts +0 -208
- package/dist/db_types.js +0 -2
- package/dist/hooks/index.js +0 -10
- package/dist/hooks/useApi.d.ts +0 -2
- package/dist/hooks/useApi.js +0 -42
- package/dist/hooks/useEndpoint.d.ts +0 -2
- package/dist/hooks/useEndpoint.js +0 -34
- package/dist/index.js +0 -19
- package/dist/lib/index.js +0 -18
- package/dist/lib/jednostka.d.ts +0 -6
- package/dist/lib/jednostkaNazwa.d.ts +0 -6
- package/dist/lib/jednostkaNazwa.js +0 -9
- package/dist/lib/typDokumentuNazwa.d.ts +0 -6
- package/dist/lib/typDokumentuNazwa.js +0 -11
- package/dist/lib/typ_dokument.d.ts +0 -0
- package/dist/lib/typ_dokumentu.d.ts +0 -6
- package/dist/lib/unit.d.ts +0 -0
- package/dist/src/api/Api.js +0 -316
- package/dist/src/api/Endpoint.js +0 -365
- package/dist/src/api/createApi.js +0 -50
- package/dist/src/api/error.js +0 -15
- package/dist/src/api/index.js +0 -5
- package/dist/src/api/status.js +0 -3
- package/dist/src/api/utils/getAlert.js +0 -63
- package/dist/src/api/utils/index.js +0 -1
- package/dist/src/app_types.js +0 -72
- package/dist/src/components/ApiHostProvider.js +0 -11
- package/dist/src/components/StatusTag.js +0 -153
- package/dist/src/components/Table/DataTableWrapper.js +0 -115
- package/dist/src/components/Table/FloatingActions.js +0 -60
- package/dist/src/components/Table/Spinner.js +0 -40
- package/dist/src/components/Table/Summary.js +0 -16
- package/dist/src/components/Table/Table.js +0 -498
- package/dist/src/components/Table/addIndexToObject.js +0 -57
- package/dist/src/components/Table/areProvidedColumnsDifferent.js +0 -19
- package/dist/src/components/Table/clicked.js +0 -12
- package/dist/src/components/Table/displayActions.js +0 -11
- package/dist/src/components/Table/hooks/useFetchPage.js +0 -254
- package/dist/src/components/Table/hooks/useGetCellRenderer.js +0 -231
- package/dist/src/components/Table/hooks/useGetColumnsWithCheckbox.js +0 -33
- package/dist/src/components/Table/hooks/useGetDeleteRow.js +0 -181
- package/dist/src/components/Table/hooks/useGetResizeColumn.js +0 -72
- package/dist/src/components/Table/hooks/useGetRowCheckbox.js +0 -55
- package/dist/src/components/Table/hooks/useLoadDataSource.js +0 -16
- package/dist/src/components/Table/hooks/usePageSize.js +0 -15
- package/dist/src/components/Table/hooks/useRenderRowActions.js +0 -50
- package/dist/src/components/Table/hooks/useResizeColumns.js +0 -70
- package/dist/src/components/Table/index.js +0 -1
- package/dist/src/components/Table/providers/OrderProvider.js +0 -65
- package/dist/src/components/Table/styles.js +0 -66
- package/dist/src/components/index.js +0 -4
- package/dist/src/config.js +0 -6
- package/dist/src/db_types.js +0 -1
- package/dist/src/hooks/index.js +0 -2
- package/dist/src/hooks/useApi.js +0 -84
- package/dist/src/hooks/useEndpoint.js +0 -60
- package/dist/src/index.js +0 -3
- package/dist/src/lib/index.js +0 -2
- package/dist/src/lib/jednostkaNazwa.js +0 -6
- package/dist/src/lib/typDokumentuNazwa.js +0 -16
- package/dist/src/utils/Query.js +0 -73
- package/dist/src/utils/getWZNumber.js +0 -4
- package/dist/src/utils/getZamowienieDokumentNumber.js +0 -4
- package/dist/utils/AlertContext.d.ts +0 -3
- package/dist/utils/AlertContext.js +0 -3
- package/dist/utils/Query.d.ts +0 -6
- package/dist/utils/Query.js +0 -33
- package/dist/utils/geNumber.d.ts +0 -2
- package/dist/utils/getDocNumber.d.ts +0 -2
- package/dist/utils/getWZNumber.js +0 -10
- package/dist/utils/getWzNumber.d.ts +0 -2
- package/dist/utils/getZamowienieDokumentNumber copy.d.ts +0 -2
- package/dist/utils/getZamowienieDokumentNumber.d.ts +0 -2
- package/dist/utils/getZamowienieDokumentNumber.js +0 -8
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -12
- /package/{dist/api/utils/index.d.ts → src/api/utils/index.ts} +0 -0
- /package/{dist/components/index.d.ts → src/components/index.ts} +0 -0
- /package/{dist/hooks/index.d.ts → src/hooks/index.ts} +0 -0
- /package/{dist/index.d.ts → src/index.ts} +0 -0
- /package/{dist/lib/index.d.ts → src/lib/index.ts} +0 -0
package/.eslintrc
ADDED
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v20.11.1
|
package/.prettierrc
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ercioko/meblotex-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Shared modules for Meblotex app",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -23,9 +23,6 @@
|
|
|
23
23
|
"url": "https://github.com/erykdziedzic/meblotex-api/issues"
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/erykdziedzic/meblotex-api#readme",
|
|
26
|
-
"files": [
|
|
27
|
-
"./dist"
|
|
28
|
-
],
|
|
29
26
|
"peerDependencies": {
|
|
30
27
|
"react": "^18.3.1",
|
|
31
28
|
"react-dom": "^18.3.1",
|
|
@@ -43,18 +40,10 @@
|
|
|
43
40
|
"@swc/core": "^1.7.3",
|
|
44
41
|
"@types/react": "^18.3.3",
|
|
45
42
|
"@types/styled-components": "^5.1.34",
|
|
46
|
-
"
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"eslint-config-prettier": "^9.1.0",
|
|
43
|
+
"eslint": "^8.57.0",
|
|
44
|
+
"eslint-config-prettier": "^8.10.0",
|
|
49
45
|
"prettier": "^3.3.3",
|
|
50
|
-
"
|
|
51
|
-
"ts-loader": "^9.5.1",
|
|
52
|
-
"typescript": "^5.5.4",
|
|
53
|
-
"webpack-cli": "^5.1.4"
|
|
46
|
+
"typescript": "^5.5.4"
|
|
54
47
|
},
|
|
55
|
-
"
|
|
56
|
-
"keywords": [
|
|
57
|
-
"meblotex",
|
|
58
|
-
"design-system"
|
|
59
|
-
]
|
|
48
|
+
"keywords": [ ]
|
|
60
49
|
}
|
package/src/api/Api.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
}
|