@kumori/aurora-interfaces 1.0.22 → 1.0.24

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.
@@ -0,0 +1,200 @@
1
+ import { ROUTE_NAMES } from "./routesEnum";
2
+ import { buttonAction, CallToActionNotification, Notification } from "../interfaces/notification-interface";
3
+
4
+ interface callToAction {
5
+ type: string;
6
+ criticality: "critical" | "high" | "low";
7
+ support?: boolean;
8
+ noActions?: boolean;
9
+ actions?: buttonAction[];
10
+ }
11
+
12
+ // La idea es tener aqui la definicion de todas las notificaciones call to action y que el userContext consulte esta definicion al recibir una notificacion normal,
13
+ // si el type de la notificacion recibida coincide con el type de algun CallToAction se creara una CallToActionNotification y se añadira a la lista de notificaciones callToActiondel usuario.
14
+ // Esto permite que el front pueda mostrar notificaciones call to action sin necesidad de que el backend las envie,
15
+ // simplemente con que el backend envie una notificacion normal con un type que coincida con alguno de los definidos aqui, el userContext creara la CallToActionNotification y el front la mostrara al usuario.
16
+ //
17
+ // De esta forma tenemos aqui una definicion desacoplada de todas las notificaciones call to action que queremos mostrar al usuario,
18
+ // el backend solo tiene que enviar notificaciones normales con un type que coincida con alguno de los de esta definicion para que el front las muestre como call to action.
19
+ //
20
+ // El front usará la route para redirigir al usuario a la pagina correspondiente cuando haga click en el boton de la notificacion call to action.
21
+ //
22
+ // Se expone como un Map (type -> callToAction) en lugar de un array porque el userContext necesita comprobar el type
23
+ // de cada notificacion que recibe, y con un array habria que recorrerlo entero (find/some) cada vez, es decir O(n) por notificacion.
24
+ // Con un Map la busqueda por type es O(1), y el coste de construirlo (recorrer las entradas una sola vez) se paga una unica vez al cargar el modulo.
25
+ // Los "type" de aqui abajo coinciden con los "subtype" definidos en errorsEnum.ts: el backend envia una
26
+ // notificacion normal cuyo type es ese identificador (p.ej. "tenant-deletion-error") y, si coincide con
27
+ // una de estas entradas, el userContext genera la CallToActionNotification correspondiente.
28
+ const callToActionDefinitions: callToAction[] = [
29
+ {
30
+ type: "tenant-creation-error",
31
+ criticality: "high",
32
+ support: true,
33
+ actions: [
34
+ { label: "Retry", buttonType: "primary", icon: "refresh", route: ROUTE_NAMES.CREATE_TENANT },
35
+ { label: "Contact support", buttonType: "text", route: ROUTE_NAMES.USER_INFO },
36
+ ],
37
+ },
38
+ {
39
+ type: "tenant-deletion-error",
40
+ criticality: "high",
41
+ support: true,
42
+ actions: [
43
+ { label: "Retry deletion", buttonType: "primary", icon: "delete", route: ROUTE_NAMES.TENANTS },
44
+ ],
45
+ },
46
+ {
47
+ type: "tenant-user-invite-error",
48
+ criticality: "low",
49
+ actions: [
50
+ { label: "Retry invite", buttonType: "secondary", route: ROUTE_NAMES.TENANTS },
51
+ ],
52
+ },
53
+ {
54
+ type: "account-creation-error",
55
+ criticality: "high",
56
+ support: true,
57
+ actions: [
58
+ { label: "Retry", buttonType: "primary", icon: "refresh", route: ROUTE_NAMES.CREATE_ACCOUNT },
59
+ ],
60
+ },
61
+ {
62
+ type: "account-deletion-error",
63
+ criticality: "high",
64
+ support: true,
65
+ actions: [
66
+ { label: "Retry", buttonType: "primary", icon: "delete", route: ROUTE_NAMES.ACCOUNTS },
67
+ ],
68
+ },
69
+ {
70
+ type: "account-clean-error",
71
+ criticality: "low",
72
+ actions: [
73
+ { label: "View account", buttonType: "text", route: ROUTE_NAMES.ACCOUNTS },
74
+ ],
75
+ },
76
+ {
77
+ type: "environment-creation-error",
78
+ criticality: "high",
79
+ support: true,
80
+ actions: [
81
+ { label: "Retry", buttonType: "primary", icon: "refresh", route: ROUTE_NAMES.CREATE_ENVIRONMENT },
82
+ ],
83
+ },
84
+ {
85
+ type: "environment-deletion-error",
86
+ criticality: "high",
87
+ support: true,
88
+ actions: [
89
+ { label: "Retry", buttonType: "primary", icon: "delete", route: ROUTE_NAMES.ENVIRONMENTS },
90
+ ],
91
+ },
92
+ {
93
+ type: "environment-scale-error",
94
+ criticality: "low",
95
+ actions: [
96
+ { label: "View environment", buttonType: "text", route: ROUTE_NAMES.ENVIRONMENTS },
97
+ ],
98
+ },
99
+ {
100
+ type: "deployment-error",
101
+ criticality: "critical",
102
+ support: true,
103
+ actions: [
104
+ { label: "Retry deployment", buttonType: "primary", icon: "refresh", route: ROUTE_NAMES.DEPLOY_SERVICE },
105
+ { label: "View logs", buttonType: "text", route: ROUTE_NAMES.OBSERVABILITY },
106
+ ],
107
+ },
108
+ {
109
+ type: "error-instance-update",
110
+ criticality: "critical",
111
+ support: true,
112
+ actions: [
113
+ { label: "Retry", buttonType: "primary", icon: "refresh", route: ROUTE_NAMES.RUNTIME },
114
+ ],
115
+ },
116
+ {
117
+ type: "error-service-link",
118
+ criticality: "high",
119
+ actions: [
120
+ { label: "Retry link", buttonType: "primary", route: ROUTE_NAMES.LINK_SERVICES },
121
+ ],
122
+ },
123
+ {
124
+ type: "resource-creation-error",
125
+ criticality: "high",
126
+ support: true,
127
+ actions: [
128
+ { label: "Retry", buttonType: "primary", icon: "refresh", route: ROUTE_NAMES.CREATE_RESOURCE },
129
+ ],
130
+ },
131
+ {
132
+ type: "resource-deletion-error",
133
+ criticality: "high",
134
+ support: true,
135
+ actions: [
136
+ { label: "Retry", buttonType: "primary", icon: "delete", route: ROUTE_NAMES.RESOURCES },
137
+ ],
138
+ },
139
+ {
140
+ type: "user-delete-error",
141
+ criticality: "critical",
142
+ support: true,
143
+ actions: [
144
+ { label: "Contact support", buttonType: "primary", route: ROUTE_NAMES.USER_INFO },
145
+ ],
146
+ },
147
+ // No todos los call to action son errores: tambien sirven para destacar notificaciones "normales"
148
+ // (exitos) que conviene que el usuario pueda abrir con un click.
149
+ {
150
+ type: "tenant-created",
151
+ criticality: "low",
152
+ actions: [
153
+ { label: "View tenant", buttonType: "text", route: ROUTE_NAMES.TENANTS },
154
+ ],
155
+ },
156
+ {
157
+ type: "account-created",
158
+ criticality: "low",
159
+ actions: [
160
+ { label: "View account", buttonType: "text", route: ROUTE_NAMES.ACCOUNTS },
161
+ ],
162
+ },
163
+ {
164
+ type: "deployment-success",
165
+ criticality: "low",
166
+ actions: [
167
+ { label: "View service", buttonType: "text", route: ROUTE_NAMES.SERVICE_DETAIL },
168
+ ],
169
+ },
170
+ {
171
+ // Caso limite a proposito: solo informa (noActions), sin actions. Sirve para probar
172
+ // createCallToActionNotification cuando cta.actions es undefined.
173
+ type: "plan-upgrade",
174
+ criticality: "low",
175
+ noActions: true,
176
+ },
177
+ ];
178
+
179
+ const CallToActionMap: Map<string, callToAction> = new Map(
180
+ callToActionDefinitions.map((cta) => [cta.type, cta])
181
+ );
182
+
183
+ // Helper para que el userContext no pueda modificar el map de ninguna forma, solo acceder a su información.
184
+ export function getCallToActionByType(type: string): callToAction | undefined {
185
+ return CallToActionMap.get(type);
186
+ }
187
+
188
+ export function createCallToActionNotification(
189
+ notification: Notification,
190
+ cta: callToAction
191
+ ): CallToActionNotification {
192
+ return {
193
+ ...notification,
194
+ notificationType: 'callToAction',
195
+ criticality: cta.criticality,
196
+ support: cta.support,
197
+ noActions: cta.noActions,
198
+ actions: cta.actions,
199
+ };
200
+ }
@@ -0,0 +1,23 @@
1
+ export enum ROUTE_NAMES {
2
+ HOME = "home",
3
+ TENANTS = "tenants",
4
+ ACCOUNTS = "accounts",
5
+ ENVIRONMENTS = "environments",
6
+ RUNTIME = "runtime",
7
+ RESOURCES = "resources",
8
+ DEPLOY = "deploy",
9
+ USER_INFO = "me",
10
+ CREATE_TENANT = "create-tenant",
11
+ DEPLOY_SERVICE = "deploy-service",
12
+ DEPLOY_MARKETPLACE = "deploy-marketplace",
13
+ CREATE_ACCOUNT = "create-account",
14
+ CREATE_ENVIRONMENT = "create-environment",
15
+ CREATE_ORGANIZATION = "create-organization",
16
+ SERVICE_DETAIL = "service-detail",
17
+ CREATE_APPLICATION = "create-application",
18
+ LINK_SERVICES = "link-services",
19
+ CREATE_RESOURCE = "create-resource",
20
+ REGISTER = "register",
21
+ OBSERVABILITY = "observability",
22
+ CREATE_RESOURCE_STANDALONE = "create-resource-standalone",
23
+ };
@@ -1,24 +1,41 @@
1
- export interface Notification{
2
- type: string;
3
- subtype: string;
4
- info_content?: {
5
- code: string;
6
- message: string;
7
- timestamp?: string;
8
- }
9
- date: string;
10
- data?: any;
11
- status: 'read' | 'unread';
12
- callToAction: boolean;
13
- userError?: boolean;
14
- }
1
+ import { ROUTE_NAMES } from "../enums/routesEnum";
15
2
 
