@coolms/core-angular 2.0.0-alpha.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/CHANGELOG.md +274 -0
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/fesm2022/coolms-core-angular.mjs +2497 -0
- package/fesm2022/coolms-core-angular.mjs.map +1 -0
- package/package.json +54 -0
- package/types/coolms-core-angular.d.ts +2373 -0
|
@@ -0,0 +1,2497 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, Injectable, InjectionToken, Injector, computed, effect, inject, input, makeEnvironmentProviders, provideAppInitializer, signal, untracked } from "@angular/core";
|
|
3
|
+
import { HttpClient, HttpContext, HttpContextToken, HttpErrorResponse, HttpParams } from "@angular/common/http";
|
|
4
|
+
import { Action, Actions, Selector, State, Store, ofActionDispatched, provideStore } from "@ngxs/store";
|
|
5
|
+
import { ReplaySubject, Subject, catchError, debounceTime, defer, filter, finalize, firstValueFrom, from, fromEvent, map, merge, of, shareReplay, switchMap, take, tap, throwError } from "rxjs";
|
|
6
|
+
import { __decorate } from "tslib";
|
|
7
|
+
import { catchError as catchError$1, map as map$1, shareReplay as shareReplay$1, switchMap as switchMap$1, tap as tap$1 } from "rxjs/operators";
|
|
8
|
+
import { DOCUMENT, Location, NgIf } from "@angular/common";
|
|
9
|
+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
10
|
+
import { ActivatedRoute, Router } from "@angular/router";
|
|
11
|
+
import * as i1 from "@angular/forms";
|
|
12
|
+
import { FormsModule } from "@angular/forms";
|
|
13
|
+
function resolvePattern(pattern, params) {
|
|
14
|
+
return Object.entries(params).reduce((url, [key, value]) => url.replace(`{${key}}`, encodeURIComponent(value)), pattern);
|
|
15
|
+
}
|
|
16
|
+
const AUTH_AUDIENCE = new InjectionToken("coolms.auth.audience", {
|
|
17
|
+
providedIn: "root",
|
|
18
|
+
factory: () => null
|
|
19
|
+
});
|
|
20
|
+
var SetAppConfig = class {
|
|
21
|
+
config;
|
|
22
|
+
static type = "[AppConfig] Set";
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.config = config;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
let AppConfigState = class AppConfigState {
|
|
28
|
+
set(ctx, { config }) {
|
|
29
|
+
ctx.setState({
|
|
30
|
+
config,
|
|
31
|
+
loaded: true
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
static config(state) {
|
|
35
|
+
return state.config;
|
|
36
|
+
}
|
|
37
|
+
static manifest(state) {
|
|
38
|
+
return state.config?.manifest ?? null;
|
|
39
|
+
}
|
|
40
|
+
static viewers(state) {
|
|
41
|
+
return state.config?.manifest.viewers ?? null;
|
|
42
|
+
}
|
|
43
|
+
static loaded(state) {
|
|
44
|
+
return state.loaded;
|
|
45
|
+
}
|
|
46
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
47
|
+
minVersion: "12.0.0",
|
|
48
|
+
version: "22.2.3",
|
|
49
|
+
ngImport: i0,
|
|
50
|
+
type: AppConfigState,
|
|
51
|
+
deps: [],
|
|
52
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
53
|
+
});
|
|
54
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
55
|
+
minVersion: "12.0.0",
|
|
56
|
+
version: "22.2.3",
|
|
57
|
+
ngImport: i0,
|
|
58
|
+
type: AppConfigState
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
__decorate([Action(SetAppConfig)], AppConfigState.prototype, "set", null);
|
|
62
|
+
__decorate([Selector()], AppConfigState, "config", null);
|
|
63
|
+
__decorate([Selector()], AppConfigState, "manifest", null);
|
|
64
|
+
__decorate([Selector()], AppConfigState, "viewers", null);
|
|
65
|
+
__decorate([Selector()], AppConfigState, "loaded", null);
|
|
66
|
+
AppConfigState = __decorate([State({
|
|
67
|
+
name: "appConfig",
|
|
68
|
+
defaults: {
|
|
69
|
+
config: null,
|
|
70
|
+
loaded: false
|
|
71
|
+
}
|
|
72
|
+
})], AppConfigState);
|
|
73
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
74
|
+
minVersion: "12.0.0",
|
|
75
|
+
version: "22.2.3",
|
|
76
|
+
ngImport: i0,
|
|
77
|
+
type: AppConfigState,
|
|
78
|
+
decorators: [{ type: Injectable }],
|
|
79
|
+
propDecorators: { set: [] }
|
|
80
|
+
});
|
|
81
|
+
var IdentityApiClient = class IdentityApiClient {
|
|
82
|
+
http = inject(HttpClient);
|
|
83
|
+
store = inject(Store);
|
|
84
|
+
audience = inject(AUTH_AUDIENCE);
|
|
85
|
+
settingsRead$;
|
|
86
|
+
get manifest() {
|
|
87
|
+
const m = this.store.selectSnapshot(AppConfigState.manifest);
|
|
88
|
+
if (!m) throw new Error("ApiManifest not loaded — call AppInitService.load() first");
|
|
89
|
+
return m;
|
|
90
|
+
}
|
|
91
|
+
login(identifier, password) {
|
|
92
|
+
const body = this.audience === null ? {
|
|
93
|
+
identifier,
|
|
94
|
+
password
|
|
95
|
+
} : {
|
|
96
|
+
identifier,
|
|
97
|
+
password,
|
|
98
|
+
audience: this.audience
|
|
99
|
+
};
|
|
100
|
+
return this.http.post(this.manifest.auth.login, body);
|
|
101
|
+
}
|
|
102
|
+
refresh(refreshToken) {
|
|
103
|
+
return this.http.post(this.manifest.auth.refresh, { refreshToken });
|
|
104
|
+
}
|
|
105
|
+
logout() {
|
|
106
|
+
return this.http.post(this.manifest.auth.logout, {});
|
|
107
|
+
}
|
|
108
|
+
me() {
|
|
109
|
+
return this.http.get(this.manifest.auth.me);
|
|
110
|
+
}
|
|
111
|
+
getSettings() {
|
|
112
|
+
if (this.settingsRead$) return this.settingsRead$;
|
|
113
|
+
const read$ = this.http.get(this.manifest.identity.settingsUrl, { headers: { Accept: "application/json" } }).pipe(finalize(() => {
|
|
114
|
+
if (this.settingsRead$ === read$) this.settingsRead$ = void 0;
|
|
115
|
+
}), shareReplay({
|
|
116
|
+
bufferSize: 1,
|
|
117
|
+
refCount: true
|
|
118
|
+
}));
|
|
119
|
+
this.settingsRead$ = read$;
|
|
120
|
+
return read$;
|
|
121
|
+
}
|
|
122
|
+
getDeclaredSettings(host) {
|
|
123
|
+
const query = host === void 0 ? "" : `?host=${encodeURIComponent(host)}`;
|
|
124
|
+
return this.http.get(`${this.manifest.identity.settingsUrl}/declared${query}`, { headers: { Accept: "application/json" } });
|
|
125
|
+
}
|
|
126
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
127
|
+
minVersion: "12.0.0",
|
|
128
|
+
version: "22.2.3",
|
|
129
|
+
ngImport: i0,
|
|
130
|
+
type: IdentityApiClient,
|
|
131
|
+
deps: [],
|
|
132
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
133
|
+
});
|
|
134
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
135
|
+
minVersion: "12.0.0",
|
|
136
|
+
version: "22.2.3",
|
|
137
|
+
ngImport: i0,
|
|
138
|
+
type: IdentityApiClient,
|
|
139
|
+
providedIn: "root"
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
143
|
+
minVersion: "12.0.0",
|
|
144
|
+
version: "22.2.3",
|
|
145
|
+
ngImport: i0,
|
|
146
|
+
type: IdentityApiClient,
|
|
147
|
+
decorators: [{
|
|
148
|
+
type: Injectable,
|
|
149
|
+
args: [{ providedIn: "root" }]
|
|
150
|
+
}]
|
|
151
|
+
});
|
|
152
|
+
const AUDIENCE_NOT_GRANTED = "/errors/identity/audience-not-granted";
|
|
153
|
+
const WRONG_INTERFACE = "/errors/identity/wrong-interface";
|
|
154
|
+
const AUDIENCE_REQUIRED = "/errors/identity/audience-required";
|
|
155
|
+
function audienceRefusalOf(error) {
|
|
156
|
+
if (!(error instanceof HttpErrorResponse) || 403 !== error.status) return null;
|
|
157
|
+
const body = error.error;
|
|
158
|
+
const type = body !== null && typeof body === "object" ? body.type : void 0;
|
|
159
|
+
if ("/errors/identity/audience-not-granted" === type) return "not-granted";
|
|
160
|
+
return "/errors/identity/audience-required" === type ? "required" : null;
|
|
161
|
+
}
|
|
162
|
+
function sessionEndsOn(error) {
|
|
163
|
+
if (error instanceof HttpErrorResponse && 403 === error.status) return null !== audienceRefusalOf(error);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
var Login = class {
|
|
167
|
+
identifier;
|
|
168
|
+
password;
|
|
169
|
+
static type = "[Auth] Login";
|
|
170
|
+
constructor(identifier, password) {
|
|
171
|
+
this.identifier = identifier;
|
|
172
|
+
this.password = password;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var Logout = class {
|
|
176
|
+
static type = "[Auth] Logout";
|
|
177
|
+
};
|
|
178
|
+
var RestoreSession = class {
|
|
179
|
+
static type = "[Auth] Restore Session";
|
|
180
|
+
};
|
|
181
|
+
var SetTokens = class {
|
|
182
|
+
response;
|
|
183
|
+
static type = "[Auth] Set Tokens";
|
|
184
|
+
constructor(response) {
|
|
185
|
+
this.response = response;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var PatchCurrentUser = class {
|
|
189
|
+
patch;
|
|
190
|
+
static type = "[Auth] Patch Current User";
|
|
191
|
+
constructor(patch) {
|
|
192
|
+
this.patch = patch;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const ELEVATION_PROMPT = new InjectionToken("coolms.elevation-prompt");
|
|
196
|
+
const ELEVATION_ACTION = new HttpContextToken(() => null);
|
|
197
|
+
const ELEVATION_NOTICE = new InjectionToken("coolms.elevation-notice");
|
|
198
|
+
const BYPASS_ELEVATION = new HttpContextToken(() => false);
|
|
199
|
+
const CROSS_TAB_KEY = "coolms.elevation.changed";
|
|
200
|
+
const RECONCILE_MIN_INTERVAL_MS = 2e3;
|
|
201
|
+
const ELEVATION_REQUIRED_HEADER = "X-Elevation-Required";
|
|
202
|
+
const BACKGROUND_REQUEST = new HttpContextToken(() => false);
|
|
203
|
+
const ELEVATION_REQUIRED_PROBLEM_TYPE = "/errors/elevation-required";
|
|
204
|
+
const ELEVATION_CODE_REQUIRED_TYPE = "/errors/elevation/code-required";
|
|
205
|
+
const ELEVATION_RETRY_TYPES = ["/errors/elevation/wrong-password", "/errors/elevation/wrong-code"];
|
|
206
|
+
function isElevationRefusal(err) {
|
|
207
|
+
if (!(err instanceof HttpErrorResponse) || err.status !== 403) return false;
|
|
208
|
+
const body = err.error;
|
|
209
|
+
return typeof body === "object" && body !== null && body.type === "/errors/elevation-required" || !!err.headers.get("X-Elevation-Required");
|
|
210
|
+
}
|
|
211
|
+
var ElevationService = class ElevationService {
|
|
212
|
+
http = inject(HttpClient);
|
|
213
|
+
store = inject(Store);
|
|
214
|
+
prompt = inject(ELEVATION_PROMPT, { optional: true });
|
|
215
|
+
destroyRef = inject(DestroyRef);
|
|
216
|
+
served = signal(null, ...ngDevMode ? [{ debugName: "served" }] : /* istanbul ignore next */ []);
|
|
217
|
+
state = () => {
|
|
218
|
+
const served = this.served();
|
|
219
|
+
if (served === null || !isPast(served)) return served;
|
|
220
|
+
const expired = expiredView(served);
|
|
221
|
+
untracked(() => this.served.set(expired));
|
|
222
|
+
this.announceExpiryLater();
|
|
223
|
+
return expired;
|
|
224
|
+
};
|
|
225
|
+
elevated = () => this.state()?.elevated ?? false;
|
|
226
|
+
mayElevate = () => this.state()?.mayElevate ?? false;
|
|
227
|
+
expiresAt = () => {
|
|
228
|
+
const iso = this.state()?.expiresAt;
|
|
229
|
+
return iso ? new Date(iso) : null;
|
|
230
|
+
};
|
|
231
|
+
changes$ = new Subject();
|
|
232
|
+
retriesWaiting = signal(0, ...ngDevMode ? [{ debugName: "retriesWaiting" }] : /* istanbul ignore next */ []);
|
|
233
|
+
retriesPending = this.retriesWaiting.asReadonly();
|
|
234
|
+
retriesSettled$ = new Subject();
|
|
235
|
+
holdForRetry() {
|
|
236
|
+
this.retriesWaiting.update((n) => n + 1);
|
|
237
|
+
let held = true;
|
|
238
|
+
return () => {
|
|
239
|
+
if (held) {
|
|
240
|
+
held = false;
|
|
241
|
+
this.retriesWaiting.update((n) => n - 1);
|
|
242
|
+
if (this.retriesWaiting() === 0) this.retriesSettled$.next();
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
expiryTimer = null;
|
|
247
|
+
pendingPrompt = null;
|
|
248
|
+
expiryAnnouncePending = false;
|
|
249
|
+
lastReconcileAt = 0;
|
|
250
|
+
constructor() {
|
|
251
|
+
if (typeof window !== "undefined") {
|
|
252
|
+
window.addEventListener("storage", this.onStorage);
|
|
253
|
+
window.addEventListener("focus", this.onFocus);
|
|
254
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", this.onVisibilityChange);
|
|
255
|
+
this.destroyRef.onDestroy(() => {
|
|
256
|
+
window.removeEventListener("storage", this.onStorage);
|
|
257
|
+
window.removeEventListener("focus", this.onFocus);
|
|
258
|
+
if (typeof document !== "undefined") document.removeEventListener("visibilitychange", this.onVisibilityChange);
|
|
259
|
+
this.clearTimer();
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
get canPrompt() {
|
|
264
|
+
return this.available && this.prompt !== null;
|
|
265
|
+
}
|
|
266
|
+
get apiBase() {
|
|
267
|
+
return this.store.selectSnapshot(AppConfigState.manifest)?.apiBase ?? "/api/v1";
|
|
268
|
+
}
|
|
269
|
+
get available() {
|
|
270
|
+
return this.url !== null;
|
|
271
|
+
}
|
|
272
|
+
get url() {
|
|
273
|
+
return this.store.selectSnapshot(AppConfigState.manifest)?.identity?.elevationUrl ?? null;
|
|
274
|
+
}
|
|
275
|
+
isThisApi(url) {
|
|
276
|
+
const apiBase = this.store.selectSnapshot(AppConfigState.manifest)?.apiBase ?? "/api/v1";
|
|
277
|
+
let path = url.split("?")[0];
|
|
278
|
+
if (/^https?:\/\//.test(path)) try {
|
|
279
|
+
const parsed = new URL(path);
|
|
280
|
+
if (typeof window !== "undefined" && parsed.host !== window.location.host) return false;
|
|
281
|
+
path = parsed.pathname;
|
|
282
|
+
} catch {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return path === apiBase || path.startsWith(`${apiBase}/`);
|
|
286
|
+
}
|
|
287
|
+
refresh() {
|
|
288
|
+
const url = this.url;
|
|
289
|
+
if (!url) return of(this.inert());
|
|
290
|
+
return this.http.get(url, this.options()).pipe(tap((s) => this.apply(s)));
|
|
291
|
+
}
|
|
292
|
+
elevate(password, code) {
|
|
293
|
+
const url = this.url;
|
|
294
|
+
if (!url) return of(this.inert());
|
|
295
|
+
const body = { password };
|
|
296
|
+
if (code) body.code = code;
|
|
297
|
+
return this.http.post(url, body, this.options()).pipe(tap((s) => this.apply(s, "granted")));
|
|
298
|
+
}
|
|
299
|
+
drop(reason = "dropped_by_user") {
|
|
300
|
+
const url = this.url;
|
|
301
|
+
if (!url) return of(this.inert());
|
|
302
|
+
return this.http.delete(`${url}?reason=${reason}`, this.options()).pipe(switchMap(() => this.refresh()));
|
|
303
|
+
}
|
|
304
|
+
offerFor(refusal) {
|
|
305
|
+
if (!this.available || !this.prompt) return of(false);
|
|
306
|
+
return this.refresh().pipe(switchMap((state) => state.elevated ? of(false) : this.requestElevation({
|
|
307
|
+
state,
|
|
308
|
+
refusal
|
|
309
|
+
})));
|
|
310
|
+
}
|
|
311
|
+
requestElevation(request) {
|
|
312
|
+
if (!this.prompt) return of(false);
|
|
313
|
+
if (this.pendingPrompt) return this.pendingPrompt;
|
|
314
|
+
const prompt = this.prompt;
|
|
315
|
+
this.pendingPrompt = defer(() => prompt.open(request)).pipe(finalize(() => {
|
|
316
|
+
this.pendingPrompt = null;
|
|
317
|
+
}), shareReplay(1));
|
|
318
|
+
return this.pendingPrompt;
|
|
319
|
+
}
|
|
320
|
+
options() {
|
|
321
|
+
return { context: new HttpContext().set(BYPASS_ELEVATION, true) };
|
|
322
|
+
}
|
|
323
|
+
inert() {
|
|
324
|
+
return {
|
|
325
|
+
elevated: false,
|
|
326
|
+
ended: {
|
|
327
|
+
reason: "never",
|
|
328
|
+
at: null
|
|
329
|
+
},
|
|
330
|
+
lifetimeSeconds: 0,
|
|
331
|
+
lifetimeCeilingSeconds: 0,
|
|
332
|
+
mfaRequired: false,
|
|
333
|
+
warnings: []
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
apply(next, explicit) {
|
|
337
|
+
const prev = untracked(() => this.served());
|
|
338
|
+
this.served.set(next);
|
|
339
|
+
this.schedule(next);
|
|
340
|
+
const kind = explicit ?? this.kindOf(prev, next);
|
|
341
|
+
if (kind === null) return;
|
|
342
|
+
this.expiryAnnouncePending = false;
|
|
343
|
+
this.changes$.next({
|
|
344
|
+
kind,
|
|
345
|
+
state: next
|
|
346
|
+
});
|
|
347
|
+
this.announceToOtherTabs();
|
|
348
|
+
}
|
|
349
|
+
kindOf(prev, next) {
|
|
350
|
+
const was = prev?.elevated ?? false;
|
|
351
|
+
if (was && !next.elevated) return next.ended.reason === "expired" ? "expired" : "dropped";
|
|
352
|
+
if (!was && next.elevated) return "granted";
|
|
353
|
+
if (was && next.elevated && (prev?.expiresAt ?? null) !== (next.expiresAt ?? null)) return "observed";
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
announceExpiryLater() {
|
|
357
|
+
if (this.expiryAnnouncePending) return;
|
|
358
|
+
this.expiryAnnouncePending = true;
|
|
359
|
+
queueMicrotask(() => {
|
|
360
|
+
if (!this.expiryAnnouncePending) return;
|
|
361
|
+
this.expiryAnnouncePending = false;
|
|
362
|
+
const state = untracked(() => this.served());
|
|
363
|
+
if (state !== null && !state.elevated) this.changes$.next({
|
|
364
|
+
kind: "expired",
|
|
365
|
+
state
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
schedule(state) {
|
|
370
|
+
this.clearTimer();
|
|
371
|
+
if (!state.elevated || !state.expiresAt) return;
|
|
372
|
+
const wanted = Date.parse(state.expiresAt) - Date.now() + 250;
|
|
373
|
+
const ms = Math.min(Math.max(1e3, wanted), 2147483647);
|
|
374
|
+
this.expiryTimer = setTimeout(() => {
|
|
375
|
+
this.expiryTimer = null;
|
|
376
|
+
this.refresh().subscribe({
|
|
377
|
+
next: (s) => {
|
|
378
|
+
if (s.elevated && s.expiresAt && Date.parse(s.expiresAt) <= Date.now()) this.scheduleRetry();
|
|
379
|
+
},
|
|
380
|
+
error: () => this.scheduleRetry()
|
|
381
|
+
});
|
|
382
|
+
}, ms);
|
|
383
|
+
}
|
|
384
|
+
scheduleRetry() {
|
|
385
|
+
this.clearTimer();
|
|
386
|
+
this.expiryTimer = setTimeout(() => {
|
|
387
|
+
this.expiryTimer = null;
|
|
388
|
+
this.refresh().subscribe({ error: () => void 0 });
|
|
389
|
+
}, 5e3);
|
|
390
|
+
}
|
|
391
|
+
clearTimer() {
|
|
392
|
+
if (this.expiryTimer !== null) {
|
|
393
|
+
clearTimeout(this.expiryTimer);
|
|
394
|
+
this.expiryTimer = null;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
announceToOtherTabs() {
|
|
398
|
+
try {
|
|
399
|
+
localStorage.setItem(CROSS_TAB_KEY, String(Date.now()));
|
|
400
|
+
} catch {}
|
|
401
|
+
}
|
|
402
|
+
onStorage = (event) => {
|
|
403
|
+
if (event.key !== CROSS_TAB_KEY || !this.available) return;
|
|
404
|
+
this.refresh().subscribe({ error: () => void 0 });
|
|
405
|
+
};
|
|
406
|
+
onFocus = () => this.reconcile();
|
|
407
|
+
onVisibilityChange = () => {
|
|
408
|
+
if (document.visibilityState === "visible") this.reconcile();
|
|
409
|
+
};
|
|
410
|
+
reconcile() {
|
|
411
|
+
this.state();
|
|
412
|
+
if (!this.available) return;
|
|
413
|
+
const now = Date.now();
|
|
414
|
+
if (now - this.lastReconcileAt < RECONCILE_MIN_INTERVAL_MS) return;
|
|
415
|
+
this.lastReconcileAt = now;
|
|
416
|
+
this.refresh().subscribe({ error: () => void 0 });
|
|
417
|
+
}
|
|
418
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
419
|
+
minVersion: "12.0.0",
|
|
420
|
+
version: "22.2.3",
|
|
421
|
+
ngImport: i0,
|
|
422
|
+
type: ElevationService,
|
|
423
|
+
deps: [],
|
|
424
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
425
|
+
});
|
|
426
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
427
|
+
minVersion: "12.0.0",
|
|
428
|
+
version: "22.2.3",
|
|
429
|
+
ngImport: i0,
|
|
430
|
+
type: ElevationService,
|
|
431
|
+
providedIn: "root"
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
435
|
+
minVersion: "12.0.0",
|
|
436
|
+
version: "22.2.3",
|
|
437
|
+
ngImport: i0,
|
|
438
|
+
type: ElevationService,
|
|
439
|
+
decorators: [{
|
|
440
|
+
type: Injectable,
|
|
441
|
+
args: [{ providedIn: "root" }]
|
|
442
|
+
}],
|
|
443
|
+
ctorParameters: () => []
|
|
444
|
+
});
|
|
445
|
+
function isPast(state) {
|
|
446
|
+
if (!state.elevated || !state.expiresAt) return false;
|
|
447
|
+
const at = Date.parse(state.expiresAt);
|
|
448
|
+
return Number.isFinite(at) && at <= Date.now();
|
|
449
|
+
}
|
|
450
|
+
function expiredView(state) {
|
|
451
|
+
return {
|
|
452
|
+
...state,
|
|
453
|
+
elevated: false,
|
|
454
|
+
expiresAt: null,
|
|
455
|
+
grantedAt: null,
|
|
456
|
+
factorConfirmed: null,
|
|
457
|
+
ended: {
|
|
458
|
+
reason: "expired",
|
|
459
|
+
at: state.expiresAt ?? null
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
const NOT_AVAILABLE = "Not available right now";
|
|
464
|
+
const SOMETHING_WENT_WRONG = "Something went wrong. Try again.";
|
|
465
|
+
function sentenceOf(text) {
|
|
466
|
+
return typeof text === "string" && text.trim() !== "" ? text : null;
|
|
467
|
+
}
|
|
468
|
+
function problemOf(error) {
|
|
469
|
+
let body = error.error;
|
|
470
|
+
if (typeof body === "string") try {
|
|
471
|
+
body = JSON.parse(body);
|
|
472
|
+
} catch {
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
if (typeof body !== "object" || body === null) return null;
|
|
476
|
+
const prototype = Object.getPrototypeOf(body);
|
|
477
|
+
return prototype === Object.prototype || prototype === null ? body : null;
|
|
478
|
+
}
|
|
479
|
+
const FRAMEWORK_FAULT = /^\/errors\/5\d\d$/;
|
|
480
|
+
function declaredProblemOf(error) {
|
|
481
|
+
if (!(error instanceof HttpErrorResponse)) return null;
|
|
482
|
+
const problem = problemOf(error);
|
|
483
|
+
const type = problem?.["type"];
|
|
484
|
+
return typeof type === "string" && type.trim() !== "" && type !== "about:blank" && !FRAMEWORK_FAULT.test(type) ? problem : null;
|
|
485
|
+
}
|
|
486
|
+
function declaredTypeOf(error) {
|
|
487
|
+
const type = declaredProblemOf(error)?.["type"];
|
|
488
|
+
return typeof type === "string" ? type : null;
|
|
489
|
+
}
|
|
490
|
+
function isRefusal(error) {
|
|
491
|
+
return error instanceof HttpErrorResponse && error.status >= 400 && error.status <= 499;
|
|
492
|
+
}
|
|
493
|
+
function firstFieldMessageOf(error) {
|
|
494
|
+
if (!(error instanceof HttpErrorResponse) || error.status !== 422) return null;
|
|
495
|
+
const violations = problemOf(error)?.["violations"];
|
|
496
|
+
if (!Array.isArray(violations)) return null;
|
|
497
|
+
for (const one of violations) {
|
|
498
|
+
const message = typeof one === "object" && one !== null ? sentenceOf(one.message) : null;
|
|
499
|
+
if (message !== null) return message;
|
|
500
|
+
}
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
function refusalWords(error) {
|
|
504
|
+
const field = firstFieldMessageOf(error);
|
|
505
|
+
if (field !== null) return field;
|
|
506
|
+
const problem = declaredProblemOf(error);
|
|
507
|
+
if (problem === null) return SOMETHING_WENT_WRONG;
|
|
508
|
+
return sentenceOf(problem["detail"]) ?? "Not available right now";
|
|
509
|
+
}
|
|
510
|
+
var ErrorHandlerService = class ErrorHandlerService {
|
|
511
|
+
humanize(err) {
|
|
512
|
+
return refusalWords(err);
|
|
513
|
+
}
|
|
514
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
515
|
+
minVersion: "12.0.0",
|
|
516
|
+
version: "22.2.3",
|
|
517
|
+
ngImport: i0,
|
|
518
|
+
type: ErrorHandlerService,
|
|
519
|
+
deps: [],
|
|
520
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
521
|
+
});
|
|
522
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
523
|
+
minVersion: "12.0.0",
|
|
524
|
+
version: "22.2.3",
|
|
525
|
+
ngImport: i0,
|
|
526
|
+
type: ErrorHandlerService,
|
|
527
|
+
providedIn: "root"
|
|
528
|
+
});
|
|
529
|
+
};
|
|
530
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
531
|
+
minVersion: "12.0.0",
|
|
532
|
+
version: "22.2.3",
|
|
533
|
+
ngImport: i0,
|
|
534
|
+
type: ErrorHandlerService,
|
|
535
|
+
decorators: [{
|
|
536
|
+
type: Injectable,
|
|
537
|
+
args: [{ providedIn: "root" }]
|
|
538
|
+
}]
|
|
539
|
+
});
|
|
540
|
+
const PREFERENCES_NOTICE = new InjectionToken("coolms.preferences-notice");
|
|
541
|
+
const DATAGRID_ENTRY_PREFIX = "datagrid:";
|
|
542
|
+
function datagridEntry(gridId) {
|
|
543
|
+
return DATAGRID_ENTRY_PREFIX + gridId;
|
|
544
|
+
}
|
|
545
|
+
const NAMESPACES = /* @__PURE__ */ new Set([
|
|
546
|
+
"grids",
|
|
547
|
+
"panel",
|
|
548
|
+
"page",
|
|
549
|
+
"terminal",
|
|
550
|
+
"nav"
|
|
551
|
+
]);
|
|
552
|
+
function isObject(value) {
|
|
553
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
554
|
+
}
|
|
555
|
+
function gridPrefOf(entry) {
|
|
556
|
+
if (!isObject(entry)) return null;
|
|
557
|
+
const pref = {};
|
|
558
|
+
if (Array.isArray(entry["columns"])) pref.columns = entry["columns"];
|
|
559
|
+
if (isObject(entry["columnWidths"])) pref.columnWidths = entry["columnWidths"];
|
|
560
|
+
if (isObject(entry["columnFractions"])) pref.columnFractions = entry["columnFractions"];
|
|
561
|
+
return pref.columns === void 0 && pref.columnWidths === void 0 && pref.columnFractions === void 0 ? null : pref;
|
|
562
|
+
}
|
|
563
|
+
var UserPreferencesService = class UserPreferencesService {
|
|
564
|
+
http = inject(HttpClient);
|
|
565
|
+
store = inject(Store);
|
|
566
|
+
destroyRef = inject(DestroyRef);
|
|
567
|
+
errors = inject(ErrorHandlerService);
|
|
568
|
+
notice = inject(PREFERENCES_NOTICE, { optional: true });
|
|
569
|
+
document = inject(DOCUMENT);
|
|
570
|
+
STORAGE_KEY = "coolms_ui_prefs";
|
|
571
|
+
CHANGED_AT = "_at";
|
|
572
|
+
SYNC_DELAY = 2e3;
|
|
573
|
+
RETRY_DELAYS = [
|
|
574
|
+
5e3,
|
|
575
|
+
3e4,
|
|
576
|
+
12e4
|
|
577
|
+
];
|
|
578
|
+
pending = /* @__PURE__ */ new Map();
|
|
579
|
+
syncSubject = new Subject();
|
|
580
|
+
failures = 0;
|
|
581
|
+
retryTimer = null;
|
|
582
|
+
constructor() {
|
|
583
|
+
this.syncSubject.pipe(debounceTime(this.SYNC_DELAY), takeUntilDestroyed(this.destroyRef)).subscribe(() => this.flush());
|
|
584
|
+
const win = this.document.defaultView;
|
|
585
|
+
if (win) merge(fromEvent(win, "online"), fromEvent(this.document, "visibilitychange").pipe(filter(() => this.document.visibilityState === "visible"))).pipe(filter(() => this.retryTimer !== null), takeUntilDestroyed(this.destroyRef)).subscribe(() => this.flush());
|
|
586
|
+
this.destroyRef.onDestroy(() => this.cancelRetry());
|
|
587
|
+
if (win) merge(fromEvent(win, "pagehide"), fromEvent(this.document, "visibilitychange").pipe(filter(() => this.document.visibilityState === "hidden"))).pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.flushOnLeave());
|
|
588
|
+
}
|
|
589
|
+
flushOnLeave() {
|
|
590
|
+
if (this.pending.size === 0) return;
|
|
591
|
+
const url = this.store.selectSnapshot(AppConfigState.manifest)?.auth?.preferencesUrl;
|
|
592
|
+
const view = this.document.defaultView;
|
|
593
|
+
if (!url || !view || typeof view.fetch !== "function") return;
|
|
594
|
+
const entries = Object.fromEntries(this.pending);
|
|
595
|
+
this.pending.clear();
|
|
596
|
+
this.cancelRetry();
|
|
597
|
+
const token = this.store.selectSnapshot((state) => state.auth?.accessToken ?? null);
|
|
598
|
+
view.fetch(url, {
|
|
599
|
+
method: "PATCH",
|
|
600
|
+
keepalive: true,
|
|
601
|
+
credentials: "include",
|
|
602
|
+
headers: {
|
|
603
|
+
"Content-Type": "application/merge-patch+json",
|
|
604
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
605
|
+
},
|
|
606
|
+
body: JSON.stringify({ uiPrefs: entries })
|
|
607
|
+
}).catch(() => void 0);
|
|
608
|
+
}
|
|
609
|
+
save(all, ...changed) {
|
|
610
|
+
const now = Date.now();
|
|
611
|
+
const at = { ...this.changedAt(all) };
|
|
612
|
+
for (const id of changed) at[id] = now;
|
|
613
|
+
all[this.CHANGED_AT] = at;
|
|
614
|
+
this.write(all);
|
|
615
|
+
for (const id of changed) this.pending.set(id, all[id] ?? {});
|
|
616
|
+
this.pendingAt(Object.fromEntries(changed.map((id) => [id, now])));
|
|
617
|
+
this.syncSubject.next();
|
|
618
|
+
}
|
|
619
|
+
pendingAt(at) {
|
|
620
|
+
const before = this.pending.get(this.CHANGED_AT);
|
|
621
|
+
this.pending.set(this.CHANGED_AT, {
|
|
622
|
+
...isObject(before) ? before : {},
|
|
623
|
+
...at
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
changedAt(all) {
|
|
627
|
+
const at = all[this.CHANGED_AT];
|
|
628
|
+
return isObject(at) ? at : {};
|
|
629
|
+
}
|
|
630
|
+
write(all) {
|
|
631
|
+
try {
|
|
632
|
+
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(all));
|
|
633
|
+
} catch {}
|
|
634
|
+
}
|
|
635
|
+
readLocal() {
|
|
636
|
+
try {
|
|
637
|
+
const raw = localStorage.getItem(this.STORAGE_KEY);
|
|
638
|
+
const all = raw ? JSON.parse(raw) : {};
|
|
639
|
+
return isObject(all) ? all : {};
|
|
640
|
+
} catch {
|
|
641
|
+
return {};
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
load() {
|
|
645
|
+
const all = this.readLocal();
|
|
646
|
+
if (this.migrate(all)) this.write(all);
|
|
647
|
+
return all;
|
|
648
|
+
}
|
|
649
|
+
migrate(all) {
|
|
650
|
+
let dirty = false;
|
|
651
|
+
if (typeof all["terminal_height"] === "number") {
|
|
652
|
+
const terminal = isObject(all["terminal"]) ? all["terminal"] : {};
|
|
653
|
+
terminal["height"] = all["terminal_height"];
|
|
654
|
+
all["terminal"] = terminal;
|
|
655
|
+
delete all["terminal_height"];
|
|
656
|
+
dirty = true;
|
|
657
|
+
}
|
|
658
|
+
if (typeof all["media_view_mode"] === "string") {
|
|
659
|
+
const page = isObject(all["page"]) ? all["page"] : {};
|
|
660
|
+
const media = isObject(page["media"]) ? page["media"] : {};
|
|
661
|
+
media["viewMode"] = all["media_view_mode"];
|
|
662
|
+
page["media"] = media;
|
|
663
|
+
all["page"] = page;
|
|
664
|
+
delete all["media_view_mode"];
|
|
665
|
+
dirty = true;
|
|
666
|
+
}
|
|
667
|
+
if (isObject(all["media_collections_panel"])) {
|
|
668
|
+
const panel = isObject(all["panel"]) ? all["panel"] : {};
|
|
669
|
+
panel["media_panel_left"] = all["media_collections_panel"];
|
|
670
|
+
all["panel"] = panel;
|
|
671
|
+
delete all["media_collections_panel"];
|
|
672
|
+
dirty = true;
|
|
673
|
+
}
|
|
674
|
+
for (const id of Object.keys(all)) if (Array.isArray(all[id])) {
|
|
675
|
+
all[id] = {};
|
|
676
|
+
dirty = true;
|
|
677
|
+
}
|
|
678
|
+
const moved = [];
|
|
679
|
+
const toEntry = (gridId, pref) => {
|
|
680
|
+
const id = datagridEntry(gridId);
|
|
681
|
+
if (isObject(pref) && !(id in all)) {
|
|
682
|
+
all[id] = pref;
|
|
683
|
+
moved.push(id);
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
for (const key of Object.keys(all)) {
|
|
687
|
+
if (NAMESPACES.has(key) || key.includes(":") || !isObject(all[key])) continue;
|
|
688
|
+
const obj = all[key];
|
|
689
|
+
if ("columns" in obj || "columnWidths" in obj) {
|
|
690
|
+
toEntry(key, obj);
|
|
691
|
+
delete all[key];
|
|
692
|
+
dirty = true;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if ("grids" in all) {
|
|
696
|
+
const grids = all["grids"];
|
|
697
|
+
if (isObject(grids)) for (const [gridId, pref] of Object.entries(grids)) toEntry(gridId, pref);
|
|
698
|
+
delete all["grids"];
|
|
699
|
+
dirty = true;
|
|
700
|
+
}
|
|
701
|
+
if (moved.length > 0) {
|
|
702
|
+
for (const id of moved) this.pending.set(id, all[id]);
|
|
703
|
+
this.syncSubject.next();
|
|
704
|
+
}
|
|
705
|
+
return dirty;
|
|
706
|
+
}
|
|
707
|
+
loadFromServer(uiPrefs) {
|
|
708
|
+
if (!isObject(uiPrefs) || Object.keys(uiPrefs).length === 0) return;
|
|
709
|
+
const all = this.readLocal();
|
|
710
|
+
const localAt = this.changedAt(all);
|
|
711
|
+
const serverAt = this.changedAt(uiPrefs);
|
|
712
|
+
const at = { ...localAt };
|
|
713
|
+
const newerHere = [];
|
|
714
|
+
const oldGrids = isObject(uiPrefs["grids"]) ? { ...uiPrefs["grids"] } : null;
|
|
715
|
+
for (const [id, value] of Object.entries(uiPrefs)) {
|
|
716
|
+
if (id === "grids" || id === this.CHANGED_AT || this.pending.has(id)) continue;
|
|
717
|
+
if ((localAt[id] ?? 0) > (serverAt[id] ?? 0) && id in all) {
|
|
718
|
+
newerHere.push(id);
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
all[id] = value;
|
|
722
|
+
if (serverAt[id] !== void 0) at[id] = serverAt[id];
|
|
723
|
+
}
|
|
724
|
+
all[this.CHANGED_AT] = at;
|
|
725
|
+
if (oldGrids !== null) all["grids"] = {
|
|
726
|
+
...oldGrids,
|
|
727
|
+
...isObject(all["grids"]) ? all["grids"] : {}
|
|
728
|
+
};
|
|
729
|
+
this.migrate(all);
|
|
730
|
+
this.write(all);
|
|
731
|
+
if (newerHere.length > 0) {
|
|
732
|
+
for (const id of newerHere) this.pending.set(id, all[id] ?? {});
|
|
733
|
+
this.pendingAt(Object.fromEntries(newerHere.map((id) => [id, localAt[id]])));
|
|
734
|
+
this.syncSubject.next();
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
flush() {
|
|
738
|
+
this.cancelRetry();
|
|
739
|
+
if (this.pending.size === 0) return;
|
|
740
|
+
const entries = Object.fromEntries(this.pending);
|
|
741
|
+
this.pending.clear();
|
|
742
|
+
this.syncToServer(entries);
|
|
743
|
+
}
|
|
744
|
+
syncToServer(entries) {
|
|
745
|
+
const url = this.store.selectSnapshot(AppConfigState.manifest)?.auth?.preferencesUrl;
|
|
746
|
+
if (!url) return;
|
|
747
|
+
this.http.patch(url, { uiPrefs: entries }, {
|
|
748
|
+
headers: { "Content-Type": "application/merge-patch+json" },
|
|
749
|
+
context: new HttpContext().set(BACKGROUND_REQUEST, true)
|
|
750
|
+
}).subscribe({
|
|
751
|
+
next: () => {
|
|
752
|
+
this.failures = 0;
|
|
753
|
+
},
|
|
754
|
+
error: (err) => this.refused(err, entries)
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
scheduleRetry() {
|
|
758
|
+
if (this.retryTimer !== null) return;
|
|
759
|
+
const delay = this.RETRY_DELAYS[Math.min(this.failures, this.RETRY_DELAYS.length) - 1];
|
|
760
|
+
this.retryTimer = setTimeout(() => {
|
|
761
|
+
this.retryTimer = null;
|
|
762
|
+
this.flush();
|
|
763
|
+
}, delay);
|
|
764
|
+
}
|
|
765
|
+
cancelRetry() {
|
|
766
|
+
if (this.retryTimer !== null) {
|
|
767
|
+
clearTimeout(this.retryTimer);
|
|
768
|
+
this.retryTimer = null;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
refused(err, entries) {
|
|
772
|
+
if (err instanceof HttpErrorResponse && err.status === 422) {
|
|
773
|
+
const sentence = `Your preferences could not be saved: ${this.errors.humanize(err)}`;
|
|
774
|
+
if (this.notice) this.notice.refused(sentence);
|
|
775
|
+
else console.warn(sentence);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
for (const [id, value] of Object.entries(entries)) {
|
|
779
|
+
if (id === this.CHANGED_AT) continue;
|
|
780
|
+
if (!this.pending.has(id)) this.pending.set(id, value);
|
|
781
|
+
}
|
|
782
|
+
const at = entries[this.CHANGED_AT];
|
|
783
|
+
if (isObject(at)) {
|
|
784
|
+
const since = this.pending.get(this.CHANGED_AT);
|
|
785
|
+
this.pending.set(this.CHANGED_AT, {
|
|
786
|
+
...at,
|
|
787
|
+
...isObject(since) ? since : {}
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
this.failures++;
|
|
791
|
+
this.scheduleRetry();
|
|
792
|
+
console.warn("Preferences sync failed:", err);
|
|
793
|
+
}
|
|
794
|
+
getGridPref(gridId) {
|
|
795
|
+
return gridPrefOf(this.load()[datagridEntry(gridId)]);
|
|
796
|
+
}
|
|
797
|
+
setColumns(gridId, columns) {
|
|
798
|
+
this.updateGrid(gridId, (existing) => ({
|
|
799
|
+
...existing,
|
|
800
|
+
columns
|
|
801
|
+
}));
|
|
802
|
+
}
|
|
803
|
+
setColumnWidth(gridId, field, width) {
|
|
804
|
+
this.updateGrid(gridId, (existing) => ({
|
|
805
|
+
...existing,
|
|
806
|
+
columnWidths: {
|
|
807
|
+
...existing.columnWidths ?? {},
|
|
808
|
+
[field]: Math.max(60, width)
|
|
809
|
+
}
|
|
810
|
+
}));
|
|
811
|
+
}
|
|
812
|
+
setColumnFractions(gridId, fractions) {
|
|
813
|
+
const clean = {};
|
|
814
|
+
for (const [field, share] of Object.entries(fractions)) if (Number.isFinite(share) && share > 0) clean[field] = Math.min(1, share);
|
|
815
|
+
this.updateGrid(gridId, (existing) => ({
|
|
816
|
+
...existing,
|
|
817
|
+
columnFractions: clean,
|
|
818
|
+
columnWidths: null
|
|
819
|
+
}));
|
|
820
|
+
}
|
|
821
|
+
resetGrid(gridId) {
|
|
822
|
+
const id = datagridEntry(gridId);
|
|
823
|
+
const all = this.load();
|
|
824
|
+
delete all[id];
|
|
825
|
+
this.write(all);
|
|
826
|
+
this.pending.set(id, {
|
|
827
|
+
columns: null,
|
|
828
|
+
columnWidths: null,
|
|
829
|
+
columnFractions: null
|
|
830
|
+
});
|
|
831
|
+
this.flush();
|
|
832
|
+
}
|
|
833
|
+
updateGrid(gridId, updater) {
|
|
834
|
+
const id = datagridEntry(gridId);
|
|
835
|
+
const all = this.load();
|
|
836
|
+
const entry = isObject(all[id]) ? all[id] : {};
|
|
837
|
+
all[id] = {
|
|
838
|
+
...entry,
|
|
839
|
+
...updater(gridPrefOf(entry) ?? {})
|
|
840
|
+
};
|
|
841
|
+
this.save(all, id);
|
|
842
|
+
}
|
|
843
|
+
getTerminalHeight() {
|
|
844
|
+
const terminal = this.load()["terminal"];
|
|
845
|
+
return typeof terminal?.["height"] === "number" ? terminal["height"] : null;
|
|
846
|
+
}
|
|
847
|
+
setTerminalHeight(height) {
|
|
848
|
+
const all = this.load();
|
|
849
|
+
const terminal = isObject(all["terminal"]) ? all["terminal"] : {};
|
|
850
|
+
terminal["height"] = Math.round(height);
|
|
851
|
+
all["terminal"] = terminal;
|
|
852
|
+
this.save(all, "terminal");
|
|
853
|
+
}
|
|
854
|
+
getPanelState(key) {
|
|
855
|
+
try {
|
|
856
|
+
const panel = this.load()["panel"];
|
|
857
|
+
if (!panel) return null;
|
|
858
|
+
const p = panel[key];
|
|
859
|
+
if (!p || typeof p !== "object") return null;
|
|
860
|
+
const { width, collapsed } = p;
|
|
861
|
+
return typeof width === "number" && typeof collapsed === "boolean" ? {
|
|
862
|
+
width,
|
|
863
|
+
collapsed
|
|
864
|
+
} : null;
|
|
865
|
+
} catch {
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
setPanelState(key, width, collapsed) {
|
|
870
|
+
const all = this.load();
|
|
871
|
+
const panel = isObject(all["panel"]) ? all["panel"] : {};
|
|
872
|
+
panel[key] = {
|
|
873
|
+
width: Math.round(width),
|
|
874
|
+
collapsed
|
|
875
|
+
};
|
|
876
|
+
all["panel"] = panel;
|
|
877
|
+
this.save(all, "panel");
|
|
878
|
+
}
|
|
879
|
+
getPageState(pageKey) {
|
|
880
|
+
try {
|
|
881
|
+
const page = this.load()["page"];
|
|
882
|
+
if (!page) return null;
|
|
883
|
+
return page[pageKey] ?? null;
|
|
884
|
+
} catch {
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
setPageState(pageKey, state) {
|
|
889
|
+
const all = this.load();
|
|
890
|
+
const page = isObject(all["page"]) ? all["page"] : {};
|
|
891
|
+
page[pageKey] = {
|
|
892
|
+
...isObject(page[pageKey]) ? page[pageKey] : {},
|
|
893
|
+
...state
|
|
894
|
+
};
|
|
895
|
+
all["page"] = page;
|
|
896
|
+
this.save(all, "page");
|
|
897
|
+
}
|
|
898
|
+
getMediaViewMode() {
|
|
899
|
+
return this.getPageState("media")?.viewMode ?? null;
|
|
900
|
+
}
|
|
901
|
+
setMediaViewMode(mode) {
|
|
902
|
+
this.setPageState("media", { viewMode: mode });
|
|
903
|
+
}
|
|
904
|
+
getMediaCollectionsPanel() {
|
|
905
|
+
return this.getPanelState("media_panel_left");
|
|
906
|
+
}
|
|
907
|
+
setMediaCollectionsPanel(width, collapsed) {
|
|
908
|
+
this.setPanelState("media_panel_left", width, collapsed);
|
|
909
|
+
}
|
|
910
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
911
|
+
minVersion: "12.0.0",
|
|
912
|
+
version: "22.2.3",
|
|
913
|
+
ngImport: i0,
|
|
914
|
+
type: UserPreferencesService,
|
|
915
|
+
deps: [],
|
|
916
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
917
|
+
});
|
|
918
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
919
|
+
minVersion: "12.0.0",
|
|
920
|
+
version: "22.2.3",
|
|
921
|
+
ngImport: i0,
|
|
922
|
+
type: UserPreferencesService,
|
|
923
|
+
providedIn: "root"
|
|
924
|
+
});
|
|
925
|
+
};
|
|
926
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
927
|
+
minVersion: "12.0.0",
|
|
928
|
+
version: "22.2.3",
|
|
929
|
+
ngImport: i0,
|
|
930
|
+
type: UserPreferencesService,
|
|
931
|
+
decorators: [{
|
|
932
|
+
type: Injectable,
|
|
933
|
+
args: [{ providedIn: "root" }]
|
|
934
|
+
}],
|
|
935
|
+
ctorParameters: () => []
|
|
936
|
+
});
|
|
937
|
+
const STORAGE_KEY$2 = "coolms_token";
|
|
938
|
+
let AuthState = class AuthState {
|
|
939
|
+
api = inject(IdentityApiClient);
|
|
940
|
+
prefs = inject(UserPreferencesService);
|
|
941
|
+
login(ctx, { identifier, password }) {
|
|
942
|
+
return this.api.login(identifier, password).pipe(tap$1((res) => {
|
|
943
|
+
const state = {
|
|
944
|
+
accessToken: res.accessToken,
|
|
945
|
+
refreshToken: res.refreshToken,
|
|
946
|
+
expiresAt: res.expiresAt,
|
|
947
|
+
user: res.user ?? null
|
|
948
|
+
};
|
|
949
|
+
ctx.setState(state);
|
|
950
|
+
localStorage.setItem(STORAGE_KEY$2, JSON.stringify(state));
|
|
951
|
+
}), switchMap$1(() => this.api.me().pipe(catchError(() => of(null)))), tap$1((me) => {
|
|
952
|
+
if (!me) return;
|
|
953
|
+
const updated = {
|
|
954
|
+
...ctx.getState(),
|
|
955
|
+
user: me
|
|
956
|
+
};
|
|
957
|
+
ctx.setState(updated);
|
|
958
|
+
localStorage.setItem(STORAGE_KEY$2, JSON.stringify(updated));
|
|
959
|
+
if (me.uiPrefs) this.prefs.loadFromServer(me.uiPrefs);
|
|
960
|
+
}));
|
|
961
|
+
}
|
|
962
|
+
logout(ctx) {
|
|
963
|
+
ctx.setState({
|
|
964
|
+
accessToken: null,
|
|
965
|
+
refreshToken: null,
|
|
966
|
+
expiresAt: null,
|
|
967
|
+
user: null
|
|
968
|
+
});
|
|
969
|
+
localStorage.removeItem(STORAGE_KEY$2);
|
|
970
|
+
}
|
|
971
|
+
restore(ctx) {
|
|
972
|
+
const raw = localStorage.getItem(STORAGE_KEY$2);
|
|
973
|
+
if (!raw) return;
|
|
974
|
+
try {
|
|
975
|
+
const state = JSON.parse(raw);
|
|
976
|
+
if (state.accessToken || state.refreshToken) ctx.setState(state);
|
|
977
|
+
else localStorage.removeItem(STORAGE_KEY$2);
|
|
978
|
+
} catch {
|
|
979
|
+
localStorage.removeItem(STORAGE_KEY$2);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
setTokens(ctx, { response }) {
|
|
983
|
+
const state = {
|
|
984
|
+
accessToken: response.accessToken,
|
|
985
|
+
refreshToken: response.refreshToken,
|
|
986
|
+
expiresAt: response.expiresAt,
|
|
987
|
+
user: response.user ?? ctx.getState().user
|
|
988
|
+
};
|
|
989
|
+
ctx.setState(state);
|
|
990
|
+
localStorage.setItem(STORAGE_KEY$2, JSON.stringify(state));
|
|
991
|
+
}
|
|
992
|
+
patchCurrentUser(ctx, { patch }) {
|
|
993
|
+
const current = ctx.getState();
|
|
994
|
+
if (!current.user) return;
|
|
995
|
+
const updated = {
|
|
996
|
+
...current,
|
|
997
|
+
user: {
|
|
998
|
+
...current.user,
|
|
999
|
+
...patch
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
ctx.setState(updated);
|
|
1003
|
+
localStorage.setItem(STORAGE_KEY$2, JSON.stringify(updated));
|
|
1004
|
+
}
|
|
1005
|
+
static isAuthenticated(state) {
|
|
1006
|
+
return null !== state.accessToken;
|
|
1007
|
+
}
|
|
1008
|
+
static accessToken(state) {
|
|
1009
|
+
return state.accessToken;
|
|
1010
|
+
}
|
|
1011
|
+
static refreshToken(state) {
|
|
1012
|
+
return state.refreshToken;
|
|
1013
|
+
}
|
|
1014
|
+
static expiresAt(state) {
|
|
1015
|
+
return state.expiresAt;
|
|
1016
|
+
}
|
|
1017
|
+
static currentUser(state) {
|
|
1018
|
+
return state.user;
|
|
1019
|
+
}
|
|
1020
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1021
|
+
minVersion: "12.0.0",
|
|
1022
|
+
version: "22.2.3",
|
|
1023
|
+
ngImport: i0,
|
|
1024
|
+
type: AuthState,
|
|
1025
|
+
deps: [],
|
|
1026
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1027
|
+
});
|
|
1028
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1029
|
+
minVersion: "12.0.0",
|
|
1030
|
+
version: "22.2.3",
|
|
1031
|
+
ngImport: i0,
|
|
1032
|
+
type: AuthState
|
|
1033
|
+
});
|
|
1034
|
+
};
|
|
1035
|
+
__decorate([Action(Login)], AuthState.prototype, "login", null);
|
|
1036
|
+
__decorate([Action(Logout)], AuthState.prototype, "logout", null);
|
|
1037
|
+
__decorate([Action(RestoreSession)], AuthState.prototype, "restore", null);
|
|
1038
|
+
__decorate([Action(SetTokens)], AuthState.prototype, "setTokens", null);
|
|
1039
|
+
__decorate([Action(PatchCurrentUser)], AuthState.prototype, "patchCurrentUser", null);
|
|
1040
|
+
__decorate([Selector()], AuthState, "isAuthenticated", null);
|
|
1041
|
+
__decorate([Selector()], AuthState, "accessToken", null);
|
|
1042
|
+
__decorate([Selector()], AuthState, "refreshToken", null);
|
|
1043
|
+
__decorate([Selector()], AuthState, "expiresAt", null);
|
|
1044
|
+
__decorate([Selector()], AuthState, "currentUser", null);
|
|
1045
|
+
AuthState = __decorate([State({
|
|
1046
|
+
name: "auth",
|
|
1047
|
+
defaults: {
|
|
1048
|
+
accessToken: null,
|
|
1049
|
+
refreshToken: null,
|
|
1050
|
+
expiresAt: null,
|
|
1051
|
+
user: null
|
|
1052
|
+
}
|
|
1053
|
+
})], AuthState);
|
|
1054
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1055
|
+
minVersion: "12.0.0",
|
|
1056
|
+
version: "22.2.3",
|
|
1057
|
+
ngImport: i0,
|
|
1058
|
+
type: AuthState,
|
|
1059
|
+
decorators: [{ type: Injectable }],
|
|
1060
|
+
propDecorators: {
|
|
1061
|
+
login: [],
|
|
1062
|
+
logout: [],
|
|
1063
|
+
restore: [],
|
|
1064
|
+
setTokens: [],
|
|
1065
|
+
patchCurrentUser: []
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
var ConsoleAccessService = class ConsoleAccessService {
|
|
1069
|
+
static URL = "/api/v1/admin/manifest";
|
|
1070
|
+
static LEGACY_URL = "/api/v1/console/manifest";
|
|
1071
|
+
static REFUSED_REASON = "no-console-access";
|
|
1072
|
+
static SIGN_IN_AGAIN_REASON = "sign-in-again";
|
|
1073
|
+
http = inject(HttpClient);
|
|
1074
|
+
store = inject(Store);
|
|
1075
|
+
answer = "unknown";
|
|
1076
|
+
pending = null;
|
|
1077
|
+
generation = 0;
|
|
1078
|
+
constructor() {
|
|
1079
|
+
inject(Actions).pipe(ofActionDispatched(Login, Logout, RestoreSession)).subscribe(() => {
|
|
1080
|
+
this.generation++;
|
|
1081
|
+
this.answer = "unknown";
|
|
1082
|
+
this.pending = null;
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
ensure() {
|
|
1086
|
+
if (!this.store.selectSnapshot(AuthState.isAuthenticated)) return Promise.resolve("unknown");
|
|
1087
|
+
if ("unknown" !== this.answer) return Promise.resolve(this.answer);
|
|
1088
|
+
if (null !== this.pending) return this.pending;
|
|
1089
|
+
const askedFor = this.generation;
|
|
1090
|
+
const pending = firstValueFrom(this.http.get(ConsoleAccessService.URL).pipe(catchError((error) => error instanceof HttpErrorResponse && 404 === error.status ? this.http.get(ConsoleAccessService.LEGACY_URL) : throwError(() => error)), map((response) => ({
|
|
1091
|
+
access: "granted",
|
|
1092
|
+
response
|
|
1093
|
+
})), catchError((error) => of({
|
|
1094
|
+
access: accessOf(error),
|
|
1095
|
+
response: null
|
|
1096
|
+
})))).then(({ access, response }) => {
|
|
1097
|
+
if (askedFor !== this.generation) return this.ensure();
|
|
1098
|
+
if (null !== response) this.merge(response);
|
|
1099
|
+
this.pending = null;
|
|
1100
|
+
this.answer = access;
|
|
1101
|
+
return access;
|
|
1102
|
+
});
|
|
1103
|
+
this.pending = pending;
|
|
1104
|
+
return pending;
|
|
1105
|
+
}
|
|
1106
|
+
signOut() {
|
|
1107
|
+
const logout = this.store.selectSnapshot(AppConfigState.manifest)?.auth?.logout ?? "/api/v1/auth/logout";
|
|
1108
|
+
return this.http.post(logout, null).pipe(catchError(() => of(null)), switchMap(() => this.store.dispatch(new Logout())), map(() => void 0));
|
|
1109
|
+
}
|
|
1110
|
+
merge(response) {
|
|
1111
|
+
const config = this.store.selectSnapshot(AppConfigState.config);
|
|
1112
|
+
this.store.dispatch(new SetAppConfig({
|
|
1113
|
+
...config ?? {},
|
|
1114
|
+
manifest: {
|
|
1115
|
+
...config?.manifest ?? {},
|
|
1116
|
+
...response.manifest
|
|
1117
|
+
}
|
|
1118
|
+
}));
|
|
1119
|
+
}
|
|
1120
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1121
|
+
minVersion: "12.0.0",
|
|
1122
|
+
version: "22.2.3",
|
|
1123
|
+
ngImport: i0,
|
|
1124
|
+
type: ConsoleAccessService,
|
|
1125
|
+
deps: [],
|
|
1126
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1127
|
+
});
|
|
1128
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1129
|
+
minVersion: "12.0.0",
|
|
1130
|
+
version: "22.2.3",
|
|
1131
|
+
ngImport: i0,
|
|
1132
|
+
type: ConsoleAccessService,
|
|
1133
|
+
providedIn: "root"
|
|
1134
|
+
});
|
|
1135
|
+
};
|
|
1136
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1137
|
+
minVersion: "12.0.0",
|
|
1138
|
+
version: "22.2.3",
|
|
1139
|
+
ngImport: i0,
|
|
1140
|
+
type: ConsoleAccessService,
|
|
1141
|
+
decorators: [{
|
|
1142
|
+
type: Injectable,
|
|
1143
|
+
args: [{ providedIn: "root" }]
|
|
1144
|
+
}],
|
|
1145
|
+
ctorParameters: () => []
|
|
1146
|
+
});
|
|
1147
|
+
function accessOf(error) {
|
|
1148
|
+
const refusal = audienceRefusalOf(error);
|
|
1149
|
+
if ("not-granted" === refusal) return "refused";
|
|
1150
|
+
return "required" === refusal ? "sign-in-again" : "unknown";
|
|
1151
|
+
}
|
|
1152
|
+
const BACKGROUND = { context: new HttpContext().set(BACKGROUND_REQUEST, true) };
|
|
1153
|
+
var RealtimeTokenClient = class RealtimeTokenClient {
|
|
1154
|
+
static REFUSED = "no console access: no realtime connection";
|
|
1155
|
+
http = inject(HttpClient);
|
|
1156
|
+
store = inject(Store);
|
|
1157
|
+
injector = inject(Injector);
|
|
1158
|
+
get manifest() {
|
|
1159
|
+
const m = this.store.selectSnapshot(AppConfigState.manifest);
|
|
1160
|
+
if (!m) throw new Error("ApiManifest not loaded — call AppInitService.load() first");
|
|
1161
|
+
return m;
|
|
1162
|
+
}
|
|
1163
|
+
connectionToken() {
|
|
1164
|
+
return defer(() => this.injector.get(ConsoleAccessService).ensure()).pipe(switchMap((access) => "refused" === access || "sign-in-again" === access ? throwError(() => new Error(RealtimeTokenClient.REFUSED)) : this.http.post(this.manifest.apiBase + "/centrifugo/connection-token", {}, BACKGROUND)));
|
|
1165
|
+
}
|
|
1166
|
+
subscriptionToken(channel) {
|
|
1167
|
+
return this.http.post(this.manifest.apiBase + "/centrifugo/subscription-token", { channel }, BACKGROUND);
|
|
1168
|
+
}
|
|
1169
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1170
|
+
minVersion: "12.0.0",
|
|
1171
|
+
version: "22.2.3",
|
|
1172
|
+
ngImport: i0,
|
|
1173
|
+
type: RealtimeTokenClient,
|
|
1174
|
+
deps: [],
|
|
1175
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1176
|
+
});
|
|
1177
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1178
|
+
minVersion: "12.0.0",
|
|
1179
|
+
version: "22.2.3",
|
|
1180
|
+
ngImport: i0,
|
|
1181
|
+
type: RealtimeTokenClient,
|
|
1182
|
+
providedIn: "root"
|
|
1183
|
+
});
|
|
1184
|
+
};
|
|
1185
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1186
|
+
minVersion: "12.0.0",
|
|
1187
|
+
version: "22.2.3",
|
|
1188
|
+
ngImport: i0,
|
|
1189
|
+
type: RealtimeTokenClient,
|
|
1190
|
+
decorators: [{
|
|
1191
|
+
type: Injectable,
|
|
1192
|
+
args: [{ providedIn: "root" }]
|
|
1193
|
+
}]
|
|
1194
|
+
});
|
|
1195
|
+
const LOCK_NAME = "coolms_auth_refresh";
|
|
1196
|
+
const FRESH_TOKEN_GRACE_MS = 3e4;
|
|
1197
|
+
const STORAGE_KEY$1 = "coolms_token";
|
|
1198
|
+
var AuthRefreshCoordinator = class AuthRefreshCoordinator {
|
|
1199
|
+
api = inject(IdentityApiClient);
|
|
1200
|
+
store = inject(Store);
|
|
1201
|
+
router = inject(Router);
|
|
1202
|
+
inFlight = null;
|
|
1203
|
+
refresh(refreshToken, refusedAccessToken = null) {
|
|
1204
|
+
if (this.inFlight) return this.inFlight;
|
|
1205
|
+
this.inFlight = defer(() => this.refreshWithCrossTabLock(refreshToken, refusedAccessToken)).pipe(catchError((refreshErr) => {
|
|
1206
|
+
const isAuthFailure = refreshErr instanceof HttpErrorResponse && refreshErr.status === 401;
|
|
1207
|
+
const refusal = audienceRefusalOf(refreshErr);
|
|
1208
|
+
if (isAuthFailure || null !== refusal) {
|
|
1209
|
+
this.store.dispatch(new Logout());
|
|
1210
|
+
if (this.router.navigated) {
|
|
1211
|
+
const reason = null === refusal ? null : "required" === refusal ? ConsoleAccessService.SIGN_IN_AGAIN_REASON : ConsoleAccessService.REFUSED_REASON;
|
|
1212
|
+
null === reason ? this.router.navigate(["/login"]) : this.router.navigate(["/login"], { queryParams: { reason } });
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return throwError(() => refreshErr);
|
|
1216
|
+
}), shareReplay(1), finalize(() => {
|
|
1217
|
+
this.inFlight = null;
|
|
1218
|
+
}));
|
|
1219
|
+
return this.inFlight;
|
|
1220
|
+
}
|
|
1221
|
+
refreshWithCrossTabLock(refreshToken, refusedAccessToken) {
|
|
1222
|
+
const lockBody = () => this.executeRefresh(refreshToken, refusedAccessToken);
|
|
1223
|
+
if (typeof navigator === "undefined" || !("locks" in navigator)) return from(lockBody());
|
|
1224
|
+
return from(navigator.locks.request(LOCK_NAME, lockBody).then((value) => {
|
|
1225
|
+
if (value === void 0) throw new Error("Refresh lock aborted before completing.");
|
|
1226
|
+
return value;
|
|
1227
|
+
}));
|
|
1228
|
+
}
|
|
1229
|
+
async executeRefresh(originalRefreshToken, refusedAccessToken) {
|
|
1230
|
+
const shared = this.readShared();
|
|
1231
|
+
if (refusedAccessToken !== null) {
|
|
1232
|
+
if (shared !== null && shared.accessToken !== refusedAccessToken) {
|
|
1233
|
+
if (this.store.selectSnapshot(AuthState.accessToken) !== shared.accessToken) this.store.dispatch(new SetTokens(shared));
|
|
1234
|
+
return shared.accessToken;
|
|
1235
|
+
}
|
|
1236
|
+
} else {
|
|
1237
|
+
const cachedAccess = this.tryConsumeFreshState(shared);
|
|
1238
|
+
if (cachedAccess !== null) return cachedAccess;
|
|
1239
|
+
}
|
|
1240
|
+
const currentRefreshToken = shared?.refreshToken ?? this.store.selectSnapshot(AuthState.refreshToken) ?? originalRefreshToken;
|
|
1241
|
+
const response = await firstValueFrom(this.api.refresh(currentRefreshToken));
|
|
1242
|
+
this.store.dispatch(new SetTokens(response));
|
|
1243
|
+
return response.accessToken;
|
|
1244
|
+
}
|
|
1245
|
+
readShared() {
|
|
1246
|
+
let raw;
|
|
1247
|
+
try {
|
|
1248
|
+
raw = localStorage.getItem(STORAGE_KEY$1);
|
|
1249
|
+
} catch {
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
if (raw === null) return null;
|
|
1253
|
+
try {
|
|
1254
|
+
const parsed = JSON.parse(raw);
|
|
1255
|
+
if (typeof parsed?.accessToken !== "string" || typeof parsed.refreshToken !== "string" || typeof parsed.expiresAt !== "string") return null;
|
|
1256
|
+
return {
|
|
1257
|
+
accessToken: parsed.accessToken,
|
|
1258
|
+
refreshToken: parsed.refreshToken,
|
|
1259
|
+
expiresAt: parsed.expiresAt
|
|
1260
|
+
};
|
|
1261
|
+
} catch {
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
tryConsumeFreshState(shared) {
|
|
1266
|
+
const accessToken = shared?.accessToken ?? this.store.selectSnapshot(AuthState.accessToken);
|
|
1267
|
+
const expiresAtStr = shared?.expiresAt ?? this.store.selectSnapshot(AuthState.expiresAt);
|
|
1268
|
+
if (accessToken === null || expiresAtStr === null) return null;
|
|
1269
|
+
const expiresAtMs = new Date(expiresAtStr).getTime();
|
|
1270
|
+
if (Number.isNaN(expiresAtMs)) return null;
|
|
1271
|
+
if (Date.now() >= expiresAtMs - FRESH_TOKEN_GRACE_MS) return null;
|
|
1272
|
+
if (shared !== null && this.store.selectSnapshot(AuthState.accessToken) !== shared.accessToken) this.store.dispatch(new SetTokens(shared));
|
|
1273
|
+
return accessToken;
|
|
1274
|
+
}
|
|
1275
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1276
|
+
minVersion: "12.0.0",
|
|
1277
|
+
version: "22.2.3",
|
|
1278
|
+
ngImport: i0,
|
|
1279
|
+
type: AuthRefreshCoordinator,
|
|
1280
|
+
deps: [],
|
|
1281
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1282
|
+
});
|
|
1283
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1284
|
+
minVersion: "12.0.0",
|
|
1285
|
+
version: "22.2.3",
|
|
1286
|
+
ngImport: i0,
|
|
1287
|
+
type: AuthRefreshCoordinator,
|
|
1288
|
+
providedIn: "root"
|
|
1289
|
+
});
|
|
1290
|
+
};
|
|
1291
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1292
|
+
minVersion: "12.0.0",
|
|
1293
|
+
version: "22.2.3",
|
|
1294
|
+
ngImport: i0,
|
|
1295
|
+
type: AuthRefreshCoordinator,
|
|
1296
|
+
decorators: [{
|
|
1297
|
+
type: Injectable,
|
|
1298
|
+
args: [{ providedIn: "root" }]
|
|
1299
|
+
}]
|
|
1300
|
+
});
|
|
1301
|
+
const BYPASS_AUTH = new HttpContextToken(() => false);
|
|
1302
|
+
const authInterceptor = (req, next) => {
|
|
1303
|
+
const store = inject(Store);
|
|
1304
|
+
const router = inject(Router);
|
|
1305
|
+
const coordinator = inject(AuthRefreshCoordinator);
|
|
1306
|
+
const initService = inject(AppInitService);
|
|
1307
|
+
if (req.context.get(BYPASS_AUTH)) return next(req);
|
|
1308
|
+
if (req.url.includes("/auth/login") || req.url.includes("/auth/refresh")) return next(req);
|
|
1309
|
+
return initService.ready$.pipe(take(1), switchMap(() => {
|
|
1310
|
+
const token = store.selectSnapshot(AuthState.accessToken);
|
|
1311
|
+
return next(token ? req.clone({ setHeaders: { Authorization: `Bearer ${token}` } }) : req).pipe(catchError((err) => {
|
|
1312
|
+
if (!(err instanceof HttpErrorResponse) || err.status !== 401) return throwError(() => err);
|
|
1313
|
+
if (req.url.includes("/auth/refresh") || req.url.includes("/auth/login")) return throwError(() => err);
|
|
1314
|
+
const refreshToken = store.selectSnapshot(AuthState.refreshToken);
|
|
1315
|
+
if (!refreshToken) {
|
|
1316
|
+
store.dispatch(new Logout());
|
|
1317
|
+
if (router.navigated) router.navigate(["/login"]);
|
|
1318
|
+
return throwError(() => err);
|
|
1319
|
+
}
|
|
1320
|
+
return coordinator.refresh(refreshToken, token).pipe(switchMap((newToken) => next(req.clone({ setHeaders: { Authorization: `Bearer ${newToken}` } }))));
|
|
1321
|
+
}));
|
|
1322
|
+
}));
|
|
1323
|
+
};
|
|
1324
|
+
const STORAGE_KEY = "coolms_token";
|
|
1325
|
+
var CrossTabAuthSyncService = class CrossTabAuthSyncService {
|
|
1326
|
+
store = inject(Store);
|
|
1327
|
+
listenerAttached = false;
|
|
1328
|
+
start() {
|
|
1329
|
+
if (this.listenerAttached) return;
|
|
1330
|
+
this.listenerAttached = true;
|
|
1331
|
+
window.addEventListener("storage", this.handleStorageEvent);
|
|
1332
|
+
}
|
|
1333
|
+
handleStorageEvent = (event) => {
|
|
1334
|
+
if (event.key !== STORAGE_KEY) return;
|
|
1335
|
+
if (event.newValue === null) {
|
|
1336
|
+
this.store.dispatch(new Logout());
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
let parsed;
|
|
1340
|
+
try {
|
|
1341
|
+
parsed = JSON.parse(event.newValue);
|
|
1342
|
+
} catch {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
if (typeof parsed.accessToken !== "string" || typeof parsed.refreshToken !== "string" || typeof parsed.expiresAt !== "string") return;
|
|
1346
|
+
const tokenResponse = {
|
|
1347
|
+
accessToken: parsed.accessToken,
|
|
1348
|
+
refreshToken: parsed.refreshToken,
|
|
1349
|
+
expiresAt: parsed.expiresAt,
|
|
1350
|
+
user: parsed.user ?? void 0
|
|
1351
|
+
};
|
|
1352
|
+
this.store.dispatch(new SetTokens(tokenResponse));
|
|
1353
|
+
};
|
|
1354
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1355
|
+
minVersion: "12.0.0",
|
|
1356
|
+
version: "22.2.3",
|
|
1357
|
+
ngImport: i0,
|
|
1358
|
+
type: CrossTabAuthSyncService,
|
|
1359
|
+
deps: [],
|
|
1360
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1361
|
+
});
|
|
1362
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1363
|
+
minVersion: "12.0.0",
|
|
1364
|
+
version: "22.2.3",
|
|
1365
|
+
ngImport: i0,
|
|
1366
|
+
type: CrossTabAuthSyncService,
|
|
1367
|
+
providedIn: "root"
|
|
1368
|
+
});
|
|
1369
|
+
};
|
|
1370
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1371
|
+
minVersion: "12.0.0",
|
|
1372
|
+
version: "22.2.3",
|
|
1373
|
+
ngImport: i0,
|
|
1374
|
+
type: CrossTabAuthSyncService,
|
|
1375
|
+
decorators: [{
|
|
1376
|
+
type: Injectable,
|
|
1377
|
+
args: [{ providedIn: "root" }]
|
|
1378
|
+
}]
|
|
1379
|
+
});
|
|
1380
|
+
var AppInitService = class AppInitService {
|
|
1381
|
+
http = inject(HttpClient);
|
|
1382
|
+
store = inject(Store);
|
|
1383
|
+
router = inject(Router);
|
|
1384
|
+
location = inject(Location);
|
|
1385
|
+
prefs = inject(UserPreferencesService);
|
|
1386
|
+
crossTabSync = inject(CrossTabAuthSyncService);
|
|
1387
|
+
refreshCoordinator = inject(AuthRefreshCoordinator);
|
|
1388
|
+
configUrl = "/api/v1/theme/config";
|
|
1389
|
+
initComplete = new ReplaySubject(1);
|
|
1390
|
+
ready$ = this.initComplete.asObservable();
|
|
1391
|
+
async load() {
|
|
1392
|
+
this.crossTabSync.start();
|
|
1393
|
+
await firstValueFrom(this.store.dispatch(new RestoreSession()));
|
|
1394
|
+
const meUrl = (await firstValueFrom(this.http.get(this.configUrl, { context: new HttpContext().set(BYPASS_AUTH, true) }).pipe(tap((cfg) => this.store.dispatch(new SetAppConfig(cfg))), catchError(() => {
|
|
1395
|
+
console.warn("CoolMS: theme/config unreachable, using safe defaults");
|
|
1396
|
+
return of(null);
|
|
1397
|
+
}))))?.manifest.identity?.meUrl;
|
|
1398
|
+
if (meUrl && this.store.selectSnapshot(AuthState.isAuthenticated)) await this.validateSession(meUrl);
|
|
1399
|
+
this.initComplete.next();
|
|
1400
|
+
this.initComplete.complete();
|
|
1401
|
+
if (this.store.selectSnapshot(AuthState.isAuthenticated)) {
|
|
1402
|
+
const requested = this.location.path();
|
|
1403
|
+
if (requested === "" || requested === "/") {
|
|
1404
|
+
const saved = this.prefs.getPageState("nav");
|
|
1405
|
+
if (saved?.lastRoute && !saved.lastRoute.startsWith("/login")) this.router.navigateByUrl(saved.lastRoute);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
async validateSession(meUrl) {
|
|
1410
|
+
const token = this.store.selectSnapshot(AuthState.accessToken);
|
|
1411
|
+
const first = await this.probe(meUrl, token);
|
|
1412
|
+
if (true === first || !sessionEndsOn(first)) return;
|
|
1413
|
+
const refreshToken = this.store.selectSnapshot(AuthState.refreshToken);
|
|
1414
|
+
if (!refreshToken) {
|
|
1415
|
+
this.store.dispatch(new Logout());
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
let refreshedToken = null;
|
|
1419
|
+
try {
|
|
1420
|
+
refreshedToken = await firstValueFrom(this.refreshCoordinator.refresh(refreshToken, token));
|
|
1421
|
+
} catch {
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const again = await this.probe(meUrl, refreshedToken);
|
|
1425
|
+
if (true !== again && sessionEndsOn(again)) this.store.dispatch(new Logout());
|
|
1426
|
+
}
|
|
1427
|
+
probe(url, token) {
|
|
1428
|
+
return firstValueFrom(this.http.get(url, {
|
|
1429
|
+
context: new HttpContext().set(BYPASS_AUTH, true),
|
|
1430
|
+
headers: token ? { Authorization: `Bearer ${token}` } : {}
|
|
1431
|
+
}).pipe(tap((me) => {
|
|
1432
|
+
const uiPrefs = me?.uiPrefs;
|
|
1433
|
+
if (uiPrefs !== null && typeof uiPrefs === "object" && !Array.isArray(uiPrefs)) this.prefs.loadFromServer(uiPrefs);
|
|
1434
|
+
}), map(() => true), catchError((error) => of(error))));
|
|
1435
|
+
}
|
|
1436
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1437
|
+
minVersion: "12.0.0",
|
|
1438
|
+
version: "22.2.3",
|
|
1439
|
+
ngImport: i0,
|
|
1440
|
+
type: AppInitService,
|
|
1441
|
+
deps: [],
|
|
1442
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1443
|
+
});
|
|
1444
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1445
|
+
minVersion: "12.0.0",
|
|
1446
|
+
version: "22.2.3",
|
|
1447
|
+
ngImport: i0,
|
|
1448
|
+
type: AppInitService,
|
|
1449
|
+
providedIn: "root"
|
|
1450
|
+
});
|
|
1451
|
+
};
|
|
1452
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1453
|
+
minVersion: "12.0.0",
|
|
1454
|
+
version: "22.2.3",
|
|
1455
|
+
ngImport: i0,
|
|
1456
|
+
type: AppInitService,
|
|
1457
|
+
decorators: [{
|
|
1458
|
+
type: Injectable,
|
|
1459
|
+
args: [{ providedIn: "root" }]
|
|
1460
|
+
}]
|
|
1461
|
+
});
|
|
1462
|
+
const authGuard = () => {
|
|
1463
|
+
const init = inject(AppInitService);
|
|
1464
|
+
const store = inject(Store);
|
|
1465
|
+
const router = inject(Router);
|
|
1466
|
+
const consoleAccess = inject(ConsoleAccessService);
|
|
1467
|
+
return init.ready$.pipe(take(1), switchMap(() => {
|
|
1468
|
+
if (!store.selectSnapshot(AuthState.isAuthenticated)) return of(router.createUrlTree(["/login"]));
|
|
1469
|
+
return from(consoleAccess.ensure()).pipe(switchMap((access) => {
|
|
1470
|
+
if (!store.selectSnapshot(AuthState.isAuthenticated)) return of(router.createUrlTree(["/login"]));
|
|
1471
|
+
if ("refused" !== access && "sign-in-again" !== access) return of(true);
|
|
1472
|
+
const reason = "refused" === access ? ConsoleAccessService.REFUSED_REASON : ConsoleAccessService.SIGN_IN_AGAIN_REASON;
|
|
1473
|
+
return consoleAccess.signOut().pipe(map(() => router.createUrlTree(["/login"], { queryParams: { reason } })));
|
|
1474
|
+
}));
|
|
1475
|
+
}));
|
|
1476
|
+
};
|
|
1477
|
+
const loginPageGuard = () => {
|
|
1478
|
+
const init = inject(AppInitService);
|
|
1479
|
+
const store = inject(Store);
|
|
1480
|
+
const router = inject(Router);
|
|
1481
|
+
return init.ready$.pipe(take(1), map(() => {
|
|
1482
|
+
if (store.selectSnapshot(AuthState.isAuthenticated)) return router.createUrlTree(["/"]);
|
|
1483
|
+
return true;
|
|
1484
|
+
}));
|
|
1485
|
+
};
|
|
1486
|
+
const ELEVATION_WARNING_PASSWORD_NOT_SET = "elevation.password_not_set";
|
|
1487
|
+
const ELEVATION_WARNING_FACTOR_MISSING = "elevation.factor_missing";
|
|
1488
|
+
const ELEVATION_WARNING_MFA_OFF = "elevation.mfa_off";
|
|
1489
|
+
const READS = /* @__PURE__ */ new Set([
|
|
1490
|
+
"GET",
|
|
1491
|
+
"HEAD",
|
|
1492
|
+
"OPTIONS"
|
|
1493
|
+
]);
|
|
1494
|
+
const elevationInterceptor = (req, next) => {
|
|
1495
|
+
const elevation = inject(ElevationService);
|
|
1496
|
+
if (req.context.get(BYPASS_ELEVATION) || req.context.get(BACKGROUND_REQUEST) || READS.has(req.method.toUpperCase()) || !elevation.isThisApi(req.url)) return next(req);
|
|
1497
|
+
const notice = inject(ELEVATION_NOTICE, { optional: true });
|
|
1498
|
+
const errors = inject(ErrorHandlerService);
|
|
1499
|
+
return next(req).pipe(catchError((err) => {
|
|
1500
|
+
if (!isElevationRefusal(err)) return throwError(() => err);
|
|
1501
|
+
const refusal = errors.humanize(err);
|
|
1502
|
+
const action = actionOf(req, elevation.apiBase);
|
|
1503
|
+
const decline = () => {
|
|
1504
|
+
notice?.refused(refusal, action);
|
|
1505
|
+
return throwError(() => err);
|
|
1506
|
+
};
|
|
1507
|
+
if (!elevation.canPrompt) return decline();
|
|
1508
|
+
const release = elevation.holdForRetry();
|
|
1509
|
+
return elevation.refresh().pipe(switchMap((state) => state.elevated ? of(true) : elevation.requestElevation({
|
|
1510
|
+
state,
|
|
1511
|
+
refusal,
|
|
1512
|
+
action
|
|
1513
|
+
})), catchError(() => of(false)), switchMap((granted) => granted ? next(req) : decline()), finalize(release));
|
|
1514
|
+
}));
|
|
1515
|
+
};
|
|
1516
|
+
function actionOf(req, apiBase = "/api/v1") {
|
|
1517
|
+
const named = req.context.get(ELEVATION_ACTION);
|
|
1518
|
+
if (named) return named;
|
|
1519
|
+
const verb = {
|
|
1520
|
+
POST: "Creating",
|
|
1521
|
+
PUT: "Saving",
|
|
1522
|
+
PATCH: "Saving",
|
|
1523
|
+
DELETE: "Deleting"
|
|
1524
|
+
}[req.method.toUpperCase()] ?? "This change";
|
|
1525
|
+
let path = req.url.split("?")[0];
|
|
1526
|
+
try {
|
|
1527
|
+
path = new URL(path, "http://x").pathname;
|
|
1528
|
+
} catch {}
|
|
1529
|
+
if (path.startsWith(apiBase)) path = path.slice(apiBase.length);
|
|
1530
|
+
const words = path.split("/").filter((s) => s !== "" && !/^[0-9a-f-]{8,}$/i.test(s) && !/^\d+$/.test(s)).map((s) => s.replace(/[-_]/g, " "));
|
|
1531
|
+
return words.length === 0 ? verb : `${verb} ${words.join(" ")}`;
|
|
1532
|
+
}
|
|
1533
|
+
var LoginComponent = class LoginComponent {
|
|
1534
|
+
identifier = "";
|
|
1535
|
+
password = "";
|
|
1536
|
+
loading = signal(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
|
|
1537
|
+
error = signal(null, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
|
|
1538
|
+
store = inject(Store);
|
|
1539
|
+
router = inject(Router);
|
|
1540
|
+
static NO_CONSOLE_ACCESS = "This account may not enter the admin.";
|
|
1541
|
+
static SIGN_IN_AGAIN = "Please sign in again.";
|
|
1542
|
+
constructor() {
|
|
1543
|
+
inject(ActivatedRoute).queryParamMap.pipe(takeUntilDestroyed()).subscribe((params) => {
|
|
1544
|
+
const reason = params.get("reason");
|
|
1545
|
+
if (ConsoleAccessService.REFUSED_REASON === reason) {
|
|
1546
|
+
this.loading.set(false);
|
|
1547
|
+
this.error.set(LoginComponent.NO_CONSOLE_ACCESS);
|
|
1548
|
+
} else if (ConsoleAccessService.SIGN_IN_AGAIN_REASON === reason) {
|
|
1549
|
+
this.loading.set(false);
|
|
1550
|
+
this.error.set(LoginComponent.SIGN_IN_AGAIN);
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
submit() {
|
|
1555
|
+
if (!this.identifier || !this.password) return;
|
|
1556
|
+
this.loading.set(true);
|
|
1557
|
+
this.error.set(null);
|
|
1558
|
+
this.store.dispatch(new Login(this.identifier, this.password)).subscribe({
|
|
1559
|
+
next: () => {
|
|
1560
|
+
this.router.navigate(["/"]).catch(() => {
|
|
1561
|
+
this.loading.set(false);
|
|
1562
|
+
this.error.set("Signed in, but the admin could not be opened. Please reload.");
|
|
1563
|
+
});
|
|
1564
|
+
},
|
|
1565
|
+
error: (err) => {
|
|
1566
|
+
this.loading.set(false);
|
|
1567
|
+
if ("not-granted" === audienceRefusalOf(err)) {
|
|
1568
|
+
this.error.set(LoginComponent.NO_CONSOLE_ACCESS);
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
this.error.set(err?.error?.detail ?? err?.error?.message ?? err?.message ?? "Invalid credentials. Please try again.");
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1576
|
+
minVersion: "12.0.0",
|
|
1577
|
+
version: "22.2.3",
|
|
1578
|
+
ngImport: i0,
|
|
1579
|
+
type: LoginComponent,
|
|
1580
|
+
deps: [],
|
|
1581
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
1582
|
+
});
|
|
1583
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
1584
|
+
minVersion: "14.0.0",
|
|
1585
|
+
version: "22.2.3",
|
|
1586
|
+
type: LoginComponent,
|
|
1587
|
+
isStandalone: true,
|
|
1588
|
+
selector: "coolms-admin-login",
|
|
1589
|
+
ngImport: i0,
|
|
1590
|
+
template: "<div class=\"d-flex align-items-center justify-content-center min-vh-100 bg-light\">\n <div class=\"card shadow-sm\" style=\"width: 360px\">\n <div class=\"card-body p-4\">\n <h1 class=\"h5 mb-1\">CoolMS Admin</h1>\n <p class=\"text-muted small mb-4\">Sign in to continue</p>\n\n <div *ngIf=\"error()\" class=\"alert alert-danger py-2 small\">{{ error() }}</div>\n\n <form (ngSubmit)=\"submit()\" #loginForm=\"ngForm\">\n <div class=\"mb-3\">\n <label class=\"form-label\">Email or username</label>\n <input\n type=\"text\"\n class=\"form-control\"\n [(ngModel)]=\"identifier\"\n name=\"identifier\"\n required\n autocomplete=\"username\"\n />\n </div>\n <div class=\"mb-3\">\n <label class=\"form-label\">Password</label>\n <input\n type=\"password\"\n class=\"form-control\"\n [(ngModel)]=\"password\"\n name=\"password\"\n required\n autocomplete=\"current-password\"\n />\n </div>\n <button\n type=\"submit\"\n class=\"cms-btn cms-btn-primary w-100 justify-content-center\"\n [disabled]=\"loading() || loginForm.invalid\"\n >\n {{ loading() ? 'Signing in…' : 'Sign in' }}\n </button>\n </form>\n </div>\n </div>\n</div>\n",
|
|
1591
|
+
dependencies: [
|
|
1592
|
+
{
|
|
1593
|
+
kind: "ngmodule",
|
|
1594
|
+
type: FormsModule
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
kind: "directive",
|
|
1598
|
+
type: i1.ɵNgNoValidate,
|
|
1599
|
+
selector: "form:not([ngNoForm]):not([ngNativeValidate])"
|
|
1600
|
+
},
|
|
1601
|
+
{
|
|
1602
|
+
kind: "directive",
|
|
1603
|
+
type: i1.DefaultValueAccessor,
|
|
1604
|
+
selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
|
|
1605
|
+
},
|
|
1606
|
+
{
|
|
1607
|
+
kind: "directive",
|
|
1608
|
+
type: i1.NgControlStatus,
|
|
1609
|
+
selector: "[formControlName],[ngModel],[formControl]"
|
|
1610
|
+
},
|
|
1611
|
+
{
|
|
1612
|
+
kind: "directive",
|
|
1613
|
+
type: i1.NgControlStatusGroup,
|
|
1614
|
+
selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]"
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
kind: "directive",
|
|
1618
|
+
type: i1.RequiredValidator,
|
|
1619
|
+
selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]",
|
|
1620
|
+
inputs: ["required"]
|
|
1621
|
+
},
|
|
1622
|
+
{
|
|
1623
|
+
kind: "directive",
|
|
1624
|
+
type: i1.NgModel,
|
|
1625
|
+
selector: "[ngModel]:not([formControlName]):not([formControl])",
|
|
1626
|
+
inputs: [
|
|
1627
|
+
"name",
|
|
1628
|
+
"disabled",
|
|
1629
|
+
"ngModel",
|
|
1630
|
+
"ngModelOptions"
|
|
1631
|
+
],
|
|
1632
|
+
outputs: ["ngModelChange"],
|
|
1633
|
+
exportAs: ["ngModel"]
|
|
1634
|
+
},
|
|
1635
|
+
{
|
|
1636
|
+
kind: "directive",
|
|
1637
|
+
type: i1.NgForm,
|
|
1638
|
+
selector: "form:not([ngNoForm]):not([formGroup]):not([formArray]),ng-form,[ngForm]",
|
|
1639
|
+
inputs: ["ngFormOptions"],
|
|
1640
|
+
outputs: ["ngSubmit"],
|
|
1641
|
+
exportAs: ["ngForm"]
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
kind: "directive",
|
|
1645
|
+
type: NgIf,
|
|
1646
|
+
selector: "[ngIf]",
|
|
1647
|
+
inputs: [
|
|
1648
|
+
"ngIf",
|
|
1649
|
+
"ngIfThen",
|
|
1650
|
+
"ngIfElse"
|
|
1651
|
+
]
|
|
1652
|
+
}
|
|
1653
|
+
]
|
|
1654
|
+
});
|
|
1655
|
+
};
|
|
1656
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1657
|
+
minVersion: "12.0.0",
|
|
1658
|
+
version: "22.2.3",
|
|
1659
|
+
ngImport: i0,
|
|
1660
|
+
type: LoginComponent,
|
|
1661
|
+
decorators: [{
|
|
1662
|
+
type: Component,
|
|
1663
|
+
args: [{
|
|
1664
|
+
selector: "coolms-admin-login",
|
|
1665
|
+
standalone: true,
|
|
1666
|
+
imports: [FormsModule, NgIf],
|
|
1667
|
+
template: "<div class=\"d-flex align-items-center justify-content-center min-vh-100 bg-light\">\n <div class=\"card shadow-sm\" style=\"width: 360px\">\n <div class=\"card-body p-4\">\n <h1 class=\"h5 mb-1\">CoolMS Admin</h1>\n <p class=\"text-muted small mb-4\">Sign in to continue</p>\n\n <div *ngIf=\"error()\" class=\"alert alert-danger py-2 small\">{{ error() }}</div>\n\n <form (ngSubmit)=\"submit()\" #loginForm=\"ngForm\">\n <div class=\"mb-3\">\n <label class=\"form-label\">Email or username</label>\n <input\n type=\"text\"\n class=\"form-control\"\n [(ngModel)]=\"identifier\"\n name=\"identifier\"\n required\n autocomplete=\"username\"\n />\n </div>\n <div class=\"mb-3\">\n <label class=\"form-label\">Password</label>\n <input\n type=\"password\"\n class=\"form-control\"\n [(ngModel)]=\"password\"\n name=\"password\"\n required\n autocomplete=\"current-password\"\n />\n </div>\n <button\n type=\"submit\"\n class=\"cms-btn cms-btn-primary w-100 justify-content-center\"\n [disabled]=\"loading() || loginForm.invalid\"\n >\n {{ loading() ? 'Signing in…' : 'Sign in' }}\n </button>\n </form>\n </div>\n </div>\n</div>\n"
|
|
1668
|
+
}]
|
|
1669
|
+
}],
|
|
1670
|
+
ctorParameters: () => []
|
|
1671
|
+
});
|
|
1672
|
+
var ConfigService = class ConfigService {
|
|
1673
|
+
http = inject(HttpClient);
|
|
1674
|
+
store = inject(Store);
|
|
1675
|
+
cache = /* @__PURE__ */ new Map();
|
|
1676
|
+
layout(id) {
|
|
1677
|
+
return this.fetch("layout", id);
|
|
1678
|
+
}
|
|
1679
|
+
dialog(id) {
|
|
1680
|
+
return this.fetch("dialog", id);
|
|
1681
|
+
}
|
|
1682
|
+
navigraph(slug) {
|
|
1683
|
+
return this.fetch("navigraph", slug);
|
|
1684
|
+
}
|
|
1685
|
+
form(id) {
|
|
1686
|
+
return this.fetch("form", id);
|
|
1687
|
+
}
|
|
1688
|
+
datagrid(id) {
|
|
1689
|
+
return this.fetch("datagrid", id);
|
|
1690
|
+
}
|
|
1691
|
+
fetch(type, id) {
|
|
1692
|
+
const key = `${type}/${id}`;
|
|
1693
|
+
if (!this.cache.has(key)) {
|
|
1694
|
+
const base = this.store.selectSnapshot(AppConfigState.manifest)?.configBase ?? "/api/v1/config";
|
|
1695
|
+
const obs = this.http.get(`${base}/${type}/${id}`).pipe(map((r) => r.data ?? r), catchError((err) => {
|
|
1696
|
+
this.cache.delete(key);
|
|
1697
|
+
return throwError(() => err);
|
|
1698
|
+
}), shareReplay(1));
|
|
1699
|
+
this.cache.set(key, obs);
|
|
1700
|
+
}
|
|
1701
|
+
return this.cache.get(key);
|
|
1702
|
+
}
|
|
1703
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1704
|
+
minVersion: "12.0.0",
|
|
1705
|
+
version: "22.2.3",
|
|
1706
|
+
ngImport: i0,
|
|
1707
|
+
type: ConfigService,
|
|
1708
|
+
deps: [],
|
|
1709
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1710
|
+
});
|
|
1711
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1712
|
+
minVersion: "12.0.0",
|
|
1713
|
+
version: "22.2.3",
|
|
1714
|
+
ngImport: i0,
|
|
1715
|
+
type: ConfigService,
|
|
1716
|
+
providedIn: "root"
|
|
1717
|
+
});
|
|
1718
|
+
};
|
|
1719
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1720
|
+
minVersion: "12.0.0",
|
|
1721
|
+
version: "22.2.3",
|
|
1722
|
+
ngImport: i0,
|
|
1723
|
+
type: ConfigService,
|
|
1724
|
+
decorators: [{
|
|
1725
|
+
type: Injectable,
|
|
1726
|
+
args: [{ providedIn: "root" }]
|
|
1727
|
+
}]
|
|
1728
|
+
});
|
|
1729
|
+
const CHOICES = [
|
|
1730
|
+
"light",
|
|
1731
|
+
"dark",
|
|
1732
|
+
"system"
|
|
1733
|
+
];
|
|
1734
|
+
const CACHE_KEY = "coolms_theme";
|
|
1735
|
+
const ACCENT_CACHE_KEY = "coolms_accent";
|
|
1736
|
+
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
1737
|
+
function isChoice(v) {
|
|
1738
|
+
return typeof v === "string" && CHOICES.includes(v);
|
|
1739
|
+
}
|
|
1740
|
+
function isAccent(v) {
|
|
1741
|
+
return typeof v === "string" && HEX.test(v);
|
|
1742
|
+
}
|
|
1743
|
+
var ThemeService = class ThemeService {
|
|
1744
|
+
api = inject(IdentityApiClient);
|
|
1745
|
+
store = inject(Store);
|
|
1746
|
+
_choice = signal(ThemeService.readCache(), ...ngDevMode ? [{ debugName: "_choice" }] : /* istanbul ignore next */ []);
|
|
1747
|
+
_systemDark = signal(false, ...ngDevMode ? [{ debugName: "_systemDark" }] : /* istanbul ignore next */ []);
|
|
1748
|
+
_userAccent = signal(ThemeService.readAccentCache(), ...ngDevMode ? [{ debugName: "_userAccent" }] : /* istanbul ignore next */ []);
|
|
1749
|
+
_platformAccent = signal(null, ...ngDevMode ? [{ debugName: "_platformAccent" }] : /* istanbul ignore next */ []);
|
|
1750
|
+
loadOnce$;
|
|
1751
|
+
choice = this._choice.asReadonly();
|
|
1752
|
+
userAccent = this._userAccent.asReadonly();
|
|
1753
|
+
platformAccent = this._platformAccent.asReadonly();
|
|
1754
|
+
accent = computed(() => this._userAccent() ?? this._platformAccent(), ...ngDevMode ? [{ debugName: "accent" }] : /* istanbul ignore next */ []);
|
|
1755
|
+
resolved = computed(() => {
|
|
1756
|
+
const c = this._choice();
|
|
1757
|
+
return c === "system" ? this._systemDark() ? "dark" : "light" : c;
|
|
1758
|
+
}, ...ngDevMode ? [{ debugName: "resolved" }] : /* istanbul ignore next */ []);
|
|
1759
|
+
constructor() {
|
|
1760
|
+
const mq = typeof window !== "undefined" && window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null;
|
|
1761
|
+
if (mq) {
|
|
1762
|
+
this._systemDark.set(mq.matches);
|
|
1763
|
+
mq.addEventListener("change", (e) => this._systemDark.set(e.matches));
|
|
1764
|
+
}
|
|
1765
|
+
effect(() => this.applyToDocument(this.resolved()));
|
|
1766
|
+
effect(() => this.applyAccent(this.accent()));
|
|
1767
|
+
}
|
|
1768
|
+
ensureLoaded() {
|
|
1769
|
+
if (this.loadOnce$) return this.loadOnce$;
|
|
1770
|
+
this.readPlatformAccent();
|
|
1771
|
+
this.loadOnce$ = this.api.getSettings().pipe(map$1((all) => {
|
|
1772
|
+
const appearance = all["appearance"];
|
|
1773
|
+
this.setAccent(isAccent(appearance?.["accentColor"]) ? appearance["accentColor"] : null);
|
|
1774
|
+
return isChoice(appearance?.["theme"]) ? appearance["theme"] : this._choice();
|
|
1775
|
+
}), tap$1((choice) => this.set(choice)), catchError$1(() => of(this._choice())), shareReplay$1({
|
|
1776
|
+
bufferSize: 1,
|
|
1777
|
+
refCount: false
|
|
1778
|
+
}));
|
|
1779
|
+
return this.loadOnce$;
|
|
1780
|
+
}
|
|
1781
|
+
update(value) {
|
|
1782
|
+
if (isChoice(value)) this.set(value);
|
|
1783
|
+
}
|
|
1784
|
+
updateAccent(value) {
|
|
1785
|
+
if (null === value || "" === value) this.setAccent(null);
|
|
1786
|
+
else if (isAccent(value)) this.setAccent(value);
|
|
1787
|
+
}
|
|
1788
|
+
set(choice) {
|
|
1789
|
+
this._choice.set(choice);
|
|
1790
|
+
try {
|
|
1791
|
+
localStorage.setItem(CACHE_KEY, choice);
|
|
1792
|
+
} catch {}
|
|
1793
|
+
}
|
|
1794
|
+
readPlatformAccent() {
|
|
1795
|
+
const value = this.store.selectSnapshot(AppConfigState.manifest)?.platformDefaults?.accentColor;
|
|
1796
|
+
this._platformAccent.set(isAccent(value) ? value : null);
|
|
1797
|
+
}
|
|
1798
|
+
setAccent(accent) {
|
|
1799
|
+
this._userAccent.set(accent);
|
|
1800
|
+
try {
|
|
1801
|
+
if (accent) localStorage.setItem(ACCENT_CACHE_KEY, accent);
|
|
1802
|
+
else localStorage.removeItem(ACCENT_CACHE_KEY);
|
|
1803
|
+
} catch {}
|
|
1804
|
+
}
|
|
1805
|
+
applyAccent(accent) {
|
|
1806
|
+
const root = document.documentElement;
|
|
1807
|
+
if (accent && HEX.test(accent)) root.style.setProperty("--cms-accent", accent);
|
|
1808
|
+
else root.style.removeProperty("--cms-accent");
|
|
1809
|
+
}
|
|
1810
|
+
applyToDocument(theme) {
|
|
1811
|
+
document.documentElement.setAttribute("data-theme", theme);
|
|
1812
|
+
}
|
|
1813
|
+
static readCache() {
|
|
1814
|
+
try {
|
|
1815
|
+
const raw = localStorage.getItem(CACHE_KEY);
|
|
1816
|
+
return isChoice(raw) ? raw : "system";
|
|
1817
|
+
} catch {
|
|
1818
|
+
return "system";
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
static readAccentCache() {
|
|
1822
|
+
try {
|
|
1823
|
+
const raw = localStorage.getItem(ACCENT_CACHE_KEY);
|
|
1824
|
+
return isAccent(raw) ? raw : null;
|
|
1825
|
+
} catch {
|
|
1826
|
+
return null;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1830
|
+
minVersion: "12.0.0",
|
|
1831
|
+
version: "22.2.3",
|
|
1832
|
+
ngImport: i0,
|
|
1833
|
+
type: ThemeService,
|
|
1834
|
+
deps: [],
|
|
1835
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1836
|
+
});
|
|
1837
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1838
|
+
minVersion: "12.0.0",
|
|
1839
|
+
version: "22.2.3",
|
|
1840
|
+
ngImport: i0,
|
|
1841
|
+
type: ThemeService,
|
|
1842
|
+
providedIn: "root"
|
|
1843
|
+
});
|
|
1844
|
+
};
|
|
1845
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1846
|
+
minVersion: "12.0.0",
|
|
1847
|
+
version: "22.2.3",
|
|
1848
|
+
ngImport: i0,
|
|
1849
|
+
type: ThemeService,
|
|
1850
|
+
decorators: [{
|
|
1851
|
+
type: Injectable,
|
|
1852
|
+
args: [{ providedIn: "root" }]
|
|
1853
|
+
}],
|
|
1854
|
+
ctorParameters: () => []
|
|
1855
|
+
});
|
|
1856
|
+
var CmsLoaderComponent = class CmsLoaderComponent {
|
|
1857
|
+
label = input("", ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
1858
|
+
overlay = input(false, ...ngDevMode ? [{ debugName: "overlay" }] : /* istanbul ignore next */ []);
|
|
1859
|
+
inline = input(false, ...ngDevMode ? [{ debugName: "inline" }] : /* istanbul ignore next */ []);
|
|
1860
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1861
|
+
minVersion: "12.0.0",
|
|
1862
|
+
version: "22.2.3",
|
|
1863
|
+
ngImport: i0,
|
|
1864
|
+
type: CmsLoaderComponent,
|
|
1865
|
+
deps: [],
|
|
1866
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
1867
|
+
});
|
|
1868
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
1869
|
+
minVersion: "17.0.0",
|
|
1870
|
+
version: "22.2.3",
|
|
1871
|
+
type: CmsLoaderComponent,
|
|
1872
|
+
isStandalone: true,
|
|
1873
|
+
selector: "cms-loader",
|
|
1874
|
+
inputs: {
|
|
1875
|
+
label: {
|
|
1876
|
+
classPropertyName: "label",
|
|
1877
|
+
publicName: "label",
|
|
1878
|
+
isSignal: true,
|
|
1879
|
+
isRequired: false,
|
|
1880
|
+
transformFunction: null
|
|
1881
|
+
},
|
|
1882
|
+
overlay: {
|
|
1883
|
+
classPropertyName: "overlay",
|
|
1884
|
+
publicName: "overlay",
|
|
1885
|
+
isSignal: true,
|
|
1886
|
+
isRequired: false,
|
|
1887
|
+
transformFunction: null
|
|
1888
|
+
},
|
|
1889
|
+
inline: {
|
|
1890
|
+
classPropertyName: "inline",
|
|
1891
|
+
publicName: "inline",
|
|
1892
|
+
isSignal: true,
|
|
1893
|
+
isRequired: false,
|
|
1894
|
+
transformFunction: null
|
|
1895
|
+
}
|
|
1896
|
+
},
|
|
1897
|
+
ngImport: i0,
|
|
1898
|
+
template: `
|
|
1899
|
+
<div class="cms-loader"
|
|
1900
|
+
[class.cms-loader--overlay]="overlay()"
|
|
1901
|
+
[class.cms-loader--inline]="inline()"
|
|
1902
|
+
role="status"
|
|
1903
|
+
[attr.aria-label]="label() || 'Loading'">
|
|
1904
|
+
<span class="cms-loader__spinner" aria-hidden="true"></span>
|
|
1905
|
+
@if (label()) {
|
|
1906
|
+
<span class="cms-loader__label">{{ label() }}</span>
|
|
1907
|
+
}
|
|
1908
|
+
</div>
|
|
1909
|
+
`,
|
|
1910
|
+
isInline: true,
|
|
1911
|
+
styles: [".cms-loader{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:24px;color:var(--cms-text-muted)}.cms-loader--overlay{position:absolute;inset:0;z-index:5;background:var(--cms-surface)}.cms-loader--inline{flex-direction:row;gap:8px;padding:0}.cms-loader__spinner{box-sizing:border-box;width:var(--cms-loader-size, var(--cms-spinner-size-page, 32px));height:var(--cms-loader-size, var(--cms-spinner-size-page, 32px));border:var(--cms-spinner-stroke, 2px) solid var(--cms-spinner-track, var(--cms-border));border-top-color:var(--cms-spinner-color, var(--cms-accent-text));border-radius:50%;flex-shrink:0;animation:cms-loader-turn var(--cms-spinner-duration, .8s) linear infinite}.cms-loader--inline .cms-loader__spinner{width:var(--cms-loader-size, var(--cms-spinner-size-inline, 16px));height:var(--cms-loader-size, var(--cms-spinner-size-inline, 16px))}@keyframes cms-loader-turn{to{transform:rotate(360deg)}}.cms-loader__label{font-size:.8125rem}@media(prefers-reduced-motion:reduce){.cms-loader__spinner{animation:cms-loader-breathe 2s ease-in-out infinite}}@keyframes cms-loader-breathe{0%,to{opacity:.35}50%{opacity:1}}\n"],
|
|
1912
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
1913
|
+
});
|
|
1914
|
+
};
|
|
1915
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1916
|
+
minVersion: "12.0.0",
|
|
1917
|
+
version: "22.2.3",
|
|
1918
|
+
ngImport: i0,
|
|
1919
|
+
type: CmsLoaderComponent,
|
|
1920
|
+
decorators: [{
|
|
1921
|
+
type: Component,
|
|
1922
|
+
args: [{
|
|
1923
|
+
selector: "cms-loader",
|
|
1924
|
+
standalone: true,
|
|
1925
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
1926
|
+
template: `
|
|
1927
|
+
<div class="cms-loader"
|
|
1928
|
+
[class.cms-loader--overlay]="overlay()"
|
|
1929
|
+
[class.cms-loader--inline]="inline()"
|
|
1930
|
+
role="status"
|
|
1931
|
+
[attr.aria-label]="label() || 'Loading'">
|
|
1932
|
+
<span class="cms-loader__spinner" aria-hidden="true"></span>
|
|
1933
|
+
@if (label()) {
|
|
1934
|
+
<span class="cms-loader__label">{{ label() }}</span>
|
|
1935
|
+
}
|
|
1936
|
+
</div>
|
|
1937
|
+
`,
|
|
1938
|
+
styles: [".cms-loader{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:24px;color:var(--cms-text-muted)}.cms-loader--overlay{position:absolute;inset:0;z-index:5;background:var(--cms-surface)}.cms-loader--inline{flex-direction:row;gap:8px;padding:0}.cms-loader__spinner{box-sizing:border-box;width:var(--cms-loader-size, var(--cms-spinner-size-page, 32px));height:var(--cms-loader-size, var(--cms-spinner-size-page, 32px));border:var(--cms-spinner-stroke, 2px) solid var(--cms-spinner-track, var(--cms-border));border-top-color:var(--cms-spinner-color, var(--cms-accent-text));border-radius:50%;flex-shrink:0;animation:cms-loader-turn var(--cms-spinner-duration, .8s) linear infinite}.cms-loader--inline .cms-loader__spinner{width:var(--cms-loader-size, var(--cms-spinner-size-inline, 16px));height:var(--cms-loader-size, var(--cms-spinner-size-inline, 16px))}@keyframes cms-loader-turn{to{transform:rotate(360deg)}}.cms-loader__label{font-size:.8125rem}@media(prefers-reduced-motion:reduce){.cms-loader__spinner{animation:cms-loader-breathe 2s ease-in-out infinite}}@keyframes cms-loader-breathe{0%,to{opacity:.35}50%{opacity:1}}\n"]
|
|
1939
|
+
}]
|
|
1940
|
+
}],
|
|
1941
|
+
propDecorators: {
|
|
1942
|
+
label: [{
|
|
1943
|
+
type: i0.Input,
|
|
1944
|
+
args: [{
|
|
1945
|
+
isSignal: true,
|
|
1946
|
+
alias: "label",
|
|
1947
|
+
required: false
|
|
1948
|
+
}]
|
|
1949
|
+
}],
|
|
1950
|
+
overlay: [{
|
|
1951
|
+
type: i0.Input,
|
|
1952
|
+
args: [{
|
|
1953
|
+
isSignal: true,
|
|
1954
|
+
alias: "overlay",
|
|
1955
|
+
required: false
|
|
1956
|
+
}]
|
|
1957
|
+
}],
|
|
1958
|
+
inline: [{
|
|
1959
|
+
type: i0.Input,
|
|
1960
|
+
args: [{
|
|
1961
|
+
isSignal: true,
|
|
1962
|
+
alias: "inline",
|
|
1963
|
+
required: false
|
|
1964
|
+
}]
|
|
1965
|
+
}]
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
var SidebarStateService = class SidebarStateService {
|
|
1969
|
+
static STORAGE_KEY = "coolms.admin.sidebar.collapsed";
|
|
1970
|
+
static STORAGE_KEY_SECTIONS = "coolms.admin.sidebar.collapsedSections";
|
|
1971
|
+
static STORAGE_KEY_ITEMS = "coolms.admin.sidebar.collapsedItems";
|
|
1972
|
+
collapsed = signal(this.readPersisted(), ...ngDevMode ? [{ debugName: "collapsed" }] : /* istanbul ignore next */ []);
|
|
1973
|
+
collapsedSections = signal(this.readSectionsPersisted(), ...ngDevMode ? [{ debugName: "collapsedSections" }] : /* istanbul ignore next */ []);
|
|
1974
|
+
collapsedItems = signal(this.readItemsPersisted(), ...ngDevMode ? [{ debugName: "collapsedItems" }] : /* istanbul ignore next */ []);
|
|
1975
|
+
toggle() {
|
|
1976
|
+
const next = !this.collapsed();
|
|
1977
|
+
this.collapsed.set(next);
|
|
1978
|
+
this.persist(next);
|
|
1979
|
+
}
|
|
1980
|
+
isSectionCollapsed(id) {
|
|
1981
|
+
return this.collapsedSections().has(id);
|
|
1982
|
+
}
|
|
1983
|
+
toggleSection(id) {
|
|
1984
|
+
const next = new Set(this.collapsedSections());
|
|
1985
|
+
if (next.has(id)) next.delete(id);
|
|
1986
|
+
else next.add(id);
|
|
1987
|
+
this.collapsedSections.set(next);
|
|
1988
|
+
this.persistSections(next);
|
|
1989
|
+
}
|
|
1990
|
+
ensureExpanded(id) {
|
|
1991
|
+
if (!this.collapsedSections().has(id)) return;
|
|
1992
|
+
const next = new Set(this.collapsedSections());
|
|
1993
|
+
next.delete(id);
|
|
1994
|
+
this.collapsedSections.set(next);
|
|
1995
|
+
this.persistSections(next);
|
|
1996
|
+
}
|
|
1997
|
+
isItemCollapsed(id) {
|
|
1998
|
+
return this.collapsedItems().has(id);
|
|
1999
|
+
}
|
|
2000
|
+
toggleItem(id) {
|
|
2001
|
+
const next = new Set(this.collapsedItems());
|
|
2002
|
+
if (next.has(id)) next.delete(id);
|
|
2003
|
+
else next.add(id);
|
|
2004
|
+
this.collapsedItems.set(next);
|
|
2005
|
+
this.persistItems(next);
|
|
2006
|
+
}
|
|
2007
|
+
readPersisted() {
|
|
2008
|
+
try {
|
|
2009
|
+
return localStorage.getItem(SidebarStateService.STORAGE_KEY) === "true";
|
|
2010
|
+
} catch {
|
|
2011
|
+
return false;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
persist(value) {
|
|
2015
|
+
try {
|
|
2016
|
+
localStorage.setItem(SidebarStateService.STORAGE_KEY, String(value));
|
|
2017
|
+
} catch {}
|
|
2018
|
+
}
|
|
2019
|
+
readSectionsPersisted() {
|
|
2020
|
+
try {
|
|
2021
|
+
const raw = localStorage.getItem(SidebarStateService.STORAGE_KEY_SECTIONS);
|
|
2022
|
+
if (raw === null) return /* @__PURE__ */ new Set();
|
|
2023
|
+
const parsed = JSON.parse(raw);
|
|
2024
|
+
if (!Array.isArray(parsed)) return /* @__PURE__ */ new Set();
|
|
2025
|
+
return new Set(parsed.filter((v) => typeof v === "string"));
|
|
2026
|
+
} catch {
|
|
2027
|
+
return /* @__PURE__ */ new Set();
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
persistSections(value) {
|
|
2031
|
+
try {
|
|
2032
|
+
localStorage.setItem(SidebarStateService.STORAGE_KEY_SECTIONS, JSON.stringify(Array.from(value)));
|
|
2033
|
+
} catch {}
|
|
2034
|
+
}
|
|
2035
|
+
readItemsPersisted() {
|
|
2036
|
+
try {
|
|
2037
|
+
const raw = localStorage.getItem(SidebarStateService.STORAGE_KEY_ITEMS);
|
|
2038
|
+
if (raw === null) return /* @__PURE__ */ new Set();
|
|
2039
|
+
const parsed = JSON.parse(raw);
|
|
2040
|
+
if (!Array.isArray(parsed)) return /* @__PURE__ */ new Set();
|
|
2041
|
+
return new Set(parsed.filter((v) => typeof v === "string"));
|
|
2042
|
+
} catch {
|
|
2043
|
+
return /* @__PURE__ */ new Set();
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
persistItems(value) {
|
|
2047
|
+
try {
|
|
2048
|
+
localStorage.setItem(SidebarStateService.STORAGE_KEY_ITEMS, JSON.stringify(Array.from(value)));
|
|
2049
|
+
} catch {}
|
|
2050
|
+
}
|
|
2051
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2052
|
+
minVersion: "12.0.0",
|
|
2053
|
+
version: "22.2.3",
|
|
2054
|
+
ngImport: i0,
|
|
2055
|
+
type: SidebarStateService,
|
|
2056
|
+
deps: [],
|
|
2057
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2058
|
+
});
|
|
2059
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2060
|
+
minVersion: "12.0.0",
|
|
2061
|
+
version: "22.2.3",
|
|
2062
|
+
ngImport: i0,
|
|
2063
|
+
type: SidebarStateService,
|
|
2064
|
+
providedIn: "root"
|
|
2065
|
+
});
|
|
2066
|
+
};
|
|
2067
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2068
|
+
minVersion: "12.0.0",
|
|
2069
|
+
version: "22.2.3",
|
|
2070
|
+
ngImport: i0,
|
|
2071
|
+
type: SidebarStateService,
|
|
2072
|
+
decorators: [{
|
|
2073
|
+
type: Injectable,
|
|
2074
|
+
args: [{ providedIn: "root" }]
|
|
2075
|
+
}]
|
|
2076
|
+
});
|
|
2077
|
+
var EntitySearchService = class EntitySearchService {
|
|
2078
|
+
http = inject(HttpClient);
|
|
2079
|
+
search(entityType, query, limit = 20) {
|
|
2080
|
+
const params = new HttpParams().set("type", entityType).set("q", query).set("limit", String(limit));
|
|
2081
|
+
return this.http.get("/api/entity-search", { params });
|
|
2082
|
+
}
|
|
2083
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2084
|
+
minVersion: "12.0.0",
|
|
2085
|
+
version: "22.2.3",
|
|
2086
|
+
ngImport: i0,
|
|
2087
|
+
type: EntitySearchService,
|
|
2088
|
+
deps: [],
|
|
2089
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2090
|
+
});
|
|
2091
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2092
|
+
minVersion: "12.0.0",
|
|
2093
|
+
version: "22.2.3",
|
|
2094
|
+
ngImport: i0,
|
|
2095
|
+
type: EntitySearchService,
|
|
2096
|
+
providedIn: "root"
|
|
2097
|
+
});
|
|
2098
|
+
};
|
|
2099
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2100
|
+
minVersion: "12.0.0",
|
|
2101
|
+
version: "22.2.3",
|
|
2102
|
+
ngImport: i0,
|
|
2103
|
+
type: EntitySearchService,
|
|
2104
|
+
decorators: [{
|
|
2105
|
+
type: Injectable,
|
|
2106
|
+
args: [{ providedIn: "root" }]
|
|
2107
|
+
}]
|
|
2108
|
+
});
|
|
2109
|
+
var NaviGraphService = class NaviGraphService {
|
|
2110
|
+
http = inject(HttpClient);
|
|
2111
|
+
router = inject(Router);
|
|
2112
|
+
store = inject(Store);
|
|
2113
|
+
errors = inject(ErrorHandlerService);
|
|
2114
|
+
adminNav = signal([], ...ngDevMode ? [{ debugName: "adminNav" }] : /* istanbul ignore next */ []);
|
|
2115
|
+
topbarNav = signal([], ...ngDevMode ? [{ debugName: "topbarNav" }] : /* istanbul ignore next */ []);
|
|
2116
|
+
cache = /* @__PURE__ */ new Map();
|
|
2117
|
+
loadAdminNav(url, options = {}) {
|
|
2118
|
+
return this.loadTree(url, options.fresh ?? false).pipe(map((tree) => {
|
|
2119
|
+
this.adminNav.set(tree);
|
|
2120
|
+
return tree;
|
|
2121
|
+
}));
|
|
2122
|
+
}
|
|
2123
|
+
loadTopbarNav(url) {
|
|
2124
|
+
return this.loadTree(url).pipe(map((tree) => {
|
|
2125
|
+
this.topbarNav.set(tree);
|
|
2126
|
+
return tree;
|
|
2127
|
+
}));
|
|
2128
|
+
}
|
|
2129
|
+
handleClick(node) {
|
|
2130
|
+
const target = node.meta.target;
|
|
2131
|
+
if (target === "action.logout") {
|
|
2132
|
+
this.store.dispatch(new Logout()).subscribe(() => {
|
|
2133
|
+
this.router.navigate(["/login"]);
|
|
2134
|
+
});
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
if (target === "_blank") {
|
|
2138
|
+
window.open(node.meta.routerLink ?? node.path, "_blank", "noopener");
|
|
2139
|
+
return;
|
|
2140
|
+
}
|
|
2141
|
+
const link = node.meta.routerLink ?? node.path;
|
|
2142
|
+
this.router.navigate([link]);
|
|
2143
|
+
}
|
|
2144
|
+
isVisible(node, record) {
|
|
2145
|
+
const showWhen = node.meta["showWhen"];
|
|
2146
|
+
if (!showWhen) return true;
|
|
2147
|
+
return this.evalCondition(showWhen, record);
|
|
2148
|
+
}
|
|
2149
|
+
matchesShowWhen(showWhen, record) {
|
|
2150
|
+
if (!showWhen) return true;
|
|
2151
|
+
return this.evalCondition(showWhen, record);
|
|
2152
|
+
}
|
|
2153
|
+
isCondition(value) {
|
|
2154
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2155
|
+
}
|
|
2156
|
+
evalCondition(cond, record) {
|
|
2157
|
+
if ("and" in cond) {
|
|
2158
|
+
const parts = cond["and"];
|
|
2159
|
+
return Array.isArray(parts) && parts.every((c) => this.isCondition(c) && this.evalCondition(c, record));
|
|
2160
|
+
}
|
|
2161
|
+
if ("or" in cond) {
|
|
2162
|
+
const parts = cond["or"];
|
|
2163
|
+
return Array.isArray(parts) && parts.some((c) => this.isCondition(c) && this.evalCondition(c, record));
|
|
2164
|
+
}
|
|
2165
|
+
const field = cond["field"];
|
|
2166
|
+
if (!(field in record)) return false;
|
|
2167
|
+
const val = record[field];
|
|
2168
|
+
switch (cond["op"]) {
|
|
2169
|
+
case "eq": return val === cond["value"];
|
|
2170
|
+
case "ne": return val !== cond["value"];
|
|
2171
|
+
case "in": return Array.isArray(cond["value"]) && cond["value"].includes(val);
|
|
2172
|
+
case "nin": return Array.isArray(cond["value"]) && !cond["value"].includes(val);
|
|
2173
|
+
case "cn": return Array.isArray(val) && val.some((item) => item === cond["value"]);
|
|
2174
|
+
case "startsWith": return typeof val === "string" && typeof cond["value"] === "string" && val.startsWith(cond["value"]);
|
|
2175
|
+
default: return false;
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
loadTree(url, fresh = false) {
|
|
2179
|
+
if (!fresh && this.cache.has(url)) return of(this.cache.get(url));
|
|
2180
|
+
return this.http.get(url, { headers: { Accept: "application/ld+json" } }).pipe(map((r) => {
|
|
2181
|
+
const raw = r["member"] ?? r["hydra:member"] ?? [];
|
|
2182
|
+
const flat = Array.isArray(raw) ? raw : [];
|
|
2183
|
+
const tree = this.buildTree(flat);
|
|
2184
|
+
this.cache.set(url, tree);
|
|
2185
|
+
return tree;
|
|
2186
|
+
}), catchError((err) => {
|
|
2187
|
+
console.error("[NaviGraph] loadTree failed for", url, this.errors.humanize(err));
|
|
2188
|
+
return of(this.cache.get(url) ?? []);
|
|
2189
|
+
}));
|
|
2190
|
+
}
|
|
2191
|
+
buildTree(flat) {
|
|
2192
|
+
if (!flat.length) return [];
|
|
2193
|
+
const map = new Map(flat.map((n) => [n.id, {
|
|
2194
|
+
...n,
|
|
2195
|
+
children: []
|
|
2196
|
+
}]));
|
|
2197
|
+
const roots = [];
|
|
2198
|
+
for (const node of map.values()) if (node.parentId && map.has(node.parentId)) map.get(node.parentId).children.push(node);
|
|
2199
|
+
else roots.push(node);
|
|
2200
|
+
const sort = (nodes) => {
|
|
2201
|
+
nodes.sort((a, b) => a.sortOrder - b.sortOrder);
|
|
2202
|
+
nodes.forEach((n) => n.children?.length && sort(n.children));
|
|
2203
|
+
};
|
|
2204
|
+
sort(roots);
|
|
2205
|
+
return roots;
|
|
2206
|
+
}
|
|
2207
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2208
|
+
minVersion: "12.0.0",
|
|
2209
|
+
version: "22.2.3",
|
|
2210
|
+
ngImport: i0,
|
|
2211
|
+
type: NaviGraphService,
|
|
2212
|
+
deps: [],
|
|
2213
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2214
|
+
});
|
|
2215
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2216
|
+
minVersion: "12.0.0",
|
|
2217
|
+
version: "22.2.3",
|
|
2218
|
+
ngImport: i0,
|
|
2219
|
+
type: NaviGraphService,
|
|
2220
|
+
providedIn: "root"
|
|
2221
|
+
});
|
|
2222
|
+
};
|
|
2223
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2224
|
+
minVersion: "12.0.0",
|
|
2225
|
+
version: "22.2.3",
|
|
2226
|
+
ngImport: i0,
|
|
2227
|
+
type: NaviGraphService,
|
|
2228
|
+
decorators: [{
|
|
2229
|
+
type: Injectable,
|
|
2230
|
+
args: [{ providedIn: "root" }]
|
|
2231
|
+
}]
|
|
2232
|
+
});
|
|
2233
|
+
function naviAccessOf(node) {
|
|
2234
|
+
return node.access === "elevate" ? "elevate" : "allowed";
|
|
2235
|
+
}
|
|
2236
|
+
var ComponentRegistry = class ComponentRegistry {
|
|
2237
|
+
static map = /* @__PURE__ */ new Map();
|
|
2238
|
+
static register(key, component) {
|
|
2239
|
+
ComponentRegistry.map.set(key, component);
|
|
2240
|
+
}
|
|
2241
|
+
static get(key) {
|
|
2242
|
+
return ComponentRegistry.map.get(key);
|
|
2243
|
+
}
|
|
2244
|
+
static has(key) {
|
|
2245
|
+
return ComponentRegistry.map.has(key);
|
|
2246
|
+
}
|
|
2247
|
+
static keys() {
|
|
2248
|
+
return Array.from(ComponentRegistry.map.keys());
|
|
2249
|
+
}
|
|
2250
|
+
register(key, component) {
|
|
2251
|
+
ComponentRegistry.register(key, component);
|
|
2252
|
+
}
|
|
2253
|
+
get(key) {
|
|
2254
|
+
return ComponentRegistry.get(key) ?? null;
|
|
2255
|
+
}
|
|
2256
|
+
has(key) {
|
|
2257
|
+
return ComponentRegistry.has(key);
|
|
2258
|
+
}
|
|
2259
|
+
keys() {
|
|
2260
|
+
return ComponentRegistry.keys();
|
|
2261
|
+
}
|
|
2262
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2263
|
+
minVersion: "12.0.0",
|
|
2264
|
+
version: "22.2.3",
|
|
2265
|
+
ngImport: i0,
|
|
2266
|
+
type: ComponentRegistry,
|
|
2267
|
+
deps: [],
|
|
2268
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2269
|
+
});
|
|
2270
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2271
|
+
minVersion: "12.0.0",
|
|
2272
|
+
version: "22.2.3",
|
|
2273
|
+
ngImport: i0,
|
|
2274
|
+
type: ComponentRegistry,
|
|
2275
|
+
providedIn: "root"
|
|
2276
|
+
});
|
|
2277
|
+
};
|
|
2278
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2279
|
+
minVersion: "12.0.0",
|
|
2280
|
+
version: "22.2.3",
|
|
2281
|
+
ngImport: i0,
|
|
2282
|
+
type: ComponentRegistry,
|
|
2283
|
+
decorators: [{
|
|
2284
|
+
type: Injectable,
|
|
2285
|
+
args: [{ providedIn: "root" }]
|
|
2286
|
+
}]
|
|
2287
|
+
});
|
|
2288
|
+
const CONSOLE_CONTRACT = {
|
|
2289
|
+
name: "console",
|
|
2290
|
+
version: "1.0"
|
|
2291
|
+
};
|
|
2292
|
+
function isPortProvision(p) {
|
|
2293
|
+
return typeof p === "object" && "port" in p && "useExisting" in p;
|
|
2294
|
+
}
|
|
2295
|
+
function consoleEntry(entry) {
|
|
2296
|
+
return entry;
|
|
2297
|
+
}
|
|
2298
|
+
const VERSION = /^(\d+)\.(\d+)$/;
|
|
2299
|
+
const RANGE = /^\^(\d+)\.(\d+)$/;
|
|
2300
|
+
function satisfiesRange(range, version) {
|
|
2301
|
+
const r = RANGE.exec(range);
|
|
2302
|
+
const v = VERSION.exec(version);
|
|
2303
|
+
if (!r || !v) return false;
|
|
2304
|
+
return Number(r[1]) === Number(v[1]) && Number(v[2]) >= Number(r[2]);
|
|
2305
|
+
}
|
|
2306
|
+
var ConsoleAssemblyError = class extends Error {
|
|
2307
|
+
problems;
|
|
2308
|
+
constructor(problems) {
|
|
2309
|
+
super(`console assembly refused:\n ${problems.join("\n ")}`);
|
|
2310
|
+
this.problems = problems;
|
|
2311
|
+
this.name = "ConsoleAssemblyError";
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
function assembleConsole(entries) {
|
|
2315
|
+
const problems = [];
|
|
2316
|
+
const seenModules = /* @__PURE__ */ new Map();
|
|
2317
|
+
const paths = /* @__PURE__ */ new Map();
|
|
2318
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
2319
|
+
const topbar = /* @__PURE__ */ new Map();
|
|
2320
|
+
const overlays = /* @__PURE__ */ new Map();
|
|
2321
|
+
const panels = /* @__PURE__ */ new Map();
|
|
2322
|
+
const states = /* @__PURE__ */ new Map();
|
|
2323
|
+
const ports = /* @__PURE__ */ new Map();
|
|
2324
|
+
const claim = (map, key, owner, what) => {
|
|
2325
|
+
const prev = map.get(key);
|
|
2326
|
+
if (prev !== void 0 && prev !== owner) problems.push(`${what} '${String(key)}' is claimed by modules '${prev}' and '${owner}'`);
|
|
2327
|
+
else map.set(key, owner);
|
|
2328
|
+
};
|
|
2329
|
+
for (const e of entries) {
|
|
2330
|
+
if (!satisfiesRange(e.range, CONSOLE_CONTRACT.version)) problems.push(`module '${e.module}' offers console ${e.range}; this host implements console ${CONSOLE_CONTRACT.version} -- refused`);
|
|
2331
|
+
seenModules.set(e.module, (seenModules.get(e.module) ?? 0) + 1);
|
|
2332
|
+
for (const r of e.routes ?? []) claim(paths, r.path, e.module, "route path");
|
|
2333
|
+
for (const b of e.bindings ?? []) claim(bindings, b.name, e.module, "binding");
|
|
2334
|
+
for (const t of e.topbar ?? []) claim(topbar, t.id, e.module, "top-bar item");
|
|
2335
|
+
for (const o of e.overlays ?? []) claim(overlays, o.id, e.module, "overlay");
|
|
2336
|
+
for (const p of e.panels ?? []) claim(panels, p.id, e.module, "panel");
|
|
2337
|
+
for (const s of e.states ?? []) claim(states, s, e.module, "state");
|
|
2338
|
+
for (const p of e.providers ?? []) if (isPortProvision(p)) claim(ports, p.port, e.module, "port");
|
|
2339
|
+
}
|
|
2340
|
+
for (const [module, n] of seenModules) if (n > 1) problems.push(`module '${module}' has ${n} entries; one entry per module`);
|
|
2341
|
+
if (problems.length) throw new ConsoleAssemblyError(problems);
|
|
2342
|
+
return entries;
|
|
2343
|
+
}
|
|
2344
|
+
const CONSOLE_ENTRIES = new InjectionToken("coolms.console.entries");
|
|
2345
|
+
var ConsolePanelHost = class {};
|
|
2346
|
+
function installedConsoleModules(manifest) {
|
|
2347
|
+
return new Set((manifest?.ui?.modules ?? []).filter((m) => m.contract === CONSOLE_CONTRACT.name).map((m) => m.module));
|
|
2348
|
+
}
|
|
2349
|
+
var ConsoleActivation = class ConsoleActivation {
|
|
2350
|
+
entries = inject(CONSOLE_ENTRIES, { optional: true }) ?? [];
|
|
2351
|
+
manifest = inject(Store).selectSignal(AppConfigState.manifest);
|
|
2352
|
+
installed = computed(() => installedConsoleModules(this.manifest()), ...ngDevMode ? [{ debugName: "installed" }] : /* istanbul ignore next */ []);
|
|
2353
|
+
active = computed(() => this.entries.filter((e) => this.installed().has(e.module)), ...ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []);
|
|
2354
|
+
topbar = computed(() => this.active().flatMap((e) => e.topbar ?? []).slice().sort((a, b) => a.order - b.order || a.id.localeCompare(b.id)), ...ngDevMode ? [{ debugName: "topbar" }] : /* istanbul ignore next */ []);
|
|
2355
|
+
overlays = computed(() => this.active().flatMap((e) => e.overlays ?? []), ...ngDevMode ? [{ debugName: "overlays" }] : /* istanbul ignore next */ []);
|
|
2356
|
+
panels = computed(() => this.active().flatMap((e) => e.panels ?? []), ...ngDevMode ? [{ debugName: "panels" }] : /* istanbul ignore next */ []);
|
|
2357
|
+
missing = computed(() => [...this.installed()].filter((m) => !this.entries.some((e) => e.module === m)).sort(), ...ngDevMode ? [{ debugName: "missing" }] : /* istanbul ignore next */ []);
|
|
2358
|
+
isInstalled(module) {
|
|
2359
|
+
return this.installed().has(module);
|
|
2360
|
+
}
|
|
2361
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2362
|
+
minVersion: "12.0.0",
|
|
2363
|
+
version: "22.2.3",
|
|
2364
|
+
ngImport: i0,
|
|
2365
|
+
type: ConsoleActivation,
|
|
2366
|
+
deps: [],
|
|
2367
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2368
|
+
});
|
|
2369
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2370
|
+
minVersion: "12.0.0",
|
|
2371
|
+
version: "22.2.3",
|
|
2372
|
+
ngImport: i0,
|
|
2373
|
+
type: ConsoleActivation,
|
|
2374
|
+
providedIn: "root"
|
|
2375
|
+
});
|
|
2376
|
+
};
|
|
2377
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2378
|
+
minVersion: "12.0.0",
|
|
2379
|
+
version: "22.2.3",
|
|
2380
|
+
ngImport: i0,
|
|
2381
|
+
type: ConsoleActivation,
|
|
2382
|
+
decorators: [{
|
|
2383
|
+
type: Injectable,
|
|
2384
|
+
args: [{ providedIn: "root" }]
|
|
2385
|
+
}]
|
|
2386
|
+
});
|
|
2387
|
+
function consoleModuleInstalled(module) {
|
|
2388
|
+
return () => {
|
|
2389
|
+
const activation = inject(ConsoleActivation);
|
|
2390
|
+
const consoleAccess = inject(ConsoleAccessService);
|
|
2391
|
+
return inject(AppInitService).ready$.pipe(take(1), switchMap(() => from(consoleAccess.ensure())), map(() => activation.isInstalled(module)));
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
function consoleChildren(entries) {
|
|
2395
|
+
const routes = [];
|
|
2396
|
+
for (const e of assembleConsole(entries)) for (const m of e.routes ?? []) {
|
|
2397
|
+
if ("redirectTo" in m) {
|
|
2398
|
+
routes.push({
|
|
2399
|
+
path: m.path,
|
|
2400
|
+
redirectTo: m.redirectTo,
|
|
2401
|
+
pathMatch: "full"
|
|
2402
|
+
});
|
|
2403
|
+
continue;
|
|
2404
|
+
}
|
|
2405
|
+
const route = {
|
|
2406
|
+
path: m.path,
|
|
2407
|
+
canMatch: [consoleModuleInstalled(e.module)],
|
|
2408
|
+
...m.nav ? { data: { ...m.nav } } : {},
|
|
2409
|
+
...m.providers ? { providers: [...m.providers] } : {}
|
|
2410
|
+
};
|
|
2411
|
+
if ("children" in m) route.loadChildren = m.children;
|
|
2412
|
+
else route.loadComponent = m.component;
|
|
2413
|
+
routes.push(route);
|
|
2414
|
+
}
|
|
2415
|
+
return routes;
|
|
2416
|
+
}
|
|
2417
|
+
function provideConsole(entries, options) {
|
|
2418
|
+
const checked = assembleConsole(entries);
|
|
2419
|
+
const providers = [
|
|
2420
|
+
{
|
|
2421
|
+
provide: CONSOLE_ENTRIES,
|
|
2422
|
+
useValue: checked
|
|
2423
|
+
},
|
|
2424
|
+
provideStore([...options.hostStates, ...checked.flatMap((e) => e.states ?? [])], { compatibility: { strictContentSecurityPolicy: true } }),
|
|
2425
|
+
provideAppInitializer(() => {
|
|
2426
|
+
const registry = inject(ComponentRegistry);
|
|
2427
|
+
for (const e of checked) for (const b of e.bindings ?? []) registry.register(b.name, b.component);
|
|
2428
|
+
})
|
|
2429
|
+
];
|
|
2430
|
+
for (const e of checked) for (const p of e.providers ?? []) providers.push(isPortProvision(p) ? {
|
|
2431
|
+
provide: p.port,
|
|
2432
|
+
useExisting: p.useExisting
|
|
2433
|
+
} : p);
|
|
2434
|
+
return makeEnvironmentProviders(providers);
|
|
2435
|
+
}
|
|
2436
|
+
const CURRENT_SECTION = new InjectionToken("coolms.current-section");
|
|
2437
|
+
const sectionInterceptor = (req, next) => {
|
|
2438
|
+
if (!shouldStamp(req.url)) return next(req);
|
|
2439
|
+
if (req.headers.has("X-CoolMS-Section")) return next(req);
|
|
2440
|
+
const slug = inject(CURRENT_SECTION, { optional: true })?.currentSlug() ?? null;
|
|
2441
|
+
if (!slug) return next(req);
|
|
2442
|
+
return next(req.clone({ setHeaders: { "X-CoolMS-Section": slug } }));
|
|
2443
|
+
};
|
|
2444
|
+
function shouldStamp(url) {
|
|
2445
|
+
const path = url.replace(/^https?:\/\/[^/]+/, "");
|
|
2446
|
+
if (!path.startsWith("/api/v1/")) return false;
|
|
2447
|
+
if (path.startsWith("/api/v1/auth/")) return false;
|
|
2448
|
+
return true;
|
|
2449
|
+
}
|
|
2450
|
+
var FloatingMenus = class FloatingMenus {
|
|
2451
|
+
current = null;
|
|
2452
|
+
claim(close) {
|
|
2453
|
+
const before = this.current;
|
|
2454
|
+
this.current = close;
|
|
2455
|
+
if (before !== null && before !== close) before();
|
|
2456
|
+
}
|
|
2457
|
+
release(close) {
|
|
2458
|
+
if (this.current === close) this.current = null;
|
|
2459
|
+
}
|
|
2460
|
+
track(open, close) {
|
|
2461
|
+
effect(() => {
|
|
2462
|
+
if (open()) untracked(() => this.claim(close));
|
|
2463
|
+
else this.release(close);
|
|
2464
|
+
});
|
|
2465
|
+
const release = () => this.release(close);
|
|
2466
|
+
inject(DestroyRef).onDestroy(release);
|
|
2467
|
+
return release;
|
|
2468
|
+
}
|
|
2469
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2470
|
+
minVersion: "12.0.0",
|
|
2471
|
+
version: "22.2.3",
|
|
2472
|
+
ngImport: i0,
|
|
2473
|
+
type: FloatingMenus,
|
|
2474
|
+
deps: [],
|
|
2475
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2476
|
+
});
|
|
2477
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2478
|
+
minVersion: "12.0.0",
|
|
2479
|
+
version: "22.2.3",
|
|
2480
|
+
ngImport: i0,
|
|
2481
|
+
type: FloatingMenus,
|
|
2482
|
+
providedIn: "root"
|
|
2483
|
+
});
|
|
2484
|
+
};
|
|
2485
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2486
|
+
minVersion: "12.0.0",
|
|
2487
|
+
version: "22.2.3",
|
|
2488
|
+
ngImport: i0,
|
|
2489
|
+
type: FloatingMenus,
|
|
2490
|
+
decorators: [{
|
|
2491
|
+
type: Injectable,
|
|
2492
|
+
args: [{ providedIn: "root" }]
|
|
2493
|
+
}]
|
|
2494
|
+
});
|
|
2495
|
+
export { AUDIENCE_NOT_GRANTED, AUDIENCE_REQUIRED, AUTH_AUDIENCE, AppConfigState, AppInitService, AuthRefreshCoordinator, AuthState, BACKGROUND_REQUEST, BYPASS_AUTH, BYPASS_ELEVATION, CONSOLE_CONTRACT, CONSOLE_ENTRIES, CURRENT_SECTION, CmsLoaderComponent, ComponentRegistry, ConfigService, ConsoleAccessService, ConsoleActivation, ConsoleAssemblyError, ConsolePanelHost, CrossTabAuthSyncService, DATAGRID_ENTRY_PREFIX, ELEVATION_ACTION, ELEVATION_CODE_REQUIRED_TYPE, ELEVATION_NOTICE, ELEVATION_PROMPT, ELEVATION_REQUIRED_HEADER, ELEVATION_REQUIRED_PROBLEM_TYPE, ELEVATION_RETRY_TYPES, ELEVATION_WARNING_FACTOR_MISSING, ELEVATION_WARNING_MFA_OFF, ELEVATION_WARNING_PASSWORD_NOT_SET, ElevationService, EntitySearchService, ErrorHandlerService, FloatingMenus, IdentityApiClient, Login, LoginComponent, Logout, NOT_AVAILABLE, NaviGraphService, PREFERENCES_NOTICE, PatchCurrentUser, RealtimeTokenClient, RestoreSession, SOMETHING_WENT_WRONG, SetAppConfig, SetTokens, SidebarStateService, ThemeService, UserPreferencesService, WRONG_INTERFACE, actionOf, assembleConsole, audienceRefusalOf, authGuard, authInterceptor, consoleChildren, consoleEntry, consoleModuleInstalled, datagridEntry, declaredProblemOf, declaredTypeOf, elevationInterceptor, installedConsoleModules, isElevationRefusal, isPortProvision, isRefusal, loginPageGuard, naviAccessOf, problemOf, provideConsole, refusalWords, resolvePattern, satisfiesRange, sectionInterceptor, sentenceOf, sessionEndsOn };
|
|
2496
|
+
|
|
2497
|
+
//# sourceMappingURL=coolms-core-angular.mjs.map
|