@bluealba/pae-bootstrap-lib 3.1.2-develop-237 → 3.1.2-feature-resilient-bootstrap-no-cr-254
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.
|
@@ -22,6 +22,21 @@ export type BootstrapOptions = {
|
|
|
22
22
|
* Adding and overriding some modules according to some env vars.
|
|
23
23
|
*/
|
|
24
24
|
transformModules?: (modules: BootstrapModule[]) => BootstrapModule[];
|
|
25
|
+
/**
|
|
26
|
+
* If true, bootstrapPlatform() will throw on failure after all retries are exhausted.
|
|
27
|
+
* If false (default), errors are logged but not propagated to the caller.
|
|
28
|
+
*/
|
|
29
|
+
throwOnError?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum number of retry attempts after the initial failure. Default: 0 (no retries).
|
|
32
|
+
* Each retry uses exponential backoff capped at 5 minutes.
|
|
33
|
+
*/
|
|
34
|
+
retries?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Delay in ms before the first attempt. Also serves as the base for backoff calculation.
|
|
37
|
+
* Default: 0.
|
|
38
|
+
*/
|
|
39
|
+
initialDelay?: number;
|
|
25
40
|
};
|
|
26
41
|
/**
|
|
27
42
|
* Reads the current application src/data folder assembles all the platform definitions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-platform.d.ts","sourceRoot":"","sources":["../../../src/bootstrap/bootstrap-platform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAG7E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap-platform.d.ts","sourceRoot":"","sources":["../../../src/bootstrap/bootstrap-platform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAG7E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,CAAC;IAErE;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAA;AAMD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,IAAI,CAwF/E,CAAC"}
|
|
@@ -13,72 +13,86 @@ exports.bootstrapPlatform = void 0;
|
|
|
13
13
|
const pae_core_1 = require("@bluealba/pae-core");
|
|
14
14
|
const read_bootstrap_applications_1 = require("./read-bootstrap-applications");
|
|
15
15
|
const apply_service_local_1 = require("./apply-service-local");
|
|
16
|
+
const MAX_BACKOFF_DELAY = 300000; // 5 minutes
|
|
17
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
16
18
|
/**
|
|
17
19
|
* Reads the current application src/data folder assembles all the platform definitions
|
|
18
20
|
* and sends them to the gateway's /bootstrap/sync endpoint for synchronization.
|
|
19
21
|
*/
|
|
20
22
|
const bootstrapPlatform = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
|
|
23
|
+
const { throwOnError = false, retries = 0, initialDelay = 0 } = options;
|
|
22
24
|
if (!options.scopedTo) {
|
|
23
|
-
|
|
25
|
+
const err = new Error('No options.scopedTo was provider neither the env var SERVICE_ACCESS_NAME is present ! Set one to identify the bootstrap as author for creating/updating entities in the platform');
|
|
26
|
+
console.error('[Bootstrap]', err.message);
|
|
27
|
+
if (throwOnError)
|
|
28
|
+
throw err;
|
|
29
|
+
return;
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const attempt = (attemptNumber, delay) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
if (delay > 0) {
|
|
34
|
+
console.log(`[Bootstrap] Waiting ${delay}ms before attempt ${attemptNumber}/${retries + 1}...`);
|
|
35
|
+
yield sleep(delay);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
console.log('[Bootstrap] Reading platform data from:', (_a = options.path) !== null && _a !== void 0 ? _a : process.cwd());
|
|
39
|
+
const platform = (0, read_bootstrap_applications_1.readPlatformBootstrapFolder)((_b = options.path) !== null && _b !== void 0 ? _b : process.cwd(), options);
|
|
40
|
+
const applications = Object.values(platform.applications);
|
|
41
|
+
console.log(`[Bootstrap] Found ${applications.length} applications`);
|
|
42
|
+
console.log(`[Bootstrap] Found ${(_d = (_c = platform.sharedLibraries) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0} shared libraries`);
|
|
43
|
+
if (options.transformModules) {
|
|
44
|
+
console.warn('[DEPRECATED] transformModules option is deprecated and will be removed in a future version.');
|
|
45
|
+
const transformedModules = options.transformModules(applications.flatMap(app => app.modules));
|
|
46
|
+
const modulesByApp = new Map();
|
|
47
|
+
transformedModules.forEach(module => {
|
|
48
|
+
const appName = module.application || pae_core_1.PLATFORM_APPLICATION_NAME;
|
|
49
|
+
if (!modulesByApp.has(appName)) {
|
|
50
|
+
modulesByApp.set(appName, []);
|
|
51
|
+
}
|
|
52
|
+
modulesByApp.get(appName).push(module);
|
|
53
|
+
});
|
|
54
|
+
modulesByApp.forEach((modules, appName) => {
|
|
55
|
+
if (platform.applications[appName]) {
|
|
56
|
+
platform.applications[appName].modules = modules;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
42
59
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
const processedPlatform = (0, apply_service_local_1.processServiceLocal)(platform);
|
|
61
|
+
const gatewayUrl = (0, pae_core_1.fromEnv)('GATEWAY_SERVICE_URL');
|
|
62
|
+
const url = `${gatewayUrl}/bootstrap/sync`;
|
|
63
|
+
console.log(`[Bootstrap] Sending data to gateway: ${url}`);
|
|
64
|
+
console.log(`[Bootstrap] Scoped to: ${options.scopedTo}`);
|
|
65
|
+
const response = yield fetch(url, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Authorization': `Bearer ${(0, pae_core_1.fromEnv)("SERVICE_ACCESS_SECRET")}`,
|
|
69
|
+
'Accept': 'application/json',
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
'x-bootstrap-scoped-to': options.scopedTo,
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(processedPlatform),
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const errorText = yield response.text();
|
|
77
|
+
throw new Error(`Bootstrap sync failed with status ${response.status}: ${errorText}`);
|
|
49
78
|
}
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
const processedPlatform = (0, apply_service_local_1.processServiceLocal)(platform);
|
|
53
|
-
try {
|
|
54
|
-
// Get gateway URL from environment
|
|
55
|
-
const gatewayUrl = (0, pae_core_1.fromEnv)('GATEWAY_SERVICE_URL');
|
|
56
|
-
const url = `${gatewayUrl}/bootstrap/sync`;
|
|
57
|
-
console.log(`[Bootstrap] Sending data to gateway: ${url}`);
|
|
58
|
-
console.log(`[Bootstrap] Scoped to: ${options.scopedTo}`);
|
|
59
|
-
const response = yield fetch(url, {
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: {
|
|
62
|
-
'Authorization': `Bearer ${(0, pae_core_1.fromEnv)("SERVICE_ACCESS_SECRET")}`,
|
|
63
|
-
'Accept': 'application/json',
|
|
64
|
-
'Content-Type': 'application/json',
|
|
65
|
-
'x-bootstrap-scoped-to': options.scopedTo,
|
|
66
|
-
},
|
|
67
|
-
body: JSON.stringify(processedPlatform),
|
|
68
|
-
});
|
|
69
|
-
if (!response.ok) {
|
|
70
|
-
const errorText = yield response.text();
|
|
71
|
-
throw new Error(`Bootstrap sync failed with status ${response.status}: ${errorText}`);
|
|
79
|
+
console.log('[Bootstrap] Sync completed successfully');
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
catch (error) {
|
|
82
|
+
const err = error instanceof Error ? error : new Error('Bootstrap sync failed with unknown error');
|
|
83
|
+
console.error(`[Bootstrap] Attempt ${attemptNumber}/${retries + 1} failed:`, err.message);
|
|
84
|
+
if (attemptNumber <= retries) {
|
|
85
|
+
const nextDelay = Math.min(delay === 0 ? 5000 : delay * 2, MAX_BACKOFF_DELAY);
|
|
86
|
+
return attempt(attemptNumber + 1, nextDelay);
|
|
87
|
+
}
|
|
88
|
+
if (retries > 0) {
|
|
89
|
+
console.error('[Bootstrap] All retry attempts exhausted. Service will continue running without bootstrap.');
|
|
90
|
+
}
|
|
91
|
+
if (throwOnError)
|
|
92
|
+
throw err;
|
|
79
93
|
}
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
});
|
|
95
|
+
return attempt(1, initialDelay);
|
|
82
96
|
});
|
|
83
97
|
exports.bootstrapPlatform = bootstrapPlatform;
|
|
84
98
|
//# sourceMappingURL=bootstrap-platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-platform.js","sourceRoot":"","sources":["../../../src/bootstrap/bootstrap-platform.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAwE;AACxE,+EAA4E;AAE5E,+DAA4D;
|
|
1
|
+
{"version":3,"file":"bootstrap-platform.js","sourceRoot":"","sources":["../../../src/bootstrap/bootstrap-platform.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAwE;AACxE,+EAA4E;AAE5E,+DAA4D;AAgD5D,MAAM,iBAAiB,GAAG,MAAO,CAAC,CAAC,YAAY;AAE/C,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE9E;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAAO,OAAyB,EAAiB,EAAE;IAClF,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAExE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,kLAAkL,CAAC,CAAC;QAC1M,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,YAAY;YAAE,MAAM,GAAG,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,CAAO,aAAqB,EAAE,KAAa,EAAiB,EAAE;;QAC5E,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,qBAAqB,aAAa,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;YAChG,MAAM,KAAK,CAAC,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AAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;YACnG,OAAO,CAAC,KAAK,CAAC,uBAAuB,aAAa,IAAI,OAAO,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YAE1F,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,iBAAiB,CAAC,CAAC;gBAC/E,OAAO,OAAO,CAAC,aAAa,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;YAED,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,4FAA4F,CAAC,CAAC;YAC9G,CAAC;YAED,IAAI,YAAY;gBAAE,MAAM,GAAG,CAAC;QAC9B,CAAC;IACH,CAAC,CAAA,CAAC;IAEF,OAAO,OAAO,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAClC,CAAC,CAAA,CAAC;AAxFW,QAAA,iBAAiB,qBAwF5B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluealba/pae-bootstrap-lib",
|
|
3
3
|
"description": "PAE library for bootstrapping platforms",
|
|
4
|
-
"version": "3.1.2-
|
|
4
|
+
"version": "3.1.2-feature-resilient-bootstrap-no-cr-254",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
7
7
|
"files": [
|