@geek-fun/serverlessinsight 0.9.0 → 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 (82) 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-volc-app-insight-volc.json.backup +2 -2
  8. package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
  9. package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +2 -2
  10. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
  11. package/README.md +2 -2
  12. package/README.zh-CN.md +2 -2
  13. package/dist/package.json +2 -2
  14. package/dist/src/commands/deploy.js +9 -3
  15. package/dist/src/commands/destroy.js +8 -2
  16. package/dist/src/commands/forceUnlock.js +5 -5
  17. package/dist/src/commands/index.js +98 -62
  18. package/dist/src/commands/login.js +12 -1
  19. package/dist/src/commands/migrate.js +287 -0
  20. package/dist/src/commands/plan.js +7 -1
  21. package/dist/src/commands/show.js +37 -25
  22. package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
  23. package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
  24. package/dist/src/common/aliyunClient/fc3Operations.js +7 -3
  25. package/dist/src/common/aliyunClient/nasOperations.js +4 -3
  26. package/dist/src/common/aliyunClient/ossOperations.js +52 -8
  27. package/dist/src/common/aliyunClient/slsOperations.js +3 -2
  28. package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
  29. package/dist/src/common/apiClient.js +22 -5
  30. package/dist/src/common/context.js +5 -4
  31. package/dist/src/common/lockManager.js +1 -1
  32. package/dist/src/common/migrationMarker.js +34 -0
  33. package/dist/src/common/runtimeMapper.js +7 -3
  34. package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
  35. package/dist/src/common/stateBackend/index.js +5 -2
  36. package/dist/src/common/stateBackend/localStateBackend.js +8 -2
  37. package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
  38. package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
  39. package/dist/src/common/stateBackend/saasStateBackend.js +83 -5
  40. package/dist/src/common/stateManager.js +56 -5
  41. package/dist/src/common/tencentClient/cosOperations.js +1 -1
  42. package/dist/src/common/tencentClient/scfOperations.js +2 -1
  43. package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
  44. package/dist/src/common/volcengineClient/index.js +6 -2
  45. package/dist/src/common/volcengineClient/vefaasOperations.js +3 -3
  46. package/dist/src/lang/en.js +211 -1
  47. package/dist/src/lang/zh-CN.js +210 -1
  48. package/dist/src/parser/index.js +1 -1
  49. package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
  50. package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
  51. package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
  52. package/dist/src/stack/aliyunStack/databasePlanner.js +2 -2
  53. package/dist/src/stack/aliyunStack/databaseResource.js +18 -10
  54. package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
  55. package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
  56. package/dist/src/stack/aliyunStack/fc3Resource.js +31 -11
  57. package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
  58. package/dist/src/stack/aliyunStack/ossResource.js +5 -1
  59. package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
  60. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
  61. package/dist/src/stack/aliyunStack/tablestoreResource.js +3 -3
  62. package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
  63. package/dist/src/stack/deploy.js +2 -3
  64. package/dist/src/stack/localStack/functionRunner.js +5 -4
  65. package/dist/src/stack/scfStack/cosExecutor.js +2 -2
  66. package/dist/src/stack/scfStack/cosResource.js +2 -2
  67. package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
  68. package/dist/src/stack/scfStack/esServerlessResource.js +7 -3
  69. package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
  70. package/dist/src/stack/scfStack/scfExecutor.js +2 -2
  71. package/dist/src/stack/scfStack/scfResource.js +32 -11
  72. package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
  73. package/dist/src/stack/scfStack/tdsqlcResource.js +7 -3
  74. package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
  75. package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
  76. package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
  77. package/dist/src/stack/volcengineStack/tosResource.js +1 -1
  78. package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
  79. package/dist/src/stack/volcengineStack/vefaasResource.js +6 -2
  80. package/dist/src/validator/rootSchema.js +29 -2
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +2 -2
@@ -37,6 +37,7 @@ exports.createNasOperations = void 0;
37
37
  const logger_1 = require("../logger");
38
38
  const nas = __importStar(require("@alicloud/nas20170626"));
39
39
  const types_1 = require("../../types");
