@geek-fun/serverlessinsight 0.9.0 → 0.9.2

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 (112) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
  3. package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +2 -2
  4. package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -3
  5. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
  6. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
  7. package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +109 -0
  8. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
  9. package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
  10. package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +2 -2
  11. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
  12. package/CHANGELOG.md +17 -0
  13. package/README.md +78 -2
  14. package/README.zh-CN.md +69 -2
  15. package/codecov +0 -0
  16. package/codecov.SHA256SUM +1 -0
  17. package/codecov.SHA256SUM.sig +16 -0
  18. package/dist/package.json +2 -2
  19. package/dist/src/commands/deploy.js +9 -3
  20. package/dist/src/commands/destroy.js +8 -2
  21. package/dist/src/commands/forceUnlock.js +5 -5
  22. package/dist/src/commands/index.js +173 -85
  23. package/dist/src/commands/login.js +12 -1
  24. package/dist/src/commands/migrate.js +287 -0
  25. package/dist/src/commands/plan.js +28 -2
  26. package/dist/src/commands/schema.js +24 -0
  27. package/dist/src/commands/show.js +99 -33
  28. package/dist/src/commands/validate.js +34 -2
  29. package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
  30. package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
  31. package/dist/src/common/aliyunClient/fc3Operations.js +39 -4
  32. package/dist/src/common/aliyunClient/nasOperations.js +4 -3
  33. package/dist/src/common/aliyunClient/ossOperations.js +52 -8
  34. package/dist/src/common/aliyunClient/slsOperations.js +3 -2
  35. package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
  36. package/dist/src/common/apiClient.js +22 -5
  37. package/dist/src/common/constants.js +7 -1
  38. package/dist/src/common/context.js +5 -4
  39. package/dist/src/common/jsonOutput.js +77 -0
  40. package/dist/src/common/lockManager.js +1 -1
  41. package/dist/src/common/logger.js +6 -3
  42. package/dist/src/common/migrationMarker.js +34 -0
  43. package/dist/src/common/noColor.js +9 -0
  44. package/dist/src/common/planFormatter.js +12 -6
  45. package/dist/src/common/runtimeMapper.js +7 -3
  46. package/dist/src/common/siCron.js +415 -0
  47. package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
  48. package/dist/src/common/stateBackend/index.js +5 -2
  49. package/dist/src/common/stateBackend/localStateBackend.js +8 -2
  50. package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
  51. package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
  52. package/dist/src/common/stateBackend/saasStateBackend.js +88 -9
  53. package/dist/src/common/stateManager.js +56 -5
  54. package/dist/src/common/tencentClient/cosOperations.js +1 -1
  55. package/dist/src/common/tencentClient/scfOperations.js +4 -1
  56. package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
  57. package/dist/src/common/volcengineClient/index.js +6 -2
  58. package/dist/src/common/volcengineClient/vefaasOperations.js +48 -3
  59. package/dist/src/lang/en.js +254 -1
  60. package/dist/src/lang/index.js +36 -1
  61. package/dist/src/lang/zh-CN.js +253 -1
  62. package/dist/src/parser/functionParser.js +47 -1
  63. package/dist/src/parser/index.js +1 -1
  64. package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
  65. package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
  66. package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
  67. package/dist/src/stack/aliyunStack/databasePlanner.js +2 -2
  68. package/dist/src/stack/aliyunStack/databaseResource.js +18 -10
  69. package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
  70. package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
  71. package/dist/src/stack/aliyunStack/fc3Planner.js +26 -0
  72. package/dist/src/stack/aliyunStack/fc3Resource.js +190 -13
  73. package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
  74. package/dist/src/stack/aliyunStack/ossResource.js +5 -1
  75. package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
  76. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
  77. package/dist/src/stack/aliyunStack/tablestoreResource.js +3 -3
  78. package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
  79. package/dist/src/stack/deploy.js +2 -3
  80. package/dist/src/stack/localStack/event.js +2 -13
  81. package/dist/src/stack/localStack/function.js +2 -13
  82. package/dist/src/stack/localStack/functionRunner.js +5 -4
  83. package/dist/src/stack/localStack/index.js +8 -1
  84. package/dist/src/stack/localStack/timer.js +162 -0
  85. package/dist/src/stack/localStack/utils.js +19 -1
  86. package/dist/src/stack/scfStack/cosExecutor.js +2 -2
  87. package/dist/src/stack/scfStack/cosResource.js +2 -2
  88. package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
  89. package/dist/src/stack/scfStack/esServerlessResource.js +7 -3
  90. package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
  91. package/dist/src/stack/scfStack/scfExecutor.js +2 -2
  92. package/dist/src/stack/scfStack/scfPlanner.js +52 -18
  93. package/dist/src/stack/scfStack/scfResource.js +202 -12
  94. package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
  95. package/dist/src/stack/scfStack/tdsqlcResource.js +7 -3
  96. package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
  97. package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
  98. package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
  99. package/dist/src/stack/volcengineStack/tosResource.js +1 -1
  100. package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
  101. package/dist/src/stack/volcengineStack/vefaasPlanner.js +49 -0
  102. package/dist/src/stack/volcengineStack/vefaasResource.js +221 -4
  103. package/dist/src/validator/functionSchema.js +25 -2
  104. package/dist/src/validator/iacSchema.js +2 -1
  105. package/dist/src/validator/index.js +4 -1
  106. package/dist/src/validator/rootSchema.js +77 -19
  107. package/dist/src/validator/schemaExport.js +60 -0
  108. package/dist/src/validator/semanticValidation.js +79 -0
  109. package/dist/src/validator/templateRefSchema.js +9 -1
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/package.json +2 -2
  112. package/samples/aliyun-poc-timer.yml +39 -0
