@kumori/aurora-backend-handler 1.0.100 → 1.0.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +21 -21
- package/CHANGELOG.md +10 -0
- package/api/account-api-service.ts +35 -27
- package/api/deploy-service-helper.ts +72 -33
- package/api/environment-api-service.ts +20 -15
- package/api/marketplace-api-service.ts +32 -81
- package/api/resources-api-service.ts +28 -28
- package/api/service-api-service.ts +26 -22
- package/api/tenant-api-service.ts +145 -257
- package/api/user-api-service.ts +27 -12
- package/backend-handler.ts +373 -348
- package/developer.md +998 -0
- package/event-helper.ts +13 -3
- package/event-names.ts +3 -0
- package/helpers/account-helper.ts +15 -15
- package/helpers/environment-helper.ts +27 -30
- package/helpers/marketplace-helper.ts +109 -0
- package/helpers/resource-helper.ts +19 -1
- package/helpers/revision-helper.ts +68 -18
- package/helpers/service-helper.ts +49 -33
- package/helpers/tenant-helper.ts +0 -5
- package/helpers/token-helper.ts +74 -2
- package/helpers/user-helper.ts +71 -31
- package/jest.config.ts +1 -0
- package/package.json +3 -3
- package/test/backend-handler.test.ts +992 -730
- package/test/deploy-service-helper.test.ts +707 -273
- package/test/event-helper.test.ts +489 -104
- package/test/event-names.test.ts +186 -0
- package/websocket-manager.ts +369 -66
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Notification, Registry, Tenant, tenantRole } from "@kumori/aurora-interfaces";
|
|
1
|
+
import { getWuiErrorCode, 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
|
|
@@ -65,7 +94,7 @@ export const createTenant = async (tenant: Tenant, security: Security) => {
|
|
|
65
94
|
subtype: "tenant-created",
|
|
66
95
|
date: Date.now().toString(),
|
|
67
96
|
status: "unread",
|
|
68
|
-
|
|
97
|
+
notificationType: "regular",
|
|
69
98
|
data: {
|
|
70
99
|
tenant: tenant.name,
|
|
71
100
|
},
|
|
@@ -79,33 +108,18 @@ export const createTenant = async (tenant: Tenant, security: Security) => {
|
|
|
79
108
|
tenant: tenant.name,
|
|
80
109
|
webSocketStatus: getWebSocketStatus(),
|
|
81
110
|
});
|
|
82
|
-
|
|
83
|
-
|
|
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: getWuiErrorCode("tenant", "createTenant", contentMessage) ?? "tenant-creation-error",
|
|
102
116
|
info_content: {
|
|
103
117
|
code: contentMessage,
|
|
104
118
|
message: errorContent,
|
|
105
119
|
},
|
|
106
120
|
date: Date.now().toString(),
|
|
107
121
|
status: "unread",
|
|
108
|
-
|
|
122
|
+
notificationType: "regular",
|
|
109
123
|
data: {
|
|
110
124
|
tenant: tenant.name,
|
|
111
125
|
},
|
|
@@ -140,40 +154,24 @@ export const deleteTenant = async (tenant: Tenant, security: string) => {
|
|
|
140
154
|
// subtype: "tenant-deleted",
|
|
141
155
|
// date: Date.now().toString(),
|
|
142
156
|
// status: "unread",
|
|
143
|
-
//
|
|
157
|
+
// notificationType: "regular",
|
|
144
158
|
// };
|
|
145
159
|
// eventHelper.notification.publish.creation(tenantDeletedNotification);
|
|
146
160
|
return response;
|
|
147
161
|
} catch (err) {
|
|
148
162
|
console.error("Error in tenant deletion WebSocket request:", err);
|
|
149
|
-
|
|
150
|
-
|
|
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: getWuiErrorCode("tenant", "deleteTenant", contentMessage) ?? "tenant-deletion-error",
|
|
170
168
|
info_content: {
|
|
171
169
|
code: contentMessage,
|
|
172
170
|
message: errorContent,
|
|
173
171
|
},
|
|
174
172
|
date: Date.now().toString(),
|
|
175
173
|
status: "unread",
|
|
176
|
-
|
|
174
|
+
notificationType: "regular",
|
|
177
175
|
data: {
|
|
178
176
|
tenant: tenant.name,
|
|
179
177
|
},
|
|
@@ -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
|
|
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(
|
|
@@ -227,7 +230,7 @@ export const updateTenant = async (tenant: Tenant, security: string) => {
|
|
|
227
230
|
subtype: "tenant-updated",
|
|
228
231
|
date: Date.now().toString(),
|
|
229
232
|
status: "unread",
|
|
230
|
-
|
|
233
|
+
notificationType: "regular",
|
|
231
234
|
data: {
|
|
232
235
|
tenant: tenant.name,
|
|
233
236
|
},
|
|
@@ -236,34 +239,20 @@ 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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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: getWuiErrorCode("tenant", "updateTenant", contentMessage) ?? "tenant-update-error",
|
|
260
249
|
info_content: {
|
|
261
250
|
code: contentMessage,
|
|
262
251
|
message: errorContent,
|
|
263
252
|
},
|
|
264
253
|
date: Date.now().toString(),
|
|
265
254
|
status: "unread",
|
|
266
|
-
|
|
255
|
+
notificationType: "regular",
|
|
267
256
|
data: {
|
|
268
257
|
tenant: tenant.name,
|
|
269
258
|
},
|
|
@@ -327,7 +316,7 @@ export const createTenantHTTP = async (tenant: Tenant) => {
|
|
|
327
316
|
subtype: "tenant-created",
|
|
328
317
|
date: Date.now().toString(),
|
|
329
318
|
status: "unread",
|
|
330
|
-
|
|
319
|
+
notificationType: "regular",
|
|
331
320
|
data: {
|
|
332
321
|
tenant: tenant.name,
|
|
333
322
|
},
|
|
@@ -356,14 +345,14 @@ export const createTenantHTTP = async (tenant: Tenant) => {
|
|
|
356
345
|
|
|
357
346
|
const tenantCreationErrorNotification: Notification = {
|
|
358
347
|
type: "error",
|
|
359
|
-
subtype: "tenant-creation-error",
|
|
348
|
+
subtype: getWuiErrorCode("tenant", "createTenant", errorCode) ?? "tenant-creation-error",
|
|
360
349
|
info_content: {
|
|
361
350
|
code: errorCode,
|
|
362
351
|
message: errorMessage,
|
|
363
352
|
},
|
|
364
353
|
date: Date.now().toString(),
|
|
365
354
|
status: "unread",
|
|
366
|
-
|
|
355
|
+
notificationType: "regular",
|
|
367
356
|
data: {
|
|
368
357
|
tenant: tenant.name,
|
|
369
358
|
},
|
|
@@ -390,7 +379,7 @@ export const deleteTenantHTTP = async (tenant: Tenant) => {
|
|
|
390
379
|
subtype: "tenant-deleting",
|
|
391
380
|
date: Date.now().toString(),
|
|
392
381
|
status: "unread",
|
|
393
|
-
|
|
382
|
+
notificationType: "regular",
|
|
394
383
|
data: {
|
|
395
384
|
tenant: tenant.name,
|
|
396
385
|
},
|
|
@@ -416,14 +405,14 @@ export const deleteTenantHTTP = async (tenant: Tenant) => {
|
|
|
416
405
|
|
|
417
406
|
const tenantDeletionErrorNotification: Notification = {
|
|
418
407
|
type: "error",
|
|
419
|
-
subtype: "tenant-deletion-error",
|
|
408
|
+
subtype: getWuiErrorCode("tenant", "deleteTenant", errorCode) ?? "tenant-deletion-error",
|
|
420
409
|
info_content: {
|
|
421
410
|
code: errorCode,
|
|
422
411
|
message: errorMessage,
|
|
423
412
|
},
|
|
424
413
|
date: Date.now().toString(),
|
|
425
414
|
status: "unread",
|
|
426
|
-
|
|
415
|
+
notificationType: "regular",
|
|
427
416
|
data: {
|
|
428
417
|
tenant: tenant.name,
|
|
429
418
|
},
|
|
@@ -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",
|
|
@@ -482,14 +468,16 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
|
|
|
482
468
|
subtype: "tenant-updated",
|
|
483
469
|
date: Date.now().toString(),
|
|
484
470
|
status: "unread",
|
|
485
|
-
|
|
471
|
+
notificationType: "regular",
|
|
486
472
|
data: {
|
|
487
473
|
tenant: tenant.name,
|
|
488
474
|
},
|
|
489
475
|
};
|
|
490
476
|
eventHelper.notification.publish.creation(tenantCreatedNotification);
|
|
491
477
|
} else {
|
|
492
|
-
|
|
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,14 +496,14 @@ export const updateTenantHTTP = async (tenant: Tenant) => {
|
|
|
508
496
|
|
|
509
497
|
const tenantUpdateErrorNotification: Notification = {
|
|
510
498
|
type: "error",
|
|
511
|
-
subtype: "tenant-update-error",
|
|
499
|
+
subtype: getWuiErrorCode("tenant", "updateTenant", errorCode) ?? "tenant-update-error",
|
|
512
500
|
info_content: {
|
|
513
501
|
code: errorCode,
|
|
514
502
|
message: errorMessage,
|
|
515
503
|
},
|
|
516
504
|
date: Date.now().toString(),
|
|
517
505
|
status: "unread",
|
|
518
|
-
|
|
506
|
+
notificationType: "regular",
|
|
519
507
|
data: {
|
|
520
508
|
tenant: tenant.name,
|
|
521
509
|
},
|
|
@@ -561,8 +549,9 @@ export const createRegistry = async (
|
|
|
561
549
|
subtype: "registry-created",
|
|
562
550
|
date: Date.now().toString(),
|
|
563
551
|
status: "unread",
|
|
564
|
-
|
|
552
|
+
notificationType: "regular",
|
|
565
553
|
data: {
|
|
554
|
+
registry: registry.name,
|
|
566
555
|
tenant: tenant.name,
|
|
567
556
|
},
|
|
568
557
|
};
|
|
@@ -577,34 +566,19 @@ export const createRegistry = async (
|
|
|
577
566
|
webSocketStatus: getWebSocketStatus(),
|
|
578
567
|
});
|
|
579
568
|
|
|
580
|
-
|
|
581
|
-
|
|
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: getWuiErrorCode("registry", "createDRegistry", contentMessage) ?? "registry-creation-error",
|
|
601
575
|
info_content: {
|
|
602
576
|
code: contentMessage,
|
|
603
577
|
message: errorContent,
|
|
604
578
|
},
|
|
605
579
|
date: Date.now().toString(),
|
|
606
580
|
status: "unread",
|
|
607
|
-
|
|
581
|
+
notificationType: "regular",
|
|
608
582
|
data: {
|
|
609
583
|
tenant: tenant.name,
|
|
610
584
|
},
|
|
@@ -661,8 +635,9 @@ export const updateRegistry = async (
|
|
|
661
635
|
subtype: "registry-updated",
|
|
662
636
|
date: Date.now().toString(),
|
|
663
637
|
status: "unread",
|
|
664
|
-
|
|
638
|
+
notificationType: "regular",
|
|
665
639
|
data: {
|
|
640
|
+
registry: registry.name,
|
|
666
641
|
tenant: tenant.name,
|
|
667
642
|
},
|
|
668
643
|
};
|
|
@@ -679,34 +654,19 @@ export const updateRegistry = async (
|
|
|
679
654
|
webSocketStatus: getWebSocketStatus(),
|
|
680
655
|
});
|
|
681
656
|
|
|
682
|
-
|
|
683
|
-
|
|
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: getWuiErrorCode("registry", "updateDRegistry", contentMessage) ?? "registry-update-error",
|
|
703
663
|
info_content: {
|
|
704
664
|
code: contentMessage,
|
|
705
665
|
message: errorContent,
|
|
706
666
|
},
|
|
707
667
|
date: Date.now().toString(),
|
|
708
668
|
status: "unread",
|
|
709
|
-
|
|
669
|
+
notificationType: "regular",
|
|
710
670
|
data: {
|
|
711
671
|
tenant: tenant.name,
|
|
712
672
|
},
|
|
@@ -745,8 +705,9 @@ export const deleteRegistry = async (
|
|
|
745
705
|
subtype: "registry-deleted",
|
|
746
706
|
date: Date.now().toString(),
|
|
747
707
|
status: "unread",
|
|
748
|
-
|
|
708
|
+
notificationType: "regular",
|
|
749
709
|
data: {
|
|
710
|
+
registry: registry.name,
|
|
750
711
|
tenant: tenant.name,
|
|
751
712
|
},
|
|
752
713
|
};
|
|
@@ -762,34 +723,19 @@ export const deleteRegistry = async (
|
|
|
762
723
|
webSocketStatus: getWebSocketStatus(),
|
|
763
724
|
});
|
|
764
725
|
|
|
765
|
-
|
|
766
|
-
|
|
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: getWuiErrorCode("registry", "deleteDRegistry", contentMessage) ?? "registry-deletion-error",
|
|
786
732
|
info_content: {
|
|
787
733
|
code: contentMessage,
|
|
788
734
|
message: errorContent,
|
|
789
735
|
},
|
|
790
736
|
date: Date.now().toString(),
|
|
791
737
|
status: "unread",
|
|
792
|
-
|
|
738
|
+
notificationType: "regular",
|
|
793
739
|
data: {
|
|
794
740
|
tenant: tenant.name,
|
|
795
741
|
},
|
|
@@ -829,7 +775,7 @@ export const inviteUser = async (
|
|
|
829
775
|
subtype: "tenant-user-invited",
|
|
830
776
|
date: Date.now().toString(),
|
|
831
777
|
status: "unread",
|
|
832
|
-
|
|
778
|
+
notificationType: "regular",
|
|
833
779
|
data: {
|
|
834
780
|
tenant: tenant,
|
|
835
781
|
email: email,
|
|
@@ -848,33 +794,18 @@ export const inviteUser = async (
|
|
|
848
794
|
role: role,
|
|
849
795
|
webSocketStatus: getWebSocketStatus(),
|
|
850
796
|
});
|
|
851
|
-
|
|
852
|
-
|
|
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: getWuiErrorCode("tenant", "proposeUser", contentMessage) ?? "tenant-user-invite-error",
|
|
871
802
|
info_content: {
|
|
872
803
|
code: contentMessage,
|
|
873
804
|
message: errorContent,
|
|
874
805
|
},
|
|
875
806
|
date: Date.now().toString(),
|
|
876
807
|
status: "unread",
|
|
877
|
-
|
|
808
|
+
notificationType: "regular",
|
|
878
809
|
data: {
|
|
879
810
|
tenant: tenant,
|
|
880
811
|
email: email,
|
|
@@ -911,7 +842,7 @@ export const removeUser = async (
|
|
|
911
842
|
subtype: "tenant-user-removed",
|
|
912
843
|
date: Date.now().toString(),
|
|
913
844
|
status: "unread",
|
|
914
|
-
|
|
845
|
+
notificationType: "regular",
|
|
915
846
|
data: {
|
|
916
847
|
tenant: tenant,
|
|
917
848
|
user: userId,
|
|
@@ -927,33 +858,18 @@ export const removeUser = async (
|
|
|
927
858
|
userId: userId,
|
|
928
859
|
webSocketStatus: getWebSocketStatus(),
|
|
929
860
|
});
|
|
930
|
-
|
|
931
|
-
|
|
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: getWuiErrorCode("tenant", "excludeUser", contentMessage) ?? "tenant-user-removed-error",
|
|
950
866
|
info_content: {
|
|
951
867
|
code: contentMessage,
|
|
952
868
|
message: errorContent,
|
|
953
869
|
},
|
|
954
870
|
date: Date.now().toString(),
|
|
955
871
|
status: "unread",
|
|
956
|
-
|
|
872
|
+
notificationType: "regular",
|
|
957
873
|
data: {
|
|
958
874
|
tenant: tenant,
|
|
959
875
|
user: userId,
|
|
@@ -992,7 +908,7 @@ export const updateUserRole = async (
|
|
|
992
908
|
subtype: "user-role-updated",
|
|
993
909
|
date: Date.now().toString(),
|
|
994
910
|
status: "unread",
|
|
995
|
-
|
|
911
|
+
notificationType: "regular",
|
|
996
912
|
data: {
|
|
997
913
|
tenant: tenant,
|
|
998
914
|
user: userId,
|
|
@@ -1010,33 +926,18 @@ export const updateUserRole = async (
|
|
|
1010
926
|
role: role,
|
|
1011
927
|
webSocketStatus: getWebSocketStatus(),
|
|
1012
928
|
});
|
|
1013
|
-
|
|
1014
|
-
|
|
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: getWuiErrorCode("tenant", "modifyUserRole", contentMessage) ?? "user-role-updated-error",
|
|
1033
934
|
info_content: {
|
|
1034
935
|
code: contentMessage,
|
|
1035
936
|
message: errorContent,
|
|
1036
937
|
},
|
|
1037
938
|
date: Date.now().toString(),
|
|
1038
939
|
status: "unread",
|
|
1039
|
-
|
|
940
|
+
notificationType: "regular",
|
|
1040
941
|
data: {
|
|
1041
942
|
tenant: tenant,
|
|
1042
943
|
user: userId,
|
|
@@ -1067,7 +968,7 @@ export const acceptInvite = async (tenant: string, security: string) => {
|
|
|
1067
968
|
subtype: "tenant-invite-accepted",
|
|
1068
969
|
date: Date.now().toString(),
|
|
1069
970
|
status: "unread",
|
|
1070
|
-
|
|
971
|
+
notificationType: "regular",
|
|
1071
972
|
data: {
|
|
1072
973
|
tenant: tenant,
|
|
1073
974
|
},
|
|
@@ -1081,33 +982,18 @@ export const acceptInvite = async (tenant: string, security: string) => {
|
|
|
1081
982
|
tenant: tenant,
|
|
1082
983
|
webSocketStatus: getWebSocketStatus(),
|
|
1083
984
|
});
|
|
1084
|
-
|
|
1085
|
-
|
|
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: getWuiErrorCode("tenant", "acceptProposalUser", contentMessage) ?? "tenant-invite-accepted-error",
|
|
1104
990
|
info_content: {
|
|
1105
991
|
code: contentMessage,
|
|
1106
992
|
message: errorContent,
|
|
1107
993
|
},
|
|
1108
994
|
date: Date.now().toString(),
|
|
1109
995
|
status: "unread",
|
|
1110
|
-
|
|
996
|
+
notificationType: "regular",
|
|
1111
997
|
data: {
|
|
1112
998
|
tenant: tenant,
|
|
1113
999
|
},
|
|
@@ -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,20 +1014,36 @@ export const rejectInvite = async (tenant: string, security: string) => {
|
|
|
1128
1014
|
"tenant:reject_proposal_user",
|
|
1129
1015
|
queryParams,
|
|
1130
1016
|
30000,
|
|
1131
|
-
"
|
|
1017
|
+
"REJECT",
|
|
1132
1018
|
`${tenant}/reject`
|
|
1133
1019
|
);
|
|
1134
|
-
|
|
1020
|
+
if(leave){
|
|
1021
|
+
const tenantInviteRejectedNotification: Notification = {
|
|
1022
|
+
type: "success",
|
|
1023
|
+
subtype: "tenant-leave",
|
|
1024
|
+
date: Date.now().toString(),
|
|
1025
|
+
status: "unread",
|
|
1026
|
+
notificationType: "regular",
|
|
1027
|
+
data: {
|
|
1028
|
+
tenant: tenant,
|
|
1029
|
+
},
|
|
1030
|
+
};
|
|
1031
|
+
eventHelper.notification.publish.creation(tenantInviteRejectedNotification);
|
|
1032
|
+
}
|
|
1033
|
+
else{
|
|
1034
|
+
const tenantInviteRejectedNotification: Notification = {
|
|
1135
1035
|
type: "success",
|
|
1136
1036
|
subtype: "tenant-invite-rejected",
|
|
1137
1037
|
date: Date.now().toString(),
|
|
1138
1038
|
status: "unread",
|
|
1139
|
-
|
|
1039
|
+
notificationType: "regular",
|
|
1140
1040
|
data: {
|
|
1141
1041
|
tenant: tenant,
|
|
1142
1042
|
},
|
|
1143
1043
|
};
|
|
1144
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,33 +1052,18 @@ export const rejectInvite = async (tenant: string, security: string) => {
|
|
|
1150
1052
|
tenant: tenant,
|
|
1151
1053
|
webSocketStatus: getWebSocketStatus(),
|
|
1152
1054
|
});
|
|
1153
|
-
|
|
1154
|
-
|
|
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: getWuiErrorCode("tenant", "rejectProposalUser", contentMessage) ?? "tenant-invite-rejected-error",
|
|
1173
1060
|
info_content: {
|
|
1174
1061
|
code: contentMessage,
|
|
1175
1062
|
message: errorContent,
|
|
1176
1063
|
},
|
|
1177
1064
|
date: Date.now().toString(),
|
|
1178
1065
|
status: "unread",
|
|
1179
|
-
|
|
1066
|
+
notificationType: "regular",
|
|
1180
1067
|
data: {
|
|
1181
1068
|
tenant: tenant,
|
|
1182
1069
|
},
|
|
@@ -1225,7 +1112,7 @@ export const createToken = async (
|
|
|
1225
1112
|
subtype: "token-created",
|
|
1226
1113
|
date: Date.now().toString(),
|
|
1227
1114
|
status: "unread",
|
|
1228
|
-
|
|
1115
|
+
notificationType: "regular",
|
|
1229
1116
|
data: {
|
|
1230
1117
|
tenant: tenantName,
|
|
1231
1118
|
tokenName: tokenDescription,
|
|
@@ -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) {
|