@gandalan/weblibs 1.5.17 → 1.5.18
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 +106 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,35 +1,124 @@
|
|
|
1
1
|
# WebLibs for Gandalan JS/TS projects
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Deutsch
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Zweck
|
|
6
|
+
`@gandalan/weblibs` stellt Hilfsfunktionen für die Authentifizierung und API-Kommunikation mit IDAS sowie lokale API-Aufrufe bereit.
|
|
6
7
|
|
|
8
|
+
### Referenz
|
|
9
|
+
- IDAS API (Swagger): https://api.dev.idas-cloudservices.net/swagger/
|
|
10
|
+
|
|
11
|
+
### Voraussetzungen
|
|
12
|
+
- Browser-Umgebung (es werden `window`, `localStorage`, URL-Redirects und `fetch` verwendet)
|
|
13
|
+
- Gültiger App-Token als UUID (wird auf Anfrage von Gandalan ausgegeben)
|
|
14
|
+
- Kontakt für Zugangsdaten/App-Token: dev-support@gandalan.de
|
|
15
|
+
- IDAS/Auth-Base-URL vorzugsweise aus `fetchEnvConfig(...)` (z. B. `envConfig.idas`)
|
|
16
|
+
- Falls die URL manuell gesetzt wird: mit abschließendem Slash (z. B. `https://api.dev.idas-cloudservices.net/api/`)
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
```bash
|
|
20
|
+
npm i @gandalan/weblibs
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Schnellstart (Fluent API + Auth)
|
|
7
24
|
```js
|
|
8
25
|
import { fetchEnvConfig, fluentApi, fluentIdasAuthManager } from '@gandalan/weblibs';
|
|
9
26
|
|
|
10
27
|
async function initializeAuthAndApi() {
|
|
11
|
-
const serviceName = 'myService'
|
|
12
|
-
const appToken = '
|
|
13
|
-
const envConfig = await fetchEnvConfig('dev'); //
|
|
28
|
+
const serviceName = 'myService';
|
|
29
|
+
const appToken = '00000000-0000-0000-0000-000000000000'; // UUID
|
|
30
|
+
const envConfig = await fetchEnvConfig('dev'); // envConfig.idas kommt aus fetchEnvConfig(...)
|
|
14
31
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
32
|
+
let authManager;
|
|
33
|
+
try {
|
|
34
|
+
authManager = await fluentIdasAuthManager(appToken, envConfig.idas).init();
|
|
35
|
+
} catch {
|
|
36
|
+
// init() kann auf Login umleiten und dabei eine Exception werfen.
|
|
37
|
+
// In diesem Fall Seite verlassen / später erneut starten.
|
|
38
|
+
return;
|
|
18
39
|
}
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
const idas = fluentApi(envConfig.idas, authManager, serviceName);
|
|
42
|
+
const api = fluentApi('/api/', authManager, serviceName);
|
|
43
|
+
|
|
44
|
+
const mandanten = await idas.get('mandanten');
|
|
45
|
+
console.log(mandanten[0]?.Name);
|
|
46
|
+
|
|
47
|
+
const localResult = await api.get('some-endpoint');
|
|
48
|
+
console.log(localResult);
|
|
22
49
|
}
|
|
23
50
|
```
|
|
24
51
|
|
|
25
|
-
|
|
52
|
+
### Exportierte APIs (Kurzüberblick)
|
|
53
|
+
- `fetchEnvConfig(env)` lädt Endpunktkonfiguration (z. B. `dev`, `staging`, `produktiv`)
|
|
54
|
+
- `fluentIdasAuthManager(appToken, authBaseUrl)` erzeugt Auth-Manager
|
|
55
|
+
- `fluentApi(baseUrl, authManager, serviceName)` erzeugt API-Client mit `get/put/post/delete`
|
|
56
|
+
- `createAuthManager()`, `createApi()`, `restClient()` für manuelle Konfiguration
|
|
57
|
+
- Legacy zusätzlich vorhanden: `initIDAS`, `IDASFactory`, `RESTClient`
|
|
58
|
+
|
|
59
|
+
### Wichtige Hinweise
|
|
60
|
+
- `init()` gibt nicht immer nur `null` zurück, sondern kann beim Redirect eine Exception auslösen.
|
|
61
|
+
- Refresh-Token wird aus URL-Parameter `t` gelesen und in `localStorage` (`idas-refresh-token`) persistiert.
|
|
62
|
+
- Ohne gültigen Auth-Status werden Requests ggf. intern per `ensureAuthenticated()` nachgezogen.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## English
|
|
67
|
+
|
|
68
|
+
### Purpose
|
|
69
|
+
`@gandalan/weblibs` provides helpers for authentication and API communication with IDAS as well as local API calls.
|
|
70
|
+
|
|
71
|
+
### Reference
|
|
72
|
+
- IDAS API (Swagger): https://api.dev.idas-cloudservices.net/swagger/
|
|
73
|
+
|
|
74
|
+
### Requirements
|
|
75
|
+
- Browser environment (uses `window`, `localStorage`, URL redirects, and `fetch`)
|
|
76
|
+
- Valid app token in UUID format (issued by Gandalan on request)
|
|
77
|
+
- Contact for credentials/app token: dev-support@gandalan.de
|
|
78
|
+
- Prefer the IDAS/auth base URL from `fetchEnvConfig(...)` (for example `envConfig.idas`)
|
|
79
|
+
- If the URL is set manually, use a trailing slash (for example `https://api.dev.idas-cloudservices.net/api/`)
|
|
26
80
|
|
|
81
|
+
### Installation
|
|
82
|
+
```bash
|
|
83
|
+
npm i @gandalan/weblibs
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Quick start (Fluent API + auth)
|
|
27
87
|
```js
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
88
|
+
import { fetchEnvConfig, fluentApi, fluentIdasAuthManager } from '@gandalan/weblibs';
|
|
89
|
+
|
|
90
|
+
async function initializeAuthAndApi() {
|
|
91
|
+
const serviceName = 'myService';
|
|
92
|
+
const appToken = '00000000-0000-0000-0000-000000000000'; // UUID
|
|
93
|
+
const envConfig = await fetchEnvConfig('dev'); // envConfig.idas is provided by fetchEnvConfig(...)
|
|
94
|
+
|
|
95
|
+
let authManager;
|
|
96
|
+
try {
|
|
97
|
+
authManager = await fluentIdasAuthManager(appToken, envConfig.idas).init();
|
|
98
|
+
} catch {
|
|
99
|
+
// init() may redirect to login and throw while doing so.
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const idas = fluentApi(envConfig.idas, authManager, serviceName);
|
|
104
|
+
const api = fluentApi('/api/', authManager, serviceName);
|
|
105
|
+
|
|
106
|
+
const mandanten = await idas.get('mandanten');
|
|
107
|
+
console.log(mandanten[0]?.Name);
|
|
31
108
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
109
|
+
const localResult = await api.get('some-endpoint');
|
|
110
|
+
console.log(localResult);
|
|
111
|
+
}
|
|
35
112
|
```
|
|
113
|
+
|
|
114
|
+
### Exported APIs (short overview)
|
|
115
|
+
- `fetchEnvConfig(env)` loads endpoint configuration (for example `dev`, `staging`, `produktiv`)
|
|
116
|
+
- `fluentIdasAuthManager(appToken, authBaseUrl)` creates an auth manager
|
|
117
|
+
- `fluentApi(baseUrl, authManager, serviceName)` creates an API client with `get/put/post/delete`
|
|
118
|
+
- `createAuthManager()`, `createApi()`, `restClient()` for manual composition
|
|
119
|
+
- Legacy exports still available: `initIDAS`, `IDASFactory`, `RESTClient`
|
|
120
|
+
|
|
121
|
+
### Important notes
|
|
122
|
+
- `init()` does not only return `null`; it may throw during login redirect.
|
|
123
|
+
- Refresh token can be read from URL parameter `t` and is stored in `localStorage` (`idas-refresh-token`).
|
|
124
|
+
- Without valid auth state, requests may trigger `ensureAuthenticated()` internally.
|