@kumori/aurora-backend-handler 1.0.99 → 1.0.111

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.
@@ -1,4 +1,4 @@
1
- import { Notification, Registry, Tenant, tenantRole } from "@kumori/aurora-interfaces";
1
+ import { errors, Notification, Registry, Tenant, tenantRole } from "@kumori/aurora-interfaces";
2
2
  import { eventHelper } from "../backend-handler";
3
3
  import { environment } from "../environment";
4
4
  import {
@@ -16,6 +16,35 @@ interface DregistryBody {
16
16
  docker_password: string;
17
17
  };
18
18
  }
19
+
20
+ /**
21
+ * Extracts a user-facing code/content pair from a failed request.
22
+ * Errors coming back from the WS layer are usually nested under `.error`
23
+ * (e.g. `{ error: { code, content } }`), but some server-side rejections
24
+ * (e.g. plan/limits validation) return the fields flat on the error object
25
+ * itself (`{ code, content }`). Without this fallback those errors were
26
+ * silently reported as "Unknown error" instead of surfacing the real code.
27
+ */
28
+ const extractWsErrorInfo = (
29
+ err: unknown
30
+ ): { code: string; content: string } => {
31
+ const candidate =
32
+ err && typeof err === "object" && "error" in err
33
+ ? (err as any).error
34
+ : err;
35
+
36
+ const code =
37
+ candidate && typeof candidate === "object" && typeof candidate.code === "string"
38
+ ? candidate.code
39
+ : "Unknown error";
40
+ const content =
41
+ candidate && typeof candidate === "object" && typeof candidate.content === "string"
42
+ ? candidate.content
43
+ : "Unknown error";
44
+
45
+ return { code, content };
46
+ };
47
+
19
48
  /**
20
49
  * Function to create a tenant using the global WebSocket connection
21
50
  * @param tenant Tenant object with the data of the tenant
@@ -62,7 +91,7 @@ export const createTenant = async (tenant: Tenant, security: Security) => {
62
91
  eventHelper.tenant.publish.created(updatedTenant);
63
92
  const tenantCreatedNotification: Notification = {
64
93
  type: "success",
65
- subtype: "tenant-created",
94
+ subtype: errors.tenant.created.subtype,
66
95
  date: Date.now().toString(),
67
96
  status: "unread",
68
97
  callToAction: false,
@@ -79,26 +108,11 @@ export const createTenant = async (tenant: Tenant, security: Security) => {
79
108
  tenant: tenant.name,
80
109
  webSocketStatus: getWebSocketStatus(),
81
110
  });
82
- let contentMessage = "Unknown error";
83
- let errorContent = "Unknown error";
84
-
85
- if (
86
- typeof error === "object" &&
87
- error !== null &&
88
- "error" in error &&
89
- typeof (error as any).error === "object" &&
90
- (error as any).error !== null
91
- ) {
92
- if ("code" in (error as any).error) {
93
- contentMessage = (error as any).error.code;
94
- }
95
- if ("content" in (error as any).error) {
96
- errorContent = (error as any).error.content;
97
- }
98
- }
111
+ const { code: contentMessage, content: errorContent } =
112
+ extractWsErrorInfo(error);
99
113
  const tenantCreationErrorNotification: Notification = {
100
114
  type: "error",
101
- subtype: "tenant-creation-error",
115
+ subtype: errors.tenant.creationError.subtype,
102
116
  info_content: {
103
117
  code: contentMessage,
104
118
  message: errorContent,
@@ -146,27 +160,11 @@ export const deleteTenant = async (tenant: Tenant, security: string) => {
146
160
  return response;
147
161
  } catch (err) {
148
162
  console.error("Error in tenant deletion WebSocket request:", err);
149
- eventHelper.tenant.publish.deletionError(tenant);
150
- let contentMessage = "Unknown error";
151
- let errorContent = "Unknown error";
152
-
153
- if (
154
- typeof err === "object" &&
155
- err !== null &&
156
- "error" in err &&
157
- typeof (err as any).error === "object" &&
158
- (err as any).error !== null
159
- ) {
160
- if ("code" in (err as any).error) {
161
- contentMessage = (err as any).error.code;
162
- }
163
- if ("content" in (err as any).error) {
164
- errorContent = (err as any).error.content;
165
- }
166
- }
163
+ const { code: contentMessage, content: errorContent } =
164
+ extractWsErrorInfo(err);
167
165
  const tenantDeletionErrorNotification: Notification = {
168
166
  type: "error",
169
- subtype: "tenant-deletion-error",
167
+ subtype: errors.tenant.deletionError.subtype,
170
168
  info_content: {
171
169
  code: contentMessage,
172
170
  message: errorContent,
@@ -189,27 +187,32 @@ export const updateTenant = async (tenant: Tenant, security: string) => {
189
187
  await initializeGlobalWebSocketClient(security);
190
188
 
191
189
  const hasNpmRegistry =
192
- tenant.npmRegistry && tenant.npmRegistry.endpoint !== "";
190
+ tenant.npmRegistry !== undefined && tenant.npmRegistry !== null;
191
+ const isNpmRegistryEmpty =
192
+ hasNpmRegistry &&
193
+ tenant.npmRegistry!.endpoint === "" &&
194
+ tenant.npmRegistry!.domain === "" &&
195
+ tenant.npmRegistry!.credentials === "" &&
196
+ tenant.npmRegistry!.public === false;
193
197
  const hasPlan = tenant.plan?.name;
194
198
 
195
199
  const updateBody: Record<string, any> = {
196
200
  tenant: tenant.name,
197
- spec: {
198
- registry: hasNpmRegistry
199
- ? {
200
- kind: "git",
201
- endpoint: tenant.npmRegistry!.endpoint,
202
- domain: tenant.npmRegistry!.domain,
203
- credentials: tenant.npmRegistry!.credentials,
204
- public: tenant.npmRegistry!.public,
205
- }
206
- : undefined,
207
- },
201
+ spec: {},
208
202
  };
209
-
210
203
  if (hasPlan) {
211
204
  updateBody.provider = tenant.plan!.provider || "";
212
205
  updateBody.plan = tenant.plan!.name;
206
+ } else if (hasNpmRegistry) {
207
+ updateBody.spec.registry = isNpmRegistryEmpty
208
+ ? null
209
+ : {
210
+ kind: "git",
211
+ endpoint: tenant.npmRegistry!.endpoint,
212
+ domain: tenant.npmRegistry!.domain,
213
+ credentials: tenant.npmRegistry!.credentials,
214
+ public: tenant.npmRegistry!.public,
215
+ };
213
216
  }
214
217
 
215
218
  const response = await makeGlobalWebSocketRequest(
@@ -224,7 +227,7 @@ export const updateTenant = async (tenant: Tenant, security: string) => {
224
227
  eventHelper.tenant.publish.updated(updatedTenant);
225
228
  const tenantCreatedNotification: Notification = {
226
229
  type: "success",
227
- subtype: "tenant-updated",
230
+ subtype: errors.tenant.updated.subtype,
228
231
  date: Date.now().toString(),
229
232
  status: "unread",
230
233
  callToAction: false,
@@ -236,27 +239,13 @@ export const updateTenant = async (tenant: Tenant, security: string) => {
236
239
  return response;
237
240
  } catch (err) {
238
241
  console.error("Error in tenant update WebSocket request:", err);
239
- eventHelper.tenant.publish.updateError(tenant);
240
- let contentMessage = "Unknown error";
241
- let errorContent = "Unknown error";
242
-
243
- if (
244
- typeof err === "object" &&
245
- err !== null &&
246
- "error" in err &&
247
- typeof (err as any).error === "object" &&
248
- (err as any).error !== null
249
- ) {
250
- if ("code" in (err as any).error) {
251
- contentMessage = (err as any).error.code;
252
- }
253
- if ("content" in (err as any).error) {
254
- errorContent = (err as any).error.content;
255
- }
256
- }
242
+ const { code: contentMessage, content: errorContent } =
243
+ extractWsErrorInfo(err);
244
+ const { plan, ...tenantWithoutPlan } = tenant;
245
+ eventHelper.tenant.publish.updateError(tenantWithoutPlan as Tenant);
257
246
  const tenantUpdateErrorNotification: Notification = {
258
247
  type: "error",
259
- subtype: "tenant-update-error",
248
+ subtype: errors.tenant.updateError.subtype,
260
249
  info_content: {
261
250
  code: contentMessage,
262
251
  message: errorContent,
@@ -324,7 +313,7 @@ export const createTenantHTTP = async (tenant: Tenant) => {
324
313
  eventHelper.tenant.publish.created(updatedTenant);
325
314
  const tenantCreatedNotification: Notification = {
326
315
  type: "success",
327
- subtype: "tenant-created",
316
+ subtype: errors.tenant.created.subtype,
328
317
  date: Date.now().toString(),
329
318
  status: "unread",
330
319
  callToAction: false,
@@ -356,7 +345,7 @@ export const createTenantHTTP = async (tenant: Tenant) => {
356
345
 
357
346
  const tenantCreationErrorNotification: Notification = {
358
347
  type: "error",
359
- subtype: "tenant-creation-error",
348
+ subtype: errors.tenant.creationError.subtype,
360
349
  info_content: {
361
350
  code: errorCode,
362
351
  message: errorMessage,
@@ -387,7 +376,7 @@ export const deleteTenantHTTP = async (tenant: Tenant) => {
387
376
  if (response.ok) {
388
377
  const tenantDeletedNotification: Notification = {
389
378
  type: "success",
390
- subtype: "tenant-deleting",
379
+ subtype: errors.tenant.deleting.subtype,
391
380
  date: Date.now().toString(),
392
381
  status: "unread",
393
382
  callToAction: false,
@@ -416,7 +405,7 @@ export const deleteTenantHTTP = async (tenant: Tenant) => {
416
405
 
417
406
  const tenantDeletionErrorNotification: Notification = {
418
407
  type: "error",
419
- subtype: "tenant-deletion-error",
408
+ subtype: errors.tenant.deletionError.subtype,
420
409
  info_content: {
421
410
  code: errorCode,
422
411
  message: errorMessage,
@@ -444,12 +433,11 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
444
433
  tenant.plan?.provider || ""
445
434
  );
446
435
  }
436
+ const hasPlan = tenant.plan && tenant.plan?.name !== "" && tenant.plan?.provider !== "";
447
437
  const tenantBody =
448
- tenant.npmRegistry && tenant.npmRegistry.endpoint !== ""
438
+ !hasPlan && tenant.npmRegistry && tenant.npmRegistry.endpoint !== ""
449
439
  ? {
450
440
  tenant: tenant.name,
451
- provider: tenant.plan?.provider || "",
452
- plan: tenant.plan?.name || "",
453
441
  spec: {
454
442
  registry: {
455
443
  kind: "git",
@@ -462,9 +450,7 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
462
450
  }
463
451
  : {
464
452
  tenant: tenant.name,
465
- spec: {
466
- registry: undefined,
467
- },
453
+ spec: {},
468
454
  };
469
455
  const response = await fetch(updateTenantUrl, {
470
456
  method: "PATCH",
@@ -479,7 +465,7 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
479
465
  eventHelper.tenant.publish.updated(updatedTenant);
480
466
  const tenantCreatedNotification: Notification = {
481
467
  type: "success",
482
- subtype: "tenant-updated",
468
+ subtype: errors.tenant.updated.subtype,
483
469
  date: Date.now().toString(),
484
470
  status: "unread",
485
471
  callToAction: false,
@@ -489,7 +475,9 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
489
475
  };
490
476
  eventHelper.notification.publish.creation(tenantCreatedNotification);
491
477
  } else {
492
- eventHelper.tenant.publish.updateError(tenant);
478
+ // The request failed, so the plan change must not be reflected as applied.
479
+ const { plan, ...tenantWithoutPlan } = tenant;
480
+ eventHelper.tenant.publish.updateError(tenantWithoutPlan as Tenant);
493
481
 
494
482
  let errorCode = "Unknown error";
495
483
  let errorMessage = "Unknown error";
@@ -508,7 +496,7 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
508
496
 
509
497
  const tenantUpdateErrorNotification: Notification = {
510
498
  type: "error",
511
- subtype: "tenant-update-error",
499
+ subtype: errors.tenant.updateError.subtype,
512
500
  info_content: {
513
501
  code: errorCode,
514
502
  message: errorMessage,
@@ -558,11 +546,12 @@ export const createRegistry = async (
558
546
 
559
547
  const dregistryCreatedNotification: Notification = {
560
548
  type: "success",
561
- subtype: "registry-created",
549
+ subtype: errors.registry.created.subtype,
562
550
  date: Date.now().toString(),
563
551
  status: "unread",
564
552
  callToAction: false,
565
553
  data: {
554
+ registry: registry.name,
566
555
  tenant: tenant.name,
567
556
  },
568
557
  };
@@ -577,27 +566,12 @@ export const createRegistry = async (
577
566
  webSocketStatus: getWebSocketStatus(),
578
567
  });
579
568
 
580
- let contentMessage = "Unknown error";
581
- let errorContent = "Unknown error";
582
-
583
- if (
584
- typeof error === "object" &&
585
- error !== null &&
586
- "error" in error &&
587
- typeof (error as any).error === "object" &&
588
- (error as any).error !== null
589
- ) {
590
- if ("code" in (error as any).error) {
591
- contentMessage = (error as any).error.code;
592
- }
593
- if ("content" in (error as any).error) {
594
- errorContent = (error as any).error.content;
595
- }
596
- }
569
+ const { code: contentMessage, content: errorContent } =
570
+ extractWsErrorInfo(error);
597
571
 
598
572
  const dregistryCreationErrorNotification: Notification = {
599
573
  type: "error",
600
- subtype: "registry-creation-error",
574
+ subtype: errors.registry.creationError.subtype,
601
575
  info_content: {
602
576
  code: contentMessage,
603
577
  message: errorContent,
@@ -658,11 +632,12 @@ export const updateRegistry = async (
658
632
  );
659
633
  const dregistryUpdatedNotification: Notification = {
660
634
  type: "success",
661
- subtype: "registry-updated",
635
+ subtype: errors.registry.updated.subtype,
662
636
  date: Date.now().toString(),
663
637
  status: "unread",
664
638
  callToAction: false,
665
639
  data: {
640
+ registry: registry.name,
666
641
  tenant: tenant.name,
667
642
  },
668
643
  };
@@ -679,27 +654,12 @@ export const updateRegistry = async (
679
654
  webSocketStatus: getWebSocketStatus(),
680
655
  });
681
656
 
682
- let contentMessage = "Unknown error";
683
- let errorContent = "Unknown error";
684
-
685
- if (
686
- typeof error === "object" &&
687
- error !== null &&
688
- "error" in error &&
689
- typeof (error as any).error === "object" &&
690
- (error as any).error !== null
691
- ) {
692
- if ("code" in (error as any).error) {
693
- contentMessage = (error as any).error.code;
694
- }
695
- if ("content" in (error as any).error) {
696
- errorContent = (error as any).error.content;
697
- }
698
- }
657
+ const { code: contentMessage, content: errorContent } =
658
+ extractWsErrorInfo(error);
699
659
 
700
660
  const dregistryUpdateErrorNotification: Notification = {
701
661
  type: "error",
702
- subtype: "registry-update-error",
662
+ subtype: errors.registry.updateError.subtype,
703
663
  info_content: {
704
664
  code: contentMessage,
705
665
  message: errorContent,
@@ -742,11 +702,12 @@ export const deleteRegistry = async (
742
702
 
743
703
  const dregistryDeletedNotification: Notification = {
744
704
  type: "success",
745
- subtype: "registry-deleted",
705
+ subtype: errors.registry.deleted.subtype,
746
706
  date: Date.now().toString(),
747
707
  status: "unread",
748
708
  callToAction: false,
749
709
  data: {
710
+ registry: registry.name,
750
711
  tenant: tenant.name,
751
712
  },
752
713
  };
@@ -762,27 +723,12 @@ export const deleteRegistry = async (
762
723
  webSocketStatus: getWebSocketStatus(),
763
724
  });
764
725
 
765
- let contentMessage = "Unknown error";
766
- let errorContent = "Unknown error";
767
-
768
- if (
769
- typeof error === "object" &&
770
- error !== null &&
771
- "error" in error &&
772
- typeof (error as any).error === "object" &&
773
- (error as any).error !== null
774
- ) {
775
- if ("code" in (error as any).error) {
776
- contentMessage = (error as any).error.code;
777
- }
778
- if ("content" in (error as any).error) {
779
- errorContent = (error as any).error.content;
780
- }
781
- }
726
+ const { code: contentMessage, content: errorContent } =
727
+ extractWsErrorInfo(error);
782
728
 
783
729
  const dregistryDeletionErrorNotification: Notification = {
784
730
  type: "error",
785
- subtype: "registry-deletion-error",
731
+ subtype: errors.registry.deletionError.subtype,
786
732
  info_content: {
787
733
  code: contentMessage,
788
734
  message: errorContent,
@@ -826,7 +772,7 @@ export const inviteUser = async (
826
772
  );
827
773
  const tenantInvitedNotification: Notification = {
828
774
  type: "success",
829
- subtype: "tenant-user-invited",
775
+ subtype: errors.tenant.userInvited.subtype,
830
776
  date: Date.now().toString(),
831
777
  status: "unread",
832
778
  callToAction: false,
@@ -848,26 +794,11 @@ export const inviteUser = async (
848
794
  role: role,
849
795
  webSocketStatus: getWebSocketStatus(),
850
796
  });
851
- let contentMessage = "Unknown error";
852
- let errorContent = "Unknown error";
853
-
854
- if (
855
- typeof error === "object" &&
856
- error !== null &&
857
- "error" in error &&
858
- typeof (error as any).error === "object" &&
859
- (error as any).error !== null
860
- ) {
861
- if ("code" in (error as any).error) {
862
- contentMessage = (error as any).error.code;
863
- }
864
- if ("content" in (error as any).error) {
865
- errorContent = (error as any).error.content;
866
- }
867
- }
797
+ const { code: contentMessage, content: errorContent } =
798
+ extractWsErrorInfo(error);
868
799
  const tenantInviteErrorNotification: Notification = {
869
800
  type: "error",
870
- subtype: "tenant-user-invite-error",
801
+ subtype: errors.tenant.userInviteError.subtype,
871
802
  info_content: {
872
803
  code: contentMessage,
873
804
  message: errorContent,
@@ -908,7 +839,7 @@ export const removeUser = async (
908
839
  );
909
840
  const tenantUserRemovedNotification: Notification = {
910
841
  type: "success",
911
- subtype: "tenant-user-removed",
842
+ subtype: errors.tenant.userRemoved.subtype,
912
843
  date: Date.now().toString(),
913
844
  status: "unread",
914
845
  callToAction: false,
@@ -927,26 +858,11 @@ export const removeUser = async (
927
858
  userId: userId,
928
859
  webSocketStatus: getWebSocketStatus(),
929
860
  });
930
- let contentMessage = "Unknown error";
931
- let errorContent = "Unknown error";
932
-
933
- if (
934
- typeof error === "object" &&
935
- error !== null &&
936
- "error" in error &&
937
- typeof (error as any).error === "object" &&
938
- (error as any).error !== null
939
- ) {
940
- if ("code" in (error as any).error) {
941
- contentMessage = (error as any).error.code;
942
- }
943
- if ("content" in (error as any).error) {
944
- errorContent = (error as any).error.content;
945
- }
946
- }
861
+ const { code: contentMessage, content: errorContent } =
862
+ extractWsErrorInfo(error);
947
863
  const tenantUserRemovedErrorNotification: Notification = {
948
864
  type: "error",
949
- subtype: "tenant-user-removed-error",
865
+ subtype: errors.tenant.userRemovedError.subtype,
950
866
  info_content: {
951
867
  code: contentMessage,
952
868
  message: errorContent,
@@ -989,7 +905,7 @@ export const updateUserRole = async (
989
905
  );
990
906
  const tenantUserUpdatedNotification: Notification = {
991
907
  type: "success",
992
- subtype: "user-role-updated",
908
+ subtype: errors.tenant.roleUpdated.subtype,
993
909
  date: Date.now().toString(),
994
910
  status: "unread",
995
911
  callToAction: false,
@@ -1010,26 +926,11 @@ export const updateUserRole = async (
1010
926
  role: role,
1011
927
  webSocketStatus: getWebSocketStatus(),
1012
928
  });
1013
- let contentMessage = "Unknown error";
1014
- let errorContent = "Unknown error";
1015
-
1016
- if (
1017
- typeof error === "object" &&
1018
- error !== null &&
1019
- "error" in error &&
1020
- typeof (error as any).error === "object" &&
1021
- (error as any).error !== null
1022
- ) {
1023
- if ("code" in (error as any).error) {
1024
- contentMessage = (error as any).error.code;
1025
- }
1026
- if ("content" in (error as any).error) {
1027
- errorContent = (error as any).error.content;
1028
- }
1029
- }
929
+ const { code: contentMessage, content: errorContent } =
930
+ extractWsErrorInfo(error);
1030
931
  const tenantUserUpdatedErrorNotification: Notification = {
1031
932
  type: "error",
1032
- subtype: "user-role-updated-error",
933
+ subtype: errors.tenant.roleUpdateError.subtype,
1033
934
  info_content: {
1034
935
  code: contentMessage,
1035
936
  message: errorContent,
@@ -1064,7 +965,7 @@ export const acceptInvite = async (tenant: string, security: string) => {
1064
965
  );
1065
966
  const tenantInviteAcceptedNotification: Notification = {
1066
967
  type: "success",
1067
- subtype: "tenant-invite-accepted",
968
+ subtype: errors.tenant.inviteAccepted.subtype,
1068
969
  date: Date.now().toString(),
1069
970
  status: "unread",
1070
971
  callToAction: false,
@@ -1081,26 +982,11 @@ export const acceptInvite = async (tenant: string, security: string) => {
1081
982
  tenant: tenant,
1082
983
  webSocketStatus: getWebSocketStatus(),
1083
984
  });
1084
- let contentMessage = "Unknown error";
1085
- let errorContent = "Unknown error";
1086
-
1087
- if (
1088
- typeof error === "object" &&
1089
- error !== null &&
1090
- "error" in error &&
1091
- typeof (error as any).error === "object" &&
1092
- (error as any).error !== null
1093
- ) {
1094
- if ("code" in (error as any).error) {
1095
- contentMessage = (error as any).error.code;
1096
- }
1097
- if ("content" in (error as any).error) {
1098
- errorContent = (error as any).error.content;
1099
- }
1100
- }
985
+ const { code: contentMessage, content: errorContent } =
986
+ extractWsErrorInfo(error);
1101
987
  const tenantInviteAcceptedErrorNotification: Notification = {
1102
988
  type: "error",
1103
- subtype: "tenant-invite-accepted-error",
989
+ subtype: errors.tenant.inviteAcceptError.subtype,
1104
990
  info_content: {
1105
991
  code: contentMessage,
1106
992
  message: errorContent,
@@ -1120,7 +1006,7 @@ export const acceptInvite = async (tenant: string, security: string) => {
1120
1006
  }
1121
1007
  };
1122
1008
 
1123
- export const rejectInvite = async (tenant: string, security: string) => {
1009
+ export const rejectInvite = async (tenant: string, security: string, leave: boolean) => {
1124
1010
  try {
1125
1011
  await initializeGlobalWebSocketClient(security);
1126
1012
  const queryParams = { tenant: tenant };
@@ -1128,12 +1014,13 @@ export const rejectInvite = async (tenant: string, security: string) => {
1128
1014
  "tenant:reject_proposal_user",
1129
1015
  queryParams,
1130
1016
  30000,
1131
- "DELETE",
1017
+ "REJECT",
1132
1018
  `${tenant}/reject`
1133
1019
  );
1134
- const tenantInviteRejectedNotification: Notification = {
1020
+ if(leave){
1021
+ const tenantInviteRejectedNotification: Notification = {
1135
1022
  type: "success",
1136
- subtype: "tenant-invite-rejected",
1023
+ subtype: errors.tenant.leave.subtype,
1137
1024
  date: Date.now().toString(),
1138
1025
  status: "unread",
1139
1026
  callToAction: false,
@@ -1142,6 +1029,21 @@ export const rejectInvite = async (tenant: string, security: string) => {
1142
1029
  },
1143
1030
  };
1144
1031
  eventHelper.notification.publish.creation(tenantInviteRejectedNotification);
1032
+ }
1033
+ else{
1034
+ const tenantInviteRejectedNotification: Notification = {
1035
+ type: "success",
1036
+ subtype: errors.tenant.inviteRejected.subtype,
1037
+ date: Date.now().toString(),
1038
+ status: "unread",
1039
+ callToAction: false,
1040
+ data: {
1041
+ tenant: tenant,
1042
+ },
1043
+ };
1044
+ eventHelper.notification.publish.creation(tenantInviteRejectedNotification);
1045
+ }
1046
+
1145
1047
  return response;
1146
1048
  } catch (error) {
1147
1049
  console.error("Error rejecting tenant invite:", {
@@ -1150,26 +1052,11 @@ export const rejectInvite = async (tenant: string, security: string) => {
1150
1052
  tenant: tenant,
1151
1053
  webSocketStatus: getWebSocketStatus(),
1152
1054
  });
1153
- let contentMessage = "Unknown error";
1154
- let errorContent = "Unknown error";
1155
-
1156
- if (
1157
- typeof error === "object" &&
1158
- error !== null &&
1159
- "error" in error &&
1160
- typeof (error as any).error === "object" &&
1161
- (error as any).error !== null
1162
- ) {
1163
- if ("code" in (error as any).error) {
1164
- contentMessage = (error as any).error.code;
1165
- }
1166
- if ("content" in (error as any).error) {
1167
- errorContent = (error as any).error.content;
1168
- }
1169
- }
1055
+ const { code: contentMessage, content: errorContent } =
1056
+ extractWsErrorInfo(error);
1170
1057
  const tenantInviteRejectedErrorNotification: Notification = {
1171
1058
  type: "error",
1172
- subtype: "tenant-invite-rejected-error",
1059
+ subtype: errors.tenant.inviteRejectError.subtype,
1173
1060
  info_content: {
1174
1061
  code: contentMessage,
1175
1062
  message: errorContent,
@@ -1222,7 +1109,7 @@ export const createToken = async (
1222
1109
 
1223
1110
  const tenantTokenCreatedNotification: Notification = {
1224
1111
  type: "success",
1225
- subtype: "token-created",
1112
+ subtype: errors.user.tokenCreated.subtype,
1226
1113
  date: Date.now().toString(),
1227
1114
  status: "unread",
1228
1115
  callToAction: false,
@@ -1259,7 +1146,8 @@ export const deleteToken = async (
1259
1146
  queryParams,
1260
1147
  30000,
1261
1148
  "DELETE",
1262
- `${tenantName}/tokens/${tokenID}`
1149
+ `${tenantName}/tokens/${tokenID}`,
1150
+ "token"
1263
1151
  );
1264
1152
  return response;
1265
1153
  } catch (error) {