40
+ const lang_1 = require("../../lang");
40
41
  const storageClassMap = {
41
42
  [types_1.NasStorageClassEnum.STANDARD_CAPACITY]: { fileSystemType: 'standard', storageType: 'Capacity' },
42
43
  [types_1.NasStorageClassEnum.STANDARD_PERFORMANCE]: {
@@ -117,7 +118,7 @@ const createNasOperations = (nasClient) => {
117
118
  const response = await nasClient.createFileSystem(request);
118
119
  const fileSystemId = response.body?.fileSystemId;
119
120
  if (!fileSystemId) {
120
- throw new Error('Failed to create NAS file system');
121
+ throw new Error(lang_1.lang.__('NAS_CREATE_FS_FAILED'));
121
122
  }
122
123
  // Wait for file system to be ready
123
124
  let retries = 0;
@@ -185,7 +186,7 @@ const createNasOperations = (nasClient) => {
185
186
  const response = await nasClient.createMountTarget(request);
186
187
  const mountTargetDomain = response.body?.mountTargetDomain;
187
188
  if (!mountTargetDomain) {
188
- throw new Error('Failed to create NAS mount target');
189
+ throw new Error(lang_1.lang.__('NAS_CREATE_MOUNT_TARGET_FAILED'));
189
190
  }
190
191
  // Wait for mount target to be ready
191
192
  let retries = 0;
@@ -221,7 +222,7 @@ const createNasOperations = (nasClient) => {
221
222
  }));
222
223
  }
223
224
  catch (error) {
224
- logger_1.logger.debug(`Failed to list mount targets: ${String(error)}`);
225
+ logger_1.logger.debug(lang_1.lang.__('NAS_LIST_MOUNT_TARGETS_FAILED', { error: String(error) }));
225
226
  return [];
226
227
  }
227
228
  },
@@ -126,6 +126,41 @@ const parseReplicationRules = (xml) => {
126
126
  expireTime: parsed.expireTime || '',
127
127
  };
128
128
  };
129
+ // ListCname (GET /?cname) → the CNAME entries bound to THIS bucket with their
130
+ // certificate info. Used to verify desired state after a 409 CnameAlreadyExists,
131
+ // since that error only means "bound elsewhere or image-processing domain"
132
+ // per the PutCname docs — it never guarantees the bind landed on this bucket.
133
+ const listBucketCnames = async (bucketName) => {
134
+ useBucket(bucketName);
135
+ const response = await ossRequest(ossClient, {
136
+ method: 'GET',
137
+ bucket: bucketName,
138
+ subres: { cname: '' },
139
+ successStatuses: [200],
140
+ });
141
+ const xml = response.data || '';
142
+ const entries = [];
143
+ const cnameRegex = /<Cname>([\s\S]*?)<\/Cname>/g;
144
+ let match;
145
+ while ((match = cnameRegex.exec(xml)) !== null) {
146
+ const cnameXml = match[1];
147
+ const read = (tag) => {
148
+ const m = new RegExp(`<${tag}>([\\s\\S]*?)<\\/${tag}>`).exec(cnameXml);
149
+ return m ? m[1].trim() : undefined;
150
+ };
151
+ const hasCertificate = /<Certificate>[\s\S]*?<\/Certificate>/.test(cnameXml);
152
+ entries.push({
153
+ domain: read('Domain') ?? '',
154
+ status: read('Status') ?? '',
155
+ certBound: hasCertificate,
156
+ });
157
+ }
158
+ return entries;
159
+ };
160
+ const verifyCnameBoundToBucket = async (bucketName, domain) => {
161
+ const entries = await listBucketCnames(bucketName);
162
+ return entries.some((entry) => entry.domain === domain && (entry.status === 'Enabled' || entry.status === ''));
163
+ };
129
164
  const putBucketCname = async (bucketName, domain, certificate) => {
130
165
  useBucket(bucketName);
131
166
  const certXml = buildCertificateXml(certificate);
@@ -149,24 +184,33 @@ const parseReplicationRules = (xml) => {
149
184
  };
150
185
  await ossClient.request(params);
151
186
  logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CNAME_BOUND', { domain }));
152
- return { success: true, needVerification: false };
187
+ return { success: true, needVerification: false, certBound: Boolean(certificate) };
153
188
  }
