@geek-fun/serverlessinsight 0.5.6 → 0.5.7

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 (31) hide show
  1. package/README.md +12 -10
  2. package/dist/package.json +2 -1
  3. package/dist/src/commands/deploy.js +74 -2
  4. package/dist/src/commands/index.js +17 -16
  5. package/dist/src/commands/show.js +302 -0
  6. package/dist/src/common/aliyunClient/apigwOperations.js +6 -22
  7. package/dist/src/common/aliyunClient/index.js +3 -2
  8. package/dist/src/common/aliyunClient/ossOperations.js +126 -1
  9. package/dist/src/common/constants.js +2 -3
  10. package/dist/src/common/context.js +4 -1
  11. package/dist/src/common/domainUtils.js +121 -0
  12. package/dist/src/common/iacHelper.js +1 -8
  13. package/dist/src/common/stateBackend/cosStateBackend.js +16 -188
  14. package/dist/src/common/stateBackend/index.js +2 -0
  15. package/dist/src/common/stateBackend/lockUtils.js +55 -0
  16. package/dist/src/common/stateBackend/ossStateBackend.js +27 -199
  17. package/dist/src/common/stateBackend/remoteStateBackend.js +150 -0
  18. package/dist/src/common/tencentClient/cosOperations.js +366 -216
  19. package/dist/src/common/tencentClient/dnspodOperations.js +105 -0
  20. package/dist/src/common/tencentClient/index.js +5 -1
  21. package/dist/src/lang/en.js +30 -0
  22. package/dist/src/lang/zh-CN.js +28 -0
  23. package/dist/src/stack/aliyunStack/apigwResource.js +35 -0
  24. package/dist/src/stack/aliyunStack/ossResource.js +63 -19
  25. package/dist/src/stack/deploy.js +6 -33
  26. package/dist/src/stack/scfStack/cosResource.js +58 -8
  27. package/dist/src/types/domains/state.js +13 -0
  28. package/dist/src/validator/templateRefSchema.js +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +2 -1
  31. package/dist/src/commands/template.js +0 -28
package/README.md CHANGED
@@ -50,11 +50,11 @@ ServerlessInsight supports the following cloud providers:
50
50
  | Provider | Functions | API Gateway | Storage | Databases | Status |
51
51
  | ----------------- | ---------------- | -------------- | -------------- | ---------------- | ------- |
52
52
  | **Alibaba Cloud** | ✅ FC3 | ✅ API Gateway | ✅ OSS | ✅ RDS, OTS, ESS | Stable |
53
+ | **Tencent Cloud** | ✅ SCF | ✅ API Gateway | ✅ COS | ✅ TDSQL-C | Stable |
53
54
  | **Huawei Cloud** | ✅ FunctionGraph | 🚧 Coming Soon | 🚧 Coming Soon | 🚧 Coming Soon | Beta |
54
55
  | **AWS** | 🔜 Planned | 🔜 Planned | 🔜 Planned | 🔜 Planned | Planned |
55
56
  | **Azure** | 🔜 Planned | 🔜 Planned | 🔜 Planned | 🔜 Planned | Planned |
56
57
  | **Google Cloud** | 🔜 Planned | 🔜 Planned | 🔜 Planned | 🔜 Planned | Planned |
57
- | **Tencent Cloud** | 🔜 Planned | 🔜 Planned | 🔜 Planned | 🔜 Planned | Planned |
58
58
 
59
59
  ---
60
60
 
@@ -85,19 +85,22 @@ si --version
85
85
 
86
86
  ```bash
87
87
  # Validate your serverless configuration
88
- si validate <stackName> -f serverless.yml
88
+ si validate -f serverless.yml
89
+
90
+ # Generate deployment plan (see what will change)
91
+ si plan -f serverless.yml
89
92
 
90
93
  # Deploy your serverless application
91
- si deploy <stackName> -f serverless.yml -s dev
94
+ si deploy -f serverless.yml -s dev
92
95
 
93
96
  # Run your application locally for debugging
94
- si local <stackName> -f serverless.yml -s local
97
+ si local -f serverless.yml -s local
95
98
 
96
- # Generate provider-specific template
97
- si template <stackName> -f serverless.yml -t JSON
99
+ # Show deployed resource information
100
+ si show -f serverless.yml
98
101
 
99
102
  # Destroy the deployed stack
100
- si destroy <stackName> -f serverless.yml
103
+ si destroy -f serverless.yml
101
104
  ```
