@geek-fun/serverlessinsight 0.8.2 → 0.8.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.
Files changed (124) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +15 -0
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
  3. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
  4. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
  5. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -0
  6. package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
  7. package/README.md +26 -18
  8. package/README.zh-CN.md +19 -6
  9. package/dist/package.json +5 -2
  10. package/dist/src/commands/deploy.js +87 -4
  11. package/dist/src/commands/destroy.js +61 -10
  12. package/dist/src/commands/forceUnlock.js +8 -0
  13. package/dist/src/commands/index.js +34 -2
  14. package/dist/src/commands/login.js +195 -0
  15. package/dist/src/commands/logout.js +17 -0
  16. package/dist/src/commands/show.js +15 -7
  17. package/dist/src/commands/whoami.js +20 -0
  18. package/dist/src/common/aliyunClient/apigwOperations.js +363 -30
  19. package/dist/src/common/aliyunClient/esOperations.js +43 -29
  20. package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
  21. package/dist/src/common/aliyunClient/ossOperations.js +165 -13
  22. package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
  23. package/dist/src/common/aliyunClient/slsOperations.js +90 -28
  24. package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
  25. package/dist/src/common/apiClient.js +102 -0
  26. package/dist/src/common/constants.js +13 -4
  27. package/dist/src/common/credentialStore.js +94 -0
  28. package/dist/src/common/credentials.js +2 -0
  29. package/dist/src/common/eventQueue.js +208 -0
  30. package/dist/src/common/hashUtils.js +87 -11
  31. package/dist/src/common/imsClient.js +1 -0
  32. package/dist/src/common/index.js +3 -0
  33. package/dist/src/common/lockManager.js +61 -54
  34. package/dist/src/common/logger.js +2 -0
  35. package/dist/src/common/polling.js +54 -0
  36. package/dist/src/common/reportResourceEvent.js +8 -0
  37. package/dist/src/common/runtimeMapper.js +11 -12
  38. package/dist/src/common/stateBackend/index.js +10 -1
  39. package/dist/src/common/stateBackend/localStateBackend.js +4 -1
  40. package/dist/src/common/stateBackend/remoteStateBackend.js +10 -4
  41. package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
  42. package/dist/src/common/stateManager.js +186 -14
  43. package/dist/src/common/tencentClient/clsOperations.js +137 -0
  44. package/dist/src/common/tencentClient/cosOperations.js +180 -3
  45. package/dist/src/common/tencentClient/esOperations.js +110 -46
  46. package/dist/src/common/tencentClient/index.js +43 -2
  47. package/dist/src/common/tencentClient/scfOperations.js +266 -133
  48. package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
  49. package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
  50. package/dist/src/common/triggerMapper.js +36 -0
  51. package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
  52. package/dist/src/common/volcengineClient/iamOperations.js +91 -48
  53. package/dist/src/common/volcengineClient/index.js +46 -21
  54. package/dist/src/common/volcengineClient/stsOperations.js +32 -0
  55. package/dist/src/common/volcengineClient/tlsOperations.js +305 -171
  56. package/dist/src/common/volcengineClient/tosOperations.js +78 -19
  57. package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
  58. package/dist/src/lang/en.js +107 -1
  59. package/dist/src/lang/zh-CN.js +107 -1
  60. package/dist/src/parser/eventParser.js +2 -0
  61. package/dist/src/parser/functionParser.js +96 -65
  62. package/dist/src/parser/index.js +7 -4
  63. package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
  64. package/dist/src/stack/aliyunStack/apigwPlanner.js +16 -10
  65. package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
  66. package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
  67. package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
  68. package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
  69. package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
  70. package/dist/src/stack/aliyunStack/deployer.js +2 -2
  71. package/dist/src/stack/aliyunStack/destroyer.js +27 -2
  72. package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
  73. package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
  74. package/dist/src/stack/aliyunStack/fc3Resource.js +416 -94
  75. package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
  76. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  77. package/dist/src/stack/aliyunStack/ossResource.js +267 -219
  78. package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
  79. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
  80. package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
  81. package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
  82. package/dist/src/stack/alreadyExists.js +26 -0
  83. package/dist/src/stack/ownershipTag.js +58 -0
  84. package/dist/src/stack/rfsStack/index.js +3 -1
  85. package/dist/src/stack/scfStack/cosExecutor.js +39 -1
  86. package/dist/src/stack/scfStack/cosPlanner.js +11 -1
  87. package/dist/src/stack/scfStack/cosResource.js +167 -64
  88. package/dist/src/stack/scfStack/deployer.js +2 -2
  89. package/dist/src/stack/scfStack/destroyer.js +15 -2
  90. package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
  91. package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
  92. package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
  93. package/dist/src/stack/scfStack/scfExecutor.js +39 -1
  94. package/dist/src/stack/scfStack/scfPlanner.js +21 -3
  95. package/dist/src/stack/scfStack/scfResource.js +686 -24
  96. package/dist/src/stack/scfStack/scfTypes.js +6 -0
  97. package/dist/src/stack/scfStack/sharedLogset.js +126 -0
  98. package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
  99. package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
  100. package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
  101. package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
  102. package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
  103. package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
  104. package/dist/src/stack/volcengineStack/apigwResource.js +434 -222
  105. package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
  106. package/dist/src/stack/volcengineStack/deployer.js +49 -14
  107. package/dist/src/stack/volcengineStack/destroyer.js +13 -1
  108. package/dist/src/stack/volcengineStack/index.js +1 -2
  109. package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
  110. package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
  111. package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
  112. package/dist/src/stack/volcengineStack/tosResource.js +82 -27
  113. package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
  114. package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
  115. package/dist/src/stack/volcengineStack/vefaasPlanner.js +78 -2
  116. package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
  117. package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
  118. package/dist/src/types/domains/backend.js +1 -0
  119. package/dist/src/types/domains/state.js +32 -1
  120. package/dist/src/validator/eventSchema.js +10 -0
  121. package/dist/src/validator/functionSchema.js +37 -12
  122. package/dist/src/validator/iacSchema.js +1 -0
  123. package/dist/tsconfig.tsbuildinfo +1 -1
  124. package/package.json +5 -2
