@gandalan/weblibs 0.0.6 → 0.0.10
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 +41 -0
- package/api/IDAS.js +34 -7
- package/api/RESTClient.js +10 -8
- package/api/index.js +4 -0
- package/components/Dialog.svelte +20 -0
- package/components/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
1
|
WebLibs for Gandalan JS/TS/Svelte projects
|
|
2
|
+
|
|
3
|
+
## IDAS API mit JavaScript/TypeScript verwenden
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
import { IDAS } from '@gandalan/weblibs/api/IDAS';
|
|
8
|
+
let idas = new IDAS();
|
|
9
|
+
|
|
10
|
+
// bei Bedarf wird der Client zur Anmeldung umgeleitet, danach wird die aktuelle Seite wieder aufgerufen
|
|
11
|
+
idas.authenticateWithSSO();
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Danach z.B. Zugriff auf die Mandant-Guid:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
let mandantGuid = idas.mandantGuid;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Datenzugriffe erfolgen über die Objekte innerhalb der IDAS-Klasse
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
let loader = Promise.all([
|
|
24
|
+
idas.mandanten.getAll()
|
|
25
|
+
.then(d => mandanten = d.sort((a,b) => a.Name.localeCompare(b.Name)))
|
|
26
|
+
.catch(e => error = e),
|
|
27
|
+
idas.rollen.getAll()
|
|
28
|
+
.then(d => rollen = d.sort((a,b) => a.Name.localeCompare(b.Name)))
|
|
29
|
+
.catch(e => error = e)
|
|
30
|
+
])
|
|
31
|
+
.then(_ => setMandant(mandantGuid));
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
der hier eingeführte `loader` kann mit dem `{#await}`-Svelte-Konstrukt verwendet werden:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
{#await loader}
|
|
38
|
+
<progress />
|
|
39
|
+
{:then}
|
|
40
|
+
...
|
|
41
|
+
{/await}
|
|
42
|
+
```
|
package/api/IDAS.js
CHANGED
|
@@ -1,39 +1,66 @@
|
|
|
1
|
-
import { get, writable } from "svelte/store";
|
|
2
1
|
import { RESTClient } from "./RESTClient";
|
|
3
2
|
|
|
3
|
+
if (window.location.search) {
|
|
4
|
+
var urlParams = new URLSearchParams(location.search);
|
|
5
|
+
if (urlParams.has("t"))
|
|
6
|
+
localStorage.setItem("IDAS_AuthToken", urlParams.get("t"));
|
|
7
|
+
if (urlParams.has("m"))
|
|
8
|
+
localStorage.setItem("IDAS_MandantGuid", urlParams.get("m"));
|
|
9
|
+
if (urlParams.has("a"))
|
|
10
|
+
localStorage.setItem("IDAS_ApiBaseUrl", urlParams.get("a"));
|
|
11
|
+
window.location = window.location.origin;
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
let appToken = localStorage.getItem("IDAS_AppToken") || "66B70E0B-F7C4-4829-B12A-18AD309E3970";
|
|
5
15
|
let authToken = localStorage.getItem("IDAS_AuthToken");
|
|
6
|
-
let mandantGuid = localStorage.getItem("IDAS_MandantGuid");
|
|
16
|
+
//let mandantGuid = localStorage.getItem("IDAS_MandantGuid");
|
|
7
17
|
let apiBaseUrl = localStorage.getItem("IDAS_ApiBaseUrl") || "https://api.dev.idas-cloudservices.net/api";
|
|
8
|
-
let siteBaseUrl = localStorage.
|
|
9
|
-
let ssoAuthUrl = apiBaseUrl.replace(
|
|
18
|
+
//let siteBaseUrl = localStorage.getItem("SiteBaseUrl") || window.location.protocol + "//" + window.location.host;
|
|
19
|
+
let ssoAuthUrl = apiBaseUrl.replace(/\/api$/, "") + "/SSO?a=" + appToken + "&r=%target%?t=%token%%26m=%mandant%";
|
|
10
20
|
let restClient = new RESTClient(apiBaseUrl, authToken);
|
|
21
|
+
restClient.onError = (error, message) => {
|
|
22
|
+
if (message.indexOf("401") || message.indexOf("403"))
|
|
23
|
+
{
|
|
24
|
+
//console.log(message+" would remove Token");
|
|
25
|
+
localStorage.removeItem("IDAS_AuthToken");
|
|
26
|
+
var ssoURL = ssoAuthUrl.replace("%target%", window.location.origin);
|
|
27
|
+
window.location = ssoURL;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
|
|
12
31
|
export class IDAS
|
|
13
32
|
{
|
|
14
33
|
async authenticate(authDTO) {
|
|
15
34
|
authDTO.AppToken = appToken;
|
|
16
35
|
var { data } = await restClient.post("/Login/Authenticate", authDTO);
|
|
36
|
+
console.log(data);
|
|
17
37
|
if (data?.Token)
|
|
18
38
|
{
|
|
19
39
|
authToken = data.Token;
|
|
40
|
+
localStorage.setItem("IDAS_AuthToken", authToken);
|
|
20
41
|
restClient = new RESTClient(apiBaseUrl, authToken);
|
|
21
42
|
}
|
|
22
43
|
return data;
|
|
23
44
|
}
|
|
24
45
|
|
|
25
46
|
async authenticateWithSSO() {
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
if (!authToken)
|
|
48
|
+
{
|
|
49
|
+
var ssoURL = ssoAuthUrl.replace("%target%", window.location.origin);
|
|
50
|
+
window.location = ssoURL;
|
|
51
|
+
}
|
|
28
52
|
}
|
|
29
53
|
|
|
54
|
+
mandantGuid = localStorage.getItem("IDAS_MandantGuid");
|
|
55
|
+
|
|
30
56
|
mandanten = {
|
|
31
57
|
async getAll() { return await restClient.get("/Mandanten"); },
|
|
58
|
+
async get(guid) { return await restClient.get("/Mandanten/" + guid); },
|
|
32
59
|
async save(m) { await restClient.put("/Mandanten", m); }
|
|
33
60
|
};
|
|
34
61
|
|
|
35
62
|
benutzer = {
|
|
36
|
-
async getAll() { return await restClient.get("/BenutzerListe"); },
|
|
63
|
+
async getAll(mandantGuid) { return await restClient.get("/BenutzerListe/" + mandantGuid + "/?mitRollenUndRechten=true"); },
|
|
37
64
|
async get(guid) { return await restClient.get("/Benutzer/" + guid); },
|
|
38
65
|
async save(m) { await restClient.put("/Benutzer", m); }
|
|
39
66
|
};
|
package/api/RESTClient.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import axios from
|
|
1
|
+
import axios from "axios";
|
|
2
2
|
|
|
3
3
|
/*export let AppToken = "66B70E0B-F7C4-4829-B12A-18AD309E3970";
|
|
4
4
|
export let AuthToken = localStorage.getItem("AuthToken");
|
|
@@ -33,7 +33,7 @@ export class RESTClient
|
|
|
33
33
|
async get(uri)
|
|
34
34
|
{
|
|
35
35
|
try {
|
|
36
|
-
const response = await axios.get(this.baseurl + uri);
|
|
36
|
+
const response = await axios.get(this.baseurl + uri, { withCredentials: false });
|
|
37
37
|
this.lastError = '';
|
|
38
38
|
return response.data;
|
|
39
39
|
}
|
|
@@ -63,7 +63,7 @@ export class RESTClient
|
|
|
63
63
|
{
|
|
64
64
|
let response = {};
|
|
65
65
|
try {
|
|
66
|
-
response = await axios.get(this.baseurl + uri, { withCredentials:
|
|
66
|
+
response = await axios.get(this.baseurl + uri, { withCredentials: false })
|
|
67
67
|
this.lastError = '';
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
@@ -75,7 +75,7 @@ export class RESTClient
|
|
|
75
75
|
async post(uri, formData)
|
|
76
76
|
{
|
|
77
77
|
try {
|
|
78
|
-
const response = await axios.post(this.baseurl + uri, formData, { withCredentials:
|
|
78
|
+
const response = await axios.post(this.baseurl + uri, formData, { withCredentials: false });
|
|
79
79
|
this.lastError = '';
|
|
80
80
|
return response;
|
|
81
81
|
}
|
|
@@ -87,7 +87,7 @@ export class RESTClient
|
|
|
87
87
|
async put(uri, formData)
|
|
88
88
|
{
|
|
89
89
|
try {
|
|
90
|
-
const response = await axios.put(this.baseurl + uri, formData, { withCredentials:
|
|
90
|
+
const response = await axios.put(this.baseurl + uri, formData, { withCredentials: false });
|
|
91
91
|
this.lastError = '';
|
|
92
92
|
return response;
|
|
93
93
|
}
|
|
@@ -100,7 +100,7 @@ export class RESTClient
|
|
|
100
100
|
{
|
|
101
101
|
try
|
|
102
102
|
{
|
|
103
|
-
const response = await axios.delete(this.baseurl + uri, { withCredentials:
|
|
103
|
+
const response = await axios.delete(this.baseurl + uri, { withCredentials: false });
|
|
104
104
|
this.lastError = '';
|
|
105
105
|
return response;
|
|
106
106
|
}
|
|
@@ -109,12 +109,14 @@ export class RESTClient
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
onError = (error, message) => {};
|
|
113
|
+
|
|
112
114
|
handleError(error)
|
|
113
115
|
{
|
|
114
|
-
let status = error && error.response ? error.response.status : -1;
|
|
115
116
|
let message = error ? error.message : "?";
|
|
116
|
-
console.log("API Error
|
|
117
|
+
console.log("API Error: " + message);
|
|
117
118
|
this.lastError = message;
|
|
119
|
+
this.onError(error, message);
|
|
118
120
|
throw error;
|
|
119
121
|
}
|
|
120
122
|
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let isOpen = false;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
{#if isOpen}
|
|
6
|
+
<div class="z-10 absolute w-screen h-screen bg-black left-0 top-0 bg-opacity-50">
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<div class="z-10 absolute left-[20vw] top-[10vw] w-[60vw] shadow-xl shadow-slate-700 bg-white p-8">
|
|
10
|
+
<div>
|
|
11
|
+
<h3 class="text-lg font-bold mb-2"><slot name="title"/></h3>
|
|
12
|
+
</div>
|
|
13
|
+
<div>
|
|
14
|
+
<slot />
|
|
15
|
+
</div>
|
|
16
|
+
<div class="mt-8">
|
|
17
|
+
<button class="float-right bg-gray-600 text-white p-4" on:click={() => isOpen = false}>Schließen</button>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
{/if}
|
package/components/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import AddButton from './AddButton.svelte';
|
|
2
2
|
import DataGrid from './DataGrid.svelte';
|
|
3
|
+
import Dialog from './Datepicker.svelte';
|
|
3
4
|
import Datepicker from './Datepicker.svelte';
|
|
4
5
|
import Inputbox from './Inputbox.svelte';
|
|
5
6
|
import RemoveButton from './RemoveButton.svelte';
|
|
6
7
|
import SaveButton from './SaveButton.svelte';
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
|
-
DataGrid, Datepicker, Inputbox,
|
|
10
|
+
DataGrid, Datepicker, Inputbox, Dialog,
|
|
10
11
|
AddButton, RemoveButton, SaveButton
|
|
11
12
|
}
|