@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.
Files changed (29) hide show
  1. package/AGENTS.md +4 -0
  2. package/README.md +10 -3
  3. package/RELEASES.md +46 -19
  4. package/ai/decisions/2026-06-02-version-start.md +1 -1
  5. package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs +29 -0
  6. package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +1 -0
  7. package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs +181 -0
  8. package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs.map +1 -0
  9. package/fesm2022/wawjs-ngx-bos.mjs +3063 -2293
  10. package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
  11. package/package.json +10 -10
  12. package/src/feature/file/file.component.ts +239 -236
  13. package/src/feature/file/file.service.ts +36 -35
  14. package/src/feature/file/pages/files/files.component.html +12 -12
  15. package/src/feature/file/pages/files/files.component.ts +116 -117
  16. package/src/feature/user/guards/admins.guard.ts +21 -28
  17. package/src/feature/user/guards/authenticated.guard.ts +15 -22
  18. package/src/feature/user/guards/guest.guard.ts +15 -15
  19. package/src/feature/user/pages/users/users.component.html +3 -3
  20. package/src/feature/user/pages/users/users.component.scss +12 -12
  21. package/src/feature/user/pages/users/users.component.ts +43 -47
  22. package/src/feature/user/user.service.ts +7 -22
  23. package/src/feature/user/user.storage.ts +31 -0
  24. package/src/icons/spider/spider.component.ts +4 -4
  25. package/src/ngx-bos.config.ts +1 -1
  26. package/src/pages/form/form.component.ts +100 -86
  27. package/src/pages/forms/forms.component.ts +9 -22
  28. package/src/public-api.ts +1 -1
  29. package/types/wawjs-ngx-bos.d.ts +402 -305