@@ -69,19 +69,19 @@ const forceUnlockCommand = async (lockId, options = {}) => {
69
69
  readLock: async () => (0, lockManager_1.readLockFileForCommand)(statePath),
70
70
  forceUnlock: async (id) => (0, lockManager_1.forceUnlock)(statePath, id),
71
71
  loadState: async () => {
72
- throw new Error('Not supported in no-location mode');
72
+ throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
73
73
  },
74
74
  saveState: async () => {
75
- throw new Error('Not supported in no-location mode');
75
+ throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
76
76
  },
77
77
  acquireLock: async () => {
78
- throw new Error('Not supported in no-location mode');
78
+ throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
79
79
  },
80
80
  releaseLock: async () => {
81
- throw new Error('Not supported in no-location mode');
81
+ throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
82
82
  },
83
83
  withLock: async () => {
84
- throw new Error('Not supported in no-location mode');
84
+ throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
85
85
  },
86
86
  };
87
87
  }
@@ -10,10 +10,13 @@ const local_1 = require("./local");
10
10
  const plan_1 = require("./plan");
11
11
  const forceUnlock_1 = require("./forceUnlock");
12
12
  const show_1 = require("./show");
13
+ const schema_1 = require("./schema");
13
14
  const login_1 = require("./login");
14
15
  const logout_1 = require("./logout");
15
16
  const whoami_1 = require("./whoami");
17
+ const migrate_1 = require("./migrate");
16
18
  const lang_1 = require("../lang");
19
+ const jsonOutput_1 = require("../common/jsonOutput");
17
20
  const parser_1 = require("../parser");
18
21
  const MAX_ERROR_MESSAGE_LENGTH = 2000;
19
22
  const truncateErrorMessage = (message) => {
@@ -23,6 +26,27 @@ const truncateErrorMessage = (message) => {
23
26
  ? `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH)}… (truncated ${message.length} chars)`
24
27
  : message;
25
28
  };
29
+ /**
30
+ * Issue #250: a thrown error's stable machine code is the i18n key behind its
31
+ * message. Errors may already carry a `code` (an i18n key); otherwise the
32
+ * message is mapped back through the catalogs — locale-independent, so the
33
+ * code is identical under LANG=zh_CN and LANG=en_US.
34
+ */
35
+ const resolveErrorCode = (error) => {
36
+ if (typeof error?.code === 'string' && (0, lang_1.hasLangKey)(error.code)) {
37
+ return error.code;
38
+ }
39
+ const fromMessage = (0, lang_1.lookupErrorCode)(error?.message);
40
+ if (fromMessage) {
41
+ return fromMessage;
42
+ }
43
+ return typeof error?.code === 'string' ? error.code : undefined;
44
+ };
45
+ // Let queued stdout writes flush (async on macOS pipes) before the process
46
+ // ends, so a piped `si ... --json | jq` never sees a truncated document.
47
+ const flushStdoutAndExit = (exitCode) => {
48
+ process.stdout.write('', () => process.exit(exitCode));
49
+ };
26
50
  // Global error handler
27
51
  const handleCommandError = (error, commandName) => {
28
52
  // Skip logging if already logged by handlePartialFailure
@@ -33,30 +57,28 @@ const handleCommandError = (error, commandName) => {
33
57
  error: truncateErrorMessage(error?.message) || 'Unknown error occurred',
34
58
  }));
