@posiwise/user-module 0.0.189 → 0.0.191

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.
@@ -12,7 +12,7 @@ import { TrackDirtyFormDirective } from "@posiwise/core-guards";
12
12
  import { CoreTranslocoModule } from "@posiwise/core-transloco";
13
13
  import { ButtonBusyDirective, DirectivesModule, DynamicBadgeDirective, LazyImgDirective, RbacAllowDirective } from "@posiwise/directives";
14
14
  import { CurrencySymbolPipe, DateFormatPipe, PipesModule } from "@posiwise/pipes";
15
- import { AiKnowledgeComponent, ConfirmDialogService, InputContainerComponent, NoDataComponent, NumberPickerComponent, PasswordValidationComponent, PrivacyAndTosComponent, PwStickyActionsComponent, PwTabsComponent, RecordsSummaryComponent, SharedComponentsModule } from "@posiwise/shared-components";
15
+ import { AiKnowledgeComponent, AiMemoryComponent, ConfirmDialogService, InputContainerComponent, NoDataComponent, NumberPickerComponent, PasswordValidationComponent, PrivacyAndTosComponent, PwStickyActionsComponent, PwTabsComponent, RecordsSummaryComponent, SharedComponentsModule } from "@posiwise/shared-components";
16
16
  import * as i2 from "ngx-captcha";
17
17
  import { NgxCaptchaModule } from "ngx-captcha";
18
18
  import * as i3 from "ngx-ui-switch";
@@ -28,18 +28,18 @@ import { Select, SelectModule } from "primeng/select";
28
28
  import { SelectButton, SelectButtonModule } from "primeng/selectbutton";
29
29
  import { Tooltip, TooltipModule } from "primeng/tooltip";
30
30
  import { Loader } from "@googlemaps/js-api-loader";
31
- import { NgbDatepickerModule, NgbInputDatepicker, NgbModal, NgbModalModule } from "@ng-bootstrap/ng-bootstrap";
31
+ import { NgbDatepickerModule, NgbInputDatepicker, NgbModal, NgbModalModule, NgbNav, NgbNavContent, NgbNavItem, NgbNavLink, NgbNavOutlet } from "@ng-bootstrap/ng-bootstrap";
32
32
  import { __decorate } from "tslib";
33
- import { AppBaseComponent } from "@posiwise/app-base-component";
34
33
  import { AuthService, CommonService, CustomToastService, FormHelperService, GeoService, PermissionService, ProductService, ProfileService, QualificationService, ScriptLoaderService, SubscriptionService, TagService, UserService, ValidationService, hasKnowledgeAlpha, isInMobileWebView } from "@posiwise/common-services";
35
34
  import { AppUser, POLL_TIMEOUT, PRODUCT_CATEGORY, Project, TAG_ENTITY, TAG_TYPE } from "@posiwise/common-utilities";
36
35
  import { HelperService } from "@posiwise/helper-service";
37
36
  import { ProfileImageCropperComponent, ValidateForm, appendQueryParam, clearQueryParams } from "@posiwise/utils";
38
- import { StatusCodes } from "http-status-codes";
39
37
  import { Bind } from "primeng/bind";
40
38
  import { EMPTY, combineLatest, firstValueFrom, forkJoin, interval, map, of, throwError, timer } from "rxjs";
41
- import { getDomain } from "tldts";
42
39
  import { TranslocoPipe, TranslocoService } from "@jsverse/transloco";
40
+ import { StatusCodes } from "http-status-codes";
41
+ import { getDomain } from "tldts";
42
+ import { AppBaseComponent } from "@posiwise/app-base-component";
43
43
  import cloneDeep from "lodash/cloneDeep";
44
44
  import sortBy from "lodash/sortBy";
45
45
  import { catchError, map as map$1, mergeMap, switchMap } from "rxjs/operators";
@@ -145,83 +145,184 @@ const MCP_ENV_SEGMENTS = [
145
145
  "go"
146
146
  ];
147
147
  const MCP_PROD_SEGMENT = "go";