16
- export interface FormattedNotification extends Notification{
17
- title: string;
18
- description: string;
19
- icon: string;
20
- color: string;
21
- actions?: { label: string; color: string; action: () => void }[];
22
- presentationType: "toast" | "popup";
3
+ export interface Notification {
4
+ type: string;
5
+ subtype: string;
6
+ info_content?: {
7
+ code: string;
8
+ message: string;
9
+ timestamp?: string;
10
+ };
11
+ date: string;
12
+ data?: any;
13
+ status: "read" | "unread";
14
+ notificationType: 'regular' | 'callToAction'; // Cambiar por type
15
+ userError?: boolean;
16
+ }
17
+ export interface buttonAction {
18
+ label: string;
19
+ buttonType: string;
20
+ outlined?: boolean;
21
+ icon?: string;
22
+ iconColor?: string;
23
+ route: ROUTE_NAMES;
24
+ }
25
+ export interface CallToActionNotification extends Notification {
26
+ notificationType: 'callToAction';
27
+ criticality: "critical" | "high" | "low";
28
+ support?: boolean;
29
+ noActions?: boolean;
30
+ actions?: buttonAction[];
31
+ // Cambiar por array actions y tiprarlo.
32
+ }
23
33
 
24
- }
34
+ export interface FormattedNotification extends Notification {
35
+ title: string;
36
+ description: string;
37
+ icon: string;
38
+ color: string;
39
+ actions?: { label: string; color: string; action: () => void }[];
40
+ presentationType: "toast" | "popup";
41
+ }
@@ -1,4 +1,4 @@
1
- import { Notification } from "./notification-interface";
1
+ import { CallToActionNotification, Notification } from "./notification-interface";
2
2
  import { Plan } from "./plan-interface";
