@appliqation/automation-sdk 2.4.0 → 2.5.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,44 @@
1
+ const logger = require('../utils/logger');
2
+
3
+ /**
4
+ * Service for auto-discovering project info from API key.
5
+ * All methods return null on failure — never throws.
6
+ */
7
+ class ProjectInfoService {
8
+ constructor() {
9
+ this._cache = null;
10
+ this._pending = null;
11
+ }
12
+
13
+ /**
14
+ * Get project info from the server.
15
+ * Caches the result and deduplicates concurrent calls.
16
+ *
17
+ * @param {Object} httpClient - The HttpClient instance
18
+ * @returns {Promise<Object|null>} Project info or null on failure
19
+ */
20
+ async getProjectInfo(httpClient) {
21
+ if (this._cache) return this._cache;
22
+ if (this._pending) return this._pending;
23
+
24
+ this._pending = httpClient.get('/api/automation/project/info')
25
+ .then(response => {
26
+ if (response && response.success && response.project) {
27
+ this._cache = response.project;
28
+ return this._cache;
29
+ }
30
+ return null;
31
+ })
32
+ .catch(err => {
33
+ logger.debug('Project auto-discovery unavailable', { error: err.message });
34
+ return null;
35
+ })
36
+ .finally(() => {
37
+ this._pending = null;
38
+ });
39
+
40
+ return this._pending;
41
+ }
42
+ }
43
+
44
+ module.exports = ProjectInfoService;