@geek-fun/serverlessinsight 0.8.9 → 0.9.1

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 (102) 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 +123 -0
  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-volc-app-insight-volc.json.backup +2 -2
  8. package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +93 -0
  9. package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +148 -0
  10. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
  11. package/CHANGELOG.md +29 -0
  12. package/README.md +2 -2
  13. package/README.zh-CN.md +2 -2
  14. package/dist/package.json +2 -2
  15. package/dist/src/commands/deploy.js +12 -4
  16. package/dist/src/commands/destroy.js +8 -2
  17. package/dist/src/commands/forceUnlock.js +5 -5
  18. package/dist/src/commands/index.js +114 -53
  19. package/dist/src/commands/login.js +12 -1
  20. package/dist/src/commands/migrate.js +287 -0
  21. package/dist/src/commands/plan.js +7 -1
  22. package/dist/src/commands/show.js +37 -25
  23. package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
  24. package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
  25. package/dist/src/common/aliyunClient/fc3Operations.js +12 -3
  26. package/dist/src/common/aliyunClient/nasOperations.js +4 -3
  27. package/dist/src/common/aliyunClient/ossOperations.js +52 -8
  28. package/dist/src/common/aliyunClient/slsOperations.js +3 -2
  29. package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
  30. package/dist/src/common/apiClient.js +22 -5
  31. package/dist/src/common/context.js +5 -4
  32. package/dist/src/common/lockManager.js +1 -1
  33. package/dist/src/common/migrationMarker.js +34 -0
  34. package/dist/src/common/nameBuilder.js +13 -1
  35. package/dist/src/common/planCompare.js +31 -1
  36. package/dist/src/common/planFormatter.js +69 -54
  37. package/dist/src/common/refreshPlanner.js +31 -8
  38. package/dist/src/common/runtimeMapper.js +7 -3
  39. package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
  40. package/dist/src/common/stateBackend/index.js +5 -2
  41. package/dist/src/common/stateBackend/localStateBackend.js +8 -2
  42. package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
  43. package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
  44. package/dist/src/common/stateBackend/saasStateBackend.js +83 -5
  45. package/dist/src/common/stateManager.js +56 -5
  46. package/dist/src/common/tencentClient/cosOperations.js +1 -1
  47. package/dist/src/common/tencentClient/scfOperations.js +2 -1
  48. package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
  49. package/dist/src/common/volcengineClient/index.js +6 -2
  50. package/dist/src/common/volcengineClient/vefaasOperations.js +3 -3
  51. package/dist/src/lang/en.js +231 -7
  52. package/dist/src/lang/zh-CN.js +230 -7
  53. package/dist/src/parser/index.js +1 -1
  54. package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
  55. package/dist/src/stack/aliyunStack/apigwPlanner.js +26 -5
  56. package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
  57. package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
  58. package/dist/src/stack/aliyunStack/databasePlanner.js +8 -3
  59. package/dist/src/stack/aliyunStack/databaseResource.js +28 -12
  60. package/dist/src/stack/aliyunStack/deployer.js +30 -13
  61. package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
  62. package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
  63. package/dist/src/stack/aliyunStack/fc3Planner.js +46 -25
  64. package/dist/src/stack/aliyunStack/fc3Resource.js +80 -31
  65. package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
  66. package/dist/src/stack/aliyunStack/ossPlanner.js +6 -1
  67. package/dist/src/stack/aliyunStack/ossResource.js +14 -3
  68. package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
  69. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
  70. package/dist/src/stack/aliyunStack/tablestorePlanner.js +2 -1
  71. package/dist/src/stack/aliyunStack/tablestoreResource.js +5 -4
  72. package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
  73. package/dist/src/stack/deploy.js +12 -7
  74. package/dist/src/stack/localStack/functionRunner.js +5 -4
  75. package/dist/src/stack/scfStack/cosExecutor.js +2 -2
  76. package/dist/src/stack/scfStack/cosPlanner.js +6 -1
  77. package/dist/src/stack/scfStack/cosResource.js +8 -4
  78. package/dist/src/stack/scfStack/deployer.js +21 -6
  79. package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
  80. package/dist/src/stack/scfStack/esServerlessPlanner.js +6 -1
  81. package/dist/src/stack/scfStack/esServerlessResource.js +12 -4
  82. package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
  83. package/dist/src/stack/scfStack/scfExecutor.js +2 -2
  84. package/dist/src/stack/scfStack/scfPlanner.js +26 -27
  85. package/dist/src/stack/scfStack/scfResource.js +38 -13
  86. package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
  87. package/dist/src/stack/scfStack/tdsqlcPlanner.js +6 -1
  88. package/dist/src/stack/scfStack/tdsqlcResource.js +12 -4
  89. package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
  90. package/dist/src/stack/volcengineStack/apigwPlanner.js +5 -1
  91. package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
  92. package/dist/src/stack/volcengineStack/deployer.js +15 -4
  93. package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
  94. package/dist/src/stack/volcengineStack/tosPlanner.js +6 -1
  95. package/dist/src/stack/volcengineStack/tosResource.js +11 -4
  96. package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
  97. package/dist/src/stack/volcengineStack/vefaasPlanner.js +39 -11
  98. package/dist/src/stack/volcengineStack/vefaasResource.js +11 -3
  99. package/dist/src/validator/rootSchema.js +29 -2
  100. package/dist/src/validator/semanticValidation.js +24 -0
  101. package/dist/tsconfig.tsbuildinfo +1 -1
  102. package/package.json +2 -2