3
3
  import { Token } from "./token-interface";
4
4
  import { Tenant } from "./tenant-interface";
@@ -52,6 +52,7 @@ export interface UserData {
52
52
  platform?: Platform;
53
53
  status?: "logged" | "notlogged" | "maintenance" | "unknown";
54
54
  notifications?: Notification[];
55
+ callToActionNotifications?: CallToActionNotification[];
55
56
  plans?: Plan[];
56
57
  discoveryMethod?: string;
57
58
  }
@@ -76,6 +77,7 @@ export class User implements UserData {
76
77
  this.platform = platform ?? userData.platform;
77
78
  this.status = userData.status || "logged";
78
79
  this.notifications = userData.notifications || [];
80
+ this.callToActionNotifications = userData.callToActionNotifications || [];
79
81
  this.plans = userData.plans || [];
80
82
  this.provider = userData.provider;
81
83
  this.discoveryMethod = userData.discoveryMethod;
@@ -99,6 +101,7 @@ export class User implements UserData {
99
101
  platform?: Platform;
100
102
  status?: "logged" | "notlogged" | "maintenance" | "unknown";
101
103
  notifications?: Notification[];
104
+ callToActionNotifications?: CallToActionNotification[];
102
105
  plans?: Plan[];
103
106
  discoveryMethod?: string;
104
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-interfaces",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "aurora interfaces",
5
5
  "main": "export-interfaces.ts",
6
6
  "repository": {