@gandalan/weblibs 0.0.1 → 0.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/README.md +1 -0
- package/api/IDAS.js +41 -0
- package/api/{api.js → RESTClient.js} +24 -25
- package/package.json +1 -1
- package/api/AuthStore.js +0 -8
- package/api/mandantenApi.js +0 -12
- package/api/nachrichtenApi.js +0 -46
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
WebLibs for Gandalan JS/TS/Svelte projects
|
package/api/IDAS.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { get, writable } from "svelte/store";
|
|
2
|
+
import { RESTClient } from "./RESTClient";
|
|
3
|
+
|
|
4
|
+
export const APP_TOKEN = "66B70E0B-F7C4-4829-B12A-18AD309E3970";
|
|
5
|
+
export const AuthToken = writable(localStorage.getItem("AuthToken"));
|
|
6
|
+
export const MandantGuid = writable(localStorage.getItem("MandantGuid"));
|
|
7
|
+
export const ApiBaseUrl = writable(localStorage.getItem("ApiBaseUrl") || "https://api.dev.idas-cloudservices.net/api");
|
|
8
|
+
export const SiteBaseUrl = writable(window.location.protocol + "//" + window.location.host);
|
|
9
|
+
export const SSOAuthUrl = writable(get(ApiBaseUrl).replace("/api", "") + "/SSO?a=" + APP_TOKEN + "&r=%target%?t=%token%%26m=%mandant%");
|
|
10
|
+
|
|
11
|
+
export class IDAS
|
|
12
|
+
{
|
|
13
|
+
authToken = {};
|
|
14
|
+
api = new RESTClient(get(ApiBaseUrl), get(AuthToken));
|
|
15
|
+
|
|
16
|
+
async authenticate(authDTO) {
|
|
17
|
+
var { data } = await this.api.post("/Login/Authenticate", authDTO);
|
|
18
|
+
this.authToken = data;
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async authenticateWithSSO() {
|
|
23
|
+
var ssoURL = get(SSOAuthUrl).replace("%target%", get(SiteBaseUrl)).replace("%mandant%", get(MandantGuid));
|
|
24
|
+
window.location = ssoURL;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
mandanten = {
|
|
28
|
+
async getAll() { return await this.api.get("/Mandanten"); },
|
|
29
|
+
async save(m) { await this.api.put("/Mandanten", m); }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
benutzer = {
|
|
33
|
+
async getAll() { return await this.api.get("/Benutzer"); },
|
|
34
|
+
async save(m) { await this.api.put("/Benutzer", m); }
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
rollen = {
|
|
38
|
+
async getAll() { return await this.api.get("/Rollen"); },
|
|
39
|
+
async save(m) { await this.api.put("/Rollen", m); }
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { AuthToken, ApiBaseUrl } from "./AuthStore";
|
|
3
|
-
import { get } from 'svelte/store';
|
|
4
2
|
|
|
5
|
-
export
|
|
3
|
+
/*export let AppToken = "66B70E0B-F7C4-4829-B12A-18AD309E3970";
|
|
4
|
+
export let AuthToken = localStorage.getItem("AuthToken");
|
|
5
|
+
export let MandantGuid = localStorage.getItem("MandantGuid");
|
|
6
|
+
export let ApiBaseUrl = localStorage.getItem("ApiBaseUrl") || "https://api.dev.idas-cloudservices.net/api";
|
|
7
|
+
export let SiteBaseUrl = window.location.origin;
|
|
8
|
+
export let SSOAuthUrl = ApiBaseUrl.replace("/api", "") + "/SSO?a=" + AppToken + "&r=%target%?t=%token%%26m=%mandant%";*/
|
|
9
|
+
|
|
10
|
+
export class RESTClient
|
|
6
11
|
{
|
|
7
12
|
lastError = '';
|
|
8
13
|
token = "";
|
|
9
14
|
baseurl = "";
|
|
10
15
|
|
|
11
|
-
constructor()
|
|
16
|
+
constructor(url, token)
|
|
12
17
|
{
|
|
13
18
|
this.lastError = "";
|
|
14
|
-
this.baseurl =
|
|
15
|
-
this.token =
|
|
19
|
+
this.baseurl = url;
|
|
20
|
+
this.token = token;
|
|
16
21
|
console.log("Base: " + this.baseurl + " Token: " + this.token);
|
|
17
22
|
|
|
18
23
|
if (this.token) {
|
|
19
24
|
axios.defaults.headers.common['X-Gdl-AuthToken'] = this.token;
|
|
20
25
|
}
|
|
26
|
+
|
|
27
|
+
axios.interceptors.request.use(req => {
|
|
28
|
+
console.log(`${req.method} ${req.url}`);
|
|
29
|
+
return req;
|
|
30
|
+
});
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
async get(uri)
|
|
24
34
|
{
|
|
25
35
|
try {
|
|
26
|
-
console.log("GET " + this.baseurl + uri);
|
|
27
36
|
const response = await axios.get(this.baseurl + uri);
|
|
28
37
|
this.lastError = '';
|
|
29
38
|
return response.data;
|
|
30
39
|
}
|
|
31
40
|
catch (error) {
|
|
32
|
-
this.
|
|
41
|
+
this.handleError(error);
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
|
|
@@ -37,19 +46,16 @@ export class API
|
|
|
37
46
|
{
|
|
38
47
|
try {
|
|
39
48
|
const response = await axios.get(this.baseurl + uri, { responseType: 'blob' });
|
|
40
|
-
console.log(response);
|
|
41
|
-
|
|
42
49
|
let fileName = "1000.pdf";
|
|
43
50
|
if (response.headers["content-disposition"]) {
|
|
44
51
|
fileName = response.headers["content-disposition"].split(';')[1];
|
|
45
52
|
fileName = fileName.replace("filename=", "").trim();
|
|
46
53
|
}
|
|
47
|
-
|
|
48
54
|
this.lastError = '';
|
|
49
55
|
return { data: response.data, filename: fileName, contentType: "application/pdf" };
|
|
50
56
|
}
|
|
51
57
|
catch (error) {
|
|
52
|
-
this.
|
|
58
|
+
this.handleError(error);
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -58,11 +64,10 @@ export class API
|
|
|
58
64
|
let response = {};
|
|
59
65
|
try {
|
|
60
66
|
response = await axios.get(this.baseurl + uri, { withCredentials: true })
|
|
61
|
-
console.log(response);
|
|
62
67
|
this.lastError = '';
|
|
63
68
|
}
|
|
64
69
|
catch (error) {
|
|
65
|
-
this.
|
|
70
|
+
this.handleError(error);
|
|
66
71
|
}
|
|
67
72
|
return response;
|
|
68
73
|
}
|
|
@@ -71,25 +76,23 @@ export class API
|
|
|
71
76
|
{
|
|
72
77
|
try {
|
|
73
78
|
const response = await axios.post(this.baseurl + uri, formData, { withCredentials: true });
|
|
74
|
-
//console.log(JSON.stringify(response));
|
|
75
79
|
this.lastError = '';
|
|
76
80
|
return response;
|
|
77
81
|
}
|
|
78
82
|
catch (error) {
|
|
79
|
-
this.
|
|
83
|
+
this.handleError(error);
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
async put(uri, formData)
|
|
84
88
|
{
|
|
85
89
|
try {
|
|
86
|
-
console.log(`PUT to ${this.baseurl}${uri}`);
|
|
87
90
|
const response = await axios.put(this.baseurl + uri, formData, { withCredentials: true });
|
|
88
91
|
this.lastError = '';
|
|
89
92
|
return response;
|
|
90
93
|
}
|
|
91
94
|
catch (error) {
|
|
92
|
-
this.
|
|
95
|
+
this.handleError(error);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -97,25 +100,21 @@ export class API
|
|
|
97
100
|
{
|
|
98
101
|
try
|
|
99
102
|
{
|
|
100
|
-
console.log(`DELETE to ${this.baseurl}${uri}`);
|
|
101
103
|
const response = await axios.delete(this.baseurl + uri, { withCredentials: true });
|
|
102
104
|
this.lastError = '';
|
|
103
105
|
return response;
|
|
104
106
|
}
|
|
105
107
|
catch (error) {
|
|
106
|
-
this.
|
|
108
|
+
this.handleError(error);
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
handleError(error)
|
|
111
113
|
{
|
|
112
114
|
let status = error && error.response ? error.response.status : -1;
|
|
113
115
|
let message = error ? error.message : "?";
|
|
114
116
|
console.log("API Error " + status + ": " + message);
|
|
115
117
|
this.lastError = message;
|
|
116
|
-
|
|
117
|
-
AuthToken.set(null);
|
|
118
|
-
localStorage.setItem("AuthToken", null);
|
|
119
|
-
}
|
|
118
|
+
throw error;
|
|
120
119
|
}
|
|
121
120
|
}
|
package/package.json
CHANGED
package/api/AuthStore.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { get, writable } from "svelte/store";
|
|
2
|
-
|
|
3
|
-
export const APP_TOKEN = "66B70E0B-F7C4-4829-B12A-18AD309E3970";
|
|
4
|
-
export const AuthToken = writable(localStorage.getItem("AuthToken"));
|
|
5
|
-
export const MandantGuid = writable(localStorage.getItem("MandantGuid"));
|
|
6
|
-
export const ApiBaseUrl = writable(localStorage.getItem("ApiBaseUrl") || "https://api.dev.idas-cloudservices.net/api");
|
|
7
|
-
export const SiteBaseUrl = writable(window.location.protocol + "//" + window.location.host);
|
|
8
|
-
export const SSOAuthUrl = writable(get(ApiBaseUrl).replace("/api", "") + "/SSO?a=" + APP_TOKEN + "&r=%target%?t=%token%%26m=%mandant%");
|
package/api/mandantenApi.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { API } from './api';
|
|
2
|
-
import { AuthToken } from "./AuthStore";
|
|
3
|
-
//import mandanten from '../data/mandanten.json';
|
|
4
|
-
|
|
5
|
-
export function getAll()
|
|
6
|
-
{
|
|
7
|
-
//return mandanten;
|
|
8
|
-
if (AuthToken)
|
|
9
|
-
return new API().get('/Mandanten');
|
|
10
|
-
else
|
|
11
|
-
return [];
|
|
12
|
-
}
|
package/api/nachrichtenApi.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { API } from './api';
|
|
2
|
-
import { get } from 'svelte/store'
|
|
3
|
-
import { MandantGuid } from "./AuthStore";
|
|
4
|
-
|
|
5
|
-
const niceContextNames = new Map();
|
|
6
|
-
niceContextNames.set("position", "Positionserfassung");
|
|
7
|
-
niceContextNames.set("start", "Programmstart");
|
|
8
|
-
|
|
9
|
-
export async function getAll()
|
|
10
|
-
{
|
|
11
|
-
let api = getNewAPI();
|
|
12
|
-
let result = await api.get('/NachrichtenKonfig?besitzerMandantGuid=' + get(MandantGuid));
|
|
13
|
-
result = result || [];
|
|
14
|
-
result.forEach(n => {
|
|
15
|
-
n.anzeigeText = n.nachricht && n.nachricht.length > 30 ? n.nachricht.substr(0,30) + "..." : n.nachricht;
|
|
16
|
-
if (n.context && niceContextNames.has(n.context))
|
|
17
|
-
{
|
|
18
|
-
n.anzeigeText += " (Anzeige bei " + niceContextNames.get(n.context) + ")";
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function addNachricht(nachricht)
|
|
25
|
-
{
|
|
26
|
-
nachricht.besitzerMandantGuid = get(MandantGuid);
|
|
27
|
-
if (!nachricht.gueltigAb) nachricht.gueltigAb = null;
|
|
28
|
-
if (!nachricht.gueltigBis) nachricht.gueltigBis = null;
|
|
29
|
-
|
|
30
|
-
let api = getNewAPI();
|
|
31
|
-
console.log(nachricht);
|
|
32
|
-
return await api.post('/NachrichtenKonfig', nachricht);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function removeNachricht(nachricht)
|
|
36
|
-
{
|
|
37
|
-
let api = getNewAPI();
|
|
38
|
-
return await api.delete('/NachrichtenKonfig?nachrichtGuid=' + nachricht.nachrichtGuid);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getNewAPI()
|
|
42
|
-
{
|
|
43
|
-
let api = new API();
|
|
44
|
-
api.baseurl = "";
|
|
45
|
-
return api;
|
|
46
|
-
}
|