@@ -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
  }
@@ -13,6 +13,7 @@ const show_1 = require("./show");
13
13
  const login_1 = require("./login");
14
14
  const logout_1 = require("./logout");
15
15
  const whoami_1 = require("./whoami");
16
+ const migrate_1 = require("./migrate");
16
17
  const lang_1 = require("../lang");
17
18
  const parser_1 = require("../parser");
18
19
  const MAX_ERROR_MESSAGE_LENGTH = 2000;
@@ -66,31 +67,31 @@ const actionWrapper = (commandName, handler) => {
66
67
  };
67
68
  };
68
69
  const program = new commander_1.Command();
69
- program.name('si').description('CLI for ServerlessInsight').version((0, common_1.getVersion)());
70
+ program.name('si').description(lang_1.lang.__('CMD_ROOT_DESC')).version((0, common_1.getVersion)());
70
71
  program
71
72
  .command('login')
72
- .description('authenticate with ServerlessInsight Console')
73
- .option('--si-api-key <key>', 'authenticate with an existing API key')
73
+ .description(lang_1.lang.__('CMD_LOGIN_DESC'))
74
+ .option('--si-api-key <key>', lang_1.lang.__('OPT_SI_API_KEY_EXISTING'))
74
75
  .action(actionWrapper('login', async ({ siApiKey }) => {
75
76
  await (0, login_1.login)({ siApiKey });
76
77
  }));
77
78
  program
78
79
  .command('logout')
79
- .description('revoke API key and clear local credentials')
80
+ .description(lang_1.lang.__('CMD_LOGOUT_DESC'))
80
81
  .action(actionWrapper('logout', async () => {
81
82
  await (0, logout_1.logout)();
82
83
  }));
83
84
  program
84
85
  .command('whoami')
85
- .description('show current login status')
86
+ .description(lang_1.lang.__('CMD_WHOAMI_DESC'))
86
87
  .action(actionWrapper('whoami', async () => {
87
88
  await (0, whoami_1.whoami)();
88
89
  }));
89
90
  program
90
91
  .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')
92
+ .description(lang_1.lang.__('CMD_SHOW_DESC'))
93
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
94
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
94
95
  .action(actionWrapper('show', async ({ file, stage }) => {
95
96
  const iacLocation = (0, common_1.getIacLocation)(file);
96
97
  const rawIac = (0, parser_1.parseYaml)(iacLocation);
@@ -109,24 +110,24 @@ program
109
110
  }));
110
111
  program
111
112
  .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')
113
+ .description(lang_1.lang.__('CMD_VALIDATE_DESC'))
114
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
115
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
115
116
  .action(actionWrapper('validate', async ({ file, stage }) => {
116
117
  common_1.logger.debug(lang_1.lang.__('LOG_COMMAND_INFO'));
117
118
  await (0, validate_1.validate)({ stage, location: file });
118
119
  }));