154
189
  catch (error) {
155
190
  const err = error;
156
191
  if (err.code === 'CnameAlreadyExists' || err.status === 409) {
157
- logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CNAME_EXISTS', { domain }));
158
- return { success: true, needVerification: false };
192
+ // Per the PutCname docs, 409 CnameAlreadyExists fires when the domain is
193
+ // bound to ANOTHER bucket (or is an image-processing domain) — a rebind
194
+ // to the same bucket is idempotent 200. So never trust the 409 alone:
195
+ // cross-check via ListCname whether the domain is actually bound here.
196
+ const boundToThisBucket = await verifyCnameBoundToBucket(bucketName, domain);
197
+ if (boundToThisBucket) {
198
+ logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CNAME_EXISTS', { domain }));
199
+ return { success: true, needVerification: false, certBound: false };
200
+ }
201
+ // eslint-disable-next-line preserve-caught-error
202
+ throw new Error(lang_1.lang.__('OSS_BUCKET_CNAME_CONFLICT', { domain, bucketName, error: String(error) }));
159
203
  }
160
204
  if (err.code === 'NeedVerifyDomainOwnership') {
161
205
  logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_CNAME_NEED_VERIFY', { domain }));
162
- return { success: false, needVerification: true };
206
+ return { success: false, needVerification: true, certBound: false };
163
207
  }
164
208
  if (certificate) {
165
209
  // eslint-disable-next-line preserve-caught-error
166
210
  throw new Error(lang_1.lang.__('OSS_BUCKET_CNAME_BIND_FAILED', { error: String(error) }));
167
211
  }
168
212
  logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_CNAME_BIND_FAILED', { error: String(error) }));
169
- return { success: false, needVerification: false };
213
+ return { success: false, needVerification: false, certBound: false };
170
214
  }
171
215
  };
172
216
  const deleteBucketCname = async (bucketName, domain) => {
@@ -276,7 +320,7 @@ const parseReplicationRules = (xml) => {
276
320
  txtRecordId = verificationResult.txtRecordId;
277
321
  }
278
322
  const bucketCnameBound = cnameResult.success;
279
- if (certificate && bucketCnameBound) {
323
+ if (certificate && cnameResult.certBound) {
280
324
  logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BOUND', { domain: normalizedDomain }));
281
325
  }
282
326
  await addCorsRuleForDomain(bucketName, normalizedDomain);
@@ -429,7 +473,7 @@ const parseReplicationRules = (xml) => {
429
473
  domain,
430
474
  txtRecord: `${fullTxtRecord}.${(0, domainUtils_1.extractMainDomain)(domain)}`,
431
475
  }));
432
- return { success: false, needVerification: true };
476
+ return { success: false, needVerification: true, certBound: false };
433
477
  };
434
478
  const createOrFindDnsCnameRecord = async (domain, mainDomain, hostRecord, ossEndpoint, bucketCnameBound) => {
435
479
  try {
@@ -456,7 +500,7 @@ const parseReplicationRules = (xml) => {
456
500
  }
457
501
  catch (error) {
458
502
  logger_1.logger.warn(lang_1.lang.__('OSS_DNS_DOMAIN_NOT_MANAGED', { domain, cname: ossEndpoint }));
459
- logger_1.logger.debug(`DNS error: ${error}`);
503
+ logger_1.logger.debug(lang_1.lang.__('DNS_OPERATION_ERROR', { error: String(error) }));
460
504
  return { domain, cname: ossEndpoint, bucketCnameBound };
461
505
  }
462
506
  };
@@ -37,6 +37,7 @@ exports.createSlsOperations = exports.SLS_LOGSTORE_SHARDS = exports.SLS_LOGSTORE
37
37
  const sls = __importStar(require("@alicloud/sls20201230"));
38
38
  const logger_1 = require("../logger");
39
39
  const polling_1 = require("../polling");
40
+ const lang_1 = require("../../lang");
40
41
  // The logstore attributes si creates with (issue #234 M1): `fn.log` is a
41
42
  // boolean — these are stack constants, so live values differing from them are
42
43
  // out-of-band drift.
@@ -60,7 +61,7 @@ const waitForSlsProject = async (getProject, projectName) => {
60
61
  maxAttempts: 30,
61
62
  onProgress: (project) => {
62
63
  if (project) {
63
- logger_1.logger.info(`Waiting for SLS project ${projectName} to be ready (current status: ${project.status ?? 'unknown'})`);
64
+ logger_1.logger.info(lang_1.lang.__('SLS_WAITING_PROJECT', { projectName, status: project.status ?? 'unknown' }));
64
65
  }
65
66
  },
66
67
  });