@@ -1,117 +1,116 @@
1
- import { Clipboard } from '@angular/cdk/clipboard';
2
- import { Component, inject } from '@angular/core';
3
- import { AlertService, TableComponent } from '@wawjs/ngx-ui';
4
- import { FormInterface, FormService } from '@wawjs/ngx-form';
5
- import { CoreService } from '@wawjs/ngx-core';
6
- import { File, FileService } from '../..';
7
-
8
- const fileFormComponents = {
9
- title: 'File',
10
- components: [
11
- {
12
- name: 'Input',
13
- key: 'url',
14
- props: {
15
- label: 'URL',
16
- placeholder: 'Enter file URL...',
17
- },
18
- },
19
- {
20
- name: 'Input',
21
- key: 'name',
22
- props: {
23
- label: 'Name',
24
- placeholder: 'Enter name...',
25
- },
26
- },
27
- {
28
- name: 'Input',
29
- key: 'description',
30
- props: {
31
- label: 'Description',
32
- placeholder: 'Enter description...',
33
- type: 'textarea',
34
- },
35
- },
36
- ],
37
- } as FormInterface;
38
-
39
- @Component({
40
- templateUrl: './files.component.html',
41
- imports: [TableComponent],
42
- })
43
- export class FilesComponent {
44
- private _fileService = inject(FileService);
45
- private _clipboard = inject(Clipboard);
46
- private _alert = inject(AlertService);
47
- private _form = inject(FormService);
48
- private _core = inject(CoreService);
49
-
50
- columns = ['img', 'url'];
51
-
52
- form = fileFormComponents;
53
-
54
- config = {
55
- paginate: this.setRows.bind(this),
56
- perPage: 20,
57
- setPerPage: this._fileService.setPerPage.bind(this._fileService),
58
- allDocs: false,
59
- create: (): void => {
60
- this._form.modal<File>(this.form, {
61
- label: 'Create',
62
- click: async (created: unknown, close: () => void) => {
63
- close();
64
- this._preCreate(created as File);
65
- this._fileService.create(created as File);
66
- this.setRows();
67
- },
68
- });
69
- },
70
- delete: (doc: File): void => {
71
- this._alert.question({
72
- text: 'Are you sure you want to delete this file?',
73
- buttons: [
74
- { text: 'No' },
75
- {
76
- text: 'Yes',
77
- callback: async (): Promise<void> => {
78
- this._fileService.delete(doc);
79
- this.setRows();
80
- },
81
- },
82
- ],
83
- });
84
- },
85
- };
86
-
87
- rows: File[] = [];
88
-
89
- constructor() {
90
- this.setRows();
91
- }
92
-
93
- copy(text: string): void {
94
- this._clipboard.copy(text);
95
- this._alert.info({ text: 'Url has been copied' });
96
- }
97
-
98
- setRows(page = this._page): void {
99
- this._page = page;
100
- this._core.afterWhile(
101
- this,
102
- () => {
103
- this._fileService.get({ page }).subscribe((rows) => {
104
- this.rows.splice(0, this.rows.length);
105
- this.rows.push(...rows);
106
- });
107
- },
108
- 250,
109
- );
110
- }
111
-
112
- private _page = 1;
113
-
114
- private _preCreate(file: File): void {
115
- delete (file as any).__created;
116
- }
117
- }
1
+ import { Clipboard } from '@angular/cdk/clipboard';
2
+ import { Component, inject, signal } from '@angular/core';
3
+ import { AlertService, CellDirective, TableComponent } from '@wawjs/ngx-ui';
4
+ import { FormInterface, FormService } from '@wawjs/ngx-form';
5
+ import { CoreService } from '@wawjs/ngx-core';
6
+ import { File, FileService } from '../..';
7
+
8
+ const fileFormComponents = {
9
+ title: 'File',
10
+ components: [
11
+ {
12
+ name: 'Input',
13
+ key: 'url',
14
+ props: {
15
+ label: 'URL',
16
+ placeholder: 'Enter file URL...',
17
+ },
18
+ },
19
+ {
20
+ name: 'Input',
21
+ key: 'name',
22
+ props: {
23
+ label: 'Name',
24
+ placeholder: 'Enter name...',
25
+ },
26
+ },
27
+ {
28
+ name: 'Input',
29
+ key: 'description',
30
+ props: {
31
+ label: 'Description',
32
+ placeholder: 'Enter description...',
33
+ type: 'textarea',
34
+ },
35
+ },
36
+ ],
37
+ } as FormInterface;
38
+
39
+ @Component({
40
+ templateUrl: './files.component.html',
41
+ imports: [TableComponent, CellDirective],
42
+ })
43
+ export class FilesComponent {
44
+ private _fileService = inject(FileService);
45
+ private _clipboard = inject(Clipboard);
46
+ private _alert = inject(AlertService);
47
+ private _form = inject(FormService);
48
+ private _core = inject(CoreService);
49
+
50
+ columns = ['img', 'url'];
51
+
52
+ form = fileFormComponents;
53
+
54
+ config = {
55
+ paginate: this.setRows.bind(this),
56
+ perPage: 20,
57
+ setPerPage: this._fileService.setPerPage.bind(this._fileService),
58
+ allDocs: false,
59
+ create: (): void => {
60
+ this._form.modal<File>(this.form, {
61
+ label: 'Create',
62
+ click: async (created: unknown, close: () => void) => {
63
+ close();
64
+ this._preCreate(created as File);
65
+ this._fileService.create(created as File);
66
+ this.setRows();
67
+ },
68
+ });
69
+ },
70
+ delete: (doc: File): void => {
71
+ this._alert.question({
72
+ text: 'Are you sure you want to delete this file?',
73
+ buttons: [
74
+ { text: 'No' },
75
+ {
76
+ text: 'Yes',
77
+ callback: async (): Promise<void> => {
78
+ this._fileService.delete(doc);
79
+ this.setRows();
80
+ },
81
+ },
82
+ ],
83
+ });
84
+ },
85
+ };
86
+
87
+ readonly rows = signal<File[]>([]);
88
+
89
+ constructor() {
90
+ this.setRows();
91
+ }
92
+
93
+ copy(text: string): void {
94
+ this._clipboard.copy(text);
95
+ this._alert.info({ text: 'Url has been copied' });
96
+ }
97
+
98
+ setRows(page = this._page): void {
99
+ this._page = page;
100
+ this._core.afterWhile(
101
+ this,
102
+ () => {
103
+ this._fileService.get({ page }).subscribe((rows) => {
104
+ this.rows.set([...rows]);
105
+ });
106
+ },
107
+ 250,
108
+ );
109
+ }
110
+
111
+ private _page = 1;
112
+
113
+ private _preCreate(file: File): void {
114
+ delete (file as any).__created;
115
+ }
116
+ }
@@ -1,28 +1,21 @@
1
- import { inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
3
- import { CanActivateFn, Router } from '@angular/router';
4
- import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
5
-
6
- export const adminsGuard: CanActivateFn = () => {
7
- const router = inject(Router);
8
- const config = inject(NGX_BOS_CONFIG);
9
-
10
- if (!isPlatformBrowser(inject(PLATFORM_ID))) {
11
- // See authenticatedGuard — no real session at build/prerender time, defer to the client.
12
- return true;
13
- }
14
-
15
- const stored = localStorage.getItem('waw_user');
16
-
17
- if (!stored) {
18
- return router.parseUrl(config.signPath);
19
- }
20
-
21
- const user = JSON.parse(stored);
22
-
23
- if (user.is && user.is.admin) {
24
- return true;
25
- }
26
-
27
- return router.parseUrl(config.profilePath);
28
- };
1
+ import { inject } from '@angular/core';
2
+ import { CanActivateFn, Router } from '@angular/router';
3
+ import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
+
6
+ export const adminsGuard: CanActivateFn = () => {
7
+ const router = inject(Router);
8
+ const config = inject(NGX_BOS_CONFIG);
9
+
10
+ const user = readStoredUser();
11
+
12
+ if (!user) {
13
+ return router.parseUrl(config.signPath);
14
+ }
15
+
16
+ if (user.is?.['admin']) {
17
+ return true;
18
+ }
19
+
20
+ return router.parseUrl(config.profilePath);
21
+ };
@@ -1,22 +1,15 @@
1
- import { inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
3
- import { CanActivateFn, Router } from '@angular/router';
4
- import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
5
-
6
- export const authenticatedGuard: CanActivateFn = () => {
7
- const router = inject(Router);
8
- const config = inject(NGX_BOS_CONFIG);
9
-
10
- if (!isPlatformBrowser(inject(PLATFORM_ID))) {
11
- // No real session exists at build/prerender time — render the shell and let the client
12
- // re-check against the real localStorage after hydration, instead of baking a redirect
13
- // stub into the static file (which would bounce an already-authenticated user on reload).
14
- return true;
15
- }
16
-
17
- if (localStorage.getItem('waw_user')) {
18
- return true;
19
- }
20
-
21
- return router.parseUrl(config.signPath);
22
- };
1
+ import { inject } from '@angular/core';
2
+ import { CanActivateFn, Router } from '@angular/router';
3
+ import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
+
6
+ export const authenticatedGuard: CanActivateFn = () => {
7
+ const router = inject(Router);
8
+ const config = inject(NGX_BOS_CONFIG);
9
+
10
+ if (readStoredUser()) {
11
+ return true;
12
+ }
13
+
14
+ return router.parseUrl(config.signPath);
15
+ };
@@ -1,15 +1,15 @@
1
- import { inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
3
- import { CanActivateFn, Router } from '@angular/router';
4
- import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
5
-
6
- export const guestGuard: CanActivateFn = () => {
7
- const router = inject(Router);
8
- const config = inject(NGX_BOS_CONFIG);
9
-
10
- if (isPlatformBrowser(inject(PLATFORM_ID)) && localStorage.getItem('waw_user')) {
11
- return router.parseUrl(config.profilePath);
12
- }
13
-
14
- return true;
15
- };
1
+ import { inject } from '@angular/core';
2
+ import { CanActivateFn, Router } from '@angular/router';
3
+ import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
+
6
+ export const guestGuard: CanActivateFn = () => {
7
+ const router = inject(Router);
8
+ const config = inject(NGX_BOS_CONFIG);
9
+
10
+ if (readStoredUser()) {
11
+ return router.parseUrl(config.profilePath);
12
+ }
13
+
14
+ return true;
15
+ };
@@ -7,9 +7,9 @@
7
7
  >
8
8
  @for (role of roles; track role) {
9
9
  <ng-template [cell]="role" let-user>
10
- <winput
11
- (click)="$event.stopPropagation()"
12
- (wChange)="updateRole(user, role, !!$event)"
10
+ <winput
11
+ (click)="$event.stopPropagation()"
12
+ (wChange)="updateRole(user, role, !!$event)"
13
13
  [wModel]="user.is[role]"
14
14
  type="checkbox"
15
15
  />
@@ -1,12 +1,12 @@
1
- :host ::ng-deep {
2
- .wtable__th:nth-child(n + 3):not(:last-child),
3
- .wtable__td:nth-child(n + 3):not(:last-child) {
4
- width: 1%;
5
- padding-inline: var(--sp-2);
6
- white-space: nowrap;
7
- }
8
-
9
- .wtable__td:nth-child(n + 3):not(:last-child) winput {
10
- display: inline-flex;
11
- }
12
- }
1
+ :host ::ng-deep {
2
+ .wtable__th:nth-child(n + 3):not(:last-child),
3
+ .wtable__td:nth-child(n + 3):not(:last-child) {
4
+ width: 1%;
5
+ padding-inline: var(--sp-2);
6
+ white-space: nowrap;
7
+ }
8
+
9
+ .wtable__td:nth-child(n + 3):not(:last-child) winput {
10
+ display: inline-flex;
11
+ }
12
+ }
@@ -1,5 +1,4 @@
1
1
  import { Component, inject } from '@angular/core';
2
- import { Router } from '@angular/router';
3
2
  import { FormInterface, FormService } from '@wawjs/ngx-form';
4
3
  import { CrudComponent } from '@wawjs/ngx-crud';
5
4
  import { CellDirective, InputComponent, TableComponent } from '@wawjs/ngx-ui';
@@ -8,59 +7,56 @@ import { User } from '../../user.interface';
8
7
  import { UserService } from '../../user.service';
9
8
 
10
9
  @Component({
11
- imports: [TableComponent, CellDirective, InputComponent],
12
- templateUrl: './users.component.html',
13
- styleUrl: './users.component.scss',
14
- })
10
+ imports: [TableComponent, CellDirective, InputComponent],
11
+ templateUrl: './users.component.html',
12
+ styleUrl: './users.component.scss',
13
+ })
15
14
  export class UsersComponent extends CrudComponent<
16
15
  UserService,
17
16
  User,
18
17
  FormInterface
19
18
  > {
20
- protected override configType: 'server' | 'local' = 'local';
21
- private readonly _formService = inject(FormService);
19
+ protected override configType: 'server' | 'local' = 'local';
20
+ private readonly _formService = inject(FormService);
22
21
 
23
22
  protected override allowUrl(): boolean {
24
23
  return false;
25
24
  }
26
25
 
27
- protected override async delete(doc: User) {
26
+ protected override async delete(doc: User) {
28
27
  this.userService.deleteAdmin(doc).subscribe(() => {
29
28
  this.setDocuments();
30
29
  });
31
- }
32
-
33
- protected override update(doc: User): void {
34
- if (this.form.formId) {
35
- this._formService.reset(
36
- this.form.formId,
37
- doc as unknown as Record<string, unknown>,
38
- );
39
- }
40
-
41
- this._formService.modal(
42
- this.form,
43
- {
44
- label: 'Update',
45
- click: (updated: unknown, close: () => void) => {
46
- close();
47
- Object.assign(doc, updated as User);
48
- this.userService.updateAdmin(doc).subscribe(() => {
49
- this.setDocuments();
50
- });
51
- },
52
- },
53
- doc,
54
- );
55
- }
30
+ }
31
+
32
+ protected override update(doc: User): void {
33
+ if (this.form.formId) {
34
+ this._formService.reset(
35
+ this.form.formId,
36
+ doc as unknown as Record<string, unknown>,
37
+ );
38
+ }
56
39
 
57
- private _router = inject(Router);
40
+ this._formService.modal(
41
+ this.form,
42
+ {
43
+ label: 'Update',
44
+ click: (updated: unknown, close: () => void) => {
45
+ close();
46
+ Object.assign(doc, updated as User);
47
+ this.userService.updateAdmin(doc).subscribe(() => {
48
+ this.setDocuments();
49
+ });
50
+ },
51
+ },
52
+ doc,
53
+ );
54
+ }
58
55
 
59
- userService = inject(UserService);
56
+ userService = inject(UserService);
60
57
 
61
- readonly roles = this._router.url.includes('admin')
62
- ? this.userService.roles
63
- : this.userService.employees;
58
+ /** Every role gets a checkbox column; matches the columns added in the constructor. */
59
+ readonly roles = this.userService.roles;
64
60
 
65
61
  columns = ['name', 'email'];
66
62
 
@@ -79,12 +75,12 @@ export class UsersComponent extends CrudComponent<
79
75
  for (const role of this.userService.roles) {
80
76
  this.columns.push(role);
81
77
  }
82
- }
83
-
84
- updateRole(user: User, role: string, value: boolean): void {
85
- user.is[role] = value;
86
- this.userService.updateAdmin(user).subscribe(() => {
87
- this.setDocuments();
88
- });
89
- }
90
- }
78
+ }
79
+
80
+ updateRole(user: User, role: string, value: boolean): void {
81
+ user.is[role] = value;
82
+ this.userService.updateAdmin(user).subscribe(() => {
83
+ this.setDocuments();
84
+ });
85
+ }
86
+ }
@@ -1,5 +1,4 @@
1
- import { Service, computed, inject, PLATFORM_ID, signal } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
1
+ import { Service, computed, inject, signal } from '@angular/core';
3
2
  import { Router } from '@angular/router';