119
120
  program
120
121
  .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)')
122
+ .description(lang_1.lang.__('CMD_PLAN_DESC'))
123
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
124
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
125
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
126
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
127
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
128
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
129
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
130
+ .option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
130
131
  .action(actionWrapper('plan', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, }) => {
131
132
  await (0, plan_1.plan)({
132
133
  stage,
@@ -139,20 +140,45 @@ program
139
140
  refresh,
140
141
  });
141
142
  }));
143
+ // Issue #246: `diff` is the primary verb users say — it runs the same plan
144
+ // flow; `plan` stays for compatibility.
145
+ program
146
+ .command('diff')
147
+ .description(lang_1.lang.__('CMD_DIFF_DESC'))
148
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
149
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
150
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
151
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
152
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
153
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
154
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
155
+ .option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
156
+ .action(actionWrapper('diff', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, }) => {
157
+ await (0, plan_1.plan)({
158
+ stage,
159
+ location: file,
160
+ region,
161
+ provider,
162
+ accessKeyId,
163
+ accessKeySecret,
164
+ securityToken,
165
+ refresh,
166
+ });
167
+ }));
142
168
  program
143
169
  .command('deploy')
144
- .description('deploy serverless Iac yaml')
145
- .option('-f, --file <path>', 'specify the yaml file')
146
- .option('-s, --stage <stage>', 'specify the stage')
147
- .option('-r, --region <region>', 'specify the region')
148
- .option('-v, --provider <provider>', 'specify the provider')
149
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
150
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
151
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
152
- .option('--si-api-key <key>', 'ServerlessInsight API key (overrides SI_API_KEY env)')
153
- .option('-y, --auto-approve', 'skip interactive approval of plan before deploying')
154
- .option('--no-refresh', 'skip live cloud probing; diff config against state only (no drift detection)')
155
- .option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
170
+ .description(lang_1.lang.__('CMD_DEPLOY_DESC'))
171
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
172
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
173
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
174
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
175
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
176
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
177
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
178
+ .option('--si-api-key <key>', lang_1.lang.__('OPT_SI_API_KEY'))
179
+ .option('-y, --auto-approve', lang_1.lang.__('OPT_AUTO_APPROVE'))
180
+ .option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
181
+ .option('-p, --parameter <key=value>', lang_1.lang.__('OPT_PARAMETER'), (value, previous) => {
156
182
  const [key, val] = value.split('=');
157
183
  previous[key] = val;
158
184
  return previous;
@@ -172,16 +198,51 @@ program
172
198
  refresh,
173
199
  });
174
200
  }));
201
+ program
202
+ .command('migrate')
203
+ .description(lang_1.lang.__('CMD_MIGRATE_DESC'))
204
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
205
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
206
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
207
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
208
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
209
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
210
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
211
+ .option('--si-api-key <key>', lang_1.lang.__('OPT_SI_API_KEY'))
212
+ .option('-y, --auto-approve', lang_1.lang.__('OPT_AUTO_APPROVE'))
213
+ .option('--force', lang_1.lang.__('OPT_FORCE'))
214
+ .option('--no-marker', lang_1.lang.__('OPT_NO_MARKER'))
215
+ .option('--dry-run', lang_1.lang.__('OPT_DRY_RUN'))
216
+ .option('--rollback', lang_1.lang.__('OPT_ROLLBACK'))
217
+ .action(actionWrapper('migrate', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, siApiKey, autoApprove, force, marker, dryRun, rollback, }) => {
218
+ await (0, migrate_1.migrate)({
219
+ stage,
220
+ location: file,
221
+ region,
222
+ provider,
223
+ accessKeyId,
224
+ accessKeySecret,
225
+ securityToken,
226
+ siApiKey,
227
+ autoApprove,
228
+ force,
229
+ // Commander models `--no-marker` as the negation of an implicit
230
+ // `marker` boolean (default true).
231
+ noMarker: marker === false,
232
+ dryRun,
233
+ rollback,
234
+ });
235
+ }));
175
236
  program
176
237
  .command('destroy')
