@aifabrix/builder 2.11.0 → 2.21.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.
Files changed (36) hide show
  1. package/.cursor/rules/project-rules.mdc +194 -0
  2. package/README.md +12 -0
  3. package/lib/api/applications.api.js +164 -0
  4. package/lib/api/auth.api.js +303 -0
  5. package/lib/api/datasources-core.api.js +87 -0
  6. package/lib/api/datasources-extended.api.js +117 -0
  7. package/lib/api/datasources.api.js +13 -0
  8. package/lib/api/deployments.api.js +126 -0
  9. package/lib/api/environments.api.js +245 -0
  10. package/lib/api/external-systems.api.js +251 -0
  11. package/lib/api/index.js +236 -0
  12. package/lib/api/pipeline.api.js +234 -0
  13. package/lib/api/types/applications.types.js +136 -0
  14. package/lib/api/types/auth.types.js +218 -0
  15. package/lib/api/types/datasources.types.js +272 -0
  16. package/lib/api/types/deployments.types.js +184 -0
  17. package/lib/api/types/environments.types.js +197 -0
  18. package/lib/api/types/external-systems.types.js +244 -0
  19. package/lib/api/types/pipeline.types.js +125 -0
  20. package/lib/app-list.js +5 -7
  21. package/lib/app-rotate-secret.js +4 -10
  22. package/lib/cli.js +30 -0
  23. package/lib/commands/login.js +41 -12
  24. package/lib/datasource-deploy.js +7 -30
  25. package/lib/datasource-list.js +9 -6
  26. package/lib/deployer.js +103 -135
  27. package/lib/environment-deploy.js +15 -26
  28. package/lib/external-system-deploy.js +12 -39
  29. package/lib/external-system-download.js +5 -13
  30. package/lib/external-system-test.js +9 -12
  31. package/lib/generator-split.js +342 -0
  32. package/lib/generator.js +94 -5
  33. package/lib/utils/app-register-api.js +5 -10
  34. package/lib/utils/deployment-errors.js +88 -6
  35. package/package.json +1 -1
  36. package/tatus +0 -181
@@ -10,7 +10,7 @@
10
10
 
11
11
  const chalk = require('chalk');
12
12
  const logger = require('./logger');
13
- const { authenticatedApiCall } = require('./api');
13
+ const { registerApplication } = require('../api/applications.api');
14
14
  const { formatApiError } = require('./api-error-handler');
15
15
 
16
16
  /**
@@ -23,14 +23,9 @@ const { formatApiError } = require('./api-error-handler');
23
23
  * @returns {Promise<Object>} API response
24
24
  */