102
105
 
103
106
  ---
@@ -248,7 +251,7 @@ This architecture enables:
248
251
 
249
252
  ## 🗄️ State Management
250
253
 
251
- ServerlessInsight uses a state-based deployment model that tracks all deployed resources in a local state file (`.serverlessinsight/state.json`). This enables:
254
+ ServerlessInsight uses a state-based deployment model that tracks all deployed resources in a local state file (`.serverlessinsight/state-{app}-{service}.json` in the project directory). This enables:
252
255
 
253
256
  - **Incremental deployments** - Only changed resources are updated
254
257
  - **Drift detection** - Identifies differences between local state and cloud resources
@@ -272,7 +275,7 @@ Next steps: 1) Review the error above, 2) Fix any configuration issues, 3) Run d
272
275
 
273
276
  ### State File Location
274
277
 
275
- The state file is stored in `.serverlessinsight/state.json` in your project directory. This file:
278
+ The state file is stored as `.serverlessinsight/state-{app}-{service}.json` in your project directory (e.g., `.serverlessinsight/state-myapp-myservice.json`). This file:
276
279
 
277
280
  - Should be committed to version control for team collaboration
278
281
  - Contains resource metadata and identifiers
@@ -336,7 +339,6 @@ ServerlessInsight is built with these amazing technologies:
336
339
  - [Node.js](https://nodejs.org/) - JavaScript runtime
337
340
  - [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript
338
341
  - [Commander.js](https://github.com/tj/commander.js/) - CLI framework
339
- - [Alibaba Cloud ROS CDK](https://github.com/aliyun/Resource-Orchestration-Service-Cloud-Development-Kit) - Cloud infrastructure SDK
340
342
 
341
343
  ---
342
344
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Full life cycle cross providers serverless application management for your fast-growing business.",
5
5
  "homepage": "https://serverlessinsight.geekfun.club",
6
6
  "main": "dist/src/index.js",
@@ -72,6 +72,7 @@
72
72
  "pino-pretty": "^13.1.3",
73
73
  "tablestore": "^5.6.3",
74
74
  "tencentcloud-sdk-nodejs-cynosdb": "^4.1.188",
75
+ "tencentcloud-sdk-nodejs-dnspod": "^4.1.197",
75
76
  "tencentcloud-sdk-nodejs-es": "^4.1.183",
76
77
  "tencentcloud-sdk-nodejs-scf": "^4.1.168",
77
78
  "yaml": "^2.8.2"
@@ -1,11 +1,63 @@
1
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
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.deploy = void 0;
37
+ const readline = __importStar(require("node:readline"));
4
38
  const stack_1 = require("../stack");
5
39
  const common_1 = require("../common");
6
40
  const stateBackend_1 = require("../common/stateBackend");
7
41
  const parser_1 = require("../parser");
42
+ const scfStack_1 = require("../stack/scfStack");
43
+ const aliyunStack_1 = require("../stack/aliyunStack");
8
44
  const lang_1 = require("../lang");
45
+ const askConfirmation = async () => {
46
+ if (!process.stdin.isTTY) {
47
+ throw new Error('Interactive confirmation required but stdin is not a TTY. ' +
48
+ 'Use --auto-approve (-y) to skip confirmation in non-interactive environments.');
49
+ }
50
+ const rl = readline.createInterface({
51
+ input: process.stdin,
52
+ output: process.stdout,
53
+ });
54
+ return new Promise((resolve) => {
55
+ rl.question(lang_1.lang.__('DEPLOY_CONFIRMATION'), (answer) => {
56
+ rl.close();
57
+ resolve(answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y');
58
+ });
59
+ });
60
+ };
9
61
  const deploy = async (options) => {
10
62
  common_1.logger.info(lang_1.lang.__('VALIDATING_YAML'));
11
63
  const iacLocation = (0, common_1.getIacLocation)(options.location);
@@ -20,10 +72,30 @@ const deploy = async (options) => {
20
72
  }, true);
21
73
  const context = (0, common_1.getContext)();
22
74
  const iac = (0, parser_1.revalYaml)(iacLocation, context);
23
- // Store IAC in context for access by all functions
24
75
  (0, common_1.setIac)(iac);
25
- common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK'));
26
76
  const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
77
+ common_1.logger.info(lang_1.lang.__('GENERATING_PLAN'));
78
+ let planResult;
79
+ if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
80
+ planResult = await (0, scfStack_1.generateTencentPlan)(iac, backend);
81
+ }
82
+ else if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
83
+ planResult = await (0, aliyunStack_1.generateAliyunPlan)(iac, backend);
84
+ }
85
+ else {
86
+ throw new Error(lang_1.lang.__('PLAN_COMMAND_NOT_SUPPORTED'));
87
+ }
88
+ (0, scfStack_1.displayPlan)(planResult);
89
+ if (planResult.items.some((item) => item.action !== 'noop')) {
90
+ if (!options.autoApprove) {
91
+ const confirmed = await askConfirmation();
92
+ if (!confirmed) {
93
+ common_1.logger.info(lang_1.lang.__('DEPLOY_CANCELLED'));
94
+ return;
95
+ }
96
+ }
97
+ }
98
+ common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK'));
27
99
  common_1.logger.info(lang_1.lang.__('ACQUIRING_LOCK'));
28
100
  await backend.withLock('deploy', async () => {
29
101
  await (0, stack_1.deployStack)(iac, backend);
@@ -5,11 +5,11 @@ const commander_1 = require("commander");
5
5
  const common_1 = require("../common");
6
6
  const validate_1 = require("./validate");
7
7
  const deploy_1 = require("./deploy");
8
- const template_1 = require("./template");
9
8
  const destroy_1 = require("./destroy");
10
9
  const local_1 = require("./local");
11
10
  const plan_1 = require("./plan");
12
11
  const forceUnlock_1 = require("./forceUnlock");
12
+ const show_1 = require("./show");
13
13
  const lang_1 = require("../lang");
14
14
  const parser_1 = require("../parser");
15
15
  // Global error handler
@@ -58,15 +58,23 @@ const program = new commander_1.Command();
58
58
  program.name('si').description('CLI for ServerlessInsight').version((0, common_1.getVersion)());
59
59
  program
60
60
  .command('show')
61
- .description('show string')
61
+ .description('show deployed resources from state')
62
62
  .option('-f, --file <path>', 'specify the yaml file')
63
+ .option('-s, --stage <stage>', 'specify the stage')
63
64
  .action(actionWrapper('show', async (options) => {
64
65
  const iacLocation = (0, common_1.getIacLocation)(options.file);
65
66
  const rawIac = (0, parser_1.parseYaml)(iacLocation);
66
- await (0, common_1.setContext)({ ...options, app: rawIac.app, service: rawIac.service });
67
+ await (0, common_1.setContext)({
68
+ ...options,
69
+ app: rawIac.app,
70
+ service: rawIac.service,
71
+ iacProvider: rawIac.provider,
72
+ stages: rawIac.stages,
73
+ });
67
74
  const context = (0, common_1.getContext)();
68
- const result = await (0, common_1.getIamInfo)(context);
69
- console.log(lang_1.lang.__('RESULT', { result: JSON.stringify(result) }));
75
+ const iac = (0, parser_1.revalYaml)(iacLocation, context);
76
+ (0, common_1.setIac)(iac);
77
+ await (0, show_1.show)({ stage: options.stage, location: options.file, iac });
70
78
  }));
71
79
  program
72
80
  .command('validate')
@@ -79,7 +87,7 @@ program
79
87
  }));
80
88
  program
81
89
  .command('plan')
82
- .description('generate and show deployment plan (Tencent provider only)')
90
+ .description('generate and show deployment plan')
83
91
  .option('-f, --file <path>', 'specify the yaml file')
84
92
  .option('-s, --stage <stage>', 'specify the stage')
85
93
  .option('-r, --region <region>', 'specify the region')
@@ -108,12 +116,13 @@ program
108
116
  .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
109
117
  .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
110
118
  .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
119
+ .option('-y, --auto-approve', 'skip interactive approval of plan before deploying')
111
120
  .option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
112
121
  const [key, val] = value.split('=');
113
122
  previous[key] = val;
114
123
  return previous;
115
124
  }, {})