177
- .option('-f, --file <path>', 'specify the yaml file')
178
- .option('-s, --stage <stage>', 'specify the stage')
179
- .option('-r, --region <region>', 'specify the region')
180
- .option('-v, --provider <provider>', 'specify the provider')
181
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
182
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
183
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
184
- .description('destroy serverless stack')
238
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
239
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
240
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
241
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
242
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
243
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
244
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
245
+ .description(lang_1.lang.__('CMD_DESTROY_DESC'))
185
246
  .action(actionWrapper('destroy', async ({ file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
186
247
  await (0, destroy_1.destroyStack)({
187
248
  location: file,
@@ -195,11 +256,11 @@ program
195
256
  }));
196
257
  program
197
258
  .command('local')
198
- .description('run Serverless application locally for debugging')
199
- .option('-f, --file <path>', 'specify the yaml file')
200
- .option('-s, --stage <stage>', 'specify the stage', 'default')
201
- .option('-d, --debug', 'enable debug mode')
202
- .option('-w, --watch', 'enable file watch', true)
259
+ .description(lang_1.lang.__('CMD_LOCAL_DESC'))
260
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
261
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'), 'default')
262
+ .option('-d, --debug', lang_1.lang.__('OPT_DEBUG'))
263
+ .option('-w, --watch', lang_1.lang.__('OPT_WATCH'), true)
203
264
  .action(actionWrapper('local', async ({ stage, debug, watch, file }) => {
204
265
  await (0, local_1.runLocal)({
205
266
  stage,
@@ -210,14 +271,14 @@ program
210
271
  }));
211
272
  program
212
273
  .command('force-unlock <lockId>')
213
- .description('manually remove a stuck lock (use with caution)')
214
- .option('-f, --file <path>', 'specify the yaml file (required for remote backends)')
215
- .option('-s, --stage <stage>', 'specify the stage')
216
- .option('-r, --region <region>', 'specify the region')
217
- .option('-v, --provider <provider>', 'specify the provider')
218
- .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
219
- .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
220
- .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
274
+ .description(lang_1.lang.__('CMD_FORCE_UNLOCK_DESC'))
275
+ .option('-f, --file <path>', lang_1.lang.__('OPT_FILE_REMOTE_REQUIRED'))
276
+ .option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
277
+ .option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
278
+ .option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
279
+ .option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
280
+ .option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
281
+ .option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
221
282
  .action(actionWrapper('force-unlock', async (lockId, { file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
222
283
  await (0, forceUnlock_1.forceUnlockCommand)(lockId, {
223
284
  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
  }
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.migrate = void 0;
40
+ const readline = __importStar(require("node:readline"));
41
+ const node_crypto_1 = __importDefault(require("node:crypto"));
42
+ const common_1 = require("../common");
43
+ const stateBackend_1 = require("../common/stateBackend");
44
+ const credentialStore_1 = require("../common/credentialStore");
45
+ const apiClient_1 = require("../common/apiClient");
46
+ const migrationMarker_1 = require("../common/migrationMarker");
47
+ const types_1 = require("../types");
48
+ const parser_1 = require("../parser");
49
+ const lang_1 = require("../lang");
50
+ const askConfirmation = async (message) => {
51
+ if (!process.stdin.isTTY) {
52
+ throw new Error(lang_1.lang.__('CONFIRMATION_STDIN_NOT_TTY'));
53
+ }
54
+ const rl = readline.createInterface({
55
+ input: process.stdin,
56
+ output: process.stdout,
57
+ });
58
+ return new Promise((resolve) => {
59
+ rl.question(message, (answer) => {
60
+ rl.close();
61
+ resolve(answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y');
62
+ });
63
+ });
64
+ };
65
+ /**
66
+ * `si migrate` — one-time migration of a legacy (local/bucket) state to the
67
+ * Console. docs/state-migration-saas.md §4.2:
68
+ * preflight → source lock → pull/validate → plan → confirm → upload
69
+ * → read-back verify → backfill console UUIDs + write marker → unlock.
70
+ * The marker (managedBy=saas) is a new persisted version of the source state
71
+ * that closes the legacy backend for mutations (decision D-4). Every step is
72
+ * re-runnable: uploads dedupe by contentHash and the marker is only written
73
+ * after verification passes.
74
+ */
75
+ const migrate = async (options) => {
76
+ common_1.logger.info(lang_1.lang.__('VALIDATING_YAML'));
77
+ const iacLocation = (0, common_1.getIacLocation)(options.location);
78
+ const rawIac = (0, parser_1.parseYaml)(iacLocation);
79
+ common_1.logger.info(lang_1.lang.__('YAML_VALID'));
80
+ await (0, common_1.setContext)({
81
+ ...options,
82
+ app: rawIac.app,
83
+ service: rawIac.service,
84
+ iacProvider: rawIac.provider,
85
+ stages: rawIac.stages,
86
+ },
87
+ // No live cloud probing: migrate only touches the state stores. This also
88
+ // lets --rollback and local-backend runs work without cloud credentials.
89
+ false);
90
+ const context = (0, common_1.getContext)();
91
+ const iac = (0, parser_1.revalYaml)(iacLocation, context);
92
+ (0, common_1.setIac)(iac);
93
+ // ① preflight — the source must be a legacy backend with actual state
94
+ const backendType = iac.backend?.type ?? types_1.StateBackendType.SAAS;
95
+ if (backendType !== types_1.StateBackendType.LOCAL && backendType !== types_1.StateBackendType.BUCKET_STORE) {
96
+ throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
97
+ }
98
+ // Marker checks stay OFF on the source backend: si migrate must be able to
99
+ // read a marked state (idempotent re-runs, --rollback).
100
+ const sourceBackend = (0, stateBackend_1.createStateBackend)(iac.backend, { ...context, siApiKey: options.siApiKey });
101
+ // --rollback: the explicit undo — clear the marker, legacy path reopens.
102
+ // Purely local to the source backend, so it needs NO Console credentials.
103
+ if (options.rollback) {
104
+ await sourceBackend.withLock('migrate-rollback', async () => {
105
+ const state = await sourceBackend.loadState(iac.provider.name, iac.app, iac.service, options.stage ?? 'default');
106
+ if (!(0, migrationMarker_1.isMigratedToSaas)(state)) {
107
+ common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_NO_MARKER'));
108
+ return;
109
+ }
110
+ if (!sourceBackend.patchPersisted) {
111
+ throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
112
+ }
113
+ await sourceBackend.patchPersisted({ managedBy: undefined });
114
+ common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_DONE'));
115
+ common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_DONE_HINT'));
116
+ });
117
+ return;
118
+ }
119
+ const creds = (0, credentialStore_1.loadCredentials)();
120
+ const apiKey = options.siApiKey ?? creds?.apiKey;
121
+ if (!apiKey) {
122
+ throw new Error(lang_1.lang.__('MIGRATE_NEED_CREDENTIALS'));
123
+ }
124
+ const baseUrl = (0, credentialStore_1.getConsoleUrl)();
125
+ const identity = await (0, apiClient_1.validateApiKey)(apiKey, baseUrl);
126
+ const orgId = identity.orgId;
127
+ common_1.logger.info(lang_1.lang.__('MIGRATE_PREFLIGHT_OK', { orgName: identity.orgName, orgId }));
128
+ const client = (0, apiClient_1.createApiClient)({ apiKey, baseUrl, orgId });
129
+ await sourceBackend.withLock('migrate', async () => {
130
+ // ③ pull + normalize (loadState applies registered state migrations)
131
+ const hydrateStage = options.stage ?? Object.keys(iac.stages ?? {})[0] ?? 'default';
132
+ const state = await sourceBackend.loadState(iac.provider.name, iac.app, iac.service, hydrateStage);
133
+ if ((0, migrationMarker_1.isMigratedToSaas)(state)) {
134
+ common_1.logger.warn(lang_1.lang.__('MIGRATE_ALREADY_MARKED'));
135
+ }
136
+ if (state.provider && state.provider !== iac.provider.name) {
137
+ throw new Error(lang_1.lang.__('MIGRATE_PROVIDER_MISMATCH', {
138
+ stateProvider: state.provider,
139
+ ymlProvider: iac.provider.name,
140
+ }));
141
+ }
142
+ // ④ mapping plan — only stages holding deployed resources migrate
143
+ const allStageKeys = Object.keys(state.stages ?? {});
144
+ if (options.stage && !allStageKeys.includes(options.stage)) {
145
+ throw new Error(lang_1.lang.__('MIGRATE_STAGE_NOT_FOUND', { stage: options.stage }));
146
+ }
147
+ const stageKeys = (options.stage ? [options.stage] : allStageKeys).filter((stageKey) => Object.keys(state.stages?.[stageKey]?.resources ?? {}).length > 0);
148
+ if (stageKeys.length === 0) {
149
+ throw new Error(lang_1.lang.__('MIGRATE_NOTHING_TO_MIGRATE'));
150
+ }
151
+ // ④ mapping plan — resolve which Console targets already exist (mapped by
152
+ // name) and which would be auto-created, so the dry-run/confirm screen
153
+ // keeps the user in control of the destination (pre-create in Console to
154
+ // adopt existing apps/services/membership settings).
155
+ const targets = await client.get(`/api/v1/state/migrate/targets?app_name=${encodeURIComponent(iac.app)}&service_name=${encodeURIComponent(iac.service)}&stages=${encodeURIComponent(stageKeys.join(','))}`);
156
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGETS_HEADER', { orgName: identity.orgName }));
157
+ if (targets.app.exists) {
158
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_APP_EXISTS', {
159
+ app: targets.app.name,
160
+ appId: targets.app.id ?? '',
161
+ }));
162
+ }
163
+ else {
164
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_APP_CREATE', { app: targets.app.name }));
165
+ }
166
+ if (targets.service.exists) {
167
+ if (targets.service.provider && targets.service.provider !== iac.provider.name) {
168
+ throw new Error(lang_1.lang.__('MIGRATE_PROVIDER_MISMATCH_TARGET', {
169
+ service: iac.service,
170
+ existingProvider: targets.service.provider,
171
+ ymlProvider: iac.provider.name,
172
+ }));
173
+ }
174
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_SERVICE_EXISTS', {
175
+ service: targets.service.name,
176
+ serviceId: targets.service.id ?? '',
177
+ provider: targets.service.provider ?? '',
178
+ }));
179
+ }
180
+ else {
181
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_SERVICE_CREATE', {
182
+ service: targets.service.name,
183
+ provider: iac.provider.name,
184
+ }));
185
+ }
186
+ for (const stageKey of stageKeys) {
187
+ const count = String(Object.keys(state.stages?.[stageKey]?.resources ?? {}).length);
188
+ const report = targets.stages.find((s) => s.name === stageKey);
189
+ if (report?.hasState) {
190
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_STAGE_EXISTS', {
191
+ stage: stageKey,
192
+ count,
193
+ version: String(report.latestVersion ?? 1),
194
+ }));
195
+ }
196
+ else if (report?.registered) {
197
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_STAGE_EMPTY', { stage: stageKey, count }));
198
+ }
199
+ else {
200
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_STAGE_NEW', { stage: stageKey, count }));
201
+ }
202
+ }
203
+ common_1.logger.info(lang_1.lang.__('MIGRATE_TARGETS_HINT'));
204
+ if (options.dryRun) {
205
+ common_1.logger.info(lang_1.lang.__('MIGRATE_DRY_RUN_NOTICE'));
206
+ return;
207
+ }
208
+ // ⑤ confirm — the writer-upgrade question is the §4.5 runbook gate
209
+ if (!options.autoApprove) {
210
+ if (!(await askConfirmation(lang_1.lang.__('MIGRATE_WRITER_CONFIRMATION')))) {
211
+ return;
212
+ }
213
+ if (!(await askConfirmation(lang_1.lang.__('MIGRATE_CONFIRMATION')))) {
214
+ return;
215
+ }
216
+ }
217
+ // ⑥ upload — same full-persisted-state contract as the SaaS backend save.
218
+ // The imported version carries the owning org id immediately (D-6 identity
219
+ // anchor), so the first post-cutover loadState can verify it without
220
+ // waiting for a fresh deploy save.
221
+ const persisted = { ...(0, common_1.toPersistedState)(state), orgId };
222
+ const contentHash = node_crypto_1.default.createHash('sha256').update(JSON.stringify(persisted)).digest('hex');
223
+ const results = [];
224
+ for (const stageKey of stageKeys) {
225
+ common_1.logger.info(lang_1.lang.__('MIGRATE_UPLOADING', { stage: stageKey }));
226
+ const resourceCount = Object.keys(state.stages?.[stageKey]?.resources ?? {}).length;
227
+ let uploadResult;
228
+ try {
229
+ uploadResult = await client.post('/api/v1/state/migrate', {
230
+ appName: iac.app,
231
+ serviceName: iac.service,
232
+ provider: iac.provider.name,
233
+ stage: stageKey,
234
+ stateJson: persisted,
235
+ contentHash,
236
+ resourceCount,
237
+ origin: backendType === types_1.StateBackendType.LOCAL ? 'local' : 'bucket',
238
+ conflict: options.force ? 'overwrite' : 'reject',
239
+ });
240
+ }
241
+ catch (error) {
242
+ if (error instanceof apiClient_1.ApiError && error.status === 409) {
243
+ throw new Error(lang_1.lang.__('MIGRATE_CONFLICT'), { cause: error });
244
+ }
245
+ throw error;
246
+ }
247
+ // ⑦ read-back verification — the stored version must be ours. The server
248
+ // echoes the hash it stored, so no JSON re-serialization is involved
249
+ // (Postgres jsonb would reorder keys and break a naive string compare).
250
+ const remote = await client.get(`/api/v1/apps/${uploadResult.appId}/services/${uploadResult.serviceId}/state/current?stage=${encodeURIComponent(stageKey)}`);
251
+ const verified = remote.contentHash === contentHash &&
252
+ remote.versionNumber === uploadResult.versionNumber &&
253
+ (uploadResult.deduped || remote.resourceCount === resourceCount);
254
+ if (!verified) {
255
+ throw new Error(lang_1.lang.__('MIGRATE_VERIFY_FAILED', { stage: stageKey }));
256
+ }
257
+ results.push({ stage: stageKey, ...uploadResult });
258
+ common_1.logger.info(lang_1.lang.__('MIGRATE_UPLOADED', {
259
+ stage: stageKey,
260
+ version: String(uploadResult.versionNumber),
261
+ deduped: uploadResult.deduped ? lang_1.lang.__('MIGRATE_UPLOADED_DEDUPLICATED') : '',
262
+ appId: uploadResult.appId,
263
+ serviceId: uploadResult.serviceId,
264
+ }));
265
+ }
266
+ // ⑧⑨ backfill console UUIDs + write the migration marker as one new
267
+ // persisted version. Only reached when every stage verified.
268
+ const first = results[0];
269
+ if (options.noMarker) {
270
+ common_1.logger.warn(lang_1.lang.__('MIGRATE_MARKER_SKIPPED'));
271
+ }
272
+ else {
273
+ if (!sourceBackend.patchPersisted) {
274
+ throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
275
+ }
276
+ await sourceBackend.patchPersisted({
277
+ orgId,
278
+ appId: first.appId,
279
+ serviceId: first.serviceId,
280
+ managedBy: 'saas',
281
+ });
282
+ common_1.logger.info(lang_1.lang.__('MIGRATE_MARKER_WRITTEN'));
283
+ }
284
+ common_1.logger.info(lang_1.lang.__('MIGRATE_CUTOVER_STEPS'));
285
+ });
286
+ };
287
+ exports.migrate = migrate;
@@ -28,7 +28,13 @@ const plan = async (options) => {
28
28
  ? lang_1.lang.__('PROVIDER_ALIYUN')
29
29
  : lang_1.lang.__('PROVIDER_TENCENT');
30
30
  common_1.logger.info(lang_1.lang.__('GENERATING_PLAN_FOR_PROVIDER', { provider: providerDisplayName }));
31
- const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
31
+ // Read-only command: a migrated state only warns here (window-period
32
+ // reconciliation still needs plan against the legacy copy).
33
+ const backend = (0, stateBackend_1.createStateBackend)(iac.backend, {
34
+ ...context,
35
+ declaredOrg: iac.org,
36
+ migrationMarker: 'warn',
37
+ });
32
38
  let planResult;
33
39
  if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
34
40
  planResult = await (0, scfStack_1.generateTencentPlan)(iac, backend);