@wawjs/ngx-bos 22.0.3 → 22.0.5
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/AGENTS.md +4 -0
- package/README.md +10 -3
- package/RELEASES.md +46 -19
- package/ai/decisions/2026-06-02-version-start.md +1 -1
- package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs +29 -0
- package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +1 -0
- package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs +181 -0
- package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs.map +1 -0
- package/fesm2022/wawjs-ngx-bos.mjs +3063 -2293
- package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
- package/package.json +10 -10
- package/src/feature/file/file.component.ts +239 -236
- package/src/feature/file/file.service.ts +36 -35
- package/src/feature/file/pages/files/files.component.html +12 -12
- package/src/feature/file/pages/files/files.component.ts +116 -117
- package/src/feature/user/guards/admins.guard.ts +21 -28
- package/src/feature/user/guards/authenticated.guard.ts +15 -22
- package/src/feature/user/guards/guest.guard.ts +15 -15
- package/src/feature/user/pages/users/users.component.html +3 -3
- package/src/feature/user/pages/users/users.component.scss +12 -12
- package/src/feature/user/pages/users/users.component.ts +43 -47
- package/src/feature/user/user.service.ts +7 -22
- package/src/feature/user/user.storage.ts +31 -0
- package/src/icons/spider/spider.component.ts +4 -4
- package/src/ngx-bos.config.ts +1 -1
- package/src/pages/form/form.component.ts +100 -86
- package/src/pages/forms/forms.component.ts +9 -22
- package/src/public-api.ts +1 -1
- package/types/wawjs-ngx-bos.d.ts +402 -305
package/AGENTS.md
CHANGED
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ The resolved config is available through the `NGX_BOS_CONFIG` injection token.
|
|
|
76
76
|
|
|
77
77
|
- **Config:** `ngxBosProvide` / `provideNgxBos`, `NGX_BOS_CONFIG`, `DEFAULT_NGX_BOS_CONFIG`, `NgxBosConfig`, `NGX_BOS_VERSION`
|
|
78
78
|
- **User / auth:** `UserService`, `User` interface, user const/form, `UserSelectorComponent`, `UserPreviewComponent`, `UsersComponent`, `ClientsComponent`
|
|
79
|
-
- **Guards:** `
|
|
79
|
+
- **Guards:** `authenticatedGuard`, `guestGuard`, `adminsGuard` (functional `CanActivateFn`)
|
|
80
80
|
- **File:** `FileSelectorComponent`, `FilesComponent`, file feature contracts
|
|
81
81
|
- **Form pages:** `FormComponent`, `FormsComponent`
|
|
82
82
|
- **Routes:** `usersRoutes`, `clientsRoutes`, `filesRoutes`, `formRoutes`, `formsRoutes`
|
|
@@ -85,13 +85,20 @@ The resolved config is available through the `NGX_BOS_CONFIG` injection token.
|
|
|
85
85
|
### Using package routes
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
|
-
import { usersRoutes,
|
|
88
|
+
import { usersRoutes, adminsGuard } from '@wawjs/ngx-bos';
|
|
89
89
|
|
|
90
90
|
export const routes: Routes = [
|
|
91
|
-
{ path: 'users', canActivate: [
|
|
91
|
+
{ path: 'users', canActivate: [adminsGuard], children: usersRoutes },
|
|
92
92
|
];
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
Prefer the `*Routes` exports over importing the page components directly. The page components
|
|
96
|
+
(`UsersComponent`, `ClientsComponent`, `FilesComponent`, `FormComponent`, `FormsComponent`) are
|
|
97
|
+
still exported for backward compatibility, so the package is a single entry point and their
|
|
98
|
+
`loadComponent()` calls do not produce separate chunks: `ng build ngx-bos` reports
|
|
99
|
+
`INEFFECTIVE_DYNAMIC_IMPORT` for them. This is expected; the page components ship with the package
|
|
100
|
+
bundle either way.
|
|
101
|
+
|
|
95
102
|
## Building
|
|
96
103
|
|
|
97
104
|
From the workspace root:
|
package/RELEASES.md
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
|
-
# Releases
|
|
2
|
-
|
|
3
|
-
## 22.0.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
# Releases
|
|
2
|
+
|
|
3
|
+
## 22.0.5
|
|
4
|
+
|
|
5
|
+
Bug-fix release on the `@wawjs/*` 22.0.12 line.
|
|
6
|
+
|
|
7
|
+
- `FilesComponent` shows loaded files again (rows are a signal) and registers its `cell` templates.
|
|
8
|
+
- `FileService.uploadBase64` rejects on HTTP errors; the file picker keeps the files that did upload and always resets.
|
|
9
|
+
- The form page reads `formId` from the route, so moving between forms loads the right one; the delete confirm names the form component.
|
|
10
|
+
- `UserService` and the user guards no longer crash on a corrupt saved user: the bad value is removed.
|
|
11
|
+
- Removed leftover SSR branches from the guards and `UserService` (BOS is browser-only).
|
|
12
|
+
|
|
13
|
+
### Migration notes
|
|
14
|
+
|
|
15
|
+
- Update all `@wawjs/*` dependencies together to `22.0.12`.
|
|
16
|
+
- Optional: the template app now uses the `@wawjs/ngx-ui` startup screen (`provideStartup()`, `startup.css`, markup in `index.html`) and no longer depends on `zone.js`.
|
|
17
|
+
|
|
18
|
+
## 22.0.4
|
|
19
|
+
|
|
20
|
+
Companion package update.
|
|
21
|
+
|
|
22
|
+
- raises the `@wawjs/*` peer dependencies to `^22.0.7` (Angular 22.2 line)
|
|
23
|
+
- picks up the `@wawjs/ngx-ui` 22.0.7 changes: modal close options (`showClose`, `closeOnEscape`, `closeOnBackdrop`), `size: 'fullscreen'`, button token fixes, and a light default theme
|
|
24
|
+
|
|
25
|
+
### Migration notes
|
|
26
|
+
|
|
27
|
+
- update all `@wawjs/*` dependencies together to `22.0.7`
|
|
28
|
+
- apps that relied on the implicit dark default of `provideNgxUi()` must now pass `mode: 'dark'`
|
|
29
|
+
|
|
30
|
+
## 22.0.2
|
|
31
|
+
|
|
32
|
+
Angular 22.0.8 and WAW 22.0.2 platform release.
|
|
33
|
+
|
|
34
|
+
- updates the reusable file upload and crop workflow, including its contracts, selector, and files page
|
|
35
|
+
- adds reusable WAW form-component adapters and form management pages
|
|
36
|
+
- adds reusable user/client administration pages, guards, selectors, and profile preview support
|
|
37
|
+
- fixes absolute user thumbnail URLs so they are not prefixed with the API base URL
|
|
38
|
+
- updates the Users page: compact role columns, direct admin role updates, and admin-safe user editing
|
|
39
|
+
- publishes the current package AI guidance and source assets for consumer apps
|
|
40
|
+
|
|
41
|
+
### Migration notes
|
|
42
|
+
|
|
43
|
+
- update all `@wawjs/*` dependencies together to the `22.0.2` platform line
|
|
44
|
+
- use `UserService.updateAdmin()` for administrative user edits; `update()` remains the signed-in user's profile update
|
|
45
|
+
|
|
46
|
+
## 22.0.1
|
|
20
47
|
|
|
21
48
|
Angular 22.0.4 and WAW 22.0.1 package update.
|
|
22
49
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InjectionToken, makeEnvironmentProviders } from "@angular/core";
|
|
2
|
+
const DEFAULT_NGX_BOS_CONFIG = {
|
|
3
|
+
appId: "",
|
|
4
|
+
url: "",
|
|
5
|
+
cdnUrl: "https://cdn.webart.work",
|
|
6
|
+
roles: [],
|
|
7
|
+
userFields: [],
|
|
8
|
+
userForm: [],
|
|
9
|
+
signPath: "/sign",
|
|
10
|
+
profilePath: "/profile",
|
|
11
|
+
defaultUserThumb: "default.png"
|
|
12
|
+
};
|
|
13
|
+
const NGX_BOS_CONFIG = new InjectionToken("NGX_BOS_CONFIG", { factory: () => DEFAULT_NGX_BOS_CONFIG });
|
|
14
|
+
function ngxBosProvide(config = {}) {
|
|
15
|
+
return makeEnvironmentProviders([{
|
|
16
|
+
provide: NGX_BOS_CONFIG,
|
|
17
|
+
useValue: {
|
|
18
|
+
...DEFAULT_NGX_BOS_CONFIG,
|
|
19
|
+
...config,
|
|
20
|
+
roles: config.roles ?? DEFAULT_NGX_BOS_CONFIG.roles,
|
|
21
|
+
userFields: config.userFields ?? DEFAULT_NGX_BOS_CONFIG.userFields,
|
|
22
|
+
userForm: config.userForm ?? DEFAULT_NGX_BOS_CONFIG.userForm
|
|
23
|
+
}
|
|
24
|
+
}]);
|
|
25
|
+
}
|
|
26
|
+
const provideNgxBos = ngxBosProvide;
|
|
27
|
+
export { provideNgxBos as i, NGX_BOS_CONFIG as n, ngxBosProvide as r, DEFAULT_NGX_BOS_CONFIG as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs","names":[],"sources":["../../../projects/ngx-bos/src/ngx-bos.config.ts"],"sourcesContent":["import {\r\n\tEnvironmentProviders,\r\n\tInjectionToken,\r\n\tProvider,\r\n\tmakeEnvironmentProviders,\r\n} from '@angular/core';\r\nimport { FormComponentInterface } from '@wawjs/ngx-form';\r\n\r\nexport interface NgxBosConfig {\r\n\tappId?: string;\r\n\turl?: string;\r\n\tcdnUrl?: string;\r\n\troles?: string[];\r\n\tuserFields?: string[];\r\n\tuserForm?: FormComponentInterface[];\r\n\tsignPath?: string;\r\n\tprofilePath?: string;\r\n\tdefaultUserThumb?: string;\r\n}\r\n\r\nexport const DEFAULT_NGX_BOS_CONFIG: Required<NgxBosConfig> = {\r\n\tappId: '',\r\n\turl: '',\r\n\tcdnUrl: 'https://cdn.webart.work',\r\n\troles: [],\r\n\tuserFields: [],\r\n\tuserForm: [],\r\n\tsignPath: '/sign',\r\n\tprofilePath: '/profile',\r\n\tdefaultUserThumb: 'default.png',\n};\r\n\r\nexport const NGX_BOS_CONFIG = new InjectionToken<Required<NgxBosConfig>>(\r\n\t'NGX_BOS_CONFIG',\r\n\t{\r\n\t\tfactory: () => DEFAULT_NGX_BOS_CONFIG,\r\n\t},\r\n);\r\n\r\nexport function ngxBosProvide(config: NgxBosConfig = {}): EnvironmentProviders {\r\n\treturn makeEnvironmentProviders([\r\n\t\t{\r\n\t\t\tprovide: NGX_BOS_CONFIG,\r\n\t\t\tuseValue: {\r\n\t\t\t\t...DEFAULT_NGX_BOS_CONFIG,\r\n\t\t\t\t...config,\r\n\t\t\t\troles: config.roles ?? DEFAULT_NGX_BOS_CONFIG.roles,\r\n\t\t\t\tuserFields: config.userFields ?? DEFAULT_NGX_BOS_CONFIG.userFields,\r\n\t\t\t\tuserForm: config.userForm ?? DEFAULT_NGX_BOS_CONFIG.userForm,\r\n\t\t\t},\r\n\t\t} satisfies Provider,\r\n\t]);\r\n}\r\n\r\nexport const provideNgxBos = ngxBosProvide;\r\n"],"mappings":";AAoBA,MAAa,yBAAiD;CAC7D,OAAO;CACP,KAAK;CACL,QAAQ;CACR,OAAO,CAAA;CACP,YAAY,CAAA;CACZ,UAAU,CAAA;CACV,UAAU;CACV,aAAa;CACb,kBAAkB;AAClB;AAED,MAAa,iBAAiB,IAAI,eACjC,kBACA,EACC,eAAe,uBACf,CAAA;AAGF,SAAgB,cAAc,SAAuB,CAAA,GAAE;CACtD,OAAO,yBAAyB,CAC/B;EACC,SAAS;EACT,UAAU;GACT,GAAG;GACH,GAAG;GACH,OAAO,OAAO,SAAS,uBAAuB;GAC9C,YAAY,OAAO,cAAc,uBAAuB;GACxD,UAAU,OAAO,YAAY,uBAAuB;EACpD;CACkB,CACpB,CAAA;AACF;AAEA,MAAa,gBAAgB"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { n as NGX_BOS_CONFIG } from "./wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { Service, computed, inject, signal } from "@angular/core";
|
|
4
|
+
import { AlertService } from "@wawjs/ngx-ui";
|
|
5
|
+
import { CrudService } from "@wawjs/ngx-crud";
|
|
6
|
+
import { HttpService } from "@wawjs/ngx-http";
|
|
7
|
+
import { EmitterService } from "@wawjs/ngx-core";
|
|
8
|
+
import { Router } from "@angular/router";
|
|
9
|
+
const createUserFormComponents = (userForm = []) => ({
|
|
10
|
+
formId: "user",
|
|
11
|
+
title: "Profile Settings",
|
|
12
|
+
components: [
|
|
13
|
+
{
|
|
14
|
+
name: "Input",
|
|
15
|
+
key: "name",
|
|
16
|
+
focused: true,
|
|
17
|
+
props: {
|
|
18
|
+
placeholder: "Enter name...",
|
|
19
|
+
label: "Name"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "Input",
|
|
24
|
+
key: "email",
|
|
25
|
+
props: {
|
|
26
|
+
placeholder: "Enter email...",
|
|
27
|
+
label: "Email",
|
|
28
|
+
type: "email"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "Input",
|
|
33
|
+
key: "phone",
|
|
34
|
+
props: {
|
|
35
|
+
placeholder: "Enter phone...",
|
|
36
|
+
label: "Phone"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "Input",
|
|
41
|
+
key: "bio",
|
|
42
|
+
props: {
|
|
43
|
+
placeholder: "Enter bio...",
|
|
44
|
+
label: "Biography",
|
|
45
|
+
type: "textarea"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
...userForm
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
const userFormComponentsFactory = () => {
|
|
52
|
+
const config = inject(NGX_BOS_CONFIG);
|
|
53
|
+
return createUserFormComponents(config.userForm);
|
|
54
|
+
};
|
|
55
|
+
const USER_STORAGE_KEY = "waw_user";
|
|
56
|
+
function readStoredUser() {
|
|
57
|
+
const stored = localStorage.getItem(USER_STORAGE_KEY);
|
|
58
|
+
if (!stored) return null;
|
|
59
|
+
try {
|
|
60
|
+
const user = JSON.parse(stored);
|
|
61
|
+
if (user && typeof user === "object") return user;
|
|
62
|
+
} catch {}
|
|
63
|
+
localStorage.removeItem(USER_STORAGE_KEY);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
var UserService = class UserService extends CrudService {
|
|
67
|
+
role(role) {
|
|
68
|
+
return !!(this.user().is || {})[role];
|
|
69
|
+
}
|
|
70
|
+
constructor() {
|
|
71
|
+
super({
|
|
72
|
+
name: "user",
|
|
73
|
+
replace: (user) => {
|
|
74
|
+
user.roles = [];
|
|
75
|
+
user.data = user.data || {};
|
|
76
|
+
user.is = user.is || {};
|
|
77
|
+
for (const field of this._bosConfig.userFields) user.data[field] = user.data[field] || {};
|
|
78
|
+
for (const role of this.roles) if (user.is[role]) user.roles.push(role);
|
|
79
|
+
return user;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this._userHttpService = inject(HttpService);
|
|
83
|
+
this._alertService = inject(AlertService);
|
|
84
|
+
this._router = inject(Router);
|
|
85
|
+
this._emitterService = inject(EmitterService);
|
|
86
|
+
this._bosConfig = inject(NGX_BOS_CONFIG);
|
|
87
|
+
this.url = this._bosConfig.url;
|
|
88
|
+
this.roles = this._bosConfig.roles.concat(["admin"]);
|
|
89
|
+
this.employees = this._bosConfig.roles;
|
|
90
|
+
this.users = this.documents;
|
|
91
|
+
this.user = signal(readStoredUser() ?? this.prepareDocument()(), ...ngDevMode ? [{ debugName: "user" }] : /* istanbul ignore next */ []);
|
|
92
|
+
this.thumb = computed(() => {
|
|
93
|
+
const thumb = this.user().thumb;
|
|
94
|
+
return !thumb || thumb.includes(this._bosConfig.defaultUserThumb) ? this._bosConfig.defaultUserThumb : /^https?:\/\//i.test(thumb) ? thumb : this.url + thumb;
|
|
95
|
+
}, ...ngDevMode ? [{ debugName: "thumb" }] : /* istanbul ignore next */ []);
|
|
96
|
+
this.usersByRole = computed(() => {
|
|
97
|
+
const splitted = {};
|
|
98
|
+
for (const user of this.documents()) for (const role of user.roles || []) {
|
|
99
|
+
if (role === void 0 || role === null) continue;
|
|
100
|
+
(splitted[String(role)] ??= []).push(user);
|
|
101
|
+
}
|
|
102
|
+
return splitted;
|
|
103
|
+
}, ...ngDevMode ? [{ debugName: "usersByRole" }] : /* istanbul ignore next */ []);
|
|
104
|
+
if (localStorage.getItem("waw_user")) {
|
|
105
|
+
this.fetch({}, { name: "me" }).subscribe((user) => {
|
|
106
|
+
if (user) this.setUser(user);
|
|
107
|
+
else if (localStorage.getItem("waw_user")) this.logout();
|
|
108
|
+
});
|
|
109
|
+
this.get({ query: this._bosConfig.appId ? "appId=" + this._bosConfig.appId : "" });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
setUser(user) {
|
|
113
|
+
this.user.set(user);
|
|
114
|
+
localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
|
|
115
|
+
this._emitterService.complete("us.user");
|
|
116
|
+
}
|
|
117
|
+
updateMe() {
|
|
118
|
+
this.setUser(this.user());
|
|
119
|
+
return this.update(this.user()).subscribe(() => {
|
|
120
|
+
this._alertService.info({ text: "Profile information has been updated" });
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
updateMeAfterWhile() {
|
|
124
|
+
this.setUser(this.user());
|
|
125
|
+
this.updateAfterWhile(this.user());
|
|
126
|
+
}
|
|
127
|
+
changePassword(oldPass, newPass) {
|
|
128
|
+
return this._userHttpService.post("/api/user/changePassword", {
|
|
129
|
+
newPass,
|
|
130
|
+
oldPass
|
|
131
|
+
}, (resp) => {
|
|
132
|
+
if (resp) this._alertService.info({ text: "Successfully changed password" });
|
|
133
|
+
else this._alertService.error({ text: "Incorrect current password" });
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
logout() {
|
|
137
|
+
this.user.set(this.prepareDocument()());
|
|
138
|
+
localStorage.removeItem(USER_STORAGE_KEY);
|
|
139
|
+
this._userHttpService.remove("token");
|
|
140
|
+
this._userHttpService.get("/api/user/logout");
|
|
141
|
+
this._router.navigateByUrl(this._bosConfig.signPath);
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
location.reload();
|
|
144
|
+
}, 100);
|
|
145
|
+
}
|
|
146
|
+
updateAdmin(user) {
|
|
147
|
+
return this.update(user, { name: "admin" });
|
|
148
|
+
}
|
|
149
|
+
deleteAdmin(user) {
|
|
150
|
+
return this.delete(user, { name: "admin" });
|
|
151
|
+
}
|
|
152
|
+
static {
|
|
153
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
154
|
+
minVersion: "12.0.0",
|
|
155
|
+
version: "22.2.5",
|
|
156
|
+
ngImport: i0,
|
|
157
|
+
type: UserService,
|
|
158
|
+
deps: [],
|
|
159
|
+
target: i0.ɵɵFactoryTarget.Service
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
static {
|
|
163
|
+
this.ɵprov = i0.ɵɵngDeclareService({
|
|
164
|
+
minVersion: "22.0.0",
|
|
165
|
+
version: "22.2.5",
|
|
166
|
+
ngImport: i0,
|
|
167
|
+
type: UserService
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
172
|
+
minVersion: "12.0.0",
|
|
173
|
+
version: "22.2.5",
|
|
174
|
+
ngImport: i0,
|
|
175
|
+
type: UserService,
|
|
176
|
+
decorators: [{ type: Service }],
|
|
177
|
+
ctorParameters: () => []
|
|
178
|
+
});
|
|
179
|
+
export { userFormComponentsFactory as i, readStoredUser as n, createUserFormComponents as r, UserService as t };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=wawjs-ngx-bos-user.service-BL0vq7J4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wawjs-ngx-bos-user.service-BL0vq7J4.mjs","names":[],"sources":["../../../projects/ngx-bos/src/feature/user/user.form.ts","../../../projects/ngx-bos/src/feature/user/user.storage.ts","../../../projects/ngx-bos/src/feature/user/user.service.ts"],"sourcesContent":["import { inject } from '@angular/core';\r\nimport { FormComponentInterface } from '@wawjs/ngx-form';\r\nimport { NGX_BOS_CONFIG } from '../../ngx-bos.config';\r\n\r\nexport const createUserFormComponents = (\r\n\tuserForm: FormComponentInterface[] = [],\r\n) => ({\r\n\tformId: 'user',\r\n\ttitle: 'Profile Settings',\r\n\tcomponents: [\r\n\t\t{\r\n\t\t\tname: 'Input',\r\n\t\t\tkey: 'name',\r\n\t\t\tfocused: true,\r\n\t\t\tprops: {\r\n\t\t\t\tplaceholder: 'Enter name...',\r\n\t\t\t\tlabel: 'Name',\r\n\t\t\t},\r\n\t\t},\r\n\t\t{\r\n\t\t\tname: 'Input',\r\n\t\t\tkey: 'email',\r\n\t\t\tprops: {\r\n\t\t\t\tplaceholder: 'Enter email...',\r\n\t\t\t\tlabel: 'Email',\r\n\t\t\t\ttype: 'email',\r\n\t\t\t},\r\n\t\t},\r\n\t\t{\r\n\t\t\tname: 'Input',\r\n\t\t\tkey: 'phone',\r\n\t\t\tprops: {\r\n\t\t\t\tplaceholder: 'Enter phone...',\r\n\t\t\t\tlabel: 'Phone',\r\n\t\t\t},\r\n\t\t},\r\n\t\t{\r\n\t\t\tname: 'Input',\r\n\t\t\tkey: 'bio',\r\n\t\t\tprops: {\r\n\t\t\t\tplaceholder: 'Enter bio...',\r\n\t\t\t\tlabel: 'Biography',\r\n\t\t\t\ttype: 'textarea',\r\n\t\t\t},\r\n\t\t},\r\n\t\t...userForm,\r\n\t],\r\n});\r\n\r\nexport const userFormComponentsFactory = () => {\r\n\tconst config = inject(NGX_BOS_CONFIG);\r\n\r\n\treturn createUserFormComponents(config.userForm);\r\n};\r\n","import { User } from './user.interface';\n\n/** localStorage key holding the signed-in user snapshot. */\nexport const USER_STORAGE_KEY = 'waw_user';\n\n/**\n * Reads the stored user snapshot. Returns `null` when nothing is stored or when the\n * stored value is corrupted; a corrupted value is removed so it cannot break guards\n * or service initialization again.\n */\nexport function readStoredUser(): User | null {\n\tconst stored = localStorage.getItem(USER_STORAGE_KEY);\n\n\tif (!stored) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst user = JSON.parse(stored) as User | null;\n\n\t\tif (user && typeof user === 'object') {\n\t\t\treturn user;\n\t\t}\n\t} catch {\n\t\t// fall through to cleanup\n\t}\n\n\tlocalStorage.removeItem(USER_STORAGE_KEY);\n\n\treturn null;\n}\n","import { Service, computed, inject, signal } from '@angular/core';\r\nimport { Router } from '@angular/router';\r\nimport { AlertService } from '@wawjs/ngx-ui';\r\nimport { CrudService } from '@wawjs/ngx-crud';\r\nimport { EmitterService } from '@wawjs/ngx-core';\r\nimport { HttpService } from '@wawjs/ngx-http';\r\nimport { NGX_BOS_CONFIG } from '../../ngx-bos.config';\r\nimport { User } from './user.interface';\r\nimport { readStoredUser, USER_STORAGE_KEY } from './user.storage';\r\n@Service()\r\nexport class UserService extends CrudService<User> {\r\n\tprivate readonly _userHttpService = inject(HttpService);\r\n\r\n\tprivate readonly _alertService = inject(AlertService);\r\n\r\n\tprivate readonly _router = inject(Router);\r\n\r\n\tprivate readonly _emitterService = inject(EmitterService);\r\n\r\n\tprivate readonly _bosConfig = inject(NGX_BOS_CONFIG);\r\n\r\n\treadonly url = this._bosConfig.url;\r\n\r\n\troles = this._bosConfig.roles.concat(['admin']);\r\n\r\n\temployees = this._bosConfig.roles;\r\n\r\n\treadonly users = this.documents;\r\n\r\n\tuser = signal<User>(readStoredUser() ?? this.prepareDocument()());\r\n\r\n\tthumb = computed(() => {\r\n\t\tconst thumb = this.user().thumb;\r\n\r\n\t\treturn !thumb || thumb.includes(this._bosConfig.defaultUserThumb)\r\n\t\t\t? this._bosConfig.defaultUserThumb\r\n\t\t\t: /^https?:\\/\\//i.test(thumb)\r\n\t\t\t\t? thumb\r\n\t\t\t\t: this.url + thumb;\r\n\t});\r\n\r\n\trole(role: string): boolean {\r\n\t\treturn !!(this.user().is || {})[role];\r\n\t}\r\n\r\n\treadonly usersByRole = computed<Record<string, User[]>>(() => {\r\n\t\tconst splitted: Record<string, User[]> = {};\r\n\r\n\t\tfor (const user of this.documents()) {\r\n\t\t\tfor (const role of user.roles || []) {\r\n\t\t\t\tif (role === undefined || role === null) continue;\r\n\t\t\t\t(splitted[String(role)] ??= []).push(user);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn splitted;\r\n\t});\r\n\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tname: 'user',\r\n\t\t\treplace: (user) => {\r\n\t\t\t\tuser.roles = [];\r\n\t\t\t\tuser.data = user.data || {};\r\n\t\t\t\tuser.is = user.is || {};\r\n\r\n\t\t\t\tfor (const field of this._bosConfig.userFields) {\r\n\t\t\t\t\tuser.data[field] = user.data[field] || {};\r\n\t\t\t\t}\r\n\r\n\t\t\t\tfor (const role of this.roles) {\r\n\t\t\t\t\tif (user.is[role]) {\r\n\t\t\t\t\t\tuser.roles.push(role);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn user;\r\n\t\t\t},\r\n\t\t});\r\n\r\n\t\tif (localStorage.getItem(USER_STORAGE_KEY)) {\r\n\t\t\tthis.fetch({}, { name: 'me' }).subscribe((user: User) => {\r\n\t\t\t\tif (user) {\r\n\t\t\t\t\tthis.setUser(user);\r\n\t\t\t\t} else if (localStorage.getItem(USER_STORAGE_KEY)) {\r\n\t\t\t\t\tthis.logout();\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\tthis.get({\r\n\t\t\t\tquery: this._bosConfig.appId ? 'appId=' + this._bosConfig.appId : '',\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tsetUser(user: User) {\r\n\t\tthis.user.set(user);\r\n\r\n\t\tlocalStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));\r\n\r\n\t\tthis._emitterService.complete('us.user');\r\n\t}\r\n\r\n\tupdateMe() {\r\n\t\tthis.setUser(this.user());\r\n\r\n\t\treturn this.update(this.user()).subscribe(() => {\r\n\t\t\tthis._alertService.info({\r\n\t\t\t\ttext: 'Profile information has been updated',\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\tupdateMeAfterWhile() {\r\n\t\tthis.setUser(this.user());\r\n\r\n\t\tthis.updateAfterWhile(this.user());\r\n\t}\r\n\r\n\tchangePassword(oldPass: string, newPass: string) {\r\n\t\treturn this._userHttpService.post(\r\n\t\t\t'/api/user/changePassword',\r\n\t\t\t{\r\n\t\t\t\tnewPass: newPass,\r\n\t\t\t\toldPass: oldPass,\r\n\t\t\t},\r\n\t\t\t(resp: boolean) => {\r\n\t\t\t\tif (resp) {\r\n\t\t\t\t\tthis._alertService.info({\r\n\t\t\t\t\t\ttext: 'Successfully changed password',\r\n\t\t\t\t\t});\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis._alertService.error({\r\n\t\t\t\t\t\ttext: 'Incorrect current password',\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t);\r\n\t}\r\n\r\n\tlogout() {\r\n\t\tthis.user.set(this.prepareDocument()());\r\n\r\n\t\tlocalStorage.removeItem(USER_STORAGE_KEY);\r\n\r\n\t\tthis._userHttpService.remove('token');\r\n\r\n\t\tthis._userHttpService.get('/api/user/logout');\r\n\r\n\t\tthis._router.navigateByUrl(this._bosConfig.signPath);\r\n\r\n\t\tsetTimeout(() => {\r\n\t\t\tlocation.reload();\r\n\t\t}, 100);\r\n\t}\r\n\r\n\tupdateAdmin(user: User) {\r\n\t\treturn this.update(user, {\r\n\t\t\tname: 'admin',\r\n\t\t});\r\n\t}\r\n\r\n\tdeleteAdmin(user: User) {\r\n\t\treturn this.delete(user, {\r\n\t\t\tname: 'admin',\r\n\t\t});\r\n\t}\r\n}\r\n"],"mappings":";;;;;;;;AAIA,MAAa,4BACZ,WAAqC,CAAA,OAChC;CACL,QAAQ;CACR,OAAO;CACP,YAAY;EACX;GACC,MAAM;GACN,KAAK;GACL,SAAS;GACT,OAAO;IACN,aAAa;IACb,OAAO;GACP;EACD;EACD;GACC,MAAM;GACN,KAAK;GACL,OAAO;IACN,aAAa;IACb,OAAO;IACP,MAAM;GACN;EACD;EACD;GACC,MAAM;GACN,KAAK;GACL,OAAO;IACN,aAAa;IACb,OAAO;GACP;EACD;EACD;GACC,MAAM;G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