@webmate-studio/cli 0.3.61 → 0.4.0

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/src/utils/auth.js DELETED
@@ -1,125 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync } from 'fs';
2
- import { join, dirname } from 'path';
3
- import { homedir } from 'os';
4
-
5
- /**
6
- * Auth Helper für CLI
7
- * Speichert Login-Credentials in ~/.webmate/auth.json
8
- */
9
-
10
- const AUTH_DIR = join(homedir(), '.webmate');
11
- const AUTH_FILE = join(AUTH_DIR, 'auth.json');
12
-
13
- /**
14
- * Lädt gespeicherte Auth-Daten
15
- */
16
- export function loadAuth() {
17
- if (!existsSync(AUTH_FILE)) {
18
- return null;
19
- }
20
-
21
- try {
22
- const content = readFileSync(AUTH_FILE, 'utf8');
23
- if (!content || content.trim() === '') {
24
- // Empty file - remove it
25
- try {
26
- unlinkSync(AUTH_FILE);
27
- } catch (e) {
28
- // Ignore cleanup errors
29
- }
30
- return null;
31
- }
32
- return JSON.parse(content);
33
- } catch (error) {
34
- // Corrupted auth file - remove it
35
- try {
36
- unlinkSync(AUTH_FILE);
37
- } catch (e) {
38
- // Ignore cleanup errors
39
- }
40
- return null;
41
- }
42
- }
43
-
44
- /**
45
- * Speichert Auth-Daten
46
- */
47
- export function saveAuth(authData) {
48
- if (!existsSync(AUTH_DIR)) {
49
- mkdirSync(AUTH_DIR, { recursive: true });
50
- }
51
-
52
- writeFileSync(AUTH_FILE, JSON.stringify(authData, null, 2), 'utf8');
53
- }
54
-
55
- /**
56
- * Löscht gespeicherte Auth-Daten
57
- */
58
- export function clearAuth() {
59
- if (existsSync(AUTH_FILE)) {
60
- writeFileSync(AUTH_FILE, '', 'utf8');
61
- }
62
- }
63
-
64
- /**
65
- * Prüft ob User eingeloggt ist
66
- */
67
- export function isLoggedIn() {
68
- const auth = loadAuth();
69
- return auth && auth.user && auth.apiToken;
70
- }
71
-
72
- /**
73
- * Gibt aktuellen User zurück
74
- */
75
- export function getCurrentUser() {
76
- const auth = loadAuth();
77
- return auth?.user || null;
78
- }
79
-
80
- /**
81
- * Gibt API Token zurück
82
- */
83
- export function getApiToken() {
84
- const auth = loadAuth();
85
- return auth?.apiToken || null;
86
- }
87
-
88
- /**
89
- * Gibt aktuellen Tenant zurück
90
- */
91
- export function getCurrentTenant() {
92
- const auth = loadAuth();
93
- return auth?.tenant || null;
94
- }
95
-
96
- /**
97
- * Gibt CMS Base URL zurück
98
- */
99
- export function getCmsBaseUrl() {
100
- const auth = loadAuth();
101
- if (!auth?.baseUrl) {
102
- return 'https://app.webmate-studio.com'; // Default für Production
103
- }
104
- return auth.baseUrl;
105
- }
106
-
107
- /**
108
- * Gibt Tenant CMS URL zurück
109
- */
110
- export function getTenantCmsUrl() {
111
- const tenant = getCurrentTenant();
112
- const baseUrl = getCmsBaseUrl();
113
-
114
- if (!tenant) {
115
- return null;
116
- }
117
-
118
- // Extrahiere Domain aus Base URL (z.B. "app.webmate-studio.com" → "webmate-studio.com")
119
- const url = new URL(baseUrl);
120
- const parts = url.host.split('.');
121
- const domain = parts.slice(1).join('.'); // Entferne "app" Subdomain
122
-
123
- // Baue Tenant CMS URL
124
- return `${url.protocol}//${tenant.subdomain}.cms.${domain}`;
125
- }