148
- var AccountDetailsComponent = class AccountDetailsComponent extends AppBaseComponent {
148
+ function mcpHostBase(hostname) {
149
+ const companyDomain = getDomain(hostname, { allowPrivateDomains: true });
150
+ if (!companyDomain) return hostname;
151
+ const prefix = hostname.slice(0, -companyDomain.length).split(".").filter(Boolean);
152
+ const segment = prefix[prefix.length - 1];
153
+ return `${MCP_ENV_SEGMENTS.includes(segment) ? segment : MCP_PROD_SEGMENT}.${companyDomain}`;
154
+ }
155
+ function toDobStruct(dob) {
156
+ let dobObject;
157
+ if (dob) dobObject = {
158
+ day: Number(dob.substring(8, 10)),
159
+ month: Number(dob.substring(5, 7)),
160
+ year: Number(dob.substring(0, 4))
161
+ };
162
+ return dobObject;
163
+ }
164
+ function copyApiKeysToUser(user) {
165
+ if (user && user.api_keys) {
166
+ if (user.api_keys.api_user_token && !user.api_user_token) user.api_user_token = user.api_keys.api_user_token;
167
+ if (user.api_keys.api_user_id && !user.api_user_id) user.api_user_id = user.api_keys.api_user_id;
168
+ if (user.api_keys.api_hits !== void 0 && user.api_hits === void 0) user.api_hits = user.api_keys.api_hits;
169
+ if (user.api_keys.api_hits_max !== void 0 && user.api_hits_max === void 0) user.api_hits_max = user.api_keys.api_hits_max;
170
+ }
171
+ }
172
+ function mergeRefreshedApiKeys(user, result) {
173
+ if (result && result.api_keys) {
174
+ if (!user.api_keys) user.api_keys = {};
175
+ if (result.api_keys.api_user_token) user.api_keys.api_user_token = result.api_keys.api_user_token;
176
+ if (result.api_keys.api_user_id) user.api_keys.api_user_id = result.api_keys.api_user_id;
177
+ if (result.api_keys.api_hits !== void 0) user.api_keys.api_hits = result.api_keys.api_hits;
178
+ if (result.api_keys.api_hits_max !== void 0) user.api_keys.api_hits_max = result.api_keys.api_hits_max;
179
+ }
180
+ }
181
+ function passwordMatcher(ac) {
182
+ if (ac.get("newPassword").value !== ac.get("confirmPassword").value) ac.get("confirmPassword").setErrors({ MatchPassword: true });
183
+ return null;
184
+ }
185
+ function dataUrlToBlob(dataUrl) {
186
+ const arr = dataUrl.split(",");
187
+ const mime = /^[A-Z]*[a-z]*:(.*?);[A-Z]*/.exec(arr[0])?.[1];
188
+ const bStr = atob(arr[1]);
189
+ let n = bStr.length;
190
+ const u8arr = new Uint8Array(n);
191
+ while (n--) u8arr[n] = bStr.charCodeAt(n);
192
+ return new Blob([u8arr], { type: mime });
193
+ }
194
+ var AccountApiCredentials = class extends AppBaseComponent {
149
195
  constructor() {
150
- super();
151
- this.fb = inject(FormBuilder);
152
- this.modalService = inject(NgbModal);
153
- this.authService = inject(AuthService);
154
- this.geoService = inject(GeoService);
155
- this.profileService = inject(ProfileService);
196
+ super(...arguments);
156
197
  this.cdr = inject(ChangeDetectorRef);
157
198
  this.confirmDialog = inject(ConfirmDialogService);
158
- this.transloco = inject(TranslocoService);
159
- this.image = "assets/img/icons/male.png";
160
- this.states = [];
161
- this.passwordVerified = false;
162
- this.isCurrentPasswordValid = true;
163
- this.isLoaded = false;
164
- this.passwordBusyButton = false;
165
- this.slugBusyButton = false;
166
- this.emailBusyButton = false;
167
- this.validatePasswordBusyButton = false;
168
- this.profileBusyButton = false;
169
199
  this.showApiToken = false;
170
200
  this.showApiClientId = false;
171
201
  this.refreshingTokens = false;
172
202
  this.updatingScope = false;
173
- this.connections = [];
174
- this.loadingConnections = false;
175
- this.getForms();
176
203
  }
177
- ngOnInit() {
178
- console.log("AccountDetailsComponent.ngOnInit()");
179
- this.getUserProfile();
180
- this.loadConnections();
181
- this.geoService.getCountries().subscribe(() => {
182
- this.countries$ = combineLatest([this.geoService.getCountries(), this.transloco.selectTranslate("User.Profile.SelectCountry")]).pipe(map(([countries, label]) => [{
183
- name: label,
184
- code: null
185
- }, ...countries]));
204
+ toggleApiTokenVisibility() {
205
+ this.showApiToken = !this.showApiToken;
206
+ }
207
+ toggleApiClientIdVisibility() {
208
+ this.showApiClientId = !this.showApiClientId;
209
+ }
210
+ refreshApiTokens() {
211
+ this.confirmDialog.open({
212
+ title: this.translation.translate("User.Subscriptions.APICredentials.RefreshConfirmTitle"),
213
+ text: this.translation.translate("User.Subscriptions.APICredentials.RefreshWarning"),
214
+ destructive: true,
215
+ confirmLabel: this.translation.translate("User.Subscriptions.APICredentials.RefreshConfirmLabel")
216
+ }).then((ok) => {
217
+ if (ok) this.performTokenRefresh();
218
+ });
219
+ }
220
+ performTokenRefresh() {
221
+ this.refreshingTokens = true;
222
+ this.userService.refreshUserApiTokens().subscribe({ next: ({ result }) => {
223
+ mergeRefreshedApiKeys(this.user, result);
224
+ this.showApiToken = false;
225
+ this.showApiClientId = false;
226
+ this.getUserProfile();
227
+ this.cdr.markForCheck();
228
+ } }).add(() => {
229
+ this.refreshingTokens = false;
186
230
  this.cdr.markForCheck();
187
231
  });
188
232
  }
189
- handleAddressChange(_event) {
190
- this.profileForm.patchValue({
191
- latitude: _event.geometry.location.lat(),
192
- longitude: _event.geometry.location.lng(),
193
- location: _event.formatted_address
233
+ get currentApiTokenScope() {
234
+ return this.user?.api_keys?.api_token_scope ?? "read_only";
235
+ }
236
+ changeApiTokenScope(scope) {
237
+ if (this.updatingScope || scope === this.currentApiTokenScope) return;
238
+ this.confirmDialog.open({
239
+ title: this.translation.translate("User.Subscriptions.APICredentials.ScopeConfirmTitle"),
240
+ text: this.translation.translate(scope === "read_write" ? "User.Subscriptions.APICredentials.ScopeWriteWarning" : "User.Subscriptions.APICredentials.ScopeReadWarning"),
241
+ destructive: scope === "read_write",
242
+ confirmLabel: this.translation.translate("User.Subscriptions.APICredentials.ScopeConfirmLabel")
243
+ }).then((ok) => {
244
+ if (ok) this.performScopeUpdate(scope);
194
245
  });
195
246
  }
196
- getUserProfile() {
197
- this.userService.getUserInfo().subscribe((user) => {
198
- if (user) {
199
- this.user = user;
200
- this.slug = user.slug;
201
- if (user?.user_avatar?.length) this.image = user?.user_avatar[2]?.url;
202
- let dobObject;
203
- if (user.dob) dobObject = {
204
- day: Number(user.dob.substring(8, 10)),
205
- month: Number(user.dob.substring(5, 7)),
206
- year: Number(user.dob.substring(0, 4))
207
- };
208
- this.getRegion(user.country);
209
- if (user && user.api_keys) {
210
- if (user.api_keys.api_user_token && !user.api_user_token) this.user.api_user_token = user.api_keys.api_user_token;
211
- if (user.api_keys.api_user_id && !user.api_user_id) this.user.api_user_id = user.api_keys.api_user_id;
212
- if (user.api_keys.api_hits !== void 0 && user.api_hits === void 0) this.user.api_hits = user.api_keys.api_hits;
213
- if (user.api_keys.api_hits_max !== void 0 && user.api_hits_max === void 0) this.user.api_hits_max = user.api_keys.api_hits_max;
214
- }
215
- this.profileForm.patchValue(this.user);
216
- this.profileForm.patchValue({ dob: dobObject });
217
- this.validatedEmail = this.user.email;
247
+ performScopeUpdate(scope) {
248
+ this.updatingScope = true;
249
+ this.userService.updateApiTokenScope(scope).subscribe({
250
+ next: () => {
251
+ if (!this.user.api_keys) this.user.api_keys = {};
252
+ this.user.api_keys.api_token_scope = scope;
253
+ this.toast.success(this.translation.translate("User.Subscriptions.APICredentials.ScopeUpdated"));
254
+ this.cdr.markForCheck();
255
+ },
256
+ error: () => {
257
+ this.toast.error(this.translation.translate("User.Subscriptions.APICredentials.ScopeUpdateFailed"));
258
+ this.cdr.markForCheck();
218
259
  }
219
- this.cdr.markForCheck();
220
260
  }).add(() => {
221
- this.isLoaded = true;
261
+ this.updatingScope = false;
222
262
  this.cdr.markForCheck();
223
263
  });
224
264
  }
265
+ };
266
+ var AccountMcpConnections = class extends AccountApiCredentials {
267
+ constructor() {
268
+ super(...arguments);
269
+ this.connections = [];
270
+ this.loadingConnections = false;
271
+ }
272
+ get mcpEndpointUrl() {
273
+ const url = `https://brain-api-mcp.${mcpHostBase(window.location.hostname)}/mcp`;
274
+ const shard = this.user?.user_shard;
275
+ return shard ? `${url}?user_shard=${encodeURIComponent(shard)}` : url;
276
+ }
277
+ get mcpCompanyName() {
278
+ return this.appConfig?.company?.name || "PosiWise";
279
+ }
280
+ loadConnections() {
281
+ this.loadingConnections = true;
282
+ this.userService.getMcpConnections().subscribe({ next: (response) => {
283
+ this.connections = response?.result ?? [];
284
+ this.cdr.markForCheck();
285
+ } }).add(() => {
286
+ this.loadingConnections = false;
287
+ this.cdr.markForCheck();
288
+ });
289
+ }
290
+ deregisterConnection(id) {
291
+ this.confirmDialog.open({
292
+ title: this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterConfirmTitle"),
293
+ text: this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterConfirmText"),
294
+ destructive: true,
295
+ confirmLabel: this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterConfirmButton")
296
+ }).then((ok) => {
297
+ if (!ok) return;
298
+ this.userService.deleteMcpConnection(id).subscribe({
299
+ next: () => {
300
+ this.loadConnections();
301
+ },
302
+ error: () => {
303
+ this.toast.error(this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterFailed"));
304
+ }
305
+ });
306
+ });
307
+ }
308
+ };
309
+ var AccountSecurityForms = class extends AccountMcpConnections {
310
+ constructor() {
311
+ super(...arguments);
312
+ this.fb = inject(FormBuilder);
313
+ this.authService = inject(AuthService);
314
+ this.emailForm = this.fb.group({ email: ["", [Validators.required, Validators.email]] });
315
+ this.passwordForm = this.fb.group({
316
+ currentPassword: ["", [Validators.required]],
317
+ newPassword: ["", [Validators.required, Validators.minLength(8)]],
318
+ confirmPassword: ["", [Validators.required, Validators.minLength(8)]]
319
+ }, { validators: passwordMatcher });
320
+ this.passwordVerified = false;
321
+ this.isCurrentPasswordValid = true;
322
+ this.passwordBusyButton = false;
323
+ this.emailBusyButton = false;
324
+ this.validatePasswordBusyButton = false;
325
+ }
225
326
  onEmailFormSubmit() {
226
327
  this.emailBusyButton = true;
227
328
  const data = this.emailForm.value;
@@ -229,7 +330,7 @@ var AccountDetailsComponent = class AccountDetailsComponent extends AppBaseCompo
229
330
  if (data && this.passwordVerified) this.userService.updateEmail(data).subscribe(() => {
230
331
  this.emailForm.reset();
231
332
  this.passwordVerified = false;
232
- this.toast.success(`A verification email has been sent to ${data.email}`, "", {
333
+ this.toast.success(this.translation.translate("User.Account.Message.VerificationEmailSent", { email: data.email }), "", {
233
334
  positionClass: "toast-top-center",
234
335
  timeOut: 1e5
235
336
  });
@@ -254,9 +355,6 @@ var AccountDetailsComponent = class AccountDetailsComponent extends AppBaseCompo
254
355
  this.cdr.markForCheck();
255
356
  });
256
357
  }
257
- handleImageError(event, fallbackPath) {
258
- HelperService.handleImageFallbackPath(event, fallbackPath);
259
- }
260
358
  checkValidity() {
261
359
  if (this.passwordRef.nativeElement.value.length > 5) this.isCurrentPasswordValid = false;
262
360
  else this.isCurrentPasswordValid = true;
@@ -282,31 +380,36 @@ var AccountDetailsComponent = class AccountDetailsComponent extends AppBaseCompo
282
380
  });
283
381
  }
284
382
  }
285
- onProfileFormSubmit() {
286
- this.profileBusyButton = true;
287
- const data = { ...this.profileForm.value };
288
- data.dob = HelperService.dateFormat(this.profileForm.get("dob")?.value);
289
- if (data.location === "") data.location = null;
290
- Object.entries(data).forEach(([key, val]) => {
291
- if (val === "" || val === null) delete data[key];
292
- });
293
- this.profileService.updateUserProfile(data).subscribe(() => {
294
- this.profileForm.markAsPristine();
295
- this.toast.success(this.translation.translate("User.Profile.ProfileUpdated"));
296
- this.cdr.markForCheck();
297
- }).add(() => {
298
- this.profileBusyButton = false;
383
+ sendMailToResetPassword() {
384
+ this.authService.forgotPassword(this.user.email, "reset-password").subscribe(() => {
385
+ this.toast.success(this.translation.translate("User.Account.Message.CheckEmail"));
299
386
  this.cdr.markForCheck();
300
387
  });
301
388
  }
302
- onAvatarSave() {
303
- const data = { avatar: this.profileForm.get("avatar")?.value };
304
- this.profileService.updateUserProfile(data).subscribe(() => {
305
- this.profileForm.markAsPristine();
306
- this.toast.success(this.translation.translate("User.Profile.ProfileUpdated"));
307
- this.cdr.markForCheck();
389
+ onToggleEmail() {
390
+ this.emailForm.reset();
391
+ this.passwordVerified = false;
392
+ this.toggleEmail = false;
393
+ }
394
+ onTogglePassword() {
395
+ this.passwordForm.reset();
396
+ this.togglePassword = false;
397
+ }
398
+ shouldUserChangeEmail() {
399
+ if (this.user.has_password) this.toggleEmail = !this.toggleEmail;
400
+ else this.confirmDialog.open({
401
+ textKey: "User.Account.Email.NoPassword",
402
+ confirmOnly: true
308
403
  });
309
404
  }
405
+ };
406
+ var AccountAvatarSlug = class extends AccountSecurityForms {
407
+ constructor() {
408
+ super(...arguments);
409
+ this.modalService = inject(NgbModal);
410
+ this.image = "assets/img/icons/male.png";
411
+ this.slugBusyButton = false;
412
+ }
310
413
  openModal(content) {
311
414
  this.modalService.open(content, {
312
415
  centered: true,
@@ -335,169 +438,95 @@ var AccountDetailsComponent = class AccountDetailsComponent extends AppBaseCompo
335
438
  this.cdr.markForCheck();
336
439
  });
337
440
  }
338
- sendMailToResetPassword() {
339
- this.authService.forgotPassword(this.user.email, "reset-password").subscribe(() => {
340
- this.toast.success(this.translation.translate("User.Account.Message.CheckEmail"));
341
- this.cdr.markForCheck();
342
- });
343
- }
344
- getRegion(countryId) {
345
- if (countryId) this.geoService.getRegions(countryId).subscribe((response) => {
346
- this.states = [{
347
- code: 0,
348
- name: "Select State"
349
- }, ...response];
350
- this.cdr.markForCheck();
351
- });
352
- }
353
- loadConnections() {
354
- this.loadingConnections = true;
355
- this.userService.getMcpConnections().subscribe({ next: (response) => {
356
- this.connections = response?.result ?? [];
357
- this.cdr.markForCheck();
358
- } }).add(() => {
359
- this.loadingConnections = false;
360
- this.cdr.markForCheck();
361
- });
362
- }
363
- deregisterConnection(id) {
364
- this.confirmDialog.open({
365
- title: this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterConfirmTitle"),
366
- text: this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterConfirmText"),
367
- destructive: true,
368
- confirmLabel: this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterConfirmButton")
369
- }).then((ok) => {
370
- if (!ok) return;
371
- this.userService.deleteMcpConnection(id).subscribe({
372
- next: () => {
373
- this.loadConnections();
374
- },
375
- error: () => {
376
- this.toast.error(this.translation.translate("User.Subscriptions.RegisteredApps.DeregisterFailed"));
377
- }
378
- });
379
- });
380
- }
381
- getForms() {
382
- this.emailForm = this.fb.group({ email: ["", [Validators.required, Validators.email]] });
383
- this.passwordForm = this.fb.group({
384
- currentPassword: ["", [Validators.required]],
385
- newPassword: ["", [Validators.required, Validators.minLength(8)]],
386
- confirmPassword: ["", [Validators.required, Validators.minLength(8)]]
387
- }, { validators: this.passwordMatcher });
388
- this.profileForm = AppUser.getForm(new AppUser({}));
389
- }
390
- passwordMatcher(ac) {
391
- if (ac.get("newPassword").value !== ac.get("confirmPassword").value) ac.get("confirmPassword").setErrors({ MatchPassword: true });
392
- return null;
393
- }
394
441
  dataURLtoBlob(dataUrl) {
395
- const arr = dataUrl.split(",");
396
- const mime = /^[A-Z]*[a-z]*:(.*?);[A-Z]*/.exec(arr[0])?.[1];
397
- const bStr = atob(arr[1]);
398
- let n = bStr.length;
399
- const u8arr = new Uint8Array(n);
400
- while (n--) u8arr[n] = bStr.charCodeAt(n);
401
- return new Blob([u8arr], { type: mime });
402
- }
403
- onToggleEmail() {
404
- this.emailForm.reset();
405
- this.passwordVerified = false;
406
- this.toggleEmail = false;
407
- }
408
- onTogglePassword() {
409
- this.passwordForm.reset();
410
- this.togglePassword = false;
442
+ return dataUrlToBlob(dataUrl);
411
443
  }
412
444
  onClose() {
413
445
  this.modalService.dismissAll();
414
446
  }
415
- shouldUserChangeEmail() {
416
- if (this.user.has_password) this.toggleEmail = !this.toggleEmail;
417
- else this.confirmDialog.open({
418
- textKey: "User.Account.Email.NoPassword",
419
- confirmOnly: true
420
- });
421
- }
422
- toggleApiTokenVisibility() {
423
- this.showApiToken = !this.showApiToken;
447
+ };
448
+ var AccountDetailsComponent = class AccountDetailsComponent extends AccountAvatarSlug {
449
+ constructor() {
450
+ super(...arguments);
451
+ this.geoService = inject(GeoService);
452
+ this.profileService = inject(ProfileService);
453
+ this.transloco = inject(TranslocoService);
454
+ this.profileForm = AppUser.getForm(new AppUser({}));
455
+ this.states = [];
456
+ this.isLoaded = false;
457
+ this.profileBusyButton = false;
424
458
  }
425
- toggleApiClientIdVisibility() {
426
- this.showApiClientId = !this.showApiClientId;
459
+ ngOnInit() {
460
+ console.log("AccountDetailsComponent.ngOnInit()");
461
+ this.getUserProfile();
462
+ this.loadConnections();
463
+ this.geoService.getCountries().subscribe(() => {
464
+ this.countries$ = combineLatest([this.geoService.getCountries(), this.transloco.selectTranslate("User.Profile.SelectCountry")]).pipe(map(([countries, label]) => [{
465
+ name: label,
466
+ code: null
467
+ }, ...countries]));
468
+ this.cdr.markForCheck();
469
+ });
427
470
  }
428
- refreshApiTokens() {
429
- this.confirmDialog.open({
430
- title: "Are you sure?",
431
- text: this.translation.translate("User.Subscriptions.APICredentials.RefreshWarning"),
432
- destructive: true,
433
- confirmLabel: "Yes, refresh tokens!"
434
- }).then((ok) => {
435
- if (ok) this.performTokenRefresh();
471
+ handleAddressChange(_event) {
472
+ this.profileForm.patchValue({
473
+ latitude: _event.geometry.location.lat(),
474
+ longitude: _event.geometry.location.lng(),
475
+ location: _event.formatted_address
436
476
  });
437
477
  }
438
- performTokenRefresh() {
439
- this.refreshingTokens = true;
440
- this.userService.refreshUserApiTokens().subscribe({ next: ({ result }) => {
441
- if (result && result.api_keys) {
442
- if (!this.user.api_keys) this.user.api_keys = {};
443
- if (result.api_keys.api_user_token) this.user.api_keys.api_user_token = result.api_keys.api_user_token;
444
- if (result.api_keys.api_user_id) this.user.api_keys.api_user_id = result.api_keys.api_user_id;
445
- if (result.api_keys.api_hits !== void 0) this.user.api_keys.api_hits = result.api_keys.api_hits;
446
- if (result.api_keys.api_hits_max !== void 0) this.user.api_keys.api_hits_max = result.api_keys.api_hits_max;
478
+ getUserProfile() {
479
+ this.userService.getUserInfo().subscribe((user) => {
480
+ if (user) {
481
+ this.user = user;
482
+ this.slug = user.slug;
483
+ if (user?.user_avatar?.length) this.image = user?.user_avatar[2]?.url;
484
+ this.getRegion(user.country);
485
+ copyApiKeysToUser(this.user);
486
+ this.profileForm.patchValue(this.user);
487
+ this.profileForm.patchValue({ dob: toDobStruct(user.dob) });
488
+ this.validatedEmail = this.user.email;
447
489
  }
448
- this.showApiToken = false;
449
- this.showApiClientId = false;
450
- this.getUserProfile();
451
490
  this.cdr.markForCheck();
452
- } }).add(() => {
453
- this.refreshingTokens = false;
491
+ }).add(() => {
492
+ this.isLoaded = true;
454
493
  this.cdr.markForCheck();
455
494
  });
456
495
  }
457
- get currentApiTokenScope() {
458
- return this.user?.api_keys?.api_token_scope ?? "read_only";
459
- }
460
- get mcpEndpointUrl() {
461
- const url = `https://brain-api-mcp.${this.mcpHostBase(window.location.hostname)}/mcp`;
462
- const shard = this.user?.user_shard;
463
- return shard ? `${url}?user_shard=${encodeURIComponent(shard)}` : url;
464
- }
465
- mcpHostBase(hostname) {
466
- const companyDomain = getDomain(hostname, { allowPrivateDomains: true });
467
- if (!companyDomain) return hostname;
468
- const prefix = hostname.slice(0, -companyDomain.length).split(".").filter(Boolean);
469
- const segment = prefix[prefix.length - 1];
470
- return `${MCP_ENV_SEGMENTS.includes(segment) ? segment : MCP_PROD_SEGMENT}.${companyDomain}`;
496
+ handleImageError(event, fallbackPath) {
497
+ HelperService.handleImageFallbackPath(event, fallbackPath);
471
498
  }
472
- get mcpCompanyName() {
473
- return this.appConfig?.company?.name || "PosiWise";
499
+ onProfileFormSubmit() {
500
+ this.profileBusyButton = true;
501
+ const data = { ...this.profileForm.value };
502
+ data.dob = HelperService.dateFormat(this.profileForm.get("dob")?.value);
503
+ if (data.location === "") data.location = null;
504
+ Object.entries(data).forEach(([key, val]) => {
505
+ if (val === "" || val === null) delete data[key];
506
+ });
507
+ this.profileService.updateUserProfile(data).subscribe(() => {
508
+ this.profileForm.markAsPristine();
509
+ this.toast.success(this.translation.translate("User.Profile.ProfileUpdated"));
510
+ this.cdr.markForCheck();
511
+ }).add(() => {
512
+ this.profileBusyButton = false;
513
+ this.cdr.markForCheck();
514
+ });
474
515
  }
475
- changeApiTokenScope(scope) {
476
- if (this.updatingScope || scope === this.currentApiTokenScope) return;
477
- this.confirmDialog.open({
478
- title: this.translation.translate("User.Subscriptions.APICredentials.ScopeConfirmTitle"),
479
- text: this.translation.translate(scope === "read_write" ? "User.Subscriptions.APICredentials.ScopeWriteWarning" : "User.Subscriptions.APICredentials.ScopeReadWarning"),
480
- destructive: scope === "read_write",
481
- confirmLabel: this.translation.translate("User.Subscriptions.APICredentials.ScopeConfirmLabel")
482
- }).then((ok) => {
483
- if (ok) this.performScopeUpdate(scope);
516
+ onAvatarSave() {
517
+ const data = { avatar: this.profileForm.get("avatar")?.value };
518
+ this.profileService.updateUserProfile(data).subscribe(() => {
519
+ this.profileForm.markAsPristine();
520
+ this.toast.success(this.translation.translate("User.Profile.ProfileUpdated"));
521
+ this.cdr.markForCheck();
484
522
  });
485
523
  }
486
- performScopeUpdate(scope) {
487
- this.updatingScope = true;
488
- this.userService.updateApiTokenScope(scope).subscribe({
489
- next: () => {
490
- if (!this.user.api_keys) this.user.api_keys = {};
491
- this.user.api_keys.api_token_scope = scope;
492
- this.toast.success(this.translation.translate("User.Subscriptions.APICredentials.ScopeUpdated"));
493
- this.cdr.markForCheck();
494
- },
495
- error: () => {
496
- this.toast.error(this.translation.translate("User.Subscriptions.APICredentials.ScopeUpdateFailed"));
497
- this.cdr.markForCheck();
498
- }
499
- }).add(() => {
500
- this.updatingScope = false;
524
+ getRegion(countryId) {
525
+ if (countryId) this.geoService.getRegions(countryId).subscribe((response) => {
526
+ this.states = [{
527
+ code: 0,
528
+ name: "Select State"
529
+ }, ...response];
501
530
  this.cdr.markForCheck();
502
531
  });
503
532
  }
@@ -507,7 +536,7 @@ var AccountDetailsComponent = class AccountDetailsComponent extends AppBaseCompo
507
536
  version: "22.2.3",
508
537
  ngImport: i0,
509
538
  type: AccountDetailsComponent,
510
- deps: [],
539
+ deps: null,
511
540
  target: i0.ɵɵFactoryTarget.Component
512
541
  });
513
542
  }
@@ -884,7 +913,6 @@ i0.ɵɵngDeclareClassMetadata({
884
913
  styles: [".card .mb-2:last-child,.card .mb-3:last-child{margin-bottom:0!important}.overlay{left:50%;opacity:0;position:absolute;text-align:center;top:50%;transform:translate(-50%,-50%);transition:.5s ease}.image-container{position:relative}.image-container:hover .image{opacity:.3}.image-container:hover .overlay{opacity:0}.overlay-text{background:#f0efef80;border-radius:50%;color:#000;font-size:16px;height:150px;line-height:150px;text-align:center;vertical-align:middle;width:150px}@media screen and (max-width:767px){.card-body{padding:20px!important}}\n"]
885
914
  }]
886
915
  }],
887
- ctorParameters: () => [],
888
916
  propDecorators: {
889
917
  placesRef: [{
890
918
  type: ViewChild,
@@ -2648,29 +2676,22 @@ i0.ɵɵngDeclareClassMetadata({
2648
2676
  ctorParameters: () => [],
2649
2677
  propDecorators: { onSave: [] }
2650
2678
  });
2651
- var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends AppBaseComponent {
2652
- get isFree() {
2653
- return !this.product?.stripe_plan_id && !Number(this.product?.price_per_unit);
2654
- }
2655
- get totalAmount() {
2656
- if (this.product) {
2657
- const units = Number(this.form.get("units").value);
2658
- if (!Number.isNaN(units)) return units * this.product.price_per_unit / 100;
2659
- }
2660
- return 0;
2661
- }
2679
+ function stripeCard(value) {
2680
+ return {
2681
+ number: value.card_number,
2682
+ cvc: value.cvc,
2683
+ exp_month: value.exp_month,
2684
+ exp_year: value.exp_year
2685
+ };
2686
+ }
2687
+ var UpgradeSubscriptionPayment = class extends AppBaseComponent {
2662
2688
  constructor() {
2663
- super();
2664
- this.productService = inject(ProductService);
2689
+ super(...arguments);
2665
2690
  this.fb = inject(FormBuilder);
2666
2691
  this.modalService = inject(NgbModal);
2667
2692
  this.subscriptionService = inject(SubscriptionService);
2668
2693
  this.store = inject(Store);
2669
- this.scriptLoader = inject(ScriptLoaderService);
2670
2694
  this.cdr = inject(ChangeDetectorRef);
2671
- this.confirmDialog = inject(ConfirmDialogService);
2672
- this.months = [];
2673
- this.years = [];
2674
2695
  this.form = this.fb.group({
2675
2696
  card_number: ["", Validators.required],
2676
2697
  units: [],
@@ -2679,61 +2700,8 @@ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends Ap
2679
2700
  exp_year: ["", Validators.required]
2680
2701
  });
2681
2702
  }
2682
- ngOnInit() {
2683
- this.scriptLoader.loadScriptOnce("head", "https://js.stripe.com/v2/");
2684
- this.years = HelperService.getYears();
2685
- this.months = HelperService.getMonths();
2686
- this.userStore().subscribe((user) => {
2687
- this.user = user;
2688
- this.cdr.markForCheck();
2689
- });
2690
- this.route.params.subscribe((response) => {
2691
- this.subscriptionId = +response["subscriptionId"];
2692
- this.productId = +response["productId"];
2693
- this.getSubscriptionDetails();
2694
- this.getCardDetails(this.subscriptionId);
2695
- this.cdr.markForCheck();
2696
- });
2697
- }
2698
- getSubscriptionDetails() {
2699
- this.subscriptionService.getById(this.subscriptionId).subscribe(({ result }) => {
2700
- this.subscription = result;
2701
- const product = this.subscription.products.find((x) => x.id === this.productId);
2702
- this.form.patchValue({ units: product?.purchased_units });
2703
- this.units = this.form.get("units").value;
2704
- this.cdr.markForCheck();
2705
- }).add(() => {
2706
- this.getProductDetails();
2707
- });
2708
- }
2709
- getProductDetails() {
2710
- this.productService.getProductById(this.productId).subscribe(({ result }) => {
2711
- this.product = result;
2712
- this.stripePublishKey = result?.stripe_publishable_key;
2713
- if (result?.stripe_publishable_key) Stripe.setPublishableKey(result.stripe_publishable_key);
2714
- const prodUnits = this.units > this.product.min_units ? this.units : this.product.min_units || 1;
2715
- this.form.patchValue({ units: prodUnits });
2716
- this.units = this.form.get("units").value;
2717
- this.cdr.markForCheck();
2718
- });
2719
- }
2720
- onMaxReached(event) {
2721
- if (event) this.unitError = `Maximum is ${this.units}`;
2722
- }
2723
- onMinReached(event) {
2724
- if (event) this.unitError = `Minimum is ${this.subscription.min_units || this.product.min_units}`;
2725
- }
2726
- onUnitChange(event) {
2727
- this.units = event;
2728
- this.form.patchValue({ units: event });
2729
- this.unitError = "";
2730
- }
2731
- onValidatePassword(isSuccess) {
2732
- if (isSuccess) {
2733
- this.onPurchaseSubmit();
2734
- this.password = null;
2735
- this.modalService.dismissAll();
2736
- }
2703
+ get isFree() {
2704
+ return !this.product?.stripe_plan_id && !Number(this.product?.price_per_unit);
2737
2705
  }
2738
2706
  postCreateToken(cardToken) {
2739
2707
  const data = {
@@ -2759,10 +2727,6 @@ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends Ap
2759
2727
  this.cdr.markForCheck();
2760
2728
  });
2761
2729
  }
2762
- attemptPurchase() {
2763
- if (this.user.has_password) this.passwordValidationModal.open();
2764
- else this.noPasswordModal();
2765
- }
2766
2730
  onPurchaseSubmit() {
2767
2731
  this.busy = true;
2768
2732
  this.passwordModalVisible = true;
@@ -2771,12 +2735,7 @@ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends Ap
2771
2735
  if (this.showNewCard) this.updateCardDetails();
2772
2736
  else this.enrollUserToSubscription();
2773
2737
  } else if (this.form.valid) {
2774
- const cardDetails = {
2775
- number: this.form.value.card_number,
2776
- cvc: this.form.value.cvc,
2777
- exp_month: this.form.value.exp_month,
2778
- exp_year: this.form.value.exp_year
2779
- };
2738
+ const cardDetails = stripeCard(this.form.value);
2780
2739
  Stripe.card.createToken(cardDetails, (status, response) => {
2781
2740
  if (status === StatusCodes.OK) {
2782
2741
  const cardToken = response.id;
@@ -2795,35 +2754,138 @@ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends Ap
2795
2754
  });
2796
2755
  }
2797
2756
  }
2798
- enrollUserToSubscription() {
2799
- const data = {
2800
- product_id: this.product.id,
2801
- units: this.form.get("units").value,
2802
- subscription_id: this.subscriptionId
2803
- };
2804
- this.subscriptionService.postSubscription(data).subscribe({
2805
- next: ({ result }) => {
2806
- this.store.dispatch(new GetUser());
2807
- if (result.id) {
2808
- this.form.markAsPristine();
2809
- this.router.navigate(["/account/subscriptions"]);
2810
- this.toast.success(this.translation.translate("User.Subscriptions.SubscriptionPurchased"));
2811
- this.isPurchaseAttempted = false;
2812
- this.modalService.dismissAll();
2813
- this.back();
2814
- }
2815
- this.cdr.markForCheck();
2816
- },
2817
- error: () => {
2818
- this.busy = false;
2819
- this.isPurchaseAttempted = false;
2820
- this.cdr.markForCheck();
2821
- },
2822
- complete: () => {
2823
- this.busy = !this.busy;
2824
- this.cdr.markForCheck();
2825
- }
2826
- });
2757
+ enrollUserToSubscription() {
2758
+ const data = {
2759
+ product_id: this.product.id,
2760
+ units: this.form.get("units").value,
2761
+ subscription_id: this.subscriptionId
2762
+ };
2763
+ this.subscriptionService.postSubscription(data).subscribe({
2764
+ next: ({ result }) => {
2765
+ this.store.dispatch(new GetUser());
2766
+ if (result.id) {
2767
+ this.form.markAsPristine();
2768
+ this.router.navigate(["/account/subscriptions"]);
2769
+ this.toast.success(this.translation.translate("User.Subscriptions.SubscriptionPurchased"));
2770
+ this.isPurchaseAttempted = false;
2771
+ this.modalService.dismissAll();
2772
+ this.back();
2773
+ }
2774
+ this.cdr.markForCheck();
2775
+ },
2776
+ error: () => {
2777
+ this.busy = false;
2778
+ this.isPurchaseAttempted = false;
2779
+ this.cdr.markForCheck();
2780
+ },
2781
+ complete: () => {
2782
+ this.busy = !this.busy;
2783
+ this.cdr.markForCheck();
2784
+ }
2785
+ });
2786
+ }
2787
+ updateCardDetails() {
2788
+ const cardDetails = stripeCard(this.form.value);
2789
+ Stripe.setPublishableKey(this.stripePublishKey);
2790
+ Stripe.card.createToken(cardDetails, (status, res) => {
2791
+ if (status !== 200) this.toast.error(res.error.message);
2792
+ else this.subscriptionService.updateCardDetails(this.form.value, this.subscriptionId).subscribe({
2793
+ next: ({ result }) => {
2794
+ if (result.error) {
2795
+ const err = result.error.errors[0].message;
2796
+ this.toast.error(err);
2797
+ } else if (result.status === StatusCodes.CREATED) {
2798
+ this.enrollUserToSubscription();
2799
+ this.toast.success(result.message);
2800
+ }
2801
+ this.cdr.markForCheck();
2802
+ },
2803
+ error: (error) => {
2804
+ this.errorMsg = HelperService.getErrorMessage(error);
2805
+ this.toast.error(this.errorMsg);
2806
+ this.cdr.markForCheck();
2807
+ }
2808
+ });
2809
+ this.cdr.markForCheck();
2810
+ });
2811
+ }
2812
+ };
2813
+ __decorate([ValidateForm("form")], UpgradeSubscriptionPayment.prototype, "updateCardDetails", null);
2814
+ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends UpgradeSubscriptionPayment {
2815
+ constructor() {
2816
+ super(...arguments);
2817
+ this.productService = inject(ProductService);
2818
+ this.scriptLoader = inject(ScriptLoaderService);
2819
+ this.confirmDialog = inject(ConfirmDialogService);
2820
+ this.months = [];
2821
+ this.years = [];
2822
+ }
2823
+ get totalAmount() {
2824
+ if (this.product) {
2825
+ const units = Number(this.form.get("units").value);
2826
+ if (!Number.isNaN(units)) return units * this.product.price_per_unit / 100;
2827
+ }
2828
+ return 0;
2829
+ }
2830
+ ngOnInit() {
2831
+ this.scriptLoader.loadScriptOnce("head", "https://js.stripe.com/v2/");
2832
+ this.years = HelperService.getYears();
2833
+ this.months = HelperService.getMonths();
2834
+ this.userStore().subscribe((user) => {
2835
+ this.user = user;
2836
+ this.cdr.markForCheck();
2837
+ });
2838
+ this.route.params.subscribe((response) => {
2839
+ this.subscriptionId = +response["subscriptionId"];
2840
+ this.productId = +response["productId"];
2841
+ this.getSubscriptionDetails();
2842
+ this.getCardDetails(this.subscriptionId);
2843
+ this.cdr.markForCheck();
2844
+ });
2845
+ }
2846
+ getSubscriptionDetails() {
2847
+ this.subscriptionService.getById(this.subscriptionId).subscribe(({ result }) => {
2848
+ this.subscription = result;
2849
+ const product = this.subscription.products.find((x) => x.id === this.productId);
2850
+ this.form.patchValue({ units: product?.purchased_units });
2851
+ this.units = this.form.get("units").value;
2852
+ this.cdr.markForCheck();
2853
+ }).add(() => {
2854
+ this.getProductDetails();
2855
+ });
2856
+ }
2857
+ getProductDetails() {
2858
+ this.productService.getProductById(this.productId).subscribe(({ result }) => {
2859
+ this.product = result;
2860
+ this.stripePublishKey = result?.stripe_publishable_key;
2861
+ if (result?.stripe_publishable_key) Stripe.setPublishableKey(result.stripe_publishable_key);
2862
+ const prodUnits = this.units > this.product.min_units ? this.units : this.product.min_units || 1;
2863
+ this.form.patchValue({ units: prodUnits });
2864
+ this.units = this.form.get("units").value;
2865
+ this.cdr.markForCheck();
2866
+ });
2867
+ }
2868
+ onMaxReached(event) {
2869
+ if (event) this.unitError = `Maximum is ${this.units}`;
2870
+ }
2871
+ onMinReached(event) {
2872
+ if (event) this.unitError = `Minimum is ${this.subscription.min_units || this.product.min_units}`;
2873
+ }
2874
+ onUnitChange(event) {
2875
+ this.units = event;
2876
+ this.form.patchValue({ units: event });
2877
+ this.unitError = "";
2878
+ }
2879
+ onValidatePassword(isSuccess) {
2880
+ if (isSuccess) {
2881
+ this.onPurchaseSubmit();
2882
+ this.password = null;
2883
+ this.modalService.dismissAll();
2884
+ }
2885
+ }
2886
+ attemptPurchase() {
2887
+ if (this.user.has_password) this.passwordValidationModal.open();
2888
+ else this.noPasswordModal();
2827
2889
  }
2828
2890
  noPasswordModal() {
2829
2891
  this.confirmDialog.open({
@@ -2848,46 +2910,13 @@ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends Ap
2848
2910
  this.form.markAllAsTouched();
2849
2911
  FormHelperService.markFormAsPristine(this.form);
2850
2912
  }
2851
- updateCardDetails() {
2852
- const cardDetails = {
2853
- number: this.form.value.card_number,
2854
- cvc: this.form.value.cvc,
2855
- exp_month: this.form.value.exp_month,
2856
- exp_year: this.form.value.exp_year
2857
- };
2858
- Stripe.setPublishableKey(this.stripePublishKey);
2859
- Stripe.card.createToken(cardDetails, (status, res) => {
2860
- if (status !== 200) this.toast.error(res.error.message);
2861
- else this.subscriptionService.updateCardDetails(this.form.value, this.subscriptionId).subscribe({
2862
- next: ({ result }) => {
2863
- if (result.error) {
2864
- const err = result.error.errors[0].message;
2865
- this.toast.error(err);
2866
- } else if (result.status === StatusCodes.CREATED) {
2867
- this.enrollUserToSubscription();
2868
- this.toast.success(result.message);
2869
- }
2870
- this.cdr.markForCheck();
2871
- },
2872
- error: (error) => {
2873
- this.errorMsg = HelperService.getErrorMessage(error);
2874
- this.toast.error(this.errorMsg);
2875
- this.cdr.markForCheck();
2876
- }
2877
- });
2878
- this.cdr.markForCheck();
2879
- });
2880
- }
2881
- ngOnDestroy() {
2882
- super.ngOnDestroy();
2883
- }
2884
2913
  static {
2885
2914
  this.ɵfac = i0.ɵɵngDeclareFactory({
2886
2915
  minVersion: "12.0.0",
2887
2916
  version: "22.2.3",
2888
2917
  ngImport: i0,
2889
2918
  type: UpgradeSubscriptionComponent,
2890
- deps: [],
2919
+ deps: null,
2891
2920
  target: i0.ɵɵFactoryTarget.Component
2892
2921
  });
2893
2922
  }
@@ -3132,7 +3161,6 @@ var UpgradeSubscriptionComponent = class UpgradeSubscriptionComponent extends Ap
3132
3161
  });
3133
3162
  }
3134
3163
  };
3135
- __decorate([ValidateForm("form")], UpgradeSubscriptionComponent.prototype, "updateCardDetails", null);
3136
3164
  i0.ɵɵngDeclareClassMetadata({
3137
3165
  minVersion: "12.0.0",
3138
3166
  version: "22.2.3",
@@ -3161,37 +3189,170 @@ i0.ɵɵngDeclareClassMetadata({
3161
3189
  styles: [".payment-left,.payment-right{border:1px solid rgb(204,204,204);height:100%}.payment-left h4,.payment-right h4{border-bottom:1px solid rgb(0,0,0);font-size:1rem;font-weight:600;margin:0 0 20px;padding:0 0 5px;text-transform:uppercase}.payment-left .summary-row.total,.payment-right .summary-row.total{padding:10px 0 0 10px}.payment-left .summary-row .summary-left,.payment-right .summary-row .summary-left{font-weight:600}.payment-provider{width:20%}@media(max-width:800px){.payment-provider{width:60%}}.summary-left{-webkit-box-flex:1;color:#555;flex-grow:1;-ms-flex-positive:1;font-weight:200;text-align:left}.summary-left.plan{color:#c93f00;font-size:14px;margin:5px 0}.summary-right{-webkit-box-flex:1;-webkit-box-pack:end;color:#000;flex-grow:1;-ms-flex-pack:end;-ms-flex-positive:1;justify-content:flex-end;text-align:right}\n"]
3162
3190
  }]
3163
3191
  }],
3164
- ctorParameters: () => [],
3165
- propDecorators: {
3166
- passwordValidationModal: [{
3167
- type: ViewChild,
3168
- args: ["passwordValidationModal", { static: true }]
3169
- }],
3170
- updateCardDetails: []
3171
- }
3192
+ propDecorators: { passwordValidationModal: [{
3193
+ type: ViewChild,
3194
+ args: ["passwordValidationModal", { static: true }]
3195
+ }] }
3172
3196
  });
3173
- var UserSubscriptionDetailsComponent = class UserSubscriptionDetailsComponent extends AppBaseComponent {
3197
+ function commaSeparatedEmailsValidator() {
3198
+ return (control) => {
3199
+ if (!control.value) return null;
3200
+ const value = control.value;
3201
+ if (value.includes(",") && (value.includes(", ") || value.includes(" ,"))) return { invalidFormat: true };
3202
+ const emailParts = value.split(",");
3203
+ if (emailParts.some((part) => part.trim() !== part || part.includes(" "))) return { invalidFormat: true };
3204
+ const emails = emailParts.map((email) => email.trim());
3205
+ for (const email of emails) if (email && !ValidationService.email(email)) return { invalidEmail: true };
3206
+ return null;
3207
+ };
3208
+ }
3209
+ function createSubscriptionDetailsForm(fb) {
3210
+ return fb.group({
3211
+ organisation: ["", [Validators.required]],
3212
+ contact_name: ["", [Validators.required]],
3213
+ contact_email: ["", [Validators.required, Validators.email]],
3214
+ contact_tel: [""],
3215
+ tax_id: [""],
3216
+ invoice_recipient_emails: ["", [commaSeparatedEmailsValidator()]],
3217
+ address: ["", [Validators.required]],
3218
+ country_code: ["", [Validators.required]],
3219
+ facebook_handle: [""],
3220
+ twitter_handle: [""],
3221
+ linkedin_handle: [""],
3222
+ reddit_handle: [""],
3223
+ company_url: [""],
3224
+ enforce_2fa: [false],
3225
+ rag_use_own_data: [true],
3226
+ rag_keep_pii: [false]
3227
+ });
3228
+ }
3229
+ function trimEmailList(emails) {
3230
+ return emails.split(",").map((email) => email.trim()).join(",");
3231
+ }
3232
+ function slugPngFile(slug, blob) {
3233
+ const filename = `${`${slug.toLocaleLowerCase()}_${Date.parse((/* @__PURE__ */ new Date()).toString())}`}.png`;
3234
+ return new File([blob], filename);
3235
+ }
3236
+ var SubscriptionApiTokens = class extends AppBaseComponent {
3237
+ constructor() {
3238
+ super(...arguments);
3239
+ this.subscriptionService = inject(SubscriptionService);
3240
+ this.cdr = inject(ChangeDetectorRef);
3241
+ this.confirmDialog = inject(ConfirmDialogService);
3242
+ this.showApiToken = false;
3243
+ this.showApiClientId = false;
3244
+ this.refreshingTokens = false;
3245
+ }
3246
+ toggleApiTokenVisibility() {
3247
+ this.showApiToken = !this.showApiToken;
3248
+ }
3249
+ toggleApiClientIdVisibility() {
3250
+ this.showApiClientId = !this.showApiClientId;
3251
+ }
3252
+ refreshApiTokens() {
3253
+ this.confirmDialog.open({
3254
+ title: this.translation.translate("User.Subscriptions.APICredentials.RefreshConfirmTitle"),
3255
+ text: this.translation.translate("Common.Confirm.RefreshApiTokens.Text"),
3256
+ destructive: true,
3257
+ confirmLabel: this.translation.translate("User.Subscriptions.APICredentials.RefreshConfirmLabel")
3258
+ }).then((ok) => {
3259
+ if (ok) this.performTokenRefresh();
3260
+ });
3261
+ }
3262
+ performTokenRefresh() {
3263
+ this.refreshingTokens = true;
3264
+ this.subscriptionService.refreshApiTokens(this.subscriptionId).subscribe({ next: ({ result }) => {
3265
+ if (result && result.api_access_token) this.subscription.api_access_token = result.api_access_token;
3266
+ if (result && result.api_client_id) this.subscription.api_client_id = result.api_client_id;
3267
+ this.showApiToken = false;
3268
+ this.showApiClientId = false;
3269
+ this.fetchData();
3270
+ this.cdr.markForCheck();
3271
+ } }).add(() => {
3272
+ this.refreshingTokens = false;
3273
+ this.cdr.markForCheck();
3274
+ });
3275
+ }
3276
+ };
3277
+ var SubscriptionLogos = class extends SubscriptionApiTokens {
3278
+ constructor() {
3279
+ super(...arguments);
3280
+ this.modalService = inject(NgbModal);
3281
+ this.fullLogoBroken = false;
3282
+ this.squaredLogoBroken = false;
3283
+ }
3284
+ openModal(content) {
3285
+ this.modalService.open(content, {
3286
+ centered: true,
3287
+ windowClass: "modal-holder"
3288
+ });
3289
+ }
3290
+ onImageSelection(event) {
3291
+ const file = slugPngFile(this.slug, this.dataURLtoBlob(event));
3292
+ this.subscriptionService.addFullLogo(this.subscriptionId, file).subscribe((res) => {
3293
+ this.modalService.dismissAll();
3294
+ this.fullLogo = res?.result?.full_logo?.url;
3295
+ this.fullLogoBroken = false;
3296
+ this.cdr.markForCheck();
3297
+ });
3298
+ }
3299
+ uploadSquaredLogo(event) {
3300
+ const file = slugPngFile(this.slug, this.dataURLtoBlob(event));
3301
+ this.subscriptionService.addSquaredLogo(this.subscriptionId, file).subscribe((res) => {
3302
+ this.modalService.dismissAll();
3303
+ this.squaredLogo = res?.result?.squared_logo?.url;
3304
+ this.squaredLogoBroken = false;
3305
+ this.cdr.markForCheck();
3306
+ });
3307
+ }
3308
+ onClose() {
3309
+ this.modalService.dismissAll();
3310
+ }
3311
+ dataURLtoBlob(dataUrl) {
3312
+ return dataUrlToBlob(dataUrl);
3313
+ }
3314
+ };
3315
+ var SubscriptionSeats = class extends SubscriptionLogos {
3316
+ constructor() {
3317
+ super(...arguments);
3318
+ this.units = 1;
3319
+ }
3174
3320
  totalAmount() {
3175
3321
  return this.subscription.products.map((x) => x.price_per_unit * this.units).reduce((a, b) => a + b, 0) / 100;
3176
3322
  }
3323
+ updateUnits() {
3324
+ if (this.subscription.products[0].trial_subscription) return;
3325
+ this.modal.open();
3326
+ }
3327
+ onPasswordValidation(_event) {
3328
+ this.subscriptionService.updateSubscriptionUnit(this.subscription.id, this.units).subscribe(({ result }) => {
3329
+ if (result.status === StatusCodes.OK) this.toast.success(this.translation.translate("User.Subscriptions.Details.UnitsUpdatedMessage"));
3330
+ else this.toast.error(this.translation.translate("GenericMessage.WentWrong"));
3331
+ this.cdr.markForCheck();
3332
+ });
3333
+ }
3334
+ onMaxReached(event) {
3335
+ if (event) this.unitError = this.translation.translate("Register.Units.Maximum", { units: this.units });
3336
+ }
3337
+ onMinReached(event) {
3338
+ if (event) this.unitError = this.translation.translate("Register.Units.Minimum", { units: this.units });
3339
+ }
3340
+ onUnitChange(event) {
3341
+ this.allowUpdate = true;
3342
+ this.hasUnitChanged = true;
3343
+ this.units = event;
3344
+ this.unitError = "";
3345
+ }
3346
+ };
3347
+ var UserSubscriptionDetailsComponent = class UserSubscriptionDetailsComponent extends SubscriptionSeats {
3177
3348
  constructor() {
3178
3349
  super();
3179
3350
  this.fb = inject(FormBuilder);
3180
3351
  this.geoService = inject(GeoService);
3181
- this.modalService = inject(NgbModal);
3182
- this.subscriptionService = inject(SubscriptionService);
3183
3352
  this.store = inject(Store);
3184
- this.cdr = inject(ChangeDetectorRef);
3185
- this.confirmDialog = inject(ConfirmDialogService);
3186
3353
  this.transloco = inject(TranslocoService);
3187
3354
  this.busyButton = false;
3188
- this.units = 1;
3189
- this.fullLogoBroken = false;
3190
- this.squaredLogoBroken = false;
3191
- this.showApiToken = false;
3192
- this.showApiClientId = false;
3193
- this.refreshingTokens = false;
3194
- this.form = this.getForm();
3355
+ this.form = createSubscriptionDetailsForm(this.fb);
3195
3356
  this.route.params.subscribe((params) => {
3196
3357
  this.subscriptionId = +params["subscriptionId"];
3197
3358
  this.fetchData();
@@ -3218,99 +3379,23 @@ var UserSubscriptionDetailsComponent = class UserSubscriptionDetailsComponent ex
3218
3379
  fetchData() {
3219
3380
  this.subscriptionService.getById(this.subscriptionId).subscribe(({ result }) => {
3220
3381
  this.subscription = result;
3221
- this.fullLogo = this.subscription?.full_logo.url;
3222
- this.squaredLogo = this.subscription?.squared_logo?.url;
3223
- this.fullLogoBroken = false;
3224
- this.squaredLogoBroken = false;
3225
- this.form.patchValue(this.subscription);
3226
- this.units = this.subscription?.products[0]?.purchased_units;
3227
- this.form.patchValue({ units: this.units });
3228
- this.cdr.markForCheck();
3229
- });
3230
- }
3231
- get brandName() {
3232
- return this.appConfig?.company?.name?.trim() || "PosiWise";
3233
- }
3234
- getForm() {
3235
- return this.fb.group({
3236
- organisation: ["", [Validators.required]],
3237
- contact_name: ["", [Validators.required]],
3238
- contact_email: ["", [Validators.required, Validators.email]],
3239
- contact_tel: [""],
3240
- tax_id: [""],
3241
- invoice_recipient_emails: ["", [this.commaSeparatedEmailsValidator()]],
3242
- address: ["", [Validators.required]],
3243
- country_code: ["", [Validators.required]],
3244
- facebook_handle: [""],
3245
- twitter_handle: [""],
3246
- linkedin_handle: [""],
3247
- reddit_handle: [""],
3248
- company_url: [""],
3249
- enforce_2fa: [false],
3250
- rag_use_own_data: [true],
3251
- rag_keep_pii: [false]
3252
- });
3253
- }
3254
- commaSeparatedEmailsValidator() {
3255
- return (control) => {
3256
- if (!control.value) return null;
3257
- const value = control.value;
3258
- if (value.includes(",") && (value.includes(", ") || value.includes(" ,"))) return { invalidFormat: true };
3259
- const emailParts = value.split(",");
3260
- if (emailParts.some((part) => part.trim() !== part || part.includes(" "))) return { invalidFormat: true };
3261
- const emails = emailParts.map((email) => email.trim());
3262
- for (const email of emails) if (email && !ValidationService.email(email)) return { invalidEmail: true };
3263
- return null;
3264
- };
3265
- }
3266
- updateUnits() {
3267
- if (this.subscription.products[0].trial_subscription) return;
3268
- this.modal.open();
3269
- }
3270
- openModal(content) {
3271
- this.modalService.open(content, {
3272
- centered: true,
3273
- windowClass: "modal-holder"
3274
- });
3275
- }
3276
- onImageSelection(event) {
3277
- const blob = this.dataURLtoBlob(event);
3278
- const filename = `${`${this.slug.toLocaleLowerCase()}_${Date.parse((/* @__PURE__ */ new Date()).toString())}`}.png`;
3279
- const file = new File([blob], filename);
3280
- this.subscriptionService.addFullLogo(this.subscriptionId, file).subscribe((res) => {
3281
- this.modalService.dismissAll();
3282
- this.fullLogo = res?.result?.full_logo?.url;
3283
- this.fullLogoBroken = false;
3284
- this.cdr.markForCheck();
3285
- });
3286
- }
3287
- uploadSquaredLogo(event) {
3288
- const blob = this.dataURLtoBlob(event);
3289
- const filename = `${`${this.slug.toLocaleLowerCase()}_${Date.parse((/* @__PURE__ */ new Date()).toString())}`}.png`;
3290
- const file = new File([blob], filename);
3291
- this.subscriptionService.addSquaredLogo(this.subscriptionId, file).subscribe((res) => {
3292
- this.modalService.dismissAll();
3293
- this.squaredLogo = res?.result?.squared_logo?.url;
3382
+ this.fullLogo = this.subscription?.full_logo.url;
3383
+ this.squaredLogo = this.subscription?.squared_logo?.url;
3384
+ this.fullLogoBroken = false;
3294
3385
  this.squaredLogoBroken = false;
3386
+ this.form.patchValue(this.subscription);
3387
+ this.units = this.subscription?.products[0]?.purchased_units;
3388
+ this.form.patchValue({ units: this.units });
3295
3389
  this.cdr.markForCheck();
3296
3390
  });
3297
3391
  }
3298
- onClose() {
3299
- this.modalService.dismissAll();
3300
- }
3301
- dataURLtoBlob(dataUrl) {
3302
- const arr = dataUrl.split(",");
3303
- const mime = /^[A-Z]*[a-z]*:(.*?);[A-Z]*/.exec(arr[0])?.[1];
3304
- const bStr = atob(arr[1]);
3305
- let n = bStr.length;
3306
- const u8arr = new Uint8Array(n);
3307
- while (n--) u8arr[n] = bStr.charCodeAt(n);
3308
- return new Blob([u8arr], { type: mime });
3392
+ get brandName() {
3393
+ return this.appConfig?.company?.name?.trim() || "PosiWise";
3309
3394
  }
3310
3395
  onSaveDetails() {
3311
3396
  this.busyButton = true;
3312
3397
  const formValue = { ...this.form.value };
3313
- if (formValue.invoice_recipient_emails) formValue.invoice_recipient_emails = formValue.invoice_recipient_emails.split(",").map((email) => email.trim()).join(",");
3398
+ if (formValue.invoice_recipient_emails) formValue.invoice_recipient_emails = trimEmailList(formValue.invoice_recipient_emails);
3314
3399
  this.subscriptionService.updateSubscription(Number(this.subscriptionId), formValue).subscribe(() => {
3315
3400
  this.form.markAsPristine();
3316
3401
  this.toast.success(this.translation.translate("User.Subscriptions.Details.UpdatedMessage"));
@@ -3322,58 +3407,9 @@ var UserSubscriptionDetailsComponent = class UserSubscriptionDetailsComponent ex
3322
3407
  this.cdr.markForCheck();
3323
3408
  });
3324
3409
  }
3325
- onPasswordValidation(_event) {
3326
- this.subscriptionService.updateSubscriptionUnit(this.subscription.id, this.units).subscribe(({ result }) => {
3327
- if (result.status === StatusCodes.OK) this.toast.success(this.translation.translate("User.Subscriptions.Details.UnitsUpdatedMessage"));
3328
- else this.toast.error(this.translation.translate("GenericMessage.WentWrong"));
3329
- this.cdr.markForCheck();
3330
- });
3331
- }
3332
- onMaxReached(event) {
3333
- if (event) this.unitError = `Maximum is ${this.units}`;
3334
- }
3335
- onMinReached(event) {
3336
- if (event) this.unitError = `Minimum is ${this.units}`;
3337
- }
3338
- onUnitChange(event) {
3339
- this.allowUpdate = true;
3340
- this.hasUnitChanged = true;
3341
- this.units = event;
3342
- this.unitError = "";
3343
- }
3344
3410
  handleAddressChange(event) {
3345
3411
  this.form.get("address").setValue(event.formatted_address);
3346
3412
  }
3347
- toggleApiTokenVisibility() {
3348
- this.showApiToken = !this.showApiToken;
3349
- }
3350
- toggleApiClientIdVisibility() {
3351
- this.showApiClientId = !this.showApiClientId;
3352
- }
3353
- refreshApiTokens() {
3354
- this.confirmDialog.open({
3355
- title: "Are you sure?",
3356
- text: "This will expire the current tokens.",
3357
- destructive: true,
3358
- confirmLabel: "Yes, refresh tokens!"
3359
- }).then((ok) => {
3360
- if (ok) this.performTokenRefresh();
3361
- });
3362
- }
3363
- performTokenRefresh() {
3364
- this.refreshingTokens = true;
3365
- this.subscriptionService.refreshApiTokens(this.subscriptionId).subscribe({ next: ({ result }) => {
3366
- if (result && result.api_access_token) this.subscription.api_access_token = result.api_access_token;
3367
- if (result && result.api_client_id) this.subscription.api_client_id = result.api_client_id;
3368
- this.showApiToken = false;
3369
- this.showApiClientId = false;
3370
- this.fetchData();
3371
- this.cdr.markForCheck();
3372
- } }).add(() => {
3373
- this.refreshingTokens = false;
3374
- this.cdr.markForCheck();
3375
- });
3376
- }
3377
3413
  trackByProduct(_index, item) {
3378
3414
  return item.id;
3379
3415
  }
@@ -3806,19 +3842,68 @@ i0.ɵɵngDeclareClassMetadata({
3806
3842
  onSaveDetails: []
3807
3843
  }
3808
3844
  });
3809
- var UserSubscriptionListComponent = class UserSubscriptionListComponent extends AppBaseComponent {
3845
+ var SubscriptionListActions = class extends AppBaseComponent {
3810
3846
  constructor() {
3811
- super();
3847
+ super(...arguments);
3812
3848
  this.subscriptionService = inject(SubscriptionService);
3813
3849
  this.adminService = inject(AdminService);
3814
3850
  this.clipboard = inject(Clipboard);
3815
3851
  this.cdr = inject(ChangeDetectorRef);
3816
3852
  this.confirmDialog = inject(ConfirmDialogService);
3817
- this.inMobileApp = isInMobileWebView();
3818
3853
  this.showApiKey = true;
3854
+ this.showTos = false;
3855
+ }
3856
+ onClipboardCopy(accessCode) {
3857
+ this.clipboard.copy(accessCode);
3858
+ this.toast.success(this.translation.translate("User.Subscriptions.AccessKeyCopied"));
3859
+ }
3860
+ updateApiKey(subscription, product) {
3861
+ this.subscriptionService.updateSubscriptionAPIKey(subscription.id, product.id).subscribe(({ result }) => {
3862
+ product.api_access_token = result;
3863
+ this.toast.success(this.translation.translate("User.Subscriptions.UpdatedKey"));
3864
+ this.getSubscribedProduct();
3865
+ this.cdr.markForCheck();
3866
+ });
3867
+ }
3868
+ showKey(item) {
3869
+ this.currentItem = item;
3870
+ this.passwordValidationModalForKey.open();
3871
+ this.showApiKey = false;
3872
+ }
3873
+ displayApiKey() {
3874
+ this.showApiKey = true;
3875
+ this.currentItem.masked = this.currentItem?.api_access_token;
3876
+ }
3877
+ showModalForAccountDeletion() {
3878
+ this.confirmDialog.confirmDelete({
3879
+ textKey: "Common.Confirm.Delete.TextSimple",
3880
+ textParams: { entityType: "account" }
3881
+ }).then((ok) => {
3882
+ if (ok) this.passwordValidationModalForAccountDelete.open();
3883
+ });
3884
+ }
3885
+ deleteUser(_event) {
3886
+ const subscriptionId = PermissionService.selectedSubscription.id;
3887
+ this.adminService.deleteUser(this.user.id, subscriptionId).subscribe(() => {
3888
+ this.router.navigate(["logout"]);
3889
+ this.cdr.markForCheck();
3890
+ });
3891
+ }
3892
+ showPrivacyAndTos(product) {
3893
+ this.productId = product.id;
3894
+ this.productName = product.name;
3895
+ this.showTos = true;
3896
+ }
3897
+ onCancel() {
3898
+ this.showTos = false;
3899
+ }
3900
+ };
3901
+ var UserSubscriptionListComponent = class UserSubscriptionListComponent extends SubscriptionListActions {
3902
+ constructor() {
3903
+ super();
3904
+ this.inMobileApp = isInMobileWebView();
3819
3905
  this.subscribedSubscriptions = [];
3820
3906
  this.isLoaded = false;
3821
- this.showTos = false;
3822
3907
  this.objectKeys = Object.keys;
3823
3908
  this.items = [
3824
3909
  {
@@ -3848,10 +3933,6 @@ var UserSubscriptionListComponent = class UserSubscriptionListComponent extends
3848
3933
  });
3849
3934
  [this.activeItem] = this.items;
3850
3935
  }
3851
- onClipboardCopy(accessCode) {
3852
- this.clipboard.copy(accessCode);
3853
- this.toast.success(this.translation.translate("User.Subscriptions.AccessKeyCopied"));
3854
- }
3855
3936
  deleteSubscription(subscription) {
3856
3937
  this.removal.start({ subscriptionId: subscription.id });
3857
3938
  }
@@ -3883,23 +3964,6 @@ var UserSubscriptionListComponent = class UserSubscriptionListComponent extends
3883
3964
  this.cdr.markForCheck();
3884
3965
  });
3885
3966
  }
3886
- updateApiKey(subscription, product) {
3887
- this.subscriptionService.updateSubscriptionAPIKey(subscription.id, product.id).subscribe(({ result }) => {
3888
- product.api_access_token = result;
3889
- this.toast.success(this.translation.translate("User.Subscriptions.UpdatedKey"));
3890
- this.getSubscribedProduct();
3891
- this.cdr.markForCheck();
3892
- });
3893
- }
3894
- showKey(item) {
3895
- this.currentItem = item;
3896
- this.passwordValidationModalForKey.open();
3897
- this.showApiKey = false;
3898
- }
3899
- displayApiKey() {
3900
- this.showApiKey = true;
3901
- this.currentItem.masked = this.currentItem?.api_access_token;
3902
- }
3903
3967
  activateMenu() {
3904
3968
  this.activeItem = this.menu["activeItem"];
3905
3969
  if (this.activeItem.id === "subscription") this.getSubscribedProduct();
@@ -3929,38 +3993,12 @@ var UserSubscriptionListComponent = class UserSubscriptionListComponent extends
3929
3993
  confirmOnly: true
3930
3994
  });
3931
3995
  }
3932
- showModalForAccountDeletion() {
3933
- this.confirmDialog.confirmDelete({
3934
- textKey: "Common.Confirm.Delete.TextSimple",
3935
- textParams: { entityType: "account" }
3936
- }).then((ok) => {
3937
- if (ok) this.passwordValidationModalForAccountDelete.open();
3938
- });
3939
- }
3940
- deleteUser(_event) {
3941
- const subscriptionId = PermissionService.selectedSubscription.id;
3942
- this.adminService.deleteUser(this.user.id, subscriptionId).subscribe(() => {
3943
- this.router.navigate(["logout"]);
3944
- this.cdr.markForCheck();
3945
- });
3946
- }
3947
- showPrivacyAndTos(product) {
3948
- this.productId = product.id;
3949
- this.productName = product.name;
3950
- this.showTos = true;
3951
- }
3952
- onCancel() {
3953
- this.showTos = false;
3954
- }
3955
3996
  trackBySubscription(_index, item) {
3956
3997
  return item.id;
3957
3998
  }
3958
3999
  trackByProduct(_index, item) {
3959
4000
  return item.id;
3960
4001
  }
3961
- ngOnDestroy() {
3962
- super.ngOnDestroy();
3963
- }
3964
4002
  static {
3965
4003
  this.ɵfac = i0.ɵɵngDeclareFactory({
3966
4004
  minVersion: "12.0.0",
@@ -4594,6 +4632,7 @@ i0.ɵɵngDeclareClassMetadata({
4594
4632
  var AiKnowledgeTabComponent = class AiKnowledgeTabComponent {
4595
4633
  constructor() {
4596
4634
  this.permissionService = inject(PermissionService);
4635
+ this.activeTab = "files";
4597
4636
  }
4598
4637
  get ready() {
4599
4638
  return !!this.permissionService.user;
@@ -4625,7 +4664,7 @@ var AiKnowledgeTabComponent = class AiKnowledgeTabComponent {
4625
4664
  isStandalone: true,
4626
4665
  selector: "pw-ai-knowledge-tab",
4627
4666
  ngImport: i0,
4628
- template: "@if (!ready) {\n <pw-loader [isVisible]=\"true\"></pw-loader>\n} @else if (!isAlpha) {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NotAvailable' | transloco\"></pw-no-data>\n} @else if (subscription) {\n <pw-ai-knowledge scope=\"personal\"\n [subscriptionId]=\"subscription.id\"\n [subscriptionName]=\"subscription.organisation\"\n [useOwnData]=\"useOwnData\"></pw-ai-knowledge>\n} @else {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NoSubscription' | transloco\"></pw-no-data>\n}\n",
4667
+ template: "@if (!ready) {\n <pw-loader [isVisible]=\"true\"></pw-loader>\n} @else if (!isAlpha) {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NotAvailable' | transloco\"></pw-no-data>\n} @else if (subscription) {\n <div class=\"title\">\n <h2>{{ 'AiKnowledge.PersonalTitle' | transloco: { name: subscription.organisation } }}</h2>\n </div>\n <ul ngbNav #nav=\"ngbNav\" [(activeId)]=\"activeTab\" [destroyOnHide]=\"false\" class=\"nav-tabs\">\n <li ngbNavItem=\"files\">\n <a ngbNavLink>{{ 'AiKnowledge.FilesTab' | transloco }}</a>\n <ng-template ngbNavContent>\n <pw-ai-knowledge scope=\"personal\"\n [subscriptionId]=\"subscription.id\"\n [subscriptionName]=\"subscription.organisation\"\n [useOwnData]=\"useOwnData\"></pw-ai-knowledge>\n </ng-template>\n </li>\n <li ngbNavItem=\"notes\">\n <a ngbNavLink>{{ 'AiMemory.Title' | transloco }}</a>\n <ng-template ngbNavContent>\n <pw-ai-memory [subscriptionId]=\"subscription.id\"></pw-ai-memory>\n </ng-template>\n </li>\n </ul>\n <div class=\"mt-3\" [ngbNavOutlet]=\"nav\"></div>\n} @else {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NoSubscription' | transloco\"></pw-no-data>\n}\n",
4629
4668
  dependencies: [
4630
4669
  {
4631
4670
  kind: "component",
@@ -4658,6 +4697,60 @@ var AiKnowledgeTabComponent = class AiKnowledgeTabComponent {
4658
4697
  "useOwnData"
4659
4698
  ]
4660
4699
  },
4700
+ {
4701
+ kind: "component",
4702
+ type: AiMemoryComponent,
4703
+ selector: "pw-ai-memory"
4704
+ },
4705
+ {
4706
+ kind: "directive",
4707
+ type: NgbNav,
4708
+ selector: "[ngbNav]",
4709
+ inputs: [
4710
+ "activeId",
4711
+ "animation",
4712
+ "destroyOnHide",
4713
+ "orientation",
4714
+ "roles",
4715
+ "keyboard"
4716
+ ],
4717
+ outputs: [
4718
+ "activeIdChange",
4719
+ "shown",
4720
+ "hidden",
4721
+ "navChange"
4722
+ ],
4723
+ exportAs: ["ngbNav"]
4724
+ },
4725
+ {
4726
+ kind: "directive",
4727
+ type: NgbNavItem,
4728
+ selector: "[ngbNavItem]",
4729
+ inputs: [
4730
+ "destroyOnHide",
4731
+ "disabled",
4732
+ "domId",
4733
+ "ngbNavItem"
4734
+ ],
4735
+ outputs: ["shown", "hidden"],
4736
+ exportAs: ["ngbNavItem"]
4737
+ },
4738
+ {
4739
+ kind: "directive",
4740
+ type: NgbNavLink,
4741
+ selector: "a[ngbNavLink]"
4742
+ },
4743
+ {
4744
+ kind: "directive",
4745
+ type: NgbNavContent,
4746
+ selector: "ng-template[ngbNavContent]"
4747
+ },
4748
+ {
4749
+ kind: "component",
4750
+ type: NgbNavOutlet,
4751
+ selector: "[ngbNavOutlet]",
4752
+ inputs: ["paneRole", "ngbNavOutlet"]
4753
+ },
4661
4754
  {
4662
4755
  kind: "pipe",
4663
4756
  type: TranslocoPipe,
@@ -4680,9 +4773,15 @@ i0.ɵɵngDeclareClassMetadata({
4680
4773
  AppLoaderComponent,
4681
4774
  NoDataComponent,
4682
4775
  AiKnowledgeComponent,
4776
+ AiMemoryComponent,
4777
+ NgbNav,
4778
+ NgbNavItem,
4779
+ NgbNavLink,
4780
+ NgbNavContent,
4781
+ NgbNavOutlet,
4683
4782
  TranslocoPipe
4684
4783
  ],
4685
- template: "@if (!ready) {\n <pw-loader [isVisible]=\"true\"></pw-loader>\n} @else if (!isAlpha) {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NotAvailable' | transloco\"></pw-no-data>\n} @else if (subscription) {\n <pw-ai-knowledge scope=\"personal\"\n [subscriptionId]=\"subscription.id\"\n [subscriptionName]=\"subscription.organisation\"\n [useOwnData]=\"useOwnData\"></pw-ai-knowledge>\n} @else {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NoSubscription' | transloco\"></pw-no-data>\n}\n"
4784
+ template: "@if (!ready) {\n <pw-loader [isVisible]=\"true\"></pw-loader>\n} @else if (!isAlpha) {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NotAvailable' | transloco\"></pw-no-data>\n} @else if (subscription) {\n <div class=\"title\">\n <h2>{{ 'AiKnowledge.PersonalTitle' | transloco: { name: subscription.organisation } }}</h2>\n </div>\n <ul ngbNav #nav=\"ngbNav\" [(activeId)]=\"activeTab\" [destroyOnHide]=\"false\" class=\"nav-tabs\">\n <li ngbNavItem=\"files\">\n <a ngbNavLink>{{ 'AiKnowledge.FilesTab' | transloco }}</a>\n <ng-template ngbNavContent>\n <pw-ai-knowledge scope=\"personal\"\n [subscriptionId]=\"subscription.id\"\n [subscriptionName]=\"subscription.organisation\"\n [useOwnData]=\"useOwnData\"></pw-ai-knowledge>\n </ng-template>\n </li>\n <li ngbNavItem=\"notes\">\n <a ngbNavLink>{{ 'AiMemory.Title' | transloco }}</a>\n <ng-template ngbNavContent>\n <pw-ai-memory [subscriptionId]=\"subscription.id\"></pw-ai-memory>\n </ng-template>\n </li>\n </ul>\n <div class=\"mt-3\" [ngbNavOutlet]=\"nav\"></div>\n} @else {\n <pw-no-data [withImage]=\"true\" [message]=\"'AiKnowledge.NoSubscription' | transloco\"></pw-no-data>\n}\n"
4686
4785
  }]
4687
4786
  }]
4688
4787
  });
@@ -7985,9 +8084,7 @@ var UserAboutComponent = class UserAboutComponent extends AppBaseComponent {
7985
8084
  trackByQualification(_index, item) {
7986
8085
  return item.id;
7987
8086
  }
7988
- ngOnDestroy() {
7989
- if (this.navigationSubscription) this.navigationSubscription.unsubscribe();
7990
- }
8087
+ ngOnDestroy() {}
7991
8088
  static {
7992
8089
  this.ɵfac = i0.ɵɵngDeclareFactory({
7993
8090
  minVersion: "12.0.0",
@@ -8280,6 +8377,71 @@ i0.ɵɵngDeclareClassMetadata({
8280
8377
  isEdit: [{ type: Input }]
8281
8378
  }
8282
8379
  });
8380
+ var UserProfileAvatar = class extends AppBaseComponent {
8381
+ constructor() {
8382
+ super(...arguments);
8383
+ this.modalService = inject(NgbModal);
8384
+ this.cdr = inject(ChangeDetectorRef);
8385
+ this.image = "assets/img/icons/male.png";
8386
+ }
8387
+ handleImageError(event, fallbackPath) {
8388
+ HelperService.handleImageFallbackPath(event, fallbackPath);
8389
+ }
8390
+ openModal(content) {
8391
+ if (this.allowEdit) this.modalService.open(content, {
8392
+ centered: true,
8393
+ windowClass: "modal-holder"
8394
+ });
8395
+ }
8396
+ onImageSelection(event) {
8397
+ const file = slugPngFile(this.slug, dataUrlToBlob(event));
8398
+ this.userService.addAvatar(file).subscribe((res) => {
8399
+ this.modalService.dismissAll();
8400
+ this.image = res?.result?.user_avatar[2]?.url;
8401
+ this.cdr.markForCheck();
8402
+ });
8403
+ }
8404
+ onClose() {
8405
+ this.modalService.dismissAll();
8406
+ }
8407
+ };
8408
+ function waitForJQuery(callback) {
8409
+ let attempts = 0;
8410
+ const maxAttempts = 100;
8411
+ const checkJQuery = () => {
8412
+ if (window["jQuery"]) callback();
8413
+ else if (attempts < maxAttempts) {
8414
+ attempts++;
8415
+ setTimeout(checkJQuery, 100);
8416
+ } else loadJQueryForUserProfile(callback);
8417
+ };
8418
+ checkJQuery();
8419
+ }
8420
+ function loadJQueryForUserProfile(callback) {
8421
+ const jquerySrc = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js";
8422
+ const script = document.createElement("script");
8423
+ script.src = jquerySrc;
8424
+ script.crossOrigin = "anonymous";
8425
+ script.async = false;
8426
+ script.onload = () => {
8427
+ callback();
8428
+ };
8429
+ script.onerror = () => {
8430
+ console.error("Failed to load jQuery for user profile");
8431
+ const fallbackScript = document.createElement("script");
8432
+ fallbackScript.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js";
8433
+ fallbackScript.crossOrigin = "anonymous";
8434
+ fallbackScript.async = false;
8435
+ fallbackScript.onload = () => {
8436
+ callback();
8437
+ };
8438
+ fallbackScript.onerror = () => {
8439
+ console.error("All jQuery CDNs failed for user profile");
8440
+ };
8441
+ document.head.appendChild(fallbackScript);
8442
+ };
8443
+ document.head.appendChild(script);
8444
+ }
8283
8445
  var UserProjectsComponent = class UserProjectsComponent extends AppBaseComponent {
8284
8446
  constructor() {
8285
8447
  super(...arguments);
@@ -8594,7 +8756,7 @@ i0.ɵɵngDeclareClassMetadata({
8594
8756
  }]
8595
8757
  }
8596
8758
  });
8597
- var UserProfilePageComponent = class UserProfilePageComponent extends AppBaseComponent {
8759
+ var UserProfilePageComponent = class UserProfilePageComponent extends UserProfileAvatar {
8598
8760
  onTabChange(value) {
8599
8761
  const item = this.items.find((i) => i.id === value);
8600
8762
  if (item) this.activeItem = item;
@@ -8602,11 +8764,8 @@ var UserProfilePageComponent = class UserProfilePageComponent extends AppBaseCom
8602
8764
  constructor() {
8603
8765
  super();
8604
8766
  this.profileService = inject(ProfileService);
8605
- this.modalService = inject(NgbModal);
8606
8767
  this.scriptLoader = inject(ScriptLoaderService);
8607
- this.cdr = inject(ChangeDetectorRef);
8608
8768
  this.objectKeys = Object.keys;
8609
- this.image = "assets/img/icons/male.png";
8610
8769
  this.isLoaded = false;
8611
8770
  this.route.params.subscribe((data) => {
8612
8771
  this.slug = data["user-slug"];
@@ -8642,38 +8801,10 @@ var UserProfilePageComponent = class UserProfilePageComponent extends AppBaseCom
8642
8801
  }
8643
8802
  ngOnInit() {
8644
8803
  this.getUserBySlug();
8645
- this.waitForJQuery(() => {
8804
+ waitForJQuery(() => {
8646
8805
  this.scriptLoader.loadScriptOnce("head", "/assets/js/vertical-timeline.js");
8647
8806
  });
8648
8807
  }
8649
- handleImageError(event, fallbackPath) {
8650
- HelperService.handleImageFallbackPath(event, fallbackPath);
8651
- }
8652
- dataURLtoBlob(dataUrl) {
8653
- const arr = dataUrl?.split(",");
8654
- const mime = /^[A-Z]*[a-z]*:(.*?);[A-Z]*/.exec(arr[0])?.[1];
8655
- const bStr = atob(arr[1]);
8656
- let n = bStr.length;
8657
- const u8arr = new Uint8Array(n);
8658
- while (n--) u8arr[n] = bStr.charCodeAt(n);
8659
- return new Blob([u8arr], { type: mime });
8660
- }
8661
- openModal(content) {
8662
- if (this.allowEdit) this.modalService.open(content, {
8663
- centered: true,
8664
- windowClass: "modal-holder"
8665
- });
8666
- }
8667
- onImageSelection(event) {
8668
- const blob = this.dataURLtoBlob(event);
8669
- const filename = `${`${this.slug.toLocaleLowerCase()}_${Date.parse((/* @__PURE__ */ new Date()).toString())}`}.png`;
8670
- const file = new File([blob], filename);
8671
- this.userService.addAvatar(file).subscribe((res) => {
8672
- this.modalService.dismissAll();
8673
- this.image = res?.result?.user_avatar[2]?.url;
8674
- this.cdr.markForCheck();
8675
- });
8676
- }
8677
8808
  getUserBySlug() {
8678
8809
  forkJoin({
8679
8810
  user: this.profileService.getUserObject("user", this.slug),
@@ -8694,9 +8825,6 @@ var UserProfilePageComponent = class UserProfilePageComponent extends AppBaseCom
8694
8825
  }
8695
8826
  });
8696
8827
  }
8697
- onClose() {
8698
- this.modalService.dismissAll();
8699
- }
8700
8828
  getCurrentUserDetails() {
8701
8829
  this.userStore().subscribe((currentUser) => {
8702
8830
  if (currentUser) {
@@ -8725,46 +8853,6 @@ var UserProfilePageComponent = class UserProfilePageComponent extends AppBaseCom
8725
8853
  this.cdr.markForCheck();
8726
8854
  });
8727
8855
  }
8728
- waitForJQuery(callback) {
8729
- let attempts = 0;
8730
- const maxAttempts = 100;
8731
- const checkJQuery = () => {
8732
- if (window["jQuery"]) callback();
8733
- else if (attempts < maxAttempts) {
8734
- attempts++;
8735
- setTimeout(checkJQuery, 100);
8736
- } else this.loadJQueryForUserProfile(callback);
8737
- };
8738
- checkJQuery();
8739
- }
8740
- loadJQueryForUserProfile(callback) {
8741
- const jquerySrc = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js";
8742
- const script = document.createElement("script");
8743
- script.src = jquerySrc;
8744
- script.crossOrigin = "anonymous";
8745
- script.async = false;
8746
- script.onload = () => {
8747
- callback();
8748
- };
8749
- script.onerror = () => {
8750
- console.error("Failed to load jQuery for user profile");
8751
- const fallbackScript = document.createElement("script");
8752
- fallbackScript.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js";
8753
- fallbackScript.crossOrigin = "anonymous";
8754
- fallbackScript.async = false;
8755
- fallbackScript.onload = () => {
8756
- callback();
8757
- };
8758
- fallbackScript.onerror = () => {
8759
- console.error("All jQuery CDNs failed for user profile");
8760
- };
8761
- document.head.appendChild(fallbackScript);
8762
- };
8763
- document.head.appendChild(script);
8764
- }
8765
- ngOnDestroy() {
8766
- super.ngOnDestroy();
8767
- }
8768
8856
  static {
8769
8857
  this.ɵfac = i0.ɵɵngDeclareFactory({
8770
8858
  minVersion: "12.0.0",