@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.
- package/.gitlab-ci.yml +57 -0
- package/README.md +352 -0
- package/api/account-api-service.ts +1092 -0
- package/api/deploy-service-helper.ts +1611 -0
- package/api/environment-api-service.ts +542 -0
- package/api/marketplace-api-service.ts +1031 -0
- package/api/organizations-api-service.ts +0 -0
- package/api/planProvider-api-service.ts +24 -0
- package/api/reporting-api-service.ts +35 -0
- package/api/resources-api-service.ts +821 -0
- package/api/service-api-service.ts +796 -0
- package/api/tenant-api-service.ts +1260 -0
- package/api/user-api-service.ts +1161 -0
- package/backend-handler.ts +1127 -0
- package/environment.ts +7 -0
- package/event-helper.ts +577 -0
- package/event-names.ts +152 -0
- package/helpers/account-helper.ts +331 -0
- package/helpers/environment-helper.ts +289 -0
- package/helpers/link-helper.ts +114 -0
- package/helpers/plan-helper.ts +104 -0
- package/helpers/registry-helper.ts +134 -0
- package/helpers/resource-helper.ts +387 -0
- package/helpers/revision-helper.ts +899 -0
- package/helpers/service-helper.ts +627 -0
- package/helpers/tenant-helper.ts +191 -0
- package/helpers/token-helper.ts +107 -0
- package/helpers/user-helper.ts +140 -0
- package/jest.config.ts +40 -0
- package/jest.setup.js +4 -0
- package/package.json +50 -0
- package/test/backend-handler.test.ts +792 -0
- package/test/deploy-service-helper.test.ts +518 -0
- package/test/event-helper.test.ts +152 -0
- package/tsconfig.json +26 -0
- package/utils/utils.ts +78 -0
- package/websocket-manager.ts +1833 -0
package/utils/utils.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export function getTimestamp(val: string | number | undefined): number {
|
|
2
|
+
if (!val) return 0;
|
|
3
|
+
if (typeof val === "number") return val;
|
|
4
|
+
const parsed = Date.parse(val);
|
|
5
|
+
return isNaN(parsed) ? 0 : parsed;
|
|
6
|
+
}
|
|
7
|
+
export const parseKeyPath = (key: string): { [entity: string]: string } => {
|
|
8
|
+
if (!key) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
const cleanKey = key?.startsWith("/") ? key.slice(1) : key;
|
|
12
|
+
const parts = cleanKey.split("/");
|
|
13
|
+
const result: { [entity: string]: string } = {};
|
|
14
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
15
|
+
if (parts[i] && parts[i + 1]) {
|
|
16
|
+
const entityType = parts[i];
|
|
17
|
+
const entityName = parts[i + 1];
|
|
18
|
+
result[entityType] = entityName;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
export const decodeRegistryAuth = (
|
|
25
|
+
base64Secret: string,
|
|
26
|
+
): { username: string; password: string } => {
|
|
27
|
+
try {
|
|
28
|
+
const decoded = atob(base64Secret);
|
|
29
|
+
const parts = decoded.split(":");
|
|
30
|
+
return {
|
|
31
|
+
username: parts[0] || "",
|
|
32
|
+
password: parts[1] || "",
|
|
33
|
+
};
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("Error decoding registry credentials:", error);
|
|
36
|
+
return { username: "", password: "" };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Converts a storage value from any unit to Gigabytes (G)
|
|
41
|
+
* Supported units: k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi, Ei
|
|
42
|
+
* @param size The numeric size value
|
|
43
|
+
* @param unit The unit string (e.g., 'M', 'Gi', 'T')
|
|
44
|
+
* @returns The value converted to Gigabytes (decimal)
|
|
45
|
+
*/
|
|
46
|
+
export const convertToGigabytes = (size: number, unit?: string): number => {
|
|
47
|
+
if (!size) return 0;
|
|
48
|
+
if (!unit) return size;
|
|
49
|
+
const decimalUnits: Record<string, number> = {
|
|
50
|
+
k: 1e3,
|
|
51
|
+
M: 1e6,
|
|
52
|
+
G: 1e9,
|
|
53
|
+
T: 1e12,
|
|
54
|
+
P: 1e15,
|
|
55
|
+
E: 1e18,
|
|
56
|
+
};
|
|
57
|
+
const binaryUnits: Record<string, number> = {
|
|
58
|
+
Ki: Math.pow(1024, 1),
|
|
59
|
+
Mi: Math.pow(1024, 2),
|
|
60
|
+
Gi: Math.pow(1024, 3),
|
|
61
|
+
Ti: Math.pow(1024, 4),
|
|
62
|
+
Pi: Math.pow(1024, 5),
|
|
63
|
+
Ei: Math.pow(1024, 6),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const GIGABYTE = 1e9;
|
|
67
|
+
|
|
68
|
+
let bytes: number;
|
|
69
|
+
if (binaryUnits[unit]) {
|
|
70
|
+
bytes = size * binaryUnits[unit];
|
|
71
|
+
} else if (decimalUnits[unit]) {
|
|
72
|
+
bytes = size * decimalUnits[unit];
|
|
73
|
+
} else {
|
|
74
|
+
console.warn(`Unknown storage unit: ${unit}, assuming bytes`);
|
|
75
|
+
bytes = size;
|
|
76
|
+
}
|
|
77
|
+
return bytes / GIGABYTE;
|
|
78
|
+
};
|