25
25
  async function callRegisterApi(apiUrl, token, environment, registrationData) {
26
- const response = await authenticatedApiCall(
27
- `${apiUrl}/api/v1/environments/${encodeURIComponent(environment)}/applications/register`,
28
- {
29
- method: 'POST',
30
- body: JSON.stringify(registrationData)
31
- },
32
- token
33
- );
26
+ // Use centralized API client
27
+ const authConfig = { type: 'bearer', token: token };
28
+ const response = await registerApplication(apiUrl, environment, authConfig, registrationData);
34
29
 
35
30
  if (!response.success) {
36
31
  const formattedError = response.formattedError || formatApiError(response);
@@ -48,7 +43,7 @@ async function callRegisterApi(apiUrl, token, environment, registrationData) {
48
43
  }
49
44
 
50
45
  // Handle API response structure:
51
- // makeApiCall returns: { success: true, data: <API response> }
46
+ // registerApplication returns: { success: true, data: <API response> }
52
47
  // API response can be:
53
48
  // 1. Direct format: { application: {...}, credentials: {...} }
54
49
  // 2. Wrapped format: { success: true, data: { application: {...}, credentials: {...} } }
@@ -18,8 +18,17 @@ const { parseErrorResponse } = require('./api-error-handler');
18
18
  * @returns {Object} Structured error information
19
19
  */
20
20
  function handleDeploymentError(error) {
21
+ if (!error) {
22
+ return {
23
+ message: 'Unknown error',
24
+ code: 'UNKNOWN',
25
+ timeout: false,
26
+ status: undefined,
27
+ data: undefined
28
+ };
29
+ }
21
30
  const safeError = {
22
- message: error.message,
31
+ message: error.message || 'Unknown error',
23
32
  code: error.code || 'UNKNOWN',
24
33
  timeout: error.code === 'ECONNABORTED',
25
34
  status: error.status || error.response?.status,
@@ -42,6 +51,38 @@ function handleDeploymentError(error) {
42
51
  * @throws {Error} User-friendly error message
43
52
  */
44
53
  async function handleDeploymentErrors(error, appName, url, alreadyLogged = false) {
54
+ // For validation errors (like URL validation), just re-throw them directly
55
+ // They already have user-friendly messages
56
+ // Handle both Error objects and strings
57
+ let errorMessage = '';
58
+ if (error instanceof Error) {
59
+ errorMessage = error.message || '';
60
+ } else if (typeof error === 'string') {
61
+ errorMessage = error;
62
+ } else if (error && typeof error === 'object' && error.message) {
63
+ errorMessage = error.message;
64
+ }
65
+
66
+ if (errorMessage && (
67
+ errorMessage.includes('Controller URL must use HTTPS') ||
68
+ errorMessage.includes('Invalid environment key') ||
69
+ errorMessage.includes('Environment key is required') ||
70
+ errorMessage.includes('Authentication configuration is required') ||
71
+ errorMessage.includes('Invalid controller URL format') ||
72
+ errorMessage.includes('Controller URL is required')
73
+ )) {
74
+ // If error is a string, convert to Error object
75
+ if (typeof error === 'string') {
76
+ throw new Error(error);
77
+ }
78
+ // If it's already an Error object, re-throw it directly
79
+ if (error instanceof Error) {
80
+ throw error;
81
+ }
82
+ // Otherwise, create a new Error with the message
83
+ throw new Error(errorMessage);
84
+ }
85
+
45
86
  // Log to audit log if not already logged
46
87
  if (!alreadyLogged) {
47
88
  try {
@@ -63,7 +104,17 @@ async function handleDeploymentErrors(error, appName, url, alreadyLogged = false
63
104
 
64
105
  // Ensure errorData is not undefined before parsing
65
106
  // If errorData is undefined, use the error message instead
66
- const errorResponse = errorData !== undefined ? errorData : safeError.message;
107
+ let errorResponse = errorData !== undefined ? errorData : safeError.message;
108
+
109
+ // Ensure errorResponse is a string or object, not an Error object
110
+ if (errorResponse instanceof Error) {
111
+ errorResponse = errorResponse.message || 'Unknown error occurred';
112
+ }
113
+
114
+ // Ensure errorResponse is not null or undefined
115
+ if (errorResponse === null || errorResponse === undefined) {
116
+ errorResponse = safeError.message || 'Unknown error occurred';
117
+ }
67
118
 
68
119
  // Determine if this is a network error
69
120
  const isNetworkError = safeError.code === 'ECONNREFUSED' ||
@@ -72,13 +123,44 @@ async function handleDeploymentErrors(error, appName, url, alreadyLogged = false
72
123
  safeError.timeout;
73
124
 
74
125
  // Parse error using error handler
75
- const parsedError = parseErrorResponse(errorResponse, safeError.status || 0, isNetworkError);
126
+ let parsedError;
127
+ try {
128
+ parsedError = parseErrorResponse(errorResponse, safeError.status || 0, isNetworkError);
129
+ // Ensure parsedError is a valid object
130
+ if (!parsedError || typeof parsedError !== 'object') {
131
+ throw new Error('parseErrorResponse returned invalid result');
132
+ }
133
+ } catch (parseErr) {
134
+ // If parsing fails, use the safe error message
135
+ parsedError = {
136
+ message: safeError.message || 'Unknown error occurred',
137
+ formatted: safeError.message || 'Unknown error occurred',
138
+ data: undefined
139
+ };
140
+ }
141
+
142
+ // Ensure parsedError is always a valid object with required properties
143
+ if (!parsedError || typeof parsedError !== 'object') {
144
+ parsedError = {
145
+ message: safeError.message || 'Unknown error occurred',
146
+ formatted: safeError.message || 'Unknown error occurred',
147
+ data: undefined
148
+ };
149
+ }
150
+
151
+ // Ensure we have a message - handle case where parsedError.message might be undefined
152
+ const finalErrorMessage = (parsedError && parsedError.message) ? parsedError.message : (safeError.message || 'Unknown error occurred');
153
+
154
+ // Validate finalErrorMessage is a string
155
+ if (typeof finalErrorMessage !== 'string') {
156
+ throw new Error(`Invalid error message type: ${typeof finalErrorMessage}. Error: ${JSON.stringify(error)}`);
157
+ }
76
158
 
77
159
  // Throw clean error message (without emoji) - CLI will format it
78
- const formattedError = new Error(parsedError.message);
79
- formattedError.formatted = parsedError.formatted;
160
+ const formattedError = new Error(finalErrorMessage);
161
+ formattedError.formatted = parsedError?.formatted || finalErrorMessage;
80
162
  formattedError.status = safeError.status;
81
- formattedError.data = parsedError.data;
163
+ formattedError.data = parsedError?.data;
82
164
  formattedError._logged = true; // Mark as logged to prevent double-logging
83
165
  throw formattedError;
84
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aifabrix/builder",
3
- "version": "2.11.0",
3
+ "version": "2.21.0",
4
4
  "description": "AI Fabrix Local Fabric & Deployment SDK",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
package/tatus DELETED
@@ -1,181 +0,0 @@
1
-
2
- SSUUMMMMAARRYY OOFF LLEESSSS CCOOMMMMAANNDDSS
3
-
4
- Commands marked with * may be preceded by a number, _N.
5
- Notes in parentheses indicate the behavior if _N is given.
6
- A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.
7
-
8
- h H Display this help.
9
- q :q Q :Q ZZ Exit.
10
- ---------------------------------------------------------------------------
11
-
12
- MMOOVVIINNGG
13
-
14
- e ^E j ^N CR * Forward one line (or _N lines).
15
- y ^Y k ^K ^P * Backward one line (or _N lines).
16
- f ^F ^V SPACE * Forward one window (or _N lines).
17
- b ^B ESC-v * Backward one window (or _N lines).
18
- z * Forward one window (and set window to _N).
19
- w * Backward one window (and set window to _N).
20
- ESC-SPACE * Forward one window, but don't stop at end-of-file.
21
- d ^D * Forward one half-window (and set half-window to _N).
22
- u ^U * Backward one half-window (and set half-window to _N).
23
- ESC-) RightArrow * Right one half screen width (or _N positions).
24
- ESC-( LeftArrow * Left one half screen width (or _N positions).
25
- ESC-} ^RightArrow Right to last column displayed.
26
- ESC-{ ^LeftArrow Left to first column.
27
- F Forward forever; like "tail -f".
28
- ESC-F Like F but stop when search pattern is found.
29
- r ^R ^L Repaint screen.
30
- R Repaint screen, discarding buffered input.
31
- ---------------------------------------------------
32
- Default "window" is the screen height.
33
- Default "half-window" is half of the screen height.
34
- ---------------------------------------------------------------------------
35
-
36
- SSEEAARRCCHHIINNGG
37
-
38
- /_p_a_t_t_e_r_n * Search forward for (_N-th) matching line.
39
- ?_p_a_t_t_e_r_n * Search backward for (_N-th) matching line.
40
- n * Repeat previous search (for _N-th occurrence).
41
- N * Repeat previous search in reverse direction.
42
- ESC-n * Repeat previous search, spanning files.
43
- ESC-N * Repeat previous search, reverse dir. & spanning files.
44
- ^O^N ^On * Search forward for (_N-th) OSC8 hyperlink.
45
- ^O^P ^Op * Search backward for (_N-th) OSC8 hyperlink.
46
- ^O^L ^Ol Jump to the currently selected OSC8 hyperlink.
47
- ESC-u Undo (toggle) search highlighting.
48
- ESC-U Clear search highlighting.
49
- &_p_a_t_t_e_r_n * Display only matching lines.
50
- ---------------------------------------------------
51
- A search pattern may begin with one or more of:
52
- ^N or ! Search for NON-matching lines.
53
- ^E or * Search multiple files (pass thru END OF FILE).
54
- ^F or @ Start search at FIRST file (for /) or last file (for ?).
55
- ^K Highlight matches, but don't move (KEEP position).
56
- ^R Don't use REGULAR EXPRESSIONS.
57
- ^S _n Search for match in _n-th parenthesized subpattern.
58
- ^W WRAP search if no match found.
59
- ^L Enter next character literally into pattern.
60
- ---------------------------------------------------------------------------
61
-
62
- JJUUMMPPIINNGG
63
-
64
- g < ESC-< * Go to first line in file (or line _N).
65
- G > ESC-> * Go to last line in file (or line _N).
66
- p % * Go to beginning of file (or _N percent into file).
67
- t * Go to the (_N-th) next tag.
68
- T * Go to the (_N-th) previous tag.
69
- { ( [ * Find close bracket } ) ].
70
- } ) ] * Find open bracket { ( [.
71
- ESC-^F _<_c_1_> _<_c_2_> * Find close bracket _<_c_2_>.
72
- ESC-^B _<_c_1_> _<_c_2_> * Find open bracket _<_c_1_>.
73
- ---------------------------------------------------
74
- Each "find close bracket" command goes forward to the close bracket
75
- matching the (_N-th) open bracket in the top line.
76
- Each "find open bracket" command goes backward to the open bracket
77
- matching the (_N-th) close bracket in the bottom line.
78
-
79
- m_<_l_e_t_t_e_r_> Mark the current top line with <letter>.
80
- M_<_l_e_t_t_e_r_> Mark the current bottom line with <letter>.
81
- '_<_l_e_t_t_e_r_> Go to a previously marked position.
82
- '' Go to the previous position.
83
- ^X^X Same as '.
84
- ESC-m_<_l_e_t_t_e_r_> Clear a mark.
85
- ---------------------------------------------------
86
- A mark is any upper-case or lower-case letter.
87
- Certain marks are predefined:
88
- ^ means beginning of the file
89
- $ means end of the file
90
- ---------------------------------------------------------------------------
91
-
92
- CCHHAANNGGIINNGG FFIILLEESS
93
-
94
- :e [_f_i_l_e] Examine a new file.
95
- ^X^V Same as :e.
96
- :n * Examine the (_N-th) next file from the command line.
97
- :p * Examine the (_N-th) previous file from the command line.
98
- :x * Examine the first (or _N-th) file from the command line.
99
- ^O^O Open the currently selected OSC8 hyperlink.
100
- :d Delete the current file from the command line list.
101
- = ^G :f Print current file name.
102
- ---------------------------------------------------------------------------
103
-
104
- MMIISSCCEELLLLAANNEEOOUUSS CCOOMMMMAANNDDSS
105
-
106
- -_<_f_l_a_g_> Toggle a command line option [see OPTIONS below].
107
- --_<_n_a_m_e_> Toggle a command line option, by name.
108
- __<_f_l_a_g_> Display the setting of a command line option.
109
- ___<_n_a_m_e_> Display the setting of an option, by name.
110
- +_c_m_d Execute the less cmd each time a new file is examined.
111
-
112
- !_c_o_m_m_a_n_d Execute the shell command with $SHELL.
113
- #_c_o_m_m_a_n_d Execute the shell command, expanded like a prompt.
114
- |XX_c_o_m_m_a_n_d Pipe file between current pos & mark XX to shell command.
115
- s _f_i_l_e Save input to a file.
116
- v Edit the current file with $VISUAL or $EDITOR.
117
- V Print version number of "less".
118
- ---------------------------------------------------------------------------
119
-
120
- OOPPTTIIOONNSS
121
-
122
- Most options may be changed either on the command line,
123
- or from within less by using the - or -- command.
124
- Options may be given in one of two forms: either a single
125
- character preceded by a -, or a name preceded by --.
126
-
127
- -? ........ --help
128
- Display help (from command line).
129
- -a ........ --search-skip-screen
130
- Search skips current screen.
131
- -A ........ --SEARCH-SKIP-SCREEN
132
- Search starts just after target line.
133
- -b [_N] .... --buffers=[_N]
134
- Number of buffers.
135
- -B ........ --auto-buffers
136
- Don't automatically allocate buffers for pipes.
137
- -c ........ --clear-screen
138
- Repaint by clearing rather than scrolling.
139
- -d ........ --dumb
140
- Dumb terminal.
141
- -D xx_c_o_l_o_r . --color=xx_c_o_l_o_r
142
- Set screen colors.
143
- -e -E .... --quit-at-eof --QUIT-AT-EOF
144
- Quit at end of file.
145
- -f ........ --force
146
- Force open non-regular files.
147
- -F ........ --quit-if-one-screen
148
- Quit if entire file fits on first screen.
149
- -g ........ --hilite-search
150
- Highlight only last match for searches.
151
- -G ........ --HILITE-SEARCH
152
- Don't highlight any matches for searches.
153
- -h [_N] .... --max-back-scroll=[_N]
154
- Backward scroll limit.
155
- -i ........ --ignore-case
156
- Ignore case in searches that do not contain uppercase.
157
- -I ........ --IGNORE-CASE
158
- Ignore case in all searches.
159
- -j [_N] .... --jump-target=[_N]
160
- Screen position of target lines.
161
- -J ........ --status-column
162
- Display a status column at left edge of screen.
163
- -k _f_i_l_e ... --lesskey-file=_f_i_l_e
164
- Use a compiled lesskey file.
165
- -K ........ --quit-on-intr
166
- Exit less in response to ctrl-C.
167
- -L ........ --no-lessopen
168
- Ignore the LESSOPEN environment variable.
169
- -m -M .... --long-prompt --LONG-PROMPT
170
- Set prompt style.
171
- -n ......... --line-numbers
172
- Suppress line numbers in prompts and messages.
173
- -N ......... --LINE-NUMBERS
174
- Display line number at start of each line.
175
- -o [_f_i_l_e] .. --log-file=[_f_i_l_e]
176
- Copy to log file (standard input only).
177
- -O [_f_i_l_e] .. --LOG-FILE=[_f_i_l_e]
178
- Copy to log file (unconditionally overwrite).
179
- -p _p_a_t_t_e_r_n . --pattern=[_p_a_t_t_e_r_n]
180
- Start at pattern (from command line).
181
- -P [_p_r_o_m_p_t] --prompt=[_p_r_o_m_p_t]