@@ -91,7 +92,7 @@ const waitForSlsLogstore = async (getLogstore, projectName, logstoreName, ttl) =
91
92
  maxAttempts: 30,
92
93
  onProgress: (logstore) => {
93
94
  if (logstore) {
94
- logger_1.logger.info(`Waiting for SLS logstore ${projectName}/${logstoreName} to be ready...`);
95
+ logger_1.logger.info(lang_1.lang.__('SLS_WAITING_LOGSTORE', { projectName, logstoreName }));
95
96
  }
96
97
  },
97
98
  });
@@ -7,6 +7,7 @@ exports.createTablestoreOperations = exports.TableStoreInstanceStatus = void 0;
7
7
  const tablestore_1 = __importDefault(require("tablestore"));
8
8
  const logger_1 = require("../logger");
9
9
  const polling_1 = require("../polling");
10
+ const lang_1 = require("../../lang");
10
11
  var TableStoreInstanceStatus;
11
12
  (function (TableStoreInstanceStatus) {
12
13
  TableStoreInstanceStatus["RUNNING"] = "RUNNING";
@@ -24,15 +25,19 @@ const waitForTableReady = async (describeTable, tableName) => {
24
25
  maxAttempts: 60,
25
26
  onProgress: (table, attempt, maxAttempts) => {
26
27
  if (!table) {
27
- logger_1.logger.info(`Waiting for table ${tableName} to be ready... (attempt ${attempt}/${maxAttempts})`);
28
+ logger_1.logger.info(lang_1.lang.__('OTS_WAITING_TABLE', {
29
+ tableName,
30
+ attempt: String(attempt),
31
+ maxAttempts: String(maxAttempts),
32
+ }));
28
33
  }
29
34
  },
30
35
  });
31
- logger_1.logger.info(`Table ${tableName} is ready`);
36
+ logger_1.logger.info(lang_1.lang.__('OTS_TABLE_READY', { tableName }));
32
37
  }
33
38
  catch (e) {
34
39
  if (e instanceof polling_1.PollingTimeoutError) {
35
- throw new Error(`Timeout waiting for table ${tableName} to be ready`, { cause: e });
40
+ throw new Error(lang_1.lang.__('OTS_TABLE_TIMEOUT', { tableName }), { cause: e });
36
41
  }
37
42
  throw e;
38
43
  }