@@ -2,52 +2,72 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTdsqlcOperations = void 0;
4
4
  const types_1 = require("./types");
5
+ const tdsqlcClusterMapper_1 = require("./tdsqlcClusterMapper");
5
6
  const logger_1 = require("../logger");
6
7
  const lang_1 = require("../../lang");
8
+ const polling_1 = require("../polling");
7
9
  // TDSQL-C helper functions
8
10
  const waitForClusterReady = async (getCluster, clusterId) => {
9
- const maxAttempts = 60;
10
- let attempts = 0;
11
- while (attempts < maxAttempts) {
12
- const cluster = await getCluster(clusterId);
13
- if (!cluster) {
14
- throw new Error(lang_1.lang.__('TDSQL_CLUSTER_NOT_FOUND', { clusterId }));
15
- }
16
- if (cluster.Status === types_1.TdsqlcClusterStatus.RUNNING) {
17
- logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_READY', { clusterId }));
18
- return;
19
- }
20
- if (cluster.Status === types_1.TdsqlcClusterStatus.ISOLATED ||
21
- cluster.Status === types_1.TdsqlcClusterStatus.OFFLINE) {
22
- throw new Error(lang_1.lang.__('TDSQL_CLUSTER_ERROR_STATE', { status: cluster.Status }));
11
+ try {
12
+ await (0, polling_1.pollUntil)({
13
+ description: `TDSQL-C cluster ${clusterId} to be ready`,
14
+ fetch: async () => {
15
+ const cluster = await getCluster(clusterId);
16
+ if (!cluster) {
17
+ throw new Error(lang_1.lang.__('TDSQL_CLUSTER_NOT_FOUND', { clusterId }));
18
+ }
19
+ if (cluster.Status === types_1.TdsqlcClusterStatus.ISOLATED ||
20
+ cluster.Status === types_1.TdsqlcClusterStatus.OFFLINE) {
21
+ throw new Error(lang_1.lang.__('TDSQL_CLUSTER_ERROR_STATE', { status: cluster.Status }));
22
+ }
23
+ return cluster;
24
+ },
25
+ isDone: (cluster) => cluster?.Status === types_1.TdsqlcClusterStatus.RUNNING,
26
+ intervalMs: 10000,
27
+ maxAttempts: 60,
28
+ onProgress: (cluster) => {
29
+ if (cluster) {
30
+ logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_WAITING', { clusterId, status: cluster.Status }));
31
+ }
32
+ },
33
+ });
34
+ logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_READY', { clusterId }));
35
+ }
36
+ catch (e) {
37
+ if (e instanceof polling_1.PollingTimeoutError) {
38
+ throw new Error(lang_1.lang.__('TDSQL_CLUSTER_TIMEOUT_READY', { clusterId }), { cause: e });
23
39
  }
24
- logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_WAITING', { clusterId, status: cluster.Status }));
25
- await new Promise((resolve) => setTimeout(resolve, 10000));
26
- attempts++;
40
+ throw e;
27
41
  }
28
- throw new Error(lang_1.lang.__('TDSQL_CLUSTER_TIMEOUT_READY', { clusterId }));
29
42
  };
30
43
  const waitForClusterDeleted = async (getCluster, clusterId) => {
31
- const maxAttempts = 60;
32
- let attempts = 0;
33
- while (attempts < maxAttempts) {
34
- const cluster = await getCluster(clusterId);
35
- if (!cluster) {
36
- logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_DELETED', { clusterId }));
37
- return;
38
- }
39
- if (cluster.Status === types_1.TdsqlcClusterStatus.ISOLATED ||
40
- cluster.Status === types_1.TdsqlcClusterStatus.OFFLINE) {
41
- logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_BEING_DELETED', { clusterId }));
42
- await new Promise((resolve) => setTimeout(resolve, 10000));
43
- attempts++;
44
- continue;
44
+ try {
45
+ await (0, polling_1.pollUntil)({
46
+ description: `TDSQL-C cluster ${clusterId} to be deleted`,
47
+ fetch: () => getCluster(clusterId),
48
+ isDone: (cluster) => cluster === null,
49
+ intervalMs: 10000,
50
+ maxAttempts: 60,
51
+ onProgress: (cluster) => {
52
+ if (cluster) {
53
+ if (cluster.Status === types_1.TdsqlcClusterStatus.ISOLATED ||
54
+ cluster.Status === types_1.TdsqlcClusterStatus.OFFLINE) {
55
+ logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_BEING_DELETED', { clusterId }));
56
+ }
57
+ else {
58
+ logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_WAITING_DELETE', { clusterId, status: cluster.Status }));
59
+ }
60
+ }
61
+ },
62
+ });
63
+ logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_DELETED', { clusterId }));
64
+ }
65
+ catch (e) {
66
+ if (e instanceof polling_1.PollingTimeoutError) {
67
+ throw new Error(lang_1.lang.__('TDSQL_CLUSTER_TIMEOUT_DELETE', { clusterId }), { cause: e });
45
68
  }
46
- logger_1.logger.info(lang_1.lang.__('TDSQL_CLUSTER_WAITING_DELETE', { clusterId, status: cluster.Status }));
47
- await new Promise((resolve) => setTimeout(resolve, 10000));
48
- attempts++;
69
+ throw e;
49
70
  }
50
- throw new Error(lang_1.lang.__('TDSQL_CLUSTER_TIMEOUT_DELETE', { clusterId }));
51
71
  };
52
72
  // TDSQL-C operations
53
73
  const createTdsqlcOperations = (cynosdbClient, context) => {
@@ -71,6 +91,7 @@ const createTdsqlcOperations = (cynosdbClient, context) => {
71
91
  AutoPauseDelay: config.AutoPauseDelay,
72
92
  StoragePayMode: config.StoragePayMode,
73
93
  StorageLimit: config.MaxStorageSize,
94
+ ...(config.ResourceTags ? { ResourceTags: config.ResourceTags } : {}),
74
95
  };
75
96
  try {
76
97
  const response = await cynosdbClient.CreateClusters(params);
@@ -103,73 +124,46 @@ const createTdsqlcOperations = (cynosdbClient, context) => {
103
124
  if (!response.ClusterSet || response.ClusterSet.length === 0) {
104
125
  return null;
105
126
  }
106
- const cluster = response.ClusterSet[0];
107
- return {
108
- ClusterId: cluster.ClusterId || '',
109
- ClusterName: cluster.ClusterName || '',
110
- Region: cluster.Region || context.region,
111
- Zone: cluster.Zone,
112
- PhysicalZone: cluster.PhysicalZone,
113
- DbType: cluster.DbType || '',
114
- DbVersion: cluster.DbVersion || '',
115
- DbMode: cluster.DbMode,
116
- Status: cluster.Status || '',
117
- StatusDesc: cluster.StatusDesc,
118
- ServerlessStatus: cluster.ServerlessStatus,
119
- VpcId: cluster.VpcId,
120
- VpcName: undefined,
121
- SubnetId: cluster.SubnetId,
122
- SubnetName: undefined,
123
- Charset: undefined,
124
- Vip: cluster.Vip,
125
- Vport: cluster.Vport,
126
- WanDomain: undefined,
127
- WanIP: undefined,
128
- WanPort: undefined,
129
- WanStatus: undefined,
130
- MinCpu: undefined,
131
- MaxCpu: undefined,
132
- MinStorageSize: cluster.MinStorageSize,
133
- MaxStorageSize: cluster.MaxStorageSize,
134
- StorageId: cluster.StorageId,
135
- Storage: cluster.Storage,
136
- StorageLimit: cluster.StorageLimit,
137
- StoragePayMode: cluster.StoragePayMode,
138
- AutoPause: cluster.ServerlessStatus,
139
- AutoPauseDelay: undefined,
140
- CreateTime: cluster.CreateTime,
141
- UpdateTime: cluster.UpdateTime,
142
- ProjectId: cluster.ProjectID,
143
- PayMode: cluster.PayMode,
144
- PeriodEndTime: cluster.PeriodEndTime,
145
- AutoRenewFlag: cluster.RenewFlag,
146
- InstanceCount: cluster.InstanceNum,
147
- ProcessingTask: cluster.ProcessingTask,
148
- SupportedFeatures: undefined,
149
- RollbackSupport: undefined,
150
- NetworkType: undefined,
151
- ResourcePackageId: undefined,
152
- ResourcePackageType: undefined,
153
- ResourcePackageState: undefined,
154
- PhysicalRegion: undefined,
155
- ProxyStatus: undefined,
156
- RwGroupId: undefined,
157
- MasterZone: cluster.MasterZone,
158
- SlaveZones: cluster.SlaveZones,
159
- BusinessType: cluster.BusinessType,
160
- IsFreeze: cluster.IsFreeze,
161
- OrderSource: cluster.OrderSource,
162
- Ability: cluster.Ability,
163
- ResourceTags: cluster.ResourceTags,
164
- CynosVersion: cluster.CynosVersion,
165
- CynosVersionStatus: undefined,
166
- IsLatestVersion: undefined,
167
- };
127
+ return (0, tdsqlcClusterMapper_1.mapClusterToInfo)(response.ClusterSet[0], context.region);
168
128
  }
169
129
  catch (error) {
170
- logger_1.logger.error(`${lang_1.lang.__('TDSQL_CLUSTER_GET_FAILED')}: ${error}`);
130
+ if (error &&
131
+ typeof error === 'object' &&
132
+ 'code' in error &&
133
+ typeof error.code === 'string' &&
134
+ error.code.startsWith('ResourceNotFound')) {
135
+ return null;
136
+ }
137
+ throw error;
138
+ }
139
+ },
140
+ // DescribeClusters filters only support ClusterId/InstanceId/InstanceName
141
+ // (SDK QueryFilter docs), so a name probe lists clusters and matches by
142
+ // ClusterName client-side. Pages up to 500 clusters (5 requests).
143
+ getClusterByName: async (clusterName) => {
144
+ try {
145
+ for (let offset = 0; offset < 500; offset += 100) {
146
+ const response = await cynosdbClient.DescribeClusters({ Limit: 100, Offset: offset });
147
+ const cluster = (response.ClusterSet ?? []).find((c) => c.ClusterName === clusterName);
148
+ if (cluster) {
149
+ return (0, tdsqlcClusterMapper_1.mapClusterToInfo)(cluster, context.region);
150
+ }
151
+ if (!response.ClusterSet || response.ClusterSet.length < 100) {
152
+ break;
153
+ }
154
+ }
171
155
  return null;
172
156
  }
157
+ catch (error) {
158
+ if (error &&
159
+ typeof error === 'object' &&
160
+ 'code' in error &&
161
+ typeof error.code === 'string' &&
162
+ error.code.startsWith('ResourceNotFound')) {
163
+ return null;
164
+ }
165
+ throw error;
166
+ }
173
167
  },
174
168
  updateCluster: async (clusterId, config) => {
175
169
  const params = {
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapAliyunAccess = exports.mapAccess = exports.mapAuthType = void 0;
4
+ const providerEnum_1 = require("./providerEnum");
5
+ const mapAuthType = (provider, authType) => {
6
+ switch (provider) {
7
+ case providerEnum_1.ProviderEnum.TENCENT:
8
+ return authType === 'public' ? 'NONE' : 'CAM';
9
+ case providerEnum_1.ProviderEnum.ALIYUN:
10
+ return authType === 'public' ? 'anonymous' : 'function';
11
+ case providerEnum_1.ProviderEnum.AWS:
12
+ return authType === 'public' ? 'NONE' : 'AWS_IAM';
13
+ default:
14
+ return authType === 'public' ? 'NONE' : 'CAM';
15
+ }
16
+ };
17
+ exports.mapAuthType = mapAuthType;
18
+ const mapAccess = (access) => {
19
+ if (!access || access.length === 0) {
20
+ return {};
21
+ }
22
+ return {
23
+ enableExtranet: access.includes('public'),
24
+ enableIntranet: access.includes('internal'),
25
+ };
26
+ };
27
+ exports.mapAccess = mapAccess;
28
+ const mapAliyunAccess = (access) => {
29
+ if (!access || access.length === 0) {
30
+ return {};
31
+ }
32
+ return {
33
+ disableURLInternet: !access.includes('public') && access.includes('internal'),
34
+ };
35
+ };
36
+ exports.mapAliyunAccess = mapAliyunAccess;