@geek-fun/serverlessinsight 0.5.3 → 0.5.4

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.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
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",
@@ -39,6 +39,7 @@ const dnsOperations_1 = require("./dnsOperations");
39
39
  const logger_1 = require("../logger");
40
40
  const lang_1 = require("../../lang");
41
41
  const stateManager_1 = require("../stateManager");
42
+ const sidUtils_1 = require("../sidUtils");
42
43
  const removeUndefined = (obj) => {
43
44
  return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
44
45
  };
@@ -187,7 +188,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
187
188
  },
188
189
  instances: [
189
190
  {
190
- arn: `arn:acs:alidns:${region}:dns-record/${recordId}`,
191
+ sid: (0, sidUtils_1.buildSid)('aliyun', 'alidns', _context.stage, recordId),
191
192
  id: recordId,
192
193
  type: 'CNAME',
193
194
  status: 'PENDING',
@@ -213,7 +214,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
213
214
  },
214
215
  instances: [
215
216
  {
216
- arn: `arn:acs:alidns:${region}:dns-record/existing`,
217
+ sid: (0, sidUtils_1.buildSid)('aliyun', 'alidns', _context.stage, 'existing'),
217
218
  id: 'existing',
218
219
  type: 'CNAME',
219
220
  status: 'EXISTING',
@@ -30,3 +30,4 @@ __exportStar(require("./scfClient"), exports);
30
30
  __exportStar(require("./runtimeMapper"), exports);
31
31
  __exportStar(require("./hashUtils"), exports);
32
32
  __exportStar(require("./dependencyGraph"), exports);
33
+ __exportStar(require("./sidUtils"), exports);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * ServerlessInsight ID (SID) — logical resource identifier.
4
+ *
5
+ * Format: si:<provider>:<service>:<stage>:<id>
6
+ * Example: si:aliyun:rds:default:rm-abc123
7
+ *
8
+ * SID is a tool-generated identifier that uniquely locates a resource
9
+ * within a ServerlessInsight deployment. It is NOT a cloud-provider
10
+ * identifier — the provider-returned physical ID is stored separately
11
+ * in the `id` field of ResourceInstance.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.buildSid = void 0;
15
+ /**
16
+ * Build a ServerlessInsight ID (SID).
17
+ *
18
+ * @param provider - Cloud provider name (e.g. 'aliyun', 'tencent')
19
+ * @param service - Cloud service name (e.g. 'fc3', 'oss', 'rds', 'scf')
20
+ * @param stage - Deployment stage (e.g. 'default', 'dev', 'prod')
21
+ * @param id - Provider-returned physical resource identifier
22
+ */
23
+ const buildSid = (provider, service, stage, id) => `si:${provider}:${service}:${stage}:${id}`;
24
+ exports.buildSid = buildSid;
@@ -124,8 +124,8 @@ const getRoleArnFromState = (state) => {
124
124
  for (const [logicalId, resourceState] of Object.entries(allResources)) {
125
125
  if (logicalId.startsWith('functions.')) {
126
126
  const ramRoleInstance = resourceState.instances?.find((i) => i.type === 'ALIYUN_RAM_ROLE');
127
- if (ramRoleInstance?.arn) {
128
- return ramRoleInstance.arn;
127
+ if (ramRoleInstance?.roleArn) {
128
+ return ramRoleInstance.roleArn;
129
129
  }
130
130
  }
131
131
  }
@@ -4,12 +4,13 @@ exports.deleteApigwResource = exports.updateApigwResource = exports.readApigwRes
4
4
  const aliyunClient_1 = require("../../common/aliyunClient");
5
5
  const apigwTypes_1 = require("./apigwTypes");
6
6
  const stateManager_1 = require("../../common/stateManager");
7
+ const common_1 = require("../../common");
7
8
  const logger_1 = require("../../common/logger");
8
9
  const lang_1 = require("../../lang");
9
- const buildApigwGroupInstanceFromProvider = (info, region) => {
10
+ const buildApigwGroupInstanceFromProvider = (info, stage) => {
10
11
  return {
11
12
  type: 'ALIYUN_APIGW_GROUP',
12
- arn: `arn:acs:apigateway:${region}:group/${info.groupId}`,
13
+ sid: (0, common_1.buildSid)('aliyun', 'apigateway', stage, info.groupId ?? ''),
13
14
  id: info.groupId ?? '',
14
15
  groupId: info.groupId ?? null,
15
16
  groupName: info.groupName ?? null,
@@ -26,10 +27,10 @@ const buildApigwGroupInstanceFromProvider = (info, region) => {
26
27
  trafficLimit: info.trafficLimit ?? null,
27
28
  };
28
29
  };
29
- const buildApigwApiInstanceFromProvider = (info, region, groupId) => {
30
+ const buildApigwApiInstanceFromProvider = (info, stage, groupId) => {
30
31
  return {
31
32
  type: 'ALIYUN_APIGW_API',
32
- arn: `arn:acs:apigateway:${region}:group/${groupId}/api/${info.apiId}`,
33
+ sid: (0, common_1.buildSid)('aliyun', 'apigateway', stage, `${groupId}/${info.apiId}`),
33
34
  id: info.apiId ?? '',
34
35
  apiId: info.apiId ?? null,
35
36
  apiName: info.apiName ?? null,
@@ -45,10 +46,10 @@ const buildApigwApiInstanceFromProvider = (info, region, groupId) => {
45
46
  modifiedTime: info.modifiedTime ?? null,
46
47
  };
47
48
  };
48
- const buildApigwDeploymentInstance = (groupId, apiId, stageName, region) => {
49
+ const buildApigwDeploymentInstance = (groupId, apiId, stageName, stage) => {
49
50
  return {
50
51
  type: 'ALIYUN_APIGW_DEPLOYMENT',
51
- arn: `arn:acs:apigateway:${region}:group/${groupId}/api/${apiId}/deployment/${stageName}`,
52
+ sid: (0, common_1.buildSid)('aliyun', 'apigateway', stage, `${groupId}/${apiId}/${stageName}`),
52
53
  id: `${groupId}/${apiId}/${stageName}`,
53
54
  groupId,
54
55
  apiId,
@@ -80,7 +81,7 @@ const createApigwResource = async (context, event, serviceName, roleArn, state)
80
81
  throw new Error(`Failed to get API group info after creation: ${groupId}`);
81
82
  }
82
83
  const instances = [
83
- buildApigwGroupInstanceFromProvider(groupInfo, context.region),
84
+ buildApigwGroupInstanceFromProvider(groupInfo, context.stage),
84
85
  ];
85
86
  const groupDefinition = (0, apigwTypes_1.extractApigwGroupDefinition)(groupConfig);
86
87
  const partialResourceState = {
@@ -111,7 +112,7 @@ const createApigwResource = async (context, event, serviceName, roleArn, state)
111
112
  // Get API info for state
112
113
  const apiInfo = await client.apigw.getApi(groupId, apiId);
113
114
  if (apiInfo) {
114
- instances.push(buildApigwApiInstanceFromProvider(apiInfo, context.region, groupId));
115
+ instances.push(buildApigwApiInstanceFromProvider(apiInfo, context.stage, groupId));
115
116
  }
116
117
  // Deploy API to RELEASE stage
117
118
  const deploymentConfig = {
@@ -121,7 +122,7 @@ const createApigwResource = async (context, event, serviceName, roleArn, state)
121
122
  description: `${serviceName} API deployment for ${trigger.method} ${trigger.path}`,
122
123
  };
123
124
  await client.apigw.deployApi(deploymentConfig);
124
- instances.push(buildApigwDeploymentInstance(groupId, apiId, 'RELEASE', context.region));
125
+ instances.push(buildApigwDeploymentInstance(groupId, apiId, 'RELEASE', context.stage));
125
126
  const updatedResourceState = {
126
127
  mode: 'managed',
127
128
  region: context.region,
@@ -215,7 +216,7 @@ const updateApigwResource = async (context, event, serviceName, roleArn, state)
215
216
  throw new Error(`Failed to get API group info after update: ${groupId}`);
216
217
  }
217
218
  const instances = [
218
- buildApigwGroupInstanceFromProvider(groupInfo, context.region),
219
+ buildApigwGroupInstanceFromProvider(groupInfo, context.stage),
219
220
  ];
220
221
  const existingApis = existingInstances.filter((i) => i.type === 'ALIYUN_APIGW_API');
221
222
  const neededApiKeys = new Set();
@@ -236,7 +237,7 @@ const updateApigwResource = async (context, event, serviceName, roleArn, state)
236
237
  }
237
238
  const apiInfo = await client.apigw.getApi(groupId, apiId);
238
239
  if (apiInfo) {
239
- instances.push(buildApigwApiInstanceFromProvider(apiInfo, context.region, groupId));
240
+ instances.push(buildApigwApiInstanceFromProvider(apiInfo, context.stage, groupId));
240
241
  }
241
242
  const deploymentConfig = {
242
243
  groupId,
@@ -245,7 +246,7 @@ const updateApigwResource = async (context, event, serviceName, roleArn, state)
245
246
  description: `${serviceName} API deployment for ${trigger.method} ${trigger.path}`,
246
247
  };
247
248
  await client.apigw.deployApi(deploymentConfig);
248
- instances.push(buildApigwDeploymentInstance(groupId, apiId, 'RELEASE', context.region));
249
+ instances.push(buildApigwDeploymentInstance(groupId, apiId, 'RELEASE', context.stage));
249
250
  }
250
251
  for (const existingApi of existingApis) {
251
252
  const apiInfo = await client.apigw.getApi(groupId, existingApi.id);
@@ -5,9 +5,11 @@ const aliyunClient_1 = require("../../common/aliyunClient");
5
5
  const rdsTypes_1 = require("./rdsTypes");
6
6
  const esServerlessTypes_1 = require("./esServerlessTypes");
7
7
  const stateManager_1 = require("../../common/stateManager");
8
- const buildRdsInstanceFromProvider = (info, arn) => {
8
+ const common_1 = require("../../common");
9
+ const logger_1 = require("../../common/logger");
10
+ const buildRdsInstanceFromProvider = (info, sid) => {
9
11
  return {
10
- arn,
12
+ sid,
11
13
  id: info.dbInstanceId ?? '',
12
14
  dbInstanceId: info.dbInstanceId ?? null,
13
15
  dbInstanceDescription: info.dbInstanceDescription ?? null,
@@ -38,9 +40,9 @@ const buildRdsInstanceFromProvider = (info, arn) => {
38
40
  multiAZ: info.multiAZ ?? null,
39
41
  };
40
42
  };
41
- const buildEsInstanceFromProvider = (info, arn) => {
43
+ const buildEsInstanceFromProvider = (info, sid) => {
42
44
  return {
43
- arn,
45
+ sid,
44
46
  id: info.appId ?? '',
45
47
  appId: info.appId ?? null,
46
48
  appName: info.appName ?? null,
@@ -98,7 +100,6 @@ const createDatabaseResource = async (context, database, state) => {
98
100
  let instanceId;
99
101
  let definition;
100
102
  let instance;
101
- let arn;
102
103
  let resourceType;
103
104
  if (database.type === "ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */) {
104
105
  // Create Elasticsearch Serverless app
@@ -110,8 +111,8 @@ const createDatabaseResource = async (context, database, state) => {
110
111
  throw new Error(`Failed to refresh state for ES app: ${instanceId}`);
111
112
  }
112
113
  definition = (0, esServerlessTypes_1.extractEsDefinition)(config);
113
- arn = `arn:acs:elasticsearch:${context.region}:${context.accountId}:serverless:${instanceId}`;
114
- instance = buildEsInstanceFromProvider(appInfo, arn);
114
+ const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
115
+ instance = buildEsInstanceFromProvider(appInfo, sid);
115
116
  resourceType = 'ALIYUN_ES_SERVERLESS';
116
117
  }
117
118
  else if ([
@@ -128,8 +129,8 @@ const createDatabaseResource = async (context, database, state) => {
128
129
  throw new Error(`Failed to refresh state for RDS instance: ${instanceId}`);
129
130
  }
130
131
  definition = (0, rdsTypes_1.extractRdsDefinition)(config);
131
- arn = `arn:acs:rds:${context.region}:${context.accountId}:dbinstance:${instanceId}`;
132
- instance = buildRdsInstanceFromProvider(rdsInfo, arn);
132
+ const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
133
+ instance = buildRdsInstanceFromProvider(rdsInfo, sid);
133
134
  resourceType = 'ALIYUN_RDS_SERVERLESS';
134
135
  }
135
136
  else {
@@ -167,7 +168,6 @@ const updateDatabaseResource = async (context, database, instanceId, resourceTyp
167
168
  const client = (0, aliyunClient_1.createAliyunClient)(context);
168
169
  let definition;
169
170
  let instance;
170
- let arn;
171
171
  if (resourceType === 'ALIYUN_ES_SERVERLESS') {
172
172
  const config = (0, esServerlessTypes_1.databaseToEsConfig)(database);
173
173
  await client.es.updateApp(instanceId, config);
@@ -177,8 +177,8 @@ const updateDatabaseResource = async (context, database, instanceId, resourceTyp
177
177
  throw new Error(`Failed to refresh state for ES app: ${instanceId}`);
178
178
  }
179
179
  definition = (0, esServerlessTypes_1.extractEsDefinition)(config);
180
- arn = `arn:acs:elasticsearch:${context.region}:${context.accountId}:serverless:${instanceId}`;
181
- instance = buildEsInstanceFromProvider(appInfo, arn);
180
+ const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
181
+ instance = buildEsInstanceFromProvider(appInfo, sid);
182
182
  }
183
183
  else if (resourceType === 'ALIYUN_RDS_SERVERLESS') {
184
184
  const config = (0, rdsTypes_1.databaseToRdsConfig)(database);
@@ -189,8 +189,8 @@ const updateDatabaseResource = async (context, database, instanceId, resourceTyp
189
189
  throw new Error(`Failed to refresh state for RDS instance: ${instanceId}`);
190
190
  }
191
191
  definition = (0, rdsTypes_1.extractRdsDefinition)(config);
192
- arn = `arn:acs:rds:${context.region}:${context.accountId}:dbinstance:${instanceId}`;
193
- instance = buildRdsInstanceFromProvider(rdsInfo, arn);
192
+ const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
193
+ instance = buildRdsInstanceFromProvider(rdsInfo, sid);
194
194
  }
195
195
  else {
196
196
  throw new Error(`Unsupported resource type: ${resourceType}`);
@@ -214,14 +214,30 @@ const updateDatabaseResource = async (context, database, instanceId, resourceTyp
214
214
  exports.updateDatabaseResource = updateDatabaseResource;
215
215
  const deleteDatabaseResource = async (context, instanceId, resourceType, logicalId, state) => {
216
216
  const client = (0, aliyunClient_1.createAliyunClient)(context);
217
- if (resourceType === 'ALIYUN_ES_SERVERLESS') {
218
- await client.es.deleteApp(instanceId);
219
- }
220
- else if (resourceType === 'ALIYUN_RDS_SERVERLESS') {
221
- await client.rds.deleteInstance(instanceId);
217
+ try {
218
+ if (resourceType === 'ALIYUN_ES_SERVERLESS') {
219
+ await client.es.deleteApp(instanceId);
220
+ }
221
+ else if (resourceType === 'ALIYUN_RDS_SERVERLESS') {
222
+ await client.rds.deleteInstance(instanceId);
223
+ }
224
+ else {
225
+ throw new Error(`Unsupported resource type: ${resourceType}`);
226
+ }
222
227
  }
223
- else {
224
- throw new Error(`Unsupported resource type: ${resourceType}`);
228
+ catch (err) {
229
+ const errorCode = err?.code;
230
+ const errorMessage = err?.message ?? '';
231
+ if (errorCode === 'InvalidDBInstanceId.NotFound' ||
232
+ errorCode === 'AppNotFound' ||
233
+ errorCode === 'NotFound' ||
234
+ errorMessage.includes('not found') ||
235
+ errorMessage.includes('NotFound')) {
236
+ logger_1.logger.warn(`Database resource ${instanceId} not found in provider, skipping deletion`);
237
+ }
238
+ else {
239
+ throw err;
240
+ }
225
241
  }
226
242
  return (0, stateManager_1.removeResource)(state, logicalId);
227
243
  };
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeFunctionPlan = void 0;
4
+ const types_1 = require("../../types");
4
5
  const fc3Resource_1 = require("./fc3Resource");
5
6
  const common_1 = require("../../common");
6
7
  const stateManager_1 = require("../../common/stateManager");
7
- const lang_1 = require("../../lang");
8
8
  const executeCreateAction = async (context, fn, currentState) => {
9
9
  common_1.logger.info(`Creating function: ${fn.name}`);
10
10
  const newState = await (0, fc3Resource_1.createResource)(context, fn, currentState);
@@ -68,14 +68,24 @@ const executeFunctionPlan = async (context, plan, functions, initialState, onSta
68
68
  successfulItems.push(item);
69
69
  if (onStateChange) {
70
70
  onStateChange(currentState);
71
- common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
72
- action: item.action,
73
- resourceId: item.logicalId,
74
- }));
75
71
  }
76
72
  }
77
73
  }
78
74
  catch (error) {
75
+ if (error instanceof types_1.PartialResourceError) {
76
+ const updatedState = error.updatedState;
77
+ if (onStateChange) {
78
+ onStateChange(updatedState);
79
+ }
80
+ return {
81
+ state: updatedState,
82
+ partialFailure: {
83
+ failedItem: item,
84
+ error: error.cause,
85
+ successfulItems,
86
+ },
87
+ };
88
+ }
79
89
  return {
80
90
  state: currentState,
81
91
  partialFailure: {
@@ -26,7 +26,7 @@ const generateFunctionPlan = async (context, state, functions) => {
26
26
  const codePath = fn.code.path;
27
27
  const desiredCodeHash = (0, common_1.computeFileHash)(codePath);
28
28
  const desiredDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
29
- if (!currentState) {
29
+ if (!currentState || currentState.status === 'tainted') {
30
30
  return {
31
31
  logicalId,
32
32
  action: 'create',