116
- .action(actionWrapper('deploy', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, }) => {
125
+ .action(actionWrapper('deploy', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, autoApprove, }) => {
117
126
  await (0, deploy_1.deploy)({
118
127
  stage,
119
128
  parameters: parameter,
@@ -123,17 +132,9 @@ program
123
132
  accessKeyId,
124
133
  accessKeySecret,
125
134
  securityToken,
135
+ autoApprove,
126
136
  });
127
137
  }));
128
- program
129
- .command('template')
130
- .description('print platform specific infrastructure as code template')
131
- .option('-f, --file <path>', 'specify the yaml file')
132
- .option('-s, --stage <stage>', 'specify the stage')
133
- .option('-t, --format <type>', 'output content type (JSON or YAML)', 'JSON')
134
- .action(actionWrapper('template', async ({ format, file, stage }) => {
135
- await (0, template_1.template)({ format, location: file, stage });
136
- }));
137
138
  program
138
139
  .command('destroy')
139
140
  .option('-f, --file <path>', 'specify the yaml file')
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.show = void 0;
4
+ const types_1 = require("../types");
5
+ const backend_1 = require("../types/domains/backend");
6
+ const common_1 = require("../common");
7
+ const lockManager_1 = require("../common/lockManager");
8
+ const stateBackend_1 = require("../common/stateBackend");
9
+ const logger_1 = require("../common/logger");
10
+ const formatTimeAgo = (dateStr) => {
11
+ const date = new Date(dateStr);
12
+ const now = new Date();
13
+ const diffMs = now.getTime() - date.getTime();
14
+ const diffMins = Math.floor(diffMs / 60000);
15
+ const diffHours = Math.floor(diffMs / 3600000);
16
+ const diffDays = Math.floor(diffMs / 86400000);
17
+ if (diffDays > 0)
18
+ return `${diffDays} day(s) ago`;
19
+ if (diffHours > 0)
20
+ return `${diffHours} hour(s) ago`;
21
+ if (diffMins > 0)
22
+ return `${diffMins} minute(s) ago`;
23
+ return 'just now';
24
+ };
25
+ const formatFunctionOutput = (logicalId, resource) => {
26
+ const lines = [];
27
+ const instance = resource.instances?.[0];
28
+ if (!instance)
29
+ return lines;
30
+ const functionName = instance.functionName || instance.id;
31
+ const runtime = instance.runtime;
32
+ const handler = instance.handler;
33
+ const memory = instance.memorySize;
34
+ const timeout = instance.timeout;
35
+ lines.push(` 📦 ${functionName}`);
36
+ lines.push(` Runtime: ${runtime}`);
37
+ lines.push(` Handler: ${handler}`);
38
+ lines.push(` Memory: ${memory}MB, Timeout: ${timeout}s`);
39
+ if (instance.internetAccess !== undefined) {
40
+ lines.push(` Internet Access: ${instance.internetAccess ? 'Yes' : 'No'}`);
41
+ }
42
+ return lines;
43
+ };
44
+ const formatApiGatewayOutput = (logicalId, resource) => {
45
+ const lines = [];
46
+ const instance = resource.instances?.[0];
47
+ if (!instance)
48
+ return lines;
49
+ if (instance.type === types_1.ResourceTypeEnum.ALIYUN_APIGW_GROUP) {
50
+ const groupName = instance.groupName || instance.id;
51
+ const subDomain = instance.subDomain;
52
+ const basePath = instance.basePath;
53
+ lines.push(` 🌐 API Group: ${groupName}`);
54
+ if (subDomain) {
55
+ lines.push(` Sub-domain: ${subDomain}`);
56
+ }
57
+ if (basePath) {
58
+ lines.push(` Base Path: ${basePath}`);
59
+ }
60
+ }
61
+ else if (instance.type === types_1.ResourceTypeEnum.ALIYUN_APIGW_API) {
62
+ const apiName = instance.apiName || instance.id;
63
+ const groupId = instance.groupId;
64
+ lines.push(` 🔗 API: ${apiName}`);
65
+ lines.push(` Group ID: ${groupId}`);
66
+ }
67
+ return lines;
68
+ };
69
+ const formatBucketOutput = (logicalId, resource) => {
70
+ const lines = [];
71
+ const instance = resource.instances?.[0];
72
+ if (!instance)
73
+ return lines;
74
+ const bucketName = instance.bucketName || instance.id;
75
+ const region = resource.region;
76
+ const isOss = instance.type === types_1.ResourceTypeEnum.ALIYUN_OSS_BUCKET;
77
+ const isCos = instance.type === types_1.ResourceTypeEnum.COS_BUCKET;
78
+ lines.push(` 🪣 ${bucketName}`);
79
+ lines.push(` Region: ${region}`);
80
+ if (isOss) {
81
+ lines.push(` Endpoint: https://${bucketName}.oss-${region}.aliyuncs.com`);
82
+ }
83
+ else if (isCos) {
84
+ lines.push(` Endpoint: https://${bucketName}.cos.${region}.myqcloud.com`);
85
+ }
86
+ const dnsInstance = resource.instances?.find((inst) => inst.type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME ||
87
+ inst.type === types_1.ResourceTypeEnum.COS_DNS_CNAME);
88
+ const customDomain = dnsInstance?.domain || instance.customDomain;
89
+ if (customDomain) {
90
+ lines.push(` Custom Domain: ${customDomain}`);
91
+ if (dnsInstance?.cname) {
92
+ lines.push(` CNAME Target: ${dnsInstance.cname}`);
93
+ }
94
+ }
95
+ return lines;
96
+ };
97
+ const formatDatabaseOutput = (logicalId, resource) => {
98
+ const lines = [];
99
+ const instance = resource.instances?.[0];
100
+ if (!instance)
101
+ return lines;
102
+ const instanceId = instance.instanceId || instance.clusterId || instance.id;
103
+ const engine = instance.engine || instance.engineMode;
104
+ const status = instance.status;
105
+ lines.push(` 🗄️ ${instanceId}`);
106
+ if (engine) {
107
+ lines.push(` Engine: ${engine}`);
108
+ }
109
+ if (status) {
110
+ lines.push(` Status: ${status}`);
111
+ }
112
+ return lines;
113
+ };
114
+ const formatDnsOutput = (logicalId, resource) => {
115
+ const lines = [];
116
+ const instance = resource.instances?.[0];
117
+ if (!instance)
118
+ return lines;
119
+ const domain = instance.domain;
120
+ const cname = instance.cname;
121
+ const rr = instance.rr;
122
+ lines.push(` 🔀 ${domain || instance.id}`);
123
+ if (rr && cname) {
124
+ lines.push(` ${rr} -> ${cname}`);
125
+ }
126
+ else if (cname) {
127
+ lines.push(` CNAME: ${cname}`);
128
+ }
129
+ return lines;
130
+ };
131
+ const formatResourceOutput = (logicalId, resource) => {
132
+ const instance = resource.instances?.[0];
133
+ if (!instance)
134
+ return [];
135
+ const type = instance.type;
136
+ if (type === types_1.ResourceTypeEnum.ALIYUN_FC3_FUNCTION || type === types_1.ResourceTypeEnum.SCF_FUNCTION) {
137
+ return formatFunctionOutput(logicalId, resource);
138
+ }
139
+ if (type === types_1.ResourceTypeEnum.ALIYUN_APIGW_GROUP || type === types_1.ResourceTypeEnum.ALIYUN_APIGW_API) {
140
+ return formatApiGatewayOutput(logicalId, resource);
141
+ }
142
+ if (type === types_1.ResourceTypeEnum.ALIYUN_OSS_BUCKET || type === types_1.ResourceTypeEnum.COS_BUCKET) {
143
+ return formatBucketOutput(logicalId, resource);
144
+ }
145
+ if (type === types_1.ResourceTypeEnum.ALIYUN_RDS_SERVERLESS ||
146
+ type === types_1.ResourceTypeEnum.TDSQL_C_SERVERLESS ||
147
+ type === types_1.ResourceTypeEnum.ALIYUN_ES_SERVERLESS ||
148
+ type === types_1.ResourceTypeEnum.ALIYUN_TABLESTORE_TABLE) {
149
+ return formatDatabaseOutput(logicalId, resource);
150
+ }
151
+ if (type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME ||
152
+ type === types_1.ResourceTypeEnum.COS_DNS_CNAME ||
153
+ type === types_1.ResourceTypeEnum.ALIYUN_APIGW_DNS_VERIFICATION) {
154
+ return formatDnsOutput(logicalId, resource);
155
+ }
156
+ return [];
157
+ };
158
+ const loadLocalState = (provider, app, service, stage, baseDir) => {
159
+ return (0, common_1.loadState)(provider, app, service, stage, baseDir);
160
+ };
161
+ const readLocalLock = (app, service, baseDir) => {
162
+ const statePath = (0, common_1.getStatePath)(app, service, baseDir);
163
+ return (0, lockManager_1.readLockFileForCommand)(statePath);
164
+ };
165
+ const getBackendLocationString = (backendConfig) => {
166
+ if (!backendConfig || backendConfig.type === backend_1.StateBackendType.LOCAL) {
167
+ return 'local';
168
+ }
169
+ const config = backendConfig;
170
+ return `bucket://${config.bucket}/${config.key}`;
171
+ };
172
+ const show = async (options) => {
173
+ const context = (0, common_1.getContext)();
174
+ const stage = options.stage ?? context.stage;
175
+ const baseDir = options.location ?? process.cwd();
176
+ logger_1.logger.info(`Loading state for app: ${context.app}, service: ${context.service}, stage: ${stage}...`);
177
+ let state;
178
+ let lockInfo;
179
+ let stateLocation;
180
+ let usingRemoteBackend = false;
181
+ const shouldUseRemoteBackend = options.iac?.backend?.type === backend_1.StateBackendType.BUCKET_STORE;
182
+ if (shouldUseRemoteBackend && (0, common_1.hasCredentials)(context)) {
183
+ try {
184
+ const backend = (0, stateBackend_1.createStateBackend)(options.iac.backend, context);
185
+ state = await backend.loadState(context.provider, context.app, context.service, stage);
186
+ lockInfo = await backend.readLock();
187
+ usingRemoteBackend = true;
188
+ stateLocation = getBackendLocationString(options.iac.backend);
189
+ }
190
+ catch (error) {
191
+ logger_1.logger.warn(`Failed to load state from remote backend, falling back to local state: ${error}`);
192
+ state = loadLocalState(context.provider, context.app, context.service, stage, baseDir);
193
+ lockInfo = readLocalLock(context.app, context.service, baseDir);
194
+ stateLocation = (0, common_1.getStatePath)(context.app, context.service, baseDir);
195
+ }
196
+ }
197
+ else {
198
+ if (shouldUseRemoteBackend && !(0, common_1.hasCredentials)(context)) {
199
+ logger_1.logger.warn('Remote backend configured but credentials not available. Falling back to local state.');
200
+ }
201
+ state = loadLocalState(context.provider, context.app, context.service, stage, baseDir);
202
+ lockInfo = readLocalLock(context.app, context.service, baseDir);
203
+ stateLocation = (0, common_1.getStatePath)(context.app, context.service, baseDir);
204
+ }
205
+ const resources = state.resources;
206
+ const resourceCount = Object.keys(resources).length;
207
+ if (resourceCount === 0) {
208
+ logger_1.logger.info('No resources found in state.');
209
+ logger_1.logger.info('');
210
+ logger_1.logger.info(`State location: ${stateLocation}`);
211
+ if (usingRemoteBackend) {
212
+ logger_1.logger.info('Backend: Remote');
213
+ }
214
+ logger_1.logger.info('');
215
+ logger_1.logger.info('To deploy resources, run: si deploy');
216
+ return;
217
+ }
218
+ logger_1.logger.info('');
219
+ logger_1.logger.info('═'.repeat(60));
220
+ logger_1.logger.info('DEPLOYED RESOURCES');
221
+ logger_1.logger.info('═'.repeat(60));
222
+ const groupedResources = {};
223
+ for (const [logicalId, resource] of Object.entries(resources)) {
224
+ const instance = resource.instances?.[0];
225
+ const type = instance?.type || 'unknown';
226
+ const category = type.includes('FUNCTION')
227
+ ? 'functions'
228
+ : type.includes('APIGW')
229
+ ? 'apiGateway'
230
+ : type.includes('BUCKET')
231
+ ? 'storage'
232
+ : type.includes('DNS') || type.includes('CNAME')
233
+ ? 'dns'
234
+ : type.includes('RDS') ||
235
+ type.includes('TDSQL') ||
236
+ type.includes('ES_') ||
237
+ type.includes('TABLESTORE')
238
+ ? 'databases'
239
+ : 'other';
240
+ if (!groupedResources[category]) {
241
+ groupedResources[category] = [];
242
+ }
243
+ groupedResources[category].push([logicalId, resource]);
244
+ }
245
+ const categoryOrder = ['functions', 'apiGateway', 'storage', 'databases', 'dns', 'other'];
246
+ const categoryLabels = {
247
+ functions: 'Functions',
248
+ apiGateway: 'API Gateway',
249
+ storage: 'Storage',
250
+ databases: 'Databases',
251
+ dns: 'DNS Records',
252
+ other: 'Other Resources',
253
+ };
254
+ for (const category of categoryOrder) {
255
+ const resourcesInCategory = groupedResources[category];
256
+ if (!resourcesInCategory || resourcesInCategory.length === 0)
257
+ continue;
258
+ logger_1.logger.info('');
259
+ logger_1.logger.info(`📦 ${categoryLabels[category]}`);
260
+ logger_1.logger.info('─'.repeat(40));
261
+ for (const [logicalId, resource] of resourcesInCategory) {
262
+ const lines = formatResourceOutput(logicalId, resource);
263
+ for (const line of lines) {
264
+ logger_1.logger.info(line);
265
+ }
266
+ }
267
+ }
268
+ logger_1.logger.info('');
269
+ logger_1.logger.info('═'.repeat(60));
270
+ logger_1.logger.info('SUMMARY');
271
+ logger_1.logger.info('═'.repeat(60));
272
+ logger_1.logger.info('');
273
+ logger_1.logger.info(` Provider: ${state.provider}`);
274
+ logger_1.logger.info(` App: ${state.app}`);
275
+ logger_1.logger.info(` Service: ${state.service}`);
276
+ logger_1.logger.info(` Stage: ${stage}`);
277
+ logger_1.logger.info(` Resources: ${resourceCount}`);
278
+ if (Object.keys(resources).length > 0) {
279
+ const lastUpdated = Object.values(resources).reduce((latest, r) => {
280
+ if (!r.lastUpdated)
281
+ return latest;
282
+ if (!latest)
283
+ return r.lastUpdated;
284
+ return r.lastUpdated > latest ? r.lastUpdated : latest;
285
+ }, undefined);
286
+ if (lastUpdated) {
287
+ logger_1.logger.info(` Last Updated: ${formatTimeAgo(lastUpdated)}`);
288
+ }
289
+ }
290
+ logger_1.logger.info('');
291
+ logger_1.logger.info(`State location: ${stateLocation}`);
292
+ if (usingRemoteBackend) {
293
+ logger_1.logger.info('Backend: Remote');
294
+ }
295
+ if (lockInfo) {
296
+ logger_1.logger.info(`Lock Status: LOCKED by ${lockInfo.user || 'unknown'}`);
297
+ }
298
+ else {
299
+ logger_1.logger.info('Lock Status: UNLOCKED');
300
+ }
301
+ };
302
+ exports.show = show;
@@ -41,32 +41,16 @@ const logger_1 = require("../logger");
41
41
  const lang_1 = require("../../lang");
