@kumori/aurora-backend-handler 1.0.0

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,1127 @@
1
+ import { createUser, loadUser, isUserLogged, updateUser, deleteUSer } from "./api/user-api-service";
2
+ import {
3
+ changeRevision,
4
+ deleteService,
5
+ deployService,
6
+ redeployService,
7
+ requestRevisionData,
8
+ restartService,
9
+ updateService,
10
+ updateServiceLinks,
11
+ } from "./api/service-api-service";
12
+ import {
13
+ deployMarketplaceItem,
14
+ getMarketplaceItems,
15
+ } from "./api/marketplace-api-service";
16
+ import {
17
+ clearAccount,
18
+ createAccount,
19
+ deleteAccount,
20
+ updateAccount,
21
+ } from "./api/account-api-service";
22
+ import {
23
+ acceptInvite,
24
+ createRegistry,
25
+ createTenant,
26
+ createTenantHTTP,
27
+ createToken,
28
+ deleteRegistry,
29
+ deleteTenant,
30
+ deleteToken,
31
+ inviteUser,
32
+ rejectInvite,
33
+ removeUser,
34
+ updateRegistry,
35
+ updateTenant,
36
+ updateTenantHTTP,
37
+ updateUserRole,
38
+ } from "./api/tenant-api-service";
39
+ import {
40
+ clearEnvironment,
41
+ createEnvironment,
42
+ deleteEnvironment,
43
+ scaleEnvironment,
44
+ updateEnvironment,
45
+ } from "./api/environment-api-service";
46
+ import EventHelper, { RegistryUpdatePayload } from "./event-helper";
47
+ import { environment } from "./environment";
48
+ import { initializeGlobalWebSocketClient, updateUserComplete } from "./websocket-manager";
49
+ import {
50
+ createResource,
51
+ deleteResource,
52
+ updateResource,
53
+ } from "./api/resources-api-service";
54
+ import { getPlanProviders } from './api/planProvider-api-service';
55
+ import { Account, Environment, Link, MarketplaceService, Notification, Organization, Resource, Service, Tenant, tenantRole, UserData } from "@hestekumori/aurora-interfaces";
56
+
57
+ export let eventHelper: EventHelper;
58
+ const token =
59
+ "";
60
+ export class BackendHandler {
61
+ private unsubscribeFunctions: (() => void)[] = [];
62
+ constructor(
63
+ route: string,
64
+ globalEventHandler: any,
65
+ baseUrl: string,
66
+ apiVersion: string
67
+ ) {
68
+ if (
69
+ !globalEventHandler ||
70
+ typeof globalEventHandler.subscribe !== "function"
71
+ ) {
72
+ throw new Error(
73
+ "globalEventHandler inválido. Asegúrate de pasar una instancia correcta de EventHandler."
74
+ );
75
+ }
76
+ eventHelper = new EventHelper(globalEventHandler);
77
+ eventHelper.user.subscribe.load((data: UserData) => {
78
+ initializeGlobalWebSocketClient(token, "", "", data);
79
+ });
80
+ const loadedCb = (data: UserData) => {
81
+ updateUserComplete(data);
82
+ };
83
+ eventHelper.user.subscribe.loaded(loadedCb);
84
+
85
+ this.changeRoute(route);
86
+ environment.apiServer.baseUrl = baseUrl;
87
+ environment.apiServer.apiVersion = apiVersion;
88
+ }
89
+
90
+ /**
91
+ * Function to change the route and subscribe to the new route events
92
+ * @param newRoute string with the new route
93
+ */
94
+ public changeRoute(newRoute: string): void {
95
+ this.unsubscribeRouteEvents();
96
+ this.subscribeForRoute(newRoute);
97
+ }
98
+ /**
99
+ * Function to subscribe to the events of the route
100
+ * @param route string with the route
101
+ */
102
+ public subscribeForRoute(route: string): void {
103
+ // const userRoutes = ["user-information", "home", "register"];
104
+ // const accountRoutes = ["accounts", "create-account"];
105
+ // const environmentRoutes = ["environments", "create-environment"];
106
+ // const serviceRoutes = ["deploy-service", "service-detail", "deploy-service","runtime"];
107
+ // const marketplaceRoutes = ["deploy-marketplace", "marketplace","deploy-service"];
108
+ // const resourceRoutes = ["resources", "create-resource", "deploy-service","deploy-marketplace"];
109
+ // const organizationRoutes = ["plans"];
110
+ // const tenantRoutes = ["tenants", "create-tenant", ...organizationRoutes, ...userRoutes];
111
+
112
+ // if (tenantRoutes.includes(route)) {
113
+ // }
114
+ // if (userRoutes.includes(route)) {
115
+ // }
116
+ // if (accountRoutes.includes(route)) {
117
+ // }
118
+ // if (environmentRoutes.includes(route)) {
119
+ // }
120
+ // if (serviceRoutes.includes(route)) {
121
+ // }
122
+ // if (marketplaceRoutes.includes(route)) {
123
+ // }
124
+ // if (resourceRoutes.includes(route)) {
125
+ // }
126
+ // if (organizationRoutes.includes(route)) {
127
+ // }
128
+ this.subscribeTenantEvents();
129
+ this.subscribeUserEvents();
130
+ this.subscribeAccountEvents();
131
+ this.subscribePlanEvents();
132
+ this.subscribeEnvironmentEvents();
133
+ this.subscribeServiceEvents();
134
+ this.subscribeMarketplaceEvents();
135
+ this.subscribeResourceEvents();
136
+ this.subscribeOrganizationEvents();
137
+
138
+ }
139
+ public async isUserLoggedIn(): Promise<boolean> {
140
+ const loggedIn = await isUserLogged(token);
141
+ return loggedIn === true;
142
+ }
143
+ /**
144
+ * Function to unsubscribe all the events
145
+ */
146
+ private unsubscribeRouteEvents(): void {
147
+ this.unsubscribeFunctions.forEach((fn) => fn());
148
+ this.unsubscribeFunctions = [];
149
+ }
150
+ /**
151
+ * Function to subscribe to the tenant events
152
+ */
153
+ private subscribeTenantEvents(): void {
154
+ const creationCb = (data: Tenant) => {
155
+ createTenant(data, token);
156
+ };
157
+ eventHelper.tenant.subscribe.creation(creationCb);
158
+ this.unsubscribeFunctions.push(() =>
159
+ eventHelper.tenant.unsubscribe.creation(creationCb)
160
+ );
161
+
162
+ const createdCb = (data: Tenant) => {
163
+ };
164
+ eventHelper.tenant.subscribe.created(createdCb);
165
+ this.unsubscribeFunctions.push(() =>
166
+ eventHelper.tenant.unsubscribe.created(createdCb)
167
+ );
168
+
169
+ const creationErrorCb = (data: Tenant) => {
170
+ };
171
+ eventHelper.tenant.subscribe.creationError(creationErrorCb);
172
+ this.unsubscribeFunctions.push(() =>
173
+ eventHelper.tenant.unsubscribe.creationError(creationErrorCb)
174
+ );
175
+
176
+ const updateCb = (data: Tenant) => {
177
+ updateTenant(data, token);
178
+ };
179
+ eventHelper.tenant.subscribe.update(updateCb);
180
+ this.unsubscribeFunctions.push(() =>
181
+ eventHelper.tenant.unsubscribe.update(updateCb)
182
+ );
183
+
184
+ const updatedCb = (data: Tenant) => {
185
+ };
186
+ eventHelper.tenant.subscribe.updated(updatedCb);
187
+ this.unsubscribeFunctions.push(() =>
188
+ eventHelper.tenant.unsubscribe.updated(updatedCb)
189
+ );
190
+
191
+ const updateErrorCb = (data: Tenant) => {
192
+ };
193
+ eventHelper.tenant.subscribe.updateError(updateErrorCb);
194
+ this.unsubscribeFunctions.push(() =>
195
+ eventHelper.tenant.unsubscribe.updateError(updateErrorCb)
196
+ );
197
+
198
+ const deleteCb = (data: Tenant) => {
199
+ deleteTenant(data, token);
200
+ //loadUserData();
201
+ };
202
+ eventHelper.tenant.subscribe.delete(deleteCb);
203
+ this.unsubscribeFunctions.push(() =>
204
+ eventHelper.tenant.unsubscribe.delete(deleteCb)
205
+ );
206
+
207
+ const deletedCb = (data: Tenant) => {
208
+ };
209
+ eventHelper.tenant.subscribe.deleted(deletedCb);
210
+ this.unsubscribeFunctions.push(() =>
211
+ eventHelper.tenant.unsubscribe.deleted(deletedCb)
212
+ );
213
+
214
+ const deletionErrorCb = (data: Tenant) => {
215
+ };
216
+ eventHelper.tenant.subscribe.deletionError(deletionErrorCb);
217
+ this.unsubscribeFunctions.push(() =>
218
+ eventHelper.tenant.unsubscribe.deletionError(deletionErrorCb)
219
+ );
220
+ const createRegistryCb = (payload: RegistryUpdatePayload) => {
221
+ createRegistry(payload.tenant, token, payload.registry);
222
+ }
223
+ eventHelper.tenant.subscribe.createRegistry(createRegistryCb);
224
+ this.unsubscribeFunctions.push(() =>
225
+ eventHelper.tenant.unsubscribe.createRegistry(createRegistryCb)
226
+ );
227
+ const registryCreatedCb = (payload: RegistryUpdatePayload) => {
228
+ }
229
+ eventHelper.tenant.subscribe.registryCreated(registryCreatedCb);
230
+ this.unsubscribeFunctions.push(() =>
231
+ eventHelper.tenant.unsubscribe.registryCreated(registryCreatedCb)
232
+ );
233
+ const registryCreationErrorCb = (payload: RegistryUpdatePayload) => {
234
+ }
235
+ eventHelper.tenant.subscribe.registryCreationError(registryCreationErrorCb);
236
+ this.unsubscribeFunctions.push(() =>
237
+ eventHelper.tenant.unsubscribe.registryCreationError(registryCreationErrorCb)
238
+ );
239
+ const updateRegistryCb = (payload: RegistryUpdatePayload) => {
240
+ updateRegistry(payload.tenant, payload.registry, token);
241
+ }
242
+ eventHelper.tenant.subscribe.updateRegistry(updateRegistryCb);
243
+ this.unsubscribeFunctions.push(() =>
244
+ eventHelper.tenant.unsubscribe.updateRegistry(updateRegistryCb)
245
+ );
246
+ const registryUpdatedCb = (payload: RegistryUpdatePayload) => {
247
+ }
248
+ eventHelper.tenant.subscribe.registryUpdated(registryUpdatedCb);
249
+ this.unsubscribeFunctions.push(() =>
250
+ eventHelper.tenant.unsubscribe.registryUpdated(registryUpdatedCb)
251
+ );
252
+ const registryUpdateErrorCb = (payload: RegistryUpdatePayload) => {
253
+ }
254
+ eventHelper.tenant.subscribe.registryUpdateError(registryUpdateErrorCb);
255
+ this.unsubscribeFunctions.push(() =>
256
+ eventHelper.tenant.unsubscribe.registryUpdateError(registryUpdateErrorCb)
257
+ );
258
+ const deleteRegistryCb = (payload: RegistryUpdatePayload) => {
259
+ deleteRegistry(payload.tenant, payload.registry, token);
260
+ }
261
+ eventHelper.tenant.subscribe.deleteRegistry(deleteRegistryCb);
262
+ this.unsubscribeFunctions.push(() =>
263
+ eventHelper.tenant.unsubscribe.deleteRegistry(deleteRegistryCb)
264
+ );
265
+ const registryDeletedCb = (payload: RegistryUpdatePayload) => {
266
+ }
267
+ eventHelper.tenant.subscribe.registryDeleted(registryDeletedCb);
268
+ this.unsubscribeFunctions.push(() =>
269
+ eventHelper.tenant.unsubscribe.registryDeleted(registryDeletedCb)
270
+ );
271
+ const registryDeletionErrorCb = (payload: RegistryUpdatePayload) => {
272
+ }
273
+ eventHelper.tenant.subscribe.registryDeletionError(registryDeletionErrorCb);
274
+ this.unsubscribeFunctions.push(() =>
275
+ eventHelper.tenant.unsubscribe.registryDeletionError(registryDeletionErrorCb)
276
+ );
277
+ const inviteUserCb = (payload: { user: string; tenant: string; role: tenantRole }) => {
278
+ inviteUser(payload.tenant, payload.user, payload.role, token);
279
+ };
280
+ eventHelper.tenant.subscribe.inviteUser(inviteUserCb);
281
+ this.unsubscribeFunctions.push(() =>
282
+ eventHelper.tenant.unsubscribe.inviteUser(inviteUserCb)
283
+ );
284
+ const userInvitedCb = (payload: { user: string; tenant: string; role: tenantRole }) => {
285
+ updateUserRole(payload.user, payload.tenant, payload.role, token);
286
+ };
287
+ eventHelper.tenant.subscribe.userInvited(userInvitedCb);
288
+ this.unsubscribeFunctions.push(() =>
289
+ eventHelper.tenant.unsubscribe.userInvited(userInvitedCb)
290
+ );
291
+ const userInviteErrorCb = (payload: { user: string; tenant: string; role: tenantRole }) => {
292
+ };
293
+ eventHelper.tenant.subscribe.inviteError(userInviteErrorCb);
294
+ this.unsubscribeFunctions.push(() =>
295
+ eventHelper.tenant.unsubscribe.inviteError(userInviteErrorCb)
296
+ );
297
+ const removeUserFromTenantCb = (payload: { user: string; tenant: string }) => {
298
+ removeUser(payload.tenant,payload.user, token)
299
+ }
300
+ eventHelper.tenant.subscribe.removeUser(removeUserFromTenantCb);
301
+ this.unsubscribeFunctions.push(() =>
302
+ eventHelper.tenant.unsubscribe.removeUser(removeUserFromTenantCb)
303
+ );
304
+ const userRemovedFromTenantCb = (payload: { user: string; tenant: string }) => {
305
+ }
306
+ eventHelper.tenant.subscribe.userRemoved(userRemovedFromTenantCb);
307
+ this.unsubscribeFunctions.push(() =>
308
+ eventHelper.tenant.unsubscribe.userRemoved(userRemovedFromTenantCb)
309
+ );
310
+ const userRemoveErrorCb = (payload: { user: string; tenant: string }) => {
311
+ }
312
+ eventHelper.tenant.subscribe.removeUserError(userRemoveErrorCb);
313
+ this.unsubscribeFunctions.push(() =>
314
+ eventHelper.tenant.unsubscribe.removeUserError(userRemoveErrorCb)
315
+ );
316
+ const updateInviteCb = (payload: { user: string; role: tenantRole; tenant: string }) => {
317
+ updateUserRole(payload.tenant, payload.user, payload.role, token)
318
+ }
319
+ eventHelper.tenant.subscribe.updateInvite(updateInviteCb);
320
+ this.unsubscribeFunctions.push(() =>
321
+ eventHelper.tenant.unsubscribe.updateInvite(updateInviteCb)
322
+ );
323
+ const inviteUpdatedCb = (payload: { user: string; role: string; tenant: string }) => {
324
+ }
325
+ eventHelper.tenant.subscribe.inviteUpdated(inviteUpdatedCb);
326
+ this.unsubscribeFunctions.push(() =>
327
+ eventHelper.tenant.unsubscribe.inviteUpdated(inviteUpdatedCb)
328
+ );
329
+ const inviteUpdateErrorCb = (payload: { user: string; role: string; tenant: string }) => {
330
+ }
331
+ eventHelper.tenant.subscribe.inviteUpdateError(inviteUpdateErrorCb);
332
+ this.unsubscribeFunctions.push(() =>
333
+ eventHelper.tenant.unsubscribe.inviteUpdateError(inviteUpdateErrorCb)
334
+ );
335
+ const acceptInviteCb = (payload: { tenant: string }) => {
336
+ acceptInvite(payload.tenant, token);
337
+ }
338
+ eventHelper.tenant.subscribe.acceptInvite(acceptInviteCb);
339
+ this.unsubscribeFunctions.push(() =>
340
+ eventHelper.tenant.unsubscribe.acceptInvite(acceptInviteCb)
341
+ );
342
+ const inviteAcceptedCb = (payload: { tenant: string}) => {
343
+ }
344
+ eventHelper.tenant.subscribe.inviteAccepted(inviteAcceptedCb);
345
+ this.unsubscribeFunctions.push(() =>
346
+ eventHelper.tenant.unsubscribe.inviteAccepted(inviteAcceptedCb)
347
+ );
348
+ const inviteAcceptErrorCb = (payload: { tenant: string }) => {
349
+ }
350
+ eventHelper.tenant.subscribe.acceptInviteError(inviteAcceptErrorCb);
351
+ this.unsubscribeFunctions.push(() =>
352
+ eventHelper.tenant.unsubscribe.acceptInviteError(inviteAcceptErrorCb)
353
+ );
354
+ const rejectInviteCb = (payload: { tenant: string }) => {
355
+ rejectInvite(payload.tenant, token);
356
+ }
357
+ eventHelper.tenant.subscribe.rejectInvite(rejectInviteCb);
358
+ this.unsubscribeFunctions.push(() =>
359
+ eventHelper.tenant.unsubscribe.rejectInvite(rejectInviteCb)
360
+ );
361
+ const inviteRejectedCb = (payload: { user: string; tenant: string }) => {
362
+ }
363
+ eventHelper.tenant.subscribe.inviteRejected(inviteRejectedCb);
364
+ this.unsubscribeFunctions.push(() =>
365
+ eventHelper.tenant.unsubscribe.inviteRejected(inviteRejectedCb)
366
+ );
367
+ const inviteRejectErrorCb = (payload: { tenant: string }) => {
368
+ }
369
+ eventHelper.tenant.subscribe.inviteRejectError(inviteRejectErrorCb);
370
+ this.unsubscribeFunctions.push(() =>
371
+ eventHelper.tenant.unsubscribe.inviteRejectError(inviteRejectErrorCb)
372
+ );
373
+ const getPlanProvidersCb = () => {
374
+ getPlanProviders(token);
375
+ }
376
+ eventHelper.planProviders.subscribe.loadPlans(getPlanProvidersCb);
377
+ this.unsubscribeFunctions.push(() =>
378
+ eventHelper.planProviders.unsubscribe.loadPlans(getPlanProvidersCb)
379
+ );
380
+ const crateTokenCb = (payload: { tenant: string; expiration: string; description: string }) => {
381
+ createToken(payload.tenant, payload.description, payload.expiration, token);
382
+
383
+ }
384
+ eventHelper.tenant.subscribe.createToken(crateTokenCb);
385
+ this.unsubscribeFunctions.push(() =>
386
+ eventHelper.tenant.unsubscribe.createToken(crateTokenCb)
387
+ );
388
+ const deleteTokenCb = (payload: { tenant: string; token: string }) => {
389
+ deleteToken(payload.tenant, payload.token, token);
390
+ }
391
+ eventHelper.tenant.subscribe.deleteToken(deleteTokenCb);
392
+ this.unsubscribeFunctions.push(() =>
393
+ eventHelper.tenant.unsubscribe.deleteToken(deleteTokenCb)
394
+ );
395
+ }
396
+ /**
397
+ * Function to subscribe to the user events
398
+ */
399
+ private subscribeUserEvents(): void {
400
+ const creationCb = (data: UserData) => {
401
+ createUser(data);
402
+ };
403
+ eventHelper.user.subscribe.creation(creationCb);
404
+ this.unsubscribeFunctions.push(() =>
405
+ eventHelper.user.unsubscribe.creation(creationCb)
406
+ );
407
+
408
+ const createdCb = (data: UserData) => {
409
+ };
410
+ eventHelper.user.subscribe.created(createdCb);
411
+ this.unsubscribeFunctions.push(() =>
412
+ eventHelper.user.unsubscribe.created(createdCb)
413
+ );
414
+
415
+ const creationErrorCb = (data: UserData) => {
416
+ };
417
+ eventHelper.user.subscribe.creationError(creationErrorCb);
418
+ this.unsubscribeFunctions.push(() =>
419
+ eventHelper.user.unsubscribe.creationError(creationErrorCb)
420
+ );
421
+
422
+ const updateCb = (data: UserData) => {
423
+ updateUser(data);
424
+ };
425
+ eventHelper.user.subscribe.update(updateCb);
426
+ this.unsubscribeFunctions.push(() =>
427
+ eventHelper.user.unsubscribe.update(updateCb)
428
+ );
429
+
430
+ const updatedCb = (data: UserData) => {
431
+ };
432
+ eventHelper.user.subscribe.updated(updatedCb);
433
+ this.unsubscribeFunctions.push(() =>
434
+ eventHelper.user.unsubscribe.updated(updatedCb)
435
+ );
436
+
437
+ const updateErrorCb = (data: UserData) => {
438
+ };
439
+ eventHelper.user.subscribe.updateError(updateErrorCb);
440
+ this.unsubscribeFunctions.push(() =>
441
+ eventHelper.user.unsubscribe.updateError(updateErrorCb)
442
+ );
443
+
444
+ const loadCb = (data: UserData) => {
445
+ loadUser(token, data);
446
+ };
447
+ eventHelper.user.subscribe.load(loadCb);
448
+ this.unsubscribeFunctions.push(() =>
449
+ eventHelper.user.unsubscribe.load(loadCb)
450
+ );
451
+
452
+ // const loadedCb = (data: UserData) => {
453
+ // //updateUserData(data);
454
+ // };
455
+ // eventHelper.user.subscribe.loaded(loadedCb);
456
+ // this.unsubscribeFunctions.push(() =>
457
+ // eventHelper.user.unsubscribe.loaded(loadedCb)
458
+ // );
459
+
460
+ const loadErrorCb = (data: UserData) => {
461
+ };
462
+ eventHelper.user.subscribe.loadError(loadErrorCb);
463
+ this.unsubscribeFunctions.push(() =>
464
+ eventHelper.user.unsubscribe.loadError(loadErrorCb)
465
+ );
466
+
467
+ const deleteCb = (data: UserData) => {
468
+ deleteUSer(data, token);
469
+ };
470
+ eventHelper.user.subscribe.delete(deleteCb);
471
+ this.unsubscribeFunctions.push(() =>
472
+ eventHelper.user.unsubscribe.delete(deleteCb)
473
+ );
474
+
475
+ const deletedCb = (data: UserData) => {
476
+ };
477
+ eventHelper.user.subscribe.deleted(deletedCb);
478
+ this.unsubscribeFunctions.push(() =>
479
+ eventHelper.user.unsubscribe.deleted(deletedCb)
480
+ );
481
+
482
+ const deletionErrorCb = (data: UserData) => {
483
+ };
484
+ eventHelper.user.subscribe.deletionError(deletionErrorCb);
485
+ this.unsubscribeFunctions.push(() =>
486
+ eventHelper.user.unsubscribe.deletionError(deletionErrorCb)
487
+ );
488
+ }
489
+ /**
490
+ * Function to subscribe to the account events
491
+ */
492
+ private subscribeAccountEvents(): void {
493
+ const creationCb = (data: Account) => {
494
+ createAccount(data, token);
495
+ };
496
+ eventHelper.account.subscribe.creation(creationCb);
497
+ this.unsubscribeFunctions.push(() =>
498
+ eventHelper.account.unsubscribe.creation(creationCb)
499
+ );
500
+
501
+ const createdCb = (data: Account) => {
502
+ };
503
+ eventHelper.account.subscribe.created(createdCb);
504
+ this.unsubscribeFunctions.push(() =>
505
+ eventHelper.account.unsubscribe.created(createdCb)
506
+ );
507
+
508
+ const creationErrorCb = (data: Account) => {
509
+ };
510
+ eventHelper.account.subscribe.creationError(creationErrorCb);
511
+ this.unsubscribeFunctions.push(() =>
512
+ eventHelper.account.unsubscribe.creationError(creationErrorCb)
513
+ );
514
+
515
+ const updateCb = (data: Account) => {
516
+ updateAccount(data, token);
517
+ };
518
+ eventHelper.account.subscribe.update(updateCb);
519
+ this.unsubscribeFunctions.push(() =>
520
+ eventHelper.account.unsubscribe.update(updateCb)
521
+ );
522
+
523
+ const updatedCb = (data: Account) => {
524
+ };
525
+ eventHelper.account.subscribe.updated(updatedCb);
526
+ this.unsubscribeFunctions.push(() =>
527
+ eventHelper.account.unsubscribe.updated(updatedCb)
528
+ );
529
+
530
+ const updateErrorCb = (data: Account) => {
531
+ };
532
+ eventHelper.account.subscribe.updateError(updateErrorCb);
533
+ this.unsubscribeFunctions.push(() =>
534
+ eventHelper.account.unsubscribe.updateError(updateErrorCb)
535
+ );
536
+
537
+ const deleteCb = (data: Account) => {
538
+ deleteAccount(data, token);
539
+ };
540
+ eventHelper.account.subscribe.delete(deleteCb);
541
+ this.unsubscribeFunctions.push(() =>
542
+ eventHelper.account.unsubscribe.delete(deleteCb)
543
+ );
544
+
545
+ const deletedCb = (data: Account) => {
546
+ };
547
+ eventHelper.account.subscribe.deleted(deletedCb);
548
+ this.unsubscribeFunctions.push(() =>
549
+ eventHelper.account.unsubscribe.deleted(deletedCb)
550
+ );
551
+
552
+ const deletionErrorCb = (data: Account) => {
553
+ };
554
+ eventHelper.account.subscribe.deletionError(deletionErrorCb);
555
+ this.unsubscribeFunctions.push(() =>
556
+ eventHelper.account.unsubscribe.deletionError(deletionErrorCb)
557
+ );
558
+ const cleanCb = (data: Account) => {
559
+ clearAccount(data, token);
560
+ };
561
+ eventHelper.account.subscribe.clean(cleanCb);
562
+ this.unsubscribeFunctions.push(() =>
563
+ eventHelper.account.unsubscribe.clean(cleanCb)
564
+ );
565
+ }
566
+ /**
567
+ * Function to subscribe to the plan events
568
+ */
569
+ private subscribePlanEvents(): void {
570
+ const updateCb = (data: string) => {
571
+ };
572
+ eventHelper.plan.subscribe.upgrade(updateCb);
573
+ this.unsubscribeFunctions.push(() =>
574
+ eventHelper.plan.unsubscribe.upgrade(updateCb)
575
+ );
576
+
577
+ const updatedCb = (data: string) => {
578
+ const upgradeNotification: Notification = {
579
+ type: "success",
580
+ subtype: "plan-upgrade",
581
+ date: Date.now().toString(),
582
+ status: "unread",
583
+ callToAction: false,
584
+ data: {
585
+ plan: data
586
+ }
587
+ };
588
+ eventHelper.notification.publish.creation(upgradeNotification);
589
+ };
590
+ eventHelper.plan.subscribe.upgraded(updatedCb);
591
+ this.unsubscribeFunctions.push(() =>
592
+ eventHelper.plan.unsubscribe.upgraded(updatedCb)
593
+ );
594
+
595
+ const updateErrorCb = (data: string) => {
596
+ };
597
+ eventHelper.plan.subscribe.upgradeError(updateErrorCb);
598
+ this.unsubscribeFunctions.push(() =>
599
+ eventHelper.plan.unsubscribe.upgradeError(updateErrorCb)
600
+ );
601
+
602
+ const downgradeCb = (data: string) => {
603
+ };
604
+ eventHelper.plan.subscribe.downgrade(downgradeCb);
605
+ this.unsubscribeFunctions.push(() =>
606
+ eventHelper.plan.unsubscribe.downgrade(downgradeCb)
607
+ );
608
+
609
+ const downgradedCb = (data: string) => {
610
+ const downgradeNotification: Notification = {
611
+ type: "success",
612
+ subtype: "plan-downgrade",
613
+ date: Date.now().toString(),
614
+ status: "unread",
615
+ callToAction: false,
616
+ data: {
617
+ plan: data
618
+ }
619
+ };
620
+ eventHelper.notification.publish.creation(downgradeNotification);
621
+ };
622
+ eventHelper.plan.subscribe.downgraded(downgradedCb);
623
+ this.unsubscribeFunctions.push(() =>
624
+ eventHelper.plan.unsubscribe.downgraded(downgradedCb)
625
+ );
626
+
627
+ const downgradeErrorCb = (data: string) => {
628
+ };
629
+ eventHelper.plan.subscribe.downgradeError(downgradeErrorCb);
630
+ this.unsubscribeFunctions.push(() =>
631
+ eventHelper.plan.unsubscribe.downgradeError(downgradeErrorCb)
632
+ );
633
+ }
634
+ /**
635
+ * Function to subscribe to the environment events
636
+ */
637
+ private subscribeEnvironmentEvents(): void {
638
+ const creationCb = (data: Environment) => {
639
+ createEnvironment(data, token);
640
+ };
641
+ eventHelper.environment.subscribe.creation(creationCb);
642
+ this.unsubscribeFunctions.push(() =>
643
+ eventHelper.environment.unsubscribe.creation(creationCb)
644
+ );
645
+
646
+ const createdCb = (data: Environment) => {
647
+ const envNotification: Notification = {
648
+ type: "success",
649
+ subtype: "environment-created",
650
+ date: Date.now().toString(),
651
+ status: "unread",
652
+ callToAction: false,
653
+ data : {
654
+ environment: data.name,
655
+ account: data.account,
656
+ tenant: data.tenant
657
+ }
658
+ };
659
+ eventHelper.notification.publish.creation(envNotification);
660
+ };
661
+ eventHelper.environment.subscribe.created(createdCb);
662
+ this.unsubscribeFunctions.push(() =>
663
+ eventHelper.environment.unsubscribe.created(createdCb)
664
+ );
665
+
666
+ const creationErrorCb = (data: Environment) => {
667
+ };
668
+ eventHelper.environment.subscribe.creationError(creationErrorCb);
669
+ this.unsubscribeFunctions.push(() =>
670
+ eventHelper.environment.unsubscribe.creationError(creationErrorCb)
671
+ );
672
+
673
+ const updateCb = (data: Environment) => {
674
+ updateEnvironment(data, token);
675
+ };
676
+ eventHelper.environment.subscribe.update(updateCb);
677
+ this.unsubscribeFunctions.push(() =>
678
+ eventHelper.environment.unsubscribe.update(updateCb)
679
+ );
680
+
681
+ const updatedCb = (data: Environment) => {
682
+ };
683
+ eventHelper.environment.subscribe.updated(updatedCb);
684
+ this.unsubscribeFunctions.push(() =>
685
+ eventHelper.environment.unsubscribe.updated(updatedCb)
686
+ );
687
+
688
+ const updateErrorCb = (data: Environment) => {
689
+ };
690
+ eventHelper.environment.subscribe.updateError(updateErrorCb);
691
+ this.unsubscribeFunctions.push(() =>
692
+ eventHelper.environment.unsubscribe.updateError(updateErrorCb)
693
+ );
694
+
695
+ const deleteCb = (data: Environment) => {
696
+ deleteEnvironment(data, token);
697
+ };
698
+ eventHelper.environment.subscribe.delete(deleteCb);
699
+ this.unsubscribeFunctions.push(() =>
700
+ eventHelper.environment.unsubscribe.delete(deleteCb)
701
+ );
702
+
703
+ const deletedCb = (data: Environment) => {
704
+ };
705
+ eventHelper.environment.subscribe.deleted(deletedCb);
706
+ this.unsubscribeFunctions.push(() =>
707
+ eventHelper.environment.unsubscribe.deleted(deletedCb)
708
+ );
709
+
710
+ const deletionErrorCb = (data: Environment) => {
711
+ };
712
+ eventHelper.environment.subscribe.deletionError(deletionErrorCb);
713
+ this.unsubscribeFunctions.push(() =>
714
+ eventHelper.environment.unsubscribe.deletionError(deletionErrorCb)
715
+ );
716
+ const cleanCb = (data: Environment) => {
717
+ clearEnvironment(data, token);
718
+ };
719
+ eventHelper.environment.subscribe.clean(cleanCb);
720
+ this.unsubscribeFunctions.push(() =>
721
+ eventHelper.environment.unsubscribe.clean(cleanCb)
722
+ );
723
+ const scaleCb = (data: Environment) => {
724
+ console.log('Scale called', data)
725
+ scaleEnvironment(data, token);
726
+ }
727
+ eventHelper.environment.subscribe.scale(scaleCb);
728
+ this.unsubscribeFunctions.push(() =>
729
+ eventHelper.environment.unsubscribe.scale(scaleCb)
730
+ )
731
+ }
732
+ /**
733
+ * Function to subscribe to the service events
734
+ */
735
+ private subscribeServiceEvents(): void {
736
+ const deployedCb = (data: Service) => {
737
+ const deploymentSuccessNotification: Notification = {
738
+ type: "success",
739
+ subtype: "deployment-success",
740
+ date: Date.now().toString(),
741
+ status: "unread",
742
+ callToAction: false,
743
+ data: {
744
+ service: data.name,
745
+ tenant: data.tenant
746
+ }
747
+ };
748
+ eventHelper.notification.publish.creation(deploymentSuccessNotification);
749
+ };
750
+ eventHelper.service.subscribe.deployed(deployedCb);
751
+ const deploymentErrorCb = (data: Service) => {
752
+ const deploymentErrorNotification: Notification = {
753
+ type: "error",
754
+ subtype: "deployment-error",
755
+ date: Date.now().toString(),
756
+ status: "unread",
757
+ info_content: {
758
+ code: data.error?.code || '',
759
+ message: data.error?.message || '',
760
+ timestamp: data.error?.timestamp || '',
761
+ },
762
+ callToAction: false,
763
+ data: {
764
+ service: data.name,
765
+ tenant: data.tenant
766
+ }
767
+ };
768
+ eventHelper.notification.publish.creation(deploymentErrorNotification);
769
+ };
770
+ eventHelper.service.subscribe.deploymentError(deploymentErrorCb);
771
+ const deployCb = async (data: Service) => {
772
+ deployService(data, token);
773
+ const deploymentSuccessNotification: Notification = {
774
+ type: "info",
775
+ subtype: "deployment-in-progress",
776
+ date: Date.now().toString(),
777
+ status: "unread",
778
+ callToAction: false,
779
+ data: {
780
+ service: data.name,
781
+ tenant: data.tenant
782
+ }
783
+ };
784
+ data.download ? '' : eventHelper.notification.publish.creation(deploymentSuccessNotification);
785
+ };
786
+ eventHelper.service.subscribe.deploy(deployCb);
787
+ this.unsubscribeFunctions.push(() =>
788
+ eventHelper.service.unsubscribe.deploy(deployCb)
789
+ );
790
+
791
+
792
+ const updateCb = (data: Service) => {
793
+ updateService(data, token);
794
+ };
795
+ eventHelper.service.subscribe.update(updateCb);
796
+ this.unsubscribeFunctions.push(() =>
797
+ eventHelper.service.unsubscribe.update(updateCb)
798
+ );
799
+
800
+ const updatedCb = (data: Service) => {
801
+ const deploymentNotification: Notification = {
802
+ type: "success",
803
+ subtype: "deployment-updated",
804
+ date: Date.now().toString(),
805
+ status: "unread",
806
+ callToAction: false,
807
+ data: {
808
+ service: data.name,
809
+ tenant: data.tenant
810
+ }
811
+ };
812
+ eventHelper.notification.publish.creation(deploymentNotification);
813
+ };
814
+ eventHelper.service.subscribe.updated(updatedCb);
815
+ this.unsubscribeFunctions.push(() =>
816
+ eventHelper.service.unsubscribe.updated(updatedCb)
817
+ );
818
+
819
+ const updateErrorCb = (data: Service) => {
820
+ };
821
+ eventHelper.service.subscribe.updateError(updateErrorCb);
822
+ this.unsubscribeFunctions.push(() =>
823
+ eventHelper.service.unsubscribe.updateError(updateErrorCb)
824
+ );
825
+
826
+ const deleteCb = (data: Service) => {
827
+ const deploymentNotification: Notification = {
828
+ type: "info",
829
+ subtype: "deployment-deleting",
830
+ date: Date.now().toString(),
831
+ status: "unread",
832
+ callToAction: false,
833
+ data: {
834
+ service: data.name,
835
+ tenant: data.tenant
836
+ }
837
+ };
838
+ eventHelper.notification.publish.creation(deploymentNotification);
839
+ deleteService(data, token);
840
+ };
841
+ eventHelper.service.subscribe.delete(deleteCb);
842
+ this.unsubscribeFunctions.push(() =>
843
+ eventHelper.service.unsubscribe.delete(deleteCb)
844
+ );
845
+
846
+ const deletedCb = (data: Service) => {
847
+ const deploymentNotification: Notification = {
848
+ type: "success",
849
+ subtype: "deployment-deleted",
850
+ date: Date.now().toString(),
851
+ status: "unread",
852
+ callToAction: false,
853
+ data: {
854
+ service: data.name,
855
+ tenant: data.tenant
856
+ }
857
+ };
858
+ eventHelper.notification.publish.creation(deploymentNotification);
859
+ };
860
+ eventHelper.service.subscribe.deleted(deletedCb);
861
+ this.unsubscribeFunctions.push(() =>
862
+ eventHelper.service.unsubscribe.deleted(deletedCb)
863
+ );
864
+
865
+ const deletionErrorCb = (data: Service) => {
866
+ };
867
+ eventHelper.service.subscribe.deletionError(deletionErrorCb);
868
+ this.unsubscribeFunctions.push(() =>
869
+ eventHelper.service.unsubscribe.deletionError(deletionErrorCb)
870
+ );
871
+
872
+ const requestLogsCb = (data: Service) => {
873
+ };
874
+ eventHelper.service.subscribe.requestLogs(requestLogsCb);
875
+ this.unsubscribeFunctions.push(() =>
876
+ eventHelper.service.unsubscribe.requestLogs(requestLogsCb)
877
+ );
878
+ const restartCb = (data: Service) => {
879
+ restartService(data, token);
880
+ };
881
+ eventHelper.service.subscribe.restart(restartCb);
882
+ this.unsubscribeFunctions.push(() =>
883
+ eventHelper.service.unsubscribe.restart(restartCb)
884
+ );
885
+ const requestRevisionCb = (data: Service) => {
886
+ requestRevisionData(data, token);
887
+ }
888
+ eventHelper.service.subscribe.requestRevisionData(requestRevisionCb);
889
+ this.unsubscribeFunctions.push(() =>
890
+ eventHelper.service.unsubscribe.requestRevisionData(requestRevisionCb)
891
+ );
892
+ const updateServiceLinksCb = (data: Link) => {
893
+ updateServiceLinks(data, token);
894
+ }
895
+ eventHelper.service.subscribe.updateServiceLinks(updateServiceLinksCb);
896
+ this.unsubscribeFunctions.push(() =>
897
+ eventHelper.service.unsubscribe.updateServiceLinks(updateServiceLinksCb)
898
+ );
899
+ const changeRevisionCb = (data: Service) => {
900
+ changeRevision(data, token);
901
+ }
902
+ eventHelper.service.subscribe.changeRevision(changeRevisionCb);
903
+ this.unsubscribeFunctions.push(() => {
904
+ eventHelper.service.unsubscribe.changeRevision(changeRevisionCb);
905
+ })
906
+ }
907
+ /**
908
+ * Function to subscribe to the marketplace events
909
+ */
910
+ private subscribeMarketplaceEvents(): void {
911
+ const deployItemCb = (data: MarketplaceService) => {
912
+ deployMarketplaceItem(data);
913
+ };
914
+ eventHelper.marketplace.subscribe.deployItem(deployItemCb);
915
+ this.unsubscribeFunctions.push(() =>
916
+ eventHelper.marketplace.unsubscribe.deployItem(deployItemCb)
917
+ );
918
+
919
+ const itemDeployedCb = (data: Service) => {
920
+ };
921
+ eventHelper.marketplace.subscribe.itemDeployed(itemDeployedCb);
922
+ this.unsubscribeFunctions.push(() =>
923
+ eventHelper.marketplace.unsubscribe.itemDeployed(itemDeployedCb)
924
+ );
925
+
926
+ const deploymentErrorCb = (data: Service) => {
927
+ };
928
+ eventHelper.marketplace.subscribe.deploymentError(deploymentErrorCb);
929
+ this.unsubscribeFunctions.push(() =>
930
+ eventHelper.marketplace.unsubscribe.deploymentError(deploymentErrorCb)
931
+ );
932
+
933
+ const updateItemCb = (data: Service) => {
934
+ };
935
+ eventHelper.marketplace.subscribe.updateItem(updateItemCb);
936
+ this.unsubscribeFunctions.push(() =>
937
+ eventHelper.marketplace.unsubscribe.updateItem(updateItemCb)
938
+ );
939
+
940
+ const itemUpdatedCb = (data: Service) => {
941
+ };
942
+ eventHelper.marketplace.subscribe.itemUpdated(itemUpdatedCb);
943
+ this.unsubscribeFunctions.push(() =>
944
+ eventHelper.marketplace.unsubscribe.itemUpdated(itemUpdatedCb)
945
+ );
946
+
947
+ const updateErrorCb = (data: Service) => {
948
+ };
949
+ eventHelper.marketplace.subscribe.updateError(updateErrorCb);
950
+ this.unsubscribeFunctions.push(() =>
951
+ eventHelper.marketplace.unsubscribe.updateError(updateErrorCb)
952
+ );
953
+
954
+ const deleteItemCb = (data: Service) => {
955
+ };
956
+ eventHelper.marketplace.subscribe.deleteItem(deleteItemCb);
957
+ this.unsubscribeFunctions.push(() =>
958
+ eventHelper.marketplace.unsubscribe.deleteItem(deleteItemCb)
959
+ );
960
+
961
+ const itemDeletedCb = (data: Service) => {
962
+ };
963
+ eventHelper.marketplace.subscribe.itemDeleted(itemDeletedCb);
964
+ this.unsubscribeFunctions.push(() =>
965
+ eventHelper.marketplace.unsubscribe.itemDeleted(itemDeletedCb)
966
+ );
967
+
968
+ const deletionErrorCb = (data: Service) => {
969
+ };
970
+ eventHelper.marketplace.subscribe.deletionError(deletionErrorCb);
971
+ this.unsubscribeFunctions.push(() =>
972
+ eventHelper.marketplace.unsubscribe.deletionError(deletionErrorCb)
973
+ );
974
+
975
+ const loadItemsCb = (data: string[]) => {
976
+ // getMarketplaceItems(data, token)
977
+ // .then((result) => {
978
+
979
+ // eventHelper.marketplace.publish.itemsLoaded(result.items);
980
+ // })
981
+ // .catch((err) => {
982
+ // console.error("Error al cargar marketplace items:", err);
983
+ // });
984
+ };
985
+ eventHelper.marketplace.subscribe.loadItems(loadItemsCb);
986
+ this.unsubscribeFunctions.push(() =>
987
+ eventHelper.marketplace.unsubscribe.loadItems(loadItemsCb)
988
+ );
989
+ }
990
+ /**
991
+ * Function to subscribe to the resource events
992
+ */
993
+ private subscribeResourceEvents(): void {
994
+ const creationCb = (data: Resource) => {
995
+ createResource(data.tenant ?? "", data, token);
996
+ };
997
+ eventHelper.resource.subscribe.creation(creationCb);
998
+ this.unsubscribeFunctions.push(() =>
999
+ eventHelper.resource.unsubscribe.creation(creationCb)
1000
+ );
1001
+
1002
+ const createdCb = (data: Resource) => {
1003
+ };
1004
+ eventHelper.resource.subscribe.created(createdCb);
1005
+ this.unsubscribeFunctions.push(() =>
1006
+ eventHelper.resource.unsubscribe.created(createdCb)
1007
+ );
1008
+
1009
+ const creationErrorCb = (data: Resource) => {
1010
+ };
1011
+ eventHelper.resource.subscribe.creationError(creationErrorCb);
1012
+ this.unsubscribeFunctions.push(() =>
1013
+ eventHelper.resource.unsubscribe.creationError(creationErrorCb)
1014
+ );
1015
+
1016
+ const updateCb = (data: Resource) => {
1017
+ updateResource(data.tenant ?? "", data, token);
1018
+ };
1019
+ eventHelper.resource.subscribe.update(updateCb);
1020
+ this.unsubscribeFunctions.push(() =>
1021
+ eventHelper.resource.unsubscribe.update(updateCb)
1022
+ );
1023
+
1024
+ const updatedCb = (data: Resource) => {
1025
+ };
1026
+ eventHelper.resource.subscribe.updated(updatedCb);
1027
+ this.unsubscribeFunctions.push(() =>
1028
+ eventHelper.resource.unsubscribe.updated(updatedCb)
1029
+ );
1030
+
1031
+ const updateErrorCb = (data: Resource) => {
1032
+ };
1033
+ eventHelper.resource.subscribe.updateError(updateErrorCb);
1034
+ this.unsubscribeFunctions.push(() =>
1035
+ eventHelper.resource.unsubscribe.updateError(updateErrorCb)
1036
+ );
1037
+
1038
+ const deleteCb = (data: Resource) => {
1039
+ deleteResource(data.tenant ?? "", data, token);
1040
+ };
1041
+ eventHelper.resource.subscribe.delete(deleteCb);
1042
+ this.unsubscribeFunctions.push(() =>
1043
+ eventHelper.resource.unsubscribe.delete(deleteCb)
1044
+ );
1045
+
1046
+ const deletedCb = (data: Resource) => {
1047
+ };
1048
+ eventHelper.resource.subscribe.deleted(deletedCb);
1049
+ this.unsubscribeFunctions.push(() =>
1050
+ eventHelper.resource.unsubscribe.deleted(deletedCb)
1051
+ );
1052
+
1053
+ const deletionErrorCb = (data: Resource) => {
1054
+ };
1055
+ eventHelper.resource.subscribe.deletionError(deletionErrorCb);
1056
+ this.unsubscribeFunctions.push(() =>
1057
+ eventHelper.resource.unsubscribe.deletionError(deletionErrorCb)
1058
+ );
1059
+ }
1060
+ /**
1061
+ * Function to subscribe to the organization events
1062
+ */
1063
+ private subscribeOrganizationEvents(): void {
1064
+ const creationCb = (data: Organization) => {
1065
+ };
1066
+ eventHelper.organization.subscribe.creation(creationCb);
1067
+ this.unsubscribeFunctions.push(() =>
1068
+ eventHelper.organization.unsubscribe.creation(creationCb)
1069
+ );
1070
+
1071
+ const createdCb = (data: Organization) => {
1072
+ };
1073
+ eventHelper.organization.subscribe.created(createdCb);
1074
+ this.unsubscribeFunctions.push(() =>
1075
+ eventHelper.organization.unsubscribe.created(createdCb)
1076
+ );
1077
+
1078
+ const creationErrorCb = (data: Organization) => {
1079
+ };
1080
+ eventHelper.organization.subscribe.creationError(creationErrorCb);
1081
+ this.unsubscribeFunctions.push(() =>
1082
+ eventHelper.organization.unsubscribe.creationError(creationErrorCb)
1083
+ );
1084
+
1085
+ const updateCb = (data: Organization) => {
1086
+ };
1087
+ eventHelper.organization.subscribe.update(updateCb);
1088
+ this.unsubscribeFunctions.push(() =>
1089
+ eventHelper.organization.unsubscribe.update(updateCb)
1090
+ );
1091
+
1092
+ const updatedCb = (data: Organization) => {
1093
+ };
1094
+ eventHelper.organization.subscribe.updated(updatedCb);
1095
+ this.unsubscribeFunctions.push(() =>
1096
+ eventHelper.organization.unsubscribe.updated(updatedCb)
1097
+ );
1098
+
1099
+ const updateErrorCb = (data: Organization) => {
1100
+ };
1101
+ eventHelper.organization.subscribe.updateError(updateErrorCb);
1102
+ this.unsubscribeFunctions.push(() =>
1103
+ eventHelper.organization.unsubscribe.updateError(updateErrorCb)
1104
+ );
1105
+
1106
+ const deleteCb = (data: Organization) => {
1107
+ };
1108
+ eventHelper.organization.subscribe.delete(deleteCb);
1109
+ this.unsubscribeFunctions.push(() =>
1110
+ eventHelper.organization.unsubscribe.delete(deleteCb)
1111
+ );
1112
+
1113
+ const deletedCb = (data: Organization) => {
1114
+ };
1115
+ eventHelper.organization.subscribe.deleted(deletedCb);
1116
+ this.unsubscribeFunctions.push(() =>
1117
+ eventHelper.organization.unsubscribe.deleted(deletedCb)
1118
+ );
1119
+
1120
+ const deletionErrorCb = (data: Organization) => {
1121
+ };
1122
+ eventHelper.organization.subscribe.deletionError(deletionErrorCb);
1123
+ this.unsubscribeFunctions.push(() =>
1124
+ eventHelper.organization.unsubscribe.deletionError(deletionErrorCb)
1125
+ );
1126
+ }
1127
+ }