@@ -69,11 +74,14 @@ const createTablestoreOperations = (endpoint, instanceName, context) => {
69
74
  return new Promise((resolve, reject) => {
70
75
  client.createTable(params, (err) => {
71
76
  if (err) {
72
- logger_1.logger.error(`Failed to create table ${config.tableName}: ${err.message}`);
77
+ logger_1.logger.error(lang_1.lang.__('OTS_CREATE_TABLE_FAILED', {
78
+ tableName: config.tableName,
79
+ error: err.message,
80
+ }));
73
81
  reject(err);
74
82
  }
75
83
  else {
76
- logger_1.logger.info(`Successfully created table ${config.tableName}`);
84
+ logger_1.logger.info(lang_1.lang.__('OTS_TABLE_CREATED', { tableName: config.tableName }));
77
85
  resolve();
78
86
  }
79
87
  });
@@ -92,7 +100,7 @@ const createTablestoreOperations = (endpoint, instanceName, context) => {
92
100
  resolve(null);
93
101
  }
94
102
  else {
95
- logger_1.logger.error(`Failed to describe table ${tableName}: ${errorMessage}`);
103
+ logger_1.logger.error(lang_1.lang.__('OTS_DESCRIBE_TABLE_FAILED', { tableName, error: errorMessage }));
96
104
  reject(err);
97
105
  }
98
106
  }
@@ -133,11 +141,14 @@ const createTablestoreOperations = (endpoint, instanceName, context) => {
133
141
  return new Promise((resolve, reject) => {
134
142
  client.updateTable(params, (err) => {
135
143
  if (err) {
136
- logger_1.logger.error(`Failed to update table ${config.tableName}: ${err.message}`);
144
+ logger_1.logger.error(lang_1.lang.__('OTS_UPDATE_TABLE_FAILED', {
145
+ tableName: config.tableName,
146
+ error: err.message,
147
+ }));
137
148
  reject(err);
138
149
  }
139
150
  else {
140
- logger_1.logger.info(`Successfully updated table ${config.tableName}`);
151
+ logger_1.logger.info(lang_1.lang.__('OTS_TABLE_UPDATED', { tableName: config.tableName }));
141
152
  resolve();
142
153
  }
143
154
  });
@@ -154,16 +165,16 @@ const createTablestoreOperations = (endpoint, instanceName, context) => {
154
165
  // If table doesn't exist, consider deletion successful
155
166
  if (errorMessage.includes('OTSObjectNotExist') ||
156
167
  errorMessage.includes('does not exist')) {
157
- logger_1.logger.info(`Table ${tableName} already deleted or does not exist`);
168
+ logger_1.logger.info(lang_1.lang.__('OTS_TABLE_ALREADY_DELETED', { tableName }));
158
169
  resolve();
159
170
  }
160
171
  else {
161
- logger_1.logger.error(`Failed to delete table ${tableName}: ${errorMessage}`);
172
+ logger_1.logger.error(lang_1.lang.__('OTS_DELETE_TABLE_FAILED', { tableName, error: errorMessage }));
162
173
  reject(err);
163
174
  }
164
175
  }
165
176
  else {
166
- logger_1.logger.info(`Successfully deleted table ${tableName}`);
177
+ logger_1.logger.info(lang_1.lang.__('OTS_TABLE_DELETED', { tableName }));
167
178
  resolve();
168
179
  }
169
180
  });
@@ -1,7 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateApiKey = exports.createApiClient = void 0;
3
+ exports.validateApiKey = exports.createApiClient = exports.ApiError = void 0;
4
4
  const lang_1 = require("../lang");
5
+ /**
6
+ * API error carrying the HTTP status so callers can distinguish "not found"
7
+ * (legitimate empty state on first deploy) from network/5xx failures, which
8
+ * must never be mistaken for an empty state.
9
+ */
10
+ class ApiError extends Error {
11
+ status;
12
+ constructor(message, status) {
13
+ super(message);
14
+ this.name = 'ApiError';
15
+ this.status = status;
16
+ }
17
+ }
18
+ exports.ApiError = ApiError;
5
19
  // Opaque JSONB payloads from the Console API — their internal keys must NOT be case-converted
6
20
  const SKIP_CASE_CONVERT = new Set([
7
21
  'spec',
@@ -29,13 +43,15 @@ const camelizeKeys = (value) => {
29
43
  const handleHttpError = (response) => {
30
44
  const status = response.status;
31
45
  if (status === 401)
32
- throw new Error(lang_1.lang.__('API_ERROR_401'));
46
+ throw new ApiError(lang_1.lang.__('API_ERROR_401'), 401);
33
47
  if (status === 403)
34
- throw new Error(lang_1.lang.__('API_ERROR_403'));
48
+ throw new ApiError(lang_1.lang.__('API_ERROR_403'), 403);
49
+ if (status === 404)
50
+ throw new ApiError(lang_1.lang.__('API_ERROR_404'), 404);
35
51
  if (status === 409) {
36
- throw new Error(lang_1.lang.__('API_ERROR_409', { message: `HTTP Error ${status}` }));
52
+ throw new ApiError(lang_1.lang.__('API_ERROR_409', { message: `HTTP Error ${status}` }), 409);
37
53
  }
38
- throw new Error(lang_1.lang.__('API_ERROR_UNKNOWN', { status: String(status), message: `HTTP Error ${status}` }));
54
+ throw new ApiError(lang_1.lang.__('API_ERROR_UNKNOWN', { status: String(status), message: `HTTP Error ${status}` }), status);
39
55
  };
40
56
  const buildRequestInit = (method, headers, body) => ({
41
57
  method: method.toUpperCase(),
@@ -95,6 +111,7 @@ const validateApiKey = async (apiKey, baseUrl) => {
95
111
  return {
96
112
  orgId: result.orgId ?? '',
97
113
  orgName: result.orgName ?? '',
114
+ orgSlug: result.orgSlug,
98
115
  userEmail: result.userEmail ?? result.user?.email ?? '',
99
116
  scopes: result.scopes ?? [],
100
117
  };
@@ -10,6 +10,7 @@ const credentials_1 = require("./credentials");
10
10
  const imsClient_1 = require("./imsClient");
11
11
  const providerEnum_1 = require("./providerEnum");
12
12
  const refreshCache_1 = require("./refreshCache");
13
+ const lang_1 = require("../lang");
13
14
  let context;
14
15
  const DEFAULT_IAC_FILES = [
15
16
  'serverlessinsight.yml',
@@ -50,7 +51,7 @@ const getIacLocation = (location) => {
50
51
  const attemptedList = Array.from(attempted)
51
52
  .map((n) => `'${n}'`)
52
53
  .join(', ');
53
- throw new Error(`No IaC file found. Tried: ${attemptedList}`);
54
+ throw new Error(lang_1.lang.__('CONTEXT_NO_IAC_FILE', { attemptedList }));
54
55
  };
55
56
  exports.getIacLocation = getIacLocation;
56
57
  const setContext = async (config, reaValToken = false) => {
@@ -60,7 +61,7 @@ const setContext = async (config, reaValToken = false) => {
60
61
  process.env.ALIYUN_REGION ??
61
62
  'cn-hangzhou';
62
63
  if (process.env.ROS_REGION_ID && !process.env.SI_REGION) {
63
- console.warn('Warning: ROS_REGION_ID environment variable is deprecated. Please use SI_REGION instead.');
64
+ console.warn(lang_1.lang.__('CONTEXT_REGION_DEPRECATED'));
64
65
  }
65
66
  const provider = (config.provider ??
66
67
  config.iacProvider?.name ??
@@ -97,14 +98,14 @@ const setContext = async (config, reaValToken = false) => {
97
98
  exports.setContext = setContext;
98
99
  const getContext = () => {
99
100
  if (!context) {
100
- throw new Error('No context found');
101
+ throw new Error(lang_1.lang.__('CONTEXT_NOT_FOUND'));
101
102
  }
102
103
  return context;
103
104
  };
104
105
  exports.getContext = getContext;
105
106
  const setIac = (iac) => {
106
107
  if (!context) {
107
- throw new Error('Context must be set before setting IAC');
108
+ throw new Error(lang_1.lang.__('CONTEXT_IAC_REQUIRES_CONTEXT'));
108
109
  }
109
110
  context.iac = iac;
110
111
  };
@@ -229,7 +229,7 @@ const forceUnlock = (statePath, lockId) => {
229
229
  return false; // No lock to remove
230
230
  }
231
231
  if (existingLock.id !== lockId) {
232
- throw new Error(`Lock ID mismatch. Current lock ID is ${existingLock.id}, but you provided ${lockId}`);
232
+ throw new Error(lang_1.lang.__('LOCK_ID_MISMATCH', { actualId: existingLock.id, providedId: lockId }));
233
233
  }
234
234
  removeLockFile(lockPath);
235
235
  return true;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceMigrationMarker = exports.isMigratedToSaas = exports.MANAGED_BY_SAAS = void 0;
4
+ const logger_1 = require("./logger");
5
+ const lang_1 = require("../lang");
6
+ /**
7
+ * Value written into the legacy state's top-level `managedBy` field once
8
+ * `si migrate` has copied the state to the Console (docs/state-migration-saas.md
9
+ * §6.3). The marker is just a new persisted version of the state — there is no
10
+ * separate tombstone mechanism.
11
+ */
12
+ exports.MANAGED_BY_SAAS = 'saas';
13
+ /** True when the state has been migrated to (and is now owned by) the Console. */
14
+ const isMigratedToSaas = (state) => {
15
+ return state?.managedBy === exports.MANAGED_BY_SAAS;
16
+ };
17
+ exports.isMigratedToSaas = isMigratedToSaas;
18
+ /**
19
+ * Ownership handover check (decision D-4): after migration the Console is the
20
+ * single source of truth. Mutating commands (deploy/destroy) pass 'refuse' so
21
+ * a legacy-backend write attempt fails closed; read-only commands (plan/diff/
22
+ * show) pass 'warn'; `si migrate` itself passes 'off' (it must be able to read
23
+ * marked state for idempotent re-runs and --rollback).
24
+ */
25
+ const enforceMigrationMarker = (state, action) => {
26
+ if (action === 'off' || !(0, exports.isMigratedToSaas)(state)) {
27
+ return;
28
+ }
29
+ if (action === 'refuse') {
30
+ throw new Error(lang_1.lang.__('MIGRATION_MARKER_REFUSED'));
31
+ }
32
+ logger_1.logger.warn(lang_1.lang.__('MIGRATION_MARKER_WARN'));
33
+ };
34
+ exports.enforceMigrationMarker = enforceMigrationMarker;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSupportedRuntimes = exports.isRuntimeSupported = exports.mapRuntime = exports.StandardRuntime = void 0;
4
4
  const providerEnum_1 = require("./providerEnum");
5
+ const lang_1 = require("../lang");
5
6
  var StandardRuntime;
6
7
  (function (StandardRuntime) {
7
8
  StandardRuntime["NODEJS24"] = "nodejs24";
@@ -151,12 +152,15 @@ const runtimeMappings = {
151
152
  const mapRuntime = (standardRuntime, provider) => {
152
153
  const mapping = runtimeMappings[standardRuntime];
153
154
  if (!mapping) {
154
- throw new Error(`Unsupported standard runtime: ${standardRuntime}`);
155
+ throw new Error(lang_1.lang.__('RUNTIME_UNSUPPORTED_STANDARD', { standardRuntime }));
155
156
  }
156
157
  const providerRuntime = mapping[provider];
157
158
  if (!providerRuntime) {
158
- throw new Error(`Runtime ${standardRuntime} is not supported for provider ${provider}. ` +
159
- `Supported providers for this runtime: ${Object.keys(mapping).join(', ')}`);
159
+ throw new Error(lang_1.lang.__('RUNTIME_NOT_SUPPORTED_FOR_PROVIDER', {
160
+ runtime: standardRuntime,
161
+ provider,
162
+ supportedProviders: Object.keys(mapping).join(', '),
163
+ }));
160
164
  }
161
165
  return providerRuntime;
162
166
  };
@@ -69,6 +69,6 @@ const createCosStorageAdapter = (config) => {
69
69
  };
70
70
  const createCosStateBackend = (config) => {
71
71
  const adapter = createCosStorageAdapter(config);
72
- return (0, remoteStateBackend_1.createRemoteStateBackend)(adapter, { key: config.key });
72
+ return (0, remoteStateBackend_1.createRemoteStateBackend)(adapter, { key: config.key, markerAction: config.markerAction });
73
73
  };
74
74
  exports.createCosStateBackend = createCosStateBackend;
@@ -34,10 +34,11 @@ const createStateBackend = (backendConfig, context) => {
34
34
  return (0, saasStateBackend_1.createSaasStateBackend)({
35
35
  app: context.app,
36
36
  service: context.service,
37
- });
37
+ declaredOrg: context.declaredOrg,
38
+ }, { apiKey: context.siApiKey });
38
39
  }
39
40
  if (backendConfig.type === types_1.StateBackendType.LOCAL) {
40
- return (0, localStateBackend_1.createLocalStateBackend)(context.app, context.service, context.baseDir);
41
+ return (0, localStateBackend_1.createLocalStateBackend)(context.app, context.service, context.baseDir, context.migrationMarker);
41
42
  }
42
43
  const bucketConfig = backendConfig;
43
44
  const region = context.region;
@@ -52,6 +53,7 @@ const createStateBackend = (backendConfig, context) => {
52
53
  accessKeyId,
53
54
  accessKeySecret,
54
55
  securityToken,
56
+ markerAction: context.migrationMarker,
55
57
  });
56
58
  }
57
59
  return (0, ossStateBackend_1.createOssStateBackend)({
@@ -61,6 +63,7 @@ const createStateBackend = (backendConfig, context) => {
61
63
  accessKeyId,
62
64
  accessKeySecret,
63
65
  securityToken,
66
+ markerAction: context.migrationMarker,
64
67
  });
65
68
  };
66
69
  exports.createStateBackend = createStateBackend;
@@ -2,16 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLocalStateBackend = void 0;
4
4
  const stateManager_1 = require("../stateManager");
5
+ const migrationMarker_1 = require("../migrationMarker");
5
6
  const lockManager_1 = require("../lockManager");
6
- const createLocalStateBackend = (app, service, baseDir = process.cwd()) => {
7
+ const createLocalStateBackend = (app, service, baseDir = process.cwd(), markerAction = 'off') => {
7
8
  const statePath = (0, stateManager_1.getStatePath)(app, service, baseDir);
8
9
  return {
9
10
  loadState: async (provider, loadApp, loadService, stage) => {
10
- return (0, stateManager_1.loadState)(provider, loadApp, loadService, stage, baseDir);
11
+ const state = (0, stateManager_1.loadState)(provider, loadApp, loadService, stage, baseDir);
12
+ (0, migrationMarker_1.enforceMigrationMarker)(state, markerAction);
13
+ return state;
11
14
  },
12
15
  saveState: async (state, saveApp, saveService, stage) => {
13
16
  (0, stateManager_1.saveState)(state, saveApp, saveService, stage, baseDir);
14
17
  },
18
+ patchPersisted: async (patch) => {
19
+ (0, stateManager_1.patchPersistedState)(app, service, patch, baseDir);
20
+ },
15
21
  acquireLock: async (operation, options) => {
16
22
  const lockMeta = await (0, lockManager_1.acquireLockInternal)(statePath, operation, options);
17
23
  return lockMeta.id;
@@ -51,6 +51,6 @@ const createOssStorageAdapter = (config) => {
51
51
  };
52
52
  const createOssStateBackend = (config) => {
53
53
  const adapter = createOssStorageAdapter(config);
54
- return (0, remoteStateBackend_1.createRemoteStateBackend)(adapter, { key: config.key });
54
+ return (0, remoteStateBackend_1.createRemoteStateBackend)(adapter, { key: config.key, markerAction: config.markerAction });
55
55
  };
56
56
  exports.createOssStateBackend = createOssStateBackend;
@@ -7,6 +7,7 @@ exports.createRemoteStateBackend = void 0;
7
7
  const node_os_1 = __importDefault(require("node:os"));
8
8
  const types_1 = require("../../types");
9
9
  const stateManager_1 = require("../stateManager");
10
+ const migrationMarker_1 = require("../migrationMarker");
10
11
  const constants_1 = require("../constants");
11
12
  const lockManager_1 = require("../lockManager");
12
13
  const logger_1 = require("../logger");
@@ -14,6 +15,7 @@ const lang_1 = require("../../lang");
14
15
  const lockUtils_1 = require("./lockUtils");
15
16
  const createRemoteStateBackend = (adapter, config) => {
16
17
  const lockKey = `${config.key}${lockUtils_1.LOCK_KEY_SUFFIX}`;
18
+ const markerAction = config.markerAction ?? 'off';
17
19
  const readLockObject = async () => {
18
20
  return adapter.read(lockKey);
19
21
  };
@@ -73,10 +75,25 @@ const createRemoteStateBackend = (adapter, config) => {
73
75
  if (state) {
74
76
  const migrated = (0, stateManager_1.migrateState)(state);
75
77
  const stageResources = migrated.stages?.[stage]?.resources ?? {};
76
- return { ...migrated, resources: stageResources };
78
+ const loaded = { ...migrated, resources: stageResources };
79
+ (0, migrationMarker_1.enforceMigrationMarker)(loaded, markerAction);
80
+ return loaded;
77
81
  }
78
82
  return { version: types_1.CURRENT_STATE_VERSION, provider, app, service, stages: {}, resources: {} };
79
83
  },
84
+ patchPersisted: async (patch) => {
85
+ const raw = await adapter.read(config.key);
86
+ const merged = raw ? { ...(0, stateManager_1.toPersistedState)(raw) } : {};
87
+ for (const [key, value] of Object.entries(patch)) {
88
+ if (value === undefined) {
89
+ delete merged[key];
90
+ }
91
+ else {
92
+ merged[key] = value;
93
+ }
94
+ }
95
+ await adapter.write(config.key, merged);
96
+ },
80
97
  saveState: async (state, app, service, stage) => {
81
98
  let existing = {
82
99
  version: types_1.CURRENT_STATE_VERSION,
@@ -124,7 +141,7 @@ const createRemoteStateBackend = (adapter, config) => {
124
141
  if (!existing)
125
142
  return false;
126
143
  if (existing.id !== lockId) {
127
- throw new Error(`Lock ID mismatch. Current lock ID is ${existing.id}, but you provided ${lockId}`);
144
+ throw new Error(lang_1.lang.__('LOCK_ID_MISMATCH', { actualId: existing.id, providedId: lockId }));
128
145
  }
129
146
  await adapter.delete(lockKey);
130
147
  return true;