@geek-fun/serverlessinsight 0.8.2 → 0.8.3

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 (119) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +14 -0
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
  3. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
  4. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
  5. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -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 +3 -1
  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 +327 -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 +56 -26
  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 +9 -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 +6 -3
  41. package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
  42. package/dist/src/common/stateManager.js +135 -13
  43. package/dist/src/common/tencentClient/cosOperations.js +180 -3
  44. package/dist/src/common/tencentClient/esOperations.js +110 -46
  45. package/dist/src/common/tencentClient/index.js +22 -1
  46. package/dist/src/common/tencentClient/scfOperations.js +255 -133
  47. package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
  48. package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
  49. package/dist/src/common/triggerMapper.js +36 -0
  50. package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
  51. package/dist/src/common/volcengineClient/iamOperations.js +58 -48
  52. package/dist/src/common/volcengineClient/index.js +46 -21
  53. package/dist/src/common/volcengineClient/stsOperations.js +32 -0
  54. package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
  55. package/dist/src/common/volcengineClient/tosOperations.js +78 -19
  56. package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
  57. package/dist/src/lang/en.js +84 -0
  58. package/dist/src/lang/zh-CN.js +84 -0
  59. package/dist/src/parser/eventParser.js +2 -0
  60. package/dist/src/parser/functionParser.js +96 -65
  61. package/dist/src/parser/index.js +7 -4
  62. package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
  63. package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
  64. package/dist/src/stack/aliyunStack/apigwResource.js +216 -124
  65. package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
  66. package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
  67. package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
  68. package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
  69. package/dist/src/stack/aliyunStack/deployer.js +2 -2
  70. package/dist/src/stack/aliyunStack/destroyer.js +2 -2
  71. package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
  72. package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
  73. package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
  74. package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
  75. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  76. package/dist/src/stack/aliyunStack/ossResource.js +267 -219
  77. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
  78. package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
  79. package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
  80. package/dist/src/stack/alreadyExists.js +26 -0
  81. package/dist/src/stack/ownershipTag.js +40 -0
  82. package/dist/src/stack/rfsStack/index.js +3 -1
  83. package/dist/src/stack/scfStack/cosExecutor.js +39 -1
  84. package/dist/src/stack/scfStack/cosPlanner.js +11 -1
  85. package/dist/src/stack/scfStack/cosResource.js +167 -64
  86. package/dist/src/stack/scfStack/deployer.js +2 -2
  87. package/dist/src/stack/scfStack/destroyer.js +2 -2
  88. package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
  89. package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
  90. package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
  91. package/dist/src/stack/scfStack/scfExecutor.js +39 -1
  92. package/dist/src/stack/scfStack/scfPlanner.js +12 -2
  93. package/dist/src/stack/scfStack/scfResource.js +484 -14
  94. package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
  95. package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
  96. package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
  97. package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
  98. package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
  99. package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
  100. package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
  101. package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
  102. package/dist/src/stack/volcengineStack/deployer.js +49 -14
  103. package/dist/src/stack/volcengineStack/destroyer.js +1 -1
  104. package/dist/src/stack/volcengineStack/index.js +1 -2
  105. package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
  106. package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
  107. package/dist/src/stack/volcengineStack/tosResource.js +82 -27
  108. package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
  109. package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
  110. package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
  111. package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
  112. package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
  113. package/dist/src/types/domains/backend.js +1 -0
  114. package/dist/src/types/domains/state.js +29 -1
  115. package/dist/src/validator/eventSchema.js +10 -0
  116. package/dist/src/validator/functionSchema.js +37 -12
  117. package/dist/src/validator/iacSchema.js +1 -0
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +3 -1
@@ -3,54 +3,137 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createApigwOperations = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const lang_1 = require("../../lang");
6
+ const polling_1 = require("../polling");
7
+ // Gateway provisioning is slow (mirrors the 30-minute Terraform timeout) —
8
+ // use a longer, gentler poll window than the 60s SCF default.
9
+ const APIGW_POLL_INTERVAL_MS = 10000;
10
+ const APIGW_POLL_MAX_ATTEMPTS = 120; // up to 20 minutes
6
11
  /* istanbul ignore next */ const createApigwOperations = (client) => {
7
12
  if (!client) {
13
+ const notInitialized = () => Promise.reject(new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED')));
8
14
  return {
9
- createGateway: async (_config) => {
10
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
11
- },
12
- getGateway: async (_gatewayId) => {
13
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
14
- },
15
- findGatewayByName: async (_gatewayName) => {
16
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
17
- },
18
- updateGateway: async (_gatewayId, _config) => {
19
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
20
- },
21
- deleteGateway: async (_gatewayId) => {
22
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
23
- },
24
- createApi: async (_config) => {
25
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
26
- },
27
- getApi: async (_gatewayId, _apiId) => {
28
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
29
- },
30
- updateApi: async (_apiId, _config) => {
31
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
32
- },
33
- deleteApi: async (_gatewayId, _apiId) => {
34
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
35
- },
36
- deployApi: async (_gatewayId, _apiId) => {
37
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
38
- },
39
- bindDomain: async (_config) => {
40
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
41
- },
42
- unbindDomain: async (_gatewayId, _domainName) => {
43
- throw new Error(lang_1.lang.__('VOLCENGINE_APIGW_CLIENT_NOT_INITIALIZED'));
44
- },
15
+ createGateway: async (_c) => notInitialized(),
16
+ getGateway: async (_id) => notInitialized(),
17
+ findGatewayByName: async (_n) => notInitialized(),
18
+ findServerlessGateway: async () => notInitialized(),
19
+ waitForGatewayRunning: async (_id) => notInitialized(),
20
+ updateGateway: async (_id, _c) => notInitialized(),
21
+ deleteGateway: async (_id) => notInitialized(),
22
+ updateGatewayLog: async (_id, _c) => notInitialized(),
23
+ createService: async (_c) => notInitialized(),
24
+ getService: async (_id) => notInitialized(),
25
+ findServiceByName: async (_g, _n) => notInitialized(),
26
+ deleteService: async (_id) => notInitialized(),
27
+ createUpstream: async (_c) => notInitialized(),
28
+ getUpstream: async (_id) => notInitialized(),
29
+ findUpstreamByName: async (_g, _n) => notInitialized(),
30
+ deleteUpstream: async (_id) => notInitialized(),
31
+ createRoute: async (_c) => notInitialized(),
32
+ getRoute: async (_id) => notInitialized(),
33
+ findRouteByName: async (_s, _n) => notInitialized(),
34
+ listRoutesByService: async (_s) => notInitialized(),
35
+ deleteRoute: async (_id) => notInitialized(),
36
+ createCustomDomain: async (_c) => notInitialized(),
37
+ deleteCustomDomain: async (_id) => notInitialized(),
45
38
  };
46
39
  }
40
+ const region = client.region ?? 'cn-beijing';
41
+ const parseGateway = (data) => {
42
+ const networkSpec = data.NetworkSpec;
43
+ const backendSpec = data.BackendSpec;
44
+ const monitorSpec = data.MonitorSpec;
45
+ const logSpec = data.LogSpec;
46
+ const resourceSpec = data.ResourceSpec;
47
+ const networkType = resourceSpec?.NetworkType;
48
+ return {
49
+ gatewayId: data.Id,
50
+ gatewayName: data.Name,
51
+ type: data.Type,
52
+ status: data.Status,
53
+ createdTime: data.CreatedTime,
54
+ // The provider returns the gateway description under `Comments` (not
55
+ // `Description`) — reading the wrong key left it always undefined.
56
+ description: data.Comments ?? data.Description,
57
+ message: data.Message,
58
+ tags: data.Tags?.map((t) => ({
59
+ Key: t.Key,
60
+ Value: t.Value,
61
+ })),
62
+ region: data.Region,
63
+ version: data.Version,
64
+ projectName: data.ProjectName,
65
+ networkSpec: networkSpec
66
+ ? {
67
+ vpcId: networkSpec.VpcId,
68
+ subnetIds: networkSpec.SubnetIds,
69
+ }
70
+ : undefined,
71
+ backendSpec: backendSpec
72
+ ? {
73
+ isVkeWithFlannelCniSupported: backendSpec.IsVkeWithFlannelCNISupported,
74
+ vkePodCidr: backendSpec.VkePodCidr,
75
+ }
76
+ : undefined,
77
+ monitorSpec: monitorSpec
78
+ ? {
79
+ enable: monitorSpec.Enable,
80
+ workspaceId: monitorSpec.WorkspaceId,
81
+ }
82
+ : undefined,
83
+ logSpec: logSpec
84
+ ? {
85
+ enable: logSpec.Enable,
86
+ projectId: logSpec.ProjectId,
87
+ topicId: logSpec.TopicId,
88
+ }
89
+ : undefined,
90
+ resourceSpec: resourceSpec
91
+ ? {
92
+ replicas: resourceSpec.Replicas,
93
+ instanceSpecCode: resourceSpec.InstanceSpecCode,
94
+ clbSpecCode: resourceSpec.ClbSpecCode,
95
+ publicNetworkBillingType: resourceSpec.PublicNetworkBillingType,
96
+ publicNetworkBandwidth: resourceSpec.PublicNetworkBandwidth,
97
+ networkType: networkType
98
+ ? {
99
+ enablePublicNetwork: networkType.EnablePublicNetwork,
100
+ enablePrivateNetwork: networkType.EnablePrivateNetwork,
101
+ }
102
+ : undefined,
103
+ }
104
+ : undefined,
105
+ };
106
+ };
107
+ // apig 无 GetGateway action;唯一读取是 ListGateways,项 ID 字段为 `Id`
108
+ // (对齐官方 terraform-provider-volcengine apig_gateway 实现)
109
+ const listGateways = async (filter) => {
110
+ const response = await client.fetchOpenAPI({
111
+ Action: 'ListGateways',
112
+ Version: '2021-03-03',
113
+ method: 'POST',
114
+ headers: { 'content-type': 'application/json' },
115
+ data: { Filter: filter, Region: region },
116
+ });
117
+ const result = (response.Result || {});
118
+ const items = (result.Items ?? []);
119
+ return items.map(parseGateway);
120
+ };
47
121
  return {
48
122
  createGateway: async (config) => {
49
- logger_1.logger.info(lang_1.lang.__('VOLCENGINE_CREATING_APIGW', { gatewayName: config.groupName }));
123
+ logger_1.logger.info(lang_1.lang.__('VOLCENGINE_CREATING_APIGW', { gatewayName: config.gatewayName }));
50
124
  const params = {
51
- Name: config.groupName,
52
- ...(config.description && { Description: config.description }),
53
- ...(config.protocol && { Protocol: config.protocol }),
125
+ Name: config.gatewayName,
126
+ Region: region,
127
+ Type: config.type ?? 'serverless',
128
+ // NetworkSpec (VPC + subnets) is REQUIRED by CreateGateway even for
129
+ // serverless gateways — verified live: omitting it returns
130
+ // "missing NetworkSpec parameter". ResourceSpec is optional; when
131
+ // present its InstanceSpecCode/Replicas become mandatory.
132
+ ...(config.network && {
133
+ NetworkSpec: { VpcId: config.network.vpcId, SubnetIds: config.network.subnetIds },
134
+ }),
135
+ ...(config.description && { Comments: config.description }),
136
+ ...(config.Tags && { Tags: config.Tags }),
54
137
  };
55
138
  const response = await client.fetchOpenAPI({
56
139
  Action: 'CreateGateway',
@@ -61,209 +144,506 @@ const lang_1 = require("../../lang");
61
144
  });
62
145
  const data = (response.Result || {});
63
146
  return {
64
- gatewayId: data.GatewayId,
65
- gatewayName: data.Name,
66
- protocol: data.Protocol,
67
- status: data.Status,
68
- createdTime: data.CreatedTime,
69
- description: data.Description,
70
- subDomain: data.SubDomain,
147
+ gatewayId: data.Id,
148
+ gatewayName: config.gatewayName,
149
+ type: config.type ?? 'serverless',
71
150
  };
72
151
  },
73
152
  getGateway: async (gatewayId) => {
153
+ const gateways = await listGateways({ Ids: [gatewayId] });
154
+ return gateways[0] ?? null;
155
+ },
156
+ findGatewayByName: async (gatewayName) => {
157
+ const gateways = await listGateways({ Name: gatewayName });
158
+ const match = gateways.find((g) => g.gatewayName === gatewayName);
159
+ return match ?? null;
160
+ },
161
+ findServerlessGateway: async () => {
162
+ const gateways = await listGateways({ Type: 'serverless' });
163
+ return gateways.find((g) => g.type === 'serverless') ?? null;
164
+ },
165
+ // Gateway creation is async — downstream calls (service/upstream/route)
166
+ // are rejected until the instance reaches Running.
167
+ waitForGatewayRunning: async (gatewayId) => {
168
+ const TERMINAL_FAILED_STATUSES = ['Failed', 'CreatedFailed', 'CreationFailed', 'Error'];
169
+ const gateway = await (0, polling_1.pollUntil)({
170
+ description: `API Gateway ${gatewayId} to be Running`,
171
+ fetch: async () => {
172
+ const gateways = await listGateways({ Ids: [gatewayId] });
173
+ const info = gateways[0] ?? null;
174
+ if (info && TERMINAL_FAILED_STATUSES.includes(info.status ?? '')) {
175
+ const reason = info.message
176
+ ? `: ${info.message}`
177
+ : ` (status ${info.status}) — check the Volcengine console for the gateway instance`;
178
+ throw new Error(`API Gateway ${gatewayId} creation failed${reason}`);
179
+ }
180
+ return info;
181
+ },
182
+ isDone: (info) => info?.status === 'Running',
183
+ intervalMs: APIGW_POLL_INTERVAL_MS,
184
+ maxAttempts: APIGW_POLL_MAX_ATTEMPTS,
185
+ onProgress: (info, attempt, maxAttempts) => {
186
+ logger_1.logger.info(lang_1.lang.__('VOLCENGINE_APIGW_WAITING_RUNNING', {
187
+ gatewayName: info?.gatewayName ?? gatewayId,
188
+ status: info?.status ?? 'unknown',
189
+ attempt: String(attempt),
190
+ maxAttempts: String(maxAttempts),
191
+ }));
192
+ },
193
+ });
194
+ if (!gateway) {
195
+ throw new Error(`API Gateway ${gatewayId} disappeared while waiting for Running`);
196
+ }
197
+ return gateway;
198
+ },
199
+ updateGateway: async (gatewayId, config) => {
200
+ await client.fetchOpenAPI({
201
+ Action: 'UpdateGateway',
202
+ Version: '2021-03-03',
203
+ method: 'POST',
204
+ headers: { 'content-type': 'application/json' },
205
+ data: {
206
+ Id: gatewayId,
207
+ ...(config.description && { Comments: config.description }),
208
+ },
209
+ });
210
+ },
211
+ updateGatewayLog: async (gatewayId, logConfig) => {
212
+ await client.fetchOpenAPI({
213
+ Action: 'UpdateGatewayLog',
214
+ Version: '2021-03-03',
215
+ method: 'POST',
216
+ headers: { 'content-type': 'application/json' },
217
+ data: {
218
+ Id: gatewayId,
219
+ LogSpec: {
220
+ Enable: logConfig.enable,
221
+ ...(logConfig.projectId && { ProjectId: logConfig.projectId }),
222
+ ...(logConfig.topicId && { TopicId: logConfig.topicId }),
223
+ },
224
+ },
225
+ });
226
+ if (logConfig.enable) {
227
+ logger_1.logger.info(lang_1.lang.__('APIGW_LOG_ENABLED', { gatewayId }));
228
+ }
229
+ else {
230
+ logger_1.logger.info(lang_1.lang.__('APIGW_LOG_DISABLED', { gatewayId }));
231
+ }
232
+ },
233
+ deleteGateway: async (gatewayId) => {
234
+ await client.fetchOpenAPI({
235
+ Action: 'DeleteGateway',
236
+ Version: '2021-03-03',
237
+ method: 'POST',
238
+ headers: { 'content-type': 'application/json' },
239
+ data: { Id: gatewayId },
240
+ });
241
+ },
242
+ createService: async (config) => {
243
+ logger_1.logger.info(lang_1.lang.__('VOLCENGINE_CREATING_APIGW_SERVICE', { serviceName: config.serviceName }));
244
+ const response = await client.fetchOpenAPI({
245
+ Action: 'CreateGatewayService',
246
+ Version: '2021-03-03',
247
+ method: 'POST',
248
+ headers: { 'content-type': 'application/json' },
249
+ data: {
250
+ GatewayId: config.gatewayId,
251
+ ServiceName: config.serviceName,
252
+ Protocol: config.protocol ?? ['HTTP'],
253
+ AuthSpec: { Enable: false },
254
+ ...(config.description && { Comments: config.description }),
255
+ },
256
+ });
257
+ const data = (response.Result || {});
258
+ return data.Id ?? '';
259
+ },
260
+ getService: async (serviceId) => {
74
261
  try {
75
262
  const response = await client.fetchOpenAPI({
76
- Action: 'GetGateway',
263
+ Action: 'GetGatewayService',
77
264
  Version: '2021-03-03',
78
265
  method: 'POST',
79
266
  headers: { 'content-type': 'application/json' },
80
- data: { GatewayId: gatewayId },
267
+ data: { Id: serviceId },
81
268
  });
82
- const data = (response.Result || {});
269
+ const result = (response.Result || {});
270
+ const data = (result.GatewayService ?? {});
271
+ const authSpec = data.AuthSpec;
83
272
  return {
273
+ serviceId: data.Id,
274
+ serviceName: data.Name,
84
275
  gatewayId: data.GatewayId,
85
- gatewayName: data.Name,
86
- protocol: data.Protocol,
87
276
  status: data.Status,
88
- createdTime: data.CreatedTime,
89
- description: data.Description,
90
- subDomain: data.SubDomain,
277
+ protocol: data.Protocol,
278
+ createdTime: data.CreateTime,
279
+ gatewayName: data.GatewayName,
280
+ message: data.Message,
281
+ comments: data.Comments ?? data.Description,
282
+ authSpec: authSpec ? { enable: authSpec.Enable } : undefined,
283
+ domains: data.Domains?.map((d) => ({
284
+ domain: d.Domain,
285
+ type: d.Type,
286
+ })),
287
+ customDomains: data.CustomDomains?.map((d) => ({
288
+ id: d.Id,
289
+ domain: d.Domain,
290
+ })),
91
291
  };
92
292
  }
93
293
  catch (error) {
94
- if (error && typeof error === 'object' && 'code' in error) {
95
- if (error.code === 'ResourceNotFound' || error.code === 'GatewayNotFound') {
96
- return null;
97
- }
294
+ const err = error;
295
+ if (err.code === 'NotFound' || err.code === 'ServiceNotFound') {
296
+ return null;
98
297
  }
99
298
  throw error;
100
299
  }
101
300
  },
102
- findGatewayByName: async (gatewayName) => {
301
+ findServiceByName: async (gatewayId, serviceName) => {
103
302
  const response = await client.fetchOpenAPI({
104
- Action: 'ListGateways',
303
+ Action: 'ListGatewayServices',
105
304
  Version: '2021-03-03',
106
305
  method: 'POST',
107
306
  headers: { 'content-type': 'application/json' },
108
- data: { Name: gatewayName },
307
+ data: { GatewayId: gatewayId, Filter: { Name: serviceName } },
109
308
  });
110
309
  const result = (response.Result || {});
111
- const gateways = (result.Gateways || []);
112
- const gateway = gateways.find((g) => g.Name === gatewayName);
113
- if (!gateway)
310
+ const items = (result.Items ?? []);
311
+ const match = items.find((s) => s.Name === serviceName);
312
+ if (!match) {
114
313
  return null;
314
+ }
315
+ const authSpec = match.AuthSpec;
115
316
  return {
116
- gatewayId: gateway.GatewayId,
117
- gatewayName: gateway.Name,
118
- protocol: gateway.Protocol,
119
- status: gateway.Status,
120
- createdTime: gateway.CreatedTime,
121
- description: gateway.Description,
122
- subDomain: gateway.SubDomain,
317
+ serviceId: match.Id,
318
+ serviceName: match.Name,
319
+ gatewayId: match.GatewayId,
320
+ status: match.Status,
321
+ protocol: match.Protocol,
322
+ createdTime: match.CreateTime,
323
+ gatewayName: match.GatewayName,
324
+ message: match.Message,
325
+ comments: match.Comments ?? match.Description,
326
+ authSpec: authSpec ? { enable: authSpec.Enable } : undefined,
327
+ domains: match.Domains?.map((d) => ({
328
+ domain: d.Domain,
329
+ type: d.Type,
330
+ })),
331
+ customDomains: match.CustomDomains?.map((d) => ({
332
+ id: d.Id,
333
+ domain: d.Domain,
334
+ })),
123
335
  };
124
336
  },
125
- updateGateway: async (gatewayId, config) => {
126
- const params = {
127
- GatewayId: gatewayId,
128
- Name: config.groupName,
129
- ...(config.description && { Description: config.description }),
130
- ...(config.protocol && { Protocol: config.protocol }),
131
- };
337
+ deleteService: async (serviceId) => {
132
338
  await client.fetchOpenAPI({
133
- Action: 'UpdateGateway',
339
+ Action: 'DeleteGatewayService',
134
340
  Version: '2021-03-03',
135
341
  method: 'POST',
136
342
  headers: { 'content-type': 'application/json' },
137
- data: params,
343
+ data: { Id: serviceId },
138
344
  });
139
345
  },
140
- deleteGateway: async (gatewayId) => {
141
- logger_1.logger.info(lang_1.lang.__('VOLCENGINE_DELETING_APIGW', { gatewayName: gatewayId }));
142
- await client.fetchOpenAPI({
143
- Action: 'DeleteGateway',
144
- Version: '2021-03-03',
145
- method: 'POST',
146
- headers: { 'content-type': 'application/json' },
147
- data: { GatewayId: gatewayId },
148
- });
149
- },
150
- createApi: async (config) => {
151
- const params = {
152
- GatewayId: config.gatewayId,
153
- Name: config.apiName,
154
- Method: config.method,
155
- Path: config.path,
156
- BackendType: 'Function',
157
- BackendConfig: {
158
- FunctionName: config.backendFunctionName,
159
- Timeout: config.requestTimeout ?? 60,
160
- },
161
- };
346
+ createUpstream: async (config) => {
347
+ logger_1.logger.info(lang_1.lang.__('VOLCENGINE_CREATING_APIGW_UPSTREAM', { upstreamName: config.upstreamName }));
162
348
  const response = await client.fetchOpenAPI({
163
- Action: 'CreateApi',
349
+ Action: 'CreateUpstream',
164
350
  Version: '2021-03-03',
165
351
  method: 'POST',
166
352
  headers: { 'content-type': 'application/json' },
167
- data: params,
353
+ data: {
354
+ Name: config.upstreamName,
355
+ GatewayId: config.gatewayId,
356
+ SourceType: config.sourceType,
357
+ Protocol: config.protocol ?? 'HTTP',
358
+ UpstreamSpec: {
359
+ // VeFaas 是单对象(非数组),内含 FunctionId
360
+ VeFaas: { FunctionId: config.functionId },
361
+ },
362
+ },
168
363
  });
169
364
  const data = (response.Result || {});
170
- return data.ApiId;
365
+ return data.Id ?? '';
171
366
  },
172
- getApi: async (gatewayId, apiId) => {
367
+ getUpstream: async (upstreamId) => {
173
368
  try {
174
369
  const response = await client.fetchOpenAPI({
175
- Action: 'GetApi',
370
+ Action: 'ListUpstreams',
176
371
  Version: '2021-03-03',
177
372
  method: 'POST',
178
373
  headers: { 'content-type': 'application/json' },
179
- data: { GatewayId: gatewayId, ApiId: apiId },
374
+ data: { Filter: { Ids: [upstreamId] } },
180
375
  });
181
- const data = (response.Result || {});
182
- const backendConfig = (data.BackendConfig || {});
376
+ const result = (response.Result || {});
377
+ const items = (result.Items ?? []);
378
+ const data = items[0];
379
+ if (!data) {
380
+ return null;
381
+ }
382
+ const upstreamSpec = data.UpstreamSpec;
383
+ const veFaas = upstreamSpec?.VeFaas;
183
384
  return {
184
- apiId: data.ApiId,
185
- apiName: data.Name,
385
+ upstreamId: data.Id,
386
+ upstreamName: data.Name,
186
387
  gatewayId: data.GatewayId,
187
- method: data.Method,
188
- path: data.Path,
189
- description: data.Description,
190
- backendType: data.BackendType,
191
- backendId: data.BackendId,
192
- backendFunctionName: backendConfig.FunctionName,
193
388
  status: data.Status,
194
- createdTime: data.CreatedTime,
389
+ sourceType: data.SourceType,
390
+ protocol: data.Protocol,
391
+ functionId: veFaas?.FunctionId ?? undefined,
392
+ createdTime: data.CreateTime,
393
+ comments: data.Comments ?? data.Description,
394
+ resourceType: data.ResourceType,
395
+ updateTime: data.UpdateTime,
396
+ backendTargetList: data.BackendTargetList?.map((b) => ({
397
+ ip: b.Ip,
398
+ port: b.Port,
399
+ healthStatus: b.HealthStatus,
400
+ })),
195
401
  };
196
402
  }
197
403
  catch (error) {
198
- if (error && typeof error === 'object' && 'code' in error) {
199
- if (error.code === 'ResourceNotFound' || error.code === 'ApiNotFound') {
200
- return null;
201
- }
404
+ const err = error;
405
+ if (err.code === 'NotFound' || err.code === 'UpstreamNotFound') {
406
+ return null;
202
407
  }
203
408
  throw error;
204
409
  }
205
410
  },
206
- updateApi: async (apiId, config) => {
207
- const params = {
208
- ApiId: apiId,
209
- GatewayId: config.gatewayId,
210
- Name: config.apiName,
211
- Method: config.method,
212
- Path: config.path,
213
- BackendType: 'Function',
214
- BackendConfig: {
215
- FunctionName: config.backendFunctionName,
216
- Timeout: config.requestTimeout ?? 60,
217
- },
218
- };
219
- await client.fetchOpenAPI({
220
- Action: 'UpdateApi',
411
+ findUpstreamByName: async (gatewayId, upstreamName) => {
412
+ const response = await client.fetchOpenAPI({
413
+ Action: 'ListUpstreams',
221
414
  Version: '2021-03-03',
222
415
  method: 'POST',
223
416
  headers: { 'content-type': 'application/json' },
224
- data: params,
417
+ data: { GatewayId: gatewayId, Filter: { Name: upstreamName } },
225
418
  });
419
+ const result = (response.Result || {});
420
+ const items = (result.Items ?? []);
421
+ const match = items.find((u) => u.Name === upstreamName);
422
+ if (!match) {
423
+ return null;
424
+ }
425
+ const upstreamSpec = match.UpstreamSpec;
426
+ const veFaas = upstreamSpec?.VeFaas;
427
+ return {
428
+ upstreamId: match.Id,
429
+ upstreamName: match.Name,
430
+ gatewayId: match.GatewayId,
431
+ sourceType: match.SourceType,
432
+ protocol: match.Protocol,
433
+ functionId: veFaas?.FunctionId ?? undefined,
434
+ status: match.Status,
435
+ createdTime: match.CreateTime,
436
+ comments: match.Comments ?? match.Description,
437
+ resourceType: match.ResourceType,
438
+ updateTime: match.UpdateTime,
439
+ backendTargetList: match.BackendTargetList?.map((b) => ({
440
+ ip: b.Ip,
441
+ port: b.Port,
442
+ healthStatus: b.HealthStatus,
443
+ })),
444
+ };
226
445
  },
227
- deleteApi: async (gatewayId, apiId) => {
446
+ deleteUpstream: async (upstreamId) => {
228
447
  await client.fetchOpenAPI({
229
- Action: 'DeleteApi',
448
+ Action: 'DeleteUpstream',
230
449
  Version: '2021-03-03',
231
450
  method: 'POST',
232
451
  headers: { 'content-type': 'application/json' },
233
- data: { GatewayId: gatewayId, ApiId: apiId },
452
+ data: { Id: upstreamId },
234
453
  });
235
454
  },
236
- deployApi: async (gatewayId, apiId) => {
237
- await client.fetchOpenAPI({
238
- Action: 'DeployApi',
239
- Version: '2021-03-03',
455
+ createRoute: async (config) => {
456
+ logger_1.logger.info(lang_1.lang.__('VOLCENGINE_CREATING_APIGW_ROUTE', { routeName: config.routeName }));
457
+ const response = await client.fetchOpenAPI({
458
+ Action: 'CreateRoute',
459
+ Version: '2022-11-12',
240
460
  method: 'POST',
241
461
  headers: { 'content-type': 'application/json' },
242
- data: { GatewayId: gatewayId, ApiId: apiId, Stage: 'RELEASE' },
462
+ data: {
463
+ Name: config.routeName,
464
+ ServiceId: config.serviceId,
465
+ Enable: true,
466
+ Priority: 0,
467
+ MatchRule: {
468
+ // Path 是单对象(非数组)
469
+ Path: { MatchType: 'Exact', MatchContent: config.path },
470
+ Method: [config.method],
471
+ },
472
+ UpstreamList: [{ UpstreamId: config.upstreamId, Weight: 100 }],
473
+ },
243
474
  });
475
+ const data = (response.Result || {});
476
+ return data.Id ?? '';
244
477
  },
245
- bindDomain: async (config) => {
246
- const params = {
247
- GatewayId: config.gatewayId,
248
- DomainName: config.domainName,
249
- ...(config.certificateId && { CertificateId: config.certificateId }),
478
+ findRouteByName: async (serviceId, routeName) => {
479
+ const response = await client.fetchOpenAPI({
480
+ Action: 'ListRoutes',
481
+ Version: '2022-11-12',
482
+ method: 'POST',
483
+ headers: { 'content-type': 'application/json' },
484
+ data: { Filter: { ServiceId: serviceId } },
485
+ });
486
+ const result = (response.Result || {});
487
+ const items = (result.Items ?? []);
488
+ const match = items.find((r) => r.Name === routeName);
489
+ if (!match) {
490
+ return null;
491
+ }
492
+ const matchRule = match.MatchRule;
493
+ const path = matchRule?.Path;
494
+ const upstreamList = match.UpstreamList;
495
+ return {
496
+ routeId: match.Id,
497
+ routeName: match.Name,
498
+ serviceId: match.ServiceId,
499
+ status: match.Status,
500
+ enable: match.Enable,
501
+ priority: match.Priority,
502
+ method: matchRule?.Method?.[0],
503
+ path: path?.MatchContent,
504
+ upstreamIds: upstreamList?.map((u) => u.UpstreamId),
505
+ matchRule: matchRule
506
+ ? {
507
+ method: matchRule.Method,
508
+ path: path
509
+ ? {
510
+ matchType: path.MatchType,
511
+ matchContent: path.MatchContent,
512
+ }
513
+ : undefined,
514
+ }
515
+ : undefined,
516
+ upstreamList: upstreamList?.map((u) => ({
517
+ upstreamId: u.UpstreamId,
518
+ version: u.Version,
519
+ weight: u.Weight,
520
+ })),
250
521
  };
522
+ },
523
+ getRoute: async (routeId) => {
524
+ try {
525
+ const response = await client.fetchOpenAPI({
526
+ Action: 'GetRoute',
527
+ Version: '2022-11-12',
528
+ method: 'POST',
529
+ headers: { 'content-type': 'application/json' },
530
+ data: { Id: routeId },
531
+ });
532
+ const result = (response.Result || {});
533
+ const data = (result.Route ?? {});
534
+ const matchRule = data.MatchRule;
535
+ const path = matchRule?.Path;
536
+ const upstreamList = data.UpstreamList;
537
+ return {
538
+ routeId: data.Id,
539
+ routeName: data.Name,
540
+ serviceId: data.ServiceId,
541
+ status: data.Status,
542
+ enable: data.Enable,
543
+ priority: data.Priority,
544
+ method: matchRule?.Method?.[0],
545
+ path: path?.MatchContent,
546
+ upstreamIds: upstreamList?.map((u) => u.UpstreamId),
547
+ matchRule: matchRule
548
+ ? {
549
+ method: matchRule.Method,
550
+ path: path
551
+ ? {
552
+ matchType: path.MatchType,
553
+ matchContent: path.MatchContent,
554
+ }
555
+ : undefined,
556
+ }
557
+ : undefined,
558
+ upstreamList: upstreamList?.map((u) => ({
559
+ upstreamId: u.UpstreamId,
560
+ version: u.Version,
561
+ weight: u.Weight,
562
+ })),
563
+ };
564
+ }
565
+ catch (error) {
566
+ const err = error;
567
+ if (err.code === 'NotFound' || err.code === 'RouteNotFound') {
568
+ return null;
569
+ }
570
+ throw error;
571
+ }
572
+ },
573
+ listRoutesByService: async (serviceId) => {
574
+ const response = await client.fetchOpenAPI({
575
+ Action: 'ListRoutes',
576
+ Version: '2022-11-12',
577
+ method: 'POST',
578
+ headers: { 'content-type': 'application/json' },
579
+ data: { Filter: { ServiceId: serviceId } },
580
+ });
581
+ const result = (response.Result || {});
582
+ const items = (result.Items ?? []);
583
+ return items.map((r) => {
584
+ const matchRule = r.MatchRule;
585
+ const path = matchRule?.Path;
586
+ const upstreamList = r.UpstreamList;
587
+ return {
588
+ routeId: r.Id,
589
+ routeName: r.Name,
590
+ serviceId: r.ServiceId,
591
+ status: r.Status,
592
+ enable: r.Enable,
593
+ priority: r.Priority,
594
+ method: matchRule?.Method?.[0],
595
+ path: path?.MatchContent,
596
+ upstreamIds: upstreamList?.map((u) => u.UpstreamId),
597
+ matchRule: matchRule
598
+ ? {
599
+ method: matchRule.Method,
600
+ path: path
601
+ ? {
602
+ matchType: path.MatchType,
603
+ matchContent: path.MatchContent,
604
+ }
605
+ : undefined,
606
+ }
607
+ : undefined,
608
+ upstreamList: upstreamList?.map((u) => ({
609
+ upstreamId: u.UpstreamId,
610
+ version: u.Version,
611
+ weight: u.Weight,
612
+ })),
613
+ };
614
+ });
615
+ },
616
+ deleteRoute: async (routeId) => {
251
617
  await client.fetchOpenAPI({
252
- Action: 'BindDomain',
618
+ Action: 'DeleteRoute',
619
+ Version: '2022-11-12',
620
+ method: 'POST',
621
+ headers: { 'content-type': 'application/json' },
622
+ data: { Id: routeId },
623
+ });
624
+ },
625
+ createCustomDomain: async (config) => {
626
+ const response = await client.fetchOpenAPI({
627
+ Action: 'CreateCustomDomain',
253
628
  Version: '2021-03-03',
254
629
  method: 'POST',
255
630
  headers: { 'content-type': 'application/json' },
256
- data: params,
631
+ data: {
632
+ ServiceId: config.serviceId,
633
+ Domain: config.domainName,
634
+ ...(config.certificateId && { CertificateId: config.certificateId }),
635
+ },
257
636
  });
258
- logger_1.logger.info(lang_1.lang.__('APIGW_DOMAIN_BOUND_SUCCESS', { domain: config.domainName }));
637
+ const data = (response.Result || {});
638
+ return data.Id ?? '';
259
639
  },
260
- unbindDomain: async (gatewayId, domainName) => {
640
+ deleteCustomDomain: async (domainId) => {
261
641
  await client.fetchOpenAPI({
262
- Action: 'UnbindDomain',
642
+ Action: 'DeleteCustomDomain',
263
643
  Version: '2021-03-03',
264
644
  method: 'POST',
265
645
  headers: { 'content-type': 'application/json' },
266
- data: { GatewayId: gatewayId, DomainName: domainName },
646
+ data: { Id: domainId },
267
647
  });
268
648
  },
269
649
  };