@wawjs/ngx-bos 22.0.6 → 22.0.7

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 (30) hide show
  1. package/README.md +1 -1
  2. package/RELEASES.md +38 -0
  3. package/fesm2022/file.service-C8Erkqrm.mjs +48 -0
  4. package/fesm2022/file.service-C8Erkqrm.mjs.map +1 -0
  5. package/fesm2022/{wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs → ngx-bos.config-DjtgUjR8.mjs} +3 -5
  6. package/fesm2022/ngx-bos.config-DjtgUjR8.mjs.map +1 -0
  7. package/fesm2022/{wawjs-ngx-bos-user.service-DFgHcvNR.mjs → user-crud.component-B1_SlIDS.mjs} +146 -16
  8. package/fesm2022/user-crud.component-B1_SlIDS.mjs.map +1 -0
  9. package/fesm2022/wawjs-ngx-bos.mjs +201 -184
  10. package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
  11. package/package.json +11 -9
  12. package/src/feature/file/file.component.html +1 -0
  13. package/src/feature/file/file.component.ts +34 -8
  14. package/src/feature/user/pages/clients/clients.component.ts +19 -45
  15. package/src/feature/user/pages/user-crud.component.ts +119 -0
  16. package/src/feature/user/pages/users/users.component.ts +33 -86
  17. package/src/feature/user/user.service.ts +102 -15
  18. package/src/form-components/ace/ace.component.ts +15 -1
  19. package/src/form-components/file/file.component.html +2 -2
  20. package/src/form-components/form-config-cache.ts +70 -0
  21. package/src/form-components/input/input.form.ts +1 -1
  22. package/src/form-components/select/select.component.html +24 -24
  23. package/src/form-components/tinymce/tinymce.component.ts +12 -0
  24. package/src/ngx-bos.config.ts +6 -4
  25. package/src/pages/form/form.component.ts +44 -7
  26. package/src/pages/forms/forms.component.ts +14 -2
  27. package/src/public-api.ts +1 -1
  28. package/types/wawjs-ngx-bos.d.ts +52 -15
  29. package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +0 -1
  30. package/fesm2022/wawjs-ngx-bos-user.service-DFgHcvNR.mjs.map +0 -1
@@ -48,7 +48,7 @@
48
48
  [cropHeight]="data.props.cropHeight ?? fileDefaults.cropHeight"
49
49
  [container]="data.props.container ?? fileDefaults.container"
50
50
  [name]="data.props.name ?? fileDefaults.name"
51
- [wImages]="getValue(data)"
51
+ [wImages]="getValue(data) ?? []"
52
52
  (wImagesChange)="onValueChange(data, $event)"
53
53
  ></ngx-file>
54
54
  } @default {
@@ -66,7 +66,7 @@
66
66
  [cropHeight]="data.props.cropHeight ?? fileDefaults.cropHeight"
67
67
  [container]="data.props.container ?? fileDefaults.container"
68
68
  [name]="data.props.name ?? fileDefaults.name"
69
- [wFiles]="getValue(data)"
69
+ [wFiles]="getValue(data) ?? []"
70
70
  (wFilesChange)="onValueChange(data, $event)"
71
71
  ></ngx-file>
72
72
  } }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Keeps one config object per distinct set of inputs, so editors bound to `getConfig(data)` in a