35
59
  }
60
+ const errorCode = resolveErrorCode(error);
61
+ if (errorCode) {
62
+ common_1.logger.error(lang_1.lang.__('ERROR_CODE', { code: errorCode }));
63
+ }
36
64
  if (error?.stack && process.env.DEBUG) {
37
65
  common_1.logger.debug(lang_1.lang.__('STACK_TRACE', { stack: error.stack }));
38
66
  }
39
- let exitCode = 1;
40
- if (error?.code) {
41
- if (typeof error.code === 'number') {
42
- exitCode = error.code;
43
- }
44
- else if (typeof error.code === 'string') {
45
- const errorCodeMap = {
46
- ENOENT: 2,
47
- EACCES: 3,
48
- VALIDATION: 4,
49
- NETWORK: 5,
50
- };
51
- exitCode = errorCodeMap[error.code] || 1;
52
- }
67
+ if ((0, jsonOutput_1.isJsonMode)()) {
68
+ (0, jsonOutput_1.writeJson)({
69
+ error: {
70
+ code: errorCode ?? 'UNKNOWN',
71
+ message: truncateErrorMessage(error?.message) || 'Unknown error occurred',
72
+ },
73
+ });
53
74
  }
54
- process.exit(exitCode);
75
+ flushStdoutAndExit(1);
55
76
  };