42
42
  const stateManager_1 = require("../stateManager");
43
43
  const sidUtils_1 = require("../sidUtils");
44
+ const domainUtils_1 = require("../domainUtils");
44
45
  const constants_1 = require("../constants");
45
46
  const removeUndefined = (obj) => {
46
47
  return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
47
48
  };
48
49
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
49
- const extractMainDomain = (domainName) => {
50
- const parts = domainName.split('.');
51
- if (parts.length <= 2) {
52
- return domainName;
53
- }
54
- return parts.slice(-2).join('.');
55
- };
56
- const extractHostRecord = (fullDomain, mainDomain) => {
57
- if (fullDomain === mainDomain) {
58
- return '@'; // @ represents the root domain
59
- }
60
- const suffix = `.${mainDomain}`;
61
- if (fullDomain.endsWith(suffix)) {
62
- return fullDomain.slice(0, -suffix.length);
63
- }
64
- return fullDomain;
65
- };
66
50
  const createApigwOperations = (apigwClient, dnsClient, _context) => {
67
51
  const dnsOps = (0, dnsOperations_1.createDnsOperations)(dnsClient);
68
52
  const buildTxtVerificationRecord = (groupId, domainName, groupSubdomain, mainDomain) => {
69
- const hostRecord = extractHostRecord(domainName, mainDomain);
53
+ const hostRecord = (0, domainUtils_1.extractHostRecord)(domainName, mainDomain);
70
54
  const rr = hostRecord === '@' ? groupId : `${groupId}.${hostRecord}`;
71
55
  // NOTE: "verfication" is Aliyun's actual typo in their API — must match exactly
72
56
  return { rr, value: `apigateway-domain-verfication=${groupSubdomain}` };
@@ -137,8 +121,8 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
137
121
  };
138
122
  const addDomainVerificationRecord = async (domainName, verificationToken, groupSubdomain, region, state, eventLogicalId) => {
139
123
  logger_1.logger.info(lang_1.lang.__('APIGW_DNS_ADDING_RECORD', { domain: domainName }));
140
- const mainDomain = extractMainDomain(domainName);
141
- const hostRecord = extractHostRecord(domainName, mainDomain);
124
+ const mainDomain = (0, domainUtils_1.extractMainDomain)(domainName);
125
+ const hostRecord = (0, domainUtils_1.extractHostRecord)(domainName, mainDomain);
142
126
  // For CNAME verification: point the domain directly to the group subdomain
143
127
  const verificationHost = domainName;
144
128
  const verificationValue = groupSubdomain;
@@ -251,7 +235,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
251
235
  }
252
236
  };