4
3
  import { AlertService } from '@wawjs/ngx-ui';
5
4
  import { CrudService } from '@wawjs/ngx-crud';
@@ -7,6 +6,7 @@ import { EmitterService } from '@wawjs/ngx-core';
7
6
  import { HttpService } from '@wawjs/ngx-http';
8
7
  import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
9
8
  import { User } from './user.interface';
9
+ import { readStoredUser, USER_STORAGE_KEY } from './user.storage';
10
10
  @Service()
11
11
  export class UserService extends CrudService<User> {
12
12
  private readonly _userHttpService = inject(HttpService);
@@ -19,8 +19,6 @@ export class UserService extends CrudService<User> {
19
19
 
20
20
  private readonly _bosConfig = inject(NGX_BOS_CONFIG);
21
21
 
22
- private readonly _isBrowserPlatform = isPlatformBrowser(inject(PLATFORM_ID));
23
-
24
22
  readonly url = this._bosConfig.url;
25
23
 
26
24
  roles = this._bosConfig.roles.concat(['admin']);
@@ -29,13 +27,7 @@ export class UserService extends CrudService<User> {
29
27
 
30
28
  readonly users = this.documents;
31
29
 
32
- private readonly _storedUser = this._isBrowserPlatform ? localStorage.getItem('waw_user') : null;
33
-
34
- user = signal<User>(
35
- this._storedUser
36
- ? JSON.parse(this._storedUser)
37
- : this.prepareDocument()(),
38
- );
30
+ user = signal<User>(readStoredUser() ?? this.prepareDocument()());
39
31
 
40
32
  thumb = computed(() => {
41
33
  const thumb = this.user().thumb;
@@ -86,18 +78,11 @@ export class UserService extends CrudService<User> {
86
78
  },
87
79
  });
88
80
 
89
- if (this._isBrowserPlatform && localStorage.getItem('waw_user')) {
81
+ if (localStorage.getItem(USER_STORAGE_KEY)) {
90
82
  this.fetch({}, { name: 'me' }).subscribe((user: User) => {
91
83
  if (user) {
92
- if (
93
- !localStorage.getItem('waw_user') &&
94
- this._router.url === this._bosConfig.signPath
95
- ) {
96
- this._router.navigateByUrl(this._bosConfig.profilePath);
97
- }
98
-
99
84
  this.setUser(user);
100
- } else if (localStorage.getItem('waw_user')) {
85
+ } else if (localStorage.getItem(USER_STORAGE_KEY)) {
101
86
  this.logout();
102
87
  }
103
88
  });
@@ -111,7 +96,7 @@ export class UserService extends CrudService<User> {
111
96
  setUser(user: User) {
112
97
  this.user.set(user);
113
98
 
114
- localStorage.setItem('waw_user', JSON.stringify(user));
99
+ localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
115
100
 
116
101
  this._emitterService.complete('us.user');
117
102
  }
@@ -156,7 +141,7 @@ export class UserService extends CrudService<User> {
156
141
  logout() {
157
142
  this.user.set(this.prepareDocument()());
158
143
 
159
- localStorage.removeItem('waw_user');
144
+ localStorage.removeItem(USER_STORAGE_KEY);
160
145
 
161
146
  this._userHttpService.remove('token');
162
147
 
@@ -0,0 +1,31 @@
1
+ import { User } from './user.interface';
2
+
3
+ /** localStorage key holding the signed-in user snapshot. */
4
+ export const USER_STORAGE_KEY = 'waw_user';
5
+
6
+ /**
7
+ * Reads the stored user snapshot. Returns `null` when nothing is stored or when the
8
+ * stored value is corrupted; a corrupted value is removed so it cannot break guards
9
+ * or service initialization again.
10
+ */
11
+ export function readStoredUser(): User | null {
12
+ const stored = localStorage.getItem(USER_STORAGE_KEY);
13
+
14
+ if (!stored) {
15
+ return null;
16
+ }
17
+
18
+ try {
19
+ const user = JSON.parse(stored) as User | null;
20
+
21
+ if (user && typeof user === 'object') {
22
+ return user;
23
+ }
24
+ } catch {
25
+ // fall through to cleanup
26
+ }
27
+
28
+ localStorage.removeItem(USER_STORAGE_KEY);
29
+
30
+ return null;
31
+ }
@@ -6,10 +6,10 @@ import { Component, input } from '@angular/core';
6
6
  styleUrl: './spider.component.scss',
7
7
  host: {
8
8
  class: 'spider',
9
- '[style.--spider-w]': 'width()',
10
- '[style.--spider-h]': 'height()',
11
- '[style.--spider-start]': 'start()',
12
- '[style.--spider-end]': 'end()',
9
+ '[style.--spider-w]': 'width()',
10
+ '[style.--spider-h]': 'height()',
11
+ '[style.--spider-start]': 'start()',
12
+ '[style.--spider-end]': 'end()',
13
13
  },
14
14
  })
15
15
  export class SpiderComponent {
@@ -27,7 +27,7 @@ export const DEFAULT_NGX_BOS_CONFIG: Required<NgxBosConfig> = {
27
27
  userForm: [],
28
28
  signPath: '/sign',
29
29
  profilePath: '/profile',
30
- defaultUserThumb: 'default.png',
30
+ defaultUserThumb: 'default.png',
31
31
  };
32
32
 
33
33
  export const NGX_BOS_CONFIG = new InjectionToken<Required<NgxBosConfig>>(