56
77
  const actionWrapper = (commandName, handler) => {
57
78
  // Reset context before each command execution
58
79
  (0, common_1.clearContext)();
59
80
  return async (...args) => {
81
+ (0, jsonOutput_1.setJsonMode)(false);
60
82
  try {
61
83
  await handler(...args);
62
84
  }
@@ -66,32 +88,41 @@ const actionWrapper = (commandName, handler) => {
66
88
  };
67
89
  };
68
90
  const program = new commander_1.Command();
69
- program.name('si').description('CLI for ServerlessInsight').version((0, common_1.getVersion)());
91
+ program.name('si').description(lang_1.lang.__('CMD_ROOT_DESC')).version((0, common_1.getVersion)());
70
92
  program
71
93
  .command('login')
72
- .description('authenticate with ServerlessInsight Console')
73
- .option('--si-api-key <key>', 'authenticate with an existing API key')
94
+ .description(lang_1.lang.__('CMD_LOGIN_DESC'))
95
+ .option('--si-api-key <key>', lang_1.lang.__('OPT_SI_API_KEY_EXISTING'))
74
96
  .action(actionWrapper('login', async ({ siApiKey }) => {
75
97
  await (0, login_1.login)({ siApiKey });
76
98
  }));
77
99
  program
78
100
  .command('logout')
79
- .description('revoke API key and clear local credentials')
101
+ .description(lang_1.lang.__('CMD_LOGOUT_DESC'))
80
102
  .action(actionWrapper('logout', async () => {
81
103
  await (0, logout_1.logout)();
82
104
  }));
83
105
  program
84
106
  .command('whoami')
85
- .description('show current login status')
107
+ .description(lang_1.lang.__('CMD_WHOAMI_DESC'))
86
108
  .action(actionWrapper('whoami', async () => {
87
109
  await (0, whoami_1.whoami)();
88
110
  }));
111
+ program
112
+ .command('schema')
113
+ .description(lang_1.lang.__('CMD_SCHEMA_DESC'))
114
+ .option('-o, --output <path>', lang_1.lang.__('OPT_SCHEMA_OUTPUT'))
115
+ .action(actionWrapper('schema', async ({ output }) => {
116
+ await (0, schema_1.schema)({ output });
117
+ }));
89
118
  program
90
119
  .command('show')
91
- .description('show deployed resources from state')
92
- .option('-f, --file <path>', 'specify the yaml file')
93
- .option('-s, --stage <stage>', 'specify the stage')
94
- .action(actionWrapper('show', async ({ file, stage }) => {
120
+ .description(lang_1.lang.__('CMD_SHOW_DESC'))
121
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
122
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
123
+ .option('--json', lang_1.lang.__('OPT_JSON'))
124
+ .action(actionWrapper('show', async ({ file, stage, json }) => {
125
+ (0, jsonOutput_1.setJsonMode)(!!json);
95
126
  const iacLocation = (0, common_1.getIacLocation)(file);
96
127
  const rawIac = (0, parser_1.parseYaml)(iacLocation);
97
128
  await (0, common_1.setContext)({
@@ -105,30 +136,38 @@ program
105
136
  const context = (0, common_1.getContext)();
106
137
  const iac = (0, parser_1.revalYaml)(iacLocation, context);
107
138
  (0, common_1.setIac)(iac);
108
- await (0, show_1.show)({ stage, location: file, iac });
139
+ await (0, show_1.show)({ stage, location: file, iac, json: !!json });
109
140
  }));
110
141
  program
111
142
  .command('validate')
112
- .description('validate serverless Iac yaml')
113
- .option('-f, --file <path>', 'specify the yaml file')
114
- .option('-s, --stage <stage>', 'specify the stage')
115
- .action(actionWrapper('validate', async ({ file, stage }) => {
143
+ .description(lang_1.lang.__('CMD_VALIDATE_DESC'))
144
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
145
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
146
+ .option('--json', lang_1.lang.__('OPT_JSON'))
147
+ .action(actionWrapper('validate', async ({ file, stage, json }) => {
148
+ (0, jsonOutput_1.setJsonMode)(!!json);
116
149
  common_1.logger.debug(lang_1.lang.__('LOG_COMMAND_INFO'));
117
- await (0, validate_1.validate)({ stage, location: file });
150
+ const result = await (0, validate_1.validate)({ stage, location: file, json: !!json });
151
+ // Issue #250 exit-code convention: 0 = valid, 1 = validation failed.
152
+ if (!result.valid) {
153
+ process.exitCode = 1;
154
+ }
118
155
  }));
119
156
  program
120
157
  .command('plan')
121
- .description('generate and show deployment plan')
122
- .option('-f, --file <path>', 'specify the yaml file')
123
- .option('-s, --stage <stage>', 'specify the stage')
124
- .option('-r, --region <region>', 'specify the region')
125
- .option('-v, --provider <provider>', 'specify the provider')
126
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
127
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
128
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
129
- .option('--no-refresh', 'skip live cloud probing; diff config against state only (no drift detection)')
130
- .action(actionWrapper('plan', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, }) => {
131
- await (0, plan_1.plan)({
158
+ .description(lang_1.lang.__('CMD_PLAN_DESC'))
159
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
160
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
161
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
162
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
163
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
164
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
165
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
166
+ .option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
167
+ .option('--json', lang_1.lang.__('OPT_JSON'))
168
+ .option('--no-color', lang_1.lang.__('OPT_NO_COLOR'))
169
+ .action(actionWrapper('plan', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, json, color, }) => {
170
+ const result = await (0, plan_1.plan)({
132
171
  stage,
133
172
  location: file,
134
173
  region,
@@ -137,23 +176,32 @@ program
137
176
  accessKeySecret,
138
177
  securityToken,
139
178
  refresh,
179
+ json: !!json,
180
+ noColor: color === false,
140
181
  });
182
+ // Issue #250 exit-code convention (terraform-compatible):
183
+ // 0 = no changes, 2 = changes present, 1 = execution error (handler).
184
+ if (result.hasChanges) {
185
+ process.exitCode = 2;
186
+ }
141
187
  }));
142
188
  // Issue #246: `diff` is the primary verb users say — it runs the same plan
143
189
  // flow; `plan` stays for compatibility.
144
190
  program
145
191
  .command('diff')
146
- .description('show changes between your config and the live cloud (alias of plan)')
147
- .option('-f, --file <path>', 'specify the yaml file')
148
- .option('-s, --stage <stage>', 'specify the stage')
149
- .option('-r, --region <region>', 'specify the region')
150
- .option('-v, --provider <provider>', 'specify the provider')
151
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
152
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
153
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
154
- .option('--no-refresh', 'skip live cloud probing; diff config against state only (no drift detection)')
155
- .action(actionWrapper('diff', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, }) => {
156
- await (0, plan_1.plan)({
192
+ .description(lang_1.lang.__('CMD_DIFF_DESC'))
193
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
194
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
195
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
196
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
197
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
198
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
199
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
200
+ .option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
201
+ .option('--json', lang_1.lang.__('OPT_JSON'))
202
+ .option('--no-color', lang_1.lang.__('OPT_NO_COLOR'))
203
+ .action(actionWrapper('diff', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, json, color, }) => {
204
+ const result = await (0, plan_1.plan)({
157
205
  stage,
158
206
  location: file,
159
207
  region,
@@ -162,22 +210,27 @@ program
162
210
  accessKeySecret,
163
211
  securityToken,
164
212
  refresh,
213
+ json: !!json,
214
+ noColor: color === false,
165
215
  });
216
+ if (result.hasChanges) {
217
+ process.exitCode = 2;
218
+ }
166
219
  }));
167
220
  program
168
221
  .command('deploy')
169
- .description('deploy serverless Iac yaml')
170
- .option('-f, --file <path>', 'specify the yaml file')
171
- .option('-s, --stage <stage>', 'specify the stage')
172
- .option('-r, --region <region>', 'specify the region')
173
- .option('-v, --provider <provider>', 'specify the provider')
174
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
175
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
176
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
177
- .option('--si-api-key <key>', 'ServerlessInsight API key (overrides SI_API_KEY env)')
178
- .option('-y, --auto-approve', 'skip interactive approval of plan before deploying')
179
- .option('--no-refresh', 'skip live cloud probing; diff config against state only (no drift detection)')
180
- .option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
222
+ .description(lang_1.lang.__('CMD_DEPLOY_DESC'))
223
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
224
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
225
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
226
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
227
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
228
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
229
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
230
+ .option('--si-api-key <key>', lang_1.lang.__('OPT_SI_API_KEY'))
231
+ .option('-y, --auto-approve', lang_1.lang.__('OPT_AUTO_APPROVE'))
232
+ .option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
233
+ .option('-p, --parameter <key=value>', lang_1.lang.__('OPT_PARAMETER'), (value, previous) => {
181
234
  const [key, val] = value.split('=');
182
235
  previous[key] = val;
183
236
  return previous;
@@ -197,16 +250,51 @@ program
197
250
  refresh,
198
251
  });
199
252
  }));
253
+ program
254
+ .command('migrate')
255
+ .description(lang_1.lang.__('CMD_MIGRATE_DESC'))
256
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
257
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
258
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
259
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
260
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
261
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
262
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
263
+ .option('--si-api-key <key>', lang_1.lang.__('OPT_SI_API_KEY'))
264
+ .option('-y, --auto-approve', lang_1.lang.__('OPT_AUTO_APPROVE'))
265
+ .option('--force', lang_1.lang.__('OPT_FORCE'))
266
+ .option('--no-marker', lang_1.lang.__('OPT_NO_MARKER'))
267
+ .option('--dry-run', lang_1.lang.__('OPT_DRY_RUN'))
268
+ .option('--rollback', lang_1.lang.__('OPT_ROLLBACK'))
269
+ .action(actionWrapper('migrate', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, siApiKey, autoApprove, force, marker, dryRun, rollback, }) => {
270
+ await (0, migrate_1.migrate)({
271
+ stage,
272
+ location: file,
273
+ region,
274
+ provider,
275
+ accessKeyId,
276
+ accessKeySecret,
277
+ securityToken,
278
+ siApiKey,
279
+ autoApprove,
280
+ force,
281
+ // Commander models `--no-marker` as the negation of an implicit
282
+ // `marker` boolean (default true).
283
+ noMarker: marker === false,
284
+ dryRun,
285
+ rollback,
286
+ });
287
+ }));
200
288
  program
201
289
  .command('destroy')
202
- .option('-f, --file <path>', 'specify the yaml file')
203
- .option('-s, --stage <stage>', 'specify the stage')
204
- .option('-r, --region <region>', 'specify the region')
205
- .option('-v, --provider <provider>', 'specify the provider')
206
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
207
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
208
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
209
- .description('destroy serverless stack')
290
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
291
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
292
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
293
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
294
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
295
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
296
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
297
+ .description(lang_1.lang.__('CMD_DESTROY_DESC'))
210
298
  .action(actionWrapper('destroy', async ({ file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
211
299
  await (0, destroy_1.destroyStack)({
212
300
  location: file,
@@ -220,11 +308,11 @@ program
220
308
  }));
221
309
  program
222
310
  .command('local')
223
- .description('run Serverless application locally for debugging')
224
- .option('-f, --file <path>', 'specify the yaml file')
225
- .option('-s, --stage <stage>', 'specify the stage', 'default')
226
- .option('-d, --debug', 'enable debug mode')
227
- .option('-w, --watch', 'enable file watch', true)
311
+ .description(lang_1.lang.__('CMD_LOCAL_DESC'))
312
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
313
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'), 'default')
314
+ .option('-d, --debug', lang_1.lang.__('OPT_DEBUG'))
315
+ .option('-w, --watch', lang_1.lang.__('OPT_WATCH'), true)
228
316
  .action(actionWrapper('local', async ({ stage, debug, watch, file }) => {
229
317
  await (0, local_1.runLocal)({
230
318
  stage,
@@ -235,14 +323,14 @@ program
235
323
  }));
236
324
  program
237
325
  .command('force-unlock <lockId>')
238
- .description('manually remove a stuck lock (use with caution)')
239
- .option('-f, --file <path>', 'specify the yaml file (required for remote backends)')
240
- .option('-s, --stage <stage>', 'specify the stage')
241
- .option('-r, --region <region>', 'specify the region')
242
- .option('-v, --provider <provider>', 'specify the provider')
243
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
244
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
245
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
326
+ .description(lang_1.lang.__('CMD_FORCE_UNLOCK_DESC'))
327
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE_REMOTE_REQUIRED'))
328
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
329
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
330
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
331
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
332
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
333
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
246
334
  .action(actionWrapper('force-unlock', async (lockId, { file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
247
335
  await (0, forceUnlock_1.forceUnlockCommand)(lockId, {
248
336
  location: file,
@@ -66,6 +66,7 @@ const loginWithKey = async (apiKey, consoleUrl) => {
66
66
  consoleUrl,
67
67
  orgId: result.orgId,
68
68
  orgName: result.orgName,
69
+ orgSlug: result.orgSlug,
69
70
  userEmail: result.userEmail,
70
71
  });
71
72
  common_1.logger.info(lang_1.lang.__('LOGIN_SUCCESS_KEY', { orgName: result.orgName }));
@@ -122,7 +123,17 @@ const loginWithBrowser = async (consoleUrl) => {
122
123
  const orgId = url.searchParams.get('org_id') || '';
123
124
  const orgName = url.searchParams.get('org_name') || '';
124
125
  const userEmail = url.searchParams.get('user_email') || '';
125
- (0, credentialStore_1.saveCredentials)({ apiKey, consoleUrl, orgId, orgName, userEmail });
126
+ // The authorize callback doesn't carry the org slug; fetch the full
127
+ // identity once so the yml `org:` cross-check works out of the box.
128
+ // Degrade to the callback params if the validate roundtrip fails.
129
+ let orgSlug;
130
+ try {
131
+ orgSlug = (await (0, apiClient_1.validateApiKey)(apiKey, consoleUrl)).orgSlug;
132
+ }
133
+ catch {
134
+ orgSlug = undefined;
135
+ }
136
+ (0, credentialStore_1.saveCredentials)({ apiKey, consoleUrl, orgId, orgName, orgSlug, userEmail });
126
137
  common_1.logger.info(lang_1.lang.__('LOGIN_SUCCESS', { userEmail, orgName }));
127
138
  resolve(true);
128
139
  }