253
237
  const addTxtVerificationRecord = async (groupId, domainName, groupSubdomain, region, state, eventLogicalId) => {
254
- const mainDomain = extractMainDomain(domainName);
238
+ const mainDomain = (0, domainUtils_1.extractMainDomain)(domainName);
255
239
  const txtRecord = buildTxtVerificationRecord(groupId, domainName, groupSubdomain, mainDomain);
256
240
  const txtResourceId = `${eventLogicalId}.dns_txt_verification`;
257
241
  logger_1.logger.info(lang_1.lang.__('APIGW_TXT_ADDING_RECORD', { rr: txtRecord.rr, value: txtRecord.value }));
@@ -305,7 +289,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
305
289
  }
306
290
  };
307
291
  const logVerificationInstructions = (domainName, groupId, groupSubdomain) => {
308
- const mainDomain = extractMainDomain(domainName);
292
+ const mainDomain = (0, domainUtils_1.extractMainDomain)(domainName);
309
293
  const txtRecord = buildTxtVerificationRecord(groupId, domainName, groupSubdomain, mainDomain);
310
294
  const separator = '='.repeat(80);
311
295
  logger_1.logger.error(`\n${separator}\n${lang_1.lang.__('APIGW_VERIFICATION_HEADER')}\n${separator}\n${lang_1.lang.__('APIGW_VERIFICATION_DOMAIN', { domain: domainName })}\n\n${lang_1.lang.__('APIGW_VERIFICATION_INSTRUCTIONS')}\n\n${lang_1.lang.__('APIGW_VERIFICATION_OPTION1')}\n${lang_1.lang.__('APIGW_VERIFICATION_RECORD_NAME', { name: domainName })}\n${lang_1.lang.__('APIGW_VERIFICATION_RECORD_TYPE', { type: 'CNAME' })}\n${lang_1.lang.__('APIGW_VERIFICATION_RECORD_VALUE', { value: groupSubdomain })}\n\n${lang_1.lang.__('APIGW_VERIFICATION_OPTION2')}\n${lang_1.lang.__('APIGW_VERIFICATION_RECORD_NAME', { name: txtRecord.rr })}\n${lang_1.lang.__('APIGW_VERIFICATION_RECORD_TYPE', { type: 'TXT' })}\n${lang_1.lang.__('APIGW_VERIFICATION_RECORD_VALUE', { value: txtRecord.value })}`);
@@ -127,17 +127,18 @@ const initializeSdkClients = (context) => {
127
127
  };
128
128
  const createAliyunClient = (context) => {
129
129
  const sdkClients = initializeSdkClients(context);
130
+ const dnsOps = (0, dnsOperations_1.createDnsOperations)(sdkClients.dns);
130
131
  return {
131
132
  fc3: (0, fc3Operations_1.createFc3Operations)(sdkClients.fc3),
132
133
  sls: (0, slsOperations_1.createSlsOperations)(sdkClients.sls),
133
134
  ram: (0, ramOperations_1.createRamOperations)(sdkClients.ram),
134
135
  ecs: (0, ecsOperations_1.createEcsOperations)(sdkClients.ecs, context),
135
136
  nas: (0, nasOperations_1.createNasOperations)(sdkClients.nas),
136
- oss: (0, ossOperations_1.createOssOperations)(sdkClients.oss, context.region),
137
+ oss: (0, ossOperations_1.createOssOperations)(sdkClients.oss, context.region, dnsOps),
137
138
  apigw: (0, apigwOperations_1.createApigwOperations)(sdkClients.apigw, sdkClients.dns, context),
138
139
  rds: (0, rdsOperations_1.createRdsOperations)(sdkClients.rds, context),
139
140
  es: (0, esOperations_1.createEsOperations)(sdkClients.es, context),
140
- dns: (0, dnsOperations_1.createDnsOperations)(sdkClients.dns),
141
+ dns: dnsOps,
141
142
  tablestore: (instanceName) => (0, tablestoreOperations_1.createTablestoreOperations)(`https://${instanceName}.${context.region}.ots.aliyuncs.com`, instanceName, context),
142
143
  };
143
144
  };