3
+ * template do not get a new config (and re-apply or re-create) on every change detection run.
4
+ *
5
+ * Plain-data inputs are matched by JSON value. Inputs that hold functions, or that cannot be
6
+ * serialized, are matched by object identity instead, because JSON drops functions and would let
7
+ * fields that differ only in callbacks share one config.
8
+ */
9
+ export class FormConfigCache<T> {
10
+ private readonly _byValue = new Map<string, T>();
11
+
12
+ private readonly _byRef = new WeakMap<object, { sources: unknown[]; config: T }[]>();
13
+
14
+ get(sources: unknown[], build: () => T): T {
15
+ const valueKey = this._valueKey(sources);
16
+
17
+ if (valueKey !== null) {
18
+ if (!this._byValue.has(valueKey)) {
19
+ this._byValue.set(valueKey, build());
20
+ }
21
+
22
+ return this._byValue.get(valueKey) as T;
23
+ }
24
+
25
+ const anchor = sources.find(
26
+ (source) => !!source && (typeof source === 'object' || typeof source === 'function'),
27
+ ) as object | undefined;
28
+
29
+ if (!anchor) {
30
+ return build();
31
+ }
32
+
33
+ const entries = this._byRef.get(anchor) ?? [];
34
+ const cached = entries.find(
35
+ (entry) =>
36
+ entry.sources.length === sources.length &&
37
+ entry.sources.every((source, index) => source === sources[index]),
38
+ );
39
+
40
+ if (cached) {
41
+ return cached.config;
42
+ }
43
+
44
+ const config = build();
45
+
46
+ entries.push({ sources: [...sources], config });
47
+ this._byRef.set(anchor, entries);
48
+
49
+ return config;
50
+ }
51
+
52
+ /** JSON key of the inputs, or `null` when they hold functions or cannot be serialized. */
53
+ private _valueKey(sources: unknown[]): string | null {
54
+ let hasFunction = false;
55
+
56
+ try {
57
+ const key = JSON.stringify(sources, (_key, value: unknown) => {
58
+ if (typeof value === 'function') {
59
+ hasFunction = true;
60
+ }
61
+
62
+ return value;
63
+ });
64
+
65
+ return hasFunction ? null : key;
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+ }
@@ -1,5 +1,5 @@
1
1
  export const inputForm = {
2
- formId: 'form',
2
+ formId: 'input',
3
3
  title: 'Form',
4
4
  components: [
5
5
  {
@@ -1,24 +1,24 @@
1
- <ng-template #templateRef let-data>
2
- <wselect
3
- [formField]="data.field"
4
- [items]="data.props.items ?? selectDefaults.items"
5
- [placeholder]="
6
- data.props.placeholder ?? selectDefaults.placeholder
7
- "
8
- [label]="data.props.label ?? selectDefaults.label"
9
- [bindLabel]="data.props.bindLabel ?? selectDefaults.bindLabel"
10
- [bindValue]="data.props.bindValue ?? selectDefaults.bindValue"
11
- [multiple]="data.props.multiple ?? selectDefaults.multiple"
12
- [clearable]="data.props.clearable ?? selectDefaults.clearable"
13
- [searchable]="data.props.searchable ?? selectDefaults.searchable"
14
- [searchableBy]="
15
- data.props.searchableBy ?? selectDefaults.searchableBy
16
- "
17
- [buttons]="data.props.buttons ?? selectDefaults.buttons"
18
- [disabled]="
19
- data.props.disabled === true ||
20
- data.component.disabled === true
21
- "
22
- (wChange)="data.props.onChange?.($event); data.wChange?.()"
23
- ></wselect>
24
- </ng-template>
1
+ <ng-template #templateRef let-data>
2
+ <wselect
3
+ [formField]="data.field"
4
+ [items]="data.props.items ?? selectDefaults.items"
5
+ [placeholder]="
6
+ data.props.placeholder ?? selectDefaults.placeholder
7
+ "
8
+ [label]="data.props.label ?? selectDefaults.label"
9
+ [bindLabel]="data.props.bindLabel ?? selectDefaults.bindLabel"
10
+ [bindValue]="data.props.bindValue ?? selectDefaults.bindValue"
11
+ [multiple]="data.props.multiple ?? selectDefaults.multiple"
12
+ [clearable]="data.props.clearable ?? selectDefaults.clearable"
13
+ [searchable]="data.props.searchable ?? selectDefaults.searchable"
14
+ [searchableBy]="
15
+ data.props.searchableBy ?? selectDefaults.searchableBy
16
+ "
17
+ [buttons]="data.props.buttons ?? selectDefaults.buttons"
18
+ [disabled]="
19
+ data.props.disabled === true ||
20
+ data.component.disabled === true
21
+ "
22
+ (wChange)="data.props.onChange?.($event); data.wChange?.()"
23
+ ></wselect>
24
+ </ng-template>
@@ -9,6 +9,7 @@ import { FormsModule } from '@angular/forms';
9
9
  import { TinymceComponent } from '@wawjs/ngx-tinymce';
10
10
  import { FormService } from '@wawjs/ngx-form';
11
11
  import { FormBridgeData } from '../form-bridge.interface';
12
+ import { FormConfigCache } from '../form-config-cache';
12
13
 
13
14
  @Component({
14
15
  templateUrl: './tinymce.component.html',
@@ -87,9 +88,20 @@ export class TinymceFormComponent implements OnInit {
87
88
 
88
89
  // ---- Props helpers (all via component.props) -----------------------------
89
90
 
91
+ /**
92
+ * The editor is re-created whenever its `config` input gets a new object, so the same props
93
+ * must give back the same config object across change detection runs.
94
+ */
95
+ private readonly _configCache = new FormConfigCache<any>();
96
+
90
97
  getConfig(data: FormBridgeData): any {
91
98
  const props = data?.props ?? {};
92
99
 
100
+ return this._configCache.get([props], () => this._buildConfig(props));
101
+ }
102
+
103
+ private _buildConfig(props: Record<string, unknown>): any {
104
+
93
105
  const toNumber = (v: unknown): number | undefined => {
94
106
  if (v === null || v === undefined || v === '') return undefined;
95
107
  const n = Number(v);
@@ -38,15 +38,17 @@ export const NGX_BOS_CONFIG = new InjectionToken<Required<NgxBosConfig>>(
38
38
  );
39
39
 
40
40
  export function ngxBosProvide(config: NgxBosConfig = {}): EnvironmentProviders {
41
+ // An explicit `undefined` (for example an unset environment value) must not replace a default.
42
+ const defined = Object.fromEntries(
43
+ Object.entries(config).filter(([, value]) => value !== undefined),
44
+ ) as NgxBosConfig;
45
+
41
46
  return makeEnvironmentProviders([
42
47
  {
43
48
  provide: NGX_BOS_CONFIG,
44
49
  useValue: {
45
50
  ...DEFAULT_NGX_BOS_CONFIG,
46
- ...config,
47
- roles: config.roles ?? DEFAULT_NGX_BOS_CONFIG.roles,
48
- userFields: config.userFields ?? DEFAULT_NGX_BOS_CONFIG.userFields,
49
- userForm: config.userForm ?? DEFAULT_NGX_BOS_CONFIG.userForm,
51
+ ...defined,
50
52
  },
51
53
  } satisfies Provider,
52
54
  ]);
@@ -1,16 +1,17 @@
1
- import { Component, computed, effect, inject } from '@angular/core';
1
+ import { Component, computed, effect, inject, untracked } from '@angular/core';
2
2
  import { toSignal } from '@angular/core/rxjs-interop';
3
3
  import { ActivatedRoute } from '@angular/router';
4
4
  import { TableComponent } from '@wawjs/ngx-ui';
5
5
  import {
6
+ createFormcomponentForm,
6
7
  Formcomponent,
7
8
  FormcomponentService,
8
- formcomponentForm,
9
9
  FormInterface,
10
10
  FormService,
11
11
  } from '@wawjs/ngx-form';
12
+ import { AlertService } from '@wawjs/ngx-ui';
12
13
  import { CrudComponent } from '@wawjs/ngx-crud';
13
- import { FORM_COMPONENT_FORM } from '../../form-components';
14
+ import { FORM_COMPONENT_FORM, FORM_COMPONENTS } from '../../form-components';
14
15
  import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
15
16
 
16
17
  @Component({
@@ -48,6 +49,27 @@ export class FormComponent extends CrudComponent<
48
49
  return false;
49
50
  }
50
51
 
52
+ /** The modal reuses one model per formId; start from an empty component, not the last one. */
53
+ protected override create() {
54
+ this._resetModel(this.createObject());
55
+
56
+ super.create();
57
+ }
58
+
59
+ protected override update(doc: Formcomponent) {
60
+ this._resetModel(doc as unknown as Record<string, unknown>);
61
+
62
+ super.update(doc);
63
+ }
64
+
65
+ private _resetModel(model: Record<string, unknown>) {
66
+ if (this.form.formId) {
67
+ this._formService.reset(this.form.formId, model);
68
+ }
69
+ }
70
+
71
+ private readonly _formService = inject(FormService);
72
+
51
73
  /** Basic columns for clients table */
52
74
  columns = ['name', 'key'];
53
75
 
@@ -57,28 +79,43 @@ export class FormComponent extends CrudComponent<
57
79
  constructor() {
58
80
  const formcomponentService = inject(FormcomponentService);
59
81
  const formService = inject(FormService);
82
+ const alertService = inject(AlertService);
60
83
 
61
84
  super(
62
- formcomponentForm,
85
+ createFormcomponentForm(FORM_COMPONENTS),
63
86
  formService,
64
87
  formcomponentService,
65
88
  'formcomponent',
66
89
  );
67
90
 
68
91
  effect(() => {
69
- // Re-filter when the route's formId changes (component is reused).
92
+ // Re-filter when the route's formId or the loaded components change (component is reused).
93
+ // setDocuments() reads and writes document signals, so it runs untracked.
70
94
  this.formId();
95
+ formcomponentService.documents();
71
96
 
72
97
  if (formcomponentService.isLoaded()) {
73
- this.setDocuments();
98
+ untracked(() => void this.setDocuments());
74
99
  }
75
100
  });
76
101
 
77
102
  this.config.buttons.unshift({
78
103
  icon: 'settings',
79
104
  click: (doc: Formcomponent) => {
105
+ const settingsForm = doc.name ? FORM_COMPONENT_FORM(doc.name) : undefined;
106
+
107
+ if (!settingsForm) {
108
+ alertService.error({ text: 'Choose a component name first' });
109
+
110
+ return;
111
+ }
112
+
113
+ if (settingsForm.formId) {
114
+ formService.reset(settingsForm.formId, doc.props || {});
115
+ }
116
+
80
117
  formService.modal<Record<string, unknown>>(
81
- FORM_COMPONENT_FORM(doc.name),
118
+ settingsForm,
82
119
  {
83
120
  label: 'Update',
84
121
  click: async (updated: unknown, close: () => void) => {
@@ -18,6 +18,11 @@ export class FormsComponent {
18
18
  {
19
19
  icon: 'edit',
20
20
  click: (form: Form) => {
21
+ // The modal reuses one model per formId; start from this form, not the last one.
22
+ if (formForm.formId) {
23
+ this._formService.reset(formForm.formId, form as unknown as Record<string, unknown>);
24
+ }
25
+
21
26
  this._formService.modal<Record<string, unknown>>(
22
27
  formForm,
23
28
  {
@@ -51,13 +56,20 @@ export class FormsComponent {
51
56
  ],
52
57
  };
53
58
 
59
+ /** Groups plain documents by formId; getSignal() writes signals, which a computed may not do. */
54
60
  readonly documents = computed<Form[]>(() => {
55
- const byFormId = this._formService.getFieldSignals('formId')();
61
+ const firstByFormId: Record<string, Form> = {};
62
+
63
+ for (const doc of this._formService.documents()) {
64
+ const formId = String(doc.formId);
65
+
66
+ firstByFormId[formId] ??= doc;
67
+ }
56
68
 
57
69
  return this._formService.formIds().map((formId) => {
58
70
  return {
71
+ ...firstByFormId[formId],
59
72
  formId,
60
- ...(byFormId[formId]?.length ? byFormId[formId][0]() : {}),
61
73
  } as Form;
62
74
  });
63
75
  });
package/src/public-api.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * the source app into the package.
6
6
  */
7
7
 
8
- export const NGX_BOS_VERSION = '22.0.5' as const;
8
+ export const NGX_BOS_VERSION = '22.0.7' as const;
9
9
 
10
10
  export type NgxBosVersion = typeof NGX_BOS_VERSION;
11
11
 
@@ -1,7 +1,7 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { EnvironmentProviders, InjectionToken, PipeTransform, Provider, TemplateRef, Type } from "@angular/core";
3
3
  import { Form, FormComponentInterface, FormInterface, Formcomponent, FormcomponentService } from "@wawjs/ngx-form";
4
- import { CrudComponent, CrudDocument, CrudService } from "@wawjs/ngx-crud";
4
+ import { CrudComponent, CrudDocument, CrudService, TableConfig } from "@wawjs/ngx-crud";
5
5
  import { SelectValue } from "@wawjs/ngx-ui";
6
6
  import { CanActivateFn, Routes } from "@angular/router";
7
7
  import { CountryCode } from "libphonenumber-js";
@@ -49,6 +49,7 @@ export declare class FileComponent {
49
49
  readonly wFiles: import("@angular/core").ModelSignal<string[]>;
50
50
  private readonly _modal;
51
51
  private readonly _fs;
52
+ private readonly _alert;
52
53
  readonly isMultiple: import("@angular/core").Signal<boolean>;
53
54
  readonly isImageMode: import("@angular/core").Signal<boolean>;
54
55
  /** Normalized list of URLs for rendering */
@@ -58,6 +59,11 @@ export declare class FileComponent {
58
59
  onPicked(input: HTMLInputElement): Promise<void>;
59
60
  removeAt(index: number): void;
60
61
  clear(): void;
62
+ /**
63
+ * The backend takes the stored file's extension from `name`; without one, images are saved
64
+ * with no extension and are later shown as plain links.
65
+ */
66
+ private _uploadName;
61
67
  private _cropStageWidth;
62
68
  private _cropStageHeight;
63
69
  private _applyNewUrls;
@@ -208,7 +214,7 @@ export declare class FileSelectorComponent {
208
214
  private _translate;
209
215
  readonly wModel: import("@angular/core").InputSignal<string | null>;
210
216
  readonly wChange: import("@angular/core").OutputEmitterRef<string | null>;
211
- readonly items: import("@angular/core").Signal<import("@wawjs/ngx-bos").File[]>;
217
+ readonly items: import("@angular/core").Signal<File$1[]>;
212
218
  readonly placeholder: import("@angular/core").WritableSignal<string>;
213
219
  onSelect(value: SelectValue): void;
214
220
  static ɵfac: i0.ɵɵFactoryDeclaration<FileSelectorComponent, never>;
@@ -284,6 +290,8 @@ export declare class UserService extends CrudService<User> {
284
290
  private readonly _router;
285
291
  private readonly _emitterService;
286
292
  private readonly _bosConfig;
293
+ /** Other CRUD collections whose cached documents and queued mutations belong to one user. */
294
+ private readonly _userScopedServices;
287
295
  readonly url: string;
288
296
  roles: string[];
289
297
  employees: string[];
@@ -291,6 +299,14 @@ export declare class UserService extends CrudService<User> {
291
299
  user: import("@angular/core").WritableSignal<User>;
292
300
  thumb: import("@angular/core").Signal<string>;
293
301
  role(role: string): boolean;
302
+ /** True when the user has at least one role (admin or any configured staff role). */
303
+ hasAnyRole(user?: User): boolean;
304
+ private _usersRequested;
305
+ /**
306
+ * Loads the user list once. The backend only gives it to users with a role (it holds emails
307
+ * and phones, and anyone can register), so plain accounts do not request it at all.
308
+ */
309
+ loadUsers(): void;
294
310
  readonly usersByRole: import("@angular/core").Signal<Record<string, User[]>>;
295
311
  constructor();
296
312
  setUser(user: User): void;
@@ -323,36 +339,51 @@ export declare class UserSelectorComponent {
323
339
  }
324
340
  export declare class UserPreviewComponent {
325
341
  userService: UserService;
326
- protected readonly bosConfig: Required<import("@wawjs/ngx-bos").NgxBosConfig>;
342
+ protected readonly bosConfig: Required<NgxBosConfig>;
327
343
  static ɵfac: i0.ɵɵFactoryDeclaration<UserPreviewComponent, never>;
328
344
  static ɵcmp: i0.ɵɵComponentDeclaration<UserPreviewComponent, "user-preview", never, {}, {}, never, never, true, never>;
329
345
  }
330
- export declare class UsersComponent extends CrudComponent<UserService, User, FormInterface> {
346
+ /**
347
+ * Shared admin behavior for the Users and Clients tables.
348
+ *
349
+ * The backend's unnamed `/api/user/update` always targets the signed-in user, and user delete only
350
+ * exists as the `admin` variant, so every mutation here goes through `updateAdmin` / `deleteAdmin`.
351
+ * Email is not an updatable key on the backend, so the edit form leaves it out.
352
+ */
353
+ declare abstract class UserCrudComponent extends CrudComponent<UserService, User, FormInterface> {
354
+ protected readonly userService: UserService;
355
+ private readonly _userFormService;
356
+ private readonly _userAlertService;
357
+ private readonly _createForm;
358
+ private readonly _editForm;
331
359
  protected configType: 'server' | 'local';
332
- private readonly _formService;
360
+ constructor();
333
361
  protected allowUrl(): boolean;
334
- protected delete(doc: User): Promise<void>;
362
+ /** Bulk edit would post every row through the self-update route, so only bulk create stays. */
363
+ protected withoutBulkEdit(config: TableConfig<User>): TableConfig<User>;
364
+ protected create(): void;
335
365
  protected update(doc: User): void;
336
- userService: UserService;
366
+ protected delete(doc: User): Promise<void>;
367
+ }
368
+ export declare class UsersComponent extends UserCrudComponent {
337
369
  /** Every role gets a checkbox column; matches the columns added in the constructor. */
338
370
  readonly roles: string[];
339
371
  columns: string[];
340
372
  config: import("@wawjs/ngx-crud").TableConfig<User>;
341
- constructor();
373
+ /** Sends a copy: the row shares its `is` object with the cached user document. */
342
374
  updateRole(user: User, role: string, value: boolean): void;
343
375
  static ɵfac: i0.ɵɵFactoryDeclaration<UsersComponent, never>;
344
376
  static ɵcmp: i0.ɵɵComponentDeclaration<UsersComponent, "ng-component", never, {}, {}, never, never, true, never>;
345
377
  }
346
378
  export declare const usersRoutes: Routes;
347
- export declare class ClientsComponent extends CrudComponent<UserService, User, FormInterface> {
348
- /** Use server-side pagination for clients */
349
- protected configType: 'server' | 'local';
379
+ export declare class ClientsComponent extends UserCrudComponent {
350
380
  /** Basic columns for clients table */
351
381
  columns: string[];
352
- /** wtable config built by CrudComponent, aware of server mode */
382
+ /**
383
+ * Local mode reads the shared user list. Server mode would replace that list with one page and
384
+ * shrink the Users table and the user selectors until reload.
385
+ */
353
386
  config: import("@wawjs/ngx-crud").TableConfig<User>;
354
- protected allowUrl(): boolean;
355
- constructor();
356
387
  static ɵfac: i0.ɵɵFactoryDeclaration<ClientsComponent, never>;
357
388
  static ɵcmp: i0.ɵɵComponentDeclaration<ClientsComponent, "ng-component", never, {}, {}, never, never, true, never>;
358
389
  }
@@ -367,6 +398,11 @@ export declare class FormComponent extends CrudComponent<FormcomponentService, F
367
398
  protected preCreate(doc: Formcomponent): void;
368
399
  protected localDocumentsFilter: (doc: Formcomponent) => boolean;
369
400
  protected allowUrl(): boolean;
401
+ /** The modal reuses one model per formId; start from an empty component, not the last one. */
402
+ protected create(): void;
403
+ protected update(doc: Formcomponent): void;
404
+ private _resetModel;
405
+ private readonly _formService;
370
406
  /** Basic columns for clients table */
371
407
  columns: string[];
372
408
  /** wtable config built by CrudComponent, aware of server mode */
@@ -391,6 +427,7 @@ export declare class FormsComponent {
391
427
  click?: undefined;
392
428
  })[];
393
429
  };
430
+ /** Groups plain documents by formId; getSignal() writes signals, which a computed may not do. */
394
431
  readonly documents: import("@angular/core").Signal<Form[]>;
395
432
  static ɵfac: i0.ɵɵFactoryDeclaration<FormsComponent, never>;
396
433
  static ɵcmp: i0.ɵɵComponentDeclaration<FormsComponent, "ng-component", never, {}, {}, never, never, true, never>;
@@ -430,6 +467,6 @@ export declare class PhonePipe implements PipeTransform {
430
467
  static ɵfac: i0.ɵɵFactoryDeclaration<PhonePipe, never>;
431
468
  static ɵpipe: i0.ɵɵPipeDeclaration<PhonePipe, "phone", true>;
432
469
  }
433
- export declare const NGX_BOS_VERSION: "22.0.5";
470
+ export declare const NGX_BOS_VERSION: "22.0.7";
434
471
  export type NgxBosVersion = typeof NGX_BOS_VERSION;
435
472
  export { File$1 as File };
@@ -1 +0,0 @@
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',\r\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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wawjs-ngx-bos-user.service-DFgHcvNR.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';\r\n\r\n/** localStorage key holding the signed-in user snapshot. */\r\nexport const USER_STORAGE_KEY = 'waw_user';\r\n\r\n/**\r\n * Reads the stored user snapshot. Returns `null` when nothing is stored or when the\r\n * stored value is corrupted; a corrupted value is removed so it cannot break guards\r\n * or service initialization again.\r\n */\r\nexport function readStoredUser(): User | null {\r\n\tconst stored = localStorage.getItem(USER_STORAGE_KEY);\r\n\r\n\tif (!stored) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\ttry {\r\n\t\tconst user = JSON.parse(stored) as User | null;\r\n\r\n\t\tif (user && typeof user === 'object') {\r\n\t\t\treturn user;\r\n\t\t}\r\n\t} catch {\r\n\t\t// fall through to cleanup\r\n\t}\r\n\r\n\tlocalStorage.removeItem(USER_STORAGE_KEY);\r\n\r\n\treturn null;\r\n}\r\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\t// Reload only after the server has cleared the session cookie: reloading right away can\r\n\t\t// cancel the request and leave the session alive. Do not wait longer than 3s if the API is down.\r\n\t\tlet finished = false;\r\n\r\n\t\tconst finish = () => {\r\n\t\t\tif (finished) return;\r\n\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tthis._router.navigateByUrl(this._bosConfig.signPath);\r\n\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\tlocation.reload();\r\n\t\t\t}, 100);\r\n\t\t};\r\n\r\n\t\tthis._userHttpService.get('/api/user/logout', finish, { err: finish });\r\n\r\n\t\tthis._userHttpService.remove('token');\r\n\r\n\t\tsetTimeout(finish, 3000);\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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